ethdev: make stats and xstats reset callbacks return int
[dpdk.git] / drivers / net / enic / enic_main.c
index ea6cddb..e507df1 100644 (file)
@@ -8,7 +8,6 @@
 #include <sys/stat.h>
 #include <sys/mman.h>
 #include <fcntl.h>
-#include <libgen.h>
 
 #include <rte_pci.h>
 #include <rte_bus_pci.h>
@@ -116,11 +115,18 @@ static void enic_init_soft_stats(struct enic *enic)
        enic_clear_soft_stats(enic);
 }
 
-void enic_dev_stats_clear(struct enic *enic)
+int enic_dev_stats_clear(struct enic *enic)
 {
-       if (vnic_dev_stats_clear(enic->vdev))
+       int ret;
+
+       ret = vnic_dev_stats_clear(enic->vdev);
+       if (ret != 0) {
                dev_err(enic, "Error in clearing stats\n");
+               return ret;
+       }
        enic_clear_soft_stats(enic);
+
+       return 0;
 }
 
 int enic_dev_stats_get(struct enic *enic, struct rte_eth_stats *r_stats)
@@ -514,17 +520,34 @@ static void enic_prep_wq_for_simple_tx(struct enic *enic, uint16_t queue_idx)
        }
 }
 
+/*
+ * The 'strong' version is in enic_rxtx_vec_avx2.c. This weak version is used
+ * used when that file is not compiled.
+ */
+__rte_weak bool
+enic_use_vector_rx_handler(__rte_unused struct enic *enic)
+{
+       return false;
+}
+
 static void pick_rx_handler(struct enic *enic)
 {
        struct rte_eth_dev *eth_dev;
 
-       /* Use the non-scatter, simplified RX handler if possible. */
+       /*
+        * Preference order:
+        * 1. The vectorized handler if possible and requested.
+        * 2. The non-scatter, simplified handler if scatter Rx is not used.
+        * 3. The default handler as a fallback.
+        */
        eth_dev = enic->rte_dev;
+       if (enic_use_vector_rx_handler(enic))
+               return;
        if (enic->rq_count > 0 && enic->rq[0].data_queue_enable == 0) {
-               PMD_INIT_LOG(DEBUG, " use the non-scatter Rx handler");
+               ENICPMD_LOG(DEBUG, " use the non-scatter Rx handler");
                eth_dev->rx_pkt_burst = &enic_noscatter_recv_pkts;
        } else {
-               PMD_INIT_LOG(DEBUG, " use the normal Rx handler");
+               ENICPMD_LOG(DEBUG, " use the normal Rx handler");
                eth_dev->rx_pkt_burst = &enic_recv_pkts;
        }
 }
@@ -535,6 +558,24 @@ int enic_enable(struct enic *enic)
        int err;
        struct rte_eth_dev *eth_dev = enic->rte_dev;
        uint64_t simple_tx_offloads;
+       uintptr_t p;
+
+       if (enic->enable_avx2_rx) {
+               struct rte_mbuf mb_def = { .buf_addr = 0 };
+
+               /*
+                * mbuf_initializer contains const-after-init fields of
+                * receive mbufs (i.e. 64 bits of fields from rearm_data).
+                * It is currently used by the vectorized handler.
+                */
+               mb_def.nb_segs = 1;
+               mb_def.data_off = RTE_PKTMBUF_HEADROOM;
+               mb_def.port = enic->port_id;
+               rte_mbuf_refcnt_set(&mb_def, 1);
+               rte_compiler_barrier();
+               p = (uintptr_t)&mb_def.rearm_data;
+               enic->mbuf_initializer = *(uint64_t *)p;
+       }
 
        eth_dev->data->dev_link.link_speed = vnic_dev_port_speed(enic->vdev);
        eth_dev->data->dev_link.link_duplex = ETH_LINK_FULL_DUPLEX;
@@ -584,12 +625,12 @@ int enic_enable(struct enic *enic)
                 DEV_TX_OFFLOAD_TCP_CKSUM);
        if ((eth_dev->data->dev_conf.txmode.offloads &
             ~simple_tx_offloads) == 0) {
-               PMD_INIT_LOG(DEBUG, " use the simple tx handler");
+               ENICPMD_LOG(DEBUG, " use the simple tx handler");
                eth_dev->tx_pkt_burst = &enic_simple_xmit_pkts;
                for (index = 0; index < enic->wq_count; index++)
                        enic_prep_wq_for_simple_tx(enic, index);
        } else {
-               PMD_INIT_LOG(DEBUG, " use the default tx handler");
+               ENICPMD_LOG(DEBUG, " use the default tx handler");
                eth_dev->tx_pkt_burst = &enic_xmit_pkts;
        }
 
@@ -1330,10 +1371,10 @@ int enic_set_vlan_strip(struct enic *enic)
                               enic->rss_enable);
 }
 
