]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net/mlx5: E-switch, modify peer miss rule index to vhca_id
authorShay Drory <shayd@nvidia.com>
Mon, 9 Mar 2026 09:34:31 +0000 (11:34 +0200)
committerLeon Romanovsky <leon@kernel.org>
Mon, 16 Mar 2026 20:23:00 +0000 (16:23 -0400)
Replace the fixed-size array peer_miss_rules[MLX5_MAX_PORTS], indexed
by physical function index, with an xarray indexed by vhca_id.

This decouples peer_miss_rules from mlx5_get_dev_index(), removing the
dependency on a PF-derived index and the arbitrary MLX5_MAX_PORTS bounds
check. Using vhca_id as the key simplifies insertion/removal logic and
scales better across multi-peer topologies.

Initialize and destroy the xarray alongside the existing esw->paired
xarray in mlx5_esw_offloads_devcom_init/cleanup respectively.

Signed-off-by: Shay Drory <shayd@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20260309093435.1850724-6-tariqt@nvidia.com
Signed-off-by: Leon Romanovsky <leon@kernel.org>
drivers/net/ethernet/mellanox/mlx5/core/eswitch.h
drivers/net/ethernet/mellanox/mlx5/core/eswitch_offloads.c

index 6841caef02d10874390dd48d49e07a18c3041227..96309a732d5050b76651965db86b29635d1891f8 100644 (file)
@@ -273,7 +273,7 @@ struct mlx5_eswitch_fdb {
                        struct mlx5_flow_group *send_to_vport_grp;
                        struct mlx5_flow_group *send_to_vport_meta_grp;
                        struct mlx5_flow_group *peer_miss_grp;
-                       struct mlx5_flow_handle **peer_miss_rules[MLX5_MAX_PORTS];
+                       struct xarray peer_miss_rules;
                        struct mlx5_flow_group *miss_grp;
                        struct mlx5_flow_handle **send_to_vport_meta_rules;
                        struct mlx5_flow_handle *miss_rule_uni;
index 1366f6e489bd2d2f35269d67378a07d27829fc17..90e6f97bdf4a0166f748c03ee1551b92f9e4c3dd 100644 (file)
@@ -1190,7 +1190,7 @@ static int esw_add_fdb_peer_miss_rules(struct mlx5_eswitch *esw,
        struct mlx5_flow_handle *flow;
        struct mlx5_vport *peer_vport;
        struct mlx5_flow_spec *spec;
-       int err, pfindex;
+       int err;
        unsigned long i;
        void *misc;
 
@@ -1274,14 +1274,10 @@ static int esw_add_fdb_peer_miss_rules(struct mlx5_eswitch *esw,
                }
        }
 
-       pfindex = mlx5_get_dev_index(peer_dev);
-       if (pfindex >= MLX5_MAX_PORTS) {
-               esw_warn(esw->dev, "Peer dev index(%d) is over the max num defined(%d)\n",
-                        pfindex, MLX5_MAX_PORTS);
-               err = -EINVAL;
+       err = xa_insert(&esw->fdb_table.offloads.peer_miss_rules,
+                       MLX5_CAP_GEN(peer_dev, vhca_id), flows, GFP_KERNEL);
+       if (err)
                goto add_ec_vf_flow_err;
-       }
-       esw->fdb_table.offloads.peer_miss_rules[pfindex] = flows;
 
        kvfree(spec);
        return 0;
@@ -1323,12 +1319,13 @@ static void esw_del_fdb_peer_miss_rules(struct mlx5_eswitch *esw,
                                        struct mlx5_core_dev *peer_dev)
 {
        struct mlx5_eswitch *peer_esw = peer_dev->priv.eswitch;
-       u16 peer_index = mlx5_get_dev_index(peer_dev);
+       u16 peer_vhca_id = MLX5_CAP_GEN(peer_dev, vhca_id);
        struct mlx5_flow_handle **flows;
        struct mlx5_vport *peer_vport;
        unsigned long i;
 
-       flows = esw->fdb_table.offloads.peer_miss_rules[peer_index];
+       flows = xa_erase(&esw->fdb_table.offloads.peer_miss_rules,
+                        peer_vhca_id);
        if (!flows)
                return;
 
@@ -1353,7 +1350,6 @@ static void esw_del_fdb_peer_miss_rules(struct mlx5_eswitch *esw,
        }
 
        kvfree(flows);
-       esw->fdb_table.offloads.peer_miss_rules[peer_index] = NULL;
 }
 
 static int esw_add_fdb_miss_rule(struct mlx5_eswitch *esw)
@@ -3250,6 +3246,7 @@ void mlx5_esw_offloads_devcom_init(struct mlx5_eswitch *esw,
                return;
 
        xa_init(&esw->paired);
+       xa_init(&esw->fdb_table.offloads.peer_miss_rules);
        esw->num_peers = 0;
        esw->devcom = mlx5_devcom_register_component(esw->dev->priv.devc,
                                                     MLX5_DEVCOM_ESW_OFFLOADS,
@@ -3277,6 +3274,7 @@ void mlx5_esw_offloads_devcom_cleanup(struct mlx5_eswitch *esw)
 
        mlx5_devcom_unregister_component(esw->devcom);
        xa_destroy(&esw->paired);
+       xa_destroy(&esw->fdb_table.offloads.peer_miss_rules);
        esw->devcom = NULL;
 }