Commit 8e80e564 authored by Paul Blakey's avatar Paul Blakey Committed by Leon Romanovsky

net/mlx5: fs_chains: Refactor to detach chains from tc usage

To support more generic chains that will be used on other
namespaces and without tc, refactor to remove the dependency
on tc terms.
Signed-off-by: default avatarPaul Blakey <paulb@nvidia.com>
Reviewed-by: default avatarRaed Salem <raeds@nvidia.com>
Link: https://lore.kernel.org/r/bb8570d532d569285b5bff981578507bd15350cb.1678714336.git.leon@kernel.orgSigned-off-by: default avatarLeon Romanovsky <leon@kernel.org>
parent eeac8ede
...@@ -5186,22 +5186,6 @@ static int mlx5e_tc_netdev_event(struct notifier_block *this, ...@@ -5186,22 +5186,6 @@ static int mlx5e_tc_netdev_event(struct notifier_block *this,
return NOTIFY_DONE; return NOTIFY_DONE;
} }
static int mlx5e_tc_nic_get_ft_size(struct mlx5_core_dev *dev)
{
int tc_grp_size, tc_tbl_size;
u32 max_flow_counter;
max_flow_counter = (MLX5_CAP_GEN(dev, max_flow_counter_31_16) << 16) |
MLX5_CAP_GEN(dev, max_flow_counter_15_0);
tc_grp_size = min_t(int, max_flow_counter, MLX5E_TC_TABLE_MAX_GROUP_SIZE);
tc_tbl_size = min_t(int, tc_grp_size * MLX5E_TC_TABLE_NUM_GROUPS,
BIT(MLX5_CAP_FLOWTABLE_NIC_RX(dev, log_max_ft_size)));
return tc_tbl_size;
}
static int mlx5e_tc_nic_create_miss_table(struct mlx5e_priv *priv) static int mlx5e_tc_nic_create_miss_table(struct mlx5e_priv *priv)
{ {
struct mlx5e_tc_table *tc = mlx5e_fs_get_tc(priv->fs); struct mlx5e_tc_table *tc = mlx5e_fs_get_tc(priv->fs);
...@@ -5274,10 +5258,10 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv) ...@@ -5274,10 +5258,10 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv)
attr.flags = MLX5_CHAINS_AND_PRIOS_SUPPORTED | attr.flags = MLX5_CHAINS_AND_PRIOS_SUPPORTED |
MLX5_CHAINS_IGNORE_FLOW_LEVEL_SUPPORTED; MLX5_CHAINS_IGNORE_FLOW_LEVEL_SUPPORTED;
attr.ns = MLX5_FLOW_NAMESPACE_KERNEL; attr.ns = MLX5_FLOW_NAMESPACE_KERNEL;
attr.max_ft_sz = mlx5e_tc_nic_get_ft_size(dev);
attr.max_grp_num = MLX5E_TC_TABLE_NUM_GROUPS; attr.max_grp_num = MLX5E_TC_TABLE_NUM_GROUPS;
attr.default_ft = tc->miss_t; attr.default_ft = tc->miss_t;
attr.mapping = chains_mapping; attr.mapping = chains_mapping;
attr.fs_base_prio = MLX5E_TC_PRIO;
tc->chains = mlx5_chains_create(dev, &attr); tc->chains = mlx5_chains_create(dev, &attr);
if (IS_ERR(tc->chains)) { if (IS_ERR(tc->chains)) {
...@@ -5285,6 +5269,8 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv) ...@@ -5285,6 +5269,8 @@ int mlx5e_tc_nic_init(struct mlx5e_priv *priv)
goto err_miss; goto err_miss;
} }
mlx5_chains_print_info(tc->chains);
tc->post_act = mlx5e_tc_post_act_init(priv, tc->chains, MLX5_FLOW_NAMESPACE_KERNEL); tc->post_act = mlx5e_tc_post_act_init(priv, tc->chains, MLX5_FLOW_NAMESPACE_KERNEL);
tc->ct = mlx5_tc_ct_init(priv, tc->chains, &tc->mod_hdr, tc->ct = mlx5_tc_ct_init(priv, tc->chains, &tc->mod_hdr,
MLX5_FLOW_NAMESPACE_KERNEL, tc->post_act); MLX5_FLOW_NAMESPACE_KERNEL, tc->post_act);
......
...@@ -1374,14 +1374,11 @@ esw_chains_create(struct mlx5_eswitch *esw, struct mlx5_flow_table *miss_fdb) ...@@ -1374,14 +1374,11 @@ esw_chains_create(struct mlx5_eswitch *esw, struct mlx5_flow_table *miss_fdb)
struct mlx5_flow_table *nf_ft, *ft; struct mlx5_flow_table *nf_ft, *ft;
struct mlx5_chains_attr attr = {}; struct mlx5_chains_attr attr = {};
struct mlx5_fs_chains *chains; struct mlx5_fs_chains *chains;
u32 fdb_max;
int err; int err;
fdb_max = 1 << MLX5_CAP_ESW_FLOWTABLE_FDB(dev, log_max_ft_size);
esw_init_chains_offload_flags(esw, &attr.flags); esw_init_chains_offload_flags(esw, &attr.flags);
attr.ns = MLX5_FLOW_NAMESPACE_FDB; attr.ns = MLX5_FLOW_NAMESPACE_FDB;
attr.max_ft_sz = fdb_max; attr.fs_base_prio = FDB_TC_OFFLOAD;
attr.max_grp_num = esw->params.large_group_num; attr.max_grp_num = esw->params.large_group_num;
attr.default_ft = miss_fdb; attr.default_ft = miss_fdb;
attr.mapping = esw->offloads.reg_c0_obj_pool; attr.mapping = esw->offloads.reg_c0_obj_pool;
...@@ -1392,6 +1389,7 @@ esw_chains_create(struct mlx5_eswitch *esw, struct mlx5_flow_table *miss_fdb) ...@@ -1392,6 +1389,7 @@ esw_chains_create(struct mlx5_eswitch *esw, struct mlx5_flow_table *miss_fdb)
esw_warn(dev, "Failed to create fdb chains err(%d)\n", err); esw_warn(dev, "Failed to create fdb chains err(%d)\n", err);
return err; return err;
} }
mlx5_chains_print_info(chains);
esw->fdb_table.offloads.esw_chains_priv = chains; esw->fdb_table.offloads.esw_chains_priv = chains;
......
...@@ -14,10 +14,8 @@ ...@@ -14,10 +14,8 @@
#define chains_lock(chains) ((chains)->lock) #define chains_lock(chains) ((chains)->lock)
#define chains_ht(chains) ((chains)->chains_ht) #define chains_ht(chains) ((chains)->chains_ht)
#define prios_ht(chains) ((chains)->prios_ht) #define prios_ht(chains) ((chains)->prios_ht)
#define tc_default_ft(chains) ((chains)->tc_default_ft) #define chains_default_ft(chains) ((chains)->chains_default_ft)
#define tc_end_ft(chains) ((chains)->tc_end_ft) #define chains_end_ft(chains) ((chains)->chains_end_ft)
#define ns_to_chains_fs_prio(ns) ((ns) == MLX5_FLOW_NAMESPACE_FDB ? \
FDB_TC_OFFLOAD : MLX5E_TC_PRIO)
#define FT_TBL_SZ (64 * 1024) #define FT_TBL_SZ (64 * 1024)
struct mlx5_fs_chains { struct mlx5_fs_chains {
...@@ -28,13 +26,15 @@ struct mlx5_fs_chains { ...@@ -28,13 +26,15 @@ struct mlx5_fs_chains {
/* Protects above chains_ht and prios_ht */ /* Protects above chains_ht and prios_ht */
struct mutex lock; struct mutex lock;
struct mlx5_flow_table *tc_default_ft; struct mlx5_flow_table *chains_default_ft;
struct mlx5_flow_table *tc_end_ft; struct mlx5_flow_table *chains_end_ft;
struct mapping_ctx *chains_mapping; struct mapping_ctx *chains_mapping;
enum mlx5_flow_namespace_type ns; enum mlx5_flow_namespace_type ns;
u32 group_num; u32 group_num;
u32 flags; u32 flags;
int fs_base_prio;
int fs_base_level;
}; };
struct fs_chain { struct fs_chain {
...@@ -145,7 +145,7 @@ void ...@@ -145,7 +145,7 @@ void
mlx5_chains_set_end_ft(struct mlx5_fs_chains *chains, mlx5_chains_set_end_ft(struct mlx5_fs_chains *chains,
struct mlx5_flow_table *ft) struct mlx5_flow_table *ft)
{ {
tc_end_ft(chains) = ft; chains_end_ft(chains) = ft;
} }
static struct mlx5_flow_table * static struct mlx5_flow_table *
...@@ -164,11 +164,11 @@ mlx5_chains_create_table(struct mlx5_fs_chains *chains, ...@@ -164,11 +164,11 @@ mlx5_chains_create_table(struct mlx5_fs_chains *chains,
sz = (chain == mlx5_chains_get_nf_ft_chain(chains)) ? FT_TBL_SZ : POOL_NEXT_SIZE; sz = (chain == mlx5_chains_get_nf_ft_chain(chains)) ? FT_TBL_SZ : POOL_NEXT_SIZE;
ft_attr.max_fte = sz; ft_attr.max_fte = sz;
/* We use tc_default_ft(chains) as the table's next_ft till /* We use chains_default_ft(chains) as the table's next_ft till
* ignore_flow_level is allowed on FT creation and not just for FTEs. * ignore_flow_level is allowed on FT creation and not just for FTEs.
* Instead caller should add an explicit miss rule if needed. * Instead caller should add an explicit miss rule if needed.
*/ */
ft_attr.next_ft = tc_default_ft(chains); ft_attr.next_ft = chains_default_ft(chains);
/* The root table(chain 0, prio 1, level 0) is required to be /* The root table(chain 0, prio 1, level 0) is required to be
* connected to the previous fs_core managed prio. * connected to the previous fs_core managed prio.
...@@ -177,22 +177,22 @@ mlx5_chains_create_table(struct mlx5_fs_chains *chains, ...@@ -177,22 +177,22 @@ mlx5_chains_create_table(struct mlx5_fs_chains *chains,
*/ */
if (!mlx5_chains_ignore_flow_level_supported(chains) || if (!mlx5_chains_ignore_flow_level_supported(chains) ||
(chain == 0 && prio == 1 && level == 0)) { (chain == 0 && prio == 1 && level == 0)) {
ft_attr.level = level; ft_attr.level = chains->fs_base_level;
ft_attr.prio = prio - 1; ft_attr.prio = chains->fs_base_prio;
ns = (chains->ns == MLX5_FLOW_NAMESPACE_FDB) ? ns = (chains->ns == MLX5_FLOW_NAMESPACE_FDB) ?
mlx5_get_fdb_sub_ns(chains->dev, chain) : mlx5_get_fdb_sub_ns(chains->dev, chain) :
mlx5_get_flow_namespace(chains->dev, chains->ns); mlx5_get_flow_namespace(chains->dev, chains->ns);
} else { } else {
ft_attr.flags |= MLX5_FLOW_TABLE_UNMANAGED; ft_attr.flags |= MLX5_FLOW_TABLE_UNMANAGED;
ft_attr.prio = ns_to_chains_fs_prio(chains->ns); ft_attr.prio = chains->fs_base_prio;
/* Firmware doesn't allow us to create another level 0 table, /* Firmware doesn't allow us to create another level 0 table,
* so we create all unmanaged tables as level 1. * so we create all unmanaged tables as level 1 (base + 1).
* *
* To connect them, we use explicit miss rules with * To connect them, we use explicit miss rules with
* ignore_flow_level. Caller is responsible to create * ignore_flow_level. Caller is responsible to create
* these rules (if needed). * these rules (if needed).
*/ */
ft_attr.level = 1; ft_attr.level = chains->fs_base_level + 1;
ns = mlx5_get_flow_namespace(chains->dev, chains->ns); ns = mlx5_get_flow_namespace(chains->dev, chains->ns);
} }
...@@ -220,7 +220,8 @@ create_chain_restore(struct fs_chain *chain) ...@@ -220,7 +220,8 @@ create_chain_restore(struct fs_chain *chain)
int err; int err;
if (chain->chain == mlx5_chains_get_nf_ft_chain(chains) || if (chain->chain == mlx5_chains_get_nf_ft_chain(chains) ||
!mlx5_chains_prios_supported(chains)) !mlx5_chains_prios_supported(chains) ||
!chains->chains_mapping)
return 0; return 0;
err = mlx5_chains_get_chain_mapping(chains, chain->chain, &index); err = mlx5_chains_get_chain_mapping(chains, chain->chain, &index);
...@@ -380,7 +381,7 @@ mlx5_chains_add_miss_rule(struct fs_chain *chain, ...@@ -380,7 +381,7 @@ mlx5_chains_add_miss_rule(struct fs_chain *chain,
dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE; dest.type = MLX5_FLOW_DESTINATION_TYPE_FLOW_TABLE;
dest.ft = next_ft; dest.ft = next_ft;
if (next_ft == tc_end_ft(chains) && if (chains->chains_mapping && next_ft == chains_end_ft(chains) &&
chain->chain != mlx5_chains_get_nf_ft_chain(chains) && chain->chain != mlx5_chains_get_nf_ft_chain(chains) &&
mlx5_chains_prios_supported(chains)) { mlx5_chains_prios_supported(chains)) {
act.modify_hdr = chain->miss_modify_hdr; act.modify_hdr = chain->miss_modify_hdr;
...@@ -494,8 +495,8 @@ mlx5_chains_create_prio(struct mlx5_fs_chains *chains, ...@@ -494,8 +495,8 @@ mlx5_chains_create_prio(struct mlx5_fs_chains *chains,
/* Default miss for each chain: */ /* Default miss for each chain: */
next_ft = (chain == mlx5_chains_get_nf_ft_chain(chains)) ? next_ft = (chain == mlx5_chains_get_nf_ft_chain(chains)) ?
tc_default_ft(chains) : chains_default_ft(chains) :
tc_end_ft(chains); chains_end_ft(chains);
list_for_each(pos, &chain_s->prios_list) { list_for_each(pos, &chain_s->prios_list) {
struct prio *p = list_entry(pos, struct prio, list); struct prio *p = list_entry(pos, struct prio, list);
...@@ -681,7 +682,7 @@ mlx5_chains_put_table(struct mlx5_fs_chains *chains, u32 chain, u32 prio, ...@@ -681,7 +682,7 @@ mlx5_chains_put_table(struct mlx5_fs_chains *chains, u32 chain, u32 prio,
struct mlx5_flow_table * struct mlx5_flow_table *
mlx5_chains_get_tc_end_ft(struct mlx5_fs_chains *chains) mlx5_chains_get_tc_end_ft(struct mlx5_fs_chains *chains)
{ {
return tc_end_ft(chains); return chains_end_ft(chains);
} }
struct mlx5_flow_table * struct mlx5_flow_table *
...@@ -718,48 +719,38 @@ mlx5_chains_destroy_global_table(struct mlx5_fs_chains *chains, ...@@ -718,48 +719,38 @@ mlx5_chains_destroy_global_table(struct mlx5_fs_chains *chains,
static struct mlx5_fs_chains * static struct mlx5_fs_chains *
mlx5_chains_init(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr) mlx5_chains_init(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr)
{ {
struct mlx5_fs_chains *chains_priv; struct mlx5_fs_chains *chains;
u32 max_flow_counter;
int err; int err;
chains_priv = kzalloc(sizeof(*chains_priv), GFP_KERNEL); chains = kzalloc(sizeof(*chains), GFP_KERNEL);
if (!chains_priv) if (!chains)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
max_flow_counter = (MLX5_CAP_GEN(dev, max_flow_counter_31_16) << 16) | chains->dev = dev;
MLX5_CAP_GEN(dev, max_flow_counter_15_0); chains->flags = attr->flags;
chains->ns = attr->ns;
mlx5_core_dbg(dev, chains->group_num = attr->max_grp_num;
"Init flow table chains, max counters(%d), groups(%d), max flow table size(%d)\n", chains->chains_mapping = attr->mapping;
max_flow_counter, attr->max_grp_num, attr->max_ft_sz); chains->fs_base_prio = attr->fs_base_prio;
chains->fs_base_level = attr->fs_base_level;
chains_priv->dev = dev; chains_default_ft(chains) = chains_end_ft(chains) = attr->default_ft;
chains_priv->flags = attr->flags;
chains_priv->ns = attr->ns;
chains_priv->group_num = attr->max_grp_num;
chains_priv->chains_mapping = attr->mapping;
tc_default_ft(chains_priv) = tc_end_ft(chains_priv) = attr->default_ft;
mlx5_core_info(dev, "Supported tc offload range - chains: %u, prios: %u\n", err = rhashtable_init(&chains_ht(chains), &chain_params);
mlx5_chains_get_chain_range(chains_priv),
mlx5_chains_get_prio_range(chains_priv));
err = rhashtable_init(&chains_ht(chains_priv), &chain_params);
if (err) if (err)
goto init_chains_ht_err; goto init_chains_ht_err;
err = rhashtable_init(&prios_ht(chains_priv), &prio_params); err = rhashtable_init(&prios_ht(chains), &prio_params);
if (err) if (err)
goto init_prios_ht_err; goto init_prios_ht_err;
mutex_init(&chains_lock(chains_priv)); mutex_init(&chains_lock(chains));
return chains_priv; return chains;
init_prios_ht_err: init_prios_ht_err:
rhashtable_destroy(&chains_ht(chains_priv)); rhashtable_destroy(&chains_ht(chains));
init_chains_ht_err: init_chains_ht_err:
kfree(chains_priv); kfree(chains);
return ERR_PTR(err); return ERR_PTR(err);
} }
...@@ -808,3 +799,9 @@ mlx5_chains_put_chain_mapping(struct mlx5_fs_chains *chains, u32 chain_mapping) ...@@ -808,3 +799,9 @@ mlx5_chains_put_chain_mapping(struct mlx5_fs_chains *chains, u32 chain_mapping)
return mapping_remove(ctx, chain_mapping); return mapping_remove(ctx, chain_mapping);
} }
void
mlx5_chains_print_info(struct mlx5_fs_chains *chains)
{
mlx5_core_dbg(chains->dev, "Flow table chains groups(%d)\n", chains->group_num);
}
...@@ -17,8 +17,9 @@ enum mlx5_chains_flags { ...@@ -17,8 +17,9 @@ enum mlx5_chains_flags {
struct mlx5_chains_attr { struct mlx5_chains_attr {
enum mlx5_flow_namespace_type ns; enum mlx5_flow_namespace_type ns;
int fs_base_prio;
int fs_base_level;
u32 flags; u32 flags;
u32 max_ft_sz;
u32 max_grp_num; u32 max_grp_num;
struct mlx5_flow_table *default_ft; struct mlx5_flow_table *default_ft;
struct mapping_ctx *mapping; struct mapping_ctx *mapping;
...@@ -68,6 +69,8 @@ void mlx5_chains_destroy(struct mlx5_fs_chains *chains); ...@@ -68,6 +69,8 @@ void mlx5_chains_destroy(struct mlx5_fs_chains *chains);
void void
mlx5_chains_set_end_ft(struct mlx5_fs_chains *chains, mlx5_chains_set_end_ft(struct mlx5_fs_chains *chains,
struct mlx5_flow_table *ft); struct mlx5_flow_table *ft);
void
mlx5_chains_print_info(struct mlx5_fs_chains *chains);
#else /* CONFIG_MLX5_CLS_ACT */ #else /* CONFIG_MLX5_CLS_ACT */
...@@ -89,7 +92,9 @@ static inline struct mlx5_fs_chains * ...@@ -89,7 +92,9 @@ static inline struct mlx5_fs_chains *
mlx5_chains_create(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr) mlx5_chains_create(struct mlx5_core_dev *dev, struct mlx5_chains_attr *attr)
{ return NULL; } { return NULL; }
static inline void static inline void
mlx5_chains_destroy(struct mlx5_fs_chains *chains) {}; mlx5_chains_destroy(struct mlx5_fs_chains *chains) {}
static inline void
mlx5_chains_print_info(struct mlx5_fs_chains *chains) {}
#endif /* CONFIG_MLX5_CLS_ACT */ #endif /* CONFIG_MLX5_CLS_ACT */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment