net/virtio: simplify queue allocation
[dpdk.git] / drivers / net / virtio / virtio_ethdev.c
index 157e44c..5a2c14b 100644 (file)
@@ -312,8 +312,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
        struct virtnet_tx *txvq = NULL;
        struct virtnet_ctl *cvq = NULL;
        struct virtqueue *vq;
-       const char *queue_names[] = {"rvq", "txq", "cvq"};
-       size_t sz_vq, sz_q = 0, sz_hdr_mz = 0;
+       size_t sz_hdr_mz = 0;
        void *sw_ring = NULL;
        int ret;
 
@@ -335,28 +334,24 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
                return -EINVAL;
        }
 
-       snprintf(vq_name, sizeof(vq_name), "port%d_%s%d",
-                dev->data->port_id, queue_names[queue_type], queue_idx);
+       snprintf(vq_name, sizeof(vq_name), "port%d_vq%d",
+                dev->data->port_id, vtpci_queue_idx);
 
-       sz_vq = RTE_ALIGN_CEIL(sizeof(*vq) +
+       size = RTE_ALIGN_CEIL(sizeof(*vq) +
                                vq_size * sizeof(struct vq_desc_extra),
                                RTE_CACHE_LINE_SIZE);
-       if (queue_type == VTNET_RQ) {
-               sz_q = sz_vq + sizeof(*rxvq);
-       } else if (queue_type == VTNET_TQ) {
-               sz_q = sz_vq + sizeof(*txvq);
+       if (queue_type == VTNET_TQ) {
                /*
                 * For each xmit packet, allocate a virtio_net_hdr
                 * and indirect ring elements
                 */
                sz_hdr_mz = vq_size * sizeof(struct virtio_tx_region);
        } else if (queue_type == VTNET_CQ) {
-               sz_q = sz_vq + sizeof(*cvq);
                /* Allocate a page for control vq command, data and status */
                sz_hdr_mz = PAGE_SIZE;
        }
 
-       vq = rte_zmalloc_socket(vq_name, sz_q, RTE_CACHE_LINE_SIZE, socket_id);
+       vq = rte_zmalloc_socket(vq_name, size, RTE_CACHE_LINE_SIZE, socket_id);
        if (vq == NULL) {
                PMD_INIT_LOG(ERR, "can not allocate vq");
                return -ENOMEM;
@@ -398,9 +393,8 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
                     (uint64_t)(uintptr_t)mz->addr);
 
        if (sz_hdr_mz) {
-               snprintf(vq_hdr_name, sizeof(vq_hdr_name), "port%d_%s%d_hdr",
-                        dev->data->port_id, queue_names[queue_type],
-                        queue_idx);
+               snprintf(vq_hdr_name, sizeof(vq_hdr_name), "port%d_vq%d_hdr",
+                        dev->data->port_id, vtpci_queue_idx);
                hdr_mz = rte_memzone_reserve_aligned(vq_hdr_name, sz_hdr_mz,
                                                     socket_id, 0,
                                                     RTE_CACHE_LINE_SIZE);
@@ -427,14 +421,14 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
                }
 
                vq->sw_ring = sw_ring;
-               rxvq = (struct virtnet_rx *)RTE_PTR_ADD(vq, sz_vq);
+               rxvq = &vq->rxq;
                rxvq->vq = vq;
                rxvq->port_id = dev->data->port_id;
                rxvq->queue_id = queue_idx;
                rxvq->mz = mz;
                *pvq = rxvq;
        } else if (queue_type == VTNET_TQ) {
-               txvq = (struct virtnet_tx *)RTE_PTR_ADD(vq, sz_vq);
+               txvq = &vq->txq;
                txvq->vq = vq;
                txvq->port_id = dev->data->port_id;
                txvq->queue_id = queue_idx;
@@ -444,7 +438,7 @@ int virtio_dev_queue_setup(struct rte_eth_dev *dev,
 
                *pvq = txvq;
        } else if (queue_type == VTNET_CQ) {
-               cvq = (struct virtnet_ctl *)RTE_PTR_ADD(vq, sz_vq);
+               cvq = &vq->cq;
                cvq->vq = vq;
                cvq->mz = mz;
                cvq->virtio_net_hdr_mz = hdr_mz;
@@ -550,9 +544,6 @@ virtio_dev_close(struct rte_eth_dev *dev)
 
        PMD_INIT_LOG(DEBUG, "virtio_dev_close");
 
-       if (hw->started == 1)
-               virtio_dev_stop(dev);
-
        if (hw->cvq)
                virtio_dev_queue_release(hw->cvq->vq);
 
@@ -560,6 +551,7 @@ 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(dev);
 }
@@ -1126,7 +1118,7 @@ virtio_interrupt_handler(__rte_unused struct rte_intr_handle *handle,
        if (isr & VIRTIO_PCI_ISR_CONFIG) {
                if (virtio_dev_link_update(dev, 0) == 0)
                        _rte_eth_dev_callback_process(dev,
-                                                     RTE_ETH_EVENT_INTR_LSC);
+                                                     RTE_ETH_EVENT_INTR_LSC, NULL);
        }
 
 }
@@ -1296,15 +1288,17 @@ 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();
 
        if (rte_eal_process_type() == RTE_PROC_SECONDARY)
                return -EPERM;
 
-       /* Close it anyway since there's no way to know if closed */
-       virtio_dev_close(eth_dev);
-
+       if (hw->started == 1) {
+               virtio_dev_stop(eth_dev);
+               virtio_dev_close(eth_dev);
+       }
        pci_dev = eth_dev->pci_dev;
 
        eth_dev->dev_ops = NULL;
@@ -1543,12 +1537,9 @@ static void
 virtio_dev_stop(struct rte_eth_dev *dev)
 {
        struct rte_eth_link link;
-       struct virtio_hw *hw = dev->data->dev_private;
 
        PMD_INIT_LOG(DEBUG, "stop");
 
-       hw->started = 0;
-
        if (dev->data->dev_conf.intr_conf.lsc)
                rte_intr_disable(&dev->pci_dev->intr_handle);
 
@@ -1593,6 +1584,7 @@ virtio_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complet
 static void
 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)
@@ -1620,6 +1612,11 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
                        DEV_TX_OFFLOAD_UDP_CKSUM |
                        DEV_TX_OFFLOAD_TCP_CKSUM;
        }
+
+       tso_mask = (1ULL << VIRTIO_NET_F_HOST_TSO4) |
+               (1ULL << VIRTIO_NET_F_HOST_TSO6);
+       if ((hw->guest_features & tso_mask) == tso_mask)
+               dev_info->tx_offload_capa |= DEV_TX_OFFLOAD_TCP_TSO;
 }
 
 /*
@@ -1633,5 +1630,5 @@ __rte_unused uint8_t is_rx)
        return 0;
 }
 
-DRIVER_EXPORT_NAME(net_virtio, __COUNTER__);
-DRIVER_REGISTER_PCI_TABLE(net_virtio, pci_id_virtio_map);
+RTE_PMD_EXPORT_NAME(net_virtio, __COUNTER__);
+RTE_PMD_REGISTER_PCI_TABLE(net_virtio, pci_id_virtio_map);