net/enic: use 64B completion queue entries if available
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
index e11751c..74b0f3d 100644 (file)
@@ -1159,6 +1159,12 @@ bnxt_receive_function(struct rte_eth_dev *eth_dev)
 {
        struct bnxt *bp = eth_dev->data->dev_private;
 
+       /* Disable vector mode RX for Stingray2 for now */
+       if (BNXT_CHIP_SR2(bp)) {
+               bp->flags &= ~BNXT_FLAG_RX_VECTOR_PKT_MODE;
+               return bnxt_recv_pkts;
+       }
+
 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
 #ifndef RTE_LIBRTE_IEEE1588
        /*
@@ -1199,12 +1205,17 @@ bnxt_receive_function(struct rte_eth_dev *eth_dev)
 }
 
 static eth_tx_burst_t
-bnxt_transmit_function(__rte_unused struct rte_eth_dev *eth_dev)
+bnxt_transmit_function(struct rte_eth_dev *eth_dev)
 {
+       struct bnxt *bp = eth_dev->data->dev_private;
+
+       /* Disable vector mode TX for Stingray2 for now */
+       if (BNXT_CHIP_SR2(bp))
+               return bnxt_xmit_pkts;
+
 #if defined(RTE_ARCH_X86) || defined(RTE_ARCH_ARM64)
 #ifndef RTE_LIBRTE_IEEE1588
        uint64_t offloads = eth_dev->data->dev_conf.txmode.offloads;
-       struct bnxt *bp = eth_dev->data->dev_private;
 
        /*
         * Vector mode transmit can be enabled only if not using scatter rx
@@ -1249,80 +1260,6 @@ static int bnxt_handle_if_change_status(struct bnxt *bp)
        return rc;
 }
 
-static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
-{
-       struct bnxt *bp = eth_dev->data->dev_private;
-       uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
-       int vlan_mask = 0;
-       int rc, retry_cnt = BNXT_IF_CHANGE_RETRY_COUNT;
-
-       if (!eth_dev->data->nb_tx_queues || !eth_dev->data->nb_rx_queues) {
-               PMD_DRV_LOG(ERR, "Queues are not configured yet!\n");
-               return -EINVAL;
-       }
-
-       if (bp->rx_cp_nr_rings > RTE_ETHDEV_QUEUE_STAT_CNTRS)
-               PMD_DRV_LOG(ERR,
-                           "RxQ cnt %d > RTE_ETHDEV_QUEUE_STAT_CNTRS %d\n",
-                           bp->rx_cp_nr_rings, RTE_ETHDEV_QUEUE_STAT_CNTRS);
-
-       do {
-               rc = bnxt_hwrm_if_change(bp, true);
-               if (rc == 0 || rc != -EAGAIN)
-                       break;
-
-               rte_delay_ms(BNXT_IF_CHANGE_RETRY_INTERVAL);
-       } while (retry_cnt--);
-
-       if (rc)
-               return rc;
-
-       if (bp->flags & BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE) {
-               rc = bnxt_handle_if_change_status(bp);
-               if (rc)
-                       return rc;
-       }
-
-       bnxt_enable_int(bp);
-
-       rc = bnxt_init_chip(bp);
-       if (rc)
-               goto error;
-
-       eth_dev->data->scattered_rx = bnxt_scattered_rx(eth_dev);
-       eth_dev->data->dev_started = 1;
-
-       bnxt_link_update_op(eth_dev, 1);
-
-       if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
-               vlan_mask |= ETH_VLAN_FILTER_MASK;
-       if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
-               vlan_mask |= ETH_VLAN_STRIP_MASK;
-       rc = bnxt_vlan_offload_set_op(eth_dev, vlan_mask);
-       if (rc)
-               goto error;
-
-       /* Initialize bnxt ULP port details */
-       rc = bnxt_ulp_port_init(bp);
-       if (rc)
-               goto error;
-
-       eth_dev->rx_pkt_burst = bnxt_receive_function(eth_dev);
-       eth_dev->tx_pkt_burst = bnxt_transmit_function(eth_dev);
-
-       bnxt_schedule_fw_health_check(bp);
-
-       return 0;
-
-error:
-       bnxt_shutdown_nic(bp);
-       bnxt_free_tx_mbufs(bp);
-       bnxt_free_rx_mbufs(bp);
-       bnxt_hwrm_if_change(bp, false);
-       eth_dev->data->dev_started = 0;
-       return rc;
-}
-
 static int bnxt_dev_set_link_up_op(struct rte_eth_dev *eth_dev)
 {
        struct bnxt *bp = eth_dev->data->dev_private;
@@ -1360,8 +1297,7 @@ static void bnxt_free_switch_domain(struct bnxt *bp)
        }
 }
 
