1d763c2ece8edc9f4eeb0a685475663feb899800
[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  * Port IN
55  *
56  */
57 /** Maximum number of packets read from any input port in a single burst.
58 Cannot be changed. */
59 #define RTE_PORT_IN_BURST_SIZE_MAX                         64
60
61 /**
62  * Input port create
63  *
64  * @param params
65  *   Parameters for input port creation
66  * @param socket_id
67  *   CPU socket ID (e.g. for memory allocation purpose)
68  * @return
69  *   Handle to input port instance
70  */
71 typedef void* (*rte_port_in_op_create)(void *params, int socket_id);
72
73 /**
74  * Input port free
75  *
76  * @param port
77  *   Handle to input port instance
78  * @return
79  *   0 on success, error code otherwise
80  */
81 typedef int (*rte_port_in_op_free)(void *port);
82
83 /**
84  * Input port packet burst RX
85  *
86  * @param port
87  *   Handle to input port instance
88  * @param pkts
89  *   Burst of input packets
90  * @param n_pkts
91  *   Number of packets in the input burst
92  * @return
93  *   0 on success, error code otherwise
94  */
95 typedef int (*rte_port_in_op_rx)(
96         void *port,
97         struct rte_mbuf **pkts,
98         uint32_t n_pkts);
99
100 /** Input port interface defining the input port operation */
101 struct rte_port_in_ops {
102         rte_port_in_op_create f_create; /**< Create */
103         rte_port_in_op_free f_free;     /**< Free */
104         rte_port_in_op_rx f_rx;         /**< Packet RX (packet burst) */
105 };
106
107 /*
108  * Port OUT
109  *
110  */
111 /**
112  * Output port create
113  *
114  * @param params
115  *   Parameters for output port creation
116  * @param socket_id
117  *   CPU socket ID (e.g. for memory allocation purpose)
118  * @return
119  *   Handle to output port instance
120  */
121 typedef void* (*rte_port_out_op_create)(void *params, int socket_id);
122
123 /**
124  * Output port free
125  *
126  * @param port
127  *   Handle to output port instance
128  * @return
129  *   0 on success, error code otherwise
130  */
131 typedef int (*rte_port_out_op_free)(void *port);
132
133 /**
134  * Output port single packet TX
135  *
136  * @param port
137  *   Handle to output port instance
138  * @param pkt
139  *   Input packet
140  * @return
141  *   0 on success, error code otherwise
142  */
143 typedef int (*rte_port_out_op_tx)(
144         void *port,
145         struct rte_mbuf *pkt);
146
147 /**
148  * Output port packet burst TX
149  *
150  * @param port
151  *   Handle to output port instance
152  * @param pkts
153  *   Burst of input packets specified as array of up to 64 pointers to struct
154  *   rte_mbuf
155  * @param pkts_mask
156  *   64-bit bitmask specifying which packets in the input burst are valid. When
157  *   pkts_mask bit n is set, then element n of pkts array is pointing to a
158  *   valid packet. Otherwise, element n of pkts array will not be accessed.
159  * @return
160  *   0 on success, error code otherwise
161  */
162 typedef int (*rte_port_out_op_tx_bulk)(
163         void *port,
164         struct rte_mbuf **pkt,
165         uint64_t pkts_mask);
166
167 /**
168  * Output port flush
169  *
170  * @param port
171  *   Handle to output port instance
172  * @return
173  *   0 on success, error code otherwise
174  */
175 typedef int (*rte_port_out_op_flush)(void *port);
176
177 /** Output port interface defining the output port operation */
178 struct rte_port_out_ops {
179         rte_port_out_op_create f_create;   /**< Create */
180         rte_port_out_op_free f_free;       /**< Free */
181         rte_port_out_op_tx f_tx;           /**< Packet TX (single packet) */
182         rte_port_out_op_tx_bulk f_tx_bulk; /**< Packet TX (packet burst) */
183         rte_port_out_op_flush f_flush;     /**< Flush */
184 };
185
186 #ifdef __cplusplus
187 }
188 #endif
189
190 #endif