All of lore.kernel.org
 help / color / mirror / Atom feed
* Cleanup PCI power states
@ 2004-11-16 13:04 Pavel Machek
  2004-11-16 15:56 ` Greg KH
  0 siblings, 1 reply; 26+ messages in thread
From: Pavel Machek @ 2004-11-16 13:04 UTC (permalink / raw)
  To: kernel list, Andrew Morton, Greg KH

Hi!

This is step 0 before adding type-safety to PCI layer... It introduces
constants and uses them to clean driver up. I'd like this to go in
now, so that I can convert drivers during 2.6.10... Please apply,

								Pavel

[amd8111e.c piece below shows exactly why this is needed; feel free to
apply it or not...]

--- clean/include/linux/pci.h	2004-10-01 00:30:30.000000000 +0200
+++ linux/include/linux/pci.h	2004-11-14 23:36:46.000000000 +0100
@@ -480,6 +480,14 @@
 #define DEVICE_COUNT_COMPATIBLE	4
 #define DEVICE_COUNT_RESOURCE	12
 
+typedef int __bitwise pci_power_t;
+
+#define PCI_D0	((pci_power_t __force) 0)
+#define PCI_D1	((pci_power_t __force) 1)
+#define PCI_D2	((pci_power_t __force) 2)
+#define PCI_D3hot	((pci_power_t __force) 3)
+#define PCI_D3cold	((pci_power_t __force) 4)
+
 /*
  * The pci_dev structure is used to describe PCI devices.
  */
--- clean/drivers/net/amd8111e.c	2004-10-01 00:30:15.000000000 +0200
+++ linux/drivers/net/amd8111e.c	2004-11-14 23:48:04.000000000 +0100
@@ -1865,17 +1865,17 @@
 		if(lp->options & OPTION_WAKE_PHY_ENABLE)
 			amd8111e_enable_link_change(lp);	
 		
-		pci_enable_wake(pci_dev, 3, 1);
-		pci_enable_wake(pci_dev, 4, 1); /* D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 1);
+		pci_enable_wake(pci_dev, PCI_D3cold, 1);
 
 	}
 	else{		
-		pci_enable_wake(pci_dev, 3, 0);
-		pci_enable_wake(pci_dev, 4, 0); /* 4 == D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 0);
+		pci_enable_wake(pci_dev, PCI_D3cold, 0);
 	}
 	
 	pci_save_state(pci_dev, lp->pm_state);
-	pci_set_power_state(pci_dev, 3);
+	pci_set_power_state(pci_dev, PCI_D3hot);
 
 	return 0;
 }
@@ -1887,11 +1887,11 @@
 	if (!netif_running(dev))
 		return 0;
 
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 	pci_restore_state(pci_dev, lp->pm_state);
 
-	pci_enable_wake(pci_dev, 3, 0);
-	pci_enable_wake(pci_dev, 4, 0); /* D3 cold */
+	pci_enable_wake(pci_dev, PCI_D3hot, 0);
+	pci_enable_wake(pci_dev, PCI_D3cold, 0);
 
 	netif_device_attach(dev);
 


-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

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

* Re: Cleanup PCI power states
  2004-11-16 13:04 Cleanup PCI power states Pavel Machek
@ 2004-11-16 15:56 ` Greg KH
  2004-11-17 12:08   ` Pavel Machek
  0 siblings, 1 reply; 26+ messages in thread
From: Greg KH @ 2004-11-16 15:56 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list, Andrew Morton

On Tue, Nov 16, 2004 at 02:04:45PM +0100, Pavel Machek wrote:
> Hi!
> 
> This is step 0 before adding type-safety to PCI layer... It introduces
> constants and uses them to clean driver up. I'd like this to go in
> now, so that I can convert drivers during 2.6.10... Please apply,

The tree is in "bugfix only" mode right now.  Changes like this need to
wait for 2.6.10 to come out before I can send it upward.

So, care to hold on to it for a while?  Or I can add it to my "to apply
after 2.6.10 comes out" tree, which will mean it will end up in the -mm
releases till that happens.

thanks,

greg k-h

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

* Re: Cleanup PCI power states
  2004-11-16 15:56 ` Greg KH
@ 2004-11-17 12:08   ` Pavel Machek
  2004-11-24 23:40     ` Greg KH
  0 siblings, 1 reply; 26+ messages in thread
From: Pavel Machek @ 2004-11-17 12:08 UTC (permalink / raw)
  To: Greg KH; +Cc: Pavel Machek, kernel list, Andrew Morton

Hi!

> > This is step 0 before adding type-safety to PCI layer... It introduces
> > constants and uses them to clean driver up. I'd like this to go in
> > now, so that I can convert drivers during 2.6.10... Please apply,
> 
> The tree is in "bugfix only" mode right now.  Changes like this need to
> wait for 2.6.10 to come out before I can send it upward.
> 
> So, care to hold on to it for a while?  Or I can add it to my "to apply
> after 2.6.10 comes out" tree, which will mean it will end up in the -mm
> releases till that happens.

I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,
				Pavel
-- 
64 bytes from 195.113.31.123: icmp_seq=28 ttl=51 time=448769.1 ms         


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

* Re: Cleanup PCI power states
  2004-11-17 12:08   ` Pavel Machek
@ 2004-11-24 23:40     ` Greg KH
  2004-11-25 11:36       ` Pavel Machek
  2004-11-25 11:39       ` Pavel Machek
  0 siblings, 2 replies; 26+ messages in thread
From: Greg KH @ 2004-11-24 23:40 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list, Andrew Morton

On Wed, Nov 17, 2004 at 01:08:58PM +0100, Pavel Machek wrote:
> Hi!
> 
> > > This is step 0 before adding type-safety to PCI layer... It introduces
> > > constants and uses them to clean driver up. I'd like this to go in
> > > now, so that I can convert drivers during 2.6.10... Please apply,
> > 
> > The tree is in "bugfix only" mode right now.  Changes like this need to
> > wait for 2.6.10 to come out before I can send it upward.
> > 
> > So, care to hold on to it for a while?  Or I can add it to my "to apply
> > after 2.6.10 comes out" tree, which will mean it will end up in the -mm
> > releases till that happens.
> 
> I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,

