Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp6797678imm; Tue, 28 Aug 2018 00:54:10 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZpKzyS6/ORPsQABe8BsNP7JIqIwteXqExc7z4AwBqD6+qaapYiAL55WWDnx7kSC+RttFts X-Received: by 2002:a62:cac5:: with SMTP id y66-v6mr340749pfk.187.1535442850337; Tue, 28 Aug 2018 00:54:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535442850; cv=none; d=google.com; s=arc-20160816; b=SThqPPW8ifWS2PRKP5oqU+S0dTsOxmUhRa8Z61BfD1QSsSTkhHR0PvES747/6s77UD AdLPVdmvCYeqWdcWdPAt84bCXxSv7/eCHxt60fvfcO2k8fpT4QYMZ7Ez6dM2tIHMiAcN paQSqWhULOHjRb4Bqg3q3K+XRloteDt7+LQl66LzCa79IRcLGGvZfZnHP2jbSCnTLFCl pxwGUrZWw1DiyWTgA8wAw9fqWKDf3P3WocfJMRJT/hkEIzvhRecRON0eEdjrjFZhKYJh 80lSGfXJPXOHYDC9mn/wtZGlx9EQX/EkghxGfoC2/w/rXLXVxzX94VMp9f+2dm8olvu9 EApw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:organization:from:references:cc:to:subject :arc-authentication-results; bh=1U/quSGzGUg2TPFQ1BitxA6AzapfKH4QAkpgJTGO9HA=; b=R6HVVefKkNmeejdJh2HUIWErf7aWdC//Z/Nnldds5sGst0gDND1aya2YUIAFHKO66k 38QLfK7/+LPPs6gHw0nSHDZ7LrOMFMdLN7hl7Zad2s49z5OMqXGeoe5X4Cr8xDU8+irQ ZMxhVVwgxT9pdqEbz3jlnyAJnKwuOD+DUExC378z3TFBx/gUVKT+23498Hym5jm5pL2x jAIrUAoxT4CHEBVJRADe9iA/wcTga8K1vzb/8+peIwLM8PmjzWST00ToCCdFCroShDmc 4bz9cAaaDGHUa5iEwfOqI5jp9tWLmYd0FDCGuw4lrJ9hVCbtJ5w5RUkuZ7y2j3a+UzE8 XddA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id y1-v6si398125pgf.146.2018.08.28.00.53.53; Tue, 28 Aug 2018 00:54:10 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727195AbeH1LnM (ORCPT + 99 others); Tue, 28 Aug 2018 07:43:12 -0400 Received: from mga11.intel.com ([192.55.52.93]:42515 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726567AbeH1LnM (ORCPT ); Tue, 28 Aug 2018 07:43:12 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga102.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 28 Aug 2018 00:52:47 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,298,1531810800"; d="scan'208";a="66534065" Received: from ahunter-desktop.fi.intel.com (HELO [10.237.72.137]) ([10.237.72.137]) by fmsmga008.fm.intel.com with ESMTP; 28 Aug 2018 00:52:46 -0700 Subject: Re: [PATCH v5 3/3] mmc: sdhci-of-dwcmshc: solve 128MB DMA boundary limitation To: Jisheng Zhang , Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20180827162026.3901de27@xhacker.debian> <20180827162419.61afe238@xhacker.debian> From: Adrian Hunter Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Message-ID: <9739a083-cb2f-1cba-19c1-1c4e0d03eedd@intel.com> Date: Tue, 28 Aug 2018 10:51:02 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.9.1 MIME-Version: 1.0 In-Reply-To: <20180827162419.61afe238@xhacker.debian> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 27/08/18 11:24, Jisheng Zhang wrote: > When using DMA, if the DMA addr spans 128MB boundary, we have to split > the DMA transfer into two so that each one doesn't exceed the boundary. > > Signed-off-by: Jisheng Zhang > --- > drivers/mmc/host/sdhci-of-dwcmshc.c | 41 +++++++++++++++++++++++++++++ > 1 file changed, 41 insertions(+) > > diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c > index 1b7cd144fb01..cfbdae8703a1 100644 > --- a/drivers/mmc/host/sdhci-of-dwcmshc.c > +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c > @@ -8,21 +8,50 @@ > */ > > #include > +#include > #include > #include > +#include > > #include "sdhci-pltfm.h" > > +#define BOUNDARY_OK(addr, len) \ > + ((addr | (SZ_128M - 1)) == ((addr + len - 1) | (SZ_128M - 1))) > + > struct dwcmshc_priv { > struct clk *bus_clk; > }; > > +/* > + * If DMA addr spans 128MB boundary, we split the DMA transfer into two > + * so that each DMA transfer doesn't exceed the boundary. > + */ > +static void dwcmshc_adma_write_desc(struct sdhci_host *host, void **desc, > + dma_addr_t addr, int len, unsigned int cmd) > +{ > + int tmplen, offset; > + > + if (likely(!len || BOUNDARY_OK(addr, len))) { > + sdhci_adma_write_desc(host, desc, addr, len, cmd); > + return; > + } > + > + offset = addr & (SZ_128M - 1); > + tmplen = SZ_128M - offset; > + sdhci_adma_write_desc(host, desc, addr, tmplen, cmd); > + > + addr += tmplen; > + len -= tmplen; > + sdhci_adma_write_desc(host, desc, addr, len, cmd); > +} > + > static const struct sdhci_ops sdhci_dwcmshc_ops = { > .set_clock = sdhci_set_clock, > .set_bus_width = sdhci_set_bus_width, > .set_uhs_signaling = sdhci_set_uhs_signaling, > .get_max_clock = sdhci_pltfm_clk_get_max_clock, > .reset = sdhci_reset, > + .adma_write_desc = dwcmshc_adma_write_desc, > }; > > static const struct sdhci_pltfm_data sdhci_dwcmshc_pdata = { > @@ -36,12 +65,24 @@ static int dwcmshc_probe(struct platform_device *pdev) > struct sdhci_host *host; > struct dwcmshc_priv *priv; > int err; > + u32 extra; > > host = sdhci_pltfm_init(pdev, &sdhci_dwcmshc_pdata, > sizeof(struct dwcmshc_priv)); > if (IS_ERR(host)) > return PTR_ERR(host); > > + /* > + * The DMA table descriptor count is calculated as the maximum > + * number of segments times 2, to allow for an alignment > + * descriptor for each segment, plus 1 for a nop end descriptor, > + * plus extra number for cross 128M boundary handling. > + */ > + extra = DIV_ROUND_UP(totalram_pages, SZ_128M / PAGE_SIZE); The amount of RAM is not necessarily the same as the highest physical address. I think what you really want is max_pfn or max_possible_pfn > + if (extra > SDHCI_MAX_SEGS) > + extra = SDHCI_MAX_SEGS; > + host->adma_table_cnt += extra; > + > pltfm_host = sdhci_priv(host); > priv = sdhci_pltfm_priv(pltfm_host); > >