4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 #ifndef __INCLUDE_RTE_PORT_H__
35 #define __INCLUDE_RTE_PORT_H__
45 * This tool is part of the Intel DPDK Packet Framework tool suite and provides
46 * a standard interface to implement different types of packet ports.
54 * Macros to allow accessing metadata stored in the mbuf headroom
55 * just beyond the end of the mbuf data structure returned by a port
57 #define RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset) \
58 (&((uint8_t *) &(mbuf)[1])[offset])
59 #define RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset) \
60 ((uint16_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
61 #define RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset) \
62 ((uint32_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
63 #define RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset) \
64 ((uint64_t *) RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
66 #define RTE_MBUF_METADATA_UINT8(mbuf, offset) \
67 (*RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset))
68 #define RTE_MBUF_METADATA_UINT16(mbuf, offset) \
69 (*RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset))
70 #define RTE_MBUF_METADATA_UINT32(mbuf, offset) \
71 (*RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset))
72 #define RTE_MBUF_METADATA_UINT64(mbuf, offset) \
73 (*RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset))
80 /** Maximum number of packets read from any input port in a single burst.
82 #define RTE_PORT_IN_BURST_SIZE_MAX 64
84 /** Input port statistics */
85 struct rte_port_in_stats {
94 * Parameters for input port creation
96 * CPU socket ID (e.g. for memory allocation purpose)
98 * Handle to input port instance
100 typedef void* (*rte_port_in_op_create)(void *params, int socket_id);
106 * Handle to input port instance
108 * 0 on success, error code otherwise
110 typedef int (*rte_port_in_op_free)(void *port);
113 * Input port packet burst RX
116 * Handle to input port instance
118 * Burst of input packets
120 * Number of packets in the input burst
122 * 0 on success, error code otherwise
124 typedef int (*rte_port_in_op_rx)(
126 struct rte_mbuf **pkts,
130 * Input port stats get
133 * Handle to output port instance
135 * Handle to port_in stats struct to copy data
137 * Flag indicating that stats should be cleared after read
140 * Error code or 0 on success.
142 typedef int (*rte_port_in_op_stats_read)(
144 struct rte_port_in_stats *stats,
147 /** Input port interface defining the input port operation */
148 struct rte_port_in_ops {
149 rte_port_in_op_create f_create; /**< Create */
150 rte_port_in_op_free f_free; /**< Free */
151 rte_port_in_op_rx f_rx; /**< Packet RX (packet burst) */
152 rte_port_in_op_stats_read f_stats; /**< Stats */
159 /** Output port statistics */
160 struct rte_port_out_stats {
162 uint64_t n_pkts_drop;
169 * Parameters for output port creation
171 * CPU socket ID (e.g. for memory allocation purpose)
173 * Handle to output port instance
175 typedef void* (*rte_port_out_op_create)(void *params, int socket_id);
181 * Handle to output port instance
183 * 0 on success, error code otherwise
185 typedef int (*rte_port_out_op_free)(void *port);
188 * Output port single packet TX
191 * Handle to output port instance
195 * 0 on success, error code otherwise
197 typedef int (*rte_port_out_op_tx)(
199 struct rte_mbuf *pkt);
202 * Output port packet burst TX
205 * Handle to output port instance
207 * Burst of input packets specified as array of up to 64 pointers to struct
210 * 64-bit bitmask specifying which packets in the input burst are valid. When
211 * pkts_mask bit n is set, then element n of pkts array is pointing to a
212 * valid packet. Otherwise, element n of pkts array will not be accessed.
214 * 0 on success, error code otherwise
216 typedef int (*rte_port_out_op_tx_bulk)(
218 struct rte_mbuf **pkt,
225 * Handle to output port instance
227 * 0 on success, error code otherwise
229 typedef int (*rte_port_out_op_flush)(void *port);
232 * Output port stats read
235 * Handle to output port instance
237 * Handle to port_out stats struct to copy data
239 * Flag indicating that stats should be cleared after read
242 * Error code or 0 on success.
244 typedef int (*rte_port_out_op_stats_read)(
246 struct rte_port_out_stats *stats,
249 /** Output port interface defining the output port operation */
250 struct rte_port_out_ops {
251 rte_port_out_op_create f_create; /**< Create */
252 rte_port_out_op_free f_free; /**< Free */
253 rte_port_out_op_tx f_tx; /**< Packet TX (single packet) */
254 rte_port_out_op_tx_bulk f_tx_bulk; /**< Packet TX (packet burst) */
255 rte_port_out_op_flush f_flush; /**< Flush */
256 rte_port_out_op_stats_read f_stats; /**< Stats */