Skip to content

Commit

Permalink
ice: Renaming and simplification in VF init path
Browse files Browse the repository at this point in the history
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 <brett.creeley@intel.com>
Tested-by: Andrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: Jeff Kirsher <jeffrey.t.kirsher@intel.com>
  • Loading branch information
Brett Creeley authored and Jeff Kirsher committed May 28, 2020
1 parent 916c7fd commit a06325a
Showing 1 changed file with 54 additions and 29 deletions.
83 changes: 54 additions & 29 deletions drivers/net/ethernet/intel/ice/ice_virtchnl_pf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1469,55 +1469,81 @@ static int ice_start_vfs(struct ice_pf *pf)
}

/**
* ice_alloc_vfs - Allocate and set up VFs resources
* ice_set_dflt_settings - set VF defaults during initialization/creation
* @pf: PF holding reference to all VFs for default configuration
*/
static void ice_set_dflt_settings_vfs(struct ice_pf *pf)
{
int i;

ice_for_each_vf(pf, i) {
struct ice_vf *vf = &pf->vf[i];

vf->pf = pf;
vf->vf_id = i;
vf->vf_sw_id = pf->first_sw;
/* assign default capabilities */
set_bit(ICE_VIRTCHNL_VF_CAP_L2, &vf->vf_caps);
vf->spoofchk = true;
vf->num_vf_qs = pf->num_qps_per_vf;
}
}

/**
* ice_alloc_vfs - allocate num_vfs in the PF structure
* @pf: PF to store the allocated VFs in
* @num_vfs: number of VFs to allocate
*/
static int ice_alloc_vfs(struct ice_pf *pf, int num_vfs)
{
struct ice_vf *vfs;

vfs = devm_kcalloc(ice_pf_to_dev(pf), num_vfs, sizeof(*vfs),
GFP_KERNEL);
if (!vfs)
return -ENOMEM;

pf->vf = vfs;
pf->num_alloc_vfs = num_vfs;

return 0;
}

/**
* ice_ena_vfs - enable VFs so they are ready to be used
* @pf: pointer to the PF structure
* @num_alloc_vfs: number of VFs to allocate
* @num_vfs: number of VFs to enable
*/
static int ice_alloc_vfs(struct ice_pf *pf, u16 num_alloc_vfs)
static int ice_ena_vfs(struct ice_pf *pf, u16 num_vfs)
{
struct device *dev = ice_pf_to_dev(pf);
struct ice_hw *hw = &pf->hw;
struct ice_vf *vfs;
int i, ret;
int ret;

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

ret = pci_enable_sriov(pf->pdev, num_alloc_vfs);
ret = pci_enable_sriov(pf->pdev, num_vfs);
if (ret) {
pf->num_alloc_vfs = 0;
goto err_unroll_intr;
}
/* allocate memory */
vfs = devm_kcalloc(dev, num_alloc_vfs, sizeof(*vfs), GFP_KERNEL);
if (!vfs) {
ret = -ENOMEM;

ret = ice_alloc_vfs(pf, num_vfs);
if (ret)
goto err_pci_disable_sriov;
}
pf->vf = vfs;
pf->num_alloc_vfs = num_alloc_vfs;

if (ice_set_per_vf_res(pf)) {
dev_err(dev, "Not enough resources for %d VFs, try with fewer number of VFs\n",
num_alloc_vfs);
num_vfs);
ret = -ENOSPC;
goto err_unroll_sriov;
}

/* apply default profile */
ice_for_each_vf(pf, i) {
vfs[i].pf = pf;
vfs[i].vf_sw_id = pf->first_sw;
vfs[i].vf_id = i;

/* assign default capabilities */
set_bit(ICE_VIRTCHNL_VF_CAP_L2, &vfs[i].vf_caps);
vfs[i].spoofchk = true;
vfs[i].num_vf_qs = pf->num_qps_per_vf;
}
ice_set_dflt_settings_vfs(pf);

if (ice_start_vfs(pf)) {
dev_err(dev, "Failed to start VF(s)\n");
Expand All @@ -1529,9 +1555,8 @@ static int ice_alloc_vfs(struct ice_pf *pf, u16 num_alloc_vfs)
return 0;

err_unroll_sriov:
devm_kfree(dev, pf->vf);
pf->vf = NULL;
devm_kfree(dev, vfs);
vfs = NULL;
pf->num_alloc_vfs = 0;
err_pci_disable_sriov:
pci_disable_sriov(pf->pdev);
Expand Down Expand Up @@ -1591,8 +1616,8 @@ static int ice_pci_sriov_ena(struct ice_pf *pf, int num_vfs)
return -EOPNOTSUPP;
}

dev_info(dev, "Allocating %d VFs\n", num_vfs);
err = ice_alloc_vfs(pf, num_vfs);
dev_info(dev, "Enabling %d VFs\n", num_vfs);
err = ice_ena_vfs(pf, num_vfs);
if (err) {
dev_err(dev, "Failed to enable SR-IOV: %d\n", err);
return err;
Expand Down

0 comments on commit a06325a

Please sign in to comment.