Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp2267665imm; Mon, 28 May 2018 05:06:12 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKIudIZosaTbcNlYrIL1Hngvx4B8BLU2ZR5kysfQpR3c4u+cgP4+iaKFdxgw9T5YRivFwXg X-Received: by 2002:a63:a84f:: with SMTP id i15-v6mr4958920pgp.422.1527509171967; Mon, 28 May 2018 05:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527509171; cv=none; d=google.com; s=arc-20160816; b=yvTa3DPDfKOYUNKhbOtBKbc61YbGYuNWfHi2gSF4VEHv6P8s9rQbTPUdr7cq1eWeEf qsfmLxvaNPEBCqh0nWQnHn1pTvzMk5vhuCJVlUm3qb5DOR46PcA7SnzEg9DGGWYcYuRf YAIzsHZ0UVAs6+lVX2coNnMJ7UpDob3584XRzj0DE177sZCy7cbgzjqGwbpHEyHwLKzb pmwC+VEC67twWtddl8DoBPslHPowk1dDp281zKKaiolqbximt73xm2Z7KW8X7XHCmyoY 20pqxCnv33zhO+ZHcIE4w6Pn7t7EKz3FJ/hiSuMQjiqJwdSDY6Kv48tE8/RRai4POzqk xSMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=VXz8xnX6rZQKdfWFLZWjMdUepxMElOnGatEwbX6QS40=; b=oZ2S+4eOQt/DyYx+2G7eSuMYpm57lV4AUM4rWE3ct3OB/awz/rN6O6qC7En+kDO2Vb dhwDX0ArUshc/IH1mUiybJfsjQ25zX/OhpzCC31fA2EnOECMZvBG2yowaS4xEQ7DnZ/a 7fkxXaHx/bY8u5xfo38leJOXwNKWHWXCHli8Cd5QvEffLIjn/YXa3KmXQ1b2L+U/x1xE 1qHC1FUiiwLOJxZhWUlR/Qm/c0vCGeD89QIsSwbPI1ww7WAY+ec0/PMv8F0X3NzfxTcg FLpGCYQKdPR7pzal8c+NUdkNm0IaE+oldN+79T7l/pIYsumKN1gWDexZlJG44t4e3jvk RH/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dTrhnIKd; 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 k134-v6si1943623pga.149.2018.05.28.05.05.57; Mon, 28 May 2018 05:06:11 -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=@kernel.org header.s=default header.b=dTrhnIKd; 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 S938545AbeE1MFM (ORCPT + 99 others); Mon, 28 May 2018 08:05:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:53022 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423195AbeE1LGG (ORCPT ); Mon, 28 May 2018 07:06:06 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DCA2A2075C; Mon, 28 May 2018 11:06:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527505565; bh=mD8ADi5EIeS6V6EQwAhtRuords4UQ3pLXfRvkEOpYzE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dTrhnIKdrM/KhwYDf+Oim92X6Qcukxevhyy1d+XabElS4ziiJwXEJdK+TUeGJS2j2 BVCkIVwFEm+j+fAngwaI+EciuVG+lWHHkGQylG/QWtnOBeFUd+nlSr5QlrgNumNM3W wCMb3p51pXhGKwXJJHUh7cCq3eH7Qg8qmIdzRU3g= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Corneliu Doban , Scott Branden , Ulf Hansson Subject: [PATCH 4.16 017/272] mmc: sdhci-iproc: fix 32bit writes for TRANSFER_MODE register Date: Mon, 28 May 2018 12:00:50 +0200 Message-Id: <20180528100241.835633675@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180528100240.256525891@linuxfoundation.org> References: <20180528100240.256525891@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.16-stable review patch. If anyone has any objections, please let me know. ------------------ From: Corneliu Doban commit 5f651b870485ee60f5abbbd85195a6852978894a upstream. When the host controller accepts only 32bit writes, the value of the 16bit TRANSFER_MODE register, that has the same 32bit address as the 16bit COMMAND register, needs to be saved and it will be written in a 32bit write together with the command as this will trigger the host to send the command on the SD interface. When sending the tuning command, TRANSFER_MODE is written and then sdhci_set_transfer_mode reads it back to clear AUTO_CMD12 bit and write it again resulting in wrong value to be written because the initial write value was saved in a shadow and the read-back returned a wrong value, from the register. Fix sdhci_iproc_readw to return the saved value of TRANSFER_MODE when a saved value exist. Same fix for read of BLOCK_SIZE and BLOCK_COUNT registers, that are saved for a different reason, although a scenario that will cause the mentioned problem on this registers is not probable. Fixes: b580c52d58d9 ("mmc: sdhci-iproc: add IPROC SDHCI driver") Signed-off-by: Corneliu Doban Signed-off-by: Scott Branden Cc: stable@vger.kernel.org # v4.1+ Signed-off-by: Ulf Hansson Signed-off-by: Greg Kroah-Hartman --- drivers/mmc/host/sdhci-iproc.c | 30 +++++++++++++++++++++++++----- 1 file changed, 25 insertions(+), 5 deletions(-) --- a/drivers/mmc/host/sdhci-iproc.c +++ b/drivers/mmc/host/sdhci-iproc.c @@ -33,6 +33,8 @@ struct sdhci_iproc_host { const struct sdhci_iproc_data *data; u32 shadow_cmd; u32 shadow_blk; + bool is_cmd_shadowed; + bool is_blk_shadowed; }; #define REG_OFFSET_IN_BITS(reg) ((reg) << 3 & 0x18) @@ -48,8 +50,22 @@ static inline u32 sdhci_iproc_readl(stru static u16 sdhci_iproc_readw(struct sdhci_host *host, int reg) { - u32 val = sdhci_iproc_readl(host, (reg & ~3)); - u16 word = val >> REG_OFFSET_IN_BITS(reg) & 0xffff; + struct sdhci_pltfm_host *pltfm_host = sdhci_priv(host); + struct sdhci_iproc_host *iproc_host = sdhci_pltfm_priv(pltfm_host); + u32 val; + u16 word; + + if ((reg == SDHCI_TRANSFER_MODE) && iproc_host->is_cmd_shadowed) { + /* Get the saved transfer mode */ + val = iproc_host->shadow_cmd; + } else if ((reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) && + iproc_host->is_blk_shadowed) { + /* Get the saved block info */ + val = iproc_host->shadow_blk; + } else { + val = sdhci_iproc_readl(host, (reg & ~3)); + } + word = val >> REG_OFFSET_IN_BITS(reg) & 0xffff; return word; } @@ -105,13 +121,15 @@ static void sdhci_iproc_writew(struct sd if (reg == SDHCI_COMMAND) { /* Write the block now as we are issuing a command */ - if (iproc_host->shadow_blk != 0) { + if (iproc_host->is_blk_shadowed) { sdhci_iproc_writel(host, iproc_host->shadow_blk, SDHCI_BLOCK_SIZE); - iproc_host->shadow_blk = 0; + iproc_host->is_blk_shadowed = false; } oldval = iproc_host->shadow_cmd; - } else if (reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) { + iproc_host->is_cmd_shadowed = false; + } else if ((reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) && + iproc_host->is_blk_shadowed) { /* Block size and count are stored in shadow reg */ oldval = iproc_host->shadow_blk; } else { @@ -123,9 +141,11 @@ static void sdhci_iproc_writew(struct sd if (reg == SDHCI_TRANSFER_MODE) { /* Save the transfer mode until the command is issued */ iproc_host->shadow_cmd = newval; + iproc_host->is_cmd_shadowed = true; } else if (reg == SDHCI_BLOCK_SIZE || reg == SDHCI_BLOCK_COUNT) { /* Save the block info until the command is issued */ iproc_host->shadow_blk = newval; + iproc_host->is_blk_shadowed = true; } else { /* Command or other regular 32-bit write */ sdhci_iproc_writel(host, newval, reg & ~3);