aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/e1000e
diff options
context:
space:
mode:
authorRafael J. Wysocki <rjw@sisk.pl>2010-03-14 10:35:17 -0400
committerDavid S. Miller <davem@davemloft.net>2010-03-17 00:23:35 -0400
commit23606cf5d1192c2b17912cb2ef6e62f9b11de133 (patch)
tree185de39a532ee3ce06f3f083bfcebad48beddbe0 /drivers/net/e1000e
parente175944115db6762d3e98520c709e5a87f933c61 (diff)
e1000e / PCI / PM: Add basic runtime PM support (rev. 4)
Use the PCI runtime power management framework to add basic PCI runtime PM support to the e1000e driver. Namely, make the driver suspend the device when the link is off and set it up for generating a wakeup event after the link has been detected again. [This feature is disabled until the user space enables it with the help of the /sys/devices/.../power/contol device attribute.] Based on a patch from Matthew Garrett. Signed-off-by: Rafael J. Wysocki <rjw@sisk.pl> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/e1000e')
-rw-r--r--drivers/net/e1000e/e1000.h5
-rw-r--r--drivers/net/e1000e/netdev.c160
2 files changed, 138 insertions, 27 deletions
diff --git a/drivers/net/e1000e/e1000.h b/drivers/net/e1000e/e1000.h
index c2ec095d2163..8da190b930a2 100644
--- a/drivers/net/e1000e/e1000.h
+++ b/drivers/net/e1000e/e1000.h
@@ -158,6 +158,9 @@ struct e1000_info;
158#define HV_M_STATUS_SPEED_1000 0x0200 158#define HV_M_STATUS_SPEED_1000 0x0200
159#define HV_M_STATUS_LINK_UP 0x0040 159#define HV_M_STATUS_LINK_UP 0x0040
160 160
161/* Time to wait before putting the device into D3 if there's no link (in ms). */
162#define LINK_TIMEOUT 100
163
161enum e1000_boards { 164enum e1000_boards {
162 board_82571, 165 board_82571,
163 board_82572, 166 board_82572,
@@ -370,6 +373,8 @@ struct e1000_adapter {
370 struct work_struct update_phy_task; 373 struct work_struct update_phy_task;
371 struct work_struct led_blink_task; 374 struct work_struct led_blink_task;
372 struct work_struct print_hang_task; 375 struct work_struct print_hang_task;
376
377 bool idle_check;
373}; 378};
374 379
375struct e1000_info { 380struct e1000_info {
diff --git a/drivers/net/e1000e/netdev.c b/drivers/net/e1000e/netdev.c
index 88d54d3efcef..79b33c512dfd 100644
--- a/drivers/net/e1000e/netdev.c
+++ b/drivers/net/e1000e/netdev.c
@@ -44,6 +44,7 @@
44#include <linux/cpu.h> 44#include <linux/cpu.h>
45#include <linux/smp.h> 45#include <linux/smp.h>
46#include <linux/pm_qos_params.h> 46#include <linux/pm_qos_params.h>
47#include <linux/pm_runtime.h>
47#include <linux/aer.h> 48#include <linux/aer.h>
48 49
49#include "e1000.h" 50#include "e1000.h"
@@ -3083,12 +3084,15 @@ static int e1000_open(struct net_device *netdev)
3083{ 3084{
3084 struct e1000_adapter *adapter = netdev_priv(netdev); 3085 struct e1000_adapter *adapter = netdev_priv(netdev);
3085 struct e1000_hw *hw = &adapter->hw; 3086 struct e1000_hw *hw = &adapter->hw;
3087 struct pci_dev *pdev = adapter->pdev;
3086 int err; 3088 int err;
3087 3089
3088 /* disallow open during test */ 3090 /* disallow open during test */
3089 if (test_bit(__E1000_TESTING, &adapter->state)) 3091 if (test_bit(__E1000_TESTING, &adapter->state))
3090 return -EBUSY; 3092 return -EBUSY;
3091 3093
3094 pm_runtime_get_sync(&pdev->dev);
3095
3092 netif_carrier_off(netdev); 3096 netif_carrier_off(netdev);
3093 3097
3094 /* allocate transmit descriptors */ 3098 /* allocate transmit descriptors */
@@ -3149,6 +3153,9 @@ static int e1000_open(struct net_device *netdev)
3149 3153
3150 netif_start_queue(netdev); 3154 netif_start_queue(netdev);
3151 3155
3156 adapter->idle_check = true;
3157 pm_runtime_put(&pdev->dev);
3158
3152 /* fire a link status change interrupt to start the watchdog */ 3159 /* fire a link status change interrupt to start the watchdog */
3153 ew32(ICS, E1000_ICS_LSC); 3160 ew32(ICS, E1000_ICS_LSC);
3154 3161
@@ -3162,6 +3169,7 @@ err_setup_rx:
3162 e1000e_free_tx_resources(adapter); 3169 e1000e_free_tx_resources(adapter);
3163err_setup_tx: 3170err_setup_tx:
3164 e1000e_reset(adapter); 3171 e1000e_reset(adapter);
3172 pm_runtime_put_sync(&pdev->dev);
3165 3173
3166 return err; 3174 return err;
3167} 3175}
@@ -3180,11 +3188,17 @@ err_setup_tx:
3180static int e1000_close(struct net_device *netdev) 3188static int e1000_close(struct net_device *netdev)
3181{ 3189{
3182 struct e1000_adapter *adapter = netdev_priv(netdev); 3190 struct e1000_adapter *adapter = netdev_priv(netdev);
3191 struct pci_dev *pdev = adapter->pdev;
3183 3192
3184 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state)); 3193 WARN_ON(test_bit(__E1000_RESETTING, &adapter->state));
3185 e1000e_down(adapter); 3194
3195 pm_runtime_get_sync(&pdev->dev);
3196
3197 if (!test_bit(__E1000_DOWN, &adapter->state)) {
3198 e1000e_down(adapter);
3199 e1000_free_irq(adapter);
3200 }
3186 e1000_power_down_phy(adapter); 3201 e1000_power_down_phy(adapter);
3187 e1000_free_irq(adapter);
3188 3202
3189 e1000e_free_tx_resources(adapter); 3203 e1000e_free_tx_resources(adapter);
3190 e1000e_free_rx_resources(adapter); 3204 e1000e_free_rx_resources(adapter);
@@ -3206,6 +3220,8 @@ static int e1000_close(struct net_device *netdev)
3206 if (adapter->flags & FLAG_HAS_AMT) 3220 if (adapter->flags & FLAG_HAS_AMT)
3207 e1000_release_hw_control(adapter); 3221 e1000_release_hw_control(adapter);
3208 3222
3223 pm_runtime_put_sync(&pdev->dev);
3224
3209 return 0; 3225 return 0;
3210} 3226}
3211/** 3227/**
@@ -3550,6 +3566,9 @@ static void e1000_watchdog_task(struct work_struct *work)
3550 3566
3551 link = e1000e_has_link(adapter); 3567 link = e1000e_has_link(adapter);
3552 if ((netif_carrier_ok(netdev)) && link) { 3568 if ((netif_carrier_ok(netdev)) && link) {
3569 /* Cancel scheduled suspend requests. */
3570 pm_runtime_resume(netdev->dev.parent);
3571
3553 e1000e_enable_receives(adapter); 3572 e1000e_enable_receives(adapter);
3554 goto link_up; 3573 goto link_up;
3555 } 3574 }
@@ -3561,6 +3580,10 @@ static void e1000_watchdog_task(struct work_struct *work)
3561 if (link) { 3580 if (link) {
3562 if (!netif_carrier_ok(netdev)) { 3581 if (!netif_carrier_ok(netdev)) {
3563 bool txb2b = 1; 3582 bool txb2b = 1;
3583
3584 /* Cancel scheduled suspend requests. */
3585 pm_runtime_resume(netdev->dev.parent);
3586
3564 /* update snapshot of PHY registers on LSC */ 3587 /* update snapshot of PHY registers on LSC */
3565 e1000_phy_read_status(adapter); 3588 e1000_phy_read_status(adapter);
3566 mac->ops.get_link_up_info(&adapter->hw, 3589 mac->ops.get_link_up_info(&adapter->hw,
@@ -3676,6 +3699,9 @@ static void e1000_watchdog_task(struct work_struct *work)
3676 3699
3677 if (adapter->flags & FLAG_RX_NEEDS_RESTART) 3700 if (adapter->flags & FLAG_RX_NEEDS_RESTART)
3678 schedule_work(&adapter->reset_task); 3701 schedule_work(&adapter->reset_task);
3702 else
3703 pm_schedule_suspend(netdev->dev.parent,
3704 LINK_TIMEOUT);
3679 } 3705 }
3680 } 3706 }
3681 3707
@@ -4473,13 +4499,15 @@ out:
4473 return retval; 4499 return retval;
4474} 4500}
4475 4501
4476static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake) 4502static int __e1000_shutdown(struct pci_dev *pdev, bool *enable_wake,
4503 bool runtime)
4477{ 4504{
4478 struct net_device *netdev = pci_get_drvdata(pdev); 4505 struct net_device *netdev = pci_get_drvdata(pdev);
4479 struct e1000_adapter *adapter = netdev_priv(netdev); 4506 struct e1000_adapter *adapter = netdev_priv(netdev);
4480 struct e1000_hw *hw = &adapter->hw; 4507 struct e1000_hw *hw = &adapter->hw;
4481 u32 ctrl, ctrl_ext, rctl, status; 4508 u32 ctrl, ctrl_ext, rctl, status;
4482 u32 wufc = adapter->wol; 4509 /* Runtime suspend should only enable wakeup for link changes */
4510 u32 wufc = runtime ? E1000_WUFC_LNKC : adapter->wol;
4483 int retval = 0; 4511 int retval = 0;
4484 4512
4485 netif_device_detach(netdev); 4513 netif_device_detach(netdev);
@@ -4637,41 +4665,65 @@ static void e1000e_disable_l1aspm(struct pci_dev *pdev)
4637} 4665}
4638 4666
4639#ifdef CONFIG_PM 4667#ifdef CONFIG_PM
4640static int e1000_suspend(struct pci_dev *pdev, pm_message_t state) 4668static bool e1000e_pm_ready(struct e1000_adapter *adapter)
4669{
4670 return !!adapter->tx_ring->buffer_info;
4671}
4672
4673static int e1000_idle(struct device *dev)
4641{ 4674{
4675 struct pci_dev *pdev = to_pci_dev(dev);
4676 struct net_device *netdev = pci_get_drvdata(pdev);
4677 struct e1000_adapter *adapter = netdev_priv(netdev);
4678
4679 if (!e1000e_pm_ready(adapter))
4680 return 0;
4681
4682 if (adapter->idle_check) {
4683 adapter->idle_check = false;
4684 if (!e1000e_has_link(adapter))
4685 pm_schedule_suspend(dev, MSEC_PER_SEC);
4686 }
4687
4688 return -EBUSY;
4689}
4690
4691static int e1000_suspend(struct device *dev)
4692{
4693 struct pci_dev *pdev = to_pci_dev(dev);
4642 int retval; 4694 int retval;
4643 bool wake; 4695 bool wake;
4644 4696
4645 retval = __e1000_shutdown(pdev, &wake); 4697 retval = __e1000_shutdown(pdev, &wake, false);
4646 if (!retval) 4698 if (!retval)
4647 e1000_complete_shutdown(pdev, true, wake); 4699 e1000_complete_shutdown(pdev, true, wake);
4648 4700
4649 return retval; 4701 return retval;
4650} 4702}
4651 4703
4652static int e1000_resume(struct pci_dev *pdev) 4704static int e1000_runtime_suspend(struct device *dev)
4653{ 4705{
4706 struct pci_dev *pdev = to_pci_dev(dev);
4654 struct net_device *netdev = pci_get_drvdata(pdev); 4707 struct net_device *netdev = pci_get_drvdata(pdev);
4655 struct e1000_adapter *adapter = netdev_priv(netdev); 4708 struct e1000_adapter *adapter = netdev_priv(netdev);
4656 struct e1000_hw *hw = &adapter->hw;
4657 u32 err;
4658 4709
4659 pci_set_power_state(pdev, PCI_D0); 4710 if (e1000e_pm_ready(adapter)) {
4660 pci_restore_state(pdev); 4711 bool wake;
4661 pci_save_state(pdev);
4662 e1000e_disable_l1aspm(pdev);
4663 4712
4664 err = pci_enable_device_mem(pdev); 4713 __e1000_shutdown(pdev, &wake, true);
4665 if (err) {
4666 dev_err(&pdev->dev,
4667 "Cannot enable PCI device from suspend\n");
4668 return err;
4669 } 4714 }
4670 4715
4671 pci_set_master(pdev); 4716 return 0;
4717}
4672 4718
4673 pci_enable_wake(pdev, PCI_D3hot, 0); 4719static int __e1000_resume(struct pci_dev *pdev)
4674 pci_enable_wake(pdev, PCI_D3cold, 0); 4720{
4721 struct net_device *netdev = pci_get_drvdata(pdev);
4722 struct e1000_adapter *adapter = netdev_priv(netdev);
4723 struct e1000_hw *hw = &adapter->hw;
4724 u32 err;
4725
4726 e1000e_disable_l1aspm(pdev);
4675 4727
4676 e1000e_set_interrupt_capability(adapter); 4728 e1000e_set_interrupt_capability(adapter);
4677 if (netif_running(netdev)) { 4729 if (netif_running(netdev)) {
@@ -4730,13 +4782,38 @@ static int e1000_resume(struct pci_dev *pdev)
4730 4782
4731 return 0; 4783 return 0;
4732} 4784}
4785
4786static int e1000_resume(struct device *dev)
4787{
4788 struct pci_dev *pdev = to_pci_dev(dev);
4789 struct net_device *netdev = pci_get_drvdata(pdev);
4790 struct e1000_adapter *adapter = netdev_priv(netdev);
4791
4792 if (e1000e_pm_ready(adapter))
4793 adapter->idle_check = true;
4794
4795 return __e1000_resume(pdev);
4796}
4797
4798static int e1000_runtime_resume(struct device *dev)
4799{
4800 struct pci_dev *pdev = to_pci_dev(dev);
4801 struct net_device *netdev = pci_get_drvdata(pdev);
4802 struct e1000_adapter *adapter = netdev_priv(netdev);
4803
4804 if (!e1000e_pm_ready(adapter))
4805 return 0;
4806
4807 adapter->idle_check = !dev->power.runtime_auto;
4808 return __e1000_resume(pdev);
4809}
4733#endif 4810#endif
4734 4811
4735static void e1000_shutdown(struct pci_dev *pdev) 4812static void e1000_shutdown(struct pci_dev *pdev)
4736{ 4813{
4737 bool wake = false; 4814 bool wake = false;
4738 4815
4739 __e1000_shutdown(pdev, &wake); 4816 __e1000_shutdown(pdev, &wake, false);
4740 4817
4741 if (system_state == SYSTEM_POWER_OFF) 4818 if (system_state == SYSTEM_POWER_OFF)
4742 e1000_complete_shutdown(pdev, false, wake); 4819 e1000_complete_shutdown(pdev, false, wake);
@@ -4809,8 +4886,8 @@ static pci_ers_result_t e1000_io_slot_reset(struct pci_dev *pdev)
4809 result = PCI_ERS_RESULT_DISCONNECT; 4886 result = PCI_ERS_RESULT_DISCONNECT;
4810 } else { 4887 } else {
4811 pci_set_master(pdev); 4888 pci_set_master(pdev);
4889 pdev->state_saved = true;
4812 pci_restore_state(pdev); 4890 pci_restore_state(pdev);
4813 pci_save_state(pdev);
4814 4891
4815 pci_enable_wake(pdev, PCI_D3hot, 0); 4892 pci_enable_wake(pdev, PCI_D3hot, 0);
4816 pci_enable_wake(pdev, PCI_D3cold, 0); 4893 pci_enable_wake(pdev, PCI_D3cold, 0);
@@ -5217,6 +5294,12 @@ static int __devinit e1000_probe(struct pci_dev *pdev,
5217 5294
5218 e1000_print_device_info(adapter); 5295 e1000_print_device_info(adapter);
5219 5296
5297 if (pci_dev_run_wake(pdev)) {
5298 pm_runtime_set_active(&pdev->dev);
5299 pm_runtime_enable(&pdev->dev);
5300 }
5301 pm_schedule_suspend(&pdev->dev, MSEC_PER_SEC);
5302
5220 return 0; 5303 return 0;
5221 5304
5222err_register: 5305err_register:
@@ -5259,12 +5342,16 @@ static void __devexit e1000_remove(struct pci_dev *pdev)
5259{ 5342{
5260 struct net_device *netdev = pci_get_drvdata(pdev); 5343 struct net_device *netdev = pci_get_drvdata(pdev);
5261 struct e1000_adapter *adapter = netdev_priv(netdev); 5344 struct e1000_adapter *adapter = netdev_priv(netdev);
5345 bool down = test_bit(__E1000_DOWN, &adapter->state);
5346
5347 pm_runtime_get_sync(&pdev->dev);
5262 5348
5263 /* 5349 /*
5264 * flush_scheduled work may reschedule our watchdog task, so 5350 * flush_scheduled work may reschedule our watchdog task, so
5265 * explicitly disable watchdog tasks from being rescheduled 5351 * explicitly disable watchdog tasks from being rescheduled
5266 */ 5352 */
5267 set_bit(__E1000_DOWN, &adapter->state); 5353 if (!down)
5354 set_bit(__E1000_DOWN, &adapter->state);
5268 del_timer_sync(&adapter->watchdog_timer); 5355 del_timer_sync(&adapter->watchdog_timer);
5269 del_timer_sync(&adapter->phy_info_timer); 5356 del_timer_sync(&adapter->phy_info_timer);
5270 5357
@@ -5278,8 +5365,17 @@ static void __devexit e1000_remove(struct pci_dev *pdev)
5278 if (!(netdev->flags & IFF_UP)) 5365 if (!(netdev->flags & IFF_UP))
5279 e1000_power_down_phy(adapter); 5366 e1000_power_down_phy(adapter);
5280 5367
5368 /* Don't lie to e1000_close() down the road. */
5369 if (!down)
5370 clear_bit(__E1000_DOWN, &adapter->state);
5281 unregister_netdev(netdev); 5371 unregister_netdev(netdev);
5282 5372
5373 if (pci_dev_run_wake(pdev)) {
5374 pm_runtime_disable(&pdev->dev);
5375 pm_runtime_set_suspended(&pdev->dev);
5376 }
5377 pm_runtime_put_noidle(&pdev->dev);
5378
5283 /* 5379 /*
5284 * Release control of h/w to f/w. If f/w is AMT enabled, this 5380 * Release control of h/w to f/w. If f/w is AMT enabled, this
5285 * would have already happened in close and is redundant. 5381 * would have already happened in close and is redundant.
@@ -5379,6 +5475,18 @@ static DEFINE_PCI_DEVICE_TABLE(e1000_pci_tbl) = {
5379}; 5475};
5380MODULE_DEVICE_TABLE(pci, e1000_pci_tbl); 5476MODULE_DEVICE_TABLE(pci, e1000_pci_tbl);
5381 5477
5478static const struct dev_pm_ops e1000_pm_ops = {
5479 .suspend = e1000_suspend,
5480 .resume = e1000_resume,
5481 .freeze = e1000_suspend,
5482 .thaw = e1000_resume,
5483 .poweroff = e1000_suspend,
5484 .restore = e1000_resume,
5485 .runtime_suspend = e1000_runtime_suspend,
5486 .runtime_resume = e1000_runtime_resume,
5487 .runtime_idle = e1000_idle,
5488};
5489
5382/* PCI Device API Driver */ 5490/* PCI Device API Driver */
5383static struct pci_driver e1000_driver = { 5491static struct pci_driver e1000_driver = {
5384 .name = e1000e_driver_name, 5492 .name = e1000e_driver_name,
@@ -5386,9 +5494,7 @@ static struct pci_driver e1000_driver = {
5386 .probe = e1000_probe, 5494 .probe = e1000_probe,
5387 .remove = __devexit_p(e1000_remove), 5495 .remove = __devexit_p(e1000_remove),
5388#ifdef CONFIG_PM 5496#ifdef CONFIG_PM
5389 /* Power Management Hooks */ 5497 .driver.pm = &e1000_pm_ops,
5390 .suspend = e1000_suspend,
5391 .resume = e1000_resume,
5392#endif 5498#endif
5393 .shutdown = e1000_shutdown, 5499 .shutdown = e1000_shutdown,
5394 .err_handler = &e1000_err_handler 5500 .err_handler = &e1000_err_handler