ethdev: remove useless parameter in callback process
[dpdk.git] / drivers / net / virtio / virtio_ethdev.c
index c6756ed..ebb968c 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- *
- *   Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
- *   All rights reserved.
- *
- *   Redistribution and use in source and binary forms, with or without
- *   modification, are permitted provided that the following conditions
- *   are met:
- *
- *     * Redistributions of source code must retain the above copyright
- *       notice, this list of conditions and the following disclaimer.
- *     * Redistributions in binary form must reproduce the above copyright
- *       notice, this list of conditions and the following disclaimer in
- *       the documentation and/or other materials provided with the
- *       distribution.
- *     * Neither the name of Intel Corporation nor the names of its
- *       contributors may be used to endorse or promote products derived
- *       from this software without specific prior written permission.
- *
- *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2016 Intel Corporation
  */
 
 #include <stdint.h>
@@ -97,12 +68,18 @@ static void virtio_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index);
 static void virtio_mac_addr_set(struct rte_eth_dev *dev,
                                struct ether_addr *mac_addr);
 
+static int virtio_intr_enable(struct rte_eth_dev *dev);
+static int virtio_intr_disable(struct rte_eth_dev *dev);
+
 static int virtio_dev_queue_stats_mapping_set(
        struct rte_eth_dev *eth_dev,
        uint16_t queue_id,
        uint8_t stat_idx,
        uint8_t is_rx);
 
+int virtio_logtype_init;
+int virtio_logtype_driver;
+
 /*
  * The set of PCI devices this driver supports
  */
@@ -493,7 +470,7 @@ virtio_init_queue(struct rte_eth_dev *dev, uint16_t vtpci_queue_idx)
         * VIRTIO_MBUF_DATA_DMA_ADDR in virtqueue.h for more information.
         */
        if (!hw->virtio_user_dev)
-               vq->offset = offsetof(struct rte_mbuf, buf_physaddr);
+               vq->offset = offsetof(struct rte_mbuf, buf_iova);
        else {
                vq->vq_ring_mem = (uintptr_t)mz->addr;
                vq->offset = offsetof(struct rte_mbuf, buf_addr);
@@ -618,7 +595,7 @@ virtio_dev_close(struct rte_eth_dev *dev)
                virtio_queues_unbind_intr(dev);
 
        if (intr_conf->lsc || intr_conf->rxq) {
-               rte_intr_disable(dev->intr_handle);
+               virtio_intr_disable(dev);
                rte_intr_efd_disable(dev->intr_handle);
                rte_free(dev->intr_handle->intr_vec);
                dev->intr_handle->intr_vec = NULL;
@@ -890,7 +867,7 @@ static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
                /* Note: limit checked in rte_eth_xstats_names() */
 
                for (i = 0; i < dev->data->nb_rx_queues; i++) {
-                       struct virtqueue *rxvq = dev->data->rx_queues[i];
+                       struct virtnet_rx *rxvq = dev->data->rx_queues[i];
                        if (rxvq == NULL)
                                continue;
                        for (t = 0; t < VIRTIO_NB_RXQ_XSTATS; t++) {
@@ -903,7 +880,7 @@ static int virtio_dev_xstats_get_names(struct rte_eth_dev *dev,
                }
 
                for (i = 0; i < dev->data->nb_tx_queues; i++) {
-                       struct virtqueue *txvq = dev->data->tx_queues[i];
+                       struct virtnet_tx *txvq = dev->data->tx_queues[i];
                        if (txvq == NULL)
                                continue;
                        for (t = 0; t < VIRTIO_NB_TXQ_XSTATS; t++) {
@@ -1159,6 +1136,34 @@ virtio_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int on)
        return virtio_send_command(hw->cvq, &ctrl, &len, 1);
 }
 
+static int
+virtio_intr_enable(struct rte_eth_dev *dev)
+{
+       struct virtio_hw *hw = dev->data->dev_private;
+
+       if (rte_intr_enable(dev->intr_handle) < 0)
+               return -1;
+
+       if (!hw->virtio_user_dev)
+               hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+
+       return 0;
+}
+
+static int
+virtio_intr_disable(struct rte_eth_dev *dev)
+{
+       struct virtio_hw *hw = dev->data->dev_private;
+
+       if (rte_intr_disable(dev->intr_handle) < 0)
+               return -1;
+
+       if (!hw->virtio_user_dev)
+               hw->use_msix = vtpci_msix_detect(RTE_ETH_DEV_TO_PCI(dev));
+
+       return 0;
+}
+
 static int
 virtio_negotiate_features(struct virtio_hw *hw, uint64_t req_features)
 {
@@ -1228,14 +1233,14 @@ virtio_interrupt_handler(void *param)
        isr = vtpci_isr(hw);
        PMD_DRV_LOG(INFO, "interrupt status = %#x", isr);
 
-       if (rte_intr_enable(dev->intr_handle) < 0)
+       if (virtio_intr_enable(dev) < 0)
                PMD_DRV_LOG(ERR, "interrupt enable failed");
 
        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,
-                                                     NULL, NULL);
+                                                     NULL);
        }
 
 }
@@ -1348,7 +1353,7 @@ virtio_configure_intr(struct rte_eth_dev *dev)
         * to change the config size from 20 to 24, or VIRTIO_MSI_QUEUE_VECTOR
         * (22) will be ignored.
         */
-       if (rte_intr_enable(dev->intr_handle) < 0) {
+       if (virtio_intr_enable(dev) < 0) {
                PMD_DRV_LOG(ERR, "interrupt enable failed");
                return -1;
        }
@@ -1388,7 +1393,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
        }
 
        /* If host does not support both status and MSI-X then disable LSC */
-       if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) && hw->use_msix)
+       if (vtpci_with_feature(hw, VIRTIO_NET_F_STATUS) &&
+           hw->use_msix != VIRTIO_MSIX_NONE)
                eth_dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
        else
                eth_dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
