2007-08-05 19:04:58

by Rafael J. Wysocki

[permalink] [raw]
Subject: [RFC][PATCH] uli526x: Add suspend and resume routines

[Sorry for the excessive CCs, but I don't know who's the maintainer. ;-)]
---
From: Rafael J. Wysocki <[email protected]>

Add suspend/resume support to the uli526x network driver (tested on x86_64,
with "Ethernet controller: ALi Corporation M5263 Ethernet Controller, rev 40").

This patch is based on the suspend/resume code in the tg3 driver.

Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/net/tulip/uli526x.c | 108 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 102 insertions(+), 6 deletions(-)

Index: linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
===================================================================
--- linux-2.6.23-rc2.orig/drivers/net/tulip/uli526x.c 2007-08-05 20:18:57.000000000 +0200
+++ linux-2.6.23-rc2/drivers/net/tulip/uli526x.c 2007-08-05 20:47:07.000000000 +0200
@@ -1110,19 +1110,15 @@ static void uli526x_timer(unsigned long


/*
- * Dynamic reset the ULI526X board
* Stop ULI526X board
* Free Tx/Rx allocated memory
- * Reset ULI526X board
- * Re-initialize ULI526X board
+ * Init system variable
*/

-static void uli526x_dynamic_reset(struct net_device *dev)
+static void uli526x_reset_prepare(struct net_device *dev)
{
struct uli526x_board_info *db = netdev_priv(dev);

- ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
-
/* Sopt MAC controller */
db->cr6_data &= ~(CR6_RXSC | CR6_TXSC); /* Disable Tx/Rx */
update_cr6(db->cr6_data, dev->base_addr);
@@ -1141,6 +1137,22 @@ static void uli526x_dynamic_reset(struct
db->link_failed = 1;
db->init=1;
db->wait_reset = 0;
+}
+
+
+/*
+ * Dynamic reset the ULI526X board
+ * Stop ULI526X board
+ * Free Tx/Rx allocated memory
+ * Reset ULI526X board
+ * Re-initialize ULI526X board
+ */
+
+static void uli526x_dynamic_reset(struct net_device *dev)
+{
+ ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
+
+ uli526x_reset_prepare(dev);

/* Re-initialize ULI526X board */
uli526x_init(dev);
@@ -1150,6 +1162,88 @@ static void uli526x_dynamic_reset(struct
}


+#ifdef CONFIG_PM_SLEEP
+
+/*
+ * Suspend the interface.
+ */
+
+static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+ struct net_device *dev = pci_get_drvdata(pdev);
+ int err = 0;
+
+ ULI526X_DBUG(0, "uli526x_suspend", 0);
+
+ if (dev && netdev_priv(dev)) {
+ pci_power_t power_state;
+
+ pci_save_state(pdev);
+
+ if (!netif_running(dev))
+ return 0;
+
+ netif_device_detach(dev);
+ uli526x_reset_prepare(dev);
+
+ power_state = pci_choose_state(pdev, state);
+ pci_enable_wake(pdev, power_state, 0);
+ err = pci_set_power_state(pdev, power_state);
+ if (err) {
+ netif_device_attach(dev);
+ /* Re-initialize ULI526X board */
+ uli526x_init(dev);
+ /* Restart upper layer interface */
+ netif_wake_queue(dev);
+ }
+ }
+ return err;
+}
+
+/*
+ * Resume the interface.
+ */
+
+static int uli526x_resume(struct pci_dev *pdev)
+{
+ struct net_device *dev = pci_get_drvdata(pdev);
+ struct uli526x_board_info *db = netdev_priv(dev);
+
+ ULI526X_DBUG(0, "uli526x_resume", 0);
+
+ if (dev && db) {
+ int err;
+
+ pci_restore_state(pdev);
+
+ if (!netif_running(dev))
+ return 0;
+
+ err = pci_set_power_state(pdev, PCI_D0);
+ if (err) {
+ printk(KERN_WARNING
+ "%s: Could not put device into D0\n",
+ dev->name);
+ return err;
+ }
+
+ netif_device_attach(dev);
+ /* Re-initialize ULI526X board */
+ uli526x_init(dev);
+ /* Restart upper layer interface */
+ netif_wake_queue(dev);
+ }
+ return 0;
+}
+
+#else /* !CONFIG_PM_SLEEP */
+
+#define uli526x_suspend NULL
+#define uli526x_resume NULL
+
+#endif /* !CONFIG_PM_SLEEP */
+
+
/*
* free all allocated rx buffer
*/
@@ -1689,6 +1783,8 @@ static struct pci_driver uli526x_driver
.id_table = uli526x_pci_tbl,
.probe = uli526x_init_one,
.remove = __devexit_p(uli526x_remove_one),
+ .suspend = uli526x_suspend,
+ .resume = uli526x_resume,
};

MODULE_AUTHOR("Peer Chen, [email protected]");


2007-08-07 22:05:09

by Jeff Garzik

[permalink] [raw]
Subject: Re: [RFC][PATCH] uli526x: Add suspend and resume routines

Rafael J. Wysocki wrote:
> +static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)
> +{
> + struct net_device *dev = pci_get_drvdata(pdev);
> + int err = 0;
> +
> + ULI526X_DBUG(0, "uli526x_suspend", 0);
> +
> + if (dev && netdev_priv(dev)) {
> + pci_power_t power_state;
> +
> + pci_save_state(pdev);
> +
> + if (!netif_running(dev))
> + return 0;
> +
> + netif_device_detach(dev);
> + uli526x_reset_prepare(dev);
> +
> + power_state = pci_choose_state(pdev, state);
> + pci_enable_wake(pdev, power_state, 0);
> + err = pci_set_power_state(pdev, power_state);
> + if (err) {
> + netif_device_attach(dev);
> + /* Re-initialize ULI526X board */
> + uli526x_init(dev);
> + /* Restart upper layer interface */
> + netif_wake_queue(dev);
> + }
> + }
> + return err;
> +}
> +
> +/*
> + * Resume the interface.
> + */
> +
> +static int uli526x_resume(struct pci_dev *pdev)
> +{
> + struct net_device *dev = pci_get_drvdata(pdev);
> + struct uli526x_board_info *db = netdev_priv(dev);
> +
> + ULI526X_DBUG(0, "uli526x_resume", 0);
> +
> + if (dev && db) {
> + int err;
> +
> + pci_restore_state(pdev);
> +
> + if (!netif_running(dev))
> + return 0;
> +
> + err = pci_set_power_state(pdev, PCI_D0);
> + if (err) {
> + printk(KERN_WARNING
> + "%s: Could not put device into D0\n",
> + dev->name);
> + return err;
> + }
> +
> + netif_device_attach(dev);
> + /* Re-initialize ULI526X board */
> + uli526x_init(dev);
> + /* Restart upper layer interface */
> + netif_wake_queue(dev);
> + }
> + return 0;


Ugh -- please fix indentation. This is not proper Linux code.

If you have the -vast majority- of code on an indented branch, as you
have here, then you should either add an early 'return x;' or a goto,
and unindent the main body of code.

I'll let our new tulip maintainer see what he thinks about the
implementation. Seems fairly sane to me, but should at least get an "it
works" test.

Jeff




2007-08-07 22:15:31

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [RFC][PATCH] uli526x: Add suspend and resume routines

On Tuesday, 7 August 2007 23:40, Jeff Garzik wrote:
> Rafael J. Wysocki wrote:
> > +static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)
> > +{
> > + struct net_device *dev = pci_get_drvdata(pdev);
> > + int err = 0;
> > +
> > + ULI526X_DBUG(0, "uli526x_suspend", 0);
> > +
> > + if (dev && netdev_priv(dev)) {
> > + pci_power_t power_state;
> > +
> > + pci_save_state(pdev);
> > +
> > + if (!netif_running(dev))
> > + return 0;
> > +
> > + netif_device_detach(dev);
> > + uli526x_reset_prepare(dev);
> > +
> > + power_state = pci_choose_state(pdev, state);
> > + pci_enable_wake(pdev, power_state, 0);
> > + err = pci_set_power_state(pdev, power_state);
> > + if (err) {
> > + netif_device_attach(dev);
> > + /* Re-initialize ULI526X board */
> > + uli526x_init(dev);
> > + /* Restart upper layer interface */
> > + netif_wake_queue(dev);
> > + }
> > + }
> > + return err;
> > +}
> > +
> > +/*
> > + * Resume the interface.
> > + */
> > +
> > +static int uli526x_resume(struct pci_dev *pdev)
> > +{
> > + struct net_device *dev = pci_get_drvdata(pdev);
> > + struct uli526x_board_info *db = netdev_priv(dev);
> > +
> > + ULI526X_DBUG(0, "uli526x_resume", 0);
> > +
> > + if (dev && db) {
> > + int err;
> > +
> > + pci_restore_state(pdev);
> > +
> > + if (!netif_running(dev))
> > + return 0;
> > +
> > + err = pci_set_power_state(pdev, PCI_D0);
> > + if (err) {
> > + printk(KERN_WARNING
> > + "%s: Could not put device into D0\n",
> > + dev->name);
> > + return err;
> > + }
> > +
> > + netif_device_attach(dev);
> > + /* Re-initialize ULI526X board */
> > + uli526x_init(dev);
> > + /* Restart upper layer interface */
> > + netif_wake_queue(dev);
> > + }
> > + return 0;
>
>
> Ugh -- please fix indentation. This is not proper Linux code.
>
> If you have the -vast majority- of code on an indented branch, as you
> have here, then you should either add an early 'return x;' or a goto,
> and unindent the main body of code.

OK, I will.

> I'll let our new tulip maintainer see what he thinks about the
> implementation. Seems fairly sane to me, but should at least get an "it
> works" test.

It has been tested, as stated in the changelog, and works (on my test system).

Greetings,
Rafael


--
"Premature optimization is the root of all evil." - Donald Knuth

2007-08-07 22:26:56

by Jeff Garzik

[permalink] [raw]
Subject: Re: [RFC][PATCH] uli526x: Add suspend and resume routines

Rafael J. Wysocki wrote:
> On Tuesday, 7 August 2007 23:40, Jeff Garzik wrote:
>> I'll let our new tulip maintainer see what he thinks about the
>> implementation. Seems fairly sane to me, but should at least get an "it
>> works" test.
>
> It has been tested, as stated in the changelog, and works (on my test system).


Apologies, I missed this. I'll look to our new tulip maintainer to
queue your resent patch, or at least ACK it...

Jeff


2007-08-07 22:47:48

by Rafael J. Wysocki

[permalink] [raw]
Subject: [RFC][PATCH] uli526x: Add suspend and resume routines (updated)

On Wednesday, 8 August 2007 00:26, Jeff Garzik wrote:
> Rafael J. Wysocki wrote:
> > On Tuesday, 7 August 2007 23:40, Jeff Garzik wrote:
> >> I'll let our new tulip maintainer see what he thinks about the
> >> implementation. Seems fairly sane to me, but should at least get an "it
> >> works" test.
> >
> > It has been tested, as stated in the changelog, and works (on my test system).
>
>
> Apologies, I missed this. I'll look to our new tulip maintainer to
> queue your resent patch, or at least ACK it...

OK

Below is the updated version. It's functionally equivalent to the previous one.

Greetings,
Rafael


---
From: Rafael J. Wysocki <[email protected]>

Add suspend/resume support to the uli526x network driver (tested on x86_64,
with 'Ethernet controller: ALi Corporation M5263 Ethernet Controller, rev 40').

This patch is based on the suspend/resume code in the tg3 driver.

Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/net/tulip/uli526x.c | 109 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 103 insertions(+), 6 deletions(-)

Index: linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
===================================================================
--- linux-2.6.23-rc2.orig/drivers/net/tulip/uli526x.c
+++ linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
@@ -1110,19 +1110,15 @@ static void uli526x_timer(unsigned long


/*
- * Dynamic reset the ULI526X board
* Stop ULI526X board
* Free Tx/Rx allocated memory
- * Reset ULI526X board
- * Re-initialize ULI526X board
+ * Init system variable
*/

-static void uli526x_dynamic_reset(struct net_device *dev)
+static void uli526x_reset_prepare(struct net_device *dev)
{
struct uli526x_board_info *db = netdev_priv(dev);

- ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
-
/* Sopt MAC controller */
db->cr6_data &= ~(CR6_RXSC | CR6_TXSC); /* Disable Tx/Rx */
update_cr6(db->cr6_data, dev->base_addr);
@@ -1141,6 +1137,22 @@ static void uli526x_dynamic_reset(struct
db->link_failed = 1;
db->init=1;
db->wait_reset = 0;
+}
+
+
+/*
+ * Dynamic reset the ULI526X board
+ * Stop ULI526X board
+ * Free Tx/Rx allocated memory
+ * Reset ULI526X board
+ * Re-initialize ULI526X board
+ */
+
+static void uli526x_dynamic_reset(struct net_device *dev)
+{
+ ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
+
+ uli526x_reset_prepare(dev);

/* Re-initialize ULI526X board */
uli526x_init(dev);
@@ -1150,6 +1162,89 @@ static void uli526x_dynamic_reset(struct
}


+#ifdef CONFIG_PM_SLEEP
+
+/*
+ * Suspend the interface.
+ */
+
+static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+ struct net_device *dev = pci_get_drvdata(pdev);
+ pci_power_t power_state;
+ int err;
+
+ ULI526X_DBUG(0, "uli526x_suspend", 0);
+
+ if (!(dev && netdev_priv(dev)))
+ return 0;
+
+ pci_save_state(pdev);
+
+ if (!netif_running(dev))
+ return 0;
+
+ netif_device_detach(dev);
+ uli526x_reset_prepare(dev);
+
+ power_state = pci_choose_state(pdev, state);
+ pci_enable_wake(pdev, power_state, 0);
+ err = pci_set_power_state(pdev, power_state);
+ if (err) {
+ netif_device_attach(dev);
+ /* Re-initialize ULI526X board */
+ uli526x_init(dev);
+ /* Restart upper layer interface */
+ netif_wake_queue(dev);
+ }
+
+ return err;
+}
+
+/*
+ * Resume the interface.
+ */
+
+static int uli526x_resume(struct pci_dev *pdev)
+{
+ struct net_device *dev = pci_get_drvdata(pdev);
+ struct uli526x_board_info *db = netdev_priv(dev);
+ int err;
+
+ ULI526X_DBUG(0, "uli526x_resume", 0);
+
+ if (!(dev && db))
+ return 0;
+
+ pci_restore_state(pdev);
+
+ if (!netif_running(dev))
+ return 0;
+
+ err = pci_set_power_state(pdev, PCI_D0);
+ if (err) {
+ printk(KERN_WARNING "%s: Could not put device into D0\n",
+ dev->name);
+ return err;
+ }
+
+ netif_device_attach(dev);
+ /* Re-initialize ULI526X board */
+ uli526x_init(dev);
+ /* Restart upper layer interface */
+ netif_wake_queue(dev);
+
+ return 0;
+}
+
+#else /* !CONFIG_PM_SLEEP */
+
+#define uli526x_suspend NULL
+#define uli526x_resume NULL
+
+#endif /* !CONFIG_PM_SLEEP */
+
+
/*
* free all allocated rx buffer
*/
@@ -1689,6 +1784,8 @@ static struct pci_driver uli526x_driver
.id_table = uli526x_pci_tbl,
.probe = uli526x_init_one,
.remove = __devexit_p(uli526x_remove_one),
+ .suspend = uli526x_suspend,
+ .resume = uli526x_resume,
};

MODULE_AUTHOR("Peer Chen, [email protected]");

2007-08-07 23:04:24

by Andrew Morton

[permalink] [raw]
Subject: Re: [RFC][PATCH] uli526x: Add suspend and resume routines

On Sun, 5 Aug 2007 21:14:01 +0200
"Rafael J. Wysocki" <[email protected]> wrote:

> +#ifdef CONFIG_PM_SLEEP
> +
> +/*
> + * Suspend the interface.
> + */
> +
> +static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)

Since when did suspend and resume methods become dependent upon CONFIG_PM_SLEEP?

We have eight thousand implementations of this, all of which presently
use CONFIG_PM.

2007-08-08 11:56:00

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [RFC][PATCH] uli526x: Add suspend and resume routines

On Wednesday, 8 August 2007 01:03, Andrew Morton wrote:
> On Sun, 5 Aug 2007 21:14:01 +0200
> "Rafael J. Wysocki" <[email protected]> wrote:
>
> > +#ifdef CONFIG_PM_SLEEP
> > +
> > +/*
> > + * Suspend the interface.
> > + */
> > +
> > +static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)
>
> Since when did suspend and resume methods become dependent upon CONFIG_PM_SLEEP?
>
> We have eight thousand implementations of this, all of which presently
> use CONFIG_PM.

