Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1822380imm; Thu, 23 Aug 2018 09:17:30 -0700 (PDT) X-Google-Smtp-Source: AA+uWPyZ2deAZmMOPUX8myv4yYsz6SkDk0DKBpgIvi241I2HzZOv+wEXBTcmYkbbIU+7pLoCBQTG X-Received: by 2002:a17:902:6946:: with SMTP id k6-v6mr59481300plt.268.1535041050264; Thu, 23 Aug 2018 09:17:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535041050; cv=none; d=google.com; s=arc-20160816; b=gJP4zNj/jYHNFGQSGlL5C+VDRR2uoIBCd5TvpkAbmNpn/ig5ZpXyT4Lhw0wJ7RXdfs t8iEsUxqXZ7ChwAKDd/y7ZD4vcYaKQXVgK4iF5MBz3r3uNudnoyWBr9qCoEubX5YCfZo Hhv4EKylIfGz30TcA/m6juu3ZrjrcnR8kQDylm4wEa1anTvJrUj3OCkVOZlr4UjQBoqE wUMt25uj3AA2i5vqmSqshTkdY4yOlsYxbToTb2P4MMcW2zu+TR1y//JkLqWlJr3Ovr5x DlYWmSzQ6MrOzQVB9GUITrNCqMfs73qPfy0pp0xvZ/pYoiJ6e+cSEBgyPKD+RiSXzUED KJmw== 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=ccPh2Vut0S/o0vMw82U3AUjyDfrCoJwQJ0HU9JNx4w0=; b=Bkb90YNGtcsdQXZ6QFiTlLXHSa8rBmA/ZeIIiRM/8o28bSIWyjSQFWmqwOCy76IFV/ LHiL5nQKE101kk/qaZK5MEEW2AogegG3B5/n+0/FUoodeT2TWWMIwLEE+SMikwk63YIR ANbsbQnLVRwjWw0fFD7VA5fZdLvqe3RZ5T+1G/t6v1zYBzXpe5DSBX8pKRpJagVjiZzV iO5d5X8V40F/fQOzDMG/6EjoYO8UC92T0C2flvv3bQvloPinj2P8cAibTejPNb5wQroK 7UY4G5Lverof5/rzkd437BRWh4COEh1dYq1a+tq+cQSWxX6izlALaE4e0Z8Im5NlYeAi 7IiA== 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 a65-v6si4766830pge.694.2018.08.23.09.17.14; Thu, 23 Aug 2018 09:17:30 -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 S1732146AbeHWPWn (ORCPT + 99 others); Thu, 23 Aug 2018 11:22:43 -0400 Received: from mga03.intel.com ([134.134.136.65]:14311 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729417AbeHWPWm (ORCPT ); Thu, 23 Aug 2018 11:22:42 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 23 Aug 2018 04:53:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.53,278,1531810800"; d="scan'208";a="256610600" Received: from ahunter-desktop.fi.intel.com (HELO [10.237.72.137]) ([10.237.72.137]) by fmsmga005.fm.intel.com with ESMTP; 23 Aug 2018 04:53:08 -0700 Subject: Re: [PATCH v4 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: <20180823180549.78e508db@xhacker.debian> <20180823180926.444b34b5@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: <6302a5a4-35cf-3d8f-fcac-a15141fcf1d0@intel.com> Date: Thu, 23 Aug 2018 14:51:26 +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: <20180823180926.444b34b5@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 23/08/18 13:09, 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 | 39 +++++++++++++++++++++++++++++ > 1 file changed, 39 insertions(+) > > diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c > index 1b7cd144fb01..df0a3aeabe19 100644 > --- a/drivers/mmc/host/sdhci-of-dwcmshc.c > +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c > @@ -8,21 +8,48 @@ > */ > > #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 the 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); Doesn't this need a return? i.e. 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 +63,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); You are assuming here that totalram_pages gives you the highest physical page number. Is that true? > + if (extra > SDHCI_MAX_SEGS) > + extra = SDHCI_MAX_SEGS; > + host->adma_table_cnt = SDHCI_MAX_SEGS * 2 + 1 + extra; That should be: host->adma_table_cnt += extra; > + > pltfm_host = sdhci_priv(host); > priv = sdhci_pltfm_priv(pltfm_host); > >