net/virtio: add helper to get interrrupt handle
[dpdk.git] / drivers / net / virtio / virtio_ethdev.c
index 245965c..80b661d 100644 (file)
@@ -308,6 +308,35 @@ virtio_get_nr_vq(struct virtio_hw *hw)
        return nr_vq;
 }
 
+static void
+virtio_init_vring(struct virtqueue *vq)
+{
+       int size = vq->vq_nentries;
+       struct vring *vr = &vq->vq_ring;
+       uint8_t *ring_mem = vq->vq_ring_virt_mem;
+
+       PMD_INIT_FUNC_TRACE();
+
+       /*
+        * Reinitialise since virtio port might have been stopped and restarted
+        */
+       memset(ring_mem, 0, vq->vq_ring_size);
+       vring_init(vr, size, ring_mem, VIRTIO_PCI_VRING_ALIGN);
+       vq->vq_used_cons_idx = 0;
+       vq->vq_desc_head_idx = 0;
+       vq->vq_avail_idx = 0;
+       vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
+       vq->vq_free_cnt = vq->vq_nentries;
+       memset(vq->vq_descx, 0, sizeof(struct vq_desc_extra) * vq->vq_nentries);
+
+       vring_desc_init(vr->desc, size);
+
+       /*
+        * Disable device(host) interrupting guest
+        */
+       virtqueue_disable_intr(vq);
+}
+
 static int
 virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
 {
@@ -371,7 +400,6 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
        vq->hw = hw;
        vq->vq_queue_index = vtpci_queue_idx;
        vq->vq_nentries = vq_size;
-       vq->vq_free_cnt = vq_size;
 
        /*
         * Reserve a memzone for vring elements
@@ -402,6 +430,8 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
        PMD_INIT_LOG(DEBUG, "vq->vq_ring_virt_mem: 0x%" PRIx64,
                     (uint64_t)(uintptr_t)mz->addr);
 
+       virtio_init_vring(vq);
+
        if (sz_hdr_mz) {
                snprintf(vq_hdr_name, sizeof(vq_hdr_name), "port%d_vq%d_hdr",
                         dev->data->port_id, vtpci_queue_idx);
@@ -572,7 +602,6 @@ virtio_dev_close(struct rte_eth_dev *dev)
        if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
                vtpci_irq_config(hw, VIRTIO_MSI_NO_VECTOR);
        vtpci_reset(hw);
-       hw->started = 0;
        virtio_dev_free_mbufs(dev);
        virtio_free_queues(hw);
 }
@@ -1122,7 +1151,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;
@@ -1133,7 +1162,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) {
@@ -1247,6 +1276,7 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
        ret = virtio_alloc_queues(eth_dev);
        if (ret < 0)
                return ret;
+       vtpci_reinit_complete(hw);
 
        if (pci_dev)
                PMD_INIT_LOG(DEBUG, "port %d vendorID=0x%x deviceID=0x%x",
@@ -1304,7 +1334,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;
@@ -1321,10 +1351,8 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
        if (rte_eal_process_type() == RTE_PROC_SECONDARY)
                return -EPERM;
 
-       if (hw->started == 1) {
-               virtio_dev_stop(eth_dev);
-               virtio_dev_close(eth_dev);
-       }
+       virtio_dev_stop(eth_dev);
+       virtio_dev_close(eth_dev);
        pci_dev = eth_dev->pci_dev;
 
        eth_dev->dev_ops = NULL;
@@ -1336,7 +1364,7 @@ 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);
@@ -1443,9 +1471,9 @@ static int
 virtio_dev_start(struct rte_eth_dev *dev)
 {
        uint16_t nb_queues, i;
-       struct virtio_hw *hw = dev->data->dev_private;
        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) {
@@ -1454,7 +1482,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;
                }
@@ -1463,29 +1491,19 @@ virtio_dev_start(struct rte_eth_dev *dev)
        /* Initialize Link state */
        virtio_dev_link_update(dev, 0);
 
-       /* On restart after stop do not touch queues */
-       if (hw->started)
-               return 0;
-
-       /* Do final configuration before rx/tx engine starts */
-       virtio_dev_rxtx_start(dev);
-       vtpci_reinit_complete(hw);
-
-       hw->started = 1;
-
        /*Notify the backend
         *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);
        }
@@ -1556,12 +1574,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);
@@ -1607,10 +1626,6 @@ 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->max_rx_queues =
                RTE_MIN(hw->max_queue_pairs, VIRTIO_MAX_RX_QUEUES);
        dev_info->max_tx_queues =
@@ -1652,3 +1667,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");