net: Phase out hybrid PCI devres API
Subsystems (9)
cover net: Phase out hybrid PCI devres API
Fixes a number of minor issues with the usage of the PCI API in net. Notbaly, it replaces calls to the sometimes-managed pci_request_regions() to the always-managed pcim_request_all_regions(), enabling us to remove that hybrid functionality from PCI.
Philipp Stanner (8):
net: prestera: Use pure PCI devres API
net: octeontx2: Use pure PCI devres API
net: tulip: Use pure PCI devres API
net: ethernet: natsemi: Use pure PCI devres API
net: ethernet: sis900: Use pure PCI devres API
net: mdio: thunder: Use pure PCI devres API
net: thunder_bgx: Use pure PCI devres API
net: thunder_bgx: Don't disable PCI device manually
drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 13 ++++--------- drivers/net/ethernet/dec/tulip/tulip_core.c | 2 +- drivers/net/ethernet/dec/tulip/winbond-840.c | 2 +- .../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 +--- .../net/ethernet/marvell/prestera/prestera_pci.c | 6 ++---- drivers/net/ethernet/natsemi/natsemi.c | 2 +- drivers/net/ethernet/sis/sis900.c | 2 +- drivers/net/mdio/mdio-thunder.c | 10 +++------- 10 files changed, 22 insertions(+), 47 deletions(-)
Signature · 1 line
2.48.1
PATCH 1/8 net: prestera: Use pure PCI devres API
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().
--- drivers/net/ethernet/marvell/prestera/prestera_pci.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/ethernet/marvell/prestera/prestera_pci.c +2 -4
@@ -845,9 +845,9 @@ static int prestera_pci_probe(struct pci_dev *pdev, goto err_pci_enable_device; } - err =pci_request_regions (pdev, driver_name); + err =pcim_request_all_regions (pdev, driver_name);if (err) { -dev_err (&pdev->dev,"pci_request_regions failed\n" ); +dev_err (&pdev->dev,"pcim_request_all_regions failed\n" ); goto err_pci_request_regions; }
@@ -938,7 +938,6 @@ static int prestera_pci_probe(struct pci_dev *pdev, err_pp_ioremap: err_mem_ioremap: err_dma_mask: -pci_release_regions (pdev); err_pci_request_regions: err_pci_enable_device:return err;
@@ -953,7 +952,6 @@ static void prestera_pci_remove(struct pci_dev *pdev)pci_free_irq_vectors (pdev);destroy_workqueue (fw->wq);prestera_fw_uninit (fw); -pci_release_regions (pdev); }static const struct pci_device_id prestera_pci_devices[] = {
Signature · 1 line
2.48.1
PATCH 2/8 net: octeontx2: Use pure PCI devres API
In reply to Philipp StannerThe 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().
--- .../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(-)
drivers/net/ethernet/marvell/octeontx2/nic/otx2_pf.c +4 -10
@@ -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 = {
drivers/net/ethernet/marvell/octeontx2/nic/otx2_vf.c +4 -10
@@ -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 = {
drivers/net/ethernet/marvell/octeontx2/nic/rep.c +1 -3
@@ -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 = {
Signature · 1 line
2.48.1
Jakub Kicinski
maintainerRe: [PATCH 2/8] net: octeontx2: Use pure PCI devres API
Review
Quoted 3 lines · On Wed, 16 Apr 2025 18:44:02 +0200 Philipp Stanner wrote:
err_release_regions:(quoted diff) +0
-1pci_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/ ?
Signature · 1 line
pw-bot: cr
Re: [PATCH 2/8] net: octeontx2: Use pure PCI devres API
Quoted 8 lines · Jakub Kicinski
Review
Quoted 3 lines · On Wed, 16 Apr 2025 18:44:02 +0200 Philipp Stanner wrote:
err_release_regions:
pci_set_drvdata(pdev, NULL);(quoted diff) +0
-1- pci_release_regions(pdev);This error path should be renamed. Could you also apply your conversion
todrivers/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
Quoted 10 lines · Philipp Stanner
Quoted 8 lines · Jakub Kicinski
Review
Quoted 3 lines · On Wed, 16 Apr 2025 18:44:02 +0200 Philipp Stanner wrote:
err_release_regions:
pci_set_drvdata(pdev, NULL);(quoted diff) +0
-1- pci_release_regions(pdev);This error path should be renamed. Could you also apply your conversion
todrivers/net/ethernet/marvell/octeontx2/af/?
Quoted 2 lines
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.
Quoted 3 lines
P.
Jakub Kicinski
maintainerRe: [PATCH 2/8] net: octeontx2: Use pure PCI devres API
Quoted 7 lines · On Wed, 23 Apr 2025 10:38:01 +0200 Philipp Stanner wrote:
Quoted 6 lines
Quoted 3 lines
This error path should be renamed. Could you also apply your conversion
todrivers/net/ethernet/marvell/octeontx2/af/?Hm, those must have slipped me for some reason. Will reiterate with them and the error path.
Quoted 8 lines
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 andpcim_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.
PATCH 3/8 net: tulip: Use pure PCI devres API
In reply to Philipp StannerThe 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.
Replace pci_request_regions() with pcim_request_all_regions().
--- drivers/net/ethernet/dec/tulip/tulip_core.c | 2 +- drivers/net/ethernet/dec/tulip/winbond-840.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/net/ethernet/dec/tulip/tulip_core.c +1 -1
@@ -1411,7 +1411,7 @@ static int tulip_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)/* grab all resources from both PIO and MMIO regions, as we * don't want anyone else messing around with our hardware */ -if (pci_request_regions (pdev,DRV_NAME )) +if (pcim_request_all_regions (pdev,DRV_NAME ))return -ENODEV ; ioaddr =pcim_iomap (pdev,TULIP_BAR , tulip_tbl[chip_idx].io_size);
drivers/net/ethernet/dec/tulip/winbond-840.c +1 -1
@@ -375,7 +375,7 @@ static int w840_probe1(struct pci_dev *pdev, const struct pci_device_id *ent)return -ENOMEM ;SET_NETDEV_DEV (dev, &pdev->dev); -if (pci_request_regions (pdev,DRV_NAME )) +if (pcim_request_all_regions (pdev,DRV_NAME )) goto err_out_netdev; ioaddr =pci_iomap (pdev,TULIP_BAR , netdev_res_size);
Signature · 1 line
2.48.1
PATCH 4/8 net: ethernet: natsemi: Use pure PCI devres API
In reply to Philipp StannerThe 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.
Replace pci_request_regions() with pcim_request_all_regions().
--- drivers/net/ethernet/natsemi/natsemi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/natsemi/natsemi.c +1 -1
@@ -846,7 +846,7 @@ static int natsemi_probe1(struct pci_dev *pdev, const struct pci_device_id *ent)return -ENOMEM ;SET_NETDEV_DEV (dev, &pdev->dev); - i =pci_request_regions (pdev,DRV_NAME ); + i =pcim_request_all_regions (pdev,DRV_NAME );if (i) goto err_pci_request_regions;
Signature · 1 line
2.48.1
PATCH 5/8 net: ethernet: sis900: Use pure PCI devres API
In reply to Philipp StannerThe 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.
Replace pci_request_regions() with pcim_request_all_regions().
--- drivers/net/ethernet/sis/sis900.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/sis/sis900.c +1 -1
@@ -468,7 +468,7 @@ static int sis900_probe(struct pci_dev *pci_dev,SET_NETDEV_DEV (net_dev, &pci_dev->dev);/* We do a request_region() to register /proc/ioports info. */ - ret =pci_request_regions (pci_dev,"sis900" ); + ret =pcim_request_all_regions (pci_dev,"sis900" );if (ret) goto err_out;
Signature · 1 line
2.48.1
PATCH 6/8 net: mdio: thunder: Use pure PCI devres API
In reply to Philipp StannerThe 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().
--- drivers/net/mdio/mdio-thunder.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
drivers/net/mdio/mdio-thunder.c +3 -7
@@ -40,16 +40,16 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev,return err; } - err =pci_request_regions (pdev,KBUILD_MODNAME ); + err =pcim_request_all_regions (pdev,KBUILD_MODNAME );if (err) { -dev_err (&pdev->dev,"pci_request_regions failed\n" ); +dev_err (&pdev->dev,"pcim_request_all_regions failed\n" ); goto err_disable_device; } nexus->bar0 =pcim_iomap (pdev,0 ,pci_resource_len (pdev,0 ));if (!nexus->bar0) { err = -ENOMEM ; - goto err_release_regions; + goto err_disable_device; } i =0 ;
@@ -107,9 +107,6 @@ static int thunder_mdiobus_pci_probe(struct pci_dev *pdev, }return 0 ; -err_release_regions: -pci_release_regions (pdev); - err_disable_device:pci_set_drvdata (pdev,NULL );return err;
@@ -129,7 +126,6 @@ static void thunder_mdiobus_pci_remove(struct pci_dev *pdev)mdiobus_unregister (bus->mii_bus);oct_mdio_writeq (0 , bus->register_base +SMI_EN ); } -pci_release_regions (pdev);pci_set_drvdata (pdev,NULL ); }
Signature · 1 line
2.48.1
PATCH 7/8 net: thunder_bgx: Use pure PCI devres API
In reply to Philipp StannerThe 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().
--- drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/ethernet/cavium/thunder/thunder_bgx.c +2 -5
@@ -1605,7 +1605,7 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)return dev_err_probe (dev, err,"Failed to enable PCI device\n" ); } - 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); goto err_disable_device;
@@ -1616,7 +1616,7 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (!bgx->reg_base) {dev_err (dev,"BGX: Cannot map CSR memory space, aborting\n" ); err = -ENOMEM ; - goto err_release_regions; + goto err_disable_device; }set_max_bgx_per_node (pdev);
@@ -1688,8 +1688,6 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err_enable: bgx_vnic[bgx->bgx_id] =NULL ;pci_free_irq (pdev,GMPX_GMI_TX_INT , bgx); -err_release_regions: -pci_release_regions (pdev); err_disable_device:pci_disable_device (pdev);pci_set_drvdata (pdev,NULL );
@@ -1710,7 +1708,6 @@ static void bgx_remove(struct pci_dev *pdev)pci_free_irq (pdev,GMPX_GMI_TX_INT , bgx); bgx_vnic[bgx->bgx_id] =NULL ; -pci_release_regions (pdev);pci_disable_device (pdev);pci_set_drvdata (pdev,NULL ); }
Signature · 1 line
2.48.1
PATCH 8/8 net: thunder_bgx: Don't disable PCI device manually
In reply to Philipp Stannerthunder_bgx's PCI device is enabled with pcim_enable_device(), a managed devres function which ensures that the device gets enabled on driver detach automatically.
Remove the calls to pci_disable_device().
--- drivers/net/ethernet/cavium/thunder/thunder_bgx.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-)
drivers/net/ethernet/cavium/thunder/thunder_bgx.c +3 -5
@@ -1608,7 +1608,7 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err =pcim_request_all_regions (pdev,DRV_NAME );if (err) {dev_err (dev,"PCI request regions failed 0x%x\n" , err); - goto err_disable_device; + goto err_zero_drv_data; }/* MAP configuration registers */
@@ -1616,7 +1616,7 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent)if (!bgx->reg_base) {dev_err (dev,"BGX: Cannot map CSR memory space, aborting\n" ); err = -ENOMEM ; - goto err_disable_device; + goto err_zero_drv_data; }set_max_bgx_per_node (pdev);
@@ -1688,8 +1688,7 @@ static int bgx_probe(struct pci_dev *pdev, const struct pci_device_id *ent) err_enable: bgx_vnic[bgx->bgx_id] =NULL ;pci_free_irq (pdev,GMPX_GMI_TX_INT , bgx); -err_disable_device: -pci_disable_device (pdev); +err_zero_drv_data:pci_set_drvdata (pdev,NULL );return err; }
@@ -1708,7 +1707,6 @@ static void bgx_remove(struct pci_dev *pdev)pci_free_irq (pdev,GMPX_GMI_TX_INT , bgx); bgx_vnic[bgx->bgx_id] =NULL ; -pci_disable_device (pdev);pci_set_drvdata (pdev,NULL ); }
Signature · 1 line
2.48.1
Quoted 21 lines
-----Original Message-----
From: Philipp Stanner <[email protected]>
Sent: Wednesday, April 16, 2025 9:44 AM
To: Sunil Goutham <[email protected]>; Andrew Lunn <[email protected]>; David S. Miller <[email protected]>; Dumazet, Eric <[email protected]>; Jakub Kicinski <[email protected]>; Paolo Abeni <[email protected]>; Geetha sowjanya <[email protected]>; Subbaraya Sundeep <[email protected]>; hariprasad <[email protected]>; Bharat Bhushan <[email protected]>; Taras Chornyi <[email protected]>; Daniele Venzano <[email protected]>; Heiner Kallweit <[email protected]>; Russell King <[email protected]>; Thomas Gleixner <[email protected]>; Philipp Stanner <[email protected]>; Helge Deller <[email protected]>; Ingo Molnar <[email protected]>; Simon Horman <[email protected]>; Al Viro <[email protected]>; Sabrina Dubroca <[email protected]>; Keller, Jacob E <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: [PATCH 0/8] net: Phase out hybrid PCI devres API
Quoted 5 lines
Fixes a number of minor issues with the usage of the PCI API in net. Notbaly, it replaces calls to the sometimes-managed
pci_request_regions()to the always-managedpcim_request_all_regions(), enabling us to remove that hybrid functionality from PCI.
Removing the problematic "sometimes" behavior is good.