Yes, they do, but if CONFIG_PM_SLEEP is not set, they won't be used.

Greetings,
Rafael

2007-08-08 12:00:27

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [RFC][PATCH] uli526x: Add suspend and resume routines

On Wednesday, 8 August 2007 14:05, Rafael J. Wysocki wrote:
> On Wednesday, 8 August 2007 01:03, Andrew Morton wrote:
> > On Sun, 5 Aug 2007 21:14:01 +0200
> > "Rafael J. Wysocki" <[email protected]> wrote:
> >
> > > +#ifdef CONFIG_PM_SLEEP
> > > +
> > > +/*
> > > + * Suspend the interface.
> > > + */
> > > +
> > > +static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)
> >
> > Since when did suspend and resume methods become dependent upon CONFIG_PM_SLEEP?
> >
> > We have eight thousand implementations of this, all of which presently
> > use CONFIG_PM.
>
> Yes, they do, but if CONFIG_PM_SLEEP is not set, they won't be used.

Well, not all of them. There are some in USB used for runtime power
management and there may be some others like that, but the majority of them
are really only useful for suspend/hibernation. Like the ones in this patch.

Greetings,
Rafael

2007-08-09 06:27:57

by Grant Grundler

[permalink] [raw]
Subject: Re: [RFC][PATCH] uli526x: Add suspend and resume routines (updated)

