From patchwork Thu Jul 26 07:14:24 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 10545353 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0E316112B for ; Thu, 26 Jul 2018 07:17:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E92D32AD78 for ; Thu, 26 Jul 2018 07:17:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DD8AA2AD9A; Thu, 26 Jul 2018 07:17:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.9 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, DKIM_SIGNED,DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7D1182AD78 for ; Thu, 26 Jul 2018 07:17:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=66/dVDUKmUwFcWOypYQcZ0/rih7SYyrywrIvX3PPwr8=; b=oGa9Q6A5DSIEQc rb02GphXjThLFhgnvKOAlZFplU/QjbvJ1QdjIqRszOw4XDtd2cuvvnBpJBseQcKanOdAgfivBJVEG 3DtlJpWEdaId9kNTQ2e59VU2WoJr91Z5IcwcKWJvS7xPGAcLNlMJAtAfHDAgD1t83SgWxM1rkfimW lkBf/tAGmTwgjZF2iuZffluhzLLU/ys0Y4EMScpMhzb4nEWvpbkmRklAfrRGP1idRopAFxsgXwCRW +mTylUUfD68s9VU0rRreeockRrKhWPKGcWwV/50Ce/VcuB4tyOq3FnD28Ce/oxJZ0jhTMAA996+za CkxwgPhSxzS1ZN+91l8g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1fiaWI-0002MJ-6u; Thu, 26 Jul 2018 07:17:06 +0000 Received: from mail-eopbgr680074.outbound.protection.outlook.com ([40.107.68.74] helo=NAM04-BN3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fiaW6-0002Bq-IM for linux-arm-kernel@lists.infradead.org; Thu, 26 Jul 2018 07:16:56 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector1-synaptics-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=HlRP5G2TG801QspAVoCKXLH6MnxPvuZHUwgGBnLxYX4=; b=XVnEikeiFVfziyuCWPtXtwESNiTYjGexCI56KxZPT/zXp9e+cBPe2Up1eHuBM2Bnb8Hci9ZPvCGRh9dzVCfjS6mqL6knQw1asDSOMxtI217XSX+q2NqkTHTTg7yFOr7jKv0a95IfaI8ZA2EYEoI/smeQfHZb+CEI5WMV/wB/RlI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; Received: from xhacker.debian (124.74.246.114) by BY2PR0301MB1574.namprd03.prod.outlook.com (2a01:111:e400:526e::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.973.21; Thu, 26 Jul 2018 07:16:39 +0000 Date: Thu, 26 Jul 2018 15:14:24 +0800 From: Jisheng Zhang To: Adrian Hunter , Ulf Hansson Subject: [PATCH mmc-next v2 3/3] mmc: sdhci-of-dwcmshc: solve 128MB DMA boundary limitation Message-ID: <20180726151424.4bcecf41@xhacker.debian> In-Reply-To: <20180726151017.4da1e336@xhacker.debian> References: <20180726151017.4da1e336@xhacker.debian> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Originating-IP: [124.74.246.114] X-ClientProxiedBy: TYAPR01CA0070.jpnprd01.prod.outlook.com (2603:1096:404:2b::34) To BY2PR0301MB1574.namprd03.prod.outlook.com (2a01:111:e400:526e::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c619941a-95fb-4468-01f4-08d5f2c7bbf0 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989117)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600073)(711020)(2017052603328)(7153060)(7193020); SRVR:BY2PR0301MB1574; X-Microsoft-Exchange-Diagnostics: 1; BY2PR0301MB1574; 3:uR8qndBRM+bi+i2EJyzGifOhGY6koOzxZ/tHarlaJ1LPtj/2JShl2S451c1O3OdkzYymO4YQPK6btNZwr5UxxWOAqF2IiFmjUJ07DJ4HGCFIkstK43WsZx6YIrCSjRuQB1IdNRG2TQa8t/+C2+a249HoqO5PQGLnPyFXMG2A/HCdx4xAQEyALKCbJ4JmOF43etEq7fP9YtyIZH9gZRKXB52TA/LRNkgOvHpceTlAyKf4Mx9bYpEl9VCAucxwam97; 25:2nvV1opx0VXHihR5Arl+3ZvJi69TJkuryw17CNY1ltU/7YDjHwGtCU18HKvd0yHzwhWmHq2B70J8VB5hyAOhRB5w8qCOIGAzTwVfweUMzi52NrGf+7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+x/zb4gOzNEjFjmYjIC4IWo18wCDoriTQXROrV73ggM5R8ZKuwhtKwjFdWZGdnNY4InedZfdYHXu8NsUsZ4O5S2/N0VPW/wa9fuStKr1p4+Jbcvf2+q8+OJXlaQ9iDMBhwPDeGs0/gqC1YkIbkT6uFk9r5psLCsKWz7UuCJsWOjuWUhVxlvM3RMVHHIM1sUvwBQEGyVKRnZ9FL43DZVM3FiaaJMa6euSfmwy89UBGZ3J5aacgQi62l3JI5U4jWeDae+w== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-MS-Exchange-SenderADCheck: 1 X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040522)(2401047)(8121501046)(5005006)(3231311)(944501410)(52105095)(93006095)(93001095)(3002001)(10201501046)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123558120)(20161123564045)(20161123560045)(20161123562045)(6072148)(201708071742011)(7699016); SRVR:BY2PR0301MB1574; BCL:0; PCL:0; RULEID:; SRVR:BY2PR0301MB1574; X-Forefront-PRVS: 07459438AA X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(346002)(366004)(396003)(376002)(136003)(39860400002)(199004)(189003)(25786009)(52116002)(6116002)(66066001)(72206003)(230700001)(106356001)(5660300001)(68736007)(4326008)(305945005)(53936002)(478600001)(105586002)(6666003)(7736002)(7696005)(76176011)(6506007)(47776003)(55016002)(33896004)(8676002)(2906002)(16526019)(26005)(81166006)(8936002)(14444005)(81156014)(186003)(86362001)(97736004)(3846002)(446003)(486006)(50226002)(11346002)(9686003)(1076002)(50466002)(956004)(23726003)(476003)(316002)(110136005)(386003)(133343001)(39210200001); DIR:OUT; SFP:1101; SCL:1; SRVR:BY2PR0301MB1574; H:xhacker.debian; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:1; MX:1; Received-SPF: None (protection.outlook.com: synaptics.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics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o4/rtAnIMiTsvljubM0JYbVCdlXbFDohj4B0d6heczip2y7YWM8Pme/fRmbtXQ==; 5:fpoeHsfOv2rk26h4mdzFtHQJRBfnZQ6wRySlMnWzTpKMdYvlo4OKH4/5LqRh/iAQ8QDSl2kFbmDfn+PqwtOT2fPAOEGR8QwoZ6eBanK9R2XEyq7kWRELmgbWpIcsaeFK3zRpNPRnpCd7oH8zW/WC4Q3FSC6Qo87bZJ6zfRDG56c=; 7:MYnh/ASPRsEmkNY4KRl+sHPF3opbknqOB6MVqRNOn3IvSMOBHfXsgYOjg69dQw2L17x0n7gcdaQ+RZdbmzKBApChKhneL55H43CTJ4Kgh37UwLa5wxJmfw9Fm5tV/z0cd53gI/af0/ZN8HbT+z1kdNl2lkX07kr9+mt2sONlwtxCc5eFHgPxSmUknjzf2HB3hyTSOQJ7yIidb9qg0vX95NYqFaCwLTbsqahY3in4/xvaG7icFcK2grco8QtsvpLo SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Jul 2018 07:16:39.4814 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c619941a-95fb-4468-01f4-08d5f2c7bbf0 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR0301MB1574 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180726_001654_669767_A2DF4E68 X-CRM114-Status: GOOD ( 11.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 | 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);