netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH net-next 0/4] DSA tagger helpers
@ 2021-08-09 11:57 Vladimir Oltean
  2021-08-09 11:57 ` [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX Vladimir Oltean
                   ` (3 more replies)
  0 siblings, 4 replies; 17+ messages in thread
From: Vladimir Oltean @ 2021-08-09 11:57 UTC (permalink / raw)
  To: netdev, Jakub Kicinski, David S. Miller
  Cc: Andrew Lunn, Florian Fainelli, Vivien Didelot, Vladimir Oltean,
	Linus Walleij, DENG Qingfang, John Crispin, Sean Wang,
	Landen Chao

The goal of this series is to minimize the use of memmove and skb->data
in the DSA tagging protocol drivers. Unfiltered access to this level of
information is not very friendly to drive-by contributors, and sometimes
is also not the easiest to review.

For starters, I have converted the most common form of DSA tagging
protocols: the DSA headers which are placed where the EtherType is.

The helper functions introduced by this series are:
- dsa_alloc_etype_header
- dsa_strip_etype_header
- dsa_etype_header_pos_rx
- dsa_etype_header_pos_tx

Vladimir Oltean (4):
  net: dsa: create a helper that strips EtherType DSA headers on RX
  net: dsa: create a helper which allocates space for EtherType DSA
    headers
  net: dsa: create a helper for locating EtherType DSA headers on RX
  net: dsa: create a helper for locating EtherType DSA headers on TX

 net/dsa/dsa_priv.h    | 78 +++++++++++++++++++++++++++++++++++++++++++
 net/dsa/tag_brcm.c    | 16 +++------
 net/dsa/tag_dsa.c     | 20 +++++------
 net/dsa/tag_lan9303.c | 18 ++++------
 net/dsa/tag_mtk.c     | 14 +++-----
 net/dsa/tag_qca.c     | 13 +++-----
 net/dsa/tag_rtl4_a.c  | 16 +++------
 net/dsa/tag_sja1105.c | 25 +++++---------
 8 files changed, 119 insertions(+), 81 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 17+ messages in thread

