1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /* Copyright (c) 2017-2018 Mellanox Technologies. All rights reserved */
4 #include <linux/kernel.h>
5 #include <linux/slab.h>
6 #include <linux/errno.h>
7 #include <linux/bitops.h>
8 #include <linux/list.h>
9 #include <linux/rhashtable.h>
10 #include <linux/netdevice.h>
11 #include <linux/mutex.h>
12 #include <linux/refcount.h>
13 #include <linux/idr.h>
14 #include <net/devlink.h>
15 #include <trace/events/mlxsw.h>
19 #include "resources.h"
21 #include "spectrum_acl_tcam.h"
22 #include "core_acl_flex_keys.h"
24 size_t mlxsw_sp_acl_tcam_priv_size(struct mlxsw_sp *mlxsw_sp)
26 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
28 return ops->priv_size;
31 #define MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_DFLT 5000 /* ms */
32 #define MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_MIN 3000 /* ms */
33 #define MLXSW_SP_ACL_TCAM_VREGION_REHASH_CREDITS 100 /* number of entries */
35 int mlxsw_sp_acl_tcam_priority_get(struct mlxsw_sp *mlxsw_sp,
36 struct mlxsw_sp_acl_rule_info *rulei,
37 u32 *priority, bool fillup_priority)
41 if (!fillup_priority) {
46 if (!MLXSW_CORE_RES_VALID(mlxsw_sp->core, KVD_SIZE))
49 /* Priority range is 1..cap_kvd_size-1. */
50 max_priority = MLXSW_CORE_RES_GET(mlxsw_sp->core, KVD_SIZE) - 1;
51 if (rulei->priority >= max_priority)
54 /* Unlike in TC, in HW, higher number means higher priority. */
55 *priority = max_priority - rulei->priority;
59 static int mlxsw_sp_acl_tcam_region_id_get(struct mlxsw_sp_acl_tcam *tcam,
64 id = ida_alloc_max(&tcam->used_regions, tcam->max_regions - 1,
74 static void mlxsw_sp_acl_tcam_region_id_put(struct mlxsw_sp_acl_tcam *tcam,
77 ida_free(&tcam->used_regions, id);
80 static int mlxsw_sp_acl_tcam_group_id_get(struct mlxsw_sp_acl_tcam *tcam,
85 id = ida_alloc_max(&tcam->used_groups, tcam->max_groups - 1,
95 static void mlxsw_sp_acl_tcam_group_id_put(struct mlxsw_sp_acl_tcam *tcam,
98 ida_free(&tcam->used_groups, id);
101 struct mlxsw_sp_acl_tcam_pattern {
102 const enum mlxsw_afk_element *elements;
103 unsigned int elements_count;
106 struct mlxsw_sp_acl_tcam_group {
107 struct mlxsw_sp_acl_tcam *tcam;
109 struct mutex lock; /* guards region list updates */
110 struct list_head region_list;
111 unsigned int region_count;
114 struct mlxsw_sp_acl_tcam_vgroup {
115 struct mlxsw_sp_acl_tcam_group group;
116 struct list_head vregion_list;
117 struct rhashtable vchunk_ht;
118 const struct mlxsw_sp_acl_tcam_pattern *patterns;
119 unsigned int patterns_count;
120 bool tmplt_elusage_set;
121 struct mlxsw_afk_element_usage tmplt_elusage;
122 bool vregion_rehash_enabled;
123 unsigned int *p_min_prio;
124 unsigned int *p_max_prio;
127 struct mlxsw_sp_acl_tcam_rehash_ctx {
129 bool this_is_rollback;
130 struct mlxsw_sp_acl_tcam_vchunk *current_vchunk; /* vchunk being
131 * currently migrated.
133 struct mlxsw_sp_acl_tcam_ventry *start_ventry; /* ventry to start
136 * currently migrated.
138 struct mlxsw_sp_acl_tcam_ventry *stop_ventry; /* ventry to stop
141 * currently migrated.
145 struct mlxsw_sp_acl_tcam_vregion {
146 struct mutex lock; /* Protects consistency of region, region2 pointers
149 struct mlxsw_sp_acl_tcam_region *region;
150 struct mlxsw_sp_acl_tcam_region *region2; /* Used during migration */
151 struct list_head list; /* Member of a TCAM group */
152 struct list_head tlist; /* Member of a TCAM */
153 struct list_head vchunk_list; /* List of vchunks under this vregion */
154 struct mlxsw_afk_key_info *key_info;
155 struct mlxsw_sp_acl_tcam *tcam;
156 struct mlxsw_sp_acl_tcam_vgroup *vgroup;
158 struct delayed_work dw;
159 struct mlxsw_sp_acl_tcam_rehash_ctx ctx;
161 struct mlxsw_sp *mlxsw_sp;
162 refcount_t ref_count;
165 struct mlxsw_sp_acl_tcam_vchunk;
167 struct mlxsw_sp_acl_tcam_chunk {
168 struct mlxsw_sp_acl_tcam_vchunk *vchunk;
169 struct mlxsw_sp_acl_tcam_region *region;
170 unsigned long priv[];
171 /* priv has to be always the last item */
174 struct mlxsw_sp_acl_tcam_vchunk {
175 struct mlxsw_sp_acl_tcam_chunk *chunk;
176 struct mlxsw_sp_acl_tcam_chunk *chunk2; /* Used during migration */
177 struct list_head list; /* Member of a TCAM vregion */
178 struct rhash_head ht_node; /* Member of a chunk HT */
179 struct list_head ventry_list;
180 unsigned int priority; /* Priority within the vregion and group */
181 struct mlxsw_sp_acl_tcam_vgroup *vgroup;
182 struct mlxsw_sp_acl_tcam_vregion *vregion;
183 refcount_t ref_count;
186 struct mlxsw_sp_acl_tcam_entry {
187 struct mlxsw_sp_acl_tcam_ventry *ventry;
188 struct mlxsw_sp_acl_tcam_chunk *chunk;
189 unsigned long priv[];
190 /* priv has to be always the last item */
193 struct mlxsw_sp_acl_tcam_ventry {
194 struct mlxsw_sp_acl_tcam_entry *entry;
195 struct list_head list; /* Member of a TCAM vchunk */
196 struct mlxsw_sp_acl_tcam_vchunk *vchunk;
197 struct mlxsw_sp_acl_rule_info *rulei;
200 static const struct rhashtable_params mlxsw_sp_acl_tcam_vchunk_ht_params = {
201 .key_len = sizeof(unsigned int),
202 .key_offset = offsetof(struct mlxsw_sp_acl_tcam_vchunk, priority),
203 .head_offset = offsetof(struct mlxsw_sp_acl_tcam_vchunk, ht_node),
204 .automatic_shrinking = true,
207 static int mlxsw_sp_acl_tcam_group_update(struct mlxsw_sp *mlxsw_sp,
208 struct mlxsw_sp_acl_tcam_group *group)
210 struct mlxsw_sp_acl_tcam_region *region;
211 char pagt_pl[MLXSW_REG_PAGT_LEN];
214 mlxsw_reg_pagt_pack(pagt_pl, group->id);
215 list_for_each_entry(region, &group->region_list, list) {
218 /* Check if the next entry in the list has the same vregion. */
219 if (region->list.next != &group->region_list &&
220 list_next_entry(region, list)->vregion == region->vregion)
222 mlxsw_reg_pagt_acl_id_pack(pagt_pl, acl_index++,
225 mlxsw_reg_pagt_size_set(pagt_pl, acl_index);
226 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pagt), pagt_pl);
230 mlxsw_sp_acl_tcam_group_add(struct mlxsw_sp_acl_tcam *tcam,
231 struct mlxsw_sp_acl_tcam_group *group)
236 INIT_LIST_HEAD(&group->region_list);
238 err = mlxsw_sp_acl_tcam_group_id_get(tcam, &group->id);
242 mutex_init(&group->lock);
247 static void mlxsw_sp_acl_tcam_group_del(struct mlxsw_sp_acl_tcam_group *group)
249 struct mlxsw_sp_acl_tcam *tcam = group->tcam;
251 mutex_destroy(&group->lock);
252 mlxsw_sp_acl_tcam_group_id_put(tcam, group->id);
253 WARN_ON(!list_empty(&group->region_list));
257 mlxsw_sp_acl_tcam_vgroup_add(struct mlxsw_sp *mlxsw_sp,
258 struct mlxsw_sp_acl_tcam *tcam,
259 struct mlxsw_sp_acl_tcam_vgroup *vgroup,
260 const struct mlxsw_sp_acl_tcam_pattern *patterns,
261 unsigned int patterns_count,
262 struct mlxsw_afk_element_usage *tmplt_elusage,
263 bool vregion_rehash_enabled,
264 unsigned int *p_min_prio,
265 unsigned int *p_max_prio)
269 vgroup->patterns = patterns;
270 vgroup->patterns_count = patterns_count;
271 vgroup->vregion_rehash_enabled = vregion_rehash_enabled;
272 vgroup->p_min_prio = p_min_prio;
273 vgroup->p_max_prio = p_max_prio;
276 vgroup->tmplt_elusage_set = true;
277 memcpy(&vgroup->tmplt_elusage, tmplt_elusage,
278 sizeof(vgroup->tmplt_elusage));
280 INIT_LIST_HEAD(&vgroup->vregion_list);
282 err = mlxsw_sp_acl_tcam_group_add(tcam, &vgroup->group);
286 err = rhashtable_init(&vgroup->vchunk_ht,
287 &mlxsw_sp_acl_tcam_vchunk_ht_params);
289 goto err_rhashtable_init;
294 mlxsw_sp_acl_tcam_group_del(&vgroup->group);
299 mlxsw_sp_acl_tcam_vgroup_del(struct mlxsw_sp_acl_tcam_vgroup *vgroup)
301 rhashtable_destroy(&vgroup->vchunk_ht);
302 mlxsw_sp_acl_tcam_group_del(&vgroup->group);
303 WARN_ON(!list_empty(&vgroup->vregion_list));
307 mlxsw_sp_acl_tcam_group_bind(struct mlxsw_sp *mlxsw_sp,
308 struct mlxsw_sp_acl_tcam_group *group,
309 struct mlxsw_sp_port *mlxsw_sp_port,
312 char ppbt_pl[MLXSW_REG_PPBT_LEN];
314 mlxsw_reg_ppbt_pack(ppbt_pl, ingress ? MLXSW_REG_PXBT_E_IACL :
315 MLXSW_REG_PXBT_E_EACL,
316 MLXSW_REG_PXBT_OP_BIND, mlxsw_sp_port->local_port,
318 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ppbt), ppbt_pl);
322 mlxsw_sp_acl_tcam_group_unbind(struct mlxsw_sp *mlxsw_sp,
323 struct mlxsw_sp_acl_tcam_group *group,
324 struct mlxsw_sp_port *mlxsw_sp_port,
327 char ppbt_pl[MLXSW_REG_PPBT_LEN];
329 mlxsw_reg_ppbt_pack(ppbt_pl, ingress ? MLXSW_REG_PXBT_E_IACL :
330 MLXSW_REG_PXBT_E_EACL,
331 MLXSW_REG_PXBT_OP_UNBIND, mlxsw_sp_port->local_port,
333 mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ppbt), ppbt_pl);
337 mlxsw_sp_acl_tcam_group_id(struct mlxsw_sp_acl_tcam_group *group)
343 mlxsw_sp_acl_tcam_vregion_prio(struct mlxsw_sp_acl_tcam_vregion *vregion)
345 struct mlxsw_sp_acl_tcam_vchunk *vchunk;
347 if (list_empty(&vregion->vchunk_list))
349 /* As a priority of a vregion, return priority of the first vchunk */
350 vchunk = list_first_entry(&vregion->vchunk_list,
351 typeof(*vchunk), list);
352 return vchunk->priority;
356 mlxsw_sp_acl_tcam_vregion_max_prio(struct mlxsw_sp_acl_tcam_vregion *vregion)
358 struct mlxsw_sp_acl_tcam_vchunk *vchunk;
360 if (list_empty(&vregion->vchunk_list))
362 vchunk = list_last_entry(&vregion->vchunk_list,
363 typeof(*vchunk), list);
364 return vchunk->priority;
368 mlxsw_sp_acl_tcam_vgroup_prio_update(struct mlxsw_sp_acl_tcam_vgroup *vgroup)
370 struct mlxsw_sp_acl_tcam_vregion *vregion;
372 if (list_empty(&vgroup->vregion_list))
374 vregion = list_first_entry(&vgroup->vregion_list,
375 typeof(*vregion), list);
376 *vgroup->p_min_prio = mlxsw_sp_acl_tcam_vregion_prio(vregion);
377 vregion = list_last_entry(&vgroup->vregion_list,
378 typeof(*vregion), list);
379 *vgroup->p_max_prio = mlxsw_sp_acl_tcam_vregion_max_prio(vregion);
383 mlxsw_sp_acl_tcam_group_region_attach(struct mlxsw_sp *mlxsw_sp,
384 struct mlxsw_sp_acl_tcam_group *group,
385 struct mlxsw_sp_acl_tcam_region *region,
386 unsigned int priority,
387 struct mlxsw_sp_acl_tcam_region *next_region)
389 struct mlxsw_sp_acl_tcam_region *region2;
390 struct list_head *pos;
393 mutex_lock(&group->lock);
394 if (group->region_count == group->tcam->max_group_size) {
396 goto err_region_count_check;
400 /* If the next region is defined, place the new one
401 * before it. The next one is a sibling.
403 pos = &next_region->list;
405 /* Position the region inside the list according to priority */
406 list_for_each(pos, &group->region_list) {
407 region2 = list_entry(pos, typeof(*region2), list);
408 if (mlxsw_sp_acl_tcam_vregion_prio(region2->vregion) >
413 list_add_tail(®ion->list, pos);
414 region->group = group;
416 err = mlxsw_sp_acl_tcam_group_update(mlxsw_sp, group);
418 goto err_group_update;
420 group->region_count++;
421 mutex_unlock(&group->lock);
425 list_del(®ion->list);
426 err_region_count_check:
427 mutex_unlock(&group->lock);
432 mlxsw_sp_acl_tcam_group_region_detach(struct mlxsw_sp *mlxsw_sp,
433 struct mlxsw_sp_acl_tcam_region *region)
435 struct mlxsw_sp_acl_tcam_group *group = region->group;
437 mutex_lock(&group->lock);
438 list_del(®ion->list);
439 group->region_count--;
440 mlxsw_sp_acl_tcam_group_update(mlxsw_sp, group);
441 mutex_unlock(&group->lock);
445 mlxsw_sp_acl_tcam_vgroup_vregion_attach(struct mlxsw_sp *mlxsw_sp,
446 struct mlxsw_sp_acl_tcam_vgroup *vgroup,
447 struct mlxsw_sp_acl_tcam_vregion *vregion,
448 unsigned int priority)
450 struct mlxsw_sp_acl_tcam_vregion *vregion2;
451 struct list_head *pos;
454 /* Position the vregion inside the list according to priority */
455 list_for_each(pos, &vgroup->vregion_list) {
456 vregion2 = list_entry(pos, typeof(*vregion2), list);
457 if (mlxsw_sp_acl_tcam_vregion_prio(vregion2) > priority)
460 list_add_tail(&vregion->list, pos);
462 err = mlxsw_sp_acl_tcam_group_region_attach(mlxsw_sp, &vgroup->group,
466 goto err_region_attach;
471 list_del(&vregion->list);
476 mlxsw_sp_acl_tcam_vgroup_vregion_detach(struct mlxsw_sp *mlxsw_sp,
477 struct mlxsw_sp_acl_tcam_vregion *vregion)
479 list_del(&vregion->list);
480 if (vregion->region2)
481 mlxsw_sp_acl_tcam_group_region_detach(mlxsw_sp,
483 mlxsw_sp_acl_tcam_group_region_detach(mlxsw_sp, vregion->region);
486 static struct mlxsw_sp_acl_tcam_vregion *
487 mlxsw_sp_acl_tcam_vgroup_vregion_find(struct mlxsw_sp_acl_tcam_vgroup *vgroup,
488 unsigned int priority,
489 struct mlxsw_afk_element_usage *elusage,
492 struct mlxsw_sp_acl_tcam_vregion *vregion, *vregion2;
493 struct list_head *pos;
496 list_for_each(pos, &vgroup->vregion_list) {
497 vregion = list_entry(pos, typeof(*vregion), list);
499 /* First, check if the requested priority does not rather belong
500 * under some of the next vregions.
502 if (pos->next != &vgroup->vregion_list) { /* not last */
503 vregion2 = list_entry(pos->next, typeof(*vregion2),
506 mlxsw_sp_acl_tcam_vregion_prio(vregion2))
510 issubset = mlxsw_afk_key_info_subset(vregion->key_info,
513 /* If requested element usage would not fit and the priority
514 * is lower than the currently inspected vregion we cannot
515 * use this region, so return NULL to indicate new vregion has
519 priority < mlxsw_sp_acl_tcam_vregion_prio(vregion))
522 /* If requested element usage would not fit and the priority
523 * is higher than the currently inspected vregion we cannot
524 * use this vregion. There is still some hope that the next
525 * vregion would be the fit. So let it be processed and
526 * eventually break at the check right above this.
529 priority > mlxsw_sp_acl_tcam_vregion_max_prio(vregion))
532 /* Indicate if the vregion needs to be split in order to add
533 * the requested priority. Split is needed when requested
534 * element usage won't fit into the found vregion.
536 *p_need_split = !issubset;
539 return NULL; /* New vregion has to be created. */
543 mlxsw_sp_acl_tcam_vgroup_use_patterns(struct mlxsw_sp_acl_tcam_vgroup *vgroup,
544 struct mlxsw_afk_element_usage *elusage,
545 struct mlxsw_afk_element_usage *out)
547 const struct mlxsw_sp_acl_tcam_pattern *pattern;
550 /* In case the template is set, we don't have to look up the pattern
551 * and just use the template.
553 if (vgroup->tmplt_elusage_set) {
554 memcpy(out, &vgroup->tmplt_elusage, sizeof(*out));
555 WARN_ON(!mlxsw_afk_element_usage_subset(elusage, out));
559 for (i = 0; i < vgroup->patterns_count; i++) {
560 pattern = &vgroup->patterns[i];
561 mlxsw_afk_element_usage_fill(out, pattern->elements,
562 pattern->elements_count);
563 if (mlxsw_afk_element_usage_subset(elusage, out))
566 memcpy(out, elusage, sizeof(*out));
570 mlxsw_sp_acl_tcam_region_alloc(struct mlxsw_sp *mlxsw_sp,
571 struct mlxsw_sp_acl_tcam_region *region)
573 struct mlxsw_afk_key_info *key_info = region->key_info;
574 char ptar_pl[MLXSW_REG_PTAR_LEN];
575 unsigned int encodings_count;
579 mlxsw_reg_ptar_pack(ptar_pl, MLXSW_REG_PTAR_OP_ALLOC,
581 MLXSW_SP_ACL_TCAM_REGION_BASE_COUNT,
582 region->id, region->tcam_region_info);
583 encodings_count = mlxsw_afk_key_info_blocks_count_get(key_info);
584 for (i = 0; i < encodings_count; i++) {
587 encoding = mlxsw_afk_key_info_block_encoding_get(key_info, i);
588 mlxsw_reg_ptar_key_id_pack(ptar_pl, i, encoding);
590 err = mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ptar), ptar_pl);
593 mlxsw_reg_ptar_unpack(ptar_pl, region->tcam_region_info);
598 mlxsw_sp_acl_tcam_region_free(struct mlxsw_sp *mlxsw_sp,
599 struct mlxsw_sp_acl_tcam_region *region)
601 char ptar_pl[MLXSW_REG_PTAR_LEN];
603 mlxsw_reg_ptar_pack(ptar_pl, MLXSW_REG_PTAR_OP_FREE,
604 region->key_type, 0, region->id,
605 region->tcam_region_info);
606 mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(ptar), ptar_pl);
610 mlxsw_sp_acl_tcam_region_enable(struct mlxsw_sp *mlxsw_sp,
611 struct mlxsw_sp_acl_tcam_region *region)
613 char pacl_pl[MLXSW_REG_PACL_LEN];
615 mlxsw_reg_pacl_pack(pacl_pl, region->id, true,
616 region->tcam_region_info);
617 return mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pacl), pacl_pl);
621 mlxsw_sp_acl_tcam_region_disable(struct mlxsw_sp *mlxsw_sp,
622 struct mlxsw_sp_acl_tcam_region *region)
624 char pacl_pl[MLXSW_REG_PACL_LEN];
626 mlxsw_reg_pacl_pack(pacl_pl, region->id, false,
627 region->tcam_region_info);
628 mlxsw_reg_write(mlxsw_sp->core, MLXSW_REG(pacl), pacl_pl);
631 static struct mlxsw_sp_acl_tcam_region *
632 mlxsw_sp_acl_tcam_region_create(struct mlxsw_sp *mlxsw_sp,
633 struct mlxsw_sp_acl_tcam *tcam,
634 struct mlxsw_sp_acl_tcam_vregion *vregion,
637 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
638 struct mlxsw_sp_acl_tcam_region *region;
641 region = kzalloc(sizeof(*region) + ops->region_priv_size, GFP_KERNEL);
643 return ERR_PTR(-ENOMEM);
644 region->mlxsw_sp = mlxsw_sp;
645 region->vregion = vregion;
646 region->key_info = vregion->key_info;
648 err = mlxsw_sp_acl_tcam_region_id_get(tcam, ®ion->id);
650 goto err_region_id_get;
652 err = ops->region_associate(mlxsw_sp, region);
654 goto err_tcam_region_associate;
656 region->key_type = ops->key_type;
657 err = mlxsw_sp_acl_tcam_region_alloc(mlxsw_sp, region);
659 goto err_tcam_region_alloc;
661 err = mlxsw_sp_acl_tcam_region_enable(mlxsw_sp, region);
663 goto err_tcam_region_enable;
665 err = ops->region_init(mlxsw_sp, region->priv, tcam->priv,
668 goto err_tcam_region_init;
672 err_tcam_region_init:
673 mlxsw_sp_acl_tcam_region_disable(mlxsw_sp, region);
674 err_tcam_region_enable:
675 mlxsw_sp_acl_tcam_region_free(mlxsw_sp, region);
676 err_tcam_region_alloc:
677 err_tcam_region_associate:
678 mlxsw_sp_acl_tcam_region_id_put(tcam, region->id);
685 mlxsw_sp_acl_tcam_region_destroy(struct mlxsw_sp *mlxsw_sp,
686 struct mlxsw_sp_acl_tcam_region *region)
688 struct mlxsw_sp_acl_tcam *tcam = mlxsw_sp_acl_to_tcam(mlxsw_sp->acl);
689 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
691 ops->region_fini(mlxsw_sp, region->priv);
692 mlxsw_sp_acl_tcam_region_disable(mlxsw_sp, region);
693 mlxsw_sp_acl_tcam_region_free(mlxsw_sp, region);
694 mlxsw_sp_acl_tcam_region_id_put(tcam, region->id);
699 mlxsw_sp_acl_tcam_vregion_rehash_work_schedule(struct mlxsw_sp_acl_tcam_vregion *vregion)
701 unsigned long interval = vregion->tcam->vregion_rehash_intrvl;
705 mlxsw_core_schedule_dw(&vregion->rehash.dw,
706 msecs_to_jiffies(interval));
710 mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp,
711 struct mlxsw_sp_acl_tcam_vregion *vregion,
714 static void mlxsw_sp_acl_tcam_vregion_rehash_work(struct work_struct *work)
716 struct mlxsw_sp_acl_tcam_vregion *vregion =
717 container_of(work, struct mlxsw_sp_acl_tcam_vregion,
719 int credits = MLXSW_SP_ACL_TCAM_VREGION_REHASH_CREDITS;
721 mutex_lock(&vregion->lock);
722 mlxsw_sp_acl_tcam_vregion_rehash(vregion->mlxsw_sp, vregion, &credits);
723 mutex_unlock(&vregion->lock);
725 /* Rehash gone out of credits so it was interrupted.
726 * Schedule the work as soon as possible to continue.
728 mlxsw_core_schedule_dw(&vregion->rehash.dw, 0);
730 mlxsw_sp_acl_tcam_vregion_rehash_work_schedule(vregion);
734 mlxsw_sp_acl_tcam_rehash_ctx_vchunk_reset(struct mlxsw_sp_acl_tcam_rehash_ctx *ctx)
736 /* The entry markers are relative to the current chunk and therefore
737 * needs to be reset together with the chunk marker.
739 ctx->current_vchunk = NULL;
740 ctx->start_ventry = NULL;
741 ctx->stop_ventry = NULL;
745 mlxsw_sp_acl_tcam_rehash_ctx_vchunk_changed(struct mlxsw_sp_acl_tcam_vchunk *vchunk)
747 struct mlxsw_sp_acl_tcam_vregion *vregion = vchunk->vregion;
749 /* If a rule was added or deleted from vchunk which is currently
750 * under rehash migration, we have to reset the ventry pointers
751 * to make sure all rules are properly migrated.
753 if (vregion->rehash.ctx.current_vchunk == vchunk) {
754 vregion->rehash.ctx.start_ventry = NULL;
755 vregion->rehash.ctx.stop_ventry = NULL;
760 mlxsw_sp_acl_tcam_rehash_ctx_vregion_changed(struct mlxsw_sp_acl_tcam_vregion *vregion)
762 /* If a chunk was added or deleted from vregion we have to reset
763 * the current chunk pointer to make sure all chunks
764 * are properly migrated.
766 mlxsw_sp_acl_tcam_rehash_ctx_vchunk_reset(&vregion->rehash.ctx);
769 static struct mlxsw_sp_acl_tcam_vregion *
770 mlxsw_sp_acl_tcam_vregion_create(struct mlxsw_sp *mlxsw_sp,
771 struct mlxsw_sp_acl_tcam_vgroup *vgroup,
772 unsigned int priority,
773 struct mlxsw_afk_element_usage *elusage)
775 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
776 struct mlxsw_afk *afk = mlxsw_sp_acl_afk(mlxsw_sp->acl);
777 struct mlxsw_sp_acl_tcam *tcam = vgroup->group.tcam;
778 struct mlxsw_sp_acl_tcam_vregion *vregion;
781 vregion = kzalloc(sizeof(*vregion), GFP_KERNEL);
783 return ERR_PTR(-ENOMEM);
784 INIT_LIST_HEAD(&vregion->vchunk_list);
785 mutex_init(&vregion->lock);
786 vregion->tcam = tcam;
787 vregion->mlxsw_sp = mlxsw_sp;
788 vregion->vgroup = vgroup;
789 refcount_set(&vregion->ref_count, 1);
791 vregion->key_info = mlxsw_afk_key_info_get(afk, elusage);
792 if (IS_ERR(vregion->key_info)) {
793 err = PTR_ERR(vregion->key_info);
794 goto err_key_info_get;
797 vregion->region = mlxsw_sp_acl_tcam_region_create(mlxsw_sp, tcam,
799 if (IS_ERR(vregion->region)) {
800 err = PTR_ERR(vregion->region);
801 goto err_region_create;
804 err = mlxsw_sp_acl_tcam_vgroup_vregion_attach(mlxsw_sp, vgroup, vregion,
807 goto err_vgroup_vregion_attach;
809 if (vgroup->vregion_rehash_enabled && ops->region_rehash_hints_get) {
810 /* Create the delayed work for vregion periodic rehash */
811 INIT_DELAYED_WORK(&vregion->rehash.dw,
812 mlxsw_sp_acl_tcam_vregion_rehash_work);
813 mlxsw_sp_acl_tcam_vregion_rehash_work_schedule(vregion);
814 mutex_lock(&tcam->lock);
815 list_add_tail(&vregion->tlist, &tcam->vregion_list);
816 mutex_unlock(&tcam->lock);
821 err_vgroup_vregion_attach:
822 mlxsw_sp_acl_tcam_region_destroy(mlxsw_sp, vregion->region);
824 mlxsw_afk_key_info_put(vregion->key_info);
831 mlxsw_sp_acl_tcam_vregion_destroy(struct mlxsw_sp *mlxsw_sp,
832 struct mlxsw_sp_acl_tcam_vregion *vregion)
834 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
835 struct mlxsw_sp_acl_tcam_vgroup *vgroup = vregion->vgroup;
836 struct mlxsw_sp_acl_tcam *tcam = vregion->tcam;
838 if (vgroup->vregion_rehash_enabled && ops->region_rehash_hints_get) {
839 struct mlxsw_sp_acl_tcam_rehash_ctx *ctx = &vregion->rehash.ctx;
841 mutex_lock(&tcam->lock);
842 list_del(&vregion->tlist);
843 mutex_unlock(&tcam->lock);
844 if (cancel_delayed_work_sync(&vregion->rehash.dw) &&
846 ops->region_rehash_hints_put(ctx->hints_priv);
848 mlxsw_sp_acl_tcam_vgroup_vregion_detach(mlxsw_sp, vregion);
849 if (vregion->region2)
850 mlxsw_sp_acl_tcam_region_destroy(mlxsw_sp, vregion->region2);
851 mlxsw_sp_acl_tcam_region_destroy(mlxsw_sp, vregion->region);
852 mlxsw_afk_key_info_put(vregion->key_info);
853 mutex_destroy(&vregion->lock);
857 static struct mlxsw_sp_acl_tcam_vregion *
858 mlxsw_sp_acl_tcam_vregion_get(struct mlxsw_sp *mlxsw_sp,
859 struct mlxsw_sp_acl_tcam_vgroup *vgroup,
860 unsigned int priority,
861 struct mlxsw_afk_element_usage *elusage)
863 struct mlxsw_afk_element_usage vregion_elusage;
864 struct mlxsw_sp_acl_tcam_vregion *vregion;
867 vregion = mlxsw_sp_acl_tcam_vgroup_vregion_find(vgroup, priority,
868 elusage, &need_split);
871 /* According to priority, new vchunk should belong to
872 * an existing vregion. However, this vchunk needs
873 * elements that vregion does not contain. We need
874 * to split the existing vregion into two and create
875 * a new vregion for the new vchunk in between.
876 * This is not supported now.
878 return ERR_PTR(-EOPNOTSUPP);
880 refcount_inc(&vregion->ref_count);
884 mlxsw_sp_acl_tcam_vgroup_use_patterns(vgroup, elusage,
887 return mlxsw_sp_acl_tcam_vregion_create(mlxsw_sp, vgroup, priority,
892 mlxsw_sp_acl_tcam_vregion_put(struct mlxsw_sp *mlxsw_sp,
893 struct mlxsw_sp_acl_tcam_vregion *vregion)
895 if (!refcount_dec_and_test(&vregion->ref_count))
897 mlxsw_sp_acl_tcam_vregion_destroy(mlxsw_sp, vregion);
900 static struct mlxsw_sp_acl_tcam_chunk *
901 mlxsw_sp_acl_tcam_chunk_create(struct mlxsw_sp *mlxsw_sp,
902 struct mlxsw_sp_acl_tcam_vchunk *vchunk,
903 struct mlxsw_sp_acl_tcam_region *region)
905 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
906 struct mlxsw_sp_acl_tcam_chunk *chunk;
908 chunk = kzalloc(sizeof(*chunk) + ops->chunk_priv_size, GFP_KERNEL);
910 return ERR_PTR(-ENOMEM);
911 chunk->vchunk = vchunk;
912 chunk->region = region;
914 ops->chunk_init(region->priv, chunk->priv, vchunk->priority);
919 mlxsw_sp_acl_tcam_chunk_destroy(struct mlxsw_sp *mlxsw_sp,
920 struct mlxsw_sp_acl_tcam_chunk *chunk)
922 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
924 ops->chunk_fini(chunk->priv);
928 static struct mlxsw_sp_acl_tcam_vchunk *
929 mlxsw_sp_acl_tcam_vchunk_create(struct mlxsw_sp *mlxsw_sp,
930 struct mlxsw_sp_acl_tcam_vgroup *vgroup,
931 unsigned int priority,
932 struct mlxsw_afk_element_usage *elusage)
934 struct mlxsw_sp_acl_tcam_vchunk *vchunk, *vchunk2;
935 struct mlxsw_sp_acl_tcam_vregion *vregion;
936 struct list_head *pos;
939 if (priority == MLXSW_SP_ACL_TCAM_CATCHALL_PRIO)
940 return ERR_PTR(-EINVAL);
942 vchunk = kzalloc(sizeof(*vchunk), GFP_KERNEL);
944 return ERR_PTR(-ENOMEM);
945 INIT_LIST_HEAD(&vchunk->ventry_list);
946 vchunk->priority = priority;
947 vchunk->vgroup = vgroup;
948 refcount_set(&vchunk->ref_count, 1);
950 vregion = mlxsw_sp_acl_tcam_vregion_get(mlxsw_sp, vgroup,
952 if (IS_ERR(vregion)) {
953 err = PTR_ERR(vregion);
954 goto err_vregion_get;
957 vchunk->vregion = vregion;
959 err = rhashtable_insert_fast(&vgroup->vchunk_ht, &vchunk->ht_node,
960 mlxsw_sp_acl_tcam_vchunk_ht_params);
962 goto err_rhashtable_insert;
964 mutex_lock(&vregion->lock);
965 vchunk->chunk = mlxsw_sp_acl_tcam_chunk_create(mlxsw_sp, vchunk,
966 vchunk->vregion->region);
967 if (IS_ERR(vchunk->chunk)) {
968 mutex_unlock(&vregion->lock);
969 err = PTR_ERR(vchunk->chunk);
970 goto err_chunk_create;
973 mlxsw_sp_acl_tcam_rehash_ctx_vregion_changed(vregion);
975 /* Position the vchunk inside the list according to priority */
976 list_for_each(pos, &vregion->vchunk_list) {
977 vchunk2 = list_entry(pos, typeof(*vchunk2), list);
978 if (vchunk2->priority > priority)
981 list_add_tail(&vchunk->list, pos);
982 mutex_unlock(&vregion->lock);
983 mlxsw_sp_acl_tcam_vgroup_prio_update(vgroup);
988 rhashtable_remove_fast(&vgroup->vchunk_ht, &vchunk->ht_node,
989 mlxsw_sp_acl_tcam_vchunk_ht_params);
990 err_rhashtable_insert:
991 mlxsw_sp_acl_tcam_vregion_put(mlxsw_sp, vregion);
998 mlxsw_sp_acl_tcam_vchunk_destroy(struct mlxsw_sp *mlxsw_sp,
999 struct mlxsw_sp_acl_tcam_vchunk *vchunk)
1001 struct mlxsw_sp_acl_tcam_vregion *vregion = vchunk->vregion;
1002 struct mlxsw_sp_acl_tcam_vgroup *vgroup = vchunk->vgroup;
1004 mutex_lock(&vregion->lock);
1005 mlxsw_sp_acl_tcam_rehash_ctx_vregion_changed(vregion);
1006 list_del(&vchunk->list);
1008 mlxsw_sp_acl_tcam_chunk_destroy(mlxsw_sp, vchunk->chunk2);
1009 mlxsw_sp_acl_tcam_chunk_destroy(mlxsw_sp, vchunk->chunk);
1010 mutex_unlock(&vregion->lock);
1011 rhashtable_remove_fast(&vgroup->vchunk_ht, &vchunk->ht_node,
1012 mlxsw_sp_acl_tcam_vchunk_ht_params);
1013 mlxsw_sp_acl_tcam_vregion_put(mlxsw_sp, vchunk->vregion);
1015 mlxsw_sp_acl_tcam_vgroup_prio_update(vgroup);
1018 static struct mlxsw_sp_acl_tcam_vchunk *
1019 mlxsw_sp_acl_tcam_vchunk_get(struct mlxsw_sp *mlxsw_sp,
1020 struct mlxsw_sp_acl_tcam_vgroup *vgroup,
1021 unsigned int priority,
1022 struct mlxsw_afk_element_usage *elusage)
1024 struct mlxsw_sp_acl_tcam_vchunk *vchunk;
1026 vchunk = rhashtable_lookup_fast(&vgroup->vchunk_ht, &priority,
1027 mlxsw_sp_acl_tcam_vchunk_ht_params);
1029 if (WARN_ON(!mlxsw_afk_key_info_subset(vchunk->vregion->key_info,
1031 return ERR_PTR(-EINVAL);
1032 refcount_inc(&vchunk->ref_count);
1035 return mlxsw_sp_acl_tcam_vchunk_create(mlxsw_sp, vgroup,
1040 mlxsw_sp_acl_tcam_vchunk_put(struct mlxsw_sp *mlxsw_sp,
1041 struct mlxsw_sp_acl_tcam_vchunk *vchunk)
1043 if (!refcount_dec_and_test(&vchunk->ref_count))
1045 mlxsw_sp_acl_tcam_vchunk_destroy(mlxsw_sp, vchunk);
1048 static struct mlxsw_sp_acl_tcam_entry *
1049 mlxsw_sp_acl_tcam_entry_create(struct mlxsw_sp *mlxsw_sp,
1050 struct mlxsw_sp_acl_tcam_ventry *ventry,
1051 struct mlxsw_sp_acl_tcam_chunk *chunk)
1053 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
1054 struct mlxsw_sp_acl_tcam_entry *entry;
1057 entry = kzalloc(sizeof(*entry) + ops->entry_priv_size, GFP_KERNEL);
1059 return ERR_PTR(-ENOMEM);
1060 entry->ventry = ventry;
1061 entry->chunk = chunk;
1063 err = ops->entry_add(mlxsw_sp, chunk->region->priv, chunk->priv,
1064 entry->priv, ventry->rulei);
1072 return ERR_PTR(err);
1075 static void mlxsw_sp_acl_tcam_entry_destroy(struct mlxsw_sp *mlxsw_sp,
1076 struct mlxsw_sp_acl_tcam_entry *entry)
1078 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
1080 ops->entry_del(mlxsw_sp, entry->chunk->region->priv,
1081 entry->chunk->priv, entry->priv);
1086 mlxsw_sp_acl_tcam_entry_action_replace(struct mlxsw_sp *mlxsw_sp,
1087 struct mlxsw_sp_acl_tcam_region *region,
1088 struct mlxsw_sp_acl_tcam_entry *entry,
1089 struct mlxsw_sp_acl_rule_info *rulei)
1091 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
1093 return ops->entry_action_replace(mlxsw_sp, region->priv,
1094 entry->priv, rulei);
1098 mlxsw_sp_acl_tcam_entry_activity_get(struct mlxsw_sp *mlxsw_sp,
1099 struct mlxsw_sp_acl_tcam_entry *entry,
1102 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
1104 return ops->entry_activity_get(mlxsw_sp, entry->chunk->region->priv,
1105 entry->priv, activity);
1108 static int mlxsw_sp_acl_tcam_ventry_add(struct mlxsw_sp *mlxsw_sp,
1109 struct mlxsw_sp_acl_tcam_vgroup *vgroup,
1110 struct mlxsw_sp_acl_tcam_ventry *ventry,
1111 struct mlxsw_sp_acl_rule_info *rulei)
1113 struct mlxsw_sp_acl_tcam_vregion *vregion;
1114 struct mlxsw_sp_acl_tcam_vchunk *vchunk;
1117 vchunk = mlxsw_sp_acl_tcam_vchunk_get(mlxsw_sp, vgroup, rulei->priority,
1118 &rulei->values.elusage);
1120 return PTR_ERR(vchunk);
1122 ventry->vchunk = vchunk;
1123 ventry->rulei = rulei;
1124 vregion = vchunk->vregion;
1126 mutex_lock(&vregion->lock);
1127 ventry->entry = mlxsw_sp_acl_tcam_entry_create(mlxsw_sp, ventry,
1129 if (IS_ERR(ventry->entry)) {
1130 mutex_unlock(&vregion->lock);
1131 err = PTR_ERR(ventry->entry);
1132 goto err_entry_create;
1135 list_add_tail(&ventry->list, &vchunk->ventry_list);
1136 mlxsw_sp_acl_tcam_rehash_ctx_vchunk_changed(vchunk);
1137 mutex_unlock(&vregion->lock);
1142 mlxsw_sp_acl_tcam_vchunk_put(mlxsw_sp, vchunk);
1146 static void mlxsw_sp_acl_tcam_ventry_del(struct mlxsw_sp *mlxsw_sp,
1147 struct mlxsw_sp_acl_tcam_ventry *ventry)
1149 struct mlxsw_sp_acl_tcam_vchunk *vchunk = ventry->vchunk;
1150 struct mlxsw_sp_acl_tcam_vregion *vregion = vchunk->vregion;
1152 mutex_lock(&vregion->lock);
1153 mlxsw_sp_acl_tcam_rehash_ctx_vchunk_changed(vchunk);
1154 list_del(&ventry->list);
1155 mlxsw_sp_acl_tcam_entry_destroy(mlxsw_sp, ventry->entry);
1156 mutex_unlock(&vregion->lock);
1157 mlxsw_sp_acl_tcam_vchunk_put(mlxsw_sp, vchunk);
1161 mlxsw_sp_acl_tcam_ventry_action_replace(struct mlxsw_sp *mlxsw_sp,
1162 struct mlxsw_sp_acl_tcam_ventry *ventry,
1163 struct mlxsw_sp_acl_rule_info *rulei)
1165 struct mlxsw_sp_acl_tcam_vchunk *vchunk = ventry->vchunk;
1167 return mlxsw_sp_acl_tcam_entry_action_replace(mlxsw_sp,
1168 vchunk->vregion->region,
1169 ventry->entry, rulei);
1173 mlxsw_sp_acl_tcam_ventry_activity_get(struct mlxsw_sp *mlxsw_sp,
1174 struct mlxsw_sp_acl_tcam_ventry *ventry,
1177 struct mlxsw_sp_acl_tcam_vregion *vregion = ventry->vchunk->vregion;
1180 mutex_lock(&vregion->lock);
1181 err = mlxsw_sp_acl_tcam_entry_activity_get(mlxsw_sp, ventry->entry,
1183 mutex_unlock(&vregion->lock);
1188 mlxsw_sp_acl_tcam_ventry_migrate(struct mlxsw_sp *mlxsw_sp,
1189 struct mlxsw_sp_acl_tcam_ventry *ventry,
1190 struct mlxsw_sp_acl_tcam_chunk *chunk,
1193 struct mlxsw_sp_acl_tcam_entry *new_entry;
1195 /* First check if the entry is not already where we want it to be. */
1196 if (ventry->entry->chunk == chunk)
1199 if (--(*credits) < 0)
1202 new_entry = mlxsw_sp_acl_tcam_entry_create(mlxsw_sp, ventry, chunk);
1203 if (IS_ERR(new_entry))
1204 return PTR_ERR(new_entry);
1205 mlxsw_sp_acl_tcam_entry_destroy(mlxsw_sp, ventry->entry);
1206 ventry->entry = new_entry;
1211 mlxsw_sp_acl_tcam_vchunk_migrate_start(struct mlxsw_sp *mlxsw_sp,
1212 struct mlxsw_sp_acl_tcam_vchunk *vchunk,
1213 struct mlxsw_sp_acl_tcam_region *region,
1214 struct mlxsw_sp_acl_tcam_rehash_ctx *ctx)
1216 struct mlxsw_sp_acl_tcam_chunk *new_chunk;
1218 WARN_ON(vchunk->chunk2);
1220 new_chunk = mlxsw_sp_acl_tcam_chunk_create(mlxsw_sp, vchunk, region);
1221 if (IS_ERR(new_chunk))
1222 return PTR_ERR(new_chunk);
1223 vchunk->chunk2 = vchunk->chunk;
1224 vchunk->chunk = new_chunk;
1225 ctx->current_vchunk = vchunk;
1226 ctx->start_ventry = NULL;
1227 ctx->stop_ventry = NULL;
1232 mlxsw_sp_acl_tcam_vchunk_migrate_end(struct mlxsw_sp *mlxsw_sp,
1233 struct mlxsw_sp_acl_tcam_vchunk *vchunk,
1234 struct mlxsw_sp_acl_tcam_rehash_ctx *ctx)
1236 mlxsw_sp_acl_tcam_chunk_destroy(mlxsw_sp, vchunk->chunk2);
1237 vchunk->chunk2 = NULL;
1238 mlxsw_sp_acl_tcam_rehash_ctx_vchunk_reset(ctx);
1242 mlxsw_sp_acl_tcam_vchunk_migrate_one(struct mlxsw_sp *mlxsw_sp,
1243 struct mlxsw_sp_acl_tcam_vchunk *vchunk,
1244 struct mlxsw_sp_acl_tcam_region *region,
1245 struct mlxsw_sp_acl_tcam_rehash_ctx *ctx,
1248 struct mlxsw_sp_acl_tcam_ventry *ventry;
1251 if (vchunk->chunk->region != region) {
1252 err = mlxsw_sp_acl_tcam_vchunk_migrate_start(mlxsw_sp, vchunk,
1256 } else if (!vchunk->chunk2) {
1257 /* The chunk is already as it should be, nothing to do. */
1261 if (list_empty(&vchunk->ventry_list))
1264 /* If the migration got interrupted, we have the ventry to start from
1265 * stored in context.
1267 if (ctx->start_ventry)
1268 ventry = ctx->start_ventry;
1270 ventry = list_first_entry(&vchunk->ventry_list,
1271 typeof(*ventry), list);
1273 WARN_ON(ventry->vchunk != vchunk);
1275 list_for_each_entry_from(ventry, &vchunk->ventry_list, list) {
1276 /* During rollback, once we reach the ventry that failed
1277 * to migrate, we are done.
1279 if (ventry == ctx->stop_ventry)
1282 err = mlxsw_sp_acl_tcam_ventry_migrate(mlxsw_sp, ventry,
1283 vchunk->chunk, credits);
1285 if (ctx->this_is_rollback) {
1286 /* Save the ventry which we ended with and try
1287 * to continue later on.
1289 ctx->start_ventry = ventry;
1292 /* Swap the chunk and chunk2 pointers so the follow-up
1293 * rollback call will see the original chunk pointer
1296 swap(vchunk->chunk, vchunk->chunk2);
1297 /* The rollback has to be done from beginning of the
1298 * chunk, that is why we have to null the start_ventry.
1299 * However, we know where to stop the rollback,
1300 * at the current ventry.
1302 ctx->start_ventry = NULL;
1303 ctx->stop_ventry = ventry;
1305 } else if (*credits < 0) {
1306 /* We are out of credits, the rest of the ventries
1307 * will be migrated later. Save the ventry
1308 * which we ended with.
1310 ctx->start_ventry = ventry;
1316 mlxsw_sp_acl_tcam_vchunk_migrate_end(mlxsw_sp, vchunk, ctx);
1321 mlxsw_sp_acl_tcam_vchunk_migrate_all(struct mlxsw_sp *mlxsw_sp,
1322 struct mlxsw_sp_acl_tcam_vregion *vregion,
1323 struct mlxsw_sp_acl_tcam_rehash_ctx *ctx,
1326 struct mlxsw_sp_acl_tcam_vchunk *vchunk;
1329 if (list_empty(&vregion->vchunk_list))
1332 /* If the migration got interrupted, we have the vchunk
1333 * we are working on stored in context.
1335 if (ctx->current_vchunk)
1336 vchunk = ctx->current_vchunk;
1338 vchunk = list_first_entry(&vregion->vchunk_list,
1339 typeof(*vchunk), list);
1341 list_for_each_entry_from(vchunk, &vregion->vchunk_list, list) {
1342 err = mlxsw_sp_acl_tcam_vchunk_migrate_one(mlxsw_sp, vchunk,
1345 if (err || *credits < 0)
1352 mlxsw_sp_acl_tcam_vregion_migrate(struct mlxsw_sp *mlxsw_sp,
1353 struct mlxsw_sp_acl_tcam_vregion *vregion,
1354 struct mlxsw_sp_acl_tcam_rehash_ctx *ctx,
1359 trace_mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion);
1360 err = mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion,
1363 if (ctx->this_is_rollback)
1365 /* In case migration was not successful, we need to swap
1366 * so the original region pointer is assigned again
1367 * to vregion->region.
1369 swap(vregion->region, vregion->region2);
1370 mlxsw_sp_acl_tcam_rehash_ctx_vchunk_reset(ctx);
1371 ctx->this_is_rollback = true;
1372 err2 = mlxsw_sp_acl_tcam_vchunk_migrate_all(mlxsw_sp, vregion,
1375 trace_mlxsw_sp_acl_tcam_vregion_rehash_rollback_failed(mlxsw_sp,
1377 dev_err(mlxsw_sp->bus_info->dev, "Failed to rollback during vregion migration fail\n");
1378 /* Let the rollback to be continued later on. */
1381 trace_mlxsw_sp_acl_tcam_vregion_migrate_end(mlxsw_sp, vregion);
1386 mlxsw_sp_acl_tcam_vregion_rehash_in_progress(const struct mlxsw_sp_acl_tcam_rehash_ctx *ctx)
1388 return ctx->hints_priv;
1392 mlxsw_sp_acl_tcam_vregion_rehash_start(struct mlxsw_sp *mlxsw_sp,
1393 struct mlxsw_sp_acl_tcam_vregion *vregion,
1394 struct mlxsw_sp_acl_tcam_rehash_ctx *ctx)
1396 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
1397 unsigned int priority = mlxsw_sp_acl_tcam_vregion_prio(vregion);
1398 struct mlxsw_sp_acl_tcam_region *new_region;
1402 trace_mlxsw_sp_acl_tcam_vregion_rehash(mlxsw_sp, vregion);
1404 hints_priv = ops->region_rehash_hints_get(vregion->region->priv);
1405 if (IS_ERR(hints_priv))
1406 return PTR_ERR(hints_priv);
1408 new_region = mlxsw_sp_acl_tcam_region_create(mlxsw_sp, vregion->tcam,
1409 vregion, hints_priv);
1410 if (IS_ERR(new_region)) {
1411 err = PTR_ERR(new_region);
1412 goto err_region_create;
1415 /* vregion->region contains the pointer to the new region
1416 * we are going to migrate to.
1418 vregion->region2 = vregion->region;
1419 vregion->region = new_region;
1420 err = mlxsw_sp_acl_tcam_group_region_attach(mlxsw_sp,
1421 vregion->region2->group,
1422 new_region, priority,
1425 goto err_group_region_attach;
1427 ctx->hints_priv = hints_priv;
1428 ctx->this_is_rollback = false;
1429 mlxsw_sp_acl_tcam_rehash_ctx_vchunk_reset(ctx);
1433 err_group_region_attach:
1434 vregion->region = vregion->region2;
1435 vregion->region2 = NULL;
1436 mlxsw_sp_acl_tcam_region_destroy(mlxsw_sp, new_region);
1438 ops->region_rehash_hints_put(hints_priv);
1443 mlxsw_sp_acl_tcam_vregion_rehash_end(struct mlxsw_sp *mlxsw_sp,
1444 struct mlxsw_sp_acl_tcam_vregion *vregion,
1445 struct mlxsw_sp_acl_tcam_rehash_ctx *ctx)
1447 struct mlxsw_sp_acl_tcam_region *unused_region = vregion->region2;
1448 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
1450 vregion->region2 = NULL;
1451 mlxsw_sp_acl_tcam_group_region_detach(mlxsw_sp, unused_region);
1452 mlxsw_sp_acl_tcam_region_destroy(mlxsw_sp, unused_region);
1453 ops->region_rehash_hints_put(ctx->hints_priv);
1454 ctx->hints_priv = NULL;
1458 mlxsw_sp_acl_tcam_vregion_rehash(struct mlxsw_sp *mlxsw_sp,
1459 struct mlxsw_sp_acl_tcam_vregion *vregion,
1462 struct mlxsw_sp_acl_tcam_rehash_ctx *ctx = &vregion->rehash.ctx;
1465 /* Check if the previous rehash work was interrupted
1466 * which means we have to continue it now.
1467 * If not, start a new rehash.
1469 if (!mlxsw_sp_acl_tcam_vregion_rehash_in_progress(ctx)) {
1470 err = mlxsw_sp_acl_tcam_vregion_rehash_start(mlxsw_sp,
1474 dev_err(mlxsw_sp->bus_info->dev, "Failed get rehash hints\n");
1479 err = mlxsw_sp_acl_tcam_vregion_migrate(mlxsw_sp, vregion,
1482 dev_err_ratelimited(mlxsw_sp->bus_info->dev, "Failed to migrate vregion\n");
1487 mlxsw_sp_acl_tcam_vregion_rehash_end(mlxsw_sp, vregion, ctx);
1491 mlxsw_sp_acl_tcam_region_rehash_intrvl_get(struct devlink *devlink, u32 id,
1492 struct devlink_param_gset_ctx *ctx)
1494 struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
1495 struct mlxsw_sp_acl_tcam *tcam;
1496 struct mlxsw_sp *mlxsw_sp;
1498 mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
1499 tcam = mlxsw_sp_acl_to_tcam(mlxsw_sp->acl);
1500 ctx->val.vu32 = tcam->vregion_rehash_intrvl;
1506 mlxsw_sp_acl_tcam_region_rehash_intrvl_set(struct devlink *devlink, u32 id,
1507 struct devlink_param_gset_ctx *ctx)
1509 struct mlxsw_core *mlxsw_core = devlink_priv(devlink);
1510 struct mlxsw_sp_acl_tcam_vregion *vregion;
1511 struct mlxsw_sp_acl_tcam *tcam;
1512 struct mlxsw_sp *mlxsw_sp;
1513 u32 val = ctx->val.vu32;
1515 if (val < MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_MIN && val)
1518 mlxsw_sp = mlxsw_core_driver_priv(mlxsw_core);
1519 tcam = mlxsw_sp_acl_to_tcam(mlxsw_sp->acl);
1520 tcam->vregion_rehash_intrvl = val;
1521 mutex_lock(&tcam->lock);
1522 list_for_each_entry(vregion, &tcam->vregion_list, tlist) {
1524 mlxsw_core_schedule_dw(&vregion->rehash.dw, 0);
1526 cancel_delayed_work_sync(&vregion->rehash.dw);
1528 mutex_unlock(&tcam->lock);
1532 static const struct devlink_param mlxsw_sp_acl_tcam_rehash_params[] = {
1533 DEVLINK_PARAM_DRIVER(MLXSW_DEVLINK_PARAM_ID_ACL_REGION_REHASH_INTERVAL,
1534 "acl_region_rehash_interval",
1535 DEVLINK_PARAM_TYPE_U32,
1536 BIT(DEVLINK_PARAM_CMODE_RUNTIME),
1537 mlxsw_sp_acl_tcam_region_rehash_intrvl_get,
1538 mlxsw_sp_acl_tcam_region_rehash_intrvl_set,
1542 static int mlxsw_sp_acl_tcam_rehash_params_register(struct mlxsw_sp *mlxsw_sp)
1544 struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
1546 if (!mlxsw_sp->acl_tcam_ops->region_rehash_hints_get)
1549 return devl_params_register(devlink, mlxsw_sp_acl_tcam_rehash_params,
1550 ARRAY_SIZE(mlxsw_sp_acl_tcam_rehash_params));
1554 mlxsw_sp_acl_tcam_rehash_params_unregister(struct mlxsw_sp *mlxsw_sp)
1556 struct devlink *devlink = priv_to_devlink(mlxsw_sp->core);
1558 if (!mlxsw_sp->acl_tcam_ops->region_rehash_hints_get)
1561 devl_params_unregister(devlink, mlxsw_sp_acl_tcam_rehash_params,
1562 ARRAY_SIZE(mlxsw_sp_acl_tcam_rehash_params));
1565 int mlxsw_sp_acl_tcam_init(struct mlxsw_sp *mlxsw_sp,
1566 struct mlxsw_sp_acl_tcam *tcam)
1568 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
1569 u64 max_tcam_regions;
1574 mutex_init(&tcam->lock);
1575 tcam->vregion_rehash_intrvl =
1576 MLXSW_SP_ACL_TCAM_VREGION_REHASH_INTRVL_DFLT;
1577 INIT_LIST_HEAD(&tcam->vregion_list);
1579 err = mlxsw_sp_acl_tcam_rehash_params_register(mlxsw_sp);
1581 goto err_rehash_params_register;
1583 max_tcam_regions = MLXSW_CORE_RES_GET(mlxsw_sp->core,
1584 ACL_MAX_TCAM_REGIONS);
1585 max_regions = MLXSW_CORE_RES_GET(mlxsw_sp->core, ACL_MAX_REGIONS);
1587 /* Use 1:1 mapping between ACL region and TCAM region */
1588 if (max_tcam_regions < max_regions)
1589 max_regions = max_tcam_regions;
1591 ida_init(&tcam->used_regions);
1592 tcam->max_regions = max_regions;
1594 max_groups = MLXSW_CORE_RES_GET(mlxsw_sp->core, ACL_MAX_GROUPS);
1595 ida_init(&tcam->used_groups);
1596 tcam->max_groups = max_groups;
1597 tcam->max_group_size = MLXSW_CORE_RES_GET(mlxsw_sp->core,
1598 ACL_MAX_GROUP_SIZE);
1599 tcam->max_group_size = min_t(unsigned int, tcam->max_group_size,
1600 MLXSW_REG_PAGT_ACL_MAX_NUM);
1602 err = ops->init(mlxsw_sp, tcam->priv, tcam);
1609 ida_destroy(&tcam->used_groups);
1610 ida_destroy(&tcam->used_regions);
1611 mlxsw_sp_acl_tcam_rehash_params_unregister(mlxsw_sp);
1612 err_rehash_params_register:
1613 mutex_destroy(&tcam->lock);
1617 void mlxsw_sp_acl_tcam_fini(struct mlxsw_sp *mlxsw_sp,
1618 struct mlxsw_sp_acl_tcam *tcam)
1620 const struct mlxsw_sp_acl_tcam_ops *ops = mlxsw_sp->acl_tcam_ops;
1622 ops->fini(mlxsw_sp, tcam->priv);
1623 ida_destroy(&tcam->used_groups);
1624 ida_destroy(&tcam->used_regions);
1625 mlxsw_sp_acl_tcam_rehash_params_unregister(mlxsw_sp);
1626 mutex_destroy(&tcam->lock);
1629 static const enum mlxsw_afk_element mlxsw_sp_acl_tcam_pattern_ipv4[] = {
1630 MLXSW_AFK_ELEMENT_SRC_SYS_PORT,
1631 MLXSW_AFK_ELEMENT_DMAC_32_47,
1632 MLXSW_AFK_ELEMENT_DMAC_0_31,
1633 MLXSW_AFK_ELEMENT_SMAC_32_47,
1634 MLXSW_AFK_ELEMENT_SMAC_0_31,
1635 MLXSW_AFK_ELEMENT_ETHERTYPE,
1636 MLXSW_AFK_ELEMENT_IP_PROTO,
1637 MLXSW_AFK_ELEMENT_SRC_IP_0_31,
1638 MLXSW_AFK_ELEMENT_DST_IP_0_31,
1639 MLXSW_AFK_ELEMENT_DST_L4_PORT,
1640 MLXSW_AFK_ELEMENT_SRC_L4_PORT,
1641 MLXSW_AFK_ELEMENT_VID,
1642 MLXSW_AFK_ELEMENT_PCP,
1643 MLXSW_AFK_ELEMENT_TCP_FLAGS,
1644 MLXSW_AFK_ELEMENT_IP_TTL_,
1645 MLXSW_AFK_ELEMENT_IP_ECN,
1646 MLXSW_AFK_ELEMENT_IP_DSCP,
1649 static const enum mlxsw_afk_element mlxsw_sp_acl_tcam_pattern_ipv6[] = {
1650 MLXSW_AFK_ELEMENT_ETHERTYPE,
1651 MLXSW_AFK_ELEMENT_IP_PROTO,
1652 MLXSW_AFK_ELEMENT_SRC_IP_96_127,
1653 MLXSW_AFK_ELEMENT_SRC_IP_64_95,
1654 MLXSW_AFK_ELEMENT_SRC_IP_32_63,
1655 MLXSW_AFK_ELEMENT_SRC_IP_0_31,
1656 MLXSW_AFK_ELEMENT_DST_IP_96_127,
1657 MLXSW_AFK_ELEMENT_DST_IP_64_95,
1658 MLXSW_AFK_ELEMENT_DST_IP_32_63,
1659 MLXSW_AFK_ELEMENT_DST_IP_0_31,
1660 MLXSW_AFK_ELEMENT_DST_L4_PORT,
1661 MLXSW_AFK_ELEMENT_SRC_L4_PORT,
1664 static const struct mlxsw_sp_acl_tcam_pattern mlxsw_sp_acl_tcam_patterns[] = {
1666 .elements = mlxsw_sp_acl_tcam_pattern_ipv4,
1667 .elements_count = ARRAY_SIZE(mlxsw_sp_acl_tcam_pattern_ipv4),
1670 .elements = mlxsw_sp_acl_tcam_pattern_ipv6,
1671 .elements_count = ARRAY_SIZE(mlxsw_sp_acl_tcam_pattern_ipv6),
1675 #define MLXSW_SP_ACL_TCAM_PATTERNS_COUNT \
1676 ARRAY_SIZE(mlxsw_sp_acl_tcam_patterns)
1678 struct mlxsw_sp_acl_tcam_flower_ruleset {
1679 struct mlxsw_sp_acl_tcam_vgroup vgroup;
1682 struct mlxsw_sp_acl_tcam_flower_rule {
1683 struct mlxsw_sp_acl_tcam_ventry ventry;
1687 mlxsw_sp_acl_tcam_flower_ruleset_add(struct mlxsw_sp *mlxsw_sp,
1688 struct mlxsw_sp_acl_tcam *tcam,
1690 struct mlxsw_afk_element_usage *tmplt_elusage,
1691 unsigned int *p_min_prio,
1692 unsigned int *p_max_prio)
1694 struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv;
1696 return mlxsw_sp_acl_tcam_vgroup_add(mlxsw_sp, tcam, &ruleset->vgroup,
1697 mlxsw_sp_acl_tcam_patterns,
1698 MLXSW_SP_ACL_TCAM_PATTERNS_COUNT,
1699 tmplt_elusage, true,
1700 p_min_prio, p_max_prio);
1704 mlxsw_sp_acl_tcam_flower_ruleset_del(struct mlxsw_sp *mlxsw_sp,
1707 struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv;
1709 mlxsw_sp_acl_tcam_vgroup_del(&ruleset->vgroup);
1713 mlxsw_sp_acl_tcam_flower_ruleset_bind(struct mlxsw_sp *mlxsw_sp,
1715 struct mlxsw_sp_port *mlxsw_sp_port,
1718 struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv;
1720 return mlxsw_sp_acl_tcam_group_bind(mlxsw_sp, &ruleset->vgroup.group,
1721 mlxsw_sp_port, ingress);
1725 mlxsw_sp_acl_tcam_flower_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,
1727 struct mlxsw_sp_port *mlxsw_sp_port,
1730 struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv;
1732 mlxsw_sp_acl_tcam_group_unbind(mlxsw_sp, &ruleset->vgroup.group,
1733 mlxsw_sp_port, ingress);
1737 mlxsw_sp_acl_tcam_flower_ruleset_group_id(void *ruleset_priv)
1739 struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv;
1741 return mlxsw_sp_acl_tcam_group_id(&ruleset->vgroup.group);
1745 mlxsw_sp_acl_tcam_flower_rule_add(struct mlxsw_sp *mlxsw_sp,
1746 void *ruleset_priv, void *rule_priv,
1747 struct mlxsw_sp_acl_rule_info *rulei)
1749 struct mlxsw_sp_acl_tcam_flower_ruleset *ruleset = ruleset_priv;
1750 struct mlxsw_sp_acl_tcam_flower_rule *rule = rule_priv;
1752 return mlxsw_sp_acl_tcam_ventry_add(mlxsw_sp, &ruleset->vgroup,
1753 &rule->ventry, rulei);
1757 mlxsw_sp_acl_tcam_flower_rule_del(struct mlxsw_sp *mlxsw_sp, void *rule_priv)
1759 struct mlxsw_sp_acl_tcam_flower_rule *rule = rule_priv;
1761 mlxsw_sp_acl_tcam_ventry_del(mlxsw_sp, &rule->ventry);
1765 mlxsw_sp_acl_tcam_flower_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
1767 struct mlxsw_sp_acl_rule_info *rulei)
1773 mlxsw_sp_acl_tcam_flower_rule_activity_get(struct mlxsw_sp *mlxsw_sp,
1774 void *rule_priv, bool *activity)
1776 struct mlxsw_sp_acl_tcam_flower_rule *rule = rule_priv;
1778 return mlxsw_sp_acl_tcam_ventry_activity_get(mlxsw_sp, &rule->ventry,
1782 static const struct mlxsw_sp_acl_profile_ops mlxsw_sp_acl_tcam_flower_ops = {
1783 .ruleset_priv_size = sizeof(struct mlxsw_sp_acl_tcam_flower_ruleset),
1784 .ruleset_add = mlxsw_sp_acl_tcam_flower_ruleset_add,
1785 .ruleset_del = mlxsw_sp_acl_tcam_flower_ruleset_del,
1786 .ruleset_bind = mlxsw_sp_acl_tcam_flower_ruleset_bind,
1787 .ruleset_unbind = mlxsw_sp_acl_tcam_flower_ruleset_unbind,
1788 .ruleset_group_id = mlxsw_sp_acl_tcam_flower_ruleset_group_id,
1789 .rule_priv_size = sizeof(struct mlxsw_sp_acl_tcam_flower_rule),
1790 .rule_add = mlxsw_sp_acl_tcam_flower_rule_add,
1791 .rule_del = mlxsw_sp_acl_tcam_flower_rule_del,
1792 .rule_action_replace = mlxsw_sp_acl_tcam_flower_rule_action_replace,
1793 .rule_activity_get = mlxsw_sp_acl_tcam_flower_rule_activity_get,
1796 struct mlxsw_sp_acl_tcam_mr_ruleset {
1797 struct mlxsw_sp_acl_tcam_vchunk *vchunk;
1798 struct mlxsw_sp_acl_tcam_vgroup vgroup;
1801 struct mlxsw_sp_acl_tcam_mr_rule {
1802 struct mlxsw_sp_acl_tcam_ventry ventry;
1806 mlxsw_sp_acl_tcam_mr_ruleset_add(struct mlxsw_sp *mlxsw_sp,
1807 struct mlxsw_sp_acl_tcam *tcam,
1809 struct mlxsw_afk_element_usage *tmplt_elusage,
1810 unsigned int *p_min_prio,
1811 unsigned int *p_max_prio)
1813 struct mlxsw_sp_acl_tcam_mr_ruleset *ruleset = ruleset_priv;
1816 err = mlxsw_sp_acl_tcam_vgroup_add(mlxsw_sp, tcam, &ruleset->vgroup,
1817 mlxsw_sp_acl_tcam_patterns,
1818 MLXSW_SP_ACL_TCAM_PATTERNS_COUNT,
1819 tmplt_elusage, false,
1820 p_min_prio, p_max_prio);
1824 /* For most of the TCAM clients it would make sense to take a tcam chunk
1825 * only when the first rule is written. This is not the case for
1826 * multicast router as it is required to bind the multicast router to a
1827 * specific ACL Group ID which must exist in HW before multicast router
1830 ruleset->vchunk = mlxsw_sp_acl_tcam_vchunk_get(mlxsw_sp,
1831 &ruleset->vgroup, 1,
1833 if (IS_ERR(ruleset->vchunk)) {
1834 err = PTR_ERR(ruleset->vchunk);
1841 mlxsw_sp_acl_tcam_vgroup_del(&ruleset->vgroup);
1846 mlxsw_sp_acl_tcam_mr_ruleset_del(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv)
1848 struct mlxsw_sp_acl_tcam_mr_ruleset *ruleset = ruleset_priv;
1850 mlxsw_sp_acl_tcam_vchunk_put(mlxsw_sp, ruleset->vchunk);
1851 mlxsw_sp_acl_tcam_vgroup_del(&ruleset->vgroup);
1855 mlxsw_sp_acl_tcam_mr_ruleset_bind(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
1856 struct mlxsw_sp_port *mlxsw_sp_port,
1859 /* Binding is done when initializing multicast router */
1864 mlxsw_sp_acl_tcam_mr_ruleset_unbind(struct mlxsw_sp *mlxsw_sp,
1866 struct mlxsw_sp_port *mlxsw_sp_port,
1872 mlxsw_sp_acl_tcam_mr_ruleset_group_id(void *ruleset_priv)
1874 struct mlxsw_sp_acl_tcam_mr_ruleset *ruleset = ruleset_priv;
1876 return mlxsw_sp_acl_tcam_group_id(&ruleset->vgroup.group);
1880 mlxsw_sp_acl_tcam_mr_rule_add(struct mlxsw_sp *mlxsw_sp, void *ruleset_priv,
1882 struct mlxsw_sp_acl_rule_info *rulei)
1884 struct mlxsw_sp_acl_tcam_mr_ruleset *ruleset = ruleset_priv;
1885 struct mlxsw_sp_acl_tcam_mr_rule *rule = rule_priv;
1887 return mlxsw_sp_acl_tcam_ventry_add(mlxsw_sp, &ruleset->vgroup,
1888 &rule->ventry, rulei);
1892 mlxsw_sp_acl_tcam_mr_rule_del(struct mlxsw_sp *mlxsw_sp, void *rule_priv)
1894 struct mlxsw_sp_acl_tcam_mr_rule *rule = rule_priv;
1896 mlxsw_sp_acl_tcam_ventry_del(mlxsw_sp, &rule->ventry);
1900 mlxsw_sp_acl_tcam_mr_rule_action_replace(struct mlxsw_sp *mlxsw_sp,
1902 struct mlxsw_sp_acl_rule_info *rulei)
1904 struct mlxsw_sp_acl_tcam_mr_rule *rule = rule_priv;
1906 return mlxsw_sp_acl_tcam_ventry_action_replace(mlxsw_sp, &rule->ventry,
1911 mlxsw_sp_acl_tcam_mr_rule_activity_get(struct mlxsw_sp *mlxsw_sp,
1912 void *rule_priv, bool *activity)
1919 static const struct mlxsw_sp_acl_profile_ops mlxsw_sp_acl_tcam_mr_ops = {
1920 .ruleset_priv_size = sizeof(struct mlxsw_sp_acl_tcam_mr_ruleset),
1921 .ruleset_add = mlxsw_sp_acl_tcam_mr_ruleset_add,
1922 .ruleset_del = mlxsw_sp_acl_tcam_mr_ruleset_del,
1923 .ruleset_bind = mlxsw_sp_acl_tcam_mr_ruleset_bind,
1924 .ruleset_unbind = mlxsw_sp_acl_tcam_mr_ruleset_unbind,
1925 .ruleset_group_id = mlxsw_sp_acl_tcam_mr_ruleset_group_id,
1926 .rule_priv_size = sizeof(struct mlxsw_sp_acl_tcam_mr_rule),
1927 .rule_add = mlxsw_sp_acl_tcam_mr_rule_add,
1928 .rule_del = mlxsw_sp_acl_tcam_mr_rule_del,
1929 .rule_action_replace = mlxsw_sp_acl_tcam_mr_rule_action_replace,
1930 .rule_activity_get = mlxsw_sp_acl_tcam_mr_rule_activity_get,
1933 static const struct mlxsw_sp_acl_profile_ops *
1934 mlxsw_sp_acl_tcam_profile_ops_arr[] = {
1935 [MLXSW_SP_ACL_PROFILE_FLOWER] = &mlxsw_sp_acl_tcam_flower_ops,
1936 [MLXSW_SP_ACL_PROFILE_MR] = &mlxsw_sp_acl_tcam_mr_ops,
1939 const struct mlxsw_sp_acl_profile_ops *
1940 mlxsw_sp_acl_tcam_profile_ops(struct mlxsw_sp *mlxsw_sp,
1941 enum mlxsw_sp_acl_profile profile)
1943 const struct mlxsw_sp_acl_profile_ops *ops;
1945 if (WARN_ON(profile >= ARRAY_SIZE(mlxsw_sp_acl_tcam_profile_ops_arr)))
1947 ops = mlxsw_sp_acl_tcam_profile_ops_arr[profile];