Care to resend this, I seem to have lost them :(

thanks,

greg k-h

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

* Re: Cleanup PCI power states
  2004-11-24 23:40     ` Greg KH
@ 2004-11-25 11:36       ` Pavel Machek
  2004-12-17  0:05         ` Greg KH
  2004-12-17 22:02         ` Greg KH
  2004-11-25 11:39       ` Pavel Machek
  1 sibling, 2 replies; 26+ messages in thread
From: Pavel Machek @ 2004-11-25 11:36 UTC (permalink / raw)
  To: Greg KH; +Cc: kernel list, Andrew Morton

Hi!

> > > > This is step 0 before adding type-safety to PCI layer... It introduces
> > > > constants and uses them to clean driver up. I'd like this to go in
> > > > now, so that I can convert drivers during 2.6.10... Please apply,
> > > 
> > > The tree is in "bugfix only" mode right now.  Changes like this need to
> > > wait for 2.6.10 to come out before I can send it upward.
> > > 
> > > So, care to hold on to it for a while?  Or I can add it to my "to apply
> > > after 2.6.10 comes out" tree, which will mean it will end up in the -mm
> > > releases till that happens.
> > 
> > I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,
> 
> Care to resend this, I seem to have lost them :(

Okay, here it is, slightly expanded version. It actually makes use of
newly defined type for type-checking purposes; still no code changes.

								Pavel

--- clean/include/linux/pci.h	2004-10-01 00:30:30.000000000 +0200
+++ linux/include/linux/pci.h	2004-11-14 23:36:46.000000000 +0100
@@ -480,6 +480,14 @@
 #define DEVICE_COUNT_COMPATIBLE	4
 #define DEVICE_COUNT_RESOURCE	12
 
+typedef int __bitwise pci_power_t;
+
+#define PCI_D0	((pci_power_t __force) 0)
+#define PCI_D1	((pci_power_t __force) 1)
+#define PCI_D2	((pci_power_t __force) 2)
+#define PCI_D3hot	((pci_power_t __force) 3)
+#define PCI_D3cold	((pci_power_t __force) 4)
+
 /*
  * The pci_dev structure is used to describe PCI devices.
  */
@@ -508,7 +516,7 @@
 					   this if your device has broken DMA
 					   or supports 64-bit transfers.  */
 
-	u32             current_state;  /* Current operating state. In ACPI-speak,
+	pci_power_t     current_state;  /* Current operating state. In ACPI-speak,
 					   this is D0-D3, D0 being fully functional,
 					   and D3 being off. */
 
@@ -645,7 +653,7 @@
 	struct pci_dynids dynids;
 };
 
-#define	to_pci_driver(drv) container_of(drv,struct pci_driver, driver)
+#define	to_pci_driver(drv) container_of(drv, struct pci_driver, driver)
 
 /**
  * PCI_DEVICE - macro used to describe a specific pci device
@@ -781,8 +789,8 @@
 /* Power management related routines */
 int pci_save_state(struct pci_dev *dev, u32 *buffer);
 int pci_restore_state(struct pci_dev *dev, u32 *buffer);
-int pci_set_power_state(struct pci_dev *dev, int state);
-int pci_enable_wake(struct pci_dev *dev, u32 state, int enable);
+int pci_set_power_state(struct pci_dev *dev, pci_power_t state);
+int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable);
 
 /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
 void pci_bus_assign_resources(struct pci_bus *bus);
--- clean/drivers/pci/pci.c	2004-10-01 00:30:16.000000000 +0200
+++ linux/drivers/pci/pci.c	2004-11-14 23:36:46.000000000 +0100
@@ -229,7 +229,7 @@
 /**
  * pci_set_power_state - Set the power state of a PCI device
  * @dev: PCI device to be suspended
- * @state: Power state we're entering
+ * @state: PCI power state (D0, D1, D2, D3hot, D3cold) we're entering
  *
  * Transition a device to a new power state, using the Power Management 
  * Capabilities in the device's config space.
@@ -242,7 +242,7 @@
  */
 
 int
-pci_set_power_state(struct pci_dev *dev, int state)
+pci_set_power_state(struct pci_dev *dev, pci_power_t state)
 {
 	int pm;
 	u16 pmcsr;
@@ -365,7 +389,7 @@
 {
 	int err;
 
-	pci_set_power_state(dev, 0);
+	pci_set_power_state(dev, PCI_D0);
 	if ((err = pcibios_enable_device(dev, bars)) < 0)
 		return err;
 	return 0;
@@ -422,7 +446,7 @@
  * 0 if operation is successful.
  * 
  */
-int pci_enable_wake(struct pci_dev *dev, u32 state, int enable)
+int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
 {
 	int pm;
 	u16 value;


-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

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

* Re: Cleanup PCI power states
  2004-11-24 23:40     ` Greg KH
  2004-11-25 11:36       ` Pavel Machek
@ 2004-11-25 11:39       ` Pavel Machek
  2004-12-17  0:06         ` Greg KH
  2004-12-17 22:02         ` Greg KH
  1 sibling, 2 replies; 26+ messages in thread
From: Pavel Machek @ 2004-11-25 11:39 UTC (permalink / raw)
  To: Greg KH; +Cc: kernel list, Andrew Morton

Hi!

> > > > This is step 0 before adding type-safety to PCI layer... It introduces
> > > > constants and uses them to clean driver up. I'd like this to go in
> > > > now, so that I can convert drivers during 2.6.10... Please apply,
> > > 
> > > The tree is in "bugfix only" mode right now.  Changes like this need to
> > > wait for 2.6.10 to come out before I can send it upward.
> > > 
> > > So, care to hold on to it for a while?  Or I can add it to my "to apply
> > > after 2.6.10 comes out" tree, which will mean it will end up in the -mm
> > > releases till that happens.
> > 
> > I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,
> 
> Care to resend this, I seem to have lost them :(

Could this go to "after 2.6.10 tree", too? It is a helper that
converts system state into PCI state. We really do not want to have
this copied into every driver, because it will need to change when
system state gets type-checked / expanded to struct.

								Pavel

--- clean/drivers/pci/pci.c	2004-10-01 00:30:16.000000000 +0200
+++ linux/drivers/pci/pci.c	2004-11-14 23:36:46.000000000 +0100
@@ -300,6 +300,30 @@
 }
 
 /**
+ * pci_choose_state - Choose the power state of a PCI device
+ * @dev: PCI device to be suspended
+ * @state: target sleep state for the whole system
+ *
+ * Returns PCI power state suitable for given device and given system
+ * message.
+ */
+
+pci_power_t pci_choose_state(struct pci_dev *dev, u32 state)
+{
+	if (!pci_find_capability(dev, PCI_CAP_ID_PM))
+		return PCI_D0;
+
+	switch (state) {
+	case 0:	return PCI_D0;
+	case 2: return PCI_D2;
+	case 3: return PCI_D3hot;
+	default: BUG();
+	}
+}
+
+EXPORT_SYMBOL(pci_choose_state);
+
+/**
  * pci_save_state - save the PCI configuration space of a device before suspending
  * @dev: - PCI device that we're dealing with
  * @buffer: - buffer to hold config space context

-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

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

* Re: Cleanup PCI power states
  2004-11-25 11:36       ` Pavel Machek
@ 2004-12-17  0:05         ` Greg KH
  2004-12-17  0:31           ` Pavel Machek
  2004-12-17 16:12           ` [linux-pm] " Alan Stern
  2004-12-17 22:02         ` Greg KH
  1 sibling, 2 replies; 26+ messages in thread
From: Greg KH @ 2004-12-17  0:05 UTC (permalink / raw)
  To: Pavel Machek, linux-pm; +Cc: kernel list, Andrew Morton

On Thu, Nov 25, 2004 at 12:36:31PM +0100, Pavel Machek wrote:
> Hi!
> 
> > > > > This is step 0 before adding type-safety to PCI layer... It introduces
> > > > > constants and uses them to clean driver up. I'd like this to go in
> > > > > now, so that I can convert drivers during 2.6.10... Please apply,
> > > > 
> > > > The tree is in "bugfix only" mode right now.  Changes like this need to
> > > > wait for 2.6.10 to come out before I can send it upward.
> > > > 
> > > > So, care to hold on to it for a while?  Or I can add it to my "to apply
> > > > after 2.6.10 comes out" tree, which will mean it will end up in the -mm
> > > > releases till that happens.
> > > 
> > > I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,
> > 
> > Care to resend this, I seem to have lost them :(
> 
> Okay, here it is, slightly expanded version. It actually makes use of
> newly defined type for type-checking purposes; still no code changes.

Hm, ok, can everyone agree (especially the linux-pm list people) that
the patch below is the way we are all moving toward?

Because, if so, I'll apply this and then start working on fixing all of
the sparse warnings this will cause.

thanks,

greg k-h


> --- clean/include/linux/pci.h	2004-10-01 00:30:30.000000000 +0200
> +++ linux/include/linux/pci.h	2004-11-14 23:36:46.000000000 +0100
> @@ -480,6 +480,14 @@
>  #define DEVICE_COUNT_COMPATIBLE	4
>  #define DEVICE_COUNT_RESOURCE	12
>  
> +typedef int __bitwise pci_power_t;
> +
> +#define PCI_D0	((pci_power_t __force) 0)
> +#define PCI_D1	((pci_power_t __force) 1)
> +#define PCI_D2	((pci_power_t __force) 2)
> +#define PCI_D3hot	((pci_power_t __force) 3)
> +#define PCI_D3cold	((pci_power_t __force) 4)
> +
>  /*
>   * The pci_dev structure is used to describe PCI devices.
>   */
> @@ -508,7 +516,7 @@
>  					   this if your device has broken DMA
>  					   or supports 64-bit transfers.  */
>  
> -	u32             current_state;  /* Current operating state. In ACPI-speak,
> +	pci_power_t     current_state;  /* Current operating state. In ACPI-speak,
>  					   this is D0-D3, D0 being fully functional,
>  					   and D3 being off. */
>  
> @@ -645,7 +653,7 @@
>  	struct pci_dynids dynids;
>  };
>  
> -#define	to_pci_driver(drv) container_of(drv,struct pci_driver, driver)
> +#define	to_pci_driver(drv) container_of(drv, struct pci_driver, driver)
>  
>  /**
>   * PCI_DEVICE - macro used to describe a specific pci device
> @@ -781,8 +789,8 @@
>  /* Power management related routines */
>  int pci_save_state(struct pci_dev *dev, u32 *buffer);
>  int pci_restore_state(struct pci_dev *dev, u32 *buffer);
> -int pci_set_power_state(struct pci_dev *dev, int state);
> -int pci_enable_wake(struct pci_dev *dev, u32 state, int enable);
> +int pci_set_power_state(struct pci_dev *dev, pci_power_t state);
> +int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable);
>  
>  /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
>  void pci_bus_assign_resources(struct pci_bus *bus);
> --- clean/drivers/pci/pci.c	2004-10-01 00:30:16.000000000 +0200
> +++ linux/drivers/pci/pci.c	2004-11-14 23:36:46.000000000 +0100
> @@ -229,7 +229,7 @@
>  /**
>   * pci_set_power_state - Set the power state of a PCI device
>   * @dev: PCI device to be suspended
> - * @state: Power state we're entering
> + * @state: PCI power state (D0, D1, D2, D3hot, D3cold) we're entering
>   *
>   * Transition a device to a new power state, using the Power Management 
>   * Capabilities in the device's config space.
> @@ -242,7 +242,7 @@
>   */
>  
>  int
> -pci_set_power_state(struct pci_dev *dev, int state)
> +pci_set_power_state(struct pci_dev *dev, pci_power_t state)
>  {
>  	int pm;
>  	u16 pmcsr;
> @@ -365,7 +389,7 @@
>  {
>  	int err;
>  
> -	pci_set_power_state(dev, 0);
> +	pci_set_power_state(dev, PCI_D0);
>  	if ((err = pcibios_enable_device(dev, bars)) < 0)
>  		return err;
>  	return 0;
> @@ -422,7 +446,7 @@
>   * 0 if operation is successful.
>   * 
>   */
> -int pci_enable_wake(struct pci_dev *dev, u32 state, int enable)
> +int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable)
>  {
>  	int pm;
>  	u16 value;
> 
> 
> -- 
> People were complaining that M$ turns users into beta-testers...
> ...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

-- 

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

* Re: Cleanup PCI power states
  2004-11-25 11:39       ` Pavel Machek
@ 2004-12-17  0:06         ` Greg KH
  2004-12-17  0:34           ` Pavel Machek
  2004-12-17  7:48           ` [linux-pm] " Benjamin Herrenschmidt
  2004-12-17 22:02         ` Greg KH
  1 sibling, 2 replies; 26+ messages in thread
From: Greg KH @ 2004-12-17  0:06 UTC (permalink / raw)
  To: Pavel Machek, linux-pm; +Cc: kernel list, Andrew Morton

On Thu, Nov 25, 2004 at 12:39:13PM +0100, Pavel Machek wrote:
> Hi!
> 
> > > > > This is step 0 before adding type-safety to PCI layer... It introduces
> > > > > constants and uses them to clean driver up. I'd like this to go in
> > > > > now, so that I can convert drivers during 2.6.10... Please apply,
> > > > 
> > > > The tree is in "bugfix only" mode right now.  Changes like this need to
> > > > wait for 2.6.10 to come out before I can send it upward.
> > > > 
> > > > So, care to hold on to it for a while?  Or I can add it to my "to apply
> > > > after 2.6.10 comes out" tree, which will mean it will end up in the -mm
> > > > releases till that happens.
> > > 
> > > I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,
> > 
> > Care to resend this, I seem to have lost them :(
> 
> Could this go to "after 2.6.10 tree", too? It is a helper that
> converts system state into PCI state. We really do not want to have
> this copied into every driver, because it will need to change when
> system state gets type-checked / expanded to struct.

So this is how you want to switch stuff over?  Can you give me an
example of how this will be used?

> --- clean/drivers/pci/pci.c	2004-10-01 00:30:16.000000000 +0200
> +++ linux/drivers/pci/pci.c	2004-11-14 23:36:46.000000000 +0100
> @@ -300,6 +300,30 @@
>  }
>  
>  /**
> + * pci_choose_state - Choose the power state of a PCI device
> + * @dev: PCI device to be suspended
> + * @state: target sleep state for the whole system
> + *
> + * Returns PCI power state suitable for given device and given system
> + * message.
> + */
> +
> +pci_power_t pci_choose_state(struct pci_dev *dev, u32 state)
> +{
> +	if (!pci_find_capability(dev, PCI_CAP_ID_PM))
> +		return PCI_D0;
> +
> +	switch (state) {
> +	case 0:	return PCI_D0;
> +	case 2: return PCI_D2;
> +	case 3: return PCI_D3hot;
> +	default: BUG();
> +	}
> +}
> +
> +EXPORT_SYMBOL(pci_choose_state);

EXPORT_SYMBOL_GPL() perhaps?

thanks,

greg k-h

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

* Re: Cleanup PCI power states
  2004-12-17  0:05         ` Greg KH
@ 2004-12-17  0:31           ` Pavel Machek
  2004-12-17 16:12           ` [linux-pm] " Alan Stern
  1 sibling, 0 replies; 26+ messages in thread
From: Pavel Machek @ 2004-12-17  0:31 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-pm, kernel list, Andrew Morton

Hi!

> > Okay, here it is, slightly expanded version. It actually makes use of
> > newly defined type for type-checking purposes; still no code changes.
> 
> Hm, ok, can everyone agree (especially the linux-pm list people) that
> the patch below is the way we are all moving toward?
> 
> Because, if so, I'll apply this and then start working on fixing all of
> the sparse warnings this will cause.

I do have some warning-fixes here, too. So if you apply it tell me and
I'll generate a copy for you.

									Pavel
-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

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

* Re: Cleanup PCI power states
  2004-12-17  0:06         ` Greg KH
@ 2004-12-17  0:34           ` Pavel Machek
  2004-12-17  7:48           ` [linux-pm] " Benjamin Herrenschmidt
  1 sibling, 0 replies; 26+ messages in thread
From: Pavel Machek @ 2004-12-17  0:34 UTC (permalink / raw)
  To: Greg KH; +Cc: linux-pm, kernel list, Andrew Morton

Hi!

> > > Care to resend this, I seem to have lost them :(
> > 
> > Could this go to "after 2.6.10 tree", too? It is a helper that
> > converts system state into PCI state. We really do not want to have
> > this copied into every driver, because it will need to change when
> > system state gets type-checked / expanded to struct.
> 
> So this is how you want to switch stuff over?  Can you give me an
> example of how this will be used?

Yes. Some way to convert between system-state and pci-state is needed;
for now it only silences warning, but I guess it will get more complex
in future.

Example is here:

--- clean/drivers/net/e100.c	2004-10-01 00:30:15.000000000 +0200
+++ linux/drivers/net/e100.c	2004-11-14 23:36:46.000000000 +0100
@@ -2313,7 +2313,7 @@
 	pci_save_state(pdev, nic->pm_state);
 	pci_enable_wake(pdev, state, nic->flags & (wol_magic | e100_asf(nic)));
 	pci_disable_device(pdev);
-	pci_set_power_state(pdev, state);
+	pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
 	return 0;
 }
@@ -2323,7 +2323,7 @@
 	struct net_device *netdev = pci_get_drvdata(pdev);
 	struct nic *nic = netdev_priv(netdev);
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev, nic->pm_state);
 	e100_hw_init(nic);
 

> > --- clean/drivers/pci/pci.c	2004-10-01 00:30:16.000000000 +0200
> > +++ linux/drivers/pci/pci.c	2004-11-14 23:36:46.000000000 +0100
> > @@ -300,6 +300,30 @@
> >  }
> >  
> >  /**
> > + * pci_choose_state - Choose the power state of a PCI device
> > + * @dev: PCI device to be suspended
> > + * @state: target sleep state for the whole system
> > + *
> > + * Returns PCI power state suitable for given device and given system
> > + * message.
> > + */
> > +
> > +pci_power_t pci_choose_state(struct pci_dev *dev, u32 state)
> > +{
> > +	if (!pci_find_capability(dev, PCI_CAP_ID_PM))
> > +		return PCI_D0;
> > +
> > +	switch (state) {
> > +	case 0:	return PCI_D0;
> > +	case 2: return PCI_D2;
> > +	case 3: return PCI_D3hot;
> > +	default: BUG();
> > +	}
> > +}
> > +
> > +EXPORT_SYMBOL(pci_choose_state);
> 
> EXPORT_SYMBOL_GPL() perhaps?

Ugh, I do not have any strong feelings here, but I want nvidia etc to
use this one so that they implement driver model properly.

								Pavel
-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

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

* Re: [linux-pm] Re: Cleanup PCI power states
  2004-12-17  0:06         ` Greg KH
  2004-12-17  0:34           ` Pavel Machek
@ 2004-12-17  7:48           ` Benjamin Herrenschmidt
  2004-12-17 19:22             ` Greg KH
  1 sibling, 1 reply; 26+ messages in thread
From: Benjamin Herrenschmidt @ 2004-12-17  7:48 UTC (permalink / raw)
  To: Greg KH
  Cc: Pavel Machek, Linux-pm mailing list, Andrew Morton, Linux Kernel list

On Thu, 2004-12-16 at 16:06 -0800, Greg KH wrote:

> > +EXPORT_SYMBOL(pci_choose_state);
> 
> EXPORT_SYMBOL_GPL() perhaps?

Ugh ? Why GPL only ? That's meant to be used by pretty much all
pci_driver's

Ben.


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

* Re: [linux-pm] Re: Cleanup PCI power states
  2004-12-17  0:05         ` Greg KH
  2004-12-17  0:31           ` Pavel Machek
@ 2004-12-17 16:12           ` Alan Stern
  2004-12-17 16:33             ` Pavel Machek
  1 sibling, 1 reply; 26+ messages in thread
From: Alan Stern @ 2004-12-17 16:12 UTC (permalink / raw)
  To: Greg KH; +Cc: Pavel Machek, linux-pm, Andrew Morton, kernel list

On Thu, 16 Dec 2004, Greg KH wrote:

> Hm, ok, can everyone agree (especially the linux-pm list people) that
> the patch below is the way we are all moving toward?

Yes, provided it is clear that this code only gives a _default_ mapping 
and that drivers will have access to the complete pm_message_t data so 
they can choose a different mapping if they want.

Alan Stern


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

* Re: [linux-pm] Re: Cleanup PCI power states
  2004-12-17 16:12           ` [linux-pm] " Alan Stern
@ 2004-12-17 16:33             ` Pavel Machek
  0 siblings, 0 replies; 26+ messages in thread
From: Pavel Machek @ 2004-12-17 16:33 UTC (permalink / raw)
  To: Alan Stern; +Cc: Greg KH, linux-pm, Andrew Morton, kernel list

Hi!

> > Hm, ok, can everyone agree (especially the linux-pm list people) that
> > the patch below is the way we are all moving toward?
> 
> Yes, provided it is clear that this code only gives a _default_ mapping 
> and that drivers will have access to the complete pm_message_t data so 
> they can choose a different mapping if they want.

Yes, that's the plan.
									Pavel
-- 
Boycott Kodak -- for their patent abuse against Java.

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

* Re: [linux-pm] Re: Cleanup PCI power states
  2004-12-17  7:48           ` [linux-pm] " Benjamin Herrenschmidt
@ 2004-12-17 19:22             ` Greg KH
  0 siblings, 0 replies; 26+ messages in thread
From: Greg KH @ 2004-12-17 19:22 UTC (permalink / raw)
  To: Benjamin Herrenschmidt
  Cc: Pavel Machek, Linux-pm mailing list, Andrew Morton, Linux Kernel list

On Fri, Dec 17, 2004 at 08:48:46AM +0100, Benjamin Herrenschmidt wrote:
> On Thu, 2004-12-16 at 16:06 -0800, Greg KH wrote:
> 
> > > +EXPORT_SYMBOL(pci_choose_state);
> > 
> > EXPORT_SYMBOL_GPL() perhaps?
> 
> Ugh ? Why GPL only ? That's meant to be used by pretty much all
> pci_driver's

Ok, fine.  I just have to ask the question :)

greg k-h

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

* Re: Cleanup PCI power states
  2004-11-25 11:36       ` Pavel Machek
  2004-12-17  0:05         ` Greg KH
@ 2004-12-17 22:02         ` Greg KH
  2004-12-17 23:39           ` Pavel Machek
                             ` (2 more replies)
  1 sibling, 3 replies; 26+ messages in thread
From: Greg KH @ 2004-12-17 22:02 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list, Andrew Morton

On Thu, Nov 25, 2004 at 12:36:31PM +0100, Pavel Machek wrote:
> Hi!
> 
> > > > > This is step 0 before adding type-safety to PCI layer... It introduces
> > > > > constants and uses them to clean driver up. I'd like this to go in
> > > > > now, so that I can convert drivers during 2.6.10... Please apply,
> > > > 
> > > > The tree is in "bugfix only" mode right now.  Changes like this need to
> > > > wait for 2.6.10 to come out before I can send it upward.
> > > > 
> > > > So, care to hold on to it for a while?  Or I can add it to my "to apply
> > > > after 2.6.10 comes out" tree, which will mean it will end up in the -mm
> > > > releases till that happens.
> > > 
> > > I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,
> > 
> > Care to resend this, I seem to have lost them :(
> 
> Okay, here it is, slightly expanded version. It actually makes use of
> newly defined type for type-checking purposes; still no code changes.

Alright, I've applied this, and it will show up in the next -mm release.
I also fixed up pci.h for when CONFIG_PCI=N due to your changed
functions.

Now, care to send patches to fix up all of the new sparse warnings in
the drivers/pci/* directory?

Also, next time I need a "Signed-off-by:" line for the patch.

thanks,

greg k-h

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

* Re: Cleanup PCI power states
  2004-11-25 11:39       ` Pavel Machek
  2004-12-17  0:06         ` Greg KH
@ 2004-12-17 22:02         ` Greg KH
  1 sibling, 0 replies; 26+ messages in thread
From: Greg KH @ 2004-12-17 22:02 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list, Andrew Morton

On Thu, Nov 25, 2004 at 12:39:13PM +0100, Pavel Machek wrote:
> Hi!
> 
> > > > > This is step 0 before adding type-safety to PCI layer... It introduces
> > > > > constants and uses them to clean driver up. I'd like this to go in
> > > > > now, so that I can convert drivers during 2.6.10... Please apply,
> > > > 
> > > > The tree is in "bugfix only" mode right now.  Changes like this need to
> > > > wait for 2.6.10 to come out before I can send it upward.
> > > > 
> > > > So, care to hold on to it for a while?  Or I can add it to my "to apply
> > > > after 2.6.10 comes out" tree, which will mean it will end up in the -mm
> > > > releases till that happens.
> > > 
> > > I think I'd prefer visibility of "to apply after 2.6.10" tree... Thanks,
> > 
> > Care to resend this, I seem to have lost them :(
> 
> Could this go to "after 2.6.10 tree", too? It is a helper that
> converts system state into PCI state. We really do not want to have
> this copied into every driver, because it will need to change when
> system state gets type-checked / expanded to struct.

Applied, but you might want to modify pci.h so people can actually call
this function :)

thanks,

greg k-h

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

* Re: Cleanup PCI power states
  2004-12-17 22:02         ` Greg KH
@ 2004-12-17 23:39           ` Pavel Machek
  2004-12-21 19:57             ` Greg KH
  2004-12-17 23:50           ` Pavel Machek
  2004-12-18  0:09           ` Pavel Machek
  2 siblings, 1 reply; 26+ messages in thread
From: Pavel Machek @ 2004-12-17 23:39 UTC (permalink / raw)
  To: Greg KH; +Cc: kernel list, Andrew Morton

Hi!

> > Okay, here it is, slightly expanded version. It actually makes use of
> > newly defined type for type-checking purposes; still no code changes.
> 
> Alright, I've applied this, and it will show up in the next -mm release.
> I also fixed up pci.h for when CONFIG_PCI=N due to your changed
> functions.

Thanks... Hopefully I guessed the change right, otherwise this will
need to be applied by hand.

This adds missing prototype for pci_choose_state.								

Signed-off-by: Pavel Machek <pavel@suse.cz>

--- linux.middle//include/linux/pci.h	2004-11-14 23:36:46.000000000 +0100
+++ linux/include/linux/pci.h	2004-12-18 00:35:33.000000000 +0100
@@ -790,6 +790,7 @@
 int pci_save_state(struct pci_dev *dev, u32 *buffer);
 int pci_restore_state(struct pci_dev *dev, u32 *buffer);
 int pci_set_power_state(struct pci_dev *dev, pci_power_t state);
+pci_power_t pci_choose_state(struct pci_dev *dev, u32 state);
 int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable);
 
 /* Helper functions for low-level code (drivers/pci/setup-[bus,res].c) */
@@ -924,6 +925,7 @@
 static inline int pci_save_state(struct pci_dev *dev, u32 *buffer) { return 0; }
 static inline int pci_restore_state(struct pci_dev *dev, u32 *buffer) { return 0; }
 static inline int pci_set_power_state(struct pci_dev *dev, pci_power_t state) { return 0; }
+static inline pci_power_t pci_choose_state(struct pci_dev *dev, u32 state) { return PCI_D0; }
 static inline int pci_enable_wake(struct pci_dev *dev, pci_power_t state, int enable) { return 0; }
 
 #define	isa_bridge	((struct pci_dev *)NULL)


-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

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

* Re: Cleanup PCI power states
  2004-12-17 22:02         ` Greg KH
  2004-12-17 23:39           ` Pavel Machek
@ 2004-12-17 23:50           ` Pavel Machek
  2004-12-21 20:03             ` Greg KH
  2004-12-18  0:09           ` Pavel Machek
  2 siblings, 1 reply; 26+ messages in thread
From: Pavel Machek @ 2004-12-17 23:50 UTC (permalink / raw)
  To: Greg KH; +Cc: kernel list, Andrew Morton, torvalds

Hi!

> > Okay, here it is, slightly expanded version. It actually makes use of
> > newly defined type for type-checking purposes; still no code changes.
> 
> Alright, I've applied this, and it will show up in the next -mm release.
> I also fixed up pci.h for when CONFIG_PCI=N due to your changed
> functions.
> 
> Now, care to send patches to fix up all of the new sparse warnings in
> the drivers/pci/* directory?

This should reduce number of warnings in pci.c. It will still warn on
comparison (because we are using __bitwise, but in fact we want
something like "this is unique but arithmetic is still ok"), but that
probably needs to be fixed in sparse.

Also killed "function does not return anything" warning.

Please apply,
								Pavel

Signed-off-by: Pavel Machek <pavel@suse.cz>

--- linux.middle//drivers/pci/pci.c	2004-11-14 23:36:46.000000000 +0100
+++ linux/drivers/pci/pci.c	2004-12-18 00:47:53.000000000 +0100
@@ -248,13 +248,13 @@
 	u16 pmcsr;
 
 	/* bound the state we're entering */
-	if (state > 3) state = 3;
+	if (state > PCI_D3hot) state = PCI_D3hot;
 
 	/* Validate current state:
 	 * Can enter D0 from any state, but if we can only go deeper 
 	 * to sleep if we're already in a low power state
 	 */
-	if (state > 0 && dev->current_state > state)
+	if (state != PCI_D0 && dev->current_state > state)
 		return -EINVAL;
 	else if (dev->current_state == state) 
 		return 0;        /* we're already there */
@@ -266,18 +266,18 @@
 	if (!pm) return -EIO; 
 
 	/* check if this device supports the desired state */
-	if (state == 1 || state == 2) {
+	if (state == PCI_D1 || state == PCI_D2) {
 		u16 pmc;
 		pci_read_config_word(dev,pm + PCI_PM_PMC,&pmc);
-		if (state == 1 && !(pmc & PCI_PM_CAP_D1)) return -EIO;
-		else if (state == 2 && !(pmc & PCI_PM_CAP_D2)) return -EIO;
+		if (state == PCI_D1 && !(pmc & PCI_PM_CAP_D1)) return -EIO;
+		else if (state == PCI_D2 && !(pmc & PCI_PM_CAP_D2)) return -EIO;
 	}
 
 	/* If we're in D3, force entire word to 0.
 	 * This doesn't affect PME_Status, disables PME_En, and
 	 * sets PowerState to 0.
 	 */
-	if (dev->current_state >= 3)
+	if (dev->current_state >= PCI_D3hot)
 		pmcsr = 0;
 	else {
 		pci_read_config_word(dev, pm + PCI_PM_CTRL, &pmcsr);
@@ -290,9 +290,9 @@
 
 	/* Mandatory power management transition delays */
 	/* see PCI PM 1.1 5.6.1 table 18 */
-	if(state == 3 || dev->current_state == 3)
+	if (state == PCI_D3hot || dev->current_state == PCI_D3hot)
 		msleep(10);
-	else if(state == 2 || dev->current_state == 2)
+	else if (state == PCI_D2 || dev->current_state == PCI_D2)
 		udelay(200);
 	dev->current_state = state;
 
@@ -319,6 +319,7 @@
 	case 3: return PCI_D3hot;
 	default: BUG();
 	}
+	return PCI_D0;
 }
 
 EXPORT_SYMBOL(pci_choose_state);


-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

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

* Re: Cleanup PCI power states
  2004-12-17 22:02         ` Greg KH
  2004-12-17 23:39           ` Pavel Machek
  2004-12-17 23:50           ` Pavel Machek
@ 2004-12-18  0:09           ` Pavel Machek
  2004-12-21 20:04             ` Greg KH
  2 siblings, 1 reply; 26+ messages in thread
From: Pavel Machek @ 2004-12-18  0:09 UTC (permalink / raw)
  To: Greg KH; +Cc: kernel list, Andrew Morton

Hi!

> Alright, I've applied this, and it will show up in the next -mm release.
> I also fixed up pci.h for when CONFIG_PCI=N due to your changed
> functions.
> 
> Now, care to send patches to fix up all of the new sparse warnings in
> the drivers/pci/* directory?

This should fix warnings in drivers/net/* and bttv (with exception of
via-rhine, which I'll do separately). Do you think you could apply it,
or shall I ask Andrew, or... ?

Signed-off-by: Pavel Machek <pavel@suse.cz>

								Pavel

--- clean/drivers/media/video/bttv-driver.c	2004-10-01 00:30:14.000000000 +0200
+++ linux/drivers/media/video/bttv-driver.c	2004-11-01 21:25:09.000000000 +0100
@@ -3945,7 +3945,7 @@
 
 	/* save pci state */
 	pci_save_state(pci_dev, btv->state.pci_cfg);
-	if (0 != pci_set_power_state(pci_dev, state)) {
+	if (0 != pci_set_power_state(pci_dev, device_to_pci_power(pci_dev, state))) {
 		pci_disable_device(pci_dev);
 		btv->state.disabled = 1;
 	}
@@ -3964,7 +3964,7 @@
 		pci_enable_device(pci_dev);
 		btv->state.disabled = 0;
 	}
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 	pci_restore_state(pci_dev, btv->state.pci_cfg);
 
 	/* restore bt878 state */
--- clean/drivers/net/3c59x.c	2004-10-19 14:16:28.000000000 +0200
+++ linux/drivers/net/3c59x.c	2004-11-14 23:36:46.000000000 +0100
@@ -1550,7 +1550,7 @@
 	int i;
 
 	if (VORTEX_PCI(vp) && vp->enable_wol) {
-		pci_set_power_state(VORTEX_PCI(vp), 0);	/* Go active */
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);	/* Go active */
 		pci_restore_state(VORTEX_PCI(vp), vp->power_state);
 	}
 
@@ -2942,7 +2942,7 @@
 	/* The kernel core really should have pci_get_power_state() */
 
 	if(state != 0)
-		pci_set_power_state(VORTEX_PCI(vp), 0);
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);
 	err = vortex_do_ioctl(dev, rq, cmd);
 	if(state != 0)
 		pci_set_power_state(VORTEX_PCI(vp), state);
@@ -3141,7 +3141,7 @@
 
 	/* Change the power state to D3; RxEnable doesn't take effect. */
 	pci_enable_wake(VORTEX_PCI(vp), 0, 1);
-	pci_set_power_state(VORTEX_PCI(vp), 3);
+	pci_set_power_state(VORTEX_PCI(vp), PCI_D3hot);
 }
 
 
