From: Chaoyong He <chaoyong.he@corigine.com>
To: stable@dpdk.org
Cc: oss-drivers@corigine.com, Chaoyong He <chaoyong.he@corigine.com>
Subject: [PATCH 22.11 v2 4/7] net/nfp: fix resource leak for exit of flower firmware
Date: Thu, 7 Mar 2024 19:20:20 +0800 [thread overview]
Message-ID: <20240307112023.1867765-5-chaoyong.he@corigine.com> (raw)
In-Reply-To: <20240307112023.1867765-1-chaoyong.he@corigine.com>
[ upstream commit a256a1227dbe0eac576a42b6c336ce55b7713109 ]
Fix the resource leak problem in the exit logic of flower firmware.
Fixes: e1124c4f8a45 ("net/nfp: add flower representor framework")
Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
---
drivers/net/nfp/flower/nfp_flower.c | 70 ++++---------------
drivers/net/nfp/flower/nfp_flower.h | 1 +
.../net/nfp/flower/nfp_flower_representor.c | 64 +++++++++++++++++
3 files changed, 79 insertions(+), 56 deletions(-)
diff --git a/drivers/net/nfp/flower/nfp_flower.c b/drivers/net/nfp/flower/nfp_flower.c
index 5896d20..28be1b9 100644
--- a/drivers/net/nfp/flower/nfp_flower.c
+++ b/drivers/net/nfp/flower/nfp_flower.c
@@ -182,61 +182,6 @@ nfp_flower_pf_stop(struct rte_eth_dev *dev)
return 0;
}
-/* Reset and stop device. The device can not be restarted. */
-static int
-nfp_flower_pf_close(struct rte_eth_dev *dev)
-{
- uint16_t i;
- struct nfp_net_hw *hw;
- struct nfp_pf_dev *pf_dev;
- struct nfp_net_txq *this_tx_q;
- struct nfp_net_rxq *this_rx_q;
- struct nfp_flower_representor *repr;
- struct nfp_app_fw_flower *app_fw_flower;
-
- if (rte_eal_process_type() != RTE_PROC_PRIMARY)
- return 0;
-
- repr = (struct nfp_flower_representor *)dev->data->dev_private;
- hw = repr->app_fw_flower->pf_hw;
- pf_dev = hw->pf_dev;
- app_fw_flower = NFP_PRIV_TO_APP_FW_FLOWER(pf_dev->app_fw_priv);
-
- /*
- * We assume that the DPDK application is stopping all the
- * threads/queues before calling the device close function.
- */
- nfp_pf_repr_disable_queues(dev);
-
- /* Clear queues */
- for (i = 0; i < dev->data->nb_tx_queues; i++) {
- this_tx_q = (struct nfp_net_txq *)dev->data->tx_queues[i];
- nfp_net_reset_tx_queue(this_tx_q);
- }
-
- for (i = 0; i < dev->data->nb_rx_queues; i++) {
- this_rx_q = (struct nfp_net_rxq *)dev->data->rx_queues[i];
- nfp_net_reset_rx_queue(this_rx_q);
- }
-
- /* Cancel possible impending LSC work here before releasing the port*/
- rte_eal_alarm_cancel(nfp_net_dev_interrupt_delayed_handler, (void *)dev);
-
- nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
-
- /* Now it is safe to free all PF resources */
- PMD_DRV_LOG(INFO, "Freeing PF resources");
- nfp_cpp_area_free(pf_dev->ctrl_area);
- nfp_cpp_area_free(pf_dev->hwqueues_area);
- free(pf_dev->hwinfo);
- free(pf_dev->sym_tbl);
- nfp_cpp_free(pf_dev->cpp);
- rte_free(app_fw_flower);
- rte_free(pf_dev);
-
- return 0;
-}
-
static const struct eth_dev_ops nfp_flower_pf_vnic_ops = {
.dev_infos_get = nfp_net_infos_get,
.link_update = nfp_net_link_update,
@@ -244,7 +189,6 @@ static const struct eth_dev_ops nfp_flower_pf_vnic_ops = {
.dev_start = nfp_flower_pf_start,
.dev_stop = nfp_flower_pf_stop,
- .dev_close = nfp_flower_pf_close,
};
static inline void
@@ -1221,6 +1165,20 @@ nfp_init_app_fw_flower(struct nfp_pf_dev *pf_dev)
return ret;
}
+void
+nfp_uninit_app_fw_flower(struct nfp_pf_dev *pf_dev)
+{
+ struct nfp_app_fw_flower *app_fw_flower;
+
+ app_fw_flower = pf_dev->app_fw_priv;
+ nfp_flower_cleanup_ctrl_vnic(app_fw_flower->ctrl_hw);
+ nfp_cpp_area_free(app_fw_flower->ctrl_hw->ctrl_area);
+ nfp_cpp_area_free(pf_dev->ctrl_area);
+ rte_free(app_fw_flower->pf_hw);
+ nfp_flow_priv_uninit(pf_dev);
+ rte_free(app_fw_flower);
+}
+
int
nfp_secondary_init_app_fw_flower(struct nfp_cpp *cpp)
{
diff --git a/drivers/net/nfp/flower/nfp_flower.h b/drivers/net/nfp/flower/nfp_flower.h
index c05a761..d82e35f 100644
--- a/drivers/net/nfp/flower/nfp_flower.h
+++ b/drivers/net/nfp/flower/nfp_flower.h
@@ -85,6 +85,7 @@ nfp_flower_support_decap_v2(const struct nfp_app_fw_flower *app_fw_flower)
}
int nfp_init_app_fw_flower(struct nfp_pf_dev *pf_dev);
+void nfp_uninit_app_fw_flower(struct nfp_pf_dev *pf_dev);
int nfp_secondary_init_app_fw_flower(struct nfp_cpp *cpp);
uint16_t nfp_flower_pf_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
uint16_t nb_pkts);
diff --git a/drivers/net/nfp/flower/nfp_flower_representor.c b/drivers/net/nfp/flower/nfp_flower_representor.c
index 3ff54a9..b3359d3 100644
--- a/drivers/net/nfp/flower/nfp_flower_representor.c
+++ b/drivers/net/nfp/flower/nfp_flower_representor.c
@@ -561,12 +561,75 @@ nfp_flower_repr_free(struct nfp_flower_representor *repr,
}
}
+/* Reset and stop device. The device can not be restarted. */
+static int
+nfp_flower_repr_dev_close(struct rte_eth_dev *dev)
+{
+ uint16_t i;
+ struct nfp_net_hw *hw;
+ struct nfp_pf_dev *pf_dev;
+ struct nfp_net_txq *this_tx_q;
+ struct nfp_net_rxq *this_rx_q;
+ struct nfp_flower_representor *repr;
+ struct nfp_app_fw_flower *app_fw_flower;
+
+ if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+ return 0;
+
+ repr = dev->data->dev_private;
+ app_fw_flower = repr->app_fw_flower;
+ hw = app_fw_flower->pf_hw;
+ pf_dev = hw->pf_dev;
+
+ /*
+ * We assume that the DPDK application is stopping all the
+ * threads/queues before calling the device close function.
+ */
+ nfp_net_disable_queues(dev);
+
+ /* Clear queues */
+ for (i = 0; i < dev->data->nb_tx_queues; i++) {
+ this_tx_q = dev->data->tx_queues[i];
+ nfp_net_reset_tx_queue(this_tx_q);
+ }
+
+ for (i = 0; i < dev->data->nb_rx_queues; i++) {
+ this_rx_q = dev->data->rx_queues[i];
+ nfp_net_reset_rx_queue(this_rx_q);
+ }
+
+ if (pf_dev->app_fw_id != NFP_APP_FW_FLOWER_NIC)
+ return -EINVAL;
+
+ nfp_flower_repr_free(repr, repr->repr_type);
+
+ for (i = 0; i < MAX_FLOWER_VFS; i++) {
+ if (app_fw_flower->vf_reprs[i] != NULL)
+ return 0;
+ }
+
+ for (i = 0; i < MAX_FLOWER_PHYPORTS; i++) {
+ if (app_fw_flower->phy_reprs[i] != NULL)
+ return 0;
+ }
+
+ if (app_fw_flower->pf_repr != NULL)
+ return 0;
+
+ /* Now it is safe to free all PF resources */
+ nfp_uninit_app_fw_flower(pf_dev);
+ nfp_pf_uninit(pf_dev);
+
+ return 0;
+}
+
static const struct eth_dev_ops nfp_flower_pf_repr_dev_ops = {
.dev_infos_get = nfp_flower_repr_dev_infos_get,
.dev_start = nfp_flower_pf_start,
.dev_configure = nfp_flower_repr_dev_configure,
.dev_stop = nfp_flower_pf_stop,
+ .dev_close = nfp_flower_repr_dev_close,
.rx_queue_setup = nfp_pf_repr_rx_queue_setup,
.tx_queue_setup = nfp_pf_repr_tx_queue_setup,
@@ -588,6 +651,7 @@ static const struct eth_dev_ops nfp_flower_repr_dev_ops = {
.dev_start = nfp_flower_repr_dev_start,
.dev_configure = nfp_flower_repr_dev_configure,
.dev_stop = nfp_flower_repr_dev_stop,
+ .dev_close = nfp_flower_repr_dev_close,
.rx_queue_setup = nfp_flower_repr_rx_queue_setup,
.tx_queue_setup = nfp_flower_repr_tx_queue_setup,
--
2.39.1
next prev parent reply other threads:[~2024-03-07 11:20 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-07 11:20 [PATCH 22.11 v2 0/7] backport patch series from NFP PMD Chaoyong He
2024-03-07 11:20 ` [PATCH 22.11 v2 1/7] net/nfp: fix resource leak for CoreNIC firmware Chaoyong He
2024-03-07 11:20 ` [PATCH 22.11 v2 2/7] net/nfp: fix resource leak for flower firmware Chaoyong He
2024-03-07 11:20 ` [PATCH 22.11 v2 3/7] net/nfp: fix resource leak for exit of CoreNIC firmware Chaoyong He
2024-03-07 11:20 ` Chaoyong He [this message]
2024-03-07 11:20 ` [PATCH 22.11 v2 5/7] net/nfp: fix device close Chaoyong He
2024-03-07 11:20 ` [PATCH 22.11 v2 6/7] net/nfp: fix device resource freeing Chaoyong He
2024-03-07 11:20 ` [PATCH 22.11 v2 7/7] net/nfp: free switch domain ID on close Chaoyong He
2024-03-07 12:45 ` [PATCH 22.11 v2 0/7] backport patch series from NFP PMD Luca Boccassi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240307112023.1867765-5-chaoyong.he@corigine.com \
--to=chaoyong.he@corigine.com \
--cc=oss-drivers@corigine.com \
--cc=stable@dpdk.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).