Skip to content

Commit

Permalink
net/mlx5e: Handle errors from netif_set_real_num_{tx,rx}_queues
Browse files Browse the repository at this point in the history
netif_set_real_num_tx_queues and netif_set_real_num_rx_queues may fail.
Now that mlx5e supports handling errors in the preactivate hook, this
commit leverages that functionality to handle errors from those
functions and roll back all changes on failure.

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 Apr 20, 2020
1 parent d7a42ad commit fa37487
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 13 deletions.
2 changes: 1 addition & 1 deletion drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ int mlx5e_ethtool_set_channels(struct mlx5e_priv *priv,

if (!test_bit(MLX5E_STATE_OPENED, &priv->state)) {
*cur_params = new_channels.params;
mlx5e_num_channels_changed(priv);
err = mlx5e_num_channels_changed(priv);
goto out;
}

Expand Down
59 changes: 47 additions & 12 deletions drivers/net/ethernet/mellanox/mlx5/core/en_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2839,11 +2839,8 @@ void mlx5e_set_netdev_mtu_boundaries(struct mlx5e_priv *priv)
ETH_MAX_MTU);
}

static void mlx5e_netdev_set_tcs(struct net_device *netdev)
static void mlx5e_netdev_set_tcs(struct net_device *netdev, u16 nch, u8 ntc)
{
struct mlx5e_priv *priv = netdev_priv(netdev);
int nch = priv->channels.params.num_channels;
int ntc = priv->channels.params.num_tc;
int tc;

netdev_reset_tc(netdev);
Expand All @@ -2860,15 +2857,47 @@ static void mlx5e_netdev_set_tcs(struct net_device *netdev)
netdev_set_tc_queue(netdev, tc, nch, 0);
}

static void mlx5e_update_netdev_queues(struct mlx5e_priv *priv, u16 count)
static int mlx5e_update_netdev_queues(struct mlx5e_priv *priv)
{
int num_txqs = count * priv->channels.params.num_tc;
int num_rxqs = count * priv->profile->rq_groups;
struct net_device *netdev = priv->netdev;
int num_txqs, num_rxqs, nch, ntc;
int old_num_txqs, old_ntc;
int err;

old_num_txqs = netdev->real_num_tx_queues;
old_ntc = netdev->num_tc;

mlx5e_netdev_set_tcs(netdev);
netif_set_real_num_tx_queues(netdev, num_txqs);
netif_set_real_num_rx_queues(netdev, num_rxqs);
nch = priv->channels.params.num_channels;
ntc = priv->channels.params.num_tc;
num_txqs = nch * ntc;
num_rxqs = nch * priv->profile->rq_groups;

mlx5e_netdev_set_tcs(netdev, nch, ntc);

err = netif_set_real_num_tx_queues(netdev, num_txqs);
if (err) {
netdev_warn(netdev, "netif_set_real_num_tx_queues failed, %d\n", err);
goto err_tcs;
}
err = netif_set_real_num_rx_queues(netdev, num_rxqs);
if (err) {
netdev_warn(netdev, "netif_set_real_num_rx_queues failed, %d\n", err);
goto err_txqs;
}

return 0;

err_txqs:
/* netif_set_real_num_rx_queues could fail only when nch increased. Only
* one of nch and ntc is changed in this function. That means, the call
* to netif_set_real_num_tx_queues below should not fail, because it
* decreases the number of TX queues.
*/
WARN_ON_ONCE(netif_set_real_num_tx_queues(netdev, old_num_txqs));

err_tcs:
mlx5e_netdev_set_tcs(netdev, old_num_txqs / old_ntc, old_ntc);
return err;
}

static void mlx5e_set_default_xps_cpumasks(struct mlx5e_priv *priv,
Expand All @@ -2895,8 +2924,12 @@ static void mlx5e_set_default_xps_cpumasks(struct mlx5e_priv *priv,
int mlx5e_num_channels_changed(struct mlx5e_priv *priv)
{
u16 count = priv->channels.params.num_channels;
int err;

err = mlx5e_update_netdev_queues(priv);
if (err)
return err;

mlx5e_update_netdev_queues(priv, count);
mlx5e_set_default_xps_cpumasks(priv, &priv->channels.params);

if (!netif_is_rxfh_configured(priv->netdev))
Expand Down Expand Up @@ -5358,9 +5391,11 @@ int mlx5e_attach_netdev(struct mlx5e_priv *priv)
*/
if (take_rtnl)
rtnl_lock();
mlx5e_num_channels_changed(priv);
err = mlx5e_num_channels_changed(priv);
if (take_rtnl)
rtnl_unlock();
if (err)
goto out;

err = profile->init_tx(priv);
if (err)
Expand Down

0 comments on commit fa37487

Please sign in to comment.