From patchwork Mon May 28 02:52:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shawn Lin X-Patchwork-Id: 10429697 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5AAEA60362 for ; Mon, 28 May 2018 02:52:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4B544284D1 for ; Mon, 28 May 2018 02:52:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3FFAE28A32; Mon, 28 May 2018 02:52:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.4 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,RCVD_IN_SORBS_WEB autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CD454284D1 for ; Mon, 28 May 2018 02:52:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753049AbeE1Cwx (ORCPT ); Sun, 27 May 2018 22:52:53 -0400 Received: from lucky1.263xmail.com ([211.157.147.132]:45627 "EHLO lucky1.263xmail.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752993AbeE1Cww (ORCPT ); Sun, 27 May 2018 22:52:52 -0400 Received: from shawn.lin?rock-chips.com (unknown [192.168.167.243]) by lucky1.263xmail.com (Postfix) with ESMTP id 5ADE0690B6; Mon, 28 May 2018 10:52:50 +0800 (CST) X-263anti-spam: KSV:0; X-MAIL-GRAY: 1 X-MAIL-DELIVERY: 0 X-KSVirus-check: 0 X-ABS-CHECKED: 4 Received: from localhost.localdomain (localhost [127.0.0.1]) by smtp.263.net (Postfix) with ESMTPA id 2AD403B2; Mon, 28 May 2018 10:52:50 +0800 (CST) X-IP-DOMAINF: 1 X-RL-SENDER: shawn.lin@rock-chips.com X-FST-TO: ulf.hansson@linaro.org X-SENDER-IP: 58.22.7.114 X-LOGIN-NAME: shawn.lin@rock-chips.com X-UNIQUE-TAG: X-ATTACHMENT-NUM: 0 X-SENDER: lintao@rock-chips.com X-DNS-TYPE: 0 Received: from localhost.localdomain (unknown [58.22.7.114]) by smtp.263.net (Postfix) whith ESMTP id 23341RJ2FJO; Mon, 28 May 2018 10:52:50 +0800 (CST) From: Shawn Lin To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, Martin Hicks , Shawn Lin Subject: [PATCH v2 6/8] mmc: core: Use mmc_poll_for_busy() for polling busy in mmc_do_erase() Date: Mon, 28 May 2018 10:52:26 +0800 Message-Id: <1527475946-11503-1-git-send-email-shawn.lin@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1527475842-10437-1-git-send-email-shawn.lin@rock-chips.com> References: <1527475842-10437-1-git-send-email-shawn.lin@rock-chips.com> Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Now mmc_poll_for_busy() could replace the whole bunch of code in mmc_do_erase() when polling for busy. Signed-off-by: Shawn Lin --- Changes in v2: None drivers/mmc/core/core.c | 46 ++++++++-------------------------------------- 1 file changed, 8 insertions(+), 38 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 6b9fc30..9509764 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -1962,13 +1962,18 @@ static unsigned int mmc_erase_timeout(struct mmc_card *card, return mmc_mmc_erase_timeout(card, arg, qty); } +static inline bool mmc_erase_in_busy_state(u32 status) +{ + return (!(status & R1_READY_FOR_DATA) || + (R1_CURRENT_STATE(status) == R1_STATE_PRG)); +} + static int mmc_do_erase(struct mmc_card *card, unsigned int from, unsigned int to, unsigned int arg) { struct mmc_command cmd = {}; unsigned int qty = 0, busy_timeout = 0; bool use_r1b_resp = false; - unsigned long timeout; int err; mmc_retune_hold(card->host); @@ -2059,43 +2064,8 @@ static int mmc_do_erase(struct mmc_card *card, unsigned int from, goto out; } - if (mmc_host_is_spi(card->host)) - goto out; - - /* - * In case of when R1B + MMC_CAP_WAIT_WHILE_BUSY is used, the polling - * shall be avoided. - */ - if ((card->host->caps & MMC_CAP_WAIT_WHILE_BUSY) && use_r1b_resp) - goto out; - - timeout = jiffies + msecs_to_jiffies(busy_timeout); - do { - memset(&cmd, 0, sizeof(struct mmc_command)); - cmd.opcode = MMC_SEND_STATUS; - cmd.arg = card->rca << 16; - cmd.flags = MMC_RSP_R1 | MMC_CMD_AC; - /* Do not retry else we can't see errors */ - err = mmc_wait_for_cmd(card->host, &cmd, 0); - if (err || R1_STATUS(cmd.resp[0])) { - pr_err("error %d requesting status %#x\n", - err, cmd.resp[0]); - err = -EIO; - goto out; - } - - /* Timeout if the device never becomes ready for data and - * never leaves the program state. - */ - if (time_after(jiffies, timeout)) { - pr_err("%s: Card stuck in programming state! %s\n", - mmc_hostname(card->host), __func__); - err = -EIO; - goto out; - } - - } while (!(cmd.resp[0] & R1_READY_FOR_DATA) || - (R1_CURRENT_STATE(cmd.resp[0]) == R1_STATE_PRG)); + err = mmc_poll_for_busy(card, busy_timeout, true, false, use_r1b_resp, + NULL, &mmc_erase_in_busy_state, false); out: mmc_retune_release(card->host); return err;