1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2016-2018 Microsoft Corporation
3 * Copyright(c) 2013-2016 Brocade Communications Systems, Inc.
13 #include <rte_ethdev.h>
14 #include <rte_memcpy.h>
15 #include <rte_string_fns.h>
16 #include <rte_memzone.h>
17 #include <rte_devargs.h>
18 #include <rte_malloc.h>
19 #include <rte_kvargs.h>
20 #include <rte_atomic.h>
21 #include <rte_branch_prediction.h>
22 #include <rte_ether.h>
23 #include <rte_ethdev_driver.h>
24 #include <rte_cycles.h>
25 #include <rte_errno.h>
26 #include <rte_memory.h>
29 #include <rte_bus_vmbus.h>
37 #define HN_TX_OFFLOAD_CAPS (DEV_TX_OFFLOAD_IPV4_CKSUM | \
38 DEV_TX_OFFLOAD_TCP_CKSUM | \
39 DEV_TX_OFFLOAD_UDP_CKSUM | \
40 DEV_TX_OFFLOAD_TCP_TSO | \
41 DEV_TX_OFFLOAD_MULTI_SEGS | \
42 DEV_TX_OFFLOAD_VLAN_INSERT)
44 #define HN_RX_OFFLOAD_CAPS (DEV_RX_OFFLOAD_CHECKSUM | \
45 DEV_RX_OFFLOAD_VLAN_STRIP | \
46 DEV_RX_OFFLOAD_RSS_HASH)
48 #define NETVSC_ARG_LATENCY "latency"
49 #define NETVSC_ARG_RXBREAK "rx_copybreak"
50 #define NETVSC_ARG_TXBREAK "tx_copybreak"
51 #define NETVSC_ARG_RX_EXTMBUF_ENABLE "rx_extmbuf_enable"
53 struct hn_xstats_name_off {
54 char name[RTE_ETH_XSTATS_NAME_SIZE];
58 static const struct hn_xstats_name_off hn_stat_strings[] = {
59 { "good_packets", offsetof(struct hn_stats, packets) },
60 { "good_bytes", offsetof(struct hn_stats, bytes) },
61 { "errors", offsetof(struct hn_stats, errors) },
62 { "ring full", offsetof(struct hn_stats, ring_full) },
63 { "channel full", offsetof(struct hn_stats, channel_full) },
64 { "multicast_packets", offsetof(struct hn_stats, multicast) },
65 { "broadcast_packets", offsetof(struct hn_stats, broadcast) },
66 { "undersize_packets", offsetof(struct hn_stats, size_bins[0]) },
67 { "size_64_packets", offsetof(struct hn_stats, size_bins[1]) },
68 { "size_65_127_packets", offsetof(struct hn_stats, size_bins[2]) },
69 { "size_128_255_packets", offsetof(struct hn_stats, size_bins[3]) },
70 { "size_256_511_packets", offsetof(struct hn_stats, size_bins[4]) },
71 { "size_512_1023_packets", offsetof(struct hn_stats, size_bins[5]) },
72 { "size_1024_1518_packets", offsetof(struct hn_stats, size_bins[6]) },
73 { "size_1519_max_packets", offsetof(struct hn_stats, size_bins[7]) },
76 /* The default RSS key.
77 * This value is the same as MLX5 so that flows will be
78 * received on same path for both VF and synthetic NIC.
80 static const uint8_t rss_default_key[NDIS_HASH_KEYSIZE_TOEPLITZ] = {
81 0x2c, 0xc6, 0x81, 0xd1, 0x5b, 0xdb, 0xf4, 0xf7,
82 0xfc, 0xa2, 0x83, 0x19, 0xdb, 0x1a, 0x3e, 0x94,
83 0x6b, 0x9e, 0x38, 0xd9, 0x2c, 0x9c, 0x03, 0xd1,
84 0xad, 0x99, 0x44, 0xa7, 0xd9, 0x56, 0x3d, 0x59,
85 0x06, 0x3c, 0x25, 0xf3, 0xfc, 0x1f, 0xdc, 0x2a,
88 static struct rte_eth_dev *
89 eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size)
91 struct rte_eth_dev *eth_dev;
97 name = dev->device.name;
99 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
100 eth_dev = rte_eth_dev_allocate(name);
102 PMD_DRV_LOG(NOTICE, "can not allocate rte ethdev");
106 if (private_data_size) {
107 eth_dev->data->dev_private =
108 rte_zmalloc_socket(name, private_data_size,
109 RTE_CACHE_LINE_SIZE, dev->device.numa_node);
110 if (!eth_dev->data->dev_private) {
111 PMD_DRV_LOG(NOTICE, "can not allocate driver data");
112 rte_eth_dev_release_port(eth_dev);
117 eth_dev = rte_eth_dev_attach_secondary(name);
119 PMD_DRV_LOG(NOTICE, "can not attach secondary");
124 eth_dev->device = &dev->device;
126 /* interrupt is simulated */
127 dev->intr_handle.type = RTE_INTR_HANDLE_EXT;
128 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
129 eth_dev->intr_handle = &dev->intr_handle;
135 eth_dev_vmbus_release(struct rte_eth_dev *eth_dev)
137 /* free ether device */
138 rte_eth_dev_release_port(eth_dev);
140 eth_dev->device = NULL;
141 eth_dev->intr_handle = NULL;
144 static int hn_set_parameter(const char *key, const char *value, void *opaque)
146 struct hn_data *hv = opaque;
150 v = strtoul(value, &endp, 0);
151 if (*value == '\0' || *endp != '\0') {
152 PMD_DRV_LOG(ERR, "invalid parameter %s=%s", key, value);
156 if (!strcmp(key, NETVSC_ARG_LATENCY)) {
158 hv->latency = v * 1000;
159 PMD_DRV_LOG(DEBUG, "set latency %u usec", hv->latency);
160 } else if (!strcmp(key, NETVSC_ARG_RXBREAK)) {
161 hv->rx_copybreak = v;
162 PMD_DRV_LOG(DEBUG, "rx copy break set to %u",
164 } else if (!strcmp(key, NETVSC_ARG_TXBREAK)) {
165 hv->tx_copybreak = v;
166 PMD_DRV_LOG(DEBUG, "tx copy break set to %u",
168 } else if (!strcmp(key, NETVSC_ARG_RX_EXTMBUF_ENABLE)) {
169 hv->rx_extmbuf_enable = v;
170 PMD_DRV_LOG(DEBUG, "rx extmbuf enable set to %u",
171 hv->rx_extmbuf_enable);
177 /* Parse device arguments */
178 static int hn_parse_args(const struct rte_eth_dev *dev)
180 struct hn_data *hv = dev->data->dev_private;
181 struct rte_devargs *devargs = dev->device->devargs;
182 static const char * const valid_keys[] = {
186 NETVSC_ARG_RX_EXTMBUF_ENABLE,
189 struct rte_kvargs *kvlist;
195 PMD_INIT_LOG(DEBUG, "device args %s %s",
196 devargs->name, devargs->args);
198 kvlist = rte_kvargs_parse(devargs->args, valid_keys);
200 PMD_DRV_LOG(ERR, "invalid parameters");
204 ret = rte_kvargs_process(kvlist, NULL, hn_set_parameter, hv);
205 rte_kvargs_free(kvlist);
210 /* Update link status.
211 * Note: the DPDK definition of "wait_to_complete"
212 * means block this call until link is up.
213 * which is not worth supporting.
216 hn_dev_link_update(struct rte_eth_dev *dev,
217 int wait_to_complete __rte_unused)
219 struct hn_data *hv = dev->data->dev_private;
220 struct rte_eth_link link, old;
223 old = dev->data->dev_link;
225 error = hn_rndis_get_linkstatus(hv);
229 hn_rndis_get_linkspeed(hv);
231 link = (struct rte_eth_link) {
232 .link_duplex = ETH_LINK_FULL_DUPLEX,
233 .link_autoneg = ETH_LINK_SPEED_FIXED,
234 .link_speed = hv->link_speed / 10000,
237 if (hv->link_status == NDIS_MEDIA_STATE_CONNECTED)
238 link.link_status = ETH_LINK_UP;
240 link.link_status = ETH_LINK_DOWN;
242 if (old.link_status == link.link_status)
245 PMD_INIT_LOG(DEBUG, "Port %d is %s", dev->data->port_id,
246 (link.link_status == ETH_LINK_UP) ? "up" : "down");
248 return rte_eth_linkstatus_set(dev, &link);
251 static int hn_dev_info_get(struct rte_eth_dev *dev,
252 struct rte_eth_dev_info *dev_info)
254 struct hn_data *hv = dev->data->dev_private;
257 dev_info->speed_capa = ETH_LINK_SPEED_10G;
258 dev_info->min_rx_bufsize = HN_MIN_RX_BUF_SIZE;
259 dev_info->max_rx_pktlen = HN_MAX_XFER_LEN;
260 dev_info->max_mac_addrs = 1;
262 dev_info->hash_key_size = NDIS_HASH_KEYSIZE_TOEPLITZ;
263 dev_info->flow_type_rss_offloads = hv->rss_offloads;
264 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
266 dev_info->max_rx_queues = hv->max_queues;
267 dev_info->max_tx_queues = hv->max_queues;
269 dev_info->tx_desc_lim.nb_min = 1;
270 dev_info->tx_desc_lim.nb_max = 4096;
272 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
275 /* fills in rx and tx offload capability */
276 rc = hn_rndis_get_offload(hv, dev_info);
280 /* merges the offload and queues of vf */
281 return hn_vf_info_get(hv, dev_info);
284 static int hn_rss_reta_update(struct rte_eth_dev *dev,
285 struct rte_eth_rss_reta_entry64 *reta_conf,
288 struct hn_data *hv = dev->data->dev_private;
292 PMD_INIT_FUNC_TRACE();
294 if (reta_size != NDIS_HASH_INDCNT) {
295 PMD_DRV_LOG(ERR, "Hash lookup table size does not match NDIS");
299 for (i = 0; i < NDIS_HASH_INDCNT; i++) {
300 uint16_t idx = i / RTE_RETA_GROUP_SIZE;
301 uint16_t shift = i % RTE_RETA_GROUP_SIZE;
302 uint64_t mask = (uint64_t)1 << shift;
304 if (reta_conf[idx].mask & mask)
305 hv->rss_ind[i] = reta_conf[idx].reta[shift];
308 err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
311 "rss disable failed");
315 err = hn_rndis_conf_rss(hv, 0);
318 "reta reconfig failed");
322 return hn_vf_reta_hash_update(dev, reta_conf, reta_size);
325 static int hn_rss_reta_query(struct rte_eth_dev *dev,
326 struct rte_eth_rss_reta_entry64 *reta_conf,
329 struct hn_data *hv = dev->data->dev_private;
332 PMD_INIT_FUNC_TRACE();
334 if (reta_size != NDIS_HASH_INDCNT) {
335 PMD_DRV_LOG(ERR, "Hash lookup table size does not match NDIS");
339 for (i = 0; i < NDIS_HASH_INDCNT; i++) {
340 uint16_t idx = i / RTE_RETA_GROUP_SIZE;
341 uint16_t shift = i % RTE_RETA_GROUP_SIZE;
342 uint64_t mask = (uint64_t)1 << shift;
344 if (reta_conf[idx].mask & mask)
345 reta_conf[idx].reta[shift] = hv->rss_ind[i];
350 static void hn_rss_hash_init(struct hn_data *hv,
351 const struct rte_eth_rss_conf *rss_conf)
353 /* Convert from DPDK RSS hash flags to NDIS hash flags */
354 hv->rss_hash = NDIS_HASH_FUNCTION_TOEPLITZ;
356 if (rss_conf->rss_hf & ETH_RSS_IPV4)
357 hv->rss_hash |= NDIS_HASH_IPV4;
358 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
359 hv->rss_hash |= NDIS_HASH_TCP_IPV4;
360 if (rss_conf->rss_hf & ETH_RSS_IPV6)
361 hv->rss_hash |= NDIS_HASH_IPV6;
362 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX)
363 hv->rss_hash |= NDIS_HASH_IPV6_EX;
364 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
365 hv->rss_hash |= NDIS_HASH_TCP_IPV6;
366 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX)
367 hv->rss_hash |= NDIS_HASH_TCP_IPV6_EX;
369 memcpy(hv->rss_key, rss_conf->rss_key ? : rss_default_key,
370 NDIS_HASH_KEYSIZE_TOEPLITZ);
373 static int hn_rss_hash_update(struct rte_eth_dev *dev,
374 struct rte_eth_rss_conf *rss_conf)
376 struct hn_data *hv = dev->data->dev_private;
379 PMD_INIT_FUNC_TRACE();
381 err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
384 "rss disable failed");
388 hn_rss_hash_init(hv, rss_conf);
390 if (rss_conf->rss_hf != 0) {
391 err = hn_rndis_conf_rss(hv, 0);
394 "rss reconfig failed (RSS disabled)");
399 return hn_vf_rss_hash_update(dev, rss_conf);
402 static int hn_rss_hash_conf_get(struct rte_eth_dev *dev,
403 struct rte_eth_rss_conf *rss_conf)
405 struct hn_data *hv = dev->data->dev_private;
407 PMD_INIT_FUNC_TRACE();
409 if (hv->ndis_ver < NDIS_VERSION_6_20) {
410 PMD_DRV_LOG(DEBUG, "RSS not supported on this host");
414 rss_conf->rss_key_len = NDIS_HASH_KEYSIZE_TOEPLITZ;
415 if (rss_conf->rss_key)
416 memcpy(rss_conf->rss_key, hv->rss_key,
417 NDIS_HASH_KEYSIZE_TOEPLITZ);
419 rss_conf->rss_hf = 0;
420 if (hv->rss_hash & NDIS_HASH_IPV4)
421 rss_conf->rss_hf |= ETH_RSS_IPV4;
423 if (hv->rss_hash & NDIS_HASH_TCP_IPV4)
424 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
426 if (hv->rss_hash & NDIS_HASH_IPV6)
427 rss_conf->rss_hf |= ETH_RSS_IPV6;
429 if (hv->rss_hash & NDIS_HASH_IPV6_EX)
430 rss_conf->rss_hf |= ETH_RSS_IPV6_EX;
432 if (hv->rss_hash & NDIS_HASH_TCP_IPV6)
433 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
435 if (hv->rss_hash & NDIS_HASH_TCP_IPV6_EX)
436 rss_conf->rss_hf |= ETH_RSS_IPV6_TCP_EX;
442 hn_dev_promiscuous_enable(struct rte_eth_dev *dev)
444 struct hn_data *hv = dev->data->dev_private;
446 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_PROMISCUOUS);
447 return hn_vf_promiscuous_enable(dev);
451 hn_dev_promiscuous_disable(struct rte_eth_dev *dev)
453 struct hn_data *hv = dev->data->dev_private;
456 filter = NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_BROADCAST;
457 if (dev->data->all_multicast)
458 filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
459 hn_rndis_set_rxfilter(hv, filter);
460 return hn_vf_promiscuous_disable(dev);
464 hn_dev_allmulticast_enable(struct rte_eth_dev *dev)
466 struct hn_data *hv = dev->data->dev_private;
468 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_DIRECTED |
469 NDIS_PACKET_TYPE_ALL_MULTICAST |
470 NDIS_PACKET_TYPE_BROADCAST);
471 return hn_vf_allmulticast_enable(dev);
475 hn_dev_allmulticast_disable(struct rte_eth_dev *dev)
477 struct hn_data *hv = dev->data->dev_private;
479 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_DIRECTED |
480 NDIS_PACKET_TYPE_BROADCAST);
481 return hn_vf_allmulticast_disable(dev);
485 hn_dev_mc_addr_list(struct rte_eth_dev *dev,
486 struct rte_ether_addr *mc_addr_set,
489 /* No filtering on the synthetic path, but can do it on VF */
490 return hn_vf_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
493 /* Setup shared rx/tx queue data */
494 static int hn_subchan_configure(struct hn_data *hv,
497 struct vmbus_channel *primary = hn_primary_chan(hv);
499 unsigned int retry = 0;
502 "open %u subchannels", subchan);
504 /* Send create sub channels command */
505 err = hn_nvs_alloc_subchans(hv, &subchan);
509 while (subchan > 0) {
510 struct vmbus_channel *new_sc;
513 err = rte_vmbus_subchan_open(primary, &new_sc);
514 if (err == -ENOENT && ++retry < 1000) {
515 /* This can happen if not ready yet */
522 "open subchannel failed: %d", err);
526 rte_vmbus_set_latency(hv->vmbus, new_sc, hv->latency);
529 chn_index = rte_vmbus_sub_channel_index(new_sc);
530 if (chn_index == 0 || chn_index > hv->max_queues) {
532 "Invalid subchannel offermsg channel %u",
537 PMD_DRV_LOG(DEBUG, "new sub channel %u", chn_index);
538 hv->channels[chn_index] = new_sc;
545 static int hn_dev_configure(struct rte_eth_dev *dev)
547 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
548 struct rte_eth_rss_conf *rss_conf = &dev_conf->rx_adv_conf.rss_conf;
549 const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode;
550 const struct rte_eth_txmode *txmode = &dev_conf->txmode;
551 struct hn_data *hv = dev->data->dev_private;
552 uint64_t unsupported;
555 PMD_INIT_FUNC_TRACE();
557 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
558 dev_conf->rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
560 unsupported = txmode->offloads & ~HN_TX_OFFLOAD_CAPS;
563 "unsupported TX offload: %#" PRIx64,
568 unsupported = rxmode->offloads & ~HN_RX_OFFLOAD_CAPS;
571 "unsupported RX offload: %#" PRIx64,
576 hv->vlan_strip = !!(rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
578 err = hn_rndis_conf_offload(hv, txmode->offloads,
582 "offload configure failed");
586 hv->num_queues = RTE_MAX(dev->data->nb_rx_queues,
587 dev->data->nb_tx_queues);
589 for (i = 0; i < NDIS_HASH_INDCNT; i++)
590 hv->rss_ind[i] = i % dev->data->nb_rx_queues;
592 hn_rss_hash_init(hv, rss_conf);
594 subchan = hv->num_queues - 1;
596 err = hn_subchan_configure(hv, subchan);
599 "subchannel configuration failed");
603 err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
606 "rss disable failed");
610 if (rss_conf->rss_hf != 0) {
611 err = hn_rndis_conf_rss(hv, 0);
614 "initial RSS config failed");
620 return hn_vf_configure(dev, dev_conf);
623 static int hn_dev_stats_get(struct rte_eth_dev *dev,
624 struct rte_eth_stats *stats)
628 hn_vf_stats_get(dev, stats);
630 for (i = 0; i < dev->data->nb_tx_queues; i++) {
631 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
636 stats->opackets += txq->stats.packets;
637 stats->obytes += txq->stats.bytes;
638 stats->oerrors += txq->stats.errors;
640 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
641 stats->q_opackets[i] = txq->stats.packets;
642 stats->q_obytes[i] = txq->stats.bytes;
646 for (i = 0; i < dev->data->nb_rx_queues; i++) {
647 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
652 stats->ipackets += rxq->stats.packets;
653 stats->ibytes += rxq->stats.bytes;
654 stats->ierrors += rxq->stats.errors;
655 stats->imissed += rxq->stats.ring_full;
657 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
658 stats->q_ipackets[i] = rxq->stats.packets;
659 stats->q_ibytes[i] = rxq->stats.bytes;
663 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
668 hn_dev_stats_reset(struct rte_eth_dev *dev)
672 PMD_INIT_FUNC_TRACE();
674 for (i = 0; i < dev->data->nb_tx_queues; i++) {
675 struct hn_tx_queue *txq = dev->data->tx_queues[i];
679 memset(&txq->stats, 0, sizeof(struct hn_stats));
682 for (i = 0; i < dev->data->nb_rx_queues; i++) {
683 struct hn_rx_queue *rxq = dev->data->rx_queues[i];
688 memset(&rxq->stats, 0, sizeof(struct hn_stats));
695 hn_dev_xstats_reset(struct rte_eth_dev *dev)
699 ret = hn_dev_stats_reset(dev);
703 return hn_vf_xstats_reset(dev);
707 hn_dev_xstats_count(struct rte_eth_dev *dev)
711 count = dev->data->nb_tx_queues * RTE_DIM(hn_stat_strings);
712 count += dev->data->nb_rx_queues * RTE_DIM(hn_stat_strings);
714 ret = hn_vf_xstats_get_names(dev, NULL, 0);
722 hn_dev_xstats_get_names(struct rte_eth_dev *dev,
723 struct rte_eth_xstat_name *xstats_names,
726 unsigned int i, t, count = 0;
730 return hn_dev_xstats_count(dev);
732 /* Note: limit checked in rte_eth_xstats_names() */
733 for (i = 0; i < dev->data->nb_tx_queues; i++) {
734 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
742 for (t = 0; t < RTE_DIM(hn_stat_strings); t++)
743 snprintf(xstats_names[count++].name,
744 RTE_ETH_XSTATS_NAME_SIZE,
745 "tx_q%u_%s", i, hn_stat_strings[t].name);
748 for (i = 0; i < dev->data->nb_rx_queues; i++) {
749 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
757 for (t = 0; t < RTE_DIM(hn_stat_strings); t++)
758 snprintf(xstats_names[count++].name,
759 RTE_ETH_XSTATS_NAME_SIZE,
761 hn_stat_strings[t].name);
764 ret = hn_vf_xstats_get_names(dev, xstats_names + count,
773 hn_dev_xstats_get(struct rte_eth_dev *dev,
774 struct rte_eth_xstat *xstats,
777 unsigned int i, t, count = 0;
778 const unsigned int nstats = hn_dev_xstats_count(dev);
782 PMD_INIT_FUNC_TRACE();
787 for (i = 0; i < dev->data->nb_tx_queues; i++) {
788 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
793 stats = (const char *)&txq->stats;
794 for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) {
795 xstats[count].id = count;
796 xstats[count].value = *(const uint64_t *)
797 (stats + hn_stat_strings[t].offset);
801 for (i = 0; i < dev->data->nb_rx_queues; i++) {
802 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
807 stats = (const char *)&rxq->stats;
808 for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) {
809 xstats[count].id = count;
810 xstats[count].value = *(const uint64_t *)
811 (stats + hn_stat_strings[t].offset);
815 ret = hn_vf_xstats_get(dev, xstats, count, n);
823 hn_dev_start(struct rte_eth_dev *dev)
825 struct hn_data *hv = dev->data->dev_private;
828 PMD_INIT_FUNC_TRACE();
830 error = hn_rndis_set_rxfilter(hv,
831 NDIS_PACKET_TYPE_BROADCAST |
832 NDIS_PACKET_TYPE_ALL_MULTICAST |
833 NDIS_PACKET_TYPE_DIRECTED);
837 error = hn_vf_start(dev);
839 hn_rndis_set_rxfilter(hv, 0);
841 /* Initialize Link state */
843 hn_dev_link_update(dev, 0);
849 hn_dev_stop(struct rte_eth_dev *dev)
851 struct hn_data *hv = dev->data->dev_private;
853 PMD_INIT_FUNC_TRACE();
854 dev->data->dev_started = 0;
856 hn_rndis_set_rxfilter(hv, 0);
857 return hn_vf_stop(dev);
861 hn_dev_close(struct rte_eth_dev *dev)
865 PMD_INIT_FUNC_TRACE();
866 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
869 ret = hn_vf_close(dev);
870 hn_dev_free_queues(dev);
875 static const struct eth_dev_ops hn_eth_dev_ops = {
876 .dev_configure = hn_dev_configure,
877 .dev_start = hn_dev_start,
878 .dev_stop = hn_dev_stop,
879 .dev_close = hn_dev_close,
880 .dev_infos_get = hn_dev_info_get,
881 .txq_info_get = hn_dev_tx_queue_info,
882 .rxq_info_get = hn_dev_rx_queue_info,
883 .dev_supported_ptypes_get = hn_vf_supported_ptypes,
884 .promiscuous_enable = hn_dev_promiscuous_enable,
885 .promiscuous_disable = hn_dev_promiscuous_disable,
886 .allmulticast_enable = hn_dev_allmulticast_enable,
887 .allmulticast_disable = hn_dev_allmulticast_disable,
888 .set_mc_addr_list = hn_dev_mc_addr_list,
889 .reta_update = hn_rss_reta_update,
890 .reta_query = hn_rss_reta_query,
891 .rss_hash_update = hn_rss_hash_update,
892 .rss_hash_conf_get = hn_rss_hash_conf_get,
893 .tx_queue_setup = hn_dev_tx_queue_setup,
894 .tx_queue_release = hn_dev_tx_queue_release,
895 .tx_done_cleanup = hn_dev_tx_done_cleanup,
896 .rx_queue_setup = hn_dev_rx_queue_setup,
897 .rx_queue_release = hn_dev_rx_queue_release,
898 .link_update = hn_dev_link_update,
899 .stats_get = hn_dev_stats_get,
900 .stats_reset = hn_dev_stats_reset,
901 .xstats_get = hn_dev_xstats_get,
902 .xstats_get_names = hn_dev_xstats_get_names,
903 .xstats_reset = hn_dev_xstats_reset,
907 * Setup connection between PMD and kernel.
910 hn_attach(struct hn_data *hv, unsigned int mtu)
915 error = hn_nvs_attach(hv, mtu);
920 error = hn_rndis_attach(hv);
926 * Under certain conditions on certain versions of Hyper-V,
927 * the RNDIS rxfilter is _not_ zero on the hypervisor side
928 * after the successful RNDIS initialization.
930 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_NONE);
939 hn_detach(struct hn_data *hv)
946 eth_hn_dev_init(struct rte_eth_dev *eth_dev)
948 struct hn_data *hv = eth_dev->data->dev_private;
949 struct rte_device *device = eth_dev->device;
950 struct rte_vmbus_device *vmbus;
951 unsigned int rxr_cnt;
954 PMD_INIT_FUNC_TRACE();
956 vmbus = container_of(device, struct rte_vmbus_device, device);
957 eth_dev->dev_ops = &hn_eth_dev_ops;
958 eth_dev->rx_queue_count = hn_dev_rx_queue_count;
959 eth_dev->rx_descriptor_status = hn_dev_rx_queue_status;
960 eth_dev->tx_descriptor_status = hn_dev_tx_descriptor_status;
961 eth_dev->tx_pkt_burst = &hn_xmit_pkts;
962 eth_dev->rx_pkt_burst = &hn_recv_pkts;
965 * for secondary processes, we don't initialize any further as primary
966 * has already done this work.
968 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
971 eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
973 /* Since Hyper-V only supports one MAC address */
974 eth_dev->data->mac_addrs = rte_calloc("hv_mac", HN_MAX_MAC_ADDRS,
975 sizeof(struct rte_ether_addr), 0);
976 if (eth_dev->data->mac_addrs == NULL) {
978 "Failed to allocate memory store MAC addresses");
983 hv->rxbuf_res = &vmbus->resource[HV_RECV_BUF_MAP];
984 hv->chim_res = &vmbus->resource[HV_SEND_BUF_MAP];
985 hv->port_id = eth_dev->data->port_id;
986 hv->latency = HN_CHAN_LATENCY_NS;
987 hv->rx_copybreak = HN_RXCOPY_THRESHOLD;
988 hv->tx_copybreak = HN_TXCOPY_THRESHOLD;
989 hv->rx_extmbuf_enable = HN_RX_EXTMBUF_ENABLE;
992 rte_rwlock_init(&hv->vf_lock);
993 hv->vf_port = HN_INVALID_PORT;
995 err = hn_parse_args(eth_dev);
999 strlcpy(hv->owner.name, eth_dev->device->name,
1000 RTE_ETH_MAX_OWNER_NAME_LEN);
1001 err = rte_eth_dev_owner_new(&hv->owner.id);
1003 PMD_INIT_LOG(ERR, "Can not get owner id");
1007 /* Initialize primary channel input for control operations */
1008 err = rte_vmbus_chan_open(vmbus, &hv->channels[0]);
1012 rte_vmbus_set_latency(hv->vmbus, hv->channels[0], hv->latency);
1014 hv->primary = hn_rx_queue_alloc(hv, 0,
1015 eth_dev->device->numa_node);
1020 err = hn_attach(hv, RTE_ETHER_MTU);
1024 err = hn_chim_init(eth_dev);
1028 err = hn_rndis_get_eaddr(hv, eth_dev->data->mac_addrs->addr_bytes);
1032 /* Multi queue requires later versions of windows server */
1033 if (hv->nvs_ver < NVS_VERSION_5)
1036 max_chan = rte_vmbus_max_channels(vmbus);
1037 PMD_INIT_LOG(DEBUG, "VMBus max channels %d", max_chan);
1041 if (hn_rndis_query_rsscaps(hv, &rxr_cnt) != 0)
1044 hv->max_queues = RTE_MIN(rxr_cnt, (unsigned int)max_chan);
1046 /* If VF was reported but not added, do it now */
1047 if (hv->vf_present && !hn_vf_attached(hv)) {
1048 PMD_INIT_LOG(DEBUG, "Adding VF device");
1050 err = hn_vf_add(eth_dev, hv);
1058 PMD_INIT_LOG(NOTICE, "device init failed");
1060 hn_chim_uninit(eth_dev);
1066 eth_hn_dev_uninit(struct rte_eth_dev *eth_dev)
1068 struct hn_data *hv = eth_dev->data->dev_private;
1071 PMD_INIT_FUNC_TRACE();
1073 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1076 ret_stop = hn_dev_stop(eth_dev);
1077 hn_dev_close(eth_dev);
1080 hn_chim_uninit(eth_dev);
1081 rte_vmbus_chan_close(hv->primary->chan);
1082 rte_free(hv->primary);
1083 ret = rte_eth_dev_owner_delete(hv->owner.id);
1090 static int eth_hn_probe(struct rte_vmbus_driver *drv __rte_unused,
1091 struct rte_vmbus_device *dev)
1093 struct rte_eth_dev *eth_dev;
1096 PMD_INIT_FUNC_TRACE();
1098 eth_dev = eth_dev_vmbus_allocate(dev, sizeof(struct hn_data));
1102 ret = eth_hn_dev_init(eth_dev);
1104 eth_dev_vmbus_release(eth_dev);
1106 rte_eth_dev_probing_finish(eth_dev);
1111 static int eth_hn_remove(struct rte_vmbus_device *dev)
1113 struct rte_eth_dev *eth_dev;
1116 PMD_INIT_FUNC_TRACE();
1118 eth_dev = rte_eth_dev_allocated(dev->device.name);
1120 return 0; /* port already released */
1122 ret = eth_hn_dev_uninit(eth_dev);
1126 eth_dev_vmbus_release(eth_dev);
1130 /* Network device GUID */
1131 static const rte_uuid_t hn_net_ids[] = {
1132 /* f8615163-df3e-46c5-913f-f2d2f965ed0e */
1133 RTE_UUID_INIT(0xf8615163, 0xdf3e, 0x46c5, 0x913f, 0xf2d2f965ed0eULL),
1137 static struct rte_vmbus_driver rte_netvsc_pmd = {
1138 .id_table = hn_net_ids,
1139 .probe = eth_hn_probe,
1140 .remove = eth_hn_remove,
1143 RTE_PMD_REGISTER_VMBUS(net_netvsc, rte_netvsc_pmd);
1144 RTE_PMD_REGISTER_KMOD_DEP(net_netvsc, "* uio_hv_generic");
1145 RTE_LOG_REGISTER(hn_logtype_init, pmd.net.netvsc.init, NOTICE);
1146 RTE_LOG_REGISTER(hn_logtype_driver, pmd.net.netvsc.driver, NOTICE);
1147 RTE_PMD_REGISTER_PARAM_STRING(net_netvsc,
1148 NETVSC_ARG_LATENCY "=<uint32> "
1149 NETVSC_ARG_RXBREAK "=<uint32> "
1150 NETVSC_ARG_TXBREAK "=<uint32> "
1151 NETVSC_ARG_RX_EXTMBUF_ENABLE "=<0|1>");