]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
net: pse-pd: Add helper to report hardware enable status of the PI
authorKory Maincent (Dent Project) <kory.maincent@bootlin.com>
Tue, 17 Jun 2025 12:12:05 +0000 (14:12 +0200)
committerJakub Kicinski <kuba@kernel.org>
Thu, 19 Jun 2025 02:00:17 +0000 (19:00 -0700)
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@bootlin.com>
Reviewed-by: Oleksij Rempel <o.rempel@pengutronix.de>
Link: https://patch.msgid.link/20250617-feature_poe_port_prio-v14-6-78a1a645e2ee@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
drivers/net/pse-pd/pse_core.c

index 7d424c22225e25340f8a413f89f93773b1b11e54..495d72f98029e64791156bce4b9823d6f9094f34 100644 (file)
@@ -272,10 +272,34 @@ static struct net_device *pse_control_get_netdev(struct pse_control *psec)
        return psec->attached_phydev->attached_dev;
 }
 
+/**
+ * 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;
 
@@ -285,15 +309,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;