2017-02-06 10:46:48 +00:00
|
|
|
From: Russell King <rmk+kernel@arm.linux.org.uk>
|
|
|
|
Date: Sun, 12 Feb 2017 17:27:17 +0100
|
|
|
|
Subject: [PATCH] phy: provide a hook for link up/link down events
|
|
|
|
|
|
|
|
Sometimes, we need to do additional work between the PHY coming up and
|
|
|
|
marking the carrier present - for example, we may need to wait for the
|
|
|
|
PHY to MAC link to finish negotiation. This changes phylib to provide
|
|
|
|
a notification function pointer which avoids the built-in
|
|
|
|
netif_carrier_on() and netif_carrier_off() functions.
|
|
|
|
|
|
|
|
Standard ->adjust_link functionality is provided by hooking a helper
|
|
|
|
into the new ->phy_link_change method.
|
|
|
|
|
|
|
|
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
|
|
|
|
---
|
|
|
|
|
|
|
|
--- a/drivers/net/phy/phy.c
|
|
|
|
+++ b/drivers/net/phy/phy.c
|
2017-08-17 08:51:05 +00:00
|
|
|
@@ -994,6 +994,16 @@ void phy_start(struct phy_device *phydev
|
2017-02-06 10:46:48 +00:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(phy_start);
|
|
|
|
|
|
|
|
+static void phy_link_up(struct phy_device *phydev)
|
|
|
|
+{
|
|
|
|
+ phydev->phy_link_change(phydev, true, true);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+static void phy_link_down(struct phy_device *phydev, bool do_carrier)
|
|
|
|
+{
|
|
|
|
+ phydev->phy_link_change(phydev, false, do_carrier);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* phy_state_machine - Handle the state machine
|
|
|
|
* @work: work_struct that describes the work to be done
|
2017-08-17 08:51:05 +00:00
|
|
|
@@ -1035,8 +1045,7 @@ void phy_state_machine(struct work_struc
|
2017-02-06 10:46:48 +00:00
|
|
|
/* If the link is down, give up on negotiation for now */
|
|
|
|
if (!phydev->link) {
|
|
|
|
phydev->state = PHY_NOLINK;
|
|
|
|
- netif_carrier_off(phydev->attached_dev);
|
|
|
|
- phydev->adjust_link(phydev->attached_dev);
|
|
|
|
+ phy_link_down(phydev, true);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-08-17 08:51:05 +00:00
|
|
|
@@ -1048,9 +1057,7 @@ void phy_state_machine(struct work_struc
|
2017-02-06 10:46:48 +00:00
|
|
|
/* If AN is done, we're running */
|
|
|
|
if (err > 0) {
|
|
|
|
phydev->state = PHY_RUNNING;
|
|
|
|
- netif_carrier_on(phydev->attached_dev);
|
|
|
|
- phydev->adjust_link(phydev->attached_dev);
|
|
|
|
-
|
|
|
|
+ phy_link_up(phydev);
|
|
|
|
} else if (0 == phydev->link_timeout--)
|
|
|
|
needs_aneg = true;
|
|
|
|
break;
|
2017-08-17 08:51:05 +00:00
|
|
|
@@ -1075,8 +1082,7 @@ void phy_state_machine(struct work_struc
|
2017-02-06 10:46:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
phydev->state = PHY_RUNNING;
|
|
|
|
- netif_carrier_on(phydev->attached_dev);
|
|
|
|
- phydev->adjust_link(phydev->attached_dev);
|
|
|
|
+ phy_link_up(phydev);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case PHY_FORCING:
|
2017-08-17 08:51:05 +00:00
|
|
|
@@ -1086,13 +1092,12 @@ void phy_state_machine(struct work_struc
|
2017-02-06 10:46:48 +00:00
|
|
|
|
|
|
|
if (phydev->link) {
|
|
|
|
phydev->state = PHY_RUNNING;
|
|
|
|
- netif_carrier_on(phydev->attached_dev);
|
|
|
|
+ phy_link_up(phydev);
|
|
|
|
} else {
|
|
|
|
if (0 == phydev->link_timeout--)
|
|
|
|
needs_aneg = true;
|
|
|
|
+ phy_link_down(phydev, false);
|
|
|
|
}
|
|
|
|
-
|
|
|
|
- phydev->adjust_link(phydev->attached_dev);
|
|
|
|
break;
|
|
|
|
case PHY_RUNNING:
|
|
|
|
/* Only register a CHANGE if we are polling and link changed
|
2017-08-17 08:51:05 +00:00
|
|
|
@@ -1124,14 +1129,12 @@ void phy_state_machine(struct work_struc
|
2017-02-06 10:46:48 +00:00
|
|
|
|
|
|
|
if (phydev->link) {
|
|
|
|
phydev->state = PHY_RUNNING;
|
|
|
|
- netif_carrier_on(phydev->attached_dev);
|
|
|
|
+ phy_link_up(phydev);
|
|
|
|
} else {
|
|
|
|
phydev->state = PHY_NOLINK;
|
|
|
|
- netif_carrier_off(phydev->attached_dev);
|
|
|
|
+ phy_link_down(phydev, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
- phydev->adjust_link(phydev->attached_dev);
|
|
|
|
-
|
|
|
|
if (phy_interrupt_is_valid(phydev))
|
|
|
|
err = phy_config_interrupt(phydev,
|
|
|
|
PHY_INTERRUPT_ENABLED);
|
2017-08-17 08:51:05 +00:00
|
|
|
@@ -1139,8 +1142,7 @@ void phy_state_machine(struct work_struc
|
2017-02-06 10:46:48 +00:00
|
|
|
case PHY_HALTED:
|
|
|
|
if (phydev->link) {
|
|
|
|
phydev->link = 0;
|
|
|
|
- netif_carrier_off(phydev->attached_dev);
|
|
|
|
- phydev->adjust_link(phydev->attached_dev);
|
|
|
|
+ phy_link_down(phydev, true);
|
|
|
|
do_suspend = true;
|
|
|
|
}
|
|
|
|
break;
|
2017-08-17 08:51:05 +00:00
|
|
|
@@ -1160,11 +1162,11 @@ void phy_state_machine(struct work_struc
|
2017-02-06 10:46:48 +00:00
|
|
|
|
|
|
|
if (phydev->link) {
|
|
|
|
phydev->state = PHY_RUNNING;
|
|
|
|
- netif_carrier_on(phydev->attached_dev);
|
|
|
|
+ phy_link_up(phydev);
|
|
|
|
} else {
|
|
|
|
phydev->state = PHY_NOLINK;
|
|
|
|
+ phy_link_down(phydev, false);
|
|
|
|
}
|
|
|
|
- phydev->adjust_link(phydev->attached_dev);
|
|
|
|
} else {
|
|
|
|
phydev->state = PHY_AN;
|
|
|
|
phydev->link_timeout = PHY_AN_TIMEOUT;
|
2017-08-17 08:51:05 +00:00
|
|
|
@@ -1176,11 +1178,11 @@ void phy_state_machine(struct work_struc
|
2017-02-06 10:46:48 +00:00
|
|
|
|
|
|
|
if (phydev->link) {
|
|
|
|
phydev->state = PHY_RUNNING;
|
|
|
|
- netif_carrier_on(phydev->attached_dev);
|
|
|
|
+ phy_link_up(phydev);
|
|
|
|
} else {
|
|
|
|
phydev->state = PHY_NOLINK;
|
|
|
|
+ phy_link_down(phydev, false);
|
|
|
|
}
|
|
|
|
- phydev->adjust_link(phydev->attached_dev);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
--- a/drivers/net/phy/phy_device.c
|
|
|
|
+++ b/drivers/net/phy/phy_device.c
|
|
|
|
@@ -645,6 +645,19 @@ struct phy_device *phy_find_first(struct
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL(phy_find_first);
|
|
|
|
|
|
|
|
+static void phy_link_change(struct phy_device *phydev, bool up, bool do_carrier)
|
|
|
|
+{
|
|
|
|
+ struct net_device *netdev = phydev->attached_dev;
|
|
|
|
+
|
|
|
|
+ if (do_carrier) {
|
|
|
|
+ if (up)
|
|
|
|
+ netif_carrier_on(netdev);
|
|
|
|
+ else
|
|
|
|
+ netif_carrier_off(netdev);
|
|
|
|
+ }
|
|
|
|
+ phydev->adjust_link(netdev);
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* phy_prepare_link - prepares the PHY layer to monitor link status
|
|
|
|
* @phydev: target phy_device struct
|
2017-06-26 09:22:11 +00:00
|
|
|
@@ -910,6 +923,7 @@ int phy_attach_direct(struct net_device
|
2017-02-06 10:46:48 +00:00
|
|
|
goto error;
|
|
|
|
}
|
|
|
|
|
|
|
|
+ phydev->phy_link_change = phy_link_change;
|
|
|
|
phydev->attached_dev = dev;
|
|
|
|
dev->phydev = phydev;
|
|
|
|
|
|
|
|
--- a/include/linux/phy.h
|
|
|
|
+++ b/include/linux/phy.h
|
2017-07-12 20:59:03 +00:00
|
|
|
@@ -429,6 +429,7 @@ struct phy_device {
|
2017-02-06 10:46:48 +00:00
|
|
|
|
|
|
|
u8 mdix;
|
|
|
|
|
|
|
|
+ void (*phy_link_change)(struct phy_device *, bool up, bool do_carrier);
|
|
|
|
void (*adjust_link)(struct net_device *dev);
|
|
|
|
};
|
|
|
|
#define to_phy_device(d) container_of(to_mdio_device(d), \
|