From patchwork Mon Jul 30 02:46:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 10548403 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 93AD914BC for ; Mon, 30 Jul 2018 02:52:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 762E12846F for ; Mon, 30 Jul 2018 02:52:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 67F6F28477; Mon, 30 Jul 2018 02:52:54 +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=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EBE6E2846F for ; Mon, 30 Jul 2018 02:52:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725814AbeG3EZk (ORCPT ); Mon, 30 Jul 2018 00:25:40 -0400 Received: from mail-eopbgr690065.outbound.protection.outlook.com ([40.107.69.65]:4096 "EHLO NAM04-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725811AbeG3EZj (ORCPT ); Mon, 30 Jul 2018 00:25:39 -0400 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=2DMtqpOMbuFhQoQgeJJlG3FGQoKSeAMNNyY9oeGv2F8=; b=d3oIT/Zib5MHs9s0fjzPOFVJmLGzLzjEcIKsXPWQRF6t6BXa1gu9PlOFS31IoPp0pu70esJ56rmi1SpgATyY80aUwoVK86OSDeq1rFbBtprd7Pc9Rawm+SRRMtXJJ0pFTg9gc5EHRajgGcD6qltbYhZQr45gYGJZQ2HFLRIvXok= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; Received: from xhacker.debian (124.74.246.114) by CY1PR0301MB1578.namprd03.prod.outlook.com (2a01:111:e400:529c::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.995.19; Mon, 30 Jul 2018 02:48:56 +0000 Date: Mon, 30 Jul 2018 10:46:36 +0800 From: Jisheng Zhang To: Adrian Hunter , Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Subject: [PATCH mmc-next v3 3/3] mmc: sdhci-of-dwcmshc: solve 128MB DMA boundary limitation Message-ID: <20180730104636.1a3e6c81@xhacker.debian> In-Reply-To: <20180730104228.28b58bd0@xhacker.debian> References: <20180730104228.28b58bd0@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: TY2PR06CA0027.apcprd06.prod.outlook.com (2603:1096:404:2e::15) To CY1PR0301MB1578.namprd03.prod.outlook.com (2a01:111:e400:529c::16) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fc42ea34-c5ef-4b9c-8695-08d5f5c6ff46 X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:(7020095)(4652040)(8989117)(5600074)(711020)(4534165)(4627221)(201703031133081)(201702281549075)(8990107)(2017052603328)(7153060)(7193020);SRVR:CY1PR0301MB1578; X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB1578;3:WXBvdwL/s6ZYQSpsN6y7zCfLoEKcB+9jx8MccKvGx/qYoHFhhCm/fQqv0YYUCfWKxKWPnkFtLP4Zywizg3oKD1PqQhsvZd7Biy/HOTOUYG1Hook5CjYIDJYbJs/llmEbVg0IncmuWMZ+9uqgXdH4nur0zNYnuq37bkxHJaQQtJqW9vliTdFdW32KLLsXnx9CGcof9lY/8+6E2ebgMADLxNzCGO7O5uwm4E0a+T4/Pcp71DwBdvxotvSW0qkV33mg;25:7Fk1vARo2e9kZXemo6zdcpnuMuJnXnK3WLJr9+gIryxKfZEeyQ7WV2CKqTZ7s3is0iz5gLZ6o5PRdOgIHdupKXNbOwwRIqqCygAO28Nbf34jzGNdcOC1Ba1vnUl5v4YxpOJTgtxuM6yVs3GeVIwZowpih4ewyKbs6KeABgBctH4mJwEw6BSQ7flRHXwmPQrM3aGANjpQT6Yp79OwDVHBK7WswgGyKDpqpdZFfknzZSbSlNtkpXP20HTqz/of9jDj4kFXhIcRyncBM5i/cup19BLzGbsABDAhNPjuLCNm8FYdzkS6n6WNvfCDem1oP43wE+LTBFJ5blWyH7Ae/lmUhw==;31:fLeS9TSy5GKeSIe9TsIwkF1bO0b0+gTldOWVp3pC2OggNbck+Kjc55+slpppDiYI+d9+hggjibbn10WosiQgMIww4A1c9MJbPslTL7jswfRqIUkCbzdq77KiBOc1GChYmCEi6xxGr8lG6tFXsZPjHQa6u0qTPJBjD2kh+GA3A5Yaevt4V2+T2o6rRo8lgZePqmJT1DMM1w3TPb4/SE9zqqakLCDfj8SbyVakwVVQNHQ= X-MS-TrafficTypeDiagnostic: CY1PR0301MB1578: X-Microsoft-Exchange-Diagnostics: 1;CY1PR0301MB1578;20:BjSAWJUKJFPY5/aoFLi81AOZBZCyTBllN3JectW6nvoSRruxJjj/46K2lYVUZSQcqkjQROYnDkgHYdwASHCtOzfSH90vetzIoE9S8aLPXx7q6EJIEaUT1wpJTJ1oht8HXonbN0OsIFL99uSoStk0z/m6JlK+Nx+mmWw5weTWtgEs1MvegCPTpzNdqhbVWYki747l8ds46TmwybACeS5AB+v3WEQ3Wyq5yR9zhU/tel2emik0vb/4E4Dtzkjk33E2GiqQsJxwpQMxHnIUjeExIJZf+HHo7pu9iTU9RlcEca9LcXIHPnh9VUaQgan6Umme4sjTfLJsIxHZQETMj3svCmgHqX3PNm3dOnnS++ZXfUtoQZGLZNaux57TmY9w4Cz/SU2JUu4RQdV9+QXqpBbYZyBQHZTmm9De4vpC4zz8H8LdFWHUYjHSeOVXudxzFGwThJCg6Kqwv3/gqwIo4yN4xfR1XsdE3j8ke3o30ugjctb2N/gGSklYvA2xaZgPfT/H;4:4NXyEBVxriNe/UdKsdaO2WIqVts3Ym7iunNWvtJp6CtJIUDlX184bDNrmtQOZ0o8jZ9vazhD98RDkU37WKqbLOehhFc/w0MCGI8xKSpH6sv1HCDip0xcqoajOdieNrCpDSO3nlLyP/ClrHpWXBm8YPiOHYrWnlSTyutEfLYei7BaqiCncGg04+u5Tglw6WfUgzZ7cn8EOOC+mVckbDPpYDD/qg9ToZDzCP7g+MmqG4lLMCZenxa/A/6pCdcSJvOIgrYwWGlm/1JsSnkGzAceSg== 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)(3002001)(10201501046)(93006095)(93001095)(3231311)(944501410)(52105095)(149027)(150027)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123564045)(20161123562045)(20161123558120)(20161123560045)(6072148)(201708071742011)(7699016);SRVR:CY1PR0301MB1578;BCL:0;PCL:0;RULEID:;SRVR:CY1PR0301MB1578; X-Forefront-PRVS: 0749DC2CE6 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(396003)(376002)(39850400004)(366004)(346002)(136003)(199004)(189003)(386003)(6506007)(8676002)(50466002)(14444005)(76176011)(81166006)(305945005)(7736002)(81156014)(33896004)(52116002)(7696005)(6116002)(3846002)(97736004)(956004)(476003)(23726003)(11346002)(105586002)(446003)(26005)(106356001)(230700001)(47776003)(1076002)(486006)(6666003)(9686003)(8936002)(53936002)(50226002)(66066001)(68736007)(5660300001)(86362001)(55016002)(4326008)(316002)(186003)(16526019)(110136005)(2906002)(25786009)(72206003)(478600001)(133343001)(39210200001);DIR:OUT;SFP:1101;SCL:1;SRVR:CY1PR0301MB1578;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: 1;CY1PR0301MB1578;23:uPixWRCW1QTZ/X+1Hr6G2Gr9FZ+nvLxdY4HbQa5OurWGjrtO8b5fz9J9KFowhphE5Bfz6m86AB96jq8qLQnyF6mBBn57QLxXLYumt2FmuQbv2++/ir4IMMipRnBs1SKOrJuKQBXXaDUDi9pa/zK9PEnA+ydur+WHeeR4w9RN3lEgsqT43r3MRaAz8fE6VIZ6Lsn48s9j6AmWxbBHVYvea3+ReO4XOmQJ6sjB5myKkDsPjbLnXk/7421wxaQk9AFxsJLtI2202g/bmiSqKEWuInT6wLrEhguZdfw2nAFji3xeZxIQwrNXxQADnVep2TWAflZgwrmjMmVDf+u4swGRsI2dMp2C2TvZ43Dn81wyrtzRDppo6DUNEvC+n4+qoJsC9VDfkeKeKkIwThmGJwMVzJ4LTx8X335mLe1z+cZa5ch1uWS/bswMSKNbAlSt/3E60vOPYPZad0b4VCtxHebD18iVrG2QN0FZHTp6FaZe+Vm4XhLcRgHti7/j0ybJQtx9moK3nGoDpJca3VTAQw+3N8C3fr7jCj7e146bsbPX44EgQmF3QOfEXQd19rxFG5DP5TjioheSUiI/TBXBG7GC/536nR+tiQgYx/1Dp4zV19U+g9s2nQ8B5RUNFgDKmHvCGh9NXxcykP9NQrct5cD+0sj13OCfGeNXu3PNK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9FsH7fjKANCd/qoIJvjaPQZfGWNscoUe3EWdC/UFkFRjJVT1QJcr8uKlyQxIB2yMaPmOu8NQEY6tyn3FdeskvEFh/rpHgiAt91Rxtg7+NCHP3JezE3SKxU6jEjp67AXjupoi30bjhH5PALg+AwSXWGXnemFz4jV8qRcxqtESOF0pn+GorqjQ5wmIOiLbzsmWTeNPcOfCN6TWz+oBhDo7LlvcrVS/94mUXB3xl+V4iQbjlh9qszjgu6lK2bH9q7XWC2OBfn+Vxbi2c4cHpUG1MGgOIY+MS60pFC0SObG3AheC0Yu1KEY9uNDUYXYgSSS9BdE6aEwQlmVmjH5r2wpNWLl/QKG+Iuaa1App2ke8yONk41k8sHRmy7tamVL8xtFQ3zGN9M3YUcW5f6AviWNlmdMxkEaDED/1A==;5:9Z/Dgd+YmXHIfoHSzbOcmmEh/aUr0lmzfs6D/6oPknxpVccxr7YYKlzZZn4SRs05PVCJ+IvTl1Y1ZWXp0qjLGc2K52kBo+M07E8qfvb2NSq65XJ1X93gNPdgmErhBR80MA/zx1UbBLL14dLBO6E9Pza2XmQMLiW0TQItMoyFWO8=;7:tyvTEVTpoX7KuwqKfq64XoliSa5wcrrF/Y9U3AUsm7/1fdI6joWJJQtXLrOjBuc8XZREWUdP2sVyZPUuwFdAm2yGfB6JlG/RtY+a3pOmpGUY4RVS7B9waOpcqubEordmNCZf6sIs4+4EatjzsK7anQVW1VVkf81//iLo7ffRna3OPsnWCYVBfT/ZJ8k086pS+ykCysPqYynvP2sDMRa3FNYqPQGG+TU7rgQVMbC80yCAzSSJQNf7M2qxAh5ob//9 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Jul 2018 02:48:56.3403 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: fc42ea34-c5ef-4b9c-8695-08d5f5c6ff46 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY1PR0301MB1578 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.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 Signed-off-by: Jisheng Zhang <Jisheng.Zhang@synaptics.com>
--- drivers/mmc/host/sdhci-of-dwcmshc.c | 43 +++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/drivers/mmc/host/sdhci-of-dwcmshc.c b/drivers/mmc/host/sdhci-of-dwcmshc.c index 1b7cd144fb01..e890fc8f5284 100644 --- a/drivers/mmc/host/sdhci-of-dwcmshc.c +++ b/drivers/mmc/host/sdhci-of-dwcmshc.c @@ -8,21 +8,52 @@ */ #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 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 (likely(!len || BOUNDARY_OK(addr, 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 +67,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);