net/bnxt: remove unnecessary interrupt disable
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
index 3f46065..ded9706 100644 (file)
@@ -74,7 +74,8 @@ int bnxt_logtype_driver;
 #define BROADCOM_DEV_ID_57508 0x1750
 #define BROADCOM_DEV_ID_57504 0x1751
 #define BROADCOM_DEV_ID_57502 0x1752
-#define BROADCOM_DEV_ID_57500_VF 0x1807
+#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
@@ -126,7 +127,8 @@ static const struct rte_pci_id bnxt_pci_id_map[] = {
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57508) },
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57504) },
        { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57502) },
-       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF1) },
+       { RTE_PCI_DEVICE(PCI_VENDOR_ID_BROADCOM, BROADCOM_DEV_ID_57500_VF2) },
        { .vendor_id = 0, /* sentinel */ },
 };
 
@@ -237,9 +239,6 @@ static int bnxt_init_chip(struct bnxt *bp)
        unsigned int i, j;
        int rc;
 
-       /* disable uio/vfio intr/eventfd mapping */
-       rte_intr_disable(intr_handle);
-
        if (bp->eth_dev->data->mtu > RTE_ETHER_MTU) {
                bp->eth_dev->data->dev_conf.rxmode.offloads |=
                        DEV_RX_OFFLOAD_JUMBO_FRAME;
@@ -394,8 +393,9 @@ static int bnxt_init_chip(struct bnxt *bp)
                                        bp->rx_cp_nr_rings);
                        return -ENOTSUP;
                }
-               if (rte_intr_efd_enable(intr_handle, intr_vector))
-                       return -1;
+               rc = rte_intr_efd_enable(intr_handle, intr_vector);
+               if (rc)
+                       return rc;
        }
 
        if (rte_intr_dp_is_en(intr_handle) && !intr_handle->intr_vec) {
@@ -406,7 +406,8 @@ static int bnxt_init_chip(struct bnxt *bp)
                if (intr_handle->intr_vec == NULL) {
                        PMD_DRV_LOG(ERR, "Failed to allocate %d rx_queues"
                                " intr_vec", bp->eth_dev->data->nb_rx_queues);
-                       return -ENOMEM;
+                       rc = -ENOMEM;
+                       goto err_disable;
                }
                PMD_DRV_LOG(DEBUG, "intr_handle->intr_vec = %p "
                        "intr_handle->nb_efd = %d intr_handle->max_intr = %d\n",
@@ -414,19 +415,22 @@ static int bnxt_init_chip(struct bnxt *bp)
                        intr_handle->max_intr);
                for (queue_id = 0; queue_id < bp->eth_dev->data->nb_rx_queues;
                     queue_id++) {
-                       intr_handle->intr_vec[queue_id] = vec;
+                       intr_handle->intr_vec[queue_id] =
+                                                       vec + BNXT_RX_VEC_START;
                        if (vec < base + intr_handle->nb_efd - 1)
                                vec++;
                }
        }
 
        /* enable uio/vfio intr/eventfd mapping */
-       rte_intr_enable(intr_handle);
+       rc = rte_intr_enable(intr_handle);
+       if (rc)
+               goto err_free;
 
        rc = bnxt_get_hwrm_link_config(bp, &new);
        if (rc) {
                PMD_DRV_LOG(ERR, "HWRM Get link config failure rc: %x\n", rc);
-               goto err_out;
+               goto err_free;
        }
 
        if (!bp->link_info.link_up) {
@@ -434,16 +438,18 @@ static int bnxt_init_chip(struct bnxt *bp)
                if (rc) {
                        PMD_DRV_LOG(ERR,
                                "HWRM link config failure rc: %x\n", rc);
-                       goto err_out;
+                       goto err_free;
                }
        }
        bnxt_print_link_info(bp->eth_dev);
 
        return 0;
 
+err_free:
+       rte_free(intr_handle->intr_vec);
+err_disable:
+       rte_intr_efd_disable(intr_handle);
 err_out:
