Skip to contentSkip to conversation

realtek/8139too: Remove Legacy Power Management

PATCH Superseded Vaibhav Gupta 3 participants 12 messages Apr 23, 2020 – Apr 24, 2020 Network drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 realtek/8139too: Remove Legacy Power Management

Upgrade Power Management from legacy to generic using dev_pm_ops.

Remove struct pci_driver.suspend and struct pci_driver.resume bindings, and add struct pci_driver.driver.pm .

---
 drivers/net/ethernet/realtek/8139too.c | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)
drivers/net/ethernet/realtek/8139too.c +7 -19
index 5caeb8368eab..b7c98b165256 100644
@@ -2603,17 +2603,13 @@ static void rtl8139_set_rx_mode (struct net_device *dev)
 	spin_unlock_irqrestore (&tp->lock, flags);
 }
 
-#ifdef CONFIG_PM
-
-static int rtl8139_suspend (struct pci_dev *pdev, pm_message_t state)
+static int rtl8139_suspend(struct device *device)
 {
-	struct net_device *dev = pci_get_drvdata (pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 	struct rtl8139_private *tp = netdev_priv(dev);
 	void __iomem *ioaddr = tp->mmio_addr;
 	unsigned long flags;
 
-	pci_save_state (pdev);
-
 	if (!netif_running (dev))
 		return 0;
 
@@ -2631,38 +2627,30 @@ static int rtl8139_suspend (struct pci_dev *pdev, pm_message_t state)
 
 	spin_unlock_irqrestore (&tp->lock, flags);
 
-	pci_set_power_state (pdev, PCI_D3hot);
-
 	return 0;
 }
 
-
-static int rtl8139_resume (struct pci_dev *pdev)
+static int rtl8139_resume(struct device *device)
 {
-	struct net_device *dev = pci_get_drvdata (pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 
-	pci_restore_state (pdev);
 	if (!netif_running (dev))
 		return 0;
-	pci_set_power_state (pdev, PCI_D0);
+
 	rtl8139_init_ring (dev);
 	rtl8139_hw_start (dev);
 	netif_device_attach (dev);
 	return 0;
 }
 
-#endif /* CONFIG_PM */
-
+static SIMPLE_DEV_PM_OPS(rtl8139_pm_ops, rtl8139_suspend, rtl8139_resume);
 
 static struct pci_driver rtl8139_pci_driver = {
 	.name		= DRV_NAME,
 	.id_table	= rtl8139_pci_tbl,
 	.probe		= rtl8139_init_one,
 	.remove		= rtl8139_remove_one,
-#ifdef CONFIG_PM
-	.suspend	= rtl8139_suspend,
-	.resume		= rtl8139_resume,
-#endif /* CONFIG_PM */
+	.driver.pm	= &rtl8139_pm_ops,
 };
 
 
Signature · 6 lines
2.26.2

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#1 lore raw

PATCH 2/2 realtek/8139cp: Remove Legacy Power Management

Upgrade Power Management from legacy to generic using dev_pm_ops.

Remove pci_save_sate(), pci_set_state(), etc. No need of directive '#ifdef CONFIG_PM' as, if CONFIG_PM is not defined, the binding will be by deafult set to NULL.

---
 drivers/net/ethernet/realtek/8139cp.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)
drivers/net/ethernet/realtek/8139cp.c +7 -18
index 60d342f82fb3..e2e79cf4e1fa 100644
@@ -2054,10 +2054,9 @@ static void cp_remove_one (struct pci_dev *pdev)
 	free_netdev(dev);
 }
 
