net/cxgbe: release port resources during port close
authorRahul Lakkireddy <rahul.lakkireddy@chelsio.com>
Tue, 1 Sep 2020 17:16:26 +0000 (22:46 +0530)
committerFerruh Yigit <ferruh.yigit@intel.com>
Fri, 18 Sep 2020 16:55:12 +0000 (18:55 +0200)
Enable RTE_ETH_DEV_CLOSE_REMOVE during PCI probe for all ports
enumerated under the PF. Free up the underlying port Virtual
Identifier (VI) and associated resources during port close.
Once all the ports under the PF are closed, free up the PF-wide
shared resources. Invoke port close function of all ports under
the PF, in PCI remove too.

Signed-off-by: Rahul Lakkireddy <rahul.lakkireddy@chelsio.com>
drivers/net/cxgbe/cxgbe_ethdev.c
drivers/net/cxgbe/cxgbe_main.c
drivers/net/cxgbe/cxgbevf_ethdev.c
drivers/net/cxgbe/cxgbevf_main.c

index a2c49cb..38b4377 100644 (file)
@@ -321,16 +321,34 @@ int cxgbe_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
  */
 void cxgbe_dev_close(struct rte_eth_dev *eth_dev)
 {
-       struct port_info *pi = eth_dev->data->dev_private;
+       struct port_info *temp_pi, *pi = eth_dev->data->dev_private;
        struct adapter *adapter = pi->adapter;
+       u8 i;
 
        CXGBE_FUNC_TRACE();
 
        if (!(adapter->flags & FULL_INIT_DONE))
                return;
 
+       if (!pi->viid)
+               return;
+
        cxgbe_down(pi);
        t4_sge_eth_release_queues(pi);
+       t4_free_vi(adapter, adapter->mbox, adapter->pf, 0, pi->viid);
+       pi->viid = 0;
+
+       /* Free up the adapter-wide resources only after all the ports
+        * under this PF have been closed.
+        */
+       for_each_port(adapter, i) {
+               temp_pi = adap2pinfo(adapter, i);
+               if (temp_pi->viid)
+                       return;
+       }
+
+       cxgbe_close(adapter);
+       rte_free(adapter);
 }
 
 /* Start the device.
@@ -1208,11 +1226,13 @@ out_free_adapter:
 
 static int eth_cxgbe_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-       struct port_info *pi = eth_dev->data->dev_private;
-       struct adapter *adap = pi->adapter;
+       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+       uint16_t port_id;
 
        /* Free up other ports and all resources */
-       cxgbe_close(adap);
+       RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device)
+               rte_eth_dev_close(port_id);
+
        return 0;
 }
 
index 2656369..d0a6422 100644 (file)
@@ -1975,9 +1975,6 @@ int cxgbe_down(struct port_info *pi)
  */
 void cxgbe_close(struct adapter *adapter)
 {
-       struct port_info *pi;
-       int i;
-
        if (adapter->flags & FULL_INIT_DONE) {
                tid_free(&adapter->tids);
                t4_cleanup_mpstcam(adapter);
@@ -1988,13 +1985,6 @@ void cxgbe_close(struct adapter *adapter)
                        t4_intr_disable(adapter);
                t4_sge_tx_monitor_stop(adapter);
                t4_free_sge_resources(adapter);
-               for_each_port(adapter, i) {
-                       pi = adap2pinfo(adapter, i);
-                       if (pi->viid != 0)
-                               t4_free_vi(adapter, adapter->mbox,
-                                          adapter->pf, 0, pi->viid);
-                       rte_eth_dev_release_port(pi->eth_dev);
-               }
                adapter->flags &= ~FULL_INIT_DONE;
        }
 
@@ -2156,6 +2146,8 @@ allocate_mac:
                        goto out_free;
                }
 
+               pi->eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+
                if (i > 0) {
                        /* First port will be notified by upper layer */
                        rte_eth_dev_probing_finish(eth_dev);
index 4165ba9..b3c885d 100644 (file)
@@ -181,11 +181,13 @@ out_free_adapter:
 
 static int eth_cxgbevf_dev_uninit(struct rte_eth_dev *eth_dev)
 {
-       struct port_info *pi = eth_dev->data->dev_private;
-       struct adapter *adap = pi->adapter;
+       struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+       uint16_t port_id;
 
        /* Free up other ports and all resources */
-       cxgbe_close(adap);
+       RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device)
+               rte_eth_dev_close(port_id);
+
        return 0;
 }
 
index 66fb923..9fe0ec6 100644 (file)
@@ -261,6 +261,8 @@ allocate_mac:
                        goto out_free;
                }
 
+               pi->eth_dev->data->dev_flags |= RTE_ETH_DEV_CLOSE_REMOVE;
+
                if (i > 0) {
                        /* First port will be notified by upper layer */
                        rte_eth_dev_probing_finish(eth_dev);