mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net] net: pse-pd: tps23881: Fix reported power class
@ 2026-11-19 11:25 Kory Maincent
  2026-11-19 11:28 ` netdev-bot+sinfo
  2026-11-23 11:35 ` netdev-bot+sashiko
  0 siblings, 2 replies; 4+ messages in thread
From: Kory Maincent @ 2026-11-19 11:25 UTC (permalink / raw)
  To: Kory Maincent, Paolo Abeni, Oleksij Rempel, Jakub Kicinski,
	netdev, linux-kernel
  Cc: thomas.petazzoni, Andrew Lunn, David S. Miller, Eric Dumazet

The power class read from the classification register is not 1:1
aligned with the IEEE 802.3 class value. Add a lookup table to report
the correct class.

Fixes: 7f076ce3f1733 ("net: pse-pd: tps23881: Add support for power limit and measurement features")
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---
 drivers/net/pse-pd/tps23881.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)

diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c
index 244ce596d845c..58ea7e0ffa996 100644
--- a/drivers/net/pse-pd/tps23881.c
+++ b/drivers/net/pse-pd/tps23881.c
@@ -402,6 +402,25 @@ tps23881_pi_get_chan_current(struct tps23881_priv *priv, u8 chan)
 	return (int)tmp_64;
 }
 
