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>
15 static struct kni_list kni_list;
24 TAILQ_INIT(&kni_list);
27 rte_kni_init(KNI_MAX);
34 kni_find(const char *name)
41 TAILQ_FOREACH(kni, &kni_list, node)
42 if (strcmp(kni->name, name) == 0)
48 #ifndef RTE_LIBRTE_KNI
51 kni_create(const char *name __rte_unused,
52 struct kni_params *params __rte_unused)
58 kni_handle_request(void)
66 kni_config_network_interface(uint16_t port_id, uint8_t if_up)
70 if (!rte_eth_dev_is_valid_port(port_id))
74 rte_eth_dev_set_link_up(port_id) :
75 rte_eth_dev_set_link_down(port_id);
81 kni_change_mtu(uint16_t port_id, unsigned int new_mtu)
85 if (!rte_eth_dev_is_valid_port(port_id))
88 if (new_mtu > ETHER_MAX_LEN)
92 ret = rte_eth_dev_set_mtu(port_id, new_mtu);
100 kni_create(const char *name, struct kni_params *params)
102 struct rte_eth_dev_info dev_info;
103 struct rte_kni_conf kni_conf;
104 struct rte_kni_ops kni_ops;
106 struct mempool *mempool;
109 const struct rte_pci_device *pci_dev;
110 const struct rte_bus *bus = NULL;
112 /* Check input params */
113 if ((name == NULL) ||
118 mempool = mempool_find(params->mempool_name);
119 link = link_find(params->link_name);
120 if ((mempool == NULL) ||
124 /* Resource create */
125 rte_eth_dev_info_get(link->port_id, &dev_info);
127 memset(&kni_conf, 0, sizeof(kni_conf));
128 snprintf(kni_conf.name, RTE_KNI_NAMESIZE, "%s", name);
129 kni_conf.force_bind = params->force_bind;
130 kni_conf.core_id = params->thread_id;
131 kni_conf.group_id = link->port_id;
132 kni_conf.mbuf_size = mempool->buffer_size;
134 bus = rte_bus_find_by_device(dev_info.device);
135 if (bus && !strcmp(bus->name, "pci")) {
136 pci_dev = RTE_DEV_TO_PCI(dev_info.device);
137 kni_conf.addr = pci_dev->addr;
138 kni_conf.id = pci_dev->id;
141 memset(&kni_ops, 0, sizeof(kni_ops));
142 kni_ops.port_id = link->port_id;
143 kni_ops.config_network_if = kni_config_network_interface;
144 kni_ops.change_mtu = kni_change_mtu;
146 k = rte_kni_alloc(mempool->m, &kni_conf, &kni_ops);
150 /* Node allocation */
151 kni = calloc(1, sizeof(struct kni));
156 strncpy(kni->name, name, sizeof(kni->name));
159 /* Node add to list */
160 TAILQ_INSERT_TAIL(&kni_list, kni, node);
166 kni_handle_request(void)
170 TAILQ_FOREACH(kni, &kni_list, node)
171 rte_kni_handle_request(kni->k);