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: 161201 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp884465vqu; Fri, 3 Nov 2023 01:49:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHovCqSTODT2Z/NnB4CvvtThYzR6SBgh6kIVgUk/p/opmPxvQhHftz01N0lfkLih9lPHZEn X-Received: by 2002:a05:6358:7e42:b0:169:9788:8741 with SMTP id p2-20020a0563587e4200b0016997888741mr9689948rwm.27.1699001385903; Fri, 03 Nov 2023 01:49:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1699001385; cv=none; d=google.com; s=arc-20160816; b=LpT2uWj/3VyEMmsINW7v+zq68k+Zfoe1VHgD42i+Ht2tRGBP6CtxHi4JyCWmVOMrED u9rfGD+Wb/Vm6eMfRXtxWvLyW45E54qiiQYJS+hdstMKbcMYD6VfXSzj7q1WApbSSe7d yccUlfNC+4OpfmcczVy3Zw+n76Ii+9tzJUeXmXnI/tVGIZt91YLYb+LiW9vazjx3LApL TFSTLbL3TJCZTOYKZCXMK0o3axD+jRCJ9lYH9Qd4w4UdBd+C5HQ5u7QH2FqAm7YdQSR+ rnnkHovhj5Gw0cylQgsDf2O/zbS12DW6jxhYBQRxTCeEHPUeyIC80PEIXCkPclnqGMEL y3QA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:organization :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=c20jI2zv0SoVtsSW7Cck3Ic1OgQTEoxnh2Wagk+pWZY=; fh=aIvDo0DPc47ZdKemLI3k3NodRhLAZ2m+5rlxdvTm1gA=; b=K0fhTYVhE51qsP/wAKpK+mW92BQzU1oYWgwgmnCVzfcD04EIcQiZ2yBRkj9hWdJqc9 UX1A8MQPP7kCLPMa01oSQXpasWVuAkyssK8A0OQhXClODpDrdiSPWUyFM0lvXhY6vqvQ sT8byuEe72Rposh+jW20v2qD4QvwzyJKc68JfRIB3vg2FgEcSf7kPkIwAtRUfk7/vMT9 LVc4nUiSwR8++YVzQB77sG5QS68QHE78g9pR80wTw7g+IY952f89PIN5wHyZnKyw7DvH y7WDwdHu/yuvrNVhEwT4CIyZb7qLLunNs52ZjWMElp4nY+NdqD6wnylhsjf54dMr9oXs sFMA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EAYuVz3f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id l12-20020a65680c000000b005b91496019esi1164574pgt.400.2023.11.03.01.49.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Nov 2023 01:49:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EAYuVz3f; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by agentk.vger.email (Postfix) with ESMTP id 8C3DD81B5D18; Fri, 3 Nov 2023 01:49:40 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235325AbjKCIs7 (ORCPT + 36 others); Fri, 3 Nov 2023 04:48:59 -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 X-Spam-Status: No, score=-1.3 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on agentk.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (agentk.vger.email [0.0.0.0]); Fri, 03 Nov 2023 01:49:40 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781532076824615070 X-GMAIL-MSGID: 1781532076824615070 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 --- 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);