net/virtio: fix wrong Rx/Tx method for secondary process
[dpdk.git] / drivers / net / virtio / virtio_ethdev.c
index 1d525dd..c3c3826 100644 (file)
@@ -483,11 +483,11 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
                hw->cvq = cvq;
        }
 
-       /* For virtio_user case (that is when dev->pci_dev is NULL), we use
+       /* For virtio_user case (that is when hw->dev is NULL), we use
         * virtual address. And we need properly set _offset_, please see
         * VIRTIO_MBUF_DATA_DMA_ADDR in virtqueue.h for more information.
         */
-       if (dev->pci_dev)
+       if (hw->dev)
                vq->offset = offsetof(struct rte_mbuf, buf_physaddr);
        else {
                vq->vq_ring_mem = (uintptr_t)mz->addr;
@@ -893,6 +893,7 @@ virtio_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
                for (t = 0; t < VIRTIO_NB_RXQ_XSTATS; t++) {
                        xstats[count].value = *(uint64_t *)(((char *)rxvq) +
                                rte_virtio_rxq_stat_strings[t].offset);
+                       xstats[count].id = count;
                        count++;
                }
        }
@@ -908,6 +909,7 @@ virtio_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
                for (t = 0; t < VIRTIO_NB_TXQ_XSTATS; t++) {
                        xstats[count].value = *(uint64_t *)(((char *)txvq) +
                                rte_virtio_txq_stat_strings[t].offset);
+                       xstats[count].id = count;
                        count++;
                }
        }
@@ -1151,7 +1153,7 @@ virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
  * if link state changed.
  */
 static void
-virtio_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
+virtio_interrupt_handler(struct rte_intr_handle *handle,
                         void *param)
 {
        struct rte_eth_dev *dev = param;
@@ -1162,7 +1164,7 @@ virtio_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
        isr = vtpci_isr(hw);
        PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
 
-       if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0)
+       if (rte_intr_enable(handle) < 0)
                PMD_DRV_LOG(ERR, "interrupt enable failed");
 
        if (isr & VIRTIO_PCI_ISR_CONFIG) {
@@ -1190,7 +1192,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
        struct virtio_hw *hw = eth_dev->data->dev_private;
        struct virtio_net_config *config;
        struct virtio_net_config local_config;
-       struct rte_pci_device *pci_dev = eth_dev->pci_dev;
+       struct rte_pci_device *pci_dev = hw->dev;
        int ret;
 
        /* Reset the device although not necessary at startup */
@@ -1210,7 +1212,10 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
        else
                eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
 
-       rte_eth_copy_pci_info(eth_dev, pci_dev);
+       if (pci_dev) {
+               rte_eth_copy_pci_info(eth_dev, pci_dev);
+               eth_dev->data->dev_flags = RTE_ETH_DEV_DETACHABLE;
+       }
 
        rx_func_get(eth_dev);
 
@@ -1294,7 +1299,6 @@ int
 eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 {
        struct virtio_hw *hw = eth_dev->data->dev_private;
-       struct rte_pci_device *pci_dev;
        uint32_t dev_flags = RTE_ETH_DEV_DETACHABLE;
        int ret;
 
@@ -1304,7 +1308,12 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
        eth_dev->tx_pkt_burst = &virtio_xmit_pkts;
 
        if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
-               rx_func_get(eth_dev);
+               if (hw->use_simple_rxtx) {
+                       eth_dev->tx_pkt_burst = virtio_xmit_pkts_simple;
+                       eth_dev->rx_pkt_burst = virtio_recv_pkts_vec;
+               } else {
+                       rx_func_get(eth_dev);
+               }
                return 0;
        }
 
@@ -1317,10 +1326,12 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
                return -ENOMEM;
        }
 
