From: Jakub Kicinski <kuba@kernel.org>
To: Ingo Rohloff <ingo.rohloff@lauterbach.com>
Cc: Roman Gushchin <roman.gushchin@linux.dev>,
Lars-Peter Clausen <lars@metafoo.de>,
robert.hancock@calian.com, Nicolas.Ferre@microchip.com,
claudiu.beznea@microchip.com, davem@davemloft.net,
netdev@vger.kernel.org, tomas.melin@vaisala.com
Subject: Re: [PATCH v2 1/1] net: macb: Avoid erroneously stopped TX ring.
Date: Fri, 21 Apr 2023 19:57:55 -0700 [thread overview]
Message-ID: <20230421195755.5e59a164@kernel.org> (raw)
In-Reply-To: <20230421130035.14346-2-ingo.rohloff@lauterbach.com>
On Fri, 21 Apr 2023 15:00:35 +0200 Ingo Rohloff wrote:
> The SW puts a frame to be transmitted into the TX descriptor ring with
> macb_start_xmit().
> The last step of this operation is, that the SW clears the TX_USED bit
> of the first descriptor it wrote.
> The HW already reached and read this descriptor with a set TX_USED bit.
> The SW sets the TSTART bit in the NCR register.
> This is a race condition:
> 1) Either the HW already has processed the descriptor and has stopped the
> transmission, so the TGO bit in the TSR register is cleared.
> 2) The HW has read, but not yet processed the descriptor.
> In case 2) the HW ignores the TSTART trigger and stops the
> transmission a little bit later.
>
> You now have got a TX descriptor in the TX ring which is ready (TX_USED
> bit cleared), but the hardware does not process the fresh descriptor,
> because it ignored the corresponding TSTART trigger.
>
> This patch checks if the hardware is processing the same descriptor, where
> the TX_USED bit was just cleared.
> If this is the case this patch ensures that the TSTART trigger is repeated
> if needed.
Were you able to measure the performance impact of the workaround?
Doesn't name a difference?
> +static void macb_fix_tstart_race(unsigned int tx_head,
> + struct macb *bp, struct macb_queue *queue)
> +{
> + u32 macb_tsr, macb_tbqp, macb_ncr;
> +
> + /* Controller was (probably) active when we wrote TSTART.
> + * This might be a race condition.
> + * Ensure TSTART is not ignored.
> + */
> + for (;;) {
> + macb_tbqp = queue_readl(queue, TBQP);
> + macb_tbqp = macb_tbqp - lower_32_bits(queue->tx_ring_dma);
> + macb_tbqp = macb_tbqp / macb_dma_desc_get_size(bp);
> + macb_tbqp = macb_tx_ring_wrap(bp, macb_tbqp);
> + if (tx_head != macb_tbqp) {
> + /* Controller is working on different descriptor.
> + * There should be no problem.
> + */
> + break;
> + }
> +
> + /* Controller works on the descriptor we just wrote.
> + * TSTART might not have worked. Check for TGO again.
> + */
> + macb_tsr = macb_readl(bp, TSR);
> + if (!(macb_tsr & MACB_BIT(TGO))) {
> + /* Controller stopped... write TSTART again.
> + */
> + macb_ncr = macb_readl(bp, NCR);
> + macb_ncr = macb_ncr | MACB_BIT(TSTART);
> + macb_writel(bp, NCR, macb_ncr);
> + break;
> + }
> + /* Controller might stop or process our descriptor.
> + * Check again.
> + */
We should add (1) cpu_relax(), (2) a statistic which would count that
the condition was encountered, and (3) some form of limit on the loop,
so that we don't hang the host with irqs off if the NIC goes bad.
> + }
> +}
> spin_lock_irq(&bp->lock);
> + macb_tsr = macb_readl(bp, TSR);
--
pw-bot: cr
next prev parent reply other threads:[~2023-04-22 2:58 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-17 10:02 [PATCH v3] net: macb: restart tx after tx used bit read Claudiu.Beznea
2018-12-17 10:14 ` Nicolas.Ferre
2018-12-18 23:58 ` David Miller
2022-03-23 8:08 ` Tomas Melin
2022-03-23 15:43 ` Jakub Kicinski
2022-03-23 16:42 ` Robert Hancock
2022-03-25 7:10 ` Tomas Melin
2022-03-25 8:13 ` Claudiu.Beznea
2022-03-25 9:33 ` Tomas Melin
2023-04-07 21:33 ` [PATCH 0/1] Alternative, " Ingo Rohloff
2023-04-07 21:33 ` [PATCH 1/1] net: macb: A different way to restart a stuck TX descriptor ring Ingo Rohloff
2023-04-11 15:25 ` Jesse Brandeburg
2023-04-10 17:05 ` [PATCH 0/1] Alternative, restart tx after tx used bit read Robert Hancock
2023-04-12 2:07 ` Jakub Kicinski
2023-04-12 3:17 ` Lars-Peter Clausen
2023-04-12 3:43 ` Roman Gushchin
2023-04-21 13:00 ` [PATCH v2 0/1] net: macb: Avoid erroneously stopped TX ring Ingo Rohloff
2023-04-21 13:00 ` [PATCH v2 1/1] " Ingo Rohloff
2023-04-22 2:57 ` Jakub Kicinski [this message]
2023-04-12 6:27 ` [PATCH 0/1] Alternative, restart tx after tx used bit read Tomas Melin
2023-04-12 16:17 ` Robert Hancock
2023-04-24 8:54 ` Claudiu.Beznea
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=20230421195755.5e59a164@kernel.org \
--to=kuba@kernel.org \
--cc=Nicolas.Ferre@microchip.com \
--cc=claudiu.beznea@microchip.com \
--cc=davem@davemloft.net \
--cc=ingo.rohloff@lauterbach.com \
--cc=lars@metafoo.de \
--cc=netdev@vger.kernel.org \
--cc=robert.hancock@calian.com \
--cc=roman.gushchin@linux.dev \
--cc=tomas.melin@vaisala.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).