From patchwork Tue Sep 14 18:20:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 12494343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FBC3C43219 for ; Tue, 14 Sep 2021 18:20:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4A61860FC0 for ; Tue, 14 Sep 2021 18:20:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231990AbhINSWN (ORCPT ); Tue, 14 Sep 2021 14:22:13 -0400 Received: from www.zeus03.de ([194.117.254.33]:56706 "EHLO mail.zeus03.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231863AbhINSV5 (ORCPT ); Tue, 14 Sep 2021 14:21:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=sang-engineering.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=k1; bh=t6jhtQZUmpEfkv mP2YyKc9ut4fUY8OiG9AIu1y5QzNU=; b=CcbgGuBzmgy2sUOa6btPKEpAfWAs6P 2yPuOKtvT+Ewv14S54ayVgJnqjZn8RriGTkR2Fu4d/IaMHx7Xht+uR9g/3I/TnEr fo5xJshcuJHrxw595SH05STzx5BAaFFPq8UlBex90WGJtQmBiCVniLjmL1BPWZUu ea71O/ed0rSsI= Received: (qmail 518145 invoked from network); 14 Sep 2021 20:20:34 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 14 Sep 2021 20:20:34 +0200 X-UD-Smtp-Session: l3s3148p1@7C09o/jLIJEgAwDPXxMyACCkRmvQydX8 From: Wolfram Sang To: linux-mmc@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda , Wolfram Sang Subject: [PATCH 1/3] mmc: core: add helper to send STOP Date: Tue, 14 Sep 2021 20:20:21 +0200 Message-Id: <20210914182023.8103-2-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210914182023.8103-1-wsa+renesas@sang-engineering.com> References: <20210914182023.8103-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org There was a helper in the block layer already, but we need it in other parts soon as well. So, make it more generic by adding the 'retries' parameter and add the helper to mmc_ops. Signed-off-by: Wolfram Sang --- drivers/mmc/core/block.c | 14 +------------- drivers/mmc/core/mmc_ops.h | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 431af5e8be2f..58f1aa5ac33f 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1642,18 +1642,6 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, #define MMC_DATA_RETRIES 2 #define MMC_NO_RETRIES (MMC_MAX_RETRIES + 1) -static int mmc_blk_send_stop(struct mmc_card *card, unsigned int timeout) -{ - struct mmc_command cmd = { - .opcode = MMC_STOP_TRANSMISSION, - .flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC, - /* Some hosts wait for busy anyway, so provide a busy timeout */ - .busy_timeout = timeout, - }; - - return mmc_wait_for_cmd(card->host, &cmd, 5); -} - static int mmc_blk_fix_state(struct mmc_card *card, struct request *req) { struct mmc_queue_req *mqrq = req_to_mmc_queue_req(req); @@ -1663,7 +1651,7 @@ static int mmc_blk_fix_state(struct mmc_card *card, struct request *req) mmc_retune_hold_now(card->host); - mmc_blk_send_stop(card, timeout); + mmc_send_stop(card->host, timeout, 5); err = mmc_poll_for_busy(card, timeout, false, MMC_BUSY_IO); diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index ae25ffc2e870..6e9d1b6b9e55 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -9,6 +9,7 @@ #define _MMC_MMC_OPS_H #include +#include enum mmc_busy_cmd { MMC_BUSY_CMD6, @@ -57,5 +58,18 @@ int mmc_cmdq_enable(struct mmc_card *card); int mmc_cmdq_disable(struct mmc_card *card); int mmc_sanitize(struct mmc_card *card, unsigned int timeout_ms); +static inline int mmc_send_stop(struct mmc_host *host, unsigned int timeout, + unsigned int retries) +{ + struct mmc_command cmd = { + .opcode = MMC_STOP_TRANSMISSION, + .flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC, + /* Some hosts wait for busy anyway, so provide a busy timeout */ + .busy_timeout = timeout, + }; + + return mmc_wait_for_cmd(host, &cmd, retries); +} + #endif From patchwork Tue Sep 14 18:20:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 12494345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFF17C4332F for ; Tue, 14 Sep 2021 18:21:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB11560F44 for ; Tue, 14 Sep 2021 18:21:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231815AbhINSWQ (ORCPT ); Tue, 14 Sep 2021 14:22:16 -0400 Received: from www.zeus03.de ([194.117.254.33]:56720 "EHLO mail.zeus03.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232013AbhINSV5 (ORCPT ); Tue, 14 Sep 2021 14:21:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=sang-engineering.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=k1; bh=FXWtXqpSRzIUuu j9A/bTtWa9z8u/sxFXhKENNzrbSiY=; b=RFzZkChPLbbUKOCIPSk2OJQCa2pxKy MKlSK227gO4FRV7wFmidNL24LIv/jLtSlavz/x8qkmrJVoL06PY8/Hbluc7bj7vK FXle5aq8w3lKcKSm8IXCxaMqR21TezZYVCkFgufFO0dD1O4rnxy+mPQxccuFMbE/ X+tSjH0V8gZo0= Received: (qmail 518175 invoked from network); 14 Sep 2021 20:20:35 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 14 Sep 2021 20:20:35 +0200 X-UD-Smtp-Session: l3s3148p1@x4VDo/jLIpEgAwDPXxMyACCkRmvQydX8 From: Wolfram Sang To: linux-mmc@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda , Wolfram Sang Subject: [PATCH 2/3] mmc: core: also abort tuning with CMD12 for SD Date: Tue, 14 Sep 2021 20:20:22 +0200 Message-Id: <20210914182023.8103-3-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210914182023.8103-1-wsa+renesas@sang-engineering.com> References: <20210914182023.8103-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org We have various SanDisk cards which fail tuning to SDR104 unless we allow a CMD12 also to be sent to abort a broken tuning. It is true that the SD specs do not mention that CMD12 is allowed, but they also don't say it is forbidden. And now reality tells that it is needed to make some cards work. Other cards I tried did not regress. So, add a new callback to the bus_ops which allows us to send STOP for MMC and SD cards but not SDIO which does not support CMD12. Signed-off-by: Wolfram Sang --- Tested with a Renesas Salvator-XS board (R-Car H3 ES2.0) and a SanDisk Ultra 64GB card. drivers/mmc/core/core.h | 1 + drivers/mmc/core/mmc.c | 6 ++++++ drivers/mmc/core/mmc_ops.c | 21 +++------------------ drivers/mmc/core/sd.c | 6 ++++++ 4 files changed, 16 insertions(+), 18 deletions(-) diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 7931a4f0137d..660873ba13ed 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -31,6 +31,7 @@ struct mmc_bus_ops { int (*sw_reset)(struct mmc_host *); bool (*cache_enabled)(struct mmc_host *); int (*flush_cache)(struct mmc_host *); + int (*send_abort_tuning)(struct mmc_host *); }; void mmc_attach_bus(struct mmc_host *host, const struct mmc_bus_ops *ops); diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 29e58ffae379..d638477e0a49 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -2227,6 +2227,11 @@ static int _mmc_hw_reset(struct mmc_host *host) return mmc_init_card(host, card->ocr, card); } +static int _mmc_send_abort_tuning(struct mmc_host *host) +{ + return mmc_send_stop(host, 150, 0); +} + static const struct mmc_bus_ops mmc_ops = { .remove = mmc_remove, .detect = mmc_detect, @@ -2239,6 +2244,7 @@ static const struct mmc_bus_ops mmc_ops = { .hw_reset = _mmc_hw_reset, .cache_enabled = _mmc_cache_enabled, .flush_cache = _mmc_flush_cache, + .send_abort_tuning = _mmc_send_abort_tuning, }; /* diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 0c54858e89c0..bc794419d443 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -705,26 +705,11 @@ EXPORT_SYMBOL_GPL(mmc_send_tuning); int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode) { - struct mmc_command cmd = {}; - - /* - * eMMC specification specifies that CMD12 can be used to stop a tuning - * command, but SD specification does not, so do nothing unless it is - * eMMC. - */ - if (opcode != MMC_SEND_TUNING_BLOCK_HS200) - return 0; + if (host->bus_ops->send_abort_tuning) + return host->bus_ops->send_abort_tuning(host); - cmd.opcode = MMC_STOP_TRANSMISSION; - cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; - - /* - * For drivers that override R1 to R1b, set an arbitrary timeout based - * on the tuning timeout i.e. 150ms. - */ - cmd.busy_timeout = 150; + return 0; - return mmc_wait_for_cmd(host, &cmd, 0); } EXPORT_SYMBOL_GPL(mmc_send_abort_tuning); diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 4646b7a03db6..19c85e6088f4 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -1784,6 +1784,11 @@ static int mmc_sd_hw_reset(struct mmc_host *host) return mmc_sd_init_card(host, host->card->ocr, host->card); } +static int sd_send_abort_tuning(struct mmc_host *host) +{ + return mmc_send_stop(host, 150, 0); +} + static const struct mmc_bus_ops mmc_sd_ops = { .remove = mmc_sd_remove, .detect = mmc_sd_detect, @@ -1796,6 +1801,7 @@ static const struct mmc_bus_ops mmc_sd_ops = { .hw_reset = mmc_sd_hw_reset, .cache_enabled = sd_cache_enabled, .flush_cache = sd_flush_cache, + .send_abort_tuning = sd_send_abort_tuning, }; /* From patchwork Tue Sep 14 18:20:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wolfram Sang X-Patchwork-Id: 12494339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D17F6C433EF for ; Tue, 14 Sep 2021 18:20:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id ADC4860F44 for ; Tue, 14 Sep 2021 18:20:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231800AbhINSWJ (ORCPT ); Tue, 14 Sep 2021 14:22:09 -0400 Received: from www.zeus03.de ([194.117.254.33]:56732 "EHLO mail.zeus03.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232012AbhINSV5 (ORCPT ); Tue, 14 Sep 2021 14:21:57 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple; d=sang-engineering.com; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=k1; bh=g3Ydjt6/rs/V/i wz5INUiD7GrceHhBFduaviPdKRHfI=; b=h1abPQcmUrW6U/2vUtmxIvyA9gQLJT OPnS903OAxAiTseAbSd1FODBXdfK3c8unGdaNI08PkrrZIeeAZx5Et33FcB85vY0 K1tHj6gFrg80Nexavhfgx3ljP1mhoBiyIADxz82WJ3L63QKzCLCkTC1KfW+Qvxqp QiXoeFIQdyDzY= Received: (qmail 518204 invoked from network); 14 Sep 2021 20:20:35 +0200 Received: by mail.zeus03.de with ESMTPSA (TLS_AES_256_GCM_SHA384 encrypted, authenticated); 14 Sep 2021 20:20:35 +0200 X-UD-Smtp-Session: l3s3148p1@BTJKo/jLJJEgAwDPXxMyACCkRmvQydX8 From: Wolfram Sang To: linux-mmc@vger.kernel.org Cc: linux-renesas-soc@vger.kernel.org, Yoshihiro Shimoda , Wolfram Sang Subject: [PATCH 3/3] mmc: core: remove obsolete parameter from mmc_send_abort_tuning Date: Tue, 14 Sep 2021 20:20:23 +0200 Message-Id: <20210914182023.8103-4-wsa+renesas@sang-engineering.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210914182023.8103-1-wsa+renesas@sang-engineering.com> References: <20210914182023.8103-1-wsa+renesas@sang-engineering.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Due to refactoring, this is not needed anymore. Remove it from the core and from drivers. Signed-off-by: Wolfram Sang --- drivers/mmc/core/mmc_ops.c | 2 +- drivers/mmc/host/renesas_sdhi_core.c | 2 +- drivers/mmc/host/sdhci.c | 2 +- include/linux/mmc/host.h | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index bc794419d443..d60750d0f1b9 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -703,7 +703,7 @@ int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error) } EXPORT_SYMBOL_GPL(mmc_send_tuning); -int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode) +int mmc_send_abort_tuning(struct mmc_host *host) { if (host->bus_ops->send_abort_tuning) return host->bus_ops->send_abort_tuning(host); diff --git a/drivers/mmc/host/renesas_sdhi_core.c b/drivers/mmc/host/renesas_sdhi_core.c index 6fc4cf3c9dce..8884ff392935 100644 --- a/drivers/mmc/host/renesas_sdhi_core.c +++ b/drivers/mmc/host/renesas_sdhi_core.c @@ -683,7 +683,7 @@ static int renesas_sdhi_execute_tuning(struct mmc_host *mmc, u32 opcode) set_bit(i, priv->smpcmp); if (cmd_error) - mmc_send_abort_tuning(mmc, opcode); + mmc_send_abort_tuning(mmc); } ret = renesas_sdhi_select_tuning(host); diff --git a/drivers/mmc/host/sdhci.c b/drivers/mmc/host/sdhci.c index 8eefa7d5fe85..8efc029ee21b 100644 --- a/drivers/mmc/host/sdhci.c +++ b/drivers/mmc/host/sdhci.c @@ -2685,7 +2685,7 @@ void sdhci_abort_tuning(struct sdhci_host *host, u32 opcode) sdhci_end_tuning(host); - mmc_send_abort_tuning(host->mmc, opcode); + mmc_send_abort_tuning(host->mmc); } EXPORT_SYMBOL_GPL(sdhci_abort_tuning); diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 0c0c9a0fdf57..890dc5c5ffce 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -633,6 +633,6 @@ static inline enum dma_data_direction mmc_get_dma_dir(struct mmc_data *data) } int mmc_send_tuning(struct mmc_host *host, u32 opcode, int *cmd_error); -int mmc_send_abort_tuning(struct mmc_host *host, u32 opcode); +int mmc_send_abort_tuning(struct mmc_host *host); #endif /* LINUX_MMC_HOST_H */