From 11df4a688de1949ce480822665ad84685b9945a3 Mon Sep 17 00:00:00 2001 From: Rahul Lakkireddy Date: Tue, 1 Sep 2020 22:46:26 +0530 Subject: [PATCH] net/cxgbe: release port resources during port close 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 --- drivers/net/cxgbe/cxgbe_ethdev.c | 28 ++++++++++++++++++++++++---- drivers/net/cxgbe/cxgbe_main.c | 12 ++---------- drivers/net/cxgbe/cxgbevf_ethdev.c | 8 +++++--- drivers/net/cxgbe/cxgbevf_main.c | 2 ++ 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/drivers/net/cxgbe/cxgbe_ethdev.c b/drivers/net/cxgbe/cxgbe_ethdev.c index a2c49cb47c..38b43772c7 100644 --- a/drivers/net/cxgbe/cxgbe_ethdev.c +++ b/drivers/net/cxgbe/cxgbe_ethdev.c @@ -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; } diff --git a/drivers/net/cxgbe/cxgbe_main.c b/drivers/net/cxgbe/cxgbe_main.c index 2656369c5f..d0a64229cd 100644 --- a/drivers/net/cxgbe/cxgbe_main.c +++ b/drivers/net/cxgbe/cxgbe_main.c @@ -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); diff --git a/drivers/net/cxgbe/cxgbevf_ethdev.c b/drivers/net/cxgbe/cxgbevf_ethdev.c index 4165ba986d..b3c885d6e1 100644 --- a/drivers/net/cxgbe/cxgbevf_ethdev.c +++ b/drivers/net/cxgbe/cxgbevf_ethdev.c @@ -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; } diff --git a/drivers/net/cxgbe/cxgbevf_main.c b/drivers/net/cxgbe/cxgbevf_main.c index 66fb923756..9fe0ec6f6e 100644 --- a/drivers/net/cxgbe/cxgbevf_main.c +++ b/drivers/net/cxgbe/cxgbevf_main.c @@ -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); -- 2.20.1