1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
9 #include <sys/socket.h>
11 #include <rte_malloc.h>
12 #include <rte_kvargs.h>
13 #include <rte_ethdev_vdev.h>
14 #include <rte_bus_vdev.h>
15 #include <rte_alarm.h>
16 #include <rte_cycles.h>
18 #include "virtio_ethdev.h"
19 #include "virtio_logs.h"
20 #include "virtio_pci.h"
21 #include "virtqueue.h"
22 #include "virtio_rxtx.h"
23 #include "virtio_user/virtio_user_dev.h"
24 #include "virtio_user/vhost.h"
26 #define virtio_user_get_dev(hw) \
27 ((struct virtio_user_dev *)(hw)->virtio_user_dev)
30 virtio_user_reset_queues_packed(struct rte_eth_dev *dev)
32 struct virtio_hw *hw = dev->data->dev_private;
33 struct virtnet_rx *rxvq;
34 struct virtnet_tx *txvq;
37 /* Add lock to avoid queue contention. */
38 rte_spinlock_lock(&hw->state_lock);
42 * Waitting for datapath to complete before resetting queues.
43 * 1 ms should be enough for the ongoing Tx/Rx function to finish.
47 /* Vring reset for each Tx queue and Rx queue. */
48 for (i = 0; i < dev->data->nb_rx_queues; i++) {
49 rxvq = dev->data->rx_queues[i];
50 virtqueue_rxvq_reset_packed(rxvq->vq);
51 virtio_dev_rx_queue_setup_finish(dev, i);
54 for (i = 0; i < dev->data->nb_tx_queues; i++) {
55 txvq = dev->data->tx_queues[i];
56 virtqueue_txvq_reset_packed(txvq->vq);
60 rte_spinlock_unlock(&hw->state_lock);
65 virtio_user_server_reconnect(struct virtio_user_dev *dev)
69 struct rte_eth_dev *eth_dev = &rte_eth_devices[dev->port_id];
70 struct virtio_hw *hw = eth_dev->data->dev_private;
72 connectfd = accept(dev->listenfd, NULL, NULL);
76 dev->vhostfd = connectfd;
77 if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES,
78 &dev->device_features) < 0) {
79 PMD_INIT_LOG(ERR, "get_features failed: %s",
84 dev->device_features |= dev->frontend_features;
86 /* umask vhost-user unsupported features */
87 dev->device_features &= ~(dev->unsupported_features);
89 dev->features &= dev->device_features;
91 /* For packed ring, resetting queues is required in reconnection. */
92 if (vtpci_packed_queue(hw) &&
93 (vtpci_get_status(hw) & VIRTIO_CONFIG_STATUS_DRIVER_OK)) {
94 PMD_INIT_LOG(NOTICE, "Packets on the fly will be dropped"
95 " when packed ring reconnecting.");
96 virtio_user_reset_queues_packed(eth_dev);
99 ret = virtio_user_start_device(dev);
103 if (dev->queue_pairs > 1) {
104 ret = virtio_user_handle_mq(dev, dev->queue_pairs);
106 PMD_INIT_LOG(ERR, "Fails to enable multi-queue pairs!");
110 if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) {
111 if (rte_intr_disable(eth_dev->intr_handle) < 0) {
112 PMD_DRV_LOG(ERR, "interrupt disable failed");
115 rte_intr_callback_unregister(eth_dev->intr_handle,
116 virtio_interrupt_handler,
118 eth_dev->intr_handle->fd = connectfd;
119 rte_intr_callback_register(eth_dev->intr_handle,
120 virtio_interrupt_handler, eth_dev);
122 if (rte_intr_enable(eth_dev->intr_handle) < 0) {
123 PMD_DRV_LOG(ERR, "interrupt enable failed");
127 PMD_INIT_LOG(NOTICE, "server mode virtio-user reconnection succeeds!");
132 virtio_user_delayed_handler(void *param)
134 struct virtio_hw *hw = (struct virtio_hw *)param;
135 struct rte_eth_dev *eth_dev = &rte_eth_devices[hw->port_id];
136 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
138 if (rte_intr_disable(eth_dev->intr_handle) < 0) {
139 PMD_DRV_LOG(ERR, "interrupt disable failed");
142 rte_intr_callback_unregister(eth_dev->intr_handle,
143 virtio_interrupt_handler, eth_dev);
144 if (dev->is_server) {
145 if (dev->vhostfd >= 0) {
149 eth_dev->intr_handle->fd = dev->listenfd;
150 rte_intr_callback_register(eth_dev->intr_handle,
151 virtio_interrupt_handler, eth_dev);
152 if (rte_intr_enable(eth_dev->intr_handle) < 0) {
153 PMD_DRV_LOG(ERR, "interrupt enable failed");
160 virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset,
161 void *dst, int length)
164 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
166 if (offset == offsetof(struct virtio_net_config, mac) &&
167 length == RTE_ETHER_ADDR_LEN) {
168 for (i = 0; i < RTE_ETHER_ADDR_LEN; ++i)
169 ((uint8_t *)dst)[i] = dev->mac_addr[i];
173 if (offset == offsetof(struct virtio_net_config, status)) {
176 if (dev->vhostfd >= 0) {
180 flags = fcntl(dev->vhostfd, F_GETFL);
181 if (fcntl(dev->vhostfd, F_SETFL,
182 flags | O_NONBLOCK) == -1) {
183 PMD_DRV_LOG(ERR, "error setting O_NONBLOCK flag");
186 r = recv(dev->vhostfd, buf, 128, MSG_PEEK);
187 if (r == 0 || (r < 0 && errno != EAGAIN)) {
188 dev->status &= (~VIRTIO_NET_S_LINK_UP);
189 PMD_DRV_LOG(ERR, "virtio-user port %u is down",
192 /* This function could be called in the process
193 * of interrupt handling, callback cannot be
194 * unregistered here, set an alarm to do it.
197 virtio_user_delayed_handler,
200 dev->status |= VIRTIO_NET_S_LINK_UP;
202 if (fcntl(dev->vhostfd, F_SETFL,
203 flags & ~O_NONBLOCK) == -1) {
204 PMD_DRV_LOG(ERR, "error clearing O_NONBLOCK flag");
207 } else if (dev->is_server) {
208 dev->status &= (~VIRTIO_NET_S_LINK_UP);
209 if (virtio_user_server_reconnect(dev) >= 0)
210 dev->status |= VIRTIO_NET_S_LINK_UP;
213 *(uint16_t *)dst = dev->status;
216 if (offset == offsetof(struct virtio_net_config, max_virtqueue_pairs))
217 *(uint16_t *)dst = dev->max_queue_pairs;
221 virtio_user_write_dev_config(struct virtio_hw *hw, size_t offset,
222 const void *src, int length)
225 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
227 if ((offset == offsetof(struct virtio_net_config, mac)) &&
228 (length == RTE_ETHER_ADDR_LEN))
229 for (i = 0; i < RTE_ETHER_ADDR_LEN; ++i)
230 dev->mac_addr[i] = ((const uint8_t *)src)[i];
232 PMD_DRV_LOG(ERR, "not supported offset=%zu, len=%d",
237 virtio_user_reset(struct virtio_hw *hw)
239 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
241 if (dev->status & VIRTIO_CONFIG_STATUS_DRIVER_OK)
242 virtio_user_stop_device(dev);
246 virtio_user_set_status(struct virtio_hw *hw, uint8_t status)
248 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
250 if (status & VIRTIO_CONFIG_STATUS_DRIVER_OK)
251 virtio_user_start_device(dev);
252 else if (status == VIRTIO_CONFIG_STATUS_RESET)
253 virtio_user_reset(hw);
254 dev->status = status;
258 virtio_user_get_status(struct virtio_hw *hw)
260 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
266 virtio_user_get_features(struct virtio_hw *hw)
268 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
270 /* unmask feature bits defined in vhost user protocol */
271 return dev->device_features & VIRTIO_PMD_SUPPORTED_GUEST_FEATURES;
275 virtio_user_set_features(struct virtio_hw *hw, uint64_t features)
277 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
279 dev->features = features & dev->device_features;
283 virtio_user_get_isr(struct virtio_hw *hw __rte_unused)
285 /* rxq interrupts and config interrupt are separated in virtio-user,
286 * here we only report config change.
288 return VIRTIO_PCI_ISR_CONFIG;
292 virtio_user_set_config_irq(struct virtio_hw *hw __rte_unused,
293 uint16_t vec __rte_unused)
299 virtio_user_set_queue_irq(struct virtio_hw *hw __rte_unused,
300 struct virtqueue *vq __rte_unused,
303 /* pretend we have done that */
307 /* This function is to get the queue size, aka, number of descs, of a specified
308 * queue. Different with the VHOST_USER_GET_QUEUE_NUM, which is used to get the
309 * max supported queues.
312 virtio_user_get_queue_num(struct virtio_hw *hw, uint16_t queue_id __rte_unused)
314 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
316 /* Currently, each queue has same queue size */
317 return dev->queue_size;
321 virtio_user_setup_queue_packed(struct virtqueue *vq,
322 struct virtio_user_dev *dev)
324 uint16_t queue_idx = vq->vq_queue_index;
325 struct vring_packed *vring;
331 vring = &dev->packed_vrings[queue_idx];
332 desc_addr = (uintptr_t)vq->vq_ring_virt_mem;
333 avail_addr = desc_addr + vq->vq_nentries *
334 sizeof(struct vring_packed_desc);
335 used_addr = RTE_ALIGN_CEIL(avail_addr +
336 sizeof(struct vring_packed_desc_event),
337 VIRTIO_PCI_VRING_ALIGN);
338 vring->num = vq->vq_nentries;
339 vring->desc = (void *)(uintptr_t)desc_addr;
340 vring->driver = (void *)(uintptr_t)avail_addr;
341 vring->device = (void *)(uintptr_t)used_addr;
342 dev->packed_queues[queue_idx].avail_wrap_counter = true;
343 dev->packed_queues[queue_idx].used_wrap_counter = true;
345 for (i = 0; i < vring->num; i++)
346 vring->desc[i].flags = 0;
350 virtio_user_setup_queue_split(struct virtqueue *vq, struct virtio_user_dev *dev)
352 uint16_t queue_idx = vq->vq_queue_index;
353 uint64_t desc_addr, avail_addr, used_addr;
355 desc_addr = (uintptr_t)vq->vq_ring_virt_mem;
356 avail_addr = desc_addr + vq->vq_nentries * sizeof(struct vring_desc);
357 used_addr = RTE_ALIGN_CEIL(avail_addr + offsetof(struct vring_avail,
358 ring[vq->vq_nentries]),
359 VIRTIO_PCI_VRING_ALIGN);
361 dev->vrings[queue_idx].num = vq->vq_nentries;
362 dev->vrings[queue_idx].desc = (void *)(uintptr_t)desc_addr;
363 dev->vrings[queue_idx].avail = (void *)(uintptr_t)avail_addr;
364 dev->vrings[queue_idx].used = (void *)(uintptr_t)used_addr;
368 virtio_user_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
370 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
372 if (vtpci_packed_queue(hw))
373 virtio_user_setup_queue_packed(vq, dev);
375 virtio_user_setup_queue_split(vq, dev);
381 virtio_user_del_queue(struct virtio_hw *hw, struct virtqueue *vq)
383 /* For legacy devices, write 0 to VIRTIO_PCI_QUEUE_PFN port, QEMU
384 * correspondingly stops the ioeventfds, and reset the status of
386 * For modern devices, set queue desc, avail, used in PCI bar to 0,
387 * not see any more behavior in QEMU.
389 * Here we just care about what information to deliver to vhost-user
390 * or vhost-kernel. So we just close ioeventfd for now.
392 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
394 close(dev->callfds[vq->vq_queue_index]);
395 close(dev->kickfds[vq->vq_queue_index]);
399 virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
402 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
404 if (hw->cvq && (hw->cvq->vq == vq)) {
405 if (vtpci_packed_queue(vq->hw))
406 virtio_user_handle_cq_packed(dev, vq->vq_queue_index);
408 virtio_user_handle_cq(dev, vq->vq_queue_index);
412 if (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0)
413 PMD_DRV_LOG(ERR, "failed to kick backend: %s",
417 const struct virtio_pci_ops virtio_user_ops = {
418 .read_dev_cfg = virtio_user_read_dev_config,
419 .write_dev_cfg = virtio_user_write_dev_config,
420 .get_status = virtio_user_get_status,
421 .set_status = virtio_user_set_status,
422 .get_features = virtio_user_get_features,
423 .set_features = virtio_user_set_features,
424 .get_isr = virtio_user_get_isr,
425 .set_config_irq = virtio_user_set_config_irq,
426 .set_queue_irq = virtio_user_set_queue_irq,
427 .get_queue_num = virtio_user_get_queue_num,
428 .setup_queue = virtio_user_setup_queue,
429 .del_queue = virtio_user_del_queue,
430 .notify_queue = virtio_user_notify_queue,
433 static const char *valid_args[] = {
434 #define VIRTIO_USER_ARG_QUEUES_NUM "queues"
435 VIRTIO_USER_ARG_QUEUES_NUM,
436 #define VIRTIO_USER_ARG_CQ_NUM "cq"
437 VIRTIO_USER_ARG_CQ_NUM,
438 #define VIRTIO_USER_ARG_MAC "mac"
440 #define VIRTIO_USER_ARG_PATH "path"
441 VIRTIO_USER_ARG_PATH,
442 #define VIRTIO_USER_ARG_QUEUE_SIZE "queue_size"
443 VIRTIO_USER_ARG_QUEUE_SIZE,
444 #define VIRTIO_USER_ARG_INTERFACE_NAME "iface"
445 VIRTIO_USER_ARG_INTERFACE_NAME,
446 #define VIRTIO_USER_ARG_SERVER_MODE "server"
447 VIRTIO_USER_ARG_SERVER_MODE,
448 #define VIRTIO_USER_ARG_MRG_RXBUF "mrg_rxbuf"
449 VIRTIO_USER_ARG_MRG_RXBUF,
450 #define VIRTIO_USER_ARG_IN_ORDER "in_order"
451 VIRTIO_USER_ARG_IN_ORDER,
452 #define VIRTIO_USER_ARG_PACKED_VQ "packed_vq"
453 VIRTIO_USER_ARG_PACKED_VQ,
454 #define VIRTIO_USER_ARG_SPEED "speed"
455 VIRTIO_USER_ARG_SPEED,
456 #define VIRTIO_USER_ARG_VECTORIZED "vectorized"
457 VIRTIO_USER_ARG_VECTORIZED,
461 #define VIRTIO_USER_DEF_CQ_EN 0
462 #define VIRTIO_USER_DEF_Q_NUM 1
463 #define VIRTIO_USER_DEF_Q_SZ 256
464 #define VIRTIO_USER_DEF_SERVER_MODE 0
467 get_string_arg(const char *key __rte_unused,
468 const char *value, void *extra_args)
470 if (!value || !extra_args)
473 *(char **)extra_args = strdup(value);
475 if (!*(char **)extra_args)
482 get_integer_arg(const char *key __rte_unused,
483 const char *value, void *extra_args)
485 uint64_t integer = 0;
486 if (!value || !extra_args)
489 integer = strtoull(value, NULL, 0);
490 /* extra_args keeps default value, it should be replaced
491 * only in case of successful parsing of the 'value' arg
494 *(uint64_t *)extra_args = integer;
498 static struct rte_eth_dev *
499 virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)
501 struct rte_eth_dev *eth_dev;
502 struct rte_eth_dev_data *data;
503 struct virtio_hw *hw;
504 struct virtio_user_dev *dev;
506 eth_dev = rte_eth_vdev_allocate(vdev, sizeof(*hw));
508 PMD_INIT_LOG(ERR, "cannot alloc rte_eth_dev");
512 data = eth_dev->data;
513 hw = eth_dev->data->dev_private;
515 dev = rte_zmalloc(NULL, sizeof(*dev), 0);
517 PMD_INIT_LOG(ERR, "malloc virtio_user_dev failed");
518 rte_eth_dev_release_port(eth_dev);
522 hw->port_id = data->port_id;
523 dev->port_id = data->port_id;
524 virtio_hw_internal[hw->port_id].vtpci_ops = &virtio_user_ops;
526 * MSIX is required to enable LSC (see virtio_init_device).
527 * Here just pretend that we support msix.
533 hw->use_inorder_rx = 0;
534 hw->use_inorder_tx = 0;
535 hw->virtio_user_dev = dev;
540 virtio_user_eth_dev_free(struct rte_eth_dev *eth_dev)
542 struct rte_eth_dev_data *data = eth_dev->data;
543 struct virtio_hw *hw = data->dev_private;
545 rte_free(hw->virtio_user_dev);
546 rte_eth_dev_release_port(eth_dev);
549 /* Dev initialization routine. Invoked once for each virtio vdev at
550 * EAL init time, see rte_bus_probe().
551 * Returns 0 on success.
554 virtio_user_pmd_probe(struct rte_vdev_device *dev)
556 struct rte_kvargs *kvlist = NULL;
557 struct rte_eth_dev *eth_dev;
558 struct virtio_hw *hw;
559 uint64_t queues = VIRTIO_USER_DEF_Q_NUM;
560 uint64_t cq = VIRTIO_USER_DEF_CQ_EN;
561 uint64_t queue_size = VIRTIO_USER_DEF_Q_SZ;
562 uint64_t server_mode = VIRTIO_USER_DEF_SERVER_MODE;
563 uint64_t mrg_rxbuf = 1;
564 uint64_t in_order = 1;
565 uint64_t packed_vq = 0;
566 uint64_t vectorized = 0;
569 char *mac_addr = NULL;
572 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
573 const char *name = rte_vdev_device_name(dev);
574 eth_dev = rte_eth_dev_attach_secondary(name);
576 PMD_INIT_LOG(ERR, "Failed to probe %s", name);
580 if (eth_virtio_dev_init(eth_dev) < 0) {
581 PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
582 rte_eth_dev_release_port(eth_dev);
586 eth_dev->dev_ops = &virtio_user_secondary_eth_dev_ops;
587 eth_dev->device = &dev->device;
588 rte_eth_dev_probing_finish(eth_dev);
592 kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_args);
594 PMD_INIT_LOG(ERR, "error when parsing param");
598 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_PATH) == 1) {
599 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_PATH,
600 &get_string_arg, &path) < 0) {
601 PMD_INIT_LOG(ERR, "error to parse %s",
602 VIRTIO_USER_ARG_PATH);
606 PMD_INIT_LOG(ERR, "arg %s is mandatory for virtio_user",
607 VIRTIO_USER_ARG_PATH);
611 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_INTERFACE_NAME) == 1) {
612 if (is_vhost_user_by_type(path)) {
614 "arg %s applies only to vhost-kernel backend",
615 VIRTIO_USER_ARG_INTERFACE_NAME);
619 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_INTERFACE_NAME,
620 &get_string_arg, &ifname) < 0) {
621 PMD_INIT_LOG(ERR, "error to parse %s",
622 VIRTIO_USER_ARG_INTERFACE_NAME);
627 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_MAC) == 1) {
628 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_MAC,
629 &get_string_arg, &mac_addr) < 0) {
630 PMD_INIT_LOG(ERR, "error to parse %s",
631 VIRTIO_USER_ARG_MAC);
636 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE) == 1) {
637 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE,
638 &get_integer_arg, &queue_size) < 0) {
639 PMD_INIT_LOG(ERR, "error to parse %s",
640 VIRTIO_USER_ARG_QUEUE_SIZE);
645 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUES_NUM) == 1) {
646 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUES_NUM,
647 &get_integer_arg, &queues) < 0) {
648 PMD_INIT_LOG(ERR, "error to parse %s",
649 VIRTIO_USER_ARG_QUEUES_NUM);
654 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_SERVER_MODE) == 1) {
655 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_SERVER_MODE,
656 &get_integer_arg, &server_mode) < 0) {
657 PMD_INIT_LOG(ERR, "error to parse %s",
658 VIRTIO_USER_ARG_SERVER_MODE);
663 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_CQ_NUM) == 1) {
664 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_CQ_NUM,
665 &get_integer_arg, &cq) < 0) {
666 PMD_INIT_LOG(ERR, "error to parse %s",
667 VIRTIO_USER_ARG_CQ_NUM);
670 } else if (queues > 1) {
674 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_PACKED_VQ) == 1) {
675 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_PACKED_VQ,
676 &get_integer_arg, &packed_vq) < 0) {
677 PMD_INIT_LOG(ERR, "error to parse %s",
678 VIRTIO_USER_ARG_PACKED_VQ);
683 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_VECTORIZED) == 1) {
684 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_VECTORIZED,
685 &get_integer_arg, &vectorized) < 0) {
686 PMD_INIT_LOG(ERR, "error to parse %s",
687 VIRTIO_USER_ARG_VECTORIZED);
692 if (queues > 1 && cq == 0) {
693 PMD_INIT_LOG(ERR, "multi-q requires ctrl-q");
697 if (queues > VIRTIO_MAX_VIRTQUEUE_PAIRS) {
698 PMD_INIT_LOG(ERR, "arg %s %" PRIu64 " exceeds the limit %u",
699 VIRTIO_USER_ARG_QUEUES_NUM, queues,
700 VIRTIO_MAX_VIRTQUEUE_PAIRS);
704 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_MRG_RXBUF) == 1) {
705 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_MRG_RXBUF,
706 &get_integer_arg, &mrg_rxbuf) < 0) {
707 PMD_INIT_LOG(ERR, "error to parse %s",
708 VIRTIO_USER_ARG_MRG_RXBUF);
713 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_IN_ORDER) == 1) {
714 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_IN_ORDER,
715 &get_integer_arg, &in_order) < 0) {
716 PMD_INIT_LOG(ERR, "error to parse %s",
717 VIRTIO_USER_ARG_IN_ORDER);
722 eth_dev = virtio_user_eth_dev_alloc(dev);
724 PMD_INIT_LOG(ERR, "virtio_user fails to alloc device");
728 hw = eth_dev->data->dev_private;
729 if (virtio_user_dev_init(hw->virtio_user_dev, path, queues, cq,
730 queue_size, mac_addr, &ifname, server_mode,
731 mrg_rxbuf, in_order, packed_vq) < 0) {
732 PMD_INIT_LOG(ERR, "virtio_user_dev_init fails");
733 virtio_user_eth_dev_free(eth_dev);
737 /* previously called by pci probing for physical dev */
738 if (eth_virtio_dev_init(eth_dev) < 0) {
739 PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
740 virtio_user_eth_dev_free(eth_dev);
746 #if defined(CC_AVX512_SUPPORT)
751 "building environment do not support packed ring vectorized");
758 rte_eth_dev_probing_finish(eth_dev);
763 rte_kvargs_free(kvlist);
774 virtio_user_pmd_remove(struct rte_vdev_device *vdev)
777 struct rte_eth_dev *eth_dev;
782 name = rte_vdev_device_name(vdev);
783 PMD_DRV_LOG(INFO, "Un-Initializing %s", name);
784 eth_dev = rte_eth_dev_allocated(name);
785 /* Port has already been released by close. */
789 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
790 return rte_eth_dev_release_port(eth_dev);
792 /* make sure the device is stopped, queues freed */
793 rte_eth_dev_close(eth_dev->data->port_id);
798 static struct rte_vdev_driver virtio_user_driver = {
799 .probe = virtio_user_pmd_probe,
800 .remove = virtio_user_pmd_remove,
803 RTE_PMD_REGISTER_VDEV(net_virtio_user, virtio_user_driver);
804 RTE_PMD_REGISTER_ALIAS(net_virtio_user, virtio_user);
805 RTE_PMD_REGISTER_PARAM_STRING(net_virtio_user,