On Fri, Nov 20, 2026 at 09:59:54AM +0200, Tariq Toukan wrote:
> From: Shay Drory <sha…@nvidia.com>
>
> The eswitch source-port match metadata is laid out as 4 bits of PFNUM
> and 12 bits of a unique id (ESW_SOURCE_PORT_METADATA_BITS). PFNUM is the
> native_port_num reported in HCA_CAP, so all VFs/SFs of the same PF share
> a single PFNUM. Each VF/SF eswitch allocates its id from its own
> vport_metadata_ida, restarting from the lowest value, so two VFs/SFs of
> the same PF can end up with identical metadata. Once their eswitches
> share an FDB (virt LAG), that metadata no longer uniquely identifies the
> source port.
>
> Add a dedicated allocator for nested (virt LAG) eswitches that replaces
> the PFNUM field with the VF/SF's slot in the LAG (its xarray index in
> ldev->fns). That index is unique per function within the LAG, so
> combined with a per-VF/SF id it yields unique metadata regardless of
> which PF the VFs/SFs belong to. The split is 8 bits for the virt LAG
> index - which fits the U8_MAX cap on the LAG xarray - and the remaining
> 8 bits for the id; the two still sum to ESW_SOURCE_PORT_METADATA_BITS,
> so nothing downstream of the match changes. Describe the nested layout
> next to the reg_c_0 layout in include/linux/mlx5/eswitch.h.
>
> The PFNUM value 0xf is reserved for internal port offload, which stamps
> it into reg_c_0 and matches it with the same mask used for vport
> metadata. That offload is gated on switchdev mode only, so it can be
> used on a nested eswitch as well. Cap the LAG index accordingly.
>
> Select the nested layout for a non-PF eswitch, unless it is virt LAG
> capable but not a LAG member, e.g. one refused as a late joiner and left
> standalone. Such a device keeps the PFNUM layout: it does not pair with
> the eswitches of the LAG members, so its metadata is never compared
> against theirs. PFs, which never report the virt LAG capabilities, keep
> the PFNUM layout.
>
> Signed-off-by: Shay Drory <sha…@nvidia.com>
> Reviewed-by: Moshe Shemesh <mos…@nvidia.com>
> Reviewed-by: Mark Bloch <mblo…@nvidia.com>
> Signed-off-by: Tariq Toukan <tari…@nvidia.com>
Reviewed-by: Simon Horman <hor…@kernel.org>