net: mscc: ocelot: store a namespaced VCAP filter ID
authorVladimir Oltean <vladimir.oltean@nxp.com>
Fri, 29 Jan 2021 01:00:01 +0000 (03:00 +0200)
committerJakub Kicinski <kuba@kernel.org>
Sat, 30 Jan 2021 05:24:30 +0000 (21:24 -0800)
We will be adding some private VCAP filters that should not interfere in
any way with the filters added using tc-flower. So we need to allocate
some IDs which will not be used by tc.

Currently ocelot uses an u32 id derived from the flow cookie, which in
itself is an unsigned long. This is a problem in itself, since on 64 bit
systems, sizeof(unsigned long)=8, so the driver is already truncating
these.

Create a struct ocelot_vcap_id which contains the full unsigned long
cookie from tc, as well as a boolean that is supposed to namespace the
filters added by tc with the ones that aren't.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/ethernet/mscc/ocelot_flower.c
drivers/net/ethernet/mscc/ocelot_vcap.c
drivers/net/ethernet/mscc/ocelot_vcap.h
include/soc/mscc/ocelot_vcap.h

index 729495a1a77ee29628302aad68e4dcab355fb95f..c3ac026f6aea2bc270e32d77789ff7481e367a63 100644 (file)
@@ -622,7 +622,8 @@ static int ocelot_flower_parse(struct ocelot *ocelot, int port, bool ingress,
        int ret;
 
        filter->prio = f->common.prio;
-       filter->id = f->cookie;
+       filter->id.cookie = f->cookie;
+       filter->id.tc_offload = true;
 
        ret = ocelot_flower_parse_action(ocelot, port, ingress, f, filter);
        if (ret)
@@ -717,7 +718,7 @@ int ocelot_cls_flower_destroy(struct ocelot *ocelot, int port,
 
        block = &ocelot->block[block_id];
 
-       filter = ocelot_vcap_block_find_filter_by_id(block, f->cookie);
+       filter = ocelot_vcap_block_find_filter_by_id(block, f->cookie, true);
        if (!filter)
                return 0;
 
@@ -741,7 +742,7 @@ int ocelot_cls_flower_stats(struct ocelot *ocelot, int port,
 
        block = &ocelot->block[block_id];
 
-       filter = ocelot_vcap_block_find_filter_by_id(block, f->cookie);
+       filter = ocelot_vcap_block_find_filter_by_id(block, f->cookie, true);
        if (!filter || filter->type == OCELOT_VCAP_FILTER_DUMMY)
                return 0;
 
index 489bf16362a7e62564b6ca53174919a416a7bb64..b82fd4103a6856fb6df24e84544722960ebbaa47 100644 (file)
@@ -959,6 +959,12 @@ static void ocelot_vcap_filter_add_to_block(struct ocelot *ocelot,
        list_add(&filter->list, pos->prev);
 }
 
+static bool ocelot_vcap_filter_equal(const struct ocelot_vcap_filter *a,
+                                    const struct ocelot_vcap_filter *b)
+{
+       return !memcmp(&a->id, &b->id, sizeof(struct ocelot_vcap_id));
+}
+
 static int ocelot_vcap_block_get_filter_index(struct ocelot_vcap_block *block,
                                              struct ocelot_vcap_filter *filter)
 {
@@ -966,7 +972,7 @@ static int ocelot_vcap_block_get_filter_index(struct ocelot_vcap_block *block,
        int index = 0;
 
        list_for_each_entry(tmp, &block->rules, list) {
-               if (filter->id == tmp->id)
+               if (ocelot_vcap_filter_equal(filter, tmp))
                        return index;
                index++;
        }
@@ -991,12 +997,14 @@ ocelot_vcap_block_find_filter_by_index(struct ocelot_vcap_block *block,
 }
 
 struct ocelot_vcap_filter *
-ocelot_vcap_block_find_filter_by_id(struct ocelot_vcap_block *block, int id)
+ocelot_vcap_block_find_filter_by_id(struct ocelot_vcap_block *block, int cookie,
+                                   bool tc_offload)
 {
        struct ocelot_vcap_filter *filter;
 
        list_for_each_entry(filter, &block->rules, list)
-               if (filter->id == id)
+               if (filter->id.tc_offload == tc_offload &&
+                   filter->id.cookie == cookie)
                        return filter;
 
        return NULL;
@@ -1161,7 +1169,7 @@ static void ocelot_vcap_block_remove_filter(struct ocelot *ocelot,
 
        list_for_each_safe(pos, q, &block->rules) {
                tmp = list_entry(pos, struct ocelot_vcap_filter, list);
-               if (tmp->id == filter->id) {
+               if (ocelot_vcap_filter_equal(filter, tmp)) {
                        if (tmp->block_id == VCAP_IS2 &&
                            tmp->action.police_ena)
                                ocelot_vcap_policer_del(ocelot, block,
index cfc8b976d1deb241e93996234069b1f710fb16dc..3b0c7916056e941e5acb8b73e8bc480ebd110659 100644 (file)
@@ -15,7 +15,8 @@
 int ocelot_vcap_filter_stats_update(struct ocelot *ocelot,
                                    struct ocelot_vcap_filter *rule);
 struct ocelot_vcap_filter *
-ocelot_vcap_block_find_filter_by_id(struct ocelot_vcap_block *block, int id);
+ocelot_vcap_block_find_filter_by_id(struct ocelot_vcap_block *block, int id,
+                                   bool tc_offload);
 
 void ocelot_detect_vcap_constants(struct ocelot *ocelot);
 int ocelot_vcap_init(struct ocelot *ocelot);
index 7f1b82fba63c7f643fb49683bc7a7b958eca5bba..76e01c927e17a3564f03623f9a858a7ed619c373 100644 (file)
@@ -648,6 +648,11 @@ enum ocelot_vcap_filter_type {
        OCELOT_VCAP_FILTER_OFFLOAD,
 };
 
+struct ocelot_vcap_id {
+       unsigned long cookie;
+       bool tc_offload;
+};
+
 struct ocelot_vcap_filter {
        struct list_head list;
 
@@ -657,7 +662,7 @@ struct ocelot_vcap_filter {
        int lookup;
        u8 pag;
        u16 prio;
-       u32 id;
+       struct ocelot_vcap_id id;
 
        struct ocelot_vcap_action action;
        struct ocelot_vcap_stats stats;