mlxsw: Implement periodic ERP rehash
Subsystems (11)
cover mlxsw: Implement periodic ERP rehash
Jiri says:
Currently, an ERP set is created for each region according to rules inserted and order of their insertion. However that might lead to suboptimal ERP sets and possible unnecessary spillage into C-TCAM. This patchset aims to fix this problem and introduces periodical checking of used ERP sets and in case a better ERP set is possible for the given set of rules, it rehashes the region to use the better ERP set.
Patch 1 prepares devlink params infra in order to fix the
init/fini sequences.
Patch 2 implements hints infra in objagg library. Patch 3 fixes a typo
Patch 4 adds number of root objects directly into objagg stats. Patches 5-7 do split of multiple structs in Spectrum TCAM code. Patch 8 introduces initial implementation of ERP rehash logic,
according to objagg hints.
Patch 9 adds hints priv passing trought the layers. Patch 10 adds multi field into PAGT reg. (new patch) Patch 11 implements actual region rules migration in TCAM code. Patch 12 adds a devlink param so user is able to control
rehash interval.
Patch 13 adds couple of tracepoints in order to track
rehash procedures.
Patch 14 adds a simple selftest to test region rehash.
Jiri Pirko (14):
devlink: publish params only after driver init is done
lib: objagg: implement optimization hints assembly and use hints for
object creation
lib: objagg: fix typo in objagg_stats_put() docstring
lib: objagg: add root count to stats
mlxsw: spectrum_acl: Split region struct into region and vregion
mlxsw: spectrum_acl: Split chunk struct into chunk and vchunk
mlxsw: spectrum_acl: Split entry struct into entry and ventry
mlxsw: spectrum_acl: Implement basic ERP rehash hits creation
mlxsw: spectrum_acl: Pass hints priv all the way to ERP code
mlxsw: reg: Add multi field to PAGT register
mlxsw: spectrum_acl: Implement region migration according to hints
mlxsw: spectrum: add "acl_region_rehash_interval" devlink param
mlxsw: spectrum_acl: Add couple of vregion rehash tracepoints
selftests: mlxsw: spectrum-2: Add simple delta rehash test
.../networking/devlink-params-mlxsw.txt | 8 + .../net/ethernet/broadcom/bnxt/bnxt_devlink.c | 3 + drivers/net/ethernet/mellanox/mlx4/main.c | 1 + drivers/net/ethernet/mellanox/mlxsw/core.c | 5 + drivers/net/ethernet/mellanox/mlxsw/core.h | 5 + drivers/net/ethernet/mellanox/mlxsw/reg.h | 11 +- .../net/ethernet/mellanox/mlxsw/spectrum.c | 69 +- .../net/ethernet/mellanox/mlxsw/spectrum.h | 7 +- .../mellanox/mlxsw/spectrum1_acl_tcam.c | 3 +- .../mellanox/mlxsw/spectrum2_acl_tcam.c | 20 +- .../ethernet/mellanox/mlxsw/spectrum_acl.c | 18 +- .../mellanox/mlxsw/spectrum_acl_atcam.c | 14 +- .../mellanox/mlxsw/spectrum_acl_erp.c | 120 ++- .../mellanox/mlxsw/spectrum_acl_tcam.c | 944 +++++++++++++----- .../mellanox/mlxsw/spectrum_acl_tcam.h | 24 +- include/linux/objagg.h | 21 +- include/net/devlink.h | 11 + include/trace/events/mlxsw.h | 61 ++ lib/objagg.c | 579 ++++++++++- lib/test_objagg.c | 194 +++- net/core/devlink.c | 48 +- .../drivers/net/mlxsw/spectrum-2/tc_flower.sh | 77 +- 22 files changed, 1943 insertions(+), 300 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/14 devlink: publish params only after driver init is done
From: Jiri Pirko <[email protected]>
Currently, user can do dump or get of param values right after the devlink params are registered. However the driver may not be initialized which is an issue. The same problem happens during notification upon param registration. Allow driver to publish devlink params whenever it is ready to handle get() ops. Note that this cannot be resolved by init reordering, as the "driverinit" params have to be available before the driver is initialized (it needs the param values there).
--- .../net/ethernet/broadcom/bnxt/bnxt_devlink.c | 3 ++ drivers/net/ethernet/mellanox/mlx4/main.c | 1 + drivers/net/ethernet/mellanox/mlxsw/core.c | 5 ++ include/net/devlink.h | 11 +++++ net/core/devlink.c | 48 ++++++++++++++++++- 5 files changed, 67 insertions(+), 1 deletion(-)
drivers/net/ethernet/broadcom/bnxt/bnxt_devlink.c +3 -0
@@ -258,6 +258,9 @@ int bnxt_dl_register(struct bnxt *bp)netdev_err (bp->dev,"devlink_port_params_register failed" ); goto err_dl_port_unreg; } + +devlink_params_publish (dl); +return 0 ; err_dl_port_unreg:
drivers/net/ethernet/mellanox/mlx4/main.c +1 -0
@@ -3981,6 +3981,7 @@ static int mlx4_init_one(struct pci_dev *pdev, const struct pci_device_id *id)if (ret) goto err_params_unregister; +devlink_params_publish (devlink);pci_save_state (pdev);return 0 ;
drivers/net/ethernet/mellanox/mlxsw/core.c +5 -0
@@ -1062,6 +1062,9 @@ __mlxsw_core_bus_device_register(const struct mlxsw_bus_info *mlxsw_bus_info, goto err_driver_init; } +if (mlxsw_driver->params_register && !reload) +devlink_params_publish (devlink); +return 0 ; err_driver_init:
@@ -1131,6 +1134,8 @@ void mlxsw_core_bus_device_unregister(struct mlxsw_core *mlxsw_core,return ; } +if (mlxsw_core->driver->params_unregister && !reload) +devlink_params_unpublish (devlink);if (mlxsw_core->driver->fini) mlxsw_core->driver->fini (mlxsw_core);mlxsw_thermal_fini (mlxsw_core->thermal);
include/net/devlink.h +11 -0
@@ -357,6 +357,7 @@ struct devlink_param_item {const struct devlink_param *param;union devlink_param_value driverinit_value;bool driverinit_value_valid; +bool published; };enum devlink_param_generic_id {
@@ -594,6 +595,8 @@ int devlink_params_register(struct devlink *devlink,void devlink_params_unregister (struct devlink *devlink,const struct devlink_param *params,size_t params_count); +void devlink_params_publish (struct devlink *devlink); +void devlink_params_unpublish (struct devlink *devlink);int devlink_port_params_register (struct devlink_port *devlink_port,const struct devlink_param *params,size_t params_count);
@@ -656,6 +659,14 @@ static inline void devlink_unregister(struct devlink *devlink) { } +static inline void devlink_params_publish (struct devlink *devlink) +{ +} + +static inline void devlink_params_unpublish (struct devlink *devlink) +{ +} +static inline void devlink_free (struct devlink *devlink) {kfree (devlink);
net/core/devlink.c +47 -1
78 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 2/14 lib: objagg: implement optimization hints assembly and use hints for object creation
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
Implement simple greedy algo to find more optimized root-delta tree for a given objagg instance. This "hints" can be used by a driver to:
1) check if the hints are better (driver's choice) than the original objagg tree. Driver does comparison of objagg stats and hints stats.
2) use the hints to create a new objagg instance which will construct the root-delta tree according to the passed hints. Currently, only a simple greedy algorithm is implemented. Basically it finds the roots according to the maximal possible user count including deltas.
--- .../mellanox/mlxsw/spectrum_acl_erp.c | 37 +- include/linux/objagg.h | 20 +- lib/objagg.c | 573 +++++++++++++++++- lib/test_objagg.c | 194 +++++- 4 files changed, 802 insertions(+), 22 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c +35 -2
@@ -1200,6 +1200,32 @@ mlxsw_sp_acl_erp_delta_fill(const struct mlxsw_sp_acl_erp_key *parent_key,return 0 ; } +static bool mlxsw_sp_acl_erp_delta_check (void *priv,const void *parent_obj, +const void *obj) +{ +const struct mlxsw_sp_acl_erp_key *parent_key = parent_obj; +const struct mlxsw_sp_acl_erp_key *key = obj; +u16 delta_start; +u8 delta_mask; +int err; + + err =mlxsw_sp_acl_erp_delta_fill (parent_key, key, + &delta_start, &delta_mask); +return err ? false : true; +} + +static int mlxsw_sp_acl_erp_hints_obj_cmp (const void *obj1,const void *obj2) +{ +const struct mlxsw_sp_acl_erp_key *key1 = obj1; +const struct mlxsw_sp_acl_erp_key *key2 = obj2; + +/* For hints purposes, two objects are considered equal +* in case the masks are the same. Does not matter what +* the "ctcam" value is. +*/ +return memcmp (key1->mask, key2->mask,sizeof (key1->mask)); +} +static void *mlxsw_sp_acl_erp_delta_create (void *priv,void *parent_obj,void *obj) {
@@ -1254,12 +1280,17 @@ static void mlxsw_sp_acl_erp_delta_destroy(void *priv, void *delta_priv)kfree (delta); } -static void *mlxsw_sp_acl_erp_root_create (void *priv,void *obj) +static void *mlxsw_sp_acl_erp_root_create (void *priv,void *obj, +unsigned int root_id) {struct mlxsw_sp_acl_atcam_region *aregion = priv;struct mlxsw_sp_acl_erp_table *erp_table = aregion->erp_table;struct mlxsw_sp_acl_erp_key *key = obj; +if (!key->ctcam && + root_id !=OBJAGG_OBJ_ROOT_ID_INVALID && + root_id >=MLXSW_SP_ACL_ERP_MAX_PER_REGION ) +return ERR_PTR (-ENOBUFS );return erp_table->ops->erp_create (erp_table, key); }
@@ -1273,6 +1304,8 @@ static void mlxsw_sp_acl_erp_root_destroy(void *priv, void *root_priv)static const struct objagg_ops mlxsw_sp_acl_erp_objagg_ops = { .obj_size =sizeof (struct mlxsw_sp_acl_erp_key ), + .delta_check = mlxsw_sp_acl_erp_delta_check, + .hints_obj_cmp = mlxsw_sp_acl_erp_hints_obj_cmp, .delta_create = mlxsw_sp_acl_erp_delta_create, .delta_destroy = mlxsw_sp_acl_erp_delta_destroy, .root_create = mlxsw_sp_acl_erp_root_create,
@@ -1290,7 +1323,7 @@ mlxsw_sp_acl_erp_table_create(struct mlxsw_sp_acl_atcam_region *aregion)return ERR_PTR (-ENOMEM ); erp_table->objagg =objagg_create (&mlxsw_sp_acl_erp_objagg_ops, - aregion); +NULL , aregion);if (IS_ERR (erp_table->objagg)) { err =PTR_ERR (erp_table->objagg); goto err_objagg_create;
include/linux/objagg.h +18 -2
@@ -6,14 +6,19 @@struct objagg_ops {size_t obj_size; +bool (*delta_check)(void *priv,const void *parent_obj, +const void *obj); +int (*hints_obj_cmp)(const void *obj1,const void *obj2);void * (*delta_create)(void *priv,void *parent_obj,void *obj);void (*delta_destroy)(void *priv,void *delta_priv); -void * (*root_create)(void *priv,void *obj); +void * (*root_create)(void *priv,void *obj,unsigned int root_id); +#define OBJAGG_OBJ_ROOT_ID_INVALID UINT_MAXvoid (*root_destroy)(void *priv,void *root_priv); };struct objagg ;struct objagg_obj ; +struct objagg_hints ;const void *objagg_obj_root_priv (const struct objagg_obj *objagg_obj);const void *objagg_obj_delta_priv (const struct objagg_obj *objagg_obj);
@@ -21,7 +26,8 @@ const void *objagg_obj_raw(const struct objagg_obj *objagg_obj);struct objagg_obj *objagg_obj_get (struct objagg *objagg,void *obj);void objagg_obj_put (struct objagg *objagg,struct objagg_obj *objagg_obj); -struct objagg *objagg_create (const struct objagg_ops *ops,void *priv); +struct objagg *objagg_create (const struct objagg_ops *ops, +struct objagg_hints *hints,void *priv);void objagg_destroy (struct objagg *objagg);struct objagg_obj_stats {
@@ -43,4 +49,14 @@ struct objagg_stats {const struct objagg_stats *objagg_stats_get (struct objagg *objagg);void objagg_stats_put (const struct objagg_stats *objagg_stats); +enum objagg_opt_algo_type { +OBJAGG_OPT_ALGO_SIMPLE_GREEDY , +}; + +struct objagg_hints *objagg_hints_get (struct objagg *objagg, +enum objagg_opt_algo_type opt_algo_type); +void objagg_hints_put (struct objagg_hints *objagg_hints); +const struct objagg_stats * +objagg_hints_stats_get (struct objagg_hints *objagg_hints); +#endif
lib/objagg.c +560 -13
686 lines not on this page · raw message
lib/test_objagg.c +189 -5
254 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 3/14 lib: objagg: fix typo in objagg_stats_put() docstring
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
--- lib/objagg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
lib/objagg.c +1 -1
@@ -634,7 +634,7 @@ const struct objagg_stats *objagg_stats_get(struct objagg *objagg)EXPORT_SYMBOL (objagg_stats_get);/** -* objagg_stats_puts - puts stats of the objagg instance +* objagg_stats_put - puts stats of the objagg instance * @objagg_stats: objagg instance stats * * Note: all locking must be provided by the caller.
Signature · 1 line
2.20.1
PATCH 4/14 lib: objagg: add root count to stats
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
Count number of roots and add it to stats. It is handy for the library user to have this stats available as it can act upon it without counting roots itself.
--- include/linux/objagg.h | 1 + lib/objagg.c | 4 ++++ 2 files changed, 5 insertions(+)
include/linux/objagg.h +1 -0
@@ -42,6 +42,7 @@ struct objagg_obj_stats_info { };struct objagg_stats { +unsigned int root_count;unsigned int stats_info_count;struct objagg_obj_stats_info stats_info[]; };
lib/objagg.c +4 -0
@@ -621,6 +621,8 @@ const struct objagg_stats *objagg_stats_get(struct objagg *objagg) objagg_stats->stats_info[i].objagg_obj = objagg_obj; objagg_stats->stats_info[i].is_root =objagg_obj_is_root (objagg_obj); +if (objagg_stats->stats_info[i].is_root) + objagg_stats->root_count++; i++; } objagg_stats->stats_info_count = i;
@@ -1031,6 +1033,8 @@ objagg_hints_stats_get(struct objagg_hints *objagg_hints)list_for_each_entry (hnode, &objagg_hints->node_list, list) {memcpy (&objagg_stats->stats_info[i], &hnode->stats_info,sizeof (objagg_stats->stats_info[0 ])); +if (objagg_stats->stats_info[i].is_root) + objagg_stats->root_count++; i++; } objagg_stats->stats_info_count = i;
Signature · 1 line
2.20.1
PATCH 5/14 mlxsw: spectrum_acl: Split region struct into region and vregion
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
Do the split of region struct so the new region struct is related to the actual HW region, whereas vregion struct is a SW abstration of that. This split prepares possibility for vregion to hold 2 HW regions which is needed for region ERP rehash flow.
--- .../mellanox/mlxsw/spectrum_acl_tcam.c | 299 +++++++++++------- .../mellanox/mlxsw/spectrum_acl_tcam.h | 5 +- 2 files changed, 180 insertions(+), 124 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +178 -121
@@ -153,7 +153,7 @@ struct mlxsw_sp_acl_tcam_pattern {struct mlxsw_sp_acl_tcam_group {struct mlxsw_sp_acl_tcam *tcam;u16 id; -struct list_head region_list; +struct list_head vregion_list;unsigned int region_count;struct rhashtable chunk_ht;struct mlxsw_sp_acl_tcam_group_ops *ops;
@@ -163,12 +163,20 @@ struct mlxsw_sp_acl_tcam_group {struct mlxsw_afk_element_usage tmplt_elusage; }; +struct mlxsw_sp_acl_tcam_vregion { +struct mlxsw_sp_acl_tcam_region *region; +struct list_head list;/* Member of a TCAM group */ +struct list_head chunk_list;/* List of chunks under this vregion */ +struct mlxsw_sp_acl_tcam_group *group; +struct mlxsw_afk_key_info *key_info; +}; +struct mlxsw_sp_acl_tcam_chunk { -struct list_head list;/* Member of a TCAM region */ +struct list_head list;/* Member of a TCAM vregion */ struct rhash_head ht_node;/* Member of a chunk HT */ -unsigned int priority;/* Priority within the region and group */ +unsigned int priority;/* Priority within the vregion and group */ struct mlxsw_sp_acl_tcam_group *group; -struct mlxsw_sp_acl_tcam_region *region; +struct mlxsw_sp_acl_tcam_vregion *vregion;unsigned int ref_count;unsigned long priv[0 ];/* priv has to be always the last item */
@@ -190,13 +198,14 @@ static const struct rhashtable_params mlxsw_sp_acl_tcam_chunk_ht_params = {static int mlxsw_sp_acl_tcam_group_update (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam_group *group) { -struct mlxsw_sp_acl_tcam_region *region; +struct mlxsw_sp_acl_tcam_vregion *vregion;char pagt_pl[MLXSW_REG_PAGT_LEN ];int acl_index =0 ;mlxsw_reg_pagt_pack (pagt_pl, group->id); -list_for_each_entry (region, &group->region_list, list) -mlxsw_reg_pagt_acl_id_pack (pagt_pl, acl_index++, region->id); +list_for_each_entry (vregion, &group->vregion_list, list) +mlxsw_reg_pagt_acl_id_pack (pagt_pl, acl_index++, + vregion->region->id);mlxsw_reg_pagt_size_set (pagt_pl, acl_index);return mlxsw_reg_write (mlxsw_sp->core,MLXSW_REG (pagt), pagt_pl); }
@@ -219,7 +228,7 @@ mlxsw_sp_acl_tcam_group_add(struct mlxsw_sp *mlxsw_sp,memcpy (&group->tmplt_elusage, tmplt_elusage,sizeof (group->tmplt_elusage)); } -INIT_LIST_HEAD (&group->region_list); +INIT_LIST_HEAD (&group->vregion_list); err =mlxsw_sp_acl_tcam_group_id_get (tcam, &group->id);if (err)return err;
@@ -243,7 +252,7 @@ static void mlxsw_sp_acl_tcam_group_del(struct mlxsw_sp *mlxsw_sp,rhashtable_destroy (&group->chunk_ht);mlxsw_sp_acl_tcam_group_id_put (tcam, group->id); -WARN_ON (!list_empty (&group->region_list)); +WARN_ON (!list_empty (&group->vregion_list)); } static int
@@ -283,140 +292,150 @@ mlxsw_sp_acl_tcam_group_id(struct mlxsw_sp_acl_tcam_group *group) }static unsigned int -mlxsw_sp_acl_tcam_region_prio (struct mlxsw_sp_acl_tcam_region *region) +mlxsw_sp_acl_tcam_vregion_prio (struct mlxsw_sp_acl_tcam_vregion *vregion) {struct mlxsw_sp_acl_tcam_chunk *chunk; -if (list_empty (®ion->chunk_list)) +if (list_empty (&vregion->chunk_list))return 0 ; -/* As a priority of a region, return priority of the first chunk */ - chunk =list_first_entry (®ion->chunk_list,typeof (*chunk), list); +/* As a priority of a vregion, return priority of the first chunk */ + chunk =list_first_entry (&vregion->chunk_list, +typeof (*chunk), list);return chunk->priority; }static unsigned int -mlxsw_sp_acl_tcam_region_max_prio (struct mlxsw_sp_acl_tcam_region *region) +mlxsw_sp_acl_tcam_vregion_max_prio (struct mlxsw_sp_acl_tcam_vregion *vregion) {struct mlxsw_sp_acl_tcam_chunk *chunk; -if (list_empty (®ion->chunk_list)) +if (list_empty (&vregion->chunk_list))return 0 ; - chunk =list_last_entry (®ion->chunk_list,typeof (*chunk), list); + chunk =list_last_entry (&vregion->chunk_list, +typeof (*chunk), list);return chunk->priority; } -static void -mlxsw_sp_acl_tcam_group_list_add (struct mlxsw_sp_acl_tcam_group *group, -struct mlxsw_sp_acl_tcam_region *region) +static int +mlxsw_sp_acl_tcam_group_region_attach (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_region *region) { -struct mlxsw_sp_acl_tcam_region *region2; -struct list_head *pos; +struct mlxsw_sp_acl_tcam_group *group = region->vregion->group; +int err; + +if (group->region_count == group->tcam->max_group_size) +return -ENOBUFS ; + + err =mlxsw_sp_acl_tcam_group_update (mlxsw_sp, group); +if (err) +return err; -/* Position the region inside the list according to priority */ -list_for_each (pos, &group->region_list) { - region2 =list_entry (pos,typeof (*region2), list); -if (mlxsw_sp_acl_tcam_region_prio (region2) > -mlxsw_sp_acl_tcam_region_prio (region)) -break ; - } -list_add_tail (®ion->list, pos); group->region_count++; +return 0 ; }static void -mlxsw_sp_acl_tcam_group_list_del (struct mlxsw_sp_acl_tcam_group *group, -struct mlxsw_sp_acl_tcam_region *region) +mlxsw_sp_acl_tcam_group_region_detach (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_region *region) { +struct mlxsw_sp_acl_tcam_group *group = region->vregion->group; + group->region_count--; -list_del (®ion->list); +mlxsw_sp_acl_tcam_group_update (mlxsw_sp, group); }static int -mlxsw_sp_acl_tcam_group_region_attach (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_group *group, -struct mlxsw_sp_acl_tcam_region *region) +mlxsw_sp_acl_tcam_group_vregion_attach (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_group *group, +struct mlxsw_sp_acl_tcam_vregion *vregion) { +struct mlxsw_sp_acl_tcam_vregion *vregion2; +struct list_head *pos;int err; -if (group->region_count == group->tcam->max_group_size) -return -ENOBUFS ; - -mlxsw_sp_acl_tcam_group_list_add (group, region); +/* Position the vregion inside the list according to priority */ +list_for_each (pos, &group->vregion_list) { + vregion2 =list_entry (pos,typeof (*vregion2), list); +if (mlxsw_sp_acl_tcam_vregion_prio (vregion2) > +mlxsw_sp_acl_tcam_vregion_prio (vregion)) +break ; + } +list_add_tail (&vregion->list, pos); + vregion->group = group; - err =mlxsw_sp_acl_tcam_group_update (mlxsw_sp, group); + err =mlxsw_sp_acl_tcam_group_region_attach (mlxsw_sp, vregion->region);if (err) - goto err_group_update; - region->group = group; + goto err_region_attach;return 0 ; -err_group_update: -mlxsw_sp_acl_tcam_group_list_del (group, region); -mlxsw_sp_acl_tcam_group_update (mlxsw_sp, group); +err_region_attach: +list_del (&vregion->list);return err; }static void -mlxsw_sp_acl_tcam_group_region_detach (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_region *region) +mlxsw_sp_acl_tcam_group_vregion_detach (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_vregion *vregion) { -struct mlxsw_sp_acl_tcam_group *group = region->group; - -mlxsw_sp_acl_tcam_group_list_del (group, region); -mlxsw_sp_acl_tcam_group_update (mlxsw_sp, group); +list_del (&vregion->list); +mlxsw_sp_acl_tcam_group_region_detach (mlxsw_sp, vregion->region); } -static struct mlxsw_sp_acl_tcam_region * -mlxsw_sp_acl_tcam_group_region_find (struct mlxsw_sp_acl_tcam_group *group, -unsigned int priority, -struct mlxsw_afk_element_usage *elusage, -bool *p_need_split) +static struct mlxsw_sp_acl_tcam_vregion * +mlxsw_sp_acl_tcam_group_vregion_find (struct mlxsw_sp_acl_tcam_group *group, +unsigned int priority, +struct mlxsw_afk_element_usage *elusage, +bool *p_need_split) { -struct mlxsw_sp_acl_tcam_region *region, *region2; +struct mlxsw_sp_acl_tcam_vregion *vregion, *vregion2;struct list_head *pos;bool issubset; -list_for_each (pos, &group->region_list) { - region =list_entry (pos,typeof (*region), list); +list_for_each (pos, &group->vregion_list) { + vregion =list_entry (pos,typeof (*vregion), list);/* First, check if the requested priority does not rather belong -* under some of the next regions. +* under some of the next vregions. */ -if (pos->next != &group->region_list) {/* not last */ - region2 =list_entry (pos->next,typeof (*region2), list); -if (priority >=mlxsw_sp_acl_tcam_region_prio (region2)) +if (pos->next != &group->vregion_list) {/* not last */ + vregion2 =list_entry (pos->next,typeof (*vregion2), + list); +if (priority >= +mlxsw_sp_acl_tcam_vregion_prio (vregion2))continue ; } - issubset =mlxsw_afk_key_info_subset (region->key_info, elusage); + issubset =mlxsw_afk_key_info_subset (vregion->key_info, + elusage);/* If requested element usage would not fit and the priority -* is lower than the currently inspected region we cannot -* use this region, so return NULL to indicate new region has +* is lower than the currently inspected vregion we cannot +* use this region, so return NULL to indicate new vregion has * to be created. */ if (!issubset && - priority <mlxsw_sp_acl_tcam_region_prio (region)) + priority <mlxsw_sp_acl_tcam_vregion_prio (vregion))return NULL ;/* If requested element usage would not fit and the priority -* is higher than the currently inspected region we cannot -* use this region. There is still some hope that the next -* region would be the fit. So let it be processed and +* is higher than the currently inspected vregion we cannot +* use this vregion. There is still some hope that the next +* vregion would be the fit. So let it be processed and * eventually break at the check right above this. */ if (!issubset && - priority >mlxsw_sp_acl_tcam_region_max_prio (region)) + priority >mlxsw_sp_acl_tcam_vregion_max_prio (vregion))continue ; -/* Indicate if the region needs to be split in order to add +/* Indicate if the vregion needs to be split in order to add * the requested priority. Split is needed when requested -* element usage won't fit into the found region. +* element usage won't fit into the found vregion. */ *p_need_split = !issubset; -return region; +return vregion; } -return NULL ;/* New region has to be created. */ +return NULL ;/* New vregion has to be created. */ } static void
@@ -511,24 +530,18 @@ mlxsw_sp_acl_tcam_region_disable(struct mlxsw_sp *mlxsw_sp,static struct mlxsw_sp_acl_tcam_region *mlxsw_sp_acl_tcam_region_create (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam *tcam, -struct mlxsw_afk_element_usage *elusage) +struct mlxsw_sp_acl_tcam_vregion *vregion) {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; -struct mlxsw_afk *afk =mlxsw_sp_acl_afk (mlxsw_sp->acl);struct mlxsw_sp_acl_tcam_region *region;int err; region =kzalloc (sizeof (*region) + ops->region_priv_size,GFP_KERNEL );if (!region)return ERR_PTR (-ENOMEM ); -INIT_LIST_HEAD (®ion->chunk_list); region->mlxsw_sp = mlxsw_sp; - - region->key_info =mlxsw_afk_key_info_get (afk, elusage); -if (IS_ERR (region->key_info)) { - err =PTR_ERR (region->key_info); - goto err_key_info_get; - } + region->vregion = vregion; + region->key_info = vregion->key_info; err =mlxsw_sp_acl_tcam_region_id_get (tcam, ®ion->id);if (err)
@@ -561,8 +574,6 @@ mlxsw_sp_acl_tcam_region_create(struct mlxsw_sp *mlxsw_sp, err_tcam_region_associate:mlxsw_sp_acl_tcam_region_id_put (tcam, region->id); err_region_id_get: -mlxsw_afk_key_info_put (region->key_info); -err_key_info_get:kfree (region);return ERR_PTR (err); }
@@ -576,11 +587,56 @@ mlxsw_sp_acl_tcam_region_destroy(struct mlxsw_sp *mlxsw_sp, ops->region_fini (mlxsw_sp, region->priv);mlxsw_sp_acl_tcam_region_disable (mlxsw_sp, region);mlxsw_sp_acl_tcam_region_free (mlxsw_sp, region); -mlxsw_sp_acl_tcam_region_id_put (region->group->tcam, region->id); -mlxsw_afk_key_info_put (region->key_info); +mlxsw_sp_acl_tcam_region_id_put (region->vregion->group->tcam, + region->id);kfree (region); } +static struct mlxsw_sp_acl_tcam_vregion * +mlxsw_sp_acl_tcam_vregion_create (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam *tcam, +struct mlxsw_afk_element_usage *elusage) +{ +struct mlxsw_afk *afk =mlxsw_sp_acl_afk (mlxsw_sp->acl); +struct mlxsw_sp_acl_tcam_vregion *vregion; +int err; + + vregion =kzalloc (sizeof (*vregion),GFP_KERNEL ); +if (!vregion) +return ERR_PTR (-ENOMEM ); +INIT_LIST_HEAD (&vregion->chunk_list); + + vregion->key_info =mlxsw_afk_key_info_get (afk, elusage); +if (IS_ERR (vregion->key_info)) { + err =PTR_ERR (vregion->key_info); + goto err_key_info_get; + } + + vregion->region =mlxsw_sp_acl_tcam_region_create (mlxsw_sp, tcam, + vregion); +if (IS_ERR (vregion->region)) { + err =PTR_ERR (vregion->region); + goto err_region_create; + } + +return vregion; + +err_region_create: +mlxsw_afk_key_info_put (vregion->key_info); +err_key_info_get: +kfree (vregion); +return ERR_PTR (err); +} + +static void +mlxsw_sp_acl_tcam_vregion_destroy (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_vregion *vregion) +{ +mlxsw_sp_acl_tcam_region_destroy (mlxsw_sp, vregion->region); +mlxsw_afk_key_info_put (vregion->key_info); +kfree (vregion); +} + static int mlxsw_sp_acl_tcam_chunk_assoc(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_group *group,
@@ -588,48 +644,49 @@ mlxsw_sp_acl_tcam_chunk_assoc(struct mlxsw_sp *mlxsw_sp,struct mlxsw_afk_element_usage *elusage, struct mlxsw_sp_acl_tcam_chunk *chunk) { - struct mlxsw_sp_acl_tcam_region *region; -bool region_created = false; + struct mlxsw_sp_acl_tcam_vregion *vregion; +bool vregion_created = false;bool need_split;int err; - region =mlxsw_sp_acl_tcam_group_region_find (group, priority, elusage, - &need_split); -if (region && need_split) { + vregion =mlxsw_sp_acl_tcam_group_vregion_find (group, priority, elusage, + &need_split); +if (vregion && need_split) {/* According to priority, the chunk should belong to an -* existing region. However, this chunk needs elements -* that region does not contain. We need to split the existing -* region into two and create a new region for this chunk +* existing vregion. However, this chunk needs elements +* that vregion does not contain. We need to split the existing +* vregion into two and create a new vregion for this chunk * in between. This is not supported now. */ return -EOPNOTSUPP ; } -if (!region) { -struct mlxsw_afk_element_usage region_elusage; +if (!vregion) { +struct mlxsw_afk_element_usage vregion_elusage;mlxsw_sp_acl_tcam_group_use_patterns (group, elusage, - ®ion_elusage); - region =mlxsw_sp_acl_tcam_region_create (mlxsw_sp, group->tcam, - ®ion_elusage); -if (IS_ERR (region)) -return PTR_ERR (region); - region_created = true; + &vregion_elusage); + vregion =mlxsw_sp_acl_tcam_vregion_create (mlxsw_sp, + group->tcam, + &vregion_elusage); +if (IS_ERR (vregion)) +return PTR_ERR (vregion); + vregion_created = true; } - chunk->region = region; -list_add_tail (&chunk->list, ®ion->chunk_list); + chunk->vregion = vregion; +list_add_tail (&chunk->list, &vregion->chunk_list); -if (!region_created) +if (!vregion_created)return 0 ; - err =mlxsw_sp_acl_tcam_group_region_attach (mlxsw_sp, group, region); + err =mlxsw_sp_acl_tcam_group_vregion_attach (mlxsw_sp, group, vregion);if (err) - goto err_group_region_attach; + goto err_group_vregion_attach;return 0 ; -err_group_region_attach: -mlxsw_sp_acl_tcam_region_destroy (mlxsw_sp, region); +err_group_vregion_attach: +mlxsw_sp_acl_tcam_vregion_destroy (mlxsw_sp, vregion);return err; }
@@ -637,12 +694,12 @@ static void mlxsw_sp_acl_tcam_chunk_deassoc(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_chunk *chunk) { - struct mlxsw_sp_acl_tcam_region *region = chunk->region; + struct mlxsw_sp_acl_tcam_vregion *vregion = chunk->vregion;list_del (&chunk->list); -if (list_empty (®ion->chunk_list)) { -mlxsw_sp_acl_tcam_group_region_detach (mlxsw_sp, region); -mlxsw_sp_acl_tcam_region_destroy (mlxsw_sp, region); +if (list_empty (&vregion->chunk_list)) { +mlxsw_sp_acl_tcam_group_vregion_detach (mlxsw_sp, vregion); +mlxsw_sp_acl_tcam_vregion_destroy (mlxsw_sp, vregion); } }
@@ -671,7 +728,7 @@ mlxsw_sp_acl_tcam_chunk_create(struct mlxsw_sp *mlxsw_sp,if (err) goto err_chunk_assoc; - ops->chunk_init (chunk->region->priv, chunk->priv, priority); + ops->chunk_init (chunk->vregion->region->priv, chunk->priv, priority); err =rhashtable_insert_fast (&group->chunk_ht, &chunk->ht_node, mlxsw_sp_acl_tcam_chunk_ht_params);
@@ -713,7 +770,7 @@ mlxsw_sp_acl_tcam_chunk_get(struct mlxsw_sp *mlxsw_sp, chunk =rhashtable_lookup_fast (&group->chunk_ht, &priority, mlxsw_sp_acl_tcam_chunk_ht_params);if (chunk) { -if (WARN_ON (!mlxsw_afk_key_info_subset (chunk->region->key_info, +if (WARN_ON (!mlxsw_afk_key_info_subset (chunk->vregion->key_info, elusage)))return ERR_PTR (-EINVAL ); chunk->ref_count++;
@@ -753,7 +810,7 @@ static int mlxsw_sp_acl_tcam_entry_add(struct mlxsw_sp *mlxsw_sp,if (IS_ERR (chunk))return PTR_ERR (chunk); - region = chunk->region; + region = chunk->vregion->region; err = ops->entry_add (mlxsw_sp, region->priv, chunk->priv, entry->priv, rulei);
@@ -773,7 +830,7 @@ static void mlxsw_sp_acl_tcam_entry_del(struct mlxsw_sp *mlxsw_sp, {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;struct mlxsw_sp_acl_tcam_chunk *chunk = entry->chunk; -struct mlxsw_sp_acl_tcam_region *region = chunk->region; +struct mlxsw_sp_acl_tcam_region *region = chunk->vregion->region; ops->entry_del (mlxsw_sp, region->priv, chunk->priv, entry->priv);mlxsw_sp_acl_tcam_chunk_put (mlxsw_sp, chunk);
@@ -786,7 +843,7 @@ mlxsw_sp_acl_tcam_entry_action_replace(struct mlxsw_sp *mlxsw_sp, {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;struct mlxsw_sp_acl_tcam_chunk *chunk = entry->chunk; -struct mlxsw_sp_acl_tcam_region *region = chunk->region; +struct mlxsw_sp_acl_tcam_region *region = chunk->vregion->region;return ops->entry_action_replace (mlxsw_sp, region->priv, entry->priv, rulei);
@@ -799,7 +856,7 @@ mlxsw_sp_acl_tcam_entry_activity_get(struct mlxsw_sp *mlxsw_sp, {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;struct mlxsw_sp_acl_tcam_chunk *chunk = entry->chunk; -struct mlxsw_sp_acl_tcam_region *region = chunk->region; +struct mlxsw_sp_acl_tcam_region *region = chunk->vregion->region;return ops->entry_activity_get (mlxsw_sp, region->priv, entry->priv, activity);
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h +2 -3
@@ -67,11 +67,10 @@ mlxsw_sp_acl_tcam_profile_ops(struct mlxsw_sp *mlxsw_sp, (MLXSW_REG_PTCEX_FLEX_KEY_BLOCKS_LEN * BITS_PER_BYTE)struct mlxsw_sp_acl_tcam_group ; +struct mlxsw_sp_acl_tcam_vregion ;struct mlxsw_sp_acl_tcam_region { -struct list_head list;/* Member of a TCAM group */ -struct list_head chunk_list;/* List of chunks under this region */ -struct mlxsw_sp_acl_tcam_group *group; +struct mlxsw_sp_acl_tcam_vregion *vregion;enum mlxsw_reg_ptar_key_type key_type;u16 id;/* ACL ID and region ID - they are same */ char tcam_region_info[MLXSW_REG_PXXX_TCAM_REGION_INFO_LEN ];
Signature · 1 line
2.20.1
PATCH 6/14 mlxsw: spectrum_acl: Split chunk struct into chunk and vchunk
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
Do the split of chunk struct so the new chunk struct is related to the actual HW chunk (differs between Spectrum and Spectrum-2), whereas vchunk struct is a SW abstraction of that. This split prepares possibility for vchunk to hold 2 HW chunks which is needed for region ERP rehash flow.
--- .../mellanox/mlxsw/spectrum_acl_tcam.c | 256 ++++++++++-------- 1 file changed, 150 insertions(+), 106 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +150 -106
@@ -155,7 +155,7 @@ struct mlxsw_sp_acl_tcam_group {u16 id;struct list_head vregion_list;unsigned int region_count; -struct rhashtable chunk_ht; +struct rhashtable vchunk_ht;struct mlxsw_sp_acl_tcam_group_ops *ops;const struct mlxsw_sp_acl_tcam_pattern *patterns;unsigned int patterns_count;
@@ -166,32 +166,39 @@ struct mlxsw_sp_acl_tcam_group {struct mlxsw_sp_acl_tcam_vregion {struct mlxsw_sp_acl_tcam_region *region;struct list_head list;/* Member of a TCAM group */ -struct list_head chunk_list;/* List of chunks under this vregion */ +struct list_head vchunk_list;/* List of vchunks under this vregion */ struct mlxsw_sp_acl_tcam_group *group;struct mlxsw_afk_key_info *key_info; }; +struct mlxsw_sp_acl_tcam_vchunk ; +struct mlxsw_sp_acl_tcam_chunk { +struct mlxsw_sp_acl_tcam_vchunk *vchunk; +unsigned long priv[0 ]; +/* priv has to be always the last item */ +}; + +struct mlxsw_sp_acl_tcam_vchunk { +struct mlxsw_sp_acl_tcam_chunk *chunk;struct list_head list;/* Member of a TCAM vregion */ struct rhash_head ht_node;/* Member of a chunk HT */ unsigned int priority;/* Priority within the vregion and group */ struct mlxsw_sp_acl_tcam_group *group;struct mlxsw_sp_acl_tcam_vregion *vregion;unsigned int ref_count; -unsigned long priv[0 ]; -/* priv has to be always the last item */ };struct mlxsw_sp_acl_tcam_entry { -struct mlxsw_sp_acl_tcam_chunk *chunk; +struct mlxsw_sp_acl_tcam_vchunk *vchunk;unsigned long priv[0 ];/* priv has to be always the last item */ }; -static const struct rhashtable_params mlxsw_sp_acl_tcam_chunk_ht_params = { +static const struct rhashtable_params mlxsw_sp_acl_tcam_vchunk_ht_params = { .key_len =sizeof (unsigned int ), - .key_offset = offsetof(struct mlxsw_sp_acl_tcam_chunk , priority), - .head_offset = offsetof(struct mlxsw_sp_acl_tcam_chunk , ht_node), + .key_offset = offsetof(struct mlxsw_sp_acl_tcam_vchunk , priority), + .head_offset = offsetof(struct mlxsw_sp_acl_tcam_vchunk , ht_node), .automatic_shrinking = true, };
@@ -233,8 +240,8 @@ mlxsw_sp_acl_tcam_group_add(struct mlxsw_sp *mlxsw_sp,if (err)return err; - err =rhashtable_init (&group->chunk_ht, - &mlxsw_sp_acl_tcam_chunk_ht_params); + err =rhashtable_init (&group->vchunk_ht, + &mlxsw_sp_acl_tcam_vchunk_ht_params);if (err) goto err_rhashtable_init;
@@ -250,7 +257,7 @@ static void mlxsw_sp_acl_tcam_group_del(struct mlxsw_sp *mlxsw_sp, {struct mlxsw_sp_acl_tcam *tcam = group->tcam; -rhashtable_destroy (&group->chunk_ht); +rhashtable_destroy (&group->vchunk_ht);mlxsw_sp_acl_tcam_group_id_put (tcam, group->id);WARN_ON (!list_empty (&group->vregion_list)); }
@@ -294,26 +301,26 @@ mlxsw_sp_acl_tcam_group_id(struct mlxsw_sp_acl_tcam_group *group)static unsigned int mlxsw_sp_acl_tcam_vregion_prio (struct mlxsw_sp_acl_tcam_vregion *vregion) { -struct mlxsw_sp_acl_tcam_chunk *chunk; +struct mlxsw_sp_acl_tcam_vchunk *vchunk; -if (list_empty (&vregion->chunk_list)) +if (list_empty (&vregion->vchunk_list))return 0 ; -/* As a priority of a vregion, return priority of the first chunk */ - chunk =list_first_entry (&vregion->chunk_list, -typeof (*chunk), list); -return chunk->priority; +/* As a priority of a vregion, return priority of the first vchunk */ + vchunk =list_first_entry (&vregion->vchunk_list, +typeof (*vchunk), list); +return vchunk->priority; }static unsigned int mlxsw_sp_acl_tcam_vregion_max_prio (struct mlxsw_sp_acl_tcam_vregion *vregion) { -struct mlxsw_sp_acl_tcam_chunk *chunk; +struct mlxsw_sp_acl_tcam_vchunk *vchunk; -if (list_empty (&vregion->chunk_list)) +if (list_empty (&vregion->vchunk_list))return 0 ; - chunk =list_last_entry (&vregion->chunk_list, -typeof (*chunk), list); -return chunk->priority; + vchunk =list_last_entry (&vregion->vchunk_list, +typeof (*vchunk), list); +return vchunk->priority; } static int
@@ -604,7 +611,7 @@ mlxsw_sp_acl_tcam_vregion_create(struct mlxsw_sp *mlxsw_sp, vregion =kzalloc (sizeof (*vregion),GFP_KERNEL );if (!vregion)return ERR_PTR (-ENOMEM ); -INIT_LIST_HEAD (&vregion->chunk_list); +INIT_LIST_HEAD (&vregion->vchunk_list); vregion->key_info =mlxsw_afk_key_info_get (afk, elusage);if (IS_ERR (vregion->key_info)) {
@@ -638,11 +645,11 @@ mlxsw_sp_acl_tcam_vregion_destroy(struct mlxsw_sp *mlxsw_sp, }static int -mlxsw_sp_acl_tcam_chunk_assoc (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_group *group, -unsigned int priority, -struct mlxsw_afk_element_usage *elusage, -struct mlxsw_sp_acl_tcam_chunk *chunk) +mlxsw_sp_acl_tcam_vchunk_assoc (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_group *group, +unsigned int priority, +struct mlxsw_afk_element_usage *elusage, +struct mlxsw_sp_acl_tcam_vchunk *vchunk) {struct mlxsw_sp_acl_tcam_vregion *vregion;bool vregion_created = false;
@@ -652,10 +659,10 @@ mlxsw_sp_acl_tcam_chunk_assoc(struct mlxsw_sp *mlxsw_sp, vregion =mlxsw_sp_acl_tcam_group_vregion_find (group, priority, elusage, &need_split);if (vregion && need_split) { -/* According to priority, the chunk should belong to an -* existing vregion. However, this chunk needs elements +/* According to priority, the vchunk should belong to an +* existing vregion. However, this vchunk needs elements * that vregion does not contain. We need to split the existing -* vregion into two and create a new vregion for this chunk +* vregion into two and create a new vregion for this vchunk * in between. This is not supported now. */ return -EOPNOTSUPP ;
@@ -673,8 +680,8 @@ mlxsw_sp_acl_tcam_chunk_assoc(struct mlxsw_sp *mlxsw_sp, vregion_created = true; } - chunk->vregion = vregion; -list_add_tail (&chunk->list, &vregion->chunk_list); + vchunk->vregion = vregion; +list_add_tail (&vchunk->list, &vregion->vchunk_list);if (!vregion_created)return 0 ;
@@ -691,13 +698,13 @@ mlxsw_sp_acl_tcam_chunk_assoc(struct mlxsw_sp *mlxsw_sp, }static void -mlxsw_sp_acl_tcam_chunk_deassoc (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_chunk *chunk) +mlxsw_sp_acl_tcam_vchunk_deassoc (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_vchunk *vchunk) { -struct mlxsw_sp_acl_tcam_vregion *vregion = chunk->vregion; +struct mlxsw_sp_acl_tcam_vregion *vregion = vchunk->vregion; -list_del (&chunk->list); -if (list_empty (&vregion->chunk_list)) { +list_del (&vchunk->list); +if (list_empty (&vregion->vchunk_list)) {mlxsw_sp_acl_tcam_group_vregion_detach (mlxsw_sp, vregion);mlxsw_sp_acl_tcam_vregion_destroy (mlxsw_sp, vregion); }
@@ -705,87 +712,120 @@ mlxsw_sp_acl_tcam_chunk_deassoc(struct mlxsw_sp *mlxsw_sp,static struct mlxsw_sp_acl_tcam_chunk *mlxsw_sp_acl_tcam_chunk_create (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_group *group, -unsigned int priority, -struct mlxsw_afk_element_usage *elusage) +struct mlxsw_sp_acl_tcam_vchunk *vchunk, +struct mlxsw_sp_acl_tcam_region *region) {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;struct mlxsw_sp_acl_tcam_chunk *chunk; + + chunk =kzalloc (sizeof (*chunk) + ops->chunk_priv_size,GFP_KERNEL ); +if (!chunk) +return ERR_PTR (-ENOMEM ); + chunk->vchunk = vchunk; + + ops->chunk_init (region->priv, chunk->priv, vchunk->priority); +return chunk; +} + +static void +mlxsw_sp_acl_tcam_chunk_destroy (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_chunk *chunk) +{ +const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; + + ops->chunk_fini (chunk->priv); +kfree (chunk); +} + +static struct mlxsw_sp_acl_tcam_vchunk * +mlxsw_sp_acl_tcam_vchunk_create (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_group *group, +unsigned int priority, +struct mlxsw_afk_element_usage *elusage) +{ +struct mlxsw_sp_acl_tcam_vchunk *vchunk;int err;if (priority ==MLXSW_SP_ACL_TCAM_CATCHALL_PRIO )return ERR_PTR (-EINVAL ); - chunk =kzalloc (sizeof (*chunk) + ops->chunk_priv_size,GFP_KERNEL ); -if (!chunk) + vchunk =kzalloc (sizeof (*vchunk),GFP_KERNEL ); +if (!vchunk)return ERR_PTR (-ENOMEM ); - chunk->priority = priority; - chunk->group = group; - chunk->ref_count =1 ; + vchunk->priority = priority; + vchunk->group = group; + vchunk->ref_count =1 ; - err =mlxsw_sp_acl_tcam_chunk_assoc (mlxsw_sp, group, priority, - elusage, chunk); + err =mlxsw_sp_acl_tcam_vchunk_assoc (mlxsw_sp, group, priority, + elusage, vchunk);if (err) - goto err_chunk_assoc; + goto err_vchunk_assoc; - ops->chunk_init (chunk->vregion->region->priv, chunk->priv, priority); - - err =rhashtable_insert_fast (&group->chunk_ht, &chunk->ht_node, - mlxsw_sp_acl_tcam_chunk_ht_params); + err =rhashtable_insert_fast (&group->vchunk_ht, &vchunk->ht_node, + mlxsw_sp_acl_tcam_vchunk_ht_params);if (err) goto err_rhashtable_insert; -return chunk; + vchunk->chunk =mlxsw_sp_acl_tcam_chunk_create (mlxsw_sp, vchunk, + vchunk->vregion->region); +if (IS_ERR (vchunk->chunk)) { + err =PTR_ERR (vchunk->chunk); + goto err_chunk_create; + } + +return vchunk; +err_chunk_create: +rhashtable_remove_fast (&group->vchunk_ht, &vchunk->ht_node, + mlxsw_sp_acl_tcam_vchunk_ht_params); err_rhashtable_insert: - ops->chunk_fini (chunk->priv); -mlxsw_sp_acl_tcam_chunk_deassoc (mlxsw_sp, chunk); -err_chunk_assoc: -kfree (chunk); +mlxsw_sp_acl_tcam_vchunk_deassoc (mlxsw_sp, vchunk); +err_vchunk_assoc: +kfree (vchunk);return ERR_PTR (err); }static void -mlxsw_sp_acl_tcam_chunk_destroy (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_chunk *chunk) +mlxsw_sp_acl_tcam_vchunk_destroy (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_vchunk *vchunk) { -const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; -struct mlxsw_sp_acl_tcam_group *group = chunk->group; +struct mlxsw_sp_acl_tcam_group *group = vchunk->group; -rhashtable_remove_fast (&group->chunk_ht, &chunk->ht_node, - mlxsw_sp_acl_tcam_chunk_ht_params); - ops->chunk_fini (chunk->priv); -mlxsw_sp_acl_tcam_chunk_deassoc (mlxsw_sp, chunk); -kfree (chunk); +mlxsw_sp_acl_tcam_chunk_destroy (mlxsw_sp, vchunk->chunk); +rhashtable_remove_fast (&group->vchunk_ht, &vchunk->ht_node, + mlxsw_sp_acl_tcam_vchunk_ht_params); +mlxsw_sp_acl_tcam_vchunk_deassoc (mlxsw_sp, vchunk); +kfree (vchunk); } -static struct mlxsw_sp_acl_tcam_chunk * -mlxsw_sp_acl_tcam_chunk_get (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_group *group, -unsigned int priority, -struct mlxsw_afk_element_usage *elusage) +static struct mlxsw_sp_acl_tcam_vchunk * +mlxsw_sp_acl_tcam_vchunk_get (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_group *group, +unsigned int priority, +struct mlxsw_afk_element_usage *elusage) { -struct mlxsw_sp_acl_tcam_chunk *chunk; +struct mlxsw_sp_acl_tcam_vchunk *vchunk; - chunk =rhashtable_lookup_fast (&group->chunk_ht, &priority, - mlxsw_sp_acl_tcam_chunk_ht_params); -if (chunk) { -if (WARN_ON (!mlxsw_afk_key_info_subset (chunk->vregion->key_info, + vchunk =rhashtable_lookup_fast (&group->vchunk_ht, &priority, + mlxsw_sp_acl_tcam_vchunk_ht_params); +if (vchunk) { +if (WARN_ON (!mlxsw_afk_key_info_subset (vchunk->vregion->key_info, elusage)))return ERR_PTR (-EINVAL ); - chunk->ref_count++; -return chunk; + vchunk->ref_count++; +return vchunk; } -return mlxsw_sp_acl_tcam_chunk_create (mlxsw_sp, group, - priority, elusage); +return mlxsw_sp_acl_tcam_vchunk_create (mlxsw_sp, group, + priority, elusage); } -static void mlxsw_sp_acl_tcam_chunk_put (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_chunk *chunk) +static void +mlxsw_sp_acl_tcam_vchunk_put (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_vchunk *vchunk) { -if (--chunk->ref_count) +if (--vchunk->ref_count)return ; -mlxsw_sp_acl_tcam_chunk_destroy (mlxsw_sp, chunk); +mlxsw_sp_acl_tcam_vchunk_destroy (mlxsw_sp, vchunk); }static size_t mlxsw_sp_acl_tcam_entry_priv_size (struct mlxsw_sp *mlxsw_sp)
@@ -801,27 +841,29 @@ static int mlxsw_sp_acl_tcam_entry_add(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_rule_info *rulei) {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; -struct mlxsw_sp_acl_tcam_chunk *chunk; +struct mlxsw_sp_acl_tcam_vchunk *vchunk;struct mlxsw_sp_acl_tcam_region *region; +struct mlxsw_sp_acl_tcam_chunk *chunk;int err; - chunk =mlxsw_sp_acl_tcam_chunk_get (mlxsw_sp, group, rulei->priority, - &rulei->values.elusage); -if (IS_ERR (chunk)) -return PTR_ERR (chunk); + vchunk =mlxsw_sp_acl_tcam_vchunk_get (mlxsw_sp, group, rulei->priority, + &rulei->values.elusage); +if (IS_ERR (vchunk)) +return PTR_ERR (vchunk); - region = chunk->vregion->region; + chunk = vchunk->chunk; + region = vchunk->vregion->region; err = ops->entry_add (mlxsw_sp, region->priv, chunk->priv, entry->priv, rulei);if (err) goto err_entry_add; - entry->chunk = chunk; + entry->vchunk = vchunk;return 0 ; err_entry_add: -mlxsw_sp_acl_tcam_chunk_put (mlxsw_sp, chunk); +mlxsw_sp_acl_tcam_vchunk_put (mlxsw_sp, vchunk);return err; }
@@ -829,11 +871,12 @@ static void mlxsw_sp_acl_tcam_entry_del(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_entry *entry) {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; -struct mlxsw_sp_acl_tcam_chunk *chunk = entry->chunk; -struct mlxsw_sp_acl_tcam_region *region = chunk->vregion->region; +struct mlxsw_sp_acl_tcam_vchunk *vchunk = entry->vchunk; +struct mlxsw_sp_acl_tcam_chunk *chunk = vchunk->chunk; +struct mlxsw_sp_acl_tcam_region *region = vchunk->vregion->region; ops->entry_del (mlxsw_sp, region->priv, chunk->priv, entry->priv); -mlxsw_sp_acl_tcam_chunk_put (mlxsw_sp, chunk); +mlxsw_sp_acl_tcam_vchunk_put (mlxsw_sp, vchunk); } static int
@@ -842,8 +885,8 @@ mlxsw_sp_acl_tcam_entry_action_replace(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_rule_info *rulei) {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; -struct mlxsw_sp_acl_tcam_chunk *chunk = entry->chunk; -struct mlxsw_sp_acl_tcam_region *region = chunk->vregion->region; +struct mlxsw_sp_acl_tcam_vchunk *vchunk = entry->vchunk; +struct mlxsw_sp_acl_tcam_region *region = vchunk->vregion->region;return ops->entry_action_replace (mlxsw_sp, region->priv, entry->priv, rulei);
@@ -855,8 +898,8 @@ mlxsw_sp_acl_tcam_entry_activity_get(struct mlxsw_sp *mlxsw_sp, bool *activity) {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; -struct mlxsw_sp_acl_tcam_chunk *chunk = entry->chunk; -struct mlxsw_sp_acl_tcam_region *region = chunk->vregion->region; +struct mlxsw_sp_acl_tcam_vchunk *vchunk = entry->vchunk; +struct mlxsw_sp_acl_tcam_region *region = vchunk->vregion->region;return ops->entry_activity_get (mlxsw_sp, region->priv, entry->priv, activity);
@@ -1033,7 +1076,7 @@ static const struct mlxsw_sp_acl_profile_ops mlxsw_sp_acl_tcam_flower_ops = { };struct mlxsw_sp_acl_tcam_mr_ruleset { -struct mlxsw_sp_acl_tcam_chunk *chunk; +struct mlxsw_sp_acl_tcam_vchunk *vchunk;struct mlxsw_sp_acl_tcam_group group; };
@@ -1063,10 +1106,11 @@ mlxsw_sp_acl_tcam_mr_ruleset_add(struct mlxsw_sp *mlxsw_sp,* specific ACL Group ID which must exist in HW before multicast router * is initialized. */ - ruleset->chunk =mlxsw_sp_acl_tcam_chunk_get (mlxsw_sp, &ruleset->group, -1 , tmplt_elusage); -if (IS_ERR (ruleset->chunk)) { - err =PTR_ERR (ruleset->chunk); + ruleset->vchunk =mlxsw_sp_acl_tcam_vchunk_get (mlxsw_sp, + &ruleset->group,1 , + tmplt_elusage); +if (IS_ERR (ruleset->vchunk)) { + err =PTR_ERR (ruleset->vchunk); goto err_chunk_get; }
@@ -1082,7 +1126,7 @@ mlxsw_sp_acl_tcam_mr_ruleset_del(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv) {struct mlxsw_sp_acl_tcam_mr_ruleset *ruleset = ruleset_priv; -mlxsw_sp_acl_tcam_chunk_put (mlxsw_sp, ruleset->chunk); +mlxsw_sp_acl_tcam_vchunk_put (mlxsw_sp, ruleset->vchunk);mlxsw_sp_acl_tcam_group_del (mlxsw_sp, &ruleset->group); }
Signature · 1 line
2.20.1
PATCH 7/14 mlxsw: spectrum_acl: Split entry struct into entry and ventry
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
Do the split of entry struct so the new entry struct is related to the actual HW entry, whereas ventry struct is a SW abstration of that. This split prepares possibility for ventry to hold 2 HW entries which is needed for region ERP rehash flow.
--- .../ethernet/mellanox/mlxsw/spectrum_acl.c | 2 +- .../mellanox/mlxsw/spectrum_acl_tcam.c | 170 +++++++++++------- .../mellanox/mlxsw/spectrum_acl_tcam.h | 2 +- 3 files changed, 108 insertions(+), 66 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +1 -1
@@ -640,7 +640,7 @@ mlxsw_sp_acl_rule_create(struct mlxsw_sp *mlxsw_sp,int err;mlxsw_sp_acl_ruleset_ref_inc (ruleset); - rule =kzalloc (sizeof (*rule) + ops->rule_priv_size (mlxsw_sp), + rule =kzalloc (sizeof (*rule) + ops->rule_priv_size,GFP_KERNEL );if (!rule) { err = -ENOMEM ;
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +106 -64
305 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h +1 -1
@@ -43,7 +43,7 @@ struct mlxsw_sp_acl_profile_ops {struct mlxsw_sp_port *mlxsw_sp_port, bool ingress);u16 (*ruleset_group_id)(void *ruleset_priv); -size_t (*rule_priv_size)(struct mlxsw_sp *mlxsw_sp); +size_t rule_priv_size;int (*rule_add)(struct mlxsw_sp *mlxsw_sp,void *ruleset_priv,void *rule_priv,struct mlxsw_sp_acl_rule_info *rulei);
Signature · 1 line
2.20.1
PATCH 8/14 mlxsw: spectrum_acl: Implement basic ERP rehash hits creation
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
Introduce an initial implementation of rehash logic in ERP code. Currently, the rehash is considered as needed only in case number of roots in the hints is smaller than the number of roots actually in use. In that case return hints pointer and let it be obtained through the callpath through the Spectrum-2 TCAM op.
--- .../net/ethernet/mellanox/mlxsw/spectrum.h | 2 + .../mellanox/mlxsw/spectrum2_acl_tcam.c | 14 ++++ .../mellanox/mlxsw/spectrum_acl_atcam.c | 11 +++ .../mellanox/mlxsw/spectrum_acl_erp.c | 74 +++++++++++++++++++ .../mellanox/mlxsw/spectrum_acl_tcam.h | 6 ++ 5 files changed, 107 insertions(+)
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +2 -0
@@ -708,6 +708,8 @@ struct mlxsw_sp_acl_tcam_ops {void (*region_fini)(struct mlxsw_sp *mlxsw_sp,void *region_priv);int (*region_associate)(struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam_region *region); +void * (*region_rehash_hints_get)(void *region_priv); +void (*region_rehash_hints_put)(void *hints_priv);size_t chunk_priv_size;void (*chunk_init)(void *region_priv,void *chunk_priv,unsigned int priority);
drivers/net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c +14 -0
@@ -166,6 +166,18 @@ mlxsw_sp2_acl_tcam_region_associate(struct mlxsw_sp *mlxsw_sp,return mlxsw_sp_acl_atcam_region_associate (mlxsw_sp, region->id); } +static void *mlxsw_sp2_acl_tcam_region_rehash_hints_get (void *region_priv) +{ +struct mlxsw_sp2_acl_tcam_region *region = region_priv; + +return mlxsw_sp_acl_atcam_rehash_hints_get (®ion->aregion); +} + +static void mlxsw_sp2_acl_tcam_region_rehash_hints_put (void *hints_priv) +{ +mlxsw_sp_acl_atcam_rehash_hints_put (hints_priv); +} +static void mlxsw_sp2_acl_tcam_chunk_init (void *region_priv,void *chunk_priv,unsigned int priority) {
@@ -243,6 +255,8 @@ const struct mlxsw_sp_acl_tcam_ops mlxsw_sp2_acl_tcam_ops = { .region_init = mlxsw_sp2_acl_tcam_region_init, .region_fini = mlxsw_sp2_acl_tcam_region_fini, .region_associate = mlxsw_sp2_acl_tcam_region_associate, + .region_rehash_hints_get = mlxsw_sp2_acl_tcam_region_rehash_hints_get, + .region_rehash_hints_put = mlxsw_sp2_acl_tcam_region_rehash_hints_put, .chunk_priv_size = sizeof(struct mlxsw_sp2_acl_tcam_chunk), .chunk_init = mlxsw_sp2_acl_tcam_chunk_init, .chunk_fini = mlxsw_sp2_acl_tcam_chunk_fini,
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_atcam.c +11 -0
@@ -634,3 +634,14 @@ void mlxsw_sp_acl_atcam_fini(struct mlxsw_sp *mlxsw_sp, {mlxsw_sp_acl_erps_fini (mlxsw_sp, atcam); } + +void * +mlxsw_sp_acl_atcam_rehash_hints_get (struct mlxsw_sp_acl_atcam_region *aregion) +{ +return mlxsw_sp_acl_erp_rehash_hints_get (aregion); +} + +void mlxsw_sp_acl_atcam_rehash_hints_put (void *hints_priv) +{ +mlxsw_sp_acl_erp_rehash_hints_put (hints_priv); +}
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c +74 -0
80 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h +6 -0
@@ -229,6 +229,9 @@ int mlxsw_sp_acl_atcam_init(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_atcam *atcam);void mlxsw_sp_acl_atcam_fini (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_atcam *atcam); +void * +mlxsw_sp_acl_atcam_rehash_hints_get (struct mlxsw_sp_acl_atcam_region *aregion); +void mlxsw_sp_acl_atcam_rehash_hints_put (void *hints_priv);struct mlxsw_sp_acl_erp_delta ;
@@ -259,6 +262,9 @@ void mlxsw_sp_acl_erp_bf_remove(struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_atcam_region *aregion, struct mlxsw_sp_acl_erp_mask *erp_mask, struct mlxsw_sp_acl_atcam_entry *aentry); +void * +mlxsw_sp_acl_erp_rehash_hints_get (struct mlxsw_sp_acl_atcam_region *aregion); +void mlxsw_sp_acl_erp_rehash_hints_put (void *hints_priv);int mlxsw_sp_acl_erp_region_init (struct mlxsw_sp_acl_atcam_region *aregion);void mlxsw_sp_acl_erp_region_fini (struct mlxsw_sp_acl_atcam_region *aregion); int mlxsw_sp_acl_erps_init(struct mlxsw_sp *mlxsw_sp,
Signature · 1 line
2.20.1
PATCH 9/14 mlxsw: spectrum_acl: Pass hints priv all the way to ERP code
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
The hints priv comes from ERP code and it is possible to obtain it from TCAM code. Add arg to appropriate functions so the hints priv could be passed back down to ERP code. Pass NULL now as the follow-up patches would pass an actual hints priv pointer.
--- drivers/net/ethernet/mellanox/mlxsw/spectrum.h | 3 ++- .../net/ethernet/mellanox/mlxsw/spectrum1_acl_tcam.c | 3 ++- .../net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c | 6 ++++-- .../net/ethernet/mellanox/mlxsw/spectrum_acl_atcam.c | 3 ++- .../net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c | 11 +++++++---- .../net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 3 ++- .../net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h | 4 +++- 7 files changed, 22 insertions(+), 11 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +2 -1
@@ -704,7 +704,8 @@ struct mlxsw_sp_acl_tcam_ops {size_t region_priv_size;int (*region_init)(struct mlxsw_sp *mlxsw_sp,void *region_priv,void *tcam_priv, -struct mlxsw_sp_acl_tcam_region *region); +struct mlxsw_sp_acl_tcam_region *region, +void *hints_priv);void (*region_fini)(struct mlxsw_sp *mlxsw_sp,void *region_priv);int (*region_associate)(struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam_region *region);
drivers/net/ethernet/mellanox/mlxsw/spectrum1_acl_tcam.c +2 -1
@@ -112,7 +112,8 @@ mlxsw_sp1_acl_ctcam_region_catchall_del(struct mlxsw_sp *mlxsw_sp,static int mlxsw_sp1_acl_tcam_region_init (struct mlxsw_sp *mlxsw_sp,void *region_priv,void *tcam_priv, -struct mlxsw_sp_acl_tcam_region *_region) +struct mlxsw_sp_acl_tcam_region *_region, +void *hints_priv) {struct mlxsw_sp1_acl_tcam_region *region = region_priv;int err;
drivers/net/ethernet/mellanox/mlxsw/spectrum2_acl_tcam.c +4 -2
@@ -139,7 +139,8 @@ static void mlxsw_sp2_acl_tcam_fini(struct mlxsw_sp *mlxsw_sp, void *priv)static int mlxsw_sp2_acl_tcam_region_init (struct mlxsw_sp *mlxsw_sp,void *region_priv,void *tcam_priv, -struct mlxsw_sp_acl_tcam_region *_region) +struct mlxsw_sp_acl_tcam_region *_region, +void *hints_priv) {struct mlxsw_sp2_acl_tcam_region *region = region_priv;struct mlxsw_sp2_acl_tcam *tcam = tcam_priv;
@@ -147,7 +148,8 @@ mlxsw_sp2_acl_tcam_region_init(struct mlxsw_sp *mlxsw_sp, void *region_priv, region->region = _region;return mlxsw_sp_acl_atcam_region_init (mlxsw_sp, &tcam->atcam, - ®ion->aregion, _region, + ®ion->aregion, + _region, hints_priv, &mlxsw_sp2_acl_ctcam_region_ops); }
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_atcam.c +2 -1
@@ -318,6 +318,7 @@ mlxsw_sp_acl_atcam_region_init(struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_atcam *atcam, struct mlxsw_sp_acl_atcam_region *aregion, struct mlxsw_sp_acl_tcam_region *region, + void *hints_priv, const struct mlxsw_sp_acl_ctcam_region_ops *ops) { int err;
@@ -334,7 +335,7 @@ mlxsw_sp_acl_atcam_region_init(struct mlxsw_sp *mlxsw_sp, err = aregion->ops->init (aregion);if (err) goto err_ops_init; - err =mlxsw_sp_acl_erp_region_init (aregion); + err =mlxsw_sp_acl_erp_region_init (aregion, hints_priv);if (err) goto err_erp_region_init; err = mlxsw_sp_acl_ctcam_region_init(mlxsw_sp, &aregion->cregion,
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_erp.c +7 -4
@@ -1313,7 +1313,8 @@ static const struct objagg_ops mlxsw_sp_acl_erp_objagg_ops = { };static struct mlxsw_sp_acl_erp_table * -mlxsw_sp_acl_erp_table_create (struct mlxsw_sp_acl_atcam_region *aregion) +mlxsw_sp_acl_erp_table_create (struct mlxsw_sp_acl_atcam_region *aregion, +struct objagg_hints *hints) {struct mlxsw_sp_acl_erp_table *erp_table;int err;
@@ -1323,7 +1324,7 @@ mlxsw_sp_acl_erp_table_create(struct mlxsw_sp_acl_atcam_region *aregion)return ERR_PTR (-ENOMEM ); erp_table->objagg =objagg_create (&mlxsw_sp_acl_erp_objagg_ops, -NULL , aregion); + hints, aregion);if (IS_ERR (erp_table->objagg)) { err =PTR_ERR (erp_table->objagg); goto err_objagg_create;
@@ -1444,12 +1445,14 @@ void mlxsw_sp_acl_erp_rehash_hints_put(void *hints_priv)objagg_hints_put (hints); } -int mlxsw_sp_acl_erp_region_init (struct mlxsw_sp_acl_atcam_region *aregion) +int mlxsw_sp_acl_erp_region_init (struct mlxsw_sp_acl_atcam_region *aregion, +void *hints_priv) {struct mlxsw_sp_acl_erp_table *erp_table; +struct objagg_hints *hints = hints_priv;int err; - erp_table =mlxsw_sp_acl_erp_table_create (aregion); + erp_table =mlxsw_sp_acl_erp_table_create (aregion, hints);if (IS_ERR (erp_table))return PTR_ERR (erp_table); aregion->erp_table = erp_table;
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +2 -1
@@ -572,7 +572,8 @@ mlxsw_sp_acl_tcam_region_create(struct mlxsw_sp *mlxsw_sp,if (err) goto err_tcam_region_enable; - err = ops->region_init (mlxsw_sp, region->priv, tcam->priv, region); + err = ops->region_init (mlxsw_sp, region->priv, tcam->priv, + region,NULL );if (err) goto err_tcam_region_init;
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h +3 -1
@@ -206,6 +206,7 @@ mlxsw_sp_acl_atcam_region_init(struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_atcam *atcam, struct mlxsw_sp_acl_atcam_region *aregion, struct mlxsw_sp_acl_tcam_region *region, + void *hints_priv, const struct mlxsw_sp_acl_ctcam_region_ops *ops);void mlxsw_sp_acl_atcam_region_fini (struct mlxsw_sp_acl_atcam_region *aregion); void mlxsw_sp_acl_atcam_chunk_init(struct mlxsw_sp_acl_atcam_region *aregion,
@@ -265,7 +266,8 @@ void mlxsw_sp_acl_erp_bf_remove(struct mlxsw_sp *mlxsw_sp,void *mlxsw_sp_acl_erp_rehash_hints_get (struct mlxsw_sp_acl_atcam_region *aregion);void mlxsw_sp_acl_erp_rehash_hints_put (void *hints_priv); -int mlxsw_sp_acl_erp_region_init (struct mlxsw_sp_acl_atcam_region *aregion); +int mlxsw_sp_acl_erp_region_init (struct mlxsw_sp_acl_atcam_region *aregion, +void *hints_priv);void mlxsw_sp_acl_erp_region_fini (struct mlxsw_sp_acl_atcam_region *aregion);int mlxsw_sp_acl_erps_init (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_atcam *atcam);
Signature · 1 line
2.20.1
PATCH 10/14 mlxsw: reg: Add multi field to PAGT register
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
For Spectrum-2 this allows parallel lookups in multiple regions.
--- drivers/net/ethernet/mellanox/mlxsw/reg.h | 11 ++++++++++- .../net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/reg.h +10 -1
@@ -2199,6 +2199,14 @@ MLXSW_ITEM32(reg, pagt, size, 0x00, 0, 8);*/ MLXSW_ITEM32 (reg, pagt, acl_group_id,0x08 ,0 ,16 ); +/* reg_pagt_multi +* Multi-ACL +* 0 - This ACL is the last ACL in the multi-ACL +* 1 - This ACL is part of a multi-ACL +* Access: RW +*/ +MLXSW_ITEM32_INDEXED (reg, pagt, multi,0x30 ,31 ,1 ,0x04 ,0x00 , false); +/* reg_pagt_acl_id * ACL identifier * Access: RW
@@ -2212,12 +2220,13 @@ static inline void mlxsw_reg_pagt_pack(char *payload, u16 acl_group_id) }static inline void mlxsw_reg_pagt_acl_id_pack (char *payload,int index, -u16 acl_id) +u16 acl_id,bool multi) {u8 size =mlxsw_reg_pagt_size_get (payload);if (index >= size)mlxsw_reg_pagt_size_set (payload, index +1 ); +mlxsw_reg_pagt_multi_set (payload, index, multi);mlxsw_reg_pagt_acl_id_set (payload, index, acl_id); }
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +1 -1
@@ -217,7 +217,7 @@ static int mlxsw_sp_acl_tcam_group_update(struct mlxsw_sp *mlxsw_sp,mlxsw_reg_pagt_pack (pagt_pl, group->id);list_for_each_entry (vregion, &group->vregion_list, list)mlxsw_reg_pagt_acl_id_pack (pagt_pl, acl_index++, - vregion->region->id); + vregion->region->id, false);mlxsw_reg_pagt_size_set (pagt_pl, acl_index);return mlxsw_reg_write (mlxsw_sp->core,MLXSW_REG (pagt), pagt_pl); }
Signature · 1 line
2.20.1
PATCH 11/14 mlxsw: spectrum_acl: Implement region migration according to hints
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
If the hints are returned, the migration should be started. For that to happen, there is a need to create a second physical region in TCAM with new ERP set by passing the hints and then move chunk by chunk, entry by entry.
During the transition, two lookups will occur. One in old region and another in new region. The highest priority rule will be chosen.
In an unlikely case that the migration will fail and also rollback to original region will fail the vregion will become in bad state. Everything will work, only no future rehash will be possible. In a follow-up work, this can be resolved by trying to resume the rollback in delayed work and repair the vregion.
--- .../mellanox/mlxsw/spectrum_acl_tcam.c | 287 ++++++++++++++++-- .../mellanox/mlxsw/spectrum_acl_tcam.h | 2 + 2 files changed, 268 insertions(+), 21 deletions(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +266 -21
@@ -23,6 +23,8 @@ size_t mlxsw_sp_acl_tcam_priv_size(struct mlxsw_sp *mlxsw_sp)return ops->priv_size; } +#define MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_DFLT 5000/* ms */ +int mlxsw_sp_acl_tcam_init (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam *tcam) {
@@ -33,6 +35,10 @@ int mlxsw_sp_acl_tcam_init(struct mlxsw_sp *mlxsw_sp,size_t alloc_size;int err; + tcam->vregion_rehash_intrvl = +MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_DFLT ; +INIT_LIST_HEAD (&tcam->vregion_list); + max_tcam_regions =MLXSW_CORE_RES_GET (mlxsw_sp->core,ACL_MAX_TCAM_REGIONS ); max_regions =MLXSW_CORE_RES_GET (mlxsw_sp->core,ACL_MAX_REGIONS );
@@ -165,24 +171,33 @@ struct mlxsw_sp_acl_tcam_group {struct mlxsw_sp_acl_tcam_vregion {struct mlxsw_sp_acl_tcam_region *region; +struct mlxsw_sp_acl_tcam_region *region2;/* Used during migration */ struct list_head list;/* Member of a TCAM group */ +struct list_head tlist;/* Member of a TCAM */ struct list_head vchunk_list;/* List of vchunks under this vregion */ struct mlxsw_sp_acl_tcam_group *group;struct mlxsw_afk_key_info *key_info; +struct mlxsw_sp_acl_tcam *tcam; +struct delayed_work rehash_dw; +struct mlxsw_sp *mlxsw_sp; +bool failed_rollback;/* Indicates failed rollback during migration */ };struct mlxsw_sp_acl_tcam_vchunk ;struct mlxsw_sp_acl_tcam_chunk {struct mlxsw_sp_acl_tcam_vchunk *vchunk; +struct mlxsw_sp_acl_tcam_region *region;unsigned long priv[0 ];/* priv has to be always the last item */ };struct mlxsw_sp_acl_tcam_vchunk {struct mlxsw_sp_acl_tcam_chunk *chunk; +struct mlxsw_sp_acl_tcam_chunk *chunk2;/* Used during migration */ struct list_head list;/* Member of a TCAM vregion */ struct rhash_head ht_node;/* Member of a chunk HT */ +struct list_head ventry_list;unsigned int priority;/* Priority within the vregion and group */ struct mlxsw_sp_acl_tcam_group *group;struct mlxsw_sp_acl_tcam_vregion *vregion;
@@ -191,13 +206,16 @@ struct mlxsw_sp_acl_tcam_vchunk {struct mlxsw_sp_acl_tcam_entry {struct mlxsw_sp_acl_tcam_ventry *ventry; +struct mlxsw_sp_acl_tcam_chunk *chunk;unsigned long priv[0 ];/* priv has to be always the last item */ };struct mlxsw_sp_acl_tcam_ventry {struct mlxsw_sp_acl_tcam_entry *entry; +struct list_head list;/* Member of a TCAM vchunk */ struct mlxsw_sp_acl_tcam_vchunk *vchunk; +struct mlxsw_sp_acl_rule_info *rulei; };static const struct rhashtable_params mlxsw_sp_acl_tcam_vchunk_ht_params = {
@@ -215,9 +233,13 @@ static int mlxsw_sp_acl_tcam_group_update(struct mlxsw_sp *mlxsw_sp,int acl_index =0 ;mlxsw_reg_pagt_pack (pagt_pl, group->id); -list_for_each_entry (vregion, &group->vregion_list, list) +list_for_each_entry (vregion, &group->vregion_list, list) { +if (vregion->region2) +mlxsw_reg_pagt_acl_id_pack (pagt_pl, acl_index++, + vregion->region2->id, true);mlxsw_reg_pagt_acl_id_pack (pagt_pl, acl_index++, vregion->region->id, false); + }mlxsw_reg_pagt_size_set (pagt_pl, acl_index);return mlxsw_reg_write (mlxsw_sp->core,MLXSW_REG (pagt), pagt_pl); }
@@ -391,6 +413,9 @@ mlxsw_sp_acl_tcam_group_vregion_detach(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_vregion *vregion) {list_del (&vregion->list); +if (vregion->region2) +mlxsw_sp_acl_tcam_group_region_detach (mlxsw_sp, + vregion->region2);mlxsw_sp_acl_tcam_group_region_detach (mlxsw_sp, vregion->region); }
@@ -542,7 +567,8 @@ mlxsw_sp_acl_tcam_region_disable(struct mlxsw_sp *mlxsw_sp,static struct mlxsw_sp_acl_tcam_region *mlxsw_sp_acl_tcam_region_create (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam *tcam, -struct mlxsw_sp_acl_tcam_vregion *vregion) +struct mlxsw_sp_acl_tcam_vregion *vregion, +void *hints_priv) {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;struct mlxsw_sp_acl_tcam_region *region;
@@ -573,7 +599,7 @@ mlxsw_sp_acl_tcam_region_create(struct mlxsw_sp *mlxsw_sp, goto err_tcam_region_enable; err = ops->region_init (mlxsw_sp, region->priv, tcam->priv, - region,NULL ); + region, hints_priv);if (err) goto err_tcam_region_init;
@@ -605,11 +631,42 @@ mlxsw_sp_acl_tcam_region_destroy(struct mlxsw_sp *mlxsw_sp,kfree (region); } +static void +mlxsw_sp_acl_tcam_vregion_rehash_work_schedule (struct mlxsw_sp_acl_tcam_vregion *vregion) +{ +unsigned long interval = vregion->tcam->vregion_rehash_intrvl; + +if (!interval) +return ; +mlxsw_core_schedule_dw (&vregion->rehash_dw, +msecs_to_jiffies (interval)); +} + +static int +mlxsw_sp_acl_tcam_vregion_rehash (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_vregion *vregion); + +static void mlxsw_sp_acl_tcam_vregion_rehash_work (struct work_struct *work) +{ +struct mlxsw_sp_acl_tcam_vregion *vregion = + container_of(work, struct mlxsw_sp_acl_tcam_vregion, + rehash_dw.work); + +/* TODO: Take rtnl lock here as the rest of the code counts on it +* now. Later, this should be replaced by per-vregion lock. +*/ +rtnl_lock (); +mlxsw_sp_acl_tcam_vregion_rehash (vregion->mlxsw_sp, vregion); +rtnl_unlock (); +mlxsw_sp_acl_tcam_vregion_rehash_work_schedule (vregion); +} +static struct mlxsw_sp_acl_tcam_vregion *mlxsw_sp_acl_tcam_vregion_create (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam *tcam,struct mlxsw_afk_element_usage *elusage) { +const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;struct mlxsw_afk *afk =mlxsw_sp_acl_afk (mlxsw_sp->acl);struct mlxsw_sp_acl_tcam_vregion *vregion;int err;
@@ -618,6 +675,8 @@ mlxsw_sp_acl_tcam_vregion_create(struct mlxsw_sp *mlxsw_sp,if (!vregion)return ERR_PTR (-ENOMEM );INIT_LIST_HEAD (&vregion->vchunk_list); + vregion->tcam = tcam; + vregion->mlxsw_sp = mlxsw_sp; vregion->key_info =mlxsw_afk_key_info_get (afk, elusage);if (IS_ERR (vregion->key_info)) {
@@ -626,12 +685,21 @@ mlxsw_sp_acl_tcam_vregion_create(struct mlxsw_sp *mlxsw_sp, } vregion->region =mlxsw_sp_acl_tcam_region_create (mlxsw_sp, tcam, - vregion); + vregion,NULL );if (IS_ERR (vregion->region)) { err =PTR_ERR (vregion->region); goto err_region_create; } +list_add_tail (&vregion->tlist, &tcam->vregion_list); + +if (ops->region_rehash_hints_get) { +/* Create the delayed work for vregion periodic rehash */ +INIT_DELAYED_WORK (&vregion->rehash_dw, + mlxsw_sp_acl_tcam_vregion_rehash_work); +mlxsw_sp_acl_tcam_vregion_rehash_work_schedule (vregion); + } +return vregion; err_region_create:
@@ -645,6 +713,13 @@ static void mlxsw_sp_acl_tcam_vregion_destroy(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_vregion *vregion) { + const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; + +if (ops->region_rehash_hints_get) +cancel_delayed_work_sync (&vregion->rehash_dw); +list_del (&vregion->tlist); +if (vregion->region2) +mlxsw_sp_acl_tcam_region_destroy (mlxsw_sp, vregion->region2);mlxsw_sp_acl_tcam_region_destroy (mlxsw_sp, vregion->region);mlxsw_afk_key_info_put (vregion->key_info);kfree (vregion);
@@ -728,6 +803,7 @@ mlxsw_sp_acl_tcam_chunk_create(struct mlxsw_sp *mlxsw_sp,if (!chunk)return ERR_PTR (-ENOMEM ); chunk->vchunk = vchunk; + chunk->region = region; ops->chunk_init (region->priv, chunk->priv, vchunk->priority);return chunk;
@@ -758,6 +834,7 @@ mlxsw_sp_acl_tcam_vchunk_create(struct mlxsw_sp *mlxsw_sp, vchunk =kzalloc (sizeof (*vchunk),GFP_KERNEL );if (!vchunk)return ERR_PTR (-ENOMEM ); +INIT_LIST_HEAD (&vchunk->ventry_list); vchunk->priority = priority; vchunk->group = group; vchunk->ref_count =1 ;
@@ -797,6 +874,8 @@ mlxsw_sp_acl_tcam_vchunk_destroy(struct mlxsw_sp *mlxsw_sp, {struct mlxsw_sp_acl_tcam_group *group = vchunk->group; +if (vchunk->chunk2) +mlxsw_sp_acl_tcam_chunk_destroy (mlxsw_sp, vchunk->chunk2);mlxsw_sp_acl_tcam_chunk_destroy (mlxsw_sp, vchunk->chunk);rhashtable_remove_fast (&group->vchunk_ht, &vchunk->ht_node, mlxsw_sp_acl_tcam_vchunk_ht_params);
@@ -837,9 +916,7 @@ mlxsw_sp_acl_tcam_vchunk_put(struct mlxsw_sp *mlxsw_sp,static struct mlxsw_sp_acl_tcam_entry *mlxsw_sp_acl_tcam_entry_create (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam_ventry *ventry, -struct mlxsw_sp_acl_tcam_region *region, -struct mlxsw_sp_acl_tcam_chunk *chunk, -struct mlxsw_sp_acl_rule_info *rulei) +struct mlxsw_sp_acl_tcam_chunk *chunk) {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;struct mlxsw_sp_acl_tcam_entry *entry;
@@ -849,9 +926,10 @@ mlxsw_sp_acl_tcam_entry_create(struct mlxsw_sp *mlxsw_sp,if (!entry)return ERR_PTR (-ENOMEM ); entry->ventry = ventry; + entry->chunk = chunk; - err = ops->entry_add (mlxsw_sp, region->priv, chunk->priv, - entry->priv, rulei); + err = ops->entry_add (mlxsw_sp, chunk->region->priv, chunk->priv, + entry->priv, ventry->rulei);if (err) goto err_entry_add;
@@ -863,13 +941,12 @@ mlxsw_sp_acl_tcam_entry_create(struct mlxsw_sp *mlxsw_sp, }static void mlxsw_sp_acl_tcam_entry_destroy (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_region *region, -struct mlxsw_sp_acl_tcam_chunk *chunk,struct mlxsw_sp_acl_tcam_entry *entry) {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; - ops->entry_del (mlxsw_sp, region->priv, chunk->priv, entry->priv); + ops->entry_del (mlxsw_sp, entry->chunk->region->priv, + entry->chunk->priv, entry->priv);kfree (entry); }
@@ -887,13 +964,12 @@ mlxsw_sp_acl_tcam_entry_action_replace(struct mlxsw_sp *mlxsw_sp,static int mlxsw_sp_acl_tcam_entry_activity_get (struct mlxsw_sp *mlxsw_sp, -struct mlxsw_sp_acl_tcam_region *region,struct mlxsw_sp_acl_tcam_entry *entry,bool *activity) {const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; -return ops->entry_activity_get (mlxsw_sp, region->priv, +return ops->entry_activity_get (mlxsw_sp, entry->chunk->region->priv, entry->priv, activity); }
@@ -911,14 +987,16 @@ static int mlxsw_sp_acl_tcam_ventry_add(struct mlxsw_sp *mlxsw_sp,return PTR_ERR (vchunk); ventry->vchunk = vchunk; + ventry->rulei = rulei; ventry->entry =mlxsw_sp_acl_tcam_entry_create (mlxsw_sp, ventry, - vchunk->vregion->region, - vchunk->chunk, rulei); + vchunk->chunk);if (IS_ERR (ventry->entry)) { err =PTR_ERR (ventry->entry); goto err_entry_create; } +list_add_tail (&ventry->list, &vchunk->ventry_list); +return 0 ; err_entry_create:
@@ -931,8 +1009,8 @@ static void mlxsw_sp_acl_tcam_ventry_del(struct mlxsw_sp *mlxsw_sp, {struct mlxsw_sp_acl_tcam_vchunk *vchunk = ventry->vchunk; -mlxsw_sp_acl_tcam_entry_destroy (mlxsw_sp, vchunk->vregion->region, - vchunk->chunk, ventry->entry); +list_del (&ventry->list); +mlxsw_sp_acl_tcam_entry_destroy (mlxsw_sp, ventry->entry);mlxsw_sp_acl_tcam_vchunk_put (mlxsw_sp, vchunk); }
@@ -953,13 +1031,180 @@ mlxsw_sp_acl_tcam_ventry_activity_get(struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam_ventry *ventry, bool *activity) { - struct mlxsw_sp_acl_tcam_vchunk *vchunk = ventry->vchunk; - return mlxsw_sp_acl_tcam_entry_activity_get(mlxsw_sp, - vchunk->vregion->region, ventry->entry, activity); } +static int +mlxsw_sp_acl_tcam_ventry_migrate (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_ventry *ventry, +struct mlxsw_sp_acl_tcam_chunk *chunk2) +{ +struct mlxsw_sp_acl_tcam_entry *entry2; + + entry2 =mlxsw_sp_acl_tcam_entry_create (mlxsw_sp, ventry, chunk2); +if (IS_ERR (entry2)) +return PTR_ERR (entry2); +mlxsw_sp_acl_tcam_entry_destroy (mlxsw_sp, ventry->entry); + ventry->entry = entry2; +return 0 ; +} + +static int +mlxsw_sp_acl_tcam_vchunk_migrate_one (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_vchunk *vchunk, +struct mlxsw_sp_acl_tcam_region *region, +bool this_is_rollback) +{ +struct mlxsw_sp_acl_tcam_ventry *ventry; +struct mlxsw_sp_acl_tcam_chunk *chunk2; +int err; +int err2; + + chunk2 =mlxsw_sp_acl_tcam_chunk_create (mlxsw_sp, vchunk, region); +if (IS_ERR (chunk2)) { +if (this_is_rollback) + vchunk->vregion->failed_rollback = true; +return PTR_ERR (chunk2); + } + vchunk->chunk2 = chunk2; +list_for_each_entry (ventry, &vchunk->ventry_list, list) { + err =mlxsw_sp_acl_tcam_ventry_migrate (mlxsw_sp, ventry, + vchunk->chunk2); +if (err) { +if (this_is_rollback) { + vchunk->vregion->failed_rollback = true; +return err; + } + goto rollback; + } + } +mlxsw_sp_acl_tcam_chunk_destroy (mlxsw_sp, vchunk->chunk); + vchunk->chunk = chunk2; + vchunk->chunk2 =NULL ; +return 0 ; + +rollback: +/* Migrate the entries back to the original chunk. If some entry +* migration fails, there's no good way how to proceed. Set the +* vregion with "failed_rollback" flag. +*/ +list_for_each_entry_continue_reverse (ventry, &vchunk->ventry_list, + list) { + err2 =mlxsw_sp_acl_tcam_ventry_migrate (mlxsw_sp, ventry, + vchunk->chunk); +if (err2) { + vchunk->vregion->failed_rollback = true; + goto err_rollback; + } + } + +mlxsw_sp_acl_tcam_chunk_destroy (mlxsw_sp, vchunk->chunk2); + vchunk->chunk2 =NULL ; + +err_rollback: +return err; +} + +static int +mlxsw_sp_acl_tcam_vchunk_migrate_all (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_vregion *vregion) +{ +struct mlxsw_sp_acl_tcam_vchunk *vchunk; +int err; + +list_for_each_entry (vchunk, &vregion->vchunk_list, list) { + err =mlxsw_sp_acl_tcam_vchunk_migrate_one (mlxsw_sp, vchunk, + vregion->region2, + false); +if (err) + goto rollback; + } +return 0 ; + +rollback: +list_for_each_entry_continue_reverse (vchunk, &vregion->vchunk_list, + list) { +mlxsw_sp_acl_tcam_vchunk_migrate_one (mlxsw_sp, vchunk, + vregion->region, true); + } +return err; +} + +static int +mlxsw_sp_acl_tcam_vregion_migrate (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_vregion *vregion, +void *hints_priv) +{ +struct mlxsw_sp_acl_tcam_region *region2, *unused_region; +int err; + + region2 =mlxsw_sp_acl_tcam_region_create (mlxsw_sp, vregion->tcam, + vregion, hints_priv); +if (IS_ERR (region2)) +return PTR_ERR (region2); + + vregion->region2 = region2; + err =mlxsw_sp_acl_tcam_group_region_attach (mlxsw_sp, region2); +if (err) + goto err_group_region_attach; + + err =mlxsw_sp_acl_tcam_vchunk_migrate_all (mlxsw_sp, vregion); +if (!vregion->failed_rollback) { +if (!err) { +/* In case of successful migration, region2 is used and +* the original is unused. +*/ + unused_region = vregion->region; + vregion->region = vregion->region2; + }else { +/* In case of failure during migration, the original +* region is still used. +*/ + unused_region = vregion->region2; + } + vregion->region2 =NULL ; +mlxsw_sp_acl_tcam_group_region_detach (mlxsw_sp, unused_region); +mlxsw_sp_acl_tcam_region_destroy (mlxsw_sp, unused_region); + } +return err; + +err_group_region_attach: + vregion->region2 =NULL ; +mlxsw_sp_acl_tcam_region_destroy (mlxsw_sp, region2); +return err; +} + +static int +mlxsw_sp_acl_tcam_vregion_rehash (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam_vregion *vregion) +{ +const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; +void *hints_priv; +int err; + +if (vregion->failed_rollback) +return -EBUSY ; + + hints_priv = ops->region_rehash_hints_get (vregion->region->priv); +if (IS_ERR (hints_priv)) { + err =PTR_ERR (hints_priv); +if (err != -EAGAIN ) +dev_err (mlxsw_sp->bus_info->dev,"Failed get rehash hints\n" ); +return err; + } + + err =mlxsw_sp_acl_tcam_vregion_migrate (mlxsw_sp, vregion, hints_priv); +if (err) { +dev_err (mlxsw_sp->bus_info->dev,"Failed to migrate vregion\n" ); +if (vregion->failed_rollback) +dev_err (mlxsw_sp->bus_info->dev,"Failed to rollback during vregion migration fail\n" ); + } + + ops->region_rehash_hints_put (hints_priv); +return err; +} +static const enum mlxsw_afk_element mlxsw_sp_acl_tcam_pattern_ipv4[] = {MLXSW_AFK_ELEMENT_SRC_SYS_PORT ,MLXSW_AFK_ELEMENT_DMAC_32_47 ,
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h +2 -0
@@ -17,6 +17,8 @@ struct mlxsw_sp_acl_tcam {unsigned long *used_groups;/* bit array */ unsigned int max_groups;unsigned int max_group_size; +struct list_head vregion_list; +u32 vregion_rehash_intrvl;/* ms */ unsigned long priv[0 ];/* priv has to be always the last item */ };
Signature · 1 line
2.20.1
PATCH 12/14 mlxsw: spectrum: add "acl_region_rehash_interval" devlink param
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
Expose new driver-specific "acl_region_rehash_interval" devlink param which would allow user to alter default ACL region rehash interval.
--- .../networking/devlink-params-mlxsw.txt | 8 +++ drivers/net/ethernet/mellanox/mlxsw/core.h | 5 ++ .../net/ethernet/mellanox/mlxsw/spectrum.c | 69 ++++++++++++++++++- .../net/ethernet/mellanox/mlxsw/spectrum.h | 2 + .../ethernet/mellanox/mlxsw/spectrum_acl.c | 16 +++++ .../mellanox/mlxsw/spectrum_acl_tcam.c | 36 ++++++++++ .../mellanox/mlxsw/spectrum_acl_tcam.h | 5 ++ 7 files changed, 139 insertions(+), 2 deletions(-)
Documentation/networking/devlink-params-mlxsw.txt +8 -0
@@ -1,2 +1,10 @@ fw_load_policy [DEVICE, GENERIC] Configuration mode: driverinit + +acl_region_rehash_interval [DEVICE, DRIVER-SPECIFIC] + Sets an interval for periodic ACL region rehashes. + The value is in milliseconds, minimal value is "3000". + Value "0" disables the periodic work. + The first rehash will be run right after value is set. + Type: u32 + Configuration mode: runtime
drivers/net/ethernet/mellanox/mlxsw/core.h +5 -0
@@ -394,4 +394,9 @@ static inline void mlxsw_thermal_fini(struct mlxsw_thermal *thermal)#endif +enum mlxsw_devlink_param_id { +MLXSW_DEVLINK_PARAM_ID_BASE =DEVLINK_PARAM_GENERIC_ID_MAX , +MLXSW_DEVLINK_PARAM_ID_ACL_REGION_REHASH_INTERVAL , +}; +#endif
drivers/net/ethernet/mellanox/mlxsw/spectrum.c +67 -2
81 lines not on this page · raw message
drivers/net/ethernet/mellanox/mlxsw/spectrum.h +2 -0
@@ -690,6 +690,8 @@ struct mlxsw_sp_fid *mlxsw_sp_acl_dummy_fid(struct mlxsw_sp *mlxsw_sp);int mlxsw_sp_acl_init (struct mlxsw_sp *mlxsw_sp);void mlxsw_sp_acl_fini (struct mlxsw_sp *mlxsw_sp); +u32 mlxsw_sp_acl_region_rehash_intrvl_get (struct mlxsw_sp *mlxsw_sp); +int mlxsw_sp_acl_region_rehash_intrvl_set (struct mlxsw_sp *mlxsw_sp,u32 val);/* spectrum_acl_tcam.c */ struct mlxsw_sp_acl_tcam ;
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl.c +16 -0
@@ -912,3 +912,19 @@ void mlxsw_sp_acl_fini(struct mlxsw_sp *mlxsw_sp)mlxsw_afk_destroy (acl->afk);kfree (acl); } + +u32 mlxsw_sp_acl_region_rehash_intrvl_get (struct mlxsw_sp *mlxsw_sp) +{ +struct mlxsw_sp_acl *acl = mlxsw_sp->acl; + +return mlxsw_sp_acl_tcam_vregion_rehash_intrvl_get (mlxsw_sp, + &acl->tcam); +} + +int mlxsw_sp_acl_region_rehash_intrvl_set (struct mlxsw_sp *mlxsw_sp,u32 val) +{ +struct mlxsw_sp_acl *acl = mlxsw_sp->acl; + +return mlxsw_sp_acl_tcam_vregion_rehash_intrvl_set (mlxsw_sp, + &acl->tcam, val); +}
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +36 -0
@@ -24,6 +24,7 @@ size_t mlxsw_sp_acl_tcam_priv_size(struct mlxsw_sp *mlxsw_sp) }#define MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_DFLT 5000/* ms */ +#define MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_MIN 3000/* ms */ int mlxsw_sp_acl_tcam_init (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam *tcam)
@@ -725,6 +726,41 @@ mlxsw_sp_acl_tcam_vregion_destroy(struct mlxsw_sp *mlxsw_sp,kfree (vregion); } +u32 mlxsw_sp_acl_tcam_vregion_rehash_intrvl_get (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam *tcam) +{ +const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; +u32 vregion_rehash_intrvl; + +if (WARN_ON (!ops->region_rehash_hints_get)) +return 0 ; + vregion_rehash_intrvl = tcam->vregion_rehash_intrvl; +return vregion_rehash_intrvl; +} + +int mlxsw_sp_acl_tcam_vregion_rehash_intrvl_set (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam *tcam, +u32 val) +{ +const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops; +struct mlxsw_sp_acl_tcam_vregion *vregion; + +if (val <MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_MIN && val) +return -EINVAL ; +if (WARN_ON (!ops->region_rehash_hints_get)) +return -EOPNOTSUPP ; + tcam->vregion_rehash_intrvl = val; +rtnl_lock (); +list_for_each_entry (vregion, &tcam->vregion_list, tlist) { +if (val) +mlxsw_core_schedule_dw (&vregion->rehash_dw,0 ); +else +cancel_delayed_work_sync (&vregion->rehash_dw); + } +rtnl_unlock (); +return 0 ; +} + static int mlxsw_sp_acl_tcam_vchunk_assoc(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam_group *group,
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.h +5 -0
@@ -28,6 +28,11 @@ int mlxsw_sp_acl_tcam_init(struct mlxsw_sp *mlxsw_sp, struct mlxsw_sp_acl_tcam *tcam);void mlxsw_sp_acl_tcam_fini (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam *tcam); +u32 mlxsw_sp_acl_tcam_vregion_rehash_intrvl_get (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam *tcam); +int mlxsw_sp_acl_tcam_vregion_rehash_intrvl_set (struct mlxsw_sp *mlxsw_sp, +struct mlxsw_sp_acl_tcam *tcam, +u32 val);int mlxsw_sp_acl_tcam_priority_get (struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_rule_info *rulei,u32 *priority,bool fillup_priority);
Signature · 1 line
2.20.1
PATCH 13/14 mlxsw: spectrum_acl: Add couple of vregion rehash tracepoints
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
As vregion rehash is happening in delayed work, add some visibility to the process using a few tracepoints.
--- .../mellanox/mlxsw/spectrum_acl_tcam.c | 9 ++- include/trace/events/mlxsw.h | 61 +++++++++++++++++++ 2 files changed, 69 insertions(+), 1 deletion(-)
drivers/net/ethernet/mellanox/mlxsw/spectrum_acl_tcam.c +8 -1
@@ -8,6 +8,7 @@#include <linux/list.h> #include <linux/rhashtable.h> #include <linux/netdevice.h> +#include <trace/events/mlxsw.h> #include "reg.h" #include "core.h"
@@ -1175,6 +1176,8 @@ mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp,struct mlxsw_sp_acl_tcam_region *region2, *unused_region;int err; +trace_mlxsw_sp_acl_tcam_vregion_migrate (mlxsw_sp, vregion); + region2 =mlxsw_sp_acl_tcam_region_create (mlxsw_sp, vregion->tcam, vregion, hints_priv);if (IS_ERR (region2))
@@ -1219,6 +1222,7 @@ mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp,void *hints_priv;int err; +trace_mlxsw_sp_acl_tcam_vregion_rehash (mlxsw_sp, vregion);if (vregion->failed_rollback)return -EBUSY ;
@@ -1233,8 +1237,11 @@ mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp, err =mlxsw_sp_acl_tcam_vregion_migrate (mlxsw_sp, vregion, hints_priv);if (err) {dev_err (mlxsw_sp->bus_info->dev,"Failed to migrate vregion\n" ); -if (vregion->failed_rollback) +if (vregion->failed_rollback) { +trace_mlxsw_sp_acl_tcam_vregion_rehash_dis (mlxsw_sp, + vregion);dev_err (mlxsw_sp->bus_info->dev,"Failed to rollback during vregion migration fail\n" ); + } } ops->region_rehash_hints_put (hints_priv);
include/trace/events/mlxsw.h +61 -0
73 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 14/14 selftests: mlxsw: spectrum-2: Add simple delta rehash test
In reply to Ido SchimmelFrom: Jiri Pirko <[email protected]>
Track the basic codepaths of delta rehash handling, using mlxsw tracepoints.
--- .../drivers/net/mlxsw/spectrum-2/tc_flower.sh | 77 ++++++++++++++++++- 1 file changed, 74 insertions(+), 3 deletions(-)
tools/testing/selftests/drivers/net/mlxsw/spectrum-2/tc_flower.sh +74 -3
@@ -9,11 +9,11 @@ lib_dir=$(dirname $0)/../../../../net/forwarding ALL_TESTS="single_mask_test identical_filters_test two_masks_test \ multiple_masks_test ctcam_edge_cases_test delta_simple_test \ - delta_two_masks_one_key_test bloom_simple_test \ - bloom_complex_test bloom_delta_test" + delta_two_masks_one_key_test delta_simple_rehash_test \ + bloom_simple_test bloom_complex_test bloom_delta_test" NUM_NETIFS=2 source $lib_dir/tc_common.sh -source $lib_dir/lib.sh +source $lib_dir/devlink_lib.sh tcflags="skip_hw"
@@ -494,6 +494,77 @@ delta_two_masks_one_key_test() log_test "delta two masks one key test ($tcflags)" } +delta_simple_rehash_test() +{ + RET=0 + + if [[ "$tcflags" != "skip_sw" ]]; then + return 0; + fi + + devlink dev param set $DEVLINK_DEV \ + name acl_region_rehash_interval cmode runtime value 0 + check_err $? "Failed to set ACL region rehash interval" + + tp_record_all mlxsw:mlxsw_sp_acl_tcam_vregion_rehash 7 + tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_rehash + check_fail $? "Rehash trace was hit even when rehash should be disabled" + + devlink dev param set $DEVLINK_DEV \ + name acl_region_rehash_interval cmode runtime value 3000 + check_err $? "Failed to set ACL region rehash interval" + + sleep 1 + + tc filter add dev $h2 ingress protocol ip pref 1 handle 101 flower \ + $tcflags dst_ip 192.0.1.0/25 action drop + tc filter add dev $h2 ingress protocol ip pref 2 handle 102 flower \ + $tcflags dst_ip 192.0.2.2 action drop + tc filter add dev $h2 ingress protocol ip pref 3 handle 103 flower \ + $tcflags dst_ip 192.0.3.0/24 action drop + + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ + -t ip -q + + tc_check_packets "dev $h2 ingress" 101 1 + check_fail $? "Matched a wrong filter" + + tc_check_packets "dev $h2 ingress" 103 1 + check_fail $? "Matched a wrong filter" + + tc_check_packets "dev $h2 ingress" 102 1 + check_err $? "Did not match on correct filter" + + tp_record_all mlxsw:* 3 + tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_rehash + check_err $? "Rehash trace was not hit" + tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_migrate + check_err $? "Migrate trace was not hit" + tp_record_all mlxsw:* 3 + tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_rehash + check_err $? "Rehash trace was not hit" + tp_check_hits_any mlxsw:mlxsw_sp_acl_tcam_vregion_migrate + check_fail $? "Migrate trace was hit when no migration should happen" + + $MZ $h1 -c 1 -p 64 -a $h1mac -b $h2mac -A 192.0.2.1 -B 192.0.2.2 \ + -t ip -q + + tc_check_packets "dev $h2 ingress" 101 1 + check_fail $? "Matched a wrong filter after rehash" + + tc_check_packets "dev $h2 ingress" 103 1 + check_fail $? "Matched a wrong filter after rehash" + + tc_check_packets "dev $h2 ingress" 102 2 + check_err $? "Did not match on correct filter after rehash" + + tc filter del dev $h2 ingress protocol ip pref 3 handle 103 flower + tc filter del dev $h2 ingress protocol ip pref 2 handle 102 flower + tc filter del dev $h2 ingress protocol ip pref 1 handle 101 flower + + log_test "delta simple rehash test ($tcflags)" +} + bloom_simple_test() { # Bloom filter requires that the eRP table is used. This test
Signature · 1 line
2.20.1
David Miller
maintainerFrom: Ido Schimmel <[email protected]>
Date: Thu, 7 Feb 2019 11:22:44 +0000
Quoted 6 lines
Currently, an ERP set is created for each region according to rules inserted and order of their insertion. However that might lead to suboptimal ERP sets and possible unnecessary spillage into C-TCAM. This patchset aims to fix this problem and introduces periodical checking of used ERP sets and in case a better ERP set is possible for the given set of rules, it rehashes the region to use the better ERP set.
...
Series applied, I'll push this out after my build tests complete.
Thanks.