net/virtio: replace full barrier with relaxed ones for Arm
[dpdk.git] / drivers / net / virtio / virtio_ethdev.c
index e492e82..92a3d4e 100644 (file)
@@ -23,6 +23,7 @@
 #include <rte_common.h>
 #include <rte_errno.h>
 #include <rte_cpuflags.h>
+#include <rte_vect.h>
 
 #include <rte_memory.h>
 #include <rte_eal.h>
@@ -40,7 +41,7 @@
 static int eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev);
 static int  virtio_dev_configure(struct rte_eth_dev *dev);
 static int  virtio_dev_start(struct rte_eth_dev *dev);
-static void virtio_dev_stop(struct rte_eth_dev *dev);
+static int  virtio_dev_stop(struct rte_eth_dev *dev);
 static int virtio_dev_promiscuous_enable(struct rte_eth_dev *dev);
 static int virtio_dev_promiscuous_disable(struct rte_eth_dev *dev);
 static int virtio_dev_allmulticast_enable(struct rte_eth_dev *dev);
@@ -202,18 +203,18 @@ virtio_send_command_packed(struct virtnet_ctl *cvq,
                vq->vq_packed.cached_flags ^= VRING_PACKED_DESC_F_AVAIL_USED;
        }
 
-       virtio_wmb(vq->hw->weak_barriers);
-       desc[head].flags = VRING_DESC_F_NEXT | flags;
+       virtqueue_store_flags_packed(&desc[head], VRING_DESC_F_NEXT | flags,
+                       vq->hw->weak_barriers);
 
        virtio_wmb(vq->hw->weak_barriers);
        virtqueue_notify(vq);
 
-       /* wait for used descriptors in virtqueue */
+       /* wait for used desc in virtqueue
+        * desc_is_used has a load-acquire or rte_io_rmb inside
+        */
        while (!desc_is_used(&desc[head], vq))
                usleep(100);
 
-       virtio_rmb(vq->hw->weak_barriers);
-
        /* now get used descriptors */
        vq->vq_free_cnt += nb_descs;
        vq->vq_used_cons_idx += nb_descs;
@@ -1718,6 +1719,8 @@ virtio_init_device(struct rte_eth_dev *eth_dev, uint64_t req_features)
        else
                eth_dev->data->dev_flags &= ~RTE_ETH_DEV_INTR_LSC;
 
+       eth_dev->data->dev_flags |= RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
+
        /* Setting up rx_header size for the device */
        if (vtpci_with_feature(hw, VIRTIO_NET_F_MRG_RXBUF) ||
            vtpci_with_feature(hw, VIRTIO_F_VERSION_1) ||
@@ -1964,12 +1967,12 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
                if (!vtpci_packed_queue(hw)) {
                        hw->use_vec_rx = 1;
                } else {
-#if !defined(CC_AVX512_SUPPORT)
-                       PMD_DRV_LOG(INFO,
-                               "building environment do not support packed ring vectorized");
-#else
+#if defined(CC_AVX512_SUPPORT) || defined(RTE_ARCH_ARM)
                        hw->use_vec_rx = 1;
                        hw->use_vec_tx = 1;
+#else
+                       PMD_DRV_LOG(INFO,
+                               "building environment do not support packed ring vectorized");
 #endif
                }
        }
@@ -1993,17 +1996,18 @@ err_vtpci_init:
 static int
 eth_virtio_dev_uninit(struct rte_eth_dev *eth_dev)
 {
+       int ret;
        PMD_INIT_FUNC_TRACE();
 
        if (rte_eal_process_type() == RTE_PROC_SECONDARY)
                return 0;
 
-       virtio_dev_stop(eth_dev);
+       ret = virtio_dev_stop(eth_dev);
        virtio_dev_close(eth_dev);
 
        PMD_INIT_LOG(DEBUG, "dev_uninit completed");
 
-       return 0;
+       return ret;
 }
 
 
@@ -2309,7 +2313,19 @@ virtio_dev_configure(struct rte_eth_dev *dev)
                if ((hw->use_vec_rx || hw->use_vec_tx) &&
                    (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_AVX512F) ||
                     !vtpci_with_feature(hw, VIRTIO_F_IN_ORDER) ||
-                    !vtpci_with_feature(hw, VIRTIO_F_VERSION_1))) {
+                    !vtpci_with_feature(hw, VIRTIO_F_VERSION_1) ||
+                    rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_512)) {
+                       PMD_DRV_LOG(INFO,
+                               "disabled packed ring vectorized path for requirements not met");
+                       hw->use_vec_rx = 0;
+                       hw->use_vec_tx = 0;
+               }
+#elif defined(RTE_ARCH_ARM)
+               if ((hw->use_vec_rx || hw->use_vec_tx) &&
+                   (!rte_cpu_get_flag_enabled(RTE_CPUFLAG_NEON) ||
+                    !vtpci_with_feature(hw, VIRTIO_F_IN_ORDER) ||
+                    !vtpci_with_feature(hw, VIRTIO_F_VERSION_1) ||
+                    rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128)) {
                        PMD_DRV_LOG(INFO,
                                "disabled packed ring vectorized path for requirements not met");
                        hw->use_vec_rx = 0;
@@ -2362,6 +2378,12 @@ virtio_dev_configure(struct rte_eth_dev *dev)
                                        "disabled split ring vectorized rx for offloading enabled");
                                hw->use_vec_rx = 0;
                        }
+
+                       if (rte_vect_get_max_simd_bitwidth() < RTE_VECT_SIMD_128) {
+                               PMD_DRV_LOG(INFO,
+                                       "disabled split ring vectorized rx, max SIMD bitwidth too low");
+                               hw->use_vec_rx = 0;
+                       }
                }
        }
 
@@ -2511,7 +2533,7 @@ static void virtio_dev_free_mbufs(struct rte_eth_dev *dev)
 /*
  * Stop device: disable interrupt and mark link down
  */
-static void
+static int
 virtio_dev_stop(struct rte_eth_dev *dev)
 {
        struct virtio_hw *hw = dev->data->dev_private;
@@ -2541,6 +2563,8 @@ virtio_dev_stop(struct rte_eth_dev *dev)
        rte_eth_linkstatus_set(dev, &link);
 out_unlock:
        rte_spinlock_unlock(&hw->state_lock);
+
+       return 0;
 }
 
 static int