Skip to content

Commit b80b376

Browse files
committed
Merge branch 'phy_power'
Sebastian Hesselbarth says: ==================== net: phy: Ethernet PHY powerdown optimization This is v2 of the ethernet PHY power optimization patches to reduce power consumption of network PHYs with link that are either unused or the corresponding netdev is down. Compared to the last version, this patch set drops a patch to disable unused PHYs after late initcall, as it is not compatible with a modular mdio bus [1]. I'll investigate different ways to have a modular mdio bus driver get notified when driver loading is done. Again, a branch with v2 applied to v3.13-rc2 can also be found at https://github.com/shesselba/linux-dove.git topic/ethphy-power-v2 [1] http://www.spinics.net/lists/arm-kernel/msg293028.html ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
2 parents be78cfc + be9dad1 commit b80b376

5 files changed

Lines changed: 59 additions & 2 deletions

File tree

‎drivers/net/ethernet/marvell/mv643xx_eth.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2080,6 +2080,7 @@ static void port_start(struct mv643xx_eth_private *mp)
20802080
mv643xx_eth_get_settings(mp->dev, &cmd);
20812081
phy_init_hw(mp->phy);
20822082
mv643xx_eth_set_settings(mp->dev, &cmd);
2083+
phy_start(mp->phy);
20832084
}
20842085

