Subject: PATCH: name PCI pwr-mgmt constants
To: None <tech-kern@netbsd.org>
From: David Young <dyoung@pobox.com>
List: tech-kern
Date: 03/29/2004 00:34:23
--xXmbgvnjoT4axfJE
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

In no fewer than three network drivers---ath, atw, ex, rtk,
tlp---essentially the same code for reseting the PCI power management
appears.  I have tried to name the constants. (See the attached
patch.) Did I get it right?

I would like to pull the duplicated code out from ath, atw, ex, and
tlp and into a subroutine. I will put the subroutine into a new file,
sys/dev/cardbus/cardbus_pmgt.c. Each of ath, atw, etc., will require
that module. Make sense?

Dave

-- 
David Young             OJC Technologies
dyoung@ojctech.com      Urbana, IL * (217) 278-3933

--xXmbgvnjoT4axfJE
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=cardbus-pwrmgmt-patch

Index: if_ath_cardbus.c
===================================================================
RCS file: /cvsroot/src/sys/dev/cardbus/if_ath_cardbus.c,v
retrieving revision 1.1
diff -u -r1.1 if_ath_cardbus.c
--- if_ath_cardbus.c	14 Oct 2003 17:47:03 -0000	1.1
+++ if_ath_cardbus.c	29 Mar 2004 06:21:44 -0000
@@ -315,9 +315,10 @@
 
 	if (cardbus_get_capability(cc, cf, csc->sc_tag,
 	    PCI_CAP_PWRMGMT, &pmreg, 0)) {
-		reg = cardbus_conf_read(cc, cf, csc->sc_tag, pmreg + 4);
+		reg = cardbus_conf_read(cc, cf, csc->sc_tag,
+		    pmreg + PCI_PMCSR) & PCI_PMCSR_STATE_MASK;
 #if 1 /* XXX Probably not right for CardBus. */
-		if (reg & 0x03) {
+		if (reg == PCI_PMCSR_STATE_D3) {
 			/*
 			 * The card has lost all configuration data in
 			 * this state, so punt.
@@ -327,11 +328,11 @@
 			return;
 		}
 #endif
-		if (reg != 0) {
+		if (reg != PCI_PMCSR_STATE_D0) {
 			printf("%s: waking up from power state D%d\n",
 			    sc->sc_dev.dv_xname, reg);
 			cardbus_conf_write(cc, cf, csc->sc_tag,
-			    pmreg + 4, 0);
+			    pmreg + PCI_PMCSR, PCI_PMCSR_STATE_D0);
 		}
 	}
 
Index: if_atw_cardbus.c
===================================================================
RCS file: /cvsroot/src/sys/dev/cardbus/if_atw_cardbus.c,v
retrieving revision 1.6
diff -u -r1.6 if_atw_cardbus.c
--- if_atw_cardbus.c	17 Feb 2004 21:20:55 -0000	1.6
+++ if_atw_cardbus.c	29 Mar 2004 06:21:44 -0000
@@ -412,9 +412,10 @@
 
 	if (cardbus_get_capability(cc, cf, csc->sc_tag,
 	    PCI_CAP_PWRMGMT, &pmreg, 0)) {
-		reg = cardbus_conf_read(cc, cf, csc->sc_tag, pmreg + 4) & 0x03;
+		reg = cardbus_conf_read(cc, cf, csc->sc_tag,
+		    pmreg + PCI_PMCSR) & PCI_PMCSR_STATE_MASK;
 #if 1 /* XXX Probably not right for CardBus. */
-		if (reg == 3) {
+		if (reg == PCI_PMCSR_STATE_D3) {
 			/*
 			 * The card has lost all configuration data in
 			 * this state, so punt.
@@ -424,11 +425,11 @@
 			return;
 		}
 #endif
-		if (reg != 0) {
+		if (reg != PCI_PMCSR_STATE_D0) {
 			printf("%s: waking up from power state D%d\n",
 			    sc->sc_dev.dv_xname, reg);
 			cardbus_conf_write(cc, cf, csc->sc_tag,
-			    pmreg + 4, 0);
+			    pmreg + PCI_PMCSR, PCI_PMCSR_STATE_D0);
 		}
 	}
 
Index: if_ex_cardbus.c
===================================================================
RCS file: /cvsroot/src/sys/dev/cardbus/if_ex_cardbus.c,v
retrieving revision 1.28
diff -u -r1.28 if_ex_cardbus.c
--- if_ex_cardbus.c	2 Nov 2003 09:56:38 -0000	1.28
+++ if_ex_cardbus.c	29 Mar 2004 06:21:44 -0000
@@ -403,11 +403,12 @@
 	int pmreg;
 
 	/* Get it out of power save mode if needed (BIOS bugs). */
-	if (cardbus_get_capability(cc, cf, csc->sc_tag,
-	    PCI_CAP_PWRMGMT, &pmreg, 0)) {
-		reg = cardbus_conf_read(cc, cf, csc->sc_tag, pmreg + 4) & 0x03;
+	if (cardbus_get_capability(cc, cf, csc->sc_tag, PCI_CAP_PWRMGMT,
+	    &pmreg, 0)) {
+		reg = cardbus_conf_read(cc, cf, csc->sc_tag,
+		    pmreg + PCI_PMCSR) & PCI_PMCSR_STATE_MASK;
 #if 1 /* XXX Probably not right for CardBus. */
-		if (reg == 3) {
+		if (reg == PCI_PMCSR_STATE_D3) {
 			/*
 			 * The card has lost all configuration data in
 			 * this state, so punt.
@@ -417,11 +418,11 @@
 			return;
 		}
 #endif
-		if (reg != 0) {
+		if (reg != PCI_PMCSR_STATE_D0) {
 			printf("%s: waking up from power state D%d\n",
 			    sc->sc_dev.dv_xname, reg);
 			cardbus_conf_write(cc, cf, csc->sc_tag,
-			    pmreg + 4, 0);
+			    pmreg + PCI_PMCSR, PCI_PMCSR_STATE_D0);
 		}
 	}
 
Index: if_rtk_cardbus.c
===================================================================
RCS file: /cvsroot/src/sys/dev/cardbus/if_rtk_cardbus.c,v
retrieving revision 1.19
diff -u -r1.19 if_rtk_cardbus.c
--- if_rtk_cardbus.c	11 Mar 2004 12:19:14 -0000	1.19
+++ if_rtk_cardbus.c	29 Mar 2004 06:21:45 -0000
@@ -314,7 +314,8 @@
 	 */
 	if (cardbus_get_capability(cc, cf, csc->sc_tag,
 	    PCI_CAP_PWRMGMT, &pmreg, 0)) {
-		command = cardbus_conf_read(cc, cf, csc->sc_tag, pmreg + 4);
+		command = cardbus_conf_read(cc, cf, csc->sc_tag,
+		    pmreg + PCI_PMCSR);
 		if (command & RTK_PSTATE_MASK) {
 			pcireg_t		iobase, membase, irq;
 
@@ -330,9 +331,9 @@
 			printf("%s: chip is in D%d power mode "
 			    "-- setting to D0\n", sc->sc_dev.dv_xname,
 			    command & RTK_PSTATE_MASK);
-			command &= 0xFFFFFFFC;
+			command &= ~RTK_PSTATE_MASK;
 			cardbus_conf_write(cc, cf, csc->sc_tag,
-			    pmreg + 4, command);
+			    pmreg + PCI_PMCSR, command);
 
 			/* Restore PCI config data. */
 			cardbus_conf_write(cc, cf, csc->sc_tag,
Index: if_tlp_cardbus.c
===================================================================
RCS file: /cvsroot/src/sys/dev/cardbus/if_tlp_cardbus.c,v
retrieving revision 1.39
diff -u -r1.39 if_tlp_cardbus.c
--- if_tlp_cardbus.c	24 Oct 2003 17:04:35 -0000	1.39
+++ if_tlp_cardbus.c	29 Mar 2004 06:21:45 -0000
@@ -623,9 +623,10 @@
 
 	if (cardbus_get_capability(cc, cf, csc->sc_tag,
 	    PCI_CAP_PWRMGMT, &pmreg, 0)) {
-		reg = cardbus_conf_read(cc, cf, csc->sc_tag, pmreg + 4) & 0x03;
+		reg = cardbus_conf_read(cc, cf, csc->sc_tag,
+		    pmreg + PCI_PMCSR) & PCI_PMCSR_STATE_MASK;
 #if 1 /* XXX Probably not right for CardBus. */
-		if (reg == 3) {
+		if (reg == PCI_PMCSR_STATE_D3) {
 			/*
 			 * The card has lost all configuration data in
 			 * this state, so punt.
@@ -635,11 +636,11 @@
 			return;
 		}
 #endif
-		if (reg != 0) {
+		if (reg != PCI_PMCSR_STATE_D0) {
 			printf("%s: waking up from power state D%d\n",
 			    sc->sc_dev.dv_xname, reg);
 			cardbus_conf_write(cc, cf, csc->sc_tag,
-			    pmreg + 4, 0);
+			    pmreg + PCI_PMCSR, PCI_PMCSR_STATE_D0);
 		}
 	}
 

--xXmbgvnjoT4axfJE--