-       pci_dev = eth_dev->pci_dev;
-
-       if (pci_dev) {
-               ret = vtpci_init(pci_dev, hw, &dev_flags);
+       /* For virtio_user case the hw->virtio_user_dev is populated by
+        * virtio_user_eth_dev_alloc() before eth_virtio_dev_init() is called.
+        */
+       if (!hw->virtio_user_dev) {
+               ret = vtpci_init(RTE_DEV_TO_PCI(eth_dev->device), hw,
+                                &dev_flags);
                if (ret)
                        return ret;
        }
@@ -1334,7 +1345,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 
        /* Setup interrupt callback  */
        if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
-               rte_intr_callback_register(&pci_dev->intr_handle,
+               rte_intr_callback_register(vtpci_intr_handle(hw),
                        virtio_interrupt_handler, eth_dev);
 
        return 0;
@@ -1343,7 +1354,7 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
 static int
 eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-       struct rte_pci_device *pci_dev;
+       struct virtio_hw *hw = eth_dev->data->dev_private;
 
        PMD_INIT_FUNC_TRACE();
 
@@ -1352,7 +1363,6 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 
        virtio_dev_stop(eth_dev);
        virtio_dev_close(eth_dev);
-       pci_dev = eth_dev->pci_dev;
 
        eth_dev->dev_ops = NULL;
        eth_dev->tx_pkt_burst = NULL;
@@ -1363,10 +1373,11 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 
        /* reset interrupt callback  */
        if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
-               rte_intr_callback_unregister(&pci_dev->intr_handle,
+               rte_intr_callback_unregister(vtpci_intr_handle(hw),
                                                virtio_interrupt_handler,
                                                eth_dev);
-       rte_eal_pci_unmap_device(pci_dev);
+       if (hw->dev)
+               rte_eal_pci_unmap_device(hw->dev);
 
        PMD_INIT_LOG(DEBUG, "dev_uninit completed");
 
@@ -1379,7 +1390,7 @@ static struct eth_driver rte_virtio_pmd = {
                        .name = "net_virtio",
                },
                .id_table = pci_id_virtio_map,
-               .drv_flags = RTE_PCI_DRV_DETACHABLE,
+               .drv_flags = 0,
                .probe = rte_eth_dev_pci_probe,
                .remove = rte_eth_dev_pci_remove,
        },
@@ -1472,6 +1483,7 @@ virtio_dev_start(struct rte_eth_dev *dev)
        uint16_t nb_queues, i;
        struct virtnet_rx *rxvq;
        struct virtnet_tx *txvq __rte_unused;
+       struct virtio_hw *hw = dev->data->dev_private;
 
        /* check if lsc interrupt feature is enabled */
        if (dev->data->dev_conf.intr_conf.lsc) {
@@ -1480,7 +1492,7 @@ virtio_dev_start(struct rte_eth_dev *dev)
                        return -ENOTSUP;
                }
 
-               if (rte_intr_enable(&dev->pci_dev->intr_handle) < 0) {
+               if (rte_intr_enable(vtpci_intr_handle(hw)) < 0) {
                        PMD_DRV_LOG(ERR, "interrupt enable failed");
                        return -EIO;
                }
@@ -1493,15 +1505,15 @@ virtio_dev_start(struct rte_eth_dev *dev)
         *Otherwise the tap backend might already stop its queue due to fullness.
         *vhost backend will have no chance to be waked up
         */
-       nb_queues = dev->data->nb_rx_queues;
-       if (nb_queues > 1) {
+       nb_queues = RTE_MAX(dev->data->nb_rx_queues, dev->data->nb_tx_queues);
+       if (hw->max_queue_pairs > 1) {
                if (virtio_set_multiple_queues(dev, nb_queues) != 0)
                        return -EINVAL;
        }
 
        PMD_INIT_LOG(DEBUG, "nb_queues=%d", nb_queues);
 
-       for (i = 0; i < nb_queues; i++) {
+       for (i = 0; i < dev->data->nb_rx_queues; i++) {
                rxvq = dev->data->rx_queues[i];
                virtqueue_notify(rxvq->vq);
        }
@@ -1572,12 +1584,13 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
 static void
 virtio_dev_stop(struct rte_eth_dev *dev)
 {
+       struct virtio_hw *hw = dev->data->dev_private;
        struct rte_eth_link link;
 
        PMD_INIT_LOG(DEBUG, "stop");
 
        if (dev->data->dev_conf.intr_conf.lsc)
-               rte_intr_disable(&dev->pci_dev->intr_handle);
+               rte_intr_disable(vtpci_intr_handle(hw));
 
        memset(&link, 0, sizeof(link));
        virtio_dev_atomic_write_link_status(dev, &link);
@@ -1623,10 +1636,7 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        uint64_t tso_mask;
        struct virtio_hw *hw = dev->data->dev_private;
 
-       if (dev->pci_dev)
-               dev_info->driver_name = dev->driver->pci_drv.driver.name;
-       else
-               dev_info->driver_name = "virtio_user PMD";
+       dev_info->pci_dev = hw->dev;
        dev_info->max_rx_queues =
                RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES);
        dev_info->max_tx_queues =
@@ -1668,3 +1678,4 @@ __rte_unused uint8_t is_rx)
 
 RTE_PMD_EXPORT_NAME(net_virtio, __COUNTER__);
 RTE_PMD_REGISTER_PCI_TABLE(net_virtio, pci_id_virtio_map);
+RTE_PMD_REGISTER_KMOD_DEP(net_virtio, "* igb_uio | uio_pci_generic | vfio");