From: Tariq Toukan <tariqt@nvidia.com>
To: Andrew Lunn <andrew+netdev@lunn.ch>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, <netdev@vger.kernel.org>,
Paolo Abeni <pabeni@redhat.com>
Cc: Adithya Jayachandran <ajayachandra@nvidia.com>,
Edward Srouji <edwards@nvidia.com>, Gal Pressman <gal@nvidia.com>,
Jason Gunthorpe <jgg@ziepe.ca>, Jiri Pirko <jiri@resnulli.us>,
Leon Romanovsky <leon@kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-rdma@vger.kernel.org>, Maher Sanalla <msanalla@nvidia.com>,
Mark Bloch <mbloch@nvidia.com>, Moshe Shemesh <moshe@nvidia.com>,
Or Har-Toov <ohartoov@nvidia.com>,
Saeed Mahameed <saeedm@nvidia.com>, Shay Drori <shayd@nvidia.com>,
Simon Horman <horms@kernel.org>, Tariq Toukan <tariqt@nvidia.com>
Subject: [PATCH net 3/3] net/mlx5: E-Switch, preserve max tx speed on vport state modification
Date: Sun, 16 Aug 2026 09:50:15 +0300 [thread overview]
Message-ID: <20260816065015.3280733-4-tariqt@nvidia.com> (raw)
In-Reply-To: <20260816065015.3280733-1-tariqt@nvidia.com>
From: Or Har-Toov <ohartoov@nvidia.com>
When modifying vport state, the firmware interprets a zero in the max tx
speed field as an intentional reset, which can overwrite previously set
values. This patch attempts to fix this by querying the current max tx
speed from firmware before modifying the vport state and passing it back
in the modification command. If the query fails, fall back to the cached
agg_max_tx_speed value to avoid inadvertently resetting the speed.
Fixes: 50f1d188c580 ("net/mlx5: Propagate LAG effective max_tx_speed to vports")
Signed-off-by: Or Har-Toov <ohartoov@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Reviewed-by: Shay Drori <shayd@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../mellanox/mlx5/core/esw/adj_vport.c | 20 ++++++++++++++++
.../net/ethernet/mellanox/mlx5/core/vport.c | 24 +++++++++++++++++++
2 files changed, 44 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/esw/adj_vport.c b/drivers/net/ethernet/mellanox/mlx5/core/esw/adj_vport.c
index 3624c680a861..7950b82d8b8a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/esw/adj_vport.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/esw/adj_vport.c
@@ -11,6 +11,26 @@ int mlx5_esw_adj_vport_modify(struct mlx5_core_dev *dev, u16 vport,
lockdep_assert_held(&dev->priv.eswitch->state_lock);
+ if (MLX5_CAP_ESW(dev, esw_vport_state_max_tx_speed)) {
+ u8 op_mod = MLX5_VPORT_STATE_OP_MOD_ESW_VPORT;
+ struct mlx5_vport *esw_vport;
+ u32 speed = 0;
+ int err;
+
+ err = mlx5_query_vport_max_tx_speed(dev, op_mod, vport,
+ true, &speed, NULL);
+ if (err) {
+ esw_vport = mlx5_eswitch_get_vport(dev->priv.eswitch,
+ vport);
+ speed = IS_ERR(esw_vport) ? 0 :
+ esw_vport->agg_max_tx_speed;
+ mlx5_core_dbg(dev,
+ "Failed to query vport %d max tx speed, err=%d, using cached %u\n",
+ vport, err, speed);
+ }
+ MLX5_SET(modify_vport_state_in, in, max_tx_speed, speed);
+ }
+
MLX5_SET(modify_vport_state_in, in, opcode,
MLX5_CMD_OP_MODIFY_VPORT_STATE);
MLX5_SET(modify_vport_state_in, in, op_mod,
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/vport.c b/drivers/net/ethernet/mellanox/mlx5/core/vport.c
index edac2d694e0f..8aa94ec87a0e 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/vport.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/vport.c
@@ -93,6 +93,30 @@ int mlx5_modify_vport_admin_state(struct mlx5_core_dev *mdev, u8 opmod,
lockdep_assert_held(&mdev->priv.eswitch->state_lock);
#endif
+ if (MLX5_CAP_ESW(mdev, esw_vport_state_max_tx_speed) &&
+ opmod == MLX5_VPORT_STATE_OP_MOD_ESW_VPORT &&
+ vport != MLX5_VPORT_UPLINK) {
+ u32 speed = 0;
+ int err;
+
+ err = mlx5_query_vport_max_tx_speed(mdev, opmod, vport,
+ other_vport, &speed, NULL);
+ if (err) {
+#ifdef CONFIG_MLX5_ESWITCH
+ struct mlx5_vport *esw_vport;
+
+ esw_vport = mlx5_eswitch_get_vport(mdev->priv.eswitch,
+ vport);
+ speed = IS_ERR(esw_vport) ? 0 :
+ esw_vport->agg_max_tx_speed;
+#endif
+ mlx5_core_dbg(mdev,
+ "Failed to query vport %d max tx speed, err=%d, using cached %u\n",
+ vport, err, speed);
+ }
+ MLX5_SET(modify_vport_state_in, in, max_tx_speed, speed);
+ }
+
MLX5_SET(modify_vport_state_in, in, opcode,
MLX5_CMD_OP_MODIFY_VPORT_STATE);
MLX5_SET(modify_vport_state_in, in, op_mod, opmod);
--
2.44.0
prev parent reply other threads:[~2026-08-16 6:51 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-16 6:50 [PATCH net 0/3] net/mlx5: Preserve speed and state across vport modify commands Tariq Toukan
2026-08-16 6:50 ` [PATCH net 1/3] net/mlx5: E-Switch, use state lock for vport state changes Tariq Toukan
2026-08-16 6:50 ` [PATCH net 2/3] net/mlx5: Move vport DOWN state check out of mlx5_query_vport_max_tx_speed() Tariq Toukan
2026-08-16 6:50 ` Tariq Toukan [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260816065015.3280733-4-tariqt@nvidia.com \
--to=tariqt@nvidia.com \
--cc=ajayachandra@nvidia.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=edwards@nvidia.com \
--cc=gal@nvidia.com \
--cc=horms@kernel.org \
--cc=jgg@ziepe.ca \
--cc=jiri@resnulli.us \
--cc=kuba@kernel.org \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rdma@vger.kernel.org \
--cc=mbloch@nvidia.com \
--cc=moshe@nvidia.com \
--cc=msanalla@nvidia.com \
--cc=netdev@vger.kernel.org \
--cc=ohartoov@nvidia.com \
--cc=pabeni@redhat.com \
--cc=saeedm@nvidia.com \
--cc=shayd@nvidia.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox