[PATCH net-next v13 06/13] net: pse-pd: Add helper to report hardware enable status of the PI

From: Kory Maincent
Date: Tue Jun 10 2025 - 04:20:37 EST


From: Kory Maincent (Dent Project) <kory.maincent@xxxxxxxxxxx>

Refactor code by introducing a helper function to retrieve the hardware
enabled state of the PI, avoiding redundant implementations in the
future.

Signed-off-by: Kory Maincent (Dent Project) <kory.maincent@xxxxxxxxxxx>
Reviewed-by: Oleksij Rempel <o.rempel@xxxxxxxxxxxxxx>
---

Change in v7:
- New patch.
---
drivers/net/pse-pd/pse_core.c | 36 ++++++++++++++++++++++++++----------
1 file changed, 26 insertions(+), 10 deletions(-)

diff --git a/drivers/net/pse-pd/pse_core.c b/drivers/net/pse-pd/pse_core.c
index debd9a721867..dd6775b9816a 100644
--- a/drivers/net/pse-pd/pse_core.c
+++ b/drivers/net/pse-pd/pse_core.c
@@ -276,10 +276,34 @@ pse_control_find_net_by_id(struct pse_controller_dev *pcdev, int id,
return NULL;
}

+/**
+ * pse_pi_is_hw_enabled - Is PI enabled at the hardware level
+ * @pcdev: a pointer to the PSE controller device
+ * @id: Index of the PI
+ *
+ * Return: 1 if the PI is enabled at the hardware level, 0 if not, and
+ * a failure value on error
+ */
+static int pse_pi_is_hw_enabled(struct pse_controller_dev *pcdev, int id)
+{
+ struct pse_admin_state admin_state = {0};
+ int ret;
+
+ ret = pcdev->ops->pi_get_admin_state(pcdev, id, &admin_state);
+ if (ret < 0)
+ return ret;
+
+ /* PI is well enabled at the hardware level */
+ if (admin_state.podl_admin_state == ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED ||
+ admin_state.c33_admin_state == ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED)
+ return 1;
+
+ return 0;
+}
+
static int pse_pi_is_enabled(struct regulator_dev *rdev)
{
struct pse_controller_dev *pcdev = rdev_get_drvdata(rdev);
- struct pse_admin_state admin_state = {0};
const struct pse_controller_ops *ops;
int id, ret;

@@ -289,15 +313,7 @@ static int pse_pi_is_enabled(struct regulator_dev *rdev)

id = rdev_get_id(rdev);
mutex_lock(&pcdev->lock);
- ret = ops->pi_get_admin_state(pcdev, id, &admin_state);
- if (ret)
- goto out;
-
- if (admin_state.podl_admin_state == ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED ||
- admin_state.c33_admin_state == ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED)
- ret = 1;
-
-out:
+ ret = pse_pi_is_hw_enabled(pcdev, id);
mutex_unlock(&pcdev->lock);

return ret;

--
2.43.0