X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Fnetvsc%2Fhn_ethdev.c;h=a7b7f15c16c841349d657af97f3b99306d848b32;hb=d566bfcff0c7bfe167f6c520d4fd5b0104130af6;hp=7f7ac155e2ab4a4c4f5634b797683e00ce87209d;hpb=323e7b667f18376c60351282950b28d4d0cc6165;p=dpdk.git diff --git a/drivers/net/netvsc/hn_ethdev.c b/drivers/net/netvsc/hn_ethdev.c index 7f7ac155e2..a7b7f15c16 100644 --- a/drivers/net/netvsc/hn_ethdev.c +++ b/drivers/net/netvsc/hn_ethdev.c @@ -9,22 +9,30 @@ #include #include #include +#include +#include +#include +#include +#include #include #include #include #include +#include #include +#include #include #include #include -#include +#include #include #include #include #include #include #include +#include #include "hn_logs.h" #include "hn_var.h" @@ -40,10 +48,16 @@ DEV_TX_OFFLOAD_VLAN_INSERT) #define HN_RX_OFFLOAD_CAPS (DEV_RX_OFFLOAD_CHECKSUM | \ - DEV_RX_OFFLOAD_VLAN_STRIP) + DEV_RX_OFFLOAD_VLAN_STRIP | \ + DEV_RX_OFFLOAD_RSS_HASH) -int hn_logtype_init; -int hn_logtype_driver; +#define NETVSC_ARG_LATENCY "latency" +#define NETVSC_ARG_RXBREAK "rx_copybreak" +#define NETVSC_ARG_TXBREAK "tx_copybreak" +#define NETVSC_ARG_RX_EXTMBUF_ENABLE "rx_extmbuf_enable" + +/* The max number of retry when hot adding a VF device */ +#define NETVSC_MAX_HOTADD_RETRY 10 struct hn_xstats_name_off { char name[RTE_ETH_XSTATS_NAME_SIZE]; @@ -54,7 +68,8 @@ static const struct hn_xstats_name_off hn_stat_strings[] = { { "good_packets", offsetof(struct hn_stats, packets) }, { "good_bytes", offsetof(struct hn_stats, bytes) }, { "errors", offsetof(struct hn_stats, errors) }, - { "allocation_failed", offsetof(struct hn_stats, nomemory) }, + { "ring full", offsetof(struct hn_stats, ring_full) }, + { "channel full", offsetof(struct hn_stats, channel_full) }, { "multicast_packets", offsetof(struct hn_stats, multicast) }, { "broadcast_packets", offsetof(struct hn_stats, broadcast) }, { "undersize_packets", offsetof(struct hn_stats, size_bins[0]) }, @@ -67,6 +82,18 @@ static const struct hn_xstats_name_off hn_stat_strings[] = { { "size_1519_max_packets", offsetof(struct hn_stats, size_bins[7]) }, }; +/* The default RSS key. + * This value is the same as MLX5 so that flows will be + * received on same path for both VF and synthetic NIC. + */ +static const uint8_t rss_default_key[NDIS_HASH_KEYSIZE_TOEPLITZ] = { + 0x2c, 0xc6, 0x81, 0xd1, 0x5b, 0xdb, 0xf4, 0xf7, + 0xfc, 0xa2, 0x83, 0x19, 0xdb, 0x1a, 0x3e, 0x94, + 0x6b, 0x9e, 0x38, 0xd9, 0x2c, 0x9c, 0x03, 0xd1, + 0xad, 0x99, 0x44, 0xa7, 0xd9, 0x56, 0x3d, 0x59, + 0x06, 0x3c, 0x25, 0xf3, 0xfc, 0x1f, 0xdc, 0x2a, +}; + static struct rte_eth_dev * eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size) { @@ -104,6 +131,10 @@ eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size) } eth_dev->device = &dev->device; + + /* interrupt is simulated */ + dev->intr_handle.type = RTE_INTR_HANDLE_EXT; + eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC; eth_dev->intr_handle = &dev->intr_handle; return eth_dev; @@ -115,19 +146,74 @@ eth_dev_vmbus_release(struct rte_eth_dev *eth_dev) /* free ether device */ rte_eth_dev_release_port(eth_dev); - if (rte_eal_process_type() == RTE_PROC_PRIMARY) - rte_free(eth_dev->data->dev_private); + eth_dev->device = NULL; + eth_dev->intr_handle = NULL; +} - eth_dev->data->dev_private = NULL; +static int hn_set_parameter(const char *key, const char *value, void *opaque) +{ + struct hn_data *hv = opaque; + char *endp = NULL; + unsigned long v; - /* - * Secondary process will check the name to attach. - * Clear this field to avoid attaching a released ports. - */ - eth_dev->data->name[0] = '\0'; + v = strtoul(value, &endp, 0); + if (*value == '\0' || *endp != '\0') { + PMD_DRV_LOG(ERR, "invalid parameter %s=%s", key, value); + return -EINVAL; + } - eth_dev->device = NULL; - eth_dev->intr_handle = NULL; + if (!strcmp(key, NETVSC_ARG_LATENCY)) { + /* usec to nsec */ + hv->latency = v * 1000; + PMD_DRV_LOG(DEBUG, "set latency %u usec", hv->latency); + } else if (!strcmp(key, NETVSC_ARG_RXBREAK)) { + hv->rx_copybreak = v; + PMD_DRV_LOG(DEBUG, "rx copy break set to %u", + hv->rx_copybreak); + } else if (!strcmp(key, NETVSC_ARG_TXBREAK)) { + hv->tx_copybreak = v; + PMD_DRV_LOG(DEBUG, "tx copy break set to %u", + hv->tx_copybreak); + } else if (!strcmp(key, NETVSC_ARG_RX_EXTMBUF_ENABLE)) { + hv->rx_extmbuf_enable = v; + PMD_DRV_LOG(DEBUG, "rx extmbuf enable set to %u", + hv->rx_extmbuf_enable); + } + + return 0; +} + +/* Parse device arguments */ +static int hn_parse_args(const struct rte_eth_dev *dev) +{ + struct hn_data *hv = dev->data->dev_private; + struct rte_devargs *devargs = dev->device->devargs; + static const char * const valid_keys[] = { + NETVSC_ARG_LATENCY, + NETVSC_ARG_RXBREAK, + NETVSC_ARG_TXBREAK, + NETVSC_ARG_RX_EXTMBUF_ENABLE, + NULL + }; + struct rte_kvargs *kvlist; + int ret; + + if (!devargs) + return 0; + + PMD_INIT_LOG(DEBUG, "device args %s %s", + devargs->name, devargs->args); + + kvlist = rte_kvargs_parse(devargs->args, valid_keys); + if (!kvlist) { + PMD_DRV_LOG(ERR, "invalid parameters"); + return -EINVAL; + } + + ret = rte_kvargs_process(kvlist, NULL, hn_set_parameter, hv); + rte_kvargs_free(kvlist); + + return ret; } /* Update link status. @@ -135,9 +221,9 @@ eth_dev_vmbus_release(struct rte_eth_dev *eth_dev) * means block this call until link is up. * which is not worth supporting. */ -static int +int hn_dev_link_update(struct rte_eth_dev *dev, - __rte_unused int wait_to_complete) + int wait_to_complete __rte_unused) { struct hn_data *hv = dev->data->dev_private; struct rte_eth_link link, old; @@ -171,10 +257,11 @@ hn_dev_link_update(struct rte_eth_dev *dev, return rte_eth_linkstatus_set(dev, &link); } -static void hn_dev_info_get(struct rte_eth_dev *dev, - struct rte_eth_dev_info *dev_info) +static int hn_dev_info_get(struct rte_eth_dev *dev, + struct rte_eth_dev_info *dev_info) { struct hn_data *hv = dev->data->dev_private; + int rc; dev_info->speed_capa = ETH_LINK_SPEED_10G; dev_info->min_rx_bufsize = HN_MIN_RX_BUF_SIZE; @@ -182,24 +269,194 @@ static void hn_dev_info_get(struct rte_eth_dev *dev, dev_info->max_mac_addrs = 1; dev_info->hash_key_size = NDIS_HASH_KEYSIZE_TOEPLITZ; - dev_info->flow_type_rss_offloads = - ETH_RSS_IPV4 | ETH_RSS_IPV6 | ETH_RSS_TCP | ETH_RSS_UDP; + dev_info->flow_type_rss_offloads = hv->rss_offloads; + dev_info->reta_size = ETH_RSS_RETA_SIZE_128; dev_info->max_rx_queues = hv->max_queues; dev_info->max_tx_queues = hv->max_queues; - hn_rndis_get_offload(hv, dev_info); + dev_info->tx_desc_lim.nb_min = 1; + dev_info->tx_desc_lim.nb_max = 4096; + + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return 0; + + /* fills in rx and tx offload capability */ + rc = hn_rndis_get_offload(hv, dev_info); + if (rc != 0) + return rc; + + /* merges the offload and queues of vf */ + return hn_vf_info_get(hv, dev_info); } -static void +static int hn_rss_reta_update(struct rte_eth_dev *dev, + struct rte_eth_rss_reta_entry64 *reta_conf, + uint16_t reta_size) +{ + struct hn_data *hv = dev->data->dev_private; + unsigned int i; + int err; + + PMD_INIT_FUNC_TRACE(); + + if (reta_size != NDIS_HASH_INDCNT) { + PMD_DRV_LOG(ERR, "Hash lookup table size does not match NDIS"); + return -EINVAL; + } + + for (i = 0; i < NDIS_HASH_INDCNT; i++) { + uint16_t idx = i / RTE_RETA_GROUP_SIZE; + uint16_t shift = i % RTE_RETA_GROUP_SIZE; + uint64_t mask = (uint64_t)1 << shift; + + if (reta_conf[idx].mask & mask) + hv->rss_ind[i] = reta_conf[idx].reta[shift]; + } + + err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE); + if (err) { + PMD_DRV_LOG(NOTICE, + "rss disable failed"); + return err; + } + + err = hn_rndis_conf_rss(hv, 0); + if (err) { + PMD_DRV_LOG(NOTICE, + "reta reconfig failed"); + return err; + } + + return hn_vf_reta_hash_update(dev, reta_conf, reta_size); +} + +static int hn_rss_reta_query(struct rte_eth_dev *dev, + struct rte_eth_rss_reta_entry64 *reta_conf, + uint16_t reta_size) +{ + struct hn_data *hv = dev->data->dev_private; + unsigned int i; + + PMD_INIT_FUNC_TRACE(); + + if (reta_size != NDIS_HASH_INDCNT) { + PMD_DRV_LOG(ERR, "Hash lookup table size does not match NDIS"); + return -EINVAL; + } + + for (i = 0; i < NDIS_HASH_INDCNT; i++) { + uint16_t idx = i / RTE_RETA_GROUP_SIZE; + uint16_t shift = i % RTE_RETA_GROUP_SIZE; + uint64_t mask = (uint64_t)1 << shift; + + if (reta_conf[idx].mask & mask) + reta_conf[idx].reta[shift] = hv->rss_ind[i]; + } + return 0; +} + +static void hn_rss_hash_init(struct hn_data *hv, + const struct rte_eth_rss_conf *rss_conf) +{ + /* Convert from DPDK RSS hash flags to NDIS hash flags */ + hv->rss_hash = NDIS_HASH_FUNCTION_TOEPLITZ; + + if (rss_conf->rss_hf & ETH_RSS_IPV4) + hv->rss_hash |= NDIS_HASH_IPV4; + if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP) + hv->rss_hash |= NDIS_HASH_TCP_IPV4; + if (rss_conf->rss_hf & ETH_RSS_IPV6) + hv->rss_hash |= NDIS_HASH_IPV6; + if (rss_conf->rss_hf & ETH_RSS_IPV6_EX) + hv->rss_hash |= NDIS_HASH_IPV6_EX; + if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP) + hv->rss_hash |= NDIS_HASH_TCP_IPV6; + if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX) + hv->rss_hash |= NDIS_HASH_TCP_IPV6_EX; + + memcpy(hv->rss_key, rss_conf->rss_key ? : rss_default_key, + NDIS_HASH_KEYSIZE_TOEPLITZ); +} + +static int hn_rss_hash_update(struct rte_eth_dev *dev, + struct rte_eth_rss_conf *rss_conf) +{ + struct hn_data *hv = dev->data->dev_private; + int err; + + PMD_INIT_FUNC_TRACE(); + + err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE); + if (err) { + PMD_DRV_LOG(NOTICE, + "rss disable failed"); + return err; + } + + hn_rss_hash_init(hv, rss_conf); + + if (rss_conf->rss_hf != 0) { + err = hn_rndis_conf_rss(hv, 0); + if (err) { + PMD_DRV_LOG(NOTICE, + "rss reconfig failed (RSS disabled)"); + return err; + } + } + + return hn_vf_rss_hash_update(dev, rss_conf); +} + +static int hn_rss_hash_conf_get(struct rte_eth_dev *dev, + struct rte_eth_rss_conf *rss_conf) +{ + struct hn_data *hv = dev->data->dev_private; + + PMD_INIT_FUNC_TRACE(); + + if (hv->ndis_ver < NDIS_VERSION_6_20) { + PMD_DRV_LOG(DEBUG, "RSS not supported on this host"); + return -EOPNOTSUPP; + } + + rss_conf->rss_key_len = NDIS_HASH_KEYSIZE_TOEPLITZ; + if (rss_conf->rss_key) + memcpy(rss_conf->rss_key, hv->rss_key, + NDIS_HASH_KEYSIZE_TOEPLITZ); + + rss_conf->rss_hf = 0; + if (hv->rss_hash & NDIS_HASH_IPV4) + rss_conf->rss_hf |= ETH_RSS_IPV4; + + if (hv->rss_hash & NDIS_HASH_TCP_IPV4) + rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP; + + if (hv->rss_hash & NDIS_HASH_IPV6) + rss_conf->rss_hf |= ETH_RSS_IPV6; + + if (hv->rss_hash & NDIS_HASH_IPV6_EX) + rss_conf->rss_hf |= ETH_RSS_IPV6_EX; + + if (hv->rss_hash & NDIS_HASH_TCP_IPV6) + rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP; + + if (hv->rss_hash & NDIS_HASH_TCP_IPV6_EX) + rss_conf->rss_hf |= ETH_RSS_IPV6_TCP_EX; + + return 0; +} + +static int hn_dev_promiscuous_enable(struct rte_eth_dev *dev) { struct hn_data *hv = dev->data->dev_private; hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_PROMISCUOUS); + return hn_vf_promiscuous_enable(dev); } -static void +static int hn_dev_promiscuous_disable(struct rte_eth_dev *dev) { struct hn_data *hv = dev->data->dev_private; @@ -209,9 +466,10 @@ hn_dev_promiscuous_disable(struct rte_eth_dev *dev) if (dev->data->all_multicast) filter |= NDIS_PACKET_TYPE_ALL_MULTICAST; hn_rndis_set_rxfilter(hv, filter); + return hn_vf_promiscuous_disable(dev); } -static void +static int hn_dev_allmulticast_enable(struct rte_eth_dev *dev) { struct hn_data *hv = dev->data->dev_private; @@ -219,15 +477,26 @@ hn_dev_allmulticast_enable(struct rte_eth_dev *dev) hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_ALL_MULTICAST | NDIS_PACKET_TYPE_BROADCAST); + return hn_vf_allmulticast_enable(dev); } -static void +static int hn_dev_allmulticast_disable(struct rte_eth_dev *dev) { struct hn_data *hv = dev->data->dev_private; hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_BROADCAST); + return hn_vf_allmulticast_disable(dev); +} + +static int +hn_dev_mc_addr_list(struct rte_eth_dev *dev, + struct rte_ether_addr *mc_addr_set, + uint32_t nb_mc_addr) +{ + /* No filtering on the synthetic path, but can do it on VF */ + return hn_vf_mc_addr_list(dev, mc_addr_set, nb_mc_addr); } /* Setup shared rx/tx queue data */ @@ -263,8 +532,7 @@ static int hn_subchan_configure(struct hn_data *hv, return err; } - rte_vmbus_set_latency(hv->vmbus, new_sc, - HN_CHAN_LATENCY_NS); + rte_vmbus_set_latency(hv->vmbus, new_sc, hv->latency); retry = 0; chn_index = rte_vmbus_sub_channel_index(new_sc); @@ -283,20 +551,144 @@ static int hn_subchan_configure(struct hn_data *hv, return err; } +static void netvsc_hotplug_retry(void *args) +{ + int ret; + struct hn_data *hv = args; + struct rte_eth_dev *dev = &rte_eth_devices[hv->port_id]; + struct rte_devargs *d = &hv->devargs; + char buf[256]; + + DIR *di; + struct dirent *dir; + struct ifreq req; + struct rte_ether_addr eth_addr; + int s; + + PMD_DRV_LOG(DEBUG, "%s: retry count %d", + __func__, hv->eal_hot_plug_retry); + + if (hv->eal_hot_plug_retry++ > NETVSC_MAX_HOTADD_RETRY) + return; + + snprintf(buf, sizeof(buf), "/sys/bus/pci/devices/%s/net", d->name); + di = opendir(buf); + if (!di) { + PMD_DRV_LOG(DEBUG, "%s: can't open directory %s, " + "retrying in 1 second", __func__, buf); + goto retry; + } + + while ((dir = readdir(di))) { + /* Skip . and .. directories */ + if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, "..")) + continue; + + /* trying to get mac address if this is a network device*/ + s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP); + if (s == -1) { + PMD_DRV_LOG(ERR, "Failed to create socket errno %d", + errno); + break; + } + strlcpy(req.ifr_name, dir->d_name, sizeof(req.ifr_name)); + ret = ioctl(s, SIOCGIFHWADDR, &req); + close(s); + if (ret == -1) { + PMD_DRV_LOG(ERR, + "Failed to send SIOCGIFHWADDR for device %s", + dir->d_name); + break; + } + if (req.ifr_hwaddr.sa_family != ARPHRD_ETHER) { + closedir(di); + return; + } + memcpy(eth_addr.addr_bytes, req.ifr_hwaddr.sa_data, + RTE_DIM(eth_addr.addr_bytes)); + + if (rte_is_same_ether_addr(ð_addr, dev->data->mac_addrs)) { + PMD_DRV_LOG(NOTICE, + "Found matching MAC address, adding device %s network name %s", + d->name, dir->d_name); + ret = rte_eal_hotplug_add(d->bus->name, d->name, + d->args); + if (ret) { + PMD_DRV_LOG(ERR, + "Failed to add PCI device %s", + d->name); + break; + } + } + /* When the code reaches here, we either have already added + * the device, or its MAC address did not match. + */ + closedir(di); + return; + } + closedir(di); +retry: + /* The device is still being initialized, retry after 1 second */ + rte_eal_alarm_set(1000000, netvsc_hotplug_retry, hv); +} + +static void +netvsc_hotadd_callback(const char *device_name, enum rte_dev_event_type type, + void *arg) +{ + struct hn_data *hv = arg; + struct rte_devargs *d = &hv->devargs; + int ret; + + PMD_DRV_LOG(INFO, "Device notification type=%d device_name=%s", + type, device_name); + + switch (type) { + case RTE_DEV_EVENT_ADD: + /* if we already has a VF, don't check on hot add */ + if (hv->vf_ctx.vf_state > vf_removed) + break; + + ret = rte_devargs_parse(d, device_name); + if (ret) { + PMD_DRV_LOG(ERR, + "devargs parsing failed ret=%d", ret); + return; + } + + if (!strcmp(d->bus->name, "pci")) { + /* Start the process of figuring out if this + * PCI device is a VF device + */ + hv->eal_hot_plug_retry = 0; + rte_eal_alarm_set(1000000, netvsc_hotplug_retry, hv); + } + + /* We will switch to VF on RDNIS configure message + * sent from VSP + */ + + break; + default: + break; + } +} + static int hn_dev_configure(struct rte_eth_dev *dev) { - const struct rte_eth_conf *dev_conf = &dev->data->dev_conf; + struct rte_eth_conf *dev_conf = &dev->data->dev_conf; + struct rte_eth_rss_conf *rss_conf = &dev_conf->rx_adv_conf.rss_conf; const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode; const struct rte_eth_txmode *txmode = &dev_conf->txmode; - - const struct rte_eth_rss_conf *rss_conf = - &dev_conf->rx_adv_conf.rss_conf; struct hn_data *hv = dev->data->dev_private; uint64_t unsupported; - int err, subchan; + int i, err, subchan; PMD_INIT_FUNC_TRACE(); + if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) + dev_conf->rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH; + unsupported = txmode->offloads & ~HN_TX_OFFLOAD_CAPS; if (unsupported) { PMD_DRV_LOG(NOTICE, @@ -313,6 +705,8 @@ static int hn_dev_configure(struct rte_eth_dev *dev) return -EINVAL; } + hv->vlan_strip = !!(rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP); + err = hn_rndis_conf_offload(hv, txmode->offloads, rxmode->offloads); if (err) { @@ -323,6 +717,12 @@ static int hn_dev_configure(struct rte_eth_dev *dev) hv->num_queues = RTE_MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues); + + for (i = 0; i < NDIS_HASH_INDCNT; i++) + hv->rss_ind[i] = i % dev->data->nb_rx_queues; + + hn_rss_hash_init(hv, rss_conf); + subchan = hv->num_queues - 1; if (subchan > 0) { err = hn_subchan_configure(hv, subchan); @@ -332,15 +732,24 @@ static int hn_dev_configure(struct rte_eth_dev *dev) return err; } - err = hn_rndis_conf_rss(hv, rss_conf); + err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE); if (err) { PMD_DRV_LOG(NOTICE, - "rss configuration failed"); + "rss disable failed"); return err; } + + if (rss_conf->rss_hf != 0) { + err = hn_rndis_conf_rss(hv, 0); + if (err) { + PMD_DRV_LOG(NOTICE, + "initial RSS config failed"); + return err; + } + } } - return 0; + return hn_vf_configure_locked(dev, dev_conf); } static int hn_dev_stats_get(struct rte_eth_dev *dev, @@ -348,6 +757,8 @@ static int hn_dev_stats_get(struct rte_eth_dev *dev, { unsigned int i; + hn_vf_stats_get(dev, stats); + for (i = 0; i < dev->data->nb_tx_queues; i++) { const struct hn_tx_queue *txq = dev->data->tx_queues[i]; @@ -356,7 +767,7 @@ static int hn_dev_stats_get(struct rte_eth_dev *dev, stats->opackets += txq->stats.packets; stats->obytes += txq->stats.bytes; - stats->oerrors += txq->stats.errors + txq->stats.nomemory; + stats->oerrors += txq->stats.errors; if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { stats->q_opackets[i] = txq->stats.packets; @@ -373,7 +784,7 @@ static int hn_dev_stats_get(struct rte_eth_dev *dev, stats->ipackets += rxq->stats.packets; stats->ibytes += rxq->stats.bytes; stats->ierrors += rxq->stats.errors; - stats->imissed += rxq->ring_full; + stats->imissed += rxq->stats.ring_full; if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) { stats->q_ipackets[i] = rxq->stats.packets; @@ -385,7 +796,7 @@ static int hn_dev_stats_get(struct rte_eth_dev *dev, return 0; } -static void +static int hn_dev_stats_reset(struct rte_eth_dev *dev) { unsigned int i; @@ -407,22 +818,48 @@ hn_dev_stats_reset(struct rte_eth_dev *dev) continue; memset(&rxq->stats, 0, sizeof(struct hn_stats)); - rxq->ring_full = 0; } + + return 0; +} + +static int +hn_dev_xstats_reset(struct rte_eth_dev *dev) +{ + int ret; + + ret = hn_dev_stats_reset(dev); + if (ret != 0) + return 0; + + return hn_vf_xstats_reset(dev); +} + +static int +hn_dev_xstats_count(struct rte_eth_dev *dev) +{ + int ret, count; + + count = dev->data->nb_tx_queues * RTE_DIM(hn_stat_strings); + count += dev->data->nb_rx_queues * RTE_DIM(hn_stat_strings); + + ret = hn_vf_xstats_get_names(dev, NULL, 0); + if (ret < 0) + return ret; + + return count + ret; } static int hn_dev_xstats_get_names(struct rte_eth_dev *dev, struct rte_eth_xstat_name *xstats_names, - __rte_unused unsigned int limit) + unsigned int limit) { unsigned int i, t, count = 0; - - PMD_INIT_FUNC_TRACE(); + int ret; if (!xstats_names) - return dev->data->nb_tx_queues * RTE_DIM(hn_stat_strings) - + dev->data->nb_rx_queues * RTE_DIM(hn_stat_strings); + return hn_dev_xstats_count(dev); /* Note: limit checked in rte_eth_xstats_names() */ for (i = 0; i < dev->data->nb_tx_queues; i++) { @@ -431,6 +868,9 @@ hn_dev_xstats_get_names(struct rte_eth_dev *dev, if (!txq) continue; + if (count >= limit) + break; + for (t = 0; t < RTE_DIM(hn_stat_strings); t++) snprintf(xstats_names[count++].name, RTE_ETH_XSTATS_NAME_SIZE, @@ -443,6 +883,9 @@ hn_dev_xstats_get_names(struct rte_eth_dev *dev, if (!rxq) continue; + if (count >= limit) + break; + for (t = 0; t < RTE_DIM(hn_stat_strings); t++) snprintf(xstats_names[count++].name, RTE_ETH_XSTATS_NAME_SIZE, @@ -450,7 +893,12 @@ hn_dev_xstats_get_names(struct rte_eth_dev *dev, hn_stat_strings[t].name); } - return count; + ret = hn_vf_xstats_get_names(dev, xstats_names + count, + limit - count); + if (ret < 0) + return ret; + + return count + ret; } static int @@ -459,11 +907,9 @@ hn_dev_xstats_get(struct rte_eth_dev *dev, unsigned int n) { unsigned int i, t, count = 0; - - const unsigned int nstats = - dev->data->nb_tx_queues * RTE_DIM(hn_stat_strings) - + dev->data->nb_rx_queues * RTE_DIM(hn_stat_strings); + const unsigned int nstats = hn_dev_xstats_count(dev); const char *stats; + int ret; PMD_INIT_FUNC_TRACE(); @@ -477,9 +923,11 @@ hn_dev_xstats_get(struct rte_eth_dev *dev, continue; stats = (const char *)&txq->stats; - for (t = 0; t < RTE_DIM(hn_stat_strings); t++) - xstats[count++].value = *(const uint64_t *) + for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) { + xstats[count].id = count; + xstats[count].value = *(const uint64_t *) (stats + hn_stat_strings[t].offset); + } } for (i = 0; i < dev->data->nb_rx_queues; i++) { @@ -489,47 +937,83 @@ hn_dev_xstats_get(struct rte_eth_dev *dev, continue; stats = (const char *)&rxq->stats; - for (t = 0; t < RTE_DIM(hn_stat_strings); t++) - xstats[count++].value = *(const uint64_t *) + for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) { + xstats[count].id = count; + xstats[count].value = *(const uint64_t *) (stats + hn_stat_strings[t].offset); + } } - return count; + ret = hn_vf_xstats_get(dev, xstats, count, n); + if (ret < 0) + return ret; + + return count + ret; } static int hn_dev_start(struct rte_eth_dev *dev) { struct hn_data *hv = dev->data->dev_private; + int error; PMD_INIT_FUNC_TRACE(); - /* check if lsc interrupt feature is enabled */ - if (dev->data->dev_conf.intr_conf.lsc) { - PMD_DRV_LOG(ERR, "link status not supported yet"); - return -ENOTSUP; + /* Register to monitor hot plug events */ + error = rte_dev_event_callback_register(NULL, netvsc_hotadd_callback, + hv); + if (error) { + PMD_DRV_LOG(ERR, "failed to register device event callback"); + return error; } - return hn_rndis_set_rxfilter(hv, - NDIS_PACKET_TYPE_BROADCAST | - NDIS_PACKET_TYPE_ALL_MULTICAST | - NDIS_PACKET_TYPE_DIRECTED); + error = hn_rndis_set_rxfilter(hv, + NDIS_PACKET_TYPE_BROADCAST | + NDIS_PACKET_TYPE_ALL_MULTICAST | + NDIS_PACKET_TYPE_DIRECTED); + if (error) + return error; + + error = hn_vf_start(dev); + if (error) + hn_rndis_set_rxfilter(hv, 0); + + /* Initialize Link state */ + if (error == 0) + hn_dev_link_update(dev, 0); + + return error; } -static void +static int hn_dev_stop(struct rte_eth_dev *dev) { struct hn_data *hv = dev->data->dev_private; PMD_INIT_FUNC_TRACE(); + dev->data->dev_started = 0; + rte_dev_event_callback_unregister(NULL, netvsc_hotadd_callback, hv); hn_rndis_set_rxfilter(hv, 0); + return hn_vf_stop(dev); } -static void -hn_dev_close(struct rte_eth_dev *dev __rte_unused) +static int +hn_dev_close(struct rte_eth_dev *dev) { - PMD_INIT_LOG(DEBUG, "close"); + int ret; + struct hn_data *hv = dev->data->dev_private; + + PMD_INIT_FUNC_TRACE(); + if (rte_eal_process_type() != RTE_PROC_PRIMARY) + return 0; + + rte_eal_alarm_cancel(netvsc_hotplug_retry, &hv->devargs); + + ret = hn_vf_close(dev); + hn_dev_free_queues(dev); + + return ret; } static const struct eth_dev_ops hn_eth_dev_ops = { @@ -540,10 +1024,16 @@ static const struct eth_dev_ops hn_eth_dev_ops = { .dev_infos_get = hn_dev_info_get, .txq_info_get = hn_dev_tx_queue_info, .rxq_info_get = hn_dev_rx_queue_info, + .dev_supported_ptypes_get = hn_vf_supported_ptypes, .promiscuous_enable = hn_dev_promiscuous_enable, .promiscuous_disable = hn_dev_promiscuous_disable, .allmulticast_enable = hn_dev_allmulticast_enable, .allmulticast_disable = hn_dev_allmulticast_disable, + .set_mc_addr_list = hn_dev_mc_addr_list, + .reta_update = hn_rss_reta_update, + .reta_query = hn_rss_reta_query, + .rss_hash_update = hn_rss_hash_update, + .rss_hash_conf_get = hn_rss_hash_conf_get, .tx_queue_setup = hn_dev_tx_queue_setup, .tx_queue_release = hn_dev_tx_queue_release, .tx_done_cleanup = hn_dev_tx_done_cleanup, @@ -551,10 +1041,10 @@ static const struct eth_dev_ops hn_eth_dev_ops = { .rx_queue_release = hn_dev_rx_queue_release, .link_update = hn_dev_link_update, .stats_get = hn_dev_stats_get, + .stats_reset = hn_dev_stats_reset, .xstats_get = hn_dev_xstats_get, .xstats_get_names = hn_dev_xstats_get_names, - .stats_reset = hn_dev_stats_reset, - .xstats_reset = hn_dev_stats_reset, + .xstats_reset = hn_dev_xstats_reset, }; /* @@ -609,6 +1099,9 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev) vmbus = container_of(device, struct rte_vmbus_device, device); eth_dev->dev_ops = &hn_eth_dev_ops; + eth_dev->rx_queue_count = hn_dev_rx_queue_count; + eth_dev->rx_descriptor_status = hn_dev_rx_queue_status; + eth_dev->tx_descriptor_status = hn_dev_tx_descriptor_status; eth_dev->tx_pkt_burst = &hn_xmit_pkts; eth_dev->rx_pkt_burst = &hn_recv_pkts; @@ -619,21 +1112,51 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev) if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; - /* Since Hyper-V only supports one MAC address, just use local data */ - eth_dev->data->mac_addrs = &hv->mac_addr; + eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; + + /* Since Hyper-V only supports one MAC address */ + eth_dev->data->mac_addrs = rte_calloc("hv_mac", HN_MAX_MAC_ADDRS, + sizeof(struct rte_ether_addr), 0); + if (eth_dev->data->mac_addrs == NULL) { + PMD_INIT_LOG(ERR, + "Failed to allocate memory store MAC addresses"); + return -ENOMEM; + } hv->vmbus = vmbus; hv->rxbuf_res = &vmbus->resource[HV_RECV_BUF_MAP]; hv->chim_res = &vmbus->resource[HV_SEND_BUF_MAP]; hv->port_id = eth_dev->data->port_id; + hv->latency = HN_CHAN_LATENCY_NS; + hv->rx_copybreak = HN_RXCOPY_THRESHOLD; + hv->tx_copybreak = HN_TXCOPY_THRESHOLD; + hv->rx_extmbuf_enable = HN_RX_EXTMBUF_ENABLE; + hv->max_queues = 1; + + rte_rwlock_init(&hv->vf_lock); + hv->vf_ctx.vf_vsc_switched = false; + hv->vf_ctx.vf_vsp_reported = false; + hv->vf_ctx.vf_attached = false; + hv->vf_ctx.vf_state = vf_unknown; + + err = hn_parse_args(eth_dev); + if (err) + return err; + + strlcpy(hv->owner.name, eth_dev->device->name, + RTE_ETH_MAX_OWNER_NAME_LEN); + err = rte_eth_dev_owner_new(&hv->owner.id); + if (err) { + PMD_INIT_LOG(ERR, "Can not get owner id"); + return err; + } /* Initialize primary channel input for control operations */ err = rte_vmbus_chan_open(vmbus, &hv->channels[0]); if (err) return err; - rte_vmbus_set_latency(hv->vmbus, hv->channels[0], - HN_CHAN_LATENCY_NS); + rte_vmbus_set_latency(hv->vmbus, hv->channels[0], hv->latency); hv->primary = hn_rx_queue_alloc(hv, 0, eth_dev->device->numa_node); @@ -641,18 +1164,22 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev) if (!hv->primary) return -ENOMEM; - err = hn_attach(hv, ETHER_MTU); + err = hn_attach(hv, RTE_ETHER_MTU); if (err) goto failed; - err = hn_tx_pool_init(eth_dev); + err = hn_chim_init(eth_dev); if (err) goto failed; - err = hn_rndis_get_eaddr(hv, hv->mac_addr.addr_bytes); + err = hn_rndis_get_eaddr(hv, eth_dev->data->mac_addrs->addr_bytes); if (err) goto failed; + /* Multi queue requires later versions of windows server */ + if (hv->nvs_ver < NVS_VERSION_5) + return 0; + max_chan = rte_vmbus_max_channels(vmbus); PMD_INIT_LOG(DEBUG, "VMBus max channels %d", max_chan); if (max_chan <= 0) @@ -663,11 +1190,19 @@ eth_hn_dev_init(struct rte_eth_dev *eth_dev) hv->max_queues = RTE_MIN(rxr_cnt, (unsigned int)max_chan); + /* If VF was reported but not added, do it now */ + if (hv->vf_ctx.vf_vsp_reported && !hv->vf_ctx.vf_vsc_switched) { + PMD_INIT_LOG(DEBUG, "Adding VF device"); + + err = hn_vf_add(eth_dev, hv); + } + return 0; failed: PMD_INIT_LOG(NOTICE, "device init failed"); + hn_chim_uninit(eth_dev); hn_detach(hv); return err; } @@ -676,26 +1211,25 @@ static int eth_hn_dev_uninit(struct rte_eth_dev *eth_dev) { struct hn_data *hv = eth_dev->data->dev_private; + int ret, ret_stop; PMD_INIT_FUNC_TRACE(); if (rte_eal_process_type() != RTE_PROC_PRIMARY) return 0; - hn_dev_stop(eth_dev); + ret_stop = hn_dev_stop(eth_dev); hn_dev_close(eth_dev); - eth_dev->dev_ops = NULL; - eth_dev->tx_pkt_burst = NULL; - eth_dev->rx_pkt_burst = NULL; - hn_detach(hv); + hn_chim_uninit(eth_dev); rte_vmbus_chan_close(hv->primary->chan); rte_free(hv->primary); + ret = rte_eth_dev_owner_delete(hv->owner.id); + if (ret != 0) + return ret; - eth_dev->data->mac_addrs = NULL; - - return 0; + return ret_stop; } static int eth_hn_probe(struct rte_vmbus_driver *drv __rte_unused, @@ -706,15 +1240,23 @@ static int eth_hn_probe(struct rte_vmbus_driver *drv __rte_unused, PMD_INIT_FUNC_TRACE(); + ret = rte_dev_event_monitor_start(); + if (ret) { + PMD_DRV_LOG(ERR, "Failed to start device event monitoring"); + return ret; + } + eth_dev = eth_dev_vmbus_allocate(dev, sizeof(struct hn_data)); if (!eth_dev) return -ENOMEM; ret = eth_hn_dev_init(eth_dev); - if (ret) + if (ret) { eth_dev_vmbus_release(eth_dev); - else + rte_dev_event_monitor_stop(); + } else { rte_eth_dev_probing_finish(eth_dev); + } return ret; } @@ -728,13 +1270,14 @@ static int eth_hn_remove(struct rte_vmbus_device *dev) eth_dev = rte_eth_dev_allocated(dev->device.name); if (!eth_dev) - return -ENODEV; + return 0; /* port already released */ ret = eth_hn_dev_uninit(eth_dev); if (ret) return ret; eth_dev_vmbus_release(eth_dev); + rte_dev_event_monitor_stop(); return 0; } @@ -753,15 +1296,10 @@ static struct rte_vmbus_driver rte_netvsc_pmd = { RTE_PMD_REGISTER_VMBUS(net_netvsc, rte_netvsc_pmd); RTE_PMD_REGISTER_KMOD_DEP(net_netvsc, "* uio_hv_generic"); - -RTE_INIT(hn_init_log); -static void -hn_init_log(void) -{ - hn_logtype_init = rte_log_register("pmd.net.netvsc.init"); - if (hn_logtype_init >= 0) - rte_log_set_level(hn_logtype_init, RTE_LOG_NOTICE); - hn_logtype_driver = rte_log_register("pmd.net.netvsc.driver"); - if (hn_logtype_driver >= 0) - rte_log_set_level(hn_logtype_driver, RTE_LOG_NOTICE); -} +RTE_LOG_REGISTER(hn_logtype_init, pmd.net.netvsc.init, NOTICE); +RTE_LOG_REGISTER(hn_logtype_driver, pmd.net.netvsc.driver, NOTICE); +RTE_PMD_REGISTER_PARAM_STRING(net_netvsc, + NETVSC_ARG_LATENCY "= " + NETVSC_ARG_RXBREAK "= " + NETVSC_ARG_TXBREAK "= " + NETVSC_ARG_RX_EXTMBUF_ENABLE "=<0|1>");