Skip to content

Commit 651e1f2

Browse files
Jakub Kicinskidavem330
authored andcommitted
nfp: set driver VF limit
PCI subsystem has support for drivers limiting the number of VFs available below what the IOV capability claims. Make use of it. While at it remove the #ifdef/#endif on CONFIG_PCI_IOV, it was there to avoid unnecessary warnings in case device read failed but kernel doesn't have SR-IOV support anyway. Device reads should not fail. Note that we still need the driver-internal check for the case where max VFs is 0 since PCI subsystem treats 0 as limit not set. Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 9d37275 commit 651e1f2

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

drivers/net/ethernet/netronome/nfp/nfp_main.c

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,20 +73,22 @@ static const struct pci_device_id nfp_pci_device_ids[] = {
7373
};
7474
MODULE_DEVICE_TABLE(pci, nfp_pci_device_ids);
7575

76-
static void nfp_pcie_sriov_read_nfd_limit(struct nfp_pf *pf)
76+
static int nfp_pcie_sriov_read_nfd_limit(struct nfp_pf *pf)
7777
{
78-
#ifdef CONFIG_PCI_IOV
7978
int err;
8079

8180
pf->limit_vfs = nfp_rtsym_read_le(pf->cpp, "nfd_vf_cfg_max_vfs", &err);
8281
if (!err)
83-
return;
82+
return pci_sriov_set_totalvfs(pf->pdev, pf->limit_vfs);
8483

8584
pf->limit_vfs = ~0;
85+
pci_sriov_set_totalvfs(pf->pdev, 0); /* 0 is unset */
8686
/* Allow any setting for backwards compatibility if symbol not found */
87-
if (err != -ENOENT)
88-
nfp_warn(pf->cpp, "Warning: VF limit read failed: %d\n", err);
89-
#endif
87+
if (err == -ENOENT)
88+
return 0;
89+
90+
nfp_warn(pf->cpp, "Warning: VF limit read failed: %d\n", err);
91+
return err;
9092
}
9193

9294
static int nfp_pcie_sriov_enable(struct pci_dev *pdev, int num_vfs)
@@ -373,14 +375,18 @@ static int nfp_pci_probe(struct pci_dev *pdev,
373375
if (err)
374376
goto err_devlink_unreg;
375377

376-
nfp_pcie_sriov_read_nfd_limit(pf);
378+
err = nfp_pcie_sriov_read_nfd_limit(pf);
379+
if (err)
380+
goto err_fw_unload;
377381

378382
err = nfp_net_pci_probe(pf);
379383
if (err)
380-
goto err_fw_unload;
384+
goto err_sriov_unlimit;
381385

382386
return 0;
383387

388+
err_sriov_unlimit:
389+
pci_sriov_set_totalvfs(pf->pdev, 0);
384390
err_fw_unload:
385391
if (pf->fw_loaded)
386392
nfp_fw_unload(pf);
@@ -411,6 +417,7 @@ static void nfp_pci_remove(struct pci_dev *pdev)
411417
nfp_net_pci_remove(pf);
412418

413419
nfp_pcie_sriov_disable(pdev);
420+
pci_sriov_set_totalvfs(pf->pdev, 0);
414421

415422
devlink_unregister(devlink);
416423

0 commit comments

Comments
 (0)