mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Florian Fainelli <f.fainelli@gmail.com>
To: netdev@vger.kernel.org
Cc: opendmb@gmail.com, Florian Fainelli <f.fainelli@gmail.com>,
	Andrew Lunn <andrew@lunn.ch>,
	Heiner Kallweit <hkallweit1@gmail.com>,
	Russell King <linux@armlinux.org.uk>,
	"David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	linux-kernel@vger.kernel.org (open list)
Subject: [PATCH net-next] net: phy: Improved phy_error() with function and error code
Date: Mon, 20 Mar 2023 14:34:51 -0700	[thread overview]
Message-ID: <20230320213451.2579608-1-f.fainelli@gmail.com> (raw)

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


             reply	other threads:[~2023-03-20 21:35 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-20 21:34 Florian Fainelli [this message]
2023-03-22  4:41 ` Jakub Kicinski
2023-03-22 16:00   ` Florian Fainelli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230320213451.2579608-1-f.fainelli@gmail.com \
    --to=f.fainelli@gmail.com \
    --cc=andrew@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=hkallweit1@gmail.com \
    --cc=kuba@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=netdev@vger.kernel.org \
    --cc=opendmb@gmail.com \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®