linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Alexander Lobakin <alobakin@dlink.ru>
To: "David S. Miller" <davem@davemloft.net>
Cc: Andrew Lunn <andrew@lunn.ch>, Song Liu <songliubraving@fb.com>,
	Jakub Kicinski <jakub.kicinski@netronome.com>,
	Alexander Lobakin <alobakin@dlink.ru>,
	Yoshiki Komachi <komachi.yoshiki@gmail.com>,
	linux-kernel@vger.kernel.org, Eric Dumazet <edumazet@google.com>,
	Stanislav Fomichev <sdf@google.com>,
	Matteo Croce <mcroce@redhat.com>,
	Edward Cree <ecree@solarflare.com>,
	Florian Fainelli <f.fainelli@gmail.com>,
	Jakub Sitnicki <jakub@cloudflare.com>,
	Daniel Borkmann <daniel@iogearbox.net>,
	Paolo Abeni <pabeni@redhat.com>,
	Vivien Didelot <vivien.didelot@gmail.com>,
	Hauke Mehrtens <hauke@hauke-m.de>,
	Sean Wang <sean.wang@mediatek.com>,
	Jiri Pirko <jiri@mellanox.com>,
	linux-mediatek@lists.infradead.org,
	Matthias Brugger <matthias.bgg@gmail.com>,
	linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org,
	Paul Blakey <paulb@mellanox.com>,
	Stephen Hemminger <stephen@networkplumber.org>,
	Taehee Yoo <ap420073@gmail.com>
Subject: [PATCH RFC net-next 18/19] net: dsa: tag_qca: split out common tag accessors
Date: Mon, 30 Dec 2019 17:30:26 +0300	[thread overview]
Message-ID: <20191230143028.27313-19-alobakin@dlink.ru> (raw)
In-Reply-To: <20191230143028.27313-1-alobakin@dlink.ru>

...to make them available for the upcoming GRO callbacks.

Signed-off-by: Alexander Lobakin <alobakin@dlink.ru>
---
 net/dsa/tag_qca.c | 45 +++++++++++++++++++++++++++++----------------
 1 file changed, 29 insertions(+), 16 deletions(-)

diff --git a/net/dsa/tag_qca.c b/net/dsa/tag_qca.c
index 8939abce36d7..bee2788e034d 100644
--- a/net/dsa/tag_qca.c
+++ b/net/dsa/tag_qca.c
@@ -28,6 +28,27 @@
 #define QCA_HDR_XMIT_FROM_CPU		BIT(7)
 #define QCA_HDR_XMIT_DP(port)		FIELD_PREP(GENMASK(6, 0), BIT(port))
 
