1 From f0942e00a1abb6404ca4302c66497fc623676c11 Mon Sep 17 00:00:00 2001
2 From: Iwan R Timmer <irtimmer@gmail.com>
3 Date: Thu, 7 Nov 2019 22:11:14 +0100
4 Subject: [PATCH] net: dsa: mv88e6xxx: Add support for port mirroring
6 Add support for configuring port mirroring through the cls_matchall
7 classifier. We do a full ingress and/or egress capture towards a
8 capture port. It allows setting a different capture port for ingress
11 It keeps track of the mirrored ports and the destination ports to
12 prevent changes to the capture port while other ports are being
15 Signed-off-by: Iwan R Timmer <irtimmer@gmail.com>
16 Reviewed-by: Andrew Lunn <andrew@lunn.ch>
17 Signed-off-by: David S. Miller <davem@davemloft.net>
19 drivers/net/dsa/mv88e6xxx/chip.c | 76 +++++++++++++++++++++++++++++
20 drivers/net/dsa/mv88e6xxx/chip.h | 6 +++
21 drivers/net/dsa/mv88e6xxx/global1.c | 18 +++++--
22 drivers/net/dsa/mv88e6xxx/port.c | 37 ++++++++++++++
23 drivers/net/dsa/mv88e6xxx/port.h | 3 ++
24 5 files changed, 136 insertions(+), 4 deletions(-)
26 --- a/drivers/net/dsa/mv88e6xxx/chip.c
27 +++ b/drivers/net/dsa/mv88e6xxx/chip.c
28 @@ -4921,6 +4921,80 @@ static int mv88e6xxx_port_mdb_del(struct
32 +static int mv88e6xxx_port_mirror_add(struct dsa_switch *ds, int port,
33 + struct dsa_mall_mirror_tc_entry *mirror,
36 + enum mv88e6xxx_egress_direction direction = ingress ?
37 + MV88E6XXX_EGRESS_DIR_INGRESS :
38 + MV88E6XXX_EGRESS_DIR_EGRESS;
39 + struct mv88e6xxx_chip *chip = ds->priv;
40 + bool other_mirrors = false;
44 + if (!chip->info->ops->set_egress_port)
47 + mutex_lock(&chip->reg_lock);
48 + if ((ingress ? chip->ingress_dest_port : chip->egress_dest_port) !=
49 + mirror->to_local_port) {
50 + for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
51 + other_mirrors |= ingress ?
52 + chip->ports[i].mirror_ingress :
53 + chip->ports[i].mirror_egress;
55 + /* Can't change egress port when other mirror is active */
56 + if (other_mirrors) {
61 + err = chip->info->ops->set_egress_port(chip,
63 + mirror->to_local_port);
68 + err = mv88e6xxx_port_set_mirror(chip, port, direction, true);
70 + mutex_unlock(&chip->reg_lock);
75 +static void mv88e6xxx_port_mirror_del(struct dsa_switch *ds, int port,
76 + struct dsa_mall_mirror_tc_entry *mirror)
78 + enum mv88e6xxx_egress_direction direction = mirror->ingress ?
79 + MV88E6XXX_EGRESS_DIR_INGRESS :
80 + MV88E6XXX_EGRESS_DIR_EGRESS;
81 + struct mv88e6xxx_chip *chip = ds->priv;
82 + bool other_mirrors = false;
85 + mutex_lock(&chip->reg_lock);
86 + if (mv88e6xxx_port_set_mirror(chip, port, direction, false))
87 + dev_err(ds->dev, "p%d: failed to disable mirroring\n", port);
89 + for (i = 0; i < mv88e6xxx_num_ports(chip); i++)
90 + other_mirrors |= mirror->ingress ?
91 + chip->ports[i].mirror_ingress :
92 + chip->ports[i].mirror_egress;
94 + /* Reset egress port when no other mirror is active */
95 + if (!other_mirrors) {
96 + if (chip->info->ops->set_egress_port(chip,
98 + dsa_upstream_port(ds,
100 + dev_err(ds->dev, "failed to set egress port\n");
103 + mutex_unlock(&chip->reg_lock);
106 static int mv88e6xxx_port_egress_floods(struct dsa_switch *ds, int port,
107 bool unicast, bool multicast)
109 @@ -4975,6 +5049,8 @@ static const struct dsa_switch_ops mv88e
110 .port_mdb_prepare = mv88e6xxx_port_mdb_prepare,
111 .port_mdb_add = mv88e6xxx_port_mdb_add,
112 .port_mdb_del = mv88e6xxx_port_mdb_del,
113 + .port_mirror_add = mv88e6xxx_port_mirror_add,
114 + .port_mirror_del = mv88e6xxx_port_mirror_del,
115 .crosschip_bridge_join = mv88e6xxx_crosschip_bridge_join,
116 .crosschip_bridge_leave = mv88e6xxx_crosschip_bridge_leave,
117 .port_hwtstamp_set = mv88e6xxx_port_hwtstamp_set,
118 --- a/drivers/net/dsa/mv88e6xxx/chip.h
119 +++ b/drivers/net/dsa/mv88e6xxx/chip.h
120 @@ -232,6 +232,8 @@ struct mv88e6xxx_port {
121 u64 vtu_member_violation;
122 u64 vtu_miss_violation;
124 + bool mirror_ingress;
125 + bool mirror_egress;
126 unsigned int serdes_irq;
129 @@ -315,6 +317,10 @@ struct mv88e6xxx_chip {
133 + /* Current ingress and egress monitor ports */
134 + int egress_dest_port;
135 + int ingress_dest_port;
137 /* Per-port timestamping resources. */
138 struct mv88e6xxx_port_hwtstamp port_hwtstamp[DSA_MAX_PORTS];
140 --- a/drivers/net/dsa/mv88e6xxx/global1.c
141 +++ b/drivers/net/dsa/mv88e6xxx/global1.c
142 @@ -267,6 +267,7 @@ int mv88e6095_g1_set_egress_port(struct
143 enum mv88e6xxx_egress_direction direction,
146 + int *dest_port_chip;
150 @@ -276,11 +277,13 @@ int mv88e6095_g1_set_egress_port(struct
153 case MV88E6XXX_EGRESS_DIR_INGRESS:
154 + dest_port_chip = &chip->ingress_dest_port;
155 reg &= MV88E6185_G1_MONITOR_CTL_INGRESS_DEST_MASK;
157 __bf_shf(MV88E6185_G1_MONITOR_CTL_INGRESS_DEST_MASK);
159 case MV88E6XXX_EGRESS_DIR_EGRESS:
160 + dest_port_chip = &chip->egress_dest_port;
161 reg &= MV88E6185_G1_MONITOR_CTL_EGRESS_DEST_MASK;
163 __bf_shf(MV88E6185_G1_MONITOR_CTL_EGRESS_DEST_MASK);
164 @@ -289,7 +292,11 @@ int mv88e6095_g1_set_egress_port(struct
168 - return mv88e6xxx_g1_write(chip, MV88E6185_G1_MONITOR_CTL, reg);
169 + err = mv88e6xxx_g1_write(chip, MV88E6185_G1_MONITOR_CTL, reg);
171 + *dest_port_chip = port;
176 /* Older generations also call this the ARP destination. It has been
177 @@ -325,14 +332,17 @@ int mv88e6390_g1_set_egress_port(struct
178 enum mv88e6xxx_egress_direction direction,
181 + int *dest_port_chip;
186 case MV88E6XXX_EGRESS_DIR_INGRESS:
187 + dest_port_chip = &chip->ingress_dest_port;
188 ptr = MV88E6390_G1_MONITOR_MGMT_CTL_PTR_INGRESS_DEST;
190 case MV88E6XXX_EGRESS_DIR_EGRESS:
191 + dest_port_chip = &chip->egress_dest_port;
192 ptr = MV88E6390_G1_MONITOR_MGMT_CTL_PTR_EGRESS_DEST;
195 @@ -340,10 +350,10 @@ int mv88e6390_g1_set_egress_port(struct
198 err = mv88e6390_g1_monitor_write(chip, ptr, port);
202 + *dest_port_chip = port;
208 int mv88e6390_g1_set_cpu_port(struct mv88e6xxx_chip *chip, int port)
209 --- a/drivers/net/dsa/mv88e6xxx/port.c
210 +++ b/drivers/net/dsa/mv88e6xxx/port.c
211 @@ -1181,6 +1181,43 @@ int mv88e6095_port_set_upstream_port(str
212 return mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL2, reg);
215 +int mv88e6xxx_port_set_mirror(struct mv88e6xxx_chip *chip, int port,
216 + enum mv88e6xxx_egress_direction direction,
224 + err = mv88e6xxx_port_read(chip, port, MV88E6XXX_PORT_CTL2, ®);
228 + switch (direction) {
229 + case MV88E6XXX_EGRESS_DIR_INGRESS:
230 + bit = MV88E6XXX_PORT_CTL2_INGRESS_MONITOR;
231 + mirror_port = &chip->ports[port].mirror_ingress;
233 + case MV88E6XXX_EGRESS_DIR_EGRESS:
234 + bit = MV88E6XXX_PORT_CTL2_EGRESS_MONITOR;
235 + mirror_port = &chip->ports[port].mirror_egress;
245 + err = mv88e6xxx_port_write(chip, port, MV88E6XXX_PORT_CTL2, reg);
247 + *mirror_port = mirror;
252 int mv88e6xxx_port_set_8021q_mode(struct mv88e6xxx_chip *chip, int port,
255 --- a/drivers/net/dsa/mv88e6xxx/port.h
256 +++ b/drivers/net/dsa/mv88e6xxx/port.h
257 @@ -368,6 +368,9 @@ int mv88e6352_port_link_state(struct mv8
258 int mv88e6xxx_port_set_map_da(struct mv88e6xxx_chip *chip, int port);
259 int mv88e6095_port_set_upstream_port(struct mv88e6xxx_chip *chip, int port,
261 +int mv88e6xxx_port_set_mirror(struct mv88e6xxx_chip *chip, int port,
262 + enum mv88e6xxx_egress_direction direction,
265 int mv88e6xxx_port_disable_learn_limit(struct mv88e6xxx_chip *chip, int port);
266 int mv88e6xxx_port_disable_pri_override(struct mv88e6xxx_chip *chip, int port);