-#ifdef CONFIG_PM
-static int cp_suspend (struct pci_dev *pdev, pm_message_t state)
+static int cp_suspend(struct device *device)
 {
-	struct net_device *dev = pci_get_drvdata(pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 	struct cp_private *cp = netdev_priv(dev);
 	unsigned long flags;
 
@@ -2075,16 +2074,12 @@ static int cp_suspend (struct pci_dev *pdev, pm_message_t state)
 
 	spin_unlock_irqrestore (&cp->lock, flags);
 
-	pci_save_state(pdev);
-	pci_enable_wake(pdev, pci_choose_state(pdev, state), cp->wol_enabled);
-	pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
 	return 0;
 }
 
-static int cp_resume (struct pci_dev *pdev)
+static int cp_resume(struct device *device)
 {
-	struct net_device *dev = pci_get_drvdata (pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 	struct cp_private *cp = netdev_priv(dev);
 	unsigned long flags;
 
@@ -2093,10 +2088,6 @@ static int cp_resume (struct pci_dev *pdev)
 
 	netif_device_attach (dev);
 
-	pci_set_power_state(pdev, PCI_D0);
-	pci_restore_state(pdev);
-	pci_enable_wake(pdev, PCI_D0, 0);
-
 	/* FIXME: sh*t may happen if the Rx ring buffer is depleted */
 	cp_init_rings_index (cp);
 	cp_init_hw (cp);
@@ -2111,7 +2102,6 @@ static int cp_resume (struct pci_dev *pdev)
 
 	return 0;
 }
-#endif /* CONFIG_PM */
 
 static const struct pci_device_id cp_pci_tbl[] = {
         { PCI_DEVICE(PCI_VENDOR_ID_REALTEK,     PCI_DEVICE_ID_REALTEK_8139), },
@@ -2120,15 +2110,14 @@ static const struct pci_device_id cp_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, cp_pci_tbl);
 
+static SIMPLE_DEV_PM_OPS(cp_pm_ops, cp_suspend, cp_resume);
+
 static struct pci_driver cp_driver = {
 	.name         = DRV_NAME,
 	.id_table     = cp_pci_tbl,
 	.probe        =	cp_init_one,
 	.remove       = cp_remove_one,
-#ifdef CONFIG_PM
-	.resume       = cp_resume,
-	.suspend      = cp_suspend,
-#endif
+	.driver.pm    = &cp_pm_ops,
 };
 
 module_pci_driver(cp_driver);
Signature · 6 lines
2.26.2

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees
#2 lore raw

Re: [Linux-kernel-mentees] [PATCH v1 2/2] realtek/8139cp: Remove Legacy Power Management

Quoted 5 lines · Vaibhav Gupta

Upgrade Power Management from legacy to generic using dev_pm_ops.

Remove pci_save_sate(), pci_set_state(), etc. No need of directive '#ifdef CONFIG_PM' as, if CONFIG_PM is not defined, the binding will be by deafult set to NULL.

s/deafult/default/

I didn't quite follow this argument. SIMPLE_DEV_PM_OPS() is defined to SET_SYSTEM_SLEEP_PM_OPS(), and SET_SYSTEM_SLEEP_PM_OPS() is defined to nothing unless CONFIG_PM_SLEEP (not CONFIG_PM).

But in any case, we don't want cp_suspend() and cp_resume() to be compiled at all if they're not referenced. So I think converting the "#ifdef CONFIG_PM" to "#ifdef CONFIG_PM_SLEEP" is the right thing.

Quoted 82 lines
---
 drivers/net/ethernet/realtek/8139cp.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)
drivers/net/ethernet/realtek/8139cp.c +7 -18
index 60d342f82fb3..e2e79cf4e1fa 100644
@@ -2054,10 +2054,9 @@ static void cp_remove_one (struct pci_dev *pdev)
 	free_netdev(dev);
 }
 