@@ -3164,7 +3164,7 @@
 	unregister_netdev(dev);
 
 	if (VORTEX_PCI(vp) && vp->enable_wol) {
-		pci_set_power_state(VORTEX_PCI(vp), 0);	/* Go active */
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);	/* Go active */
 		if (vp->pm_state_valid)
 			pci_restore_state(VORTEX_PCI(vp), vp->power_state);
 	}
--- clean/drivers/net/8139cp.c	2004-10-01 00:30:15.000000000 +0200
+++ linux/drivers/net/8139cp.c	2004-11-14 23:36:46.000000000 +0100
@@ -1623,7 +1623,7 @@
 static void cp_set_d3_state (struct cp_private *cp)
 {
 	pci_enable_wake (cp->pdev, 0, 1); /* Enable PME# generation */
-	pci_set_power_state (cp->pdev, 3);
+	pci_set_power_state (cp->pdev, PCI_D3hot);
 }
 
 static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -1813,7 +1813,7 @@
 		BUG();
 	unregister_netdev(dev);
 	iounmap(cp->regs);
-	if (cp->wol_enabled) pci_set_power_state (pdev, 0);
+	if (cp->wol_enabled) pci_set_power_state (pdev, PCI_D0);
 	pci_release_regions(pdev);
 	pci_clear_mwi(pdev);
 	pci_disable_device(pdev);
