Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1429757imm; Thu, 6 Sep 2018 23:28:29 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZ+hE41UWA47KWgme2xvumDKtYHS24ySB02xrXLJD6ZSvN5ww7GZGunWC43HnGA/n9YwpMQ X-Received: by 2002:a63:7058:: with SMTP id a24-v6mr6536901pgn.206.1536301709456; Thu, 06 Sep 2018 23:28:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1536301709; cv=none; d=google.com; s=arc-20160816; b=Sx97EYWzZ3W3pPD7NtEzl32Ia0XeelxAGwo7SrkZOG2AFo4DYJtsn7NANGtPJ02aUy qIM5sCiB2/B0vX64J/jkM5Y4+JrNIHQZ5zfq9UiC3QdoJGZOrlcQX/6Gu+0PSfp13S46 DmTUKIxYk3kbisH+eF8Wy6fcWSgUuHsn9AYId4UT6693fBDLVzZKIdKt20+wH60IvrL6 zJ/z/aUzwcp2aOYEoMKfHHvxw1LTn2BIvYTWoRREoMgDF8RBPAiRAN6500tSPV5JekOC OBABmSkgJgOX+0byZ40rU1zOuH5eh0hUJ3+t8b/jaQhqHerHqpMsja+jiVyH4Ooe8mcS oDIA== 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; bh=8e5h0rJlmTWn/SkUrpSaeFuxlSy8Y3IfyDjMz/ZKAYw=; b=sKrM8Kv5c0onQ4Dca98ItHTIM82jNJ5KCHfzhnGZl0Ex4EF2YaFiGxGqTGJEsZA8fI HuPJM+X1WLyl6xr5FUp7oKkDIe1Ii4SA38REXfRaFyN4Aqbk9V+Dk0EGVcSMnsIotRO3 XTdTpCirjze+pYmm0xbwj/cw+8yNmQaaJq/WxBeIgzPjd1bN3zMNFBf96GqzCewPjcgr AYw6iA2rhRvDImm888ObchSplklF5Q0RIulE6JrICivozTTtynrxtEWTuzrbHESnYiWq YOpyIUF0AJYU/3aEEE6ojW57ui8b3ERpHppeRREL9iCzz2eC5BtesjY3akChCiOO0a3A B97g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=Ng5Jwu9N; 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 5-v6si7517548pls.431.2018.09.06.23.28.14; Thu, 06 Sep 2018 23:28: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=Ng5Jwu9N; 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 S1727745AbeIGLFH (ORCPT + 99 others); Fri, 7 Sep 2018 07:05:07 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:36319 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725831AbeIGLEu (ORCPT ); Fri, 7 Sep 2018 07:04:50 -0400 Received: by mail-wm0-f66.google.com with SMTP id j192-v6so13474285wmj.1; Thu, 06 Sep 2018 23:25:26 -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=8e5h0rJlmTWn/SkUrpSaeFuxlSy8Y3IfyDjMz/ZKAYw=; b=Ng5Jwu9N9JfkQVZVIOspqsxdHiGoOcr8lWcab+Z54nfXsZspRvOc9MtuLgwF+Ph3Mc BCL+woL6YxvEJ1fY5bZ3WPG+PvQCkIUcheYuDPx98CUWaSi16hDoftnjWPvuSWdffWxh Icok83NAjXKo1cZhg6dz2yr/ocvzgQIoH/p9ENQWzycuziEdd8L3r5Ju7Al33OBTe6iK mHO99FyD2q9TOYO8HeFVarY/7VTWwMiXSWelR6Mp0e8hMMRMK6FIKQEAdp9s7qHB2JgX cxdqRu0ht2+kPPvMu7pKjonfPn5cNsR3Dw/6wdyB1NpPrHBWfYhXVGNkgUUyxPhKRNF5 xtcg== 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=8e5h0rJlmTWn/SkUrpSaeFuxlSy8Y3IfyDjMz/ZKAYw=; b=jcUKscAjnCAheaM3VReYqUhbo429/vq0KQZWeoKtyDsKDeHjCoTZKNvoWpJ+NwXOzg kvTp/SiMDyHGkxgptjaFwOxDblXk8M+USMa+XNDfdM+qt34OZ2zzASiM+FhX/mzkgYnZ i+7UpG24r1ek3vyleJ7TDwxlUJ16EU+C2wOU//I0HKcMzVHatCC3CJ25K2WMRi8p3pkl CrUkitwt87H+TvkeDLgDXPVoXMmcUdF8fPU5cNL8PgJCRYzSzyg0AGRjGK8PB0WQBXhC kEkFfVEm/UJVJ18U2AKmfyfn5E2cEpePkZI+9AGQg2Y/80H+sHUnXHzi4OYFScgSwJ5g viYw== X-Gm-Message-State: APzg51B6RjAxE/ZdDWh/zgBrzNM0fZVxlJIEP5fostrAy8fzJlYgyKYZ qS82cgvwEY+UySlFeLmqkGI= X-Received: by 2002:a1c:8682:: with SMTP id i124-v6mr4453038wmd.77.1536301522886; Thu, 06 Sep 2018 23:25:22 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 06 Sep 2018 23:25:22 -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 4/7] dmaengine: xilinx_dma: program hardware supported buffer length Date: Fri, 7 Sep 2018 08:24:59 +0200 Message-Id: <20180907062502.8241-4-andrea.merello@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180907062502.8241-1-andrea.merello@gmail.com> References: <20180907062502.8241-1-andrea.merello@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Radhey Shyam Pandey AXI-DMA IP supports configurable (c_sg_length_width) buffer length register width, hence read buffer length (xlnx,sg-length-width) DT property and ensure that driver doesn't program buffer length exceeding the supported limit. For VDMA and CDMA there is no change. Cc: Rob Herring Cc: Mark Rutland Cc: devicetree@vger.kernel.org Signed-off-by: Radhey Shyam Pandey Signed-off-by: Michal Simek Signed-off-by: Andrea Merello [rebase, reword] --- Changes in v2: - drop original patch and replace with the one in Xilinx tree Changes in v3: - cc DT maintainers/ML Changes in v4: - upper bound for the property should be 26, not 23 - add warn for width > 23 as per xilinx original patch - rework due to changes introduced in 1/6 Changes in v5: None --- drivers/dma/xilinx/xilinx_dma.c | 36 +++++++++++++++++++++++++-------- 1 file changed, 28 insertions(+), 8 deletions(-) diff --git a/drivers/dma/xilinx/xilinx_dma.c b/drivers/dma/xilinx/xilinx_dma.c index aaa6de8a70e4..b17f24e4ec35 100644 --- a/drivers/dma/xilinx/xilinx_dma.c +++ b/drivers/dma/xilinx/xilinx_dma.c @@ -158,7 +158,9 @@ #define XILINX_DMA_REG_BTT 0x28 /* AXI DMA Specific Masks/Bit fields */ -#define XILINX_DMA_MAX_TRANS_LEN GENMASK(22, 0) +#define XILINX_DMA_MAX_TRANS_LEN_MIN 8 +#define XILINX_DMA_MAX_TRANS_LEN_MAX 23 +#define XILINX_DMA_V2_MAX_TRANS_LEN_MAX 26 #define XILINX_DMA_CR_COALESCE_MAX GENMASK(23, 16) #define XILINX_DMA_CR_CYCLIC_BD_EN_MASK BIT(4) #define XILINX_DMA_CR_COALESCE_SHIFT 16 @@ -418,6 +420,7 @@ struct xilinx_dma_config { * @rxs_clk: DMA s2mm stream clock * @nr_channels: Number of channels DMA device supports * @chan_id: DMA channel identifier + * @max_buffer_len: Max buffer length */ struct xilinx_dma_device { void __iomem *regs; @@ -437,6 +440,7 @@ struct xilinx_dma_device { struct clk *rxs_clk; u32 nr_channels; u32 chan_id; + u32 max_buffer_len; }; /* Macros */ @@ -964,7 +968,7 @@ static int xilinx_dma_calc_copysize(struct xilinx_dma_chan *chan, int size, int done) { size_t copy = min_t(size_t, size - done, - XILINX_DMA_MAX_TRANS_LEN); + chan->xdev->max_buffer_len); if ((copy + done < size) && chan->xdev->common.copy_align) { @@ -1011,7 +1015,7 @@ static enum dma_status xilinx_dma_tx_status(struct dma_chan *dchan, list_for_each_entry(segment, &desc->segments, node) { hw = &segment->hw; residue += (hw->control - hw->status) & - XILINX_DMA_MAX_TRANS_LEN; + chan->xdev->max_buffer_len; } } spin_unlock_irqrestore(&chan->lock, flags); @@ -1263,7 +1267,7 @@ static void xilinx_cdma_start_transfer(struct xilinx_dma_chan *chan) /* Start the transfer */ dma_ctrl_write(chan, XILINX_DMA_REG_BTT, - hw->control & XILINX_DMA_MAX_TRANS_LEN); + hw->control & chan->xdev->max_buffer_len); } list_splice_tail_init(&chan->pending_list, &chan->active_list); @@ -1366,7 +1370,7 @@ static void xilinx_dma_start_transfer(struct xilinx_dma_chan *chan) /* Start the transfer */ dma_ctrl_write(chan, XILINX_DMA_REG_BTT, - hw->control & XILINX_DMA_MAX_TRANS_LEN); + hw->control & chan->xdev->max_buffer_len); } list_splice_tail_init(&chan->pending_list, &chan->active_list); @@ -1727,7 +1731,7 @@ xilinx_cdma_prep_memcpy(struct dma_chan *dchan, dma_addr_t dma_dst, struct xilinx_cdma_tx_segment *segment; struct xilinx_cdma_desc_hw *hw; - if (!len || len > XILINX_DMA_MAX_TRANS_LEN) + if (!len || len > chan->xdev->max_buffer_len) return NULL; desc = xilinx_dma_alloc_tx_descriptor(chan); @@ -2596,7 +2600,7 @@ static int xilinx_dma_probe(struct platform_device *pdev) struct xilinx_dma_device *xdev; struct device_node *child, *np = pdev->dev.of_node; struct resource *io; - u32 num_frames, addr_width; + u32 num_frames, addr_width, len_width; int i, err; /* Allocate and initialize the DMA engine structure */ @@ -2628,8 +2632,24 @@ static int xilinx_dma_probe(struct platform_device *pdev) /* Retrieve the DMA engine properties from the device tree */ xdev->has_sg = of_property_read_bool(node, "xlnx,include-sg"); - if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) + xdev->max_buffer_len = GENMASK(XILINX_DMA_MAX_TRANS_LEN_MAX - 1, 0); + + if (xdev->dma_config->dmatype == XDMA_TYPE_AXIDMA) { xdev->mcdma = of_property_read_bool(node, "xlnx,mcdma"); + if (!of_property_read_u32(node, "xlnx,sg-length-width", + &len_width)) { + if (len_width < XILINX_DMA_MAX_TRANS_LEN_MIN || + len_width > XILINX_DMA_V2_MAX_TRANS_LEN_MAX) { + dev_warn(xdev->dev, + "invalid xlnx,sg-length-width property value. Using default width\n"); + } else { + if (len_width > XILINX_DMA_MAX_TRANS_LEN_MAX) + dev_warn(xdev->dev, "Please ensure that IP supports buffer length > 23 bits\n"); + xdev->max_buffer_len = + GENMASK(len_width - 1, 0); + } + } + } if (xdev->dma_config->dmatype == XDMA_TYPE_VDMA) { err = of_property_read_u32(node, "xlnx,num-fstores", -- 2.17.1