xref: /dpdk/lib/port/rte_swx_port.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2020 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson #ifndef __INCLUDE_RTE_SWX_PORT_H__
599a2dd95SBruce Richardson #define __INCLUDE_RTE_SWX_PORT_H__
699a2dd95SBruce Richardson 
799a2dd95SBruce Richardson /**
899a2dd95SBruce Richardson  * @file
999a2dd95SBruce Richardson  * RTE SWX Port
1099a2dd95SBruce Richardson  *
1199a2dd95SBruce Richardson  * Packet I/O port interface.
1299a2dd95SBruce Richardson  */
1399a2dd95SBruce Richardson 
1499a2dd95SBruce Richardson #include <stdint.h>
1599a2dd95SBruce Richardson 
1699a2dd95SBruce Richardson /** Packet. */
1799a2dd95SBruce Richardson struct rte_swx_pkt {
1899a2dd95SBruce Richardson 	/** Opaque packet handle. */
1999a2dd95SBruce Richardson 	void *handle;
2099a2dd95SBruce Richardson 
2199a2dd95SBruce Richardson 	/** Buffer where the packet is stored. */
2299a2dd95SBruce Richardson 	uint8_t *pkt;
2399a2dd95SBruce Richardson 
2499a2dd95SBruce Richardson 	/** Packet buffer offset of the first packet byte. */
2599a2dd95SBruce Richardson 	uint32_t offset;
2699a2dd95SBruce Richardson 
2799a2dd95SBruce Richardson 	/** Packet length in bytes. */
2899a2dd95SBruce Richardson 	uint32_t length;
2999a2dd95SBruce Richardson };
3099a2dd95SBruce Richardson 
3199a2dd95SBruce Richardson /*
3299a2dd95SBruce Richardson  * Input port
3399a2dd95SBruce Richardson  */
3499a2dd95SBruce Richardson 
3599a2dd95SBruce Richardson /**
3699a2dd95SBruce Richardson  * Input port create
3799a2dd95SBruce Richardson  *
3899a2dd95SBruce Richardson  * @param[in] args
3999a2dd95SBruce Richardson  *   Arguments for input port creation. Format specific to each port type.
4099a2dd95SBruce Richardson  * @return
4199a2dd95SBruce Richardson  *   Handle to input port instance on success, NULL on error.
4299a2dd95SBruce Richardson  */
4399a2dd95SBruce Richardson typedef void *
4499a2dd95SBruce Richardson (*rte_swx_port_in_create_t)(void *args);
4599a2dd95SBruce Richardson 
4699a2dd95SBruce Richardson /**
4799a2dd95SBruce Richardson  * Input port free
4899a2dd95SBruce Richardson  *
4999a2dd95SBruce Richardson  * @param[in] port
5099a2dd95SBruce Richardson  *   Input port handle.
5199a2dd95SBruce Richardson  */
5299a2dd95SBruce Richardson typedef void
5399a2dd95SBruce Richardson (*rte_swx_port_in_free_t)(void *port);
5499a2dd95SBruce Richardson 
5599a2dd95SBruce Richardson /**
5699a2dd95SBruce Richardson  * Input port packet receive
5799a2dd95SBruce Richardson  *
5899a2dd95SBruce Richardson  * @param[in] port
5999a2dd95SBruce Richardson  *   Input port handle.
6099a2dd95SBruce Richardson  * @param[out] pkt
6199a2dd95SBruce Richardson  *   Received packet. Only valid when the function returns 1. Must point to
6299a2dd95SBruce Richardson  *   valid memory.
6399a2dd95SBruce Richardson  * @return
6499a2dd95SBruce Richardson  *   0 when no packet was received, 1 when a packet was received. No other
6599a2dd95SBruce Richardson  *   return values are allowed.
6699a2dd95SBruce Richardson  */
6799a2dd95SBruce Richardson typedef int
6899a2dd95SBruce Richardson (*rte_swx_port_in_pkt_rx_t)(void *port,
6999a2dd95SBruce Richardson 			    struct rte_swx_pkt *pkt);
7099a2dd95SBruce Richardson 
7199a2dd95SBruce Richardson /** Input port statistics counters. */
7299a2dd95SBruce Richardson struct rte_swx_port_in_stats {
7399a2dd95SBruce Richardson 	/** Number of packets. */
7499a2dd95SBruce Richardson 	uint64_t n_pkts;
7599a2dd95SBruce Richardson 
7699a2dd95SBruce Richardson 	/** Number of bytes. */
7799a2dd95SBruce Richardson 	uint64_t n_bytes;
7899a2dd95SBruce Richardson 
7999a2dd95SBruce Richardson 	/** Number of empty polls. */
8099a2dd95SBruce Richardson 	uint64_t n_empty;
8199a2dd95SBruce Richardson };
8299a2dd95SBruce Richardson 
8399a2dd95SBruce Richardson /**
8499a2dd95SBruce Richardson  * Input port statistics counters read
8599a2dd95SBruce Richardson  *
8699a2dd95SBruce Richardson  * @param[in] port
8799a2dd95SBruce Richardson  *   Input port handle.
8899a2dd95SBruce Richardson  * @param[out] stats
8999a2dd95SBruce Richardson  *   Input port statistics counters. Must point to valid memory.
9099a2dd95SBruce Richardson  */
9199a2dd95SBruce Richardson typedef void
9299a2dd95SBruce Richardson (*rte_swx_port_in_stats_read_t)(void *port,
9399a2dd95SBruce Richardson 				struct rte_swx_port_in_stats *stats);
9499a2dd95SBruce Richardson 
9599a2dd95SBruce Richardson /** Input port operations. */
9699a2dd95SBruce Richardson struct rte_swx_port_in_ops {
9799a2dd95SBruce Richardson 	/** Create. Must be non-NULL. */
9899a2dd95SBruce Richardson 	rte_swx_port_in_create_t create;
9999a2dd95SBruce Richardson 
10099a2dd95SBruce Richardson 	/** Free. Must be non-NULL. */
10199a2dd95SBruce Richardson 	rte_swx_port_in_free_t free;
10299a2dd95SBruce Richardson 
10399a2dd95SBruce Richardson 	/** Packet reception. Must be non-NULL. */
10499a2dd95SBruce Richardson 	rte_swx_port_in_pkt_rx_t pkt_rx;
10599a2dd95SBruce Richardson 
10699a2dd95SBruce Richardson 	/** Statistics counters read. Must be non-NULL. */
10799a2dd95SBruce Richardson 	rte_swx_port_in_stats_read_t stats_read;
10899a2dd95SBruce Richardson };
10999a2dd95SBruce Richardson 
11099a2dd95SBruce Richardson /*
11199a2dd95SBruce Richardson  * Output port
11299a2dd95SBruce Richardson  */
11399a2dd95SBruce Richardson 
11499a2dd95SBruce Richardson /**
11599a2dd95SBruce Richardson  * Output port create
11699a2dd95SBruce Richardson  *
11799a2dd95SBruce Richardson  * @param[in] args
11899a2dd95SBruce Richardson  *   Arguments for output port creation. Format specific to each port type.
11999a2dd95SBruce Richardson  * @return
12099a2dd95SBruce Richardson  *   Handle to output port instance on success, NULL on error.
12199a2dd95SBruce Richardson  */
12299a2dd95SBruce Richardson typedef void *
12399a2dd95SBruce Richardson (*rte_swx_port_out_create_t)(void *args);
12499a2dd95SBruce Richardson 
12599a2dd95SBruce Richardson /**
12699a2dd95SBruce Richardson  * Output port free
12799a2dd95SBruce Richardson  *
12899a2dd95SBruce Richardson  * @param[in] port
12999a2dd95SBruce Richardson  *   Output port handle.
13099a2dd95SBruce Richardson  */
13199a2dd95SBruce Richardson typedef void
13299a2dd95SBruce Richardson (*rte_swx_port_out_free_t)(void *port);
13399a2dd95SBruce Richardson 
13499a2dd95SBruce Richardson /**
13599a2dd95SBruce Richardson  * Output port packet transmit
13699a2dd95SBruce Richardson  *
13799a2dd95SBruce Richardson  * @param[in] port
13899a2dd95SBruce Richardson  *   Output port handle.
13999a2dd95SBruce Richardson  * @param[in] pkt
14099a2dd95SBruce Richardson  *   Packet to be transmitted.
14199a2dd95SBruce Richardson  */
14299a2dd95SBruce Richardson typedef void
14399a2dd95SBruce Richardson (*rte_swx_port_out_pkt_tx_t)(void *port,
14499a2dd95SBruce Richardson 			     struct rte_swx_pkt *pkt);
14599a2dd95SBruce Richardson 
14699a2dd95SBruce Richardson /**
147b94eb6cdSCristian Dumitrescu  * Output port packet fast clone and transmit
148b94eb6cdSCristian Dumitrescu  *
149b94eb6cdSCristian Dumitrescu  * @param[in] port
150b94eb6cdSCristian Dumitrescu  *   Output port handle.
151b94eb6cdSCristian Dumitrescu  * @param[in] pkt
152b94eb6cdSCristian Dumitrescu  *   Packet to be transmitted.
153b94eb6cdSCristian Dumitrescu  */
154b94eb6cdSCristian Dumitrescu typedef void
155b94eb6cdSCristian Dumitrescu (*rte_swx_port_out_pkt_fast_clone_tx_t)(void *port,
156b94eb6cdSCristian Dumitrescu 					struct rte_swx_pkt *pkt);
157b94eb6cdSCristian Dumitrescu 
158b94eb6cdSCristian Dumitrescu /**
159b94eb6cdSCristian Dumitrescu  * Output port packet clone and transmit
160b94eb6cdSCristian Dumitrescu  *
161b94eb6cdSCristian Dumitrescu  * @param[in] port
162b94eb6cdSCristian Dumitrescu  *   Output port handle.
163b94eb6cdSCristian Dumitrescu  * @param[in] pkt
164b94eb6cdSCristian Dumitrescu  *   Packet to be transmitted.
165b94eb6cdSCristian Dumitrescu  * @param[in] truncation_length
166b94eb6cdSCristian Dumitrescu  *   Packet length to be cloned.
167b94eb6cdSCristian Dumitrescu  */
168b94eb6cdSCristian Dumitrescu typedef void
169b94eb6cdSCristian Dumitrescu (*rte_swx_port_out_pkt_clone_tx_t)(void *port,
170b94eb6cdSCristian Dumitrescu 				   struct rte_swx_pkt *pkt,
171b94eb6cdSCristian Dumitrescu 				   uint32_t truncation_length);
172b94eb6cdSCristian Dumitrescu 
173b94eb6cdSCristian Dumitrescu /**
17499a2dd95SBruce Richardson  * Output port flush
17599a2dd95SBruce Richardson  *
17699a2dd95SBruce Richardson  * @param[in] port
17799a2dd95SBruce Richardson  *   Output port handle.
17899a2dd95SBruce Richardson  */
17999a2dd95SBruce Richardson typedef void
18099a2dd95SBruce Richardson (*rte_swx_port_out_flush_t)(void *port);
18199a2dd95SBruce Richardson 
18299a2dd95SBruce Richardson /** Output port statistics counters. */
18399a2dd95SBruce Richardson struct rte_swx_port_out_stats {
184*e28e064bSCristian Dumitrescu 	/** Number of packets successfully transmitted. */
18599a2dd95SBruce Richardson 	uint64_t n_pkts;
18699a2dd95SBruce Richardson 
187*e28e064bSCristian Dumitrescu 	/** Number of bytes successfully transmitted. */
18899a2dd95SBruce Richardson 	uint64_t n_bytes;
189b94eb6cdSCristian Dumitrescu 
190*e28e064bSCristian Dumitrescu 	/** Number of packets dropped. */
191*e28e064bSCristian Dumitrescu 	uint64_t n_pkts_drop;
192*e28e064bSCristian Dumitrescu 
193*e28e064bSCristian Dumitrescu 	/** Number of bytes dropped. */
194*e28e064bSCristian Dumitrescu 	uint64_t n_bytes_drop;
195*e28e064bSCristian Dumitrescu 
196b94eb6cdSCristian Dumitrescu 	/** Number of packets cloned successfully. */
197b94eb6cdSCristian Dumitrescu 	uint64_t n_pkts_clone;
198b94eb6cdSCristian Dumitrescu 
199b94eb6cdSCristian Dumitrescu 	/** Number of packets with clone errors. */
200b94eb6cdSCristian Dumitrescu 	uint64_t n_pkts_clone_err;
20199a2dd95SBruce Richardson };
20299a2dd95SBruce Richardson 
20399a2dd95SBruce Richardson /**
20499a2dd95SBruce Richardson  * Output port statistics counters read
20599a2dd95SBruce Richardson  *
20699a2dd95SBruce Richardson  * @param[in] port
20799a2dd95SBruce Richardson  *   Output port handle.
20899a2dd95SBruce Richardson  * @param[out] stats
20999a2dd95SBruce Richardson  *   Output port statistics counters. Must point to valid memory.
21099a2dd95SBruce Richardson  */
21199a2dd95SBruce Richardson typedef void
21299a2dd95SBruce Richardson (*rte_swx_port_out_stats_read_t)(void *port,
21399a2dd95SBruce Richardson 				 struct rte_swx_port_out_stats *stats);
21499a2dd95SBruce Richardson 
21599a2dd95SBruce Richardson /** Output port operations. */
21699a2dd95SBruce Richardson struct rte_swx_port_out_ops {
21799a2dd95SBruce Richardson 	/** Create. Must be non-NULL. */
21899a2dd95SBruce Richardson 	rte_swx_port_out_create_t create;
21999a2dd95SBruce Richardson 
22099a2dd95SBruce Richardson 	/** Free. Must be non-NULL. */
22199a2dd95SBruce Richardson 	rte_swx_port_out_free_t free;
22299a2dd95SBruce Richardson 
22399a2dd95SBruce Richardson 	/** Packet transmission. Must be non-NULL. */
22499a2dd95SBruce Richardson 	rte_swx_port_out_pkt_tx_t pkt_tx;
22599a2dd95SBruce Richardson 
226b94eb6cdSCristian Dumitrescu 	/** Packet fast clone and transmission. Must be non-NULL. */
227b94eb6cdSCristian Dumitrescu 	rte_swx_port_out_pkt_fast_clone_tx_t pkt_fast_clone_tx;
228b94eb6cdSCristian Dumitrescu 
229b94eb6cdSCristian Dumitrescu 	/** Packet clone and transmission. Must be non-NULL. */
230b94eb6cdSCristian Dumitrescu 	rte_swx_port_out_pkt_clone_tx_t pkt_clone_tx;
231b94eb6cdSCristian Dumitrescu 
23299a2dd95SBruce Richardson 	/** Flush. May be NULL. */
23399a2dd95SBruce Richardson 	rte_swx_port_out_flush_t flush;
23499a2dd95SBruce Richardson 
23599a2dd95SBruce Richardson 	/** Statistics counters read. Must be non-NULL. */
23699a2dd95SBruce Richardson 	rte_swx_port_out_stats_read_t stats_read;
23799a2dd95SBruce Richardson };
23899a2dd95SBruce Richardson 
23999a2dd95SBruce Richardson #endif
240