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