Imported Upstream version 16.04
[deb_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 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_PTR(mbuf, offset)          \
58         (&((uint8_t *)(mbuf))[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))
65
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))
74 /**@}*/
75
76 /*
77  * Port IN
78  *
79  */
80 /** Maximum number of packets read from any input port in a single burst.
81 Cannot be changed. */
82 #define RTE_PORT_IN_BURST_SIZE_MAX                         64
83
84 /** Input port statistics */
85 struct rte_port_in_stats {
86         uint64_t n_pkts_in;
87         uint64_t n_pkts_drop;
88 };
89
90 /**
91  * Input port create
92  *
93  * @param params
94  *   Parameters for input port creation
95  * @param socket_id
96  *   CPU socket ID (e.g. for memory allocation purpose)
97  * @return
98  *   Handle to input port instance
99  */
100 typedef void* (*rte_port_in_op_create)(void *params, int socket_id);
101
102 /**
103  * Input port free
104  *
105  * @param port
106  *   Handle to input port instance
107  * @return
108  *   0 on success, error code otherwise
109  */
110 typedef int (*rte_port_in_op_free)(void *port);
111
112 /**
113  * Input port packet burst RX
114  *
115  * @param port
116  *   Handle to input port instance
117  * @param pkts
118  *   Burst of input packets
119  * @param n_pkts
120  *   Number of packets in the input burst
121  * @return
122  *   0 on success, error code otherwise
123  */
124 typedef int (*rte_port_in_op_rx)(
125         void *port,
126         struct rte_mbuf **pkts,
127         uint32_t n_pkts);
128
129 /**
130  * Input port stats get
131  *
132  * @param port
133  *   Handle to output port instance
134  * @param stats
135  *   Handle to port_in stats struct to copy data
136  * @param clear
137  *   Flag indicating that stats should be cleared after read
138  *
139  * @return
140  *   Error code or 0 on success.
141  */
142 typedef int (*rte_port_in_op_stats_read)(
143                 void *port,
144                 struct rte_port_in_stats *stats,
145                 int clear);
146
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 */
153 };
154
155 /*
156  * Port OUT
157  *
158  */
159 /** Output port statistics */
160 struct rte_port_out_stats {
161         uint64_t n_pkts_in;
162         uint64_t n_pkts_drop;
163 };
164
165 /**
166  * Output port create
167  *
168  * @param params
169  *   Parameters for output port creation
170  * @param socket_id
171  *   CPU socket ID (e.g. for memory allocation purpose)
172  * @return
173  *   Handle to output port instance
174  */
175 typedef void* (*rte_port_out_op_create)(void *params, int socket_id);
176
177 /**
178  * Output port free
179  *
180  * @param port
181  *   Handle to output port instance
182  * @return
183  *   0 on success, error code otherwise
184  */
185 typedef int (*rte_port_out_op_free)(void *port);
186
187 /**
188  * Output port single packet TX
189  *
190  * @param port
191  *   Handle to output port instance
192  * @param pkt
193  *   Input packet
194  * @return
195  *   0 on success, error code otherwise
196  */
197 typedef int (*rte_port_out_op_tx)(
198         void *port,
199         struct rte_mbuf *pkt);
200
201 /**
202  * Output port packet burst TX
203  *
204  * @param port
205  *   Handle to output port instance
206  * @param pkts
207  *   Burst of input packets specified as array of up to 64 pointers to struct
208  *   rte_mbuf
209  * @param pkts_mask
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.
213  * @return
214  *   0 on success, error code otherwise
215  */
216 typedef int (*rte_port_out_op_tx_bulk)(
217         void *port,
218         struct rte_mbuf **pkt,
219         uint64_t pkts_mask);
220
221 /**
222  * Output port flush
223  *
224  * @param port
225  *   Handle to output port instance
226  * @return
227  *   0 on success, error code otherwise
228  */
229 typedef int (*rte_port_out_op_flush)(void *port);
230
231 /**
232  * Output port stats read
233  *
234  * @param port
235  *   Handle to output port instance
236  * @param stats
237  *   Handle to port_out stats struct to copy data
238  * @param clear
239  *   Flag indicating that stats should be cleared after read
240  *
241  * @return
242  *   Error code or 0 on success.
243  */
244 typedef int (*rte_port_out_op_stats_read)(
245                 void *port,
246                 struct rte_port_out_stats *stats,
247                 int clear);
248
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 */
257 };
258
259 #ifdef __cplusplus
260 }
261 #endif
262
263 #endif