Commit a696d615 authored by Jacob Keller's avatar Jacob Keller Committed by Tony Nguyen
Browse files

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: default avatarJacob Keller <jacob.e.keller@intel.com>
Signed-off-by: default avatarMichal Swiatkowski <michal.swiatkowski@linux.intel.com>
Tested-by: Gurucharan G <gurucharanx.g@intel.com> (A Contingent worker at Intel)
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
parent 6624e780
Loading
Loading
Loading
Loading
+15 −19
Original line number Diff line number Diff line
@@ -479,9 +479,6 @@ int ice_vsi_free(struct ice_vsi *vsi)
	/* updates the PF for this cleared VSI */

	pf->vsi[vsi->idx] = NULL;
	if (vsi->idx < pf->next_vsi && vsi->type != ICE_VSI_CTRL)
		pf->next_vsi = vsi->idx;
	if (vsi->idx < pf->next_vsi && vsi->type == ICE_VSI_CTRL && vsi->vf)
	pf->next_vsi = vsi->idx;

	ice_vsi_free_stats(vsi);
@@ -690,12 +687,6 @@ ice_vsi_alloc(struct ice_pf *pf, struct ice_port_info *pi,
	vsi->vf = vf;
	set_bit(ICE_VSI_DOWN, vsi->state);

	if (vsi->type == ICE_VSI_CTRL && !vf) {
		/* Use the last VSI slot as the index for PF control VSI */
		vsi->idx = pf->num_alloc_vsi - 1;
		pf->ctrl_vsi_idx = vsi->idx;
		pf->vsi[vsi->idx] = vsi;
	} else {
	/* fill slot and make note of the index */
	vsi->idx = pf->next_vsi;
	pf->vsi[pf->next_vsi] = vsi;
@@ -703,10 +694,15 @@ ice_vsi_alloc(struct ice_pf *pf, struct ice_port_info *pi,
	/* prepare pf->next_vsi for next use */
	pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
					 pf->next_vsi);
	}

	if (vsi->type == ICE_VSI_CTRL && vf)
	if (vsi->type == ICE_VSI_CTRL) {
		if (vf) {
			vf->ctrl_vsi_idx = vsi->idx;
		} else {
			WARN_ON(pf->ctrl_vsi_idx != ICE_NO_VSI);
			pf->ctrl_vsi_idx = vsi->idx;
		}
	}

unlock_pf:
	mutex_unlock(&pf->sw_mutex);