All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Purkait, Soham" <soham.purkait@intel.com>
To: Karthik Poosa <karthik.poosa@intel.com>,
	<intel-xe@lists.freedesktop.org>
Cc: <rodrigo.vivi@intel.com>, <anshuman.gupta@intel.com>,
	<badal.nilawar@intel.com>, <raag.jadav@intel.com>,
	<riana.tauro@intel.com>, <sk.anirban@intel.com>,
	<mallesh.koujalagi@intel.com>,
	<ravi.kishore.koppuravuri@intel.com>
Subject: Re: [PATCH v4 01/10] drm/xe/hwmon: Initialize fan-control backend and table cache
Date: Sat, 28 Nov 2026 03:01:50 +0530	[thread overview]
Message-ID: <5bb1590d-441d-4a58-95c2-4498134e66e7@intel.com> (raw)
In-Reply-To: <20261124054811.798763-2-karthik.poosa@intel.com>

Hi Karthik,

On 24-11-2026 11:18, Karthik Poosa wrote:
> Initialize Xe hwmon fan-control support by detecting enabled fans,
> reading stock fan control points and min PWM.
>
> FSC_READ_NUM_FANS returns a bitmask of enabled fans, so use it as a mask
> when exposing fanN_input.
>
> Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
> ---
>
> v2:
>   - Avoid user table initialization during probe. (Badal)
>   - Move unused code to appropriate patches.
>   - Use xe helpers for dmesg logs.
>
> v3:
>   - Rebase.
>   - Refine a few debug log messages and comments.
>   - Update xe_hwmon_read_fan_control_info() to return on any stock table
>     read failures.
>   - Avoid returning when num_fans is 0 in
>     xe_hwmon_get_preregistration_info(), ensuring thermal mailbox
>     initialization is not skipped.
>   - Remove XE_PCODE_FAN_CONTROL_TIMEOUT_MS which is unnecessary as default
>     timeout itself is now 10ms.
>   - Use xe_pcode_read() instead of xe_pcode_read_timeout().
>   - Rename fan_control_point_count to point_count in struct fan_table.
>   - Resolve kernel-doc warnings.
>   - Add valid check for stock table fan point count.
>   - Use the fan-enable bitmap reported by FSC_READ_NUM_FANS when enumerating
>     fans. This avoids assuming contiguous fan indices and allows masks with
>     gaps to be represented correctly in the hwmon interface.
>
> v4:
>   - Clamp unsupported fan masks and oversized stock tables instead of
>     failing initialization. (Soham)
>   - On stock table read failure, mark that fan's table empty and continue
>     with the remaining fans; fan_input stays visible. (Soham)
>   - Clear fan enable mask and min PWM on pcode read failure. (Soham)
>   - Fix FCP_INDEX() type safety and clean up macro usage. (Soham)
>   - Use xe_hwmon_pcode_read_fan_control() for fan mailbox reads. (Soham)
>   - Fix kernel-doc for fan_table_type and nested fan_table members.
>   - Skip min PWM read for fans without a stock table.
>   - Make xe_hwmon_get_fan_enable_mask() return void.
>
>   drivers/gpu/drm/xe/xe_hwmon.c     | 177 +++++++++++++++++++++++++++---
>   drivers/gpu/drm/xe/xe_pcode_api.h |   5 +
>   2 files changed, 166 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c b/drivers/gpu/drm/xe/xe_hwmon.c
> index 42c2f9129da5..2ee4f89e7bf7 100644
> --- a/drivers/gpu/drm/xe/xe_hwmon.c
> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
> @@ -22,6 +22,7 @@
>   #include "xe_pcode_api.h"
>   #include "xe_sriov.h"
>   #include "xe_pm.h"
> +#include "xe_printk.h"
>   #include "xe_vsec.h"
>   #include "regs/xe_pmt.h"
>   
> @@ -139,13 +140,53 @@ struct xe_hwmon_energy_info {
>   };
>   
>   /**
> - * struct xe_hwmon_fan_info - to cache previous fan reading
> + * enum fan_table_type - fan table types tracked per fan
> + */
> +enum fan_table_type {
> +	/** @STOCK_FAN_TABLE: firmware-provided fan table */
> +	STOCK_FAN_TABLE,
> +	/** @USER_FAN_TABLE: user fan table written through sysfs */
> +	USER_FAN_TABLE,
> +	/** @FAN_TABLE_MAX: number of fan tables tracked per fan */
> +	FAN_TABLE_MAX,
> +};
> +
> +/* Check if a fan is enabled based on the fan_enable_mask got from FSC_READ_NUM_FANS. */
> +#define IS_FAN_ENABLED(hwmon, fan) ((hwmon)->fan_enable_mask & BIT(fan))
> +
> +/* Maximum number of fan control points supported by each fan. */
> +#define MAX_FAN_CONTROL_POINTS	10
> +
> +/* 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)))
> +
> +/**
> + * struct xe_hwmon_fan_info - cached fan telemetry and control state
> + *
> + * Each fan keeps the latest tachometer sampling state along with two fan
> + * tables: the stock table discovered from firmware and the user table managed
> + * by hwmon sysfs writes.
>    */
>   struct xe_hwmon_fan_info {
>   	/** @reg_val_prev: previous fan reg val */
>   	u32 reg_val_prev;
>   	/** @time_prev: previous timestamp */
>   	u64 time_prev;
> +	/** @fan_table: fan control tables */
> +	struct fan_table {
> +		/** @fan_table.point_count: number of fan control points */
> +		u8 point_count;
> +		/** @fan_table.fcp: array of fan control points */
> +		struct fan_control_point {
> +			/** @fan_table.fcp.temp: temperature in degree celsius */
> +			u8 temp;
> +			/** @fan_table.fcp.speed: fan speed in percentage */
> +			u8 speed;
> +		} fcp[MAX_FAN_CONTROL_POINTS];
> +	} fan_table[FAN_TABLE_MAX];
> +	/** @min_pwm: minimum fan PWM */
> +	u32 min_pwm;
>   };
>   
>   /**
> @@ -194,6 +235,8 @@ struct xe_hwmon {
>   	int scl_shift_time;
>   	/** @ei: Energy info for energyN_input */
>   	struct xe_hwmon_energy_info ei[CHANNEL_MAX];
> +	/** @fan_enable_mask: bitmask of available fans */
> +	u32 fan_enable_mask;
>   	/** @fi: Fan info for fanN_input */
>   	struct xe_hwmon_fan_info fi[FAN_MAX];
>   	/** @read_power_limit_from_pcode: pcode accepted power limits write for the channel */
> @@ -1076,17 +1119,117 @@ static int xe_hwmon_pcode_write_i1(const struct xe_hwmon *hwmon, u32 uval)
>   			      (uval & POWER_SETUP_I1_DATA_MASK));
>   }
>   
> -static int xe_hwmon_pcode_read_fan_control(const struct xe_hwmon *hwmon, u32 subcmd, u32 *uval)
> +static int xe_hwmon_pcode_read_fan_control(const struct xe_hwmon *hwmon, u32 subcmd, u8 fan_num,
> +					   u32 *uval)
>   {
>   	struct xe_tile *root_tile = xe_device_get_root_tile(hwmon->xe);
>   
> +	return xe_pcode_read(root_tile, PCODE_MBOX(FAN_SPEED_CONTROL, subcmd, fan_num),
> +				     uval, NULL);
> +}
> +
> +static void xe_hwmon_get_fan_enable_mask(struct xe_hwmon *hwmon)
> +{
> +	int ret;
> +
>   	/* Platforms that don't return correct value */
> -	if (hwmon->xe->info.platform == XE_DG2 && subcmd == FSC_READ_NUM_FANS) {
> -		*uval = 2;
> -		return 0;
> +	if (hwmon->xe->info.platform == XE_DG2) {
> +		hwmon->fan_enable_mask = GENMASK(1, 0);
> +		return;
> +	}
> +
> +	ret = xe_hwmon_pcode_read_fan_control(hwmon, FSC_READ_NUM_FANS, 0,
> +					      &hwmon->fan_enable_mask);
> +	if (ret) {
> +		hwmon->fan_enable_mask = 0;
> +		xe_warn(hwmon->xe, "failed to read number of fans, ret=%d\n", ret);
> +		return;
>   	}
>   
> -	return xe_pcode_read(root_tile, PCODE_MBOX(FAN_SPEED_CONTROL, subcmd, 0), uval, NULL);
> +	/* Check if fan mask exceeds FAN_MAX and log a warning if it does */
> +	if (hwmon->fan_enable_mask & ~GENMASK(FAN_MAX - 1, 0)) {
> +		xe_warn(hwmon->xe, "Fan enable mask exceeds %d supported fans, clamping\n",
> +			FAN_MAX);
> +		hwmon->fan_enable_mask &= GENMASK(FAN_MAX - 1, 0);
> +	}
> +
> +	xe_info(hwmon->xe, "Number of fans detected: %u\n", hweight32(hwmon->fan_enable_mask));
Other messages in this patch start with a lowercase letter. Could these 
two match that style throughout the series ?
> +}
> +
> +static int xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon)
> +{
> +	int point;
> +	int fan;
> +	int ret;
> +	int err = 0;
> +
> +	/* Stock table failures leave fan_input visible; tach readout doesn't need it. */
> +	for (fan = 0; fan < FAN_MAX; fan++) {
> +		struct xe_hwmon_fan_info *fi = &hwmon->fi[fan];
> +		u32 stock_fcp_count = 0;
> +
> +		if (!IS_FAN_ENABLED(hwmon, fan))
> +			continue;
> +
> +		ret = xe_hwmon_pcode_read_fan_control(hwmon,
> +						      FSC_READ_STOCK_FAN_CONTROL_POINTS,
> +						      fan, &stock_fcp_count);
> +		if (ret || !stock_fcp_count) {
> +			xe_warn(hwmon->xe,
> +				"fan %d stock table unavailable, ret=%d, point count=%u\n",
> +				fan, ret, ret ? 0 : stock_fcp_count);
> +			err = ret ?: -ENODATA;
> Only the last error is kept when more than one fan fails. Is that intended?
> +			continue;
> +		}
> +
> +		if (stock_fcp_count > MAX_FAN_CONTROL_POINTS) {
> +			xe_warn(hwmon->xe,
> +				"fan %d stock table point count %u exceeds maximum %u, clamping\n",
> +				fan, stock_fcp_count, MAX_FAN_CONTROL_POINTS);
> +			stock_fcp_count = MAX_FAN_CONTROL_POINTS;
> +		}
> +
> +		fi->fan_table[STOCK_FAN_TABLE].point_count = stock_fcp_count;
> +		xe_dbg(hwmon->xe, "fan %d stock table point count is %u\n", fan,
> +		       fi->fan_table[STOCK_FAN_TABLE].point_count);
> +
> +		/* Cache the stock fan table for later use. */
> +		for (point = 0; point < fi->fan_table[STOCK_FAN_TABLE].point_count;
> +		     point++) {
> +			u32 fcp = FCP_INDEX(STOCK_FAN_TABLE, point);
> +
> +			ret = xe_hwmon_pcode_read_fan_control(hwmon, FSC_READ_FAN_TABLE, fan, &fcp);
> +			if (ret) {
> +				xe_warn(hwmon->xe, "failed to read fan %d stock point %d, ret=%d\n",
> +					fan, point, ret);
> +				fi->fan_table[STOCK_FAN_TABLE].point_count = 0;
> +				err = ret;
> +				break;
> +			}
> +
> +			fi->fan_table[STOCK_FAN_TABLE].fcp[point].temp =
> +						REG_FIELD_GET(FAN_CONTROL_POINT_TEMP_MASK, fcp);
> +			fi->fan_table[STOCK_FAN_TABLE].fcp[point].speed =
> +						REG_FIELD_GET(FAN_CONTROL_POINT_SPEED_MASK, fcp);
> +			xe_dbg(hwmon->xe, "fan %d stock point %d: temp %u C, speed %u %%\n",
> +			       fan, point, fi->fan_table[STOCK_FAN_TABLE].fcp[point].temp,
> +			       fi->fan_table[STOCK_FAN_TABLE].fcp[point].speed);
> +		}
> +
> +		if (!fi->fan_table[STOCK_FAN_TABLE].point_count)
> +			continue;
> +
> +		/* Read minimum fan PWM */
> +		ret = xe_hwmon_pcode_read_fan_control(hwmon, FSC_READ_FAN_MIN_PWM, fan,
> +						      &fi->min_pwm);
Why does reading min_pwm depend on the stock table?
> +		if (ret) {
> +			fi->min_pwm = 0;
> +			xe_warn(hwmon->xe, "fan %d min pwm unavailable, ret=%d\n", fan, ret);
> +		} else {
> +			xe_dbg(hwmon->xe, "fan %d min PWM %u\n", fan, fi->min_pwm);
> +		}
> +	}
> +	return err;
>   }
>   
>   static int xe_hwmon_power_curr_crit_read(struct xe_hwmon *hwmon, int channel,
> @@ -1616,17 +1759,12 @@ xe_hwmon_energy_read(struct xe_hwmon *hwmon, u32 attr, int channel, long *val)
>   static umode_t
>   xe_hwmon_fan_is_visible(struct xe_hwmon *hwmon, u32 attr, int channel)
>   {
> -	u32 uval = 0;
> -
>   	if (!hwmon->xe->info.has_fan_control)
>   		return 0;
>   
>   	switch (attr) {
>   	case hwmon_fan_input:
> -		if (xe_hwmon_pcode_read_fan_control(hwmon, FSC_READ_NUM_FANS, &uval))
> -			return 0;
> -
> -		return channel < uval ? 0444 : 0;
> +		return IS_FAN_ENABLED(hwmon, channel) ? 0444 : 0;
>   	default:
>   		return 0;
>   	}
> @@ -1859,11 +1997,18 @@ xe_hwmon_get_preregistration_info(struct xe_hwmon *hwmon)
>   		if (xe_hwmon_is_visible(hwmon, hwmon_energy, hwmon_energy_input, channel))
>   			xe_hwmon_energy_get(hwmon, channel, &energy);
>   
> -	/* Initialize 'struct xe_hwmon_fan_info' with initial fan register reading. */
> -	for (channel = 0; channel < FAN_MAX; channel++)
> -		if (xe_hwmon_is_visible(hwmon, hwmon_fan, hwmon_fan_input, channel))
> -			xe_hwmon_fan_input_read(hwmon, channel, &fan_speed);
> +	if (hwmon->xe->info.has_fan_control) {
> +		xe_hwmon_get_fan_enable_mask(hwmon);
> +
> +		/* Initialize 'struct xe_hwmon_fan_info' with initial fan register reading. */
> +		for (channel = 0; channel < FAN_MAX; channel++)
> +			if (IS_FAN_ENABLED(hwmon, channel))
> +				xe_hwmon_fan_input_read(hwmon, channel, &fan_speed);
>   
> +		/* Fan control tables initialization */
> +		if (xe_hwmon_read_fan_control_info(hwmon))
> +			xe_warn(hwmon->xe, "Fan control tables are not available\n");
A warning is already printed for each fan, so this one repeats it. Would 
xe_dbg() be enough here?

Regards,
Soham
> +	}
>   	return xe_hwmon_init_temp_info(hwmon);
>   }
>   
> diff --git a/drivers/gpu/drm/xe/xe_pcode_api.h b/drivers/gpu/drm/xe/xe_pcode_api.h
> index 00c4fc7d0124..0349b24a8259 100644
> --- a/drivers/gpu/drm/xe/xe_pcode_api.h
> +++ b/drivers/gpu/drm/xe/xe_pcode_api.h
> @@ -83,6 +83,11 @@
>   
>   #define   FAN_SPEED_CONTROL			0x7D
>   #define     FSC_READ_NUM_FANS			0x4
> +#define     FSC_READ_STOCK_FAN_CONTROL_POINTS	0x5
> +#define     FSC_READ_FAN_TABLE			0x7
> +#define     FAN_CONTROL_POINT_TEMP_MASK		REG_GENMASK(7, 0)
> +#define     FAN_CONTROL_POINT_SPEED_MASK	REG_GENMASK(15, 8)
> +#define     FSC_READ_FAN_MIN_PWM		0x8
>   
>   #define PCODE_SCRATCH(x)		XE_REG(0x138320 + ((x) * 4))
>   /* PCODE_SCRATCH0 */

  reply	other threads:[~2026-11-27 21:32 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24  5:48 [PATCH v4 00/10] drm/xe/hwmon: Add fan control support Karthik Poosa
2026-11-24  5:48 ` [PATCH v4 01/10] drm/xe/hwmon: Initialize fan-control backend and table cache Karthik Poosa
2026-11-27 21:31   ` Purkait, Soham [this message]
2026-11-24  5:48 ` [PATCH v4 02/10] drm/xe/hwmon: Expose fanN_max Karthik Poosa
2026-11-25 18:26   ` Rodrigo Vivi
2026-11-24  5:48 ` [PATCH v4 03/10] drm/xe/pcode: Add ordered write batch helper Karthik Poosa
2026-11-25 18:29   ` Rodrigo Vivi
2026-11-26 13:48     ` Poosa, Karthik
2026-11-24  5:48 ` [PATCH v4 04/10] drm/xe/hwmon: Expose pwm[1-3] Karthik Poosa
2026-11-24  5:48 ` [PATCH v4 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable Karthik Poosa
2026-11-24  6:01   ` sashiko-bot
2026-11-25 13:26     ` Poosa, Karthik
2026-11-24  5:48 ` [PATCH v4 06/10] drm/xe/hwmon: Enable fan curve control support Karthik Poosa
2026-11-24  6:02   ` sashiko-bot
2026-11-26 17:05     ` Poosa, Karthik
2026-11-24  5:48 ` [PATCH v4 07/10] drm/xe/hwmon: Add kernel-doc for fan control Karthik Poosa
2026-11-24  5:53   ` sashiko-bot
2026-11-26 12:33     ` Poosa, Karthik
2026-11-24  5:48 ` [PATCH v4 08/10] drm/xe/hwmon: Preserve fan user table across suspend resume Karthik Poosa
2026-11-24  6:07   ` sashiko-bot
2026-11-26 13:35     ` Poosa, Karthik
2026-11-24  5:48 ` [PATCH v4 09/10] drm/xe/hwmon: Update fan info after late binding Karthik Poosa
2026-11-24  6:11   ` sashiko-bot
2026-11-24  5:48 ` [PATCH v4 10/10] drm/xe/hwmon: Enable fan support for CRI Karthik Poosa
2026-11-25 18:30   ` Rodrigo Vivi
2026-11-24  5:56 ` ✗ CI.KUnit: failure for drm/xe/hwmon: Add fan control support Patchwork

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=5bb1590d-441d-4a58-95c2-4498134e66e7@intel.com \
    --to=soham.purkait@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=rodrigo.vivi@intel.com \
    --cc=sk.anirban@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.