diff mbox series

[net-next] net: phy: Improved phy_error() with function and error code

Message ID 20230320213451.2579608-1-f.fainelli@gmail.com (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] net: phy: Improved phy_error() with function and error code | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 426 this patch: 426
netdev/cc_maintainers success CCed 8 of 8 maintainers
netdev/build_clang success Errors and warnings before: 300 this patch: 300
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 No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 412 this patch: 412
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 78 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Florian Fainelli March 20, 2023, 9:34 p.m. UTC
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(-)

Comments

Jakub Kicinski March 22, 2023, 4:41 a.m. UTC | #1
On Mon, 20 Mar 2023 14:34:51 -0700 Florian Fainelli wrote:
> +static inline void phy_error(struct phy_device *phydev)
> +{
> +	phy_error_precise(phydev, (const void *)_RET_IP_, -EIO);
> +}

LGTM apart from this _RET_IP_ here. Wouldn't this make @func
sometimes the function that returned the error and sometimes
the caller? The caller is in the stack trace already, so no
need to duplicate. Besides how dependable is using _RET_IP_ 
inside a static inline?
Florian Fainelli March 22, 2023, 4 p.m. UTC | #2
On 3/21/2023 9:41 PM, Jakub Kicinski wrote:
> On Mon, 20 Mar 2023 14:34:51 -0700 Florian Fainelli wrote:
>> +static inline void phy_error(struct phy_device *phydev)
>> +{
>> +	phy_error_precise(phydev, (const void *)_RET_IP_, -EIO);
>> +}
> 
> LGTM apart from this _RET_IP_ here. Wouldn't this make @func
> sometimes the function that returned the error and sometimes
> the caller? The caller is in the stack trace already, so no
> need to duplicate. Besides how dependable is using _RET_IP_
> inside a static inline?

You have a point that the existing phy_error() already has a WARN_ON() 
that will tell us which function it has been invoked from whenever 
phy_error() is used outside of the phy_state_machine(), expect a v2 shortly.
diff mbox series

Patch

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);