Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1944303imm; Thu, 21 Jun 2018 05:00:36 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLFPiQ8oVSudKg15qkvoixX3PuO0Tos7P+HMc5nb4Z+i5jtH3reNsMTFPt6t/tj2zqytt01 X-Received: by 2002:a62:f0d:: with SMTP id x13-v6mr27202498pfi.100.1529582436506; Thu, 21 Jun 2018 05:00:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529582436; cv=none; d=google.com; s=arc-20160816; b=hm+ue6zq0dYSwHU3zN3uPnXNs9dL2oyXdOdC4mV4w5+5QF5wJHP4SUGVYV1zCx0wkB B77mBT3TFc/P8vI65cFYkZXWiOdUGEXPsiWNkHD0dy67cTFqgHjeGdGwEXPaxuHkJ9wB rjGTFESODZzAEtCdu9LjlySlUQsXJ2l/10mjprCC0JQXrd+oH4JvrCxToloc6tPKuufA kN80mhqWTfaoqaqQFDORwvdG522NyzY6BEm5crf1ZRRtKhYxskW+E22EUqSyNPHekdfn CufISEGL7GbXU6N29xkysiD9qo3aoMePCONxrjgGFnTTFgTW3YDj5d/m5a6U8CpcB6yo eS3Q== 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=lI/z+yKhhFOkL1kzRd55CKW4Yhq8MBfhB4UVprsjI94=; b=kVOWQN/8NBeIb2e52r7uDypa+1rIcJmkFRnHkX0nBkGudFfSNU/l+HcmMNwWOTdiV+ yXOrYkxW+1BTUHw70p11no4JyOJ2DGEarMetIklE8dwvQ9zG1/1xsYlYgrU6R+DN4dVL VgQWiwJh8w2/CQnc13dFFvFopbwuDlgAuc6mNZcFZTxFzgrYkw2aF5fEXDhukxkNsFLF 2ZYeW2HQPc6/jvZkKtFttd6eD+2s7jgn8S5naufYjbl5USp6za/+eF1icmuL2WnRNPaU 4Ii4HmGsDZQlnBfgzE8FqBrpoM+z039EuDZpxGeY3AKfcBGX6wwHDZblNfOcMJrgNZSe rgPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=YYmqEaKl; 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 t19-v6si3787334pgb.196.2018.06.21.05.00.21; Thu, 21 Jun 2018 05:00:36 -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=YYmqEaKl; 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 S933270AbeFUL6c (ORCPT + 99 others); Thu, 21 Jun 2018 07:58:32 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:32768 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933130AbeFUL6a (ORCPT ); Thu, 21 Jun 2018 07:58:30 -0400 Received: by mail-wm0-f65.google.com with SMTP id z6-v6so2931949wma.0; Thu, 21 Jun 2018 04:58:30 -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=lI/z+yKhhFOkL1kzRd55CKW4Yhq8MBfhB4UVprsjI94=; b=YYmqEaKly5AfIHq25H010eo2FvAp4Pgxs4L1LsmAN/+w5MxNprV25rcoYuLUiflS5D wDrBLGqPNXBE5EJ15DtJRYJJoM8/EKD7ZInckd5KkmDo18YWLWUG7iwbKJo+P3BWK3ov rw8Sr2M3jXGhf5yrsRJEgQkESQms8hBjnKw7h2PnXrxSllr0incul+I6ALZxcY5whryh 75c5ihidy7FD20umPOkpW42+AG2sZVV6KpUNaTwq1/9kxEoP/F4UD71cJ06Pj0R4JyNh brvIvy1Uh3eRce6fDjcfErndwLmoesiEWoEQdG+pmwq2EiF6WrcGj50NZJ1etLQlYWNq ciUw== 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=lI/z+yKhhFOkL1kzRd55CKW4Yhq8MBfhB4UVprsjI94=; b=OZlpUTzLOzHi/s8n7eF5kgikqH7vXDROMZY5MaZn+sqHpHhhUwqNxQmEzz/vDwacre czvMxhhZO5M40mPepBKUtIy9lo/4i4xMV8I0cDeVP0VE0nyXlTAR6tYoj6S5Mcry1x9c dB+JKU8qnAONfIf7Lc3fWz1yhhnD0L2HrHKRQeJ5bu7fgjQuScxXjozxOce+iFhjwDB2 /0xaS35YvROwp/ItYFEpJA6Z39xnnM8B0SY/WCYSOjvtn9Gxr3ehnpbM1Z5dg4SbVGGM uFubKcHa43wxjEaBtZwCxVVdWb+AejD82fMyp5Z7YCyzO9D4rvK6e/l8152JtRSUPQXE gdGg== X-Gm-Message-State: APt69E0KiFpIIwFwPe3PATpL86me1OnxuvCTxU7rOm7RhvSRrvRXUvJt dU3kCy4oD/9lN5NsnsoxkiQ= X-Received: by 2002:a1c:9788:: with SMTP id z130-v6mr5136377wmd.88.1529582309584; Thu, 21 Jun 2018 04:58:29 -0700 (PDT) Received: from NewMoon.iit.local ([90.147.180.254]) by smtp.gmail.com with ESMTPSA id e188-v6sm13779773wmf.21.2018.06.21.04.58.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 21 Jun 2018 04:58:28 -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, Andrea Merello Subject: [PATCH v2 1/5] dmaengine: xilinx_dma: in axidma slave_sg and dma_cyclic mode align split descriptors Date: Thu, 21 Jun 2018 13:58:18 +0200 Message-Id: <20180621115822.20058-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 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. Signed-off-by: Andrea Merello --- Changes in v2: - don't introduce copy_mask field, rather rely on already-esistent copy_align field. Suggested by Radhey Shyam Pandey - reword title --- drivers/dma/xilinx/xilinx_dma.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/dma/xilinx/xilinx_dma.c b/drivers/dma/xilinx/xilinx_dma.c index 27b523530c4a..22d7a6b85e65 100644 --- a/drivers/dma/xilinx/xilinx_dma.c +++ b/drivers/dma/xilinx/xilinx_dma.c @@ -1789,10 +1789,15 @@ 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 + * making sure it is less than the hw limit and that + * the next chunck start address is aligned */ - copy = min_t(size_t, sg_dma_len(sg) - sg_used, - XILINX_DMA_MAX_TRANS_LEN); + copy = sg_dma_len(sg) - sg_used; + if (copy > XILINX_DMA_MAX_TRANS_LEN && + chan->xdev->common.copy_align) + copy = rounddown(XILINX_DMA_MAX_TRANS_LEN, + (1 << chan->xdev->common.copy_align)); + hw = &segment->hw; /* Fill in the descriptor */ @@ -1894,10 +1899,15 @@ 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 + * making sure it is less than the hw limit and that + * the next chunck start address is aligned */ - copy = min_t(size_t, period_len - sg_used, - XILINX_DMA_MAX_TRANS_LEN); + copy = period_len - sg_used; + if (copy > XILINX_DMA_MAX_TRANS_LEN && + chan->xdev->common.copy_align) + copy = rounddown(XILINX_DMA_MAX_TRANS_LEN, + (1 << chan->xdev->common.copy_align)); + hw = &segment->hw; xilinx_axidma_buf(chan, hw, buf_addr, sg_used, period_len * i); -- 2.17.1