From patchwork Fri Jan 29 09:45:51 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Russell King X-Patchwork-Id: 8161311 Return-Path: X-Original-To: patchwork-linux-mmc@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id C0145BEEE5 for ; Fri, 29 Jan 2016 09:46:04 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E1B6F20374 for ; Fri, 29 Jan 2016 09:46:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id EE62B20361 for ; Fri, 29 Jan 2016 09:46:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754015AbcA2Jp7 (ORCPT ); Fri, 29 Jan 2016 04:45:59 -0500 Received: from pandora.arm.linux.org.uk ([78.32.30.218]:44268 "EHLO pandora.arm.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753913AbcA2Jp5 (ORCPT ); Fri, 29 Jan 2016 04:45:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=arm.linux.org.uk; s=pandora-2014; h=Date:Sender:Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References:In-Reply-To; bh=kCnerwRVmKT0MBN8IIpvq+pWAt0J7NJthAH/l0abTAo=; b=haop/SdBVFf+Nc1K4nm/2VxV3WmH8V039dcFOnIHfsu6j6vSScRKezEquDqs8Rk67zXRyD0W/3rvBgg4b1iSJFSr6jk57K+KH7M6OfNlqyax4YG8AipP7+q9ck2zzNOsng1lMa80WklKlur2ibT8BDWJyRMNWGmEKa6ScTkRt6I=; Received: from e0022681537dd.dyn.arm.linux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:42088 helo=rmk-PC.arm.linux.org.uk) by pandora.arm.linux.org.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1aP5cn-0001lT-U8; Fri, 29 Jan 2016 09:45:54 +0000 Received: from rmk by rmk-PC.arm.linux.org.uk with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1aP5cl-0001qw-PN; Fri, 29 Jan 2016 09:45:51 +0000 In-Reply-To: <20160129094324.GA20025@n2100.arm.linux.org.uk> References: <20160129094324.GA20025@n2100.arm.linux.org.uk> From: Russell King To: Ulf Hansson Cc: Gregory CLEMENT , linux-mmc@vger.kernel.org, Marcin Wojtas , Shawn Guo , Sascha Hauer Subject: [PATCH v4 24/25] mmc: sdhci: consolidate the DMA/ADMA size/address quicks MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Fri, 29 Jan 2016 09:45:51 +0000 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Rather than scanning the scatterlist multiple times for each quirk, scan it once, checking for each possible quirk. This should be cheaper due to the length and offset members commonly sharing the same cache line than scanning the scatterlist multiple times. Signed-off-by: Russell King --- drivers/mmc/host/sdhci.c | 48 ++++++++++++++++-------------------------------- 1 file changed, 16 insertions(+), 32 deletions(-) diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index a033155984a4..cd5e62f273b3 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -731,22 +731,35 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd) /* * FIXME: This doesn't account for merging when mapping the * scatterlist. + * + * The assumption here being that alignment and lengths are + * the same after DMA mapping to device address space. */ if (host->flags & SDHCI_REQ_USE_DMA) { struct scatterlist *sg; - unsigned int length_mask; + unsigned int length_mask, offset_mask; int i; length_mask = 0; + offset_mask = 0; if (host->flags & SDHCI_USE_ADMA) { - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) + if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) { length_mask = 3; + /* + * As we use up to 3 byte chunks to work + * around alignment problems, we need to + * check the offset as well. + */ + offset_mask = 3; + } } else { if (host->quirks & SDHCI_QUIRK_32BIT_DMA_SIZE) length_mask = 3; + if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) + offset_mask = 3; } - if (unlikely(length_mask)) { + if (unlikely(length_mask | offset_mask)) { for_each_sg(data->sg, sg, data->sg_len, i) { if (sg->length & length_mask) { DBG("Reverting to PIO because of transfer size (%d)\n", @@ -754,35 +767,6 @@ static void sdhci_prepare_data(struct sdhci_host *host, struct mmc_command *cmd) host->flags &= ~SDHCI_REQ_USE_DMA; break; } - } - } - } - - /* - * The assumption here being that alignment is the same after - * translation to device address space. - */ - if (host->flags & SDHCI_REQ_USE_DMA) { - struct scatterlist *sg; - unsigned int offset_mask; - int i; - - offset_mask = 0; - if (host->flags & SDHCI_USE_ADMA) { - /* - * As we use 3 byte chunks to work around - * alignment problems, we need to check this - * quirk. - */ - if (host->quirks & SDHCI_QUIRK_32BIT_ADMA_SIZE) - offset_mask = 3; - } else { - if (host->quirks & SDHCI_QUIRK_32BIT_DMA_ADDR) - offset_mask = 3; - } - - if (unlikely(offset_mask)) { - for_each_sg(data->sg, sg, data->sg_len, i) { if (sg->offset & offset_mask) { DBG("Reverting to PIO because of bad alignment\n"); host->flags &= ~SDHCI_REQ_USE_DMA;