Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp5645628imm; Mon, 27 Aug 2018 01:28:46 -0700 (PDT) X-Google-Smtp-Source: ANB0VdY4awLCLjVdmUhQIvLYQDs/n1WQnjGjqHecEJgs9OtKQsFIS7IDBQ6t+Cb3pY13Zs9xdMMz X-Received: by 2002:a17:902:f:: with SMTP id 15-v6mr11981626pla.195.1535358526169; Mon, 27 Aug 2018 01:28:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535358526; cv=none; d=google.com; s=arc-20160816; b=xXr+Jo/tCTqQRdfBlcGDuorRRpsWOXYPIWfsoCmNfHoyQw+3uo/q+ereVIFMfHKSI/ vnYWvs74thgCwJUYgfrNEclFfBsZokjkcK5t1qk6THFYoq4x7HES8hryahuzcjiILlYZ fgaIRAfgva3GcmMWlxbQH67ZwTg5ewobXvlysv+iLtbPlbx/5RFQd3TOtSLOC4E1irDI c+YevW2VJfsOWxGulbISmXqJDyuWwbGgrw46pUBL0NmOgOM5MZyeajoTEf6Zfh/P887l WNH1Ol0y6scJ2v3POqC8x7QC6Z8VgD3gvLNtjEXtxH/FdbvP+knMyje+OAbd9dqXErEq c1IA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature:arc-authentication-results; bh=N9RRjbOvBHjb8Mm5unulNA3GXdei0drLuVJUXzZw4R4=; b=gamPLgnlmEbQvTNF+zaN/CmP4CHawYvVYIy2DDmcv0+HVn3/6wvnXogpFt1882XksI eAknqnUlgL68jY/Lxi46LDPXayIZSPE81FMB4k/aXefQMXIyYgz4aQns6YQzRMHz7ynZ j8GMa9hgikyoHSu1+tj6IQD1iaR6c3Yn5/r95Z0J7KGgUI3jgbceDnMLNPiiSL+I6QfG CZkVnHA5cU8Q5bJv4jzT2G0Ce9JA+2V0YqaIeRiLuzdjsK4xEA88Jk8NVtKldlcpwWt+ ajqZKviQgbDT/uolSfR6yVRL75r46M15ic8DFVPrAd0SXwZi/QgCQ1pLgcdip2wnbLbE WhIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@Synaptics.onmicrosoft.com header.s=selector1-synaptics-com header.b=p7+2+IIj; 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 f34-v6si12585760pgf.488.2018.08.27.01.28.30; Mon, 27 Aug 2018 01:28:46 -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; dkim=pass header.i=@Synaptics.onmicrosoft.com header.s=selector1-synaptics-com header.b=p7+2+IIj; 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 S1726942AbeH0MNC (ORCPT + 99 others); Mon, 27 Aug 2018 08:13:02 -0400 Received: from mail-by2nam03on0080.outbound.protection.outlook.com ([104.47.42.80]:26496 "EHLO NAM03-BY2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726802AbeH0MNB (ORCPT ); Mon, 27 Aug 2018 08:13:01 -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=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 Cc: , , 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 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit 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+Pj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Q0bKK9hQ2aNxTcwyMnu1kx5jLDud1X8QdhUiHhvhpXVTj1vaBA9Cabea/cJ2tWxZAMMLmN5iYH6JfgdINf3qEryyfcQ5TBQ4Rb1eaHn2y2mRO8qR1hJGwT/m2j4yhbVroOxCs5xG2nlGfVFzDWpAO4ycffnQ16pyD0F1+p/oAkvPkx1WyKN404n0kPrZOFKxLFKN+ojDsVTsYq/A+VVl/WIWXIp9fx72o2bGgLDSXWP9+8NqdSwXjBwuf0IH/QXBxEb;4:2YfO3l9s6U/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-Exchange-Diagnostics: =?us-ascii?Q?1;CY1PR0301MB1580;23:cKU/3ACjFHLdOqzFLY1c0xXQK9STfYvt5gk1VKt?= =?us-ascii?Q?uzXJUfZxVqIaXR0q03GDo3b/vWY5XAytHFZkRMN3H2s9Jx3Cu8I5auWhvXi2?= =?us-ascii?Q?tS2p1fyu9I0HKT3VglK7UcNou+/baSY778xkIyP9fLT40lcga8WaJK0OSgW5?= =?us-ascii?Q?Ln1abIgaoGXUZ3CNMW+Om3UtDLwmvU31cr+er2vgHJwkPBh9g4m62+c1q01W?= =?us-ascii?Q?HgtsWNSAmXvpFWmuBj0RWC+UGyKC3S/iM1iKO8jMMg5lRI9t+Vme+L7m4IMh?= =?us-ascii?Q?uMj4qIdCNpSjzZilaqvqkhYBkC3vhFHZCJejw0wB3VnClppli86HNfqQEZFp?= =?us-ascii?Q?XXo+ZewHr37IVYA3TXVSUT6cHwO7uglpF+ic7Vwx6+/3FcJWOFNM4yNgaoVp?= =?us-ascii?Q?JAMYqOgfxO2hbhugs3Yxo6uolTnJrMV3l5ZmAZ4O4QfhSUjynnh+I3VHOdzS?= =?us-ascii?Q?ghbtXUMHZ1p1fPqoAURWIU+Vi+SXf1PZ/NJiHoE5FdJGg+deGl9EW5stX8UM?= =?us-ascii?Q?E2+C2L/lPmybGMkCQ+wX6mLhcIaJEu8QvB91ElaNa5vhzX+O4g+If1Pn7ol9?= =?us-ascii?Q?XG7D+OiVcvtqgmy9dUZ+dct9jwnYcCmdTAN54W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pamDiagnosticOutput: 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 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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); -- 2.18.0