if_tlp_cardbus.c revision 1.22 1 1.22 thorpej /* $NetBSD: if_tlp_cardbus.c,v 1.22 2000/03/22 01:35:14 thorpej Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*-
4 1.10 thorpej * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 thorpej * NASA Ames Research Center.
10 1.1 thorpej *
11 1.1 thorpej * Redistribution and use in source and binary forms, with or without
12 1.1 thorpej * modification, are permitted provided that the following conditions
13 1.1 thorpej * are met:
14 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.1 thorpej * notice, this list of conditions and the following disclaimer.
16 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.1 thorpej * documentation and/or other materials provided with the distribution.
19 1.1 thorpej * 3. All advertising materials mentioning features or use of this software
20 1.1 thorpej * must display the following acknowledgement:
21 1.1 thorpej * This product includes software developed by the NetBSD
22 1.1 thorpej * Foundation, Inc. and its contributors.
23 1.1 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.1 thorpej * contributors may be used to endorse or promote products derived
25 1.1 thorpej * from this software without specific prior written permission.
26 1.1 thorpej *
27 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
38 1.1 thorpej */
39 1.1 thorpej
40 1.1 thorpej /*
41 1.1 thorpej * CardBus bus front-end for the Digital Semiconductor ``Tulip'' (21x4x)
42 1.1 thorpej * Ethernet controller family driver.
43 1.1 thorpej */
44 1.1 thorpej
45 1.1 thorpej #include "opt_inet.h"
46 1.1 thorpej #include "opt_ns.h"
47 1.1 thorpej #include "bpfilter.h"
48 1.1 thorpej
49 1.1 thorpej #include <sys/param.h>
50 1.1 thorpej #include <sys/systm.h>
51 1.1 thorpej #include <sys/mbuf.h>
52 1.1 thorpej #include <sys/malloc.h>
53 1.1 thorpej #include <sys/kernel.h>
54 1.1 thorpej #include <sys/socket.h>
55 1.1 thorpej #include <sys/ioctl.h>
56 1.1 thorpej #include <sys/errno.h>
57 1.1 thorpej #include <sys/device.h>
58 1.5 thorpej
59 1.5 thorpej #include <machine/endian.h>
60 1.1 thorpej
61 1.1 thorpej #include <net/if.h>
62 1.1 thorpej #include <net/if_dl.h>
63 1.1 thorpej #include <net/if_media.h>
64 1.1 thorpej #include <net/if_ether.h>
65 1.1 thorpej
66 1.1 thorpej #if NBPFILTER > 0
67 1.1 thorpej #include <net/bpf.h>
68 1.1 thorpej #endif
69 1.1 thorpej
70 1.1 thorpej #ifdef INET
71 1.1 thorpej #include <netinet/in.h>
72 1.1 thorpej #include <netinet/if_inarp.h>
73 1.1 thorpej #endif
74 1.1 thorpej
75 1.1 thorpej #ifdef NS
76 1.1 thorpej #include <netns/ns.h>
77 1.1 thorpej #include <netns/ns_if.h>
78 1.1 thorpej #endif
79 1.1 thorpej
80 1.1 thorpej #include <machine/bus.h>
81 1.1 thorpej #include <machine/intr.h>
82 1.1 thorpej
83 1.1 thorpej #include <dev/mii/miivar.h>
84 1.1 thorpej #include <dev/mii/mii_bitbang.h>
85 1.1 thorpej
86 1.1 thorpej #include <dev/ic/tulipreg.h>
87 1.1 thorpej #include <dev/ic/tulipvar.h>
88 1.1 thorpej
89 1.1 thorpej #include <dev/pci/pcivar.h>
90 1.1 thorpej #include <dev/pci/pcireg.h>
91 1.1 thorpej #include <dev/pci/pcidevs.h>
92 1.1 thorpej
93 1.1 thorpej #include <dev/cardbus/cardbusvar.h>
94 1.1 thorpej
95 1.1 thorpej /*
96 1.1 thorpej * PCI configuration space registers used by the Tulip.
97 1.1 thorpej */
98 1.1 thorpej #define TULIP_PCI_IOBA 0x10 /* i/o mapped base */
99 1.1 thorpej #define TULIP_PCI_MMBA 0x14 /* memory mapped base */
100 1.1 thorpej #define TULIP_PCI_CFDA 0x40 /* configuration driver area */
101 1.1 thorpej
102 1.1 thorpej #define CFDA_SLEEP 0x80000000 /* sleep mode */
103 1.4 thorpej #define CFDA_SNOOZE 0x40000000 /* snooze mode */
104 1.1 thorpej
105 1.1 thorpej struct tulip_cardbus_softc {
106 1.1 thorpej struct tulip_softc sc_tulip; /* real Tulip softc */
107 1.1 thorpej
108 1.1 thorpej /* CardBus-specific goo. */
109 1.1 thorpej void *sc_ih; /* interrupt handle */
110 1.1 thorpej cardbus_devfunc_t sc_ct; /* our CardBus devfuncs */
111 1.17 thorpej cardbustag_t sc_tag; /* our CardBus tag */
112 1.1 thorpej int sc_csr; /* CSR bits */
113 1.17 thorpej bus_size_t sc_mapsize; /* the size of mapped bus space
114 1.17 thorpej region */
115 1.17 thorpej /* product info */
116 1.17 thorpej const struct tulip_cardbus_product *sc_product;
117 1.18 thorpej
118 1.18 thorpej int sc_cben; /* CardBus enables */
119 1.18 thorpej int sc_bar_reg; /* which BAR to use */
120 1.18 thorpej pcireg_t sc_bar_val; /* value of the BAR */
121 1.20 thorpej
122 1.20 thorpej int sc_intrline; /* interrupt line */
123 1.1 thorpej };
124 1.1 thorpej
125 1.1 thorpej int tlp_cardbus_match __P((struct device *, struct cfdata *, void *));
126 1.1 thorpej void tlp_cardbus_attach __P((struct device *, struct device *, void *));
127 1.11 thorpej int tlp_cardbus_detach __P((struct device *, int));
128 1.1 thorpej
129 1.1 thorpej struct cfattach tlp_cardbus_ca = {
130 1.1 thorpej sizeof(struct tulip_cardbus_softc),
131 1.1 thorpej tlp_cardbus_match, tlp_cardbus_attach,
132 1.11 thorpej tlp_cardbus_detach, tlp_activate,
133 1.1 thorpej };
134 1.1 thorpej
135 1.1 thorpej const struct tulip_cardbus_product {
136 1.1 thorpej u_int32_t tcp_vendor; /* PCI vendor ID */
137 1.1 thorpej u_int32_t tcp_product; /* PCI product ID */
138 1.1 thorpej tulip_chip_t tcp_chip; /* base Tulip chip type */
139 1.1 thorpej int tcp_pmreg; /* power management register offset */
140 1.1 thorpej } tlp_cardbus_products[] = {
141 1.1 thorpej { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21142,
142 1.3 thorpej TULIP_CHIP_21142, 0xe0 },
143 1.1 thorpej
144 1.10 thorpej { PCI_VENDOR_XIRCOM, PCI_PRODUCT_XIRCOM_X3201_3_21143,
145 1.10 thorpej TULIP_CHIP_X3201_3, 0xe0 },
146 1.10 thorpej
147 1.1 thorpej { 0, 0,
148 1.1 thorpej TULIP_CHIP_INVALID, 0 },
149 1.1 thorpej };
150 1.1 thorpej
151 1.18 thorpej void tlp_cardbus_setup __P((struct tulip_cardbus_softc *));
152 1.17 thorpej
153 1.20 thorpej int tlp_cardbus_enable __P((struct tulip_softc *));
154 1.20 thorpej void tlp_cardbus_disable __P((struct tulip_softc *));
155 1.21 thorpej void tlp_cardbus_power __P((struct tulip_softc *, int));
156 1.20 thorpej
157 1.10 thorpej void tlp_cardbus_x3201_reset __P((struct tulip_softc *));
158 1.10 thorpej
159 1.1 thorpej const struct tulip_cardbus_product *tlp_cardbus_lookup
160 1.1 thorpej __P((const struct cardbus_attach_args *));
161 1.1 thorpej
162 1.1 thorpej const struct tulip_cardbus_product *
163 1.1 thorpej tlp_cardbus_lookup(ca)
164 1.1 thorpej const struct cardbus_attach_args *ca;
165 1.1 thorpej {
166 1.1 thorpej const struct tulip_cardbus_product *tcp;
167 1.1 thorpej
168 1.1 thorpej for (tcp = tlp_cardbus_products;
169 1.9 thorpej tlp_chip_names[tcp->tcp_chip] != NULL;
170 1.1 thorpej tcp++) {
171 1.1 thorpej if (PCI_VENDOR(ca->ca_id) == tcp->tcp_vendor &&
172 1.1 thorpej PCI_PRODUCT(ca->ca_id) == tcp->tcp_product)
173 1.1 thorpej return (tcp);
174 1.1 thorpej }
175 1.1 thorpej return (NULL);
176 1.1 thorpej }
177 1.1 thorpej
178 1.1 thorpej int
179 1.1 thorpej tlp_cardbus_match(parent, match, aux)
180 1.1 thorpej struct device *parent;
181 1.1 thorpej struct cfdata *match;
182 1.1 thorpej void *aux;
183 1.1 thorpej {
184 1.1 thorpej struct cardbus_attach_args *ca = aux;
185 1.1 thorpej
186 1.1 thorpej if (tlp_cardbus_lookup(ca) != NULL)
187 1.1 thorpej return (1);
188 1.1 thorpej
189 1.1 thorpej return (0);
190 1.1 thorpej }
191 1.1 thorpej
192 1.1 thorpej void
193 1.1 thorpej tlp_cardbus_attach(parent, self, aux)
194 1.1 thorpej struct device *parent, *self;
195 1.1 thorpej void *aux;
196 1.1 thorpej {
197 1.15 mycroft struct tulip_cardbus_softc *csc = (void *)self;
198 1.1 thorpej struct tulip_softc *sc = &csc->sc_tulip;
199 1.1 thorpej struct cardbus_attach_args *ca = aux;
200 1.1 thorpej cardbus_devfunc_t ct = ca->ca_ct;
201 1.1 thorpej const struct tulip_cardbus_product *tcp;
202 1.1 thorpej u_int8_t enaddr[ETHER_ADDR_LEN];
203 1.15 mycroft bus_addr_t adr;
204 1.1 thorpej
205 1.1 thorpej sc->sc_devno = ca->ca_device;
206 1.1 thorpej sc->sc_dmat = ca->ca_dmat;
207 1.1 thorpej csc->sc_ct = ct;
208 1.17 thorpej csc->sc_tag = ca->ca_tag;
209 1.1 thorpej
210 1.1 thorpej tcp = tlp_cardbus_lookup(ca);
211 1.1 thorpej if (tcp == NULL) {
212 1.1 thorpej printf("\n");
213 1.1 thorpej panic("tlp_cardbus_attach: impossible");
214 1.1 thorpej }
215 1.1 thorpej sc->sc_chip = tcp->tcp_chip;
216 1.17 thorpej csc->sc_product = tcp;
217 1.1 thorpej
218 1.1 thorpej /*
219 1.1 thorpej * By default, Tulip registers are 8 bytes long (4 bytes
220 1.1 thorpej * followed by a 4 byte pad).
221 1.1 thorpej */
222 1.1 thorpej sc->sc_regshift = 3;
223 1.1 thorpej
224 1.1 thorpej /*
225 1.20 thorpej * Power management hooks.
226 1.20 thorpej */
227 1.20 thorpej sc->sc_enable = tlp_cardbus_enable;
228 1.20 thorpej sc->sc_disable = tlp_cardbus_disable;
229 1.21 thorpej sc->sc_power = tlp_cardbus_power;
230 1.20 thorpej
231 1.20 thorpej /*
232 1.1 thorpej * Get revision info, and set some chip-specific variables.
233 1.1 thorpej */
234 1.1 thorpej sc->sc_rev = PCI_REVISION(ca->ca_class);
235 1.1 thorpej switch (sc->sc_chip) {
236 1.1 thorpej case TULIP_CHIP_21142:
237 1.1 thorpej if (sc->sc_rev >= 0x20)
238 1.1 thorpej sc->sc_chip = TULIP_CHIP_21143;
239 1.1 thorpej break;
240 1.1 thorpej
241 1.1 thorpej default:
242 1.1 thorpej /* Nothing. */
243 1.1 thorpej }
244 1.1 thorpej
245 1.1 thorpej printf(": %s Ethernet, pass %d.%d\n",
246 1.9 thorpej tlp_chip_names[sc->sc_chip],
247 1.1 thorpej (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
248 1.2 thorpej
249 1.2 thorpej /*
250 1.1 thorpej * Map the device.
251 1.1 thorpej */
252 1.1 thorpej csc->sc_csr = PCI_COMMAND_MASTER_ENABLE;
253 1.19 thorpej if (Cardbus_mapreg_map(ct, TULIP_PCI_IOBA,
254 1.19 thorpej PCI_MAPREG_TYPE_IO, 0, &sc->sc_st, &sc->sc_sh, &adr,
255 1.19 thorpej &csc->sc_mapsize) == 0) {
256 1.19 thorpej #if rbus
257 1.19 thorpej #else
258 1.19 thorpej (*ct->ct_cf->cardbus_io_open)(cc, 0, adr, adr+csc->sc_mapsize);
259 1.19 thorpej #endif
260 1.19 thorpej csc->sc_cben = CARDBUS_IO_ENABLE;
261 1.19 thorpej csc->sc_csr |= PCI_COMMAND_IO_ENABLE;
262 1.19 thorpej csc->sc_bar_reg = TULIP_PCI_IOBA;
263 1.19 thorpej csc->sc_bar_val = adr | PCI_MAPREG_TYPE_IO;
264 1.19 thorpej } else if (Cardbus_mapreg_map(ct, TULIP_PCI_MMBA,
265 1.1 thorpej PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
266 1.15 mycroft &sc->sc_st, &sc->sc_sh, &adr, &csc->sc_mapsize) == 0) {
267 1.15 mycroft #if rbus
268 1.15 mycroft #else
269 1.15 mycroft (*ct->ct_cf->cardbus_mem_open)(cc, 0, adr, adr+csc->sc_mapsize);
270 1.15 mycroft #endif
271 1.18 thorpej csc->sc_cben = CARDBUS_MEM_ENABLE;
272 1.1 thorpej csc->sc_csr |= PCI_COMMAND_MEM_ENABLE;
273 1.18 thorpej csc->sc_bar_reg = TULIP_PCI_MMBA;
274 1.18 thorpej csc->sc_bar_val = adr | PCI_MAPREG_TYPE_MEM;
275 1.1 thorpej } else {
276 1.1 thorpej printf("%s: unable to map device registers\n",
277 1.1 thorpej sc->sc_dev.dv_xname);
278 1.1 thorpej return;
279 1.1 thorpej }
280 1.1 thorpej
281 1.7 thorpej /*
282 1.18 thorpej * Bring the chip out of powersave mode and initialize the
283 1.18 thorpej * configuration registers.
284 1.7 thorpej */
285 1.18 thorpej tlp_cardbus_setup(csc);
286 1.1 thorpej
287 1.1 thorpej /*
288 1.10 thorpej * Read the contents of the Ethernet Address ROM/SROM.
289 1.1 thorpej */
290 1.10 thorpej switch (sc->sc_chip) {
291 1.10 thorpej case TULIP_CHIP_X3201_3:
292 1.10 thorpej /*
293 1.10 thorpej * No SROM on this chip.
294 1.10 thorpej */
295 1.10 thorpej break;
296 1.10 thorpej
297 1.10 thorpej default:
298 1.15 mycroft if (tlp_read_srom(sc) == 0)
299 1.15 mycroft goto cant_cope;
300 1.15 mycroft break;
301 1.1 thorpej }
302 1.1 thorpej
303 1.1 thorpej /*
304 1.1 thorpej * Deal with chip/board quirks. This includes setting up
305 1.1 thorpej * the mediasw, and extracting the Ethernet address from
306 1.1 thorpej * the rombuf.
307 1.1 thorpej */
308 1.1 thorpej switch (sc->sc_chip) {
309 1.1 thorpej case TULIP_CHIP_21142:
310 1.1 thorpej case TULIP_CHIP_21143:
311 1.1 thorpej /* Check for new format SROM. */
312 1.1 thorpej if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
313 1.1 thorpej /*
314 1.15 mycroft * Not an ISV SROM; try the old DEC Ethernet Address
315 1.15 mycroft * ROM format.
316 1.1 thorpej */
317 1.15 mycroft if (tlp_parse_old_srom(sc, enaddr) == 0)
318 1.15 mycroft goto cant_cope;
319 1.1 thorpej } else {
320 1.1 thorpej /*
321 1.1 thorpej * We start out with the 2114x ISV media switch.
322 1.1 thorpej * When we search for quirks, we may change to
323 1.1 thorpej * a different switch.
324 1.1 thorpej */
325 1.1 thorpej sc->sc_mediasw = &tlp_2114x_isv_mediasw;
326 1.1 thorpej }
327 1.1 thorpej
328 1.1 thorpej /*
329 1.1 thorpej * Bail out now if we can't deal with this board.
330 1.1 thorpej */
331 1.1 thorpej if (sc->sc_mediasw == NULL)
332 1.1 thorpej goto cant_cope;
333 1.1 thorpej break;
334 1.1 thorpej
335 1.10 thorpej case TULIP_CHIP_X3201_3:
336 1.1 thorpej /*
337 1.15 mycroft * The X3201 doesn't have an SROM. Lift the MAC address
338 1.10 thorpej * from the CIS. Also, we have a special media switch:
339 1.10 thorpej * MII-on-SIO, plus some special GPIO setup.
340 1.1 thorpej */
341 1.10 thorpej memcpy(enaddr, ca->ca_cis.funce.network.netid, sizeof(enaddr));
342 1.10 thorpej sc->sc_reset = tlp_cardbus_x3201_reset;
343 1.10 thorpej sc->sc_mediasw = &tlp_sio_mii_mediasw;
344 1.10 thorpej break;
345 1.1 thorpej
346 1.10 thorpej default:
347 1.10 thorpej cant_cope:
348 1.1 thorpej printf("%s: sorry, unable to handle your board\n",
349 1.1 thorpej sc->sc_dev.dv_xname);
350 1.1 thorpej return;
351 1.1 thorpej }
352 1.1 thorpej
353 1.20 thorpej /* Remember which interrupt line. */
354 1.20 thorpej csc->sc_intrline = ca->ca_intrline;
355 1.20 thorpej
356 1.1 thorpej /*
357 1.20 thorpej * Finish off the attach.
358 1.1 thorpej */
359 1.20 thorpej tlp_attach(sc, enaddr);
360 1.1 thorpej
361 1.1 thorpej /*
362 1.20 thorpej * Power down the socket.
363 1.1 thorpej */
364 1.20 thorpej Cardbus_function_disable(csc->sc_ct);
365 1.11 thorpej }
366 1.11 thorpej
367 1.11 thorpej int
368 1.11 thorpej tlp_cardbus_detach(self, flags)
369 1.11 thorpej struct device *self;
370 1.11 thorpej int flags;
371 1.11 thorpej {
372 1.15 mycroft struct tulip_cardbus_softc *csc = (void *)self;
373 1.11 thorpej struct tulip_softc *sc = &csc->sc_tulip;
374 1.13 augustss struct cardbus_devfunc *ct = csc->sc_ct;
375 1.11 thorpej int rv;
376 1.12 haya
377 1.13 augustss #if defined(DIAGNOSTIC)
378 1.20 thorpej if (ct == NULL)
379 1.12 haya panic("%s: data structure lacks\n", sc->sc_dev.dv_xname);
380 1.12 haya #endif
381 1.11 thorpej
382 1.20 thorpej rv = tlp_detach(sc);
383 1.20 thorpej if (rv)
384 1.20 thorpej return (rv);
385 1.15 mycroft
386 1.15 mycroft /*
387 1.15 mycroft * Unhook the interrupt handler.
388 1.15 mycroft */
389 1.20 thorpej if (csc->sc_ih != NULL)
390 1.20 thorpej cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, csc->sc_ih);
391 1.12 haya
392 1.15 mycroft /*
393 1.20 thorpej * Release bus space and close window.
394 1.15 mycroft */
395 1.22 thorpej if (csc->sc_bar_reg != 0)
396 1.22 thorpej Cardbus_mapreg_unmap(ct, csc->sc_bar_reg,
397 1.22 thorpej sc->sc_st, sc->sc_sh, csc->sc_mapsize);
398 1.12 haya
399 1.15 mycroft return (0);
400 1.20 thorpej }
401 1.20 thorpej
402 1.20 thorpej int
403 1.20 thorpej tlp_cardbus_enable(sc)
404 1.20 thorpej struct tulip_softc *sc;
405 1.20 thorpej {
406 1.20 thorpej struct tulip_cardbus_softc *csc = (void *) sc;
407 1.20 thorpej cardbus_devfunc_t ct = csc->sc_ct;
408 1.20 thorpej cardbus_chipset_tag_t cc = ct->ct_cc;
409 1.20 thorpej cardbus_function_tag_t cf = ct->ct_cf;
410 1.20 thorpej
411 1.20 thorpej /*
412 1.20 thorpej * Power on the socket.
413 1.20 thorpej */
414 1.20 thorpej Cardbus_function_enable(ct);
415 1.20 thorpej
416 1.20 thorpej /*
417 1.20 thorpej * Set up the PCI configuration registers.
418 1.20 thorpej */
419 1.20 thorpej tlp_cardbus_setup(csc);
420 1.20 thorpej
421 1.20 thorpej /*
422 1.20 thorpej * Map and establish the interrupt.
423 1.20 thorpej */
424 1.20 thorpej csc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline, IPL_NET,
425 1.20 thorpej tlp_intr, sc);
426 1.20 thorpej if (csc->sc_ih == NULL) {
427 1.20 thorpej printf("%s: unable to establish interrupt at %d\n",
428 1.20 thorpej sc->sc_dev.dv_xname, csc->sc_intrline);
429 1.20 thorpej Cardbus_function_disable(csc->sc_ct);
430 1.20 thorpej return (1);
431 1.20 thorpej }
432 1.20 thorpej printf("%s: interrupting at %d\n", sc->sc_dev.dv_xname,
433 1.20 thorpej csc->sc_intrline);
434 1.20 thorpej
435 1.20 thorpej return (0);
436 1.20 thorpej }
437 1.20 thorpej
438 1.20 thorpej void
439 1.20 thorpej tlp_cardbus_disable(sc)
440 1.20 thorpej struct tulip_softc *sc;
441 1.20 thorpej {
442 1.20 thorpej struct tulip_cardbus_softc *csc = (void *) sc;
443 1.20 thorpej cardbus_devfunc_t ct = csc->sc_ct;
444 1.20 thorpej cardbus_chipset_tag_t cc = ct->ct_cc;
445 1.20 thorpej cardbus_function_tag_t cf = ct->ct_cf;
446 1.20 thorpej
447 1.20 thorpej /* Unhook the interrupt handler. */
448 1.20 thorpej cardbus_intr_disestablish(cc, cf, csc->sc_ih);
449 1.20 thorpej csc->sc_ih = NULL;
450 1.20 thorpej
451 1.20 thorpej /* Power down the socket. */
452 1.20 thorpej Cardbus_function_disable(ct);
453 1.21 thorpej }
454 1.21 thorpej
455 1.21 thorpej void
456 1.21 thorpej tlp_cardbus_power(sc, why)
457 1.21 thorpej struct tulip_softc *sc;
458 1.21 thorpej int why;
459 1.21 thorpej {
460 1.21 thorpej struct tulip_cardbus_softc *csc = (void *) sc;
461 1.21 thorpej
462 1.21 thorpej if (why == PWR_RESUME) {
463 1.21 thorpej /*
464 1.21 thorpej * Give the PCI configuration registers a kick
465 1.21 thorpej * in the head.
466 1.21 thorpej */
467 1.21 thorpej #ifdef DIAGNOSTIC
468 1.21 thorpej if (TULIP_IS_ENABLED(sc) == 0)
469 1.21 thorpej panic("tlp_cardbus_power");
470 1.21 thorpej #endif
471 1.21 thorpej tlp_cardbus_setup(csc);
472 1.21 thorpej }
473 1.17 thorpej }
474 1.17 thorpej
475 1.17 thorpej void
476 1.18 thorpej tlp_cardbus_setup(csc)
477 1.17 thorpej struct tulip_cardbus_softc *csc;
478 1.17 thorpej {
479 1.17 thorpej struct tulip_softc *sc = &csc->sc_tulip;
480 1.17 thorpej const struct tulip_cardbus_product *tcp = csc->sc_product;
481 1.17 thorpej cardbus_devfunc_t ct = csc->sc_ct;
482 1.17 thorpej cardbus_chipset_tag_t cc = ct->ct_cc;
483 1.17 thorpej cardbus_function_tag_t cf = ct->ct_cf;
484 1.17 thorpej pcireg_t reg;
485 1.17 thorpej
486 1.17 thorpej /*
487 1.17 thorpej * Check to see if the device is in power-save mode, and
488 1.17 thorpej * bring it out if necessary.
489 1.17 thorpej */
490 1.17 thorpej switch (sc->sc_chip) {
491 1.17 thorpej case TULIP_CHIP_21142:
492 1.17 thorpej case TULIP_CHIP_21143:
493 1.17 thorpej case TULIP_CHIP_X3201_3:
494 1.17 thorpej /*
495 1.17 thorpej * Clear the "sleep mode" bit in the CFDA register.
496 1.17 thorpej */
497 1.17 thorpej reg = cardbus_conf_read(cc, cf, csc->sc_tag, TULIP_PCI_CFDA);
498 1.17 thorpej if (reg & (CFDA_SLEEP|CFDA_SNOOZE))
499 1.17 thorpej cardbus_conf_write(cc, cf, csc->sc_tag, TULIP_PCI_CFDA,
500 1.17 thorpej reg & ~(CFDA_SLEEP|CFDA_SNOOZE));
501 1.17 thorpej break;
502 1.17 thorpej
503 1.17 thorpej default:
504 1.17 thorpej /* Nothing. */
505 1.17 thorpej }
506 1.17 thorpej
507 1.17 thorpej if (cardbus_get_capability(cc, cf, csc->sc_tag,
508 1.17 thorpej PCI_CAP_PWRMGMT, 0, 0)) {
509 1.17 thorpej if (tcp->tcp_pmreg == 0) {
510 1.17 thorpej printf("%s: don't know location of PMCSR for this "
511 1.17 thorpej "chip\n", sc->sc_dev.dv_xname);
512 1.17 thorpej return;
513 1.17 thorpej }
514 1.17 thorpej reg = cardbus_conf_read(cc, cf, csc->sc_tag,
515 1.17 thorpej tcp->tcp_pmreg) & 0x03;
516 1.17 thorpej #if 1 /* XXX Probably not right for CardBus. */
517 1.17 thorpej if (reg == 3) {
518 1.17 thorpej /*
519 1.17 thorpej * The card has lost all configuration data in
520 1.17 thorpej * this state, so punt.
521 1.17 thorpej */
522 1.17 thorpej printf("%s: unable to wake up from power state D3\n",
523 1.17 thorpej sc->sc_dev.dv_xname);
524 1.17 thorpej return;
525 1.17 thorpej }
526 1.17 thorpej #endif
527 1.17 thorpej if (reg != 0) {
528 1.17 thorpej printf("%s: waking up from power state D%d\n",
529 1.17 thorpej sc->sc_dev.dv_xname, reg);
530 1.17 thorpej cardbus_conf_write(cc, cf, csc->sc_tag,
531 1.17 thorpej tcp->tcp_pmreg, 0);
532 1.17 thorpej }
533 1.18 thorpej }
534 1.18 thorpej
535 1.18 thorpej /* Make sure the right access type is on the CardBus bridge. */
536 1.18 thorpej (*ct->ct_cf->cardbus_ctrl)(cc, csc->sc_cben);
537 1.18 thorpej (*ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
538 1.18 thorpej
539 1.18 thorpej /* Program the BAR. */
540 1.18 thorpej cardbus_conf_write(cc, cf, csc->sc_tag, csc->sc_bar_reg,
541 1.18 thorpej csc->sc_bar_val);
542 1.18 thorpej
543 1.18 thorpej /* Enable the appropriate bits in the PCI CSR. */
544 1.18 thorpej reg = cardbus_conf_read(cc, cf, csc->sc_tag, PCI_COMMAND_STATUS_REG);
545 1.18 thorpej reg &= ~(PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE);
546 1.18 thorpej reg |= csc->sc_csr;
547 1.18 thorpej cardbus_conf_write(cc, cf, csc->sc_tag, PCI_COMMAND_STATUS_REG, reg);
548 1.18 thorpej
549 1.18 thorpej /*
550 1.18 thorpej * Make sure the latency timer is set to some reasonable
551 1.18 thorpej * value.
552 1.18 thorpej */
553 1.18 thorpej reg = cardbus_conf_read(cc, cf, csc->sc_tag, PCI_BHLC_REG);
554 1.18 thorpej if (PCI_LATTIMER(reg) < 0x20) {
555 1.18 thorpej reg &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
556 1.18 thorpej reg |= (0x20 << PCI_LATTIMER_SHIFT);
557 1.18 thorpej cardbus_conf_write(cc, cf, csc->sc_tag, PCI_BHLC_REG, reg);
558 1.17 thorpej }
559 1.10 thorpej }
560 1.10 thorpej
561 1.10 thorpej void
562 1.10 thorpej tlp_cardbus_x3201_reset(sc)
563 1.10 thorpej struct tulip_softc *sc;
564 1.10 thorpej {
565 1.10 thorpej u_int32_t reg;
566 1.10 thorpej
567 1.10 thorpej reg = TULIP_READ(sc, CSR_SIAGEN);
568 1.10 thorpej
569 1.10 thorpej /* make GP[2,0] outputs */
570 1.10 thorpej TULIP_WRITE(sc, CSR_SIAGEN, (reg & ~SIAGEN_MD) | SIAGEN_CWE |
571 1.10 thorpej 0x00050000);
572 1.10 thorpej TULIP_WRITE(sc, CSR_SIAGEN, (reg & ~SIAGEN_CWE) | SIAGEN_MD);
573 1.1 thorpej }
574