Lines Matching refs:ruleset
140 struct prestera_acl_ruleset *ruleset; in prestera_acl_ruleset_create() local
147 ruleset = kzalloc(sizeof(*ruleset), GFP_KERNEL); in prestera_acl_ruleset_create()
148 if (!ruleset) in prestera_acl_ruleset_create()
151 ruleset->acl = acl; in prestera_acl_ruleset_create()
152 ruleset->ingress = block->ingress; in prestera_acl_ruleset_create()
153 ruleset->ht_key.block = block; in prestera_acl_ruleset_create()
154 ruleset->ht_key.chain_index = chain_index; in prestera_acl_ruleset_create()
155 refcount_set(&ruleset->refcount, 1); in prestera_acl_ruleset_create()
157 err = rhashtable_init(&ruleset->rule_ht, &prestera_acl_rule_ht_params); in prestera_acl_ruleset_create()
166 ruleset->pcl_id = PRESTERA_ACL_PCL_ID_MAKE((u8)uid, chain_index); in prestera_acl_ruleset_create()
167 ruleset->index = uid; in prestera_acl_ruleset_create()
169 ruleset->prio.min = UINT_MAX; in prestera_acl_ruleset_create()
170 ruleset->prio.max = 0; in prestera_acl_ruleset_create()
172 err = rhashtable_insert_fast(&acl->ruleset_ht, &ruleset->ht_node, in prestera_acl_ruleset_create()
177 return ruleset; in prestera_acl_ruleset_create()
182 rhashtable_destroy(&ruleset->rule_ht); in prestera_acl_ruleset_create()
184 kfree(ruleset); in prestera_acl_ruleset_create()
188 int prestera_acl_ruleset_keymask_set(struct prestera_acl_ruleset *ruleset, in prestera_acl_ruleset_keymask_set() argument
191 ruleset->keymask = kmemdup(keymask, ACL_KEYMASK_SIZE, GFP_KERNEL); in prestera_acl_ruleset_keymask_set()
192 if (!ruleset->keymask) in prestera_acl_ruleset_keymask_set()
198 int prestera_acl_ruleset_offload(struct prestera_acl_ruleset *ruleset) in prestera_acl_ruleset_offload() argument
205 dir = ruleset->ingress ? in prestera_acl_ruleset_offload()
208 if (ruleset->offload) in prestera_acl_ruleset_offload()
211 err = prestera_acl_vtcam_id_get(ruleset->acl, in prestera_acl_ruleset_offload()
212 ruleset->ht_key.chain_index, in prestera_acl_ruleset_offload()
214 ruleset->keymask, &vtcam_id); in prestera_acl_ruleset_offload()
218 if (ruleset->ht_key.chain_index) { in prestera_acl_ruleset_offload()
222 iface.index = ruleset->index; in prestera_acl_ruleset_offload()
224 err = prestera_hw_vtcam_iface_bind(ruleset->acl->sw, &iface, in prestera_acl_ruleset_offload()
225 vtcam_id, ruleset->pcl_id); in prestera_acl_ruleset_offload()
230 ruleset->vtcam_id = vtcam_id; in prestera_acl_ruleset_offload()
231 ruleset->offload = true; in prestera_acl_ruleset_offload()
235 prestera_acl_vtcam_id_put(ruleset->acl, ruleset->vtcam_id); in prestera_acl_ruleset_offload()
240 static void prestera_acl_ruleset_destroy(struct prestera_acl_ruleset *ruleset) in prestera_acl_ruleset_destroy() argument
242 struct prestera_acl *acl = ruleset->acl; in prestera_acl_ruleset_destroy()
243 u8 uid = ruleset->pcl_id & PRESTERA_ACL_KEYMASK_PCL_ID_USER; in prestera_acl_ruleset_destroy()
246 rhashtable_remove_fast(&acl->ruleset_ht, &ruleset->ht_node, in prestera_acl_ruleset_destroy()
249 if (ruleset->offload) { in prestera_acl_ruleset_destroy()
250 if (ruleset->ht_key.chain_index) { in prestera_acl_ruleset_destroy()
253 .index = ruleset->index in prestera_acl_ruleset_destroy()
256 ruleset->vtcam_id); in prestera_acl_ruleset_destroy()
259 WARN_ON(prestera_acl_vtcam_id_put(acl, ruleset->vtcam_id)); in prestera_acl_ruleset_destroy()
263 rhashtable_destroy(&ruleset->rule_ht); in prestera_acl_ruleset_destroy()
264 kfree(ruleset->keymask); in prestera_acl_ruleset_destroy()
265 kfree(ruleset); in prestera_acl_ruleset_destroy()
287 struct prestera_acl_ruleset *ruleset; in prestera_acl_ruleset_lookup() local
289 ruleset = __prestera_acl_ruleset_lookup(acl, block, chain_index); in prestera_acl_ruleset_lookup()
290 if (!ruleset) in prestera_acl_ruleset_lookup()
293 refcount_inc(&ruleset->refcount); in prestera_acl_ruleset_lookup()
294 return ruleset; in prestera_acl_ruleset_lookup()
302 struct prestera_acl_ruleset *ruleset; in prestera_acl_ruleset_get() local
304 ruleset = __prestera_acl_ruleset_lookup(acl, block, chain_index); in prestera_acl_ruleset_get()
305 if (ruleset) { in prestera_acl_ruleset_get()
306 refcount_inc(&ruleset->refcount); in prestera_acl_ruleset_get()
307 return ruleset; in prestera_acl_ruleset_get()
313 void prestera_acl_ruleset_put(struct prestera_acl_ruleset *ruleset) in prestera_acl_ruleset_put() argument
315 if (!refcount_dec_and_test(&ruleset->refcount)) in prestera_acl_ruleset_put()
318 prestera_acl_ruleset_destroy(ruleset); in prestera_acl_ruleset_put()
321 int prestera_acl_ruleset_bind(struct prestera_acl_ruleset *ruleset, in prestera_acl_ruleset_bind() argument
329 return prestera_hw_vtcam_iface_bind(port->sw, &iface, ruleset->vtcam_id, in prestera_acl_ruleset_bind()
330 ruleset->pcl_id); in prestera_acl_ruleset_bind()
333 int prestera_acl_ruleset_unbind(struct prestera_acl_ruleset *ruleset, in prestera_acl_ruleset_unbind() argument
342 ruleset->vtcam_id); in prestera_acl_ruleset_unbind()
345 static int prestera_acl_ruleset_block_bind(struct prestera_acl_ruleset *ruleset, in prestera_acl_ruleset_block_bind() argument
351 block->ruleset_zero = ruleset; in prestera_acl_ruleset_block_bind()
353 err = prestera_acl_ruleset_bind(ruleset, binding->port); in prestera_acl_ruleset_block_bind()
362 err = prestera_acl_ruleset_unbind(ruleset, binding->port); in prestera_acl_ruleset_block_bind()
369 prestera_acl_ruleset_block_unbind(struct prestera_acl_ruleset *ruleset, in prestera_acl_ruleset_block_unbind() argument
375 prestera_acl_ruleset_unbind(ruleset, binding->port); in prestera_acl_ruleset_block_unbind()
381 struct prestera_acl_ruleset *ruleset) in prestera_acl_ruleset_prio_refresh() argument
385 ruleset->prio.min = UINT_MAX; in prestera_acl_ruleset_prio_refresh()
386 ruleset->prio.max = 0; in prestera_acl_ruleset_prio_refresh()
389 if (ruleset->ingress != rule->ruleset->ingress) in prestera_acl_ruleset_prio_refresh()
391 if (ruleset->ht_key.chain_index != rule->chain_index) in prestera_acl_ruleset_prio_refresh()
394 ruleset->prio.min = min(ruleset->prio.min, rule->priority); in prestera_acl_ruleset_prio_refresh()
395 ruleset->prio.max = max(ruleset->prio.max, rule->priority); in prestera_acl_ruleset_prio_refresh()
411 prestera_acl_rule_lookup(struct prestera_acl_ruleset *ruleset, in prestera_acl_rule_lookup() argument
414 return rhashtable_lookup_fast(&ruleset->rule_ht, &cookie, in prestera_acl_rule_lookup()
418 u32 prestera_acl_ruleset_index_get(const struct prestera_acl_ruleset *ruleset) in prestera_acl_ruleset_index_get() argument
420 return ruleset->index; in prestera_acl_ruleset_index_get()
423 void prestera_acl_ruleset_prio_get(struct prestera_acl_ruleset *ruleset, in prestera_acl_ruleset_prio_get() argument
426 *prio_min = ruleset->prio.min; in prestera_acl_ruleset_prio_get()
427 *prio_max = ruleset->prio.max; in prestera_acl_ruleset_prio_get()
430 bool prestera_acl_ruleset_is_offload(struct prestera_acl_ruleset *ruleset) in prestera_acl_ruleset_is_offload() argument
432 return ruleset->offload; in prestera_acl_ruleset_is_offload()
436 prestera_acl_rule_create(struct prestera_acl_ruleset *ruleset, in prestera_acl_rule_create() argument
445 rule->ruleset = ruleset; in prestera_acl_rule_create()
449 refcount_inc(&ruleset->refcount); in prestera_acl_rule_create()
466 prestera_acl_ruleset_put(rule->ruleset); in prestera_acl_rule_destroy()
470 static void prestera_acl_ruleset_prio_update(struct prestera_acl_ruleset *ruleset, in prestera_acl_ruleset_prio_update() argument
473 ruleset->prio.min = min(ruleset->prio.min, prio); in prestera_acl_ruleset_prio_update()
474 ruleset->prio.max = max(ruleset->prio.max, prio); in prestera_acl_ruleset_prio_update()
481 struct prestera_acl_ruleset *ruleset = rule->ruleset; in prestera_acl_rule_add() local
482 struct prestera_flow_block *block = ruleset->ht_key.block; in prestera_acl_rule_add()
485 err = rhashtable_insert_fast(&ruleset->rule_ht, &rule->ht_node, in prestera_acl_rule_add()
490 prestera_acl_rule_keymask_pcl_id_set(rule, ruleset->pcl_id); in prestera_acl_rule_add()
491 rule->re_arg.vtcam_id = ruleset->vtcam_id; in prestera_acl_rule_add()
508 if (!ruleset->ht_key.chain_index && !ruleset->rule_count) { in prestera_acl_rule_add()
509 err = prestera_acl_ruleset_block_bind(ruleset, block); in prestera_acl_rule_add()
515 ruleset->rule_count++; in prestera_acl_rule_add()
516 prestera_acl_ruleset_prio_update(ruleset, rule->priority); in prestera_acl_rule_add()
523 rhashtable_remove_fast(&ruleset->rule_ht, &rule->ht_node, in prestera_acl_rule_add()
532 struct prestera_acl_ruleset *ruleset = rule->ruleset; in prestera_acl_rule_del() local
533 struct prestera_flow_block *block = ruleset->ht_key.block; in prestera_acl_rule_del()
535 rhashtable_remove_fast(&ruleset->rule_ht, &rule->ht_node, in prestera_acl_rule_del()
537 ruleset->rule_count--; in prestera_acl_rule_del()
541 prestera_acl_ruleset_prio_refresh(sw->acl, ruleset); in prestera_acl_rule_del()
544 if (!ruleset->ht_key.chain_index && !ruleset->rule_count) in prestera_acl_rule_del()
545 prestera_acl_ruleset_block_unbind(ruleset, block); in prestera_acl_rule_del()