[PATCH net 09/11] net/mlx5e: Update and set Xon/Xoff upon MTU set

Mark Bloch posted 11 patches 1 month, 1 week ago
[PATCH net 09/11] net/mlx5e: Update and set Xon/Xoff upon MTU set
Posted by Mark Bloch 1 month, 1 week ago
From: Alexei Lazar <alazar@nvidia.com>

Xon/Xoff sizes are derived from calculation that include the MTU size.
Set Xon/Xoff when MTU is set.
If Xon/Xoff fails, set the previous MTU.

Fixes: 0696d60853d5 ("net/mlx5e: Receive buffer configuration")
Signed-off-by: Alexei Lazar <alazar@nvidia.com>
Reviewed-by: Tariq Toukan <tariqt@nvidia.com>
Signed-off-by: Mark Bloch <mbloch@nvidia.com>
---
 .../mellanox/mlx5/core/en/port_buffer.h         | 12 ++++++++++++
 .../net/ethernet/mellanox/mlx5/core/en_main.c   | 17 ++++++++++++++++-
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.h b/drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.h
index f4a19ffbb641..39efa4d98cc3 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.h
@@ -66,11 +66,23 @@ struct mlx5e_port_buffer {
 	struct mlx5e_bufferx_reg  buffer[MLX5E_MAX_NETWORK_BUFFER];
 };
 
+#ifdef CONFIG_MLX5_CORE_EN_DCB
 int mlx5e_port_manual_buffer_config(struct mlx5e_priv *priv,
 				    u32 change, unsigned int mtu,
 				    struct ieee_pfc *pfc,
 				    u32 *buffer_size,
 				    u8 *prio2buffer);
+#else
+static inline int
+mlx5e_port_manual_buffer_config(struct mlx5e_priv *priv,
+				u32 change, unsigned int mtu,
+				struct ieee_pfc *pfc,
+				u32 *buffer_size,
+				u8 *prio2buffer)
+{
+	return 0;
+}
+#endif
 
 int mlx5e_port_query_buffer(struct mlx5e_priv *priv,
 			    struct mlx5e_port_buffer *port_buffer);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
index 21bb88c5d3dc..15eded36b872 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c
@@ -49,6 +49,7 @@
 #include "en.h"
 #include "en/dim.h"
 #include "en/txrx.h"
+#include "en/port_buffer.h"
 #include "en_tc.h"
 #include "en_rep.h"
 #include "en_accel/ipsec.h"
@@ -3040,9 +3041,11 @@ int mlx5e_set_dev_port_mtu(struct mlx5e_priv *priv)
 	struct mlx5e_params *params = &priv->channels.params;
 	struct net_device *netdev = priv->netdev;
 	struct mlx5_core_dev *mdev = priv->mdev;
-	u16 mtu;
+	u16 mtu, prev_mtu;
 	int err;
 
+	mlx5e_query_mtu(mdev, params, &prev_mtu);
+
 	err = mlx5e_set_mtu(mdev, params, params->sw_mtu);
 	if (err)
 		return err;
@@ -3052,6 +3055,18 @@ int mlx5e_set_dev_port_mtu(struct mlx5e_priv *priv)
 		netdev_warn(netdev, "%s: VPort MTU %d is different than netdev mtu %d\n",
 			    __func__, mtu, params->sw_mtu);
 
+	if (mtu != prev_mtu && MLX5_BUFFER_SUPPORTED(mdev)) {
+		err = mlx5e_port_manual_buffer_config(priv, 0, mtu,
+						      NULL, NULL, NULL);
+		if (err) {
+			netdev_warn(netdev, "%s: Failed to set Xon/Xoff values with MTU %d (err %d), setting back to previous MTU %d\n",
+				    __func__, mtu, err, prev_mtu);
+
+			mlx5e_set_mtu(mdev, params, prev_mtu);
+			return err;
+		}
+	}
+
 	params->sw_mtu = mtu;
 	return 0;
 }
-- 
2.34.1
Re: [PATCH net 09/11] net/mlx5e: Update and set Xon/Xoff upon MTU set
Posted by kernel test robot 1 month, 1 week ago
Hi Mark,

kernel test robot noticed the following build warnings:

[auto build test WARNING on ec79003c5f9d2c7f9576fc69b8dbda80305cbe3a]

url:    https://github.com/intel-lab-lkp/linux/commits/Mark-Bloch/net-mlx5-HWS-Fix-memory-leak-in-hws_pool_buddy_init-error-path/20250824-164938
base:   ec79003c5f9d2c7f9576fc69b8dbda80305cbe3a
patch link:    https://lore.kernel.org/r/20250824083944.523858-10-mbloch%40nvidia.com
patch subject: [PATCH net 09/11] net/mlx5e: Update and set Xon/Xoff upon MTU set
config: um-randconfig-002-20250824 (https://download.01.org/0day-ci/archive/20250824/202508242120.QljNCAgz-lkp@intel.com/config)
compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project d26ea02060b1c9db751d188b2edb0059a9eb273d)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250824/202508242120.QljNCAgz-lkp@intel.com/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202508242120.QljNCAgz-lkp@intel.com/

All warnings (new ones prefixed by >>):

   In file included from drivers/net/ethernet/mellanox/mlx5/core/en_main.c:34:
   In file included from include/net/tc_act/tc_gact.h:5:
   In file included from include/net/act_api.h:10:
   In file included from include/net/flow_offload.h:6:
   In file included from include/linux/netlink.h:7:
   In file included from include/linux/skbuff.h:17:
   In file included from include/linux/bvec.h:10:
   In file included from include/linux/highmem.h:12:
   In file included from include/linux/hardirq.h:11:
   In file included from arch/um/include/asm/hardirq.h:5:
   In file included from include/asm-generic/hardirq.h:17:
   In file included from include/linux/irq.h:20:
   In file included from include/linux/io.h:12:
   In file included from arch/um/include/asm/io.h:24:
   include/asm-generic/io.h:1175:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
    1175 |         return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
         |                                                   ~~~~~~~~~~ ^
   In file included from drivers/net/ethernet/mellanox/mlx5/core/en_main.c:52:
>> drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.h:79:12: warning: declaration of 'struct ieee_pfc' will not be visible outside of this function [-Wvisibility]
      79 |                                 struct ieee_pfc *pfc,
         |                                        ^
   2 warnings generated.


vim +79 drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.h

    68	
    69	#ifdef CONFIG_MLX5_CORE_EN_DCB
    70	int mlx5e_port_manual_buffer_config(struct mlx5e_priv *priv,
    71					    u32 change, unsigned int mtu,
    72					    struct ieee_pfc *pfc,
    73					    u32 *buffer_size,
    74					    u8 *prio2buffer);
    75	#else
    76	static inline int
    77	mlx5e_port_manual_buffer_config(struct mlx5e_priv *priv,
    78					u32 change, unsigned int mtu,
  > 79					struct ieee_pfc *pfc,
    80					u32 *buffer_size,
    81					u8 *prio2buffer)
    82	{
    83		return 0;
    84	}
    85	#endif
    86	

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH net 09/11] net/mlx5e: Update and set Xon/Xoff upon MTU set
Posted by Mark Bloch 1 month, 1 week ago

On 24/08/2025 16:54, kernel test robot wrote:
> Hi Mark,
> 
> kernel test robot noticed the following build warnings:
> 
> [auto build test WARNING on ec79003c5f9d2c7f9576fc69b8dbda80305cbe3a]
> 
> url:    https://github.com/intel-lab-lkp/linux/commits/Mark-Bloch/net-mlx5-HWS-Fix-memory-leak-in-hws_pool_buddy_init-error-path/20250824-164938
> base:   ec79003c5f9d2c7f9576fc69b8dbda80305cbe3a
> patch link:    https://lore.kernel.org/r/20250824083944.523858-10-mbloch%40nvidia.com
> patch subject: [PATCH net 09/11] net/mlx5e: Update and set Xon/Xoff upon MTU set
> config: um-randconfig-002-20250824 (https://download.01.org/0day-ci/archive/20250824/202508242120.QljNCAgz-lkp@intel.com/config)
> compiler: clang version 22.0.0git (https://github.com/llvm/llvm-project d26ea02060b1c9db751d188b2edb0059a9eb273d)
> reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250824/202508242120.QljNCAgz-lkp@intel.com/reproduce)
> 
> If you fix the issue in a separate patch/commit (i.e. not just a new version of
> the same patch/commit), kindly add following tags
> | Reported-by: kernel test robot <lkp@intel.com>
> | Closes: https://lore.kernel.org/oe-kbuild-all/202508242120.QljNCAgz-lkp@intel.com/
> 
> All warnings (new ones prefixed by >>):
> 
>    In file included from drivers/net/ethernet/mellanox/mlx5/core/en_main.c:34:
>    In file included from include/net/tc_act/tc_gact.h:5:
>    In file included from include/net/act_api.h:10:
>    In file included from include/net/flow_offload.h:6:
>    In file included from include/linux/netlink.h:7:
>    In file included from include/linux/skbuff.h:17:
>    In file included from include/linux/bvec.h:10:
>    In file included from include/linux/highmem.h:12:
>    In file included from include/linux/hardirq.h:11:
>    In file included from arch/um/include/asm/hardirq.h:5:
>    In file included from include/asm-generic/hardirq.h:17:
>    In file included from include/linux/irq.h:20:
>    In file included from include/linux/io.h:12:
>    In file included from arch/um/include/asm/io.h:24:
>    include/asm-generic/io.h:1175:55: warning: performing pointer arithmetic on a null pointer has undefined behavior [-Wnull-pointer-arithmetic]
>     1175 |         return (port > MMIO_UPPER_LIMIT) ? NULL : PCI_IOBASE + port;
>          |                                                   ~~~~~~~~~~ ^
>    In file included from drivers/net/ethernet/mellanox/mlx5/core/en_main.c:52:
>>> drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.h:79:12: warning: declaration of 'struct ieee_pfc' will not be visible outside of this function [-Wvisibility]
>       79 |                                 struct ieee_pfc *pfc,
>          |                                        ^
>    2 warnings generated.

It seems net/dcbnl.h is only included (via linux/netdevice.h)
if CONFIG_DCB is set. We've tested only by not setting
CONFIG_MLX5_CORE_EN_DCB but left CONFIG_DCB set so it was missed.
Will fix.

Mark

> 
> 
> vim +79 drivers/net/ethernet/mellanox/mlx5/core/en/port_buffer.h
> 
>     68	
>     69	#ifdef CONFIG_MLX5_CORE_EN_DCB
>     70	int mlx5e_port_manual_buffer_config(struct mlx5e_priv *priv,
>     71					    u32 change, unsigned int mtu,
>     72					    struct ieee_pfc *pfc,
>     73					    u32 *buffer_size,
>     74					    u8 *prio2buffer);
>     75	#else
>     76	static inline int
>     77	mlx5e_port_manual_buffer_config(struct mlx5e_priv *priv,
>     78					u32 change, unsigned int mtu,
>   > 79					struct ieee_pfc *pfc,
>     80					u32 *buffer_size,
>     81					u8 *prio2buffer)
>     82	{
>     83		return 0;
>     84	}
>     85	#endif
>     86	
>