1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
12 * The KNI library provides the ability to create and destroy kernel NIC
13 * interfaces that may be used by the RTE application to receive/transmit
14 * packets from/to Linux kernel net interfaces.
16 * This library provides two APIs to burst receive packets from KNI interfaces,
17 * and burst transmit packets to KNI interfaces.
21 #include <rte_memory.h>
22 #include <rte_mempool.h>
23 #include <rte_ether.h>
25 #include <exec-env/rte_kni_common.h>
35 * Structure which has the function pointers for KNI interface.
38 uint16_t port_id; /* Port ID */
40 /* Pointer to function of changing MTU */
41 int (*change_mtu)(uint16_t port_id, unsigned int new_mtu);
43 /* Pointer to function of configuring network interface */
44 int (*config_network_if)(uint16_t port_id, uint8_t if_up);
46 /* Pointer to function of configuring mac address */
47 int (*config_mac_address)(uint16_t port_id, uint8_t mac_addr[]);
49 /* Pointer to function of configuring promiscuous mode */
50 int (*config_promiscusity)(uint16_t port_id, uint8_t to_on);
54 * Structure for configuring KNI device.
58 * KNI name which will be used in relevant network device.
59 * Let the name as short as possible, as it will be part of
62 char name[RTE_KNI_NAMESIZE];
63 uint32_t core_id; /* Core ID to bind kernel thread on */
64 uint16_t group_id; /* Group ID */
65 unsigned mbuf_size; /* mbuf size */
66 struct rte_pci_addr addr;
70 uint8_t force_bind : 1; /* Flag to bind kernel thread */
71 char mac_addr[ETHER_ADDR_LEN]; /* MAC address assigned to KNI */
76 * Initialize and preallocate KNI subsystem
78 * This function is to be executed on the MASTER lcore only, after EAL
79 * initialization and before any KNI interface is attempted to be
82 * @param max_kni_ifaces
83 * The maximum number of KNI interfaces that can coexist concurrently
85 void rte_kni_init(unsigned int max_kni_ifaces);
89 * Allocate KNI interface according to the port id, mbuf size, mbuf pool,
90 * configurations and callbacks for kernel requests.The KNI interface created
91 * in the kernel space is the net interface the traditional Linux application
94 * The rte_kni_alloc shall not be called before rte_kni_init() has been
95 * called. rte_kni_alloc is thread safe.
97 * The mempool should have capacity of more than "2 x KNI_FIFO_COUNT_MAX"
98 * elements for each KNI interface allocated.
100 * @param pktmbuf_pool
101 * The mempool for allocating mbufs for packets.
103 * The pointer to the configurations of the KNI device.
105 * The pointer to the callbacks for the KNI kernel requests.
108 * - The pointer to the context of a KNI interface.
109 * - NULL indicate error.
111 struct rte_kni *rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
112 const struct rte_kni_conf *conf, struct rte_kni_ops *ops);
115 * Release KNI interface according to the context. It will also release the
116 * paired KNI interface in kernel space. All processing on the specific KNI
117 * context need to be stopped before calling this interface.
119 * rte_kni_release is thread safe.
122 * The pointer to the context of an existent KNI interface.
125 * - 0 indicates success.
126 * - negative value indicates failure.
128 int rte_kni_release(struct rte_kni *kni);
131 * It is used to handle the request mbufs sent from kernel space.
132 * Then analyzes it and calls the specific actions for the specific requests.
133 * Finally constructs the response mbuf and puts it back to the resp_q.
136 * The pointer to the context of an existent KNI interface.
140 * - negative value indicates failure.
142 int rte_kni_handle_request(struct rte_kni *kni);
145 * Retrieve a burst of packets from a KNI interface. The retrieved packets are
146 * stored in rte_mbuf structures whose pointers are supplied in the array of
147 * mbufs, and the maximum number is indicated by num. It handles allocating
148 * the mbufs for KNI interface alloc queue.
151 * The KNI interface context.
153 * The array to store the pointers of mbufs.
155 * The maximum number per burst.
158 * The actual number of packets retrieved.
160 unsigned rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs,
164 * Send a burst of packets to a KNI interface. The packets to be sent out are
165 * stored in rte_mbuf structures whose pointers are supplied in the array of
166 * mbufs, and the maximum number is indicated by num. It handles the freeing of
167 * the mbufs in the free queue of KNI interface.
170 * The KNI interface context.
172 * The array to store the pointers of mbufs.
174 * The maximum number per burst.
177 * The actual number of packets sent.
179 unsigned rte_kni_tx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs,
183 * Get the KNI context of its name.
186 * pointer to the KNI device name.
189 * On success: Pointer to KNI interface.
192 struct rte_kni *rte_kni_get(const char *name);
195 * Get the name given to a KNI device
198 * The KNI instance to query
200 * The pointer to the KNI name
202 const char *rte_kni_get_name(const struct rte_kni *kni);
205 * Register KNI request handling for a specified port,and it can
206 * be called by master process or slave process.
209 * pointer to struct rte_kni.
211 * pointer to struct rte_kni_ops.
217 int rte_kni_register_handlers(struct rte_kni *kni, struct rte_kni_ops *ops);
220 * Unregister KNI request handling for a specified port.
223 * pointer to struct rte_kni.
229 int rte_kni_unregister_handlers(struct rte_kni *kni);
234 void rte_kni_close(void);
240 #endif /* _RTE_KNI_H_ */