+static inline bool qca_tag_sanity_check(const u8 *data)
+{
+	/* 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
+	 */
+	u16 hdr = ntohs(*(__be16 *)(data - 2));
+
+	return QCA_HDR_RECV_VERSION(hdr) == QCA_HDR_VERSION;
+}
+
+static inline int qca_tag_source_port(const u8 *data)
+{
+	return *(data - 1) & QCA_HDR_RECV_SOURCE_PORT_MASK;
+}
+
+static inline __be16 qca_tag_encap_proto(const u8 *data)
+{
+	return *(__be16 *)data;
+}
+
 static struct sk_buff *qca_tag_xmit(struct sk_buff *skb, struct net_device *dev)
 {
 	const struct dsa_port *dp = dsa_slave_to_port(dev);
@@ -55,34 +76,26 @@ static struct sk_buff *qca_tag_rcv(struct sk_buff *skb, struct net_device *dev,
 				   struct packet_type *pt)
 {
 	int port;
-	__be16 *phdr, hdr;
 
 	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);
-	hdr = ntohs(*phdr);
-
 	/* Make sure the version is correct */
-	if (unlikely(QCA_HDR_RECV_VERSION(hdr) != QCA_HDR_VERSION))
+	if (unlikely(!qca_tag_sanity_check(skb->data)))
 		return NULL;
 
-	/* 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);
-
 	/* Get source port information */
-	port = (hdr & QCA_HDR_RECV_SOURCE_PORT_MASK);
+	port = qca_tag_source_port(skb->data);
 
 	skb->dev = dsa_master_find_slave(dev, 0, port);
 	if (!skb->dev)
 		return NULL;
 
+	/* 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);
+
 	return skb;
 }
 
@@ -90,7 +103,7 @@ static void qca_tag_flow_dissect(const struct sk_buff *skb, __be16 *proto,
 				 int *offset)
 {
 	*offset = QCA_HDR_LEN;
-	*proto = ((__be16 *)skb->data)[0];
+	*proto = qca_tag_encap_proto(skb->data);
 }
 
 static const struct dsa_device_ops qca_netdev_ops = {
-- 
2.24.1


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  parent reply	other threads:[~2019-12-30 14:42 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-12-30 14:30 [PATCH RFC net-next 00/20] net: dsa: add GRO support Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 01/19] net: dsa: make .flow_dissect() callback returning void Alexander Lobakin
2019-12-30 18:11   ` Florian Fainelli
2019-12-30 14:30 ` [PATCH RFC net-next 02/19] net: dsa: add GRO support infrastructure Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 03/19] net: dsa: tag_ar9331: add .flow_dissect() callback Alexander Lobakin
2019-12-30 18:22   ` Florian Fainelli
2019-12-30 14:30 ` [PATCH RFC net-next 04/19] net: dsa: tag_ar9331: split out common tag accessors Alexander Lobakin
2019-12-30 17:18   ` Andrew Lunn
2019-12-30 14:30 ` [PATCH RFC net-next 05/19] net: dsa: tag_ar9331: add GRO callbacks Alexander Lobakin
2019-12-30 18:20   ` Florian Fainelli
2019-12-30 20:36     ` Andrew Lunn
2020-01-13  9:21     ` Alexander Lobakin
2020-01-13  9:42       ` Vladimir Oltean
2020-01-13  9:46         ` Alexander Lobakin
2020-01-13 10:28           ` Vladimir Oltean
2020-01-14 21:56             ` Florian Fainelli
2020-01-15  7:38               ` Alexander Lobakin
2020-01-15 11:29                 ` Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 06/19] net: dsa: tag_gswip: fix typo in tag name Alexander Lobakin
2019-12-30 17:22   ` Andrew Lunn
2020-01-14 21:57     ` Florian Fainelli
2020-01-15  7:24       ` Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 07/19] net: dsa: tag_gswip: switch to bitfield helpers Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 08/19] net: dsa: tag_gswip: add .flow_dissect() callback Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 09/19] net: dsa: tag_gswip: split out common tag accessors Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 10/19] net: dsa: tag_gswip: add GRO callbacks Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 11/19] net: dsa: tag_lan9303: add .flow_dissect() callback Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 12/19] net: dsa: tag_lan9303: split out common tag accessors Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 13/19] net: dsa: tag_lan9303: add GRO callbacks Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 14/19] net: dsa: tag_mtk: split out common tag accessors Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 15/19] net: dsa: tag_mtk: add GRO callbacks Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 16/19] net: dsa: tag_qca: fix doubled Tx statistics Alexander Lobakin
2019-12-30 17:23   ` Andrew Lunn
2020-01-14 21:57     ` Florian Fainelli
2019-12-30 14:30 ` [PATCH RFC net-next 17/19] net: dsa: tag_qca: switch to bitfield helpers Alexander Lobakin
2019-12-30 14:30 ` Alexander Lobakin [this message]
2019-12-30 14:30 ` [PATCH RFC net-next 19/19] net: dsa: tag_qca: add GRO callbacks Alexander Lobakin
2019-12-30 14:30 ` [PATCH RFC net-next 20/20] net: core: add (unlikely) DSA support in napi_gro_frags() Alexander Lobakin
2019-12-30 17:12 ` [PATCH RFC net-next 00/20] net: dsa: add GRO support Andrew Lunn
2020-01-13  9:25   ` Alexander Lobakin
2019-12-31 15:32 ` Vladimir Oltean
2020-01-13  9:30   ` Alexander Lobakin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191230143028.27313-19-alobakin@dlink.ru \
    --to=alobakin@dlink.ru \
    --cc=andrew@lunn.ch \
    --cc=ap420073@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=davem@davemloft.net \
    --cc=ecree@solarflare.com \
    --cc=edumazet@google.com \
    --cc=f.fainelli@gmail.com \
    --cc=hauke@hauke-m.de \
    --cc=jakub.kicinski@netronome.com \
    --cc=jakub@cloudflare.com \
    --cc=jiri@mellanox.com \
    --cc=komachi.yoshiki@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=mcroce@redhat.com \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=paulb@mellanox.com \
    --cc=sdf@google.com \
    --cc=sean.wang@mediatek.com \
    --cc=songliubraving@fb.com \
    --cc=stephen@networkplumber.org \
    --cc=vivien.didelot@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).