xref: /f-stack/dpdk/lib/librte_port/rte_swx_port.h (revision 2d9fd380)
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] args
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] args
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 flush
152  *
153  * @param[in] port
154  *   Output port handle.
155  */
156 typedef void
157 (*rte_swx_port_out_flush_t)(void *port);
158 
159 /** Output port statistics counters. */
160 struct rte_swx_port_out_stats {
161 	/** Number of packets. */
162 	uint64_t n_pkts;
163 
164 	/** Number of bytes. */
165 	uint64_t n_bytes;
166 };
167 
168 /**
169  * Output port statistics counters read
170  *
171  * @param[in] port
172  *   Output port handle.
173  * @param[out] stats
174  *   Output port statistics counters. Must point to valid memory.
175  */
176 typedef void
177 (*rte_swx_port_out_stats_read_t)(void *port,
178 				 struct rte_swx_port_out_stats *stats);
179 
180 /** Output port operations. */
181 struct rte_swx_port_out_ops {
182 	/** Create. Must be non-NULL. */
183 	rte_swx_port_out_create_t create;
184 
185 	/** Free. Must be non-NULL. */
186 	rte_swx_port_out_free_t free;
187 
188 	/** Packet transmission. Must be non-NULL. */
189 	rte_swx_port_out_pkt_tx_t pkt_tx;
190 
191 	/** Flush. May be NULL. */
192 	rte_swx_port_out_flush_t flush;
193 
194 	/** Statistics counters read. Must be non-NULL. */
195 	rte_swx_port_out_stats_read_t stats_read;
196 };
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif
203