From patchwork Thu May 18 21:02:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 13247386 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CCCD7C77B7A for ; Thu, 18 May 2023 21:03:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=GP9TQXtkdL+MM90jAen2NCmjwxt+qj9cOekQ2pI8feM=; b=4QQ6WmImmgQb0g IoBM+xOSHyB7URwBJztVcr4spdqPoYVMi8NT7VtJ5TRTqYh8FTnHsfixG66unhFH4grrkf8+b03XI mDWF8f8nVYt1QHbQB5w/OWUvU5f9K0mhaiMyWVdVrFhdRqlxhsmaq2PYfmZDIgaRhN/Bt2+ezkW32 Ns84mo1bZcSTLBSEYhRfhlp1Qo4TesOXgZRqHk7B9cBcQdddt6++0GbVacWdQZyPNtN48Ld4hWive qt6vzTX3f4R9++mgS8qD8rGF0a8LMyelgSJCH0TikLsZfSfgKAnuda5ZbUMPIzB+pw280EzKZHXTr F8cXhe9xJMYgpIOStD4Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1pzkm5-00EBc5-0h; Thu, 18 May 2023 21:03:01 +0000 Received: from mail-lf1-x12f.google.com ([2a00:1450:4864:20::12f]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1pzkm1-00EBaR-2Y for linux-arm-kernel@lists.infradead.org; Thu, 18 May 2023 21:02:59 +0000 Received: by mail-lf1-x12f.google.com with SMTP id 2adb3069b0e04-4f24d4900bbso2903235e87.3 for ; Thu, 18 May 2023 14:02:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1684443773; x=1687035773; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4G/ypnTlXP4W9YP4yFZVLIByppuXGY5xpC0A2Ptkn3o=; b=DFdOB7eKGcqxxSuHNtOSjwyWO2dAjoPmGTPylJ1IpBJspPmIa+u/kfPx8yW4k5Zt+v b6IShs/9RGcBNORsufG0710YZkbM5P6skUh6ytsSfeQwH324NbXsBmzzRempIb099Sy9 bL67x+FwyC0QkrBDdfGAbq/DSfDWtrrzEIus64R/ANDCwWmZan23ILgPKO1AOiyboJpF Z+myqL7xGiS1azy96kVbX8Glmt+OqnBxPRaHtC+LI0CerhrKny/VDWMZDzQMRsBggJtM Zw5dec39O7OcO8zUNd0MOH9QutA4w7UFLCSQjC1qpY/HTuaQ8l03RzmCpLD7l03Bx1/r wNkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684443773; x=1687035773; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4G/ypnTlXP4W9YP4yFZVLIByppuXGY5xpC0A2Ptkn3o=; b=jypMPN/UwSWeDmUkVw5oEaNiAMA0P6BJRx8o7ZciU4KCbb79IUyXNkS6jKO8JeeS5w 4VK3W9t0sPdOVdSqi/bQCVjlNmJyqaCX6kPtE9hjrrAdwCAWhPMGrVOa727BbU0BTClg QkoXfqu+c7/BTxigy1LwExU9mWF7NcIXO1vLn/SkKToMJse3SoOmi6d+5L61AdtGTMz4 rbPc9vRvDE5PSj4sPSlHn6nLRSDRuEUx4KqAkv5dxEX7bx+OhVVGNzufP136wMC/PzKf sX1KhXLpohpUSgOgxJSwrOAc1JBTWwuLCY9I2zPj1tG0Is9iZfJu/zEqt6LTEQaw/Odi b4+Q== X-Gm-Message-State: AC+VfDxQDBXbGX7NDuBF8uXe305DBJ4yMYYmlGsAxQuzN5LHURiCzTGy imV661JFJDy+N6+2Rf2Rtr/yUg== X-Google-Smtp-Source: ACHHUZ6p5AD48mQDJSPMyJR1xmeALZxRdNttjQaQKjI3gTpssk9h4Kvj4nRFh7kTVHC8olyzm88VKw== X-Received: by 2002:ac2:5973:0:b0:4f3:7a8c:d46c with SMTP id h19-20020ac25973000000b004f37a8cd46cmr62166lfp.66.1684443773143; Thu, 18 May 2023 14:02:53 -0700 (PDT) Received: from Fecusia.lan (c-05d8225c.014-348-6c756e10.bbcust.telenor.se. [92.34.216.5]) by smtp.gmail.com with ESMTPSA id i13-20020ac25d2d000000b004b40c1f1c70sm354976lfb.212.2023.05.18.14.02.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 May 2023 14:02:52 -0700 (PDT) From: Linus Walleij To: Ulf Hansson , linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Stephan Gerhold Cc: Russell King , Linus Walleij , stable@vger.kernel.org, phone-devel@vger.kernel.org, Stefan Hansson Subject: [PATCH v3] mmc: mmci: Add busydetect timeout Date: Thu, 18 May 2023 23:02:46 +0200 Message-Id: <20230518210246.2401737-1-linus.walleij@linaro.org> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230518_140257_828576_40B6DF3B X-CRM114-Status: GOOD ( 19.56 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 and Codina phones. Notice that the hardware time-out cannot be used, because the state machine in the MMCI will not see that something is wrong. Cc: stable@vger.kernel.org Cc: phone-devel@vger.kernel.org Cc: Stefan Hansson Signed-off-by: Linus Walleij --- ChangeLog v2->v3: - Took out the most urgent fix from the pile of changes and send separately, without the rest of the refactorings that were used for debugging the issue. After this the Skomer and Codina with problematic eMMC boots fine. - Now just a single patch! - This version should be easier to backport as well. --- drivers/mmc/host/mmci.c | 22 ++++++++++++++++++++++ drivers/mmc/host/mmci.h | 1 + 2 files changed, 23 insertions(+) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index f2b2e8b0574e..f3349fb99590 100644 --- a/drivers/mmc/host/mmci.c +++ b/drivers/mmc/host/mmci.c @@ -37,6 +37,7 @@ #include #include #include +#include #include #include @@ -695,6 +696,8 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) if (host->busy_status && (status & host->variant->busy_detect_flag)) { writel(host->variant->busy_detect_mask, base + MMCICLEAR); + schedule_delayed_work(&host->busy_timeout_work, + msecs_to_jiffies(10)); return false; } @@ -1429,6 +1432,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); @@ -2242,6 +2261,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 e1a9b96a3396..de2c1436f4cd 100644 --- a/drivers/mmc/host/mmci.h +++ b/drivers/mmc/host/mmci.h @@ -437,6 +437,7 @@ struct mmci_host { void *dma_priv; s32 next_cookie; + struct delayed_work busy_timeout_work; }; #define dma_inprogress(host) ((host)->dma_in_progress)