mbuf: move metadata macros to rte_port library
[dpdk.git] / lib / librte_port / rte_port.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #ifndef __INCLUDE_RTE_PORT_H__
35 #define __INCLUDE_RTE_PORT_H__
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41 /**
42  * @file
43  * RTE Port
44  *
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.
47  *
48  ***/
49
50 #include <stdint.h>
51 #include <rte_mbuf.h>
52
53 /**
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
56  */
57 #define RTE_MBUF_METADATA_UINT8(mbuf, offset)              \
58         (((uint8_t *)&(mbuf)[1])[offset])
59 #define RTE_MBUF_METADATA_UINT16(mbuf, offset)             \
60         (((uint16_t *)&(mbuf)[1])[offset/sizeof(uint16_t)])
61 #define RTE_MBUF_METADATA_UINT32(mbuf, offset)             \
62         (((uint32_t *)&(mbuf)[1])[offset/sizeof(uint32_t)])
63 #define RTE_MBUF_METADATA_UINT64(mbuf, offset)             \
64         (((uint64_t *)&(mbuf)[1])[offset/sizeof(uint64_t)])
65
66 #define RTE_MBUF_METADATA_UINT8_PTR(mbuf, offset)          \
67         (&RTE_MBUF_METADATA_UINT8(mbuf, offset))
68 #define RTE_MBUF_METADATA_UINT16_PTR(mbuf, offset)         \
69         (&RTE_MBUF_METADATA_UINT16(mbuf, offset))
70 #define RTE_MBUF_METADATA_UINT32_PTR(mbuf, offset)         \
71         (&RTE_MBUF_METADATA_UINT32(mbuf, offset))
72 #define RTE_MBUF_METADATA_UINT64_PTR(mbuf, offset)         \
73         (&RTE_MBUF_METADATA_UINT64(mbuf, offset))
74
75 /*
76  * Port IN
77  *
78  */
79 /** Maximum number of packets read from any input port in a single burst.
80 Cannot be changed. */
81 #define RTE_PORT_IN_BURST_SIZE_MAX                         64
82
83 /**
84  * Input port create
85  *
86  * @param params
87  *   Parameters for input port creation
88  * @param socket_id
89  *   CPU socket ID (e.g. for memory allocation purpose)
90  * @return
91  *   Handle to input port instance
92  */
93 typedef void* (*rte_port_in_op_create)(void *params, int socket_id);
94
95 /**
96  * Input port free
97  *
98  * @param port
99  *   Handle to input port instance
100  * @return
101  *   0 on success, error code otherwise
102  */
103 typedef int (*rte_port_in_op_free)(void *port);
104
105 /**
106  * Input port packet burst RX
107  *
108  * @param port
109  *   Handle to input port instance
110  * @param pkts
111  *   Burst of input packets
112  * @param n_pkts
113  *   Number of packets in the input burst
114  * @return
115  *   0 on success, error code otherwise
116  */
117 typedef int (*rte_port_in_op_rx)(
118         void *port,
119         struct rte_mbuf **pkts,
120         uint32_t n_pkts);
121
122 /** Input port interface defining the input port operation */
123 struct rte_port_in_ops {
124         rte_port_in_op_create f_create; /**< Create */
125         rte_port_in_op_free f_free;     /**< Free */
126         rte_port_in_op_rx f_rx;         /**< Packet RX (packet burst) */
127 };
128
129 /*
130  * Port OUT
131  *
132  */
133 /**
134  * Output port create
135  *
136  * @param params
137  *   Parameters for output port creation
138  * @param socket_id
139  *   CPU socket ID (e.g. for memory allocation purpose)
140  * @return
141  *   Handle to output port instance
142  */
143 typedef void* (*rte_port_out_op_create)(void *params, int socket_id);
144
145 /**
146  * Output port free
147  *
148  * @param port
149  *   Handle to output port instance
150  * @return
151  *   0 on success, error code otherwise
152  */
153 typedef int (*rte_port_out_op_free)(void *port);
154
155 /**
156  * Output port single packet TX
157  *
158  * @param port
159  *   Handle to output port instance
160  * @param pkt
161  *   Input packet
162  * @return
163  *   0 on success, error code otherwise
164  */
165 typedef int (*rte_port_out_op_tx)(
166         void *port,
167         struct rte_mbuf *pkt);
168
169 /**
170  * Output port packet burst TX
171  *
172  * @param port
173  *   Handle to output port instance
174  * @param pkts
175  *   Burst of input packets specified as array of up to 64 pointers to struct
176  *   rte_mbuf
177  * @param pkts_mask
178  *   64-bit bitmask specifying which packets in the input burst are valid. When
179  *   pkts_mask bit n is set, then element n of pkts array is pointing to a
180  *   valid packet. Otherwise, element n of pkts array will not be accessed.
181  * @return
182  *   0 on success, error code otherwise
183  */
184 typedef int (*rte_port_out_op_tx_bulk)(
185         void *port,
186         struct rte_mbuf **pkt,
187         uint64_t pkts_mask);
188
189 /**
190  * Output port flush
191  *
192  * @param port
193  *   Handle to output port instance
194  * @return
195  *   0 on success, error code otherwise
196  */
197 typedef int (*rte_port_out_op_flush)(void *port);
198
199 /** Output port interface defining the output port operation */
200 struct rte_port_out_ops {
201         rte_port_out_op_create f_create;   /**< Create */
202         rte_port_out_op_free f_free;       /**< Free */
203         rte_port_out_op_tx f_tx;           /**< Packet TX (single packet) */
204         rte_port_out_op_tx_bulk f_tx_bulk; /**< Packet TX (packet burst) */
205         rte_port_out_op_flush f_flush;     /**< Flush */
206 };
207
208 #ifdef __cplusplus
209 }
210 #endif
211
212 #endif