BCM5325 and BCM5365 use an 11-bit bitmap for the mirror capture port, whereas newer switches use a four-bit port ID. Programming the port number directly can select no destination or the wrong destination, and can select multiple destinations. For example, port 2 requires BIT(2), but writing 2 selects port 1 instead. Use the bitmap encoding on BCM5325 and BCM5365, including translating logical CPU port 5 to hardware bit 8. Apply the corresponding field mask when checking for a conflicting destination, replacing the destination, and clearing it after the last mirror source is removed. Keep the port ID encoding for newer switches. The ingress and egress mirror source masks use the same layout on these switches, with the CPU port at bit 8 and bits 5-7 reserved, so apply the same translation when setting and clearing a source port bit. Fixes: ed3af5fd08eb ("net: dsa: b53: Add support for port mirroring") Signed-off-by: Florian Fainelli --- drivers/net/dsa/b53/b53_common.c | 40 +++++++++++++++++++++++++++----- drivers/net/dsa/b53/b53_regs.h | 1 + 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index c2706c2e643f..c320f53b41cd 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -2544,6 +2544,31 @@ enum dsa_tag_protocol b53_get_tag_protocol(struct dsa_switch *ds, int port, } EXPORT_SYMBOL(b53_get_tag_protocol); +static u16 b53_mirror_capture_port_mask(struct b53_device *dev) +{ + if (is5325(dev) || is5365(dev)) + return CAP_PORT_MASK_25; + + return CAP_PORT_MASK; +} + +static u16 b53_mirror_port_mask(struct b53_device *dev, int port) +{ + /* These switches use a bitmap with the CPU port at bit 8. */ + if ((is5325(dev) || is5365(dev)) && port == B53_CPU_PORT_25) + port = B53_CPU_PORT; + + return BIT(port); +} + +static u16 b53_mirror_capture_port(struct b53_device *dev, int port) +{ + if (is5325(dev) || is5365(dev)) + return b53_mirror_port_mask(dev, port); + + return port; +} + int b53_mirror_init(struct dsa_switch *ds) { struct b53_device *dev = ds->priv; @@ -2569,6 +2594,8 @@ int b53_mirror_add(struct dsa_switch *ds, int port, struct b53_device *dev = ds->priv; unsigned int *mirror_count = &dev->ports[port].mirror_count[ingress]; u16 reg, other_reg, loc, other_loc, cap_ctl; + u16 cap_mask = b53_mirror_capture_port_mask(dev); + u16 cap_port = b53_mirror_capture_port(dev, mirror->to_local_port); int ret; loc = ingress ? B53_IG_MIR_CTL : B53_EG_MIR_CTL; @@ -2587,7 +2614,7 @@ int b53_mirror_add(struct dsa_switch *ds, int port, return ret; if (((reg | other_reg) & MIRROR_MASK) && - (cap_ctl & CAP_PORT_MASK) != mirror->to_local_port) { + (cap_ctl & cap_mask) != cap_port) { NL_SET_ERR_MSG_MOD(extack, "Only one mirroring destination is supported"); return -EOPNOTSUPP; @@ -2599,14 +2626,15 @@ int b53_mirror_add(struct dsa_switch *ds, int port, } /* Select the destination before enabling the new source. */ - cap_ctl &= ~CAP_PORT_MASK; - cap_ctl |= mirror->to_local_port; + cap_ctl &= ~cap_mask; + cap_ctl |= cap_port; cap_ctl |= MIRROR_EN; ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, cap_ctl); if (ret) return ret; - ret = b53_write16(dev, B53_MGMT_PAGE, loc, reg | BIT(port)); + ret = b53_write16(dev, B53_MGMT_PAGE, loc, + reg | b53_mirror_port_mask(dev, port)); if (ret) return ret; @@ -2639,7 +2667,7 @@ void b53_mirror_del(struct dsa_switch *ds, int port, if (ret) goto err; - reg &= ~BIT(port); + reg &= ~b53_mirror_port_mask(dev, port); ret = b53_write16(dev, B53_MGMT_PAGE, loc, reg); if (ret) goto err; @@ -2658,7 +2686,7 @@ void b53_mirror_del(struct dsa_switch *ds, int port, if (ret) goto err; - reg &= ~(MIRROR_EN | CAP_PORT_MASK); + reg &= ~(MIRROR_EN | b53_mirror_capture_port_mask(dev)); ret = b53_write16(dev, B53_MGMT_PAGE, B53_MIR_CAP_CTL, reg); if (ret) goto err; diff --git a/drivers/net/dsa/b53/b53_regs.h b/drivers/net/dsa/b53/b53_regs.h index 54a278db67c9..821ac74777f2 100644 --- a/drivers/net/dsa/b53/b53_regs.h +++ b/drivers/net/dsa/b53/b53_regs.h @@ -239,6 +239,7 @@ /* Mirror capture control register (16 bit) */ #define B53_MIR_CAP_CTL 0x10 #define CAP_PORT_MASK 0xf +#define CAP_PORT_MASK_25 0x7ff #define BLK_NOT_MIR BIT(14) #define MIRROR_EN BIT(15) -- 2.53.0