Linux SPI subsystem development
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: Frieder Schrempf <frieder.schrempf@kontron.de>
Cc: Mark Brown <broonie@kernel.org>, David Jander <david@protonic.nl>,
	Fabio Estevam <festevam@gmail.com>,
	linux-spi@vger.kernel.org, stable@kernel.org
Subject: Re: [PATCH] spi: spi-imx: Revert "spi: spi-imx: add PIO polling support"
Date: Tue, 15 Nov 2022 13:55:49 +0100	[thread overview]
Message-ID: <20221115125549.iih75abpy7cppiss@pengutronix.de> (raw)
In-Reply-To: <46dc7280-545d-6b8c-ff7f-4bad13486292@kontron.de>

[-- Attachment #1: Type: text/plain, Size: 3473 bytes --]

On 15.11.2022 11:51:53, Frieder Schrempf wrote:
> On 14.11.22 12:29, Mark Brown wrote:
> > On Mon, Nov 14, 2022 at 09:30:26AM +0100, Frieder Schrempf wrote:
> > 
> >> As far as I know Fabio also discovered that disabling SDMA also fixes
> >> the problem.
> > 
> >> I guess I will try to repeat some tests on latest master and see if
> >> there is anything that makes things work again without reducing the
> >> clock. If anyone has some more ideas of how to fix this properly, please
> >> let me know. If nothing else helps we could also reduce the SPI clock.
> > 
> > It sounds like the commit can stay and that everyone is happy
> > that the issue is that the the commit made things run faster and
> > exposed some other misconfiguration for these systems?
> 
> Honestly I'm not really sure how to proceed.
> 
> My first impression was to keep the PIO polling support with its
> benefits if there's just this single issue with the SPI NOR on our board
> and assuming that the performance improvements uncovered a bug somewhere
> else. But at the moment I'm not quite sure this is really the case.
> 
> I did another test on v6.1-rc5 and disabling either PIO polling
> (spi-imx.polling_limit_us=0) or DMA (spi-imx.use_dma=0), or both of them
> makes reading the SPI NOR work again.

That was a good hint, I think I've found something.

Can you check if this fixes your problem? Just a quick hack to, a proper
solution needs some more love.

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 30d82cc7300b..76021b9bb445 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -1270,9 +1270,22 @@ static int spi_imx_setupxfer(struct spi_device *spi,
                spi_imx->dynamic_burst = 0;
        }
 
-       if (spi_imx_can_dma(spi_imx->controller, spi, t))
-               spi_imx->usedma = true;
-       else
+       if (spi_imx_can_dma(spi_imx->controller, spi, t)) {
+               unsigned long hz_per_byte, byte_limit;
+
+               /*
+                * Calculate the estimated time in us the transfer runs. Find
+                * the number of Hz per byte per polling limit.
+                */
+               hz_per_byte = polling_limit_us ? ((8 + 4) * USEC_PER_SEC) / polling_limit_us : 0;
+               byte_limit = hz_per_byte ? t->effective_speed_hz / hz_per_byte : 1;
+
+               /* run in polling mode for short transfers */
+               if (t->len < byte_limit)
+                       spi_imx->usedma = false;
+               else
+                       spi_imx->usedma = true;
+       } else
                spi_imx->usedma = false;
 
        spi_imx->rx_only = ((t->tx_buf == NULL)
@@ -1597,8 +1610,8 @@ static int spi_imx_transfer_one(struct spi_controller *controller,
        struct spi_imx_data *spi_imx = spi_controller_get_devdata(spi->controller);
        unsigned long hz_per_byte, byte_limit;
 
-       spi_imx_setupxfer(spi, transfer);
        transfer->effective_speed_hz = spi_imx->spi_bus_clk;
+       spi_imx_setupxfer(spi, transfer);
 
        /* flush rxfifo before transfer */
        while (spi_imx->devtype_data->rx_available(spi_imx))

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  parent reply	other threads:[~2022-11-15 12:56 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-11  0:30 [PATCH] spi: spi-imx: Revert "spi: spi-imx: add PIO polling support" Fabio Estevam
2022-11-11  9:50 ` David Jander
2022-11-11 11:33   ` Fabio Estevam
2022-11-11 12:59     ` David Jander
2022-11-14  8:30       ` Frieder Schrempf
2022-11-14 11:29         ` Mark Brown
2022-11-15 10:51           ` Frieder Schrempf
2022-11-15 12:09             ` Frieder Schrempf
2022-11-15 12:55             ` Marc Kleine-Budde [this message]
2022-11-15 14:46               ` Frieder Schrempf
2022-11-15 15:45                 ` Fabio Estevam
2022-11-15 15:46                 ` Marc Kleine-Budde
2022-11-15 16:05                   ` Frieder Schrempf
2022-11-15 16:52                 ` Marc Kleine-Budde
2022-11-15 17:11                   ` Frieder Schrempf
2022-11-15 18:01                     ` Marc Kleine-Budde
2022-11-15 17:17                   ` Fabio Estevam
2022-11-14 13:01         ` Fabio Estevam

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=20221115125549.iih75abpy7cppiss@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=broonie@kernel.org \
    --cc=david@protonic.nl \
    --cc=festevam@gmail.com \
    --cc=frieder.schrempf@kontron.de \
    --cc=linux-spi@vger.kernel.org \
    --cc=stable@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