netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: Joakim Zhang <qiangqing.zhang@nxp.com>,
	peppe.cavallaro@st.com, alexandre.torgue@foss.st.com,
	joabreu@synopsys.com, davem@davemloft.net, kuba@kernel.org,
	mcoquelin.stm32@gmail.com, andrew@lunn.ch
Cc: linux-imx@nxp.com, jonathanh@nvidia.com, treding@nvidia.com,
	netdev@vger.kernel.org
Subject: Re: [RFC net-next] net: stmmac: should not modify RX descriptor when STMMAC resume
Date: Thu, 22 Apr 2021 09:31:51 -0700	[thread overview]
Message-ID: <1b2dd47e-184a-2dea-f62d-5417192f2710@gmail.com> (raw)
In-Reply-To: <20210419115921.19219-1-qiangqing.zhang@nxp.com>



On 4/19/2021 4:59 AM, Joakim Zhang wrote:
> When system resume back, STMMAC will clear RX descriptors:
> stmmac_resume()
> 	->stmmac_clear_descriptors()
> 		->stmmac_clear_rx_descriptors()
> 			->stmmac_init_rx_desc()
> 				->dwmac4_set_rx_owner()
> 				//p->des3 |= cpu_to_le32(RDES3_OWN | RDES3_BUFFER1_VALID_ADDR);
> It only assets OWN and BUF1V bits in desc3 field, doesn't clear desc0/1/2 fields.
> 
> Let's take a case into account, when system suspend, it is possible that
> there are packets have not received yet, so the RX descriptors are wrote
> back by DMA, e.g.
> 008 [0x00000000c4310080]: 0x0 0x40 0x0 0x34010040
> 
> When system resume back, after above process, it became a broken
> descriptor:
> 008 [0x00000000c4310080]: 0x0 0x40 0x0 0xb5010040
> 
> The issue is that it only changes the owner of this descriptor, but do nothing
> about desc0/1/2 fields. The descriptor of STMMAC a bit special, applicaton
> prepares RX descriptors for DMA, after DMA recevie the packets, it will write
> back the descriptors, so the same field of a descriptor have different
> meanings to application and DMA. It should be a software bug there, and may
> not easy to reproduce, but there is a certain probability that it will
> occur.
> 
> Commit 9c63faaa931e ("net: stmmac: re-init rx buffers when mac resume back") tried
> to re-init desc0/desc1 (buffer address fields) to fix this issue, but it
> is not a proper solution, and made regression on Jetson TX2 boards.
> 
> It is unreasonable to modify RX descriptors outside of stmmac_rx_refill() function,
> where it will clear all desc0/desc1/desc2/desc3 fields together.
> 
> This patch removes RX descriptors modification when STMMAC resume.

Your patch makes sense to me, however the explanation seems to highlight
that you may have a few cases to consider while you suspend.

Usually you will turn off the RX DMA such that DMA into DRAM stops
there, this may not an entirely atomic operation as the MAC may have to
wait for a certain packet boundary to be crossed, that could leave you
with descriptors in 3 states I believe:

- descriptor is ready for RX DMA to process and is owned by RX DMA, no
need to do anything

- descriptor has been fully consumed by the CPU and is owned by the CPU,
CPU should be putting the descriptor back on the ring and relinquish
ownership

- descriptor has been written to DRAM but not processed by CPU, and it
should be put back on the ring for RX DMA to use it

Out of suspend, don't you need to deal with descriptors in cases 2 and 3
somehow? Does the DMA skip over descriptors that are still marked as
owned by the CPU or does it stop/stall?
-- 
Florian

  parent reply	other threads:[~2021-04-22 16:32 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-19 11:59 [RFC net-next] net: stmmac: should not modify RX descriptor when STMMAC resume Joakim Zhang
2021-04-19 15:12 ` Jon Hunter
2021-04-20  1:49   ` Joakim Zhang
2021-04-20 13:33     ` Jon Hunter
2021-04-22  4:53       ` Joakim Zhang
2021-04-22 15:56         ` Jakub Kicinski
2021-04-23 13:48           ` Jon Hunter
2021-05-06  6:33             ` Joakim Zhang
2021-05-07 14:22               ` Jon Hunter
2021-05-08 11:20                 ` Joakim Zhang
2021-05-08 15:42                   ` Florian Fainelli
2021-05-10  2:10                     ` Joakim Zhang
2021-05-17  7:53                       ` Thierry Reding
2021-05-18  7:52                         ` Joakim Zhang
2021-04-22 16:12         ` Florian Fainelli
2021-04-22 17:00           ` Jon Hunter
2021-04-22 17:32             ` Florian Fainelli
2021-04-22 18:18               ` Jon Hunter
2021-04-22 18:20                 ` Florian Fainelli
2021-04-23 13:46                   ` Jon Hunter
2021-04-23 15:38                     ` Heiner Kallweit
2021-04-23  2:37               ` Joakim Zhang
2021-04-22 16:31 ` Florian Fainelli [this message]
2021-04-23  2:17   ` Joakim Zhang

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=1b2dd47e-184a-2dea-f62d-5417192f2710@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=joabreu@synopsys.com \
    --cc=jonathanh@nvidia.com \
    --cc=kuba@kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=peppe.cavallaro@st.com \
    --cc=qiangqing.zhang@nxp.com \
    --cc=treding@nvidia.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;
as well as URLs for NNTP newsgroup(s).