From patchwork Tue Jun 27 15:45:19 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 9812699 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 000C660351 for ; Tue, 27 Jun 2017 15:47:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E367928696 for ; Tue, 27 Jun 2017 15:47:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D67B1286E0; Tue, 27 Jun 2017 15:47:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6496828696 for ; Tue, 27 Jun 2017 15:47:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=pR2mKr8rALaliiadelkOxORP6VP41+I8gDnKpDUCZhs=; b=ltqctbIMm8MrGJ 3F+oYFG9f1UyZ19rBQDxfJpFgAC6nre2IL/pnUFIKVKwpgjVIBemaaFq70lpFqtMGCoDB4UprY1ku tK2nOVyDiafk6wkabLXuApkwimdZkqPactbv2aVPs61u1WZcFZWlKIiqwhSgf/9uFN4dkeLwhAbqV /jFfUQHK0H+yyGOEVsvd3svw9XDjGCRmZlQQxUIabXnbC61ngTXV8883sdGYJ5UZBzhcYCEcb9fbT oNqmBWWYGc3MjHoz9MFoy1Wgw7lhfqKmX9yK5a7MibRtC4MUOg9Vs2RIlMKt/i7Tbi7wEBsKw742T pZb0tv7ozt0jN0mA0x1A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dPsiS-0000X5-Bg; Tue, 27 Jun 2017 15:47:48 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dPsgp-0006sV-Rk for linux-arm-kernel@lists.infradead.org; Tue, 27 Jun 2017 15:46:10 +0000 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx08-.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id v5RFiFHw025628; Tue, 27 Jun 2017 17:45:43 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-.pphosted.com with ESMTP id 2b9d748vqq-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Tue, 27 Jun 2017 17:45:43 +0200 Received: from zeta.dmz-eu.st.com (zeta.dmz-eu.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 9C7EF31; Tue, 27 Jun 2017 15:45:42 +0000 (GMT) Received: from Webmail-eu.st.com (Safex1hubcas21.st.com [10.75.90.44]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 806082572; Tue, 27 Jun 2017 15:45:42 +0000 (GMT) Received: from localhost (10.201.23.160) by Webmail-ga.st.com (10.75.90.48) with Microsoft SMTP Server (TLS) id 14.3.339.0; Tue, 27 Jun 2017 17:45:42 +0200 From: Amelie Delaunay To: Mark Brown , Rob Herring , Mark Rutland , Maxime Coquelin , Alexandre Torgue Subject: [PATCHv2 7/9] spi: stm32: enhance DMA error management Date: Tue, 27 Jun 2017 17:45:19 +0200 Message-ID: <1498578321-13980-8-git-send-email-amelie.delaunay@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498578321-13980-1-git-send-email-amelie.delaunay@st.com> References: <1498578321-13980-1-git-send-email-amelie.delaunay@st.com> MIME-Version: 1.0 X-Originating-IP: [10.201.23.160] X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-06-27_09:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170627_084608_472614_6913AA32 X-CRM114-Status: GOOD ( 12.76 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Amelie Delaunay , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-spi@vger.kernel.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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. Moreover, stm32_spi_can_dma doesn't care about the state of dma channels. During driver probe, master->can_dma is initialised if dma channel request is successful. That's why we must use master->can_dma to know if dma use is possible (dma channel are successfully requested and the transfer size is greater than fifo size). Signed-off-by: Amelie Delaunay --- drivers/spi/spi-stm32.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/spi/spi-stm32.c b/drivers/spi/spi-stm32.c index 209afda..fdbc648 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 */ } /** @@ -986,7 +996,8 @@ static int stm32_spi_transfer_one(struct spi_master *master, spi->tx_len = spi->tx_buf ? transfer->len : 0; spi->rx_len = spi->rx_buf ? transfer->len : 0; - spi->cur_usedma = stm32_spi_can_dma(master, spi_dev, transfer); + spi->cur_usedma = (master->can_dma && + stm32_spi_can_dma(master, spi_dev, transfer)); ret = stm32_spi_transfer_one_setup(spi, spi_dev, transfer); if (ret) {