@@ -1863,7 +1863,7 @@
 	netif_device_attach (dev);
 	
 	if (cp->pdev && cp->wol_enabled) {
-		pci_set_power_state (cp->pdev, 0);
+		pci_set_power_state (cp->pdev, PCI_D0);
 		pci_restore_state (cp->pdev, cp->power_state);
 	}
 	
--- clean/drivers/net/8139too.c	2004-10-01 00:30:15.000000000 +0200
+++ linux/drivers/net/8139too.c	2004-11-01 20:41:29.000000000 +0100
@@ -2608,7 +2608,7 @@
 
 	spin_unlock_irqrestore (&tp->lock, flags);
 
-	pci_set_power_state (pdev, 3);
+	pci_set_power_state (pdev, PCI_D3hot);
 
 	return 0;
 }
@@ -2622,7 +2622,7 @@
 	pci_restore_state (pdev, tp->pci_state);
 	if (!netif_running (dev))
 		return 0;
-	pci_set_power_state (pdev, 0);
+	pci_set_power_state (pdev, PCI_D0);
 	rtl8139_init_ring (dev);
 	rtl8139_hw_start (dev);
 	netif_device_attach (dev);
--- clean/drivers/net/amd8111e.c	2004-10-01 00:30:15.000000000 +0200
+++ linux/drivers/net/amd8111e.c	2004-11-14 23:48:04.000000000 +0100
@@ -1865,17 +1865,17 @@
 		if(lp->options & OPTION_WAKE_PHY_ENABLE)
 			amd8111e_enable_link_change(lp);	
 		
