Do not mark a link-local frame as forwarded in hardware if the switch trapped it to the CPU. The switch did not forward such a frame, so the bridge has to decide whether to forward it. Not all Microchip KSZ switch families trap the full set of link-local groups. The KSZ9477 family traps all groups from 01:80:C2:00:00:00 to :0F except :01. The KSZ8873 uses the same tag as the KSZ9893, but traps only :00 and floods most other groups like normal multicast. These flooded frames must stay marked, or the bridge would forward them a second time. The switch driver therefore gives the tagger a bitmap of the groups that the switch traps. No driver fills the bitmap yet, so frame handling does not change with this patch alone. The tagger now reads its data for every KSZ tag, so the KSZ8795 tag gets a connect callback that allocates it. Signed-off-by: Oleksij Rempel --- Changes in v2: - Use dsa_link_local_offload_fwd_mark() (Andrew). - Commit message: shorten it. --- include/linux/dsa/ksz_common.h | 5 +++++ net/dsa/tag_ksz.c | 25 +++++++++++++++++++++++-- 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/include/linux/dsa/ksz_common.h b/include/linux/dsa/ksz_common.h index 576a99ca698d13cc3debd41a310502b29fc85c63..cef71188a6c651dae37d4238b527c89a303f6b79 100644 --- a/include/linux/dsa/ksz_common.h +++ b/include/linux/dsa/ksz_common.h @@ -32,6 +32,11 @@ 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: the switch traps frames to 01:80:C2:00:00:0N to the CPU. + * A switch driver that traps link-local groups sets it in + * .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..413794e97e1594931ad0505b88299b47030d2172 100644 --- a/net/dsa/tag_ksz.c +++ b/net/dsa/tag_ksz.c @@ -48,11 +48,27 @@ 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; } +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; @@ -85,6 +101,8 @@ static struct sk_buff *ksz_common_rcv(struct sk_buff *skb, struct net_device *dev, unsigned int port, unsigned int len) { + struct ksz_tagger_data *tagger_data; + skb->dev = dsa_conduit_find_user(dev, 0, port); if (!skb->dev) { kfree_skb(skb); @@ -96,7 +114,8 @@ static struct sk_buff *ksz_common_rcv(struct sk_buff *skb, return NULL; } - dsa_default_offload_fwd_mark(skb); + tagger_data = ksz_tagger_data(dsa_user_to_port(skb->dev)->ds); + dsa_link_local_offload_fwd_mark(skb, tagger_data->link_local_to_cpu); return skb; } @@ -360,6 +379,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