LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [RFC][PATCH] uli526x: Add suspend and resume routines
@ 2007-08-05 19:14 Rafael J. Wysocki
  2007-08-07 21:40 ` Jeff Garzik
  2007-08-07 23:03 ` [RFC][PATCH] uli526x: Add suspend and resume routines Andrew Morton
  0 siblings, 2 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2007-08-05 19:14 UTC (permalink / raw)
  To: LKML; +Cc: Jeff Garzik, pm list, Grant Grundler, Kyle McMartin

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

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 <rjw@sisk.pl>
---
 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, peer.chen@uli.com.tw");

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC][PATCH] uli526x: Add suspend and resume routines
  2007-08-05 19:14 [RFC][PATCH] uli526x: Add suspend and resume routines Rafael J. Wysocki
@ 2007-08-07 21:40 ` Jeff Garzik
  2007-08-07 22:24   ` Rafael J. Wysocki
  2007-08-07 23:03 ` [RFC][PATCH] uli526x: Add suspend and resume routines Andrew Morton
  1 sibling, 1 reply; 12+ messages in thread
From: Jeff Garzik @ 2007-08-07 21:40 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: LKML, pm list, Grant Grundler, Kyle McMartin

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





^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC][PATCH] uli526x: Add suspend and resume routines
  2007-08-07 21:40 ` Jeff Garzik
@ 2007-08-07 22:24   ` Rafael J. Wysocki
  2007-08-07 22:26     ` Jeff Garzik
  0 siblings, 1 reply; 12+ messages in thread
From: Rafael J. Wysocki @ 2007-08-07 22:24 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: LKML, pm list, Grant Grundler, Kyle McMartin

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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC][PATCH] uli526x: Add suspend and resume routines
  2007-08-07 22:24   ` Rafael J. Wysocki
@ 2007-08-07 22:26     ` Jeff Garzik
  2007-08-07 22:56       ` [RFC][PATCH] uli526x: Add suspend and resume routines (updated) Rafael J. Wysocki
  0 siblings, 1 reply; 12+ messages in thread
From: Jeff Garzik @ 2007-08-07 22:26 UTC (permalink / raw)
  To: Rafael J. Wysocki, Kyle McMartin; +Cc: LKML, pm list, Grant Grundler

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



^ permalink raw reply	[flat|nested] 12+ messages in thread

* [RFC][PATCH] uli526x: Add suspend and resume routines (updated)
  2007-08-07 22:26     ` Jeff Garzik
@ 2007-08-07 22:56       ` Rafael J. Wysocki
  2007-08-09  6:27         ` Grant Grundler
  2007-08-14  5:58         ` Jeff Garzik
  0 siblings, 2 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2007-08-07 22:56 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Kyle McMartin, LKML, pm list, Grant Grundler

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 <rjw@sisk.pl>

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 <rjw@sisk.pl>
---
 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, peer.chen@uli.com.tw");

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC][PATCH] uli526x: Add suspend and resume routines
  2007-08-05 19:14 [RFC][PATCH] uli526x: Add suspend and resume routines Rafael J. Wysocki
  2007-08-07 21:40 ` Jeff Garzik
@ 2007-08-07 23:03 ` Andrew Morton
  2007-08-08 12:05   ` Rafael J. Wysocki
  1 sibling, 1 reply; 12+ messages in thread
From: Andrew Morton @ 2007-08-07 23:03 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: LKML, Jeff Garzik, pm list, Grant Grundler, Kyle McMartin

On Sun, 5 Aug 2007 21:14:01 +0200
"Rafael J. Wysocki" <rjw@sisk.pl> 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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC][PATCH] uli526x: Add suspend and resume routines
  2007-08-07 23:03 ` [RFC][PATCH] uli526x: Add suspend and resume routines Andrew Morton
@ 2007-08-08 12:05   ` Rafael J. Wysocki
  2007-08-08 12:09     ` Rafael J. Wysocki
  0 siblings, 1 reply; 12+ messages in thread
From: Rafael J. Wysocki @ 2007-08-08 12:05 UTC (permalink / raw)
  To: Andrew Morton; +Cc: LKML, Jeff Garzik, pm list, Grant Grundler, Kyle McMartin

On Wednesday, 8 August 2007 01:03, Andrew Morton wrote:
> On Sun, 5 Aug 2007 21:14:01 +0200
> "Rafael J. Wysocki" <rjw@sisk.pl> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC][PATCH] uli526x: Add suspend and resume routines
  2007-08-08 12:05   ` Rafael J. Wysocki
