From patchwork Fri Jun 16 08:30: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: 693937 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 E3B3DEB64DA for ; Fri, 16 Jun 2023 08:30:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231469AbjFPIan (ORCPT ); Fri, 16 Jun 2023 04:30:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32950 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244545AbjFPIaj (ORCPT ); Fri, 16 Jun 2023 04:30:39 -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 25CE12D77 for ; Fri, 16 Jun 2023 01:30:38 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-4f6195d2b3fso482358e87.1 for ; Fri, 16 Jun 2023 01:30:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686904236; x=1689496236; 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=qAY1A0L5J452WPGRxo2jOeYk3l6HQDTQHokl5FBzRto=; b=TLXlhCuU302ifQfNQoGNRhJC8CZdyuaqtoALXuOD0e25eDoWqDmD/Hm7GrMB2U6RuU 43ZFqwdNHyl5blYFuUsU0PioZlXOFbTp1nzMPHS+uRGrlm4KZrdGRd5h8vxFXHgnc59/ FajLrU8zRg7HRmnmJifqmHFelmjJT0Kc+QbVOQ1geIela+/zEzI7Ix1vSA53P0F9slGR QPVrgEC3cNTARH11oCYogx3maZZwqRvlgT57Z8VDSK8GJAhiEMmIN5nF8Clx/nQff7fz 9NBsCdSHTSwPF0Mafwy7Y11Yy/lZstY/Y0bQRAWY1jIHkYjRETra/x6lj3S29wVupsGy /VLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686904236; x=1689496236; 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=qAY1A0L5J452WPGRxo2jOeYk3l6HQDTQHokl5FBzRto=; b=gEw9EtQv0KGudm5ieCPad7FcqG69VjBD9ABLUTxV4m8ULgwTWCzgL7t67/Gj3MfkxB QTvOqUHwdqh6ugfj4o/co/pMvwkTs09la0NrF7Eq3BvlJWGi2iYtC8rAkPS4ErjA4Qvr A3sHMUfyiXFStoeCH9edl34bMPeXzjzpE+S8yC2fjnTIaofFXFbWz8IDOfz3+t/ym+9R 7DgcDAFs6eKXQObrWKw6YoNBmoTfqKY4rkh+AIljc1dXxMojiAelKUObXFq0v9TSnh5S xAJzelS14c4dU+Y36J2ZKWwLHyHeYFjA76sI2IxCOeeVxB4TmR2X4T1Jb9z5MOAvz1t1 gvkw== X-Gm-Message-State: AC+VfDxd1VIP//43C2LbLc6W5UlGV5pkDE0HLfK8M9sThq2eGSn/984T Z5ZsAkmEQwD2kk2hhZ2bduzqqA== X-Google-Smtp-Source: ACHHUZ7BSgxJiY9sOkyLihVNLPsqyXx/q5hvthiq2DHxAnf55Cs1Sz0NyP2V6OPFvMmmxmRajzwqyQ== X-Received: by 2002:a19:441a:0:b0:4f5:bc19:68dd with SMTP id r26-20020a19441a000000b004f5bc1968ddmr737690lfa.53.1686904236383; Fri, 16 Jun 2023 01:30:36 -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 j8-20020ac25508000000b004eb44c2ab6bsm2918106lfk.294.2023.06.16.01.30.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 01:30:35 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 10:30:33 +0200 Subject: [PATCH v6 1/9] mmc: mmci: Clear busy_status when starting command MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v6-1-b850ec8019f3@linaro.org> References: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@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 v4->v6: - No changes. 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 Fri Jun 16 08:30: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: 693936 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 7E828EB64D7 for ; Fri, 16 Jun 2023 08:30:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245423AbjFPIan (ORCPT ); Fri, 16 Jun 2023 04:30:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242529AbjFPIak (ORCPT ); Fri, 16 Jun 2023 04:30:40 -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 106652D7B for ; Fri, 16 Jun 2023 01:30:39 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f841b7a697so466640e87.3 for ; Fri, 16 Jun 2023 01:30:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686904237; x=1689496237; 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=6ghF3xs3yQs3rXYpWsa33Muru521Sx+tCdBOCvTmZKM=; b=Y72Kg6S+HS9H/kKU98N2aG7RMxLkI5SqQER+/1E7WxjgHQQZJGIZlUiC5I1sdMNvJ0 LvVvYKGl5hvJvZ8rHILjpp/9C061rWu1HjH0QOUEEhCL664Qagll5+R8ZbraXz4L5OYB JJa9McOUT72+9ierH5xTtYa9EDpfeWDsWl3r2u/BON6KPVM7FtjZ8WqNZuofd6z3wEtA uZNFLCqKy54/0NJwHJ2M/WOWn7g9naoBh8rtOZ82AgBBQ/sqiVhoChgHTQXnGE1l+x91 FfVZH5UowipJBt9uw+CCMIy2MIu94JP07nsRM1v1qggJV/MzlsNo/37rvjDC/Ptv8NRy VCoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686904237; x=1689496237; 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=6ghF3xs3yQs3rXYpWsa33Muru521Sx+tCdBOCvTmZKM=; b=L6zexfmKccfMbLeEMeBsoSqetz3B/Y83pmVGo7kkOqk+mTNBRQaimYnBOKQNIVQtPn tfuWSAJrX7tVSGTT0brf5B0GNeRT3KMYJFz19XDkuJFEqde23yRFnC1dS291JKKoXJZt 8UbMl5c2PoLg2Ovjl0qJe28C1yVYEHe0RCninfDMmwkLnCPCoHnl0hDnNZBcMUpoIFj2 MuPxT957FC54nQATrp0WeL3gdbUOgdfbOLDD7pL6tZCXps5PO+Q5wHuoB2fL/fU7CSvh koQ9eDg7qHCe9y6K3y/7We/ccpWOtn53a/cUHiNd1xEGfU9zrzUnp7XM3Kdcn4Fqf6KA f8Kg== X-Gm-Message-State: AC+VfDxzMhah95mt1Jx88IK5OlFQeFu0y5zh7Y+4+lUmkUST8Qyfq/O4 Mhiwfz49spWPWUFm8Ivo6mnYpg== X-Google-Smtp-Source: ACHHUZ62k2noxCvM8fqALPVmY/PVnzzSyFYRFFqiq3iaxrSKtVg/R2icMjX1lNvG3js9VO32t+lVuQ== X-Received: by 2002:a05:6512:2f4:b0:4f8:582e:f4f2 with SMTP id m20-20020a05651202f400b004f8582ef4f2mr369827lfq.47.1686904237351; Fri, 16 Jun 2023 01:30:37 -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 j8-20020ac25508000000b004eb44c2ab6bsm2918106lfk.294.2023.06.16.01.30.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 01:30:36 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 10:30:34 +0200 Subject: [PATCH v6 2/9] mmc: mmci: Unwind big if() clause MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v6-2-b850ec8019f3@linaro.org> References: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@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 v4->v6: - No changes. 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 Fri Jun 16 08:30: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: 693499 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 31FFCEB64DD for ; Fri, 16 Jun 2023 08:30:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242529AbjFPIap (ORCPT ); Fri, 16 Jun 2023 04:30:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245214AbjFPIal (ORCPT ); Fri, 16 Jun 2023 04:30:41 -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 1713F2D6A for ; Fri, 16 Jun 2023 01:30:40 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4f655293a38so504941e87.0 for ; Fri, 16 Jun 2023 01:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686904238; x=1689496238; 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=eDWfJmNzbQmAA05jmoYd7JfIZxnwDGKXAdDTLkWtQe8=; b=rnRES/KizDc5sZNv1sxzWYXABFokGf5WfqZ4Z5QCzoPAkNGS0PZiGzBnvfszK0qSDz pKiLL6uDm8yoxCHV90drVHHsVJvv1m+P8hVYxgSH86akSYG6YEuut2qeGuzi64gXpznu gsBv8sOMLCbx90Wp4ymOh+dR1CkdLpQiauu1YYljK56vJxymqT05vMpvaOGG8S3GpfIt lwWtiwevyOQiwKvcOpNFMNBobd3H5sCOaN+IdnYkvgj3GRviThDF8/dEIrEdr25uYRvR I0dpQzO9QzYKTm3eWAguadGptMGdWDetd6RzDCKw+iufED5MozIv8yTiA5fwM9QPRRrw scFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686904238; x=1689496238; 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=eDWfJmNzbQmAA05jmoYd7JfIZxnwDGKXAdDTLkWtQe8=; b=hXxx6H8uzask7DqmHF6DpSS3gtKEX6i9uLxu+C7aT1A/7KPbKd+kFrz+EPCPRn8Iyh AUec/31sy+2TGa4REdFNDcMXVxDcnEmyRpM6pmfrCq3Xbiz37c33NEkTDOKOCb2rjZYt iDUZI95T94G4pFzBQy3D+twWPdCr9CKJ8URmyL9ZCXJFyIUY2FxfjBZNFKuM9xdFowFX 3njqTKY/PXcg5VSfKnn7qR51LHHxugAHbRiiEgCyhzcpM7q5rAjGlEcPfbY7XnVtAZlR qRmpkW19EP0ziZQeWPgRtw/XFrBvFSeOlZnBHxwQeiz1Qovlus1nWkBsruWfG4rB+mHp q3nw== X-Gm-Message-State: AC+VfDw2beYE7I0VwHBd8LYw+mlrfE+JmaGXEF80o76POiRG/vLyTIr+ gLv0lWB2YxacjguvohP3Dci11w== X-Google-Smtp-Source: ACHHUZ43n6Onh9gPaHpBFHKAz+4wBfXNSaEw9klHW3mmZGfZx9mivm/Sm/i5wD68dFDsVnhL8xibtw== X-Received: by 2002:a19:ca50:0:b0:4f8:578f:ace1 with SMTP id h16-20020a19ca50000000b004f8578face1mr367985lfj.21.1686904238280; Fri, 16 Jun 2023 01:30:38 -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 j8-20020ac25508000000b004eb44c2ab6bsm2918106lfk.294.2023.06.16.01.30.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 01:30:37 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 10:30:35 +0200 Subject: [PATCH v6 3/9] mmc: mmci: Stash status while waiting for busy MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v6-3-b850ec8019f3@linaro.org> References: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@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 v4->v6: - No changes. 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 Fri Jun 16 08:30: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: 693935 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 09C6DEB64D8 for ; Fri, 16 Jun 2023 08:30:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244209AbjFPIaq (ORCPT ); Fri, 16 Jun 2023 04:30:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245279AbjFPIal (ORCPT ); Fri, 16 Jun 2023 04:30:41 -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 C60852D72 for ; Fri, 16 Jun 2023 01:30:40 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f74cda5f1dso486371e87.3 for ; Fri, 16 Jun 2023 01:30:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686904239; x=1689496239; 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=Uv8R+uMF6WnTLu76PBd8GfNWo7ysNcJe7YfGwPaXEWU=; b=QoYP48KAf3RwPJaEbejINyEVXQe7cKnpoIbr3A/hnMCCMoYsiPPzr34sjjP0neYCwH yztC+OkJcv7XglNtZ3vuKiPF4UgP8lDqbkbXK4ZXJPfp8QobefMk88MHkDnYJ+kfhULA SildRRCvlMmq57C/kKm5soyFYzcy8M6kBIe5AO0JOZo0+JHncK+y0Y2l7qr3Cd+cfyEg cJdWwxPxeqMiee1sK7nX1Dte8f7s+cF2zLr9uCDTVQRpquRBiUJ72/1czfr7Qenjylhs ommaDHYiNQRb/GBQ4m2llhGrveYQJebrKctJcgQAr1TJsNBvW1HN536U81CvPH9D0FSr mBDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686904239; x=1689496239; 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=Uv8R+uMF6WnTLu76PBd8GfNWo7ysNcJe7YfGwPaXEWU=; b=RwS7mywn9xkMgOPMq2KYzmmShVfBQzLiVNxLJqgvpCc/pjqIEuWdvi9404QnppADyR 7uT0PqwKx6vLai6y2/rzqahJz2psNMNcdRnEZGVoSB4tnIAPriOPXWFhWNzaiStdtflg EhLkHM+jjphOPJ5BVvrhzgU2ytOEyaRBIswQYjg943oALcvoR1k527elmugmlLl9lHtu pEyadUlJMa94Stu9VajEpLNMZzZ58QMexdmPhDYpJEerLaPq2+1z+wj2yhwu0Iz/pLAp IlQeWTi7Wh/NkFR+oqEVpaGLNF5ZdxwWM0uStzLDmTay4ry9gUclJLSyiBabezM0cWiq C9gw== X-Gm-Message-State: AC+VfDxsriJhhnrVVvVe6Vewn9YxzCngA3whKx9cAcI4U6ooXwemi9t8 IQaarTcJuZCPqH7LxVUQyuwd8Q== X-Google-Smtp-Source: ACHHUZ5WHQjxkZY8dwst0quP+F94G7KA9eK2YAo0+wbrOxLBa2XdWWcG+cXXHZRKkCqcPoOzO+fZXg== X-Received: by 2002:a19:4f1c:0:b0:4f7:6454:655d with SMTP id d28-20020a194f1c000000b004f76454655dmr690211lfb.0.1686904239036; Fri, 16 Jun 2023 01:30:39 -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 j8-20020ac25508000000b004eb44c2ab6bsm2918106lfk.294.2023.06.16.01.30.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 01:30:38 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 10:30:36 +0200 Subject: [PATCH v6 4/9] mmc: mmci: Break out error check in busy detect MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v6-4-b850ec8019f3@linaro.org> References: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@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 v4->v6: - No changes. 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 Fri Jun 16 08:30:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 693498 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 492D7EB64DA for ; Fri, 16 Jun 2023 08:30:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245405AbjFPIap (ORCPT ); Fri, 16 Jun 2023 04:30:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244566AbjFPIan (ORCPT ); Fri, 16 Jun 2023 04:30:43 -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 92AC12D77 for ; Fri, 16 Jun 2023 01:30:41 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f762b3227dso651973e87.1 for ; Fri, 16 Jun 2023 01:30:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686904240; x=1689496240; 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=mHs5jC6hJCi4aT4wPnCdwjt7mkInY7nwzFZM2gLulD4=; b=ynsLHqnpgy13jMtJKM6Vk5xR9+KqeO05n8sXxSGpHgQQ9Z2blErKc5STg5GABg8AD5 gZcjgWToPH5GMb6+94ml9VzJpTUCLvK9fWc9V3FJT72EpFJBVWQ4BGP++kSVMUb5T8e4 b5TP3RKw5AroJquqnj5/tdpzvGwZKaStjLDp3gSvcXRzE8joDmzISGcC8SASkTCg6+AC PEqhNZpQIyjuSuFLZFAZjfxaK2BElgNyo79XK8mFO0Tnai2LKTHeqLLfGXy+tGgMV13X UGc3ek8JRTE/A9yo0LB0zCA4xzFWupBK4xppoMdJpsDrvwrIp7PboWQrmMIJvMppxdpJ 25kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686904240; x=1689496240; 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=mHs5jC6hJCi4aT4wPnCdwjt7mkInY7nwzFZM2gLulD4=; b=Oi2vgQDl+UzJywDdvHqGYd0gqYzBWUyxjGU7bvXgEBNl3shaQd0nchT8cKt4r7Yufb c2+imXZeS7YflYb/abnjd5ZN4BUhccaZYBFzAdO5UCXdSoiwTIFdSFE0vLrglm6AMIei zR7LGDyosrH/mObo6tvhesqVwTExhJshdyQ3f1YJrm+BUJ8ZV2HdfrUhslwggjk6gzLz 5p2IyNrJMEFl17sqFFrN1l8XBxrD86F57sNvd+RBZU1oS6sbIg04YX5icYEWKDOTTGxI 1n4dGXIQst71VGTNbdOS9lDTYuH8fbMa7y6nFQV/XR3wl7vofyHx11RL9iy2JUHCfSms dTgA== X-Gm-Message-State: AC+VfDx6waciPlCA4gDlx8Mcbpdsojdf7aUseza42+DA7NkIvHTbBAWP 9Y8vVA0PYlUT4J6q09F34G+u3g== X-Google-Smtp-Source: ACHHUZ4MHYzVMNSKCKXAWaVJad9rh/dJZZkScBJ77tvpo+XXdhgV2hnRSI8nQCG5Yw6/wZFUlnaNNw== X-Received: by 2002:a19:6758:0:b0:4f8:5498:17a9 with SMTP id e24-20020a196758000000b004f8549817a9mr288698lfj.5.1686904239887; Fri, 16 Jun 2023 01:30:39 -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 j8-20020ac25508000000b004eb44c2ab6bsm2918106lfk.294.2023.06.16.01.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 01:30:39 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 10:30:37 +0200 Subject: [PATCH v6 5/9] mmc: mmci: Make busy complete state machine explicit MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v6-5-b850ec8019f3@linaro.org> References: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@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 v4->v6: - When waiting for the busy end IRQ, what we expect is that the IRQ should trigger right after the busy signal ends, and thus thes busy indication should be de-asserted (low). We invert the logic such that this is what we expect, and the error case is if the busy detect status is still high when we get the busy end IRQ. 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..ccfca055f9a1 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); + host->busy_state = MMCI_BUSY_DONE; + return false; + } else { + dev_dbg(mmc_dev(host->mmc), + "busy status still asserted when handling busy end IRQ\n"); + /* Force clear the spurious IRQ */ + 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 Fri Jun 16 08:30:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 693934 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 F3444EB64D7 for ; Fri, 16 Jun 2023 08:30:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245115AbjFPIar (ORCPT ); Fri, 16 Jun 2023 04:30:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245419AbjFPIan (ORCPT ); Fri, 16 Jun 2023 04:30:43 -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 567972D7F for ; Fri, 16 Jun 2023 01:30:42 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f762b3227dso651989e87.1 for ; Fri, 16 Jun 2023 01:30:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686904240; x=1689496240; 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=cWdIfBnqggtpxe/X8Z+ZH/SZJCqCCQqCNdgmsOsdMhQ=; b=qmOTDNzkugpHumXZcoh3VoKKpvZrpMUikuhc3B4jPLE7z7gO+TTBIY05aggGcO54xQ wU3QICVn/5gNcAFjEP4j0pjO+yWxrP2ty0CHUqxR0lc4N+xKdeWHGmY9c8XdWWSvqlUD rIlDwRSLQWkULjK17eeUlLBYn6n7bIuBi4WzBH6+G6e5V7S0FEDGZp/GCiIU1WXomPXy lvhEFZFw1tyUw8DFrDZGAUbYmL25lOP8ONPgPq1gT7EiH3EobN31sF5FVFtJTRgpTnCy dASrK/+1dslsV9ZY7Lwyhshts/b9M6oLKwCt3v8XEykgjfZa/dZW0NtXvCHY3i4m2Eek xwEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686904240; x=1689496240; 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=cWdIfBnqggtpxe/X8Z+ZH/SZJCqCCQqCNdgmsOsdMhQ=; b=Jw/dQj0qQ3WlRWEcfb+mQhvAK/K3XSkTOIQvgz2CeO5r8dFu7BR3adiQbRTUiXqKy/ prxH+IWwhs6huKDRqZ0hqcM2NX3UDMLVx0fjW+qjN04jA8J6FvU5RbebeuHCVc7kxe4a VYaEtIn6rzaBlJ+JT3fhkOw+HYczPiY5zqwk0VrapjibB6Y/GhQoBHfJSKxODjYcPjXf tMvxrBxUvut5Tq01XdbWimzttWUUnMBUGRd5ZGt2ePbarMRkMnyY3g+OkwOhXuEikScM AIXOmDtC6HZXnttrj1dAmRigM4ykZg7q9Bd8bx/IF3GrflfGjecfyDxWNUwTA+R2XXF6 9RNg== X-Gm-Message-State: AC+VfDwGrtUr2owGX2dlbgoYHpmh3KRFLJfIrngbWfb6E8s1G4lzSpEu inHhff5o/tFwdJtcsrjWc7UWBA== X-Google-Smtp-Source: ACHHUZ7PjDest9LjXsbK3niqA/tyRClWCXZwHuonUF6zUKXU4gYd6oXf3Sg3iFzSyuX3rHGdiFJTbQ== X-Received: by 2002:a19:6910:0:b0:4f6:43ac:d28d with SMTP id e16-20020a196910000000b004f643acd28dmr346466lfc.33.1686904240696; Fri, 16 Jun 2023 01:30:40 -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 j8-20020ac25508000000b004eb44c2ab6bsm2918106lfk.294.2023.06.16.01.30.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 01:30:40 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 10:30:38 +0200 Subject: [PATCH v6 6/9] mmc: mmci: Retry the busy start condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v6-6-b850ec8019f3@linaro.org> References: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@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 v4->v6: - No changes. 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 ccfca055f9a1..6ae56c973b0d 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 Fri Jun 16 08:30:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 693497 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 A4161EB64DB for ; Fri, 16 Jun 2023 08:30:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233268AbjFPIas (ORCPT ); Fri, 16 Jun 2023 04:30:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242847AbjFPIap (ORCPT ); Fri, 16 Jun 2023 04:30:45 -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 5F3102966 for ; Fri, 16 Jun 2023 01:30:43 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f640e48bc3so492888e87.2 for ; Fri, 16 Jun 2023 01:30:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686904241; x=1689496241; 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=AKBnKIdK2CO+P/WwZHo2AYQY3pe5441V6fpY4p0irEc=; b=rK4mZCX/IjZuLgF8DNqx1Su73VwpJdM0o0SzCj50IzO4/6TsEcJHwanPqvaMP8Ldcb zw+HivJZThGGPCh9dAW3zNu8Nfopj38bxnvpNvhBGo/Vzvg2hmyHZVQI9+ybocZXwIdj EyxYjrZDWuRLMiuQIRDXFRkraIVC8Euo+0buQ7MPgaDo6Tob4b7tODOhzqEvmzYZnjHy vjPIKqquUl77LAzsxMuSJZwVcRnIf6gfcayvek5y80lzfnBr+gYjwoHWficJOPt0/dZ7 m6R+e5a4/ptMecSECvjhXTTuKhlDsCL+NN5YRtp3koLs9nJ93U3/4/MbfZNo48F8IfE5 FJ5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686904241; x=1689496241; 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=AKBnKIdK2CO+P/WwZHo2AYQY3pe5441V6fpY4p0irEc=; b=KlHuB0sHyEX/+5DPKLxkI9Cmnkgx7QG1pnVtGVkWdsgPX+M9uio6kJpqK02cVeJbvc 07ccfkB8rDAchLde5DfV29mqw5knLBd8LR5+OeBaIZrh00w8UrHgRRx6kaefuYUKnM6t sIz+LAGngEbHwdpgDo7vrCReRwgFaYkqkYyeYbhHxIELsJoRt6kXLqLg4QQYCthpx75K IRICiaZHeEyCzjU8gnhEV2KuG+eBRAqMd8R9PJFqv32rh7zMoa5EWb8jmoPUwOK5kbjS xGYOTS3T2HrU5pIYE6zy2kb3tOcJ3esS0K2juwRS+eQM10SVI/rcmR+0g7sUNP8Y6ba4 nnrg== X-Gm-Message-State: AC+VfDxwT6R6ycx38pRt2uhCM26FtVcVk8+cJl8cNsr/MqSW2Eohu6Au ElB9m/W5ldJCKO+ND7oMil+FFg== X-Google-Smtp-Source: ACHHUZ69GNE4ZOqc3XtliTEHCTLTnYoMy/Zbi656rhwXpt06TURFYrcxTdKki18tWOPEX1/NdQoXRg== X-Received: by 2002:ac2:5b08:0:b0:4f7:4f30:1532 with SMTP id v8-20020ac25b08000000b004f74f301532mr727845lfn.31.1686904241687; Fri, 16 Jun 2023 01:30: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 j8-20020ac25508000000b004eb44c2ab6bsm2918106lfk.294.2023.06.16.01.30.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 01:30:41 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 10:30:39 +0200 Subject: [PATCH v6 7/9] mmc: mmci: Use state machine state as exit condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v6-7-b850ec8019f3@linaro.org> References: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@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 v4->v6: - No changes. 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 6ae56c973b0d..437b2144ecd4 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; } } @@ -749,7 +748,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); host->busy_state = MMCI_BUSY_DONE; - return false; + goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "busy status still asserted when handling 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 Fri Jun 16 08:30:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 693933 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 56B6BEB64D8 for ; Fri, 16 Jun 2023 08:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242847AbjFPIat (ORCPT ); Fri, 16 Jun 2023 04:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245274AbjFPIap (ORCPT ); Fri, 16 Jun 2023 04:30:45 -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 22A6F30C6 for ; Fri, 16 Jun 2023 01:30:44 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f655293a38so505023e87.0 for ; Fri, 16 Jun 2023 01:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686904242; x=1689496242; 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=VIAYT4EhNtooRN/YpBr1IWKLrfpKpu0Ay5MDZbIHZMY=; b=IAeb2948KGs6CDAVxiBSy3g+HWmJ1nE/JB8ILamXBsDnNU2xytjnjn+btSFEjG5IWm zKn27oHP5ielDEfuvSrFW9vZR8fMzwssSY2nxp02U0ryHDJZbdg1YoxlEpinvW0GAWtP E14TDsqbEd3eyhEOhKzFsNbogLSAaICsBNGZsLkOFwrfDLiwFZIqmSUMK3hRxnXr6snz Om+d7nos3XNsEyopvqluXDzqz9Id0FvrUZ5nLpsg2dNcJ/5nlCsKY/G3jAbX56ivttnr i017MSRbWWLuboaVJIkdzEgaS54gJNEcyc+RXAidqZY4Fm241fXIoaerlvbAK8Pqs29N I2KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686904242; x=1689496242; 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=VIAYT4EhNtooRN/YpBr1IWKLrfpKpu0Ay5MDZbIHZMY=; b=GEoFxemw6c0mHwuzS6YJXqdms+ytH5uSGhjOBKlUp0SoBk5eXbz+IrsfO6AjWNRLg3 7YO9z+OoiymeQvWlH7PPwmd1tpPw6n5EdwUacMitHYTYvcW0q6QqyvZ0xrRhOxWVkqvg 6tEhoIf7B98dtu/1IEfkG6sZTwuJzpneRgidK28Mxq9gh6R7HuXKcm3qkgj+dIbYMW8Q zgPC01vPHEVP6xmBHT0HB6kqt5fQre5tU951o24pu/viqFU3JGUWFM1nkzhzYNzuWdvS ZJApCWjcdyr5IaxMONQ2P2AZyzJ7Ymxw9hTxGQ7MtKLlx2nWTqkSyeUOuHynd8WAAviF 0DTw== X-Gm-Message-State: AC+VfDznzFlvIpHevqsEFNEPHHSh9l/e/ZDpP2gpY3p09vsdvnSZrets 9rou6fobz9t71zERrRyEodQK3A== X-Google-Smtp-Source: ACHHUZ7rIHaAlGRnwQv12z82K3cMuxWAUUScNh5plFCiBswWEM+Pw4JL281Q7AwruztwWncE/VaEtw== X-Received: by 2002:a05:6512:329b:b0:4f6:2cd8:5ffe with SMTP id p27-20020a056512329b00b004f62cd85ffemr748562lfe.1.1686904242507; Fri, 16 Jun 2023 01:30: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 j8-20020ac25508000000b004eb44c2ab6bsm2918106lfk.294.2023.06.16.01.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 01:30:42 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 10:30:40 +0200 Subject: [PATCH v6 8/9] mmc: mmci: Use a switch statement machine MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v6-8-b850ec8019f3@linaro.org> References: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@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 v4->v6: - No changes. 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 437b2144ecd4..f7522c3fe849 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,15 +744,13 @@ 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); host->busy_state = MMCI_BUSY_DONE; - goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "busy status still asserted when handling 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 Fri Jun 16 08:30:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 693496 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 35E1DEB64DC for ; Fri, 16 Jun 2023 08:30:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240464AbjFPIau (ORCPT ); Fri, 16 Jun 2023 04:30:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241806AbjFPIaq (ORCPT ); Fri, 16 Jun 2023 04:30:46 -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 0B95C2D72 for ; Fri, 16 Jun 2023 01:30:45 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f64fb05a8aso533558e87.0 for ; Fri, 16 Jun 2023 01:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686904243; x=1689496243; 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=TKSfFjErQqrA4N+AgDBWwU9EqGS/Y9GhjAuAbiYkf/A=; b=lJp1deBjvOtAoLHVmyF8tziPljobz5sX4gqcf3XUrQaXYLZ+n+XtL1QeG7OAk7Ay9O M9iB6WKFlxeDpwkiRU11vP2bjvU/nSrVziTEBCYVLO3itjrdN5K/aCRO4upNardE2xds pm8BWc4LlGPs0O0SavCx9TURPStpvTStdqhrsf7GUFbKppPp/QcUtIryAzrFjdZAiHxv FUmPjwwPgKgwL2AaDGNNMstB1QEF58Y/GY8mWd9h13D97hyny1sCKAQvwTVdp1PnOuiv WubAXxfGfkdxb2Dd4U82vu+rviH35CUaG6r4kqUkpv6BpeYK5kOe88an/faQSwYy5Vg7 yCwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686904243; x=1689496243; 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=TKSfFjErQqrA4N+AgDBWwU9EqGS/Y9GhjAuAbiYkf/A=; b=hZF5EUUfPabKzcBZYzGDtvtFpowvpV7RoGBPQ6FxbiPk7zwBXdvV8/9CErjhnMzbP4 w9pSVnesqRDJ9SDTNJ+pAnuilPIeW8RSbedzgNVc/7k6gsAQXRXs5CSJrW5gFaBpMtv5 4tIKE+hOO4hsEmwK3h4c20qaj/0EtAnzRxJe7N6nZ/1mXqZ3zEiMNfqu2vJsmPjkIrl7 tFutz2BdL1n2gREN68uxRV4/SiAHHv/wCtU2AJ/ESPS4qOq2VbC9bKCmIWpGEqbArZH3 MScJQOs5BgBQu+kj6enbOF2x7Cqs1/yFS4+FPLQwZW0xzGHzvARfRLaHwpSVgvraDxCc Nopg== X-Gm-Message-State: AC+VfDw1cIAKQctTJpfOMILbE9ivxE0OuPyd6SW7h7kLhfpFazxq9zmc ap2ZpXrmE/hg26NJRJLIP5dbqQ== X-Google-Smtp-Source: ACHHUZ78mZiFnu3XwZGmaHeF12C0NqYoXkJ5x9w6amIE0Fv0MQnjxaaBVgSQLpQTBJRfgqzbBd9qzw== X-Received: by 2002:a19:500d:0:b0:4f6:20b1:ef81 with SMTP id e13-20020a19500d000000b004f620b1ef81mr811165lfb.36.1686904243379; Fri, 16 Jun 2023 01:30: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 j8-20020ac25508000000b004eb44c2ab6bsm2918106lfk.294.2023.06.16.01.30.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 01:30:42 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 10:30:41 +0200 Subject: [PATCH v6 9/9] mmc: mmci: Break out a helper function MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v6-9-b850ec8019f3@linaro.org> References: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@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 v4->v6: - No changes. ChangeLog v3->v4: - No changes. ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index f7522c3fe849..a08d96918cae 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,27 +743,20 @@ 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; case MMCI_BUSY_WAITING_FOR_END_IRQ: if (!(status & host->variant->busy_detect_flag)) { host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); - host->busy_state = MMCI_BUSY_DONE; + writel(host->variant->busy_detect_mask, base + MMCICLEAR); + ux500_busy_clear_mask_done(host); } else { dev_dbg(mmc_dev(host->mmc), "busy status still asserted when handling busy end IRQ\n"); /* Force clear the spurious IRQ */ - 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;