Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: pse-pd: Add helper to report hardware enable status of the PI

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>

authored by

Kory Maincent (Dent Project) and committed by
Jakub Kicinski
c394e757 1176978e

+26 -10
+26 -10
drivers/net/pse-pd/pse_core.c
··· 272 272 return psec->attached_phydev->attached_dev; 273 273 } 274 274 275 + /** 276 + * pse_pi_is_hw_enabled - Is PI enabled at the hardware level 277 + * @pcdev: a pointer to the PSE controller device 278 + * @id: Index of the PI 279 + * 280 + * Return: 1 if the PI is enabled at the hardware level, 0 if not, and 281 + * a failure value on error 282 + */ 283 + static int pse_pi_is_hw_enabled(struct pse_controller_dev *pcdev, int id) 284 + { 285 + struct pse_admin_state admin_state = {0}; 286 + int ret; 287 + 288 + ret = pcdev->ops->pi_get_admin_state(pcdev, id, &admin_state); 289 + if (ret < 0) 290 + return ret; 291 + 292 + /* PI is well enabled at the hardware level */ 293 + if (admin_state.podl_admin_state == ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED || 294 + admin_state.c33_admin_state == ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED) 295 + return 1; 296 + 297 + return 0; 298 + } 299 + 275 300 static int pse_pi_is_enabled(struct regulator_dev *rdev) 276 301 { 277 302 struct pse_controller_dev *pcdev = rdev_get_drvdata(rdev); 278 - struct pse_admin_state admin_state = {0}; 279 303 const struct pse_controller_ops *ops; 280 304 int id, ret; 281 305 ··· 309 285 310 286 id = rdev_get_id(rdev); 311 287 mutex_lock(&pcdev->lock); 312 - ret = ops->pi_get_admin_state(pcdev, id, &admin_state); 313 - if (ret) 314 - goto out; 315 - 316 - if (admin_state.podl_admin_state == ETHTOOL_PODL_PSE_ADMIN_STATE_ENABLED || 317 - admin_state.c33_admin_state == ETHTOOL_C33_PSE_ADMIN_STATE_ENABLED) 318 - ret = 1; 319 - 320 - out: 288 + ret = pse_pi_is_hw_enabled(pcdev, id); 321 289 mutex_unlock(&pcdev->lock); 322 290 323 291 return ret;