if_tlp_cardbus.c revision 1.48.4.1 1 1.48.4.1 rpaulo /* $NetBSD: if_tlp_cardbus.c,v 1.48.4.1 2006/09/09 02:49:44 rpaulo 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.31 lukem
45 1.31 lukem #include <sys/cdefs.h>
46 1.48.4.1 rpaulo __KERNEL_RCSID(0, "$NetBSD: if_tlp_cardbus.c,v 1.48.4.1 2006/09/09 02:49:44 rpaulo Exp $");
47 1.1 thorpej
48 1.1 thorpej #include "opt_inet.h"
49 1.1 thorpej #include "bpfilter.h"
50 1.1 thorpej
51 1.1 thorpej #include <sys/param.h>
52 1.45 perry #include <sys/systm.h>
53 1.45 perry #include <sys/mbuf.h>
54 1.1 thorpej #include <sys/malloc.h>
55 1.1 thorpej #include <sys/kernel.h>
56 1.1 thorpej #include <sys/socket.h>
57 1.1 thorpej #include <sys/ioctl.h>
58 1.1 thorpej #include <sys/errno.h>
59 1.1 thorpej #include <sys/device.h>
60 1.5 thorpej
61 1.5 thorpej #include <machine/endian.h>
62 1.45 perry
63 1.1 thorpej #include <net/if.h>
64 1.1 thorpej #include <net/if_dl.h>
65 1.1 thorpej #include <net/if_media.h>
66 1.1 thorpej #include <net/if_ether.h>
67 1.1 thorpej
68 1.45 perry #if NBPFILTER > 0
69 1.1 thorpej #include <net/bpf.h>
70 1.45 perry #endif
71 1.1 thorpej
72 1.1 thorpej #ifdef INET
73 1.45 perry #include <netinet/in.h>
74 1.1 thorpej #include <netinet/if_inarp.h>
75 1.1 thorpej #endif
76 1.1 thorpej
77 1.1 thorpej
78 1.1 thorpej #include <machine/bus.h>
79 1.1 thorpej #include <machine/intr.h>
80 1.1 thorpej
81 1.1 thorpej #include <dev/mii/miivar.h>
82 1.1 thorpej #include <dev/mii/mii_bitbang.h>
83 1.1 thorpej
84 1.1 thorpej #include <dev/ic/tulipreg.h>
85 1.1 thorpej #include <dev/ic/tulipvar.h>
86 1.1 thorpej
87 1.1 thorpej #include <dev/pci/pcivar.h>
88 1.1 thorpej #include <dev/pci/pcireg.h>
89 1.1 thorpej #include <dev/pci/pcidevs.h>
90 1.1 thorpej
91 1.1 thorpej #include <dev/cardbus/cardbusvar.h>
92 1.43 mycroft #include <dev/pci/pcidevs.h>
93 1.1 thorpej
94 1.1 thorpej /*
95 1.1 thorpej * PCI configuration space registers used by the Tulip.
96 1.1 thorpej */
97 1.1 thorpej #define TULIP_PCI_IOBA 0x10 /* i/o mapped base */
98 1.1 thorpej #define TULIP_PCI_MMBA 0x14 /* memory mapped base */
99 1.1 thorpej #define TULIP_PCI_CFDA 0x40 /* configuration driver area */
100 1.1 thorpej
101 1.1 thorpej #define CFDA_SLEEP 0x80000000 /* sleep mode */
102 1.4 thorpej #define CFDA_SNOOZE 0x40000000 /* snooze mode */
103 1.1 thorpej
104 1.1 thorpej struct tulip_cardbus_softc {
105 1.1 thorpej struct tulip_softc sc_tulip; /* real Tulip softc */
106 1.1 thorpej
107 1.1 thorpej /* CardBus-specific goo. */
108 1.1 thorpej void *sc_ih; /* interrupt handle */
109 1.1 thorpej cardbus_devfunc_t sc_ct; /* our CardBus devfuncs */
110 1.17 thorpej cardbustag_t sc_tag; /* our CardBus tag */
111 1.1 thorpej int sc_csr; /* CSR bits */
112 1.17 thorpej bus_size_t sc_mapsize; /* the size of mapped bus space
113 1.17 thorpej region */
114 1.18 thorpej
115 1.18 thorpej int sc_cben; /* CardBus enables */
116 1.18 thorpej int sc_bar_reg; /* which BAR to use */
117 1.18 thorpej pcireg_t sc_bar_val; /* value of the BAR */
118 1.20 thorpej
119 1.20 thorpej int sc_intrline; /* interrupt line */
120 1.1 thorpej };
121 1.1 thorpej
122 1.44 perry int tlp_cardbus_match(struct device *, struct cfdata *, void *);
123 1.44 perry void tlp_cardbus_attach(struct device *, struct device *, void *);
124 1.44 perry int tlp_cardbus_detach(struct device *, int);
125 1.1 thorpej
126 1.36 thorpej CFATTACH_DECL(tlp_cardbus, sizeof(struct tulip_cardbus_softc),
127 1.37 thorpej tlp_cardbus_match, tlp_cardbus_attach, tlp_cardbus_detach, tlp_activate);
128 1.1 thorpej
129 1.1 thorpej const struct tulip_cardbus_product {
130 1.1 thorpej u_int32_t tcp_vendor; /* PCI vendor ID */
131 1.1 thorpej u_int32_t tcp_product; /* PCI product ID */
132 1.1 thorpej tulip_chip_t tcp_chip; /* base Tulip chip type */
133 1.1 thorpej } tlp_cardbus_products[] = {
134 1.43 mycroft { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21142,
135 1.23 thorpej TULIP_CHIP_21142 },
136 1.1 thorpej
137 1.43 mycroft { PCI_VENDOR_XIRCOM, PCI_PRODUCT_XIRCOM_X3201_3_21143,
138 1.23 thorpej TULIP_CHIP_X3201_3 },
139 1.27 kanaoka
140 1.48.4.1 rpaulo { PCI_VENDOR_ADMTEK, PCI_PRODUCT_ADMTEK_AN983,
141 1.43 mycroft TULIP_CHIP_AN985 },
142 1.43 mycroft
143 1.43 mycroft { PCI_VENDOR_ACCTON, PCI_PRODUCT_ACCTON_EN2242,
144 1.27 kanaoka TULIP_CHIP_AN985 },
145 1.10 thorpej
146 1.43 mycroft { PCI_VENDOR_ABOCOM, PCI_PRODUCT_ABOCOM_FE2500,
147 1.25 thorpej TULIP_CHIP_AN985 },
148 1.25 thorpej
149 1.43 mycroft { PCI_VENDOR_ABOCOM, PCI_PRODUCT_ABOCOM_PCM200,
150 1.26 christos TULIP_CHIP_AN985 },
151 1.26 christos
152 1.43 mycroft { PCI_VENDOR_ABOCOM, PCI_PRODUCT_ABOCOM_FE2500MX,
153 1.38 onoe TULIP_CHIP_AN985 },
154 1.38 onoe
155 1.43 mycroft { PCI_VENDOR_HAWKING, PCI_PRODUCT_HAWKING_PN672TX,
156 1.32 augustss TULIP_CHIP_AN985 },
157 1.32 augustss
158 1.48.4.1 rpaulo { PCI_VENDOR_ADMTEK, PCI_PRODUCT_ADMTEK_AN985,
159 1.39 mycroft TULIP_CHIP_AN985 },
160 1.39 mycroft
161 1.43 mycroft { PCI_VENDOR_MICROSOFT, PCI_PRODUCT_MICROSOFT_MN120,
162 1.25 thorpej TULIP_CHIP_AN985 },
163 1.25 thorpej
164 1.46 tron { PCI_VENDOR_LINKSYS, PCI_PRODUCT_LINKSYS_PCMPC200,
165 1.46 tron TULIP_CHIP_AN985 },
166 1.46 tron
167 1.1 thorpej { 0, 0,
168 1.23 thorpej TULIP_CHIP_INVALID },
169 1.1 thorpej };
170 1.1 thorpej
171 1.33 mycroft struct tlp_cardbus_quirks {
172 1.44 perry void (*tpq_func)(struct tulip_cardbus_softc *,
173 1.44 perry const u_int8_t *);
174 1.33 mycroft u_int8_t tpq_oui[3];
175 1.33 mycroft };
176 1.33 mycroft
177 1.44 perry void tlp_cardbus_lxt_quirks(struct tulip_cardbus_softc *,
178 1.44 perry const u_int8_t *);
179 1.33 mycroft
180 1.33 mycroft const struct tlp_cardbus_quirks tlp_cardbus_21142_quirks[] = {
181 1.33 mycroft { tlp_cardbus_lxt_quirks, { 0x00, 0x40, 0x05 } },
182 1.33 mycroft { NULL, { 0, 0, 0 } }
183 1.33 mycroft };
184 1.33 mycroft
185 1.44 perry void tlp_cardbus_setup(struct tulip_cardbus_softc *);
186 1.17 thorpej
187 1.44 perry int tlp_cardbus_enable(struct tulip_softc *);
188 1.44 perry void tlp_cardbus_disable(struct tulip_softc *);
189 1.44 perry void tlp_cardbus_power(struct tulip_softc *, int);
190 1.20 thorpej
191 1.44 perry void tlp_cardbus_x3201_reset(struct tulip_softc *);
192 1.10 thorpej
193 1.1 thorpej const struct tulip_cardbus_product *tlp_cardbus_lookup
194 1.44 perry (const struct cardbus_attach_args *);
195 1.44 perry void tlp_cardbus_get_quirks(struct tulip_cardbus_softc *,
196 1.44 perry const u_int8_t *, const struct tlp_cardbus_quirks *);
197 1.1 thorpej
198 1.1 thorpej const struct tulip_cardbus_product *
199 1.1 thorpej tlp_cardbus_lookup(ca)
200 1.1 thorpej const struct cardbus_attach_args *ca;
201 1.1 thorpej {
202 1.1 thorpej const struct tulip_cardbus_product *tcp;
203 1.1 thorpej
204 1.1 thorpej for (tcp = tlp_cardbus_products;
205 1.9 thorpej tlp_chip_names[tcp->tcp_chip] != NULL;
206 1.1 thorpej tcp++) {
207 1.1 thorpej if (PCI_VENDOR(ca->ca_id) == tcp->tcp_vendor &&
208 1.1 thorpej PCI_PRODUCT(ca->ca_id) == tcp->tcp_product)
209 1.1 thorpej return (tcp);
210 1.1 thorpej }
211 1.1 thorpej return (NULL);
212 1.1 thorpej }
213 1.1 thorpej
214 1.33 mycroft void
215 1.33 mycroft tlp_cardbus_get_quirks(csc, enaddr, tpq)
216 1.33 mycroft struct tulip_cardbus_softc *csc;
217 1.33 mycroft const u_int8_t *enaddr;
218 1.33 mycroft const struct tlp_cardbus_quirks *tpq;
219 1.33 mycroft {
220 1.33 mycroft
221 1.33 mycroft for (; tpq->tpq_func != NULL; tpq++) {
222 1.33 mycroft if (tpq->tpq_oui[0] == enaddr[0] &&
223 1.33 mycroft tpq->tpq_oui[1] == enaddr[1] &&
224 1.33 mycroft tpq->tpq_oui[2] == enaddr[2]) {
225 1.33 mycroft (*tpq->tpq_func)(csc, enaddr);
226 1.33 mycroft return;
227 1.33 mycroft }
228 1.33 mycroft }
229 1.33 mycroft }
230 1.33 mycroft
231 1.1 thorpej int
232 1.1 thorpej tlp_cardbus_match(parent, match, aux)
233 1.1 thorpej struct device *parent;
234 1.1 thorpej struct cfdata *match;
235 1.1 thorpej void *aux;
236 1.1 thorpej {
237 1.1 thorpej struct cardbus_attach_args *ca = aux;
238 1.1 thorpej
239 1.1 thorpej if (tlp_cardbus_lookup(ca) != NULL)
240 1.1 thorpej return (1);
241 1.1 thorpej
242 1.1 thorpej return (0);
243 1.1 thorpej }
244 1.1 thorpej
245 1.1 thorpej void
246 1.1 thorpej tlp_cardbus_attach(parent, self, aux)
247 1.1 thorpej struct device *parent, *self;
248 1.1 thorpej void *aux;
249 1.1 thorpej {
250 1.48.4.1 rpaulo struct tulip_cardbus_softc *csc = device_private(self);
251 1.1 thorpej struct tulip_softc *sc = &csc->sc_tulip;
252 1.1 thorpej struct cardbus_attach_args *ca = aux;
253 1.1 thorpej cardbus_devfunc_t ct = ca->ca_ct;
254 1.1 thorpej const struct tulip_cardbus_product *tcp;
255 1.1 thorpej u_int8_t enaddr[ETHER_ADDR_LEN];
256 1.15 mycroft bus_addr_t adr;
257 1.25 thorpej pcireg_t reg;
258 1.1 thorpej
259 1.47 drochner sc->sc_devno = 0;
260 1.1 thorpej sc->sc_dmat = ca->ca_dmat;
261 1.1 thorpej csc->sc_ct = ct;
262 1.17 thorpej csc->sc_tag = ca->ca_tag;
263 1.1 thorpej
264 1.1 thorpej tcp = tlp_cardbus_lookup(ca);
265 1.1 thorpej if (tcp == NULL) {
266 1.1 thorpej printf("\n");
267 1.1 thorpej panic("tlp_cardbus_attach: impossible");
268 1.1 thorpej }
269 1.1 thorpej sc->sc_chip = tcp->tcp_chip;
270 1.1 thorpej
271 1.1 thorpej /*
272 1.1 thorpej * By default, Tulip registers are 8 bytes long (4 bytes
273 1.1 thorpej * followed by a 4 byte pad).
274 1.1 thorpej */
275 1.1 thorpej sc->sc_regshift = 3;
276 1.1 thorpej
277 1.1 thorpej /*
278 1.20 thorpej * Power management hooks.
279 1.20 thorpej */
280 1.20 thorpej sc->sc_enable = tlp_cardbus_enable;
281 1.20 thorpej sc->sc_disable = tlp_cardbus_disable;
282 1.21 thorpej sc->sc_power = tlp_cardbus_power;
283 1.20 thorpej
284 1.20 thorpej /*
285 1.1 thorpej * Get revision info, and set some chip-specific variables.
286 1.1 thorpej */
287 1.1 thorpej sc->sc_rev = PCI_REVISION(ca->ca_class);
288 1.1 thorpej switch (sc->sc_chip) {
289 1.1 thorpej case TULIP_CHIP_21142:
290 1.1 thorpej if (sc->sc_rev >= 0x20)
291 1.1 thorpej sc->sc_chip = TULIP_CHIP_21143;
292 1.1 thorpej break;
293 1.1 thorpej
294 1.25 thorpej case TULIP_CHIP_AN985:
295 1.25 thorpej /*
296 1.25 thorpej * The AN983 and AN985 are very similar, and are
297 1.25 thorpej * differentiated by a "signature" register that
298 1.25 thorpej * is like, but not identical, to a PCI ID register.
299 1.25 thorpej */
300 1.25 thorpej reg = cardbus_conf_read(ct->ct_cc, ct->ct_cf, csc->sc_tag,
301 1.25 thorpej 0x80);
302 1.25 thorpej switch (reg) {
303 1.25 thorpej case 0x09811317:
304 1.25 thorpej sc->sc_chip = TULIP_CHIP_AN985;
305 1.25 thorpej break;
306 1.25 thorpej
307 1.25 thorpej case 0x09851317:
308 1.25 thorpej sc->sc_chip = TULIP_CHIP_AN983;
309 1.25 thorpej break;
310 1.25 thorpej
311 1.25 thorpej }
312 1.25 thorpej break;
313 1.25 thorpej
314 1.29 onoe default:
315 1.29 onoe /* Nothing. -- to make gcc happy */
316 1.30 thorpej break;
317 1.1 thorpej }
318 1.1 thorpej
319 1.1 thorpej printf(": %s Ethernet, pass %d.%d\n",
320 1.9 thorpej tlp_chip_names[sc->sc_chip],
321 1.1 thorpej (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
322 1.2 thorpej
323 1.2 thorpej /*
324 1.1 thorpej * Map the device.
325 1.1 thorpej */
326 1.33 mycroft csc->sc_csr = CARDBUS_COMMAND_MASTER_ENABLE;
327 1.33 mycroft if (Cardbus_mapreg_map(ct, TULIP_PCI_MMBA,
328 1.33 mycroft CARDBUS_MAPREG_TYPE_MEM, 0, &sc->sc_st, &sc->sc_sh, &adr,
329 1.33 mycroft &csc->sc_mapsize) == 0) {
330 1.33 mycroft #if rbus
331 1.33 mycroft #else
332 1.33 mycroft (*ct->ct_cf->cardbus_mem_open)(cc, 0, adr, adr+csc->sc_mapsize);
333 1.33 mycroft #endif
334 1.33 mycroft csc->sc_cben = CARDBUS_MEM_ENABLE;
335 1.33 mycroft csc->sc_csr |= CARDBUS_COMMAND_MEM_ENABLE;
336 1.33 mycroft csc->sc_bar_reg = TULIP_PCI_MMBA;
337 1.33 mycroft csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_MEM;
338 1.33 mycroft } else if (Cardbus_mapreg_map(ct, TULIP_PCI_IOBA,
339 1.33 mycroft CARDBUS_MAPREG_TYPE_IO, 0, &sc->sc_st, &sc->sc_sh, &adr,
340 1.19 thorpej &csc->sc_mapsize) == 0) {
341 1.19 thorpej #if rbus
342 1.19 thorpej #else
343 1.19 thorpej (*ct->ct_cf->cardbus_io_open)(cc, 0, adr, adr+csc->sc_mapsize);
344 1.19 thorpej #endif
345 1.19 thorpej csc->sc_cben = CARDBUS_IO_ENABLE;
346 1.33 mycroft csc->sc_csr |= CARDBUS_COMMAND_IO_ENABLE;
347 1.19 thorpej csc->sc_bar_reg = TULIP_PCI_IOBA;
348 1.33 mycroft csc->sc_bar_val = adr | CARDBUS_MAPREG_TYPE_IO;
349 1.1 thorpej } else {
350 1.1 thorpej printf("%s: unable to map device registers\n",
351 1.1 thorpej sc->sc_dev.dv_xname);
352 1.1 thorpej return;
353 1.1 thorpej }
354 1.1 thorpej
355 1.7 thorpej /*
356 1.18 thorpej * Bring the chip out of powersave mode and initialize the
357 1.18 thorpej * configuration registers.
358 1.7 thorpej */
359 1.18 thorpej tlp_cardbus_setup(csc);
360 1.1 thorpej
361 1.1 thorpej /*
362 1.10 thorpej * Read the contents of the Ethernet Address ROM/SROM.
363 1.1 thorpej */
364 1.10 thorpej switch (sc->sc_chip) {
365 1.10 thorpej case TULIP_CHIP_X3201_3:
366 1.10 thorpej /*
367 1.10 thorpej * No SROM on this chip.
368 1.10 thorpej */
369 1.10 thorpej break;
370 1.10 thorpej
371 1.10 thorpej default:
372 1.15 mycroft if (tlp_read_srom(sc) == 0)
373 1.15 mycroft goto cant_cope;
374 1.15 mycroft break;
375 1.1 thorpej }
376 1.1 thorpej
377 1.1 thorpej /*
378 1.1 thorpej * Deal with chip/board quirks. This includes setting up
379 1.1 thorpej * the mediasw, and extracting the Ethernet address from
380 1.1 thorpej * the rombuf.
381 1.1 thorpej */
382 1.1 thorpej switch (sc->sc_chip) {
383 1.1 thorpej case TULIP_CHIP_21142:
384 1.1 thorpej case TULIP_CHIP_21143:
385 1.1 thorpej /* Check for new format SROM. */
386 1.24 thorpej if (tlp_isv_srom_enaddr(sc, enaddr) != 0) {
387 1.1 thorpej /*
388 1.1 thorpej * We start out with the 2114x ISV media switch.
389 1.1 thorpej * When we search for quirks, we may change to
390 1.1 thorpej * a different switch.
391 1.1 thorpej */
392 1.1 thorpej sc->sc_mediasw = &tlp_2114x_isv_mediasw;
393 1.24 thorpej } else if (tlp_parse_old_srom(sc, enaddr) == 0) {
394 1.23 thorpej /*
395 1.24 thorpej * Not an ISV SROM, and not in old DEC Address
396 1.24 thorpej * ROM format. Try to snarf it out of the CIS.
397 1.23 thorpej */
398 1.23 thorpej if (ca->ca_cis.funce.network.netid_present == 0)
399 1.23 thorpej goto cant_cope;
400 1.23 thorpej
401 1.23 thorpej /* Grab the MAC address from the CIS. */
402 1.23 thorpej memcpy(enaddr, ca->ca_cis.funce.network.netid,
403 1.23 thorpej sizeof(enaddr));
404 1.24 thorpej }
405 1.23 thorpej
406 1.33 mycroft /*
407 1.33 mycroft * Deal with any quirks this board might have.
408 1.33 mycroft */
409 1.33 mycroft tlp_cardbus_get_quirks(csc, enaddr, tlp_cardbus_21142_quirks);
410 1.24 thorpej
411 1.24 thorpej /*
412 1.24 thorpej * If we don't already have a media switch, default to
413 1.24 thorpej * MII-over-SIO, with no special reset routine.
414 1.24 thorpej */
415 1.24 thorpej if (sc->sc_mediasw == NULL) {
416 1.24 thorpej printf("%s: defaulting to MII-over-SIO; no bets...\n",
417 1.24 thorpej sc->sc_dev.dv_xname);
418 1.23 thorpej sc->sc_mediasw = &tlp_sio_mii_mediasw;
419 1.23 thorpej }
420 1.25 thorpej break;
421 1.25 thorpej
422 1.25 thorpej case TULIP_CHIP_AN983:
423 1.25 thorpej case TULIP_CHIP_AN985:
424 1.25 thorpej /*
425 1.25 thorpej * The ADMtek AN985's Ethernet address is located
426 1.25 thorpej * at offset 8 of its EEPROM.
427 1.25 thorpej */
428 1.25 thorpej memcpy(enaddr, &sc->sc_srom[8], ETHER_ADDR_LEN);
429 1.25 thorpej
430 1.25 thorpej /*
431 1.25 thorpej * The ADMtek AN985 can be configured in Single-Chip
432 1.25 thorpej * mode or MAC-only mode. Single-Chip uses the built-in
433 1.25 thorpej * PHY, MAC-only has an external PHY (usually HomePNA).
434 1.25 thorpej * The selection is based on an EEPROM setting, and both
435 1.25 thorpej * PHYs are access via MII attached to SIO.
436 1.25 thorpej *
437 1.25 thorpej * The AN985 "ghosts" the internal PHY onto all
438 1.25 thorpej * MII addresses, so we have to use a media init
439 1.25 thorpej * routine that limits the search.
440 1.25 thorpej * XXX How does this work with MAC-only mode?
441 1.25 thorpej */
442 1.25 thorpej sc->sc_mediasw = &tlp_an985_mediasw;
443 1.1 thorpej break;
444 1.1 thorpej
445 1.10 thorpej case TULIP_CHIP_X3201_3:
446 1.1 thorpej /*
447 1.15 mycroft * The X3201 doesn't have an SROM. Lift the MAC address
448 1.10 thorpej * from the CIS. Also, we have a special media switch:
449 1.10 thorpej * MII-on-SIO, plus some special GPIO setup.
450 1.1 thorpej */
451 1.10 thorpej memcpy(enaddr, ca->ca_cis.funce.network.netid, sizeof(enaddr));
452 1.10 thorpej sc->sc_reset = tlp_cardbus_x3201_reset;
453 1.10 thorpej sc->sc_mediasw = &tlp_sio_mii_mediasw;
454 1.10 thorpej break;
455 1.1 thorpej
456 1.10 thorpej default:
457 1.10 thorpej cant_cope:
458 1.1 thorpej printf("%s: sorry, unable to handle your board\n",
459 1.1 thorpej sc->sc_dev.dv_xname);
460 1.1 thorpej return;
461 1.1 thorpej }
462 1.1 thorpej
463 1.20 thorpej /* Remember which interrupt line. */
464 1.20 thorpej csc->sc_intrline = ca->ca_intrline;
465 1.20 thorpej
466 1.1 thorpej /*
467 1.23 thorpej * The CardBus cards will make it to store-and-forward mode as
468 1.23 thorpej * soon as you put them under any kind of load, so just start
469 1.23 thorpej * out there.
470 1.23 thorpej */
471 1.23 thorpej sc->sc_txthresh = TXTH_SF;
472 1.23 thorpej
473 1.23 thorpej /*
474 1.20 thorpej * Finish off the attach.
475 1.1 thorpej */
476 1.20 thorpej tlp_attach(sc, enaddr);
477 1.1 thorpej
478 1.1 thorpej /*
479 1.20 thorpej * Power down the socket.
480 1.1 thorpej */
481 1.20 thorpej Cardbus_function_disable(csc->sc_ct);
482 1.11 thorpej }
483 1.11 thorpej
484 1.11 thorpej int
485 1.11 thorpej tlp_cardbus_detach(self, flags)
486 1.11 thorpej struct device *self;
487 1.11 thorpej int flags;
488 1.11 thorpej {
489 1.48.4.1 rpaulo struct tulip_cardbus_softc *csc = device_private(self);
490 1.11 thorpej struct tulip_softc *sc = &csc->sc_tulip;
491 1.13 augustss struct cardbus_devfunc *ct = csc->sc_ct;
492 1.11 thorpej int rv;
493 1.12 haya
494 1.13 augustss #if defined(DIAGNOSTIC)
495 1.20 thorpej if (ct == NULL)
496 1.34 provos panic("%s: data structure lacks", sc->sc_dev.dv_xname);
497 1.12 haya #endif
498 1.11 thorpej
499 1.20 thorpej rv = tlp_detach(sc);
500 1.20 thorpej if (rv)
501 1.20 thorpej return (rv);
502 1.15 mycroft
503 1.15 mycroft /*
504 1.15 mycroft * Unhook the interrupt handler.
505 1.15 mycroft */
506 1.20 thorpej if (csc->sc_ih != NULL)
507 1.20 thorpej cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, csc->sc_ih);
508 1.12 haya
509 1.15 mycroft /*
510 1.20 thorpej * Release bus space and close window.
511 1.15 mycroft */
512 1.22 thorpej if (csc->sc_bar_reg != 0)
513 1.22 thorpej Cardbus_mapreg_unmap(ct, csc->sc_bar_reg,
514 1.22 thorpej sc->sc_st, sc->sc_sh, csc->sc_mapsize);
515 1.12 haya
516 1.15 mycroft return (0);
517 1.20 thorpej }
518 1.20 thorpej
519 1.20 thorpej int
520 1.20 thorpej tlp_cardbus_enable(sc)
521 1.20 thorpej struct tulip_softc *sc;
522 1.20 thorpej {
523 1.20 thorpej struct tulip_cardbus_softc *csc = (void *) sc;
524 1.20 thorpej cardbus_devfunc_t ct = csc->sc_ct;
525 1.20 thorpej cardbus_chipset_tag_t cc = ct->ct_cc;
526 1.20 thorpej cardbus_function_tag_t cf = ct->ct_cf;
527 1.20 thorpej
528 1.20 thorpej /*
529 1.20 thorpej * Power on the socket.
530 1.20 thorpej */
531 1.20 thorpej Cardbus_function_enable(ct);
532 1.20 thorpej
533 1.20 thorpej /*
534 1.20 thorpej * Set up the PCI configuration registers.
535 1.20 thorpej */
536 1.20 thorpej tlp_cardbus_setup(csc);
537 1.20 thorpej
538 1.20 thorpej /*
539 1.20 thorpej * Map and establish the interrupt.
540 1.20 thorpej */
541 1.20 thorpej csc->sc_ih = cardbus_intr_establish(cc, cf, csc->sc_intrline, IPL_NET,
542 1.20 thorpej tlp_intr, sc);
543 1.20 thorpej if (csc->sc_ih == NULL) {
544 1.20 thorpej printf("%s: unable to establish interrupt at %d\n",
545 1.20 thorpej sc->sc_dev.dv_xname, csc->sc_intrline);
546 1.20 thorpej Cardbus_function_disable(csc->sc_ct);
547 1.20 thorpej return (1);
548 1.20 thorpej }
549 1.20 thorpej printf("%s: interrupting at %d\n", sc->sc_dev.dv_xname,
550 1.20 thorpej csc->sc_intrline);
551 1.20 thorpej
552 1.20 thorpej return (0);
553 1.20 thorpej }
554 1.20 thorpej
555 1.20 thorpej void
556 1.20 thorpej tlp_cardbus_disable(sc)
557 1.20 thorpej struct tulip_softc *sc;
558 1.20 thorpej {
559 1.20 thorpej struct tulip_cardbus_softc *csc = (void *) sc;
560 1.20 thorpej cardbus_devfunc_t ct = csc->sc_ct;
561 1.20 thorpej cardbus_chipset_tag_t cc = ct->ct_cc;
562 1.20 thorpej cardbus_function_tag_t cf = ct->ct_cf;
563 1.20 thorpej
564 1.20 thorpej /* Unhook the interrupt handler. */
565 1.20 thorpej cardbus_intr_disestablish(cc, cf, csc->sc_ih);
566 1.20 thorpej csc->sc_ih = NULL;
567 1.20 thorpej
568 1.20 thorpej /* Power down the socket. */
569 1.20 thorpej Cardbus_function_disable(ct);
570 1.21 thorpej }
571 1.21 thorpej
572 1.21 thorpej void
573 1.21 thorpej tlp_cardbus_power(sc, why)
574 1.21 thorpej struct tulip_softc *sc;
575 1.21 thorpej int why;
576 1.21 thorpej {
577 1.21 thorpej
578 1.43 mycroft switch (why) {
579 1.43 mycroft case PWR_RESUME:
580 1.43 mycroft tlp_cardbus_enable(sc);
581 1.43 mycroft break;
582 1.43 mycroft case PWR_SUSPEND:
583 1.43 mycroft tlp_cardbus_disable(sc);
584 1.43 mycroft break;
585 1.21 thorpej }
586 1.17 thorpej }
587 1.17 thorpej
588 1.17 thorpej void
589 1.18 thorpej tlp_cardbus_setup(csc)
590 1.17 thorpej struct tulip_cardbus_softc *csc;
591 1.17 thorpej {
592 1.17 thorpej struct tulip_softc *sc = &csc->sc_tulip;
593 1.17 thorpej cardbus_devfunc_t ct = csc->sc_ct;
594 1.17 thorpej cardbus_chipset_tag_t cc = ct->ct_cc;
595 1.17 thorpej cardbus_function_tag_t cf = ct->ct_cf;
596 1.17 thorpej pcireg_t reg;
597 1.17 thorpej
598 1.17 thorpej /*
599 1.17 thorpej * Check to see if the device is in power-save mode, and
600 1.17 thorpej * bring it out if necessary.
601 1.17 thorpej */
602 1.17 thorpej switch (sc->sc_chip) {
603 1.17 thorpej case TULIP_CHIP_21142:
604 1.17 thorpej case TULIP_CHIP_21143:
605 1.17 thorpej case TULIP_CHIP_X3201_3:
606 1.17 thorpej /*
607 1.17 thorpej * Clear the "sleep mode" bit in the CFDA register.
608 1.17 thorpej */
609 1.17 thorpej reg = cardbus_conf_read(cc, cf, csc->sc_tag, TULIP_PCI_CFDA);
610 1.17 thorpej if (reg & (CFDA_SLEEP|CFDA_SNOOZE))
611 1.17 thorpej cardbus_conf_write(cc, cf, csc->sc_tag, TULIP_PCI_CFDA,
612 1.17 thorpej reg & ~(CFDA_SLEEP|CFDA_SNOOZE));
613 1.17 thorpej break;
614 1.29 onoe
615 1.29 onoe default:
616 1.29 onoe /* Nothing. -- to make gcc happy */
617 1.30 thorpej break;
618 1.17 thorpej }
619 1.17 thorpej
620 1.40 christos (void)cardbus_setpowerstate(sc->sc_dev.dv_xname, ct, csc->sc_tag,
621 1.40 christos PCI_PWR_D0);
622 1.18 thorpej
623 1.42 mycroft /* Program the BAR. */
624 1.42 mycroft cardbus_conf_write(cc, cf, csc->sc_tag, csc->sc_bar_reg,
625 1.42 mycroft csc->sc_bar_val);
626 1.42 mycroft
627 1.18 thorpej /* Make sure the right access type is on the CardBus bridge. */
628 1.18 thorpej (*ct->ct_cf->cardbus_ctrl)(cc, csc->sc_cben);
629 1.18 thorpej (*ct->ct_cf->cardbus_ctrl)(cc, CARDBUS_BM_ENABLE);
630 1.18 thorpej
631 1.18 thorpej /* Enable the appropriate bits in the PCI CSR. */
632 1.18 thorpej reg = cardbus_conf_read(cc, cf, csc->sc_tag, PCI_COMMAND_STATUS_REG);
633 1.18 thorpej reg &= ~(PCI_COMMAND_IO_ENABLE|PCI_COMMAND_MEM_ENABLE);
634 1.18 thorpej reg |= csc->sc_csr;
635 1.18 thorpej cardbus_conf_write(cc, cf, csc->sc_tag, PCI_COMMAND_STATUS_REG, reg);
636 1.18 thorpej
637 1.18 thorpej /*
638 1.18 thorpej * Make sure the latency timer is set to some reasonable
639 1.18 thorpej * value.
640 1.18 thorpej */
641 1.18 thorpej reg = cardbus_conf_read(cc, cf, csc->sc_tag, PCI_BHLC_REG);
642 1.18 thorpej if (PCI_LATTIMER(reg) < 0x20) {
643 1.18 thorpej reg &= ~(PCI_LATTIMER_MASK << PCI_LATTIMER_SHIFT);
644 1.18 thorpej reg |= (0x20 << PCI_LATTIMER_SHIFT);
645 1.18 thorpej cardbus_conf_write(cc, cf, csc->sc_tag, PCI_BHLC_REG, reg);
646 1.17 thorpej }
647 1.10 thorpej }
648 1.10 thorpej
649 1.10 thorpej void
650 1.10 thorpej tlp_cardbus_x3201_reset(sc)
651 1.10 thorpej struct tulip_softc *sc;
652 1.10 thorpej {
653 1.10 thorpej u_int32_t reg;
654 1.10 thorpej
655 1.10 thorpej reg = TULIP_READ(sc, CSR_SIAGEN);
656 1.10 thorpej
657 1.10 thorpej /* make GP[2,0] outputs */
658 1.10 thorpej TULIP_WRITE(sc, CSR_SIAGEN, (reg & ~SIAGEN_MD) | SIAGEN_CWE |
659 1.10 thorpej 0x00050000);
660 1.10 thorpej TULIP_WRITE(sc, CSR_SIAGEN, (reg & ~SIAGEN_CWE) | SIAGEN_MD);
661 1.33 mycroft }
662 1.33 mycroft
663 1.33 mycroft void
664 1.33 mycroft tlp_cardbus_lxt_quirks(csc, enaddr)
665 1.33 mycroft struct tulip_cardbus_softc *csc;
666 1.33 mycroft const u_int8_t *enaddr;
667 1.33 mycroft {
668 1.33 mycroft struct tulip_softc *sc = &csc->sc_tulip;
669 1.33 mycroft
670 1.33 mycroft sc->sc_mediasw = &tlp_sio_mii_mediasw;
671 1.1 thorpej }
672