35b2d13fd6
Add 'RTE_' prefix to defines: - rename ETHER_ADDR_LEN as RTE_ETHER_ADDR_LEN. - rename ETHER_TYPE_LEN as RTE_ETHER_TYPE_LEN. - rename ETHER_CRC_LEN as RTE_ETHER_CRC_LEN. - rename ETHER_HDR_LEN as RTE_ETHER_HDR_LEN. - rename ETHER_MIN_LEN as RTE_ETHER_MIN_LEN. - rename ETHER_MAX_LEN as RTE_ETHER_MAX_LEN. - rename ETHER_MTU as RTE_ETHER_MTU. - rename ETHER_MAX_VLAN_FRAME_LEN as RTE_ETHER_MAX_VLAN_FRAME_LEN. - rename ETHER_MAX_VLAN_ID as RTE_ETHER_MAX_VLAN_ID. - rename ETHER_MAX_JUMBO_FRAME_LEN as RTE_ETHER_MAX_JUMBO_FRAME_LEN. - rename ETHER_MIN_MTU as RTE_ETHER_MIN_MTU. - rename ETHER_LOCAL_ADMIN_ADDR as RTE_ETHER_LOCAL_ADMIN_ADDR. - rename ETHER_GROUP_ADDR as RTE_ETHER_GROUP_ADDR. - rename ETHER_TYPE_IPv4 as RTE_ETHER_TYPE_IPv4. - rename ETHER_TYPE_IPv6 as RTE_ETHER_TYPE_IPv6. - rename ETHER_TYPE_ARP as RTE_ETHER_TYPE_ARP. - rename ETHER_TYPE_VLAN as RTE_ETHER_TYPE_VLAN. - rename ETHER_TYPE_RARP as RTE_ETHER_TYPE_RARP. - rename ETHER_TYPE_QINQ as RTE_ETHER_TYPE_QINQ. - rename ETHER_TYPE_ETAG as RTE_ETHER_TYPE_ETAG. - rename ETHER_TYPE_1588 as RTE_ETHER_TYPE_1588. - rename ETHER_TYPE_SLOW as RTE_ETHER_TYPE_SLOW. - rename ETHER_TYPE_TEB as RTE_ETHER_TYPE_TEB. - rename ETHER_TYPE_LLDP as RTE_ETHER_TYPE_LLDP. - rename ETHER_TYPE_MPLS as RTE_ETHER_TYPE_MPLS. - rename ETHER_TYPE_MPLSM as RTE_ETHER_TYPE_MPLSM. - rename ETHER_VXLAN_HLEN as RTE_ETHER_VXLAN_HLEN. - rename ETHER_ADDR_FMT_SIZE as RTE_ETHER_ADDR_FMT_SIZE. - rename VXLAN_GPE_TYPE_IPV4 as RTE_VXLAN_GPE_TYPE_IPV4. - rename VXLAN_GPE_TYPE_IPV6 as RTE_VXLAN_GPE_TYPE_IPV6. - rename VXLAN_GPE_TYPE_ETH as RTE_VXLAN_GPE_TYPE_ETH. - rename VXLAN_GPE_TYPE_NSH as RTE_VXLAN_GPE_TYPE_NSH. - rename VXLAN_GPE_TYPE_MPLS as RTE_VXLAN_GPE_TYPE_MPLS. - rename VXLAN_GPE_TYPE_GBP as RTE_VXLAN_GPE_TYPE_GBP. - rename VXLAN_GPE_TYPE_VBNG as RTE_VXLAN_GPE_TYPE_VBNG. - rename ETHER_VXLAN_GPE_HLEN as RTE_ETHER_VXLAN_GPE_HLEN. Do not update the command line library to avoid adding a dependency to librte_net. Signed-off-by: Olivier Matz <olivier.matz@6wind.com> Reviewed-by: Stephen Hemminger <stephen@networkplumber.org> Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com> Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
176 lines
3.1 KiB
C
176 lines
3.1 KiB
C
/* SPDX-License-Identifier: BSD-3-Clause
|
|
* Copyright(c) 2010-2018 Intel Corporation
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
|
|
#include <rte_ethdev.h>
|
|
#include <rte_bus_pci.h>
|
|
#include <rte_string_fns.h>
|
|
|
|
#include "kni.h"
|
|
#include "mempool.h"
|
|
#include "link.h"
|
|
|
|
static struct kni_list kni_list;
|
|
|
|
#ifndef KNI_MAX
|
|
#define KNI_MAX 16
|
|
#endif
|
|
|
|
int
|
|
kni_init(void)
|
|
{
|
|
TAILQ_INIT(&kni_list);
|
|
|
|
#ifdef RTE_LIBRTE_KNI
|
|
rte_kni_init(KNI_MAX);
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct kni *
|
|
kni_find(const char *name)
|
|
{
|
|
struct kni *kni;
|
|
|
|
if (name == NULL)
|
|
return NULL;
|
|
|
|
TAILQ_FOREACH(kni, &kni_list, node)
|
|
if (strcmp(kni->name, name) == 0)
|
|
return kni;
|
|
|
|
return NULL;
|
|
}
|
|
|
|
#ifndef RTE_LIBRTE_KNI
|
|
|
|
struct kni *
|
|
kni_create(const char *name __rte_unused,
|
|
struct kni_params *params __rte_unused)
|
|
{
|
|
return NULL;
|
|
}
|
|
|
|
void
|
|
kni_handle_request(void)
|
|
{
|
|
return;
|
|
}
|
|
|
|
#else
|
|
|
|
static int
|
|
kni_config_network_interface(uint16_t port_id, uint8_t if_up)
|
|
{
|
|
int ret = 0;
|
|
|
|
if (!rte_eth_dev_is_valid_port(port_id))
|
|
return -EINVAL;
|
|
|
|
ret = (if_up) ?
|
|
rte_eth_dev_set_link_up(port_id) :
|
|
rte_eth_dev_set_link_down(port_id);
|
|
|
|
return ret;
|
|
}
|
|
|
|
static int
|
|
kni_change_mtu(uint16_t port_id, unsigned int new_mtu)
|
|
{
|
|
int ret;
|
|
|
|
if (!rte_eth_dev_is_valid_port(port_id))
|
|
return -EINVAL;
|
|
|
|
if (new_mtu > RTE_ETHER_MAX_LEN)
|
|
return -EINVAL;
|
|
|
|
/* Set new MTU */
|
|
ret = rte_eth_dev_set_mtu(port_id, new_mtu);
|
|
if (ret < 0)
|
|
return ret;
|
|
|
|
return 0;
|
|
}
|
|
|
|
struct kni *
|
|
kni_create(const char *name, struct kni_params *params)
|
|
{
|
|
struct rte_eth_dev_info dev_info;
|
|
struct rte_kni_conf kni_conf;
|
|
struct rte_kni_ops kni_ops;
|
|
struct kni *kni;
|
|
struct mempool *mempool;
|
|
struct link *link;
|
|
struct rte_kni *k;
|
|
const struct rte_pci_device *pci_dev;
|
|
const struct rte_bus *bus = NULL;
|
|
|
|
/* Check input params */
|
|
if ((name == NULL) ||
|
|
kni_find(name) ||
|
|
(params == NULL))
|
|
return NULL;
|
|
|
|
mempool = mempool_find(params->mempool_name);
|
|
link = link_find(params->link_name);
|
|
if ((mempool == NULL) ||
|
|
(link == NULL))
|
|
return NULL;
|
|
|
|
/* Resource create */
|
|
rte_eth_dev_info_get(link->port_id, &dev_info);
|
|
|
|
memset(&kni_conf, 0, sizeof(kni_conf));
|
|
strlcpy(kni_conf.name, name, RTE_KNI_NAMESIZE);
|
|
kni_conf.force_bind = params->force_bind;
|
|
kni_conf.core_id = params->thread_id;
|
|
kni_conf.group_id = link->port_id;
|
|
kni_conf.mbuf_size = mempool->buffer_size;
|
|
if (dev_info.device)
|
|
bus = rte_bus_find_by_device(dev_info.device);
|
|
if (bus && !strcmp(bus->name, "pci")) {
|
|
pci_dev = RTE_DEV_TO_PCI(dev_info.device);
|
|
kni_conf.addr = pci_dev->addr;
|
|
kni_conf.id = pci_dev->id;
|
|
}
|
|
|
|
memset(&kni_ops, 0, sizeof(kni_ops));
|
|
kni_ops.port_id = link->port_id;
|
|
kni_ops.config_network_if = kni_config_network_interface;
|
|
kni_ops.change_mtu = kni_change_mtu;
|
|
|
|
k = rte_kni_alloc(mempool->m, &kni_conf, &kni_ops);
|
|
if (k == NULL)
|
|
return NULL;
|
|
|
|
/* Node allocation */
|
|
kni = calloc(1, sizeof(struct kni));
|
|
if (kni == NULL)
|
|
return NULL;
|
|
|
|
/* Node fill in */
|
|
strlcpy(kni->name, name, sizeof(kni->name));
|
|
kni->k = k;
|
|
|
|
/* Node add to list */
|
|
TAILQ_INSERT_TAIL(&kni_list, kni, node);
|
|
|
|
return kni;
|
|
}
|
|
|
|
void
|
|
kni_handle_request(void)
|
|
{
|
|
struct kni *kni;
|
|
|
|
TAILQ_FOREACH(kni, &kni_list, node)
|
|
rte_kni_handle_request(kni->k);
|
|
}
|
|
|
|
#endif
|