From patchwork Fri Jun 16 20:42:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 693929 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 31F8DEB64DA for ; Fri, 16 Jun 2023 20:42:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233200AbjFPUmf (ORCPT ); Fri, 16 Jun 2023 16:42:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232085AbjFPUme (ORCPT ); Fri, 16 Jun 2023 16:42:34 -0400 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [IPv6:2a00:1450:4864:20::135]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C9203A91 for ; Fri, 16 Jun 2023 13:42:33 -0700 (PDT) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4f76a4c211dso1647024e87.3 for ; Fri, 16 Jun 2023 13:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686948151; x=1689540151; 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=9t6pgncZlYopzh3WmgICbr64f7ZfnkyzvZkpH3TsLrY=; b=joNZ39NmzIwO0y7dgE/UoRyr2pCDbczmTjtEenUcQYNFut+RFfugo7RFrfXYtn1z22 2iC8EtKicSQVU45V61HhmR6Zr3KMkRRJCegZXu4VojgHJSfiR0CRSUXeKu1obT7Lhj98 RUaB6oxmf+dhdvd1B6jkFPeBH3x8dU8qQT0b3v3zwxJksRD3q9zNyr+8bxn0arKiVNE1 CaoX7KHLssNQyFaNhCsyZxOlEsIw0vbYPByAHS0NbpgTKEcPFwPBCOopBmZtCejBNL2e fqxfHnOXmNxEuIEKNuKrCtGMJiNSvpm/YkeFrrZrjfb2w46Z4sLH431kl4k6pWCDfOd8 uKag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686948151; x=1689540151; 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=9t6pgncZlYopzh3WmgICbr64f7ZfnkyzvZkpH3TsLrY=; b=cyl64kTRfGhx5HkYsmQiLubFklfMrvkh4+rrR3FPE2aqskMhYsPLYE1NBeQgSeAB/o zNiqfg3B3XxiX0N8KqZM4nT+AuJN+1iKcQinxqRip5PG8ZCXxZ1oabDzyD/4AxIp0lUN 2ZO7g2pIbM0QPXP7qQC7godsx7BWmfuI5wtstxY3HPMeEXtqQCn6Fo0AEKDmlECfk5sY DjH38IZb2GPhsHg6B/5ItWmuh0pjbVbkazYpN/kjyZWMVSKwKT/oCyEET5K0Dq0TRy76 RePiNTKELSAdXpU2XngPThTahPcB799OYeP4oF37ryPK1FmDkTcnHwnJiY3BTfWtajG2 8sjw== X-Gm-Message-State: AC+VfDz1jV9WfxrIMjPMjTSqt8Zj2AfSdPfFEdh3Je/uY65aUzilYlx5 06AiiTwDnvZoOKP/3GzKZFlqQA== X-Google-Smtp-Source: ACHHUZ5wuDlFmsGGNMNksjY0h2w+P+KhrCvN7EqX361uupuau7Bm/InRm2H3RKVU6ZFB93vboNtPRQ== X-Received: by 2002:a19:4419:0:b0:4e9:cfd2:e2d with SMTP id r25-20020a194419000000b004e9cfd20e2dmr2293131lfa.65.1686948151542; Fri, 16 Jun 2023 13:42:31 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id d22-20020ac244d6000000b004f845907454sm770981lfm.232.2023.06.16.13.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 13:42:31 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 22:42:19 +0200 Subject: [PATCH v7 1/9] mmc: mmci: Clear busy_status when starting command MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v7-1-69a7164f2a61@linaro.org> References: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> To: Stefan Hansson , Ulf Hansson Cc: linux-mmc@vger.kernel.org, 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 v6->v7: - No changes. 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 20:42:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 693491 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 2061AEB64D8 for ; Fri, 16 Jun 2023 20:42:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235399AbjFPUmg (ORCPT ); Fri, 16 Jun 2023 16:42:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232049AbjFPUmf (ORCPT ); Fri, 16 Jun 2023 16:42:35 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E7123AA4 for ; Fri, 16 Jun 2023 13:42:34 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4f122ff663eso1611987e87.2 for ; Fri, 16 Jun 2023 13:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686948152; x=1689540152; 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=TgLzIEwUjksEjQv4aYSqatUN+oXUaB2j9A2tsvxCYyc=; b=a322ThMVtliN+JEBQ+qCe3D+6A5ug1thhAi1c8LpJTWiCxXxIip+Fsrbw7zY+nZMXx FHF8SbgZ4woyMCXHIoRHGjuxxyVLMEUQPSPaIyAiFsAi8N16k5rIVwcfOr0lqO7Fd4yP UixGCEIgncxhn+39SloQDpqVDuYw1kmDz3QH7HwiclwaVacWGvvlbqwLb/duOErVDkpL LykYJPgiXcEXkW/YvbJvl2+26F1vyg9Hm2Yv8/orVEOeWfyBTykc+GxSwjSn2kozW7j1 4es++iIK5juyhIoe5urvtJMC1K2seGFR4+63XI2dWZ6EwrZ2cgBNk57XPQ00Fu9+9nWf erRw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686948152; x=1689540152; 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=TgLzIEwUjksEjQv4aYSqatUN+oXUaB2j9A2tsvxCYyc=; b=DeaOZGYH6HgNM6BE9mK3jyRtRNZg2KslHe6deSob5ZTq0wswLCNvo3nkizxv5POH7o OUugx9HeL53ALoj1N3Qnmmi7MGwA8FXfmkAgk3MbrUPJ1sqb9xa1C5O7pBiteESTbn9V mg3qso5OJBjxguAT49Xa/L6rWEEQeYu+AP+7yqnPocQ7Pt6Df3kHqGCM5p3KWf+AQRvZ dvwP0Q5UADyp/0Wnni/Z5+pzLhZBZeZHRHI9CTU/ZUGeoWh2wSUWeHp41LRcJUxWtkLI aKF7Ebn6+ES9h8RAjTTbNNWUcZbEvV0Kc1jWLb6E31aDqhnXD8R0ogpBwQmA/pOlRPtZ mjxw== X-Gm-Message-State: AC+VfDyoqdmCFQGsiGtv5S5L9nnZJhAwv6OPzcjnykYRe8MMl8VdjCTK c/DI7kzxqcmzo/zEZcIzm+i6xQ== X-Google-Smtp-Source: ACHHUZ5RAv9vEfDAx5rHOg0jbQFgU/y+kBgq7As5IHeWBPWJ9YEYxJ7Qk6XkUVgw0fKcAYhA3fojFw== X-Received: by 2002:a19:644e:0:b0:4e9:9e45:3470 with SMTP id b14-20020a19644e000000b004e99e453470mr2437539lfj.3.1686948152503; Fri, 16 Jun 2023 13:42:32 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id d22-20020ac244d6000000b004f845907454sm770981lfm.232.2023.06.16.13.42.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 13:42:32 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 22:42:20 +0200 Subject: [PATCH v7 2/9] mmc: mmci: Unwind big if() clause MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v7-2-69a7164f2a61@linaro.org> References: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> To: Stefan Hansson , Ulf Hansson Cc: linux-mmc@vger.kernel.org, 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 v6->v7: - Add nice ASCII art illustration of the two interrupts. 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 | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 0a4b6b6e0f03..b2c7c2d39767 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -654,6 +654,23 @@ 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. + * + * The Ux500 typically fires two IRQs over a busy cycle like this: + * + * DAT0 busy +-----------------+ + * | | + * DAT0 not busy ----+ +-------- + * + * ^ ^ + * | | + * IRQ1 IRQ2 + */ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) { void __iomem *base = host->base; @@ -671,14 +688,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 20:42:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 693928 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 82B96EB64DB for ; Fri, 16 Jun 2023 20:42:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232049AbjFPUmg (ORCPT ); Fri, 16 Jun 2023 16:42:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59332 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232085AbjFPUmf (ORCPT ); Fri, 16 Jun 2023 16:42:35 -0400 Received: from mail-lf1-x131.google.com (mail-lf1-x131.google.com [IPv6:2a00:1450:4864:20::131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3A5030EF for ; Fri, 16 Jun 2023 13:42:34 -0700 (PDT) Received: by mail-lf1-x131.google.com with SMTP id 2adb3069b0e04-4f004cc54f4so1677081e87.3 for ; Fri, 16 Jun 2023 13:42:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686948153; x=1689540153; 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=Z9MD7T6l8zvLVJ/fOvCH77GltOs80Rm4EnRGEKnGhEE=; b=bW16p5BgLLEVTQ/p00oo7zlTthVUlwfeRCnDG8XjhAq2/wjpG44WqM9Pqrjit2b7oe p+7kFWQf6kOGc6ZpikV/59oD5d0L5zRHAQl9q/QcxK1rNLWeh9L3/pvu40EGt+WxrZYX On3aV3NpbxGl0v+YMGuF5MJzezhMoa9mgVNOdA+8P8DoE+Y7z/SkWxn94Jw+A4CcdhDz RS1xBKURqdGF2cBbHIkd0ztmWwLkYAevv1ZYCI3GcVodHbMiuuAdHUG3fvOfJ7ebnkIC Wce3MLcMuTCfBoV/vgb9oYo5dZ/fla6jBjNgjdbf8gFp8PgUKEK4JnP3LqYgPetxp7MP VtrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686948153; x=1689540153; 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=Z9MD7T6l8zvLVJ/fOvCH77GltOs80Rm4EnRGEKnGhEE=; b=gs7SwDmxfpHy4CQyMEWtvKqwsz9vH4R47vPWTbkWaq6FynAbtL9NeaFejXbDmy/M28 DLnfYneF29MiDMWX94GL89vRLBfW7Q8dM0MmBmI6n/K1trjjk6QLdc/TQEYor+2VO9OS 9KTREgXzMcw/yceVB7p/jhpkbx1QDWyGQ7FVeOPFr6eyWw3WYDW/JGjfrEkjhRW+fNiY uL4FQhYiLwUPDbfQoJSqMhnLEgjiKTr9D8fU2e2CXGRG/63k1079086j4kfu3US92Bha u+ZzCRK3nRo7Hwk+VIg2xqOuEkAcM3rzdvLvSx7qM1AVQHHIBaJGqWNcwVzsw1TCS/Rg 2EIQ== X-Gm-Message-State: AC+VfDyXvTODRu7Gg97xSGsVu+Jdf4UgQIY4HyaEm4QcOaaCsboZt+el xGRuRbHai210raaBfaL2OQ79LA== X-Google-Smtp-Source: ACHHUZ5yX9jck7OGuqSI51rJNYwjPqBvEoCmQq3iZfXK2/VJV4HDNiIlCxvrEBDQrJnQJroZoa+MfQ== X-Received: by 2002:ac2:5f98:0:b0:4f2:34f1:cf24 with SMTP id r24-20020ac25f98000000b004f234f1cf24mr2449109lfe.22.1686948153271; Fri, 16 Jun 2023 13:42:33 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id d22-20020ac244d6000000b004f845907454sm770981lfm.232.2023.06.16.13.42.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 13:42:32 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 22:42:21 +0200 Subject: [PATCH v7 3/9] mmc: mmci: Stash status while waiting for busy MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v7-3-69a7164f2a61@linaro.org> References: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> To: Stefan Hansson , Ulf Hansson Cc: linux-mmc@vger.kernel.org, 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 v6->v7: - No changes. 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 b2c7c2d39767..417dc3b1c744 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -713,6 +713,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 20:42: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: 693927 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 EB450EB64DC for ; Fri, 16 Jun 2023 20:42:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232085AbjFPUmi (ORCPT ); Fri, 16 Jun 2023 16:42:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242048AbjFPUmh (ORCPT ); Fri, 16 Jun 2023 16:42:37 -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 CBA0F3A91 for ; Fri, 16 Jun 2023 13:42:35 -0700 (PDT) Received: by mail-lf1-x12b.google.com with SMTP id 2adb3069b0e04-4f764e92931so1683810e87.2 for ; Fri, 16 Jun 2023 13:42:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686948154; x=1689540154; 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=RJ/lYkJaS0LH2m3+0Gfk93tQBU1oPRi1nXcMIJdJKlg=; b=qdfB+W1xo1X8kL0DzWuF6yndtLd2rh9VRNEcfHocgTjTpXlrVcnYr077uDuJXpXNDI TgN62dcvPcLeEQqiM3QBudPdV1msK+HfAX/n+pWKTXpPLGKl5dBUvLxaK+UM+yPZqJYn ann8ohJH7Ws9YbWjF37gVxLAysSSGyLbRXmd/MvvLROtjggMRyzYNbPoLUf135zN+xx8 nCUNmQiJGV/JShWXJWNu0S9pFpCLaIdvn01GnImfm4pPdhKAs+BxYdRPhxkUCn7rOG7W dFU2LOlm85eVSyR27Drff7YEDJvWZVvx+y3Lhh5kwYeoxrUTTeED1Dh+JGTtrzQC/WHX Qh4w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686948154; x=1689540154; 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=RJ/lYkJaS0LH2m3+0Gfk93tQBU1oPRi1nXcMIJdJKlg=; b=VdlCqoq1Fns6g957ieLr60u7sXjpmEOZmEVKt64Bq3Re8Xtn4rto8DfHQOig1dtpFz ly8IUVhjCT+wKgDUPT1oAPTMQE/O4ryFHnoUoPNP7o5E82LtpJ6JKs6QsLVTXz3W0Bya yCHyA1pfO5y4dTjyxhiY6mVH8X6SSOnuFET0/ZkvK5lyaJxzxmqnCDnahJ+dLlEt8jnT dbvS9LCMkRixGYNOeRgR0IwzD2vFGmCJFNMiNweQ2Q/IerV9+YLSMDScvFxxAU8j/XEc eAtcTKgjputenUnTJgleperRf3rRkcFA0JjVhGOzDwIfJU3BzWqDda2/mg4hZOS+TZpN K2yQ== X-Gm-Message-State: AC+VfDzdBTp69Uh6cr/8cZTSLLtb+0mvLF1WjXiXLexng0bPlgbbetYn OTskQPsaXOUVWlzuIicLRJRlIGeLvfDrTMgZ6bc= X-Google-Smtp-Source: ACHHUZ6yFZtRn/Ra54pqvdEbxTlxjqxhVLGS8D8VoYO51DVRB2mfN172DqDZJYU8wPQURExHPJeyuQ== X-Received: by 2002:ac2:5f98:0:b0:4f2:34f1:cf24 with SMTP id r24-20020ac25f98000000b004f234f1cf24mr2449125lfe.22.1686948154143; Fri, 16 Jun 2023 13:42:34 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id d22-20020ac244d6000000b004f845907454sm770981lfm.232.2023.06.16.13.42.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 13:42:33 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 22:42:22 +0200 Subject: [PATCH v7 4/9] mmc: mmci: Break out error check in busy detect MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v7-4-69a7164f2a61@linaro.org> References: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> To: Stefan Hansson , Ulf Hansson Cc: linux-mmc@vger.kernel.org, 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 v6->v7: - No changes. 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 417dc3b1c744..e493fb7c724f 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -675,6 +675,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 @@ -688,7 +697,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 20:42: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: 693490 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 A29F8EB64D7 for ; Fri, 16 Jun 2023 20:42:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S245082AbjFPUmi (ORCPT ); Fri, 16 Jun 2023 16:42:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244916AbjFPUmi (ORCPT ); Fri, 16 Jun 2023 16:42:38 -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 8C27E30EF for ; Fri, 16 Jun 2023 13:42:36 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4f85fcef623so57334e87.0 for ; Fri, 16 Jun 2023 13:42:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686948155; x=1689540155; 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=8MaSrGsItjz38jmRCKZDyUKiiCZ5FqGUYqo/gG3lc/s=; b=OXlcMWIsMKz1SPtQEZCKgftVjgdmOlr53aapZasGvO4VPT0Y3QoawALDRX113OMZL9 8LdnADjX0rQwu+aJefAeKG7HXAOYjb+J7NIjzTFB4aAo9jXLR1Wzr/MV+6qa6vUakKji wURZKbtU3ZPdQmSH9okDg6cwEYBVlcJhMnuG02VkgZEc134oXojwTp1TjeVTdYxuRHLe dIjSXJhVJia1zCUPJNveSeW/vTq2TobrmbwQTvMhCld4RIdB4L03zQ9pPMSPTM0v/P/h WHYUfAZWVxVaTMjJW5tsycVsF3GO2wA2e1s5nzbEd5i/2C+PTxuRLB+Y2Xjj04lpKja/ F9Nw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686948155; x=1689540155; 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=8MaSrGsItjz38jmRCKZDyUKiiCZ5FqGUYqo/gG3lc/s=; b=bCO9j2C3vVI3zyWYxBAB0KM4sUF1sR+2tSYod3+3I2GAmU0/YRTjYaX0Y9U6CNaETP LWxk9D+w5++OG2vhi1RREVWSOXnVKAseih14CRaIG48sKr486/FgOFU+AlmAc7UW6vZ4 TnTMU7yFrtz34GYbz/P4lcqL88f/m6YgMOJP0nBURotctWhKgM8Qfr3OhiC+G1WIMkYz pssYy8exokLAZSJVsppCM0xoUVS++SG5jT9prfTJMYR4Y0Lx7zVEv1Mq24fEbD0xSs6Z papEbp8oGl9wwhGn5HAiclRDuUL+SEhRJY5ch0Xae1z4hQaNSZjfEjvmq+YHlkprCkH5 vo8g== X-Gm-Message-State: AC+VfDyYQSa9V1OwVVfgP06SNLiL2uxxdXNZtRUzN9QJgp7E0cBXj1f7 RqCErI2g/Io7ENxo1qRpSM4bNw== X-Google-Smtp-Source: ACHHUZ7z57R+8+5C0ijjO+dqc+GjE5JefqDQEhH5siUiZoEy4gcFiEJKOkMzvy2v4klete84pLtRkw== X-Received: by 2002:a19:911e:0:b0:4f7:3ee8:eeda with SMTP id t30-20020a19911e000000b004f73ee8eedamr1101648lfd.34.1686948154880; Fri, 16 Jun 2023 13:42:34 -0700 (PDT) Received: from [192.168.1.2] (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id d22-20020ac244d6000000b004f845907454sm770981lfm.232.2023.06.16.13.42.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 13:42:34 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 22:42:23 +0200 Subject: [PATCH v7 5/9] mmc: mmci: Make busy complete state machine explicit MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v7-5-69a7164f2a61@linaro.org> References: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> To: Stefan Hansson , Ulf Hansson Cc: linux-mmc@vger.kernel.org, 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. 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, the following happens a lot: [ 3.380554] mmci-pl18x 80005000.mmc: no busy signalling in time [ 3.387420] mmci-pl18x 80005000.mmc: no busy signalling in time [ 3.394561] mmci-pl18x 80005000.mmc: lost busy status when waiting for busy start 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 v6->v7: - Return properly with true if we get the second "busy end IRQ" as expected. - If busy is still asserted at busy end IRQ, we keep waiting instead of aborting and completing the command. - Drop the STM32 changes - just makes things complex. 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 | 49 +++++++++++++++++++++++++++++++------------------ drivers/mmc/host/mmci.h | 14 ++++++++++++++ 2 files changed, 45 insertions(+), 18 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index e493fb7c724f..e61aeca278ec 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -680,6 +680,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; } @@ -697,7 +698,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) | @@ -705,6 +706,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; } } @@ -720,25 +722,34 @@ 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 true; + } else { + dev_dbg(mmc_dev(host->mmc), + "busy status still asserted when handling busy end IRQ - will keep waiting\n"); + return false; + } } return true; @@ -1268,6 +1279,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; From patchwork Fri Jun 16 20:42: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: 693926 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 4CDB5EB64DD for ; Fri, 16 Jun 2023 20:42:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230132AbjFPUmj (ORCPT ); Fri, 16 Jun 2023 16:42:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242048AbjFPUmi (ORCPT ); Fri, 16 Jun 2023 16:42:38 -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 6BCB93AA3 for ; Fri, 16 Jun 2023 13:42:37 -0700 (PDT) Received: by mail-lf1-x130.google.com with SMTP id 2adb3069b0e04-4f764e92931so1683846e87.2 for ; Fri, 16 Jun 2023 13:42:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686948156; x=1689540156; 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=rjsyh8HKup5upDCLPid4awp+IS7Z6M7SAZiVl4zctHA=; b=X+PodAaeInuf0O+d/zgrs2lkQSEmTMMODroUtX8Xz2WhVSk3xFRPnWp+qdT7unBOZQ q8ySuV8METFG9rCWGI9wLxJQkkoP5b+npsahJ2MDkg3ib7bXlAu45paBOsUs62d3UITE Av9K8EwCjyb+mNBKWR79dhA7OZBBA4CFlXHxQ5ukJHJlM1tbFDfkaxWoVxEkyALWw5Oc Kwo7dRJo6rpRgyLBSByI4tO7sAlS4VoiQRuChbw+0c4nXXaBi9mSrmqRSJUI4LFcbdi/ m8wXy+yNtDxDL1PA9idSh0Qqbz7QpR6J1PcTy11P+Z7CUD69RRw1Q2IwlAhJpcXQS1N2 iJ7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686948156; x=1689540156; 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=rjsyh8HKup5upDCLPid4awp+IS7Z6M7SAZiVl4zctHA=; b=DgttXCgZE5QadZPP8+vUv6n6PW7pENDjh2kg+UVt8JdJElQCT6c1oa4YVLQH5U0/an ML2m6krXsKBrwpadzDfreMUL1oIKPDDDIjCpJRuZ/Ddf1lEJv9zvWI90cRa7FYcwLKv4 ud2Dw7MGUdTlIH5TVKz8psrv2kqTVNASdT/bZTW+o62/JOr3sYVgad4VeOG+GqSV6xvv aJ3aO20le0677+OMn6itKvA3wIPns5QsRcbQjMMaKV2MnUBNh0RyWCC63yMjy7aiuFU9 9OMfSxe2vFgRiHsut8xzpErRpS7j5vxvDaLvwiEMUH9PNpHjc5Wkgvg1FFEYOKUfeen5 hzwQ== X-Gm-Message-State: AC+VfDxr7TI43w92dSnKPwzYFPLPnbuDEu9HZ9N75/Chatklvobk162Z cY8CL4Wn+mi1Cl76CEaUntaORg== X-Google-Smtp-Source: ACHHUZ5aHzFuuNbQ75rOaWvIgySxBmXGkEhrRl3IzKxBPGadvKhHKdErE/kk8SIc/ZlQhePgwgtdGg== X-Received: by 2002:a05:6512:285:b0:4f8:41f6:5adb with SMTP id j5-20020a056512028500b004f841f65adbmr2090120lfp.46.1686948155803; Fri, 16 Jun 2023 13:42: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 d22-20020ac244d6000000b004f845907454sm770981lfm.232.2023.06.16.13.42.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 13:42:35 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 22:42:24 +0200 Subject: [PATCH v7 6/9] mmc: mmci: Retry the busy start condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v7-6-69a7164f2a61@linaro.org> References: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> To: Stefan Hansson , Ulf Hansson Cc: linux-mmc@vger.kernel.org, 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 v6->v7: - No changes. 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 e61aeca278ec..b38c471a7f8b 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -674,6 +674,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 */ @@ -694,21 +695,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 20:42: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: 693489 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 1B71DEB64DA for ; Fri, 16 Jun 2023 20:42:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232827AbjFPUmk (ORCPT ); Fri, 16 Jun 2023 16:42:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59358 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244916AbjFPUmj (ORCPT ); Fri, 16 Jun 2023 16:42:39 -0400 Received: from mail-lf1-x134.google.com (mail-lf1-x134.google.com [IPv6:2a00:1450:4864:20::134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3E0C03A91 for ; Fri, 16 Jun 2023 13:42:38 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id 2adb3069b0e04-4f619c2ba18so1602921e87.1 for ; Fri, 16 Jun 2023 13:42:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686948156; x=1689540156; 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=Zlsqifmiy9RHgiGZhPS+dUQEdIvZeWv3JFMxBbM8nEg=; b=rmijbMYGLGZ1raQKJLQ2P4DOrZXd9qydalbHVLmJYg2KC+f6rCQ/z6k3mtOKNZNirH 6hUH1T3OtNHaUHTY0wufHPUND38W2KRt10Q2C/x6C7dzvbQsw9ZCGxlqrByJjc/yj7PT bj0NypLuQOIPzwsQcOsVgu/1EKt9pkXRsUg6A9h4rMNQmn6Ej4m1kd4hOPuGqIroYZog wEtkMzLnX/+3oKpJpATKkde1YgY0cyKbYQdX2q3PRDyN+sDLUOpzd1lRFuP0xnQyaZor i89de23EH8LvpORkwh6+yx1K1N91QvQsTrOn/S7AvdJCDTenEYtr2Lt5FGjPYkEjaHu3 KYCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686948156; x=1689540156; 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=Zlsqifmiy9RHgiGZhPS+dUQEdIvZeWv3JFMxBbM8nEg=; b=RtH9FRGd7FvT1m1rynVIfOvqPGF7DYZq7t2fZnJqWhTnC0mM0NDENchHvD6WWHjDuY TY5CyGRrddVbXfw5mZ1PuxF9jRMbWK+6JmqgM2ZJ88sR4aEcw5O5VKWlknfm0JKdBtnH w2E0EoMDWch/AWniZTlfDR5yCd/6/m29TRmy7853oWMUqYsoKA6WEF+pKlaKP3EHljiR Vv5zKOExdwbD7JTcrQ3jLPOi9/FtCHXNKFgH2arsxwsWDwVhlLaDRmE54LA4Na+usfCx 1R4O2zvt9zmOvaxPffxwueXmRYoVN/Numm75gK5L1IUddWwDAW8okDPsfuLyAZ24xNAc MVWw== X-Gm-Message-State: AC+VfDy9CbGbBRvNQoyBVxey5miaOWvsDD4KBBRFiLMXLNZ0Dc9DHK/i mVHJct3lOHz1eFWcCvceBav9ug== X-Google-Smtp-Source: ACHHUZ5hzcjTLMcpSuRJdwyHwbgflB9k7mRnmcZLmblovwVPy6X2OIda+S4MSNIKUZDc/pBW0AdFSw== X-Received: by 2002:a19:2d17:0:b0:4f8:55dd:e726 with SMTP id k23-20020a192d17000000b004f855dde726mr2191563lfj.12.1686948156618; Fri, 16 Jun 2023 13:42: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 d22-20020ac244d6000000b004f845907454sm770981lfm.232.2023.06.16.13.42.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 13:42:36 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 22:42:25 +0200 Subject: [PATCH v7 7/9] mmc: mmci: Use state machine state as exit condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v7-7-69a7164f2a61@linaro.org> References: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> To: Stefan Hansson , Ulf Hansson Cc: linux-mmc@vger.kernel.org, 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 v6->v7: - No changes. 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 b38c471a7f8b..f89e4c44ea04 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -683,7 +683,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; } /* @@ -713,7 +713,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--; } @@ -722,8 +722,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; } /* @@ -742,7 +741,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"); @@ -751,7 +750,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; } } @@ -759,15 +758,18 @@ 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 true; + goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "busy status still asserted when handling busy end IRQ - will keep waiting\n"); - return false; + goto out_ret_state; } } return true; + +out_ret_state: + return (host->busy_state == MMCI_BUSY_DONE); } /* From patchwork Fri Jun 16 20:42: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: 693925 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 884A6EB64D7 for ; Fri, 16 Jun 2023 20:42:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242048AbjFPUml (ORCPT ); Fri, 16 Jun 2023 16:42:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231928AbjFPUmk (ORCPT ); Fri, 16 Jun 2023 16:42:40 -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 4FD3630EF for ; Fri, 16 Jun 2023 13:42:39 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4f6170b1486so1539361e87.0 for ; Fri, 16 Jun 2023 13:42:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686948157; x=1689540157; 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=E+YfQHHTaK1F9cdLN5V1bAawJ006MIRupdl+qM41oJM=; b=Sw1malw1PwQKzk3KvN+ch294ScTLM131f36w6dW3v0N38yk586wxB3+ZaHuAYFbFKY e9pN3xh5Iy0JjMy3/ldDaCVY9fa0ytUginx5WTYwiIiM9m1NFWDuEqlITYuQgjbsacPn iXkDM1KOyJy8vz07EHNjW+AlrlpgfSh5dJfPhThheOnLYyHtden5WPDIeLiCNCXo3jZj 4GmjFsm0I9CBKgLll+692O7cs3Yoa8wA50GfDjRlKmees9SuPa/J3F7ILKqJOxQ6/7sl achrCto1jenGY+qfe+mMzedS7GLcKf0DFzZtZCQDN0iCEUMOOnEvCYcy/h84XVdiwNqL Frmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686948157; x=1689540157; 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=E+YfQHHTaK1F9cdLN5V1bAawJ006MIRupdl+qM41oJM=; b=ZMjFatxxEcyAfoRjXPwXbbT7RW0t1MhRTW1c9q1CX5y1fBdeXbtcmBsWCUfWe5LMo/ 1gayAWctMg150uU/S+tboyHihyTzUlR2BPybeuu9je75tFE58XTA7mxlYhLcPsn5CYey YaxA0y8InrXKsVY0mQ41gJB8Az3jAVT0uzONnNezONEINJTlrxXrDIlD5JdXUex0BXIa 0IzpP0M3S0vHy3f4VQvhB6aqcMHduIDYTwB+suHrOOD+I1949QHRm0C/vfjgxqr7+xbU Pid/vtGr2wSqVHN4lFwCh3cp/d/HFcVdwsKWtS7o7muKqeeth/34A6nrOPEH2TR8D+S1 KK5g== X-Gm-Message-State: AC+VfDwOiStlizw1i+B3rsxd1X66kvyXV8jKClfkr4m2UcRA0P4mwcjB IxQOEfqLbj9nuQqd8L7CzuPKhCLh0lvHUdpm8bg= X-Google-Smtp-Source: ACHHUZ4mtCwLJm+5uyEd1opc6EH46BmcwDmg9yHNuT1qkZzqedblx0Ws0Q6pur2x9knD3KlQSgfHuw== X-Received: by 2002:ac2:4d97:0:b0:4f6:5473:7bf0 with SMTP id g23-20020ac24d97000000b004f654737bf0mr1134293lfe.21.1686948157674; Fri, 16 Jun 2023 13:42: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 d22-20020ac244d6000000b004f845907454sm770981lfm.232.2023.06.16.13.42.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 13:42:37 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 22:42:26 +0200 Subject: [PATCH v7 8/9] mmc: mmci: Use a switch statement machine MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v7-8-69a7164f2a61@linaro.org> References: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> To: Stefan Hansson , Ulf Hansson Cc: linux-mmc@vger.kernel.org, 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 v6->v7: - No changes. 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 f89e4c44ea04..d38ba9aa9be8 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -686,6 +686,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 @@ -696,7 +702,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 @@ -722,8 +728,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 @@ -736,12 +741,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"); @@ -750,23 +754,24 @@ 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 - will keep waiting\n"); - 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 20:42: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: 693488 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 CB13EEB64D8 for ; Fri, 16 Jun 2023 20:42:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231928AbjFPUmm (ORCPT ); Fri, 16 Jun 2023 16:42:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59378 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244916AbjFPUml (ORCPT ); Fri, 16 Jun 2023 16:42:41 -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 2F8DD3A91 for ; Fri, 16 Jun 2023 13:42:40 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f76a4c211dso1647139e87.3 for ; Fri, 16 Jun 2023 13:42:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686948158; x=1689540158; 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=c5hpKzB4PSZ5/2TnmnUTZaUgH+o6qsetcSAjQGCuqhI=; b=Au1TK4WFf+YdRUpL6SQUEpTJ0E5hYlwc41KWln1nCx8aHFI7gED0FRo02seqRrzMgp 4eoYrzUhihR7yK1XJzD5wlz0rzlr5FOE+5fOzUvAdtqku9GaLLkAX/7FEOPfVVayMMYi yQCsyKaZza4Dotq161PHvHk59GQ/HN4oC5IHtu0/FXznav8E5s0lnTj9xQ8et/cXWDlP ly7T7acoPTlRSXkYzXROe5A98xn2vBO7UBM04vW+vVZTLrAQdgENlBZjhIybJQEdwy2/ CW1xsK3kce95T1+43/4RDBdyy/EXZdb448hHZip+tPhp0Hsp5qt/L6uGFSOVLrljGw24 pOYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686948158; x=1689540158; 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=c5hpKzB4PSZ5/2TnmnUTZaUgH+o6qsetcSAjQGCuqhI=; b=QZGvBpb+wIioHgSTbJZkSEn47OYcnl+Dudpe+UurqSqBQZrct0P93J7O5saR2RZyGu J0xvu/vHVpWklgyNsQfI5RUmtsejx8nL+kNHXybvahFRgJ8pM/4qfC21A3/kjxV/B4l6 884WVtPICaO9qCxbZn7xZY5Rhl7ckr8ry9iP2eyA3sn918pfF7egbyVnFeseLiS1KWWQ 5nZ13DYeXa0RZGrP3LuhoSjxICkAP1Ys+U4MSWah4XxfSycZo8taKf+xo2s86FNqiAtB AcejfC7iCpHQ1sKHH3Ydcduvf/SN6RH8y+B0yoVzEz96U9URctbfpfMrztWIelmBowwU ov1w== X-Gm-Message-State: AC+VfDz+zKGh6SQgYuSey2yC5ZMHyxkvY7fJjfYx5VBezpTXtXMERhkf XcGVwlWF3vHklS2eLoABa4skpQ== X-Google-Smtp-Source: ACHHUZ6WMRB2Em41hyyDro/rcfLKRlO++fqjJsjyjoma0qkFjUfJhRi7+5ERaCqHV3x/qXpYj55k+g== X-Received: by 2002:ac2:4982:0:b0:4f6:4616:9f68 with SMTP id f2-20020ac24982000000b004f646169f68mr3008013lfl.38.1686948158511; Fri, 16 Jun 2023 13:42: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 d22-20020ac244d6000000b004f845907454sm770981lfm.232.2023.06.16.13.42.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 13:42:38 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 22:42:27 +0200 Subject: [PATCH v7 9/9] mmc: mmci: Break out a helper function MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v7-9-69a7164f2a61@linaro.org> References: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v7-0-69a7164f2a61@linaro.org> To: Stefan Hansson , Ulf Hansson Cc: linux-mmc@vger.kernel.org, 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 v6->v7: - No changes. ChangeLog v4->v6: - No changes. ChangeLog v3->v4: - No changes. ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index d38ba9aa9be8..309676c7e050 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 @@ -678,11 +689,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; } @@ -724,10 +731,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; /* @@ -749,18 +753,15 @@ 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 - will keep waiting\n");