xref: /dpdk/lib/port/rte_port.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2010-2014 Intel Corporation
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef __INCLUDE_RTE_PORT_H__
699a2dd95SBruce Richardson #define __INCLUDE_RTE_PORT_H__
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  * RTE Port
1199a2dd95SBruce Richardson  *
1299a2dd95SBruce Richardson  * This tool is part of the DPDK Packet Framework tool suite and provides
1399a2dd95SBruce Richardson  * a standard interface to implement different types of packet ports.
14*3e4c5be9SThomas Monjalon  */
1599a2dd95SBruce Richardson 
1699a2dd95SBruce Richardson #include <stdint.h>
1799a2dd95SBruce Richardson #include <rte_mbuf.h>
1899a2dd95SBruce Richardson 
1999a2dd95SBruce Richardson /**@{
2099a2dd95SBruce Richardson  * Macros to allow accessing metadata stored in the mbuf headroom
2199a2dd95SBruce Richardson  * just beyond the end of the mbuf data structure returned by a port
2299a2dd95SBruce Richardson  */
2399a2dd95SBruce Richardson #define RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)          \
2499a2dd95SBruce Richardson 	(&((uint8_t *)(mbuf))[offset])
2599a2dd95SBruce Richardson #define RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset)         \
2699a2dd95SBruce Richardson 	((uint16_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
2799a2dd95SBruce Richardson #define RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset)         \
2899a2dd95SBruce Richardson 	((uint32_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
2999a2dd95SBruce Richardson #define RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset)         \
3099a2dd95SBruce Richardson 	((uint64_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
3199a2dd95SBruce Richardson 
3299a2dd95SBruce Richardson #define RTE_MBUF_METADATA_UINT8(mbuf, offset)              \
3399a2dd95SBruce Richardson 	(*RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
3499a2dd95SBruce Richardson #define RTE_MBUF_METADATA_UINT16(mbuf, offset)             \
3599a2dd95SBruce Richardson 	(*RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset))
3699a2dd95SBruce Richardson #define RTE_MBUF_METADATA_UINT32(mbuf, offset)             \
3799a2dd95SBruce Richardson 	(*RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset))
3899a2dd95SBruce Richardson #define RTE_MBUF_METADATA_UINT64(mbuf, offset)             \
3999a2dd95SBruce Richardson 	(*RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset))
4099a2dd95SBruce Richardson /**@}*/
4199a2dd95SBruce Richardson 
4299a2dd95SBruce Richardson /*
4399a2dd95SBruce Richardson  * Port IN
4499a2dd95SBruce Richardson  */
4599a2dd95SBruce Richardson /** Maximum number of packets read from any input port in a single burst.
4699a2dd95SBruce Richardson Cannot be changed. */
4799a2dd95SBruce Richardson #define RTE_PORT_IN_BURST_SIZE_MAX                         64
4899a2dd95SBruce Richardson 
4999a2dd95SBruce Richardson /** Input port statistics */
5099a2dd95SBruce Richardson struct rte_port_in_stats {
5199a2dd95SBruce Richardson 	uint64_t n_pkts_in;
5299a2dd95SBruce Richardson 	uint64_t n_pkts_drop;
5399a2dd95SBruce Richardson };
5499a2dd95SBruce Richardson 
5599a2dd95SBruce Richardson /**
5699a2dd95SBruce Richardson  * Input port create
5799a2dd95SBruce Richardson  *
5899a2dd95SBruce Richardson  * @param params
5999a2dd95SBruce Richardson  *   Parameters for input port creation
6099a2dd95SBruce Richardson  * @param socket_id
6199a2dd95SBruce Richardson  *   CPU socket ID (e.g. for memory allocation purpose)
6299a2dd95SBruce Richardson  * @return
6399a2dd95SBruce Richardson  *   Handle to input port instance
6499a2dd95SBruce Richardson  */
6599a2dd95SBruce Richardson typedef void* (*rte_port_in_op_create)(void *params, int socket_id);
6699a2dd95SBruce Richardson 
6799a2dd95SBruce Richardson /**
6899a2dd95SBruce Richardson  * Input port free
6999a2dd95SBruce Richardson  *
7099a2dd95SBruce Richardson  * @param port
7199a2dd95SBruce Richardson  *   Handle to input port instance
7299a2dd95SBruce Richardson  * @return
7399a2dd95SBruce Richardson  *   0 on success, error code otherwise
7499a2dd95SBruce Richardson  */
7599a2dd95SBruce Richardson typedef int (*rte_port_in_op_free)(void *port);
7699a2dd95SBruce Richardson 
7799a2dd95SBruce Richardson /**
7899a2dd95SBruce Richardson  * Input port packet burst RX
7999a2dd95SBruce Richardson  *
8099a2dd95SBruce Richardson  * @param port
8199a2dd95SBruce Richardson  *   Handle to input port instance
8299a2dd95SBruce Richardson  * @param pkts
8399a2dd95SBruce Richardson  *   Burst of input packets
8499a2dd95SBruce Richardson  * @param n_pkts
8599a2dd95SBruce Richardson  *   Number of packets in the input burst
8699a2dd95SBruce Richardson  * @return
8799a2dd95SBruce Richardson  *   0 on success, error code otherwise
8899a2dd95SBruce Richardson  */
8999a2dd95SBruce Richardson typedef int (*rte_port_in_op_rx)(
9099a2dd95SBruce Richardson 	void *port,
9199a2dd95SBruce Richardson 	struct rte_mbuf **pkts,
9299a2dd95SBruce Richardson 	uint32_t n_pkts);
9399a2dd95SBruce Richardson 
9499a2dd95SBruce Richardson /**
9599a2dd95SBruce Richardson  * Input port stats get
9699a2dd95SBruce Richardson  *
9799a2dd95SBruce Richardson  * @param port
9899a2dd95SBruce Richardson  *   Handle to output port instance
9999a2dd95SBruce Richardson  * @param stats
10099a2dd95SBruce Richardson  *   Handle to port_in stats struct to copy data
10199a2dd95SBruce Richardson  * @param clear
10299a2dd95SBruce Richardson  *   Flag indicating that stats should be cleared after read
10399a2dd95SBruce Richardson  *
10499a2dd95SBruce Richardson  * @return
10599a2dd95SBruce Richardson  *   Error code or 0 on success.
10699a2dd95SBruce Richardson  */
10799a2dd95SBruce Richardson typedef int (*rte_port_in_op_stats_read)(
10899a2dd95SBruce Richardson 		void *port,
10999a2dd95SBruce Richardson 		struct rte_port_in_stats *stats,
11099a2dd95SBruce Richardson 		int clear);
11199a2dd95SBruce Richardson 
11299a2dd95SBruce Richardson /** Input port interface defining the input port operation */
11399a2dd95SBruce Richardson struct rte_port_in_ops {
11499a2dd95SBruce Richardson 	rte_port_in_op_create f_create;      /**< Create */
11599a2dd95SBruce Richardson 	rte_port_in_op_free f_free;          /**< Free */
11699a2dd95SBruce Richardson 	rte_port_in_op_rx f_rx;              /**< Packet RX (packet burst) */
11799a2dd95SBruce Richardson 	rte_port_in_op_stats_read f_stats;   /**< Stats */
11899a2dd95SBruce Richardson };
11999a2dd95SBruce Richardson 
12099a2dd95SBruce Richardson /*
12199a2dd95SBruce Richardson  * Port OUT
12299a2dd95SBruce Richardson  */
12399a2dd95SBruce Richardson /** Output port statistics */
12499a2dd95SBruce Richardson struct rte_port_out_stats {
12599a2dd95SBruce Richardson 	uint64_t n_pkts_in;
12699a2dd95SBruce Richardson 	uint64_t n_pkts_drop;
12799a2dd95SBruce Richardson };
12899a2dd95SBruce Richardson 
12999a2dd95SBruce Richardson /**
13099a2dd95SBruce Richardson  * Output port create
13199a2dd95SBruce Richardson  *
13299a2dd95SBruce Richardson  * @param params
13399a2dd95SBruce Richardson  *   Parameters for output port creation
13499a2dd95SBruce Richardson  * @param socket_id
13599a2dd95SBruce Richardson  *   CPU socket ID (e.g. for memory allocation purpose)
13699a2dd95SBruce Richardson  * @return
13799a2dd95SBruce Richardson  *   Handle to output port instance
13899a2dd95SBruce Richardson  */
13999a2dd95SBruce Richardson typedef void* (*rte_port_out_op_create)(void *params, int socket_id);
14099a2dd95SBruce Richardson 
14199a2dd95SBruce Richardson /**
14299a2dd95SBruce Richardson  * Output port free
14399a2dd95SBruce Richardson  *
14499a2dd95SBruce Richardson  * @param port
14599a2dd95SBruce Richardson  *   Handle to output port instance
14699a2dd95SBruce Richardson  * @return
14799a2dd95SBruce Richardson  *   0 on success, error code otherwise
14899a2dd95SBruce Richardson  */
14999a2dd95SBruce Richardson typedef int (*rte_port_out_op_free)(void *port);
15099a2dd95SBruce Richardson 
15199a2dd95SBruce Richardson /**
15299a2dd95SBruce Richardson  * Output port single packet TX
15399a2dd95SBruce Richardson  *
15499a2dd95SBruce Richardson  * @param port
15599a2dd95SBruce Richardson  *   Handle to output port instance
15699a2dd95SBruce Richardson  * @param pkt
15799a2dd95SBruce Richardson  *   Input packet
15899a2dd95SBruce Richardson  * @return
15999a2dd95SBruce Richardson  *   0 on success, error code otherwise
16099a2dd95SBruce Richardson  */
16199a2dd95SBruce Richardson typedef int (*rte_port_out_op_tx)(
16299a2dd95SBruce Richardson 	void *port,
16399a2dd95SBruce Richardson 	struct rte_mbuf *pkt);
16499a2dd95SBruce Richardson 
16599a2dd95SBruce Richardson /**
16699a2dd95SBruce Richardson  * Output port packet burst TX
16799a2dd95SBruce Richardson  *
16899a2dd95SBruce Richardson  * @param port
16999a2dd95SBruce Richardson  *   Handle to output port instance
17099a2dd95SBruce Richardson  * @param pkts
17199a2dd95SBruce Richardson  *   Burst of input packets specified as array of up to 64 pointers to struct
17299a2dd95SBruce Richardson  *   rte_mbuf
17399a2dd95SBruce Richardson  * @param pkts_mask
17499a2dd95SBruce Richardson  *   64-bit bitmask specifying which packets in the input burst are valid. When
17599a2dd95SBruce Richardson  *   pkts_mask bit n is set, then element n of pkts array is pointing to a
17699a2dd95SBruce Richardson  *   valid packet. Otherwise, element n of pkts array will not be accessed.
17799a2dd95SBruce Richardson  * @return
17899a2dd95SBruce Richardson  *   0 on success, error code otherwise
17999a2dd95SBruce Richardson  */
18099a2dd95SBruce Richardson typedef int (*rte_port_out_op_tx_bulk)(
18199a2dd95SBruce Richardson 	void *port,
18299a2dd95SBruce Richardson 	struct rte_mbuf **pkts,
18399a2dd95SBruce Richardson 	uint64_t pkts_mask);
18499a2dd95SBruce Richardson 
18599a2dd95SBruce Richardson /**
18699a2dd95SBruce Richardson  * Output port flush
18799a2dd95SBruce Richardson  *
18899a2dd95SBruce Richardson  * @param port
18999a2dd95SBruce Richardson  *   Handle to output port instance
19099a2dd95SBruce Richardson  * @return
19199a2dd95SBruce Richardson  *   0 on success, error code otherwise
19299a2dd95SBruce Richardson  */
19399a2dd95SBruce Richardson typedef int (*rte_port_out_op_flush)(void *port);
19499a2dd95SBruce Richardson 
19599a2dd95SBruce Richardson /**
19699a2dd95SBruce Richardson  * Output port stats read
19799a2dd95SBruce Richardson  *
19899a2dd95SBruce Richardson  * @param port
19999a2dd95SBruce Richardson  *   Handle to output port instance
20099a2dd95SBruce Richardson  * @param stats
20199a2dd95SBruce Richardson  *   Handle to port_out stats struct to copy data
20299a2dd95SBruce Richardson  * @param clear
20399a2dd95SBruce Richardson  *   Flag indicating that stats should be cleared after read
20499a2dd95SBruce Richardson  *
20599a2dd95SBruce Richardson  * @return
20699a2dd95SBruce Richardson  *   Error code or 0 on success.
20799a2dd95SBruce Richardson  */
20899a2dd95SBruce Richardson typedef int (*rte_port_out_op_stats_read)(
20999a2dd95SBruce Richardson 		void *port,
21099a2dd95SBruce Richardson 		struct rte_port_out_stats *stats,
21199a2dd95SBruce Richardson 		int clear);
21299a2dd95SBruce Richardson 
21399a2dd95SBruce Richardson /** Output port interface defining the output port operation */
21499a2dd95SBruce Richardson struct rte_port_out_ops {
21599a2dd95SBruce Richardson 	rte_port_out_op_create f_create;      /**< Create */
21699a2dd95SBruce Richardson 	rte_port_out_op_free f_free;          /**< Free */
21799a2dd95SBruce Richardson 	rte_port_out_op_tx f_tx;              /**< Packet TX (single packet) */
21899a2dd95SBruce Richardson 	rte_port_out_op_tx_bulk f_tx_bulk;    /**< Packet TX (packet burst) */
21999a2dd95SBruce Richardson 	rte_port_out_op_flush f_flush;        /**< Flush */
22099a2dd95SBruce Richardson 	rte_port_out_op_stats_read f_stats;   /**< Stats */
22199a2dd95SBruce Richardson };
22299a2dd95SBruce Richardson 
22399a2dd95SBruce Richardson #endif
224