@@ -1588,13 +1594,13 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
        if (!hw->virtio_user_dev) {
                ret = vtpci_init(RTE_ETH_DEV_TO_PCI(eth_dev), hw);
                if (ret)
-                       return ret;
+                       goto out;
        }
 
        /* reset device and negotiate default features */
        ret = virtio_init_device(eth_dev, VIRTIO_PMD_DEFAULT_GUEST_FEATURES);
        if (ret < 0)
-               return ret;
+               goto out;
 
        /* Setup interrupt callback  */
        if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
@@ -1602,6 +1608,10 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
                        virtio_interrupt_handler, eth_dev);
 
        return 0;
+
+out:
+       rte_free(eth_dev->data->mac_addrs);
+       return ret;
 }
 
 static int
@@ -1718,7 +1728,7 @@ virtio_dev_configure(struct rte_eth_dev *dev)
 
        if (rxmode->enable_lro &&
                (!vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_TSO4) ||
-                       !vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_TSO4))) {
+                !vtpci_with_feature(hw, VIRTIO_NET_F_GUEST_TSO6))) {
                PMD_DRV_LOG(ERR,
                        "Large Receive Offload not available on this host");
                return -ENOTSUP;
@@ -1801,9 +1811,9 @@ virtio_dev_start(struct rte_eth_dev *dev)
         */
        if (dev->data->dev_conf.intr_conf.lsc ||
            dev->data->dev_conf.intr_conf.rxq) {
-               rte_intr_disable(dev->intr_handle);
+               virtio_intr_disable(dev);
 
-               if (rte_intr_enable(dev->intr_handle) < 0) {
+               if (virtio_intr_enable(dev) < 0) {
                        PMD_DRV_LOG(ERR, "interrupt enable failed");
                        return -EIO;
                }
@@ -1824,7 +1834,7 @@ virtio_dev_start(struct rte_eth_dev *dev)
        for (i = 0; i < dev->data->nb_rx_queues; i++) {
                rxvq = dev->data->rx_queues[i];
                /* Flush the old packets */
-               virtqueue_flush(rxvq->vq);
+               virtqueue_rxvq_flush(rxvq->vq);
                virtqueue_notify(rxvq->vq);
        }
 
@@ -1912,7 +1922,7 @@ virtio_dev_stop(struct rte_eth_dev *dev)
        PMD_INIT_LOG(DEBUG, "stop");
 
        if (intr_conf->lsc || intr_conf->rxq)
-               rte_intr_disable(dev->intr_handle);
+               virtio_intr_disable(dev);
 
        hw->started = 0;
        memset(&link, 0, sizeof(link));
@@ -1929,7 +1939,7 @@ virtio_dev_link_update(struct rte_eth_dev *dev, __rte_unused int wait_to_complet
        virtio_dev_atomic_read_link_status(dev, &link);
        old = link;
        link.link_duplex = ETH_LINK_FULL_DUPLEX;
-       link.link_speed  = SPEED_10G;
+       link.link_speed  = ETH_SPEED_NUM_10G;
 
        if (hw->started == 0) {
                link.link_status = ETH_LINK_DOWN;
@@ -2036,3 +2046,15 @@ __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-pci");
+
+RTE_INIT(virtio_init_log);
+static void
+virtio_init_log(void)
+{
+       virtio_logtype_init = rte_log_register("pmd.virtio.init");
+       if (virtio_logtype_init >= 0)
+               rte_log_set_level(virtio_logtype_init, RTE_LOG_NOTICE);
+       virtio_logtype_driver = rte_log_register("pmd.virtio.driver");
+       if (virtio_logtype_driver >= 0)
+               rte_log_set_level(virtio_logtype_driver, RTE_LOG_NOTICE);
+}