From patchwork Fri Sep 7 06:24:56 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Merello X-Patchwork-Id: 10591703 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 09D8B139B for ; Fri, 7 Sep 2018 06:25:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EAE4E2AD88 for ; Fri, 7 Sep 2018 06:25:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE63E2AD97; Fri, 7 Sep 2018 06:25:48 +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_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham 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 692D82AD88 for ; Fri, 7 Sep 2018 06:25:48 +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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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:In-Reply-To: References:List-Owner; bh=LCSyadM4IAEmfLI3345BFW8QH/XaqmOiLNStpjkGX4Y=; b=gtN Ts3cUUK76t2WBs01Q2VZiPnEn+8ANumczmXNg54Cj0hMi+BhLhQ4fqe4/TpfqOVY667QGdDsosnfM wWpm9eOW5hIOXNDhqTCrLAKtVEAQxKJiA2PT60VmZLB2qLWlhM8bTvgCWg+womPBh85ff6K6djO4V Gkg8EDwqHtpfuFTk91ITpxiYO2Z+sATwICj8sOBs4LSqGE0SjymzF/zQgzsIcPLsLZeZT9iN6a5l4 Unf22MOmk7l71rGYjBBmiNI+05nJK7/5PKO3YosLiTKzqZkEEGZiJqdZBBvkQSP7otVxYRUp9lmf7 2pPGczpZl5t2X4zespcv1ZT6pNaIrBw==; 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 1fyAD2-0002cB-Cb; Fri, 07 Sep 2018 06:25:36 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fyACx-0001zk-VD for linux-arm-kernel@lists.infradead.org; Fri, 07 Sep 2018 06:25:33 +0000 Received: by mail-wr1-x442.google.com with SMTP id g33-v6so13754263wrd.1 for ; Thu, 06 Sep 2018 23:25:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=Fo4uTu35nfqETk1eWWm0rsB3UI2a2lLeir3RiOJ544s=; b=LFlx4YzX5Ya7qjOtnIVcTKcznS6oeSSl96/9Eol2DoVDZV4tfaciINHpN5I28FWHp5 FG+kdQfb8vZtSonZm3U4no34XsHQOlhf4Y9GmoBSPYK8ekVWtjiHQzdvJSlxEPt/8U+g zxEH+zMHN6dGDO3DcgmSh83wEbx+CUSvQgO8+277LyiMTom+cSSwCZXPvI73+fMFG+7N dXQ+EGHqUX5PQrpDh7Eh2X+v7NhTKJ/FgDZw7ssdxbxRVuDDsevkauPGWdHAN5ZE2YfC lgL1CiEcDuf2esZnwYcvGdzEtx/U/5gBnlbNVOW1zuwKXbdKJUNsosBpSIAJeJ+LCY0D kDyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=Fo4uTu35nfqETk1eWWm0rsB3UI2a2lLeir3RiOJ544s=; b=k0yASDF/y16mFoNseNBKD/nKBw//qV/C7mEKwFEG/U5ho7/IbIG69oRw3GLGr5x65R d/Yub6qVpotWokEdPvKY6tDla+/emUsMRIAucQhC4sjOl2d/S34kEw9C3YXyG89j/E8G PdzgkzgwxvrdH1eHrgtgpaIoUC1SMRI6LbbW1DRK4GFXLsvrUPMg54zY10MdcjXipXJD 6ESdi5XPB1df9OTW1UDdnqKvT5WHVvPumbfWjS7Uvs+htAPOqfBGaHgS4oS5Y5Zv1scZ YLy5wzw1B95F0GvFV3N9cDvwm0RzJ3aJJkMIhoTjHBaCh0RLsWOZiARR1ezDEPt1RJrW 7O4Q== X-Gm-Message-State: APzg51Amvddu7yHN3M5k5MiZnqqAtdQfn0AmIQClZAFYbtcQml+X0Yr+ YbGnBjj8mm1+p03oadP7lK0= X-Google-Smtp-Source: ANB0VdYTWL2yOchrIoG9vcULbX7veGh8LNTcSKTcf8Y3FzjiOgnNtos3Ep7jw0Hit8PVEqHbLRL7HA== X-Received: by 2002:adf:a3d9:: with SMTP id m25-v6mr4974145wrb.1.1536301519078; Thu, 06 Sep 2018 23:25:19 -0700 (PDT) Received: from NewMoon.iit.local ([90.147.180.254]) by smtp.gmail.com with ESMTPSA id w10-v6sm8387233wrp.31.2018.09.06.23.25.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 23:25:18 -0700 (PDT) From: Andrea Merello To: vkoul@kernel.org, dan.j.williams@intel.com, michal.simek@xilinx.com, appana.durga.rao@xilinx.com, dmaengine@vger.kernel.org Subject: [PATCH v5 1/7] dmaengine: xilinx_dma: commonize DMA copy size calculation Date: Fri, 7 Sep 2018 08:24:56 +0200 Message-Id: <20180907062502.8241-1-andrea.merello@gmail.com> X-Mailer: git-send-email 2.17.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180906_232532_013787_706F7453 X-CRM114-Status: GOOD ( 14.15 ) 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: mark.rutland@arm.com, devicetree@vger.kernel.org, Andrea Merello , radhey.shyam.pandey@xilinx.com, linux-kernel@vger.kernel.org, robh+dt@kernel.org, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 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 removes a bit of duplicated code by introducing a new function that implements calculations for DMA copy size. Suggested-by: Vinod Koul Signed-off-by: Andrea Merello --- Changes in v4: - introduce this patch in the patch series Changes in v5: None --- drivers/dma/xilinx/xilinx_dma.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/drivers/dma/xilinx/xilinx_dma.c b/drivers/dma/xilinx/xilinx_dma.c index 27b523530c4a..a3aaa0e34cc7 100644 --- a/drivers/dma/xilinx/xilinx_dma.c +++ b/drivers/dma/xilinx/xilinx_dma.c @@ -952,6 +952,19 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan) return 0; } +/** + * xilinx_dma_calc_copysize - Calculate the amount of data to copy + * @size: Total data that needs to be copied + * @done: Amount of data that has been already copied + * + * Return: Amount of data that has to be copied + */ +static int xilinx_dma_calc_copysize(int size, int done) +{ + return min_t(size_t, size - done, + XILINX_DMA_MAX_TRANS_LEN); +} + /** * xilinx_dma_tx_status - Get DMA transaction status * @dchan: DMA channel @@ -1791,8 +1804,8 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_slave_sg( * Calculate the maximum number of bytes to transfer, * making sure it is less than the hw limit */ - copy = min_t(size_t, sg_dma_len(sg) - sg_used, - XILINX_DMA_MAX_TRANS_LEN); + copy = xilinx_dma_calc_copysize(sg_dma_len(sg), + sg_used); hw = &segment->hw; /* Fill in the descriptor */ @@ -1896,8 +1909,7 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_dma_cyclic( * Calculate the maximum number of bytes to transfer, * making sure it is less than the hw limit */ - copy = min_t(size_t, period_len - sg_used, - XILINX_DMA_MAX_TRANS_LEN); + copy = xilinx_dma_calc_copysize(period_len, sg_used); hw = &segment->hw; xilinx_axidma_buf(chan, hw, buf_addr, sg_used, period_len * i);