Skip to content

Commit 61ad640

Browse files
committed
Merge branch 'r8169-improve-runtime-pm'
Heiner Kallweit says: ==================== r8169: improve runtime pm On my system with two network ports I found that runtime PM didn't suspend the unused port. Therefore I checked runtime pm in this driver in somewhat more detail and this series improves runtime pm in general and solves the mentioned issue. Tested on a system with RTL8168evl (MAC version 34). ==================== Signed-off-by: David S. Miller <[email protected]>
2 parents fdb533c + a92a084 commit 61ad640

File tree

1 file changed

+17
-27
lines changed
  • drivers/net/ethernet/realtek

1 file changed

+17
-27
lines changed

drivers/net/ethernet/realtek/r8169.c

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1675,33 +1675,24 @@ static void rtl_link_chg_patch(struct rtl8169_private *tp)
16751675
}
16761676
}
16771677

1678-
static void __rtl8169_check_link_status(struct net_device *dev,
1679-
struct rtl8169_private *tp,
1680-
void __iomem *ioaddr, bool pm)
1678+
static void rtl8169_check_link_status(struct net_device *dev,
1679+
struct rtl8169_private *tp,
1680+
void __iomem *ioaddr)
16811681
{
16821682
if (tp->link_ok(ioaddr)) {
16831683
rtl_link_chg_patch(tp);
16841684
/* This is to cancel a scheduled suspend if there's one. */
1685-
if (pm)
1686-
pm_request_resume(&tp->pci_dev->dev);
1685+
pm_request_resume(&tp->pci_dev->dev);
16871686
netif_carrier_on(dev);
16881687
if (net_ratelimit())
16891688
netif_info(tp, ifup, dev, "link up\n");
16901689
} else {
16911690
netif_carrier_off(dev);
16921691
netif_info(tp, ifdown, dev, "link down\n");
1693-
if (pm)
1694-
pm_schedule_suspend(&tp->pci_dev->dev, 5000);
1692+
pm_runtime_idle(&tp->pci_dev->dev);
16951693
}
16961694
}
16971695

1698-
static void rtl8169_check_link_status(struct net_device *dev,
1699-
struct rtl8169_private *tp,
1700-
void __iomem *ioaddr)
1701-
{
1702-
__rtl8169_check_link_status(dev, tp, ioaddr, false);
1703-
}
1704-
17051696
#define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST)
17061697

17071698
static u32 __rtl8169_get_wol(struct rtl8169_private *tp)
@@ -7746,7 +7737,7 @@ static void rtl_slow_event_work(struct rtl8169_private *tp)
77467737
rtl8169_pcierr_interrupt(dev);
77477738

77487739
if (status & LinkChg)
7749-
__rtl8169_check_link_status(dev, tp, tp->mmio_addr, true);
7740+
rtl8169_check_link_status(dev, tp, tp->mmio_addr);
77507741

77517742
rtl_irq_enable_all(tp);
77527743
}
@@ -7959,7 +7950,7 @@ static int rtl_open(struct net_device *dev)
79597950
rtl_unlock_work(tp);
79607951

79617952
tp->saved_wolopts = 0;
7962-
pm_runtime_put_noidle(&pdev->dev);
7953+
pm_runtime_put_sync(&pdev->dev);
79637954

79647955
rtl8169_check_link_status(dev, tp, ioaddr);
79657956
out:
@@ -8103,8 +8094,10 @@ static int rtl8169_runtime_suspend(struct device *device)
81038094
struct net_device *dev = pci_get_drvdata(pdev);
81048095
struct rtl8169_private *tp = netdev_priv(dev);
81058096

8106-
if (!tp->TxDescArray)
8097+
if (!tp->TxDescArray) {
8098+
rtl_pll_power_down(tp);
81078099
return 0;
8100+
}
81088101

81098102
rtl_lock_work(tp);
81108103
tp->saved_wolopts = __rtl8169_get_wol(tp);
@@ -8146,9 +8139,11 @@ static int rtl8169_runtime_idle(struct device *device)
81468139
{
81478140
struct pci_dev *pdev = to_pci_dev(device);
81488141
struct net_device *dev = pci_get_drvdata(pdev);
8149-
struct rtl8169_private *tp = netdev_priv(dev);
81508142

8151-
return tp->TxDescArray ? -EBUSY : 0;
8143+
if (!netif_running(dev) || !netif_carrier_ok(dev))
8144+
pm_schedule_suspend(device, 10000);
8145+
8146+
return -EBUSY;
81528147
}
81538148

81548149
static const struct dev_pm_ops rtl8169_pm_ops = {
@@ -8195,9 +8190,6 @@ static void rtl_shutdown(struct pci_dev *pdev)
81958190
{
81968191
struct net_device *dev = pci_get_drvdata(pdev);
81978192
struct rtl8169_private *tp = netdev_priv(dev);
8198-
struct device *d = &pdev->dev;
8199-
8200-
pm_runtime_get_sync(d);
82018193

82028194
rtl8169_net_suspend(dev);
82038195

@@ -8215,8 +8207,6 @@ static void rtl_shutdown(struct pci_dev *pdev)
82158207
pci_wake_from_d3(pdev, true);
82168208
pci_set_power_state(pdev, PCI_D3hot);
82178209
}
8218-
8219-
pm_runtime_put_noidle(d);
82208210
}
82218211

82228212
static void rtl_remove_one(struct pci_dev *pdev)
@@ -8701,11 +8691,11 @@ static int rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
87018691
rtl8168_driver_start(tp);
87028692
}
87038693

8704-
if (pci_dev_run_wake(pdev))
8705-
pm_runtime_put_noidle(&pdev->dev);
8706-
87078694
netif_carrier_off(dev);
87088695

8696+
if (pci_dev_run_wake(pdev))
8697+
pm_runtime_put_sync(&pdev->dev);
8698+
87098699
return 0;
87108700
}
87118701

0 commit comments

Comments
 (0)