From patchwork Tue Dec 13 13:40:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: M'boumba Cedric Madianga X-Patchwork-Id: 9472293 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 632326021C for ; Tue, 13 Dec 2016 13:42:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 553ED2833C for ; Tue, 13 Dec 2016 13:42:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 47CDE284B8; Tue, 13 Dec 2016 13:42:37 +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=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id BF3842833C for ; Tue, 13 Dec 2016 13:42:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933028AbcLMNmg (ORCPT ); Tue, 13 Dec 2016 08:42:36 -0500 Received: from mail-wm0-f65.google.com ([74.125.82.65]:36586 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933116AbcLMNlP (ORCPT ); Tue, 13 Dec 2016 08:41:15 -0500 Received: by mail-wm0-f65.google.com with SMTP id m203so18421239wma.3; Tue, 13 Dec 2016 05:41:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ZUvcO1VdqUp7fCNyNBXBmZ7ABx2CPLQwAcFNTBANEfw=; b=wldC09tTsGqz3Njg9EbLT+/NlJCqI2m4SmwycA3jAoiTOZqhpmAFElGKezjNLJcw5Z jQRkXq7KOMKKFo1uhOICadZIBFaBN+uBXYzuz3DXX4wANSJZ3HzvfWSx6JRWsMED+lu9 F3re0QKBfB1EXNpIwsbgQ4Vc51tLVtK0eU69yY1MbBOlwXAFG7KNcuSIMk18L1F5NQVz EpJE4wh9mub7liNeRm+0lJeOAdQtKYnW6+Vk1E3Wg5VggIbaLcSifZM+/RKushw4oIrt oKbgWuUq5hJnGpRxI6x2IE67vupJwtgZJHunO2BJYXf2kStMZHz1HdrnOGpRpY6t6M0q XtwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ZUvcO1VdqUp7fCNyNBXBmZ7ABx2CPLQwAcFNTBANEfw=; b=UMIjvSC62pAl4XyVia+CCijyBbUq64YJwF3aqNzBbRcrJvdZqa2FbxjewWV7l4CJw1 KUMCidoLH23WmRsfvEbv/3hW0KFqdIg5E6Vee4jP6+RHV+0psDM2+KFvgvx/rYvYFn/G 00SKRS6UGBkgcbIf9DiFTXXxqGyaaynb7rXksSsAUdLaMa9zD5uviBB6AYCz6G3PKAIC PPECk1OeaAUTmjcV4L4F71c2KZyPx5JrtvjGmOQk8nNjBDVgHv8kC3iLzDz+KQdUojGv 8hWykq5aKzvHAFSlj67jZdiREUeVD3ARPKLW0iTf5oIHyFis8wS0nfnrXb4QDbQ5RvPG jKMA== X-Gm-Message-State: AKaTC02fLC99xSAIZEbNCjxcPI/CDR4uYGWjmdILPdyCqT8uhDxbdFu2AKSxFr6F5zPqfg== X-Received: by 10.28.105.194 with SMTP id z63mr2622977wmh.78.1481636473802; Tue, 13 Dec 2016 05:41:13 -0800 (PST) Received: from lmenx29w.st.com. ([80.215.199.148]) by smtp.gmail.com with ESMTPSA id vr9sm62269846wjc.35.2016.12.13.05.41.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 13 Dec 2016 05:41:13 -0800 (PST) From: M'boumba Cedric Madianga To: vinod.koul@intel.com, robh+dt@kernel.org, mark.rutland@arm.com, mcoquelin.stm32@gmail.com, alexandre.torgue@st.com, dan.j.williams@intel.com, dmaengine@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Cc: M'boumba Cedric Madianga Subject: [PATCH 6/9] dmaengine: stm32-dma: Fix residue computation issue in cyclic mode Date: Tue, 13 Dec 2016 14:40:48 +0100 Message-Id: <1481636451-27863-7-git-send-email-cedric.madianga@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1481636451-27863-1-git-send-email-cedric.madianga@gmail.com> References: <1481636451-27863-1-git-send-email-cedric.madianga@gmail.com> Sender: dmaengine-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dmaengine@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch resolves the residue computation issue detected in cyclic mode. Now, in cyclic mode, we increment next_sg variable as soon as a period is transferred instead of after pushing a new sg request. Then, we take into account that after transferring a complete buffer, the next_sg variable is equal to 0. Signed-off-by: M'boumba Cedric Madianga Reviewed-by: Ludovic BARRE --- drivers/dma/stm32-dma.c | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/drivers/dma/stm32-dma.c b/drivers/dma/stm32-dma.c index adb846c..ba929a9 100644 --- a/drivers/dma/stm32-dma.c +++ b/drivers/dma/stm32-dma.c @@ -500,8 +500,6 @@ static void stm32_dma_configure_next_sg(struct stm32_dma_chan *chan) dev_dbg(chan2dev(chan), "CT=0 <=> SM1AR: 0x%08x\n", stm32_dma_read(dmadev, STM32_DMA_SM1AR(id))); } - - chan->next_sg++; } } @@ -510,6 +508,7 @@ static void stm32_dma_handle_chan_done(struct stm32_dma_chan *chan) if (chan->desc) { if (chan->desc->cyclic) { vchan_cyclic_callback(&chan->desc->vdesc); + chan->next_sg++; stm32_dma_configure_next_sg(chan); } else { chan->busy = false; @@ -846,26 +845,40 @@ static struct dma_async_tx_descriptor *stm32_dma_prep_dma_memcpy( return vchan_tx_prep(&chan->vchan, &desc->vdesc, flags); } +static u32 stm32_dma_get_remaining_bytes(struct stm32_dma_chan *chan) +{ + u32 dma_scr, width, ndtr; + struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan); + + dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id)); + width = STM32_DMA_SCR_PSIZE_GET(dma_scr); + ndtr = stm32_dma_read(dmadev, STM32_DMA_SNDTR(chan->id)); + + return ndtr << width; +} + static size_t stm32_dma_desc_residue(struct stm32_dma_chan *chan, struct stm32_dma_desc *desc, u32 next_sg) { - struct stm32_dma_device *dmadev = stm32_dma_get_dev(chan); - u32 dma_scr, width, residue, count; + u32 residue = 0; int i; - residue = 0; + /* + * In cyclic mode, for the last period, residue = remaining bytes from + * NDTR + */ + if (chan->desc->cyclic && next_sg == 0) + return stm32_dma_get_remaining_bytes(chan); + /* + * For all other periods in cyclic mode, and in sg mode, + * residue = remaining bytes from NDTR + remaining periods/sg to be + * transferred + */ for (i = next_sg; i < desc->num_sgs; i++) residue += desc->sg_req[i].len; - - if (next_sg != 0) { - dma_scr = stm32_dma_read(dmadev, STM32_DMA_SCR(chan->id)); - width = STM32_DMA_SCR_PSIZE_GET(dma_scr); - count = stm32_dma_read(dmadev, STM32_DMA_SNDTR(chan->id)); - - residue += count << width; - } + residue += stm32_dma_get_remaining_bytes(chan); return residue; }