On Wed, Aug 08, 2007 at 12:56:41AM +0200, Rafael J. Wysocki wrote:
...
> > Apologies, I missed this. I'll look to our new tulip maintainer to
> > queue your resent patch, or at least ACK it...
>
> OK
>
> Below is the updated version. It's functionally equivalent to the previous one.

ACK. Looks fine to me too. I don't have the HW to test it though.

cheers,
grant

>
> Greetings,
> Rafael
>
>
> ---
> From: Rafael J. Wysocki <[email protected]>
>
> Add suspend/resume support to the uli526x network driver (tested on x86_64,
> with 'Ethernet controller: ALi Corporation M5263 Ethernet Controller, rev 40').
>
> This patch is based on the suspend/resume code in the tg3 driver.
>
> Signed-off-by: Rafael J. Wysocki <[email protected]>
> ---
> drivers/net/tulip/uli526x.c | 109 +++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 103 insertions(+), 6 deletions(-)
>
> Index: linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
> ===================================================================
> --- linux-2.6.23-rc2.orig/drivers/net/tulip/uli526x.c
> +++ linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
> @@ -1110,19 +1110,15 @@ static void uli526x_timer(unsigned long
>
>
> /*
> - * Dynamic reset the ULI526X board
> * Stop ULI526X board
> * Free Tx/Rx allocated memory
> - * Reset ULI526X board
> - * Re-initialize ULI526X board
> + * Init system variable
> */
>
> -static void uli526x_dynamic_reset(struct net_device *dev)
> +static void uli526x_reset_prepare(struct net_device *dev)
> {
> struct uli526x_board_info *db = netdev_priv(dev);
>
> - ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
> -
> /* Sopt MAC controller */
> db->cr6_data &= ~(CR6_RXSC | CR6_TXSC); /* Disable Tx/Rx */
> update_cr6(db->cr6_data, dev->base_addr);
> @@ -1141,6 +1137,22 @@ static void uli526x_dynamic_reset(struct
> db->link_failed = 1;
> db->init=1;
> db->wait_reset = 0;
> +}
> +
> +
> +/*
> + * Dynamic reset the ULI526X board
> + * Stop ULI526X board
> + * Free Tx/Rx allocated memory
> + * Reset ULI526X board
> + * Re-initialize ULI526X board
> + */
> +
> +static void uli526x_dynamic_reset(struct net_device *dev)
> +{
> + ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
> +
> + uli526x_reset_prepare(dev);
>
> /* Re-initialize ULI526X board */
> uli526x_init(dev);
> @@ -1150,6 +1162,89 @@ static void uli526x_dynamic_reset(struct
> }
>
>
> +#ifdef CONFIG_PM_SLEEP
> +
> +/*
> + * Suspend the interface.
> + */
> +
> +static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)
> +{
> + struct net_device *dev = pci_get_drvdata(pdev);
> + pci_power_t power_state;
> + int err;
> +
> + ULI526X_DBUG(0, "uli526x_suspend", 0);
> +
> + if (!(dev && netdev_priv(dev)))
> + return 0;
> +
> + pci_save_state(pdev);
> +
> + if (!netif_running(dev))
> + return 0;
> +
> + netif_device_detach(dev);
> + uli526x_reset_prepare(dev);
> +
> + power_state = pci_choose_state(pdev, state);
> + pci_enable_wake(pdev, power_state, 0);
> + err = pci_set_power_state(pdev, power_state);
> + if (err) {
> + netif_device_attach(dev);
> + /* Re-initialize ULI526X board */
> + uli526x_init(dev);
> + /* Restart upper layer interface */
> + netif_wake_queue(dev);
> + }
> +
> + return err;
> +}
> +
> +/*
> + * Resume the interface.
> + */
> +
> +static int uli526x_resume(struct pci_dev *pdev)
> +{
> + struct net_device *dev = pci_get_drvdata(pdev);
> + struct uli526x_board_info *db = netdev_priv(dev);
> + int err;
> +
> + ULI526X_DBUG(0, "uli526x_resume", 0);
> +
> + if (!(dev && db))
> + return 0;
> +
> + pci_restore_state(pdev);
> +
> + if (!netif_running(dev))
> + return 0;
> +
> + err = pci_set_power_state(pdev, PCI_D0);
> + if (err) {
> + printk(KERN_WARNING "%s: Could not put device into D0\n",
> + dev->name);
> + return err;
> + }
> +
> + netif_device_attach(dev);
> + /* Re-initialize ULI526X board */
> + uli526x_init(dev);
> + /* Restart upper layer interface */
> + netif_wake_queue(dev);
> +
> + return 0;
> +}
> +
> +#else /* !CONFIG_PM_SLEEP */
> +
> +#define uli526x_suspend NULL
> +#define uli526x_resume NULL
> +
> +#endif /* !CONFIG_PM_SLEEP */
> +
> +
> /*
> * free all allocated rx buffer
> */
> @@ -1689,6 +1784,8 @@ static struct pci_driver uli526x_driver
> .id_table = uli526x_pci_tbl,
> .probe = uli526x_init_one,
> .remove = __devexit_p(uli526x_remove_one),
> + .suspend = uli526x_suspend,
> + .resume = uli526x_resume,
> };
>
> MODULE_AUTHOR("Peer Chen, [email protected]");

2007-08-14 05:59:05

by Jeff Garzik

[permalink] [raw]
Subject: Re: [RFC][PATCH] uli526x: Add suspend and resume routines (updated)

Rafael J. Wysocki wrote:
> On Wednesday, 8 August 2007 00:26, Jeff Garzik wrote:
>> Rafael J. Wysocki wrote:
>>> On Tuesday, 7 August 2007 23:40, Jeff Garzik wrote:
>>>> I'll let our new tulip maintainer see what he thinks about the
>>>> implementation. Seems fairly sane to me, but should at least get an "it
>>>> works" test.
>>> It has been tested, as stated in the changelog, and works (on my test system).
>>
>> Apologies, I missed this. I'll look to our new tulip maintainer to
>> queue your resent patch, or at least ACK it...
>
> OK
>
> Below is the updated version. It's functionally equivalent to the previous one.
>
> Greetings,
> Rafael
>
>
> ---
> From: Rafael J. Wysocki <[email protected]>
>
> Add suspend/resume support to the uli526x network driver (tested on x86_64,
> with 'Ethernet controller: ALi Corporation M5263 Ethernet Controller, rev 40').
>
> This patch is based on the suspend/resume code in the tg3 driver.
>
> Signed-off-by: Rafael J. Wysocki <[email protected]>
> ---
> drivers/net/tulip/uli526x.c | 109 +++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 103 insertions(+), 6 deletions(-)
>
> Index: linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
> ===================================================================
> --- linux-2.6.23-rc2.orig/drivers/net/tulip/uli526x.c
> +++ linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
> @@ -1110,19 +1110,15 @@ static void uli526x_timer(unsigned long
>
>
> /*
> - * Dynamic reset the ULI526X board
> * Stop ULI526X board
> * Free Tx/Rx allocated memory
> - * Reset ULI526X board
> - * Re-initialize ULI526X board
> + * Init system variable
> */
>
> -static void uli526x_dynamic_reset(struct net_device *dev)
> +static void uli526x_reset_prepare(struct net_device *dev)
> {
> struct uli526x_board_info *db = netdev_priv(dev);
>
> - ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
> -
> /* Sopt MAC controller */
> db->cr6_data &= ~(CR6_RXSC | CR6_TXSC); /* Disable Tx/Rx */
> update_cr6(db->cr6_data, dev->base_addr);
> @@ -1141,6 +1137,22 @@ static void uli526x_dynamic_reset(struct
> db->link_failed = 1;
> db->init=1;
> db->wait_reset = 0;
> +}
> +
> +
> +/*
> + * Dynamic reset the ULI526X board
> + * Stop ULI526X board
> + * Free Tx/Rx allocated memory
> + * Reset ULI526X board
> + * Re-initialize ULI526X board
> + */
> +
> +static void uli526x_dynamic_reset(struct net_device *dev)
> +{
> + ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
> +
> + uli526x_reset_prepare(dev);
>
> /* Re-initialize ULI526X board */
> uli526x_init(dev);
> @@ -1150,6 +1162,89 @@ static void uli526x_dynamic_reset(struct
> }
>
>
> +#ifdef CONFIG_PM_SLEEP
> +
> +/*
> + * Suspend the interface.
> + */
> +
> +static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)
> +{
> + struct net_device *dev = pci_get_drvdata(pdev);
> + pci_power_t power_state;
> + int err;
> +
> + ULI526X_DBUG(0, "uli526x_suspend", 0);
> +
> + if (!(dev && netdev_priv(dev)))
> + return 0;

> +static int uli526x_resume(struct pci_dev *pdev)
> +{
> + struct net_device *dev = pci_get_drvdata(pdev);
> + struct uli526x_board_info *db = netdev_priv(dev);
> + int err;
> +
> + ULI526X_DBUG(0, "uli526x_resume", 0);
> +
> + if (!(dev && db))
> + return 0;


Two comments:

1) Like akpm, the CONFIG_PM_SLEEP is out of place. All other drivers
use CONFIG_PM

2) just remove the !dev checks, that is an impossible condition

2007-08-14 17:59:53

by Rafael J. Wysocki

[permalink] [raw]
Subject: Re: [RFC][PATCH] uli526x: Add suspend and resume routines (updated)

On Tuesday, 14 August 2007 07:58, Jeff Garzik wrote:
> Rafael J. Wysocki wrote:
> > On Wednesday, 8 August 2007 00:26, Jeff Garzik wrote:
> >> Rafael J. Wysocki wrote:
> >>> On Tuesday, 7 August 2007 23:40, Jeff Garzik wrote:
> >>>> I'll let our new tulip maintainer see what he thinks about the
> >>>> implementation. Seems fairly sane to me, but should at least get an "it
> >>>> works" test.
> >>> It has been tested, as stated in the changelog, and works (on my test system).
[--snip--]

> Two comments:
>
> 1) Like akpm, the CONFIG_PM_SLEEP is out of place. All other drivers
> use CONFIG_PM

OK

> 2) just remove the !dev checks, that is an impossible condition

OK

Updated patch follows.

---
From: Rafael J. Wysocki <[email protected]>

Add suspend/resume support to the uli526x network driver (tested on x86_64,
with 'Ethernet controller: ALi Corporation M5263 Ethernet Controller, rev 40').

This patch is based on the suspend/resume code in the tg3 driver.

Signed-off-by: Rafael J. Wysocki <[email protected]>
---
drivers/net/tulip/uli526x.c | 108 +++++++++++++++++++++++++++++++++++++++++---
1 file changed, 102 insertions(+), 6 deletions(-)

Index: linux-2.6.23-rc3/drivers/net/tulip/uli526x.c
===================================================================
--- linux-2.6.23-rc3.orig/drivers/net/tulip/uli526x.c
+++ linux-2.6.23-rc3/drivers/net/tulip/uli526x.c
@@ -1110,19 +1110,15 @@ static void uli526x_timer(unsigned long


/*
- * Dynamic reset the ULI526X board
* Stop ULI526X board
* Free Tx/Rx allocated memory
- * Reset ULI526X board
- * Re-initialize ULI526X board
+ * Init system variable
*/

-static void uli526x_dynamic_reset(struct net_device *dev)
+static void uli526x_reset_prepare(struct net_device *dev)
{
struct uli526x_board_info *db = netdev_priv(dev);

- ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
-
/* Sopt MAC controller */
db->cr6_data &= ~(CR6_RXSC | CR6_TXSC); /* Disable Tx/Rx */
update_cr6(db->cr6_data, dev->base_addr);
@@ -1141,6 +1137,22 @@ static void uli526x_dynamic_reset(struct
db->link_failed = 1;
db->init=1;
db->wait_reset = 0;
+}
+
+
+/*
+ * Dynamic reset the ULI526X board
+ * Stop ULI526X board
+ * Free Tx/Rx allocated memory
+ * Reset ULI526X board
+ * Re-initialize ULI526X board
+ */
+
+static void uli526x_dynamic_reset(struct net_device *dev)
+{
+ ULI526X_DBUG(0, "uli526x_dynamic_reset()", 0);
+
+ uli526x_reset_prepare(dev);

/* Re-initialize ULI526X board */
uli526x_init(dev);
@@ -1150,6 +1162,88 @@ static void uli526x_dynamic_reset(struct
}


+#ifdef CONFIG_PM
+
+/*
+ * Suspend the interface.
+ */
+
+static int uli526x_suspend(struct pci_dev *pdev, pm_message_t state)
+{
+ struct net_device *dev = pci_get_drvdata(pdev);
+ pci_power_t power_state;
+ int err;
+
+ ULI526X_DBUG(0, "uli526x_suspend", 0);
+
+ if (!netdev_priv(dev))
+ return 0;
+
+ pci_save_state(pdev);
+
+ if (!netif_running(dev))
+ return 0;
+
+ netif_device_detach(dev);
+ uli526x_reset_prepare(dev);
+
+ power_state = pci_choose_state(pdev, state);
+ pci_enable_wake(pdev, power_state, 0);
+ err = pci_set_power_state(pdev, power_state);
+ if (err) {
+ netif_device_attach(dev);
+ /* Re-initialize ULI526X board */
+ uli526x_init(dev);
+ /* Restart upper layer interface */
+ netif_wake_queue(dev);
+ }
+
+ return err;
+}
+
+/*
+ * Resume the interface.
+ */
+
+static int uli526x_resume(struct pci_dev *pdev)
+{
+ struct net_device *dev = pci_get_drvdata(pdev);
+ int err;
+
+ ULI526X_DBUG(0, "uli526x_resume", 0);
+
+ if (!netdev_priv(dev))
+ return 0;
+
+ pci_restore_state(pdev);
+
+ if (!netif_running(dev))
+ return 0;
+
+ err = pci_set_power_state(pdev, PCI_D0);
+ if (err) {
+ printk(KERN_WARNING "%s: Could not put device into D0\n",
+ dev->name);
+ return err;
+ }
+
+ netif_device_attach(dev);
+ /* Re-initialize ULI526X board */
+ uli526x_init(dev);
+ /* Restart upper layer interface */
+ netif_wake_queue(dev);
+
+ return 0;
+}
+
+#else /* !CONFIG_PM */
+
+#define uli526x_suspend NULL
+#define uli526x_resume NULL
+
+#endif /* !CONFIG_PM */
+
+
/*
* free all allocated rx buffer
*/
@@ -1689,6 +1783,8 @@ static struct pci_driver uli526x_driver
.id_table = uli526x_pci_tbl,
.probe = uli526x_init_one,
.remove = __devexit_p(uli526x_remove_one),
+ .suspend = uli526x_suspend,
+ .resume = uli526x_resume,
};

MODULE_AUTHOR("Peer Chen, [email protected]");

2007-08-31 12:52:28

by Jeff Garzik

[permalink] [raw]
Subject: Re: [RFC][PATCH] uli526x: Add suspend and resume routines (updated)

Rafael J. Wysocki wrote:
> On Tuesday, 14 August 2007 07:58, Jeff Garzik wrote:
>> Rafael J. Wysocki wrote:
>>> On Wednesday, 8 August 2007 00:26, Jeff Garzik wrote:
>>>> Rafael J. Wysocki wrote:
>>>>> On Tuesday, 7 August 2007 23:40, Jeff Garzik wrote:
>>>>>> I'll let our new tulip maintainer see what he thinks about the
>>>>>> implementation. Seems fairly sane to me, but should at least get an "it
>>>>>> works" test.
>>>>> It has been tested, as stated in the changelog, and works (on my test system).
> [--snip--]
>
>> Two comments:
>>
>> 1) Like akpm, the CONFIG_PM_SLEEP is out of place. All other drivers
>> use CONFIG_PM
>
> OK
>
>> 2) just remove the !dev checks, that is an impossible condition
>
> OK
>
> Updated patch follows.
>
> ---
> From: Rafael J. Wysocki <[email protected]>
>
> Add suspend/resume support to the uli526x network driver (tested on x86_64,
> with 'Ethernet controller: ALi Corporation M5263 Ethernet Controller, rev 40').
>
> This patch is based on the suspend/resume code in the tg3 driver.
>
> Signed-off-by: Rafael J. Wysocki <[email protected]>
> ---
> drivers/net/tulip/uli526x.c | 108 +++++++++++++++++++++++++++++++++++++++++---
> 1 file changed, 102 insertions(+), 6 deletions(-)

applied