From patchwork Tue Feb 7 10:30:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 13131359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7B815C636CD for ; Tue, 7 Feb 2023 10:31:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:MIME-Version: Content-Transfer-Encoding:Content-Type:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=4Y4OMC14risVihGyOmksynEVTFRTeMEHgGToHfOtsM4=; b=HJ+s0Ft/FWyK5aPO9ObBKOSHmM yFKY+ltyzB1O1cCQfrTesC7+HCbN+O/HgBWjWEDmttJI7vyRCfOIepFXkVnhe4VNqXPhssjZVgLn+ 4/IuO1V7V6V7ymhEmuKME+ey5arltXqlTQzLj//U8c7cgk4g+3wmkBmZSWzX53AQKuDxek/LJD2nJ /WfcrbjFeqFCgsSju2/c/4rI1A82VXNSPbvQmn+K+GVVptoCmIvTOAADhZbng5D8sxXRsAAE/YboI tAtacl6+Z9EvzU1fW1oCBjSBs64phY6GT/xEGEmnKfUzx+XV28V6+Oawe5SQ+C6nY4spidsFJCFD4 +lnynZGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pPLFf-00BiV3-8p; Tue, 07 Feb 2023 10:31:03 +0000 Received: from mail-vi1eur02on2061a.outbound.protection.outlook.com ([2a01:111:f400:fe16::61a] helo=EUR02-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pPLFQ-00BiOK-MU; Tue, 07 Feb 2023 10:30:50 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R3vxlteb4LUSYWpb8GpCOgmzfEQBR0RRp+Pw6lyaE+5gwOblUUqdGI/QVAZAvLa1yRNCftob3dhhprLw7F+faxQAMAb299ig9pOQ3fN9Mou7We9B92hviqroWJ/w9EYx4/UO8Qae5fRwquXJTfT1sMiVL2MhW1iOGbBXtYp7bteDkcSd0xy8C5IRIQYPI6/n1VADfDcOivbtB+i3/ZrZa6wKeF6x5hUzxzjMIfuKENcikuGSlzXfFvSOlTxMtb5s6STHGHwzCXjrWPgWac8etahZEJgrMNGR7wizL/wqVF+m7/oeOFGsMf4q3WUM0XBSdvxc8upIWYUfyS2Hx8zMKg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4Y4OMC14risVihGyOmksynEVTFRTeMEHgGToHfOtsM4=; b=fp9t0J37kDZezmhUkmg5jKBPtCDcVJXmzATq5KI2E91VnPoNzpUwN5Lp2PKsqOAw09VltkPDPlrccVRK+EssHLH6cCiVx07djXgHlKxx3G1ru6jFruUVw72+2GTvEfQzlodXszzqD8qX/mZzFAsG4pypTc9tuW6YrtLevPZXXQ7ydpuWO8qBhnUXNe3VYkFa7UFRbXgCnbg0+Lp3Cxkguw2KIQetJzA7x1Ps/I4pGhAouU7EdhDgWjPXhU/XdTZLplQpUnek/Vc1LC1/krXUkLGApd84XC+gDoyTPxgGTlTiAYi8WSkQME1MQKGpSGIWXPfyJGRoEd2nC8z+cubDbQ== 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=4Y4OMC14risVihGyOmksynEVTFRTeMEHgGToHfOtsM4=; b=FQzowdrJvjrsqk4MZc5O1yrPXfb2zYxzO5nNJhhAMI/5dmyGgE6P5gOeV88/22fzff4xNaFf+SpTAM/No4N2i/dm4dY+XQ7y2pIyEzOB1LMNicJzfG4DVdr+yxzD6sqC7V/HHkuO51jXOTYd3zI74fQmtxb7GO14U5y8zhMBrDA= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by AM9PR04MB8274.eurprd04.prod.outlook.com (2603:10a6:20b:3e8::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.36; Tue, 7 Feb 2023 10:30:43 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3cfb:3ae7:1686:a68b%5]) with mapi id 15.20.6064.034; Tue, 7 Feb 2023 10:30:43 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Felix Fietkau , John Crispin , Sean Wang , Mark Lee , Lorenzo Bianconi , Matthias Brugger , AngeloGioacchino Del Regno , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, =?utf-8?b?QXLEsW7DpyDDnE5BTA==?= Subject: [PATCH net] net: ethernet: mtk_eth_soc: fix DSA TX tag hwaccel for switch port 0 Date: Tue, 7 Feb 2023 12:30:27 +0200 Message-Id: <20230207103027.1203344-1-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: AS4P191CA0006.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:5d5::17) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5136:EE_|AM9PR04MB8274:EE_ X-MS-Office365-Filtering-Correlation-Id: 09968a17-4ed3-4557-5078-08db08f65de8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZMxrWPusrYCB0sMmJfiiwNmb5utU0+Mtlyu6xC6rf+qx2VuVfAFas5YZJ3y3Y4CWZvuQF3GAxlnsx7g7r0G+Mqsa4OrfgAqRMLQYB1AFesb1KW5dB2oehcEcy86t2IBiCqB44spf++GHgSklfbHhQS3vcglGkuy557lhyEfl/DMPCh9DAsmCoq33ik4fHQfZuwrnXZbB/JldLjTf1fjWAEQSvTEWIaAVSb6kFyxKwhIS6ddPG5uKvq1OxGqD8vmQSG7BvqjFNGYdt0jv8m9lnIe1ZqIpUFT8wm0Gb8Y91ETKdw/G8CUMhfnKK+mJx1L2BoRVWSIqlJUlPPZsfnM4gUquw+5Jsq/iL2FuVI89mBCKz86JXAoyd8DZGjvCmhjLaJ2/Pb6xw3wFa3svD6Pd9SStx3qd+gmJtfi+d5zXqKNycsn1a6IKLXek52gv+dnp4NwJ/9qBKc7suq1DRUk2p0NdNtMTjW9gtCPFHgX+3AVZhIDOqY93BE/rhpQrEPYDw6Ene6j2Y8i75jVr91rEqZ1PEan6057t3s02DPRzjXEaGatcJj9fX+0hC5gAXQSVB6kLXH50g77KTR0y9JCKTFe8M0QUyIQUdAXR663v5QhF813b23EzQ1DabMmTxhFZIH6li7RnKwDMfALFJNtXyV9IaZuIjbIfQsyZpcFtoTqxW1WaBmsbIivXTlVhhCIyvmtnIBaAIqRd937N9hXf1UhPdcEqNXwkgdLx8OJ8Nvk= 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:(13230025)(4636009)(366004)(346002)(136003)(396003)(39860400002)(376002)(451199018)(54906003)(186003)(6512007)(86362001)(52116002)(66574015)(36756003)(2906002)(44832011)(41300700001)(5660300002)(66556008)(66476007)(8936002)(66946007)(4326008)(8676002)(6916009)(26005)(478600001)(2616005)(1076003)(6666004)(7416002)(6506007)(966005)(6486002)(38100700002)(38350700002)(83380400001)(316002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?q?AyOTJFDNqsa2in5My8KMBB0JftUf?= =?utf-8?q?62eE0riOfrmIdaOhf+ufvibdNIJnIyUA7+WDJLVo0SlrWIgH5d87iOZAGACvloBzz?= =?utf-8?q?pa0sBDcILBWYTTthlYzN7/gIIKAMWAj/F/N2gG+oSVPSdT//qAunxGxQHm6A7F7hJ?= =?utf-8?q?CsSxrjGOraWPIv5prmgsBDSieB5Mqi5s574aIBbK2pmtUzncFZpUa8OTmkNvPSg/T?= =?utf-8?q?HZMxqIPg2pQh4WD7XpMZ+eZg4uWSHuJzd9j5SBVoRIjATS9rNcZGb9XNpWpZggEVS?= =?utf-8?q?3FDoZiexj7iVMnmbLT/GjIYt5M1uH53dui7S47VfNrqr7Tx4kKcTdZfSqctJ4U7sD?= =?utf-8?q?ZycbGLJigCQbCK7hLPU3sitEvmyfYrmIGzk101VWz5UCZg2Uza8Xu2HME67+hqCrG?= =?utf-8?q?6Klz5P8E+8Etoo5pleEk98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USF5Lkhc0ROzQkUJn9vbYVBXQRUvVrM5SFSMcKood7V?= =?utf-8?q?9Xj/KUVb67/MdY/fu2HY5kgxGHALKUyA2je4KnKnfjCLNMaZF2ugVQek5TpcoBZiI?= =?utf-8?q?5lKqhWLg+JppIFYlTZ35cMynyWbfRAzo6a0fseQYxR7OhkGCE6bCUI9WWwKJLFlpK?= =?utf-8?q?y+dWNqzotYwO/FZxZQDUto16JVUMNjeMoXvNdFKQmh3chTwhGyhUjly9v/rMYFAni?= =?utf-8?q?usY3tk7tUqdfIwcu6ct35vRYWBIqL4ko+g=3D=3D?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 09968a17-4ed3-4557-5078-08db08f65de8 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2023 10:30:43.5883 (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: mLBjsKgWoNImZGCiTVYUMcuESKFVrrwK8JoZIQFF+bwkEy084bV6mGuOuw6TLtFf+rGTdvrRZldP6rjHgyNsSQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM9PR04MB8274 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230207_023048_987562_D09427BA X-CRM114-Status: GOOD ( 23.21 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org Arınç reports that on his MT7621AT Unielec U7621-06 board and MT7623NI Bananapi BPI-R2, packets received by the CPU over mt7530 switch port 0 (of which this driver acts as the DSA master) are not processed correctly by software. More precisely, they arrive without a DSA tag (in packet or in the hwaccel area - skb_metadata_dst()), so DSA cannot demux them towards the switch's interface for port 0. Traffic from other ports receives a skb_metadata_dst() with the correct port and is demuxed properly. Looking at mtk_poll_rx(), it becomes apparent that this driver uses the skb vlan hwaccel area: union { u32 vlan_all; struct { __be16 vlan_proto; __u16 vlan_tci; }; }; as a temporary storage for the VLAN hwaccel tag, or the DSA hwaccel tag. If this is a DSA master it's a DSA hwaccel tag, and finally clears up the skb VLAN hwaccel header. I'm guessing that the problem is the (mis)use of API. skb_vlan_tag_present() looks like this: #define skb_vlan_tag_present(__skb) (!!(__skb)->vlan_all) So if both vlan_proto and vlan_tci are zeroes, skb_vlan_tag_present() returns precisely false. I don't know for sure what is the format of the DSA hwaccel tag, but I surely know that lowermost 3 bits of vlan_proto are 0 when receiving from port 0: unsigned int port = vlan_proto & GENMASK(2, 0); If the RX descriptor has no other bits set to non-zero values in RX_DMA_VTAG, then the call to __vlan_hwaccel_put_tag() will not, in fact, make the subsequent skb_vlan_tag_present() return true, because it's implemented like this: static inline void __vlan_hwaccel_put_tag(struct sk_buff *skb, __be16 vlan_proto, u16 vlan_tci) { skb->vlan_proto = vlan_proto; skb->vlan_tci = vlan_tci; } What we need to do to fix this problem (assuming this is the problem) is to stop using skb->vlan_all as temporary storage for driver affairs, and just create some local variables that serve the same purpose, but hopefully better. Instead of calling skb_vlan_tag_present(), let's look at a boolean has_hwaccel_tag which we set to true when the RX DMA descriptors have something. Disambiguate based on netdev_uses_dsa() whether this is a VLAN or DSA hwaccel tag, and only call __vlan_hwaccel_put_tag() if we're certain it's a VLAN tag. Arınç confirms that the treatment works, so this validates the assumption. Link: https://lore.kernel.org/netdev/704f3a72-fc9e-714a-db54-272e17612637@arinc9.com/ Fixes: 2d7605a72906 ("net: ethernet: mtk_eth_soc: enable hardware DSA untagging") Reported-by: Arınç ÜNAL Tested-by: Arınç ÜNAL Signed-off-by: Vladimir Oltean Reviewed-by: Felix Fietkau --- drivers/net/ethernet/mediatek/mtk_eth_soc.c | 24 ++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c index f1cb1efc94cf..64b575fbe317 100644 --- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c +++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c @@ -1921,7 +1921,9 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, while (done < budget) { unsigned int pktlen, *rxdcsum; + bool has_hwaccel_tag = false; struct net_device *netdev; + u16 vlan_proto, vlan_tci; dma_addr_t dma_addr; u32 hash, reason; int mac = 0; @@ -2061,27 +2063,29 @@ static int mtk_poll_rx(struct napi_struct *napi, int budget, if (netdev->features & NETIF_F_HW_VLAN_CTAG_RX) { if (MTK_HAS_CAPS(eth->soc->caps, MTK_NETSYS_V2)) { - if (trxd.rxd3 & RX_DMA_VTAG_V2) - __vlan_hwaccel_put_tag(skb, - htons(RX_DMA_VPID(trxd.rxd4)), - RX_DMA_VID(trxd.rxd4)); + if (trxd.rxd3 & RX_DMA_VTAG_V2) { + vlan_proto = RX_DMA_VPID(trxd.rxd4); + vlan_tci = RX_DMA_VID(trxd.rxd4); + has_hwaccel_tag = true; + } } else if (trxd.rxd2 & RX_DMA_VTAG) { - __vlan_hwaccel_put_tag(skb, htons(RX_DMA_VPID(trxd.rxd3)), - RX_DMA_VID(trxd.rxd3)); + vlan_proto = RX_DMA_VPID(trxd.rxd3); + vlan_tci = RX_DMA_VID(trxd.rxd3); + has_hwaccel_tag = true; } } /* When using VLAN untagging in combination with DSA, the * hardware treats the MTK special tag as a VLAN and untags it. */ - if (skb_vlan_tag_present(skb) && netdev_uses_dsa(netdev)) { - unsigned int port = ntohs(skb->vlan_proto) & GENMASK(2, 0); + if (has_hwaccel_tag && netdev_uses_dsa(netdev)) { + unsigned int port = vlan_proto & GENMASK(2, 0); if (port < ARRAY_SIZE(eth->dsa_meta) && eth->dsa_meta[port]) skb_dst_set_noref(skb, ð->dsa_meta[port]->dst); - - __vlan_hwaccel_clear_tag(skb); + } else if (has_hwaccel_tag) { + __vlan_hwaccel_put_tag(skb, htons(vlan_proto), vlan_tci); } skb_record_rx_queue(skb, 0);