+static int tps23881_class_table[] = {
+	-ERANGE,
+	1,
+	2,
+	3,
+	4,
+	0,
+	0,
+	-ERANGE,
+	5,
+	6,
+	7,
+	8,
+	4,
+	5,
+	-ERANGE,
+	-ERANGE,
+};
+
 static int tps23881_pi_get_pw_class(struct pse_controller_dev *pcdev,
 				    int id)
 {
@@ -416,7 +435,8 @@ static int tps23881_pi_get_pw_class(struct pse_controller_dev *pcdev,
 	if (ret < 0)
 		return ret;
 
-	return tps23881_calc_val(ret, chan, 4, 0x0f);
+	ret = tps23881_calc_val(ret, chan, 4, 0x0f);
+	return tps23881_class_table[ret];
 }
 
 static int
-- 
2.43.0


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

* Re: [PATCH net] net: pse-pd: tps23881: Fix reported power class
  2026-11-19 11:25 [PATCH net] net: pse-pd: tps23881: Fix reported power class Kory Maincent
@ 2026-11-19 11:28 ` netdev-bot+sinfo
  2026-11-23 11:35 ` netdev-bot+sashiko
  1 sibling, 0 replies; 4+ messages in thread
From: netdev-bot+sinfo @ 2026-11-19 11:28 UTC (permalink / raw)
  To: Kory Maincent
  Cc: Paolo Abeni, Oleksij Rempel, Jakub Kicinski, netdev,
	linux-kernel, thomas.petazzoni, Andrew Lunn, David S. Miller,
	Eric Dumazet

Hi!

This is an automated message. This series looks like a fix, but its
commit messages seem to be missing some information:

 - How the issue was discovered, e.g. hit in production, hit during
   development, syzbot report, manual code inspection, LLM or static
   analysis tool scan.

 - Whether the issue was actually triggered, or is only theoretical
   (e.g. found by LLM and not proven at runtime). If it was triggered
   please include the symptoms, like the stack trace or kernel messages.

Please do not repost the series just to address the above. Instead,
reply to this email with the missing information, so that reviewers
can take it into account.

*IMPORTANT*: If you do repost (for other reasons) - please include
the relevant info in the cover letter or commit messages.
-- 
The evaluation is done by an LLM so it may be wrong, if you think
that is the case please reply and explain.

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

* Re: [PATCH net] net: pse-pd: tps23881: Fix reported power class
  2026-11-19 11:25 [PATCH net] net: pse-pd: tps23881: Fix reported power class Kory Maincent
  2026-11-19 11:28 ` netdev-bot+sinfo
@ 2026-11-23 11:35 ` netdev-bot+sashiko
  2026-11-23 13:24   ` Kory Maincent
  1 sibling, 1 reply; 4+ messages in thread
From: netdev-bot+sashiko @ 2026-11-23 11:35 UTC (permalink / raw)
  To: kory.maincent
  Cc: pabeni, o.rempel, kuba, netdev, linux-kernel, thomas.petazzoni,
	andrew+netdev, davem, edumazet

Thank you for your contribution! Sashiko AI review found 1 potential
issue(s) to consider.

Critical: 0 · High: 1 · Medium: 0 · Low: 0

If you believe none of the issues are legitimate, please reply to each
issue of Medium severity or higher and explain why the AI is wrong.
If any of them are legitimate and you plan to respin, please let patchwork
know by including "pw-bot: cr" as a separate line at the end of your reply
(one such reply per series is enough).

- [High] The new lookup table in tps23881_pi_get_pw_class()
  (drivers/net/pse-pd/tps23881.c) maps four raw class codes to -ERANGE:…

--

net: pse-pd: tps23881: Fix reported power class

This commit adds a lookup table to tps23881_pi_get_pw_class() that
translates the raw classification register value into the IEEE 802.3
class number. Before this, the raw value was reported directly.

> diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c
> index 244ce596d845c..58ea7e0ffa996 100644
> --- a/drivers/net/pse-pd/tps23881.c
> +++ b/drivers/net/pse-pd/tps23881.c
> @@ -402,6 +402,25 @@ tps23881_pi_get_chan_current(struct tps23881_priv *priv, u8 chan)
>  	return (int)tmp_64;
>  }
>  
> +static int tps23881_class_table[] = {
> +	-ERANGE,
> +	1,
> +	2,
> +	3,
> +	4,
> +	0,
> +	0,
> +	-ERANGE,
> +	5,
> +	6,
> +	7,
> +	8,
> +	4,
> +	5,
> +	-ERANGE,
> +	-ERANGE,
> +};
> +

[ ... ]

> @@ -416,7 +435,8 @@ static int tps23881_pi_get_pw_class(struct pse_controller_dev *pcdev,
>  	if (ret < 0)
>  		return ret;
>  
> -	return tps23881_calc_val(ret, chan, 4, 0x0f);
> +	ret = tps23881_calc_val(ret, chan, 4, 0x0f);
> +	return tps23881_class_table[ret];

[Severity: High]
Will this make the whole PSE status query fail on a port with no
classified PD?

The table maps four raw codes to -ERANGE: 0x0 (unknown / not
classified), 0x7 (overcurrent during classification), 0xE (reserved)
and 0xF (class mismatch). Code 0x0 is the register's reset value. It is
what an empty, disabled or still-detecting port normally reads.

pse_ethtool_get_status() in drivers/net/pse-pd/pse_core.c treats any
negative return as fatal:

	if (ops->pi_get_pw_class) {
		ret = ops->pi_get_pw_class(pcdev, psec->id);
		if (ret < 0)
			goto out;

The error then goes back to userspace through this path:

  pse_prepare_data()
    -> pse_get_pse_attributes()
      -> pse_ethtool_get_status()
        -> tps23881_pi_get_pw_class()  /* returns -ERANGE */

The admin state and power status, which were already read, are thrown
away. Actual power, power limit and limit ranges are never read.

Before this patch, raw 0 set c33_pw_class to 0. pse_fill_reply() in
net/ethtool/pse-pd.c then just left the attribute out:

	if (st->c33_pw_class > 0 &&
	    nla_put_u32(skb, ETHTOOL_A_C33_PSE_PW_CLASS,
			st->c33_pw_class))

For the same op, pd692x0_pi_get_pw_class() returns 0 for unknown or
out-of-range classes:

	class = buf.data[3] >> 4;
	if (class <= 8)
		return class;

	return 0;

Could these four entries be 0 instead of -ERANGE, so that ethtool
--show-pse still works on unclassified ports and on ports in the fault
states (0x7, 0xF)?

The commit message also doesn't say that some register values now cause
the status query to fail.

>  }
>  
>  static int

-- 
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261119112511.239208-1-kory.maincent%40bootlin.com

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

* Re: [PATCH net] net: pse-pd: tps23881: Fix reported power class
  2026-11-23 11:35 ` netdev-bot+sashiko
@ 2026-11-23 13:24   ` Kory Maincent
  0 siblings, 0 replies; 4+ messages in thread
From: Kory Maincent @ 2026-11-23 13:24 UTC (permalink / raw)
  To: netdev-bot+sashiko
  Cc: pabeni, o.rempel, kuba, netdev, linux-kernel, thomas.petazzoni,
	andrew+netdev, davem, edumazet



On 11/23/26 12:35, netdev-bot+sashiko@kernel.org wrote:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue(s) to consider.
> 
> Critical: 0 · High: 1 · Medium: 0 · Low: 0
> 
> If you believe none of the issues are legitimate, please reply to each
> issue of Medium severity or higher and explain why the AI is wrong.
> If any of them are legitimate and you plan to respin, please let patchwork
> know by including "pw-bot: cr" as a separate line at the end of your reply
> (one such reply per series is enough).
> 
> - [High] The new lookup table in tps23881_pi_get_pw_class()
>    (drivers/net/pse-pd/tps23881.c) maps four raw class codes to -ERANGE:…
> 
> --
> 
> net: pse-pd: tps23881: Fix reported power class
> 
> This commit adds a lookup table to tps23881_pi_get_pw_class() that
> translates the raw classification register value into the IEEE 802.3
> class number. Before this, the raw value was reported directly.
> 
>> diff --git a/drivers/net/pse-pd/tps23881.c b/drivers/net/pse-pd/tps23881.c
>> index 244ce596d845c..58ea7e0ffa996 100644
>> --- a/drivers/net/pse-pd/tps23881.c
>> +++ b/drivers/net/pse-pd/tps23881.c
>> @@ -402,6 +402,25 @@ tps23881_pi_get_chan_current(struct tps23881_priv *priv, u8 chan)
>>   	return (int)tmp_64;
>>   }
>>   
>> +static int tps23881_class_table[] = {
>> +	-ERANGE,
>> +	1,
>> +	2,
>> +	3,
>> +	4,
>> +	0,
>> +	0,
>> +	-ERANGE,
>> +	5,
>> +	6,
>> +	7,
>> +	8,
>> +	4,
>> +	5,
>> +	-ERANGE,
>> +	-ERANGE,
>> +};
>> +
> 
> [ ... ]
> 
>> @@ -416,7 +435,8 @@ static int tps23881_pi_get_pw_class(struct pse_controller_dev *pcdev,
>>   	if (ret < 0)
>>   		return ret;
>>   
>> -	return tps23881_calc_val(ret, chan, 4, 0x0f);
>> +	ret = tps23881_calc_val(ret, chan, 4, 0x0f);
>> +	return tps23881_class_table[ret];
> 
> [Severity: High]
> Will this make the whole PSE status query fail on a port with no
> classified PD?

Yes indeed.
> The error then goes back to userspace through this path:
> 
>    pse_prepare_data()
>      -> pse_get_pse_attributes()
>        -> pse_ethtool_get_status()
>          -> tps23881_pi_get_pw_class()  /* returns -ERANGE */
> 
> The admin state and power status, which were already read, are thrown
> away. Actual power, power limit and limit ranges are never read.
> 
> Before this patch, raw 0 set c33_pw_class to 0. pse_fill_reply() in
> net/ethtool/pse-pd.c then just left the attribute out:
> 
> 	if (st->c33_pw_class > 0 &&
> 	    nla_put_u32(skb, ETHTOOL_A_C33_PSE_PW_CLASS,
> 			st->c33_pw_class))

I am wondering about this. Class 0 is a valid class, it means 
classification is not implemented. Then on this case should we report it 
or not. A unknown class is kind of similar to a classification not 
implemented. I will change ERANGE value to 0.

-- 
Köry Maincent, Bootlin
Embedded Linux and kernel engineering
https://bootlin.com


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

end of thread, other threads:[~2026-11-23 13:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 11:25 [PATCH net] net: pse-pd: tps23881: Fix reported power class Kory Maincent
2026-11-19 11:28 ` netdev-bot+sinfo
2026-11-23 11:35 ` netdev-bot+sashiko
2026-11-23 13:24   ` Kory Maincent

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®