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)
48 int hn_logtype_driver;
50 struct hn_xstats_name_off {
51 char name[RTE_ETH_XSTATS_NAME_SIZE];
55 static const struct hn_xstats_name_off hn_stat_strings[] = {
56 { "good_packets", offsetof(struct hn_stats, packets) },
57 { "good_bytes", offsetof(struct hn_stats, bytes) },
58 { "errors", offsetof(struct hn_stats, errors) },
59 { "ring full", offsetof(struct hn_stats, ring_full) },
60 { "multicast_packets", offsetof(struct hn_stats, multicast) },
61 { "broadcast_packets", offsetof(struct hn_stats, broadcast) },
62 { "undersize_packets", offsetof(struct hn_stats, size_bins[0]) },
63 { "size_64_packets", offsetof(struct hn_stats, size_bins[1]) },
64 { "size_65_127_packets", offsetof(struct hn_stats, size_bins[2]) },
65 { "size_128_255_packets", offsetof(struct hn_stats, size_bins[3]) },
66 { "size_256_511_packets", offsetof(struct hn_stats, size_bins[4]) },
67 { "size_512_1023_packets", offsetof(struct hn_stats, size_bins[5]) },
68 { "size_1024_1518_packets", offsetof(struct hn_stats, size_bins[6]) },
69 { "size_1519_max_packets", offsetof(struct hn_stats, size_bins[7]) },
72 /* The default RSS key.
73 * This value is the same as MLX5 so that flows will be
74 * received on same path for both VF ans synthetic NIC.
76 static const uint8_t rss_default_key[NDIS_HASH_KEYSIZE_TOEPLITZ] = {
77 0x2c, 0xc6, 0x81, 0xd1, 0x5b, 0xdb, 0xf4, 0xf7,
78 0xfc, 0xa2, 0x83, 0x19, 0xdb, 0x1a, 0x3e, 0x94,
79 0x6b, 0x9e, 0x38, 0xd9, 0x2c, 0x9c, 0x03, 0xd1,
80 0xad, 0x99, 0x44, 0xa7, 0xd9, 0x56, 0x3d, 0x59,
81 0x06, 0x3c, 0x25, 0xf3, 0xfc, 0x1f, 0xdc, 0x2a,
84 static struct rte_eth_dev *
85 eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size)
87 struct rte_eth_dev *eth_dev;
93 name = dev->device.name;
95 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
96 eth_dev = rte_eth_dev_allocate(name);
98 PMD_DRV_LOG(NOTICE, "can not allocate rte ethdev");
102 if (private_data_size) {
103 eth_dev->data->dev_private =
104 rte_zmalloc_socket(name, private_data_size,
105 RTE_CACHE_LINE_SIZE, dev->device.numa_node);
106 if (!eth_dev->data->dev_private) {
107 PMD_DRV_LOG(NOTICE, "can not allocate driver data");
108 rte_eth_dev_release_port(eth_dev);
113 eth_dev = rte_eth_dev_attach_secondary(name);
115 PMD_DRV_LOG(NOTICE, "can not attach secondary");
120 eth_dev->device = &dev->device;
122 /* interrupt is simulated */
123 dev->intr_handle.type = RTE_INTR_HANDLE_EXT;
124 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
125 eth_dev->intr_handle = &dev->intr_handle;
127 /* allow ethdev to remove on close */
128 eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
134 eth_dev_vmbus_release(struct rte_eth_dev *eth_dev)
136 /* mac_addrs must not be freed alone because part of dev_private */
137 eth_dev->data->mac_addrs = NULL;
138 /* free ether device */
139 rte_eth_dev_release_port(eth_dev);
141 eth_dev->device = NULL;
142 eth_dev->intr_handle = NULL;
145 /* handle "latency=X" from devargs */
146 static int hn_set_latency(const char *key, const char *value, void *opaque)
148 struct hn_data *hv = opaque;
153 lat = strtoul(value, &endp, 0);
155 if (*value == '\0' || *endp != '\0') {
156 PMD_DRV_LOG(ERR, "invalid parameter %s=%s", key, value);
160 PMD_DRV_LOG(DEBUG, "set latency %lu usec", lat);
162 hv->latency = lat * 1000; /* usec to nsec */
166 /* Parse device arguments */
167 static int hn_parse_args(const struct rte_eth_dev *dev)
169 struct hn_data *hv = dev->data->dev_private;
170 struct rte_devargs *devargs = dev->device->devargs;
171 static const char * const valid_keys[] = {
175 struct rte_kvargs *kvlist;
181 PMD_INIT_LOG(DEBUG, "device args %s %s",
182 devargs->name, devargs->args);
184 kvlist = rte_kvargs_parse(devargs->args, valid_keys);
186 PMD_DRV_LOG(NOTICE, "invalid parameters");
190 ret = rte_kvargs_process(kvlist, "latency", hn_set_latency, hv);
192 PMD_DRV_LOG(ERR, "Unable to process latency arg\n");
194 rte_kvargs_free(kvlist);
198 /* Update link status.
199 * Note: the DPDK definition of "wait_to_complete"
200 * means block this call until link is up.
201 * which is not worth supporting.
204 hn_dev_link_update(struct rte_eth_dev *dev,
205 int wait_to_complete)
207 struct hn_data *hv = dev->data->dev_private;
208 struct rte_eth_link link, old;
211 old = dev->data->dev_link;
213 error = hn_rndis_get_linkstatus(hv);
217 hn_rndis_get_linkspeed(hv);
219 hn_vf_link_update(dev, wait_to_complete);
221 link = (struct rte_eth_link) {
222 .link_duplex = ETH_LINK_FULL_DUPLEX,
223 .link_autoneg = ETH_LINK_SPEED_FIXED,
224 .link_speed = hv->link_speed / 10000,
227 if (hv->link_status == NDIS_MEDIA_STATE_CONNECTED)
228 link.link_status = ETH_LINK_UP;
230 link.link_status = ETH_LINK_DOWN;
232 if (old.link_status == link.link_status)
235 PMD_INIT_LOG(DEBUG, "Port %d is %s", dev->data->port_id,
236 (link.link_status == ETH_LINK_UP) ? "up" : "down");
238 return rte_eth_linkstatus_set(dev, &link);
241 static int hn_dev_info_get(struct rte_eth_dev *dev,
242 struct rte_eth_dev_info *dev_info)
244 struct hn_data *hv = dev->data->dev_private;
247 dev_info->speed_capa = ETH_LINK_SPEED_10G;
248 dev_info->min_rx_bufsize = HN_MIN_RX_BUF_SIZE;
249 dev_info->max_rx_pktlen = HN_MAX_XFER_LEN;
250 dev_info->max_mac_addrs = 1;
252 dev_info->hash_key_size = NDIS_HASH_KEYSIZE_TOEPLITZ;
253 dev_info->flow_type_rss_offloads = hv->rss_offloads;
254 dev_info->reta_size = ETH_RSS_RETA_SIZE_128;
256 dev_info->max_rx_queues = hv->max_queues;
257 dev_info->max_tx_queues = hv->max_queues;
259 rc = hn_rndis_get_offload(hv, dev_info);
263 rc = hn_vf_info_get(hv, dev_info);
270 static int hn_rss_reta_update(struct rte_eth_dev *dev,
271 struct rte_eth_rss_reta_entry64 *reta_conf,
274 struct hn_data *hv = dev->data->dev_private;
278 PMD_INIT_FUNC_TRACE();
280 if (reta_size != NDIS_HASH_INDCNT) {
281 PMD_DRV_LOG(ERR, "Hash lookup table size does not match NDIS");
285 for (i = 0; i < NDIS_HASH_INDCNT; i++) {
286 uint16_t idx = i / RTE_RETA_GROUP_SIZE;
287 uint16_t shift = i % RTE_RETA_GROUP_SIZE;
288 uint64_t mask = (uint64_t)1 << shift;
290 if (reta_conf[idx].mask & mask)
291 hv->rss_ind[i] = reta_conf[idx].reta[shift];
294 err = hn_rndis_conf_rss(hv, 0);
297 "reta reconfig failed");
301 return hn_vf_reta_hash_update(dev, reta_conf, reta_size);
304 static int hn_rss_reta_query(struct rte_eth_dev *dev,
305 struct rte_eth_rss_reta_entry64 *reta_conf,
308 struct hn_data *hv = dev->data->dev_private;
311 PMD_INIT_FUNC_TRACE();
313 if (reta_size != NDIS_HASH_INDCNT) {
314 PMD_DRV_LOG(ERR, "Hash lookup table size does not match NDIS");
318 for (i = 0; i < NDIS_HASH_INDCNT; i++) {
319 uint16_t idx = i / RTE_RETA_GROUP_SIZE;
320 uint16_t shift = i % RTE_RETA_GROUP_SIZE;
321 uint64_t mask = (uint64_t)1 << shift;
323 if (reta_conf[idx].mask & mask)
324 reta_conf[idx].reta[shift] = hv->rss_ind[i];
329 static void hn_rss_hash_init(struct hn_data *hv,
330 const struct rte_eth_rss_conf *rss_conf)
332 /* Convert from DPDK RSS hash flags to NDIS hash flags */
333 hv->rss_hash = NDIS_HASH_FUNCTION_TOEPLITZ;
335 if (rss_conf->rss_hf & ETH_RSS_IPV4)
336 hv->rss_hash |= NDIS_HASH_IPV4;
337 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV4_TCP)
338 hv->rss_hash |= NDIS_HASH_TCP_IPV4;
339 if (rss_conf->rss_hf & ETH_RSS_IPV6)
340 hv->rss_hash |= NDIS_HASH_IPV6;
341 if (rss_conf->rss_hf & ETH_RSS_IPV6_EX)
342 hv->rss_hash |= NDIS_HASH_IPV6_EX;
343 if (rss_conf->rss_hf & ETH_RSS_NONFRAG_IPV6_TCP)
344 hv->rss_hash |= NDIS_HASH_TCP_IPV6;
345 if (rss_conf->rss_hf & ETH_RSS_IPV6_TCP_EX)
346 hv->rss_hash |= NDIS_HASH_TCP_IPV6_EX;
348 memcpy(hv->rss_key, rss_conf->rss_key ? : rss_default_key,
349 NDIS_HASH_KEYSIZE_TOEPLITZ);
352 static int hn_rss_hash_update(struct rte_eth_dev *dev,
353 struct rte_eth_rss_conf *rss_conf)
355 struct hn_data *hv = dev->data->dev_private;
358 PMD_INIT_FUNC_TRACE();
360 err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
363 "rss disable failed");
367 hn_rss_hash_init(hv, rss_conf);
369 err = hn_rndis_conf_rss(hv, 0);
372 "rss reconfig failed (RSS disabled)");
377 return hn_vf_rss_hash_update(dev, rss_conf);
380 static int hn_rss_hash_conf_get(struct rte_eth_dev *dev,
381 struct rte_eth_rss_conf *rss_conf)
383 struct hn_data *hv = dev->data->dev_private;
385 PMD_INIT_FUNC_TRACE();
387 if (hv->ndis_ver < NDIS_VERSION_6_20) {
388 PMD_DRV_LOG(DEBUG, "RSS not supported on this host");
392 rss_conf->rss_key_len = NDIS_HASH_KEYSIZE_TOEPLITZ;
393 if (rss_conf->rss_key)
394 memcpy(rss_conf->rss_key, hv->rss_key,
395 NDIS_HASH_KEYSIZE_TOEPLITZ);
397 rss_conf->rss_hf = 0;
398 if (hv->rss_hash & NDIS_HASH_IPV4)
399 rss_conf->rss_hf |= ETH_RSS_IPV4;
401 if (hv->rss_hash & NDIS_HASH_TCP_IPV4)
402 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV4_TCP;
404 if (hv->rss_hash & NDIS_HASH_IPV6)
405 rss_conf->rss_hf |= ETH_RSS_IPV6;
407 if (hv->rss_hash & NDIS_HASH_IPV6_EX)
408 rss_conf->rss_hf |= ETH_RSS_IPV6_EX;
410 if (hv->rss_hash & NDIS_HASH_TCP_IPV6)
411 rss_conf->rss_hf |= ETH_RSS_NONFRAG_IPV6_TCP;
413 if (hv->rss_hash & NDIS_HASH_TCP_IPV6_EX)
414 rss_conf->rss_hf |= ETH_RSS_IPV6_TCP_EX;
420 hn_dev_promiscuous_enable(struct rte_eth_dev *dev)
422 struct hn_data *hv = dev->data->dev_private;
424 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_PROMISCUOUS);
425 return hn_vf_promiscuous_enable(dev);
429 hn_dev_promiscuous_disable(struct rte_eth_dev *dev)
431 struct hn_data *hv = dev->data->dev_private;
434 filter = NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_BROADCAST;
435 if (dev->data->all_multicast)
436 filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
437 hn_rndis_set_rxfilter(hv, filter);
438 return hn_vf_promiscuous_disable(dev);
442 hn_dev_allmulticast_enable(struct rte_eth_dev *dev)
444 struct hn_data *hv = dev->data->dev_private;
446 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_DIRECTED |
447 NDIS_PACKET_TYPE_ALL_MULTICAST |
448 NDIS_PACKET_TYPE_BROADCAST);
449 return hn_vf_allmulticast_enable(dev);
453 hn_dev_allmulticast_disable(struct rte_eth_dev *dev)
455 struct hn_data *hv = dev->data->dev_private;
457 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_DIRECTED |
458 NDIS_PACKET_TYPE_BROADCAST);
459 return hn_vf_allmulticast_disable(dev);
463 hn_dev_mc_addr_list(struct rte_eth_dev *dev,
464 struct rte_ether_addr *mc_addr_set,
467 /* No filtering on the synthetic path, but can do it on VF */
468 return hn_vf_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
471 /* Setup shared rx/tx queue data */
472 static int hn_subchan_configure(struct hn_data *hv,
475 struct vmbus_channel *primary = hn_primary_chan(hv);
477 unsigned int retry = 0;
480 "open %u subchannels", subchan);
482 /* Send create sub channels command */
483 err = hn_nvs_alloc_subchans(hv, &subchan);
487 while (subchan > 0) {
488 struct vmbus_channel *new_sc;
491 err = rte_vmbus_subchan_open(primary, &new_sc);
492 if (err == -ENOENT && ++retry < 1000) {
493 /* This can happen if not ready yet */
500 "open subchannel failed: %d", err);
504 rte_vmbus_set_latency(hv->vmbus, new_sc, hv->latency);
507 chn_index = rte_vmbus_sub_channel_index(new_sc);
508 if (chn_index == 0 || chn_index > hv->max_queues) {
510 "Invalid subchannel offermsg channel %u",
515 PMD_DRV_LOG(DEBUG, "new sub channel %u", chn_index);
516 hv->channels[chn_index] = new_sc;
523 static int hn_dev_configure(struct rte_eth_dev *dev)
525 struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
526 struct rte_eth_rss_conf *rss_conf = &dev_conf->rx_adv_conf.rss_conf;
527 const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode;
528 const struct rte_eth_txmode *txmode = &dev_conf->txmode;
529 struct hn_data *hv = dev->data->dev_private;
530 uint64_t unsupported;
533 PMD_INIT_FUNC_TRACE();
535 unsupported = txmode->offloads & ~HN_TX_OFFLOAD_CAPS;
538 "unsupported TX offload: %#" PRIx64,
543 unsupported = rxmode->offloads & ~HN_RX_OFFLOAD_CAPS;
546 "unsupported RX offload: %#" PRIx64,
551 hv->vlan_strip = !!(rxmode->offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
553 err = hn_rndis_conf_offload(hv, txmode->offloads,
557 "offload configure failed");
561 hv->num_queues = RTE_MAX(dev->data->nb_rx_queues,
562 dev->data->nb_tx_queues);
564 for (i = 0; i < NDIS_HASH_INDCNT; i++)
565 hv->rss_ind[i] = i % hv->num_queues;
567 hn_rss_hash_init(hv, rss_conf);
569 subchan = hv->num_queues - 1;
571 err = hn_subchan_configure(hv, subchan);
574 "subchannel configuration failed");
578 err = hn_rndis_conf_rss(hv, 0);
581 "initial RSS config failed");
586 return hn_vf_configure(dev, dev_conf);
589 static int hn_dev_stats_get(struct rte_eth_dev *dev,
590 struct rte_eth_stats *stats)
594 hn_vf_stats_get(dev, stats);
596 for (i = 0; i < dev->data->nb_tx_queues; i++) {
597 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
602 stats->opackets += txq->stats.packets;
603 stats->obytes += txq->stats.bytes;
604 stats->oerrors += txq->stats.errors;
606 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
607 stats->q_opackets[i] = txq->stats.packets;
608 stats->q_obytes[i] = txq->stats.bytes;
612 for (i = 0; i < dev->data->nb_rx_queues; i++) {
613 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
618 stats->ipackets += rxq->stats.packets;
619 stats->ibytes += rxq->stats.bytes;
620 stats->ierrors += rxq->stats.errors;
621 stats->imissed += rxq->stats.ring_full;
623 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
624 stats->q_ipackets[i] = rxq->stats.packets;
625 stats->q_ibytes[i] = rxq->stats.bytes;
629 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
634 hn_dev_stats_reset(struct rte_eth_dev *dev)
638 PMD_INIT_FUNC_TRACE();
640 for (i = 0; i < dev->data->nb_tx_queues; i++) {
641 struct hn_tx_queue *txq = dev->data->tx_queues[i];
645 memset(&txq->stats, 0, sizeof(struct hn_stats));
648 for (i = 0; i < dev->data->nb_rx_queues; i++) {
649 struct hn_rx_queue *rxq = dev->data->rx_queues[i];
654 memset(&rxq->stats, 0, sizeof(struct hn_stats));
661 hn_dev_xstats_reset(struct rte_eth_dev *dev)
665 ret = hn_dev_stats_reset(dev);
669 return hn_vf_xstats_reset(dev);
673 hn_dev_xstats_count(struct rte_eth_dev *dev)
677 count = dev->data->nb_tx_queues * RTE_DIM(hn_stat_strings);
678 count += dev->data->nb_rx_queues * RTE_DIM(hn_stat_strings);
680 ret = hn_vf_xstats_get_names(dev, NULL, 0);
688 hn_dev_xstats_get_names(struct rte_eth_dev *dev,
689 struct rte_eth_xstat_name *xstats_names,
692 unsigned int i, t, count = 0;
696 return hn_dev_xstats_count(dev);
698 /* Note: limit checked in rte_eth_xstats_names() */
699 for (i = 0; i < dev->data->nb_tx_queues; i++) {
700 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
708 for (t = 0; t < RTE_DIM(hn_stat_strings); t++)
709 snprintf(xstats_names[count++].name,
710 RTE_ETH_XSTATS_NAME_SIZE,
711 "tx_q%u_%s", i, hn_stat_strings[t].name);
714 for (i = 0; i < dev->data->nb_rx_queues; i++) {
715 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
723 for (t = 0; t < RTE_DIM(hn_stat_strings); t++)
724 snprintf(xstats_names[count++].name,
725 RTE_ETH_XSTATS_NAME_SIZE,
727 hn_stat_strings[t].name);
730 ret = hn_vf_xstats_get_names(dev, xstats_names + count,
739 hn_dev_xstats_get(struct rte_eth_dev *dev,
740 struct rte_eth_xstat *xstats,
743 unsigned int i, t, count = 0;
744 const unsigned int nstats = hn_dev_xstats_count(dev);
748 PMD_INIT_FUNC_TRACE();
753 for (i = 0; i < dev->data->nb_tx_queues; i++) {
754 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
759 stats = (const char *)&txq->stats;
760 for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) {
761 xstats[count].id = count;
762 xstats[count].value = *(const uint64_t *)
763 (stats + hn_stat_strings[t].offset);
767 for (i = 0; i < dev->data->nb_rx_queues; i++) {
768 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
773 stats = (const char *)&rxq->stats;
774 for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) {
775 xstats[count].id = count;
776 xstats[count].value = *(const uint64_t *)
777 (stats + hn_stat_strings[t].offset);
781 ret = hn_vf_xstats_get(dev, xstats, count, n);
789 hn_dev_start(struct rte_eth_dev *dev)
791 struct hn_data *hv = dev->data->dev_private;
794 PMD_INIT_FUNC_TRACE();
796 error = hn_rndis_set_rxfilter(hv,
797 NDIS_PACKET_TYPE_BROADCAST |
798 NDIS_PACKET_TYPE_ALL_MULTICAST |
799 NDIS_PACKET_TYPE_DIRECTED);
803 error = hn_vf_start(dev);
805 hn_rndis_set_rxfilter(hv, 0);
811 hn_dev_stop(struct rte_eth_dev *dev)
813 struct hn_data *hv = dev->data->dev_private;
815 PMD_INIT_FUNC_TRACE();
817 hn_rndis_set_rxfilter(hv, 0);
822 hn_dev_close(struct rte_eth_dev *dev)
824 PMD_INIT_FUNC_TRACE();
827 hn_dev_free_queues(dev);
830 static const struct eth_dev_ops hn_eth_dev_ops = {
831 .dev_configure = hn_dev_configure,
832 .dev_start = hn_dev_start,
833 .dev_stop = hn_dev_stop,
834 .dev_close = hn_dev_close,
835 .dev_infos_get = hn_dev_info_get,
836 .dev_supported_ptypes_get = hn_vf_supported_ptypes,
837 .promiscuous_enable = hn_dev_promiscuous_enable,
838 .promiscuous_disable = hn_dev_promiscuous_disable,
839 .allmulticast_enable = hn_dev_allmulticast_enable,
840 .allmulticast_disable = hn_dev_allmulticast_disable,
841 .set_mc_addr_list = hn_dev_mc_addr_list,
842 .reta_update = hn_rss_reta_update,
843 .reta_query = hn_rss_reta_query,
844 .rss_hash_update = hn_rss_hash_update,
845 .rss_hash_conf_get = hn_rss_hash_conf_get,
846 .tx_queue_setup = hn_dev_tx_queue_setup,
847 .tx_queue_release = hn_dev_tx_queue_release,
848 .tx_done_cleanup = hn_dev_tx_done_cleanup,
849 .rx_queue_setup = hn_dev_rx_queue_setup,
850 .rx_queue_release = hn_dev_rx_queue_release,
851 .link_update = hn_dev_link_update,
852 .stats_get = hn_dev_stats_get,
853 .stats_reset = hn_dev_stats_reset,
854 .xstats_get = hn_dev_xstats_get,
855 .xstats_get_names = hn_dev_xstats_get_names,
856 .xstats_reset = hn_dev_xstats_reset,
860 * Setup connection between PMD and kernel.
863 hn_attach(struct hn_data *hv, unsigned int mtu)
868 error = hn_nvs_attach(hv, mtu);
873 error = hn_rndis_attach(hv);
879 * Under certain conditions on certain versions of Hyper-V,
880 * the RNDIS rxfilter is _not_ zero on the hypervisor side
881 * after the successful RNDIS initialization.
883 hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_NONE);
892 hn_detach(struct hn_data *hv)
899 eth_hn_dev_init(struct rte_eth_dev *eth_dev)
901 struct hn_data *hv = eth_dev->data->dev_private;
902 struct rte_device *device = eth_dev->device;
903 struct rte_vmbus_device *vmbus;
904 unsigned int rxr_cnt;
907 PMD_INIT_FUNC_TRACE();
909 vmbus = container_of(device, struct rte_vmbus_device, device);
910 eth_dev->dev_ops = &hn_eth_dev_ops;
911 eth_dev->tx_pkt_burst = &hn_xmit_pkts;
912 eth_dev->rx_pkt_burst = &hn_recv_pkts;
915 * for secondary processes, we don't initialize any further as primary
916 * has already done this work.
918 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
921 /* Since Hyper-V only supports one MAC address, just use local data */
922 eth_dev->data->mac_addrs = &hv->mac_addr;
925 hv->rxbuf_res = &vmbus->resource[HV_RECV_BUF_MAP];
926 hv->chim_res = &vmbus->resource[HV_SEND_BUF_MAP];
927 hv->port_id = eth_dev->data->port_id;
928 hv->latency = HN_CHAN_LATENCY_NS;
930 rte_spinlock_init(&hv->vf_lock);
931 hv->vf_port = HN_INVALID_PORT;
933 err = hn_parse_args(eth_dev);
937 strlcpy(hv->owner.name, eth_dev->device->name,
938 RTE_ETH_MAX_OWNER_NAME_LEN);
939 err = rte_eth_dev_owner_new(&hv->owner.id);
941 PMD_INIT_LOG(ERR, "Can not get owner id");
945 /* Initialize primary channel input for control operations */
946 err = rte_vmbus_chan_open(vmbus, &hv->channels[0]);
950 rte_vmbus_set_latency(hv->vmbus, hv->channels[0], hv->latency);
952 hv->primary = hn_rx_queue_alloc(hv, 0,
953 eth_dev->device->numa_node);
958 err = hn_attach(hv, RTE_ETHER_MTU);
962 err = hn_tx_pool_init(eth_dev);
966 err = hn_rndis_get_eaddr(hv, hv->mac_addr.addr_bytes);
970 /* Multi queue requires later versions of windows server */
971 if (hv->nvs_ver < NVS_VERSION_5)
974 max_chan = rte_vmbus_max_channels(vmbus);
975 PMD_INIT_LOG(DEBUG, "VMBus max channels %d", max_chan);
979 if (hn_rndis_query_rsscaps(hv, &rxr_cnt) != 0)
982 hv->max_queues = RTE_MIN(rxr_cnt, (unsigned int)max_chan);
984 /* If VF was reported but not added, do it now */
985 if (hv->vf_present && !hn_vf_attached(hv)) {
986 PMD_INIT_LOG(DEBUG, "Adding VF device");
988 err = hn_vf_add(eth_dev, hv);
996 PMD_INIT_LOG(NOTICE, "device init failed");
998 hn_tx_pool_uninit(eth_dev);
1004 eth_hn_dev_uninit(struct rte_eth_dev *eth_dev)
1006 struct hn_data *hv = eth_dev->data->dev_private;
1009 PMD_INIT_FUNC_TRACE();
1011 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1014 hn_dev_stop(eth_dev);
1015 hn_dev_close(eth_dev);
1017 eth_dev->dev_ops = NULL;
1018 eth_dev->tx_pkt_burst = NULL;
1019 eth_dev->rx_pkt_burst = NULL;
1022 hn_tx_pool_uninit(eth_dev);
1023 rte_vmbus_chan_close(hv->primary->chan);
1024 rte_free(hv->primary);
1025 ret = rte_eth_dev_owner_delete(hv->owner.id);
1032 static int eth_hn_probe(struct rte_vmbus_driver *drv __rte_unused,
1033 struct rte_vmbus_device *dev)
1035 struct rte_eth_dev *eth_dev;
1038 PMD_INIT_FUNC_TRACE();
1040 eth_dev = eth_dev_vmbus_allocate(dev, sizeof(struct hn_data));
1044 ret = eth_hn_dev_init(eth_dev);
1046 eth_dev_vmbus_release(eth_dev);
1048 rte_eth_dev_probing_finish(eth_dev);
1053 static int eth_hn_remove(struct rte_vmbus_device *dev)
1055 struct rte_eth_dev *eth_dev;
1058 PMD_INIT_FUNC_TRACE();
1060 eth_dev = rte_eth_dev_allocated(dev->device.name);
1064 ret = eth_hn_dev_uninit(eth_dev);
1068 eth_dev_vmbus_release(eth_dev);
1072 /* Network device GUID */
1073 static const rte_uuid_t hn_net_ids[] = {
1074 /* f8615163-df3e-46c5-913f-f2d2f965ed0e */
1075 RTE_UUID_INIT(0xf8615163, 0xdf3e, 0x46c5, 0x913f, 0xf2d2f965ed0eULL),
1079 static struct rte_vmbus_driver rte_netvsc_pmd = {
1080 .id_table = hn_net_ids,
1081 .probe = eth_hn_probe,
1082 .remove = eth_hn_remove,
1085 RTE_PMD_REGISTER_VMBUS(net_netvsc, rte_netvsc_pmd);
1086 RTE_PMD_REGISTER_KMOD_DEP(net_netvsc, "* uio_hv_generic");
1088 RTE_INIT(hn_init_log)
1090 hn_logtype_init = rte_log_register("pmd.net.netvsc.init");
1091 if (hn_logtype_init >= 0)
1092 rte_log_set_level(hn_logtype_init, RTE_LOG_NOTICE);
1093 hn_logtype_driver = rte_log_register("pmd.net.netvsc.driver");
1094 if (hn_logtype_driver >= 0)
1095 rte_log_set_level(hn_logtype_driver, RTE_LOG_NOTICE);