DPDK patches and discussions
 help / color / mirror / Atom feed
From: Heinrich Kuhn <heinrich.kuhn@netronome.com>
To: dev@dpdk.org
Cc: Heinrich Kuhn <heinrich.kuhn@netronome.com>,
	Louis Peens <louis.peens@netronome.com>,
	Simon Horman <simon.horman@netronome.com>
Subject: [dpdk-dev] [PATCH 2/2] net/nfp: free port private data in dev close callback
Date: Tue, 19 Jan 2021 13:56:17 +0200	[thread overview]
Message-ID: <20210119115616.1807-3-heinrich.kuhn@netronome.com> (raw)
In-Reply-To: <20210119115616.1807-1-heinrich.kuhn@netronome.com>

Free the private data of a port when the .dev_close() callback is
invoked. For NFP6000/4000 devices multiple ports may exist under a
single PF device. In this situation the PF resources will only be freed
when all the ports associated with the PF has been freed too.

PF hot plugging isn't explicitly supported for NFP6000/4000 devices but
all the private data of all the ports under the PF in question will be
freed upon device removal.

Signed-off-by: Heinrich Kuhn <heinrich.kuhn@netronome.com>
Reviewed-by: Louis Peens <louis.peens@netronome.com>
Signed-off-by: Simon Horman <simon.horman@netronome.com>
---
 drivers/net/nfp/nfp_net.c | 63 ++++++++++++++++++++++++++++++++-------
 1 file changed, 52 insertions(+), 11 deletions(-)

diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index 9b9bd9e3d..b2cebf3e7 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -59,6 +59,7 @@ static int nfp_net_infos_get(struct rte_eth_dev *dev,
 			     struct rte_eth_dev_info *dev_info);
 static int nfp_net_init(struct rte_eth_dev *eth_dev);
 static int nfp_pf_init(struct rte_eth_dev *eth_dev);
+static int nfp_pci_uninit(struct rte_eth_dev *eth_dev);
 static int nfp_init_phyports(struct nfp_pf_dev *pf_dev);
 static int nfp_net_link_update(struct rte_eth_dev *dev, int wait_to_complete);
 static int nfp_net_promisc_enable(struct rte_eth_dev *dev);
@@ -909,8 +910,34 @@ nfp_net_close(struct rte_eth_dev *dev)
 			(struct nfp_net_rxq *)dev->data->rx_queues[i]);
 	}
 
+	/* Only free PF resources after all physical ports have been closed */
+	if (pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC ||
+	    pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC) {
+		struct nfp_pf_dev *pf_dev;
+		pf_dev = NFP_NET_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+		/* Mark this port as unused and free device priv resources*/
+		nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
+		pf_dev->ports[hw->idx] = NULL;
+		rte_eth_dev_release_port(dev);
+
+		for (i = 0; i < pf_dev->total_phyports; i++) {
+			/* Check to see if ports are still in use */
+			if (pf_dev->ports[i])
+				return 0;
+		}
+
+		/* Now it is safe to free all PF resources */
+		PMD_INIT_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(pf_dev);
+	}
+
 	rte_intr_disable(&pci_dev->intr_handle);
-	nn_cfg_writeb(hw, NFP_NET_CFG_LSC, 0xff);
 
 	/* unregister callback func from eal lib */
 	rte_intr_callback_unregister(&pci_dev->intr_handle,
@@ -3765,6 +3792,29 @@ static const struct rte_pci_id pci_id_nfp_vf_net_map[] = {
 	},
 };
 
+static int nfp_pci_uninit(struct rte_eth_dev *eth_dev)
+{
+	struct rte_pci_device *pci_dev;
+	uint16_t port_id;
+
+	pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+
+	if (pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC ||
+	    pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC) {
+		/* Free up all physical ports under PF */
+		RTE_ETH_FOREACH_DEV_OF(port_id, &pci_dev->device)
+			rte_eth_dev_close(port_id);
+		/*
+		 * Ports can be closed and freed but hotplugging is not
+		 * currently supported
+		 */
+		return -ENOTSUP;
+	}
+
+	/* VF cleanup, just free private port data */
+	return nfp_net_close(eth_dev);
+}
+
 static int eth_nfp_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 	struct rte_pci_device *pci_dev)
 {
@@ -3774,16 +3824,7 @@ static int eth_nfp_pci_probe(struct rte_pci_driver *pci_drv __rte_unused,
 
 static int eth_nfp_pci_remove(struct rte_pci_device *pci_dev)
 {
-	struct rte_eth_dev *eth_dev;
-
-	eth_dev = rte_eth_dev_allocated(pci_dev->device.name);
-	if (eth_dev == NULL)
-		return 0; /* port already released */
-	if ((pci_dev->id.device_id == PCI_DEVICE_ID_NFP4000_PF_NIC) ||
-	    (pci_dev->id.device_id == PCI_DEVICE_ID_NFP6000_PF_NIC))
-		return -ENOTSUP;
-
-	return rte_eth_dev_pci_generic_remove(pci_dev, NULL);
+	return rte_eth_dev_pci_generic_remove(pci_dev, nfp_pci_uninit);
 }
 
 static struct rte_pci_driver rte_nfp_net_pf_pmd = {
-- 
2.30.0


  parent reply	other threads:[~2021-01-19 11:57 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-01-19 11:56 [dpdk-dev] [PATCH 0/2] free port private data in dev_close callback Heinrich Kuhn
2021-01-19 11:56 ` [dpdk-dev] [PATCH 1/2] net/nfp: create a separate entity for a NFP PF device Heinrich Kuhn
2021-01-19 11:56 ` Heinrich Kuhn [this message]
2021-01-27 22:45 ` [dpdk-dev] [PATCH 0/2] free port private data in dev_close callback Ferruh Yigit

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=20210119115616.1807-3-heinrich.kuhn@netronome.com \
    --to=heinrich.kuhn@netronome.com \
    --cc=dev@dpdk.org \
    --cc=louis.peens@netronome.com \
    --cc=simon.horman@netronome.com \
    /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).