-#ifdef CONFIG_PM
-static int cp_suspend (struct pci_dev *pdev, pm_message_t state)
+static int cp_suspend(struct device *device)
 {
-	struct net_device *dev = pci_get_drvdata(pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 	struct cp_private *cp = netdev_priv(dev);
 	unsigned long flags;
 
@@ -2075,16 +2074,12 @@ static int cp_suspend (struct pci_dev *pdev, pm_message_t state)
 
 	spin_unlock_irqrestore (&cp->lock, flags);
 
-	pci_save_state(pdev);
-	pci_enable_wake(pdev, pci_choose_state(pdev, state), cp->wol_enabled);
-	pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
 	return 0;
 }
 
-static int cp_resume (struct pci_dev *pdev)
+static int cp_resume(struct device *device)
 {
-	struct net_device *dev = pci_get_drvdata (pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 	struct cp_private *cp = netdev_priv(dev);
 	unsigned long flags;
 
@@ -2093,10 +2088,6 @@ static int cp_resume (struct pci_dev *pdev)
 
 	netif_device_attach (dev);
 
-	pci_set_power_state(pdev, PCI_D0);
-	pci_restore_state(pdev);
-	pci_enable_wake(pdev, PCI_D0, 0);
-
 	/* FIXME: sh*t may happen if the Rx ring buffer is depleted */
 	cp_init_rings_index (cp);
 	cp_init_hw (cp);
@@ -2111,7 +2102,6 @@ static int cp_resume (struct pci_dev *pdev)
 
 	return 0;
 }
-#endif /* CONFIG_PM */
 
 static const struct pci_device_id cp_pci_tbl[] = {
         { PCI_DEVICE(PCI_VENDOR_ID_REALTEK,     PCI_DEVICE_ID_REALTEK_8139), },
@@ -2120,15 +2110,14 @@ static const struct pci_device_id cp_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, cp_pci_tbl);
 
+static SIMPLE_DEV_PM_OPS(cp_pm_ops, cp_suspend, cp_resume);
+
 static struct pci_driver cp_driver = {
 	.name         = DRV_NAME,
 	.id_table     = cp_pci_tbl,
 	.probe        =	cp_init_one,
 	.remove       = cp_remove_one,
-#ifdef CONFIG_PM
-	.resume       = cp_resume,
-	.suspend      = cp_suspend,
-#endif
+	.driver.pm    = &cp_pm_ops,
 };
 
 module_pci_driver(cp_driver);
Signature · 1 line
2.26.2

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#3 lore raw

Re: [Linux-kernel-mentees] [PATCH v1 2/2] realtek/8139cp: Remove Legacy Power Management

Quoted 8 lines · Bjorn Helgaas
Quoted 5 lines · Vaibhav Gupta

Upgrade Power Management from legacy to generic using dev_pm_ops.

Remove pci_save_sate(), pci_set_state(), etc. No need of directive '#ifdef CONFIG_PM' as, if CONFIG_PM is not defined, the binding will be by deafult set to NULL.

Quoted 5 lines

s/deafult/default/

I didn't quite follow this argument. SIMPLE_DEV_PM_OPS() is defined to SET_SYSTEM_SLEEP_PM_OPS(), and SET_SYSTEM_SLEEP_PM_OPS() is defined to nothing unless CONFIG_PM_SLEEP (not CONFIG_PM).

yes, and we can find about CONFIG_PM_SLEEP inside kernel/power/kconfig It is defined as:
config PM_SLEEP

        def_bool y
        depends on SUSPEND || HIBERNATE_CALLBACKS
        select PM
        select SRCU

Hence it is selecting CONFIG_PM. So any of the macro check works.So i should go with
#ifded CONFIG_PM
or
#ifdef CONFIG_PM_SLEEP ?

Quoted 4 lines

But in any case, we don't want cp_suspend() and cp_resume() to be compiled at all if they're not referenced. So I think converting the "#ifdef CONFIG_PM" to "#ifdef CONFIG_PM_SLEEP" is the right thing.

Actually I removed it because Andy also removed them in 226e6b866d74, thought it has to be done that way.

--Vaibhav Gupta

Quoted 79 lines
Quoted 79 lines
---
 drivers/net/ethernet/realtek/8139cp.c | 25 +++++++------------------
 1 file changed, 7 insertions(+), 18 deletions(-)
drivers/net/ethernet/realtek/8139cp.c +7 -18
index 60d342f82fb3..e2e79cf4e1fa 100644
@@ -2054,10 +2054,9 @@ static void cp_remove_one (struct pci_dev *pdev)
      free_netdev(dev);
 }
 
-#ifdef CONFIG_PM
-static int cp_suspend (struct pci_dev *pdev, pm_message_t state)
+static int cp_suspend(struct device *device)
 {
-     struct net_device *dev = pci_get_drvdata(pdev);
+     struct net_device *dev = dev_get_drvdata(device);
      struct cp_private *cp = netdev_priv(dev);
      unsigned long flags;
 
@@ -2075,16 +2074,12 @@ static int cp_suspend (struct pci_dev *pdev, pm_message_t state)
 
      spin_unlock_irqrestore (&cp->lock, flags);
 
-     pci_save_state(pdev);
-     pci_enable_wake(pdev, pci_choose_state(pdev, state), cp->wol_enabled);
-     pci_set_power_state(pdev, pci_choose_state(pdev, state));
-
      return 0;
 }
 
-static int cp_resume (struct pci_dev *pdev)
+static int cp_resume(struct device *device)
 {
-     struct net_device *dev = pci_get_drvdata (pdev);
+     struct net_device *dev = dev_get_drvdata(device);
      struct cp_private *cp = netdev_priv(dev);
      unsigned long flags;
 
@@ -2093,10 +2088,6 @@ static int cp_resume (struct pci_dev *pdev)
 
      netif_device_attach (dev);
 
-     pci_set_power_state(pdev, PCI_D0);
-     pci_restore_state(pdev);
-     pci_enable_wake(pdev, PCI_D0, 0);
-
      /* FIXME: sh*t may happen if the Rx ring buffer is depleted */
      cp_init_rings_index (cp);
      cp_init_hw (cp);
@@ -2111,7 +2102,6 @@ static int cp_resume (struct pci_dev *pdev)
 
      return 0;
 }
-#endif /* CONFIG_PM */
 
 static const struct pci_device_id cp_pci_tbl[] = {
         { PCI_DEVICE(PCI_VENDOR_ID_REALTEK,     PCI_DEVICE_ID_REALTEK_8139), },
@@ -2120,15 +2110,14 @@ static const struct pci_device_id cp_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, cp_pci_tbl);
 
+static SIMPLE_DEV_PM_OPS(cp_pm_ops, cp_suspend, cp_resume);
+
 static struct pci_driver cp_driver = {
      .name         = DRV_NAME,
      .id_table     = cp_pci_tbl,
      .probe        = cp_init_one,
      .remove       = cp_remove_one,
-#ifdef CONFIG_PM
-     .resume       = cp_resume,
-     .suspend      = cp_suspend,
-#endif
+     .driver.pm    = &cp_pm_ops,
 };
 
Quoted 8 lines
Quoted 4 lines
drivers/net/ethernet/realtek/8139cp.c +0 -1
 module_pci_driver(cp_driver);
--

2.26.2

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#4 lore raw

Re: [Linux-kernel-mentees] [PATCH v1 2/2] realtek/8139cp: Remove Legacy Power Management

Quoted 22 lines · Vaibhav Gupta
Quoted 8 lines · Bjorn Helgaas
Quoted 5 lines · Vaibhav Gupta

Upgrade Power Management from legacy to generic using dev_pm_ops.

Remove pci_save_sate(), pci_set_state(), etc. No need of directive '#ifdef CONFIG_PM' as, if CONFIG_PM is not defined, the binding will be by deafult set to NULL.

Quoted 5 lines

s/deafult/default/

I didn't quite follow this argument. SIMPLE_DEV_PM_OPS() is defined to SET_SYSTEM_SLEEP_PM_OPS(), and SET_SYSTEM_SLEEP_PM_OPS() is defined to nothing unless CONFIG_PM_SLEEP (not CONFIG_PM).

yes, and we can find about CONFIG_PM_SLEEP inside kernel/power/kconfig It is defined as:
config PM_SLEEP

        def_bool y
        depends on SUSPEND || HIBERNATE_CALLBACKS
        select PM
        select SRCU
Quoted 5 lines

Hence it is selecting CONFIG_PM. So any of the macro check works.So i should go with
#ifded CONFIG_PM
or
#ifdef CONFIG_PM_SLEEP ?

Well, the point was that it's possible to have CONFIG_PM=y but CONFIG_PM_SLEEP unset. In that case, using "#ifdef CONFIG_PM" will mean those functions will be compiled but not referenced.

Quoted 5 lines
Quoted 3 lines

But in any case, we don't want cp_suspend() and cp_resume() to be compiled at all if they're not referenced. So I think converting the "#ifdef CONFIG_PM" to "#ifdef CONFIG_PM_SLEEP" is the right thing.

Actually I removed it because Andy also removed them in 226e6b866d74, thought it has to be done that way.

Hmm, yes, I see that. I wish we had one canonical way to do this.

In 226e6b866d74 ("gpio: pch: Convert to dev_pm_ops"), I see that Andy also added "__maybe_unused", which I think turns off the compiler warning about the function being unused.

I had been looking at recent additions of SIMPLE_DEV_PM_OPS() via

  $ git log -p drivers/

and searching with "/^\+.*SIMPLE_DEV_PM_OPS". There's a mix of using "#ifdef CONFIG_PM_SLEEP" and using "__maybe_unused", but it does look like "__maybe_unused" is winning. It leaves unusable code in the image but arguably looks a little prettier.

So I guess I'm fine with either way. But I do think we need either "#ifdef CONFIG_PM_SLEEP" or "__maybe_unused" so we don't get compiler warnings.

Bjorn
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#5 lore raw

Re: [Linux-kernel-mentees] [PATCH v1 2/2] realtek/8139cp: Remove Legacy Power Management

Quoted 50 lines · Bjorn Helgaas
Quoted 22 lines · Vaibhav Gupta
Quoted 8 lines · Bjorn Helgaas
Quoted 5 lines · Vaibhav Gupta

Upgrade Power Management from legacy to generic using dev_pm_ops.

Remove pci_save_sate(), pci_set_state(), etc. No need of directive '#ifdef CONFIG_PM' as, if CONFIG_PM is not defined, the binding will be by deafult set to NULL.

Quoted 5 lines

s/deafult/default/

I didn't quite follow this argument. SIMPLE_DEV_PM_OPS() is defined to SET_SYSTEM_SLEEP_PM_OPS(), and SET_SYSTEM_SLEEP_PM_OPS() is defined to nothing unless CONFIG_PM_SLEEP (not CONFIG_PM).

yes, and we can find about CONFIG_PM_SLEEP inside kernel/power/kconfig It is defined as:
config PM_SLEEP

        def_bool y
        depends on SUSPEND || HIBERNATE_CALLBACKS
        select PM
        select SRCU
Quoted 5 lines

Hence it is selecting CONFIG_PM. So any of the macro check works.So i should go with
#ifded CONFIG_PM
or
#ifdef CONFIG_PM_SLEEP ?

Well, the point was that it's possible to have CONFIG_PM=y but CONFIG_PM_SLEEP unset. In that case, using "#ifdef CONFIG_PM" will mean those functions will be compiled but not referenced.

Quoted 5 lines
Quoted 3 lines

But in any case, we don't want cp_suspend() and cp_resume() to be compiled at all if they're not referenced. So I think converting the "#ifdef CONFIG_PM" to "#ifdef CONFIG_PM_SLEEP" is the right thing.

Actually I removed it because Andy also removed them in 226e6b866d74, thought it has to be done that way.

Hmm, yes, I see that. I wish we had one canonical way to do this.

In 226e6b866d74 ("gpio: pch: Convert to dev_pm_ops"), I see that Andy also added "__maybe_unused", which I think turns off the compiler warning about the function being unused.

I had been looking at recent additions of SIMPLE_DEV_PM_OPS() via

  $ git log -p drivers/
Quoted 8 lines

and searching with "/^\+.*SIMPLE_DEV_PM_OPS". There's a mix of using "#ifdef CONFIG_PM_SLEEP" and using "__maybe_unused", but it does look like "__maybe_unused" is winning. It leaves unusable code in the image but arguably looks a little prettier.

So I guess I'm fine with either way. But I do think we need either "#ifdef CONFIG_PM_SLEEP" or "__maybe_unused" so we don't get compiler warnings.

I totally agree with your argument. But in case of "#ifdef CONFIG_PM_SLEEP", neither the suspend() & resume() are compiled and neither ".driver.pm" gets bind.

But in case of "__maybe_unused", we don't keep a check while binding ".driver.pm".
Hence, if CONFIG_PM_SLEEP is not defined, still the ".driver.pm" is bind with a structure
with some random initial values.

We can use the mix of both?
__maybe_unused xyz_suspend(){}
__maybe_unused xyz_resume(){}
...
#ifdef CONIFG_PM_SLEEP
.driver.pm = &xyz_pm_ops;
#endif

-- Vaibhav Gupta

Quoted 2 lines

Bjorn

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#6 lore raw

Re: [Linux-kernel-mentees] [PATCH v1 2/2] realtek/8139cp: Remove Legacy Power Management

Quoted 68 lines · Vaibhav Gupta
Quoted 48 lines · Bjorn Helgaas
Quoted 21 lines · Vaibhav Gupta
Quoted 7 lines · Bjorn Helgaas
Quoted 5 lines · Vaibhav Gupta

Upgrade Power Management from legacy to generic using dev_pm_ops.

Remove pci_save_sate(), pci_set_state(), etc. No need of directive '#ifdef CONFIG_PM' as, if CONFIG_PM is not defined, the binding will be by deafult set to NULL.

Quoted 5 lines

s/deafult/default/

I didn't quite follow this argument. SIMPLE_DEV_PM_OPS() is defined to SET_SYSTEM_SLEEP_PM_OPS(), and SET_SYSTEM_SLEEP_PM_OPS() is defined to nothing unless CONFIG_PM_SLEEP (not CONFIG_PM).

yes, and we can find about CONFIG_PM_SLEEP inside kernel/power/kconfig It is defined as:
config PM_SLEEP

        def_bool y
        depends on SUSPEND || HIBERNATE_CALLBACKS
        select PM
        select SRCU
Quoted 5 lines

Hence it is selecting CONFIG_PM. So any of the macro check works.So i should go with
#ifded CONFIG_PM
or
#ifdef CONFIG_PM_SLEEP ?

Well, the point was that it's possible to have CONFIG_PM=y but CONFIG_PM_SLEEP unset. In that case, using "#ifdef CONFIG_PM" will mean those functions will be compiled but not referenced.

Quoted 5 lines
Quoted 3 lines

But in any case, we don't want cp_suspend() and cp_resume() to be compiled at all if they're not referenced. So I think converting the "#ifdef CONFIG_PM" to "#ifdef CONFIG_PM_SLEEP" is the right thing.

Actually I removed it because Andy also removed them in 226e6b866d74, thought it has to be done that way.

Hmm, yes, I see that. I wish we had one canonical way to do this.

In 226e6b866d74 ("gpio: pch: Convert to dev_pm_ops"), I see that Andy also added "__maybe_unused", which I think turns off the compiler warning about the function being unused.

I had been looking at recent additions of SIMPLE_DEV_PM_OPS() via

  $ git log -p drivers/
Quoted 8 lines

and searching with "/^\+.*SIMPLE_DEV_PM_OPS". There's a mix of using "#ifdef CONFIG_PM_SLEEP" and using "__maybe_unused", but it does look like "__maybe_unused" is winning. It leaves unusable code in the image but arguably looks a little prettier.

So I guess I'm fine with either way. But I do think we need either "#ifdef CONFIG_PM_SLEEP" or "__maybe_unused" so we don't get compiler warnings.

I totally agree with your argument. But in case of "#ifdef CONFIG_PM_SLEEP", neither the suspend() & resume() are compiled and neither ".driver.pm" gets bind.

But in case of "__maybe_unused", we don't keep a check while binding ".driver.pm".
Hence, if CONFIG_PM_SLEEP is not defined, still the ".driver.pm" is bind with a structure
with some random initial values.

Quoted 7 lines

We can use the mix of both?
__maybe_unused xyz_suspend(){}
__maybe_unused xyz_resume(){}
...
#ifdef CONFIG_PM_SLEEP
.driver.pm = &xyz_pm_ops;
#endif

I don't think we need the mix because when CONFIG_PM_SLEEP isn't defined, SIMPLE_DEV_PM_OPS() compiles to:

const struct dev_pm_ops xyz_pm_ops = { }

and the xyz_pm_ops struct should be zero-filled. The #ifdef around ".driver.pm = &xyz_pm_ops" doesn't buy us anything -- the space for the driver.pm pointer is there regardless, so we don't save any space, and the default initialization is zero-filled, so the result is the same.
_______________________________________________
Linux-kernel-mentees mailing list [email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#7 lore raw

Re: [Linux-kernel-mentees] [PATCH v1 2/2] realtek/8139cp: Remove Legacy Power Management

Quoted 18 lines
Quoted 7 lines

But in case of "__maybe_unused", we don't keep a check while binding ".driver.pm".
Hence, if CONFIG_PM_SLEEP is not defined, still the ".driver.pm" is bind with a structure
with some random initial values.

Quoted 7 lines

We can use the mix of both?
__maybe_unused xyz_suspend(){}
__maybe_unused xyz_resume(){}
...
#ifdef CONFIG_PM_SLEEP
.driver.pm = &xyz_pm_ops;
#endif

I don't think we need the mix because when CONFIG_PM_SLEEP isn't defined, SIMPLE_DEV_PM_OPS() compiles to:

Quoted 7 lines

const struct dev_pm_ops xyz_pm_ops = { }

and the xyz_pm_ops struct should be zero-filled. The #ifdef around ".driver.pm = &xyz_pm_ops" doesn't buy us anything -- the space for the driver.pm pointer is there regardless, so we don't save any space, and the default initialization is zero-filled, so the result is the same.

Then, I guess my step to remove "#ifdef CONFIG_PM" won't go complete waste, I should just use "__maybe_unused" with suspend() and resume() to suppress warnings. Right?

-- Vaibhav Gupta
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#8 lore raw

Re: [Linux-kernel-mentees] [PATCH v1 2/2] realtek/8139cp: Remove Legacy Power Management

Quoted 26 lines · Vaibhav Gupta
Quoted 18 lines
Quoted 7 lines

But in case of "__maybe_unused", we don't keep a check while binding ".driver.pm".
Hence, if CONFIG_PM_SLEEP is not defined, still the ".driver.pm" is bind with a structure
with some random initial values.

Quoted 7 lines

We can use the mix of both?
__maybe_unused xyz_suspend(){}
__maybe_unused xyz_resume(){}
...
#ifdef CONFIG_PM_SLEEP
.driver.pm = &xyz_pm_ops;
#endif

I don't think we need the mix because when CONFIG_PM_SLEEP isn't defined, SIMPLE_DEV_PM_OPS() compiles to:

Quoted 7 lines

const struct dev_pm_ops xyz_pm_ops = { }

and the xyz_pm_ops struct should be zero-filled. The #ifdef around ".driver.pm = &xyz_pm_ops" doesn't buy us anything -- the space for the driver.pm pointer is there regardless, so we don't save any space, and the default initialization is zero-filled, so the result is the same.

Quoted 3 lines

Then, I guess my step to remove "#ifdef CONFIG_PM" won't go complete waste, I should just use "__maybe_unused" with suspend() and resume() to suppress warnings. Right?

Yes, that's what I'd do. This is all window dressing; the important thing is getting the semantic change right, i.e., the transformations of the xyz_suspend() and xyz_resume() functions. This #ifdef and __maybe_unused stuff can be trivially changed if necessary.

Bjorn
_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#9 lore raw

Re: [Linux-kernel-mentees] [PATCH v1 2/2] realtek/8139cp: Remove Legacy Power Management

Quoted 28 lines · Bjorn Helgaas
Quoted 26 lines · Vaibhav Gupta
Quoted 25 lines
Quoted 7 lines

But in case of "__maybe_unused", we don't keep a check while binding ".driver.pm".
Hence, if CONFIG_PM_SLEEP is not defined, still the ".driver.pm" is bind with a structure
with some random initial values.

Quoted 7 lines

We can use the mix of both?
__maybe_unused xyz_suspend(){}
__maybe_unused xyz_resume(){}
...
#ifdef CONFIG_PM_SLEEP
.driver.pm = &xyz_pm_ops;
#endif

I don't think we need the mix because when CONFIG_PM_SLEEP isn't defined, SIMPLE_DEV_PM_OPS() compiles to:

const struct dev_pm_ops xyz_pm_ops = { }

and the xyz_pm_ops struct should be zero-filled. The #ifdef around ".driver.pm = &xyz_pm_ops" doesn't buy us anything -- the space for the driver.pm pointer is there regardless, so we don't save any space, and the default initialization is zero-filled, so the result is the same.

Quoted 8 lines
Quoted 3 lines

Then, I guess my step to remove "#ifdef CONFIG_PM" won't go complete waste, I should just use "__maybe_unused" with suspend() and resume() to suppress warnings. Right?

Yes, that's what I'd do. This is all window dressing; the important thing is getting the semantic change right, i.e., the transformations of the xyz_suspend() and xyz_resume() functions. This #ifdef and __maybe_unused stuff can be trivially changed if necessary.

Yes, I will send a new patch series for this one.

-- Vaibhav Gupta

Quoted 2 lines

Bjorn

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#10 lore raw
In reply to Vaibhav Gupta

If you post more that one patch in a series, it's best if you include a cover letter with the patches being responses to the cover letter. In this case, it would be:

[0/2] cover letter
-> [1/2] realtek/8139too: Remove ...
-> [2/2] realtek/8139cp: Remove ...

Quoted 54 lines · Vaibhav Gupta

Upgrade Power Management from legacy to generic using dev_pm_ops.

Remove struct pci_driver.suspend and struct pci_driver.resume bindings, and add struct pci_driver.driver.pm .

---
 drivers/net/ethernet/realtek/8139too.c | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)
drivers/net/ethernet/realtek/8139too.c +4 -13
index 5caeb8368eab..b7c98b165256 100644
@@ -2603,17 +2603,13 @@ static void rtl8139_set_rx_mode (struct net_device *dev)
 	spin_unlock_irqrestore (&tp->lock, flags);
 }
 
