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: 430878 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936324jao; Tue, 4 May 2021 09:12:35 -0700 (PDT) X-Received: by 2002:a2e:814c:: with SMTP id t12mr18116476ljg.361.1620144755049; Tue, 04 May 2021 09:12:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144755; cv=none; d=google.com; s=arc-20160816; b=W5T5KiO3tWEneLolAKBinVAeO0DLKtwICOBNVaWbZC7b5RBwvZKeV/+czRvv9BVJm3 HW7lF8lyaw3fnljDJW8B3PaCCgo3qLZ8WNZIAX2wdJUXeVQnQAzsgoH+HkjB9CGLn5r7 KB0gUzNQbr1PFpOx8Usn/KhNcbMdOA8xMEnRUW5+YyCo0J3yjdixWeYPEtSYRGK1vtfL kepl3iT+kjkLuADmzHA6tm99nCXZR8Q3SF7qjGGYUqOGLhSR45MQ8F5D6rN5YTErt6LX YxkGyVvZ3+fR4Uc/fVwNmwNS+9zQohywykjkPAHSFPDjtoCA1n2MDcxLL/RRGfFpfq7e +2Xg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=3a82EmNZunJK3ZJbNP0JbGj7NLetG3uE0s2MHagCq3U=; b=0IXZseS2/W0ZSTumUXxqa3KDPvfEcvidKTNVBDOnMl2ET9QIUGymmHOAIfDD2ebKux lnRerTKKHHOUnUsaWb+b1qSf/veu1emsS29Q8hIgD/MFTu0FCfJ2IJY81VqSd/vofmBo nmu02x59oIMNRcOHlxYfdjWPOWRox3Vvl111Se9W1RQzXx9Hd/9mDJBAuXsWOjktvd8E ouwbbkpEmwSokD/2y/QSm6toxf8zldCQOlbDBi58maYR7mtRpQnVsLbEnmeS3Bwe1k2G ncllo5vA5RHGz+E8nuuClEhs6NWqJSE8CRRTMo5GstyVEO+qI0+4nIN4Q8yClJ73d2r6 E7nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wxyfiIk9; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id o24sor2342754lfb.51.2021.05.04.09.12.34 for (Google Transport Security); Tue, 04 May 2021 09:12:35 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wxyfiIk9; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=LVL4Mx9c00M+VtUG4G5AFnztHn4vRTm/wHT0ZeXIxQQWJJk8/qlTcVHeENB/DrUF90 DQ5iTqRnuaqq2szGTqEDiIyomjXZZxG7AhH0yWanLBS8cS5mFJzHcg5LPttht3j8Zn7t BvrCvSkAAhmw7oz4DFH8nXkOCHfC0AHaNITg4CXo/ThLQQpRTDu+aNp9gH9wUkFLyhI/ HlU+/G5+IKRbYqUbzWNlZnBxuFFflLOABRjJ1gBvCtajq9fXs4f96RrEfAHXOtSqbbNG kgeMbq+f13tmpSJSMSi61REGjuFGr1dR4jG7CT8h0ucaQrFRhEq5m1uxzQu5bAgbi2x0 cd0w== X-Gm-Message-State: AOAM530IqYtB5VwahDv2tJlrfo1/GKnqeabIeP7Vw3+S8heMvbYhI5n/ x2PPHUg1byiKPW9UhUSa2SZkZd+M 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) Return-Path: 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 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 --- 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(-) -- 2.25.1 Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin 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: 430879 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936354jao; Tue, 4 May 2021 09:12:37 -0700 (PDT) X-Received: by 2002:a05:6512:3b8c:: with SMTP id g12mr17536855lfv.195.1620144757075; Tue, 04 May 2021 09:12:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144757; cv=none; d=google.com; s=arc-20160816; b=M75EHMbSpdmZ3gjvC/jo9fTldsaOuRGJznmch8CnpvqRmTtLqxaErUp7gufLaVdDG7 L53cp8orMyOklfsoFSGetBnKIqku4nVDd4gol79WOlfzyjPLngOA39w/HO0HBgW6K32F JncC3QAf2pefyXVKC4aywr8xtAGdA4JzaosYgGL7TpBR8c23MLOZD6x3t8P2n3xPovWj lNpGFhV5xzD85EqlYbp8YBtS04QoRrq4oHlwm6s8TcSJvSDUsBRjfSLg6Wkpfr8ugs2x NiL1B5Szi42/5TIIkvHeZBqV2HBtqM/kjdYBAsopf35R1PsjMsAWQeTcAWdwtyAOAHXC HLiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=0EaNyrJPx800SxJDWlIRfuBN901wRckS9/iskflhAQE=; b=Fs1thgPTu3dozihmoz336K3+v0do2dJZ3gluEW15eozg5dIvDDPJ2VDAK+IClqRcCU T8MZz95M3IzCXEXc0OVBhwDSaLEJUnodvc5R+xBkguMJc7UxBHCR3UYcQYrZMZDXdzdL Mj6CvYM2vA4B+9UDgnrkJ/HyJndcN6z3HYvXbsGARUyo3oLGSeUI3PctMDYTkwRBafWL hkzu4SInFqPa/dseXeoSJ5x4lV5V2tq9HlvNnIxKY1YbN2HuzPD4u7ps23pEZ5G4DfHr CAcqaelWHuQCK2qaT7u1A87KeYwODaZlQMcFVYRIcOtejJD61TZY90kFxE/mPIPRVqUu iUwA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rLqzdYDt; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id q4sor4170612lfg.79.2021.05.04.09.12.36 for (Google Transport Security); Tue, 04 May 2021 09:12:37 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=rLqzdYDt; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=CKQc9HaBJnna6pbFGZc0sOU/NIW7fwJPSo8vjBBCkDdz7w5m2EzRppLwlSlycbvac/ jzrHcq3UgNGF6Z0LKR/MmTG/LGwSmrbuMymIbfQOp8OCTor8hZIAM94jVtykFP4y75qK /PY0QTURTabHPYG284MxstcDlMvo/RYW0zUTjPDZejSAwXT/a3hV0RCWLZR2ri87wafy LVo51ngb+QDMTCRwaS3KJACjpp1IOEVOiArB4koo07/kB8+NY9AKVyBCsRWhPncBBk2V NnlA9yv3lXRREamRC5Fwff4Wwp8kcWG3rCbF1Ad7F103P5acJ8EYbgngvn5Q3YMN2AI4 gRUA== X-Gm-Message-State: AOAM531cqg0KG4yzCMtpQ23YBLDrEzKgLpXZinlabfI8MmWsZIIwlLss OiQRbP59QABUI1EjtTIIhKwLoutw 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) Return-Path: 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 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 --- drivers/mmc/core/mmc_ops.c | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) -- 2.25.1 Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin 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: 430880 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936382jao; Tue, 4 May 2021 09:12:39 -0700 (PDT) X-Received: by 2002:a05:651c:105a:: with SMTP id x26mr6637148ljm.440.1620144759191; Tue, 04 May 2021 09:12:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144759; cv=none; d=google.com; s=arc-20160816; b=R8ycRbYs5JoaEJCq2HVNE+GD6OmMnk075Z/gfFOUrn2uE8+CkeflqEsxulErXc2qtw WUnk0J1yk3WBPnk2ko8dhcNanvBR8xIBGt8oPUF1bN6lhuQIFL36qtv1gPl6d/HyINto Ru0XXPzxSJhIeYPCTibCkB5DMIaGAPd2hVqULN2IMNjRu6iBcsR+dQK4iwKy/Y8HmCZU BAWRBDw2qLkt+BG1d7ZlH7kr4AGyr+8VZhTrlgb/zBhHzS58TCpj4t7nXisIGszdEDDH OedrSeVVdu9Lst5AsvvPC2kFHEGM7LO7LIBmc4KRUhuNO0vrI9PAXwVESNEHnoQX69Xb gQFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=/ee795yxnzHs29v3TjQa721b4l02PWsrUGNagPQX+uQ=; b=EVbIkdErvPOMOZmiEKhIFdZc8fcx3IxCi94pr6CSoHusZbpHxx+EDQn8WwDY9dEicL j20r7hp1JSnfZ0bLxWCJ3pX/LPg/WeZvNDOcmkgOvjVjA0oO/BX8xbwynou/YU8+xcix Y+X7oq0RtGKKnjSCuLkrn4BQE1d3EBusxL6YTi2CyDfTdQjVyFKYlgp7Sd0AF734MuRa /WjT6lytWLoPTfzfiRsNkGmQZOfmw8bL8550LVHButlN6o4MrLQHATHsFRJdPap4hEyc SRrhdLvk0ZZWX9vw8ENRGlhstoZ63lE8+68mRW0dKV72qClD1PXcnP7t5AICfVkI9q0R UaGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dHVCBXhe; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id j10sor445107lfe.35.2021.05.04.09.12.39 for (Google Transport Security); Tue, 04 May 2021 09:12:39 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dHVCBXhe; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=IRT7LGUoGbVYzN2BDFoTbxDHUd7W4PX3FJoIzBcNOxaBYX42jCfNi1J4EdIW5gBdIz +bzFyeGl4k//NZqC6ghGhuo5xgJy+U1v4kssuzsgHVEaoG0bNw87hRzhFZkgwS0+O1fS C4m0+hPx45U8HPWcdSbSNV8/tDtDhpuYu6inUEEbJlV1NSY0n8pjtEn0YQ1EMW+H7H2C 4+tNlzofO+V+iXCqSAjy9KprLNzcxP3JsgeUuvt4ZqK2jhOMRouH+EpBGMfCGt/4unTF MqoxxbsFV+V6ddhvBS3ut3uNIzYHSFjdSUkF119m8Q82GOCokEGcHkxrcy1CFUx4F7ng pQXw== X-Gm-Message-State: AOAM530zI3eyxwMDACxtpyeFjA5QwbVidngoLV1L33C28sXQ8aRipc16 Bz1R9DsqKFhZ0Igm2sZ4ZYAIwufS 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) Return-Path: 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 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 --- drivers/mmc/core/mmc_ops.c | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) -- 2.25.1 Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin 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: 430881 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936408jao; Tue, 4 May 2021 09:12:41 -0700 (PDT) X-Received: by 2002:a2e:9650:: with SMTP id z16mr2870058ljh.487.1620144761189; Tue, 04 May 2021 09:12:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144761; cv=none; d=google.com; s=arc-20160816; b=bXDHTvWfKLf5FdTZhoAiTsp7BgknlxCN8q22RaD8SQvYcXzeJX6Qj8DnKCiofqUSn2 DcOkawCzt9uJDviak0s+KMw3wjzCqRne9IdnH+l1bVXQTvbP3QIEpi4hbARO4bZIc/G8 RLfPMIV+Jfw2J/pcHaPUXLim530LEFkz6tk+aqIT6OaJ+IyIrGDE2H8cok+5FP+/qB7n kK7HJoygqlsu/6dkkOs6UiHCZN8+znYpLSvf9e25JaT0Th1JOnjrXMA8xOlaI3sQaQKL 7qeOFBa8VRlHY5AwwhVS0S9WeynkcO+VY1uM2jqgm9sj+mFWmEjYSjMf02Oejt+epIxd 5hjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=v4QtfaGRpyWEeOpttGEoGwuwCU8/+wjbWkEbFI1DKy8=; b=KIMm9yJNSr8wbgu0Cqoe2aGpnEZRpZJ0S/GkVGVOx5r0DuvwY2f2Rc4/Rltt7xf/ay LG2dQb7oo7UphaATyHYy8HsMeeZyJJxBIgg1RDtXVKKrQiguHY6ZTrJYVZYD/t3xV/Cg mpMW3DRcpM5gEE7/NKtONbFWFmRVhGgonTfder0opc49yL/v3INPRxeamuCnfYzteXSF 5oYXxE5ws/qXw/4EZif4lesZKiIWPdZefOAIFLATPpcWgfJAazhQF9Vn1rudhcPrp6n0 /BMGBzx3Szb7M+KEmbZYLfPqrpeD1nSawqL0j0GAszitcnWbAvQ0Ikmwf5+BriAYn+pR tlNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xNPTrT0P; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id 5sor4365996lfc.19.2021.05.04.09.12.41 for (Google Transport Security); Tue, 04 May 2021 09:12:41 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xNPTrT0P; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=I43rKHQ7UeSyaBLWtJqncJzHjv0R2xebhkNZA4DwX5M88aXjGAaSQTRTCoSSDxGZw9 mTHykjjU526M77uxNjZ7SenNCz8BOiUU7CZxtr7rDa2SUBpLiH2BqlRutzeUoy7ueH4d ekOpdVj1Gk8Ipfvt7KJmlqs4KSRAk7aoCQWvrOe/KRsxFJzT4r3sIWFdEdlGfP3cbGUZ GlVAFD8g1Ov5e3g31XpQM36boul3BOoH8W5OG8ZhQmHNLSWIwhP7IiTYDgAriWZ0u/8/ iXukTfAWyYH+245VgssnYzyY2fw1vfdumqJ+yAw5VKqM4j9mOBYebpnoRy9uGCGYq31A Q07Q== X-Gm-Message-State: AOAM533N/gk/Po+WBJNXXiUkcbLu7dstwGeFAh8YjiDoV9X8wzQ95FFe pZREI0c6EQ2Aw8gakKGL46yX8YTg 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) Return-Path: 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 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 --- 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(-) -- 2.25.1 Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin 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: 430882 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936445jao; Tue, 4 May 2021 09:12:43 -0700 (PDT) X-Received: by 2002:a2e:b5bc:: with SMTP id f28mr555ljn.210.1620144763715; Tue, 04 May 2021 09:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144763; cv=none; d=google.com; s=arc-20160816; b=DIGmKmbJxoGHvT9ORZ2eV7/AoT2u8JAwLyPyH5MjtMeMf2XBnclWStEja0JkfZllJZ wp2nzOMtPmoNSvt4j+Gr6Iy4aJBKSHvb6EeTSKsIGPRQW25O29fnqX/5G0TBTmd1r12O pX/osDCYm5vXOTbgrp60e5AQcPFFtDoVYeT08Rs1eUl2ck205z9v8M+NyeioE8Gg4t59 Tc8NSLCLTelZlUJYbmwhztAtMNJrc4eMhtVH57XI7bkAkFgUY7sW57txb0aBrsgaQwS8 YOkFyDHMHN9sFFLDAnfi7t0hpaVXZyBtyBDr4UYCF52bM/a69EqF+spgk1yDh0Q51mbG NRQg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=BD0REsdi9mYrsTQHgnQYm8ynmTMvDhWbCRyzYdtenaE=; b=YN3Js3x7fp/J14ZiuDmhU6um+tyc8gvmEFzrHC1KkvFsE0oFBt6Qsi44ht5cSFPqL2 ZF+bU/ajt9c/+K3E9YSoy8j0y98SoBCqx6b1DaCgC9gPrCplLRLdjJLhWv01GL508i2r ZihyYCBa1pdrdPn8P/AVjFEo2SkhKGjTxq2Z4rv9awNIPj6X+h0/ppxz/H6HkHk/++XP jFoq9tSG1tyGlmYeTE1Lnj2mXjXB6uSx+gY3l/CktFneZk/np1/tRns0rvZFdAJ5L2tz ZVHbftZFIzGbCdVsR/kWWc6vIZuNXNhDCyu6v66n1+ji7OSjSVSXTxsiHrPh3YRb/nxs eD9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BNrJU8ET; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id k12sor592204lfo.112.2021.05.04.09.12.43 for (Google Transport Security); Tue, 04 May 2021 09:12:43 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BNrJU8ET; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=kfRlMk+lF9wwhTFQeNiTkzAobyWQUentn5fBRycakVpm7v7s+fR/8m0Dco6X9nWJ2W 5BZVcmyjuhbfgJtl0u0PTHXRVom4cUsqbSkQXamOlKgIcpBJKM5e7Dv73eoLFfO1fOU+ ApnLVY5pNPpc0FwWgHQ+5+GgtmlTT83jrxkD/rukUiUORGqusE0HDP1gy/SOtJQ8hPjC CjjPVmjhxpTLvVxc9fXsBGCi54wXWvTc2RKYFhneOKHcNsWWRygTObh90mEmVTJD0q3T G77FaxY+nOMBu1nOva5q8sZFOOcNkJ1WAUqmKRppK8W+7VF/ZGoeBIb9OcHvmuCTBZKZ pwgA== X-Gm-Message-State: AOAM532Wz17j2zFEeNz/XdYC5OEQhwZ/8sLWYn/GUSjFEPdahx390vxi Li/qADpnbjsMIbVrxDe+cA+sQyw9 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) Return-Path: 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 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 --- drivers/mmc/core/mmc.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) -- 2.25.1 Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin 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: 430883 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936479jao; Tue, 4 May 2021 09:12:45 -0700 (PDT) X-Received: by 2002:a2e:b558:: with SMTP id a24mr17506355ljn.404.1620144765366; Tue, 04 May 2021 09:12:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144765; cv=none; d=google.com; s=arc-20160816; b=yzMBzvKA3Z2iWPC1yvDeRPkJSDKdKeZ672DJ9UlAjnlXPrTpnKuatAavZ0/KGgIvJj oaDt3Ie0iWkYWnpIYUJQhkCAvMhiZ6fcE05ZgOR6xe4DvZuVGSZ5Uyh05quMZpmRj1AM l6qhLhemfUK+bvQXxV+bxnslfX8YJU+SL3swnW1554sl3Y7ICEnM5Dqae2cAD6SUgCth iKF15I9NS7b4TojVWnqdxIYZshZqDaGw/bKeQMTBJMV35Czcp9co1hVF51/SwlSqCjE2 qCjnfCvkUg7M8YfCkLdq0izgh8e1OGxmNc18iwX26dHwx3Lls9ZZk0Ij+7H1WCxS8Ozx UVIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=TbWXoJHQ0uWHFVcBWf57QwZSLHYhmQWZi0APC0CkQ08=; b=C294CSWa28RVvUkq2VIdVFv0Nvs0yglhvcdb+hCV9hWBfT9PwV6VwjzzFsYAk9oo4J mEjFG/AW5WnOvQEUPb5TSyfbcpWSEJRblnCtMzYv/EJTsVRS5Nq/JktTyo0KmQCx4LOl p50dEqfREdQQfzn1JWf/+92L/l8MrSdZLe05avEzNtqT2cErU0wu4mab6OpTT8ACAZXD vpO/dh59nO4ElIUgjp4YrNc/tc+k/UqhRsqGRmGXMyPDDzL+6eodohAZLOnJcjq+PRss n4QWlOVO4SkxqJkhwC2K3o4sjdWYDEuxLOVkkkU80T0nlaOttXgjjRd65LqvbxYeWECR BYQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gExKlqDo; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id i21sor1918969lfo.67.2021.05.04.09.12.45 for (Google Transport Security); Tue, 04 May 2021 09:12:45 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gExKlqDo; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=RAhrCX2qLTry2XixSE7RYTQV2vRKQhVq0z+tStkp/uDSwscoSRgdLe1Ezo20PItsCU mQooUUY1+zjNVb4BOvy/2SIXTux+I8i7sN+Jw/sx+/b561N4ZnwGwx8JA9h5LenRZCrc QJ0ECun0IaB9IPqJ9sT5dFNbFBL8bSi4OXoU+0qXMDrH5Izsnjqyj8RemO69JPo5Nd0Q caLkOP/aMGVIHEVgxjhoHwTvdtafCxbE93Aqswq/HaOZe+50Cds8/7Gk4vrGFey14yWg vtjBwVja1m5ehHxA028UZGGMezvnsXO0d2xUaraKfdH5oWhykmNvbjkYXxS6t3EBp4lB pPFQ== X-Gm-Message-State: AOAM530eJHQJU6s3liutIHbBmqwpTsbYJnLtWWyd2vc8RluoPdq+GJYp jztmFPFoFAp30VfQTrTpvvSf3pon 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) Return-Path: 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 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 --- drivers/mmc/core/mmc_ops.c | 11 +++++------ drivers/mmc/core/mmc_ops.h | 2 ++ 2 files changed, 7 insertions(+), 6 deletions(-) -- 2.25.1 Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin 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: 430884 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936517jao; Tue, 4 May 2021 09:12:47 -0700 (PDT) X-Received: by 2002:a2e:b60c:: with SMTP id r12mr3103694ljn.460.1620144767484; Tue, 04 May 2021 09:12:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144767; cv=none; d=google.com; s=arc-20160816; b=lkd4gwhule+Jx2GNdL9TVBkJDIHDIwcWEai9zQtL8iBp2eqNCZ7i82ESZeGdztj1ce V/QX5ur1GcuNardlwCSgYAQd/T39d3+dkAQhwZxx0Xh8rZsuXiMBMyKJ1zTtQLdshqRu j/IOnR98H5rf5ul0xRD0iGz6RaAFNlmEBIh8a30dR7GBeODPIy4g/HrJCyHCST42SpLE z37Bd90lu8hR2Ye4hAiTjcFe5H2uIFOiSwnzagyZCp6XTQeOkBtrGOzEY3Rv/j71t873 QDB2ArTu5DZouBYWktRWzL6Wjs6dS7A6cR7l/OaZDEaSUtgLN9vhijIP12yth0Ltnyhv zpcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=RnseO+HlWfm8PnP329KlCqz9KF+klL6BviqqSWTWuio=; b=hiibhL/1D7a74oykCt2RsdVZs6EPrlLP+yVP02e9O+votMlwm4XYPfoO22PDvYPAXK H4aFFNqBmKE7/1K3L9hY9Z6XqWJf58wrah6+171jxiw2eOhrB3vPv93NEr52CNtADrHu T2AhiQyKtZI2wrq2B9DKgdUb8WvIClYDBG5acqpEZMZkMbEMZ7W7kcZ4LKoIQm1yE+E+ ngnYwa45Tp75BtrSgH/Dtce0geW51BGa76z7tVSLCOcA4goIjoJswMya5es6ksBnk1c0 g6iMD8EfWD+sJ6SSdKex/Cx1v/bawvRvjTAPJFeLfFEl4nrho9wBnonMGe5Umce8FRy6 q20Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lgIb6O2Y; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id h6sor3932943lfd.24.2021.05.04.09.12.47 for (Google Transport Security); Tue, 04 May 2021 09:12:47 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lgIb6O2Y; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=ADlYhuXpnJFVZFOKeEJFXswOFo+2POOyDFdBtgoZM/SuYu0P8kOqDFlqRMeJ9UFjr8 O1LK7nSUlnbJ1p8WnCCrqjAOo4nuiBEQJ8hh45Umdj23lbTjDlHJrhlJ52wbxhpsJUuI brU+5b9s9e2uLX/sdgNBuy8uXRepOQJnpyx4+t6kM0wO1jE/tij3hiVEaUBPHOYOmPji irVsJWbdNxq6OrX/vc9f8SqcfU4BvNIXujRSP4nxU/X4mlqQ28d4nvjAm8sPwmimku5R CZ44dedz9mCYijG7OHEiZmJSGaq7cXibMlbJvZZGdV9pVwFKi2DxgDIECnoZbLa4bqFT +j5A== X-Gm-Message-State: AOAM531m24FP6U4cyqSSUqouT3E+3P8SKoRWG3i+Z7UWbGaIIHrWJF1j 94iie2cgPNlZw+e3fISKQ7pnU7zJ 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) Return-Path: 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 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 --- drivers/mmc/core/sd_ops.c | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) -- 2.25.1 Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin 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: 430885 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936540jao; Tue, 4 May 2021 09:12:49 -0700 (PDT) X-Received: by 2002:a05:6512:48c:: with SMTP id v12mr17004440lfq.132.1620144769257; Tue, 04 May 2021 09:12:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144769; cv=none; d=google.com; s=arc-20160816; b=u5HDWwoqRRkerMHC1LC2ozN1VV35ZCIhNhtLru7qSgfjlDEn/BZlvpsj/4cpDU/ViD SlefYKtydcTbXmQ3Ce643991yO7qVwVMZaI0FSBglY7RxGk7Vj8Nlo9gsFZQPhl7lR8K e5o90adAg0fJtEx4Xi+onw+vuLQM2nyK3nNZA8zawnQRP6/x5xL3PpXz/OeR4uLaolxa u3Md3pmhOG43aJC8UUQnqjVvK6BNmyDF48FrDFuVuc06Yp2nPY5JUEkAwKQLtNPpDedk +Cn8qL3HzQ3Gh/37IyQjKbHMY+/1RvJ8RhbYBK8IhsfqsTEJ0yfupLKur0kbEwzcd+9C IT2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=3YPvSgtMwuWKmsANJZN3wDrqLMspZZxchfU1o9bNBS0=; b=HbOZKyQDqLzlSp2pfFZm05cLSEa6FrSiDB6TAnhQ/dFNmjXtoRr6isfHAuQUrvq/Vd Gpe1jcB/gsKPAZOQ+UvSSMtTWHUOrN1kCC69KX3MpX3OemIb8NjJFv/dH2D9VchHJMaT Err1hfKOhJqSoBh42Wvu+ZhRUAzUs/SZGDSIq08K3RH04T/vW1dERG1sNbuMTnLqMpzN fT8uV94p802hUs1OmqAB43dU7a2EG5wNeKUngI1VLswmsZ3dmDpt4xLq45O0tQmRoUbF n5dy78vagTv08+JYXoJ+fYX2Cu8+NwS7xIVvlcxHi5fHe5G4Jqud2UAFO0mQzeJSYvIb 4UdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mQphSbjp; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id v23sor4145574lfp.145.2021.05.04.09.12.49 for (Google Transport Security); Tue, 04 May 2021 09:12:49 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=mQphSbjp; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=fMe+DtQXXPx+bUJbvQEkYBileMVQJtRsZZfYMfX46h/5QNLZRoCMrnm4b97wBDJJ/u hmI5rN1oT/Iq7ZUCPlkWgblS2dJzDh/kQ8i2yHTiHLWFY+aFlrWfVvkOxeKSGOO5DnQ/ +VKIiGJzrYJctlgY9dQ/fWp6p6OM604UzXrsp4qkR8dUHpoGLPvgdOExsZikoOASoLtE CJRmFb9hGnUHpGrix9bUt0m/JIOP2gywCAW/N7Uu8zdwpHTFrY1bVt47x3kUJwEP2JO9 5o7GfBpwg65gpu5TDHupxxyy5jgiH/7aZ66q6QeV0iXsdeEmCkV92DCnsSNDYaExONab MyIg== X-Gm-Message-State: AOAM531KY0W12/VSbk3bVl5io/Ftqs1XX0LhEuCIjTGK2Gz3wplLtPcd 2UYoEW/yGZecmsNfPLPNkn7vIO6B 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) Return-Path: 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 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 --- drivers/mmc/core/sd.c | 4 +++- include/linux/mmc/card.h | 2 ++ 2 files changed, 5 insertions(+), 1 deletion(-) -- 2.25.1 Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin 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: 430886 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936570jao; Tue, 4 May 2021 09:12:51 -0700 (PDT) X-Received: by 2002:a2e:9606:: with SMTP id v6mr17752540ljh.79.1620144770957; Tue, 04 May 2021 09:12:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144770; cv=none; d=google.com; s=arc-20160816; b=rekOh7Y13R4Tibw0JXvrA+wZ5kp93ONxPsRaxfOdAvN1CEBsn1JNMOVSWaMaH05pbT sbYSjZ8ECYPdFo4nN5DyDcau0rEjB+cFz+auXRU9bk4tsk8BGNbcE6Onch0JPTWCIoUg ZOHOucXDnKED0x7mYuOALZ+W2wB7ABvpGDlOiRmB7s3q66ilGfhwNgi7T1w+TDhwb5dt NlDtuHEqtB3VAUuy+CvI2zKkc9HjDgQoSnPwVNcq+3GDRvGHzf9oh8GsDCyadgYpIX8U weTBm8FHpP7/vcAj9D1q/zEOmEridbNnE2k19SjDgCB2Hc66kzLttDgTgicoUivR0jG3 f53w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=rUlKHRwg9oGMLgy4OD6Eu0j2Eug1Mwe4w1pydrhg7ho=; b=zpaHK/O68DJC3rWetsbEamQIB8xuVErK0XEboYKjYcARwku6PJM78mZqHb5Mg4Y2sq WSYhjm7QL3LgLLckdoGcsER9Z83cm61i5PbSDJYxG8fqMnoNFen+j+L9olyPgjjkBnNc 7IKatdTrAsxCceUbuUVrAVZj+3S+3Bs6qLO2rE/ekjveGTjjAxstvwW6sTx+a7xGZ09R k68q5pg93KRj04I7F5njFuMFMeX2HFLRYV283ibm6FPgS57rmc9uDq7UOuHXaL7k0DGP d5SYK4tfEA6xfy4uGGocWdj4L/8gLxL+eckgZmDtOyusA/C8QpIR0MZ9Vc1PMA6o+o3y 7uxg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eudWWkPW; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id x4sor4875845ljh.20.2021.05.04.09.12.50 for (Google Transport Security); Tue, 04 May 2021 09:12:50 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eudWWkPW; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=Riqtuc0OBqugRScMaSe81co7WxllWq9FpXH7wU6BzqTXRjeB816tJFuxVzjOIRSWNV KFQ72LWWdhgbNRdes2lqqi5stvqMfwwctjz/Z0qmGUpG12cSVjPRVOQyJK1586t62CTA u75jF6EYbMtArKVWmn71KGAS9oktu2t5zQEhH+MmDAqlMA2vrwoD9fFuwmm0AX6pM1ok 14qGcjZK6/NRonlNCo/ac6UD8Rm7ah4JPzUfBxto7+XKedm/fLtM/+csFyf3uFj+cjDH 3qYb+Q/WekRy+4k609t5aazkJOeR6ny0EcxK3aCZ502Mpbp1g0gN38VBeeb8Ier+gC43 eR2Q== X-Gm-Message-State: AOAM532H7uhcWCMobJYUqyz/LQgZXC/tVo8Wgt8dsRx1A2akabwLDw6C xk+9QUvBcgi54zXIzpkmTIMAT431 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) Return-Path: 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 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 --- drivers/mmc/core/sd.c | 178 +++++++++++++++++++++++++++++++++++++++ include/linux/mmc/card.h | 13 +++ include/linux/mmc/sd.h | 3 + 3 files changed, 194 insertions(+) -- 2.25.1 Reviewed-by: Linus Walleij Reviewed-by: Shawn Lin 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: 430887 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936605jao; Tue, 4 May 2021 09:12:53 -0700 (PDT) X-Received: by 2002:ac2:5e99:: with SMTP id b25mr6297275lfq.288.1620144772958; Tue, 04 May 2021 09:12:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144772; cv=none; d=google.com; s=arc-20160816; b=O9H09p7c1KH5LEBHQ6RR3cluY0HmbcJzYhs0S5oPhvxrz/AXE+ATEsczgSP0UAf1VU aTkIabWWr7OfuSuirmeCvmG8yqAbarN2v+A0FYQOOvrhsC9CuS59giheoXZdGBLKyTOw sihnYh3UBfhE02h/ezHsjtMzlfTOmWoN8r4AJRJHZB9mk/qOhunUgyrc/RFBXZpvGk3h hbFndSC2hhnh8NaqwijriSAOd4MuHTyM5CyQzqtGd4J5kZGQlhZ50FnjD9owLdTa+Ry4 3jjLsk6cZHyzXSUjfhXIOuab2heIqdontBLMo+umrvvTjDrl52V0VncEeAtWTan3yraF Um6A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=TugmmnMP6RDSPp2L8UfvdmsSklrTobWCwgxHv2Rsq4s=; b=p3vcTKy99LfT5HogNPCH+oPsh8dkkStJGGu8B9g5n9x8t24j4oL38fPNTSPqMKh+rG Wq1B/2IH/JO6hX4jCv59QbUJvtNBtOGnLMy6HlvMNbwe1Vtv4SFbe6qc05gZNJoGlxZN C0IHiEVoYmZ6DtPLZBsCivje5pKnDCHjwjftyat9i+wxDz/5xxwZ+XJbjtv3ko+pyI9v mRiaD+U6GMqjRG1tUXBchbksHu7RVxkz2o631OC5NYu/K2hn2R0p6CeUa/b9XZ1cSz34 i++/cDV/PpFKf+wXZ5/jHfLk/FWtUmS1v/GA4ytnzreETecfJV2T8CQdumEzCDeGn4hg UvoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x7LwYTyy; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id o25sor4332649lfl.59.2021.05.04.09.12.52 for (Google Transport Security); Tue, 04 May 2021 09:12:52 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x7LwYTyy; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=nlxlpfXBCf7iAIM7NsqUJZSgt8RTUaVtqhV/7r2wfR7okBw5/7G75tBNrypQQoT2oH /XXX3hEBsTVofQTWMl5i2c7ablPj0Ipc5mlvhvLRSllhR0hsoTLtbG3q3+Sul395zv0D csmqU/yqdm4FN+ZHwcgHhQMA+YjYvHQ3WQe+9idc51eslVAq4z58+oaI3HT2VnzW10yK GdAmR6s/PhQYXIgst/UwrUk3buFMOgB5lDCGEHtx5Hg4aQGAlXuflyDbEwE1nAM7I+si UkWCyDilHQfJI7pa5BR92QuomdeG8na3Ok2inzRn8wX40gY32TntO3nRKHlB7L8yLHtq +hkg== X-Gm-Message-State: AOAM533q5rF9lizbuJt/Ywx0ikjDtvtnJe2sae1ZAwWgYqjRCTqTSB9O dGNOwjGMp8bh4OAyda2dTbTNRLlGRejJAeDg3ig= 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) Return-Path: 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 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 --- drivers/mmc/core/sd.c | 53 ++++++++++++++++++++++++++++++++++++++++ include/linux/mmc/card.h | 7 ++++++ 2 files changed, 60 insertions(+) -- 2.25.1 Reviewed-by: Linus Walleij 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: 430888 Delivered-To: patches@linaro.org Received: by 2002:a02:c901:0:0:0:0:0 with SMTP id t1csp3936641jao; Tue, 4 May 2021 09:12:55 -0700 (PDT) X-Received: by 2002:a2e:9701:: with SMTP id r1mr18365191lji.213.1620144775040; Tue, 04 May 2021 09:12:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620144775; cv=none; d=google.com; s=arc-20160816; b=0EgtQVAI64QOljdLe5hIQ4Vy2bre30LRLDda4davFhF8VWjmSsGNhQ/afT5jjROKJ6 asjoHzTGVA3XSo2Lo3PvOYAgG1xAsWsh05QwKW1sp87CHu3OZ6uVSrzA4PTzlDWJBlPM 55MMC5bMUQBuHcI5FyMBJGVQJGgkHTOg7V/I4CWqZ4u1kjHcpb2LLC4f5IVC9AflZuf3 KXzJbF4ZMd7Z8seVipqCvL/MybskSmBNJSCEQQp+I0yH1m7/c5qf1JeEOX/q55hdsF35 8gVsjvoWGo31dgif+gNJiQK8UtiLIWfScrjyu+YDmsEUi1yeG/SmLwyll+PjnLeyvlKC H9LA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=xyxXmo/h/dfhEx4WikBIp+kaYZCmt7Npv/WLTwwg9eE=; b=Pdgeoo68oGgY59TWiizJ0QQiM7VOEvWq2+F0U8XIhBKAWsefrbAWYSONLDiRQ9DS6h tUCjEcgNM4DnzirX7ngMm3huIAbMlynv295KS1Z9UG8pQGbxYFwxA+sor4MmzqhwfgU4 7XJpMgGa1DxHP4jk4HeZVdx0eJlfikKQTMMcXCj9dlNAcnSLButY8cmrXF8KJ7X1lDFa iyfC+7keWl+uaerRenAfl3pPI7DKIoF+45TX6Dfp/4i04iwX4E3XvvnK4wzRjjqJdh8A 4M6Rs1xeOTIqWJoajgDc5Dn16VkUZ0vwy1ZgRd2lrghE4WPjtwQi2jR4EDCw2IvPUU1x wBWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="B/8bDkEW"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f41.google.com (mail-sor-f41.google.com. [209.85.220.41]) by mx.google.com with SMTPS id x16sor7781230lji.58.2021.05.04.09.12.54 for (Google Transport Security); Tue, 04 May 2021 09:12:55 -0700 (PDT) Received-SPF: pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) client-ip=209.85.220.41; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="B/8bDkEW"; spf=pass (google.com: domain of ulf.hansson@linaro.org designates 209.85.220.41 as permitted sender) smtp.mailfrom=ulf.hansson@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=jwZ4cZ4uy18sUgKR3+anG0TeJckTWdNCq3kmAI1i2X3xaiFKoLCVV7G9i0sPEp4rOb ARXYd7BqlqG29/5+mVt6plhrOTxL5hPIyZH50VB6QtzAtrNze8d+IpKY2DQpg9pgs2y7 QDFwnfm/gB+ID9nT74FqE2T2RaUf/YQWMJmo0uScWpTXrVUFkV6Bux35ooTeMg34lTor JyKH07UGJSIn4HyDV/SLl2P8n43BAz+ioSXUAfZUh+1znFDcLtKsrFG0wOKU5yYhVhBs suFu99vEFfuX4WzPaQVOXIs1qPlc97npWdMHE1/I5vQL86HmMUpEomSh48v5kFSTdfCU 717Q== X-Gm-Message-State: AOAM530EW5WPNS5LXqgLwgw1/dQ0Z950nk6cyL9iTI36ahXxbE13aWan fYUhBMBFpJ3cqMeV9JvJ4GCIjRpe 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) Return-Path: 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 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 --- drivers/mmc/core/sd.c | 136 ++++++++++++++++++++++++++++++++++++++++- include/linux/mmc/sd.h | 1 + 2 files changed, 134 insertions(+), 3 deletions(-) -- 2.25.1 Reviewed-by: Linus Walleij 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 */