-       bnxt_free_all_hwrm_resources(bp);
-
        /* Some of the error status returned by FW may not be from errno.h */
        if (rc > 0)
                rc = -EIO;
@@ -493,7 +499,7 @@ static void bnxt_dev_info_get_op(struct rte_eth_dev *eth_dev,
        /* PF/VF specifics */
        if (BNXT_PF(bp))
                dev_info->max_vfs = bp->pdev->max_vfs;
-       max_rx_rings = RTE_MIN(bp->max_vnics, bp->max_stat_ctx);
+       max_rx_rings = RTE_MIN(bp->max_rx_rings, bp->max_stat_ctx);
        /* For the sake of symmetry, max_rx_queues = max_tx_queues */
        dev_info->max_rx_queues = max_rx_rings;
        dev_info->max_tx_queues = max_rx_rings;
@@ -725,13 +731,11 @@ bnxt_transmit_function(__rte_unused struct rte_eth_dev *eth_dev)
 {
 #ifdef RTE_ARCH_X86
        /*
-        * Vector mode receive can be enabled only if scatter tx is not
-        * in use and tx offloads other than VLAN insertion are not
-        * in use.
+        * Vector mode transmit can be enabled only if not using scatter rx
+        * or tx offloads.
         */
        if (!eth_dev->data->scattered_rx &&
-           !(eth_dev->data->dev_conf.txmode.offloads &
-             ~DEV_TX_OFFLOAD_VLAN_INSERT)) {
+           !eth_dev->data->dev_conf.txmode.offloads) {
                PMD_DRV_LOG(INFO, "Using vector mode transmit for port %d\n",
                            eth_dev->data->port_id);
                return bnxt_xmit_pkts_vec;
@@ -759,7 +763,6 @@ static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
                        "RxQ cnt %d > CONFIG_RTE_ETHDEV_QUEUE_STAT_CNTRS %d\n",
                        bp->rx_cp_nr_rings, RTE_ETHDEV_QUEUE_STAT_CNTRS);
        }
-       bp->dev_stopped = 0;
 
        rc = bnxt_init_chip(bp);
        if (rc)
@@ -779,7 +782,9 @@ static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
 
        eth_dev->rx_pkt_burst = bnxt_receive_function(eth_dev);
        eth_dev->tx_pkt_burst = bnxt_transmit_function(eth_dev);
+       bnxt_enable_int(bp);
        bp->flags |= BNXT_FLAG_INIT_DONE;
+       bp->dev_stopped = 0;
        return 0;
 
 error:
@@ -818,6 +823,13 @@ static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
 static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
 {
        struct bnxt *bp = eth_dev->data->dev_private;
+       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+       struct rte_intr_handle *intr_handle = &pci_dev->intr_handle;
+
+       bnxt_disable_int(bp);
+
+       /* disable uio/vfio intr/eventfd mapping */
+       rte_intr_disable(intr_handle);
 
        bp->flags &= ~BNXT_FLAG_INIT_DONE;
        if (bp->eth_dev->data->dev_started) {
@@ -825,6 +837,14 @@ static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
                eth_dev->data->dev_link.link_status = 0;
        }
        bnxt_set_hwrm_link_config(bp, false);
+
+       /* Clean queue intr-vector mapping */
+       rte_intr_efd_disable(intr_handle);
+       if (intr_handle->intr_vec != NULL) {
+               rte_free(intr_handle->intr_vec);
+               intr_handle->intr_vec = NULL;
+       }
+
        bnxt_hwrm_port_clr_stats(bp);
        bnxt_free_tx_mbufs(bp);
        bnxt_free_rx_mbufs(bp);
@@ -893,6 +913,7 @@ static int bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
        struct bnxt *bp = eth_dev->data->dev_private;
        struct bnxt_vnic_info *vnic = &bp->vnic_info[pool];
        struct bnxt_filter_info *filter;
+       int rc = 0;
 
        if (BNXT_VF(bp) & !BNXT_VF_IS_TRUSTED(bp)) {
                PMD_DRV_LOG(ERR, "Cannot add MAC address to a VF interface\n");
@@ -916,10 +937,20 @@ static int bnxt_mac_addr_add_op(struct rte_eth_dev *eth_dev,
                PMD_DRV_LOG(ERR, "L2 filter alloc failed\n");
                return -ENODEV;
        }
-       STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
+
        filter->mac_index = index;
        memcpy(filter->l2_addr, mac_addr, RTE_ETHER_ADDR_LEN);
-       return bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
+
+       rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
+       if (!rc) {
+               STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
+       } else {
+               filter->mac_index = INVALID_MAC_INDEX;
+               memset(&filter->l2_addr, 0, RTE_ETHER_ADDR_LEN);
+               bnxt_free_filter(bp, filter);
+       }
+
+       return rc;
 }
 
 int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete)
@@ -940,11 +971,12 @@ int bnxt_link_update_op(struct rte_eth_dev *eth_dev, int wait_to_complete)
                                "Failed to retrieve link rc = 0x%x!\n", rc);
                        goto out;
                }