-		pci_enable_wake(pci_dev, 3, 1);
-		pci_enable_wake(pci_dev, 4, 1); /* D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 1);
+		pci_enable_wake(pci_dev, PCI_D3cold, 1);
 
 	}
 	else{		
-		pci_enable_wake(pci_dev, 3, 0);
-		pci_enable_wake(pci_dev, 4, 0); /* 4 == D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 0);
+		pci_enable_wake(pci_dev, PCI_D3cold, 0);
 	}
 	
 	pci_save_state(pci_dev, lp->pm_state);
-	pci_set_power_state(pci_dev, 3);
+	pci_set_power_state(pci_dev, PCI_D3hot);
 
 	return 0;
 }
@@ -1887,11 +1887,11 @@
 	if (!netif_running(dev))
 		return 0;
 
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 	pci_restore_state(pci_dev, lp->pm_state);
 
-	pci_enable_wake(pci_dev, 3, 0);
-	pci_enable_wake(pci_dev, 4, 0); /* D3 cold */
+	pci_enable_wake(pci_dev, PCI_D3hot, 0);
+	pci_enable_wake(pci_dev, PCI_D3cold, 0);
 
 	netif_device_attach(dev);
 
--- clean/drivers/net/e100.c	2004-10-01 00:30:15.000000000 +0200
+++ linux/drivers/net/e100.c	2004-11-14 23:36:46.000000000 +0100
@@ -2313,7 +2313,7 @@
 	pci_save_state(pdev, nic->pm_state);
 	pci_enable_wake(pdev, state, nic->flags & (wol_magic | e100_asf(nic)));
 	pci_disable_device(pdev);
-	pci_set_power_state(pdev, state);
+	pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
 	return 0;
 }
@@ -2323,7 +2323,7 @@
 	struct net_device *netdev = pci_get_drvdata(pdev);
 	struct nic *nic = netdev_priv(netdev);
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev, nic->pm_state);
 	e100_hw_init(nic);
 
--- clean/drivers/net/eepro100.c	2004-10-01 00:30:15.000000000 +0200
+++ linux/drivers/net/eepro100.c	2004-11-14 23:36:46.000000000 +0100
@@ -1015,7 +1005,7 @@
 	if (netif_msg_ifup(sp))
 		printk(KERN_DEBUG "%s: speedo_open() irq %d.\n", dev->name, dev->irq);
 
-	pci_set_power_state(sp->pdev, 0);
+	pci_set_power_state(sp->pdev, PCI_D0);
 
 	/* Set up the Tx queue early.. */
 	sp->cur_tx = 0;
@@ -1964,7 +1954,7 @@
 	if (netif_msg_ifdown(sp))
 		printk(KERN_DEBUG "%s: %d multicast blocks dropped.\n", dev->name, i);
 
-	pci_set_power_state(sp->pdev, 2);
+	pci_set_power_state(sp->pdev, PCI_D2);
 
 	return 0;
 }
@@ -2103,7 +2093,7 @@
 		   access from the timeout handler.
 		   They are currently serialized only with MDIO access from the
 		   timer routine.  2000/05/09 SAW */
-		saved_acpi = pci_set_power_state(sp->pdev, 0);
+		saved_acpi = pci_set_power_state(sp->pdev, PCI_D0);
 		t = del_timer_sync(&sp->timer);
 		data->val_out = mdio_read(dev, data->phy_id & 0x1f, data->reg_num & 0x1f);
 		if (t)
@@ -2114,7 +2104,7 @@
 	case SIOCSMIIREG:		/* Write MII PHY register. */
 		if (!capable(CAP_NET_ADMIN))
 			return -EPERM;
-		saved_acpi = pci_set_power_state(sp->pdev, 0);
+		saved_acpi = pci_set_power_state(sp->pdev, PCI_D0);
 		t = del_timer_sync(&sp->timer);
 		mdio_write(dev, data->phy_id, data->reg_num, data->val_in);
 		if (t)
--- clean/drivers/net/pci-skeleton.c	2004-08-15 19:14:58.000000000 +0200
+++ linux/drivers/net/pci-skeleton.c	2004-11-14 23:36:46.000000000 +0100
@@ -1922,7 +1922,7 @@
 	spin_unlock_irqrestore (&tp->lock, flags);
 
 	pci_save_state (pdev, tp->pci_state);
-	pci_set_power_state (pdev, 3);
+	pci_set_power_state (pdev, PCI_D3hot);
 
 	return 0;
 }
@@ -1935,7 +1935,7 @@
 
 	if (!netif_running(dev))
 		return 0;
-	pci_set_power_state (pdev, 0);
+	pci_set_power_state (pdev, PCI_D0);
 	pci_restore_state (pdev, tp->pci_state);
 	netif_device_attach (dev);
 	netdrv_hw_start (dev);
--- clean/drivers/net/sis900.c	2004-10-01 00:30:15.000000000 +0200
+++ linux/drivers/net/sis900.c	2004-11-14 23:36:46.000000000 +0100
@@ -2212,7 +2212,7 @@
 	/* Stop the chip's Tx and Rx Status Machine */
 	outl(RxDIS | TxDIS | inl(ioaddr + cr), ioaddr + cr);
 
-	pci_set_power_state(pci_dev, 3);
+	pci_set_power_state(pci_dev, PCI_D3hot);
 	pci_save_state(pci_dev, sis_priv->pci_state);
 
 	return 0;
@@ -2227,7 +2227,7 @@
 	if(!netif_running(net_dev))
 		return 0;
 	pci_restore_state(pci_dev, sis_priv->pci_state);
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 
 	sis900_init_rxfilter(net_dev);
 
--- clean/drivers/net/starfire.c	2004-08-15 19:14:58.000000000 +0200
+++ linux/drivers/net/starfire.c	2004-11-14 23:36:46.000000000 +0100
@@ -2186,7 +2186,7 @@
 	unregister_netdev(dev);
 
 	/* XXX: add wakeup code -- requires firmware for MagicPacket */
-	pci_set_power_state(pdev, 3);	/* go to sleep in D3 mode */
+	pci_set_power_state(pdev, PCI_D3hot);	/* go to sleep in D3 mode */
 	pci_disable_device(pdev);
 
 	iounmap((char *)dev->base_addr);
--- clean/drivers/net/typhoon.c	2004-10-01 00:30:16.000000000 +0200
+++ linux/drivers/net/typhoon.c	2004-11-14 23:36:46.000000000 +0100
@@ -1884,7 +1884,7 @@
 
 	pci_enable_wake(tp->pdev, state, 1);
 	pci_disable_device(pdev);
