Received: by 2002:a05:7412:b130:b0:e2:908c:2ebd with SMTP id az48csp424321rdb; Fri, 17 Nov 2023 02:52:30 -0800 (PST) X-Google-Smtp-Source: AGHT+IH1jq9rVf97D7Y+/zP24n10daYj2PJDvsBsuIyAqOOi21Hlzwl/6BA7TgAd6OrrG2lE41kE X-Received: by 2002:a05:6870:5b33:b0:1d7:1533:6869 with SMTP id ds51-20020a0568705b3300b001d715336869mr17558317oab.31.1700218350346; Fri, 17 Nov 2023 02:52:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700218350; cv=none; d=google.com; s=arc-20160816; b=afwchn7tOFiFW9Jy63BiaXqL0HmkNShPojQ5AuhbIv8vwwuA+uBw8XqK09BJSHWJPM CYrN+OWm1LeWPBa0W9bMUVxIZyssUYwknmuUt95flgh8VRrrsSI14JXgEWOYz7lRRbSP UODXKWSwuBlJEtV3DV3f6wmntKuyaPQn1M5Gy5awwnYK5Ky4flBLmTcv+EW8e+YfAoeY 8itd1exhjrdTtxLlXVc7FkuYDe8Ykj6mwj6hSDnF9K2CYaBxAej8CsrbEoKCkrekQvqq B93sDAsl0gZJXskUm2HHKY3XN7IpKrAD2a/nQVjYNL/Z8Ftk6HhWHxKh337JZiD58rlr dgNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Vg6ZRI4dNrEPiTO9SEzNCL6/GObRrK4fghBQ1m3rpkM=; fh=E9dRX3P9+1ACoiVN3TLqgt71N7WLrYiSbf3DtPzMktQ=; b=csIM2Yv9ODDS0XbHdSgAdS0pDXtMv+LJJmSPSw2fvg6SzrfDQcdozvSwPzbhR/gGWM Pig6LKL1ApN+3KDkOQKYkO39h5iWqwVgN1gd/PX9Wps56yGGySsc5PX8rS3IbQNSv8mm DU400A8rFRtZWE3THeSpGGePsRzGxcm0Rxifuaac24UnsKwTpTDUjfDYz/fmt2vLiTKv uxwzoL4zCCXbqPuvLnotzEaak1nWhGpwkk0GEi/PA9HS/YBBOoCWE9GW2gM8iqNmO6uc +3hAqi6nnBMHpGDDbu7bNsvctA+/nFKPt7lnwwb96yS0LVFyxn81sXU7sEFC4nfK/BsS in9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=HsPwIIe4; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id c13-20020a056a000acd00b0068e47f1fc7esi1706480pfl.159.2023.11.17.02.52.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Nov 2023 02:52:30 -0800 (PST) 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=@gmail.com header.s=20230601 header.b=HsPwIIe4; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id E61F18047069; Fri, 17 Nov 2023 02:51:12 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346073AbjKQKu7 (ORCPT + 99 others); Fri, 17 Nov 2023 05:50:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346061AbjKQKul (ORCPT ); Fri, 17 Nov 2023 05:50:41 -0500 Received: from mail-vk1-xa36.google.com (mail-vk1-xa36.google.com [IPv6:2607:f8b0:4864:20::a36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB0641738; Fri, 17 Nov 2023 02:50:29 -0800 (PST) Received: by mail-vk1-xa36.google.com with SMTP id 71dfb90a1353d-4acb1260852so643757e0c.2; Fri, 17 Nov 2023 02:50:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1700218229; x=1700823029; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Vg6ZRI4dNrEPiTO9SEzNCL6/GObRrK4fghBQ1m3rpkM=; b=HsPwIIe4XxjY9cLGpLycT99bZVLzbtfHilzhPD6o5xcjOhAENhY5tLpY1GR/DydQKj sNJiDujDUxHU6LlY9koGq8lHrBQevs8B+ryTWwWQXbfCd0G7Ut/KOI7mC1f12FaCqnZ+ T/swqeus23SWE2GC09I+Xrn/FNRvd1N8IHymvKQzLwdU/9S5VNTQypW9PdSI4JbTpt57 AkQFt59X9nk2rXpmkN18i4TK+cnEMCFzTn7YftglReip8nVD9Ls1lMsQA80Je/UU/jNy ADb077nnePSan70/0F9imR+iwCeynq/wPhRxskYN7weC1XnjBZd2IF0DtU3GIjMGlMHX Xh5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1700218229; x=1700823029; h=content-transfer-encoding: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=Vg6ZRI4dNrEPiTO9SEzNCL6/GObRrK4fghBQ1m3rpkM=; b=belVqAfJ9aUvU/Tcyny6/qf90RW4VomT66GSwdyENsyU7kgaQ5g6B3p51lF+3/EhdJ XVV5V7O5ohuwCAvn3YItA9Za5FP/mXgnbEELwfGS/M53wEQLrXmjyxpEL6F8jRaoQHwS nBpJeJszxXpOlc882eE0GBZawfhCJj0rLI3p0Oqghu61VE8E2sjy0suufS7HeNFjduQq H0Kt1w4oZVnTFYVaGhiVpMo24FSXf8jzA2uynrM7AbtrGDgyZVZVUqdkXE+dmx6J/eCT rH4TvC5xDRUHFh2/x5/iknNQxOOaJ19wGQMPV6BPdjuYUhaEjibtD4PDzjPyxn0xe5dl L7Fw== X-Gm-Message-State: AOJu0Yzi5tJCJhIvH68JDUQnq2relHmAP42IQfJAublPmEveAGHqe1Ob RVDdCNBGKVAI4PNkABu4cULfW68nA6gKNpAvAJE= X-Received: by 2002:a05:6122:468a:b0:4ab:fc1a:ae93 with SMTP id di10-20020a056122468a00b004abfc1aae93mr19402394vkb.16.1700218228753; Fri, 17 Nov 2023 02:50:28 -0800 (PST) MIME-Version: 1.0 References: <20230915094351.11120-1-victorshihgli@gmail.com> <20230915094351.11120-19-victorshihgli@gmail.com> In-Reply-To: From: Victor Shih Date: Fri, 17 Nov 2023 18:50:16 +0800 Message-ID: Subject: Re: [PATCH V12 18/23] mmc: sdhci-uhs2: add request() and others To: Ulf Hansson 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" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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]); Fri, 17 Nov 2023 02:51:13 -0800 (PST) On Tue, Oct 3, 2023 at 8:15=E2=80=AFPM Ulf Hansson = wrote: > > On Fri, 15 Sept 2023 at 11:44, Victor Shih wrot= e: > > > > From: Victor Shih > > > > This is a sdhci version of mmc's request operation. > > It covers both UHS-I and UHS-II. > > Okay, but again, please elaborate on why we need/want this. > Hi, Ulf I will try to update this in version 13. Thanks, Victor Shih > > > > Signed-off-by: Ben Chuang > > Signed-off-by: AKASHI Takahiro > > Signed-off-by: Victor Shih > > --- > > > > Updates in V11: > > - Drop the check mmc_card_uhs2_hd_mode(host->mmc) > > in sdhci_uhs2_set_transfer_mode(). > > > > Updates in V10: > > - Use tmode_half_duplex to instead of uhs2_tmode0_flag > > in sdhci_uhs2_set_transfer_mode(). > > > > Updates in V9: > > - Modify the annotations in __sdhci_uhs2_send_command(). > > > > Updates in V8: > > - Adjust the position of matching brackets in > > sdhci_uhs2_send_command_retry(). > > - Modify CameCase definition in __sdhci_uhs2_finish_command(). > > - Modify error message in __sdhci_uhs2_finish_command(). > > - sdhci_uhs2_send_command_retry() to instead of sdhci_uhs2_send_comman= d() > > in sdhci_uhs2_request(). > > - Use sdhci_uhs2_mode() to simplify code in sdhci_uhs2_request_atomic(= ). > > - Add forward declaration for sdhci_send_command(). > > > > Updates in V7: > > - Cancel export state of some functions. > > - Remove unnecessary whitespace changes. > > > > Updates in V6: > > - Add uhs2_dev_cmd() to simplify code. > > - Remove unnecessary functions. > > - Cancel export state of some functions. > > - Drop use CONFIG_MMC_DEBUG(). > > - Wrap at 100 columns in some functions. > > > > --- > > > > drivers/mmc/host/sdhci-uhs2.c | 412 ++++++++++++++++++++++++++++++++++ > > drivers/mmc/host/sdhci.c | 49 ++-- > > drivers/mmc/host/sdhci.h | 8 + > > 3 files changed, 454 insertions(+), 15 deletions(-) > > > > diff --git a/drivers/mmc/host/sdhci-uhs2.c b/drivers/mmc/host/sdhci-uhs= 2.c > > index 09b86fec9f7b..1f8d527424fd 100644 > > --- a/drivers/mmc/host/sdhci-uhs2.c > > +++ b/drivers/mmc/host/sdhci-uhs2.c > > [...] > > > + > > +static void __sdhci_uhs2_send_command(struct sdhci_host *host, struct = mmc_command *cmd) > > +{ > > + int i, j; > > + int cmd_reg; > > + > > + i =3D 0; > > + sdhci_writel(host, > > + ((u32)cmd->uhs2_cmd->arg << 16) | > > + (u32)cmd->uhs2_cmd->header, > > + SDHCI_UHS2_CMD_PACKET + i); > > + i +=3D 4; > > + > > + /* > > + * Per spec, payload (config) should be MSB before sending out. > > + * But we don't need convert here because had set payload as > > + * MSB when preparing config read/write commands. > > + */ > > + for (j =3D 0; j < cmd->uhs2_cmd->payload_len / sizeof(u32); j++= ) { > > + sdhci_writel(host, *(cmd->uhs2_cmd->payload + j), SDHCI= _UHS2_CMD_PACKET + i); > > + i +=3D 4; > > + } > > + > > + for ( ; i < SDHCI_UHS2_CMD_PACK_MAX_LEN; i +=3D 4) > > + sdhci_writel(host, 0, SDHCI_UHS2_CMD_PACKET + i); > > + > > + DBG("UHS2 CMD packet_len =3D %d.\n", cmd->uhs2_cmd->packet_len)= ; > > + for (i =3D 0; i < cmd->uhs2_cmd->packet_len; i++) > > + DBG("UHS2 CMD_PACKET[%d] =3D 0x%x.\n", i, > > + sdhci_readb(host, SDHCI_UHS2_CMD_PACKET + i)); > > We are ignoring what we just read. Isn't there something we need to verif= y? > > Moreover, the whole thing with i,j and the +4 thing above looks a bit > odd to me. I am not sure whether the above can be simplified, but I > leave that for you to have a second look at. > Hi, Ulf Sorry, I don't have any ideas on this, could you please give me some ideas? Thanks, Victor Shih > > + > > + cmd_reg =3D FIELD_PREP(SDHCI_UHS2_CMD_PACK_LEN_MASK, cmd->uhs2_= cmd->packet_len); > > + if ((cmd->flags & MMC_CMD_MASK) =3D=3D MMC_CMD_ADTC) > > + cmd_reg |=3D SDHCI_UHS2_CMD_DATA; > > + if (cmd->opcode =3D=3D MMC_STOP_TRANSMISSION) > > + cmd_reg |=3D SDHCI_UHS2_CMD_CMD12; > > + > > + /* UHS2 Native ABORT */ > > + if ((cmd->uhs2_cmd->header & UHS2_NATIVE_PACKET) && > > + (uhs2_dev_cmd(cmd) =3D=3D UHS2_DEV_CMD_TRANS_ABORT)) > > + cmd_reg |=3D SDHCI_UHS2_CMD_TRNS_ABORT; > > + > > + /* UHS2 Native DORMANT */ > > + if ((cmd->uhs2_cmd->header & UHS2_NATIVE_PACKET) && > > + (uhs2_dev_cmd(cmd) =3D=3D UHS2_DEV_CMD_GO_DORMANT_STATE)) > > + cmd_reg |=3D SDHCI_UHS2_CMD_DORMANT; > > + > > + DBG("0x%x is set to UHS2 CMD register.\n", cmd_reg); > > + > > + sdhci_writew(host, cmd_reg, SDHCI_UHS2_CMD); > > +} > > [...] > > > +static bool sdhci_uhs2_send_command_retry(struct sdhci_host *host, > > + struct mmc_command *cmd, > > + unsigned long flags) > > + __releases(host->lock) > > + __acquires(host->lock) > > +{ > > + struct mmc_command *deferred_cmd =3D host->deferred_cmd; > > + int timeout =3D 10; /* Approx. 10 ms */ > > + bool present; > > Why do we need a retry mechanism at this level? The mmc core sometimes > retries commands when it seems reasonable, why isn't that sufficient? > Hi, Ulf According to my testing experience, this function is sometimes called to resend the command. Thanks, Victor Shih > > + > > + while (!sdhci_uhs2_send_command(host, cmd)) { > > + if (!timeout--) { > > + pr_err("%s: Controller never released inhibit b= it(s).\n", > > + mmc_hostname(host->mmc)); > > + sdhci_dumpregs(host); > > + cmd->error =3D -EIO; > > + return false; > > + } > > + > > + spin_unlock_irqrestore(&host->lock, flags); > > + > > + usleep_range(1000, 1250); > > + > > + present =3D host->mmc->ops->get_cd(host->mmc); > > + > > + spin_lock_irqsave(&host->lock, flags); > > + > > + /* A deferred command might disappear, handle that */ > > + if (cmd =3D=3D deferred_cmd && cmd !=3D host->deferred_= cmd) > > + return true; > > + > > + if (sdhci_present_error(host, cmd, present)) > > + return false; > > + } > > If the retry is needed, would it be possible to convert into using > read_poll_timeout() for the above while loop instead? If so, please > make that conversion. > Hi, Ulf I have no idea how to use read_poll_timeout() instead of while loop, because there are still other functions running inside the while loop. Can you give me some ideas? Thanks, Victor Shih > > + > > + if (cmd =3D=3D host->deferred_cmd) > > + host->deferred_cmd =3D NULL; > > + > > + return true; > > +} > > + > > +static void __sdhci_uhs2_finish_command(struct sdhci_host *host) > > +{ > > + struct mmc_command *cmd =3D host->cmd; > > + u8 resp; > > + u8 ecode; > > + bool breada0 =3D 0; > > Nitpick: Maybe find some better variable names. Like error_code... > Hi, Ulf I will update this in version 13. Thanks, Victor Shih > > + int i; > > + > > + if (host->mmc->flags & MMC_UHS2_SD_TRAN) { > > + resp =3D sdhci_readb(host, SDHCI_UHS2_RESPONSE + 2); > > + if (resp & UHS2_RES_NACK_MASK) { > > + ecode =3D (resp >> UHS2_RES_ECODE_POS) & UHS2_R= ES_ECODE_MASK; > > + pr_err("%s: NACK response, ECODE=3D0x%x.\n", mm= c_hostname(host->mmc), ecode); > > + } > > + breada0 =3D 1; > > + } > > + > > + if (cmd->uhs2_resp && > > + cmd->uhs2_resp_len && cmd->uhs2_resp_len <=3D 20) { > > + /* Get whole response of some native CCMD, like > > + * DEVICE_INIT, ENUMERATE. > > + */ > > + for (i =3D 0; i < cmd->uhs2_resp_len; i++) > > + cmd->uhs2_resp[i] =3D sdhci_readb(host, SDHCI_U= HS2_RESPONSE + i); > > + } else { > > + /* Get SD CMD response and Payload for some read > > + * CCMD, like INQUIRY_CFG. > > + */ > > + /* Per spec (p136), payload field is divided into > > + * a unit of DWORD and transmission order within > > + * a DWORD is big endian. > > + */ > > + if (!breada0) > > + sdhci_readl(host, SDHCI_UHS2_RESPONSE); > > + for (i =3D 4; i < 20; i +=3D 4) { > > Again we do sdhci_readl above but just ignore the data. I assume > that's deliberate, as we are probably just interested in the remaining > pieces. > > Moreover, the whole thing with +4 things continues to look a bit odd > to me. I am not sure whether it can be simplified, but I leave that > for you to have a second look at. > Hi, Ulf Sorry, I don't have any ideas on this, could you please give me some ideas? Thanks, Victor Shih > > + cmd->resp[i / 4 - 1] =3D > > + (sdhci_readb(host, > > + SDHCI_UHS2_RESPONSE + i) <= < 24) | > > + (sdhci_readb(host, > > + SDHCI_UHS2_RESPONSE + i + = 1) > > + << 16) | > > + (sdhci_readb(host, > > + SDHCI_UHS2_RESPONSE + i + = 2) > > + << 8) | > > + sdhci_readb(host, SDHCI_UHS2_RESPONSE += i + 3); > > + } > > + } > > +} > > [...] > > > + > > +void sdhci_uhs2_request(struct mmc_host *mmc, struct mmc_request *mrq) > > static void > Hi, Ulf I will try to update this in version 13. Thanks, Victor Shih > > +{ > > + struct sdhci_host *host =3D mmc_priv(mmc); > > + struct mmc_command *cmd; > > + unsigned long flags; > > + bool present; > > + > > + if (!(sdhci_uhs2_mode(host))) { > > + sdhci_request(mmc, mrq); > > + return; > > + } > > + > > + mrq->stop =3D NULL; > > + mrq->sbc =3D NULL; > > + if (mrq->data) > > + mrq->data->stop =3D NULL; > > + > > + /* Firstly check card presence */ > > + present =3D mmc->ops->get_cd(mmc); > > + > > + spin_lock_irqsave(&host->lock, flags); > > + > > + if (sdhci_present_error(host, mrq->cmd, present)) > > + goto out_finish; > > + > > + cmd =3D mrq->cmd; > > + > > + if (!sdhci_uhs2_send_command_retry(host, cmd, flags)) > > + goto out_finish; > > + > > + spin_unlock_irqrestore(&host->lock, flags); > > + > > + return; > > + > > +out_finish: > > + sdhci_finish_mrq(host, mrq); > > + spin_unlock_irqrestore(&host->lock, flags); > > +} > > +EXPORT_SYMBOL_GPL(sdhci_uhs2_request); > > Drop this, it's not used outside this module. > Hi, Ulf I will try to update this in version 13. Thanks, Victor Shih > > + > > +int sdhci_uhs2_request_atomic(struct mmc_host *mmc, struct mmc_request= *mrq) > > This function is entirely unused. Did you actually test this with an > hsq enabled host? Or perhaps you have just added this for > completeness? > Hi, Ulf I will drop this in version 13. Thanks, Victor Shih > > +{ > > + struct sdhci_host *host =3D mmc_priv(mmc); > > + struct mmc_command *cmd; > > + unsigned long flags; > > + int ret =3D 0; > > + > > + if (!sdhci_uhs2_mode(host)) > > + return sdhci_request_atomic(mmc, mrq); > > + > > + spin_lock_irqsave(&host->lock, flags); > > + > > + if (sdhci_present_error(host, mrq->cmd, true)) { > > + sdhci_finish_mrq(host, mrq); > > + goto out_finish; > > + } > > + > > + cmd =3D mrq->cmd; > > + > > + /* > > + * The HSQ may send a command in interrupt context without poll= ing > > + * the busy signaling, which means we should return BUSY if con= troller > > + * has not released inhibit bits to allow HSQ trying to send re= quest > > + * again in non-atomic context. So we should not finish this re= quest > > + * here. > > + */ > > + if (!sdhci_uhs2_send_command(host, cmd)) > > + ret =3D -EBUSY; > > + > > +out_finish: > > + spin_unlock_irqrestore(&host->lock, flags); > > + return ret; > > +} > > +EXPORT_SYMBOL_GPL(sdhci_uhs2_request_atomic); > > + > > [...] > > Kind regards > Uffe