All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] hwmon: (pmbus) Fall back to CLEAR_FAULTS when STATUS_CML is read-only
@ 2026-11-25  5:37 Arthur Korn
  2026-11-25  5:49 ` sashiko-bot
  0 siblings, 1 reply; 6+ messages in thread
From: Arthur Korn @ 2026-11-25  5:37 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: linux-hwmon, linux-kernel, Arthur Korn

Some PMBus 1.2 devices (such as ADI ADM1273 and ADM1281) report
PMBUS_REVISION = 0x22 and implement STATUS_CML (0x7e) as read-only:
they ACK SMBus byte writes to PMBUS_STATUS_CML without clearing latched
fault bits, and only clear STATUS_CML via CLEAR_FAULTS (0x03).

During pmbus_init_common(), probing an unsupported register such as
PMBUS_WRITE_PROTECT (0x10) latches PB_CML_FAULT_INVALID_COMMAND in
STATUS_CML. When pmbus_clear_cml_fault() writes to PMBUS_STATUS_CML and
sees ret == 0, PB_CML_FAULT_INVALID_COMMAND remains latched, causing
subsequent pmbus_check_status_cml() calls during attribute discovery to
fail with -EIO.

Verify on non-write-protected devices that PB_CML_FAULT_INVALID_COMMAND
and PB_CML_FAULT_INVALID_DATA actually cleared when a CML fault is
expected or cleared unconditionally. If either bit remains set after the
write, disable STATUS_CML write-1-to-clear for the device and fall back
to pmbus_clear_fault_page(). Skipping the readback on supported register
probes (rv >= 0) avoids extra SMBus traffic in the common path.

Tested on BMC hardware across 130 hwmon devices including 4x ADI
ADM1273-1A (adm1275), Renesas RAA228234 (isl68137), Infineon XDPE1A2G5B
(tda38740), ADI ADM1266, and factory write-protected converters,
verifying clean ADM1273-1A probe/re-bind fallback to CLEAR_FAULTS and
preservation of companion STATUS_CML fault bits on W1C-capable VRs.

Fixes: d9d30e1cb9ca ("hwmon: (pmbus) Clear only CML command and data faults during probe")
Signed-off-by: Arthur Korn <akorn@google.com>
---
 drivers/hwmon/pmbus/pmbus_core.c | 40 ++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 12 deletions(-)

diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
index 2772860..82dfa82 100644
--- a/drivers/hwmon/pmbus/pmbus_core.c
+++ b/drivers/hwmon/pmbus/pmbus_core.c
@@ -727,15 +727,31 @@ void pmbus_clear_faults(struct i2c_client *client)
 }
 EXPORT_SYMBOL_NS_GPL(pmbus_clear_faults, "PMBUS");
 
-static void pmbus_clear_cml_fault(struct i2c_client *client, int page)
+#define PB_CML_FAULT_CLEAR_MASK	(PB_CML_FAULT_INVALID_COMMAND | \
+				 PB_CML_FAULT_INVALID_DATA)
+
+static void pmbus_clear_cml_fault(struct i2c_client *client, int page,
+				  bool verify)
 {
 	struct pmbus_data *data = i2c_get_clientdata(client);
+	int ret;
+
+	if (data->has_status_cml) {
+		ret = _pmbus_write_byte_data(client, page, PMBUS_STATUS_CML,
+					     PB_CML_FAULT_CLEAR_MASK);
+		if (ret >= 0 && verify &&
+		    !(data->flags & PMBUS_WRITE_PROTECTED)) {
+			ret = _pmbus_read_byte_data(client, page,
+						    PMBUS_STATUS_CML);
+			if (ret >= 0 && (ret & PB_CML_FAULT_CLEAR_MASK))
+				ret = -EIO;
+		}
+		if (ret >= 0)
+			return;
+		data->has_status_cml = false;
+	}
 
-	if (!data->has_status_cml ||
-	    _pmbus_write_byte_data(client, page, PMBUS_STATUS_CML,
-				   PB_CML_FAULT_INVALID_COMMAND |
-				   PB_CML_FAULT_INVALID_DATA) < 0)
-		pmbus_clear_fault_page(client, page);
+	pmbus_clear_fault_page(client, page);
 }
 
 void pmbus_clear_cml_faults(struct i2c_client *client)
@@ -744,7 +760,7 @@ void pmbus_clear_cml_faults(struct i2c_client *client)
 	int i;
 
 	for (i = 0; i < data->info->pages; i++)
-		pmbus_clear_cml_fault(client, i);
+		pmbus_clear_cml_fault(client, i, true);
 }
 EXPORT_SYMBOL_NS_GPL(pmbus_clear_cml_faults, "PMBUS");
 
@@ -776,7 +792,7 @@ static bool pmbus_check_register(struct i2c_client *client,
 	if (rv < 0 && (data->flags & PMBUS_READ_STATUS_AFTER_FAILED_CHECK))
 		data->read_status(client, -1);
 	if (reg < PMBUS_VIRT_BASE)
-		pmbus_clear_cml_fault(client, -1);
+		pmbus_clear_cml_fault(client, -1, rv < 0);
 	return rv >= 0;
 }
 
@@ -793,7 +809,7 @@ static bool pmbus_check_status_register(struct i2c_client *client, int page)
 			status = -EIO;
 	}
 
-	pmbus_clear_cml_fault(client, -1);
+	pmbus_clear_cml_fault(client, -1, status < 0);
 	return status >= 0;
 }
 
@@ -821,7 +837,7 @@ static bool __maybe_unused pmbus_check_block_register(struct i2c_client *client,
 		rv = pmbus_check_status_cml(client);
 	if (rv < 0 && (data->flags & PMBUS_READ_STATUS_AFTER_FAILED_CHECK))
 		data->read_status(client, -1);
-	pmbus_clear_cml_fault(client, -1);
+	pmbus_clear_cml_fault(client, -1, rv < 0);
 	return rv >= 0;
 }
 
@@ -3094,7 +3110,7 @@ static int pmbus_init_common(struct i2c_client *client, struct pmbus_data *data,
 	if (data->info->pages)
 		pmbus_clear_cml_faults(client);
 	else
-		pmbus_clear_cml_fault(client, -1);
+		pmbus_clear_cml_fault(client, -1, true);
 
 	if (info->identify) {
 		ret = (*info->identify)(client, info);
@@ -3742,7 +3758,7 @@ static int pmbus_write_smbalert_mask(struct i2c_client *client, u8 page, u8 reg,
 	 * Clear fault systematically in case writing PMBUS_SMBALERT_MASK
 	 * is not supported by the chip.
 	 */
-	pmbus_clear_cml_fault(client, page);
+	pmbus_clear_cml_fault(client, page, true);
 
 	return ret;
 }
-- 
2.56.1.750.gf70dc682cf-goog


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] hwmon: (pmbus) Fall back to CLEAR_FAULTS when STATUS_CML is read-only
  2026-11-25  5:37 [PATCH] hwmon: (pmbus) Fall back to CLEAR_FAULTS when STATUS_CML is read-only Arthur Korn
@ 2026-11-25  5:49 ` sashiko-bot
  2026-11-25 15:53   ` Guenter Roeck
  0 siblings, 1 reply; 6+ messages in thread
From: sashiko-bot @ 2026-11-25  5:49 UTC (permalink / raw)
  To: Arthur Korn; +Cc: linux-hwmon

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] hwmon: (pmbus) pmbus_clear_cml_fault() disables W1C on
  virtual pages
--

commit 55aa274a3350ffb5857e7b698b066e9435f264ba
Author: Arthur Korn <akorn@google.com>

hwmon: (pmbus) Fall back to CLEAR_FAULTS when STATUS_CML is read-only

This commit reads back PMBUS_STATUS_CML after attempting to clear CML
faults on non-write-protected devices, disabling STATUS_CML write-1-to-clear
and falling back to CLEAR_FAULTS if the fault bits remain set.

> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
> index db5c5f533eb97..af8f589b328df 100644
> --- a/drivers/hwmon/pmbus/pmbus_core.c
> +++ b/drivers/hwmon/pmbus/pmbus_core.c
> @@ -728,15 +728,31 @@ void pmbus_clear_faults(struct i2c_client *client)
>  }
>  EXPORT_SYMBOL_NS_GPL(pmbus_clear_faults, "PMBUS");
>  
> -static void pmbus_clear_cml_fault(struct i2c_client *client, int page)
> +#define PB_CML_FAULT_CLEAR_MASK	(PB_CML_FAULT_INVALID_COMMAND | \
> +				 PB_CML_FAULT_INVALID_DATA)
> +
> +static void pmbus_clear_cml_fault(struct i2c_client *client, int page,
> +				  bool verify)
>  {
>  	struct pmbus_data *data = i2c_get_clientdata(client);
> +	int ret;
> +
> +	if (data->has_status_cml) {
> +		ret = _pmbus_write_byte_data(client, page, PMBUS_STATUS_CML,
> +					     PB_CML_FAULT_CLEAR_MASK);
> +		if (ret >= 0 && verify &&
> +		    !(data->flags & PMBUS_WRITE_PROTECTED)) {
> +			ret = _pmbus_read_byte_data(client, page,
> +						    PMBUS_STATUS_CML);
> +			if (ret >= 0 && (ret & PB_CML_FAULT_CLEAR_MASK))
> +				ret = -EIO;
> +		}
> +		if (ret >= 0)
> +			return;
> +		data->has_status_cml = false;
> +	}
>  
> -	if (!data->has_status_cml ||
> -	    _pmbus_write_byte_data(client, page, PMBUS_STATUS_CML,
> -				   PB_CML_FAULT_INVALID_COMMAND |
> -				   PB_CML_FAULT_INVALID_DATA) < 0)
> -		pmbus_clear_fault_page(client, page);
> +	pmbus_clear_fault_page(client, page);
>  }

[Severity: Medium]
Does clearing data->has_status_cml on any negative return value from
_pmbus_write_byte_data() disable STATUS_CML write-1-to-clear across the
whole device when a driver exposes a read-only virtual page?

During pmbus_init_common(), pmbus_clear_cml_faults() iterates over all
pages.  On multi-page devices such as max16601, virtual page 1 is
read-only while pages 0 (VCORE) and 2 (VSA) support byte writes:

drivers/hwmon/pmbus/max16601.c:max16601_write_byte_data() {
	...
	if (page > 0) {
		if (page == 2)	/* VSA */
			return i2c_smbus_write_byte_data(data->vsa, reg, value);
		return -EOPNOTSUPP;
	}
	return -ENODATA;
}

When pmbus_clear_cml_faults() reaches page 1, _pmbus_write_byte_data()
returns -EOPNOTSUPP and sets data->has_status_cml = false.  Unlike before,
where only page 1 fell back to pmbus_clear_fault_page(), this regression
disables STATUS_CML write-1-to-clear for page 2 and for all subsequent
register probes on page 0, sending PMBUS_CLEAR_FAULTS and wiping latched
faults on both rails.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261125053711.3098007-1-akorn@google.com?part=1

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] hwmon: (pmbus) Fall back to CLEAR_FAULTS when STATUS_CML is read-only
  2026-11-25  5:49 ` sashiko-bot
