Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1117850lqa; Sun, 28 Apr 2024 20:32:29 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVhvU+6rDw8Q2CWLvd9WRZaucAkPIZbG4sfhPENLyRFwGeCqqwsV1CbQEWvj0UcrS0Azq4GUTdDuw8O36ym+WoKHfe35t7sfz6BYiNFjw== X-Google-Smtp-Source: AGHT+IEB4bpiAzEnhpVmJtVxTJ2fgwW2sItuLinBTjTH4ILJDrRTdFUxx5y8YIs8Ng/++QyUdjGP X-Received: by 2002:a05:620a:5224:b0:790:a727:8f60 with SMTP id dc36-20020a05620a522400b00790a7278f60mr9710858qkb.9.1714361548904; Sun, 28 Apr 2024 20:32:28 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714361548; cv=pass; d=google.com; s=arc-20160816; b=N4ZH6pmJfxFfcqh6eH1kM1RXlqqJS32oFmp5NCKSZ8CEZIyN/u/WybWgaKAVodk4bM ZwrdW9ipG8WNeD3Dy5PlBBYpx9xEpGlOv0dyYM/olMVwaFWwMjOiqUnke14hcDn6CBQ1 2Z3B7Twy4Y/4/mmPbpeeiQsNICGDqIkn3VtTtrKKdP45gzETAntuYO+8cLW7hIBUYQu+ zdM5BZ6sd6Vyx72Cp/fHs6Dpjrg3B7lhsFKU2F0T+GMwEMEseqdEqZmb6gjTHqXd0Evy 7DSukOsKHCKpk5F+lr6tjVSh5BGfpflpg6ooxRxMMikj7UJR62+zJh/t6Jrlj5IH7q20 8tsQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:date:message-id:dkim-signature; bh=CHSUhxC6lM1/IFRN+7v8UnKMqdYD3kpZXA4RJ6Yr18A=; fh=FLE51e7dUd39p3yRhSalCBiAW63mLkSvIjoeZY81WDI=; b=ZFAsDeatpfJEnpa+JJcIo3vgSGWLebizHhYEsPZqNnezdTe9EkPn53lRJszN8frPJQ p+7myd6JxqlJcNOrpddKRfaeTr/ex4FZlMvysx1tgozq7HogPTq4ssjUJjMEPciXG5pe KCd5aBEvrlnzGIeOm55Tp/u98mQglu8h9FBWD3bxnl2xm3Ljrtl2nfeQyy5URg11Kgrw 8TenBf26J+YNnCNg5t+gqhc6HtvyqUIQsa91VgeELMbgTXYkw2rPSGVL2x3pEhTdRATy Zl+RlmmmcI8pT9N3smAFRDcnS5o/t40NCtFGfwT4LupgtkIlo5FjdNl4FzBZ5TyFyaau sgJA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b="VAY/pWr+"; arc=pass (i=1 spf=pass spfdomain=126.com dkim=pass dkdomain=126.com dmarc=pass fromdomain=126.com); spf=pass (google.com: domain of linux-kernel+bounces-161698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161698-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id t12-20020a05620a0b0c00b007906837a560si20470271qkg.103.2024.04.28.20.32.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 28 Apr 2024 20:32:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-161698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@126.com header.s=s110527 header.b="VAY/pWr+"; arc=pass (i=1 spf=pass spfdomain=126.com dkim=pass dkdomain=126.com dmarc=pass fromdomain=126.com); spf=pass (google.com: domain of linux-kernel+bounces-161698-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-161698-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=126.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 92CA51C2105A for ; Mon, 29 Apr 2024 03:32:28 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 45A2C8F6A; Mon, 29 Apr 2024 03:32:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b="VAY/pWr+" Received: from m16.mail.126.com (m16.mail.126.com [220.197.31.8]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3E8798BEC; Mon, 29 Apr 2024 03:32:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=220.197.31.8 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714361540; cv=none; b=Ef8D4NKcnjJhjsEqUTXt8bL6T0JsYfZ+ByV11yHeYPUsX/ClxxiB77PzNU3jy6/PKVwz3M6UAnOK5rUf92x1ZHEH71wCqf/9w08js9kn0yt/zAQ9Twcwf0+PygxeDEbxlxtwaSNNgv17jvmm+KYY75rtxIIo9aJaUst6ZUMSa8E= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714361540; c=relaxed/simple; bh=f2KQguX71x1xq7iC9KGN5UfbWpxX4Rd3/wmNbAjMcLU=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=I58asYjtimWwi+5lSvEkYasZj4P/8ImUSKXyylclRliaedoOSvJlAtnljbE9WV8Ymr/CghcBmx/AxK046WPutY+BK04/VaeHnmIvAixhfwlX3Cu5KDIpIq6kg226JhrTI4e3DyAAzXvSQt5JuAfeKLBbLE7X4q+vUNqL0OXPDzw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com; spf=pass smtp.mailfrom=126.com; dkim=pass (1024-bit key) header.d=126.com header.i=@126.com header.b=VAY/pWr+; arc=none smtp.client-ip=220.197.31.8 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=126.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=126.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=Message-ID:Date:MIME-Version:Subject:From: Content-Type; bh=CHSUhxC6lM1/IFRN+7v8UnKMqdYD3kpZXA4RJ6Yr18A=; b=VAY/pWr+mr1srwZ7TVWSsxCFRjJ4x5BDWIcj9slomL8YMxH110QFrsI82LJzq9 Rmhi/dsnpDpestidFNjF2DjPdfBcg/f8Sxjfh8339B5MkWOWf0OqUUtrIag9ApqW w5sapIsILs+O+AZ5AfAOKHBgCG+o4wU1/rlNt6OaMLEU0= Received: from [192.168.50.76] (unknown [58.22.7.114]) by gzga-smtp-mta-g0-0 (Coremail) with SMTP id _____wD3v7NwFC9mrac4Bg--.23843S2; Mon, 29 Apr 2024 11:31:00 +0800 (CST) Message-ID: Date: Mon, 29 Apr 2024 11:30:57 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mmc: core: Convert to use __mmc_poll_for_busy() SD_APP_OP_COND too Content-Language: en-GB To: Ulf Hansson , linux-mmc@vger.kernel.org Cc: Adrian Hunter , Avri Altman , Dragan Simic , linux-kernel@vger.kernel.org References: <20240425133034.79599-1-ulf.hansson@linaro.org> From: Yao Xiao In-Reply-To: <20240425133034.79599-1-ulf.hansson@linaro.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CM-TRANSID:_____wD3v7NwFC9mrac4Bg--.23843S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxGw15JF4ktFWrtFykKF17Wrg_yoW5tF18pF WUXryYkF4Dtr1a9F97WanF93s3uw1SkFWUG3s7X34FvrsI9r98KFyvkayFvF18Zr9rC3yI vFWjgr15u3sxJrDanT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07U65lnUUUUU= X-CM-SenderInfo: 50ld0yhhtl0xhhdo3xa6rslhhfrp/1tbiEBXP1WVLbIDYJgAAsj Hi ulf, On 2024/4/25 21:30, Ulf Hansson wrote: > Similar to what has already been changed for eMMC and the MMC_SEND_OP_COND > (CMD1), let's convert the SD_APP_OP_COND (ACMD41) for SD cards to use the > common __mmc_poll_for_busy() too. > > This change means the initial delay period, that starts as 10ms will now > increase for every loop when being busy. The total accepted timeout for > being busy is 1s, which is according to the SD spec. > > Signed-off-by: Ulf Hansson > --- > drivers/mmc/core/sd_ops.c | 77 +++++++++++++++++++++++++-------------- > 1 file changed, 50 insertions(+), 27 deletions(-) > > diff --git a/drivers/mmc/core/sd_ops.c b/drivers/mmc/core/sd_ops.c > index a59cd592f06e..3ce1ff336826 100644 > --- a/drivers/mmc/core/sd_ops.c > +++ b/drivers/mmc/core/sd_ops.c > @@ -19,6 +19,15 @@ > #include "sd_ops.h" > #include "mmc_ops.h" > > +#define SD_APP_OP_COND_PERIOD_US (10 * 1000) /* 10ms */ > +#define SD_APP_OP_COND_TIMEOUT_MS 1000 /* 1s */ > + > +struct sd_app_op_cond_busy_data { > + struct mmc_host *host; > + u32 ocr; > + struct mmc_command *cmd; > +}; > + > int mmc_app_cmd(struct mmc_host *host, struct mmc_card *card) > { > int err; > @@ -115,10 +124,44 @@ int mmc_app_set_bus_width(struct mmc_card *card, int width) > return mmc_wait_for_app_cmd(card->host, card, &cmd); > } > > +static int sd_app_op_cond_cb(void *cb_data, bool *busy) > +{ > + struct sd_app_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; > + *busy = false; > + > + err = mmc_wait_for_app_cmd(host, NULL, cmd); > + if (err) > + return err; > + > + /* If we're just probing, do a single pass. */ > + if (ocr == 0) > + return 0; > + > + /* Wait until reset completes. */ > + if (mmc_host_is_spi(host)) { > + if (!(cmd->resp[0] & R1_SPI_IDLE)) > + return 0; > + } else if (cmd->resp[0] & MMC_CARD_BUSY) { > + return 0; > + } > + > + *busy = true; > + return 0; > +} > + > int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) > { > struct mmc_command cmd = {}; > - int i, err = 0; > + struct sd_app_op_cond_busy_data cb_data = { > + .host = host, > + .ocr = ocr, > + .cmd = &cmd > + }; > + int err; > > cmd.opcode = SD_APP_OP_COND; > if (mmc_host_is_spi(host)) > @@ -127,36 +170,16 @@ int mmc_send_app_op_cond(struct mmc_host *host, u32 ocr, u32 *rocr) > cmd.arg = ocr; > cmd.flags = MMC_RSP_SPI_R1 | MMC_RSP_R3 | MMC_CMD_BCR; > > - for (i = 100; i; i--) { > - err = mmc_wait_for_app_cmd(host, NULL, &cmd); > - if (err) > - break; > - > - /* if we're just probing, do a single pass */ > - if (ocr == 0) > - break; > - > - /* otherwise 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); > - } > - > - if (!i) > - pr_err("%s: card never left busy state\n", mmc_hostname(host)); > + err = __mmc_poll_for_busy(host, SD_APP_OP_COND_PERIOD_US, > + SD_APP_OP_COND_TIMEOUT_MS, &sd_app_op_cond_cb, > + &cb_data); > + if (err) > + return err; > > if (rocr && !mmc_host_is_spi(host)) > *rocr = cmd.resp[0]; > > - return err; > + return 0; > } > > static int __mmc_send_if_cond(struct mmc_host *host, u32 ocr, u8 pcie_bits, The implementation looks solid and it works as expected in the scenarios I tested. Acked-by: Felix Qin