[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20181104120957.GS23864@amd>
Date: Sun, 4 Nov 2018 13:09:57 +0100
From: Pavel Machek <pavel@....cz>
To: Lubomir Rintel <lkundrak@...sk>
Cc: Mark Brown <broonie@...nel.org>,
Geert Uytterhoeven <geert+renesas@...der.be>,
James Cameron <quozl@...top.org>,
Rob Herring <robh+dt@...nel.org>,
Mark Rutland <mark.rutland@....com>,
Eric Miao <eric.y.miao@...il.com>,
Haojian Zhuang <haojian.zhuang@...il.com>,
Daniel Mack <daniel@...que.org>,
Robert Jarzmik <robert.jarzmik@...e.fr>,
linux-spi@...r.kernel.org, devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org, linux-arm-kernel@...ts.infradead.org
Subject: Re: [PATCH 07/11] spi: Deal with slaves that return from
transfer_one() unfinished
On Wed 2018-10-10 19:09:32, Lubomir Rintel wrote:
> Some drivers, such as spi-pxa2xx return from the transfer_one callback
> immediately, idicating that the transfer will be finished asynchronously.
>
> Normally, spi_transfer_one_message() synchronously waits for the
> transfer to finish with wait_for_completion_timeout(). For slaves, we
> don't want the transaction to time out as it can complete in a long time
> in future. Use wait_for_completion_interruptible() instead.
>
> Signed-off-by: Lubomir Rintel <lkundrak@...sk>
Acked-by: Pavel Machek <pavel@....cz>
> @@ -993,6 +993,44 @@ static int spi_map_msg(struct spi_controller *ctlr, struct spi_message *msg)
> return __spi_map_msg(ctlr, msg);
> }
>
> +static int spi_transfer_wait(struct spi_controller *ctlr,
> + struct spi_message *msg,
> + struct spi_transfer *xfer)
> +{
> + struct spi_statistics *statm = &ctlr->statistics;
> + struct spi_statistics *stats = &msg->spi->statistics;
> + unsigned long long ms = 1;
> +
> + if (spi_controller_is_slave(ctlr)) {
> + if (wait_for_completion_interruptible(&ctlr->xfer_completion)) {
> + dev_dbg(&msg->spi->dev, "SPI transfer interrupted\n");
> + return -EINTR;
> + }
Do "return 0" here, and you can get rid of the else branch.
> + } else {
> + ms = 8LL * 1000LL * xfer->len;
> + do_div(ms, xfer->speed_hz);
> + ms += ms + 200; /* some tolerance */
> +
> + if (ms > UINT_MAX)
> + ms = UINT_MAX;
> +
> + ms = wait_for_completion_timeout(&ctlr->xfer_completion,
> + msecs_to_jiffies(ms));
> +
> + if (ms == 0) {
> + SPI_STATISTICS_INCREMENT_FIELD(statm,
> + timedout);
> + SPI_STATISTICS_INCREMENT_FIELD(stats,
> + timedout);
> + dev_err(&msg->spi->dev,
> + "SPI transfer timed out\n");
> + msg->status = -ETIMEDOUT;
> + }
> + }
> +
> + return 0;
> +}
> +
> /*
> * spi_transfer_one_message - Default implementation of transfer_one_message()
> *
--
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
Download attachment "signature.asc" of type "application/pgp-signature" (182 bytes)
Powered by blists - more mailing lists