net/mlx5: HWS, simplify allocations as we support only FDB

In pools, STCs and actions: no need to allocate array for various
table types, as HWS is used to manage only FDB flow tables.

Signed-off-by: Yevgeny Kliteynik <kliteyn@nvidia.com>
Reviewed-by: Erez Shitrit <erezsh@nvidia.com>
Reviewed-by: Mark Bloch <mbloch@nvidia.com>
Signed-off-by: Tariq Toukan <tariqt@nvidia.com>
Link: https://patch.msgid.link/20250102181415.1477316-5-tariqt@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Yevgeny Kliteynik 2025-01-02 20:14:03 +02:00 committed by Jakub Kicinski
parent 0a1ef807a4
commit c86963aae5
9 changed files with 87 additions and 112 deletions

View File

@ -11,31 +11,29 @@
/* This is the longest supported action sequence for FDB table:
* DECAP, POP_VLAN, MODIFY, CTR, ASO, PUSH_VLAN, MODIFY, ENCAP, Term.
*/
static const u32 action_order_arr[MLX5HWS_TABLE_TYPE_MAX][MLX5HWS_ACTION_TYP_MAX] = {
[MLX5HWS_TABLE_TYPE_FDB] = {
BIT(MLX5HWS_ACTION_TYP_REMOVE_HEADER) |
BIT(MLX5HWS_ACTION_TYP_REFORMAT_TNL_L2_TO_L2) |
BIT(MLX5HWS_ACTION_TYP_REFORMAT_TNL_L3_TO_L2),
BIT(MLX5HWS_ACTION_TYP_POP_VLAN),
BIT(MLX5HWS_ACTION_TYP_POP_VLAN),
BIT(MLX5HWS_ACTION_TYP_MODIFY_HDR),
BIT(MLX5HWS_ACTION_TYP_PUSH_VLAN),
BIT(MLX5HWS_ACTION_TYP_PUSH_VLAN),
BIT(MLX5HWS_ACTION_TYP_INSERT_HEADER) |
BIT(MLX5HWS_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
BIT(MLX5HWS_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
BIT(MLX5HWS_ACTION_TYP_CTR),
BIT(MLX5HWS_ACTION_TYP_TAG),
BIT(MLX5HWS_ACTION_TYP_ASO_METER),
BIT(MLX5HWS_ACTION_TYP_MODIFY_HDR),
BIT(MLX5HWS_ACTION_TYP_TBL) |
BIT(MLX5HWS_ACTION_TYP_VPORT) |
BIT(MLX5HWS_ACTION_TYP_DROP) |
BIT(MLX5HWS_ACTION_TYP_SAMPLER) |
BIT(MLX5HWS_ACTION_TYP_RANGE) |
BIT(MLX5HWS_ACTION_TYP_DEST_ARRAY),
BIT(MLX5HWS_ACTION_TYP_LAST),
},
static const u32 action_order_arr[MLX5HWS_ACTION_TYP_MAX] = {
BIT(MLX5HWS_ACTION_TYP_REMOVE_HEADER) |
BIT(MLX5HWS_ACTION_TYP_REFORMAT_TNL_L2_TO_L2) |
BIT(MLX5HWS_ACTION_TYP_REFORMAT_TNL_L3_TO_L2),
BIT(MLX5HWS_ACTION_TYP_POP_VLAN),
BIT(MLX5HWS_ACTION_TYP_POP_VLAN),
BIT(MLX5HWS_ACTION_TYP_MODIFY_HDR),
BIT(MLX5HWS_ACTION_TYP_PUSH_VLAN),
BIT(MLX5HWS_ACTION_TYP_PUSH_VLAN),
BIT(MLX5HWS_ACTION_TYP_INSERT_HEADER) |
BIT(MLX5HWS_ACTION_TYP_REFORMAT_L2_TO_TNL_L2) |
BIT(MLX5HWS_ACTION_TYP_REFORMAT_L2_TO_TNL_L3),
BIT(MLX5HWS_ACTION_TYP_CTR),
BIT(MLX5HWS_ACTION_TYP_TAG),
BIT(MLX5HWS_ACTION_TYP_ASO_METER),
BIT(MLX5HWS_ACTION_TYP_MODIFY_HDR),
BIT(MLX5HWS_ACTION_TYP_TBL) |
BIT(MLX5HWS_ACTION_TYP_VPORT) |
BIT(MLX5HWS_ACTION_TYP_DROP) |
BIT(MLX5HWS_ACTION_TYP_SAMPLER) |
BIT(MLX5HWS_ACTION_TYP_RANGE) |
BIT(MLX5HWS_ACTION_TYP_DEST_ARRAY),
BIT(MLX5HWS_ACTION_TYP_LAST),
};
static const char * const mlx5hws_action_type_str[] = {
@ -83,8 +81,8 @@ static int hws_action_get_shared_stc_nic(struct mlx5hws_context *ctx,
int ret;
mutex_lock(&ctx->ctrl_lock);
if (ctx->common_res[tbl_type].shared_stc[stc_type]) {
ctx->common_res[tbl_type].shared_stc[stc_type]->refcount++;
if (ctx->common_res.shared_stc[stc_type]) {
ctx->common_res.shared_stc[stc_type]->refcount++;
mutex_unlock(&ctx->ctrl_lock);
return 0;
}
@ -124,8 +122,8 @@ static int hws_action_get_shared_stc_nic(struct mlx5hws_context *ctx,
goto free_shared_stc;
}
ctx->common_res[tbl_type].shared_stc[stc_type] = shared_stc;
ctx->common_res[tbl_type].shared_stc[stc_type]->refcount = 1;
ctx->common_res.shared_stc[stc_type] = shared_stc;
ctx->common_res.shared_stc[stc_type]->refcount = 1;
mutex_unlock(&ctx->ctrl_lock);
@ -178,16 +176,16 @@ static void hws_action_put_shared_stc(struct mlx5hws_action *action,
}
mutex_lock(&ctx->ctrl_lock);
if (--ctx->common_res[tbl_type].shared_stc[stc_type]->refcount) {
if (--ctx->common_res.shared_stc[stc_type]->refcount) {
mutex_unlock(&ctx->ctrl_lock);
return;
}
shared_stc = ctx->common_res[tbl_type].shared_stc[stc_type];
shared_stc = ctx->common_res.shared_stc[stc_type];
mlx5hws_action_free_single_stc(ctx, tbl_type, &shared_stc->stc_chunk);
kfree(shared_stc);
ctx->common_res[tbl_type].shared_stc[stc_type] = NULL;
ctx->common_res.shared_stc[stc_type] = NULL;
mutex_unlock(&ctx->ctrl_lock);
}
@ -206,10 +204,10 @@ bool mlx5hws_action_check_combo(struct mlx5hws_context *ctx,
enum mlx5hws_action_type *user_actions,
enum mlx5hws_table_type table_type)
{
const u32 *order_arr = action_order_arr[table_type];
const u32 *order_arr = action_order_arr;
bool valid_combo;
u8 order_idx = 0;
u8 user_idx = 0;
bool valid_combo;
if (table_type >= MLX5HWS_TABLE_TYPE_MAX) {
mlx5hws_err(ctx, "Invalid table_type %d", table_type);
@ -321,8 +319,8 @@ int mlx5hws_action_alloc_single_stc(struct mlx5hws_context *ctx,
__must_hold(&ctx->ctrl_lock)
{
struct mlx5hws_cmd_stc_modify_attr cleanup_stc_attr = {0};
struct mlx5hws_pool *stc_pool = ctx->stc_pool[table_type];
struct mlx5hws_cmd_stc_modify_attr fixup_stc_attr = {0};
struct mlx5hws_pool *stc_pool = ctx->stc_pool;
bool use_fixup;
u32 obj_0_id;
int ret;
@ -387,8 +385,8 @@ void mlx5hws_action_free_single_stc(struct mlx5hws_context *ctx,
struct mlx5hws_pool_chunk *stc)
__must_hold(&ctx->ctrl_lock)
{
struct mlx5hws_pool *stc_pool = ctx->stc_pool[table_type];
struct mlx5hws_cmd_stc_modify_attr stc_attr = {0};
struct mlx5hws_pool *stc_pool = ctx->stc_pool;
u32 obj_id;
/* Modify the STC not to point to an object */
@ -561,7 +559,7 @@ hws_action_create_stcs(struct mlx5hws_action *action, u32 obj_id)
if (action->flags & MLX5HWS_ACTION_FLAG_HWS_FDB) {
ret = mlx5hws_action_alloc_single_stc(ctx, &stc_attr,
MLX5HWS_TABLE_TYPE_FDB,
&action->stc[MLX5HWS_TABLE_TYPE_FDB]);
&action->stc);
if (ret)
goto out_err;
}
@ -585,7 +583,7 @@ hws_action_destroy_stcs(struct mlx5hws_action *action)
if (action->flags & MLX5HWS_ACTION_FLAG_HWS_FDB)
mlx5hws_action_free_single_stc(ctx, MLX5HWS_TABLE_TYPE_FDB,
&action->stc[MLX5HWS_TABLE_TYPE_FDB]);
&action->stc);
mutex_unlock(&ctx->ctrl_lock);
}
@ -1639,8 +1637,8 @@ hws_action_create_dest_match_range_table(struct mlx5hws_context *ctx,
rtc_attr.table_type = mlx5hws_table_get_res_fw_ft_type(MLX5HWS_TABLE_TYPE_FDB, false);
/* STC is a single resource (obj_id), use any STC for the ID */
stc_pool = ctx->stc_pool[MLX5HWS_TABLE_TYPE_FDB];
default_stc = ctx->common_res[MLX5HWS_TABLE_TYPE_FDB].default_stc;
stc_pool = ctx->stc_pool;
default_stc = ctx->common_res.default_stc;
obj_id = mlx5hws_pool_chunk_get_base_id(stc_pool, &default_stc->default_hit);
rtc_attr.stc_base = obj_id;
@ -1731,7 +1729,7 @@ hws_action_create_dest_match_range_fill_table(struct mlx5hws_context *ctx,
ste_attr.used_id_rtc_0 = &used_rtc_0_id;
ste_attr.used_id_rtc_1 = &used_rtc_1_id;
common_res = &ctx->common_res[MLX5HWS_TABLE_TYPE_FDB];
common_res = &ctx->common_res;
/* init an empty match STE which will always hit */
ste_attr.wqe_ctrl = &wqe_ctrl;
@ -1750,7 +1748,7 @@ hws_action_create_dest_match_range_fill_table(struct mlx5hws_context *ctx,
wqe_ctrl.stc_ix[MLX5HWS_ACTION_STC_IDX_CTRL] |=
htonl(MLX5HWS_ACTION_STC_IDX_LAST_COMBO2 << 29);
wqe_ctrl.stc_ix[MLX5HWS_ACTION_STC_IDX_HIT] =
htonl(hit_ft_action->stc[MLX5HWS_TABLE_TYPE_FDB].offset);
htonl(hit_ft_action->stc.offset);
wqe_data_arr = (__force __be32 *)&range_wqe_data;
@ -1843,7 +1841,7 @@ mlx5hws_action_create_dest_match_range(struct mlx5hws_context *ctx,
stc_attr.ste_table.match_definer_id = ctx->caps->trivial_match_definer;
ret = mlx5hws_action_alloc_single_stc(ctx, &stc_attr, MLX5HWS_TABLE_TYPE_FDB,
&action->stc[MLX5HWS_TABLE_TYPE_FDB]);
&action->stc);
if (ret)
goto error_unlock;
@ -1970,8 +1968,8 @@ __must_hold(&ctx->ctrl_lock)
struct mlx5hws_action_default_stc *default_stc;
int ret;
if (ctx->common_res[tbl_type].default_stc) {
ctx->common_res[tbl_type].default_stc->refcount++;
if (ctx->common_res.default_stc) {
ctx->common_res.default_stc->refcount++;
return 0;
}
@ -2023,8 +2021,8 @@ __must_hold(&ctx->ctrl_lock)
goto free_nop_dw7;
}
ctx->common_res[tbl_type].default_stc = default_stc;
ctx->common_res[tbl_type].default_stc->refcount++;
ctx->common_res.default_stc = default_stc;
ctx->common_res.default_stc->refcount++;
return 0;
@ -2046,9 +2044,7 @@ __must_hold(&ctx->ctrl_lock)
{
struct mlx5hws_action_default_stc *default_stc;
default_stc = ctx->common_res[tbl_type].default_stc;
default_stc = ctx->common_res[tbl_type].default_stc;
default_stc = ctx->common_res.default_stc;
if (--default_stc->refcount)
return;
@ -2058,7 +2054,7 @@ __must_hold(&ctx->ctrl_lock)
mlx5hws_action_free_single_stc(ctx, tbl_type, &default_stc->nop_dw5);
mlx5hws_action_free_single_stc(ctx, tbl_type, &default_stc->nop_ctr);
kfree(default_stc);
ctx->common_res[tbl_type].default_stc = NULL;
ctx->common_res.default_stc = NULL;
}
static void hws_action_modify_write(struct mlx5hws_send_engine *queue,
@ -2150,8 +2146,7 @@ hws_action_apply_stc(struct mlx5hws_actions_apply_data *apply,
{
struct mlx5hws_action *action = apply->rule_action[action_idx].action;
apply->wqe_ctrl->stc_ix[stc_idx] =
htonl(action->stc[apply->tbl_type].offset);
apply->wqe_ctrl->stc_ix[stc_idx] = htonl(action->stc.offset);
}
static void
@ -2181,7 +2176,7 @@ hws_action_setter_modify_header(struct mlx5hws_actions_apply_data *apply,
rule_action = &apply->rule_action[setter->idx_double];
action = rule_action->action;
stc_idx = htonl(action->stc[apply->tbl_type].offset);
stc_idx = htonl(action->stc.offset);
apply->wqe_ctrl->stc_ix[MLX5HWS_ACTION_STC_IDX_DW6] = stc_idx;
apply->wqe_ctrl->stc_ix[MLX5HWS_ACTION_STC_IDX_DW7] = 0;
@ -2240,7 +2235,7 @@ hws_action_setter_insert_ptr(struct mlx5hws_actions_apply_data *apply,
apply->wqe_data[MLX5HWS_ACTION_OFFSET_DW6] = 0;
apply->wqe_data[MLX5HWS_ACTION_OFFSET_DW7] = htonl(arg_idx);
stc_idx = htonl(action->stc[apply->tbl_type].offset);
stc_idx = htonl(action->stc.offset);
apply->wqe_ctrl->stc_ix[MLX5HWS_ACTION_STC_IDX_DW6] = stc_idx;
apply->wqe_ctrl->stc_ix[MLX5HWS_ACTION_STC_IDX_DW7] = 0;
@ -2272,7 +2267,7 @@ hws_action_setter_tnl_l3_to_l2(struct mlx5hws_actions_apply_data *apply,
apply->wqe_data[MLX5HWS_ACTION_OFFSET_DW6] = 0;
apply->wqe_data[MLX5HWS_ACTION_OFFSET_DW7] = htonl(arg_idx);
stc_idx = htonl(action->stc[apply->tbl_type].offset);
stc_idx = htonl(action->stc.offset);
apply->wqe_ctrl->stc_ix[MLX5HWS_ACTION_STC_IDX_DW6] = stc_idx;
apply->wqe_ctrl->stc_ix[MLX5HWS_ACTION_STC_IDX_DW7] = 0;

View File

@ -124,7 +124,7 @@ struct mlx5hws_action {
struct mlx5hws_context *ctx;
union {
struct {
struct mlx5hws_pool_chunk stc[MLX5HWS_TABLE_TYPE_MAX];
struct mlx5hws_pool_chunk stc;
union {
struct {
u32 pat_id;

View File

@ -359,7 +359,7 @@ void mlx5hws_cmd_set_attr_connect_miss_tbl(struct mlx5hws_context *ctx,
ft_attr->type = fw_ft_type;
ft_attr->table_miss_action = MLX5_IFC_MODIFY_FLOW_TABLE_MISS_ACTION_GOTO_TBL;
default_miss_tbl = ctx->common_res[type].default_miss->ft_id;
default_miss_tbl = ctx->common_res.default_miss->ft_id;
if (!default_miss_tbl) {
pr_warn("HWS: no flow table ID for default miss\n");
return;

View File

@ -23,7 +23,6 @@ static int hws_context_pools_init(struct mlx5hws_context *ctx)
struct mlx5hws_pool_attr pool_attr = {0};
u8 max_log_sz;
int ret;
int i;
ret = mlx5hws_pat_init_pattern_cache(&ctx->pattern_cache);
if (ret)
@ -39,23 +38,17 @@ static int hws_context_pools_init(struct mlx5hws_context *ctx)
max_log_sz = min(MLX5HWS_POOL_STC_LOG_SZ, ctx->caps->stc_alloc_log_max);
pool_attr.alloc_log_sz = max(max_log_sz, ctx->caps->stc_alloc_log_gran);
for (i = 0; i < MLX5HWS_TABLE_TYPE_MAX; i++) {
pool_attr.table_type = i;
ctx->stc_pool[i] = mlx5hws_pool_create(ctx, &pool_attr);
if (!ctx->stc_pool[i]) {
mlx5hws_err(ctx, "Failed to allocate STC pool [%d]", i);
ret = -ENOMEM;
goto free_stc_pools;
}
pool_attr.table_type = MLX5HWS_TABLE_TYPE_FDB;
ctx->stc_pool = mlx5hws_pool_create(ctx, &pool_attr);
if (!ctx->stc_pool) {
mlx5hws_err(ctx, "Failed to allocate STC pool\n");
ret = -ENOMEM;
goto uninit_cache;
}
return 0;
free_stc_pools:
for (i = 0; i < MLX5HWS_TABLE_TYPE_MAX; i++)
if (ctx->stc_pool[i])
mlx5hws_pool_destroy(ctx->stc_pool[i]);
uninit_cache:
mlx5hws_definer_uninit_cache(ctx->definer_cache);
uninit_pat_cache:
mlx5hws_pat_uninit_pattern_cache(ctx->pattern_cache);
@ -64,12 +57,8 @@ static int hws_context_pools_init(struct mlx5hws_context *ctx)
static void hws_context_pools_uninit(struct mlx5hws_context *ctx)
{
int i;
for (i = 0; i < MLX5HWS_TABLE_TYPE_MAX; i++) {
if (ctx->stc_pool[i])
mlx5hws_pool_destroy(ctx->stc_pool[i]);
}
if (ctx->stc_pool)
mlx5hws_pool_destroy(ctx->stc_pool);
mlx5hws_definer_uninit_cache(ctx->definer_cache);
mlx5hws_pat_uninit_pattern_cache(ctx->pattern_cache);

View File

@ -38,8 +38,8 @@ struct mlx5hws_context {
struct mlx5_core_dev *mdev;
struct mlx5hws_cmd_query_caps *caps;
u32 pd_num;
struct mlx5hws_pool *stc_pool[MLX5HWS_TABLE_TYPE_MAX];
struct mlx5hws_context_common_res common_res[MLX5HWS_TABLE_TYPE_MAX];
struct mlx5hws_pool *stc_pool;
struct mlx5hws_context_common_res common_res;
struct mlx5hws_pattern_cache *pattern_cache;
struct mlx5hws_definer_cache *definer_cache;
struct mutex ctrl_lock; /* control lock to protect the whole context */

View File

@ -368,9 +368,10 @@ static int hws_debug_dump_context_info(struct seq_file *f, struct mlx5hws_contex
static int hws_debug_dump_context_stc_resource(struct seq_file *f,
struct mlx5hws_context *ctx,
u32 tbl_type,
struct mlx5hws_pool_resource *resource)
{
u32 tbl_type = MLX5HWS_TABLE_TYPE_BASE + MLX5HWS_TABLE_TYPE_FDB;
seq_printf(f, "%d,0x%llx,%u,%u\n",
MLX5HWS_DEBUG_RES_TYPE_CONTEXT_STC,
HWS_PTR_TO_ID(ctx),
@ -382,31 +383,22 @@ static int hws_debug_dump_context_stc_resource(struct seq_file *f,
static int hws_debug_dump_context_stc(struct seq_file *f, struct mlx5hws_context *ctx)
{
struct mlx5hws_pool *stc_pool;
u32 table_type;
struct mlx5hws_pool *stc_pool = ctx->stc_pool;
int ret;
int i;
for (i = 0; i < MLX5HWS_TABLE_TYPE_MAX; i++) {
stc_pool = ctx->stc_pool[i];
table_type = MLX5HWS_TABLE_TYPE_BASE + i;
if (!stc_pool)
return 0;
if (!stc_pool)
continue;
if (stc_pool->resource[0]) {
ret = hws_debug_dump_context_stc_resource(f, ctx, stc_pool->resource[0]);
if (ret)
return ret;
}
if (stc_pool->resource[0]) {
ret = hws_debug_dump_context_stc_resource(f, ctx, table_type,
stc_pool->resource[0]);
if (ret)
return ret;
}
if (i == MLX5HWS_TABLE_TYPE_FDB && stc_pool->mirror_resource[0]) {
ret = hws_debug_dump_context_stc_resource(f, ctx, table_type,
stc_pool->mirror_resource[0]);
if (ret)
return ret;
}
if (stc_pool->mirror_resource[0]) {
ret = hws_debug_dump_context_stc_resource(f, ctx, stc_pool->mirror_resource[0]);
if (ret)
return ret;
}
return 0;

View File

@ -318,8 +318,8 @@ static int hws_matcher_create_rtc(struct mlx5hws_matcher *matcher,
hws_matcher_set_rtc_attr_sz(matcher, &rtc_attr, rtc_type, false);
/* STC is a single resource (obj_id), use any STC for the ID */
stc_pool = ctx->stc_pool[tbl->type];
default_stc = ctx->common_res[tbl->type].default_stc;
stc_pool = ctx->stc_pool;
default_stc = ctx->common_res.default_stc;
obj_id = mlx5hws_pool_chunk_get_base_id(stc_pool, &default_stc->default_hit);
rtc_attr.stc_base = obj_id;

View File

@ -315,7 +315,7 @@ static void hws_rule_create_init(struct mlx5hws_rule *rule,
/* Init default action apply */
apply->tbl_type = tbl->type;
apply->common_res = &ctx->common_res[tbl->type];
apply->common_res = &ctx->common_res;
apply->jump_to_action_stc = matcher->action_ste[0].stc.offset;
apply->require_dep = 0;
}

View File

@ -49,8 +49,8 @@ __must_hold(&tbl->ctx->ctrl_lock)
if (tbl->type != MLX5HWS_TABLE_TYPE_FDB)
return 0;
if (ctx->common_res[tbl_type].default_miss) {
ctx->common_res[tbl_type].default_miss->refcount++;
if (ctx->common_res.default_miss) {
ctx->common_res.default_miss->refcount++;
return 0;
}
@ -71,8 +71,8 @@ __must_hold(&tbl->ctx->ctrl_lock)
return -EINVAL;
}
ctx->common_res[tbl_type].default_miss = default_miss;
ctx->common_res[tbl_type].default_miss->refcount++;
ctx->common_res.default_miss = default_miss;
ctx->common_res.default_miss->refcount++;
return 0;
}
@ -83,17 +83,16 @@ __must_hold(&tbl->ctx->ctrl_lock)
{
struct mlx5hws_cmd_forward_tbl *default_miss;
struct mlx5hws_context *ctx = tbl->ctx;
u8 tbl_type = tbl->type;
if (tbl->type != MLX5HWS_TABLE_TYPE_FDB)
return;
default_miss = ctx->common_res[tbl_type].default_miss;
default_miss = ctx->common_res.default_miss;
if (--default_miss->refcount)
return;
mlx5hws_cmd_forward_tbl_destroy(ctx->mdev, default_miss);
ctx->common_res[tbl_type].default_miss = NULL;
ctx->common_res.default_miss = NULL;
}
static int hws_table_connect_to_default_miss_tbl(struct mlx5hws_table *tbl, u32 ft_id)