[PATCH 2/8] net: octeontx2: Use pure PCI devres API

Philipp Stanner posted 8 patches 9 months, 4 weeks ago
[PATCH 2/8] net: octeontx2: Use pure PCI devres API
Posted by Philipp Stanner 9 months, 4 weeks ago
The currently used function pci_request_regions() is one of the
problematic "hybrid devres" PCI functions, which are sometimes managed
through devres, and sometimes not (depending on whether
pci_enable_device() or pcim_enable_device() has been called before).

The PCI subsystem wants to remove this behavior and, therefore, needs to
port all users to functions that don't have this problem.

Furthermore, the PCI function being managed implies that it's not
necessary to call pci_release_regions() manually.

Remove the calls to pci_release_regions().

Replace pci_request_regions() with pcim_request_all_regions().

Signed-off-by: Philipp Stanner <phasta@kernel.org>
---
 .../net/ethernet/marvell/octeontx2/nic/otx2_pf.c   | 14 ++++----------
 .../net/ethernet/marvell/octeontx2/nic/otx2_vf.c   | 14 ++++----------
 drivers/net/ethernet/marvell/octeontx2/nic/rep.c   |  4 +---
 3 files changed, 9 insertions(+), 23 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
index cfed9ec5b157..0aee8e3861f3 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c
@@ -3048,7 +3048,7 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		return err;
 	}
 
-	err = pci_request_regions(pdev, DRV_NAME);
+	err = pcim_request_all_regions(pdev, DRV_NAME);
 	if (err) {
 		dev_err(dev, "PCI request regions failed 0x%x\n", err);
 		return err;
@@ -3057,7 +3057,7 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
 	if (err) {
 		dev_err(dev, "DMA mask config failed, abort\n");
-		goto err_release_regions;
+		return err;
 	}
 
 	pci_set_master(pdev);
@@ -3067,10 +3067,8 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	qos_txqs = min_t(int, qcount, OTX2_QOS_MAX_LEAF_NODES);
 
 	netdev = alloc_etherdev_mqs(sizeof(*pf), qcount + qos_txqs, qcount);
-	if (!netdev) {
-		err = -ENOMEM;
-		goto err_release_regions;
-	}
+	if (!netdev)
+		return -ENOMEM;
 
 	pci_set_drvdata(pdev, netdev);
 	SET_NETDEV_DEV(netdev, &pdev->dev);
@@ -3246,8 +3244,6 @@ static int otx2_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 err_free_netdev:
 	pci_set_drvdata(pdev, NULL);
 	free_netdev(netdev);
-err_release_regions:
-	pci_release_regions(pdev);
 	return err;
 }
 
@@ -3447,8 +3443,6 @@ static void otx2_remove(struct pci_dev *pdev)
 	pci_free_irq_vectors(pf->pdev);
 	pci_set_drvdata(pdev, NULL);
 	free_netdev(netdev);
-
-	pci_release_regions(pdev);
 }
 
 static struct pci_driver otx2_pf_driver = {
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
index 7ef3ba477d49..fb4da816d218 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c
@@ -548,7 +548,7 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		return err;
 	}
 
-	err = pci_request_regions(pdev, DRV_NAME);
+	err = pcim_request_all_regions(pdev, DRV_NAME);
 	if (err) {
 		dev_err(dev, "PCI request regions failed 0x%x\n", err);
 		return err;
@@ -557,7 +557,7 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	err = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
 	if (err) {
 		dev_err(dev, "DMA mask config failed, abort\n");
-		goto err_release_regions;
+		return err;
 	}
 
 	pci_set_master(pdev);
@@ -565,10 +565,8 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	qcount = num_online_cpus();
 	qos_txqs = min_t(int, qcount, OTX2_QOS_MAX_LEAF_NODES);
 	netdev = alloc_etherdev_mqs(sizeof(*vf), qcount + qos_txqs, qcount);
-	if (!netdev) {
-		err = -ENOMEM;
-		goto err_release_regions;
-	}
+	if (!netdev)
+		return -ENOMEM;
 
 	pci_set_drvdata(pdev, netdev);
 	SET_NETDEV_DEV(netdev, &pdev->dev);
@@ -765,8 +763,6 @@ static int otx2vf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 err_free_netdev:
 	pci_set_drvdata(pdev, NULL);
 	free_netdev(netdev);
-err_release_regions:
-	pci_release_regions(pdev);
 	return err;
 }
 
@@ -815,8 +811,6 @@ static void otx2vf_remove(struct pci_dev *pdev)
 	pci_free_irq_vectors(vf->pdev);
 	pci_set_drvdata(pdev, NULL);
 	free_netdev(netdev);
