Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp1540457pxb; Thu, 16 Sep 2021 09:31:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrV8DOjJ0a1l7duhfzSaY4/scUPp21uSiZ2N1lobw29X8G5CIOGr4jzXIEseNHDljanCQY X-Received: by 2002:a05:6e02:4a4:: with SMTP id e4mr4627671ils.232.1631809913703; Thu, 16 Sep 2021 09:31:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631809913; cv=none; d=google.com; s=arc-20160816; b=iTeQ3fymN4GvH3EmI/xLn/XygW/PpfC04nXkvCB3DFsyssBUDumimXJc35WFVPpkeh SPCYI/QAfc5lk+Gg2jIpNJPdo9dMOE5rAbeM1qHsm54PTnKKkIj6ETXs3dK2t+C7RmVU 0K4Gt2qY3JmNsh7OyFpm04nBxqy8OaOHk+TJn26scj2Saj4jW/YdYfnTbebv0l9DFTBz 0Nu8NXdo6OKLSKqUZuw0v6k3hnZPfeDcV9WlPhmKowRM94DpcXkCEgxtjAyIqlQMpUDO +SSuOLW7YMTyyGLbDPRXGT0CVWI8zXHIZfWxPFI671HM/OpjrCtmFpcta3NEEGOWaQIB 2aFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Qojz1pJ/tUHDchoNzEVLQ1WsBbi2LOS09xlJE4IsV90=; b=jSaAeOK1n4tH+m2PE9t2Yedg0hT3tKbNuhwZrRaqJ1p6CazfT4rmo3LIsAqzyeEoAJ TbIAQGuz6JPMAlbS+eVaENFdv12ZwYiHQNPz3hsmOCkmyPrUNCu64nDUCPwhh4qG0G6x SkyW71KqQKptj/Q/NGhBDGCgzGFBhT/J/NyRho9yTMGQiToBsNdhDoU7mZM6c8LF2ZU5 eM68o8X1AbS3oGGlThetJ8rP0mduYIjPuajFlnI2Y9X52f4VNdgJ4xW8dMOB+9O700nE XXHRQT7WCUH3n2dxyocytXmoRmDNb4G7uYyTze6Xut5LUcz8OOJn0m60Te2KxjUgkhsk 37xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=upDdswO5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v18si3389229ilc.7.2021.09.16.09.31.39; Thu, 16 Sep 2021 09:31:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=upDdswO5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241972AbhIPQbp (ORCPT + 99 others); Thu, 16 Sep 2021 12:31:45 -0400 Received: from mail.kernel.org ([198.145.29.99]:59280 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239857AbhIPQXh (ORCPT ); Thu, 16 Sep 2021 12:23:37 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 855E36126A; Thu, 16 Sep 2021 16:15:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1631808948; bh=ijaTQrH7uzrbDQqtZaDZWTvEZxY3LK3zfnRWPTU1wnM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=upDdswO5dlTZARL7brNtwuBPWanUPdTho37A9s2EiWEk+rok0ITKRsiKh2IcZscPw NzDnHuHMwuyFaQQJOHVQLjhsa+HtNlr/SoLHzTK8q7qx+Ohb5jSWJramhwFbXWM7Go Lh4gO6OQqottyAfG5zLZE0AJgNrr8ikJlFFxYwwc= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Thomas Hebb , Ulf Hansson , Sasha Levin Subject: [PATCH 5.10 249/306] mmc: rtsx_pci: Fix long reads when clock is prescaled Date: Thu, 16 Sep 2021 17:59:54 +0200 Message-Id: <20210916155802.553039998@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210916155753.903069397@linuxfoundation.org> References: <20210916155753.903069397@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Thomas Hebb [ Upstream commit 3ac5e45291f3f0d699a721357380d4593bc2dcb3 ] For unexplained reasons, the prescaler register for this device needs to be cleared (set to 1) while performing a data read or else the command will hang. This does not appear to affect the real clock rate sent out on the bus, so I assume it's purely to work around a hardware bug. During normal operation, the prescaler is already set to 1, so nothing needs to be done. However, in "initial mode" (which is used for sub-MHz clock speeds, like the core sets while enumerating cards), it's set to 128 and so we need to reset it during data reads. We currently fail to do this for long reads. This has no functional affect on the driver's operation currently written, as the MMC core always sets a clock above 1MHz before attempting any long reads. However, the core could conceivably set any clock speed at any time and the driver should still work, so I think this fix is worthwhile. I personally encountered this issue while performing data recovery on an external chip. My connections had poor signal integrity, so I modified the core code to reduce the clock speed. Without this change, I saw the card enumerate but was unable to actually read any data. Writes don't seem to work in the situation described above even with this change (and even if the workaround is extended to encompass data write commands). I was not able to find a way to get them working. Signed-off-by: Thomas Hebb Link: https://lore.kernel.org/r/2fef280d8409ab0100c26c6ac7050227defd098d.1627818365.git.tommyhebb@gmail.com Signed-off-by: Ulf Hansson Signed-off-by: Sasha Levin --- drivers/mmc/host/rtsx_pci_sdmmc.c | 36 ++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 13 deletions(-) diff --git a/drivers/mmc/host/rtsx_pci_sdmmc.c b/drivers/mmc/host/rtsx_pci_sdmmc.c index eb395e144207..e00167bcfaf6 100644 --- a/drivers/mmc/host/rtsx_pci_sdmmc.c +++ b/drivers/mmc/host/rtsx_pci_sdmmc.c @@ -539,9 +539,22 @@ static int sd_write_long_data(struct realtek_pci_sdmmc *host, return 0; } +static inline void sd_enable_initial_mode(struct realtek_pci_sdmmc *host) +{ + rtsx_pci_write_register(host->pcr, SD_CFG1, + SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_128); +} + +static inline void sd_disable_initial_mode(struct realtek_pci_sdmmc *host) +{ + rtsx_pci_write_register(host->pcr, SD_CFG1, + SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_0); +} + static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq) { struct mmc_data *data = mrq->data; + int err; if (host->sg_count < 0) { data->error = host->sg_count; @@ -550,22 +563,19 @@ static int sd_rw_multi(struct realtek_pci_sdmmc *host, struct mmc_request *mrq) return data->error; } - if (data->flags & MMC_DATA_READ) - return sd_read_long_data(host, mrq); + if (data->flags & MMC_DATA_READ) { + if (host->initial_mode) + sd_disable_initial_mode(host); - return sd_write_long_data(host, mrq); -} + err = sd_read_long_data(host, mrq); -static inline void sd_enable_initial_mode(struct realtek_pci_sdmmc *host) -{ - rtsx_pci_write_register(host->pcr, SD_CFG1, - SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_128); -} + if (host->initial_mode) + sd_enable_initial_mode(host); -static inline void sd_disable_initial_mode(struct realtek_pci_sdmmc *host) -{ - rtsx_pci_write_register(host->pcr, SD_CFG1, - SD_CLK_DIVIDE_MASK, SD_CLK_DIVIDE_0); + return err; + } + + return sd_write_long_data(host, mrq); } static void sd_normal_rw(struct realtek_pci_sdmmc *host, -- 2.30.2