Skip to content

Commit a06325a

Browse files
bcreeley13Jeff Kirsher
authored andcommitted
ice: Renaming and simplification in VF init path
Some function names weren't very clear and some portions of VF creation could be moved into functions for clarity. Fix this by renaming some functions and move pieces of code into clearly name functions. Signed-off-by: Brett Creeley <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 916c7fd commit a06325a

File tree

1 file changed

+54
-29
lines changed

1 file changed

+54
-29
lines changed

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

Lines changed: 54 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1469,55 +1469,81 @@ static int ice_start_vfs(struct ice_pf *pf)
14691469
}
14701470

14711471
/**
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
14731514
* @pf: pointer to the PF structure
1474-
* @num_alloc_vfs: number of VFs to allocate
1515+
* @num_vfs: number of VFs to enable
14751516
*/
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)
14771518
{
14781519
struct device *dev = ice_pf_to_dev(pf);
14791520
struct ice_hw *hw = &pf->hw;
1480-
struct ice_vf *vfs;
1481-
int i, ret;
1521+
int ret;
14821522

14831523
/* Disable global interrupt 0 so we don't try to handle the VFLR. */
14841524
wr32(hw, GLINT_DYN_CTL(pf->oicr_idx),
14851525
ICE_ITR_NONE << GLINT_DYN_CTL_ITR_INDX_S);
14861526
set_bit(__ICE_OICR_INTR_DIS, pf->state);
14871527
ice_flush(hw);
14881528

1489-
ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
1529+
ret = pci_enable_sriov(pf->pdev, num_vfs);
14901530
if (ret) {
14911531
pf->num_alloc_vfs = 0;
14921532
goto err_unroll_intr;
14931533
}
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)
14981537
goto err_pci_disable_sriov;
1499-
}
1500-
pf->vf = vfs;
1501-
pf->num_alloc_vfs = num_alloc_vfs;
15021538

15031539
if (ice_set_per_vf_res(pf)) {
15041540
dev_err(dev, "Not enough resources for %d VFs, try with fewer number of VFs\n",
1505-
num_alloc_vfs);
1541+
num_vfs);
15061542
ret = -ENOSPC;
15071543
goto err_unroll_sriov;
15081544
}
15091545

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);
15211547

15221548
if (ice_start_vfs(pf)) {
15231549
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)
15291555
return 0;
15301556

15311557
err_unroll_sriov:
1558+
devm_kfree(dev, pf->vf);
15321559
pf->vf = NULL;
1533-
devm_kfree(dev, vfs);
1534-
vfs = NULL;
15351560
pf->num_alloc_vfs = 0;
15361561
err_pci_disable_sriov:
15371562
pci_disable_sriov(pf->pdev);
@@ -1591,8 +1616,8 @@ static int ice_pci_sriov_ena(struct ice_pf *pf, int num_vfs)
15911616
return -EOPNOTSUPP;
15921617
}
15931618

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);
15961621
if (err) {
15971622
dev_err(dev, "Failed to enable SR-IOV: %d\n", err);
15981623
return err;

0 commit comments

Comments
 (0)