@ 2026-11-25 15:53   ` Guenter Roeck
  2026-11-25 18:15     ` Arthur Korn
       [not found]     ` <CAJ5cSJE1_zxkS861BT-8-+pxMnp3ONiJkGYjk1jnLQG57EZxmQ@mail.gmail.com>
  0 siblings, 2 replies; 6+ messages in thread
From: Guenter Roeck @ 2026-11-25 15:53 UTC (permalink / raw)
  To: sashiko-reviews, Arthur Korn; +Cc: linux-hwmon

On 11/24/26 21:49, sashiko-bot@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] hwmon: (pmbus) pmbus_clear_cml_fault() disables W1C on
>    virtual pages
> --
> 
> commit 55aa274a3350ffb5857e7b698b066e9435f264ba
> Author: Arthur Korn <akorn@google.com>
> 
> hwmon: (pmbus) Fall back to CLEAR_FAULTS when STATUS_CML is read-only
> 
> This commit reads back PMBUS_STATUS_CML after attempting to clear CML
> faults on non-write-protected devices, disabling STATUS_CML write-1-to-clear
> and falling back to CLEAR_FAULTS if the fault bits remain set.
> 
>> diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
>> index db5c5f533eb97..af8f589b328df 100644
>> --- a/drivers/hwmon/pmbus/pmbus_core.c
>> +++ b/drivers/hwmon/pmbus/pmbus_core.c
>> @@ -728,15 +728,31 @@ void pmbus_clear_faults(struct i2c_client *client)
>>   }
>>   EXPORT_SYMBOL_NS_GPL(pmbus_clear_faults, "PMBUS");
>>   
>> -static void pmbus_clear_cml_fault(struct i2c_client *client, int page)
>> +#define PB_CML_FAULT_CLEAR_MASK	(PB_CML_FAULT_INVALID_COMMAND | \
>> +				 PB_CML_FAULT_INVALID_DATA)
>> +
>> +static void pmbus_clear_cml_fault(struct i2c_client *client, int page,
>> +				  bool verify)
>>   {
>>   	struct pmbus_data *data = i2c_get_clientdata(client);
>> +	int ret;
>> +
>> +	if (data->has_status_cml) {
>> +		ret = _pmbus_write_byte_data(client, page, PMBUS_STATUS_CML,
>> +					     PB_CML_FAULT_CLEAR_MASK);
>> +		if (ret >= 0 && verify &&
>> +		    !(data->flags & PMBUS_WRITE_PROTECTED)) {
>> +			ret = _pmbus_read_byte_data(client, page,
>> +						    PMBUS_STATUS_CML);
>> +			if (ret >= 0 && (ret & PB_CML_FAULT_CLEAR_MASK))
>> +				ret = -EIO;
>> +		}
>> +		if (ret >= 0)
>> +			return;
>> +		data->has_status_cml = false;
>> +	}
>>   
>> -	if (!data->has_status_cml ||
>> -	    _pmbus_write_byte_data(client, page, PMBUS_STATUS_CML,
>> -				   PB_CML_FAULT_INVALID_COMMAND |
>> -				   PB_CML_FAULT_INVALID_DATA) < 0)
>> -		pmbus_clear_fault_page(client, page);
>> +	pmbus_clear_fault_page(client, page);
>>   }
> 
> [Severity: Medium]
> Does clearing data->has_status_cml on any negative return value from
> _pmbus_write_byte_data() disable STATUS_CML write-1-to-clear across the
> whole device when a driver exposes a read-only virtual page?
> 
> During pmbus_init_common(), pmbus_clear_cml_faults() iterates over all
> pages.  On multi-page devices such as max16601, virtual page 1 is
> read-only while pages 0 (VCORE) and 2 (VSA) support byte writes:
> 
> drivers/hwmon/pmbus/max16601.c:max16601_write_byte_data() {
> 	...
> 	if (page > 0) {
> 		if (page == 2)	/* VSA */
> 			return i2c_smbus_write_byte_data(data->vsa, reg, value);
> 		return -EOPNOTSUPP;
> 	}
> 	return -ENODATA;
> }
> 
> When pmbus_clear_cml_faults() reaches page 1, _pmbus_write_byte_data()
> returns -EOPNOTSUPP and sets data->has_status_cml = false.  Unlike before,
> where only page 1 fell back to pmbus_clear_fault_page(), this regression
> disables STATUS_CML write-1-to-clear for page 2 and for all subsequent
> register probes on page 0, sending PMBUS_CLEAR_FAULTS and wiping latched
> faults on both rails.
> 

Seems real. Arthur, what do you think ?

[ PMBus is really annoying :-( ]

Guenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] hwmon: (pmbus) Fall back to CLEAR_FAULTS when STATUS_CML is read-only
  2026-11-25 15:53   ` Guenter Roeck
