From: Rodrigo Vivi <rodrigo.vivi@intel.com>
To: Karthik Poosa <karthik.poosa@intel.com>
Cc: <intel-xe@lists.freedesktop.org>, <anshuman.gupta@intel.com>,
<badal.nilawar@intel.com>, <raag.jadav@intel.com>,
<riana.tauro@intel.com>, <sk.anirban@intel.com>,
<mallesh.koujalagi@intel.com>, <soham.purkait@intel.com>,
<ravi.kishore.koppuravuri@intel.com>
Subject: Re: [PATCH v7 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable
Date: Wed, 2 Dec 2026 09:22:47 -0500 [thread overview]
Message-ID: <axApt1r9_SfX35F7@intel.com> (raw)
In-Reply-To: <20261202125637.1581881-6-karthik.poosa@intel.com>
On Wed, Dec 02, 2026 at 06:26:32PM +0530, Karthik Poosa wrote:
> 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.
>
> Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
Reviewed-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
> ---
>
> 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<i>/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 dd6f1f97fbf7..4eca1aa43564 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
> @@ -139,6 +139,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
> */
> @@ -190,6 +204,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;
> };
>
> /**
> @@ -926,7 +942,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
> };
>
> @@ -1211,11 +1229,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,
> @@ -1291,6 +1312,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
>
> @@ -1302,6 +1373,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);
>
> @@ -1401,6 +1477,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. */
> @@ -1965,6 +2043,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;
> @@ -2024,25 +2103,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;
>
> @@ -2070,7 +2167,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;
> }
>
> @@ -2139,25 +2236,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);
> @@ -2168,6 +2265,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;
> @@ -2181,8 +2286,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) {
> @@ -2194,6 +2302,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;
> @@ -2407,6 +2542,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 */
> @@ -2421,6 +2557,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
>
next prev parent reply other threads:[~2026-12-02 14:23 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 12:56 [PATCH v7 00/10] drm/xe/hwmon: Add fan control support Karthik Poosa
2026-12-02 12:56 ` [PATCH v7 01/10] drm/xe/hwmon: Initialize fan-control backend and table cache Karthik Poosa
2026-12-02 13:05 ` sashiko-bot
2026-12-02 12:56 ` [PATCH v7 02/10] drm/xe/hwmon: Expose fanN_max Karthik Poosa
2026-12-02 12:56 ` [PATCH v7 03/10] drm/xe/pcode: Add ordered write batch helper Karthik Poosa
2026-12-02 12:56 ` [PATCH v7 04/10] drm/xe/hwmon: Expose pwm[1-3] Karthik Poosa
2026-12-02 14:22 ` Rodrigo Vivi
2026-12-02 12:56 ` [PATCH v7 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable Karthik Poosa
2026-12-02 14:22 ` Rodrigo Vivi [this message]
2026-12-02 12:56 ` [PATCH v7 06/10] drm/xe/hwmon: Enable fan curve control support Karthik Poosa
2026-12-02 12:56 ` [PATCH v7 07/10] drm/xe: Expose tjmax_fan_control_enable device sysfs Karthik Poosa
2026-12-02 14:23 ` Rodrigo Vivi
2026-12-02 12:56 ` [PATCH v7 08/10] drm/xe/hwmon: Restore fan user tables after resume Karthik Poosa
2026-12-02 13:19 ` sashiko-bot
2026-12-02 14:33 ` Poosa, Karthik
2026-12-02 12:56 ` [PATCH v7 09/10] drm/xe/hwmon: Refresh fan data after late binding Karthik Poosa
2026-12-02 13:19 ` sashiko-bot
2026-12-02 12:56 ` [PATCH v7 10/10] drm/xe/hwmon: Add kernel-doc for fan control Karthik Poosa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=axApt1r9_SfX35F7@intel.com \
--to=rodrigo.vivi@intel.com \
--cc=anshuman.gupta@intel.com \
--cc=badal.nilawar@intel.com \
--cc=intel-xe@lists.freedesktop.org \
--cc=karthik.poosa@intel.com \
--cc=mallesh.koujalagi@intel.com \
--cc=raag.jadav@intel.com \
--cc=ravi.kishore.koppuravuri@intel.com \
--cc=riana.tauro@intel.com \
--cc=sk.anirban@intel.com \
--cc=soham.purkait@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox