Messages in this thread Patch in this message | | | From | Florian Fainelli <> | Subject | [PATCH net-next] net: phy: Improved phy_error() with function and error code | Date | Mon, 20 Mar 2023 14:34:51 -0700 |
| |
When the PHY library calls phy_error() something bad has happened, and we halt the PHY state machine. To facilitate debugging, introduce phy_error_precise() which allows us to provide useful information about the calling function and the error actually returned to facilitate debugging.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> --- drivers/net/phy/phy.c | 21 ++++++++++++++------- include/linux/phy.h | 6 +++++- 2 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c index b33e55a7364e..a84f7873700d 100644 --- a/drivers/net/phy/phy.c +++ b/drivers/net/phy/phy.c @@ -1170,17 +1170,20 @@ void phy_stop_machine(struct phy_device *phydev) } /** - * phy_error - enter HALTED state for this PHY device + * phy_error_precise - enter HALTED state for this PHY device * @phydev: target phy_device struct + * @func: symbolic function name that returned the error + * @err: return code from the function that caused the error * * Moves the PHY to the HALTED state in response to a read * or write error, and tells the controller the link is down. * Must not be called from interrupt context, or while the * phydev->lock is held. */ -void phy_error(struct phy_device *phydev) +void phy_error_precise(struct phy_device *phydev, const void *func, + int err) { - WARN_ON(1); + WARN(1, "%pS: returned: %d\n", func, err); mutex_lock(&phydev->lock); phydev->state = PHY_HALTED; @@ -1188,7 +1191,7 @@ void phy_error(struct phy_device *phydev) phy_trigger_machine(phydev); } -EXPORT_SYMBOL(phy_error); +EXPORT_SYMBOL(phy_error_precise); /** * phy_disable_interrupts - Disable the PHY interrupts from the PHY side @@ -1378,6 +1381,7 @@ void phy_state_machine(struct work_struct *work) struct net_device *dev = phydev->attached_dev; bool needs_aneg = false, do_suspend = false; enum phy_state old_state; + const void *func = NULL; bool finished = false; int err = 0; @@ -1396,6 +1400,7 @@ void phy_state_machine(struct work_struct *work) case PHY_NOLINK: case PHY_RUNNING: err = phy_check_link_status(phydev); + func = &phy_check_link_status; break; case PHY_CABLETEST: err = phydev->drv->cable_test_get_status(phydev, &finished); @@ -1425,16 +1430,18 @@ void phy_state_machine(struct work_struct *work) mutex_unlock(&phydev->lock); - if (needs_aneg) + if (needs_aneg) { err = phy_start_aneg(phydev); - else if (do_suspend) + func = &phy_start_aneg; + } else if (do_suspend) { phy_suspend(phydev); + } if (err == -ENODEV) return; if (err < 0) - phy_error(phydev); + phy_error_precise(phydev, func, err); if (old_state != phydev->state) { phydev_dbg(phydev, "PHY state change %s -> %s\n", diff --git a/include/linux/phy.h b/include/linux/phy.h index fefd5091bc24..dc77b09908da 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -1793,7 +1793,11 @@ void phy_drivers_unregister(struct phy_driver *drv, int n); int phy_driver_register(struct phy_driver *new_driver, struct module *owner); int phy_drivers_register(struct phy_driver *new_driver, int n, struct module *owner); -void phy_error(struct phy_device *phydev); +void phy_error_precise(struct phy_device *phydev, const void *func, int err); +static inline void phy_error(struct phy_device *phydev) +{ + phy_error_precise(phydev, (const void *)_RET_IP_, -EIO); +} void phy_state_machine(struct work_struct *work); void phy_queue_state_machine(struct phy_device *phydev, unsigned long jiffies); void phy_trigger_machine(struct phy_device *phydev); -- 2.34.1
| |