/*
-// Copyright (c) 2010-2017 Intel Corporation
+// Copyright (c) 2010-2020 Intel Corporation
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
#endif
#endif
+#include <sys/ioctl.h>
+#include <net/if.h>
+
#include "prox_port_cfg.h"
#include "prox_globals.h"
#include "log.h"
#include "prox_cksum.h"
#include "stats_irq.h"
#include "prox_compat.h"
+#include "rte_ethdev.h"
struct prox_port_cfg prox_port_cfg[PROX_MAX_PORTS];
rte_atomic32_t lsc;
struct rte_mbuf *mbuf = _m;
#if RTE_VERSION >= RTE_VERSION_NUM(1,8,0,0)
- mbuf->tx_offload = CALC_TX_OL(sizeof(struct ether_hdr), sizeof(struct ipv4_hdr));
+ mbuf->tx_offload = CALC_TX_OL(sizeof(prox_rte_ether_hdr), sizeof(prox_rte_ipv4_hdr));
#else
- mbuf->pkt.vlan_macip.f.l2_len = sizeof(struct ether_hdr);
- mbuf->pkt.vlan_macip.f.l3_len = sizeof(struct ipv4_hdr);
+ mbuf->pkt.vlan_macip.f.l2_len = sizeof(prox_rte_ether_hdr);
+ mbuf->pkt.vlan_macip.f.l3_len = sizeof(prox_rte_ipv4_hdr);
#endif
rte_pktmbuf_init(mp, opaque_arg, mbuf, i);
}\
+static void set_ip_address (char *devname, uint32_t *ip)
+{
+ struct ifreq ifreq;
+ struct sockaddr_in in_addr;
+ int fd, rc;
+
+ memset(&ifreq, 0, sizeof(struct ifreq));
+ memset(&in_addr, 0, sizeof(struct sockaddr_in));
+
+ in_addr.sin_family = AF_INET;
+ in_addr.sin_addr = *(struct in_addr *)ip;
+ fd = socket(in_addr.sin_family, SOCK_DGRAM, 0);
+
+ strncpy(ifreq.ifr_name, devname, IFNAMSIZ);
+ ifreq.ifr_addr = *(struct sockaddr *)&in_addr;
+ rc = ioctl(fd, SIOCSIFADDR, &ifreq);
+ PROX_PANIC(rc < 0, "Failed to set IP address %d on device %s: error = %d\n", *ip, devname, errno);
+ close(fd);
+}
+
/* initialize rte devices and check the number of available ports */
void init_rte_dev(int use_dummy_devices)
{
uint8_t nb_ports, port_id_max;
- int port_id_last;
+ int port_id_last, rc = 0;
struct rte_eth_dev_info dev_info;
const struct rte_pci_device *pci_dev;
- nb_ports = rte_eth_dev_count();
+ for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
+ if (!prox_port_cfg[port_id].active) {
+ continue;
+ }
+ struct prox_port_cfg* port_cfg = &prox_port_cfg[port_id];
+ if (port_cfg->vdev[0]) {
+#if (RTE_VERSION > RTE_VERSION_NUM(17,5,0,1))
+ char name[MAX_NAME_SIZE], tap[MAX_NAME_SIZE];
+ snprintf(tap, MAX_NAME_SIZE, "net_tap%d", port_id);
+ snprintf(name, MAX_NAME_SIZE, "iface=%s", port_cfg->vdev);
+ rc = rte_vdev_init(tap, name);
+#else
+ rc = eth_dev_null_create(tap, name, PROX_RTE_ETHER_MIN_LEN, 0);
+#endif
+ PROX_PANIC(rc != 0, "Unable to create device %s %s\n", "net tap", port_cfg->vdev);
+ int vdev_port_id = rte_eth_dev_count() - 1;
+ PROX_PANIC(vdev_port_id >= PROX_MAX_PORTS, "Too many port defined %d >= %d\n", vdev_port_id, PROX_MAX_PORTS);
+ plog_info("\tCreating device %s, port %d\n", port_cfg->vdev, vdev_port_id);
+ prox_port_cfg[vdev_port_id].active = 1;
+ prox_port_cfg[vdev_port_id].dpdk_mapping = port_id;
+ prox_port_cfg[vdev_port_id].n_txq = 1;
+
+ if (prox_port_cfg[port_id].vlan_tag) {
+ char command[1024];
+ snprintf(prox_port_cfg[vdev_port_id].name, MAX_NAME_SIZE, "%s_%d", port_cfg->vdev, prox_port_cfg[port_id].vlan_tag);
+ sprintf(command, "ip link add link %s name %s type vlan id %d", port_cfg->vdev, prox_port_cfg[vdev_port_id].name, prox_port_cfg[port_id].vlan_tag);
+ system(command);
+ plog_info("Running %s\n", command);
+ plog_info("Using vlan tag %d - added device %s\n", prox_port_cfg[port_id].vlan_tag, prox_port_cfg[vdev_port_id].name);
+ } else
+ strncpy(prox_port_cfg[vdev_port_id].name, port_cfg->vdev, MAX_NAME_SIZE);
+
+ prox_port_cfg[port_id].dpdk_mapping = vdev_port_id;
+ prox_port_cfg[vdev_port_id].ip = rte_be_to_cpu_32(prox_port_cfg[port_id].ip);
+ prox_port_cfg[port_id].ip = 0; // So only vdev has an IP associated
+ prox_port_cfg[vdev_port_id].type = prox_port_cfg[port_id].type;
+ if (prox_port_cfg[vdev_port_id].type == PROX_PORT_MAC_HW) {
+ // If DPDK port MAC set to HW, then make sure the vdev has the same MAC as DPDK port
+ prox_port_cfg[vdev_port_id].type = PROX_PORT_MAC_SET;
+ rte_eth_macaddr_get(port_id, &prox_port_cfg[vdev_port_id].eth_addr);
+ plog_info("\tDPDK port %d MAC address pre-configured to MAC from port %d: "MAC_BYTES_FMT"\n",
+ vdev_port_id, port_id, MAC_BYTES(prox_port_cfg[vdev_port_id].eth_addr.addr_bytes));
+ } else
+ memcpy(&prox_port_cfg[vdev_port_id].eth_addr, &prox_port_cfg[port_id].eth_addr, sizeof(prox_port_cfg[port_id].eth_addr));
+ }
+ }
+ nb_ports = prox_rte_eth_dev_count_avail();
/* get available ports configuration */
PROX_PANIC(use_dummy_devices && nb_ports, "Can't use dummy devices while there are also real ports\n");
char port_name[32] = "0dummy_dev";
for (uint32_t i = 0; i < nb_ports; ++i) {
#if (RTE_VERSION > RTE_VERSION_NUM(17,5,0,1))
- rte_vdev_init(port_name, "size=ETHER_MIN_LEN,copy=0");
+ rte_vdev_init(port_name, "size=64,copy=0");
#else
- eth_dev_null_create(port_name, 0, ETHER_MIN_LEN, 0);
+ eth_dev_null_create(port_name, 0, PROX_RTE_ETHER_MIN_LEN, 0);
#endif
port_name[0]++;
}
port_cfg->max_rxq = dev_info.max_rx_queues;
port_cfg->max_rx_pkt_len = dev_info.max_rx_pktlen;
port_cfg->min_rx_bufsize = dev_info.min_rx_bufsize;
+ port_cfg->min_tx_desc = dev_info.tx_desc_lim.nb_min;
+ port_cfg->max_tx_desc = dev_info.tx_desc_lim.nb_max;
+ port_cfg->min_rx_desc = dev_info.rx_desc_lim.nb_min;
+ port_cfg->max_rx_desc = dev_info.rx_desc_lim.nb_max;
- strncpy(port_cfg->driver_name, dev_info.driver_name, sizeof(port_cfg->driver_name));
+ prox_strncpy(port_cfg->driver_name, dev_info.driver_name, sizeof(port_cfg->driver_name));
plog_info("\tPort %u : driver='%s' tx_queues=%d rx_queues=%d\n", port_id, !strcmp(port_cfg->driver_name, "")? "null" : port_cfg->driver_name, port_cfg->max_txq, port_cfg->max_rxq);
+ plog_info("\tPort %u : %d<=nb_tx_desc<=%d %d<=nb_rx_desc<=%d\n", port_id, port_cfg->min_tx_desc, port_cfg->max_tx_desc, port_cfg->min_rx_desc, port_cfg->max_rx_desc);
if (strncmp(port_cfg->driver_name, "rte_", 4) == 0) {
- strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name + 4, sizeof(port_cfg->short_name));
+ prox_strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name + 4, sizeof(port_cfg->short_name));
} else if (strncmp(port_cfg->driver_name, "net_", 4) == 0) {
- strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name + 4, sizeof(port_cfg->short_name));
+ prox_strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name + 4, sizeof(port_cfg->short_name));
} else {
- strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name, sizeof(port_cfg->short_name));
+ prox_strncpy(port_cfg->short_name, prox_port_cfg[port_id].driver_name, sizeof(port_cfg->short_name));
}
char *ptr;
if ((ptr = strstr(port_cfg->short_name, "_pmd")) != NULL) {
plog_info("\t\tDisabling UDP cksum on vmxnet3\n");
port_cfg->disabled_tx_offload |= DEV_TX_OFFLOAD_UDP_CKSUM;
}
+ // Some OVS versions reports that they support UDP offload and no IPv4 offload, but fails when UDP offload is enabled
+ if ((!strcmp(port_cfg->short_name, "virtio")) &&
+ ((port_cfg->dev_info.tx_offload_capa & DEV_TX_OFFLOAD_IPV4_CKSUM) == 0) &&
+ (port_cfg->dev_info.tx_offload_capa & DEV_TX_OFFLOAD_UDP_CKSUM)) {
+ plog_info("\t\tDisabling UDP cksum on virtio\n");
+ port_cfg->disabled_tx_offload |= DEV_TX_OFFLOAD_UDP_CKSUM;
+ }
}
}
plog_info("VLAN EXTEND | ");
if (port_cfg->dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME)
plog_info("JUMBO FRAME | ");
+#if defined(DEV_RX_OFFLOAD_CRC_STRIP)
if (port_cfg->dev_info.rx_offload_capa & DEV_RX_OFFLOAD_CRC_STRIP)
plog_info("CRC STRIP | ");
+#endif
+#if defined(DEV_RX_OFFLOAD_KEEP_CRC)
+ if (port_cfg->dev_info.rx_offload_capa & DEV_RX_OFFLOAD_KEEP_CRC)
+ plog_info("KEEP CRC | ");
+#endif
if (port_cfg->dev_info.rx_offload_capa & DEV_RX_OFFLOAD_SCATTER)
plog_info("SCATTER | ");
if (port_cfg->dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP)
dummy_pool_name[0]++;
} else {
// Most pmd should now support setting mtu
- if (port_cfg->mtu + ETHER_HDR_LEN + ETHER_CRC_LEN > port_cfg->max_rx_pkt_len) {
+ if (port_cfg->mtu + PROX_RTE_ETHER_HDR_LEN + PROX_RTE_ETHER_CRC_LEN > port_cfg->max_rx_pkt_len) {
plog_info("\t\tMTU is too big for the port, reducing MTU from %d to %d\n", port_cfg->mtu, port_cfg->max_rx_pkt_len);
port_cfg->mtu = port_cfg->max_rx_pkt_len;
}
#if RTE_VERSION >= RTE_VERSION_NUM(2,0,0,0)
port_cfg->port_conf.rx_adv_conf.rss_conf.rss_hf &= port_cfg->dev_info.flow_type_rss_offloads;
#endif
- plog_info("\t\t Enabling RSS rss_hf = 0x%lx (requested 0x%llx)\n", port_cfg->port_conf.rx_adv_conf.rss_conf.rss_hf, ETH_RSS_IP|ETH_RSS_UDP);
+ plog_info("\t\t Enabling RSS rss_hf = 0x%lx (requested 0x%llx, supported 0x%lx)\n", port_cfg->port_conf.rx_adv_conf.rss_conf.rss_hf, ETH_RSS_IP|ETH_RSS_UDP, port_cfg->dev_info.flow_type_rss_offloads);
// rxmode such as hw src strip
#if RTE_VERSION >= RTE_VERSION_NUM(18,8,0,1)
+#if defined (DEV_RX_OFFLOAD_CRC_STRIP)
CONFIGURE_RX_OFFLOAD(DEV_RX_OFFLOAD_CRC_STRIP);
+#endif
+#if defined (DEV_RX_OFFLOAD_KEEP_CRC)
+ CONFIGURE_RX_OFFLOAD(DEV_RX_OFFLOAD_KEEP_CRC);
+#endif
CONFIGURE_RX_OFFLOAD(DEV_RX_OFFLOAD_JUMBO_FRAME);
CONFIGURE_RX_OFFLOAD(DEV_RX_OFFLOAD_VLAN_STRIP);
#else
port_cfg->port_conf.intr_conf.lsc = port_cfg->lsc_val;
plog_info("\t\tOverriding link state interrupt configuration to '%s'\n", port_cfg->lsc_val? "enabled" : "disabled");
}
- if (!strcmp(port_cfg->short_name, "vmxnet3")) {
- if (port_cfg->n_txd < 512) {
- // Vmxnet3 driver requires minimum 512 tx descriptors
- plog_info("\t\tNumber of TX descriptors is set to 512 (minimum required for vmxnet3\n");
- port_cfg->n_txd = 512;
- }
+ if (port_cfg->n_txd < port_cfg->min_tx_desc) {
+ plog_info("\t\tNumber of TX descriptors is set to %d (minimum required for %s\n", port_cfg->min_tx_desc, port_cfg->short_name);
+ port_cfg->n_txd = port_cfg->min_tx_desc;
+ }
+
+ if (port_cfg->n_rxd < port_cfg->min_rx_desc) {
+ plog_info("\t\tNumber of RX descriptors is set to %d (minimum required for %s\n", port_cfg->min_rx_desc, port_cfg->short_name);
+ port_cfg->n_rxd = port_cfg->min_rx_desc;
+ }
+
+ if (port_cfg->n_txd > port_cfg->max_tx_desc) {
+ plog_info("\t\tNumber of TX descriptors is set to %d (maximum required for %s\n", port_cfg->max_tx_desc, port_cfg->short_name);
+ port_cfg->n_txd = port_cfg->max_tx_desc;
+ }
+
+ if (port_cfg->n_rxd > port_cfg->max_rx_desc) {
+ plog_info("\t\tNumber of RX descriptors is set to %d (maximum required for %s\n", port_cfg->max_rx_desc, port_cfg->short_name);
+ port_cfg->n_rxd = port_cfg->max_rx_desc;
}
ret = rte_eth_dev_configure(port_id, port_cfg->n_rxq,
PROX_PANIC(ret < 0, "\n\t\t\trte_eth_dev_start() failed on port %u: error %d\n", port_id, ret);
plog_info(" done: ");
+ if (prox_port_cfg[port_id].ip) {
+ set_ip_address(prox_port_cfg[port_id].name, &prox_port_cfg[port_id].ip);
+ }
/* Getting link status can be done without waiting if Link
State Interrupt is enabled since in that case, if the link
is recognized as being down, an interrupt will notify that
strcmp(port_cfg->short_name, "i40e") &&
strcmp(port_cfg->short_name, "i40e_vf") &&
strcmp(port_cfg->short_name, "vmxnet3")) {
- for (uint8_t i = 0; i < 16; ++i) {
+ for (uint8_t i = 0; i < port_cfg->n_rxq; ++i) {
ret = rte_eth_dev_set_rx_queue_stats_mapping(port_id, i, i);
if (ret) {
plog_info("\t\trte_eth_dev_set_rx_queue_stats_mapping() failed: error %d\n", ret);
}
+ }
+ for (uint8_t i = 0; i < port_cfg->n_txq; ++i) {
ret = rte_eth_dev_set_tx_queue_stats_mapping(port_id, i, i);
if (ret) {
plog_info("\t\trte_eth_dev_set_tx_queue_stats_mapping() failed: error %d\n", ret);
}
}
}
+ if (port_cfg->nb_mc_addr) {
+ rte_eth_allmulticast_enable(port_id);
+ if ((ret = rte_eth_dev_set_mc_addr_list(port_id, port_cfg->mc_addr, port_cfg->nb_mc_addr)) != 0) {
+ plog_err("\t\trte_eth_dev_set_mc_addr_list returns %d on port %u\n", ret, port_id);
+ port_cfg->nb_mc_addr = 0;
+ rte_eth_allmulticast_disable(port_id);
+ plog_info("\t\tport %u NOT in multicast mode as failed to add mcast address\n", port_id);
+ } else {
+ plog_info("\t\trte_eth_dev_set_mc_addr_list(%d addr) on port %u\n", port_cfg->nb_mc_addr, port_id);
+ plog_info("\t\tport %u in multicast mode\n", port_id);
+ }
+ }
}
void init_port_all(void)
void init_port_addr(void)
{
struct prox_port_cfg *port_cfg;
+ int rc;
for (uint8_t port_id = 0; port_id < PROX_MAX_PORTS; ++port_id) {
if (!prox_port_cfg[port_id].active) {
rte_eth_macaddr_get(port_id, &port_cfg->eth_addr);
break;
case PROX_PORT_MAC_RAND:
- eth_random_addr(port_cfg->eth_addr.addr_bytes);
+ prox_rte_eth_random_addr(port_cfg->eth_addr.addr_bytes);
break;
case PROX_PORT_MAC_SET:
+ plog_info("Setting MAC to "MAC_BYTES_FMT"\n", MAC_BYTES(port_cfg->eth_addr.addr_bytes));
+ if ((rc = rte_eth_dev_default_mac_addr_set(port_id, &port_cfg->eth_addr)) != 0)
+ plog_warn("port %u: failed to set mac address. Error = %d\n", port_id, rc);
break;
}
}