-	return pci_set_power_state(pdev, state);
+	return pci_set_power_state(pdev, pci_choose_state(pdev, state));
 }
 
 static int
@@ -1893,7 +1893,7 @@
 	struct pci_dev *pdev = tp->pdev;
 	void __iomem *ioaddr = tp->ioaddr;
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev, tp->pci_state);
 
 	/* Post 2.x.x versions of the Sleep Image require a reset before
@@ -2541,7 +2541,7 @@
 	struct typhoon *tp = (struct typhoon *) (dev->priv);
 
 	unregister_netdev(dev);
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev, tp->pci_state);
 	typhoon_reset(tp->ioaddr, NoWait);
 	iounmap(tp->ioaddr);
--- clean/drivers/net/via-velocity.c	2004-10-19 14:16:28.000000000 +0200
+++ linux/drivers/net/via-velocity.c	2004-11-14 23:36:46.000000000 +0100
@@ -804,7 +804,7 @@
 	
 	/* and leave the chip powered down */
 	
-	pci_set_power_state(pdev, 3);
+	pci_set_power_state(pdev, PCI_D3hot);
 #ifdef CONFIG_PM
 	{
 		unsigned long flags;
@@ -1742,7 +1742,7 @@
 		goto err_free_rd_ring;
 	
 	/* Ensure chip is running */	
-	pci_set_power_state(vptr->pdev, 0);
+	pci_set_power_state(vptr->pdev, PCI_D0);
 	
 	velocity_init_registers(vptr, VELOCITY_INIT_COLD);
 
@@ -1750,7 +1750,7 @@
 			  dev->name, dev);
 	if (ret < 0) {
 		/* Power down the chip */
-		pci_set_power_state(vptr->pdev, 3);
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 		goto err_free_td_ring;
 	}
 
@@ -1868,7 +1868,7 @@
 		free_irq(dev->irq, dev);
 		
 	/* Power down the chip */
-	pci_set_power_state(vptr->pdev, 3);
+	pci_set_power_state(vptr->pdev, PCI_D3hot);
 	
 	/* Free the resources */
 	velocity_free_td_ring(vptr);
@@ -2194,8 +2194,8 @@
 	/* If we are asked for information and the device is power
 	   saving then we need to bring the device back up to talk to it */
 	   	
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 0);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D0);
 		
 	switch (cmd) {
 	case SIOCGMIIPHY:	/* Get address of MII PHY in use. */
@@ -2207,8 +2207,8 @@
 	default:
 		ret = -EOPNOTSUPP;
 	}
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 3);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 		
 		
 	return ret;
@@ -2818,8 +2818,8 @@
 static int velocity_ethtool_up(struct net_device *dev)
 {
 	struct velocity_info *vptr = dev->priv;
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 0);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D0);
 	return 0;
 }	
 
@@ -2834,8 +2834,8 @@
 static void velocity_ethtool_down(struct net_device *dev)
 {
 	struct velocity_info *vptr = dev->priv;
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 3);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 }
 
 static int velocity_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
@@ -3229,15 +3229,15 @@
 		velocity_shutdown(vptr);
 		velocity_set_wol(vptr);
 		pci_enable_wake(pdev, 3, 1);
-		pci_set_power_state(pdev, 3);
+		pci_set_power_state(pdev, PCI_D3hot);
 	} else {
 		velocity_save_context(vptr, &vptr->context);
 		velocity_shutdown(vptr);
 		pci_disable_device(pdev);
-		pci_set_power_state(pdev, state);
+		pci_set_power_state(pdev, pci_choose_state(pdev, state));
 	}
 #else
-	pci_set_power_state(pdev, state);
+	pci_set_power_state(pdev, pci_choose_state(pdev, state));
 #endif
 	spin_unlock_irqrestore(&vptr->lock, flags);
 	return 0;
@@ -3252,7 +3252,7 @@
 	if(!netif_running(vptr->dev))
 		return 0;
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_enable_wake(pdev, 0, 0);
 	pci_restore_state(pdev, vptr->pci_state);
 


-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

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

* Re: Cleanup PCI power states
  2004-12-17 23:39           ` Pavel Machek
@ 2004-12-21 19:57             ` Greg KH
  0 siblings, 0 replies; 26+ messages in thread
From: Greg KH @ 2004-12-21 19:57 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list, Andrew Morton

On Sat, Dec 18, 2004 at 12:39:15AM +0100, Pavel Machek wrote:
> Hi!
> 
> > > Okay, here it is, slightly expanded version. It actually makes use of
> > > newly defined type for type-checking purposes; still no code changes.
> > 
> > Alright, I've applied this, and it will show up in the next -mm release.
> > I also fixed up pci.h for when CONFIG_PCI=N due to your changed
> > functions.
> 
> Thanks... Hopefully I guessed the change right, otherwise this will
> need to be applied by hand.

You guessed right :)

> This adds missing prototype for pci_choose_state.								
> 
> Signed-off-by: Pavel Machek <pavel@suse.cz>

Applied, thanks.

greg k-h

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

* Re: Cleanup PCI power states
  2004-12-17 23:50           ` Pavel Machek
@ 2004-12-21 20:03             ` Greg KH
  2004-12-21 23:25               ` Pavel Machek
  0 siblings, 1 reply; 26+ messages in thread
From: Greg KH @ 2004-12-21 20:03 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list, Andrew Morton, torvalds

On Sat, Dec 18, 2004 at 12:50:51AM +0100, Pavel Machek wrote:
> Hi!
> 
> > > Okay, here it is, slightly expanded version. It actually makes use of
> > > newly defined type for type-checking purposes; still no code changes.
> > 
> > Alright, I've applied this, and it will show up in the next -mm release.
> > I also fixed up pci.h for when CONFIG_PCI=N due to your changed
> > functions.
> > 
> > Now, care to send patches to fix up all of the new sparse warnings in
> > the drivers/pci/* directory?
> 
> This should reduce number of warnings in pci.c. It will still warn on
> comparison (because we are using __bitwise, but in fact we want
> something like "this is unique but arithmetic is still ok"), but that
> probably needs to be fixed in sparse.
> 
> Also killed "function does not return anything" warning.
> 
> Please apply,

What kernel tree is this against?  I get rejects in the second hunk.

thanks,

greg k-h

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

* Re: Cleanup PCI power states
  2004-12-18  0:09           ` Pavel Machek
@ 2004-12-21 20:04             ` Greg KH
  2004-12-21 23:37               ` Pavel Machek
  0 siblings, 1 reply; 26+ messages in thread
From: Greg KH @ 2004-12-21 20:04 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list, Andrew Morton

On Sat, Dec 18, 2004 at 01:09:20AM +0100, Pavel Machek wrote:
> Hi!
> 
> > Alright, I've applied this, and it will show up in the next -mm release.
> > I also fixed up pci.h for when CONFIG_PCI=N due to your changed
> > functions.
> > 
> > Now, care to send patches to fix up all of the new sparse warnings in
> > the drivers/pci/* directory?
> 
> This should fix warnings in drivers/net/* and bttv (with exception of
> via-rhine, which I'll do separately). Do you think you could apply it,
> or shall I ask Andrew, or... ?
> 
> Signed-off-by: Pavel Machek <pavel@suse.cz>

What kernel tree is this against?  I get lots of rejects against the
latest -bk tree.

thanks,

greg k-h

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

* Re: Cleanup PCI power states
  2004-12-21 20:03             ` Greg KH
@ 2004-12-21 23:25               ` Pavel Machek
  2004-12-21 23:29                 ` Greg KH
  0 siblings, 1 reply; 26+ messages in thread
From: Pavel Machek @ 2004-12-21 23:25 UTC (permalink / raw)
  To: Greg KH; +Cc: kernel list, Andrew Morton, torvalds

Hi!

> > This should reduce number of warnings in pci.c. It will still warn on
> > comparison (because we are using __bitwise, but in fact we want
> > something like "this is unique but arithmetic is still ok"), but that
> > probably needs to be fixed in sparse.
> > 
> > Also killed "function does not return anything" warning.
> > 
> > Please apply,
> 
> What kernel tree is this against?  I get rejects in the second hunk.

Strange, it applied okay here over latest -bk. What tree should I
generate it against?
								Pavel
-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

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

* Re: Cleanup PCI power states
  2004-12-21 23:25               ` Pavel Machek
@ 2004-12-21 23:29                 ` Greg KH
  0 siblings, 0 replies; 26+ messages in thread
From: Greg KH @ 2004-12-21 23:29 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list, Andrew Morton, torvalds

On Wed, Dec 22, 2004 at 12:25:10AM +0100, Pavel Machek wrote:
> Hi!
> 
> > > This should reduce number of warnings in pci.c. It will still warn on
> > > comparison (because we are using __bitwise, but in fact we want
> > > something like "this is unique but arithmetic is still ok"), but that
> > > probably needs to be fixed in sparse.
> > > 
> > > Also killed "function does not return anything" warning.
> > > 
> > > Please apply,
> > 
> > What kernel tree is this against?  I get rejects in the second hunk.
> 
> Strange, it applied okay here over latest -bk. What tree should I
> generate it against?

Ah, ok, it's my fault, I have some changes by someone else in my tree.
I'll merge it in by hand.  Sorry about that.

greg k-h

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

* Re: Cleanup PCI power states
  2004-12-21 20:04             ` Greg KH
@ 2004-12-21 23:37               ` Pavel Machek
  2004-12-22  0:41                 ` Greg KH
  0 siblings, 1 reply; 26+ messages in thread
From: Pavel Machek @ 2004-12-21 23:37 UTC (permalink / raw)
  To: Greg KH; +Cc: kernel list, Andrew Morton

Hi!

> > > Alright, I've applied this, and it will show up in the next -mm release.
> > > I also fixed up pci.h for when CONFIG_PCI=N due to your changed
> > > functions.
> > > 
> > > Now, care to send patches to fix up all of the new sparse warnings in
> > > the drivers/pci/* directory?
> > 
> > This should fix warnings in drivers/net/* and bttv (with exception of
> > via-rhine, which I'll do separately). Do you think you could apply it,
> > or shall I ask Andrew, or... ?
> > 
> > Signed-off-by: Pavel Machek <pavel@suse.cz>
> 
> What kernel tree is this against?  I get lots of rejects against the
> latest -bk tree.

It was against 2.6.9. pci_{save,restore}_state(), therefore it rejects
in surrounding text. Here's version against latest -bk.

This should fix sparse warnings in drivers/net/* and bttv. Please
apply,

								Pavel


Signed-off-by: Pavel Machek <pavel@suse.cz>

--- clean-cvs/drivers/media/video/bttv-driver.c	2004-12-09 21:46:07.000000000 +0100
+++ linux-greg/drivers/media/video/bttv-driver.c	2004-12-22 00:30:21.000000000 +0100
@@ -3942,7 +3942,7 @@
 
 	/* save pci state */
 	pci_save_state(pci_dev);
