From patchwork Mon Oct 11 09:42:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 12549477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E7A4C433EF for ; Mon, 11 Oct 2021 09:43:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F9AC60F92 for ; Mon, 11 Oct 2021 09:43:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235613AbhJKJpS (ORCPT ); Mon, 11 Oct 2021 05:45:18 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:51802 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235577AbhJKJpS (ORCPT ); Mon, 11 Oct 2021 05:45:18 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B80XNt014101; Mon, 11 Oct 2021 11:43:07 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=O0JMbw+qIeEBzzCCeApdP+Pra+K3FyzR/Sgp0B/Og3Y=; b=yJh92PjsvkcrAxXt82FJvTDRTmx2ZCBQVD/6/azsCHvrt1UFObw8R2z+rjV/ql+iuYL+ qHBK7DZZd9zlpkwSJ2QxN4XNgat++JHaLDJpIAT8Ji2q4zV7U7N5NqoJiKlcV/kJ2MLp 28+v+zdK8PuOD5GM+3UebymtJpUtMFTmil1dunvGliyykluQ2uHN9OJM85tVfkzkucNq n0Wgo6v37Cj8bTTCh62FXT3yUgo/Mn5bdhr9P+RKA48FM+36aYQOfddVWtJsHDY2rSLu vq/OwMFXP2Z9QqvztOfmJXIyoq9YbgL7smLxz8uLWzqjoXlZy7wXKuFbptBqJN6ZNMO0 BA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 3bmasq2mxs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Oct 2021 11:43:07 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 0C96010002A; Mon, 11 Oct 2021 11:43:07 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 019FB21B50C; Mon, 11 Oct 2021 11:43:07 +0200 (CEST) Received: from localhost (10.75.127.47) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 11 Oct 2021 11:43:06 +0200 From: Amelie Delaunay To: Vinod Koul , Maxime Coquelin , Alexandre Torgue CC: , , , , Amelie Delaunay , Pierre-Yves Mordret Subject: [PATCH 1/3] dmaengine: stm32-dma: mark pending descriptor complete in terminate_all Date: Mon, 11 Oct 2021 11:42:57 +0200 Message-ID: <20211011094259.315023-2-amelie.delaunay@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211011094259.315023-1-amelie.delaunay@foss.st.com> References: <20211011094259.315023-1-amelie.delaunay@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-10-11_03,2021-10-07_02,2020-04-07_01 Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org To prevent accidental repeated completion, mark pending descriptor complete in terminate_all. It can be the case when terminate_all is called while no end of transfer interrupt occurs. Signed-off-by: Amelie Delaunay --- drivers/dma/stm32-dma.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index 9063c727962e..a5ccf3fa95e0 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -497,6 +497,7 @@ static int stm32_dma_terminate_all(struct dma_chan *c) spin_lock_irqsave(&chan->vchan.lock, flags); if (chan->desc) { + dma_cookie_complete(&chan->desc->vdesc.tx); vchan_terminate_vdesc(&chan->desc->vdesc); if (chan->busy) stm32_dma_stop(chan); From patchwork Mon Oct 11 09:42:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 12549479 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2BF5BC433FE for ; Mon, 11 Oct 2021 09:43:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16B6B61039 for ; Mon, 11 Oct 2021 09:43:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235577AbhJKJpU (ORCPT ); Mon, 11 Oct 2021 05:45:20 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:51828 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235614AbhJKJpU (ORCPT ); Mon, 11 Oct 2021 05:45:20 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B824qK014133; Mon, 11 Oct 2021 11:43:08 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=k+FUI2/olr8bNkpun0hAvkx43pYCKhp8ezqw9X5l4vE=; b=4cPkjy0H768j5aIDb16+uDHojnh3TL7TfDPuAkldrfuvgm1OMIvvXI4lYbWJ+MHDN7Fp lPrIpm4vducRfYVVJMMy3DO7nXWeyWUnm9ke37qUkDRUARVg6mE6H8xcaVMzl45Q3Zcs 6hzPn4R2Onw4XJkoQGvqr0G7Iz9FPPtsJyTdXVhhN7IPAaWExtdyQFras5/65E6QfHuR PwgSfxq4SuhRfpswXw11nissj1juRZE9KlEwsLTClFq8ymJaeZ2OJL3BXY6y+xQPT8pg F+xtvSTN2Vl8AngCRXjPjVEJwRtEaoIKS/izW8o1TVbdrB4Gfw14I7P0mV/GMFhPchlP qA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 3bmasq2mxv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Oct 2021 11:43:08 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3346010002A; Mon, 11 Oct 2021 11:43:08 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 29C7721B50C; Mon, 11 Oct 2021 11:43:08 +0200 (CEST) Received: from localhost (10.75.127.45) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 11 Oct 2021 11:43:07 +0200 From: Amelie Delaunay To: Vinod Koul , Maxime Coquelin , Alexandre Torgue CC: , , , , Amelie Delaunay , Pierre-Yves Mordret Subject: [PATCH 2/3] dmaengine: stm32-dma: fix stm32_dma_get_max_width Date: Mon, 11 Oct 2021 11:42:58 +0200 Message-ID: <20211011094259.315023-3-amelie.delaunay@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211011094259.315023-1-amelie.delaunay@foss.st.com> References: <20211011094259.315023-1-amelie.delaunay@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-10-11_03,2021-10-07_02,2020-04-07_01 Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org buf_addr parameter of stm32_dma_set_xfer_param function is a dma_addr_t. We only need to check the remainder of buf_addr/max_width, so, no need to use do_div and extra u64 addr. Use '%' instead. Fixes: e0ebdbdcb42a ("dmaengine: stm32-dma: take address into account when computing max width") Signed-off-by: Amelie Delaunay --- drivers/dma/stm32-dma.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index a5ccf3fa95e0..6e4ef44941ef 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -270,7 +270,6 @@ static enum dma_slave_buswidth stm32_dma_get_max_width(u32 buf_len, u32 threshold) { enum dma_slave_buswidth max_width; - u64 addr = buf_addr; if (threshold == STM32_DMA_FIFO_THRESHOLD_FULL) max_width = DMA_SLAVE_BUSWIDTH_4_BYTES; @@ -281,7 +280,7 @@ static enum dma_slave_buswidth stm32_dma_get_max_width(u32 buf_len, max_width > DMA_SLAVE_BUSWIDTH_1_BYTE) max_width = max_width >> 1; - if (do_div(addr, max_width)) + if (buf_addr % max_width) max_width = DMA_SLAVE_BUSWIDTH_1_BYTE; return max_width; From patchwork Mon Oct 11 09:42:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amelie Delaunay X-Patchwork-Id: 12549481 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8E6DCC433EF for ; Mon, 11 Oct 2021 09:43:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 71CDF60F92 for ; Mon, 11 Oct 2021 09:43:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235500AbhJKJpZ (ORCPT ); Mon, 11 Oct 2021 05:45:25 -0400 Received: from mx07-00178001.pphosted.com ([185.132.182.106]:51862 "EHLO mx07-00178001.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235626AbhJKJpV (ORCPT ); Mon, 11 Oct 2021 05:45:21 -0400 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.1.2/8.16.1.2) with SMTP id 19B7vWne014070; Mon, 11 Oct 2021 11:43:09 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=foss.st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=selector1; bh=xcge6Tmp8n1Scab5wy+5ZALoDl294NFVjrwUjkjXu/Q=; b=EsqTpSAUtYI9/6GlAWdAUvACFFkiZPukMajqPObihvVMPWzTXsRWmS4Xz0XWpazynxqs /39JsSUZ1Ve06TdZU298DIAjLS+S//VkRq2VPiLpyhU5R0sVqIx5BLiYjTQADfze0MAm iY8ITJsnyjf8qvxTKLz6vcpP/40sfPn4RsEctGoqW+Q8yWOHlxdZeXG1N9uurDQZbBi6 Mylredubg2sXYU51yNy/lJZhzvi3BU+XPa/OlpKzdPC2occt1PEi0rlBPqT45fQQYWPg FziT8INl0suqcTcOV5mm68zxwsvEunNv6Jy9S0PI0uiYgbfzHkYZpagp992uZcMrCNTt aw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 3bmasq2my0-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 11 Oct 2021 11:43:09 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3F81310002A; Mon, 11 Oct 2021 11:43:09 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag2node2.st.com [10.75.127.5]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 3839021B50C; Mon, 11 Oct 2021 11:43:09 +0200 (CEST) Received: from localhost (10.75.127.45) by SFHDAG2NODE2.st.com (10.75.127.5) with Microsoft SMTP Server (TLS) id 15.0.1497.18; Mon, 11 Oct 2021 11:43:08 +0200 From: Amelie Delaunay To: Vinod Koul , Maxime Coquelin , Alexandre Torgue CC: , , , , Amelie Delaunay , Pierre-Yves Mordret Subject: [PATCH 3/3] dmaengine: stm32-dma: fix burst in case of unaligned memory address Date: Mon, 11 Oct 2021 11:42:59 +0200 Message-ID: <20211011094259.315023-4-amelie.delaunay@foss.st.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211011094259.315023-1-amelie.delaunay@foss.st.com> References: <20211011094259.315023-1-amelie.delaunay@foss.st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG2NODE2.st.com (10.75.127.5) To SFHDAG2NODE2.st.com (10.75.127.5) X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.182.1,Aquarius:18.0.790,Hydra:6.0.391,FMLib:17.0.607.475 definitions=2021-10-11_03,2021-10-07_02,2020-04-07_01 Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org Theorically, address pointers used by STM32 DMA must be chosen so as to ensure that all transfers within a burst block are aligned on the address boundary equal to the size of the transfer. If this is always the case for peripheral addresses on STM32, it is not for memory addresses if the user doesn't respect this alignment constraint. To avoid a weird behavior of the DMA controller in this case (no error triggered but data are not transferred as expected), force no burst. Signed-off-by: Amelie Delaunay --- drivers/dma/stm32-dma.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index 6e4ef44941ef..2283c500f4ce 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -753,8 +753,14 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan, if (src_bus_width < 0) return src_bus_width; - /* Set memory burst size */ - src_maxburst = STM32_DMA_MAX_BURST; + /* + * Set memory burst size - burst not possible if address is not aligned on + * the address boundary equal to the size of the transfer + */ + if (buf_addr % buf_len) + src_maxburst = 1; + else + src_maxburst = STM32_DMA_MAX_BURST; src_best_burst = stm32_dma_get_best_burst(buf_len, src_maxburst, fifoth, @@ -803,8 +809,14 @@ static int stm32_dma_set_xfer_param(struct stm32_dma_chan *chan, if (dst_bus_width < 0) return dst_bus_width; - /* Set memory burst size */ - dst_maxburst = STM32_DMA_MAX_BURST; + /* + * Set memory burst size - burst not possible if address is not aligned on + * the address boundary equal to the size of the transfer + */ + if (buf_addr % buf_len) + dst_maxburst = 1; + else + dst_maxburst = STM32_DMA_MAX_BURST; dst_best_burst = stm32_dma_get_best_burst(buf_len, dst_maxburst, fifoth,