-               rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
 
-               if (!wait_to_complete)
+               if (!wait_to_complete || new.link_status)
                        break;
-       } while (!new.link_status && cnt--);
+
+               rte_delay_ms(BNXT_LINK_WAIT_INTERVAL);
+       } while (cnt--);
 
 out:
        /* Timed out or success */
@@ -1465,141 +1497,98 @@ bnxt_udp_tunnel_port_del_op(struct rte_eth_dev *eth_dev,
 
 static int bnxt_del_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
 {
-       struct bnxt_filter_info *filter, *temp_filter, *new_filter;
+       struct bnxt_filter_info *filter;
        struct bnxt_vnic_info *vnic;
-       unsigned int i;
        int rc = 0;
-       uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_OVLAN;
-
-       /* Cycle through all VNICs */
-       for (i = 0; i < bp->nr_vnics; i++) {
-               /*
-                * For each VNIC and each associated filter(s)
-                * if VLAN exists && VLAN matches vlan_id
-                *      remove the MAC+VLAN filter
-                *      add a new MAC only filter
-                * else
-                *      VLAN filter doesn't exist, just skip and continue
-                */
-               vnic = &bp->vnic_info[i];
-               filter = STAILQ_FIRST(&vnic->filter);
-               while (filter) {
-                       temp_filter = STAILQ_NEXT(filter, next);
+       uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
 
-                       if (filter->enables & chk &&
-                           filter->l2_ovlan == vlan_id) {
-                               /* Must delete the filter */
-                               STAILQ_REMOVE(&vnic->filter, filter,
-                                             bnxt_filter_info, next);
-                               bnxt_hwrm_clear_l2_filter(bp, filter);
-                               STAILQ_INSERT_TAIL(&bp->free_filter_list,
-                                                  filter, next);
+       /* if VLAN exists && VLAN matches vlan_id
+        *      remove the MAC+VLAN filter
+        *      add a new MAC only filter
+        * else
+        *      VLAN filter doesn't exist, just skip and continue
+        */
+       vnic = BNXT_GET_DEFAULT_VNIC(bp);
+       filter = STAILQ_FIRST(&vnic->filter);
+       while (filter) {
+               /* Search for this matching MAC+VLAN filter */
+               if (filter->enables & chk && filter->l2_ivlan == vlan_id &&
+                   !memcmp(filter->l2_addr,
+                           bp->mac_addr,
+                           RTE_ETHER_ADDR_LEN)) {
+                       /* Delete the filter */
+                       rc = bnxt_hwrm_clear_l2_filter(bp, filter);
+                       if (rc)
+                               return rc;
+                       STAILQ_REMOVE(&vnic->filter, filter,
+                                     bnxt_filter_info, next);
+                       STAILQ_INSERT_TAIL(&bp->free_filter_list, filter, next);
 
-                               /*
-                                * Need to examine to see if the MAC
-                                * filter already existed or not before
-                                * allocating a new one
-                                */
-
-                               new_filter = bnxt_alloc_filter(bp);
-                               if (!new_filter) {
-                                       PMD_DRV_LOG(ERR,
-                                                       "MAC/VLAN filter alloc failed\n");
-                                       rc = -ENOMEM;
-                                       goto exit;
-                               }
-                               STAILQ_INSERT_TAIL(&vnic->filter,
-                                               new_filter, next);
-                               /* Inherit MAC from previous filter */
-                               new_filter->mac_index =
-                                       filter->mac_index;
-                               memcpy(new_filter->l2_addr, filter->l2_addr,
-                                      RTE_ETHER_ADDR_LEN);
-                               /* MAC only filter */
-                               rc = bnxt_hwrm_set_l2_filter(bp,
-                                                            vnic->fw_vnic_id,
-                                                            new_filter);
-                               if (rc)
-                                       goto exit;
-                               PMD_DRV_LOG(INFO,
-                                           "Del Vlan filter for %d\n",
-                                           vlan_id);
-                       }
-                       filter = temp_filter;
+                       PMD_DRV_LOG(INFO,
+                                   "Del Vlan filter for %d\n",
+                                   vlan_id);
+                       return rc;
                }
+               filter = STAILQ_NEXT(filter, next);
        }
-exit:
-       return rc;
+       return -ENOENT;
 }
 
 static int bnxt_add_vlan_filter(struct bnxt *bp, uint16_t vlan_id)
 {
-       struct bnxt_filter_info *filter, *temp_filter, *new_filter;
+       struct bnxt_filter_info *filter;
        struct bnxt_vnic_info *vnic;
-       unsigned int i;
        int rc = 0;
        uint32_t en = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN |
                HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN_MASK;
        uint32_t chk = HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_IVLAN;
 
-       /* Cycle through all VNICs */
-       for (i = 0; i < bp->nr_vnics; i++) {
-               /*
-                * For each VNIC and each associated filter(s)
-                * if VLAN exists:
-                *   if VLAN matches vlan_id
-                *      VLAN filter already exists, just skip and continue
-                *   else
-                *      add a new MAC+VLAN filter
-                * else
-                *   Remove the old MAC only filter
-                *    Add a new MAC+VLAN filter
-                */
-               vnic = &bp->vnic_info[i];
-               filter = STAILQ_FIRST(&vnic->filter);
-               while (filter) {
-                       temp_filter = STAILQ_NEXT(filter, next);
+       /* Implementation notes on the use of VNIC in this command:
+        *
+        * By default, these filters belong to default vnic for the function.
+        * Once these filters are set up, only destination VNIC can be modified.
+        * If the destination VNIC is not specified in this command,
+        * then the HWRM shall only create an l2 context id.
+        */
 
-                       if (filter->enables & chk) {
-                               if (filter->l2_ivlan == vlan_id)
-                                       goto cont;
-                       } else {
-                               /* Must delete the MAC filter */
-                               STAILQ_REMOVE(&vnic->filter, filter,
-                                               bnxt_filter_info, next);
-                               bnxt_hwrm_clear_l2_filter(bp, filter);
-                               filter->l2_ovlan = 0;
-                               STAILQ_INSERT_TAIL(&bp->free_filter_list,
-                                                  filter, next);
-                       }
-                       new_filter = bnxt_alloc_filter(bp);
-                       if (!new_filter) {
-                               PMD_DRV_LOG(ERR,
-                                               "MAC/VLAN filter alloc failed\n");
-                               rc = -ENOMEM;
-                               goto exit;
-                       }
-                       STAILQ_INSERT_TAIL(&vnic->filter, new_filter, next);
-                       /* Inherit MAC from the previous filter */
-                       new_filter->mac_index = filter->mac_index;
-                       memcpy(new_filter->l2_addr, filter->l2_addr,
-                              RTE_ETHER_ADDR_LEN);
-                       /* MAC + VLAN ID filter */
-                       new_filter->l2_ivlan = vlan_id;
-                       new_filter->l2_ivlan_mask = 0xF000;
-                       new_filter->enables |= en;
-                       rc = bnxt_hwrm_set_l2_filter(bp,
-                                       vnic->fw_vnic_id,
-                                       new_filter);
-                       if (rc)
-                               goto exit;
-                       PMD_DRV_LOG(INFO,
-                                   "Added Vlan filter for %d\n", vlan_id);
-cont:
-                       filter = temp_filter;
-               }
+       vnic = BNXT_GET_DEFAULT_VNIC(bp);
+       filter = STAILQ_FIRST(&vnic->filter);
+       /* Check if the VLAN has already been added */
+       while (filter) {
+               if (filter->enables & chk && filter->l2_ivlan == vlan_id &&
+                   !memcmp(filter->l2_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN))
+                       return -EEXIST;
+
+               filter = STAILQ_NEXT(filter, next);
        }
-exit:
+
+       /* No match found. Alloc a fresh filter and issue the L2_FILTER_ALLOC
+        * command to create MAC+VLAN filter with the right flags, enables set.
+        */
+       filter = bnxt_alloc_filter(bp);
+       if (!filter) {
+               PMD_DRV_LOG(ERR,
+                           "MAC/VLAN filter alloc failed\n");
+               return -ENOMEM;
+       }
+       /* MAC + VLAN ID filter */
+       filter->l2_ivlan = vlan_id;
+       filter->l2_ivlan_mask = 0x0FFF;
+       filter->enables |= en;
+       rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
+       if (rc) {
+               /* Free the newly allocated filter as we were
+                * not able to create the filter in hardware.
+                */
+               filter->fw_l2_filter_id = UINT64_MAX;
+               STAILQ_INSERT_TAIL(&bp->free_filter_list, filter, next);
+               return rc;
+       }
+
+       /* Add this new filter to the list */
+       STAILQ_INSERT_TAIL(&vnic->filter, filter, next);
+       PMD_DRV_LOG(INFO,
+                   "Added Vlan filter for %d\n", vlan_id);
        return rc;
 }
 
@@ -1665,26 +1654,28 @@ bnxt_set_default_mac_addr_op(struct rte_eth_dev *dev,
        if (BNXT_VF(bp) && !BNXT_VF_IS_TRUSTED(bp))
                return -EPERM;
 
-       memcpy(bp->mac_addr, addr, sizeof(bp->mac_addr));
+       if (rte_is_zero_ether_addr(addr))
+               return -EINVAL;
 
        STAILQ_FOREACH(filter, &vnic->filter, next) {
                /* Default Filter is at Index 0 */
                if (filter->mac_index != 0)
                        continue;
-               rc = bnxt_hwrm_clear_l2_filter(bp, filter);
-               if (rc)
-                       return rc;
+
                memcpy(filter->l2_addr, bp->mac_addr, RTE_ETHER_ADDR_LEN);
                memset(filter->l2_addr_mask, 0xff, RTE_ETHER_ADDR_LEN);
                filter->flags |= HWRM_CFA_L2_FILTER_ALLOC_INPUT_FLAGS_PATH_RX;
                filter->enables |=
                        HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR |
                        HWRM_CFA_L2_FILTER_ALLOC_INPUT_ENABLES_L2_ADDR_MASK;
+
                rc = bnxt_hwrm_set_l2_filter(bp, vnic->fw_vnic_id, filter);
                if (rc)
                        return rc;
-               filter->mac_index = 0;
+
+               memcpy(bp->mac_addr, addr, RTE_ETHER_ADDR_LEN);
                PMD_DRV_LOG(DEBUG, "Set MAC addr\n");
+               return 0;
        }
 
        return 0;
@@ -2116,7 +2107,7 @@ bnxt_ethertype_filter(struct rte_eth_dev *dev,
 
                filter1 = bnxt_get_l2_filter(bp, bfilter, vnic0);
                if (filter1 == NULL) {
-                       ret = -1;
+                       ret = -EINVAL;
                        goto cleanup;
                }
                bfilter->enables |=
@@ -2310,7 +2301,7 @@ bnxt_cfg_ntuple_filter(struct bnxt *bp,
        vnic0 = &bp->vnic_info[0];
        filter1 = STAILQ_FIRST(&vnic0->filter);
        if (filter1 == NULL) {
-               ret = -1;
+               ret = -EINVAL;
                goto free_filter;
        }
 
@@ -3252,7 +3243,6 @@ bnxt_set_eeprom_op(struct rte_eth_dev *dev,
 
        return bnxt_hwrm_flash_nvram(bp, type, ordinal, ext, attr,
                                     in_eeprom->data, in_eeprom->length);
-       return 0;
 }
 
 /*
@@ -3337,7 +3327,8 @@ static bool bnxt_vf_pciid(uint16_t id)
            id == BROADCOM_DEV_ID_STRATUS_NIC_VF1 ||
            id == BROADCOM_DEV_ID_STRATUS_NIC_VF2 ||
            id == BROADCOM_DEV_ID_58802_VF ||
-           id == BROADCOM_DEV_ID_57500_VF)
+           id == BROADCOM_DEV_ID_57500_VF1 ||
+           id == BROADCOM_DEV_ID_57500_VF2)
                return true;
        return false;
 }
@@ -3355,48 +3346,21 @@ bool bnxt_stratus_device(struct bnxt *bp)
 
 static int bnxt_init_board(struct rte_eth_dev *eth_dev)
 {
-       struct bnxt *bp = eth_dev->data->dev_private;
        struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
-       int rc;
+       struct bnxt *bp = eth_dev->data->dev_private;
 
        /* enable device (incl. PCI PM wakeup), and bus-mastering */
-       if (!pci_dev->mem_resource[0].addr) {
-               PMD_DRV_LOG(ERR,
-                       "Cannot find PCI device base address, aborting\n");
-               rc = -ENODEV;
-               goto init_err_disable;
+       bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
+       bp->doorbell_base = (void *)pci_dev->mem_resource[2].addr;
+       if (!bp->bar0 || !bp->doorbell_base) {
+               PMD_DRV_LOG(ERR, "Unable to access Hardware\n");
+               return -ENODEV;
        }
 
        bp->eth_dev = eth_dev;
        bp->pdev = pci_dev;
 
-       bp->bar0 = (void *)pci_dev->mem_resource[0].addr;
-       if (!bp->bar0) {
-               PMD_DRV_LOG(ERR, "Cannot map device registers, aborting\n");
-               rc = -ENOMEM;
-               goto init_err_release;
-       }
-
-       if (!pci_dev->mem_resource[2].addr) {
-               PMD_DRV_LOG(ERR,
-                           "Cannot find PCI device BAR 2 address, aborting\n");
-               rc = -ENODEV;
-               goto init_err_release;
-       } else {
-               bp->doorbell_base = (void *)pci_dev->mem_resource[2].addr;
-       }
-
        return 0;
-
-init_err_release:
-       if (bp->bar0)
-               bp->bar0 = NULL;
-       if (bp->doorbell_base)
-               bp->doorbell_base = NULL;
-
-init_err_disable:
-
-       return rc;
 }
 
 static int bnxt_alloc_ctx_mem_blk(__rte_unused struct bnxt *bp,
@@ -3450,7 +3414,7 @@ static int bnxt_alloc_ctx_mem_blk(__rte_unused struct bnxt *bp,
                        PMD_DRV_LOG(WARNING,
                                    "Using rte_mem_virt2iova()\n");
                        mz_phys_addr = rte_mem_virt2iova(mz->addr);
-                       if (mz_phys_addr == 0) {
+                       if (mz_phys_addr == RTE_BAD_IOVA) {
                                PMD_DRV_LOG(ERR,
                                        "unable to map addr to phys memory\n");
                                return -ENOMEM;
@@ -3636,7 +3600,7 @@ int bnxt_alloc_ctx_mem(struct bnxt *bp)
        else
                ctx->flags |= BNXT_CTX_FLAG_INITED;
 
-       return 0;
+       return rc;
 }
 
 static int bnxt_alloc_stats_mem(struct bnxt *bp)
@@ -3676,7 +3640,7 @@ static int bnxt_alloc_stats_mem(struct bnxt *bp)
                PMD_DRV_LOG(WARNING,
                            "Using rte_mem_virt2iova()\n");
                mz_phys_addr = rte_mem_virt2iova(mz->addr);
-               if (mz_phys_addr == 0) {
+               if (mz_phys_addr == RTE_BAD_IOVA) {
                        PMD_DRV_LOG(ERR,
                                    "Can't map address to physical memory\n");
                        return -ENOMEM;
@@ -3714,7 +3678,7 @@ static int bnxt_alloc_stats_mem(struct bnxt *bp)
                PMD_DRV_LOG(WARNING,
                            "Using rte_mem_virt2iova()\n");
                mz_phys_addr = rte_mem_virt2iova(mz->addr);
-               if (mz_phys_addr == 0) {
+               if (mz_phys_addr == RTE_BAD_IOVA) {
                        PMD_DRV_LOG(ERR,
                                    "Can't map address to physical memory\n");
                        return -ENOMEM;
@@ -3817,8 +3781,16 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
 
        bp->dev_stopped = 1;
 
+       eth_dev->dev_ops = &bnxt_dev_ops;
+       eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
+       eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
+
+       /*
+        * For secondary processes, we don't initialise any further
+        * as primary has already done this work.
+        */
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-               goto skip_init;
+               return 0;
 
        if (bnxt_vf_pciid(pci_dev->id.device_id))
                bp->flags |= BNXT_FLAG_VF;
@@ -3826,7 +3798,8 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
        if (pci_dev->id.device_id == BROADCOM_DEV_ID_57508 ||
            pci_dev->id.device_id == BROADCOM_DEV_ID_57504 ||
            pci_dev->id.device_id == BROADCOM_DEV_ID_57502 ||
-           pci_dev->id.device_id == BROADCOM_DEV_ID_57500_VF)
+           pci_dev->id.device_id == BROADCOM_DEV_ID_57500_VF1 ||
+           pci_dev->id.device_id == BROADCOM_DEV_ID_57500_VF2)
                bp->flags |= BNXT_FLAG_THOR_CHIP;
 
        rc = bnxt_init_board(eth_dev);
@@ -3835,12 +3808,6 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
                        "Board initialization failed rc: %x\n", rc);
                goto error;
        }
-skip_init:
-       eth_dev->dev_ops = &bnxt_dev_ops;
-       eth_dev->rx_pkt_burst = &bnxt_recv_pkts;
-       eth_dev->tx_pkt_burst = &bnxt_xmit_pkts;
-       if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-               return 0;
 
        rc = bnxt_alloc_hwrm_resources(bp);
        if (rc) {
@@ -3985,22 +3952,16 @@ skip_init:
 
        rc = bnxt_alloc_mem(bp);
        if (rc)
-               goto error_free_int;
+               goto error_free;
+
+       bnxt_init_nic(bp);
 
        rc = bnxt_request_int(bp);
        if (rc)
-               goto error_free_int;
-
-       bnxt_enable_int(bp);
-       bnxt_init_nic(bp);
+               goto error_free;
 
        return 0;
 
-error_free_int:
-       bnxt_disable_int(bp);
-       bnxt_hwrm_func_buf_unrgtr(bp);
-       bnxt_free_int(bp);
-       bnxt_free_mem(bp);
 error_free:
        bnxt_dev_uninit(eth_dev);
 error:
@@ -4020,6 +3981,9 @@ bnxt_dev_uninit(struct rte_eth_dev *eth_dev)
        bnxt_disable_int(bp);
        bnxt_free_int(bp);
        bnxt_free_mem(bp);
+
+       bnxt_hwrm_func_buf_unrgtr(bp);
+
        if (bp->grp_info != NULL) {
                rte_free(bp->grp_info);
                bp->grp_info = NULL;