From patchwork Sat Apr 8 22:00: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: 672013 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 CFF3EC77B61 for ; Sat, 8 Apr 2023 22:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229452AbjDHWAk (ORCPT ); Sat, 8 Apr 2023 18:00:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229445AbjDHWAi (ORCPT ); Sat, 8 Apr 2023 18:00:38 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B85D4558A for ; Sat, 8 Apr 2023 15:00:36 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id z8so4100852lfb.12 for ; Sat, 08 Apr 2023 15:00:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991235; 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=Lw3XG8iQC5gX8Uhau9KwDjMohP4XjFt98wfUm6sYpak=; b=Jr+zCxPVmuN7u4WW0VprumqpO+7exh+l2L9UIvs1dUFOOCJKfeDvUS5yAUMg1QEDbb /A2iAz3VS+nE9jZSOzuAVl4qLiQfMbIU45pNx3rZ1rqzUPL+z+kNlCfhP8Art1t03UP3 kaihr2lWbL/SKEyKTDpH7oPkQny6k83Gg/zNocJ1z9gISwHWnfhkuuFV+K2OWq9k1bUq n4UjFnrmKdltwmfp6lle9eX/e1NqZZ6dZH/QN1tbeF7LdfrrgiFi5gtPl+t5dEEWYzLJ L38TSdLnMAaivCzEz7kRfrsX1rjRNG6n+v+uAJb/UT6uMCKR04dNg8sbzZwZDZuwewo+ rWGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991235; 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=Lw3XG8iQC5gX8Uhau9KwDjMohP4XjFt98wfUm6sYpak=; b=2w6gqhno2iyDp4TYw9VXEBD7NinR6iwA0d1fp4+6iV1B+BpLetGvODH5pPaiOYXkIW kfkgCd8Jq7JGnQXtqvn/gcnxgCKmOG0/pfY5HmIEfUo9i6S5FaAJFdlKFdPWV6ePkR0o IJyuw6XDwM4OdBc9i/G1AyiVG24sp5xYvV/tWP0AymbyyTG6LcI31W1BMC2kQgrIGpTR o0jMnOJwTGDWlv+fp4BygkaBRUn/glbt0q5cZmA0JpiLgl4av5DYri7HVFiHOx+ZUtR1 nn0aMhpxRw8JJNwGhoLw4KmwxSpJ+EaBxMvUBNQpTthPgcGY+lFWGx4G5HY2lljK8oUY ap3g== X-Gm-Message-State: AAQBX9eBwStELZjiJREq3a05BjaEv+9S3FDgcYNu8Oxm8cYOjKjFUef1 qlaKVMAa0Joq8c1vm8OT7EG6VQ== X-Google-Smtp-Source: AKy350Y9kOlYLM2ZeuRBQ6/s7P5O+DOglnhe/y95JUOU6D8fllrRE/bjLDxQz2noH/HlTJqP2ClHDg== X-Received: by 2002:ac2:547b:0:b0:4d8:82d5:f5bc with SMTP id e27-20020ac2547b000000b004d882d5f5bcmr811710lfn.34.1680991235145; Sat, 08 Apr 2023 15:00:35 -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 v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:34 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:22 +0200 Subject: [PATCH v2 01/12] mmc: mmci: Clear busy_status when starting command MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-1-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 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 v1->v2: - Unconditionally clear host->busy_status if we get a busy response. --- drivers/mmc/host/mmci.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index b9e5dfe74e5c..9b48df842425 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1238,17 +1238,21 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) c |= host->variant->cmdreg_srsp; } - if (host->variant->busy_timeout && cmd->flags & MMC_RSP_BUSY) { - if (!cmd->busy_timeout) - cmd->busy_timeout = 10 * MSEC_PER_SEC; + if (cmd->flags & MMC_RSP_BUSY) { + host->busy_status = 0; - if (cmd->busy_timeout > host->mmc->max_busy_timeout) - clks = (unsigned long long)host->mmc->max_busy_timeout * host->cclk; - else - clks = (unsigned long long)cmd->busy_timeout * host->cclk; + if (host->variant->busy_timeout) { + if (!cmd->busy_timeout) + cmd->busy_timeout = 10 * MSEC_PER_SEC; - do_div(clks, MSEC_PER_SEC); - writel_relaxed(clks, host->base + MMCIDATATIMER); + if (cmd->busy_timeout > host->mmc->max_busy_timeout) + clks = (unsigned long long)host->mmc->max_busy_timeout * host->cclk; + else + clks = (unsigned long long)cmd->busy_timeout * host->cclk; + + do_div(clks, MSEC_PER_SEC); + writel_relaxed(clks, host->base + MMCIDATATIMER); + } } if (host->ops->pre_sig_volt_switch && cmd->opcode == SD_SWITCH_VOLTAGE) From patchwork Sat Apr 8 22:00: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: 671848 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 F3D98C77B6C for ; Sat, 8 Apr 2023 22:00:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229495AbjDHWAk (ORCPT ); Sat, 8 Apr 2023 18:00:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjDHWAj (ORCPT ); Sat, 8 Apr 2023 18:00: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 BFA9455A1 for ; Sat, 8 Apr 2023 15:00:37 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id t20so2261760lfd.5 for ; Sat, 08 Apr 2023 15:00:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991236; 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=5nydUHwsIwjtIyju2PPVdWDGkaHFsBAEFCxHgjn6c38=; b=o7QDfJtBk3tXHOEoou4q9FOBDB1hNBSTcVIuhUOc2NYgNXlxNOzU8NTQHmzhyBOxs/ Hc72lhgqMXu/6SfdhFCIto4XGOCM0zcEirTLVbSPJvAv9dj9aWPfgGca2iisGXTa+Bwz qE9VXB25fsIi/xExwkKa+dELWqgr+1cbh5yWp0nD+OvI2T5c+LWbnl+WaoUy1rgarsBS OXOGzt8kFNU/LcaY7RnDqoZaYMU9StEsAwH29gOClQY4SfjRFOkTJrpivIRadwvVwHAw s4++l06b6jMkA569csDPQQfDYdNkU5iPj40V7Zmruno48fTDa1zFTJaIKhrngl7i9nBP 6img== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991236; 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=5nydUHwsIwjtIyju2PPVdWDGkaHFsBAEFCxHgjn6c38=; b=6AawZfU7B32crzP1PPrrHQrXvAzRWw0SQCR9JSYyLWUsM0Zw2CHIzGNeDdMNMhTh+b KcJY0MEDZyQTaSdJC6Dw6OkTU/ZZ2YNwi7o9lZIhjal5mKTL7dWmAd3NsStmVrwVPoI5 2F1RtlCEW738XQvtDWxW+XlxCRSayCEMeHnGANT0AL4V7q181RFfLldRQAVu5RzLxIRn 9sXShYhD/XPbDrmWW8w9VNCt2lPfPWVHF4KW5Q1QssDfn88+kNSa02TYbw8XfJ8CtPfP LTDwQC3VLdQdT6CR1LP/ZSm5xPCOsQevE8UJHLySqpSbCuiJvxqmKVAvih5vahlEZuvP +oFw== X-Gm-Message-State: AAQBX9eDHWdhJQT+T1faWo0qACjO+DIvT6x+VBodU8crkbXkhCzksHx+ awTlohrbGgwiyLQEmV+WFPQ+Hg== X-Google-Smtp-Source: AKy350azw0lQFoJtbHGZb4b39JvnxqRzxzCjAtZiWUW4js1hCbiF1B1tHHNT7s5to9J8iBxLTeOcWQ== X-Received: by 2002:ac2:4d11:0:b0:4db:25f2:c116 with SMTP id r17-20020ac24d11000000b004db25f2c116mr2068158lfi.18.1680991236063; Sat, 08 Apr 2023 15:00: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 v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:35 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:23 +0200 Subject: [PATCH v2 02/12] mmc: mmci: Unwind big if() clause MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-2-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 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 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 9b48df842425..8496df2020d9 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 Sat Apr 8 22:00: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: 671849 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 95A42C77B70 for ; Sat, 8 Apr 2023 22:00:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229445AbjDHWAl (ORCPT ); Sat, 8 Apr 2023 18:00:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjDHWAj (ORCPT ); Sat, 8 Apr 2023 18:00: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 A411955BF for ; Sat, 8 Apr 2023 15:00:38 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id h11so51424564lfu.8 for ; Sat, 08 Apr 2023 15:00:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991237; 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=eL2tfczN7su2jHUV2L3L9PcxI+ycYQtmblvqUdrfgmI=; b=sbCZRGtj0pBtvuBE5qNrrAagA41l80nwBDTq9ERbV6uofvc9xMva7TzDVOiDm0nJBG UpgBWOg4DpEZc0LdhmVOtrp7/GNV/52R1jgnUp9KtAWAruqmkuOhDrGJFUBZ105Xe8ia aVysJEU5LxZSZ7sjfCyRrNi+7riA35fQTFZ3mEsnwTrXWk1QPExdyYpWdRVJT+wuU3Wa geBtzI7TYoIthWk+pZfr0Zh4I4scxVMC7zx4PSqHyb1Yr3NCrkwYplOtjRN8qDqVlmyN 71rEgtepq666wLQ7NInidKflpds+sqHV8DPxt9Rw70Kn2IvMWh/OpTUt494kJxkShVPx pdxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991237; 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=eL2tfczN7su2jHUV2L3L9PcxI+ycYQtmblvqUdrfgmI=; b=pbf/S2L0pQLLbKYfeRTXsQ5EwgdlWHW5HngTTU6iQjdtFX25VckSLo/ypu73zk/TAI YZt/Z3iVESbUDvH7Hg31t6YAq/RmmRbCvzITPbkFuxkV0aJnVgMBvuTFc1w8tcbMTd7u KKpwSzQMDYf9kw3PB8Sc8eLahDEhKhiJn5D6ZOg3JEurjVzKAovQRnngGQea4EuVKlJ9 bRPriS1ukvtEtCbWnzsuNCiKwkyIJokzPiN7UMdmYUHioOndMTykrYH5axNKnlxqUV4J izJq9wwxFLNSw+8chaLI/XcUTdLgRF1ynO+MzKWbYIWnge2hQG8oSvG4gRHq8JO30fPY ps/A== X-Gm-Message-State: AAQBX9eeb7FzlMTbajK61d/WrIjGpxvMpFx8bz/aeiSctjKE8Y2sB9I7 0svX96q2Z5WI+plx/S2GzZ8nyk2U1TdHnsdiQBo= X-Google-Smtp-Source: AKy350bdedttz8LNGHVTqRJZTPzHsZh/f5b5PazxcSTopf17Qg+1MOLB28Li27oAmDRNouCVlW0O5Q== X-Received: by 2002:a19:c206:0:b0:4eb:30f9:eed7 with SMTP id l6-20020a19c206000000b004eb30f9eed7mr1630557lfc.22.1680991236968; Sat, 08 Apr 2023 15:00: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 v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:36 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:24 +0200 Subject: [PATCH v2 03/12] mmc: mmci: Stash status while waiting for busy MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-3-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 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 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 8496df2020d9..e742dedaca1a 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 Sat Apr 8 22:00: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: 672010 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 7529BC7619A for ; Sat, 8 Apr 2023 22:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229525AbjDHWAq (ORCPT ); Sat, 8 Apr 2023 18:00:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjDHWAo (ORCPT ); Sat, 8 Apr 2023 18:00:44 -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 90DFD5271 for ; Sat, 8 Apr 2023 15:00:39 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id m4so2112121lfj.13 for ; Sat, 08 Apr 2023 15:00:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991238; 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=YJsyZE/JIyPbZVqKw0X4sKoqKT/D+w7MAVDudQ5nzcs=; b=hOD1t4Lo/31LCyAASej5HsSHFq5ckS+258NNJXMKYW9d+QzQjQvV3aPXTRKouyskLY VQgG3wAecuPmi+67x0BD74KJ0vUgYxxH29VF7ThpXa+g+vmXeHjAhNkAGtqFZG0GRuQV UwVW1uOhmFGjW5ZVHN1cGa4ZJdqqEgtelsmjFswgrJGCVnCMop+9y098ldYJnRaWxiwP zm8Uht9BlE+UGtSRl3S0DCXkB91vd6hW3ygwn3Hlu6r4eO0wlKl4MQEJeTbjwz5IA8do OliUFw1NyV6fxIO7tj4kae7dQRTX47Pa+j1CagRASLmWAPRiZq2CueIXNHaNa4jJGo3M 75Gg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991238; 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=YJsyZE/JIyPbZVqKw0X4sKoqKT/D+w7MAVDudQ5nzcs=; b=P2HUAI4frks1K2a1v9yWhwJkmyTs32dEoiGrf/VijMZxvGCE6dmYNjXQ4vSctq25EB Gk9pQAHxhrX5ZjhenGXcd/SOyEiYf76CfW4hkDEkUJkt7zwa97ll1cBGN7mbFm/zb6Gt h71463PX2iIiY4VJgdNt5cjRJdNk3oaG2deVS3Xw8mtcA5gDaPQFTb0hypT4W7b0VPkW YCpYfE0cHfk9iIRrjahhOKX6FWYqgxAlZhfOzdhUppTjpW6GIGO+DW/QjAEWPA5k/nM9 o400pTqfc6mhBVVpnpKPanc0WYX3yMVJ2LKJuM6nLgliLkOk7yDvIrInxFxjkpN8sNB+ QQlw== X-Gm-Message-State: AAQBX9c4rOiB8Pwle8ulXNR3s+G2Ky1V1EN8K0UC+DCx+T7PVFB6IaWG ymCxcoZ7ih99xslNGqG7zEtvVA== X-Google-Smtp-Source: AKy350andnvVy70t9th/ugLsnTSHw/vQxQcHGqsjcQA8CqI4Gx/+OfteSZvp1zDW482e39XJrjpTtg== X-Received: by 2002:a05:6512:986:b0:4ea:f7af:7ee with SMTP id w6-20020a056512098600b004eaf7af07eemr1386157lft.45.1680991237948; Sat, 08 Apr 2023 15:00: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 v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:37 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:25 +0200 Subject: [PATCH v2 04/12] mmc: mmci: Break out error check in busy detect MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-4-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 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 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 e742dedaca1a..7d42625f2356 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 Sat Apr 8 22:00: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: 672011 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 5F697C77B74 for ; Sat, 8 Apr 2023 22:00:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229456AbjDHWAn (ORCPT ); Sat, 8 Apr 2023 18:00:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229501AbjDHWAm (ORCPT ); Sat, 8 Apr 2023 18:00:42 -0400 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D2B455A1 for ; Sat, 8 Apr 2023 15:00:40 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id r27so2339895lfe.0 for ; Sat, 08 Apr 2023 15:00:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991239; 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=zqZGMFnsNYppNHEjJU3Id3G9gHyKFj8hUL8QQ14wDPc=; b=YPFnb73KNc8nQxfZWba9/TEkDqT3+t4nLQC/I6bezWUX0VU2Sp9CeGSLoYCAh2ZsnX ITTEylM/6Gr22tQUVOPwH77uY+wAHQVhm/DC01nxFyVxw4BAzHrCtX+vaYN6dPY0OSNw atHWfZNWyBSjnRAY+plc4lMc40jTQB3/UO9Yz734wk9gr20qj/vhU2ZGR7UpTScb/q0D WGKDhdRGXxfRxlTKhHIhl5iSz7hGyafqpAM5PAPgabLyGyGyueoSLiTwIwQTrYFvADK0 eBod3PhN8eS9gn+NtjDLIq3d+bus7ipuM16tm2i7m5SdQnjV1NFme8RzBMnPTosuz45G /ToQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991239; 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=zqZGMFnsNYppNHEjJU3Id3G9gHyKFj8hUL8QQ14wDPc=; b=cb8phaRh9fDBOWr+lHfA2iLoRhuRkheqKTL9sOr9W70Xku5mujH+lMblAhdMmwESHV e5OIhh5uy3zfre+coZU4CuxdWWW5tFUDQpzmMzXMXU0tDQeGEE1wG95xxjvPtyg2aNk9 ZOzKOU7yZMfEY5GtmGAmFIaNBwORE1y6vTiFQ+kUfmQP4bOExmjKZvUoStt3gpJMC/Xe 6PRfcnRYwhcN4B4tpftLJ6KVdkSOWd+UDPtwtwLL6hAyDjfV4VE7/RESWvjWyd1QkrYv 08IQqooYw0StjDb6jrJ0RK/milcXsFpsKtkKf55ecp66dUOphqQrqqCjZ1+KKdbz/ziQ t8iQ== X-Gm-Message-State: AAQBX9dZXsYJnublrWAAKd6TNARmh1lXiLgAk4rEc+//aE5y2EowcEhD /HrSXH+0tLS3NSBTfMBotwR/dg== X-Google-Smtp-Source: AKy350bytppW9j4EnEtNwAXVAYuyk33SR51sQnA0WepKJf/jWMOIsFfAdaDWj6ulifvWmWfBKUsSWA== X-Received: by 2002:ac2:554e:0:b0:4b4:8f01:f8b1 with SMTP id l14-20020ac2554e000000b004b48f01f8b1mr1779726lfk.31.1680991238877; Sat, 08 Apr 2023 15:00: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 v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:38 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:26 +0200 Subject: [PATCH v2 05/12] mmc: mmci: Make busy complete state machine explicit MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-5-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org This refactors the ->busy_complete() callback currently only used by Ux500 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 four states: MMCI_BUSY_NOT_STARTED, MMCI_BUSY_WAITING_FOR_IRQS, MMCI_BUSY_START_IRQ and MMCI_BUSY_END_IRQ. The 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 dev_err() 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 v1->v2: - No changes --- drivers/mmc/host/mmci.c | 55 +++++++++++++++++++++++++++++++------ drivers/mmc/host/mmci.h | 16 +++++++++++ drivers/mmc/host/mmci_stm32_sdmmc.c | 6 +++- 3 files changed, 68 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 7d42625f2356..887b83e392a4 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_IDLE) { 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_IRQS; return false; } } @@ -710,11 +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_IRQS) { + 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_START_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 (host->busy_state == MMCI_BUSY_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_END_IRQ; + 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; + } } /* @@ -723,11 +754,18 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * 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); + if (host->busy_state == MMCI_BUSY_END_IRQ) { + if (status & host->variant->busy_detect_flag) { + /* We should just get two IRQs for busy detect */ + dev_err(mmc_dev(host->mmc), "spurious busy detect IRQ\n"); + return false; + } + 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; } @@ -1258,6 +1296,7 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) } if (cmd->flags & MMC_RSP_BUSY) { + host->busy_state = MMCI_BUSY_IDLE; host->busy_status = 0; if (host->variant->busy_timeout) { diff --git a/drivers/mmc/host/mmci.h b/drivers/mmc/host/mmci.h index e1a9b96a3396..82f3850325c8 100644 --- a/drivers/mmc/host/mmci.h +++ b/drivers/mmc/host/mmci.h @@ -261,6 +261,21 @@ 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_IDLE, + MMCI_BUSY_WAITING_FOR_IRQS, + MMCI_BUSY_START_IRQ, + MMCI_BUSY_END_IRQ, + MMCI_BUSY_DONE, +}; + /** * struct variant_data - MMCI variant-specific quirks * @clkreg: default value for MCICLOCK register @@ -409,6 +424,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..24831a1092b2 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_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 Sat Apr 8 22:00:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 672012 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 19778C77B73 for ; Sat, 8 Apr 2023 22:00:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229473AbjDHWAm (ORCPT ); Sat, 8 Apr 2023 18:00:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48624 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbjDHWAl (ORCPT ); Sat, 8 Apr 2023 18:00:41 -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 27479558A for ; Sat, 8 Apr 2023 15:00:40 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id t20so2261870lfd.5 for ; Sat, 08 Apr 2023 15:00:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991239; 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=v33mdlLpkYzHfi1E5gVGRd0TDuZZSfA4mjcfujBxM+A=; b=zvZB0OsK/1qjVkWxdzfOC5rxLs2ixQsTrsrH8tt9pxn8hIVAa0FtUmLrUoOCEBdIMv ozL83UVSkgDA6lNgbVtnIbuDf0VobRhkes47FotsXDhzvbdX3ENquL+B3D2eQmZ5b1Ri Fk4rqL607LcjwGHPpsHgbUyWkjcu2Sv9SxnOzGzQfv3YEe91A/rdDK1c+KspVN71p59/ G7jIa0sco4r6KEpcrgezhgVbzstNC53lp+HyoOQIVt8Uzq1WAErBbkSI/pvjnMcfecbS bLEZi3MRfnS0Ae5QeXdoMXvXaA66aFVS7piCXN0P8L4QL4B2r0hvZb8uqiasJhl2JTOi Di5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991239; 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=v33mdlLpkYzHfi1E5gVGRd0TDuZZSfA4mjcfujBxM+A=; b=V21kOVVo0xfQqucC1p8vr5hLdAXkLiT5SLL2422BXCHNTEu/81W6iv19tUpcC0dT6R flJgGkXAkKeSR06FsJaGMoKx/kgF7SNKh+nw72P3KgKEkCom5+hyhUhI6vsAXzsvcyGK +TQ7UovOmMEc2alIiW3bqOlX4zauYllHFZtqrFQEKFxSjWZCQyG3MDDWD7q8/o0jqDK5 uG5YzWjbxSBnrWoGWj3LAZPJdLC9WYr7WBkH2r+KIvzipFyFxh+ZP9sj8TTGKNUd1MRj SOtSIjNjwlTkIyfsQCMRhDsEzb7tcye4sNt9OtfRq5Cw9/sGtDgwxgCuVIYMlCdqIpEL 4iVw== X-Gm-Message-State: AAQBX9dv2YAifvuBaxynmYhe2wfGSKCHFmEW6BVZH+mGgCfuBCN38Btq /RMckBl8RpT9XBFoguNxuX81tQ== X-Google-Smtp-Source: AKy350aJyNhiarkMTNpxNF5MoILdc0xBtNXt+OmxPmuqAPlydU7BJ+Cd+Y29utF9rWOb39niLKzGUA== X-Received: by 2002:ac2:5df0:0:b0:4ec:5648:70e4 with SMTP id z16-20020ac25df0000000b004ec564870e4mr1905122lfq.12.1680991239718; Sat, 08 Apr 2023 15:00: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 v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:39 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:27 +0200 Subject: [PATCH v2 06/12] mmc: mmci: Retry the busy start condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-6-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 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 v1->v2: - Move over the initial saving of host->busy_status from an unrelated patch to this one: it is clear what we are doing: we don't want to miss any transient (MCI_CMDSENT | MCI_CMDRESPEND) in the status register. --- drivers/mmc/host/mmci.c | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 887b83e392a4..590703075bbc 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -664,6 +664,7 @@ static u32 ux500v2_get_dctrl_cfg(struct mmci_host *host) static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) { void __iomem *base = host->base; + int retries = 10; if (status & err_msk) { /* Stop any ongoing busy detection if an error occurs */ @@ -684,21 +685,36 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * Note that, the card may need a couple of clock cycles before * it starts signaling busy on DAT0, hence re-read the * MMCISTATUS register here, to allow the busy bit to be set. - * Potentially we may even need to poll the register for a - * while, to allow it to be set, but tests indicates that it - * isn't needed. */ if (host->busy_state == MMCI_BUSY_IDLE) { - 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_IRQS; - return false; + /* + * Save the first status register read to be sure to catch + * all bits that may be lost will retrying. If the command + * is still busy this will result in assigning 0 to + * host->busy_status, which is what it should be in IDLE. + */ + host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); + while (retries) { + status = readl(base + MMCISTATUS); + if (status & host->variant->busy_detect_flag) { + writel(readl(base + MMCIMASK0) | + host->variant->busy_detect_mask, + base + MMCIMASK0); + + /* Keep accumulating status bits */ + host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); + host->busy_state = MMCI_BUSY_WAITING_FOR_IRQS; + 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 Sat Apr 8 22:00:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 671846 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 ECBF5C77B6C for ; Sat, 8 Apr 2023 22:00:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229501AbjDHWAr (ORCPT ); Sat, 8 Apr 2023 18:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229504AbjDHWAo (ORCPT ); Sat, 8 Apr 2023 18:00:44 -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 6AB4872A2 for ; Sat, 8 Apr 2023 15:00:42 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id e11so2231950lfc.10 for ; Sat, 08 Apr 2023 15:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991240; 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=68Rc2WXbmYgQ43B8wxGeYxLEsTfSBnBHmmvyKE+wjgE=; b=Jng6vM67VkLbQpEqx8soGTvigQAOITwa4rDGWidfa2GHkOXL86H3Vq1tRTtiU6vA4G P5WvV6/xJ1NRw98f2cY+/GZgPFodUaspwGjMFtctx17JbDn9My2G88RztkuimPoDcboV swYRndtqyjuBLAmHXEFVVZep5N/aUo1QZuBZ6mCy5sB7BIbDLJwEcNLBgAVuFQyodkBN ev/bm768A0Dve3wQab2svqiatzbiAdl3INZQOkHU1MXLzERHwNFy4FNAH8hV1/d3JFMc 9VynWj09z6ZLRgbvCkgUNwJSrO7+sOpiktCRhJMQxrJfp8qbWzVNTNJgQozoKWvn54tF 8nRg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991240; 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=68Rc2WXbmYgQ43B8wxGeYxLEsTfSBnBHmmvyKE+wjgE=; b=tY0+msS6LPnFw/0CuQ7JxPhS1sgKKbrniZ7/F1+FNpVvuRW362z7Wj2fSRTnKDIMNb MAzFAfYbouNs7pZCcLC3x88n7LpyPRU+OlqYS1sJODpiQi0ZoEnezPxZk3xCoJv+FE2A 6AJYUhyDd1t3jiSrX0DUGL6w/ZiZUWfRChHGGAyCmtxUNKVapMkCApacY/GbBN3H1Yb5 faLfxDNytrg6aRa+MRIKnnBVGIyqAPRGmUzySB8rmdSLRtJ3XKikJ64AUkFGnjDu+KHz j+RxqP4msNMuvqYcM2AOUKG12gkSUSmDGESiR9Z7I2V6GCVSgTS+VU++8IsfKrAWqibH nY7Q== X-Gm-Message-State: AAQBX9eFNwth37BaEBnKAZ3IPZnVcT/dPMbf6exnBG5+7znoChPAMlYz OGpmumtuCdyEzxTa1Tt/mwD5mgqOvkq3d2AGv2g= X-Google-Smtp-Source: AKy350YlfCdenr9RWRKwBxE0XtY7Fl0xZTzRe9Mb8WEbRjfGWi9vUwzBUMckkJButIQ1kGSAgitciQ== X-Received: by 2002:ac2:47ec:0:b0:4e0:a426:6ddc with SMTP id b12-20020ac247ec000000b004e0a4266ddcmr1890164lfp.0.1680991240796; Sat, 08 Apr 2023 15:00: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 v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:40 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:28 +0200 Subject: [PATCH v2 07/12] mmc: mmci: Use state machine state as exit condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-7-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 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 v1->v2: - No changes --- drivers/mmc/host/mmci.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 590703075bbc..2689c6bb62d6 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -673,7 +673,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; - return true; + goto out_ret_state; } /* @@ -704,7 +704,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) /* Keep accumulating status bits */ host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); host->busy_state = MMCI_BUSY_WAITING_FOR_IRQS; - return false; + goto out_ret_state; } retries--; } @@ -713,8 +713,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) writel(readl(base + MMCIMASK0) & ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; - return true; + goto out_ret_state; } /* @@ -733,7 +732,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); host->busy_state = MMCI_BUSY_START_IRQ; - return false; + goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); @@ -742,7 +741,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; - return true; + goto out_ret_state; } } @@ -751,7 +750,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); host->busy_state = MMCI_BUSY_END_IRQ; - return false; + goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy end IRQ\n"); @@ -760,7 +759,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; } } @@ -774,7 +773,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) if (status & host->variant->busy_detect_flag) { /* We should just get two IRQs for busy detect */ dev_err(mmc_dev(host->mmc), "spurious busy detect IRQ\n"); - return false; + goto out_ret_state; } writel(host->variant->busy_detect_mask, base + MMCICLEAR); @@ -783,9 +782,13 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; + } else { + dev_dbg(mmc_dev(host->mmc), "fell through on state %d\n", + host->busy_state); } - return true; +out_ret_state: + return (host->busy_state == MMCI_BUSY_DONE); } /* From patchwork Sat Apr 8 22:00:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 671847 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 95B63C77B61 for ; Sat, 8 Apr 2023 22:00:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229517AbjDHWAp (ORCPT ); Sat, 8 Apr 2023 18:00:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjDHWAn (ORCPT ); Sat, 8 Apr 2023 18:00:43 -0400 Received: from mail-lf1-x12b.google.com (mail-lf1-x12b.google.com [IPv6:2a00:1450:4864:20::12b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 44E8C7D8C for ; Sat, 8 Apr 2023 15:00:42 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id z8so4101057lfb.12 for ; Sat, 08 Apr 2023 15:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991242; 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=ulSk45VVtkQg/VdJQPl9abn/cnbMSUxtNO73oyBUdnI=; b=xNtWRgV51u81o5Ru5snbvFHi2CMdQ/qYrwzEfDnwHb9oacILRfg7jP1XbwIDMLHPsD hHEE3aI1uFJqAUzSwReO4uEqZzGvN1AK3xv4heIlTVuaQMIYi6VDesg/oI0g6kWnbKKN rK+s2FheyK2Kc0mX6AAXhPv1k3JoL52oiJQD5fKQU8IcuQC0hgMMpgsOIWp0wCyNpsof 7eBb18o8rLx2rhHyGeipGcCyX8WbUiY/CvS8yf0eA+KWCiV9HfqBSj1xjg8B8/4+xGxr mL1RpnMnTWqVdmZJdJMZEbCmwgunkW6P8KswOfIkuoD8wV3WScx+G9BfI5C/5aJqmrA9 xuOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991242; 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=ulSk45VVtkQg/VdJQPl9abn/cnbMSUxtNO73oyBUdnI=; b=HMr9t56zObYOzu7DUgJ1aRQmESHu0ZJLwTxgRyKgtPMxvBVzpQV1nMO1rW6F4fhMd4 bZ47zCSLl5cy41E6dSUKJzKuLAjU7OUgbjk8QUChGwXOjvAFkX0o8KL/LPIrE0O9mrdJ 0FuiHqwrdPo7+koF6QMGWc1w5a/PRGNTjD0NATOEiowUpJjwjdSZ5CKlqt7CW7jRx4/D kopGh4sHlcrN/gJlSTq3Z12Hde/Z+2AO6rzMM48//HU/O9DVT98aib9+GCIJfTBGEamI G1jAYwl2IBKDTOJw11HMGtqRlUIkMwumIt1drGPQBHduwGM3Ot1+d00kcv1VDWNDQ5Jj viXw== X-Gm-Message-State: AAQBX9c3QDSmzJ+UHWV0O/Ij6hugnZAfCPV3BrGd7VmNNNfFo+JXXAJ4 Fdc9cXQTJREPxtZBlsOT0SKkm3z4br9cnwVq+Mw= X-Google-Smtp-Source: AKy350al+1pRL1fKihF3snfzUxn/XCgYEiLlufMjMilEnI+leSgyi3G5zSBnXdRXnw3k8tn4QYQWZA== X-Received: by 2002:a05:6512:985:b0:4eb:1e73:d30a with SMTP id w5-20020a056512098500b004eb1e73d30amr594315lft.45.1680991241832; Sat, 08 Apr 2023 15:00: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 v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:41 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:29 +0200 Subject: [PATCH v2 08/12] mmc: mmci: Use a switch statement machine MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-8-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 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 v1->v2: - No changes --- drivers/mmc/host/mmci.c | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 2689c6bb62d6..76d885d7e49f 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_IDLE) { + case MMCI_BUSY_IDLE: /* * Save the first status register read to be sure to catch * all bits that may be lost will retrying. If the command @@ -713,8 +719,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) writel(readl(base + MMCIMASK0) & ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; - goto out_ret_state; - } + break; /* * If there is a command in-progress that has been successfully @@ -727,12 +732,11 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * both the start and the end interrupts needs to be cleared, * one after the other. So, clear the busy start IRQ here. */ - if (host->busy_state == MMCI_BUSY_WAITING_FOR_IRQS) { + case MMCI_BUSY_WAITING_FOR_IRQS: 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_START_IRQ; - goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); @@ -741,16 +745,14 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; - goto out_ret_state; } - } + break; - if (host->busy_state == MMCI_BUSY_START_IRQ) { + case MMCI_BUSY_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_END_IRQ; - goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy end IRQ\n"); @@ -759,9 +761,8 @@ 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 there is a command in-progress that has been successfully @@ -769,11 +770,10 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * the busy end IRQ. Clear and mask the IRQ, then continue to * process the command. */ - if (host->busy_state == MMCI_BUSY_END_IRQ) { + case MMCI_BUSY_END_IRQ: if (status & host->variant->busy_detect_flag) { /* We should just get two IRQs for busy detect */ dev_err(mmc_dev(host->mmc), "spurious busy detect IRQ\n"); - goto out_ret_state; } writel(host->variant->busy_detect_mask, base + MMCICLEAR); @@ -782,9 +782,15 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; - } else { + break; + + case MMCI_BUSY_DONE: + break; + + default: dev_dbg(mmc_dev(host->mmc), "fell through on state %d\n", host->busy_state); + break; } out_ret_state: From patchwork Sat Apr 8 22:00:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 672009 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 9B0DDC77B70 for ; Sat, 8 Apr 2023 22:00:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229504AbjDHWAr (ORCPT ); Sat, 8 Apr 2023 18:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229503AbjDHWAq (ORCPT ); Sat, 8 Apr 2023 18:00:46 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 581255271 for ; Sat, 8 Apr 2023 15:00:44 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id g19so45284652lfr.9 for ; Sat, 08 Apr 2023 15:00:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991242; 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=ULAzhGFOFghdBv7gibJVH7jzq8I3KmMXjSq82uGdpgg=; b=kW6IvLkJFEUd+u+C5vxTrWmTcDMtgKnnz/RA3bxulR8plM+mgPgVIHU5SFci7Ko9Xl fBqy7oBnhxibaNJYHYj3gp6rhj0oJEX68vH9AfJ+p2UIggS/o19tW6RH3Pu9cHG92tg2 HUDs4PVTqYmUPkt8M+OB7GJEYBsrd2tp+mWNa8dpMElWjAjcGke1y5STI9VOxOtdExDv m77w6XHbFkRfBmuTkFWxCrgm0LvXFiQ1+Di/lAoGEpvMGXaeR3lHvLCuUy+77HX0Qt8v /YykX9VrfN3xO+eoxqRIt42zgB+UiE8pOhk0gZ1dCBrdBYfeP/TJI1/Mu7cr2aYFBqGV c8bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991242; 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=ULAzhGFOFghdBv7gibJVH7jzq8I3KmMXjSq82uGdpgg=; b=A0yAysshgOf1c71Xf5sNB1w4x5Bx1mg3rKkp652HNjpSaio0DHw5dpeoJXRFCPoV9p c3eqlO2q7wsboWx24VebbIWJbwmvL4Jvu7KtWsA8GiAlPt3GKvSZyVmaFE9WGPahjjCA CmOrkIqllnqEpf0song+Ms7UmkPL0HBDpvCn+x1XqLNzXvhCHBwaz4zJlDEXmkDO8dvy A4JBI4HhmaMm4/RiwnGM745nB3oO/ArZTAcqoYcbZ93igW3wB4GBXDGOq86l/QVjbUah MD6/wAoH84gNZzHnWSrOdTaDMlv1Wk1PCWk9lqUI+bY5aglPqSvb/+0KsjFBXruSYE/5 mUUA== X-Gm-Message-State: AAQBX9f8JDkjHat3J0XwvlZqr+f5chnboDZc9GIbZE/rgydCW48hWboa D8e45uO00L/Xtb6DLTPll9XKig== X-Google-Smtp-Source: AKy350aU5KX6WtplCCVlS7xJYrXmCJUhSjgdJ2ze+/oiJOLk96JJMhDvVg5EYOc7SWhgokdXLmpXGA== X-Received: by 2002:ac2:5ddb:0:b0:4eb:44bb:faeb with SMTP id x27-20020ac25ddb000000b004eb44bbfaebmr1870019lfq.39.1680991242725; Sat, 08 Apr 2023 15:00: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 v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:42 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:30 +0200 Subject: [PATCH v2 09/12] mmc: mmci: Break out a helper function MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-9-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 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 v1->v2: - No changes --- drivers/mmc/host/mmci.c | 42 ++++++++++++++++-------------------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 76d885d7e49f..9a7f441ec9d6 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -654,6 +654,17 @@ static u32 ux500v2_get_dctrl_cfg(struct mmci_host *host) return MCI_DPSM_ENABLE | (host->data->blksz << 16); } +static void ux500_busy_clear_mask_done(struct mmci_host *host) +{ + void __iomem *base = host->base; + + writel(host->variant->busy_detect_mask, base + MMCICLEAR); + writel(readl(base + MMCIMASK0) & + ~host->variant->busy_detect_mask, base + MMCIMASK0); + host->busy_state = MMCI_BUSY_DONE; + host->busy_status = 0; +} + /* * ux500_busy_complete() - this will wait until the busy status * goes off, saving any status that occur in the meantime into @@ -668,11 +679,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) if (status & err_msk) { /* Stop any ongoing busy detection if an error occurs */ - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; + ux500_busy_clear_mask_done(host); goto out_ret_state; } @@ -715,10 +722,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) retries--; } dev_dbg(mmc_dev(host->mmc), "no busy signalling in time\n"); - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; + ux500_busy_clear_mask_done(host); break; /* @@ -740,11 +744,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); - writel(host->variant->busy_detect_mask, base + MMCICLEAR); - writel(readl(base + MMCIMASK0) & - ~host->variant->busy_detect_mask, base + MMCIMASK0); - host->busy_state = MMCI_BUSY_DONE; - host->busy_status = 0; + ux500_busy_clear_mask_done(host); } break; @@ -756,11 +756,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 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; @@ -775,13 +771,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) /* We should just get two IRQs for busy detect */ dev_err(mmc_dev(host->mmc), "spurious busy detect 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_DONE: From patchwork Sat Apr 8 22:00:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 671845 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 3E8CFC77B61 for ; Sat, 8 Apr 2023 22:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229532AbjDHWAs (ORCPT ); Sat, 8 Apr 2023 18:00:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48738 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229530AbjDHWAq (ORCPT ); Sat, 8 Apr 2023 18:00:46 -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 32EB255BF for ; Sat, 8 Apr 2023 15:00:45 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id d7so13374720lfj.3 for ; Sat, 08 Apr 2023 15:00:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991243; 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=/LHmw5cP/mktYU3ZkTHFGE0ry3dquVBbcV8PSndMvnw=; b=yMyhy+Ihg6G5x+T2QZ+9BFIOcqTsNMP/ImmEzutXidDwICWaT+uedcy7b52mXWVDFQ v42FmEeZSJ/xKI6NXJkmNIvbtLvrO5MtD2I5gUIsVxJYRQgdqMOre+bgy31fXctRjDmZ 09FNLUNXAKMIEJUex7HQkMSAfh2pGeF0yeTrSDgDd22ZCbx2IuplZncdJhRIafiCPlDC nYkqloRGn8cnMuJ7dCH5CHEZlvpySriNKnQejQwn6ZCCQyonS6vNPRMuHdtZ7LSsveuU 4ZmO7Brq/Wz71O651U1oAKoY4tPEcXIrTLcoUtZqylvlldjiV/rbOmSJxhXSIcUaU09w HxKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991243; 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=/LHmw5cP/mktYU3ZkTHFGE0ry3dquVBbcV8PSndMvnw=; b=YyrDhhT8SYgza9srCrMzFupBCqxjlv4c9dgynW4qjEAqBfMdck2hC6D9WyPNWL7yai sSCSSWXW1T5ZLQkQz7RPZxDXW4OsJpoEfRoU5XJwXNj2dcQHsKSj6tmqNHIlZlQKSYFv H6ldlSksPm2j1YEmcf/NM29PqUQ2ADYXFAE89V9zv9hc1p06QOqtNFef/UHxJeCeMtHy ck9R/ZbOfDL3IVNYjZsEqcoy3h5BKFnLari0gqx0V61MTKt4uJJtEC/FZqQ96V6oBgNm UN7XUaAP0xET7THdGOMU08oxlLmv/c2D67CuXW1en7sRxAibvigPGTKZq4bhCF9KsAVm 1Lhw== X-Gm-Message-State: AAQBX9fTDxoizNdtWxJqOceUZbNyANl+lTQA5Z00ym2IPR2T42fWrjZK 8Zq6ex/cGIN0qQwhkNaTJgIb2Q== X-Google-Smtp-Source: AKy350ZuZSKTqn5CvyZR6lbMeyKnlxxnApYA3GcKVyg/68BqUZNskF5lIsVOhC+ly4y81O2l7Q2/OQ== X-Received: by 2002:ac2:551b:0:b0:4dd:9eb6:443e with SMTP id j27-20020ac2551b000000b004dd9eb6443emr1606943lfk.31.1680991243598; Sat, 08 Apr 2023 15:00: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 v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:43 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:31 +0200 Subject: [PATCH v2 10/12] mmc: mmci: mmci_card_busy() from state machine MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-10-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org If we have a .busy_complete() callback, then check if the state machine triggered from the busy detect interrupts is busy: then we are certainly busy. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - Do this in a safer way that falls back to reading busy status from the hardware if the state machine is NOT busy. --- drivers/mmc/host/mmci.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 9a7f441ec9d6..180a7b719347 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -339,6 +339,12 @@ static int mmci_card_busy(struct mmc_host *mmc) unsigned long flags; int busy = 0; + /* If we are waiting for IRQs we are certainly busy */ + if (host->ops->busy_complete && + host->busy_state != MMCI_BUSY_IDLE && + host->busy_state != MMCI_BUSY_DONE) + return 1; + spin_lock_irqsave(&host->lock, flags); if (readl(host->base + MMCISTATUS) & host->variant->busy_detect_flag) busy = 1; From patchwork Sat Apr 8 22:00:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 672008 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 EF92DC7619A for ; Sat, 8 Apr 2023 22:00:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229530AbjDHWAt (ORCPT ); Sat, 8 Apr 2023 18:00:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229521AbjDHWAs (ORCPT ); Sat, 8 Apr 2023 18:00:48 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 301B56A4D for ; Sat, 8 Apr 2023 15:00:46 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id e11so2232052lfc.10 for ; Sat, 08 Apr 2023 15:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991244; 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=pkQYbCEjQjRXzRX/K8hF+kF32jmLe8MMLCT5UxEXp3k=; b=dN4Sif9FwK2AKgY9RtwUQyZSenp59SlULTS32GEgCCPwGhdP9zo9mT5vL+4GKpGjBg F5u2H50Hht1eZT4cFxy9a9KG/tnEL6ZgF+onkvvU/QPp1ohh+vhJPR2ZzsViuR9egCD/ oM/boKwODw3hkVDxxR5jTqYTZFsXvLMFoW2ETfZFtrM+Y67641QUGXuX+gJYSUDqo9Au F9SbyW2mzPW8WRR6eUwyBEdNyX+ZvteZpEgo+kcAo8DZu5mQFU1o0xEypi1stuUoCUKf 7oodWVX16V125nMJ94Ff8ievHleQ7ronScCTNnjw6bXVVak+MyLmSB1pBZlA0djDYi82 2dyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991244; 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=pkQYbCEjQjRXzRX/K8hF+kF32jmLe8MMLCT5UxEXp3k=; b=2/+6hClqrbpgsppjsb6y+ONEPygXlAf6a7GwDQnspr1kZQ7vKKj99xwNi+8q+s/rZR 42f7SE1WJTv/U5W77iuIiszLoPwHzWF8r1ovJaFuASc64Z6OD/W5akbyWOHZsvP4/jCU XaGibtaZPWQCFA5KZsinLH+0yy9MxKljZGvbb9bHZQIqdN78Lq4Uq9VXSJPuSiIMmYLk uxYMTHGPd+vjXP1TcFaxD3qAl6rYH5cT5ZtzCh7pDXB6FqgDvNS6BC6OQfplBPDOoxuB aHAxTaMVCPJhSz4PQGHIV6d3h7jZA5Klu7toMjD2ExninMljGHFZs2W2558ivjFazSZr Dhpw== X-Gm-Message-State: AAQBX9cLAh0kraAHz/cN4TEuxW9MIZO46Mbm9qpdvDQeyJCWH5QH8lTM HRg21ePUYuvsz7U9ZXBzToBg2QvK/sSDNENVoPE= X-Google-Smtp-Source: AKy350ZQGnM+k/Wd37miZZuhFoTdrColl3OzRBE7aZn2aD+nmoCN3Te3icSUTua7vrHaBYUy9BZjSg== X-Received: by 2002:ac2:43c3:0:b0:4dc:4b92:dbc4 with SMTP id u3-20020ac243c3000000b004dc4b92dbc4mr1301602lfl.14.1680991244466; Sat, 08 Apr 2023 15:00:44 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:44 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:32 +0200 Subject: [PATCH v2 11/12] mmc: mmci: Drop end IRQ from Ux500 busydetect MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-11-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org The Ux500 has these state transition edges: IDLE -> WAITING_FOR_IRQS -> START_IRQ -> DONE The first IRQ move us from WAITING_FOR_IRQS to START_IRQ and the second IRQ moves us from START_IRQ to DONE. This didn't come out until after all refactoring. For STM32 we keep the END_IRQ state around, because that is indeed what we are waiting for in that case. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 180a7b719347..17233702e7fb 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -758,7 +758,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); - host->busy_state = MMCI_BUSY_END_IRQ; + ux500_busy_clear_mask_done(host); } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy end IRQ\n"); @@ -766,20 +766,6 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) } break; - /* - * 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. - */ - case MMCI_BUSY_END_IRQ: - if (status & host->variant->busy_detect_flag) { - /* We should just get two IRQs for busy detect */ - dev_err(mmc_dev(host->mmc), "spurious busy detect IRQ\n"); - } - ux500_busy_clear_mask_done(host); - break; - case MMCI_BUSY_DONE: break; From patchwork Sat Apr 8 22:00: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: 671844 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 0C78FC77B71 for ; Sat, 8 Apr 2023 22:00:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229503AbjDHWAt (ORCPT ); Sat, 8 Apr 2023 18:00:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229531AbjDHWAs (ORCPT ); Sat, 8 Apr 2023 18:00:48 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0ACEE7D8C for ; Sat, 8 Apr 2023 15:00:47 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id t14so2156970lft.7 for ; Sat, 08 Apr 2023 15:00:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680991245; 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=NK/Fry9T9gbXULkf+X1lnmSQBtAcyXPtx15VS/8mjZQ=; b=uVqJUmRLIEBX067m4GrdxYkkBbmoL93WK/V0QPpzSlQlHjdHL+TM+3p45evtn9jw7z dKkfjIznLuceUL2QMGjpI0QBWpodTQV0SSe9n9Ii8QV1ohGQ0UPAWYrTIDIBDZFTIMRK 4KK3PN+iwo3zQQNIgECnTlcCznJ6uY7XhYcepsHb7fcwBRNyBgfG8/Jxk9qdO21+Ykf2 nybbBMbd+2kIfXQjlmO9crx0B8br2DkWemP4X+BcoJkw+g3dRh5RiuHNsPoAS5oxOWIe 5kHRjjNa4zUMJFE8fYl/Jg2DDaunp6jph7EdJxxTNuLyYs8PnPTvZP+VdVFu1uRt2/nF Z5RQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680991245; 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=NK/Fry9T9gbXULkf+X1lnmSQBtAcyXPtx15VS/8mjZQ=; b=HAhpflQXZwlW+aNHbybYEtgJ2onBrrc1FmJD0hCZ3oMSf72Z9y779crjRFpcXVLmEY cwAdnLBOQcy9++REXQgt29OoXOAQqKrxuggKmlgmonPt00V4yKYmvhOamGADZsX3lxBa OswAF0jmRBsKoBehcXD6bOFuUzloy9PPW3nx0rBd5EodawyyV42YnVZkQ/ETHkQZu+3k XtT+88e1gc6hFP6Wr6UfNlyDZMLIu4ZeDRK3U1KIsPmMAkGKSrSY6oEP0+dCoZRs8vE2 ftr7takv/bId4LwH+Lym8VbtmPT6BW1ZhdT1cnSzJxyc/t3ZO6ZAcvw7SrLdAA31kIJc sfzA== X-Gm-Message-State: AAQBX9ecYCa7nMsnGJkaKYN4lL+K6gR8vHryMBC1kxh41vXohUGgX96D hj5j55aG9slKl80OF8Q0tvLUJg== X-Google-Smtp-Source: AKy350an2GH9i7wmQ/+Ebm1829Zb1RXtBYT4meUnPlrJWgb7glP+JurXh9Xwhe9//nJscwBjStDNtg== X-Received: by 2002:ac2:4477:0:b0:4eb:2ac1:52a6 with SMTP id y23-20020ac24477000000b004eb2ac152a6mr1839681lfl.36.1680991245335; Sat, 08 Apr 2023 15:00:45 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id v9-20020a056512048900b004e9cad1cd7csm1328904lfq.229.2023.04.08.15.00.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 08 Apr 2023 15:00:44 -0700 (PDT) From: Linus Walleij Date: Sun, 09 Apr 2023 00:00:33 +0200 Subject: [PATCH v2 12/12] mmc: mmci: Add busydetect timeout MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v2-12-eeb10323b546@linaro.org> References: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v2-0-eeb10323b546@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.0 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Add a timeout for busydetect IRQs using a delayed work. It might happen (and does happen) on Ux500 that the first busy detect IRQ appears and not the second one. This will make the host hang indefinitely waiting for the second IRQ to appear. Fire a delayed work after 10ms and re-engage the command IRQ so the transaction finishes: we are certainly done at this point, or we will catch an error in the status register. This makes the eMMC work again on Skomer. Signed-off-by: Linus Walleij --- ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 23 +++++++++++++++++++++++ drivers/mmc/host/mmci.h | 1 + 2 files changed, 24 insertions(+) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 17233702e7fb..1af129fba0ed 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -747,6 +748,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_START_IRQ; + schedule_delayed_work(&host->busy_timeout_work, + msecs_to_jiffies(10)); } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); @@ -758,6 +761,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), @@ -1498,6 +1502,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); @@ -2311,6 +2331,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 82f3850325c8..68ce7ea4d3b2 100644 --- a/drivers/mmc/host/mmci.h +++ b/drivers/mmc/host/mmci.h @@ -453,6 +453,7 @@ struct mmci_host { void *dma_priv; s32 next_cookie; + struct delayed_work busy_timeout_work; }; #define dma_inprogress(host) ((host)->dma_in_progress)