Received: by 2002:a05:7412:40d:b0:e2:908c:2ebd with SMTP id 13csp1158495rdf; Wed, 22 Nov 2023 07:08:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IGtrVPRU0ZAa4r6nn207CDqQP3AK6sE/7rMz2nXlX4kY8awQ17QT+iJ4xQxfo5jjJ7PnnVN X-Received: by 2002:a17:902:f691:b0:1ca:b820:74ed with SMTP id l17-20020a170902f69100b001cab82074edmr3190758plg.14.1700665679472; Wed, 22 Nov 2023 07:07:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700665679; cv=none; d=google.com; s=arc-20160816; b=mz2pn7ehpFTClgtdxTAe48J2GUquFr+AZBB3fPcmVJ1UZmYOwNHH7lseAfAOjh1T2U M3J1eAI9/1VSuEaIsHSh+L96j/z6pklG5Ct7GO/fIgbP+77aslvfE530PwUyvPy02wKo YHcoNIGrfbVAs8LQ1Me0Sju3xg7IqX99bMkedoiDmAXkPyAAf6QydCB5D9toCglyuqu5 vA1/srm1NzmQC2VC/iLPN2wdGvXSPVmuGyzqkAKif5aX7EqsJl/hAG76aIBsmzvXTENN RDFJATaUSf4E9dXN2Z5Jn322DdLWbBSbz9T9ULVe5IzwcEXpfp0Mqbz81NznnaAvUFEu oYuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=1Ux9M0cpMAvSsqsj6rpcMtIgfBNr3A/yZ31PuvivaKI=; fh=/VuINNdlghvGu536xw49I2wqgFy46KoPADwh9yTUkHc=; b=VYdIR2nBXARJSPqsY2ycaVkPaCWl3Hl7zwlcQT0DID7gBZQX4NcePbBfgEoobK/QcF O9/BCcVTF+urHZUwKtkBiAhWnavCdiMpmJE7fcMFIACbV8v1bm1To1VmEA57AxCuZIih 0yTjcAANaqndpkwepyQiHyBVBbMio6gbmlw7p/JNvVxyuNroNZ4KlIQ1V19DwEyBpGWf TRhtvgUXp2D4Y6++G0E2T1Tzzk5cXa+3cL0jD1Ce1IL6iLksiBBkcnyu2lu0nQkL1W1f sn527LrKSiDf9Gj3V39wJHMCWaUKVvJdUuBJZLGT+1XKDudCtUm0IuNuZQvPI3dlWwwH sN0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QCiimk31; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lipwig.vger.email (lipwig.vger.email. [23.128.96.33]) by mx.google.com with ESMTPS id bj12-20020a170902850c00b001cc649af5e7si12291713plb.243.2023.11.22.07.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 07:07:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) client-ip=23.128.96.33; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=QCiimk31; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.33 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by lipwig.vger.email (Postfix) with ESMTP id D8A8E81FDB87; Wed, 22 Nov 2023 07:07:54 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at lipwig.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343937AbjKVPHh (ORCPT + 99 others); Wed, 22 Nov 2023 10:07:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231596AbjKVPHf (ORCPT ); Wed, 22 Nov 2023 10:07:35 -0500 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EB0E31B1; Wed, 22 Nov 2023 07:07:28 -0800 (PST) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-507cd62472dso1023133e87.0; Wed, 22 Nov 2023 07:07:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700665647; x=1701270447; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=1Ux9M0cpMAvSsqsj6rpcMtIgfBNr3A/yZ31PuvivaKI=; b=QCiimk31yr9+QcecPzQxWybx/Y4Ziela2ljN4Q2PK+ZqTKziChfK42C/i00dmWBSyX MvoMbB8XpI/sZh7wiQyange7hIYKU30/PkyYLLJiFHmGUPxdzeXi5nvAvwN39mPKsi8/ kLFC/TeIhtaw3Q7FvOCP9bh3YmtKSfy4eLt23F4z5pQRbpI//GC6kdgNzyunWp8nZlmb oGtKQJ6HAkdosXjCqoG5V4Cf/w4flt0NFBvlXA04L8Sn4jJy8nWKAi8E3V45N67Eq9we 19w8Z21heJTItkHFCxpDgosk2tGbA52pZC0t4Oaj4Roue0hX55h2KSDC+1rTSAJxLt0h GGwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700665647; x=1701270447; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=1Ux9M0cpMAvSsqsj6rpcMtIgfBNr3A/yZ31PuvivaKI=; b=viUgUnL3YwC8xZd02PXkOmSxF7XrHDlGZ8S/WKOm4s0fUrZHmSdSXr4ZJYqpXj3QPw tNwrl6mlvB1zB+EblP7Cv6pfpKeDVZViOsjBQnKtj1vChVAQmbst2VaXOX9VOeOqcaCo INzSl6hCyZGfytcyUaX3xGmMKio9hD628ZchkSooYp5l3n4gvY2F6uy6M9NG3APTu1x2 0h+mxzbFXkwShPSNeVbS4ydbrRks92WWpB4HlFNsv+YiL2VDoN0c7pALMMba1HSr2fSg mu0hhxs1tIv5INaBn9modrvEIBxKE+E6njK7lk/ZRu7r3xw/Nvzh9wCRkRXjSlRb6x9V mTRg== X-Gm-Message-State: AOJu0Yx2GJdQjw5VSj0Lqt4rV7tpxflOmwJqSncLX+71QjlA9rMV7mQc skb207J+5PAqWdwU17lBhuM= X-Received: by 2002:a05:6512:1243:b0:500:d96e:f6eb with SMTP id fb3-20020a056512124300b00500d96ef6ebmr2498141lfb.19.1700665646721; Wed, 22 Nov 2023 07:07:26 -0800 (PST) Received: from mobilestation ([178.176.56.174]) by smtp.gmail.com with ESMTPSA id q12-20020a05651232ac00b0050a71df5d39sm1861088lfe.300.2023.11.22.07.07.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Nov 2023 07:07:26 -0800 (PST) Date: Wed, 22 Nov 2023 18:07:22 +0300 From: Serge Semin To: Jianheng Zhang Cc: Russell King , Alexandre Torgue , Jose Abreu , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Maxime Coquelin , Tan Tee Min , Ong Boon Leong , Voon Weifeng , Mohammad Athari Bin Ismail , "netdev@vger.kernel.org" , "linux-stm32@st-md-mailman.stormreply.com" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" , James Li , Martin McKenny Subject: Re: [PATCH] net: stmmac: fix FPE events losing Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.6 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lipwig.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (lipwig.vger.email [0.0.0.0]); Wed, 22 Nov 2023 07:07:55 -0800 (PST) On Wed, Nov 22, 2023 at 07:37:51AM +0000, Jianheng Zhang wrote: > > From: Serge Semin > > Sent: Tuesday, November 21, 2023 8:09 PM > > To: Jianheng Zhang > > Cc: Russell King ; Alexandre Torgue ; Jose > > Abreu ; David S. Miller ; Eric Dumazet > > ; Jakub Kicinski ; Paolo Abeni ; > > Maxime Coquelin ; Tan Tee Min ; Ong Boon > > Leong ; Voon Weifeng ; Mohammad Athari Bin > > Ismail ; netdev@vger.kernel.org; > > linux-stm32@st-md-mailman.stormreply.com; linux-arm-kernel@lists.infradead.org; > > linux-kernel@vger.kernel.org; James Li > > Subject: Re: [PATCH] net: stmmac: fix FPE events losing > > > > On Tue, Nov 21, 2023 at 09:31:31AM +0000, Jianheng Zhang wrote: > > > > From: Jianheng Zhang > > > > Sent: Thursday, November 16, 2023 12:01 AM > > > > To: Russell King ; Serge Semin > > > > Cc: Alexandre Torgue ; Jose Abreu ; David > > S. > > > > Miller ; Eric Dumazet ; Jakub Kicinski > > > > ; Paolo Abeni ; Maxime Coquelin > > > > ; Tan Tee Min ; Ong Boon Leong > > > > ; Voon Weifeng ; Mohammad Athari Bin > > Ismail > > > > ; netdev@vger.kernel.org; > > > > linux-stm32@st-md-mailman.stormreply.com; linux-arm-kernel@lists.infradead.org; > > > > linux-kernel@vger.kernel.org > > > > Subject: RE: [PATCH] net: stmmac: fix FPE events losing > > > > > > > > > > > > > -----Original Message----- > > > > > From: Russell King > > > > > Sent: Wednesday, November 15, 2023 10:26 PM > > > > > To: Serge Semin > > > > > Cc: Jianheng Zhang ; Alexandre Torgue > > ; > > > > Jose > > > > > Abreu ; David S. Miller ; Eric Dumazet > > > > > ; Jakub Kicinski ; Paolo Abeni ; > > > > > Maxime Coquelin ; Tan Tee Min ; Ong > > Boon > > > > > Leong ; Voon Weifeng ; Mohammad > > Athari > > > > Bin > > > > > Ismail ; netdev@vger.kernel.org; > > > > > linux-stm32@st-md-mailman.stormreply.com; linux-arm-kernel@lists.infradead.org; > > > > > linux-kernel@vger.kernel.org > > > > > Subject: Re: [PATCH] net: stmmac: fix FPE events losing > > > > > > > > > > On Tue, Nov 14, 2023 at 02:59:57PM +0300, Serge Semin wrote: > > > > > > On Tue, Nov 14, 2023 at 11:07:34AM +0000, Jianheng Zhang wrote: > > > > > > > The 32-bit access of register MAC_FPE_CTRL_STS may clear the FPE status > > > > > > > bits unexpectedly. Use 8-bit access for MAC_FPE_CTRL_STS control bits to > > > > > > > avoid unexpected access of MAC_FPE_CTRL_STS status bits that can reduce > > > > > > > the FPE handshake retries. > > > > > > > > > > > > > > The bit[19:17] of register MAC_FPE_CTRL_STS are status register bits. > > > > > > > Those bits are clear on read (or write of 1 when RCWE bit in > > > > > > > MAC_CSR_SW_Ctrl register is set). Using 32-bit access for > > > > > > > MAC_FPE_CTRL_STS control bits makes side effects that clear the status > > > > > > > bits. Then the stmmac interrupt handler missing FPE event status and > > > > > > > leads to FPE handshake failure and retries. > > > > > > > > > > > > > > The bit[7:0] of register MAC_FPE_CTRL_STS are control bits or reserved > > > > > > > that have no access side effects, so can use 8-bit access for > > > > > > > MAC_FPE_CTRL_STS control bits. > > > > > > > > > > > > > > Fixes: 5a5586112b92 ("net: stmmac: support FPE link partner hand-shaking procedure") > > > > > > > Signed-off-by: jianheng > > > > > > > --- > > > > > > > drivers/net/ethernet/stmicro/stmmac/dwmac5.c | 12 ++++++------ > > > > > > > 1 file changed, 6 insertions(+), 6 deletions(-) > > > > > > > > > > > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > > > > > b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > > > > > > > index e95d35f..7333995 100644 > > > > > > > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > > > > > > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > > > > > > > @@ -716,11 +716,11 @@ void dwmac5_fpe_configure(void __iomem *ioaddr, u32 num_txq, > > u32 > > > > > num_rxq, > > > > > > > u32 value; > > > > > > > > > > > > > > if (!enable) { > > > > > > > > > > > > > - value = readl(ioaddr + MAC_FPE_CTRL_STS); > > > > > > > + value = readb(ioaddr + MAC_FPE_CTRL_STS); > > > > > > > > > > > > Note this may break the platforms which don't support non-32 MMIOs for > > > > > > some devices. None of the currently supported glue-drivers explicitly > > > > > > state they have such peculiarity, but at the same time the STMMAC-core > > > > > > driver at the present state uses the dword IO ops only. For instance > > > > > > the PCIe subsystem has the special accessors for such cases: > > > > > > pci_generic_config_read32() > > > > > > pci_generic_config_write32() > > > > > > which at the very least are utilized on the Tegra and Loongson > > > > > > platforms to access the host CSR spaces. These platforms are also > > > > > > equipped with the DW MACs. The problem might be irrelevant for all the > > > > > > currently supported DW MAC controllers implementations though, but > > > > > > still it worth to draw an attention to the problem possibility and in > > > > > > order to prevent it before ahead it would be better to just avoid > > > > > > using the byte-/word- IOs if it's possible. > > > > > > > > > > Yes, this exists for configuration accesses, and is damn annoying > > > > > because the read-modify-write of these can end up clearing PCI > > > > > status register bits that are W1C. > > > > > > > > > > I've never heard of that problem with MMIO though. > > > > > > > > > > -- > > > > > RMK's Patch system: > > > > > > > > > > > https://urldefense.com/v3/__https://www.armlinux.org.uk/developer/patches/__;!!A4F2R9G_pg!ZnsQc > > > > > > > > > > > 7LKbdCiIj_nLBkt44MRSL8W8YD4WvMmPNkHFlDMrjrVqEVOVA1-P-9BVE3Oa5bC1ymKXLNV5C9mJ_rfFtLW > > > > > Fg$ > > > > > FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last! > > > > Thanks for all your mention about the potential risks of using readb and suggestions, I'll consider a > > new > > > > solution and update the patch. > > > > > > > > Best Regards, > > > > Jianheng > > > > > > Thanks for Andrew's suggestion. I consider the solution of set > > > MAC_CSR_SW_Ctrl.RCWE carefully and found that the MAC_CSR_SW_Ctrl.RCWE > > > is efficient for many other interrupt status registers, and some are used > > > in current stmmac driver (LPI PMT MMC etc). Those registers work fine in > > > clear on read mode with current code. So, I think there is no need to > > > set MAC_CSR_SW_Ctrl.RCWE that will make a large impact to current > > > interrupt handler. > > > > > > I try adding a new member variable(staged_fpe_state) to stmmac_fpe_cfg > > > that is used to stage the MAC_FPE_CTRL_STS value read in > > > dwmac5_fpe_send_mpacket(). And in dwmac5_fpe_irq_status(), use this staged > > > value and current value of MAC_FPE_CTRL_STS to check FPE status. The > > > draft patch is below. > > > > Are the status flags in the MAC_FPE_CTRL_STS register cleared on > > _writes_? (I am asking because for some reason my DW QoS Eth v5.10a HW > > manual has the status MAC_FPE_CTRL_STS flags marked as R/W, which is > > weird access mode for the status flags.) If they turn to be _not_ > > changeable on writes, then what about just converting the > > dwmac5_fpe_configure() and dwmac5_fpe_send_mpacket() methods to always > > writing to the MAC_FPE_CTRL_STS register, and if required preserve the > > shadow control MAC_FPE_CTRL_STS flags in the stmmac_fpe_cfg structure? > > AFAICS the only flag which needs to be preserved is EFPE - "enable > > FPE" flag. > > > > Such implementation (if it's possible) shall be free from the _status_ > > flags race condition and won't require additional serializations. On > > the contrary your suggestion AFAICS causes unresolved race condition > > in here > > > > > + value = readl(ioaddr + MAC_FPE_CTRL_STS) | fpe_cfg->staged_fpe_state; > > > + fpe_cfg->staged_fpe_state = 0x0; > > > > and here > > > > > value = readl(ioaddr + MAC_FPE_CTRL_STS); > > > + cfg->staged_fpe_state = value; > > > > Depending on the IRQ handling and the task scheduling timing you may > > end up with loosing the status flags anyway. > > > > * Note I am not concerning here the MAC_FPE_CTRL_STS control flags > > * race condition which AFAICS already exist in the current frame > > * preemption code. See the configs performed in the open/close/suspend > > * methods, in the link state change callbacks, in the worker task and > > * in the FPE status IRQ handler. Control flag accesses don't look > > * coherent there. > > > > -Serge(y) > > > > > > > > Best Regards, > > > Jianheng > > > > > > [PATCH v2] net: stmmac: fix FPE events losing > > > > > > --- > > > drivers/net/ethernet/stmicro/stmmac/dwmac5.c | 9 +++++++-- > > > drivers/net/ethernet/stmicro/stmmac/dwmac5.h | 1 + > > > drivers/net/ethernet/stmicro/stmmac/hwif.h | 1 + > > > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 6 +++++- > > > include/linux/stmmac.h | 1 + > > > 5 files changed, 15 insertions(+), 3 deletions(-) > > > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > > b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > > > index e95d35f..8917fd0 100644 > > > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > > > @@ -736,12 +736,15 @@ void dwmac5_fpe_configure(void __iomem *ioaddr, u32 num_txq, u32 > > num_rxq, > > > > > > int dwmac5_fpe_irq_status(void __iomem *ioaddr, struct net_device *dev) > > > { > > > + struct stmmac_priv *priv = netdev_priv(dev); > > > + struct stmmac_fpe_cfg *fpe_cfg = priv->plat->fpe_cfg; > > > u32 value; > > > int status; > > > > > > status = FPE_EVENT_UNKNOWN; > > > > > > - value = readl(ioaddr + MAC_FPE_CTRL_STS); > > > + value = readl(ioaddr + MAC_FPE_CTRL_STS) | fpe_cfg->staged_fpe_state; > > > + fpe_cfg->staged_fpe_state = 0x0; > > > > > > if (value & TRSP) { > > > status |= FPE_EVENT_TRSP; > > > @@ -766,11 +769,13 @@ int dwmac5_fpe_irq_status(void __iomem *ioaddr, struct net_device *dev) > > > return status; > > > } > > > > > > -void dwmac5_fpe_send_mpacket(void __iomem *ioaddr, enum stmmac_mpacket_type type) > > > +void dwmac5_fpe_send_mpacket(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg, > > > + enum stmmac_mpacket_type type) > > > { > > > u32 value; > > > > > > value = readl(ioaddr + MAC_FPE_CTRL_STS); > > > + cfg->staged_fpe_state = value; > > > > > > if (type == MPACKET_VERIFY) { > > > value &= ~SRSP; > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.h > > b/drivers/net/ethernet/stmicro/stmmac/dwmac5.h > > > index 53c138d..022c1a2 100644 > > > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.h > > > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.h > > > @@ -156,6 +156,7 @@ void dwmac5_est_irq_status(void __iomem *ioaddr, struct net_device *dev, > > > void dwmac5_fpe_configure(void __iomem *ioaddr, u32 num_txq, u32 num_rxq, > > > bool enable); > > > void dwmac5_fpe_send_mpacket(void __iomem *ioaddr, > > > + struct stmmac_fpe_cfg *cfg, > > > enum stmmac_mpacket_type type); > > > int dwmac5_fpe_irq_status(void __iomem *ioaddr, struct net_device *dev); > > > > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h > > b/drivers/net/ethernet/stmicro/stmmac/hwif.h > > > index b95d3e1..5496781 100644 > > > --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h > > > +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h > > > @@ -415,6 +415,7 @@ struct stmmac_ops { > > > void (*fpe_configure)(void __iomem *ioaddr, u32 num_txq, u32 num_rxq, > > > bool enable); > > > void (*fpe_send_mpacket)(void __iomem *ioaddr, > > > + struct stmmac_fpe_cfg *cfg, > > > enum stmmac_mpacket_type type); > > > int (*fpe_irq_status)(void __iomem *ioaddr, struct net_device *dev); > > > }; > > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > > index 3e50fd5..6a29f55 100644 > > > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > > > @@ -964,7 +964,8 @@ static void stmmac_fpe_link_state_handle(struct stmmac_priv *priv, bool > > is_up) > > > bool *hs_enable = &fpe_cfg->hs_enable; > > > > > > if (is_up && *hs_enable) { > > > - stmmac_fpe_send_mpacket(priv, priv->ioaddr, MPACKET_VERIFY); > > > + stmmac_fpe_send_mpacket(priv, priv->ioaddr, fpe_cfg, > > > + MPACKET_VERIFY); > > > } else { > > > *lo_state = FPE_STATE_OFF; > > > *lp_state = FPE_STATE_OFF; > > > @@ -5838,6 +5839,7 @@ static void stmmac_fpe_event_status(struct stmmac_priv *priv, int status) > > > /* If user has requested FPE enable, quickly response */ > > > if (*hs_enable) > > > stmmac_fpe_send_mpacket(priv, priv->ioaddr, > > > + fpe_cfg, > > > MPACKET_RESPONSE); > > > } > > > > > > @@ -7280,6 +7282,7 @@ static void stmmac_fpe_lp_task(struct work_struct *work) > > > netdev_info(priv->dev, SEND_VERIFY_MPAKCET_FMT, > > > *lo_state, *lp_state); > > > stmmac_fpe_send_mpacket(priv, priv->ioaddr, > > > + fpe_cfg, > > > MPACKET_VERIFY); > > > } > > > /* Sleep then retry */ > > > @@ -7294,6 +7297,7 @@ void stmmac_fpe_handshake(struct stmmac_priv *priv, bool enable) > > > if (priv->plat->fpe_cfg->hs_enable != enable) { > > > if (enable) { > > > stmmac_fpe_send_mpacket(priv, priv->ioaddr, > > > + priv->plat->fpe_cfg, > > > MPACKET_VERIFY); > > > } else { > > > priv->plat->fpe_cfg->lo_fpe_state = FPE_STATE_OFF; > > > diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h > > > index 0b4658a..1322c78 100644 > > > --- a/include/linux/stmmac.h > > > +++ b/include/linux/stmmac.h > > > @@ -175,6 +175,7 @@ struct stmmac_fpe_cfg { > > > bool hs_enable; /* FPE handshake enable */ > > > enum stmmac_fpe_state lp_fpe_state; /* Link Partner FPE state */ > > > enum stmmac_fpe_state lo_fpe_state; /* Local station FPE state */ > > > + u32 staged_fpe_state; /* Staged FPE state when read MAC_FPE_CTRL_STS */ > > > }; > > > > > > struct stmmac_safety_feature_cfg { > > > -- > > > 1.8.3.1 > > > > > Hi Serge, > > Thanks for your suggestion. > > > Are the status flags in the MAC_FPE_CTRL_STS register cleared on > > _writes_? > A write of 0 has no impact irrespective of the value programmed in RCWE bit. > This is safe option when writing the MAC_FPE_CTRL_STS register, which will > ensure that bits[19:16] are not modified unintentionally. > When RCWE bit is 0 and status bits[19:16] are read, those will be cleared, a write > of 0 or 1 do not have any impact in this mode. Great! Than always writing shall do the trick. > > > then what about just converting the > > dwmac5_fpe_configure() and dwmac5_fpe_send_mpacket() methods to always > > writing to the MAC_FPE_CTRL_STS register, and if required preserve the > > shadow control MAC_FPE_CTRL_STS flags in the stmmac_fpe_cfg structure? > > AFAICS the only flag which needs to be preserved is EFPE - "enable > > FPE" flag. > I think this is a good solution, pls check my draft patch below. Some comments are below. > > -Jianheng > > [PATCH v2] net: stmmac: fix FPE events losing > > --- > drivers/net/ethernet/stmicro/stmmac/dwmac5.c | 26 +++++++++------------- > drivers/net/ethernet/stmicro/stmmac/dwmac5.h | 4 +++- > .../net/ethernet/stmicro/stmmac/dwxgmac2_core.c | 3 ++- > drivers/net/ethernet/stmicro/stmmac/hwif.h | 4 +++- > drivers/net/ethernet/stmicro/stmmac/stmmac_main.c | 8 ++++++- > drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c | 1 + > include/linux/stmmac.h | 1 + > 7 files changed, 28 insertions(+), 19 deletions(-) > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > index e95d35f..9575e84 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.c > @@ -710,17 +710,15 @@ void dwmac5_est_irq_status(void __iomem *ioaddr, struct net_device *dev, > } > } > > -void dwmac5_fpe_configure(void __iomem *ioaddr, u32 num_txq, u32 num_rxq, > +void dwmac5_fpe_configure(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg, > + u32 num_txq, u32 num_rxq, > bool enable) > { > u32 value; > > if (!enable) { > - value = readl(ioaddr + MAC_FPE_CTRL_STS); > - > - value &= ~EFPE; > - > - writel(value, ioaddr + MAC_FPE_CTRL_STS); > + writel(0x0, ioaddr + MAC_FPE_CTRL_STS); > + cfg->fpe_ctrl_sts_shadow = 0x0; > return; > } > > @@ -729,9 +727,9 @@ void dwmac5_fpe_configure(void __iomem *ioaddr, u32 num_txq, u32 num_rxq, > value |= (num_rxq - 1) << GMAC_RXQCTRL_FPRQ_SHIFT; > writel(value, ioaddr + GMAC_RXQ_CTRL1); > > - value = readl(ioaddr + MAC_FPE_CTRL_STS); > - value |= EFPE; > + value = EFPE; > writel(value, ioaddr + MAC_FPE_CTRL_STS); > + cfg->fpe_ctrl_sts_shadow = EFPE; What about just: if (enable) cfg->fpe_csr = EFPE; else cfg->fpe_csr = 0; writel(cfg->fpe_csr, ioaddr + MAC_FPE_CTRL_STS); then ... > } > > int dwmac5_fpe_irq_status(void __iomem *ioaddr, struct net_device *dev) > @@ -766,19 +764,17 @@ int dwmac5_fpe_irq_status(void __iomem *ioaddr, struct net_device *dev) > return status; > } > > -void dwmac5_fpe_send_mpacket(void __iomem *ioaddr, enum stmmac_mpacket_type type) > +void dwmac5_fpe_send_mpacket(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg, > + enum stmmac_mpacket_type type) > { > u32 value; > > - value = readl(ioaddr + MAC_FPE_CTRL_STS); > + value = cfg->fpe_ctrl_sts_shadow; > > - if (type == MPACKET_VERIFY) { > - value &= ~SRSP; > + if (type == MPACKET_VERIFY) > value |= SVER; > - } else { > - value &= ~SVER; > + else > value |= SRSP; > - } > > writel(value, ioaddr + MAC_FPE_CTRL_STS); this can be replaced with u32 value = cfg->fpe_csr; if (type == MPACKET_VERIFY) value |= SVER; else if (type == MPACKET_RESPONSE) value |= SRSP; writel(value, ioaddr + MAC_FPE_CTRL_STS); > } > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac5.h b/drivers/net/ethernet/stmicro/stmmac/dwmac5.h > index 53c138d..aca846d 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwmac5.h > +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac5.h > @@ -153,9 +153,11 @@ int dwmac5_est_configure(void __iomem *ioaddr, struct stmmac_est *cfg, > unsigned int ptp_rate); > void dwmac5_est_irq_status(void __iomem *ioaddr, struct net_device *dev, > struct stmmac_extra_stats *x, u32 txqcnt); > -void dwmac5_fpe_configure(void __iomem *ioaddr, u32 num_txq, u32 num_rxq, > +void dwmac5_fpe_configure(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg, > + u32 num_txq, u32 num_rxq, > bool enable); > void dwmac5_fpe_send_mpacket(void __iomem *ioaddr, > + struct stmmac_fpe_cfg *cfg, > enum stmmac_mpacket_type type); > int dwmac5_fpe_irq_status(void __iomem *ioaddr, struct net_device *dev); > > diff --git a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c > index 453e88b..a74e71d 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c > +++ b/drivers/net/ethernet/stmicro/stmmac/dwxgmac2_core.c > @@ -1484,7 +1484,8 @@ static int dwxgmac3_est_configure(void __iomem *ioaddr, struct stmmac_est *cfg, > return 0; > } > > -static void dwxgmac3_fpe_configure(void __iomem *ioaddr, u32 num_txq, > +static void dwxgmac3_fpe_configure(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg, > + u32 num_txq, > u32 num_rxq, bool enable) > { > u32 value; > diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.h b/drivers/net/ethernet/stmicro/stmmac/hwif.h > index b95d3e1..68aa2d5 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/hwif.h > +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.h > @@ -412,9 +412,11 @@ struct stmmac_ops { > unsigned int ptp_rate); > void (*est_irq_status)(void __iomem *ioaddr, struct net_device *dev, > struct stmmac_extra_stats *x, u32 txqcnt); > - void (*fpe_configure)(void __iomem *ioaddr, u32 num_txq, u32 num_rxq, > + void (*fpe_configure)(void __iomem *ioaddr, struct stmmac_fpe_cfg *cfg, > + u32 num_txq, u32 num_rxq, > bool enable); > void (*fpe_send_mpacket)(void __iomem *ioaddr, > + struct stmmac_fpe_cfg *cfg, > enum stmmac_mpacket_type type); > int (*fpe_irq_status)(void __iomem *ioaddr, struct net_device *dev); > }; > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > index 3e50fd5..7791e9b 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c > @@ -964,7 +964,8 @@ static void stmmac_fpe_link_state_handle(struct stmmac_priv *priv, bool is_up) > bool *hs_enable = &fpe_cfg->hs_enable; > > if (is_up && *hs_enable) { > - stmmac_fpe_send_mpacket(priv, priv->ioaddr, MPACKET_VERIFY); > + stmmac_fpe_send_mpacket(priv, priv->ioaddr, fpe_cfg, > + MPACKET_VERIFY); > } else { > *lo_state = FPE_STATE_OFF; > *lp_state = FPE_STATE_OFF; > @@ -5838,6 +5839,7 @@ static void stmmac_fpe_event_status(struct stmmac_priv *priv, int status) > /* If user has requested FPE enable, quickly response */ > if (*hs_enable) > stmmac_fpe_send_mpacket(priv, priv->ioaddr, > + fpe_cfg, > MPACKET_RESPONSE); > } > > @@ -7262,6 +7264,7 @@ static void stmmac_fpe_lp_task(struct work_struct *work) > if (*lo_state == FPE_STATE_ENTERING_ON && > *lp_state == FPE_STATE_ENTERING_ON) { > stmmac_fpe_configure(priv, priv->ioaddr, > + fpe_cfg, > priv->plat->tx_queues_to_use, > priv->plat->rx_queues_to_use, > *enable); > @@ -7280,6 +7283,7 @@ static void stmmac_fpe_lp_task(struct work_struct *work) > netdev_info(priv->dev, SEND_VERIFY_MPAKCET_FMT, > *lo_state, *lp_state); > stmmac_fpe_send_mpacket(priv, priv->ioaddr, > + fpe_cfg, > MPACKET_VERIFY); > } > /* Sleep then retry */ > @@ -7294,6 +7298,7 @@ void stmmac_fpe_handshake(struct stmmac_priv *priv, bool enable) > if (priv->plat->fpe_cfg->hs_enable != enable) { > if (enable) { > stmmac_fpe_send_mpacket(priv, priv->ioaddr, > + priv->plat->fpe_cfg, > MPACKET_VERIFY); > } else { > priv->plat->fpe_cfg->lo_fpe_state = FPE_STATE_OFF; > @@ -7754,6 +7759,7 @@ int stmmac_suspend(struct device *dev) > if (priv->dma_cap.fpesel) { > /* Disable FPE */ > stmmac_fpe_configure(priv, priv->ioaddr, > + priv->plat->fpe_cfg, > priv->plat->tx_queues_to_use, > priv->plat->rx_queues_to_use, false); > > diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c > index ac41ef4..6ad3e0a 100644 > --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c > +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_tc.c > @@ -1079,6 +1079,7 @@ static int tc_setup_taprio(struct stmmac_priv *priv, > > priv->plat->fpe_cfg->enable = false; > stmmac_fpe_configure(priv, priv->ioaddr, > + priv->plat->fpe_cfg, > priv->plat->tx_queues_to_use, > priv->plat->rx_queues_to_use, > false); > diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h > index 0b4658a..48385c7 100644 > --- a/include/linux/stmmac.h > +++ b/include/linux/stmmac.h > @@ -175,6 +175,7 @@ struct stmmac_fpe_cfg { > bool hs_enable; /* FPE handshake enable */ > enum stmmac_fpe_state lp_fpe_state; /* Link Partner FPE state */ > enum stmmac_fpe_state lo_fpe_state; /* Local station FPE state */ > + u32 fpe_ctrl_sts_shadow; /* shadow of MAC_FPE_CTRL_STS */ + u32 fpe_csr; /* MAC_FPE_CTRL_STS reg cache */ I would have had it named as "fpe_csr" - short and well readable especially seeing CSR is a well known abbreviation for Control and Status register, which the MAC_FPE_CTRL_STS register actually is. * Note one more time: current FPE handshaking implementation is vastly clumsy, needlessly overcomplicated and prone to races. I would have seriously considered having it refactored. -Serge(y) > }; > > struct stmmac_safety_feature_cfg { > -- > 1.8.3.1 >