20852086
/*
@@ -2275,7 +2276,8 @@ static int mv643xx_eth_stop(struct net_device *dev)
22752276
del_timer_sync(&mp->rx_oom);
22762277

22772278
netif_carrier_off(dev);
2278-
2279+
if (mp->phy)
2280+
phy_stop(mp->phy);
22792281
free_irq(dev->irq, dev);
22802282

22812283
port_reset(mp);

‎drivers/net/phy/marvell.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -894,6 +894,8 @@ static struct phy_driver marvell_drivers[] = {
894894
.read_status = &genphy_read_status,
895895
.ack_interrupt = &marvell_ack_interrupt,
896896
.config_intr = &marvell_config_intr,
897+
.resume = &genphy_resume,
898+
.suspend = &genphy_suspend,
897899
.driver = { .owner = THIS_MODULE },
898900
},
899901
{
@@ -907,6 +909,8 @@ static struct phy_driver marvell_drivers[] = {
907909
.read_status = &genphy_read_status,
908910
.ack_interrupt = &marvell_ack_interrupt,
909911
.config_intr = &marvell_config_intr,
912+
.resume = &genphy_resume,
913+
.suspend = &genphy_suspend,
910914
.driver = { .owner = THIS_MODULE },
911915
},
912916
{
@@ -920,6 +924,8 @@ static struct phy_driver marvell_drivers[] = {
920924
.read_status = &marvell_read_status,
921925
.ack_interrupt = &marvell_ack_interrupt,
922926
.config_intr = &marvell_config_intr,
927+
.resume = &genphy_resume,
928+
.suspend = &genphy_suspend,
923929
.driver = { .owner = THIS_MODULE },
924930
},
925931
{
@@ -933,6 +939,8 @@ static struct phy_driver marvell_drivers[] = {
933939
.read_status = &genphy_read_status,
934940
.ack_interrupt = &marvell_ack_interrupt,
935941
.config_intr = &marvell_config_intr,
942+
.resume = &genphy_resume,
943+
.suspend = &genphy_suspend,
936944
.driver = {.owner = THIS_MODULE,},
937945
},
938946
{
@@ -946,6 +954,8 @@ static struct phy_driver marvell_drivers[] = {
946954
.ack_interrupt = &marvell_ack_interrupt,
947955
.config_intr = &marvell_config_intr,
948956
.did_interrupt = &m88e1121_did_interrupt,
957+
.resume = &genphy_resume,
958+
.suspend = &genphy_suspend,
949959
.driver = { .owner = THIS_MODULE },
950960
},
951961
{
@@ -961,6 +971,8 @@ static struct phy_driver marvell_drivers[] = {
961971
.did_interrupt = &m88e1121_did_interrupt,
962972
.get_wol = &m88e1318_get_wol,
963973
.set_wol = &m88e1318_set_wol,
974+
.resume = &genphy_resume,
975+
.suspend = &genphy_suspend,
964976
.driver = { .owner = THIS_MODULE },
965977
},
966978
{
@@ -974,6 +986,8 @@ static struct phy_driver marvell_drivers[] = {
974986
.read_status = &genphy_read_status,
975987
.ack_interrupt = &marvell_ack_interrupt,
976988
.config_intr = &marvell_config_intr,
989+
.resume = &genphy_resume,
990+
.suspend = &genphy_suspend,
977991
.driver = { .owner = THIS_MODULE },
978992
},
979993
{
@@ -987,6 +1001,8 @@ static struct phy_driver marvell_drivers[] = {
9871001
.read_status = &genphy_read_status,
9881002
.ack_interrupt = &marvell_ack_interrupt,
9891003
.config_intr = &marvell_config_intr,
1004+
.resume = &genphy_resume,
1005+
.suspend = &genphy_suspend,
9901006
.driver = { .owner = THIS_MODULE },
9911007
},
9921008
{
@@ -1000,6 +1016,8 @@ static struct phy_driver marvell_drivers[] = {
10001016
.read_status = &genphy_read_status,
10011017
.ack_interrupt = &marvell_ack_interrupt,
10021018
.config_intr = &marvell_config_intr,
1019+
.resume = &genphy_resume,
1020+
.suspend = &genphy_suspend,
10031021
.driver = { .owner = THIS_MODULE },
10041022
},
10051023
{
@@ -1013,6 +1031,8 @@ static struct phy_driver marvell_drivers[] = {
10131031
.read_status = &genphy_read_status,
10141032
.ack_interrupt = &marvell_ack_interrupt,
10151033
.config_intr = &marvell_config_intr,
1034+
.resume = &genphy_resume,
1035+
.suspend = &genphy_suspend,
10161036
.driver = { .owner = THIS_MODULE },
10171037
},
10181038
{
@@ -1026,6 +1046,8 @@ static struct phy_driver marvell_drivers[] = {
10261046
.ack_interrupt = &marvell_ack_interrupt,
10271047
.config_intr = &marvell_config_intr,
10281048
.did_interrupt = &m88e1121_did_interrupt,
1049+
.resume = &genphy_resume,
1050+
.suspend = &genphy_suspend,
10291051
.driver = { .owner = THIS_MODULE },
10301052
},
10311053
};

‎drivers/net/phy/phy.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ void phy_state_machine(struct work_struct *work)
739739
struct delayed_work *dwork = to_delayed_work(work);
740740
struct phy_device *phydev =
741741
container_of(dwork, struct phy_device, state_queue);
742-
int needs_aneg = 0;
742+
int needs_aneg = 0, do_suspend = 0;
743743
int err = 0;
744744

745745
mutex_lock(&phydev->lock);
@@ -854,6 +854,7 @@ void phy_state_machine(struct work_struct *work)
854854
phydev->link = 0;
855855
netif_carrier_off(phydev->attached_dev);
856856
phydev->adjust_link(phydev->attached_dev);
857+
do_suspend = 1;
857858
}
858859
break;
859860
case PHY_RESUMING:
@@ -912,6 +913,9 @@ void phy_state_machine(struct work_struct *work)
912913
if (needs_aneg)
913914
err = phy_start_aneg(phydev);
914915

916+
if (do_suspend)
917+
phy_suspend(phydev);
918+
915919
if (err < 0)
916920
phy_error(phydev);
917921

‎drivers/net/phy/phy_device.c‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,6 +624,8 @@ static int phy_attach_direct(struct net_device *dev, struct phy_device *phydev,
624624
if (err)
625625
phy_detach(phydev);
626626

627+
phy_resume(phydev);
628+
627629
return err;
628630
}
629631

@@ -669,6 +671,7 @@ void phy_detach(struct phy_device *phydev)
669671
{
670672
phydev->attached_dev->phydev = NULL;
671673
phydev->attached_dev = NULL;
674+
phy_suspend(phydev);
672675

673676
/* If the device had no specific driver before (i.e. - it
674677
* was using the generic driver), we unbind the device
@@ -679,6 +682,30 @@ void phy_detach(struct phy_device *phydev)
679682
}
680683
EXPORT_SYMBOL(phy_detach);
681684

685+
int phy_suspend(struct phy_device *phydev)
686+
{
687+
struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver);
688+
struct ethtool_wolinfo wol;
689+
690+
/* If the device has WOL enabled, we cannot suspend the PHY */
691+
wol.cmd = ETHTOOL_GWOL;
692+
phy_ethtool_get_wol(phydev, &wol);
693+
if (wol.wolopts)
694+
return -EBUSY;
695+
696+
if (phydrv->suspend)
697+
return phydrv->suspend(phydev);
698+
return 0;
699+
}
700+
701+
int phy_resume(struct phy_device *phydev)
702+
{
703+
struct phy_driver *phydrv = to_phy_driver(phydev->dev.driver);
704+
705+
if (phydrv->resume)
706+
return phydrv->resume(phydev);
707+
return 0;
708+
}
682709

683710
/* Generic PHY support and helper functions */
684711

‎include/linux/phy.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,8 @@ struct phy_device *phy_device_create(struct mii_bus *bus, int addr, int phy_id,
548548
struct phy_device *get_phy_device(struct mii_bus *bus, int addr, bool is_c45);
549549
int phy_device_register(struct phy_device *phy);
550550
int phy_init_hw(struct phy_device *phydev);
551+
int phy_suspend(struct phy_device *phydev);
552+
int phy_resume(struct phy_device *phydev);
551553
struct phy_device * phy_attach(struct net_device *dev,
552554
const char *bus_id, phy_interface_t interface);
553555
struct phy_device *phy_find_first(struct mii_bus *bus);

0 commit comments

Comments
 (0)