| b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 0db7fba746b5608c30d4e2ba1c99a2a309e2d288 Mon Sep 17 00:00:00 2001 |
| 2 | From: Russell King <rmk+kernel@armlinux.org.uk> |
| 3 | Date: Fri, 8 Nov 2019 15:22:48 +0000 |
| 4 | Subject: [PATCH 649/660] net: phylink: re-split __phylink_connect_phy() |
| 5 | |
| 6 | In order to support Clause 45 PHYs on SFP+ modules, which have an |
| 7 | indeterminant phy interface mode, we need to be able to call |
| 8 | phylink_bringup_phy() with a different interface mode to that used when |
| 9 | binding the PHY. Reduce __phylink_connect_phy() to an attach operation, |
| 10 | and move the call to phylink_bringup_phy() to its call sites. |
| 11 | |
| 12 | Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> |
| 13 | --- |
| 14 | drivers/net/phy/phylink.c | 39 ++++++++++++++++++++++++--------------- |
| 15 | 1 file changed, 24 insertions(+), 15 deletions(-) |
| 16 | |
| 17 | --- a/drivers/net/phy/phylink.c |
| 18 | +++ b/drivers/net/phy/phylink.c |
| 19 | @@ -765,11 +765,9 @@ static int phylink_bringup_phy(struct ph |
| 20 | return 0; |
| 21 | } |
| 22 | |
| 23 | -static int __phylink_connect_phy(struct phylink *pl, struct phy_device *phy, |
| 24 | - phy_interface_t interface) |
| 25 | +static int phylink_attach_phy(struct phylink *pl, struct phy_device *phy, |
| 26 | + phy_interface_t interface) |
| 27 | { |
| 28 | - int ret; |
| 29 | - |
| 30 | if (WARN_ON(pl->link_an_mode == MLO_AN_FIXED || |
| 31 | (pl->link_an_mode == MLO_AN_INBAND && |
| 32 | phy_interface_mode_is_8023z(interface)))) |
| 33 | @@ -778,15 +776,7 @@ static int __phylink_connect_phy(struct |
| 34 | if (pl->phydev) |
| 35 | return -EBUSY; |
| 36 | |
| 37 | - ret = phy_attach_direct(pl->netdev, phy, 0, interface); |
| 38 | - if (ret) |
| 39 | - return ret; |
| 40 | - |
| 41 | - ret = phylink_bringup_phy(pl, phy); |
| 42 | - if (ret) |
| 43 | - phy_detach(phy); |
| 44 | - |
| 45 | - return ret; |
| 46 | + return phy_attach_direct(pl->netdev, phy, 0, interface); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | @@ -806,13 +796,23 @@ static int __phylink_connect_phy(struct |
| 51 | */ |
| 52 | int phylink_connect_phy(struct phylink *pl, struct phy_device *phy) |
| 53 | { |
| 54 | + int ret; |
| 55 | + |
| 56 | /* Use PHY device/driver interface */ |
| 57 | if (pl->link_interface == PHY_INTERFACE_MODE_NA) { |
| 58 | pl->link_interface = phy->interface; |
| 59 | pl->link_config.interface = pl->link_interface; |
| 60 | } |
| 61 | |
| 62 | - return __phylink_connect_phy(pl, phy, pl->link_interface); |
| 63 | + ret = phylink_attach_phy(pl, phy, pl->link_interface); |
| 64 | + if (ret < 0) |
| 65 | + return ret; |
| 66 | + |
| 67 | + ret = phylink_bringup_phy(pl, phy); |
| 68 | + if (ret) |
| 69 | + phy_detach(phy); |
| 70 | + |
| 71 | + return ret; |
| 72 | } |
| 73 | EXPORT_SYMBOL_GPL(phylink_connect_phy); |
| 74 | |
| 75 | @@ -1814,8 +1814,17 @@ static void phylink_sfp_link_up(void *up |
| 76 | static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy) |
| 77 | { |
| 78 | struct phylink *pl = upstream; |
| 79 | + int ret; |
| 80 | |
| 81 | - return __phylink_connect_phy(upstream, phy, pl->link_config.interface); |
| 82 | + ret = phylink_attach_phy(pl, phy, pl->link_config.interface); |
| 83 | + if (ret < 0) |
| 84 | + return ret; |
| 85 | + |
| 86 | + ret = phylink_bringup_phy(pl, phy); |
| 87 | + if (ret) |
| 88 | + phy_detach(phy); |
| 89 | + |
| 90 | + return ret; |
| 91 | } |
| 92 | |
| 93 | static void phylink_sfp_disconnect_phy(void *upstream) |