diff mbox series

[net] net: pse-pd: Fix enabled status mismatch

Message ID 20241002121706.246143-1-kory.maincent@bootlin.com (mailing list archive)
State Accepted
Commit dda3529d2e84e2ee7b97158c9cdf5e10308f37bc
Delegated to: Netdev Maintainers
Headers show
Series [net] net: pse-pd: Fix enabled status mismatch | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 9 this patch: 9
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers success CCed 7 of 7 maintainers
netdev/build_clang success Errors and warnings before: 9 this patch: 9
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 17 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
netdev/contest success net-next-2024-10-04--18-00 (tests: 773)

Commit Message

Kory Maincent Oct. 2, 2024, 12:17 p.m. UTC
PSE controllers like the TPS23881 can forcefully turn off their
configuration state. In such cases, the is_enabled() and get_status()
callbacks will report the PSE as disabled, while admin_state_enabled
will show it as enabled. This mismatch can lead the user to attempt
to enable it, but no action is taken as admin_state_enabled remains set.

The solution is to disable the PSE before enabling it, ensuring the
actual status matches admin_state_enabled.

Fixes: d83e13761d5b ("net: pse-pd: Use regulator framework within PSE framework")
Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
---

FYI: Saving the enabled state in the driver is not a viable solution, as a
reboot may cause a mismatch between the real and software-saved states.
---
 drivers/net/pse-pd/pse_core.c | 11 +++++++++++
 1 file changed, 11 insertions(+)

Comments

Andrew Lunn Oct. 2, 2024, 12:38 p.m. UTC | #1
On Wed, Oct 02, 2024 at 02:17:05PM +0200, Kory Maincent wrote:
> PSE controllers like the TPS23881 can forcefully turn off their
> configuration state. In such cases, the is_enabled() and get_status()
> callbacks will report the PSE as disabled, while admin_state_enabled
> will show it as enabled. This mismatch can lead the user to attempt
> to enable it, but no action is taken as admin_state_enabled remains set.
> 
> The solution is to disable the PSE before enabling it, ensuring the
> actual status matches admin_state_enabled.
> 
> Fixes: d83e13761d5b ("net: pse-pd: Use regulator framework within PSE framework")
> Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> ---
> 
> FYI: Saving the enabled state in the driver is not a viable solution, as a
> reboot may cause a mismatch between the real and software-saved states.

This seems O.K. to me.

I'm assuming the controller has turned the configuration state to off
to stop the magic smoke escaping? Is there any sort of notification of
this?  Does it raise an interrupt? Sometime in the future we might
want to add a netlink notification about this?

Reviewed-by: Andrew Lunn <andrew@lunn.ch>

    Andrew
Kory Maincent Oct. 2, 2024, 12:46 p.m. UTC | #2
On Wed, 2 Oct 2024 14:38:19 +0200
Andrew Lunn <andrew@lunn.ch> wrote:

> On Wed, Oct 02, 2024 at 02:17:05PM +0200, Kory Maincent wrote:
> > PSE controllers like the TPS23881 can forcefully turn off their
> > configuration state. In such cases, the is_enabled() and get_status()
> > callbacks will report the PSE as disabled, while admin_state_enabled
> > will show it as enabled. This mismatch can lead the user to attempt
> > to enable it, but no action is taken as admin_state_enabled remains set.
> > 
> > The solution is to disable the PSE before enabling it, ensuring the
> > actual status matches admin_state_enabled.
> > 
> > Fixes: d83e13761d5b ("net: pse-pd: Use regulator framework within PSE
> > framework") Signed-off-by: Kory Maincent <kory.maincent@bootlin.com>
> > ---
> > 
> > FYI: Saving the enabled state in the driver is not a viable solution, as a
> > reboot may cause a mismatch between the real and software-saved states.  
> 
> This seems O.K. to me.
> 
> I'm assuming the controller has turned the configuration state to off
> to stop the magic smoke escaping? Is there any sort of notification of
> this?  Does it raise an interrupt? Sometime in the future we might
> want to add a netlink notification about this?

Thanks for your review!

Yes, in case of over-current or over-temperature, there is an interrupt. The
netlink notifications support will arrive soon in the series in progress.

Regards,
patchwork-bot+netdevbpf@kernel.org Oct. 4, 2024, 10:40 p.m. UTC | #3
Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed,  2 Oct 2024 14:17:05 +0200 you wrote:
> PSE controllers like the TPS23881 can forcefully turn off their
> configuration state. In such cases, the is_enabled() and get_status()
> callbacks will report the PSE as disabled, while admin_state_enabled
> will show it as enabled. This mismatch can lead the user to attempt
> to enable it, but no action is taken as admin_state_enabled remains set.
> 
> The solution is to disable the PSE before enabling it, ensuring the
> actual status matches admin_state_enabled.
> 
> [...]

Here is the summary with links:
  - [net] net: pse-pd: Fix enabled status mismatch
    https://git.kernel.org/netdev/net/c/dda3529d2e84

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
index 4f032b16a8a0..f8e6854781e6 100644
--- a/drivers/net/pse-pd/pse_core.c
+++ b/drivers/net/pse-pd/pse_core.c
@@ -785,6 +785,17 @@  static int pse_ethtool_c33_set_config(struct pse_control *psec,
 	 */
 	switch (config->c33_admin_control) {
 	case ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED:
+		/* We could have mismatch between admin_state_enabled and
+		 * state reported by regulator_is_enabled. This can occur when
+		 * the PI is forcibly turn off by the controller. Call
+		 * regulator_disable on that case to fix the counters state.
+		 */
+		if (psec->pcdev->pi[psec->id].admin_state_enabled &&
+		    !regulator_is_enabled(psec->ps)) {
+			err = regulator_disable(psec->ps);
+			if (err)
+				break;
+		}
 		if (!psec->pcdev->pi[psec->id].admin_state_enabled)
 			err = regulator_enable(psec->ps);
 		break;