-#ifdef CONFIG_PM
-
-static int rtl8139_suspend (struct pci_dev *pdev, pm_message_t state)
+static int rtl8139_suspend(struct device *device)
 {
-	struct net_device *dev = pci_get_drvdata (pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 	struct rtl8139_private *tp = netdev_priv(dev);
 	void __iomem *ioaddr = tp->mmio_addr;
 	unsigned long flags;
 
-	pci_save_state (pdev);
-
 	if (!netif_running (dev))
 		return 0;
 
@@ -2631,38 +2627,30 @@ static int rtl8139_suspend (struct pci_dev *pdev, pm_message_t state)
 
 	spin_unlock_irqrestore (&tp->lock, flags);
 
-	pci_set_power_state (pdev, PCI_D3hot);
-
 	return 0;
 }
 
-
-static int rtl8139_resume (struct pci_dev *pdev)
+static int rtl8139_resume(struct device *device)
 {
-	struct net_device *dev = pci_get_drvdata (pdev);
+	struct net_device *dev = dev_get_drvdata(device);
 
-	pci_restore_state (pdev);
 	if (!netif_running (dev))
 		return 0;
-	pci_set_power_state (pdev, PCI_D0);

drivers/net/ethernet/realtek/8139too.c static int rtl8139_suspend (struct pci_dev *pdev, pm_message_t state) · line 2646

Quoted 10 lines
drivers/net/ethernet/realtek/8139too.c +2 -2
+
 	rtl8139_init_ring (dev);
 	rtl8139_hw_start (dev);
 	netif_device_attach (dev);
 	return 0;
 }
 
-#endif /* CONFIG_PM */
-
+static SIMPLE_DEV_PM_OPS(rtl8139_pm_ops, rtl8139_suspend, rtl8139_resume);

The common pattern here seems to be:

  #ifdef CONFIG_PM_SLEEP
  static int *_suspend(struct device *device) { ... }
  static int *_resume(struct device *device) { ... }
  #endif
  static SIMPLE_DEV_PM_OPS(*_pm_ops, *_suspend, *_resume);

So your patch looks great except that I think you should keep the #ifdef and convert it to CONFIG_PM_SLEEP.

Quoted 16 lines
drivers/net/ethernet/realtek/8139too.c +1 -4
 static struct pci_driver rtl8139_pci_driver = {
 	.name		= DRV_NAME,
 	.id_table	= rtl8139_pci_tbl,
 	.probe		= rtl8139_init_one,
 	.remove		= rtl8139_remove_one,
-#ifdef CONFIG_PM
-	.suspend	= rtl8139_suspend,
-	.resume		= rtl8139_resume,
-#endif /* CONFIG_PM */
+	.driver.pm	= &rtl8139_pm_ops,
 };
 
 
Signature · 1 line
2.26.2

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees

#11 lore raw
Quoted 8 lines · Bjorn Helgaas

If you post more that one patch in a series, it's best if you include a cover letter with the patches being responses to the cover letter. In this case, it would be:

[0/2] cover letter
-> [1/2] realtek/8139too: Remove ...
-> [2/2] realtek/8139cp: Remove ...

Okay! I will do it.

--Vaibhav Gupta

Quoted 37 lines · Vaibhav Gupta
Quoted 22 lines

Upgrade Power Management from legacy to generic using dev_pm_ops.

Remove struct pci_driver.suspend and struct pci_driver.resume bindings, and add struct pci_driver.driver.pm .

---
 drivers/net/ethernet/realtek/8139too.c | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)
