1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2016 Intel Corporation
11 #include <rte_ethdev_driver.h>
12 #include <rte_ethdev_pci.h>
13 #include <rte_memcpy.h>
14 #include <rte_string_fns.h>
15 #include <rte_memzone.h>
16 #include <rte_malloc.h>
17 #include <rte_branch_prediction.h>
19 #include <rte_bus_pci.h>
20 #include <rte_ether.h>
23 #include <rte_common.h>
24 #include <rte_errno.h>
25 #include <rte_cpuflags.h>
27 #include <rte_memory.h>
30 #include <rte_cycles.h>
31 #include <rte_kvargs.h>
33 #include "virtio_ethdev.h"
34 #include "virtio_pci.h"
35 #include "virtio_logs.h"
36 #include "virtqueue.h"
37 #include "virtio_rxtx.h"
39 static int eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev);
40 static int virtio_dev_configure(struct rte_eth_dev *dev);
41 static int virtio_dev_start(struct rte_eth_dev *dev);
42 static void virtio_dev_stop(struct rte_eth_dev *dev);
43 static void virtio_dev_promiscuous_enable(struct rte_eth_dev *dev);
44 static void virtio_dev_promiscuous_disable(struct rte_eth_dev *dev);
45 static void virtio_dev_allmulticast_enable(struct rte_eth_dev *dev);
46 static void virtio_dev_allmulticast_disable(struct rte_eth_dev *dev);
47 static void virtio_dev_info_get(struct rte_eth_dev *dev,
48 struct rte_eth_dev_info *dev_info);
49 static int virtio_dev_link_update(struct rte_eth_dev *dev,
50 int wait_to_complete);
51 static int virtio_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask);
53 static void virtio_set_hwaddr(struct virtio_hw *hw);
54 static void virtio_get_hwaddr(struct virtio_hw *hw);
56 static int virtio_dev_stats_get(struct rte_eth_dev *dev,
57 struct rte_eth_stats *stats);
58 static int virtio_dev_xstats_get(struct rte_eth_dev *dev,
59 struct rte_eth_xstat *xstats, unsigned n);
60 static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
61 struct rte_eth_xstat_name *xstats_names,
63 static void virtio_dev_stats_reset(struct rte_eth_dev *dev);
64 static void virtio_dev_free_mbufs(struct rte_eth_dev *dev);
65 static int virtio_vlan_filter_set(struct rte_eth_dev *dev,
66 uint16_t vlan_id, int on);
67 static int virtio_mac_addr_add(struct rte_eth_dev *dev,
68 struct ether_addr *mac_addr,
69 uint32_t index, uint32_t vmdq);
70 static void virtio_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
71 static int virtio_mac_addr_set(struct rte_eth_dev *dev,
72 struct ether_addr *mac_addr);
74 static int virtio_intr_enable(struct rte_eth_dev *dev);
75 static int virtio_intr_disable(struct rte_eth_dev *dev);
77 static int virtio_dev_queue_stats_mapping_set(
78 struct rte_eth_dev *eth_dev,
83 int virtio_logtype_init;
84 int virtio_logtype_driver;
86 static void virtio_notify_peers(struct rte_eth_dev *dev);
87 static void virtio_ack_link_announce(struct rte_eth_dev *dev);
90 * The set of PCI devices this driver supports
92 static const struct rte_pci_id pci_id_virtio_map[] = {
93 { RTE_PCI_DEVICE(VIRTIO_PCI_VENDORID, VIRTIO_PCI_LEGACY_DEVICEID_NET) },
94 { RTE_PCI_DEVICE(VIRTIO_PCI_VENDORID, VIRTIO_PCI_MODERN_DEVICEID_NET) },
95 { .vendor_id = 0, /* sentinel */ },
98 struct rte_virtio_xstats_name_off {
99 char name[RTE_ETH_XSTATS_NAME_SIZE];
103 /* [rt]x_qX_ is prepended to the name string here */
104 static const struct rte_virtio_xstats_name_off rte_virtio_rxq_stat_strings[] = {
105 {"good_packets", offsetof(struct virtnet_rx, stats.packets)},
106 {"good_bytes", offsetof(struct virtnet_rx, stats.bytes)},
107 {"errors", offsetof(struct virtnet_rx, stats.errors)},
108 {"multicast_packets", offsetof(struct virtnet_rx, stats.multicast)},
109 {"broadcast_packets", offsetof(struct virtnet_rx, stats.broadcast)},
110 {"undersize_packets", offsetof(struct virtnet_rx, stats.size_bins[0])},
111 {"size_64_packets", offsetof(struct virtnet_rx, stats.size_bins[1])},
112 {"size_65_127_packets", offsetof(struct virtnet_rx, stats.size_bins[2])},
113 {"size_128_255_packets", offsetof(struct virtnet_rx, stats.size_bins[3])},
114 {"size_256_511_packets", offsetof(struct virtnet_rx, stats.size_bins[4])},
115 {"size_512_1023_packets", offsetof(struct virtnet_rx, stats.size_bins[5])},
116 {"size_1024_1518_packets", offsetof(struct virtnet_rx, stats.size_bins[6])},
117 {"size_1519_max_packets", offsetof(struct virtnet_rx, stats.size_bins[7])},
120 /* [rt]x_qX_ is prepended to the name string here */
121 static const struct rte_virtio_xstats_name_off rte_virtio_txq_stat_strings[] = {
122 {"good_packets", offsetof(struct virtnet_tx, stats.packets)},
123 {"good_bytes", offsetof(struct virtnet_tx, stats.bytes)},
124 {"errors", offsetof(struct virtnet_tx, stats.errors)},
125 {"multicast_packets", offsetof(struct virtnet_tx, stats.multicast)},
126 {"broadcast_packets", offsetof(struct virtnet_tx, stats.broadcast)},
127 {"undersize_packets", offsetof(struct virtnet_tx, stats.size_bins[0])},
128 {"size_64_packets", offsetof(struct virtnet_tx, stats.size_bins[1])},
129 {"size_65_127_packets", offsetof(struct virtnet_tx, stats.size_bins[2])},
130 {"size_128_255_packets", offsetof(struct virtnet_tx, stats.size_bins[3])},
131 {"size_256_511_packets", offsetof(struct virtnet_tx, stats.size_bins[4])},
132 {"size_512_1023_packets", offsetof(struct virtnet_tx, stats.size_bins[5])},
133 {"size_1024_1518_packets", offsetof(struct virtnet_tx, stats.size_bins[6])},
134 {"size_1519_max_packets", offsetof(struct virtnet_tx, stats.size_bins[7])},
137 #define VIRTIO_NB_RXQ_XSTATS (sizeof(rte_virtio_rxq_stat_strings) / \
138 sizeof(rte_virtio_rxq_stat_strings[0]))
139 #define VIRTIO_NB_TXQ_XSTATS (sizeof(rte_virtio_txq_stat_strings) / \
140 sizeof(rte_virtio_txq_stat_strings[0]))
142 struct virtio_hw_internal virtio_hw_internal[RTE_MAX_ETHPORTS];
145 virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
146 int *dlen, int pkt_num)
150 virtio_net_ctrl_ack status = ~0;
151 struct virtio_pmd_ctrl *result;
152 struct virtqueue *vq;
154 ctrl->status = status;
156 if (!cvq || !cvq->vq) {
157 PMD_INIT_LOG(ERR, "Control queue is not supported.");
161 rte_spinlock_lock(&cvq->lock);
163 head = vq->vq_desc_head_idx;
165 PMD_INIT_LOG(DEBUG, "vq->vq_desc_head_idx = %d, status = %d, "
166 "vq->hw->cvq = %p vq = %p",
167 vq->vq_desc_head_idx, status, vq->hw->cvq, vq);
169 if (vq->vq_free_cnt < pkt_num + 2 || pkt_num < 1) {
170 rte_spinlock_unlock(&cvq->lock);
174 memcpy(cvq->virtio_net_hdr_mz->addr, ctrl,
175 sizeof(struct virtio_pmd_ctrl));
178 * Format is enforced in qemu code:
179 * One TX packet for header;
180 * At least one TX packet per argument;
181 * One RX packet for ACK.
183 vq->vq_ring.desc[head].flags = VRING_DESC_F_NEXT;
184 vq->vq_ring.desc[head].addr = cvq->virtio_net_hdr_mem;
185 vq->vq_ring.desc[head].len = sizeof(struct virtio_net_ctrl_hdr);
187 i = vq->vq_ring.desc[head].next;
189 for (k = 0; k < pkt_num; k++) {
190 vq->vq_ring.desc[i].flags = VRING_DESC_F_NEXT;
191 vq->vq_ring.desc[i].addr = cvq->virtio_net_hdr_mem
192 + sizeof(struct virtio_net_ctrl_hdr)
193 + sizeof(ctrl->status) + sizeof(uint8_t)*sum;
194 vq->vq_ring.desc[i].len = dlen[k];
197 i = vq->vq_ring.desc[i].next;
200 vq->vq_ring.desc[i].flags = VRING_DESC_F_WRITE;
201 vq->vq_ring.desc[i].addr = cvq->virtio_net_hdr_mem
202 + sizeof(struct virtio_net_ctrl_hdr);
203 vq->vq_ring.desc[i].len = sizeof(ctrl->status);
206 vq->vq_desc_head_idx = vq->vq_ring.desc[i].next;
208 vq_update_avail_ring(vq, head);
209 vq_update_avail_idx(vq);
211 PMD_INIT_LOG(DEBUG, "vq->vq_queue_index = %d", vq->vq_queue_index);
213 virtqueue_notify(vq);
216 while (VIRTQUEUE_NUSED(vq) == 0) {
221 while (VIRTQUEUE_NUSED(vq)) {
222 uint32_t idx, desc_idx, used_idx;
223 struct vring_used_elem *uep;
225 used_idx = (uint32_t)(vq->vq_used_cons_idx
226 & (vq->vq_nentries - 1));
227 uep = &vq->vq_ring.used->ring[used_idx];
228 idx = (uint32_t) uep->id;
231 while (vq->vq_ring.desc[desc_idx].flags & VRING_DESC_F_NEXT) {
232 desc_idx = vq->vq_ring.desc[desc_idx].next;
236 vq->vq_ring.desc[desc_idx].next = vq->vq_desc_head_idx;
237 vq->vq_desc_head_idx = idx;
239 vq->vq_used_cons_idx++;
243 PMD_INIT_LOG(DEBUG, "vq->vq_free_cnt=%d\nvq->vq_desc_head_idx=%d",
244 vq->vq_free_cnt, vq->vq_desc_head_idx);
246 result = cvq->virtio_net_hdr_mz->addr;
248 rte_spinlock_unlock(&cvq->lock);
249 return result->status;
253 virtio_set_multiple_queues(struct rte_eth_dev *dev, uint16_t nb_queues)
255 struct virtio_hw *hw = dev->data->dev_private;
256 struct virtio_pmd_ctrl ctrl;
260 ctrl.hdr.class = VIRTIO_NET_CTRL_MQ;
261 ctrl.hdr.cmd = VIRTIO_NET_CTRL_MQ_VQ_PAIRS_SET;
262 memcpy(ctrl.data, &nb_queues, sizeof(uint16_t));
264 dlen[0] = sizeof(uint16_t);
266 ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
268 PMD_INIT_LOG(ERR, "Multiqueue configured but send command "
269 "failed, this is too late now...");
277 virtio_dev_queue_release(void *queue __rte_unused)
283 virtio_get_nr_vq(struct virtio_hw *hw)
285 uint16_t nr_vq = hw->max_queue_pairs * 2;
287 if (vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_VQ))
294 virtio_init_vring(struct virtqueue *vq)
296 int size = vq->vq_nentries;
297 struct vring *vr = &vq->vq_ring;
298 uint8_t *ring_mem = vq->vq_ring_virt_mem;
300 PMD_INIT_FUNC_TRACE();
303 * Reinitialise since virtio port might have been stopped and restarted
305 memset(ring_mem, 0, vq->vq_ring_size);
306 vring_init(vr, size, ring_mem, VIRTIO_PCI_VRING_ALIGN);
307 vq->vq_used_cons_idx = 0;
308 vq->vq_desc_head_idx = 0;
309 vq->vq_avail_idx = 0;
310 vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
311 vq->vq_free_cnt = vq->vq_nentries;
312 memset(vq->vq_descx, 0, sizeof(struct vq_desc_extra) * vq->vq_nentries);
314 vring_desc_init(vr->desc, size);
317 * Disable device(host) interrupting guest
319 virtqueue_disable_intr(vq);
323 virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
325 char vq_name[VIRTQUEUE_MAX_NAME_SZ];
326 char vq_hdr_name[VIRTQUEUE_MAX_NAME_SZ];
327 const struct rte_memzone *mz = NULL, *hdr_mz = NULL;
328 unsigned int vq_size, size;
329 struct virtio_hw *hw = dev->data->dev_private;
330 struct virtnet_rx *rxvq = NULL;
331 struct virtnet_tx *txvq = NULL;
332 struct virtnet_ctl *cvq = NULL;
333 struct virtqueue *vq;
334 size_t sz_hdr_mz = 0;
335 void *sw_ring = NULL;
336 int queue_type = virtio_get_queue_type(hw, vtpci_queue_idx);
339 PMD_INIT_LOG(DEBUG, "setting up queue: %u", vtpci_queue_idx);
342 * Read the virtqueue size from the Queue Size field
343 * Always power of 2 and if 0 virtqueue does not exist
345 vq_size = VTPCI_OPS(hw)->get_queue_num(hw, vtpci_queue_idx);
346 PMD_INIT_LOG(DEBUG, "vq_size: %u", vq_size);
348 PMD_INIT_LOG(ERR, "virtqueue does not exist");
352 if (!rte_is_power_of_2(vq_size)) {
353 PMD_INIT_LOG(ERR, "virtqueue size is not powerof 2");
357 snprintf(vq_name, sizeof(vq_name), "port%d_vq%d",
358 dev->data->port_id, vtpci_queue_idx);
360 size = RTE_ALIGN_CEIL(sizeof(*vq) +
361 vq_size * sizeof(struct vq_desc_extra),
362 RTE_CACHE_LINE_SIZE);
363 if (queue_type == VTNET_TQ) {
365 * For each xmit packet, allocate a virtio_net_hdr
366 * and indirect ring elements
368 sz_hdr_mz = vq_size * sizeof(struct virtio_tx_region);
369 } else if (queue_type == VTNET_CQ) {
370 /* Allocate a page for control vq command, data and status */
371 sz_hdr_mz = PAGE_SIZE;
374 vq = rte_zmalloc_socket(vq_name, size, RTE_CACHE_LINE_SIZE,
377 PMD_INIT_LOG(ERR, "can not allocate vq");
380 hw->vqs[vtpci_queue_idx] = vq;
383 vq->vq_queue_index = vtpci_queue_idx;
384 vq->vq_nentries = vq_size;
387 * Reserve a memzone for vring elements
389 size = vring_size(vq_size, VIRTIO_PCI_VRING_ALIGN);
390 vq->vq_ring_size = RTE_ALIGN_CEIL(size, VIRTIO_PCI_VRING_ALIGN);
391 PMD_INIT_LOG(DEBUG, "vring_size: %d, rounded_vring_size: %d",
392 size, vq->vq_ring_size);
394 mz = rte_memzone_reserve_aligned(vq_name, vq->vq_ring_size,
395 SOCKET_ID_ANY, RTE_MEMZONE_IOVA_CONTIG,
396 VIRTIO_PCI_VRING_ALIGN);
398 if (rte_errno == EEXIST)
399 mz = rte_memzone_lookup(vq_name);
406 memset(mz->addr, 0, mz->len);
408 vq->vq_ring_mem = mz->iova;
409 vq->vq_ring_virt_mem = mz->addr;
410 PMD_INIT_LOG(DEBUG, "vq->vq_ring_mem: 0x%" PRIx64,
412 PMD_INIT_LOG(DEBUG, "vq->vq_ring_virt_mem: 0x%" PRIx64,
413 (uint64_t)(uintptr_t)mz->addr);
415 virtio_init_vring(vq);
418 snprintf(vq_hdr_name, sizeof(vq_hdr_name), "port%d_vq%d_hdr",
419 dev->data->port_id, vtpci_queue_idx);
420 hdr_mz = rte_memzone_reserve_aligned(vq_hdr_name, sz_hdr_mz,
421 SOCKET_ID_ANY, RTE_MEMZONE_IOVA_CONTIG,
422 RTE_CACHE_LINE_SIZE);
423 if (hdr_mz == NULL) {
424 if (rte_errno == EEXIST)
425 hdr_mz = rte_memzone_lookup(vq_hdr_name);
426 if (hdr_mz == NULL) {
433 if (queue_type == VTNET_RQ) {
434 size_t sz_sw = (RTE_PMD_VIRTIO_RX_MAX_BURST + vq_size) *
435 sizeof(vq->sw_ring[0]);
437 sw_ring = rte_zmalloc_socket("sw_ring", sz_sw,
438 RTE_CACHE_LINE_SIZE, SOCKET_ID_ANY);
440 PMD_INIT_LOG(ERR, "can not allocate RX soft ring");
445 vq->sw_ring = sw_ring;
448 rxvq->port_id = dev->data->port_id;
450 } else if (queue_type == VTNET_TQ) {
453 txvq->port_id = dev->data->port_id;
455 txvq->virtio_net_hdr_mz = hdr_mz;
456 txvq->virtio_net_hdr_mem = hdr_mz->iova;
457 } else if (queue_type == VTNET_CQ) {
461 cvq->virtio_net_hdr_mz = hdr_mz;
462 cvq->virtio_net_hdr_mem = hdr_mz->iova;
463 memset(cvq->virtio_net_hdr_mz->addr, 0, PAGE_SIZE);
468 /* For virtio_user case (that is when hw->dev is NULL), we use
469 * virtual address. And we need properly set _offset_, please see
470 * VIRTIO_MBUF_DATA_DMA_ADDR in virtqueue.h for more information.
472 if (!hw->virtio_user_dev)
473 vq->offset = offsetof(struct rte_mbuf, buf_iova);
475 vq->vq_ring_mem = (uintptr_t)mz->addr;
476 vq->offset = offsetof(struct rte_mbuf, buf_addr);
477 if (queue_type == VTNET_TQ)
478 txvq->virtio_net_hdr_mem = (uintptr_t)hdr_mz->addr;
479 else if (queue_type == VTNET_CQ)
480 cvq->virtio_net_hdr_mem = (uintptr_t)hdr_mz->addr;
483 if (queue_type == VTNET_TQ) {
484 struct virtio_tx_region *txr;
488 memset(txr, 0, vq_size * sizeof(*txr));
489 for (i = 0; i < vq_size; i++) {
490 struct vring_desc *start_dp = txr[i].tx_indir;
492 vring_desc_init(start_dp, RTE_DIM(txr[i].tx_indir));
494 /* first indirect descriptor is always the tx header */
495 start_dp->addr = txvq->virtio_net_hdr_mem
497 + offsetof(struct virtio_tx_region, tx_hdr);
499 start_dp->len = hw->vtnet_hdr_size;
500 start_dp->flags = VRING_DESC_F_NEXT;
504 if (VTPCI_OPS(hw)->setup_queue(hw, vq) < 0) {
505 PMD_INIT_LOG(ERR, "setup_queue failed");
513 rte_memzone_free(hdr_mz);
514 rte_memzone_free(mz);
521 virtio_free_queues(struct virtio_hw *hw)
523 uint16_t nr_vq = virtio_get_nr_vq(hw);
524 struct virtqueue *vq;
531 for (i = 0; i < nr_vq; i++) {
536 queue_type = virtio_get_queue_type(hw, i);
537 if (queue_type == VTNET_RQ) {
538 rte_free(vq->sw_ring);
539 rte_memzone_free(vq->rxq.mz);
540 } else if (queue_type == VTNET_TQ) {
541 rte_memzone_free(vq->txq.mz);
542 rte_memzone_free(vq->txq.virtio_net_hdr_mz);
544 rte_memzone_free(vq->cq.mz);
545 rte_memzone_free(vq->cq.virtio_net_hdr_mz);
557 virtio_alloc_queues(struct rte_eth_dev *dev)
559 struct virtio_hw *hw = dev->data->dev_private;
560 uint16_t nr_vq = virtio_get_nr_vq(hw);
564 hw->vqs = rte_zmalloc(NULL, sizeof(struct virtqueue *) * nr_vq, 0);
566 PMD_INIT_LOG(ERR, "failed to allocate vqs");
570 for (i = 0; i < nr_vq; i++) {
571 ret = virtio_init_queue(dev, i);
573 virtio_free_queues(hw);
581 static void virtio_queues_unbind_intr(struct rte_eth_dev *dev);
584 virtio_dev_close(struct rte_eth_dev *dev)
586 struct virtio_hw *hw = dev->data->dev_private;
587 struct rte_intr_conf *intr_conf = &dev->data->dev_conf.intr_conf;
589 PMD_INIT_LOG(DEBUG, "virtio_dev_close");
592 if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
593 VTPCI_OPS(hw)->set_config_irq(hw, VIRTIO_MSI_NO_VECTOR);
595 virtio_queues_unbind_intr(dev);
597 if (intr_conf->lsc || intr_conf->rxq) {
598 virtio_intr_disable(dev);
599 rte_intr_efd_disable(dev->intr_handle);
600 rte_free(dev->intr_handle->intr_vec);
601 dev->intr_handle->intr_vec = NULL;
605 virtio_dev_free_mbufs(dev);
606 virtio_free_queues(hw);
610 virtio_dev_promiscuous_enable(struct rte_eth_dev *dev)
612 struct virtio_hw *hw = dev->data->dev_private;
613 struct virtio_pmd_ctrl ctrl;
617 if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
618 PMD_INIT_LOG(INFO, "host does not support rx control");
622 ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
623 ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_PROMISC;
627 ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
629 PMD_INIT_LOG(ERR, "Failed to enable promisc");
633 virtio_dev_promiscuous_disable(struct rte_eth_dev *dev)
635 struct virtio_hw *hw = dev->data->dev_private;
636 struct virtio_pmd_ctrl ctrl;
640 if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
641 PMD_INIT_LOG(INFO, "host does not support rx control");
645 ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
646 ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_PROMISC;
650 ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
652 PMD_INIT_LOG(ERR, "Failed to disable promisc");
656 virtio_dev_allmulticast_enable(struct rte_eth_dev *dev)
658 struct virtio_hw *hw = dev->data->dev_private;
659 struct virtio_pmd_ctrl ctrl;
663 if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
664 PMD_INIT_LOG(INFO, "host does not support rx control");
668 ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
669 ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_ALLMULTI;
673 ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
675 PMD_INIT_LOG(ERR, "Failed to enable allmulticast");
679 virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
681 struct virtio_hw *hw = dev->data->dev_private;
682 struct virtio_pmd_ctrl ctrl;
686 if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_RX)) {
687 PMD_INIT_LOG(INFO, "host does not support rx control");
691 ctrl.hdr.class = VIRTIO_NET_CTRL_RX;
692 ctrl.hdr.cmd = VIRTIO_NET_CTRL_RX_ALLMULTI;
696 ret = virtio_send_command(hw->cvq, &ctrl, dlen, 1);
698 PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
701 #define VLAN_TAG_LEN 4 /* 802.3ac tag (not DMA'd) */
703 virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
705 struct virtio_hw *hw = dev->data->dev_private;
706 uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_LEN +
708 uint32_t frame_size = mtu + ether_hdr_len;
709 uint32_t max_frame_size = hw->max_mtu + ether_hdr_len;
711 max_frame_size = RTE_MIN(max_frame_size, VIRTIO_MAX_RX_PKTLEN);
713 if (mtu < ETHER_MIN_MTU || frame_size > max_frame_size) {
714 PMD_INIT_LOG(ERR, "MTU should be between %d and %d",
715 ETHER_MIN_MTU, max_frame_size - ether_hdr_len);
722 virtio_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
724 struct virtnet_rx *rxvq = dev->data->rx_queues[queue_id];
725 struct virtqueue *vq = rxvq->vq;
727 virtqueue_enable_intr(vq);
732 virtio_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
734 struct virtnet_rx *rxvq = dev->data->rx_queues[queue_id];
735 struct virtqueue *vq = rxvq->vq;
737 virtqueue_disable_intr(vq);
742 * dev_ops for virtio, bare necessities for basic operation
744 static const struct eth_dev_ops virtio_eth_dev_ops = {
745 .dev_configure = virtio_dev_configure,
746 .dev_start = virtio_dev_start,
747 .dev_stop = virtio_dev_stop,
748 .dev_close = virtio_dev_close,
749 .promiscuous_enable = virtio_dev_promiscuous_enable,
750 .promiscuous_disable = virtio_dev_promiscuous_disable,
751 .allmulticast_enable = virtio_dev_allmulticast_enable,
752 .allmulticast_disable = virtio_dev_allmulticast_disable,
753 .mtu_set = virtio_mtu_set,
754 .dev_infos_get = virtio_dev_info_get,
755 .stats_get = virtio_dev_stats_get,
756 .xstats_get = virtio_dev_xstats_get,
757 .xstats_get_names = virtio_dev_xstats_get_names,
758 .stats_reset = virtio_dev_stats_reset,
759 .xstats_reset = virtio_dev_stats_reset,
760 .link_update = virtio_dev_link_update,
761 .vlan_offload_set = virtio_dev_vlan_offload_set,
762 .rx_queue_setup = virtio_dev_rx_queue_setup,
763 .rx_queue_intr_enable = virtio_dev_rx_queue_intr_enable,
764 .rx_queue_intr_disable = virtio_dev_rx_queue_intr_disable,
765 .rx_queue_release = virtio_dev_queue_release,
766 .rx_descriptor_done = virtio_dev_rx_queue_done,
767 .tx_queue_setup = virtio_dev_tx_queue_setup,
768 .tx_queue_release = virtio_dev_queue_release,
769 /* collect stats per queue */
770 .queue_stats_mapping_set = virtio_dev_queue_stats_mapping_set,
771 .vlan_filter_set = virtio_vlan_filter_set,
772 .mac_addr_add = virtio_mac_addr_add,
773 .mac_addr_remove = virtio_mac_addr_remove,
774 .mac_addr_set = virtio_mac_addr_set,
778 virtio_update_stats(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
782 for (i = 0; i < dev->data->nb_tx_queues; i++) {
783 const struct virtnet_tx *txvq = dev->data->tx_queues[i];
787 stats->opackets += txvq->stats.packets;
788 stats->obytes += txvq->stats.bytes;
789 stats->oerrors += txvq->stats.errors;
791 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
792 stats->q_opackets[i] = txvq->stats.packets;
793 stats->q_obytes[i] = txvq->stats.bytes;
797 for (i = 0; i < dev->data->nb_rx_queues; i++) {
798 const struct virtnet_rx *rxvq = dev->data->rx_queues[i];
802 stats->ipackets += rxvq->stats.packets;
803 stats->ibytes += rxvq->stats.bytes;
804 stats->ierrors += rxvq->stats.errors;
806 if (i < RTE_ETHDEV_QUEUE_STAT_CNTRS) {
807 stats->q_ipackets[i] = rxvq->stats.packets;
808 stats->q_ibytes[i] = rxvq->stats.bytes;
812 stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed;
815 static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
816 struct rte_eth_xstat_name *xstats_names,
817 __rte_unused unsigned limit)
823 unsigned nstats = dev->data->nb_tx_queues * VIRTIO_NB_TXQ_XSTATS +
824 dev->data->nb_rx_queues * VIRTIO_NB_RXQ_XSTATS;
826 if (xstats_names != NULL) {
827 /* Note: limit checked in rte_eth_xstats_names() */
829 for (i = 0; i < dev->data->nb_rx_queues; i++) {
830 struct virtnet_rx *rxvq = dev->data->rx_queues[i];
833 for (t = 0; t < VIRTIO_NB_RXQ_XSTATS; t++) {
834 snprintf(xstats_names[count].name,
835 sizeof(xstats_names[count].name),
837 rte_virtio_rxq_stat_strings[t].name);
842 for (i = 0; i < dev->data->nb_tx_queues; i++) {
843 struct virtnet_tx *txvq = dev->data->tx_queues[i];
846 for (t = 0; t < VIRTIO_NB_TXQ_XSTATS; t++) {
847 snprintf(xstats_names[count].name,
848 sizeof(xstats_names[count].name),
850 rte_virtio_txq_stat_strings[t].name);
860 virtio_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
866 unsigned nstats = dev->data->nb_tx_queues * VIRTIO_NB_TXQ_XSTATS +
867 dev->data->nb_rx_queues * VIRTIO_NB_RXQ_XSTATS;
872 for (i = 0; i < dev->data->nb_rx_queues; i++) {
873 struct virtnet_rx *rxvq = dev->data->rx_queues[i];
880 for (t = 0; t < VIRTIO_NB_RXQ_XSTATS; t++) {
881 xstats[count].value = *(uint64_t *)(((char *)rxvq) +
882 rte_virtio_rxq_stat_strings[t].offset);
883 xstats[count].id = count;
888 for (i = 0; i < dev->data->nb_tx_queues; i++) {
889 struct virtnet_tx *txvq = dev->data->tx_queues[i];
896 for (t = 0; t < VIRTIO_NB_TXQ_XSTATS; t++) {
897 xstats[count].value = *(uint64_t *)(((char *)txvq) +
898 rte_virtio_txq_stat_strings[t].offset);
899 xstats[count].id = count;
908 virtio_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
910 virtio_update_stats(dev, stats);
916 virtio_dev_stats_reset(struct rte_eth_dev *dev)
920 for (i = 0; i < dev->data->nb_tx_queues; i++) {
921 struct virtnet_tx *txvq = dev->data->tx_queues[i];
925 txvq->stats.packets = 0;
926 txvq->stats.bytes = 0;
927 txvq->stats.errors = 0;
928 txvq->stats.multicast = 0;
929 txvq->stats.broadcast = 0;
930 memset(txvq->stats.size_bins, 0,
931 sizeof(txvq->stats.size_bins[0]) * 8);
934 for (i = 0; i < dev->data->nb_rx_queues; i++) {
935 struct virtnet_rx *rxvq = dev->data->rx_queues[i];
939 rxvq->stats.packets = 0;
940 rxvq->stats.bytes = 0;
941 rxvq->stats.errors = 0;
942 rxvq->stats.multicast = 0;
943 rxvq->stats.broadcast = 0;
944 memset(rxvq->stats.size_bins, 0,
945 sizeof(rxvq->stats.size_bins[0]) * 8);
950 virtio_set_hwaddr(struct virtio_hw *hw)
952 vtpci_write_dev_config(hw,
953 offsetof(struct virtio_net_config, mac),
954 &hw->mac_addr, ETHER_ADDR_LEN);
958 virtio_get_hwaddr(struct virtio_hw *hw)
960 if (vtpci_with_feature(hw, VIRTIO_NET_F_MAC)) {
961 vtpci_read_dev_config(hw,
962 offsetof(struct virtio_net_config, mac),
963 &hw->mac_addr, ETHER_ADDR_LEN);
965 eth_random_addr(&hw->mac_addr[0]);
966 virtio_set_hwaddr(hw);
971 virtio_mac_table_set(struct virtio_hw *hw,
972 const struct virtio_net_ctrl_mac *uc,
973 const struct virtio_net_ctrl_mac *mc)
975 struct virtio_pmd_ctrl ctrl;
978 if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_MAC_ADDR)) {
979 PMD_DRV_LOG(INFO, "host does not support mac table");
983 ctrl.hdr.class = VIRTIO_NET_CTRL_MAC;
984 ctrl.hdr.cmd = VIRTIO_NET_CTRL_MAC_TABLE_SET;
986 len[0] = uc->entries * ETHER_ADDR_LEN + sizeof(uc->entries);
987 memcpy(ctrl.data, uc, len[0]);
989 len[1] = mc->entries * ETHER_ADDR_LEN + sizeof(mc->entries);
990 memcpy(ctrl.data + len[0], mc, len[1]);
992 err = virtio_send_command(hw->cvq, &ctrl, len, 2);
994 PMD_DRV_LOG(NOTICE, "mac table set failed: %d", err);
999 virtio_mac_addr_add(struct rte_eth_dev *dev, struct ether_addr *mac_addr,
1000 uint32_t index, uint32_t vmdq __rte_unused)
1002 struct virtio_hw *hw = dev->data->dev_private;
1003 const struct ether_addr *addrs = dev->data->mac_addrs;
1005 struct virtio_net_ctrl_mac *uc, *mc;
1007 if (index >= VIRTIO_MAX_MAC_ADDRS) {
1008 PMD_DRV_LOG(ERR, "mac address index %u out of range", index);
1012 uc = alloca(VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN + sizeof(uc->entries));
1014 mc = alloca(VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN + sizeof(mc->entries));
1017 for (i = 0; i < VIRTIO_MAX_MAC_ADDRS; i++) {
1018 const struct ether_addr *addr
1019 = (i == index) ? mac_addr : addrs + i;
1020 struct virtio_net_ctrl_mac *tbl
1021 = is_multicast_ether_addr(addr) ? mc : uc;
1023 memcpy(&tbl->macs[tbl->entries++], addr, ETHER_ADDR_LEN);
1026 return virtio_mac_table_set(hw, uc, mc);
1030 virtio_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
1032 struct virtio_hw *hw = dev->data->dev_private;
1033 struct ether_addr *addrs = dev->data->mac_addrs;
1034 struct virtio_net_ctrl_mac *uc, *mc;
1037 if (index >= VIRTIO_MAX_MAC_ADDRS) {
1038 PMD_DRV_LOG(ERR, "mac address index %u out of range", index);
1042 uc = alloca(VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN + sizeof(uc->entries));
1044 mc = alloca(VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN + sizeof(mc->entries));
1047 for (i = 0; i < VIRTIO_MAX_MAC_ADDRS; i++) {
1048 struct virtio_net_ctrl_mac *tbl;
1050 if (i == index || is_zero_ether_addr(addrs + i))
1053 tbl = is_multicast_ether_addr(addrs + i) ? mc : uc;
1054 memcpy(&tbl->macs[tbl->entries++], addrs + i, ETHER_ADDR_LEN);
1057 virtio_mac_table_set(hw, uc, mc);
1061 virtio_mac_addr_set(struct rte_eth_dev *dev, struct ether_addr *mac_addr)
1063 struct virtio_hw *hw = dev->data->dev_private;
1065 memcpy(hw->mac_addr, mac_addr, ETHER_ADDR_LEN);
1067 /* Use atomic update if available */
1068 if (vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_MAC_ADDR)) {
1069 struct virtio_pmd_ctrl ctrl;
1070 int len = ETHER_ADDR_LEN;
1072 ctrl.hdr.class = VIRTIO_NET_CTRL_MAC;
1073 ctrl.hdr.cmd = VIRTIO_NET_CTRL_MAC_ADDR_SET;
1075 memcpy(ctrl.data, mac_addr, ETHER_ADDR_LEN);
1076 return virtio_send_command(hw->cvq, &ctrl, &len, 1);
1079 if (!vtpci_with_feature(hw, VIRTIO_NET_F_MAC))
1082 virtio_set_hwaddr(hw);
1087 virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
1089 struct virtio_hw *hw = dev->data->dev_private;
1090 struct virtio_pmd_ctrl ctrl;
1093 if (!vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_VLAN))
1096 ctrl.hdr.class = VIRTIO_NET_CTRL_VLAN;
1097 ctrl.hdr.cmd = on ? VIRTIO_NET_CTRL_VLAN_ADD : VIRTIO_NET_CTRL_VLAN_DEL;
1098 memcpy(ctrl.data, &vlan_id, sizeof(vlan_id));
1099 len = sizeof(vlan_id);
1101 return virtio_send_command(hw->cvq, &ctrl, &len, 1);
1105 virtio_intr_enable(struct rte_eth_dev *dev)
1107 struct virtio_hw *hw = dev->data->dev_private;
1109 if (rte_intr_enable(dev->intr_handle) < 0)
1112 if (!hw->virtio_user_dev)
1113 hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
1119 virtio_intr_disable(struct rte_eth_dev *dev)
1121 struct virtio_hw *hw = dev->data->dev_private;
1123 if (rte_intr_disable(dev->intr_handle) < 0)
1126 if (!hw->virtio_user_dev)
1127 hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
1133 virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
1135 uint64_t host_features;
1137 /* Prepare guest_features: feature that driver wants to support */
1138 PMD_INIT_LOG(DEBUG, "guest_features before negotiate = %" PRIx64,
1141 /* Read device(host) feature bits */
1142 host_features = VTPCI_OPS(hw)->get_features(hw);
1143 PMD_INIT_LOG(DEBUG, "host_features before negotiate = %" PRIx64,
1146 /* If supported, ensure MTU value is valid before acknowledging it. */
1147 if (host_features & req_features & (1ULL << VIRTIO_NET_F_MTU)) {
1148 struct virtio_net_config config;
1150 vtpci_read_dev_config(hw,
1151 offsetof(struct virtio_net_config, mtu),
1152 &config.mtu, sizeof(config.mtu));
1154 if (config.mtu < ETHER_MIN_MTU)
1155 req_features &= ~(1ULL << VIRTIO_NET_F_MTU);
1159 * Negotiate features: Subset of device feature bits are written back
1160 * guest feature bits.
1162 hw->guest_features = req_features;
1163 hw->guest_features = vtpci_negotiate_features(hw, host_features);
1164 PMD_INIT_LOG(DEBUG, "features after negotiate = %" PRIx64,
1165 hw->guest_features);
1168 if (!vtpci_with_feature(hw, VIRTIO_F_VERSION_1)) {
1170 "VIRTIO_F_VERSION_1 features is not enabled.");
1173 vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_FEATURES_OK);
1174 if (!(vtpci_get_status(hw) & VIRTIO_CONFIG_STATUS_FEATURES_OK)) {
1176 "failed to set FEATURES_OK status!");
1181 hw->req_guest_features = req_features;
1187 virtio_dev_pause(struct rte_eth_dev *dev)
1189 struct virtio_hw *hw = dev->data->dev_private;
1191 rte_spinlock_lock(&hw->state_lock);
1193 if (hw->started == 0) {
1194 /* Device is just stopped. */
1195 rte_spinlock_unlock(&hw->state_lock);
1200 * Prevent the worker threads from touching queues to avoid contention,
1201 * 1 ms should be enough for the ongoing Tx function to finish.
1208 * Recover hw state to let the worker threads continue.
1211 virtio_dev_resume(struct rte_eth_dev *dev)
1213 struct virtio_hw *hw = dev->data->dev_private;
1216 rte_spinlock_unlock(&hw->state_lock);
1220 * Should be called only after device is paused.
1223 virtio_inject_pkts(struct rte_eth_dev *dev, struct rte_mbuf **tx_pkts,
1226 struct virtio_hw *hw = dev->data->dev_private;
1227 struct virtnet_tx *txvq = dev->data->tx_queues[0];
1230 hw->inject_pkts = tx_pkts;
1231 ret = dev->tx_pkt_burst(txvq, tx_pkts, nb_pkts);
1232 hw->inject_pkts = NULL;
1238 virtio_notify_peers(struct rte_eth_dev *dev)
1240 struct virtio_hw *hw = dev->data->dev_private;
1241 struct virtnet_rx *rxvq;
1242 struct rte_mbuf *rarp_mbuf;
1244 if (!dev->data->rx_queues)
1247 rxvq = dev->data->rx_queues[0];
1248 rarp_mbuf = rte_net_make_rarp_packet(rxvq->mpool,
1249 (struct ether_addr *)hw->mac_addr);
1250 if (rarp_mbuf == NULL) {
1251 PMD_DRV_LOG(ERR, "failed to make RARP packet.");
1255 /* If virtio port just stopped, no need to send RARP */
1256 if (virtio_dev_pause(dev) < 0) {
1257 rte_pktmbuf_free(rarp_mbuf);
1261 virtio_inject_pkts(dev, &rarp_mbuf, 1);
1262 virtio_dev_resume(dev);
1266 virtio_ack_link_announce(struct rte_eth_dev *dev)
1268 struct virtio_hw *hw = dev->data->dev_private;
1269 struct virtio_pmd_ctrl ctrl;
1271 ctrl.hdr.class = VIRTIO_NET_CTRL_ANNOUNCE;
1272 ctrl.hdr.cmd = VIRTIO_NET_CTRL_ANNOUNCE_ACK;
1274 virtio_send_command(hw->cvq, &ctrl, NULL, 0);
1278 * Process virtio config changed interrupt. Call the callback
1279 * if link state changed, generate gratuitous RARP packet if
1280 * the status indicates an ANNOUNCE.
1283 virtio_interrupt_handler(void *param)
1285 struct rte_eth_dev *dev = param;
1286 struct virtio_hw *hw = dev->data->dev_private;
1289 /* Read interrupt status which clears interrupt */
1290 isr = vtpci_isr(hw);
1291 PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
1293 if (virtio_intr_enable(dev) < 0)
1294 PMD_DRV_LOG(ERR, "interrupt enable failed");
1296 if (isr & VIRTIO_PCI_ISR_CONFIG) {
1297 if (virtio_dev_link_update(dev, 0) == 0)
1298 _rte_eth_dev_callback_process(dev,
1299 RTE_ETH_EVENT_INTR_LSC,
1303 if (isr & VIRTIO_NET_S_ANNOUNCE) {
1304 virtio_notify_peers(dev);
1306 virtio_ack_link_announce(dev);
1310 /* set rx and tx handlers according to what is supported */
1312 set_rxtx_funcs(struct rte_eth_dev *eth_dev)
1314 struct virtio_hw *hw = eth_dev->data->dev_private;
1316 if (hw->use_simple_rx) {
1317 PMD_INIT_LOG(INFO, "virtio: using simple Rx path on port %u",
1318 eth_dev->data->port_id);
1319 eth_dev->rx_pkt_burst = virtio_recv_pkts_vec;
1320 } else if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
1322 "virtio: using mergeable buffer Rx path on port %u",
1323 eth_dev->data->port_id);
1324 eth_dev->rx_pkt_burst = &virtio_recv_mergeable_pkts;
1326 PMD_INIT_LOG(INFO, "virtio: using standard Rx path on port %u",
1327 eth_dev->data->port_id);
1328 eth_dev->rx_pkt_burst = &virtio_recv_pkts;
1331 if (hw->use_simple_tx) {
1332 PMD_INIT_LOG(INFO, "virtio: using simple Tx path on port %u",
1333 eth_dev->data->port_id);
1334 eth_dev->tx_pkt_burst = virtio_xmit_pkts_simple;
1336 PMD_INIT_LOG(INFO, "virtio: using standard Tx path on port %u",
1337 eth_dev->data->port_id);
1338 eth_dev->tx_pkt_burst = virtio_xmit_pkts;
1342 /* Only support 1:1 queue/interrupt mapping so far.
1343 * TODO: support n:1 queue/interrupt mapping when there are limited number of
1344 * interrupt vectors (<N+1).
1347 virtio_queues_bind_intr(struct rte_eth_dev *dev)
1350 struct virtio_hw *hw = dev->data->dev_private;
1352 PMD_INIT_LOG(INFO, "queue/interrupt binding");
1353 for (i = 0; i < dev->data->nb_rx_queues; ++i) {
1354 dev->intr_handle->intr_vec[i] = i + 1;
1355 if (VTPCI_OPS(hw)->set_queue_irq(hw, hw->vqs[i * 2], i + 1) ==
1356 VIRTIO_MSI_NO_VECTOR) {
1357 PMD_DRV_LOG(ERR, "failed to set queue vector");
1366 virtio_queues_unbind_intr(struct rte_eth_dev *dev)
1369 struct virtio_hw *hw = dev->data->dev_private;
1371 PMD_INIT_LOG(INFO, "queue/interrupt unbinding");
1372 for (i = 0; i < dev->data->nb_rx_queues; ++i)
1373 VTPCI_OPS(hw)->set_queue_irq(hw,
1374 hw->vqs[i * VTNET_CQ],
1375 VIRTIO_MSI_NO_VECTOR);
1379 virtio_configure_intr(struct rte_eth_dev *dev)
1381 struct virtio_hw *hw = dev->data->dev_private;
1383 if (!rte_intr_cap_multiple(dev->intr_handle)) {
1384 PMD_INIT_LOG(ERR, "Multiple intr vector not supported");
1388 if (rte_intr_efd_enable(dev->intr_handle, dev->data->nb_rx_queues)) {
1389 PMD_INIT_LOG(ERR, "Fail to create eventfd");
1393 if (!dev->intr_handle->intr_vec) {
1394 dev->intr_handle->intr_vec =
1395 rte_zmalloc("intr_vec",
1396 hw->max_queue_pairs * sizeof(int), 0);
1397 if (!dev->intr_handle->intr_vec) {
1398 PMD_INIT_LOG(ERR, "Failed to allocate %u rxq vectors",
1399 hw->max_queue_pairs);
1404 /* Re-register callback to update max_intr */
1405 rte_intr_callback_unregister(dev->intr_handle,
1406 virtio_interrupt_handler,
1408 rte_intr_callback_register(dev->intr_handle,
1409 virtio_interrupt_handler,
1412 /* DO NOT try to remove this! This function will enable msix, or QEMU
1413 * will encounter SIGSEGV when DRIVER_OK is sent.
1414 * And for legacy devices, this should be done before queue/vec binding
1415 * to change the config size from 20 to 24, or VIRTIO_MSI_QUEUE_VECTOR
1416 * (22) will be ignored.
1418 if (virtio_intr_enable(dev) < 0) {
1419 PMD_DRV_LOG(ERR, "interrupt enable failed");
1423 if (virtio_queues_bind_intr(dev) < 0) {
1424 PMD_INIT_LOG(ERR, "Failed to bind queue/interrupt");
1431 /* reset device and renegotiate features if needed */
1433 virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
1435 struct virtio_hw *hw = eth_dev->data->dev_private;
1436 struct virtio_net_config *config;
1437 struct virtio_net_config local_config;
1438 struct rte_pci_device *pci_dev = NULL;
1441 /* Reset the device although not necessary at startup */
1445 virtio_dev_free_mbufs(eth_dev);
1446 virtio_free_queues(hw);
1449 /* Tell the host we've noticed this device. */
1450 vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_ACK);
1452 /* Tell the host we've known how to drive the device. */
1453 vtpci_set_status(hw, VIRTIO_CONFIG_STATUS_DRIVER);
1454 if (virtio_negotiate_features(hw, req_features) < 0)
1457 if (!hw->virtio_user_dev) {
1458 pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
1459 rte_eth_copy_pci_info(eth_dev, pci_dev);
1462 /* If host does not support both status and MSI-X then disable LSC */
1463 if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) &&
1464 hw->use_msix != VIRTIO_MSIX_NONE)
1465 eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
1467 eth_dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
1469 /* Setting up rx_header size for the device */
1470 if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) ||
1471 vtpci_with_feature(hw, VIRTIO_F_VERSION_1))
1472 hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr_mrg_rxbuf);
1474 hw->vtnet_hdr_size = sizeof(struct virtio_net_hdr);
1476 /* Copy the permanent MAC address to: virtio_hw */
1477 virtio_get_hwaddr(hw);
1478 ether_addr_copy((struct ether_addr *) hw->mac_addr,
1479 ð_dev->data->mac_addrs[0]);
1481 "PORT MAC: %02X:%02X:%02X:%02X:%02X:%02X",
1482 hw->mac_addr[0], hw->mac_addr[1], hw->mac_addr[2],
1483 hw->mac_addr[3], hw->mac_addr[4], hw->mac_addr[5]);
1485 if (vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_VQ)) {
1486 config = &local_config;
1488 vtpci_read_dev_config(hw,
1489 offsetof(struct virtio_net_config, mac),
1490 &config->mac, sizeof(config->mac));
1492 if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS)) {
1493 vtpci_read_dev_config(hw,
1494 offsetof(struct virtio_net_config, status),
1495 &config->status, sizeof(config->status));
1498 "VIRTIO_NET_F_STATUS is not supported");
1502 if (vtpci_with_feature(hw, VIRTIO_NET_F_MQ)) {
1503 vtpci_read_dev_config(hw,
1504 offsetof(struct virtio_net_config, max_virtqueue_pairs),
1505 &config->max_virtqueue_pairs,
1506 sizeof(config->max_virtqueue_pairs));
1509 "VIRTIO_NET_F_MQ is not supported");
1510 config->max_virtqueue_pairs = 1;
1513 hw->max_queue_pairs = config->max_virtqueue_pairs;
1515 if (vtpci_with_feature(hw, VIRTIO_NET_F_MTU)) {
1516 vtpci_read_dev_config(hw,
1517 offsetof(struct virtio_net_config, mtu),
1519 sizeof(config->mtu));
1522 * MTU value has already been checked at negotiation
1523 * time, but check again in case it has changed since
1524 * then, which should not happen.
1526 if (config->mtu < ETHER_MIN_MTU) {
1527 PMD_INIT_LOG(ERR, "invalid max MTU value (%u)",
1532 hw->max_mtu = config->mtu;
1533 /* Set initial MTU to maximum one supported by vhost */
1534 eth_dev->data->mtu = config->mtu;
1537 hw->max_mtu = VIRTIO_MAX_RX_PKTLEN - ETHER_HDR_LEN -
1538 VLAN_TAG_LEN - hw->vtnet_hdr_size;
1541 PMD_INIT_LOG(DEBUG, "config->max_virtqueue_pairs=%d",
1542 config->max_virtqueue_pairs);
1543 PMD_INIT_LOG(DEBUG, "config->status=%d", config->status);
1545 "PORT MAC: %02X:%02X:%02X:%02X:%02X:%02X",
1546 config->mac[0], config->mac[1],
1547 config->mac[2], config->mac[3],
1548 config->mac[4], config->mac[5]);
1550 PMD_INIT_LOG(DEBUG, "config->max_virtqueue_pairs=1");
1551 hw->max_queue_pairs = 1;
1552 hw->max_mtu = VIRTIO_MAX_RX_PKTLEN - ETHER_HDR_LEN -
1553 VLAN_TAG_LEN - hw->vtnet_hdr_size;
1556 ret = virtio_alloc_queues(eth_dev);
1560 if (eth_dev->data->dev_conf.intr_conf.rxq) {
1561 if (virtio_configure_intr(eth_dev) < 0) {
1562 PMD_INIT_LOG(ERR, "failed to configure interrupt");
1567 vtpci_reinit_complete(hw);
1570 PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
1571 eth_dev->data->port_id, pci_dev->id.vendor_id,
1572 pci_dev->id.device_id);
1578 * Remap the PCI device again (IO port map for legacy device and
1579 * memory map for modern device), so that the secondary process
1580 * could have the PCI initiated correctly.
1583 virtio_remap_pci(struct rte_pci_device *pci_dev, struct virtio_hw *hw)
1587 * We don't have to re-parse the PCI config space, since
1588 * rte_pci_map_device() makes sure the mapped address
1589 * in secondary process would equal to the one mapped in
1590 * the primary process: error will be returned if that
1591 * requirement is not met.
1593 * That said, we could simply reuse all cap pointers
1594 * (such as dev_cfg, common_cfg, etc.) parsed from the
1595 * primary process, which is stored in shared memory.
1597 if (rte_pci_map_device(pci_dev)) {
1598 PMD_INIT_LOG(DEBUG, "failed to map pci device!");
1602 if (rte_pci_ioport_map(pci_dev, 0, VTPCI_IO(hw)) < 0)
1610 virtio_set_vtpci_ops(struct virtio_hw *hw)
1612 #ifdef RTE_VIRTIO_USER
1613 if (hw->virtio_user_dev)
1614 VTPCI_OPS(hw) = &virtio_user_ops;
1618 VTPCI_OPS(hw) = &modern_ops;
1620 VTPCI_OPS(hw) = &legacy_ops;
1624 * This function is based on probe() function in virtio_pci.c
1625 * It returns 0 on success.
1628 eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
1630 struct virtio_hw *hw = eth_dev->data->dev_private;
1633 RTE_BUILD_BUG_ON(RTE_PKTMBUF_HEADROOM < sizeof(struct virtio_net_hdr_mrg_rxbuf));
1635 eth_dev->dev_ops = &virtio_eth_dev_ops;
1637 if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
1638 if (!hw->virtio_user_dev) {
1639 ret = virtio_remap_pci(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
1644 virtio_set_vtpci_ops(hw);
1645 set_rxtx_funcs(eth_dev);
1650 /* Allocate memory for storing MAC addresses */
1651 eth_dev->data->mac_addrs = rte_zmalloc("virtio", VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN, 0);
1652 if (eth_dev->data->mac_addrs == NULL) {
1654 "Failed to allocate %d bytes needed to store MAC addresses",
1655 VIRTIO_MAX_MAC_ADDRS * ETHER_ADDR_LEN);
1659 hw->port_id = eth_dev->data->port_id;
1660 /* For virtio_user case the hw->virtio_user_dev is populated by
1661 * virtio_user_eth_dev_alloc() before eth_virtio_dev_init() is called.
1663 if (!hw->virtio_user_dev) {
1664 ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
1669 /* reset device and negotiate default features */
1670 ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
1674 /* Setup interrupt callback */
1675 if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
1676 rte_intr_callback_register(eth_dev->intr_handle,
1677 virtio_interrupt_handler, eth_dev);
1682 rte_free(eth_dev->data->mac_addrs);
1687 eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
1689 PMD_INIT_FUNC_TRACE();
1691 if (rte_eal_process_type() == RTE_PROC_SECONDARY)
1694 virtio_dev_stop(eth_dev);
1695 virtio_dev_close(eth_dev);
1697 eth_dev->dev_ops = NULL;
1698 eth_dev->tx_pkt_burst = NULL;
1699 eth_dev->rx_pkt_burst = NULL;
1701 rte_free(eth_dev->data->mac_addrs);
1702 eth_dev->data->mac_addrs = NULL;
1704 /* reset interrupt callback */
1705 if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
1706 rte_intr_callback_unregister(eth_dev->intr_handle,
1707 virtio_interrupt_handler,
1709 if (eth_dev->device)
1710 rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(eth_dev));
1712 PMD_INIT_LOG(DEBUG, "dev_uninit completed");
1717 static int vdpa_check_handler(__rte_unused const char *key,
1718 const char *value, __rte_unused void *opaque)
1720 if (strcmp(value, "1"))
1727 vdpa_mode_selected(struct rte_devargs *devargs)
1729 struct rte_kvargs *kvlist;
1730 const char *key = "vdpa";
1733 if (devargs == NULL)
1736 kvlist = rte_kvargs_parse(devargs->args, NULL);
1740 if (!rte_kvargs_count(kvlist, key))
1743 /* vdpa mode selected when there's a key-value pair: vdpa=1 */
1744 if (rte_kvargs_process(kvlist, key,
1745 vdpa_check_handler, NULL) < 0) {
1751 rte_kvargs_free(kvlist);
1755 static int eth_virtio_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
1756 struct rte_pci_device *pci_dev)
1758 /* virtio pmd skips probe if device needs to work in vdpa mode */
1759 if (vdpa_mode_selected(pci_dev->device.devargs))
1762 return rte_eth_dev_pci_generic_probe(pci_dev, sizeof(struct virtio_hw),
1763 eth_virtio_dev_init);
1766 static int eth_virtio_pci_remove(struct rte_pci_device *pci_dev)
1768 return rte_eth_dev_pci_generic_remove(pci_dev, eth_virtio_dev_uninit);
1771 static struct rte_pci_driver rte_virtio_pmd = {
1773 .name = "net_virtio",
1775 .id_table = pci_id_virtio_map,
1777 .probe = eth_virtio_pci_probe,
1778 .remove = eth_virtio_pci_remove,
1781 RTE_INIT(rte_virtio_pmd_init);
1783 rte_virtio_pmd_init(void)
1785 if (rte_eal_iopl_init() != 0) {
1786 PMD_INIT_LOG(ERR, "IOPL call failed - cannot use virtio PMD");
1790 rte_pci_register(&rte_virtio_pmd);
1794 * Configure virtio device
1795 * It returns 0 on success.
1798 virtio_dev_configure(struct rte_eth_dev *dev)
1800 const struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
1801 struct virtio_hw *hw = dev->data->dev_private;
1802 uint64_t rx_offloads = rxmode->offloads;
1803 uint64_t req_features;
1806 PMD_INIT_LOG(DEBUG, "configure");
1807 req_features = VIRTIO_PMD_DEFAULT_GUEST_FEATURES;
1809 if (dev->data->dev_conf.intr_conf.rxq) {
1810 ret = virtio_init_device(dev, hw->req_guest_features);
1815 if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM |
1816 DEV_RX_OFFLOAD_TCP_CKSUM))
1817 req_features |= (1ULL << VIRTIO_NET_F_GUEST_CSUM);
1819 if (rx_offloads & DEV_RX_OFFLOAD_TCP_LRO)
1821 (1ULL << VIRTIO_NET_F_GUEST_TSO4) |
1822 (1ULL << VIRTIO_NET_F_GUEST_TSO6);
1824 /* if request features changed, reinit the device */
1825 if (req_features != hw->req_guest_features) {
1826 ret = virtio_init_device(dev, req_features);
1831 if ((rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM |
1832 DEV_RX_OFFLOAD_TCP_CKSUM)) &&
1833 !vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_CSUM)) {
1835 "rx checksum not available on this host");
1839 if ((rx_offloads & DEV_RX_OFFLOAD_TCP_LRO) &&
1840 (!vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_TSO4) ||
1841 !vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_TSO6))) {
1843 "Large Receive Offload not available on this host");
1847 /* start control queue */
1848 if (vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_VQ))
1849 virtio_dev_cq_start(dev);
1851 if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
1854 if ((rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
1855 && !vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_VLAN)) {
1857 "vlan filtering not available on this host");
1861 if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
1862 /* Enable vector (0) for Link State Intrerrupt */
1863 if (VTPCI_OPS(hw)->set_config_irq(hw, 0) ==
1864 VIRTIO_MSI_NO_VECTOR) {
1865 PMD_DRV_LOG(ERR, "failed to set config vector");
1869 rte_spinlock_init(&hw->state_lock);
1871 hw->use_simple_rx = 1;
1872 hw->use_simple_tx = 1;
1874 #if defined RTE_ARCH_ARM64 || defined RTE_ARCH_ARM
1875 if (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON)) {
1876 hw->use_simple_rx = 0;
1877 hw->use_simple_tx = 0;
1880 if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF)) {
1881 hw->use_simple_rx = 0;
1882 hw->use_simple_tx = 0;
1885 if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM |
1886 DEV_RX_OFFLOAD_TCP_CKSUM))
1887 hw->use_simple_rx = 0;
1894 virtio_dev_start(struct rte_eth_dev *dev)
1896 uint16_t nb_queues, i;
1897 struct virtnet_rx *rxvq;
1898 struct virtnet_tx *txvq __rte_unused;
1899 struct virtio_hw *hw = dev->data->dev_private;
1902 /* Finish the initialization of the queues */
1903 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1904 ret = virtio_dev_rx_queue_setup_finish(dev, i);
1908 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1909 ret = virtio_dev_tx_queue_setup_finish(dev, i);
1914 /* check if lsc interrupt feature is enabled */
1915 if (dev->data->dev_conf.intr_conf.lsc) {
1916 if (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)) {
1917 PMD_DRV_LOG(ERR, "link status not supported by host");
1922 /* Enable uio/vfio intr/eventfd mapping: althrough we already did that
1923 * in device configure, but it could be unmapped when device is
1926 if (dev->data->dev_conf.intr_conf.lsc ||
1927 dev->data->dev_conf.intr_conf.rxq) {
1928 virtio_intr_disable(dev);
1930 if (virtio_intr_enable(dev) < 0) {
1931 PMD_DRV_LOG(ERR, "interrupt enable failed");
1936 /*Notify the backend
1937 *Otherwise the tap backend might already stop its queue due to fullness.
1938 *vhost backend will have no chance to be waked up
1940 nb_queues = RTE_MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
1941 if (hw->max_queue_pairs > 1) {
1942 if (virtio_set_multiple_queues(dev, nb_queues) != 0)
1946 PMD_INIT_LOG(DEBUG, "nb_queues=%d", nb_queues);
1948 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1949 rxvq = dev->data->rx_queues[i];
1950 /* Flush the old packets */
1951 virtqueue_rxvq_flush(rxvq->vq);
1952 virtqueue_notify(rxvq->vq);
1955 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1956 txvq = dev->data->tx_queues[i];
1957 virtqueue_notify(txvq->vq);
1960 PMD_INIT_LOG(DEBUG, "Notified backend at initialization");
1962 for (i = 0; i < dev->data->nb_rx_queues; i++) {
1963 rxvq = dev->data->rx_queues[i];
1964 VIRTQUEUE_DUMP(rxvq->vq);
1967 for (i = 0; i < dev->data->nb_tx_queues; i++) {
1968 txvq = dev->data->tx_queues[i];
1969 VIRTQUEUE_DUMP(txvq->vq);
1972 set_rxtx_funcs(dev);
1975 /* Initialize Link state */
1976 virtio_dev_link_update(dev, 0);
1981 static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
1983 struct virtio_hw *hw = dev->data->dev_private;
1984 uint16_t nr_vq = virtio_get_nr_vq(hw);
1985 const char *type __rte_unused;
1986 unsigned int i, mbuf_num = 0;
1987 struct virtqueue *vq;
1988 struct rte_mbuf *buf;
1991 if (hw->vqs == NULL)
1994 for (i = 0; i < nr_vq; i++) {
1999 queue_type = virtio_get_queue_type(hw, i);
2000 if (queue_type == VTNET_RQ)
2002 else if (queue_type == VTNET_TQ)
2008 "Before freeing %s[%d] used and unused buf",
2012 while ((buf = virtqueue_detach_unused(vq)) != NULL) {
2013 rte_pktmbuf_free(buf);
2018 "After freeing %s[%d] used and unused buf",
2023 PMD_INIT_LOG(DEBUG, "%d mbufs freed", mbuf_num);
2027 * Stop device: disable interrupt and mark link down
2030 virtio_dev_stop(struct rte_eth_dev *dev)
2032 struct virtio_hw *hw = dev->data->dev_private;
2033 struct rte_eth_link link;
2034 struct rte_intr_conf *intr_conf = &dev->data->dev_conf.intr_conf;
2036 PMD_INIT_LOG(DEBUG, "stop");
2038 rte_spinlock_lock(&hw->state_lock);
2039 if (intr_conf->lsc || intr_conf->rxq)
2040 virtio_intr_disable(dev);
2043 memset(&link, 0, sizeof(link));
2044 rte_eth_linkstatus_set(dev, &link);
2045 rte_spinlock_unlock(&hw->state_lock);
2049 virtio_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complete)
2051 struct rte_eth_link link;
2053 struct virtio_hw *hw = dev->data->dev_private;
2055 memset(&link, 0, sizeof(link));
2056 link.link_duplex = ETH_LINK_FULL_DUPLEX;
2057 link.link_speed = ETH_SPEED_NUM_10G;
2058 link.link_autoneg = ETH_LINK_FIXED;
2060 if (hw->started == 0) {
2061 link.link_status = ETH_LINK_DOWN;
2062 } else if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS)) {
2063 PMD_INIT_LOG(DEBUG, "Get link status from hw");
2064 vtpci_read_dev_config(hw,
2065 offsetof(struct virtio_net_config, status),
2066 &status, sizeof(status));
2067 if ((status & VIRTIO_NET_S_LINK_UP) == 0) {
2068 link.link_status = ETH_LINK_DOWN;
2069 PMD_INIT_LOG(DEBUG, "Port %d is down",
2070 dev->data->port_id);
2072 link.link_status = ETH_LINK_UP;
2073 PMD_INIT_LOG(DEBUG, "Port %d is up",
2074 dev->data->port_id);
2077 link.link_status = ETH_LINK_UP;
2080 return rte_eth_linkstatus_set(dev, &link);
2084 virtio_dev_vlan_offload_set(struct rte_eth_dev *dev, int mask)
2086 const struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
2087 struct virtio_hw *hw = dev->data->dev_private;
2088 uint64_t offloads = rxmode->offloads;
2090 if (mask & ETH_VLAN_FILTER_MASK) {
2091 if ((offloads & DEV_RX_OFFLOAD_VLAN_FILTER) &&
2092 !vtpci_with_feature(hw, VIRTIO_NET_F_CTRL_VLAN)) {
2095 "vlan filtering not available on this host");
2101 if (mask & ETH_VLAN_STRIP_MASK)
2102 hw->vlan_strip = !!(offloads & DEV_RX_OFFLOAD_VLAN_STRIP);
2108 virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
2110 uint64_t tso_mask, host_features;
2111 struct virtio_hw *hw = dev->data->dev_private;
2113 dev_info->speed_capa = ETH_LINK_SPEED_10G; /* fake value */
2115 dev_info->max_rx_queues =
2116 RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES);
2117 dev_info->max_tx_queues =
2118 RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_TX_QUEUES);
2119 dev_info->min_rx_bufsize = VIRTIO_MIN_RX_BUFSIZE;
2120 dev_info->max_rx_pktlen = VIRTIO_MAX_RX_PKTLEN;
2121 dev_info->max_mac_addrs = VIRTIO_MAX_MAC_ADDRS;
2122 dev_info->default_txconf = (struct rte_eth_txconf) {
2123 .txq_flags = ETH_TXQ_FLAGS_NOOFFLOADS
2126 host_features = VTPCI_OPS(hw)->get_features(hw);
2127 dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
2128 if (host_features & (1ULL << VIRTIO_NET_F_GUEST_CSUM)) {
2129 dev_info->rx_offload_capa |=
2130 DEV_RX_OFFLOAD_TCP_CKSUM |
2131 DEV_RX_OFFLOAD_UDP_CKSUM;
2133 if (host_features & (1ULL << VIRTIO_NET_F_CTRL_VLAN))
2134 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_VLAN_FILTER;
2135 tso_mask = (1ULL << VIRTIO_NET_F_GUEST_TSO4) |
2136 (1ULL << VIRTIO_NET_F_GUEST_TSO6);
2137 if ((host_features & tso_mask) == tso_mask)
2138 dev_info->rx_offload_capa |= DEV_RX_OFFLOAD_TCP_LRO;
2140 dev_info->tx_offload_capa = DEV_TX_OFFLOAD_MULTI_SEGS |
2141 DEV_TX_OFFLOAD_VLAN_INSERT;
2142 if (hw->guest_features & (1ULL << VIRTIO_NET_F_CSUM)) {
2143 dev_info->tx_offload_capa |=
2144 DEV_TX_OFFLOAD_UDP_CKSUM |
2145 DEV_TX_OFFLOAD_TCP_CKSUM;
2147 tso_mask = (1ULL << VIRTIO_NET_F_HOST_TSO4) |
2148 (1ULL << VIRTIO_NET_F_HOST_TSO6);
2149 if ((hw->guest_features & tso_mask) == tso_mask)
2150 dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_TCP_TSO;
2154 * It enables testpmd to collect per queue stats.
2157 virtio_dev_queue_stats_mapping_set(__rte_unused struct rte_eth_dev *eth_dev,
2158 __rte_unused uint16_t queue_id, __rte_unused uint8_t stat_idx,
2159 __rte_unused uint8_t is_rx)
2164 RTE_PMD_EXPORT_NAME(net_virtio, __COUNTER__);
2165 RTE_PMD_REGISTER_PCI_TABLE(net_virtio, pci_id_virtio_map);
2166 RTE_PMD_REGISTER_KMOD_DEP(net_virtio, "* igb_uio | uio_pci_generic | vfio-pci");
2168 RTE_INIT(virtio_init_log);
2170 virtio_init_log(void)
2172 virtio_logtype_init = rte_log_register("pmd.net.virtio.init");
2173 if (virtio_logtype_init >= 0)
2174 rte_log_set_level(virtio_logtype_init, RTE_LOG_NOTICE);
2175 virtio_logtype_driver = rte_log_register("pmd.net.virtio.driver");
2176 if (virtio_logtype_driver >= 0)
2177 rte_log_set_level(virtio_logtype_driver, RTE_LOG_NOTICE);