Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1724919lqa; Mon, 29 Apr 2024 18:19:41 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVuRwTaOwJLg2IjxGxdCb2j3ESFDud3SuBs/0i2prai/ElVk6imanSI8fcDNhs6oqCkCOkTNC551G5HHfCoiCx+2gbHPpRaPshcbnfTKg== X-Google-Smtp-Source: AGHT+IGYUFgBSzZi7427UP/Uvb8Kzl1TJMtpYHyrvsK9r0RzrivqaJrWFm8W7MHdR7XhaWCLAQ0L X-Received: by 2002:ac2:4c2f:0:b0:519:63c1:6f2b with SMTP id u15-20020ac24c2f000000b0051963c16f2bmr5903869lfq.54.1714439981509; Mon, 29 Apr 2024 18:19:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714439981; cv=pass; d=google.com; s=arc-20160816; b=bexzB1umey1r6Vkh1iU6FE2jwfqqAF11sQVF34ZfQNM8+gGAJoqHJErFlmBEsljkVF G5RjfKFlgEAez7aUd64VwFtS7flqACShIPH22j/JKLGtUnWASvclQt4XJkk3qoU6jlTe jUKZhMFsq3jCZGn14scFF48c7mQL38inu3YcCU8xwscdZKOtn7h8OrA6oNIEAow1M+fh 9C7AMSzOElGfMLY6dWGikGdq81+qRvIO+JiBl0zwc1gy0bBk1eg9+aKJdI1w1m2J7fvf 1VRmrNgeXFaODb/xdiVC7DZCbtUdzlHjt6N11rnQvxcKVRksfT3tk9pECZe0oukER1c9 NnKg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:message-id:references:in-reply-to:subject :cc:to:from:date:dkim-signature:mime-version:list-unsubscribe :list-subscribe:list-id:precedence; bh=PqS7lS1pIBbD6kDZllq0+3D20q6bY1tUda5Uk1RI7Lw=; fh=RU5qwii5mIxEMm2YySLqq3afvzb0UJXfcs4O4fvg2RA=; b=BRPFL/IBic3lYwuGS1Xq7Z4hsbEg2Fg+Nhhvy+H79sJ4ovyEn9RsiVNCdykTSbEJVX 6LMXpqXn166vSxYcsaYNQJ+3x6y6s86kU/UNj9UfzFeRe63fAK5TB+PGfc1UfqGZrisy niJx7mqMHfS/qS7VayAdTWtm2g7lisBHDyeEN11hOHLAr322sLFwDBOtGKvP8JKltRph TYKH4q4lz9QULn9h0tVeJXnaiiNjDpAXPY9pd5YtoEKXmrYp6d08XtCJwRulzYXvifwi 4Wm2PcMgmA3ufWYyU8gKR6HcXS7g8e5mL0FOO3WvYvYDf+YCl+itpaBdtOgfE49P+9jg mPHQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@manjaro.org header.s=2021 header.b=lLFpyqSo; arc=pass (i=1 spf=pass spfdomain=manjaro.org dkim=pass dkdomain=manjaro.org dmarc=pass fromdomain=manjaro.org); spf=pass (google.com: domain of linux-kernel+bounces-163219-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163219-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=manjaro.org Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id o20-20020a170906359400b00a58ee75c67bsi3079520ejb.219.2024.04.29.18.19.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 18:19:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163219-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@manjaro.org header.s=2021 header.b=lLFpyqSo; arc=pass (i=1 spf=pass spfdomain=manjaro.org dkim=pass dkdomain=manjaro.org dmarc=pass fromdomain=manjaro.org); spf=pass (google.com: domain of linux-kernel+bounces-163219-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163219-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=manjaro.org 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 am.mirrors.kernel.org (Postfix) with ESMTPS id 3159D1F218A5 for ; Tue, 30 Apr 2024 01:19:41 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D2FE8211C; Tue, 30 Apr 2024 01:19:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="lLFpyqSo" Received: from mail.manjaro.org (mail.manjaro.org [116.203.91.91]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5443117F5; Tue, 30 Apr 2024 01:19:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=116.203.91.91 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714439972; cv=none; b=WOEf/bWJZVsIqL03D1pu9CyG7JA+XirbR18JS8/ckQNYjgKKhfOl6SWSo1fGAaXS856TGbGfDTha4GrDKo0UKiEYj1soTFMjnIdMHafNboUNP92orCygkCZ+OoxorMqR1C0AAuN9zXb5Ox35DWXS4knc/43ndZtDSE/qhOkaDHo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714439972; c=relaxed/simple; bh=5iZ99hL8rLW9Omic3Ib3QCvQr5r/yy03qKPRpwL6b1Q=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type; b=kDNlD+5lH3uPP7b/9o/THnLX8BAWmDko+A8zvxpurrhlUSOISn6+6QyOFPcXcUeuO6n4SEWDGMnalJwrt1y4hDk2mU74HxOCfrukJTZxf5hH9pNNm/4X7G14Qcebey5IkMHTCah1K4SbGdtUNWvlusQlghEHiPU4i2fEERN+EPY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org; spf=pass smtp.mailfrom=manjaro.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b=lLFpyqSo; arc=none smtp.client-ip=116.203.91.91 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=manjaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=manjaro.org Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=manjaro.org; s=2021; t=1714439967; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=PqS7lS1pIBbD6kDZllq0+3D20q6bY1tUda5Uk1RI7Lw=; b=lLFpyqSoCd4YDFQ3nZQfh4C6eELTR5tG/ZP9vYPoNtjb/kLirRgx/DUgkP35dbA89vuCcK bHwvEBfFW+jo0m76i/nEXK4OQ3wybwZgHaXOeUblKjjJf46AQ8sNTPGDX6aXq2ZC1OP6We BeF1JwG29iBMQSDGrTh5t8kHLk7k0pJV6d5JNx6wnjSbV4tTs68xqeVYdhwhex/HVLsij1 2FVSXsdGAx7kmzMhw66TzLD+I2cFsrvRnv+LG3HCz0Mc+DjQxC7HO1seesL+cV7kdttVgq PmaF/06kHwNAfGtmHepLTbnZUEK9hJWxvsNnooSpPP4iVpBQHqo0zgolVQ8xTg== Date: Tue, 30 Apr 2024 03:19:27 +0200 From: Dragan Simic To: Ulf Hansson Cc: linux-mmc@vger.kernel.org, Adrian Hunter , Avri Altman , Felix Qin , linux-kernel@vger.kernel.org Subject: Re: [PATCH] mmc: core: Convert to use __mmc_poll_for_busy() SD_APP_OP_COND too In-Reply-To: <581352225de29859544b88f95ae5de89@manjaro.org> References: <20240425133034.79599-1-ulf.hansson@linaro.org> <581352225de29859544b88f95ae5de89@manjaro.org> Message-ID: <0062850816281e5720d88577cff2bfa9@manjaro.org> X-Sender: dsimic@manjaro.org Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Authentication-Results: ORIGINATING; auth=pass smtp.auth=dsimic@manjaro.org smtp.mailfrom=dsimic@manjaro.org On 2024-04-30 03:17, Dragan Simic wrote: > Hello Ulf, > > Please see my comment below. > > On 2024-04-25 15: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; > > Minor nitpick... An empty line should be added here, to > separate the variable definitions from the subsequent code. > > Otherwise, the patch is looking to me, so please include my Oops... s/looking to me/looking good to me/ Sorry for the noise. > Reviewed-by: Dragan Simic > >> + *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,