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 80E1E606A322 for ; Thu, 3 Dec 2026 09:05:49 +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=gbTd0ofZ Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4830511201C; Thu, 3 Dec 2026 09:05:44 +0000 (UTC) Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.18]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3B3F41120F4 for ; Thu, 3 Dec 2026 09:05:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796288739; x=1827824739; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=1xBJPsXIfqeLiMhH5nyCTNqCjj+eTMEaQ0+vZjCNWJs=; b=gbTd0ofZGhBTL0RfZQQfuZbmXRYAxMKwGnjBDBGj4EFlfcU2zdJyRo9M NqU7ipPbwR3R4Py8JtfwfCuCnpbO8T6y21065y37ybNmhzFOIbK/BnCSZ z0vTjZZr7RgfW7hh1XlZBNoUx4bswdCYgmu3KZwDo+fm2yVa250MTODpI 42Nn5CAeRAIlOxDa72ZLm8VVKcK7lEOjvsu+2bLNHtVuAO8KH1S3TUmtV yiwDnzf8SxaDXMuapREbnDOn/l++RXSpQ2zewVxKtBlOFJScYOa85rHt8 fIXCeRYz5PfiCoWMC2Iy+5E+6HxsTn4A6M6qvX9PhYHdelPmvSY006XW4 A==; X-CSE-ConnectionGUID: Cjn/ZqeASCS6rBGG6bP90A== X-CSE-MsgGUID: DB4ld11eQ9Gg1hpcDVV6BQ== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5254261" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5254261" Received: from fmviesa013.fm.intel.com ([10.60.135.153]) by orvoesa110.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 01:05:38 -0800 X-CSE-ConnectionGUID: XHARSiFqTcSV7N7F7HqXXQ== X-CSE-MsgGUID: EbeOXEfIQTKRp2H+HMJBiQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="15730381" Received: from sinjan-super-server.iind.intel.com ([10.190.239.39]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 01:05:36 -0800 From: Karthik Poosa To: intel-xe@lists.freedesktop.org Cc: rodrigo.vivi@intel.com, anshuman.gupta@intel.com, badal.nilawar@intel.com, raag.jadav@intel.com, soham.purkait@intel.com, riana.tauro@intel.com, Karthik Poosa Subject: [PATCH v11 06/11] drm/xe/hwmon: Expose pwm[1-3]_enable Date: Thu, 3 Dec 2026 14:37:00 +0530 Message-Id: <20261203090705.2500610-7-karthik.poosa@intel.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20261203090705.2500610-1-karthik.poosa@intel.com> References: <20261203090705.2500610-1-karthik.poosa@intel.com> X-Archived-By: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=-18.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,USER_AGENT_GIT 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 Expose pwm[1-3]_enable to control the fan operating mode through the hwmon interface. Mode 0 forces the fan to run at full speed. Mode 1 enables user fan-table control. Mode 2 restores firmware-controlled fan management. pwm[1-3] writes now require pwm[1-3]_enable to be 1 first. Since fans start in mode 2 after probe, a pwm[1-3] write without selecting manual mode is rejected with -EINVAL. Document pwm[1-3]_enable in the Xe hwmon ABI. Reviewed-by: Rodrigo Vivi Reviewed-by: Soham Purkait Signed-off-by: Karthik Poosa --- v2: - Use xe helpers for dmesg logs. - Update kernel version in Xe hwmon documentation. - Correct level of some dmesg logs. v3: - Each pwm_enable mode now sets its own state; drop the redundant post-switch pwm_enable_mode/is_full_speed update. (Badal) - Fix misindented dead assignment in the stock-table branch. - Make error handling consistent across pwm_enable modes. (Badal) - Document the pwm[1-3] manual-mode write precondition in the ABI. (Badal) - Use xe_pcode_write() instead of the timeout variant api as it is not needed. v4: - Rebase on reworked pwm[1-3] patch. - Clamp min PWM to 100% when activating the user table, since fan table speed is in percent. - Drop redundant channel range check in pwm write. - Use tab indentation and update Date and KernelVersion to November 2026 and 7.5 in the pwm[1-3]_enable ABI entry. v5: - Address review comments from sashiko. - Avoid returning pwm[1-3]_enable as XE_FAN_PWM_MANUAL_USER_TABLE, when setting to full speed mode. (sashiko) - Set default pwm[1-3]_enable to XE_FAN_PWM_AUTO_STOCK_TABLE after probe. (sashiko) - Make pwm[1-3]_enable visible only if stock fan table has valid point count. - Add flag XE_FAN_PWM_UNINITIALIZED. - Fall back to the stock table if firmware does not accept a table. v6: - Remove is_full_speed as it is redundant with pwm_enable_mode now. - Rename xe_hwmon_get_stock_table_pwm() to xe_hwmon_get_active_table_pwm(). - Avoid overwriting user table cache for full speed. - Align pwm_enable mode kernel-doc with the ABI wording. (Soham) - Add debug logs before -EINVAL returns. (Soham) - Note the pwm[1-3] write precondition in the commit message. (Soham) v7: - Use xe_hwmon_commit_user_fan_table() helper in xe_hwmon_activate_user_fan_table() for table update. (Badal) - Return -ENODATA from pwm[1-3] reads on BMG too while the fan control mode is not established. (sashiko) - Add debug log if fan control mode is uninitialized. (Rodrigo) - Made source_table const in xe_hwmon_commit_user_fan_table(). - Added a user_table pointer for stock-table cache updates. - Avoided redundant cache updates when the source is already USER_FAN_TABLE. .../ABI/testing/sysfs-driver-intel-xe-hwmon | 19 ++ drivers/gpu/drm/xe/xe_hwmon.c | 196 +++++++++++++++--- 2 files changed, 187 insertions(+), 28 deletions(-) diff --git a/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon b/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon index 34c50f13f0b4..dbf2c6d01376 100644 --- a/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon +++ b/Documentation/ABI/testing/sysfs-driver-intel-xe-hwmon @@ -354,4 +354,23 @@ Contact: intel-xe@lists.freedesktop.org Description: RW. Target fan PWM duty value in the range 0..255, where 255 is 100% fan speed. + Writing requires the corresponding pwm[1-3]_enable to be set to + 1 (manual user-table mode) first; otherwise the write is + rejected with -EINVAL. + + Only supported for particular Intel Xe graphics platforms. + +What: /sys/bus/pci/drivers/xe/.../hwmon/hwmon/pwm[1-3]_enable +Date: December 2026 +KernelVersion: 7.5 +Contact: intel-xe@lists.freedesktop.org +Description: RW. Fan control mode selector. + + Use value 0 to run fans at full speed. Use value 1 to enable + user table control and value 2 to use firmware default behavior. + + The user fan curve is kept across modes 0 and 2, and re-applied + when switching back to 1. Without a user curve, mode 1 starts + from the firmware stock curve. + 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 6f47865dbf61..614fb392f899 100644 --- a/drivers/gpu/drm/xe/xe_hwmon.c +++ b/drivers/gpu/drm/xe/xe_hwmon.c @@ -146,6 +146,20 @@ struct xe_hwmon_energy_info { long accum_energy; }; +/** + * enum xe_fan_pwm_enable_mode - fan PWM enable modes + */ +enum xe_fan_pwm_enable_mode { + /** @XE_FAN_PWM_FULL_SPEED: run the fan at full speed */ + XE_FAN_PWM_FULL_SPEED = 0, + /** @XE_FAN_PWM_MANUAL_USER_TABLE: user table control */ + XE_FAN_PWM_MANUAL_USER_TABLE = 1, + /** @XE_FAN_PWM_AUTO_STOCK_TABLE: firmware default behavior using the stock table */ + XE_FAN_PWM_AUTO_STOCK_TABLE = 2, + /** @XE_FAN_PWM_UNINITIALIZED: fan control mode is not established */ + XE_FAN_PWM_UNINITIALIZED = 0xff, +}; + /** * enum fan_table_type - fan table types tracked per fan */ @@ -197,6 +211,8 @@ struct xe_hwmon_fan_info { } fan_table[FAN_TABLE_MAX]; /** @max_rps: maximum fan RPS */ u32 max_rps; + /** @pwm_enable_mode: current xe_fan_pwm_enable_mode */ + u8 pwm_enable_mode; }; /** @@ -933,7 +949,9 @@ static const struct hwmon_channel_info * const hwmon_info[] = { HWMON_CHANNEL_INFO(energy, HWMON_E_INPUT | HWMON_E_LABEL, HWMON_E_INPUT | HWMON_E_LABEL), HWMON_CHANNEL_INFO(fan, HWMON_F_INPUT | HWMON_F_MAX, HWMON_F_INPUT | HWMON_F_MAX, HWMON_F_INPUT | HWMON_F_MAX), - HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT, HWMON_PWM_INPUT, HWMON_PWM_INPUT), + HWMON_CHANNEL_INFO(pwm, HWMON_PWM_INPUT | HWMON_PWM_ENABLE, + HWMON_PWM_INPUT | HWMON_PWM_ENABLE, + HWMON_PWM_INPUT | HWMON_PWM_ENABLE), NULL }; @@ -1218,11 +1236,14 @@ static int xe_hwmon_fan_set_auto(struct xe_hwmon *hwmon, u8 fan) PCODE_MBOX(FAN_SPEED_CONTROL, FSC_WRITE_NUM_FAN_CONTROL_POINTS, fan), 0); if (ret) - return ret; - - fi->fan_table[USER_FAN_TABLE].point_count = 0; + goto fail; + fi->pwm_enable_mode = XE_FAN_PWM_AUTO_STOCK_TABLE; return 0; + +fail: + fi->pwm_enable_mode = XE_FAN_PWM_UNINITIALIZED; + return ret; } static int xe_hwmon_commit_user_fan_table(struct xe_hwmon *hwmon, u8 fan, @@ -1298,6 +1319,56 @@ static int xe_hwmon_commit_user_fan_table(struct xe_hwmon *hwmon, u8 fan, 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 xe_hwmon_fan_info *fi = &hwmon->fi[fan]; + struct fan_control_point points[MAX_FAN_CONTROL_POINTS]; + const struct fan_table *source_table; + u32 point_count, point; + int 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 %u is invalid, cannot activate user table\n", + fan, (table_source == USER_FAN_TABLE) ? "user" : "stock", point_count); + return -EINVAL; + } + + 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) { + struct fan_table *user_table = &fi->fan_table[USER_FAN_TABLE]; + + for (point = 0; point < point_count; point++) { + user_table->fcp[point].temp = source_table->fcp[point].temp; + user_table->fcp[point].speed = + min_t(u8, source_table->fcp[point].speed, 100); + } + user_table->point_count = point_count; + } + + fi->pwm_enable_mode = is_full_speed ? XE_FAN_PWM_FULL_SPEED : + XE_FAN_PWM_MANUAL_USER_TABLE; + + return 0; +} + /* Temperature to set when setting the fan PWM with pwm[1-3]. */ #define FIXED_PWM_TEMP 1 @@ -1309,6 +1380,11 @@ static int xe_hwmon_set_user_fan_pwm(struct xe_hwmon *hwmon, u8 fan, u8 pwm) int ret, i; u8 speed; + if (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE) { + xe_dbg(hwmon->xe, "fan %d manual mode is not active, cannot set pwm\n", fan); + return -EINVAL; + } + /* Fan table speed are in percent. */ speed = min_t(u32, DIV_ROUND_CLOSEST(pwm * 100, U8_MAX), 100); @@ -1408,6 +1484,8 @@ static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon) stock_fcp_count * sizeof(stock_fcp[0])); fi->fan_table[STOCK_FAN_TABLE].point_count = stock_fcp_count; found = true; + if (fi->pwm_enable_mode == XE_FAN_PWM_UNINITIALIZED) + fi->pwm_enable_mode = XE_FAN_PWM_AUTO_STOCK_TABLE; } /* Succeed if any enabled fan's stock table was read. */ @@ -1972,6 +2050,7 @@ xe_hwmon_pwm_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel) switch (attr) { case hwmon_pwm_input: + case hwmon_pwm_enable: return 0644; default: return 0; @@ -2031,25 +2110,43 @@ 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_stock_table_pwm - Calculate PWM from the stock fan curve + * xe_hwmon_get_active_table_pwm - Calculate PWM from the active fan curve * @hwmon: hwmon instance, with hwmon_lock held and runtime PM active * @channel: fan channel * @val: calculated PWM percentage * - * Read package temperature and linearly interpolate the stock table. Temperatures - * outside the table range use the speed at the nearest endpoint. + * Read package temperature and linearly interpolate the fan table selected by + * pwm_enable. Temperatures outside the table range use the nearest endpoint. * * Return: 0 on success, or a negative error code. */ -static int xe_hwmon_get_stock_table_pwm(struct xe_hwmon *hwmon, int channel, long *val) +static int xe_hwmon_get_active_table_pwm(struct xe_hwmon *hwmon, int channel, long *val) { - const struct fan_table *table = &hwmon->fi[channel].fan_table[STOCK_FAN_TABLE]; + const struct fan_table *table; long temperature, pwm; int point, ret; lockdep_assert_held(&hwmon->hwmon_lock); + switch (hwmon->fi[channel].pwm_enable_mode) { + case XE_FAN_PWM_UNINITIALIZED: + return -ENODATA; + case XE_FAN_PWM_FULL_SPEED: + *val = 100; + return 0; + default: + break; + } + + table = &hwmon->fi[channel].fan_table[xe_hwmon_get_active_fan_table(hwmon, channel)]; + if (!table->point_count) return -ENODATA; @@ -2077,7 +2174,7 @@ static int xe_hwmon_get_stock_table_pwm(struct xe_hwmon *hwmon, int channel, lon } *val = pwm; - xe_dbg(hwmon->xe, "fan %d stock table active PWM value: %ld\n", channel, pwm); + xe_dbg(hwmon->xe, "fan %d: pwm value from active table cache: %ld\n", channel, pwm); return 0; } @@ -2146,25 +2243,25 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) switch (attr) { case hwmon_pwm_input: - /* If the user fan table is not populated, get active stock pwm */ - if (!fi->fan_table[USER_FAN_TABLE].point_count) { - xe_dbg(hwmon->xe, "user fan table not active for fan %d\n", channel); - switch (hwmon->xe->info.platform) { - case XE_BATTLEMAGE: + switch (hwmon->xe->info.platform) { + case XE_BATTLEMAGE: + if (fi->pwm_enable_mode == XE_FAN_PWM_UNINITIALIZED) + ret = -ENODATA; + else ret = xe_hwmon_get_pwm_from_pmt(hwmon, channel, &pwm); - break; - default: - ret = xe_hwmon_get_stock_table_pwm(hwmon, channel, &pwm); - break; - } - if (ret) - goto unlock; - } else { - /* - * pwmN writes set every user-table point to the same speed, - * so the first point gives the cached manual PWM percentage. - */ - pwm = fi->fan_table[USER_FAN_TABLE].fcp[0].speed; + break; + default: + ret = xe_hwmon_get_active_table_pwm(hwmon, channel, &pwm); + break; + } + if (ret == -ENODATA) { + xe_dbg(hwmon->xe, "fan %d control mode not established\n", channel); + goto unlock; + } + if (ret) { + xe_err(hwmon->xe, "failed to get active pwm for fan %d, ret=%d\n", + channel, ret); + goto unlock; } if (pwm < 0 || pwm > 100) { xe_dbg(hwmon->xe, "invalid PWM value %ld read for fan %d\n", pwm, channel); @@ -2175,6 +2272,14 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) *val = DIV_ROUND_CLOSEST(pwm * U8_MAX, 100); xe_dbg(hwmon->xe, "pwm read for fan %d: %ld\n", channel, *val); break; + case hwmon_pwm_enable: + if (fi->pwm_enable_mode == XE_FAN_PWM_UNINITIALIZED) { + xe_dbg(hwmon->xe, "fan %d control mode is not initialized\n", channel); + ret = -ENODATA; + goto unlock; + } + *val = fi->pwm_enable_mode; + break; default: ret = -EOPNOTSUPP; break; @@ -2188,8 +2293,11 @@ xe_hwmon_pwm_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val) static int xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) { + struct xe_hwmon_fan_info *fi; int ret = 0; + fi = &hwmon->fi[channel]; + mutex_lock(&hwmon->hwmon_lock); switch (attr) { @@ -2201,6 +2309,33 @@ xe_hwmon_pwm_write(struct xe_hwmon *hwmon, u32 attr, int channel, long val) } ret = xe_hwmon_set_user_fan_pwm(hwmon, channel, (u8)val); break; + case hwmon_pwm_enable: + if (val == XE_FAN_PWM_FULL_SPEED || val == XE_FAN_PWM_MANUAL_USER_TABLE) { + bool full_speed = val == XE_FAN_PWM_FULL_SPEED; + /* Without a user curve, start from the clamped stock table. */ + enum fan_table_type source = fi->fan_table[USER_FAN_TABLE].point_count ? + USER_FAN_TABLE : STOCK_FAN_TABLE; + + ret = xe_hwmon_activate_user_fan_table(hwmon, channel, full_speed, source); + if (ret) + xe_warn(hwmon->xe, "failed to set fan %d pwm_enable %ld, ret=%d\n", + channel, val, ret); + } else if (val == XE_FAN_PWM_AUTO_STOCK_TABLE) { + ret = xe_hwmon_fan_set_auto(hwmon, channel); + if (ret) { + xe_warn(hwmon->xe, + "failed to switch fan %d to automatic stock control, ret=%d\n", + channel, ret); + break; + } + xe_dbg(hwmon->xe, + "automatic control enabled for fan %d using stock table\n", + channel); + } else { + xe_dbg(hwmon->xe, "invalid pwm%d_enable value %ld\n", channel + 1, val); + ret = -EINVAL; + } + break; default: ret = -EOPNOTSUPP; break; @@ -2414,6 +2549,7 @@ int xe_hwmon_register(struct xe_device *xe) { struct device *dev = xe->drm.dev; struct xe_hwmon *hwmon; + int fan; int ret; /* hwmon is available only for dGfx */ @@ -2428,6 +2564,10 @@ int xe_hwmon_register(struct xe_device *xe) if (!hwmon) return -ENOMEM; + /* Zero is XE_FAN_PWM_FULL_SPEED; stay unset until the stock table is read. */ + 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); if (ret) return ret; -- 2.34.1