From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 97C39606A335 for ; Wed, 2 Dec 2026 22:31:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=jNT54wfX Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5BB8210E0D6; Wed, 2 Dec 2026 22:31:38 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.21]) by gabe.freedesktop.org (Postfix) with ESMTPS id C389410E694 for ; Wed, 2 Dec 2026 22:31:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796250692; x=1827786692; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=CZDjY6p5UtwNo10bfkiQq1SOsQW//j3i28jLT0I5GUs=; b=jNT54wfXY07wWxJeAwGwZNTtKJ8k28kS8sBMGizO9EEXRmEOl9LuThC3 BmttQkkR8MiDxVBA0EpmXN7GKbJfxAid7m04DLfw8zk8bEjboLSx22lb8 C8s7sveIhF4S1vdScL6yjYeIs0ql0yVticcXHIBq/KlWmP7fNUP7upl7L i12TLYj2+OYyVGxJhGyKcD++4lKndgOf4t0mHJsDXHDMH+gYmJ7GGYd8V pP1ZuO3C96/FFM5m4sv7II1Jw7eMShx2KIOQploYq2Qffdz98HbgYJQgz yOkTGcdaKqtszDynWOqVZ/LdSpZfdqcK2Ku22TJGMNUWXRT5rQ7am9Lbg g==; X-CSE-ConnectionGUID: 2sZblceRTpqHyR/UPOZBwg== X-CSE-MsgGUID: 1ujX2idnQeOhK+5RW2q71w== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5295572" X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="5295572" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 14:31:32 -0800 X-CSE-ConnectionGUID: /xYWPJ/GSLWAMvt3VY33vw== X-CSE-MsgGUID: 0vOYyav+TwyTGhN9tbUlsQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,247,1787036400"; d="scan'208";a="13667912" Received: from fmsmsx901.amr.corp.intel.com ([10.18.126.90]) by orviesa007.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 02 Dec 2026 14:31:31 -0800 Received: from FMSMSX903.amr.corp.intel.com (10.18.126.92) by fmsmsx901.amr.corp.intel.com (10.18.126.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 14:31:30 -0800 Received: from fmsedg903.ED.cps.intel.com (10.1.192.145) by FMSMSX903.amr.corp.intel.com (10.18.126.92) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Wed, 2 Dec 2026 14:31:30 -0800 Received: from SN4PR0501CU005.outbound.protection.outlook.com (40.93.194.11) by edgegateway.intel.com (192.55.55.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Wed, 2 Dec 2026 14:31:30 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=RZojxtmYGsJpBCdpiASXNc2xoKzLVYSWv7YaRVyfI/eNPptDGNtir5tXlARDLFOinRaZr9lHrdXthpDs7Z1CzqirpF6kKRoNihChewksVoNtrRWEUeI6gjIMxpbhOJMLSWvYdOD519DDkxbaaGpVOIqJix3AKuWRZCj07NM5/ZcCs3PBeasu5ZweQeacTPmBWph1iHAHfTgl3S7RRYvksEVVM+Ij2VWKsKUkx7jZ1Ya3ZjJLdyke2WjTyrAJE1AnpJPJCkyPMWPrulFe9Vc1xRe8a5gmYou1JL/dq8m3IVSDArcPluxh3EvhT+CrX+STjrxSDnNTIkj06/HgQazwVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CZDjY6p5UtwNo10bfkiQq1SOsQW//j3i28jLT0I5GUs=; b=DNnAn2a8+RsAxsfPyrO651gLtVfrpgLI7as8+awiExmmS3hQgygdeCnyL//EUhqa7MOLMBaIPZWE21bVIEy2rH5C7Z+fH4B1u9jS8nXkt6LtsG5nCsxeXmCaW7aeb2e9UrQj+jWUErrdtxJ4Jux+r8vXVX2OO8V6tJjKUhtwoYXD/qX0liIWrAT0gKKLjj2lAzVkiuqUkpTNaOmS87KA5kYyWeqtkXVMprxMdJPislBwlXFE5+ON1XysG5AWIxpQqqr6O6Z6MGeXRQ5vvNJWM4IZZRcC+XW0O7Mbp0BCd1TFvhwhARe0nwPszpQ3036TysRlzVN5AGZ+BlpZnzLPlg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=intel.com; Received: from DS7PR11MB5990.namprd11.prod.outlook.com (2603:10b6:8:71::5) by DS7PR11MB7739.namprd11.prod.outlook.com (2603:10b6:8:e0::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.688.10; Wed, 2 Dec 2026 22:31:28 +0000 Received: from DS7PR11MB5990.namprd11.prod.outlook.com ([fe80::133c:5eed:3aec:b899]) by DS7PR11MB5990.namprd11.prod.outlook.com ([fe80::133c:5eed:3aec:b899%3]) with mapi id 15.21.0688.009; Wed, 2 Dec 2026 22:31:28 +0000 Date: Wed, 2 Dec 2026 17:31:24 -0500 From: Rodrigo Vivi To: Karthik Poosa CC: , , , , Subject: Re: [PATCH v9 10/11] drm/xe/hwmon: Refresh fan data after late binding Message-ID: References: <20261202195221.1862825-1-karthik.poosa@intel.com> <20261202195221.1862825-11-karthik.poosa@intel.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261202195221.1862825-11-karthik.poosa@intel.com> X-ClientProxiedBy: SJ0PR13CA0122.namprd13.prod.outlook.com (2603:10b6:a03:2c6::7) To DS7PR11MB5990.namprd11.prod.outlook.com (2603:10b6:8:71::5) X-Archived-By: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: DS7PR11MB5990:EE_|DS7PR11MB7739:EE_ X-MS-Office365-Filtering-Correlation-Id: 925d6e23-0579-4604-4e11-08df50c4019e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|23010399003|376014|10067099003|56012099006|261022075727099003|261026121527099003|261022105027099003|261028144727099003|261021121427099003|261021123027099003|261102123227099003|261026140227099003|261009223027099003|261009223327099003|261009221727099003|261009221227099003|261009220027099003|18002099003|22082099003|4143699003|11063799006; X-Microsoft-Antispam-Message-Info: DJ/TiUAnt01g67LhaBYqcWp/kZq5VJxMspjpO9RiDgfcCJJnfCAPxSbbDLYnvVRm5mUnPtK0ipP5M+OnkAoFRDprWg7eQ2Y8FOhaTSU6awBpBM3MXnUrnkZ8hpQWwPMJSLNP6NLiUXwxQ7ZLaWp+3CShcp2Szu4g1CXaLKt/AiHSngl+bDar4vYBzOekFLSZ5Duf6pjRZ+eiEv9pDd9R1ugFD3Haf2JqIMdzOP8y/nQTbgXXMRPvi+ODEK1di3rGKdPmurWYD5hcaTIRewiFQxzBZTxfkGwCp05t07cCObI/A2oZg16GZgtauv0KwDuuK2uSzynIxDNORzDlKJ4kYej9cwHKqqTbcCjoElZ77EEr2znY1C0t4u9+NvsWJAXsxheVSIGLcEm73EXBmUttN2LYPQF/tNB36oTQnS5E1RzvSZwANgWOf/8D5Rlu2KaZA4Na17cKpcN3DtuHMJ2kwyoF2cSYOIcm/lrMzr3JhORh3364d4VGc56NzydN3r3sot9teWgOJj2PDpBaiDuggkHlf4aijBEC19skmEHFQgkKyOC0pXhuTpKOA548d6qkcJN3JAKTPA+j5UxNDbSW72v6OYHNwsBWJRwFDu1Q0WmHHasFbcupNwFnKtpSzBC3fZ8tDnF7wH3aeDFR0VUqxHAPFAvykrjYb1YjdhmQre8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:DS7PR11MB5990.namprd11.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(23010399003)(376014)(10067099003)(56012099006)(261022075727099003)(261026121527099003)(261022105027099003)(261028144727099003)(261021121427099003)(261021123027099003)(261102123227099003)(261026140227099003)(261009223027099003)(261009223327099003)(261009221727099003)(261009221227099003)(261009220027099003)(18002099003)(22082099003)(4143699003)(11063799006); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?snutb5/2TsxOJcIYhL5wgosK+SAexB5lrE4ywyWXemSEFVoWFMGG6hMvumnx?= =?us-ascii?Q?rjmSXAFFaXIvcznZ33nSBop3vvRqRSSkzISKnL7lzl0CX8sWXZOjZz3OdSA2?= =?us-ascii?Q?DrRSuCOml6v6DgtTDMS6GTfiHB6BGpSd7tFHM7sAOo9yIp2oKU+ZAFvZv9gr?= =?us-ascii?Q?V/EZ9PQbMCrFO8lLIyg4aGrELs1NDkUbnqPYJCvV5tJ2P97E5Ca8tq7G0Yzc?= =?us-ascii?Q?ZfVeehn/4PUJjt7iieH6s2uF5iH6TBb47vvobaSn4FkeOBQ+hR+6JFUyJurQ?= =?us-ascii?Q?X98tfQInhPiSwdxaZ24a1LIITxUODThhgm49btjkVz059k86dscJbIotepMS?= =?us-ascii?Q?sfTlZV559BPMyuV2OoWfK6raeIVsSujuAPKj10vCkciunssbqQquWTrw8fo7?= =?us-ascii?Q?jkWpfLsy5HEnnu67OsgN8ahhXqOV45KZ2SIXDqIAVFzq5ZsDTBgvOuxhBU52?= =?us-ascii?Q?SzicMA1JQ345uThZ54RM4moajwVyR28x4y1LwUJh0e3846i9MLST2STxetdA?= =?us-ascii?Q?8gI3L1OXlmZIGMJMTfRtn1B9Kxj3zk4CVIm9kUQnaqD3vStEWTSQr+Sw2hNr?= =?us-ascii?Q?z8lNqDti/wG44QNNIRI8teDiB2rMWxGO+YSsweEHaYWncvKM2pXw0p4yV64o?= =?us-ascii?Q?2J69FgHbZN9MHuRJ26ZDddbmtisc4+Zee17JUO1PUHiUZ1Xfj8FHDtOSjKVz?= =?us-ascii?Q?Pvg9v+UFPD9T38cW2Tt6NLrSE+FBeofLhCA4KuR9EPiuOABzbefGhgisAGuH?= =?us-ascii?Q?t8epl9Cqkx5sfDRiN9Kuuax2KwE23BNfrM+UOn8LTejX10NG3FMiJZC/COEc?= =?us-ascii?Q?8aeTQ+EliUc9T3cSlLGia6okX40/OQguYyQsnbDglpMlMafzX/RhCe+wNpwL?= =?us-ascii?Q?cxVZbsBICUAqbrYMOeaQLSVP0oZdbYNCDU796IIBukyh4o0ThIUSoM4NXRfN?= =?us-ascii?Q?drm/TNnHJSiaBPF95jfA4x/93U3izubOdV5pPlNb1e4ZuGe3XNho3XQqfGtC?= =?us-ascii?Q?IAHangz4/hlQaPF3NtG3l/RM+IhGsC9aFcslfbXwd26U4VPyaAFxNtJ+Pma5?= =?us-ascii?Q?W5m5vLL2VJEBpcZXfCm8j3pnE7dEOSSEXPyuN/8XZDY6NPG+Dzc+SY6qL1yn?= =?us-ascii?Q?8qKuYtYe8CIbN01Nb7yrFGb69h4FDXCifAjt4wu8uIuwb+MMOZ3i0G6P2me0?= =?us-ascii?Q?U8v5EVNYwWmh3yGjIPaIZpgLQKcPfpKz0OqNU1IrXmEmPl4ZovVdBGjwORai?= =?us-ascii?Q?ERUbKk1V0+qAhm7A4CMTUrmCnrohtAPOnFEEhi7a0WyqPnjMUHr4rc2Ft4Zw?= =?us-ascii?Q?Sc5N1jTcFZF4iICC3J+Bxl2ilTqazOveE91TCp3mZZjQZl2MeyJNdDghoOBD?= =?us-ascii?Q?ulMisIF34bLqggHpKJQI5jF2TFVB3ga8MQpTE4gzKbC42RDi1MQEE5kQGMa3?= =?us-ascii?Q?1YUXhCC8kX1bmTsS11jwAFRjUg7jUUK6v4EfZYWq5l8tS0ZfvcoK71RTa+8H?= =?us-ascii?Q?bOtgkXznw9Vctvjjch1gmBgePQ1+6P1Ls4WLOXH6fcllgNSRDXf6Ze2GsCa8?= =?us-ascii?Q?dew4YBgEDkaQoZxPAfIgwaBYAGf9TXBrxHSrNvKcfpQGMrZ3M2sKvmSfpdM2?= =?us-ascii?Q?SWquIow21Kc9Ku0lNUxY0g8PGfs8zKDVGyVHnb9mbxf6/sJ8q36k7pT4fxCc?= =?us-ascii?Q?monoc1rvchQ5e4JC5CkBOyw43hXc3vJxQ76LtB3oJ/kg++NY41tUebt3t7g5?= =?us-ascii?Q?y6/DPLZ51w=3D=3D?= X-Exchange-RoutingPolicyChecked: Ua/pSTQQa9fnuvdbUcGDRsLbV197nVggrWnWSHPWYWcRKzGDcRoHCZ4YsxNcmoHTa6R0MxttybfHnGSkhtjoYK8cwl+63xyxYF+qb5lYUqx4LOgwB/lYwFoBltpqsbRr1MFerOhtYvp0rJP1pJcvPnjs//bWfBJtZBjjlh5NluWvTiO/YOWo/Y16WxsebHD/QtVSNWVxSFTZiCCRpXCzoonPLBPfugN3/OpFGruqgnHwgap47hrmvYIArhnRMBlvJFDzs1cI6IwzQQ1G5HY8TFA6OD99Vu4Pv0ccF95xQmGpsjsc6LwzkHIWhnIIl2bNCEige/naqXruIbCV16hdyA== X-MS-Exchange-CrossTenant-Network-Message-Id: 925d6e23-0579-4604-4e11-08df50c4019e X-MS-Exchange-CrossTenant-AuthSource: DS7PR11MB5990.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Dec 2026 22:31:28.7824 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: 6mnHFwa2kSFyLRhI+N3gKJmmP+5a9QW9kJ8OnKvhmfmaTtyzmUYldH2asVtmrwsYgGdioskzI06E8z/ibaJxvg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DS7PR11MB7739 X-OriginatorOrg: intel.com X-BeenThere: intel-xe@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel Xe graphics driver List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Intel-xe" X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 On Thu, Dec 03, 2026 at 01:22:20AM +0530, Karthik Poosa wrote: > Refresh cached stock fan tables and maximum RPM for registered fans after > fan-control firmware loads. Keep the previous stock table if a complete > table cannot be read, and keep the previous maximum RPM if its read fails. > Re-program user tables for fans in manual or full-speed mode. > > Serialize refresh with hwmon registration and teardown. Protect cached > fan data reads against concurrent late-binding updates. Unregister hwmon > outside registration_lock to avoid deadlocking sysfs callbacks with > late-binding work. Use drmm for hwmon state shared with the late-binding > worker so it remains valid until DRM device release. > > Signed-off-by: Karthik Poosa > --- > > v2: > - Compare lbfw->id with XE_LB_FW_FAN_CONTROL. (Soham) > - Use xe already in scope. (Soham) > - Spell out "late binding" in warnings. (Soham) > - Start fans enabled after late binding in automatic mode. > > v3: > - Serialize the refresh with hwmon registration and teardown. Flush > late binding work before releasing hwmon state, and protect > fanN_max reads against concurrent max_rps updates. > > v4: > - Keep the previous stock table if the refresh does not read a > complete one. > - Re-program user tables of fans in manual or full-speed mode after > late binding. > - Unregister the hwmon device outside registration_lock, so sysfs > callbacks resuming the device cannot deadlock with late binding work. > - Keep the previous max RPM if the refresh read fails. > > v5: > - Fix xe_hwmon_fan_late_binding_update() kernel-doc; it does not read > the number of fans. (sashiko) > - Drop a v2 note that does not belong to this patch. (sashiko) > - Use "late binding" consistently and rename > xe_hwmon_fan_update_post_lb() to xe_hwmon_fan_late_binding_update(). > (Soham) > - Use guards for hwmon_lock. (Soham) > > v6: > - Move late-binding status polling and fan-data refresh into hwmon-owned > delayed work. > - Poll V1_FAN_PROVISIONED after hwmon registration and resume; avoid > waking a runtime-suspended GPU and cancel the work during unregister. > - Remove the direct dependency from xe_late_bind_fw.c to xe_hwmon.c. > - Read maximum RPM into a temporary value and publish it only after > success, preserving the previous cache on mailbox read failure. > - Allocate shared hwmon state and locks with drmm so they remain valid > until DRM device release. > - Protect fan cache visibility checks with hwmon_lock. > > v7: > - Address review comments form sashiko. > - Gate fan provisioning polling on the fan late-binding capability. > - Cancel polling synchronously before suspend/FLR state snapshots. > - Restart polling before the D3hot resume early return. > - Delay the first resume check and retry inactive runtime-PM acquisitions > within the existing retry limit; release only acquired PM references. > - Replace deprecated system_wq with system_dfl_wq. > - Remove the stale acquire/release pairing comment and use WRITE_ONCE() > to publish xe->hwmon. > - Add few debug logs in fan late binding flow. > > drivers/gpu/drm/xe/xe_device.c | 3 + > drivers/gpu/drm/xe/xe_hwmon.c | 188 +++++++++++++++++++++++++++++++-- > drivers/gpu/drm/xe/xe_hwmon.h | 2 + > drivers/gpu/drm/xe/xe_pm.c | 1 + > 4 files changed, 186 insertions(+), 8 deletions(-) > > diff --git a/drivers/gpu/drm/xe/xe_device.c b/drivers/gpu/drm/xe/xe_device.c > index d11e01ce50ca..5decebc0361a 100644 > --- a/drivers/gpu/drm/xe/xe_device.c > +++ b/drivers/gpu/drm/xe/xe_device.c > @@ -1152,6 +1152,8 @@ void xe_device_shutdown(struct xe_device *xe) > > drm_dbg(&xe->drm, "Shutting down device\n"); > > + xe_hwmon_unregister(xe); > + > xe_display_shutdown(xe); > > xe_irq_suspend(xe); > @@ -1465,6 +1467,7 @@ int xe_device_suspend(struct xe_device *xe, bool hibernate, bool flr) > err_display: > xe_display_pm_resume(xe); > xe_pxp_pm_resume(xe->pxp); > + xe_hwmon_suspend_abort(xe); > return err; > } > > diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c > index 94825d1f2928..0407f6f1ab45 100644 > --- a/drivers/gpu/drm/xe/xe_hwmon.c > +++ b/drivers/gpu/drm/xe/xe_hwmon.c > @@ -9,6 +9,7 @@ > #include > #include > #include > +#include > > #include > #include "regs/xe_gt_regs.h" > @@ -16,6 +17,7 @@ > #include "regs/xe_pcode_regs.h" > #include "xe_device.h" > #include "xe_hwmon.h" > +#include "xe_late_bind_fw_types.h" > #include "xe_log.h" > #include "xe_mmio.h" > #include "xe_pcode.h" > @@ -183,6 +185,9 @@ enum fan_table_type { > /* Maximum number of fan control points supported by each fan. */ > #define MAX_FAN_CONTROL_POINTS 10 > > +#define XE_FAN_LATE_BIND_POLL_INTERVAL msecs_to_jiffies(1000) > +#define XE_FAN_LATE_BIND_POLL_RETRIES 30 > + > /* Minimum number of points required for a user fan table. */ > #define MIN_FAN_CONTROL_POINTS 2 > > @@ -269,6 +274,8 @@ struct xe_hwmon { > struct device *hwmon_dev; > /** @xe: Xe device */ > struct xe_device *xe; > + /** @registration_lock: serialize registration with late binding updates */ > + struct mutex registration_lock; > /** @hwmon_lock: lock for rw attributes*/ > struct mutex hwmon_lock; > /** @scl_shift_power: pkg power unit */ > @@ -293,6 +300,10 @@ struct xe_hwmon { > struct xe_hwmon_thermal_info temp; > /** @tjmax_fan_control_state: saved TjMax fan-control state */ > enum xe_tjmax_fan_control_state tjmax_fan_control_state; > + /** @fan_late_bind_work: polls for fan firmware provisioning */ > + struct delayed_work fan_late_bind_work; > + /** @fan_late_bind_poll_count: polls since the fan firmware check was queued */ > + u8 fan_late_bind_poll_count; > /** @curve_sda: fan curve sensor attributes */ > struct sensor_device_attribute curve_sda[XE_CURVE_ATTRS]; > /** @curve_names: names of the fan curve sensor attributes */ > @@ -1703,6 +1714,8 @@ static umode_t xe_hwmon_curve_attributes_visible(struct kobject *kobj, > struct xe_hwmon *hwmon = dev_get_drvdata(dev); > u32 fan = index / XE_CURVE_ATTRS_PER_FAN; > > + guard(mutex)(&hwmon->hwmon_lock); > + > /* Manual mode, and thus curve writes, need a stock table, as for pwmN_enable. */ > if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED(hwmon, fan) || > hwmon->fi[fan].fan_table[STOCK_FAN_TABLE].point_count < MIN_FAN_CONTROL_POINTS) > @@ -2372,7 +2385,10 @@ xe_hwmon_fan_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) > case hwmon_fan_input: > return IS_FAN_ENABLED(hwmon, channel) ? 0444 : 0; > case hwmon_fan_max: > + { > + guard(mutex)(&hwmon->hwmon_lock); > return IS_FAN_ENABLED(hwmon, channel) && hwmon->fi[channel].max_rps ? 0444 : 0; > + } > default: > return 0; > } > @@ -2381,6 +2397,8 @@ xe_hwmon_fan_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) > static umode_t > xe_hwmon_pwm_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) > { > + guard(mutex)(&hwmon->hwmon_lock); > + > /* Manual control starts from the stock table, so it needs a usable curve. */ > if (!hwmon->xe->info.has_fan_control || !IS_FAN_ENABLED(hwmon, channel) || > hwmon->fi[channel].fan_table[STOCK_FAN_TABLE].point_count < MIN_FAN_CONTROL_POINTS) > @@ -2441,7 +2459,9 @@ xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) > case hwmon_fan_input: > return xe_hwmon_fan_input_read(hwmon, channel, val); > case hwmon_fan_max: > - *val = mul_u32_u32(hwmon->fi[channel].max_rps, 60); > + scoped_guard(mutex, &hwmon->hwmon_lock) { > + *val = mul_u32_u32(hwmon->fi[channel].max_rps, 60); > + } > return 0; > default: > return -EOPNOTSUPP; > @@ -2883,6 +2903,8 @@ xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon) > return xe_hwmon_init_temp_info(hwmon); > } > > +static void xe_hwmon_fan_late_bind_work(struct work_struct *work); > + > int xe_hwmon_register(struct xe_device *xe) > { > struct device *dev = xe->drm.dev; > @@ -2898,9 +2920,11 @@ int xe_hwmon_register(struct xe_device *xe) > if (IS_SRIOV_VF(xe)) > return 0; > > - hwmon = devm_kzalloc(dev, sizeof(*hwmon), GFP_KERNEL); > + /* drmm keeps this state alive until late binding work is gone at device release. */ > + hwmon = drmm_kzalloc(&xe->drm, sizeof(*hwmon), GFP_KERNEL); > if (!hwmon) > return -ENOMEM; > + INIT_DELAYED_WORK(&hwmon->fan_late_bind_work, xe_hwmon_fan_late_bind_work); > > hwmon->tjmax_fan_control_state = XE_TJMAX_FAN_CONTROL_UNKNOWN; > > @@ -2908,13 +2932,19 @@ int xe_hwmon_register(struct xe_device *xe) > for (fan = 0; fan < FAN_MAX; fan++) > hwmon->fi[fan].pwm_enable_mode = XE_FAN_PWM_UNINITIALIZED; > > - ret = devm_mutex_init(dev, &hwmon->hwmon_lock); > + ret = drmm_mutex_init(&xe->drm, &hwmon->hwmon_lock); > if (ret) > return ret; > > + ret = drmm_mutex_init(&xe->drm, &hwmon->registration_lock); > + if (ret) > + return ret; > + > + guard(mutex)(&hwmon->registration_lock); > + > /* There's only one instance of hwmon per device */ > hwmon->xe = xe; > - xe->hwmon = hwmon; > + WRITE_ONCE(xe->hwmon, hwmon); > > ret = xe_hwmon_get_preregistration_info(hwmon); > if (ret) > @@ -2937,11 +2967,17 @@ int xe_hwmon_register(struct xe_device *xe) > xe_log_err(xe, HWMON, ret, "Failed to register xe hwmon\n"); > goto err_null_hwmon; > } > + if (xe->info.has_fan_control && > + (xe->info.late_bind_mask & BIT(XE_LB_FW_FAN_CONTROL))) { > + hwmon->fan_late_bind_poll_count = 0; > + xe_dbg(xe, "queue fan firmware provisioning check\n"); > + mod_delayed_work(system_dfl_wq, &hwmon->fan_late_bind_work, 0); > + } > > return 0; > > err_null_hwmon: > - xe->hwmon = NULL; > + WRITE_ONCE(xe->hwmon, NULL); > return ret; > } > > @@ -2954,11 +2990,27 @@ int xe_hwmon_register(struct xe_device *xe) > */ > void xe_hwmon_unregister(struct xe_device *xe) > { > - if (!xe->hwmon) > + struct xe_hwmon *hwmon; > + > + hwmon = READ_ONCE(xe->hwmon); > + if (!hwmon) > + return; > + > + /* An in-flight late binding update finishes before xe->hwmon is cleared. */ > + mutex_lock(&hwmon->registration_lock); > + if (READ_ONCE(xe->hwmon) != hwmon) { > + mutex_unlock(&hwmon->registration_lock); > return; > + } > + WRITE_ONCE(xe->hwmon, NULL); > + mutex_unlock(&hwmon->registration_lock); > + cancel_delayed_work_sync(&hwmon->fan_late_bind_work); > > - hwmon_device_unregister(xe->hwmon->hwmon_dev); > - xe->hwmon = NULL; > + /* > + * Sysfs callbacks may wait on hwmon_lock held by a late-bind update > + * that needs registration_lock. > + */ > + hwmon_device_unregister(hwmon->hwmon_dev); > } > > /** > @@ -2976,6 +3028,8 @@ void xe_hwmon_suspend(struct xe_device *xe, bool runtime) > if (!hwmon || !xe->info.has_fan_control) > return; > > + cancel_delayed_work_sync(&hwmon->fan_late_bind_work); > + > /* Runtime suspend keeps the fan tables unless the device enters d3cold. */ > if (runtime && !xe->d3cold.allowed) { > xe_dbg(xe, "d3cold not allowed, skipping fan state snapshot\n"); > @@ -3026,6 +3080,35 @@ void xe_hwmon_suspend(struct xe_device *xe, bool runtime) > } > } > > +static void xe_hwmon_fan_late_bind_restart(struct xe_hwmon *hwmon) > +{ > + struct xe_device *xe = hwmon->xe; > + > + mutex_lock(&hwmon->registration_lock); > + if (READ_ONCE(xe->hwmon) == hwmon && > + (xe->info.late_bind_mask & BIT(XE_LB_FW_FAN_CONTROL))) { > + hwmon->fan_late_bind_poll_count = 0; > + xe_dbg(xe, "restart fan firmware provisioning checks\n"); > + mod_delayed_work(system_dfl_wq, &hwmon->fan_late_bind_work, > + XE_FAN_LATE_BIND_POLL_INTERVAL); > + } > + mutex_unlock(&hwmon->registration_lock); > +} > + > +/** > + * xe_hwmon_suspend_abort - Restart fan provisioning checks after failed suspend > + * @xe: xe device instance > + */ > +void xe_hwmon_suspend_abort(struct xe_device *xe) > +{ > + struct xe_hwmon *hwmon = READ_ONCE(xe->hwmon); > + > + if (!hwmon || !xe->info.has_fan_control) > + return; > + > + xe_hwmon_fan_late_bind_restart(hwmon); > +} > + > /** > * xe_hwmon_resume - Restore hwmon state after resume > * @xe: xe device instance > @@ -3041,6 +3124,8 @@ void xe_hwmon_resume(struct xe_device *xe, bool runtime) > if (!hwmon || !xe->info.has_fan_control) > return; > > + xe_hwmon_fan_late_bind_restart(hwmon); Thanks for fixing the worker. Small thing for a follow-up: now every runtime resume, D3hot included, restarts the worker, and once the fw is provisioned it re-reads the stock tables and re-writes the user tables each time. Maybe remember that the refresh was done, and only restart when the fw could have been reloaded (D3cold, system resume, FLR). Reviewed-by: Rodrigo Vivi > + > if (runtime && !xe->d3cold.allowed) { > xe_dbg(xe, "d3cold not allowed, skipping fan state restore\n"); > return; > @@ -3087,4 +3172,91 @@ void xe_hwmon_resume(struct xe_device *xe, bool runtime) > } > } > > +static void xe_hwmon_refresh_fan_data(struct xe_hwmon *hwmon) > +{ > + struct xe_device *xe = hwmon->xe; > + int fan; > + > + guard(mutex)(&hwmon->registration_lock); > + if (READ_ONCE(xe->hwmon) != hwmon) > + return; > + > + guard(mutex)(&hwmon->hwmon_lock); > + > + if (xe_hwmon_read_fan_control_info(hwmon)) > + xe_warn(hwmon->xe, "failed to read stock fan tables after late binding\n"); > + > + for (fan = 0; fan < FAN_MAX; fan++) { > + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; > + int ret; > + > + if (!IS_FAN_ENABLED(hwmon, fan) || > + (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE && > + fi->pwm_enable_mode != XE_FAN_PWM_FULL_SPEED)) > + continue; > + > + ret = xe_hwmon_activate_user_fan_table(hwmon, fan, > + fi->pwm_enable_mode == XE_FAN_PWM_FULL_SPEED, > + USER_FAN_TABLE); > + if (ret) > + xe_warn(hwmon->xe, > + "failed to restore fan %d user table after late binding, ret=%d\n", > + fan, ret); > + } > +} > + > +static void xe_hwmon_fan_late_bind_work(struct work_struct *work) > +{ > + struct xe_hwmon *hwmon = container_of(to_delayed_work(work), > + struct xe_hwmon, fan_late_bind_work); > + struct xe_device *xe = hwmon->xe; > + const char *retry_reason; > + u32 status = 0; > + bool active; > + int ret = 0; > + > + active = xe_pm_runtime_get_if_active(xe); > + if (!active) { > + retry_reason = "device is not runtime active"; > + goto retry; > + } > + > + ret = xe_pcode_read(xe_device_get_root_tile(xe), > + PCODE_MBOX(PCODE_LATE_BINDING, GET_CAPABILITY_STATUS, 0), > + &status, NULL); > + if (ret) { > + retry_reason = "failed to read fan firmware provisioning status"; > + goto retry; > + } > + > + if (!(status & V1_FAN_SUPPORTED)) { > + xe_dbg(xe, "fan firmware does not support fan control (status=%#x)\n", status); > + goto out; > + } > + > + if (status & V1_FAN_PROVISIONED) { > + xe_dbg(xe, "fan firmware provisioned (status=%#x); refreshing fan data\n", status); > + xe_hwmon_refresh_fan_data(hwmon); > + goto out; > + } > + > + retry_reason = "fan firmware not provisioned yet"; > +retry: > + mutex_lock(&hwmon->registration_lock); > + if (READ_ONCE(xe->hwmon) == hwmon && > + ++hwmon->fan_late_bind_poll_count < XE_FAN_LATE_BIND_POLL_RETRIES) { > + xe_dbg(xe, "retry fan firmware provisioning check: %s (ret=%d, status=%#x, poll %u/%u)\n", > + retry_reason, ret, status, hwmon->fan_late_bind_poll_count, > + XE_FAN_LATE_BIND_POLL_RETRIES); > + mod_delayed_work(system_dfl_wq, &hwmon->fan_late_bind_work, > + XE_FAN_LATE_BIND_POLL_INTERVAL); > + } else if (READ_ONCE(xe->hwmon) == hwmon) { > + xe_dbg(xe, "timed out waiting for fan firmware provisioning\n"); > + } > + mutex_unlock(&hwmon->registration_lock); > +out: > + if (active) > + xe_pm_runtime_put(xe); > +} > + > MODULE_IMPORT_NS("INTEL_PMT_TELEMETRY"); > diff --git a/drivers/gpu/drm/xe/xe_hwmon.h b/drivers/gpu/drm/xe/xe_hwmon.h > index 50874b6b6527..4eba2bbcc469 100644 > --- a/drivers/gpu/drm/xe/xe_hwmon.h > +++ b/drivers/gpu/drm/xe/xe_hwmon.h > @@ -14,11 +14,13 @@ struct xe_device; > int xe_hwmon_register(struct xe_device *xe); > void xe_hwmon_unregister(struct xe_device *xe); > void xe_hwmon_suspend(struct xe_device *xe, bool runtime); > +void xe_hwmon_suspend_abort(struct xe_device *xe); > void xe_hwmon_resume(struct xe_device *xe, bool runtime); > #else > static inline int xe_hwmon_register(struct xe_device *xe) { return 0; }; > static inline void xe_hwmon_unregister(struct xe_device *xe) { } > static inline void xe_hwmon_suspend(struct xe_device *xe, bool runtime) {} > +static inline void xe_hwmon_suspend_abort(struct xe_device *xe) {} > static inline void xe_hwmon_resume(struct xe_device *xe, bool runtime) {} > #endif > > diff --git a/drivers/gpu/drm/xe/xe_pm.c b/drivers/gpu/drm/xe/xe_pm.c > index 4d4b398cbeda..65728995cb81 100644 > --- a/drivers/gpu/drm/xe/xe_pm.c > +++ b/drivers/gpu/drm/xe/xe_pm.c > @@ -608,6 +608,7 @@ int xe_pm_runtime_suspend(struct xe_device *xe) > xe_pm_update_pme_enabled(xe, false); > xe_display_pm_runtime_resume(xe); > xe_pxp_pm_resume(xe->pxp); > + xe_hwmon_suspend_abort(xe); > out: > xe_rpm_lockmap_release(xe); > xe_pm_write_callback_task(xe, NULL); > -- > 2.34.1 >