From 2e79cb303010d5d2b7810c11bc5d1f09a8500405 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Thu, 5 Dec 2013 14:52:10 -0800 Subject: net: of_mdio: factor PHY registration from of_mdiobus_register Since commit 779d835e ("net: of_mdio: scan mdiobus for PHYs without reg property") we have two foreach loops which do pretty much the same thing. Factor the PHY device registration in a function helper: of_mdiobus_register_phy() which takes care of the details and allows for future PHY specific extensions. Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller --- drivers/of/of_mdio.c | 109 ++++++++++++++++++++++----------------------------- 1 file changed, 46 insertions(+), 63 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index d5a57a9e329c..82485d2dac89 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -22,6 +22,47 @@ MODULE_AUTHOR("Grant Likely "); MODULE_LICENSE("GPL"); +static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *child, + u32 addr) +{ + struct phy_device *phy; + bool is_c45; + int rc; + + is_c45 = of_device_is_compatible(child, + "ethernet-phy-ieee802.3-c45"); + + phy = get_phy_device(mdio, addr, is_c45); + if (!phy || IS_ERR(phy)) + return 1; + + if (mdio->irq) { + mdio->irq[addr] = + irq_of_parse_and_map(child, 0); + if (!mdio->irq[addr]) + mdio->irq[addr] = PHY_POLL; + } + + /* Associate the OF node with the device structure so it + * can be looked up later */ + of_node_get(child); + phy->dev.of_node = child; + + /* All data is now stored in the phy struct; + * register it */ + rc = phy_device_register(phy); + if (rc) { + phy_device_free(phy); + of_node_put(child); + return 1; + } + + dev_dbg(&mdio->dev, "registered phy %s at address %i\n", + child->name, addr); + + return 0; +} + /** * of_mdiobus_register - Register mii_bus and create PHYs from the device tree * @mdio: pointer to mii_bus structure @@ -32,11 +73,10 @@ MODULE_LICENSE("GPL"); */ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) { - struct phy_device *phy; struct device_node *child; const __be32 *paddr; u32 addr; - bool is_c45, scanphys = false; + bool scanphys = false; int rc, i, len; /* Mask out all PHYs from auto probing. Instead the PHYs listed in @@ -73,38 +113,9 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) continue; } - if (mdio->irq) { - mdio->irq[addr] = irq_of_parse_and_map(child, 0); - if (!mdio->irq[addr]) - mdio->irq[addr] = PHY_POLL; - } - - is_c45 = of_device_is_compatible(child, - "ethernet-phy-ieee802.3-c45"); - phy = get_phy_device(mdio, addr, is_c45); - - if (!phy || IS_ERR(phy)) { - dev_err(&mdio->dev, - "cannot get PHY at address %i\n", - addr); - continue; - } - - /* Associate the OF node with the device structure so it - * can be looked up later */ - of_node_get(child); - phy->dev.of_node = child; - - /* All data is now stored in the phy struct; register it */ - rc = phy_device_register(phy); - if (rc) { - phy_device_free(phy); - of_node_put(child); + rc = of_mdiobus_register_phy(mdio, child, addr); + if (rc) continue; - } - - dev_dbg(&mdio->dev, "registered phy %s at address %i\n", - child->name, addr); } if (!scanphys) @@ -117,9 +128,6 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) if (paddr) continue; - is_c45 = of_device_is_compatible(child, - "ethernet-phy-ieee802.3-c45"); - for (addr = 0; addr < PHY_MAX_ADDR; addr++) { /* skip already registered PHYs */ if (mdio->phy_map[addr]) @@ -129,34 +137,9 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) dev_info(&mdio->dev, "scan phy %s at address %i\n", child->name, addr); - phy = get_phy_device(mdio, addr, is_c45); - if (!phy || IS_ERR(phy)) + rc = of_mdiobus_register_phy(mdio, child, addr); + if (rc) continue; - - if (mdio->irq) { - mdio->irq[addr] = - irq_of_parse_and_map(child, 0); - if (!mdio->irq[addr]) - mdio->irq[addr] = PHY_POLL; - } - - /* Associate the OF node with the device structure so it - * can be looked up later */ - of_node_get(child); - phy->dev.of_node = child; - - /* All data is now stored in the phy struct; - * register it */ - rc = phy_device_register(phy); - if (rc) { - phy_device_free(phy); - of_node_put(child); - continue; - } - - dev_info(&mdio->dev, "registered phy %s at address %i\n", - child->name, addr); - break; } } -- cgit v1.2.3 From bed2f9ed2f3c4debe2e930c44ee95af980db7e20 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Thu, 5 Dec 2013 14:52:11 -0800 Subject: net: of_mdio: use PHY_MAX_ADDR constant Use the PHY_MAX_ADDR constant for checking if a MDIO bus address is valid instead of using a plain "32". Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller --- drivers/of/of_mdio.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/of') diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index 82485d2dac89..f93ebca0fcb7 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -107,7 +107,7 @@ int of_mdiobus_register(struct mii_bus *mdio, struct device_node *np) } addr = be32_to_cpup(paddr); - if (addr >= 32) { + if (addr >= PHY_MAX_ADDR) { dev_err(&mdio->dev, "%s PHY address %i is too large\n", child->full_name, addr); continue; -- cgit v1.2.3 From 7d976376560b72e187c96e4b18d059e0a0f9eba5 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Thu, 5 Dec 2013 14:52:12 -0800 Subject: net: of_mdio: do not overwrite PHY interrupt configuration If irq_of_parse_and_map fails to find an interrupt line for a given PHY, we will force the PHY interrupt to be PHY_POLL, completely overriding the previous value that the MDIO bus may have set for us (e.g: PHY_IGNORE_INTERRUPT). In case of failure, just restore the previous value. Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller --- drivers/of/of_mdio.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/of') diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index f93ebca0fcb7..14feffc36964 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -27,7 +27,7 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi { struct phy_device *phy; bool is_c45; - int rc; + int rc, prev_irq; is_c45 = of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45"); @@ -37,10 +37,11 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi return 1; if (mdio->irq) { + prev_irq = mdio->irq[addr]; mdio->irq[addr] = irq_of_parse_and_map(child, 0); if (!mdio->irq[addr]) - mdio->irq[addr] = PHY_POLL; + mdio->irq[addr] = prev_irq; } /* Associate the OF node with the device structure so it -- cgit v1.2.3 From 8fdade4be755af17a3d205d07f594f939f173504 Mon Sep 17 00:00:00 2001 From: Florian Fainelli Date: Thu, 5 Dec 2013 14:52:14 -0800 Subject: net: of_mdio: parse "max-speed" property to set PHY supported features The "max-speed" property is defined per the ePAPR specification to express the maximum speed a PHY supports. Use that property, if present to set the phydev->supported features which properly restricts the PHY within the range of defined speeds. Signed-off-by: Florian Fainelli Signed-off-by: David S. Miller --- drivers/of/of_mdio.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'drivers/of') diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index 14feffc36964..a43b8523c61e 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -22,12 +22,30 @@ MODULE_AUTHOR("Grant Likely "); MODULE_LICENSE("GPL"); +static void of_set_phy_supported(struct phy_device *phydev, u32 max_speed) +{ + phydev->supported |= PHY_DEFAULT_FEATURES; + + switch (max_speed) { + default: + return; + + case SPEED_1000: + phydev->supported |= PHY_1000BT_FEATURES; + case SPEED_100: + phydev->supported |= PHY_100BT_FEATURES; + case SPEED_10: + phydev->supported |= PHY_10BT_FEATURES; + } +} + static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *child, u32 addr) { struct phy_device *phy; bool is_c45; int rc, prev_irq; + u32 max_speed = 0; is_c45 = of_device_is_compatible(child, "ethernet-phy-ieee802.3-c45"); @@ -58,8 +76,13 @@ static int of_mdiobus_register_phy(struct mii_bus *mdio, struct device_node *chi return 1; } + /* Set phydev->supported based on the "max-speed" property + * if present */ + if (!of_property_read_u32(child, "max-speed", &max_speed)) + of_set_phy_supported(phy, max_speed); + dev_dbg(&mdio->dev, "registered phy %s at address %i\n", - child->name, addr); + child->name, addr); return 0; } -- cgit v1.2.3 From 898dd0bda366edd0b077db4389a26c00509c73c9 Mon Sep 17 00:00:00 2001 From: Andy Fleming Date: Fri, 10 Jan 2014 14:26:46 +0800 Subject: phylib: introduce PHY_INTERFACE_MODE_XGMII for 10G PHY Signed-off-by: Andy Fleming Signed-off-by: Shaohui Xie Acked-by: Florian Fainelli Signed-off-by: David S. Miller --- drivers/of/of_net.c | 1 + include/linux/phy.h | 1 + 2 files changed, 2 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/of_net.c b/drivers/of/of_net.c index 8f9be2e09937..a208a457558c 100644 --- a/drivers/of/of_net.c +++ b/drivers/of/of_net.c @@ -30,6 +30,7 @@ static const char *phy_modes[] = { [PHY_INTERFACE_MODE_RGMII_TXID] = "rgmii-txid", [PHY_INTERFACE_MODE_RTBI] = "rtbi", [PHY_INTERFACE_MODE_SMII] = "smii", + [PHY_INTERFACE_MODE_XGMII] = "xgmii", }; /** diff --git a/include/linux/phy.h b/include/linux/phy.h index 3eda43c90875..a9685b109049 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -73,6 +73,7 @@ typedef enum { PHY_INTERFACE_MODE_RGMII_TXID, PHY_INTERFACE_MODE_RTBI, PHY_INTERFACE_MODE_SMII, + PHY_INTERFACE_MODE_XGMII, } phy_interface_t; -- cgit v1.2.3 From 7614aba6a330a6c4937edc24fd4c6a935c1ae703 Mon Sep 17 00:00:00 2001 From: Andy Fleming Date: Fri, 10 Jan 2014 14:28:11 +0800 Subject: phylib: Add of_phy_attach 10G PHYs don't currently support running the state machine, which is implicitly setup via of_phy_connect(). Therefore, it is necessary to implement an OF version of phy_attach(), which does everything except start the state machine. Signed-off-by: Andy Fleming Signed-off-by: Shaohui Xie Acked-by: Florian Fainelli Signed-off-by: David S. Miller --- drivers/of/of_mdio.c | 20 ++++++++++++++++++++ include/linux/of_mdio.h | 10 ++++++++++ 2 files changed, 30 insertions(+) (limited to 'drivers/of') diff --git a/drivers/of/of_mdio.c b/drivers/of/of_mdio.c index a43b8523c61e..875b7b6f0d2a 100644 --- a/drivers/of/of_mdio.c +++ b/drivers/of/of_mdio.c @@ -254,3 +254,23 @@ struct phy_device *of_phy_connect_fixed_link(struct net_device *dev, return IS_ERR(phy) ? NULL : phy; } EXPORT_SYMBOL(of_phy_connect_fixed_link); + +/** + * of_phy_attach - Attach to a PHY without starting the state machine + * @dev: pointer to net_device claiming the phy + * @phy_np: Node pointer for the PHY + * @flags: flags to pass to the PHY + * @iface: PHY data interface type + */ +struct phy_device *of_phy_attach(struct net_device *dev, + struct device_node *phy_np, u32 flags, + phy_interface_t iface) +{ + struct phy_device *phy = of_phy_find_device(phy_np); + + if (!phy) + return NULL; + + return phy_attach_direct(dev, phy, flags, iface) ? NULL : phy; +} +EXPORT_SYMBOL(of_phy_attach); diff --git a/include/linux/of_mdio.h b/include/linux/of_mdio.h index 8163107b94b4..6fe8464ed767 100644 --- a/include/linux/of_mdio.h +++ b/include/linux/of_mdio.h @@ -19,6 +19,9 @@ extern struct phy_device *of_phy_connect(struct net_device *dev, struct device_node *phy_np, void (*hndlr)(struct net_device *), u32 flags, phy_interface_t iface); +struct phy_device *of_phy_attach(struct net_device *dev, + struct device_node *phy_np, u32 flags, + phy_interface_t iface); extern struct phy_device *of_phy_connect_fixed_link(struct net_device *dev, void (*hndlr)(struct net_device *), phy_interface_t iface); @@ -44,6 +47,13 @@ static inline struct phy_device *of_phy_connect(struct net_device *dev, return NULL; } +static inline struct phy_device *of_phy_attach(struct net_device *dev, + struct device_node *phy_np, + u32 flags, phy_interface_t iface) +{ + return NULL; +} + static inline struct phy_device *of_phy_connect_fixed_link(struct net_device *dev, void (*hndlr)(struct net_device *), phy_interface_t iface) -- cgit v1.2.3