Skip to content

Commit 7e41837

Browse files
baruchsiachdavem330
authored andcommitted
net: phy: phylink: fix SFP interface autodetection
When connecting SFP PHY to phylink use the detected interface. Otherwise, the link fails to come up when the configured 'phy-mode' differs from the SFP detected mode. Move most of phylink_connect_phy() into __phylink_connect_phy(), and leave phylink_connect_phy() as a wrapper. phylink_sfp_connect_phy() can now pass the SFP detected PHY interface to __phylink_connect_phy(). This fixes 1GB SFP module link up on eth3 of the Macchiatobin board that is configured in the DT to "2500base-x" phy-mode. Fixes: 9525ae8 ("phylink: add phylink infrastructure") Suggested-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: Baruch Siach <baruch@tkos.co.il> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2d52527 commit 7e41837

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

drivers/net/phy/phylink.c

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,30 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy)
717717
return 0;
718718
}
719719

720+
static int __phylink_connect_phy(struct phylink *pl, struct phy_device *phy,
721+
phy_interface_t interface)
722+
{
723+
int ret;
724+
725+
if (WARN_ON(pl->link_an_mode == MLO_AN_FIXED ||
726+
(pl->link_an_mode == MLO_AN_INBAND &&
727+
phy_interface_mode_is_8023z(interface))))
728+
return -EINVAL;
729+
730+
if (pl->phydev)
731+
return -EBUSY;
732+
733+
ret = phy_attach_direct(pl->netdev, phy, 0, interface);
734+
if (ret)
735+
return ret;
736+
737+
ret = phylink_bringup_phy(pl, phy);
738+
if (ret)
739+
phy_detach(phy);
740+
741+
return ret;
742+
}
743+
720744
/**
721745
* phylink_connect_phy() - connect a PHY to the phylink instance
722746
* @pl: a pointer to a &struct phylink returned from phylink_create()
@@ -734,31 +758,13 @@ static int phylink_bringup_phy(struct phylink *pl, struct phy_device *phy)
734758
*/
735759
int phylink_connect_phy(struct phylink *pl, struct phy_device *phy)
736760
{
737-
int ret;
738-
739-
if (WARN_ON(pl->link_an_mode == MLO_AN_FIXED ||
740-
(pl->link_an_mode == MLO_AN_INBAND &&
741-
phy_interface_mode_is_8023z(pl->link_interface))))
742-
return -EINVAL;
743-
744-
if (pl->phydev)
745-
return -EBUSY;
746-
747761
/* Use PHY device/driver interface */
748762
if (pl->link_interface == PHY_INTERFACE_MODE_NA) {
749763
pl->link_interface = phy->interface;
750764
pl->link_config.interface = pl->link_interface;
751765
}
752766

753-
ret = phy_attach_direct(pl->netdev, phy, 0, pl->link_interface);
754-
if (ret)
755-
return ret;
756-
757-
ret = phylink_bringup_phy(pl, phy);
758-
if (ret)
759-
phy_detach(phy);
760-
761-
return ret;
767+
return __phylink_connect_phy(pl, phy, pl->link_interface);
762768
}
763769
EXPORT_SYMBOL_GPL(phylink_connect_phy);
764770

@@ -1672,7 +1678,9 @@ static void phylink_sfp_link_up(void *upstream)
16721678

16731679
static int phylink_sfp_connect_phy(void *upstream, struct phy_device *phy)
16741680
{
1675-
return phylink_connect_phy(upstream, phy);
1681+
struct phylink *pl = upstream;
1682+
1683+
return __phylink_connect_phy(upstream, phy, pl->link_config.interface);
16761684
}
16771685

16781686
static void phylink_sfp_disconnect_phy(void *upstream)

0 commit comments

Comments
 (0)