[net-next RFC v2 2/4] mlx5: Add queue number parameter to mlx5e_safe_switch_params()

From: Nabil S. Alramli
Date: Mon Sep 18 2023 - 18:45:18 EST


Currently mlx5e_safe_switch_params() does not take a queue number and
assumes a global operation. This allows the function to handle individual
channels. Note that Global operations reset the individual channel
settings.

Signed-off-by: Nabil S. Alramli <dev@xxxxxxxxxxxx>
---
drivers/net/ethernet/mellanox/mlx5/core/en.h | 3 +-
.../ethernet/mellanox/mlx5/core/en_dcbnl.c | 2 +-
.../ethernet/mellanox/mlx5/core/en_ethtool.c | 18 ++++----
.../net/ethernet/mellanox/mlx5/core/en_main.c | 42 +++++++++++++------
.../ethernet/mellanox/mlx5/core/ipoib/ipoib.c | 2 +-
5 files changed, 42 insertions(+), 25 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h
index 3657839b88f8..ba8eb2b30251 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h
@@ -1063,7 +1063,8 @@ int mlx5e_safe_reopen_channels(struct mlx5e_priv *priv);
int mlx5e_safe_switch_params(struct mlx5e_priv *priv,
struct mlx5e_params *new_params,
mlx5e_fp_preactivate preactivate,
- void *context, bool reset);
+ void *context, bool reset,
+ int queue);
int mlx5e_update_tx_netdev_queues(struct mlx5e_priv *priv);
int mlx5e_num_channels_changed_ctx(struct mlx5e_priv *priv, void *context);
void mlx5e_activate_priv_channels(struct mlx5e_priv *priv);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c b/drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
index 8705cffc747f..8c0704beb25c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
@@ -1159,7 +1159,7 @@ static int mlx5e_set_trust_state(struct mlx5e_priv *priv, u8 trust_state)

err = mlx5e_safe_switch_params(priv, &new_params,
mlx5e_update_trust_state_hw,
- &trust_state, reset);
+ &trust_state, reset, -1);

mutex_unlock(&priv->state_lock);

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
index dff02434ff45..13e5838ff1ee 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
@@ -389,7 +389,7 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
if (err)
goto unlock;

- err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);
+ err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true, -1);

unlock:
mutex_unlock(&priv->state_lock);
@@ -489,7 +489,7 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,

/* Switch to new channels, set new parameters and close old ones */
err = mlx5e_safe_switch_params(priv, &new_params,
- mlx5e_num_channels_changed_ctx, NULL, true);
+ mlx5e_num_channels_changed_ctx, NULL, true, -1);

if (arfs_enabled) {
int err2 = mlx5e_arfs_enable(priv->fs);
@@ -684,7 +684,7 @@ int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
reset = false;
}

- err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, reset);
+ err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, reset, -1);

mutex_unlock(&priv->state_lock);
return err;
@@ -1893,7 +1893,7 @@ static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable,
else
mlx5e_set_tx_cq_mode_params(&new_params, cq_period_mode);

- return mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);
+ return mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true, -1);
}

static int set_pflag_tx_cqe_based_moder(struct net_device *netdev, bool enable)
@@ -1935,10 +1935,10 @@ int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool new_val
new_params.ptp_rx = new_val;

if (new_params.ptp_rx == priv->channels.params.ptp_rx)
- err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);
+ err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true, -1);
else
err = mlx5e_safe_switch_params(priv, &new_params, mlx5e_ptp_rx_manage_fs_ctx,
- &new_params.ptp_rx, true);
+ &new_params.ptp_rx, true, -1);
if (err)
return err;

@@ -1996,7 +1996,7 @@ static int set_pflag_rx_striding_rq(struct net_device *netdev, bool enable)
MLX5E_SET_PFLAG(&new_params, MLX5E_PFLAG_RX_STRIDING_RQ, enable);
mlx5e_set_rq_type(mdev, &new_params);

- err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);
+ err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true, -1);
if (err)
return err;

@@ -2041,7 +2041,7 @@ static int set_pflag_tx_mpwqe_common(struct net_device *netdev, u32 flag, bool e

MLX5E_SET_PFLAG(&new_params, flag, enable);

- return mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);
+ return mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true, -1);
}

static int set_pflag_xdp_tx_mpwqe(struct net_device *netdev, bool enable)
@@ -2094,7 +2094,7 @@ static int set_pflag_tx_port_ts(struct net_device *netdev, bool enable)
*/

