2018-07-13 17:06:43 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
* Copyright(c) 2016-2018 Microsoft Corporation
|
|
|
|
* Copyright(c) 2013-2016 Brocade Communications Systems, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include <rte_ethdev.h>
|
|
|
|
#include <rte_memcpy.h>
|
|
|
|
#include <rte_string_fns.h>
|
|
|
|
#include <rte_memzone.h>
|
2018-08-30 22:35:09 +00:00
|
|
|
#include <rte_devargs.h>
|
2018-07-13 17:06:43 +00:00
|
|
|
#include <rte_malloc.h>
|
2018-08-30 22:35:09 +00:00
|
|
|
#include <rte_kvargs.h>
|
2018-07-13 17:06:43 +00:00
|
|
|
#include <rte_atomic.h>
|
|
|
|
#include <rte_branch_prediction.h>
|
|
|
|
#include <rte_ether.h>
|
|
|
|
#include <rte_ethdev_driver.h>
|
|
|
|
#include <rte_cycles.h>
|
|
|
|
#include <rte_errno.h>
|
|
|
|
#include <rte_memory.h>
|
|
|
|
#include <rte_eal.h>
|
|
|
|
#include <rte_dev.h>
|
|
|
|
#include <rte_bus_vmbus.h>
|
|
|
|
|
|
|
|
#include "hn_logs.h"
|
|
|
|
#include "hn_var.h"
|
|
|
|
#include "hn_rndis.h"
|
|
|
|
#include "hn_nvs.h"
|
|
|
|
#include "ndis.h"
|
|
|
|
|
|
|
|
#define HN_TX_OFFLOAD_CAPS (DEV_TX_OFFLOAD_IPV4_CKSUM | \
|
|
|
|
DEV_TX_OFFLOAD_TCP_CKSUM | \
|
|
|
|
DEV_TX_OFFLOAD_UDP_CKSUM | \
|
|
|
|
DEV_TX_OFFLOAD_TCP_TSO | \
|
|
|
|
DEV_TX_OFFLOAD_MULTI_SEGS | \
|
|
|
|
DEV_TX_OFFLOAD_VLAN_INSERT)
|
|
|
|
|
|
|
|
#define HN_RX_OFFLOAD_CAPS (DEV_RX_OFFLOAD_CHECKSUM | \
|
2019-12-06 23:52:47 +00:00
|
|
|
DEV_RX_OFFLOAD_VLAN_STRIP | \
|
|
|
|
DEV_RX_OFFLOAD_RSS_HASH)
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
struct hn_xstats_name_off {
|
|
|
|
char name[RTE_ETH_XSTATS_NAME_SIZE];
|
|
|
|
unsigned int offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
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) },
|
2018-08-30 22:35:10 +00:00
|
|
|
{ "ring full", offsetof(struct hn_stats, ring_full) },
|
2020-05-19 16:52:26 +00:00
|
|
|
{ "channel full", offsetof(struct hn_stats, channel_full) },
|
2018-07-13 17:06:43 +00:00
|
|
|
{ "multicast_packets", offsetof(struct hn_stats, multicast) },
|
|
|
|
{ "broadcast_packets", offsetof(struct hn_stats, broadcast) },
|
|
|
|
{ "undersize_packets", offsetof(struct hn_stats, size_bins[0]) },
|
|
|
|
{ "size_64_packets", offsetof(struct hn_stats, size_bins[1]) },
|
|
|
|
{ "size_65_127_packets", offsetof(struct hn_stats, size_bins[2]) },
|
|
|
|
{ "size_128_255_packets", offsetof(struct hn_stats, size_bins[3]) },
|
|
|
|
{ "size_256_511_packets", offsetof(struct hn_stats, size_bins[4]) },
|
|
|
|
{ "size_512_1023_packets", offsetof(struct hn_stats, size_bins[5]) },
|
|
|
|
{ "size_1024_1518_packets", offsetof(struct hn_stats, size_bins[6]) },
|
|
|
|
{ "size_1519_max_packets", offsetof(struct hn_stats, size_bins[7]) },
|
|
|
|
};
|
|
|
|
|
2019-06-13 15:03:43 +00:00
|
|
|
/* The default RSS key.
|
|
|
|
* This value is the same as MLX5 so that flows will be
|
2020-04-30 19:08:47 +00:00
|
|
|
* received on same path for both VF and synthetic NIC.
|
2019-06-13 15:03:43 +00:00
|
|
|
*/
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
static struct rte_eth_dev *
|
|
|
|
eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size)
|
|
|
|
{
|
|
|
|
struct rte_eth_dev *eth_dev;
|
|
|
|
const char *name;
|
|
|
|
|
|
|
|
if (!dev)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
name = dev->device.name;
|
|
|
|
|
|
|
|
if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
|
|
|
|
eth_dev = rte_eth_dev_allocate(name);
|
|
|
|
if (!eth_dev) {
|
|
|
|
PMD_DRV_LOG(NOTICE, "can not allocate rte ethdev");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (private_data_size) {
|
|
|
|
eth_dev->data->dev_private =
|
|
|
|
rte_zmalloc_socket(name, private_data_size,
|
|
|
|
RTE_CACHE_LINE_SIZE, dev->device.numa_node);
|
|
|
|
if (!eth_dev->data->dev_private) {
|
|
|
|
PMD_DRV_LOG(NOTICE, "can not allocate driver data");
|
|
|
|
rte_eth_dev_release_port(eth_dev);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
eth_dev = rte_eth_dev_attach_secondary(name);
|
|
|
|
if (!eth_dev) {
|
|
|
|
PMD_DRV_LOG(NOTICE, "can not attach secondary");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
eth_dev->device = &dev->device;
|
2018-08-30 22:35:11 +00:00
|
|
|
|
|
|
|
/* interrupt is simulated */
|
|
|
|
dev->intr_handle.type = RTE_INTR_HANDLE_EXT;
|
|
|
|
eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
|
2018-07-13 17:06:43 +00:00
|
|
|
eth_dev->intr_handle = &dev->intr_handle;
|
|
|
|
|
2019-04-30 18:12:17 +00:00
|
|
|
/* allow ethdev to remove on close */
|
|
|
|
eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
return eth_dev;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
eth_dev_vmbus_release(struct rte_eth_dev *eth_dev)
|
|
|
|
{
|
|
|
|
/* free ether device */
|
|
|
|
rte_eth_dev_release_port(eth_dev);
|
|
|
|
|
|
|
|
eth_dev->device = NULL;
|
|
|
|
eth_dev->intr_handle = NULL;
|
|
|
|
}
|
|
|
|
|
2018-08-30 22:35:09 +00:00
|
|
|
/* handle "latency=X" from devargs */
|
|
|
|
static int hn_set_latency(const char *key, const char *value, void *opaque)
|
|
|
|
{
|
|
|
|
struct hn_data *hv = opaque;
|
|
|
|
char *endp = NULL;
|
|
|
|
unsigned long lat;
|
|
|
|
|
|
|
|
errno = 0;
|
|
|
|
lat = strtoul(value, &endp, 0);
|
|
|
|
|
|
|
|
if (*value == '\0' || *endp != '\0') {
|
|
|
|
PMD_DRV_LOG(ERR, "invalid parameter %s=%s", key, value);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
PMD_DRV_LOG(DEBUG, "set latency %lu usec", lat);
|
|
|
|
|
|
|
|
hv->latency = lat * 1000; /* usec to nsec */
|
|
|
|
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[] = {
|
|
|
|
"latency",
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
struct rte_kvargs *kvlist;
|
2018-09-26 09:31:12 +00:00
|
|
|
int ret;
|
2018-08-30 22:35:09 +00:00
|
|
|
|
|
|
|
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(NOTICE, "invalid parameters");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-09-26 09:31:12 +00:00
|
|
|
ret = rte_kvargs_process(kvlist, "latency", hn_set_latency, hv);
|
|
|
|
if (ret)
|
|
|
|
PMD_DRV_LOG(ERR, "Unable to process latency arg\n");
|
|
|
|
|
2018-08-30 22:35:09 +00:00
|
|
|
rte_kvargs_free(kvlist);
|
2018-09-26 09:31:12 +00:00
|
|
|
return ret;
|
2018-08-30 22:35:09 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
/* Update link status.
|
|
|
|
* Note: the DPDK definition of "wait_to_complete"
|
|
|
|
* means block this call until link is up.
|
|
|
|
* which is not worth supporting.
|
|
|
|
*/
|
2018-08-30 22:35:11 +00:00
|
|
|
int
|
2018-07-13 17:06:43 +00:00
|
|
|
hn_dev_link_update(struct rte_eth_dev *dev,
|
2020-05-19 16:52:28 +00:00
|
|
|
int wait_to_complete __rte_unused)
|
2018-07-13 17:06:43 +00:00
|
|
|
{
|
|
|
|
struct hn_data *hv = dev->data->dev_private;
|
|
|
|
struct rte_eth_link link, old;
|
|
|
|
int error;
|
|
|
|
|
|
|
|
old = dev->data->dev_link;
|
|
|
|
|
|
|
|
error = hn_rndis_get_linkstatus(hv);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
|
|
|
|
hn_rndis_get_linkspeed(hv);
|
|
|
|
|
|
|
|
link = (struct rte_eth_link) {
|
|
|
|
.link_duplex = ETH_LINK_FULL_DUPLEX,
|
|
|
|
.link_autoneg = ETH_LINK_SPEED_FIXED,
|
|
|
|
.link_speed = hv->link_speed / 10000,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (hv->link_status == NDIS_MEDIA_STATE_CONNECTED)
|
|
|
|
link.link_status = ETH_LINK_UP;
|
|
|
|
else
|
|
|
|
link.link_status = ETH_LINK_DOWN;
|
|
|
|
|
|
|
|
if (old.link_status == link.link_status)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
PMD_INIT_LOG(DEBUG, "Port %d is %s", dev->data->port_id,
|
|
|
|
(link.link_status == ETH_LINK_UP) ? "up" : "down");
|
|
|
|
|
|
|
|
return rte_eth_linkstatus_set(dev, &link);
|
|
|
|
}
|
|
|
|
|
2019-09-12 16:42:28 +00:00
|
|
|
static int hn_dev_info_get(struct rte_eth_dev *dev,
|
|
|
|
struct rte_eth_dev_info *dev_info)
|
2018-07-13 17:06:43 +00:00
|
|
|
{
|
|
|
|
struct hn_data *hv = dev->data->dev_private;
|
2019-09-12 16:42:28 +00:00
|
|
|
int rc;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
dev_info->speed_capa = ETH_LINK_SPEED_10G;
|
|
|
|
dev_info->min_rx_bufsize = HN_MIN_RX_BUF_SIZE;
|
|
|
|
dev_info->max_rx_pktlen = HN_MAX_XFER_LEN;
|
|
|
|
dev_info->max_mac_addrs = 1;
|
|
|
|
|
|
|
|
dev_info->hash_key_size = NDIS_HASH_KEYSIZE_TOEPLITZ;
|
2019-06-13 15:03:42 +00:00
|
|
|
dev_info->flow_type_rss_offloads = hv->rss_offloads;
|
|
|
|
dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
dev_info->max_rx_queues = hv->max_queues;
|
|
|
|
dev_info->max_tx_queues = hv->max_queues;
|
|
|
|
|
2020-03-31 17:13:59 +00:00
|
|
|
dev_info->tx_desc_lim.nb_min = 1;
|
|
|
|
dev_info->tx_desc_lim.nb_max = 4096;
|
|
|
|
|
2020-01-13 19:12:38 +00:00
|
|
|
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
|
|
|
|
return 0;
|
2019-09-12 16:42:28 +00:00
|
|
|
|
2020-01-13 19:12:38 +00:00
|
|
|
/* fills in rx and tx offload capability */
|
|
|
|
rc = hn_rndis_get_offload(hv, dev_info);
|
2019-09-12 16:42:28 +00:00
|
|
|
if (rc != 0)
|
|
|
|
return rc;
|
|
|
|
|
2020-01-13 19:12:38 +00:00
|
|
|
/* merges the offload and queues of vf */
|
|
|
|
return hn_vf_info_get(hv, dev_info);
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-13 15:03:43 +00:00
|
|
|
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];
|
|
|
|
}
|
|
|
|
|
2019-12-06 23:52:48 +00:00
|
|
|
err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
|
|
|
|
if (err) {
|
|
|
|
PMD_DRV_LOG(NOTICE,
|
|
|
|
"rss disable failed");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-06-13 15:03:43 +00:00
|
|
|
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);
|
|
|
|
|
2020-04-30 19:08:53 +00:00
|
|
|
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;
|
|
|
|
}
|
2019-06-13 15:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2019-09-14 11:37:24 +00:00
|
|
|
static int
|
2018-07-13 17:06:43 +00:00
|
|
|
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);
|
2019-09-14 11:37:24 +00:00
|
|
|
return hn_vf_promiscuous_enable(dev);
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
2019-09-14 11:37:24 +00:00
|
|
|
static int
|
2018-07-13 17:06:43 +00:00
|
|
|
hn_dev_promiscuous_disable(struct rte_eth_dev *dev)
|
|
|
|
{
|
|
|
|
struct hn_data *hv = dev->data->dev_private;
|
|
|
|
uint32_t filter;
|
|
|
|
|
|
|
|
filter = NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_BROADCAST;
|
|
|
|
if (dev->data->all_multicast)
|
|
|
|
filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
|
|
|
|
hn_rndis_set_rxfilter(hv, filter);
|
2019-09-14 11:37:24 +00:00
|
|
|
return hn_vf_promiscuous_disable(dev);
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
2019-09-24 12:56:10 +00:00
|
|
|
static int
|
2018-07-13 17:06:43 +00:00
|
|
|
hn_dev_allmulticast_enable(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_ALL_MULTICAST |
|
|
|
|
NDIS_PACKET_TYPE_BROADCAST);
|
2019-09-24 12:56:10 +00:00
|
|
|
return hn_vf_allmulticast_enable(dev);
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
2019-09-24 12:56:10 +00:00
|
|
|
static int
|
2018-07-13 17:06:43 +00:00
|
|
|
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);
|
2019-09-24 12:56:10 +00:00
|
|
|
return hn_vf_allmulticast_disable(dev);
|
2018-09-21 16:54:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hn_dev_mc_addr_list(struct rte_eth_dev *dev,
|
2019-05-21 16:13:03 +00:00
|
|
|
struct rte_ether_addr *mc_addr_set,
|
2018-09-21 16:54:25 +00:00
|
|
|
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);
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup shared rx/tx queue data */
|
|
|
|
static int hn_subchan_configure(struct hn_data *hv,
|
|
|
|
uint32_t subchan)
|
|
|
|
{
|
|
|
|
struct vmbus_channel *primary = hn_primary_chan(hv);
|
|
|
|
int err;
|
|
|
|
unsigned int retry = 0;
|
|
|
|
|
|
|
|
PMD_DRV_LOG(DEBUG,
|
|
|
|
"open %u subchannels", subchan);
|
|
|
|
|
|
|
|
/* Send create sub channels command */
|
|
|
|
err = hn_nvs_alloc_subchans(hv, &subchan);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
|
|
|
while (subchan > 0) {
|
|
|
|
struct vmbus_channel *new_sc;
|
|
|
|
uint16_t chn_index;
|
|
|
|
|
|
|
|
err = rte_vmbus_subchan_open(primary, &new_sc);
|
|
|
|
if (err == -ENOENT && ++retry < 1000) {
|
|
|
|
/* This can happen if not ready yet */
|
|
|
|
rte_delay_ms(10);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (err) {
|
|
|
|
PMD_DRV_LOG(ERR,
|
|
|
|
"open subchannel failed: %d", err);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2018-08-30 22:35:09 +00:00
|
|
|
rte_vmbus_set_latency(hv->vmbus, new_sc, hv->latency);
|
2018-08-09 17:50:07 +00:00
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
retry = 0;
|
|
|
|
chn_index = rte_vmbus_sub_channel_index(new_sc);
|
|
|
|
if (chn_index == 0 || chn_index > hv->max_queues) {
|
|
|
|
PMD_DRV_LOG(ERR,
|
|
|
|
"Invalid subchannel offermsg channel %u",
|
|
|
|
chn_index);
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
PMD_DRV_LOG(DEBUG, "new sub channel %u", chn_index);
|
|
|
|
hv->channels[chn_index] = new_sc;
|
|
|
|
--subchan;
|
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int hn_dev_configure(struct rte_eth_dev *dev)
|
|
|
|
{
|
2019-06-13 15:03:43 +00:00
|
|
|
struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
|
|
|
|
struct rte_eth_rss_conf *rss_conf = &dev_conf->rx_adv_conf.rss_conf;
|
2018-07-13 17:06:43 +00:00
|
|
|
const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode;
|
|
|
|
const struct rte_eth_txmode *txmode = &dev_conf->txmode;
|
|
|
|
struct hn_data *hv = dev->data->dev_private;
|
|
|
|
uint64_t unsupported;
|
2019-06-13 15:03:43 +00:00
|
|
|
int i, err, subchan;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
PMD_INIT_FUNC_TRACE();
|
|
|
|
|
2019-11-14 16:40:50 +00:00
|
|
|
if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
|
|
|
|
dev_conf->rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
|
2019-11-11 13:19:08 +00:00
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
unsupported = txmode->offloads & ~HN_TX_OFFLOAD_CAPS;
|
|
|
|
if (unsupported) {
|
|
|
|
PMD_DRV_LOG(NOTICE,
|
|
|
|
"unsupported TX offload: %#" PRIx64,
|
|
|
|
unsupported);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
unsupported = rxmode->offloads & ~HN_RX_OFFLOAD_CAPS;
|
|
|
|
if (unsupported) {
|
|
|
|
PMD_DRV_LOG(NOTICE,
|
|
|
|
"unsupported RX offload: %#" PRIx64,
|
|
|
|
rxmode->offloads);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2018-12-14 01:26:19 +00:00
|
|
|
hv->vlan_strip = !!(rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
err = hn_rndis_conf_offload(hv, txmode->offloads,
|
|
|
|
rxmode->offloads);
|
|
|
|
if (err) {
|
|
|
|
PMD_DRV_LOG(NOTICE,
|
|
|
|
"offload configure failed");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
hv->num_queues = RTE_MAX(dev->data->nb_rx_queues,
|
|
|
|
dev->data->nb_tx_queues);
|
2019-06-13 15:03:43 +00:00
|
|
|
|
|
|
|
for (i = 0; i < NDIS_HASH_INDCNT; i++)
|
2020-04-30 19:08:52 +00:00
|
|
|
hv->rss_ind[i] = i % dev->data->nb_rx_queues;
|
2019-06-13 15:03:43 +00:00
|
|
|
|
|
|
|
hn_rss_hash_init(hv, rss_conf);
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
subchan = hv->num_queues - 1;
|
|
|
|
if (subchan > 0) {
|
|
|
|
err = hn_subchan_configure(hv, subchan);
|
|
|
|
if (err) {
|
|
|
|
PMD_DRV_LOG(NOTICE,
|
|
|
|
"subchannel configuration failed");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2019-12-06 23:52:48 +00:00
|
|
|
err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
|
|
|
|
if (err) {
|
|
|
|
PMD_DRV_LOG(NOTICE,
|
|
|
|
"rss disable failed");
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2020-04-30 19:08:53 +00:00
|
|
|
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;
|
|
|
|
}
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 22:35:12 +00:00
|
|
|
return hn_vf_configure(dev, dev_conf);
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int hn_dev_stats_get(struct rte_eth_dev *dev,
|
|
|
|
struct rte_eth_stats *stats)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
2018-08-30 22:35:12 +00:00
|
|
|
hn_vf_stats_get(dev, stats);
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
for (i = 0; i < dev->data->nb_tx_queues; i++) {
|
|
|
|
const struct hn_tx_queue *txq = dev->data->tx_queues[i];
|
|
|
|
|
|
|
|
if (!txq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stats->opackets += txq->stats.packets;
|
|
|
|
stats->obytes += txq->stats.bytes;
|
2018-08-30 22:35:10 +00:00
|
|
|
stats->oerrors += txq->stats.errors;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
|
|
|
|
stats->q_opackets[i] = txq->stats.packets;
|
|
|
|
stats->q_obytes[i] = txq->stats.bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dev->data->nb_rx_queues; i++) {
|
|
|
|
const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
|
|
|
|
|
|
|
|
if (!rxq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stats->ipackets += rxq->stats.packets;
|
|
|
|
stats->ibytes += rxq->stats.bytes;
|
|
|
|
stats->ierrors += rxq->stats.errors;
|
2018-08-30 22:35:10 +00:00
|
|
|
stats->imissed += rxq->stats.ring_full;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
|
|
|
|
stats->q_ipackets[i] = rxq->stats.packets;
|
|
|
|
stats->q_ibytes[i] = rxq->stats.bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-09-06 14:34:54 +00:00
|
|
|
static int
|
2018-07-13 17:06:43 +00:00
|
|
|
hn_dev_stats_reset(struct rte_eth_dev *dev)
|
|
|
|
{
|
|
|
|
unsigned int i;
|
|
|
|
|
|
|
|
PMD_INIT_FUNC_TRACE();
|
|
|
|
|
|
|
|
for (i = 0; i < dev->data->nb_tx_queues; i++) {
|
|
|
|
struct hn_tx_queue *txq = dev->data->tx_queues[i];
|
|
|
|
|
|
|
|
if (!txq)
|
|
|
|
continue;
|
|
|
|
memset(&txq->stats, 0, sizeof(struct hn_stats));
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dev->data->nb_rx_queues; i++) {
|
|
|
|
struct hn_rx_queue *rxq = dev->data->rx_queues[i];
|
|
|
|
|
|
|
|
if (!rxq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
memset(&rxq->stats, 0, sizeof(struct hn_stats));
|
|
|
|
}
|
2019-09-06 14:34:54 +00:00
|
|
|
|
|
|
|
return 0;
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
2019-09-06 14:34:54 +00:00
|
|
|
static int
|
2018-08-30 22:35:12 +00:00
|
|
|
hn_dev_xstats_reset(struct rte_eth_dev *dev)
|
|
|
|
{
|
2019-09-06 14:34:54 +00:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = hn_dev_stats_reset(dev);
|
|
|
|
if (ret != 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return hn_vf_xstats_reset(dev);
|
2018-08-30 22:35:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
static int
|
|
|
|
hn_dev_xstats_get_names(struct rte_eth_dev *dev,
|
|
|
|
struct rte_eth_xstat_name *xstats_names,
|
2018-08-30 22:35:12 +00:00
|
|
|
unsigned int limit)
|
2018-07-13 17:06:43 +00:00
|
|
|
{
|
|
|
|
unsigned int i, t, count = 0;
|
2018-08-30 22:35:12 +00:00
|
|
|
int ret;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
if (!xstats_names)
|
2018-08-30 22:35:12 +00:00
|
|
|
return hn_dev_xstats_count(dev);
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
/* Note: limit checked in rte_eth_xstats_names() */
|
|
|
|
for (i = 0; i < dev->data->nb_tx_queues; i++) {
|
|
|
|
const struct hn_tx_queue *txq = dev->data->tx_queues[i];
|
|
|
|
|
|
|
|
if (!txq)
|
|
|
|
continue;
|
|
|
|
|
2018-08-30 22:35:12 +00:00
|
|
|
if (count >= limit)
|
|
|
|
break;
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
for (t = 0; t < RTE_DIM(hn_stat_strings); t++)
|
|
|
|
snprintf(xstats_names[count++].name,
|
|
|
|
RTE_ETH_XSTATS_NAME_SIZE,
|
|
|
|
"tx_q%u_%s", i, hn_stat_strings[t].name);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dev->data->nb_rx_queues; i++) {
|
|
|
|
const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
|
|
|
|
|
|
|
|
if (!rxq)
|
|
|
|
continue;
|
|
|
|
|
2018-08-30 22:35:12 +00:00
|
|
|
if (count >= limit)
|
|
|
|
break;
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
for (t = 0; t < RTE_DIM(hn_stat_strings); t++)
|
|
|
|
snprintf(xstats_names[count++].name,
|
|
|
|
RTE_ETH_XSTATS_NAME_SIZE,
|
|
|
|
"rx_q%u_%s", i,
|
|
|
|
hn_stat_strings[t].name);
|
|
|
|
}
|
|
|
|
|
2018-08-30 22:35:12 +00:00
|
|
|
ret = hn_vf_xstats_get_names(dev, xstats_names + count,
|
|
|
|
limit - count);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return count + ret;
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hn_dev_xstats_get(struct rte_eth_dev *dev,
|
|
|
|
struct rte_eth_xstat *xstats,
|
|
|
|
unsigned int n)
|
|
|
|
{
|
|
|
|
unsigned int i, t, count = 0;
|
2018-08-30 22:35:12 +00:00
|
|
|
const unsigned int nstats = hn_dev_xstats_count(dev);
|
2018-07-13 17:06:43 +00:00
|
|
|
const char *stats;
|
2018-08-30 22:35:12 +00:00
|
|
|
int ret;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
PMD_INIT_FUNC_TRACE();
|
|
|
|
|
|
|
|
if (n < nstats)
|
|
|
|
return nstats;
|
|
|
|
|
|
|
|
for (i = 0; i < dev->data->nb_tx_queues; i++) {
|
|
|
|
const struct hn_tx_queue *txq = dev->data->tx_queues[i];
|
|
|
|
|
|
|
|
if (!txq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stats = (const char *)&txq->stats;
|
2019-06-20 22:09:23 +00:00
|
|
|
for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) {
|
|
|
|
xstats[count].id = count;
|
|
|
|
xstats[count].value = *(const uint64_t *)
|
2018-07-13 17:06:43 +00:00
|
|
|
(stats + hn_stat_strings[t].offset);
|
2019-06-20 22:09:23 +00:00
|
|
|
}
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < dev->data->nb_rx_queues; i++) {
|
|
|
|
const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
|
|
|
|
|
|
|
|
if (!rxq)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
stats = (const char *)&rxq->stats;
|
2019-06-20 22:09:23 +00:00
|
|
|
for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) {
|
|
|
|
xstats[count].id = count;
|
|
|
|
xstats[count].value = *(const uint64_t *)
|
2018-07-13 17:06:43 +00:00
|
|
|
(stats + hn_stat_strings[t].offset);
|
2019-06-20 22:09:23 +00:00
|
|
|
}
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
2019-06-20 22:09:24 +00:00
|
|
|
ret = hn_vf_xstats_get(dev, xstats, count, n);
|
2018-08-30 22:35:12 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
return count + ret;
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
hn_dev_start(struct rte_eth_dev *dev)
|
|
|
|
{
|
|
|
|
struct hn_data *hv = dev->data->dev_private;
|
2018-08-30 22:35:12 +00:00
|
|
|
int error;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
PMD_INIT_FUNC_TRACE();
|
|
|
|
|
2018-08-30 22:35:12 +00:00
|
|
|
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);
|
|
|
|
|
2020-02-07 18:08:16 +00:00
|
|
|
/* Initialize Link state */
|
|
|
|
if (error == 0)
|
|
|
|
hn_dev_link_update(dev, 0);
|
|
|
|
|
2018-08-30 22:35:12 +00:00
|
|
|
return error;
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hn_dev_stop(struct rte_eth_dev *dev)
|
|
|
|
{
|
|
|
|
struct hn_data *hv = dev->data->dev_private;
|
|
|
|
|
|
|
|
PMD_INIT_FUNC_TRACE();
|
|
|
|
|
|
|
|
hn_rndis_set_rxfilter(hv, 0);
|
2018-08-30 22:35:12 +00:00
|
|
|
hn_vf_stop(dev);
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-04-30 18:12:17 +00:00
|
|
|
hn_dev_close(struct rte_eth_dev *dev)
|
2018-07-13 17:06:43 +00:00
|
|
|
{
|
2019-04-30 18:12:17 +00:00
|
|
|
PMD_INIT_FUNC_TRACE();
|
2018-08-30 22:35:12 +00:00
|
|
|
|
|
|
|
hn_vf_close(dev);
|
2019-04-30 18:12:17 +00:00
|
|
|
hn_dev_free_queues(dev);
|
2018-07-13 17:06:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct eth_dev_ops hn_eth_dev_ops = {
|
|
|
|
.dev_configure = hn_dev_configure,
|
|
|
|
.dev_start = hn_dev_start,
|
|
|
|
.dev_stop = hn_dev_stop,
|
|
|
|
.dev_close = hn_dev_close,
|
|
|
|
.dev_infos_get = hn_dev_info_get,
|
2020-05-19 16:52:24 +00:00
|
|
|
.txq_info_get = hn_dev_tx_queue_info,
|
|
|
|
.rxq_info_get = hn_dev_rx_queue_info,
|
2018-08-30 22:35:12 +00:00
|
|
|
.dev_supported_ptypes_get = hn_vf_supported_ptypes,
|
2018-07-13 17:06:43 +00:00
|
|
|
.promiscuous_enable = hn_dev_promiscuous_enable,
|
|
|
|
.promiscuous_disable = hn_dev_promiscuous_disable,
|
|
|
|
.allmulticast_enable = hn_dev_allmulticast_enable,
|
|
|
|
.allmulticast_disable = hn_dev_allmulticast_disable,
|
2018-09-21 16:54:25 +00:00
|
|
|
.set_mc_addr_list = hn_dev_mc_addr_list,
|
2019-06-13 15:03:43 +00:00
|
|
|
.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,
|
2018-07-13 17:06:43 +00:00
|
|
|
.tx_queue_setup = hn_dev_tx_queue_setup,
|
|
|
|
.tx_queue_release = hn_dev_tx_queue_release,
|
2018-08-09 17:50:08 +00:00
|
|
|
.tx_done_cleanup = hn_dev_tx_done_cleanup,
|
2020-05-19 16:52:25 +00:00
|
|
|
.tx_descriptor_status = hn_dev_tx_descriptor_status,
|
2018-07-13 17:06:43 +00:00
|
|
|
.rx_queue_setup = hn_dev_rx_queue_setup,
|
|
|
|
.rx_queue_release = hn_dev_rx_queue_release,
|
2020-05-19 16:52:25 +00:00
|
|
|
.rx_queue_count = hn_dev_rx_queue_count,
|
|
|
|
.rx_descriptor_status = hn_dev_rx_queue_status,
|
2018-07-13 17:06:43 +00:00
|
|
|
.link_update = hn_dev_link_update,
|
|
|
|
.stats_get = hn_dev_stats_get,
|
2018-08-30 22:35:12 +00:00
|
|
|
.stats_reset = hn_dev_stats_reset,
|
2018-07-13 17:06:43 +00:00
|
|
|
.xstats_get = hn_dev_xstats_get,
|
|
|
|
.xstats_get_names = hn_dev_xstats_get_names,
|
2018-08-30 22:35:12 +00:00
|
|
|
.xstats_reset = hn_dev_xstats_reset,
|
2018-07-13 17:06:43 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setup connection between PMD and kernel.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
hn_attach(struct hn_data *hv, unsigned int mtu)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
|
|
|
|
/* Attach NVS */
|
|
|
|
error = hn_nvs_attach(hv, mtu);
|
|
|
|
if (error)
|
|
|
|
goto failed_nvs;
|
|
|
|
|
|
|
|
/* Attach RNDIS */
|
|
|
|
error = hn_rndis_attach(hv);
|
|
|
|
if (error)
|
|
|
|
goto failed_rndis;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE:
|
|
|
|
* Under certain conditions on certain versions of Hyper-V,
|
|
|
|
* the RNDIS rxfilter is _not_ zero on the hypervisor side
|
|
|
|
* after the successful RNDIS initialization.
|
|
|
|
*/
|
|
|
|
hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_NONE);
|
|
|
|
return 0;
|
|
|
|
failed_rndis:
|
|
|
|
hn_nvs_detach(hv);
|
|
|
|
failed_nvs:
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
hn_detach(struct hn_data *hv)
|
|
|
|
{
|
|
|
|
hn_nvs_detach(hv);
|
|
|
|
hn_rndis_detach(hv);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
eth_hn_dev_init(struct rte_eth_dev *eth_dev)
|
|
|
|
{
|
|
|
|
struct hn_data *hv = eth_dev->data->dev_private;
|
|
|
|
struct rte_device *device = eth_dev->device;
|
|
|
|
struct rte_vmbus_device *vmbus;
|
|
|
|
unsigned int rxr_cnt;
|
|
|
|
int err, max_chan;
|
|
|
|
|
|
|
|
PMD_INIT_FUNC_TRACE();
|
|
|
|
|
|
|
|
vmbus = container_of(device, struct rte_vmbus_device, device);
|
|
|
|
eth_dev->dev_ops = &hn_eth_dev_ops;
|
|
|
|
eth_dev->tx_pkt_burst = &hn_xmit_pkts;
|
|
|
|
eth_dev->rx_pkt_burst = &hn_recv_pkts;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for secondary processes, we don't initialize any further as primary
|
|
|
|
* has already done this work.
|
|
|
|
*/
|
|
|
|
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
|
|
|
|
return 0;
|
|
|
|
|
2020-03-31 17:14:00 +00:00
|
|
|
/* 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;
|
|
|
|
}
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
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;
|
2018-08-30 22:35:09 +00:00
|
|
|
hv->latency = HN_CHAN_LATENCY_NS;
|
2018-12-05 22:11:58 +00:00
|
|
|
hv->max_queues = 1;
|
2020-04-30 19:08:51 +00:00
|
|
|
rte_rwlock_init(&hv->vf_lock);
|
2019-02-08 03:44:02 +00:00
|
|
|
hv->vf_port = HN_INVALID_PORT;
|
2018-08-30 22:35:09 +00:00
|
|
|
|
|
|
|
err = hn_parse_args(eth_dev);
|
|
|
|
if (err)
|
|
|
|
return err;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
2018-08-30 22:35:12 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
/* Initialize primary channel input for control operations */
|
|
|
|
err = rte_vmbus_chan_open(vmbus, &hv->channels[0]);
|
|
|
|
if (err)
|
|
|
|
return err;
|
|
|
|
|
2018-08-30 22:35:09 +00:00
|
|
|
rte_vmbus_set_latency(hv->vmbus, hv->channels[0], hv->latency);
|
2018-08-09 17:50:07 +00:00
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
hv->primary = hn_rx_queue_alloc(hv, 0,
|
|
|
|
eth_dev->device->numa_node);
|
|
|
|
|
|
|
|
if (!hv->primary)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2019-05-21 16:13:05 +00:00
|
|
|
err = hn_attach(hv, RTE_ETHER_MTU);
|
2018-07-13 17:06:43 +00:00
|
|
|
if (err)
|
|
|
|
goto failed;
|
|
|
|
|
2020-03-31 17:13:59 +00:00
|
|
|
err = hn_chim_init(eth_dev);
|
2018-07-13 17:06:43 +00:00
|
|
|
if (err)
|
|
|
|
goto failed;
|
|
|
|
|
2020-03-31 17:14:00 +00:00
|
|
|
err = hn_rndis_get_eaddr(hv, eth_dev->data->mac_addrs->addr_bytes);
|
2018-07-13 17:06:43 +00:00
|
|
|
if (err)
|
|
|
|
goto failed;
|
|
|
|
|
2018-12-05 22:11:58 +00:00
|
|
|
/* Multi queue requires later versions of windows server */
|
|
|
|
if (hv->nvs_ver < NVS_VERSION_5)
|
|
|
|
return 0;
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
max_chan = rte_vmbus_max_channels(vmbus);
|
|
|
|
PMD_INIT_LOG(DEBUG, "VMBus max channels %d", max_chan);
|
|
|
|
if (max_chan <= 0)
|
|
|
|
goto failed;
|
|
|
|
|
|
|
|
if (hn_rndis_query_rsscaps(hv, &rxr_cnt) != 0)
|
|
|
|
rxr_cnt = 1;
|
|
|
|
|
|
|
|
hv->max_queues = RTE_MIN(rxr_cnt, (unsigned int)max_chan);
|
|
|
|
|
2018-08-30 22:35:12 +00:00
|
|
|
/* If VF was reported but not added, do it now */
|
2019-02-08 03:44:02 +00:00
|
|
|
if (hv->vf_present && !hn_vf_attached(hv)) {
|
2018-08-30 22:35:12 +00:00
|
|
|
PMD_INIT_LOG(DEBUG, "Adding VF device");
|
|
|
|
|
|
|
|
err = hn_vf_add(eth_dev, hv);
|
|
|
|
if (err)
|
2018-12-14 01:26:21 +00:00
|
|
|
hv->vf_present = 0;
|
2018-08-30 22:35:12 +00:00
|
|
|
}
|
|
|
|
|
2018-07-13 17:06:43 +00:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
failed:
|
|
|
|
PMD_INIT_LOG(NOTICE, "device init failed");
|
|
|
|
|
2020-03-31 17:13:59 +00:00
|
|
|
hn_chim_uninit(eth_dev);
|
2018-07-13 17:06:43 +00:00
|
|
|
hn_detach(hv);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
eth_hn_dev_uninit(struct rte_eth_dev *eth_dev)
|
|
|
|
{
|
|
|
|
struct hn_data *hv = eth_dev->data->dev_private;
|
2019-09-10 09:02:16 +00:00
|
|
|
int ret;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
PMD_INIT_FUNC_TRACE();
|
|
|
|
|
|
|
|
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
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);
|
2020-03-31 17:13:59 +00:00
|
|
|
hn_chim_uninit(eth_dev);
|
2018-07-13 17:06:43 +00:00
|
|
|
rte_vmbus_chan_close(hv->primary->chan);
|
|
|
|
rte_free(hv->primary);
|
2019-09-10 09:02:16 +00:00
|
|
|
ret = rte_eth_dev_owner_delete(hv->owner.id);
|
|
|
|
if (ret != 0)
|
|
|
|
return ret;
|
2018-07-13 17:06:43 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int eth_hn_probe(struct rte_vmbus_driver *drv __rte_unused,
|
|
|
|
struct rte_vmbus_device *dev)
|
|
|
|
{
|
|
|
|
struct rte_eth_dev *eth_dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
PMD_INIT_FUNC_TRACE();
|
|
|
|
|
|
|
|
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)
|
|
|
|
eth_dev_vmbus_release(eth_dev);
|
|
|
|
else
|
|
|
|
rte_eth_dev_probing_finish(eth_dev);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int eth_hn_remove(struct rte_vmbus_device *dev)
|
|
|
|
{
|
|
|
|
struct rte_eth_dev *eth_dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
PMD_INIT_FUNC_TRACE();
|
|
|
|
|
|
|
|
eth_dev = rte_eth_dev_allocated(dev->device.name);
|
|
|
|
if (!eth_dev)
|
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
ret = eth_hn_dev_uninit(eth_dev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
eth_dev_vmbus_release(eth_dev);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Network device GUID */
|
|
|
|
static const rte_uuid_t hn_net_ids[] = {
|
|
|
|
/* f8615163-df3e-46c5-913f-f2d2f965ed0e */
|
|
|
|
RTE_UUID_INIT(0xf8615163, 0xdf3e, 0x46c5, 0x913f, 0xf2d2f965ed0eULL),
|
|
|
|
{ 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct rte_vmbus_driver rte_netvsc_pmd = {
|
|
|
|
.id_table = hn_net_ids,
|
|
|
|
.probe = eth_hn_probe,
|
|
|
|
.remove = eth_hn_remove,
|
|
|
|
};
|
|
|
|
|
|
|
|
RTE_PMD_REGISTER_VMBUS(net_netvsc, rte_netvsc_pmd);
|
|
|
|
RTE_PMD_REGISTER_KMOD_DEP(net_netvsc, "* uio_hv_generic");
|
2020-07-01 12:33:35 +00:00
|
|
|
RTE_LOG_REGISTER(hn_logtype_init, pmd.net.netvsc.init, NOTICE);
|
|
|
|
RTE_LOG_REGISTER(hn_logtype_driver, pmd.net.netvsc.driver, NOTICE);
|