Skip to content

Commit a696d61

Browse files
jacob-kelleranguy11
authored andcommitted
ice: stop hard coding the ICE_VSI_CTRL location
When allocating the ICE_VSI_CTRL, the allocated struct ice_vsi pointer is stored into the PF's pf->vsi array at a fixed location. This was historically done on the basis that it could provide an O(1) lookup for the special control VSI. Since we store the ctrl_vsi_idx, we already have O(1) lookup regardless of where in the array we store this VSI. Simplify the logic in ice_vsi_alloc by using the same method of storing the control VSI as other types of VSIs. Signed-off-by: Jacob Keller <[email protected]> Signed-off-by: Michal Swiatkowski <[email protected]> Tested-by: Gurucharan G <[email protected]> (A Contingent worker at Intel) Signed-off-by: Tony Nguyen <[email protected]>
1 parent 6624e78 commit a696d61

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

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

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,7 @@ int ice_vsi_free(struct ice_vsi *vsi)
479479
/* updates the PF for this cleared VSI */
480480

481481
pf->vsi[vsi->idx] = NULL;
482-
if (vsi->idx < pf->next_vsi && vsi->type != ICE_VSI_CTRL)
483-
pf->next_vsi = vsi->idx;
484-
if (vsi->idx < pf->next_vsi && vsi->type == ICE_VSI_CTRL && vsi->vf)
485-
pf->next_vsi = vsi->idx;
482+
pf->next_vsi = vsi->idx;
486483

487484
ice_vsi_free_stats(vsi);
488485
ice_vsi_free_arrays(vsi);
@@ -690,23 +687,22 @@ ice_vsi_alloc(struct ice_pf *pf, struct ice_port_info *pi,
690687
vsi->vf = vf;
691688
set_bit(ICE_VSI_DOWN, vsi->state);
692689

693-
if (vsi->type == ICE_VSI_CTRL && !vf) {
694-
/* Use the last VSI slot as the index for PF control VSI */
695-
vsi->idx = pf->num_alloc_vsi - 1;
696-
pf->ctrl_vsi_idx = vsi->idx;
697-
pf->vsi[vsi->idx] = vsi;
698-
} else {
699-
/* fill slot and make note of the index */
700-
vsi->idx = pf->next_vsi;
701-
pf->vsi[pf->next_vsi] = vsi;
690+
/* fill slot and make note of the index */
691+
vsi->idx = pf->next_vsi;
692+
pf->vsi[pf->next_vsi] = vsi;
702693

703-
/* prepare pf->next_vsi for next use */
704-
pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
705-
pf->next_vsi);
706-
}
694+
/* prepare pf->next_vsi for next use */
695+
pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
696+
pf->next_vsi);
707697

708-
if (vsi->type == ICE_VSI_CTRL && vf)
709-
vf->ctrl_vsi_idx = vsi->idx;
698+
if (vsi->type == ICE_VSI_CTRL) {
699+
if (vf) {
700+
vf->ctrl_vsi_idx = vsi->idx;
701+
} else {
702+
WARN_ON(pf->ctrl_vsi_idx != ICE_NO_VSI);
703+
pf->ctrl_vsi_idx = vsi->idx;
704+
}
705+
}
710706

711707
unlock_pf:
712708
mutex_unlock(&pf->sw_mutex);

0 commit comments

Comments
 (0)