Skip to content

Commit

Permalink
net/mlx5e: Add context to the preactivate hook
Browse files Browse the repository at this point in the history
Sometimes the preactivate hook of mlx5e_safe_switch_channels needs more
parameters than just struct mlx5e_priv *. For such cases, a new
parameter (void *context) is added to preactivate hooks.

Some of the existing normal functions are currently used as preactivate
callbacks. To avoid adding an extra unused parameter, they are wrapped
in an automatic way using the MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX
macro.

Signed-off-by: Maxim Mikityanskiy <maximmi@mellanox.com>
Reviewed-by: Tariq Toukan <tariqt@mellanox.com>
Signed-off-by: Saeed Mahameed <saeedm@mellanox.com>
  • Loading branch information
Maxim Mikityanskiy authored and Saeed Mahameed committed Feb 26, 2020
1 parent 35a78ed commit b9ab5d0
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 27 deletions.
15 changes: 11 additions & 4 deletions drivers/net/ethernet/mellanox/mlx5/core/en.h
Original file line number Diff line number Diff line change
Expand Up @@ -1047,12 +1047,19 @@ void mlx5e_close_channels(struct mlx5e_channels *chs);
/* Function pointer to be used to modify HW or kernel settings while
* switching channels
*/
typedef int (*mlx5e_fp_preactivate)(struct mlx5e_priv *priv);
typedef int (*mlx5e_fp_preactivate)(struct mlx5e_priv *priv, void *context);
#define MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX(fn) \
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);
mlx5e_fp_preactivate preactivate,
void *context);
int mlx5e_num_channels_changed(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);
void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv);

Expand Down Expand Up @@ -1132,10 +1139,10 @@ void mlx5e_update_ndo_stats(struct mlx5e_priv *priv);
void mlx5e_queue_update_stats(struct mlx5e_priv *priv);
int mlx5e_bits_invert(unsigned long a, int size);

typedef int (*change_hw_mtu_cb)(struct mlx5e_priv *priv);
int mlx5e_set_dev_port_mtu(struct mlx5e_priv *priv);
int mlx5e_set_dev_port_mtu_ctx(struct mlx5e_priv *priv, void *context);
int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,
change_hw_mtu_cb set_mtu_cb);
mlx5e_fp_preactivate preactivate);

/* ethtool helpers */
void mlx5e_ethtool_get_drvinfo(struct mlx5e_priv *priv,
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx5/core/en_dcbnl.c
Original file line number Diff line number Diff line change
Expand Up @@ -1126,7 +1126,7 @@ static void mlx5e_trust_update_sq_inline_mode(struct mlx5e_priv *priv)
priv->channels.params.tx_min_inline_mode)
goto out;

mlx5e_safe_switch_channels(priv, &new_channels, NULL);
mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);

out:
mutex_unlock(&priv->state_lock);
Expand Down
15 changes: 8 additions & 7 deletions drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
goto unlock;
}

err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);

unlock:
mutex_unlock(&priv->state_lock);
Expand Down Expand Up @@ -441,7 +441,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);
err = mlx5e_safe_switch_channels(priv, &new_channels,
mlx5e_num_channels_changed_ctx, NULL);

if (arfs_enabled) {
int err2 = mlx5e_arfs_enable(priv);
Expand Down Expand Up @@ -574,7 +575,7 @@ int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
goto out;
}

err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);

out:
mutex_unlock(&priv->state_lock);
Expand Down Expand Up @@ -1742,7 +1743,7 @@ static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable,
return 0;
}

return mlx5e_safe_switch_channels(priv, &new_channels, NULL);
return mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
}

static int set_pflag_tx_cqe_based_moder(struct net_device *netdev, bool enable)
Expand Down Expand Up @@ -1775,7 +1776,7 @@ int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool new_val
return 0;
}

err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
if (err)
return err;

Expand Down Expand Up @@ -1832,7 +1833,7 @@ static int set_pflag_rx_striding_rq(struct net_device *netdev, bool enable)
return 0;
}

return mlx5e_safe_switch_channels(priv, &new_channels, NULL);
return mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
}

static int set_pflag_rx_no_csum_complete(struct net_device *netdev, bool enable)
Expand Down Expand Up @@ -1876,7 +1877,7 @@ static int set_pflag_xdp_tx_mpwqe(struct net_device *netdev, bool enable)
return 0;
}

err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
return err;
}

Expand Down
36 changes: 23 additions & 13 deletions drivers/net/ethernet/mellanox/mlx5/core/en_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2753,6 +2753,8 @@ static int mlx5e_modify_tirs_lro(struct mlx5e_priv *priv)
return err;
}

static MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX(mlx5e_modify_tirs_lro);

static int mlx5e_set_mtu(struct mlx5_core_dev *mdev,
struct mlx5e_params *params, u16 mtu)
{
Expand Down Expand Up @@ -2802,6 +2804,8 @@ int mlx5e_set_dev_port_mtu(struct mlx5e_priv *priv)
return 0;
}

MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX(mlx5e_set_dev_port_mtu);

void mlx5e_set_netdev_mtu_boundaries(struct mlx5e_priv *priv)
{
struct mlx5e_params *params = &priv->channels.params;
Expand Down Expand Up @@ -2884,6 +2888,8 @@ int mlx5e_num_channels_changed(struct mlx5e_priv *priv)
return 0;
}

MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX(mlx5e_num_channels_changed);

static void mlx5e_build_txq_maps(struct mlx5e_priv *priv)
{
int i, ch;
Expand Down Expand Up @@ -2939,7 +2945,8 @@ void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv)

static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
struct mlx5e_channels *new_chs,
mlx5e_fp_preactivate preactivate)
mlx5e_fp_preactivate preactivate,
void *context)
{
struct net_device *netdev = priv->netdev;
struct mlx5e_channels old_chs;
Expand All @@ -2958,7 +2965,7 @@ static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
* to modify HW settings or update kernel parameters.
*/
if (preactivate) {
err = preactivate(priv);
err = preactivate(priv, context);
if (err) {
priv->channels = old_chs;
goto out;
Expand All @@ -2980,15 +2987,16 @@ static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv,

int mlx5e_safe_switch_channels(struct mlx5e_priv *priv,
struct mlx5e_channels *new_chs,
mlx5e_fp_preactivate preactivate)
mlx5e_fp_preactivate preactivate,
void *context)
{
int err;

err = mlx5e_open_channels(priv, new_chs);
if (err)
return err;

err = mlx5e_switch_priv_channels(priv, new_chs, preactivate);
err = mlx5e_switch_priv_channels(priv, new_chs, preactivate, context);
if (err)
goto err_close;

Expand All @@ -3005,7 +3013,7 @@ int mlx5e_safe_reopen_channels(struct mlx5e_priv *priv)
struct mlx5e_channels new_channels = {};

new_channels.params = priv->channels.params;
return mlx5e_safe_switch_channels(priv, &new_channels, NULL);
return mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
}

void mlx5e_timestamp_init(struct mlx5e_priv *priv)
Expand Down Expand Up @@ -3454,7 +3462,8 @@ static int mlx5e_setup_tc_mqprio(struct mlx5e_priv *priv,
goto out;
}

err = mlx5e_safe_switch_channels(priv, &new_channels, mlx5e_num_channels_changed);
err = mlx5e_safe_switch_channels(priv, &new_channels,
mlx5e_num_channels_changed_ctx, NULL);
if (err)
goto out;

Expand Down Expand Up @@ -3667,7 +3676,8 @@ static int set_feature_lro(struct net_device *netdev, bool enable)
goto out;
}

err = mlx5e_safe_switch_channels(priv, &new_channels, mlx5e_modify_tirs_lro);
err = mlx5e_safe_switch_channels(priv, &new_channels,
mlx5e_modify_tirs_lro_ctx, NULL);
out:
mutex_unlock(&priv->state_lock);
return err;
Expand Down Expand Up @@ -3886,7 +3896,7 @@ static bool mlx5e_xsk_validate_mtu(struct net_device *netdev,
}

int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,
change_hw_mtu_cb set_mtu_cb)
mlx5e_fp_preactivate preactivate)
{
struct mlx5e_priv *priv = netdev_priv(netdev);
struct mlx5e_channels new_channels = {};
Expand Down Expand Up @@ -3935,13 +3945,13 @@ int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,

if (!reset) {
params->sw_mtu = new_mtu;
if (set_mtu_cb)
set_mtu_cb(priv);
if (preactivate)
preactivate(priv, NULL);
netdev->mtu = params->sw_mtu;
goto out;
}

err = mlx5e_safe_switch_channels(priv, &new_channels, set_mtu_cb);
err = mlx5e_safe_switch_channels(priv, &new_channels, preactivate, NULL);
if (err)
goto out;

Expand All @@ -3954,7 +3964,7 @@ int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,

static int mlx5e_change_nic_mtu(struct net_device *netdev, int new_mtu)
{
return mlx5e_change_mtu(netdev, new_mtu, mlx5e_set_dev_port_mtu);
return mlx5e_change_mtu(netdev, new_mtu, mlx5e_set_dev_port_mtu_ctx);
}

int mlx5e_hwstamp_set(struct mlx5e_priv *priv, struct ifreq *ifr)
Expand Down Expand Up @@ -4415,7 +4425,7 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog)
mlx5e_set_rq_type(priv->mdev, &new_channels.params);
old_prog = priv->channels.params.xdp_prog;

err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
if (err)
goto unlock;
} else {
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx5/core/en_rep.c
Original file line number Diff line number Diff line change
Expand Up @@ -1396,7 +1396,7 @@ static int mlx5e_rep_change_mtu(struct net_device *netdev, int new_mtu)

static int mlx5e_uplink_rep_change_mtu(struct net_device *netdev, int new_mtu)
{
return mlx5e_change_mtu(netdev, new_mtu, mlx5e_set_dev_port_mtu);
return mlx5e_change_mtu(netdev, new_mtu, mlx5e_set_dev_port_mtu_ctx);
}

static int mlx5e_uplink_rep_set_mac(struct net_device *netdev, void *addr)
Expand Down
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx5/core/ipoib/ipoib.c
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ static int mlx5i_change_mtu(struct net_device *netdev, int new_mtu)
new_channels.params = *params;
new_channels.params.sw_mtu = new_mtu;

err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
if (err)
goto out;

Expand Down

0 comments on commit b9ab5d0

Please sign in to comment.