Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

net/mlx5: LAG, replace mlx5_get_dev_index with LAG sequence number

Introduce mlx5_lag_get_dev_seq() which returns a device's sequence
number within the LAG: master is always 0, remaining devices numbered
sequentially. This provides a stable index for peer flow tracking and
vport ordering without depending on native_port_num.

Replace mlx5_get_dev_index() usage in en_tc.c (peer flow array
indexing) and ib_rep.c (vport index ordering) with the new API.

Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260309093435.1850724-7-tariqt@nvidia.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>

authored by

Shay Drory and committed by
Leon Romanovsky
971b28ac da0349d0

+53 -5
+3 -1
drivers/infiniband/hw/mlx5/ib_rep.c
··· 3 3 * Copyright (c) 2018 Mellanox Technologies. All rights reserved. 4 4 */ 5 5 6 + #include <linux/mlx5/lag.h> 6 7 #include <linux/mlx5/vport.h> 7 8 #include "ib_rep.h" 8 9 #include "srq.h" ··· 135 134 /* Only 1 ib port is the representor for all uplinks */ 136 135 peer_n_ports--; 137 136 138 - if (mlx5_get_dev_index(peer_dev) < mlx5_get_dev_index(dev)) 137 + if (mlx5_lag_get_dev_seq(peer_dev) < 138 + mlx5_lag_get_dev_seq(dev)) 139 139 vport_index += peer_n_ports; 140 140 } 141 141 }
+5 -4
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c
··· 35 35 #include <net/sch_generic.h> 36 36 #include <net/pkt_cls.h> 37 37 #include <linux/mlx5/fs.h> 38 + #include <linux/mlx5/lag.h> 38 39 #include <linux/mlx5/device.h> 39 40 #include <linux/rhashtable.h> 40 41 #include <linux/refcount.h> ··· 2132 2131 mutex_unlock(&esw->offloads.peer_mutex); 2133 2132 2134 2133 list_for_each_entry_safe(peer_flow, tmp, &flow->peer_flows, peer_flows) { 2135 - if (peer_index != mlx5_get_dev_index(peer_flow->priv->mdev)) 2134 + if (peer_index != mlx5_lag_get_dev_seq(peer_flow->priv->mdev)) 2136 2135 continue; 2137 2136 2138 2137 list_del(&peer_flow->peer_flows); ··· 2155 2154 2156 2155 devcom = flow->priv->mdev->priv.eswitch->devcom; 2157 2156 mlx5_devcom_for_each_peer_entry(devcom, peer_esw, pos) { 2158 - i = mlx5_get_dev_index(peer_esw->dev); 2157 + i = mlx5_lag_get_dev_seq(peer_esw->dev); 2159 2158 mlx5e_tc_del_fdb_peer_flow(flow, i); 2160 2159 } 2161 2160 } ··· 4585 4584 struct mlx5_eswitch *esw = priv->mdev->priv.eswitch; 4586 4585 struct mlx5_esw_flow_attr *attr = flow->attr->esw_attr; 4587 4586 struct mlx5e_tc_flow_parse_attr *parse_attr; 4588 - int i = mlx5_get_dev_index(peer_esw->dev); 4587 + int i = mlx5_lag_get_dev_seq(peer_esw->dev); 4589 4588 struct mlx5e_rep_priv *peer_urpriv; 4590 4589 struct mlx5e_tc_flow *peer_flow; 4591 4590 struct mlx5_core_dev *in_mdev; ··· 5526 5525 devcom = esw->devcom; 5527 5526 5528 5527 mlx5_devcom_for_each_peer_entry(devcom, peer_esw, pos) { 5529 - i = mlx5_get_dev_index(peer_esw->dev); 5528 + i = mlx5_lag_get_dev_seq(peer_esw->dev); 5530 5529 list_for_each_entry_safe(flow, tmp, &esw->offloads.peer_flows[i], peer[i]) 5531 5530 mlx5e_tc_del_fdb_peers_flow(flow); 5532 5531 }
+34
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
··· 35 35 #include <linux/mlx5/driver.h> 36 36 #include <linux/mlx5/eswitch.h> 37 37 #include <linux/mlx5/vport.h> 38 + #include <linux/mlx5/lag.h> 38 39 #include "lib/mlx5.h" 39 40 #include "lib/devcom.h" 40 41 #include "mlx5_core.h" ··· 369 368 } 370 369 return -ENOENT; 371 370 } 371 + 372 + /* Reverse of mlx5_lag_get_dev_index_by_seq: given a device, return its 373 + * sequence number in the LAG. Master is always 0, others numbered 374 + * sequentially starting from 1. 375 + */ 376 + int mlx5_lag_get_dev_seq(struct mlx5_core_dev *dev) 377 + { 378 + struct mlx5_lag *ldev = mlx5_lag_dev(dev); 379 + int master_idx, i, num = 1; 380 + struct lag_func *pf; 381 + 382 + if (!ldev) 383 + return -ENOENT; 384 + 385 + master_idx = mlx5_lag_get_master_idx(ldev); 386 + if (master_idx < 0) 387 + return -ENOENT; 388 + 389 + pf = mlx5_lag_pf(ldev, master_idx); 390 + if (pf && pf->dev == dev) 391 + return 0; 392 + 393 + mlx5_ldev_for_each(i, 0, ldev) { 394 + if (i == master_idx) 395 + continue; 396 + pf = mlx5_lag_pf(ldev, i); 397 + if (pf->dev == dev) 398 + return num; 399 + num++; 400 + } 401 + return -ENOENT; 402 + } 403 + EXPORT_SYMBOL(mlx5_lag_get_dev_seq); 372 404 373 405 /* Devcom events for LAG master marking */ 374 406 #define LAG_DEVCOM_PAIR (0)
+11
include/linux/mlx5/lag.h
··· 1 + /* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ 2 + /* Copyright (c) 2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ 3 + 4 + #ifndef __MLX5_LAG_API_H__ 5 + #define __MLX5_LAG_API_H__ 6 + 7 + struct mlx5_core_dev; 8 + 9 + int mlx5_lag_get_dev_seq(struct mlx5_core_dev *dev); 10 + 11 + #endif /* __MLX5_LAG_API_H__ */