* [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs
@ 2026-11-16 10:30 Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 01/10] net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG grouping Tariq Toukan
` (9 more replies)
0 siblings, 10 replies; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
Hi,
This series by Shay is the first part of enabling a LAG over functions
that do not represent a physical port - a "virtual LAG" (virt LAG) of
VFs or SFs acting as nested e-switch managers. New FW lets a VF/SF front
the physical uplinks through a multi-uplink e-switch; such a function
reports num_lag_ports < 2 and drives port selection via the e-switch
(port_select_eswitch) rather than the HW port-selection flow table. A
virt LAG is therefore a software-managed, shared-FDB MPESW LAG: the
driver builds the LAG demux and vport-LAG in software.
This part prepares the LAG core. A follow-up series adds the e-switch
and representor support and the patch that admits a virt LAG; until then
no ldev is marked as a virt LAG and the virt LAG paths added here are
unused.
The patches fall into two parts.
LAG code cleanup (patches 5, 6, 7, 8, 9)
- Finish removing the fixed MLX5_MAX_PORTS sizing the first series
began: convert the remaining structures to dynamic, port-count-based
allocation and inline iteration. A virt LAG's member count is
unrelated to the physical port count.
- Rename the LAG "pf" naming to "fn", since a member is now any
function (PF, VF or SF), not necessarily a PF.
- Resolve the queue-affinity member indices only in that mode, so the
other port-select modes are not rejected for indices they never use.
Virtual LAG core (patches 1, 2, 3, 4, 10)
- Distinguish VFs/SFs from their PF in the SW system image GUID, so
they group into their own LAG instead of with the PF.
- Select the MPESW master from the live member snapshot: VF/SF members
are dynamic and not marked by the devcom PAIR event, so the master
is chosen from the current membership (tie-broken by PCI BDF for
VFs, sfnum for SFs).
- Skip the phys-LAG prerequisites (port_select_flow_table,
create_lag_when_not_master_up, ...) for a virt LAG, and require
port_select_eswitch instead.
- Treat a virt LAG as a software-managed LAG (demux + vport-LAG in
SW).
- Do not add a device to an already-active virt LAG.
Regards,
Tariq
V2:
- Split the patch set to ease the review: this is v1 patches 1-10; v1
patches 11-15 will be sent as a follow-up series.
- Patch 1: define mlx5_virt_lag_is_supported() in
include/linux/mlx5/driver.h, so mlx5_ib can use it in the follow-up
series.
- Patch 3: fix the commit message: a LAG of VFs/SFs still issues
CREATE_LAG, but a VF/SF issuing it does not create a LAG of physical
ports (Sashiko).
- Patch 10: retitled, and the commit message says the rejection applies
only to a virt LAG, and why the other join paths are safe (Sashiko).
V1:
https://lore.kernel.org/all/20261103171009.563034-1-tariqt@nvidia.com/
Answers to sashiko comments on v1:
net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG grouping
Q: A VF/SF that reports multi_uplink_eswitch, lag_master and
num_lag_ports < 2 now gets a key that differs from its PF's key, and
mlx5_same_hw_devs() requires the keys to match exactly. Does this break
PF to VF/SF same-HW detection, e.g. mlx5e_tc_is_vf_tunnel() and mirred
offload in NIC mode? Should mlx5_same_hw_devs() use a key without the
VF/SF markers?
[SD] No, this is the point of the patch. A VF/SF that reports
multi_uplink_eswitch and lag_master (and num_lag_ports < 2) is a nested
eswitch manager. That makes it a different switch domain from its
PF, not one more vport of the PF's FDB, so it must not be identified as
the same HW as the PF. Without the marker it would also be grouped into
the PF's LAG, which is what the patch prevents.
A VF/SF that does not report these caps, i.e. every VF/SF that exists
today, keeps its key unchanged and is still the same HW as its PF, as
the commit message says. Dropping the markers inside mlx5_same_hw_devs()
would make a nested eswitch manager the same HW as its PF again, i.e.
undo the patch.
net/mlx5: LAG, skip phys LAG prerequisites for a virt LAG
> + if (mlx5_eswitch_mode(dev0) != MLX5_ESWITCH_OFFLOADS ||
> + !MLX5_CAP_PORT_SELECTION(dev0, port_select_eswitch) ||
Q: mlx5_virt_lag_is_supported() does not check port_select_eswitch. A
VF/SF that reports multi_uplink_eswitch and lag_master but not
port_select_eswitch would get the VF/SF marker in its SW GUID and join a
virt ldev, yet MPESW could never be enabled on it. Should
port_select_eswitch be checked in mlx5_virt_lag_is_supported() instead,
so the two checks agree?
[SD] The two checks are at different stages on purpose. A function with
the first two and without the third doesn't exist.
Even if it were, the result is benign: the function stays an inactive
member and esw_multiport fails cleanly with -EOPNOTSUPP, nothing else
changes.
net/mlx5: LAG, treat virt LAG as a software managed LAG
> -static int mlx5_lag_is_sw_lag(struct mlx5_core_dev *dev)
> +int mlx5_lag_is_sw_managed(struct mlx5_core_dev *dev)
> {
> - return mlx5_lag_is_sd(dev);
> + struct mlx5_lag *ldev = mlx5_lag_dev(dev);
Q: If dev is NULL, does mlx5_lag_dev(dev) NULL-deref dev->priv.lag? When
called from mlx5_lag_multipath_check_prereq() via the FIB notifier,
pf->dev can be NULL due to concurrent removal in mlx5_ldev_remove_mdev().
__mlx5_lag_is_sd() was safe (lockless pointer compare). Does this need a
NULL check?
[SD] mlx5_lag_is_sw_managed() assumes a valid dev pointer, like the rest
of the mlx5_lag_is_* APIs. It is true mlx5_lag_multipath_check_prereq()
can provide an invalid device pointer, but that is an existing bug there
which should be handled in its own patch.
net/mlx5: LAG, decouple iteration end-of-walk from MLX5_MAX_PORTS
> - if (i < MLX5_MAX_PORTS) {
> + if (i < ldev->ports) {
> slave = bond_slave_get_rcu(ndev_tmp);
Q: Should this compare against ldev->max_funcs, like the other converted
call sites? A PORT-marked member can sit at an index in
[ldev->ports, max_funcs) if more PFs than num_lag_ports join the ldev
and a lower-index one is removed later. Physical ports also share the
xarray with VFs/SFs. Wouldn't that leave the bond silently not
offloaded?
[SD] No. mlx5 creates an ldev per sw_guid, and PFs have a different
sw_guid than VFs/SFs, so only PFs share this ldev. The only case with
more PFs than num_lag_ports in one ldev is SD, and for SD the netdev
notifier, and with it mlx5_handle_changeupper_event(), is not
registered. So a PORT-marked member here always sits at an index below
ldev->ports.
> - err = xa_alloc(&ldev->pfs, &idx, pf, XA_LIMIT(0, MLX5_MAX_PORTS - 1),
> + err = xa_alloc(&ldev->pfs, &idx, pf, XA_LIMIT(0, U8_MAX - 1),
Q: Physical members and Socket Direct secondaries share the xarray index
space. Can a physical member get an index >= MLX5_MAX_PORTS and make
mlx5_ldev_add_netdev() write beyond tracker.netdev_state[]?
[SD] Such HW doesn't exist; it needs LAG over SD with more than
MLX5_MAX_PORTS / 2 ports, and when it does MLX5_MAX_PORTS will be
increased. To protect a new HW running an old driver, a check that
num_lag_ports times the SD group size fits in MLX5_MAX_PORTS will be added
to mlx5_lag_is_supported() separately.
Q: Can removing the xa_alloc() limit let member indices reach 8 or more
while pf_metadata[], devs[], the cong counter array,
tracker.netdev_state[] and the port_sel rules[] are still sized
MLX5_MAX_PORTS? Could the limit stay at MLX5_MAX_PORTS - 1 until all of
these users are converted?
[SD] No. In this series a 9th member is impossible: an ldev holds only
PFs and SD secondaries, and no HW has more than MLX5_MAX_PORTS of them.
VFs/SFs join an ldev only in the follow-up series.
The limit can't be kept until all arrays are converted, since not all
of them will be. Some arrays are used only by a PF LAG, others by both a
PF LAG and a virt LAG. The shared ones, the fns xarray included, are
converted in this series (pf_metadata[] and devs[]; the cong counter
array is converted as well). The PF LAG only ones,
tracker.netdev_state[] and the port_sel rules[], keep their static
MLX5_MAX_PORTS size: they are walked only over PORT-marked members, in
the hash and queue affinity modes. A virt member is never PORT-marked
and sits in its own ldev, and a virt LAG supports only MPESW, so these
arrays never see more than MLX5_MAX_PORTS entries.
> + /* max_funcs is the iteration ceiling; grow it, never shrink. */
> + if (idx >= ldev->max_funcs)
> + ldev->max_funcs = idx + 1;
Q: Is this store safe against readers that only hold lag_lock?
mlx5_lag_get_next_peer_mdev(), mlx5_lag_get_slave_port() and
mlx5_lag_query_cong_counters() read max_funcs more than once per walk,
so a concurrent add could make the sentinel and the loop condition
disagree, and the body could see a pf whose dev is not set yet.
[SD] all the readers above running only while LAG is active, and
mlx5_lag_query_cong_counters() and mlx5_lag_get_slave_port() check
whether lag is active explicitly before walking over the lag
> - ldev->ports);
> + ldev->max_funcs);
Q: The commit message says "No functional change". Is that accurate?
max_slaves sizes the master's egress ACL, so the size of the hardware
flow table changes whenever max_funcs != ports.
[SD] Only the ACL size changes, and only for SD, where more PFs than
ports join the ldev and max_funcs > ports. The rules installed are the
same as before, so there is no functional change.
Q: end_flow_index is inclusive, so the master egress group spans
max_slaves + 1 entries in a table created with max_fte = max_slaves.
If max_slaves equals a flow table pool size, e.g. 128, can the group
creation fail?
[SD] This is theoretical only; there is no such use case. In this
series max_slaves is at most MLX5_MAX_PORTS, and the table is rounded
up to 128 entries, so the group fits.
Q: The patch also changes the xa_alloc() limit in mlx5_ldev_add_mdev(),
which now accepts a 9th member, and the found check in
mlx5_handle_changeupper_event(), which now uses i < ldev->ports. Could
the commit message describe these changes?
[SD] The xa_alloc() change is already in the commit message ("remove the
xa_alloc() limit of MLX5_MAX_PORTS"), and the answer above explains why
it can't let in a 9th member.
mlx5_handle_changeupper_event() runs only for a PF LAG without SD: the
netdev notifier is registered only when !mlx5_sd_is_supported(). There
each LAG port is one PF at an xarray index below ldev->ports
(num_lag_ports), so "i < ldev->ports" is true in exactly the same cases
as the old end-of-walk check.
net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation
> + ldev = mlx5_lag_dev(dev);
> + num_ports = ldev ? max_t(int, ldev->ports, 1) : 1;
> + mdev = kcalloc(num_ports, sizeof(mdev[0]), GFP_KERNEL);
Q: Could mlx5_lag_query_cong_counters() keep a freed ldev across this
sleeping allocation if teardown removes the association and drops the
last LAG reference before the query resumes?
[SD] No. The query runs on the IB device of dev, and dev leaves the LAG
only in its own teardown, after its IB device is unregistered.
Q: Can this loop write past the end of mdev[]? The array has
max(ldev->ports, 1) entries, mlx5_ldev_for_each() writes one entry per
PORT-marked member, and nothing caps the PORT-marked members at
ldev->ports. Should the loop break once idx >= num_ports?
[SD] It can't. The loop runs only for a non-virt LAG, and the
PORT-marked members of such an ldev are the PFs of one card, at most
num_lag_ports == ldev->ports of them (an SD secondary is not PORT-marked
and a virt member is excluded by the !ldev->virt_lag check right here).
Q: Can mlx5_mpesw_metadata_cleanup() index past the end of
pf_metadata[]? The buffer is sized by ldev->max_fns when MPESW is
enabled, but sd_lag_init() can add SD secondaries afterwards and grow
max_fns, and the cleanup loop stops at the current max_fns.
[SD] this is pre-existing bug, MPESW should failed if SD Secondary
is down. this will be handle in separate patch.
net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan
> + mlx5_lag_for_each(i, 0, ldev, filter) {
> + pf = mlx5_lag_pf(ldev, i);
> + ...
> + mlx5_rescan_drivers_locked(pf->dev);
Q: Is it safe to iterate the LAG PFs and deref pf->dev while ldev->lock is
dropped?
[SD] Valid. Membership can be removed by SD cleanup while ldev->lock
is dropped; this will be fixed in a separate patch.
Q: Does using the sparse XArray index directly as a dense-array index
cause OOB writes elsewhere? With Socket Direct the XArray index (i) for a
primary port can exceed ldev->ports, and it is used directly in
mlx5_infer_tx_affinity_mapping() (ports[idx]) and
mlx5_handle_changelowerstate_event() (tracker->netdev_state[idx]) - could
these overflow the heap/stack buffers?
[SD] All these buffers aren't used in LAG over SD; only MPESW is, and
MPESW doesn't use these APIs.
net/mlx5: LAG, do not add a device to an already-active virt LAG
Q: After this change only -EOPNOTSUPP is final. Every other error from
__mlx5_lag_dev_add_mdev() is retried with no limit. xa_alloc() returns
-EBUSY once all 255 slots are in use, and membership does not change
while the probe waits. Can mlx5_load() loop forever? Would it make sense
to retry only on -EAGAIN?
[SD] This is pre-existing: mlx5_lag_add_mdev() retried every error
before this series as well. for example future HW can return -EBUSY.
The fix will be sent as a separate patch.
Shay Drory (10):
net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG
grouping
net/mlx5: LAG, select the MPESW master from the live member snapshot
net/mlx5: LAG, skip phys LAG prerequisites for a virt LAG
net/mlx5: LAG, treat virt LAG as a software managed LAG
net/mlx5: LAG, decouple iteration end-of-walk from MLX5_MAX_PORTS
net/mlx5: LAG, rename PF naming to fn
net/mlx5: LAG, resolve affinity indices only in queue-affinity mode
net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic
allocation
net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan
net/mlx5: LAG, do not add a device to an already-active virt LAG
.../mellanox/mlx5/core/eswitch_offloads.c | 4 +
.../ethernet/mellanox/mlx5/core/lag/debugfs.c | 2 +-
.../net/ethernet/mellanox/mlx5/core/lag/lag.c | 568 ++++++++++--------
.../net/ethernet/mellanox/mlx5/core/lag/lag.h | 62 +-
.../net/ethernet/mellanox/mlx5/core/lag/mp.c | 29 +-
.../ethernet/mellanox/mlx5/core/lag/mpesw.c | 125 ++--
.../ethernet/mellanox/mlx5/core/lag/mpesw.h | 2 +-
.../mellanox/mlx5/core/lag/port_sel.c | 25 +-
.../mellanox/mlx5/core/lag/shared_fdb.c | 44 +-
.../net/ethernet/mellanox/mlx5/core/lib/sd.c | 32 +-
.../ethernet/mellanox/mlx5/core/sf/dev/dev.h | 12 +
.../net/ethernet/mellanox/mlx5/core/vport.c | 40 +-
include/linux/mlx5/driver.h | 11 +-
13 files changed, 573 insertions(+), 383 deletions(-)
base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next V2 01/10] net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG grouping
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
@ 2026-11-16 10:30 ` Tariq Toukan
2026-11-18 10:31 ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 02/10] net/mlx5: LAG, select the MPESW master from the live member snapshot Tariq Toukan
` (8 subsequent siblings)
9 siblings, 1 reply; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
From: Shay Drory <shayd@nvidia.com>
mlx5_query_nic_sw_system_image_guid() builds the key used to group
devices that may form a LAG. A PF and its VFs/SFs share the same FW
system image GUID, so without a discriminator a VF/SF that can join a
virt LAG would be grouped with its PF.
Appending bare discriminator bytes at conditional offsets is not enough:
distinct capability sets can collapse to the same key (a PF ending in a
load_balance byte of 0x01 vs a VF whose marker is 0x01). Give each
discriminator a fixed position instead, and add the VF and SF as such
fields. Trailing zero fields are trimmed, so keys of devices that set
none of the new fields are unchanged.
Set the VF/SF markers only when mlx5_virt_lag_is_supported(). The same
key also backs mlx5_same_hw_devs(), so a VF/SF that cannot join a virt
LAG keeps its current key and is still identified as the same HW as its
PF.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/vport.c | 40 +++++++++++++++++--
include/linux/mlx5/driver.h | 11 ++++-
2 files changed, 47 insertions(+), 4 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/vport.c b/drivers/net/ethernet/mellanox/mlx5/core/vport.c
index 78f3d15b599d..bab43df6a7d7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/vport.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/vport.c
@@ -1308,10 +1308,37 @@ u64 mlx5_query_nic_system_image_guid(struct mlx5_core_dev *mdev)
}
EXPORT_SYMBOL_GPL(mlx5_query_nic_system_image_guid);
+static u8 mlx5_sw_guid_load_balance(const struct mlx5_core_dev *mdev)
+{
+ if (MLX5_CAP_GEN_2(mdev, load_balance_id) &&
+ MLX5_CAP_GEN_2(mdev, lag_per_mp_group))
+ return MLX5_CAP_GEN_2(mdev, load_balance_id);
+ return 0;
+}
+
+static u8 mlx5_sw_guid_sf(const struct mlx5_core_dev *mdev)
+{
+ return mlx5_core_is_sf(mdev) && mlx5_virt_lag_is_supported(mdev);
+}
+
+static u8 mlx5_sw_guid_vf(const struct mlx5_core_dev *mdev)
+{
+ return mlx5_core_is_vf(mdev) && mlx5_virt_lag_is_supported(mdev);
+}
+
+static u8 (* const mlx5_sw_guid_fields[])(const struct mlx5_core_dev *mdev) = {
+ mlx5_sw_guid_load_balance,
+ mlx5_sw_guid_vf,
+ mlx5_sw_guid_sf,
+ /* New fields should be added at the end */
+};
+
void mlx5_query_nic_sw_system_image_guid(struct mlx5_core_dev *mdev, u8 *buf,
u8 *len)
{
u64 fw_system_image_guid;
+ u8 trim_len;
+ int i;
*len = 0;
@@ -1321,10 +1348,17 @@ void mlx5_query_nic_sw_system_image_guid(struct mlx5_core_dev *mdev, u8 *buf,
memcpy(buf, &fw_system_image_guid, sizeof(fw_system_image_guid));
*len += sizeof(fw_system_image_guid);
+ trim_len = *len;
- if (MLX5_CAP_GEN_2(mdev, load_balance_id) &&
- MLX5_CAP_GEN_2(mdev, lag_per_mp_group))
- buf[(*len)++] = MLX5_CAP_GEN_2(mdev, load_balance_id);
+ for (i = 0; i < ARRAY_SIZE(mlx5_sw_guid_fields); i++) {
+ u8 val = mlx5_sw_guid_fields[i](mdev);
+
+ buf[(*len)++] = val;
+ if (val)
+ trim_len = *len;
+ }
+
+ *len = trim_len;
}
bool mlx5_vport_use_vhca_id_as_func_id(struct mlx5_core_dev *dev,
diff --git a/include/linux/mlx5/driver.h b/include/linux/mlx5/driver.h
index 84e9f6bdb7c1..e28b9c23c165 100644
--- a/include/linux/mlx5/driver.h
+++ b/include/linux/mlx5/driver.h
@@ -1270,6 +1270,15 @@ static inline int mlx5_lag_is_lacp_owner(struct mlx5_core_dev *dev)
MLX5_CAP_GEN(dev, lag_master);
}
+static inline bool mlx5_virt_lag_is_supported(const struct mlx5_core_dev *dev)
+{
+ if (!MLX5_CAP_GEN(dev, multi_uplink_eswitch) ||
+ !MLX5_CAP_GEN(dev, lag_master) ||
+ MLX5_CAP_GEN(dev, num_lag_ports) >= 2)
+ return false;
+ return true;
+}
+
static inline u16 mlx5_core_max_ec_vfs(const struct mlx5_core_dev *dev)
{
return dev->priv.sriov.max_ec_vfs;
@@ -1399,7 +1408,7 @@ static inline struct net *mlx5_core_net(struct mlx5_core_dev *dev)
return devlink_net(priv_to_devlink(dev));
}
-#define MLX5_SW_IMAGE_GUID_MAX_BYTES 9
+#define MLX5_SW_IMAGE_GUID_MAX_BYTES 11
static inline bool mlx5_data_direct_supported(struct mlx5_core_dev *mdev)
{
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next V2 02/10] net/mlx5: LAG, select the MPESW master from the live member snapshot
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 01/10] net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG grouping Tariq Toukan
@ 2026-11-16 10:30 ` Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 03/10] net/mlx5: LAG, skip phys LAG prerequisites for a virt LAG Tariq Toukan
` (7 subsequent siblings)
9 siblings, 0 replies; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
From: Shay Drory <shayd@nvidia.com>
The LAG master is marked by the devcom PAIR event when all physical
ports have registered (mlx5_lag_num_devs() == ldev->ports). That does
not work for a virtual LAG of VFs/SFs: those functions are unrelated to
the physical port count.
Select the master from the current membership snapshot in
mlx5_lag_enable_mpesw() via mlx5_virt_lag_mark_master(), and clear it in
mlx5_lag_disable_mpesw(). Unlike the regular path, it walks all LAG
members.
mlx5_get_dev_index() is identical for a PF and all its VFs/SFs, so
tie-break by a stable per-member key is used - PCI BDF for VFs, sfnum
for SFs.
This is gated by a new ldev->virt_lag bit identifying this type of LAG.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/lag/lag.c | 46 +++++++++++++++++--
.../net/ethernet/mellanox/mlx5/core/lag/lag.h | 3 ++
.../ethernet/mellanox/mlx5/core/lag/mpesw.c | 42 +++++++++++++----
.../ethernet/mellanox/mlx5/core/sf/dev/dev.h | 12 +++++
4 files changed, 90 insertions(+), 13 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
index 9330aab24c02..c7ece82fd457 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -39,6 +39,7 @@
#include "lib/mlx5.h"
#include "lib/devcom.h"
#include "mlx5_core.h"
+#include "sf/dev/dev.h"
#include "eswitch.h"
#include "esw/acl/ofld.h"
#include "lag.h"
@@ -598,7 +599,43 @@ static void mlx5_lag_mark_master(struct mlx5_lag *ldev)
xa_set_mark(&ldev->pfs, master_xa_idx, MLX5_LAG_XA_MARK_MASTER);
}
-static void mlx5_lag_clear_master(struct mlx5_lag *ldev)
+static u64 mlx5_lag_member_tiebreak(struct mlx5_core_dev *dev)
+{
+ struct pci_dev *pdev = dev->pdev;
+
+ if (mlx5_core_is_sf(dev))
+ return mlx5_sf_coredev_sfnum(dev);
+
+ return ((u64)pci_domain_nr(pdev->bus) << 16) | pci_dev_id(pdev);
+}
+
+void mlx5_virt_lag_mark_master(struct mlx5_lag *ldev)
+{
+ u64 lowest_tiebreak = U64_MAX;
+ int lowest_dev_idx = INT_MAX;
+ int master_xa_idx = -1;
+ struct lag_func *pf;
+ u64 tiebreak;
+ int dev_idx;
+ int i;
+
+ mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
+ pf = mlx5_lag_pf(ldev, i);
+ dev_idx = mlx5_get_dev_index(pf->dev);
+ tiebreak = mlx5_lag_member_tiebreak(pf->dev);
+ if (dev_idx < lowest_dev_idx ||
+ (dev_idx == lowest_dev_idx && tiebreak < lowest_tiebreak)) {
+ lowest_dev_idx = dev_idx;
+ lowest_tiebreak = tiebreak;
+ master_xa_idx = i;
+ }
+ }
+
+ if (master_xa_idx >= 0)
+ xa_set_mark(&ldev->pfs, master_xa_idx, MLX5_LAG_XA_MARK_MASTER);
+}
+
+void mlx5_lag_clear_master(struct mlx5_lag *ldev)
{
unsigned long idx = 0;
void *entry;
@@ -618,7 +655,7 @@ static int mlx5_lag_devcom_event(int event, void *my_data, void *event_data)
int idx;
ldev = mlx5_lag_dev(dev);
- if (!ldev)
+ if (!ldev || ldev->virt_lag)
return 0;
mutex_lock(&ldev->lock);
@@ -1784,10 +1821,13 @@ struct mlx5_devcom_comp_dev *mlx5_lag_get_devcom_comp(struct mlx5_lag *ldev)
{
struct mlx5_devcom_comp_dev *devcom = NULL;
struct lag_func *pf;
+ u32 filter;
int i;
mutex_lock(&ldev->lock);
- i = mlx5_get_next_lag_func(ldev, 0, MLX5_LAG_FILTER_PORTS);
+ filter = ldev->virt_lag ? MLX5_LAG_FILTER_ALL :
+ MLX5_LAG_FILTER_PORTS;
+ i = mlx5_get_next_lag_func(ldev, 0, filter);
if (i < MLX5_MAX_PORTS) {
pf = mlx5_lag_pf(ldev, i);
devcom = pf->dev->priv.hca_devcom_comp;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
index 8552792b9035..21c83f51fcb5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
@@ -84,6 +84,7 @@ struct mlx5_lag {
unsigned long state_flags;
u8 ports;
u8 buckets;
+ bool virt_lag;
int mode_changes_in_progress;
u8 *v2p_map;
struct kref ref;
@@ -225,6 +226,8 @@ static inline bool mlx5_lag_shared_fdb_supported(struct mlx5_lag *ldev)
}
#endif
bool mlx5_lag_check_prereq(struct mlx5_lag *ldev);
+void mlx5_virt_lag_mark_master(struct mlx5_lag *ldev);
+void mlx5_lag_clear_master(struct mlx5_lag *ldev);
bool mlx5_lag_is_sd(struct mlx5_core_dev *dev);
int mlx5_lag_demux_init(struct mlx5_core_dev *dev,
struct mlx5_flow_table_attr *ft_attr);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
index 549d31812c2f..0bf5b4754a44 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
@@ -109,8 +109,8 @@ static bool mlx5_lag_has_sd_group(struct mlx5_lag *ldev)
static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)
{
- int idx = mlx5_lag_get_dev_index_by_seq(ldev, MLX5_LAG_P1);
struct mlx5_core_dev *dev0;
+ int idx;
int err;
if (ldev->mode == MLX5_LAG_MODE_MPESW)
@@ -119,20 +119,32 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)
if (ldev->mode != MLX5_LAG_MODE_NONE)
return -EINVAL;
- if (idx < 0)
- return -EINVAL;
+ /* VFs/SFs (nested LAG) are not marked by the LAG devcom PAIR event;
+ * select the master from the current snapshot before resolving it via
+ * mlx5_lag_get_dev_index_by_seq().
+ */
+ if (ldev->virt_lag)
+ mlx5_virt_lag_mark_master(ldev);
+
+ idx = mlx5_lag_get_dev_index_by_seq(ldev, MLX5_LAG_P1);
+ if (idx < 0) {
+ err = -EINVAL;
+ goto err_clear_master;
+ }
dev0 = mlx5_lag_pf(ldev, idx)->dev;
if (mlx5_eswitch_mode(dev0) != MLX5_ESWITCH_OFFLOADS ||
!MLX5_CAP_PORT_SELECTION(dev0, port_select_flow_table) ||
!MLX5_CAP_GEN(dev0, create_lag_when_not_master_up) ||
!mlx5_lag_check_prereq(ldev) ||
- !mlx5_lag_shared_fdb_supported_filter(ldev, MLX5_LAG_FILTER_ALL))
- return -EOPNOTSUPP;
+ !mlx5_lag_shared_fdb_supported_filter(ldev, MLX5_LAG_FILTER_ALL)) {
+ err = -EOPNOTSUPP;
+ goto err_clear_master;
+ }
err = mlx5_mpesw_metadata_set(ldev);
if (err)
- return err;
+ goto err_clear_master;
if (mlx5_lag_has_sd_group(ldev))
mlx5_mpesw_teardown_sd_fdb(ldev);
@@ -143,13 +155,19 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)
mlx5_core_warn(dev0,
"Failed to create LAG in MPESW mode (%d)\n",
err);
- if (mlx5_lag_has_sd_group(ldev))
- mlx5_mpesw_restore_sd_fdb(ldev);
- mlx5_mpesw_metadata_cleanup(ldev);
- return err;
+ goto err_restore;
}
return 0;
+
+err_restore:
+ if (mlx5_lag_has_sd_group(ldev))
+ mlx5_mpesw_restore_sd_fdb(ldev);
+ mlx5_mpesw_metadata_cleanup(ldev);
+err_clear_master:
+ if (ldev->virt_lag)
+ mlx5_lag_clear_master(ldev);
+ return err;
}
void mlx5_lag_disable_mpesw(struct mlx5_lag *ldev)
@@ -161,6 +179,10 @@ void mlx5_lag_disable_mpesw(struct mlx5_lag *ldev)
mlx5_lag_shared_fdb_destroy(ldev, MLX5_LAG_FILTER_ALL);
if (mlx5_lag_has_sd_group(ldev))
mlx5_mpesw_restore_sd_fdb(ldev);
+
+ /* Pair with the master mark taken at MPESW create for VFs. */
+ if (ldev->virt_lag)
+ mlx5_lag_clear_master(ldev);
}
void mlx5_mpesw_sd_devcoms_lock(struct mlx5_lag *ldev)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h
index 3ab0449c770c..382162baabdb 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/sf/dev/dev.h
@@ -19,6 +19,13 @@ struct mlx5_sf_dev {
u16 fn_id;
};
+static inline u32 mlx5_sf_coredev_sfnum(struct mlx5_core_dev *mdev)
+{
+ struct auxiliary_device *adev = mlx5_sf_coredev_to_adev(mdev);
+
+ return container_of(adev, struct mlx5_sf_dev, adev)->sfnum;
+}
+
struct mlx5_sf_peer_devlink_event_ctx {
u16 fn_id;
struct devlink *devlink;
@@ -68,6 +75,11 @@ static inline bool mlx5_sf_dev_allocated(const struct mlx5_core_dev *dev)
return false;
}
+static inline u32 mlx5_sf_coredev_sfnum(struct mlx5_core_dev *mdev)
+{
+ return 0;
+}
+
#endif
#endif
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next V2 03/10] net/mlx5: LAG, skip phys LAG prerequisites for a virt LAG
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 01/10] net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG grouping Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 02/10] net/mlx5: LAG, select the MPESW master from the live member snapshot Tariq Toukan
@ 2026-11-16 10:30 ` Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 04/10] net/mlx5: LAG, treat virt LAG as a software managed LAG Tariq Toukan
` (6 subsequent siblings)
9 siblings, 0 replies; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
From: Shay Drory <shayd@nvidia.com>
mlx5_lag_enable_mpesw() gates on port_select_flow_table and
create_lag_when_not_master_up, and on mlx5_lag_check_prereq(). Those
describe the phys LAG: the port-selection flow table and the
physical-LAG prerequisites (e.g. member count equal to the physical port
count).
A LAG of VFs/SFs still issues the same CREATE_LAG command in MPESW mode
from its master. Issued by a VF/SF, though, the command has different
semantics: it does not create a LAG of physical ports, so these checks
do not apply and would reject it outright. Require them only when it is
a phys LAG; a LAG of VFs/SFs instead requires port_select_eswitch.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../ethernet/mellanox/mlx5/core/lag/mpesw.c | 31 ++++++++++++++++---
1 file changed, 26 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
index 0bf5b4754a44..fd70fbebb1de 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
@@ -107,9 +107,32 @@ static bool mlx5_lag_has_sd_group(struct mlx5_lag *ldev)
return false;
}
+static bool mlx5_phys_mpesw_validate(struct mlx5_lag *ldev,
+ struct mlx5_core_dev *dev0)
+{
+ if (mlx5_eswitch_mode(dev0) != MLX5_ESWITCH_OFFLOADS ||
+ !MLX5_CAP_PORT_SELECTION(dev0, port_select_flow_table) ||
+ !MLX5_CAP_GEN(dev0, create_lag_when_not_master_up) ||
+ !mlx5_lag_check_prereq(ldev) ||
+ !mlx5_lag_shared_fdb_supported_filter(ldev, MLX5_LAG_FILTER_ALL))
+ return false;
+ return true;
+}
+
+static bool mlx5_virt_mpesw_validate(struct mlx5_lag *ldev,
+ struct mlx5_core_dev *dev0)
+{
+ if (mlx5_eswitch_mode(dev0) != MLX5_ESWITCH_OFFLOADS ||
+ !MLX5_CAP_PORT_SELECTION(dev0, port_select_eswitch) ||
+ !mlx5_lag_shared_fdb_supported_filter(ldev, MLX5_LAG_FILTER_ALL))
+ return false;
+ return true;
+}
+
static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)
{
struct mlx5_core_dev *dev0;
+ bool valid;
int idx;
int err;
@@ -133,11 +156,9 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)
}
dev0 = mlx5_lag_pf(ldev, idx)->dev;
- if (mlx5_eswitch_mode(dev0) != MLX5_ESWITCH_OFFLOADS ||
- !MLX5_CAP_PORT_SELECTION(dev0, port_select_flow_table) ||
- !MLX5_CAP_GEN(dev0, create_lag_when_not_master_up) ||
- !mlx5_lag_check_prereq(ldev) ||
- !mlx5_lag_shared_fdb_supported_filter(ldev, MLX5_LAG_FILTER_ALL)) {
+ valid = ldev->virt_lag ? mlx5_virt_mpesw_validate(ldev, dev0) :
+ mlx5_phys_mpesw_validate(ldev, dev0);
+ if (!valid) {
err = -EOPNOTSUPP;
goto err_clear_master;
}
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next V2 04/10] net/mlx5: LAG, treat virt LAG as a software managed LAG
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
` (2 preceding siblings ...)
2026-11-16 10:30 ` [PATCH net-next V2 03/10] net/mlx5: LAG, skip phys LAG prerequisites for a virt LAG Tariq Toukan
@ 2026-11-16 10:30 ` Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 05/10] net/mlx5: LAG, decouple iteration end-of-walk from MLX5_MAX_PORTS Tariq Toukan
` (5 subsequent siblings)
9 siblings, 0 replies; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
From: Shay Drory <shayd@nvidia.com>
mlx5_lag_is_sw_managed() (renamed from mlx5_lag_is_sw_lag()) marks the
LAG paths the driver builds in software - the LAG demux and vport-LAG -
which must skip the FW vport-LAG commands. A virt LAG is
software-managed like an SD LAG.
In the same manner, block multipath LAG over virt LAG as well.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c | 12 +++++++-----
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h | 1 +
drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c | 4 ++--
3 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
index c7ece82fd457..669b2167a82d 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -173,9 +173,11 @@ static u32 mlx5_lag_dev_group_id(struct mlx5_core_dev *dev)
return 0;
}
-static int mlx5_lag_is_sw_lag(struct mlx5_core_dev *dev)
+bool mlx5_lag_is_sw_managed(struct mlx5_core_dev *dev)
{
- return mlx5_lag_is_sd(dev);
+ struct mlx5_lag *ldev = mlx5_lag_dev(dev);
+
+ return mlx5_lag_is_sd(dev) || (ldev && ldev->virt_lag);
}
int mlx5_cmd_create_vport_lag(struct mlx5_core_dev *dev)
@@ -184,7 +186,7 @@ int mlx5_cmd_create_vport_lag(struct mlx5_core_dev *dev)
struct mlx5_lag *ldev = mlx5_lag_dev(dev);
int ret;
- if (mlx5_lag_is_sw_lag(dev)) {
+ if (mlx5_lag_is_sw_managed(dev)) {
if (!ldev)
return -ENODEV;
@@ -206,7 +208,7 @@ int mlx5_cmd_destroy_vport_lag(struct mlx5_core_dev *dev)
u32 in[MLX5_ST_SZ_DW(destroy_vport_lag_in)] = {};
struct mlx5_lag *ldev = mlx5_lag_dev(dev);
- if (mlx5_lag_is_sw_lag(dev)) {
+ if (mlx5_lag_is_sw_managed(dev)) {
if (!ldev)
return 0;
@@ -1911,7 +1913,7 @@ int mlx5_lag_demux_init(struct mlx5_core_dev *dev,
xa_init(&pf->lag_demux_rules);
- if (mlx5_lag_is_sw_lag(dev))
+ if (mlx5_lag_is_sw_managed(dev))
return mlx5_lag_demux_ft_fg_init(dev, ft_attr, pf);
return mlx5_lag_demux_fw_init(dev, ft_attr, pf);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
index 21c83f51fcb5..94e07870e506 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
@@ -229,6 +229,7 @@ bool mlx5_lag_check_prereq(struct mlx5_lag *ldev);
void mlx5_virt_lag_mark_master(struct mlx5_lag *ldev);
void mlx5_lag_clear_master(struct mlx5_lag *ldev);
bool mlx5_lag_is_sd(struct mlx5_core_dev *dev);
+bool mlx5_lag_is_sw_managed(struct mlx5_core_dev *dev);
int mlx5_lag_demux_init(struct mlx5_core_dev *dev,
struct mlx5_flow_table_attr *ft_attr);
void mlx5_lag_demux_cleanup(struct mlx5_core_dev *dev);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c
index 65c76bd748c6..2077fc5d80c7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c
@@ -26,8 +26,8 @@ static bool mlx5_lag_multipath_check_prereq(struct mlx5_lag *ldev)
if (__mlx5_lag_is_active(ldev) && !__mlx5_lag_is_multipath(ldev))
return false;
- if (__mlx5_lag_is_sd(ldev, mlx5_lag_pf(ldev, idx0)->dev) ||
- __mlx5_lag_is_sd(ldev, mlx5_lag_pf(ldev, idx1)->dev))
+ if (mlx5_lag_is_sw_managed(mlx5_lag_pf(ldev, idx0)->dev) ||
+ mlx5_lag_is_sw_managed(mlx5_lag_pf(ldev, idx1)->dev))
return false;
if (ldev->ports > MLX5_LAG_MULTIPATH_OFFLOADS_SUPPORTED_PORTS)
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next V2 05/10] net/mlx5: LAG, decouple iteration end-of-walk from MLX5_MAX_PORTS
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
` (3 preceding siblings ...)
2026-11-16 10:30 ` [PATCH net-next V2 04/10] net/mlx5: LAG, treat virt LAG as a software managed LAG Tariq Toukan
@ 2026-11-16 10:30 ` Tariq Toukan
2026-11-18 10:31 ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 06/10] net/mlx5: LAG, rename PF naming to fn Tariq Toukan
` (4 subsequent siblings)
9 siblings, 1 reply; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
From: Shay Drory <shayd@nvidia.com>
The LAG xarray iterators returned MLX5_MAX_PORTS as their end-of-walk
sentinel, and the open-coded callers compared the current index against
MLX5_MAX_PORTS to detect the end of iteration. This ties iteration to a
compile-time maximum rather than to the actual number of LAG members.
Add ldev->max_funcs, and use it as the loop bound. Update the open-coded
callers accordingly. When a member is added at an xarray index >=
ldev->max_funcs, increase max_funcs.
In addition, remove the xa_alloc() limit of MLX5_MAX_PORTS.
No functional change; this only removes the dependency on
MLX5_MAX_PORTS.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/lag/lag.c | 22 +++++++++++--------
.../net/ethernet/mellanox/mlx5/core/lag/lag.h | 3 ++-
.../ethernet/mellanox/mlx5/core/lag/mpesw.c | 2 +-
.../mellanox/mlx5/core/lag/shared_fdb.c | 2 +-
4 files changed, 17 insertions(+), 12 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
index 669b2167a82d..cbef6ab1e38a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -395,6 +395,7 @@ static struct mlx5_lag *mlx5_lag_dev_alloc(struct mlx5_core_dev *dev)
mlx5_core_err(dev, "Failed to init multipath lag err=%d\n",
err);
+ ldev->max_funcs = ldev->ports;
return ldev;
err_wq:
@@ -1283,7 +1284,7 @@ static void mlx5_lag_assert_locked_transition(struct mlx5_lag *ldev, u32 filter)
lockdep_assert_held(&ldev->lock);
i = mlx5_get_next_lag_func(ldev, 0, filter);
- if (i < MLX5_MAX_PORTS) {
+ if (i < ldev->max_funcs) {
pf = mlx5_lag_pf(ldev, i);
if (filter == MLX5_LAG_FILTER_PORTS ||
filter == MLX5_LAG_FILTER_ALL)
@@ -1830,7 +1831,7 @@ struct mlx5_devcom_comp_dev *mlx5_lag_get_devcom_comp(struct mlx5_lag *ldev)
filter = ldev->virt_lag ? MLX5_LAG_FILTER_ALL :
MLX5_LAG_FILTER_PORTS;
i = mlx5_get_next_lag_func(ldev, 0, filter);
- if (i < MLX5_MAX_PORTS) {
+ if (i < ldev->max_funcs) {
pf = mlx5_lag_pf(ldev, i);
devcom = pf->dev->priv.hca_devcom_comp;
}
@@ -2094,7 +2095,7 @@ static int mlx5_handle_changeupper_event(struct mlx5_lag *ldev,
break;
}
}
- if (i < MLX5_MAX_PORTS) {
+ if (i < ldev->ports) {
if (netif_is_bond_master(upper)) {
slave = bond_slave_get_rcu(ndev_tmp);
if (slave)
@@ -2359,13 +2360,16 @@ int mlx5_ldev_add_mdev(struct mlx5_lag *ldev,
if (!pf)
return -ENOMEM;
- err = xa_alloc(&ldev->pfs, &idx, pf, XA_LIMIT(0, MLX5_MAX_PORTS - 1),
+ err = xa_alloc(&ldev->pfs, &idx, pf, XA_LIMIT(0, U8_MAX - 1),
GFP_KERNEL);
if (err) {
kfree(pf);
return err;
}
+ /* max_funcs is the iteration ceiling; grow it, never shrink. */
+ if (idx >= ldev->max_funcs)
+ ldev->max_funcs = idx + 1;
pf->idx = idx;
pf->dev = dev;
pf->group_id = group_id;
@@ -2394,7 +2398,7 @@ void mlx5_ldev_remove_mdev(struct mlx5_lag *ldev,
if (pf->dev == dev)
break;
}
- if (i >= MLX5_MAX_PORTS)
+ if (i >= ldev->max_funcs)
return;
if (pf->port_change_nb.nb.notifier_call)
@@ -2607,7 +2611,7 @@ int mlx5_get_next_lag_func(struct mlx5_lag *ldev, int start_idx, u32 filter)
MLX5_LAG_XA_MARK_PORT, start_idx)
if (pf->dev)
return idx;
- return MLX5_MAX_PORTS;
+ return ldev->max_funcs;
}
xa_for_each_start(&ldev->pfs, idx, pf, start_idx) {
@@ -2617,7 +2621,7 @@ int mlx5_get_next_lag_func(struct mlx5_lag *ldev, int start_idx, u32 filter)
filter == pf->group_id)
return idx;
}
- return MLX5_MAX_PORTS;
+ return ldev->max_funcs;
}
bool mlx5_lag_is_roce(struct mlx5_core_dev *dev)
@@ -2867,7 +2871,7 @@ struct mlx5_core_dev *mlx5_lag_get_next_peer_mdev(struct mlx5_core_dev *dev, int
if (!ldev)
goto unlock;
- if (*i == MLX5_MAX_PORTS)
+ if (*i == ldev->max_funcs)
goto unlock;
mlx5_lag_for_each(idx, *i, ldev, mlx5_lag_get_filter(ldev, dev)) {
pf = mlx5_lag_pf(ldev, idx);
@@ -2875,7 +2879,7 @@ struct mlx5_core_dev *mlx5_lag_get_next_peer_mdev(struct mlx5_core_dev *dev, int
break;
}
- if (idx == MLX5_MAX_PORTS) {
+ if (idx == ldev->max_funcs) {
*i = idx;
goto unlock;
}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
index 94e07870e506..1dcd0b87997f 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
@@ -83,6 +83,7 @@ struct mlx5_lag {
unsigned long mode_flags;
unsigned long state_flags;
u8 ports;
+ u8 max_funcs;
u8 buckets;
bool virt_lag;
int mode_changes_in_progress;
@@ -289,7 +290,7 @@ static inline bool mlx5_lag_is_supported(struct mlx5_core_dev *dev)
#define mlx5_lag_for_each(i, start_index, ldev, filter) \
for (int tmp = start_index; \
tmp = mlx5_get_next_lag_func(ldev, tmp, filter), \
- i = tmp, tmp < MLX5_MAX_PORTS; tmp++)
+ i = tmp, tmp < (ldev)->max_funcs; tmp++)
#define mlx5_lag_for_each_reverse(i, start_index, end_index, ldev, filter) \
for (int tmp = start_index, tmp1 = end_index; \
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
index fd70fbebb1de..45e92d71e62c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
@@ -223,7 +223,7 @@ void mlx5_mpesw_sd_devcoms_unlock(struct mlx5_lag *ldev)
struct mlx5_devcom_comp_dev *sd_devcom;
int i;
- mlx5_ldev_for_each_reverse(i, MLX5_MAX_PORTS, 0, ldev) {
+ mlx5_ldev_for_each_reverse(i, ldev->max_funcs, 0, ldev) {
sd_devcom = mlx5_sd_get_devcom(mlx5_lag_pf(ldev, i)->dev);
if (sd_devcom)
mlx5_devcom_comp_unlock(sd_devcom);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
index 7c7e6c832a93..29048b0c2797 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
@@ -71,7 +71,7 @@ static int mlx5_lag_create_single_fdb_filter(struct mlx5_lag *ldev, u32 filter)
err = mlx5_eswitch_offloads_single_fdb_add_one(master_esw,
slave_esw,
- ldev->ports);
+ ldev->max_funcs);
if (err)
goto err;
}
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next V2 06/10] net/mlx5: LAG, rename PF naming to fn
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
` (4 preceding siblings ...)
2026-11-16 10:30 ` [PATCH net-next V2 05/10] net/mlx5: LAG, decouple iteration end-of-walk from MLX5_MAX_PORTS Tariq Toukan
@ 2026-11-16 10:30 ` Tariq Toukan
2026-11-18 10:31 ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 07/10] net/mlx5: LAG, resolve affinity indices only in queue-affinity mode Tariq Toukan
` (3 subsequent siblings)
9 siblings, 1 reply; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
From: Shay Drory <shayd@nvidia.com>
The LAG member bookkeeping is named after physical functions: the xarray
is ldev->pfs, the lookup helpers are mlx5_lag_pf(),
mlx5_lag_pf_by_dev(), mlx5_lag_pf_by_dev_idx() and
mlx5_lag_dev_get_master_pf(), and the local variables holding the result
are pf.
A follow-up series enables virt LAG, which means LAG members won't
always be physical functions.
Rename the xarray to ldev->fns, the helpers to mlx5_lag_fn*(), and the
locals to fn, so the naming matches struct lag_fn.
No functional change.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../ethernet/mellanox/mlx5/core/lag/debugfs.c | 2 +-
.../net/ethernet/mellanox/mlx5/core/lag/lag.c | 472 +++++++++---------
.../net/ethernet/mellanox/mlx5/core/lag/lag.h | 54 +-
.../net/ethernet/mellanox/mlx5/core/lag/mp.c | 29 +-
.../ethernet/mellanox/mlx5/core/lag/mpesw.c | 42 +-
.../mellanox/mlx5/core/lag/port_sel.c | 25 +-
.../mellanox/mlx5/core/lag/shared_fdb.c | 44 +-
.../net/ethernet/mellanox/mlx5/core/lib/sd.c | 32 +-
8 files changed, 354 insertions(+), 346 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c
index b6125c7bd91b..116432cb7ce5 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/debugfs.c
@@ -154,7 +154,7 @@ static int members_show(struct seq_file *file, void *priv)
mutex_lock(&ldev->lock);
mlx5_ldev_for_each(i, 0, ldev)
seq_printf(file, "%s\n",
- dev_name(mlx5_lag_pf(ldev, i)->dev->device));
+ dev_name(mlx5_lag_fn(ldev, i)->dev->device));
mutex_unlock(&ldev->lock);
return 0;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
index cbef6ab1e38a..74e7e7161c95 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -159,16 +159,16 @@ static int mlx5_cmd_modify_lag(struct mlx5_core_dev *dev, struct mlx5_lag *ldev,
static u32 mlx5_lag_dev_group_id(struct mlx5_core_dev *dev)
{
struct mlx5_lag *ldev = mlx5_lag_dev(dev);
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
if (!ldev)
return 0;
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->dev == dev)
- return pf->sd_fdb_active ? pf->group_id : 0;
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->dev == dev)
+ return fn->sd_fdb_active ? fn->group_id : 0;
}
return 0;
}
@@ -313,7 +313,7 @@ static void mlx5_do_bond_work(struct work_struct *work);
static void mlx5_ldev_free(struct kref *ref)
{
struct mlx5_lag *ldev = container_of(ref, struct mlx5_lag, ref);
- struct lag_func *pf;
+ struct lag_fn *fn;
struct net *net;
int i;
@@ -323,16 +323,16 @@ static void mlx5_ldev_free(struct kref *ref)
}
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->port_change_nb.nb.notifier_call) {
- struct mlx5_nb *nb = &pf->port_change_nb;
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->port_change_nb.nb.notifier_call) {
+ struct mlx5_nb *nb = &fn->port_change_nb;
- mlx5_eq_notifier_unregister(pf->dev, nb);
+ mlx5_eq_notifier_unregister(fn->dev, nb);
}
- xa_erase(&ldev->pfs, i);
- kfree(pf);
+ xa_erase(&ldev->fns, i);
+ kfree(fn);
}
- xa_destroy(&ldev->pfs);
+ xa_destroy(&ldev->fns);
mlx5_lag_mp_cleanup(ldev);
cancel_delayed_work_sync(&ldev->bond_work);
@@ -375,7 +375,7 @@ static struct mlx5_lag *mlx5_lag_dev_alloc(struct mlx5_core_dev *dev)
kref_init(&ldev->ref);
mutex_init(&ldev->lock);
- xa_init_flags(&ldev->pfs, XA_FLAGS_ALLOC);
+ xa_init_flags(&ldev->fns, XA_FLAGS_ALLOC);
INIT_DELAYED_WORK(&ldev->bond_work, mlx5_do_bond_work);
INIT_WORK(&ldev->speed_update_work, mlx5_mpesw_speed_update_work);
@@ -395,7 +395,7 @@ static struct mlx5_lag *mlx5_lag_dev_alloc(struct mlx5_core_dev *dev)
mlx5_core_err(dev, "Failed to init multipath lag err=%d\n",
err);
- ldev->max_funcs = ldev->ports;
+ ldev->max_fns = ldev->ports;
return ldev;
err_wq:
@@ -408,12 +408,12 @@ static struct mlx5_lag *mlx5_lag_dev_alloc(struct mlx5_core_dev *dev)
int mlx5_lag_dev_get_netdev_idx(struct mlx5_lag *ldev,
struct net_device *ndev)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->netdev == ndev)
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->netdev == ndev)
return i;
}
@@ -428,7 +428,7 @@ static int mlx5_lag_get_master_idx(struct mlx5_lag *ldev)
if (!ldev)
return -ENOENT;
- entry = xa_find(&ldev->pfs, &idx, U8_MAX, MLX5_LAG_XA_MARK_MASTER);
+ entry = xa_find(&ldev->fns, &idx, U8_MAX, MLX5_LAG_XA_MARK_MASTER);
if (!entry)
return -ENOENT;
@@ -470,11 +470,11 @@ int mlx5_lag_get_dev_index_by_seq(struct mlx5_lag *ldev, int seq)
*/
static u32 mlx5_lag_get_filter(struct mlx5_lag *ldev, struct mlx5_core_dev *dev)
{
- struct lag_func *pf = mlx5_lag_pf_by_dev(ldev, dev);
+ struct lag_fn *fn = mlx5_lag_fn_by_dev(ldev, dev);
- if (pf && pf->sd_fdb_active)
- return pf->group_id;
- if (pf && pf->group_id)
+ if (fn && fn->sd_fdb_active)
+ return fn->group_id;
+ if (fn && fn->group_id)
return MLX5_LAG_FILTER_ALL;
return MLX5_LAG_FILTER_PORTS;
}
@@ -487,7 +487,7 @@ int mlx5_lag_get_dev_seq(struct mlx5_core_dev *dev)
{
struct mlx5_lag *ldev = mlx5_lag_dev(dev);
int master_idx, i, num = 1;
- struct lag_func *pf;
+ struct lag_fn *fn;
u32 filter;
if (!ldev)
@@ -498,15 +498,15 @@ int mlx5_lag_get_dev_seq(struct mlx5_core_dev *dev)
if (master_idx < 0)
return -ENOENT;
- pf = mlx5_lag_pf(ldev, master_idx);
- if (pf && pf->dev == dev)
+ fn = mlx5_lag_fn(ldev, master_idx);
+ if (fn && fn->dev == dev)
return 0;
mlx5_lag_for_each(i, 0, ldev, filter) {
if (i == master_idx)
continue;
- pf = mlx5_lag_pf(ldev, i);
- if (pf->dev == dev)
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->dev == dev)
return num;
num++;
}
@@ -544,7 +544,7 @@ static int mlx5_lag_get_dev_index_by_seq_group(struct mlx5_lag *ldev, int seq,
int i, num = 0;
mlx5_lag_for_each(i, 0, ldev, group_id) {
- if (xa_get_mark(&ldev->pfs, i, MLX5_LAG_XA_MARK_PORT)) {
+ if (xa_get_mark(&ldev->fns, i, MLX5_LAG_XA_MARK_PORT)) {
if (seq == 0)
return i;
num++;
@@ -553,7 +553,7 @@ static int mlx5_lag_get_dev_index_by_seq_group(struct mlx5_lag *ldev, int seq,
}
mlx5_lag_for_each(i, 0, ldev, group_id) {
- if (xa_get_mark(&ldev->pfs, i, MLX5_LAG_XA_MARK_PORT))
+ if (xa_get_mark(&ldev->fns, i, MLX5_LAG_XA_MARK_PORT))
continue;
if (num == seq)
return i;
@@ -584,14 +584,14 @@ int mlx5_lag_get_dev_index_by_seq_filter(struct mlx5_lag *ldev, int seq,
static void mlx5_lag_mark_master(struct mlx5_lag *ldev)
{
int lowest_dev_idx = INT_MAX;
- struct lag_func *pf;
+ struct lag_fn *fn;
int master_xa_idx = -1;
int dev_idx;
int i;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- dev_idx = mlx5_get_dev_index(pf->dev);
+ fn = mlx5_lag_fn(ldev, i);
+ dev_idx = mlx5_get_dev_index(fn->dev);
if (dev_idx < lowest_dev_idx) {
lowest_dev_idx = dev_idx;
master_xa_idx = i;
@@ -599,7 +599,7 @@ static void mlx5_lag_mark_master(struct mlx5_lag *ldev)
}
if (master_xa_idx >= 0)
- xa_set_mark(&ldev->pfs, master_xa_idx, MLX5_LAG_XA_MARK_MASTER);
+ xa_set_mark(&ldev->fns, master_xa_idx, MLX5_LAG_XA_MARK_MASTER);
}
static u64 mlx5_lag_member_tiebreak(struct mlx5_core_dev *dev)
@@ -617,15 +617,15 @@ void mlx5_virt_lag_mark_master(struct mlx5_lag *ldev)
u64 lowest_tiebreak = U64_MAX;
int lowest_dev_idx = INT_MAX;
int master_xa_idx = -1;
- struct lag_func *pf;
+ struct lag_fn *fn;
u64 tiebreak;
int dev_idx;
int i;
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
- pf = mlx5_lag_pf(ldev, i);
- dev_idx = mlx5_get_dev_index(pf->dev);
- tiebreak = mlx5_lag_member_tiebreak(pf->dev);
+ fn = mlx5_lag_fn(ldev, i);
+ dev_idx = mlx5_get_dev_index(fn->dev);
+ tiebreak = mlx5_lag_member_tiebreak(fn->dev);
if (dev_idx < lowest_dev_idx ||
(dev_idx == lowest_dev_idx && tiebreak < lowest_tiebreak)) {
lowest_dev_idx = dev_idx;
@@ -635,7 +635,7 @@ void mlx5_virt_lag_mark_master(struct mlx5_lag *ldev)
}
if (master_xa_idx >= 0)
- xa_set_mark(&ldev->pfs, master_xa_idx, MLX5_LAG_XA_MARK_MASTER);
+ xa_set_mark(&ldev->fns, master_xa_idx, MLX5_LAG_XA_MARK_MASTER);
}
void mlx5_lag_clear_master(struct mlx5_lag *ldev)
@@ -643,11 +643,11 @@ void mlx5_lag_clear_master(struct mlx5_lag *ldev)
unsigned long idx = 0;
void *entry;
- entry = xa_find(&ldev->pfs, &idx, U8_MAX, MLX5_LAG_XA_MARK_MASTER);
+ entry = xa_find(&ldev->fns, &idx, U8_MAX, MLX5_LAG_XA_MARK_MASTER);
if (!entry)
return;
- xa_clear_mark(&ldev->pfs, idx, MLX5_LAG_XA_MARK_MASTER);
+ xa_clear_mark(&ldev->fns, idx, MLX5_LAG_XA_MARK_MASTER);
}
/* Devcom event handler to manage LAG master marking */
@@ -698,15 +698,15 @@ int mlx5_lag_num_devs(struct mlx5_lag *ldev)
int mlx5_lag_num_netdevs(struct mlx5_lag *ldev)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
int i, num = 0;
if (!ldev)
return 0;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->netdev)
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->netdev)
num++;
}
return num;
@@ -725,9 +725,9 @@ static bool __mlx5_lag_is_sriov(struct mlx5_lag *ldev)
static bool __mlx5_lag_is_sd_active(struct mlx5_lag *ldev,
struct mlx5_core_dev *dev)
{
- struct lag_func *pf = mlx5_lag_pf_by_dev(ldev, dev);
+ struct lag_fn *fn = mlx5_lag_fn_by_dev(ldev, dev);
- return pf && pf->sd_fdb_active;
+ return fn && fn->sd_fdb_active;
}
/* Create a mapping between steering slots and active ports.
@@ -802,12 +802,12 @@ static int mlx5_infer_tx_affinity_mapping(struct lag_tracker *tracker,
static bool mlx5_lag_has_drop_rule(struct mlx5_lag *ldev)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->has_drop)
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->has_drop)
return true;
}
return false;
@@ -815,17 +815,19 @@ static bool mlx5_lag_has_drop_rule(struct mlx5_lag *ldev)
static void mlx5_lag_drop_rule_cleanup(struct mlx5_lag *ldev)
{
- struct lag_func *pf;
+ struct mlx5_eswitch *esw;
+ struct lag_fn *fn;
int i;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (!pf->has_drop)
+ fn = mlx5_lag_fn(ldev, i);
+ if (!fn->has_drop)
continue;
- mlx5_esw_acl_ingress_vport_drop_rule_destroy(pf->dev->priv.eswitch,
+ esw = fn->dev->priv.eswitch;
+ mlx5_esw_acl_ingress_vport_drop_rule_destroy(esw,
MLX5_VPORT_UPLINK);
- pf->has_drop = false;
+ fn->has_drop = false;
}
}
@@ -833,7 +835,7 @@ static void mlx5_lag_drop_rule_setup(struct mlx5_lag *ldev,
struct lag_tracker *tracker)
{
struct mlx5_core_dev *dev;
- struct lag_func *pf;
+ struct lag_fn *fn;
int err;
int i;
@@ -849,12 +851,12 @@ static void mlx5_lag_drop_rule_setup(struct mlx5_lag *ldev,
if (tracker->netdev_state[i].tx_enabled &&
tracker->netdev_state[i].link_up)
continue;
- pf = mlx5_lag_pf(ldev, i);
- dev = pf->dev;
+ fn = mlx5_lag_fn(ldev, i);
+ dev = fn->dev;
err = mlx5_esw_acl_ingress_vport_drop_rule_create(dev->priv.eswitch,
MLX5_VPORT_UPLINK);
if (!err)
- pf->has_drop = true;
+ fn->has_drop = true;
else
mlx5_core_err(dev,
"Failed to create lag drop rule, error: %d",
@@ -888,7 +890,7 @@ static int _mlx5_modify_lag(struct mlx5_lag *ldev,
if (idx < 0)
return -EINVAL;
- dev0 = mlx5_lag_pf(ldev, idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, idx)->dev;
if (test_bit(MLX5_LAG_MODE_FLAG_HASH_BASED, &ldev->mode_flags)) {
ret = mlx5_lag_port_sel_modify(ldev, ports);
if (ret ||
@@ -908,7 +910,7 @@ static int _mlx5_modify_lag(struct mlx5_lag *ldev,
static struct net_device *mlx5_lag_active_backup_get_netdev(struct mlx5_core_dev *dev)
{
struct net_device *ndev = NULL;
- struct lag_func *pf;
+ struct lag_fn *fn;
struct mlx5_lag *ldev;
unsigned long flags;
int i, last_idx;
@@ -920,16 +922,16 @@ static struct net_device *mlx5_lag_active_backup_get_netdev(struct mlx5_core_dev
goto unlock;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
+ fn = mlx5_lag_fn(ldev, i);
if (ldev->tracker.netdev_state[i].tx_enabled)
- ndev = pf->netdev;
+ ndev = fn->netdev;
}
if (!ndev) {
last_idx = mlx5_lag_get_dev_index_by_seq(ldev, ldev->ports - 1);
if (last_idx < 0)
goto unlock;
- pf = mlx5_lag_pf(ldev, last_idx);
- ndev = pf->netdev;
+ fn = mlx5_lag_fn(ldev, last_idx);
+ ndev = fn->netdev;
}
dev_hold(ndev);
@@ -954,7 +956,7 @@ void mlx5_modify_lag(struct mlx5_lag *ldev,
if (first_idx < 0)
return;
- dev0 = mlx5_lag_pf(ldev, first_idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, first_idx)->dev;
ports = kcalloc(ldev->ports * MLX5_LAG_MAX_HASH_BUCKETS,
sizeof(*ports), GFP_KERNEL);
@@ -1022,7 +1024,7 @@ static int mlx5_lag_set_port_sel_mode(struct mlx5_lag *ldev,
mode == MLX5_LAG_MODE_MULTIPATH)
return 0;
- dev0 = mlx5_lag_pf(ldev, first_idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, first_idx)->dev;
if (!MLX5_CAP_PORT_SELECTION(dev0, port_select_flow_table)) {
if (ldev->ports > 2)
@@ -1080,7 +1082,7 @@ static int mlx5_create_lag(struct mlx5_lag *ldev,
if (first_idx < 0)
return -EINVAL;
- dev0 = mlx5_lag_pf(ldev, first_idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, first_idx)->dev;
if (tracker)
mlx5_lag_print_mapping(dev0, ldev, tracker, flags);
mlx5_core_info(dev0, "shared_fdb:%d mode:%s\n",
@@ -1128,7 +1130,7 @@ int mlx5_activate_lag(struct mlx5_lag *ldev,
if (master_idx < 0)
return -EINVAL;
- dev0 = mlx5_lag_pf(ldev, master_idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, master_idx)->dev;
err = mlx5_lag_set_flags(ldev, mode, tracker, shared_fdb, &flags);
if (err)
return err;
@@ -1191,7 +1193,7 @@ int mlx5_deactivate_lag(struct mlx5_lag *ldev)
if (master_idx < 0)
return -EINVAL;
- dev0 = mlx5_lag_pf(ldev, master_idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, master_idx)->dev;
ldev->mode = MLX5_LAG_MODE_NONE;
ldev->mode_flags = 0;
mlx5_lag_mp_reset(ldev);
@@ -1231,7 +1233,7 @@ bool mlx5_lag_check_prereq(struct mlx5_lag *ldev)
struct mlx5_core_dev *dev;
u8 mode;
#endif
- struct lag_func *pf;
+ struct lag_fn *fn;
bool roce_support;
int i;
@@ -1240,35 +1242,35 @@ bool mlx5_lag_check_prereq(struct mlx5_lag *ldev)
#ifdef CONFIG_MLX5_ESWITCH
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- dev = pf->dev;
+ fn = mlx5_lag_fn(ldev, i);
+ dev = fn->dev;
if (mlx5_eswitch_num_vfs(dev->priv.eswitch) && !is_mdev_switchdev_mode(dev))
return false;
}
- pf = mlx5_lag_pf(ldev, master_idx);
- dev = pf->dev;
+ fn = mlx5_lag_fn(ldev, master_idx);
+ dev = fn->dev;
mode = mlx5_eswitch_mode(dev);
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (mlx5_eswitch_mode(pf->dev) != mode)
+ fn = mlx5_lag_fn(ldev, i);
+ if (mlx5_eswitch_mode(fn->dev) != mode)
return false;
}
#else
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (mlx5_sriov_is_enabled(pf->dev))
+ fn = mlx5_lag_fn(ldev, i);
+ if (mlx5_sriov_is_enabled(fn->dev))
return false;
}
#endif
- pf = mlx5_lag_pf(ldev, master_idx);
- roce_support = mlx5_get_roce_state(pf->dev);
+ fn = mlx5_lag_fn(ldev, master_idx);
+ roce_support = mlx5_get_roce_state(fn->dev);
mlx5_ldev_for_each(i, 0, ldev) {
if (i == master_idx)
continue;
- pf = mlx5_lag_pf(ldev, i);
- if (mlx5_get_roce_state(pf->dev) != roce_support)
+ fn = mlx5_lag_fn(ldev, i);
+ if (mlx5_get_roce_state(fn->dev) != roce_support)
return false;
}
@@ -1278,19 +1280,19 @@ bool mlx5_lag_check_prereq(struct mlx5_lag *ldev)
static void mlx5_lag_assert_locked_transition(struct mlx5_lag *ldev, u32 filter)
{
struct mlx5_devcom_comp_dev *devcom = NULL;
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
lockdep_assert_held(&ldev->lock);
i = mlx5_get_next_lag_func(ldev, 0, filter);
- if (i < ldev->max_funcs) {
- pf = mlx5_lag_pf(ldev, i);
+ if (i < ldev->max_fns) {
+ fn = mlx5_lag_fn(ldev, i);
if (filter == MLX5_LAG_FILTER_PORTS ||
filter == MLX5_LAG_FILTER_ALL)
- devcom = pf->dev->priv.hca_devcom_comp;
+ devcom = fn->dev->priv.hca_devcom_comp;
else
- devcom = mlx5_sd_get_devcom(pf->dev);
+ devcom = mlx5_sd_get_devcom(fn->dev);
}
mlx5_devcom_comp_assert_locked(devcom);
}
@@ -1337,22 +1339,22 @@ static void mlx5_lag_rescan_devices_locked_filter(struct mlx5_lag *ldev,
bool enable, u32 filter)
{
struct mlx5_core_dev *devs[MLX5_MAX_PORTS];
- struct lag_func *pf;
+ struct lag_fn *fn;
int num_devs = 0;
int i;
mlx5_lag_assert_locked_transition(ldev, filter);
mlx5_lag_for_each(i, 0, ldev, filter) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->dev->priv.flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV)
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->dev->priv.flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV)
continue;
if (enable)
- pf->dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
+ fn->dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
else
- pf->dev->priv.flags |= MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
- devs[num_devs++] = pf->dev;
+ fn->dev->priv.flags |= MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
+ devs[num_devs++] = fn->dev;
}
mlx5_lag_drop_lock_for_reps(ldev, filter);
@@ -1384,14 +1386,14 @@ void mlx5_lag_remove_devices(struct mlx5_lag *ldev)
static int mlx5_lag_reload_ib_reps_idx(struct mlx5_lag *ldev, int idx,
u32 flags)
{
- struct lag_func *pf = mlx5_lag_pf(ldev, idx);
+ struct lag_fn *fn = mlx5_lag_fn(ldev, idx);
struct mlx5_eswitch *esw;
int ret;
- if (pf->dev->priv.flags & flags)
+ if (fn->dev->priv.flags & flags)
return 0;
- esw = pf->dev->priv.eswitch;
+ esw = fn->dev->priv.eswitch;
mlx5_esw_reps_block(esw);
ret = mlx5_eswitch_reload_ib_reps(esw);
mlx5_esw_reps_unblock(esw);
@@ -1452,14 +1454,14 @@ int mlx5_lag_reload_ib_reps_from_locked(struct mlx5_lag *ldev, u32 flags,
static void mlx5_lag_unload_reps_unlocked(struct mlx5_lag *ldev, u32 filter)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
mlx5_lag_for_each(i, 0, ldev, filter) {
struct mlx5_eswitch *esw;
- pf = mlx5_lag_pf(ldev, i);
- esw = pf->dev->priv.eswitch;
+ fn = mlx5_lag_fn(ldev, i);
+ esw = fn->dev->priv.eswitch;
mlx5_esw_reps_block(esw);
mlx5_eswitch_unload_reps(esw);
mlx5_esw_reps_unblock(esw);
@@ -1493,7 +1495,7 @@ void mlx5_disable_lag(struct mlx5_lag *ldev)
return;
}
- dev0 = mlx5_lag_pf(ldev, idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, idx)->dev;
roce_lag = __mlx5_lag_is_roce(ldev);
if (roce_lag) {
@@ -1501,7 +1503,7 @@ void mlx5_disable_lag(struct mlx5_lag *ldev)
mlx5_ldev_for_each(i, 0, ldev) {
if (i == idx)
continue;
- mlx5_nic_vport_disable_roce(mlx5_lag_pf(ldev, i)->dev);
+ mlx5_nic_vport_disable_roce(mlx5_lag_fn(ldev, i)->dev);
}
}
@@ -1516,18 +1518,18 @@ void mlx5_disable_lag(struct mlx5_lag *ldev)
static bool mlx5_lag_is_roce_lag(struct mlx5_lag *ldev)
{
bool roce_lag = true;
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- roce_lag = roce_lag && !mlx5_sriov_is_enabled(pf->dev);
+ fn = mlx5_lag_fn(ldev, i);
+ roce_lag = roce_lag && !mlx5_sriov_is_enabled(fn->dev);
}
#ifdef CONFIG_MLX5_ESWITCH
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- roce_lag = roce_lag && is_mdev_legacy_mode(pf->dev);
+ fn = mlx5_lag_fn(ldev, i);
+ roce_lag = roce_lag && is_mdev_legacy_mode(fn->dev);
}
#endif
@@ -1556,15 +1558,15 @@ static int mlx5_lag_get_devices_oper_speed(struct mlx5_lag *ldev,
mlx5_ldev_for_each(pf_idx, 0, ldev) {
u8 opmod = MLX5_VPORT_STATE_OP_MOD_VNIC_VPORT;
struct mlx5_core_dev *pf_mdev;
- struct lag_func *pf;
+ struct lag_fn *fn;
u32 speed;
u8 state;
int ret;
- pf = mlx5_lag_pf(ldev, pf_idx);
- if (!pf)
+ fn = mlx5_lag_fn(ldev, pf_idx);
+ if (!fn)
continue;
- pf_mdev = pf->dev;
+ pf_mdev = fn->dev;
if (!pf_mdev)
continue;
ret = mlx5_query_vport_max_tx_speed(pf_mdev, opmod, 0, 0,
@@ -1603,14 +1605,14 @@ static int mlx5_lag_get_devices_max_speed(struct mlx5_lag *ldev, u32 *max_speed)
*max_speed = 0;
mlx5_ldev_for_each(pf_idx, 0, ldev) {
struct mlx5_core_dev *pf_mdev;
- struct lag_func *pf;
+ struct lag_fn *fn;
u32 speed;
int ret;
- pf = mlx5_lag_pf(ldev, pf_idx);
- if (!pf)
+ fn = mlx5_lag_fn(ldev, pf_idx);
+ if (!fn)
continue;
- pf_mdev = pf->dev;
+ pf_mdev = fn->dev;
if (!pf_mdev)
continue;
@@ -1670,7 +1672,7 @@ static void mlx5_lag_modify_device_vports_speed(struct mlx5_core_dev *mdev,
void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev)
{
struct mlx5_core_dev *mdev;
- struct lag_func *pf;
+ struct lag_fn *fn;
u32 speed;
int pf_idx;
@@ -1690,10 +1692,10 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev)
speed = speed / MLX5_MAX_TX_SPEED_UNIT;
mlx5_ldev_for_each(pf_idx, 0, ldev) {
- pf = mlx5_lag_pf(ldev, pf_idx);
- if (!pf)
+ fn = mlx5_lag_fn(ldev, pf_idx);
+ if (!fn)
continue;
- mdev = pf->dev;
+ mdev = fn->dev;
if (!mdev)
continue;
@@ -1704,16 +1706,16 @@ void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev)
void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev)
{
struct mlx5_core_dev *mdev;
- struct lag_func *pf;
+ struct lag_fn *fn;
u32 speed;
int pf_idx;
int ret;
mlx5_ldev_for_each(pf_idx, 0, ldev) {
- pf = mlx5_lag_pf(ldev, pf_idx);
- if (!pf)
+ fn = mlx5_lag_fn(ldev, pf_idx);
+ if (!fn)
continue;
- mdev = pf->dev;
+ mdev = fn->dev;
if (!mdev)
continue;
@@ -1744,7 +1746,7 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)
if (idx < 0)
return;
- dev0 = mlx5_lag_pf(ldev, idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, idx)->dev;
if (!mlx5_lag_is_ready(ldev)) {
do_bond = false;
} else {
@@ -1789,7 +1791,7 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)
mlx5_ldev_for_each(i, 0, ldev) {
if (i == idx)
continue;
- dev = mlx5_lag_pf(ldev, i)->dev;
+ dev = mlx5_lag_fn(ldev, i)->dev;
if (mlx5_get_roce_state(dev))
mlx5_nic_vport_enable_roce(dev);
}
@@ -1823,7 +1825,7 @@ static void mlx5_do_bond(struct mlx5_lag *ldev)
struct mlx5_devcom_comp_dev *mlx5_lag_get_devcom_comp(struct mlx5_lag *ldev)
{
struct mlx5_devcom_comp_dev *devcom = NULL;
- struct lag_func *pf;
+ struct lag_fn *fn;
u32 filter;
int i;
@@ -1831,9 +1833,9 @@ struct mlx5_devcom_comp_dev *mlx5_lag_get_devcom_comp(struct mlx5_lag *ldev)
filter = ldev->virt_lag ? MLX5_LAG_FILTER_ALL :
MLX5_LAG_FILTER_PORTS;
i = mlx5_get_next_lag_func(ldev, 0, filter);
- if (i < ldev->max_funcs) {
- pf = mlx5_lag_pf(ldev, i);
- devcom = pf->dev->priv.hca_devcom_comp;
+ if (i < ldev->max_fns) {
+ fn = mlx5_lag_fn(ldev, i);
+ devcom = fn->dev->priv.hca_devcom_comp;
}
mutex_unlock(&ldev->lock);
return devcom;
@@ -1841,7 +1843,7 @@ struct mlx5_devcom_comp_dev *mlx5_lag_get_devcom_comp(struct mlx5_lag *ldev)
static int mlx5_lag_demux_ft_fg_init(struct mlx5_core_dev *dev,
struct mlx5_flow_table_attr *ft_attr,
- struct lag_func *pf)
+ struct lag_fn *fn)
{
#ifdef CONFIG_MLX5_ESWITCH
struct mlx5_flow_namespace *ns;
@@ -1852,20 +1854,20 @@ static int mlx5_lag_demux_ft_fg_init(struct mlx5_core_dev *dev,
if (!ns)
return 0;
- pf->lag_demux_ft = mlx5_create_flow_table(ns, ft_attr);
- if (IS_ERR(pf->lag_demux_ft))
- return PTR_ERR(pf->lag_demux_ft);
+ fn->lag_demux_ft = mlx5_create_flow_table(ns, ft_attr);
+ if (IS_ERR(fn->lag_demux_ft))
+ return PTR_ERR(fn->lag_demux_ft);
fg = mlx5_esw_lag_demux_fg_create(dev->priv.eswitch,
- pf->lag_demux_ft);
+ fn->lag_demux_ft);
if (IS_ERR(fg)) {
err = PTR_ERR(fg);
- mlx5_destroy_flow_table(pf->lag_demux_ft);
- pf->lag_demux_ft = NULL;
+ mlx5_destroy_flow_table(fn->lag_demux_ft);
+ fn->lag_demux_ft = NULL;
return err;
}
- pf->lag_demux_fg = fg;
+ fn->lag_demux_fg = fg;
return 0;
#else
return -EOPNOTSUPP;
@@ -1874,7 +1876,7 @@ static int mlx5_lag_demux_ft_fg_init(struct mlx5_core_dev *dev,
static int mlx5_lag_demux_fw_init(struct mlx5_core_dev *dev,
struct mlx5_flow_table_attr *ft_attr,
- struct lag_func *pf)
+ struct lag_fn *fn)
{
struct mlx5_flow_namespace *ns;
int err;
@@ -1883,12 +1885,12 @@ static int mlx5_lag_demux_fw_init(struct mlx5_core_dev *dev,
if (!ns)
return 0;
- pf->lag_demux_fg = NULL;
+ fn->lag_demux_fg = NULL;
ft_attr->max_fte = 1;
- pf->lag_demux_ft = mlx5_create_lag_demux_flow_table(ns, ft_attr);
- if (IS_ERR(pf->lag_demux_ft)) {
- err = PTR_ERR(pf->lag_demux_ft);
- pf->lag_demux_ft = NULL;
+ fn->lag_demux_ft = mlx5_create_lag_demux_flow_table(ns, ft_attr);
+ if (IS_ERR(fn->lag_demux_ft)) {
+ err = PTR_ERR(fn->lag_demux_ft);
+ fn->lag_demux_ft = NULL;
return err;
}
@@ -1899,7 +1901,7 @@ int mlx5_lag_demux_init(struct mlx5_core_dev *dev,
struct mlx5_flow_table_attr *ft_attr)
{
struct mlx5_lag *ldev;
- struct lag_func *pf;
+ struct lag_fn *fn;
if (!ft_attr)
return -EINVAL;
@@ -1908,16 +1910,16 @@ int mlx5_lag_demux_init(struct mlx5_core_dev *dev,
if (!ldev)
return -ENODEV;
- pf = mlx5_lag_pf_by_dev(ldev, dev);
- if (!pf)
+ fn = mlx5_lag_fn_by_dev(ldev, dev);
+ if (!fn)
return -ENODEV;
- xa_init(&pf->lag_demux_rules);
+ xa_init(&fn->lag_demux_rules);
if (mlx5_lag_is_sw_managed(dev))
- return mlx5_lag_demux_ft_fg_init(dev, ft_attr, pf);
+ return mlx5_lag_demux_ft_fg_init(dev, ft_attr, fn);
- return mlx5_lag_demux_fw_init(dev, ft_attr, pf);
+ return mlx5_lag_demux_fw_init(dev, ft_attr, fn);
}
EXPORT_SYMBOL(mlx5_lag_demux_init);
@@ -1926,31 +1928,31 @@ void mlx5_lag_demux_cleanup(struct mlx5_core_dev *dev)
struct mlx5_flow_handle *rule;
struct mlx5_lag *ldev;
unsigned long vport_num;
- struct lag_func *pf;
+ struct lag_fn *fn;
ldev = mlx5_lag_dev(dev);
if (!ldev)
return;
- pf = mlx5_lag_pf_by_dev(ldev, dev);
- if (!pf)
+ fn = mlx5_lag_fn_by_dev(ldev, dev);
+ if (!fn)
return;
- xa_for_each(&pf->lag_demux_rules, vport_num, rule)
+ xa_for_each(&fn->lag_demux_rules, vport_num, rule)
mlx5_del_flow_rules(rule);
- xa_destroy(&pf->lag_demux_rules);
+ xa_destroy(&fn->lag_demux_rules);
- if (pf->lag_demux_fg)
- mlx5_destroy_flow_group(pf->lag_demux_fg);
- if (pf->lag_demux_ft)
- mlx5_destroy_flow_table(pf->lag_demux_ft);
- pf->lag_demux_fg = NULL;
- pf->lag_demux_ft = NULL;
+ if (fn->lag_demux_fg)
+ mlx5_destroy_flow_group(fn->lag_demux_fg);
+ if (fn->lag_demux_ft)
+ mlx5_destroy_flow_table(fn->lag_demux_ft);
+ fn->lag_demux_fg = NULL;
+ fn->lag_demux_ft = NULL;
}
EXPORT_SYMBOL(mlx5_lag_demux_cleanup);
-static struct lag_func *mlx5_lag_dev_get_master_pf(struct mlx5_lag *ldev,
- struct mlx5_core_dev *dev)
+static struct lag_fn *mlx5_lag_dev_get_master_fn(struct mlx5_lag *ldev,
+ struct mlx5_core_dev *dev)
{
u32 filter = mlx5_lag_get_filter(ldev, dev);
int idx;
@@ -1959,14 +1961,14 @@ static struct lag_func *mlx5_lag_dev_get_master_pf(struct mlx5_lag *ldev,
if (idx < 0)
return NULL;
- return mlx5_lag_pf(ldev, idx);
+ return mlx5_lag_fn(ldev, idx);
}
int mlx5_lag_demux_rule_add(struct mlx5_core_dev *vport_dev, u16 vport_num,
int index)
{
struct mlx5_flow_handle *rule;
- struct lag_func *master;
+ struct lag_fn *master;
struct mlx5_lag *ldev;
int err;
@@ -1974,7 +1976,7 @@ int mlx5_lag_demux_rule_add(struct mlx5_core_dev *vport_dev, u16 vport_num,
if (!ldev)
return 0;
- master = mlx5_lag_dev_get_master_pf(ldev, vport_dev);
+ master = mlx5_lag_dev_get_master_fn(ldev, vport_dev);
if (!master || !master->lag_demux_fg)
return 0;
@@ -2007,18 +2009,18 @@ EXPORT_SYMBOL(mlx5_lag_demux_rule_add);
void mlx5_lag_demux_rule_del(struct mlx5_core_dev *dev, int index)
{
struct mlx5_flow_handle *rule;
- struct lag_func *master_pf;
+ struct lag_fn *master_fn;
struct mlx5_lag *ldev;
ldev = mlx5_lag_dev(dev);
if (!ldev)
return;
- master_pf = mlx5_lag_dev_get_master_pf(ldev, dev);
- if (!master_pf || !master_pf->lag_demux_fg)
+ master_fn = mlx5_lag_dev_get_master_fn(ldev, dev);
+ if (!master_fn || !master_fn->lag_demux_fg)
return;
- rule = xa_erase(&master_pf->lag_demux_rules, index);
+ rule = xa_erase(&master_fn->lag_demux_rules, index);
if (rule)
mlx5_del_flow_rules(rule);
}
@@ -2068,7 +2070,7 @@ static int mlx5_handle_changeupper_event(struct mlx5_lag *ldev,
struct netdev_lag_upper_info *lag_upper_info = NULL;
bool is_bonded, is_in_lag, mode_supported;
bool has_inactive = 0;
- struct lag_func *pf;
+ struct lag_fn *fn;
struct slave *slave;
u8 bond_status = 0;
int num_slaves = 0;
@@ -2089,8 +2091,8 @@ static int mlx5_handle_changeupper_event(struct mlx5_lag *ldev,
rcu_read_lock();
for_each_netdev_in_bond_rcu(upper, ndev_tmp) {
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->netdev == ndev_tmp) {
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->netdev == ndev_tmp) {
idx++;
break;
}
@@ -2312,16 +2314,16 @@ static void mlx5_ldev_add_netdev(struct mlx5_lag *ldev,
struct mlx5_core_dev *dev,
struct net_device *netdev)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
unsigned long flags;
int i;
spin_lock_irqsave(&lag_lock, flags);
- /* Find pf entry by matching dev pointer */
+ /* Find fn entry by matching dev pointer */
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->dev == dev) {
- pf->netdev = netdev;
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->dev == dev) {
+ fn->netdev = netdev;
ldev->tracker.netdev_state[i].link_up = 0;
ldev->tracker.netdev_state[i].tx_enabled = 0;
break;
@@ -2333,15 +2335,15 @@ static void mlx5_ldev_add_netdev(struct mlx5_lag *ldev,
static void mlx5_ldev_remove_netdev(struct mlx5_lag *ldev,
struct net_device *netdev)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
unsigned long flags;
int i;
spin_lock_irqsave(&lag_lock, flags);
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->netdev == netdev) {
- pf->netdev = NULL;
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->netdev == netdev) {
+ fn->netdev = NULL;
break;
}
}
@@ -2352,37 +2354,37 @@ int mlx5_ldev_add_mdev(struct mlx5_lag *ldev,
struct mlx5_core_dev *dev,
u32 group_id)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
u32 idx;
int err;
- pf = kzalloc_obj(*pf);
- if (!pf)
+ fn = kzalloc_obj(*fn);
+ if (!fn)
return -ENOMEM;
- err = xa_alloc(&ldev->pfs, &idx, pf, XA_LIMIT(0, U8_MAX - 1),
+ err = xa_alloc(&ldev->fns, &idx, fn, XA_LIMIT(0, U8_MAX - 1),
GFP_KERNEL);
if (err) {
- kfree(pf);
+ kfree(fn);
return err;
}
- /* max_funcs is the iteration ceiling; grow it, never shrink. */
- if (idx >= ldev->max_funcs)
- ldev->max_funcs = idx + 1;
- pf->idx = idx;
- pf->dev = dev;
- pf->group_id = group_id;
+ /* max_fns is the iteration ceiling; grow it, never shrink. */
+ if (idx >= ldev->max_fns)
+ ldev->max_fns = idx + 1;
+ fn->idx = idx;
+ fn->dev = dev;
+ fn->group_id = group_id;
dev->priv.lag = ldev;
if (group_id)
return 0;
- xa_set_mark(&ldev->pfs, idx, MLX5_LAG_XA_MARK_PORT);
+ xa_set_mark(&ldev->fns, idx, MLX5_LAG_XA_MARK_PORT);
- MLX5_NB_INIT(&pf->port_change_nb,
+ MLX5_NB_INIT(&fn->port_change_nb,
mlx5_lag_mpesw_port_change_event, PORT_CHANGE);
- mlx5_eq_notifier_register(dev, &pf->port_change_nb);
+ mlx5_eq_notifier_register(dev, &fn->port_change_nb);
return 0;
}
@@ -2390,24 +2392,24 @@ int mlx5_ldev_add_mdev(struct mlx5_lag *ldev,
void mlx5_ldev_remove_mdev(struct mlx5_lag *ldev,
struct mlx5_core_dev *dev)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->dev == dev)
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->dev == dev)
break;
}
- if (i >= ldev->max_funcs)
+ if (i >= ldev->max_fns)
return;
- if (pf->port_change_nb.nb.notifier_call)
- mlx5_eq_notifier_unregister(dev, &pf->port_change_nb);
+ if (fn->port_change_nb.nb.notifier_call)
+ mlx5_eq_notifier_unregister(dev, &fn->port_change_nb);
- pf->dev = NULL;
+ fn->dev = NULL;
dev->priv.lag = NULL;
- xa_erase(&ldev->pfs, pf->idx);
- kfree(pf);
+ xa_erase(&ldev->fns, fn->idx);
+ kfree(fn);
}
/* Must be called with HCA devcom component lock held */
@@ -2583,18 +2585,18 @@ void mlx5_lag_add_netdev(struct mlx5_core_dev *dev,
int mlx5_get_pre_lag_func(struct mlx5_lag *ldev, int start_idx, int end_idx,
u32 filter)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
for (i = start_idx; i >= end_idx; i--) {
- pf = xa_load(&ldev->pfs, i);
- if (!pf || !pf->dev)
+ fn = xa_load(&ldev->fns, i);
+ if (!fn || !fn->dev)
continue;
if (filter == MLX5_LAG_FILTER_PORTS) {
- if (xa_get_mark(&ldev->pfs, i, MLX5_LAG_XA_MARK_PORT))
+ if (xa_get_mark(&ldev->fns, i, MLX5_LAG_XA_MARK_PORT))
return i;
} else if (filter == MLX5_LAG_FILTER_ALL ||
- filter == pf->group_id) {
+ filter == fn->group_id) {
return i;
}
}
@@ -2603,25 +2605,25 @@ int mlx5_get_pre_lag_func(struct mlx5_lag *ldev, int start_idx, int end_idx,
int mlx5_get_next_lag_func(struct mlx5_lag *ldev, int start_idx, u32 filter)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
unsigned long idx;
if (filter == MLX5_LAG_FILTER_PORTS) {
- xa_for_each_marked_start(&ldev->pfs, idx, pf,
+ xa_for_each_marked_start(&ldev->fns, idx, fn,
MLX5_LAG_XA_MARK_PORT, start_idx)
- if (pf->dev)
+ if (fn->dev)
return idx;
- return ldev->max_funcs;
+ return ldev->max_fns;
}
- xa_for_each_start(&ldev->pfs, idx, pf, start_idx) {
- if (!pf->dev)
+ xa_for_each_start(&ldev->fns, idx, fn, start_idx) {
+ if (!fn->dev)
continue;
if (filter == MLX5_LAG_FILTER_ALL ||
- filter == pf->group_id)
+ filter == fn->group_id)
return idx;
}
- return ldev->max_funcs;
+ return ldev->max_fns;
}
bool mlx5_lag_is_roce(struct mlx5_core_dev *dev)
@@ -2675,7 +2677,7 @@ bool mlx5_lag_is_master(struct mlx5_core_dev *dev)
{
struct mlx5_lag *ldev;
unsigned long flags;
- struct lag_func *pf;
+ struct lag_fn *fn;
bool res = false;
int idx;
@@ -2689,8 +2691,8 @@ bool mlx5_lag_is_master(struct mlx5_core_dev *dev)
filter);
if ((__mlx5_lag_is_active(ldev) ||
__mlx5_lag_is_sd_active(ldev, dev)) && idx >= 0) {
- pf = mlx5_lag_pf(ldev, idx);
- res = pf && dev == pf->dev;
+ fn = mlx5_lag_fn(ldev, idx);
+ res = fn && dev == fn->dev;
}
}
spin_unlock_irqrestore(&lag_lock, flags);
@@ -2753,7 +2755,7 @@ void mlx5_lag_disable_change(struct mlx5_core_dev *dev)
struct mlx5_devcom_comp_dev *sd_devcom = mlx5_sd_get_devcom(dev);
struct mlx5_core_dev *primary = dev;
struct mlx5_lag *ldev;
- struct lag_func *pf;
+ struct lag_fn *fn;
bool mpesw;
int i;
@@ -2792,9 +2794,9 @@ void mlx5_lag_disable_change(struct mlx5_core_dev *dev)
mlx5_devcom_comp_lock(sd_devcom);
mutex_lock(&ldev->lock);
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->dev == dev && pf->sd_fdb_active) {
- mlx5_lag_shared_fdb_destroy(ldev, pf->group_id);
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->dev == dev && fn->sd_fdb_active) {
+ mlx5_lag_shared_fdb_destroy(ldev, fn->group_id);
break;
}
}
@@ -2821,7 +2823,7 @@ u8 mlx5_lag_get_slave_port(struct mlx5_core_dev *dev,
{
struct mlx5_lag *ldev;
unsigned long flags;
- struct lag_func *pf;
+ struct lag_fn *fn;
u8 port = 0;
int i;
@@ -2831,8 +2833,8 @@ u8 mlx5_lag_get_slave_port(struct mlx5_core_dev *dev,
goto unlock;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->netdev == slave) {
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->netdev == slave) {
port = i;
break;
}
@@ -2863,7 +2865,7 @@ struct mlx5_core_dev *mlx5_lag_get_next_peer_mdev(struct mlx5_core_dev *dev, int
struct mlx5_core_dev *peer_dev = NULL;
struct mlx5_lag *ldev;
unsigned long flags;
- struct lag_func *pf;
+ struct lag_fn *fn;
int idx;
spin_lock_irqsave(&lag_lock, flags);
@@ -2871,22 +2873,22 @@ struct mlx5_core_dev *mlx5_lag_get_next_peer_mdev(struct mlx5_core_dev *dev, int
if (!ldev)
goto unlock;
- if (*i == ldev->max_funcs)
+ if (*i == ldev->max_fns)
goto unlock;
mlx5_lag_for_each(idx, *i, ldev, mlx5_lag_get_filter(ldev, dev)) {
- pf = mlx5_lag_pf(ldev, idx);
- if (pf->dev != dev)
+ fn = mlx5_lag_fn(ldev, idx);
+ if (fn->dev != dev)
break;
}
- if (idx == ldev->max_funcs) {
+ if (idx == ldev->max_fns) {
*i = idx;
goto unlock;
}
*i = idx + 1;
- pf = mlx5_lag_pf(ldev, idx);
- peer_dev = pf->dev;
+ fn = mlx5_lag_fn(ldev, idx);
+ peer_dev = fn->dev;
unlock:
spin_unlock_irqrestore(&lag_lock, flags);
@@ -2904,7 +2906,7 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
int ret = 0, i, j, idx = 0;
struct mlx5_lag *ldev;
unsigned long flags;
- struct lag_func *pf;
+ struct lag_fn *fn;
int num_ports;
void *out;
@@ -2925,8 +2927,8 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
if (ldev && __mlx5_lag_is_active(ldev)) {
num_ports = ldev->ports;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- mdev[idx++] = pf->dev;
+ fn = mlx5_lag_fn(ldev, i);
+ mdev[idx++] = fn->dev;
}
} else {
num_ports = 1;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
index 1dcd0b87997f..330f5ab83a18 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
@@ -51,7 +51,7 @@ enum mlx5_lag_mode {
MLX5_LAG_MODE_MPESW,
};
-struct lag_func {
+struct lag_fn {
struct mlx5_core_dev *dev;
struct net_device *netdev;
bool has_drop;
@@ -83,13 +83,13 @@ struct mlx5_lag {
unsigned long mode_flags;
unsigned long state_flags;
u8 ports;
- u8 max_funcs;
+ u8 max_fns;
u8 buckets;
bool virt_lag;
int mode_changes_in_progress;
u8 *v2p_map;
struct kref ref;
- struct xarray pfs;
+ struct xarray fns;
struct lag_tracker tracker;
struct workqueue_struct *wq;
struct delayed_work bond_work;
@@ -109,44 +109,44 @@ mlx5_lag_dev(struct mlx5_core_dev *dev)
return dev->priv.lag;
}
-static inline struct lag_func *
-mlx5_lag_pf(struct mlx5_lag *ldev, unsigned int idx)
+static inline struct lag_fn *
+mlx5_lag_fn(struct mlx5_lag *ldev, unsigned int idx)
{
- return xa_load(&ldev->pfs, idx);
+ return xa_load(&ldev->fns, idx);
}
/* Get device index (mlx5_get_dev_index) from xarray index */
static inline int mlx5_lag_xa_to_dev_idx(struct mlx5_lag *ldev, int xa_idx)
{
- struct lag_func *pf = mlx5_lag_pf(ldev, xa_idx);
+ struct lag_fn *fn = mlx5_lag_fn(ldev, xa_idx);
- return pf ? mlx5_get_dev_index(pf->dev) : -ENOENT;
+ return fn ? mlx5_get_dev_index(fn->dev) : -ENOENT;
}
-/* Find lag_func by device index (reverse lookup from mlx5_get_dev_index) */
-static inline struct lag_func *
-mlx5_lag_pf_by_dev_idx(struct mlx5_lag *ldev, int dev_idx)
+/* Find lag_fn by device index (reverse lookup from mlx5_get_dev_index) */
+static inline struct lag_fn *
+mlx5_lag_fn_by_dev_idx(struct mlx5_lag *ldev, int dev_idx)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
unsigned long idx;
- xa_for_each(&ldev->pfs, idx, pf) {
- if (mlx5_get_dev_index(pf->dev) == dev_idx)
- return pf;
+ xa_for_each(&ldev->fns, idx, fn) {
+ if (mlx5_get_dev_index(fn->dev) == dev_idx)
+ return fn;
}
return NULL;
}
-/* Find lag_func by mlx5_core_dev pointer */
-static inline struct lag_func *
-mlx5_lag_pf_by_dev(struct mlx5_lag *ldev, struct mlx5_core_dev *dev)
+/* Find lag_fn by mlx5_core_dev pointer */
+static inline struct lag_fn *
+mlx5_lag_fn_by_dev(struct mlx5_lag *ldev, struct mlx5_core_dev *dev)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
unsigned long idx;
- xa_for_each(&ldev->pfs, idx, pf) {
- if (pf->dev == dev)
- return pf;
+ xa_for_each(&ldev->fns, idx, fn) {
+ if (fn->dev == dev)
+ return fn;
}
return NULL;
}
@@ -154,17 +154,17 @@ mlx5_lag_pf_by_dev(struct mlx5_lag *ldev, struct mlx5_core_dev *dev)
static inline bool
__mlx5_lag_is_sd(struct mlx5_lag *ldev, struct mlx5_core_dev *dev)
{
- struct lag_func *pf = mlx5_lag_pf_by_dev(ldev, dev);
+ struct lag_fn *fn = mlx5_lag_fn_by_dev(ldev, dev);
- return pf && pf->group_id != 0;
+ return fn && fn->group_id != 0;
}
static inline bool
__mlx5_lag_dev_is_port(struct mlx5_lag *ldev, struct mlx5_core_dev *dev)
{
- struct lag_func *pf = mlx5_lag_pf_by_dev(ldev, dev);
+ struct lag_fn *fn = mlx5_lag_fn_by_dev(ldev, dev);
- return pf && xa_get_mark(&ldev->pfs, pf->idx, MLX5_LAG_XA_MARK_PORT);
+ return fn && xa_get_mark(&ldev->fns, fn->idx, MLX5_LAG_XA_MARK_PORT);
}
static inline bool
@@ -290,7 +290,7 @@ static inline bool mlx5_lag_is_supported(struct mlx5_core_dev *dev)
#define mlx5_lag_for_each(i, start_index, ldev, filter) \
for (int tmp = start_index; \
tmp = mlx5_get_next_lag_func(ldev, tmp, filter), \
- i = tmp, tmp < (ldev)->max_funcs; tmp++)
+ i = tmp, tmp < (ldev)->max_fns; tmp++)
#define mlx5_lag_for_each_reverse(i, start_index, end_index, ldev, filter) \
for (int tmp = start_index, tmp1 = end_index; \
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c
index 2077fc5d80c7..587638278f34 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mp.c
@@ -26,15 +26,15 @@ static bool mlx5_lag_multipath_check_prereq(struct mlx5_lag *ldev)
if (__mlx5_lag_is_active(ldev) && !__mlx5_lag_is_multipath(ldev))
return false;
- if (mlx5_lag_is_sw_managed(mlx5_lag_pf(ldev, idx0)->dev) ||
- mlx5_lag_is_sw_managed(mlx5_lag_pf(ldev, idx1)->dev))
+ if (mlx5_lag_is_sw_managed(mlx5_lag_fn(ldev, idx0)->dev) ||
+ mlx5_lag_is_sw_managed(mlx5_lag_fn(ldev, idx1)->dev))
return false;
if (ldev->ports > MLX5_LAG_MULTIPATH_OFFLOADS_SUPPORTED_PORTS)
return false;
- return mlx5_esw_multipath_prereq(mlx5_lag_pf(ldev, idx0)->dev,
- mlx5_lag_pf(ldev, idx1)->dev);
+ return mlx5_esw_multipath_prereq(mlx5_lag_fn(ldev, idx0)->dev,
+ mlx5_lag_fn(ldev, idx1)->dev);
}
bool mlx5_lag_is_multipath(struct mlx5_core_dev *dev)
@@ -59,11 +59,15 @@ static void mlx5_lag_set_port_affinity(struct mlx5_lag *ldev,
{
int idx0 = mlx5_lag_get_dev_index_by_seq(ldev, MLX5_LAG_P1);
int idx1 = mlx5_lag_get_dev_index_by_seq(ldev, MLX5_LAG_P2);
+ struct mlx5_core_dev *dev0, *dev1;
struct lag_tracker tracker = {};
if (idx0 < 0 || idx1 < 0 || !__mlx5_lag_is_multipath(ldev))
return;
+ dev0 = mlx5_lag_fn(ldev, idx0)->dev;
+ dev1 = mlx5_lag_fn(ldev, idx1)->dev;
+
switch (port) {
case MLX5_LAG_NORMAL_AFFINITY:
tracker.netdev_state[idx0].tx_enabled = true;
@@ -84,18 +88,17 @@ static void mlx5_lag_set_port_affinity(struct mlx5_lag *ldev,
tracker.netdev_state[idx1].link_up = true;
break;
default:
- mlx5_core_warn(mlx5_lag_pf(ldev, idx0)->dev,
- "Invalid affinity port %d", port);
+ mlx5_core_warn(dev0, "Invalid affinity port %d", port);
return;
}
if (tracker.netdev_state[idx0].tx_enabled)
- mlx5_notifier_call_chain(mlx5_lag_pf(ldev, idx0)->dev->priv.events,
+ mlx5_notifier_call_chain(dev0->priv.events,
MLX5_DEV_EVENT_PORT_AFFINITY,
(void *)0);
if (tracker.netdev_state[idx1].tx_enabled)
- mlx5_notifier_call_chain(mlx5_lag_pf(ldev, idx1)->dev->priv.events,
+ mlx5_notifier_call_chain(dev1->priv.events,
MLX5_DEV_EVENT_PORT_AFFINITY,
(void *)0);
@@ -150,7 +153,7 @@ mlx5_lag_get_next_fib_dev(struct mlx5_lag *ldev,
fib_dev = fib_info_nh(fi, i)->fib_nh_dev;
ldev_idx = mlx5_lag_dev_get_netdev_idx(ldev, fib_dev);
if (ldev_idx >= 0)
- return mlx5_lag_pf(ldev, ldev_idx)->netdev;
+ return mlx5_lag_fn(ldev, ldev_idx)->netdev;
}
return NULL;
@@ -182,7 +185,7 @@ static void mlx5_lag_fib_route_event(struct mlx5_lag *ldev, unsigned long event,
mp->fib.dst_len <= fen_info->dst_len &&
!(mp->fib.dst_len == fen_info->dst_len &&
fi->fib_priority < mp->fib.priority)) {
- mlx5_core_dbg(mlx5_lag_pf(ldev, idx)->dev,
+ mlx5_core_dbg(mlx5_lag_fn(ldev, idx)->dev,
"Multipath entry with lower priority was rejected\n");
return;
}
@@ -198,7 +201,7 @@ static void mlx5_lag_fib_route_event(struct mlx5_lag *ldev, unsigned long event,
}
if (nh_dev0 == nh_dev1) {
- mlx5_core_warn(mlx5_lag_pf(ldev, idx)->dev,
+ mlx5_core_warn(mlx5_lag_fn(ldev, idx)->dev,
"Multipath offload doesn't support routes with multiple nexthops of the same device");
return;
}
@@ -207,7 +210,7 @@ static void mlx5_lag_fib_route_event(struct mlx5_lag *ldev, unsigned long event,
if (__mlx5_lag_is_active(ldev)) {
mlx5_ldev_for_each(i, 0, ldev) {
dev_idx++;
- if (mlx5_lag_pf(ldev, i)->netdev == nh_dev0)
+ if (mlx5_lag_fn(ldev, i)->netdev == nh_dev0)
break;
}
mlx5_lag_set_port_affinity(ldev, dev_idx);
@@ -244,7 +247,7 @@ static void mlx5_lag_fib_nexthop_event(struct mlx5_lag *ldev,
/* nh added/removed */
if (event == FIB_EVENT_NH_DEL) {
mlx5_ldev_for_each(i, 0, ldev) {
- if (mlx5_lag_pf(ldev, i)->netdev == fib_nh->fib_nh_dev)
+ if (mlx5_lag_fn(ldev, i)->netdev == fib_nh->fib_nh_dev)
break;
dev_idx++;
}
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
index 45e92d71e62c..49602f830615 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
@@ -16,7 +16,7 @@ static void mlx5_mpesw_metadata_cleanup(struct mlx5_lag *ldev)
int i;
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
- dev = mlx5_lag_pf(ldev, i)->dev;
+ dev = mlx5_lag_fn(ldev, i)->dev;
esw = dev->priv.eswitch;
pf_metadata = ldev->lag_mpesw.pf_metadata[i];
if (!pf_metadata)
@@ -37,7 +37,7 @@ static int mlx5_mpesw_metadata_set(struct mlx5_lag *ldev)
int i, err;
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
- dev = mlx5_lag_pf(ldev, i)->dev;
+ dev = mlx5_lag_fn(ldev, i)->dev;
esw = dev->priv.eswitch;
pf_metadata = mlx5_esw_match_metadata_alloc(esw);
if (!pf_metadata) {
@@ -53,7 +53,7 @@ static int mlx5_mpesw_metadata_set(struct mlx5_lag *ldev)
}
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
- dev = mlx5_lag_pf(ldev, i)->dev;
+ dev = mlx5_lag_fn(ldev, i)->dev;
mlx5_notifier_call_chain(dev->priv.events, MLX5_DEV_EVENT_MULTIPORT_ESW,
(void *)0);
}
@@ -67,14 +67,14 @@ static int mlx5_mpesw_metadata_set(struct mlx5_lag *ldev)
static void mlx5_mpesw_restore_sd_fdb(struct mlx5_lag *ldev)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
int err, i;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- err = mlx5_lag_shared_fdb_create(ldev, NULL, 0, pf->group_id);
+ fn = mlx5_lag_fn(ldev, i);
+ err = mlx5_lag_shared_fdb_create(ldev, NULL, 0, fn->group_id);
if (err)
- mlx5_core_warn(pf->dev,
+ mlx5_core_warn(fn->dev,
"Failed to restore SD shared FDB (%d)\n",
err);
}
@@ -82,26 +82,26 @@ static void mlx5_mpesw_restore_sd_fdb(struct mlx5_lag *ldev)
static int mlx5_mpesw_teardown_sd_fdb(struct mlx5_lag *ldev)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (!pf->sd_fdb_active)
+ fn = mlx5_lag_fn(ldev, i);
+ if (!fn->sd_fdb_active)
continue;
- mlx5_lag_shared_fdb_destroy(ldev, pf->group_id);
+ mlx5_lag_shared_fdb_destroy(ldev, fn->group_id);
}
return 0;
}
static bool mlx5_lag_has_sd_group(struct mlx5_lag *ldev)
{
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->group_id)
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->group_id)
return true;
}
return false;
@@ -155,7 +155,7 @@ static int mlx5_lag_enable_mpesw(struct mlx5_lag *ldev)
goto err_clear_master;
}
- dev0 = mlx5_lag_pf(ldev, idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, idx)->dev;
valid = ldev->virt_lag ? mlx5_virt_mpesw_validate(ldev, dev0) :
mlx5_phys_mpesw_validate(ldev, dev0);
if (!valid) {
@@ -212,7 +212,7 @@ void mlx5_mpesw_sd_devcoms_lock(struct mlx5_lag *ldev)
int i;
mlx5_ldev_for_each(i, 0, ldev) {
- sd_devcom = mlx5_sd_get_devcom(mlx5_lag_pf(ldev, i)->dev);
+ sd_devcom = mlx5_sd_get_devcom(mlx5_lag_fn(ldev, i)->dev);
if (sd_devcom)
mlx5_devcom_comp_lock(sd_devcom);
}
@@ -223,8 +223,8 @@ void mlx5_mpesw_sd_devcoms_unlock(struct mlx5_lag *ldev)
struct mlx5_devcom_comp_dev *sd_devcom;
int i;
- mlx5_ldev_for_each_reverse(i, ldev->max_funcs, 0, ldev) {
- sd_devcom = mlx5_sd_get_devcom(mlx5_lag_pf(ldev, i)->dev);
+ mlx5_ldev_for_each_reverse(i, ldev->max_fns, 0, ldev) {
+ sd_devcom = mlx5_sd_get_devcom(mlx5_lag_fn(ldev, i)->dev);
if (sd_devcom)
mlx5_devcom_comp_unlock(sd_devcom);
}
@@ -348,10 +348,10 @@ int mlx5_lag_mpesw_port_change_event(struct notifier_block *nb,
unsigned long event, void *data)
{
struct mlx5_nb *mlx5_nb = container_of(nb, struct mlx5_nb, nb);
- struct lag_func *lag_func = container_of(mlx5_nb,
- struct lag_func,
+ struct lag_fn *lag_fn = container_of(mlx5_nb,
+ struct lag_fn,
port_change_nb);
- struct mlx5_core_dev *dev = lag_func->dev;
+ struct mlx5_core_dev *dev = lag_fn->dev;
struct mlx5_lag *ldev = dev->priv.lag;
struct mlx5_eqe *eqe = data;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
index 2a034b2a3eee..183e18910095 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.c
@@ -50,7 +50,7 @@ static int mlx5_lag_create_port_sel_table(struct mlx5_lag *ldev,
if (first_idx < 0)
return -EINVAL;
- dev = mlx5_lag_pf(ldev, first_idx)->dev;
+ dev = mlx5_lag_fn(ldev, first_idx)->dev;
ft_attr.max_fte = ldev->ports * ldev->buckets;
ft_attr.level = MLX5_LAG_FT_LEVEL_DEFINER;
@@ -79,6 +79,7 @@ static int mlx5_lag_create_port_sel_table(struct mlx5_lag *ldev,
flow_act.flags |= FLOW_ACT_NO_APPEND;
mlx5_ldev_for_each(i, 0, ldev) {
for (j = 0; j < ldev->buckets; j++) {
+ struct mlx5_core_dev *mdev;
u8 affinity;
idx = i * ldev->buckets + j;
@@ -87,9 +88,8 @@ static int mlx5_lag_create_port_sel_table(struct mlx5_lag *ldev,
/* affinity is 1-indexed device index,
* use reverse lookup.
*/
- dest.vport.vhca_id =
- MLX5_CAP_GEN(mlx5_lag_pf_by_dev_idx(ldev, affinity - 1)->dev,
- vhca_id);
+ mdev = mlx5_lag_fn_by_dev_idx(ldev, affinity - 1)->dev;
+ dest.vport.vhca_id = MLX5_CAP_GEN(mdev, vhca_id);
lag_definer->rules[idx] = mlx5_add_flow_rules(lag_definer->ft,
NULL, &flow_act,
&dest, 1);
@@ -311,7 +311,7 @@ mlx5_lag_create_definer(struct mlx5_lag *ldev, enum netdev_lag_hash hash,
if (first_idx < 0)
return ERR_PTR(-EINVAL);
- dev = mlx5_lag_pf(ldev, first_idx)->dev;
+ dev = mlx5_lag_fn(ldev, first_idx)->dev;
lag_definer = kzalloc_obj(*lag_definer);
if (!lag_definer)
return ERR_PTR(-ENOMEM);
@@ -360,7 +360,7 @@ static void mlx5_lag_destroy_definer(struct mlx5_lag *ldev,
if (first_idx < 0)
return;
- dev = mlx5_lag_pf(ldev, first_idx)->dev;
+ dev = mlx5_lag_fn(ldev, first_idx)->dev;
mlx5_ldev_for_each(i, 0, ldev) {
for (j = 0; j < ldev->buckets; j++) {
idx = i * ldev->buckets + j;
@@ -524,7 +524,7 @@ static int mlx5_lag_create_ttc_table(struct mlx5_lag *ldev)
if (first_idx < 0)
return -EINVAL;
- dev = mlx5_lag_pf(ldev, first_idx)->dev;
+ dev = mlx5_lag_fn(ldev, first_idx)->dev;
mlx5_lag_set_outer_ttc_params(ldev, &ttc_params);
port_sel->outer.ttc = mlx5_create_ttc_table(dev, &ttc_params);
return PTR_ERR_OR_ZERO(port_sel->outer.ttc);
@@ -540,7 +540,7 @@ static int mlx5_lag_create_inner_ttc_table(struct mlx5_lag *ldev)
if (first_idx < 0)
return -EINVAL;
- dev = mlx5_lag_pf(ldev, first_idx)->dev;
+ dev = mlx5_lag_fn(ldev, first_idx)->dev;
mlx5_lag_set_inner_ttc_params(ldev, &ttc_params);
port_sel->inner.ttc = mlx5_create_inner_ttc_table(dev, &ttc_params);
return PTR_ERR_OR_ZERO(port_sel->inner.ttc);
@@ -594,6 +594,9 @@ static int __mlx5_lag_modify_definers_destinations(struct mlx5_lag *ldev,
mlx5_ldev_for_each(i, 0, ldev) {
for (j = 0; j < ldev->buckets; j++) {
+ struct mlx5_core_dev *mdev;
+ u8 affinity;
+
idx = i * ldev->buckets + j;
if (ldev->v2p_map[idx] == ports[idx])
continue;
@@ -601,9 +604,9 @@ static int __mlx5_lag_modify_definers_destinations(struct mlx5_lag *ldev,
/* ports[] contains 1-indexed device indices,
* use reverse lookup.
*/
- dest.vport.vhca_id =
- MLX5_CAP_GEN(mlx5_lag_pf_by_dev_idx(ldev, ports[idx] - 1)->dev,
- vhca_id);
+ affinity = ports[idx];
+ mdev = mlx5_lag_fn_by_dev_idx(ldev, affinity - 1)->dev;
+ dest.vport.vhca_id = MLX5_CAP_GEN(mdev, vhca_id);
err = mlx5_modify_rule_destination(def->rules[idx], &dest, NULL);
if (err)
return err;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
index 29048b0c2797..404278a15ef7 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
@@ -19,11 +19,11 @@ bool mlx5_lag_shared_fdb_supported_filter(struct mlx5_lag *ldev, u32 filter)
if (idx < 0)
return false;
- dev0 = mlx5_lag_pf(ldev, idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, idx)->dev;
mlx5_lag_for_each(i, 0, ldev, filter) {
if (i == idx)
continue;
- dev = mlx5_lag_pf(ldev, i)->dev;
+ dev = mlx5_lag_fn(ldev, i)->dev;
if (is_mdev_switchdev_mode(dev) &&
mlx5_eswitch_vport_match_metadata_enabled(dev->priv.eswitch) &&
MLX5_CAP_GEN(dev, lag_native_fdb_selection) &&
@@ -59,7 +59,7 @@ static int mlx5_lag_create_single_fdb_filter(struct mlx5_lag *ldev, u32 filter)
if (master_idx < 0)
return -EINVAL;
- dev0 = mlx5_lag_pf(ldev, master_idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, master_idx)->dev;
master_esw = dev0->priv.eswitch;
mlx5_lag_for_each(i, 0, ldev, filter) {
struct mlx5_eswitch *slave_esw;
@@ -67,11 +67,11 @@ static int mlx5_lag_create_single_fdb_filter(struct mlx5_lag *ldev, u32 filter)
if (i == master_idx)
continue;
- slave_esw = mlx5_lag_pf(ldev, i)->dev->priv.eswitch;
+ slave_esw = mlx5_lag_fn(ldev, i)->dev->priv.eswitch;
err = mlx5_eswitch_offloads_single_fdb_add_one(master_esw,
slave_esw,
- ldev->max_funcs);
+ ldev->max_fns);
if (err)
goto err;
}
@@ -82,7 +82,7 @@ static int mlx5_lag_create_single_fdb_filter(struct mlx5_lag *ldev, u32 filter)
if (j == master_idx)
continue;
- slave_esw = mlx5_lag_pf(ldev, j)->dev->priv.eswitch;
+ slave_esw = mlx5_lag_fn(ldev, j)->dev->priv.eswitch;
mlx5_eswitch_offloads_single_fdb_del_one(master_esw, slave_esw);
}
return err;
@@ -101,7 +101,7 @@ int mlx5_lag_create_vport_lag(struct mlx5_lag *ldev, u32 group_id)
if (master_idx < 0)
return -EINVAL;
- dev0 = mlx5_lag_pf(ldev, master_idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, master_idx)->dev;
master_esw = dev0->priv.eswitch;
mlx5_lag_for_each(i, 0, ldev, filter) {
@@ -110,7 +110,7 @@ int mlx5_lag_create_vport_lag(struct mlx5_lag *ldev, u32 group_id)
if (i == master_idx)
continue;
- slave_esw = mlx5_lag_pf(ldev, i)->dev->priv.eswitch;
+ slave_esw = mlx5_lag_fn(ldev, i)->dev->priv.eswitch;
err = mlx5_eswitch_offloads_vport_lag_add_one(master_esw,
slave_esw);
if (err)
@@ -125,7 +125,7 @@ int mlx5_lag_create_vport_lag(struct mlx5_lag *ldev, u32 group_id)
if (j == master_idx)
continue;
- slave_esw = mlx5_lag_pf(ldev, j)->dev->priv.eswitch;
+ slave_esw = mlx5_lag_fn(ldev, j)->dev->priv.eswitch;
mlx5_eswitch_offloads_vport_lag_del_one(master_esw, slave_esw);
}
return err;
@@ -143,7 +143,7 @@ int mlx5_lag_destroy_vport_lag(struct mlx5_lag *ldev, u32 group_id)
if (master_idx < 0)
return 0;
- dev0 = mlx5_lag_pf(ldev, master_idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, master_idx)->dev;
master_esw = dev0->priv.eswitch;
mlx5_lag_for_each(i, 0, ldev, filter) {
@@ -151,7 +151,7 @@ int mlx5_lag_destroy_vport_lag(struct mlx5_lag *ldev, u32 group_id)
if (i == master_idx)
continue;
- dev = mlx5_lag_pf(ldev, i)->dev;
+ dev = mlx5_lag_fn(ldev, i)->dev;
mlx5_eswitch_offloads_vport_lag_del_one(master_esw,
dev->priv.eswitch);
}
@@ -170,12 +170,12 @@ static void mlx5_lag_destroy_single_fdb_filter(struct mlx5_lag *ldev,
if (master_idx < 0)
return;
- master_esw = mlx5_lag_pf(ldev, master_idx)->dev->priv.eswitch;
+ master_esw = mlx5_lag_fn(ldev, master_idx)->dev->priv.eswitch;
mlx5_lag_for_each(i, 0, ldev, filter) {
if (i == master_idx)
continue;
- peer_esw = mlx5_lag_pf(ldev, i)->dev->priv.eswitch;
+ peer_esw = mlx5_lag_fn(ldev, i)->dev->priv.eswitch;
mlx5_eswitch_offloads_single_fdb_del_one(master_esw, peer_esw);
}
}
@@ -214,14 +214,14 @@ int mlx5_lag_shared_fdb_create(struct mlx5_lag *ldev,
int idx = mlx5_lag_get_dev_index_by_seq_filter(ldev, MLX5_LAG_P1,
filter);
struct mlx5_core_dev *dev0;
- struct lag_func *pf;
+ struct lag_fn *fn;
int err;
int i;
if (idx < 0)
return -EINVAL;
- dev0 = mlx5_lag_pf(ldev, idx)->dev;
+ dev0 = mlx5_lag_fn(ldev, idx)->dev;
mlx5_lag_remove_devices_filter(ldev, filter);
@@ -242,8 +242,8 @@ int mlx5_lag_shared_fdb_create(struct mlx5_lag *ldev,
goto err_add_devices;
}
mlx5_lag_for_each(i, 0, ldev, filter) {
- pf = mlx5_lag_pf(ldev, i);
- pf->sd_fdb_active = true;
+ fn = mlx5_lag_fn(ldev, i);
+ fn->sd_fdb_active = true;
}
BLOCKING_INIT_NOTIFIER_HEAD(&dev0->priv.lag_nh);
}
@@ -265,8 +265,8 @@ int mlx5_lag_shared_fdb_create(struct mlx5_lag *ldev,
mlx5_deactivate_lag(ldev);
} else {
mlx5_lag_for_each(i, 0, ldev, filter) {
- pf = mlx5_lag_pf(ldev, i);
- pf->sd_fdb_active = false;
+ fn = mlx5_lag_fn(ldev, i);
+ fn->sd_fdb_active = false;
}
mlx5_lag_destroy_single_fdb_filter(ldev, group_id);
mlx5_lag_unload_reps_from_locked(ldev, filter);
@@ -280,7 +280,7 @@ int mlx5_lag_shared_fdb_create(struct mlx5_lag *ldev,
void mlx5_lag_shared_fdb_destroy(struct mlx5_lag *ldev, u32 group_id)
{
u32 filter = group_id ? group_id : MLX5_LAG_FILTER_ALL;
- struct lag_func *pf;
+ struct lag_fn *fn;
int err;
int i;
@@ -292,8 +292,8 @@ void mlx5_lag_shared_fdb_destroy(struct mlx5_lag *ldev, u32 group_id)
return;
} else {
mlx5_lag_for_each(i, 0, ldev, filter) {
- pf = mlx5_lag_pf(ldev, i);
- pf->sd_fdb_active = false;
+ fn = mlx5_lag_fn(ldev, i);
+ fn->sd_fdb_active = false;
}
mlx5_lag_destroy_single_fdb_filter(ldev, group_id);
mlx5_lag_unload_reps_from_locked(ldev, filter);
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c b/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c
index 4cdc50cd6f03..f843efbca660 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c
@@ -300,7 +300,7 @@ static int sd_lag_state_show(struct seq_file *file, void *priv)
{
struct mlx5_core_dev *dev = file->private;
struct mlx5_lag *ldev;
- struct lag_func *pf;
+ struct lag_fn *fn;
bool active = false;
int i;
@@ -310,9 +310,9 @@ static int sd_lag_state_show(struct seq_file *file, void *priv)
mutex_lock(&ldev->lock);
mlx5_ldev_for_each(i, 0, ldev) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->dev == dev) {
- active = pf->sd_fdb_active;
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->dev == dev) {
+ active = fn->sd_fdb_active;
break;
}
}
@@ -334,7 +334,7 @@ static void sd_lag_init(struct mlx5_core_dev *dev)
struct mlx5_sd *sd = mlx5_get_sd(primary);
struct mlx5_core_dev *pos, *to;
struct mlx5_lag *ldev;
- struct lag_func *pf;
+ struct lag_fn *fn;
int err;
int i;
@@ -346,14 +346,14 @@ static void sd_lag_init(struct mlx5_core_dev *dev)
}
mutex_lock(&ldev->lock);
- pf = mlx5_lag_pf_by_dev(ldev, primary);
- if (!pf) {
+ fn = mlx5_lag_fn_by_dev(ldev, primary);
+ if (!fn) {
sd_warn(primary, "%s: primary not registered in ldev, skipping\n",
__func__);
goto out;
}
- pf->group_id = sd->group_id;
+ fn->group_id = sd->group_id;
mlx5_sd_for_each_secondary(i, primary, pos) {
err = mlx5_ldev_add_mdev(ldev, pos, sd->group_id);
@@ -372,7 +372,7 @@ static void sd_lag_init(struct mlx5_core_dev *dev)
to = pos;
mlx5_sd_for_each_secondary_to(i, primary, to, pos)
mlx5_ldev_remove_mdev(ldev, pos);
- pf->group_id = 0;
+ fn->group_id = 0;
mutex_unlock(&ldev->lock);
}
@@ -381,7 +381,7 @@ static void sd_lag_cleanup(struct mlx5_core_dev *dev)
struct mlx5_core_dev *primary = mlx5_sd_get_primary(dev);
struct mlx5_core_dev *pos;
struct mlx5_lag *ldev;
- struct lag_func *pf;
+ struct lag_fn *fn;
int i;
ldev = mlx5_lag_dev(primary);
@@ -392,9 +392,9 @@ static void sd_lag_cleanup(struct mlx5_core_dev *dev)
mlx5_sd_for_each_secondary(i, primary, pos)
mlx5_ldev_remove_mdev(ldev, pos);
- pf = mlx5_lag_pf_by_dev(ldev, primary);
- if (pf)
- pf->group_id = 0;
+ fn = mlx5_lag_fn_by_dev(ldev, primary);
+ if (fn)
+ fn->group_id = 0;
mutex_unlock(&ldev->lock);
}
@@ -989,7 +989,7 @@ static void mlx5_sd_activate_shared_fdb(struct mlx5_core_dev *primary)
struct mlx5_sd *sd = mlx5_get_sd(primary);
struct mlx5_core_dev *pos;
struct mlx5_lag *ldev;
- struct lag_func *pf;
+ struct lag_fn *fn;
int err;
int i;
@@ -1009,8 +1009,8 @@ static void mlx5_sd_activate_shared_fdb(struct mlx5_core_dev *primary)
/* Check if SD FDB is already active for this group */
mlx5_lag_for_each(i, 0, ldev, sd->group_id) {
- pf = mlx5_lag_pf(ldev, i);
- if (pf->sd_fdb_active)
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->sd_fdb_active)
goto unlock;
break;
}
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next V2 07/10] net/mlx5: LAG, resolve affinity indices only in queue-affinity mode
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
` (5 preceding siblings ...)
2026-11-16 10:30 ` [PATCH net-next V2 06/10] net/mlx5: LAG, rename PF naming to fn Tariq Toukan
@ 2026-11-16 10:30 ` Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 08/10] net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation Tariq Toukan
` (2 subsequent siblings)
9 siblings, 0 replies; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
From: Shay Drory <shayd@nvidia.com>
mlx5_cmd_create_lag() resolved the first two members up front via
mlx5_lag_get_dev_index_by_seq() and returned -EINVAL if either failed,
but only the queue-affinity mode uses them.
Move the lookup into that case.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/lag/lag.c | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
index 74e7e7161c95..5c9f200c9637 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -95,23 +95,25 @@ static int mlx5_cmd_create_lag(struct mlx5_core_dev *dev, struct mlx5_lag *ldev,
int port_sel_mode = get_port_sel_mode(mode, flags);
u32 in[MLX5_ST_SZ_DW(create_lag_in)] = {};
u8 *ports = ldev->v2p_map;
- int idx0, idx1;
void *lag_ctx;
lag_ctx = MLX5_ADDR_OF(create_lag_in, in, ctx);
MLX5_SET(create_lag_in, in, opcode, MLX5_CMD_OP_CREATE_LAG);
MLX5_SET(lagc, lag_ctx, fdb_selection_mode, fdb_sel_mode);
- idx0 = mlx5_lag_get_dev_index_by_seq(ldev, 0);
- idx1 = mlx5_lag_get_dev_index_by_seq(ldev, 1);
+ switch (port_sel_mode) {
+ case MLX5_LAG_PORT_SELECT_MODE_QUEUE_AFFINITY: {
+ int idx0, idx1;
- if (idx0 < 0 || idx1 < 0)
- return -EINVAL;
+ idx0 = mlx5_lag_get_dev_index_by_seq(ldev, 0);
+ idx1 = mlx5_lag_get_dev_index_by_seq(ldev, 1);
+
+ if (idx0 < 0 || idx1 < 0)
+ return -EINVAL;
- switch (port_sel_mode) {
- case MLX5_LAG_PORT_SELECT_MODE_QUEUE_AFFINITY:
MLX5_SET(lagc, lag_ctx, tx_remap_affinity_1, ports[idx0]);
MLX5_SET(lagc, lag_ctx, tx_remap_affinity_2, ports[idx1]);
break;
+ }
case MLX5_LAG_PORT_SELECT_MODE_PORT_SELECT_FT: {
u8 active_port;
int ret;
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next V2 08/10] net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
` (6 preceding siblings ...)
2026-11-16 10:30 ` [PATCH net-next V2 07/10] net/mlx5: LAG, resolve affinity indices only in queue-affinity mode Tariq Toukan
@ 2026-11-16 10:30 ` Tariq Toukan
2026-11-18 10:31 ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 09/10] net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 10/10] net/mlx5: LAG, do not add a device to an already-active virt LAG Tariq Toukan
9 siblings, 1 reply; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
From: Shay Drory <shayd@nvidia.com>
Converts two fixed-size arrays sized to MLX5_MAX_PORTS into
dynamically allocated pointers:
- lag_mpesw.pf_metadata in mpesw.c/mpesw.h, sized by ldev->max_fns
- mdev array in mlx5_lag_query_cong_counters(), sized by ldev->ports
The cong-counters array is sized by ldev->ports, which is fixed at ldev
allocation, rather than by the LAG mode, so a mode change between the
allocation and filling the array cannot overflow it. The query loop is
bounded by the number of entries actually filled. A virt LAG is not
aggregated and queries only the given device, as its members are not
LAG ports.
Thus, removes the hard dependency on MLX5_MAX_PORTS.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c | 15 +++++++--------
.../net/ethernet/mellanox/mlx5/core/lag/mpesw.c | 12 ++++++++++++
.../net/ethernet/mellanox/mlx5/core/lag/mpesw.h | 2 +-
3 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
index 5c9f200c9637..a7b12353b722 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -2916,7 +2916,9 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
if (!out)
return -ENOMEM;
- mdev = kvzalloc(sizeof(mdev[0]) * MLX5_MAX_PORTS, GFP_KERNEL);
+ ldev = mlx5_lag_dev(dev);
+ num_ports = ldev ? max_t(int, ldev->ports, 1) : 1;
+ mdev = kcalloc(num_ports, sizeof(mdev[0]), GFP_KERNEL);
if (!mdev) {
ret = -ENOMEM;
goto free_out;
@@ -2925,20 +2927,17 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
memset(values, 0, sizeof(*values) * num_counters);
spin_lock_irqsave(&lag_lock, flags);
- ldev = mlx5_lag_dev(dev);
- if (ldev && __mlx5_lag_is_active(ldev)) {
- num_ports = ldev->ports;
+ if (ldev && __mlx5_lag_is_active(ldev) && !ldev->virt_lag) {
mlx5_ldev_for_each(i, 0, ldev) {
fn = mlx5_lag_fn(ldev, i);
mdev[idx++] = fn->dev;
}
} else {
- num_ports = 1;
- mdev[MLX5_LAG_P1] = dev;
+ mdev[idx++] = dev;
}
spin_unlock_irqrestore(&lag_lock, flags);
- for (i = 0; i < num_ports; ++i) {
+ for (i = 0; i < idx; ++i) {
u32 in[MLX5_ST_SZ_DW(query_cong_statistics_in)] = {};
MLX5_SET(query_cong_statistics_in, in, opcode,
@@ -2953,7 +2952,7 @@ int mlx5_lag_query_cong_counters(struct mlx5_core_dev *dev,
}
free_mdev:
- kvfree(mdev);
+ kfree(mdev);
free_out:
kvfree(out);
return ret;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
index 49602f830615..8a867a04916a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
@@ -15,6 +15,9 @@ static void mlx5_mpesw_metadata_cleanup(struct mlx5_lag *ldev)
u32 pf_metadata;
int i;
+ if (!ldev->lag_mpesw.pf_metadata)
+ return;
+
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
dev = mlx5_lag_fn(ldev, i)->dev;
esw = dev->priv.eswitch;
@@ -27,6 +30,9 @@ static void mlx5_mpesw_metadata_cleanup(struct mlx5_lag *ldev)
mlx5_esw_match_metadata_free(esw, pf_metadata);
ldev->lag_mpesw.pf_metadata[i] = 0;
}
+
+ kfree(ldev->lag_mpesw.pf_metadata);
+ ldev->lag_mpesw.pf_metadata = NULL;
}
static int mlx5_mpesw_metadata_set(struct mlx5_lag *ldev)
@@ -36,6 +42,12 @@ static int mlx5_mpesw_metadata_set(struct mlx5_lag *ldev)
u32 pf_metadata;
int i, err;
+ ldev->lag_mpesw.pf_metadata =
+ kcalloc(ldev->max_fns, sizeof(*ldev->lag_mpesw.pf_metadata),
+ GFP_KERNEL);
+ if (!ldev->lag_mpesw.pf_metadata)
+ return -ENOMEM;
+
mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
dev = mlx5_lag_fn(ldev, i)->dev;
esw = dev->priv.eswitch;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.h b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.h
index 5099723ba0f7..6296e3edd38c 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.h
@@ -9,7 +9,7 @@
struct lag_mpesw {
struct work_struct mpesw_work;
- u32 pf_metadata[MLX5_MAX_PORTS];
+ u32 *pf_metadata;
};
enum mpesw_op {
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next V2 09/10] net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
` (7 preceding siblings ...)
2026-11-16 10:30 ` [PATCH net-next V2 08/10] net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation Tariq Toukan
@ 2026-11-16 10:30 ` Tariq Toukan
2026-11-18 10:31 ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 10/10] net/mlx5: LAG, do not add a device to an already-active virt LAG Tariq Toukan
9 siblings, 1 reply; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
From: Shay Drory <shayd@nvidia.com>
mlx5_lag_rescan_devices_locked_filter() collected the participating LAG
members into a fixed-size devs[MLX5_MAX_PORTS] array only to iterate
over it a second time for the rescan calls. Drop the scratch array and
re-walk the members directly with mlx5_lag_for_each().
This removes another dependency on the compile-time MLX5_MAX_PORTS bound
with no functional change.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c | 12 +++++++-----
1 file changed, 7 insertions(+), 5 deletions(-)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
index a7b12353b722..3e88b3f51612 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -1340,9 +1340,7 @@ void mlx5_lag_rescan_dev_locked(struct mlx5_lag *ldev,
static void mlx5_lag_rescan_devices_locked_filter(struct mlx5_lag *ldev,
bool enable, u32 filter)
{
- struct mlx5_core_dev *devs[MLX5_MAX_PORTS];
struct lag_fn *fn;
- int num_devs = 0;
int i;
mlx5_lag_assert_locked_transition(ldev, filter);
@@ -1356,12 +1354,16 @@ static void mlx5_lag_rescan_devices_locked_filter(struct mlx5_lag *ldev,
fn->dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
else
fn->dev->priv.flags |= MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
- devs[num_devs++] = fn->dev;
}
mlx5_lag_drop_lock_for_reps(ldev, filter);
- for (i = 0; i < num_devs; i++)
- mlx5_rescan_drivers_locked(devs[i]);
+ mlx5_lag_for_each(i, 0, ldev, filter) {
+ fn = mlx5_lag_fn(ldev, i);
+ if (fn->dev->priv.flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV)
+ continue;
+
+ mlx5_rescan_drivers_locked(fn->dev);
+ }
mlx5_lag_retake_lock_after_reps(ldev);
}
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH net-next V2 10/10] net/mlx5: LAG, do not add a device to an already-active virt LAG
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
` (8 preceding siblings ...)
2026-11-16 10:30 ` [PATCH net-next V2 09/10] net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan Tariq Toukan
@ 2026-11-16 10:30 ` Tariq Toukan
2026-11-18 10:32 ` netdev-bot+sashiko
9 siblings, 1 reply; 17+ messages in thread
From: Tariq Toukan @ 2026-11-16 10:30 UTC (permalink / raw)
To: Andrew Lunn, David S. Miller, Eric Dumazet, Jakub Kicinski,
netdev, Paolo Abeni
Cc: Carolina Jubran, Cosmin Ratiu, Gal Pressman, Leon Romanovsky,
open list, linux-rdma, Mark Bloch, Moshe Shemesh, Or Har-Toov,
Patrisious Haddad, Saeed Mahameed, Shay Drory, Tariq Toukan,
Uri Dar
From: Shay Drory <shayd@nvidia.com>
mlx5_ldev_add_mdev() would add a newly probed device to the LAG even
when the LAG is already active, mutating membership while getters may be
iterating it and while the active mapping assumes a fixed member set.
A LAG of VFs/SFs is the only one whose members come independently of
its activation. Reject the join of a virt LAG capable function when the
group's virt LAG is active. The device stays out of the LAG until it
is reprobed and the LAG is disabled.
The other join paths cannot reach an active LAG. A LAG of PFs is
activated only once all the PFs of the card are members, so there is no
further PF that could join it, and SD secondaries join at load, before
MPESW can be enabled. Hence the check is limited to virt LAG capable
functions, and it is a no-op for existing configurations.
In addition, do not register the eswitch devcom component of such a
device, so it does not pair with the eswitches of the LAG members.
Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Moshe Shemesh <moshe@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
---
.../net/ethernet/mellanox/mlx5/core/eswitch_offloads.c | 4 ++++
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c | 9 +++++++++
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h | 5 +++++
3 files changed, 18 insertions(+)
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
index 474784131091..1323114ce7f9 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c
@@ -3572,6 +3572,10 @@ void mlx5_esw_offloads_devcom_init(struct mlx5_eswitch *esw,
xa_init(&esw->offloads.peer_flows);
mutex_init(&esw->offloads.peer_mutex);
+ /* do not pair a virt LAG capable VF/SF that is not part of a LAG */
+ if (!mlx5_core_is_pf(esw->dev) && mlx5_virt_lag_nonmember(esw->dev))
+ return;
+
if (!MLX5_CAP_ESW(esw->dev, merged_eswitch))
return;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
index 3e88b3f51612..abcab76fced0 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
@@ -2448,6 +2448,11 @@ static int __mlx5_lag_dev_add_mdev(struct mlx5_core_dev *dev)
mutex_unlock(&ldev->lock);
return -EAGAIN;
}
+
+ if (mlx5_virt_lag_is_supported(dev) && __mlx5_lag_is_active(ldev)) {
+ mutex_unlock(&ldev->lock);
+ return -EOPNOTSUPP;
+ }
mlx5_ldev_get(ldev);
err = mlx5_ldev_add_mdev(ldev, dev, 0);
if (err) {
@@ -2536,6 +2541,10 @@ void mlx5_lag_add_mdev(struct mlx5_core_dev *dev)
err = __mlx5_lag_dev_add_mdev(dev);
mlx5_devcom_comp_unlock(dev->priv.hca_devcom_comp);
+ if (err == -EOPNOTSUPP) {
+ mlx5_lag_unregister_hca_devcom_comp(dev);
+ return;
+ }
if (err) {
msleep(100);
goto recheck;
diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
index 330f5ab83a18..61afccba68ca 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h
@@ -271,6 +271,11 @@ static inline void mlx5_lag_set_vports_agg_speed(struct mlx5_lag *ldev) {}
static inline void mlx5_lag_reset_vports_speed(struct mlx5_lag *ldev) {}
#endif
+static inline bool mlx5_virt_lag_nonmember(struct mlx5_core_dev *dev)
+{
+ return mlx5_virt_lag_is_supported(dev) && !mlx5_lag_dev(dev);
+}
+
static inline bool mlx5_lag_is_supported(struct mlx5_core_dev *dev)
{
if (!MLX5_CAP_GEN(dev, vport_group_manager) ||
--
2.44.0
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next V2 01/10] net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG grouping
2026-11-16 10:30 ` [PATCH net-next V2 01/10] net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG grouping Tariq Toukan
@ 2026-11-18 10:31 ` netdev-bot+sashiko
0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 10:31 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, cjubran,
cratiu, gal, leon, linux-kernel, linux-rdma, mbloch, moshe,
ohartoov, phaddad, saeedm, shayd, udar
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] The patch changes the SW system image GUID of a VF/SF that
passes mlx5_virt_lag_is_supported(): mlx5_sw_guid_vf() or…
--
net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG grouping
This patch changes mlx5_query_nic_sw_system_image_guid() so that each
discriminator byte after the FW system image GUID has a fixed position,
and trailing zero fields are trimmed. It adds VF and SF marker bytes that
are only set when mlx5_virt_lag_is_supported() is true, and it raises
MLX5_SW_IMAGE_GUID_MAX_BYTES from 9 to 11.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/vport.c b/drivers/net/ethernet/mellanox/mlx5/core/vport.c
> index 78f3d15b599d0..bab43df6a7d72 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/vport.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/vport.c
> @@ -1308,10 +1308,37 @@ u64 mlx5_query_nic_system_image_guid(struct mlx5_core_dev *mdev)
> }
> EXPORT_SYMBOL_GPL(mlx5_query_nic_system_image_guid);
>
> +static u8 mlx5_sw_guid_load_balance(const struct mlx5_core_dev *mdev)
> +{
> + if (MLX5_CAP_GEN_2(mdev, load_balance_id) &&
> + MLX5_CAP_GEN_2(mdev, lag_per_mp_group))
> + return MLX5_CAP_GEN_2(mdev, load_balance_id);
> + return 0;
> +}
> +
> +static u8 mlx5_sw_guid_sf(const struct mlx5_core_dev *mdev)
> +{
> + return mlx5_core_is_sf(mdev) && mlx5_virt_lag_is_supported(mdev);
> +}
> +
> +static u8 mlx5_sw_guid_vf(const struct mlx5_core_dev *mdev)
> +{
> + return mlx5_core_is_vf(mdev) && mlx5_virt_lag_is_supported(mdev);
> +}
[Severity: Medium]
Does this break the same-HW check between a PF and a VF/SF that passes
mlx5_virt_lag_is_supported()?
Suppose the VF/SF's own caps report multi_uplink_eswitch=1, lag_master=1
and num_lag_ports < 2. The VF key then becomes guid + [lb|0] + 0x01, which
is 10 bytes. The SF key becomes guid + [lb|0] + 0x00 + 0x01, which is 11
bytes. A PF never sets either marker, so its key is still 8 or 9 bytes.
mlx5_same_hw_devs() requires the lengths to match:
drivers/net/ethernet/mellanox/mlx5/core/dev.c:mlx5_same_hw_devs() {
...
return plen && flen && flen == plen &&
!memcmp(fsystem_guid, psystem_guid, flen);
}
That means it now returns false for any PF paired with such a VF/SF.
mlx5e_tc_is_vf_tunnel() only reaches that comparison when out_mdev is a
PF and route_mdev is a VF/SF:
drivers/net/ethernet/mellanox/mlx5/core/en_tc.c:mlx5e_tc_is_vf_tunnel() {
...
if (route_mdev->coredev_type != MLX5_COREDEV_VF &&
route_mdev->coredev_type != MLX5_COREDEV_SF)
return false;
return mlx5e_same_hw_devs(out_priv, route_priv);
}
For a virt-LAG-capable VF/SF route device, will it now always return
false? These are the paths that would be affected:
mlx5e_set_vf_tunnel()
mlx5e_tc_is_vf_tunnel()
mlx5e_same_hw_devs()
mlx5_same_hw_devs()
- In mlx5e_set_vf_tunnel() the check fails and the code jumps to out with
err = 0. The encap flow is still offloaded, but without the VF vport
source port rewrite (MLX5_ESW_DEST_CHAIN_WITH_SRC_PORT_CHANGE plus the
VPORT_TO_REG metadata). The encapsulated packet then goes straight to
the uplink and skips FDB processing of the VF vport.
- mlx5e_update_vf_tunnel() returns -ENODEV on route updates.
- On decap, mlx5e_tc_tun_route_lookup() no longer sets
rx_tun_attr->decap_vport to the VF vport.
- In mirred_nic.c, the NIC-mode redirect check
if (priv->netdev->netdev_ops != out_dev->netdev_ops ||
!mlx5e_same_hw_devs(priv, netdev_priv(out_dev))) {
now rejects redirects between a PF netdev and such a VF/SF netdev with
"devices are not on same switch HW".
The commit message says:
"so a VF/SF that cannot join a virt LAG keeps its current key and is
still identified as the same HW as its PF."
That covers VFs/SFs that cannot join a virt LAG. It doesn't cover the
ones that can, and none of the consumers above are updated.
Should mlx5_same_hw_devs() compare without the VF/SF markers? Or should
the LAG grouping key be kept separate from the key used for same-HW
detection?
> +
> +static u8 (* const mlx5_sw_guid_fields[])(const struct mlx5_core_dev *mdev) = {
> + mlx5_sw_guid_load_balance,
> + mlx5_sw_guid_vf,
> + mlx5_sw_guid_sf,
> + /* New fields should be added at the end */
> +};
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116103010.1129666-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next V2 05/10] net/mlx5: LAG, decouple iteration end-of-walk from MLX5_MAX_PORTS
2026-11-16 10:30 ` [PATCH net-next V2 05/10] net/mlx5: LAG, decouple iteration end-of-walk from MLX5_MAX_PORTS Tariq Toukan
@ 2026-11-18 10:31 ` netdev-bot+sashiko
0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 10:31 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, cjubran,
cratiu, gal, leon, linux-kernel, linux-rdma, mbloch, moshe,
ohartoov, phaddad, saeedm, shayd, udar
Thank you for your contribution! Sashiko AI review found 5 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 2 · Low: 2
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] mlx5_ldev_add_mdev() raises the xa_alloc() range from
XA_LIMIT(0, MLX5_MAX_PORTS - 1) to XA_LIMIT(0, U8_MAX - 1).
- [Medium] mlx5_handle_changeupper_event() now tests whether the port was
found with `if (i < ldev->ports)`.
- [Medium] The end-of-walk sentinel used to be the compile-time constant
MLX5_MAX_PORTS.
- [Low] In mlx5_lag_create_single_fdb_filter() (shared_fdb.c), the
max_slaves argument to mlx5_eswitch_offloads_single_fdb_add_one()…
- [Low] mlx5_lag_dev_alloc() sets `ldev->max_funcs = ldev->ports` only at
the very end.
--
net/mlx5: LAG, decouple iteration end-of-walk from MLX5_MAX_PORTS
This patch adds ldev->max_funcs and uses it as the end-of-walk sentinel
for the LAG xarray iterators in place of MLX5_MAX_PORTS. max_funcs grows
when a member is added at a higher xarray index. The patch also raises
the xa_alloc() limit in mlx5_ldev_add_mdev() from MLX5_MAX_PORTS - 1 to
U8_MAX - 1.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> index 669b2167a82d2..cbef6ab1e38a8 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> @@ -395,6 +395,7 @@ static struct mlx5_lag *mlx5_lag_dev_alloc(struct mlx5_core_dev *dev)
> mlx5_core_err(dev, "Failed to init multipath lag err=%d\n",
> err);
>
> + ldev->max_funcs = ldev->ports;
> return ldev;
[Severity: Low]
Can a netdev event see max_funcs == 0 here?
By the time this assignment runs, register_netdevice_notifier_net() has
already made ldev->nb live. mlx5_lag_mp_init() has also registered the
FIB notifier, which dumps the FIB and can take a while. Until this line,
max_funcs is still 0 from kzalloc.
Suppose a NETDEV_CHANGEUPPER for a bond in the same netns arrives in that
window. mlx5_handle_changeupper_event() then runs mlx5_ldev_for_each()
with max_funcs == 0:
- mlx5_get_next_lag_func() returns 0.
- The loop exits with i = 0 and idx still -1.
- The new "i < ldev->ports" check passes.
The handler then executes:
bond_status |= (1 << idx);
This is a shift by -1. Would it be better to set max_funcs right after
ldev->ports is assigned, before any notifier is registered?
[ ... ]
> @@ -2094,7 +2095,7 @@ static int mlx5_handle_changeupper_event(struct mlx5_lag *ldev,
> break;
> }
> }
> - if (i < MLX5_MAX_PORTS) {
> + if (i < ldev->ports) {
[Severity: Medium]
Should this compare against ldev->max_funcs, like the other converted call
sites? mlx5_ldev_for_each() now ends with i == ldev->max_funcs. This patch
also explicitly allows members at xarray indices >= ldev->ports, since
mlx5_ldev_add_mdev() grows max_funcs for that case.
xa_alloc() hands out the lowest free index to both port and SD members.
For example, after a PF is unbound and rebound, SD secondaries added by
sd_lag_init() can hold the low indices, so the matched port PF can end up
at an index >= ports.
In that case the loop breaks with i equal to that index, "i < ldev->ports"
is false, and the PF is treated as not found. Its bond_status bit is never
set and has_inactive is not computed for it, so this never becomes true:
is_in_lag = num_slaves == ldev->ports &&
bond_status == GENMASK(ldev->ports - 1, 0);
As a result, the bond is never offloaded. Before this patch, indices were
capped at 7, so any found entry passed the check.
The notifier is only registered when !mlx5_sd_is_supported(dev), so this
may need a mixed or unusual topology to trigger. The check is still the
same at the end of the series.
[ ... ]
> @@ -2359,13 +2360,16 @@ int mlx5_ldev_add_mdev(struct mlx5_lag *ldev,
> if (!pf)
> return -ENOMEM;
>
> - err = xa_alloc(&ldev->pfs, &idx, pf, XA_LIMIT(0, MLX5_MAX_PORTS - 1),
> + err = xa_alloc(&ldev->pfs, &idx, pf, XA_LIMIT(0, U8_MAX - 1),
> GFP_KERNEL);
[Severity: High]
Is it safe to drop the MLX5_MAX_PORTS limit before the arrays that depend
on it are resized?
This limit was the only thing that kept both the member count and every
xarray index below MLX5_MAX_PORTS (8). Neither __mlx5_lag_dev_add_mdev()
nor sd_lag_init() checks the member count.
At this commit, once an ldev has more than 8 members, these writes look
like they go out of bounds:
- mlx5_mpesw_metadata_set() writes ldev->lag_mpesw.pf_metadata[i]
(u32[MLX5_MAX_PORTS]) under MLX5_LAG_FILTER_ALL. lag_mpesw is the last
member of struct mlx5_lag, so this writes past the kzalloc'd ldev.
- mlx5_lag_rescan_devices_locked_filter() fills the on-stack
devs[MLX5_MAX_PORTS] with devs[num_devs++] without any bound check.
- mlx5_lag_query_cong_counters() fills a buffer of MLX5_MAX_PORTS entries
with mdev[idx++].
- struct lag_tracker::netdev_state[MLX5_MAX_PORTS] is written at the
port's xarray index in mlx5_ldev_add_netdev() and in
mlx5_handle_changelowerstate_event():
tracker->netdev_state[idx] = *lag_lower_info;
- struct mlx5_lag_definer::rules[MLX5_MAX_PORTS *
MLX5_LAG_MAX_HASH_BUCKETS] is indexed by i * ldev->buckets + j in
port_sel.c, where i is the port's xarray index.
Before this patch, such a configuration failed cleanly: xa_alloc()
returned -EBUSY and sd_lag_init() rolled back the secondaries. An 8-port
SD configuration, for example, would now give 16 members.
Later patches in the series fix some of these:
- "net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic
allocation" makes pf_metadata kcalloc(max_fns) and sizes the
cong-counter buffer from ports.
- "net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan"
removes devs[].
At the end of the series, though, lag_tracker::netdev_state[] and
mlx5_lag_definer::rules[] are still sized by MLX5_MAX_PORTS and indexed
by xarray indices that are no longer bounded.
The commit message also says:
No functional change; this only removes the dependency on
MLX5_MAX_PORTS.
Isn't dropping the xa_alloc() bound a functional change in itself?
> if (err) {
> kfree(pf);
> return err;
> }
>
> + /* max_funcs is the iteration ceiling; grow it, never shrink. */
> + if (idx >= ldev->max_funcs)
> + ldev->max_funcs = idx + 1;
> pf->idx = idx;
> pf->dev = dev;
[Severity: Medium]
Can walkers that don't hold ldev->lock see an inconsistent max_funcs?
The end-of-walk sentinel used to be a constant. It is now this field,
which is written with a plain store under ldev->lock only. Each iteration
of mlx5_lag_for_each() loads it twice: once as the return value of
mlx5_get_next_lag_func(), and again in the macro test:
i = tmp, tmp < (ldev)->max_funcs; tmp++)
Several walkers don't hold ldev->lock:
- mlx5_mpesw_sd_devcoms_lock(), called from mlx5_mpesw_work() and
mlx5_lag_disable_change(), runs under the HCA devcom lock but before
mutex_lock(&ldev->lock).
- mlx5_ldev_add_netdev(), mlx5_lag_get_next_peer_mdev() and
mlx5_lag_query_cong_counters() hold only lag_lock.
- mlx5_handle_changeupper_event() holds only RCU.
sd_lag_init() adds secondaries while holding only ldev->lock. The writer
order is:
1. xa_alloc() publishes a zeroed pf at idx == old max_funcs.
2. max_funcs = idx + 1.
3. pf->dev = dev.
4. The PORT mark is set.
Suppose a reader's walk ends while the new pf isn't valid yet. It gets
sentinel N back from mlx5_get_next_lag_func(), then re-reads max_funcs as
N + 1. The loop body then runs once with i = N, skipping the !pf->dev
check and the PORT-mark filter. In mlx5_mpesw_sd_devcoms_lock() that
means:
sd_devcom = mlx5_sd_get_devcom(mlx5_lag_pf(ldev, i)->dev);
runs with a NULL dev, which mlx5_get_sd() dereferences. In
mlx5_lag_get_next_peer_mdev(), a NULL or non-port dev could be returned
as a peer.
Also, on weakly ordered architectures nothing orders this store against
the xarray slot, so xa_load(N) could return NULL as well.
[ ... ]
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
> index 7c7e6c832a93d..29048b0c27977 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/shared_fdb.c
> @@ -71,7 +71,7 @@ static int mlx5_lag_create_single_fdb_filter(struct mlx5_lag *ldev, u32 filter)
>
> err = mlx5_eswitch_offloads_single_fdb_add_one(master_esw,
> slave_esw,
> - ldev->ports);
> + ldev->max_funcs);
[Severity: Low]
Is this change intended? This argument isn't an end-of-walk sentinel. It
is max_slaves, which goes through esw_set_master_egress_rule() to
esw_master_egress_create_resources(). There it becomes ft_attr.max_fte
and the bounce group's end_flow_index for the master's egress ACL table
in firmware.
With SD, secondaries take extra xarray indices, so max_funcs can exceed
ports (for example, 4 on a 2-port SD card) and the ACL table is created
larger. max_funcs is also a high-water mark of xarray indices that never
shrinks, not a slave count.
Bounce rules are only added for SD primaries, so ldev->ports seems to
have been sufficient already.
This doesn't match "No functional change" in the commit message. Could
the change be explained in the commit message, or dropped?
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116103010.1129666-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next V2 06/10] net/mlx5: LAG, rename PF naming to fn
2026-11-16 10:30 ` [PATCH net-next V2 06/10] net/mlx5: LAG, rename PF naming to fn Tariq Toukan
@ 2026-11-18 10:31 ` netdev-bot+sashiko
0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 10:31 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, cjubran,
cratiu, gal, leon, linux-kernel, linux-rdma, mbloch, moshe,
ohartoov, phaddad, saeedm, shayd, udar
Thank you for your contribution! Sashiko AI review found more severe
issue(s) in other patches of this series. This mail is only an FYI, in case
you want to address the nit picks below when you respin.
Low priority / nit picks for your consideration:
- [Low] The commit message misstates what this patch renames.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but it is still
present at the end of the series.
--
net/mlx5: LAG, rename PF naming to fn
This commit renames the LAG member bookkeeping from PF naming to fn. The
ldev->pfs xarray becomes ldev->fns, the mlx5_lag_pf*() helpers become
mlx5_lag_fn*(), and the pf locals become fn. The rename prepares for virt
LAG, where LAG members will not always be physical functions.
> Rename the xarray to ldev->fns, the helpers to mlx5_lag_fn*(), and the
> locals to fn, so the naming matches struct lag_fn.
[Severity: Low]
Is this description accurate? struct lag_fn doesn't exist before this
patch. The patch creates it by renaming the struct in lag.h:
-struct lag_func {
+struct lag_fn {
It also renames a field of struct mlx5_lag:
- u8 max_funcs;
+ u8 max_fns;
The commit message mentions neither rename.
The patch also makes a few small changes that are not renames:
- a new esw local in mlx5_lag_drop_rule_cleanup()
- dev0/dev1 moved above the switch in mlx5_lag_set_port_affinity()
- new mdev/affinity locals in mlx5_lag_create_port_sel_table() and
__mlx5_lag_modify_definers_destinations()
Could the commit message mention these as well?
A few spots look like they were missed by the rename. The pf_idx and
pf_mdev locals remain in mlx5_lag_get_devices_oper_speed(),
mlx5_lag_get_devices_max_speed(), mlx5_lag_set_vports_agg_speed() and
mlx5_lag_reset_vports_speed():
mlx5_ldev_for_each(pf_idx, 0, ldev) {
...
pf_mdev = fn->dev;
mlx5_get_next_lag_func() and mlx5_get_pre_lag_func() walk the renamed fns
xarray but keep their old names.
In mlx5_lag_mpesw_port_change_event(), the local now has the same name as
the struct tag. The container_of() continuation lines are still aligned for
the old, longer name:
struct lag_fn *lag_fn = container_of(mlx5_nb,
struct lag_fn,
port_change_nb);
Was that intended?
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> index cbef6ab1e38a8..74e7e7161c95d 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
[ ... ]
> @@ -2390,24 +2392,24 @@ int mlx5_ldev_add_mdev(struct mlx5_lag *ldev,
> void mlx5_ldev_remove_mdev(struct mlx5_lag *ldev,
> struct mlx5_core_dev *dev)
> {
[ ... ]
> - pf->dev = NULL;
> + fn->dev = NULL;
> dev->priv.lag = NULL;
> - xa_erase(&ldev->pfs, pf->idx);
> - kfree(pf);
> + xa_erase(&ldev->fns, fn->idx);
> + kfree(fn);
> }
[Severity: High]
This is a pre-existing issue and was not introduced by this patch. Since
this code is being touched: is it safe to free the lag_fn here while
readers holding only lag_lock may still be using it?
mlx5_ldev_remove_mdev() runs with only ldev->lock held. It is called from:
- mlx5_unload()->mlx5_lag_remove_mdev()
- sd_lag_cleanup()
- the error path of sd_lag_init()
It erases the entry and frees it right away with kfree(). There is no RCU
grace period, and lag_lock is not taken.
Several exported helpers walk the same ldev->fns xarray while holding only
lag_lock, without ldev->lock. For example:
mlx5_lag_get_next_peer_mdev() {
spin_lock_irqsave(&lag_lock, flags);
...
mlx5_lag_for_each(idx, *i, ldev, mlx5_lag_get_filter(ldev, dev)) {
fn = mlx5_lag_fn(ldev, idx);
if (fn->dev != dev)
break;
}
...
fn = mlx5_lag_fn(ldev, idx);
peer_dev = fn->dev;
...
}
mlx5_lag_is_master(), mlx5_lag_is_shared_fdb() and mlx5_lag_is_sd() read
fn->dev, fn->group_id and fn->sd_fdb_active through mlx5_lag_get_filter()
and mlx5_lag_fn_by_dev(). mlx5_lag_get_slave_port() and
mlx5_lag_active_backup_get_netdev() also dereference entries while holding
only lag_lock.
Can this interleaving happen between two devices in the same ldev?
CPU0 (peer device A) CPU1 (device B unload)
mlx5_esw_is_owner()
mlx5_lag_is_master()
spin_lock_irqsave(&lag_lock)
mlx5_lag_get_filter()
mlx5_lag_fn_by_dev()
xa_for_each() loads fn
mlx5_lag_remove_mdev()
mutex_lock(&ldev->lock)
mlx5_ldev_remove_mdev()
xa_erase(&ldev->fns, fn->idx)
kfree(fn)
fn->dev == dev <- reads freed memory
If mlx5_lag_get_next_peer_mdev() hits the same window, it returns the stale
fn->dev to its caller as a peer mlx5_core_dev pointer.
The baseline already has the same xa_erase() and kfree() in
mlx5_ldev_remove_mdev(), and nothing later in the series changes this.
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116103010.1129666-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next V2 08/10] net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation
2026-11-16 10:30 ` [PATCH net-next V2 08/10] net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation Tariq Toukan
@ 2026-11-18 10:31 ` netdev-bot+sashiko
0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 10:31 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, cjubran,
cratiu, gal, leon, linux-kernel, linux-rdma, mbloch, moshe,
ohartoov, phaddad, saeedm, shayd, udar
Thank you for your contribution! Sashiko AI review found 2 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 1
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] Possible heap out-of-bounds read/write in
mlx5_mpesw_metadata_cleanup()…
- [Low] The commit message ends with "Thus, removes the hard dependency
on MLX5_MAX_PORTS", which overstates what the patch does.
--
net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation
This converts lag_mpesw.pf_metadata and the mdev array in
mlx5_lag_query_cong_counters() from fixed MLX5_MAX_PORTS sized arrays to
dynamically allocated buffers. pf_metadata is sized by ldev->max_fns when
MPESW is enabled. The cong counters array is sized by ldev->ports.
> Thus, removes the hard dependency on MLX5_MAX_PORTS.
[Severity: Low]
Is this statement accurate? This patch converts only two arrays.
This patch leaves the devs[MLX5_MAX_PORTS] scratch array in
mlx5_lag_rescan_devices_locked_filter() in place. The later series patch
"drop MLX5_MAX_PORTS scratch array from device rescan" removes it.
Some arrays tied to the LAG member index space are still there at the end
of the series. That index space is no longer capped at MLX5_MAX_PORTS,
because "decouple iteration end-of-walk from MLX5_MAX_PORTS" moved
xa_alloc() to XA_LIMIT(0, U8_MAX - 1):
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.h:struct lag_tracker {
...
struct netdev_lag_lower_state_info netdev_state[MLX5_MAX_PORTS];
...
}
drivers/net/ethernet/mellanox/mlx5/core/lag/port_sel.h:struct mlx5_lag_port_sel {
...
struct mlx5_flow_handle *rules[MLX5_MAX_PORTS * MLX5_LAG_MAX_HASH_BUCKETS];
...
}
Could the commit message say that these remain? Or should they be
converted or bounded as well?
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
> index 49602f8306155..8a867a04916a8 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/mpesw.c
> @@ -15,6 +15,9 @@ static void mlx5_mpesw_metadata_cleanup(struct mlx5_lag *ldev)
> u32 pf_metadata;
> int i;
>
> + if (!ldev->lag_mpesw.pf_metadata)
> + return;
> +
> mlx5_lag_for_each(i, 0, ldev, MLX5_LAG_FILTER_ALL) {
> dev = mlx5_lag_fn(ldev, i)->dev;
> esw = dev->priv.eswitch;
> @@ -27,6 +30,9 @@ static void mlx5_mpesw_metadata_cleanup(struct mlx5_lag *ldev)
> mlx5_esw_match_metadata_free(esw, pf_metadata);
> ldev->lag_mpesw.pf_metadata[i] = 0;
> }
> +
> + kfree(ldev->lag_mpesw.pf_metadata);
> + ldev->lag_mpesw.pf_metadata = NULL;
> }
>
> static int mlx5_mpesw_metadata_set(struct mlx5_lag *ldev)
> @@ -36,6 +42,12 @@ static int mlx5_mpesw_metadata_set(struct mlx5_lag *ldev)
> u32 pf_metadata;
> int i, err;
>
> + ldev->lag_mpesw.pf_metadata =
> + kcalloc(ldev->max_fns, sizeof(*ldev->lag_mpesw.pf_metadata),
> + GFP_KERNEL);
> + if (!ldev->lag_mpesw.pf_metadata)
> + return -ENOMEM;
> +
[Severity: High]
Can ldev->max_fns grow after this allocation while MPESW is still active?
The allocated length is not stored anywhere. Yet
mlx5_mpesw_metadata_cleanup() walks the members with mlx5_lag_for_each(),
which checks against the current max_fns:
#define mlx5_lag_for_each(i, start_index, ldev, filter) \
for (int tmp = start_index; \
tmp = mlx5_get_next_lag_func(ldev, tmp, filter), \
i = tmp, tmp < (ldev)->max_fns; tmp++)
mlx5_ldev_add_mdev() grows max_fns without looking at the LAG mode:
drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c:mlx5_ldev_add_mdev() {
...
/* max_fns is the iteration ceiling; grow it, never shrink. */
if (idx >= ldev->max_fns)
ldev->max_fns = idx + 1;
...
}
sd_lag_init() calls it for each SD secondary, also without checking
ldev->mode:
drivers/net/ethernet/mellanox/mlx5/core/lib/sd.c:sd_lag_init() {
...
mlx5_sd_for_each_secondary(i, primary, pos) {
err = mlx5_ldev_add_mdev(ldev, pos, sd->group_id);
...
}
Here is one possible sequence on an SD card:
devlink esw_multiport=true
mlx5_lag_enable_mpesw()
mlx5_mpesw_metadata_set()
kcalloc(max_fns = 2)
secondary PF probes later
mlx5e_probe() -> mlx5_sd_init() -> sd_lag_init()
mlx5_ldev_add_mdev() /* idx 2, max_fns = 3 */
devlink esw_multiport=false, or unload
mlx5_lag_disable_mpesw()
mlx5_mpesw_metadata_cleanup()
reads and writes pf_metadata[2]
SD secondaries have fn->dev set, so the MLX5_LAG_FILTER_ALL walk visits
them. Three things then go wrong for any index past the allocated count:
- cleanup reads pf_metadata[i] past the end of the slab object.
- if that stale value is non-zero, it calls
mlx5_esw_acl_ingress_vport_metadata_update() on that eswitch, and
mlx5_esw_match_metadata_free() with an ida id that was never allocated.
- it writes 0 to pf_metadata[i] past the end of the buffer.
With the old embedded u32 pf_metadata[MLX5_MAX_PORTS], a member added
later at an index below MLX5_MAX_PORTS read a zero slot and was skipped.
The last patch in the series ("do not add a device to an already-active
virt LAG") says SD secondaries join before MPESW can be enabled. Is that
enforced anywhere?
- mlx5_devlink_esw_multiport_set()->mlx5_lag_mpesw_enable() does not
check SD readiness.
- mlx5_phys_mpesw_validate()->mlx5_lag_check_prereq() only checks
mlx5_lag_num_devs(ldev) == ldev->ports. That counts port members, not
SD secondaries.
Would it be safer to record the allocated length and bound the cleanup
loop by it? Another option is to refuse max_fns growth and SD joins
while MPESW is active.
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116103010.1129666-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next V2 09/10] net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan
2026-11-16 10:30 ` [PATCH net-next V2 09/10] net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan Tariq Toukan
@ 2026-11-18 10:31 ` netdev-bot+sashiko
0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 10:31 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, cjubran,
cratiu, gal, leon, linux-kernel, linux-rdma, mbloch, moshe,
ohartoov, phaddad, saeedm, shayd, udar
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 1 · Medium: 0 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [High] In mlx5_lag_rescan_devices_locked_filter()
(drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c), this patch…
--
net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan
This commit removes the devs[MLX5_MAX_PORTS] array from
mlx5_lag_rescan_devices_locked_filter(). The post-unlock rescan loop now
walks the LAG members again with mlx5_lag_for_each(). The commit message
describes this as having no functional change.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> index a7b12353b7225..3e88b3f51612e 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
[ ... ]
> @@ -1356,12 +1354,16 @@ static void mlx5_lag_rescan_devices_locked_filter(struct mlx5_lag *ldev,
> fn->dev->priv.flags &= ~MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
> else
> fn->dev->priv.flags |= MLX5_PRIV_FLAGS_DISABLE_IB_ADEV;
> - devs[num_devs++] = fn->dev;
> }
>
> mlx5_lag_drop_lock_for_reps(ldev, filter);
> - for (i = 0; i < num_devs; i++)
> - mlx5_rescan_drivers_locked(devs[i]);
> + mlx5_lag_for_each(i, 0, ldev, filter) {
> + fn = mlx5_lag_fn(ldev, i);
> + if (fn->dev->priv.flags & MLX5_PRIV_FLAGS_DISABLE_ALL_ADEV)
> + continue;
> +
> + mlx5_rescan_drivers_locked(fn->dev);
> + }
[Severity: High]
This loop now walks ldev->fns after mlx5_lag_drop_lock_for_reps() has
released ldev->lock. Can a concurrent SD member removal free a lag_fn
while the walk is in progress?
On each step, mlx5_get_next_lag_func() reads xarray entries and fn->dev.
mlx5_lag_fn() then does an xa_load(), and the loop dereferences
fn->dev->priv.flags. The only thing guarding membership while the lock is
dropped is ldev->mode_changes_in_progress. The comment in
mlx5_lag_drop_lock_for_reps() says:
/* Keep PF membership stable while ldev->lock is dropped. Device add
* and remove paths observe mode_changes_in_progress and retry.
*/
The SD paths in lib/sd.c don't appear to check that counter, though.
sd_lag_cleanup() takes the lock directly:
mutex_lock(&ldev->lock);
mlx5_sd_for_each_secondary(i, primary, pos)
mlx5_ldev_remove_mdev(ldev, pos);
mlx5_ldev_remove_mdev() then frees the entry right away, with no RCU
deferral:
fn->dev = NULL;
dev->priv.lag = NULL;
xa_erase(&ldev->fns, fn->idx);
kfree(fn);
sd_lag_cleanup() is serialized only by sd->devcom. For
MLX5_LAG_FILTER_ALL, this function runs under the HCA devcom instead.
mlx5_do_bond_work() takes only the HCA devcom trylock plus ldev->lock, and
not mlx5_mpesw_sd_devcoms_lock(). It reaches this function as follows:
mlx5_do_bond_work()
mlx5_do_bond()
mlx5_lag_shared_fdb_create(ldev, ..., MLX5_LAG_MODE_SRIOV, 0)
mlx5_lag_remove_devices_filter(ldev, MLX5_LAG_FILTER_ALL)
mlx5_lag_rescan_devices_locked_filter()
mlx5_disable_lag() -> mlx5_lag_shared_fdb_destroy(ldev, 0) reaches it the
same way. Group id 0 maps to MLX5_LAG_FILTER_ALL, which matches every
member, SD secondaries included.
At the same time, removing an SD member's eth aux driver can run:
mlx5e_remove() / mlx5e_suspend()
mlx5_sd_cleanup()
sd_lag_cleanup()
mlx5_ldev_remove_mdev()
This removal can come from a sysfs unbind of mlx5_core.eth.N. It can also
come from a reload of an SD secondary whose hca_devcom_comp is NULL or in a
different component. Neither case holds the HCA devcom that the bond work
holds.
If that happens, mlx5_get_next_lag_func() could read fn->dev from a freed
lag_fn. mlx5_lag_fn() could also return NULL after xa_erase(), and the
loop would then dereference it.
The old loop touched only the devs[] core_dev pointers once the lock was
dropped. Those pointers stay valid across an aux unbind, so lag_fn and
xarray state was never accessed without the lock.
A similar question applies to sd_lag_init(), which also takes ldev->lock
without checking mode_changes_in_progress and calls mlx5_ldev_add_mdev().
Could the second loop then rescan a newly added member whose
MLX5_PRIV_FLAGS_DISABLE_IB_ADEV flag the first loop never updated?
Given the above, is the "no functional change" statement in the commit
message accurate?
Would it be safer to keep a snapshot taken under the lock? For example, a
dynamically sized array, or a reference on each core_dev collected before
mlx5_lag_drop_lock_for_reps().
As far as I can tell, the last patch in the series doesn't touch this
function or the SD paths, so this would still be present at the end of the
series.
> mlx5_lag_retake_lock_after_reps(ldev);
> }
>
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116103010.1129666-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH net-next V2 10/10] net/mlx5: LAG, do not add a device to an already-active virt LAG
2026-11-16 10:30 ` [PATCH net-next V2 10/10] net/mlx5: LAG, do not add a device to an already-active virt LAG Tariq Toukan
@ 2026-11-18 10:32 ` netdev-bot+sashiko
0 siblings, 0 replies; 17+ messages in thread
From: netdev-bot+sashiko @ 2026-11-18 10:32 UTC (permalink / raw)
To: tariqt
Cc: andrew+netdev, davem, edumazet, kuba, netdev, pabeni, cjubran,
cratiu, gal, leon, linux-kernel, linux-rdma, mbloch, moshe,
ohartoov, phaddad, saeedm, shayd, udar
Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.
Critical: 0 · High: 0 (1) · Medium: 1 · Low: 0
If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).
- [Medium] In this tree, both parts of the patch hit a predicate
mismatch.
Pre-existing issues:
- [High] This problem wasn't introduced by this patch, but the patch now
cleans up the HCA devcom component on its own new -EOPNOTSUPP path…
--
net/mlx5: LAG, do not add a device to an already-active virt LAG
This patch stops a virt LAG capable function from joining a LAG whose mode
is already active. In that case __mlx5_lag_dev_add_mdev() returns
-EOPNOTSUPP, and mlx5_lag_add_mdev() then unregisters the HCA devcom
component. The patch also makes mlx5_esw_offloads_devcom_init() skip eswitch
devcom registration for a non-PF virt LAG capable function that has no ldev.
> diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> index 3e88b3f51612e..abcab76fced0b 100644
> --- a/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> +++ b/drivers/net/ethernet/mellanox/mlx5/core/lag/lag.c
> @@ -2448,6 +2448,11 @@ static int __mlx5_lag_dev_add_mdev(struct mlx5_core_dev *dev)
> mutex_unlock(&ldev->lock);
> return -EAGAIN;
> }
> +
> + if (mlx5_virt_lag_is_supported(dev) && __mlx5_lag_is_active(ldev)) {
> + mutex_unlock(&ldev->lock);
> + return -EOPNOTSUPP;
> + }
[Severity: Medium]
Can this condition ever be true in this tree?
mlx5_lag_add_mdev() is the only caller of __mlx5_lag_dev_add_mdev(). It
returns early unless mlx5_lag_is_supported() passes:
mlx5_lag_add_mdev() {
if (!mlx5_lag_is_supported(dev))
return;
...
}
mlx5_lag_is_supported() requires num_lag_ports >= 2:
if (!MLX5_CAP_GEN(dev, vport_group_manager) ||
!MLX5_CAP_GEN(dev, lag_master) ||
MLX5_CAP_GEN(dev, num_lag_ports) < 2 ||
...
mlx5_virt_lag_is_supported(), on the other hand, requires
num_lag_ports < 2:
if (!MLX5_CAP_GEN(dev, multi_uplink_eswitch) ||
!MLX5_CAP_GEN(dev, lag_master) ||
MLX5_CAP_GEN(dev, num_lag_ports) >= 2)
return false;
No device can satisfy both, so this -EOPNOTSUPP return and the new cleanup
branch in mlx5_lag_add_mdev() look unreachable.
The commit message says:
"mlx5_ldev_add_mdev() would add a newly probed device to the LAG even
when the LAG is already active"
Can that happen today for a virt LAG capable function? If this check only
prepares for a later series that enables virt LAG, could the commit message
say so?
The same mismatch seems to affect the eswitch change. A non-PF virt LAG
capable function never reaches mlx5_ldev_add_mdev() here, because
sd_lag_init() only handles PF SD secondaries. So dev->priv.lag stays NULL
for it, and mlx5_virt_lag_nonmember() is always true:
static inline bool mlx5_virt_lag_nonmember(struct mlx5_core_dev *dev)
{
return mlx5_virt_lag_is_supported(dev) && !mlx5_lag_dev(dev);
}
As a result, the new early return in mlx5_esw_offloads_devcom_init() fires
for every such VF/SF eswitch:
if (!mlx5_core_is_pf(esw->dev) && mlx5_virt_lag_nonmember(esw->dev))
return;
Before this patch, a VF/SF eswitch with merged_eswitch would register
MLX5_DEVCOM_ESW_OFFLOADS and send ESW_OFFLOADS_DEVCOM_PAIR. The existing
MLX5_VPORT_MANAGER() / !mlx5_lag_is_supported() gate further down does not
stop a non-PF, because MLX5_VPORT_MANAGER() requires mlx5_core_is_pf().
Does this drop eswitch devcom pairing for those VF/SF eswitches? That would
contradict "it is a no-op for existing configurations".
The commit message also limits the devcom change to "such a device", meaning
one rejected from an active LAG. The condition, however, matches any virt LAG
capable VF/SF that has no ldev.
Once virt LAG joins are allowed, devices that are left out because
mlx5_lag_dev_alloc(), mlx5_ldev_add_mdev() or
mlx5_lag_register_hca_devcom_comp() failed would also be treated as
non-members. Is that intended?
> mlx5_ldev_get(ldev);
> err = mlx5_ldev_add_mdev(ldev, dev, 0);
> if (err) {
> @@ -2536,6 +2541,10 @@ void mlx5_lag_add_mdev(struct mlx5_core_dev *dev)
> err = __mlx5_lag_dev_add_mdev(dev);
> mlx5_devcom_comp_unlock(dev->priv.hca_devcom_comp);
>
> + if (err == -EOPNOTSUPP) {
> + mlx5_lag_unregister_hca_devcom_comp(dev);
> + return;
> + }
[Severity: High]
This isn't a bug introduced by this patch, but this new path unregisters the
HCA devcom component, while the nearby failure paths in
__mlx5_lag_dev_add_mdev() still leave it registered.
If no peer ldev exists and mlx5_lag_dev_alloc() or mlx5_ldev_add_mdev()
fails, __mlx5_lag_dev_add_mdev() returns 0 with dev->priv.lag still NULL:
if (!ldev) {
ldev = mlx5_lag_dev_alloc(dev);
if (!ldev) {
mlx5_core_err(dev, "Failed to alloc lag dev\n");
return 0;
}
err = mlx5_ldev_add_mdev(ldev, dev, 0);
if (err) {
mlx5_core_err(dev, "Failed to add mdev to lag dev\n");
mlx5_ldev_put(ldev);
return 0;
}
return 0;
}
mlx5_lag_add_mdev() treats that as success, sends LAG_DEVCOM_PAIR and keeps
dev->priv.hca_devcom_comp. On teardown, mlx5_lag_remove_mdev() returns
before it reaches mlx5_lag_unregister_hca_devcom_comp():
ldev = mlx5_lag_dev(dev);
if (!ldev)
return;
The comp_dev's data still points at this mlx5_core_dev. Does that comp_dev
stay on the shared component list after the core dev is freed?
If so, a peer with the same key that probes or reloads would get the freed
dev back from mlx5_devcom_get_next_peer_data() in __mlx5_lag_dev_add_mdev().
It would then call mlx5_lag_dev(tmp_dev) on freed memory.
A peer's LAG_DEVCOM_PAIR/UNPAIR event would likewise call
mlx5_lag_devcom_event() with the freed dev. That reads dev->priv.lag and can
call mutex_lock() on a garbage ldev.
Could the component also be unregistered on those allocation failure paths?
> if (err) {
> msleep(100);
> goto recheck;
[ ... ]
--
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261116103010.1129666-1-tariqt%40nvidia.com
^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2026-11-18 10:32 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-16 10:30 [PATCH net-next V2 00/10] net/mlx5: LAG, preparations for LAG over VFs/SFs Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 01/10] net/mlx5: Distinguish VFs/SFs in the SW system image GUID for LAG grouping Tariq Toukan
2026-11-18 10:31 ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 02/10] net/mlx5: LAG, select the MPESW master from the live member snapshot Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 03/10] net/mlx5: LAG, skip phys LAG prerequisites for a virt LAG Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 04/10] net/mlx5: LAG, treat virt LAG as a software managed LAG Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 05/10] net/mlx5: LAG, decouple iteration end-of-walk from MLX5_MAX_PORTS Tariq Toukan
2026-11-18 10:31 ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 06/10] net/mlx5: LAG, rename PF naming to fn Tariq Toukan
2026-11-18 10:31 ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 07/10] net/mlx5: LAG, resolve affinity indices only in queue-affinity mode Tariq Toukan
2026-11-16 10:30 ` [PATCH net-next V2 08/10] net/mlx5: LAG: replace fixed MLX5_MAX_PORTS arrays with dynamic allocation Tariq Toukan
2026-11-18 10:31 ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 09/10] net/mlx5: LAG, drop MLX5_MAX_PORTS scratch array from device rescan Tariq Toukan
2026-11-18 10:31 ` netdev-bot+sashiko
2026-11-16 10:30 ` [PATCH net-next V2 10/10] net/mlx5: LAG, do not add a device to an already-active virt LAG Tariq Toukan
2026-11-18 10:32 ` netdev-bot+sashiko
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®