Commit 1fe8a3b6 authored by Jakub Kicinski's avatar Jakub Kicinski
Browse files
Tony Nguyen says:

====================
ice: various virtualization cleanups

Jacob Keller says:

This series contains a variety of refactors and cleanups in the VF code for
the ice driver. Its primary focus is cleanup and simplification of the VF
operations and addition of a few new operations that will be required by
Scalable IOV, as well as some other refactors needed for the handling of VF
subfunctions.

* '100GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue:
  ice: remove unnecessary virtchnl_ether_addr struct use
  ice: introduce .irq_close VF operation
  ice: introduce clear_reset_state operation
  ice: convert vf_ops .vsi_rebuild to .create_vsi
  ice: introduce ice_vf_init_host_cfg function
  ice: add a function to initialize vf entry
  ice: Pull common tasks into ice_vf_post_vsi_rebuild
  ice: move ice_vf_vsi_release into ice_vf_lib.c
  ice: move vsi_type assignment from ice_vsi_alloc to ice_vsi_cfg
  ice: refactor VSI setup to use parameter structure
  ice: drop unnecessary VF parameter from several VSI functions
  ice: fix function comment referring to ice_vsi_alloc
  ice: Add more usage of existing function ice_get_vf_vsi(vf)
====================

Link: https://lore.kernel.org/r/20230206214813.20107-1-anthony.l.nguyen@intel.com


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents cb6b2e11 e0645311
Loading
Loading
Loading
Loading
+16 −10
Original line number Diff line number Diff line
@@ -71,17 +71,17 @@ void ice_eswitch_replay_vf_mac_rule(struct ice_vf *vf)
	if (!ice_is_switchdev_running(vf->pf))
		return;

	if (is_valid_ether_addr(vf->hw_lan_addr.addr)) {
	if (is_valid_ether_addr(vf->hw_lan_addr)) {
		err = ice_eswitch_add_vf_mac_rule(vf->pf, vf,
						  vf->hw_lan_addr.addr);
						  vf->hw_lan_addr);
		if (err) {
			dev_err(ice_pf_to_dev(vf->pf), "Failed to add MAC %pM for VF %d\n, error %d\n",
				vf->hw_lan_addr.addr, vf->vf_id, err);
				vf->hw_lan_addr, vf->vf_id, err);
			return;
		}
		vf->num_mac++;

		ether_addr_copy(vf->dev_lan_addr.addr, vf->hw_lan_addr.addr);
		ether_addr_copy(vf->dev_lan_addr, vf->hw_lan_addr);
	}
}

@@ -237,7 +237,7 @@ ice_eswitch_release_reprs(struct ice_pf *pf, struct ice_vsi *ctrl_vsi)
		ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
		metadata_dst_free(vf->repr->dst);
		vf->repr->dst = NULL;
		ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr.addr,
		ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
					       ICE_FWD_TO_VSI);

		netif_napi_del(&vf->repr->q_vector->napi);
@@ -265,14 +265,14 @@ static int ice_eswitch_setup_reprs(struct ice_pf *pf)
						   GFP_KERNEL);
		if (!vf->repr->dst) {
			ice_fltr_add_mac_and_broadcast(vsi,
						       vf->hw_lan_addr.addr,
						       vf->hw_lan_addr,
						       ICE_FWD_TO_VSI);
			goto err;
		}

		if (ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof)) {
			ice_fltr_add_mac_and_broadcast(vsi,
						       vf->hw_lan_addr.addr,
						       vf->hw_lan_addr,
						       ICE_FWD_TO_VSI);
			metadata_dst_free(vf->repr->dst);
			vf->repr->dst = NULL;
@@ -281,7 +281,7 @@ static int ice_eswitch_setup_reprs(struct ice_pf *pf)

		if (ice_vsi_add_vlan_zero(vsi)) {
			ice_fltr_add_mac_and_broadcast(vsi,
						       vf->hw_lan_addr.addr,
						       vf->hw_lan_addr,
						       ICE_FWD_TO_VSI);
			metadata_dst_free(vf->repr->dst);
			vf->repr->dst = NULL;
@@ -338,7 +338,7 @@ void ice_eswitch_update_repr(struct ice_vsi *vsi)

	ret = ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof);
	if (ret) {
		ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr.addr, ICE_FWD_TO_VSI);
		ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr, ICE_FWD_TO_VSI);
		dev_err(ice_pf_to_dev(pf), "Failed to update VF %d port representor",
			vsi->vf->vf_id);
	}
