Skip to contentSkip to conversation

uli526x: Add suspend and resume routines

RFC PATCH In review Rafael J. Wysocki 4 participants 21 messages Aug 5, 2007 – Aug 31, 2007 Network drivers

lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 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.

---
 drivers/net/tulip/uli526x.c |  108 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 102 insertions(+), 6 deletions(-)
drivers/net/tulip/uli526x.c +102 -6
Index: 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,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]");
#1 lore raw
Quoted 56 lines · Rafael J. Wysocki
drivers/net/tulip/uli526x.c +56 -0
+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);

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1236

Quoted 10 lines
drivers/net/tulip/uli526x.c +10 -0
+			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

#2 lore raw
In reply to Rafael J. Wysocki
Quoted 56 lines · Rafael J. Wysocki
drivers/net/tulip/uli526x.c +56 -0
+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);

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1236

Quoted 10 lines
drivers/net/tulip/uli526x.c +10 -0
+			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

#3 lore raw
Quoted 71 lines · Jeff Garzik
Quoted 56 lines · Rafael J. Wysocki
drivers/net/tulip/uli526x.c +56 -0
+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);

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1236

Quoted 10 lines
drivers/net/tulip/uli526x.c +10 -0
+			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.

Quoted 3 lines

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.

Quoted 3 lines

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

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#4 lore raw
Quoted 4 lines · Rafael J. Wysocki
Quoted 1 line · Jeff Garzik

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

#5 lore raw
In reply to Rafael J. Wysocki
Quoted 4 lines · Rafael J. Wysocki
Quoted 1 line · Jeff Garzik

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

#6 lore raw

RFC PATCH 1/1 uli526x: Add suspend and resume routines (updated)

Quoted 11 lines · Jeff Garzik
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines · Jeff Garzik

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.

---
 drivers/net/tulip/uli526x.c |  109 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 103 insertions(+), 6 deletions(-)
drivers/net/tulip/uli526x.c +103 -6
Index: 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]");
#7 lore raw

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

On Wed, Aug 08, 2007 at 12:56:41AM +0200, Rafael J. Wysocki wrote:
...

Quoted 6 lines
Quoted 2 lines

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

Quoted 166 lines

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.

---
 drivers/net/tulip/uli526x.c |  109 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 103 insertions(+), 6 deletions(-)

Index: linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
===================================================================

drivers/net/tulip/uli526x.c +103 -6
@@ -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]");
#8 lore raw

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

In reply to Rafael J. Wysocki

On Wed, Aug 08, 2007 at 12:56:41AM +0200, Rafael J. Wysocki wrote:
...

Quoted 6 lines
Quoted 2 lines

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

Quoted 166 lines

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.

---
 drivers/net/tulip/uli526x.c |  109 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 103 insertions(+), 6 deletions(-)

Index: linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
===================================================================

drivers/net/tulip/uli526x.c +103 -6
@@ -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]");
#9 lore raw

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

In reply to Rafael J. Wysocki
Quoted 99 lines · Rafael J. Wysocki
Quoted 6 lines · Jeff Garzik
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line · Jeff Garzik

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.

---
 drivers/net/tulip/uli526x.c |  109 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 103 insertions(+), 6 deletions(-)

Index: linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
===================================================================

drivers/net/tulip/uli526x.c +34 -6
@@ -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;
 

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1191

Quoted 10 lines
drivers/net/tulip/uli526x.c +10 -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

#10 lore raw

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

In reply to Rafael J. Wysocki
Quoted 99 lines · Rafael J. Wysocki
Quoted 6 lines · Jeff Garzik
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line · Jeff Garzik

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.

---
 drivers/net/tulip/uli526x.c |  109 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 103 insertions(+), 6 deletions(-)

Index: linux-2.6.23-rc2/drivers/net/tulip/uli526x.c
===================================================================

drivers/net/tulip/uli526x.c +34 -6
@@ -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;
 

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1191

Quoted 10 lines
drivers/net/tulip/uli526x.c +10 -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

#11 lore raw

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

