Commit b9ab5d0e authored by Maxim Mikityanskiy's avatar Maxim Mikityanskiy Committed by Saeed Mahameed

net/mlx5e: Add context to the preactivate hook

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: default avatarMaxim Mikityanskiy <maximmi@mellanox.com>
Reviewed-by: default avatarTariq Toukan <tariqt@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent 35a78ed4
...@@ -1047,12 +1047,19 @@ void mlx5e_close_channels(struct mlx5e_channels *chs); ...@@ -1047,12 +1047,19 @@ void mlx5e_close_channels(struct mlx5e_channels *chs);
/* Function pointer to be used to modify HW or kernel settings while /* Function pointer to be used to modify HW or kernel settings while
* switching channels * 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_reopen_channels(struct mlx5e_priv *priv);
int mlx5e_safe_switch_channels(struct mlx5e_priv *priv, int mlx5e_safe_switch_channels(struct mlx5e_priv *priv,
struct mlx5e_channels *new_chs, 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(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_activate_priv_channels(struct mlx5e_priv *priv);
void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv); void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv);
...@@ -1132,10 +1139,10 @@ void mlx5e_update_ndo_stats(struct mlx5e_priv *priv); ...@@ -1132,10 +1139,10 @@ void mlx5e_update_ndo_stats(struct mlx5e_priv *priv);
void mlx5e_queue_update_stats(struct mlx5e_priv *priv); void mlx5e_queue_update_stats(struct mlx5e_priv *priv);
int mlx5e_bits_invert(unsigned long a, int size); 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(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, int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,
change_hw_mtu_cb set_mtu_cb); mlx5e_fp_preactivate preactivate);
/* ethtool helpers */ /* ethtool helpers */
void mlx5e_ethtool_get_drvinfo(struct mlx5e_priv *priv, void mlx5e_ethtool_get_drvinfo(struct mlx5e_priv *priv,
......
...@@ -1126,7 +1126,7 @@ static void mlx5e_trust_update_sq_inline_mode(struct mlx5e_priv *priv) ...@@ -1126,7 +1126,7 @@ static void mlx5e_trust_update_sq_inline_mode(struct mlx5e_priv *priv)
priv->channels.params.tx_min_inline_mode) priv->channels.params.tx_min_inline_mode)
goto out; goto out;
mlx5e_safe_switch_channels(priv, &new_channels, NULL); mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
out: out:
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
......
...@@ -357,7 +357,7 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv, ...@@ -357,7 +357,7 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
goto unlock; goto unlock;
} }
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL); err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
unlock: unlock:
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
...@@ -441,7 +441,8 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv, ...@@ -441,7 +441,8 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,
mlx5e_arfs_disable(priv); mlx5e_arfs_disable(priv);
/* Switch to new channels, set new parameters and close old ones */ /* 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) { if (arfs_enabled) {
int err2 = mlx5e_arfs_enable(priv); int err2 = mlx5e_arfs_enable(priv);
...@@ -574,7 +575,7 @@ int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv, ...@@ -574,7 +575,7 @@ int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
goto out; goto out;
} }
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL); err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
out: out:
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
...@@ -1742,7 +1743,7 @@ static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable, ...@@ -1742,7 +1743,7 @@ static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable,
return 0; 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) static int set_pflag_tx_cqe_based_moder(struct net_device *netdev, bool enable)
...@@ -1775,7 +1776,7 @@ int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool new_val ...@@ -1775,7 +1776,7 @@ int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool new_val
return 0; return 0;
} }
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL); err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
if (err) if (err)
return err; return err;
...@@ -1832,7 +1833,7 @@ static int set_pflag_rx_striding_rq(struct net_device *netdev, bool enable) ...@@ -1832,7 +1833,7 @@ static int set_pflag_rx_striding_rq(struct net_device *netdev, bool enable)
return 0; 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) static int set_pflag_rx_no_csum_complete(struct net_device *netdev, bool enable)
...@@ -1876,7 +1877,7 @@ static int set_pflag_xdp_tx_mpwqe(struct net_device *netdev, bool enable) ...@@ -1876,7 +1877,7 @@ static int set_pflag_xdp_tx_mpwqe(struct net_device *netdev, bool enable)
return 0; return 0;
} }
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL); err = mlx5e_safe_switch_channels(priv, &new_channels, NULL, NULL);
return err; return err;
} }
......
...@@ -2753,6 +2753,8 @@ static int mlx5e_modify_tirs_lro(struct mlx5e_priv *priv) ...@@ -2753,6 +2753,8 @@ static int mlx5e_modify_tirs_lro(struct mlx5e_priv *priv)
return err; return err;
} }
static MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX(mlx5e_modify_tirs_lro);
static int mlx5e_set_mtu(struct mlx5_core_dev *mdev, static int mlx5e_set_mtu(struct mlx5_core_dev *mdev,
struct mlx5e_params *params, u16 mtu) struct mlx5e_params *params, u16 mtu)
{ {
...@@ -2802,6 +2804,8 @@ int mlx5e_set_dev_port_mtu(struct mlx5e_priv *priv) ...@@ -2802,6 +2804,8 @@ int mlx5e_set_dev_port_mtu(struct mlx5e_priv *priv)
return 0; return 0;
} }
MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX(mlx5e_set_dev_port_mtu);
void mlx5e_set_netdev_mtu_boundaries(struct mlx5e_priv *priv) void mlx5e_set_netdev_mtu_boundaries(struct mlx5e_priv *priv)
{ {
struct mlx5e_params *params = &priv->channels.params; struct mlx5e_params *params = &priv->channels.params;
...@@ -2884,6 +2888,8 @@ int mlx5e_num_channels_changed(struct mlx5e_priv *priv) ...@@ -2884,6 +2888,8 @@ int mlx5e_num_channels_changed(struct mlx5e_priv *priv)
return 0; return 0;
} }
MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX(mlx5e_num_channels_changed);
static void mlx5e_build_txq_maps(struct mlx5e_priv *priv) static void mlx5e_build_txq_maps(struct mlx5e_priv *priv)
{ {
int i, ch; int i, ch;
...@@ -2939,7 +2945,8 @@ void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv) ...@@ -2939,7 +2945,8 @@ void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv)
static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv, static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
struct mlx5e_channels *new_chs, struct mlx5e_channels *new_chs,
mlx5e_fp_preactivate preactivate) mlx5e_fp_preactivate preactivate,
void *context)
{ {
struct net_device *netdev = priv->netdev; struct net_device *netdev = priv->netdev;
struct mlx5e_channels old_chs; struct mlx5e_channels old_chs;
...@@ -2958,7 +2965,7 @@ static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv, ...@@ -2958,7 +2965,7 @@ static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
* to modify HW settings or update kernel parameters. * to modify HW settings or update kernel parameters.
*/ */
if (preactivate) { if (preactivate) {
err = preactivate(priv); err = preactivate(priv, context);
if (err) { if (err) {
priv->channels = old_chs; priv->channels = old_chs;
goto out; goto out;
...@@ -2980,7 +2987,8 @@ static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv, ...@@ -2980,7 +2987,8 @@ static int mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
int mlx5e_safe_switch_channels(struct mlx5e_priv *priv, int mlx5e_safe_switch_channels(struct mlx5e_priv *priv,
struct mlx5e_channels *new_chs, struct mlx5e_channels *new_chs,
mlx5e_fp_preactivate preactivate) mlx5e_fp_preactivate preactivate,
void *context)
{ {
int err; int err;
...@@ -2988,7 +2996,7 @@ int mlx5e_safe_switch_channels(struct mlx5e_priv *priv, ...@@ -2988,7 +2996,7 @@ int mlx5e_safe_switch_channels(struct mlx5e_priv *priv,
if (err) if (err)
return err; return err;
err = mlx5e_switch_priv_channels(priv, new_chs, preactivate); err = mlx5e_switch_priv_channels(priv, new_chs, preactivate, context);
if (err) if (err)
goto err_close; goto err_close;
...@@ -3005,7 +3013,7 @@ int mlx5e_safe_reopen_channels(struct mlx5e_priv *priv) ...@@ -3005,7 +3013,7 @@ int mlx5e_safe_reopen_channels(struct mlx5e_priv *priv)
struct mlx5e_channels new_channels = {}; struct mlx5e_channels new_channels = {};
new_channels.params = priv->channels.params; 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) void mlx5e_timestamp_init(struct mlx5e_priv *priv)
...@@ -3454,7 +3462,8 @@ static int mlx5e_setup_tc_mqprio(struct mlx5e_priv *priv, ...@@ -3454,7 +3462,8 @@ static int mlx5e_setup_tc_mqprio(struct mlx5e_priv *priv,
goto out; 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) if (err)
goto out; goto out;
...@@ -3667,7 +3676,8 @@ static int set_feature_lro(struct net_device *netdev, bool enable) ...@@ -3667,7 +3676,8 @@ static int set_feature_lro(struct net_device *netdev, bool enable)
goto out; 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: out:
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
return err; return err;
...@@ -3886,7 +3896,7 @@ static bool mlx5e_xsk_validate_mtu(struct net_device *netdev, ...@@ -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, 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_priv *priv = netdev_priv(netdev);
struct mlx5e_channels new_channels = {}; struct mlx5e_channels new_channels = {};
...@@ -3935,13 +3945,13 @@ int mlx5e_change_mtu(struct net_device *netdev, int new_mtu, ...@@ -3935,13 +3945,13 @@ int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,
if (!reset) { if (!reset) {
params->sw_mtu = new_mtu; params->sw_mtu = new_mtu;
if (set_mtu_cb) if (preactivate)
set_mtu_cb(priv); preactivate(priv, NULL);
netdev->mtu = params->sw_mtu; netdev->mtu = params->sw_mtu;
goto out; 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) if (err)
goto out; goto out;
...@@ -3954,7 +3964,7 @@ int mlx5e_change_mtu(struct net_device *netdev, int new_mtu, ...@@ -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) 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) int mlx5e_hwstamp_set(struct mlx5e_priv *priv, struct ifreq *ifr)
...@@ -4415,7 +4425,7 @@ static int mlx5e_xdp_set(struct net_device *netdev, struct bpf_prog *prog) ...@@ -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); mlx5e_set_rq_type(priv->mdev, &new_channels.params);
old_prog = priv->channels.params.xdp_prog; 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) if (err)
goto unlock; goto unlock;
} else { } else {
......
...@@ -1396,7 +1396,7 @@ static int mlx5e_rep_change_mtu(struct net_device *netdev, int new_mtu) ...@@ -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) 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) static int mlx5e_uplink_rep_set_mac(struct net_device *netdev, void *addr)
......
...@@ -483,7 +483,7 @@ static int mlx5i_change_mtu(struct net_device *netdev, int new_mtu) ...@@ -483,7 +483,7 @@ static int mlx5i_change_mtu(struct net_device *netdev, int new_mtu)
new_channels.params = *params; new_channels.params = *params;
new_channels.params.sw_mtu = new_mtu; 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) if (err)
goto out; goto out;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment