2017-12-19 15:49:03 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2010-2014 Intel Corporation
|
2012-12-19 23:00:00 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _RTE_KNI_H_
|
|
|
|
#define _RTE_KNI_H_
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* RTE KNI
|
|
|
|
*
|
|
|
|
* The KNI library provides the ability to create and destroy kernel NIC
|
|
|
|
* interfaces that may be used by the RTE application to receive/transmit
|
|
|
|
* packets from/to Linux kernel net interfaces.
|
|
|
|
*
|
2016-11-07 03:20:19 +00:00
|
|
|
* This library provides two APIs to burst receive packets from KNI interfaces,
|
2012-12-19 23:00:00 +00:00
|
|
|
* and burst transmit packets to KNI interfaces.
|
|
|
|
*/
|
|
|
|
|
2013-09-18 10:00:00 +00:00
|
|
|
#include <rte_pci.h>
|
2015-05-25 12:23:54 +00:00
|
|
|
#include <rte_memory.h>
|
|
|
|
#include <rte_mempool.h>
|
2018-01-18 06:12:58 +00:00
|
|
|
#include <rte_ether.h>
|
2012-12-19 23:00:00 +00:00
|
|
|
|
2019-04-01 23:07:12 +00:00
|
|
|
#include <rte_kni_common.h>
|
2013-09-18 10:00:00 +00:00
|
|
|
|
2012-12-19 23:00:00 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
struct rte_kni;
|
2015-04-23 13:03:52 +00:00
|
|
|
struct rte_mbuf;
|
2012-12-19 23:00:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Structure which has the function pointers for KNI interface.
|
|
|
|
*/
|
|
|
|
struct rte_kni_ops {
|
2017-09-29 07:17:24 +00:00
|
|
|
uint16_t port_id; /* Port ID */
|
2013-09-18 10:00:00 +00:00
|
|
|
|
2012-12-19 23:00:00 +00:00
|
|
|
/* Pointer to function of changing MTU */
|
2017-09-29 07:17:24 +00:00
|
|
|
int (*change_mtu)(uint16_t port_id, unsigned int new_mtu);
|
2012-12-19 23:00:00 +00:00
|
|
|
|
|
|
|
/* Pointer to function of configuring network interface */
|
2017-09-29 07:17:24 +00:00
|
|
|
int (*config_network_if)(uint16_t port_id, uint8_t if_up);
|
2018-01-18 06:12:58 +00:00
|
|
|
|
|
|
|
/* Pointer to function of configuring mac address */
|
|
|
|
int (*config_mac_address)(uint16_t port_id, uint8_t mac_addr[]);
|
2018-01-18 06:12:59 +00:00
|
|
|
|
|
|
|
/* Pointer to function of configuring promiscuous mode */
|
|
|
|
int (*config_promiscusity)(uint16_t port_id, uint8_t to_on);
|
2019-08-12 03:06:30 +00:00
|
|
|
|
|
|
|
/* Pointer to function of configuring allmulticast mode */
|
|
|
|
int (*config_allmulticast)(uint16_t port_id, uint8_t to_on);
|
2012-12-19 23:00:00 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-09-18 10:00:00 +00:00
|
|
|
* Structure for configuring KNI device.
|
|
|
|
*/
|
|
|
|
struct rte_kni_conf {
|
|
|
|
/*
|
|
|
|
* KNI name which will be used in relevant network device.
|
|
|
|
* Let the name as short as possible, as it will be part of
|
|
|
|
* memzone name.
|
|
|
|
*/
|
|
|
|
char name[RTE_KNI_NAMESIZE];
|
2013-09-18 10:00:00 +00:00
|
|
|
uint32_t core_id; /* Core ID to bind kernel thread on */
|
2013-09-18 10:00:00 +00:00
|
|
|
uint16_t group_id; /* Group ID */
|
|
|
|
unsigned mbuf_size; /* mbuf size */
|
2019-05-24 16:55:20 +00:00
|
|
|
struct rte_pci_addr addr; /* depreciated */
|
|
|
|
struct rte_pci_id id; /* depreciated */
|
2013-09-18 10:00:00 +00:00
|
|
|
|
2016-09-08 12:25:05 +00:00
|
|
|
__extension__
|
2013-09-18 10:00:00 +00:00
|
|
|
uint8_t force_bind : 1; /* Flag to bind kernel thread */
|
2019-05-21 16:13:05 +00:00
|
|
|
uint8_t mac_addr[RTE_ETHER_ADDR_LEN]; /* MAC address assigned to KNI */
|
2018-01-18 06:13:00 +00:00
|
|
|
uint16_t mtu;
|
2019-10-25 18:30:58 +00:00
|
|
|
uint16_t min_mtu;
|
|
|
|
uint16_t max_mtu;
|
2013-09-18 10:00:00 +00:00
|
|
|
};
|
|
|
|
|
2014-10-21 10:46:55 +00:00
|
|
|
/**
|
|
|
|
* Initialize and preallocate KNI subsystem
|
|
|
|
*
|
2020-10-15 22:57:19 +00:00
|
|
|
* This function is to be executed on the main lcore only, after EAL
|
2014-10-21 10:46:55 +00:00
|
|
|
* initialization and before any KNI interface is attempted to be
|
|
|
|
* allocated
|
|
|
|
*
|
|
|
|
* @param max_kni_ifaces
|
|
|
|
* The maximum number of KNI interfaces that can coexist concurrently
|
2018-09-26 16:21:06 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - 0 indicates success.
|
|
|
|
* - negative value indicates failure.
|
2014-10-21 10:46:55 +00:00
|
|
|
*/
|
2018-09-26 16:21:06 +00:00
|
|
|
int rte_kni_init(unsigned int max_kni_ifaces);
|
2014-10-21 10:46:55 +00:00
|
|
|
|
|
|
|
|
2013-09-18 10:00:00 +00:00
|
|
|
/**
|
|
|
|
* Allocate KNI interface according to the port id, mbuf size, mbuf pool,
|
|
|
|
* configurations and callbacks for kernel requests.The KNI interface created
|
2012-12-19 23:00:00 +00:00
|
|
|
* in the kernel space is the net interface the traditional Linux application
|
|
|
|
* talking to.
|
|
|
|
*
|
2014-10-21 10:46:55 +00:00
|
|
|
* The rte_kni_alloc shall not be called before rte_kni_init() has been
|
|
|
|
* called. rte_kni_alloc is thread safe.
|
|
|
|
*
|
2016-05-21 07:58:36 +00:00
|
|
|
* The mempool should have capacity of more than "2 x KNI_FIFO_COUNT_MAX"
|
|
|
|
* elements for each KNI interface allocated.
|
|
|
|
*
|
2012-12-19 23:00:00 +00:00
|
|
|
* @param pktmbuf_pool
|
2017-11-02 19:30:17 +00:00
|
|
|
* The mempool for allocating mbufs for packets.
|
2013-09-18 10:00:00 +00:00
|
|
|
* @param conf
|
|
|
|
* The pointer to the configurations of the KNI device.
|
|
|
|
* @param ops
|
|
|
|
* The pointer to the callbacks for the KNI kernel requests.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - The pointer to the context of a KNI interface.
|
|
|
|
* - NULL indicate error.
|
|
|
|
*/
|
2016-01-28 14:31:23 +00:00
|
|
|
struct rte_kni *rte_kni_alloc(struct rte_mempool *pktmbuf_pool,
|
|
|
|
const struct rte_kni_conf *conf, struct rte_kni_ops *ops);
|
2013-09-18 10:00:00 +00:00
|
|
|
|
2013-06-03 00:00:00 +00:00
|
|
|
/**
|
2013-09-18 10:00:00 +00:00
|
|
|
* Release KNI interface according to the context. It will also release the
|
|
|
|
* paired KNI interface in kernel space. All processing on the specific KNI
|
2013-06-03 00:00:00 +00:00
|
|
|
* context need to be stopped before calling this interface.
|
|
|
|
*
|
2014-10-21 10:46:55 +00:00
|
|
|
* rte_kni_release is thread safe.
|
|
|
|
*
|
2013-06-03 00:00:00 +00:00
|
|
|
* @param kni
|
2014-05-02 23:42:52 +00:00
|
|
|
* The pointer to the context of an existent KNI interface.
|
2013-06-03 00:00:00 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* - 0 indicates success.
|
|
|
|
* - negative value indicates failure.
|
|
|
|
*/
|
2016-01-28 14:31:23 +00:00
|
|
|
int rte_kni_release(struct rte_kni *kni);
|
2013-06-03 00:00:00 +00:00
|
|
|
|
|
|
|
/**
|
2014-06-03 23:42:50 +00:00
|
|
|
* It is used to handle the request mbufs sent from kernel space.
|
2013-06-03 00:00:00 +00:00
|
|
|
* Then analyzes it and calls the specific actions for the specific requests.
|
|
|
|
* Finally constructs the response mbuf and puts it back to the resp_q.
|
|
|
|
*
|
|
|
|
* @param kni
|
2014-05-02 23:42:52 +00:00
|
|
|
* The pointer to the context of an existent KNI interface.
|
2013-06-03 00:00:00 +00:00
|
|
|
*
|
|
|
|
* @return
|
2014-06-03 23:42:50 +00:00
|
|
|
* - 0
|
2013-06-03 00:00:00 +00:00
|
|
|
* - negative value indicates failure.
|
|
|
|
*/
|
2016-01-28 14:31:23 +00:00
|
|
|
int rte_kni_handle_request(struct rte_kni *kni);
|
2013-06-03 00:00:00 +00:00
|
|
|
|
2012-12-19 23:00:00 +00:00
|
|
|
/**
|
2013-09-18 10:00:00 +00:00
|
|
|
* Retrieve a burst of packets from a KNI interface. The retrieved packets are
|
2012-12-19 23:00:00 +00:00
|
|
|
* stored in rte_mbuf structures whose pointers are supplied in the array of
|
2016-05-21 07:58:35 +00:00
|
|
|
* mbufs, and the maximum number is indicated by num. It handles allocating
|
|
|
|
* the mbufs for KNI interface alloc queue.
|
2012-12-19 23:00:00 +00:00
|
|
|
*
|
|
|
|
* @param kni
|
2013-09-18 10:00:00 +00:00
|
|
|
* The KNI interface context.
|
2012-12-19 23:00:00 +00:00
|
|
|
* @param mbufs
|
|
|
|
* The array to store the pointers of mbufs.
|
|
|
|
* @param num
|
|
|
|
* The maximum number per burst.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* The actual number of packets retrieved.
|
|
|
|
*/
|
2016-01-28 14:31:23 +00:00
|
|
|
unsigned rte_kni_rx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs,
|
|
|
|
unsigned num);
|
2012-12-19 23:00:00 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-18 10:00:00 +00:00
|
|
|
* Send a burst of packets to a KNI interface. The packets to be sent out are
|
2012-12-19 23:00:00 +00:00
|
|
|
* stored in rte_mbuf structures whose pointers are supplied in the array of
|
2016-05-21 07:58:35 +00:00
|
|
|
* mbufs, and the maximum number is indicated by num. It handles the freeing of
|
|
|
|
* the mbufs in the free queue of KNI interface.
|
2012-12-19 23:00:00 +00:00
|
|
|
*
|
|
|
|
* @param kni
|
2013-09-18 10:00:00 +00:00
|
|
|
* The KNI interface context.
|
2012-12-19 23:00:00 +00:00
|
|
|
* @param mbufs
|
|
|
|
* The array to store the pointers of mbufs.
|
|
|
|
* @param num
|
|
|
|
* The maximum number per burst.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* The actual number of packets sent.
|
|
|
|
*/
|
2016-01-28 14:31:23 +00:00
|
|
|
unsigned rte_kni_tx_burst(struct rte_kni *kni, struct rte_mbuf **mbufs,
|
|
|
|
unsigned num);
|
2012-12-19 23:00:00 +00:00
|
|
|
|
2013-09-18 10:00:00 +00:00
|
|
|
/**
|
|
|
|
* Get the KNI context of its name.
|
|
|
|
*
|
|
|
|
* @param name
|
|
|
|
* pointer to the KNI device name.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* On success: Pointer to KNI interface.
|
|
|
|
* On failure: NULL.
|
|
|
|
*/
|
2016-01-28 14:31:23 +00:00
|
|
|
struct rte_kni *rte_kni_get(const char *name);
|
2012-12-19 23:00:00 +00:00
|
|
|
|
2015-05-27 13:47:49 +00:00
|
|
|
/**
|
|
|
|
* Get the name given to a KNI device
|
|
|
|
*
|
|
|
|
* @param kni
|
|
|
|
* The KNI instance to query
|
|
|
|
* @return
|
|
|
|
* The pointer to the KNI name
|
|
|
|
*/
|
2016-01-28 14:31:23 +00:00
|
|
|
const char *rte_kni_get_name(const struct rte_kni *kni);
|
2015-05-27 13:47:49 +00:00
|
|
|
|
2013-06-03 00:00:00 +00:00
|
|
|
/**
|
2013-09-18 10:00:00 +00:00
|
|
|
* Register KNI request handling for a specified port,and it can
|
2020-08-06 17:19:43 +00:00
|
|
|
* be called by primary process or secondary process.
|
2013-06-03 00:00:00 +00:00
|
|
|
*
|
2014-06-03 23:42:50 +00:00
|
|
|
* @param kni
|
|
|
|
* pointer to struct rte_kni.
|
|
|
|
* @param ops
|
2017-11-10 08:24:23 +00:00
|
|
|
* pointer to struct rte_kni_ops.
|
2013-06-03 00:00:00 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* On success: 0
|
|
|
|
* On failure: -1
|
|
|
|
*/
|
2016-01-28 14:31:23 +00:00
|
|
|
int rte_kni_register_handlers(struct rte_kni *kni, struct rte_kni_ops *ops);
|
2013-06-03 00:00:00 +00:00
|
|
|
|
|
|
|
/**
|
2013-09-18 10:00:00 +00:00
|
|
|
* Unregister KNI request handling for a specified port.
|
2014-06-03 23:42:50 +00:00
|
|
|
*
|
|
|
|
* @param kni
|
|
|
|
* pointer to struct rte_kni.
|
2013-06-03 00:00:00 +00:00
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* On success: 0
|
|
|
|
* On failure: -1
|
|
|
|
*/
|
2016-01-28 14:31:23 +00:00
|
|
|
int rte_kni_unregister_handlers(struct rte_kni *kni);
|
2013-06-03 00:00:00 +00:00
|
|
|
|
2018-10-24 22:26:27 +00:00
|
|
|
/**
|
|
|
|
* Update link carrier state for KNI port.
|
|
|
|
*
|
|
|
|
* Update the linkup/linkdown state of a KNI interface in the kernel.
|
|
|
|
*
|
|
|
|
* @param kni
|
|
|
|
* pointer to struct rte_kni.
|
|
|
|
* @param linkup
|
|
|
|
* New link state:
|
|
|
|
* 0 for linkdown.
|
|
|
|
* > 0 for linkup.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* On failure: -1
|
|
|
|
* Previous link state == linkdown: 0
|
|
|
|
* Previous link state == linkup: 1
|
|
|
|
*/
|
2019-06-29 11:58:53 +00:00
|
|
|
__rte_experimental
|
|
|
|
int
|
2018-10-24 22:26:27 +00:00
|
|
|
rte_kni_update_link(struct rte_kni *kni, unsigned int linkup);
|
|
|
|
|
2014-02-12 16:23:56 +00:00
|
|
|
/**
|
2015-06-18 21:43:06 +00:00
|
|
|
* Close KNI device.
|
2014-02-12 16:23:56 +00:00
|
|
|
*/
|
2016-01-28 14:31:23 +00:00
|
|
|
void rte_kni_close(void);
|
2014-02-12 16:23:56 +00:00
|
|
|
|
2012-12-19 23:00:00 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* _RTE_KNI_H_ */
|