-/* Unload the driver, release resources */
-static int bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
+static int bnxt_dev_stop(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);
@@ -1429,6 +1365,105 @@ static int bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
        return 0;
 }
 
+/* Unload the driver, release resources */
+static int bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
+{
+       struct bnxt *bp = eth_dev->data->dev_private;
+
+       pthread_mutex_lock(&bp->err_recovery_lock);
+       if (bp->flags & BNXT_FLAG_FW_RESET) {
+               PMD_DRV_LOG(ERR,
+                           "Adapter recovering from error..Please retry\n");
+               return -EAGAIN;
+       }
+       pthread_mutex_unlock(&bp->err_recovery_lock);
+
+       return bnxt_dev_stop(eth_dev);
+}
+
+static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
+{
+       struct bnxt *bp = eth_dev->data->dev_private;
+       uint64_t rx_offloads = eth_dev->data->dev_conf.rxmode.offloads;
+       int vlan_mask = 0;
+       int rc, retry_cnt = BNXT_IF_CHANGE_RETRY_COUNT;
+
+       if (!eth_dev->data->nb_tx_queues || !eth_dev->data->nb_rx_queues) {
+               PMD_DRV_LOG(ERR, "Queues are not configured yet!\n");
+               return -EINVAL;
+       }
+
+       if (bp->rx_cp_nr_rings > RTE_ETHDEV_QUEUE_STAT_CNTRS)
+               PMD_DRV_LOG(ERR,
+                           "RxQ cnt %d > RTE_ETHDEV_QUEUE_STAT_CNTRS %d\n",
+                           bp->rx_cp_nr_rings, RTE_ETHDEV_QUEUE_STAT_CNTRS);
+
+       do {
+               rc = bnxt_hwrm_if_change(bp, true);
+               if (rc == 0 || rc != -EAGAIN)
+                       break;
+
+               rte_delay_ms(BNXT_IF_CHANGE_RETRY_INTERVAL);
+       } while (retry_cnt--);
+
+       if (rc)
+               return rc;
+
+       if (bp->flags & BNXT_FLAG_IF_CHANGE_HOT_FW_RESET_DONE) {
+               rc = bnxt_handle_if_change_status(bp);
+               if (rc)
+                       return rc;
+       }
+
+       bnxt_enable_int(bp);
+
+       rc = bnxt_init_chip(bp);
+       if (rc)
+               goto error;
+
+       eth_dev->data->scattered_rx = bnxt_scattered_rx(eth_dev);
+       eth_dev->data->dev_started = 1;
+
+       bnxt_link_update_op(eth_dev, 1);
+
+       if (rx_offloads & DEV_RX_OFFLOAD_VLAN_FILTER)
+               vlan_mask |= ETH_VLAN_FILTER_MASK;
+       if (rx_offloads & DEV_RX_OFFLOAD_VLAN_STRIP)
+               vlan_mask |= ETH_VLAN_STRIP_MASK;
+       rc = bnxt_vlan_offload_set_op(eth_dev, vlan_mask);
+       if (rc)
+               goto error;
+
+       /* Initialize bnxt ULP port details */
+       rc = bnxt_ulp_port_init(bp);
+       if (rc)
+               goto error;
+
+       eth_dev->rx_pkt_burst = bnxt_receive_function(eth_dev);
+       eth_dev->tx_pkt_burst = bnxt_transmit_function(eth_dev);
+
+       bnxt_schedule_fw_health_check(bp);
+
+       return 0;
+
+error:
+       bnxt_dev_stop(eth_dev);
+       return rc;
+}
+
+static void
+bnxt_uninit_locks(struct bnxt *bp)
+{
+       pthread_mutex_destroy(&bp->flow_lock);
+       pthread_mutex_destroy(&bp->def_cp_lock);
+       pthread_mutex_destroy(&bp->health_check_lock);
+       pthread_mutex_destroy(&bp->err_recovery_lock);
+       if (bp->rep_info) {
+               pthread_mutex_destroy(&bp->rep_info->vfr_lock);
+               pthread_mutex_destroy(&bp->rep_info->vfr_start_lock);
+       }
+}
+
 static int bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
 {
        struct bnxt *bp = eth_dev->data->dev_private;
@@ -1437,13 +1472,21 @@ static int bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
        if (rte_eal_process_type() != RTE_PROC_PRIMARY)
                return 0;
 
+       pthread_mutex_lock(&bp->err_recovery_lock);
+       if (bp->flags & BNXT_FLAG_FW_RESET) {
+               PMD_DRV_LOG(ERR,
+                           "Adapter recovering from error...Please retry\n");
+               return -EAGAIN;
+       }
+       pthread_mutex_unlock(&bp->err_recovery_lock);
+
        /* cancel the recovery handler before remove dev */
        rte_eal_alarm_cancel(bnxt_dev_reset_and_resume, (void *)bp);
        rte_eal_alarm_cancel(bnxt_dev_recover, (void *)bp);
        bnxt_cancel_fc_thread(bp);
 
        if (eth_dev->data->dev_started)
-               ret = bnxt_dev_stop_op(eth_dev);
+               ret = bnxt_dev_stop(eth_dev);
 
        bnxt_free_switch_domain(bp);
 
@@ -1454,6 +1497,7 @@ static int bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
        bnxt_free_link_info(bp);
        bnxt_free_pf_info(bp);
        bnxt_free_parent_info(bp);
+       bnxt_uninit_locks(bp);
 
        rte_memzone_free((const struct rte_memzone *)bp->tx_mem_zone);
        bp->tx_mem_zone = NULL;
@@ -3656,7 +3700,7 @@ static void bnxt_dev_cleanup(struct bnxt *bp)
        bp->eth_dev->data->dev_link.link_status = 0;
        bp->link_info->link_up = 0;
        if (bp->eth_dev->data->dev_started)
-               bnxt_dev_stop_op(bp->eth_dev);
+               bnxt_dev_stop(bp->eth_dev);
 
        bnxt_uninit_resources(bp, true);
 }
