* [PATCH net-next v2 1/4] net: dsa: Add plumbing for port mirroring
2017-01-28 1:25 [PATCH net-next v2 0/4] net: dsa: Port mirroring support Florian Fainelli
@ 2017-01-28 1:25 ` Florian Fainelli
2017-01-28 9:14 ` Jiri Pirko
2017-01-28 1:25 ` [PATCH net-next v2 2/4] net: dsa: b53: Add mirror capture register definitions Florian Fainelli
` (2 subsequent siblings)
3 siblings, 1 reply; 7+ messages in thread
From: Florian Fainelli @ 2017-01-28 1:25 UTC (permalink / raw)
To: netdev; +Cc: davem, andrew, vivien.didelot, cphealy, Florian Fainelli
Add necessary plumbing at the slave network device level to have switch
drivers implement ndo_setup_tc() and most particularly the cls_matchall
classifier. We add support for two switch operations:
port_add_mirror and port_del_mirror() which configure, on a per-port
basis the mirror parameters requested from the cls_matchall classifier.
Code is largely borrowed from the Mellanox Spectrum switch driver.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
include/net/dsa.h | 36 ++++++++++++++
net/dsa/dsa_priv.h | 3 ++
net/dsa/slave.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
3 files changed, 181 insertions(+), 1 deletion(-)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index 92fd795e9573..831a789594f1 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -20,6 +20,8 @@
#include <linux/phy_fixed.h>
#include <linux/ethtool.h>
+struct tc_action;
+
enum dsa_tag_protocol {
DSA_TAG_PROTO_NONE = 0,
DSA_TAG_PROTO_DSA,
@@ -139,6 +141,31 @@ struct dsa_switch_tree {
const struct dsa_device_ops *tag_ops;
};
+enum dsa_port_mall_action_type {
+ DSA_PORT_MALL_MIRROR,
+};
+
+/*
+ * Mirroring TC entry
+ */
+struct dsa_mall_mirror_tc_entry {
+ u8 to_local_port;
+ bool ingress;
+};
+
+/*
+ * TC matchall entry
+ */
+struct dsa_mall_tc_entry {
+ struct list_head list;
+ unsigned long cookie;
+ enum dsa_port_mall_action_type type;
+ union {
+ struct dsa_mall_mirror_tc_entry mirror;
+ };
+};
+
+
struct dsa_port {
struct net_device *netdev;
struct device_node *dn;
@@ -370,6 +397,15 @@ struct dsa_switch_ops {
int (*port_mdb_dump)(struct dsa_switch *ds, int port,
struct switchdev_obj_port_mdb *mdb,
int (*cb)(struct switchdev_obj *obj));
+
+ /*
+ * TC integration
+ */
+ int (*port_mirror_add)(struct dsa_switch *ds, int port,
+ struct dsa_mall_mirror_tc_entry *mirror,
+ bool ingress);
+ void (*port_mirror_del)(struct dsa_switch *ds, int port,
+ struct dsa_mall_mirror_tc_entry *mirror);
};
struct dsa_switch_driver {
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 16194a4bb2fe..b10b03028b24 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -46,6 +46,9 @@ struct dsa_slave_priv {
#ifdef CONFIG_NET_POLL_CONTROLLER
struct netpoll *netpoll;
#endif
+
+ /* TC context */
+ struct list_head mall_tc_list;
};
/* dsa.c */
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index b8e58689a9a1..a5f9f1ebca2e 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -16,12 +16,17 @@
#include <linux/of_net.h>
#include <linux/of_mdio.h>
#include <linux/mdio.h>
+#include <linux/list.h>
#include <net/rtnetlink.h>
#include <net/switchdev.h>
+#include <net/pkt_cls.h>
+#include <net/tc_act/tc_mirred.h>
#include <linux/if_bridge.h>
#include <linux/netpoll.h>
#include "dsa_priv.h"
+static bool dsa_slave_dev_check(struct net_device *dev);
+
/* slave mii_bus handling ***************************************************/
static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg)
{
@@ -994,6 +999,139 @@ static int dsa_slave_get_phys_port_name(struct net_device *dev,
return 0;
}
+static struct dsa_mall_tc_entry *
+dsa_slave_mall_tc_entry_find(struct dsa_slave_priv *p,
+ unsigned long cookie)
+{
+ struct dsa_mall_tc_entry *mall_tc_entry;
+
+ list_for_each_entry(mall_tc_entry, &p->mall_tc_list, list)
+ if (mall_tc_entry->cookie == cookie)
+ return mall_tc_entry;
+
+ return NULL;
+}
+
+static int dsa_slave_add_cls_matchall(struct net_device *dev,
+ __be16 protocol,
+ struct tc_cls_matchall_offload *cls,
+ bool ingress)
+{
+ struct dsa_slave_priv *p = netdev_priv(dev);
+ struct dsa_mall_tc_entry *mall_tc_entry;
+ struct dsa_switch *ds = p->parent;
+ struct net *net = dev_net(dev);
+ struct dsa_slave_priv *to_p;
+ struct net_device *to_dev;
+ const struct tc_action *a;
+ int err = -EOPNOTSUPP;
+ LIST_HEAD(actions);
+ int ifindex;
+
+ if (!ds->ops->port_mirror_add)
+ return err;
+
+ if (!tc_single_action(cls->exts)) {
+ netdev_err(dev, "only singular actions are supported\n");
+ return err;
+ }
+
+ mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL);
+ if (!mall_tc_entry)
+ return -ENOMEM;
+ mall_tc_entry->cookie = cls->cookie;
+
+ tcf_exts_to_list(cls->exts, &actions);
+ a = list_first_entry(&actions, struct tc_action, list);
+
+ if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) {
+ struct dsa_mall_mirror_tc_entry *mirror;
+
+ mall_tc_entry->type = DSA_PORT_MALL_MIRROR;
+ mirror = &mall_tc_entry->mirror;
+
+ ifindex = tcf_mirred_ifindex(a);
+ to_dev = __dev_get_by_index(net, ifindex);
+ if (!to_dev) {
+ err = -EINVAL;
+ goto err_add_action;
+ }
+
+ if (!dsa_slave_dev_check(to_dev)) {
+ err = -EOPNOTSUPP;
+ goto err_add_action;
+ }
+
+ to_p = netdev_priv(to_dev);
+
+ mirror->to_local_port = to_p->port;
+ mirror->ingress = ingress;
+
+ err = ds->ops->port_mirror_add(ds, p->port, mirror, ingress);
+ }
+
+ if (err)
+ goto err_add_action;
+
+ list_add_tail(&mall_tc_entry->list, &p->mall_tc_list);
+ return 0;
+
+err_add_action:
+ kfree(mall_tc_entry);
+ return err;
+}
+
+static void dsa_slave_del_cls_matchall(struct net_device *dev,
+ struct tc_cls_matchall_offload *cls)
+{
+ struct dsa_slave_priv *p = netdev_priv(dev);
+ struct dsa_mall_tc_entry *mall_tc_entry;
+ struct dsa_switch *ds = p->parent;
+
+ if (!ds->ops->port_mirror_del)
+ return;
+
+ mall_tc_entry = dsa_slave_mall_tc_entry_find(p, cls->cookie);
+ if (!mall_tc_entry)
+ return;
+
+ list_del(&mall_tc_entry->list);
+
+ switch (mall_tc_entry->type) {
+ case DSA_PORT_MALL_MIRROR:
+ ds->ops->port_mirror_del(ds, p->port, &mall_tc_entry->mirror);
+ break;
+ default:
+ WARN_ON(1);
+ }
+
+ kfree(mall_tc_entry);
+}
+
+static int dsa_slave_setup_tc(struct net_device *dev, u32 handle,
+ __be16 protocol, struct tc_to_netdev *tc)
+{
+ bool ingress = TC_H_MAJ(handle) == TC_H_MAJ(TC_H_INGRESS);
+ int ret = -EOPNOTSUPP;
+
+ switch (tc->type) {
+ case TC_SETUP_MATCHALL:
+ switch (tc->cls_mall->command) {
+ case TC_CLSMATCHALL_REPLACE:
+ return dsa_slave_add_cls_matchall(dev, protocol,
+ tc->cls_mall,
+ ingress);
+ case TC_CLSMATCHALL_DESTROY:
+ dsa_slave_del_cls_matchall(dev, tc->cls_mall);
+ return 0;
+ }
+ default:
+ break;
+ }
+
+ return ret;
+}
+
void dsa_cpu_port_ethtool_init(struct ethtool_ops *ops)
{
ops->get_sset_count = dsa_cpu_port_get_sset_count;
@@ -1042,6 +1180,7 @@ static const struct net_device_ops dsa_slave_netdev_ops = {
.ndo_bridge_setlink = switchdev_port_bridge_setlink,
.ndo_bridge_dellink = switchdev_port_bridge_dellink,
.ndo_get_phys_port_name = dsa_slave_get_phys_port_name,
+ .ndo_setup_tc = dsa_slave_setup_tc,
};
static const struct switchdev_ops dsa_slave_switchdev_ops = {
@@ -1257,7 +1396,8 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
if (slave_dev == NULL)
return -ENOMEM;
- slave_dev->features = master->vlan_features;
+ slave_dev->features = master->vlan_features | NETIF_F_HW_TC;
+ slave_dev->hw_features |= NETIF_F_HW_TC;
slave_dev->ethtool_ops = &dsa_slave_ethtool_ops;
eth_hw_addr_inherit(slave_dev, master);
slave_dev->priv_flags |= IFF_NO_QUEUE;
@@ -1275,6 +1415,7 @@ int dsa_slave_create(struct dsa_switch *ds, struct device *parent,
slave_dev->vlan_features = master->vlan_features;
p = netdev_priv(slave_dev);
+ INIT_LIST_HEAD(&p->mall_tc_list);
p->parent = ds;
p->port = port;
p->xmit = dst->tag_ops->xmit;
--
2.9.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* Re: [PATCH net-next v2 1/4] net: dsa: Add plumbing for port mirroring
2017-01-28 1:25 ` [PATCH net-next v2 1/4] net: dsa: Add plumbing for port mirroring Florian Fainelli
@ 2017-01-28 9:14 ` Jiri Pirko
2017-01-28 17:20 ` Florian Fainelli
0 siblings, 1 reply; 7+ messages in thread
From: Jiri Pirko @ 2017-01-28 9:14 UTC (permalink / raw)
To: Florian Fainelli; +Cc: netdev, davem, andrew, vivien.didelot, cphealy
Sat, Jan 28, 2017 at 02:25:25AM CET, f.fainelli@gmail.com wrote:
>Add necessary plumbing at the slave network device level to have switch
>drivers implement ndo_setup_tc() and most particularly the cls_matchall
>classifier. We add support for two switch operations:
>
>port_add_mirror and port_del_mirror() which configure, on a per-port
>basis the mirror parameters requested from the cls_matchall classifier.
>
>Code is largely borrowed from the Mellanox Spectrum switch driver.
>
>Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>---
[...]
>+/*
>+ * Mirroring TC entry
>+ */
>+struct dsa_mall_mirror_tc_entry {
>+ u8 to_local_port;
>+ bool ingress;
>+};
>+
>+/*
>+ * TC matchall entry
>+ */
Why are you using multiline comment format for single line comments?
>+struct dsa_mall_tc_entry {
>+ struct list_head list;
>+ unsigned long cookie;
>+ enum dsa_port_mall_action_type type;
>+ union {
>+ struct dsa_mall_mirror_tc_entry mirror;
>+ };
>+};
>+
>+
> struct dsa_port {
> struct net_device *netdev;
> struct device_node *dn;
>@@ -370,6 +397,15 @@ struct dsa_switch_ops {
> int (*port_mdb_dump)(struct dsa_switch *ds, int port,
> struct switchdev_obj_port_mdb *mdb,
> int (*cb)(struct switchdev_obj *obj));
>+
>+ /*
>+ * TC integration
>+ */
>+ int (*port_mirror_add)(struct dsa_switch *ds, int port,
>+ struct dsa_mall_mirror_tc_entry *mirror,
>+ bool ingress);
>+ void (*port_mirror_del)(struct dsa_switch *ds, int port,
>+ struct dsa_mall_mirror_tc_entry *mirror);
> };
[...]
>+static int dsa_slave_add_cls_matchall(struct net_device *dev,
>+ __be16 protocol,
>+ struct tc_cls_matchall_offload *cls,
>+ bool ingress)
>+{
>+ struct dsa_slave_priv *p = netdev_priv(dev);
>+ struct dsa_mall_tc_entry *mall_tc_entry;
>+ struct dsa_switch *ds = p->parent;
>+ struct net *net = dev_net(dev);
>+ struct dsa_slave_priv *to_p;
>+ struct net_device *to_dev;
>+ const struct tc_action *a;
>+ int err = -EOPNOTSUPP;
>+ LIST_HEAD(actions);
>+ int ifindex;
>+
>+ if (!ds->ops->port_mirror_add)
>+ return err;
>+
>+ if (!tc_single_action(cls->exts)) {
>+ netdev_err(dev, "only singular actions are supported\n");
Why you note the user in this case, but in case he tries to add
non-supported action you don't note him?
>+ return err;
>+ }
>+
>+ mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL);
>+ if (!mall_tc_entry)
>+ return -ENOMEM;
>+ mall_tc_entry->cookie = cls->cookie;
Hmm, I believe that this allocation and initialization should go into
the "is_mirred if". You can do the checks in advance. That would also
make the error path simplier.
>+
>+ tcf_exts_to_list(cls->exts, &actions);
>+ a = list_first_entry(&actions, struct tc_action, list);
>+
>+ if (is_tcf_mirred_egress_mirror(a) && protocol == htons(ETH_P_ALL)) {
>+ struct dsa_mall_mirror_tc_entry *mirror;
>+
>+ mall_tc_entry->type = DSA_PORT_MALL_MIRROR;
>+ mirror = &mall_tc_entry->mirror;
>+
>+ ifindex = tcf_mirred_ifindex(a);
>+ to_dev = __dev_get_by_index(net, ifindex);
>+ if (!to_dev) {
>+ err = -EINVAL;
>+ goto err_add_action;
>+ }
>+
>+ if (!dsa_slave_dev_check(to_dev)) {
>+ err = -EOPNOTSUPP;
>+ goto err_add_action;
>+ }
>+
>+ to_p = netdev_priv(to_dev);
>+
>+ mirror->to_local_port = to_p->port;
>+ mirror->ingress = ingress;
>+
>+ err = ds->ops->port_mirror_add(ds, p->port, mirror, ingress);
>+ }
>+
>+ if (err)
>+ goto err_add_action;
>+
>+ list_add_tail(&mall_tc_entry->list, &p->mall_tc_list);
>+ return 0;
>+
>+err_add_action:
>+ kfree(mall_tc_entry);
>+ return err;
>+}
^ permalink raw reply [flat|nested] 7+ messages in thread* Re: [PATCH net-next v2 1/4] net: dsa: Add plumbing for port mirroring
2017-01-28 9:14 ` Jiri Pirko
@ 2017-01-28 17:20 ` Florian Fainelli
0 siblings, 0 replies; 7+ messages in thread
From: Florian Fainelli @ 2017-01-28 17:20 UTC (permalink / raw)
To: Jiri Pirko; +Cc: netdev, davem, andrew, vivien.didelot, cphealy
Le 01/28/17 à 01:14, Jiri Pirko a écrit :
> Sat, Jan 28, 2017 at 02:25:25AM CET, f.fainelli@gmail.com wrote:
>> Add necessary plumbing at the slave network device level to have switch
>> drivers implement ndo_setup_tc() and most particularly the cls_matchall
>> classifier. We add support for two switch operations:
>>
>> port_add_mirror and port_del_mirror() which configure, on a per-port
>> basis the mirror parameters requested from the cls_matchall classifier.
>>
>> Code is largely borrowed from the Mellanox Spectrum switch driver.
>>
>> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>> ---
>
> [...]
>
>
>> +/*
>> + * Mirroring TC entry
>> + */
>> +struct dsa_mall_mirror_tc_entry {
>> + u8 to_local_port;
>> + bool ingress;
>> +};
>> +
>> +/*
>> + * TC matchall entry
>> + */
>
> Why are you using multiline comment format for single line comments?
There are precedents in that file, but I will remove it.
>
>
>> +struct dsa_mall_tc_entry {
>> + struct list_head list;
>> + unsigned long cookie;
>> + enum dsa_port_mall_action_type type;
>> + union {
>> + struct dsa_mall_mirror_tc_entry mirror;
>> + };
>> +};
>> +
>> +
>> struct dsa_port {
>> struct net_device *netdev;
>> struct device_node *dn;
>> @@ -370,6 +397,15 @@ struct dsa_switch_ops {
>> int (*port_mdb_dump)(struct dsa_switch *ds, int port,
>> struct switchdev_obj_port_mdb *mdb,
>> int (*cb)(struct switchdev_obj *obj));
>> +
>> + /*
>> + * TC integration
>> + */
>> + int (*port_mirror_add)(struct dsa_switch *ds, int port,
>> + struct dsa_mall_mirror_tc_entry *mirror,
>> + bool ingress);
>> + void (*port_mirror_del)(struct dsa_switch *ds, int port,
>> + struct dsa_mall_mirror_tc_entry *mirror);
>> };
>
> [...]
>
>
>> +static int dsa_slave_add_cls_matchall(struct net_device *dev,
>> + __be16 protocol,
>> + struct tc_cls_matchall_offload *cls,
>> + bool ingress)
>> +{
>> + struct dsa_slave_priv *p = netdev_priv(dev);
>> + struct dsa_mall_tc_entry *mall_tc_entry;
>> + struct dsa_switch *ds = p->parent;
>> + struct net *net = dev_net(dev);
>> + struct dsa_slave_priv *to_p;
>> + struct net_device *to_dev;
>> + const struct tc_action *a;
>> + int err = -EOPNOTSUPP;
>> + LIST_HEAD(actions);
>> + int ifindex;
>> +
>> + if (!ds->ops->port_mirror_add)
>> + return err;
>> +
>> + if (!tc_single_action(cls->exts)) {
>> + netdev_err(dev, "only singular actions are supported\n");
>
> Why you note the user in this case, but in case he tries to add
> non-supported action you don't note him?
Will remove that message.
>
>
>> + return err;
>> + }
>> +
>> + mall_tc_entry = kzalloc(sizeof(*mall_tc_entry), GFP_KERNEL);
>> + if (!mall_tc_entry)
>> + return -ENOMEM;
>> + mall_tc_entry->cookie = cls->cookie;
>
> Hmm, I believe that this allocation and initialization should go into
> the "is_mirred if". You can do the checks in advance. That would also
> make the error path simplier.
Yes good point, seems like you may want to do the same in mlxsw since
that part of the code was loosely based on that too.
Thanks Jiri!
--
Florian
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH net-next v2 2/4] net: dsa: b53: Add mirror capture register definitions
2017-01-28 1:25 [PATCH net-next v2 0/4] net: dsa: Port mirroring support Florian Fainelli
2017-01-28 1:25 ` [PATCH net-next v2 1/4] net: dsa: Add plumbing for port mirroring Florian Fainelli
@ 2017-01-28 1:25 ` Florian Fainelli
2017-01-28 1:25 ` [PATCH net-next v2 3/4] net: dsa: b53: Add support for port mirroring Florian Fainelli
2017-01-28 1:25 ` [PATCH net-next v2 4/4] net: dsa: bcm_sf2: " Florian Fainelli
3 siblings, 0 replies; 7+ messages in thread
From: Florian Fainelli @ 2017-01-28 1:25 UTC (permalink / raw)
To: netdev; +Cc: davem, andrew, vivien.didelot, cphealy, Florian Fainelli
Add definitions for the different Roboswitch registers relevant for
ingress and egress mirroring.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/dsa/b53/b53_regs.h | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h
index dac0af4e2cd0..9fd24c418fa4 100644
--- a/drivers/net/dsa/b53/b53_regs.h
+++ b/drivers/net/dsa/b53/b53_regs.h
@@ -206,6 +206,38 @@
#define BRCM_HDR_P8_EN BIT(0) /* Enable tagging on port 8 */
#define BRCM_HDR_P5_EN BIT(1) /* Enable tagging on port 5 */
+/* Mirror capture control register (16 bit) */
+#define B53_MIR_CAP_CTL 0x10
+#define CAP_PORT_MASK 0xf
+#define BLK_NOT_MIR BIT(14)
+#define MIRROR_EN BIT(15)
+
+/* Ingress mirror control register (16 bit) */
+#define B53_IG_MIR_CTL 0x12
+#define MIRROR_MASK 0x1ff
+#define DIV_EN BIT(13)
+#define MIRROR_FILTER_MASK 0x3
+#define MIRROR_FILTER_SHIFT 14
+#define MIRROR_ALL 0
+#define MIRROR_DA 1
+#define MIRROR_SA 2
+
+/* Ingress mirror divider register (16 bit) */
+#define B53_IG_MIR_DIV 0x14
+#define IN_MIRROR_DIV_MASK 0x3ff
+
+/* Ingress mirror MAC address register (48 bit) */
+#define B53_IG_MIR_MAC 0x16
+
+/* Egress mirror control register (16 bit) */
+#define B53_EG_MIR_CTL 0x1C
+
+/* Egress mirror divider register (16 bit) */
+#define B53_EG_MIR_DIV 0x1E
+
+/* Egress mirror MAC address register (48 bit) */
+#define B53_EG_MIR_MAC 0x20
+
/* Device ID register (8 or 32 bit) */
#define B53_DEVICE_ID 0x30
--
2.9.3
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH net-next v2 3/4] net: dsa: b53: Add support for port mirroring
2017-01-28 1:25 [PATCH net-next v2 0/4] net: dsa: Port mirroring support Florian Fainelli
2017-01-28 1:25 ` [PATCH net-next v2 1/4] net: dsa: Add plumbing for port mirroring Florian Fainelli
2017-01-28 1:25 ` [PATCH net-next v2 2/4] net: dsa: b53: Add mirror capture register definitions Florian Fainelli
@ 2017-01-28 1:25 ` Florian Fainelli
2017-01-28 1:25 ` [PATCH net-next v2 4/4] net: dsa: bcm_sf2: " Florian Fainelli
3 siblings, 0 replies; 7+ messages in thread
From: Florian Fainelli @ 2017-01-28 1:25 UTC (permalink / raw)
To: netdev; +Cc: davem, andrew, vivien.didelot, cphealy, Florian Fainelli
Add support for configuring port mirroring through the cls_matchall
classifier. We do a full ingress or egress capture towards the capture
port. Future improvements could include leveraging the divider to allow
less frames to be captured, as well as matching specific MAC DA/SA.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/dsa/b53/b53_common.c | 67 ++++++++++++++++++++++++++++++++++++++++
drivers/net/dsa/b53/b53_priv.h | 4 +++
2 files changed, 71 insertions(+)
diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c
index bb210b12ad1b..052ff4c22667 100644
--- a/drivers/net/dsa/b53/b53_common.c
+++ b/drivers/net/dsa/b53/b53_common.c
@@ -1453,6 +1453,71 @@ static enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds)
return DSA_TAG_PROTO_NONE;
}
+int b53_mirror_add(struct dsa_switch *ds, int port,
+ struct dsa_mall_mirror_tc_entry *mirror, bool ingress)
+{
+ struct b53_device *dev = ds->priv;
+ u16 reg, loc;
+
+ if (ingress)
+ loc = B53_IG_MIR_CTL;
+ else
+ loc = B53_EG_MIR_CTL;
+
+ b53_read16(dev, B53_MGMT_PAGE, loc, ®);
+ reg &= ~MIRROR_MASK;
+ reg |= BIT(port);
+ b53_write16(dev, B53_MGMT_PAGE, loc, reg);
+
+ b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®);
+ reg &= ~CAP_PORT_MASK;
+ reg |= mirror->to_local_port;
+ reg |= MIRROR_EN;
+ b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
+
+ return 0;
+}
+EXPORT_SYMBOL(b53_mirror_add);
+
+void b53_mirror_del(struct dsa_switch *ds, int port,
+ struct dsa_mall_mirror_tc_entry *mirror)
+{
+ struct b53_device *dev = ds->priv;
+ bool loc_disable = false, other_loc_disable = false;
+ u16 reg, loc;
+
+ if (mirror->ingress)
+ loc = B53_IG_MIR_CTL;
+ else
+ loc = B53_EG_MIR_CTL;
+
+ /* Update the desired ingress/egress register */
+ b53_read16(dev, B53_MGMT_PAGE, loc, ®);
+ reg &= ~BIT(port);
+ if (!(reg & MIRROR_MASK))
+ loc_disable = true;
+ b53_write16(dev, B53_MGMT_PAGE, loc, reg);
+
+ /* Now look at the other one to know if we can disable mirroring
+ * entirely
+ */
+ if (mirror->ingress)
+ b53_read16(dev, B53_MGMT_PAGE, B53_EG_MIR_CTL, ®);
+ else
+ b53_read16(dev, B53_MGMT_PAGE, B53_IG_MIR_CTL, ®);
+ if (!(reg & MIRROR_MASK))
+ other_loc_disable = true;
+
+ b53_read16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, ®);
+ /* Both no longer have ports, let's disable mirroring */
+ if (loc_disable && other_loc_disable) {
+ reg &= ~MIRROR_EN;
+ reg &= ~mirror->to_local_port;
+ }
+ b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg);
+}
+EXPORT_SYMBOL(b53_mirror_del);
+
static const struct dsa_switch_ops b53_switch_ops = {
.get_tag_protocol = b53_get_tag_protocol,
.setup = b53_setup,
@@ -1477,6 +1542,8 @@ static const struct dsa_switch_ops b53_switch_ops = {
.port_fdb_dump = b53_fdb_dump,
.port_fdb_add = b53_fdb_add,
.port_fdb_del = b53_fdb_del,
+ .port_mirror_add = b53_mirror_add,
+ .port_mirror_del = b53_mirror_del,
};
struct b53_chip_data {
diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h
index a8031b382c55..28ffe255276f 100644
--- a/drivers/net/dsa/b53/b53_priv.h
+++ b/drivers/net/dsa/b53/b53_priv.h
@@ -408,5 +408,9 @@ int b53_fdb_del(struct dsa_switch *ds, int port,
int b53_fdb_dump(struct dsa_switch *ds, int port,
struct switchdev_obj_port_fdb *fdb,
int (*cb)(struct switchdev_obj *obj));
+int b53_mirror_add(struct dsa_switch *ds, int port,
+ struct dsa_mall_mirror_tc_entry *mirror, bool ingress);
+void b53_mirror_del(struct dsa_switch *ds, int port,
+ struct dsa_mall_mirror_tc_entry *mirror);
#endif
--
2.9.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH net-next v2 4/4] net: dsa: bcm_sf2: Add support for port mirroring
2017-01-28 1:25 [PATCH net-next v2 0/4] net: dsa: Port mirroring support Florian Fainelli
` (2 preceding siblings ...)
2017-01-28 1:25 ` [PATCH net-next v2 3/4] net: dsa: b53: Add support for port mirroring Florian Fainelli
@ 2017-01-28 1:25 ` Florian Fainelli
3 siblings, 0 replies; 7+ messages in thread
From: Florian Fainelli @ 2017-01-28 1:25 UTC (permalink / raw)
To: netdev; +Cc: davem, andrew, vivien.didelot, cphealy, Florian Fainelli
We can use b53_mirror_add and b53_mirror_del because the Starfighter 2
is register compatible in that specific case.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/dsa/bcm_sf2.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 8eecfd227e06..3e514d7af218 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -1036,6 +1036,8 @@ static const struct dsa_switch_ops bcm_sf2_ops = {
.port_fdb_dump = b53_fdb_dump,
.port_fdb_add = b53_fdb_add,
.port_fdb_del = b53_fdb_del,
+ .port_mirror_add = b53_mirror_add,
+ .port_mirror_del = b53_mirror_del,
};
struct bcm_sf2_of_data {
--
2.9.3
^ permalink raw reply related [flat|nested] 7+ messages in thread