All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Nilawar, Badal" <badal.nilawar@intel.com>
To: "Poosa, Karthik" <karthik.poosa@intel.com>,
	<intel-xe@lists.freedesktop.org>
Cc: <rodrigo.vivi@intel.com>, <anshuman.gupta@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 v6 08/10] drm/xe/hwmon: Refresh fan data after late binding
Date: Wed, 2 Dec 2026 11:54:13 +0530	[thread overview]
Message-ID: <5b1a7587-bfbe-47b0-89f2-12ea37494591@intel.com> (raw)
In-Reply-To: <4c61f46b-ccce-4ec0-b115-0c845c724b88@intel.com>


On 01-12-2026 22:11, Poosa, Karthik wrote:
>
> On 01-12-2026 11:02, Nilawar, Badal wrote:
>>
>> On 01-12-2026 00:20, Karthik Poosa wrote:
>>> Refresh cached stock fan tables and maximum RPM for registered fans 
>>> after
>>> fan-control firmware loads. The stock table can change with the late
>>> bound firmware; keep the previous one if a complete table cannot be
>>> read, and likewise keep the previous maximum RPM if its read fails.
>>> Re-program the user table of fans in manual or full-speed mode.
>>>
>>> Serialize the refresh with hwmon registration and teardown. Flush
>>> late binding work before releasing hwmon state, and protect fanN_max 
>>> reads
>>> against concurrent max_rps updates.
>>>
>>> Signed-off-by: Karthik Poosa <karthik.poosa@intel.com>
>>> ---
>>>
>>> v2:
>>>   - Compare lbfw->id with XE_LB_FW_FAN_CONTROL. (Soham)
>>>   - Use xe already in scope. (Soham)
>>>   - Spell out "late binding" in warnings. (Soham)
>>>   - Start fans enabled after late binding in automatic mode.
>>>
>>> v3:
>>>   - Serialize the refresh with hwmon registration and teardown. Flush
>>>     late binding work before releasing hwmon state, and protect
>>>     fanN_max reads against concurrent max_rps updates.
>>>
>>> v4:
>>>   - Keep the previous stock table if the refresh does not read a
>>>     complete one.
>>>   - Re-program user tables of fans in manual or full-speed mode after
>>>     late binding.
>>>   - Unregister the hwmon device outside registration_lock, so sysfs
>>>     callbacks resuming the device cannot deadlock with late binding 
>>> work.
>>>   - Keep the previous max RPM if the refresh read fails.
>>>
>>> v5:
>>>   - Fix xe_hwmon_fan_late_binding_update() kernel-doc; it does not read
>>>     the number of fans. (sashiko)
>>>   - Drop a v2 note that does not belong to this patch. (sashiko)
>>>   - Use "late binding" consistently and rename
>>>     xe_hwmon_fan_update_post_lb() to 
>>> xe_hwmon_fan_late_binding_update().
>>>     (Soham)
>>>   - Use guards for hwmon_lock. (Soham)
>>>
>>>   drivers/gpu/drm/xe/xe_hwmon.c        | 99 
>>> +++++++++++++++++++++++++---
>>>   drivers/gpu/drm/xe/xe_hwmon.h        |  2 +
>>>   drivers/gpu/drm/xe/xe_late_bind_fw.c |  3 +
>>>   3 files changed, 96 insertions(+), 8 deletions(-)
>>>
>>> diff --git a/drivers/gpu/drm/xe/xe_hwmon.c 
>>> b/drivers/gpu/drm/xe/xe_hwmon.c
>>> index ea342f12a756..4ee51cfc9283 100644
>>> --- a/drivers/gpu/drm/xe/xe_hwmon.c
>>> +++ b/drivers/gpu/drm/xe/xe_hwmon.c
>>> @@ -16,6 +16,7 @@
>>>   #include "regs/xe_pcode_regs.h"
>>>   #include "xe_device.h"
>>>   #include "xe_hwmon.h"
>>> +#include "xe_late_bind_fw.h"
>>>   #include "xe_log.h"
>>>   #include "xe_mmio.h"
>>>   #include "xe_pcode.h"
>>> @@ -257,6 +258,8 @@ struct xe_hwmon {
>>>       struct device *hwmon_dev;
>>>       /** @xe: Xe device */
>>>       struct xe_device *xe;
>>> +    /** @registration_lock: serialize registration with late 
>>> binding updates */
>>> +    struct mutex registration_lock;
>>>       /** @hwmon_lock: lock for rw attributes*/
>>>       struct mutex hwmon_lock;
>>>       /** @scl_shift_power: pkg power unit */
>>> @@ -291,6 +294,13 @@ struct xe_hwmon {
>>>       const struct attribute_group *groups[3];
>>>   };
>>>   +static void xe_hwmon_flush_late_bind(void *arg)
>>> +{
>>> +    struct xe_device *xe = arg;
>>> +
>>> +    xe_late_bind_pm_suspend(&xe->late_bind);
>>> +}
>>> +
>>>   static inline int prepare_power_limit_param2(const struct xe_hwmon 
>>> *hwmon, int channel)
>>>   {
>>>       if (hwmon->read_power_limit_from_pcode[channel]) {
>>> @@ -1735,16 +1745,17 @@ static int 
>>> xe_hwmon_read_fan_control_info(struct xe_hwmon *hwmon)
>>>           struct fan_control_point stock_fcp[MAX_FAN_CONTROL_POINTS];
>>>           struct xe_hwmon_fan_info *fi = &hwmon->fi[fan];
>>>           u32 stock_fcp_count = 0;
>>> +        u32 max_rps = 0;
>>>             if (!IS_FAN_ENABLED(hwmon, fan))
>>>               continue;
>>>             ret = xe_hwmon_pcode_read_fan_control(hwmon, 
>>> FSC_READ_MAX_FAN_RPS, fan,
>>> -                              &fi->max_rps);
>>> +                              &max_rps);
>>>           if (ret) {
>>> -            fi->max_rps = 0;
>>>               xe_warn(hwmon->xe, "failed to read fan %d max RPS, 
>>> ret=%d\n", fan, ret);
>>>           } else {
>>> +            fi->max_rps = max_rps;
>>>               xe_dbg(hwmon->xe, "fan %d max RPS %u\n", fan, 
>>> fi->max_rps);
>>>           }
>>>   @@ -2409,7 +2420,9 @@ xe_hwmon_fan_read(struct xe_hwmon *hwmon, 
>>> u32 attr, int channel, long *val)
>>>       case hwmon_fan_input:
>>>           return xe_hwmon_fan_input_read(hwmon, channel, val);
>>>       case hwmon_fan_max:
>>> -        *val = mul_u32_u32(hwmon->fi[channel].max_rps, 60);
>>> +        scoped_guard(mutex, &hwmon->hwmon_lock) {
>>> +            *val = mul_u32_u32(hwmon->fi[channel].max_rps, 60);
>>> +        }
>>>           return 0;
>>>       default:
>>>           return -EOPNOTSUPP;
>>> @@ -2874,9 +2887,21 @@ int xe_hwmon_register(struct xe_device *xe)
>>>       if (ret)
>>>           return ret;
>>>   +    ret = devm_mutex_init(dev, &hwmon->registration_lock);
>>> +    if (ret)
>>> +        return ret;
>>> +
>>> +    /* Flush late binding work before devm releases the hwmon state 
>>> it may use. */
>>> +    ret = devm_add_action_or_reset(dev, xe_hwmon_flush_late_bind, xe);
>> Why is this needed here? I would prefer hwmon not to manage the 
>> lifetime or synchronization of late-binding work.
>
> This was needed only because hwmon state was devm-managed.
>
> With devm reverse cleanup, the late-bind worker could still use hwmon 
> after that state was released.
>
> Instead of this, we can use drmm-managed state, so it remains valid 
> until final DRM release.
>
>>> +    if (ret)
>>> +        return ret;
>>> +
>>> +    guard(mutex)(&hwmon->registration_lock);
>>> +
>>>       /* There's only one instance of hwmon per device */
>>>       hwmon->xe = xe;
>>> -    xe->hwmon = hwmon;
>>> +    /* Pair with the acquire load in 
>>> xe_hwmon_fan_late_binding_update(). */
>>> +    smp_store_release(&xe->hwmon, hwmon);
>>>         ret = xe_hwmon_get_preregistration_info(hwmon);
>>>       if (ret)
>>> @@ -2903,7 +2928,7 @@ int xe_hwmon_register(struct xe_device *xe)
>>>       return 0;
>>>     err_null_hwmon:
>>> -    xe->hwmon = NULL;
>>> +    WRITE_ONCE(xe->hwmon, NULL);
>>>       return ret;
>>>   }
>>>   @@ -2916,11 +2941,25 @@ int xe_hwmon_register(struct xe_device *xe)
>>>    */
>>>   void xe_hwmon_unregister(struct xe_device *xe)
>>>   {
>>> -    if (!xe->hwmon)
>>> +    struct xe_hwmon *hwmon;
>>> +
>>> +    /* Stop updates before unregistering hwmon or unplugging the 
>>> device. */
>>> +    xe_late_bind_pm_suspend(&xe->late_bind);
>>> +
>>> +    hwmon = READ_ONCE(xe->hwmon);
>>> +    if (!hwmon)
>>>           return;
>>>   -    hwmon_device_unregister(xe->hwmon->hwmon_dev);
>>> -    xe->hwmon = NULL;
>>> +    mutex_lock(&hwmon->registration_lock);
>>> +    if (READ_ONCE(xe->hwmon) != hwmon) {
>>> +        mutex_unlock(&hwmon->registration_lock);
>>> +        return;
>>> +    }
>>> +    WRITE_ONCE(xe->hwmon, NULL);
>>> +    mutex_unlock(&hwmon->registration_lock);
>>> +
>>> +    /* Sysfs callbacks may resume and wait on late binding work 
>>> that takes registration_lock. */
>>> +    hwmon_device_unregister(hwmon->hwmon_dev);
>>>   }
>>>     /**
>>> @@ -3021,4 +3060,48 @@ void xe_hwmon_resume(struct xe_device *xe, 
>>> bool runtime)
>>>       mutex_unlock(&hwmon->hwmon_lock);
>>>   }
>>>   +/**
>>> + * xe_hwmon_fan_late_binding_update - Update fan info after late 
>>> binding
>>> + * @xe: xe device instance
>>> + *
>>> + * Re-read the maximum fan speed and stock fan tables after late 
>>> binding, and
>>> + * re-program the user table of fans in manual or full-speed mode.
>>> + */
>>> +void xe_hwmon_fan_late_binding_update(struct xe_device *xe)
>>> +{
>>> +    /* Pair with the release store in xe_hwmon_register(). */
>>> +    struct xe_hwmon *hwmon = smp_load_acquire(&xe->hwmon);
>>> +    int fan;
>>> +
>>> +    if (!hwmon || !xe->info.has_fan_control)
>>> +        return;
>>> +
>>> +    guard(mutex)(&hwmon->registration_lock);
>>> +    if (READ_ONCE(xe->hwmon) != hwmon)
>>> +        return;
>>> +
>>> +    guard(mutex)(&hwmon->hwmon_lock);
>>> +
>>> +    if (xe_hwmon_read_fan_control_info(hwmon))
>>> +        xe_warn(hwmon->xe, "failed to read stock fan tables after 
>>> late binding\n");
>>> +
>>> +    for (fan = 0; fan < FAN_MAX; fan++) {
>>> +        struct xe_hwmon_fan_info *fi = &hwmon->fi[fan];
>>> +        int ret;
>>> +
>>> +        if (!IS_FAN_ENABLED(hwmon, fan) ||
>>> +            (fi->pwm_enable_mode != XE_FAN_PWM_MANUAL_USER_TABLE &&
>>> +             fi->pwm_enable_mode != XE_FAN_PWM_FULL_SPEED))
>>> +            continue;
>>> +
>>> +        ret = xe_hwmon_activate_user_fan_table(hwmon, fan,
>>> +                               fi->pwm_enable_mode == 
>>> XE_FAN_PWM_FULL_SPEED,
>>> +                               USER_FAN_TABLE);
>>> +        if (ret)
>>> +            xe_warn(hwmon->xe,
>>> +                "failed to restore fan %d user table after late 
>>> binding, ret=%d\n",
>>> +                fan, ret);
>>> +    }
>>> +}
>>> +
>>>   MODULE_IMPORT_NS("INTEL_PMT_TELEMETRY");
>>> diff --git a/drivers/gpu/drm/xe/xe_hwmon.h 
>>> b/drivers/gpu/drm/xe/xe_hwmon.h
>>> index 50874b6b6527..ceb3cbe93a5d 100644
>>> --- a/drivers/gpu/drm/xe/xe_hwmon.h
>>> +++ b/drivers/gpu/drm/xe/xe_hwmon.h
>>> @@ -15,11 +15,13 @@ int xe_hwmon_register(struct xe_device *xe);
>>>   void xe_hwmon_unregister(struct xe_device *xe);
>>>   void xe_hwmon_suspend(struct xe_device *xe, bool runtime);
>>>   void xe_hwmon_resume(struct xe_device *xe, bool runtime);
>>> +void xe_hwmon_fan_late_binding_update(struct xe_device *xe);
>>>   #else
>>>   static inline int xe_hwmon_register(struct xe_device *xe) { return 
>>> 0; };
>>>   static inline void xe_hwmon_unregister(struct xe_device *xe) { }
>>>   static inline void xe_hwmon_suspend(struct xe_device *xe, bool 
>>> runtime) {}
>>>   static inline void xe_hwmon_resume(struct xe_device *xe, bool 
>>> runtime) {}
>>> +static inline void xe_hwmon_fan_late_binding_update(struct 
>>> xe_device *xe) {}
>>>   #endif
>>>     #endif /* _XE_HWMON_H_ */
>>> diff --git a/drivers/gpu/drm/xe/xe_late_bind_fw.c 
>>> b/drivers/gpu/drm/xe/xe_late_bind_fw.c
>>> index ad39383a7e41..b76c18f91849 100644
>>> --- a/drivers/gpu/drm/xe/xe_late_bind_fw.c
>>> +++ b/drivers/gpu/drm/xe/xe_late_bind_fw.c
>>> @@ -14,6 +14,7 @@
>>>     #include "xe_configfs.h"
>>>   #include "xe_device.h"
>>> +#include "xe_hwmon.h"
>>>   #include "xe_late_bind_fw.h"
>>>   #include "xe_pcode.h"
>>>   #include "xe_pcode_api.h"
>>> @@ -298,6 +299,8 @@ static void xe_late_bind_work(struct work_struct 
>>> *work)
>>>       if (!ret) {
>>>           drm_dbg(&xe->drm, "Load %s firmware successful\n",
>>>               fw_id_to_name[lbfw->id]);
>>> +        if (lbfw->id == XE_LB_FW_FAN_CONTROL)
>>> +            xe_hwmon_fan_late_binding_update(xe);
>>
>> Instead of directly calling hwmon here, how about hwmon sync (in 
>> another worker) with LB and then update the table.
>>
>> Thanks,
>> Badal
> I don't think another worker is needed here, any issues with this 
> implementation.

I would prefer to keep this worker limited to late binding. Since it 
handles different firmware types, including OCode, the consumer should 
synchronize with LB completion and handle its own post-LB update.

For the fan late-binding status, lb_fan_control_version_show() can be 
leveraged.

Flow can be.

Check FAN control LB capability
         |
         +-- FAN LB already complete
         |       |
         |       +-- Refresh fan data
         |
         +-- FAN LB not complete
                 |
                 +-- Trigger LB worker
                 |
                 +-- Poll FAN LB status
                 |

                 +-- Refresh fan data once complete

Thanks,
Badal

>>
>>>           goto out;
>>>       }

  reply	other threads:[~2026-12-02  6:24 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 18:50 [PATCH v6 00/10] drm/xe/hwmon: Add fan control support Karthik Poosa
2026-11-30 18:50 ` [PATCH v6 01/10] drm/xe/hwmon: Initialize fan-control backend and table cache Karthik Poosa
2026-11-30 19:04   ` sashiko-bot
2026-12-01  5:10     ` Poosa, Karthik
2026-12-01  8:09   ` Purkait, Soham
2026-11-30 18:50 ` [PATCH v6 02/10] drm/xe/hwmon: Expose fanN_max Karthik Poosa
2026-12-01  8:10   ` Purkait, Soham
2026-11-30 18:50 ` [PATCH v6 03/10] drm/xe/pcode: Add ordered write batch helper Karthik Poosa
2026-11-30 20:59   ` Rodrigo Vivi
2026-11-30 18:50 ` [PATCH v6 04/10] drm/xe/hwmon: Expose pwm[1-3] Karthik Poosa
2026-12-01 13:04   ` Purkait, Soham
2026-11-30 18:50 ` [PATCH v6 05/10] drm/xe/hwmon: Expose pwm[1-3]_enable Karthik Poosa
2026-12-01 13:38   ` Purkait, Soham
2026-11-30 18:50 ` [PATCH v6 06/10] drm/xe/hwmon: Enable fan curve control support Karthik Poosa
2026-11-30 21:00   ` Rodrigo Vivi
2026-12-01 12:06     ` Purkait, Soham
2026-11-30 18:50 ` [PATCH v6 07/10] drm/xe/hwmon: Restore fan user tables after resume Karthik Poosa
2026-11-30 21:03   ` Rodrigo Vivi
2026-12-01  4:55   ` Nilawar, Badal
2026-12-01  5:13     ` Poosa, Karthik
2026-11-30 18:50 ` [PATCH v6 08/10] drm/xe/hwmon: Refresh fan data after late binding Karthik Poosa
2026-12-01  5:32   ` Nilawar, Badal
2026-12-01 16:41     ` Poosa, Karthik
2026-12-02  6:24       ` Nilawar, Badal [this message]
2026-11-30 18:50 ` [PATCH v6 09/10] drm/xe: Expose tjmax_fan_control_enable device sysfs Karthik Poosa
2026-12-01 16:14   ` Purkait, Soham
2026-12-01 17:31     ` Poosa, Karthik
2026-11-30 18:50 ` [PATCH v6 10/10] drm/xe/hwmon: Add kernel-doc for fan control Karthik Poosa
2026-11-30 21:04   ` Rodrigo Vivi
2026-12-01  8:13   ` Purkait, Soham
2026-11-30 20:52 ` ✓ CI.KUnit: success for drm/xe/hwmon: Add fan control support (rev3) Patchwork
2026-11-30 21:32 ` ✓ Xe.CI.BAT: " Patchwork
2026-12-01  9:17 ` ✗ Xe.CI.FULL: failure " 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=5b1a7587-bfbe-47b0-89f2-12ea37494591@intel.com \
    --to=badal.nilawar@intel.com \
    --cc=anshuman.gupta@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 \
    --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 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.