Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1322857pxb; Wed, 3 Nov 2021 23:36:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzX8bL0gyxuk6IuPf9DbRNXnf/spZDOyc07TbLJUXCT/9uS95ilkbPg+Gab5rTIo0JPQ20H X-Received: by 2002:a92:7f0e:: with SMTP id a14mr32653499ild.215.1636007766857; Wed, 03 Nov 2021 23:36:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1636007766; cv=none; d=google.com; s=arc-20160816; b=gX3dtfpaAvGaAAElSRmLyXhHZbBa9H2DOrbvHuCWbFAQpuxgUbCOAPcZriQOJFslaY DPpr1XK6mSlAsu5wwhmEUo6nx1ciEcVVkSfptbjl8UyV3Cg+vX6c/iAQwUkLR9hNc1m9 pYuHJkEY4xgktKHovLAPxsckoEaCzto1s9TZsStKawWE4Ew0Q8oT2d7p/rArB2ujTjmT zASFbw1T3UQVkI5Q5rzkK66GiwvKKPYasLXw9q+HywRVxUoZ89a1pLFzXkPLLkML9hP0 793upt++6PLDe61qrmvyiLHTMRVWWqCXJyVPjDuHkCFUjAIPefvS8VTMF+S4LxYtHeQS w+sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:dlp-filter:cms-type :content-transfer-encoding:mime-version:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:dkim-filter; bh=HbUW4qifAWoNUuU9gayTS1pIYwS2WitkSoJNEgHsies=; b=Xl2SySg2gWC4u150FwwKTJLfxiiLDxX96V1e3r71WaUJTQVunOuGKfEYQ9X3sniIKo d2vS1+ewhlcLkI56d43OqdXg4HTXWu/y6AiU1Gfb7iXBagGKQ11msBRV6nJ64WfU/rEW 82vxPML9Ba5NbxA4sUKCVdC6NxA0P/FuVO/EwAaHJ63YVHwyiJdXVQsZPR07MP6B5G5I tkLuqWgKPlj+OHZeob9tBV1sPocuQLg6xus8ntg4YwkJsqsNfj/osELOL8nvhQr2iiI4 U9ZzOxxwL5TNUH3FJvtvqjh9CvOiF2gK9Es31zk/M0E4A7LBjLcJ3hlgqzjAUXEUK6fC 2sfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=eq+sBj5r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id m15si8608343jat.58.2021.11.03.23.35.54; Wed, 03 Nov 2021 23:36:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@samsung.com header.s=mail20170921 header.b=eq+sBj5r; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=samsung.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230472AbhKDGfq (ORCPT + 99 others); Thu, 4 Nov 2021 02:35:46 -0400 Received: from mailout3.samsung.com ([203.254.224.33]:33173 "EHLO mailout3.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbhKDGff (ORCPT ); Thu, 4 Nov 2021 02:35:35 -0400 Received: from epcas1p1.samsung.com (unknown [182.195.41.45]) by mailout3.samsung.com (KnoxPortal) with ESMTP id 20211104063256epoutp037fad77257027ed0c83bac59a19cbe415~0RDkkA_Es0489404894epoutp03C for ; Thu, 4 Nov 2021 06:32:56 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 mailout3.samsung.com 20211104063256epoutp037fad77257027ed0c83bac59a19cbe415~0RDkkA_Es0489404894epoutp03C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=samsung.com; s=mail20170921; t=1636007576; bh=HbUW4qifAWoNUuU9gayTS1pIYwS2WitkSoJNEgHsies=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=eq+sBj5rSH1cPIigM8ji5Y6LYK8ou50Gy1JzH6jjV6hN1oSVrXyBPnlv2j17QmWbc /fNOAerCHtICjxyQ8QEBMMnV2wjKskRWA2A/dMPO4zgvWBoynB/o4xVhd6uC5d2VZF Q75KZ4Byr8OVpBDVwXLx/pJYxvIDQlSijUnKgAO0= Received: from epsnrtp4.localdomain (unknown [182.195.42.165]) by epcas1p4.samsung.com (KnoxPortal) with ESMTP id 20211104063256epcas1p4b7b0f710764b287e59389e671d60b126~0RDkLwAuX2541625416epcas1p49; Thu, 4 Nov 2021 06:32:56 +0000 (GMT) Received: from epsmges1p1.samsung.com (unknown [182.195.38.243]) by epsnrtp4.localdomain (Postfix) with ESMTP id 4HlDN50Y71z4x9QW; Thu, 4 Nov 2021 06:32:53 +0000 (GMT) Received: from epcas1p4.samsung.com ( [182.195.41.48]) by epsmges1p1.samsung.com (Symantec Messaging Gateway) with SMTP id 36.D8.64085.29E73816; Thu, 4 Nov 2021 15:32:51 +0900 (KST) Received: from epsmtrp1.samsung.com (unknown [182.195.40.13]) by epcas1p3.samsung.com (KnoxPortal) with ESMTPA id 20211104063250epcas1p36056caad956e599300146bae77f799d6~0RDe6DQHw0544305443epcas1p3D; Thu, 4 Nov 2021 06:32:50 +0000 (GMT) Received: from epsmgms1p1new.samsung.com (unknown [182.195.42.41]) by epsmtrp1.samsung.com (KnoxPortal) with ESMTP id 20211104063250epsmtrp132d1cb882998642c86b71cea5f8bcda1~0RDe5blWs0558305583epsmtrp1z; Thu, 4 Nov 2021 06:32:50 +0000 (GMT) X-AuditID: b6c32a35-9c3ff7000000fa55-6e-61837e9261f7 Received: from epsmtip2.samsung.com ( [182.195.34.31]) by epsmgms1p1new.samsung.com (Symantec Messaging Gateway) with SMTP id 08.19.29871.29E73816; Thu, 4 Nov 2021 15:32:50 +0900 (KST) Received: from localhost.localdomain (unknown [10.88.98.193]) by epsmtip2.samsung.com (KnoxPortal) with ESMTPA id 20211104063250epsmtip2a64034e61511a06726339c954d48cd69~0RDes1Z4i2388323883epsmtip2m; Thu, 4 Nov 2021 06:32:50 +0000 (GMT) From: Huijin Park To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, Huijin Park , Huijin Park Subject: [PATCH v2 2/2] mmc: core: adjust polling interval for CMD1 Date: Thu, 4 Nov 2021 15:32:31 +0900 Message-Id: <20211104063231.2115-3-huijin.park@samsung.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211104063231.2115-1-huijin.park@samsung.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFvrLKsWRmVeSWpSXmKPExsWy7bCmge7kuuZEg1VfGC1e7j3EbNFx0cXi 8q45bBZH/vczWhxfG+7A6rFz1l12jzvX9rB59G1ZxejxeZNcAEtUtk1GamJKapFCal5yfkpm XrqtkndwvHO8qZmBoa6hpYW5kkJeYm6qrZKLT4CuW2YO0FYlhbLEnFKgUEBicbGSvp1NUX5p SapCRn5xia1SakFKToFZgV5xYm5xaV66Xl5qiZWhgYGRKVBhQnbGnL8bGAumK1bs+3eJuYHx m2QXIyeHhICJxJk9s9i6GLk4hAR2MEr8u7GdHcL5xChx9NchVgjnG6PE5yN32WBavre1sUAk 9jJKrO/5iNCypWkBE0gVm4C2xPW1WxlBbBEBDYk9D8+zgtjMAl2MEjdvOYDYwgLOEhNmngKL swioSuz6d4QZxOYVsJb4+38lE8Q2eYmZl76zg9icAjYSS57/ZoKoEZQ4OfMJC8RMeYnmrbOZ QY6QELjELrFjxQ1GiGYXidYpc6FsYYlXx7ewQ9hSEi/726DscoldE65CNTcwSvSt/c4KkTCW ePd2LVCCA2iDpsT6XfoQYUWJnb8hZjIL8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veT83E2M 4HDV0tzBuH3VB71DjEwcjIcYJTiYlUR4n29oShTiTUmsrEotyo8vKs1JLT7EKM3BoiTOe6Hr ZLyQQHpiSWp2ampBahFMlomDU6qBac/y5ZMWXHNa1mmfLOK+7cf53YrVxSXXOr8Ydb17HMa8 VUerNDJp7ao5z3oCXxgyeOVdCnm9btWzuvOPv9jFu967I9BicsFhtjP3WicF9q55HhFLJxxk 8nsxW+njlMjTS+zdc1y+K7NwTTjkvnC7tF2SmfrP5e9Pxu8699En3qAuz8nri0tzsPlzPY52 bp/+UxFWuyJ+TnHnLC1qj9t3KP3vwhQF9b2XbkvInT28M2lD1bxboo9Ov9n46vGHizafVdNb fx/U93+/ryhwUpPNKotneeJqTemLC2bztgUW+JfemXbudtYb70+TCxTcX/j5pu6aezfvQmfK eV2X7i+pQavWZEZNFLyWeT/zqMybC0osxRmJhlrMRcWJADDv6mPGAgAA X-CMS-MailID: 20211104063250epcas1p36056caad956e599300146bae77f799d6 X-Msg-Generator: CA Content-Type: text/plain; charset="utf-8" X-Sendblock-Type: SVC_REQ_APPROVE CMS-TYPE: 101P DLP-Filter: Pass X-CFilter-Loop: Reflected X-CMS-RootMailID: 20211104063250epcas1p36056caad956e599300146bae77f799d6 References: <20211104063231.2115-1-huijin.park@samsung.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In mmc_send_op_cond(), loops are continuously performed at the same interval of 10 ms. However the behaviour is not good for some eMMC which can be out from a busy state earlier than 10 ms if normal. Rather than fixing about the interval time in mmc_send_op_cond(), let's instead convert into using the common __mmc_poll_for_busy(). The reason for adjusting the interval time is that it is important to reduce the eMMC initialization time, especially in devices that use eMMC as rootfs. Test log(eMMC:KLM8G1GETF-B041): before: 12 ms (0.311016 - 0.298729) [ 0.295823] mmc0: starting CMD0 arg 00000000 flags 000000c0 [ 0.298729] mmc0: starting CMD1 arg 40000080 flags 000000e1<-start [ 0.311016] mmc0: starting CMD1 arg 40000080 flags 000000e1<-finish [ 0.311336] mmc0: starting CMD2 arg 00000000 flags 00000007 after: 2 ms (0.301270 - 0.298762) [ 0.295862] mmc0: starting CMD0 arg 00000000 flags 000000c0 [ 0.298762] mmc0: starting CMD1 arg 40000080 flags 000000e1<-start [ 0.299067] mmc0: starting CMD1 arg 40000080 flags 000000e1 [ 0.299441] mmc0: starting CMD1 arg 40000080 flags 000000e1 [ 0.299879] mmc0: starting CMD1 arg 40000080 flags 000000e1 [ 0.300446] mmc0: starting CMD1 arg 40000080 flags 000000e1 [ 0.301270] mmc0: starting CMD1 arg 40000080 flags 000000e1<-finish [ 0.301572] mmc0: starting CMD2 arg 00000000 flags 00000007 Signed-off-by: Huijin Park diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c index 9946733a34c6..d63d1c735335 100644 --- a/drivers/mmc/core/mmc_ops.c +++ b/drivers/mmc/core/mmc_ops.c @@ -58,6 +58,12 @@ struct mmc_busy_data { enum mmc_busy_cmd busy_cmd; }; +struct mmc_op_cond_busy_data { + struct mmc_host *host; + u32 ocr; + struct mmc_command *cmd; +}; + int __mmc_send_status(struct mmc_card *card, u32 *status, unsigned int retries) { int err; @@ -173,43 +179,62 @@ int mmc_go_idle(struct mmc_host *host) return err; } +static int __mmc_send_op_cond_cb(void *cb_data, bool *busy) +{ + struct mmc_op_cond_busy_data *data = cb_data; + struct mmc_host *host = data->host; + struct mmc_command *cmd = data->cmd; + u32 ocr = data->ocr; + int err = 0; + + err = mmc_wait_for_cmd(host, cmd, 0); + if (err) + return err; + + if (mmc_host_is_spi(host)) { + if (!(cmd->resp[0] & R1_SPI_IDLE)) { + *busy = false; + return 0; + } + } else { + if (cmd->resp[0] & MMC_CARD_BUSY) { + *busy = false; + return 0; + } + } + + *busy = true; + + /* + * According to eMMC specification v5.1 section 6.4.3, we + * should issue CMD1 repeatedly in the idle state until + * the eMMC is ready. Otherwise some eMMC devices seem to enter + * the inactive mode after mmc_init_card() issued CMD0 when + * the eMMC device is busy. + */ + if (!ocr && !mmc_host_is_spi(host)) + cmd->arg = cmd->resp[0] | BIT(30); + + return 0; +} + int mmc_send_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) { struct mmc_command cmd = {}; - int i, err = 0; + int err = 0; + struct mmc_op_cond_busy_data cb_data = { + .host = host, + .ocr = ocr, + .cmd = &cmd + }; cmd.opcode = MMC_SEND_OP_COND; cmd.arg = mmc_host_is_spi(host) ? 0 : ocr; cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR; - for (i = 100; i; i--) { - err = mmc_wait_for_cmd(host, &cmd, 0); - if (err) - break; - - /* wait until reset completes */ - if (mmc_host_is_spi(host)) { - if (!(cmd.resp[0] & R1_SPI_IDLE)) - break; - } else { - if (cmd.resp[0] & MMC_CARD_BUSY) - break; - } - - err = -ETIMEDOUT; - - mmc_delay(10); - - /* - * According to eMMC specification v5.1 section 6.4.3, we - * should issue CMD1 repeatedly in the idle state until - * the eMMC is ready. Otherwise some eMMC devices seem to enter - * the inactive mode after mmc_init_card() issued CMD0 when - * the eMMC device is busy. - */ - if (!ocr && !mmc_host_is_spi(host)) - cmd.arg = cmd.resp[0] | BIT(30); - } + err = __mmc_poll_for_busy(host, 1000, &__mmc_send_op_cond_cb, &cb_data); + if (err) + return err; if (rocr && !mmc_host_is_spi(host)) *rocr = cmd.resp[0]; -- 2.17.1