1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #ifndef __INCLUDE_RTE_PORT_H__
6 #define __INCLUDE_RTE_PORT_H__
16 * This tool is part of the DPDK Packet Framework tool suite and provides
17 * a standard interface to implement different types of packet ports.
25 * Macros to allow accessing metadata stored in the mbuf headroom
26 * just beyond the end of the mbuf data structure returned by a port
28 #define RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset) \
29 (&((uint8_t *)(mbuf))[offset])
30 #define RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset) \
31 ((uint16_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
32 #define RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset) \
33 ((uint32_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
34 #define RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset) \
35 ((uint64_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
37 #define RTE_MBUF_METADATA_UINT8(mbuf, offset) \
38 (*RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
39 #define RTE_MBUF_METADATA_UINT16(mbuf, offset) \
40 (*RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset))
41 #define RTE_MBUF_METADATA_UINT32(mbuf, offset) \
42 (*RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset))
43 #define RTE_MBUF_METADATA_UINT64(mbuf, offset) \
44 (*RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset))
51 /** Maximum number of packets read from any input port in a single burst.
53 #define RTE_PORT_IN_BURST_SIZE_MAX 64
55 /** Input port statistics */
56 struct rte_port_in_stats {
65 * Parameters for input port creation
67 * CPU socket ID (e.g. for memory allocation purpose)
69 * Handle to input port instance
71 typedef void* (*rte_port_in_op_create)(void *params, int socket_id);
77 * Handle to input port instance
79 * 0 on success, error code otherwise
81 typedef int (*rte_port_in_op_free)(void *port);
84 * Input port packet burst RX
87 * Handle to input port instance
89 * Burst of input packets
91 * Number of packets in the input burst
93 * 0 on success, error code otherwise
95 typedef int (*rte_port_in_op_rx)(
97 struct rte_mbuf **pkts,
101 * Input port stats get
104 * Handle to output port instance
106 * Handle to port_in stats struct to copy data
108 * Flag indicating that stats should be cleared after read
111 * Error code or 0 on success.
113 typedef int (*rte_port_in_op_stats_read)(
115 struct rte_port_in_stats *stats,
118 /** Input port interface defining the input port operation */
119 struct rte_port_in_ops {
120 rte_port_in_op_create f_create; /**< Create */
121 rte_port_in_op_free f_free; /**< Free */
122 rte_port_in_op_rx f_rx; /**< Packet RX (packet burst) */
123 rte_port_in_op_stats_read f_stats; /**< Stats */
130 /** Output port statistics */
131 struct rte_port_out_stats {
133 uint64_t n_pkts_drop;
140 * Parameters for output port creation
142 * CPU socket ID (e.g. for memory allocation purpose)
144 * Handle to output port instance
146 typedef void* (*rte_port_out_op_create)(void *params, int socket_id);
152 * Handle to output port instance
154 * 0 on success, error code otherwise
156 typedef int (*rte_port_out_op_free)(void *port);
159 * Output port single packet TX
162 * Handle to output port instance
166 * 0 on success, error code otherwise
168 typedef int (*rte_port_out_op_tx)(
170 struct rte_mbuf *pkt);
173 * Output port packet burst TX
176 * Handle to output port instance
178 * Burst of input packets specified as array of up to 64 pointers to struct
181 * 64-bit bitmask specifying which packets in the input burst are valid. When
182 * pkts_mask bit n is set, then element n of pkts array is pointing to a
183 * valid packet. Otherwise, element n of pkts array will not be accessed.
185 * 0 on success, error code otherwise
187 typedef int (*rte_port_out_op_tx_bulk)(
189 struct rte_mbuf **pkt,
196 * Handle to output port instance
198 * 0 on success, error code otherwise
200 typedef int (*rte_port_out_op_flush)(void *port);
203 * Output port stats read
206 * Handle to output port instance
208 * Handle to port_out stats struct to copy data
210 * Flag indicating that stats should be cleared after read
213 * Error code or 0 on success.
215 typedef int (*rte_port_out_op_stats_read)(
217 struct rte_port_out_stats *stats,
220 /** Output port interface defining the output port operation */
221 struct rte_port_out_ops {
222 rte_port_out_op_create f_create; /**< Create */
223 rte_port_out_op_free f_free; /**< Free */
224 rte_port_out_op_tx f_tx; /**< Packet TX (single packet) */
225 rte_port_out_op_tx_bulk f_tx_bulk; /**< Packet TX (packet burst) */
226 rte_port_out_op_flush f_flush; /**< Flush */
227 rte_port_out_op_stats_read f_stats; /**< Stats */