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

====================
i40e: cleanups & refactors

Ivan Vecera says:

This series do following:
Patch 1 - Removes write-only flags field from i40e_veb structure and
          from i40e_veb_setup() parameters
Patch 2 - Refactors parameter of i40e_notify_client_of_l2_param_changes()
          and i40e_notify_client_of_netdev_close()
Patch 3 - Refactors parameter of i40e_detect_recover_hung()
Patch 4 - Adds helper i40e_pf_get_main_vsi() to get main VSI and uses it
          in existing code
Patch 5 - Consolidates checks whether given VSI is the main one
Patch 6 - Adds helper i40e_pf_get_main_veb() to get main VEB and uses it
          in existing code
Patch 7 - Adds helper i40e_vsi_reconfig_tc() to reconfigure TC for
          particular and uses it to replace existing open-coded pieces

* '40GbE' of git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue:
  i40e: Add and use helper to reconfigure TC for given VSI
  i40e: Add helper to access main VEB
  i40e: Consolidate checks whether given VSI is main
  i40e: Add helper to access main VSI
  i40e: Refactor argument of i40e_detect_recover_hung()
  i40e: Refactor argument of several client notification functions
  i40e: Remove flags field from i40e_veb
====================

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


Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parents 86735b57 29385de3
Loading
Loading
Loading
Loading
+25 −4
Original line number Diff line number Diff line
@@ -788,7 +788,6 @@ struct i40e_veb {
	u16 stats_idx;		/* index of VEB parent */
	u8  enabled_tc;
	u16 bridge_mode;	/* Bridge Mode (VEB/VEPA) */
	u16 flags;
	u16 bw_limit;
	u8  bw_max_quanta;
	bool is_abs_credits;
@@ -1213,7 +1212,7 @@ void i40e_vsi_stop_rings(struct i40e_vsi *vsi);
void i40e_vsi_stop_rings_no_wait(struct  i40e_vsi *vsi);
int i40e_vsi_wait_queues_disabled(struct i40e_vsi *vsi);
int i40e_reconfig_rss_queues(struct i40e_pf *pf, int queue_count);
struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 flags, u16 uplink_seid,
struct i40e_veb *i40e_veb_setup(struct i40e_pf *pf, u16 uplink_seid,
				u16 downlink_seid, u8 enabled_tc);
void i40e_veb_release(struct i40e_veb *veb);

@@ -1237,8 +1236,8 @@ static inline void i40e_dbg_exit(void) {}
int i40e_lan_add_device(struct i40e_pf *pf);
int i40e_lan_del_device(struct i40e_pf *pf);
void i40e_client_subtask(struct i40e_pf *pf);
void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi);
void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset);
void i40e_notify_client_of_l2_param_changes(struct i40e_pf *pf);
void i40e_notify_client_of_netdev_close(struct i40e_pf *pf, bool reset);
void i40e_notify_client_of_vf_enable(struct i40e_pf *pf, u32 num_vfs);
void i40e_notify_client_of_vf_reset(struct i40e_pf *pf, u32 vf_id);
void i40e_client_update_msix_info(struct i40e_pf *pf);
@@ -1373,6 +1372,17 @@ i40e_pf_get_vsi_by_seid(struct i40e_pf *pf, u16 seid)
	return NULL;
}

/**
 * i40e_pf_get_main_vsi - get pointer to main VSI
 * @pf: pointer to a PF
 *
 * Return: pointer to main VSI or NULL if it does not exist
 **/
static inline struct i40e_vsi *i40e_pf_get_main_vsi(struct i40e_pf *pf)
{
	return (pf->lan_vsi != I40E_NO_VSI) ? pf->vsi[pf->lan_vsi] : NULL;
}

/**
 * i40e_pf_get_veb_by_seid - find VEB by SEID
 * @pf: pointer to a PF
@@ -1391,4 +1401,15 @@ i40e_pf_get_veb_by_seid(struct i40e_pf *pf, u16 seid)
	return NULL;
}

/**
 * i40e_pf_get_main_veb - get pointer to main VEB
 * @pf: pointer to a PF
 *
 * Return: pointer to main VEB or NULL if it does not exist
 **/
static inline struct i40e_veb *i40e_pf_get_main_veb(struct i40e_pf *pf)
{
	return (pf->lan_veb != I40E_NO_VEB) ? pf->veb[pf->lan_veb] : NULL;
}

#endif /* _I40E_H_ */
+14 −14
Original line number Diff line number Diff line
@@ -101,25 +101,26 @@ i40e_notify_client_of_vf_msg(struct i40e_vsi *vsi, u32 vf_id, u8 *msg, u16 len)

