kni: remove inclusion of mbuf header
[dpdk.git] / lib / librte_kni / rte_kni.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 _RTE_KNI_H_
35 #define _RTE_KNI_H_
36
37 /**
38  * @file
39  * RTE KNI
40  *
41  * The KNI library provides the ability to create and destroy kernel NIC
42  * interfaces that may be used by the RTE application to receive/transmit
43  * packets from/to Linux kernel net interfaces.
44  *
45  * This library provide two APIs to burst receive packets from KNI interfaces,
46  * and burst transmit packets to KNI interfaces.
47  */
48
49 #include <rte_pci.h>
50
51 #include <exec-env/rte_kni_common.h>
52
53 #ifdef __cplusplus
54 extern "C" {
55 #endif
56
57 struct rte_kni;
58 struct rte_mbuf;
59
60 /**
61  * Structure which has the function pointers for KNI interface.
62  */
63 struct rte_kni_ops {
64         uint8_t port_id; /* Port ID */
65
66         /* Pointer to function of changing MTU */
67         int (*change_mtu)(uint8_t port_id, unsigned new_mtu);
68
69         /* Pointer to function of configuring network interface */
70         int (*config_network_if)(uint8_t port_id, uint8_t if_up);
71 };
72
73 /**
74  * Structure for configuring KNI device.
75  */
76 struct rte_kni_conf {
77         /*
78          * KNI name which will be used in relevant network device.
79          * Let the name as short as possible, as it will be part of
80          * memzone name.
81          */
82         char name[RTE_KNI_NAMESIZE];
83         uint32_t core_id;   /* Core ID to bind kernel thread on */
84         uint16_t group_id;  /* Group ID */
85         unsigned mbuf_size; /* mbuf size */
86         struct rte_pci_addr addr;
87         struct rte_pci_id id;
88
89         uint8_t force_bind : 1; /* Flag to bind kernel thread */
90 };
91
92 /**
93  * Initialize and preallocate KNI subsystem
94  *
95  * This function is to be executed on the MASTER lcore only, after EAL
96  * initialization and before any KNI interface is attempted to be
97  * allocated
98  *
99  * @param max_kni_ifaces
100  *  The maximum number of KNI interfaces that can coexist concurrently
101  */
102 extern void rte_kni_init(unsigned int max_kni_ifaces);
103
104
105 /**
106  * Allocate KNI interface according to the port id, mbuf size, mbuf pool,
107  * configurations and callbacks for kernel requests.The KNI interface created
108  * in the kernel space is the net interface the traditional Linux application
109  * talking to.
110  *
111  * The rte_kni_alloc shall not be called before rte_kni_init() has been
112  * called. rte_kni_alloc is thread safe.
113  *
114  * @param pktmbuf_pool
115  *  The mempool for allocting mbufs for packets.
116  * @param conf
117  *  The pointer to the configurations of the KNI device.
118  * @param ops
119  *  The pointer to the callbacks for the KNI kernel requests.
120  *
121  * @return
122  *  - The pointer to the context of a KNI interface.
123  *  - NULL indicate error.
124  */
125 extern struct rte_kni *rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
126                                      const struct rte_kni_conf *conf,
127                                      struct rte_kni_ops *ops);
128
129 /**
130  * It create a KNI device for specific port.
131  *
132  * Note: It is deprecated and just for backward compatibility.
133  *
134  * @param port_id
135  *  Port ID.
136  * @param mbuf_size
137  *  mbuf size.
138  * @param pktmbuf_pool
139  *  The mempool for allocting mbufs for packets.
140  * @param ops
141  *  The pointer to the callbacks for the KNI kernel requests.
142  *
143  * @return
144  *  - The pointer to the context of a KNI interface.
145  *  - NULL indicate error.
146  */
147 extern struct rte_kni *rte_kni_create(uint8_t port_id,
148                                       unsigned mbuf_size,
149                                       struct rte_mempool *pktmbuf_pool,
150                                       struct rte_kni_ops *ops) \
151                                       __attribute__ ((deprecated));
152
153 /**
154  * Release KNI interface according to the context. It will also release the
155  * paired KNI interface in kernel space. All processing on the specific KNI
156  * context need to be stopped before calling this interface.
157  *
158  * rte_kni_release is thread safe.
159  *
160  * @param kni
161  *  The pointer to the context of an existent KNI interface.
162  *
163  * @return
164  *  - 0 indicates success.
165  *  - negative value indicates failure.
166  */
167 extern int rte_kni_release(struct rte_kni *kni);
168
169 /**
170  * It is used to handle the request mbufs sent from kernel space.
171  * Then analyzes it and calls the specific actions for the specific requests.
172  * Finally constructs the response mbuf and puts it back to the resp_q.
173  *
174  * @param kni
175  *  The pointer to the context of an existent KNI interface.
176  *
177  * @return
178  *  - 0
179  *  - negative value indicates failure.
180  */
181 extern int rte_kni_handle_request(struct rte_kni *kni);
182
183 /**
184  * Retrieve a burst of packets from a KNI interface. The retrieved packets are
185  * stored in rte_mbuf structures whose pointers are supplied in the array of
186  * mbufs, and the maximum number is indicated by num. It handles the freeing of
187  * the mbufs in the free queue of KNI interface.
188  *
189  * @param kni
190  *  The KNI interface context.
191  * @param mbufs
192  *  The array to store the pointers of mbufs.
193  * @param num
194  *  The maximum number per burst.
195  *
196  * @return
197  *  The actual number of packets retrieved.
198  */
199 extern unsigned rte_kni_rx_burst(struct rte_kni *kni,
200                 struct rte_mbuf **mbufs, unsigned num);
201
202 /**
203  * Send a burst of packets to a KNI interface. The packets to be sent out are
204  * stored in rte_mbuf structures whose pointers are supplied in the array of
205  * mbufs, and the maximum number is indicated by num. It handles allocating
206  * the mbufs for KNI interface alloc queue.
207  *
208  * @param kni
209  *  The KNI interface context.
210  * @param mbufs
211  *  The array to store the pointers of mbufs.
212  * @param num
213  *  The maximum number per burst.
214  *
215  * @return
216  *  The actual number of packets sent.
217  */
218 extern unsigned rte_kni_tx_burst(struct rte_kni *kni,
219                 struct rte_mbuf **mbufs, unsigned num);
220
221 /**
222  * Get the port id from KNI interface.
223  *
224  * Note: It is deprecated and just for backward compatibility.
225  *
226  * @param kni
227  *  The KNI interface context.
228  *
229  * @return
230  *  On success: The port id.
231  *  On failure: ~0x0
232  */
233 extern uint8_t rte_kni_get_port_id(struct rte_kni *kni) \
234                                 __attribute__ ((deprecated));
235
236 /**
237  * Get the KNI context of its name.
238  *
239  * @param name
240  *  pointer to the KNI device name.
241  *
242  * @return
243  *  On success: Pointer to KNI interface.
244  *  On failure: NULL.
245  */
246 extern struct rte_kni *rte_kni_get(const char *name);
247
248 /**
249  * Get the KNI context of the specific port.
250  *
251  * Note: It is deprecated and just for backward compatibility.
252  *
253  * @param port_id
254  *  the port id.
255  *
256  * @return
257  *  On success: Pointer to KNI interface.
258  *  On failure: NULL
259  */
260 extern struct rte_kni *rte_kni_info_get(uint8_t port_id) \
261                                 __attribute__ ((deprecated));
262
263 /**
264  * Register KNI request handling for a specified port,and it can
265  * be called by master process or slave process.
266  *
267  * @param kni
268  *  pointer to struct rte_kni.
269  * @param ops
270  *  ponter to struct rte_kni_ops.
271  *
272  * @return
273  *  On success: 0
274  *  On failure: -1
275  */
276 extern int rte_kni_register_handlers(struct rte_kni *kni,
277                         struct rte_kni_ops *ops);
278
279 /**
280  *  Unregister KNI request handling for a specified port.
281  *
282  *  @param kni
283  *   pointer to struct rte_kni.
284  *
285  *  @return
286  *   On success: 0
287  *   On failure: -1
288  */
289 extern int rte_kni_unregister_handlers(struct rte_kni *kni);
290
291 /**
292  *  close KNI device.
293  *
294  *  @param void
295  *
296  *  @return
297  *   void
298  */
299 extern void rte_kni_close(void);
300
301 #ifdef __cplusplus
302 }
303 #endif
304
305 #endif /* _RTE_KNI_H_ */
306