Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2160240imm; Thu, 2 Aug 2018 07:11:29 -0700 (PDT) X-Google-Smtp-Source: AAOMgpco7PfMTmp8218DxGcvNnRTpBh/ErekSxwbdayoGMCxapb837GnFHkwAP9WMQvW3tagDejc X-Received: by 2002:a17:902:d807:: with SMTP id a7-v6mr361548plz.3.1533219089423; Thu, 02 Aug 2018 07:11:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533219089; cv=none; d=google.com; s=arc-20160816; b=JA0t9JpL9mloqVynCB2M1ly4JuJS1KQN1bFdr+VJfYa+aVME89Bvx1S7LAHhv4461S GiViX0jdddlK1PIv+NxUD/yb9cP2KDzwUSeoqYscwjXi4Mh2Zl5o2rbjSKyx4+idCSr2 vCcRSZajsM1i2Y7Wx2nva0ri3qMB84i0xDuSbsb6jrENn3yG7IQsnr/mmKysEjR2gD1A Fg5amHZ4SrltEv5olJMYZzTUvdspHlXBGCMp5r9zYs1JJ7LhF5D5hud4JfOasChCNc9K Wny7xgXbTkg0IpBBYH9zcXhFaaWpyj2vyBGdzpnq2BY0hInhvd5WDeBPu+SR076lutKv H6mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=NPisTIUxEJWllPtVLNR+w7rnRDOVuscZpqNlMO4PTg8=; b=TipBFoCTyRUTmLW5OHLeJw6sf0fAAVGTW+wbBFZO64j3hnm4IJeNSRxpdVq68UAdiD dq/HadNoY1pZSUG1C9Rf8hss18xpZ4yL9Zo7oi6icfSgZqn1lXtbDjWQ4Coc6o4n0qsG cvLcTKWoIzuAaK6+Bix30yea6tcdmkmGEwtOrmOGpJ+nx38PGp3GBtjII6aKtOqg6qcp 4VyVSB2X6q1kXmwRl9RhI2cUK/MOFMCQ93HFUqtbQmHkN2v9uZaYPgzicbe5RC4AZ42y fjaf2J8pVv5DId/Vu6AMuj0FEDAX1ihWbbqx6I6feRALMknfIiUIHLMIRjM96vbOzxAo aUhw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qVQHkycN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l59-v6si1323497plb.519.2018.08.02.07.11.14; Thu, 02 Aug 2018 07:11:29 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=qVQHkycN; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732468AbeHBQBm (ORCPT + 99 others); Thu, 2 Aug 2018 12:01:42 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:36732 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732141AbeHBQBm (ORCPT ); Thu, 2 Aug 2018 12:01:42 -0400 Received: by mail-wr1-f66.google.com with SMTP id h9-v6so2299429wro.3; Thu, 02 Aug 2018 07:10:18 -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=NPisTIUxEJWllPtVLNR+w7rnRDOVuscZpqNlMO4PTg8=; b=qVQHkycNLclULwTXiDeJPxKYdPwDoM0UCfDyc2FdD0++BxTwl3kSb0MOnH3uMV4qdb qKSg4R4VcVDls2VmQa17AB0GIPU4kR0WnMIHsrILlUejoJtzWE7DpbJtmvJKWPpuhNgD NZvBx4xIM5oPTXPzV7A0+RGCTBOrEcbh6+w8XleP2HpUi+iA7T8VOv8DmZWLlSmR5fm+ p2sI7LkpQBEuKX5SzcbcLIBwwEYY+wEOPczGVpF5fePlrEB2ryXoTIQnivUT/KeevhMy U+MBnFD6S8HA8AuEPfDy/JeRmB+HG4jvn2Dhj7VyczHejMAjIMnMeynJK18PRFtVau23 zWzg== 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=NPisTIUxEJWllPtVLNR+w7rnRDOVuscZpqNlMO4PTg8=; b=CEE6lv0Bfoa3QsIHRiZwyH66WG8jk26tnBdYmtfWgdVIN47LgL0YPQpTk3wRsh2SUs U2NPocMlmsQAebH1lpi0zYvBNKeuP6Crqrqy71z4EwYL5HfQDRzvEbo9lMo08nObFA14 RTq5ZPBQnQuOB4Yi1EHYCWP8XJGeB4/3O0zlJciUiStdXZcABjt41bUGLKMuCMXb3PAa eSyAFfgPsHgb5jSl89i8C8tgH05IeM7g7oxTc1VRHK2wSdTW+nW0pPL58xwIv4zRFzTP POZgue0apKmPof/8VVNsIY3P2kZyVj6XuzVSijPYDRbScIBHGgTsZ8TVF/I20EzbcQoz VA+w== X-Gm-Message-State: AOUpUlE8DTwYYBvZYk6T/ZKh6DcerPGs+vrvY+Y0LurvAbInbSOyTp2w TEzdDHqB6qJykJZyRbgTYiQ= X-Received: by 2002:adf:bc03:: with SMTP id s3-v6mr2262503wrg.211.1533219018243; Thu, 02 Aug 2018 07:10:18 -0700 (PDT) Received: from NewMoon.iit.local ([90.147.180.254]) by smtp.gmail.com with ESMTPSA id d78-v6sm3392310wma.37.2018.08.02.07.10.17 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Aug 2018 07:10:17 -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 Cc: v4-000linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, devicetree@vger.kernel.org, radhey.shyam.pandey@xilinx.com, Andrea Merello Subject: [PATCH v4 1/7] dmaengine: xilinx_dma: commonize DMA copy size calculation Date: Thu, 2 Aug 2018 16:10:06 +0200 Message-Id: <20180802141012.19970-1-andrea.merello@gmail.com> X-Mailer: git-send-email 2.17.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 --- 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); -- 2.17.1