Quoted 8 lines · Jeff Garzik
Quoted 7 lines · Rafael J. Wysocki
Quoted 6 lines · Jeff Garzik
Quoted 5 lines · Rafael J. Wysocki
Quoted 3 lines · Jeff Garzik

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--]

Quoted 4 lines

Two comments:

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

OK

Quoted 1 line

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.

---
 drivers/net/tulip/uli526x.c |  108 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 102 insertions(+), 6 deletions(-)
drivers/net/tulip/uli526x.c +102 -6
Index: 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]");
Applied
#12 lore raw

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

Quoted 27 lines · Rafael J. Wysocki
Quoted 6 lines · Jeff Garzik
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Jeff Garzik
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line · Jeff Garzik

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--]

Quoted 3 lines

Two comments:

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

OK

Quoted 1 line

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').

Quoted 6 lines

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

---
 drivers/net/tulip/uli526x.c |  108 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 102 insertions(+), 6 deletions(-)

applied

Applied
#13 lore raw

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

In reply to Rafael J. Wysocki
Quoted 27 lines · Rafael J. Wysocki
Quoted 6 lines · Jeff Garzik
Quoted 5 lines · Rafael J. Wysocki
Quoted 4 lines · Jeff Garzik
Quoted 3 lines · Rafael J. Wysocki
Quoted 1 line · Jeff Garzik

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--]

Quoted 3 lines

Two comments:

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

OK

Quoted 1 line

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').

Quoted 6 lines

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

---
 drivers/net/tulip/uli526x.c |  108 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 102 insertions(+), 6 deletions(-)

applied

#14 lore raw

RFC PATCH 1/1 uli526x: Add suspend and resume routines (updated)

In reply to Jeff Garzik
Quoted 11 lines · Jeff Garzik
Quoted 6 lines · Rafael J. Wysocki
Quoted 3 lines · Jeff Garzik

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.

---
 drivers/net/tulip/uli526x.c |  109 +++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 103 insertions(+), 6 deletions(-)
drivers/net/tulip/uli526x.c +103 -6
Index: 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]");
#15 lore raw
In reply to Jeff Garzik
Quoted 71 lines · Jeff Garzik
Quoted 56 lines · Rafael J. Wysocki
drivers/net/tulip/uli526x.c +56 -0
+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);

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1236

Quoted 10 lines
drivers/net/tulip/uli526x.c +10 -0
+			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.

Quoted 3 lines

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.

Quoted 3 lines

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

Signature · 1 line
"Premature optimization is the root of all evil." - Donald Knuth
#16 lore raw
In reply to Rafael J. Wysocki

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1171

Quoted 7 lines · On Sun, 5 Aug 2007 21:14:01 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
drivers/net/tulip/uli526x.c +7 -0
+#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.

#17 lore raw
In reply to Rafael J. Wysocki

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1171

Quoted 7 lines · On Sun, 5 Aug 2007 21:14:01 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
drivers/net/tulip/uli526x.c +7 -0
+#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.

#18 lore raw
Quoted 13 lines · Andrew Morton

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1171

Quoted 7 lines · On Sun, 5 Aug 2007 21:14:01 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
drivers/net/tulip/uli526x.c +7 -0
+#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?

Quoted 2 lines

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

#19 lore raw
Quoted 14 lines · Rafael J. Wysocki
Quoted 13 lines · Andrew Morton

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1171

Quoted 7 lines · On Sun, 5 Aug 2007 21:14:01 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
drivers/net/tulip/uli526x.c +7 -0
+#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?

Quoted 4 lines
Quoted 2 lines

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

#20 lore raw
In reply to Andrew Morton
Quoted 13 lines · Andrew Morton

drivers/net/tulip/uli526x.c static void uli526x_dynamic_reset(struct · line 1171

Quoted 7 lines · On Sun, 5 Aug 2007 21:14:01 +0200 "Rafael J. Wysocki" <[email protected]> wrote:
drivers/net/tulip/uli526x.c +7 -0
+#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?

Quoted 2 lines

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