/**
 * i40e_notify_client_of_l2_param_changes - call the client notify callback
 * @vsi: the VSI with l2 param changes
 * @pf: PF device pointer
 *
 * If there is a client to this VSI, call the client
 * If there is a client, call its callback
 **/
void i40e_notify_client_of_l2_param_changes(struct i40e_vsi *vsi)
void i40e_notify_client_of_l2_param_changes(struct i40e_pf *pf)
{
	struct i40e_pf *pf = vsi->back;
	struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
	struct i40e_client_instance *cdev = pf->cinst;
	struct i40e_params params;

	if (!cdev || !cdev->client)
		return;
	if (!cdev->client->ops || !cdev->client->ops->l2_param_change) {
		dev_dbg(&vsi->back->pdev->dev,
		dev_dbg(&pf->pdev->dev,
			"Cannot locate client instance l2_param_change routine\n");
		return;
	}
	if (!test_bit(__I40E_CLIENT_INSTANCE_OPENED, &cdev->state)) {
		dev_dbg(&vsi->back->pdev->dev, "Client is not open, abort l2 param change\n");
		dev_dbg(&pf->pdev->dev,
			"Client is not open, abort l2 param change\n");
		return;
	}
	memset(&params, 0, sizeof(params));
@@ -157,20 +158,19 @@ static void i40e_client_release_qvlist(struct i40e_info *ldev)

/**
 * i40e_notify_client_of_netdev_close - call the client close callback
 * @vsi: the VSI with netdev closed
 * @pf: PF device pointer
 * @reset: true when close called due to a reset pending
 *
 * If there is a client to this netdev, call the client with close
 **/
void i40e_notify_client_of_netdev_close(struct i40e_vsi *vsi, bool reset)
void i40e_notify_client_of_netdev_close(struct i40e_pf *pf, bool reset)
{
	struct i40e_pf *pf = vsi->back;
	struct i40e_client_instance *cdev = pf->cinst;

	if (!cdev || !cdev->client)
		return;
	if (!cdev->client->ops || !cdev->client->ops->close) {
		dev_dbg(&vsi->back->pdev->dev,
		dev_dbg(&pf->pdev->dev,
			"Cannot locate client instance close routine\n");
		return;
	}
@@ -333,9 +333,9 @@ static int i40e_register_auxiliary_dev(struct i40e_info *ldev, const char *name)
 **/
static void i40e_client_add_instance(struct i40e_pf *pf)
{
	struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
	struct i40e_client_instance *cdev = NULL;
	struct netdev_hw_addr *mac = NULL;
	struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];

	cdev = kzalloc(sizeof(*cdev), GFP_KERNEL);
	if (!cdev)
@@ -399,9 +399,9 @@ void i40e_client_del_instance(struct i40e_pf *pf)
 **/
void i40e_client_subtask(struct i40e_pf *pf)
{
	struct i40e_client *client;
	struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
	struct i40e_client_instance *cdev;
	struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
	struct i40e_client *client;
	int ret = 0;

	if (!test_and_clear_bit(__I40E_CLIENT_SERVICE_REQUESTED, pf->state))
@@ -665,8 +665,8 @@ static int i40e_client_update_vsi_ctxt(struct i40e_info *ldev,
				       bool is_vf, u32 vf_id,
				       u32 flag, u32 valid_flag)
{
	struct i40e_vsi *vsi = i40e_pf_get_main_vsi(ldev->pf);
	struct i40e_pf *pf = ldev->pf;
	struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
	struct i40e_vsi_context ctxt;
	bool update = true;
	int err;
+2 −1
Original line number Diff line number Diff line
@@ -407,8 +407,9 @@ static int i40e_ddp_load(struct net_device *netdev, const u8 *data, size_t size,
 **/
static int i40e_ddp_restore(struct i40e_pf *pf)
{
	struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);
	struct net_device *netdev = vsi->netdev;
	struct i40e_ddp_old_profile_list *entry;
	struct net_device *netdev = pf->vsi[pf->lan_vsi]->netdev;
	int status = 0;

	if (!list_empty(&pf->ddp_old_prof)) {
+20 −16
Original line number Diff line number Diff line
@@ -53,6 +53,7 @@ static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer,
				     size_t count, loff_t *ppos)
{
	struct i40e_pf *pf = filp->private_data;
	struct i40e_vsi *main_vsi;
	int bytes_not_copied;
	int buf_size = 256;
	char *buf;
@@ -68,8 +69,8 @@ static ssize_t i40e_dbg_command_read(struct file *filp, char __user *buffer,
	if (!buf)
		return -ENOSPC;

	len = snprintf(buf, buf_size, "%s: %s\n",
		       pf->vsi[pf->lan_vsi]->netdev->name,
	main_vsi = i40e_pf_get_main_vsi(pf);
	len = snprintf(buf, buf_size, "%s: %s\n", main_vsi->netdev->name,
		       i40e_dbg_command_buf);

	bytes_not_copied = copy_to_user(buffer, buf, len);
@@ -128,7 +129,7 @@ static void i40e_dbg_dump_vsi_seid(struct i40e_pf *pf, int seid)
		dev_info(&pf->pdev->dev,
			 "    state[%d] = %08lx\n",
			 i, vsi->state[i]);
	if (vsi == pf->vsi[pf->lan_vsi])
	if (vsi->type == I40E_VSI_MAIN)
		dev_info(&pf->pdev->dev, "    MAC address: %pM Port MAC: %pM\n",
			 pf->hw.mac.addr,
			 pf->hw.mac.port_addr);
@@ -786,7 +787,8 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
		cnt = sscanf(&cmd_buf[7], "%i", &vsi_seid);
		if (cnt == 0) {
			/* default to PF VSI */
			vsi_seid = pf->vsi[pf->lan_vsi]->seid;
			vsi = i40e_pf_get_main_vsi(pf);
			vsi_seid = vsi->seid;
		} else if (vsi_seid < 0) {
			dev_info(&pf->pdev->dev, "add VSI %d: bad vsi seid\n",
				 vsi_seid);
@@ -867,7 +869,7 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
			goto command_write_done;
		}

		veb = i40e_veb_setup(pf, 0, uplink_seid, vsi_seid, enabled_tc);
		veb = i40e_veb_setup(pf, uplink_seid, vsi_seid, enabled_tc);
		if (veb)
			dev_info(&pf->pdev->dev, "added relay %d\n", veb->seid);
		else
@@ -1030,7 +1032,7 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
				goto command_write_done;
			}

			vsi = pf->vsi[pf->lan_vsi];
			vsi = i40e_pf_get_main_vsi(pf);
			switch_id =
				le16_to_cpu(vsi->info.switch_id) &
					    I40E_AQ_VSI_SW_ID_MASK;
@@ -1380,6 +1382,9 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
		dev_info(&pf->pdev->dev, "FD current total filter count for this interface: %d\n",
			 i40e_get_current_fd_count(pf));
	} else if (strncmp(cmd_buf, "lldp", 4) == 0) {
		/* Get main VSI */
		struct i40e_vsi *main_vsi = i40e_pf_get_main_vsi(pf);

		if (strncmp(&cmd_buf[5], "stop", 4) == 0) {
			int ret;

@@ -1391,10 +1396,9 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
				goto command_write_done;
			}
			ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
						pf->hw.mac.addr,
						ETH_P_LLDP, 0,
						pf->vsi[pf->lan_vsi]->seid,
						0, true, NULL, NULL);
						pf->hw.mac.addr, ETH_P_LLDP, 0,
						main_vsi->seid, 0, true, NULL,
						NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					"%s: Add Control Packet Filter AQ command failed =0x%x\n",
@@ -1409,10 +1413,9 @@ static ssize_t i40e_dbg_command_write(struct file *filp,
			int ret;

			ret = i40e_aq_add_rem_control_packet_filter(&pf->hw,
						pf->hw.mac.addr,
						ETH_P_LLDP, 0,
						pf->vsi[pf->lan_vsi]->seid,
						0, false, NULL, NULL);
						pf->hw.mac.addr, ETH_P_LLDP, 0,
						main_vsi->seid, 0, false, NULL,
						NULL);
			if (ret) {
				dev_info(&pf->pdev->dev,
					"%s: Remove Control Packet Filter AQ command failed =0x%x\n",
@@ -1639,6 +1642,7 @@ static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
					size_t count, loff_t *ppos)
{
	struct i40e_pf *pf = filp->private_data;
	struct i40e_vsi *main_vsi;
	int bytes_not_copied;
	int buf_size = 256;
	char *buf;
@@ -1654,8 +1658,8 @@ static ssize_t i40e_dbg_netdev_ops_read(struct file *filp, char __user *buffer,
	if (!buf)
		return -ENOSPC;

	len = snprintf(buf, buf_size, "%s: %s\n",
		       pf->vsi[pf->lan_vsi]->netdev->name,
	main_vsi = i40e_pf_get_main_vsi(pf);
	len = snprintf(buf, buf_size, "%s: %s\n", main_vsi->netdev->name,
		       i40e_dbg_netdev_ops_buf);

	bytes_not_copied = copy_to_user(buffer, buf, len);
+13 −16
Original line number Diff line number Diff line
@@ -1241,7 +1241,7 @@ static int i40e_set_link_ksettings(struct net_device *netdev,
		i40e_partition_setting_complaint(pf);
		return -EOPNOTSUPP;
	}
	if (vsi != pf->vsi[pf->lan_vsi])
	if (vsi->type != I40E_VSI_MAIN)
		return -EOPNOTSUPP;
	if (hw->phy.media_type != I40E_MEDIA_TYPE_BASET &&
	    hw->phy.media_type != I40E_MEDIA_TYPE_FIBER &&
@@ -1710,7 +1710,7 @@ static int i40e_set_pauseparam(struct net_device *netdev,
		return -EOPNOTSUPP;
	}

	if (vsi != pf->vsi[pf->lan_vsi])
	if (vsi->type != I40E_VSI_MAIN)
		return -EOPNOTSUPP;

	is_an = hw_link_info->an_info & I40E_AQ_AN_COMPLETED;
@@ -2029,7 +2029,7 @@ static void i40e_get_ringparam(struct net_device *netdev,
{
	struct i40e_netdev_priv *np = netdev_priv(netdev);
	struct i40e_pf *pf = np->vsi->back;
	struct i40e_vsi *vsi = pf->vsi[pf->lan_vsi];
	struct i40e_vsi *vsi = i40e_pf_get_main_vsi(pf);

	ring->rx_max_pending = i40e_get_max_num_descriptors(pf);
	ring->tx_max_pending = i40e_get_max_num_descriptors(pf);
@@ -2292,7 +2292,7 @@ static int i40e_get_stats_count(struct net_device *netdev)
	struct i40e_pf *pf = vsi->back;
	int stats_len;

	if (vsi == pf->vsi[pf->lan_vsi] && pf->hw.partition_id == 1)
	if (vsi->type == I40E_VSI_MAIN && pf->hw.partition_id == 1)
		stats_len = I40E_PF_STATS_LEN;
	else
		stats_len = I40E_VSI_STATS_LEN;
@@ -2422,17 +2422,14 @@ static void i40e_get_ethtool_stats(struct net_device *netdev,
	}
	rcu_read_unlock();

	if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
	if (vsi->type != I40E_VSI_MAIN || pf->hw.partition_id != 1)
		goto check_data_pointer;

	veb_stats = ((pf->lan_veb != I40E_NO_VEB) &&
		     (pf->lan_veb < I40E_MAX_VEB) &&
		     test_bit(I40E_FLAG_VEB_STATS_ENA, pf->flags));
	veb = i40e_pf_get_main_veb(pf);
	veb_stats = veb && test_bit(I40E_FLAG_VEB_STATS_ENA, pf->flags);

	if (veb_stats) {
		veb = pf->veb[pf->lan_veb];
	if (veb_stats)
		i40e_update_veb_stats(veb);
	}

	/* If veb stats aren't enabled, pass NULL instead of the veb so that
	 * we initialize stats to zero and update the data pointer
@@ -2495,7 +2492,7 @@ static void i40e_get_stat_strings(struct net_device *netdev, u8 *data)
				      "rx", i);
	}

	if (vsi != pf->vsi[pf->lan_vsi] || pf->hw.partition_id != 1)
	if (vsi->type != I40E_VSI_MAIN || pf->hw.partition_id != 1)
		goto check_data_pointer;

	i40e_add_stat_strings(&data, i40e_gstrings_veb_stats);
@@ -2792,7 +2789,7 @@ static int i40e_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol)
		return -EOPNOTSUPP;
	}

	if (vsi != pf->vsi[pf->lan_vsi])
	if (vsi->type != I40E_VSI_MAIN)
		return -EOPNOTSUPP;

	/* NVM bit on means WoL disabled for the port */
@@ -3370,6 +3367,7 @@ static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
	struct i40e_rx_flow_userdef userdef = {0};
	struct i40e_fdir_filter *rule = NULL;
	struct hlist_node *node2;
	struct i40e_vsi *vsi;
	u64 input_set;
	u16 index;

@@ -3493,9 +3491,8 @@ static int i40e_get_ethtool_fdir_entry(struct i40e_pf *pf,
		fsp->flow_type |= FLOW_EXT;
	}

	if (rule->dest_vsi != pf->vsi[pf->lan_vsi]->id) {
		struct i40e_vsi *vsi;

	vsi = i40e_pf_get_main_vsi(pf);
	if (rule->dest_vsi != vsi->id) {
		vsi = i40e_find_vsi_from_id(pf, rule->dest_vsi);
		if (vsi && vsi->type == I40E_VSI_SRIOV) {
			/* VFs are zero-indexed by the driver, but ethtool
Loading