From patchwork Fri Sep 28 13:01:54 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: 10619923 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 62462174A for ; Fri, 28 Sep 2018 13:07:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51C9A284CE for ; Fri, 28 Sep 2018 13:07:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 45BEC2ADE4; Fri, 28 Sep 2018 13:07:03 +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 B2B43284CE for ; Fri, 28 Sep 2018 13:07:02 +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=iMnFpFvUUXBwdHCVyv+AQLd4XYV/MPaKRBQU3zA2Ywg=; b=TpSqmkNLUpX4jT AQB8fU6ikj1GTCwkFKr7EFTdd464jnQoFo5Tl2YdE2oE9dsvy/5IJfArfHDXjt6ZatTGpcZjRwV+o xoGlqFhq6IQHReb6Ll7+Pb+1temF10Y1vCv/h93f+LOTwOpifGvfjZB8MDWfCk6YuHhpf+Hc/9vtj oyB0PvhTjOI3LfNc9IahN0k/vmAkdvMBzcSGs6VCyNO/WEKjn0j5P+o7lQWDDLK/EhZZGgd62j5LD XqDHKOTY5mjmwmEMLAanjAQk+HNdcSjGazJGr1/epOFMa+ntd9zc5JKT61eaq07wRzoqSscdK8eht S2eYA3roEcGV2AuRtQAA==; 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 1g5sTn-0000tn-Dh; Fri, 28 Sep 2018 13:06:47 +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 1g5sPy-0006O0-EK for linux-arm-kernel@lists.infradead.org; Fri, 28 Sep 2018 13:03:16 +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 w8SD1wwq030074; Fri, 28 Sep 2018 15:02:32 +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 2mqd47ydtc-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT); Fri, 28 Sep 2018 15:02:31 +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 238D63A; Fri, 28 Sep 2018 13:02:31 +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 CA99F2C1B; Fri, 28 Sep 2018 13:02:30 +0000 (GMT) Received: from localhost (10.75.127.50) by SFHDAG5NODE2.st.com (10.75.127.14) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 28 Sep 2018 15:02:29 +0200 From: Pierre-Yves MORDRET To: Vinod Koul , Rob Herring , Mark Rutland , Alexandre Torgue , Maxime Coquelin , Dan Williams , , , , Subject: [PATCH v3 6/7] dmaengine: stm32-dma: enable descriptor_reuse Date: Fri, 28 Sep 2018 15:01:54 +0200 Message-ID: <1538139715-24406-7-git-send-email-pierre-yves.mordret@st.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1538139715-24406-1-git-send-email-pierre-yves.mordret@st.com> References: <1538139715-24406-1-git-send-email-pierre-yves.mordret@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.50] X-ClientProxiedBy: SFHDAG1NODE2.st.com (10.75.127.2) To SFHDAG5NODE2.st.com (10.75.127.14) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:, , definitions=2018-09-28_06:, , signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180928_060250_836959_1F658D05 X-CRM114-Status: GOOD ( 17.02 ) 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: v3: v2: 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 85e81c4..ba79051 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);