From patchwork Tue Jun 13 20:34:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13279178 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 CC77FEB64D8 for ; Tue, 13 Jun 2023 20:34:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230451AbjFMUec (ORCPT ); Tue, 13 Jun 2023 16:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230516AbjFMUeb (ORCPT ); Tue, 13 Jun 2023 16:34:31 -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 4C04A1989 for ; Tue, 13 Jun 2023 13:34:28 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f619c2ba18so7138841e87.1 for ; Tue, 13 Jun 2023 13:34:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686688466; x=1689280466; 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=S7UBLcTRqRDwyg2dTPn5N53PKfQxU1SA5dNqRVb2SiA=; b=MVhtYZ3zaidcK4sb8yl4WR2oTheh70dTSCD+vkNSi7R31b8Uk+pqOR85uMtcRJVv/z ctEXi/2cgxkQmfbvlqypQYC2tqRy0H2ErzChOE4aztJEjCguhjQfsjnbI8/VsQzEe5bN nkXBa+0Au3ZT559GepoJg6jOxrRo1sWBM58zSDt2qj1kWe6R7HTZnvDwWzoOCJLbTwjJ TciLFO3X1+KGuxcG3ebuZENy9Mq/xc4MewlBvcTyZw1k/+T96M7ChJqrgMud2J/j+B8S sEKWs8z6vf/Nvkei7Z4jGF6cGTq+HPgo0Oqi8F7Q/gXoR9p5lZKknqCCem9K9eG2yJa2 Kaqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686688466; x=1689280466; 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=S7UBLcTRqRDwyg2dTPn5N53PKfQxU1SA5dNqRVb2SiA=; b=GhMiUta/e5T0NYEASq9SmEgdj+WF38oiUpFuSR7iuFgAUCFCS4T4ZnENayuHgUMeHY WL1TjWaV6dLDrO+4VoYWY0SV2G8c8n8RnrmeWEOz0l0Pu1camqrc3P+V7afYvGVt+cKq bmfVHnRMwgEki1mSdaHGwOe0mc4betKC+6HrL9uuEm2Q3E1iyaBKkT6KQwpkjb30uPN1 /N/4k1zR26DmJox0FWnlsT7U5fIUkweiTc7Jr9NdBJG5sLuS9WjxlcypDcfj0a9DrUqD r/ufQr1O5hXlFZ9SmecsgMtnQxB6j9Aajc/i4eb2vHADMbTkcC2XSawOHQb1rp7R4OVA 07ug== X-Gm-Message-State: AC+VfDzSwe5PEuwCVv633G27l/EZRlGoIR4sYnDeiAdfFP6ycBdTN+1m F32Zc8l9oDk+6LWwTK/mZWBqSg== X-Google-Smtp-Source: ACHHUZ7W4kB0+K6j6YMrWQpjURfpqZwC7/r7SId+XagPh+drqL6h7JN+J4aLHswQiULgS5gxsosIyw== X-Received: by 2002:a19:8c4b:0:b0:4db:3d51:6896 with SMTP id i11-20020a198c4b000000b004db3d516896mr6367821lfj.11.1686688466325; Tue, 13 Jun 2023 13:34:26 -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 l12-20020a19c20c000000b004f26f699e9dsm1897813lfc.184.2023.06.13.13.34.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 13:34:25 -0700 (PDT) From: Linus Walleij Date: Tue, 13 Jun 2023 22:34:17 +0200 Subject: [PATCH v4 01/10] mmc: mmci: Clear busy_status when starting command MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v4-1-df9c8c504353@linaro.org> References: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@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 v3->v4: - Fix the oneline stray change to semantic order of busy flag so the patch is the oneliner it's supposed to be. 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 | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 97a77eefb11a..0a4b6b6e0f03 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1238,6 +1238,7 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) c |= host->variant->cmdreg_srsp; } + host->busy_status = 0; if (host->variant->busy_timeout && cmd->flags & MMC_RSP_BUSY) { if (!cmd->busy_timeout) cmd->busy_timeout = 10 * MSEC_PER_SEC; From patchwork Tue Jun 13 20:34:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13279181 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 566DCEB64DB for ; Tue, 13 Jun 2023 20:34:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230108AbjFMUed (ORCPT ); Tue, 13 Jun 2023 16:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231209AbjFMUeb (ORCPT ); Tue, 13 Jun 2023 16:34:31 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23D4A1996 for ; Tue, 13 Jun 2023 13:34:29 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4f620583bc2so7460675e87.1 for ; Tue, 13 Jun 2023 13:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686688467; x=1689280467; 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=zjbTCpreEwrPILZW6pVXqr+kf3zl3RqDAOxeSTWO4Xo=; b=OGfRhCFCEBHmYRzodJx0DsHjJwHotZpGZY8TupzhoiuigjQ/wY3KjwP/2zSy6xQ7jC PzyIy7Z6+Zzfe0fnf3t0qlYmFcb3E/xFhSgJ4+GfHB5vDnWFxP9fhsj2u9E5Voo5ICaV 7JDEOksiEw/NbZKgGU04Qjzj83hKRY/8qb85uxw46wGTnI9bEChR+zIRKY0n2BLYcUf3 vBHDzKlWlAu7aJ/snZj+kaX13XoDtJAbrxWlsfdi7fmaL+EYFuxKHT0/K7iZeRAa0twU hW31Y2XZcT+dsH1pEoPysyw2A0/Q+QNKG2xxIwx6WnzRVcJcC6UUmRExQaVswFouOG8P nXjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686688467; x=1689280467; 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=zjbTCpreEwrPILZW6pVXqr+kf3zl3RqDAOxeSTWO4Xo=; b=cfK5GQptt3twPs2BSVMhsVRaM0Qwsq0R49P+a6dxfXXo7ahXjl8aU+Cg1CJ2JJYOE7 tyuNL2XV3Fg7R2yybdRQrkeTsuzLCs9F7Y34/3WSORuMeBk4RqwigXC3u0cY351MlXn1 Eg3M7KdPOHbEpqjVWSXBTBoeBJElG7e6fxK93rOUr6GQxLo79e9Og3suH4wztVuT3cEx ANRobw4YUzlnTCygyqf9cUYpYJx+yMMhC/gmxNxaichoDRTDWOA4USHoLcajVFCCQmsi 6FfiWugqxEzrh9roTF5BYComYQ9j1oY5npziXzxgal48a7+NDCJFUlluv+weB0zUv6QK A8GQ== X-Gm-Message-State: AC+VfDyTJ0G0NqMrJatczTPE4ea/Mmpeq5rzxTXqB2h4tgyeDjmo+gyo doBoshgpzwoQuWXSy82ucgbsPg== X-Google-Smtp-Source: ACHHUZ4bLabGiY0m9kbpH88S2x0f/T1TMtQw6g60ZJS+cKL8tYcQdAXtZcauyjVGuutNwa1+6YGaWQ== X-Received: by 2002:a19:ab01:0:b0:4f1:3bd7:e53a with SMTP id u1-20020a19ab01000000b004f13bd7e53amr6432839lfe.49.1686688467301; Tue, 13 Jun 2023 13:34:27 -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 l12-20020a19c20c000000b004f26f699e9dsm1897813lfc.184.2023.06.13.13.34.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 13:34:26 -0700 (PDT) From: Linus Walleij Date: Tue, 13 Jun 2023 22:34:18 +0200 Subject: [PATCH v4 02/10] mmc: mmci: Unwind big if() clause MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v4-2-df9c8c504353@linaro.org> References: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@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 v3->v4: - No changes. 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 0a4b6b6e0f03..eee449f90915 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 Tue Jun 13 20:34:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13279179 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 EA5E5EB64DA for ; Tue, 13 Jun 2023 20:34:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231209AbjFMUee (ORCPT ); Tue, 13 Jun 2023 16:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230433AbjFMUec (ORCPT ); Tue, 13 Jun 2023 16:34:32 -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 D06DD199C for ; Tue, 13 Jun 2023 13:34:29 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f62b552751so7453450e87.3 for ; Tue, 13 Jun 2023 13:34:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686688468; x=1689280468; 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=HEWZ3mk4O5IbHesXExTqQF3woZXVOofkrFDb7Wvq9pM=; b=O3GqsVFjd8mTLVD5WMmFXeH/dZGabEKtmTTLdPUlcbL6BI4/+J3hsqPTuDlIz9BAzg +cg7hXy+74KOIH8eCT2LGEieWXtZCLlQGgVtf81BgpZljJ/Mq4hlGUn1fFDWvPQ9qkAU UfJBeXE7AJl/Mq+Xl6WWc4TNju3HUX04vcK6G/Q6MFXEDqXvnpC1pfB+xamyJOY1D3/x RIUwjQZe9Smvndk1o1K5kKJH09osYlWsc+2PBcT4FsMJsKbLcGJkNCib+LeE9cwNANNP FmH75hPPyCgE/cW4lesnquNjqourWLSiHJ9XsP1ucIOkA4WFNH3YVWYrTMmmk5ubewj3 tmDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686688468; x=1689280468; 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=HEWZ3mk4O5IbHesXExTqQF3woZXVOofkrFDb7Wvq9pM=; b=bx140xYdwKSWIlk8P5VuKD2foeRFq9KFe9FoHhDjOTsq9d1i9TP+0EmjxeM0FzPldV 6G6icJZl02VWAALu1jrHbuobXUs8A17cTYAjnTdgx2pikDU/7mkfTyoO8UCk13rHzPTK uCLvGuKu92Nlr8Vxy/eve5gmYJQGVWc1S63954ngrBvZMF43WEf1y84wBXjz5Lnw/q4J +W6xeVRj3fP1yTEn5E0zLAVrwR6IdiiXXfw3KafmD8RGZF7E6MY15ZSxhRTLTlPAY+UX 6sR9Z0rrhr64Illl5xtdA0M3qCY6hu/Crqg/gUbzrCD9Q48euJzMXuEV2bNGvxv2PV5s 4BPg== X-Gm-Message-State: AC+VfDzYsqihvI7aeYfyNhcmSWfoOwA4XAcg9siNGY7R8hn39QgAZ/AZ sN8+3d3G+DgXQH8cexJyu3kK8Q== X-Google-Smtp-Source: ACHHUZ4MJ1g+3kaOn/hlXnU8wnvFYa+Alm2v+9RG63pXCADxF8i/SEE0xuvW94dag0BU0pXA4yYBfw== X-Received: by 2002:ac2:5b5b:0:b0:4f3:a9d3:4893 with SMTP id i27-20020ac25b5b000000b004f3a9d34893mr7278345lfp.35.1686688468189; Tue, 13 Jun 2023 13:34:28 -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 l12-20020a19c20c000000b004f26f699e9dsm1897813lfc.184.2023.06.13.13.34.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 13:34:27 -0700 (PDT) From: Linus Walleij Date: Tue, 13 Jun 2023 22:34:19 +0200 Subject: [PATCH v4 03/10] mmc: mmci: Stash status while waiting for busy MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v4-3-df9c8c504353@linaro.org> References: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@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 v3->v4: - No changes. 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 eee449f90915..47b306e45f78 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 Tue Jun 13 20:34:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13279180 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 8F268EB64DD for ; Tue, 13 Jun 2023 20:34:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230433AbjFMUee (ORCPT ); Tue, 13 Jun 2023 16:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230496AbjFMUec (ORCPT ); Tue, 13 Jun 2023 16:34:32 -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 B8A69DC for ; Tue, 13 Jun 2023 13:34:30 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4f658a17aa4so6691550e87.0 for ; Tue, 13 Jun 2023 13:34:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686688469; x=1689280469; 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=Y2Xs3XgGJttCT2952b8M8V6pJJgNj+V+JW7LJwfPkUM=; b=YZZUMljVoLCRehekqNwUr42thbxpLbBIH/2jnNJqY5Y7DE0SwxpGZACVeYsMb8oqOV lQsLn4YYLs2fEREGsIw0gUkUMwxAenDkeFX4PGlNSCA4n4y6x8hiJ8Y+jP/KxH1lE6fX wa591VIA/MtLG9q3olyAeD4ZxMCROoMKrH8MCUdSAU0vByfD3FO74QMSQ+PCkNih26bq 7bR1ThZ5hJdF6gkb3Q6HL4kH1NCwg+yW60pW7PKoGVWSAzGvNu6aAkQsCxMBTVQkQLeT z4J0Xshd9xMPVuJZi2O26CMTArz0PI709LYWoU8qqPIuGHBEZ14c3fGb3KTT0oDWutVK LONQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686688469; x=1689280469; 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=Y2Xs3XgGJttCT2952b8M8V6pJJgNj+V+JW7LJwfPkUM=; b=A/BqY0UjkD9ZrFyX2wh0ZPxTJWNM8MPAUcKhYhmmvl2Ul6GbcHXLci+fCOYS0FiZHo /nbTj+KCpFMWvK/aPU4ygrCAa5yQ0z7IUKdDFxOIqeDBmScpyCsAeIzoo5goVgYXxpfm pjrGdQbXVP1FhPExiKd+YFzRMRtpWVyT1BSsAVZzlgM0HrrCr6wvEGE3fbfeW6NbsEnS BLEgWIXpXq6xeQ9nTASBsgvDd+BGM/tVbED+gnunGrrnbVAbjqih85LLpDCUDaMWyKi9 0PnBlPq6aXoQ6GNBhBlPqIaonEtRDPbk97n/5AqtEjxW2s6E1dTLT2EUIocM8MmtR9y5 3heQ== X-Gm-Message-State: AC+VfDySgjl8QAglZtEybUHRctOZi8HwOezAWrh1IyBi9zwouzkRq4L8 4N3DeJhd4KuzTL780+Q4E8UX7w== X-Google-Smtp-Source: ACHHUZ6fZm7YQd7MlaNDN8uljS3Hdj3RBXwGZEnl6OMQ0T50GRRu2flWt5GAGuE0HYaEU9gJ6Q7y9Q== X-Received: by 2002:a19:8c0d:0:b0:4f4:c973:c97f with SMTP id o13-20020a198c0d000000b004f4c973c97fmr5921646lfd.49.1686688469107; Tue, 13 Jun 2023 13:34:29 -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 l12-20020a19c20c000000b004f26f699e9dsm1897813lfc.184.2023.06.13.13.34.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 13:34:28 -0700 (PDT) From: Linus Walleij Date: Tue, 13 Jun 2023 22:34:20 +0200 Subject: [PATCH v4 04/10] mmc: mmci: Break out error check in busy detect MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v4-4-df9c8c504353@linaro.org> References: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@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 v3->v4: - No changes. 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 47b306e45f78..d632658d9d20 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 Tue Jun 13 20:34:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13279182 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 52575EB64D7 for ; Tue, 13 Jun 2023 20:34:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230430AbjFMUef (ORCPT ); Tue, 13 Jun 2023 16:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230516AbjFMUed (ORCPT ); Tue, 13 Jun 2023 16:34:33 -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 DE3FA92 for ; Tue, 13 Jun 2023 13:34:31 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4f74cda5f1dso3038364e87.3 for ; Tue, 13 Jun 2023 13:34:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686688470; x=1689280470; 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=UdAVTh09lAy/OHXiQCijK6TEu6mm4fi+59Msl6eq5C0=; b=nCT8P6i7F/Ve7lyjs0+Tuq1RYpdwJVpglRlNRcB7iQWZcjg8iiOhIZQIFmfRq9z2ZQ lVY2nkK5J/dmvoYJ3V1b533yTJjBIVfTv3W/1w+MNe37IL8VthHbh2N49R/SJIiVHEyY Fp/jcMXJGGjt/VFUTG8l/VDK7dFsdnDRaGyYrEBAS3MH0pBIrTAyEg/Nh7gx9I4lnQuU /Ic7697q3o84X4ex4i7o4k0aTF5R0q+meZgoqY0bjZYN9buCkN4T0sxC05tFGAh7Mmi3 IVQ1+0yuGXREfuEUUfTq+cZVXShXnhlNqAGwsDmVzSeyO1eEBnn857I1VOb90hHFdZoa g1wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686688470; x=1689280470; 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=UdAVTh09lAy/OHXiQCijK6TEu6mm4fi+59Msl6eq5C0=; b=RM9C37YMDkHU9XXsDv7pZKBJGM30f5oN75WinUEKR2YViDOxbufIbnVYKIvom6ltoT l9rRwmbqtUTeHl+e9sKoAuWS75nTaScxx7230miGmlpO8xMZxyW4y5ggVBbas05/YjkF ozzdgUQJ3LQdU377dsd/9wnUC/cYj97Xz5nTOlgrdiCnAI2Fed/a8O7mJzVRjKZGNbun O9P1X7PxCF1BSAJA44rLX2AmXWSfyD4qSdrF1ZFt+kD1VxNz13zSXnX2kipCeA63mnXH /5eC1M6RHrSWPDFOQcd82ode35m8aXh0PoxTiB+IA8muBtj5d9XpsCF3wbqKiSpYdfIJ bJpg== X-Gm-Message-State: AC+VfDzUYznSGROhLWlUH65YrSCTCHA8KAA2BHJs4sAWyQ+WykDpG5ZM m5ThmMhSdtVMZOo1QI+XS/EQtQ== X-Google-Smtp-Source: ACHHUZ7pVrL9wCigCd2X2+n7AcKK7OjRXgFApwazZIlZs+P+w+KKCtoh6hsQN0XiViuf8Qs2JOpfZg== X-Received: by 2002:ac2:5b87:0:b0:4f3:b708:f554 with SMTP id o7-20020ac25b87000000b004f3b708f554mr8051429lfn.47.1686688470168; Tue, 13 Jun 2023 13:34:30 -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 l12-20020a19c20c000000b004f26f699e9dsm1897813lfc.184.2023.06.13.13.34.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 13:34:29 -0700 (PDT) From: Linus Walleij Date: Tue, 13 Jun 2023 22:34:21 +0200 Subject: [PATCH v4 05/10] mmc: mmci: Make busy complete state machine explicit MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v4-5-df9c8c504353@linaro.org> References: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@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 v3->v4: - Assign state MMCI_BUSY_DONE outside the if()-clause for the busy detect initialization. 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 d632658d9d20..3b1a23e4ec1c 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; @@ -1258,6 +1275,8 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) } host->busy_status = 0; + host->busy_state = MMCI_BUSY_DONE; + if (host->variant->busy_timeout && cmd->flags & MMC_RSP_BUSY) { 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 Tue Jun 13 20:34:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13279183 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 66874EB64D8 for ; Tue, 13 Jun 2023 20:34:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230496AbjFMUef (ORCPT ); Tue, 13 Jun 2023 16:34:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231651AbjFMUee (ORCPT ); Tue, 13 Jun 2023 16:34:34 -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 A2DB0B8 for ; Tue, 13 Jun 2023 13:34:32 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4f649db9b25so7440701e87.0 for ; Tue, 13 Jun 2023 13:34:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686688471; x=1689280471; 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=LrZysrHENuW7Go4ISnRgrIAfcenSBPlLC8M9RsAwT2M=; b=xPagHHSysBnXwwl7UbNSgtYhf7WnjXzwEItZgkcsvapQyoFhrh2IWdQvXlH1ndEsQP QefpdQZZhgHRvwJS9KmdbYP9noACVipd2lqaqy9VShtStbK56yoL5dmgYO0GhZYKSotN aAK8q0Fq3d0mCNdzJHD2uqFZBaVS4z0UW+QfQOQuFuJ/czUWQKxLBfsXh8GcGXSJMMfG GEdHJk5VaC7+VL6xJuN3HU61zPy16zv1pL0jNSYtfM5nsY2qC5RyjAHAhNsNbWrHZAWk QNkpFJLW4ogesncx4t0gLoyPptlyfucxpHxUmkaWI7ZFhnPUeZdd3o1N+eOdXF66x4Lz qy0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686688471; x=1689280471; 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=LrZysrHENuW7Go4ISnRgrIAfcenSBPlLC8M9RsAwT2M=; b=l1oOnPdcGVAzmjIOp7KC3m/u9ygIHhiOP+EaQ4po76r4Js6JHaPFcc7vCFWCI+PLmC L22SzLMA9SlP8Vd7+UxtjHAaYis95CPoCvSEkgFWpMBekTozYjUGXA5UCz2uvHA8ddAx 5k84/TyUmLYmVPJy1njh164UUwXXcaf7fUYvCf7Z6es3QIizGcU+syptX1mVgo1RSvBz 9AY9OtgITqoxnGScfMMOxr6Kci7jUc+guXRgsK38tfWjQGrNVz4X5q+AkvVPZK0sNfDV p/tDXbbScpKVkO1gVkZcLYhxxOIJCERulSNb72q3+q2VHj0/yEbBDxAsDQKLRtKAMJit P7uA== X-Gm-Message-State: AC+VfDzHSX/01a7WuicOcqkqzeUPqeMJWhGZUJZ+iP27+qSbKa7tFCvq O0nv9RuYtjqvs8WzIeb5lH6BzCLsLotNIcRTUOH4iA== X-Google-Smtp-Source: ACHHUZ5LaeGTyGWYf/6jYG5YnmIHRVeFpdY5z5E1lQsdVjyrL/Fba0h8+LYGk56qpQsSe1vHkghBTQ== X-Received: by 2002:a05:6512:457:b0:4f3:a91c:23d0 with SMTP id y23-20020a056512045700b004f3a91c23d0mr7147416lfk.31.1686688471016; Tue, 13 Jun 2023 13:34:31 -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 l12-20020a19c20c000000b004f26f699e9dsm1897813lfc.184.2023.06.13.13.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 13:34:30 -0700 (PDT) From: Linus Walleij Date: Tue, 13 Jun 2023 22:34:22 +0200 Subject: [PATCH v4 06/10] mmc: mmci: Retry the busy start condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v4-6-df9c8c504353@linaro.org> References: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@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 v3->v4: - Accumulate status flags outside the if()-clause in the busy detect retry loop. 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 | 39 +++++++++++++++++++++++++++------------ 1 file changed, 27 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 3b1a23e4ec1c..a412ecdee63a 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,35 @@ 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); + /* Keep accumulating status bits */ + host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); + if (status & host->variant->busy_detect_flag) { + writel(readl(base + MMCIMASK0) | + host->variant->busy_detect_mask, + base + MMCIMASK0); + 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 Tue Jun 13 20:34:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13279184 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 26F4CEB64DA for ; Tue, 13 Jun 2023 20:34:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231651AbjFMUeg (ORCPT ); Tue, 13 Jun 2023 16:34:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42536 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231839AbjFMUee (ORCPT ); Tue, 13 Jun 2023 16:34:34 -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 B6A6EE0 for ; Tue, 13 Jun 2023 13:34:33 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f4b2bc1565so7429750e87.2 for ; Tue, 13 Jun 2023 13:34:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686688472; x=1689280472; 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=Adhu9PdZtBYOCnLOWJSJpjhVZuSODtE/R96GA6MZfjQ=; b=b1IIp6tt+uAkYRZ4sjwCMJY2mQWcMcxObRQyDRGapb0uq+3wtwjqry1BMVU75W9mly YDbIBMdxJPRvJqDWgZYbQRtQWWcsTbRw7XIao9rlOspi6q3VP4oepKVapJK+Ote9sWDa NHoa07QULjJSomeMim4Rt1eDp260UMLH8uQVQYCuaFUPRzqFmSloEqdz3XYF3otGErfK v06i3XW9iFXZ8oKeT45ZB69ITGUmM4tjXuxH9uXLOChv8/2SqVtMgTL1xWkm8ByYWM3+ 9bLPL9fI/83GT9YWafMXf6ayomvKLnSlAFpHmazHQVIOgKl3sZYkNfX81Nv9wTzQfazs xL5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686688472; x=1689280472; 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=Adhu9PdZtBYOCnLOWJSJpjhVZuSODtE/R96GA6MZfjQ=; b=gO+IxmMbh2a9m1X1gU7sJr77LEtX9IbDfouvvyvgRY29M/YsuDEL2lOWF3neKA1Ed3 CuVCyIRfF/yBgFPCVvaOhDstlMaSAPqIx2j23aCb/q8Llplmh5tYTrutQ8rJFjDoUUrs V+vKeB407oR9OBZrGjLLDqHI+mb5VgPYxFkb33ybn7+h/rOQ0VPYjFNrijxtjm5TWAFQ kszBkN2r7W9OvRBQPeU+tbEEvAaA9PM82puUKhRdIqUpMo0cGAnqPSEsCwdC8o8wYVWs lnrRgtcvJ/W01NdyzgqX8oz5tFWlB+Jsna6JXOqhVagTQR4Gv8Z0JQVPdL04kfUUMtUL hVxw== X-Gm-Message-State: AC+VfDw16u48kzaKCe+aYR6j6uyDZBRqMgGIW9DAFad4/T7kG2e4MFxf ixk4N5MuH8SpKFgUcdBCPUblzw== X-Google-Smtp-Source: ACHHUZ4UoekS54u0lEghgz1uB/kpxKJ1A49IdD+1ZrPrZSOBsgoSFklRjb3PcnBvW99Chfi+MrX1bg== X-Received: by 2002:ac2:498e:0:b0:4ec:8615:303e with SMTP id f14-20020ac2498e000000b004ec8615303emr7491271lfl.33.1686688472016; Tue, 13 Jun 2023 13:34:32 -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 l12-20020a19c20c000000b004f26f699e9dsm1897813lfc.184.2023.06.13.13.34.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 13:34:31 -0700 (PDT) From: Linus Walleij Date: Tue, 13 Jun 2023 22:34:23 +0200 Subject: [PATCH v4 07/10] mmc: mmci: Use state machine state as exit condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v4-7-df9c8c504353@linaro.org> References: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@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 v3->v4: - No changes. 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 a412ecdee63a..48714e570116 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; } /* @@ -703,7 +703,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_WAITING_FOR_START_IRQ; - return false; + goto out_ret_state; } retries--; } @@ -712,8 +712,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; } /* @@ -732,7 +731,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"); @@ -741,7 +740,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; } } @@ -750,7 +749,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"); @@ -759,11 +758,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 Tue Jun 13 20:34:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13279185 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 87D0EEB64D7 for ; Tue, 13 Jun 2023 20:34:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231848AbjFMUei (ORCPT ); Tue, 13 Jun 2023 16:34:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230516AbjFMUeg (ORCPT ); Tue, 13 Jun 2023 16:34:36 -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 ACD4F135 for ; Tue, 13 Jun 2023 13:34:34 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-4f624daccd1so7144484e87.0 for ; Tue, 13 Jun 2023 13:34:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686688473; x=1689280473; 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=JE66c0ktyvQx6kWI5NItLAz064PDkHXvXmuP+9scr2c=; b=bxsgHbO44p214U+802iMIXHWym+XLhFjEkkLg7UGgTF1wcSkxCPGWMvoweXCkMQ6bl xD7caYOksWThGvMKGZ7VTM5z+1VD/aJzuRD0PIafxoUPPlbVhaNQ3GLkEENin+bMtH5L +/wqnumydUKsk9iJ+hm0prpnv1vzIWoNEsT4KwKDu7vP7jHgTzoxwwgJTMi9HgTN31iI SFT+j1Pb5wkVNARLBTTOZbE1ChcqiA33bj5admkhDnLeh+4n+XQY+Phqji0LtD3QgeOX eZcnN/WJbwMlA5wzercPLKZgOx8kqoD/X/iTV04xUuA+TFvNB9nbVFuURcgqcYn+FNp0 RWEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686688473; x=1689280473; 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=JE66c0ktyvQx6kWI5NItLAz064PDkHXvXmuP+9scr2c=; b=UWC+JGl59nBbUHODZVohy0ag7qcdHDCcAwiwxCaygShlIepvr1LnDoltUoovIo316x RHV29iyUQuHegiNjKgbLDBtxVWvXdmKh7UnFFgzjV7cZcCRsrYIdgyk9mWAnakLJ9i5f 4QjgPAJyU8Nc/xvF/3bdMW8IG/RrnhIknU8w3syndDgb+L2y3EHMtLCOr8HhKc/U5qkv 6tlThgdyOxMMlf0TYBChX+eIA75Y5sFuQ9aU/XWcXX1QOYi8JHCCfRp0ppKM+N/AZkxt qlX2lRvmeQSP3YkD3K8DdR65BILNcbmwGiI8/yzCeAId2wwmSt3oigWr4EIJGyVK7//h OISw== X-Gm-Message-State: AC+VfDy6xb9XhOALsYvUWrJ6g7IWPVH2IKwHpXcy4LnhJeLxfDsX8Lnz 95NYeMxQMWs7k0OzgHXsi61stg== X-Google-Smtp-Source: ACHHUZ4g5V/S4mNpuHFoty2XirnD9QeYi5zuSZOi4dtpWJjMEcYhCAOj4HaKbTiQ2OLH0thHxm4yPg== X-Received: by 2002:a19:2d17:0:b0:4ef:f1f4:14db with SMTP id k23-20020a192d17000000b004eff1f414dbmr6092205lfj.16.1686688473049; Tue, 13 Jun 2023 13:34:33 -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 l12-20020a19c20c000000b004f26f699e9dsm1897813lfc.184.2023.06.13.13.34.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 13:34:32 -0700 (PDT) From: Linus Walleij Date: Tue, 13 Jun 2023 22:34:24 +0200 Subject: [PATCH v4 08/10] mmc: mmci: Use a switch statement machine MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v4-8-df9c8c504353@linaro.org> References: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@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 v3->v4: - No changes. 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 48714e570116..cb766b8d419d 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 @@ -712,8 +718,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 @@ -726,12 +731,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"); @@ -740,16 +744,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"); @@ -758,11 +760,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 Tue Jun 13 20:34:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13279186 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 43D98EB64D8 for ; Tue, 13 Jun 2023 20:34:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230516AbjFMUej (ORCPT ); Tue, 13 Jun 2023 16:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230117AbjFMUeh (ORCPT ); Tue, 13 Jun 2023 16:34:37 -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 957E6DC for ; Tue, 13 Jun 2023 13:34:35 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4f644dffd71so7542789e87.1 for ; Tue, 13 Jun 2023 13:34:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686688474; x=1689280474; 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=SAfIo/HStS4ssmJ5VnFiRuxpA+ACqAiRQGlqQ7Ljwos=; b=J9jgl1fHcdpUNuOaw8NgNxbIqW9ldZJGhghSwketWliDS3ppFYG1x1QXcJ/Gyv6gWI CC3fFu8jUh1ymG75hNlIh/1KsbNjfgZN6d02JSA19Gmd3Ro6xPkL9xMBQAHuQ5HJ+ojV id3kYghTPHZVL5Ku8jMZQpiPzciWWePbIqX0cf1uY+dUesHp79NcQBmOpHCi/7hZncAp t6TiFGmRBYtSuuvjH2V79rxQHeKuDjyVv2QjyoDiJjRsC8FhIp0HPZ3MsKZ1DGjS4PGd /hkJSIhLEf1OHsAy41qNeyMjv5mHc79km2qGSJgiMFwy2JuWohXl5KW9eRdfUCcypiPx 5oWQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686688474; x=1689280474; 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=SAfIo/HStS4ssmJ5VnFiRuxpA+ACqAiRQGlqQ7Ljwos=; b=Os+BHeyeItnYDn9nIsOVJtYVN2rScckWTz2Qbz34UE7DWs94yX7sQFt8Dl3/Bdbmnm GtLQYujziDqRMoDYvxX0CaFhlm/wtWF2qQcKku4R93b10lS9tGmz2+SirivwdsXevQ9w 69GVKLix41ilxVoiZw1awQ3C8237Iv3qxmDclUT2QdmA3cFzGdjPgajO5tUPypJOPIay 4imx6s/w68IJvnb4Fzy0Aq9s3b5ZWflEnYOO7dEDrysBndwpwAZYTbhFv3dBEkbihVau 3fnuSpMzaOGPAtY25sbho00Kw+EAQjl0tN0EMXtXdX7owxTDUdkfi8aLGiy5AMHk93oW HgPw== X-Gm-Message-State: AC+VfDx4jHdrQLqA4DWM5TIk7xAreJ98O4uoD4pXBoYZU+mxYsJbI/tx WqIKT2JVTdc4FrKDLnrEkEzFfA== X-Google-Smtp-Source: ACHHUZ5xvUSgzRJCXb8G6VFIK8RZEFvMypqc6eZdYCcV/6Cf2jx9ee1Qy9lYaQlE/YexEGmCv5ixZw== X-Received: by 2002:a19:5e18:0:b0:4dc:807a:d144 with SMTP id s24-20020a195e18000000b004dc807ad144mr6502866lfb.39.1686688473988; Tue, 13 Jun 2023 13:34:33 -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 l12-20020a19c20c000000b004f26f699e9dsm1897813lfc.184.2023.06.13.13.34.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 13:34:33 -0700 (PDT) From: Linus Walleij Date: Tue, 13 Jun 2023 22:34:25 +0200 Subject: [PATCH v4 09/10] mmc: mmci: Break out a helper function MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v4-9-df9c8c504353@linaro.org> References: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@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 v3->v4: - No changes. 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 cb766b8d419d..478f71dc7f34 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; } @@ -714,10 +721,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; /* @@ -739,11 +743,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; @@ -751,15 +751,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 Tue Jun 13 20:34:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13279187 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 CA4ACEB64DB for ; Tue, 13 Jun 2023 20:34:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231937AbjFMUej (ORCPT ); Tue, 13 Jun 2023 16:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42572 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231732AbjFMUeh (ORCPT ); Tue, 13 Jun 2023 16:34:37 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7CD1918C for ; Tue, 13 Jun 2023 13:34:36 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4f6370ddd27so7478088e87.0 for ; Tue, 13 Jun 2023 13:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686688475; x=1689280475; 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=WWKwNW1e3O9pZLa+y32ctA1ee6HTYoouSwcC3BybN+g=; b=QGYyuzZVnU4QISKkli0HiuDScYZ0QZySflKskizSHBN5975GKBU+mutVM0U4ZQFblc KaGOU177Qyww9UK4GjhWfvaXcOCzfvFvRRRZl1SvL50WA7RPGs3QNPiH8PtNpK+hzkAl ZyONkLmrX0PKFHLznDmCLx8FJXsgYf+7bfGNXqvGOVsYXw0gwfv0FwUc1MrHj+gyltUa N/cyE2fYEwpAt/zHipR/VyvVzcUntXHdbR3Z+2jxKZjsCJv2st95kz/ex2f8YjVzcLCk HVDGz3WCnY27BjVyATcXTZkQmevlc5N3yXrLcKOEnML+bELFQkYK9M6/8s4wd8tVmQ7n +DCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686688475; x=1689280475; 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=WWKwNW1e3O9pZLa+y32ctA1ee6HTYoouSwcC3BybN+g=; b=eVBa567ANGvIL47pet+6+1Cv9Ku7vdbhnte33y9v/My1+rt4Tc3f9cUNmWYlv9tfSI 64/os27euqPw+YkrcgFNKaweOCOh+X4C5Cvusv0IqMLhPfagcbmkKnm2Pk35sIXvzn5Q tTFYtlL44U19M29cTzyowJg04Fd5YjR6oHxHHngs0sRmuDSbl8tJdRaXFePRbGvwWq9K iX/QyWQDAEU65XP3wGrHrLfUtFj+UW5a2X3WeukC1V4jcdr3P19WtTD2yIuZo61s7eZY UJxovmALjNmc9zgkRAB4kB+xxlgPtY+oWqFuHCiwC7VHEUVHVGyT9LepxdZnr0iA5bfI mUNg== X-Gm-Message-State: AC+VfDw5nOq1UCMKvcjX6UTGz2i5mkpea6JgyUFTqhApvm8ARMRm/Qgv FY0isjCjmpcHTKcpSGqwvAvrnA== X-Google-Smtp-Source: ACHHUZ7prTJM/cGdgP+zQZasvHAkCXCCG4a+f1mqLSPuOoGkDIe5m1jILBW1YnsOGQAb2JtZJSglTw== X-Received: by 2002:a19:ab01:0:b0:4f1:3bd7:e53a with SMTP id u1-20020a19ab01000000b004f13bd7e53amr6432996lfe.49.1686688474801; Tue, 13 Jun 2023 13:34:34 -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 l12-20020a19c20c000000b004f26f699e9dsm1897813lfc.184.2023.06.13.13.34.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Jun 2023 13:34:34 -0700 (PDT) From: Linus Walleij Date: Tue, 13 Jun 2023 22:34:26 +0200 Subject: [PATCH v4 10/10] mmc: mmci: Add busydetect timeout MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v4-10-df9c8c504353@linaro.org> References: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v4-0-df9c8c504353@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. Calculate the busy timeout unconditionally in mmci_start_command() using the code developed for STM32 and use this as a timeout for the command. This makes the eMMC work again on Skomer. Signed-off-by: Linus Walleij --- ChangeLog v3->v4: - Use the calculated command busy timeout from the core or the same calculated default as for STM32. ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 30 +++++++++++++++++++++++++++--- drivers/mmc/host/mmci.h | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 478f71dc7f34..12df1c231177 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -740,6 +741,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(host->cmd->busy_timeout)); } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); @@ -751,6 +754,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), @@ -1295,10 +1299,11 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) host->busy_status = 0; host->busy_state = MMCI_BUSY_DONE; - if (host->variant->busy_timeout && cmd->flags & MMC_RSP_BUSY) { - if (!cmd->busy_timeout) - cmd->busy_timeout = 10 * MSEC_PER_SEC; + /* Assign a default timeout if the core does not provide one */ + if (!cmd->busy_timeout) + cmd->busy_timeout = 10 * MSEC_PER_SEC; + if (host->variant->busy_timeout && cmd->flags & MMC_RSP_BUSY) { if (cmd->busy_timeout > host->mmc->max_busy_timeout) clks = (unsigned long long)host->mmc->max_busy_timeout * host->cclk; else @@ -1486,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); @@ -2299,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)