@ 2026-11-25 18:15     ` Arthur Korn
  2026-11-25 20:28       ` Guenter Roeck
       [not found]     ` <CAJ5cSJE1_zxkS861BT-8-+pxMnp3ONiJkGYjk1jnLQG57EZxmQ@mail.gmail.com>
  1 sibling, 1 reply; 6+ messages in thread
From: Arthur Korn @ 2026-11-25 18:15 UTC (permalink / raw)
  To: Guenter Roeck; +Cc: Arthur Korn, sashiko-reviews, linux-hwmon

On 11/25/26 07:53, Guenter Roeck wrote:
> On 11/24/26 21:49, sashiko-bot@kernel.org wrote:
>> [Severity: Medium]
>> Does clearing data->has_status_cml on any negative return value from
>> _pmbus_write_byte_data() disable STATUS_CML write-1-to-clear across the
>> whole device when a driver exposes a read-only virtual page?
...
> Seems real. Arthur, what do you think ?
>
> [ PMBus is really annoying :-( ]

Confirmed -- Sashiko's finding is real.

I tested on a system with 30x MAX16600B.04 VRs driven by max16601 (which
sets PMBUS_PAGE_VIRTUAL on all 3 pages because the chip NACKs PMBUS_PAGE
0x00 and latches INVALID_COMMAND):

  - Page 0 (VCORE at addr) and Page 2 (VSA dummy client at addr + 1)
    both implement writable STATUS_CML (0x7e): writing 0xc0 clears
    latched INVALID_COMMAND | INVALID_DATA cleanly to 0x00 on both I2C
    addresses while preserving other STATUS_CML bits.
  - Page 1 is a software-only virtual page exposing vendor registers
    0xf1/0xf2 (IIN_SENSOR / TOTAL_INPUT_POWER); max16601_write_byte_data()
    and max16601_write_byte() both return -EOPNOTSUPP for page == 1.

With v1, pmbus_clear_cml_faults() hit -EOPNOTSUPP on page 1 and set
data->has_status_cml = false for the whole device, causing page 2 and
subsequent register checks on page 0 to fall back to CLEAR_FAULTS.

In v2, I moved data->has_status_cml = false inside the readback check so
it is only cleared when _pmbus_write_byte_data() succeeds and the readback
still shows PB_CML_FAULT_CLEAR_MASK set (the read-only STATUS_CML case).
When _pmbus_write_byte_data() returns an error (such as -EOPNOTSUPP on a
virtual page), only that call falls back to pmbus_clear_fault_page(),
preserving the existing behavior from d9d30e1cb9ca.

(Side note noticed on the live MAX16600B.04 system: untouched devices boot
with status2 = 0x0002 / status2_cml = 0x80 latched on VSA because
pmbus_check_register() and pmbus_check_status_register() pass page = -1 to
pmbus_clear_cml_fault() / pmbus_check_status_cml(), which targets the
primary client 0x69 instead of data->vsa 0x6a when probing page 2. Happy
to look at that separately if useful.)

Sending [PATCH v2] shortly.

Thanks,
Arthur

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] hwmon: (pmbus) Fall back to CLEAR_FAULTS when STATUS_CML is read-only
       [not found]     ` <CAJ5cSJE1_zxkS861BT-8-+pxMnp3ONiJkGYjk1jnLQG57EZxmQ@mail.gmail.com>
