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 struct hn_xstats_name_off {
49 char name[RTE_ETH_XSTATS_NAME_SIZE];
53 static const struct hn_xstats_name_off hn_stat_strings[] = {
54 { "good_packets", offsetof(struct hn_stats, packets) },
55 { "good_bytes", offsetof(struct hn_stats, bytes) },
56 { "errors", offsetof(struct hn_stats, errors) },
57 { "ring full", offsetof(struct hn_stats, ring_full) },
58 { "channel full", offsetof(struct hn_stats, channel_full) },
59 { "multicast_packets", offsetof(struct hn_stats, multicast) },
60 { "broadcast_packets", offsetof(struct hn_stats, broadcast) },
61 { "undersize_packets", offsetof(struct hn_stats, size_bins[0]) },
62 { "size_64_packets", offsetof(struct hn_stats, size_bins[1]) },
63 { "size_65_127_packets", offsetof(struct hn_stats, size_bins[2]) },
64 { "size_128_255_packets", offsetof(struct hn_stats, size_bins[3]) },
65 { "size_256_511_packets", offsetof(struct hn_stats, size_bins[4]) },
66 { "size_512_1023_packets", offsetof(struct hn_stats, size_bins[5]) },
67 { "size_1024_1518_packets", offsetof(struct hn_stats, size_bins[6]) },
68 { "size_1519_max_packets", offsetof(struct hn_stats, size_bins[7]) },
71 /* The default RSS key.
72 * This value is the same as MLX5 so that flows will be
73 * received on same path for both VF and synthetic NIC.
75 static const uint8_t rss_default_key[NDIS_HASH_KEYSIZE_TOEPLITZ] = {
76 0x2c, 0xc6, 0x81, 0xd1, 0x5b, 0xdb, 0xf4, 0xf7,
77 0xfc, 0xa2, 0x83, 0x19, 0xdb, 0x1a, 0x3e, 0x94,
78 0x6b, 0x9e, 0x38, 0xd9, 0x2c, 0x9c, 0x03, 0xd1,
79 0xad, 0x99, 0x44, 0xa7, 0xd9, 0x56, 0x3d, 0x59,
80 0x06, 0x3c, 0x25, 0xf3, 0xfc, 0x1f, 0xdc, 0x2a,
83 static struct rte_eth_dev *
84 eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size)
86 struct rte_eth_dev *eth_dev;
92 name = dev->device.name;
94 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
95 eth_dev = rte_eth_dev_allocate(name);
97 PMD_DRV_LOG(NOTICE, "can not allocate rte ethdev");
101 if (private_data_size) {
102 eth_dev->data->dev_private =
103 rte_zmalloc_socket(name, private_data_size,
104 RTE_CACHE_LINE_SIZE, dev->device.numa_node);
105 if (!eth_dev->data->dev_private) {
106 PMD_DRV_LOG(NOTICE, "can not allocate driver data");
107 rte_eth_dev_release_port(eth_dev);
112 eth_dev = rte_eth_dev_attach_secondary(name);
114 PMD_DRV_LOG(NOTICE, "can not attach secondary");
119 eth_dev->device = &dev->device;
121 /* interrupt is simulated */
122 dev->intr_handle.type = RTE_INTR_HANDLE_EXT;
123 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
124 eth_dev->intr_handle = &dev->intr_handle;
130 eth_dev_vmbus_release(struct rte_eth_dev *eth_dev)
132 /* free ether device */
133 rte_eth_dev_release_port(eth_dev);
135 eth_dev->device = NULL;
136 eth_dev->intr_handle = NULL;
139 /* handle "latency=X" from devargs */
140 static int hn_set_latency(const char *key, const char *value, void *opaque)
142 struct hn_data *hv = opaque;
147 lat = strtoul(value, &endp, 0);
149 if (*value == '\0' || *endp != '\0') {
150 PMD_DRV_LOG(ERR, "invalid parameter %s=%s", key, value);
154 PMD_DRV_LOG(DEBUG, "set latency %lu usec", lat);
156 hv->latency = lat * 1000; /* usec to nsec */
160 /* Parse device arguments */
161 static int hn_parse_args(const struct rte_eth_dev *dev)
163 struct hn_data *hv = dev->data->dev_private;
164 struct rte_devargs *devargs = dev->device->devargs;
165 static const char * const valid_keys[] = {
169 struct rte_kvargs *kvlist;
175 PMD_INIT_LOG(DEBUG, "device args %s %s",
176 devargs->name, devargs->args);
178 kvlist = rte_kvargs_parse(devargs->args, valid_keys);
180 PMD_DRV_LOG(NOTICE, "invalid parameters");
184 ret = rte_kvargs_process(kvlist, "latency", hn_set_latency, hv);
186 PMD_DRV_LOG(ERR, "Unable to process latency arg\n");
188 rte_kvargs_free(kvlist);
192 /* Update link status.
193 * Note: the DPDK definition of "wait_to_complete"
194 * means block this call until link is up.
195 * which is not worth supporting.
198 hn_dev_link_update(struct rte_eth_dev *dev,
199 int wait_to_complete __rte_unused)
201 struct hn_data *hv = dev->data->dev_private;
202 struct rte_eth_link link, old;
205 old = dev->data->dev_link;
207 error = hn_rndis_get_linkstatus(hv);
211 hn_rndis_get_linkspeed(hv);
213 link = (struct rte_eth_link) {
214 .link_duplex = ETH_LINK_FULL_DUPLEX,
215 .link_autoneg = ETH_LINK_SPEED_FIXED,
216 .link_speed = hv->link_speed / 10000,
219 if (hv->link_status == NDIS_MEDIA_STATE_CONNECTED)
220 link.link_status = ETH_LINK_UP;
222 link.link_status = ETH_LINK_DOWN;
224 if (old.link_status == link.link_status)
227 PMD_INIT_LOG(DEBUG, "Port %d is %s", dev->data->port_id,
228 (link.link_status == ETH_LINK_UP) ? "up" : "down");
230 return rte_eth_linkstatus_set(dev, &link);
233 static int hn_dev_info_get(struct rte_eth_dev *dev,
234 struct rte_eth_dev_info *dev_info)
236 struct hn_data *hv = dev->data->dev_private;
239 dev_info->speed_capa = ETH_LINK_SPEED_10G;
240 dev_info->min_rx_bufsize = HN_MIN_RX_BUF_SIZE;
241 dev_info->max_rx_pktlen = HN_MAX_XFER_LEN;
242 dev_info->max_mac_addrs = 1;
244 dev_info->hash_key_size = NDIS_HASH_KEYSIZE_TOEPLITZ;
245 dev_info->flow_type_rss_offloads = hv->rss_offloads;
246 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
248 dev_info->max_rx_queues = hv->max_queues;
249 dev_info->max_tx_queues = hv->max_queues;
251 dev_info->tx_desc_lim.nb_min = 1;
252 dev_info->tx_desc_lim.nb_max = 4096;
254 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
257 /* fills in rx and tx offload capability */
258 rc = hn_rndis_get_offload(hv, dev_info);
262 /* merges the offload and queues of vf */
263 return hn_vf_info_get(hv, dev_info);
266 static int hn_rss_reta_update(struct rte_eth_dev *dev,
267 struct rte_eth_rss_reta_entry64 *reta_conf,
270 struct hn_data *hv = dev->data->dev_private;
274 PMD_INIT_FUNC_TRACE();
276 if (reta_size != NDIS_HASH_INDCNT) {
277 PMD_DRV_LOG(ERR, "Hash lookup table size does not match NDIS");
281 for (i = 0; i < NDIS_HASH_INDCNT; i++) {
282 uint16_t idx = i / RTE_RETA_GROUP_SIZE;
283 uint16_t shift = i % RTE_RETA_GROUP_SIZE;
284 uint64_t mask = (uint64_t)1 << shift;
286 if (reta_conf[idx].mask & mask)
287 hv->rss_ind[i] = reta_conf[idx].reta[shift];
290 err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
293 "rss disable failed");
297 err = hn_rndis_conf_rss(hv, 0);
300 "reta reconfig failed");
304 return hn_vf_reta_hash_update(dev, reta_conf, reta_size);
307 static int hn_rss_reta_query(struct rte_eth_dev *dev,
308 struct rte_eth_rss_reta_entry64 *reta_conf,
311 struct hn_data *hv = dev->data->dev_private;
314 PMD_INIT_FUNC_TRACE();
316 if (reta_size != NDIS_HASH_INDCNT) {
317 PMD_DRV_LOG(ERR, "Hash lookup table size does not match NDIS");
321 for (i = 0; i < NDIS_HASH_INDCNT; i++) {
322 uint16_t idx = i / RTE_RETA_GROUP_SIZE;
323 uint16_t shift = i % RTE_RETA_GROUP_SIZE;
324 uint64_t mask = (uint64_t)1 << shift;
326 if (reta_conf[idx].mask & mask)
327 reta_conf[idx].reta[shift] = hv->rss_ind[i];
332 static void hn_rss_hash_init(struct hn_data *hv,
333 const struct rte_eth_rss_conf *rss_conf)
335 /* Convert from DPDK RSS hash flags to NDIS hash flags */
336 hv->rss_hash = NDIS_HASH_FUNCTION_TOEPLITZ;
338 if (rss_conf->rss_hf & ETH_RSS_IPV4)
339 hv->rss_hash |= NDIS_HASH_IPV4;
340 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
341 hv->rss_hash |= NDIS_HASH_TCP_IPV4;
342 if (rss_conf->rss_hf & ETH_RSS_IPV6)
343 hv->rss_hash |= NDIS_HASH_IPV6;
344 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX)
345 hv->rss_hash |= NDIS_HASH_IPV6_EX;
346 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
347 hv->rss_hash |= NDIS_HASH_TCP_IPV6;
348 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX)
349 hv->rss_hash |= NDIS_HASH_TCP_IPV6_EX;
351 memcpy(hv->rss_key, rss_conf->rss_key ? : rss_default_key,
352 NDIS_HASH_KEYSIZE_TOEPLITZ);
355 static int hn_rss_hash_update(struct rte_eth_dev *dev,
356 struct rte_eth_rss_conf *rss_conf)
358 struct hn_data *hv = dev->data->dev_private;
361 PMD_INIT_FUNC_TRACE();
363 err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
366 "rss disable failed");
370 hn_rss_hash_init(hv, rss_conf);
372 if (rss_conf->rss_hf != 0) {
373 err = hn_rndis_conf_rss(hv, 0);
376 "rss reconfig failed (RSS disabled)");
381 return hn_vf_rss_hash_update(dev, rss_conf);
384 static int hn_rss_hash_conf_get(struct rte_eth_dev *dev,
385 struct rte_eth_rss_conf *rss_conf)
387 struct hn_data *hv = dev->data->dev_private;
389 PMD_INIT_FUNC_TRACE();
391 if (hv->ndis_ver < NDIS_VERSION_6_20) {
392 PMD_DRV_LOG(DEBUG, "RSS not supported on this host");
396 rss_conf->rss_key_len = NDIS_HASH_KEYSIZE_TOEPLITZ;
397 if (rss_conf->rss_key)
398 memcpy(rss_conf->rss_key, hv->rss_key,
399 NDIS_HASH_KEYSIZE_TOEPLITZ);
401 rss_conf->rss_hf = 0;
402 if (hv->rss_hash & NDIS_HASH_IPV4)
403 rss_conf->rss_hf |= ETH_RSS_IPV4;
405 if (hv->rss_hash & NDIS_HASH_TCP_IPV4)
406 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
408 if (hv->rss_hash & NDIS_HASH_IPV6)
409 rss_conf->rss_hf |= ETH_RSS_IPV6;
411 if (hv->rss_hash & NDIS_HASH_IPV6_EX)
412 rss_conf->rss_hf |= ETH_RSS_IPV6_EX;
414 if (hv->rss_hash & NDIS_HASH_TCP_IPV6)
415 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
417 if (hv->rss_hash & NDIS_HASH_TCP_IPV6_EX)
418 rss_conf->rss_hf |= ETH_RSS_IPV6_TCP_EX;
424 hn_dev_promiscuous_enable(struct rte_eth_dev *dev)
426 struct hn_data *hv = dev->data->dev_private;
428 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_PROMISCUOUS);
429 return hn_vf_promiscuous_enable(dev);
433 hn_dev_promiscuous_disable(struct rte_eth_dev *dev)
435 struct hn_data *hv = dev->data->dev_private;
438 filter = NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_BROADCAST;
439 if (dev->data->all_multicast)
440 filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
441 hn_rndis_set_rxfilter(hv, filter);
442 return hn_vf_promiscuous_disable(dev);
446 hn_dev_allmulticast_enable(struct rte_eth_dev *dev)
448 struct hn_data *hv = dev->data->dev_private;
450 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_DIRECTED |
451 NDIS_PACKET_TYPE_ALL_MULTICAST |
452 NDIS_PACKET_TYPE_BROADCAST);
453 return hn_vf_allmulticast_enable(dev);
457 hn_dev_allmulticast_disable(struct rte_eth_dev *dev)
459 struct hn_data *hv = dev->data->dev_private;
461 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_DIRECTED |
462 NDIS_PACKET_TYPE_BROADCAST);
463 return hn_vf_allmulticast_disable(dev);
467 hn_dev_mc_addr_list(struct rte_eth_dev *dev,
468 struct rte_ether_addr *mc_addr_set,
471 /* No filtering on the synthetic path, but can do it on VF */
472 return hn_vf_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
475 /* Setup shared rx/tx queue data */
476 static int hn_subchan_configure(struct hn_data *hv,
479 struct vmbus_channel *primary = hn_primary_chan(hv);
481 unsigned int retry = 0;
484 "open %u subchannels", subchan);
486 /* Send create sub channels command */
487 err = hn_nvs_alloc_subchans(hv, &subchan);
491 while (subchan > 0) {
492 struct vmbus_channel *new_sc;
495 err = rte_vmbus_subchan_open(primary, &new_sc);
496 if (err == -ENOENT && ++retry < 1000) {
497 /* This can happen if not ready yet */
504 "open subchannel failed: %d", err);
508 rte_vmbus_set_latency(hv->vmbus, new_sc, hv->latency);
511 chn_index = rte_vmbus_sub_channel_index(new_sc);
512 if (chn_index == 0 || chn_index > hv->max_queues) {
514 "Invalid subchannel offermsg channel %u",
519 PMD_DRV_LOG(DEBUG, "new sub channel %u", chn_index);
520 hv->channels[chn_index] = new_sc;
527 static int hn_dev_configure(struct rte_eth_dev *dev)
529 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
530 struct rte_eth_rss_conf *rss_conf = &dev_conf->rx_adv_conf.rss_conf;
531 const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode;
532 const struct rte_eth_txmode *txmode = &dev_conf->txmode;
533 struct hn_data *hv = dev->data->dev_private;
534 uint64_t unsupported;
537 PMD_INIT_FUNC_TRACE();
539 if (dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG)
540 dev_conf->rxmode.offloads |= DEV_RX_OFFLOAD_RSS_HASH;
542 unsupported = txmode->offloads & ~HN_TX_OFFLOAD_CAPS;
545 "unsupported TX offload: %#" PRIx64,
550 unsupported = rxmode->offloads & ~HN_RX_OFFLOAD_CAPS;
553 "unsupported RX offload: %#" PRIx64,
558 hv->vlan_strip = !!(rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
560 err = hn_rndis_conf_offload(hv, txmode->offloads,
564 "offload configure failed");
568 hv->num_queues = RTE_MAX(dev->data->nb_rx_queues,
569 dev->data->nb_tx_queues);
571 for (i = 0; i < NDIS_HASH_INDCNT; i++)
572 hv->rss_ind[i] = i % dev->data->nb_rx_queues;
574 hn_rss_hash_init(hv, rss_conf);
576 subchan = hv->num_queues - 1;
578 err = hn_subchan_configure(hv, subchan);
581 "subchannel configuration failed");
585 err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
588 "rss disable failed");
592 if (rss_conf->rss_hf != 0) {
593 err = hn_rndis_conf_rss(hv, 0);
596 "initial RSS config failed");
602 return hn_vf_configure(dev, dev_conf);
605 static int hn_dev_stats_get(struct rte_eth_dev *dev,
606 struct rte_eth_stats *stats)
610 hn_vf_stats_get(dev, stats);
612 for (i = 0; i < dev->data->nb_tx_queues; i++) {
613 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
618 stats->opackets += txq->stats.packets;
619 stats->obytes += txq->stats.bytes;
620 stats->oerrors += txq->stats.errors;
622 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
623 stats->q_opackets[i] = txq->stats.packets;
624 stats->q_obytes[i] = txq->stats.bytes;
628 for (i = 0; i < dev->data->nb_rx_queues; i++) {
629 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
634 stats->ipackets += rxq->stats.packets;
635 stats->ibytes += rxq->stats.bytes;
636 stats->ierrors += rxq->stats.errors;
637 stats->imissed += rxq->stats.ring_full;
639 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
640 stats->q_ipackets[i] = rxq->stats.packets;
641 stats->q_ibytes[i] = rxq->stats.bytes;
645 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
650 hn_dev_stats_reset(struct rte_eth_dev *dev)
654 PMD_INIT_FUNC_TRACE();
656 for (i = 0; i < dev->data->nb_tx_queues; i++) {
657 struct hn_tx_queue *txq = dev->data->tx_queues[i];
661 memset(&txq->stats, 0, sizeof(struct hn_stats));
664 for (i = 0; i < dev->data->nb_rx_queues; i++) {
665 struct hn_rx_queue *rxq = dev->data->rx_queues[i];
670 memset(&rxq->stats, 0, sizeof(struct hn_stats));
677 hn_dev_xstats_reset(struct rte_eth_dev *dev)
681 ret = hn_dev_stats_reset(dev);
685 return hn_vf_xstats_reset(dev);
689 hn_dev_xstats_count(struct rte_eth_dev *dev)
693 count = dev->data->nb_tx_queues * RTE_DIM(hn_stat_strings);
694 count += dev->data->nb_rx_queues * RTE_DIM(hn_stat_strings);
696 ret = hn_vf_xstats_get_names(dev, NULL, 0);
704 hn_dev_xstats_get_names(struct rte_eth_dev *dev,
705 struct rte_eth_xstat_name *xstats_names,
708 unsigned int i, t, count = 0;
712 return hn_dev_xstats_count(dev);
714 /* Note: limit checked in rte_eth_xstats_names() */
715 for (i = 0; i < dev->data->nb_tx_queues; i++) {
716 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
724 for (t = 0; t < RTE_DIM(hn_stat_strings); t++)
725 snprintf(xstats_names[count++].name,
726 RTE_ETH_XSTATS_NAME_SIZE,
727 "tx_q%u_%s", i, hn_stat_strings[t].name);
730 for (i = 0; i < dev->data->nb_rx_queues; i++) {
731 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
739 for (t = 0; t < RTE_DIM(hn_stat_strings); t++)
740 snprintf(xstats_names[count++].name,
741 RTE_ETH_XSTATS_NAME_SIZE,
743 hn_stat_strings[t].name);
746 ret = hn_vf_xstats_get_names(dev, xstats_names + count,
755 hn_dev_xstats_get(struct rte_eth_dev *dev,
756 struct rte_eth_xstat *xstats,
759 unsigned int i, t, count = 0;
760 const unsigned int nstats = hn_dev_xstats_count(dev);
764 PMD_INIT_FUNC_TRACE();
769 for (i = 0; i < dev->data->nb_tx_queues; i++) {
770 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
775 stats = (const char *)&txq->stats;
776 for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) {
777 xstats[count].id = count;
778 xstats[count].value = *(const uint64_t *)
779 (stats + hn_stat_strings[t].offset);
783 for (i = 0; i < dev->data->nb_rx_queues; i++) {
784 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
789 stats = (const char *)&rxq->stats;
790 for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) {
791 xstats[count].id = count;
792 xstats[count].value = *(const uint64_t *)
793 (stats + hn_stat_strings[t].offset);
797 ret = hn_vf_xstats_get(dev, xstats, count, n);
805 hn_dev_start(struct rte_eth_dev *dev)
807 struct hn_data *hv = dev->data->dev_private;
810 PMD_INIT_FUNC_TRACE();
812 error = hn_rndis_set_rxfilter(hv,
813 NDIS_PACKET_TYPE_BROADCAST |
814 NDIS_PACKET_TYPE_ALL_MULTICAST |
815 NDIS_PACKET_TYPE_DIRECTED);
819 error = hn_vf_start(dev);
821 hn_rndis_set_rxfilter(hv, 0);
823 /* Initialize Link state */
825 hn_dev_link_update(dev, 0);
831 hn_dev_stop(struct rte_eth_dev *dev)
833 struct hn_data *hv = dev->data->dev_private;
835 PMD_INIT_FUNC_TRACE();
836 dev->data->dev_started = 0;
838 hn_rndis_set_rxfilter(hv, 0);
843 hn_dev_close(struct rte_eth_dev *dev)
845 PMD_INIT_FUNC_TRACE();
846 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
850 hn_dev_free_queues(dev);
855 static const struct eth_dev_ops hn_eth_dev_ops = {
856 .dev_configure = hn_dev_configure,
857 .dev_start = hn_dev_start,
858 .dev_stop = hn_dev_stop,
859 .dev_close = hn_dev_close,
860 .dev_infos_get = hn_dev_info_get,
861 .txq_info_get = hn_dev_tx_queue_info,
862 .rxq_info_get = hn_dev_rx_queue_info,
863 .dev_supported_ptypes_get = hn_vf_supported_ptypes,
864 .promiscuous_enable = hn_dev_promiscuous_enable,
865 .promiscuous_disable = hn_dev_promiscuous_disable,
866 .allmulticast_enable = hn_dev_allmulticast_enable,
867 .allmulticast_disable = hn_dev_allmulticast_disable,
868 .set_mc_addr_list = hn_dev_mc_addr_list,
869 .reta_update = hn_rss_reta_update,
870 .reta_query = hn_rss_reta_query,
871 .rss_hash_update = hn_rss_hash_update,
872 .rss_hash_conf_get = hn_rss_hash_conf_get,
873 .tx_queue_setup = hn_dev_tx_queue_setup,
874 .tx_queue_release = hn_dev_tx_queue_release,
875 .tx_done_cleanup = hn_dev_tx_done_cleanup,
876 .rx_queue_setup = hn_dev_rx_queue_setup,
877 .rx_queue_release = hn_dev_rx_queue_release,
878 .link_update = hn_dev_link_update,
879 .stats_get = hn_dev_stats_get,
880 .stats_reset = hn_dev_stats_reset,
881 .xstats_get = hn_dev_xstats_get,
882 .xstats_get_names = hn_dev_xstats_get_names,
883 .xstats_reset = hn_dev_xstats_reset,
887 * Setup connection between PMD and kernel.
890 hn_attach(struct hn_data *hv, unsigned int mtu)
895 error = hn_nvs_attach(hv, mtu);
900 error = hn_rndis_attach(hv);
906 * Under certain conditions on certain versions of Hyper-V,
907 * the RNDIS rxfilter is _not_ zero on the hypervisor side
908 * after the successful RNDIS initialization.
910 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_NONE);
919 hn_detach(struct hn_data *hv)
926 eth_hn_dev_init(struct rte_eth_dev *eth_dev)
928 struct hn_data *hv = eth_dev->data->dev_private;
929 struct rte_device *device = eth_dev->device;
930 struct rte_vmbus_device *vmbus;
931 unsigned int rxr_cnt;
934 PMD_INIT_FUNC_TRACE();
936 vmbus = container_of(device, struct rte_vmbus_device, device);
937 eth_dev->dev_ops = &hn_eth_dev_ops;
938 eth_dev->rx_queue_count = hn_dev_rx_queue_count;
939 eth_dev->rx_descriptor_status = hn_dev_rx_queue_status;
940 eth_dev->tx_descriptor_status = hn_dev_tx_descriptor_status;
941 eth_dev->tx_pkt_burst = &hn_xmit_pkts;
942 eth_dev->rx_pkt_burst = &hn_recv_pkts;
945 * for secondary processes, we don't initialize any further as primary
946 * has already done this work.
948 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
951 /* Since Hyper-V only supports one MAC address */
952 eth_dev->data->mac_addrs = rte_calloc("hv_mac", HN_MAX_MAC_ADDRS,
953 sizeof(struct rte_ether_addr), 0);
954 if (eth_dev->data->mac_addrs == NULL) {
956 "Failed to allocate memory store MAC addresses");
961 hv->rxbuf_res = &vmbus->resource[HV_RECV_BUF_MAP];
962 hv->chim_res = &vmbus->resource[HV_SEND_BUF_MAP];
963 hv->port_id = eth_dev->data->port_id;
964 hv->latency = HN_CHAN_LATENCY_NS;
966 rte_rwlock_init(&hv->vf_lock);
967 hv->vf_port = HN_INVALID_PORT;
969 err = hn_parse_args(eth_dev);
973 strlcpy(hv->owner.name, eth_dev->device->name,
974 RTE_ETH_MAX_OWNER_NAME_LEN);
975 err = rte_eth_dev_owner_new(&hv->owner.id);
977 PMD_INIT_LOG(ERR, "Can not get owner id");
981 /* Initialize primary channel input for control operations */
982 err = rte_vmbus_chan_open(vmbus, &hv->channels[0]);
986 rte_vmbus_set_latency(hv->vmbus, hv->channels[0], hv->latency);
988 hv->primary = hn_rx_queue_alloc(hv, 0,
989 eth_dev->device->numa_node);
994 err = hn_attach(hv, RTE_ETHER_MTU);
998 err = hn_chim_init(eth_dev);
1002 err = hn_rndis_get_eaddr(hv, eth_dev->data->mac_addrs->addr_bytes);
1006 /* Multi queue requires later versions of windows server */
1007 if (hv->nvs_ver < NVS_VERSION_5)
1010 max_chan = rte_vmbus_max_channels(vmbus);
1011 PMD_INIT_LOG(DEBUG, "VMBus max channels %d", max_chan);
1015 if (hn_rndis_query_rsscaps(hv, &rxr_cnt) != 0)
1018 hv->max_queues = RTE_MIN(rxr_cnt, (unsigned int)max_chan);
1020 /* If VF was reported but not added, do it now */
1021 if (hv->vf_present && !hn_vf_attached(hv)) {
1022 PMD_INIT_LOG(DEBUG, "Adding VF device");
1024 err = hn_vf_add(eth_dev, hv);
1032 PMD_INIT_LOG(NOTICE, "device init failed");
1034 hn_chim_uninit(eth_dev);
1040 eth_hn_dev_uninit(struct rte_eth_dev *eth_dev)
1042 struct hn_data *hv = eth_dev->data->dev_private;
1045 PMD_INIT_FUNC_TRACE();
1047 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1050 hn_dev_stop(eth_dev);
1051 hn_dev_close(eth_dev);
1054 hn_chim_uninit(eth_dev);
1055 rte_vmbus_chan_close(hv->primary->chan);
1056 rte_free(hv->primary);
1057 ret = rte_eth_dev_owner_delete(hv->owner.id);
1064 static int eth_hn_probe(struct rte_vmbus_driver *drv __rte_unused,
1065 struct rte_vmbus_device *dev)
1067 struct rte_eth_dev *eth_dev;
1070 PMD_INIT_FUNC_TRACE();
1072 eth_dev = eth_dev_vmbus_allocate(dev, sizeof(struct hn_data));
1076 ret = eth_hn_dev_init(eth_dev);
1078 eth_dev_vmbus_release(eth_dev);
1080 rte_eth_dev_probing_finish(eth_dev);
1085 static int eth_hn_remove(struct rte_vmbus_device *dev)
1087 struct rte_eth_dev *eth_dev;
1090 PMD_INIT_FUNC_TRACE();
1092 eth_dev = rte_eth_dev_allocated(dev->device.name);
1094 return 0; /* port already released */
1096 ret = eth_hn_dev_uninit(eth_dev);
1100 eth_dev_vmbus_release(eth_dev);
1104 /* Network device GUID */
1105 static const rte_uuid_t hn_net_ids[] = {
1106 /* f8615163-df3e-46c5-913f-f2d2f965ed0e */
1107 RTE_UUID_INIT(0xf8615163, 0xdf3e, 0x46c5, 0x913f, 0xf2d2f965ed0eULL),
1111 static struct rte_vmbus_driver rte_netvsc_pmd = {
1112 .id_table = hn_net_ids,
1113 .probe = eth_hn_probe,
1114 .remove = eth_hn_remove,
1117 RTE_PMD_REGISTER_VMBUS(net_netvsc, rte_netvsc_pmd);
1118 RTE_PMD_REGISTER_KMOD_DEP(net_netvsc, "* uio_hv_generic");
1119 RTE_LOG_REGISTER(hn_logtype_init, pmd.net.netvsc.init, NOTICE);
1120 RTE_LOG_REGISTER(hn_logtype_driver, pmd.net.netvsc.driver, NOTICE);