From patchwork Fri Sep 28 08:36:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre Yves MORDRET X-Patchwork-Id: 10619187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1042115A7 for ; Fri, 28 Sep 2018 08:41:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 01B7A2AB1F for ; Fri, 28 Sep 2018 08:41:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E99EA2AB4F; Fri, 28 Sep 2018 08:41:01 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.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 432162AB1F for ; Fri, 28 Sep 2018 08:41:01 +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=UKNwDcLL0kqUWPe+J/dJEgjSYLszZYU7cQWd8iSIZks=; b=uSp5OIWFugxuaQ uqJQGaqFYodYXkAlJi26LVuDp7AqiF4HF/JWBYMD8Y5OAu3KFoFfz302eQK9ljT8eyDHl4AY0F3jh ILrExNnadjbcbCBI+Z72X5RIcRPma1x4FpCAZAvxpshZx8/nu1IRWfs/lhe3RBUNAgCNXjjKzClsg l4Q09M6cl5PXPrKQZ/nIbU34x8tv6OTdkBcbF7w4/SZcDEt52U6j5UHndZVNtcFxi6ac+JpD4DWEX TKuTCLJZTejq0VHIVOi0GWvMsK7egkqh34Fsr/CK0bYY2yE/e0QeZmhWbjBMqKg+aNOVTWJGokkCy HYNNqMZP/qbxd/P8XdeA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g5oKO-0001Dg-QY; Fri, 28 Sep 2018 08:40: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.90_1 #2 (Red Hat Linux)) id 1g5oHA-00071u-VK for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 08:37:54 +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 w8S8YNS8007704; Fri, 28 Sep 2018 10:37:15 +0200 Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx08-00178001.pphosted.com with ESMTP id 2mqd47wx6g-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 28 Sep 2018 10:37:15 +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 A301538; Fri, 28 Sep 2018 08:37:14 +0000 (GMT) Received: from Webmail-eu.st.com (sfhdag5node2.st.com [10.75.127.14]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3F005110B; Fri, 28 Sep 2018 08:37:14 +0000 (GMT) Received: from localhost (10.75.127.45) by SFHDAG5NODE2.st.com (10.75.127.14) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 28 Sep 2018 10:37:13 +0200 From: Pierre-Yves MORDRET To: Vinod Koul , Rob Herring , Mark Rutland , Alexandre Torgue , Maxime Coquelin , Dan Williams , , , , Subject: [PATCH v2 6/7] dmaengine: stm32-dma: enable descriptor_reuse Date: Fri, 28 Sep 2018 10:36:33 +0200 Message-ID: <1538123794-17085-7-git-send-email-pierre-yves.mordret@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1538123794-17085-1-git-send-email-pierre-yves.mordret@st.com> References: <1538123794-17085-1-git-send-email-pierre-yves.mordret@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG4NODE2.st.com (10.75.127.11) To SFHDAG5NODE2.st.com (10.75.127.14) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-09-28_03:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180928_013729_373239_B4CF6D91 X-CRM114-Status: GOOD ( 17.10 ) 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: Pierre-Yves MORDRET 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 Enable client to resubmit already processed descriptors in order to save descriptor creation time. Signed-off-by: Pierre-Yves MORDRET --- Version history: v1: * Initial --- --- drivers/dma/stm32-dma.c | 84 +++++++++++++++++++++++++++++++------------------ 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index 1571f2f..fac44ed 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -836,34 +836,8 @@ static int stm32_dma_mdma_start(struct stm32_dma_chan *chan, { struct stm32_dma_mdma *mchan = &chan->mchan; struct stm32_dma_mdma_desc *m_desc = &sg_req->m_desc; - struct dma_slave_config config; int ret; - /* Configure MDMA channel */ - memset(&config, 0, sizeof(config)); - if (mchan->dir == DMA_MEM_TO_DEV) - config.dst_addr = mchan->sram_buf; - else - config.src_addr = mchan->sram_buf; - - ret = dmaengine_slave_config(mchan->chan, &config); - if (ret < 0) - goto error; - - /* Prepare MDMA descriptor */ - m_desc->desc = dmaengine_prep_slave_sg(mchan->chan, m_desc->sgt.sgl, - m_desc->sgt.nents, mchan->dir, - DMA_PREP_INTERRUPT); - if (!m_desc->desc) { - ret = -EINVAL; - goto error; - } - - if (mchan->dir != DMA_MEM_TO_DEV) { - m_desc->desc->callback_result = stm32_mdma_chan_complete; - m_desc->desc->callback_param = chan; - } - ret = dma_submit_error(dmaengine_submit(m_desc->desc)); if (ret < 0) { dev_err(chan2dev(chan), "MDMA submit failed\n"); @@ -1001,6 +975,7 @@ static void stm32_dma_start_transfer(struct stm32_dma_chan *chan) chan->next_sg++; + reg->dma_scr &= ~STM32_DMA_SCR_EN; stm32_dma_write(dmadev, STM32_DMA_SCR(chan->id), reg->dma_scr); stm32_dma_write(dmadev, STM32_DMA_SPAR(chan->id), reg->dma_spar); stm32_dma_write(dmadev, STM32_DMA_SM0AR(chan->id), reg->dma_sm0ar); @@ -1238,9 +1213,11 @@ static void stm32_dma_clear_reg(struct stm32_dma_chan_reg *regs) static int stm32_dma_mdma_prep_slave_sg(struct stm32_dma_chan *chan, struct scatterlist *sgl, u32 sg_len, - struct stm32_dma_desc *desc) + struct stm32_dma_desc *desc, + unsigned long flags) { struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan); + struct stm32_dma_mdma *mchan = &chan->mchan; struct scatterlist *sg, *m_sg; dma_addr_t dma_buf; u32 len, num_sgs, sram_period; @@ -1256,12 +1233,13 @@ static int stm32_dma_mdma_prep_slave_sg(struct stm32_dma_chan *chan, for_each_sg(sgl, sg, sg_len, i) { struct stm32_dma_mdma_desc *m_desc = &desc->sg_req[i].m_desc; + struct dma_slave_config config; len = sg_dma_len(sg); desc->sg_req[i].stm32_sgl_req = *sg; num_sgs = 1; - if (chan->mchan.dir == DMA_MEM_TO_DEV) { + if (mchan->dir == DMA_MEM_TO_DEV) { if (len > chan->sram_size) { dev_err(chan2dev(chan), "max buf size = %d bytes\n", @@ -1293,6 +1271,38 @@ static int stm32_dma_mdma_prep_slave_sg(struct stm32_dma_chan *chan, dma_buf += bytes; len -= bytes; } + + /* Configure MDMA channel */ + memset(&config, 0, sizeof(config)); + if (mchan->dir == DMA_MEM_TO_DEV) + config.dst_addr = desc->dma_buf; + else + config.src_addr = desc->dma_buf; + + ret = dmaengine_slave_config(mchan->chan, &config); + if (ret < 0) + goto err; + + /* Prepare MDMA descriptor */ + m_desc->desc = dmaengine_prep_slave_sg(mchan->chan, + m_desc->sgt.sgl, + m_desc->sgt.nents, + mchan->dir, + DMA_PREP_INTERRUPT); + + if (!m_desc->desc) { + ret = -EINVAL; + goto err; + } + + if (flags & DMA_CTRL_REUSE) + dmaengine_desc_set_reuse(m_desc->desc); + + if (mchan->dir != DMA_MEM_TO_DEV) { + m_desc->desc->callback_result = + stm32_mdma_chan_complete; + m_desc->desc->callback_param = chan; + } } chan->mchan.sram_buf = desc->dma_buf; @@ -1302,8 +1312,12 @@ static int stm32_dma_mdma_prep_slave_sg(struct stm32_dma_chan *chan, return 0; err: - for (j = 0; j < i; j++) + for (j = 0; j < i; j++) { + struct stm32_dma_mdma_desc *m_desc = &desc->sg_req[j].m_desc; + + m_desc->desc = NULL; sg_free_table(&desc->sg_req[j].m_desc.sgt); + } free_alloc: gen_pool_free(dmadev->sram_pool, (unsigned long)desc->dma_buf_cpu, chan->sram_size); @@ -1385,7 +1399,8 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_slave_sg( struct scatterlist *s, *_sgl; chan->mchan.dir = direction; - ret = stm32_dma_mdma_prep_slave_sg(chan, sgl, sg_len, desc); + ret = stm32_dma_mdma_prep_slave_sg(chan, sgl, sg_len, desc, + flags); if (ret < 0) return NULL; @@ -1791,6 +1806,14 @@ static void stm32_dma_desc_free(struct virt_dma_desc *vdesc) int i; if (chan->use_mdma) { + struct stm32_dma_mdma_desc *m_desc; + + for (i = 0; i < desc->num_sgs; i++) { + m_desc = &desc->sg_req[i].m_desc; + dmaengine_desc_free(m_desc->desc); + m_desc->desc = NULL; + } + for (i = 0; i < desc->num_sgs; i++) sg_free_table(&desc->sg_req[i].m_desc.sgt); @@ -1934,6 +1957,7 @@ static int stm32_dma_probe(struct platform_device *pdev) dd->directions = BIT(DMA_DEV_TO_MEM) | BIT(DMA_MEM_TO_DEV); dd->residue_granularity = DMA_RESIDUE_GRANULARITY_BURST; dd->max_burst = STM32_DMA_MAX_BURST; + dd->descriptor_reuse = true; dd->dev = &pdev->dev; INIT_LIST_HEAD(&dd->channels);