Commit b9bace6e authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: mscc: ocelot: use a single VCAP filter for all MRP traps

The MRP assist code installs a VCAP IS2 trapping rule for each port, but
since the key and the action is the same, just the ingress port mask
differs, there isn't any need to do this. We can save some space in the
TCAM by using a single filter and adjusting the ingress port mask.

Reuse the ocelot_trap_add() and ocelot_trap_del() functions for this
purpose.

Now that the cookies are no longer per port, we need to change the
allocation scheme such that MRP traps use a fixed number.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 36fac35b
...@@ -1468,8 +1468,7 @@ ocelot_populate_ipv6_ptp_general_trap_key(struct ocelot_vcap_filter *trap) ...@@ -1468,8 +1468,7 @@ ocelot_populate_ipv6_ptp_general_trap_key(struct ocelot_vcap_filter *trap)
trap->key.ipv6.dport.mask = 0xffff; trap->key.ipv6.dport.mask = 0xffff;
} }
static int ocelot_trap_add(struct ocelot *ocelot, int port, int ocelot_trap_add(struct ocelot *ocelot, int port, unsigned long cookie,
unsigned long cookie,
void (*populate)(struct ocelot_vcap_filter *f)) void (*populate)(struct ocelot_vcap_filter *f))
{ {
struct ocelot_vcap_block *block_vcap_is2; struct ocelot_vcap_block *block_vcap_is2;
...@@ -1515,8 +1514,7 @@ static int ocelot_trap_add(struct ocelot *ocelot, int port, ...@@ -1515,8 +1514,7 @@ static int ocelot_trap_add(struct ocelot *ocelot, int port,
return 0; return 0;
} }
static int ocelot_trap_del(struct ocelot *ocelot, int port, int ocelot_trap_del(struct ocelot *ocelot, int port, unsigned long cookie)
unsigned long cookie)
{ {
struct ocelot_vcap_block *block_vcap_is2; struct ocelot_vcap_block *block_vcap_is2;
struct ocelot_vcap_filter *trap; struct ocelot_vcap_filter *trap;
......
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
#include <soc/mscc/ocelot_dev.h> #include <soc/mscc/ocelot_dev.h>
#include <soc/mscc/ocelot_ana.h> #include <soc/mscc/ocelot_ana.h>
#include <soc/mscc/ocelot_ptp.h> #include <soc/mscc/ocelot_ptp.h>
#include <soc/mscc/ocelot_vcap.h>
#include <soc/mscc/ocelot.h> #include <soc/mscc/ocelot.h>
#include "ocelot_rew.h" #include "ocelot_rew.h"
#include "ocelot_qs.h" #include "ocelot_qs.h"
...@@ -102,6 +103,10 @@ int ocelot_port_devlink_init(struct ocelot *ocelot, int port, ...@@ -102,6 +103,10 @@ int ocelot_port_devlink_init(struct ocelot *ocelot, int port,
enum devlink_port_flavour flavour); enum devlink_port_flavour flavour);
void ocelot_port_devlink_teardown(struct ocelot *ocelot, int port); void ocelot_port_devlink_teardown(struct ocelot *ocelot, int port);
int ocelot_trap_add(struct ocelot *ocelot, int port, unsigned long cookie,
void (*populate)(struct ocelot_vcap_filter *f));
int ocelot_trap_del(struct ocelot *ocelot, int port, unsigned long cookie);
extern struct notifier_block ocelot_netdevice_nb; extern struct notifier_block ocelot_netdevice_nb;
extern struct notifier_block ocelot_switchdev_nb; extern struct notifier_block ocelot_switchdev_nb;
extern struct notifier_block ocelot_switchdev_blocking_nb; extern struct notifier_block ocelot_switchdev_blocking_nb;
......
...@@ -77,37 +77,30 @@ static int ocelot_mrp_redirect_add_vcap(struct ocelot *ocelot, int src_port, ...@@ -77,37 +77,30 @@ static int ocelot_mrp_redirect_add_vcap(struct ocelot *ocelot, int src_port,
return err; return err;
} }
static int ocelot_mrp_copy_add_vcap(struct ocelot *ocelot, int port, int prio) static void ocelot_populate_mrp_trap_key(struct ocelot_vcap_filter *filter)
{ {
const u8 mrp_mask[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }; const u8 mrp_mask[] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 };
struct ocelot_vcap_filter *filter;
int err;
filter = kzalloc(sizeof(*filter), GFP_KERNEL);
if (!filter)
return -ENOMEM;
filter->key_type = OCELOT_VCAP_KEY_ETYPE;
filter->prio = prio;
filter->id.cookie = OCELOT_VCAP_IS2_MRP_TRAP(ocelot, port);
filter->id.tc_offload = false;
filter->block_id = VCAP_IS2;
filter->type = OCELOT_VCAP_FILTER_OFFLOAD;
filter->ingress_port_mask = BIT(port);
/* Here is possible to use control or test dmac because the mask /* Here is possible to use control or test dmac because the mask
* doesn't cover the LSB * doesn't cover the LSB
*/ */
ether_addr_copy(filter->key.etype.dmac.value, mrp_test_dmac); ether_addr_copy(filter->key.etype.dmac.value, mrp_test_dmac);
ether_addr_copy(filter->key.etype.dmac.mask, mrp_mask); ether_addr_copy(filter->key.etype.dmac.mask, mrp_mask);
filter->action.mask_mode = OCELOT_MASK_MODE_PERMIT_DENY; }
filter->action.port_mask = 0x0;
filter->action.cpu_copy_ena = true;
err = ocelot_vcap_filter_add(ocelot, filter, NULL); static int ocelot_mrp_trap_add(struct ocelot *ocelot, int port)
if (err) {
kfree(filter); unsigned long cookie = OCELOT_VCAP_IS2_MRP_TRAP(ocelot);
return err; return ocelot_trap_add(ocelot, port, cookie,
ocelot_populate_mrp_trap_key);
}
static int ocelot_mrp_trap_del(struct ocelot *ocelot, int port)
{
unsigned long cookie = OCELOT_VCAP_IS2_MRP_TRAP(ocelot);
return ocelot_trap_del(ocelot, port, cookie);
} }
static void ocelot_mrp_save_mac(struct ocelot *ocelot, static void ocelot_mrp_save_mac(struct ocelot *ocelot,
...@@ -184,7 +177,7 @@ int ocelot_mrp_add_ring_role(struct ocelot *ocelot, int port, ...@@ -184,7 +177,7 @@ int ocelot_mrp_add_ring_role(struct ocelot *ocelot, int port,
ocelot_mrp_save_mac(ocelot, ocelot_port); ocelot_mrp_save_mac(ocelot, ocelot_port);
if (mrp->ring_role != BR_MRP_RING_ROLE_MRC) if (mrp->ring_role != BR_MRP_RING_ROLE_MRC)
return ocelot_mrp_copy_add_vcap(ocelot, port, 1); return ocelot_mrp_trap_add(ocelot, port);
dst_port = ocelot_mrp_find_partner_port(ocelot, ocelot_port); dst_port = ocelot_mrp_find_partner_port(ocelot, ocelot_port);
if (dst_port == -1) if (dst_port == -1)
...@@ -194,7 +187,7 @@ int ocelot_mrp_add_ring_role(struct ocelot *ocelot, int port, ...@@ -194,7 +187,7 @@ int ocelot_mrp_add_ring_role(struct ocelot *ocelot, int port,
if (err) if (err)
return err; return err;
err = ocelot_mrp_copy_add_vcap(ocelot, port, 2); err = ocelot_mrp_trap_add(ocelot, port);
if (err) { if (err) {
ocelot_mrp_del_vcap(ocelot, ocelot_mrp_del_vcap(ocelot,
OCELOT_VCAP_IS2_MRP_REDIRECT(ocelot, port)); OCELOT_VCAP_IS2_MRP_REDIRECT(ocelot, port));
...@@ -209,7 +202,7 @@ int ocelot_mrp_del_ring_role(struct ocelot *ocelot, int port, ...@@ -209,7 +202,7 @@ int ocelot_mrp_del_ring_role(struct ocelot *ocelot, int port,
const struct switchdev_obj_ring_role_mrp *mrp) const struct switchdev_obj_ring_role_mrp *mrp)
{ {
struct ocelot_port *ocelot_port = ocelot->ports[port]; struct ocelot_port *ocelot_port = ocelot->ports[port];
int i; int err, i;
if (!ocelot_port) if (!ocelot_port)
return -EOPNOTSUPP; return -EOPNOTSUPP;
...@@ -220,8 +213,11 @@ int ocelot_mrp_del_ring_role(struct ocelot *ocelot, int port, ...@@ -220,8 +213,11 @@ int ocelot_mrp_del_ring_role(struct ocelot *ocelot, int port,
if (ocelot_port->mrp_ring_id != mrp->ring_id) if (ocelot_port->mrp_ring_id != mrp->ring_id)
return 0; return 0;
err = ocelot_mrp_trap_del(ocelot, port);
if (err)
return err;
ocelot_mrp_del_vcap(ocelot, OCELOT_VCAP_IS2_MRP_REDIRECT(ocelot, port)); ocelot_mrp_del_vcap(ocelot, OCELOT_VCAP_IS2_MRP_REDIRECT(ocelot, port));
ocelot_mrp_del_vcap(ocelot, OCELOT_VCAP_IS2_MRP_TRAP(ocelot, port));
for (i = 0; i < ocelot->num_phys_ports; ++i) { for (i = 0; i < ocelot->num_phys_ports; ++i) {
ocelot_port = ocelot->ports[i]; ocelot_port = ocelot->ports[i];
......
...@@ -21,8 +21,8 @@ ...@@ -21,8 +21,8 @@
#define OCELOT_VCAP_IS2_IPV4_EV_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports + 3) #define OCELOT_VCAP_IS2_IPV4_EV_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports + 3)
#define OCELOT_VCAP_IS2_IPV6_GEN_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports + 4) #define OCELOT_VCAP_IS2_IPV6_GEN_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports + 4)
#define OCELOT_VCAP_IS2_IPV6_EV_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports + 5) #define OCELOT_VCAP_IS2_IPV6_EV_PTP_TRAP(ocelot) ((ocelot)->num_phys_ports + 5)
#define OCELOT_VCAP_IS2_MRP_TRAP(ocelot) ((ocelot)->num_phys_ports + 6)
#define OCELOT_VCAP_IS2_MRP_REDIRECT(ocelot, port) (port) #define OCELOT_VCAP_IS2_MRP_REDIRECT(ocelot, port) (port)
#define OCELOT_VCAP_IS2_MRP_TRAP(ocelot, port) ((ocelot)->num_phys_ports + (port))
/* ================================================================= /* =================================================================
* VCAP Common * VCAP Common
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment