Skip to content

Commit 3726cce

Browse files
bcreeley13Jeff Kirsher
authored andcommitted
ice: Refactor VF VSI release and setup functions
Currently when a VF VSI calls ice_vsi_release() and ice_vsi_setup() it subsequently clears/sets the VF cached variables for lan_vsi_idx and lan_vsi_num. This works fine, but can be improved by handling this in the VF specific VSI release and setup functions. Also, when a VF VSI is setup too many parameters are passed that can be derived from the VF. Fix this by only calling VF VSI setup with the bare minimum parameters. Also, add functionality to invalidate a VF's VSI when it's released and/or setup fails. This will make it so a VF VSI cannot be accessed via its cached vsi_idx/vsi_num in these cases. Finally when a VF's VSI is invalidated set the lan_vsi_idx and lan_vsi_num to ICE_NO_VSI to clearly show that there is no valid VSI associated with this VF. Signed-off-by: Brett Creeley <[email protected]> Tested-by: Andrew Bowers <[email protected]> Signed-off-by: Jeff Kirsher <[email protected]>
1 parent 12bb018 commit 3726cce

File tree

1 file changed

+55
-31
lines changed

1 file changed

+55
-31
lines changed

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

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,26 @@ static void ice_vc_notify_vf_link_state(struct ice_vf *vf)
181181
sizeof(pfe), NULL);
182182
}
183183

184+
/**
185+
* ice_vf_invalidate_vsi - invalidate vsi_idx/vsi_num to remove VSI access
186+
* @vf: VF to remove access to VSI for
187+
*/
188+
static void ice_vf_invalidate_vsi(struct ice_vf *vf)
189+
{
190+
vf->lan_vsi_idx = ICE_NO_VSI;
191+
vf->lan_vsi_num = ICE_NO_VSI;
192+
}
193+
194+
/**
195+
* ice_vf_vsi_release - invalidate the VF's VSI after freeing it
196+
* @vf: invalidate this VF's VSI after freeing it
197+
*/
198+
static void ice_vf_vsi_release(struct ice_vf *vf)
199+
{
200+
ice_vsi_release(vf->pf->vsi[vf->lan_vsi_idx]);
201+
ice_vf_invalidate_vsi(vf);
202+
}
203+
184204
/**
185205
* ice_free_vf_res - Free a VF's resources
186206
* @vf: pointer to the VF info
@@ -196,10 +216,8 @@ static void ice_free_vf_res(struct ice_vf *vf)
196216
clear_bit(ICE_VF_STATE_INIT, vf->vf_states);
197217

198218
/* free VSI and disconnect it from the parent uplink */
199-
if (vf->lan_vsi_idx) {
200-
ice_vsi_release(pf->vsi[vf->lan_vsi_idx]);
201-
vf->lan_vsi_idx = 0;
202-
vf->lan_vsi_num = 0;
219+
if (vf->lan_vsi_idx != ICE_NO_VSI) {
220+
ice_vf_vsi_release(vf);
203221
vf->num_mac = 0;
204222
}
205223

@@ -505,19 +523,40 @@ static int ice_vsi_manage_pvid(struct ice_vsi *vsi, u16 pvid_info, bool enable)
505523
return ret;
506524
}
507525

526+
/**
527+
* ice_vf_get_port_info - Get the VF's port info structure
528+
* @vf: VF used to get the port info structure for
529+
*/
530+
static struct ice_port_info *ice_vf_get_port_info(struct ice_vf *vf)
531+
{
532+
return vf->pf->hw.port_info;
533+
}
534+
508535
/**
509536
* ice_vf_vsi_setup - Set up a VF VSI
510-
* @pf: board private structure
511-
* @pi: pointer to the port_info instance
512-
* @vf_id: defines VF ID to which this VSI connects.
537+
* @vf: VF to setup VSI for
513538
*
514539
* Returns pointer to the successfully allocated VSI struct on success,
515540
* otherwise returns NULL on failure.
516541
*/
517-
static struct ice_vsi *
518-
ice_vf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi, u16 vf_id)
542+
static struct ice_vsi *ice_vf_vsi_setup(struct ice_vf *vf)
519543
{
520-
return ice_vsi_setup(pf, pi, ICE_VSI_VF, vf_id);
544+
struct ice_port_info *pi = ice_vf_get_port_info(vf);
545+
struct ice_pf *pf = vf->pf;
546+
struct ice_vsi *vsi;
547+
548+
vsi = ice_vsi_setup(pf, pi, ICE_VSI_VF, vf->vf_id);
549+
550+
if (!vsi) {
551+
dev_err(ice_pf_to_dev(pf), "Failed to create VF VSI\n");
552+
ice_vf_invalidate_vsi(vf);
553+
return NULL;
554+
}
555+
556+
vf->lan_vsi_idx = vsi->idx;
557+
vf->lan_vsi_num = vsi->vsi_num;
558+
559+
return vsi;
521560
}
522561

523562
/**
@@ -1043,19 +1082,9 @@ static void ice_vf_rebuild_host_cfg(struct ice_vf *vf)
10431082
*/
10441083
static int ice_vf_rebuild_vsi_with_release(struct ice_vf *vf)
10451084
{
1046-
struct ice_pf *pf = vf->pf;
1047-
struct ice_vsi *vsi;
1048-
1049-
vsi = pf->vsi[vf->lan_vsi_idx];
1050-
ice_vsi_release(vsi);
1051-
vsi = ice_vf_vsi_setup(pf, pf->hw.port_info, vf->vf_id);
1052-
if (!vsi) {
1053-
dev_err(ice_pf_to_dev(pf), "Failed to create VF VSI\n");
1085+
ice_vf_vsi_release(vf);
1086+
if (!ice_vf_vsi_setup(vf))
10541087
return -ENOMEM;
1055-
}
1056-
1057-
vf->lan_vsi_idx = vsi->idx;
1058-
vf->lan_vsi_num = vsi->vsi_num;
10591088

10601089
return 0;
10611090
}
@@ -1395,14 +1424,9 @@ static int ice_init_vf_vsi_res(struct ice_vf *vf)
13951424
vf->first_vector_idx = ice_calc_vf_first_vector_idx(pf, vf);
13961425

13971426
dev = ice_pf_to_dev(pf);
1398-
vsi = ice_vf_vsi_setup(pf, pf->hw.port_info, vf->vf_id);
1399-
if (!vsi) {
1400-
dev_err(dev, "Failed to create VF VSI\n");
1427+
vsi = ice_vf_vsi_setup(vf);
1428+
if (!vsi)
14011429
return -ENOMEM;
1402-
}
1403-
1404-
vf->lan_vsi_idx = vsi->idx;
1405-
vf->lan_vsi_num = vsi->vsi_num;
14061430

14071431
err = ice_vsi_add_vlan(vsi, 0, ICE_FWD_TO_VSI);
14081432
if (err) {
@@ -1425,7 +1449,7 @@ static int ice_init_vf_vsi_res(struct ice_vf *vf)
14251449
return 0;
14261450

14271451
release_vsi:
1428-
ice_vsi_release(vsi);
1452+
ice_vf_vsi_release(vf);
14291453
return err;
14301454
}
14311455

@@ -1463,7 +1487,7 @@ static int ice_start_vfs(struct ice_pf *pf)
14631487
struct ice_vf *vf = &pf->vf[i];
14641488

14651489
ice_dis_vf_mappings(vf);
1466-
ice_vsi_release(pf->vsi[vf->lan_vsi_idx]);
1490+
ice_vf_vsi_release(vf);
14671491
}
14681492

14691493
return retval;

0 commit comments

Comments
 (0)