]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
net/mlx5e: Modifying channels number and updating TX queues
authorCarolina Jubran <cjubran@nvidia.com>
Sun, 12 May 2024 12:43:04 +0000 (15:43 +0300)
committerJakub Kicinski <kuba@kernel.org>
Mon, 13 May 2024 23:35:47 +0000 (16:35 -0700)
It is not appropriate for the mlx5e_num_channels_changed
function to be called solely for updating the TX queues,
even if the channels number has not been changed.

Move the code responsible for updating the TC and TX queues
from mlx5e_num_channels_changed and produce a new function
called mlx5e_update_tc_and_tx_queues. This new function should
only be called when the channels number remains unchanged.

Signed-off-by: Carolina Jubran <cjubran@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Link: https://lore.kernel.org/r/20240512124306.740898-3-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/en.h
drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c
drivers/net/ethernet/mellanox/mlx5/core/en_main.c

index f8bd9dbf59cd6aa8631ce56e0632dd2569e4c586..e85fb71bf0b46239c07a968eab443cef4650b4a1 100644 (file)
@@ -1102,6 +1102,7 @@ int mlx5e_safe_switch_params(struct mlx5e_priv *priv,
                             void *context, bool reset);
 int mlx5e_update_tx_netdev_queues(struct mlx5e_priv *priv);
 int mlx5e_num_channels_changed_ctx(struct mlx5e_priv *priv, void *context);
+int mlx5e_update_tc_and_tx_queues_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);
 int mlx5e_ptp_rx_manage_fs_ctx(struct mlx5e_priv *priv, void *ctx);
index 1eb3a712930b920575479a18d903d682446b83d2..3320f12ba2dbd3b9709f90568d91c35a7a26dad3 100644 (file)
@@ -2292,7 +2292,7 @@ static int set_pflag_tx_port_ts(struct net_device *netdev, bool enable)
         */
 
        err = mlx5e_safe_switch_params(priv, &new_params,
-                                      mlx5e_num_channels_changed_ctx, NULL, true);
+                                      mlx5e_update_tc_and_tx_queues_ctx, NULL, true);
        if (!err)
                priv->tx_ptp_opened = true;
 
index ffe8919494d55a1c054ca1a706c7dbb0f47486f2..0a3d1999ede5d1fc719453b28e7e759f7db18670 100644 (file)
@@ -3002,7 +3002,28 @@ int mlx5e_update_tx_netdev_queues(struct mlx5e_priv *priv)
        return err;
 }
 
-static int mlx5e_update_netdev_queues(struct mlx5e_priv *priv)
+static void mlx5e_set_default_xps_cpumasks(struct mlx5e_priv *priv,
+                                          struct mlx5e_params *params)
+{
+       struct mlx5_core_dev *mdev = priv->mdev;
+       int num_comp_vectors, ix, irq;
+
+       num_comp_vectors = mlx5_comp_vectors_max(mdev);
+
+       for (ix = 0; ix < params->num_channels; ix++) {
+               cpumask_clear(priv->scratchpad.cpumask);
+
+               for (irq = ix; irq < num_comp_vectors; irq += params->num_channels) {
+                       int cpu = mlx5_comp_vector_get_cpu(mdev, irq);
+
+                       cpumask_set_cpu(cpu, priv->scratchpad.cpumask);
+               }
+
+               netif_set_xps_queue(priv->netdev, priv->scratchpad.cpumask, ix);
+       }
+}
+
+static int mlx5e_update_tc_and_tx_queues(struct mlx5e_priv *priv)
 {
        struct netdev_tc_txq old_tc_to_txq[TC_MAX_QUEUE], *tc_to_txq;
        struct net_device *netdev = priv->netdev;
@@ -3026,22 +3047,10 @@ static int mlx5e_update_netdev_queues(struct mlx5e_priv *priv)
        err = mlx5e_update_tx_netdev_queues(priv);
        if (err)
                goto err_tcs;
-       err = netif_set_real_num_rx_queues(netdev, nch);
-       if (err) {
-               netdev_warn(netdev, "netif_set_real_num_rx_queues failed, %d\n", err);
-               goto err_txqs;
-       }
+       mlx5e_set_default_xps_cpumasks(priv, &priv->channels.params);
 
        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:
        WARN_ON_ONCE(mlx5e_netdev_set_tcs(netdev, old_num_txqs / old_ntc, old_ntc,
                                          old_tc_to_txq));
@@ -3049,42 +3058,32 @@ err_out:
        return err;
 }
 
