update Intel copyright years to 2014
[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 #include <rte_mbuf.h>
51
52 #include <exec-env/rte_kni_common.h>
53
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
57
58 struct rte_kni;
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  * Allocate KNI interface according to the port id, mbuf size, mbuf pool,
94  * configurations and callbacks for kernel requests.The KNI interface created
95  * in the kernel space is the net interface the traditional Linux application
96  * talking to.
97  *
98  * @param pktmbuf_pool
99  *  The mempool for allocting mbufs for packets.
100  * @param conf
101  *  The pointer to the configurations of the KNI device.
102  * @param ops
103  *  The pointer to the callbacks for the KNI kernel requests.
104  *
105  * @return
106  *  - The pointer to the context of a KNI interface.
107  *  - NULL indicate error.
108  */
109 extern struct rte_kni *rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
110                                      const struct rte_kni_conf *conf,
111                                      struct rte_kni_ops *ops);
112
113 /**
114  * It create a KNI device for specific port.
115  *
116  * Note: It is deprecated and just for backward compatibility.
117  *
118  * @param port_id
119  *  Port ID.
120  * @param mbuf_size
121  *  mbuf size.
122  * @param pktmbuf_pool
123  *  The mempool for allocting mbufs for packets.
124  * @param ops
125  *  The pointer to the callbacks for the KNI kernel requests.
126  *
127  * @return
128  *  - The pointer to the context of a KNI interface.
129  *  - NULL indicate error.
130  */
131 extern struct rte_kni *rte_kni_create(uint8_t port_id,
132                                       unsigned mbuf_size,
133                                       struct rte_mempool *pktmbuf_pool,
134                                       struct rte_kni_ops *ops) \
135                                       __attribute__ ((deprecated));
136
137 /**
138  * Release KNI interface according to the context. It will also release the
139  * paired KNI interface in kernel space. All processing on the specific KNI
140  * context need to be stopped before calling this interface.
141  *
142  * @param kni
143  *  The pointer to the context of an existant KNI interface.
144  *
145  * @return
146  *  - 0 indicates success.
147  *  - negative value indicates failure.
148  */
149 extern int rte_kni_release(struct rte_kni *kni);
150
151 /**
152  * It is used to handle the request mbufs sent from kernel space. 
153  * Then analyzes it and calls the specific actions for the specific requests.
154  * Finally constructs the response mbuf and puts it back to the resp_q.
155  *
156  * @param kni
157  *  The pointer to the context of an existant KNI interface.
158  *
159  * @return
160  *  - 0 
161  *  - negative value indicates failure.
162  */
163 extern int rte_kni_handle_request(struct rte_kni *kni);
164
165 /**
166  * Retrieve a burst of packets from a KNI interface. The retrieved packets are
167  * stored in rte_mbuf structures whose pointers are supplied in the array of
168  * mbufs, and the maximum number is indicated by num. It handles the freeing of
169  * the mbufs in the free queue of KNI interface.
170  *
171  * @param kni
172  *  The KNI interface context.
173  * @param mbufs
174  *  The array to store the pointers of mbufs.
175  * @param num
176  *  The maximum number per burst.
177  *
178  * @return
179  *  The actual number of packets retrieved.
180  */
181 extern unsigned rte_kni_rx_burst(struct rte_kni *kni,
182                 struct rte_mbuf **mbufs, unsigned num);
183
184 /**
185  * Send a burst of packets to a KNI interface. The packets to be sent out are
186  * stored in rte_mbuf structures whose pointers are supplied in the array of
187  * mbufs, and the maximum number is indicated by num. It handles allocating
188  * the mbufs for KNI interface alloc queue.
189  *
190  * @param kni
191  *  The KNI interface context.
192  * @param mbufs
193  *  The array to store the pointers of mbufs.
194  * @param num
195  *  The maximum number per burst.
196  *
197  * @return
198  *  The actual number of packets sent.
199  */
200 extern unsigned rte_kni_tx_burst(struct rte_kni *kni,
201                 struct rte_mbuf **mbufs, unsigned num);
202
203 /**
204  * Get the port id from KNI interface.
205  *
206  * Note: It is deprecated and just for backward compatibility.
207  *
208  * @param kni
209  *  The KNI interface context.
210  *
211  * @return
212  *  On success: The port id.
213  *  On failure: ~0x0
214  */
215 extern uint8_t rte_kni_get_port_id(struct rte_kni *kni) \
216                                 __attribute__ ((deprecated));
217
218 /**
219  * Get the KNI context of its name.
220  *
221  * @param name
222  *  pointer to the KNI device name.
223  *
224  * @return
225  *  On success: Pointer to KNI interface.
226  *  On failure: NULL.
227  */
228 extern struct rte_kni *rte_kni_get(const char *name);
229
230 /**
231  * Get the KNI context of the specific port.
232  *
233  * Note: It is deprecated and just for backward compatibility.
234  *
235  * @param port_id
236  *  the port id.
237  *
238  * @return 
239  *  On success: Pointer to KNI interface.
240  *  On failure: NULL
241  */
242 extern struct rte_kni *rte_kni_info_get(uint8_t port_id) \
243                                 __attribute__ ((deprecated));
244
245 /**
246  * Register KNI request handling for a specified port,and it can
247  * be called by master process or slave process.
248  *
249  * @param kni 
250  *  pointer to struct rte_kni. 
251  * @param ops 
252  *  ponter to struct rte_kni_ops.
253  *
254  * @return
255  *  On success: 0
256  *  On failure: -1
257  */
258 extern int rte_kni_register_handlers(struct rte_kni *kni,
259                         struct rte_kni_ops *ops);
260
261 /**
262  *  Unregister KNI request handling for a specified port.
263  * 
264  *  @param kni 
265  *   pointer to struct rte_kni. 
266  *
267  *  @return
268  *   On success: 0
269  *   On failure: -1
270  */
271 extern int rte_kni_unregister_handlers(struct rte_kni *kni);
272
273 #ifdef __cplusplus
274 }
275 #endif
276
277 #endif /* _RTE_KNI_H_ */
278