From patchwork Tue Aug 10 13:13:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 494793 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BD98FC432BE for ; Tue, 10 Aug 2021 13:14:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F6AE6101E for ; Tue, 10 Aug 2021 13:14:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240865AbhHJNOq (ORCPT ); Tue, 10 Aug 2021 09:14:46 -0400 Received: from mail-db8eur05on2089.outbound.protection.outlook.com ([40.107.20.89]:28640 "EHLO EUR05-DB8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S239339AbhHJNOn (ORCPT ); Tue, 10 Aug 2021 09:14:43 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ETIEP7E6eEXi1M/dNrRZejtNaIGtZtzNdfx6jGSGDjrJg/AJ3ZUZ+0hIsGj4uDlTh9fRfSgQw3nEWl2z1aQ2WcfvRhPbq0o+aD5vIuGa2gPhPm0j8FPGYv67dhENCYL7U9sG0axkI3d8RKNnxy9BjUdfKZlqvHsKU6IX9EDIhOtHW0zzME2FRDiZRGX9uX7dwP/dbDVD7Y2K68im6JdPEcJd/u+YvbI3mNRuskqqIbkH40pF85ECY/TIKOzN9K0uxObq4JxJDuiJcKLfhw/szajomAYXKiryx5YwqERLsyY1JzW6/vAHzo5O5Bd+lKbvc7sweOdcg76gFm9Be4jj1g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=i6JnGFyND2rju3c8NYQUj43DsLIaGDjphJAEumeJcek=; b=UQYKRflADde/hJlhRx80V3XdcQo2KS324wAyZTNOqE40nazR55Fh7+2xFrMHgzORRwMLIsgxg4v4jqpZkuRIPQkcPQPg85F29zlAGu4R3e5HgU4Xjd31ZTLtefRibYLs9YpHteKAtxhQwtdOqtQiYu0hdXYL9QYhYQdQQJOjsv6zkaBdTc/Gb27zLbFFwQ6mJzVi/tBz/I9lkTaYjIgKeP7vaxS45zWId1CIstHf3hQYke4rzKssqH6qO+kYVI21eKq/RxwJDCXqRwtgG1KkaFPDau6b+k5GYSuh/5JsYmlX0IAr5i8XIleE8RP6ab+2XZlHcwYlsoQ6LvcEQaoXHA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=i6JnGFyND2rju3c8NYQUj43DsLIaGDjphJAEumeJcek=; b=A4eePPdwkeL3mV+PkwARttoVYFg27yKVQCvlJSkggocZe+ZdrFCPBvYLJlQe07Oz2Loa7L515sGR1/bh3C9pl2apUeD0iBJndg1u2jP7zu0X+ca/Fwwbkng+OZpU7FQgdfNJ3FqBXUB2asHrKx5nh/UOFdwa1ewKhzKeX09ry7o= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB7119.eurprd04.prod.outlook.com (2603:10a6:800:12e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.21; Tue, 10 Aug 2021 13:14:18 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4394.023; Tue, 10 Aug 2021 13:14:18 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Vladimir Oltean , Linus Walleij , DENG Qingfang , John Crispin , Sean Wang , Landen Chao Subject: [PATCH v2 net-next 3/4] net: dsa: create a helper for locating EtherType DSA headers on RX Date: Tue, 10 Aug 2021 16:13:55 +0300 Message-Id: <20210810131356.1655069-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210810131356.1655069-1-vladimir.oltean@nxp.com> References: <20210810131356.1655069-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR02CA0228.eurprd02.prod.outlook.com (2603:10a6:20b:28f::35) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (188.25.144.60) by AM0PR02CA0228.eurprd02.prod.outlook.com (2603:10a6:20b:28f::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.14 via Frontend Transport; Tue, 10 Aug 2021 13:14:17 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 24adc024-bf84-46cd-f8d1-08d95c00c27c X-MS-TrafficTypeDiagnostic: VI1PR04MB7119: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QGZAimQkuJgU7Yibc0UJ550WjAfBy602IrSvF9K/JCTmLxocps+AYA5sSr3dmKRcIpn3mH/74+7esqb+geB5Zdy2+lqyhVrPW/qSfYtOgVQQmTqqEO5tHBavvCD3wTgyVXCXefB3tY7k7Z0W46WutMsXYYL5ifgDQdu/eWNqtsIA1DqSWX8I9txG8LBWo9vIFyA5kqZdDPbj5hDrtcDeyAjyF7Kf02pt8hywrA8YzhipK+ROt2njz3l5yFEyG3mgrR2tzDoUQQTp2QLqLhCKJOIKtL0GhZ+YNdsDgEy0xJIbIFrcU7Nbd5yHded7Mnz7/wp7XVYgqrcx/HIa2uNafYBf+9uTSz8Nb3HVZro030Z55nuWdHOLDdaDYMhoOJdOv+/0So4FSRLqOSSkUn+DwaJwWTquGlQELKsrwA3e0x5QtZs3BxhWF7MdYoBDF0ygJNGqwFGY47FWDhexLvHroA1fR5Cg34ZUG4lAoAnVXnWs1CToLd8M40cG6k/alfvOKEUjrNBij8s2AC1HU4a0udIFc7htVSIZ5zokXONw/foMKM/AvL09whFhLdfMcym79dmgLfKKceB9Ex76cV2K4sK9tk6DokEaAjmLasNBPynxzqly9Y2GiiFSZ9jxGyrjK0QZiZHU0CNNNB005EQpNEnRk2kTF/A9Icax+QpSbPC2tk+Hrfzd3QPM+8JsYg7Bf+LKyPuHgFyYauiwb5i0JYCblhj2QoYip5+OjxkEU4I= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(396003)(346002)(376002)(39860400002)(366004)(186003)(26005)(478600001)(8936002)(4326008)(52116002)(2906002)(8676002)(38100700002)(66476007)(86362001)(66556008)(6506007)(38350700002)(6666004)(66946007)(36756003)(6486002)(1076003)(956004)(2616005)(316002)(110136005)(6512007)(5660300002)(44832011)(83380400001)(7416002)(54906003)(83323001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Djy4LZhpN1nWBDSgKq8GDzXtHH9VflT2yVJngONTp7Grw5tEjPaJncD9JMygg5ZfYZtyD8/LjSrAC5knP8wU0sM8C1IBrhvtUjpIsQr0ksfY1B0wv6Dhz3xXtLKjqyfBDUu8NbNKU3fEhUy4G85T1XYHM5/sveXy6LXchIb/gUZ1dMdF5w4URXUGFxnxyBL660FV2DQsmkLNfyhAOqeN+ZoNKO4vq29FKjh/m2H14E+R57zfP+xkWOvVNJhf/c7viQDNOUYk81L42DXO4F7x2vcGTUqf4FYaP87GXprLgmR++GfwFyPDO/V7C30stnPWuH3PPZE9bMhYETb98knZr7PY9A1uUxofEXiU4kKuyCCPf398aOeyku5Gp/8E547yRe828MHD1KC5gXJ6G8d0tSslHmG0soGTzWxuHFVQsjI5ragDbTWZ2cm2LMfc+iWGv6aBvplRszDxS8IVT9pDPdGQwQq5JuU7PIWST0aP7Htops1mY1sDanYBV6q2Mk0NbBb9sHmvr36nEYA85IzXZWxhRwsOcddCIyglQ/6suFugRXZsDpYB+RPK+9BILsBSJ3Hr9lFH3kNIKDBNRgNkLVEaKomzLGv/5APuW0pZJtNqLUmhv9gqKRLeIKEYkPV+2WTlai1SCig5BHjbsIbX9gj8SZOUt/HEeigyN95a0OMs6By96NaN8fXX/kRH3VCNOahmdXo9CgysbTn0vS5OTsavVVnCdXgpnGSrNcir7VQeabbjujJIMkh9VPhjtG6IJcTaffepTdEKT0TOSbeM7E23qsRlsPY7FpSKAD8RQNEpvbEbMqz6Zs4h6z8qGOJLzKnLY06w8kQj/xxIotdp5ojD1lQC6lGKRxO7vs9t4SmURlpdngqtD1for6xxWFRc2gNw6Gyuc9iTWM6Fvk+sX84Fk14Zk27+DMGRgJ/+dk9FCs1zIc9I2JP75Xva1cg3pXEEv3u8EtW1exyQehhi4idNeo72TtoJHEq9Sm/4fJxQki5+wNMV77Njquhl4XkaErzlfiwhLK+rixJlflRLbipfVbHL69OlD8TDq2BbYF9ZARqJJ3DBOczPNGpL3dQJUb0fifZ7RetWPndQtzoHVMhx1gWH0ipMb3PNm3blw1q2th/z0F4BjbRDCpVHC4wYy8nvFBELcCxgGTPnIyLV4AhYhS8NZp9h8xs9QOl/uWrZQGu5vEg/lxGpRgD65+qkos+jGMP3Wtf8j02TOa1FwAFK6W7nJ3HoPa+dtZOH5PdrHSgA0KMiji1VJE0pxQEG0OZVdPjtSQVRJ+Zq4TYUdoDjEF4FqOC1kQ+P/uQRTzjeXPK2yvifiuD1pR13+d5L X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 24adc024-bf84-46cd-f8d1-08d95c00c27c X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2021 13:14:18.4280 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DX9LryMhL1GWEncNsVUfNEqEaDapYJSPr4CnQxEUsqHh/iTlzm7ew/3KqYxZfQttlKLYqermfBInA9ViDqw4eA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7119 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Reviewed-by: Florian Fainelli Reviewed-by: Andrew Lunn --- 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; From patchwork Tue Aug 10 13:13:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 494792 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CF9A0C4338F for ; Tue, 10 Aug 2021 13:14:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AAEAC6101E for ; Tue, 10 Aug 2021 13:14:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241117AbhHJNOs (ORCPT ); Tue, 10 Aug 2021 09:14:48 -0400 Received: from mail-db8eur05on2089.outbound.protection.outlook.com ([40.107.20.89]:28640 "EHLO EUR05-DB8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S240574AbhHJNOo (ORCPT ); Tue, 10 Aug 2021 09:14:44 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fq6848kTzQ0j8bmxH7wbFd2eyv9Zg0Rzc3a6p/eYY9VNjcrHghIslYf75E6v+jmiZ81pcq5fO7tjv9SeDg4xOz9UZ6XtPv/7Yt/HQLmMHLdysiOFfFd+CLkl9/Gm87DWHzmw2FComQWv6mb4dB/FFr06QQ9Wndwzm0aUKmYTp4+LLOtMuOewKC7gEGXSl8yqcs6LQlS/uV1EFh+sqCSkRsOBbMEZIagKfi4hPV4x9/BgBG9IBbthZiJyZvL8mJ1ob2NcqFDXFNb7APBzMA7442JGmRnjPdmTB4IeFHEjxb9O8LFz4CF6pGO/M/LkWUlSL/K31ISxoZga/o+WuSKb+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+iPTgYox/DcBCPz5437/Eo/vms7PZS4C+yt8q8gckt4=; b=ReBiiVkHS0VFF8oOAV+3Lj9cXA10++yspItQjaeZEV49CwXFbUlVytiyuGXukwhNbZ4wVlgA/2ZI9AGfpH74LvkV+ESykQqWMR1IwtOBIx+VYk1aYtQFuvVkBK++QEXxQEisGH8jMWqSRU+96/+JP/y7nxMBojaAuww9ooyKNk3jcRxi4sGvGm3dbbjBlOL4zlc59xd4L3PMJ2B37UXQLH1qFyZqcpCy8AgCJ0MTcc8oRPMGbbBjl3MIL1SFzOUZOM3sKWVIxq4MNpFLhuCEiYwovY9BL/NJd3XnF6aT0CH4M1oxd5xKIa+mmX5ohtzH5OjIcWOJKthBttHzX+RAEQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+iPTgYox/DcBCPz5437/Eo/vms7PZS4C+yt8q8gckt4=; b=jAfkTbWcS3Je2BlsbUdX74rfSQPdzXZWkiIruaMgsWJ2j35emLKyUfA5jQ4somdKJw18sfzrJBpzc3uvojSjOcdlOH21XgftDLVCsu7MQdBzK0zP9g/ylY7h9DP4E27826VEgkBEao1+ZT7DaYmfErfMQ4PU5zIaPW6KYNoyVZE= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB7119.eurprd04.prod.outlook.com (2603:10a6:800:12e::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.21; Tue, 10 Aug 2021 13:14:20 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4394.023; Tue, 10 Aug 2021 13:14:19 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Vladimir Oltean , Linus Walleij , DENG Qingfang , John Crispin , Sean Wang , Landen Chao Subject: [PATCH v2 net-next 4/4] net: dsa: create a helper for locating EtherType DSA headers on TX Date: Tue, 10 Aug 2021 16:13:56 +0300 Message-Id: <20210810131356.1655069-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210810131356.1655069-1-vladimir.oltean@nxp.com> References: <20210810131356.1655069-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR02CA0228.eurprd02.prod.outlook.com (2603:10a6:20b:28f::35) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (188.25.144.60) by AM0PR02CA0228.eurprd02.prod.outlook.com (2603:10a6:20b:28f::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.14 via Frontend Transport; Tue, 10 Aug 2021 13:14:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6fd74470-8567-4bac-f7a4-08d95c00c345 X-MS-TrafficTypeDiagnostic: VI1PR04MB7119: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4AhVHFW0q5tKYb7AfsLKAcgwglb8mNqJXPblqpTOQDAaNnxi9zLTA2oHshcpyno9ogWA9Lg5/OrqyDfQe6jJpiMy68A46hgEvUOSZWZZzxGaCxUXo9QbLpNpEdboMpbEBLFMy4KmqTC4QAklfqn55WJ1AYmljmd/0wERiEn5iv5Ad+aFn3SBPfo4rwOYDi9Rgz3AxG/9rNws226cbWJQrW7UASktIo2KjXhql/3Y91MhxTB/V2z2g6SSSnEZ17osodX5IKedrHml6RH2i0ry2mF0Ri9dZHISk2wn5j4uu/T8W2Hpb1YBzVYPmr8V/hlSvRT0WlBXlXv9m7qvWENBc1FOEZHuhyBSR9uUA+5oLkIFF+0zD1Y1hcQIXXLA1+VPXmhp/2Ulnrkt06YPwv/XGMTddpVAlgKW9ZOHaT9f+HJc7C9AqfC8GauzHRYOh5Rn5M2HL6BEwnFtcUCHjJqMWSokmbTdbsIyKQxcvjflIJh+kJVZixNeAcAqTVnsGEcatKKv0qySPHCWi4/PdDVu4PF01mcOtq5msgA5YDcVbra0F4ybLy8W8FP3I/rf2Z9XO8NcOt+QZ5lciOECxULKwSKWtK2VmUKQJH0gaQTs1EHALIts5xrcX2H2338PruXog9/MogQvaOY1q/IwwJbmG1bNVFWWJLNJI53v+WQyf7Xta2OTGw/onWRIo5hI3wqOBj/lEGDXaShoJYgxbNKwLg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(136003)(396003)(346002)(376002)(39860400002)(366004)(186003)(26005)(478600001)(8936002)(4326008)(52116002)(2906002)(8676002)(38100700002)(66476007)(86362001)(66556008)(6506007)(38350700002)(6666004)(66946007)(36756003)(6486002)(1076003)(956004)(2616005)(316002)(110136005)(6512007)(5660300002)(44832011)(83380400001)(7416002)(54906003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YuYSWR4JN8Adq+6ulms4To/+QdQlBegcGamVQ+F+5o65zbsIB41x/5G/lSIyN70Qjn9dU0DOXhrbOC73PmbeerA3nnYFgk0yyFCnK466qGITDA3NJDHMi3TYkCYYHOcFd7heok74j2riomvx/NiQUcLG7R4xK5aas1jYxOuZM/OkBWx+jhJ9ARo68soCpi03kqJ664mgLIW6DKxIf3AITSI8u+/9gE4s4SIluYVuUGeEA0e/hh1RcVa8/UyJx1QznEXtCClUwHFMBJTRYe1HqdrOTAWqZ4uJS3CV4F+UVbM2m4xWnpMZgErh7l+ORUYGw/XNbZpQK5bNyNv1H3T3aS83azV/y/wi3x56UX8fIJ8TwzMxFWYtzcrL+V25hci0rTu0vINkNQhqukwv3rozSUMl0rnEuogPs4M7wQM6zjzFcqqZ6205K1xUMrGAcIFCsIUJoq+diHnsAIuSZLgMmCWU0Hy+/mdhst+YeWSM1KyheCAOCrAuMJxCj/skV/zG/QAAfQ1FaaJcakNqoMMQJQuLWgKpW+jR8WhOtZIea0GERIYN7d3OlUSSRdw6sjAbnoO22W1ZpLD12wibZpjleyX4rkzIY62s7DJD7R/OvSwmNaS/HzSctByFBjEMiQmLQyi7DozNR5ihcelomjI+aEcFo4Ye/7Di20+12FuGPWAkPaaUz+/v0xVd14WZI5rphs22yr3UOMsvQV4aQFA9vUUFHLVPDkx/TmnOdgn1MySalYS5tj+DL4ZF/gVnXKXq6a7WplVycgtmHkl0orBuw/lH+lTUUiVQKIageweovwHZ6aCNGxnuBDk9mgAXaNGKdCr7hnbA/ifWvD0VavERn8xybUggOjoVjbsDS/4bY07KmAzwFqmy+nLduEK5sLi4hlIbNvdi8Ia+uyP3LsDxMROLAUJhE6t0+acQdovU3Uenf/4QFQasgq2VrXo+rZKrIlJEYvn2iR+VLNcMxkdgZEOnrlue+8JQYN+rumUzfLO9itNtNXSBB/Hk9jALleaFnF0jPYa0SPt2ZoLDNFl1lrS8TcXrC3AFakUrrMcoTDGBM+kRot89TyliBu1xYdQMRsXiN718fQxvrkVE4VcgRU5I4WpckPDRwbZg6aY5hO1UNkYihaB92zVJciukca/wWSjs5AsSyW8rIJJbcu3zNjJL87ExZCzLEv/Y2iDP2YumxVAapd6tWkFK5au8cUlJw70lrmn33IwnxBHmOXnhtLUqvqSQaONAFxv7t5QdIvzSeO1MMknx9790bHqJcKvIUm/MXoZAizpNuHF3Bo8DhT9t3+9guZb+502SWAxlGUHN9Ha7JPh6NwNzeroUA9D+ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6fd74470-8567-4bac-f7a4-08d95c00c345 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2021 13:14:19.7842 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: j2o00ESUNuH8dyes/SGCNwCGmiMVeUDi1kUr1mwq+7jxzi/7SAbgmefL/uf1gCYDOWYH7TVEDfUJ7Akm7Cjcsw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB7119 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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 Reviewed-by: Florian Fainelli Reviewed-by: Andrew Lunn --- 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)); }