-void enic_add_packet_filter(struct enic *enic)
+int enic_add_packet_filter(struct enic *enic)
 {
        /* Args -> directed, multicast, broadcast, promisc, allmulti */
-       vnic_dev_packet_filter(enic->vdev, 1, 1, 1,
+       return vnic_dev_packet_filter(enic->vdev, 1, 1, 1,
                enic->promisc, enic->allmulti);
 }
 
@@ -1344,12 +1385,10 @@ int enic_get_link_status(struct enic *enic)
 
 static void enic_dev_deinit(struct enic *enic)
 {
-       struct rte_eth_dev *eth_dev = enic->rte_dev;
-
        /* stop link status checking */
        vnic_dev_notify_unset(enic->vdev);
 
-       rte_free(eth_dev->data->mac_addrs);
+       /* mac_addrs is freed by rte_eth_dev_release_port() */
        rte_free(enic->cq);
        rte_free(enic->intr);
        rte_free(enic->rq);
@@ -1634,20 +1673,19 @@ static int enic_dev_init(struct enic *enic)
        /* Get the supported filters */
        enic_fdir_info(enic);
 
-       eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr", ETH_ALEN
-                                               * ENIC_MAX_MAC_ADDR, 0);
+       eth_dev->data->mac_addrs = rte_zmalloc("enic_mac_addr",
+                                       sizeof(struct rte_ether_addr) *
+                                       ENIC_UNICAST_PERFECT_FILTERS, 0);
        if (!eth_dev->data->mac_addrs) {
                dev_err(enic, "mac addr storage alloc failed, aborting.\n");
                return -1;
        }
-       ether_addr_copy((struct ether_addr *) enic->mac_addr,
+       rte_ether_addr_copy((struct rte_ether_addr *)enic->mac_addr,
                        eth_dev->data->mac_addrs);
 
        vnic_dev_set_reset_flag(enic->vdev, 0);
 
        LIST_INIT(&enic->flows);
-       rte_spinlock_init(&enic->flows_lock);
-       enic->max_flow_counter = -1;
 
        /* set up link status checking */
        vnic_dev_notify_set(enic->vdev, -1); /* No Intr for notify */
@@ -1675,16 +1713,21 @@ static int enic_dev_init(struct enic *enic)
                        DEV_TX_OFFLOAD_OUTER_IPV4_CKSUM |
                        DEV_TX_OFFLOAD_GENEVE_TNL_TSO |
                        DEV_TX_OFFLOAD_VXLAN_TNL_TSO;
-               /*
-                * Do not add PKT_TX_OUTER_{IPV4,IPV6} as they are not
-                * 'offload' flags (i.e. not part of PKT_TX_OFFLOAD_MASK).
-                */
                enic->tx_offload_mask |=
+                       PKT_TX_OUTER_IPV6 |
+                       PKT_TX_OUTER_IPV4 |
                        PKT_TX_OUTER_IP_CKSUM |
                        PKT_TX_TUNNEL_MASK;
                enic->overlay_offload = true;
-               enic->vxlan_port = ENIC_DEFAULT_VXLAN_PORT;
                dev_info(enic, "Overlay offload is enabled\n");
+       }
+       /*
+        * Reset the vxlan port if HW vxlan parsing is available. It
+        * is always enabled regardless of overlay offload
+        * enable/disable.
+        */
+       if (enic->vxlan) {
+               enic->vxlan_port = ENIC_DEFAULT_VXLAN_PORT;
                /*
                 * Reset the vxlan port to the default, as the NIC firmware
                 * does not reset it automatically and keeps the old setting.
@@ -1706,7 +1749,7 @@ int enic_probe(struct enic *enic)
        struct rte_pci_device *pdev = enic->pdev;
        int err = -1;
 
-       dev_debug(enic, " Initializing ENIC PMD\n");
+       dev_debug(enic, "Initializing ENIC PMD\n");
 
        /* if this is a secondary process the hardware is already initialized */
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
@@ -1730,20 +1773,14 @@ int enic_probe(struct enic *enic)
                enic_free_consistent);
 
        /*
-        * Allocate the consistent memory for stats and counters upfront so
-        * both primary and secondary processes can dump stats.
+        * Allocate the consistent memory for stats upfront so both primary and
+        * secondary processes can dump stats.
         */
        err = vnic_dev_alloc_stats_mem(enic->vdev);
        if (err) {
                dev_err(enic, "Failed to allocate cmd memory, aborting\n");
                goto err_out_unregister;
        }
-       err = vnic_dev_alloc_counter_mem(enic->vdev);
-       if (err) {
-               dev_err(enic, "Failed to allocate counter memory, aborting\n");
-               goto err_out_unregister;
-       }
-
        /* Issue device open to get device in known state */
        err = enic_dev_open(enic);
        if (err) {