Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp382194ybe; Wed, 4 Sep 2019 00:57:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqxLBZ6bahbOpnK+29sC+sh+HSG/VJiG4DQrlA353hlli8BMh/CM4RYlRTFLUadP1UmVmYFC X-Received: by 2002:a17:902:ac98:: with SMTP id h24mr14764007plr.27.1567583841719; Wed, 04 Sep 2019 00:57:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1567583841; cv=none; d=google.com; s=arc-20160816; b=ta0RCSSZlb/4KpHCvfEU5EOF2cIMyAZsBBwdS0f+Z+JmEWIiHSEm5vexWKzEu0ol90 DELurxRSqMWn66E4mQuOvy57nYwFlgR0HYy17Gx8j3o1fc8YbfEIZ2N0nH791sTkB4ID 8kghXmqAHL3CB/B31xCt2CW4ZpXe6S6R8hGpqNei7vUkyxzVVpV24LGj9nZFqN+P1XoP JXI74fUFPIsFUWr+OD/4Qrz94uIgRmjSrTdWBMV/RqW+ExuaP7NIcbMOmMTz5vzEyTQZ UKz8r0OAVAevXNdaZ5Y6OXxfM9lBOxBQUh7thL+qm6ciWrmkrvirky9SJ6SXOVCTC3cT VW8A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=/zy6sHLHhMjntxLYsewceZr7FlH7FVNTOzqNeWl8yvc=; b=o13Y9CZVELW0InMjO68/5FO66WS8gNTY0c7UUFIDH9Wx9OXS5tU/qNT12r9wVtLL4n rua0EkXLzil7vpK6HmB3ib6WdDG41DSWTbtR0rnkUHyHBEGoxU4WP8DDQwLKG2RrM0/S MbaYuI6wf6vpGWCvzq/CfY05s5e6nCsPkB3vg9M+7pEdYpqOMqYiYOaOcmJ0eSCqZD9d Avs3LsAnWBUGYQ/OraJNgrN1STN9sK/7I/gqFhM7E1LVwSGT2NDpujFUDgdW99uCVXoz 5G8Vz4/32LSrCvs60Hl+4/0gp+5zAJfqDxaL1kUCLM6iNMRlCkrxCJUuQoOkSIpYua4c 9yDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ck12si1763784pjb.56.2019.09.04.00.57.06; Wed, 04 Sep 2019 00:57:21 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mediatek.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729350AbfIDHzA (ORCPT + 99 others); Wed, 4 Sep 2019 03:55:00 -0400 Received: from mailgw02.mediatek.com ([210.61.82.184]:51881 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1729112AbfIDHy6 (ORCPT ); Wed, 4 Sep 2019 03:54:58 -0400 X-UUID: 838997b885c34f9ca05f1094a8b60309-20190904 X-UUID: 838997b885c34f9ca05f1094a8b60309-20190904 Received: from mtkcas08.mediatek.inc [(172.21.101.126)] by mailgw02.mediatek.com (envelope-from ) (Cellopoint E-mail Firewall v4.1.10 Build 0809 with TLS) with ESMTP id 1684064925; Wed, 04 Sep 2019 15:54:54 +0800 Received: from mtkcas07.mediatek.inc (172.21.101.84) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 4 Sep 2019 15:54:52 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas07.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 4 Sep 2019 15:54:51 +0800 From: Chaotian Jing To: Ulf Hansson CC: Matthias Brugger , Jens Axboe , Hannes Reinecke , Chaotian Jing , Avri Altman , YueHaibing , Wolfram Sang , Ming Lei , Chris Boot , Zachary Hays , , , , , Subject: [PATCH 2/2] mmc: block: add CMD13 polling for ioctl() cmd with R1B response Date: Wed, 4 Sep 2019 15:54:44 +0800 Message-ID: <20190904075444.2163-3-chaotian.jing@mediatek.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20190904075444.2163-1-chaotian.jing@mediatek.com> References: <20190904075444.2163-1-chaotian.jing@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org currently there is no CMD13 polling and other code to wait card change to transfer state after R1B command completed. and this polling operation cannot do in user space, because other request may coming before the CMD13 from user space. Signed-off-by: Chaotian Jing --- drivers/mmc/core/block.c | 107 ++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 52 deletions(-) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index aa7c19f7e298..9d6f7a5612b5 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -468,6 +468,58 @@ static int ioctl_do_sanitize(struct mmc_card *card) return err; } +static inline bool mmc_blk_in_tran_state(u32 status) +{ + /* + * Some cards mishandle the status bits, so make sure to check both the + * busy indication and the card state. + */ + return status & R1_READY_FOR_DATA && + (R1_CURRENT_STATE(status) == R1_STATE_TRAN); +} + +static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms, + u32 *resp_errs) +{ + unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms); + int err = 0; + u32 status; + + do { + bool done = time_after(jiffies, timeout); + + err = __mmc_send_status(card, &status, 5); + if (err) { + dev_err(mmc_dev(card->host), + "error %d requesting status\n", err); + return err; + } + + /* Accumulate any response error bits seen */ + if (resp_errs) + *resp_errs |= status; + + /* + * Timeout if the device never becomes ready for data and never + * leaves the program state. + */ + if (done) { + dev_err(mmc_dev(card->host), + "Card stuck in wrong state! %s status: %#x\n", + __func__, status); + return -ETIMEDOUT; + } + + /* + * Some cards mishandle the status bits, + * so make sure to check both the busy + * indication and the card state. + */ + } while (!mmc_blk_in_tran_state(status)); + + return err; +} + static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, struct mmc_blk_ioc_data *idata) { @@ -623,6 +675,9 @@ static int __mmc_blk_ioctl_cmd(struct mmc_card *card, struct mmc_blk_data *md, __func__, status, err); } + if (!err && (cmd.flags & MMC_RSP_R1B)) + err = card_busy_detect(card, MMC_BLK_TIMEOUT_MS, NULL); + return err; } @@ -970,58 +1025,6 @@ static unsigned int mmc_blk_data_timeout_ms(struct mmc_host *host, return ms; } -static inline bool mmc_blk_in_tran_state(u32 status) -{ - /* - * Some cards mishandle the status bits, so make sure to check both the - * busy indication and the card state. - */ - return status & R1_READY_FOR_DATA && - (R1_CURRENT_STATE(status) == R1_STATE_TRAN); -} - -static int card_busy_detect(struct mmc_card *card, unsigned int timeout_ms, - u32 *resp_errs) -{ - unsigned long timeout = jiffies + msecs_to_jiffies(timeout_ms); - int err = 0; - u32 status; - - do { - bool done = time_after(jiffies, timeout); - - err = __mmc_send_status(card, &status, 5); - if (err) { - dev_err(mmc_dev(card->host), - "error %d requesting status\n", err); - return err; - } - - /* Accumulate any response error bits seen */ - if (resp_errs) - *resp_errs |= status; - - /* - * Timeout if the device never becomes ready for data and never - * leaves the program state. - */ - if (done) { - dev_err(mmc_dev(card->host), - "Card stuck in wrong state! %s status: %#x\n", - __func__, status); - return -ETIMEDOUT; - } - - /* - * Some cards mishandle the status bits, - * so make sure to check both the busy - * indication and the card state. - */ - } while (!mmc_blk_in_tran_state(status)); - - return err; -} - static int mmc_blk_reset(struct mmc_blk_data *md, struct mmc_host *host, int type) { -- 2.18.0