Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp3816936imm; Mon, 30 Jul 2018 04:08:03 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdiVlp0RkufaZ7QMM9Imjd/zmTef8eC5ZZCOxTj9l7Is0Wij7P3IVZp9V+BxVa2DuoOh9zr X-Received: by 2002:a63:c046:: with SMTP id z6-v6mr7442795pgi.114.1532948883844; Mon, 30 Jul 2018 04:08:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532948883; cv=none; d=google.com; s=arc-20160816; b=e/ASusMS3EZFpp2LzKMhyu0d3D3/Dasc1m9N0maITmzLwpUk7jmqPvYQALUV6Q4+6P 5VTcn9gWQT0bC+cuMEvyOGmv+zWDLjWVcCafeTwicGiiVE9s1gSKfBU+cB7nF2mvnTqn yFG08bnH1+otYRGF05+77cGakcPmHwcgIKlzgW8GQHszcTIAo0SvCS5xeMAMvX56xjuG CQYzdpOWr+gsdbtWQaJ+QjZCbFFXQYFFCROcm9SRrrnQcXuyzPoQbnzTfZpqlUDMTehG Z8QsC+CGWucGMr39KRYm1Obaw8yMK0zHKut38QCLACxS3aq2oygY5R6GuNkBbJRQhXX3 hUig== 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:from:references:cc:to:subject:arc-authentication-results; bh=M2iMyv3/X75pGu0oPcv3yllOwcRe+s0eL5iyh+SxHt0=; b=dIpbVc8JU2Cg5O3w8MIPFef2qX4N+2TGD17ZFa+YIiu5dks4Kos8gp9WmR9IoWI4G/ CqigJ3xsca3lILE5WHMFABfPV2FFAQzNhQeBiWYd8XE1ML/EIATCESUkGTT1HDuLlyjE /hw4/UrIqrNiHZnN+2KDtLLJNwCmoLZYv8Y5arUknNiZ3WQQEm9bsiVO2tD8nb+IrTCB GwsKcrLi9XMe9eCzpm3JOJbJt81mMzWsGRtliLg1pl2lvQGR3JKogmB2k+ADfWtEi2rI chC1eGj06vpGPdWR9571U5HGqBQ10hY84ZqQN2DVbKLmllCB0j6fpoDo4rFiR1nRgLir XKTQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b2-v6si11118961pff.192.2018.07.30.04.07.49; Mon, 30 Jul 2018 04:08:03 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731434AbeG3Mki (ORCPT + 99 others); Mon, 30 Jul 2018 08:40:38 -0400 Received: from foss.arm.com ([217.140.101.70]:36834 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726611AbeG3Mki (ORCPT ); Mon, 30 Jul 2018 08:40:38 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id CAAA480D; Mon, 30 Jul 2018 04:06:10 -0700 (PDT) Received: from [10.4.12.131] (e110467-lin.Emea.Arm.com [10.4.12.131]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BAAA23F6A8; Mon, 30 Jul 2018 04:06:09 -0700 (PDT) Subject: Re: [PATCH mmc-next v2 3/3] mmc: sdhci-of-dwcmshc: solve 128MB DMA boundary limitation To: Jisheng Zhang , Adrian Hunter , Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org References: <20180726151017.4da1e336@xhacker.debian> <20180726151424.4bcecf41@xhacker.debian> From: Robin Murphy Message-ID: Date: Mon, 30 Jul 2018 12:06:08 +0100 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: <20180726151424.4bcecf41@xhacker.debian> Content-Type: text/plain; charset=utf-8; format=flowed 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 Hi Jisheng, On 26/07/18 08:14, 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. Out of interest, is the driver already setting its segment boundary mask appropriately? This sounds like the exact kind of hardware restriction that dma_parms is intended to describe, which scatterlist-generating code is *supposed* to already respect. Robin. > Signed-off-by: Jisheng Zhang > --- > drivers/mmc/host/sdhci-of-dwcmshc.c | 42 +++++++++++++++++++++++++++++ > 1 file changed, 42 insertions(+) > > diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c > index 1b7cd144fb01..7e189514bc83 100644 > --- a/drivers/mmc/host/sdhci-of-dwcmshc.c > +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c > @@ -8,21 +8,51 @@ > */ > > #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 unsigned int dwcmshc_adma_write_desc(struct sdhci_host *host, > + void *desc, dma_addr_t addr, > + int len, unsigned int cmd) > +{ > + int tmplen, offset; > + > + if (BOUNDARY_OK(addr, len) || !len) > + return _sdhci_adma_write_desc(host, desc, addr, len, cmd); > + > + offset = addr & (SZ_128M - 1); > + tmplen = SZ_128M - offset; > + _sdhci_adma_write_desc(host, desc, addr, tmplen, cmd); > + > + addr += tmplen; > + len -= tmplen; > + desc += host->desc_sz; > + _sdhci_adma_write_desc(host, desc, addr, len, cmd); > + > + return host->desc_sz * 2; > +} > + > 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 +66,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 descriptor table number 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); > + if (extra > SDHCI_MAX_SEGS) > + extra = SDHCI_MAX_SEGS; > + host->adma_table_num = SDHCI_MAX_SEGS * 2 + 1 + extra; > + > pltfm_host = sdhci_priv(host); > priv = sdhci_pltfm_priv(pltfm_host); > >