From patchwork Fri Jun 16 08:30:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Linus Walleij X-Patchwork-Id: 693933 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 56B6BEB64D8 for ; Fri, 16 Jun 2023 08:30:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242847AbjFPIat (ORCPT ); Fri, 16 Jun 2023 04:30:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S245274AbjFPIap (ORCPT ); Fri, 16 Jun 2023 04:30:45 -0400 Received: from mail-lf1-x12c.google.com (mail-lf1-x12c.google.com [IPv6:2a00:1450:4864:20::12c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 22A6F30C6 for ; Fri, 16 Jun 2023 01:30:44 -0700 (PDT) Received: by mail-lf1-x12c.google.com with SMTP id 2adb3069b0e04-4f655293a38so505023e87.0 for ; Fri, 16 Jun 2023 01:30:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1686904242; x=1689496242; 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=VIAYT4EhNtooRN/YpBr1IWKLrfpKpu0Ay5MDZbIHZMY=; b=IAeb2948KGs6CDAVxiBSy3g+HWmJ1nE/JB8ILamXBsDnNU2xytjnjn+btSFEjG5IWm zKn27oHP5ielDEfuvSrFW9vZR8fMzwssSY2nxp02U0ryHDJZbdg1YoxlEpinvW0GAWtP E14TDsqbEd3eyhEOhKzFsNbogLSAaICsBNGZsLkOFwrfDLiwFZIqmSUMK3hRxnXr6snz Om+d7nos3XNsEyopvqluXDzqz9Id0FvrUZ5nLpsg2dNcJ/5nlCsKY/G3jAbX56ivttnr i017MSRbWWLuboaVJIkdzEgaS54gJNEcyc+RXAidqZY4Fm241fXIoaerlvbAK8Pqs29N I2KQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686904242; x=1689496242; 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=VIAYT4EhNtooRN/YpBr1IWKLrfpKpu0Ay5MDZbIHZMY=; b=GEoFxemw6c0mHwuzS6YJXqdms+ytH5uSGhjOBKlUp0SoBk5eXbz+IrsfO6AjWNRLg3 7YO9z+OoiymeQvWlH7PPwmd1tpPw6n5EdwUacMitHYTYvcW0q6QqyvZ0xrRhOxWVkqvg 6tEhoIf7B98dtu/1IEfkG6sZTwuJzpneRgidK28Mxq9gh6R7HuXKcm3qkgj+dIbYMW8Q zgPC01vPHEVP6xmBHT0HB6kqt5fQre5tU951o24pu/viqFU3JGUWFM1nkzhzYNzuWdvS ZJApCWjcdyr5IaxMONQ2P2AZyzJ7Ymxw9hTxGQ7MtKLlx2nWTqkSyeUOuHynd8WAAviF 0DTw== X-Gm-Message-State: AC+VfDznzFlvIpHevqsEFNEPHHSh9l/e/ZDpP2gpY3p09vsdvnSZrets 9rou6fobz9t71zERrRyEodQK3A== X-Google-Smtp-Source: ACHHUZ7rIHaAlGRnwQv12z82K3cMuxWAUUScNh5plFCiBswWEM+Pw4JL281Q7AwruztwWncE/VaEtw== X-Received: by 2002:a05:6512:329b:b0:4f6:2cd8:5ffe with SMTP id p27-20020a056512329b00b004f62cd85ffemr748562lfe.1.1686904242507; Fri, 16 Jun 2023 01:30: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 j8-20020ac25508000000b004eb44c2ab6bsm2918106lfk.294.2023.06.16.01.30.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 01:30:42 -0700 (PDT) From: Linus Walleij Date: Fri, 16 Jun 2023 10:30:40 +0200 Subject: [PATCH v6 8/9] mmc: mmci: Use a switch statement machine MIME-Version: 1.0 Message-Id: <20230405-pl180-busydetect-fix-v6-8-b850ec8019f3@linaro.org> References: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> In-Reply-To: <20230405-pl180-busydetect-fix-v6-0-b850ec8019f3@linaro.org> To: Yann Gautier , Stefan Hansson , Ulf Hansson , Maxime Coquelin , Alexandre Torgue Cc: linux-mmc@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com, Linus Walleij X-Mailer: b4 0.12.2 Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org As is custom, use a big switch statement to transition between the edges of the state machine inside the ux500 ->busy_complete callback. Signed-off-by: Linus Walleij --- ChangeLog v4->v6: - No changes. ChangeLog v3->v4: - No changes. ChangeLog v2->v3: - Rebased. ChangeLog v1->v2: - No changes --- drivers/mmc/host/mmci.c | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c index 437b2144ecd4..f7522c3fe849 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_DONE) { + case MMCI_BUSY_DONE: /* * Save the first status register read to be sure to catch * all bits that may be lost will retrying. If the command @@ -712,8 +718,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 @@ -726,12 +731,11 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) * both the start and the end interrupts needs to be cleared, * one after the other. So, clear the busy start IRQ here. */ - if (host->busy_state == MMCI_BUSY_WAITING_FOR_START_IRQ) { + case MMCI_BUSY_WAITING_FOR_START_IRQ: if (status & host->variant->busy_detect_flag) { host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); writel(host->variant->busy_detect_mask, base + MMCICLEAR); host->busy_state = MMCI_BUSY_WAITING_FOR_END_IRQ; - goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "lost busy status when waiting for busy start IRQ\n"); @@ -740,15 +744,13 @@ static bool ux500_busy_complete(struct mmci_host *host, u32 status, u32 err_msk) ~host->variant->busy_detect_mask, base + MMCIMASK0); host->busy_state = MMCI_BUSY_DONE; host->busy_status = 0; - goto out_ret_state; } - } + break; - if (host->busy_state == MMCI_BUSY_WAITING_FOR_END_IRQ) { + case MMCI_BUSY_WAITING_FOR_END_IRQ: if (!(status & host->variant->busy_detect_flag)) { host->busy_status |= status & (MCI_CMDSENT | MCI_CMDRESPEND); host->busy_state = MMCI_BUSY_DONE; - goto out_ret_state; } else { dev_dbg(mmc_dev(host->mmc), "busy status still asserted when handling busy end IRQ\n"); @@ -758,11 +760,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; - return true; + default: + dev_dbg(mmc_dev(host->mmc), "fell through on state %d\n", + host->busy_state); + break; + } out_ret_state: return (host->busy_state == MMCI_BUSY_DONE);