@@ -3757,6 +3801,7 @@ static void bnxt_dev_recover(void *arg)
        int timeout = bp->fw_reset_max_msecs;
        int rc = 0;
 
+       pthread_mutex_lock(&bp->err_recovery_lock);
        /* Clear Error flag so that device re-init should happen */
        bp->flags &= ~BNXT_FLAG_FATAL_ERROR;
 
@@ -3793,12 +3838,15 @@ static void bnxt_dev_recover(void *arg)
                goto err_start;
 
        PMD_DRV_LOG(INFO, "Recovered from FW reset\n");
+       pthread_mutex_unlock(&bp->err_recovery_lock);
+
        return;
 err_start:
-       bnxt_dev_stop_op(bp->eth_dev);
+       bnxt_dev_stop(bp->eth_dev);
 err:
        bp->flags |= BNXT_FLAG_FATAL_ERROR;
        bnxt_uninit_resources(bp, false);
+       pthread_mutex_unlock(&bp->err_recovery_lock);
        PMD_DRV_LOG(ERR, "Failed to recover from FW reset\n");
 }
 
@@ -4755,8 +4803,15 @@ bnxt_init_locks(struct bnxt *bp)
        }
 
        err = pthread_mutex_init(&bp->health_check_lock, NULL);
-       if (err)
+       if (err) {
                PMD_DRV_LOG(ERR, "Unable to initialize health_check_lock\n");
+               return err;
+       }
+
+       err = pthread_mutex_init(&bp->err_recovery_lock, NULL);
+       if (err)
+               PMD_DRV_LOG(ERR, "Unable to initialize err_recovery_lock\n");
+
        return err;
 }
 
@@ -4821,10 +4876,6 @@ static int bnxt_init_resources(struct bnxt *bp, bool reconfig_dev)
                return rc;
        }
 
-       rc = bnxt_init_locks(bp);
-       if (rc)
-               return rc;
-
        return 0;
 }
 
@@ -5311,6 +5362,10 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev, void *params __rte_unused)
        if (rc)
                goto error_free;
 
+       rc = bnxt_init_locks(bp);
+       if (rc)
+               goto error_free;
+
        rc = bnxt_init_resources(bp, false);
        if (rc)
                goto error_free;
@@ -5402,18 +5457,6 @@ bnxt_free_error_recovery_info(struct bnxt *bp)
        bp->fw_cap &= ~BNXT_FW_CAP_ERROR_RECOVERY;
 }
 
-static void
-bnxt_uninit_locks(struct bnxt *bp)
-{
-       pthread_mutex_destroy(&bp->flow_lock);
-       pthread_mutex_destroy(&bp->def_cp_lock);
-       pthread_mutex_destroy(&bp->health_check_lock);
-       if (bp->rep_info) {
-               pthread_mutex_destroy(&bp->rep_info->vfr_lock);
-               pthread_mutex_destroy(&bp->rep_info->vfr_start_lock);
-       }
-}
-
 static int
 bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev)
 {
@@ -5435,7 +5478,6 @@ bnxt_uninit_resources(struct bnxt *bp, bool reconfig_dev)
 
        bnxt_uninit_ctx_mem(bp);
 
-       bnxt_uninit_locks(bp);
        bnxt_free_flow_stats_info(bp);
        bnxt_free_rep_info(bp);
        rte_free(bp->ptp_cfg);