mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@intel.com>
To: Conor Dooley <conor.dooley@microchip.com>
Cc: linux-spi@vger.kernel.org, stable@vger.kernel.org,
	Daire McNamara <daire.mcnamara@microchip.com>,
	Mark Brown <broonie@kernel.org>,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] spi: microchip-core: prevent RX overflows when transmit size > FIFO size
Date: Tue, 4 Mar 2025 17:25:01 +0200	[thread overview]
Message-ID: <Z8cbTc7zdT58J4Br@black.fi.intel.com> (raw)
In-Reply-To: <20250303-veal-snooper-712c1dfad336@wendy>

On Mon, Mar 03, 2025 at 10:47:40AM +0000, Conor Dooley wrote:
> When the size of a transfer exceeds the size of the FIFO (32 bytes), RX
> overflows will be generated and receive data will be corrupted and
> warnings will be produced. For example, here's an error generated by a
> transfer of 36 bytes:
> 
>   spi_master spi0: mchp_corespi_interrupt: RX OVERFLOW: rxlen: 4, txlen: 0
> 
> The driver is currently split between handling receiving in the
> interrupt handler, and sending outside of it. Move all handling out of
> the interrupt handling, and explicitly link the number of bytes read of
> of the RX FIFO to the number written into the TX one. This both resolves
> the overflow problems as well as simplifying the flow of the driver.

...

> +static inline void mchp_corespi_read_fifo(struct mchp_corespi *spi, int fifo_max)
>  {
> +	for (int i = 0; i < fifo_max; i++) {
> +		u32 data;

> +		while (mchp_corespi_read(spi, REG_STATUS) & STATUS_RXFIFO_EMPTY)
> +			;

What may go wrong with this code? :-)
I think limiting the infinite loop by a timeout is a good thing to have.

> +		data = mchp_corespi_read(spi, REG_RX_DATA);
>  
>  		spi->rx_len -= spi->n_bytes;
>  

>  	mchp_corespi_write(spi, REG_FRAMESUP, len);
>  }

-- 
With Best Regards,
Andy Shevchenko



      parent reply	other threads:[~2025-03-04 15:25 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-03 10:47 Conor Dooley
2025-03-04 12:34 ` Mark Brown
2025-03-04 15:25 ` Andy Shevchenko [this message]

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=Z8cbTc7zdT58J4Br@black.fi.intel.com \
    --to=andriy.shevchenko@intel.com \
    --cc=broonie@kernel.org \
    --cc=conor.dooley@microchip.com \
    --cc=daire.mcnamara@microchip.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /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

all inboxes | Powered by JetHome®