Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1872209rdb; Tue, 3 Oct 2023 03:55:49 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGBrgsbYuAfqSfdBaBb4RdXF5sCTM9HyA20gCHq8dIRMasq+MSyck3svHxmBeUllRQs5gEb X-Received: by 2002:a67:fa52:0:b0:452:e1f9:584c with SMTP id j18-20020a67fa52000000b00452e1f9584cmr12653068vsq.29.1696330549046; Tue, 03 Oct 2023 03:55:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696330548; cv=none; d=google.com; s=arc-20160816; b=oJueW1OgARpleSCycT63/orlVjre/8R5uTKPnC5972qXXmc9nMMTCJPxxmBW34ZNrT OYMDJxijMQZc/T/YKWz8Gk8G45vBRb4aYmdFfMV5796KXTQUb6JwLTzJQ2a9dura5bWC Vrh4keUjrutPK4xepRJqfjxMeudZBAYCzsp/gq8pml7yfQeFx6obwFtrOGo0jlpf1Ghh u8OFuKL/Gqk/x0wkLEgOZf2IRvlaf8bolZZZ7yx8zEbItkJ6yTRc3mKwdxkqs2dVLrSv kmETv08DBb2BoaD/gGsGYqA3LaOue9s+6hS2edD4xC2cZ4RijcJSYg/75K9tvVU+dgui 2c0Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=uLeNz/tHlH5fEkHGvlFYa80O2Py5PCvrgAn0bS6V+94=; fh=vBnKFefFPFrDyJU1mppZP0jQUnKYIcYzbFz/qeRKvVo=; b=eoj3wg06NWVOl1/wXdWFP+TEiJgtICA5gr1lLaxOLY1ChEAvaL+C3zHCA1Iz33SlJe Rh4foT5ynoP360Ap6hA9RuKaTv7U3Y68FYm6fBiE5+1LYHzJbxTbIQSghyB91lBKLh1F t3gvl9j5diQpItUoRVnYsVS/zNMW+YxxDbo9zLWxIsNzp8Ux+CeTYTgCa2zS4wchJOin Bcvw6Mf9krIV1coPeM8RjyvCsMPyHh3N0z9BZ+QQXlH4ktwf6tHoOmZl9VjDxjrWwwZ7 7FVAlnnmu7m8J4bdInfFfK5kTWm+rCy3aJfKqm0X1NQd8CU6aC1nU2k10mDGZEd7r6HY cTdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YAFjnXfv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id f27-20020a63755b000000b005859c255cedsi1150576pgn.197.2023.10.03.03.55.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 03:55:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YAFjnXfv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id B79ED808726C; Tue, 3 Oct 2023 03:55:27 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231555AbjJCKzY (ORCPT + 99 others); Tue, 3 Oct 2023 06:55:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34430 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231566AbjJCKzX (ORCPT ); Tue, 3 Oct 2023 06:55:23 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 667C5AF for ; Tue, 3 Oct 2023 03:55:20 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id 3f1490d57ef6-d8a000f6a51so855894276.3 for ; Tue, 03 Oct 2023 03:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1696330519; x=1696935319; 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=uLeNz/tHlH5fEkHGvlFYa80O2Py5PCvrgAn0bS6V+94=; b=YAFjnXfvoAAGMnQQKft0jjX/2ohqgWMTXeQMdOFUiufRzQIlbBJymRTPevIH7yjef2 GGU95GxRFyW00wp944Xk63Hxz7M8HZm5RE/W6c39A76RDvwobkfWwWgg44s9C/ZgEdU7 EPwfHTWcaJikUKUF3TrwTpxX8IzKuOEd01hM/YTs2E+KfeMohR2uGt/1XqHeWHXEk71I 7SEffahAQYGzlz11jyca/fxRzczYNnARr+Ry3jxaQf/omEK90pkaP3n27dTeLaBPmxjs bMJcJ7zAA+QfY1dHNM+gGu+/xauEHUDWzq1cthbxHWqqSaMOOg8icJeCHQx6+bE9OYXO 6Kfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696330519; x=1696935319; 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=uLeNz/tHlH5fEkHGvlFYa80O2Py5PCvrgAn0bS6V+94=; b=r/bWR+Bzf5oghgO7e8ZqC0Co/XotF366izNBKK/iiuZWNqztLdVb8vfx0sJkcPgbYm +40YgpUr0CiXv3s4owSwxG0L1nV8RrH70v36kAE34tl/KKL5so2UwiJHNmP297X2MI4K WvQm/Jy4PlXHoAZKFvYJJk24dR6K7f04Xj0KcugFk6LqgxUiAbKNENRKxUs3BcLNacod cENZBhIcBK0GAjJFQTz43WjQRYPg+ZlHkkYxo64+uk5N8BYalnCZsZ9dz9aa0CmniH5U tFSYVyXm2t9za8bwSaUW0Tl/LKJlbjVHfvZ8GEPhA4wp72xJsL7k7x72bvHami+xbjQx ZnWg== X-Gm-Message-State: AOJu0YxkGJqn8TQymDIwLB6gnSyQK0fNczZ91A1/x2X5LXk9idddjo8t fuCqSQ+eaOOoChe5SNUsvDToWqyj65FzKd6gfrPBbJPr8Ef2kuWj X-Received: by 2002:a25:83d0:0:b0:d71:68e4:6db8 with SMTP id v16-20020a2583d0000000b00d7168e46db8mr12245016ybm.34.1696330519569; Tue, 03 Oct 2023 03:55:19 -0700 (PDT) MIME-Version: 1.0 References: <20230915094351.11120-1-victorshihgli@gmail.com> <20230915094351.11120-14-victorshihgli@gmail.com> In-Reply-To: <20230915094351.11120-14-victorshihgli@gmail.com> From: Ulf Hansson Date: Tue, 3 Oct 2023 12:54:43 +0200 Message-ID: Subject: Re: [PATCH V12 13/23] mmc: sdhci-uhs2: add set_timeout() To: Victor Shih Cc: adrian.hunter@intel.com, linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org, benchuanggli@gmail.com, HL.Liu@genesyslogic.com.tw, Greg.tu@genesyslogic.com.tw, takahiro.akashi@linaro.org, dlunev@chromium.org, Ben Chuang , Victor Shih Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 03 Oct 2023 03:55:27 -0700 (PDT) On Fri, 15 Sept 2023 at 11:44, Victor Shih wrote: > > From: Victor Shih > > This is a UHS-II version of sdhci's set_timeout() operation. This needs more explanations and justifications. Other than that, the patch looks good to me! Kind regards Uffe > > Signed-off-by: Ben Chuang > Signed-off-by: AKASHI Takahiro > Signed-off-by: Victor Shih > Acked-by: Adrian Hunter > --- > > Updates in V8: > - Initialization be combined with declaration and realigned > in sdhci_calc_timeout_uhs2(). > - Forward declare struct mmc_command in sdhci_uhs2.h. > > Updates in V6: > - Use GENMASK() and FIELD_PREP() in some case. > - Use sdhci_uhs2_mode() to simplify code. > - Remove unnecessary functions. > > --- > > drivers/mmc/host/sdhci-uhs2.c | 72 +++++++++++++++++++++++++++++++++++ > drivers/mmc/host/sdhci-uhs2.h | 2 + > 2 files changed, 74 insertions(+) > > diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs2.c > index 92fb69b7e209..d519e6ce6199 100644 > --- a/drivers/mmc/host/sdhci-uhs2.c > +++ b/drivers/mmc/host/sdhci-uhs2.c > @@ -13,6 +13,7 @@ > #include > #include > #include > +#include > > #include "sdhci.h" > #include "sdhci-uhs2.h" > @@ -142,6 +143,77 @@ static void sdhci_uhs2_set_power(struct sdhci_host *host, unsigned char mode, un > } > } > > +static u8 sdhci_calc_timeout_uhs2(struct sdhci_host *host, u8 *cmd_res, u8 *dead_lock) > +{ > + /* timeout in us */ > + unsigned int dead_lock_timeout = 1 * 1000 * 1000; > + unsigned int cmd_res_timeout = 5 * 1000; > + unsigned int current_timeout; > + u8 count; > + > + /* > + * Figure out needed cycles. > + * We do this in steps in order to fit inside a 32 bit int. > + * The first step is the minimum timeout, which will have a > + * minimum resolution of 6 bits: > + * (1) 2^13*1000 > 2^22, > + * (2) host->timeout_clk < 2^16 > + * => > + * (1) / (2) > 2^6 > + */ > + count = 0; > + current_timeout = (1 << 13) * 1000 / host->timeout_clk; > + while (current_timeout < cmd_res_timeout) { > + count++; > + current_timeout <<= 1; > + if (count >= 0xF) > + break; > + } > + > + if (count >= 0xF) { > + DBG("%s: Too large timeout 0x%x requested for CMD_RES!\n", > + mmc_hostname(host->mmc), count); > + count = 0xE; > + } > + *cmd_res = count; > + > + count = 0; > + current_timeout = (1 << 13) * 1000 / host->timeout_clk; > + while (current_timeout < dead_lock_timeout) { > + count++; > + current_timeout <<= 1; > + if (count >= 0xF) > + break; > + } > + > + if (count >= 0xF) { > + DBG("%s: Too large timeout 0x%x requested for DEADLOCK!\n", > + mmc_hostname(host->mmc), count); > + count = 0xE; > + } > + *dead_lock = count; > + > + return count; > +} > + > +static void __sdhci_uhs2_set_timeout(struct sdhci_host *host) > +{ > + u8 cmd_res, dead_lock; > + > + sdhci_calc_timeout_uhs2(host, &cmd_res, &dead_lock); > + cmd_res |= FIELD_PREP(SDHCI_UHS2_TIMER_CTRL_DEADLOCK_MASK, dead_lock); > + sdhci_writeb(host, cmd_res, SDHCI_UHS2_TIMER_CTRL); > +} > + > +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd) > +{ > + __sdhci_set_timeout(host, cmd); > + > + if (sdhci_uhs2_mode(host)) > + __sdhci_uhs2_set_timeout(host); > +} > +EXPORT_SYMBOL_GPL(sdhci_uhs2_set_timeout); > + > /*****************************************************************************\ > * * > * MMC callbacks * > diff --git a/drivers/mmc/host/sdhci-uhs2.h b/drivers/mmc/host/sdhci-uhs2.h > index 8253d50f7852..ccf4e1834c2d 100644 > --- a/drivers/mmc/host/sdhci-uhs2.h > +++ b/drivers/mmc/host/sdhci-uhs2.h > @@ -175,9 +175,11 @@ > #define SDHCI_UHS2_VENDOR_PTR 0xE8 > > struct sdhci_host; > +struct mmc_command; > > void sdhci_uhs2_dump_regs(struct sdhci_host *host); > bool sdhci_uhs2_mode(struct sdhci_host *host); > void sdhci_uhs2_reset(struct sdhci_host *host, u16 mask); > +void sdhci_uhs2_set_timeout(struct sdhci_host *host, struct mmc_command *cmd); > > #endif /* __SDHCI_UHS2_H */ > -- > 2.25.1 >