Skip to content

Commit

Permalink
net/mlx5e: Cleanup safe switch channels API by passing params
Browse files Browse the repository at this point in the history
mlx5e_safe_switch_channels accepts new_chs as a parameter and opens new
channels in place, then copying them to priv->channels. It requires all
the callers to allocate space for this temporary storage of the new
channels.

This commit cleans up the API by replacing new_chs with new_params, a
meaningful subset of new_chs to be filled by the caller. The temporary
space for the new channels is allocated inside mlx5e_safe_switch_params
(a new name for mlx5e_safe_switch_channels). An extra copy of params is
made, but since it's control flow, it's not critical.

Signed-off-by: Maxim Mikityanskiy <maximmi@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
  • Loading branch information
Maxim Mikityanskiy authored and Saeed Mahameed committed Apr 16, 2021
1 parent b3b886c commit 94872d4
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 116 deletions.
8 changes: 4 additions & 4 deletions drivers/net/ethernet/mellanox/mlx5/core/en.h
Original file line number Diff line number Diff line change
Expand Up @@ -1018,10 +1018,10 @@ int fn##_ctx(struct mlx5e_priv *priv, void *context) \
return fn(priv); \
}
int mlx5e_safe_reopen_channels(struct mlx5e_priv *priv);
int mlx5e_safe_switch_channels(struct mlx5e_priv *priv,
struct mlx5e_channels *new_chs,
mlx5e_fp_preactivate preactivate,
void *context, bool reset);
int mlx5e_safe_switch_params(struct mlx5e_priv *priv,
struct mlx5e_params *new_params,
mlx5e_fp_preactivate preactivate,
void *context, bool reset);
int mlx5e_update_tx_netdev_queues(struct mlx5e_priv *priv);
int mlx5e_num_channels_changed(struct mlx5e_priv *priv);
int mlx5e_num_channels_changed_ctx(struct mlx5e_priv *priv, void *context);
Expand Down
15 changes: 7 additions & 8 deletions drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1149,24 +1149,23 @@ static int mlx5e_update_trust_state_hw(struct mlx5e_priv *priv, void *context)

