Skip to content

Commit 439e843

Browse files
Paul BlakeySaeed Mahameed
authored andcommitted
net/mlx5: Refactor creating fast path prio chains
Next patch will re-use this to add a new chain but in a different prio. Signed-off-by: Paul Blakey <[email protected]> Reviewed-by: Mark Bloch <[email protected]> Acked-by: Pablo Neira Ayuso <[email protected]> Signed-off-by: Saeed Mahameed <[email protected]>
1 parent 34b13cb commit 439e843

File tree

1 file changed

+82
-36
lines changed
  • drivers/net/ethernet/mellanox/mlx5/core

1 file changed

+82
-36
lines changed

drivers/net/ethernet/mellanox/mlx5/core/fs_core.c

Lines changed: 82 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,60 +2558,106 @@ static int init_rdma_rx_root_ns(struct mlx5_flow_steering *steering)
25582558
steering->rdma_rx_root_ns = NULL;
25592559
return err;
25602560
}
2561-
static int init_fdb_root_ns(struct mlx5_flow_steering *steering)
2561+
2562+
/* FT and tc chains are stored in the same array so we can re-use the
2563+
* mlx5_get_fdb_sub_ns() and tc api for FT chains.
2564+
* When creating a new ns for each chain store it in the first available slot.
2565+
* Assume tc chains are created and stored first and only then the FT chain.
2566+
*/
2567+
static void store_fdb_sub_ns_prio_chain(struct mlx5_flow_steering *steering,
2568+
struct mlx5_flow_namespace *ns)
2569+
{
2570+
int chain = 0;
2571+
2572+
while (steering->fdb_sub_ns[chain])
2573+
++chain;
2574+
2575+
steering->fdb_sub_ns[chain] = ns;
2576+
}
2577+
2578+
static int create_fdb_sub_ns_prio_chain(struct mlx5_flow_steering *steering,
2579+
struct fs_prio *maj_prio)
25622580
{
25632581
struct mlx5_flow_namespace *ns;
2564-
struct fs_prio *maj_prio;
25652582
struct fs_prio *min_prio;
2583+
int prio;
2584+
2585+
ns = fs_create_namespace(maj_prio, MLX5_FLOW_TABLE_MISS_ACTION_DEF);
2586+
if (IS_ERR(ns))
2587+
return PTR_ERR(ns);
2588+
2589+
for (prio = 0; prio < FDB_TC_MAX_PRIO; prio++) {
2590+
min_prio = fs_create_prio(ns, prio, FDB_TC_LEVELS_PER_PRIO);
2591+
if (IS_ERR(min_prio))
2592+
return PTR_ERR(min_prio);
2593+
}
2594+
2595+
store_fdb_sub_ns_prio_chain(steering, ns);
2596+
2597+
return 0;
2598+
}
2599+
2600+
static int create_fdb_chains(struct mlx5_flow_steering *steering,
2601+
int fs_prio,
2602+
int chains)
2603+
{
2604+
struct fs_prio *maj_prio;
25662605
int levels;
25672606
int chain;
2568-
int prio;
25692607
int err;
25702608

2571-
steering->fdb_root_ns = create_root_ns(steering, FS_FT_FDB);
2572-
if (!steering->fdb_root_ns)
2573-
return -ENOMEM;
2609+
levels = FDB_TC_LEVELS_PER_PRIO * FDB_TC_MAX_PRIO * chains;
2610+
maj_prio = fs_create_prio_chained(&steering->fdb_root_ns->ns,
2611+
fs_prio,
2612+
levels);
2613+
if (IS_ERR(maj_prio))
2614+
return PTR_ERR(maj_prio);
2615+
2616+
for (chain = 0; chain < chains; chain++) {
2617+
err = create_fdb_sub_ns_prio_chain(steering, maj_prio);
2618+
if (err)
2619+
return err;
2620+
}
2621+
2622+
return 0;
2623+
}
25742624

2575-
steering->fdb_sub_ns = kzalloc(sizeof(steering->fdb_sub_ns) *
2576-
(FDB_TC_MAX_CHAIN + 1), GFP_KERNEL);
2625+
static int create_fdb_fast_path(struct mlx5_flow_steering *steering)
2626+
{
2627+
const int total_chains = FDB_TC_MAX_CHAIN + 1;
2628+
int err;
2629+
2630+
steering->fdb_sub_ns = kcalloc(total_chains,
2631+
sizeof(*steering->fdb_sub_ns),
2632+
GFP_KERNEL);
25772633
if (!steering->fdb_sub_ns)
25782634
return -ENOMEM;
25792635

2636+
err = create_fdb_chains(steering, FDB_FAST_PATH, FDB_TC_MAX_CHAIN + 1);
2637+
if (err)
2638+
return err;
2639+
2640+
return 0;
2641+
}
2642+
2643+
static int init_fdb_root_ns(struct mlx5_flow_steering *steering)
2644+
{
2645+
struct fs_prio *maj_prio;
2646+
int err;
2647+
2648+
steering->fdb_root_ns = create_root_ns(steering, FS_FT_FDB);
2649+
if (!steering->fdb_root_ns)
2650+
return -ENOMEM;
2651+
25802652
maj_prio = fs_create_prio(&steering->fdb_root_ns->ns, FDB_BYPASS_PATH,
25812653
1);
25822654
if (IS_ERR(maj_prio)) {
25832655
err = PTR_ERR(maj_prio);
25842656
goto out_err;
25852657
}
2586-
2587-
levels = FDB_TC_LEVELS_PER_PRIO *
2588-
FDB_TC_MAX_PRIO * (FDB_TC_MAX_CHAIN + 1);
2589-
maj_prio = fs_create_prio_chained(&steering->fdb_root_ns->ns,
2590-
FDB_FAST_PATH,
2591-
levels);
2592-
if (IS_ERR(maj_prio)) {
2593-
err = PTR_ERR(maj_prio);
2658+
err = create_fdb_fast_path(steering);
2659+
if (err)
25942660
goto out_err;
2595-
}
2596-
2597-
for (chain = 0; chain <= FDB_TC_MAX_CHAIN; chain++) {
2598-
ns = fs_create_namespace(maj_prio, MLX5_FLOW_TABLE_MISS_ACTION_DEF);
2599-
if (IS_ERR(ns)) {
2600-
err = PTR_ERR(ns);
2601-
goto out_err;
2602-
}
2603-
2604-
for (prio = 0; prio < FDB_TC_MAX_PRIO * (chain + 1); prio++) {
2605-
min_prio = fs_create_prio(ns, prio,
2606-
FDB_TC_LEVELS_PER_PRIO);
2607-
if (IS_ERR(min_prio)) {
2608-
err = PTR_ERR(min_prio);
2609-
goto out_err;
2610-
}
2611-
}
2612-
2613-
steering->fdb_sub_ns[chain] = ns;
2614-
}
26152661

26162662
maj_prio = fs_create_prio(&steering->fdb_root_ns->ns, FDB_SLOW_PATH, 1);
26172663
if (IS_ERR(maj_prio)) {

0 commit comments

Comments
 (0)