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: 670686 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: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: 670685 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: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: 670684 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: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: 670683 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: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: 670682 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: 670681 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: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: 670680 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)