From patchwork Mon Aug 27 08:24:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 10576629 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 A40A317DB for ; Mon, 27 Aug 2018 08:28:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AF342968D for ; Mon, 27 Aug 2018 08:28:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7BE7E29692; Mon, 27 Aug 2018 08:28:00 +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,RCVD_IN_DNSWL_NONE 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 BF2E22968D for ; Mon, 27 Aug 2018 08:27:59 +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=4m9lmisb40zOKaHt8dYaT8oGeSeVwZliyztnExzOkXg=; b=rTRXgzVCV6Q/CG FLVwK6+H7BySUMZQOM/SKqs0ituphjyPuaLSe40mmc2W4hYpQ6F5iFUT9e5DLr7BwegWbIeYefS5W CEBu6cfGD1dvP2+5MiPXKl2/37jmm506Hwe5HCmLQhwWFqC5DrJ39+5CsAmOadUbX9mTJXmra5F1p yrDC5RLe+YMbDyxYOqfwY0+0y5/YuDeT8ExpltuhkGxoEuGdUa606R5NTsMb50iVPAaFTsS1VVQMy udDy3AWVbrqISooM6Hc7ikpGpV9/NkHb5E+EBO1KvaMl3lj/oROWH18zXRxKUJ2CJOl5uK1mapRsI JYZtgO+8SOhcZFJ0tR8Q==; 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 1fuCsJ-0002fm-0W; Mon, 27 Aug 2018 08:27:51 +0000 Received: from mail-by2nam03on0067.outbound.protection.outlook.com ([104.47.42.67] helo=NAM03-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1fuCs0-0002Uo-Ir for linux-arm-kernel@lists.infradead.org; Mon, 27 Aug 2018 08:27:34 +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=N9RRjbOvBHjb8Mm5unulNA3GXdei0drLuVJUXzZw4R4=; b=p7+2+IIjN/xaJIbEyB7/s5fEDFCBQMPY9DfDobiODs1bEcXwfGaOAAuMHW/pIzh+xP6Kpv5x4MQWxcqMCd+yTkdp2qXHnsqj02kqVoTTV0JpAX4I+qw7dpdy80Sw1phjw67/qsHR4eLOsciH45Y9rmY+0WledEPRAuML/V5AcWE= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; Received: from xhacker.debian (124.74.246.114) by CY1PR0301MB1580.namprd03.prod.outlook.com (2a01:111:e400:529c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1080.14; Mon, 27 Aug 2018 08:27:18 +0000 Date: Mon, 27 Aug 2018 16:24:19 +0800 From: Jisheng Zhang To: Adrian Hunter , Ulf Hansson Subject: [PATCH v5 3/3] mmc: sdhci-of-dwcmshc: solve 128MB DMA boundary limitation Message-ID: <20180827162419.61afe238@xhacker.debian> In-Reply-To: <20180827162026.3901de27@xhacker.debian> References: <20180827162026.3901de27@xhacker.debian> X-Mailer: Claws Mail 3.17.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 X-Originating-IP: [124.74.246.114] X-ClientProxiedBy: TY1PR01CA0185.jpnprd01.prod.outlook.com (2603:1096:403::15) To CY1PR0301MB1580.namprd03.prod.outlook.com (2a01:111:e400:529c::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2da08f8f-342c-4e77-ac78-08d60bf6e7c1 X-Microsoft-Antispam: BCL:0; PCL:0; RULEID:(7020095)(4652040)(8989137)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(5600074)(711020)(2017052603328)(7153060)(7193020); SRVR:CY1PR0301MB1580; X-Microsoft-Exchange-Diagnostics: 1; CY1PR0301MB1580; 3:OQLlM4zE4bsPMkNCHJSlksYe0nPAl2tm4O0N3nAluJeRqkHTTD984FGYLQR5Xpht3cSa0+yy8YVw+PjPQnGV8Zzww4Iz5jMs15QLuRXAVGdKQMl5vBo3Wcbn0O5EdrUMGH6dTS8tT3/uLg9o5FKzG4a8G025l5QJIowh8rVXFAUMHnaemsLHXqT57s8vLJ5V7HFPOUhwG4973cEHaM2miJQS6YlaTRunkQWtPb3xA40gTTiwFi0iw402gOQ/FmmT; 25:oGXd4NEqEaFMo3dplCPTDplmHLcYYW+Ne7YF94rf8IwP/Amw4zKDtL7IbRKMXG5NErkvHJtmoro3axEP0SVa+pkUdZ4KMdSFo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fO3l9s6U/gql6+rNcdoEHo1SOjt0luz8NSL75psTMKmHDpGyuKDZm23qT2IMvUOiaObNNaFsgI3YRfF9v9HgUtLn/MtYUYJFVbOAs53LNEuI5OHwlquEAmwppwS7E6Ji4Z6Y6tCc7Rni0yW88m34uPgFhgqNwkGBRYn5UdiXC5ECTMkz7C/VUuU5Afgn/HwkrTQhZz4oWXPgbqhFPE8+mwjj4MSFTCEr7jIRhfptPUzTqalcTtbk9iGK5JdEVlTFAPlg3ev+ccWjqvh75/qg== 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)(5005006)(8121501046)(3231311)(944501410)(52105095)(10201501046)(3002001)(93006095)(93001095)(149027)(150027)(6041310)(20161123560045)(20161123564045)(20161123562045)(20161123558120)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(201708071742011)(7699016); SRVR:CY1PR0301MB1580; BCL:0; PCL:0; RULEID:; SRVR:CY1PR0301MB1580; X-Forefront-PRVS: 07778E4001 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10009020)(366004)(376002)(346002)(136003)(39850400004)(396003)(199004)(189003)(2906002)(6506007)(446003)(14444005)(66066001)(50226002)(8676002)(8936002)(86362001)(11346002)(72206003)(478600001)(68736007)(386003)(47776003)(26005)(476003)(316002)(54906003)(110136005)(53936002)(186003)(76176011)(1076002)(81166006)(81156014)(55016002)(9686003)(486006)(16526019)(97736004)(106356001)(5660300001)(230700001)(105586002)(3846002)(7736002)(33896004)(6116002)(25786009)(50466002)(4326008)(305945005)(23726003)(7696005)(956004)(52116002)(133343001)(39210200001); DIR:OUT; SFP:1101; SCL:1; SRVR:CY1PR0301MB1580; 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-Ex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zJXJzAmCVC3uWJvOm9214fGwGEha2jCH5sTH9n+jbraMwrQ2Yp2RHoGGlKDoDp+JxxccBiwzqE4TW30YA==; 5:Ew8p1sRQa+ak9mJAo3Lz3vuA2sd5xKZvbxbQrJMetsf8VRzWkCZUx7lxrXgHF5DpxrkedUlNrq4bjg8uQKrGoQvxjq18MOHlrB4dG3JskUae8DpaA9vSOy3Ihnar4bCFMWC2zu+orMRh0H5e+liFJ/lWq1mvLcywXWpwvOZJd/Q=; 7:ISH74r7aQBqIgmdjxydA00BP0GWXRM+yIODyqIBpQlsUNGI5twdq9mzd+UVr+escejvg/jvsjacEo97eQlWBw51sxBOyQAOqcqUgIOXRjMI/aq/4XYiAjdNbkO6MSdaBSUCg8yQQH5tKurKNxhM8spyYrrzuPd70sY6NEL/3odQDgs76OoahWpNQptoTYaIkEvkp6VSEfGGrgr0L8NxvcznSWebE6EBUPKF/nGU5JO7wXpjmBucd4SpbIOQ5rprA SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Aug 2018 08:27:18.3242 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2da08f8f-342c-4e77-ac78-08d60bf6e7c1 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB1580 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180827_012732_666630_C553DC12 X-CRM114-Status: GOOD ( 11.07 ) 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 | 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); + 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);