-	if (0 != pci_set_power_state(pci_dev, state)) {
+	if (0 != pci_set_power_state(pci_dev, device_to_pci_power(pci_dev, state))) {
 		pci_disable_device(pci_dev);
 		btv->state.disabled = 1;
 	}
@@ -3961,7 +3961,7 @@
 		pci_enable_device(pci_dev);
 		btv->state.disabled = 0;
 	}
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 	pci_restore_state(pci_dev);
 
 	/* restore bt878 state */
--- clean-cvs/drivers/net/3c59x.c	2004-11-19 12:19:53.000000000 +0100
+++ linux-greg/drivers/net/3c59x.c	2004-12-22 00:32:24.000000000 +0100
@@ -1549,7 +1549,7 @@
 	int i;
 
 	if (VORTEX_PCI(vp) && vp->enable_wol) {
-		pci_set_power_state(VORTEX_PCI(vp), 0);	/* Go active */
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);	/* Go active */
 		pci_restore_state(VORTEX_PCI(vp));
 	}
 
@@ -2941,7 +2941,7 @@
 	/* The kernel core really should have pci_get_power_state() */
 
 	if(state != 0)
-		pci_set_power_state(VORTEX_PCI(vp), 0);
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);
 	err = vortex_do_ioctl(dev, rq, cmd);
 	if(state != 0)
 		pci_set_power_state(VORTEX_PCI(vp), state);
@@ -3140,7 +3140,7 @@
 
 	/* Change the power state to D3; RxEnable doesn't take effect. */
 	pci_enable_wake(VORTEX_PCI(vp), 0, 1);
-	pci_set_power_state(VORTEX_PCI(vp), 3);
+	pci_set_power_state(VORTEX_PCI(vp), PCI_D3hot);
 }
 
 
@@ -3163,7 +3163,7 @@
 	unregister_netdev(dev);
 
 	if (VORTEX_PCI(vp) && vp->enable_wol) {
-		pci_set_power_state(VORTEX_PCI(vp), 0);	/* Go active */
+		pci_set_power_state(VORTEX_PCI(vp), PCI_D0);	/* Go active */
 		if (vp->pm_state_valid)
 			pci_restore_state(VORTEX_PCI(vp));
 	}
--- clean-cvs/drivers/net/8139cp.c	2004-11-19 12:19:53.000000000 +0100
+++ linux-greg/drivers/net/8139cp.c	2004-12-22 00:32:48.000000000 +0100
@@ -1623,7 +1623,7 @@
 static void cp_set_d3_state (struct cp_private *cp)
 {
 	pci_enable_wake (cp->pdev, 0, 1); /* Enable PME# generation */
-	pci_set_power_state (cp->pdev, 3);
+	pci_set_power_state (cp->pdev, PCI_D3hot);
 }
 
 static int cp_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -1813,7 +1813,7 @@
 		BUG();
 	unregister_netdev(dev);
 	iounmap(cp->regs);
-	if (cp->wol_enabled) pci_set_power_state (pdev, 0);
+	if (cp->wol_enabled) pci_set_power_state (pdev, PCI_D0);
 	pci_release_regions(pdev);
 	pci_clear_mwi(pdev);
 	pci_disable_device(pdev);
@@ -1863,7 +1863,7 @@
 	netif_device_attach (dev);
 	
 	if (cp->pdev && cp->wol_enabled) {
-		pci_set_power_state (cp->pdev, 0);
+		pci_set_power_state (cp->pdev, PCI_D0);
 		pci_restore_state (cp->pdev);
 	}
 	
--- clean-cvs/drivers/net/8139too.c	2004-11-19 12:19:53.000000000 +0100
+++ linux-greg/drivers/net/8139too.c	2004-12-22 00:29:11.000000000 +0100
@@ -2607,7 +2607,7 @@
 
 	spin_unlock_irqrestore (&tp->lock, flags);
 
-	pci_set_power_state (pdev, 3);
+	pci_set_power_state (pdev, PCI_D3hot);
 
 	return 0;
 }
@@ -2620,7 +2620,7 @@
 	pci_restore_state (pdev);
 	if (!netif_running (dev))
 		return 0;
-	pci_set_power_state (pdev, 0);
+	pci_set_power_state (pdev, PCI_D0);
 	rtl8139_init_ring (dev);
 	rtl8139_hw_start (dev);
 	netif_device_attach (dev);
--- clean-cvs/drivers/net/amd8111e.c	2004-11-19 12:19:54.000000000 +0100
+++ linux-greg/drivers/net/amd8111e.c	2004-12-22 00:33:46.000000000 +0100
@@ -1826,17 +1826,17 @@
 		if(lp->options & OPTION_WAKE_PHY_ENABLE)
 			amd8111e_enable_link_change(lp);	
 		
-		pci_enable_wake(pci_dev, 3, 1);
-		pci_enable_wake(pci_dev, 4, 1); /* D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 1);
+		pci_enable_wake(pci_dev, PCI_D3cold, 1);
 
 	}
 	else{		
-		pci_enable_wake(pci_dev, 3, 0);
-		pci_enable_wake(pci_dev, 4, 0); /* 4 == D3 cold */
+		pci_enable_wake(pci_dev, PCI_D3hot, 0);
+		pci_enable_wake(pci_dev, PCI_D3cold, 0);
 	}
 	
 	pci_save_state(pci_dev);
-	pci_set_power_state(pci_dev, 3);
+	pci_set_power_state(pci_dev, PCI_D3hot);
 
 	return 0;
 }
@@ -1848,11 +1848,11 @@
 	if (!netif_running(dev))
 		return 0;
 
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 	pci_restore_state(pci_dev);
 
-	pci_enable_wake(pci_dev, 3, 0);
-	pci_enable_wake(pci_dev, 4, 0); /* D3 cold */
+	pci_enable_wake(pci_dev, PCI_D3hot, 0);
+	pci_enable_wake(pci_dev, PCI_D3cold, 0); /* D3 cold */
 
 	netif_device_attach(dev);
 
--- clean-cvs/drivers/net/e100.c	2004-12-09 21:46:08.000000000 +0100
+++ linux-greg/drivers/net/e100.c	2004-12-22 00:34:04.000000000 +0100
@@ -2326,7 +2326,7 @@
 	pci_save_state(pdev);
 	pci_enable_wake(pdev, state, nic->flags & (wol_magic | e100_asf(nic)));
 	pci_disable_device(pdev);
-	pci_set_power_state(pdev, state);
+	pci_set_power_state(pdev, pci_choose_state(pdev, state));
 
 	return 0;
 }
@@ -2336,7 +2336,7 @@
 	struct net_device *netdev = pci_get_drvdata(pdev);
 	struct nic *nic = netdev_priv(netdev);
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev);
 	e100_hw_init(nic);
 
--- clean-cvs/drivers/net/eepro100.c	2004-12-13 21:18:25.000000000 +0100
+++ linux-greg/drivers/net/eepro100.c	2004-12-22 00:29:11.000000000 +0100
@@ -1014,7 +1014,7 @@
 	if (netif_msg_ifup(sp))
 		printk(KERN_DEBUG "%s: speedo_open() irq %d.\n", dev->name, dev->irq);
 
-	pci_set_power_state(sp->pdev, 0);
+	pci_set_power_state(sp->pdev, PCI_D0);
 
 	/* Set up the Tx queue early.. */
 	sp->cur_tx = 0;
@@ -1963,7 +1963,7 @@
 	if (netif_msg_ifdown(sp))
 		printk(KERN_DEBUG "%s: %d multicast blocks dropped.\n", dev->name, i);
 
-	pci_set_power_state(sp->pdev, 2);
+	pci_set_power_state(sp->pdev, PCI_D2);
 
 	return 0;
 }
@@ -2088,7 +2088,7 @@
 		   access from the timeout handler.
 		   They are currently serialized only with MDIO access from the
 		   timer routine.  2000/05/09 SAW */
-		saved_acpi = pci_set_power_state(sp->pdev, 0);
+		saved_acpi = pci_set_power_state(sp->pdev, PCI_D0);
 		t = del_timer_sync(&sp->timer);
 		data->val_out = mdio_read(dev, data->phy_id & 0x1f, data->reg_num & 0x1f);
 		if (t)
@@ -2099,7 +2099,7 @@
 	case SIOCSMIIREG:		/* Write MII PHY register. */
 		if (!capable(CAP_NET_ADMIN))
 			return -EPERM;
-		saved_acpi = pci_set_power_state(sp->pdev, 0);
+		saved_acpi = pci_set_power_state(sp->pdev, PCI_D0);
 		t = del_timer_sync(&sp->timer);
 		mdio_write(dev, data->phy_id, data->reg_num, data->val_in);
 		if (t)
--- clean-cvs/drivers/net/pci-skeleton.c	2004-11-19 12:19:56.000000000 +0100
+++ linux-greg/drivers/net/pci-skeleton.c	2004-12-22 00:34:18.000000000 +0100
@@ -1921,7 +1921,7 @@
 	spin_unlock_irqrestore (&tp->lock, flags);
 
 	pci_save_state (pdev);
-	pci_set_power_state (pdev, 3);
+	pci_set_power_state (pdev, PCI_D3hot);
 
 	return 0;
 }
@@ -1934,7 +1934,7 @@
 
 	if (!netif_running(dev))
 		return 0;
