Skip to content

Commit 02337f1

Browse files
bcreeley13Jeff Kirsher
authored andcommitted
ice: Simplify ice_sriov_configure
Add a new function for checking if SR-IOV can be configured based on the PF and/or device's state/capabilities. Also, simplify the flow in ice_sriov_configure(). Signed-off-by: Brett Creeley <[email protected]> Signed-off-by: Tony Nguyen <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent ac37161 commit 02337f1

File tree

1 file changed

+48
-24
lines changed

1 file changed

+48
-24
lines changed

drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1460,27 +1460,19 @@ static bool ice_pf_state_is_nominal(struct ice_pf *pf)
14601460
* ice_pci_sriov_ena - Enable or change number of VFs
14611461
* @pf: pointer to the PF structure
14621462
* @num_vfs: number of VFs to allocate
1463+
*
1464+
* Returns 0 on success and negative on failure
14631465
*/
14641466
static int ice_pci_sriov_ena(struct ice_pf *pf, int num_vfs)
14651467
{
14661468
int pre_existing_vfs = pci_num_vf(pf->pdev);
14671469
struct device *dev = ice_pf_to_dev(pf);
14681470
int err;
14691471

1470-
if (!ice_pf_state_is_nominal(pf)) {
1471-
dev_err(dev, "Cannot enable SR-IOV, device not ready\n");
1472-
return -EBUSY;
1473-
}
1474-
1475-
if (!test_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags)) {
1476-
dev_err(dev, "This device is not capable of SR-IOV\n");
1477-
return -EOPNOTSUPP;
1478-
}
1479-
14801472
if (pre_existing_vfs && pre_existing_vfs != num_vfs)
14811473
ice_free_vfs(pf);
14821474
else if (pre_existing_vfs && pre_existing_vfs == num_vfs)
1483-
return num_vfs;
1475+
return 0;
14841476

14851477
if (num_vfs > pf->num_vfs_supported) {
14861478
dev_err(dev, "Can't enable %d VFs, max VFs supported is %d\n",
@@ -1496,37 +1488,69 @@ static int ice_pci_sriov_ena(struct ice_pf *pf, int num_vfs)
14961488
}
14971489

14981490
set_bit(ICE_FLAG_SRIOV_ENA, pf->flags);
1499-
return num_vfs;
1491+
return 0;
1492+
}
1493+
1494+
/**
1495+
* ice_check_sriov_allowed - check if SR-IOV is allowed based on various checks
1496+
* @pf: PF to enabled SR-IOV on
1497+
*/
1498+
static int ice_check_sriov_allowed(struct ice_pf *pf)
1499+
{
1500+
struct device *dev = ice_pf_to_dev(pf);
1501+
1502+
if (!test_bit(ICE_FLAG_SRIOV_CAPABLE, pf->flags)) {
1503+
dev_err(dev, "This device is not capable of SR-IOV\n");
1504+
return -EOPNOTSUPP;
1505+
}
1506+
1507+
if (ice_is_safe_mode(pf)) {
1508+
dev_err(dev, "SR-IOV cannot be configured - Device is in Safe Mode\n");
1509+
return -EOPNOTSUPP;
1510+
}
1511+
1512+
if (!ice_pf_state_is_nominal(pf)) {
1513+
dev_err(dev, "Cannot enable SR-IOV, device not ready\n");
1514+
return -EBUSY;
1515+
}
1516+
1517+
return 0;
15001518
}
15011519

15021520
/**
15031521
* ice_sriov_configure - Enable or change number of VFs via sysfs
15041522
* @pdev: pointer to a pci_dev structure
1505-
* @num_vfs: number of VFs to allocate
1523+
* @num_vfs: number of VFs to allocate or 0 to free VFs
15061524
*
1507-
* This function is called when the user updates the number of VFs in sysfs.
1525+
* This function is called when the user updates the number of VFs in sysfs. On
1526+
* success return whatever num_vfs was set to by the caller. Return negative on
1527+
* failure.
15081528
*/
15091529
int ice_sriov_configure(struct pci_dev *pdev, int num_vfs)
15101530
{
15111531
struct ice_pf *pf = pci_get_drvdata(pdev);
15121532
struct device *dev = ice_pf_to_dev(pf);
1533+
int err;
15131534

1514-
if (ice_is_safe_mode(pf)) {
1515-
dev_err(dev, "SR-IOV cannot be configured - Device is in Safe Mode\n");
1516-
return -EOPNOTSUPP;
1517-
}
1535+
err = ice_check_sriov_allowed(pf);
1536+
if (err)
1537+
return err;
15181538

1519-
if (num_vfs)
1520-
return ice_pci_sriov_ena(pf, num_vfs);
1539+
if (!num_vfs) {
1540+
if (!pci_vfs_assigned(pdev)) {
1541+
ice_free_vfs(pf);
1542+
return 0;
1543+
}
15211544

1522-
if (!pci_vfs_assigned(pdev)) {
1523-
ice_free_vfs(pf);
1524-
} else {
15251545
dev_err(dev, "can't free VFs because some are assigned to VMs.\n");
15261546
return -EBUSY;
15271547
}
15281548

1529-
return 0;
1549+
err = ice_pci_sriov_ena(pf, num_vfs);
1550+
if (err)
1551+
return err;
1552+
1553+
return num_vfs;
15301554
}
15311555

15321556
/**

0 commit comments

Comments
 (0)