@@ -1460,27 +1460,19 @@ static bool ice_pf_state_is_nominal(struct ice_pf *pf)
1460
1460
* ice_pci_sriov_ena - Enable or change number of VFs
1461
1461
* @pf: pointer to the PF structure
1462
1462
* @num_vfs: number of VFs to allocate
1463
+ *
1464
+ * Returns 0 on success and negative on failure
1463
1465
*/
1464
1466
static int ice_pci_sriov_ena (struct ice_pf * pf , int num_vfs )
1465
1467
{
1466
1468
int pre_existing_vfs = pci_num_vf (pf -> pdev );
1467
1469
struct device * dev = ice_pf_to_dev (pf );
1468
1470
int err ;
1469
1471
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
-
1480
1472
if (pre_existing_vfs && pre_existing_vfs != num_vfs )
1481
1473
ice_free_vfs (pf );
1482
1474
else if (pre_existing_vfs && pre_existing_vfs == num_vfs )
1483
- return num_vfs ;
1475
+ return 0 ;
1484
1476
1485
1477
if (num_vfs > pf -> num_vfs_supported ) {
1486
1478
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)
1496
1488
}
1497
1489
1498
1490
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 ;
1500
1518
}
1501
1519
1502
1520
/**
1503
1521
* ice_sriov_configure - Enable or change number of VFs via sysfs
1504
1522
* @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
1506
1524
*
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.
1508
1528
*/
1509
1529
int ice_sriov_configure (struct pci_dev * pdev , int num_vfs )
1510
1530
{
1511
1531
struct ice_pf * pf = pci_get_drvdata (pdev );
1512
1532
struct device * dev = ice_pf_to_dev (pf );
1533
+ int err ;
1513
1534
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 ;
1518
1538
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
+ }
1521
1544
1522
- if (!pci_vfs_assigned (pdev )) {
1523
- ice_free_vfs (pf );
1524
- } else {
1525
1545
dev_err (dev , "can't free VFs because some are assigned to VMs.\n" );
1526
1546
return - EBUSY ;
1527
1547
}
1528
1548
1529
- return 0 ;
1549
+ err = ice_pci_sriov_ena (pf , num_vfs );
1550
+ if (err )
1551
+ return err ;
1552
+
1553
+ return num_vfs ;
1530
1554
}
1531
1555
1532
1556
/**
0 commit comments