net/bnxt: fix race between interrupt handler and dev config
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
index 4fc182b..e7ec99e 100644 (file)
@@ -14,7 +14,6 @@
 #include <rte_alarm.h>
 
 #include "bnxt.h"
-#include "bnxt_cpr.h"
 #include "bnxt_filter.h"
 #include "bnxt_hwrm.h"
 #include "bnxt_irq.h"
 #include "bnxt_vnic.h"
 #include "hsi_struct_def_dpdk.h"
 #include "bnxt_nvm_defs.h"
-#include "bnxt_util.h"
 
 #define DRV_MODULE_NAME                "bnxt"
 static const char bnxt_version[] =
        "Broadcom NetXtreme driver " DRV_MODULE_NAME;
 int bnxt_logtype_driver;
 
-#define PCI_VENDOR_ID_BROADCOM 0x14E4
-
-#define BROADCOM_DEV_ID_STRATUS_NIC_VF1 0x1606
-#define BROADCOM_DEV_ID_STRATUS_NIC_VF2 0x1609
-#define BROADCOM_DEV_ID_STRATUS_NIC 0x1614
-#define BROADCOM_DEV_ID_57414_VF 0x16c1
-#define BROADCOM_DEV_ID_57301 0x16c8
-#define BROADCOM_DEV_ID_57302 0x16c9
-#define BROADCOM_DEV_ID_57304_PF 0x16ca
-#define BROADCOM_DEV_ID_57304_VF 0x16cb
-#define BROADCOM_DEV_ID_57417_MF 0x16cc
-#define BROADCOM_DEV_ID_NS2 0x16cd
-#define BROADCOM_DEV_ID_57311 0x16ce
-#define BROADCOM_DEV_ID_57312 0x16cf
-#define BROADCOM_DEV_ID_57402 0x16d0
-#define BROADCOM_DEV_ID_57404 0x16d1
-#define BROADCOM_DEV_ID_57406_PF 0x16d2
-#define BROADCOM_DEV_ID_57406_VF 0x16d3
-#define BROADCOM_DEV_ID_57402_MF 0x16d4
-#define BROADCOM_DEV_ID_57407_RJ45 0x16d5
-#define BROADCOM_DEV_ID_57412 0x16d6
-#define BROADCOM_DEV_ID_57414 0x16d7
-#define BROADCOM_DEV_ID_57416_RJ45 0x16d8
-#define BROADCOM_DEV_ID_57417_RJ45 0x16d9
-#define BROADCOM_DEV_ID_5741X_VF 0x16dc
-#define BROADCOM_DEV_ID_57412_MF 0x16de
-#define BROADCOM_DEV_ID_57314 0x16df
-#define BROADCOM_DEV_ID_57317_RJ45 0x16e0
-#define BROADCOM_DEV_ID_5731X_VF 0x16e1
-#define BROADCOM_DEV_ID_57417_SFP 0x16e2
-#define BROADCOM_DEV_ID_57416_SFP 0x16e3
-#define BROADCOM_DEV_ID_57317_SFP 0x16e4
-#define BROADCOM_DEV_ID_57404_MF 0x16e7
-#define BROADCOM_DEV_ID_57406_MF 0x16e8
-#define BROADCOM_DEV_ID_57407_SFP 0x16e9
-#define BROADCOM_DEV_ID_57407_MF 0x16ea
-#define BROADCOM_DEV_ID_57414_MF 0x16ec
-#define BROADCOM_DEV_ID_57416_MF 0x16ee
-#define BROADCOM_DEV_ID_57508 0x1750
-#define BROADCOM_DEV_ID_57504 0x1751
-#define BROADCOM_DEV_ID_57502 0x1752
-#define BROADCOM_DEV_ID_57500_VF1 0x1806
-#define BROADCOM_DEV_ID_57500_VF2 0x1807
-#define BROADCOM_DEV_ID_58802 0xd802
-#define BROADCOM_DEV_ID_58804 0xd804
-#define BROADCOM_DEV_ID_58808 0x16f0
-#define BROADCOM_DEV_ID_58802_VF 0xd800
-
+/*
+ * The set of PCI devices this driver supports
+ */
 static const struct rte_pci_id bnxt_pci_id_map[] = {
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM,
                         BROADCOM_DEV_ID_STRATUS_NIC_VF1) },
