Commit 877662e2 authored by Tariq Toukan's avatar Tariq Toukan Committed by Saeed Mahameed

net/mlx5e: Wrap the open and apply of channels in one fail-safe function

Take into a function the common code structure of opening
a side set of channels followed by a call to apply them.
Signed-off-by: default avatarTariq Toukan <tariqt@mellanox.com>
Signed-off-by: default avatarSaeed Mahameed <saeedm@mellanox.com>
parent 6a897372
...@@ -858,9 +858,9 @@ void mlx5e_close_channels(struct mlx5e_channels *chs); ...@@ -858,9 +858,9 @@ void mlx5e_close_channels(struct mlx5e_channels *chs);
* switching channels * switching channels
*/ */
typedef int (*mlx5e_fp_hw_modify)(struct mlx5e_priv *priv); typedef int (*mlx5e_fp_hw_modify)(struct mlx5e_priv *priv);
void mlx5e_switch_priv_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_hw_modify hw_modify); mlx5e_fp_hw_modify hw_modify);
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);
......
...@@ -1126,9 +1126,7 @@ static void mlx5e_trust_update_sq_inline_mode(struct mlx5e_priv *priv) ...@@ -1126,9 +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;
if (mlx5e_open_channels(priv, &new_channels)) mlx5e_safe_switch_channels(priv, &new_channels, NULL);
goto out;
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
out: out:
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
......
...@@ -369,11 +369,7 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv, ...@@ -369,11 +369,7 @@ int mlx5e_ethtool_set_ringparam(struct mlx5e_priv *priv,
goto unlock; goto unlock;
} }
err = mlx5e_open_channels(priv, &new_channels); err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
if (err)
goto unlock;
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
unlock: unlock:
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
...@@ -431,11 +427,6 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv, ...@@ -431,11 +427,6 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,
goto out; goto out;
} }
/* Create fresh channels with new parameters */
err = mlx5e_open_channels(priv, &new_channels);
if (err)
goto out;
arfs_enabled = priv->netdev->features & NETIF_F_NTUPLE; arfs_enabled = priv->netdev->features & NETIF_F_NTUPLE;
if (arfs_enabled) if (arfs_enabled)
mlx5e_arfs_disable(priv); mlx5e_arfs_disable(priv);
...@@ -445,13 +436,14 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv, ...@@ -445,13 +436,14 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,
MLX5E_INDIR_RQT_SIZE, count); MLX5E_INDIR_RQT_SIZE, count);
/* Switch to new channels, set new parameters and close old ones */ /* Switch to new channels, set new parameters and close old ones */
mlx5e_switch_priv_channels(priv, &new_channels, NULL); err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
if (arfs_enabled) { if (arfs_enabled) {
err = mlx5e_arfs_enable(priv); int err2 = mlx5e_arfs_enable(priv);
if (err)
if (err2)
netdev_err(priv->netdev, "%s: mlx5e_arfs_enable failed: %d\n", netdev_err(priv->netdev, "%s: mlx5e_arfs_enable failed: %d\n",
__func__, err); __func__, err2);
} }
out: out:
...@@ -577,12 +569,7 @@ int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv, ...@@ -577,12 +569,7 @@ int mlx5e_ethtool_set_coalesce(struct mlx5e_priv *priv,
goto out; goto out;
} }
/* open fresh channels with new coal parameters */ err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
err = mlx5e_open_channels(priv, &new_channels);
if (err)
goto out;
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
out: out:
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
...@@ -1635,7 +1622,6 @@ static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable, ...@@ -1635,7 +1622,6 @@ static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable,
struct mlx5e_channels new_channels = {}; struct mlx5e_channels new_channels = {};
bool mode_changed; bool mode_changed;
u8 cq_period_mode, current_cq_period_mode; u8 cq_period_mode, current_cq_period_mode;
int err = 0;
cq_period_mode = enable ? cq_period_mode = enable ?
MLX5_CQ_PERIOD_MODE_START_FROM_CQE : MLX5_CQ_PERIOD_MODE_START_FROM_CQE :
...@@ -1663,12 +1649,7 @@ static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable, ...@@ -1663,12 +1649,7 @@ static int set_pflag_cqe_based_moder(struct net_device *netdev, bool enable,
return 0; return 0;
} }
err = mlx5e_open_channels(priv, &new_channels); return mlx5e_safe_switch_channels(priv, &new_channels, NULL);
if (err)
return err;
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
return 0;
} }
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)
...@@ -1701,11 +1682,10 @@ int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool new_val ...@@ -1701,11 +1682,10 @@ int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool new_val
return 0; return 0;
} }
err = mlx5e_open_channels(priv, &new_channels); err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
if (err) if (err)
return err; return err;
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
mlx5e_dbg(DRV, priv, "MLX5E: RxCqeCmprss was turned %s\n", mlx5e_dbg(DRV, priv, "MLX5E: RxCqeCmprss was turned %s\n",
MLX5E_GET_PFLAG(&priv->channels.params, MLX5E_GET_PFLAG(&priv->channels.params,
MLX5E_PFLAG_RX_CQE_COMPRESS) ? "ON" : "OFF"); MLX5E_PFLAG_RX_CQE_COMPRESS) ? "ON" : "OFF");
...@@ -1738,7 +1718,6 @@ static int set_pflag_rx_striding_rq(struct net_device *netdev, bool enable) ...@@ -1738,7 +1718,6 @@ static int set_pflag_rx_striding_rq(struct net_device *netdev, bool enable)
struct mlx5e_priv *priv = netdev_priv(netdev); struct mlx5e_priv *priv = netdev_priv(netdev);
struct mlx5_core_dev *mdev = priv->mdev; struct mlx5_core_dev *mdev = priv->mdev;
struct mlx5e_channels new_channels = {}; struct mlx5e_channels new_channels = {};
int err;
if (enable) { if (enable) {
if (!mlx5e_check_fragmented_striding_rq_cap(mdev)) if (!mlx5e_check_fragmented_striding_rq_cap(mdev))
...@@ -1760,12 +1739,7 @@ static int set_pflag_rx_striding_rq(struct net_device *netdev, bool enable) ...@@ -1760,12 +1739,7 @@ static int set_pflag_rx_striding_rq(struct net_device *netdev, bool enable)
return 0; return 0;
} }
err = mlx5e_open_channels(priv, &new_channels); return mlx5e_safe_switch_channels(priv, &new_channels, NULL);
if (err)
return err;
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
return 0;
} }
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)
...@@ -1808,12 +1782,8 @@ static int set_pflag_xdp_tx_mpwqe(struct net_device *netdev, bool enable) ...@@ -1808,12 +1782,8 @@ static int set_pflag_xdp_tx_mpwqe(struct net_device *netdev, bool enable)
return 0; return 0;
} }
err = mlx5e_open_channels(priv, &new_channels); err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
if (err) return err;
return err;
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
return 0;
} }
static const struct pflag_desc mlx5e_priv_flags[MLX5E_NUM_PFLAGS] = { static const struct pflag_desc mlx5e_priv_flags[MLX5E_NUM_PFLAGS] = {
......
...@@ -2885,13 +2885,14 @@ void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv) ...@@ -2885,13 +2885,14 @@ void mlx5e_deactivate_priv_channels(struct mlx5e_priv *priv)
mlx5e_deactivate_channels(&priv->channels); mlx5e_deactivate_channels(&priv->channels);
} }
void mlx5e_switch_priv_channels(struct mlx5e_priv *priv, static void mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
struct mlx5e_channels *new_chs, struct mlx5e_channels *new_chs,
mlx5e_fp_hw_modify hw_modify) mlx5e_fp_hw_modify hw_modify)
{ {
struct net_device *netdev = priv->netdev; struct net_device *netdev = priv->netdev;
int new_num_txqs; int new_num_txqs;
int carrier_ok; int carrier_ok;
new_num_txqs = new_chs->num * new_chs->params.num_tc; new_num_txqs = new_chs->num * new_chs->params.num_tc;
carrier_ok = netif_carrier_ok(netdev); carrier_ok = netif_carrier_ok(netdev);
...@@ -2917,6 +2918,20 @@ void mlx5e_switch_priv_channels(struct mlx5e_priv *priv, ...@@ -2917,6 +2918,20 @@ void mlx5e_switch_priv_channels(struct mlx5e_priv *priv,
netif_carrier_on(netdev); netif_carrier_on(netdev);
} }
int mlx5e_safe_switch_channels(struct mlx5e_priv *priv,
struct mlx5e_channels *new_chs,
mlx5e_fp_hw_modify hw_modify)
{
int err;
err = mlx5e_open_channels(priv, new_chs);
if (err)
return err;
mlx5e_switch_priv_channels(priv, new_chs, hw_modify);
return 0;
}
void mlx5e_timestamp_init(struct mlx5e_priv *priv) void mlx5e_timestamp_init(struct mlx5e_priv *priv)
{ {
priv->tstamp.tx_type = HWTSTAMP_TX_OFF; priv->tstamp.tx_type = HWTSTAMP_TX_OFF;
...@@ -3333,13 +3348,12 @@ static int mlx5e_setup_tc_mqprio(struct net_device *netdev, ...@@ -3333,13 +3348,12 @@ static int mlx5e_setup_tc_mqprio(struct net_device *netdev,
goto out; goto out;
} }
err = mlx5e_open_channels(priv, &new_channels); err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
if (err) if (err)
goto out; goto out;
priv->max_opened_tc = max_t(u8, priv->max_opened_tc, priv->max_opened_tc = max_t(u8, priv->max_opened_tc,
new_channels.params.num_tc); new_channels.params.num_tc);
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
out: out:
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
return err; return err;
...@@ -3549,11 +3563,7 @@ static int set_feature_lro(struct net_device *netdev, bool enable) ...@@ -3549,11 +3563,7 @@ static int set_feature_lro(struct net_device *netdev, bool enable)
goto out; goto out;
} }
err = mlx5e_open_channels(priv, &new_channels); err = mlx5e_safe_switch_channels(priv, &new_channels, mlx5e_modify_tirs_lro);
if (err)
goto out;
mlx5e_switch_priv_channels(priv, &new_channels, mlx5e_modify_tirs_lro);
out: out:
mutex_unlock(&priv->state_lock); mutex_unlock(&priv->state_lock);
return err; return err;
...@@ -3771,11 +3781,10 @@ int mlx5e_change_mtu(struct net_device *netdev, int new_mtu, ...@@ -3771,11 +3781,10 @@ int mlx5e_change_mtu(struct net_device *netdev, int new_mtu,
goto out; goto out;
} }
err = mlx5e_open_channels(priv, &new_channels); err = mlx5e_safe_switch_channels(priv, &new_channels, set_mtu_cb);
if (err) if (err)
goto out; goto out;
mlx5e_switch_priv_channels(priv, &new_channels, set_mtu_cb);
netdev->mtu = new_channels.params.sw_mtu; netdev->mtu = new_channels.params.sw_mtu;
out: out:
......
...@@ -446,11 +446,11 @@ static int mlx5i_change_mtu(struct net_device *netdev, int new_mtu) ...@@ -446,11 +446,11 @@ 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_open_channels(priv, &new_channels);
err = mlx5e_safe_switch_channels(priv, &new_channels, NULL);
if (err) if (err)
goto out; goto out;
mlx5e_switch_priv_channels(priv, &new_channels, NULL);
netdev->mtu = new_channels.params.sw_mtu; netdev->mtu = new_channels.params.sw_mtu;
out: 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