net/virtio: register/unregister intr handler on start/stop
[dpdk.git] / drivers / net / virtio / virtio_ethdev.c
index 1d223d0..da87177 100644 (file)
@@ -1679,11 +1679,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
        if (ret < 0)
                goto out;
 
-       /* Setup interrupt callback  */
-       if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
-               rte_intr_callback_register(eth_dev->intr_handle,
-                       virtio_interrupt_handler, eth_dev);
-
        return 0;
 
 out:
@@ -1697,7 +1692,7 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
        PMD_INIT_FUNC_TRACE();
 
        if (rte_eal_process_type() == RTE_PROC_SECONDARY)
-               return -EPERM;
+               return 0;
 
        virtio_dev_stop(eth_dev);
        virtio_dev_close(eth_dev);
@@ -1706,14 +1701,6 @@ eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
        eth_dev->tx_pkt_burst = NULL;
        eth_dev->rx_pkt_burst = NULL;
 
-       rte_free(eth_dev->data->mac_addrs);
-       eth_dev->data->mac_addrs = NULL;
-
-       /* reset interrupt callback  */
-       if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
-               rte_intr_callback_unregister(eth_dev->intr_handle,
-                                               virtio_interrupt_handler,
-                                               eth_dev);
        if (eth_dev->device)
                rte_pci_unmap_device(RTE_ETH_DEV_TO_PCI(eth_dev));
 
@@ -1786,9 +1773,7 @@ static struct rte_pci_driver rte_virtio_pmd = {
        .remove = eth_virtio_pci_remove,
 };
 
-RTE_INIT(rte_virtio_pmd_init);
-static void
-rte_virtio_pmd_init(void)
+RTE_INIT(rte_virtio_pmd_init)
 {
        if (rte_eal_iopl_init() != 0) {
                PMD_INIT_LOG(ERR, "IOPL call failed - cannot use virtio PMD");
@@ -1798,6 +1783,22 @@ rte_virtio_pmd_init(void)
        rte_pci_register(&rte_virtio_pmd);
 }
 
+static bool
+rx_offload_enabled(struct virtio_hw *hw)
+{
+       return vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_CSUM) ||
+               vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_TSO4) ||
+               vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_TSO6);
+}
+
+static bool
+tx_offload_enabled(struct virtio_hw *hw)
+{
+       return vtpci_with_feature(hw, VIRTIO_NET_F_CSUM) ||
+               vtpci_with_feature(hw, VIRTIO_NET_F_HOST_TSO4) ||
+               vtpci_with_feature(hw, VIRTIO_NET_F_HOST_TSO6);
+}
+
 /*
  * Configure virtio device
  * It returns 0 on success.
@@ -1877,6 +1878,9 @@ virtio_dev_configure(struct rte_eth_dev *dev)
                return -ENOTSUP;
        }
 
+       hw->has_tx_offload = tx_offload_enabled(hw);
+       hw->has_rx_offload = rx_offload_enabled(hw);
+
        if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
                /* Enable vector (0) for Link State Intrerrupt */
                if (VTPCI_OPS(hw)->set_config_irq(hw, 0) ==
@@ -1909,7 +1913,9 @@ virtio_dev_configure(struct rte_eth_dev *dev)
        }
 
        if (rx_offloads & (DEV_RX_OFFLOAD_UDP_CKSUM |
-                          DEV_RX_OFFLOAD_TCP_CKSUM))
+                          DEV_RX_OFFLOAD_TCP_CKSUM |
+                          DEV_RX_OFFLOAD_TCP_LRO |
+                          DEV_RX_OFFLOAD_VLAN_STRIP))
                hw->use_simple_rx = 0;
 
        return 0;
@@ -1953,6 +1959,12 @@ virtio_dev_start(struct rte_eth_dev *dev)
            dev->data->dev_conf.intr_conf.rxq) {
                virtio_intr_disable(dev);
 
+               /* Setup interrupt callback  */
+               if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
+                       rte_intr_callback_register(dev->intr_handle,
+                                                  virtio_interrupt_handler,
+                                                  dev);
+
                if (virtio_intr_enable(dev) < 0) {
                        PMD_DRV_LOG(ERR, "interrupt enable failed");
                        return -EIO;
@@ -2062,9 +2074,17 @@ virtio_dev_stop(struct rte_eth_dev *dev)
        PMD_INIT_LOG(DEBUG, "stop");
 
        rte_spinlock_lock(&hw->state_lock);
-       if (intr_conf->lsc || intr_conf->rxq)
+       if (intr_conf->lsc || intr_conf->rxq) {
                virtio_intr_disable(dev);
 
+               /* Reset interrupt callback  */
+               if (dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC) {
+                       rte_intr_callback_unregister(dev->intr_handle,
+                                                    virtio_interrupt_handler,
+                                                    dev);
+               }
+       }
+
        hw->started = 0;
        memset(&link, 0, sizeof(link));
        rte_eth_linkstatus_set(dev, &link);
@@ -2145,13 +2165,9 @@ virtio_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
        dev_info->min_rx_bufsize = VIRTIO_MIN_RX_BUFSIZE;
        dev_info->max_rx_pktlen = VIRTIO_MAX_RX_PKTLEN;
        dev_info->max_mac_addrs = VIRTIO_MAX_MAC_ADDRS;
-       dev_info->default_txconf = (struct rte_eth_txconf) {
-               .txq_flags = ETH_TXQ_FLAGS_NOOFFLOADS
-       };
 
        host_features = VTPCI_OPS(hw)->get_features(hw);
-       dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP |
-                                   DEV_RX_OFFLOAD_CRC_STRIP;
+       dev_info->rx_offload_capa = DEV_RX_OFFLOAD_VLAN_STRIP;
        if (host_features & (1ULL << VIRTIO_NET_F_GUEST_CSUM)) {
                dev_info->rx_offload_capa |=
                        DEV_RX_OFFLOAD_TCP_CKSUM |
@@ -2192,9 +2208,7 @@ 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-pci");
 
-RTE_INIT(virtio_init_log);
-static void
-virtio_init_log(void)
+RTE_INIT(virtio_init_log)
 {
        virtio_logtype_init = rte_log_register("pmd.net.virtio.init");
        if (virtio_logtype_init >= 0)