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 0EE7A606A320 for ; Mon, 30 Nov 2026 21:00:58 +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=nI0G7YIF Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CF08510F480; Mon, 30 Nov 2026 21:00:52 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.9]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5FCE410F48A for ; Mon, 30 Nov 2026 21:00:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796072447; x=1827608447; h=date:from:to:cc:subject:message-id:references: in-reply-to:mime-version; bh=0JgKC/wF1vk0r8O6vvxEXMP6MvnoDKjLRJSRdbXp1lM=; b=nI0G7YIFk8ebxF0LTcYUZ4WBVadUE8PPjgdrq2JlWQ8a1A8NDJR8j0aY kjAcMn+CtgPFqnJIbwhU0nnNaiENeCVOqWIKLGMGgdrqT/CPBVQW22EgL mh7u05yR+OBSygqBBO4gSRdi7Ssxcb3fyz5mGYI8eit9zb6cRiYzY9jag juZpKDqmHIa+aYnAOQZbbdMNt8ga81TDBuRbKlPSH85OFpv1cYtOor7kB I56ZTpb6fUT9DEs/EfBBNiyLUZpFnmpXkqVb3T4by+tuZLwD5BHKVTYXU 1kVYEb+T8qtSNIhpqTFCKqIiatCtbqS7QXGxwZjPit4hbh/0fV88bVyyg A==; X-CSE-ConnectionGUID: AKpZKshaQEmo1aKEjF/RNA== X-CSE-MsgGUID: 1kzRyUP4SaeEARWEWKu81Q== X-IronPort-AV: E=McAfee;i="6800,10657,11982"; a="4828041" X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="4828041" Received: from orviesa002.jf.intel.com ([10.64.159.142]) by orvoesa101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 13:00:46 -0800 X-CSE-ConnectionGUID: tqKLRwt8QgmRDd5NpR9agQ== X-CSE-MsgGUID: ozlxjqAuRJqd0KeufkjHcQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,243,1787036400"; d="scan'208";a="13051493" Received: from fmsmsx902.amr.corp.intel.com ([10.18.126.91]) by orviesa002.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2026 13:00:47 -0800 Received: from FMSMSX902.amr.corp.intel.com (10.18.126.91) by fmsmsx902.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Mon, 30 Nov 2026 13:00:46 -0800 Received: from fmsedg902.ED.cps.intel.com (10.1.192.144) by FMSMSX902.amr.corp.intel.com (10.18.126.91) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57 via Frontend Transport; Mon, 30 Nov 2026 13:00:46 -0800 Received: from SN4PR2101CU001.outbound.protection.outlook.com (40.93.195.5) by edgegateway.intel.com (192.55.55.82) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.2562.57; Mon, 30 Nov 2026 13:00:45 -0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=GwcxqnKIRAX1HFz2WWTUlncowJ4TOgCMeggvRhn5roOHpUVhklI+ygB4MeXlwD33UJfjy9Tym3HGHm6U84zyMQbJ3X7Cb3LZn0FJ7xrPWyA7LhY7/wzawY1XfrtN1zvn9bKmjje3niI+RftSzKJRzsJMUupvCee6e4H7sI/WXyQlN4xa+fWM/VPlo1pSqUqyL03b5cZ9Mpj5sCj+kq5Ic6cpzLT+O9hZM6K1yW0y8bYxAwVon349x3WScPjpTAkSl2Kkdzdkm3UOIn6k4DAOVQuabHD4yJwiWBXtdIYDD1pdxuTXJySlpTnOUIjJUdek/VeGrBMLBelvyCNm/WGCog== 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=0JgKC/wF1vk0r8O6vvxEXMP6MvnoDKjLRJSRdbXp1lM=; b=ULwE7Fw+dl7kcP+/1CQ/bZNcDoDNru64X6YhSJik4gOb+Q4WHr1i2ne1NaUGIvPngIaUEwIxevIkk7oPaugCv/gKnhznwcSeJhteGVtEZhX8ZA6pICDPzaaMhPWUwKSbZmDG7aXAmUzmpMl/X7hJ3fAdHUxEr6o4gnKGQWQOCVez4SoMnGyZENeB4O+PJig342sU6RtGdRVzvotgXsHh9mvoDlKGcm2jy1FNzqK8NfX+ZWxkCSqFC+yV8oQ/gMLnHndS/aSKjBCizPQZX7VJdxRbRfJglNvl7eHuQqo1VmZkbkes+E8kfUOLEBpHa5f12l2fCkiV3xHShO8XK1PULA== 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 PH3PPF5A636EDE4.namprd11.prod.outlook.com (2603:10b6:518:1::d21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Mon, 30 Nov 2026 21:00:40 +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.0662.007; Mon, 30 Nov 2026 21:00:40 +0000 Date: Mon, 30 Nov 2026 16:00:36 -0500 From: Rodrigo Vivi To: Karthik Poosa CC: , , , , , , , , Subject: Re: [PATCH v6 06/10] drm/xe/hwmon: Enable fan curve control support Message-ID: References: <20261130185050.36979-1-karthik.poosa@intel.com> <20261130185050.36979-7-karthik.poosa@intel.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261130185050.36979-7-karthik.poosa@intel.com> X-ClientProxiedBy: BY3PR03CA0027.namprd03.prod.outlook.com (2603:10b6:a03:39a::32) 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_|PH3PPF5A636EDE4:EE_ X-MS-Office365-Filtering-Correlation-Id: eab7d369-1c07-4035-797d-08df4f24fd4b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|1800799024|376014|23010399003|10067099003|56012099006|11063799006|261021135927099003|261021133027099003|261021121427099003|261026135527099003|261026140227099003|261021123027099003|261021130227099003|261009223027099003|261022115727099003|261022113327099003|261026121527099003|261026130827099003|261028144727099003|261102123227099003|261022105027099003|261022075727099003|22082099003|18002099003|4143699003|6133799003|3023799007; X-Microsoft-Antispam-Message-Info: /8VkBQfYI6czkDgCDcrI15F6GdVEzcfWiI6Q0JiJ8dPlWVDqXcbbhtR8o0voYE0Rj5jXgv/dAjhfTODUufTS0ML68y/OaZqdwO6s13zXvxKXiUAb3f04lJK5k779hM5cSoc6CpdnqORRosRe2hqf3t+dAlJHtyCDtQiDDLSYn1tCu03wgduShJE+UVjkYC8MmO8H15/vySODZgeLGp8HQsBPiAQFpLc3TzDlnJ30c5ZqTT2mGt1p5Rg7HYygcMBvlfxF/+dEqE9xkMquyfmRffkU9azxxsGRUA9muHd2qgZNwXSX0u4aevJjJSBHd+qLI4qAhyeFwo3jQSqI+675/lpECIlbaOqef8M+UdTBwmgoWsD7AU7vltkm116oNMu0a0BP/eoAZvwZsKV1ozdkRGd+Zxk0CxWh6mN7iJiKTBg4ePXVY+iOVmHk2nJo0HShr89lk9Bza9hXTDaJk0/Yj3HkLMBWvXYdrocwcmZkqx4BzU9+Zr9lImV8A6SHSWvvzh1065tlW+aqUVdmADl7dPaUmE2/E3gv4vF92FYW4GdbnCJHgZef/OVM7QGN9ZN1D5IARG92Pa4YHZ/xPthU7IorYgFWuTWgXIZIKWye/iGotEVleFKOD7lmv8NPqLQpPyofbScxUD+qsdejhSKXyO6lwzzLpugIaKx9/EG7ag4= 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)(376014)(23010399003)(10067099003)(56012099006)(11063799006)(261021135927099003)(261021133027099003)(261021121427099003)(261026135527099003)(261026140227099003)(261021123027099003)(261021130227099003)(261009223027099003)(261022115727099003)(261022113327099003)(261026121527099003)(261026130827099003)(261028144727099003)(261102123227099003)(261022105027099003)(261022075727099003)(22082099003)(18002099003)(4143699003)(6133799003)(3023799007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?zrfXuKBRo6+3N/Yi7eMloOoAifA8G20tkzZGFAv1az5Uf/kZzHDX+iYlD4Gs?= =?us-ascii?Q?9ayr/FL7H2Ash+z6ztSCPWZ6GVECUIzgKagwmpsJajC914g4VtfRkTy8ETLp?= =?us-ascii?Q?PGsyBkFlvfwCRVU7po9nlxvqciKJNQViaOxmQfs5nWcftArXwFNwUBCxlWZ5?= =?us-ascii?Q?DPhqyKz5dEIhHZba79Eo/ORTw3jatWt0Vdls38F+g4X9PLWsNqNIW0rf49nU?= =?us-ascii?Q?g9bK4my0sailZyhKcQtQCf2MRz7OHe/fGXr3c55gTYGxcXASoBfC4/h+nLeA?= =?us-ascii?Q?fRUk6cbuyR1okGtc2F+rTnI3tcqF+LUz63/lMvYm1B2DZA95rCW7c/wRLDkU?= =?us-ascii?Q?QmVVvSJEJnlfQpwK6RNHg7O7pVR1NNUJku0tyE+qiO7puXpR2OMSDBt7YjFW?= =?us-ascii?Q?woFUKnOwQa0TxouzymQ7C/ROC/TKJDl7rMFoT1nKuutpNXCi+1eVfS9jpCkG?= =?us-ascii?Q?zFPP8IdiVqYCr9IaVNUi+/VEbjcaReNxuGzkGgI1XFhRKroiLiKyPywsItHZ?= =?us-ascii?Q?0lJEz1DvveJnkMvdtJ3UhpiroJBrcjgv33CjOuNew3anoNp0J7Um8YTuUIMJ?= =?us-ascii?Q?POs/TomdH0pmWwI2TaKy0evsqYYyrU+piwqZQbiUDTmfeOH6aVsX9b81SumB?= =?us-ascii?Q?oll7e+UxlV7xOkKwfTKpslF+nRX91Ml71ML2lTgisJh0GYwY7tpwjUJRiraQ?= =?us-ascii?Q?nJYpG1WalLxNOGrVYALHWZNuCNDIX3qfSAUkmM0egUiYNITy6dys79I1PRYy?= =?us-ascii?Q?4VdZVLsp9geWvFcM95ma9ezh25rTmyLA5g4qI/1RPCacryvy6L8dwJ1HG6VO?= =?us-ascii?Q?t8qaXYZVCSmn7iRy1vXufrsu3yK6hgUodhmySVi47ASa7ZUQOYlOVo8jaMrQ?= =?us-ascii?Q?wvrQ3nxqlm3+jIU5pwlY/YxA0dyeqee0zO0jQ9ZP7K6rFOnWeTOzJsEYwP+n?= =?us-ascii?Q?sIXGjgG/T9xdx9iqkHJEGbqIL/YNx/FA3BHNS8Dx9wixlVQM5T7k7dG/Cx+N?= =?us-ascii?Q?hUviGzmhBaYS89Y9W6m2BrRcqWW4QE2tjKEji4Dweecslb3v2fA843rbBtq/?= =?us-ascii?Q?fSch3to6FrSTH2gtn4+sCbQ8FZbGUBz/qjAnl188jUBkEmf+dpo5PwaQqHEq?= =?us-ascii?Q?nZrke5D0us+mG/Guqgo6KkEVgLP7kOrTI0IWCpfoYbodkTYeDmzpMjAA5kt5?= =?us-ascii?Q?b8i802XPmQPAHj1EQ+MqMm3vPylZaksVSsbYhslbY5unxmkMBzQq6aJAG06p?= =?us-ascii?Q?iLm42ST4y8Yrg6GKarcJIU7urklKNbmmOx/DtsQLtOedt79GUcKnIe+Q9WKm?= =?us-ascii?Q?pdpAncgW6aOm0WP+T1YiAd4g8oL3iYJ2QEW90WGKJpoACsU3IxTrYs4eMDS+?= =?us-ascii?Q?tLLxVUPj4UM9xSocULFpiSksOGMAx/2Q3bzd+TpuE7nH5QkDkM5SP9l4vrbG?= =?us-ascii?Q?3RdC4dniBe1Ip6ELEO1LdJrQqFpYan/ZIqCUhiGttGSBhIS1iQF20STK1NLl?= =?us-ascii?Q?BqyEiOBEFknPsAz5SblmdjYz2WUpYXXnNe3GQDHyBS1jUm/kMmnuqx1N2k7n?= =?us-ascii?Q?qBK8BwrBvrTKJ1l+d4yx10k4P5xXqgKhB5OG2PQrHubpCglvTh3ZYdoWtxGJ?= =?us-ascii?Q?DGYypqPgmfUwMm5XxH8e3Ha1GaLFx9GimHKvnKnq61A8HPGgSU28zUGAtOL6?= =?us-ascii?Q?z7U29FROgscMFHjpQqsp+efGQqtf+eOW72T8lemyK1jkjYn/eJDwXuhvgD62?= =?us-ascii?Q?TKvNKfOzLQ=3D=3D?= X-Exchange-RoutingPolicyChecked: LRFlon1Hkct0MSjdsV0IB2xPO1+0YbCFYIaaChdJR51Bn/vRcC3ndCuplSvXA/14OBLisDGcg1al8YwLoHgn+ZoMMoVhbnaN0sag91C4G7NX2i1lvaBr37kuJjWr7YltTLjWw8cDYsIS7ziTSq05x7LtQz4KIljp4YeORtl80ZS3MSWz09pizWAPG+WAm7bEo9fo3EoaXF9VcUf/GplDfF1p11dxjCVfOQtLVL91oohzarX0/yTbYonl4GsVLXmt89tKTmsrR2QWo4H40MpePp6vvb0UFa+8IDowZ0aMhpKTFCkV6VXtoF+pHoUe5MpXq44Z7/EiYvUPnr2V4SUA6A== X-MS-Exchange-CrossTenant-Network-Message-Id: eab7d369-1c07-4035-797d-08df4f24fd4b X-MS-Exchange-CrossTenant-AuthSource: DS7PR11MB5990.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 21:00:39.9909 (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: 9FKGlWlF/WwWZWYAZUrcxUeWgCZeQ2QzPl8+nSPZg0Mfa+Ww9Sr4k1rW88l2Iq6CtRjfvNrJLSCLVKGbiLvCYQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH3PPF5A636EDE4 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 Tue, Dec 01, 2026 at 12:20:46AM +0530, Karthik Poosa wrote: > Expose curve-point temperature and pwm controls via > pwmF_auto_point[P]_temp and pwmF_auto_point[P]_pwm, where > F is the fan number and P is the fan curve point number. > Each fan curve point has a temperature and a pwm attribute. > > Update Xe hwmon ABI documentation for pwm auto point temperature > attributes. > > Signed-off-by: Karthik Poosa > --- > > v2: > - Use xe helpers for dmesg logs. > - Update kernel version in Xe hwmon documentation. > - Correct debug level of some dmesg logs. > > v3: > - Allow variable fan curve points from >=2 to MAX_FAN_CONTROL_POINTS. > - Expose all MAX_FAN_CONTROL_POINTS fan-curve slots so users can extend > a short fan table. > - Stage temp/PWM pairs without changing the active curve. Commit at a > (0, 0) end marker or after all MAX_FAN_CONTROL_POINTS pairs. > - Write the points together, verify the firmware count, then update the > active cache. > > v4: > - Use the two-argument IS_FAN_ENABLED() after rebase. > - Fix kernel-doc for nested staged fan_table members. > - Use "speed" for percent values and "pwm" only for the 0..255 sysfs > value. (Soham) > - Use u32 for the point index in xe_hwmon_commit_user_fan_table(). (Soham) > - Fix comment to say curve points must not decrease. (Soham) > - Add debug logs before -EINVAL returns. (Soham) > - Drop inline from xe_hwmon_get_active_fan_table(). (Soham) > - Use reverse xmas tree ordering for local variables. (Soham) > - Rename xe_hwmon_get_u8_from_sysfs() to xe_hwmon_sysfs_to_hw_val(). > (Soham) > - Use if/else if/else for value selection in pwm auto point show. (Soham) > - Create the fan curve sensor attributes at probe time instead of 60 > static definitions. (Soham) > - Clamp min PWM to 100% and reject pwm values above 100% speed. > - Use xe helpers for logs in the auto point store functions. > > v5: > - Address review comments from Sashiko. > - Remove min_pwm as it is not available. > - Read back the user point count after curve programming and fall back > to stock control when firmware does not accept it. > > v6: > - Require strictly increasing temperatures across curve points, as > firmware rejects equal temperatures. > - Reject tables with fewer than MIN_FAN_CONTROL_POINTS before writing > to firmware. > - Expose pwmN_auto_point* only when the fan has a stock table, like > pwmN_enable. > - Return -ENODATA from pwmN_auto_point* reads while the fan control > mode is not established, like pwmN and pwmN_enable. > - Add the missing ABI documentation for pwm[1-3]_auto_point[1-10]_temp > and pwm[1-3]_auto_point[1-10]_pwm. > - Use reverse xmas tree ordering in xe_hwmon_activate_user_fan_table(). > (Soham) > - Drop the else after return in xe_hwmon_get_active_fan_table(). > (Soham) > - Keep staged curve points when the user table is re-applied on > resume or after late binding; clear them only on pwm_enable writes. > (sashiko) > - Document that a failed completing curve write drops all staged > points. (Soham) > > .../ABI/testing/sysfs-driver-intel-xe-hwmon | 46 ++ > drivers/gpu/drm/xe/xe_hwmon.c | 513 +++++++++++++++--- > 2 files changed, 475 insertions(+), 84 deletions(-) > > diff --git a/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon b/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon > index dbf2c6d01376..81c0c8217d4a 100644 > --- a/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon > +++ b/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon > @@ -374,3 +374,49 @@ Description: RW. Fan control mode selector. > from the firmware stock curve. > > Only supported for particular Intel Xe graphics platforms. > + > +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon/pwm[1-3]_auto_point[1-10]_temp > +Date: December 2026 > +KernelVersion: 7.5 This will have to change if we miss this round. Reviewed-by: Rodrigo Vivi > +Contact: intel-xe@lists.freedesktop.org > +Description: RW. Temperature of fan curve point in millidegree Celsius. > + > + Reads return the point of the stock fan curve when > + pwm[1-3]_enable is 2 and of the user fan curve otherwise. Unused > + points read 0. Reads fail with -ENODATA while the fan control > + mode is not established. > + > + Writes stage the user curve point and require pwm[1-3]_enable > + to be 1; otherwise they are rejected with -EINVAL. See > + pwm[1-3]_auto_point[1-10]_pwm for how the curve is committed. > + > + Only supported for particular Intel Xe graphics platforms. > + > +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon/pwm[1-3]_auto_point[1-10]_pwm > +Date: December 2026 > +KernelVersion: 7.5 > +Contact: intel-xe@lists.freedesktop.org > +Description: RW. Fan PWM duty of fan curve point in the range 0..255, where > + 255 is 100% fan speed. Firmware stores the duty in percent, so > + reads return the value rounded to the nearest percent step. > + > + Reads return the point of the stock fan curve when > + pwm[1-3]_enable is 2 and of the user fan curve otherwise. Unused > + points read 0. Reads fail with -ENODATA while the fan control > + mode is not established. > + > + Writes stage the user curve point and require pwm[1-3]_enable > + to be 1; otherwise they are rejected with -EINVAL. Nonzero > + values are kept at least 1%. > + > + The staged curve is programmed once points 1..K all have both a > + temperature and a PWM value and either point K+1 is set to > + temperature 0 and PWM 0, or K is 10. The end marker is not part > + of the curve. The curve needs at least two points, temperature > + must increase and PWM must not decrease from one point to the > + next; otherwise the completing write fails with -EINVAL. A > + completing write that fails drops all staged points. If > + firmware does not accept the curve, the fan falls back to > + pwm[1-3]_enable 2 and the write fails. > + > + Only supported for particular Intel Xe graphics platforms. > diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c > index 1ef9c12b7110..857c9d293f09 100644 > --- a/drivers/gpu/drm/xe/xe_hwmon.c > +++ b/drivers/gpu/drm/xe/xe_hwmon.c > @@ -174,6 +174,11 @@ enum fan_table_type { > /* Minimum number of points required for a user fan table. */ > #define MIN_FAN_CONTROL_POINTS 2 > > +/* pwmN_auto_pointM_temp and pwmN_auto_pointM_pwm for every curve point of a fan. */ > +#define XE_CURVE_ATTRS_PER_FAN (2 * MAX_FAN_CONTROL_POINTS) > +#define XE_CURVE_ATTRS (FAN_MAX * XE_CURVE_ATTRS_PER_FAN) > +#define XE_CURVE_ATTR_NAME_LEN sizeof("pwmN_auto_pointNN_temp") > + > /* Fan control point index: bit31 selects fan table type; bits30:0 control point index. */ > #define FCP_INDEX(table_type, point_num) (((u32)(table_type) << 31) | \ > ((u32)(point_num) & GENMASK(30, 0))) > @@ -201,6 +206,12 @@ struct xe_hwmon_fan_info { > /** @fan_table.fcp.speed: fan speed in percentage */ > u8 speed; > } fcp[MAX_FAN_CONTROL_POINTS]; > + /** @fan_table.staged_fcp: curve supplied via sysfs but not yet committed */ > + struct fan_control_point staged_fcp[MAX_FAN_CONTROL_POINTS]; > + /** @fan_table.temp_staged: bitmask of temperature fields supplied via sysfs */ > + u16 temp_staged; > + /** @fan_table.speed_staged: bitmask of speed fields supplied via sysfs */ > + u16 speed_staged; > } fan_table[FAN_TABLE_MAX]; > /** @max_rps: maximum fan RPS */ > u32 max_rps; > @@ -266,6 +277,16 @@ struct xe_hwmon { > u32 pl2_on_boot[CHANNEL_MAX]; > /** @temp: Temperature info */ > struct xe_hwmon_thermal_info temp; > + /** @curve_sda: fan curve sensor attributes */ > + struct sensor_device_attribute curve_sda[XE_CURVE_ATTRS]; > + /** @curve_names: names of the fan curve sensor attributes */ > + char curve_names[XE_CURVE_ATTRS][XE_CURVE_ATTR_NAME_LEN]; > + /** @curve_attrs: NULL-terminated list of fan curve attributes */ > + struct attribute *curve_attrs[XE_CURVE_ATTRS + 1]; > + /** @curve_group: fan curve attribute group */ > + struct attribute_group curve_group; > + /** @groups: NULL-terminated list of extra attribute groups */ > + const struct attribute_group *groups[3]; > }; > > static inline int prepare_power_limit_param2(const struct xe_hwmon *hwmon, int channel) > @@ -910,11 +931,6 @@ static const struct attribute_group hwmon_attrgroup = { > .is_visible = xe_hwmon_attributes_visible, > }; > > -static const struct attribute_group *hwmon_groups[] = { > - &hwmon_attrgroup, > - NULL > -}; > - > static const u32 hwmon_temp_config[CHANNEL_MAX + 1] = { > [CHANNEL_CARD] = HWMON_T_LABEL, > [CHANNEL_PKG] = HWMON_T_CRIT | HWMON_T_EMERGENCY | HWMON_T_INPUT | > @@ -1240,55 +1256,65 @@ static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) > return ret; > } > > -static int xe_hwmon_activate_user_fan_table(struct xe_hwmon *hwmon, u8 fan, > - bool is_full_speed, enum fan_table_type table_source) > +static int xe_hwmon_commit_user_fan_table(struct xe_hwmon *hwmon, u8 fan, > + const struct fan_control_point *points, u32 point_count) > { > + /* The extra write is for the final write that sets the number of fan control points */ > struct xe_pcode_write writes[MAX_FAN_CONTROL_POINTS + 1]; > - struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; > - struct fan_table *source_table; > - u32 expected_count, point_count; > - int ret, write_ret, verify_ret; > + u32 accepted_count = 0; > u32 point; > + int ret, write_ret, verify_ret; > > - source_table = &fi->fan_table[table_source]; > - > - xe_dbg(hwmon->xe, "activating fan %d user table from %s table\n", fan, > - (table_source == USER_FAN_TABLE) ? "user" : "stock"); > - > - point_count = source_table->point_count; > - if (!point_count || point_count > MAX_FAN_CONTROL_POINTS) { > - xe_err(hwmon->xe, > - "fan %d %s table point count %d is invalid, cannot activate user table\n", > - fan, (table_source == USER_FAN_TABLE) ? "user" : "stock", point_count); > + if (point_count < MIN_FAN_CONTROL_POINTS) { > + xe_err(hwmon->xe, "fan %d table needs at least %d points, got %u\n", fan, > + MIN_FAN_CONTROL_POINTS, point_count); > return -EINVAL; > } > - expected_count = point_count; > > for (point = 0; point < point_count; point++) { > - u8 temp = source_table->fcp[point].temp; > - u8 speed = is_full_speed ? 100 : min_t(u8, source_table->fcp[point].speed, 100); > + u8 temp = points[point].temp; > + u8 speed = points[point].speed; > + > + /* Firmware requires increasing temperature and non-decreasing speed. */ > + if (point > 0) { > + u8 prev_temp = points[point - 1].temp; > + u8 prev_speed = points[point - 1].speed; > + > + if (temp <= prev_temp || speed < prev_speed) { > + xe_dbg(hwmon->xe, > + "fan %d point %u not monotonic: %u/%u%% after %u/%u%%\n", > + fan, point, temp, speed, prev_temp, prev_speed); > + return -EINVAL; > + } > + } > > - writes[point].mbox = PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_FAN_TABLE, fan); > + /* Prepare the write for this fan control point */ > + writes[point].mbox = PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_FAN_TABLE, > + fan); > writes[point].data = FIELD_PREP(FAN_CONTROL_POINT_TEMP_MASK, temp) | > - FIELD_PREP(FAN_CONTROL_POINT_SPEED_MASK, speed); > + FIELD_PREP(FAN_CONTROL_POINT_SPEED_MASK, speed); > } > > + xe_dbg(hwmon->xe, "committing fan %d user table with %u points\n", fan, point_count); > + > + /* pcode fills the user table from point 0 in write order; the count write commits it. */ > writes[point_count].mbox = PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_NUM_FAN_CONTROL_POINTS, > fan); > writes[point_count].data = point_count; > + > write_ret = xe_pcode_write_batch(xe_device_get_root_tile(hwmon->xe), writes, > point_count + 1); > if (write_ret) > xe_dbg(hwmon->xe, "failed to write fan %d user table, ret=%d\n", fan, write_ret); > > - verify_ret = xe_hwmon_get_fan_point_count(hwmon, fan, &point_count, USER_FAN_TABLE); > - if (write_ret || verify_ret || point_count != expected_count) { > + verify_ret = xe_hwmon_get_fan_point_count(hwmon, fan, &accepted_count, USER_FAN_TABLE); > + if (write_ret || verify_ret || accepted_count != point_count) { > int failure_ret = write_ret ?: verify_ret ?: -EIO; > > - if (verify_ret || point_count != expected_count) > + if (verify_ret || accepted_count != point_count) > xe_err(hwmon->xe, > - "fan %d user table count mismatch: ret=%d, expected=%u, got=%u\n", > - fan, verify_ret, expected_count, point_count); > + "fan %d table count verification failed: ret=%d, expected=%u, got=%u\n", > + fan, verify_ret, point_count, accepted_count); > /* Firmware may have accepted only part of the table; fall back to stock. */ > ret = xe_hwmon_fan_set_auto(hwmon, fan); > if (ret) > @@ -1297,15 +1323,45 @@ static int xe_hwmon_activate_user_fan_table(struct xe_hwmon *hwmon, u8 fan, > return failure_ret; > } > > + xe_dbg(hwmon->xe, "fan %d user table committed successfully with %u points\n", fan, > + point_count); > + return 0; > +} > + > +static int xe_hwmon_activate_user_fan_table(struct xe_hwmon *hwmon, u8 fan, > + bool is_full_speed, enum fan_table_type table_source) > +{ > + struct fan_control_point points[MAX_FAN_CONTROL_POINTS]; > + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; > + struct fan_table *source_table, *user_table; > + u32 point_count, point; > + int ret; > + > + source_table = &fi->fan_table[table_source]; > + user_table = &fi->fan_table[USER_FAN_TABLE]; > + point_count = source_table->point_count; > + > + xe_dbg(hwmon->xe, "activating fan %d user table from %s table\n", fan, > + (table_source == USER_FAN_TABLE) ? "user" : "stock"); > + > + for (point = 0; point < point_count; point++) { > + points[point].temp = source_table->fcp[point].temp; > + points[point].speed = is_full_speed ? 100 : > + min_t(u8, source_table->fcp[point].speed, 100); > + } > + > + ret = xe_hwmon_commit_user_fan_table(hwmon, fan, points, point_count); > + if (ret) > + return ret; > + > /* Full speed only overrides firmware; the cache keeps the manual curve. */ > if (table_source == STOCK_FAN_TABLE) { > for (point = 0; point < point_count; point++) { > - fi->fan_table[USER_FAN_TABLE].fcp[point].temp = > - source_table->fcp[point].temp; > - fi->fan_table[USER_FAN_TABLE].fcp[point].speed = > - min_t(u8, source_table->fcp[point].speed, 100); > + user_table->fcp[point].temp = source_table->fcp[point].temp; > + user_table->fcp[point].speed = min_t(u8, source_table->fcp[point].speed, > + 100); > } > - fi->fan_table[USER_FAN_TABLE].point_count = point_count; > + user_table->point_count = point_count; > } > > fi->pwm_enable_mode = is_full_speed ? XE_FAN_PWM_FULL_SPEED : > @@ -1319,10 +1375,10 @@ static int xe_hwmon_activate_user_fan_table(struct xe_hwmon *hwmon, u8 fan, > > static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm) > { > - struct xe_pcode_write writes[MIN_FAN_CONTROL_POINTS + 1]; > struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; > - int ret, write_ret, verify_ret, i; > - u32 point_count = 0; > + struct fan_table *user_table = &fi->fan_table[USER_FAN_TABLE]; > + struct fan_control_point points[MIN_FAN_CONTROL_POINTS]; > + int ret, i; > u8 speed; > > if (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE) { > @@ -1331,58 +1387,341 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm) > } > > /* Fan table speed are in percent. */ > - speed = DIV_ROUND_CLOSEST(pwm * 100, U8_MAX); > - speed = min_t(u32, speed, 100); > + speed = min_t(u32, DIV_ROUND_CLOSEST(pwm * 100, U8_MAX), 100); > > /* Fan control needs at least two points; program them all at the same speed. */ > for (i = 0; i < MIN_FAN_CONTROL_POINTS; i++) { > - writes[i].mbox = PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_FAN_TABLE, fan); > - writes[i].data = FIELD_PREP(FAN_CONTROL_POINT_TEMP_MASK, FIXED_PWM_TEMP + i) | > - FIELD_PREP(FAN_CONTROL_POINT_SPEED_MASK, speed); > - xe_dbg(hwmon->xe, "prepared fan control point %d with temp=%d, speed=%u%%\n", i, > - FIXED_PWM_TEMP + i, speed); > + points[i].temp = FIXED_PWM_TEMP + i; > + points[i].speed = speed; > } > > - /* pcode fills the user table from point 0 in write order; the count write commits it. */ > - writes[i].mbox = PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_NUM_FAN_CONTROL_POINTS, fan); > - writes[i].data = MIN_FAN_CONTROL_POINTS; > - write_ret = xe_pcode_write_batch(xe_device_get_root_tile(hwmon->xe), writes, > - ARRAY_SIZE(writes)); > - if (write_ret) > - xe_err(hwmon->xe, "failed to write pwm %u (%u%%) for fan %d, ret=%d\n", > - pwm, speed, fan, write_ret); > + ret = xe_hwmon_commit_user_fan_table(hwmon, fan, points, MIN_FAN_CONTROL_POINTS); > + if (ret) { > + xe_err(hwmon->xe, "failed to set pwm %u (%u%%) for fan %d, ret=%d\n", > + pwm, speed, fan, ret); > + return ret; > + } > + > + memcpy(user_table->fcp, points, sizeof(points)); > + user_table->point_count = MIN_FAN_CONTROL_POINTS; > + user_table->temp_staged = 0; > + user_table->speed_staged = 0; > + xe_dbg(hwmon->xe, "applied pwm %u (%u%%) for fan %d\n", pwm, speed, fan); > + > + return 0; > +} > + > +#define XE_CURVE_IDX(fan, point) (((fan) << 8) | (point)) > +#define XE_CURVE_FAN(idx) ((u8)(((idx) >> 8) & 0xff)) > +#define XE_CURVE_POINT(idx) ((u8)((idx) & 0xff)) > + > +static int > +xe_hwmon_decode_curve_index(struct xe_hwmon *hwmon, u32 index, u8 *fan, u8 *point) > +{ > + u8 local_fan = XE_CURVE_FAN(index); > + u8 local_point = XE_CURVE_POINT(index); > + > + if (local_fan >= FAN_MAX || local_point >= MAX_FAN_CONTROL_POINTS) { > + xe_dbg(hwmon->xe, "invalid fan curve index 0x%x: fan %u point %u\n", > + index, local_fan, local_point); > + return -EINVAL; > + } > + > + *fan = local_fan; > + *point = local_point; > + > + return 0; > +} > + > +static enum fan_table_type xe_hwmon_get_active_fan_table(struct xe_hwmon *hwmon, u8 fan) > +{ > + return (hwmon->fi[fan].pwm_enable_mode == XE_FAN_PWM_AUTO_STOCK_TABLE) ? STOCK_FAN_TABLE : > + USER_FAN_TABLE; > +} > + > +static ssize_t > +xe_hwmon_pwm_auto_point_temp_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); > + struct xe_hwmon *hwmon = dev_get_drvdata(dev); > + enum fan_table_type active_table; > + struct xe_hwmon_fan_info *fi; > + u32 point_count; > + u8 point; > + u8 temp; > + int ret; > + u8 fan; > + > + ret = xe_hwmon_decode_curve_index(hwmon, sattr->index, &fan, &point); > + if (ret) > + return ret; > + > + guard(mutex)(&hwmon->hwmon_lock); > + > + fi = &hwmon->fi[fan]; > + if (fi->pwm_enable_mode == XE_FAN_PWM_UNINITIALIZED) > + return -ENODATA; > + > + active_table = xe_hwmon_get_active_fan_table(hwmon, fan); > + > + point_count = fi->fan_table[active_table].point_count; > + > + if (point >= point_count) > + temp = 0; > else > - xe_dbg(hwmon->xe, "applied pwm %u (%u%%) for fan %d\n", pwm, speed, fan); > + temp = fi->fan_table[active_table].fcp[point].temp; > + return sysfs_emit(buf, "%u\n", temp * MILLIDEGREE_PER_DEGREE); > +} > > - verify_ret = xe_hwmon_get_fan_point_count(hwmon, fan, &point_count, USER_FAN_TABLE); > - if (write_ret || verify_ret || point_count != MIN_FAN_CONTROL_POINTS) { > - int failure_ret = write_ret ?: verify_ret ?: -EIO; > +static int xe_hwmon_update_user_fan_point(struct xe_hwmon *hwmon, u8 fan, u32 point, > + bool is_temp, u8 value) > +{ > + struct xe_hwmon_fan_info *fi = &hwmon->fi[fan]; > + struct fan_table *table; > + u32 point_count; > + int ret; > > - if (verify_ret || point_count != MIN_FAN_CONTROL_POINTS) > - xe_err(hwmon->xe, > - "fan %d PWM table count verification failed: ret=%d, count=%u\n", > - fan, verify_ret, point_count); > - /* Firmware may have accepted only part of the table; fall back to stock. */ > - ret = xe_hwmon_fan_set_auto(hwmon, fan); > - if (ret) > - xe_err(hwmon->xe, "failed to restore fan %d to auto mode ret=%d\n", > - fan, ret); > - return failure_ret; > + table = &fi->fan_table[USER_FAN_TABLE]; > + > + if (is_temp) { > + table->staged_fcp[point].temp = value; > + table->temp_staged |= BIT(point); > + } else { > + table->staged_fcp[point].speed = value; > + table->speed_staged |= BIT(point); > } > > - /* Update the user fan table cache. */ > - for (i = 0; i < MIN_FAN_CONTROL_POINTS; i++) { > - fi->fan_table[USER_FAN_TABLE].fcp[i].temp = FIXED_PWM_TEMP + i; > - fi->fan_table[USER_FAN_TABLE].fcp[i].speed = speed; > - xe_dbg(hwmon->xe, "fan %d user table cache point %d with temp=%d, speed=%u%%\n", > - fan, i, fi->fan_table[USER_FAN_TABLE].fcp[i].temp, > - fi->fan_table[USER_FAN_TABLE].fcp[i].speed); > + /* Wait for a complete prefix; (0, 0) ends the curve without becoming a point. */ > + for (point_count = 0; point_count < MAX_FAN_CONTROL_POINTS; point_count++) { > + if (!(table->temp_staged & BIT(point_count)) || > + !(table->speed_staged & BIT(point_count))) > + return 0; > + if (!table->staged_fcp[point_count].temp && > + !table->staged_fcp[point_count].speed) > + break; > + } > + > + if (point_count < MIN_FAN_CONTROL_POINTS) { > + xe_dbg(hwmon->xe, "fan %d curve needs at least %d points, got %u\n", > + fan, MIN_FAN_CONTROL_POINTS, point_count); > + ret = -EINVAL; > + goto clear_staged; > } > - fi->fan_table[USER_FAN_TABLE].point_count = MIN_FAN_CONTROL_POINTS; > + > + ret = xe_hwmon_commit_user_fan_table(hwmon, fan, table->staged_fcp, point_count); > + if (ret) > + goto clear_staged; > + > + /* Publish the new curve only after firmware accepts its point count. */ > + memcpy(table->fcp, table->staged_fcp, point_count * sizeof(table->fcp[0])); > + table->point_count = point_count; > + fi->pwm_enable_mode = XE_FAN_PWM_MANUAL_USER_TABLE; > + > +clear_staged: > + table->temp_staged = 0; > + table->speed_staged = 0; > + return ret; > +} > + > +static int xe_hwmon_sysfs_to_hw_val(struct xe_hwmon *hwmon, long val, bool is_temp, u8 *out) > +{ > + long max = is_temp ? U8_MAX * MILLIDEGREE_PER_DEGREE : U8_MAX; > + long hw_val; > + > + if (val < 0 || val > max) { > + xe_dbg(hwmon->xe, "%s value %ld out of range\n", is_temp ? "temp" : "pwm", val); > + return -EINVAL; > + } > + > + /* Temperature is in degrees Celsius, speed in percent. */ > + if (is_temp) > + hw_val = DIV_ROUND_CLOSEST(val, MILLIDEGREE_PER_DEGREE); > + else > + hw_val = DIV_ROUND_CLOSEST(val * 100, U8_MAX); > + > + if (!is_temp && val && !hw_val) > + hw_val = 1; > + > + *out = hw_val; > > return 0; > } > > +static ssize_t > +xe_hwmon_pwm_auto_point_temp_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); > + struct xe_hwmon *hwmon = dev_get_drvdata(dev); > + struct xe_hwmon_fan_info *fi; > + long val; > + u8 point; > + u8 temp; > + int ret; > + u8 fan; > + > + ret = xe_hwmon_decode_curve_index(hwmon, sattr->index, &fan, &point); > + if (ret) > + return ret; > + > + ret = kstrtol(buf, 10, &val); > + if (ret) > + return ret; > + > + ret = xe_hwmon_sysfs_to_hw_val(hwmon, val, true, &temp); > + if (ret) > + return ret; > + > + guard(xe_pm_runtime)(hwmon->xe); > + > + guard(mutex)(&hwmon->hwmon_lock); > + fi = &hwmon->fi[fan]; > + > + if (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE) { > + xe_dbg(hwmon->xe, "pwm%d_enable not in manual mode; cannot update temp point %d\n", > + fan + 1, point + 1); > + return -EINVAL; > + } > + > + xe_dbg(hwmon->xe, "staging fan %d point %d temp to %u\n", fan, point, temp); > + ret = xe_hwmon_update_user_fan_point(hwmon, fan, point, true, temp); > + > + return ret ? ret : count; > +} > + > +static ssize_t > +xe_hwmon_pwm_auto_point_pwm_show(struct device *dev, > + struct device_attribute *attr, > + char *buf) > +{ > + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); > + struct xe_hwmon *hwmon = dev_get_drvdata(dev); > + enum fan_table_type active_table; > + struct xe_hwmon_fan_info *fi; > + u32 point_count; > + u8 point; > + u8 speed; > + int ret; > + u8 fan; > + > + ret = xe_hwmon_decode_curve_index(hwmon, sattr->index, &fan, &point); > + if (ret) > + return ret; > + > + guard(mutex)(&hwmon->hwmon_lock); > + > + fi = &hwmon->fi[fan]; > + if (fi->pwm_enable_mode == XE_FAN_PWM_UNINITIALIZED) > + return -ENODATA; > + > + active_table = xe_hwmon_get_active_fan_table(hwmon, fan); > + > + point_count = fi->fan_table[active_table].point_count; > + > + if (point >= point_count) > + speed = 0; > + else > + speed = fi->fan_table[active_table].fcp[point].speed; > + return sysfs_emit(buf, "%u\n", DIV_ROUND_CLOSEST(speed * U8_MAX, 100)); > +} > + > +static ssize_t > +xe_hwmon_pwm_auto_point_pwm_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct sensor_device_attribute *sattr = to_sensor_dev_attr(attr); > + struct xe_hwmon *hwmon = dev_get_drvdata(dev); > + struct xe_hwmon_fan_info *fi; > + long val; > + u8 point; > + u8 speed; > + int ret; > + u8 fan; > + > + ret = xe_hwmon_decode_curve_index(hwmon, sattr->index, &fan, &point); > + if (ret) > + return ret; > + > + ret = kstrtol(buf, 10, &val); > + if (ret) > + return ret; > + > + ret = xe_hwmon_sysfs_to_hw_val(hwmon, val, false, &speed); > + if (ret) > + return ret; > + > + guard(xe_pm_runtime)(hwmon->xe); > + > + guard(mutex)(&hwmon->hwmon_lock); > + fi = &hwmon->fi[fan]; > + > + if (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE) { > + xe_dbg(hwmon->xe, > + "pwm%d_enable is not in manual user mode, cannot update pwm point %d\n", > + fan + 1, point + 1); > + return -EINVAL; > + } > + > + xe_dbg(hwmon->xe, "staging fan %d point %d speed to %u%%\n", fan, point, speed); > + ret = xe_hwmon_update_user_fan_point(hwmon, fan, point, false, speed); > + > + return ret ? ret : count; > +} > + > +static umode_t xe_hwmon_curve_attributes_visible(struct kobject *kobj, > + struct attribute *attr, int index) > +{ > + struct device *dev = kobj_to_dev(kobj); > + struct xe_hwmon *hwmon = dev_get_drvdata(dev); > + u32 fan = index / XE_CURVE_ATTRS_PER_FAN; > + > + /* 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) > + return 0; > + > + /* All slots must exist at registration, before the user curve has been staged. */ > + return attr->mode; > +} > + > +static void xe_hwmon_init_curve_attrs(struct xe_hwmon *hwmon) > +{ > + int fan, kind, point, i = 0; > + > + /* Per fan: all temp points then all pwm points; is_visible relies on this layout. */ > + for (fan = 0; fan < FAN_MAX; fan++) { > + for (kind = 0; kind < 2; kind++) { > + bool is_temp = !kind; > + > + for (point = 0; point < MAX_FAN_CONTROL_POINTS; point++, i++) { > + struct sensor_device_attribute *sda = &hwmon->curve_sda[i]; > + > + snprintf(hwmon->curve_names[i], XE_CURVE_ATTR_NAME_LEN, > + "pwm%d_auto_point%d_%s", fan + 1, point + 1, > + is_temp ? "temp" : "pwm"); > + sysfs_attr_init(&sda->dev_attr.attr); > + sda->dev_attr.attr.name = hwmon->curve_names[i]; > + sda->dev_attr.attr.mode = 0644; > + if (is_temp) { > + sda->dev_attr.show = xe_hwmon_pwm_auto_point_temp_show; > + sda->dev_attr.store = xe_hwmon_pwm_auto_point_temp_store; > + } else { > + sda->dev_attr.show = xe_hwmon_pwm_auto_point_pwm_show; > + sda->dev_attr.store = xe_hwmon_pwm_auto_point_pwm_store; > + } > + sda->index = XE_CURVE_IDX(fan, point); > + hwmon->curve_attrs[i] = &sda->dev_attr.attr; > + } > + } > + } > + > + hwmon->curve_group.attrs = hwmon->curve_attrs; > + hwmon->curve_group.is_visible = xe_hwmon_curve_attributes_visible; > +} > + > static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon) > { > int point; > @@ -2075,12 +2414,6 @@ xe_hwmon_fan_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) > } > } > > -static enum fan_table_type xe_hwmon_get_active_fan_table(struct xe_hwmon *hwmon, u8 fan) > -{ > - return (hwmon->fi[fan].pwm_enable_mode == XE_FAN_PWM_AUTO_STOCK_TABLE) ? STOCK_FAN_TABLE : > - USER_FAN_TABLE; > -} > - > /** > * xe_hwmon_get_active_table_pwm - Calculate PWM from the active fan curve > * @hwmon: hwmon instance, with hwmon_lock held and runtime PM active > @@ -2278,9 +2611,13 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) > USER_FAN_TABLE : STOCK_FAN_TABLE; > > ret = xe_hwmon_activate_user_fan_table(hwmon, channel, full_speed, source); > - if (ret) > + if (ret) { > xe_warn(hwmon->xe, "failed to set fan %d pwm_enable %ld, ret=%d\n", > channel, val, ret); > + break; > + } > + fi->fan_table[USER_FAN_TABLE].temp_staged = 0; > + fi->fan_table[USER_FAN_TABLE].speed_staged = 0; > } else if (val == XE_FAN_PWM_AUTO_STOCK_TABLE) { > ret = xe_hwmon_fan_set_auto(hwmon, channel); > if (ret) { > @@ -2292,6 +2629,8 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) > xe_dbg(hwmon->xe, > "automatic control enabled for fan %d using stock table\n", > channel); > + fi->fan_table[USER_FAN_TABLE].temp_staged = 0; > + fi->fan_table[USER_FAN_TABLE].speed_staged = 0; > } else { > xe_dbg(hwmon->xe, "invalid pwm%d_enable value %ld\n", channel + 1, val); > ret = -EINVAL; > @@ -2543,10 +2882,16 @@ int xe_hwmon_register(struct xe_device *xe) > > drm_dbg(&xe->drm, "Register xe hwmon interface\n"); > > + hwmon->groups[0] = &hwmon_attrgroup; > + if (xe->info.has_fan_control) { > + xe_hwmon_init_curve_attrs(hwmon); > + hwmon->groups[1] = &hwmon->curve_group; > + } > + > /* hwmon_dev points to device hwmon */ > hwmon->hwmon_dev = hwmon_device_register_with_info(dev, "xe", hwmon, > &hwmon_chip_info, > - hwmon_groups); > + hwmon->groups); > if (IS_ERR(hwmon->hwmon_dev)) { > ret = PTR_ERR(hwmon->hwmon_dev); > xe_log_err(xe, HWMON, ret, "Failed to register xe hwmon\n"); > -- > 2.34.1 >