@ 2026-11-25 18:32       ` Guenter Roeck
  0 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2026-11-25 18:32 UTC (permalink / raw)
  To: Arthur Korn; +Cc: sashiko-reviews, linux-hwmon

On 11/25/26 08:53, Arthur Korn wrote:
> What are virtual pages even? PMBus spec 1.3.1 part II doesn't mention them.
> 

Implementation specific, mapping of device internals into PMBus functions.
For example, the max16601 driver uses a virtual page to access the
vsa client (which is at another i2C address and requires a dummy I2C
device).

Guenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] hwmon: (pmbus) Fall back to CLEAR_FAULTS when STATUS_CML is read-only
  2026-11-25 18:15     ` Arthur Korn
@ 2026-11-25 20:28       ` Guenter Roeck
  0 siblings, 0 replies; 6+ messages in thread
From: Guenter Roeck @ 2026-11-25 20:28 UTC (permalink / raw)
  To: Arthur Korn; +Cc: sashiko-reviews, linux-hwmon

On 11/25/26 10:15, Arthur Korn wrote:
> On 11/25/26 07:53, Guenter Roeck wrote:
>> On 11/24/26 21:49, sashiko-bot@kernel.org wrote:
>>> [Severity: Medium]
>>> Does clearing data->has_status_cml on any negative return value from
>>> _pmbus_write_byte_data() disable STATUS_CML write-1-to-clear across the
>>> whole device when a driver exposes a read-only virtual page?
> ...
>> Seems real. Arthur, what do you think ?
>>
>> [ PMBus is really annoying :-( ]
> 
> Confirmed -- Sashiko's finding is real.
> 
> I tested on a system with 30x MAX16600B.04 VRs driven by max16601 (which
> sets PMBUS_PAGE_VIRTUAL on all 3 pages because the chip NACKs PMBUS_PAGE
> 0x00 and latches INVALID_COMMAND):
> 
>    - Page 0 (VCORE at addr) and Page 2 (VSA dummy client at addr + 1)
>      both implement writable STATUS_CML (0x7e): writing 0xc0 clears
>      latched INVALID_COMMAND | INVALID_DATA cleanly to 0x00 on both I2C
>      addresses while preserving other STATUS_CML bits.
>    - Page 1 is a software-only virtual page exposing vendor registers
>      0xf1/0xf2 (IIN_SENSOR / TOTAL_INPUT_POWER); max16601_write_byte_data()
>      and max16601_write_byte() both return -EOPNOTSUPP for page == 1.
> 
> With v1, pmbus_clear_cml_faults() hit -EOPNOTSUPP on page 1 and set
> data->has_status_cml = false for the whole device, causing page 2 and
> subsequent register checks on page 0 to fall back to CLEAR_FAULTS.
> 
> In v2, I moved data->has_status_cml = false inside the readback check so
> it is only cleared when _pmbus_write_byte_data() succeeds and the readback
> still shows PB_CML_FAULT_CLEAR_MASK set (the read-only STATUS_CML case).
> When _pmbus_write_byte_data() returns an error (such as -EOPNOTSUPP on a
> virtual page), only that call falls back to pmbus_clear_fault_page(),
> preserving the existing behavior from d9d30e1cb9ca.
> 
> (Side note noticed on the live MAX16600B.04 system: untouched devices boot
> with status2 = 0x0002 / status2_cml = 0x80 latched on VSA because
> pmbus_check_register() and pmbus_check_status_register() pass page = -1 to
> pmbus_clear_cml_fault() / pmbus_check_status_cml(), which targets the
> primary client 0x69 instead of data->vsa 0x6a when probing page 2. Happy
> to look at that separately if useful.)
> Sure, that would be great.

Thanks,
Guenter


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-11-25 20:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  5:37 [PATCH] hwmon: (pmbus) Fall back to CLEAR_FAULTS when STATUS_CML is read-only Arthur Korn
2026-11-25  5:49 ` sashiko-bot
2026-11-25 15:53   ` Guenter Roeck
2026-11-25 18:15     ` Arthur Korn
2026-11-25 20:28       ` Guenter Roeck
     [not found]     ` <CAJ5cSJE1_zxkS861BT-8-+pxMnp3ONiJkGYjk1jnLQG57EZxmQ@mail.gmail.com>
2026-11-25 18:32       ` Guenter Roeck

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.