net/virtio: support modern device id
[dpdk.git] / drivers / net / virtio / virtio_ethdev.c
index 12fa640..2232dfe 100644 (file)
@@ -103,11 +103,9 @@ static int virtio_dev_queue_stats_mapping_set(
  * The set of PCI devices this driver supports
  */
 static const struct rte_pci_id pci_id_virtio_map[] = {
-
-#define RTE_PCI_DEV_ID_DECL_VIRTIO(vend, dev) {RTE_PCI_DEVICE(vend, dev)},
-#include "rte_pci_dev_ids.h"
-
-{ .vendor_id = 0, /* sentinel */ },
+       { RTE_PCI_DEVICE(VIRTIO_PCI_VENDORID, VIRTIO_PCI_LEGACY_DEVICEID_NET) },
+       { RTE_PCI_DEVICE(VIRTIO_PCI_VENDORID, VIRTIO_PCI_MODERN_DEVICEID_NET) },
+       { .vendor_id = 0, /* sentinel */ },
 };
 
 struct rte_virtio_xstats_name_off {
@@ -128,8 +126,8 @@ static const struct rte_virtio_xstats_name_off rte_virtio_rxq_stat_strings[] = {
        {"size_128_255_packets",   offsetof(struct virtnet_rx, stats.size_bins[3])},
        {"size_256_511_packets",   offsetof(struct virtnet_rx, stats.size_bins[4])},
        {"size_512_1023_packets",  offsetof(struct virtnet_rx, stats.size_bins[5])},
-       {"size_1024_1517_packets", offsetof(struct virtnet_rx, stats.size_bins[6])},
-       {"size_1518_max_packets",  offsetof(struct virtnet_rx, stats.size_bins[7])},
+       {"size_1024_1518_packets", offsetof(struct virtnet_rx, stats.size_bins[6])},
+       {"size_1519_max_packets",  offsetof(struct virtnet_rx, stats.size_bins[7])},
 };
 
 /* [rt]x_qX_ is prepended to the name string here */
@@ -145,8 +143,8 @@ static const struct rte_virtio_xstats_name_off rte_virtio_txq_stat_strings[] = {
        {"size_128_255_packets",   offsetof(struct virtnet_tx, stats.size_bins[3])},
        {"size_256_511_packets",   offsetof(struct virtnet_tx, stats.size_bins[4])},
        {"size_512_1023_packets",  offsetof(struct virtnet_tx, stats.size_bins[5])},
-       {"size_1024_1517_packets", offsetof(struct virtnet_tx, stats.size_bins[6])},
-       {"size_1518_max_packets",  offsetof(struct virtnet_tx, stats.size_bins[7])},
+       {"size_1024_1518_packets", offsetof(struct virtnet_tx, stats.size_bins[6])},
+       {"size_1519_max_packets",  offsetof(struct virtnet_tx, stats.size_bins[7])},
 };
 
 #define VIRTIO_NB_RXQ_XSTATS (sizeof(rte_virtio_rxq_stat_strings) / \
@@ -166,7 +164,7 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
 
        ctrl->status = status;
 
-       if (!cvq && !cvq->vq) {
+       if (!cvq || !cvq->vq) {
                PMD_INIT_LOG(ERR, "Control queue is not supported.");
                return -1;
        }
@@ -222,12 +220,12 @@ virtio_send_command(struct virtnet_ctl *cvq, struct virtio_pmd_ctrl *ctrl,
        virtqueue_notify(vq);
 
        rte_rmb();
-       while (vq->vq_used_cons_idx == vq->vq_ring.used->idx) {
+       while (VIRTQUEUE_NUSED(vq) == 0) {
                rte_rmb();
                usleep(100);
        }
 
-       while (vq->vq_used_cons_idx != vq->vq_ring.used->idx) {
+       while (VIRTQUEUE_NUSED(vq)) {
                uint32_t idx, desc_idx, used_idx;
                struct vring_used_elem *uep;
 
@@ -455,9 +453,9 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
                *pvq = cvq;
        }
 
-       /* For virtio-user case (that is when dev->pci_dev is NULL), we use
+       /* For virtio_user case (that is when dev->pci_dev is NULL), we use
         * virtual address. And we need properly set _offset_, please see
-        * MBUF_DATA_DMA_ADDR in virtqueue.h for more information.
+        * VIRTIO_MBUF_DATA_DMA_ADDR in virtqueue.h for more information.
         */
        if (dev->pci_dev)
                vq->offset = offsetof(struct rte_mbuf, buf_physaddr);
@@ -655,6 +653,23 @@ virtio_dev_allmulticast_disable(struct rte_eth_dev *dev)
                PMD_INIT_LOG(ERR, "Failed to disable allmulticast");
 }
 
+#define VLAN_TAG_LEN           4    /* 802.3ac tag (not DMA'd) */
+static int
+virtio_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+{
+       struct virtio_hw *hw = dev->data->dev_private;
+       uint32_t ether_hdr_len = ETHER_HDR_LEN + VLAN_TAG_LEN +
+                                hw->vtnet_hdr_size;
+       uint32_t frame_size = mtu + ether_hdr_len;
+
+       if (mtu < ETHER_MIN_MTU || frame_size > VIRTIO_MAX_RX_PKTLEN) {
+               PMD_INIT_LOG(ERR, "MTU should be between %d and %d\n",
+                       ETHER_MIN_MTU, VIRTIO_MAX_RX_PKTLEN - ether_hdr_len);
+               return -EINVAL;
+       }
+       return 0;
+}
+
 /*
  * dev_ops for virtio, bare necessities for basic operation
  */
@@ -667,7 +682,7 @@ static const struct eth_dev_ops virtio_eth_dev_ops = {
        .promiscuous_disable     = virtio_dev_promiscuous_disable,
        .allmulticast_enable     = virtio_dev_allmulticast_enable,
        .allmulticast_disable    = virtio_dev_allmulticast_disable,
-
+       .mtu_set                 = virtio_mtu_set,
        .dev_infos_get           = virtio_dev_info_get,
        .stats_get               = virtio_dev_stats_get,
        .xstats_get              = virtio_dev_xstats_get,
@@ -788,7 +803,6 @@ static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
                                        sizeof(xstats_names[count].name),
                                        "rx_q%u_%s", i,
                                        rte_virtio_rxq_stat_strings[t].name);
-                               xstats_names[count].id = count;
                                count++;
                        }
                }
@@ -802,7 +816,6 @@ static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
                                        sizeof(xstats_names[count].name),
                                        "tx_q%u_%s", i,
                                        rte_virtio_txq_stat_strings[t].name);
-                               xstats_names[count].id = count;
                                count++;
                        }
                }
@@ -833,7 +846,6 @@ virtio_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
                unsigned t;
 
                for (t = 0; t < VIRTIO_NB_RXQ_XSTATS; t++) {
-                       xstats[count].id = count;
                        xstats[count].value = *(uint64_t *)(((char *)rxvq) +
                                rte_virtio_rxq_stat_strings[t].offset);
                        count++;
@@ -849,7 +861,6 @@ virtio_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
                unsigned t;
 
                for (t = 0; t < VIRTIO_NB_TXQ_XSTATS; t++) {
-                       xstats[count].id = count;
                        xstats[count].value = *(uint64_t *)(((char *)txvq) +
                                rte_virtio_txq_stat_strings[t].offset);
                        count++;
@@ -1311,32 +1322,29 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 
 static struct eth_driver rte_virtio_pmd = {
        .pci_drv = {
-               .name = "rte_virtio_pmd",
+               .driver = {
+                       .name = "net_virtio",
+               },
                .id_table = pci_id_virtio_map,
                .drv_flags = RTE_PCI_DRV_DETACHABLE,
+               .probe = rte_eth_dev_pci_probe,
+               .remove = rte_eth_dev_pci_remove,
        },
        .eth_dev_init = eth_virtio_dev_init,
        .eth_dev_uninit = eth_virtio_dev_uninit,
        .dev_private_size = sizeof(struct virtio_hw),
 };
 
-/*
- * Driver initialization routine.
- * Invoked once at EAL init time.
- * Register itself as the [Poll Mode] Driver of PCI virtio devices.
- * Returns 0 on success.
- */
-static int
-rte_virtio_pmd_init(const char *name __rte_unused,
-                   const char *param __rte_unused)
+RTE_INIT(rte_virtio_pmd_init);
+static void
+rte_virtio_pmd_init(void)
 {
        if (rte_eal_iopl_init() != 0) {
                PMD_INIT_LOG(ERR, "IOPL call failed - cannot use virtio PMD");
-               return -1;
+               return;
        }
 
-       rte_eth_driver_register(&rte_virtio_pmd);
-       return 0;
+       rte_eal_pci_register(&rte_virtio_pmd.pci_drv);
 }
 
 /*
@@ -1546,9 +1554,9 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        struct virtio_hw *hw = dev->data->dev_private;
 
        if (dev->pci_dev)
-               dev_info->driver_name = dev->driver->pci_drv.name;
+               dev_info->driver_name = dev->driver->pci_drv.driver.name;
        else
-               dev_info->driver_name = "virtio-user PMD";
+               dev_info->driver_name = "virtio_user PMD";
        dev_info->max_rx_queues = (uint16_t)hw->max_rx_queues;
        dev_info->max_tx_queues = (uint16_t)hw->max_tx_queues;
        dev_info->min_rx_bufsize = VIRTIO_MIN_RX_BUFSIZE;
@@ -1570,9 +1578,5 @@ __rte_unused uint8_t is_rx)
        return 0;
 }
 
-static struct rte_driver rte_virtio_driver = {
-       .type = PMD_PDEV,
-       .init = rte_virtio_pmd_init,
-};
-
-PMD_REGISTER_DRIVER(rte_virtio_driver);
+DRIVER_EXPORT_NAME(net_virtio, __COUNTER__);
+DRIVER_REGISTER_PCI_TABLE(net_virtio, pci_id_virtio_map);