@@ -163,7 +116,8 @@ static const struct rte_pci_id bnxt_pci_id_map[] = {
                                     DEV_RX_OFFLOAD_JUMBO_FRAME | \
                                     DEV_RX_OFFLOAD_KEEP_CRC | \
                                     DEV_RX_OFFLOAD_VLAN_EXTEND | \
-                                    DEV_RX_OFFLOAD_TCP_LRO)
+                                    DEV_RX_OFFLOAD_TCP_LRO | \
+                                    DEV_RX_OFFLOAD_SCATTER)
 
 static int bnxt_vlan_offload_set_op(struct rte_eth_dev *dev, int mask);
 static void bnxt_print_link_info(struct rte_eth_dev *eth_dev);
@@ -223,6 +177,7 @@ static void bnxt_free_mem(struct bnxt *bp, bool reconfig)
                bnxt_free_rx_rings(bp);
        }
        bnxt_free_async_cp_ring(bp);
+       bnxt_free_rxtx_nq_ring(bp);
 }
 
 static int bnxt_alloc_mem(struct bnxt *bp, bool reconfig)
@@ -253,6 +208,10 @@ static int bnxt_alloc_mem(struct bnxt *bp, bool reconfig)
        if (rc)
                goto alloc_mem_err;
 
+       rc = bnxt_alloc_rxtx_nq_ring(bp);
+       if (rc)
+               goto alloc_mem_err;
+
        return 0;
 
 alloc_mem_err:
@@ -308,6 +267,25 @@ static int bnxt_init_chip(struct bnxt *bp)
                goto err_out;
        }
 
+       if (!(bp->vnic_cap_flags & BNXT_VNIC_CAP_COS_CLASSIFY))
+               goto skip_cosq_cfg;
+
+       for (j = 0, i = 0; i < BNXT_COS_QUEUE_COUNT; i++) {
+               if (bp->rx_cos_queue[i].id != 0xff) {
+                       struct bnxt_vnic_info *vnic = &bp->vnic_info[j++];
+
+                       if (!vnic) {
+                               PMD_DRV_LOG(ERR,
+                                           "Num pools more than FW profile\n");
+                               rc = -EINVAL;
+                               goto err_out;
+                       }
+                       vnic->cos_queue_id = bp->rx_cos_queue[i].id;
+                       bp->rx_cosq_cnt++;
+               }
+       }
+
+skip_cosq_cfg:
        rc = bnxt_mq_rx_configure(bp);
        if (rc) {
                PMD_DRV_LOG(ERR, "MQ mode configure failure rc: %x\n", rc);
@@ -644,11 +622,36 @@ static int bnxt_dev_configure_op(struct rte_eth_dev *eth_dev)
                        return -ENOSPC;
                }
 
+               /* If a resource has already been allocated - in this case
+                * it is the async completion ring, free it. Reallocate it after
+                * resource reservation. This will ensure the resource counts
+                * are calculated correctly.
+                */
+
+               pthread_mutex_lock(&bp->def_cp_lock);
+
+               if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
+                       bnxt_disable_int(bp);
+                       bnxt_free_cp_ring(bp, bp->async_cp_ring);
+               }
+
                rc = bnxt_hwrm_func_reserve_vf_resc(bp, false);
                if (rc) {
                        PMD_DRV_LOG(ERR, "HWRM resource alloc fail:%x\n", rc);
+                       pthread_mutex_unlock(&bp->def_cp_lock);
                        return -ENOSPC;
                }
+
+               if (!BNXT_HAS_NQ(bp) && bp->async_cp_ring) {
+                       rc = bnxt_alloc_async_cp_ring(bp);
+                       if (rc) {
+                               pthread_mutex_unlock(&bp->def_cp_lock);
+                               return rc;
+                       }
+                       bnxt_enable_int(bp);
+               }
+
+               pthread_mutex_unlock(&bp->def_cp_lock);
        } else {
                /* legacy driver needs to get updated values */
                rc = bnxt_hwrm_func_qcaps(bp);
@@ -725,6 +728,9 @@ static int bnxt_scattered_rx(struct rte_eth_dev *eth_dev)
        uint16_t buf_size;
        int i;
 
+       if (eth_dev->data->dev_conf.rxmode.offloads & DEV_RX_OFFLOAD_SCATTER)
+               return 1;
+
        for (i = 0; i < eth_dev->data->nb_rx_queues; i++) {
                struct bnxt_rx_queue *rxq = eth_dev->data->rx_queues[i];
 
@@ -831,7 +837,6 @@ static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
                        bp->rx_cp_nr_rings, RTE_ETHDEV_QUEUE_STAT_CNTRS);
        }
 
