Tue May 5 10:02:52 2009 UTC ()
print autoconf error message with aprint_error


(cegger)
diff -r1.49 -r1.50 src/sys/dev/pci/if_ex_pci.c

cvs diff -r1.49 -r1.50 src/sys/dev/pci/if_ex_pci.c (switch to unified diff)

--- src/sys/dev/pci/if_ex_pci.c 2008/04/28 20:23:55 1.49
+++ src/sys/dev/pci/if_ex_pci.c 2009/05/05 10:02:52 1.50
@@ -1,420 +1,420 @@ @@ -1,420 +1,420 @@
1/* $NetBSD: if_ex_pci.c,v 1.49 2008/04/28 20:23:55 martin Exp $ */ 1/* $NetBSD: if_ex_pci.c,v 1.50 2009/05/05 10:02:52 cegger Exp $ */
2 2
3/*- 3/*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc. 4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved. 5 * All rights reserved.
6 * 6 *
7 * This code is derived from software contributed to The NetBSD Foundation 7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Frank van der Linden; Jason R. Thorpe of the Numerical Aerospace 8 * by Frank van der Linden; Jason R. Thorpe of the Numerical Aerospace
9 * Simulation Facility, NASA Ames Research Center. 9 * Simulation Facility, NASA Ames Research Center.
10 * 10 *
11 * Redistribution and use in source and binary forms, with or without 11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions 12 * modification, are permitted provided that the following conditions
13 * are met: 13 * are met:
14 * 1. Redistributions of source code must retain the above copyright 14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer. 15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright 16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the 17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution. 18 * documentation and/or other materials provided with the distribution.
19 * 19 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE. 30 * POSSIBILITY OF SUCH DAMAGE.
31 */ 31 */
32 32
33#include <sys/cdefs.h> 33#include <sys/cdefs.h>
34__KERNEL_RCSID(0, "$NetBSD: if_ex_pci.c,v 1.49 2008/04/28 20:23:55 martin Exp $"); 34__KERNEL_RCSID(0, "$NetBSD: if_ex_pci.c,v 1.50 2009/05/05 10:02:52 cegger Exp $");
35 35
36#include <sys/param.h> 36#include <sys/param.h>
37#include <sys/systm.h> 37#include <sys/systm.h>
38#include <sys/mbuf.h> 38#include <sys/mbuf.h>
39#include <sys/socket.h> 39#include <sys/socket.h>
40#include <sys/ioctl.h> 40#include <sys/ioctl.h>
41#include <sys/errno.h> 41#include <sys/errno.h>
42#include <sys/syslog.h> 42#include <sys/syslog.h>
43#include <sys/select.h> 43#include <sys/select.h>
44#include <sys/device.h> 44#include <sys/device.h>
45 45
46#include <net/if.h> 46#include <net/if.h>
47#include <net/if_dl.h> 47#include <net/if_dl.h>
48#include <net/if_ether.h> 48#include <net/if_ether.h>
49#include <net/if_media.h> 49#include <net/if_media.h>
50 50
51#include <sys/cpu.h> 51#include <sys/cpu.h>
52#include <sys/bus.h> 52#include <sys/bus.h>
53#include <sys/intr.h> 53#include <sys/intr.h>
54 54
55#include <dev/mii/miivar.h> 55#include <dev/mii/miivar.h>
56#include <dev/mii/mii.h> 56#include <dev/mii/mii.h>
57 57
58#include <dev/ic/elink3var.h> 58#include <dev/ic/elink3var.h>
59#include <dev/ic/elink3reg.h> 59#include <dev/ic/elink3reg.h>
60#include <dev/ic/elinkxlreg.h> 60#include <dev/ic/elinkxlreg.h>
61#include <dev/ic/elinkxlvar.h> 61#include <dev/ic/elinkxlvar.h>
62 62
63#include <dev/pci/pcivar.h> 63#include <dev/pci/pcivar.h>
64#include <dev/pci/pcireg.h> 64#include <dev/pci/pcireg.h>
65#include <dev/pci/pcidevs.h> 65#include <dev/pci/pcidevs.h>
66 66
67struct ex_pci_softc { 67struct ex_pci_softc {
68 struct ex_softc sc_ex; 68 struct ex_softc sc_ex;
69 69
70 /* PCI function status space. 556,556B requests it. */ 70 /* PCI function status space. 556,556B requests it. */
71 bus_space_tag_t sc_funct; 71 bus_space_tag_t sc_funct;
72 bus_space_handle_t sc_funch; 72 bus_space_handle_t sc_funch;
73 73
74 pci_chipset_tag_t psc_pc; /* pci chipset tag */ 74 pci_chipset_tag_t psc_pc; /* pci chipset tag */
75 pcireg_t psc_regs[0x40>>2]; /* saved PCI config regs (sparse) */ 75 pcireg_t psc_regs[0x40>>2]; /* saved PCI config regs (sparse) */
76 pcitag_t psc_tag; /* pci device tag */ 76 pcitag_t psc_tag; /* pci device tag */
77 77
78 int psc_pwrmgmt_csr_reg; /* ACPI power management register */ 78 int psc_pwrmgmt_csr_reg; /* ACPI power management register */
79 pcireg_t psc_pwrmgmt_csr; /* ...and the contents at D0 */ 79 pcireg_t psc_pwrmgmt_csr; /* ...and the contents at D0 */
80}; 80};
81 81
82/* 82/*
83 * PCI constants. 83 * PCI constants.
84 * XXX These should be in a common file! 84 * XXX These should be in a common file!
85 */ 85 */
86#define PCI_CONN 0x48 /* Connector type */ 86#define PCI_CONN 0x48 /* Connector type */
87#define PCI_CBIO 0x10 /* Configuration Base IO Address */ 87#define PCI_CBIO 0x10 /* Configuration Base IO Address */
88#define PCI_POWERCTL 0xe0 88#define PCI_POWERCTL 0xe0
89#define PCI_FUNCMEM 0x18 89#define PCI_FUNCMEM 0x18
90 90
91#define PCI_INTR 4 91#define PCI_INTR 4
92#define PCI_INTRACK 0x00008000 92#define PCI_INTRACK 0x00008000
93 93
94static int ex_pci_match(device_t, cfdata_t, void *); 94static int ex_pci_match(device_t, cfdata_t, void *);
95static void ex_pci_attach(device_t, device_t, void *); 95static void ex_pci_attach(device_t, device_t, void *);
96static void ex_pci_intr_ack(struct ex_softc *); 96static void ex_pci_intr_ack(struct ex_softc *);
97 97
98static int ex_pci_enable(struct ex_softc *); 98static int ex_pci_enable(struct ex_softc *);
99static void ex_pci_disable(struct ex_softc *); 99static void ex_pci_disable(struct ex_softc *);
100 100
101static void ex_pci_confreg_restore(struct ex_pci_softc *); 101static void ex_pci_confreg_restore(struct ex_pci_softc *);
102static int ex_d3tod0(pci_chipset_tag_t, pcitag_t, device_t, pcireg_t); 102static int ex_d3tod0(pci_chipset_tag_t, pcitag_t, device_t, pcireg_t);
103 103
104CFATTACH_DECL_NEW(ex_pci, sizeof(struct ex_pci_softc), 104CFATTACH_DECL_NEW(ex_pci, sizeof(struct ex_pci_softc),
105 ex_pci_match, ex_pci_attach, NULL, NULL); 105 ex_pci_match, ex_pci_attach, NULL, NULL);
106 106
107static const struct ex_pci_product { 107static const struct ex_pci_product {
108 uint32_t epp_prodid; /* PCI product ID */ 108 uint32_t epp_prodid; /* PCI product ID */
109 int epp_flags; /* initial softc flags */ 109 int epp_flags; /* initial softc flags */
110 const char *epp_name; /* device name */ 110 const char *epp_name; /* device name */
111} ex_pci_products[] = { 111} ex_pci_products[] = {
112 { PCI_PRODUCT_3COM_3C900TPO, 0, 112 { PCI_PRODUCT_3COM_3C900TPO, 0,
113 "3c900-TPO Ethernet" }, 113 "3c900-TPO Ethernet" },
114 { PCI_PRODUCT_3COM_3C900COMBO, 0, 114 { PCI_PRODUCT_3COM_3C900COMBO, 0,
115 "3c900-COMBO Ethernet" }, 115 "3c900-COMBO Ethernet" },
116 116
117 { PCI_PRODUCT_3COM_3C905TX, EX_CONF_MII, 117 { PCI_PRODUCT_3COM_3C905TX, EX_CONF_MII,
118 "3c905-TX 10/100 Ethernet" }, 118 "3c905-TX 10/100 Ethernet" },
119 { PCI_PRODUCT_3COM_3C905T4, EX_CONF_MII, 119 { PCI_PRODUCT_3COM_3C905T4, EX_CONF_MII,
120 "3c905-T4 10/100 Ethernet" }, 120 "3c905-T4 10/100 Ethernet" },
121 121
122 { PCI_PRODUCT_3COM_3C900BTPO, EX_CONF_90XB, 122 { PCI_PRODUCT_3COM_3C900BTPO, EX_CONF_90XB,
123 "3c900B-TPO Ethernet" }, 123 "3c900B-TPO Ethernet" },
124 { PCI_PRODUCT_3COM_3C900BCOMBO, EX_CONF_90XB, 124 { PCI_PRODUCT_3COM_3C900BCOMBO, EX_CONF_90XB,
125 "3c900B-COMBO Ethernet" }, 125 "3c900B-COMBO Ethernet" },
126 { PCI_PRODUCT_3COM_3C900BTPC, EX_CONF_90XB, 126 { PCI_PRODUCT_3COM_3C900BTPC, EX_CONF_90XB,
127 "3c900B-TPC Ethernet" }, 127 "3c900B-TPC Ethernet" },
128 128
129 { PCI_PRODUCT_3COM_3C905BTX, EX_CONF_90XB|EX_CONF_MII|EX_CONF_INTPHY, 129 { PCI_PRODUCT_3COM_3C905BTX, EX_CONF_90XB|EX_CONF_MII|EX_CONF_INTPHY,
130 "3c905B-TX 10/100 Ethernet" }, 130 "3c905B-TX 10/100 Ethernet" },
131 { PCI_PRODUCT_3COM_3C905BT4, EX_CONF_90XB|EX_CONF_MII, 131 { PCI_PRODUCT_3COM_3C905BT4, EX_CONF_90XB|EX_CONF_MII,
132 "3c905B-T4 10/100 Ethernet" }, 132 "3c905B-T4 10/100 Ethernet" },
133 { PCI_PRODUCT_3COM_3C905BCOMBO, EX_CONF_90XB/*|EX_CONF_MII|EX_CONF_INTPHY*/, 133 { PCI_PRODUCT_3COM_3C905BCOMBO, EX_CONF_90XB/*|EX_CONF_MII|EX_CONF_INTPHY*/,
134 "3c905B-COMBO 10/100 Ethernet" }, 134 "3c905B-COMBO 10/100 Ethernet" },
135 { PCI_PRODUCT_3COM_3C905BFX, EX_CONF_90XB, 135 { PCI_PRODUCT_3COM_3C905BFX, EX_CONF_90XB,
136 "3c905B-FX 10/100 Ethernet" }, 136 "3c905B-FX 10/100 Ethernet" },
137 137
138 /* XXX Internal PHY? */ 138 /* XXX Internal PHY? */
139 { PCI_PRODUCT_3COM_3C980SRV, EX_CONF_90XB, 139 { PCI_PRODUCT_3COM_3C980SRV, EX_CONF_90XB,
140 "3c980 Server Adapter 10/100 Ethernet" }, 140 "3c980 Server Adapter 10/100 Ethernet" },
141 { PCI_PRODUCT_3COM_3C980CTXM, EX_CONF_90XB|EX_CONF_MII, 141 { PCI_PRODUCT_3COM_3C980CTXM, EX_CONF_90XB|EX_CONF_MII,
142 "3c980C-TXM 10/100 Ethernet" }, 142 "3c980C-TXM 10/100 Ethernet" },
143 143
144 { PCI_PRODUCT_3COM_3C905CTX, EX_CONF_90XB|EX_CONF_MII, 144 { PCI_PRODUCT_3COM_3C905CTX, EX_CONF_90XB|EX_CONF_MII,
145 "3c905C-TX 10/100 Ethernet with mngmt" }, 145 "3c905C-TX 10/100 Ethernet with mngmt" },
146 146
147 { PCI_PRODUCT_3COM_3C450TX, EX_CONF_90XB, 147 { PCI_PRODUCT_3COM_3C450TX, EX_CONF_90XB,
148 "3c450-TX 10/100 Ethernet" }, 148 "3c450-TX 10/100 Ethernet" },
149 149
150 { PCI_PRODUCT_3COM_3CSOHO100TX, EX_CONF_90XB, 150 { PCI_PRODUCT_3COM_3CSOHO100TX, EX_CONF_90XB,
151 "3cSOHO100-TX 10/100 Ethernet" }, 151 "3cSOHO100-TX 10/100 Ethernet" },
152 152
153 { PCI_PRODUCT_3COM_3C555, 153 { PCI_PRODUCT_3COM_3C555,
154 EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF | 154 EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF |
155 EX_CONF_EEPROM_8BIT, 155 EX_CONF_EEPROM_8BIT,
156 "3c555 MiniPCI 10/100 Ethernet" }, 156 "3c555 MiniPCI 10/100 Ethernet" },
157 157
158 { PCI_PRODUCT_3COM_3C556, 158 { PCI_PRODUCT_3COM_3C556,
159 EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF | 159 EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF |
160 EX_CONF_PCI_FUNCREG | EX_CONF_RESETHACK | EX_CONF_INV_LED_POLARITY | 160 EX_CONF_PCI_FUNCREG | EX_CONF_RESETHACK | EX_CONF_INV_LED_POLARITY |
161 EX_CONF_PHY_POWER | EX_CONF_EEPROM_8BIT, 161 EX_CONF_PHY_POWER | EX_CONF_EEPROM_8BIT,
162 "3c556 MiniPCI 10/100 Ethernet" }, 162 "3c556 MiniPCI 10/100 Ethernet" },
163 163
164 { PCI_PRODUCT_3COM_3C556B, 164 { PCI_PRODUCT_3COM_3C556B,
165 EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF | 165 EX_CONF_90XB | EX_CONF_MII | EX_CONF_EEPROM_OFF |
166 EX_CONF_PCI_FUNCREG | EX_CONF_RESETHACK | EX_CONF_INV_LED_POLARITY | 166 EX_CONF_PCI_FUNCREG | EX_CONF_RESETHACK | EX_CONF_INV_LED_POLARITY |
167 EX_CONF_PHY_POWER | EX_CONF_NO_XCVR_PWR, 167 EX_CONF_PHY_POWER | EX_CONF_NO_XCVR_PWR,
168 "3c556B MiniPCI 10/100 Ethernet" }, 168 "3c556B MiniPCI 10/100 Ethernet" },
169 169
170 { PCI_PRODUCT_3COM_3C905CXTX, EX_CONF_90XB|EX_CONF_MII, 170 { PCI_PRODUCT_3COM_3C905CXTX, EX_CONF_90XB|EX_CONF_MII,
171 "3c905CX-TX 10/100 Ethernet with mngmt" }, 171 "3c905CX-TX 10/100 Ethernet with mngmt" },
172 172
173 { PCI_PRODUCT_3COM_3C920BEMBW, EX_CONF_90XB|EX_CONF_MII, 173 { PCI_PRODUCT_3COM_3C920BEMBW, EX_CONF_90XB|EX_CONF_MII,
174 "3c920B-EMB-WNM Integrated Fast Ethernet" }, 174 "3c920B-EMB-WNM Integrated Fast Ethernet" },
175 175
176 { 0, 0, 176 { 0, 0,
177 NULL }, 177 NULL },
178}; 178};
179 179
180static const struct ex_pci_product * 180static const struct ex_pci_product *
181ex_pci_lookup(const struct pci_attach_args *pa) 181ex_pci_lookup(const struct pci_attach_args *pa)
182{ 182{
183 const struct ex_pci_product *epp; 183 const struct ex_pci_product *epp;
184 184
185 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM) 185 if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_3COM)
186 return (NULL); 186 return (NULL);
187 187
188 for (epp = ex_pci_products; epp->epp_name != NULL; epp++) 188 for (epp = ex_pci_products; epp->epp_name != NULL; epp++)
189 if (PCI_PRODUCT(pa->pa_id) == epp->epp_prodid) 189 if (PCI_PRODUCT(pa->pa_id) == epp->epp_prodid)
190 return (epp); 190 return (epp);
191 return (NULL); 191 return (NULL);
192} 192}
193 193
194static int 194static int
195ex_pci_match(device_t parent, cfdata_t match, 195ex_pci_match(device_t parent, cfdata_t match,
196 void *aux) 196 void *aux)
197{ 197{
198 struct pci_attach_args *pa = (struct pci_attach_args *) aux; 198 struct pci_attach_args *pa = (struct pci_attach_args *) aux;
199 199
200 if (ex_pci_lookup(pa) != NULL) 200 if (ex_pci_lookup(pa) != NULL)
201 return (2); /* beat ep_pci */ 201 return (2); /* beat ep_pci */
202 202
203 return (0); 203 return (0);
204} 204}
205 205
206static void 206static void
207ex_pci_attach(device_t parent, device_t self, void *aux) 207ex_pci_attach(device_t parent, device_t self, void *aux)
208{ 208{
209 struct ex_pci_softc *psc = device_private(self); 209 struct ex_pci_softc *psc = device_private(self);
210 struct ex_softc *sc = &psc->sc_ex; 210 struct ex_softc *sc = &psc->sc_ex;
211 struct pci_attach_args *pa = aux; 211 struct pci_attach_args *pa = aux;
212 pci_chipset_tag_t pc = pa->pa_pc; 212 pci_chipset_tag_t pc = pa->pa_pc;
213 pci_intr_handle_t ih; 213 pci_intr_handle_t ih;
214 const struct ex_pci_product *epp; 214 const struct ex_pci_product *epp;
215 const char *intrstr = NULL; 215 const char *intrstr = NULL;
216 int rev; 216 int rev;
217 int error; 217 int error;
218 218
219 aprint_naive(": Ethernet controller\n"); 219 aprint_naive(": Ethernet controller\n");
220 220
221 sc->sc_dev = self; 221 sc->sc_dev = self;
222 222
223 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0, 223 if (pci_mapreg_map(pa, PCI_CBIO, PCI_MAPREG_TYPE_IO, 0,
224 &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) { 224 &sc->sc_iot, &sc->sc_ioh, NULL, NULL)) {
225 aprint_error(": can't map i/o space\n"); 225 aprint_error(": can't map i/o space\n");
226 return; 226 return;
227 } 227 }
228 228
229 epp = ex_pci_lookup(pa); 229 epp = ex_pci_lookup(pa);
230 if (epp == NULL) { 230 if (epp == NULL) {
231 printf("\n"); 231 printf("\n");
232 panic("ex_pci_attach: impossible"); 232 panic("ex_pci_attach: impossible");
233 } 233 }
234 234
235 rev = PCI_REVISION(pci_conf_read(pc, pa->pa_tag, PCI_CLASS_REG)); 235 rev = PCI_REVISION(pci_conf_read(pc, pa->pa_tag, PCI_CLASS_REG));
236 aprint_normal(": 3Com %s (rev. 0x%x)\n", epp->epp_name, rev); 236 aprint_normal(": 3Com %s (rev. 0x%x)\n", epp->epp_name, rev);
237 237
238 sc->sc_dmat = pa->pa_dmat; 238 sc->sc_dmat = pa->pa_dmat;
239 239
240 sc->ex_bustype = EX_BUS_PCI; 240 sc->ex_bustype = EX_BUS_PCI;
241 sc->ex_conf = epp->epp_flags; 241 sc->ex_conf = epp->epp_flags;
242 242
243 /* Enable the card. */ 243 /* Enable the card. */
244 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG, 244 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
245 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) | 245 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
246 PCI_COMMAND_MASTER_ENABLE); 246 PCI_COMMAND_MASTER_ENABLE);
247 247
248 psc->psc_pc = pc; 248 psc->psc_pc = pc;
249 psc->psc_tag = pa->pa_tag; 249 psc->psc_tag = pa->pa_tag;
250 psc->psc_regs[PCI_COMMAND_STATUS_REG>>2] = 250 psc->psc_regs[PCI_COMMAND_STATUS_REG>>2] =
251 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG); 251 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
252 psc->psc_regs[PCI_BHLC_REG>>2] = 252 psc->psc_regs[PCI_BHLC_REG>>2] =
253 pci_conf_read(pc, pa->pa_tag, PCI_BHLC_REG); 253 pci_conf_read(pc, pa->pa_tag, PCI_BHLC_REG);
254 psc->psc_regs[PCI_CBIO>>2] = 254 psc->psc_regs[PCI_CBIO>>2] =
255 pci_conf_read(pc, pa->pa_tag, PCI_CBIO); 255 pci_conf_read(pc, pa->pa_tag, PCI_CBIO);
256 256
257 if (sc->ex_conf & EX_CONF_PCI_FUNCREG) { 257 if (sc->ex_conf & EX_CONF_PCI_FUNCREG) {
258 /* Map PCI function status window. */ 258 /* Map PCI function status window. */
259 if (pci_mapreg_map(pa, PCI_FUNCMEM, PCI_MAPREG_TYPE_MEM, 0, 259 if (pci_mapreg_map(pa, PCI_FUNCMEM, PCI_MAPREG_TYPE_MEM, 0,
260 &psc->sc_funct, &psc->sc_funch, NULL, NULL)) { 260 &psc->sc_funct, &psc->sc_funch, NULL, NULL)) {
261 aprint_error_dev(self, 261 aprint_error_dev(self,
262 "unable to map function status window\n"); 262 "unable to map function status window\n");
263 return; 263 return;
264 } 264 }
265 sc->intr_ack = ex_pci_intr_ack; 265 sc->intr_ack = ex_pci_intr_ack;
266 266
267 psc->psc_regs[PCI_FUNCMEM>>2] = 267 psc->psc_regs[PCI_FUNCMEM>>2] =
268 pci_conf_read(pc, pa->pa_tag, PCI_FUNCMEM); 268 pci_conf_read(pc, pa->pa_tag, PCI_FUNCMEM);
269 } 269 }
270 270
271 psc->psc_regs[PCI_INTERRUPT_REG>>2] = 271 psc->psc_regs[PCI_INTERRUPT_REG>>2] =
272 pci_conf_read(pc, pa->pa_tag, PCI_INTERRUPT_REG); 272 pci_conf_read(pc, pa->pa_tag, PCI_INTERRUPT_REG);
273 /* power up chip */ 273 /* power up chip */
274 error = pci_activate(pa->pa_pc, pa->pa_tag, self, ex_d3tod0); 274 error = pci_activate(pa->pa_pc, pa->pa_tag, self, ex_d3tod0);
275 switch (error) { 275 switch (error) {
276 case EOPNOTSUPP: 276 case EOPNOTSUPP:
277 break; 277 break;
278 case 0:  278 case 0:
279 sc->enable = ex_pci_enable; 279 sc->enable = ex_pci_enable;
280 sc->disable = ex_pci_disable; 280 sc->disable = ex_pci_disable;
281 break; 281 break;
282 default: 282 default:
283 aprint_error_dev(self, "cannot activate %d\n", error); 283 aprint_error_dev(self, "cannot activate %d\n", error);
284 return; 284 return;
285 } 285 }
286 sc->enabled = 1; 286 sc->enabled = 1;
287 287
288 /* Map and establish the interrupt. */ 288 /* Map and establish the interrupt. */
289 if (pci_intr_map(pa, &ih)) { 289 if (pci_intr_map(pa, &ih)) {
290 aprint_error_dev(self, "couldn't map interrupt\n"); 290 aprint_error_dev(self, "couldn't map interrupt\n");
291 return; 291 return;
292 } 292 }
293 293
294 intrstr = pci_intr_string(pc, ih); 294 intrstr = pci_intr_string(pc, ih);
295 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, ex_intr, sc); 295 sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, ex_intr, sc);
296 if (sc->sc_ih == NULL) { 296 if (sc->sc_ih == NULL) {
297 aprint_error_dev(self, "couldn't establish interrupt"); 297 aprint_error_dev(self, "couldn't establish interrupt");
298 if (intrstr != NULL) 298 if (intrstr != NULL)
299 aprint_normal(" at %s", intrstr); 299 aprint_error(" at %s", intrstr);
300 aprint_normal("\n"); 300 aprint_error("\n");
301 return; 301 return;
302 } 302 }
303 aprint_normal_dev(self, "interrupting at %s\n", intrstr); 303 aprint_normal_dev(self, "interrupting at %s\n", intrstr);
304 304
305 ex_config(sc); 305 ex_config(sc);
306 306
307 if (sc->ex_conf & EX_CONF_PCI_FUNCREG) 307 if (sc->ex_conf & EX_CONF_PCI_FUNCREG)
308 bus_space_write_4(psc->sc_funct, psc->sc_funch, PCI_INTR, 308 bus_space_write_4(psc->sc_funct, psc->sc_funch, PCI_INTR,
309 PCI_INTRACK); 309 PCI_INTRACK);
310 310
311 if (sc->disable != NULL) 311 if (sc->disable != NULL)
312 ex_disable(sc); 312 ex_disable(sc);
313} 313}
314 314
315static void 315static void
316ex_pci_intr_ack(struct ex_softc *sc) 316ex_pci_intr_ack(struct ex_softc *sc)
317{ 317{
318 struct ex_pci_softc *psc = (struct ex_pci_softc *)sc; 318 struct ex_pci_softc *psc = (struct ex_pci_softc *)sc;
319 319
320 bus_space_write_4(psc->sc_funct, psc->sc_funch, PCI_INTR, 320 bus_space_write_4(psc->sc_funct, psc->sc_funch, PCI_INTR,
321 PCI_INTRACK); 321 PCI_INTRACK);
322} 322}
323 323
324static int 324static int
325ex_d3tod0(pci_chipset_tag_t pc, pcitag_t tag, device_t self, pcireg_t state) 325ex_d3tod0(pci_chipset_tag_t pc, pcitag_t tag, device_t self, pcireg_t state)
326{ 326{
327 327
328#define PCI_CACHE_LAT_BIST 0x0c 328#define PCI_CACHE_LAT_BIST 0x0c
329#define PCI_BAR0 0x10 329#define PCI_BAR0 0x10
330#define PCI_BAR1 0x14 330#define PCI_BAR1 0x14
331#define PCI_BAR2 0x18 331#define PCI_BAR2 0x18
332#define PCI_BAR3 0x1C 332#define PCI_BAR3 0x1C
333#define PCI_BAR4 0x20 333#define PCI_BAR4 0x20
334#define PCI_BAR5 0x24 334#define PCI_BAR5 0x24
335#define PCI_EXP_ROM_BAR 0x30 335#define PCI_EXP_ROM_BAR 0x30
336#define PCI_INT_GNT_LAT 0x3c 336#define PCI_INT_GNT_LAT 0x3c
337 337
338 uint32_t base0; 338 uint32_t base0;
339 uint32_t base1; 339 uint32_t base1;
340 uint32_t romaddr; 340 uint32_t romaddr;
341 uint32_t pci_command; 341 uint32_t pci_command;
342 uint32_t pci_int_lat; 342 uint32_t pci_int_lat;
343 uint32_t pci_cache_lat; 343 uint32_t pci_cache_lat;
344 344
345 if (state != PCI_PMCSR_STATE_D3) 345 if (state != PCI_PMCSR_STATE_D3)
346 return 0; 346 return 0;
347 347
348 aprint_normal_dev(self, "found in power state D%d, " 348 aprint_normal_dev(self, "found in power state D%d, "
349 "attempting to recover.\n", state); 349 "attempting to recover.\n", state);
350 pci_command = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG); 350 pci_command = pci_conf_read(pc, tag, PCI_COMMAND_STATUS_REG);
351 base0 = pci_conf_read(pc, tag, PCI_BAR0); 351 base0 = pci_conf_read(pc, tag, PCI_BAR0);
352 base1 = pci_conf_read(pc, tag, PCI_BAR1); 352 base1 = pci_conf_read(pc, tag, PCI_BAR1);
353 romaddr = pci_conf_read(pc, tag, PCI_EXP_ROM_BAR); 353 romaddr = pci_conf_read(pc, tag, PCI_EXP_ROM_BAR);
354 pci_cache_lat= pci_conf_read(pc, tag, PCI_CACHE_LAT_BIST); 354 pci_cache_lat= pci_conf_read(pc, tag, PCI_CACHE_LAT_BIST);
355 pci_int_lat = pci_conf_read(pc, tag, PCI_INT_GNT_LAT); 355 pci_int_lat = pci_conf_read(pc, tag, PCI_INT_GNT_LAT);
356 356
357 pci_conf_write(pc, tag, PCI_POWERCTL, 0); 357 pci_conf_write(pc, tag, PCI_POWERCTL, 0);
358 pci_conf_write(pc, tag, PCI_BAR0, base0); 358 pci_conf_write(pc, tag, PCI_BAR0, base0);
359 pci_conf_write(pc, tag, PCI_BAR1, base1); 359 pci_conf_write(pc, tag, PCI_BAR1, base1);
360 pci_conf_write(pc, tag, PCI_EXP_ROM_BAR, romaddr); 360 pci_conf_write(pc, tag, PCI_EXP_ROM_BAR, romaddr);
361 pci_conf_write(pc, tag, PCI_INT_GNT_LAT, pci_int_lat); 361 pci_conf_write(pc, tag, PCI_INT_GNT_LAT, pci_int_lat);
362 pci_conf_write(pc, tag, PCI_CACHE_LAT_BIST, pci_cache_lat); 362 pci_conf_write(pc, tag, PCI_CACHE_LAT_BIST, pci_cache_lat);
363 pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG, 363 pci_conf_write(pc, tag, PCI_COMMAND_STATUS_REG,
364 (PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE)); 364 (PCI_COMMAND_MASTER_ENABLE | PCI_COMMAND_IO_ENABLE));
365 aprint_normal_dev(self, "changed power state to D0.\n"); 365 aprint_normal_dev(self, "changed power state to D0.\n");
366 return 0; 366 return 0;
367} 367}
368 368
369static void 369static void
370ex_pci_confreg_restore(struct ex_pci_softc *psc) 370ex_pci_confreg_restore(struct ex_pci_softc *psc)
371{ 371{
372 struct ex_softc *sc = (void *) psc; 372 struct ex_softc *sc = (void *) psc;
373 pcireg_t reg; 373 pcireg_t reg;
374 374
375 reg = pci_conf_read(psc->psc_pc, psc->psc_tag, PCI_COMMAND_STATUS_REG); 375 reg = pci_conf_read(psc->psc_pc, psc->psc_tag, PCI_COMMAND_STATUS_REG);
376 376
377 pci_conf_write(psc->psc_pc, psc->psc_tag, 377 pci_conf_write(psc->psc_pc, psc->psc_tag,
378 PCI_COMMAND_STATUS_REG, 378 PCI_COMMAND_STATUS_REG,
379 (reg & 0xffff0000) | 379 (reg & 0xffff0000) |
380 (psc->psc_regs[PCI_COMMAND_STATUS_REG>>2] & 0xffff)); 380 (psc->psc_regs[PCI_COMMAND_STATUS_REG>>2] & 0xffff));
381 pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_BHLC_REG, 381 pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_BHLC_REG,
382 psc->psc_regs[PCI_BHLC_REG>>2]); 382 psc->psc_regs[PCI_BHLC_REG>>2]);
383 pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_CBIO, 383 pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_CBIO,
384 psc->psc_regs[PCI_CBIO>>2]); 384 psc->psc_regs[PCI_CBIO>>2]);
385 if (sc->ex_conf & EX_CONF_PCI_FUNCREG) 385 if (sc->ex_conf & EX_CONF_PCI_FUNCREG)
386 pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_FUNCMEM, 386 pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_FUNCMEM,
387 psc->psc_regs[PCI_FUNCMEM>>2]); 387 psc->psc_regs[PCI_FUNCMEM>>2]);
388 pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_INTERRUPT_REG, 388 pci_conf_write(psc->psc_pc, psc->psc_tag, PCI_INTERRUPT_REG,
389 psc->psc_regs[PCI_INTERRUPT_REG>>2]); 389 psc->psc_regs[PCI_INTERRUPT_REG>>2]);
390} 390}
391 391
392static int 392static int
393ex_pci_enable(struct ex_softc *sc) 393ex_pci_enable(struct ex_softc *sc)
394{ 394{
395 struct ex_pci_softc *psc = (void *) sc; 395 struct ex_pci_softc *psc = (void *) sc;
396 396
397 aprint_debug_dev(sc->sc_dev, "going to power state D0\n"); 397 aprint_debug_dev(sc->sc_dev, "going to power state D0\n");
398 398
399 /* Bring the device into D0 power state. */ 399 /* Bring the device into D0 power state. */
400 pci_conf_write(psc->psc_pc, psc->psc_tag, 400 pci_conf_write(psc->psc_pc, psc->psc_tag,
401 psc->psc_pwrmgmt_csr_reg, psc->psc_pwrmgmt_csr); 401 psc->psc_pwrmgmt_csr_reg, psc->psc_pwrmgmt_csr);
402 402
403 /* Now restore the configuration registers. */ 403 /* Now restore the configuration registers. */
404 ex_pci_confreg_restore(psc); 404 ex_pci_confreg_restore(psc);
405 405
406 return (0); 406 return (0);
407} 407}
408 408
409static void 409static void
410ex_pci_disable(struct ex_softc *sc) 410ex_pci_disable(struct ex_softc *sc)
411{ 411{
412 struct ex_pci_softc *psc = (void *) sc; 412 struct ex_pci_softc *psc = (void *) sc;
413 413
414 aprint_debug_dev(sc->sc_dev, "going to power state D3\n"); 414 aprint_debug_dev(sc->sc_dev, "going to power state D3\n");
415 415
416 /* Put the device into D3 state. */ 416 /* Put the device into D3 state. */
417 pci_conf_write(psc->psc_pc, psc->psc_tag, 417 pci_conf_write(psc->psc_pc, psc->psc_tag,
418 psc->psc_pwrmgmt_csr_reg, (psc->psc_pwrmgmt_csr & 418 psc->psc_pwrmgmt_csr_reg, (psc->psc_pwrmgmt_csr &
419 ~PCI_PMCSR_STATE_MASK) | PCI_PMCSR_STATE_D3); 419 ~PCI_PMCSR_STATE_MASK) | PCI_PMCSR_STATE_D3);
420} 420}