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 (port_id >= rte_eth_dev_count())
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 (port_id >= rte_eth_dev_count())
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;
110 /* Check input params */
111 if ((name == NULL) ||
116 mempool = mempool_find(params->mempool_name);
117 link = link_find(params->link_name);
118 if ((mempool == NULL) ||
122 /* Resource create */
123 rte_eth_dev_info_get(link->port_id, &dev_info);
125 memset(&kni_conf, 0, sizeof(kni_conf));
126 snprintf(kni_conf.name, RTE_KNI_NAMESIZE, "%s", name);
127 kni_conf.force_bind = params->force_bind;
128 kni_conf.core_id = params->thread_id;
129 kni_conf.group_id = link->port_id;
130 kni_conf.mbuf_size = mempool->buffer_size;
131 kni_conf.addr = dev_info.pci_dev->addr;
132 kni_conf.id = dev_info.pci_dev->id;
134 memset(&kni_ops, 0, sizeof(kni_ops));
135 kni_ops.port_id = link->port_id;
136 kni_ops.config_network_if = kni_config_network_interface;
137 kni_ops.change_mtu = kni_change_mtu;
139 k = rte_kni_alloc(mempool->m, &kni_conf, &kni_ops);
143 /* Node allocation */
144 kni = calloc(1, sizeof(struct kni));
149 strncpy(kni->name, name, sizeof(kni->name));
152 /* Node add to list */
153 TAILQ_INSERT_TAIL(&kni_list, kni, node);
159 kni_handle_request(void)
163 TAILQ_FOREACH(kni, &kni_list, node)
164 rte_kni_handle_request(kni->k);