Skip to content

Commit 4e8386f

Browse files
committed
Merge branch 'phy_check_downshift'
Heiner Kallweit says: ==================== net: phy: add and use phy_check_downshift So far PHY drivers have to check whether a downshift occurred to be able to notify the user. To make life of drivers authors a little bit easier move the downshift notification to phylib. phy_check_downshift() compares the highest mutually advertised speed with the actual value of phydev->speed (typically read by the PHY driver from a vendor-specific register) to detect a downshift. v2: Add downshift hint to phy_print_status(). ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents f4d3e61 + 1ec32eb commit 4e8386f

5 files changed

Lines changed: 45 additions & 49 deletions

File tree

‎drivers/net/phy/aquantia_main.c‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -290,17 +290,6 @@ static int aqr_read_status(struct phy_device *phydev)
290290
return genphy_c45_read_status(phydev);
291291
}
292292

293-
static int aqr107_read_downshift_event(struct phy_device *phydev)
294-
{
295-
int val;
296-
297-
val = phy_read_mmd(phydev, MDIO_MMD_AN, MDIO_AN_TX_VEND_INT_STATUS1);
298-
if (val < 0)
299-
return val;
300-
301-
return !!(val & MDIO_AN_TX_VEND_INT_STATUS1_DOWNSHIFT);
302-
}
303-
304293
static int aqr107_read_rate(struct phy_device *phydev)
305294
{
306295
int val;
@@ -377,13 +366,7 @@ static int aqr107_read_status(struct phy_device *phydev)
377366
break;
378367
}
379368

380-
val = aqr107_read_downshift_event(phydev);
381-
if (val <= 0)
382-
return val;
383-
384-
phydev_warn(phydev, "Downshift occurred! Cabling may be defective.\n");
385-
386-
/* Read downshifted rate from vendor register */
369+
/* Read possibly downshifted rate from vendor register */
387370
return aqr107_read_rate(phydev);
388371
}
389372

@@ -506,9 +489,6 @@ static int aqr107_config_init(struct phy_device *phydev)
506489
if (!ret)
507490
aqr107_chip_info(phydev);
508491

509-
/* ensure that a latched downshift event is cleared */
510-
aqr107_read_downshift_event(phydev);
511-
512492
return aqr107_set_downshift(phydev, MDIO_AN_VEND_PROV_DOWNSHIFT_DFLT);
513493
}
514494

@@ -533,9 +513,6 @@ static int aqcs109_config_init(struct phy_device *phydev)
533513
if (ret)
534514
return ret;
535515

536-
/* ensure that a latched downshift event is cleared */
537-
aqr107_read_downshift_event(phydev);
538-
539516
return aqr107_set_downshift(phydev, MDIO_AN_VEND_PROV_DOWNSHIFT_DFLT);
540517
}
541518

‎drivers/net/phy/marvell.c‎

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -867,21 +867,6 @@ static int m88e1011_set_tunable(struct phy_device *phydev,
867867
}
868868
}
869869

