Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1428441imm; Thu, 6 Sep 2018 23:26:50 -0700 (PDT) X-Google-Smtp-Source: ANB0Vdbu6wXP6KAD81k3lrx1dQe40Dt4ynI4tI5wnm3JYJtN/4fTydYqQHBATDeNUG33P6FQ2xRv X-Received: by 2002:a63:6243:: with SMTP id w64-v6mr6705987pgb.145.1536301610610; Thu, 06 Sep 2018 23:26:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536301610; cv=none; d=google.com; s=arc-20160816; b=nil5V4LIciw4SyF0BQQjuqnyZBgJdD98Vw5uZdSh667a1N82D1Wc3xgExkuSR4+j7x Hxt8atx0JKPuuaIcVQGb+hBENSVhqE+K1uZKAp8CvPcWAlXV2tjERf+6fm05S1Uz451E QUvUKjHzdAOTuEqBkoQXsdmZ6PnrH5al0Ev/4qd3U/FHcS7NHobVChqFDSYjt4pFpEhC 63XHEU0LGPSK/hkPXbD9iW3jOxYd5Z+5AcwA8Q+Ukfvwce9cT/yrQ3asrhWo4F3FaIMN WIpB2IzcdYhZk1jYTf+NPfRNn4sws8rXz/OPY34wMcB4bcO/b98skqWUg+anXCYHCWTY qacA== 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; bh=Fo4uTu35nfqETk1eWWm0rsB3UI2a2lLeir3RiOJ544s=; b=Esh6s4lFjOVcshX842UjQIZO3g0UqDpA8g0sA5FYmRRdn/RwTW2WIFQlyuBB0iEnBT QxbQKXgRs+hJAYvL2UjJhM3VF20P/dDRb8CMUZfbnZKeha3Gm/lIgs7CVest4ijQP5rR ZxAwWOTO6ZtFr5RKnzDmoHVDhlCbA7ShKwLOEmjG6SiAzqBNEi/BzhhCSjYxkU9uFdQa GRjx35LDejS0wHczPOjnQMW4KJ7IWkeUznOWxIkteZhVQqudhtgf9IXtAFJlL5UC1yw+ Zfft5el3amsix5UhLqhYR68/FJcyP9F/w83pU1zvIZFVlQ9s1OTJXWUwT6SJrO3vj2NS T1BA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LFlx4YzX; 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 v18-v6si7334656pgl.171.2018.09.06.23.26.34; Thu, 06 Sep 2018 23:26:50 -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=LFlx4YzX; 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 S1726738AbeIGLEn (ORCPT + 99 others); Fri, 7 Sep 2018 07:04:43 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:36017 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725831AbeIGLEn (ORCPT ); Fri, 7 Sep 2018 07:04:43 -0400 Received: by mail-wr1-f68.google.com with SMTP id e1-v6so4659383wrt.3; Thu, 06 Sep 2018 23:25:19 -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=lG+kZoVIAFw3ZatCQOchiOrT7t92BpYEHQOvdefnZuPzpL0yclmRaDrlbeL2lbagxb ROu3HO4RWHNxZbEakUoxtvxQHRzFef5+iA1zHteWzA3flDHSgJh4QW018xd6U9MxVN6v 7NBbYPWYFCtYcrk2ogII6DZY5x0fDA9eE4pkN0vW5olANbPZtXKQmLIGbV7pV5dVWt1V 8JTYFlhZb9vZw6nRlka9ad0Z815Fmw3rdB0/dxWPa45XOMcbx56+oXu0nbbKpcMH7xzc 37zB7/K7l1BaDRlVDJrtjwNSbu8E5WvDeJhr9yXmOhzLwQGlJxdjfq7NYKUdmLfbQm8K cCsw== X-Gm-Message-State: APzg51ATqQUZBxQHlEsR8yzNSEw7STZH+Pse8fOb4yAb/UJrsjHRwhK0 OSlHM8gSmg2Irpf15Cl8vdk= 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 Cc: linux-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 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 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 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); -- 2.17.1