drivers/net/ethernet/realtek/8139too.c +1 -3
index 5caeb8368eab..b7c98b165256 100644
@@ -2603,17 +2603,13 @@ static void rtl8139_set_rx_mode (struct net_device *dev)
      spin_unlock_irqrestore (&tp->lock, flags);
 }
 
-#ifdef CONFIG_PM
-
-static int rtl8139_suspend (struct pci_dev *pdev, pm_message_t state)
+static int rtl8139_suspend(struct device *device)

drivers/net/ethernet/realtek/8139too.c static void rtl8139_set_rx_mode (struct net_device *dev) · line 2614

Quoted 10 lines
drivers/net/ethernet/realtek/8139too.c +1 -2
 
      rtl8139_init_ring (dev);
      rtl8139_hw_start (dev);
      netif_device_attach (dev);
      return 0;
 }
 
-#endif /* CONFIG_PM */
-
+static SIMPLE_DEV_PM_OPS(rtl8139_pm_ops, rtl8139_suspend, rtl8139_resume);

The common pattern here seems to be:

Quoted 9 lines
  #ifdef CONFIG_PM_SLEEP
  static int *_suspend(struct device *device) { ... }
  static int *_resume(struct device *device) { ... }
  #endif
  static SIMPLE_DEV_PM_OPS(*_pm_ops, *_suspend, *_resume);

So your patch looks great except that I think you should keep the #ifdef and convert it to CONFIG_PM_SLEEP.

_______________________________________________
Linux-kernel-mentees mailing list
[email protected]
https://lists.linuxfoundation.org/mailman/listinfo/linux-kernel-mentees