Commit 44af9571 authored by Maksym Glubokiy's avatar Maksym Glubokiy Committed by David S. Miller
Browse files

net: prestera: manage matchall and flower priorities



matchall rules can be added only to chain 0 and their priorities have
limitations:
 - new matchall ingress rule's priority must be higher (lower value)
   than any existing flower rule;
 - new matchall egress rule's priority must be lower (higher value)
   than any existing flower rule.

The opposite works for flower rule adding:
 - new flower ingress rule's priority must be lower (higher value)
   than any existing matchall rule;
 - new flower egress rule's priority must be higher (lower value)
   than any existing matchall rule.

This is a hardware limitation and thus must be properly handled in
driver by reporting errors to the user when newly added rule has such a
priority that cannot be installed into the hardware.

To achieve this, the driver must maintain both min/max matchall
priorities for every flower block when user adds/deletes a matchall
rule, as well as both min/max flower priorities for chain 0 for every
adding/deletion of flower rules for chain 0.

Cc: Serhiy Boiko <serhiy.boiko@plvision.eu>
Signed-off-by: default avatarMaksym Glubokiy <maksym.glubokiy@plvision.eu>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 8c448c2b
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -54,6 +54,10 @@ struct prestera_acl_ruleset {
	struct prestera_acl_ruleset_ht_key ht_key;
	struct rhashtable rule_ht;
	struct prestera_acl *acl;
	struct {
		u32 min;
		u32 max;
	} prio;
	unsigned long rule_count;
	refcount_t refcount;
	void *keymask;
@@ -162,6 +166,9 @@ prestera_acl_ruleset_create(struct prestera_acl *acl,
	ruleset->pcl_id = PRESTERA_ACL_PCL_ID_MAKE((u8)uid, chain_index);
	ruleset->index = uid;

	ruleset->prio.min = UINT_MAX;
	ruleset->prio.max = 0;

	err = rhashtable_insert_fast(&acl->ruleset_ht, &ruleset->ht_node,
				     prestera_acl_ruleset_ht_params);
	if (err)
@@ -365,6 +372,26 @@ prestera_acl_ruleset_block_unbind(struct prestera_acl_ruleset *ruleset,
	block->ruleset_zero = NULL;
}

static void
prestera_acl_ruleset_prio_refresh(struct prestera_acl *acl,
				  struct prestera_acl_ruleset *ruleset)
{
	struct prestera_acl_rule *rule;

	ruleset->prio.min = UINT_MAX;
	ruleset->prio.max = 0;

	list_for_each_entry(rule, &acl->rules, list) {
		if (ruleset->ingress != rule->ruleset->ingress)
			continue;
		if (ruleset->ht_key.chain_index != rule->chain_index)
			continue;

		ruleset->prio.min = min(ruleset->prio.min, rule->priority);
		ruleset->prio.max = max(ruleset->prio.max, rule->priority);
	}
}

void
prestera_acl_rule_keymask_pcl_id_set(struct prestera_acl_rule *rule, u16 pcl_id)
{
@@ -389,6 +416,13 @@ u32 prestera_acl_ruleset_index_get(const struct prestera_acl_ruleset *ruleset)
	return ruleset->index;
}

void prestera_acl_ruleset_prio_get(struct prestera_acl_ruleset *ruleset,
				   u32 *prio_min, u32 *prio_max)
{
	*prio_min = ruleset->prio.min;
	*prio_max = ruleset->prio.max;
}

bool prestera_acl_ruleset_is_offload(struct prestera_acl_ruleset *ruleset)
{
	return ruleset->offload;
@@ -429,6 +463,13 @@ void prestera_acl_rule_destroy(struct prestera_acl_rule *rule)
	kfree(rule);
}

static void prestera_acl_ruleset_prio_update(struct prestera_acl_ruleset *ruleset,
					     u32 prio)
{
	ruleset->prio.min = min(ruleset->prio.min, prio);
	ruleset->prio.max = max(ruleset->prio.max, prio);
}

int prestera_acl_rule_add(struct prestera_switch *sw,
			  struct prestera_acl_rule *rule)
{
@@ -468,6 +509,7 @@ int prestera_acl_rule_add(struct prestera_switch *sw,

	list_add_tail(&rule->list, &sw->acl->rules);
	ruleset->rule_count++;
	prestera_acl_ruleset_prio_update(ruleset, rule->priority);
	return 0;

err_acl_block_bind:
@@ -492,6 +534,7 @@ void prestera_acl_rule_del(struct prestera_switch *sw,
	list_del(&rule->list);

	prestera_acl_rule_entry_destroy(sw->acl, rule->re);
	prestera_acl_ruleset_prio_refresh(sw->acl, ruleset);

	/* unbind block (all ports) */
	if (!ruleset->ht_key.chain_index && !ruleset->rule_count)
+2 −0
Original line number Diff line number Diff line
@@ -195,6 +195,8 @@ int prestera_acl_ruleset_bind(struct prestera_acl_ruleset *ruleset,
int prestera_acl_ruleset_unbind(struct prestera_acl_ruleset *ruleset,
				struct prestera_port *port);
u32 prestera_acl_ruleset_index_get(const struct prestera_acl_ruleset *ruleset);
void prestera_acl_ruleset_prio_get(struct prestera_acl_ruleset *ruleset,
				   u32 *prio_min, u32 *prio_max);
void
prestera_acl_rule_keymask_pcl_id_set(struct prestera_acl_rule *rule,
				     u16 pcl_id);
+3 −0
Original line number Diff line number Diff line
@@ -90,6 +90,9 @@ prestera_flow_block_create(struct prestera_switch *sw,
	INIT_LIST_HEAD(&block->template_list);
	block->net = net;
	block->sw = sw;
	block->mall.prio_min = UINT_MAX;
	block->mall.prio_max = 0;
	block->mall.bound = false;
	block->ingress = ingress;

	return block;
+5 −0
Original line number Diff line number Diff line
@@ -22,6 +22,11 @@ struct prestera_flow_block {
	struct prestera_acl_ruleset *ruleset_zero;
	struct flow_block_cb *block_cb;
	struct list_head template_list;
	struct {
		u32 prio_min;
		u32 prio_max;
		bool bound;
	} mall;
	unsigned int rule_count;
	bool ingress;
};
+48 −0
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@
#include "prestera_acl.h"
#include "prestera_flow.h"
#include "prestera_flower.h"
#include "prestera_matchall.h"

struct prestera_flower_template {
	struct prestera_acl_ruleset *ruleset;
@@ -360,6 +361,49 @@ static int prestera_flower_parse(struct prestera_flow_block *block,
					     f->common.extack);
}

static int prestera_flower_prio_check(struct prestera_flow_block *block,
				      struct flow_cls_offload *f)
{
	u32 mall_prio_min;
	u32 mall_prio_max;
	int err;

	err = prestera_mall_prio_get(block, &mall_prio_min, &mall_prio_max);
	if (err == -ENOENT)
		/* No matchall filters installed on this chain. */
		return 0;

	if (err) {
		NL_SET_ERR_MSG(f->common.extack, "Failed to get matchall priorities");
		return err;
	}

	if (f->common.prio <= mall_prio_max && block->ingress) {
		NL_SET_ERR_MSG(f->common.extack,
			       "Failed to add in front of existing matchall rules");
		return -EOPNOTSUPP;
	}
	if (f->common.prio >= mall_prio_min && !block->ingress) {
		NL_SET_ERR_MSG(f->common.extack, "Failed to add behind of existing matchall rules");
		return -EOPNOTSUPP;
	}

	return 0;
}

int prestera_flower_prio_get(struct prestera_flow_block *block, u32 chain_index,
			     u32 *prio_min, u32 *prio_max)
{
	struct prestera_acl_ruleset *ruleset;

	ruleset = prestera_acl_ruleset_lookup(block->sw->acl, block, chain_index);
	if (IS_ERR(ruleset))
		return PTR_ERR(ruleset);

	prestera_acl_ruleset_prio_get(ruleset, prio_min, prio_max);
	return 0;
}

int prestera_flower_replace(struct prestera_flow_block *block,
			    struct flow_cls_offload *f)
{
@@ -368,6 +412,10 @@ int prestera_flower_replace(struct prestera_flow_block *block,
	struct prestera_acl_rule *rule;
	int err;

	err = prestera_flower_prio_check(block, f);
	if (err)
		return err;

	ruleset = prestera_acl_ruleset_get(acl, block, f->common.chain_index);
	if (IS_ERR(ruleset))
		return PTR_ERR(ruleset);
Loading