-
-	pci_release_regions(pdev);
 }
 
 static struct pci_driver otx2vf_driver = {
diff --git a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
index 04e08e06f30f..516471f172d1 100644
--- a/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
+++ b/drivers/net/ethernet/marvell/octeontx2/nic/rep.c
@@ -763,7 +763,7 @@ static int rvu_rep_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		return err;
 	}
 
-	err = pci_request_regions(pdev, DRV_NAME);
+	err = pcim_request_all_regions(pdev, DRV_NAME);
 	if (err) {
 		dev_err(dev, "PCI request regions failed 0x%x\n", err);
 		return err;
@@ -822,7 +822,6 @@ static int rvu_rep_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	pci_free_irq_vectors(pdev);
 err_release_regions:
 	pci_set_drvdata(pdev, NULL);
-	pci_release_regions(pdev);
 	return err;
 }
 
@@ -842,7 +841,6 @@ static void rvu_rep_remove(struct pci_dev *pdev)
 	otx2_pfaf_mbox_destroy(priv);
 	pci_free_irq_vectors(priv->pdev);
 	pci_set_drvdata(pdev, NULL);
-	pci_release_regions(pdev);
 }
 
 static struct pci_driver rvu_rep_driver = {
-- 
2.48.1
Re: [PATCH 2/8] net: octeontx2: Use pure PCI devres API
Posted by Jakub Kicinski 9 months, 3 weeks ago
On Wed, 16 Apr 2025 18:44:02 +0200 Philipp Stanner wrote:
>  err_release_regions:
>  	pci_set_drvdata(pdev, NULL);
> -	pci_release_regions(pdev);

This error path should be renamed. Could you also apply your conversion
to drivers/net/ethernet/marvell/octeontx2/af/ ?
-- 
pw-bot: cr
Re: [PATCH 2/8] net: octeontx2: Use pure PCI devres API
Posted by Philipp Stanner 9 months, 3 weeks ago
On Tue, 2025-04-22 at 17:49 -0700, Jakub Kicinski wrote:
> On Wed, 16 Apr 2025 18:44:02 +0200 Philipp Stanner wrote:
> >  err_release_regions:
> >  	pci_set_drvdata(pdev, NULL);
> > -	pci_release_regions(pdev);
> 
> This error path should be renamed. Could you also apply your
> conversion
> to drivers/net/ethernet/marvell/octeontx2/af/ ?

Hm, those must have slipped me for some reason. Will reiterate with
them and the error path.

P.
Re: [PATCH 2/8] net: octeontx2: Use pure PCI devres API
Posted by Philipp Stanner 9 months, 3 weeks ago
On Wed, 2025-04-23 at 08:28 +0200, Philipp Stanner wrote:
> On Tue, 2025-04-22 at 17:49 -0700, Jakub Kicinski wrote:
> > On Wed, 16 Apr 2025 18:44:02 +0200 Philipp Stanner wrote:
> > >  err_release_regions:
> > >  	pci_set_drvdata(pdev, NULL);
> > > -	pci_release_regions(pdev);
> > 
> > This error path should be renamed. Could you also apply your
> > conversion
> > to drivers/net/ethernet/marvell/octeontx2/af/ ?
> 
> Hm, those must have slipped me for some reason. Will reiterate with
> them and the error path.

Wait, false alarm. I actually did look at them and those in af/ don't
seem to use the combination of pcim_enable_device() + pci_request_*

Only users of that combination have to be ported. Users of
pci_enable_device() + pcim_* functions and pcim_enable_device() +
pcim_* functions are fine.

Correct me if I missed the first mentioned combination up there.

P.

> 
> P.
> 
Re: [PATCH 2/8] net: octeontx2: Use pure PCI devres API
Posted by Jakub Kicinski 9 months, 3 weeks ago
On Wed, 23 Apr 2025 10:38:01 +0200 Philipp Stanner wrote:
> > > This error path should be renamed. Could you also apply your
> > > conversion
> > > to drivers/net/ethernet/marvell/octeontx2/af/ ?  
> > 
> > Hm, those must have slipped me for some reason. Will reiterate with
> > them and the error path.  
> 
> Wait, false alarm. I actually did look at them and those in af/ don't
> seem to use the combination of pcim_enable_device() + pci_request_*
> 
> Only users of that combination have to be ported. Users of
> pci_enable_device() + pcim_* functions and pcim_enable_device() +
> pcim_* functions are fine.
> 
> Correct me if I missed the first mentioned combination up there.

I think you're right, there are apparently multiple but separate
drivers in that directory.