Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp1772791lqm; Fri, 3 May 2024 06:19:47 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVco03zMK3vx878aTBE0jp5ihJDa5svue63yA1ZsIdCwOFJJdOxc8pjLk1mH7V9kPUTit3jc9yNQZK5N6PHObK00v1kZQM6rG7t8pj2Qg== X-Google-Smtp-Source: AGHT+IEhvJJ5I0e0W3zlnm8SyPd8CIENxQQYKlvloVq0tbVpDmMs8unD1hNWAD3DPqul3Gkf4Cej X-Received: by 2002:a05:6a00:3922:b0:6f3:b041:716d with SMTP id fh34-20020a056a00392200b006f3b041716dmr3044624pfb.17.1714742387632; Fri, 03 May 2024 06:19:47 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714742387; cv=pass; d=google.com; s=arc-20160816; b=QIVzVJxxkpwjfrNpriQS7+rlSO6e1ZBj/6G9kEGj3tA70zw/BqzzIUq4MOsK+F4gY2 RlE389T99UZj2xdutaXl78nqyXooIpT4flY0ZhfKyL3AiZu+BsS9YgLdBwmI2ibpTEPA WCfeCzVMP+ZX31zwa7gztpCUpLYe3TOty+ijvesHWzh7mBss6CVg73CIFgiqOgTAR2RL CWUCSzsNcmx7iwgmOlBm8N2PO00rAYGdIMwUzgB3ikQDkj+/HzFI5g3MtCbmi5uXQdqY jBeq/EYLQE/w7DUNF96jy+Be0WNFn6oCVN1smTwPz9iWUu9vkQI+Lo+ZPydN9p3FqYk+ 12rg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=yVNII6J9Gm42hbYviigMrcoeuivG18QFbOOCKlRMXeQ=; fh=fLNbGNecvfybgjmo6G8yeu43awbeLyqty9WwqjW9Vx8=; b=vDYb3wB1WyFLYfFx/x6tiV0yLrWKVKR1jGZwg47zUhYn4hrWkvgDZ//7rCs21eNqK6 wCv/sAInXlksWcwLuGp8eiBFeRY449a1KxFE9qgCCkDWc61BFkF3XNVEzvbofe5sDpwg yDpYB07+2uzd6nxvegQfs5Sx0gsIngCPVtlfHOaQdTF+2yY5GnBPz2qUj+yV7R3jDig7 in+HwZFBlplGYyl8FMC+v9TZQX5/DIQv1+9K/91IOymEKTwVR67KloAcipSmh2/9W6Ed OnuxTK0dNY4bj5HjIba9iVkNSbGVrnw4TURzaNqf26c+dr+9w9YTy2QlGsAknyHlGMra ZZmA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vyuk05+e; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-167688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167688-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id fj15-20020a056a003a0f00b006ed5f889124si3014120pfb.133.2024.05.03.06.19.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 May 2024 06:19:47 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-167688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Vyuk05+e; arc=pass (i=1 spf=pass spfdomain=linaro.org dkim=pass dkdomain=linaro.org dmarc=pass fromdomain=linaro.org); spf=pass (google.com: domain of linux-kernel+bounces-167688-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-167688-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.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 sy.mirrors.kernel.org (Postfix) with ESMTPS id D911BB228F7 for ; Fri, 3 May 2024 13:18:46 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 441C1153BCE; Fri, 3 May 2024 13:15:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="Vyuk05+e" Received: from mail-yb1-f179.google.com (mail-yb1-f179.google.com [209.85.219.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9569515357D for ; Fri, 3 May 2024 13:15:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.179 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714742118; cv=none; b=peS+AggWg+jL/WU1AaWGpR9uRR2KxJu7VkNxawz6yBhN4DrtJvUCk9u7WLD141bRUz9m9WS//c0WtXIGIsbwfyh3rWSlEi5P4IIW1vsxqp+nVqWAykYxze6w6IM7mX+0xiG59CInQgsLttVm++emsfQ+SAk2ZtKahOqhPJujc7w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714742118; c=relaxed/simple; bh=HzAUgRyvVHqHcP8yFm/mihYEIdANCSWUcftDdROCFAE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=YJxDxqRPYZJVSUeia1BV/wUci1J7TcjTw2IPvquTRhDRqDxr9tvdhVjKRcr8Jepq4AzJc/UDGp+LxN6KW6XtiJ9amQzlt7q5tk+VWKIU2ME+tvNYtEviE2AikPPBuuun2VSB5JyohDqqltgHoNpS+dZkObqXmbJerDpt88Mw8DY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=Vyuk05+e; arc=none smtp.client-ip=209.85.219.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Received: by mail-yb1-f179.google.com with SMTP id 3f1490d57ef6-de45dba15feso10644309276.3 for ; Fri, 03 May 2024 06:15:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1714742115; x=1715346915; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=yVNII6J9Gm42hbYviigMrcoeuivG18QFbOOCKlRMXeQ=; b=Vyuk05+enFU2uos24b99xANyP3PO1Z8oRuhox8FTQGeIJQozkEekmCBuG9wYXEm94i DCqcfgNV9UPMlgNW3DJgvhVkKQ9RpYAeDLtWaTnuOEpaAipv8BZUb85+z1e+bLzdtdUT /CS0BfPEsqF9tm8HbStWfniR8ILAH7TlMWwkBe+D/XWyRbofNCFMgch74k/wmkEVBJKn ObJGTtjOXhZTxOhgviXk5JgOVjDDbibewEX0Kr2Xg1leeS9ISIj58m4kfof5M6mVSstu pghcSTzl6RBALGAjIJl71st9+3JFSAQ52aMaptEQJUGRn+KR+YH9x7tNoCwKqIzxXJkw QAwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714742115; x=1715346915; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yVNII6J9Gm42hbYviigMrcoeuivG18QFbOOCKlRMXeQ=; b=qKQHTjt6tFBd3kJIlqLfYr+k4Vp5fsFfQoGnNCVuZQTRg9ImCbPLqnqEp7BCpZNOw4 WUN6GR5tyjh/pP9ctzGziLSGuRTcyoMrG6pjtuT7W0XxN9h241cCVpXi8LdS703m+AJj FCaAROWSWw5APnq1sY+Ivv4n2jLvyzqXPzT9U/D0XxtMmkNmXEEnvem0CCEN3fHdjoG8 5FV7EHHgFHUDtpvctu9uBZe4AjJMQbF1e3IiKfOM1Ta1ZLKVOBvoDkPvNBeAs4mUiKy2 BFuwJ8e99P+tnChmHxlRWZZVAYe8XdqHtxJS/XzPB2OHoNCyLehwwoDecA6CKDc/FblT 29GQ== X-Forwarded-Encrypted: i=1; AJvYcCUbN7CYwuF4ZnvjpHOIoyS7cehqGjgiOjMiOMAt6JEG9pvmFkKGzWiFN6L+9c0QJinRSdUYv8ku4+fRUK8nDrOPitFNrMx9zUdoaTSc X-Gm-Message-State: AOJu0YwC53Asy6ayKPkN21c5FLQhvGnrnhUdN8u2CVPGvZHQrC4OOm23 VMJLm2EOwAAn/KerN241ivmojJvISruAL+a+1zYug3aqaMWqFzW4mjVgjIYaJZLXTfu2ORyW5H0 6ZE74Z1nJqbx+k8y7uFylDks2FLzyOKCV0Kzpyg== X-Received: by 2002:a05:6902:2213:b0:de5:d1cd:b580 with SMTP id dm19-20020a056902221300b00de5d1cdb580mr3447075ybb.36.1714742115606; Fri, 03 May 2024 06:15:15 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240425133034.79599-1-ulf.hansson@linaro.org> <581352225de29859544b88f95ae5de89@manjaro.org> In-Reply-To: <581352225de29859544b88f95ae5de89@manjaro.org> From: Ulf Hansson Date: Fri, 3 May 2024 15:14:40 +0200 Message-ID: Subject: Re: [PATCH] mmc: core: Convert to use __mmc_poll_for_busy() SD_APP_OP_COND too To: Dragan Simic Cc: linux-mmc@vger.kernel.org, Adrian Hunter , Avri Altman , Felix Qin , linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" On Tue, 30 Apr 2024 at 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. Thanks for noticing, I have fixed it when applying! > > Otherwise, the patch is looking to me, so please include my > > Reviewed-by: Dragan Simic Thanks! Kind regards Uffe > > > + *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,