net/bnxt: fix crash when closing
[dpdk.git] / drivers / net / bnxt / bnxt_ethdev.c
index 4099a5e..4e6fa51 100644 (file)
@@ -428,6 +428,7 @@ static int bnxt_dev_start_op(struct rte_eth_dev *eth_dev)
        struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
        int rc;
 
+       bp->dev_stopped = 0;
        rc = bnxt_hwrm_func_reset(bp);
        if (rc) {
                RTE_LOG(ERR, PMD, "hwrm chip reset failure rc: %x\n", rc);
@@ -471,10 +472,27 @@ static int bnxt_dev_set_link_down_op(struct rte_eth_dev *eth_dev)
        return 0;
 }
 
+/* Unload the driver, release resources */
+static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
+{
+       struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
+
+       if (bp->eth_dev->data->dev_started) {
+               /* TBD: STOP HW queues DMA */
+               eth_dev->data->dev_link.link_status = 0;
+       }
+       bnxt_set_hwrm_link_config(bp, false);
+       bnxt_shutdown_nic(bp);
+       bp->dev_stopped = 1;
+}
+
 static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
 {
        struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
 
+       if (bp->dev_stopped == 0)
+               bnxt_dev_stop_op(eth_dev);
+
        bnxt_free_tx_mbufs(bp);
        bnxt_free_rx_mbufs(bp);
        bnxt_free_mem(bp);
@@ -488,18 +506,6 @@ static void bnxt_dev_close_op(struct rte_eth_dev *eth_dev)
        }
 }
 
-/* Unload the driver, release resources */
-static void bnxt_dev_stop_op(struct rte_eth_dev *eth_dev)
-{
-       struct bnxt *bp = (struct bnxt *)eth_dev->data->dev_private;
-
-       if (bp->eth_dev->data->dev_started) {
-               /* TBD: STOP HW queues DMA */
-               eth_dev->data->dev_link.link_status = 0;
-       }
-       bnxt_shutdown_nic(bp);
-}
-
 static void bnxt_mac_addr_remove_op(struct rte_eth_dev *eth_dev,
                                    uint32_t index)
 {
@@ -1078,6 +1084,8 @@ bnxt_dev_init(struct rte_eth_dev *eth_dev)
                eth_dev->pci_dev->mem_resource[0].phys_addr,
                eth_dev->pci_dev->mem_resource[0].addr);
 
+       bp->dev_stopped = 0;
+
        return 0;
 
 error_free:
@@ -1101,6 +1109,8 @@ bnxt_dev_uninit(struct rte_eth_dev *eth_dev) {
        }
        rc = bnxt_hwrm_func_driver_unregister(bp, 0);
        bnxt_free_hwrm_resources(bp);
+       if (bp->dev_stopped == 0)
+               bnxt_dev_close_op(eth_dev);
        eth_dev->dev_ops = NULL;
        eth_dev->rx_pkt_burst = NULL;
        eth_dev->tx_pkt_burst = NULL;