@@ -425,7 +425,13 @@ static void ice_eswitch_release_env(struct ice_pf *pf)
static struct ice_vsi *
ice_eswitch_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
{
	return ice_vsi_setup(pf, pi, ICE_VSI_SWITCHDEV_CTRL, NULL, NULL);
	struct ice_vsi_cfg_params params = {};

	params.type = ICE_VSI_SWITCHDEV_CTRL;
	params.pi = pi;
	params.flags = ICE_VSI_FLAG_INIT;

	return ice_vsi_setup(pf, &params);
}

/**
+68 −70
Original line number Diff line number Diff line
@@ -166,14 +166,14 @@ static void ice_vsi_set_num_desc(struct ice_vsi *vsi)
/**
 * ice_vsi_set_num_qs - Set number of queues, descriptors and vectors for a VSI
 * @vsi: the VSI being configured
 * @vf: the VF associated with this VSI, if any
 *
 * Return 0 on success and a negative value on error
 */
static void ice_vsi_set_num_qs(struct ice_vsi *vsi, struct ice_vf *vf)
static void ice_vsi_set_num_qs(struct ice_vsi *vsi)
{
	enum ice_vsi_type vsi_type = vsi->type;
	struct ice_pf *pf = vsi->back;
	struct ice_vf *vf = vsi->vf;

	if (WARN_ON(vsi_type == ICE_VSI_VF && !vf))
		return;
@@ -594,15 +594,13 @@ static int ice_vsi_alloc_stat_arrays(struct ice_vsi *vsi)
/**
 * ice_vsi_alloc_def - set default values for already allocated VSI
 * @vsi: ptr to VSI
 * @vf: VF for ICE_VSI_VF and ICE_VSI_CTRL
 * @ch: ptr to channel
 */
static int
ice_vsi_alloc_def(struct ice_vsi *vsi, struct ice_vf *vf,
		  struct ice_channel *ch)
ice_vsi_alloc_def(struct ice_vsi *vsi, struct ice_channel *ch)
{
	if (vsi->type != ICE_VSI_CHNL) {
		ice_vsi_set_num_qs(vsi, vf);
		ice_vsi_set_num_qs(vsi);
		if (ice_vsi_alloc_arrays(vsi))
			return -ENOMEM;
	}
@@ -641,28 +639,18 @@ ice_vsi_alloc_def(struct ice_vsi *vsi, struct ice_vf *vf,
/**
 * ice_vsi_alloc - Allocates the next available struct VSI in the PF
 * @pf: board private structure
 * @pi: pointer to the port_info instance
 * @vsi_type: type of VSI
 * @ch: ptr to channel
 * @vf: VF for ICE_VSI_VF and ICE_VSI_CTRL
 *
 * The VF pointer is used for ICE_VSI_VF and ICE_VSI_CTRL. For ICE_VSI_CTRL,
 * it may be NULL in the case there is no association with a VF. For
 * ICE_VSI_VF the VF pointer *must not* be NULL.
 * Reserves a VSI index from the PF and allocates an empty VSI structure
 * without a type. The VSI structure must later be initialized by calling
 * ice_vsi_cfg().
 *
 * returns a pointer to a VSI on success, NULL on failure.
 */
static struct ice_vsi *
ice_vsi_alloc(struct ice_pf *pf, struct ice_port_info *pi,
	      enum ice_vsi_type vsi_type, struct ice_channel *ch,
	      struct ice_vf *vf)
static struct ice_vsi *ice_vsi_alloc(struct ice_pf *pf)
{
	struct device *dev = ice_pf_to_dev(pf);
	struct ice_vsi *vsi = NULL;

	if (WARN_ON(vsi_type == ICE_VSI_VF && !vf))
		return NULL;

	/* Need to protect the allocation of the VSIs at the PF level */
	mutex_lock(&pf->sw_mutex);

@@ -679,11 +667,7 @@ ice_vsi_alloc(struct ice_pf *pf, struct ice_port_info *pi,
	if (!vsi)
		goto unlock_pf;

	vsi->type = vsi_type;
	vsi->back = pf;
	vsi->port_info = pi;
	/* For VSIs which don't have a connected VF, this will be NULL */
	vsi->vf = vf;
	set_bit(ICE_VSI_DOWN, vsi->state);

	/* fill slot and make note of the index */
@@ -694,15 +678,6 @@ ice_vsi_alloc(struct ice_pf *pf, struct ice_port_info *pi,
	pf->next_vsi = ice_get_free_slot(pf->vsi, pf->num_alloc_vsi,
					 pf->next_vsi);

	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);
	return vsi;
@@ -1267,12 +1242,15 @@ ice_chnl_vsi_setup_q_map(struct ice_vsi *vsi, struct ice_vsi_ctx *ctxt)
/**
 * ice_vsi_init - Create and initialize a VSI
 * @vsi: the VSI being configured
 * @init_vsi: flag, tell if VSI need to be initialized
 * @vsi_flags: VSI configuration flags
 *
 * Set ICE_FLAG_VSI_INIT to initialize a new VSI context, clear it to
 * reconfigure an existing context.
 *
 * This initializes a VSI context depending on the VSI type to be added and
 * passes it down to the add_vsi aq command to create a new VSI.
 */
static int ice_vsi_init(struct ice_vsi *vsi, int init_vsi)
static int ice_vsi_init(struct ice_vsi *vsi, u32 vsi_flags)
{
	struct ice_pf *pf = vsi->back;
	struct ice_hw *hw = &pf->hw;
@@ -1334,7 +1312,7 @@ static int ice_vsi_init(struct ice_vsi *vsi, int init_vsi)
		/* if updating VSI context, make sure to set valid_section:
		 * to indicate which section of VSI context being updated
		 */
		if (!(init_vsi & ICE_VSI_FLAG_INIT))
		if (!(vsi_flags & ICE_VSI_FLAG_INIT))
			ctxt->info.valid_sections |=
				cpu_to_le16(ICE_AQ_VSI_PROP_Q_OPT_VALID);
	}
@@ -1347,7 +1325,7 @@ static int ice_vsi_init(struct ice_vsi *vsi, int init_vsi)
		if (ret)
			goto out;

		if (!(init_vsi & ICE_VSI_FLAG_INIT))
		if (!(vsi_flags & ICE_VSI_FLAG_INIT))
			/* means VSI being updated */
			/* must to indicate which section of VSI context are
			 * being modified
@@ -1363,7 +1341,7 @@ static int ice_vsi_init(struct ice_vsi *vsi, int init_vsi)
			cpu_to_le16(ICE_AQ_VSI_PROP_SECURITY_VALID);
	}

	if (init_vsi & ICE_VSI_FLAG_INIT) {
	if (vsi_flags & ICE_VSI_FLAG_INIT) {
		ret = ice_add_vsi(hw, vsi->idx, ctxt, NULL);
		if (ret) {
			dev_err(dev, "Add VSI failed, err %d\n", ret);
@@ -1527,7 +1505,7 @@ static int ice_get_vf_ctrl_res(struct ice_pf *pf, struct ice_vsi *vsi)
 * ice_vsi_setup_vector_base - Set up the base vector for the given VSI
 * @vsi: ptr to the VSI
 *
 * This should only be called after ice_vsi_alloc() which allocates the
 * This should only be called after ice_vsi_alloc_def() which allocates the
 * corresponding SW VSI structure and initializes num_queue_pairs for the
 * newly allocated VSI.
 *
@@ -2702,14 +2680,10 @@ static int ice_vsi_cfg_tc_lan(struct ice_pf *pf, struct ice_vsi *vsi)
/**
 * ice_vsi_cfg_def - configure default VSI based on the type
 * @vsi: pointer to VSI
 * @vf: pointer to VF to which this VSI connects. This field is used primarily
 *      for the ICE_VSI_VF type. Other VSI types should pass NULL.
 * @ch: ptr to channel
 * @init_vsi: is this an initialization or a reconfigure of the VSI
 * @params: the parameters to configure this VSI with
 */
static int
ice_vsi_cfg_def(struct ice_vsi *vsi, struct ice_vf *vf, struct ice_channel *ch,
		int init_vsi)
ice_vsi_cfg_def(struct ice_vsi *vsi, struct ice_vsi_cfg_params *params)
{
	struct device *dev = ice_pf_to_dev(vsi->back);
	struct ice_pf *pf = vsi->back;
@@ -2717,7 +2691,7 @@ ice_vsi_cfg_def(struct ice_vsi *vsi, struct ice_vf *vf, struct ice_channel *ch,

	vsi->vsw = pf->first_sw;

	ret = ice_vsi_alloc_def(vsi, vf, ch);
	ret = ice_vsi_alloc_def(vsi, params->ch);
	if (ret)
		return ret;

@@ -2740,7 +2714,7 @@ ice_vsi_cfg_def(struct ice_vsi *vsi, struct ice_vf *vf, struct ice_channel *ch,
	ice_vsi_set_tc_cfg(vsi);

	/* create the VSI */
	ret = ice_vsi_init(vsi, init_vsi);
	ret = ice_vsi_init(vsi, params->flags);
	if (ret)
		goto unroll_get_qs;

@@ -2863,19 +2837,25 @@ ice_vsi_cfg_def(struct ice_vsi *vsi, struct ice_vf *vf, struct ice_channel *ch,
}

/**
 * ice_vsi_cfg - configure VSI and tc on it
 * ice_vsi_cfg - configure a previously allocated VSI
 * @vsi: pointer to VSI
 * @vf: pointer to VF to which this VSI connects. This field is used primarily
 *      for the ICE_VSI_VF type. Other VSI types should pass NULL.
 * @ch: ptr to channel
 * @init_vsi: is this an initialization or a reconfigure of the VSI
 * @params: parameters used to configure this VSI
 */
int ice_vsi_cfg(struct ice_vsi *vsi, struct ice_vf *vf, struct ice_channel *ch,
		int init_vsi)
int ice_vsi_cfg(struct ice_vsi *vsi, struct ice_vsi_cfg_params *params)
{
	struct ice_pf *pf = vsi->back;
	int ret;

	ret = ice_vsi_cfg_def(vsi, vf, ch, init_vsi);
	if (WARN_ON(params->type == ICE_VSI_VF && !params->vf))
		return -EINVAL;

	vsi->type = params->type;
	vsi->port_info = params->pi;

	/* For VSIs which don't have a connected VF, this will be NULL */
	vsi->vf = params->vf;

	ret = ice_vsi_cfg_def(vsi, params);
	if (ret)
		return ret;

@@ -2883,6 +2863,16 @@ int ice_vsi_cfg(struct ice_vsi *vsi, struct ice_vf *vf, struct ice_channel *ch,
	if (ret)
		ice_vsi_decfg(vsi);

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

	return ret;
}

@@ -2946,11 +2936,7 @@ void ice_vsi_decfg(struct ice_vsi *vsi)
/**
 * ice_vsi_setup - Set up a VSI by a given type
 * @pf: board private structure
 * @pi: pointer to the port_info instance
 * @vsi_type: VSI type
 * @vf: pointer to VF to which this VSI connects. This field is used primarily
 *      for the ICE_VSI_VF type. Other VSI types should pass NULL.
 * @ch: ptr to channel
 * @params: parameters to use when creating the VSI
 *
 * This allocates the sw VSI structure and its queue resources.
 *
@@ -2958,21 +2944,26 @@ void ice_vsi_decfg(struct ice_vsi *vsi)
 * success, NULL on failure.
 */
struct ice_vsi *
ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
	      enum ice_vsi_type vsi_type, struct ice_vf *vf,
	      struct ice_channel *ch)
ice_vsi_setup(struct ice_pf *pf, struct ice_vsi_cfg_params *params)
{
	struct device *dev = ice_pf_to_dev(pf);
	struct ice_vsi *vsi;
	int ret;

	vsi = ice_vsi_alloc(pf, pi, vsi_type, ch, vf);
	/* ice_vsi_setup can only initialize a new VSI, and we must have
	 * a port_info structure for it.
	 */
	if (WARN_ON(!(params->flags & ICE_VSI_FLAG_INIT)) ||
	    WARN_ON(!params->pi))
		return NULL;

	vsi = ice_vsi_alloc(pf);
	if (!vsi) {
		dev_err(dev, "could not allocate VSI\n");
		return NULL;
	}

	ret = ice_vsi_cfg(vsi, vf, ch, ICE_VSI_FLAG_INIT);
	ret = ice_vsi_cfg(vsi, params);
	if (ret)
		goto err_vsi_cfg;

@@ -2997,7 +2988,7 @@ ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
	return vsi;

err_vsi_cfg:
	if (vsi_type == ICE_VSI_VF)
	if (params->type == ICE_VSI_VF)
		ice_enable_lag(pf->lag);
	ice_vsi_free(vsi);

@@ -3477,12 +3468,16 @@ ice_vsi_realloc_stat_arrays(struct ice_vsi *vsi, int prev_txq, int prev_rxq)
/**
 * ice_vsi_rebuild - Rebuild VSI after reset
 * @vsi: VSI to be rebuild
 * @init_vsi: flag, tell if VSI need to be initialized
 * @vsi_flags: flags used for VSI rebuild flow
 *
 * Set vsi_flags to ICE_VSI_FLAG_INIT to initialize a new VSI, or
 * ICE_VSI_FLAG_NO_INIT to rebuild an existing VSI in hardware.
 *
 * Returns 0 on success and negative value on failure
 */
int ice_vsi_rebuild(struct ice_vsi *vsi, int init_vsi)
int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags)
{
	struct ice_vsi_cfg_params params = {};
	struct ice_coalesce_stored *coalesce;
	int ret, prev_txq, prev_rxq;
	int prev_num_q_vectors = 0;
@@ -3491,6 +3486,9 @@ int ice_vsi_rebuild(struct ice_vsi *vsi, int init_vsi)
	if (!vsi)
		return -EINVAL;

	params = ice_vsi_to_params(vsi);
	params.flags = vsi_flags;

	pf = vsi->back;
	if (WARN_ON(vsi->type == ICE_VSI_VF && !vsi->vf))
		return -EINVAL;
@@ -3506,13 +3504,13 @@ int ice_vsi_rebuild(struct ice_vsi *vsi, int init_vsi)
	prev_rxq = vsi->num_rxq;

	ice_vsi_decfg(vsi);
	ret = ice_vsi_cfg_def(vsi, vsi->vf, vsi->ch, init_vsi);
	ret = ice_vsi_cfg_def(vsi, &params);
	if (ret)
		goto err_vsi_cfg;

	ret = ice_vsi_cfg_tc_lan(pf, vsi);
	if (ret) {
		if (init_vsi & ICE_VSI_FLAG_INIT) {
		if (vsi_flags & ICE_VSI_FLAG_INIT) {
			ret = -EIO;
			goto err_vsi_cfg_tc_lan;
		} else {
+44 −8
Original line number Diff line number Diff line
@@ -7,6 +7,47 @@
#include "ice.h"
#include "ice_vlan.h"

/* Flags used for VSI configuration and rebuild */
#define ICE_VSI_FLAG_INIT	BIT(0)
#define ICE_VSI_FLAG_NO_INIT	0

/**
 * struct ice_vsi_cfg_params - VSI configuration parameters
 * @pi: pointer to the port_info instance for the VSI
 * @ch: pointer to the channel structure for the VSI, may be NULL
 * @vf: pointer to the VF associated with this VSI, may be NULL
 * @type: the type of VSI to configure
 * @flags: VSI flags used for rebuild and configuration
 *
 * Parameter structure used when configuring a new VSI.
 */
struct ice_vsi_cfg_params {
	struct ice_port_info *pi;
	struct ice_channel *ch;
	struct ice_vf *vf;
	enum ice_vsi_type type;
	u32 flags;
};

/**
 * ice_vsi_to_params - Get parameters for an existing VSI
 * @vsi: the VSI to get parameters for
 *
 * Fill a parameter structure for reconfiguring a VSI with its current
 * parameters, such as during a rebuild operation.
 */
static inline struct ice_vsi_cfg_params ice_vsi_to_params(struct ice_vsi *vsi)
{
	struct ice_vsi_cfg_params params = {};

	params.pi = vsi->port_info;
	params.ch = vsi->ch;
	params.vf = vsi->vf;
	params.type = vsi->type;

	return params;
}

const char *ice_vsi_type_str(enum ice_vsi_type vsi_type);

bool ice_pf_state_is_nominal(struct ice_pf *pf);
@@ -50,9 +91,7 @@ int ice_vsi_cfg_rss_lut_key(struct ice_vsi *vsi);
void ice_vsi_cfg_netdev_tc(struct ice_vsi *vsi, u8 ena_tc);

struct ice_vsi *
ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
	      enum ice_vsi_type vsi_type, struct ice_vf *vf,
	      struct ice_channel *ch);
ice_vsi_setup(struct ice_pf *pf, struct ice_vsi_cfg_params *params);

void ice_napi_del(struct ice_vsi *vsi);

@@ -70,11 +109,8 @@ int ice_free_res(struct ice_res_tracker *res, u16 index, u16 id);
int
ice_get_res(struct ice_pf *pf, struct ice_res_tracker *res, u16 needed, u16 id);

#define ICE_VSI_FLAG_INIT	BIT(0)
#define ICE_VSI_FLAG_NO_INIT	0
int ice_vsi_rebuild(struct ice_vsi *vsi, int init_vsi);
int ice_vsi_cfg(struct ice_vsi *vsi, struct ice_vf *vf,
		struct ice_channel *ch, int init_vsi);
int ice_vsi_rebuild(struct ice_vsi *vsi, u32 vsi_flags);
int ice_vsi_cfg(struct ice_vsi *vsi, struct ice_vsi_cfg_params *params);

bool ice_is_reset_in_progress(unsigned long *state);
int ice_wait_for_reset(struct ice_pf *pf, unsigned long timeout);
+36 −6
Original line number Diff line number Diff line
@@ -537,7 +537,7 @@ ice_prepare_for_reset(struct ice_pf *pf, enum ice_reset_req reset_type)
	/* Disable VFs until reset is completed */
	mutex_lock(&pf->vfs.table_lock);
	ice_for_each_vf(pf, bkt, vf)
		ice_set_vf_state_qs_dis(vf);
		ice_set_vf_state_dis(vf);
	mutex_unlock(&pf->vfs.table_lock);

	if (ice_is_eswitch_mode_switchdev(pf)) {
@@ -3447,14 +3447,27 @@ void ice_fill_rss_lut(u8 *lut, u16 rss_table_size, u16 rss_size)
static struct ice_vsi *
ice_pf_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
{
	return ice_vsi_setup(pf, pi, ICE_VSI_PF, NULL, NULL);
	struct ice_vsi_cfg_params params = {};

	params.type = ICE_VSI_PF;
	params.pi = pi;
	params.flags = ICE_VSI_FLAG_INIT;

	return ice_vsi_setup(pf, &params);
}

static struct ice_vsi *
ice_chnl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
		   struct ice_channel *ch)
{
	return ice_vsi_setup(pf, pi, ICE_VSI_CHNL, NULL, ch);
	struct ice_vsi_cfg_params params = {};

	params.type = ICE_VSI_CHNL;
	params.pi = pi;
	params.ch = ch;
	params.flags = ICE_VSI_FLAG_INIT;

	return ice_vsi_setup(pf, &params);
}

/**
@@ -3468,7 +3481,13 @@ ice_chnl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
static struct ice_vsi *
ice_ctrl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
{
	return ice_vsi_setup(pf, pi, ICE_VSI_CTRL, NULL, NULL);
	struct ice_vsi_cfg_params params = {};

	params.type = ICE_VSI_CTRL;
	params.pi = pi;
	params.flags = ICE_VSI_FLAG_INIT;

	return ice_vsi_setup(pf, &params);
}

/**
@@ -3482,7 +3501,13 @@ ice_ctrl_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
struct ice_vsi *
ice_lb_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi)
{
	return ice_vsi_setup(pf, pi, ICE_VSI_LB, NULL, NULL);
	struct ice_vsi_cfg_params params = {};

	params.type = ICE_VSI_LB;
	params.pi = pi;
	params.flags = ICE_VSI_FLAG_INIT;

	return ice_vsi_setup(pf, &params);
}

/**
@@ -5002,6 +5027,7 @@ static void ice_deinit(struct ice_pf *pf)
 */
int ice_load(struct ice_pf *pf)
{
	struct ice_vsi_cfg_params params = {};
	struct ice_vsi *vsi;
	int err;

@@ -5014,7 +5040,11 @@ int ice_load(struct ice_pf *pf)
		return err;

	vsi = ice_get_main_vsi(pf);
	err = ice_vsi_cfg(vsi, NULL, NULL, ICE_VSI_FLAG_INIT);

	params = ice_vsi_to_params(vsi);
	params.flags = ICE_VSI_FLAG_INIT;

	err = ice_vsi_cfg(vsi, &params);
	if (err)
		goto err_vsi_cfg;

+45 −88
Original line number Diff line number Diff line
@@ -40,21 +40,6 @@ static void ice_free_vf_entries(struct ice_pf *pf)
	}
}

/**
 * ice_vf_vsi_release - invalidate the VF's VSI after freeing it
 * @vf: invalidate this VF's VSI after freeing it
 */
static void ice_vf_vsi_release(struct ice_vf *vf)
{
	struct ice_vsi *vsi = ice_get_vf_vsi(vf);

	if (WARN_ON(!vsi))
		return;

	ice_vsi_release(vsi);
	ice_vf_invalidate_vsi(vf);
}

/**
 * ice_free_vf_res - Free a VF's resources
 * @vf: pointer to the VF info
@@ -248,11 +233,16 @@ void ice_free_vfs(struct ice_pf *pf)
 */
static struct ice_vsi *ice_vf_vsi_setup(struct ice_vf *vf)
{
	struct ice_port_info *pi = ice_vf_get_port_info(vf);
	struct ice_vsi_cfg_params params = {};
	struct ice_pf *pf = vf->pf;
	struct ice_vsi *vsi;

	vsi = ice_vsi_setup(pf, pi, ICE_VSI_VF, vf, NULL);
	params.type = ICE_VSI_VF;
	params.pi = ice_vf_get_port_info(vf);
	params.vf = vf;
	params.flags = ICE_VSI_FLAG_INIT;

	vsi = ice_vsi_setup(pf, &params);

	if (!vsi) {
		dev_err(ice_pf_to_dev(pf), "Failed to create VF VSI\n");
@@ -583,51 +573,19 @@ static int ice_set_per_vf_res(struct ice_pf *pf, u16 num_vfs)
 */
static int ice_init_vf_vsi_res(struct ice_vf *vf)
{
	struct ice_vsi_vlan_ops *vlan_ops;
	struct ice_pf *pf = vf->pf;
	u8 broadcast[ETH_ALEN];
	struct ice_vsi *vsi;
	struct device *dev;
	int err;

	vf->first_vector_idx = ice_calc_vf_first_vector_idx(pf, vf);

	dev = ice_pf_to_dev(pf);
	vsi = ice_vf_vsi_setup(vf);
	if (!vsi)
		return -ENOMEM;

	err = ice_vsi_add_vlan_zero(vsi);
	if (err) {
		dev_warn(dev, "Failed to add VLAN 0 filter for VF %d\n",
			 vf->vf_id);
		goto release_vsi;
	}

	vlan_ops = ice_get_compat_vsi_vlan_ops(vsi);
	err = vlan_ops->ena_rx_filtering(vsi);
	if (err) {
		dev_warn(dev, "Failed to enable Rx VLAN filtering for VF %d\n",
			 vf->vf_id);
		goto release_vsi;
	}

	eth_broadcast_addr(broadcast);
	err = ice_fltr_add_mac(vsi, broadcast, ICE_FWD_TO_VSI);
	if (err) {
		dev_err(dev, "Failed to add broadcast MAC filter for VF %d, error %d\n",
			vf->vf_id, err);
		goto release_vsi;
	}

	err = ice_vsi_apply_spoofchk(vsi, vf->spoofchk);
	if (err) {
		dev_warn(dev, "Failed to initialize spoofchk setting for VF %d\n",
			 vf->vf_id);
	err = ice_vf_init_host_cfg(vf, vsi);
	if (err)
		goto release_vsi;
	}

	vf->num_mac = 1;

	return 0;

@@ -696,6 +654,21 @@ static void ice_sriov_free_vf(struct ice_vf *vf)
	kfree_rcu(vf, rcu);
}

/**
 * ice_sriov_clear_reset_state - clears VF Reset status register
 * @vf: the vf to configure
 */
static void ice_sriov_clear_reset_state(struct ice_vf *vf)
{
	struct ice_hw *hw = &vf->pf->hw;

	/* Clear the reset status register so that VF immediately sees that
	 * the device is resetting, even if hardware hasn't yet gotten around
	 * to clearing VFGEN_RSTAT for us.
	 */
	wr32(hw, VFGEN_RSTAT(vf->vf_id), VIRTCHNL_VFR_INPROGRESS);
}

/**
 * ice_sriov_clear_mbx_register - clears SRIOV VF's mailbox registers
 * @vf: the vf to configure
@@ -799,23 +772,19 @@ static void ice_sriov_clear_reset_trigger(struct ice_vf *vf)
}

/**
 * ice_sriov_vsi_rebuild - release and rebuild VF's VSI
 * @vf: VF to release and setup the VSI for
 * ice_sriov_create_vsi - Create a new VSI for a VF
 * @vf: VF to create the VSI for
 *
 * This is only called when a single VF is being reset (i.e. VFR, VFLR, host VF
 * configuration change, etc.).
 * This is called by ice_vf_recreate_vsi to create the new VSI after the old
 * VSI has been released.
 */
static int ice_sriov_vsi_rebuild(struct ice_vf *vf)
static int ice_sriov_create_vsi(struct ice_vf *vf)
{
	struct ice_pf *pf = vf->pf;
	struct ice_vsi *vsi;

	ice_vf_vsi_release(vf);
	if (!ice_vf_vsi_setup(vf)) {
		dev_err(ice_pf_to_dev(pf),
			"Failed to release and setup the VF%u's VSI\n",
			vf->vf_id);
	vsi = ice_vf_vsi_setup(vf);
	if (!vsi)
		return -ENOMEM;
	}

	return 0;
}
@@ -826,8 +795,6 @@ static int ice_sriov_vsi_rebuild(struct ice_vf *vf)
 */
static void ice_sriov_post_vsi_rebuild(struct ice_vf *vf)
{
	ice_vf_rebuild_host_cfg(vf);
	ice_vf_set_initialized(vf);
	ice_ena_vf_mappings(vf);
	wr32(&vf->pf->hw, VFGEN_RSTAT(vf->vf_id), VIRTCHNL_VFR_VFACTIVE);
}
@@ -835,11 +802,13 @@ static void ice_sriov_post_vsi_rebuild(struct ice_vf *vf)
static const struct ice_vf_ops ice_sriov_vf_ops = {
	.reset_type = ICE_VF_RESET,
	.free = ice_sriov_free_vf,
	.clear_reset_state = ice_sriov_clear_reset_state,
	.clear_mbx_register = ice_sriov_clear_mbx_register,
	.trigger_reset_register = ice_sriov_trigger_reset_register,
	.poll_reset_status = ice_sriov_poll_reset_status,
	.clear_reset_trigger = ice_sriov_clear_reset_trigger,
	.vsi_rebuild = ice_sriov_vsi_rebuild,
	.irq_close = NULL,
	.create_vsi = ice_sriov_create_vsi,
	.post_vsi_rebuild = ice_sriov_post_vsi_rebuild,
};

@@ -879,21 +848,9 @@ static int ice_create_vf_entries(struct ice_pf *pf, u16 num_vfs)
		/* set sriov vf ops for VFs created during SRIOV flow */
		vf->vf_ops = &ice_sriov_vf_ops;

		vf->vf_sw_id = pf->first_sw;
		/* assign default capabilities */
		vf->spoofchk = true;
		vf->num_vf_qs = pf->vfs.num_qps_per;
		ice_vc_set_default_allowlist(vf);

		/* ctrl_vsi_idx will be set to a valid value only when VF
		 * creates its first fdir rule.
		 */
		ice_vf_ctrl_invalidate_vsi(vf);
		ice_vf_fdir_init(vf);

		ice_virtchnl_set_dflt_ops(vf);
		ice_initialize_vf_entry(vf);

		mutex_init(&vf->cfg_lock);
		vf->vf_sw_id = pf->first_sw;

		hash_add_rcu(vfs->table, &vf->entry, vf_id);
	}
@@ -1285,7 +1242,7 @@ ice_get_vf_cfg(struct net_device *netdev, int vf_id, struct ifla_vf_info *ivi)
		goto out_put_vf;

	ivi->vf = vf_id;
	ether_addr_copy(ivi->mac, vf->hw_lan_addr.addr);
	ether_addr_copy(ivi->mac, vf->hw_lan_addr);

	/* VF configuration for VLAN and applicable QoS */
	ivi->vlan = ice_vf_get_port_vlan_id(vf);
@@ -1333,8 +1290,8 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
		return -EINVAL;

	/* nothing left to do, unicast MAC already set */
	if (ether_addr_equal(vf->dev_lan_addr.addr, mac) &&
	    ether_addr_equal(vf->hw_lan_addr.addr, mac)) {
	if (ether_addr_equal(vf->dev_lan_addr, mac) &&
	    ether_addr_equal(vf->hw_lan_addr, mac)) {
		ret = 0;
		goto out_put_vf;
	}
@@ -1348,8 +1305,8 @@ int ice_set_vf_mac(struct net_device *netdev, int vf_id, u8 *mac)
	/* VF is notified of its new MAC via the PF's response to the
	 * VIRTCHNL_OP_GET_VF_RESOURCES message after the VF has been reset
	 */
	ether_addr_copy(vf->dev_lan_addr.addr, mac);
	ether_addr_copy(vf->hw_lan_addr.addr, mac);
	ether_addr_copy(vf->dev_lan_addr, mac);
	ether_addr_copy(vf->hw_lan_addr, mac);
	if (is_zero_ether_addr(mac)) {
		/* VF will send VIRTCHNL_OP_ADD_ETH_ADDR message with its MAC */
		vf->pf_set_mac = false;
@@ -1750,7 +1707,7 @@ void ice_print_vf_rx_mdd_event(struct ice_vf *vf)

	dev_info(dev, "%d Rx Malicious Driver Detection events detected on PF %d VF %d MAC %pM. mdd-auto-reset-vfs=%s\n",
		 vf->mdd_rx_events.count, pf->hw.pf_id, vf->vf_id,
		 vf->dev_lan_addr.addr,
		 vf->dev_lan_addr,
		 test_bit(ICE_FLAG_MDD_AUTO_RESET_VF, pf->flags)
			  ? "on" : "off");
}
@@ -1794,7 +1751,7 @@ void ice_print_vfs_mdd_events(struct ice_pf *pf)

			dev_info(dev, "%d Tx Malicious Driver Detection events detected on PF %d VF %d MAC %pM.\n",
				 vf->mdd_tx_events.count, hw->pf_id, vf->vf_id,
				 vf->dev_lan_addr.addr);
				 vf->dev_lan_addr);
		}
	}
	mutex_unlock(&pf->vfs.table_lock);
@@ -1884,7 +1841,7 @@ ice_is_malicious_vf(struct ice_pf *pf, struct ice_rq_event_info *event,

			if (pf_vsi)
				dev_warn(dev, "VF MAC %pM on PF MAC %pM is generating asynchronous messages and may be overflowing the PF message queue. Please see the Adapter User Guide for more information\n",
					 &vf->dev_lan_addr.addr[0],
					 &vf->dev_lan_addr[0],
					 pf_vsi->netdev->dev_addr);
		}
	}
Loading