4 * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
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.
45 * This library provide two APIs to burst receive packets from KNI interfaces,
46 * and burst transmit packets to KNI interfaces.
52 #include <exec-env/rte_kni_common.h>
61 * Structure which has the function pointers for KNI interface.
64 uint8_t port_id; /* Port ID */
66 /* Pointer to function of changing MTU */
67 int (*change_mtu)(uint8_t port_id, unsigned new_mtu);
69 /* Pointer to function of configuring network interface */
70 int (*config_network_if)(uint8_t port_id, uint8_t if_up);
74 * Structure for configuring KNI device.
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
82 char name[RTE_KNI_NAMESIZE];
83 uint16_t group_id; /* Group ID */
84 unsigned mbuf_size; /* mbuf size */
85 struct rte_pci_addr addr;
90 * Allocate KNI interface according to the port id, mbuf size, mbuf pool,
91 * configurations and callbacks for kernel requests.The KNI interface created
92 * in the kernel space is the net interface the traditional Linux application
96 * The mempool for allocting mbufs for packets.
98 * The pointer to the configurations of the KNI device.
100 * The pointer to the callbacks for the KNI kernel requests.
103 * - The pointer to the context of a KNI interface.
104 * - NULL indicate error.
106 extern struct rte_kni *rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
107 const struct rte_kni_conf *conf,
108 struct rte_kni_ops *ops);
111 * It create a KNI device for specific port.
113 * Note: It is deprecated and just for backward compatibility.
119 * @param pktmbuf_pool
120 * The mempool for allocting mbufs for packets.
122 * The pointer to the callbacks for the KNI kernel requests.
125 * - The pointer to the context of a KNI interface.
126 * - NULL indicate error.
128 extern struct rte_kni *rte_kni_create(uint8_t port_id,
130 struct rte_mempool *pktmbuf_pool,
131 struct rte_kni_ops *ops) \
132 __attribute__ ((deprecated));
135 * Release KNI interface according to the context. It will also release the
136 * paired KNI interface in kernel space. All processing on the specific KNI
137 * context need to be stopped before calling this interface.
140 * The pointer to the context of an existant KNI interface.
143 * - 0 indicates success.
144 * - negative value indicates failure.
146 extern int rte_kni_release(struct rte_kni *kni);
149 * It is used to handle the request mbufs sent from kernel space.
150 * Then analyzes it and calls the specific actions for the specific requests.
151 * Finally constructs the response mbuf and puts it back to the resp_q.
154 * The pointer to the context of an existant KNI interface.
158 * - negative value indicates failure.
160 extern int rte_kni_handle_request(struct rte_kni *kni);
163 * Retrieve a burst of packets from a KNI interface. The retrieved packets are
164 * stored in rte_mbuf structures whose pointers are supplied in the array of
165 * mbufs, and the maximum number is indicated by num. It handles the freeing of
166 * the mbufs in the free queue of KNI interface.
169 * The KNI interface context.
171 * The array to store the pointers of mbufs.
173 * The maximum number per burst.
176 * The actual number of packets retrieved.
178 extern unsigned rte_kni_rx_burst(struct rte_kni *kni,
179 struct rte_mbuf **mbufs, unsigned num);
182 * Send a burst of packets to a KNI interface. The packets to be sent out are
183 * stored in rte_mbuf structures whose pointers are supplied in the array of
184 * mbufs, and the maximum number is indicated by num. It handles allocating
185 * the mbufs for KNI interface alloc queue.
188 * The KNI interface context.
190 * The array to store the pointers of mbufs.
192 * The maximum number per burst.
195 * The actual number of packets sent.
197 extern unsigned rte_kni_tx_burst(struct rte_kni *kni,
198 struct rte_mbuf **mbufs, unsigned num);
201 * Get the port id from KNI interface.
203 * Note: It is deprecated and just for backward compatibility.
206 * The KNI interface context.
209 * On success: The port id.
212 extern uint8_t rte_kni_get_port_id(struct rte_kni *kni) \
213 __attribute__ ((deprecated));
216 * Get the KNI context of its name.
219 * pointer to the KNI device name.
222 * On success: Pointer to KNI interface.
225 extern struct rte_kni *rte_kni_get(const char *name);
228 * Get the KNI context of the specific port.
230 * Note: It is deprecated and just for backward compatibility.
236 * On success: Pointer to KNI interface.
239 extern struct rte_kni *rte_kni_info_get(uint8_t port_id) \
240 __attribute__ ((deprecated));
243 * Register KNI request handling for a specified port,and it can
244 * be called by master process or slave process.
247 * pointer to struct rte_kni.
249 * ponter to struct rte_kni_ops.
255 extern int rte_kni_register_handlers(struct rte_kni *kni,
256 struct rte_kni_ops *ops);
259 * Unregister KNI request handling for a specified port.
262 * pointer to struct rte_kni.
268 extern int rte_kni_unregister_handlers(struct rte_kni *kni);
274 #endif /* _RTE_KNI_H_ */