9c4ae80e7e16cce4094e9b620136eaf165bd47d4
[dpdk.git] / drivers / net / netvsc / hn_ethdev.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2016-2018 Microsoft Corporation
3  * Copyright(c) 2013-2016 Brocade Communications Systems, Inc.
4  * All rights reserved.
5  */
6
7 #include <stdint.h>
8 #include <string.h>
9 #include <stdio.h>
10 #include <errno.h>
11 #include <unistd.h>
12 #include <dirent.h>
13 #include <net/if.h>
14 #include <net/if_arp.h>
15 #include <netinet/in.h>
16 #include <sys/ioctl.h>
17
18 #include <rte_ethdev.h>
19 #include <rte_memcpy.h>
20 #include <rte_string_fns.h>
21 #include <rte_memzone.h>
22 #include <rte_devargs.h>
23 #include <rte_malloc.h>
24 #include <rte_kvargs.h>
25 #include <rte_atomic.h>
26 #include <rte_branch_prediction.h>
27 #include <rte_ether.h>
28 #include <ethdev_driver.h>
29 #include <rte_cycles.h>
30 #include <rte_errno.h>
31 #include <rte_memory.h>
32 #include <rte_eal.h>
33 #include <rte_dev.h>
34 #include <rte_bus_vmbus.h>
35 #include <rte_alarm.h>
36
37 #include "hn_logs.h"
38 #include "hn_var.h"
39 #include "hn_rndis.h"
40 #include "hn_nvs.h"
41 #include "ndis.h"
42
43 #define HN_TX_OFFLOAD_CAPS (RTE_ETH_TX_OFFLOAD_IPV4_CKSUM | \
44                             RTE_ETH_TX_OFFLOAD_TCP_CKSUM  | \
45                             RTE_ETH_TX_OFFLOAD_UDP_CKSUM  | \
46                             RTE_ETH_TX_OFFLOAD_TCP_TSO    | \
47                             RTE_ETH_TX_OFFLOAD_MULTI_SEGS | \
48                             RTE_ETH_TX_OFFLOAD_VLAN_INSERT)
49
50 #define HN_RX_OFFLOAD_CAPS (RTE_ETH_RX_OFFLOAD_CHECKSUM | \
51                             RTE_ETH_RX_OFFLOAD_VLAN_STRIP | \
52                             RTE_ETH_RX_OFFLOAD_RSS_HASH)
53
54 #define NETVSC_ARG_LATENCY "latency"
55 #define NETVSC_ARG_RXBREAK "rx_copybreak"
56 #define NETVSC_ARG_TXBREAK "tx_copybreak"
57 #define NETVSC_ARG_RX_EXTMBUF_ENABLE "rx_extmbuf_enable"
58
59 /* The max number of retry when hot adding a VF device */
60 #define NETVSC_MAX_HOTADD_RETRY 10
61
62 struct hn_xstats_name_off {
63         char name[RTE_ETH_XSTATS_NAME_SIZE];
64         unsigned int offset;
65 };
66
67 static const struct hn_xstats_name_off hn_stat_strings[] = {
68         { "good_packets",           offsetof(struct hn_stats, packets) },
69         { "good_bytes",             offsetof(struct hn_stats, bytes) },
70         { "errors",                 offsetof(struct hn_stats, errors) },
71         { "ring full",              offsetof(struct hn_stats, ring_full) },
72         { "channel full",           offsetof(struct hn_stats, channel_full) },
73         { "multicast_packets",      offsetof(struct hn_stats, multicast) },
74         { "broadcast_packets",      offsetof(struct hn_stats, broadcast) },
75         { "undersize_packets",      offsetof(struct hn_stats, size_bins[0]) },
76         { "size_64_packets",        offsetof(struct hn_stats, size_bins[1]) },
77         { "size_65_127_packets",    offsetof(struct hn_stats, size_bins[2]) },
78         { "size_128_255_packets",   offsetof(struct hn_stats, size_bins[3]) },
79         { "size_256_511_packets",   offsetof(struct hn_stats, size_bins[4]) },
80         { "size_512_1023_packets",  offsetof(struct hn_stats, size_bins[5]) },
81         { "size_1024_1518_packets", offsetof(struct hn_stats, size_bins[6]) },
82         { "size_1519_max_packets",  offsetof(struct hn_stats, size_bins[7]) },
83 };
84
85 /* The default RSS key.
86  * This value is the same as MLX5 so that flows will be
87  * received on same path for both VF and synthetic NIC.
88  */
89 static const uint8_t rss_default_key[NDIS_HASH_KEYSIZE_TOEPLITZ] = {
90         0x2c, 0xc6, 0x81, 0xd1, 0x5b, 0xdb, 0xf4, 0xf7,
91         0xfc, 0xa2, 0x83, 0x19, 0xdb, 0x1a, 0x3e, 0x94,
92         0x6b, 0x9e, 0x38, 0xd9, 0x2c, 0x9c, 0x03, 0xd1,
93         0xad, 0x99, 0x44, 0xa7, 0xd9, 0x56, 0x3d, 0x59,
94         0x06, 0x3c, 0x25, 0xf3, 0xfc, 0x1f, 0xdc, 0x2a,
95 };
96
97 static struct rte_eth_dev *
98 eth_dev_vmbus_allocate(struct rte_vmbus_device *dev, size_t private_data_size)
99 {
100         struct rte_eth_dev *eth_dev;
101         const char *name;
102
103         if (!dev)
104                 return NULL;
105
106         name = dev->device.name;
107
108         if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
109                 eth_dev = rte_eth_dev_allocate(name);
110                 if (!eth_dev) {
111                         PMD_DRV_LOG(NOTICE, "can not allocate rte ethdev");
112                         return NULL;
113                 }
114
115                 if (private_data_size) {
116                         eth_dev->data->dev_private =
117                                 rte_zmalloc_socket(name, private_data_size,
118                                                      RTE_CACHE_LINE_SIZE, dev->device.numa_node);
119                         if (!eth_dev->data->dev_private) {
120                                 PMD_DRV_LOG(NOTICE, "can not allocate driver data");
121                                 rte_eth_dev_release_port(eth_dev);
122                                 return NULL;
123                         }
124                 }
125         } else {
126                 eth_dev = rte_eth_dev_attach_secondary(name);
127                 if (!eth_dev) {
128                         PMD_DRV_LOG(NOTICE, "can not attach secondary");
129                         return NULL;
130                 }
131         }
132
133         eth_dev->device = &dev->device;
134
135         /* interrupt is simulated */
136         dev->intr_handle.type = RTE_INTR_HANDLE_EXT;
137         eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
138         eth_dev->intr_handle = &dev->intr_handle;
139
140         return eth_dev;
141 }
142
143 static void
144 eth_dev_vmbus_release(struct rte_eth_dev *eth_dev)
145 {
146         /* free ether device */
147         rte_eth_dev_release_port(eth_dev);
148
149         eth_dev->device = NULL;
150         eth_dev->intr_handle = NULL;
151 }
152
153 static int hn_set_parameter(const char *key, const char *value, void *opaque)
154 {
155         struct hn_data *hv = opaque;
156         char *endp = NULL;
157         unsigned long v;
158
159         v = strtoul(value, &endp, 0);
160         if (*value == '\0' || *endp != '\0') {
161                 PMD_DRV_LOG(ERR, "invalid parameter %s=%s", key, value);
162                 return -EINVAL;
163         }
164
165         if (!strcmp(key, NETVSC_ARG_LATENCY)) {
166                 /* usec to nsec */
167                 hv->latency = v * 1000;
168                 PMD_DRV_LOG(DEBUG, "set latency %u usec", hv->latency);
169         } else if (!strcmp(key, NETVSC_ARG_RXBREAK)) {
170                 hv->rx_copybreak = v;
171                 PMD_DRV_LOG(DEBUG, "rx copy break set to %u",
172                             hv->rx_copybreak);
173         } else if (!strcmp(key, NETVSC_ARG_TXBREAK)) {
174                 hv->tx_copybreak = v;
175                 PMD_DRV_LOG(DEBUG, "tx copy break set to %u",
176                             hv->tx_copybreak);
177         } else if (!strcmp(key, NETVSC_ARG_RX_EXTMBUF_ENABLE)) {
178                 hv->rx_extmbuf_enable = v;
179                 PMD_DRV_LOG(DEBUG, "rx extmbuf enable set to %u",
180                             hv->rx_extmbuf_enable);
181         }
182
183         return 0;
184 }
185
186 /* Parse device arguments */
187 static int hn_parse_args(const struct rte_eth_dev *dev)
188 {
189         struct hn_data *hv = dev->data->dev_private;
190         struct rte_devargs *devargs = dev->device->devargs;
191         static const char * const valid_keys[] = {
192                 NETVSC_ARG_LATENCY,
193                 NETVSC_ARG_RXBREAK,
194                 NETVSC_ARG_TXBREAK,
195                 NETVSC_ARG_RX_EXTMBUF_ENABLE,
196                 NULL
197         };
198         struct rte_kvargs *kvlist;
199         int ret;
200
201         if (!devargs)
202                 return 0;
203
204         PMD_INIT_LOG(DEBUG, "device args %s %s",
205                      devargs->name, devargs->args);
206
207         kvlist = rte_kvargs_parse(devargs->args, valid_keys);
208         if (!kvlist) {
209                 PMD_DRV_LOG(ERR, "invalid parameters");
210                 return -EINVAL;
211         }
212
213         ret = rte_kvargs_process(kvlist, NULL, hn_set_parameter, hv);
214         rte_kvargs_free(kvlist);
215
216         return ret;
217 }
218
219 /* Update link status.
220  * Note: the DPDK definition of "wait_to_complete"
221  *   means block this call until link is up.
222  *   which is not worth supporting.
223  */
224 int
225 hn_dev_link_update(struct rte_eth_dev *dev,
226                    int wait_to_complete __rte_unused)
227 {
228         struct hn_data *hv = dev->data->dev_private;
229         struct rte_eth_link link, old;
230         int error;
231
232         old = dev->data->dev_link;
233
234         error = hn_rndis_get_linkstatus(hv);
235         if (error)
236                 return error;
237
238         hn_rndis_get_linkspeed(hv);
239
240         link = (struct rte_eth_link) {
241                 .link_duplex = RTE_ETH_LINK_FULL_DUPLEX,
242                 .link_autoneg = RTE_ETH_LINK_SPEED_FIXED,
243                 .link_speed = hv->link_speed / 10000,
244         };
245
246         if (hv->link_status == NDIS_MEDIA_STATE_CONNECTED)
247                 link.link_status = RTE_ETH_LINK_UP;
248         else
249                 link.link_status = RTE_ETH_LINK_DOWN;
250
251         if (old.link_status == link.link_status)
252                 return 0;
253
254         PMD_INIT_LOG(DEBUG, "Port %d is %s", dev->data->port_id,
255                      (link.link_status == RTE_ETH_LINK_UP) ? "up" : "down");
256
257         return rte_eth_linkstatus_set(dev, &link);
258 }
259
260 static int hn_dev_info_get(struct rte_eth_dev *dev,
261                            struct rte_eth_dev_info *dev_info)
262 {
263         struct hn_data *hv = dev->data->dev_private;
264         int rc;
265
266         dev_info->speed_capa = RTE_ETH_LINK_SPEED_10G;
267         dev_info->min_rx_bufsize = HN_MIN_RX_BUF_SIZE;
268         dev_info->max_rx_pktlen  = HN_MAX_XFER_LEN;
269         dev_info->max_mac_addrs  = 1;
270
271         dev_info->hash_key_size = NDIS_HASH_KEYSIZE_TOEPLITZ;
272         dev_info->flow_type_rss_offloads = hv->rss_offloads;
273         dev_info->reta_size = RTE_ETH_RSS_RETA_SIZE_128;
274
275         dev_info->max_rx_queues = hv->max_queues;
276         dev_info->max_tx_queues = hv->max_queues;
277
278         dev_info->tx_desc_lim.nb_min = 1;
279         dev_info->tx_desc_lim.nb_max = 4096;
280
281         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
282                 return 0;
283
284         /* fills in rx and tx offload capability */
285         rc = hn_rndis_get_offload(hv, dev_info);
286         if (rc != 0)
287                 return rc;
288
289         /* merges the offload and queues of vf */
290         return hn_vf_info_get(hv, dev_info);
291 }
292
293 static int hn_rss_reta_update(struct rte_eth_dev *dev,
294                               struct rte_eth_rss_reta_entry64 *reta_conf,
295                               uint16_t reta_size)
296 {
297         struct hn_data *hv = dev->data->dev_private;
298         unsigned int i;
299         int err;
300
301         PMD_INIT_FUNC_TRACE();
302
303         if (reta_size != NDIS_HASH_INDCNT) {
304                 PMD_DRV_LOG(ERR, "Hash lookup table size does not match NDIS");
305                 return -EINVAL;
306         }
307
308         for (i = 0; i < NDIS_HASH_INDCNT; i++) {
309                 uint16_t idx = i / RTE_ETH_RETA_GROUP_SIZE;
310                 uint16_t shift = i % RTE_ETH_RETA_GROUP_SIZE;
311                 uint64_t mask = (uint64_t)1 << shift;
312
313                 if (reta_conf[idx].mask & mask)
314                         hv->rss_ind[i] = reta_conf[idx].reta[shift];
315         }
316
317         err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
318         if (err) {
319                 PMD_DRV_LOG(NOTICE,
320                         "rss disable failed");
321                 return err;
322         }
323
324         err = hn_rndis_conf_rss(hv, 0);
325         if (err) {
326                 PMD_DRV_LOG(NOTICE,
327                             "reta reconfig failed");
328                 return err;
329         }
330
331         return hn_vf_reta_hash_update(dev, reta_conf, reta_size);
332 }
333
334 static int hn_rss_reta_query(struct rte_eth_dev *dev,
335                              struct rte_eth_rss_reta_entry64 *reta_conf,
336                              uint16_t reta_size)
337 {
338         struct hn_data *hv = dev->data->dev_private;
339         unsigned int i;
340
341         PMD_INIT_FUNC_TRACE();
342
343         if (reta_size != NDIS_HASH_INDCNT) {
344                 PMD_DRV_LOG(ERR, "Hash lookup table size does not match NDIS");
345                 return -EINVAL;
346         }
347
348         for (i = 0; i < NDIS_HASH_INDCNT; i++) {
349                 uint16_t idx = i / RTE_ETH_RETA_GROUP_SIZE;
350                 uint16_t shift = i % RTE_ETH_RETA_GROUP_SIZE;
351                 uint64_t mask = (uint64_t)1 << shift;
352
353                 if (reta_conf[idx].mask & mask)
354                         reta_conf[idx].reta[shift] = hv->rss_ind[i];
355         }
356         return 0;
357 }
358
359 static void hn_rss_hash_init(struct hn_data *hv,
360                              const struct rte_eth_rss_conf *rss_conf)
361 {
362         /* Convert from DPDK RSS hash flags to NDIS hash flags */
363         hv->rss_hash = NDIS_HASH_FUNCTION_TOEPLITZ;
364
365         if (rss_conf->rss_hf & RTE_ETH_RSS_IPV4)
366                 hv->rss_hash |= NDIS_HASH_IPV4;
367         if (rss_conf->rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP)
368                 hv->rss_hash |= NDIS_HASH_TCP_IPV4;
369         if (rss_conf->rss_hf & RTE_ETH_RSS_IPV6)
370                 hv->rss_hash |=  NDIS_HASH_IPV6;
371         if (rss_conf->rss_hf & RTE_ETH_RSS_IPV6_EX)
372                 hv->rss_hash |=  NDIS_HASH_IPV6_EX;
373         if (rss_conf->rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP)
374                 hv->rss_hash |= NDIS_HASH_TCP_IPV6;
375         if (rss_conf->rss_hf & RTE_ETH_RSS_IPV6_TCP_EX)
376                 hv->rss_hash |= NDIS_HASH_TCP_IPV6_EX;
377
378         memcpy(hv->rss_key, rss_conf->rss_key ? : rss_default_key,
379                NDIS_HASH_KEYSIZE_TOEPLITZ);
380 }
381
382 static int hn_rss_hash_update(struct rte_eth_dev *dev,
383                               struct rte_eth_rss_conf *rss_conf)
384 {
385         struct hn_data *hv = dev->data->dev_private;
386         int err;
387
388         PMD_INIT_FUNC_TRACE();
389
390         err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
391         if (err) {
392                 PMD_DRV_LOG(NOTICE,
393                             "rss disable failed");
394                 return err;
395         }
396
397         hn_rss_hash_init(hv, rss_conf);
398
399         if (rss_conf->rss_hf != 0) {
400                 err = hn_rndis_conf_rss(hv, 0);
401                 if (err) {
402                         PMD_DRV_LOG(NOTICE,
403                                     "rss reconfig failed (RSS disabled)");
404                         return err;
405                 }
406         }
407
408         return hn_vf_rss_hash_update(dev, rss_conf);
409 }
410
411 static int hn_rss_hash_conf_get(struct rte_eth_dev *dev,
412                                 struct rte_eth_rss_conf *rss_conf)
413 {
414         struct hn_data *hv = dev->data->dev_private;
415
416         PMD_INIT_FUNC_TRACE();
417
418         if (hv->ndis_ver < NDIS_VERSION_6_20) {
419                 PMD_DRV_LOG(DEBUG, "RSS not supported on this host");
420                 return -EOPNOTSUPP;
421         }
422
423         rss_conf->rss_key_len = NDIS_HASH_KEYSIZE_TOEPLITZ;
424         if (rss_conf->rss_key)
425                 memcpy(rss_conf->rss_key, hv->rss_key,
426                        NDIS_HASH_KEYSIZE_TOEPLITZ);
427
428         rss_conf->rss_hf = 0;
429         if (hv->rss_hash & NDIS_HASH_IPV4)
430                 rss_conf->rss_hf |= RTE_ETH_RSS_IPV4;
431
432         if (hv->rss_hash & NDIS_HASH_TCP_IPV4)
433                 rss_conf->rss_hf |= RTE_ETH_RSS_NONFRAG_IPV4_TCP;
434
435         if (hv->rss_hash & NDIS_HASH_IPV6)
436                 rss_conf->rss_hf |= RTE_ETH_RSS_IPV6;
437
438         if (hv->rss_hash & NDIS_HASH_IPV6_EX)
439                 rss_conf->rss_hf |= RTE_ETH_RSS_IPV6_EX;
440
441         if (hv->rss_hash & NDIS_HASH_TCP_IPV6)
442                 rss_conf->rss_hf |= RTE_ETH_RSS_NONFRAG_IPV6_TCP;
443
444         if (hv->rss_hash & NDIS_HASH_TCP_IPV6_EX)
445                 rss_conf->rss_hf |= RTE_ETH_RSS_IPV6_TCP_EX;
446
447         return 0;
448 }
449
450 static int
451 hn_dev_promiscuous_enable(struct rte_eth_dev *dev)
452 {
453         struct hn_data *hv = dev->data->dev_private;
454
455         hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_PROMISCUOUS);
456         return hn_vf_promiscuous_enable(dev);
457 }
458
459 static int
460 hn_dev_promiscuous_disable(struct rte_eth_dev *dev)
461 {
462         struct hn_data *hv = dev->data->dev_private;
463         uint32_t filter;
464
465         filter = NDIS_PACKET_TYPE_DIRECTED | NDIS_PACKET_TYPE_BROADCAST;
466         if (dev->data->all_multicast)
467                 filter |= NDIS_PACKET_TYPE_ALL_MULTICAST;
468         hn_rndis_set_rxfilter(hv, filter);
469         return hn_vf_promiscuous_disable(dev);
470 }
471
472 static int
473 hn_dev_allmulticast_enable(struct rte_eth_dev *dev)
474 {
475         struct hn_data *hv = dev->data->dev_private;
476
477         hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_DIRECTED |
478                               NDIS_PACKET_TYPE_ALL_MULTICAST |
479                         NDIS_PACKET_TYPE_BROADCAST);
480         return hn_vf_allmulticast_enable(dev);
481 }
482
483 static int
484 hn_dev_allmulticast_disable(struct rte_eth_dev *dev)
485 {
486         struct hn_data *hv = dev->data->dev_private;
487
488         hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_DIRECTED |
489                              NDIS_PACKET_TYPE_BROADCAST);
490         return hn_vf_allmulticast_disable(dev);
491 }
492
493 static int
494 hn_dev_mc_addr_list(struct rte_eth_dev *dev,
495                      struct rte_ether_addr *mc_addr_set,
496                      uint32_t nb_mc_addr)
497 {
498         /* No filtering on the synthetic path, but can do it on VF */
499         return hn_vf_mc_addr_list(dev, mc_addr_set, nb_mc_addr);
500 }
501
502 /* Setup shared rx/tx queue data */
503 static int hn_subchan_configure(struct hn_data *hv,
504                                 uint32_t subchan)
505 {
506         struct vmbus_channel *primary = hn_primary_chan(hv);
507         int err;
508         unsigned int retry = 0;
509
510         PMD_DRV_LOG(DEBUG,
511                     "open %u subchannels", subchan);
512
513         /* Send create sub channels command */
514         err = hn_nvs_alloc_subchans(hv, &subchan);
515         if (err)
516                 return  err;
517
518         while (subchan > 0) {
519                 struct vmbus_channel *new_sc;
520                 uint16_t chn_index;
521
522                 err = rte_vmbus_subchan_open(primary, &new_sc);
523                 if (err == -ENOENT && ++retry < 1000) {
524                         /* This can happen if not ready yet */
525                         rte_delay_ms(10);
526                         continue;
527                 }
528
529                 if (err) {
530                         PMD_DRV_LOG(ERR,
531                                     "open subchannel failed: %d", err);
532                         return err;
533                 }
534
535                 rte_vmbus_set_latency(hv->vmbus, new_sc, hv->latency);
536
537                 retry = 0;
538                 chn_index = rte_vmbus_sub_channel_index(new_sc);
539                 if (chn_index == 0 || chn_index > hv->max_queues) {
540                         PMD_DRV_LOG(ERR,
541                                     "Invalid subchannel offermsg channel %u",
542                                     chn_index);
543                         return -EIO;
544                 }
545
546                 PMD_DRV_LOG(DEBUG, "new sub channel %u", chn_index);
547                 hv->channels[chn_index] = new_sc;
548                 --subchan;
549         }
550
551         return err;
552 }
553
554 static void netvsc_hotplug_retry(void *args)
555 {
556         int ret;
557         struct hn_data *hv = args;
558         struct rte_eth_dev *dev = &rte_eth_devices[hv->port_id];
559         struct rte_devargs *d = &hv->devargs;
560         char buf[256];
561
562         DIR *di;
563         struct dirent *dir;
564         struct ifreq req;
565         struct rte_ether_addr eth_addr;
566         int s;
567
568         PMD_DRV_LOG(DEBUG, "%s: retry count %d",
569                     __func__, hv->eal_hot_plug_retry);
570
571         if (hv->eal_hot_plug_retry++ > NETVSC_MAX_HOTADD_RETRY)
572                 return;
573
574         snprintf(buf, sizeof(buf), "/sys/bus/pci/devices/%s/net", d->name);
575         di = opendir(buf);
576         if (!di) {
577                 PMD_DRV_LOG(DEBUG, "%s: can't open directory %s, "
578                             "retrying in 1 second", __func__, buf);
579                 goto retry;
580         }
581
582         while ((dir = readdir(di))) {
583                 /* Skip . and .. directories */
584                 if (!strcmp(dir->d_name, ".") || !strcmp(dir->d_name, ".."))
585                         continue;
586
587                 /* trying to get mac address if this is a network device*/
588                 s = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
589                 if (s == -1) {
590                         PMD_DRV_LOG(ERR, "Failed to create socket errno %d",
591                                     errno);
592                         break;
593                 }
594                 strlcpy(req.ifr_name, dir->d_name, sizeof(req.ifr_name));
595                 ret = ioctl(s, SIOCGIFHWADDR, &req);
596                 close(s);
597                 if (ret == -1) {
598                         PMD_DRV_LOG(ERR,
599                                     "Failed to send SIOCGIFHWADDR for device %s",
600                                     dir->d_name);
601                         break;
602                 }
603                 if (req.ifr_hwaddr.sa_family != ARPHRD_ETHER) {
604                         closedir(di);
605                         return;
606                 }
607                 memcpy(eth_addr.addr_bytes, req.ifr_hwaddr.sa_data,
608                        RTE_DIM(eth_addr.addr_bytes));
609
610                 if (rte_is_same_ether_addr(&eth_addr, dev->data->mac_addrs)) {
611                         PMD_DRV_LOG(NOTICE,
612                                     "Found matching MAC address, adding device %s network name %s",
613                                     d->name, dir->d_name);
614                         ret = rte_eal_hotplug_add(d->bus->name, d->name,
615                                                   d->args);
616                         if (ret) {
617                                 PMD_DRV_LOG(ERR,
618                                             "Failed to add PCI device %s",
619                                             d->name);
620                                 break;
621                         }
622                 }
623                 /* When the code reaches here, we either have already added
624                  * the device, or its MAC address did not match.
625                  */
626                 closedir(di);
627                 return;
628         }
629         closedir(di);
630 retry:
631         /* The device is still being initialized, retry after 1 second */
632         rte_eal_alarm_set(1000000, netvsc_hotplug_retry, hv);
633 }
634
635 static void
636 netvsc_hotadd_callback(const char *device_name, enum rte_dev_event_type type,
637                        void *arg)
638 {
639         struct hn_data *hv = arg;
640         struct rte_devargs *d = &hv->devargs;
641         int ret;
642
643         PMD_DRV_LOG(INFO, "Device notification type=%d device_name=%s",
644                     type, device_name);
645
646         switch (type) {
647         case RTE_DEV_EVENT_ADD:
648                 /* if we already has a VF, don't check on hot add */
649                 if (hv->vf_ctx.vf_state > vf_removed)
650                         break;
651
652                 ret = rte_devargs_parse(d, device_name);
653                 if (ret) {
654                         PMD_DRV_LOG(ERR,
655                                     "devargs parsing failed ret=%d", ret);
656                         return;
657                 }
658
659                 if (!strcmp(d->bus->name, "pci")) {
660                         /* Start the process of figuring out if this
661                          * PCI device is a VF device
662                          */
663                         hv->eal_hot_plug_retry = 0;
664                         rte_eal_alarm_set(1000000, netvsc_hotplug_retry, hv);
665                 }
666
667                 /* We will switch to VF on RDNIS configure message
668                  * sent from VSP
669                  */
670
671                 break;
672         default:
673                 break;
674         }
675 }
676
677 static int hn_dev_configure(struct rte_eth_dev *dev)
678 {
679         struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
680         struct rte_eth_rss_conf *rss_conf = &dev_conf->rx_adv_conf.rss_conf;
681         const struct rte_eth_rxmode *rxmode = &dev_conf->rxmode;
682         const struct rte_eth_txmode *txmode = &dev_conf->txmode;
683         struct hn_data *hv = dev->data->dev_private;
684         uint64_t unsupported;
685         int i, err, subchan;
686
687         PMD_INIT_FUNC_TRACE();
688
689         if (dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
690                 dev_conf->rxmode.offloads |= RTE_ETH_RX_OFFLOAD_RSS_HASH;
691
692         unsupported = txmode->offloads & ~HN_TX_OFFLOAD_CAPS;
693         if (unsupported) {
694                 PMD_DRV_LOG(NOTICE,
695                             "unsupported TX offload: %#" PRIx64,
696                             unsupported);
697                 return -EINVAL;
698         }
699
700         unsupported = rxmode->offloads & ~HN_RX_OFFLOAD_CAPS;
701         if (unsupported) {
702                 PMD_DRV_LOG(NOTICE,
703                             "unsupported RX offload: %#" PRIx64,
704                             rxmode->offloads);
705                 return -EINVAL;
706         }
707
708         hv->vlan_strip = !!(rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
709
710         err = hn_rndis_conf_offload(hv, txmode->offloads,
711                                     rxmode->offloads);
712         if (err) {
713                 PMD_DRV_LOG(NOTICE,
714                             "offload configure failed");
715                 return err;
716         }
717
718         hv->num_queues = RTE_MAX(dev->data->nb_rx_queues,
719                                  dev->data->nb_tx_queues);
720
721         for (i = 0; i < NDIS_HASH_INDCNT; i++)
722                 hv->rss_ind[i] = i % dev->data->nb_rx_queues;
723
724         hn_rss_hash_init(hv, rss_conf);
725
726         subchan = hv->num_queues - 1;
727         if (subchan > 0) {
728                 err = hn_subchan_configure(hv, subchan);
729                 if (err) {
730                         PMD_DRV_LOG(NOTICE,
731                                     "subchannel configuration failed");
732                         return err;
733                 }
734
735                 err = hn_rndis_conf_rss(hv, NDIS_RSS_FLAG_DISABLE);
736                 if (err) {
737                         PMD_DRV_LOG(NOTICE,
738                                 "rss disable failed");
739                         return err;
740                 }
741
742                 if (rss_conf->rss_hf != 0) {
743                         err = hn_rndis_conf_rss(hv, 0);
744                         if (err) {
745                                 PMD_DRV_LOG(NOTICE,
746                                             "initial RSS config failed");
747                                 return err;
748                         }
749                 }
750         }
751
752         return hn_vf_configure_locked(dev, dev_conf);
753 }
754
755 static int hn_dev_stats_get(struct rte_eth_dev *dev,
756                             struct rte_eth_stats *stats)
757 {
758         unsigned int i;
759
760         hn_vf_stats_get(dev, stats);
761
762         for (i = 0; i < dev->data->nb_tx_queues; i++) {
763                 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
764
765                 if (!txq)
766                         continue;
767
768                 stats->opackets += txq->stats.packets;
769                 stats->obytes += txq->stats.bytes;
770                 stats->oerrors += txq->stats.errors;
771
772                 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
773                         stats->q_opackets[i] = txq->stats.packets;
774                         stats->q_obytes[i] = txq->stats.bytes;
775                 }
776         }
777
778         for (i = 0; i < dev->data->nb_rx_queues; i++) {
779                 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
780
781                 if (!rxq)
782                         continue;
783
784                 stats->ipackets += rxq->stats.packets;
785                 stats->ibytes += rxq->stats.bytes;
786                 stats->ierrors += rxq->stats.errors;
787                 stats->imissed += rxq->stats.ring_full;
788
789                 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
790                         stats->q_ipackets[i] = rxq->stats.packets;
791                         stats->q_ibytes[i] = rxq->stats.bytes;
792                 }
793         }
794
795         stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
796         return 0;
797 }
798
799 static int
800 hn_dev_stats_reset(struct rte_eth_dev *dev)
801 {
802         unsigned int i;
803
804         PMD_INIT_FUNC_TRACE();
805
806         for (i = 0; i < dev->data->nb_tx_queues; i++) {
807                 struct hn_tx_queue *txq = dev->data->tx_queues[i];
808
809                 if (!txq)
810                         continue;
811                 memset(&txq->stats, 0, sizeof(struct hn_stats));
812         }
813
814         for (i = 0; i < dev->data->nb_rx_queues; i++) {
815                 struct hn_rx_queue *rxq = dev->data->rx_queues[i];
816
817                 if (!rxq)
818                         continue;
819
820                 memset(&rxq->stats, 0, sizeof(struct hn_stats));
821         }
822
823         return 0;
824 }
825
826 static int
827 hn_dev_xstats_reset(struct rte_eth_dev *dev)
828 {
829         int ret;
830
831         ret = hn_dev_stats_reset(dev);
832         if (ret != 0)
833                 return 0;
834
835         return hn_vf_xstats_reset(dev);
836 }
837
838 static int
839 hn_dev_xstats_count(struct rte_eth_dev *dev)
840 {
841         int ret, count;
842
843         count = dev->data->nb_tx_queues * RTE_DIM(hn_stat_strings);
844         count += dev->data->nb_rx_queues * RTE_DIM(hn_stat_strings);
845
846         ret = hn_vf_xstats_get_names(dev, NULL, 0);
847         if (ret < 0)
848                 return ret;
849
850         return count + ret;
851 }
852
853 static int
854 hn_dev_xstats_get_names(struct rte_eth_dev *dev,
855                         struct rte_eth_xstat_name *xstats_names,
856                         unsigned int limit)
857 {
858         unsigned int i, t, count = 0;
859         int ret;
860
861         if (!xstats_names)
862                 return hn_dev_xstats_count(dev);
863
864         /* Note: limit checked in rte_eth_xstats_names() */
865         for (i = 0; i < dev->data->nb_tx_queues; i++) {
866                 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
867
868                 if (!txq)
869                         continue;
870
871                 if (count >= limit)
872                         break;
873
874                 for (t = 0; t < RTE_DIM(hn_stat_strings); t++)
875                         snprintf(xstats_names[count++].name,
876                                  RTE_ETH_XSTATS_NAME_SIZE,
877                                  "tx_q%u_%s", i, hn_stat_strings[t].name);
878         }
879
880         for (i = 0; i < dev->data->nb_rx_queues; i++)  {
881                 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
882
883                 if (!rxq)
884                         continue;
885
886                 if (count >= limit)
887                         break;
888
889                 for (t = 0; t < RTE_DIM(hn_stat_strings); t++)
890                         snprintf(xstats_names[count++].name,
891                                  RTE_ETH_XSTATS_NAME_SIZE,
892                                  "rx_q%u_%s", i,
893                                  hn_stat_strings[t].name);
894         }
895
896         ret = hn_vf_xstats_get_names(dev, xstats_names + count,
897                                      limit - count);
898         if (ret < 0)
899                 return ret;
900
901         return count + ret;
902 }
903
904 static int
905 hn_dev_xstats_get(struct rte_eth_dev *dev,
906                   struct rte_eth_xstat *xstats,
907                   unsigned int n)
908 {
909         unsigned int i, t, count = 0;
910         const unsigned int nstats = hn_dev_xstats_count(dev);
911         const char *stats;
912         int ret;
913
914         PMD_INIT_FUNC_TRACE();
915
916         if (n < nstats)
917                 return nstats;
918
919         for (i = 0; i < dev->data->nb_tx_queues; i++) {
920                 const struct hn_tx_queue *txq = dev->data->tx_queues[i];
921
922                 if (!txq)
923                         continue;
924
925                 stats = (const char *)&txq->stats;
926                 for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) {
927                         xstats[count].id = count;
928                         xstats[count].value = *(const uint64_t *)
929                                 (stats + hn_stat_strings[t].offset);
930                 }
931         }
932
933         for (i = 0; i < dev->data->nb_rx_queues; i++) {
934                 const struct hn_rx_queue *rxq = dev->data->rx_queues[i];
935
936                 if (!rxq)
937                         continue;
938
939                 stats = (const char *)&rxq->stats;
940                 for (t = 0; t < RTE_DIM(hn_stat_strings); t++, count++) {
941                         xstats[count].id = count;
942                         xstats[count].value = *(const uint64_t *)
943                                 (stats + hn_stat_strings[t].offset);
944                 }
945         }
946
947         ret = hn_vf_xstats_get(dev, xstats, count, n);
948         if (ret < 0)
949                 return ret;
950
951         return count + ret;
952 }
953
954 static int
955 hn_dev_start(struct rte_eth_dev *dev)
956 {
957         struct hn_data *hv = dev->data->dev_private;
958         int error;
959
960         PMD_INIT_FUNC_TRACE();
961
962         /* Register to monitor hot plug events */
963         error = rte_dev_event_callback_register(NULL, netvsc_hotadd_callback,
964                                                 hv);
965         if (error) {
966                 PMD_DRV_LOG(ERR, "failed to register device event callback");
967                 return error;
968         }
969
970         error = hn_rndis_set_rxfilter(hv,
971                                       NDIS_PACKET_TYPE_BROADCAST |
972                                       NDIS_PACKET_TYPE_ALL_MULTICAST |
973                                       NDIS_PACKET_TYPE_DIRECTED);
974         if (error)
975                 return error;
976
977         error = hn_vf_start(dev);
978         if (error)
979                 hn_rndis_set_rxfilter(hv, 0);
980
981         /* Initialize Link state */
982         if (error == 0)
983                 hn_dev_link_update(dev, 0);
984
985         return error;
986 }
987
988 static int
989 hn_dev_stop(struct rte_eth_dev *dev)
990 {
991         struct hn_data *hv = dev->data->dev_private;
992
993         PMD_INIT_FUNC_TRACE();
994         dev->data->dev_started = 0;
995
996         rte_dev_event_callback_unregister(NULL, netvsc_hotadd_callback, hv);
997         hn_rndis_set_rxfilter(hv, 0);
998         return hn_vf_stop(dev);
999 }
1000
1001 static int
1002 hn_dev_close(struct rte_eth_dev *dev)
1003 {
1004         int ret;
1005         struct hn_data *hv = dev->data->dev_private;
1006
1007         PMD_INIT_FUNC_TRACE();
1008         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1009                 return 0;
1010
1011         rte_eal_alarm_cancel(netvsc_hotplug_retry, &hv->devargs);
1012
1013         ret = hn_vf_close(dev);
1014         hn_dev_free_queues(dev);
1015
1016         return ret;
1017 }
1018
1019 static const struct eth_dev_ops hn_eth_dev_ops = {
1020         .dev_configure          = hn_dev_configure,
1021         .dev_start              = hn_dev_start,
1022         .dev_stop               = hn_dev_stop,
1023         .dev_close              = hn_dev_close,
1024         .dev_infos_get          = hn_dev_info_get,
1025         .txq_info_get           = hn_dev_tx_queue_info,
1026         .rxq_info_get           = hn_dev_rx_queue_info,
1027         .dev_supported_ptypes_get = hn_vf_supported_ptypes,
1028         .promiscuous_enable     = hn_dev_promiscuous_enable,
1029         .promiscuous_disable    = hn_dev_promiscuous_disable,
1030         .allmulticast_enable    = hn_dev_allmulticast_enable,
1031         .allmulticast_disable   = hn_dev_allmulticast_disable,
1032         .set_mc_addr_list       = hn_dev_mc_addr_list,
1033         .reta_update            = hn_rss_reta_update,
1034         .reta_query             = hn_rss_reta_query,
1035         .rss_hash_update        = hn_rss_hash_update,
1036         .rss_hash_conf_get      = hn_rss_hash_conf_get,
1037         .tx_queue_setup         = hn_dev_tx_queue_setup,
1038         .tx_queue_release       = hn_dev_tx_queue_release,
1039         .tx_done_cleanup        = hn_dev_tx_done_cleanup,
1040         .rx_queue_setup         = hn_dev_rx_queue_setup,
1041         .rx_queue_release       = hn_dev_rx_queue_release,
1042         .link_update            = hn_dev_link_update,
1043         .stats_get              = hn_dev_stats_get,
1044         .stats_reset            = hn_dev_stats_reset,
1045         .xstats_get             = hn_dev_xstats_get,
1046         .xstats_get_names       = hn_dev_xstats_get_names,
1047         .xstats_reset           = hn_dev_xstats_reset,
1048 };
1049
1050 /*
1051  * Setup connection between PMD and kernel.
1052  */
1053 static int
1054 hn_attach(struct hn_data *hv, unsigned int mtu)
1055 {
1056         int error;
1057
1058         /* Attach NVS */
1059         error = hn_nvs_attach(hv, mtu);
1060         if (error)
1061                 goto failed_nvs;
1062
1063         /* Attach RNDIS */
1064         error = hn_rndis_attach(hv);
1065         if (error)
1066                 goto failed_rndis;
1067
1068         /*
1069          * NOTE:
1070          * Under certain conditions on certain versions of Hyper-V,
1071          * the RNDIS rxfilter is _not_ zero on the hypervisor side
1072          * after the successful RNDIS initialization.
1073          */
1074         hn_rndis_set_rxfilter(hv, NDIS_PACKET_TYPE_NONE);
1075         return 0;
1076 failed_rndis:
1077         hn_nvs_detach(hv);
1078 failed_nvs:
1079         return error;
1080 }
1081
1082 static void
1083 hn_detach(struct hn_data *hv)
1084 {
1085         hn_nvs_detach(hv);
1086         hn_rndis_detach(hv);
1087 }
1088
1089 static int
1090 eth_hn_dev_init(struct rte_eth_dev *eth_dev)
1091 {
1092         struct hn_data *hv = eth_dev->data->dev_private;
1093         struct rte_device *device = eth_dev->device;
1094         struct rte_vmbus_device *vmbus;
1095         unsigned int rxr_cnt;
1096         int err, max_chan;
1097
1098         PMD_INIT_FUNC_TRACE();
1099
1100         vmbus = container_of(device, struct rte_vmbus_device, device);
1101         eth_dev->dev_ops = &hn_eth_dev_ops;
1102         eth_dev->rx_queue_count = hn_dev_rx_queue_count;
1103         eth_dev->rx_descriptor_status = hn_dev_rx_queue_status;
1104         eth_dev->tx_descriptor_status = hn_dev_tx_descriptor_status;
1105         eth_dev->tx_pkt_burst = &hn_xmit_pkts;
1106         eth_dev->rx_pkt_burst = &hn_recv_pkts;
1107
1108         /*
1109          * for secondary processes, we don't initialize any further as primary
1110          * has already done this work.
1111          */
1112         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1113                 return 0;
1114
1115         eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
1116
1117         /* Since Hyper-V only supports one MAC address */
1118         eth_dev->data->mac_addrs = rte_calloc("hv_mac", HN_MAX_MAC_ADDRS,
1119                                               sizeof(struct rte_ether_addr), 0);
1120         if (eth_dev->data->mac_addrs == NULL) {
1121                 PMD_INIT_LOG(ERR,
1122                              "Failed to allocate memory store MAC addresses");
1123                 return -ENOMEM;
1124         }
1125
1126         hv->vmbus = vmbus;
1127         hv->rxbuf_res = &vmbus->resource[HV_RECV_BUF_MAP];
1128         hv->chim_res  = &vmbus->resource[HV_SEND_BUF_MAP];
1129         hv->port_id = eth_dev->data->port_id;
1130         hv->latency = HN_CHAN_LATENCY_NS;
1131         hv->rx_copybreak = HN_RXCOPY_THRESHOLD;
1132         hv->tx_copybreak = HN_TXCOPY_THRESHOLD;
1133         hv->rx_extmbuf_enable = HN_RX_EXTMBUF_ENABLE;
1134         hv->max_queues = 1;
1135
1136         rte_rwlock_init(&hv->vf_lock);
1137         hv->vf_ctx.vf_vsc_switched = false;
1138         hv->vf_ctx.vf_vsp_reported = false;
1139         hv->vf_ctx.vf_attached = false;
1140         hv->vf_ctx.vf_state = vf_unknown;
1141
1142         err = hn_parse_args(eth_dev);
1143         if (err)
1144                 return err;
1145
1146         strlcpy(hv->owner.name, eth_dev->device->name,
1147                 RTE_ETH_MAX_OWNER_NAME_LEN);
1148         err = rte_eth_dev_owner_new(&hv->owner.id);
1149         if (err) {
1150                 PMD_INIT_LOG(ERR, "Can not get owner id");
1151                 return err;
1152         }
1153
1154         /* Initialize primary channel input for control operations */
1155         err = rte_vmbus_chan_open(vmbus, &hv->channels[0]);
1156         if (err)
1157                 return err;
1158
1159         rte_vmbus_set_latency(hv->vmbus, hv->channels[0], hv->latency);
1160
1161         hv->primary = hn_rx_queue_alloc(hv, 0,
1162                                         eth_dev->device->numa_node);
1163
1164         if (!hv->primary)
1165                 return -ENOMEM;
1166
1167         err = hn_attach(hv, RTE_ETHER_MTU);
1168         if  (err)
1169                 goto failed;
1170
1171         err = hn_chim_init(eth_dev);
1172         if (err)
1173                 goto failed;
1174
1175         err = hn_rndis_get_eaddr(hv, eth_dev->data->mac_addrs->addr_bytes);
1176         if (err)
1177                 goto failed;
1178
1179         /* Multi queue requires later versions of windows server */
1180         if (hv->nvs_ver < NVS_VERSION_5)
1181                 return 0;
1182
1183         max_chan = rte_vmbus_max_channels(vmbus);
1184         PMD_INIT_LOG(DEBUG, "VMBus max channels %d", max_chan);
1185         if (max_chan <= 0)
1186                 goto failed;
1187
1188         if (hn_rndis_query_rsscaps(hv, &rxr_cnt) != 0)
1189                 rxr_cnt = 1;
1190
1191         hv->max_queues = RTE_MIN(rxr_cnt, (unsigned int)max_chan);
1192
1193         /* If VF was reported but not added, do it now */
1194         if (hv->vf_ctx.vf_vsp_reported && !hv->vf_ctx.vf_vsc_switched) {
1195                 PMD_INIT_LOG(DEBUG, "Adding VF device");
1196
1197                 err = hn_vf_add(eth_dev, hv);
1198         }
1199
1200         return 0;
1201
1202 failed:
1203         PMD_INIT_LOG(NOTICE, "device init failed");
1204
1205         hn_chim_uninit(eth_dev);
1206         hn_detach(hv);
1207         return err;
1208 }
1209
1210 static int
1211 eth_hn_dev_uninit(struct rte_eth_dev *eth_dev)
1212 {
1213         struct hn_data *hv = eth_dev->data->dev_private;
1214         int ret, ret_stop;
1215
1216         PMD_INIT_FUNC_TRACE();
1217
1218         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
1219                 return 0;
1220
1221         ret_stop = hn_dev_stop(eth_dev);
1222         hn_dev_close(eth_dev);
1223
1224         hn_detach(hv);
1225         hn_chim_uninit(eth_dev);
1226         rte_vmbus_chan_close(hv->primary->chan);
1227         rte_free(hv->primary);
1228         ret = rte_eth_dev_owner_delete(hv->owner.id);
1229         if (ret != 0)
1230                 return ret;
1231
1232         return ret_stop;
1233 }
1234
1235 static int eth_hn_probe(struct rte_vmbus_driver *drv __rte_unused,
1236                         struct rte_vmbus_device *dev)
1237 {
1238         struct rte_eth_dev *eth_dev;
1239         int ret;
1240
1241         PMD_INIT_FUNC_TRACE();
1242
1243         ret = rte_dev_event_monitor_start();
1244         if (ret) {
1245                 PMD_DRV_LOG(ERR, "Failed to start device event monitoring");
1246                 return ret;
1247         }
1248
1249         eth_dev = eth_dev_vmbus_allocate(dev, sizeof(struct hn_data));
1250         if (!eth_dev)
1251                 return -ENOMEM;
1252
1253         ret = eth_hn_dev_init(eth_dev);
1254         if (ret) {
1255                 eth_dev_vmbus_release(eth_dev);
1256                 rte_dev_event_monitor_stop();
1257         } else {
1258                 rte_eth_dev_probing_finish(eth_dev);
1259         }
1260
1261         return ret;
1262 }
1263
1264 static int eth_hn_remove(struct rte_vmbus_device *dev)
1265 {
1266         struct rte_eth_dev *eth_dev;
1267         int ret;
1268
1269         PMD_INIT_FUNC_TRACE();
1270
1271         eth_dev = rte_eth_dev_allocated(dev->device.name);
1272         if (!eth_dev)
1273                 return 0; /* port already released */
1274
1275         ret = eth_hn_dev_uninit(eth_dev);
1276         if (ret)
1277                 return ret;
1278
1279         eth_dev_vmbus_release(eth_dev);
1280         rte_dev_event_monitor_stop();
1281         return 0;
1282 }
1283
1284 /* Network device GUID */
1285 static const rte_uuid_t hn_net_ids[] = {
1286         /*  f8615163-df3e-46c5-913f-f2d2f965ed0e */
1287         RTE_UUID_INIT(0xf8615163, 0xdf3e, 0x46c5, 0x913f, 0xf2d2f965ed0eULL),
1288         { 0 }
1289 };
1290
1291 static struct rte_vmbus_driver rte_netvsc_pmd = {
1292         .id_table = hn_net_ids,
1293         .probe = eth_hn_probe,
1294         .remove = eth_hn_remove,
1295 };
1296
1297 RTE_PMD_REGISTER_VMBUS(net_netvsc, rte_netvsc_pmd);
1298 RTE_PMD_REGISTER_KMOD_DEP(net_netvsc, "* uio_hv_generic");
1299 RTE_LOG_REGISTER_SUFFIX(hn_logtype_init, init, NOTICE);
1300 RTE_LOG_REGISTER_SUFFIX(hn_logtype_driver, driver, NOTICE);
1301 RTE_PMD_REGISTER_PARAM_STRING(net_netvsc,
1302                               NETVSC_ARG_LATENCY "=<uint32> "
1303                               NETVSC_ARG_RXBREAK "=<uint32> "
1304                               NETVSC_ARG_TXBREAK "=<uint32> "
1305                               NETVSC_ARG_RX_EXTMBUF_ENABLE "=<0|1>");