From a139ab1b82f8f597570e5b623a16d43ea174c517 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= Date: Fri, 19 Mar 2021 10:53:51 +0100 Subject: bmips: backport b53 legacy tags support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These patches have been accepted upstream for linux 5.13. Signed-off-by: Álvaro Fernández Rojas --- ...lement-a-central-TX-reallocation-procedur.patch | 104 ++++++++++ ...-dsa-tag_brcm-add-support-for-legacy-tags.patch | 180 ++++++++++++++++++ ...050-v5.13-net-dsa-b53-support-legacy-tags.patch | 53 ++++++ ...-dsa-b53-support-tags-for-legacy-switches.patch | 209 --------------------- 4 files changed, 337 insertions(+), 209 deletions(-) create mode 100644 target/linux/bmips/patches-5.10/010-v5.11-net-dsa-implement-a-central-TX-reallocation-procedur.patch create mode 100644 target/linux/bmips/patches-5.10/049-v5.13-net-dsa-tag_brcm-add-support-for-legacy-tags.patch create mode 100644 target/linux/bmips/patches-5.10/050-v5.13-net-dsa-b53-support-legacy-tags.patch delete mode 100644 target/linux/bmips/patches-5.10/502-net-dsa-b53-support-tags-for-legacy-switches.patch (limited to 'target/linux/bmips') diff --git a/target/linux/bmips/patches-5.10/010-v5.11-net-dsa-implement-a-central-TX-reallocation-procedur.patch b/target/linux/bmips/patches-5.10/010-v5.11-net-dsa-implement-a-central-TX-reallocation-procedur.patch new file mode 100644 index 0000000000..4171a69d1d --- /dev/null +++ b/target/linux/bmips/patches-5.10/010-v5.11-net-dsa-implement-a-central-TX-reallocation-procedur.patch @@ -0,0 +1,104 @@ +From a3b0b6479700a5b0af2c631cb2ec0fb7a0d978f2 Mon Sep 17 00:00:00 2001 +From: Vladimir Oltean +Date: Sun, 1 Nov 2020 21:16:09 +0200 +Subject: [PATCH] net: dsa: implement a central TX reallocation procedure + +At the moment, taggers are left with the task of ensuring that the skb +headers are writable (which they aren't, if the frames were cloned for +TX timestamping, for flooding by the bridge, etc), and that there is +enough space in the skb data area for the DSA tag to be pushed. + +Moreover, the life of tail taggers is even harder, because they need to +ensure that short frames have enough padding, a problem that normal +taggers don't have. + +The principle of the DSA framework is that everything except for the +most intimate hardware specifics (like in this case, the actual packing +of the DSA tag bits) should be done inside the core, to avoid having +code paths that are very rarely tested. + +So provide a TX reallocation procedure that should cover the known needs +of DSA today. + +Note that this patch also gives the network stack a good hint about the +headroom/tailroom it's going to need. Up till now it wasn't doing that. +So the reallocation procedure should really be there only for the +exceptional cases, and for cloned packets which need to be unshared. + +Signed-off-by: Vladimir Oltean +Tested-by: Christian Eggers # For tail taggers only +Tested-by: Kurt Kanzenbach +Reviewed-by: Florian Fainelli +Signed-off-by: Jakub Kicinski +--- + net/dsa/slave.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ + 1 file changed, 45 insertions(+) + +--- a/net/dsa/slave.c ++++ b/net/dsa/slave.c +@@ -548,6 +548,30 @@ netdev_tx_t dsa_enqueue_skb(struct sk_bu + } + EXPORT_SYMBOL_GPL(dsa_enqueue_skb); + ++static int dsa_realloc_skb(struct sk_buff *skb, struct net_device *dev) ++{ ++ int needed_headroom = dev->needed_headroom; ++ int needed_tailroom = dev->needed_tailroom; ++ ++ /* For tail taggers, we need to pad short frames ourselves, to ensure ++ * that the tail tag does not fail at its role of being at the end of ++ * the packet, once the master interface pads the frame. Account for ++ * that pad length here, and pad later. ++ */ ++ if (unlikely(needed_tailroom && skb->len < ETH_ZLEN)) ++ needed_tailroom += ETH_ZLEN - skb->len; ++ /* skb_headroom() returns unsigned int... */ ++ needed_headroom = max_t(int, needed_headroom - skb_headroom(skb), 0); ++ needed_tailroom = max_t(int, needed_tailroom - skb_tailroom(skb), 0); ++ ++ if (likely(!needed_headroom && !needed_tailroom && !skb_cloned(skb))) ++ /* No reallocation needed, yay! */ ++ return 0; ++ ++ return pskb_expand_head(skb, needed_headroom, needed_tailroom, ++ GFP_ATOMIC); ++} ++ + static netdev_tx_t dsa_slave_xmit(struct sk_buff *skb, struct net_device *dev) + { + struct dsa_slave_priv *p = netdev_priv(dev); +@@ -567,6 +591,17 @@ static netdev_tx_t dsa_slave_xmit(struct + */ + dsa_skb_tx_timestamp(p, skb); + ++ if (dsa_realloc_skb(skb, dev)) { ++ dev_kfree_skb_any(skb); ++ return NETDEV_TX_OK; ++ } ++ ++ /* needed_tailroom should still be 'warm' in the cache line from ++ * dsa_realloc_skb(), which has also ensured that padding is safe. ++ */ ++ if (dev->needed_tailroom) ++ eth_skb_pad(skb); ++ + /* Transmit function may have to reallocate the original SKB, + * in which case it must have freed it. Only free it here on error. + */ +@@ -1825,6 +1860,16 @@ int dsa_slave_create(struct dsa_port *po + slave_dev->netdev_ops = &dsa_slave_netdev_ops; + if (ds->ops->port_max_mtu) + slave_dev->max_mtu = ds->ops->port_max_mtu(ds, port->index); ++ if (cpu_dp->tag_ops->tail_tag) ++ slave_dev->needed_tailroom = cpu_dp->tag_ops->overhead; ++ else ++ slave_dev->needed_headroom = cpu_dp->tag_ops->overhead; ++ /* Try to save one extra realloc later in the TX path (in the master) ++ * by also inheriting the master's needed headroom and tailroom. ++ * The 8021q driver also does this. ++ */ ++ slave_dev->needed_headroom += master->needed_headroom; ++ slave_dev->needed_tailroom += master->needed_tailroom; + SET_NETDEV_DEVTYPE(slave_dev, &dsa_type); + + netdev_for_each_tx_queue(slave_dev, dsa_slave_set_lockdep_class_one, diff --git a/target/linux/bmips/patches-5.10/049-v5.13-net-dsa-tag_brcm-add-support-for-legacy-tags.patch b/target/linux/bmips/patches-5.10/049-v5.13-net-dsa-tag_brcm-add-support-for-legacy-tags.patch new file mode 100644 index 0000000000..a9b689ca9c --- /dev/null +++ b/target/linux/bmips/patches-5.10/049-v5.13-net-dsa-tag_brcm-add-support-for-legacy-tags.patch @@ -0,0 +1,180 @@ +From 964dbf186eaa84d409c359ddf09c827a3fbe8228 Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= +Date: Wed, 17 Mar 2021 11:29:26 +0100 +Subject: [PATCH 1/2] net: dsa: tag_brcm: add support for legacy tags +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +Add support for legacy Broadcom tags, which are similar to DSA_TAG_PROTO_BRCM. +These tags are used on BCM5325, BCM5365 and BCM63xx switches. + +Signed-off-by: Álvaro Fernández Rojas +Signed-off-by: David S. Miller +--- + include/net/dsa.h | 2 + + net/dsa/Kconfig | 7 +++ + net/dsa/tag_brcm.c | 107 +++++++++++++++++++++++++++++++++++++++++++-- + 3 files changed, 113 insertions(+), 3 deletions(-) + +--- a/include/net/dsa.h ++++ b/include/net/dsa.h +@@ -45,10 +45,12 @@ struct phylink_link_state; + #define DSA_TAG_PROTO_OCELOT_VALUE 15 + #define DSA_TAG_PROTO_AR9331_VALUE 16 + #define DSA_TAG_PROTO_RTL4_A_VALUE 17 ++#define DSA_TAG_PROTO_BRCM_LEGACY_VALUE 22 + + enum dsa_tag_protocol { + DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, + DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE, ++ DSA_TAG_PROTO_BRCM_LEGACY = DSA_TAG_PROTO_BRCM_LEGACY_VALUE, + DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE, + DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE, + DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE, +--- a/net/dsa/Kconfig ++++ b/net/dsa/Kconfig +@@ -47,6 +47,13 @@ config NET_DSA_TAG_BRCM + Say Y if you want to enable support for tagging frames for the + Broadcom switches which place the tag after the MAC source address. + ++config NET_DSA_TAG_BRCM_LEGACY ++ tristate "Tag driver for Broadcom legacy switches using in-frame headers" ++ select NET_DSA_TAG_BRCM_COMMON ++ help ++ Say Y if you want to enable support for tagging frames for the ++ Broadcom legacy switches which place the tag after the MAC source ++ address. + + config NET_DSA_TAG_BRCM_PREPEND + tristate "Tag driver for Broadcom switches using prepended headers" +--- a/net/dsa/tag_brcm.c ++++ b/net/dsa/tag_brcm.c +@@ -11,9 +11,26 @@ + + #include "dsa_priv.h" + +-/* This tag length is 4 bytes, older ones were 6 bytes, we do not +- * handle them +- */ ++/* Legacy Broadcom tag (6 bytes) */ ++#define BRCM_LEG_TAG_LEN 6 ++ ++/* Type fields */ ++/* 1st byte in the tag */ ++#define BRCM_LEG_TYPE_HI 0x88 ++/* 2nd byte in the tag */ ++#define BRCM_LEG_TYPE_LO 0x74 ++ ++/* Tag fields */ ++/* 3rd byte in the tag */ ++#define BRCM_LEG_UNICAST (0 << 5) ++#define BRCM_LEG_MULTICAST (1 << 5) ++#define BRCM_LEG_EGRESS (2 << 5) ++#define BRCM_LEG_INGRESS (3 << 5) ++ ++/* 6th byte in the tag */ ++#define BRCM_LEG_PORT_ID (0xf) ++ ++/* Newer Broadcom tag (4 bytes) */ + #define BRCM_TAG_LEN 4 + + /* Tag is constructed and desconstructed using byte by byte access +@@ -197,6 +214,87 @@ DSA_TAG_DRIVER(brcm_netdev_ops); + MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM); + #endif + ++#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_LEGACY) ++static struct sk_buff *brcm_leg_tag_xmit(struct sk_buff *skb, ++ struct net_device *dev) ++{ ++ struct dsa_port *dp = dsa_slave_to_port(dev); ++ u8 *brcm_tag; ++ ++ /* The Ethernet switch we are interfaced with needs packets to be at ++ * least 64 bytes (including FCS) otherwise they will be discarded when ++ * they enter the switch port logic. When Broadcom tags are enabled, we ++ * need to make sure that packets are at least 70 bytes ++ * (including FCS and tag) because the length verification is done after ++ * the Broadcom tag is stripped off the ingress packet. ++ * ++ * Let dsa_slave_xmit() free the SKB ++ */ ++ if (__skb_put_padto(skb, ETH_ZLEN + BRCM_LEG_TAG_LEN, false)) ++ return NULL; ++ ++ skb_push(skb, BRCM_LEG_TAG_LEN); ++ ++ memmove(skb->data, skb->data + BRCM_LEG_TAG_LEN, 2 * ETH_ALEN); ++ ++ brcm_tag = skb->data + 2 * ETH_ALEN; ++ ++ /* Broadcom tag type */ ++ brcm_tag[0] = BRCM_LEG_TYPE_HI; ++ brcm_tag[1] = BRCM_LEG_TYPE_LO; ++ ++ /* Broadcom tag value */ ++ brcm_tag[2] = BRCM_LEG_EGRESS; ++ brcm_tag[3] = 0; ++ brcm_tag[4] = 0; ++ brcm_tag[5] = dp->index & BRCM_LEG_PORT_ID; ++ ++ return skb; ++} ++ ++static struct sk_buff *brcm_leg_tag_rcv(struct sk_buff *skb, ++ struct net_device *dev, ++ struct packet_type *pt) ++{ ++ int source_port; ++ u8 *brcm_tag; ++ ++ if (unlikely(!pskb_may_pull(skb, BRCM_LEG_PORT_ID))) ++ return NULL; ++ ++ brcm_tag = skb->data - 2; ++ ++ source_port = brcm_tag[5] & BRCM_LEG_PORT_ID; ++ ++ skb->dev = dsa_master_find_slave(dev, 0, source_port); ++ if (!skb->dev) ++ return NULL; ++ ++ /* Remove Broadcom tag and update checksum */ ++ skb_pull_rcsum(skb, BRCM_LEG_TAG_LEN); ++ ++ skb->offload_fwd_mark = 1; ++ ++ /* Move the Ethernet DA and SA */ ++ memmove(skb->data - ETH_HLEN, ++ skb->data - ETH_HLEN - BRCM_LEG_TAG_LEN, ++ 2 * ETH_ALEN); ++ ++ return skb; ++} ++ ++static const struct dsa_device_ops brcm_legacy_netdev_ops = { ++ .name = "brcm-legacy", ++ .proto = DSA_TAG_PROTO_BRCM_LEGACY, ++ .xmit = brcm_leg_tag_xmit, ++ .rcv = brcm_leg_tag_rcv, ++ .overhead = BRCM_LEG_TAG_LEN, ++}; ++ ++DSA_TAG_DRIVER(brcm_legacy_netdev_ops); ++MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_LEGACY); ++#endif /* CONFIG_NET_DSA_TAG_BRCM_LEGACY */ ++ + #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND) + static struct sk_buff *brcm_tag_xmit_prepend(struct sk_buff *skb, + struct net_device *dev) +@@ -229,6 +327,9 @@ static struct dsa_tag_driver *dsa_tag_dr + #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) + &DSA_TAG_DRIVER_NAME(brcm_netdev_ops), + #endif ++#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_LEGACY) ++ &DSA_TAG_DRIVER_NAME(brcm_legacy_netdev_ops), ++#endif + #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND) + &DSA_TAG_DRIVER_NAME(brcm_prepend_netdev_ops), + #endif diff --git a/target/linux/bmips/patches-5.10/050-v5.13-net-dsa-b53-support-legacy-tags.patch b/target/linux/bmips/patches-5.10/050-v5.13-net-dsa-b53-support-legacy-tags.patch new file mode 100644 index 0000000000..59a7217663 --- /dev/null +++ b/target/linux/bmips/patches-5.10/050-v5.13-net-dsa-b53-support-legacy-tags.patch @@ -0,0 +1,53 @@ +From 46c5176c586c81306bf9e7024c13b95da775490f Mon Sep 17 00:00:00 2001 +From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= +Date: Wed, 17 Mar 2021 11:29:27 +0100 +Subject: [PATCH 2/2] net: dsa: b53: support legacy tags +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +These tags are used on BCM5325, BCM5365 and BCM63xx switches. + +Signed-off-by: Álvaro Fernández Rojas +Acked-by: Florian Fainelli +Signed-off-by: David S. Miller +--- + drivers/net/dsa/b53/Kconfig | 1 + + drivers/net/dsa/b53/b53_common.c | 12 +++++++----- + 2 files changed, 8 insertions(+), 5 deletions(-) + +--- a/drivers/net/dsa/b53/Kconfig ++++ b/drivers/net/dsa/b53/Kconfig +@@ -3,6 +3,7 @@ menuconfig B53 + tristate "Broadcom BCM53xx managed switch support" + depends on NET_DSA + select NET_DSA_TAG_BRCM ++ select NET_DSA_TAG_BRCM_LEGACY + select NET_DSA_TAG_BRCM_PREPEND + help + This driver adds support for Broadcom managed switch chips. It supports +--- a/drivers/net/dsa/b53/b53_common.c ++++ b/drivers/net/dsa/b53/b53_common.c +@@ -2010,15 +2010,17 @@ enum dsa_tag_protocol b53_get_tag_protoc + { + struct b53_device *dev = ds->priv; + +- /* Older models (5325, 5365) support a different tag format that we do +- * not support in net/dsa/tag_brcm.c yet. +- */ +- if (is5325(dev) || is5365(dev) || +- !b53_can_enable_brcm_tags(ds, port, mprot)) { ++ if (!b53_can_enable_brcm_tags(ds, port, mprot)) { + dev->tag_protocol = DSA_TAG_PROTO_NONE; + goto out; + } + ++ /* Older models require a different 6 byte tag */ ++ if (is5325(dev) || is5365(dev) || is63xx(dev)) { ++ dev->tag_protocol = DSA_TAG_PROTO_BRCM_LEGACY; ++ goto out; ++ } ++ + /* Broadcom BCM58xx chips have a flow accelerator on Port 8 + * which requires us to use the prepended Broadcom tag type + */ diff --git a/target/linux/bmips/patches-5.10/502-net-dsa-b53-support-tags-for-legacy-switches.patch b/target/linux/bmips/patches-5.10/502-net-dsa-b53-support-tags-for-legacy-switches.patch deleted file mode 100644 index b8aa8b844d..0000000000 --- a/target/linux/bmips/patches-5.10/502-net-dsa-b53-support-tags-for-legacy-switches.patch +++ /dev/null @@ -1,209 +0,0 @@ -From 3bc3d79efdff6e29b80bf35f7a56baaa36e4d8fe Mon Sep 17 00:00:00 2001 -From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Rojas?= -Date: Fri, 12 Mar 2021 12:35:39 +0100 -Subject: [PATCH] net: dsa: b53: support tags for legacy switches -MIME-Version: 1.0 -Content-Type: text/plain; charset=UTF-8 -Content-Transfer-Encoding: 8bit - -Signed-off-by: Álvaro Fernández Rojas ---- - drivers/net/dsa/b53/Kconfig | 1 + - drivers/net/dsa/b53/b53_common.c | 6 +++ - include/net/dsa.h | 2 + - net/dsa/Kconfig | 7 +++ - net/dsa/tag_brcm.c | 93 ++++++++++++++++++++++++++++++++ - 5 files changed, 109 insertions(+) - ---- a/drivers/net/dsa/b53/Kconfig -+++ b/drivers/net/dsa/b53/Kconfig -@@ -3,6 +3,7 @@ menuconfig B53 - tristate "Broadcom BCM53xx managed switch support" - depends on NET_DSA - select NET_DSA_TAG_BRCM -+ select NET_DSA_TAG_BRCM_LEGACY - select NET_DSA_TAG_BRCM_PREPEND - help - This driver adds support for Broadcom managed switch chips. It supports ---- a/drivers/net/dsa/b53/b53_common.c -+++ b/drivers/net/dsa/b53/b53_common.c -@@ -1992,6 +1992,7 @@ static bool b53_can_enable_brcm_tags(str - - switch (tag_protocol) { - case DSA_TAG_PROTO_BRCM: -+ case DSA_TAG_PROTO_BRCM_LEGACY: - case DSA_TAG_PROTO_BRCM_PREPEND: - dev_warn(ds->dev, - "Port %d is stacked to Broadcom tag switch\n", port); -@@ -2013,12 +2014,16 @@ enum dsa_tag_protocol b53_get_tag_protoc - /* Older models (5325, 5365) support a different tag format that we do - * not support in net/dsa/tag_brcm.c yet. - */ -- if (is5325(dev) || is5365(dev) || -- !b53_can_enable_brcm_tags(ds, port, mprot)) { -+ if (!b53_can_enable_brcm_tags(ds, port, mprot)) { - dev->tag_protocol = DSA_TAG_PROTO_NONE; - goto out; - } - -+ if (is5325(dev) || is5365(dev) || is63xx(dev)) { -+ dev->tag_protocol = DSA_TAG_PROTO_BRCM_LEGACY; -+ goto out; -+ } -+ - /* Broadcom BCM58xx chips have a flow accelerator on Port 8 - * which requires us to use the prepended Broadcom tag type - */ ---- a/include/net/dsa.h -+++ b/include/net/dsa.h -@@ -45,10 +45,12 @@ struct phylink_link_state; - #define DSA_TAG_PROTO_OCELOT_VALUE 15 - #define DSA_TAG_PROTO_AR9331_VALUE 16 - #define DSA_TAG_PROTO_RTL4_A_VALUE 17 -+#define DSA_TAG_PROTO_BRCM_LEGACY_VALUE 22 - - enum dsa_tag_protocol { - DSA_TAG_PROTO_NONE = DSA_TAG_PROTO_NONE_VALUE, - DSA_TAG_PROTO_BRCM = DSA_TAG_PROTO_BRCM_VALUE, -+ DSA_TAG_PROTO_BRCM_LEGACY = DSA_TAG_PROTO_BRCM_LEGACY_VALUE, - DSA_TAG_PROTO_BRCM_PREPEND = DSA_TAG_PROTO_BRCM_PREPEND_VALUE, - DSA_TAG_PROTO_DSA = DSA_TAG_PROTO_DSA_VALUE, - DSA_TAG_PROTO_EDSA = DSA_TAG_PROTO_EDSA_VALUE, ---- a/net/dsa/Kconfig -+++ b/net/dsa/Kconfig -@@ -47,6 +47,13 @@ config NET_DSA_TAG_BRCM - Say Y if you want to enable support for tagging frames for the - Broadcom switches which place the tag after the MAC source address. - -+config NET_DSA_TAG_BRCM_LEGACY -+ tristate "Tag driver for Broadcom legacy switches using in-frame headers" -+ select NET_DSA_TAG_BRCM_COMMON -+ help -+ Say Y if you want to enable support for tagging frames for the -+ Broadcom legacy switches which place the tag after the MAC source -+ address. - - config NET_DSA_TAG_BRCM_PREPEND - tristate "Tag driver for Broadcom switches using prepended headers" ---- a/net/dsa/tag_brcm.c -+++ b/net/dsa/tag_brcm.c -@@ -8,9 +8,23 @@ - #include - #include - #include -+#include - - #include "dsa_priv.h" - -+struct bcm_legacy_tag { -+ uint16_t type; -+#define BRCM_LEG_TYPE 0x8874 -+ -+ uint32_t tag; -+#define BRCM_LEG_TAG_PORT_ID (0xf) -+#define BRCM_LEG_TAG_MULTICAST (1 << 29) -+#define BRCM_LEG_TAG_EGRESS (2 << 29) -+#define BRCM_LEG_TAG_INGRESS (3 << 29) -+} __attribute__((packed)); -+ -+#define BRCM_LEG_TAG_LEN sizeof(struct bcm_legacy_tag) -+ - /* This tag length is 4 bytes, older ones were 6 bytes, we do not - * handle them - */ -@@ -197,6 +211,85 @@ DSA_TAG_DRIVER(brcm_netdev_ops); - MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM); - #endif - -+#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_LEGACY) -+static struct sk_buff *brcm_leg_tag_xmit(struct sk_buff *skb, -+ struct net_device *dev) -+{ -+ struct dsa_port *dp = dsa_slave_to_port(dev); -+ struct bcm_legacy_tag *brcm_tag; -+ -+ if (skb_cow_head(skb, BRCM_LEG_TAG_LEN) < 0) -+ return NULL; -+ -+ /* The Ethernet switch we are interfaced with needs packets to be at -+ * least 64 bytes (including FCS) otherwise they will be discarded when -+ * they enter the switch port logic. When Broadcom tags are enabled, we -+ * need to make sure that packets are at least 70 bytes -+ * (including FCS and tag) because the length verification is done after -+ * the Broadcom tag is stripped off the ingress packet. -+ * -+ * Let dsa_slave_xmit() free the SKB -+ */ -+ if (__skb_put_padto(skb, ETH_ZLEN + BRCM_LEG_TAG_LEN, false)) -+ return NULL; -+ -+ skb_push(skb, BRCM_LEG_TAG_LEN); -+ -+ memmove(skb->data, skb->data + BRCM_LEG_TAG_LEN, 2 * ETH_ALEN); -+ -+ brcm_tag = (struct bcm_legacy_tag *) (skb->data + 2 * ETH_ALEN); -+ -+ brcm_tag->type = BRCM_LEG_TYPE; -+ brcm_tag->tag = BRCM_LEG_TAG_EGRESS; -+ brcm_tag->tag |= dp->index & BRCM_LEG_TAG_PORT_ID; -+ -+ return skb; -+} -+ -+ -+static struct sk_buff *brcm_leg_tag_rcv(struct sk_buff *skb, -+ struct net_device *dev, -+ struct packet_type *pt) -+{ -+ int source_port; -+ struct bcm_legacy_tag *brcm_tag; -+ -+ if (unlikely(!pskb_may_pull(skb, BRCM_LEG_TAG_LEN))) -+ return NULL; -+ -+ brcm_tag = (struct bcm_legacy_tag *) (skb->data - 2); -+ -+ source_port = brcm_tag->tag & BRCM_LEG_TAG_PORT_ID; -+ -+ skb->dev = dsa_master_find_slave(dev, 0, source_port); -+ if (!skb->dev) -+ return NULL; -+ -+ /* Remove Broadcom tag and update checksum */ -+ skb_pull_rcsum(skb, BRCM_LEG_TAG_LEN); -+ -+ skb->offload_fwd_mark = 1; -+ -+ /* Move the Ethernet DA and SA */ -+ memmove(skb->data - ETH_HLEN, -+ skb->data - ETH_HLEN - BRCM_LEG_TAG_LEN, -+ 2 * ETH_ALEN); -+ -+ return skb; -+} -+ -+static const struct dsa_device_ops brcm_legacy_netdev_ops = { -+ .name = "brcm-legacy", -+ .proto = DSA_TAG_PROTO_BRCM_LEGACY, -+ .xmit = brcm_leg_tag_xmit, -+ .rcv = brcm_leg_tag_rcv, -+ .overhead = BRCM_LEG_TAG_LEN, -+}; -+ -+DSA_TAG_DRIVER(brcm_legacy_netdev_ops); -+MODULE_ALIAS_DSA_TAG_DRIVER(DSA_TAG_PROTO_BRCM_LEGACY); -+#endif /* CONFIG_NET_DSA_TAG_BRCM_LEGACY */ -+ - #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND) - static struct sk_buff *brcm_tag_xmit_prepend(struct sk_buff *skb, - struct net_device *dev) -@@ -229,6 +322,9 @@ static struct dsa_tag_driver *dsa_tag_dr - #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM) - &DSA_TAG_DRIVER_NAME(brcm_netdev_ops), - #endif -+#if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_LEGACY) -+ &DSA_TAG_DRIVER_NAME(brcm_legacy_netdev_ops), -+#endif - #if IS_ENABLED(CONFIG_NET_DSA_TAG_BRCM_PREPEND) - &DSA_TAG_DRIVER_NAME(brcm_prepend_netdev_ops), - #endif -- cgit v1.2.3