net: dsa: Port mirroring support
cover net: dsa: Port mirroring support
Hi all,
This patch series adds support for port mirroring in the two Broadcom switch drivers. The major part of the functional are actually with the plumbing between tc and the drivers.
David, this will most likely conflict a little bit with my other series:
net: dsa: bcm_sf2: CFP support, so just let me know if that happens, and
I will provide a rebased version. Thanks!
Tested using the two iproute2 examples:
# ingress
tc qdisc add dev eth1 handle ffff: ingress
tc filter add dev eth1 parent ffff: \
matchall skip_sw \
action mirred egress mirror \
dev eth2
# egress
tc qdisc add dev eth1 handle 1: root prio
tc filter add dev eth1 parent 1: \
matchall skip_sw \
action mirred egress mirror \
dev eth2Florian Fainelli (4):
net: dsa: Add plumbing for port mirroring
net: dsa: b53: Add mirror capture register definitions
net: dsa: b53: Add support for port mirroring
net: dsa: bcm_sf2: Add support for port mirroring
drivers/net/dsa/b53/b53_common.c | 54 +++++++++++++++ drivers/net/dsa/b53/b53_priv.h | 4 ++ drivers/net/dsa/b53/b53_regs.h | 32 +++++++++ drivers/net/dsa/bcm_sf2.c | 2 + include/net/dsa.h | 41 +++++++++++ net/dsa/dsa_priv.h | 3 + net/dsa/slave.c | 143 ++++++++++++++++++++++++++++++++++++++- 7 files changed, 278 insertions(+), 1 deletion(-)
Signature · 1 line
2.9.3
PATCH 1/4 net: dsa: Add plumbing for port mirroring
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.
--- include/net/dsa.h | 41 +++++++++++++++ net/dsa/dsa_priv.h | 3 ++ net/dsa/slave.c | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 186 insertions(+), 1 deletion(-)
include/net/dsa.h +41 -0
@@ -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,11 +141,41 @@ 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;unsigned int ageing_time;u8 stp_state; + +/* +* TC context +*/ +struct list_head mall_tc_list; };struct dsa_switch {
@@ -370,6 +402,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 {
net/dsa/dsa_priv.h +3 -0
@@ -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 */
net/dsa/slave.c +142 -1
179 lines not on this page · raw message
Signature · 1 line
2.9.3
PATCH 2/4 net: dsa: b53: Add mirror capture register definitions
In reply to Florian FainelliAdd definitions for the different Roboswitch registers relevant for ingress and egress mirroring.
--- drivers/net/dsa/b53/b53_regs.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
drivers/net/dsa/b53/b53_regs.h +32 -0
@@ -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
Signature · 1 line
2.9.3
PATCH 3/4 net: dsa: b53: Add support for port mirroring
In reply to Florian FainelliAdd 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.
--- drivers/net/dsa/b53/b53_common.c | 54 ++++++++++++++++++++++++++++++++++++++++ drivers/net/dsa/b53/b53_priv.h | 4 +++ 2 files changed, 58 insertions(+)
drivers/net/dsa/b53/b53_common.c +54 -0
@@ -1453,6 +1453,58 @@ 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 disable_mirror = false; +u16 reg, loc; + +if (mirror->ingress) + loc =B53_IG_MIR_CTL ; +else + loc =B53_EG_MIR_CTL ; + +b53_read16 (dev,B53_MGMT_PAGE , loc, ®); + reg &= ~BIT (port); +if (!(reg &MIRROR_MASK )) + disable_mirror = true; +b53_write16 (dev,B53_MGMT_PAGE , loc, reg); + +b53_read16 (dev,B53_MGMT_PAGE ,B53_MIR_CAP_CTL , ®); +if (disable_mirror) + 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 +1529,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 {
drivers/net/dsa/b53/b53_priv.h +4 -0
@@ -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
Signature · 1 line
2.9.3
PATCH 4/4 net: dsa: bcm_sf2: Add support for port mirroring
In reply to Florian FainelliWe can use b53_mirror_add and b53_mirror_del because the Starfighter 2 is register compatible in that specific case.
--- drivers/net/dsa/bcm_sf2.c | 2 ++ 1 file changed, 2 insertions(+)
drivers/net/dsa/bcm_sf2.c +2 -0
@@ -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 {
Signature · 1 line
2.9.3
Quoted 5 lines · Florian Fainelli
Hi all,
This patch series adds support for port mirroring in the two Broadcom switch drivers. The major part of the functional are actually with the plumbing between tc and the drivers.
Meh, there are two issues that need fixing:
- left a stray list_head in the dsa_port structure which we do not need
- if we remove either the ingress, or egress filter, we end-up disabling the mirroring entirely, so need to rework the b53_mirror_del logic a bit
Will re-submit shortly.
Quoted 36 lines
David, this will most likely conflict a little bit with my other series:
net: dsa:bcm_sf2: CFP support, so just let me know if that happens, and
I will provide a rebased version. Thanks!Tested using the two iproute2 examples:
# ingress tc qdisc add dev eth1 handle ffff: ingress tc filter add dev eth1 parent ffff: \ matchall skip_sw \ action mirred egress mirror \ dev eth2 # egress tc qdisc add dev eth1 handle 1: root prio tc filter add dev eth1 parent 1: \ matchall skip_sw \ action mirred egress mirror \ dev eth2Florian Fainelli (4):
net: dsa: Add plumbing for port mirroring
net: dsa: b53: Add mirror capture register definitions
net: dsa: b53: Add support for port mirroring
net: dsa:bcm_sf2: Add support for port mirroringdrivers/net/dsa/b53/b53_common.c | 54 +++++++++++++++ drivers/net/dsa/b53/b53_priv.h | 4 ++ drivers/net/dsa/b53/b53_regs.h | 32 +++++++++ drivers/net/dsa/bcm_sf2.c | 2 + include/net/dsa.h | 41 +++++++++++ net/dsa/dsa_priv.h | 3 + net/dsa/slave.c | 143 ++++++++++++++++++++++++++++++++++++++- 7 files changed, 278 insertions(+), 1 deletion(-)
Signature · 1 line
Florian