* [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX
  2021-08-09 11:57 [RFC PATCH net-next 0/4] DSA tagger helpers Vladimir Oltean
@ 2021-08-09 11:57 ` Vladimir Oltean
  2021-08-10  1:01   ` Andrew Lunn
                     ` (2 more replies)
  2021-08-09 11:57 ` [RFC PATCH net-next 2/4] net: dsa: create a helper which allocates space for EtherType DSA headers Vladimir Oltean
                   ` (2 subsequent siblings)
  3 siblings, 3 replies; 17+ messages in thread
From: Vladimir Oltean @ 2021-08-09 11:57 UTC (permalink / raw)
  To: netdev, Jakub Kicinski, David S. Miller
  Cc: Andrew Lunn, Florian Fainelli, Vivien Didelot, Vladimir Oltean,
	Linus Walleij, DENG Qingfang, John Crispin, Sean Wang,
	Landen Chao

All header taggers open-code a memmove that is fairly not all that
obvious, and we can hide the details behind a helper function, since the
only thing specific to the driver is the length of the header tag.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/dsa_priv.h    | 26 ++++++++++++++++++++++++++
 net/dsa/tag_brcm.c    | 10 ++--------
 net/dsa/tag_dsa.c     |  8 ++------
 net/dsa/tag_lan9303.c |  5 +++--
 net/dsa/tag_mtk.c     |  4 +---
 net/dsa/tag_qca.c     |  3 +--
 net/dsa/tag_rtl4_a.c  |  5 +----
 net/dsa/tag_sja1105.c |  4 +---
 8 files changed, 37 insertions(+), 28 deletions(-)

diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 9575cabd3ec3..8a12ec1f9d21 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -452,6 +452,32 @@ static inline void dsa_default_offload_fwd_mark(struct sk_buff *skb)
 	skb->offload_fwd_mark = !!(dp->bridge_dev);
 }
 
+/* Helper for removing DSA header tags from packets in the RX path.
+ * Must not be called before skb_pull(len).
+ *                                                                 skb->data
+ *                                                                         |
+ *                                                                         v
+ * |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
+ * +-----------------------+-----------------------+---------------+-------+
+ * |    Destination MAC    |      Source MAC       |  DSA header   | EType |
+ * +-----------------------+-----------------------+---------------+-------+
+ *                                                 |               |
+ * <----- len ----->                               <----- len ----->
+ *                 |
+ *       >>>>>>>   v
+ *       >>>>>>>   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
+ *       >>>>>>>   +-----------------------+-----------------------+-------+
+ *       >>>>>>>   |    Destination MAC    |      Source MAC       | EType |
+ *                 +-----------------------+-----------------------+-------+
+ *                                                                         ^
+ *                                                                         |
+ *                                                                 skb->data
+ */
+static inline void dsa_strip_etype_header(struct sk_buff *skb, int len)
+{
+	memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - len, 2 * ETH_ALEN);
+}
+
 /* switch.c */
 int dsa_switch_register_notifier(struct dsa_switch *ds);
 void dsa_switch_unregister_notifier(struct dsa_switch *ds);
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 96e93b544a0d..2fc546b31ad8 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -190,10 +190,7 @@ static struct sk_buff *brcm_tag_rcv(struct sk_buff *skb, struct net_device *dev)
 	if (!nskb)
 		return nskb;
 
-	/* Move the Ethernet DA and SA */
-	memmove(nskb->data - ETH_HLEN,
-		nskb->data - ETH_HLEN - BRCM_TAG_LEN,
-		2 * ETH_ALEN);
+	dsa_strip_etype_header(skb, BRCM_TAG_LEN);
 
 	return nskb;
 }
@@ -270,10 +267,7 @@ static struct sk_buff *brcm_leg_tag_rcv(struct sk_buff *skb,
 
 	dsa_default_offload_fwd_mark(skb);
 
-	/* Move the Ethernet DA and SA */
-	memmove(skb->data - ETH_HLEN,
-		skb->data - ETH_HLEN - BRCM_LEG_TAG_LEN,
-		2 * ETH_ALEN);
+	dsa_strip_etype_header(skb, BRCM_LEG_TAG_LEN);
 
 	return skb;
 }
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index e32f8160e895..ad9c841c998f 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -312,14 +312,10 @@ static struct sk_buff *dsa_rcv_ll(struct sk_buff *skb, struct net_device *dev,
 		memcpy(dsa_header, new_header, DSA_HLEN);
 
 		if (extra)
-			memmove(skb->data - ETH_HLEN,
-				skb->data - ETH_HLEN - extra,
-				2 * ETH_ALEN);
+			dsa_strip_etype_header(skb, extra);
 	} else {
 		skb_pull_rcsum(skb, DSA_HLEN);
-		memmove(skb->data - ETH_HLEN,
-			skb->data - ETH_HLEN - DSA_HLEN - extra,
-			2 * ETH_ALEN);
+		dsa_strip_etype_header(skb, DSA_HLEN + extra);
 	}
 
 	return skb;
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index 58d3a0e712d2..af13c0a9cb41 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -112,8 +112,9 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
 	 * and the current ethertype field.
 	 */
 	skb_pull_rcsum(skb, 2 + 2);
-	memmove(skb->data - ETH_HLEN, skb->data - (ETH_HLEN + LAN9303_TAG_LEN),
-		2 * ETH_ALEN);
+
+	dsa_strip_etype_header(skb, LAN9303_TAG_LEN);
+
 	if (!(lan9303_tag1 & LAN9303_TAG_RX_TRAPPED_TO_CPU))
 		dsa_default_offload_fwd_mark(skb);
 
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index bbf37c031d44..6a78e9f146e5 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -80,9 +80,7 @@ static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev)
 	/* Remove MTK tag and recalculate checksum. */
 	skb_pull_rcsum(skb, MTK_HDR_LEN);
 
-	memmove(skb->data - ETH_HLEN,
-		skb->data - ETH_HLEN - MTK_HDR_LEN,
-		2 * ETH_ALEN);
+	dsa_strip_etype_header(skb, MTK_HDR_LEN);
 
 	/* Get source port information */
 	port = (hdr & MTK_HDR_RECV_SOURCE_PORT_MASK);
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index 6e3136990491..f9fc881da591 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -72,8 +72,7 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
 
 	/* Remove QCA tag and recalculate checksum */
 	skb_pull_rcsum(skb, QCA_HDR_LEN);
-	memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - QCA_HDR_LEN,
-		ETH_HLEN - QCA_HDR_LEN);
+	dsa_strip_etype_header(skb, QCA_HDR_LEN);
 
 	/* Get source port information */
 	port = (hdr & QCA_HDR_RECV_SOURCE_PORT_MASK);
diff --git a/net/dsa/tag_rtl4_a.c b/net/dsa/tag_rtl4_a.c
index aaddca3c0245..ff8707ff0c5b 100644
--- a/net/dsa/tag_rtl4_a.c
+++ b/net/dsa/tag_rtl4_a.c
@@ -108,10 +108,7 @@ static struct sk_buff *rtl4a_tag_rcv(struct sk_buff *skb,
 	/* Remove RTL4 tag and recalculate checksum */
 	skb_pull_rcsum(skb, RTL4_A_HDR_LEN);
 
-	/* Move ethernet DA and SA in front of the data */
-	memmove(skb->data - ETH_HLEN,
-		skb->data - ETH_HLEN - RTL4_A_HDR_LEN,
-		2 * ETH_ALEN);
+	dsa_strip_etype_header(skb, RTL4_A_HDR_LEN);
 
 	dsa_default_offload_fwd_mark(skb);
 
diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
index fc4cde775e50..5e8234079d08 100644
--- a/net/dsa/tag_sja1105.c
+++ b/net/dsa/tag_sja1105.c
@@ -571,9 +571,7 @@ static struct sk_buff *sja1110_rcv_inband_control_extension(struct sk_buff *skb,
 	/* Advance skb->data past the DSA header */
 	skb_pull_rcsum(skb, SJA1110_HEADER_LEN);
 
-	/* Remove the DSA header */
-	memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - SJA1110_HEADER_LEN,
-		2 * ETH_ALEN);
+	dsa_strip_etype_header(skb, SJA1110_HEADER_LEN);
 
 	/* With skb->data in its final place, update the MAC header
 	 * so that eth_hdr() continues to works properly.
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [RFC PATCH net-next 2/4] net: dsa: create a helper which allocates space for EtherType DSA headers
  2021-08-09 11:57 [RFC PATCH net-next 0/4] DSA tagger helpers Vladimir Oltean
  2021-08-09 11:57 ` [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX Vladimir Oltean
@ 2021-08-09 11:57 ` Vladimir Oltean
  2021-08-10  1:03   ` Andrew Lunn
                     ` (2 more replies)
  2021-08-09 11:57 ` [RFC PATCH net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX Vladimir Oltean
  2021-08-09 11:57 ` [RFC PATCH net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX Vladimir Oltean
  3 siblings, 3 replies; 17+ messages in thread
From: Vladimir Oltean @ 2021-08-09 11:57 UTC (permalink / raw)
  To: netdev, Jakub Kicinski, David S. Miller
  Cc: Andrew Lunn, Florian Fainelli, Vivien Didelot, Vladimir Oltean,
	Linus Walleij, DENG Qingfang, John Crispin, Sean Wang,
	Landen Chao

Hide away the memmove used by DSA EtherType header taggers to shift the
MAC SA and DA to the left to make room for the header, after they've
called skb_push(). The call to skb_push() is still left explicit in
drivers, to be symmetric with dsa_strip_etype_header, and because not
all callers can be refactored to do it (for example, brcm_tag_xmit_ll
has common code for a pre-Ethernet DSA tag and an EtherType DSA tag).

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/dsa_priv.h    | 29 +++++++++++++++++++++++++++++
 net/dsa/tag_brcm.c    |  4 ++--
 net/dsa/tag_dsa.c     |  4 ++--
 net/dsa/tag_lan9303.c |  2 +-
 net/dsa/tag_mtk.c     |  2 +-
 net/dsa/tag_qca.c     |  2 +-
 net/dsa/tag_rtl4_a.c  |  2 +-
 net/dsa/tag_sja1105.c |  3 +--
 8 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 8a12ec1f9d21..28e1fbe64ee0 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -478,6 +478,35 @@ static inline void dsa_strip_etype_header(struct sk_buff *skb, int len)
 	memmove(skb->data - ETH_HLEN, skb->data - ETH_HLEN - len, 2 * ETH_ALEN);
 }
 
+/* Helper for creating space for DSA header tags in TX path packets.
+ * Must not be called before skb_push(len).
+ *
+ * Before:
+ *
+ *       <<<<<<<   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
+ * ^     <<<<<<<   +-----------------------+-----------------------+-------+
+ * |     <<<<<<<   |    Destination MAC    |      Source MAC       | EType |
+ * |               +-----------------------+-----------------------+-------+
+ * <----- len ----->
+ * |
+ * |
+ * skb->data
+ *
+ * After:
+ *
+ * |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |   |
+ * +-----------------------+-----------------------+---------------+-------+
+ * |    Destination MAC    |      Source MAC       |  DSA header   | EType |
+ * +-----------------------+-----------------------+---------------+-------+
+ * ^                                               |               |
+ * |                                               <----- len ----->
+ * skb->data
+ */
+static inline void dsa_alloc_etype_header(struct sk_buff *skb, int len)
+{
+	memmove(skb->data, skb->data + len, 2 * ETH_ALEN);
+}
+
 /* switch.c */
 int dsa_switch_register_notifier(struct dsa_switch *ds);
 void dsa_switch_unregister_notifier(struct dsa_switch *ds);
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index 2fc546b31ad8..c62a89bb8de3 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -99,7 +99,7 @@ static struct sk_buff *brcm_tag_xmit_ll(struct sk_buff *skb,
 	skb_push(skb, BRCM_TAG_LEN);
 
 	if (offset)
-		memmove(skb->data, skb->data + BRCM_TAG_LEN, offset);
+		dsa_alloc_etype_header(skb, BRCM_TAG_LEN);
 
 	brcm_tag = skb->data + offset;
 
@@ -228,7 +228,7 @@ static struct sk_buff *brcm_leg_tag_xmit(struct sk_buff *skb,
 
 	skb_push(skb, BRCM_LEG_TAG_LEN);
 
-	memmove(skb->data, skb->data + BRCM_LEG_TAG_LEN, 2 * ETH_ALEN);
+	dsa_alloc_etype_header(skb, BRCM_LEG_TAG_LEN);
 
 	brcm_tag = skb->data + 2 * ETH_ALEN;
 
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index ad9c841c998f..ab2c63859d12 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -166,7 +166,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
 	if (skb->protocol == htons(ETH_P_8021Q)) {
 		if (extra) {
 			skb_push(skb, extra);
-			memmove(skb->data, skb->data + extra, 2 * ETH_ALEN);
+			dsa_alloc_etype_header(skb, extra);
 		}
 
 		/* Construct tagged DSA tag from 802.1Q tag. */
@@ -181,7 +181,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
 		}
 	} else {
 		skb_push(skb, DSA_HLEN + extra);
-		memmove(skb->data, skb->data + DSA_HLEN + extra, 2 * ETH_ALEN);
+		dsa_alloc_etype_header(skb, DSA_HLEN + extra);
 
 		/* Construct untagged DSA tag. */
 		dsa_header = skb->data + 2 * ETH_ALEN + extra;
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index af13c0a9cb41..e8ad3727433e 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -62,7 +62,7 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
 	skb_push(skb, LAN9303_TAG_LEN);
 
 	/* make room between MACs and Ether-Type */
-	memmove(skb->data, skb->data + LAN9303_TAG_LEN, 2 * ETH_ALEN);
+	dsa_alloc_etype_header(skb, LAN9303_TAG_LEN);
 
 	lan9303_tag = (__be16 *)(skb->data + 2 * ETH_ALEN);
 	tag = lan9303_xmit_use_arl(dp, skb->data) ?
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index 6a78e9f146e5..06d1cfc6d19b 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -41,7 +41,7 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
 	default:
 		xmit_tpid = MTK_HDR_XMIT_UNTAGGED;
 		skb_push(skb, MTK_HDR_LEN);
-		memmove(skb->data, skb->data + MTK_HDR_LEN, 2 * ETH_ALEN);
+		dsa_alloc_etype_header(skb, MTK_HDR_LEN);
 	}
 
 	mtk_tag = skb->data + 2 * ETH_ALEN;
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index f9fc881da591..c68a814188e7 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -36,7 +36,7 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	skb_push(skb, QCA_HDR_LEN);
 
-	memmove(skb->data, skb->data + QCA_HDR_LEN, 2 * ETH_ALEN);
+	dsa_alloc_etype_header(skb, QCA_HDR_LEN);
 	phdr = (__be16 *)(skb->data + 2 * ETH_ALEN);
 
 	/* Set the version field, and set destination port information */
diff --git a/net/dsa/tag_rtl4_a.c b/net/dsa/tag_rtl4_a.c
index ff8707ff0c5b..06e901eda298 100644
--- a/net/dsa/tag_rtl4_a.c
+++ b/net/dsa/tag_rtl4_a.c
@@ -47,7 +47,7 @@ static struct sk_buff *rtl4a_tag_xmit(struct sk_buff *skb,
 		   dp->index);
 	skb_push(skb, RTL4_A_HDR_LEN);
 
-	memmove(skb->data, skb->data + RTL4_A_HDR_LEN, 2 * ETH_ALEN);
+	dsa_alloc_etype_header(skb, RTL4_A_HDR_LEN);
 	tag = skb->data + 2 * ETH_ALEN;
 
 	/* Set Ethertype */
diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
index 5e8234079d08..939161822f31 100644
--- a/net/dsa/tag_sja1105.c
+++ b/net/dsa/tag_sja1105.c
@@ -245,8 +245,7 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
 
 	skb_push(skb, SJA1110_HEADER_LEN);
 
-	/* Move Ethernet header to the left, making space for DSA tag */
-	memmove(skb->data, skb->data + SJA1110_HEADER_LEN, 2 * ETH_ALEN);
+	dsa_alloc_etype_header(skb, SJA1110_HEADER_LEN);
 
 	trailer_pos = skb->len;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [RFC PATCH net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX
  2021-08-09 11:57 [RFC PATCH net-next 0/4] DSA tagger helpers Vladimir Oltean
  2021-08-09 11:57 ` [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX Vladimir Oltean
  2021-08-09 11:57 ` [RFC PATCH net-next 2/4] net: dsa: create a helper which allocates space for EtherType DSA headers Vladimir Oltean
@ 2021-08-09 11:57 ` Vladimir Oltean
  2021-08-10  1:05   ` Andrew Lunn
                     ` (2 more replies)
  2021-08-09 11:57 ` [RFC PATCH net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX Vladimir Oltean
  3 siblings, 3 replies; 17+ messages in thread
From: Vladimir Oltean @ 2021-08-09 11:57 UTC (permalink / raw)
  To: netdev, Jakub Kicinski, David S. Miller
  Cc: Andrew Lunn, Florian Fainelli, Vivien Didelot, Vladimir Oltean,
	Linus Walleij, DENG Qingfang, John Crispin, Sean Wang,
	Landen Chao

It seems that protocol tagging driver writers are always surprised about
the formula they use to reach their EtherType header on RX, which
becomes apparent from the fact that there are comments in multiple
drivers that mention the same information.

Create a helper that returns a void pointer to skb->data - 2, as well as
centralize the explanation why that is the case.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/dsa_priv.h    | 14 ++++++++++++++
 net/dsa/tag_brcm.c    |  2 +-
 net/dsa/tag_dsa.c     |  2 +-
 net/dsa/tag_lan9303.c |  8 +-------
 net/dsa/tag_mtk.c     |  6 +-----
 net/dsa/tag_qca.c     |  6 +-----
 net/dsa/tag_rtl4_a.c  |  7 +------
 net/dsa/tag_sja1105.c |  2 +-
 8 files changed, 21 insertions(+), 26 deletions(-)

diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 28e1fbe64ee0..ee194df68902 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -507,6 +507,20 @@ static inline void dsa_alloc_etype_header(struct sk_buff *skb, int len)
 	memmove(skb->data, skb->data + len, 2 * ETH_ALEN);
 }
 
+/* On RX, eth_type_trans() on the DSA master pulls ETH_HLEN bytes starting from
+ * skb_mac_header(skb), which leaves skb->data pointing at the first byte after
+ * what the DSA master perceives as the EtherType (the beginning of the L3
+ * protocol). Since DSA EtherType header taggers treat the EtherType as part of
+ * the DSA tag itself, and the EtherType is 2 bytes in length, the DSA header
+ * is located 2 bytes behind skb->data. Note that EtherType in this context
+ * means the first 2 bytes of the DSA header, not the encapsulated EtherType
+ * that will become visible after the DSA header is stripped.
+ */
+static inline void *dsa_etype_header_pos_rx(struct sk_buff *skb)
+{
+	return skb->data - 2;
+}
+
 /* switch.c */
 int dsa_switch_register_notifier(struct dsa_switch *ds);
 void dsa_switch_unregister_notifier(struct dsa_switch *ds);
diff --git a/net/dsa/tag_brcm.c b/net/dsa/tag_brcm.c
index c62a89bb8de3..96dbb8ee2fee 100644
--- a/net/dsa/tag_brcm.c
+++ b/net/dsa/tag_brcm.c
@@ -254,7 +254,7 @@ static struct sk_buff *brcm_leg_tag_rcv(struct sk_buff *skb,
 	if (unlikely(!pskb_may_pull(skb, BRCM_LEG_PORT_ID)))
 		return NULL;
 
-	brcm_tag = skb->data - 2;
+	brcm_tag = dsa_etype_header_pos_rx(skb);
 
 	source_port = brcm_tag[5] & BRCM_LEG_PORT_ID;
 
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index ab2c63859d12..2eeabab27078 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -205,7 +205,7 @@ static struct sk_buff *dsa_rcv_ll(struct sk_buff *skb, struct net_device *dev,
 	u8 *dsa_header;
 
 	/* The ethertype field is part of the DSA header. */
-	dsa_header = skb->data - 2;
+	dsa_header = dsa_etype_header_pos_rx(skb);
 
 	cmd = dsa_header[0] >> 6;
 	switch (cmd) {
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index e8ad3727433e..d06951273127 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -86,13 +86,7 @@ static struct sk_buff *lan9303_rcv(struct sk_buff *skb, struct net_device *dev)
 		return NULL;
 	}
 
-	/* '->data' points into the middle of our special VLAN tag information:
-	 *
-	 * ~ MAC src   | 0x81 | 0x00 | 0xyy | 0xzz | ether type
-	 *                           ^
-	 *                        ->data
-	 */
-	lan9303_tag = (__be16 *)(skb->data - 2);
+	lan9303_tag = dsa_etype_header_pos_rx(skb);
 
 	if (lan9303_tag[0] != htons(ETH_P_8021Q)) {
 		dev_warn_ratelimited(&dev->dev, "Dropping packet due to invalid VLAN marker\n");
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index 06d1cfc6d19b..a75f99e5fbe3 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -70,11 +70,7 @@ static struct sk_buff *mtk_tag_rcv(struct sk_buff *skb, struct net_device *dev)
 	if (unlikely(!pskb_may_pull(skb, MTK_HDR_LEN)))
 		return NULL;
 
-	/* The MTK header is added by the switch between src addr
-	 * and ethertype at this point, skb->data points to 2 bytes
-	 * after src addr so header should be 2 bytes right before.
-	 */
-	phdr = (__be16 *)(skb->data - 2);
+	phdr = dsa_etype_header_pos_rx(skb);
 	hdr = ntohs(*phdr);
 
 	/* Remove MTK tag and recalculate checksum. */
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index c68a814188e7..79a81569d7ec 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -58,11 +58,7 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev)
 	if (unlikely(!pskb_may_pull(skb, QCA_HDR_LEN)))
 		return NULL;
 
-	/* The QCA header is added by the switch between src addr and Ethertype
-	 * At this point, skb->data points to ethertype so header should be
-	 * right before
-	 */
-	phdr = (__be16 *)(skb->data - 2);
+	phdr = dsa_etype_header_pos_rx(skb);
 	hdr = ntohs(*phdr);
 
 	/* Make sure the version is correct */
diff --git a/net/dsa/tag_rtl4_a.c b/net/dsa/tag_rtl4_a.c
index 06e901eda298..947247d2124e 100644
--- a/net/dsa/tag_rtl4_a.c
+++ b/net/dsa/tag_rtl4_a.c
@@ -76,12 +76,7 @@ static struct sk_buff *rtl4a_tag_rcv(struct sk_buff *skb,
 	if (unlikely(!pskb_may_pull(skb, RTL4_A_HDR_LEN)))
 		return NULL;
 
-	/* The RTL4 header has its own custom Ethertype 0x8899 and that
-	 * starts right at the beginning of the packet, after the src
-	 * ethernet addr. Apparently skb->data always points 2 bytes in,
-	 * behind the Ethertype.
-	 */
-	tag = skb->data - 2;
+	tag = dsa_etype_header_pos_rx(skb);
 	p = (__be16 *)tag;
 	etype = ntohs(*p);
 	if (etype != RTL4_A_ETHERTYPE) {
diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
index 939161822f31..34f3212a6703 100644
--- a/net/dsa/tag_sja1105.c
+++ b/net/dsa/tag_sja1105.c
@@ -481,11 +481,11 @@ static struct sk_buff *sja1105_rcv(struct sk_buff *skb,
 
 static struct sk_buff *sja1110_rcv_meta(struct sk_buff *skb, u16 rx_header)
 {
+	u8 *buf = dsa_etype_header_pos_rx(skb) + SJA1110_HEADER_LEN;
 	int switch_id = SJA1110_RX_HEADER_SWITCH_ID(rx_header);
 	int n_ts = SJA1110_RX_HEADER_N_TS(rx_header);
 	struct net_device *master = skb->dev;
 	struct dsa_port *cpu_dp;
-	u8 *buf = skb->data + 2;
 	struct dsa_switch *ds;
 	int i;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* [RFC PATCH net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX
  2021-08-09 11:57 [RFC PATCH net-next 0/4] DSA tagger helpers Vladimir Oltean
                   ` (2 preceding siblings ...)
  2021-08-09 11:57 ` [RFC PATCH net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX Vladimir Oltean
@ 2021-08-09 11:57 ` Vladimir Oltean
  2021-08-10  1:07   ` Andrew Lunn
                     ` (2 more replies)
  3 siblings, 3 replies; 17+ messages in thread
From: Vladimir Oltean @ 2021-08-09 11:57 UTC (permalink / raw)
  To: netdev, Jakub Kicinski, David S. Miller
  Cc: Andrew Lunn, Florian Fainelli, Vivien Didelot, Vladimir Oltean,
	Linus Walleij, DENG Qingfang, John Crispin, Sean Wang,
	Landen Chao

Create a similar helper for locating the offset to the DSA header
relative to skb->data, and make the existing EtherType header taggers to
use it.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
 net/dsa/dsa_priv.h    |  9 +++++++++
 net/dsa/tag_dsa.c     |  6 +++---
 net/dsa/tag_lan9303.c |  3 ++-
 net/dsa/tag_mtk.c     |  2 +-
 net/dsa/tag_qca.c     |  2 +-
 net/dsa/tag_rtl4_a.c  |  2 +-
 net/dsa/tag_sja1105.c | 16 ++++++----------
 7 files changed, 23 insertions(+), 17 deletions(-)

diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index ee194df68902..9ea637832ea9 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -521,6 +521,15 @@ static inline void *dsa_etype_header_pos_rx(struct sk_buff *skb)
 	return skb->data - 2;
 }
 
+/* On TX, skb->data points to skb_mac_header(skb), which means that EtherType
+ * header taggers start exactly where the EtherType is (the EtherType is
+ * treated as part of the DSA header).
+ */
+static inline void *dsa_etype_header_pos_tx(struct sk_buff *skb)
+{
+	return skb->data + 2 * ETH_ALEN;
+}
+
 /* switch.c */
 int dsa_switch_register_notifier(struct dsa_switch *ds);
 void dsa_switch_unregister_notifier(struct dsa_switch *ds);
diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c
index 2eeabab27078..77d0ce89ab77 100644
--- a/net/dsa/tag_dsa.c
+++ b/net/dsa/tag_dsa.c
@@ -170,7 +170,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
 		}
 
 		/* Construct tagged DSA tag from 802.1Q tag. */
-		dsa_header = skb->data + 2 * ETH_ALEN + extra;
+		dsa_header = dsa_etype_header_pos_tx(skb) + extra;
 		dsa_header[0] = (cmd << 6) | 0x20 | tag_dev;
 		dsa_header[1] = tag_port << 3;
 
@@ -184,7 +184,7 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev,
 		dsa_alloc_etype_header(skb, DSA_HLEN + extra);
 
 		/* Construct untagged DSA tag. */
-		dsa_header = skb->data + 2 * ETH_ALEN + extra;
+		dsa_header = dsa_etype_header_pos_tx(skb) + extra;
 
 		dsa_header[0] = (cmd << 6) | tag_dev;
 		dsa_header[1] = tag_port << 3;
@@ -360,7 +360,7 @@ static struct sk_buff *edsa_xmit(struct sk_buff *skb, struct net_device *dev)
 	if (!skb)
 		return NULL;
 
-	edsa_header = skb->data + 2 * ETH_ALEN;
+	edsa_header = dsa_etype_header_pos_tx(skb);
 	edsa_header[0] = (ETH_P_EDSA >> 8) & 0xff;
 	edsa_header[1] = ETH_P_EDSA & 0xff;
 	edsa_header[2] = 0x00;
diff --git a/net/dsa/tag_lan9303.c b/net/dsa/tag_lan9303.c
index d06951273127..cb548188f813 100644
--- a/net/dsa/tag_lan9303.c
+++ b/net/dsa/tag_lan9303.c
@@ -64,7 +64,8 @@ static struct sk_buff *lan9303_xmit(struct sk_buff *skb, struct net_device *dev)
 	/* make room between MACs and Ether-Type */
 	dsa_alloc_etype_header(skb, LAN9303_TAG_LEN);
 
-	lan9303_tag = (__be16 *)(skb->data + 2 * ETH_ALEN);
+	lan9303_tag = dsa_etype_header_pos_tx(skb);
+
 	tag = lan9303_xmit_use_arl(dp, skb->data) ?
 		LAN9303_TAG_TX_USE_ALR :
 		dp->index | LAN9303_TAG_TX_STP_OVERRIDE;
diff --git a/net/dsa/tag_mtk.c b/net/dsa/tag_mtk.c
index a75f99e5fbe3..415d8ece242a 100644
--- a/net/dsa/tag_mtk.c
+++ b/net/dsa/tag_mtk.c
@@ -44,7 +44,7 @@ static struct sk_buff *mtk_tag_xmit(struct sk_buff *skb,
 		dsa_alloc_etype_header(skb, MTK_HDR_LEN);
 	}
 
-	mtk_tag = skb->data + 2 * ETH_ALEN;
+	mtk_tag = dsa_etype_header_pos_tx(skb);
 
 	/* Mark tag attribute on special tag insertion to notify hardware
 	 * whether that's a combined special tag with 802.1Q header.
diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index 79a81569d7ec..1ea9401b8ace 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -37,7 +37,7 @@ static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
 	skb_push(skb, QCA_HDR_LEN);
 
 	dsa_alloc_etype_header(skb, QCA_HDR_LEN);
-	phdr = (__be16 *)(skb->data + 2 * ETH_ALEN);
+	phdr = dsa_etype_header_pos_tx(skb);
 
 	/* Set the version field, and set destination port information */
 	hdr = QCA_HDR_VERSION << QCA_HDR_XMIT_VERSION_S |
diff --git a/net/dsa/tag_rtl4_a.c b/net/dsa/tag_rtl4_a.c
index 947247d2124e..40811bab4d09 100644
--- a/net/dsa/tag_rtl4_a.c
+++ b/net/dsa/tag_rtl4_a.c
@@ -48,7 +48,7 @@ static struct sk_buff *rtl4a_tag_xmit(struct sk_buff *skb,
 	skb_push(skb, RTL4_A_HDR_LEN);
 
 	dsa_alloc_etype_header(skb, RTL4_A_HDR_LEN);
-	tag = skb->data + 2 * ETH_ALEN;
+	tag = dsa_etype_header_pos_tx(skb);
 
 	/* Set Ethertype */
 	p = (__be16 *)tag;
diff --git a/net/dsa/tag_sja1105.c b/net/dsa/tag_sja1105.c
index 34f3212a6703..0ed379a28ab6 100644
--- a/net/dsa/tag_sja1105.c
+++ b/net/dsa/tag_sja1105.c
@@ -223,7 +223,6 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
 	u16 tx_vid = dsa_8021q_tx_vid(dp->ds, dp->index);
 	u16 queue_mapping = skb_get_queue_mapping(skb);
 	u8 pcp = netdev_txq_to_tc(netdev, queue_mapping);
-	struct ethhdr *eth_hdr;
 	__be32 *tx_trailer;
 	__be16 *tx_header;
 	int trailer_pos;
@@ -249,23 +248,20 @@ static struct sk_buff *sja1110_xmit(struct sk_buff *skb,
 
 	trailer_pos = skb->len;
 
-	/* On TX, skb->data points to skb_mac_header(skb) */
-	eth_hdr = (struct ethhdr *)skb->data;
-	tx_header = (__be16 *)(eth_hdr + 1);
+	tx_header = dsa_etype_header_pos_tx(skb);
 	tx_trailer = skb_put(skb, SJA1110_TX_TRAILER_LEN);
 
-	eth_hdr->h_proto = htons(ETH_P_SJA1110);
-
-	*tx_header = htons(SJA1110_HEADER_HOST_TO_SWITCH |
-			   SJA1110_TX_HEADER_HAS_TRAILER |
-			   SJA1110_TX_HEADER_TRAILER_POS(trailer_pos));
+	tx_header[0] = htons(ETH_P_SJA1110);
+	tx_header[1] = htons(SJA1110_HEADER_HOST_TO_SWITCH |
+			     SJA1110_TX_HEADER_HAS_TRAILER |
+			     SJA1110_TX_HEADER_TRAILER_POS(trailer_pos));
 	*tx_trailer = cpu_to_be32(SJA1110_TX_TRAILER_PRIO(pcp) |
 				  SJA1110_TX_TRAILER_SWITCHID(dp->ds->index) |
 				  SJA1110_TX_TRAILER_DESTPORTS(BIT(dp->index)));
 	if (clone) {
 		u8 ts_id = SJA1105_SKB_CB(clone)->ts_id;
 
-		*tx_header |= htons(SJA1110_TX_HEADER_TAKE_TS);
+		tx_header[1] |= htons(SJA1110_TX_HEADER_TAKE_TS);
 		*tx_trailer |= cpu_to_be32(SJA1110_TX_TRAILER_TSTAMP_ID(ts_id));
 	}
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX
  2021-08-09 11:57 ` [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX Vladimir Oltean
@ 2021-08-10  1:01   ` Andrew Lunn
  2021-08-10  9:18   ` Florian Fainelli
  2021-08-11 13:23   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Andrew Lunn @ 2021-08-10  1:01 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, Jakub Kicinski, David S. Miller, Florian Fainelli,
	Vivien Didelot, Vladimir Oltean, Linus Walleij, DENG Qingfang,
	John Crispin, Sean Wang, Landen Chao

On Mon, Aug 09, 2021 at 02:57:19PM +0300, Vladimir Oltean wrote:
> All header taggers open-code a memmove that is fairly not all that
> obvious, and we can hide the details behind a helper function, since the
> only thing specific to the driver is the length of the header tag.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 2/4] net: dsa: create a helper which allocates space for EtherType DSA headers
  2021-08-09 11:57 ` [RFC PATCH net-next 2/4] net: dsa: create a helper which allocates space for EtherType DSA headers Vladimir Oltean
@ 2021-08-10  1:03   ` Andrew Lunn
  2021-08-10  9:21   ` Florian Fainelli
  2021-08-11 13:24   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Andrew Lunn @ 2021-08-10  1:03 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, Jakub Kicinski, David S. Miller, Florian Fainelli,
	Vivien Didelot, Vladimir Oltean, Linus Walleij, DENG Qingfang,
	John Crispin, Sean Wang, Landen Chao

On Mon, Aug 09, 2021 at 02:57:20PM +0300, Vladimir Oltean wrote:
> Hide away the memmove used by DSA EtherType header taggers to shift the
> MAC SA and DA to the left to make room for the header, after they've
> called skb_push(). The call to skb_push() is still left explicit in
> drivers, to be symmetric with dsa_strip_etype_header, and because not
> all callers can be refactored to do it (for example, brcm_tag_xmit_ll
> has common code for a pre-Ethernet DSA tag and an EtherType DSA tag).
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX
  2021-08-09 11:57 ` [RFC PATCH net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX Vladimir Oltean
@ 2021-08-10  1:05   ` Andrew Lunn
  2021-08-10  9:21   ` Florian Fainelli
  2021-08-11 13:27   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Andrew Lunn @ 2021-08-10  1:05 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, Jakub Kicinski, David S. Miller, Florian Fainelli,
	Vivien Didelot, Vladimir Oltean, Linus Walleij, DENG Qingfang,
	John Crispin, Sean Wang, Landen Chao

On Mon, Aug 09, 2021 at 02:57:21PM +0300, Vladimir Oltean wrote:
> It seems that protocol tagging driver writers are always surprised about
> the formula they use to reach their EtherType header on RX, which
> becomes apparent from the fact that there are comments in multiple
> drivers that mention the same information.
> 
> Create a helper that returns a void pointer to skb->data - 2, as well as
> centralize the explanation why that is the case.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX
  2021-08-09 11:57 ` [RFC PATCH net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX Vladimir Oltean
@ 2021-08-10  1:07   ` Andrew Lunn
  2021-08-10  9:22   ` Florian Fainelli
  2021-08-11 13:28   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Andrew Lunn @ 2021-08-10  1:07 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, Jakub Kicinski, David S. Miller, Florian Fainelli,
	Vivien Didelot, Vladimir Oltean, Linus Walleij, DENG Qingfang,
	John Crispin, Sean Wang, Landen Chao

On Mon, Aug 09, 2021 at 02:57:22PM +0300, Vladimir Oltean wrote:
> Create a similar helper for locating the offset to the DSA header
> relative to skb->data, and make the existing EtherType header taggers to
> use it.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX
  2021-08-09 11:57 ` [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX Vladimir Oltean
  2021-08-10  1:01   ` Andrew Lunn
@ 2021-08-10  9:18   ` Florian Fainelli
  2021-08-11 13:23   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Florian Fainelli @ 2021-08-10  9:18 UTC (permalink / raw)
  To: Vladimir Oltean, netdev, Jakub Kicinski, David S. Miller
  Cc: Andrew Lunn, Vivien Didelot, Vladimir Oltean, Linus Walleij,
	DENG Qingfang, John Crispin, Sean Wang, Landen Chao



On 8/9/2021 4:57 AM, Vladimir Oltean wrote:
> All header taggers open-code a memmove that is fairly not all that
> obvious, and we can hide the details behind a helper function, since the
> only thing specific to the driver is the length of the header tag.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 2/4] net: dsa: create a helper which allocates space for EtherType DSA headers
  2021-08-09 11:57 ` [RFC PATCH net-next 2/4] net: dsa: create a helper which allocates space for EtherType DSA headers Vladimir Oltean
  2021-08-10  1:03   ` Andrew Lunn
@ 2021-08-10  9:21   ` Florian Fainelli
  2021-08-11 13:24   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Florian Fainelli @ 2021-08-10  9:21 UTC (permalink / raw)
  To: Vladimir Oltean, netdev, Jakub Kicinski, David S. Miller
  Cc: Andrew Lunn, Vivien Didelot, Vladimir Oltean, Linus Walleij,
	DENG Qingfang, John Crispin, Sean Wang, Landen Chao



On 8/9/2021 4:57 AM, Vladimir Oltean wrote:
> Hide away the memmove used by DSA EtherType header taggers to shift the
> MAC SA and DA to the left to make room for the header, after they've
> called skb_push(). The call to skb_push() is still left explicit in
> drivers, to be symmetric with dsa_strip_etype_header, and because not
> all callers can be refactored to do it (for example, brcm_tag_xmit_ll
> has common code for a pre-Ethernet DSA tag and an EtherType DSA tag).
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX
  2021-08-09 11:57 ` [RFC PATCH net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX Vladimir Oltean
  2021-08-10  1:05   ` Andrew Lunn
@ 2021-08-10  9:21   ` Florian Fainelli
  2021-08-11 13:27   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Florian Fainelli @ 2021-08-10  9:21 UTC (permalink / raw)
  To: Vladimir Oltean, netdev, Jakub Kicinski, David S. Miller
  Cc: Andrew Lunn, Vivien Didelot, Vladimir Oltean, Linus Walleij,
	DENG Qingfang, John Crispin, Sean Wang, Landen Chao



On 8/9/2021 4:57 AM, Vladimir Oltean wrote:
> It seems that protocol tagging driver writers are always surprised about
> the formula they use to reach their EtherType header on RX, which
> becomes apparent from the fact that there are comments in multiple
> drivers that mention the same information.
> 
> Create a helper that returns a void pointer to skb->data - 2, as well as
> centralize the explanation why that is the case.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX
  2021-08-09 11:57 ` [RFC PATCH net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX Vladimir Oltean
  2021-08-10  1:07   ` Andrew Lunn
@ 2021-08-10  9:22   ` Florian Fainelli
  2021-08-11 13:28   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Florian Fainelli @ 2021-08-10  9:22 UTC (permalink / raw)
  To: Vladimir Oltean, netdev, Jakub Kicinski, David S. Miller
  Cc: Andrew Lunn, Vivien Didelot, Vladimir Oltean, Linus Walleij,
	DENG Qingfang, John Crispin, Sean Wang, Landen Chao



On 8/9/2021 4:57 AM, Vladimir Oltean wrote:
> Create a similar helper for locating the offset to the DSA header
> relative to skb->data, and make the existing EtherType header taggers to
> use it.
> 
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
-- 
Florian

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX
  2021-08-09 11:57 ` [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX Vladimir Oltean
  2021-08-10  1:01   ` Andrew Lunn
  2021-08-10  9:18   ` Florian Fainelli
@ 2021-08-11 13:23   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Linus Walleij @ 2021-08-11 13:23 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, Jakub Kicinski, David S. Miller, Andrew Lunn,
	Florian Fainelli, Vivien Didelot, Vladimir Oltean, DENG Qingfang,
	John Crispin, Sean Wang, Landen Chao

On Mon, Aug 9, 2021 at 1:57 PM Vladimir Oltean <vladimir.oltean@nxp.com> wrote:

> All header taggers open-code a memmove that is fairly not all that
> obvious, and we can hide the details behind a helper function, since the
> only thing specific to the driver is the length of the header tag.
>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 2/4] net: dsa: create a helper which allocates space for EtherType DSA headers
  2021-08-09 11:57 ` [RFC PATCH net-next 2/4] net: dsa: create a helper which allocates space for EtherType DSA headers Vladimir Oltean
  2021-08-10  1:03   ` Andrew Lunn
  2021-08-10  9:21   ` Florian Fainelli
@ 2021-08-11 13:24   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Linus Walleij @ 2021-08-11 13:24 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, Jakub Kicinski, David S. Miller, Andrew Lunn,
	Florian Fainelli, Vivien Didelot, Vladimir Oltean, DENG Qingfang,
	John Crispin, Sean Wang, Landen Chao

On Mon, Aug 9, 2021 at 1:57 PM Vladimir Oltean <vladimir.oltean@nxp.com> wrote:

> Hide away the memmove used by DSA EtherType header taggers to shift the
> MAC SA and DA to the left to make room for the header, after they've
> called skb_push(). The call to skb_push() is still left explicit in
> drivers, to be symmetric with dsa_strip_etype_header, and because not
> all callers can be refactored to do it (for example, brcm_tag_xmit_ll
> has common code for a pre-Ethernet DSA tag and an EtherType DSA tag).
>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX
  2021-08-09 11:57 ` [RFC PATCH net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX Vladimir Oltean
  2021-08-10  1:05   ` Andrew Lunn
  2021-08-10  9:21   ` Florian Fainelli
@ 2021-08-11 13:27   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Linus Walleij @ 2021-08-11 13:27 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, Jakub Kicinski, David S. Miller, Andrew Lunn,
	Florian Fainelli, Vivien Didelot, Vladimir Oltean, DENG Qingfang,
	John Crispin, Sean Wang, Landen Chao

On Mon, Aug 9, 2021 at 1:57 PM Vladimir Oltean <vladimir.oltean@nxp.com> wrote:

> It seems that protocol tagging driver writers are always surprised about
> the formula they use to reach their EtherType header on RX, which
> becomes apparent from the fact that there are comments in multiple
> drivers that mention the same information.
>
> Create a helper that returns a void pointer to skb->data - 2, as well as
> centralize the explanation why that is the case.
>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [RFC PATCH net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX
  2021-08-09 11:57 ` [RFC PATCH net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX Vladimir Oltean
  2021-08-10  1:07   ` Andrew Lunn
  2021-08-10  9:22   ` Florian Fainelli
@ 2021-08-11 13:28   ` Linus Walleij
  2 siblings, 0 replies; 17+ messages in thread
From: Linus Walleij @ 2021-08-11 13:28 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, Jakub Kicinski, David S. Miller, Andrew Lunn,
	Florian Fainelli, Vivien Didelot, Vladimir Oltean, DENG Qingfang,
	John Crispin, Sean Wang, Landen Chao

On Mon, Aug 9, 2021 at 1:57 PM Vladimir Oltean <vladimir.oltean@nxp.com> wrote:

> Create a similar helper for locating the offset to the DSA header
> relative to skb->data, and make the existing EtherType header taggers to
> use it.
>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>

Yours,
Linus Walleij

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2021-08-11 13:28 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-09 11:57 [RFC PATCH net-next 0/4] DSA tagger helpers Vladimir Oltean
2021-08-09 11:57 ` [RFC PATCH net-next 1/4] net: dsa: create a helper that strips EtherType DSA headers on RX Vladimir Oltean
2021-08-10  1:01   ` Andrew Lunn
2021-08-10  9:18   ` Florian Fainelli
2021-08-11 13:23   ` Linus Walleij
2021-08-09 11:57 ` [RFC PATCH net-next 2/4] net: dsa: create a helper which allocates space for EtherType DSA headers Vladimir Oltean
2021-08-10  1:03   ` Andrew Lunn
2021-08-10  9:21   ` Florian Fainelli
2021-08-11 13:24   ` Linus Walleij
2021-08-09 11:57 ` [RFC PATCH net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX Vladimir Oltean
2021-08-10  1:05   ` Andrew Lunn
2021-08-10  9:21   ` Florian Fainelli
2021-08-11 13:27   ` Linus Walleij
2021-08-09 11:57 ` [RFC PATCH net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX Vladimir Oltean
2021-08-10  1:07   ` Andrew Lunn
2021-08-10  9:22   ` Florian Fainelli
2021-08-11 13:28   ` Linus Walleij

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).