1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
8 #include <rte_ethdev.h>
9 #include <rte_bus_pci.h>
10 #include <rte_string_fns.h>
16 static struct kni_list kni_list;
25 TAILQ_INIT(&kni_list);
28 rte_kni_init(KNI_MAX);
35 kni_find(const char *name)
42 TAILQ_FOREACH(kni, &kni_list, node)
43 if (strcmp(kni->name, name) == 0)
49 #ifndef RTE_LIBRTE_KNI
52 kni_create(const char *name __rte_unused,
53 struct kni_params *params __rte_unused)
59 kni_handle_request(void)
67 kni_config_network_interface(uint16_t port_id, uint8_t if_up)
71 if (!rte_eth_dev_is_valid_port(port_id))
75 rte_eth_dev_set_link_up(port_id) :
76 rte_eth_dev_set_link_down(port_id);
82 kni_change_mtu(uint16_t port_id, unsigned int new_mtu)
86 if (!rte_eth_dev_is_valid_port(port_id))
89 if (new_mtu > RTE_ETHER_MAX_LEN)
93 ret = rte_eth_dev_set_mtu(port_id, new_mtu);
101 kni_create(const char *name, struct kni_params *params)
103 struct rte_eth_dev_info dev_info;
104 struct rte_kni_conf kni_conf;
105 struct rte_kni_ops kni_ops;
107 struct mempool *mempool;
110 const struct rte_pci_device *pci_dev;
111 const struct rte_bus *bus = NULL;
114 /* Check input params */
115 if ((name == NULL) ||
120 mempool = mempool_find(params->mempool_name);
121 link = link_find(params->link_name);
122 if ((mempool == NULL) ||
126 /* Resource create */
127 ret = rte_eth_dev_info_get(link->port_id, &dev_info);
131 memset(&kni_conf, 0, sizeof(kni_conf));
132 strlcpy(kni_conf.name, name, RTE_KNI_NAMESIZE);
133 kni_conf.force_bind = params->force_bind;
134 kni_conf.core_id = params->thread_id;
135 kni_conf.group_id = link->port_id;
136 kni_conf.mbuf_size = mempool->buffer_size;
138 bus = rte_bus_find_by_device(dev_info.device);
139 if (bus && !strcmp(bus->name, "pci")) {
140 pci_dev = RTE_DEV_TO_PCI(dev_info.device);
141 kni_conf.addr = pci_dev->addr;
142 kni_conf.id = pci_dev->id;
145 memset(&kni_ops, 0, sizeof(kni_ops));
146 kni_ops.port_id = link->port_id;
147 kni_ops.config_network_if = kni_config_network_interface;
148 kni_ops.change_mtu = kni_change_mtu;
150 k = rte_kni_alloc(mempool->m, &kni_conf, &kni_ops);
154 /* Node allocation */
155 kni = calloc(1, sizeof(struct kni));
160 strlcpy(kni->name, name, sizeof(kni->name));
163 /* Node add to list */
164 TAILQ_INSERT_TAIL(&kni_list, kni, node);
170 kni_handle_request(void)
174 TAILQ_FOREACH(kni, &kni_list, node)
175 rte_kni_handle_request(kni->k);