err = mlx5e_safe_switch_params(priv, &new_params,
- mlx5e_num_channels_changed_ctx, NULL, true);
+ mlx5e_num_channels_changed_ctx, NULL, true, -1);
if (!err)
priv->tx_ptp_opened = true;

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index a1578219187b..d7325fc4f2c0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -3055,19 +3055,35 @@ static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
int mlx5e_safe_switch_params(struct mlx5e_priv *priv,
struct mlx5e_params *params,
mlx5e_fp_preactivate preactivate,
- void *context, bool reset)
+ void *context, bool reset,
+ int queue)
{
struct mlx5e_channels *new_chs;
int err;
+ int i;
+
+ if (queue == -1) {
+ for (i = 0; i < priv->channels.num; i++)
+ priv->channels.c[i]->params = *params;
+ } else {
+ priv->channels.c[queue]->params = *params;
+ }

reset &= test_bit(MLX5E_STATE_OPENED, &priv->state);
- if (!reset)
- return mlx5e_switch_priv_params(priv, params, preactivate, context);
+ if (!reset) {
+ if (queue == -1)
+ return mlx5e_switch_priv_params(priv, params, preactivate, context);
+ else
+ return 0;
+ }

new_chs = kzalloc(sizeof(*new_chs), GFP_KERNEL);
if (!new_chs)
return -ENOMEM;
- new_chs->params = *params;
+ if (queue == -1)
+ new_chs->params = *params;
+ else
+ new_chs->params = priv->channels.params;

mlx5e_selq_prepare_params(&priv->selq, &new_chs->params);

@@ -3093,7 +3109,7 @@ int mlx5e_safe_switch_params(struct mlx5e_priv *priv,

int mlx5e_safe_reopen_channels(struct mlx5e_priv *priv)
{
- return mlx5e_safe_switch_params(priv, &priv->channels.params, NULL, NULL, true);
+ return mlx5e_safe_switch_params(priv, &priv->channels.params, NULL, NULL, true, -1);
}

void mlx5e_timestamp_init(struct mlx5e_priv *priv)
@@ -3486,7 +3502,7 @@ static int mlx5e_setup_tc_mqprio_dcb(struct mlx5e_priv *priv,
mlx5e_params_mqprio_dcb_set(&new_params, tc ? tc : 1);

err = mlx5e_safe_switch_params(priv, &new_params,
- mlx5e_num_channels_changed_ctx, NULL, true);
+ mlx5e_num_channels_changed_ctx, NULL, true, -1);

if (!err && priv->mqprio_rl) {
mlx5e_mqprio_rl_cleanup(priv->mqprio_rl);
@@ -3607,7 +3623,7 @@ static int mlx5e_setup_tc_mqprio_channel(struct mlx5e_priv *priv,
nch_changed = mlx5e_get_dcb_num_tc(&priv->channels.params) > 1;
preactivate = nch_changed ? mlx5e_num_channels_changed_ctx :
mlx5e_update_netdev_queues_ctx;
- err = mlx5e_safe_switch_params(priv, &new_params, preactivate, NULL, true);
+ err = mlx5e_safe_switch_params(priv, &new_params, preactivate, NULL, true, -1);
if (err) {
if (rl) {
mlx5e_mqprio_rl_cleanup(rl);
@@ -3849,7 +3865,7 @@ static int set_feature_lro(struct net_device *netdev, bool enable)
}

err = mlx5e_safe_switch_params(priv, &new_params,
- mlx5e_modify_tirs_packet_merge_ctx, NULL, reset);
+ mlx5e_modify_tirs_packet_merge_ctx, NULL, reset, -1);
out:
mutex_unlock(&priv->state_lock);
return err;
@@ -3877,7 +3893,7 @@ static int set_feature_hw_gro(struct net_device *netdev, bool enable)
goto out;
}

- err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, reset);
+ err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, reset, -1);
out:
mutex_unlock(&priv->state_lock);
return err;
@@ -3975,7 +3991,7 @@ static int set_feature_rx_fcs(struct net_device *netdev, bool enable)
new_params = chs->params;
new_params.scatter_fcs_en = enable;
err = mlx5e_safe_switch_params(priv, &new_params, mlx5e_set_rx_port_ts_wrap,
- &new_params.scatter_fcs_en, true);
+ &new_params.scatter_fcs_en, true, -1);
mutex_unlock(&priv->state_lock);
return err;
}
@@ -4349,7 +4365,7 @@ int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,
reset = false;
}

- err = mlx5e_safe_switch_params(priv, &new_params, preactivate, NULL, reset);
+ err = mlx5e_safe_switch_params(priv, &new_params, preactivate, NULL, reset, -1);

out:
netdev->mtu = params->sw_mtu;
@@ -4400,7 +4416,7 @@ static int mlx5e_hwstamp_config_ptp_rx(struct mlx5e_priv *priv, bool ptp_rx)
new_params = priv->channels.params;
new_params.ptp_rx = ptp_rx;
return mlx5e_safe_switch_params(priv, &new_params, mlx5e_ptp_rx_manage_fs_ctx,
- &new_params.ptp_rx, true);
+ &new_params.ptp_rx, true, -1);
}

int mlx5e_hwstamp_set(struct mlx5e_priv *priv, struct ifreq *ifr)
@@ -4831,7 +4847,7 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog)

old_prog = priv->channels.params.xdp_prog;

- err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, reset);
+ err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, reset, -1);
if (err)
goto unlock;

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c
index baa7ef812313..877719c4454a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c
@@ -522,7 +522,7 @@ static int mlx5i_change_mtu(struct net_device *netdev, int new_mtu)
new_params = priv->channels.params;
new_params.sw_mtu = new_mtu;

- err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);
+ err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true, -1);
if (err)
goto out;

--
2.35.1