-       bnxt_enable_int(bp);
        rc = bnxt_hwrm_if_change(bp, 1);
        if (!rc) {
                if (bp->flags & BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE) {
@@ -840,6 +845,7 @@ static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
                                return rc;
                }
        }
+       bnxt_enable_int(bp);
 
        rc = bnxt_init_chip(bp);
        if (rc)
@@ -885,7 +891,7 @@ static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
                eth_dev->data->dev_link.link_status = 1;
 
        bnxt_print_link_info(eth_dev);
-       return 0;
+       return rc;
 }
 
 static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
@@ -924,8 +930,12 @@ static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
                eth_dev->data->dev_link.link_status = 0;
        }
        bnxt_dev_set_link_down_op(eth_dev);
-       /* Wait for link to be reset and the async notification to process. */
-       rte_delay_ms(BNXT_LINK_WAIT_INTERVAL * 2);
+
+       /* Wait for link to be reset and the async notification to process.
+        * During reset recovery, there is no need to wait
+        */
+       if (!is_bnxt_in_error(bp))
+               rte_delay_ms(BNXT_LINK_WAIT_INTERVAL * 2);
 
        /* Clean queue intr-vector mapping */
        rte_intr_efd_disable(intr_handle);
@@ -2955,7 +2965,6 @@ bnxt_parse_fdir_filter(struct bnxt *bp,
                return -EINVAL;
        }
 
-
        if (fdir_mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) {
                rte_memcpy(filter->dst_macaddr,
                        fdir->input.flow.mac_vlan_flow.mac_addr.addr_bytes, 6);
@@ -4540,7 +4549,7 @@ static int bnxt_init_fw(struct bnxt *bp)
        if (rc)
                return -EIO;
 
-       rc = bnxt_hwrm_cfa_adv_flow_mgmt_qcaps(bp);
+       rc = bnxt_hwrm_vnic_qcaps(bp);
        if (rc)
                return rc;
 
@@ -4548,16 +4557,19 @@ static int bnxt_init_fw(struct bnxt *bp)
        if (rc)
                return rc;
 
-       /* Get the MAX capabilities for this function */
+       /* Get the MAX capabilities for this function.
+        * This function also allocates context memory for TQM rings and
+        * informs the firmware about this allocated backing store memory.
+        */
        rc = bnxt_hwrm_func_qcaps(bp);
        if (rc)
                return rc;
 
-       rc = bnxt_hwrm_vnic_qcaps(bp);
+       rc = bnxt_hwrm_func_qcfg(bp, &mtu);
        if (rc)
                return rc;
 
-       rc = bnxt_hwrm_func_qcfg(bp, &mtu);
+       rc = bnxt_hwrm_cfa_adv_flow_mgmt_qcaps(bp);
        if (rc)
                return rc;
 
@@ -4581,8 +4593,14 @@ bnxt_init_locks(struct bnxt *bp)
        int err;
 
        err = pthread_mutex_init(&bp->flow_lock, NULL);
-       if (err)
+       if (err) {
                PMD_DRV_LOG(ERR, "Unable to initialize flow_lock\n");
+               return err;
+       }
+
+       err = pthread_mutex_init(&bp->def_cp_lock, NULL);
+       if (err)
+               PMD_DRV_LOG(ERR, "Unable to initialize def_cp_lock\n");
        return err;
 }
 
@@ -4731,6 +4749,7 @@ static void
 bnxt_uninit_locks(struct bnxt *bp)
 {
        pthread_mutex_destroy(&bp->flow_lock);
+       pthread_mutex_destroy(&bp->def_cp_lock);
 }
 
 static int