From patchwork Sun Jun 11 19:41:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13275357 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8DBB4C83005 for ; Sun, 11 Jun 2023 19:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232267AbjFKTlt (ORCPT ); Sun, 11 Jun 2023 15:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232757AbjFKTlr (ORCPT ); Sun, 11 Jun 2023 15:41:47 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 27EEC126 for ; Sun, 11 Jun 2023 12:41:43 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4f6195d2b3fso4240428e87.1 for ; Sun, 11 Jun 2023 12:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686512501; x=1689104501; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=ZK0mkbjHAu8JAeEkTRBOfo0afA15/I72HAPEj6zPizo=; b=lf3qjqz6c7HOa/hWJYdEzlwmZ9nRwDuCifWRyX10OijK5MuueM4fuIU2gL+JiQcCKY KT1uCtul0Wsdx9fi1ULMuQsfdwxIdme8/sclPwDmqthuCTt3rhWAnAdKEOjX/8UT4mEl m6BfyjV/x+1H5Ewfq+jitm2R24ATsNk/mtyAjMGq4RWOeMUHF4Qv2Y5LU0WN58tm2o7U Y1oJhrrRqf2I80ltpUPspXQAgVFe0ijwB0Z5v9A0/Hig03KS+3KNppMoxwRjePzNFFPH LN6n+ATRHFbffJqN4whYJWFWnCz2yVzcboROJ7gc25MoINn7IO4Eq7hcd50F/Bk1w0wo BkZg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686512501; x=1689104501; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZK0mkbjHAu8JAeEkTRBOfo0afA15/I72HAPEj6zPizo=; b=JLjcAS9R1E4FRdJbEKPtWm3M6syAK16vk5sTXvwlab7l6xDsn0eJZFFfZq32+26WdX DlZFobZh4QBTR75fGRTcOWJVgX1chwUth9DjTKbmorKj/6WVUD8VclSpX9waj5LXBCwO 5P7ky9JZL3R9DLLYx2uJTVWLlQvNcugGm4YZjplaGo9U/CvPBuZ05cirEOlsr7RG6MSN gSmrX8JOS7n4dxDKeCXl60rD9p1FxrfPRxBt+rN3P12M92eCK/M2QuLAGvt0pRghkhjU ZO2NfGuPKnvYIxD2XWQRU7CSs+iHfpDxlWoPK88t7xFkN+/f6QhO8siunaBinZt/Wwh8 /QQQ== X-Gm-Message-State: AC+VfDx3+RkypW/r899KTHxaClQ6+olPIVcJwV6Ag0xd4klT2ZqoioFf zkkloU88AW3J+lQoHg8M14dkog== X-Google-Smtp-Source: ACHHUZ7jKBMBuYlNtBKwlZYc72v7+1ashCmnM6/royQj08B4wm4S141TRISJSSuxEpWDx39jDiuYSA== X-Received: by 2002:a05:6512:614:b0:4f4:aea9:2a2f with SMTP id b20-20020a056512061400b004f4aea92a2fmr3634906lfe.57.1686512501410; Sun, 11 Jun 2023 12:41:41 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1246960lfl.28.2023.06.11.12.41.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 12:41:41 -0700 (PDT) From: Linus Walleij Date: Sun, 11 Jun 2023 21:41:27 +0200 Subject: [PATCH v3 01/10] mmc: mmci: Clear busy_status when starting command MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v3-1-cd3d5925ae64@linaro.org> References: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org If we are starting a command which can generate a busy response, then clear the variable host->busy_status if the variant is using a ->busy_complete callback. We are lucky that the member is zero by default and hopefully always gets cleared in the ->busy_complete callback even on errors, but it's just fragile so make sure it is always initialized to zero. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Clear host->busy_status no matter if the MMC_RSP_BUSY flag is set or not. - Now we have an if inside an if left, so combine these into one singel conditional. - Resulting re-flow the if-clause. ChangeLog v1->v2: - Unconditionally clear host->busy_status if we get a busy response. --- drivers/mmc/host/mmci.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index f2b2e8b0574e..14d639872952 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1238,7 +1238,8 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) c |= host->variant->cmdreg_srsp; } - if (host->variant->busy_timeout && cmd->flags & MMC_RSP_BUSY) { + host->busy_status = 0; + if ((cmd->flags & MMC_RSP_BUSY) && (host->variant->busy_timeout)) { if (!cmd->busy_timeout) cmd->busy_timeout = 10 * MSEC_PER_SEC; From patchwork Sun Jun 11 19:41:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13275356 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9D438C7EE23 for ; Sun, 11 Jun 2023 19:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229750AbjFKTls (ORCPT ); Sun, 11 Jun 2023 15:41:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232058AbjFKTlq (ORCPT ); Sun, 11 Jun 2023 15:41:46 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5B6D3E42 for ; Sun, 11 Jun 2023 12:41:44 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4f63a2e1c5fso4217799e87.2 for ; Sun, 11 Jun 2023 12:41:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686512502; x=1689104502; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=97fyKcVEFuh2Yeg9Iaqs54dTpBgorwtoQwgxut62TCg=; b=yA0SGohAqbPT7T7z8/1vC7qEJb2uBbpUCq00HUlyQl6KSBH0cIZsKbggzUaaJbbX8w 6xMiluvmqvyH3+2mi8cUQ+qY/dwp1NSL1LWZ+14JP2bxQOG/mTkpFZb7+R9ikSrXADyL +n5/kxPUUjXHLOIQWVoM/GFoVnGCu5kTQ/fGQjAbb+K84mDr1TmWYcFeAXgVh/Ctp0G8 k4ox7k2GhzU1TrZi704Bh07grXgTOg9jFKpt4iwVa7Lz0tE/HOmUTy5D+yYELdH/+dT9 3+AkwAcnmlD1/Ip+LbADMTInfuN7Z7Dw/FFyurY8yPB8Ndw77h0Jpc/3jVlDYVObzxLZ zgGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686512502; x=1689104502; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=97fyKcVEFuh2Yeg9Iaqs54dTpBgorwtoQwgxut62TCg=; b=UpR4iz0QPN9BVkJWFghoejuROjy6FzehX8d1jtZXJHmMfxQxnnsSgBQeKNpB5s1TGj GN3CtoUrDQiCkB81dPr4CM64Zp6ni0vLCiyy+h5EHeIAhsACHMJcm5QSgCX2g23Hh9JP +SX++fPt78VA3tlY78Gf4c/8lPPH6Gp1166BPOXWExmHqVD+bsrim6v+bZcpPaN0pRth zDLirnaGEBmcqRCCSEPk3XivbWfDaUqCwm6KYv9VKrIyFiQoJZL5+9+ZQkaa0Mx4oyYQ 3E0GLs0xAyIWdAppd3jIoGKKBCAMNlpxDeNI2OqKzxwzzMDsK5n2Cje7WLaw7k3HXGJy 8bzQ== X-Gm-Message-State: AC+VfDwHYONGqRxgbQw+GwHA/EJh8e8ppFgQuaNTW+B4bCdkwMfT9yq3 bC2mgBPJfYcFyvtnDjf9ppG/IA== X-Google-Smtp-Source: ACHHUZ4FPt8+JEfGlHmbu5/k2niTR5QSnYLJBX0CszSWlXLxjQ6sdECjmra5ebSwlCr6RPqBbhbpZQ== X-Received: by 2002:ac2:498f:0:b0:4f4:b378:469d with SMTP id f15-20020ac2498f000000b004f4b378469dmr3280704lfl.41.1686512502572; Sun, 11 Jun 2023 12:41:42 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1246960lfl.28.2023.06.11.12.41.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 12:41:41 -0700 (PDT) From: Linus Walleij Date: Sun, 11 Jun 2023 21:41:28 +0200 Subject: [PATCH v3 02/10] mmc: mmci: Unwind big if() clause MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v3-2-cd3d5925ae64@linaro.org> References: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org This does two things: firsr replace the hard-to-read long if-expression: if (!host->busy_status && !(status & err_msk) && (readl(base + MMCISTATUS) & host->variant->busy_detect_flag)) { With the more readable: if (!host->busy_status && !(status & err_msk)) { status = readl(base + MMCISTATUS); if (status & host->variant->busy_detect_flag) { Second notice that the re-read MMCISTATUS register is now stored into the status variable, using logic OR because what if something else changed too? While we are at it, explain what the function is doing. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - Only assign the cached status in host->busy_status if we have busy detect signalling going on. --- drivers/mmc/host/mmci.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 14d639872952..d8e7b17adaee 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -654,6 +654,13 @@ static u32 ux500v2_get_dctrl_cfg(struct mmci_host *host) return MCI_DPSM_ENABLE | (host->data->blksz << 16); } +/* + * ux500_busy_complete() - this will wait until the busy status + * goes off, saving any status that occur in the meantime into + * host->busy_status until we know the card is not busy any more. + * The function returns true when the busy detection is ended + * and we should continue processing the command. + */ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) { void __iomem *base = host->base; @@ -671,14 +678,16 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * while, to allow it to be set, but tests indicates that it * isn't needed. */ - if (!host->busy_status && !(status & err_msk) && - (readl(base + MMCISTATUS) & host->variant->busy_detect_flag)) { - writel(readl(base + MMCIMASK0) | - host->variant->busy_detect_mask, - base + MMCIMASK0); + if (!host->busy_status && !(status & err_msk)) { + status = readl(base + MMCISTATUS); + if (status & host->variant->busy_detect_flag) { + writel(readl(base + MMCIMASK0) | + host->variant->busy_detect_mask, + base + MMCIMASK0); - host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); - return false; + host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); + return false; + } } /* From patchwork Sun Jun 11 19:41:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13275358 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EEDA5C7EE2F for ; Sun, 11 Jun 2023 19:41:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232016AbjFKTlt (ORCPT ); Sun, 11 Jun 2023 15:41:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232267AbjFKTlq (ORCPT ); Sun, 11 Jun 2023 15:41:46 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BEC7E50 for ; Sun, 11 Jun 2023 12:41:45 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f61b45ee0dso4160109e87.0 for ; Sun, 11 Jun 2023 12:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686512503; x=1689104503; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=leQo1eQI2yGMA+F1whh7Mzh5/OHjjWPGlqQlPIARggM=; b=JzHmoRxskRPBqRU0oxKMdWiC2ux9EoTDP5BA2bYiUG0GeVVIU7Utrz8oOaEDumSQmr LjKCrXIwwSQPFIBDkQ4m2wQqemqC7fXKtgX0A+Ih5Y+XxUIQiP7d8Nuqynn1IIuF4vl0 YQHJE9ZVparD2CXEpB9wSwFNr0EJAXGwW0TSXfR8orn6EoyHDGuGuirHQw6CL6Y5L7bI bCXFtjmnC+3No/SzLyPTE5SPBcNZxVzDIqafdKyAlytg6tOyEeYEMnziCHXB216sBU75 UPXazQ0LQrzBTY7woP24hkPo3y7DMryNqRofh31mSHFmKLBze+7IeMIaJq3g6YzaYPfd GjiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686512503; x=1689104503; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=leQo1eQI2yGMA+F1whh7Mzh5/OHjjWPGlqQlPIARggM=; b=jaPZbCCUFT1c+9qDpyCVLOVyxErNpsRvc2J+TgrLhbu9qjCBkXwWQTEwkiXFCPD2mx aNx8N5pEbTdMYtn+7wgblnZ81ziU93EovCRvuoIjbFc4+2mhHtignIM7570WaE9JkZBj pLsfezLszPksZIh67chvqFbQi363KgqeDNfLMz/7ZxuSzkpoQLe34hTsKEbCtesFJYRz egjUSJXPxXbEP+UdLLsrDj8vezjMxJBEUY/hlPGa4uBdWEnDS07qGPz/Dqr5Vy9qY+xj MnoVFG9aY/bi4o3dJLB72h7v8+0LGnqDc1Hon0/BOdpzOuHJXL0XHlHoTtNARx7TqwlZ 47nA== X-Gm-Message-State: AC+VfDwmKUDfrNBOLahLCNJCNVR5DFAr6h/iFUQNJJzIOqPx7gecbuf7 XTvA4oWB3RlifRlpxgdDvRtvqw== X-Google-Smtp-Source: ACHHUZ6ULkkOOmgR+U1/7iaSinRzCgPnItOqoS3hN/U8Qa60/d6WPvkdwtgBFv4NuUS9F58fDYBJZQ== X-Received: by 2002:a19:711c:0:b0:4f1:2986:3920 with SMTP id m28-20020a19711c000000b004f129863920mr2977578lfc.41.1686512503739; Sun, 11 Jun 2023 12:41:43 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1246960lfl.28.2023.06.11.12.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 12:41:43 -0700 (PDT) From: Linus Walleij Date: Sun, 11 Jun 2023 21:41:29 +0200 Subject: [PATCH v3 03/10] mmc: mmci: Stash status while waiting for busy MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v3-3-cd3d5925ae64@linaro.org> References: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Some interesting flags can arrive while we are waiting for the first busy detect IRQ so OR then onto the stashed flags so they are not missed. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index d8e7b17adaee..73b5205592ae 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -703,6 +703,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) */ if (host->busy_status && (status & host->variant->busy_detect_flag)) { + host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); return false; } From patchwork Sun Jun 11 19:41:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13275359 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25281C7EE45 for ; Sun, 11 Jun 2023 19:41:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232314AbjFKTlu (ORCPT ); Sun, 11 Jun 2023 15:41:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233466AbjFKTlr (ORCPT ); Sun, 11 Jun 2023 15:41:47 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5141FD2 for ; Sun, 11 Jun 2023 12:41:46 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4f61d79b0f2so4310113e87.3 for ; Sun, 11 Jun 2023 12:41:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686512504; x=1689104504; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=I6Ue4bYrXyR9j80ovW9fc7Vt7MxWUEhRPqPmpf2o0qo=; b=zd20DlhR2hxHUuFfATGWD/CU45g0SHtMXtYWmhJmj4p+WAOkPdH13eS5m8WSILbe+R FK/JP5aLMN66icLCgm4LYJsMbuM6gxEOYKOhEg74swgtQ7Ihmt34njRw9ZB3C74Fdec/ NCo+uI5OLk3xPeG+Wz5ULGjKLQQ3l9f8rL2Sw4LNo7v9UK9XudLnVisOIQFY1ezZ2xA0 t/ijZtDJXvKiGBrNIrNjSFgcmO8YkoWVOSXnOckw/+qDZfdCgGqLRHkZFhoUzX0rWItw w2sJgQhZFTcQXIreLySn5GnhwxZk9kVuyptUWokNJH4uu6P5k2cP0WOQ2mVtKlgndqsu ew9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686512504; x=1689104504; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=I6Ue4bYrXyR9j80ovW9fc7Vt7MxWUEhRPqPmpf2o0qo=; b=WgFSlD8/iCnXk/dPbXpycAti0DHLDzbOLCxPZ13/ruF5akMCaE6ZRsOJPUpaU9BRkF VTFni3z9VZ1o2ZWrgH+2VsXxWUsiOo5f45U+kjOuGESqghgxdpaULu0o5BlrTeez8ZM8 uvfb/A1u5lMZRf338bYpPdmVp7yLkQ2YuKK5uzYx3CwdSfaID/PPtrseJb93fMvAmWAr kWAcm6Wr9mRQTJLrN3Oj6ZppfjOBSCs1EjJ+S74fULbDyfbXyrcJYwvJKHRDD3YkZvVJ Enk18/gUxVtvPc3ZLq+H4WQccOWAN7/IlmvIomx7VyskVvdAkHLR5k/7FeFOVK5tE0H/ AR+A== X-Gm-Message-State: AC+VfDxXPo56Ow+5QjEAv5Hz4hNudW+Jan4aHbivcWoueoXStJAQIs/e ENiZEoHNAUEQbpSA5L05p9lm2g== X-Google-Smtp-Source: ACHHUZ4rtxZmAAiTtmPxVVXhq3W7BSegGOw3ef9o1EK9vWgXdelDsLn/HHhHvMActgf6HZguAlCmfQ== X-Received: by 2002:a05:6512:286:b0:4f6:3ab6:3d9e with SMTP id j6-20020a056512028600b004f63ab63d9emr3127554lfp.59.1686512504688; Sun, 11 Jun 2023 12:41:44 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1246960lfl.28.2023.06.11.12.41.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 12:41:44 -0700 (PDT) From: Linus Walleij Date: Sun, 11 Jun 2023 21:41:30 +0200 Subject: [PATCH v3 04/10] mmc: mmci: Break out error check in busy detect MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v3-4-cd3d5925ae64@linaro.org> References: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The busy detect callback for Ux500 checks for an error in the status in the first if() clause. The only practical reason is that if an error occurs, the if()-clause is not executed, and the code falls through to the last if()-clause if (host->busy_status) which will clear and disable the irq. Make this explicit instead: it is easier to read. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 73b5205592ae..fbc13923f4fe 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -665,6 +665,15 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) { void __iomem *base = host->base; + if (status & err_msk) { + /* Stop any ongoing busy detection if an error occurs */ + writel(host->variant->busy_detect_mask, base + MMCICLEAR); + writel(readl(base + MMCIMASK0) & + ~host->variant->busy_detect_mask, base + MMCIMASK0); + host->busy_status = 0; + return true; + } + /* * Before unmasking for the busy end IRQ, confirm that the * command was sent successfully. To keep track of having a @@ -678,7 +687,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * while, to allow it to be set, but tests indicates that it * isn't needed. */ - if (!host->busy_status && !(status & err_msk)) { + if (!host->busy_status) { status = readl(base + MMCISTATUS); if (status & host->variant->busy_detect_flag) { writel(readl(base + MMCIMASK0) | From patchwork Sun Jun 11 19:41:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13275361 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F7F2C87FDC for ; Sun, 11 Jun 2023 19:41:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232757AbjFKTlu (ORCPT ); Sun, 11 Jun 2023 15:41:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44124 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232058AbjFKTlt (ORCPT ); Sun, 11 Jun 2023 15:41:49 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A9EDE51 for ; Sun, 11 Jun 2023 12:41:47 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-4f64fb05a8aso4234132e87.0 for ; Sun, 11 Jun 2023 12:41:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686512505; x=1689104505; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=cnoJbS9/Ay6FH59vYZflel3IJO/fgTDRMIeCev/1iAY=; b=mZLBvIw4hd4Az9ncr1RPQ7plZHc4samFRNtZA/X/ZF9PjeqwKA+lzIdgOSFeaFdSfs rOp2q/2p0VPnM6zivWX/CFt2yPbGv9nIr2LXh/MTalCngWTFCDNu7DfKmHMtZq7fBPt0 oiWuQ3WLzLtsdi3tGvq7+DMrhSquGsVbUNDAzC7OdCVWzUA2X5vovczgQku15dhIXszn uhdOEhWtDR0NRoF1qVhU1jiAvRlpohq8Zu1BQWyOot88CKfh1Ew7/WUb8xHIQ48OT0fm D874cLJUa12Uv4APiXzmJORdi5LlocuXQB5TjJ5KwKzOWLnjxsY/H//r9nq4ucq1Xj8m 9tJw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686512505; x=1689104505; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cnoJbS9/Ay6FH59vYZflel3IJO/fgTDRMIeCev/1iAY=; b=SKKGeHj7/UbbAfk/clBw1as6rfFVoKtBZvk9UDuDv0oR2kBqT7+1RqYXcRz6TeyWVJ Cg326urCSQqxylwWy1vqfqgRko5tXXRBAVTv/Qo3p0GigkCfEJZPnBAyyGwRanrJNEvd 5T+/2+nCOFzSv2a1eJBBjFQSGoBH98ZnMm/FN7Avmy+VZi3QUastdIH2cFGLZYhUgJQM nxJI99zql6a8qK93z7V/ztNPjaxtXiN8hjmgt6khq9t07qOyu8N791dhbm/iPnd0Zg6U OcKoas+LwPVkkN3O1NcSZFB9OVfBhm/tFAQisxCklsk464Vbx+3zSNXTUdqkKfHjD4+j 0g/g== X-Gm-Message-State: AC+VfDzZwt7DS3gibbz42NC0w4ialr5S//wTKwA9h3Tui0pbzmmX4YuR MGFtrKlSFrLX7TdcVGS1z/8KMg== X-Google-Smtp-Source: ACHHUZ5hYwBw8cIGDbN4Ma0k4bYHBtE95hYPa3a9ldyxqKx2nnq1c9L+fCfHXxY1VqYMfmc9PMWVMQ== X-Received: by 2002:ac2:465b:0:b0:4f6:1805:6080 with SMTP id s27-20020ac2465b000000b004f618056080mr3751407lfo.4.1686512505612; Sun, 11 Jun 2023 12:41:45 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1246960lfl.28.2023.06.11.12.41.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 12:41:45 -0700 (PDT) From: Linus Walleij Date: Sun, 11 Jun 2023 21:41:31 +0200 Subject: [PATCH v3 05/10] mmc: mmci: Make busy complete state machine explicit MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v3-5-cd3d5925ae64@linaro.org> References: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org This refactors the ->busy_complete() callback currently only used by Ux500 and STM32 to handle busy detection on hardware where one and the same IRQ is fired whether we get a start or an end signal on busy detect. The code is currently using the cached status from the command IRQ in ->busy_status as a state to select what to do next: if this state is non-zero we are waiting for IRQs and if it is zero we treat the state as the starting point for a busy detect wait cycle. Make this explicit by creating a state machine where the ->busy_complete callback moves between three states. The Ux500 busy detect code currently assumes this order: we enable the busy detect IRQ, get a busy start IRQ, then a busy end IRQ, and then we clear and mask this IRQ and proceed. We insert debug prints for unexpected states. Augment the STM32 driver with similar states for completeness. This works as before on most cards, however on a problematic card that is not working with busy detect, and which I have been debugging, this happens: [127220.662719] mmci-pl18x 80005000.mmc: lost busy status when waiting for busy end IRQ This probably means that the busy detect start IRQ has already occurred when we start executing the ->busy_complete() callbacks, and the busy detect end IRQ is counted as the start IRQ, and this is what is causing the card to not be detected properly. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Drop surplus states and merge IDLE and DONE states into one, we start out DONE. Name states *_WAITING_FOR_* so it is clear what is going on. - Rebase on other changes. - Reword commit message. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 55 +++++++++++++++++++++++++------------ drivers/mmc/host/mmci.h | 14 ++++++++++ drivers/mmc/host/mmci_stm32_sdmmc.c | 6 +++- 3 files changed, 56 insertions(+), 19 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index fbc13923f4fe..edc68fc7b642 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -670,6 +670,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) writel(host->variant->busy_detect_mask, base + MMCICLEAR); writel(readl(base + MMCIMASK0) & ~host->variant->busy_detect_mask, base + MMCIMASK0); + host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; return true; } @@ -687,7 +688,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * while, to allow it to be set, but tests indicates that it * isn't needed. */ - if (!host->busy_status) { + if (host->busy_state == MMCI_BUSY_DONE) { status = readl(base + MMCISTATUS); if (status & host->variant->busy_detect_flag) { writel(readl(base + MMCIMASK0) | @@ -695,6 +696,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) base + MMCIMASK0); host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); + host->busy_state = MMCI_BUSY_WAITING_FOR_START_IRQ; return false; } } @@ -710,25 +712,40 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * both the start and the end interrupts needs to be cleared, * one after the other. So, clear the busy start IRQ here. */ - if (host->busy_status && - (status & host->variant->busy_detect_flag)) { - host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - return false; + if (host->busy_state == MMCI_BUSY_WAITING_FOR_START_IRQ) { + if (status & host->variant->busy_detect_flag) { + host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); + writel(host->variant->busy_detect_mask, base + MMCICLEAR); + host->busy_state = MMCI_BUSY_WAITING_FOR_END_IRQ; + return false; + } else { + dev_dbg(mmc_dev(host->mmc), + "lost busy status when waiting for busy start IRQ\n"); + writel(host->variant->busy_detect_mask, base + MMCICLEAR); + writel(readl(base + MMCIMASK0) & + ~host->variant->busy_detect_mask, base + MMCIMASK0); + host->busy_state = MMCI_BUSY_DONE; + host->busy_status = 0; + return true; + } } - /* - * If there is a command in-progress that has been successfully - * sent and the busy bit isn't set, it means we have received - * the busy end IRQ. Clear and mask the IRQ, then continue to - * process the command. - */ - if (host->busy_status) { - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_status = 0; + if (host->busy_state == MMCI_BUSY_WAITING_FOR_END_IRQ) { + if (status & host->variant->busy_detect_flag) { + host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); + writel(host->variant->busy_detect_mask, base + MMCICLEAR); + host->busy_state = MMCI_BUSY_DONE; + return false; + } else { + dev_dbg(mmc_dev(host->mmc), + "lost busy status when waiting for busy end IRQ\n"); + writel(host->variant->busy_detect_mask, base + MMCICLEAR); + writel(readl(base + MMCIMASK0) & + ~host->variant->busy_detect_mask, base + MMCIMASK0); + host->busy_state = MMCI_BUSY_DONE; + host->busy_status = 0; + return true; + } } return true; @@ -1259,6 +1276,8 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) host->busy_status = 0; if ((cmd->flags & MMC_RSP_BUSY) && (host->variant->busy_timeout)) { + host->busy_state = MMCI_BUSY_DONE; + if (!cmd->busy_timeout) cmd->busy_timeout = 10 * MSEC_PER_SEC; diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h index e1a9b96a3396..12a7bbd3ce26 100644 --- a/drivers/mmc/host/mmci.h +++ b/drivers/mmc/host/mmci.h @@ -261,6 +261,19 @@ struct clk; struct dma_chan; struct mmci_host; +/** + * enum mmci_busy_state - enumerate the busy detect wait states + * + * This is used for the state machine waiting for different busy detect + * interrupts on hardware that fire a single IRQ for start and end of + * the busy detect phase on DAT0. + */ +enum mmci_busy_state { + MMCI_BUSY_WAITING_FOR_START_IRQ, + MMCI_BUSY_WAITING_FOR_END_IRQ, + MMCI_BUSY_DONE, +}; + /** * struct variant_data - MMCI variant-specific quirks * @clkreg: default value for MCICLOCK register @@ -409,6 +422,7 @@ struct mmci_host { u32 clk_reg; u32 clk_reg_add; u32 datactrl_reg; + enum mmci_busy_state busy_state; u32 busy_status; u32 mask1_reg; u8 vqmmc_enabled:1; diff --git a/drivers/mmc/host/mmci_stm32_sdmmc.c b/drivers/mmc/host/mmci_stm32_sdmmc.c index 60bca78a72b1..a805647b6664 100644 --- a/drivers/mmc/host/mmci_stm32_sdmmc.c +++ b/drivers/mmc/host/mmci_stm32_sdmmc.c @@ -393,8 +393,10 @@ static bool sdmmc_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) busy_d0 = sdmmc_status & MCI_STM32_BUSYD0; /* complete if there is an error or busy_d0end */ - if ((status & err_msk) || busy_d0end) + if ((status & err_msk) || busy_d0end) { + host->busy_state = MMCI_BUSY_DONE; goto complete; + } /* * On response the busy signaling is reflected in the BUSYD0 flag. @@ -408,6 +410,7 @@ static bool sdmmc_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); } + host->busy_state = MMCI_BUSY_WAITING_FOR_END_IRQ; return false; } @@ -416,6 +419,7 @@ static bool sdmmc_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) writel_relaxed(mask & ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_status = 0; + host->busy_state = MMCI_BUSY_DONE; } writel_relaxed(host->variant->busy_detect_mask, base + MMCICLEAR); From patchwork Sun Jun 11 19:41:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13275360 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 24637C8300C for ; Sun, 11 Jun 2023 19:41:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233466AbjFKTlv (ORCPT ); Sun, 11 Jun 2023 15:41:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233752AbjFKTlt (ORCPT ); Sun, 11 Jun 2023 15:41:49 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 234F7E42 for ; Sun, 11 Jun 2023 12:41:48 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4effb818c37so4217932e87.3 for ; Sun, 11 Jun 2023 12:41:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686512506; x=1689104506; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=14aHGZ8oHIVpggHbzlWvOkwC1BB515dSDX3YOpp4NLY=; b=tzfzQwo71K+8FmLa7PRd7RaqrdSICWkIxsQPh2IdvMqAjv9JnPh3ncT3GAqaKCTHPv GoUsSQzIppJYVy4+UJ4HP772V3BM5msioBtvbbNfdW+jmgrP2bB4qCM4Pla5bUodiubP Xtz/8zTwnT8kGvcNfCl9uA3rDl0lBODNTzvn1xJ17eGfKIbE1zC9R3c/D9TVZ8CDxB6l o0TC1DRTsCRaAtjTiW9Utv1NyCKFBP4Jr0yAGQdePcyXQBOkWxIcgD8zC6wKyj2WiFv8 3I9jTxBbtnPR7RcPRpej0ivI7HeHZinH5TWFDiT99fARcQEHaSYyoe7q+47I89JT3Alm qnzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686512506; x=1689104506; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=14aHGZ8oHIVpggHbzlWvOkwC1BB515dSDX3YOpp4NLY=; b=bj/QQ5/6CsgiAIGo2Sh4zuSKTUp6qkxPRtrmgU+5T+jiZ3/DEkVqr8ZX5vXAjyoMA8 D4BLz925TwCMm7j0/YnBRkJ7UZvs5p/Lmias3x1uZ5zLx3sih2Rkc4NeXRUZ/pILw+Ec DB4/ZPmrFTC3yzJdoUc/dLbhJL21UTGgqarr+NJInv7F+JBKgStpeWmd8igZVuN5EP98 msRZUsT8PP5nYVrBUsD9BIeiBVPYT6RBelU6+CxSTblj3W2itVxIvpxoM4C2Du24n9go tKkKRG47Fjoe42yQgapeyYRrQUG8dBKiEueXp+pT/AREsYiFBwmF7UjL2ytgiQs6smSC VLzA== X-Gm-Message-State: AC+VfDyMJRuuIvhldqdPs+J9aTlwF2FUL+2TDzH8P//2Q2raStb4/ftR xU0FTqfukTtV6cBuv9aqUx9Cdg== X-Google-Smtp-Source: ACHHUZ6crYauMFC6n3ylXmNgLHPRvnZDSbE86QHa9gdkBoRJJY+fHDqlPvd2ItZt2U0YVCVgQvrOtg== X-Received: by 2002:a19:670f:0:b0:4f4:d0ab:97d5 with SMTP id b15-20020a19670f000000b004f4d0ab97d5mr2903591lfc.14.1686512506515; Sun, 11 Jun 2023 12:41:46 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1246960lfl.28.2023.06.11.12.41.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 12:41:46 -0700 (PDT) From: Linus Walleij Date: Sun, 11 Jun 2023 21:41:32 +0200 Subject: [PATCH v3 06/10] mmc: mmci: Retry the busy start condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v3-6-cd3d5925ae64@linaro.org> References: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org This makes the ux500 ->busy_complete() callback re-read the status register 10 times while waiting for the busy signal to assert in the status register. If this does not happen, we bail out regarding the command completed already, i.e. before we managed to start to check the busy status. There is a comment in the code about this, let's just implement it to be certain that we can catch this glitch if it happens. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - Move over the initial saving of host->busy_status from an unrelated patch to this one: it is clear what we are doing: we don't want to miss any transient (MCI_CMDSENT | MCI_CMDRESPEND) in the status register. --- drivers/mmc/host/mmci.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index edc68fc7b642..2858d8d67129 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -664,6 +664,7 @@ static u32 ux500v2_get_dctrl_cfg(struct mmci_host *host) static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) { void __iomem *base = host->base; + int retries = 10; if (status & err_msk) { /* Stop any ongoing busy detection if an error occurs */ @@ -684,21 +685,36 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * Note that, the card may need a couple of clock cycles before * it starts signaling busy on DAT0, hence re-read the * MMCISTATUS register here, to allow the busy bit to be set. - * Potentially we may even need to poll the register for a - * while, to allow it to be set, but tests indicates that it - * isn't needed. */ if (host->busy_state == MMCI_BUSY_DONE) { - status = readl(base + MMCISTATUS); - if (status & host->variant->busy_detect_flag) { - writel(readl(base + MMCIMASK0) | - host->variant->busy_detect_mask, - base + MMCIMASK0); - - host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); - host->busy_state = MMCI_BUSY_WAITING_FOR_START_IRQ; - return false; + /* + * Save the first status register read to be sure to catch + * all bits that may be lost will retrying. If the command + * is still busy this will result in assigning 0 to + * host->busy_status, which is what it should be in IDLE. + */ + host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); + while (retries) { + status = readl(base + MMCISTATUS); + if (status & host->variant->busy_detect_flag) { + writel(readl(base + MMCIMASK0) | + host->variant->busy_detect_mask, + base + MMCIMASK0); + + /* Keep accumulating status bits */ + host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); + host->busy_state = MMCI_BUSY_WAITING_FOR_START_IRQ; + return false; + } + retries--; } + dev_dbg(mmc_dev(host->mmc), "no busy signalling in time\n"); + writel(host->variant->busy_detect_mask, base + MMCICLEAR); + writel(readl(base + MMCIMASK0) & + ~host->variant->busy_detect_mask, base + MMCIMASK0); + host->busy_state = MMCI_BUSY_DONE; + host->busy_status = 0; + return true; } /* From patchwork Sun Jun 11 19:41:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13275363 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D2B7FC7EE23 for ; Sun, 11 Jun 2023 19:41:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233752AbjFKTlw (ORCPT ); Sun, 11 Jun 2023 15:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44136 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232630AbjFKTlu (ORCPT ); Sun, 11 Jun 2023 15:41:50 -0400 Received: from mail-lf1-x130.google.com (mail-lf1-x130.google.com [IPv6:2a00:1450:4864:20::130]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18C42D2 for ; Sun, 11 Jun 2023 12:41:49 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f61b45ee0dso4160146e87.0 for ; Sun, 11 Jun 2023 12:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686512507; x=1689104507; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=jb6D+kyxjkuniw+/i6BXNpuEvbzBFiePmlC8MrIMF84=; b=ueBKRNSj+qiOglYdOAP1NmAJnT4q2z4Ep1yygyyM5QRiFarezlroh/ou7p6rm8MZ6w nP+wis0Ox4JspfWfonVcByZdJxGFMy8eyMwGFaPQTNtU90BtTBTrd8K5CuYXOgA/rvft a9oM8OL74JRbkYe1+XgVikMGJvHkDZ3M2qRLoEdVI24EKbCV4QuWw+NROf1BS9okGPOJ 2CjaEdeqLQXRWb8cwVoWyBJus/pRwQ49EQ3uuzE5Hwcbl+W3c8Qj1SBWqkPBi2U59fMo /za7FKKny9gkld3v4fbNigf08RtD5n/mdc4Kt7Z/xVrsYlLbS60QY7/vrDeLStL+05gH lG6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686512507; x=1689104507; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jb6D+kyxjkuniw+/i6BXNpuEvbzBFiePmlC8MrIMF84=; b=a3AHSChPhZeh8SjjbDW0zK0eWpb3KuawfLPyx1P45f5bIUz76qIyhowDf0tbHsdudj bTQdbVHcd9hVKTFitcoz248p+7JP60gBtTe1KSW4kti6CffIEg/BXFKfFt9HHxdoAT2r nQkiyfLQv8QNOMtjm4rtvPD3SS9kwlhvQSiI3JB/IZ5Kd5S02kGuOU13CLqn+WFFC9Gj Ytw8qawjsZ54QkehMFxFdT/p9Pk16S9BhTKE578q2tpXkhtIVsynHozGl8LqfLzstEon cCzFhuJuu1uecVutLmgtyu8KR0myyWJOWG9+6vrAmUV5PWrfXb954LJgGwGU6VAaNYdH CpSw== X-Gm-Message-State: AC+VfDy8ym8IBIiyZ/FL4kKnzNYvKcS0bBViObbxxkmExpJ4ngKNyR0w 9C2RazTv6qyVYswogBqWcca+lg== X-Google-Smtp-Source: ACHHUZ7jNFBqqbCOkEvQqb29hL+y2cNlyTFSgIIk2Xq0bkD4rLIG8OBydLrmkNXcaYonBXkhtvXHLQ== X-Received: by 2002:a19:7b04:0:b0:4f3:b61a:a941 with SMTP id w4-20020a197b04000000b004f3b61aa941mr2822391lfc.51.1686512507448; Sun, 11 Jun 2023 12:41:47 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1246960lfl.28.2023.06.11.12.41.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 12:41:46 -0700 (PDT) From: Linus Walleij Date: Sun, 11 Jun 2023 21:41:33 +0200 Subject: [PATCH v3 07/10] mmc: mmci: Use state machine state as exit condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v3-7-cd3d5925ae64@linaro.org> References: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Return true if and only if we reached the state MMCI_BUSY_DONE in the ux500 ->busy_complete() callback. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 2858d8d67129..fe928f8f4d8f 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -673,7 +673,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; - return true; + goto out_ret_state; } /* @@ -704,7 +704,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) /* Keep accumulating status bits */ host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); host->busy_state = MMCI_BUSY_WAITING_FOR_START_IRQ; - return false; + goto out_ret_state; } retries--; } @@ -713,8 +713,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) writel(readl(base + MMCIMASK0) & ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; - return true; + goto out_ret_state; } /* @@ -733,7 +732,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); host->busy_state = MMCI_BUSY_WAITING_FOR_END_IRQ; - return false; + goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); @@ -742,7 +741,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; - return true; + goto out_ret_state; } } @@ -751,7 +750,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); host->busy_state = MMCI_BUSY_DONE; - return false; + goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy end IRQ\n"); @@ -760,11 +759,14 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; - return true; + goto out_ret_state; } } return true; + +out_ret_state: + return (host->busy_state == MMCI_BUSY_DONE); } /* From patchwork Sun Jun 11 19:41:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13275362 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 506D8C87FDD for ; Sun, 11 Jun 2023 19:41:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232630AbjFKTlw (ORCPT ); Sun, 11 Jun 2023 15:41:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232058AbjFKTlv (ORCPT ); Sun, 11 Jun 2023 15:41:51 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D971126 for ; Sun, 11 Jun 2023 12:41:50 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f004cc54f4so4211544e87.3 for ; Sun, 11 Jun 2023 12:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686512508; x=1689104508; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=mzqgnubCrQNmFQQRG76ba6Xb4A3msmE4+GEzwS5EvGY=; b=DtPdIKvWV7nxGFh/sAytmeI2kE7/UE+3zDp1pa3x5xP3tHALcFDnw2i2ijaQR7T0mc nl2P7fkYEIR6kCzGmLgiclGHDjzTAypC4xVdTuw50xuR9ABEP/v06KxQSX01ku7YY82i QADKelWU5kxbMe3u+3gZ5wqCyPiesW5HBnGnxiUvRK0aPfDkYJjqKQ0CsTGBCUvZaKwA ItMqrDYxW3LEm0z7h+ey4jM1ahP1PvOznoVXXbG5qAPCC9IRRkA4IrDC66X819mxoF6O 3KSHbAY9pOWzJ5jebbJ7CIphZkkYiN8K6YdsxqnWmw++78CVTHzrPQXJ2qEwaCMgi1Dm 3WgQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686512508; x=1689104508; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=mzqgnubCrQNmFQQRG76ba6Xb4A3msmE4+GEzwS5EvGY=; b=gIdIIPJFoFSwrFfrRnY5EyAizyJQfJ6iXzjPB+RA7ZPATXu6kEhIH+/74ZFmarXXaT 5T87NXSdqOBHjf1B04nwo4d0h/pNZBOXxg/vwVD1xG0hd3yjfhcGXGKq1pH6SZ08KV+h BcGGJgBuQGP5uh8k9VX/nxawNa1PDEBsizzdkKmYNUFvWOa8AuKGvsDUpf2nHyj17pMK GSHMbZmGVpoW60mnKXVnPGux0Y61uV8PvmieXosFDTyDZLFhDtfcsWkQU4yn7RSxIRjb /IHPGcE1KyUAbwkhDfWXyfeFiKj+gMrix16oaJ/MTLGuQArlCZ7GNylH0Q0wAeEWGKsK VyoQ== X-Gm-Message-State: AC+VfDz1Jir0RvdDoNe0kwrZPmCfH13A0iRNde9EjL+I/m4tYr22cjYa lMGoPma8LzPtiprD5LNvwaSWXw== X-Google-Smtp-Source: ACHHUZ6Oy90IMsC6hgXxCtYYcJIsf4zoXIIia97ReoBpGIM9mjzY227XjC7bthvVB4KlV1LrjyPiEA== X-Received: by 2002:a05:6512:548:b0:4f6:4a10:ac4c with SMTP id h8-20020a056512054800b004f64a10ac4cmr3112046lfl.42.1686512508452; Sun, 11 Jun 2023 12:41:48 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1246960lfl.28.2023.06.11.12.41.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 12:41:47 -0700 (PDT) From: Linus Walleij Date: Sun, 11 Jun 2023 21:41:34 +0200 Subject: [PATCH v3 08/10] mmc: mmci: Use a switch statement machine MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v3-8-cd3d5925ae64@linaro.org> References: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org As is custom, use a big switch statement to transition between the edges of the state machine inside the ux500 ->busy_complete callback. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index fe928f8f4d8f..e80dd7e7a001 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -676,6 +676,12 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) goto out_ret_state; } + /* + * The state transitions are encoded in a state machine crossing + * the edges in this switch statement. + */ + switch (host->busy_state) { + /* * Before unmasking for the busy end IRQ, confirm that the * command was sent successfully. To keep track of having a @@ -686,7 +692,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * it starts signaling busy on DAT0, hence re-read the * MMCISTATUS register here, to allow the busy bit to be set. */ - if (host->busy_state == MMCI_BUSY_DONE) { + case MMCI_BUSY_DONE: /* * Save the first status register read to be sure to catch * all bits that may be lost will retrying. If the command @@ -713,8 +719,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) writel(readl(base + MMCIMASK0) & ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; - goto out_ret_state; - } + break; /* * If there is a command in-progress that has been successfully @@ -727,12 +732,11 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * both the start and the end interrupts needs to be cleared, * one after the other. So, clear the busy start IRQ here. */ - if (host->busy_state == MMCI_BUSY_WAITING_FOR_START_IRQ) { + case MMCI_BUSY_WAITING_FOR_START_IRQ: if (status & host->variant->busy_detect_flag) { host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); host->busy_state = MMCI_BUSY_WAITING_FOR_END_IRQ; - goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); @@ -741,16 +745,14 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; - goto out_ret_state; } - } + break; - if (host->busy_state == MMCI_BUSY_WAITING_FOR_END_IRQ) { + case MMCI_BUSY_WAITING_FOR_END_IRQ: if (status & host->variant->busy_detect_flag) { host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); host->busy_state = MMCI_BUSY_DONE; - goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy end IRQ\n"); @@ -759,11 +761,14 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; - goto out_ret_state; } - } + break; - return true; + default: + dev_dbg(mmc_dev(host->mmc), "fell through on state %d\n", + host->busy_state); + break; + } out_ret_state: return (host->busy_state == MMCI_BUSY_DONE); From patchwork Sun Jun 11 19:41:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13275364 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 817A3C7EE23 for ; Sun, 11 Jun 2023 19:41:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233871AbjFKTlz (ORCPT ); Sun, 11 Jun 2023 15:41:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44166 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232058AbjFKTlz (ORCPT ); Sun, 11 Jun 2023 15:41:55 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0834FE42 for ; Sun, 11 Jun 2023 12:41:51 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f642a24555so4227707e87.3 for ; Sun, 11 Jun 2023 12:41:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686512509; x=1689104509; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=DOREVZA+zERMYs+RJDBSFYM3ALswR/wHOUbJG0YlIJE=; b=mKf5kxK4RJQHf+3S71k1y9a4LnmDcogYClmmdgwmFExBsXVpkFOik+LdjfXB8FHtkU wpFOnYxjjslfR5c4FC37/PjGgUSW3DEk601aEs6E1Iwp1MiQTv9gI/XFoZzDHMBsMcx+ LSS9RpZLWQ1HWSD6K2P1BoqrRS39+GWE6MNiMy8Q5RQuvsVO2MQnK7522ELl+iKoSyrU Q7xVehFcIu3eh1QkvHea5oaSQaBCKgL/5QLvpSEmCtz7nlmEEdd01i9q+HNLO9+MMYfN grTQl3u+m+hHSwyryF+ZmmIOpJ094cbNmiXs+VoSU0O78G1z4+kbqN/gH3A0vUQ+P15R 2owg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686512509; x=1689104509; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=DOREVZA+zERMYs+RJDBSFYM3ALswR/wHOUbJG0YlIJE=; b=A+18F+Nnqe/FHpyiMeuzwuG/QTLQKLddV5riFezs8esjXYWgGmsV9/wv4XmoQ/B6B2 I4oJDMKb3zLJF3Ls47raSJyk0aol3SJ1Df2Z9lNNDqUmRrlIMbqjbO2Glb/j+8AdYz80 uh/qNGPEpn9rLlMb9wC0l2c2sodg0zlD3XooQa/ig+PYVT2/TT9yWqWSZ1CNaTBEJqk/ h0bCa2VBU3nSe84Qgs7lkW8StrpewSADrXpyk/uFMvcECFOr+s5ecrG/HPULqb0YlDeh Q2RFKY/E6GJL1pUzruftSVNFkjbRZN4YtrgMnwWrAn0s+iYfbaWW8vqm1WaHne2ccuMm 7nzw== X-Gm-Message-State: AC+VfDxbH+kOwsZDP399icNJjUhbzZ6AtKI7dIjEBezGeKTwcrKB20e6 rgqyg5nfrUptqpGzpo2JBqV+rA== X-Google-Smtp-Source: ACHHUZ5Pm/aLx2cAktRf/CkifxFJKVMQo87Q+ScHJU8mgadflGv+kwdWQVDRjhEaLLGoWQj2hysh9Q== X-Received: by 2002:ac2:5928:0:b0:4f4:c909:cddf with SMTP id v8-20020ac25928000000b004f4c909cddfmr3097520lfi.44.1686512509382; Sun, 11 Jun 2023 12:41:49 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1246960lfl.28.2023.06.11.12.41.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 12:41:48 -0700 (PDT) From: Linus Walleij Date: Sun, 11 Jun 2023 21:41:35 +0200 Subject: [PATCH v3 09/10] mmc: mmci: Break out a helper function MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v3-9-cd3d5925ae64@linaro.org> References: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org These four lines clearing, masking and resetting the state of the busy detect state machine is repeated five times in the code so break this out to a small helper so things are easier to read. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 36 ++++++++++++++++-------------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index e80dd7e7a001..05b8fad26c10 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -654,6 +654,17 @@ static u32 ux500v2_get_dctrl_cfg(struct mmci_host *host) return MCI_DPSM_ENABLE | (host->data->blksz << 16); } +static void ux500_busy_clear_mask_done(struct mmci_host *host) +{ + void __iomem *base = host->base; + + writel(host->variant->busy_detect_mask, base + MMCICLEAR); + writel(readl(base + MMCIMASK0) & + ~host->variant->busy_detect_mask, base + MMCIMASK0); + host->busy_state = MMCI_BUSY_DONE; + host->busy_status = 0; +} + /* * ux500_busy_complete() - this will wait until the busy status * goes off, saving any status that occur in the meantime into @@ -668,11 +679,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) if (status & err_msk) { /* Stop any ongoing busy detection if an error occurs */ - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; + ux500_busy_clear_mask_done(host); goto out_ret_state; } @@ -715,10 +722,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) retries--; } dev_dbg(mmc_dev(host->mmc), "no busy signalling in time\n"); - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; + ux500_busy_clear_mask_done(host); break; /* @@ -740,11 +744,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; + ux500_busy_clear_mask_done(host); } break; @@ -752,15 +752,11 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) if (status & host->variant->busy_detect_flag) { host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); - host->busy_state = MMCI_BUSY_DONE; + ux500_busy_clear_mask_done(host); } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy end IRQ\n"); - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; + ux500_busy_clear_mask_done(host); } break; From patchwork Sun Jun 11 19:41:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13275365 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2DB64C7EE2F for ; Sun, 11 Jun 2023 19:41:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232058AbjFKTl4 (ORCPT ); Sun, 11 Jun 2023 15:41:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233772AbjFKTlz (ORCPT ); Sun, 11 Jun 2023 15:41:55 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1554B126 for ; Sun, 11 Jun 2023 12:41:52 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4f63ab1ac4aso4146758e87.0 for ; Sun, 11 Jun 2023 12:41:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686512510; x=1689104510; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=j+1+S9hp0bTxPBqMP9IlZLkTv4wJCYyQn7oPu0mlDDM=; b=wO3ThUt4hp5j3C9HdmnPZMDUtmaKLluhsXOfPKD2WgZtfcDvjFYQLknqeaySvZ2fhq kx5lwGmIZo7AnyHS9n0PuHRGILFVDnTI9UdHMru0nSd34YqrwoueZ/0tkYou6iDqBFgu vgA1Ss7rqkfhnT9u9H4SDzhOn1LR9L9zAVJB8br5/A3RYbWgCsUw/gYP3sPeHVzq9sua vGGDa/GbcL+sBaRDfKIvGS3GZfcaW0NgwpW8EApFZtHc2+G98isB9HVZRb3DhA6TyXAG CZzL6j8HyEaD2E3pMPn96of+sbmdzWEfbg4OYBVgvVG6JZIYLoclZDEyk3FhHMkjWMV5 TdzQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686512510; x=1689104510; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=j+1+S9hp0bTxPBqMP9IlZLkTv4wJCYyQn7oPu0mlDDM=; b=evVp6LM4vZmEPHA+foy4tHoFZmzeMC+Wb/y9d9QAPrkfbm7yMZzPBiLV83r2+XY+Jl jorYKLd5YgxcQEk4hlfKT0XxcPWh2sSaCWrmRAGoYMDu4FVMFJX2kwT/gnl7297x9FpK wqtqQVhQvf3pc9Oevz3oBnlHqDQqjw+280RRev+rIQuY+QcGu81ZHrmsEKowwCymWtc/ Y1ZvBHQmdhVolLsTfhk3bQfsyLpmQ5YV8Br64yOVd7B3HM9wngRKPmonQsqebDftsDGQ A+TTZ7uQOMYrnSVOWKMSIZYV2mJVL8q5/x23KgOWGSqIxauIcMCwUPNUmG94xkiHo1cu SGjQ== X-Gm-Message-State: AC+VfDwVxyIiPAQVnHi32tLtm5PS6sID4IuQfgmS/tMWVEg8CtnDJsxk tGjM0YopxZWyOhyqxtZnb2PtuQ== X-Google-Smtp-Source: ACHHUZ7gwtSEITF6+GPD71WfSTdThuSmOnOuI2Mb0zrUP0AP15KtxfazuP9qFj/EtAJSsXpvHUUH1Q== X-Received: by 2002:a19:6550:0:b0:4f4:b218:e85f with SMTP id c16-20020a196550000000b004f4b218e85fmr2301600lfj.31.1686512510394; Sun, 11 Jun 2023 12:41:50 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id u24-20020ac243d8000000b004f14ae5ded8sm1246960lfl.28.2023.06.11.12.41.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Jun 2023 12:41:49 -0700 (PDT) From: Linus Walleij Date: Sun, 11 Jun 2023 21:41:36 +0200 Subject: [PATCH v3 10/10] mmc: mmci: Add busydetect timeout MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v3-10-cd3d5925ae64@linaro.org> References: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v3-0-cd3d5925ae64@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Add a timeout for busydetect IRQs using a delayed work. It might happen (and does happen) on Ux500 that the first busy detect IRQ appears and not the second one. This will make the host hang indefinitely waiting for the second IRQ to appear. Fire a delayed work after 10ms and re-engage the command IRQ so the transaction finishes: we are certainly done at this point, or we will catch an error in the status register. This makes the eMMC work again on Skomer. Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 23 +++++++++++++++++++++++ drivers/mmc/host/mmci.h | 1 + 2 files changed, 24 insertions(+) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 05b8fad26c10..7e40b8f2dbf3 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -741,6 +742,8 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); host->busy_state = MMCI_BUSY_WAITING_FOR_END_IRQ; + schedule_delayed_work(&host->busy_timeout_work, + msecs_to_jiffies(10)); } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); @@ -752,6 +755,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) if (status & host->variant->busy_detect_flag) { host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); + cancel_delayed_work_sync(&host->busy_timeout_work); ux500_busy_clear_mask_done(host); } else { dev_dbg(mmc_dev(host->mmc), @@ -1487,6 +1491,22 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, } } +/* + * This busy timeout worker is used to "kick" the command IRQ if a + * busy detect IRQ fails to appear in reasonable time. Only used on + * variants with busy detection IRQ delivery. + */ +static void busy_timeout_work(struct work_struct *work) +{ + struct mmci_host *host = + container_of(work, struct mmci_host, busy_timeout_work.work); + u32 status; + + dev_dbg(mmc_dev(host->mmc), "timeout waiting for busy IRQ\n"); + status = readl(host->base + MMCISTATUS); + mmci_cmd_irq(host, host->cmd, status); +} + static int mmci_get_rx_fifocnt(struct mmci_host *host, u32 status, int remain) { return remain - (readl(host->base + MMCIFIFOCNT) << 2); @@ -2300,6 +2320,9 @@ static int mmci_probe(struct amba_device *dev, goto clk_disable; } + if (host->variant->busy_detect && host->ops->busy_complete) + INIT_DELAYED_WORK(&host->busy_timeout_work, busy_timeout_work); + writel(MCI_IRQENABLE | variant->start_err, host->base + MMCIMASK0); amba_set_drvdata(dev, mmc); diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h index 12a7bbd3ce26..95d3d0a6049b 100644 --- a/drivers/mmc/host/mmci.h +++ b/drivers/mmc/host/mmci.h @@ -451,6 +451,7 @@ struct mmci_host { void *dma_priv; s32 next_cookie; + struct delayed_work busy_timeout_work; }; #define dma_inprogress(host) ((host)->dma_in_progress)