Skip to content

Commit f3a6bd3

Browse files
hormsdavem330
authored andcommitted
phylib: Add phy_set_max_speed helper
Add a helper to allow ethernet drivers to limit the speed of a phy (that they are attached to). This mainly involves factoring out the business-end of of_set_phy_supported() and exporting a new symbol. This code seems to be open coded in several places, in several different variants. It is is envisaged that this will be used in situations where setting the "max-speed" property in DT is not appropriate, e.g. because the maximum speed is not a property of the phy hardware. Signed-off-by: Simon Horman <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f8e1100 commit f3a6bd3

File tree

2 files changed

+41
-19
lines changed

2 files changed

+41
-19
lines changed

drivers/net/phy/phy_device.c

Lines changed: 40 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1239,6 +1239,44 @@ static int gen10g_resume(struct phy_device *phydev)
12391239
return 0;
12401240
}
12411241

1242+
static int __set_phy_supported(struct phy_device *phydev, u32 max_speed)
1243+
{
1244+
/* The default values for phydev->supported are provided by the PHY
1245+
* driver "features" member, we want to reset to sane defaults first
1246+
* before supporting higher speeds.
1247+
*/
1248+
phydev->supported &= PHY_DEFAULT_FEATURES;
1249+
1250+
switch (max_speed) {
1251+
default:
1252+
return -ENOTSUPP;
1253+
case SPEED_1000:
1254+
phydev->supported |= PHY_1000BT_FEATURES;
1255+
/* fall through */
1256+
case SPEED_100:
1257+
phydev->supported |= PHY_100BT_FEATURES;
1258+
/* fall through */
1259+
case SPEED_10:
1260+
phydev->supported |= PHY_10BT_FEATURES;
1261+
}
1262+
1263+
return 0;
1264+
}
1265+
1266+
int phy_set_max_speed(struct phy_device *phydev, u32 max_speed)
1267+
{
1268+
int err;
1269+
1270+
err = __set_phy_supported(phydev, max_speed);
1271+
if (err)
1272+
return err;
1273+
1274+
phydev->advertising = phydev->supported;
1275+
1276+
return 0;
1277+
}
1278+
EXPORT_SYMBOL(phy_set_max_speed);
1279+
12421280
static void of_set_phy_supported(struct phy_device *phydev)
12431281
{
12441282
struct device_node *node = phydev->dev.of_node;
@@ -1250,25 +1288,8 @@ static void of_set_phy_supported(struct phy_device *phydev)
12501288
if (!node)
12511289
return;
12521290

1253-
if (!of_property_read_u32(node, "max-speed", &max_speed)) {
1254-
/* The default values for phydev->supported are provided by the PHY
1255-
* driver "features" member, we want to reset to sane defaults fist
1256-
* before supporting higher speeds.
1257-
*/
1258-
phydev->supported &= PHY_DEFAULT_FEATURES;
1259-
1260-
switch (max_speed) {
1261-
default:
1262-
return;
1263-
1264-
case SPEED_1000:
1265-
phydev->supported |= PHY_1000BT_FEATURES;
1266-
case SPEED_100:
1267-
phydev->supported |= PHY_100BT_FEATURES;
1268-
case SPEED_10:
1269-
phydev->supported |= PHY_10BT_FEATURES;
1270-
}
1271-
}
1291+
if (!of_property_read_u32(node, "max-speed", &max_speed))
1292+
__set_phy_supported(phydev, max_speed);
12721293
}
12731294

12741295
/**

include/linux/phy.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,7 @@ int phy_mii_ioctl(struct phy_device *phydev, struct ifreq *ifr, int cmd);
798798
int phy_start_interrupts(struct phy_device *phydev);
799799
void phy_print_status(struct phy_device *phydev);
800800
void phy_device_free(struct phy_device *phydev);
801+
int phy_set_max_speed(struct phy_device *phydev, u32 max_speed);
801802

802803
int phy_register_fixup(const char *bus_id, u32 phy_uid, u32 phy_uid_mask,
803804
int (*run)(struct phy_device *));

0 commit comments

Comments
 (0)