if_tlp_pci.c revision 1.16 1 /* $NetBSD: if_tlp_pci.c,v 1.16 1999/09/26 04:43:45 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
83 #include <dev/ic/tulipreg.h>
84 #include <dev/ic/tulipvar.h>
85
86 #include <dev/pci/pcivar.h>
87 #include <dev/pci/pcireg.h>
88 #include <dev/pci/pcidevs.h>
89
90 /*
91 * PCI configuration space registers used by the Tulip.
92 */
93 #define TULIP_PCI_IOBA 0x10 /* i/o mapped base */
94 #define TULIP_PCI_MMBA 0x14 /* memory mapped base */
95
96 struct tulip_pci_softc {
97 struct tulip_softc sc_tulip; /* real Tulip softc */
98
99 /* PCI-specific goo. */
100 void *sc_ih; /* interrupt handle */
101
102 pci_chipset_tag_t sc_pc; /* our PCI chipset */
103 pcitag_t sc_pcitag; /* our PCI tag */
104
105 int sc_flags; /* flags; see below */
106
107 LIST_HEAD(, tulip_pci_softc) sc_intrslaves;
108 LIST_ENTRY(tulip_pci_softc) sc_intrq;
109
110 /* Our {ROM,interrupt} master. */
111 struct tulip_pci_softc *sc_master;
112 };
113
114 /* sc_flags */
115 #define TULIP_PCI_SHAREDINTR 0x01 /* interrupt is shared */
116 #define TULIP_PCI_SLAVEINTR 0x02 /* interrupt is slave */
117 #define TULIP_PCI_SHAREDROM 0x04 /* ROM is shared */
118 #define TULIP_PCI_SLAVEROM 0x08 /* slave of shared ROM */
119
120 int tlp_pci_match __P((struct device *, struct cfdata *, void *));
121 void tlp_pci_attach __P((struct device *, struct device *, void *));
122
123 struct cfattach tlp_pci_ca = {
124 sizeof(struct tulip_pci_softc), tlp_pci_match, tlp_pci_attach,
125 };
126
127 const struct tulip_pci_product {
128 u_int32_t tpp_vendor; /* PCI vendor ID */
129 u_int32_t tpp_product; /* PCI product ID */
130 tulip_chip_t tpp_chip; /* base Tulip chip type */
131 } tlp_pci_products[] = {
132 #ifdef TLP_MATCH_21040
133 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21040,
134 TULIP_CHIP_21040 },
135 #endif
136 #ifdef TLP_MATCH_21041
137 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21041,
138 TULIP_CHIP_21041 },
139 #endif
140 #ifdef TLP_MATCH_21140
141 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21140,
142 TULIP_CHIP_21140 },
143 #endif
144 #ifdef TLP_MATCH_21142
145 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21142,
146 TULIP_CHIP_21142 },
147 #endif
148
149 { PCI_VENDOR_LITEON, PCI_PRODUCT_LITEON_82C168,
150 TULIP_CHIP_82C168 },
151
152 #if 0
153 /*
154 * Note: This is like a MX98715A with Wake-On-LAN and a
155 * 128-bit multicast hash table.
156 */
157 { PCI_VENDOR_LITEON, PCI_PRODUCT_LITEON_82C115,
158 TULIP_CHIP_82C115 },
159 #endif
160
161 #if 0
162 { PCI_VENDOR_MACRONIX, PCI_PRODUCT_MACRONIX_MX98713,
163 TULIP_CHIP_MX98713 },
164 { PCI_VENDOR_MACRONIX, PCI_PRODUCT_MACRONIX_MX987x5,
165 TULIP_CHIP_MX98715 },
166
167 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_RL100TX,
168 TULIP_CHIP_MX98713 },
169 #endif
170
171 { PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C840F,
172 TULIP_CHIP_WB89C840F },
173 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_RL100ATX,
174 TULIP_CHIP_WB89C840F },
175
176 #if 0
177 { PCI_VENDOR_DAVICOM, PCI_PRODUCT_DAVICOM_DM9102,
178 TULIP_CHIP_DM9102 },
179
180 { PCI_VENDOR_ADMTEK, PCI_PRODUCT_ADMTEK_AL981,
181 TULIP_CHIP_AL981 },
182
183 { PCI_VENDOR_ASIX, PCI_PRODUCT_ASIX_AX88140A,
184 TULIP_CHIP_AX88140 },
185 #endif
186
187 { 0, 0,
188 TULIP_CHIP_INVALID },
189 };
190
191 struct tlp_pci_quirks {
192 void (*tpq_func) __P((struct tulip_pci_softc *,
193 const u_int8_t *));
194 u_int8_t tpq_oui[3];
195 };
196
197 void tlp_pci_dec_quirks __P((struct tulip_pci_softc *,
198 const u_int8_t *));
199
200 void tlp_pci_znyx_21040_quirks __P((struct tulip_pci_softc *,
201 const u_int8_t *));
202 void tlp_pci_smc_21040_quirks __P((struct tulip_pci_softc *,
203 const u_int8_t *));
204 void tlp_pci_cogent_21040_quirks __P((struct tulip_pci_softc *,
205 const u_int8_t *));
206 void tlp_pci_accton_21040_quirks __P((struct tulip_pci_softc *,
207 const u_int8_t *));
208
209 const struct tlp_pci_quirks tlp_pci_21040_quirks[] = {
210 { tlp_pci_znyx_21040_quirks, { 0x00, 0xc0, 0x95 } },
211 { tlp_pci_smc_21040_quirks, { 0x00, 0x00, 0xc0 } },
212 { tlp_pci_cogent_21040_quirks, { 0x00, 0x00, 0x92 } },
213 { tlp_pci_accton_21040_quirks, { 0x00, 0x00, 0xe8 } },
214 { NULL, { 0, 0, 0 } }
215 };
216
217 const struct tlp_pci_quirks tlp_pci_21041_quirks[] = {
218 { tlp_pci_dec_quirks, { 0x08, 0x00, 0x2b } },
219 { tlp_pci_dec_quirks, { 0x00, 0x00, 0xf8 } },
220 { NULL, { 0, 0, 0 } }
221 };
222
223 const struct tlp_pci_quirks tlp_pci_21140_quirks[] = {
224 { tlp_pci_dec_quirks, { 0x08, 0x00, 0x2b } },
225 { tlp_pci_dec_quirks, { 0x00, 0x00, 0xf8 } },
226 { NULL, { 0, 0, 0 } }
227 };
228
229 const char *tlp_pci_chip_names[] = TULIP_CHIP_NAMES;
230
231 int tlp_pci_shared_intr __P((void *));
232
233 const struct tulip_pci_product *tlp_pci_lookup
234 __P((const struct pci_attach_args *));
235 void tlp_pci_get_quirks __P((struct tulip_pci_softc *, const u_int8_t *,
236 const struct tlp_pci_quirks *));
237 void tlp_pci_check_slaved __P((struct tulip_pci_softc *, int, int));
238
239 const struct tulip_pci_product *
240 tlp_pci_lookup(pa)
241 const struct pci_attach_args *pa;
242 {
243 const struct tulip_pci_product *tpp;
244
245 for (tpp = tlp_pci_products;
246 tlp_pci_chip_names[tpp->tpp_chip] != NULL;
247 tpp++) {
248 if (PCI_VENDOR(pa->pa_id) == tpp->tpp_vendor &&
249 PCI_PRODUCT(pa->pa_id) == tpp->tpp_product)
250 return (tpp);
251 }
252 return (NULL);
253 }
254
255 void
256 tlp_pci_get_quirks(psc, enaddr, tpq)
257 struct tulip_pci_softc *psc;
258 const u_int8_t *enaddr;
259 const struct tlp_pci_quirks *tpq;
260 {
261
262 for (; tpq->tpq_func != NULL; tpq++) {
263 if (tpq->tpq_oui[0] == enaddr[0] &&
264 tpq->tpq_oui[1] == enaddr[1] &&
265 tpq->tpq_oui[2] == enaddr[2]) {
266 (*tpq->tpq_func)(psc, enaddr);
267 return;
268 }
269 }
270 }
271
272 void
273 tlp_pci_check_slaved(psc, shared, slaved)
274 struct tulip_pci_softc *psc;
275 int shared, slaved;
276 {
277 extern struct cfdriver tlp_cd;
278 struct tulip_pci_softc *cur, *best = NULL;
279 struct tulip_softc *sc = &psc->sc_tulip;
280 int i;
281
282 /*
283 * First of all, find the lowest pcidev numbered device on our
284 * bus marked as shared. That should be our master.
285 */
286 for (i = 0; i < tlp_cd.cd_ndevs; i++) {
287 if ((cur = tlp_cd.cd_devs[i]) == NULL)
288 continue;
289 if (cur->sc_tulip.sc_dev.dv_parent != sc->sc_dev.dv_parent)
290 continue;
291 if ((cur->sc_flags & shared) == 0)
292 continue;
293 if (cur == psc)
294 continue;
295 if (best == NULL ||
296 best->sc_tulip.sc_devno > cur->sc_tulip.sc_devno)
297 best = cur;
298 }
299
300 if (best != NULL) {
301 psc->sc_master = best;
302 psc->sc_flags |= (shared | slaved);
303 }
304 }
305
306 int
307 tlp_pci_match(parent, match, aux)
308 struct device *parent;
309 struct cfdata *match;
310 void *aux;
311 {
312 struct pci_attach_args *pa = aux;
313
314 if (tlp_pci_lookup(pa) != NULL)
315 return (10); /* beat if_de.c */
316
317 return (0);
318 }
319
320 void
321 tlp_pci_attach(parent, self, aux)
322 struct device *parent, *self;
323 void *aux;
324 {
325 struct tulip_pci_softc *psc = (void *) self;
326 struct tulip_softc *sc = &psc->sc_tulip;
327 struct pci_attach_args *pa = aux;
328 pci_chipset_tag_t pc = pa->pa_pc;
329 pci_intr_handle_t ih;
330 const char *intrstr = NULL;
331 bus_space_tag_t iot, memt;
332 bus_space_handle_t ioh, memh;
333 int ioh_valid, memh_valid, i, j;
334 const struct tulip_pci_product *tpp;
335 u_int8_t enaddr[ETHER_ADDR_LEN];
336 u_int32_t val;
337
338 sc->sc_devno = pa->pa_device;
339 psc->sc_pc = pa->pa_pc;
340 psc->sc_pcitag = pa->pa_tag;
341
342 LIST_INIT(&psc->sc_intrslaves);
343
344 /*
345 * Map the device.
346 */
347 ioh_valid = (pci_mapreg_map(pa, TULIP_PCI_IOBA,
348 PCI_MAPREG_TYPE_IO, 0,
349 &iot, &ioh, NULL, NULL) == 0);
350 memh_valid = (pci_mapreg_map(pa, TULIP_PCI_MMBA,
351 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
352 &memt, &memh, NULL, NULL) == 0);
353
354 if (memh_valid) {
355 sc->sc_st = memt;
356 sc->sc_sh = memh;
357 } else if (ioh_valid) {
358 sc->sc_st = iot;
359 sc->sc_sh = ioh;
360 } else {
361 printf(": unable to map device registers\n");
362 return;
363 }
364
365 tpp = tlp_pci_lookup(pa);
366 if (tpp == NULL) {
367 printf("\n");
368 panic("tlp_pci_attach: impossible");
369 }
370 sc->sc_chip = tpp->tpp_chip;
371
372 /*
373 * By default, Tulip registers are 8 bytes long (4 bytes
374 * followed by a 4 byte pad).
375 */
376 sc->sc_regshift = 3;
377
378 /*
379 * Get revision info, and set some chip-specific variables.
380 */
381 sc->sc_rev = PCI_REVISION(pa->pa_class);
382 switch (sc->sc_chip) {
383 case TULIP_CHIP_21140:
384 if (sc->sc_rev >= 0x20)
385 sc->sc_chip = TULIP_CHIP_21140A;
386 break;
387
388 case TULIP_CHIP_21142:
389 if (sc->sc_rev >= 0x20)
390 sc->sc_chip = TULIP_CHIP_21143;
391 break;
392
393 case TULIP_CHIP_82C168:
394 if (sc->sc_rev >= 0x20)
395 sc->sc_chip = TULIP_CHIP_82C169;
396 break;
397
398 case TULIP_CHIP_MX98713:
399 if (sc->sc_rev >= 0x10)
400 sc->sc_chip = TULIP_CHIP_MX98713A;
401 break;
402
403 case TULIP_CHIP_MX98715:
404 if (sc->sc_rev >= 0x30)
405 sc->sc_chip = TULIP_CHIP_MX98725;
406 break;
407
408 case TULIP_CHIP_WB89C840F:
409 sc->sc_regshift = 2;
410 break;
411
412 case TULIP_CHIP_AX88140:
413 if (sc->sc_rev >= 0x10)
414 sc->sc_chip = TULIP_CHIP_AX88141;
415 break;
416
417 default:
418 /* Nothing. */
419 }
420
421 printf(": %s Ethernet, pass %d.%d\n",
422 tlp_pci_chip_names[sc->sc_chip],
423 (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
424
425 switch (sc->sc_chip) {
426 case TULIP_CHIP_21040:
427 if (sc->sc_rev < 0x20) {
428 printf("%s: 21040 must be at least pass 2.0\n",
429 sc->sc_dev.dv_xname);
430 return;
431 }
432 break;
433
434 case TULIP_CHIP_21140:
435 if (sc->sc_rev < 0x11) {
436 printf("%s: 21140 must be at least pass 1.1\n",
437 sc->sc_dev.dv_xname);
438 return;
439 }
440 break;
441
442 default:
443 /* Nothing. */
444 }
445
446 sc->sc_dmat = pa->pa_dmat;
447
448 /*
449 * Make sure bus mastering is enabled.
450 */
451 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
452 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
453 PCI_COMMAND_MASTER_ENABLE);
454
455 /*
456 * Get the cacheline size.
457 */
458 sc->sc_cacheline = PCI_CACHELINE(pci_conf_read(pc, pa->pa_tag,
459 PCI_BHLC_REG));
460
461 /*
462 * Read the contents of the Ethernet Address ROM/SROM.
463 */
464 memset(sc->sc_srom, 0, sizeof(sc->sc_srom));
465 switch (sc->sc_chip) {
466 case TULIP_CHIP_21040:
467 TULIP_WRITE(sc, CSR_MIIROM, MIIROM_SROMCS);
468 for (i = 0; i < sizeof(sc->sc_srom); i++) {
469 for (j = 0; j < 10000; j++) {
470 val = TULIP_READ(sc, CSR_MIIROM);
471 if ((val & MIIROM_DN) == 0)
472 break;
473 }
474 sc->sc_srom[i] = val & MIIROM_DATA;
475 }
476 break;
477
478 case TULIP_CHIP_82C168:
479 case TULIP_CHIP_82C169:
480 {
481 u_int16_t *rombuf = (u_int16_t *)sc->sc_srom;
482
483 /*
484 * The Lite-On PNIC stores the Ethernet address in
485 * the first 3 words of the EEPROM. EEPROM access
486 * is not like the other Tulip chips.
487 */
488 for (i = 0; i < 3; i++) {
489 TULIP_WRITE(sc, CSR_PNIC_SROMCTL,
490 PNIC_SROMCTL_READ | i);
491 for (j = 0; j < 500; j++) {
492 delay(2);
493 val = TULIP_READ(sc, CSR_MIIROM);
494 if ((val & PNIC_MIIROM_BUSY) == 0)
495 break;
496 }
497 if (val & PNIC_MIIROM_BUSY) {
498 printf("%s: EEPROM timed out\n",
499 sc->sc_dev.dv_xname);
500 return;
501 }
502 rombuf[i] = bswap16(val & PNIC_MIIROM_DATA);
503 }
504 break;
505 }
506
507 default:
508 tlp_read_srom(sc, 0, sizeof(sc->sc_srom) >> 1, sc->sc_srom);
509 #if 0
510 printf("SROM CONTENTS:");
511 for (i = 0; i < sizeof(sc->sc_srom); i++) {
512 if ((i % 8) == 0)
513 printf("\n\t");
514 printf("0x%02x ", sc->sc_srom[i]);
515 }
516 printf("\n");
517 #endif
518 }
519
520 /*
521 * Deal with chip/board quirks. This includes setting up
522 * the mediasw, and extracting the Ethernet address from
523 * the rombuf.
524 */
525 switch (sc->sc_chip) {
526 case TULIP_CHIP_21040:
527 /* Check for a slaved ROM on a multi-port board. */
528 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
529 TULIP_PCI_SLAVEROM);
530 if (psc->sc_flags & TULIP_PCI_SLAVEROM)
531 memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom,
532 sizeof(sc->sc_srom));
533
534 /*
535 * Parse the Ethernet Address ROM.
536 */
537 if (tlp_parse_old_srom(sc, enaddr) == 0) {
538 printf("%s: unable to decode Ethernet Address ROM\n",
539 sc->sc_dev.dv_xname);
540 return;
541 }
542
543 /*
544 * If we have a slaved ROM, adjust the Ethernet address.
545 */
546 if (psc->sc_flags & TULIP_PCI_SLAVEROM)
547 enaddr[5] +=
548 sc->sc_devno - psc->sc_master->sc_tulip.sc_devno;
549
550 /*
551 * All 21040 boards start out with the same
552 * media switch.
553 */
554 sc->sc_mediasw = &tlp_21040_mediasw;
555
556 /*
557 * Deal with any quirks this board might have.
558 */
559 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21040_quirks);
560 break;
561
562 case TULIP_CHIP_21041:
563 /* Check for a slaved ROM on a multi-port board. */
564 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
565 TULIP_PCI_SLAVEROM);
566 if (psc->sc_flags & TULIP_PCI_SLAVEROM)
567 memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom,
568 sizeof(sc->sc_srom));
569
570 /* Check for new format SROM. */
571 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
572 /*
573 * Not an ISV SROM; try the old DEC Ethernet Address
574 * ROM format.
575 */
576 if (tlp_parse_old_srom(sc, enaddr) == 0) {
577 printf("%s: unable to decode Ethernet "
578 "Address ROM\n", sc->sc_dev.dv_xname);
579 return;
580 }
581 }
582
583 /*
584 * All 21041 boards use the same media switch; they all
585 * work basically the same! Yippee!
586 */
587 sc->sc_mediasw = &tlp_21041_mediasw;
588
589 /*
590 * Deal with any quirks this board might have.
591 */
592 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21041_quirks);
593 break;
594
595 case TULIP_CHIP_21140:
596 case TULIP_CHIP_21140A:
597 /* Check for new format SROM. */
598 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
599 /*
600 * Not an ISV SROM; try the old DEC Ethernet Address
601 * ROM format.
602 */
603 if (tlp_parse_old_srom(sc, enaddr) == 0) {
604 printf("%s: unable to decode Ethernet "
605 "Address ROM\n", sc->sc_dev.dv_xname);
606 return;
607 }
608 } else {
609 /*
610 * We start out with the 2114x ISV media switch.
611 * When we search for quirks, we may change to
612 * a different switch.
613 */
614 sc->sc_mediasw = &tlp_2114x_isv_mediasw;
615 }
616
617 /*
618 * Deal with any quirks this board might have.
619 */
620 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21140_quirks);
621
622 /*
623 * Bail out now if we can't deal with this board.
624 */
625 if (sc->sc_mediasw == NULL)
626 goto cant_cope;
627 break;
628
629 case TULIP_CHIP_82C168:
630 case TULIP_CHIP_82C169:
631 /*
632 * Lite-On PNIC's Ethernet address is the first 6
633 * bytes of its EEPROM.
634 */
635 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
636
637 /*
638 * Lite-On PNICs always use the same mediasw; we
639 * select MII vs. internal NWAY automatically.
640 */
641 sc->sc_mediasw = &tlp_pnic_mediasw;
642 break;
643
644 case TULIP_CHIP_WB89C840F:
645 /*
646 * Winbond 89C840F's Ethernet address is the first
647 * 6 bytes of its EEPROM.
648 */
649 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
650
651 /*
652 * Winbond 89C840F has an MII attached to the SIO.
653 */
654 sc->sc_mediasw = &tlp_sio_mii_mediasw;
655 break;
656
657 default:
658 cant_cope:
659 printf("%s: sorry, unable to handle your board\n",
660 sc->sc_dev.dv_xname);
661 return;
662 }
663
664 /*
665 * Handle shared interrupts.
666 */
667 if (psc->sc_flags & TULIP_PCI_SHAREDINTR) {
668 if (psc->sc_master)
669 psc->sc_flags |= TULIP_PCI_SLAVEINTR;
670 else {
671 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDINTR,
672 TULIP_PCI_SLAVEINTR);
673 if (psc->sc_master == NULL)
674 psc->sc_master = psc;
675 }
676 LIST_INSERT_HEAD(&psc->sc_master->sc_intrslaves,
677 psc, sc_intrq);
678 }
679
680 if (psc->sc_flags & TULIP_PCI_SLAVEINTR) {
681 printf("%s: sharing interrupt with %s\n",
682 sc->sc_dev.dv_xname,
683 psc->sc_master->sc_tulip.sc_dev.dv_xname);
684 } else {
685 /*
686 * Map and establish our interrupt.
687 */
688 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
689 pa->pa_intrline, &ih)) {
690 printf("%s: unable to map interrupt\n",
691 sc->sc_dev.dv_xname);
692 return;
693 }
694 intrstr = pci_intr_string(pc, ih);
695 psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET,
696 (psc->sc_flags & TULIP_PCI_SHAREDINTR) ?
697 tlp_pci_shared_intr : tlp_intr, sc);
698 if (psc->sc_ih == NULL) {
699 printf("%s: unable to establish interrupt",
700 sc->sc_dev.dv_xname);
701 if (intrstr != NULL)
702 printf(" at %s", intrstr);
703 printf("\n");
704 return;
705 }
706 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
707 intrstr);
708 }
709
710 /*
711 * Finish off the attach.
712 */
713 tlp_attach(sc, enaddr);
714 }
715
716 int
717 tlp_pci_shared_intr(arg)
718 void *arg;
719 {
720 struct tulip_pci_softc *master = arg, *slave;
721 int rv = 0;
722
723 for (slave = LIST_FIRST(&master->sc_intrslaves);
724 slave != NULL;
725 slave = LIST_NEXT(slave, sc_intrq))
726 rv |= tlp_intr(&slave->sc_tulip);
727
728 return (rv);
729 }
730
731 void
732 tlp_pci_dec_quirks(psc, enaddr)
733 struct tulip_pci_softc *psc;
734 const u_int8_t *enaddr;
735 {
736 struct tulip_softc *sc = &psc->sc_tulip;
737
738 /*
739 * This isn't really a quirk-gathering device, really. We
740 * just want to get the spiffy DEC board name from the SROM.
741 */
742 strcpy(sc->sc_name, "DEC ");
743
744 if (memcmp(&sc->sc_srom[29], "DE500", 5) == 0 ||
745 memcmp(&sc->sc_srom[29], "DE450", 5) == 0)
746 memcpy(&sc->sc_name[4], &sc->sc_srom[29], 8);
747 }
748
749 void
750 tlp_pci_znyx_21040_quirks(psc, enaddr)
751 struct tulip_pci_softc *psc;
752 const u_int8_t *enaddr;
753 {
754 struct tulip_softc *sc = &psc->sc_tulip;
755 u_int16_t id = 0;
756
757 /*
758 * If we have a slaved ROM, just copy the bits from the master.
759 * This is in case we fail the ROM ID check (older boards) and
760 * need to fall back on Ethernet address model checking; that
761 * will fail for slave chips.
762 */
763 if (psc->sc_flags & TULIP_PCI_SLAVEROM) {
764 strcpy(sc->sc_name, psc->sc_master->sc_tulip.sc_name);
765 sc->sc_mediasw = psc->sc_master->sc_tulip.sc_mediasw;
766 psc->sc_flags |=
767 psc->sc_master->sc_flags & TULIP_PCI_SHAREDINTR;
768 return;
769 }
770
771 if (sc->sc_srom[32] == 0x4a && sc->sc_srom[33] == 0x52) {
772 id = sc->sc_srom[37] | (sc->sc_srom[36] << 8);
773 switch (id) {
774 zx312:
775 case 0x0602: /* ZX312 */
776 strcpy(sc->sc_name, "ZNYX ZX312");
777 return;
778
779 case 0x0622: /* ZX312T */
780 strcpy(sc->sc_name, "ZNYX ZX312T");
781 sc->sc_mediasw = &tlp_21040_tp_mediasw;
782 return;
783
784 zx314_inta:
785 case 0x0701: /* ZX314 INTA */
786 psc->sc_flags |= TULIP_PCI_SHAREDINTR;
787 /* FALLTHROUGH */
788 case 0x0711: /* ZX314 */
789 strcpy(sc->sc_name, "ZNYX ZX314");
790 psc->sc_flags |= TULIP_PCI_SHAREDROM;
791 sc->sc_mediasw = &tlp_21040_tp_mediasw;
792 return;
793
794 zx315_inta:
795 case 0x0801: /* ZX315 INTA */
796 psc->sc_flags |= TULIP_PCI_SHAREDINTR;
797 /* FALLTHROUGH */
798 case 0x0811: /* ZX315 */
799 strcpy(sc->sc_name, "ZNYX ZX315");
800 psc->sc_flags |= TULIP_PCI_SHAREDROM;
801 return;
802
803 default:
804 id = 0;
805 }
806 }
807
808 /*
809 * Deal with boards that have broken ROMs.
810 */
811 if (id == 0) {
812 if ((enaddr[3] & ~3) == 0xf0 && (enaddr[5] & 3) == 0x00)
813 goto zx314_inta;
814 if ((enaddr[3] & ~3) == 0xf4 && (enaddr[5] & 1) == 0x00)
815 goto zx315_inta;
816 if ((enaddr[3] & ~3) == 0xec)
817 goto zx312;
818 }
819
820 strcpy(sc->sc_name, "ZNYX ZX31x");
821 }
822
823 void
824 tlp_pci_smc_21040_quirks(psc, enaddr)
825 struct tulip_pci_softc *psc;
826 const u_int8_t *enaddr;
827 {
828 struct tulip_softc *sc = &psc->sc_tulip;
829 u_int16_t id1, id2, ei;
830 int auibnc = 0, utp = 0;
831 char *cp;
832
833 id1 = sc->sc_srom[0x60] | (sc->sc_srom[0x61] << 8);
834 id2 = sc->sc_srom[0x62] | (sc->sc_srom[0x63] << 8);
835 ei = sc->sc_srom[0x66] | (sc->sc_srom[0x67] << 8);
836
837 strcpy(sc->sc_name, "SMC 8432");
838 cp = &sc->sc_name[8];
839
840 if ((id1 & 1) == 0) {
841 *cp++ = 'B';
842 auibnc = 1;
843 }
844 if ((id1 & 0xff) > 0x32) {
845 *cp++ = 'T';
846 utp = 1;
847 }
848 if ((id1 & 0x4000) == 0) {
849 *cp++ = 'A';
850 auibnc = 1;
851 }
852 if (id2 == 0x15) {
853 sc->sc_name[7] = '4';
854 *cp++ = '-';
855 *cp++ = 'C';
856 *cp++ = 'H';
857 *cp++ = ei ? '2' : '1';
858 }
859 *cp = '\0';
860
861 if (utp != 0 && auibnc == 0)
862 sc->sc_mediasw = &tlp_21040_tp_mediasw;
863 else if (utp == 0 && auibnc != 0)
864 sc->sc_mediasw = &tlp_21040_auibnc_mediasw;
865 }
866
867 void
868 tlp_pci_cogent_21040_quirks(psc, enaddr)
869 struct tulip_pci_softc *psc;
870 const u_int8_t *enaddr;
871 {
872
873 strcpy(psc->sc_tulip.sc_name, "Cogent multi-port");
874 psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
875 }
876
877 void
878 tlp_pci_accton_21040_quirks(psc, enaddr)
879 struct tulip_pci_softc *psc;
880 const u_int8_t *enaddr;
881 {
882
883 strcpy(psc->sc_tulip.sc_name, "ACCTON EN1203");
884 }
885