Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp3203375rdb; Tue, 26 Dec 2023 22:29:01 -0800 (PST) X-Google-Smtp-Source: AGHT+IFlOxaebg0k1RWyf+toXWkiX8RMcQLgIB/5sPK9SbnrcFoy+oGhZC+l/7XzM5beGAWBYUO5 X-Received: by 2002:a17:902:788c:b0:1d3:f40a:a089 with SMTP id q12-20020a170902788c00b001d3f40aa089mr8612372pll.61.1703658541022; Tue, 26 Dec 2023 22:29:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703658541; cv=none; d=google.com; s=arc-20160816; b=Acy5I4RR6r6BomKBIjSXwrCVdS3zVY04X2oq6FIdb6on21n0FJoriwcm8mbGJUeNSb dfgoePawgu1X1JUySBbcICJUcjcfj4KaB0D5CRCCXDyUph7N34XmTvWtGftkwt9hdYl+ m4l5rMT1Q6tChwNtvVCOokmG+ZA41r6wv5QuseZ4+qIDP3wlWO5xhXBA4Df99JGBetrJ Gk/3F1hKtY+0tmyuFkxQy9+BZc7jj0nfqFMDwhwc6oPK3LoAsmkulpjV1pIzEohpWELA xwhrrUfCXiMgQ0iG6diWx9cjPtSVwvm1Yhp6jCmvfKyFz4TEbvBMqgZo5fn9+C9DleMg Ww7g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-unsubscribe:list-subscribe:list-id:precedence:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature; bh=JQlcJ7WoZJZ8oRDPlihcUW2VufrvhkYsQ/1WszBCSV0=; fh=+uoRuePerzEUtGMtUkxhzXG+DZX8dBsFnLC2Ry+GNNY=; b=uMsRkEMVi1zFmYZZ3V0R+nbIZ6Fdv76aWi5xVjBfOR2BJM0ayW/b/DpVn2iAaGJPGy fYepOjVqlRtuoa+lj/1Tvsu1SDeNyb8tucun5cvr9wEA1A96boclaA1E5UFi/nZObG5s V9iYwBlx+i9nmqAa7/4Pofqt8AUKd0d2DEZxJAgIVficAh3kTAoWfFwhgc0xGogbflak vXMQc02LaJy4c8C1otlo+irr07UO7YiK86hsMXkWfjYLTU+LEcAq1BJ5uxsyDxp+4gBm H17LMM1OtgoNPu8B5sRuXAipmCe17sfdsFHz27DetaSdr0Z6TJ0GTUd5WPRMlzrYDpu1 aGag== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SU4c8Umk; spf=pass (google.com: domain of linux-kernel+bounces-11861-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11861-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id m24-20020a170902bb9800b001d454ce72d3si4525169pls.581.2023.12.26.22.29.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Dec 2023 22:29:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-11861-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=SU4c8Umk; spf=pass (google.com: domain of linux-kernel+bounces-11861-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-11861-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id A8122283781 for ; Wed, 27 Dec 2023 06:29:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id BF39D6FCB; Wed, 27 Dec 2023 06:28:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="SU4c8Umk" X-Original-To: linux-kernel@vger.kernel.org Received: from mgamail.intel.com (mgamail.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B36E566F; Wed, 27 Dec 2023 06:28:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1703658485; x=1735194485; h=from:to:cc:subject:date:message-id:in-reply-to: references; bh=UBcg3tvQxTk+X28iZS6swUBYQTo6XZRYHj3J6Mm2IvM=; b=SU4c8UmkYxzr35uIZX/Szsr+cABZNs2z964wSqLR279KkLpsxNMnWL5J M1gVMkglYPt0tvBQJwxQE1RZuZ9A34H+vfmC9EJHZ3dpIpt+720xNQ3a+ +BBnmlG0h2T3LoNtgDrKNi/gu94ij2Uvs7cLqg2DbgPNaq95tLcdfeakj MOd7t9u8SGuI+3MScrkvvPVpBX4oyUtssFTOn5mQgBYKvGaQkqKu5kbh9 9zjlDjjXVaMYQIXzqIA47iIdW7mRwj2k/XjPRd4GtNtUN9SahSaHeKWXH Qdl24aa7Wt/EeRxceIabyv9oGmNaWOAzoWphZT6Zb1kl/lNfwPxhM0Puk Q==; X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="427584074" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="427584074" Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Dec 2023 22:28:00 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10935"; a="1025316088" X-IronPort-AV: E=Sophos;i="6.04,308,1695711600"; d="scan'208";a="1025316088" Received: from ranerica-svr.sc.intel.com ([172.25.110.23]) by fmsmga006.fm.intel.com with ESMTP; 26 Dec 2023 22:28:00 -0800 From: Ricardo Neri To: "Rafael J. Wysocki" Cc: Chen Yu , Len Brown , Srinivas Pandruvada , Stanislaw Gruszka , Zhang Rui , Zhao Liu , stable@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Ricardo Neri , Zhao Liu Subject: [PATCH 3/4] thermal: intel: hfi: Disable an HFI instance when all its CPUs go offline Date: Tue, 26 Dec 2023 22:29:39 -0800 Message-Id: <20231227062940.10780-4-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20231227062940.10780-1-ricardo.neri-calderon@linux.intel.com> References: <20231227062940.10780-1-ricardo.neri-calderon@linux.intel.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: In preparation to support hibernation, add functionality to disable an HFI instance during CPU offline. The last CPU of an instance that goes offline will disable such instance. The Intel Software Development Manual states that the operating system must wait for the hardware to set MSR_IA32_PACKAGE_THERM_STATUS[26] after disabling an HFI instance to ensure that it will no longer write on the HFI memory. Some processors, however, do not ever set such bit. Wait a minimum of 2ms to give time hardware to complete any pending memory writes. Cc: Chen Yu Cc: Len Brown Cc: Srinivas Pandruvada Cc: Stanislaw Gruszka Cc: Zhang Rui Cc: Zhao Liu Cc: linux-pm@vger.kernel.org Cc: stable@vger.kernel.org Signed-off-by: Ricardo Neri --- drivers/thermal/intel/intel_hfi.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/drivers/thermal/intel/intel_hfi.c b/drivers/thermal/intel/intel_hfi.c index 15c8c3b841d2..d2c874f43786 100644 --- a/drivers/thermal/intel/intel_hfi.c +++ b/drivers/thermal/intel/intel_hfi.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -366,6 +367,31 @@ static void hfi_set_hw_table(struct hfi_instance *hfi_instance) wrmsrl(MSR_IA32_HW_FEEDBACK_PTR, msr_val); } +static void hfi_disable(void) +{ + u64 msr_val; + int i; + + rdmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val); + msr_val &= ~HW_FEEDBACK_CONFIG_HFI_ENABLE_BIT; + wrmsrl(MSR_IA32_HW_FEEDBACK_CONFIG, msr_val); + + /* + * Wait for hardware to acknowledge the disabling of HFI. Some + * processors may not do it. Wait for ~2ms. This is a reasonable + * time for hardware to complete any pending actions on the HFI + * memory. + */ + for (i = 0; i < 2000; i++) { + rdmsrl(MSR_IA32_PACKAGE_THERM_STATUS, msr_val); + if (msr_val & PACKAGE_THERM_STATUS_HFI_UPDATED) + break; + + udelay(1); + cpu_relax(); + } +} + /** * intel_hfi_online() - Enable HFI on @cpu * @cpu: CPU in which the HFI will be enabled @@ -491,6 +517,10 @@ void intel_hfi_offline(unsigned int cpu) mutex_lock(&hfi_instance_lock); cpumask_clear_cpu(cpu, hfi_instance->cpus); + + if (!cpumask_weight(hfi_instance->cpus)) + hfi_disable(); + mutex_unlock(&hfi_instance_lock); } -- 2.25.1