@@ -1469,55 +1469,81 @@ static int ice_start_vfs(struct ice_pf *pf)
1469
1469
}
1470
1470
1471
1471
/**
1472
- * ice_alloc_vfs - Allocate and set up VFs resources
1472
+ * ice_set_dflt_settings - set VF defaults during initialization/creation
1473
+ * @pf: PF holding reference to all VFs for default configuration
1474
+ */
1475
+ static void ice_set_dflt_settings_vfs (struct ice_pf * pf )
1476
+ {
1477
+ int i ;
1478
+
1479
+ ice_for_each_vf (pf , i ) {
1480
+ struct ice_vf * vf = & pf -> vf [i ];
1481
+
1482
+ vf -> pf = pf ;
1483
+ vf -> vf_id = i ;
1484
+ vf -> vf_sw_id = pf -> first_sw ;
1485
+ /* assign default capabilities */
1486
+ set_bit (ICE_VIRTCHNL_VF_CAP_L2 , & vf -> vf_caps );
1487
+ vf -> spoofchk = true;
1488
+ vf -> num_vf_qs = pf -> num_qps_per_vf ;
1489
+ }
1490
+ }
1491
+
1492
+ /**
1493
+ * ice_alloc_vfs - allocate num_vfs in the PF structure
1494
+ * @pf: PF to store the allocated VFs in
1495
+ * @num_vfs: number of VFs to allocate
1496
+ */
1497
+ static int ice_alloc_vfs (struct ice_pf * pf , int num_vfs )
1498
+ {
1499
+ struct ice_vf * vfs ;
1500
+
1501
+ vfs = devm_kcalloc (ice_pf_to_dev (pf ), num_vfs , sizeof (* vfs ),
1502
+ GFP_KERNEL );
1503
+ if (!vfs )
1504
+ return - ENOMEM ;
1505
+
1506
+ pf -> vf = vfs ;
1507
+ pf -> num_alloc_vfs = num_vfs ;
1508
+
1509
+ return 0 ;
1510
+ }
1511
+
1512
+ /**
1513
+ * ice_ena_vfs - enable VFs so they are ready to be used
1473
1514
* @pf: pointer to the PF structure
1474
- * @num_alloc_vfs : number of VFs to allocate
1515
+ * @num_vfs : number of VFs to enable
1475
1516
*/
1476
- static int ice_alloc_vfs (struct ice_pf * pf , u16 num_alloc_vfs )
1517
+ static int ice_ena_vfs (struct ice_pf * pf , u16 num_vfs )
1477
1518
{
1478
1519
struct device * dev = ice_pf_to_dev (pf );
1479
1520
struct ice_hw * hw = & pf -> hw ;
1480
- struct ice_vf * vfs ;
1481
- int i , ret ;
1521
+ int ret ;
1482
1522
1483
1523
/* Disable global interrupt 0 so we don't try to handle the VFLR. */
1484
1524
wr32 (hw , GLINT_DYN_CTL (pf -> oicr_idx ),
1485
1525
ICE_ITR_NONE << GLINT_DYN_CTL_ITR_INDX_S );
1486
1526
set_bit (__ICE_OICR_INTR_DIS , pf -> state );
1487
1527
ice_flush (hw );
1488
1528
1489
- ret = pci_enable_sriov (pf -> pdev , num_alloc_vfs );
1529
+ ret = pci_enable_sriov (pf -> pdev , num_vfs );
1490
1530
if (ret ) {
1491
1531
pf -> num_alloc_vfs = 0 ;
1492
1532
goto err_unroll_intr ;
1493
1533
}
1494
- /* allocate memory */
1495
- vfs = devm_kcalloc (dev , num_alloc_vfs , sizeof (* vfs ), GFP_KERNEL );
1496
- if (!vfs ) {
1497
- ret = - ENOMEM ;
1534
+
1535
+ ret = ice_alloc_vfs (pf , num_vfs );
1536
+ if (ret )
1498
1537
goto err_pci_disable_sriov ;
1499
- }
1500
- pf -> vf = vfs ;
1501
- pf -> num_alloc_vfs = num_alloc_vfs ;
1502
1538
1503
1539
if (ice_set_per_vf_res (pf )) {
1504
1540
dev_err (dev , "Not enough resources for %d VFs, try with fewer number of VFs\n" ,
1505
- num_alloc_vfs );
1541
+ num_vfs );
1506
1542
ret = - ENOSPC ;
1507
1543
goto err_unroll_sriov ;
1508
1544
}
1509
1545
1510
- /* apply default profile */
1511
- ice_for_each_vf (pf , i ) {
1512
- vfs [i ].pf = pf ;
1513
- vfs [i ].vf_sw_id = pf -> first_sw ;
1514
- vfs [i ].vf_id = i ;
1515
-
1516
- /* assign default capabilities */
1517
- set_bit (ICE_VIRTCHNL_VF_CAP_L2 , & vfs [i ].vf_caps );
1518
- vfs [i ].spoofchk = true;
1519
- vfs [i ].num_vf_qs = pf -> num_qps_per_vf ;
1520
- }
1546
+ ice_set_dflt_settings_vfs (pf );
1521
1547
1522
1548
if (ice_start_vfs (pf )) {
1523
1549
dev_err (dev , "Failed to start VF(s)\n" );
@@ -1529,9 +1555,8 @@ static int ice_alloc_vfs(struct ice_pf *pf, u16 num_alloc_vfs)
1529
1555
return 0 ;
1530
1556
1531
1557
err_unroll_sriov :
1558
+ devm_kfree (dev , pf -> vf );
1532
1559
pf -> vf = NULL ;
1533
- devm_kfree (dev , vfs );
1534
- vfs = NULL ;
1535
1560
pf -> num_alloc_vfs = 0 ;
1536
1561
err_pci_disable_sriov :
1537
1562
pci_disable_sriov (pf -> pdev );
@@ -1591,8 +1616,8 @@ static int ice_pci_sriov_ena(struct ice_pf *pf, int num_vfs)
1591
1616
return - EOPNOTSUPP ;
1592
1617
}
1593
1618
1594
- dev_info (dev , "Allocating %d VFs\n" , num_vfs );
1595
- err = ice_alloc_vfs (pf , num_vfs );
1619
+ dev_info (dev , "Enabling %d VFs\n" , num_vfs );
1620
+ err = ice_ena_vfs (pf , num_vfs );
1596
1621
if (err ) {
1597
1622
dev_err (dev , "Failed to enable SR-IOV: %d\n" , err );
1598
1623
return err ;
0 commit comments