Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2172295imm; Thu, 2 Aug 2018 07:21:41 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcFlYMZmB+WE/C3HZZnjjBt24sDenIrDg9ddBkyxq7g5D6aoKPFRr0bSYRk6tRcLuNGHJuF X-Received: by 2002:a17:902:8481:: with SMTP id c1-v6mr2571940plo.177.1533219701334; Thu, 02 Aug 2018 07:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533219701; cv=none; d=google.com; s=arc-20160816; b=MWIF9K2cqBF6WRSHJei64Hc2U/WYl8pFWOdZVphjG0jjvcETzwBpA/MhNa5H1iolz7 mou3utYlLdGmNY3ENtbSHqoBCFdFwt7Z+LrbTjSsffdChSB++upRzgDl76f2pPpNxUEG Qg2r8hSImc4aC1PJb6i6eS54kvthDeYfD40wHVAF1Mo0WATQbcpQ0sOZKQCCXHvrnFxC tKXlWlRxuAS4XMrn/OPhuaoS3R8Qv9aPIRaxgLEvuMmPxNk7gMfn6e67pnyKHwez7PsK WNOSHQ8Muggotk1f+HA2A9XC70+rKjmRq/D3W5Ed2plFGhE1ZRm2ErpYkTSHxhECmNIh INQQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=13UB+8MFeFfRAoIF7WXwnAp2DUzob6xSPX4RlR1oE4g=; b=Jsf5uUvyYcdLm8NXJck6TwxAeBkW5Xe9ovGuMoNNrAvKD352DOSJA00SrmsEmuAp+b 8Qs07efVGs023NSaYYwOh/BtyYRR1PUbuJLsYQLjV/gc30THxKYoNb+/GvCi8DSpI9k0 6jbXfTd42GYOxxEw7z7KWG1XpD3lN8Fc5i0T1yuHoyvl6ZRn+JC+UquQBWk8G65oAnaJ aimQytq+bKVO11DEPVWuINBLtAepr72eN4GcBGSU9CrccTzl1BjbqFH/lWhO44Dv83PZ gpU/I8pxq4FUPoYNXs0k/yE8JzNkWwWxU+WF8/QwK9h8jygSFoTJuTc4XE7e5X03E7lb LW9Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=iPMEKV+e; 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 d38-v6si1456751pla.422.2018.08.02.07.21.25; Thu, 02 Aug 2018 07:21:41 -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=iPMEKV+e; 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 S1732530AbeHBQBp (ORCPT + 99 others); Thu, 2 Aug 2018 12:01:45 -0400 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36673 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732231AbeHBQBo (ORCPT ); Thu, 2 Aug 2018 12:01:44 -0400 Received: by mail-wm0-f68.google.com with SMTP id w24-v6so2726349wmc.1; Thu, 02 Aug 2018 07:10:20 -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:in-reply-to:references; bh=13UB+8MFeFfRAoIF7WXwnAp2DUzob6xSPX4RlR1oE4g=; b=iPMEKV+e50KrFb96gOmYfO4cE2Y3nPDiPCQzQiDZ4QKZezHfltiWJj8BHT4WrdfNVP 8pTXNghF2FAFqOlwBZ7SLp35Mjc2U+79vUds6iv8qgIW9813/bNQe4ShOXIfMqLeN1y7 v2I11JdOSKw8t789Bq2TqDO+vo3PfVcXnEQya117fJUrDCX/JT9QDZ1gLnqtPQ8zUkXO 7UplD+Vb8n5ZOw3TvfoxxOTCnkYwK31fZKgRr7fAHvCGhoqDPzfUniDA8U3XBi/Ag68N e1qMT1Xo+U1d8/Wmo+75p3NCKcLH5R7Daf8Ex3EWHKPNl3m457DtDdUO5mLa8oWjR4cg FyJw== 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:in-reply-to :references; bh=13UB+8MFeFfRAoIF7WXwnAp2DUzob6xSPX4RlR1oE4g=; b=BAQIxEWO39kWMc1tfmkq9h/xPMrB/VrAejNuY3fnMvVubaOlHkMSHvtDpbUK0ePd0e f69lTqu9BAhMkGvOzzsTKFrfC4ZTEIEtfXheQQW+YjGaIosqq+7ZgMYTB6UPzBWyx6+9 hZxVvnqrWOeD67prDIkXEbo1dWeH1y2BGWhBYCOkdObaNk+TnOfEj/GyZ3opVFoEJW1D yRyTEUlVgMZNPibYGmFmSuxRrO9KsmL8Nds5VYWYTLLqujml/dVw0eJSyRzE7czmLIVJ /dPZVR/AjZn7K5hx/d1IMv/h8s2fiidkNK+Q0AdPxR7DbYR/hdbbqFklzC4FmX4m2CQo gicA== X-Gm-Message-State: AOUpUlGHJKOI24BO0hVjGx//isJKJDjxswy2Wa3wA/ugNBnKCYqQBctr ReixjXH5LStJBzZ70fNceDU= X-Received: by 2002:a1c:8414:: with SMTP id g20-v6mr2366880wmd.90.1533219019457; Thu, 02 Aug 2018 07:10:19 -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.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 02 Aug 2018 07:10: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: 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 2/7] dmaengine: xilinx_dma: in axidma slave_sg and dma_cylic mode align split descriptors Date: Thu, 2 Aug 2018 16:10:07 +0200 Message-Id: <20180802141012.19970-2-andrea.merello@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180802141012.19970-1-andrea.merello@gmail.com> References: <20180802141012.19970-1-andrea.merello@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Whenever a single or cyclic transaction is prepared, the driver could eventually split it over several SG descriptors in order to deal with the HW maximum transfer length. This could end up in DMA operations starting from a misaligned address. This seems fatal for the HW if DRE is not enabled. This patch eventually adjusts the transfer size in order to make sure all operations start from an aligned address. Cc: Radhey Shyam Pandey Signed-off-by: Andrea Merello Reviewed-by: Radhey Shyam Pandey --- Changes in v2: - don't introduce copy_mask field, rather rely on already-esistent copy_align field. Suggested by Radhey Shyam Pandey - reword title Changes in v3: - fix bug introduced in v2: wrong copy size when DRE is enabled - use implementation suggested by Radhey Shyam Pandey Changes in v4: - rework on the top of 1/6 --- drivers/dma/xilinx/xilinx_dma.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/drivers/dma/xilinx/xilinx_dma.c b/drivers/dma/xilinx/xilinx_dma.c index a3aaa0e34cc7..aaa6de8a70e4 100644 --- a/drivers/dma/xilinx/xilinx_dma.c +++ b/drivers/dma/xilinx/xilinx_dma.c @@ -954,15 +954,28 @@ static int xilinx_dma_alloc_chan_resources(struct dma_chan *dchan) /** * xilinx_dma_calc_copysize - Calculate the amount of data to copy + * @chan: Driver specific DMA channel * @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) +static int xilinx_dma_calc_copysize(struct xilinx_dma_chan *chan, + int size, int done) { - return min_t(size_t, size - done, + size_t copy = min_t(size_t, size - done, XILINX_DMA_MAX_TRANS_LEN); + + if ((copy + done < size) && + chan->xdev->common.copy_align) { + /* + * If this is not the last descriptor, make sure + * the next one will be properly aligned + */ + copy = rounddown(copy, + (1 << chan->xdev->common.copy_align)); + } + return copy; } /** @@ -1804,7 +1817,7 @@ 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 = xilinx_dma_calc_copysize(sg_dma_len(sg), + copy = xilinx_dma_calc_copysize(chan, sg_dma_len(sg), sg_used); hw = &segment->hw; @@ -1909,7 +1922,8 @@ 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 = xilinx_dma_calc_copysize(period_len, sg_used); + copy = xilinx_dma_calc_copysize(chan, + period_len, sg_used); hw = &segment->hw; xilinx_axidma_buf(chan, hw, buf_addr, sg_used, period_len * i); -- 2.17.1