Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp3664166imm; Mon, 25 Jun 2018 02:29:32 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLP8ZuWy79uVA/gjSaXVMEtA9Bg3J6XJ796elJJ5mBFDKQY7UiLIlsdku1v6I2z6JqGteRZ X-Received: by 2002:a62:701:: with SMTP id b1-v6mr12289872pfd.252.1529918972419; Mon, 25 Jun 2018 02:29:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529918972; cv=none; d=google.com; s=arc-20160816; b=B6N9BLEO3u1eIV/OZisqmC6AB7ODwV+grlBpsjbslhob57uVqP/+fjbZ1P54ExeNAg YR9eW7XH7bPp+zj7+HqFRYR9NCHCh8/fGpvSjGkYcpG5SbVk2dj/muEZHe7++/bCgHH9 LMx+dJ5mDZOqxWcljAV0kp2CMLc0rLdrnz77q1lUzwnsxzd+MmfDL5Z0UawPdh4HJprq TTdChtMioNQxNGGsxWRsS+6jCbG6+2bie116gTQjbAaWdrGmNTqO2hvS7cIn4Doi/uUF ISmGgNU6v/ty4UqvZWGRmin1ke+4MLSZUkuG2lktpAU4vQ+tAf+iZtxu+vwaaQBmNFj5 6T1w== 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=67rhiyFVzoKVQXTuifEiGRJEsSDBWmuXfM2BvfFlAMY=; b=CQXEpTfLa+m6spahHM/y6rG9tgem5QQdtQ+O4iTneaoeyCoqkfpmdf4HpfD7BKjRGs S5tTTbuHoNF7lzCs1/uxVE7LHYye5b3AVRCGfzgLV52rj5OChsKCVTMfg9hJ5g4BQwoz pTH8D9Q7eAaqxuIzOfsDCYCJM77m2uFxuleSLrTdGFhbJvPgvlx5Pd5XABG+eYLyNCw2 5Rw0R+VAyBd9H4JjEq8tLvUwbJHNtTa2zP2tOZflEWAcJBmucl9zwu+mS01+cRl4A//l 0QSZG+Gr+r/wDGXScoWIiA09NNWxPVpV5R6eTdFDB9q5NRUJOgKaYlQPEAgLWbwAekfC UFBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=dhl6y9+v; 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 p2-v6si13581120plr.494.2018.06.25.02.29.18; Mon, 25 Jun 2018 02:29:32 -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=dhl6y9+v; 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 S1754650AbeFYJ1v (ORCPT + 99 others); Mon, 25 Jun 2018 05:27:51 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:44912 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750919AbeFYJ1t (ORCPT ); Mon, 25 Jun 2018 05:27:49 -0400 Received: by mail-wr0-f193.google.com with SMTP id p12-v6so11265010wrn.11; Mon, 25 Jun 2018 02:27:48 -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=67rhiyFVzoKVQXTuifEiGRJEsSDBWmuXfM2BvfFlAMY=; b=dhl6y9+v+ycSfiUBxdNf416LexO1FtagKLWSYz/FgwWxbTaD3JRk0mDpOP0heFjpm9 +b3bnFN4pscTJYmixfYnM2e+Jm7m5C1mwGxrV620QGuUiJVlhVkEECRWwfSfh0km33A7 yYorPABnKZZ3RG8C2P2sfOVQyylVwsky0nz2x5UPDmz/+dhU9lQCW+uTxF6gZIi9iLvN wsWI6S0KuUy9q3I7mq9oAteeeaskSNnI6OmqnV84cofVzs95Dy5i1nFah6B5x6xGylkp yxzC3HfzEdcR3SkuBlzXykESDM9uTfQmt55hO4qtvUrFoctqMt6qGG6dqnU++8L0MIE5 Oq2A== 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=67rhiyFVzoKVQXTuifEiGRJEsSDBWmuXfM2BvfFlAMY=; b=g2ZJyTsH7a1u6ux04buofvyA1t2FRh/OwRno/N8OQNx1xKcGD+udH09VMRmKZNFyGK bqYr2leI7Dd/5Ji7KDXOAbUS4y0HclDBvfNo30i/T9Y7Xyne6+bMPsnWvjXNEYUuPklY UJPGRIfshg4DFY1qDaHB8AIYjqO/eCRl2tEr5Zihb7zpaqhKwl2E6YpGxYpOHvQIojtz fX4laN7ahMwRagqohX9URxOt+LKEX+mYTbrmTclTfYL2D27+8NmpdIl5ut3zGQMUrRjB 9YBw1jiq1sSXZTg8DqjZQwWlOE7VjQSTsyazlTlwsw/JfkfybAyfieWJ2O4ccMlnWCTJ lw6Q== X-Gm-Message-State: APt69E0f7VfSsjZej4yNOd9hflNvUPZb32wQ0QZTD01PaCLjFBdb72Nv Uwy6o3dxLRaGIObzHR5yMqM= X-Received: by 2002:a5d:41c5:: with SMTP id e5-v6mr3256028wrq.25.1529918868222; Mon, 25 Jun 2018 02:27:48 -0700 (PDT) Received: from NewMoon.iit.local ([90.147.180.254]) by smtp.gmail.com with ESMTPSA id v2-v6sm15638779wrm.84.2018.06.25.02.27.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 25 Jun 2018 02:27:47 -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 , Radhey Shyam Pandey Subject: [PATCH v3 1/5] dmaengine: xilinx_dma: in axidma slave_sg and dma_cylic mode align split descriptors Date: Mon, 25 Jun 2018 11:27:20 +0200 Message-Id: <20180625092724.22164-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. 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 --- drivers/dma/xilinx/xilinx_dma.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/drivers/dma/xilinx/xilinx_dma.c b/drivers/dma/xilinx/xilinx_dma.c index 27b523530c4a..113d9bf1b6a1 100644 --- a/drivers/dma/xilinx/xilinx_dma.c +++ b/drivers/dma/xilinx/xilinx_dma.c @@ -1793,6 +1793,16 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_slave_sg( */ copy = min_t(size_t, sg_dma_len(sg) - sg_used, XILINX_DMA_MAX_TRANS_LEN); + + if ((copy + sg_used < sg_dma_len(sg)) && + 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)); + } hw = &segment->hw; /* Fill in the descriptor */ @@ -1898,6 +1908,16 @@ static struct dma_async_tx_descriptor *xilinx_dma_prep_dma_cyclic( */ copy = min_t(size_t, period_len - sg_used, XILINX_DMA_MAX_TRANS_LEN); + + if ((copy + sg_used < period_len) && + 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)); + } hw = &segment->hw; xilinx_axidma_buf(chan, hw, buf_addr, sg_used, period_len * i); -- 2.17.1