if_tlp_pci.c revision 1.23 1 /* $NetBSD: if_tlp_pci.c,v 1.23 1999/11/19 18:22:43 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * PCI bus front-end for the Digital Semiconductor ``Tulip'' (21x4x)
42 * Ethernet controller family driver.
43 */
44
45 #include "opt_inet.h"
46 #include "opt_ns.h"
47 #include "bpfilter.h"
48
49 #include <sys/param.h>
50 #include <sys/systm.h>
51 #include <sys/mbuf.h>
52 #include <sys/malloc.h>
53 #include <sys/kernel.h>
54 #include <sys/socket.h>
55 #include <sys/ioctl.h>
56 #include <sys/errno.h>
57 #include <sys/device.h>
58
59 #include <net/if.h>
60 #include <net/if_dl.h>
61 #include <net/if_media.h>
62 #include <net/if_ether.h>
63
64 #if NBPFILTER > 0
65 #include <net/bpf.h>
66 #endif
67
68 #ifdef INET
69 #include <netinet/in.h>
70 #include <netinet/if_inarp.h>
71 #endif
72
73 #ifdef NS
74 #include <netns/ns.h>
75 #include <netns/ns_if.h>
76 #endif
77
78 #include <machine/bus.h>
79 #include <machine/intr.h>
80
81 #include <dev/mii/miivar.h>
82 #include <dev/mii/mii_bitbang.h>
83
84 #include <dev/ic/tulipreg.h>
85 #include <dev/ic/tulipvar.h>
86
87 #include <dev/pci/pcivar.h>
88 #include <dev/pci/pcireg.h>
89 #include <dev/pci/pcidevs.h>
90
91 /*
92 * PCI configuration space registers used by the Tulip.
93 */
94 #define TULIP_PCI_IOBA 0x10 /* i/o mapped base */
95 #define TULIP_PCI_MMBA 0x14 /* memory mapped base */
96 #define TULIP_PCI_CFDA 0x40 /* configuration driver area */
97
98 #define CFDA_SLEEP 0x80000000 /* sleep mode */
99
100 struct tulip_pci_softc {
101 struct tulip_softc sc_tulip; /* real Tulip softc */
102
103 /* PCI-specific goo. */
104 void *sc_ih; /* interrupt handle */
105
106 pci_chipset_tag_t sc_pc; /* our PCI chipset */
107 pcitag_t sc_pcitag; /* our PCI tag */
108
109 int sc_flags; /* flags; see below */
110
111 LIST_HEAD(, tulip_pci_softc) sc_intrslaves;
112 LIST_ENTRY(tulip_pci_softc) sc_intrq;
113
114 /* Our {ROM,interrupt} master. */
115 struct tulip_pci_softc *sc_master;
116 };
117
118 /* sc_flags */
119 #define TULIP_PCI_SHAREDINTR 0x01 /* interrupt is shared */
120 #define TULIP_PCI_SLAVEINTR 0x02 /* interrupt is slave */
121 #define TULIP_PCI_SHAREDROM 0x04 /* ROM is shared */
122 #define TULIP_PCI_SLAVEROM 0x08 /* slave of shared ROM */
123
124 int tlp_pci_match __P((struct device *, struct cfdata *, void *));
125 void tlp_pci_attach __P((struct device *, struct device *, void *));
126
127 struct cfattach tlp_pci_ca = {
128 sizeof(struct tulip_pci_softc), tlp_pci_match, tlp_pci_attach,
129 };
130
131 const struct tulip_pci_product {
132 u_int32_t tpp_vendor; /* PCI vendor ID */
133 u_int32_t tpp_product; /* PCI product ID */
134 tulip_chip_t tpp_chip; /* base Tulip chip type */
135 int tpp_pmreg; /* power management register offset */
136 } tlp_pci_products[] = {
137 #ifdef TLP_MATCH_21040
138 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21040,
139 TULIP_CHIP_21040, 0 },
140 #endif
141 #ifdef TLP_MATCH_21041
142 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21041,
143 TULIP_CHIP_21041, 0 },
144 #endif
145 #ifdef TLP_MATCH_21140
146 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21140,
147 TULIP_CHIP_21140, 0 },
148 #endif
149 #ifdef TLP_MATCH_21142
150 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21142,
151 TULIP_CHIP_21142, 0 },
152 #endif
153
154 { PCI_VENDOR_LITEON, PCI_PRODUCT_LITEON_82C168,
155 TULIP_CHIP_82C168, 0 },
156
157 /*
158 * Note: This is like a MX98725 with Wake-On-LAN and a
159 * 128-bit multicast hash table.
160 */
161 { PCI_VENDOR_LITEON, PCI_PRODUCT_LITEON_82C115,
162 TULIP_CHIP_82C115, 0x48 },
163
164 { PCI_VENDOR_MACRONIX, PCI_PRODUCT_MACRONIX_MX98713,
165 TULIP_CHIP_MX98713, 0 },
166 { PCI_VENDOR_MACRONIX, PCI_PRODUCT_MACRONIX_MX987x5,
167 TULIP_CHIP_MX98715, 0x48 },
168
169 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_RL100TX,
170 TULIP_CHIP_MX98713, 0 },
171
172 { PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C840F,
173 TULIP_CHIP_WB89C840F, 0 },
174 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_RL100ATX,
175 TULIP_CHIP_WB89C840F, 0 },
176
177 #if 0
178 { PCI_VENDOR_DAVICOM, PCI_PRODUCT_DAVICOM_DM9102,
179 TULIP_CHIP_DM9102, 0 },
180 #endif
181
182 { PCI_VENDOR_ADMTEK, PCI_PRODUCT_ADMTEK_AL981,
183 TULIP_CHIP_AL981, 0xc4 },
184
185 #if 0
186 { PCI_VENDOR_ASIX, PCI_PRODUCT_ASIX_AX88140A,
187 TULIP_CHIP_AX88140, 0 },
188 #endif
189
190 { 0, 0,
191 TULIP_CHIP_INVALID, 0 },
192 };
193
194 struct tlp_pci_quirks {
195 void (*tpq_func) __P((struct tulip_pci_softc *,
196 const u_int8_t *));
197 u_int8_t tpq_oui[3];
198 };
199
200 void tlp_pci_dec_quirks __P((struct tulip_pci_softc *,
201 const u_int8_t *));
202
203 void tlp_pci_znyx_21040_quirks __P((struct tulip_pci_softc *,
204 const u_int8_t *));
205 void tlp_pci_smc_21040_quirks __P((struct tulip_pci_softc *,
206 const u_int8_t *));
207 void tlp_pci_cogent_21040_quirks __P((struct tulip_pci_softc *,
208 const u_int8_t *));
209 void tlp_pci_accton_21040_quirks __P((struct tulip_pci_softc *,
210 const u_int8_t *));
211
212 const struct tlp_pci_quirks tlp_pci_21040_quirks[] = {
213 { tlp_pci_znyx_21040_quirks, { 0x00, 0xc0, 0x95 } },
214 { tlp_pci_smc_21040_quirks, { 0x00, 0x00, 0xc0 } },
215 { tlp_pci_cogent_21040_quirks, { 0x00, 0x00, 0x92 } },
216 { tlp_pci_accton_21040_quirks, { 0x00, 0x00, 0xe8 } },
217 { NULL, { 0, 0, 0 } }
218 };
219
220 const struct tlp_pci_quirks tlp_pci_21041_quirks[] = {
221 { tlp_pci_dec_quirks, { 0x08, 0x00, 0x2b } },
222 { tlp_pci_dec_quirks, { 0x00, 0x00, 0xf8 } },
223 { NULL, { 0, 0, 0 } }
224 };
225
226 void tlp_pci_asante_21140_quirks __P((struct tulip_pci_softc *,
227 const u_int8_t *));
228
229 const struct tlp_pci_quirks tlp_pci_21140_quirks[] = {
230 { tlp_pci_dec_quirks, { 0x08, 0x00, 0x2b } },
231 { tlp_pci_dec_quirks, { 0x00, 0x00, 0xf8 } },
232 { tlp_pci_asante_21140_quirks, { 0x00, 0x00, 0x94 } },
233 { NULL, { 0, 0, 0 } }
234 };
235
236 const struct tlp_pci_quirks tlp_pci_21142_quirks[] = {
237 { tlp_pci_dec_quirks, { 0x08, 0x00, 0x2b } },
238 { tlp_pci_dec_quirks, { 0x00, 0x00, 0xf8 } },
239 { NULL, { 0, 0, 0 } }
240 };
241
242 const char *tlp_pci_chip_names[] = TULIP_CHIP_NAMES;
243
244 int tlp_pci_shared_intr __P((void *));
245
246 const struct tulip_pci_product *tlp_pci_lookup
247 __P((const struct pci_attach_args *));
248 void tlp_pci_get_quirks __P((struct tulip_pci_softc *, const u_int8_t *,
249 const struct tlp_pci_quirks *));
250 void tlp_pci_check_slaved __P((struct tulip_pci_softc *, int, int));
251
252 const struct tulip_pci_product *
253 tlp_pci_lookup(pa)
254 const struct pci_attach_args *pa;
255 {
256 const struct tulip_pci_product *tpp;
257
258 for (tpp = tlp_pci_products;
259 tlp_pci_chip_names[tpp->tpp_chip] != NULL;
260 tpp++) {
261 if (PCI_VENDOR(pa->pa_id) == tpp->tpp_vendor &&
262 PCI_PRODUCT(pa->pa_id) == tpp->tpp_product)
263 return (tpp);
264 }
265 return (NULL);
266 }
267
268 void
269 tlp_pci_get_quirks(psc, enaddr, tpq)
270 struct tulip_pci_softc *psc;
271 const u_int8_t *enaddr;
272 const struct tlp_pci_quirks *tpq;
273 {
274
275 for (; tpq->tpq_func != NULL; tpq++) {
276 if (tpq->tpq_oui[0] == enaddr[0] &&
277 tpq->tpq_oui[1] == enaddr[1] &&
278 tpq->tpq_oui[2] == enaddr[2]) {
279 (*tpq->tpq_func)(psc, enaddr);
280 return;
281 }
282 }
283 }
284
285 void
286 tlp_pci_check_slaved(psc, shared, slaved)
287 struct tulip_pci_softc *psc;
288 int shared, slaved;
289 {
290 extern struct cfdriver tlp_cd;
291 struct tulip_pci_softc *cur, *best = NULL;
292 struct tulip_softc *sc = &psc->sc_tulip;
293 int i;
294
295 /*
296 * First of all, find the lowest pcidev numbered device on our
297 * bus marked as shared. That should be our master.
298 */
299 for (i = 0; i < tlp_cd.cd_ndevs; i++) {
300 if ((cur = tlp_cd.cd_devs[i]) == NULL)
301 continue;
302 if (cur->sc_tulip.sc_dev.dv_parent != sc->sc_dev.dv_parent)
303 continue;
304 if ((cur->sc_flags & shared) == 0)
305 continue;
306 if (cur == psc)
307 continue;
308 if (best == NULL ||
309 best->sc_tulip.sc_devno > cur->sc_tulip.sc_devno)
310 best = cur;
311 }
312
313 if (best != NULL) {
314 psc->sc_master = best;
315 psc->sc_flags |= (shared | slaved);
316 }
317 }
318
319 int
320 tlp_pci_match(parent, match, aux)
321 struct device *parent;
322 struct cfdata *match;
323 void *aux;
324 {
325 struct pci_attach_args *pa = aux;
326
327 if (tlp_pci_lookup(pa) != NULL)
328 return (10); /* beat if_de.c */
329
330 return (0);
331 }
332
333 void
334 tlp_pci_attach(parent, self, aux)
335 struct device *parent, *self;
336 void *aux;
337 {
338 struct tulip_pci_softc *psc = (void *) self;
339 struct tulip_softc *sc = &psc->sc_tulip;
340 struct pci_attach_args *pa = aux;
341 pci_chipset_tag_t pc = pa->pa_pc;
342 pci_intr_handle_t ih;
343 const char *intrstr = NULL;
344 bus_space_tag_t iot, memt;
345 bus_space_handle_t ioh, memh;
346 int ioh_valid, memh_valid, i, j;
347 const struct tulip_pci_product *tpp;
348 u_int8_t enaddr[ETHER_ADDR_LEN];
349 u_int32_t val;
350 pcireg_t reg;
351
352 sc->sc_devno = pa->pa_device;
353 psc->sc_pc = pa->pa_pc;
354 psc->sc_pcitag = pa->pa_tag;
355
356 LIST_INIT(&psc->sc_intrslaves);
357
358 tpp = tlp_pci_lookup(pa);
359 if (tpp == NULL) {
360 printf("\n");
361 panic("tlp_pci_attach: impossible");
362 }
363 sc->sc_chip = tpp->tpp_chip;
364
365 /*
366 * By default, Tulip registers are 8 bytes long (4 bytes
367 * followed by a 4 byte pad).
368 */
369 sc->sc_regshift = 3;
370
371 /*
372 * Get revision info, and set some chip-specific variables.
373 */
374 sc->sc_rev = PCI_REVISION(pa->pa_class);
375 switch (sc->sc_chip) {
376 case TULIP_CHIP_21140:
377 if (sc->sc_rev >= 0x20)
378 sc->sc_chip = TULIP_CHIP_21140A;
379 break;
380
381 case TULIP_CHIP_21142:
382 if (sc->sc_rev >= 0x20)
383 sc->sc_chip = TULIP_CHIP_21143;
384 break;
385
386 case TULIP_CHIP_82C168:
387 if (sc->sc_rev >= 0x20)
388 sc->sc_chip = TULIP_CHIP_82C169;
389 break;
390
391 case TULIP_CHIP_MX98713:
392 if (sc->sc_rev >= 0x10)
393 sc->sc_chip = TULIP_CHIP_MX98713A;
394 break;
395
396 case TULIP_CHIP_MX98715:
397 if (sc->sc_rev >= 0x20)
398 sc->sc_chip = TULIP_CHIP_MX98715A;
399 if (sc->sc_rev >= 0x30)
400 sc->sc_chip = TULIP_CHIP_MX98725;
401 break;
402
403 case TULIP_CHIP_WB89C840F:
404 sc->sc_regshift = 2;
405 break;
406
407 case TULIP_CHIP_AX88140:
408 if (sc->sc_rev >= 0x10)
409 sc->sc_chip = TULIP_CHIP_AX88141;
410 break;
411
412 default:
413 /* Nothing. */
414 }
415
416 printf(": %s Ethernet, pass %d.%d\n",
417 tlp_pci_chip_names[sc->sc_chip],
418 (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
419
420 switch (sc->sc_chip) {
421 case TULIP_CHIP_21040:
422 if (sc->sc_rev < 0x20) {
423 printf("%s: 21040 must be at least pass 2.0\n",
424 sc->sc_dev.dv_xname);
425 return;
426 }
427 break;
428
429 case TULIP_CHIP_21140:
430 if (sc->sc_rev < 0x11) {
431 printf("%s: 21140 must be at least pass 1.1\n",
432 sc->sc_dev.dv_xname);
433 return;
434 }
435 break;
436
437 default:
438 /* Nothing. */
439 }
440
441 /*
442 * Check to see if the device is in power-save mode, and
443 * being it out if necessary.
444 */
445 switch (sc->sc_chip) {
446 case TULIP_CHIP_21140:
447 case TULIP_CHIP_21140A:
448 case TULIP_CHIP_MX98713A:
449 case TULIP_CHIP_MX98715:
450 case TULIP_CHIP_MX98715A:
451 case TULIP_CHIP_MX98725:
452 /*
453 * Clear the "sleep mode" bit in the CFDA register.
454 */
455 reg = pci_conf_read(pc, pa->pa_tag, TULIP_PCI_CFDA);
456 if (reg & CFDA_SLEEP)
457 pci_conf_write(pc, pa->pa_tag, TULIP_PCI_CFDA,
458 reg & ~CFDA_SLEEP);
459 break;
460
461 default:
462 /* Nothing. */
463 }
464
465 if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, 0, 0)) {
466 if (tpp->tpp_pmreg == 0) {
467 printf("%s: don't know location of PMCSR for this "
468 "chip\n", sc->sc_dev.dv_xname);
469 return;
470 }
471 reg = pci_conf_read(pc, pa->pa_tag, tpp->tpp_pmreg) & 0x3;
472 if (reg == 3) {
473 /*
474 * The card has lost all configuration data in
475 * this state, so punt.
476 */
477 printf("%s: unable to wake up from power state D3\n",
478 sc->sc_dev.dv_xname);
479 return;
480 }
481 if (reg != 0) {
482 printf("%s: waking up from power state D%d\n",
483 sc->sc_dev.dv_xname, reg);
484 pci_conf_write(pc, pa->pa_tag, tpp->tpp_pmreg, 0);
485 }
486 }
487
488 /*
489 * Map the device.
490 */
491 ioh_valid = (pci_mapreg_map(pa, TULIP_PCI_IOBA,
492 PCI_MAPREG_TYPE_IO, 0,
493 &iot, &ioh, NULL, NULL) == 0);
494 memh_valid = (pci_mapreg_map(pa, TULIP_PCI_MMBA,
495 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
496 &memt, &memh, NULL, NULL) == 0);
497
498 if (memh_valid) {
499 sc->sc_st = memt;
500 sc->sc_sh = memh;
501 } else if (ioh_valid) {
502 sc->sc_st = iot;
503 sc->sc_sh = ioh;
504 } else {
505 printf(": unable to map device registers\n");
506 return;
507 }
508
509 sc->sc_dmat = pa->pa_dmat;
510
511 /*
512 * Make sure bus mastering is enabled.
513 */
514 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
515 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
516 PCI_COMMAND_MASTER_ENABLE);
517
518 /*
519 * Get the cacheline size.
520 */
521 sc->sc_cacheline = PCI_CACHELINE(pci_conf_read(pc, pa->pa_tag,
522 PCI_BHLC_REG));
523
524 /*
525 * Get PCI data moving command info.
526 */
527 if (pa->pa_flags & PCI_FLAGS_MRL_OKAY)
528 sc->sc_flags |= TULIPF_MRL;
529 if (pa->pa_flags & PCI_FLAGS_MRM_OKAY)
530 sc->sc_flags |= TULIPF_MRM;
531 if (pa->pa_flags & PCI_FLAGS_MWI_OKAY)
532 sc->sc_flags |= TULIPF_MWI;
533
534 /*
535 * Read the contents of the Ethernet Address ROM/SROM. PCI
536 * chips have a 128 byte SROM (6 address bits).
537 */
538 sc->sc_srom_addrbits = 6;
539 memset(sc->sc_srom, 0, sizeof(sc->sc_srom));
540 switch (sc->sc_chip) {
541 case TULIP_CHIP_21040:
542 TULIP_WRITE(sc, CSR_MIIROM, MIIROM_SROMCS);
543 for (i = 0; i < TULIP_ROM_SIZE(sc->sc_srom_addrbits); i++) {
544 for (j = 0; j < 10000; j++) {
545 val = TULIP_READ(sc, CSR_MIIROM);
546 if ((val & MIIROM_DN) == 0)
547 break;
548 }
549 sc->sc_srom[i] = val & MIIROM_DATA;
550 }
551 break;
552
553 case TULIP_CHIP_82C168:
554 case TULIP_CHIP_82C169:
555 {
556 u_int16_t *rombuf = (u_int16_t *)sc->sc_srom;
557
558 /*
559 * The Lite-On PNIC stores the Ethernet address in
560 * the first 3 words of the EEPROM. EEPROM access
561 * is not like the other Tulip chips.
562 */
563 for (i = 0; i < 3; i++) {
564 TULIP_WRITE(sc, CSR_PNIC_SROMCTL,
565 PNIC_SROMCTL_READ | i);
566 for (j = 0; j < 500; j++) {
567 delay(2);
568 val = TULIP_READ(sc, CSR_MIIROM);
569 if ((val & PNIC_MIIROM_BUSY) == 0)
570 break;
571 }
572 if (val & PNIC_MIIROM_BUSY) {
573 printf("%s: EEPROM timed out\n",
574 sc->sc_dev.dv_xname);
575 return;
576 }
577 rombuf[i] = bswap16(val & PNIC_MIIROM_DATA);
578 }
579 break;
580 }
581
582 default:
583 tlp_read_srom(sc, 0, TULIP_ROM_SIZE(sc->sc_srom_addrbits) >> 1,
584 sc->sc_srom);
585 #if 0
586 printf("SROM CONTENTS:");
587 for (i = 0; i < TULIP_ROM_SIZE(sc->sc_srom_addrbits); i++) {
588 if ((i % 8) == 0)
589 printf("\n\t");
590 printf("0x%02x ", sc->sc_srom[i]);
591 }
592 printf("\n");
593 #endif
594 }
595
596 /*
597 * Deal with chip/board quirks. This includes setting up
598 * the mediasw, and extracting the Ethernet address from
599 * the rombuf.
600 */
601 switch (sc->sc_chip) {
602 case TULIP_CHIP_21040:
603 /* Check for a slaved ROM on a multi-port board. */
604 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
605 TULIP_PCI_SLAVEROM);
606 if (psc->sc_flags & TULIP_PCI_SLAVEROM)
607 memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom,
608 sizeof(sc->sc_srom));
609
610 /*
611 * Parse the Ethernet Address ROM.
612 */
613 if (tlp_parse_old_srom(sc, enaddr) == 0) {
614 printf("%s: unable to decode Ethernet Address ROM\n",
615 sc->sc_dev.dv_xname);
616 return;
617 }
618
619 /*
620 * If we have a slaved ROM, adjust the Ethernet address.
621 */
622 if (psc->sc_flags & TULIP_PCI_SLAVEROM)
623 enaddr[5] +=
624 sc->sc_devno - psc->sc_master->sc_tulip.sc_devno;
625
626 /*
627 * All 21040 boards start out with the same
628 * media switch.
629 */
630 sc->sc_mediasw = &tlp_21040_mediasw;
631
632 /*
633 * Deal with any quirks this board might have.
634 */
635 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21040_quirks);
636 break;
637
638 case TULIP_CHIP_21041:
639 /* Check for a slaved ROM on a multi-port board. */
640 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
641 TULIP_PCI_SLAVEROM);
642 if (psc->sc_flags & TULIP_PCI_SLAVEROM)
643 memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom,
644 sizeof(sc->sc_srom));
645
646 /* Check for new format SROM. */
647 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
648 /*
649 * Not an ISV SROM; try the old DEC Ethernet Address
650 * ROM format.
651 */
652 if (tlp_parse_old_srom(sc, enaddr) == 0) {
653 printf("%s: unable to decode Ethernet "
654 "Address ROM\n", sc->sc_dev.dv_xname);
655 return;
656 }
657 }
658
659 /*
660 * All 21041 boards use the same media switch; they all
661 * work basically the same! Yippee!
662 */
663 sc->sc_mediasw = &tlp_21041_mediasw;
664
665 /*
666 * Deal with any quirks this board might have.
667 */
668 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21041_quirks);
669 break;
670
671 case TULIP_CHIP_21140:
672 case TULIP_CHIP_21140A:
673 /* Check for new format SROM. */
674 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
675 /*
676 * Not an ISV SROM; try the old DEC Ethernet Address
677 * ROM format.
678 */
679 if (tlp_parse_old_srom(sc, enaddr) == 0) {
680 printf("%s: unable to decode Ethernet "
681 "Address ROM\n", sc->sc_dev.dv_xname);
682 return;
683 }
684 } else {
685 /*
686 * We start out with the 2114x ISV media switch.
687 * When we search for quirks, we may change to
688 * a different switch.
689 */
690 sc->sc_mediasw = &tlp_2114x_isv_mediasw;
691 }
692
693 /*
694 * Deal with any quirks this board might have.
695 */
696 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21140_quirks);
697
698 /*
699 * Bail out now if we can't deal with this board.
700 */
701 if (sc->sc_mediasw == NULL)
702 goto cant_cope;
703 break;
704
705 case TULIP_CHIP_21142:
706 case TULIP_CHIP_21143:
707 /* Check for new format SROM. */
708 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
709 /*
710 * Not an ISV SROM; can't cope, for now.
711 */
712 goto cant_cope;
713 } else {
714 /*
715 * We start out with the 2114x ISV media switch.
716 * When we search for quirks, we may change to
717 * a different switch.
718 */
719 sc->sc_mediasw = &tlp_2114x_isv_mediasw;
720 }
721
722 /*
723 * Deal with any quirks this board might have.
724 */
725 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21142_quirks);
726
727 /*
728 * Bail out now if we can't deal with this board.
729 */
730 if (sc->sc_mediasw == NULL)
731 goto cant_cope;
732 break;
733
734 case TULIP_CHIP_82C168:
735 case TULIP_CHIP_82C169:
736 /*
737 * Lite-On PNIC's Ethernet address is the first 6
738 * bytes of its EEPROM.
739 */
740 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
741
742 /*
743 * Lite-On PNICs always use the same mediasw; we
744 * select MII vs. internal NWAY automatically.
745 */
746 sc->sc_mediasw = &tlp_pnic_mediasw;
747 break;
748
749 case TULIP_CHIP_MX98713:
750 /*
751 * The Macronix MX98713 has an MII and GPIO, but no
752 * internal Nway block. This chip is basically a
753 * perfect 21140A clone, with the exception of the
754 * a magic register frobbing in order to make the
755 * interface function.
756 */
757 if (tlp_isv_srom_enaddr(sc, enaddr)) {
758 sc->sc_mediasw = &tlp_2114x_isv_mediasw;
759 break;
760 }
761 /* FALLTHROUGH */
762
763 case TULIP_CHIP_82C115:
764 /*
765 * Yippee! The Lite-On 82C115 is a clone of
766 * the MX98725 (the data sheet even says `MXIC'
767 * on it)! Imagine that, a clone of a clone.
768 *
769 * The differences are really minimal:
770 *
771 * - Wake-On-LAN support
772 * - 128-bit multicast hash table, rather than
773 * the standard 512-bit hash table
774 */
775 /* FALLTHROUGH */
776
777 case TULIP_CHIP_MX98713A:
778 case TULIP_CHIP_MX98715A:
779 case TULIP_CHIP_MX98725:
780 /*
781 * The MX98713A has an MII as well as an internal Nway block,
782 * but no GPIO. The MX98715 and MX98725 have an internal
783 * Nway block only.
784 *
785 * The internal Nway block, unlike the Lite-On PNIC's, does
786 * just that - performs Nway. Once autonegotiation completes,
787 * we must program the GPR media information into the chip.
788 *
789 * The byte offset of the Ethernet address is stored at
790 * offset 0x70.
791 */
792 memcpy(enaddr, &sc->sc_srom[sc->sc_srom[0x70]], ETHER_ADDR_LEN);
793 sc->sc_mediasw = &tlp_pmac_mediasw;
794 break;
795
796 case TULIP_CHIP_WB89C840F:
797 /*
798 * Winbond 89C840F's Ethernet address is the first
799 * 6 bytes of its EEPROM.
800 */
801 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
802
803 /*
804 * Winbond 89C840F has an MII attached to the SIO.
805 */
806 sc->sc_mediasw = &tlp_sio_mii_mediasw;
807 break;
808
809 case TULIP_CHIP_AL981:
810 /*
811 * The ADMtek AL981's Ethernet address is located
812 * at offset 8 of its EEPROM.
813 */
814 memcpy(enaddr, &sc->sc_srom[8], ETHER_ADDR_LEN);
815
816 /*
817 * ADMtek AL981 has a built-in PHY accessed through
818 * special registers.
819 */
820 sc->sc_mediasw = &tlp_al981_mediasw;
821 break;
822
823 default:
824 cant_cope:
825 printf("%s: sorry, unable to handle your board\n",
826 sc->sc_dev.dv_xname);
827 return;
828 }
829
830 /*
831 * Handle shared interrupts.
832 */
833 if (psc->sc_flags & TULIP_PCI_SHAREDINTR) {
834 if (psc->sc_master)
835 psc->sc_flags |= TULIP_PCI_SLAVEINTR;
836 else {
837 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDINTR,
838 TULIP_PCI_SLAVEINTR);
839 if (psc->sc_master == NULL)
840 psc->sc_master = psc;
841 }
842 LIST_INSERT_HEAD(&psc->sc_master->sc_intrslaves,
843 psc, sc_intrq);
844 }
845
846 if (psc->sc_flags & TULIP_PCI_SLAVEINTR) {
847 printf("%s: sharing interrupt with %s\n",
848 sc->sc_dev.dv_xname,
849 psc->sc_master->sc_tulip.sc_dev.dv_xname);
850 } else {
851 /*
852 * Map and establish our interrupt.
853 */
854 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
855 pa->pa_intrline, &ih)) {
856 printf("%s: unable to map interrupt\n",
857 sc->sc_dev.dv_xname);
858 return;
859 }
860 intrstr = pci_intr_string(pc, ih);
861 psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET,
862 (psc->sc_flags & TULIP_PCI_SHAREDINTR) ?
863 tlp_pci_shared_intr : tlp_intr, sc);
864 if (psc->sc_ih == NULL) {
865 printf("%s: unable to establish interrupt",
866 sc->sc_dev.dv_xname);
867 if (intrstr != NULL)
868 printf(" at %s", intrstr);
869 printf("\n");
870 return;
871 }
872 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
873 intrstr);
874 }
875
876 /*
877 * Finish off the attach.
878 */
879 tlp_attach(sc, enaddr);
880 }
881
882 int
883 tlp_pci_shared_intr(arg)
884 void *arg;
885 {
886 struct tulip_pci_softc *master = arg, *slave;
887 int rv = 0;
888
889 for (slave = LIST_FIRST(&master->sc_intrslaves);
890 slave != NULL;
891 slave = LIST_NEXT(slave, sc_intrq))
892 rv |= tlp_intr(&slave->sc_tulip);
893
894 return (rv);
895 }
896
897 void
898 tlp_pci_dec_quirks(psc, enaddr)
899 struct tulip_pci_softc *psc;
900 const u_int8_t *enaddr;
901 {
902 struct tulip_softc *sc = &psc->sc_tulip;
903
904 /*
905 * This isn't really a quirk-gathering device, really. We
906 * just want to get the spiffy DEC board name from the SROM.
907 */
908 strcpy(sc->sc_name, "DEC ");
909
910 if (memcmp(&sc->sc_srom[29], "DE500", 5) == 0 ||
911 memcmp(&sc->sc_srom[29], "DE450", 5) == 0)
912 memcpy(&sc->sc_name[4], &sc->sc_srom[29], 8);
913 }
914
915 void
916 tlp_pci_znyx_21040_quirks(psc, enaddr)
917 struct tulip_pci_softc *psc;
918 const u_int8_t *enaddr;
919 {
920 struct tulip_softc *sc = &psc->sc_tulip;
921 u_int16_t id = 0;
922
923 /*
924 * If we have a slaved ROM, just copy the bits from the master.
925 * This is in case we fail the ROM ID check (older boards) and
926 * need to fall back on Ethernet address model checking; that
927 * will fail for slave chips.
928 */
929 if (psc->sc_flags & TULIP_PCI_SLAVEROM) {
930 strcpy(sc->sc_name, psc->sc_master->sc_tulip.sc_name);
931 sc->sc_mediasw = psc->sc_master->sc_tulip.sc_mediasw;
932 psc->sc_flags |=
933 psc->sc_master->sc_flags & TULIP_PCI_SHAREDINTR;
934 return;
935 }
936
937 if (sc->sc_srom[32] == 0x4a && sc->sc_srom[33] == 0x52) {
938 id = sc->sc_srom[37] | (sc->sc_srom[36] << 8);
939 switch (id) {
940 zx312:
941 case 0x0602: /* ZX312 */
942 strcpy(sc->sc_name, "ZNYX ZX312");
943 return;
944
945 case 0x0622: /* ZX312T */
946 strcpy(sc->sc_name, "ZNYX ZX312T");
947 sc->sc_mediasw = &tlp_21040_tp_mediasw;
948 return;
949
950 zx314_inta:
951 case 0x0701: /* ZX314 INTA */
952 psc->sc_flags |= TULIP_PCI_SHAREDINTR;
953 /* FALLTHROUGH */
954 case 0x0711: /* ZX314 */
955 strcpy(sc->sc_name, "ZNYX ZX314");
956 psc->sc_flags |= TULIP_PCI_SHAREDROM;
957 sc->sc_mediasw = &tlp_21040_tp_mediasw;
958 return;
959
960 zx315_inta:
961 case 0x0801: /* ZX315 INTA */
962 psc->sc_flags |= TULIP_PCI_SHAREDINTR;
963 /* FALLTHROUGH */
964 case 0x0811: /* ZX315 */
965 strcpy(sc->sc_name, "ZNYX ZX315");
966 psc->sc_flags |= TULIP_PCI_SHAREDROM;
967 return;
968
969 default:
970 id = 0;
971 }
972 }
973
974 /*
975 * Deal with boards that have broken ROMs.
976 */
977 if (id == 0) {
978 if ((enaddr[3] & ~3) == 0xf0 && (enaddr[5] & 3) == 0x00)
979 goto zx314_inta;
980 if ((enaddr[3] & ~3) == 0xf4 && (enaddr[5] & 1) == 0x00)
981 goto zx315_inta;
982 if ((enaddr[3] & ~3) == 0xec)
983 goto zx312;
984 }
985
986 strcpy(sc->sc_name, "ZNYX ZX31x");
987 }
988
989 void
990 tlp_pci_smc_21040_quirks(psc, enaddr)
991 struct tulip_pci_softc *psc;
992 const u_int8_t *enaddr;
993 {
994 struct tulip_softc *sc = &psc->sc_tulip;
995 u_int16_t id1, id2, ei;
996 int auibnc = 0, utp = 0;
997 char *cp;
998
999 id1 = sc->sc_srom[0x60] | (sc->sc_srom[0x61] << 8);
1000 id2 = sc->sc_srom[0x62] | (sc->sc_srom[0x63] << 8);
1001 ei = sc->sc_srom[0x66] | (sc->sc_srom[0x67] << 8);
1002
1003 strcpy(sc->sc_name, "SMC 8432");
1004 cp = &sc->sc_name[8];
1005
1006 if ((id1 & 1) == 0) {
1007 *cp++ = 'B';
1008 auibnc = 1;
1009 }
1010 if ((id1 & 0xff) > 0x32) {
1011 *cp++ = 'T';
1012 utp = 1;
1013 }
1014 if ((id1 & 0x4000) == 0) {
1015 *cp++ = 'A';
1016 auibnc = 1;
1017 }
1018 if (id2 == 0x15) {
1019 sc->sc_name[7] = '4';
1020 *cp++ = '-';
1021 *cp++ = 'C';
1022 *cp++ = 'H';
1023 *cp++ = ei ? '2' : '1';
1024 }
1025 *cp = '\0';
1026
1027 if (utp != 0 && auibnc == 0)
1028 sc->sc_mediasw = &tlp_21040_tp_mediasw;
1029 else if (utp == 0 && auibnc != 0)
1030 sc->sc_mediasw = &tlp_21040_auibnc_mediasw;
1031 }
1032
1033 void
1034 tlp_pci_cogent_21040_quirks(psc, enaddr)
1035 struct tulip_pci_softc *psc;
1036 const u_int8_t *enaddr;
1037 {
1038
1039 strcpy(psc->sc_tulip.sc_name, "Cogent multi-port");
1040 psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
1041 }
1042
1043 void
1044 tlp_pci_accton_21040_quirks(psc, enaddr)
1045 struct tulip_pci_softc *psc;
1046 const u_int8_t *enaddr;
1047 {
1048
1049 strcpy(psc->sc_tulip.sc_name, "ACCTON EN1203");
1050 }
1051
1052 void tlp_pci_asante_21140_reset __P((struct tulip_softc *));
1053
1054 void
1055 tlp_pci_asante_21140_quirks(psc, enaddr)
1056 struct tulip_pci_softc *psc;
1057 const u_int8_t *enaddr;
1058 {
1059 struct tulip_softc *sc = &psc->sc_tulip;
1060
1061 /*
1062 * Some Asante boards don't use the ISV SROM format. For
1063 * those that don't, we initialize the GPIO direction bits,
1064 * and provide our own reset hook, which resets the MII.
1065 *
1066 * All of these boards use SIO-attached-MII media.
1067 */
1068 if (sc->sc_mediasw == &tlp_2114x_isv_mediasw)
1069 return;
1070
1071 strcpy(sc->sc_name, "Asante");
1072
1073 sc->sc_gp_dir = 0xbf;
1074 sc->sc_reset = tlp_pci_asante_21140_reset;
1075 sc->sc_mediasw = &tlp_sio_mii_mediasw;
1076 }
1077
1078 void
1079 tlp_pci_asante_21140_reset(sc)
1080 struct tulip_softc *sc;
1081 {
1082
1083 TULIP_WRITE(sc, CSR_GPP, GPP_GPC | sc->sc_gp_dir);
1084 TULIP_WRITE(sc, CSR_GPP, 0x8);
1085 delay(100);
1086 TULIP_WRITE(sc, CSR_GPP, 0);
1087 }
1088