4 * Copyright(c) 2010-2014 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 provides two APIs to burst receive packets from KNI interfaces,
46 * and burst transmit packets to KNI interfaces.
50 #include <rte_memory.h>
51 #include <rte_mempool.h>
53 #include <exec-env/rte_kni_common.h>
63 * Structure which has the function pointers for KNI interface.
66 uint8_t port_id; /* Port ID */
68 /* Pointer to function of changing MTU */
69 int (*change_mtu)(uint8_t port_id, unsigned new_mtu);
71 /* Pointer to function of configuring network interface */
72 int (*config_network_if)(uint8_t port_id, uint8_t if_up);
76 * Structure for configuring KNI device.
80 * KNI name which will be used in relevant network device.
81 * Let the name as short as possible, as it will be part of
84 char name[RTE_KNI_NAMESIZE];
85 uint32_t core_id; /* Core ID to bind kernel thread on */
86 uint16_t group_id; /* Group ID */
87 unsigned mbuf_size; /* mbuf size */
88 struct rte_pci_addr addr;
92 uint8_t force_bind : 1; /* Flag to bind kernel thread */
96 * Initialize and preallocate KNI subsystem
98 * This function is to be executed on the MASTER lcore only, after EAL
99 * initialization and before any KNI interface is attempted to be
102 * @param max_kni_ifaces
103 * The maximum number of KNI interfaces that can coexist concurrently
105 void rte_kni_init(unsigned int max_kni_ifaces);
109 * Allocate KNI interface according to the port id, mbuf size, mbuf pool,
110 * configurations and callbacks for kernel requests.The KNI interface created
111 * in the kernel space is the net interface the traditional Linux application
114 * The rte_kni_alloc shall not be called before rte_kni_init() has been
115 * called. rte_kni_alloc is thread safe.
117 * The mempool should have capacity of more than "2 x KNI_FIFO_COUNT_MAX"
118 * elements for each KNI interface allocated.
120 * @param pktmbuf_pool
121 * The mempool for allocting mbufs for packets.
123 * The pointer to the configurations of the KNI device.
125 * The pointer to the callbacks for the KNI kernel requests.
128 * - The pointer to the context of a KNI interface.
129 * - NULL indicate error.
131 struct rte_kni *rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
132 const struct rte_kni_conf *conf, struct rte_kni_ops *ops);
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.
139 * rte_kni_release is thread safe.
142 * The pointer to the context of an existent KNI interface.
145 * - 0 indicates success.
146 * - negative value indicates failure.
148 int rte_kni_release(struct rte_kni *kni);
151 * It is used to handle the request mbufs sent from kernel space.
152 * Then analyzes it and calls the specific actions for the specific requests.
153 * Finally constructs the response mbuf and puts it back to the resp_q.
156 * The pointer to the context of an existent KNI interface.
160 * - negative value indicates failure.
162 int rte_kni_handle_request(struct rte_kni *kni);
165 * Retrieve a burst of packets from a KNI interface. The retrieved packets are
166 * stored in rte_mbuf structures whose pointers are supplied in the array of
167 * mbufs, and the maximum number is indicated by num. It handles allocating
168 * the mbufs for KNI interface alloc queue.
171 * The KNI interface context.
173 * The array to store the pointers of mbufs.
175 * The maximum number per burst.
178 * The actual number of packets retrieved.
180 unsigned rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs,
184 * Send a burst of packets to a KNI interface. The packets to be sent out 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.
190 * The KNI interface context.
192 * The array to store the pointers of mbufs.
194 * The maximum number per burst.
197 * The actual number of packets sent.
199 unsigned rte_kni_tx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs,
203 * Get the KNI context of its name.
206 * pointer to the KNI device name.
209 * On success: Pointer to KNI interface.
212 struct rte_kni *rte_kni_get(const char *name);
215 * Get the name given to a KNI device
218 * The KNI instance to query
220 * The pointer to the KNI name
222 const char *rte_kni_get_name(const struct rte_kni *kni);
225 * Register KNI request handling for a specified port,and it can
226 * be called by master process or slave process.
229 * pointer to struct rte_kni.
231 * ponter to struct rte_kni_ops.
237 int rte_kni_register_handlers(struct rte_kni *kni, struct rte_kni_ops *ops);
240 * Unregister KNI request handling for a specified port.
243 * pointer to struct rte_kni.
249 int rte_kni_unregister_handlers(struct rte_kni *kni);
254 void rte_kni_close(void);
260 #endif /* _RTE_KNI_H_ */