Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp880533pxk; Thu, 17 Sep 2020 20:11:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxAE1qkMOiUYLunRW95Imqxa2SyWAGWayhozt1BAkfMDFj90b3OsJCoVcG6sT7a6zJOreqV X-Received: by 2002:a17:906:e88:: with SMTP id p8mr35696147ejf.134.1600398696835; Thu, 17 Sep 2020 20:11:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600398696; cv=none; d=google.com; s=arc-20160816; b=ZznCSoGftynd2GVGznxBa6ugSRsZ8Of+jEswR3uuws9ogGiUPMSgSGZNQfnGgSyrWc GF5P48qGnA1z2oIH+g3rCFm8UbpdkHIXUlJG1emVeiWN1NlK59WNr303ItP0WlWojXxy BMVeg2gyql5NwgplD9ev9ShnxAME6jfLSPc3/Z9zweGEebDxkMBjhuYECYs+xwddEAGv JUgaG0aCcpYszniniKCQ6jeUIeAgX7ZmXu2Ko+RoW+Xt/716HUrpHC2PSBwPguJYi+MP 9H2eYJuQCCGpawIH8icPgmRHm5WKb0tHfb5gEW/hb4e0ZtegKuIbGfG19Zv2fReaK8BF Zkyg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=DPY6shbE8NHb4N10WX05p4E3h/xo9ABIRuQBTHKSl44=; b=0nhD2r/SzL1lDovFa31NPPwftZJRbHynxBOpW47FDrlAwLbi33zOLYBkixbyvbXYzD W72sU+QDhIG8yTjucX9ORbCmf0Jv44ve/okgCaswKhJIxF36BbqrcpgHjtI8l7lCYNX0 xwqMlmvi95E8NFY8WnDWC0Iuqh4Hg3bxu5OweqCPjCeIvY9c/CYNuFEPZXZf3fYpfS10 /mdZd5+ZgTxHD3gpOP7dXklV7pznc9skb/PYEymbfwOlI7QSu5/jCFDlXrw0CsE7ZG1n PUXnaQDeRZyXhE7u/l5jkObTc0pDQximquYeL8NHHf0LNjaBJp/n87gF3LAqEuq4snH5 Co2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IfYIaZmT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t17si1545484ejs.91.2020.09.17.20.11.13; Thu, 17 Sep 2020 20:11:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IfYIaZmT; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726929AbgIRDJH (ORCPT + 99 others); Thu, 17 Sep 2020 23:09:07 -0400 Received: from mail.kernel.org ([198.145.29.99]:49082 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726983AbgIRCDK (ORCPT ); Thu, 17 Sep 2020 22:03:10 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 355DD235F9; Fri, 18 Sep 2020 02:03:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1600394590; bh=MnnWDFyrkqvG3zkn6qDUnnMZ34RE9hdHGsEeA+0Snow=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IfYIaZmTlqqE0gK5urk+oFW6pyAWbxFraGflfSPUrlqA8xBRJTw2WK7tGJz0sokBB cXhu2k6WDameBgHCr3saNGrmC7QjEfYxJQg7E7O9fsE/ERigPb9habp0qoizMmfmcF JHEcY2MUvcHN99q2HJMCX8uSinLCIkK+HJAKqhtQ= From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Matthias Fend , Vinod Koul , Sasha Levin , dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH AUTOSEL 5.4 098/330] dmaengine: zynqmp_dma: fix burst length configuration Date: Thu, 17 Sep 2020 21:57:18 -0400 Message-Id: <20200918020110.2063155-98-sashal@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200918020110.2063155-1-sashal@kernel.org> References: <20200918020110.2063155-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Matthias Fend [ Upstream commit cc88525ebffc757e00cc5a5d61da6271646c7f5f ] Since the dma engine expects the burst length register content as power of 2 value, the burst length needs to be converted first. Additionally add a burst length range check to avoid corrupting unrelated register bits. Signed-off-by: Matthias Fend Link: https://lore.kernel.org/r/20200115102249.24398-1-matthias.fend@wolfvision.net Signed-off-by: Vinod Koul Signed-off-by: Sasha Levin --- drivers/dma/xilinx/zynqmp_dma.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/dma/xilinx/zynqmp_dma.c b/drivers/dma/xilinx/zynqmp_dma.c index 9c845c07b107c..d47749a35863f 100644 --- a/drivers/dma/xilinx/zynqmp_dma.c +++ b/drivers/dma/xilinx/zynqmp_dma.c @@ -123,10 +123,12 @@ /* Max transfer size per descriptor */ #define ZYNQMP_DMA_MAX_TRANS_LEN 0x40000000 +/* Max burst lengths */ +#define ZYNQMP_DMA_MAX_DST_BURST_LEN 32768U +#define ZYNQMP_DMA_MAX_SRC_BURST_LEN 32768U + /* Reset values for data attributes */ #define ZYNQMP_DMA_AXCACHE_VAL 0xF -#define ZYNQMP_DMA_ARLEN_RST_VAL 0xF -#define ZYNQMP_DMA_AWLEN_RST_VAL 0xF #define ZYNQMP_DMA_SRC_ISSUE_RST_VAL 0x1F @@ -534,17 +536,19 @@ static void zynqmp_dma_handle_ovfl_int(struct zynqmp_dma_chan *chan, u32 status) static void zynqmp_dma_config(struct zynqmp_dma_chan *chan) { - u32 val; + u32 val, burst_val; val = readl(chan->regs + ZYNQMP_DMA_CTRL0); val |= ZYNQMP_DMA_POINT_TYPE_SG; writel(val, chan->regs + ZYNQMP_DMA_CTRL0); val = readl(chan->regs + ZYNQMP_DMA_DATA_ATTR); + burst_val = __ilog2_u32(chan->src_burst_len); val = (val & ~ZYNQMP_DMA_ARLEN) | - (chan->src_burst_len << ZYNQMP_DMA_ARLEN_OFST); + ((burst_val << ZYNQMP_DMA_ARLEN_OFST) & ZYNQMP_DMA_ARLEN); + burst_val = __ilog2_u32(chan->dst_burst_len); val = (val & ~ZYNQMP_DMA_AWLEN) | - (chan->dst_burst_len << ZYNQMP_DMA_AWLEN_OFST); + ((burst_val << ZYNQMP_DMA_AWLEN_OFST) & ZYNQMP_DMA_AWLEN); writel(val, chan->regs + ZYNQMP_DMA_DATA_ATTR); } @@ -560,8 +564,10 @@ static int zynqmp_dma_device_config(struct dma_chan *dchan, { struct zynqmp_dma_chan *chan = to_chan(dchan); - chan->src_burst_len = config->src_maxburst; - chan->dst_burst_len = config->dst_maxburst; + chan->src_burst_len = clamp(config->src_maxburst, 1U, + ZYNQMP_DMA_MAX_SRC_BURST_LEN); + chan->dst_burst_len = clamp(config->dst_maxburst, 1U, + ZYNQMP_DMA_MAX_DST_BURST_LEN); return 0; } @@ -887,8 +893,8 @@ static int zynqmp_dma_chan_probe(struct zynqmp_dma_device *zdev, return PTR_ERR(chan->regs); chan->bus_width = ZYNQMP_DMA_BUS_WIDTH_64; - chan->dst_burst_len = ZYNQMP_DMA_AWLEN_RST_VAL; - chan->src_burst_len = ZYNQMP_DMA_ARLEN_RST_VAL; + chan->dst_burst_len = ZYNQMP_DMA_MAX_DST_BURST_LEN; + chan->src_burst_len = ZYNQMP_DMA_MAX_SRC_BURST_LEN; err = of_property_read_u32(node, "xlnx,bus-width", &chan->bus_width); if (err < 0) { dev_err(&pdev->dev, "missing xlnx,bus-width property\n"); -- 2.25.1