From patchwork Wed Aug 21 06:03:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: EnDe Tan X-Patchwork-Id: 13770800 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 EB40EC52D7C for ; Wed, 21 Aug 2024 06:04:41 +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-Type: Content-Transfer-Encoding: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=t9D9QoSNSCch8sMt3vpZR4Q/R6B8e0FF7iRRaZ56bGE=; b=3EHlT1HmPqHT5oUAPt1DF40ymp Yb0CCzAznNAuBSNPkPfqgoLYD1mVBJmJdkqIVvHodF1J0fPymZhMn+M6VXgS2SuAvHQwvRE/HdChX 2MnXiFolEQh7OL7Y2aEaCVwX2hHArKK3+We4D6HS3DC21KOi2LKP9dGRuWiA+nPjipGJWWW3yd12H BSd6C5QCwOiQ2RurYbHOF2sC89hpEPULfD5B/SHcbnPohgMYnZ09oAMbAVbcv8uAGrq8dxfAeHjUF srJsEt3idH2EuVd9MTK6wSojmw+WpWEvuMAzPF86NDuINREVeQO2MryzvEVgPzp5j6f/EcbwnrrpD Volxe+RA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgeSF-00000007ehn-1Tbv; Wed, 21 Aug 2024 06:04:23 +0000 Received: from mail-sh0chn02on20703.outbound.protection.partner.outlook.cn ([2406:e500:4420:2::703] helo=CHN02-SH0-obe.outbound.protection.partner.outlook.cn) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sgeRW-00000007eYi-01CN for linux-arm-kernel@lists.infradead.org; Wed, 21 Aug 2024 06:03:40 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EYaBQGEW0XNJku6dRTns2vEk2BNQLFNbU5ZGHUFRpJH1dD8HbnMBqGGTmnZATpVvtwPJe7TmmAKtq8Dudteb5BXMnGYN6tpZz0FBg1FWtrpwHA+9ktywN3bNTx5woNYHwPwvari5nuM1q/WBpYTHqOV4SD03NcVcX6TGdvbPHULmzlwqKPyJ7e67ZvNujHLTQ70YWZraEHAqBJ5Efmh4UYZT44hzFelagddQxW636ekZq6esepvyL+7Djg12eQCXRVql9JzsdgTHljfN/tSqcepLr2e7ls1hIGmuWwGbD8mwoaPuGCFXOlROVKpOyLQ9cXMofoLEhe3I5Mtf9iGx0A== 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=t9D9QoSNSCch8sMt3vpZR4Q/R6B8e0FF7iRRaZ56bGE=; b=fWA7f/OIL7uR702jSZ1f0Hz/Xjndk3KC1L3uBF/7UBWzgSgtMEqF1UELf4VAhlN2BOz88l/hrFUKawVOyoh5L9qS9uP/R/J0KZmTC9et5p7OJa4BJSpCcmau8dwupYiiaXebtgzhPC9HuRqPm8n3MojcmHFo2/KLESOVxDUr15M9PQIXpRDYNW/5MlWSB4I6qbkELeMvWLU2Upm9b5Wqq1kV9hCn62j+pBu4ROI+iRJsrq1tkxABGip947KVQ7NK6n5DL9UGIDdnZ7Yq8Tlm9gVVDfAn+l02D+SMiIoGfc6rkhbvCly/nroMKNfzG6Sl/t/63/2grRmizw2oGh/zPg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=starfivetech.com; dmarc=pass action=none header.from=starfivetech.com; dkim=pass header.d=starfivetech.com; arc=none Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=starfivetech.com; Received: from NTZPR01MB1018.CHNPR01.prod.partner.outlook.cn (2406:e500:c510:b::7) by NTZPR01MB1097.CHNPR01.prod.partner.outlook.cn (2406:e500:c510:a::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7875.20; Wed, 21 Aug 2024 06:03:17 +0000 Received: from NTZPR01MB1018.CHNPR01.prod.partner.outlook.cn ([fe80::e1c4:5bb3:adc:97f5]) by NTZPR01MB1018.CHNPR01.prod.partner.outlook.cn ([fe80::e1c4:5bb3:adc:97f5%5]) with mapi id 15.20.7875.019; Wed, 21 Aug 2024 06:03:17 +0000 From: ende.tan@starfivetech.com To: netdev@vger.kernel.org Cc: andrew@lunn.ch, alexandre.torgue@foss.st.com, joabreu@synopsys.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, mcoquelin.stm32@gmail.com, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, leyfoon.tan@starfivetech.com, minda.chen@starfivetech.com, endeneer@gmail.com, Tan En De Subject: [net-next,v2,1/1] net: stmmac: Add dma_wmb() barrier before setting OWN bit in set_rx_owner() Date: Wed, 21 Aug 2024 14:03:07 +0800 Message-Id: <20240821060307.46350-1-ende.tan@starfivetech.com> X-Mailer: git-send-email 2.34.1 X-ClientProxiedBy: NT0PR01CA0002.CHNPR01.prod.partner.outlook.cn (2406:e500:c510::23) To NTZPR01MB1018.CHNPR01.prod.partner.outlook.cn (2406:e500:c510:b::7) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: NTZPR01MB1018:EE_|NTZPR01MB1097:EE_ X-MS-Office365-Filtering-Correlation-Id: cb7aa6b1-de3b-41b2-80ea-08dcc1a6f379 X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|41320700013|366016|7416014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: zt7Xt04coafzbvwTxlKPODIfvKjGObNHfOgwAygSWXClyBCHojP472ZH1h6ej84LFYyGnGxOoWXQFnG9ZxzoV3PSopURxyeVylPfowgfChfMWcrmH73qllsp/My5Jgtp0r4PkHK032G+oye6/yJS9NvJNIIN1GUkRMXCljF4X4TQmsTOk/vE8iQMN7Uxv1gpJ8T76vhyoWGnaP5rLEWYJYAgHlbn3c1bo8SSIJLetZqNtExcWB/7eANpF6ZKe9Y/cCVLydIpIIU5ZNnlDGCVtjj4252W0Ho+XyEQAlgwBfAtO50BAnfLMoy0hKi3U2nXPeZKqpI22GA/K8WGz21C03c4NuHZ1teTqln1ZrZYb2I/FHk2OQTkEG3aqi14/uG7pWHT4RUcRENME+yq+AbFkkcScdB2FAcziPCqPTQ3oOfEv1eai/ZA+B1XrcnMLe8rXbeSg5HGXiyG16qB10On3iWfXwLeY1kfkqDs9BABnulyVl5PpOQCI3mNj6l9oxyhxXqI/RcQuhou9hKl7YgiMqvMC3rmso6mGQfs6du3s79IJ50lXFTIFFSLJ6FApQyLSSBpAv5a1iMILENOFmUV/Zj7QDycFI4OxMC8G3k86V58jVAUu1SPMaHu4y1Z1ENj X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:NTZPR01MB1018.CHNPR01.prod.partner.outlook.cn;PTR:;CAT:NONE;SFS:(13230040)(1800799024)(41320700013)(366016)(7416014)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-A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GslPP4aAuV4YtUy/7A/AV/o56sHpKjF7OTEAr87ypTovtLGWouP5zZG3/ivF1UhhrZjSEqkCzvHt6aFKyeut42doj7sw6lF51fMXlaqQjBGIsF5YIaBsvD4ziCoIodqwzQUlKAOl2iQTnTSYslOMOUoIzVpdfp/5VQoeGAXWMyDGrXH1dvGY2Fa7PeaYlC4d0KixpFLMy0otm3PGHDiad2PO3C1f7j96WIJAGD1QgP/IFsWKJZ5QB+lf/p5RnKBC9nakA1Pe9J3wX5K2qSnXNxmFk81Pz3Hmji9YhW0667ruxS4KLeDm3xgNvHfMlvtT917dlLOAhEPHMDXgBbNl/uYj8lh3DR6zHrrcMPHA9nnGAA2VIy/R2239HT+SBjJNU8renDOv+2W5BVBQMmKWKgtdl3taDu7Y17uyHIwsfxfbrx6JlIWqLWPvq3BHJCZJcNclDsecSwPkS1NF08q2Dq4lQ/uhXF7rgFtFuTnvHqoDUwnNpcPBJ0QLdoOrK/WFg1t1ILe2XHBHjKf8hq1TU8f4K2ZmHes1oChIS/Gf/vK8xY1ZIQc3aG6cCAWitbEi4scBTyP/yhfA== X-OriginatorOrg: starfivetech.com X-MS-Exchange-CrossTenant-Network-Message-Id: cb7aa6b1-de3b-41b2-80ea-08dcc1a6f379 X-MS-Exchange-CrossTenant-AuthSource: NTZPR01MB1018.CHNPR01.prod.partner.outlook.cn X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Aug 2024 06:03:17.4318 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 06fe3fa3-1221-43d3-861b-5a4ee687a85c X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: fkCX7Oo4q5N0Demc1HMx2lIXvbNQBJw2L9L1ZW1SLqee+wjZgMlsNglhUBCCRYcSJrN9mYDH6jCvydVBxh+Z32xZhDBAqcbDtgZK6bggzmM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: NTZPR01MB1097 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240820_230338_080929_D5D654D0 X-CRM114-Status: GOOD ( 14.17 ) X-BeenThere: linux-arm-kernel@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-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Tan En De Currently, some set_rx_owner() callbacks set interrupt-on-completion bit in addition to OWN bit, without inserting a dma_wmb() barrier in between. This might cause missed interrupt if the DMA sees the OWN bit before the interrupt-on-completion bit is set. Thus, this patch adds dma_wmb() barrier right before setting OWN bit in each of the callbacks. Now that the responsibility of calling dma_wmb() is delegated to the callbacks, let's simplify main driver code by removing dma_wmb() before stmmac_set_rx_owner(). Signed-off-by: Tan En De --- v2: - Avoid introducing a new function just to set the interrupt-on-completion bit, as it is wasteful to do so. - Delegate the responsibility of calling dma_wmb() from main driver code to set_rx_owner() callbacks (i.e. let callbacks to manage the low-level ordering/barrier rather than cluttering up the main driver code). v1: - https://patchwork.kernel.org/project/netdevbpf/patch/20240814092438.3129-1-ende.tan@starfivetech.com/ --- drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c | 5 ++++- drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c | 5 +++-- drivers/net/ethernet/stmicro/stmmac/enh_desc.c | 1 + drivers/net/ethernet/stmicro/stmmac/norm_desc.c | 1 + drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 2 -- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c index 1c5802e0d7f4..95aea6ad485b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac4_descs.c @@ -186,10 +186,13 @@ static void dwmac4_set_tx_owner(struct dma_desc *p) static void dwmac4_set_rx_owner(struct dma_desc *p, int disable_rx_ic) { - p->des3 |= cpu_to_le32(RDES3_OWN | RDES3_BUFFER1_VALID_ADDR); + p->des3 |= cpu_to_le32(RDES3_BUFFER1_VALID_ADDR); if (!disable_rx_ic) p->des3 |= cpu_to_le32(RDES3_INT_ON_COMPLETION_EN); + + dma_wmb(); + p->des3 |= cpu_to_le32(RDES3_OWN); } static int dwmac4_get_tx_ls(struct dma_desc *p) diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c index fc82862a612c..d76ae833c840 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_descs.c @@ -56,10 +56,11 @@ static void dwxgmac2_set_tx_owner(struct dma_desc *p) static void dwxgmac2_set_rx_owner(struct dma_desc *p, int disable_rx_ic) { - p->des3 |= cpu_to_le32(XGMAC_RDES3_OWN); - if (!disable_rx_ic) p->des3 |= cpu_to_le32(XGMAC_RDES3_IOC); + + dma_wmb(); + p->des3 |= cpu_to_le32(XGMAC_RDES3_OWN); } static int dwxgmac2_get_tx_ls(struct dma_desc *p) diff --git a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c index 937b7a0466fc..9219fe69ea44 100644 --- a/drivers/net/ethernet/stmicro/stmmac/enh_desc.c +++ b/drivers/net/ethernet/stmicro/stmmac/enh_desc.c @@ -289,6 +289,7 @@ static void enh_desc_set_tx_owner(struct dma_desc *p) static void enh_desc_set_rx_owner(struct dma_desc *p, int disable_rx_ic) { + dma_wmb(); p->des0 |= cpu_to_le32(RDES0_OWN); } diff --git a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c index 68a7cfcb1d8f..d0b703a3346f 100644 --- a/drivers/net/ethernet/stmicro/stmmac/norm_desc.c +++ b/drivers/net/ethernet/stmicro/stmmac/norm_desc.c @@ -155,6 +155,7 @@ static void ndesc_set_tx_owner(struct dma_desc *p) static void ndesc_set_rx_owner(struct dma_desc *p, int disable_rx_ic) { + dma_wmb(); p->des0 |= cpu_to_le32(RDES0_OWN); } diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index d9fca8d1227c..859a2c4c9e5c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -4848,7 +4848,6 @@ static inline void stmmac_rx_refill(struct stmmac_priv *priv, u32 queue) if (!priv->use_riwt) use_rx_wd = false; - dma_wmb(); stmmac_set_rx_owner(priv, p, use_rx_wd); entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_rx_size); @@ -5205,7 +5204,6 @@ static bool stmmac_rx_refill_zc(struct stmmac_priv *priv, u32 queue, u32 budget) if (!priv->use_riwt) use_rx_wd = false; - dma_wmb(); stmmac_set_rx_owner(priv, rx_desc, use_rx_wd); entry = STMMAC_GET_ENTRY(entry, priv->dma_conf.dma_rx_size);