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 <ende.tan@starfivetech.com>
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 [thread overview]
Message-ID: <20240821060307.46350-1-ende.tan@starfivetech.com> (raw)
From: Tan En De <ende.tan@starfivetech.com>
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 <ende.tan@starfivetech.com>
---
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);
--
2.34.1
next reply other threads:[~2024-08-21 6:03 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-21 6:03 ende.tan [this message]
2024-08-21 7:57 ` [net-next,v2,1/1] net: stmmac: Add dma_wmb() barrier before setting OWN bit in set_rx_owner() Eric Dumazet
2024-08-23 11:39 ` Serge Semin
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=20240821060307.46350-1-ende.tan@starfivetech.com \
--to=ende.tan@starfivetech.com \
--cc=alexandre.torgue@foss.st.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=endeneer@gmail.com \
--cc=joabreu@synopsys.com \
--cc=kuba@kernel.org \
--cc=leyfoon.tan@starfivetech.com \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-stm32@st-md-mailman.stormreply.com \
--cc=mcoquelin.stm32@gmail.com \
--cc=minda.chen@starfivetech.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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