-	pci_set_power_state (pdev, 0);
+	pci_set_power_state (pdev, PCI_D0);
 	pci_restore_state (pdev);
 	netif_device_attach (dev);
 	netdrv_hw_start (dev);
--- clean-cvs/drivers/net/sis900.c	2004-11-19 12:19:57.000000000 +0100
+++ linux-greg/drivers/net/sis900.c	2004-12-22 00:34:43.000000000 +0100
@@ -2238,7 +2238,7 @@
 	/* Stop the chip's Tx and Rx Status Machine */
 	outl(RxDIS | TxDIS | inl(ioaddr + cr), ioaddr + cr);
 
-	pci_set_power_state(pci_dev, 3);
+	pci_set_power_state(pci_dev, PCI_D3);
 	pci_save_state(pci_dev);
 
 	return 0;
@@ -2253,7 +2253,7 @@
 	if(!netif_running(net_dev))
 		return 0;
 	pci_restore_state(pci_dev);
-	pci_set_power_state(pci_dev, 0);
+	pci_set_power_state(pci_dev, PCI_D0);
 
 	sis900_init_rxfilter(net_dev);
 
--- clean-cvs/drivers/net/starfire.c	2004-10-20 17:32:59.000000000 +0200
+++ linux-greg/drivers/net/starfire.c	2004-12-22 00:29:11.000000000 +0100
@@ -2159,7 +2159,7 @@
 
 
 	/* XXX: add wakeup code -- requires firmware for MagicPacket */
-	pci_set_power_state(pdev, 3);	/* go to sleep in D3 mode */
+	pci_set_power_state(pdev, PCI_D3hot);	/* go to sleep in D3 mode */
 	pci_disable_device(pdev);
 
 	iounmap((char *)dev->base_addr);
--- clean-cvs/drivers/net/typhoon.c	2004-11-19 12:19:58.000000000 +0100
+++ linux-greg/drivers/net/typhoon.c	2004-12-22 00:34:59.000000000 +0100
@@ -1890,7 +1890,7 @@
 
 	pci_enable_wake(tp->pdev, state, 1);
 	pci_disable_device(pdev);
-	return pci_set_power_state(pdev, state);
+	return pci_set_power_state(pdev, pci_choose_state(pdev, state));
 }
 
 static int
@@ -1899,7 +1899,7 @@
 	struct pci_dev *pdev = tp->pdev;
 	void __iomem *ioaddr = tp->ioaddr;
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev);
 
 	/* Post 2.x.x versions of the Sleep Image require a reset before
@@ -2553,7 +2553,7 @@
 	struct typhoon *tp = netdev_priv(dev);
 
 	unregister_netdev(dev);
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_restore_state(pdev);
 	typhoon_reset(tp->ioaddr, NoWait);
 	iounmap(tp->ioaddr);
--- clean-cvs/drivers/net/via-rhine.c	2004-11-19 12:19:58.000000000 +0100
+++ linux-greg/drivers/net/via-rhine.c	2004-12-22 00:29:20.000000000 +0100
@@ -1974,7 +1974,7 @@
         if (request_irq(dev->irq, rhine_interrupt, SA_SHIRQ, dev->name, dev))
 		printk(KERN_ERR "via-rhine %s: request_irq failed\n", dev->name);
 
-	ret = pci_set_power_state(pdev, 0);
+	ret = pci_set_power_state(pdev, PCI_D0);
 	if (debug > 1)
 		printk(KERN_INFO "%s: Entering power state D0 %s (%d).\n",
 			dev->name, ret ? "failed" : "succeeded", ret);
--- clean-cvs/drivers/net/via-velocity.c	2004-10-20 03:26:30.000000000 +0200
+++ linux-greg/drivers/net/via-velocity.c	2004-12-22 00:29:11.000000000 +0100
@@ -804,7 +804,7 @@
 	
 	/* and leave the chip powered down */
 	
-	pci_set_power_state(pdev, 3);
+	pci_set_power_state(pdev, PCI_D3hot);
 #ifdef CONFIG_PM
 	{
 		unsigned long flags;
@@ -1742,7 +1742,7 @@
 		goto err_free_rd_ring;
 	
 	/* Ensure chip is running */	
-	pci_set_power_state(vptr->pdev, 0);
+	pci_set_power_state(vptr->pdev, PCI_D0);
 	
 	velocity_init_registers(vptr, VELOCITY_INIT_COLD);
 
@@ -1750,7 +1750,7 @@
 			  dev->name, dev);
 	if (ret < 0) {
 		/* Power down the chip */
-		pci_set_power_state(vptr->pdev, 3);
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 		goto err_free_td_ring;
 	}
 
@@ -1868,7 +1868,7 @@
 		free_irq(dev->irq, dev);
 		
 	/* Power down the chip */
-	pci_set_power_state(vptr->pdev, 3);
+	pci_set_power_state(vptr->pdev, PCI_D3hot);
 	
 	/* Free the resources */
 	velocity_free_td_ring(vptr);
@@ -2194,8 +2194,8 @@
 	/* If we are asked for information and the device is power
 	   saving then we need to bring the device back up to talk to it */
 	   	
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 0);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D0);
 		
 	switch (cmd) {
 	case SIOCGMIIPHY:	/* Get address of MII PHY in use. */
@@ -2207,8 +2207,8 @@
 	default:
 		ret = -EOPNOTSUPP;
 	}
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 3);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 		
 		
 	return ret;
@@ -2818,8 +2818,8 @@
 static int velocity_ethtool_up(struct net_device *dev)
 {
 	struct velocity_info *vptr = dev->priv;
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 0);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D0);
 	return 0;
 }	
 
@@ -2834,8 +2834,8 @@
 static void velocity_ethtool_down(struct net_device *dev)
 {
 	struct velocity_info *vptr = dev->priv;
-	if(!netif_running(dev))
-		pci_set_power_state(vptr->pdev, 3);
+	if (!netif_running(dev))
+		pci_set_power_state(vptr->pdev, PCI_D3hot);
 }
 
 static int velocity_get_settings(struct net_device *dev, struct ethtool_cmd *cmd)
@@ -3229,15 +3229,15 @@
 		velocity_shutdown(vptr);
 		velocity_set_wol(vptr);
 		pci_enable_wake(pdev, 3, 1);
-		pci_set_power_state(pdev, 3);
+		pci_set_power_state(pdev, PCI_D3hot);
 	} else {
 		velocity_save_context(vptr, &vptr->context);
 		velocity_shutdown(vptr);
 		pci_disable_device(pdev);
-		pci_set_power_state(pdev, state);
+		pci_set_power_state(pdev, pci_choose_state(pdev, state));
 	}
 #else
-	pci_set_power_state(pdev, state);
+	pci_set_power_state(pdev, pci_choose_state(pdev, state));
 #endif
 	spin_unlock_irqrestore(&vptr->lock, flags);
 	return 0;
@@ -3252,7 +3252,7 @@
 	if(!netif_running(vptr->dev))
 		return 0;
 
-	pci_set_power_state(pdev, 0);
+	pci_set_power_state(pdev, PCI_D0);
 	pci_enable_wake(pdev, 0, 0);
 	pci_restore_state(pdev);
 


-- 
People were complaining that M$ turns users into beta-testers...
...jr ghea gurz vagb qrirybcref, naq gurl frrz gb yvxr vg gung jnl!

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

* Re: Cleanup PCI power states
  2004-12-21 23:37               ` Pavel Machek
@ 2004-12-22  0:41                 ` Greg KH
  0 siblings, 0 replies; 26+ messages in thread
From: Greg KH @ 2004-12-22  0:41 UTC (permalink / raw)
  To: Pavel Machek; +Cc: kernel list, Andrew Morton

On Wed, Dec 22, 2004 at 12:37:43AM +0100, Pavel Machek wrote:
> Hi!
> 
> > > > Alright, I've applied this, and it will show up in the next -mm release.
> > > > I also fixed up pci.h for when CONFIG_PCI=N due to your changed
> > > > functions.
> > > > 
> > > > Now, care to send patches to fix up all of the new sparse warnings in
> > > > the drivers/pci/* directory?
> > > 
> > > This should fix warnings in drivers/net/* and bttv (with exception of
> > > via-rhine, which I'll do separately). Do you think you could apply it,
> > > or shall I ask Andrew, or... ?
> > > 
> > > Signed-off-by: Pavel Machek <pavel@suse.cz>
> > 
> > What kernel tree is this against?  I get lots of rejects against the
> > latest -bk tree.
> 
> It was against 2.6.9. pci_{save,restore}_state(), therefore it rejects
> in surrounding text. Here's version against latest -bk.
> 
> This should fix sparse warnings in drivers/net/* and bttv. Please
> apply,

Applied, thanks.

greg k-h

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

end of thread, other threads:[~2004-12-22  0:41 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-16 13:04 Cleanup PCI power states Pavel Machek
2004-11-16 15:56 ` Greg KH
2004-11-17 12:08   ` Pavel Machek
2004-11-24 23:40     ` Greg KH
2004-11-25 11:36       ` Pavel Machek
2004-12-17  0:05         ` Greg KH
2004-12-17  0:31           ` Pavel Machek
2004-12-17 16:12           ` [linux-pm] " Alan Stern
2004-12-17 16:33             ` Pavel Machek
2004-12-17 22:02         ` Greg KH
2004-12-17 23:39           ` Pavel Machek
2004-12-21 19:57             ` Greg KH
2004-12-17 23:50           ` Pavel Machek
2004-12-21 20:03             ` Greg KH
2004-12-21 23:25               ` Pavel Machek
2004-12-21 23:29                 ` Greg KH
2004-12-18  0:09           ` Pavel Machek
2004-12-21 20:04             ` Greg KH
2004-12-21 23:37               ` Pavel Machek
2004-12-22  0:41                 ` Greg KH
2004-11-25 11:39       ` Pavel Machek
2004-12-17  0:06         ` Greg KH
2004-12-17  0:34           ` Pavel Machek
2004-12-17  7:48           ` [linux-pm] " Benjamin Herrenschmidt
2004-12-17 19:22             ` Greg KH
2004-12-17 22:02         ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.