devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amelie Delaunay <amelie.delaunay-qxv4g6HH51o@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	Maxime Coquelin
	<mcoquelin.stm32-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Alexandre Torgue <alexandre.torgue-qxv4g6HH51o@public.gmane.org>
Cc: linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Amelie Delaunay <amelie.delaunay-qxv4g6HH51o@public.gmane.org>
Subject: [PATCH 7/8] spi: stm32: enhance DMA error management
Date: Fri, 23 Jun 2017 14:55:49 +0200	[thread overview]
Message-ID: <1498222550-19092-8-git-send-email-amelie.delaunay@st.com> (raw)
In-Reply-To: <1498222550-19092-1-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>

This patch reworks DMA error management. In case the DMA callback is
called while EOT (End Of Transfer) flag is not set, that means that DMA
encountered an error. This error will result in an auto-suspend of SPI
flow, which could also result in an overrun. So, in DMA mode, SUSP and
OVR flags are a condition to stop the current transfer.

Signed-off-by: Amelie Delaunay <amelie.delaunay-qxv4g6HH51o@public.gmane.org>
---
 drivers/spi/spi-stm32.c | 20 +++++++++++++++-----
 1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c
index 209afda..63af9d9 100644
--- a/drivers/spi/spi-stm32.c
+++ b/drivers/spi/spi-stm32.c
@@ -514,6 +514,12 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
 		dev_warn(spi->dev, "Communication suspended\n");
 		if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
 			stm32_spi_read_rxfifo(spi, false);
+		/*
+		 * If communication is suspended while using DMA, it means
+		 * that something went wrong, so stop the current transfer
+		 */
+		if (spi->cur_usedma)
+			end = true;
 	}
 
 	if (sr & SPI_SR_MODF) {
@@ -525,6 +531,12 @@ static irqreturn_t stm32_spi_irq(int irq, void *dev_id)
 		dev_warn(spi->dev, "Overrun: received value discarded\n");
 		if (!spi->cur_usedma && (spi->rx_buf && (spi->rx_len > 0)))
 			stm32_spi_read_rxfifo(spi, false);
+		/*
+		 * If overrun is detected while using DMA, it means that
+		 * something went wrong, so stop the current transfer
+		 */
+		if (spi->cur_usedma)
+			end = true;
 	}
 
 	if (sr & SPI_SR_EOT) {
@@ -645,12 +657,10 @@ static void stm32_spi_dma_cb(void *data)
 
 	spin_unlock_irqrestore(&spi->lock, flags);
 
-	if (!(sr & SPI_SR_EOT)) {
-		dev_warn(spi->dev, "DMA callback (sr=0x%08x)\n", sr);
+	if (!(sr & SPI_SR_EOT))
+		dev_warn(spi->dev, "DMA error (sr=0x%08x)\n", sr);
 
-		spi_finalize_current_transfer(spi->master);
-		stm32_spi_disable(spi);
-	}
+	/* Now wait for EOT, or SUSP or OVR in case of error */
 }
 
 /**
-- 
1.9.1

--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2017-06-23 12:55 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23 12:55 [PATCH 0/8] STM32 SPI various fixes Amelie Delaunay
2017-06-23 12:55 ` [PATCH 1/8] dt-bindings: spi: stm32: use SoC specific compatible Amelie Delaunay
     [not found]   ` <1498222550-19092-2-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-26 19:08     ` Rob Herring
2017-06-28 19:25     ` Applied "spi: stm32: use SoC specific compatible" to the spi tree Mark Brown
2017-06-23 12:55 ` [PATCH 2/8] spi: stm32: fix compatible to fit with new bindings Amelie Delaunay
     [not found]   ` <1498222550-19092-3-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-28 19:25     ` Applied "spi: stm32: fix compatible to fit with new bindings" to the spi tree Mark Brown
2017-06-23 12:55 ` [PATCH 3/8] dt-bindings: spi: stm32: fix example with st,spi-midi-ns property Amelie Delaunay
     [not found]   ` <1498222550-19092-4-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-26 19:12     ` Rob Herring
2017-06-23 12:55 ` [PATCH 4/8] spi: stm32: replace st, spi-midi with st, spi-midi-ns to fit bindings Amelie Delaunay
     [not found]   ` <1498222550-19092-5-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-28 19:25     ` Applied "spi: stm32: replace st, spi-midi with st, spi-midi-ns to fit bindings" to the spi tree Mark Brown
2017-06-23 12:55 ` [PATCH 5/8] spi: stm32: use normal conditional statements instead of ternary operator Amelie Delaunay
     [not found]   ` <1498222550-19092-6-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-28 19:25     ` Applied "spi: stm32: use normal conditional statements instead of ternary operator" to the spi tree Mark Brown
2017-06-23 12:55 ` [PATCH 6/8] spi: stm32: add runtime PM support Amelie Delaunay
2017-06-28 19:25   ` Applied "spi: stm32: add runtime PM support" to the spi tree Mark Brown
     [not found] ` <1498222550-19092-1-git-send-email-amelie.delaunay-qxv4g6HH51o@public.gmane.org>
2017-06-23 12:55   ` Amelie Delaunay [this message]
2017-06-23 12:55 ` [PATCH 8/8] spi: stm32: fix potential dereference null return value Amelie Delaunay
2017-06-28 19:25   ` Applied "spi: stm32: fix potential dereference null return value" to the spi tree Mark Brown

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=1498222550-19092-8-git-send-email-amelie.delaunay@st.com \
    --to=amelie.delaunay-qxv4g6hh51o@public.gmane.org \
    --cc=alexandre.torgue-qxv4g6HH51o@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=mcoquelin.stm32-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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;
as well as URLs for NNTP newsgroup(s).