From patchwork Tue May 4 16:12:12 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238221 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 21FE6C43462 for ; Tue, 4 May 2021 16:12:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F30E7611AC for ; Tue, 4 May 2021 16:12:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231733AbhEDQNc (ORCPT ); Tue, 4 May 2021 12:13:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53062 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231719AbhEDQNc (ORCPT ); Tue, 4 May 2021 12:13:32 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3961C061761 for ; Tue, 4 May 2021 09:12:36 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id z13so14129933lft.1 for ; Tue, 04 May 2021 09:12:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3a82EmNZunJK3ZJbNP0JbGj7NLetG3uE0s2MHagCq3U=; b=wxyfiIk9ZRKFFMu7Qtt5D/PUwNqqFhRB8Wcgj+YyHPHc5cUKgZgwxGiMfRwQCKCNM8 EgWBJpOWPBZhW+XZQhEd32rkfi5DSS9AD3cI21p5SQcsSpTZAhlcmllGAhet3/MF/J3p s33FUkYxOw0T+Z5SMErf9E6yFlscuq5QRNlfX9bnJsKOZ4FjvE6BYu+6TLz4IiAnoSeR bz2shSeX3nc3ijfLvYIiNwG89kPrzMh7qZzQNtb4eX/tiLyb7DpOV6oJHln6oWaOvv3D yN6TRqQNfZfq+1iiZUayBPeByWBNMGnWz10iGW9p55E/ULKjQL6XKyZptpm0iXpKmcva 116Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3a82EmNZunJK3ZJbNP0JbGj7NLetG3uE0s2MHagCq3U=; b=kZEuiGIZ9iAtrzGURt8IgEfQr7Y5quojLNX61Rdk+RXYYWZb37iS3Z93c2dyMRVeRQ AX07WRI6vdbF8CmbuVzUqOGvhnDZZcNQMvta1zIjkhhaYG7uhCV3OmKDR7WfnYKtEQcp ZzHYDIrFsiE0aOs7XxrMDy4bX/vOiDjlM3jlWJ8wfjAX8ZAMFs4zTFenP4p/Wpdm/Nn5 h5dl5qAs2YwEzQZJhxEpkxUEB9dwCPi0IimgjAe/Zy4TvmN44uJt2kqB/sPRYitasS0I VhMGPq+BSSBmxF5yQCWFs23aYOwmxSfCMjnBWO/6fU0N7Y3BonyFbOEw4f1Vii1DQtuj +VGQ== X-Gm-Message-State: AOAM533IcrlzMYnjLuLnQbXJ0mqnYl3Sayrm6SeI6iJ1RrUq+pOTvUed 5Ciiy0GgwFmHb6aR90fX6oafBX0R08uMNl6x X-Google-Smtp-Source: ABdhPJy5ytaKbLf4TX6lQSUesKQr3QHIJFShNZOFpX3OXVXBNCo7ueewQGWviNbTDs02xbIDL2YzkQ== X-Received: by 2002:a19:c510:: with SMTP id w16mr17895584lfe.433.1620144754632; Tue, 04 May 2021 09:12:34 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:33 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 01/11] mmc: core: Drop open coding when preparing commands with busy signaling Date: Tue, 4 May 2021 18:12:12 +0200 Message-Id: <20210504161222.101536-2-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Similar code for validating the host->max_busy_timeout towards the current command's busy timeout, exists in mmc_do_erase(), mmc_sleep() and __mmc_switch(). Let's move the common code into a helper function. Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin --- drivers/mmc/core/core.c | 20 ++---------------- drivers/mmc/core/mmc.c | 20 +++--------------- drivers/mmc/core/mmc_ops.c | 42 +++++++++++++++++++++----------------- drivers/mmc/core/mmc_ops.h | 3 +++ 4 files changed, 31 insertions(+), 54 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index f194940c5974..b00c84ea8441 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1582,7 +1582,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, { struct mmc_command cmd = {}; unsigned int qty = 0, busy_timeout = 0; - bool use_r1b_resp = false; + bool use_r1b_resp; int err; mmc_retune_hold(card->host); @@ -1650,23 +1650,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, cmd.opcode = MMC_ERASE; cmd.arg = arg; busy_timeout = mmc_erase_timeout(card, arg, qty); - /* - * If the host controller supports busy signalling and the timeout for - * the erase operation does not exceed the max_busy_timeout, we should - * use R1B response. Or we need to prevent the host from doing hw busy - * detection, which is done by converting to a R1 response instead. - * Note, some hosts requires R1B, which also means they are on their own - * when it comes to deal with the busy timeout. - */ - if (!(card->host->caps & MMC_CAP_NEED_RSP_BUSY) && - card->host->max_busy_timeout && - busy_timeout > card->host->max_busy_timeout) { - cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_AC; - } else { - cmd.flags = MMC_RSP_SPI_R1B | MMC_RSP_R1B | MMC_CMD_AC; - cmd.busy_timeout = busy_timeout; - use_r1b_resp = true; - } + use_r1b_resp = mmc_prepare_busy_cmd(card->host, &cmd, busy_timeout); err = mmc_wait_for_cmd(card->host, &cmd, 0); if (err) { diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 8674c3e0c02c..63a7bd0b239c 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1910,6 +1910,7 @@ static int mmc_sleep(struct mmc_host *host) struct mmc_command cmd = {}; struct mmc_card *card = host->card; unsigned int timeout_ms = DIV_ROUND_UP(card->ext_csd.sa_timeout, 10000); + bool use_r1b_resp; int err; /* Re-tuning can't be done once the card is deselected */ @@ -1922,22 +1923,7 @@ static int mmc_sleep(struct mmc_host *host) cmd.opcode = MMC_SLEEP_AWAKE; cmd.arg = card->rca << 16; cmd.arg |= 1 << 15; - - /* - * If the max_busy_timeout of the host is specified, validate it against - * the sleep cmd timeout. A failure means we need to prevent the host - * from doing hw busy detection, which is done by converting to a R1 - * response instead of a R1B. Note, some hosts requires R1B, which also - * means they are on their own when it comes to deal with the busy - * timeout. - */ - if (!(host->caps & MMC_CAP_NEED_RSP_BUSY) && host->max_busy_timeout && - (timeout_ms > host->max_busy_timeout)) { - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; - } else { - cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; - cmd.busy_timeout = timeout_ms; - } + use_r1b_resp = mmc_prepare_busy_cmd(host, &cmd, timeout_ms); err = mmc_wait_for_cmd(host, &cmd, 0); if (err) @@ -1949,7 +1935,7 @@ static int mmc_sleep(struct mmc_host *host) * SEND_STATUS command to poll the status because that command (and most * others) is invalid while the card sleeps. */ - if (!cmd.busy_timeout || !(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) + if (!use_r1b_resp || !(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) mmc_delay(timeout_ms); out_release: diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 5756781fef37..025a4134d5c7 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -521,6 +521,27 @@ int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, return __mmc_poll_for_busy(card, timeout_ms, true, false, busy_cmd); } +bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd, + unsigned int timeout_ms) +{ + /* + * If the max_busy_timeout of the host is specified, make sure it's + * enough to fit the used timeout_ms. In case it's not, let's instruct + * the host to avoid HW busy detection, by converting to a R1 response + * instead of a R1B. Note, some hosts requires R1B, which also means + * they are on their own when it comes to deal with the busy timeout. + */ + if (!(host->caps & MMC_CAP_NEED_RSP_BUSY) && host->max_busy_timeout && + (timeout_ms > host->max_busy_timeout)) { + cmd->flags = MMC_CMD_AC | MMC_RSP_SPI_R1 | MMC_RSP_R1; + return false; + } + + cmd->flags = MMC_CMD_AC | MMC_RSP_SPI_R1B | MMC_RSP_R1B; + cmd->busy_timeout = timeout_ms; + return true; +} + /** * __mmc_switch - modify EXT_CSD register * @card: the MMC card associated with the data transfer @@ -543,7 +564,7 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, struct mmc_host *host = card->host; int err; struct mmc_command cmd = {}; - bool use_r1b_resp = true; + bool use_r1b_resp; unsigned char old_timing = host->ios.timing; mmc_retune_hold(host); @@ -554,29 +575,12 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, timeout_ms = card->ext_csd.generic_cmd6_time; } - /* - * If the max_busy_timeout of the host is specified, make sure it's - * enough to fit the used timeout_ms. In case it's not, let's instruct - * the host to avoid HW busy detection, by converting to a R1 response - * instead of a R1B. Note, some hosts requires R1B, which also means - * they are on their own when it comes to deal with the busy timeout. - */ - if (!(host->caps & MMC_CAP_NEED_RSP_BUSY) && host->max_busy_timeout && - (timeout_ms > host->max_busy_timeout)) - use_r1b_resp = false; - cmd.opcode = MMC_SWITCH; cmd.arg = (MMC_SWITCH_MODE_WRITE_BYTE << 24) | (index << 16) | (value << 8) | set; - cmd.flags = MMC_CMD_AC; - if (use_r1b_resp) { - cmd.flags |= MMC_RSP_SPI_R1B | MMC_RSP_R1B; - cmd.busy_timeout = timeout_ms; - } else { - cmd.flags |= MMC_RSP_SPI_R1 | MMC_RSP_R1; - } + use_r1b_resp = mmc_prepare_busy_cmd(host, &cmd, timeout_ms); err = mmc_wait_for_cmd(host, &cmd, retries); if (err) diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index 7bc1cfb0654c..ba898c435658 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -18,6 +18,7 @@ enum mmc_busy_cmd { struct mmc_host; struct mmc_card; +struct mmc_command; int mmc_select_card(struct mmc_card *card); int mmc_deselect_cards(struct mmc_host *host); @@ -35,6 +36,8 @@ int mmc_bus_test(struct mmc_card *card, u8 bus_width); int mmc_can_ext_csd(struct mmc_card *card); int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd); int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal); +bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd, + unsigned int timeout_ms); int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, enum mmc_busy_cmd busy_cmd); int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, From patchwork Tue May 4 16:12:13 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238223 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 1A7C8C433ED for ; Tue, 4 May 2021 16:12:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D0A97611CB for ; Tue, 4 May 2021 16:12:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231756AbhEDQNf (ORCPT ); Tue, 4 May 2021 12:13:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231735AbhEDQNe (ORCPT ); Tue, 4 May 2021 12:13:34 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DBF29C0613ED for ; Tue, 4 May 2021 09:12:38 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2so14109987lft.4 for ; Tue, 04 May 2021 09:12:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0EaNyrJPx800SxJDWlIRfuBN901wRckS9/iskflhAQE=; b=rLqzdYDt2bR1nt+32bTw5Wj2OBKwKaY9mrTO+TeMNsCSJDdsSHogYHXYq5aVUojavE 3LCmWXYW2vY3UAjcjB/f3iKc/sj6kaqqMUPm4/EO9RaJa6D6V5mAWSivkj7fGhnKWuAV UrvtBimlKBhnhYKItjnUr1wwzR9g4K7+MjnfkHv9MyLN6ZNtmBhyFXD1gUiCVeObhn8R 9rT7bJ6X7D4bzJG7yDkJ6XVoqMPt1cZICN+UiFYlAIS0c8ftRV2e172076Fxst9vrAo7 VralKmATjvw3d4BaT3+vwxzZPv4NA3r48RUgGFmcu+i085fi3Cdgy0POR82KLLN+201j 36hw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0EaNyrJPx800SxJDWlIRfuBN901wRckS9/iskflhAQE=; b=c05a2/IlBcBA8/xaxa+QtzNEirz4ZIDwq+vXV9VczQI4O9PAGURpNS8x82cRCAIoJ3 2phorumDA6J+4r7RyEqgak3CYBX7bUi5OeX/ATuFbf77F8TwxR43JEUqQaoffy17mNg+ L3Pm8K0OfHtSEx+qZw9gmdFKwZsGDpksVoy563gh86C6N93R2lO30rqGlpGdVLjcEdI3 EjVTWiiiqKn1i2lwM0V3jCeoG3K5Ksss8ay/jqvukAmtp2fnaWKH3y3h9Nr2vzyhSVJ3 my8iSXKhAiLxG2HnZM1sB5jbG2V+JLFWbaSWCJgHKle41XboY8xJLZj5RM9Io8r5HYon wBdw== X-Gm-Message-State: AOAM5336n9Mog2GKcBkD+t4oyF3A0joucFCY8FPs7HVtfcJkyy/AwJUQ bos2AoqIyTSWAViQzK759OniooZaNoDXwKvc X-Google-Smtp-Source: ABdhPJwJgHrJrftbsHwgtxIfiKijEzdjusVilj+/efOsaaWnqgmRssrUyapG+NpbSFPTrxS8x3rgWA== X-Received: by 2002:ac2:5fcb:: with SMTP id q11mr17218402lfg.248.1620144756714; Tue, 04 May 2021 09:12:36 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:35 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 02/11] mmc: core: Take into account MMC_CAP_NEED_RSP_BUSY for eMMC HPI commands Date: Tue, 4 May 2021 18:12:13 +0200 Message-Id: <20210504161222.101536-3-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org In mmc_send_hpi_cmd() the host->max_busy_timeout is being validated towards the timeout for the eMMC HPI command, as to decide whether an R1 or R1B response should be used. Although, it has turned out the some host can't cope with that conversion, but needs R1B, which means MMC_CAP_NEED_RSP_BUSY is set for them. Let's take this into account, via using the common mmc_prepare_busy_cmd() when doing the validation, which also avoids some open coding. Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin --- drivers/mmc/core/mmc_ops.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 025a4134d5c7..66ae699a410f 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -817,28 +817,17 @@ static int mmc_send_hpi_cmd(struct mmc_card *card) { unsigned int busy_timeout_ms = card->ext_csd.out_of_int_time; struct mmc_host *host = card->host; - bool use_r1b_resp = true; + bool use_r1b_resp = false; struct mmc_command cmd = {}; int err; cmd.opcode = card->ext_csd.hpi_cmd; cmd.arg = card->rca << 16 | 1; + cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; - /* - * Make sure the host's max_busy_timeout fit the needed timeout for HPI. - * In case it doesn't, let's instruct the host to avoid HW busy - * detection, by using a R1 response instead of R1B. - */ - if (host->max_busy_timeout && busy_timeout_ms > host->max_busy_timeout) - use_r1b_resp = false; - - if (cmd.opcode == MMC_STOP_TRANSMISSION && use_r1b_resp) { - cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; - cmd.busy_timeout = busy_timeout_ms; - } else { - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; - use_r1b_resp = false; - } + if (cmd.opcode == MMC_STOP_TRANSMISSION) + use_r1b_resp = mmc_prepare_busy_cmd(host, &cmd, + busy_timeout_ms); err = mmc_wait_for_cmd(host, &cmd, 0); if (err) { From patchwork Tue May 4 16:12:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238225 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 610D3C43460 for ; Tue, 4 May 2021 16:12:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2FBC5610A7 for ; Tue, 4 May 2021 16:12:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231750AbhEDQNh (ORCPT ); Tue, 4 May 2021 12:13:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53082 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231744AbhEDQNg (ORCPT ); Tue, 4 May 2021 12:13:36 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3B2CC0613ED for ; Tue, 4 May 2021 09:12:40 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id n138so14140181lfa.3 for ; Tue, 04 May 2021 09:12:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/ee795yxnzHs29v3TjQa721b4l02PWsrUGNagPQX+uQ=; b=dHVCBXheSA/nPVW+TvqCQLGQZ10Py/jY6VqG4/6GNO7B5xKIefq2DXnenApc2gSdUp LP0AhRlyrY2mAHLH5pEaY894wET3dw1t3OcPjOeGQBDR3LhjKQfGucKOHTk5Y6pKT93f AR6uaY5SgrPu9fbqt4QgOsjNRWz4n997XqkGaqJpv53dnQtL0VZ2Jnwf3OhUjzxLeb9G ZgcW+q0mWP3l2y9syoSGF1+Dele0STkqqimV2XS0jpUoKnw5xl1wswtj00ZM5/V0MJ35 jsTFwUki0BL0LkhtTiIX15Wn3zlmim4qHrxgnSB9MOlGtPwqzjVInl6MCzas7VubLfKO Asuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/ee795yxnzHs29v3TjQa721b4l02PWsrUGNagPQX+uQ=; b=EEBo19izUSRg9PzYBzEEN6haNB/zMmUW93cNdXFSTgybbajaaHK85wzwQLyF9ayqIh tDOvFrXWcfFfGF1HelRCbkq/m3vJzWQRjTyAE+z8ALmw4CdZcws2qzqJlnP4/PwxYqSn dY7A97wYDQgmF1KUzlf+oFJTJcP89XoBcCyY5BIg1KVqlyuLxeiPBRa1ttGEPVs0vbNY A9yPoeAfZzHzoucoh18p4c1F3+AljSD3956VkW8BZ+GbAmCc51Oxit3R+5P/b+Xuu02x pgZTm65FlXZoSsctUmFzE6s3Rj2zEbZltVJYYCPQf38smImEgS44i90zjFoxu6jKzWuF OXew== X-Gm-Message-State: AOAM531w5UGoZRvNTTChst2vonYijVQs45UE3Zs0pgJCp5WI4ln7Jt+x elIiTR/z1Pjrt5uYJkLqNJYRjjMd4UJAVe3M X-Google-Smtp-Source: ABdhPJwaLC553y4EWUnONr50m/PHQiryaxLapFqcwSYnqXkOCKi79+Q6m6D8DiB+LSijTT4KL2vyaw== X-Received: by 2002:a19:4849:: with SMTP id v70mr17190047lfa.590.1620144758840; Tue, 04 May 2021 09:12:38 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:37 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/11] mmc: core: Re-structure some code in __mmc_poll_for_busy() Date: Tue, 4 May 2021 18:12:14 +0200 Message-Id: <20210504161222.101536-4-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org To make the code a bit more understandable, let's move the check about whether polling is allowed or not, out to the caller instead. In this way, we can also drop the send_status in-parameter, so let's do that. Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin --- drivers/mmc/core/mmc_ops.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 66ae699a410f..ccaee1cb7ff5 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -465,8 +465,7 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, } static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, - bool send_status, bool retry_crc_err, - enum mmc_busy_cmd busy_cmd) + bool retry_crc_err, enum mmc_busy_cmd busy_cmd) { struct mmc_host *host = card->host; int err; @@ -475,16 +474,6 @@ static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, bool expired = false; bool busy = false; - /* - * In cases when not allowed to poll by using CMD13 or because we aren't - * capable of polling by using ->card_busy(), then rely on waiting the - * stated timeout to be sufficient. - */ - if (!send_status && !host->ops->card_busy) { - mmc_delay(timeout_ms); - return 0; - } - timeout = jiffies + msecs_to_jiffies(timeout_ms) + 1; do { /* @@ -518,7 +507,7 @@ static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, enum mmc_busy_cmd busy_cmd) { - return __mmc_poll_for_busy(card, timeout_ms, true, false, busy_cmd); + return __mmc_poll_for_busy(card, timeout_ms, false, busy_cmd); } bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd, @@ -591,8 +580,18 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, mmc_host_is_spi(host)) goto out_tim; + /* + * If the host doesn't support HW polling via the ->card_busy() ops and + * when it's not allowed to poll by using CMD13, then we need to rely on + * waiting the stated timeout to be sufficient. + */ + if (!send_status && !host->ops->card_busy) { + mmc_delay(timeout_ms); + goto out_tim; + } + /* Let's try to poll to find out when the command is completed. */ - err = __mmc_poll_for_busy(card, timeout_ms, send_status, retry_crc_err, + err = __mmc_poll_for_busy(card, timeout_ms, retry_crc_err, MMC_BUSY_CMD6); if (err) goto out; From patchwork Tue May 4 16:12:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238227 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 3110CC43470 for ; Tue, 4 May 2021 16:12:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0F134610A7 for ; Tue, 4 May 2021 16:12:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231779AbhEDQNj (ORCPT ); Tue, 4 May 2021 12:13:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231768AbhEDQNi (ORCPT ); Tue, 4 May 2021 12:13:38 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08DE4C06174A for ; Tue, 4 May 2021 09:12:43 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id c3so10056911lfs.7 for ; Tue, 04 May 2021 09:12:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=v4QtfaGRpyWEeOpttGEoGwuwCU8/+wjbWkEbFI1DKy8=; b=xNPTrT0PNqf0Qw8c+KbvpzqPpCjDtGX3yVuSHicPqaC8XNqkvk9DC4JEW/6vmsZWdk IpWLjIas9hI1O7Z9blr6mxKAdCS1fD5zDPZ0IznMT49CkoYaLTXnBiu0dkYIfvdO9bWP pqbem6g1S1atUD4fvQZfFaBE4WQstVoddK74imXD8sQae3XBJWvjLqRpSsJQB/nU9nYo hLAQImj7C1mHNAxgI6sHY1wBzkKi7yxDBvwN2r3BU20Z5a5U3AfIcrsPgbczgp0/4Ssj /lNeZw0/tCA2TaHeC1DrqDS/HkzmkwjPlW61RJB3O0Zajunv4H9xwiruNynIUPijYKLl /GTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=v4QtfaGRpyWEeOpttGEoGwuwCU8/+wjbWkEbFI1DKy8=; b=VLf66KklB7RvlaMzOWfv/7b/PutGZ+7GiEH13Y5/MkcY887Zt88Bt/tCWo+QDnPcYb XXS/nlZQm1W5S6Tobx5ZolZZ1GcKK04klZOwPvahz2nKZ9dtSXLP8ZFYjmjn3kM5ZQEh /CYrV4I5m50FjY5rJLCMz36jfqhNnEF2JagcUeCthjRWOD824ZSBFv5H2trWLT/PvBCs NqwbgdM8scU40J3eDRSTZTX55bjxIFQ8QdggVi2lJ260dJHf8CB67yv8ztlR8ujHlc30 9NAvcWF4Dq6o6j1Y9XGMDCHP3+gtXmR/bvw45HhDg+oP5SXH7M0BMzHbOePQNU7r5Npd bL3A== X-Gm-Message-State: AOAM530two8LZmgisOKRs1PVVvGarXnqL1tb9wXq73f0Q4U2R28UsOdd B32F5vERz4jeayh/mhT1lL6xd3KHH/Qoa2qY X-Google-Smtp-Source: ABdhPJx1wt6VMGFLlriL4jaDRSlTuppXDkgOtyiEw05YgzMo9uI39oyIeRs69QNapeDY4v085rOv9A== X-Received: by 2002:ac2:5e99:: with SMTP id b25mr6296576lfq.288.1620144760786; Tue, 04 May 2021 09:12:40 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:39 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/11] mmc: core: Extend re-use of __mmc_poll_for_busy() Date: Tue, 4 May 2021 18:12:15 +0200 Message-Id: <20210504161222.101536-5-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Via __mmc_poll_for_busy() we end up polling with the ->card_busy() host ops or by sending the CMD13. To allow polling of different types, which is needed to support a few new SD card features, let's rework the code around __mmc_poll_for_busy() to make it more generic. More precisely, let __mmc_poll_for_busy() take a pointer to a callback function as in-parameter, which it calls to poll for busy state completion. Additionally, let's share __mmc_poll_for_busy() to allow it to be re-used outside of mmc_ops.c. Subsequent changes will make use of it. Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin --- drivers/mmc/core/core.c | 2 +- drivers/mmc/core/mmc_ops.c | 42 ++++++++++++++++++++++++-------------- drivers/mmc/core/mmc_ops.h | 5 ++++- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index b00c84ea8441..b039dcff17f8 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1671,7 +1671,7 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, goto out; /* Let's poll to find out when the erase operation completes. */ - err = mmc_poll_for_busy(card, busy_timeout, MMC_BUSY_ERASE); + err = mmc_poll_for_busy(card, busy_timeout, false, MMC_BUSY_ERASE); out: mmc_retune_release(card->host); diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index ccaee1cb7ff5..653627fe02a3 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -53,6 +53,12 @@ static const u8 tuning_blk_pattern_8bit[] = { 0xff, 0x77, 0x77, 0xff, 0x77, 0xbb, 0xdd, 0xee, }; +struct mmc_busy_data { + struct mmc_card *card; + bool retry_crc_err; + enum mmc_busy_cmd busy_cmd; +}; + int __mmc_send_status(struct mmc_card *card, u32 *status, unsigned int retries) { int err; @@ -424,10 +430,10 @@ int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal) return mmc_switch_status_error(card->host, status); } -static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, - enum mmc_busy_cmd busy_cmd, bool *busy) +static int mmc_busy_cb(void *cb_data, bool *busy) { - struct mmc_host *host = card->host; + struct mmc_busy_data *data = cb_data; + struct mmc_host *host = data->card->host; u32 status = 0; int err; @@ -436,17 +442,17 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, return 0; } - err = mmc_send_status(card, &status); - if (retry_crc_err && err == -EILSEQ) { + err = mmc_send_status(data->card, &status); + if (data->retry_crc_err && err == -EILSEQ) { *busy = true; return 0; } if (err) return err; - switch (busy_cmd) { + switch (data->busy_cmd) { case MMC_BUSY_CMD6: - err = mmc_switch_status_error(card->host, status); + err = mmc_switch_status_error(host, status); break; case MMC_BUSY_ERASE: err = R1_STATUS(status) ? -EIO : 0; @@ -464,8 +470,9 @@ static int mmc_busy_status(struct mmc_card *card, bool retry_crc_err, return 0; } -static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, - bool retry_crc_err, enum mmc_busy_cmd busy_cmd) +int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, + int (*busy_cb)(void *cb_data, bool *busy), + void *cb_data) { struct mmc_host *host = card->host; int err; @@ -482,7 +489,7 @@ static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, */ expired = time_after(jiffies, timeout); - err = mmc_busy_status(card, retry_crc_err, busy_cmd, &busy); + err = (*busy_cb)(cb_data, &busy); if (err) return err; @@ -505,9 +512,15 @@ static int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, } int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, - enum mmc_busy_cmd busy_cmd) + bool retry_crc_err, enum mmc_busy_cmd busy_cmd) { - return __mmc_poll_for_busy(card, timeout_ms, false, busy_cmd); + struct mmc_busy_data cb_data; + + cb_data.card = card; + cb_data.retry_crc_err = retry_crc_err; + cb_data.busy_cmd = busy_cmd; + + return __mmc_poll_for_busy(card, timeout_ms, &mmc_busy_cb, &cb_data); } bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd, @@ -591,8 +604,7 @@ int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, } /* Let's try to poll to find out when the command is completed. */ - err = __mmc_poll_for_busy(card, timeout_ms, retry_crc_err, - MMC_BUSY_CMD6); + err = mmc_poll_for_busy(card, timeout_ms, retry_crc_err, MMC_BUSY_CMD6); if (err) goto out; @@ -840,7 +852,7 @@ static int mmc_send_hpi_cmd(struct mmc_card *card) return 0; /* Let's poll to find out when the HPI request completes. */ - return mmc_poll_for_busy(card, busy_timeout_ms, MMC_BUSY_HPI); + return mmc_poll_for_busy(card, busy_timeout_ms, false, MMC_BUSY_HPI); } /** diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index ba898c435658..aca66c128804 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -38,8 +38,11 @@ int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd); int mmc_switch_status(struct mmc_card *card, bool crc_err_fatal); bool mmc_prepare_busy_cmd(struct mmc_host *host, struct mmc_command *cmd, unsigned int timeout_ms); +int __mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, + int (*busy_cb)(void *cb_data, bool *busy), + void *cb_data); int mmc_poll_for_busy(struct mmc_card *card, unsigned int timeout_ms, - enum mmc_busy_cmd busy_cmd); + bool retry_crc_err, enum mmc_busy_cmd busy_cmd); int __mmc_switch(struct mmc_card *card, u8 set, u8 index, u8 value, unsigned int timeout_ms, unsigned char timing, bool send_status, bool retry_crc_err, unsigned int retries); From patchwork Tue May 4 16:12:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238229 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 176F5C43460 for ; Tue, 4 May 2021 16:12:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D87D3610A7 for ; Tue, 4 May 2021 16:12:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231797AbhEDQNl (ORCPT ); Tue, 4 May 2021 12:13:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231769AbhEDQNk (ORCPT ); Tue, 4 May 2021 12:13:40 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D592C0613ED for ; Tue, 4 May 2021 09:12:45 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id j10so14068559lfb.12 for ; Tue, 04 May 2021 09:12:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BD0REsdi9mYrsTQHgnQYm8ynmTMvDhWbCRyzYdtenaE=; b=BNrJU8ETwTzMQmDoewcwRrwdt+JF/8bPFkNqC9iSYX8GmcOdxoZUPWw9E4k0cnGKvk 77PhDK128+Z1d73zP2zPsDGLqcOZA04MD5Ys3wFNpOmsNZv1z0Yak4clljxF8NwEiVdY y93x/3Sx8ITu7wIKkkWw5t/QHsdQzwokdnLWsU4akPfRIFxjPS6u6rNGB9xbC6z4Rhvi PdxHhC34fXzWlJpQGf92/0W5QoV76LROJ3y3ExKR0XPlE2ByVMXKdaclarn5RP7OSIb6 5vrWZawduBZ9kpPE+YYKSt5n9MKaPfD65yTIMiZvkIGJb9mEJhqntqAbw9r+PTdPsM1i mtAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BD0REsdi9mYrsTQHgnQYm8ynmTMvDhWbCRyzYdtenaE=; b=aDNGDXu+dK8YKZ0u0UIerPUjV7jynEWbGVfwIUt0vjGjkRsZQbvrc0vnUGSoX+66q2 gMHIMHc6TYGwPtQPjUxadAohgsUentMlsluo/9wfDDphbOMCBr1eGmOvytgcKUJVnH45 N1Zki5jr5lMrhmJyY2T7nQ9KTBLh3c1h4bWD6L44TwULdLEBSefBwCSoaWSD7bTlLeVl 1KLRUdKKvY44ibypnAxvLdO0+bMn8oEwpzF+k14B7Tc4bu4q68FwPKFkhHffZJFb1uxo O1s1l6YjYaPzxuzrwTPp/ur8x7BRccd0wirZzmdF5fCIUW3cIyLjCr6rKdSUih6xOEOw XABg== X-Gm-Message-State: AOAM532ypON5eQ1F4oVb0g/lfij6B3ahV2hkm9/n5+IqC0W6LZJGfPnv NKhqdfUTDyURZwJ26vOgyqeYpUnoqb+z0cMn X-Google-Smtp-Source: ABdhPJzTWescUDGeNdcqNOKmn/4NYKWiyZROmOnTzqAYSbKve6znLgTJKGetZjhuqJS77CByg7cxeQ== X-Received: by 2002:a19:48d7:: with SMTP id v206mr17301695lfa.629.1620144763115; Tue, 04 May 2021 09:12:43 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:41 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 05/11] mmc: core: Enable eMMC sleep commands to use HW busy polling Date: Tue, 4 May 2021 18:12:16 +0200 Message-Id: <20210504161222.101536-6-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org After the eMMC sleep command (CMD5) has been sent, the card start signals busy on the DAT0 line, which can be monitored to understand when it's allowed to proceed to power off the VCC regulator. When MMC_CAP_WAIT_WHILE_BUSY isn't supported by the host the DAT0 line isn't being monitored for busy completion, but instead we are waiting a fixed period of time. The time corresponds to the sleep timeout that is specified in the EXT_CSD register of the eMMC card. This is many cases suboptimal, as the timeout corresponds to the worst case scenario. To improve the situation add support for HW busy polling through the ->card_busy() host ops, when the host supports this. Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin --- drivers/mmc/core/mmc.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 63a7bd0b239c..13074aa1f605 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -1905,6 +1905,14 @@ static int mmc_can_sleep(struct mmc_card *card) return card->ext_csd.rev >= 3; } +static int mmc_sleep_busy_cb(void *cb_data, bool *busy) +{ + struct mmc_host *host = cb_data; + + *busy = host->ops->card_busy(host); + return 0; +} + static int mmc_sleep(struct mmc_host *host) { struct mmc_command cmd = {}; @@ -1930,13 +1938,20 @@ static int mmc_sleep(struct mmc_host *host) goto out_release; /* - * If the host does not wait while the card signals busy, then we will - * will have to wait the sleep/awake timeout. Note, we cannot use the - * SEND_STATUS command to poll the status because that command (and most - * others) is invalid while the card sleeps. + * If the host does not wait while the card signals busy, then we can + * try to poll, but only if the host supports HW polling, as the + * SEND_STATUS cmd is not allowed. If we can't poll, then we simply need + * to wait the sleep/awake timeout. */ - if (!use_r1b_resp || !(host->caps & MMC_CAP_WAIT_WHILE_BUSY)) + if (host->caps & MMC_CAP_WAIT_WHILE_BUSY && use_r1b_resp) + goto out_release; + + if (!host->ops->card_busy) { mmc_delay(timeout_ms); + goto out_release; + } + + err = __mmc_poll_for_busy(card, timeout_ms, &mmc_sleep_busy_cb, host); out_release: mmc_retune_release(host); From patchwork Tue May 4 16:12:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238247 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 1922FC433B4 for ; Tue, 4 May 2021 16:12:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E5079613C0 for ; Tue, 4 May 2021 16:12:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231851AbhEDQNr (ORCPT ); Tue, 4 May 2021 12:13:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231808AbhEDQNm (ORCPT ); Tue, 4 May 2021 12:13:42 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D6FFC061761 for ; Tue, 4 May 2021 09:12:47 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id c11so14080588lfi.9 for ; Tue, 04 May 2021 09:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TbWXoJHQ0uWHFVcBWf57QwZSLHYhmQWZi0APC0CkQ08=; b=gExKlqDoKgJalaIZaU8BM2x89Hb4Dohp9KedfOXruDPXVcWDkbMIubEXRTev60u9Th HcZRM3d7e8VDENDbx9lfI6MezGAisJxM1un5F/Yi1e2NR23HxAFVr0MsR2xpmDyh/tL8 AEeIZn3rjHu66iBNPk3Dxe0fZ1LYs5keoyuEWGyNZAnb2ica6U0UeMr3NXzO35CiwVxi tsEszOaRd4F+OAR65+/pPl8pDiWdMZHW3pk+2xZOqB9Vp0l/GgNuBNWLE499L+A9Q+LJ Ku+PuQzagL5cp1qjHyUWmkt8mhIVkYt/L+FCAgIga1xTunlbn3N3Z9DAQwIJpighfA8X 567A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TbWXoJHQ0uWHFVcBWf57QwZSLHYhmQWZi0APC0CkQ08=; b=TCg4J851Q8o65I3PH96B1bcZ0J7gv10VEqEC0i/6eiiFjverNHbNMCZE2AQzaPOLpQ /q/3YBZrjA0/lhsnhHJBamyPhtef2D5fZprmj0vGaenP0ZzEtdwId1a5UHtCMoKDEoIq NVcWfSD3qGxsPxkFKbzZA/bltxDN3be5YUZqn6BTQ2mXSiuhlfYq7YUUPrQITCKLUH/7 2EAhLkFOBZwA/MYcQOfoWm5hyfK6WbKbS0Asd7wwTJ2t8zA9Prl74Obl5awTt0vWjer0 cJEZW62EwhNtXUNn+SPlw/XnfQeWTqQ6tVdSMmiSBrq4Ak6/K9WmU0M/JKELiDC3TRUq dECw== X-Gm-Message-State: AOAM5322skMvGWAJ3e8CojWRuRjMnf0y7PdxLubCvPe9hY6RwB0PZzXT 7hO2l68QhWnaF6G8vBzXEdSI0UnZuNGb6pB0 X-Google-Smtp-Source: ABdhPJyvMw01Rzrp2T1AFFthQkcduusLKNZ1Zsiz/LYkrImYWZ59EDKdnOxO8rE7EoDsNLHKgHvDrA== X-Received: by 2002:a19:ac4a:: with SMTP id r10mr17287804lfc.112.1620144765023; Tue, 04 May 2021 09:12:45 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:44 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 06/11] mmc: core: Prepare mmc_send_cxd_data() to be re-used for additional cmds Date: Tue, 4 May 2021 18:12:17 +0200 Message-Id: <20210504161222.101536-7-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The function mmc_send_cxd_data() sends a data read command of ADTC type and prepares to receive an R1 response. To make it even more re-usable, let's extend it with another in-parameter for the command argument. While at it, let's also rename the function to mmc_send_adtc_data() as it better describes its purpose. Note that, this change doesn't add any new users of the function. Instead that is done from subsequent changes. Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin --- drivers/mmc/core/mmc_ops.c | 11 +++++------ drivers/mmc/core/mmc_ops.h | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 653627fe02a3..b1da8f1950ee 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -252,9 +252,8 @@ mmc_send_cxd_native(struct mmc_host *host, u32 arg, u32 *cxd, int opcode) * NOTE: void *buf, caller for the buf is required to use DMA-capable * buffer or on-stack buffer (with some overhead in callee). */ -static int -mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host, - u32 opcode, void *buf, unsigned len) +int mmc_send_adtc_data(struct mmc_card *card, struct mmc_host *host, u32 opcode, + u32 args, void *buf, unsigned len) { struct mmc_request mrq = {}; struct mmc_command cmd = {}; @@ -265,7 +264,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host, mrq.data = &data; cmd.opcode = opcode; - cmd.arg = 0; + cmd.arg = args; /* NOTE HACK: the MMC_RSP_SPI_R1 is always correct here, but we * rely on callers to never use this with "native" calls for reading @@ -311,7 +310,7 @@ static int mmc_spi_send_cxd(struct mmc_host *host, u32 *cxd, u32 opcode) if (!cxd_tmp) return -ENOMEM; - ret = mmc_send_cxd_data(NULL, host, opcode, cxd_tmp, 16); + ret = mmc_send_adtc_data(NULL, host, opcode, 0, cxd_tmp, 16); if (ret) goto err; @@ -359,7 +358,7 @@ int mmc_get_ext_csd(struct mmc_card *card, u8 **new_ext_csd) if (!ext_csd) return -ENOMEM; - err = mmc_send_cxd_data(card, card->host, MMC_SEND_EXT_CSD, ext_csd, + err = mmc_send_adtc_data(card, card->host, MMC_SEND_EXT_CSD, 0, ext_csd, 512); if (err) kfree(ext_csd); diff --git a/drivers/mmc/core/mmc_ops.h b/drivers/mmc/core/mmc_ops.h index aca66c128804..2b1d730e56bf 100644 --- a/drivers/mmc/core/mmc_ops.h +++ b/drivers/mmc/core/mmc_ops.h @@ -26,6 +26,8 @@ int mmc_set_dsr(struct mmc_host *host); int mmc_go_idle(struct mmc_host *host); int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr); int mmc_set_relative_addr(struct mmc_card *card); +int mmc_send_adtc_data(struct mmc_card *card, struct mmc_host *host, u32 opcode, + u32 args, void *buf, unsigned len); int mmc_send_csd(struct mmc_card *card, u32 *csd); int __mmc_send_status(struct mmc_card *card, u32 *status, unsigned int retries); int mmc_send_status(struct mmc_card *card, u32 *status); From patchwork Tue May 4 16:12:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238249 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 E62E1C433B4 for ; Tue, 4 May 2021 16:13:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C3E5A611AC for ; Tue, 4 May 2021 16:13:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231875AbhEDQNy (ORCPT ); Tue, 4 May 2021 12:13:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231834AbhEDQNq (ORCPT ); Tue, 4 May 2021 12:13:46 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D736C06138C for ; Tue, 4 May 2021 09:12:49 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id x20so14124572lfu.6 for ; Tue, 04 May 2021 09:12:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RnseO+HlWfm8PnP329KlCqz9KF+klL6BviqqSWTWuio=; b=lgIb6O2YX+Ez0RMKw2US7fma0pchqhR4ksTVapAcxtj4ryBpTR93IrbfTqcGMVMAPL rxvWkxeBiHUzjrxc52/H0TDvuEw7y3w9XqDH59uP0LDM0HAEKWVvDGpvznJ1Tp0YjcKE lDHoyyuqx+7iGXZv3dfcz6jCik43KPq46pPmTKQvyOwQUxjm+ECvEDM5G6F7fRyNt5+z IEmxzZi8sEODp1XIe5hTgspTD+ANs14cC7FGdv4E5JURrrQwm3uRAEhM7hDtwl51KInE J9+zp26pXYSmhtdunLd728m1ItkWJLG4+ytaYzejqFlLqiJVzhr8EK6vyhM5/nc7mMEM VRTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RnseO+HlWfm8PnP329KlCqz9KF+klL6BviqqSWTWuio=; b=TZcx6oZG7W+xDZeoC04o5izzjOPZIEn4sCcEUrnJeagw7ThVJOiElkXK2OQs120UE8 bSp0ARTzFwmSkk57QpfPyEb5WEHiLi+ythwKJg+4uRRYACfYz81YsggyqI74B7YlUgqg XHodToO48+xhKl9JT7LcMuvkt1CAmYA6PTioKBLnJHW4B4WmI5AtL1LuIPHJWJfewxL9 aPKAhPCFXduLvmJjqOCQYY9VApG9zQMpmnKGqlkW9AeZJKntSr2lLHPjkKX51zqetU4P fHc9xsBvwGw2QASVeawIV1hzZXa3Cxe8ErQYuJkLjBA//WTOU7+Su8nko8ktp4Ob5Sy9 0wUg== X-Gm-Message-State: AOAM531ggB6nQ4FuJb+ieUlu9Il6DeTAfI7YUUZcgrQn5na5Og20BbHZ H4jQSx0+nUvEslsLR3p3Y4V3fYjV9twXGUpd X-Google-Smtp-Source: ABdhPJztL23XdscbpvYGwlpduSQ+/7dS5kub7ci6q1CTV7oAB7WUi7fOy7SpxGt3MMA8cz6xqA4yOw== X-Received: by 2002:ac2:5289:: with SMTP id q9mr3001194lfm.141.1620144766986; Tue, 04 May 2021 09:12:46 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:45 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/11] mmc: core: Drop open coding in mmc_sd_switch() Date: Tue, 4 May 2021 18:12:18 +0200 Message-Id: <20210504161222.101536-8-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The SD_SWITCH (CMD6) is an ADTC type of command with an R1 response, which can be sent by using the mmc_send_adtc_data(). Let's do that and drop the open coding in mmc_sd_switch(). Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin --- drivers/mmc/core/sd_ops.c | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c index d61ff811218c..ef8d1dce5af1 100644 --- a/drivers/mmc/core/sd_ops.c +++ b/drivers/mmc/core/sd_ops.c @@ -17,6 +17,7 @@ #include "core.h" #include "sd_ops.h" +#include "mmc_ops.h" int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card) { @@ -309,43 +310,18 @@ int mmc_app_send_scr(struct mmc_card *card) int mmc_sd_switch(struct mmc_card *card, int mode, int group, u8 value, u8 *resp) { - struct mmc_request mrq = {}; - struct mmc_command cmd = {}; - struct mmc_data data = {}; - struct scatterlist sg; + u32 cmd_args; /* NOTE: caller guarantees resp is heap-allocated */ mode = !!mode; value &= 0xF; + cmd_args = mode << 31 | 0x00FFFFFF; + cmd_args &= ~(0xF << (group * 4)); + cmd_args |= value << (group * 4); - mrq.cmd = &cmd; - mrq.data = &data; - - cmd.opcode = SD_SWITCH; - cmd.arg = mode << 31 | 0x00FFFFFF; - cmd.arg &= ~(0xF << (group * 4)); - cmd.arg |= value << (group * 4); - cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R1 | MMC_CMD_ADTC; - - data.blksz = 64; - data.blocks = 1; - data.flags = MMC_DATA_READ; - data.sg = &sg; - data.sg_len = 1; - - sg_init_one(&sg, resp, 64); - - mmc_set_data_timeout(&data, card); - - mmc_wait_for_req(card->host, &mrq); - - if (cmd.error) - return cmd.error; - if (data.error) - return data.error; - - return 0; + return mmc_send_adtc_data(card, card->host, SD_SWITCH, cmd_args, resp, + 64); } int mmc_app_sd_status(struct mmc_card *card, void *ssr) From patchwork Tue May 4 16:12:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238251 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 11310C433ED for ; Tue, 4 May 2021 16:13:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5C23613BA for ; Tue, 4 May 2021 16:13:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231995AbhEDQOL (ORCPT ); Tue, 4 May 2021 12:14:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231811AbhEDQNs (ORCPT ); Tue, 4 May 2021 12:13:48 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EBE91C0613ED for ; Tue, 4 May 2021 09:12:50 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id h4so6486582lfv.0 for ; Tue, 04 May 2021 09:12:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3YPvSgtMwuWKmsANJZN3wDrqLMspZZxchfU1o9bNBS0=; b=mQphSbjpUQsny9Y+iTx74acCw2RC/7Rw66VAAOnWDQUbQN8E9LjjfCVAzjwDg73JYA 2IIFyaDZjid8qqdoeGQAIR3C515ImGXr120DHipM+PWv/A7IWFOERw4csxR8Xz3MfWLM BXA++rt0qv0y7yOl7xPOtANwFhnssW285d9b7MaIeL/719Jnyeb7Fl7m9GuBgfjiVELN ofhx+tgSVyM2kJoNjey09xJSfBxoagBzS0jZrS5u5+1y1oM7dYuX66Vx3x778dqu120z AIVs+p3XrD8Ngj1UbGm3GJ74xLM090JwCD/Eh0r13hdXrw6GlBAK/t+2pAA/afENElZM c5Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3YPvSgtMwuWKmsANJZN3wDrqLMspZZxchfU1o9bNBS0=; b=p6m+yan9NTjOjv30D2KE3cTlWDrxKH2xp5TDgeTewPwILO0OUX+jldDp+ROhI4SePJ COGKEp8qHT/FeCmzCqGVlw4C/vWL7H+bQCK8LUAaYzkL8bsW746ajk9JOCL3nlGmP+gq KyPUQGmWUNEJs1N+UovX91jiF7jbh5hIYC6u3SEj4csyZULKCE/pGZ4c0pnCoMsy6C/k 8tsuCCsibYwVNsDSwHPtdT7L7iU0yO+pU8d6b2eswA8kCb1VdBkatyDDrqfZVosN7MSI 2I3TPPfgBitQBVe2x6jbpbofXmQylDt68JJrE0nIX3dfcmb6gEb1lBv+Ie/q0mf/YTW4 w+IQ== X-Gm-Message-State: AOAM532Do+9tNzxck90aWKTa7lWGdhj39C0KFB7Rb3O6SwIftCp2KGqJ 0nLxm+FR5agbGa+N9x9Pu/GcRUWeowJCMz4l X-Google-Smtp-Source: ABdhPJzEg4JyZbtiP7/8bkCcH2v8n2BiNms886QzrgiideGRN2RshaK0sMxOvd1N+Ux3WM8cYYi4Ig== X-Received: by 2002:a05:6512:c0a:: with SMTP id z10mr17587062lfu.467.1620144768925; Tue, 04 May 2021 09:12:48 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:48 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 08/11] mmc: core: Parse the SD SCR register for support of CMD48/49 and CMD58/59 Date: Tue, 4 May 2021 18:12:19 +0200 Message-Id: <20210504161222.101536-9-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org In SD spec v4.x the support for CMD48/49 and CMD58/59 were introduced as optional features. To let the card announce whether it supports the commands, the SCR register has been extended with corresponding support bits. Let's parse and store this information for later use. Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin --- drivers/mmc/core/sd.c | 4 +++- include/linux/mmc/card.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 2c48d6504101..de7b5f8df550 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -222,7 +222,9 @@ static int mmc_decode_scr(struct mmc_card *card) else card->erased_byte = 0x0; - if (scr->sda_spec3) + if (scr->sda_spec4) + scr->cmds = UNSTUFF_BITS(resp, 32, 4); + else if (scr->sda_spec3) scr->cmds = UNSTUFF_BITS(resp, 32, 2); /* SD Spec says: any SD Card shall set at least bits 0 and 2 */ diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index f9ad35dd6012..858fc4d11240 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -139,6 +139,8 @@ struct sd_scr { unsigned char cmds; #define SD_SCR_CMD20_SUPPORT (1<<0) #define SD_SCR_CMD23_SUPPORT (1<<1) +#define SD_SCR_CMD48_SUPPORT (1<<2) +#define SD_SCR_CMD58_SUPPORT (1<<3) }; struct sd_ssr { From patchwork Tue May 4 16:12:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238255 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 6CF1BC43461 for ; Tue, 4 May 2021 16:13:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 36BBC611AD for ; Tue, 4 May 2021 16:13:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231810AbhEDQOM (ORCPT ); Tue, 4 May 2021 12:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231868AbhEDQNw (ORCPT ); Tue, 4 May 2021 12:13:52 -0400 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A83CFC061349 for ; Tue, 4 May 2021 09:12:52 -0700 (PDT) Received: by mail-lj1-x232.google.com with SMTP id s25so11893108lji.0 for ; Tue, 04 May 2021 09:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rUlKHRwg9oGMLgy4OD6Eu0j2Eug1Mwe4w1pydrhg7ho=; b=eudWWkPW46AfVF42Ji3LQad4suEzOF8chyrMlQvLTVKVJlEiNz0Zt5m9WE2sGi4tXW 3lDI+6R3sVzCk7t+3f8l7oXqP3i+zGd/qnJ0n/IroLLWHUgJt1rqVa8Kon5h0+lQSk91 cKc4yfeh8aIZgeCURHcSAQoDNEbOdMfjBNV30AwXPkXWMsMVc18Yk5+5KRFH63xBFOTj yUiP94xIuaZccP3loU3WY0WjuNNlw3iIw93yK1D3PHcBf2ydx9f8YV3xULD8Yk5/kJ9D YDmflZGuOgbeUGOY3qtH3a8CD72uYcOYS2K0Ve22hLHi7GvCaSwQZngZyR38hBKauoZl Ft2A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=rUlKHRwg9oGMLgy4OD6Eu0j2Eug1Mwe4w1pydrhg7ho=; b=DtXAwXGcjGdPpxajUfSAOMpovr2HDJr+tS4ntJm9g1tLtP1TUYf3qHPdAmjJmUqppD /DwlUYSyKTSVQwNZKAWK0dKshsOWEStuXUQPyl0pioSAeEIwId7SGoAysLz5/DABcfH7 zNLbvWaVwsu4dKxi/kWzpfQog/w5rxQfZxwnn3gzapIABJTac8I8iLWIO3v45EGcQX9T otoDtfz7KC4G99eZJMOG69TeMnIA8sd/CKXbAO+C5v7OTThec4b4Et8nSc9b2H3oPzlX c0ncG2c7XyWz1zzOU12s6CfhSVCPGG7KRENpIWEHPRSM2RQeho1pcdTybtXjTZxf8/Aj dQbw== X-Gm-Message-State: AOAM533h2evtCXlgRQvmMKxVMOqFqTOl2iIhzjB5e3yWYVNxxuk6w2tQ y8Nqma9Whmg0pVf2iXBBFnOV+/J80iRkIV+m X-Google-Smtp-Source: ABdhPJwt+ggDdDdmydD0bGx9A/9b6AOE49jrzu2HOeXIrEHlxkxG/fTv1rd5w+WfVYIiMK0VVqvq6g== X-Received: by 2002:a2e:161a:: with SMTP id w26mr16293287ljd.436.1620144770395; Tue, 04 May 2021 09:12:50 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:49 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 09/11] mmc: core: Read the SD function extension registers for power management Date: Tue, 4 May 2021 18:12:20 +0200 Message-Id: <20210504161222.101536-10-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org In SD spec v4.x the SD function extension registers were introduced. A specific function register were added to let the card announce support for optional features in regards to power management. The features that were added are "Power Off Notification", "Power Down Mode" and "Power Sustenance". As a first step, let's read and parse this register for power management during the SD card initialization and store the information about the supported features in the struct mmc_card. In this way, we prepare for subsequent changes to implement the complete support for the new features. Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin --- drivers/mmc/core/sd.c | 178 +++++++++++++++++++++++++++++++++++++++ include/linux/mmc/card.h | 13 +++ include/linux/mmc/sd.h | 3 + 3 files changed, 194 insertions(+) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index de7b5f8df550..cb5e8b2fc32f 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -996,6 +996,177 @@ static bool mmc_sd_card_using_v18(struct mmc_card *card) (SD_MODE_UHS_SDR50 | SD_MODE_UHS_SDR104 | SD_MODE_UHS_DDR50); } +static int sd_read_ext_reg(struct mmc_card *card, u8 fno, u8 page, + u16 offset, u16 len, u8 *reg_buf) +{ + u32 cmd_args; + + /* + * Command arguments of CMD48: + * [31:31] MIO (0 = memory). + * [30:27] FNO (function number). + * [26:26] reserved (0). + * [25:18] page number. + * [17:9] offset address. + * [8:0] length (0 = 1 byte, 1ff = 512 bytes). + */ + cmd_args = fno << 27 | page << 18 | offset << 9 | (len -1); + + return mmc_send_adtc_data(card, card->host, SD_READ_EXTR_SINGLE, + cmd_args, reg_buf, 512); +} + +static int sd_parse_ext_reg_power(struct mmc_card *card, u8 fno, u8 page, + u16 offset) +{ + int err; + u8 *reg_buf; + + reg_buf = kzalloc(512, GFP_KERNEL); + if (!reg_buf) + return -ENOMEM; + + /* Read the extension register for power management function. */ + err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf); + if (err) { + pr_warn("%s: error %d reading PM func of ext reg\n", + mmc_hostname(card->host), err); + goto out; + } + + /* PM revision consists of 4 bits. */ + card->ext_power.rev = reg_buf[0] & 0xf; + + /* Power Off Notification support at bit 4. */ + if (reg_buf[1] & 0x10) + card->ext_power.feature_support |= SD_EXT_POWER_OFF_NOTIFY; + + /* Power Sustenance support at bit 5. */ + if (reg_buf[1] & 0x20) + card->ext_power.feature_support |= SD_EXT_POWER_SUSTENANCE; + + /* Power Down Mode support at bit 6. */ + if (reg_buf[1] & 0x40) + card->ext_power.feature_support |= SD_EXT_POWER_DOWN_MODE; + + card->ext_power.fno = fno; + card->ext_power.page = page; + card->ext_power.offset = offset; + +out: + kfree(reg_buf); + return err; +} + +static int sd_parse_ext_reg(struct mmc_card *card, u8 *gen_info_buf, + u16 *next_ext_addr) +{ + u8 num_regs, fno, page; + u16 sfc, offset, ext = *next_ext_addr; + u32 reg_addr; + + /* + * Parse only one register set per extension, as that is sufficient to + * support the standard functions. This means another 48 bytes in the + * buffer must be available. + */ + if (ext + 48 > 512) + return -EFAULT; + + /* Standard Function Code */ + memcpy(&sfc, &gen_info_buf[ext], 2); + + /* Address to the next extension. */ + memcpy(next_ext_addr, &gen_info_buf[ext + 40], 2); + + /* Number of registers for this extension. */ + num_regs = gen_info_buf[ext + 42]; + + /* We support only one register per extension. */ + if (num_regs != 1) + return 0; + + /* Extension register address. */ + memcpy(®_addr, &gen_info_buf[ext + 44], 4); + + /* 9 bits (0 to 8) contains the offset address. */ + offset = reg_addr & 0x1ff; + + /* 8 bits (9 to 16) contains the page number. */ + page = reg_addr >> 9 & 0xff ; + + /* 4 bits (18 to 21) contains the function number. */ + fno = reg_addr >> 18 & 0xf; + + /* Standard Function Code for power management. */ + if (sfc == 0x1) + return sd_parse_ext_reg_power(card, fno, page, offset); + + return 0; +} + +static int sd_read_ext_regs(struct mmc_card *card) +{ + int err, i; + u8 num_ext, *gen_info_buf; + u16 rev, len, next_ext_addr; + + if (mmc_host_is_spi(card->host)) + return 0; + + if (!(card->scr.cmds & SD_SCR_CMD48_SUPPORT)) + return 0; + + gen_info_buf = kzalloc(512, GFP_KERNEL); + if (!gen_info_buf) + return -ENOMEM; + + /* + * Read 512 bytes of general info, which is found at function number 0, + * at page 0 and with no offset. + */ + err = sd_read_ext_reg(card, 0, 0, 0, 512, gen_info_buf); + if (err) { + pr_warn("%s: error %d reading general info of SD ext reg\n", + mmc_hostname(card->host), err); + goto out; + } + + /* General info structure revision. */ + memcpy(&rev, &gen_info_buf[0], 2); + + /* Length of general info in bytes. */ + memcpy(&len, &gen_info_buf[2], 2); + + /* Number of extensions to be find. */ + num_ext = gen_info_buf[4]; + + /* We support revision 0, but limit it to 512 bytes for simplicity. */ + if (rev != 0 || len > 512) { + pr_warn("%s: non-supported SD ext reg layout\n", + mmc_hostname(card->host)); + goto out; + } + + /* + * Parse the extension registers. The first extension should start + * immediately after the general info header (16 bytes). + */ + next_ext_addr = 16; + for (i = 0; i < num_ext; i++) { + err = sd_parse_ext_reg(card, gen_info_buf, &next_ext_addr); + if (err) { + pr_warn("%s: error %d parsing SD ext reg\n", + mmc_hostname(card->host), err); + goto out; + } + } + +out: + kfree(gen_info_buf); + return err; +} + /* * Handle the detection and initialisation of a card. * @@ -1144,6 +1315,13 @@ static int mmc_sd_init_card(struct mmc_host *host, u32 ocr, } } + if (!oldcard) { + /* Read/parse the extension registers. */ + err = sd_read_ext_regs(card); + if (err) + goto free_card; + } + if (host->cqe_ops && !host->cqe_enabled) { err = host->cqe_ops->cqe_enable(host, card); if (!err) { diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 858fc4d11240..03a862e93594 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -191,6 +191,18 @@ struct sd_switch_caps { #define SD_MAX_CURRENT_800 (1 << SD_SET_CURRENT_LIMIT_800) }; +struct sd_ext_reg { + u8 fno; + u8 page; + u16 offset; + u8 rev; + u8 feature_support; +/* Power Management Function. */ +#define SD_EXT_POWER_OFF_NOTIFY (1<<0) +#define SD_EXT_POWER_SUSTENANCE (1<<1) +#define SD_EXT_POWER_DOWN_MODE (1<<2) +}; + struct sdio_cccr { unsigned int sdio_vsn; unsigned int sd_vsn; @@ -292,6 +304,7 @@ struct mmc_card { struct sd_scr scr; /* extra SD information */ struct sd_ssr ssr; /* yet more SD information */ struct sd_switch_caps sw_caps; /* switch (CMD6) caps */ + struct sd_ext_reg ext_power; /* SD extension reg for PM */ unsigned int sdio_funcs; /* number of SDIO functions */ atomic_t sdio_funcs_probed; /* number of probed SDIO funcs */ diff --git a/include/linux/mmc/sd.h b/include/linux/mmc/sd.h index 2236aa540faa..43bfc5c39ad4 100644 --- a/include/linux/mmc/sd.h +++ b/include/linux/mmc/sd.h @@ -29,6 +29,9 @@ #define SD_APP_OP_COND 41 /* bcr [31:0] OCR R3 */ #define SD_APP_SEND_SCR 51 /* adtc R1 */ + /* class 11 */ +#define SD_READ_EXTR_SINGLE 48 /* adtc [31:0] R1 */ + /* OCR bit definitions */ #define SD_OCR_S18R (1 << 24) /* 1.8V switching request */ #define SD_ROCR_S18A SD_OCR_S18R /* 1.8V switching accepted by card */ From patchwork Tue May 4 16:12:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238253 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 ED039C43462 for ; Tue, 4 May 2021 16:13:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B0876611AC for ; Tue, 4 May 2021 16:13:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231805AbhEDQOM (ORCPT ); Tue, 4 May 2021 12:14:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231874AbhEDQNy (ORCPT ); Tue, 4 May 2021 12:13:54 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB1ADC06138A for ; Tue, 4 May 2021 09:12:54 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id x19so14127816lfa.2 for ; Tue, 04 May 2021 09:12:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TugmmnMP6RDSPp2L8UfvdmsSklrTobWCwgxHv2Rsq4s=; b=x7LwYTyyiO5EtiSTP/BPjhP9eQrFZqFYpQLS2CmnQjKkQZw4od7tGy8UXuFTWYv1LQ 1Axih3agolSFgjjMtieA8LhbmKveLqqkx5XbcK+qoBgaBQB8Km0sjqPpvYzXMF9aHi2f JhAqdotYH9n0s1TDaRyNsaE8b/1ATss11DSsIgcD26G4DjKvY2baR2fT9odGyuA6LTcl 340q7sfFGMR7IgOHASR52aooO9vkXQOFFBJY61X/SRRV6toD1cPUn5AVW9Pe7pzT1rTW jXcUO9592B8NdUvOJ0SUPZVCNjvtKn+MYADQ62S3NIHlCRxN472YCmfEQRyefBJqiy5M F47w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TugmmnMP6RDSPp2L8UfvdmsSklrTobWCwgxHv2Rsq4s=; b=lh88ulsuZ6O5gQHcHb0r7xG6hbOEJrY3qPAcxE2Lgr+jl599RhI87DeqyfXL0eHLtO VKkMUFvCwG0DLcmq6Vz3B3PuV0rc7hskBLtqRTm73mPCRjFH/UAGnAMbTv3ZQ1EpqODr sWIzQ0gJSLFHbPXxoN9NbAe5HAw4TvOhdO8ZPujxhWe3p0J2AmA6BLye+FEfoLyefKtj kYcKC0VBIqecSmb0+glZamrVy9Q1hAHAsd41OkCYn+hMN5QH9ni1W+/zlOKGKjMTuOxG UYaf4sGo7rqMZ4VivZXL/YxtZQ6zcZlPsasrC4rcMk56diWTqchLMii2nwe1vR8vftvm 2myA== X-Gm-Message-State: AOAM531ARED+PCIDRUSna316V+dOOm8wuIgX84mwmO8205VjW8qOkAMP A4HMdaou1IMRaO7tveSKKeV55YRybKk9tDe9 X-Google-Smtp-Source: ABdhPJwRcHKF0j+XAEQinX49FLpArbd5Qu9pJndUnwAUxs9SZ+chNoCiFzzPoZIAt3hnQZ4HTmyIXw== X-Received: by 2002:a19:48d3:: with SMTP id v202mr15024111lfa.315.1620144772586; Tue, 04 May 2021 09:12:52 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:51 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 10/11] mmc: core: Read performance enhancements registers for SD cards Date: Tue, 4 May 2021 18:12:21 +0200 Message-Id: <20210504161222.101536-11-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org In SD spec v6.x the SD function extension registers for performance enhancements were introduced. These registers let the SD card announce supports for various performance related features, like "self-maintenance", "cache" and "command queuing". Let's extend the parsing of SD function extension registers and store the information in the struct mmc_card. This prepares for subsequent changes to implement the complete support for new the performance enhancement features. Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij --- drivers/mmc/core/sd.c | 53 ++++++++++++++++++++++++++++++++++++++++ include/linux/mmc/card.h | 7 ++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index cb5e8b2fc32f..702d7c1a0aec 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -1058,6 +1058,55 @@ static int sd_parse_ext_reg_power(struct mmc_card *card, u8 fno, u8 page, return err; } +static int sd_parse_ext_reg_perf(struct mmc_card *card, u8 fno, u8 page, + u16 offset) +{ + int err; + u8 *reg_buf; + + reg_buf = kzalloc(512, GFP_KERNEL); + if (!reg_buf) + return -ENOMEM; + + err = sd_read_ext_reg(card, fno, page, offset, 512, reg_buf); + if (err) { + pr_warn("%s: error %d reading PERF func of ext reg\n", + mmc_hostname(card->host), err); + goto out; + } + + /* PERF revision. */ + card->ext_perf.rev = reg_buf[0]; + + /* FX_EVENT support at bit 0. */ + if (reg_buf[1] & 0x1) + card->ext_perf.feature_support |= SD_EXT_PERF_FX_EVENT; + + /* Card initiated self-maintenance support at bit 0. */ + if (reg_buf[2] & 0x1) + card->ext_perf.feature_support |= SD_EXT_PERF_CARD_MAINT; + + /* Host initiated self-maintenance support at bit 1. */ + if (reg_buf[2] & 0x2) + card->ext_perf.feature_support |= SD_EXT_PERF_HOST_MAINT; + + /* Cache support at bit 0. */ + if (reg_buf[4] & 0x1) + card->ext_perf.feature_support |= SD_EXT_PERF_CACHE; + + /* Command queue support indicated via queue depth bits (0 to 4). */ + if (reg_buf[6] & 0x1f) + card->ext_perf.feature_support |= SD_EXT_PERF_CMD_QUEUE; + + card->ext_perf.fno = fno; + card->ext_perf.page = page; + card->ext_perf.offset = offset; + +out: + kfree(reg_buf); + return err; +} + static int sd_parse_ext_reg(struct mmc_card *card, u8 *gen_info_buf, u16 *next_ext_addr) { @@ -1102,6 +1151,10 @@ static int sd_parse_ext_reg(struct mmc_card *card, u8 *gen_info_buf, if (sfc == 0x1) return sd_parse_ext_reg_power(card, fno, page, offset); + /* Standard Function Code for performance enhancement. */ + if (sfc == 0x2) + return sd_parse_ext_reg_perf(card, fno, page, offset); + return 0; } diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 03a862e93594..2867af0635f8 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -201,6 +201,12 @@ struct sd_ext_reg { #define SD_EXT_POWER_OFF_NOTIFY (1<<0) #define SD_EXT_POWER_SUSTENANCE (1<<1) #define SD_EXT_POWER_DOWN_MODE (1<<2) +/* Performance Enhancement Function. */ +#define SD_EXT_PERF_FX_EVENT (1<<0) +#define SD_EXT_PERF_CARD_MAINT (1<<1) +#define SD_EXT_PERF_HOST_MAINT (1<<2) +#define SD_EXT_PERF_CACHE (1<<3) +#define SD_EXT_PERF_CMD_QUEUE (1<<4) }; struct sdio_cccr { @@ -305,6 +311,7 @@ struct mmc_card { struct sd_ssr ssr; /* yet more SD information */ struct sd_switch_caps sw_caps; /* switch (CMD6) caps */ struct sd_ext_reg ext_power; /* SD extension reg for PM */ + struct sd_ext_reg ext_perf; /* SD extension reg for PERF */ unsigned int sdio_funcs; /* number of SDIO functions */ atomic_t sdio_funcs_probed; /* number of probed SDIO funcs */ From patchwork Tue May 4 16:12:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ulf Hansson X-Patchwork-Id: 12238257 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=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,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 DE1D0C433B4 for ; Tue, 4 May 2021 16:13:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BFCD1613B3 for ; Tue, 4 May 2021 16:13:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232006AbhEDQOQ (ORCPT ); Tue, 4 May 2021 12:14:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231890AbhEDQN5 (ORCPT ); Tue, 4 May 2021 12:13:57 -0400 Received: from mail-lj1-x233.google.com (mail-lj1-x233.google.com [IPv6:2a00:1450:4864:20::233]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DC43DC06134A for ; Tue, 4 May 2021 09:12:56 -0700 (PDT) Received: by mail-lj1-x233.google.com with SMTP id y9so6839313ljn.6 for ; Tue, 04 May 2021 09:12:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xyxXmo/h/dfhEx4WikBIp+kaYZCmt7Npv/WLTwwg9eE=; b=B/8bDkEWNw9lcVCx0PtUoNt7PqWM7Aqe72ivfqWbaPh/eRdVEWPCMbeBiURN09vtPv eaLYG1oyLwLPVMdxeXNeKPyW05JULHoQwN3dH6snp0j1X19uxyrqUwx6HaVGZBoMD9xu nFmncr3Kqjzwlcv+yI2wJkwzznLVr11iLd/je9Z99ASGJ4voNXdXTYGdTFevulbCj1z9 fxiI3xiIaZktMJ9K2TUEi7421g/Zer+60ExIyh+lQH5B/govXJXoc51+OAFt02P/PtUW j5NIOgCMyKbHK7fcgHnLaMOdwTCSqJnuHfZCe/mKb19n8PFe4YugrbhJVmK8W6qWGXBN iS/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xyxXmo/h/dfhEx4WikBIp+kaYZCmt7Npv/WLTwwg9eE=; b=VTEnde/HHRD21NTDXg53u294tbECFeDN8S/MERGuyYRlxeb+V8tB+8H4D8tJN5vj31 yOmHmRQdeRO14tCsmNbtRuBnGtWxK6KsIbzsjUBsNvtuslvvuIk9pjCkyx1yTbdB8HcU F54RbaV38mbL/9dc/r2uck61FHdT+ameSO7Wf8gzIKshXaPy+nOds+06XsyGDponDZH5 eWFsatdClMO+oso3H9zcJk18Wb6855i0uOP7JbhDwMznlp6N4gOIoRAIo4jKL/Kvf4h8 UMYxKapMwEcAsHt9LZ+r0PwEVp3fs2PgSKiJOQw1/Rc957SBHVn2mYcMZzLSCeJ70vmP 48gg== X-Gm-Message-State: AOAM531/vlivmw5N9p2NQAyrlVoDwZo0/xhNlmqGUp/7QN6E8ZK+3AA4 f5EsGnn1xDqP2o2jaPls8HckE1tTr+6iHF/Y X-Google-Smtp-Source: ABdhPJzDqhFP0LwJ32oqCrgAn+o3dx2QbgOiI/z/xlyYdNewtvYHfnYoBbUK3lz6+2cgvEPXHgckJA== X-Received: by 2002:a2e:a544:: with SMTP id e4mr18016480ljn.452.1620144774558; Tue, 04 May 2021 09:12:54 -0700 (PDT) Received: from localhost.localdomain (h-98-128-180-197.NA.cust.bahnhof.se. [98.128.180.197]) by smtp.gmail.com with ESMTPSA id s20sm164193ljs.116.2021.05.04.09.12.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 May 2021 09:12:53 -0700 (PDT) From: Ulf Hansson To: linux-mmc@vger.kernel.org, Ulf Hansson , Adrian Hunter Cc: Linus Walleij , Wolfram Sang , Shawn Lin , Avri Altman , Masami Hiramatsu , linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 11/11] mmc: core: Add support for Power Off Notification for SD cards Date: Tue, 4 May 2021 18:12:22 +0200 Message-Id: <20210504161222.101536-12-ulf.hansson@linaro.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210504161222.101536-1-ulf.hansson@linaro.org> References: <20210504161222.101536-1-ulf.hansson@linaro.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Rather than only deselecting the SD card via a CMD7, before we cut power to it at system suspend, at runtime suspend or at shutdown, let's add support for a graceful power off sequence via enabling the SD Power Off Notification feature. Note that, the Power Off Notification feature was added in the SD spec v4.x, which is several years ago. However, it's still a bit unclear how often the SD card vendors decides to implement support for it. To validate these changes a Sandisk Extreme PRO A2 64GB has been used, which seems to work nicely. Signed-off-by: Ulf Hansson Reviewed-by: Linus Walleij --- drivers/mmc/core/sd.c | 136 ++++++++++++++++++++++++++++++++++++++++- include/linux/mmc/sd.h | 1 + 2 files changed, 134 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/core/sd.c b/drivers/mmc/core/sd.c index 702d7c1a0aec..760aa86bd54d 100644 --- a/drivers/mmc/core/sd.c +++ b/drivers/mmc/core/sd.c @@ -66,6 +66,13 @@ static const unsigned int sd_au_size[] = { __res & __mask; \ }) +#define SD_POWEROFF_NOTIFY_TIMEOUT_MS 2000 + +struct sd_busy_data { + struct mmc_card *card; + u8 *reg_buf; +}; + /* * Given the decoded CSD structure, decode the raw CID to our CID structure. */ @@ -996,6 +1003,66 @@ static bool mmc_sd_card_using_v18(struct mmc_card *card) (SD_MODE_UHS_SDR50 | SD_MODE_UHS_SDR104 | SD_MODE_UHS_DDR50); } +static int sd_write_ext_reg(struct mmc_card *card, u8 fno, u8 page, u16 offset, + u8 reg_data) +{ + struct mmc_host *host = card->host; + struct mmc_request mrq = {}; + struct mmc_command cmd = {}; + struct mmc_data data = {}; + struct scatterlist sg; + u8 *reg_buf; + + reg_buf = kzalloc(512, GFP_KERNEL); + if (!reg_buf) + return -ENOMEM; + + mrq.cmd = &cmd; + mrq.data = &data; + + /* + * Arguments of CMD49: + * [31:31] MIO (0 = memory). + * [30:27] FNO (function number). + * [26:26] MW - mask write mode (0 = disable). + * [25:18] page number. + * [17:9] offset address. + * [8:0] length (0 = 1 byte). + */ + cmd.arg = fno << 27 | page << 18 | offset << 9; + + /* The first byte in the buffer is the data to be written. */ + reg_buf[0] = reg_data; + + data.flags = MMC_DATA_WRITE; + data.blksz = 512; + data.blocks = 1; + data.sg = &sg; + data.sg_len = 1; + sg_init_one(&sg, reg_buf, 512); + + cmd.opcode = SD_WRITE_EXTR_SINGLE; + cmd.flags = MMC_RSP_R1 | MMC_CMD_ADTC; + + mmc_set_data_timeout(&data, card); + mmc_wait_for_req(host, &mrq); + + kfree(reg_buf); + + /* + * Note that, the SD card is allowed to signal busy on DAT0 up to 1s + * after the CMD49. Although, let's leave this to be managed by the + * caller. + */ + + if (cmd.error) + return cmd.error; + if (data.error) + return data.error; + + return 0; +} + static int sd_read_ext_reg(struct mmc_card *card, u8 fno, u8 page, u16 offset, u16 len, u8 *reg_buf) { @@ -1446,21 +1513,84 @@ static void mmc_sd_detect(struct mmc_host *host) } } +static int sd_can_poweroff_notify(struct mmc_card *card) +{ + return card->ext_power.feature_support & SD_EXT_POWER_OFF_NOTIFY; +} + +static int sd_busy_poweroff_notify_cb(void *cb_data, bool *busy) +{ + struct sd_busy_data *data = cb_data; + struct mmc_card *card = data->card; + int err; + + /* + * Read the status register for the power management function. It's at + * one byte offset and is one byte long. The Power Off Notification + * Ready is bit 0. + */ + err = sd_read_ext_reg(card, card->ext_power.fno, card->ext_power.page, + card->ext_power.offset + 1, 1, data->reg_buf); + if (err) { + pr_warn("%s: error %d reading status reg of PM func\n", + mmc_hostname(card->host), err); + return err; + } + + *busy = !(data->reg_buf[0] & 0x1); + return 0; +} + +static int sd_poweroff_notify(struct mmc_card *card) +{ + struct sd_busy_data cb_data; + u8 *reg_buf; + int err; + + reg_buf = kzalloc(512, GFP_KERNEL); + if (!reg_buf) + return -ENOMEM; + + /* + * Set the Power Off Notification bit in the power management settings + * register at 2 bytes offset. + */ + err = sd_write_ext_reg(card, card->ext_power.fno, card->ext_power.page, + card->ext_power.offset + 2, 0x1); + if (err) { + pr_warn("%s: error %d writing Power Off Notify bit\n", + mmc_hostname(card->host), err); + goto out; + } + + cb_data.card = card; + cb_data.reg_buf = reg_buf; + err = __mmc_poll_for_busy(card, SD_POWEROFF_NOTIFY_TIMEOUT_MS, + &sd_busy_poweroff_notify_cb, &cb_data); + +out: + kfree(reg_buf); + return err; +} + static int _mmc_sd_suspend(struct mmc_host *host) { + struct mmc_card *card = host->card; int err = 0; mmc_claim_host(host); - if (mmc_card_suspended(host->card)) + if (mmc_card_suspended(card)) goto out; - if (!mmc_host_is_spi(host)) + if (sd_can_poweroff_notify(card)) + err = sd_poweroff_notify(card); + else if (!mmc_host_is_spi(host)) err = mmc_deselect_cards(host); if (!err) { mmc_power_off(host); - mmc_card_set_suspended(host->card); + mmc_card_set_suspended(card); } out: diff --git a/include/linux/mmc/sd.h b/include/linux/mmc/sd.h index 43bfc5c39ad4..6727576a8755 100644 --- a/include/linux/mmc/sd.h +++ b/include/linux/mmc/sd.h @@ -31,6 +31,7 @@ /* class 11 */ #define SD_READ_EXTR_SINGLE 48 /* adtc [31:0] R1 */ +#define SD_WRITE_EXTR_SINGLE 49 /* adtc [31:0] R1 */ /* OCR bit definitions */ #define SD_OCR_S18R (1 << 24) /* 1.8V switching request */