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