Received: by 2002:ab2:1689:0:b0:1f7:5705:b850 with SMTP id d9csp1724378lqa; Mon, 29 Apr 2024 18:18:06 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWoYTaZg/jrbKBNqyK3q68Fmx9GGtnYIDWt3H9jUYI0/wpEP6Rcto46YSGNXDuRvTEj4l9EKC3dkF8FP7f0TKPyj5AcydPXOTq9VGHAqw== X-Google-Smtp-Source: AGHT+IG7p59TZNj8AmYKfOs8qj9zowtgIedmGHDi9kpwJJGDts19No+3IyT+VyL9zpsJBX6XdEZ8 X-Received: by 2002:a2e:95da:0:b0:2d8:dd28:8748 with SMTP id y26-20020a2e95da000000b002d8dd288748mr6814335ljh.1.1714439886263; Mon, 29 Apr 2024 18:18:06 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714439886; cv=pass; d=google.com; s=arc-20160816; b=tjRxGYPnQKDXBobjuoXe+JfiwiSziiaXZ3XKFhWScf9/yWRSJ2yrPKAje9El1Yys9t ClYEeCOkjv/jq0LIBsJhXBbfcyDYGcRWLmI40cHbdEZ9nUGaD7KlY3kcQ4CCYtffv0ZB xpp1uKnJAyqE6ZtMNGeN6BbhSpMxu9H+I5wxel0MwaW1aPhgfkZHS1ctBXMW4FebzM9A XK7TsxQEWFyQdlzFd7DXd/BRhZEvruI+HWyjxJZItss6x5CjYeGaEZhGILkHfgqiZuPp SmDRBXXGVkdxy/ogtDTMSXptAZpKlgIWCS9PDXXANyyfXh1Ph4ZBjgyLkX3GDzVptqG4 8ukg== 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=CPP2Y7+4lIcvbSyWo3Mqwwjrkod3nWNj2T4EfqTdNgw=; fh=RU5qwii5mIxEMm2YySLqq3afvzb0UJXfcs4O4fvg2RA=; b=mF7dZ2KqkC9K1Dg9PAtHmTGeTCbCB5Q4eKocA5SrI8o+Susgx1oecrpvV+tlMDm4db rUMwaaC1muQe7iB8f3QlqS3H5BUNPe0Ge8WjlnJf+Ums8sMazK0w05RcWwMpebgu2vGS DP9jCKDrc8055VsvgMH1YNjMUkxAm9OocCw6m1GtXpJFNF3Ed0K4e+ZXRrGs2R8VjKpr 7p0TiWu5HmV7GUCN5DiGP6bytlqbqR9/ko6PNn8lF+DLtpQYUMWZLcfVzLneoJ1PcTOe qPrY+JXtxowtsgvT9ZlN+EYuBbVFHxe/gVn6Wi7qpuzbsI3rxo5Nh3WsejfLeW6a5vMp rZCA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@manjaro.org header.s=2021 header.b=ujdfOPlj; 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-163218-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163218-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 v23-20020a50d597000000b00572242f02casi8237005edi.122.2024.04.29.18.18.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 Apr 2024 18:18:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-163218-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=ujdfOPlj; 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-163218-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-163218-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 C98BB1F2184B for ; Tue, 30 Apr 2024 01:18:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 73E2A2107; Tue, 30 Apr 2024 01:17:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=manjaro.org header.i=@manjaro.org header.b="ujdfOPlj" 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 4F8FB1FA4; Tue, 30 Apr 2024 01:17:53 +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=1714439876; cv=none; b=DwFH/Qn1gghWVLaeDjIrG29lL4WE1TXr5LBd7SqbaN/a+02WlNkRHXsNZFW+r3Z6O4R/L8b8zNJE82f59MRjV4uENroBQgBxqA7jOm6yjtyQD5dMechfy3ZHfrljZ2/pq/Ysr2uZ0URBV2HXp6uYjE30v8IwkIi8AzPTZX4xh+k= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714439876; c=relaxed/simple; bh=BOmEbAuWOQj/1+m4/q3FLSzQUGKdfJJVnapot4vtFyc=; h=MIME-Version:Date:From:To:Cc:Subject:In-Reply-To:References: Message-ID:Content-Type; b=BnNl/sFiHmJOiGXzCKNTjWTfAFk6viV2In4tKZbptkZkkI4wMK/5MkX6MA4nJnXxQo+HQN4f+Nj2bdGJT60QboXQckawfd86e46KAibq0QKDkyxrAzSWA45waDE7h/0bixPH9X7ZkTDEYUyIOrGcF1d7ZoJce1gTyxTStATl3Es= 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=ujdfOPlj; 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=1714439870; 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=CPP2Y7+4lIcvbSyWo3Mqwwjrkod3nWNj2T4EfqTdNgw=; b=ujdfOPljn9Ji/gwAy45S8FcabYS8bpQ8DkuBf9jxmziqvLWWx3CF2Hs+T43lskJoezCW0c RHLlMjej0UnR8gvMiD5YlMXI5LSQrIbMsxNkiUy9gCNWEy5UTfMLYHYn4VJy9BdjPdnEq2 zDTiTV9V/x8iSkTwvN5t/8vYJaCYcZO0LeYFF1QTfpL8GE7LfSmAtuWatTZ4GxfQEgocrw 8cKjZ4pBYwAQ2CsLX4CJVXoEFtcnfCMq0+cixKAnRIC2wwT6ZPvhYDEavYsoLiU78KN69v wpjFQlIfq7mC6rUz8N3fkZUzeedxz2Dbu7do82/yq+GaY11Tkq02IFDN3r8Zlw== Date: Tue, 30 Apr 2024 03:17:49 +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: <20240425133034.79599-1-ulf.hansson@linaro.org> References: <20240425133034.79599-1-ulf.hansson@linaro.org> Message-ID: <581352225de29859544b88f95ae5de89@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 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 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,