xref: /dpdk/lib/port/rte_swx_port.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2020 Intel Corporation
3  */
4 #ifndef __INCLUDE_RTE_SWX_PORT_H__
5 #define __INCLUDE_RTE_SWX_PORT_H__
6 
7 /**
8  * @file
9  * RTE SWX Port
10  *
11  * Packet I/O port interface.
12  */
13 
14 #include <stdint.h>
15 
16 /** Packet. */
17 struct rte_swx_pkt {
18 	/** Opaque packet handle. */
19 	void *handle;
20 
21 	/** Buffer where the packet is stored. */
22 	uint8_t *pkt;
23 
24 	/** Packet buffer offset of the first packet byte. */
25 	uint32_t offset;
26 
27 	/** Packet length in bytes. */
28 	uint32_t length;
29 };
30 
31 /*
32  * Input port
33  */
34 
35 /**
36  * Input port create
37  *
38  * @param[in] args
39  *   Arguments for input port creation. Format specific to each port type.
40  * @return
41  *   Handle to input port instance on success, NULL on error.
42  */
43 typedef void *
44 (*rte_swx_port_in_create_t)(void *args);
45 
46 /**
47  * Input port free
48  *
49  * @param[in] port
50  *   Input port handle.
51  */
52 typedef void
53 (*rte_swx_port_in_free_t)(void *port);
54 
55 /**
56  * Input port packet receive
57  *
58  * @param[in] port
59  *   Input port handle.
60  * @param[out] pkt
61  *   Received packet. Only valid when the function returns 1. Must point to
62  *   valid memory.
63  * @return
64  *   0 when no packet was received, 1 when a packet was received. No other
65  *   return values are allowed.
66  */
67 typedef int
68 (*rte_swx_port_in_pkt_rx_t)(void *port,
69 			    struct rte_swx_pkt *pkt);
70 
71 /** Input port statistics counters. */
72 struct rte_swx_port_in_stats {
73 	/** Number of packets. */
74 	uint64_t n_pkts;
75 
76 	/** Number of bytes. */
77 	uint64_t n_bytes;
78 
79 	/** Number of empty polls. */
80 	uint64_t n_empty;
81 };
82 
83 /**
84  * Input port statistics counters read
85  *
86  * @param[in] port
87  *   Input port handle.
88  * @param[out] stats
89  *   Input port statistics counters. Must point to valid memory.
90  */
91 typedef void
92 (*rte_swx_port_in_stats_read_t)(void *port,
93 				struct rte_swx_port_in_stats *stats);
94 
95 /** Input port operations. */
96 struct rte_swx_port_in_ops {
97 	/** Create. Must be non-NULL. */
98 	rte_swx_port_in_create_t create;
99 
100 	/** Free. Must be non-NULL. */
101 	rte_swx_port_in_free_t free;
102 
103 	/** Packet reception. Must be non-NULL. */
104 	rte_swx_port_in_pkt_rx_t pkt_rx;
105 
106 	/** Statistics counters read. Must be non-NULL. */
107 	rte_swx_port_in_stats_read_t stats_read;
108 };
109 
110 /*
111  * Output port
112  */
113 
114 /**
115  * Output port create
116  *
117  * @param[in] args
118  *   Arguments for output port creation. Format specific to each port type.
119  * @return
120  *   Handle to output port instance on success, NULL on error.
121  */
122 typedef void *
123 (*rte_swx_port_out_create_t)(void *args);
124 
125 /**
126  * Output port free
127  *
128  * @param[in] port
129  *   Output port handle.
130  */
131 typedef void
132 (*rte_swx_port_out_free_t)(void *port);
133 
134 /**
135  * Output port packet transmit
136  *
137  * @param[in] port
138  *   Output port handle.
139  * @param[in] pkt
140  *   Packet to be transmitted.
141  */
142 typedef void
143 (*rte_swx_port_out_pkt_tx_t)(void *port,
144 			     struct rte_swx_pkt *pkt);
145 
146 /**
147  * Output port packet fast clone and transmit
148  *
149  * @param[in] port
150  *   Output port handle.
151  * @param[in] pkt
152  *   Packet to be transmitted.
153  */
154 typedef void
155 (*rte_swx_port_out_pkt_fast_clone_tx_t)(void *port,
156 					struct rte_swx_pkt *pkt);
157 
158 /**
159  * Output port packet clone and transmit
160  *
161  * @param[in] port
162  *   Output port handle.
163  * @param[in] pkt
164  *   Packet to be transmitted.
165  * @param[in] truncation_length
166  *   Packet length to be cloned.
167  */
168 typedef void
169 (*rte_swx_port_out_pkt_clone_tx_t)(void *port,
170 				   struct rte_swx_pkt *pkt,
171 				   uint32_t truncation_length);
172 
173 /**
174  * Output port flush
175  *
176  * @param[in] port
177  *   Output port handle.
178  */
179 typedef void
180 (*rte_swx_port_out_flush_t)(void *port);
181 
182 /** Output port statistics counters. */
183 struct rte_swx_port_out_stats {
184 	/** Number of packets successfully transmitted. */
185 	uint64_t n_pkts;
186 
187 	/** Number of bytes successfully transmitted. */
188 	uint64_t n_bytes;
189 
190 	/** Number of packets dropped. */
191 	uint64_t n_pkts_drop;
192 
193 	/** Number of bytes dropped. */
194 	uint64_t n_bytes_drop;
195 
196 	/** Number of packets cloned successfully. */
197 	uint64_t n_pkts_clone;
198 
199 	/** Number of packets with clone errors. */
200 	uint64_t n_pkts_clone_err;
201 };
202 
203 /**
204  * Output port statistics counters read
205  *
206  * @param[in] port
207  *   Output port handle.
208  * @param[out] stats
209  *   Output port statistics counters. Must point to valid memory.
210  */
211 typedef void
212 (*rte_swx_port_out_stats_read_t)(void *port,
213 				 struct rte_swx_port_out_stats *stats);
214 
215 /** Output port operations. */
216 struct rte_swx_port_out_ops {
217 	/** Create. Must be non-NULL. */
218 	rte_swx_port_out_create_t create;
219 
220 	/** Free. Must be non-NULL. */
221 	rte_swx_port_out_free_t free;
222 
223 	/** Packet transmission. Must be non-NULL. */
224 	rte_swx_port_out_pkt_tx_t pkt_tx;
225 
226 	/** Packet fast clone and transmission. Must be non-NULL. */
227 	rte_swx_port_out_pkt_fast_clone_tx_t pkt_fast_clone_tx;
228 
229 	/** Packet clone and transmission. Must be non-NULL. */
230 	rte_swx_port_out_pkt_clone_tx_t pkt_clone_tx;
231 
232 	/** Flush. May be NULL. */
233 	rte_swx_port_out_flush_t flush;
234 
235 	/** Statistics counters read. Must be non-NULL. */
236 	rte_swx_port_out_stats_read_t stats_read;
237 };
238 
239 #endif
240