From patchwork Wed Apr 5 06:50: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: 13201175 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 ED176C761AF for ; Wed, 5 Apr 2023 06:50:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236708AbjDEGui (ORCPT ); Wed, 5 Apr 2023 02:50:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236804AbjDEGuh (ORCPT ); Wed, 5 Apr 2023 02:50:37 -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 3FA5E3A8E for ; Tue, 4 Apr 2023 23:50:36 -0700 (PDT) Received: by mail-lf1-x129.google.com with SMTP id d7so305721lfj.3 for ; Tue, 04 Apr 2023 23:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677434; 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=qiM54vpHAvlLc1pdSUZ0ibiOpnt1h50sa+Xwq+/IdPw=; b=NrIzxPmGSXw+D7zfQWluH8L67j+7Z5MeDhw3zqZd5jjc3icWMdC0My/4MCvihvPCZK onfKRBKS/1mUMkIL0ijSbq5OZKFmkM1NQhIHMWsNNdkBB2uH63+Xz4ewbNurBVEzD7hK aGPKZki4YxEwtXS06+AZqPV1ZtxwX6QAZq8y6c4wVflu3XZ6mkjzqkfNaHo3vTF/FyBn UFYWXmOw0XASQOEAyKdMImwGlYsXqMzMeBwU3p8Os0jayDDQYpRZtfqzu9UIKllkaLdI eBdQ5I6i+vVFSZAeY1lowqoodbxbKsgy3Hv+ldudIDG7+VbTbkn/mGQssA21b77sTtI/ 4Bhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677434; 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=qiM54vpHAvlLc1pdSUZ0ibiOpnt1h50sa+Xwq+/IdPw=; b=4OIJl1rt8r4wHLF5Rp9BT/2VR928f4ex6u7HxqF0Ul7ZoXfGD9LJOVMHSrkjNuafKS CIwukbvMXFDFiY/5KdC8QTZb51CGQp64NQtisG+xc688R3DAur4l3bac1c7To0M1HZLM eGDwYo3qLxKH5ic2drU+ORCr9K/12nsHX8Km2/XBLNvIhyf2fK7fp2q2zjZVeMP2hDhl H2pBEEmi5Q5eNjyz913mZ8h1/HU7zXy4CrDpzuC+4wDYoH4S6TKLffPCkHXQO8F9DTr0 fFakDLvitebX9HDOVRHfgBmmZ2n/ZTc7d/HlnTlTuXIoyjpFq06npjUCFV6sItvFAb1l OlgA== X-Gm-Message-State: AAQBX9coK7NX3IJYz+VNTWa5hOOirBk7XMqOTIcNH30ayRAEREI0Ey9X a17L8jJNe+kJDStMXysviPAa9y3hABY/rRBuFHM= X-Google-Smtp-Source: AKy350bgqog8tYcwKoOQ4OK5DxI1lxCKOcQXvd+tbHHbQya6iSPCxpQb5CJPGihAIirSEe3C3YDMCA== X-Received: by 2002:ac2:55af:0:b0:4eb:2a0:4021 with SMTP id y15-20020ac255af000000b004eb02a04021mr1365131lfg.34.1680677434539; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:34 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:27 +0200 Subject: [PATCH 01/13] mmc: mmci: Only call busy_complete if callback defined MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-1-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 code unconditionally calls host->ops->busy_complete() if we get a busy response and the variant supports busy detection (variant->busy_detect = true). However there are several STM32 variants that define variant->busy_detect to true but do not define any busy_complete() callback. This looks like a recepie for a NULL pointer exception. Check that the callback is valid before calling it. Signed-off-by: Linus Walleij --- drivers/mmc/host/mmci.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index b9e5dfe74e5c..bc150c0d5eed 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1381,7 +1381,7 @@ mmci_cmd_irq(struct mmci_host *host, struct mmc_command *cmd, return; /* Handle busy detection on DAT0 if the variant supports it. */ - if (busy_resp && host->variant->busy_detect) + if (busy_resp && host->variant->busy_detect && host->ops->busy_complete) if (!host->ops->busy_complete(host, status, err_msk)) return; From patchwork Wed Apr 5 06:50: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: 13201176 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 12E14C76188 for ; Wed, 5 Apr 2023 06:50:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236967AbjDEGuj (ORCPT ); Wed, 5 Apr 2023 02:50:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236872AbjDEGui (ORCPT ); Wed, 5 Apr 2023 02:50:38 -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 054CC4200 for ; Tue, 4 Apr 2023 23:50:37 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id y20so45369689lfj.2 for ; Tue, 04 Apr 2023 23:50:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677435; 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=htFleaT/35Wjah78kezRl5LI+byd+7VcD53GDDOkAxc=; b=tuEyDg0Aqj7IhYFmgZGVe9k/t5Xn0hgxfRE4pF5UxJE793NNpx66snKWdLvDVypXdu AXT5JmeHVy9nEU4J/963/pJ3HnV4ZYGje5uR4hXtxp6oXyCCuY0u/JiA8RloiYp87WGs KBig72/DAEnoIKjZ7peOe8kchx9+5EJCVfgxev15TIV6MQFtGQRscCVsFvrsOuxwMcXw fJ734NL6O4rIkBjcqpbnRQB5AtPTjv3RvVR5xe4xVCvlPtXjuu9GOV3qzzc9YZ+0XBNW LGInzH33p401dYAEZPnA9fOJdmv344OMoHIoeFHZjFDOIJCMg9yvroeiCV01Vz/yTCXD CGGg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677435; 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=htFleaT/35Wjah78kezRl5LI+byd+7VcD53GDDOkAxc=; b=W4RjryPoexUnFCTZYbIw3d1jXeu02R5m/qD54I4dTe/QLc5a5hNoGfHqGEyUL8cRyL wf8PLO90MX+JtNPxI5C21WhCUm2xqC9CLA7y4gHxs0s5woYs715eMlfS3pbOacBMrofa tE4jEs55ql2yIve7xfJom+wZNf7svrxyfc4SSFQrcba6rdh67mJ0gn+Rk1XO4DMSsNtm FrmZy3CXQQSbZokYCgTB5hOHv67NcgFLWyaY5dRHwkrNcNgxFv7vT7MjNQSdRI5Z42JN 5vs4t81hhvV+t6Pz93HQz1edgdhhy+cpDSS35nTdhEvAt6MxHonyfBvs9RJYME4ZH5Wp wVEw== X-Gm-Message-State: AAQBX9foSANb3CcD4JsoeOjD1JDkAAPS458fIL9piZC2sV1wbOjpzm+e cLbhnguGXIoJFb1MP+a7no9PsQ== X-Google-Smtp-Source: AKy350avGN+mdyKp1Y9p5PspjESseEq6nRVNgL1kpPC1dh54xzy6aldKYul26M2/CP56SKCcB9pX5w== X-Received: by 2002:ac2:5482:0:b0:4db:3e2d:3efc with SMTP id t2-20020ac25482000000b004db3e2d3efcmr1215834lfk.10.1680677435406; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:34 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:28 +0200 Subject: [PATCH 02/13] mmc: mmci: Clear busy_status when starting command MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-2-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 --- drivers/mmc/host/mmci.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index bc150c0d5eed..3e08b2e95550 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -1238,17 +1238,22 @@ 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) { + if (host->ops->busy_complete) + 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; + + 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); + 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 Wed Apr 5 06:50: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: 13201177 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 E89FEC77B62 for ; Wed, 5 Apr 2023 06:50:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236978AbjDEGuj (ORCPT ); Wed, 5 Apr 2023 02:50:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51300 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236804AbjDEGuj (ORCPT ); Wed, 5 Apr 2023 02:50:39 -0400 Received: from mail-lf1-x12f.google.com (mail-lf1-x12f.google.com [IPv6:2a00:1450:4864:20::12f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D33E3A8E for ; Tue, 4 Apr 2023 23:50:38 -0700 (PDT) Received: by mail-lf1-x12f.google.com with SMTP id y20so45369736lfj.2 for ; Tue, 04 Apr 2023 23:50:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677436; 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=EzNDUri52+ydwnf/71tMhyZyGCHdCPy1yA6ftXOBwcg=; b=xwbw5c1tMoZpFDnTx4NAqBXZGcaMkUkhjWMiuO9UG19bRMZaouaHMfUN4Llg69zepE +24Zl+9gH8GGbC49btX52adt4iZBT+56J2Gl8mq1kqqYETj9CB1ggq8xt1lT1AFFBJL8 jV9TSGuFqFfBdLAAqbB1rIBXEbbM9j47YDVH8hv2sXeotgrrPi0SMWL3/o5+crv5YRtZ Syap8G15D341r3qyk3srGJ0SDgS82j8dQa0EAz0g5sLCNGNYqtsBS/8DzW29bZFd4bMG A9u4RVqqfPKV71XLzEHzD2S31RttzrFkdf/LHFkeGB0Sg/Aqv3Uu767EfWyVVbVSF0QY 57WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677436; 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=EzNDUri52+ydwnf/71tMhyZyGCHdCPy1yA6ftXOBwcg=; b=RH4aKkWWBjEnt5S0KkuN6bMsz6wSgnFhDI5IlPyZ3LJA4JeJjZFsVH5Klo4XW0/72B nPlsqEL+8KKkIMr9z9pfgKWFnL/AnvbBdsvUCUeYNgxYcu0xZSywFr9th/pBZmbOvRY7 SXP8Oz0W5hZbjttOvXRkM5y3idPQrIpf5D9NhJZTDwqxl8q0UA1ZuQ1Zf40NuhZYTxkT iVKhhU49SFiWde5kWudTM+0TIbQxKWZymwr+mn3oPDlu8Gzcar+obsizv3Xqwn+BJ9+0 8cLiA6Qs/qOiGvZwBUhFf3UbJzuEbZifUO8FXDgRtW+djNrvkF0oBObmymVbS+Z1qb0/ Rpkw== X-Gm-Message-State: AAQBX9ctext/TnC5V2JJTg+Oed0v4RqadkxCFNZLbVZlaX1ZRaSpZmlc CE+2lqnp5U3qULf27FHP4yiM5Q== X-Google-Smtp-Source: AKy350bFChkzu/xDuMrQEacxaYMKmPDwmQZtQnPBti5B1xqTDTgiwMx5x20RvKZlOVJIVjSyFspsEQ== X-Received: by 2002:ac2:5d46:0:b0:4ea:e296:fe9e with SMTP id w6-20020ac25d46000000b004eae296fe9emr1235549lfd.9.1680677436318; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:35 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:29 +0200 Subject: [PATCH 03/13] mmc: mmci: Unwind big if() clause MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-3-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 --- drivers/mmc/host/mmci.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 3e08b2e95550..3c1e11266fa9 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,17 @@ 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)) { host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); - return false; + 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; + } } /* From patchwork Wed Apr 5 06:50: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: 13201178 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 9DB21C7619A for ; Wed, 5 Apr 2023 06:50:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236872AbjDEGul (ORCPT ); Wed, 5 Apr 2023 02:50:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236779AbjDEGuk (ORCPT ); Wed, 5 Apr 2023 02:50:40 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFD764200 for ; Tue, 4 Apr 2023 23:50:38 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id k37so45379164lfv.0 for ; Tue, 04 Apr 2023 23:50:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677437; 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=cSJ4MzJQ8UoPiz3rGVKBpIQtOY1lklGXlYq7/mXSQCU=; b=kRXZrFDq4/sV1F5HRJwuIvnh6JTWv/kvEjyGrh00xAUixf6+JOCnJhimtch92xg/SL dkm7lhBjKbP6wPWTCSfjIh6ok49XTRZXSDvW3sj1aM7ED67Tk3HbXuxd9SVlGaWYZVb0 xKQhobCrl87z/3vKBIUZhU2ZwTsMtNyUi9JOmWrXM49z6Cz7706JKrK+rXB3YLcygQ12 1IoOkUPFTDJq/PWlHG5X8r4jBgDkA2Q61PrZWAQ1/b5HAmfb3mIo/qTn15JEX8JLB+PC u1sJLx3++5QK57WbglBk64Gs3aDItT93xvXQR/cI7cay/+iY6H4rQNR4XjbMfalkXw0h ZN5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677437; 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=cSJ4MzJQ8UoPiz3rGVKBpIQtOY1lklGXlYq7/mXSQCU=; b=jclIpPPvh38AYD32PVIcrEiWYsS2w49+Af5t3K7mqXlE2HzD5hVrauUyx/uE6jo7Rh zVFbl5SGFSC++JEfJ/nRJeWyJBNZBXrtF61XDWkC8tnGosPsVmswrb/zZlZFPdbPuBNc Tf6Y236kFFvV3Tuh0YEPQT14lZ/H6xZEC9RgtFm+0dC/UMQn78TudiyWrxSWznHW7soN ZelVnsUx1TlG2g8y+my7PrcqiNJ4Di6Du96YNaBhQ7b7PxjCWv4b5YIceFhffwI8cU21 KplX36a0yPLB0qbh6r/1T8E+34MhRiFH3BUxBEnVKtE/6F34fNzTxS0vML8v+XZYKjAx 65lg== X-Gm-Message-State: AAQBX9eVw75NHgQ5bhOSkej4GKOVI4gekXUeTiuq+l2agrN0M1lr5EYM WT33tUejr/O2leQsTiW94402tA== X-Google-Smtp-Source: AKy350Z8FesrBLZIGWRqwdr9YER0mju4LtzITsqbu9lQmVTwD33TDZguDxpYfgzVF655JsV+OwrlIg== X-Received: by 2002:ac2:46e4:0:b0:4e9:d53b:337e with SMTP id q4-20020ac246e4000000b004e9d53b337emr1257013lfo.45.1680677437096; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:36 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:30 +0200 Subject: [PATCH 04/13] mmc: mmci: Stash status while waiting for busy MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-4-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 --- 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 3c1e11266fa9..db3a8ce27a0e 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -704,6 +704,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 Wed Apr 5 06:50: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: 13201179 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 3FF3AC76188 for ; Wed, 5 Apr 2023 06:50:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236449AbjDEGum (ORCPT ); Wed, 5 Apr 2023 02:50:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236804AbjDEGul (ORCPT ); Wed, 5 Apr 2023 02:50:41 -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 E5A583A8E for ; Tue, 4 Apr 2023 23:50:39 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id k37so45379212lfv.0 for ; Tue, 04 Apr 2023 23:50:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677438; 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=JZaLiA0g44U1TRcntaLQYKCUF28R2/Q5H+MPwsKmLwc=; b=fL7wUylNUaTmX4XGMPv3Cf3g4V40XOfdDDRUJhuxhA1S73DqkqRsTKyTkpRo26F3I5 wYiswhO7fQSs/zhzMjc1rSdhzmAYgDucl/YGPmUPSD4/mT5Cc4ksFxdxx/h5oBn3KP2W 7ChV88hCqTnfVwOqgqDN57/4ncGkTnsTfvtEp250NJaW0UQVSs981X4E46XHW7rdXf8E iSagJzZW9Vc61fAU6Amnh7D02OZZOpa9vTxS6ckzHkPS1rJN7bmLTldumT91APF2Vldl ttmxnsQ2LZcprscsEi7Dp7bsDPEI0B8oN61ccha3C+Jr2DTFd5sy1VvHmPihFCFhgy4q D9+Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677438; 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=JZaLiA0g44U1TRcntaLQYKCUF28R2/Q5H+MPwsKmLwc=; b=AAPR9hYZA19ILOnMS5z/LnCa8csdo4h2GLDRxOdq20HMHaY5GUaCpaPNTIaJdmnEaQ pLxdIG/nXVua2hjIDdQKn09gbsuomunk00RmL4obZnfSo1r40ZofZZWmBv0g2ENUHI7v +SwuluOLRBZLwhqK344XfDhsVXcdw6xPtr2UTfAakR+cEN8EwnuXxAmK8t+tCk8IV5AZ BbL+Oy1vMfQjlGyYjJ40PnZQT2sahyHtGG14bxxT/HFQ9D7/Mmkv72dQFZYlG9vb/3ge ArWmA3hNoJxepP5q5ZW41xDvvyMc2Gg+Qe+HzCrnih2FcaX1tL3sXoaiHKZvrQIB7ym7 6PDA== X-Gm-Message-State: AAQBX9cOIv8YhK2DvgNRXmyaRI0Mu8jRSUdTnRTQLsK8xsWcsmGDsrQQ JkmqHKrgE1o7yoM4LHx284I6yw== X-Google-Smtp-Source: AKy350blL9duykk1KRNQnFkCyz/h8/m3XElkUTeiFRvWyhGuExbfjktkfA11jOcl64HmbSeHNW8YWQ== X-Received: by 2002:ac2:55a8:0:b0:4e8:3fc7:9483 with SMTP id y8-20020ac255a8000000b004e83fc79483mr1370064lfg.23.1680677438330; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:37 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:31 +0200 Subject: [PATCH 05/13] mmc: mmci: Break out error check in busy detect MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-5-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 --- 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 db3a8ce27a0e..13dec2e09164 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) { host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); status = readl(base + MMCISTATUS); if (status & host->variant->busy_detect_flag) { From patchwork Wed Apr 5 06:50: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: 13201180 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 50517C77B62 for ; Wed, 5 Apr 2023 06:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236999AbjDEGun (ORCPT ); Wed, 5 Apr 2023 02:50:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51420 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236804AbjDEGum (ORCPT ); Wed, 5 Apr 2023 02:50:42 -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 DA45646AC for ; Tue, 4 Apr 2023 23:50:40 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id q16so45303839lfe.10 for ; Tue, 04 Apr 2023 23:50:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677439; 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=y3hEnuBO3Z3EAaHvrNPA+CXdYyDV16bUmPpb/P3uEpM=; b=bS8QZTdCDuTDcyJ1AsakjW9MBQVd+JThH0c3L8QajEZRb3zdQFhBx1etjad7PZVtvj +pzseQFbF0w5/R4d6EkybhE3nTYEbZMdzuUIX8fnM2vTf+RJXhB6DhBdWU3l8P++mUJj DUyjzwJmRT20x2KXUXVI0iCHVNt5wsV4EyscPbX4NHNEZQlov/Cjx4JxUMXeB1arJDSm 44F1gb3TLqBV7tBpgWyPkVx0ZBkYUsG8bCJ3QZQ/IOhQnTdJVgD+n+8HGatjdmC/Kmf4 O4kXHDS51KIyLFFtdVvF0U4PMpdBk/sMgldDNYGlKpG8XmgrMjsHqSSrSSNaTcKuizoi JHmw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677439; 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=y3hEnuBO3Z3EAaHvrNPA+CXdYyDV16bUmPpb/P3uEpM=; b=r+K8rR0JGEJ/ptuAeGhsbvU7hJ/1qs6Ka/kb4/2Sm7vi2a1k2eVdmr0CtsIlUPTlXk NXqsp0upK6VcKq6jTbj1jb9wulSuGvna+u4yFiilGLbhCOeq9FExoSPyLo0GIEazfrOF hAbtruCmZYDydHvQCCU/T2OhWZlaJ5opX8NtNMPA0kJHRLMFyhi91KedwacGQ+x3Ul91 bVBsjb2EqBAwPtJhvxQBzNY9OTsFIbS/A74sm7plOWVVdQcMlPfgy+pYRXhCo3SlRtAi 7M/NijRLITqy15C9joiW+//1duGY6Ys3QHBG3FSNUT5AKsPL2ECO7h7lE68C+miLoudV k4cw== X-Gm-Message-State: AAQBX9f4RL2gd0BJXaNwHhdsWTJO6Fxy/OsO/dHD/Rs8AY6xExrPD07X uwiZ06vNYQCfYHOYb64s4UgbJw== X-Google-Smtp-Source: AKy350YM/jGSXJNB+fwDQ+O120FuphFZJmJ0Zb85Nj+dXjSbxQyyy+LZ5qSOTdQ5Cbn/Os2O0GeS5g== X-Received: by 2002:ac2:558d:0:b0:4e6:9b01:b92b with SMTP id v13-20020ac2558d000000b004e69b01b92bmr1192437lfg.67.1680677439163; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:38 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:32 +0200 Subject: [PATCH 06/13] mmc: mmci: Make busy complete state machine explicit MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-6-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 --- drivers/mmc/host/mmci.c | 58 +++++++++++++++++++++++++++++++------ drivers/mmc/host/mmci.h | 16 ++++++++++ drivers/mmc/host/mmci_stm32_sdmmc.c | 6 +++- 3 files changed, 70 insertions(+), 10 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 13dec2e09164..c14a7732386e 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) { host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); status = readl(base + MMCISTATUS); if (status & host->variant->busy_detect_flag) { @@ -696,6 +697,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; } } @@ -711,11 +713,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; + } } /* @@ -724,11 +755,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; } @@ -1259,8 +1297,10 @@ mmci_start_command(struct mmci_host *host, struct mmc_command *cmd, u32 c) } if (cmd->flags & MMC_RSP_BUSY) { - if (host->ops->busy_complete) + if (host->ops->busy_complete) { + host->busy_state = MMCI_BUSY_IDLE; host->busy_status = 0; + } if (host->variant->busy_timeout) { if (!cmd->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 Wed Apr 5 06:50: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: 13201181 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 D4863C761AF for ; Wed, 5 Apr 2023 06:50:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236804AbjDEGuo (ORCPT ); Wed, 5 Apr 2023 02:50:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51422 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236985AbjDEGum (ORCPT ); Wed, 5 Apr 2023 02:50:42 -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 875AF4200 for ; Tue, 4 Apr 2023 23:50:41 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id x17so45372189lfu.5 for ; Tue, 04 Apr 2023 23:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677440; 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=h7+5pU+r96Qz2w0wNTiDpH3eRUOcskPk55XY3zWiSmk=; b=zgWbUgX/XfiSWni75W9Bj0RZ1KnO1TF7F0GaVsByzr2hWpatcrvkwvEY9UQD3VKBuE 1q0xiP3XRDRrEmuHfNtCITo+UFbTrxvQISanWWfFooW7rA56xHFsfNlJmo58pwU4zWyz 1SPMxoD1RgrXN3+8OZaX1ZSgu/KjL+oiyRuaXkWZLbGhrbHYdpQI+k5eC497CJ2Hashr +LgFfHHaGUY8lBoZUKeRv20slfoKQak3McmU52ROLAhoJlfe9dNWyztgLPIxzTDkPFAK PItfnSfCC3EhAdgIh8Dw0sL3FqRP5fuYJmbLKJWdo5AMordUGt+bOenQlbCi5s7MhAbA Vfig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677440; 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=h7+5pU+r96Qz2w0wNTiDpH3eRUOcskPk55XY3zWiSmk=; b=H5P40BL7cjBI2Df+b2iBAig/yA1hpHS96e5tMF8QqKAQbMXqSBWWS05oOaRD3RKUpt IyYNxwobfFnch08ubvoCZkrdTHxA7UdVxZYalmmJ/+STWFoCVtjlwRubtBxEMzTr8rjG YIpnobWyo1H2LR8qlE57v526g9Q4joR0bD0U29Ca3u6q2BooGEnWOjBN2+FoG12PuCCr 5GWmm5ZPGmBpG4JjC4WEGrVEFk6YsGYbDmBAiFq/uX6I2hoGUk7Zk2qJs8/T0hh/jbDL IXCvRHMjrT0fVONgtuM8kdn6dQDweUzxnbYbrir6KSlXZDIRoBlMI2UfvZn+GUKYgnAf YKKw== X-Gm-Message-State: AAQBX9evEnBddPoM55BkZXNY3PriUCvCjVcc62ZMyZTi3FvwjNFxQ4hQ 0hUJz7uMA+76CwQYHoGMnA7VrzwG1kVnQLkNu0M= X-Google-Smtp-Source: AKy350Y9Ih333G9FNO5tvFGMZKM2N4TIypLFGpKiUu5kNp4TOyhAj5kFHyeL59gAQNbpRzZR1MD6aw== X-Received: by 2002:a19:7506:0:b0:4e8:5392:492c with SMTP id y6-20020a197506000000b004e85392492cmr1275150lfe.43.1680677439946; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:39 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:33 +0200 Subject: [PATCH 07/13] mmc: mmci: Retry the busy start condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-7-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 implementit to be certain that we can catch this glitch if it happens. Signed-off-by: Linus Walleij --- drivers/mmc/host/mmci.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index c14a7732386e..670b1622d282 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,22 +685,29 @@ 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) { host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); - 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; + while (retries) { + 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; + } + 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 Wed Apr 5 06:50:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13201182 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 85ACBC76188 for ; Wed, 5 Apr 2023 06:50:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236779AbjDEGuo (ORCPT ); Wed, 5 Apr 2023 02:50:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51454 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237022AbjDEGun (ORCPT ); Wed, 5 Apr 2023 02:50:43 -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 5A41F4699 for ; Tue, 4 Apr 2023 23:50:42 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id bi9so45296992lfb.12 for ; Tue, 04 Apr 2023 23:50:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677440; 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=SedxMfIaYADPukzZhH8Geg5DKkhSk0IMn5jBUH6WQ7c=; b=sKYVbnpmuCmXmd11jodJYOCxpGxuL4BUxhbyfMi7lHX+/WmeAsgbyeFU+pBvpdGJj/ OSnbKCfMGCyjjWSZ38H+KyCuzhMLZaPq2YToZ9JW2ZxKAUrdZLm3wl4M3D/Oc9hXknUj XvMyrnjRXYdI7dr5Jn0/y9KDi2+GwG/aWmACwMLAj0GWVr5gX6qEM4bcFeDuLtomHt/3 LPkjTMQtaPQRf5YNR2A0ManO7FtcQG3hpjQ+QSR7zoora7/kYXp85roBnnJbk0zfpjAd xLmaiHUU/GQ0jfvAQk+vTJdYYwrUdl2SDCYzAVe3a1pk95EgftcjpI94ROWB5gVnlQra WZ7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677440; 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=SedxMfIaYADPukzZhH8Geg5DKkhSk0IMn5jBUH6WQ7c=; b=5tw7NOnbrtRqEIzSEpynF55U/hBq7zaCEvc/ofRJEFQ4D6Mf24QmUsZuX2pNOL70yt s/FsAlmLvxOCoFb5tcjWp9+67lW33wmXLSoYP5LNm4/LidvjkSSqewRSObuSjOh5LyRK IOuH7DxX2/y31ckzRnok2hi8Kfs7kJlBiXRhfu04IE1fYVF0Ed87frmLIhBNYN9MJgYP ckNztJWkz3TeaqxVgPKfyJafEEpQhQwB+jXfMEA9oE5q0FU4acpsA7+Yufyr0AbPJvKj qmEbYuhSjA7NX/0UAJC7LeUZj6MhbnkJJL9RyhYKYiC64Mp5QO2U5Ch56uKZ8B2erN01 IqQQ== X-Gm-Message-State: AAQBX9cWODsKUPS2XocFNKzeExbfSovo6fPNEKeBfnEQqi/AXVRnS2X0 nVwIo0vLEmvdCj94sZdOENN+6g== X-Google-Smtp-Source: AKy350ae5XuGbnSNHcqmrQvRUyQYF8kbODHnokFj4Kv5Dc/ENzkhYswUuLUVjYMfQR/kno9SN1buSw== X-Received: by 2002:ac2:43c2:0:b0:4d8:56d8:92ee with SMTP id u2-20020ac243c2000000b004d856d892eemr1205865lfl.35.1680677440764; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:40 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:34 +0200 Subject: [PATCH 08/13] mmc: mmci: Use state machine state as exit condition MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-8-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 --- 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 670b1622d282..734e8364b2f6 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; } /* @@ -697,7 +697,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); host->busy_state = MMCI_BUSY_WAITING_FOR_IRQS; - return false; + goto out_ret_state; } retries--; } @@ -706,8 +706,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; } /* @@ -726,7 +725,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"); @@ -735,7 +734,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; } } @@ -744,7 +743,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"); @@ -753,7 +752,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; } } @@ -767,7 +766,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); @@ -776,9 +775,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 Wed Apr 5 06:50:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13201183 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 32B63C7619A for ; Wed, 5 Apr 2023 06:50:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237023AbjDEGuq (ORCPT ); Wed, 5 Apr 2023 02:50:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51508 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236964AbjDEGup (ORCPT ); Wed, 5 Apr 2023 02:50:45 -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 5407249ED for ; Tue, 4 Apr 2023 23:50:43 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id bi9so45297038lfb.12 for ; Tue, 04 Apr 2023 23:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677441; 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=L/SmBW/GkWFXqDOQZgjdK6e878vcBSCxZ/ZaM+lu/CM=; b=CXUCGJB4hYnoAKHMAECayVXuAgAvyVtfc23qS+2hMtlWTROX2TKQJqETvCTUjeSa3s lCo+VCUDw+LlxqKqtPHddrVfeLPSbE5EIuGaH8YsglzkAOLVyjbOsoFrQnez/egAI3GX 1+nujNi5QGVuqlEL9VwCUYtria6NBbyzd7efucK6nm9A9A5jm4hfcgRvMkLFtE/aJVMt JpDgxt10H2d8buIX2x8L6uWzJwQRYzMIYwMEYoIok1w4x+Np87IbGyBnAKPtZaRD3rmb y4D1r5x8NPkMOXhnYNQbymTwA7Z2lHQXTiZymdR1KPHWam0lxRKZ64Q++zYP/SUj63Ca dXIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677441; 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=L/SmBW/GkWFXqDOQZgjdK6e878vcBSCxZ/ZaM+lu/CM=; b=owgQ3oBQEsX7fxDVSGBGLd/qtpB1yW5pi6f1QtaprbpaDwU3ZsCQOQlAVMSv6mw6CC pdlDcYu2TakEVBtY+H7iDH4tOX+ezc7+NjKnPyhYp/x2ynumFdgNBcSEu7XRbnzCweqA DnMWd/8AlrBSnK82pgUaH35Ol0Ra3oHoeofc3xlxOTRoBCO6uePE+ET8wsdDLjO/GTGD HZZA6MlC11dvcg0V5almwg7agyeIaqVU1OLFthEkN7xy4z731ELgZIx5p6ImAgxgEjxa NIvW+8IeKxCagzv71EF3pxBHuM4MGI8EMPMhD1CWHrFBbtJC+JeluFFCi1AIVpn7PGp6 CBvg== X-Gm-Message-State: AAQBX9ff/N+oKwg5dTyDUkX86uV3Xtb7riTG47d/drNd6dZ1ukkUg8rD 4rQheUDe9l1qoU4/BpbOc5EDSw== X-Google-Smtp-Source: AKy350a3RuFZiKyjRYefevxxRtGIx0ndWexlaTbianqmBPW+3FVCUBdrLSmoVGHHODX/1i06RCnk+g== X-Received: by 2002:ac2:42d7:0:b0:4bb:9415:38a2 with SMTP id n23-20020ac242d7000000b004bb941538a2mr1154549lfl.51.1680677441634; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:41 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:35 +0200 Subject: [PATCH 09/13] mmc: mmci: Use a switch statement machine MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-9-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 --- 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 734e8364b2f6..626467c212d6 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: host->busy_status = status & (MCI_CMDSENT | MCI_CMDRESPEND); while (retries) { status = readl(base + MMCISTATUS); @@ -706,8 +712,7 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) writel(readl(base + MMCIMASK0) & ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; - goto out_ret_state; - } + break; /* * If there is a command in-progress that has been successfully @@ -720,12 +725,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"); @@ -734,16 +738,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"); @@ -752,9 +754,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 @@ -762,11 +763,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); @@ -775,9 +775,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 Wed Apr 5 06:50:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13201185 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 A7F1EC761AF for ; Wed, 5 Apr 2023 06:50:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237059AbjDEGur (ORCPT ); Wed, 5 Apr 2023 02:50:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237022AbjDEGup (ORCPT ); Wed, 5 Apr 2023 02:50:45 -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 4C69C4699 for ; Tue, 4 Apr 2023 23:50:44 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id g17so45347286lfv.4 for ; Tue, 04 Apr 2023 23:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677442; 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=I/3dUAFFLmPEFbiRTS4QngmloNK4Qd6ucFKUCirU0Nk=; b=PqF2iMYy26F8ui+o5n25ZjqFFxg0RWAdxpUr3ygoyMAFP9AOkKFOHPfupNdleCFFNt g39dxrJBvUh7WakLlpQgDohuiaEZLicAWbIjEbTALTi8JvxKYs9/d97c3Pq9m5VNnvAy A1yPZzxRQCbBE+90IVK/X1t2S8HA17iX9CVvSQjj/D8PW8KGlM73/9URycHaIFC2P95G iCmFx6c3+9mz7eWSEBW0ItsDgZvytOgZ0+/ELLHYFSlxyozyC3zOybycPr56U9lwQCGj PONc5BVn1PTAr9396slH/wpfXYzhs5Hy+I01OnvGO+MfRM6GdGf6OPi2zlBrXUzug6Se NbBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677442; 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=I/3dUAFFLmPEFbiRTS4QngmloNK4Qd6ucFKUCirU0Nk=; b=l6dEjgtDa+g+JPBapdop5ltnJe8vZ6bMyJko7Gobbr4GtqWfPzZWL96Zj7d88QGnqs 94gVNyAHzKha5XurMdQ2a//91Q4XzEP9k4cBmd+AejMMC3crrpHYDX5Wc8U48E8VNGPv fqhMLCdUgFDvGn+gMOR5N5nfIpjN6Jg82wydqzuyaVXafl978KJDDuYrdYMasZoXWb0r nAPvsZhxnTrXIrQLnUvyIKKvAjm1tkwKJsD/FpITb0YJ8q4CIiWgexyhFqUFhrLA3SQg 1C07/TOsnBlhdNengS/9eTHveBWluoc/q4NwlXEyky0YgNgC2UoTWQfqRfBmzcYVCOru D+ng== X-Gm-Message-State: AAQBX9eZq2vQl/ro6kqMxHeIcxsePcU/y0oy7agRTWbVA5dbl4StgRva kxlj9Zyiq205ucNwtCRy8bMFrA== X-Google-Smtp-Source: AKy350anT1t3PDljDUP4k7VGAmBPC9H/vSN1JvcbTRndDQRSdbciABahibCG71axu4PZDIK6R1vgXA== X-Received: by 2002:ac2:4201:0:b0:4ea:e0e7:d12d with SMTP id y1-20020ac24201000000b004eae0e7d12dmr1089962lfh.1.1680677442688; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:42 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:36 +0200 Subject: [PATCH 10/13] mmc: mmci: Break out a helper function MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-10-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 --- 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 626467c212d6..92a49726cf83 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; } @@ -708,10 +715,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; /* @@ -733,11 +737,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; @@ -749,11 +749,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; @@ -768,13 +764,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 Wed Apr 5 06:50:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13201184 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 21F5AC76188 for ; Wed, 5 Apr 2023 06:50:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237041AbjDEGuq (ORCPT ); Wed, 5 Apr 2023 02:50:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51542 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236985AbjDEGup (ORCPT ); Wed, 5 Apr 2023 02:50:45 -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 EDA40448C for ; Tue, 4 Apr 2023 23:50:43 -0700 (PDT) Received: by mail-lf1-x134.google.com with SMTP id q16so45304016lfe.10 for ; Tue, 04 Apr 2023 23:50:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677443; 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=OU29sLolFBKRRrM2SwmaE/cR08rID9BsyZV6fg0YEgw=; b=hV2g54d4uBykzRRJFGdYqiFznq7btZms3bs8Iwn3lBuAlDhrl660foVDXeaOb+yChM jLZsKYiFd5IN2KrdTGCQR+qP6Lq+kLNkP3fPvd5HHL9vHgNzHwQQQab4kUMskCSJ5mwf dZr3pQD5KswfyfofrZ1is7+YjNm3HbuwRS6BODkaLmfDgmpWswjtMqj14vWcfaq5Evqf r8tn6a0iTtDo5r6tU2xfTm8gzgmDhPjDJvHLQMUDAt6B1JddEbV0UgS5v4e3tvu/8kea t3F94MMl1byFw4ZZaUn3BhcZR7UMC4fqyL9adCDdMUb5xV2lKRYRfjT8SWDTwr8IcXbR vM6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677443; 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=OU29sLolFBKRRrM2SwmaE/cR08rID9BsyZV6fg0YEgw=; b=gw1rSFFDO3x5ZZiOhhPD4V9FBGAfxcuGgZPCz58Wvd5sWiMUCD42s1ZnN+dEUHdTip lary4ILvMaV436QIVqxZ/M7FRRqpJo50sdUhhKMDBwmAUgoLVNOJNaqZd62Kmyq5Ky+Z cVYB7Q+wla9a0yyVhWN9FQHWkBbNY2yGRnbz4lByUh0o07mBJK9stZdGmkbgGBYczlMI 18L7trXk3WqHOjqfL4G0lJXWkfve5sXkU2umVA6qRp95ApW4BevqV+i+xNWDGKBO4fgB GWCXgGemIc7zKd61seF0XP4StuWeb0R94Xthb2nUNaCYV4c0I8aAT4j2Voo3ahhtquFj EPDw== X-Gm-Message-State: AAQBX9faJ/pjc0Rh3uzjdroglNAKz1C9DolcqrgeeOHDITE07ZgRtPP+ xvh9bYHPFiVEuo37sXSmvUi1ug== X-Google-Smtp-Source: AKy350bXEOoF7rWHlL8fzzu9oZ6TpABcoX6qKLw/hdmAZRE2CTKjJfGoxdLsmUdIdnZ//D83I+EngA== X-Received: by 2002:a05:6512:971:b0:4dc:537c:9229 with SMTP id v17-20020a056512097100b004dc537c9229mr1340343lft.30.1680677443526; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:43 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:37 +0200 Subject: [PATCH 11/13] mmc: mmci: mmci_card_busy() from state machine MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-11-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 the state machine triggered from the busy detect interrupts will determine if the busy is complete or not. Signed-off-by: Linus Walleij --- drivers/mmc/host/mmci.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 92a49726cf83..2779d4985b63 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -339,6 +339,14 @@ static int mmci_card_busy(struct mmc_host *mmc) unsigned long flags; int busy = 0; + if (host->ops->busy_complete) { + if ((host->busy_state == MMCI_BUSY_IDLE) || + (host->busy_state == MMCI_BUSY_DONE)) + return 0; + else + return 1; + } + spin_lock_irqsave(&host->lock, flags); if (readl(host->base + MMCISTATUS) & host->variant->busy_detect_flag) busy = 1; From patchwork Wed Apr 5 06:50:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13201186 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 37E5FC77B62 for ; Wed, 5 Apr 2023 06:50:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237022AbjDEGus (ORCPT ); Wed, 5 Apr 2023 02:50:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236964AbjDEGuq (ORCPT ); Wed, 5 Apr 2023 02:50:46 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12F574224 for ; Tue, 4 Apr 2023 23:50:44 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id bi9so45297140lfb.12 for ; Tue, 04 Apr 2023 23:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677444; 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=CZrJBp7bxoAmhQOHIoV/FMgL+sx0Mt/COQx900KM35s=; b=D835TBlnPHXFapIYypyvesZyxDll44ncpPJGjZwsseIA5xWhnue7u2ULafh1Mgvlyl YjOJnM9b1HvRutgUyTLMGE9WGf6JrOU5dCfzBHzSR9Xe9WsLTG3P0nk32KZLeApRbArW 1aTojXFiLyOZCOrmdOWZ8Obte3mGx9cOW+LFjTie0AJ7BkkteCuMtcrbwogRUbV492yD I0qerXkzk2jh31o7/Nblf4zTN2ZfqNrPnAu8LPYXmQAM6ryqEwQfXThVxA1ToSpqiKtA 8PtVjFrfVLTf6xoCgJ3R/pKXWYQgACPT4TkZStnVJRUDf/DnbGV8LKHsQ32rl+0cGHTQ jF9A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677444; 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=CZrJBp7bxoAmhQOHIoV/FMgL+sx0Mt/COQx900KM35s=; b=G7ogzZWqt+0bNbx5ZcOWgBR25rD72lckOeg9UpV2Ic3wkNcxKzI3ZbvksdPI4wa+7Y UKaNv29J7E3fydYo+ecFGN5UKTIQC2ExpOYXRlWiSx9iC1gcRZjZ4Hlc4P/sxpn0mFv+ L/EqhSu+LkSuiD7pLMipf0+V8MryJLkJOWHXgmGgDp/EOU6QRGqSH+ubzmnVMOZS4MzH tnTiY5K6NG5tDbML/fJwugI2elBM5h5xaN2sKDxniTUpa2sZ6AUshJ887zx/+LzXlMAN CkpEt0z2OC6b8/jdG89WBX/0KDeP3xA2bhiegp5a4kgINmZOBxxxMstWK7eVQLVhpSL2 TKAw== X-Gm-Message-State: AAQBX9eII+gn1movcP/gaDfWlI56cftwtS3hc1tJtbjlx176WZwt0F3D HVcmj4tFHVtjiMIkH807tsyrGQ== X-Google-Smtp-Source: AKy350Zfmmhvue8OWU2JCIJTabcCiWBx+GsA92bBBeT4onZu0NRIuw9PoqPJ9+MUp9fIf0TV7V/lsw== X-Received: by 2002:a19:750b:0:b0:4dc:82b0:4c68 with SMTP id y11-20020a19750b000000b004dc82b04c68mr1159856lfe.50.1680677444364; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:43 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:38 +0200 Subject: [PATCH 12/13] mmc: mmci: Drop end IRQ from Ux500 busydetect MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-12-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 --- 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 2779d4985b63..a4c9a3a9b037 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -753,7 +753,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"); @@ -761,20 +761,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 Wed Apr 5 06:50:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13201187 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 551D9C7619A for ; Wed, 5 Apr 2023 06:50:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236964AbjDEGut (ORCPT ); Wed, 5 Apr 2023 02:50:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237057AbjDEGur (ORCPT ); Wed, 5 Apr 2023 02:50:47 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B7FED4C1A for ; Tue, 4 Apr 2023 23:50:45 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id k37so45379488lfv.0 for ; Tue, 04 Apr 2023 23:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1680677445; 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=zcZ9y9W+kNr4GBYOAR4xnjODyPefHWCpFtqS37+iUts=; b=gMLto1DLl/Sx9jxGvY87jOLVl+RaMCy6/eY6Vd1oc0NXA/fkhQi7mdiJVPf/4uUw4w epGyNKWarhygTVgdGdFd2F0HydW+/wM7ucdD4afTj/ZzkZlqEsPfsFxzxx1jZLi0FjbT ctfHRk6wMDCMC/wgAx+am68tjp5gBUTJdtXqp/ALH6TR6E+43nDwpzoQIPFThat5aOFf YB8Qkb37KBFWpH0nzT0gF/sbhGTRdzQLAjBFsu9gSdhLRIfoep9ulxwYy4p5wekqCJuH i63Y9k5MK/9AuHyB72sVj+mngQq84RyOp6RUabUvfRIUQlIkpt94jWHdueu272RPy0cu Nczw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680677445; 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=zcZ9y9W+kNr4GBYOAR4xnjODyPefHWCpFtqS37+iUts=; b=FQY+SUo5cAnxSjc/YNbxyDYcN7IauYVcKzPrt11Fewl3WL2TI2Id0wGwZIZNg4bMei 9a7qRqhIN2oH2zwp/9dcmypqD39X5CXOOJ8ryMOR6JhBwJxc1pD+MA4I5kI9Zu6WWPQT RMYce6Cwzv3vcj8QjmQkjGOfYni8P9zIYrijeJynPa1jktKOA8U3sh1J8mn1DZS/k1s2 +/3RzM6hTsu1fAwcxWrPxSLl/ie3q1YczCQU3Y/6l8utpIvdMnPqgkeJJPfEiVY/2h97 CiOpBFvWMtBkUCPNR8DHOt561VjV2yN7gxrEGuGtZ9G19Pz02AhT3WZp/Kv3ho2mub4+ 8IYg== X-Gm-Message-State: AAQBX9cvJYwdv7ZBE5EuaSAz33iomx9Y71cjmOZQiX8ElZNK2DcL8eeS xOOQebU/cIzOI80bIC+F3baMMQ== X-Google-Smtp-Source: AKy350bedXi6nON6Hsk4E2elo/aP6kp1nyIyXYsBfNXheLNsp7UfhlR4yXl7PiZOfDd/fXrwywGSOA== X-Received: by 2002:a05:6512:3912:b0:4e0:2455:3ade with SMTP id a18-20020a056512391200b004e024553ademr1278336lfu.60.1680677445163; Tue, 04 Apr 2023 23:50: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 z19-20020ac25df3000000b004eb274b3a43sm2683086lfq.134.2023.04.04.23.50.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 23:50:44 -0700 (PDT) From: Linus Walleij Date: Wed, 05 Apr 2023 08:50:39 +0200 Subject: [PATCH 13/13] mmc: mmci: Add busydetect timeout MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v1-13-28ac19a74e5e@linaro.org> References: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v1-0-28ac19a74e5e@linaro.org> To: 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 --- 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 a4c9a3a9b037..d8abd2cad2af 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -742,6 +743,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"); @@ -753,6 +756,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), @@ -1495,6 +1499,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); @@ -2308,6 +2328,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)