static int mlx5e_set_trust_state(struct mlx5e_priv *priv, u8 trust_state)
{
struct mlx5e_channels new_channels = {};
struct mlx5e_params new_params;
bool reset = true;
int err;

mutex_lock(&priv->state_lock);

new_channels.params = priv->channels.params;
mlx5e_params_calc_trust_tx_min_inline_mode(priv->mdev, &new_channels.params,
new_params = priv->channels.params;
mlx5e_params_calc_trust_tx_min_inline_mode(priv->mdev, &new_params,
trust_state);

/* Skip if tx_min_inline is the same */
if (new_channels.params.tx_min_inline_mode ==
priv->channels.params.tx_min_inline_mode)
if (new_params.tx_min_inline_mode == priv->channels.params.tx_min_inline_mode)
reset = false;

err = mlx5e_safe_switch_channels(priv, &new_channels,
mlx5e_update_trust_state_hw,
&trust_state, reset);
err = mlx5e_safe_switch_params(priv, &new_params,
mlx5e_update_trust_state_hw,
&trust_state, reset);

mutex_unlock(&priv->state_lock);

Expand Down
98 changes: 49 additions & 49 deletions drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ static void mlx5e_get_ringparam(struct net_device *dev,
int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
struct ethtool_ringparam *param)
{
struct mlx5e_channels new_channels = {};
struct mlx5e_params new_params;
u8 log_rq_size;
u8 log_sq_size;
int err = 0;
Expand Down Expand Up @@ -365,15 +365,15 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,

mutex_lock(&priv->state_lock);

new_channels.params = priv->channels.params;
new_channels.params.log_rq_mtu_frames = log_rq_size;
new_channels.params.log_sq_size = log_sq_size;
new_params = priv->channels.params;
new_params.log_rq_mtu_frames = log_rq_size;
new_params.log_sq_size = log_sq_size;

err = mlx5e_validate_params(priv->mdev, &new_channels.params);
err = mlx5e_validate_params(priv->mdev, &new_params);
if (err)
goto unlock;

err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL, true);
err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);

unlock:
mutex_unlock(&priv->state_lock);
Expand Down Expand Up @@ -418,7 +418,7 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,
{
struct mlx5e_params *cur_params = &priv->channels.params;
unsigned int count = ch->combined_count;
struct mlx5e_channels new_channels = {};
struct mlx5e_params new_params;
bool arfs_enabled;
bool opened;
int err = 0;
Expand Down Expand Up @@ -455,8 +455,8 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,
goto out;
}

new_channels.params = *cur_params;
new_channels.params.num_channels = count;
new_params = *cur_params;
new_params.num_channels = count;

opened = test_bit(MLX5E_STATE_OPENED, &priv->state);

Expand All @@ -465,8 +465,8 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,
mlx5e_arfs_disable(priv);

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

if (arfs_enabled) {
int err2 = mlx5e_arfs_enable(priv);
Expand Down Expand Up @@ -561,7 +561,7 @@ int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
{
struct dim_cq_moder *rx_moder, *tx_moder;
struct mlx5_core_dev *mdev = priv->mdev;
struct mlx5e_channels new_channels = {};
struct mlx5e_params new_params;
bool reset_rx, reset_tx;
bool reset = true;
int err = 0;
Expand All @@ -584,32 +584,32 @@ int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
}

mutex_lock(&priv->state_lock);
new_channels.params = priv->channels.params;
new_params = priv->channels.params;

rx_moder = &new_channels.params.rx_cq_moderation;
rx_moder = &new_params.rx_cq_moderation;
rx_moder->usec = coal->rx_coalesce_usecs;
rx_moder->pkts = coal->rx_max_coalesced_frames;
new_channels.params.rx_dim_enabled = !!coal->use_adaptive_rx_coalesce;
new_params.rx_dim_enabled = !!coal->use_adaptive_rx_coalesce;

tx_moder = &new_channels.params.tx_cq_moderation;
tx_moder = &new_params.tx_cq_moderation;
tx_moder->usec = coal->tx_coalesce_usecs;
tx_moder->pkts = coal->tx_max_coalesced_frames;
new_channels.params.tx_dim_enabled = !!coal->use_adaptive_tx_coalesce;
new_params.tx_dim_enabled = !!coal->use_adaptive_tx_coalesce;

reset_rx = !!coal->use_adaptive_rx_coalesce != priv->channels.params.rx_dim_enabled;
reset_tx = !!coal->use_adaptive_tx_coalesce != priv->channels.params.tx_dim_enabled;

if (reset_rx) {
u8 mode = MLX5E_GET_PFLAG(&new_channels.params,
u8 mode = MLX5E_GET_PFLAG(&new_params,
MLX5E_PFLAG_RX_CQE_BASED_MODER);

mlx5e_reset_rx_moderation(&new_channels.params, mode);
mlx5e_reset_rx_moderation(&new_params, mode);
}
if (reset_tx) {
u8 mode = MLX5E_GET_PFLAG(&new_channels.params,
u8 mode = MLX5E_GET_PFLAG(&new_params,
MLX5E_PFLAG_TX_CQE_BASED_MODER);

mlx5e_reset_tx_moderation(&new_channels.params, mode);
mlx5e_reset_tx_moderation(&new_params, mode);
}

/* If DIM state hasn't changed, it's possible to modify interrupt
Expand All @@ -623,7 +623,7 @@ int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
reset = false;
}

err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL, reset);
err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, reset);

mutex_unlock(&priv->state_lock);
return err;
Expand Down Expand Up @@ -1843,7 +1843,7 @@ static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable,
{
struct mlx5e_priv *priv = netdev_priv(netdev);
struct mlx5_core_dev *mdev = priv->mdev;
struct mlx5e_channels new_channels = {};
struct mlx5e_params new_params;
bool mode_changed;
u8 cq_period_mode, current_cq_period_mode;

Expand All @@ -1862,13 +1862,13 @@ static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable,
if (!mode_changed)
return 0;

new_channels.params = priv->channels.params;
new_params = priv->channels.params;
if (is_rx_cq)
mlx5e_set_rx_cq_mode_params(&new_channels.params, cq_period_mode);
mlx5e_set_rx_cq_mode_params(&new_params, cq_period_mode);
else
mlx5e_set_tx_cq_mode_params(&new_channels.params, cq_period_mode);
mlx5e_set_tx_cq_mode_params(&new_params, cq_period_mode);

return mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL, true);
return mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);
}

static int set_pflag_tx_cqe_based_moder(struct net_device *netdev, bool enable)
Expand All @@ -1884,7 +1884,7 @@ static int set_pflag_rx_cqe_based_moder(struct net_device *netdev, bool enable)
int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool new_val)
{
bool curr_val = MLX5E_GET_PFLAG(&priv->channels.params, MLX5E_PFLAG_RX_CQE_COMPRESS);
struct mlx5e_channels new_channels = {};
struct mlx5e_params new_params;
int err = 0;

if (!MLX5_CAP_GEN(priv->mdev, cqe_compression))
Expand All @@ -1893,16 +1893,16 @@ int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool new_val
if (curr_val == new_val)
return 0;

new_channels.params = priv->channels.params;
MLX5E_SET_PFLAG(&new_channels.params, MLX5E_PFLAG_RX_CQE_COMPRESS, new_val);
new_params = priv->channels.params;
MLX5E_SET_PFLAG(&new_params, MLX5E_PFLAG_RX_CQE_COMPRESS, new_val);
if (priv->tstamp.rx_filter != HWTSTAMP_FILTER_NONE)
new_channels.params.ptp_rx = new_val;
new_params.ptp_rx = new_val;

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

Expand Down Expand Up @@ -1936,7 +1936,7 @@ static int set_pflag_rx_striding_rq(struct net_device *netdev, bool enable)
{
struct mlx5e_priv *priv = netdev_priv(netdev);
struct mlx5_core_dev *mdev = priv->mdev;
struct mlx5e_channels new_channels = {};
struct mlx5e_params new_params;

if (enable) {
if (!mlx5e_check_fragmented_striding_rq_cap(mdev))
Expand All @@ -1948,12 +1948,12 @@ static int set_pflag_rx_striding_rq(struct net_device *netdev, bool enable)
return -EINVAL;
}

new_channels.params = priv->channels.params;
new_params = priv->channels.params;

MLX5E_SET_PFLAG(&new_channels.params, MLX5E_PFLAG_RX_STRIDING_RQ, enable);
mlx5e_set_rq_type(mdev, &new_channels.params);
MLX5E_SET_PFLAG(&new_params, MLX5E_PFLAG_RX_STRIDING_RQ, enable);
mlx5e_set_rq_type(mdev, &new_params);

return mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL, true);
return mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);
}

static int set_pflag_rx_no_csum_complete(struct net_device *netdev, bool enable)
Expand Down Expand Up @@ -1982,16 +1982,16 @@ static int set_pflag_tx_mpwqe_common(struct net_device *netdev, u32 flag, bool e
{
struct mlx5e_priv *priv = netdev_priv(netdev);
struct mlx5_core_dev *mdev = priv->mdev;
struct mlx5e_channels new_channels = {};
struct mlx5e_params new_params;

if (enable && !MLX5_CAP_ETH(mdev, enhanced_multi_pkt_send_wqe))
return -EOPNOTSUPP;

new_channels.params = priv->channels.params;
new_params = priv->channels.params;

MLX5E_SET_PFLAG(&new_channels.params, flag, enable);
MLX5E_SET_PFLAG(&new_params, flag, enable);

return mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL, true);
return mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true);
}

static int set_pflag_xdp_tx_mpwqe(struct net_device *netdev, bool enable)
Expand All @@ -2008,7 +2008,7 @@ static int set_pflag_tx_port_ts(struct net_device *netdev, bool enable)
{
struct mlx5e_priv *priv = netdev_priv(netdev);
struct mlx5_core_dev *mdev = priv->mdev;
struct mlx5e_channels new_channels = {};
struct mlx5e_params new_params;
int err;

if (!MLX5_CAP_GEN(mdev, ts_cqe_to_dest_cqn))
Expand All @@ -2024,15 +2024,15 @@ static int set_pflag_tx_port_ts(struct net_device *netdev, bool enable)
return -EINVAL;
}

new_channels.params = priv->channels.params;
MLX5E_SET_PFLAG(&new_channels.params, MLX5E_PFLAG_TX_PORT_TS, enable);
new_params = priv->channels.params;
MLX5E_SET_PFLAG(&new_params, MLX5E_PFLAG_TX_PORT_TS, enable);
/* No need to verify SQ stop room as
* ptpsq.txqsq.stop_room <= generic_sq->stop_room, and both
* has the same log_sq_size.
*/

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

Expand Down
Loading

0 comments on commit 94872d4

Please sign in to comment.