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;
71 uint64_t protocol_features;
73 connectfd = accept(dev->listenfd, NULL, NULL);
77 dev->vhostfd = connectfd;
78 if (dev->ops->send_request(dev, VHOST_USER_GET_FEATURES,
79 &dev->device_features) < 0) {
80 PMD_INIT_LOG(ERR, "get_features failed: %s",
85 if (dev->device_features &
86 (1ULL << VHOST_USER_F_PROTOCOL_FEATURES)) {
87 if (dev->ops->send_request(dev,
88 VHOST_USER_GET_PROTOCOL_FEATURES,
92 dev->protocol_features &= protocol_features;
94 if (dev->ops->send_request(dev,
95 VHOST_USER_SET_PROTOCOL_FEATURES,
96 &dev->protocol_features))
99 if (!(dev->protocol_features &
100 (1ULL << VHOST_USER_PROTOCOL_F_MQ)))
101 dev->unsupported_features |= (1ull << VIRTIO_NET_F_MQ);
104 dev->device_features |= dev->frontend_features;
106 /* umask vhost-user unsupported features */
107 dev->device_features &= ~(dev->unsupported_features);
109 dev->features &= dev->device_features;
111 /* For packed ring, resetting queues is required in reconnection. */
112 if (vtpci_packed_queue(hw) &&
113 (vtpci_get_status(hw) & VIRTIO_CONFIG_STATUS_DRIVER_OK)) {
114 PMD_INIT_LOG(NOTICE, "Packets on the fly will be dropped"
115 " when packed ring reconnecting.");
116 virtio_user_reset_queues_packed(eth_dev);
119 ret = virtio_user_start_device(dev);
123 if (dev->queue_pairs > 1) {
124 ret = virtio_user_handle_mq(dev, dev->queue_pairs);
126 PMD_INIT_LOG(ERR, "Fails to enable multi-queue pairs!");
130 if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) {
131 if (rte_intr_disable(eth_dev->intr_handle) < 0) {
132 PMD_DRV_LOG(ERR, "interrupt disable failed");
135 rte_intr_callback_unregister(eth_dev->intr_handle,
136 virtio_interrupt_handler,
138 eth_dev->intr_handle->fd = connectfd;
139 rte_intr_callback_register(eth_dev->intr_handle,
140 virtio_interrupt_handler, eth_dev);
142 if (rte_intr_enable(eth_dev->intr_handle) < 0) {
143 PMD_DRV_LOG(ERR, "interrupt enable failed");
147 PMD_INIT_LOG(NOTICE, "server mode virtio-user reconnection succeeds!");
152 virtio_user_delayed_handler(void *param)
154 struct virtio_hw *hw = (struct virtio_hw *)param;
155 struct rte_eth_dev *eth_dev = &rte_eth_devices[hw->port_id];
156 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
158 if (rte_intr_disable(eth_dev->intr_handle) < 0) {
159 PMD_DRV_LOG(ERR, "interrupt disable failed");
162 rte_intr_callback_unregister(eth_dev->intr_handle,
163 virtio_interrupt_handler, eth_dev);
164 if (dev->is_server) {
165 if (dev->vhostfd >= 0) {
169 eth_dev->intr_handle->fd = dev->listenfd;
170 rte_intr_callback_register(eth_dev->intr_handle,
171 virtio_interrupt_handler, eth_dev);
172 if (rte_intr_enable(eth_dev->intr_handle) < 0) {
173 PMD_DRV_LOG(ERR, "interrupt enable failed");
180 virtio_user_read_dev_config(struct virtio_hw *hw, size_t offset,
181 void *dst, int length)
184 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
186 if (offset == offsetof(struct virtio_net_config, mac) &&
187 length == RTE_ETHER_ADDR_LEN) {
188 for (i = 0; i < RTE_ETHER_ADDR_LEN; ++i)
189 ((uint8_t *)dst)[i] = dev->mac_addr[i];
193 if (offset == offsetof(struct virtio_net_config, status)) {
196 if (dev->vhostfd >= 0) {
200 flags = fcntl(dev->vhostfd, F_GETFL);
201 if (fcntl(dev->vhostfd, F_SETFL,
202 flags | O_NONBLOCK) == -1) {
203 PMD_DRV_LOG(ERR, "error setting O_NONBLOCK flag");
206 r = recv(dev->vhostfd, buf, 128, MSG_PEEK);
207 if (r == 0 || (r < 0 && errno != EAGAIN)) {
208 dev->net_status &= (~VIRTIO_NET_S_LINK_UP);
209 PMD_DRV_LOG(ERR, "virtio-user port %u is down",
212 /* This function could be called in the process
213 * of interrupt handling, callback cannot be
214 * unregistered here, set an alarm to do it.
217 virtio_user_delayed_handler,
220 dev->net_status |= VIRTIO_NET_S_LINK_UP;
222 if (fcntl(dev->vhostfd, F_SETFL,
223 flags & ~O_NONBLOCK) == -1) {
224 PMD_DRV_LOG(ERR, "error clearing O_NONBLOCK flag");
227 } else if (dev->is_server) {
228 dev->net_status &= (~VIRTIO_NET_S_LINK_UP);
229 if (virtio_user_server_reconnect(dev) >= 0)
230 dev->net_status |= VIRTIO_NET_S_LINK_UP;
233 *(uint16_t *)dst = dev->net_status;
236 if (offset == offsetof(struct virtio_net_config, max_virtqueue_pairs))
237 *(uint16_t *)dst = dev->max_queue_pairs;
241 virtio_user_write_dev_config(struct virtio_hw *hw, size_t offset,
242 const void *src, int length)
245 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
247 if ((offset == offsetof(struct virtio_net_config, mac)) &&
248 (length == RTE_ETHER_ADDR_LEN))
249 for (i = 0; i < RTE_ETHER_ADDR_LEN; ++i)
250 dev->mac_addr[i] = ((const uint8_t *)src)[i];
252 PMD_DRV_LOG(ERR, "not supported offset=%zu, len=%d",
257 virtio_user_reset(struct virtio_hw *hw)
259 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
261 if (dev->status & VIRTIO_CONFIG_STATUS_DRIVER_OK)
262 virtio_user_stop_device(dev);
266 virtio_user_set_status(struct virtio_hw *hw, uint8_t status)
268 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
270 if (status & VIRTIO_CONFIG_STATUS_DRIVER_OK)
271 virtio_user_start_device(dev);
272 else if (status == VIRTIO_CONFIG_STATUS_RESET)
273 virtio_user_reset(hw);
274 dev->status = status;
275 virtio_user_send_status_update(dev, status);
279 virtio_user_get_status(struct virtio_hw *hw)
281 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
287 virtio_user_get_features(struct virtio_hw *hw)
289 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
291 /* unmask feature bits defined in vhost user protocol */
292 return dev->device_features & VIRTIO_PMD_SUPPORTED_GUEST_FEATURES;
296 virtio_user_set_features(struct virtio_hw *hw, uint64_t features)
298 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
300 dev->features = features & dev->device_features;
304 virtio_user_get_isr(struct virtio_hw *hw __rte_unused)
306 /* rxq interrupts and config interrupt are separated in virtio-user,
307 * here we only report config change.
309 return VIRTIO_PCI_ISR_CONFIG;
313 virtio_user_set_config_irq(struct virtio_hw *hw __rte_unused,
314 uint16_t vec __rte_unused)
320 virtio_user_set_queue_irq(struct virtio_hw *hw __rte_unused,
321 struct virtqueue *vq __rte_unused,
324 /* pretend we have done that */
328 /* This function is to get the queue size, aka, number of descs, of a specified
329 * queue. Different with the VHOST_USER_GET_QUEUE_NUM, which is used to get the
330 * max supported queues.
333 virtio_user_get_queue_num(struct virtio_hw *hw, uint16_t queue_id __rte_unused)
335 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
337 /* Currently, each queue has same queue size */
338 return dev->queue_size;
342 virtio_user_setup_queue_packed(struct virtqueue *vq,
343 struct virtio_user_dev *dev)
345 uint16_t queue_idx = vq->vq_queue_index;
346 struct vring_packed *vring;
352 vring = &dev->packed_vrings[queue_idx];
353 desc_addr = (uintptr_t)vq->vq_ring_virt_mem;
354 avail_addr = desc_addr + vq->vq_nentries *
355 sizeof(struct vring_packed_desc);
356 used_addr = RTE_ALIGN_CEIL(avail_addr +
357 sizeof(struct vring_packed_desc_event),
358 VIRTIO_PCI_VRING_ALIGN);
359 vring->num = vq->vq_nentries;
360 vring->desc = (void *)(uintptr_t)desc_addr;
361 vring->driver = (void *)(uintptr_t)avail_addr;
362 vring->device = (void *)(uintptr_t)used_addr;
363 dev->packed_queues[queue_idx].avail_wrap_counter = true;
364 dev->packed_queues[queue_idx].used_wrap_counter = true;
366 for (i = 0; i < vring->num; i++)
367 vring->desc[i].flags = 0;
371 virtio_user_setup_queue_split(struct virtqueue *vq, struct virtio_user_dev *dev)
373 uint16_t queue_idx = vq->vq_queue_index;
374 uint64_t desc_addr, avail_addr, used_addr;
376 desc_addr = (uintptr_t)vq->vq_ring_virt_mem;
377 avail_addr = desc_addr + vq->vq_nentries * sizeof(struct vring_desc);
378 used_addr = RTE_ALIGN_CEIL(avail_addr + offsetof(struct vring_avail,
379 ring[vq->vq_nentries]),
380 VIRTIO_PCI_VRING_ALIGN);
382 dev->vrings[queue_idx].num = vq->vq_nentries;
383 dev->vrings[queue_idx].desc = (void *)(uintptr_t)desc_addr;
384 dev->vrings[queue_idx].avail = (void *)(uintptr_t)avail_addr;
385 dev->vrings[queue_idx].used = (void *)(uintptr_t)used_addr;
389 virtio_user_setup_queue(struct virtio_hw *hw, struct virtqueue *vq)
391 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
393 if (vtpci_packed_queue(hw))
394 virtio_user_setup_queue_packed(vq, dev);
396 virtio_user_setup_queue_split(vq, dev);
402 virtio_user_del_queue(struct virtio_hw *hw, struct virtqueue *vq)
404 /* For legacy devices, write 0 to VIRTIO_PCI_QUEUE_PFN port, QEMU
405 * correspondingly stops the ioeventfds, and reset the status of
407 * For modern devices, set queue desc, avail, used in PCI bar to 0,
408 * not see any more behavior in QEMU.
410 * Here we just care about what information to deliver to vhost-user
411 * or vhost-kernel. So we just close ioeventfd for now.
413 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
415 close(dev->callfds[vq->vq_queue_index]);
416 close(dev->kickfds[vq->vq_queue_index]);
420 virtio_user_notify_queue(struct virtio_hw *hw, struct virtqueue *vq)
423 struct virtio_user_dev *dev = virtio_user_get_dev(hw);
425 if (hw->cvq && (hw->cvq->vq == vq)) {
426 if (vtpci_packed_queue(vq->hw))
427 virtio_user_handle_cq_packed(dev, vq->vq_queue_index);
429 virtio_user_handle_cq(dev, vq->vq_queue_index);
433 if (write(dev->kickfds[vq->vq_queue_index], &buf, sizeof(buf)) < 0)
434 PMD_DRV_LOG(ERR, "failed to kick backend: %s",
438 const struct virtio_pci_ops virtio_user_ops = {
439 .read_dev_cfg = virtio_user_read_dev_config,
440 .write_dev_cfg = virtio_user_write_dev_config,
441 .get_status = virtio_user_get_status,
442 .set_status = virtio_user_set_status,
443 .get_features = virtio_user_get_features,
444 .set_features = virtio_user_set_features,
445 .get_isr = virtio_user_get_isr,
446 .set_config_irq = virtio_user_set_config_irq,
447 .set_queue_irq = virtio_user_set_queue_irq,
448 .get_queue_num = virtio_user_get_queue_num,
449 .setup_queue = virtio_user_setup_queue,
450 .del_queue = virtio_user_del_queue,
451 .notify_queue = virtio_user_notify_queue,
454 static const char *valid_args[] = {
455 #define VIRTIO_USER_ARG_QUEUES_NUM "queues"
456 VIRTIO_USER_ARG_QUEUES_NUM,
457 #define VIRTIO_USER_ARG_CQ_NUM "cq"
458 VIRTIO_USER_ARG_CQ_NUM,
459 #define VIRTIO_USER_ARG_MAC "mac"
461 #define VIRTIO_USER_ARG_PATH "path"
462 VIRTIO_USER_ARG_PATH,
463 #define VIRTIO_USER_ARG_QUEUE_SIZE "queue_size"
464 VIRTIO_USER_ARG_QUEUE_SIZE,
465 #define VIRTIO_USER_ARG_INTERFACE_NAME "iface"
466 VIRTIO_USER_ARG_INTERFACE_NAME,
467 #define VIRTIO_USER_ARG_SERVER_MODE "server"
468 VIRTIO_USER_ARG_SERVER_MODE,
469 #define VIRTIO_USER_ARG_MRG_RXBUF "mrg_rxbuf"
470 VIRTIO_USER_ARG_MRG_RXBUF,
471 #define VIRTIO_USER_ARG_IN_ORDER "in_order"
472 VIRTIO_USER_ARG_IN_ORDER,
473 #define VIRTIO_USER_ARG_PACKED_VQ "packed_vq"
474 VIRTIO_USER_ARG_PACKED_VQ,
475 #define VIRTIO_USER_ARG_SPEED "speed"
476 VIRTIO_USER_ARG_SPEED,
477 #define VIRTIO_USER_ARG_VECTORIZED "vectorized"
478 VIRTIO_USER_ARG_VECTORIZED,
482 #define VIRTIO_USER_DEF_CQ_EN 0
483 #define VIRTIO_USER_DEF_Q_NUM 1
484 #define VIRTIO_USER_DEF_Q_SZ 256
485 #define VIRTIO_USER_DEF_SERVER_MODE 0
488 get_string_arg(const char *key __rte_unused,
489 const char *value, void *extra_args)
491 if (!value || !extra_args)
494 *(char **)extra_args = strdup(value);
496 if (!*(char **)extra_args)
503 get_integer_arg(const char *key __rte_unused,
504 const char *value, void *extra_args)
506 uint64_t integer = 0;
507 if (!value || !extra_args)
510 integer = strtoull(value, NULL, 0);
511 /* extra_args keeps default value, it should be replaced
512 * only in case of successful parsing of the 'value' arg
515 *(uint64_t *)extra_args = integer;
519 static struct rte_eth_dev *
520 virtio_user_eth_dev_alloc(struct rte_vdev_device *vdev)
522 struct rte_eth_dev *eth_dev;
523 struct rte_eth_dev_data *data;
524 struct virtio_hw *hw;
525 struct virtio_user_dev *dev;
527 eth_dev = rte_eth_vdev_allocate(vdev, sizeof(*hw));
529 PMD_INIT_LOG(ERR, "cannot alloc rte_eth_dev");
533 data = eth_dev->data;
534 hw = eth_dev->data->dev_private;
536 dev = rte_zmalloc(NULL, sizeof(*dev), 0);
538 PMD_INIT_LOG(ERR, "malloc virtio_user_dev failed");
539 rte_eth_dev_release_port(eth_dev);
543 hw->port_id = data->port_id;
544 dev->port_id = data->port_id;
545 virtio_hw_internal[hw->port_id].vtpci_ops = &virtio_user_ops;
547 * MSIX is required to enable LSC (see virtio_init_device).
548 * Here just pretend that we support msix.
554 hw->use_inorder_rx = 0;
555 hw->use_inorder_tx = 0;
556 hw->virtio_user_dev = dev;
561 virtio_user_eth_dev_free(struct rte_eth_dev *eth_dev)
563 struct rte_eth_dev_data *data = eth_dev->data;
564 struct virtio_hw *hw = data->dev_private;
566 rte_free(hw->virtio_user_dev);
567 rte_eth_dev_release_port(eth_dev);
570 /* Dev initialization routine. Invoked once for each virtio vdev at
571 * EAL init time, see rte_bus_probe().
572 * Returns 0 on success.
575 virtio_user_pmd_probe(struct rte_vdev_device *dev)
577 struct rte_kvargs *kvlist = NULL;
578 struct rte_eth_dev *eth_dev;
579 struct virtio_hw *hw;
580 uint64_t queues = VIRTIO_USER_DEF_Q_NUM;
581 uint64_t cq = VIRTIO_USER_DEF_CQ_EN;
582 uint64_t queue_size = VIRTIO_USER_DEF_Q_SZ;
583 uint64_t server_mode = VIRTIO_USER_DEF_SERVER_MODE;
584 uint64_t mrg_rxbuf = 1;
585 uint64_t in_order = 1;
586 uint64_t packed_vq = 0;
587 uint64_t vectorized = 0;
590 char *mac_addr = NULL;
593 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
594 const char *name = rte_vdev_device_name(dev);
595 eth_dev = rte_eth_dev_attach_secondary(name);
597 PMD_INIT_LOG(ERR, "Failed to probe %s", name);
601 if (eth_virtio_dev_init(eth_dev) < 0) {
602 PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
603 rte_eth_dev_release_port(eth_dev);
607 eth_dev->dev_ops = &virtio_user_secondary_eth_dev_ops;
608 eth_dev->device = &dev->device;
609 rte_eth_dev_probing_finish(eth_dev);
613 kvlist = rte_kvargs_parse(rte_vdev_device_args(dev), valid_args);
615 PMD_INIT_LOG(ERR, "error when parsing param");
619 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_PATH) == 1) {
620 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_PATH,
621 &get_string_arg, &path) < 0) {
622 PMD_INIT_LOG(ERR, "error to parse %s",
623 VIRTIO_USER_ARG_PATH);
627 PMD_INIT_LOG(ERR, "arg %s is mandatory for virtio_user",
628 VIRTIO_USER_ARG_PATH);
632 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_INTERFACE_NAME) == 1) {
633 if (is_vhost_user_by_type(path)) {
635 "arg %s applies only to vhost-kernel backend",
636 VIRTIO_USER_ARG_INTERFACE_NAME);
640 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_INTERFACE_NAME,
641 &get_string_arg, &ifname) < 0) {
642 PMD_INIT_LOG(ERR, "error to parse %s",
643 VIRTIO_USER_ARG_INTERFACE_NAME);
648 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_MAC) == 1) {
649 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_MAC,
650 &get_string_arg, &mac_addr) < 0) {
651 PMD_INIT_LOG(ERR, "error to parse %s",
652 VIRTIO_USER_ARG_MAC);
657 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE) == 1) {
658 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUE_SIZE,
659 &get_integer_arg, &queue_size) < 0) {
660 PMD_INIT_LOG(ERR, "error to parse %s",
661 VIRTIO_USER_ARG_QUEUE_SIZE);
666 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_QUEUES_NUM) == 1) {
667 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_QUEUES_NUM,
668 &get_integer_arg, &queues) < 0) {
669 PMD_INIT_LOG(ERR, "error to parse %s",
670 VIRTIO_USER_ARG_QUEUES_NUM);
675 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_SERVER_MODE) == 1) {
676 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_SERVER_MODE,
677 &get_integer_arg, &server_mode) < 0) {
678 PMD_INIT_LOG(ERR, "error to parse %s",
679 VIRTIO_USER_ARG_SERVER_MODE);
684 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_CQ_NUM) == 1) {
685 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_CQ_NUM,
686 &get_integer_arg, &cq) < 0) {
687 PMD_INIT_LOG(ERR, "error to parse %s",
688 VIRTIO_USER_ARG_CQ_NUM);
691 } else if (queues > 1) {
695 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_PACKED_VQ) == 1) {
696 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_PACKED_VQ,
697 &get_integer_arg, &packed_vq) < 0) {
698 PMD_INIT_LOG(ERR, "error to parse %s",
699 VIRTIO_USER_ARG_PACKED_VQ);
704 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_VECTORIZED) == 1) {
705 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_VECTORIZED,
706 &get_integer_arg, &vectorized) < 0) {
707 PMD_INIT_LOG(ERR, "error to parse %s",
708 VIRTIO_USER_ARG_VECTORIZED);
713 if (queues > 1 && cq == 0) {
714 PMD_INIT_LOG(ERR, "multi-q requires ctrl-q");
718 if (queues > VIRTIO_MAX_VIRTQUEUE_PAIRS) {
719 PMD_INIT_LOG(ERR, "arg %s %" PRIu64 " exceeds the limit %u",
720 VIRTIO_USER_ARG_QUEUES_NUM, queues,
721 VIRTIO_MAX_VIRTQUEUE_PAIRS);
725 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_MRG_RXBUF) == 1) {
726 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_MRG_RXBUF,
727 &get_integer_arg, &mrg_rxbuf) < 0) {
728 PMD_INIT_LOG(ERR, "error to parse %s",
729 VIRTIO_USER_ARG_MRG_RXBUF);
734 if (rte_kvargs_count(kvlist, VIRTIO_USER_ARG_IN_ORDER) == 1) {
735 if (rte_kvargs_process(kvlist, VIRTIO_USER_ARG_IN_ORDER,
736 &get_integer_arg, &in_order) < 0) {
737 PMD_INIT_LOG(ERR, "error to parse %s",
738 VIRTIO_USER_ARG_IN_ORDER);
743 eth_dev = virtio_user_eth_dev_alloc(dev);
745 PMD_INIT_LOG(ERR, "virtio_user fails to alloc device");
749 hw = eth_dev->data->dev_private;
750 if (virtio_user_dev_init(hw->virtio_user_dev, path, queues, cq,
751 queue_size, mac_addr, &ifname, server_mode,
752 mrg_rxbuf, in_order, packed_vq) < 0) {
753 PMD_INIT_LOG(ERR, "virtio_user_dev_init fails");
754 virtio_user_eth_dev_free(eth_dev);
758 /* previously called by pci probing for physical dev */
759 if (eth_virtio_dev_init(eth_dev) < 0) {
760 PMD_INIT_LOG(ERR, "eth_virtio_dev_init fails");
761 virtio_user_eth_dev_free(eth_dev);
767 #if defined(CC_AVX512_SUPPORT)
772 "building environment do not support packed ring vectorized");
779 rte_eth_dev_probing_finish(eth_dev);
784 rte_kvargs_free(kvlist);
795 virtio_user_pmd_remove(struct rte_vdev_device *vdev)
798 struct rte_eth_dev *eth_dev;
803 name = rte_vdev_device_name(vdev);
804 PMD_DRV_LOG(INFO, "Un-Initializing %s", name);
805 eth_dev = rte_eth_dev_allocated(name);
806 /* Port has already been released by close. */
810 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
811 return rte_eth_dev_release_port(eth_dev);
813 /* make sure the device is stopped, queues freed */
814 rte_eth_dev_close(eth_dev->data->port_id);
819 static struct rte_vdev_driver virtio_user_driver = {
820 .probe = virtio_user_pmd_probe,
821 .remove = virtio_user_pmd_remove,
824 RTE_PMD_REGISTER_VDEV(net_virtio_user, virtio_user_driver);
825 RTE_PMD_REGISTER_ALIAS(net_virtio_user, virtio_user);
826 RTE_PMD_REGISTER_PARAM_STRING(net_virtio_user,