-static MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX(mlx5e_update_netdev_queues);
-
-static void mlx5e_set_default_xps_cpumasks(struct mlx5e_priv *priv,
-                                          struct mlx5e_params *params)
-{
-       int ix;
-
-       for (ix = 0; ix < params->num_channels; ix++) {
-               int num_comp_vectors, irq, vec_ix;
-               struct mlx5_core_dev *mdev;
-
-               mdev = mlx5_sd_ch_ix_get_dev(priv->mdev, ix);
-               num_comp_vectors = mlx5_comp_vectors_max(mdev);
-               cpumask_clear(priv->scratchpad.cpumask);
-               vec_ix = mlx5_sd_ch_ix_get_vec_ix(mdev, ix);
-
-               for (irq = vec_ix; irq < num_comp_vectors; irq += params->num_channels) {
-                       int cpu = mlx5_comp_vector_get_cpu(mdev, irq);
-
-                       cpumask_set_cpu(cpu, priv->scratchpad.cpumask);
-               }
-
-               netif_set_xps_queue(priv->netdev, priv->scratchpad.cpumask, ix);
-       }
-}
+MLX5E_DEFINE_PREACTIVATE_WRAPPER_CTX(mlx5e_update_tc_and_tx_queues);
 
 static int mlx5e_num_channels_changed(struct mlx5e_priv *priv)
 {
        u16 count = priv->channels.params.num_channels;
+       struct net_device *netdev = priv->netdev;
+       int old_num_rxqs;
        int err;
 
-       err = mlx5e_update_netdev_queues(priv);
-       if (err)
+       old_num_rxqs = netdev->real_num_rx_queues;
+       err = netif_set_real_num_rx_queues(netdev, count);
+       if (err) {
+               netdev_warn(netdev, "%s: netif_set_real_num_rx_queues failed, %d\n",
+                           __func__, err);
                return err;
-
-       mlx5e_set_default_xps_cpumasks(priv, &priv->channels.params);
+       }
+       err = mlx5e_update_tc_and_tx_queues(priv);
+       if (err) {
+               /* mlx5e_update_tc_and_tx_queues can fail if channels or TCs number increases.
+                * Since channel number changed, it increased. That means, the call to
+                * netif_set_real_num_rx_queues below should not fail, because it
+                * decreases the number of RX queues.
+                */
+               WARN_ON_ONCE(netif_set_real_num_rx_queues(netdev, old_num_rxqs));
+               return err;
+       }
 
        /* This function may be called on attach, before priv->rx_res is created. */
        if (priv->rx_res) {
@@ -3617,7 +3616,7 @@ static int mlx5e_setup_tc_mqprio_dcb(struct mlx5e_priv *priv,
        mlx5e_params_mqprio_dcb_set(&new_params, tc ? tc : 1);
 
        err = mlx5e_safe_switch_params(priv, &new_params,
-                                      mlx5e_num_channels_changed_ctx, NULL, true);
+                                      mlx5e_update_tc_and_tx_queues_ctx, NULL, true);
 
        if (!err && priv->mqprio_rl) {
                mlx5e_mqprio_rl_cleanup(priv->mqprio_rl);
@@ -3718,10 +3717,8 @@ static struct mlx5e_mqprio_rl *mlx5e_mqprio_rl_create(struct mlx5_core_dev *mdev
 static int mlx5e_setup_tc_mqprio_channel(struct mlx5e_priv *priv,
                                         struct tc_mqprio_qopt_offload *mqprio)
 {
-       mlx5e_fp_preactivate preactivate;
        struct mlx5e_params new_params;
        struct mlx5e_mqprio_rl *rl;
-       bool nch_changed;
        int err;
 
        err = mlx5e_mqprio_channel_validate(priv, mqprio);
@@ -3735,10 +3732,8 @@ static int mlx5e_setup_tc_mqprio_channel(struct mlx5e_priv *priv,
        new_params = priv->channels.params;
        mlx5e_params_mqprio_channel_set(&new_params, mqprio, rl);
 
-       nch_changed = mlx5e_get_dcb_num_tc(&priv->channels.params) > 1;
-       preactivate = nch_changed ? mlx5e_num_channels_changed_ctx :
-               mlx5e_update_netdev_queues_ctx;
-       err = mlx5e_safe_switch_params(priv, &new_params, preactivate, NULL, true);
+       err = mlx5e_safe_switch_params(priv, &new_params,
+                                      mlx5e_update_tc_and_tx_queues_ctx, NULL, true);
        if (err) {
                if (rl) {
                        mlx5e_mqprio_rl_cleanup(rl);