@ 2007-08-08 12:09     ` Rafael J. Wysocki
  0 siblings, 0 replies; 12+ messages in thread
From: Rafael J. Wysocki @ 2007-08-08 12:09 UTC (permalink / raw)
  To: Andrew Morton; +Cc: LKML, Jeff Garzik, pm list, Grant Grundler, Kyle McMartin

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" <rjw@sisk.pl> 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

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC][PATCH] uli526x: Add suspend and resume routines (updated)
  2007-08-07 22:56       ` [RFC][PATCH] uli526x: Add suspend and resume routines (updated) Rafael J. Wysocki
@ 2007-08-09  6:27         ` Grant Grundler
  2007-08-14  5:58         ` Jeff Garzik
  1 sibling, 0 replies; 12+ messages in thread
From: Grant Grundler @ 2007-08-09  6:27 UTC (permalink / raw)
  To: Rafael J. Wysocki
  Cc: Jeff Garzik, Kyle McMartin, LKML, pm list, Grant Grundler

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 <rjw@sisk.pl>
> 
> 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 <rjw@sisk.pl>
> ---
>  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, peer.chen@uli.com.tw");

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC][PATCH] uli526x: Add suspend and resume routines (updated)
  2007-08-07 22:56       ` [RFC][PATCH] uli526x: Add suspend and resume routines (updated) Rafael J. Wysocki
  2007-08-09  6:27         ` Grant Grundler
@ 2007-08-14  5:58         ` Jeff Garzik
  2007-08-14 18:09           ` Rafael J. Wysocki
  1 sibling, 1 reply; 12+ messages in thread
From: Jeff Garzik @ 2007-08-14  5:58 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Kyle McMartin, LKML, pm list, Grant Grundler

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 <rjw@sisk.pl>
> 
> 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 <rjw@sisk.pl>
> ---
>  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


^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC][PATCH] uli526x: Add suspend and resume routines (updated)
  2007-08-14  5:58         ` Jeff Garzik
@ 2007-08-14 18:09           ` Rafael J. Wysocki
  2007-08-31 12:52             ` Jeff Garzik
  0 siblings, 1 reply; 12+ messages in thread
From: Rafael J. Wysocki @ 2007-08-14 18:09 UTC (permalink / raw)
  To: Jeff Garzik; +Cc: Kyle McMartin, LKML, pm list, Grant Grundler

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 <rjw@sisk.pl>

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 <rjw@sisk.pl>
---
 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, peer.chen@uli.com.tw");

^ permalink raw reply	[flat|nested] 12+ messages in thread

* Re: [RFC][PATCH] uli526x: Add suspend and resume routines (updated)
  2007-08-14 18:09           ` Rafael J. Wysocki
@ 2007-08-31 12:52             ` Jeff Garzik
  0 siblings, 0 replies; 12+ messages in thread
From: Jeff Garzik @ 2007-08-31 12:52 UTC (permalink / raw)
  To: Rafael J. Wysocki; +Cc: Kyle McMartin, LKML, pm list, Grant Grundler

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 <rjw@sisk.pl>
> 
> 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 <rjw@sisk.pl>
> ---
>  drivers/net/tulip/uli526x.c |  108 +++++++++++++++++++++++++++++++++++++++++---
>  1 file changed, 102 insertions(+), 6 deletions(-)

applied



^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2007-08-31 12:52 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-05 19:14 [RFC][PATCH] uli526x: Add suspend and resume routines Rafael J. Wysocki
2007-08-07 21:40 ` Jeff Garzik
2007-08-07 22:24   ` Rafael J. Wysocki
2007-08-07 22:26     ` Jeff Garzik
2007-08-07 22:56       ` [RFC][PATCH] uli526x: Add suspend and resume routines (updated) Rafael J. Wysocki
2007-08-09  6:27         ` Grant Grundler
2007-08-14  5:58         ` Jeff Garzik
2007-08-14 18:09           ` Rafael J. Wysocki
2007-08-31 12:52             ` Jeff Garzik
2007-08-07 23:03 ` [RFC][PATCH] uli526x: Add suspend and resume routines Andrew Morton
2007-08-08 12:05   ` Rafael J. Wysocki
2007-08-08 12:09     ` Rafael J. Wysocki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).