Do not mark trapped link-local frames as forwarded in hardware. The
switch did not forward them, so the mark would be wrong. Whether such a
frame is forwarded is policy, and that belongs to the bridge, not to the
driver.
The switch traps frames to some of the reserved addresses
01:80:C2:00:00:00 to :0F, that is, sends them only to the CPU. For
example:
- 01:80:C2:00:00:00: STP BPDUs
- 01:80:C2:00:00:02: LACP and other slow protocols
- 01:80:C2:00:00:03: 802.1X (EAPOL)
- 01:80:C2:00:00:0E: LLDP, PTP
Some link-local frames must still be marked as forwarded. The KSZ8873,
which uses the same tag as the KSZ9893, traps only 01:80:C2:00:00:00
and floods LLDP frames (01:80:C2:00:00:0E) like normal multicast.
Without the forwarding mark, the bridge could forward such a frame a
second time, if group_fwd_mask allows it. The tail tag does not say
whether a frame was trapped, so the switch driver gives the tagger a
bitmap of the groups the switch traps. No driver fills the bitmap yet,
so frame handling does not change with this patch alone.
Give the KSZ8795 tag a connect callback that allocates the tagger data,
as the tagger now reads it for every KSZ tag protocol.
Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
---
include/linux/dsa/ksz_common.h | 8 ++++++++
net/dsa/tag_ksz.c | 42 ++++++++++++++++++++++++++++++++++++++++--
2 files changed, 48 insertions(+), 2 deletions(-)
diff --git a/include/linux/dsa/ksz_common.h b/include/linux/dsa/ksz_common.h
index 576a99ca698d13cc3debd41a310502b29fc85c63..66d480c435c2f98b5a77bc64422b43414946f143 100644
--- a/include/linux/dsa/ksz_common.h
+++ b/include/linux/dsa/ksz_common.h
@@ -32,6 +32,14 @@ struct ksz_deferred_xmit_work {
struct ksz_tagger_data {
void (*xmit_work_fn)(struct kthread_work *work);
void (*hwtstamp_set_state)(struct dsa_switch *ds, bool on);
+ /* Bit N is set if the switch traps frames to 01:80:C2:00:00:0N
+ * (N = 0x0 to 0xf), that is, sends them to the CPU only. The tagger
+ * does not mark these frames as forwarded, so the bridge, not the
+ * switch, decides whether to forward them. Only the switch driver
+ * writes this bitmap, from .connect_tag_protocol, before the tagger
+ * receives any frame.
+ */
+ u16 link_local_to_cpu;
};
struct ksz_skb_cb {diff --git a/net/dsa/tag_ksz.c b/net/dsa/tag_ksz.c
index b0340a7be8c9a6dcd52a64117e10fe3e134026e6..16da9daf774904222bd92f771086aa74e1bc390b 100644
--- a/net/dsa/tag_ksz.c
+++ b/net/dsa/tag_ksz.c
@@ -48,11 +48,28 @@ static void ksz_disconnect(struct dsa_switch *ds)
{
struct ksz_tagger_private *priv = ds->tagger_data;
- kthread_destroy_worker(priv->xmit_worker);
+ /* Tags without deferred xmit have no worker */
+ if (priv->xmit_worker)
+ kthread_destroy_worker(priv->xmit_worker);
+
kfree(priv);
ds->tagger_data = NULL;
}
+/* Allocate the tagger data, without a deferred xmit worker */
+static int ksz8795_connect(struct dsa_switch *ds)
+{
+ struct ksz_tagger_private *priv;
+
+ priv = kzalloc_obj(*priv);
+ if (!priv)
+ return -ENOMEM;
+
+ ds->tagger_data = priv;
+
+ return 0;
+}
+
static int ksz_connect(struct dsa_switch *ds)
{
struct ksz_tagger_data *tagger_data;@@ -81,6 +98,19 @@ static int ksz_connect(struct dsa_switch *ds)
return 0;
}
+static bool ksz_link_local_trapped(struct net_device *user, const u8 *addr)
+{
+ struct ksz_tagger_data *tagger_data;
+
+ if (!is_link_local_ether_addr(addr))
+ return false;
+
+ tagger_data = ksz_tagger_data(dsa_user_to_port(user)->ds);
+
+ /* is_link_local_ether_addr() limits addr[5] to 0x00..0x0f */
+ return tagger_data->link_local_to_cpu & BIT(addr[5]);
+}
+
static struct sk_buff *ksz_common_rcv(struct sk_buff *skb,
struct net_device *dev,
unsigned int port, unsigned int len)@@ -96,7 +126,13 @@ static struct sk_buff *ksz_common_rcv(struct sk_buff *skb,
return NULL;
}
- dsa_default_offload_fwd_mark(skb);
+ /* The switch driver reports which link-local groups the switch sends
+ * to the CPU only. The switch did not forward frames to these groups,
+ * so do not mark them, and let the bridge apply its own rules
+ * (group_fwd_mask, STP state).
+ */
+ if (!ksz_link_local_trapped(skb->dev, eth_hdr(skb)->h_dest))
+ dsa_default_offload_fwd_mark(skb);
return skb;
}
@@ -360,6 +396,8 @@ static const struct dsa_device_ops ksz8795_netdev_ops = {
.proto = DSA_TAG_PROTO_KSZ8795,
.xmit = ksz8795_xmit,
.rcv = ksz8795_rcv,
+ .connect = ksz8795_connect,
+ .disconnect = ksz_disconnect,
.needed_tailroom = KSZ_INGRESS_TAG_LEN,
};
--
2.47.3