port: remove an ethdev writer implementation
[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 /*
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 /**
85  * Input port create
86  *
87  * @param params
88  *   Parameters for input port creation
89  * @param socket_id
90  *   CPU socket ID (e.g. for memory allocation purpose)
91  * @return
92  *   Handle to input port instance
93  */
94 typedef void* (*rte_port_in_op_create)(void *params, int socket_id);
95
96 /**
97  * Input port free
98  *
99  * @param port
100  *   Handle to input port instance
101  * @return
102  *   0 on success, error code otherwise
103  */
104 typedef int (*rte_port_in_op_free)(void *port);
105
106 /**
107  * Input port packet burst RX
108  *
109  * @param port
110  *   Handle to input port instance
111  * @param pkts
112  *   Burst of input packets
113  * @param n_pkts
114  *   Number of packets in the input burst
115  * @return
116  *   0 on success, error code otherwise
117  */
118 typedef int (*rte_port_in_op_rx)(
119         void *port,
120         struct rte_mbuf **pkts,
121         uint32_t n_pkts);
122
123 /** Input port interface defining the input port operation */
124 struct rte_port_in_ops {
125         rte_port_in_op_create f_create; /**< Create */
126         rte_port_in_op_free f_free;     /**< Free */
127         rte_port_in_op_rx f_rx;         /**< Packet RX (packet burst) */
128 };
129
130 /*
131  * Port OUT
132  *
133  */
134 /**
135  * Output port create
136  *
137  * @param params
138  *   Parameters for output port creation
139  * @param socket_id
140  *   CPU socket ID (e.g. for memory allocation purpose)
141  * @return
142  *   Handle to output port instance
143  */
144 typedef void* (*rte_port_out_op_create)(void *params, int socket_id);
145
146 /**
147  * Output port free
148  *
149  * @param port
150  *   Handle to output port instance
151  * @return
152  *   0 on success, error code otherwise
153  */
154 typedef int (*rte_port_out_op_free)(void *port);
155
156 /**
157  * Output port single packet TX
158  *
159  * @param port
160  *   Handle to output port instance
161  * @param pkt
162  *   Input packet
163  * @return
164  *   0 on success, error code otherwise
165  */
166 typedef int (*rte_port_out_op_tx)(
167         void *port,
168         struct rte_mbuf *pkt);
169
170 /**
171  * Output port packet burst TX
172  *
173  * @param port
174  *   Handle to output port instance
175  * @param pkts
176  *   Burst of input packets specified as array of up to 64 pointers to struct
177  *   rte_mbuf
178  * @param pkts_mask
179  *   64-bit bitmask specifying which packets in the input burst are valid. When
180  *   pkts_mask bit n is set, then element n of pkts array is pointing to a
181  *   valid packet. Otherwise, element n of pkts array will not be accessed.
182  * @return
183  *   0 on success, error code otherwise
184  */
185 typedef int (*rte_port_out_op_tx_bulk)(
186         void *port,
187         struct rte_mbuf **pkt,
188         uint64_t pkts_mask);
189
190 /**
191  * Output port flush
192  *
193  * @param port
194  *   Handle to output port instance
195  * @return
196  *   0 on success, error code otherwise
197  */
198 typedef int (*rte_port_out_op_flush)(void *port);
199
200 /** Output port interface defining the output port operation */
201 struct rte_port_out_ops {
202         rte_port_out_op_create f_create;   /**< Create */
203         rte_port_out_op_free f_free;       /**< Free */
204         rte_port_out_op_tx f_tx;           /**< Packet TX (single packet) */
205         rte_port_out_op_tx_bulk f_tx_bulk; /**< Packet TX (packet burst) */
206         rte_port_out_op_flush f_flush;     /**< Flush */
207 };
208
209 #ifdef __cplusplus
210 }
211 #endif
212
213 #endif