From patchwork Fri Nov 3 08:47:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 13444406 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 AEAEAC4332F for ; Fri, 3 Nov 2023 08:48:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235205AbjKCIsW (ORCPT ); Fri, 3 Nov 2023 04:48:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36862 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234700AbjKCIsV (ORCPT ); Fri, 3 Nov 2023 04:48:21 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC920D49; Fri, 3 Nov 2023 01:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699001296; x=1730537296; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=CPuhmUzZJc2Fl7jj6hRHKrHunHiCOvwemWTDCOmv/zs=; b=S2OVV7QbJBG4ROH5g7x7WP85fN7u/NMpnfj5NsBWMC223/6pCHHcVzCa hEp61SZNH9r3Abv/blWconm2ynk2benzTUh8tkKX1n2LOxvfXjz5Uu7QG d54u+0WBCUCAtRFthwyVWxTOm2U9qkRZSQW8PSDbAYd3nXq1P7WXF63ze 3k0+1IrEzZaTlRYK6UWbugLxW4ILMk6YbvPKFaljfV4PIfLn0bRE8GdB2 6uh74a4YFQjpclnV9Iyt/AyX2Yel8cYeg3mkPpeTb3tBfGTHTbYo7Pq/a FYSvPO/NhgY2PNvg3CM9Ag2zDYot1pFVrKjvHpmWt/826gdWwbLDLouuU Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="391774495" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="391774495" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="796556454" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="796556454" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.133]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:10 -0700 From: Adrian Hunter To: Ulf Hansson , =?utf-8?q?Kornel_Dul=C4=99ba?= , Radoslaw Biernacki , Gwendal Grignou , Asutosh Das Cc: Chaotian Jing , Bhavya Kapoor , Kamal Dasu , Al Cooper , Haibo Chen , Shaik Sajida Bhanu , Sai Krishna Potthuri , Victor Shih , Ben Chuang , Thierry Reding , Aniruddha Tvs Rao , Chun-Hung Wu , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 1/6] mmc: block: Do not lose cache flush during CQE error recovery Date: Fri, 3 Nov 2023 10:47:15 +0200 Message-Id: <20231103084720.6886-2-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103084720.6886-1-adrian.hunter@intel.com> References: <20231103084720.6886-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org During CQE error recovery, error-free data commands get requeued if there is any data left to transfer, but non-data commands are completed even though they have not been processed. Requeue them instead. Note the only non-data command is cache flush, which would have resulted in a cache flush being lost if it was queued at the time of CQE recovery. Fixes: 1e8e55b67030 ("mmc: block: Add CQE support") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter Reviewed-by: Avri Altman --- drivers/mmc/core/block.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 3a8f27c3e310..4a32b756b7d8 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -1482,6 +1482,8 @@ static void mmc_blk_cqe_complete_rq(struct mmc_queue *mq, struct request *req) blk_mq_requeue_request(req, true); else __blk_mq_end_request(req, BLK_STS_OK); + } else if (mq->in_recovery) { + blk_mq_requeue_request(req, true); } else { blk_mq_end_request(req, BLK_STS_OK); } From patchwork Fri Nov 3 08:47:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 13444407 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 5D561C4332F for ; Fri, 3 Nov 2023 08:48:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234700AbjKCIsa (ORCPT ); Fri, 3 Nov 2023 04:48:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345458AbjKCIsZ (ORCPT ); Fri, 3 Nov 2023 04:48:25 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E457CE; Fri, 3 Nov 2023 01:48:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699001301; x=1730537301; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cUiL60Q4g/FFeKGo5RkMz2YZaR7uRt/yFxzYNEjO4gA=; b=NKXXyLYpweIc7hJ3SvY3EM5xJp2MFZk4bOIRRbMaVOO9jAHogMCWzVNo Edx3sTvdR9Wwfh4UEXZ1Zvz5qTFVi5ORIj3e68GcDmlQA8dpI4OKs4Qkw Xv4xOz0opBRTGYzaK4U4ud5AnFXS3GjIlI7uWpQ5uB1RL93EXs8lM4hK8 FpmDNKtJBUnhlctjZx0imqMu7Vk2JEc5E1atDFzPPYlOp9C8Yb/wWuf+u fbGJQiXs3w3otEDJ6E8tUUOgjE7IOQ7ubWWff3pQjdwKicH0p2wuqCkHT 2hDjrJfqdTcCHMOmnvPYTEGDPKaKro1NiEDQw00K3g2Qw3rgAK09sYZk6 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="391774512" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="391774512" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:20 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="796556495" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="796556495" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.133]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:15 -0700 From: Adrian Hunter To: Ulf Hansson , =?utf-8?q?Kornel_Dul=C4=99ba?= , Radoslaw Biernacki , Gwendal Grignou , Asutosh Das Cc: Chaotian Jing , Bhavya Kapoor , Kamal Dasu , Al Cooper , Haibo Chen , Shaik Sajida Bhanu , Sai Krishna Potthuri , Victor Shih , Ben Chuang , Thierry Reding , Aniruddha Tvs Rao , Chun-Hung Wu , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 2/6] mmc: cqhci: Increase recovery halt timeout Date: Fri, 3 Nov 2023 10:47:16 +0200 Message-Id: <20231103084720.6886-3-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103084720.6886-1-adrian.hunter@intel.com> References: <20231103084720.6886-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org Failing to halt complicates the recovery. Additionally, unless the card or controller are stuck, which is expected to be very rare, then the halt should succeed, so it is better to wait. Set a large timeout. Fixes: a4080225f51d ("mmc: cqhci: support for command queue enabled host") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter Reviewed-by: Avri Altman --- drivers/mmc/host/cqhci-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c index b3d7d6d8d654..15f5a069af1f 100644 --- a/drivers/mmc/host/cqhci-core.c +++ b/drivers/mmc/host/cqhci-core.c @@ -984,10 +984,10 @@ static bool cqhci_halt(struct mmc_host *mmc, unsigned int timeout) /* * After halting we expect to be able to use the command line. We interpret the * failure to halt to mean the data lines might still be in use (and the upper - * layers will need to send a STOP command), so we set the timeout based on a - * generous command timeout. + * layers will need to send a STOP command), however failing to halt complicates + * the recovery, so set a timeout that would reasonably allow I/O to complete. */ -#define CQHCI_START_HALT_TIMEOUT 5 +#define CQHCI_START_HALT_TIMEOUT 500 static void cqhci_recovery_start(struct mmc_host *mmc) { From patchwork Fri Nov 3 08:47:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 13444408 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 96710C4167B for ; Fri, 3 Nov 2023 08:48:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345509AbjKCIsd (ORCPT ); Fri, 3 Nov 2023 04:48:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345458AbjKCIsc (ORCPT ); Fri, 3 Nov 2023 04:48:32 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AC4AD4C; Fri, 3 Nov 2023 01:48:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699001306; x=1730537306; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=mP6Mo3+Nw1x4znWMjlIBYHth0os2JHcW2xe8+eVSNhY=; b=fUibThXbGmf0QqoFUB5cbQ5iuRSh+YG9qigwb0TOFsHLSOe4NuSiAAzM BFmrIDEZPOiolOW6IN9CBfIhMBTKIkRksxpVcx8HwDxNfqWRkFn2NoRst vjlv2TpgjoWbw1SI65bkIvQGD7XpXKkelXLGNgxyOx8WlWVzlkCt/A8Pe 3A/GCQkq2GJvhmnTxgLbQrh8/DPk/Cfb6DBvH4LwW4862BdZ/DVDLGXDE mBU4EHZZXQVrdAnG/istQBgazXHiBxAu1NtIw8M0EGxk91YTqqACONJAM AkGomgHyra78/arJDac2tE1eafOSx0FXAzgWLkAB+wkZpRtcyTK55HpV6 w==; X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="391774560" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="391774560" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="796556575" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="796556575" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.133]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:20 -0700 From: Adrian Hunter To: Ulf Hansson , =?utf-8?q?Kornel_Dul=C4=99ba?= , Radoslaw Biernacki , Gwendal Grignou , Asutosh Das Cc: Chaotian Jing , Bhavya Kapoor , Kamal Dasu , Al Cooper , Haibo Chen , Shaik Sajida Bhanu , Sai Krishna Potthuri , Victor Shih , Ben Chuang , Thierry Reding , Aniruddha Tvs Rao , Chun-Hung Wu , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 3/6] mmc: block: Be sure to wait while busy in CQE error recovery Date: Fri, 3 Nov 2023 10:47:17 +0200 Message-Id: <20231103084720.6886-4-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103084720.6886-1-adrian.hunter@intel.com> References: <20231103084720.6886-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org STOP command does not guarantee to wait while busy, but subsequent command MMC_CMDQ_TASK_MGMT to discard the queue will fail if the card is busy, so be sure to wait by employing mmc_poll_for_busy(). Fixes: 72a5af554df8 ("mmc: core: Add support for handling CQE requests") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter Reviewed-by: Avri Altman Reviewed-by: Christian Loehle --- drivers/mmc/core/core.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 3d3e0ca52614..befde2bd26d3 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -553,6 +553,8 @@ int mmc_cqe_recovery(struct mmc_host *host) cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT; mmc_wait_for_cmd(host, &cmd, 0); + mmc_poll_for_busy(host->card, MMC_CQE_RECOVERY_TIMEOUT, true, MMC_BUSY_IO); + memset(&cmd, 0, sizeof(cmd)); cmd.opcode = MMC_CMDQ_TASK_MGMT; cmd.arg = 1; /* Discard entire queue */ From patchwork Fri Nov 3 08:47:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 13444409 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 9F094C4332F for ; Fri, 3 Nov 2023 08:48:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235195AbjKCIso (ORCPT ); Fri, 3 Nov 2023 04:48:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235601AbjKCIsl (ORCPT ); Fri, 3 Nov 2023 04:48:41 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21285D50; Fri, 3 Nov 2023 01:48:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699001311; x=1730537311; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OV8RDN4Bd1h5BCWBvIEygF8kScSzkr9HTkdiwgabNdQ=; b=XlnPH/nDTf/57/Y//gWwmw8gGwYDhUoO2SCsp3/zUXCNxiqhyDhCl9Qi 12OS/RnYc8sIjh3SueKOyLsEyT+EFvDZDvDCKj509QRUcz8Az/AIoB1qW FGtLhbIaMi55bXLxO7wFMvD5GOuERP5N4NeZsUIcDPYeFuQ6W6Ew2293u pUK4w5XYr1e11C2CHPpT3B+5/VFFTS1kr5pjP0YIZEv9xcs00yC+oVaq7 syLoXXYikAAET/BpiPcugQFsn9WTqVPvG9Kzk6EI6pmQjqaYUqguPWHkL ee/Q3hUL6VzeBwJCbemZY6gRT24fea2a+SnBR/e/4fnM3y8aeq+PeJ68r A==; X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="391774580" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="391774580" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:30 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="796556610" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="796556610" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.133]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:25 -0700 From: Adrian Hunter To: Ulf Hansson , =?utf-8?q?Kornel_Dul=C4=99ba?= , Radoslaw Biernacki , Gwendal Grignou , Asutosh Das Cc: Chaotian Jing , Bhavya Kapoor , Kamal Dasu , Al Cooper , Haibo Chen , Shaik Sajida Bhanu , Sai Krishna Potthuri , Victor Shih , Ben Chuang , Thierry Reding , Aniruddha Tvs Rao , Chun-Hung Wu , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 4/6] mmc: block: Retry commands in CQE error recovery Date: Fri, 3 Nov 2023 10:47:18 +0200 Message-Id: <20231103084720.6886-5-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103084720.6886-1-adrian.hunter@intel.com> References: <20231103084720.6886-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org It is important that MMC_CMDQ_TASK_MGMT command to discard the queue is successful because otherwise a subsequent reset might fail to flush the cache first. Retry it and the previous STOP command. Fixes: 72a5af554df8 ("mmc: core: Add support for handling CQE requests") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter Reviewed-by: Avri Altman --- drivers/mmc/core/core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index befde2bd26d3..a8c17b4cd737 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -551,7 +551,7 @@ int mmc_cqe_recovery(struct mmc_host *host) cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; cmd.flags &= ~MMC_RSP_CRC; /* Ignore CRC */ cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT; - mmc_wait_for_cmd(host, &cmd, 0); + mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); mmc_poll_for_busy(host->card, MMC_CQE_RECOVERY_TIMEOUT, true, MMC_BUSY_IO); @@ -561,10 +561,13 @@ int mmc_cqe_recovery(struct mmc_host *host) cmd.flags = MMC_RSP_R1B | MMC_CMD_AC; cmd.flags &= ~MMC_RSP_CRC; /* Ignore CRC */ cmd.busy_timeout = MMC_CQE_RECOVERY_TIMEOUT; - err = mmc_wait_for_cmd(host, &cmd, 0); + err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); host->cqe_ops->cqe_recovery_finish(host); + if (err) + err = mmc_wait_for_cmd(host, &cmd, MMC_CMD_RETRIES); + mmc_retune_release(host); return err; From patchwork Fri Nov 3 08:47:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 13444410 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 D85ABC4167B for ; Fri, 3 Nov 2023 08:48:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1345563AbjKCIsp (ORCPT ); Fri, 3 Nov 2023 04:48:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235812AbjKCIsn (ORCPT ); Fri, 3 Nov 2023 04:48:43 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26745D61; Fri, 3 Nov 2023 01:48:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699001316; x=1730537316; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=YBQ2Lyin2LPrMqjjbn7C4KRka6RjCsHhKLhnLJTF9TM=; b=BlEtAY7q1rtdlgC+Q5k7lk9cmmOvLixbDgsRfZ8p4KhTolwLpgpgSPGD 4tqpYTD2rN4nEOhH34BROmvvXPj/WRxalJ8uH/0d32MevQQDLixYkJ0nl x9YO5XBzplL7Hth6MwBa98671/z7kcDIwcZFgM/6Ou4nbM/QZuELLSDX1 XWLxDyhzLNHIYcTDkW6rmU8Yv6Lty3SrsNVV29nUDobbxAqKRLrkaBNJq fqcO0aeVN/jB5reKKKS00kgUIfxyPLj6x8eLz//mTrzGfjBhss3WYB30o zF4vIYR/W9Fhb1sjpUaSWoOPK+RQG60YBdQAV2Yrn+wsT2Ntw25YjaJFZ g==; X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="391774604" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="391774604" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="796556657" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="796556657" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.133]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:30 -0700 From: Adrian Hunter To: Ulf Hansson , =?utf-8?q?Kornel_Dul=C4=99ba?= , Radoslaw Biernacki , Gwendal Grignou , Asutosh Das Cc: Chaotian Jing , Bhavya Kapoor , Kamal Dasu , Al Cooper , Haibo Chen , Shaik Sajida Bhanu , Sai Krishna Potthuri , Victor Shih , Ben Chuang , Thierry Reding , Aniruddha Tvs Rao , Chun-Hung Wu , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 5/6] mmc: cqhci: Warn of halt or task clear failure Date: Fri, 3 Nov 2023 10:47:19 +0200 Message-Id: <20231103084720.6886-6-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103084720.6886-1-adrian.hunter@intel.com> References: <20231103084720.6886-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org A correctly operating controller should successfully halt and clear tasks. Failure may result in errors elsewhere, so promote messages from debug to warnings. Fixes: a4080225f51d ("mmc: cqhci: support for command queue enabled host") Cc: stable@vger.kernel.org Signed-off-by: Adrian Hunter Reviewed-by: Avri Altman Reviewed-by: Avri Altman --- drivers/mmc/host/cqhci-core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c index 15f5a069af1f..948799a0980c 100644 --- a/drivers/mmc/host/cqhci-core.c +++ b/drivers/mmc/host/cqhci-core.c @@ -942,8 +942,8 @@ static bool cqhci_clear_all_tasks(struct mmc_host *mmc, unsigned int timeout) ret = cqhci_tasks_cleared(cq_host); if (!ret) - pr_debug("%s: cqhci: Failed to clear tasks\n", - mmc_hostname(mmc)); + pr_warn("%s: cqhci: Failed to clear tasks\n", + mmc_hostname(mmc)); return ret; } @@ -976,7 +976,7 @@ static bool cqhci_halt(struct mmc_host *mmc, unsigned int timeout) ret = cqhci_halted(cq_host); if (!ret) - pr_debug("%s: cqhci: Failed to halt\n", mmc_hostname(mmc)); + pr_warn("%s: cqhci: Failed to halt\n", mmc_hostname(mmc)); return ret; } From patchwork Fri Nov 3 08:47:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Adrian Hunter X-Patchwork-Id: 13444411 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 CE6C7C4332F for ; Fri, 3 Nov 2023 08:48:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234672AbjKCIs6 (ORCPT ); Fri, 3 Nov 2023 04:48:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346130AbjKCIsr (ORCPT ); Fri, 3 Nov 2023 04:48:47 -0400 Received: from mgamail.intel.com (mgamail.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68241D4E; Fri, 3 Nov 2023 01:48:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1699001321; x=1730537321; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=QAFnkZjCEfVfLAK7KrRDYxSV98mreyDoOmktfPkz9T8=; b=EAYuVz3f2lClSgtM2RSUPVYMj9S0Of5Gbsa/B4PXfWcNw3qZ1GMNhkOp qDU2Mk0O1vFKxWUWZt/kYbAbHLeuDM47x55pn8btRglA80I0jNWoELfa0 E7/d7ergo2NekkcshsxT/xkfzLgjqjbFXhFhrL19Za7JLhGOQpGRDgMb5 JFCj6+ZuNxpji4jDXZH+Ujq6TBuPankpxMMYn8BBJ19WhvK8fhZCCTFNS ZjDlQVmMHW66H8qnTOjVWGlOaL2MZspi7IdkFXvGVJW83e0VSXuwaocuQ ErXnVK2aJLqg2nRlKT660u8hGy/3guR+jtcNqZBW9vMKL3cgpLCgPM+Ge Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="391774620" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="391774620" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:40 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10882"; a="796556695" X-IronPort-AV: E=Sophos;i="6.03,273,1694761200"; d="scan'208";a="796556695" Received: from ahunter6-mobl1.ger.corp.intel.com (HELO ahunter-VirtualBox.home\044ger.corp.intel.com) ([10.252.51.133]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Nov 2023 01:48:35 -0700 From: Adrian Hunter To: Ulf Hansson , =?utf-8?q?Kornel_Dul=C4=99ba?= , Radoslaw Biernacki , Gwendal Grignou , Asutosh Das Cc: Chaotian Jing , Bhavya Kapoor , Kamal Dasu , Al Cooper , Haibo Chen , Shaik Sajida Bhanu , Sai Krishna Potthuri , Victor Shih , Ben Chuang , Thierry Reding , Aniruddha Tvs Rao , Chun-Hung Wu , linux-mmc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 6/6] mmc: cqhci: Fix task clearing in CQE error recovery Date: Fri, 3 Nov 2023 10:47:20 +0200 Message-Id: <20231103084720.6886-7-adrian.hunter@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231103084720.6886-1-adrian.hunter@intel.com> References: <20231103084720.6886-1-adrian.hunter@intel.com> MIME-Version: 1.0 Organization: Intel Finland Oy, Registered Address: PL 281, 00181 Helsinki, Business Identity Code: 0357606 - 4, Domiciled in Helsinki Precedence: bulk List-ID: X-Mailing-List: linux-mmc@vger.kernel.org If a task completion notification (TCN) is received when there is no outstanding task, the cqhci driver issues a "spurious TCN" warning. This was observed to happen right after CQE error recovery. When an error interrupt is received the driver runs recovery logic. It halts the controller, clears all pending tasks, and then re-enables it. On some platforms, like Intel Jasper Lake, a stale task completion event was observed, regardless of the CQHCI_CLEAR_ALL_TASKS bit being set. This results in either: a) Spurious TC completion event for an empty slot. b) Corrupted data being passed up the stack, as a result of premature completion for a newly added task. Rather than add a quirk for affected controllers, ensure tasks are cleared by toggling CQHCI_ENABLE, which would happen anyway if cqhci_clear_all_tasks() timed out. This is simpler and should be safe and effective for all controllers. Fixes: a4080225f51d ("mmc: cqhci: support for command queue enabled host") Cc: stable@vger.kernel.org Reported-by: Kornel Dulęba Tested-by: Kornel Dulęba Co-developed-by: Kornel Dulęba Signed-off-by: Kornel Dulęba Signed-off-by: Adrian Hunter Reviewed-by: Avri Altman --- drivers/mmc/host/cqhci-core.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/mmc/host/cqhci-core.c b/drivers/mmc/host/cqhci-core.c index 948799a0980c..41e94cd14109 100644 --- a/drivers/mmc/host/cqhci-core.c +++ b/drivers/mmc/host/cqhci-core.c @@ -1075,28 +1075,28 @@ static void cqhci_recovery_finish(struct mmc_host *mmc) ok = cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT); - if (!cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT)) - ok = false; - /* * The specification contradicts itself, by saying that tasks cannot be * cleared if CQHCI does not halt, but if CQHCI does not halt, it should * be disabled/re-enabled, but not to disable before clearing tasks. * Have a go anyway. */ - if (!ok) { - pr_debug("%s: cqhci: disable / re-enable\n", mmc_hostname(mmc)); - cqcfg = cqhci_readl(cq_host, CQHCI_CFG); - cqcfg &= ~CQHCI_ENABLE; - cqhci_writel(cq_host, cqcfg, CQHCI_CFG); - cqcfg |= CQHCI_ENABLE; - cqhci_writel(cq_host, cqcfg, CQHCI_CFG); - /* Be sure that there are no tasks */ - ok = cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT); - if (!cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT)) - ok = false; - WARN_ON(!ok); - } + if (!cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT)) + ok = false; + + /* Disable to make sure tasks really are cleared */ + cqcfg = cqhci_readl(cq_host, CQHCI_CFG); + cqcfg &= ~CQHCI_ENABLE; + cqhci_writel(cq_host, cqcfg, CQHCI_CFG); + + cqcfg = cqhci_readl(cq_host, CQHCI_CFG); + cqcfg |= CQHCI_ENABLE; + cqhci_writel(cq_host, cqcfg, CQHCI_CFG); + + cqhci_halt(mmc, CQHCI_FINISH_HALT_TIMEOUT); + + if (!ok) + cqhci_clear_all_tasks(mmc, CQHCI_CLEAR_TIMEOUT); cqhci_recover_mrqs(cq_host);