870-
static void m88e1011_link_change_notify(struct phy_device *phydev)
871-
{
872-
int status;
873-
874-
if (phydev->state != PHY_RUNNING)
875-
return;
876-
877-
/* we may be on fiber page currently */
878-
status = phy_read_paged(phydev, MII_MARVELL_COPPER_PAGE,
879-
MII_M1011_PHY_SSR);
880-
881-
if (status > 0 && status & MII_M1011_PHY_SSR_DOWNSHIFT)
882-
phydev_warn(phydev, "Downshift occurred! Cabling may be defective.\n");
883-
}
884-
885870
static int m88e1116r_config_init(struct phy_device *phydev)
886871
{
887872
int err;
@@ -2201,7 +2186,6 @@ static struct phy_driver marvell_drivers[] = {
22012186
.get_stats = marvell_get_stats,
22022187
.get_tunable = m88e1011_get_tunable,
22032188
.set_tunable = m88e1011_set_tunable,
2204-
.link_change_notify = m88e1011_link_change_notify,
22052189
},
22062190
{
22072191
.phy_id = MARVELL_PHY_ID_88E1111,
@@ -2223,7 +2207,6 @@ static struct phy_driver marvell_drivers[] = {
22232207
.get_stats = marvell_get_stats,
22242208
.get_tunable = m88e1111_get_tunable,
22252209
.set_tunable = m88e1111_set_tunable,
2226-
.link_change_notify = m88e1011_link_change_notify,
22272210
},
22282211
{
22292212
.phy_id = MARVELL_PHY_ID_88E1118,
@@ -2264,7 +2247,6 @@ static struct phy_driver marvell_drivers[] = {
22642247
.get_stats = marvell_get_stats,
22652248
.get_tunable = m88e1011_get_tunable,
22662249
.set_tunable = m88e1011_set_tunable,
2267-
.link_change_notify = m88e1011_link_change_notify,
22682250
},
22692251
{
22702252
.phy_id = MARVELL_PHY_ID_88E1318S,
@@ -2308,7 +2290,6 @@ static struct phy_driver marvell_drivers[] = {
23082290
.get_stats = marvell_get_stats,
23092291
.get_tunable = m88e1111_get_tunable,
23102292
.set_tunable = m88e1111_set_tunable,
2311-
.link_change_notify = m88e1011_link_change_notify,
23122293
},
23132294
{
23142295
.phy_id = MARVELL_PHY_ID_88E1149R,
@@ -2364,7 +2345,6 @@ static struct phy_driver marvell_drivers[] = {
23642345
.get_stats = marvell_get_stats,
23652346
.get_tunable = m88e1011_get_tunable,
23662347
.set_tunable = m88e1011_set_tunable,
2367-
.link_change_notify = m88e1011_link_change_notify,
23682348
},
23692349
{
23702350
.phy_id = MARVELL_PHY_ID_88E1510,
@@ -2390,7 +2370,6 @@ static struct phy_driver marvell_drivers[] = {
23902370
.set_loopback = genphy_loopback,
23912371
.get_tunable = m88e1011_get_tunable,
23922372
.set_tunable = m88e1011_set_tunable,
2393-
.link_change_notify = m88e1011_link_change_notify,
23942373
},
23952374
{
23962375
.phy_id = MARVELL_PHY_ID_88E1540,
@@ -2413,7 +2392,6 @@ static struct phy_driver marvell_drivers[] = {
24132392
.get_stats = marvell_get_stats,
24142393
.get_tunable = m88e1540_get_tunable,
24152394
.set_tunable = m88e1540_set_tunable,
2416-
.link_change_notify = m88e1011_link_change_notify,
24172395
},
24182396
{
24192397
.phy_id = MARVELL_PHY_ID_88E1545,
@@ -2436,7 +2414,6 @@ static struct phy_driver marvell_drivers[] = {
24362414
.get_stats = marvell_get_stats,
24372415
.get_tunable = m88e1540_get_tunable,
24382416
.set_tunable = m88e1540_set_tunable,
2439-
.link_change_notify = m88e1011_link_change_notify,
24402417
},
24412418
{
24422419
.phy_id = MARVELL_PHY_ID_88E3016,
@@ -2479,7 +2456,6 @@ static struct phy_driver marvell_drivers[] = {
24792456
.get_stats = marvell_get_stats,
24802457
.get_tunable = m88e1540_get_tunable,
24812458
.set_tunable = m88e1540_set_tunable,
2482-
.link_change_notify = m88e1011_link_change_notify,
24832459
},
24842460
};
24852461

‎drivers/net/phy/phy-core.c‎

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,44 @@ void phy_resolve_aneg_linkmode(struct phy_device *phydev)
329329
}
330330
EXPORT_SYMBOL_GPL(phy_resolve_aneg_linkmode);
331331

332+
/**
333+
* phy_check_downshift - check whether downshift occurred
334+
* @phydev: The phy_device struct
335+
*
336+
* Check whether a downshift to a lower speed occurred. If this should be the
337+
* case warn the user.
338+
* Prerequisite for detecting downshift is that PHY driver implements the
339+
* read_status callback and sets phydev->speed to the actual link speed.
340+
*/
341+
void phy_check_downshift(struct phy_device *phydev)
342+
{
343+
__ETHTOOL_DECLARE_LINK_MODE_MASK(common);
344+
int i, speed = SPEED_UNKNOWN;
345+
346+
phydev->downshifted_rate = 0;
347+
348+
if (phydev->autoneg == AUTONEG_DISABLE ||
349+
phydev->speed == SPEED_UNKNOWN)
350+
return;
351+
352+
linkmode_and(common, phydev->lp_advertising, phydev->advertising);
353+
354+
for (i = 0; i < ARRAY_SIZE(settings); i++)
355+
if (test_bit(settings[i].bit, common)) {
356+
speed = settings[i].speed;
357+
break;
358+
}
359+
360+
if (speed == SPEED_UNKNOWN || phydev->speed >= speed)
361+
return;
362+
363+
phydev_warn(phydev, "Downshift occurred from negotiated speed %s to actual speed %s, check cabling!\n",
364+
phy_speed_to_str(speed), phy_speed_to_str(phydev->speed));
365+
366+
phydev->downshifted_rate = 1;
367+
}
368+
EXPORT_SYMBOL_GPL(phy_check_downshift);
369+
332370
static int phy_resolve_min_speed(struct phy_device *phydev, bool fdx_only)
333371
{
334372
__ETHTOOL_DECLARE_LINK_MODE_MASK(common);

‎drivers/net/phy/phy.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,10 @@ void phy_print_status(struct phy_device *phydev)
9696
{
9797
if (phydev->link) {
9898
netdev_info(phydev->attached_dev,
99-
"Link is Up - %s/%s - flow control %s\n",
99+
"Link is Up - %s/%s %s- flow control %s\n",
100100
phy_speed_to_str(phydev->speed),
101101
phy_duplex_to_str(phydev->duplex),
102+
phydev->downshifted_rate ? "(downshifted) " : "",
102103
phy_pause_str(phydev));
103104
} else {
104105
netdev_info(phydev->attached_dev, "Link is Down\n");
@@ -507,6 +508,7 @@ static int phy_check_link_status(struct phy_device *phydev)
507508
return err;
508509

509510
if (phydev->link && phydev->state != PHY_RUNNING) {
511+
phy_check_downshift(phydev);
510512
phydev->state = PHY_RUNNING;
511513
phy_link_up(phydev);
512514
} else if (!phydev->link && phydev->state != PHY_NOLINK) {

‎include/linux/phy.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ struct macsec_ops;
365365
* suspended_by_mdio_bus: Set to true if this phy was suspended by MDIO bus.
366366
* sysfs_links: Internal boolean tracking sysfs symbolic links setup/removal.
367367
* loopback_enabled: Set true if this phy has been loopbacked successfully.
368+
* downshifted_rate: Set true if link speed has been downshifted.
368369
* state: state of the PHY for management purposes
369370
* dev_flags: Device-specific flags used by the PHY driver.
370371
* irq: IRQ number of the PHY's interrupt (-1 if none)
@@ -405,6 +406,7 @@ struct phy_device {
405406
unsigned suspended_by_mdio_bus:1;
406407
unsigned sysfs_links:1;
407408
unsigned loopback_enabled:1;
409+
unsigned downshifted_rate:1;
408410

409411
unsigned autoneg:1;
410412
/* The most recently read link state */
@@ -698,6 +700,7 @@ static inline bool phy_is_started(struct phy_device *phydev)
698700

699701
void phy_resolve_aneg_pause(struct phy_device *phydev);
700702
void phy_resolve_aneg_linkmode(struct phy_device *phydev);
703+
void phy_check_downshift(struct phy_device *phydev);
701704

702705
/**
703706
* phy_read - Convenience function for reading a given PHY register

0 commit comments

Comments
 (0)