if_tlp_pci.c revision 1.12 1 /* $NetBSD: if_tlp_pci.c,v 1.12 1999/09/20 19:26:55 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_znyx_21040_quirks __P((struct tulip_pci_softc *,
198 const u_int8_t *));
199 void tlp_pci_smc_21040_quirks __P((struct tulip_pci_softc *,
200 const u_int8_t *));
201 void tlp_pci_cogent_21040_quirks __P((struct tulip_pci_softc *,
202 const u_int8_t *));
203 void tlp_pci_accton_21040_quirks __P((struct tulip_pci_softc *,
204 const u_int8_t *));
205
206 const struct tlp_pci_quirks tlp_pci_21040_quirks[] = {
207 { tlp_pci_znyx_21040_quirks, { 0x00, 0xc0, 0x95 } },
208 { tlp_pci_smc_21040_quirks, { 0x00, 0x00, 0xc0 } },
209 { tlp_pci_cogent_21040_quirks, { 0x00, 0x00, 0x92 } },
210 { tlp_pci_accton_21040_quirks, { 0x00, 0x00, 0xe8 } },
211 { NULL, { 0, 0, 0 } }
212 };
213
214 const char *tlp_pci_chip_names[] = TULIP_CHIP_NAMES;
215
216 int tlp_pci_shared_intr __P((void *));
217
218 const struct tulip_pci_product *tlp_pci_lookup
219 __P((const struct pci_attach_args *));
220 void tlp_pci_get_quirks __P((struct tulip_pci_softc *, const u_int8_t *,
221 const struct tlp_pci_quirks *));
222 void tlp_pci_check_slaved __P((struct tulip_pci_softc *, int, int));
223
224 const struct tulip_pci_product *
225 tlp_pci_lookup(pa)
226 const struct pci_attach_args *pa;
227 {
228 const struct tulip_pci_product *tpp;
229
230 for (tpp = tlp_pci_products;
231 tlp_pci_chip_names[tpp->tpp_chip] != NULL;
232 tpp++) {
233 if (PCI_VENDOR(pa->pa_id) == tpp->tpp_vendor &&
234 PCI_PRODUCT(pa->pa_id) == tpp->tpp_product)
235 return (tpp);
236 }
237 return (NULL);
238 }
239
240 void
241 tlp_pci_get_quirks(psc, enaddr, tpq)
242 struct tulip_pci_softc *psc;
243 const u_int8_t *enaddr;
244 const struct tlp_pci_quirks *tpq;
245 {
246
247 for (; tpq->tpq_func != NULL; tpq++) {
248 if (tpq->tpq_oui[0] == enaddr[0] &&
249 tpq->tpq_oui[1] == enaddr[1] &&
250 tpq->tpq_oui[2] == enaddr[2]) {
251 (*tpq->tpq_func)(psc, enaddr);
252 return;
253 }
254 }
255 }
256
257 void
258 tlp_pci_check_slaved(psc, shared, slaved)
259 struct tulip_pci_softc *psc;
260 int shared, slaved;
261 {
262 extern struct cfdriver tlp_cd;
263 struct tulip_pci_softc *cur, *best = NULL;
264 struct tulip_softc *sc = &psc->sc_tulip;
265 int i;
266
267 /*
268 * First of all, find the lowest pcidev numbered device on our
269 * bus marked as shared. That should be our master.
270 */
271 for (i = 0; i < tlp_cd.cd_ndevs; i++) {
272 if ((cur = tlp_cd.cd_devs[i]) == NULL)
273 continue;
274 if (cur->sc_tulip.sc_dev.dv_parent != sc->sc_dev.dv_parent)
275 continue;
276 if ((cur->sc_flags & shared) == 0)
277 continue;
278 if (cur == psc)
279 continue;
280 if (best == NULL ||
281 best->sc_tulip.sc_devno > cur->sc_tulip.sc_devno)
282 best = cur;
283 }
284
285 if (best != NULL) {
286 psc->sc_master = best;
287 psc->sc_flags |= (shared | slaved);
288 }
289 }
290
291 int
292 tlp_pci_match(parent, match, aux)
293 struct device *parent;
294 struct cfdata *match;
295 void *aux;
296 {
297 struct pci_attach_args *pa = aux;
298
299 if (tlp_pci_lookup(pa) != NULL)
300 return (10); /* beat if_de.c */
301
302 return (0);
303 }
304
305 void
306 tlp_pci_attach(parent, self, aux)
307 struct device *parent, *self;
308 void *aux;
309 {
310 struct tulip_pci_softc *psc = (void *) self;
311 struct tulip_softc *sc = &psc->sc_tulip;
312 struct pci_attach_args *pa = aux;
313 pci_chipset_tag_t pc = pa->pa_pc;
314 pci_intr_handle_t ih;
315 const char *intrstr = NULL;
316 bus_space_tag_t iot, memt;
317 bus_space_handle_t ioh, memh;
318 int ioh_valid, memh_valid, i, j;
319 const struct tulip_pci_product *tpp;
320 u_int8_t enaddr[ETHER_ADDR_LEN];
321 u_int32_t val;
322
323 sc->sc_devno = pa->pa_device;
324 psc->sc_pc = pa->pa_pc;
325 psc->sc_pcitag = pa->pa_tag;
326
327 LIST_INIT(&psc->sc_intrslaves);
328
329 /*
330 * Map the device.
331 */
332 ioh_valid = (pci_mapreg_map(pa, TULIP_PCI_IOBA,
333 PCI_MAPREG_TYPE_IO, 0,
334 &iot, &ioh, NULL, NULL) == 0);
335 memh_valid = (pci_mapreg_map(pa, TULIP_PCI_MMBA,
336 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
337 &memt, &memh, NULL, NULL) == 0);
338
339 if (memh_valid) {
340 sc->sc_st = memt;
341 sc->sc_sh = memh;
342 } else if (ioh_valid) {
343 sc->sc_st = iot;
344 sc->sc_sh = ioh;
345 } else {
346 printf(": unable to map device registers\n");
347 return;
348 }
349
350 tpp = tlp_pci_lookup(pa);
351 if (tpp == NULL) {
352 printf("\n");
353 panic("tlp_pci_attach: impossible");
354 }
355 sc->sc_chip = tpp->tpp_chip;
356
357 /*
358 * By default, Tulip registers are 8 bytes long (4 bytes
359 * followed by a 4 byte pad).
360 */
361 sc->sc_regshift = 3;
362
363 /*
364 * Get revision info, and set some chip-specific variables.
365 */
366 sc->sc_rev = PCI_REVISION(pa->pa_class);
367 switch (sc->sc_chip) {
368 case TULIP_CHIP_21140:
369 if (sc->sc_rev >= 0x20)
370 sc->sc_chip = TULIP_CHIP_21140A;
371 break;
372
373 case TULIP_CHIP_21142:
374 if (sc->sc_rev >= 0x20)
375 sc->sc_chip = TULIP_CHIP_21143;
376 break;
377
378 case TULIP_CHIP_82C168:
379 if (sc->sc_rev >= 0x20)
380 sc->sc_chip = TULIP_CHIP_82C169;
381 break;
382
383 case TULIP_CHIP_MX98713:
384 if (sc->sc_rev >= 0x10)
385 sc->sc_chip = TULIP_CHIP_MX98713A;
386 break;
387
388 case TULIP_CHIP_MX98715:
389 if (sc->sc_rev >= 0x30)
390 sc->sc_chip = TULIP_CHIP_MX98725;
391 break;
392
393 case TULIP_CHIP_WB89C840F:
394 sc->sc_regshift = 2;
395 break;
396
397 case TULIP_CHIP_AX88140:
398 if (sc->sc_rev >= 0x10)
399 sc->sc_chip = TULIP_CHIP_AX88141;
400 break;
401
402 default:
403 /* Nothing. */
404 }
405
406 printf(": %s Ethernet, pass %d.%d\n",
407 tlp_pci_chip_names[sc->sc_chip],
408 (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
409
410 switch (sc->sc_chip) {
411 case TULIP_CHIP_21040:
412 if (sc->sc_rev < 0x20) {
413 printf("%s: 21040 must be at least pass 2.0\n",
414 sc->sc_dev.dv_xname);
415 return;
416 }
417 break;
418
419 case TULIP_CHIP_21140:
420 if (sc->sc_rev < 0x11) {
421 printf("%s: 21140 must be at least pass 1.1\n",
422 sc->sc_dev.dv_xname);
423 return;
424 }
425 break;
426
427 default:
428 /* Nothing. */
429 }
430
431 sc->sc_dmat = pa->pa_dmat;
432
433 /*
434 * Make sure bus mastering is enabled.
435 */
436 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
437 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
438 PCI_COMMAND_MASTER_ENABLE);
439
440 /*
441 * Get the cacheline size.
442 */
443 sc->sc_cacheline = PCI_CACHELINE(pci_conf_read(pc, pa->pa_tag,
444 PCI_BHLC_REG));
445
446 /*
447 * Read the contents of the Ethernet Address ROM/SROM.
448 */
449 memset(sc->sc_srom, 0, sizeof(sc->sc_srom));
450 switch (sc->sc_chip) {
451 case TULIP_CHIP_21040:
452 TULIP_WRITE(sc, CSR_MIIROM, MIIROM_SROMCS);
453 for (i = 0; i < sizeof(sc->sc_srom); i++) {
454 for (j = 0; j < 10000; j++) {
455 val = TULIP_READ(sc, CSR_MIIROM);
456 if ((val & MIIROM_DN) == 0)
457 break;
458 }
459 sc->sc_srom[i] = val & MIIROM_DATA;
460 }
461 break;
462
463 case TULIP_CHIP_82C168:
464 case TULIP_CHIP_82C169:
465 {
466 u_int16_t *rombuf = (u_int16_t *)sc->sc_srom;
467
468 /*
469 * The Lite-On PNIC stores the Ethernet address in
470 * the first 3 words of the EEPROM. EEPROM access
471 * is not like the other Tulip chips.
472 */
473 for (i = 0; i < 3; i++) {
474 TULIP_WRITE(sc, CSR_PNIC_SROMCTL,
475 PNIC_SROMCTL_READ | i);
476 for (j = 0; j < 500; j++) {
477 delay(2);
478 val = TULIP_READ(sc, CSR_MIIROM);
479 if ((val & PNIC_MIIROM_BUSY) == 0)
480 break;
481 }
482 if (val & PNIC_MIIROM_BUSY) {
483 printf("%s: EEPROM timed out\n",
484 sc->sc_dev.dv_xname);
485 return;
486 }
487 rombuf[i] = bswap16(val & PNIC_MIIROM_DATA);
488 }
489 break;
490 }
491
492 default:
493 tlp_read_srom(sc, 0, sizeof(sc->sc_srom) >> 2,
494 (u_int16_t *)sc->sc_srom);
495 #if 0
496 printf("SROM CONTENTS:");
497 for (i = 0; i < sizeof(sc->sc_srom); i++) {
498 if ((i % 10) == 0)
499 printf("\n\t");
500 printf("0x%02x ", sc->sc_srom[i]);
501 }
502 printf("\n");
503 #endif
504 }
505
506 /*
507 * Deal with chip/board quirks. This includes setting up
508 * the mediasw, and extracting the Ethernet address from
509 * the rombuf.
510 */
511 switch (sc->sc_chip) {
512 case TULIP_CHIP_21040:
513 /* Check for a slaved ROM on a multi-port board. */
514 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
515 TULIP_PCI_SLAVEROM);
516 if (psc->sc_flags & TULIP_PCI_SLAVEROM)
517 memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom,
518 sizeof(sc->sc_srom));
519
520 /*
521 * Parse the Ethernet Address ROM.
522 */
523 if (tlp_parse_old_srom(sc, enaddr) == 0) {
524 printf("%s: unable to decode Ethernet Address ROM\n",
525 sc->sc_dev.dv_xname);
526 return;
527 }
528
529 /*
530 * If we have a slaved ROM, adjust the Ethernet address.
531 */
532 if (psc->sc_flags & TULIP_PCI_SLAVEROM)
533 enaddr[5] +=
534 sc->sc_devno - psc->sc_master->sc_tulip.sc_devno;
535
536 /*
537 * All 21040 boards start out with the same
538 * media switch.
539 */
540 sc->sc_mediasw = &tlp_21040_mediasw;
541
542 /*
543 * Deal with any quirks this board might have.
544 */
545 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21040_quirks);
546 break;
547
548 case TULIP_CHIP_21041:
549 /* Check for a slaved ROM on a multi-port board. */
550 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
551 TULIP_PCI_SLAVEROM);
552 if (psc->sc_flags & TULIP_PCI_SLAVEROM)
553 memcpy(sc->sc_srom, psc->sc_master->sc_tulip.sc_srom,
554 sizeof(sc->sc_srom));
555
556 /* Check for new format SROM. */
557 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
558 /*
559 * Not an ISV SROM; try the old DEC Ethernet Address
560 * ROM format.
561 */
562 if (tlp_parse_old_srom(sc, enaddr) == 0) {
563 printf("%s: unable to decode Ethernet "
564 "Address ROM\n", sc->sc_dev.dv_xname);
565 return;
566 }
567 }
568
569 /*
570 * All 21041 boards use the same media switch; they all
571 * work basically the same! Yippee!
572 */
573 sc->sc_mediasw = &tlp_21041_mediasw;
574
575 /*
576 * Deal with any quirks this board might have.
577 */
578 /* XXX */
579 break;
580
581 case TULIP_CHIP_82C168:
582 case TULIP_CHIP_82C169:
583 /*
584 * Lite-On PNIC's Ethernet address is the first 6
585 * bytes of its EEPROM.
586 */
587 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
588
589 /*
590 * Lite-On PNICs always use the same mediasw; we
591 * select MII vs. internal NWAY automatically.
592 */
593 sc->sc_mediasw = &tlp_pnic_mediasw;
594 break;
595
596 case TULIP_CHIP_WB89C840F:
597 /*
598 * Winbond 89C840F's Ethernet address is the first
599 * 6 bytes of its EEPROM.
600 */
601 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
602
603 /*
604 * Winbond 89C840F has an MII attached to the SIO.
605 */
606 sc->sc_mediasw = &tlp_sio_mii_mediasw;
607 break;
608
609 default:
610 printf("%s: sorry, unable to handle your board\n",
611 sc->sc_dev.dv_xname);
612 return;
613 }
614
615 /*
616 * Handle shared interrupts.
617 */
618 if (psc->sc_flags & TULIP_PCI_SHAREDINTR) {
619 if (psc->sc_master)
620 psc->sc_flags |= TULIP_PCI_SLAVEINTR;
621 else {
622 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDINTR,
623 TULIP_PCI_SLAVEINTR);
624 if (psc->sc_master == NULL)
625 psc->sc_master = psc;
626 }
627 LIST_INSERT_HEAD(&psc->sc_master->sc_intrslaves,
628 psc, sc_intrq);
629 }
630
631 if (psc->sc_flags & TULIP_PCI_SLAVEINTR) {
632 printf("%s: sharing interrupt with %s\n",
633 sc->sc_dev.dv_xname,
634 psc->sc_master->sc_tulip.sc_dev.dv_xname);
635 } else {
636 /*
637 * Map and establish our interrupt.
638 */
639 if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin,
640 pa->pa_intrline, &ih)) {
641 printf("%s: unable to map interrupt\n",
642 sc->sc_dev.dv_xname);
643 return;
644 }
645 intrstr = pci_intr_string(pc, ih);
646 psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET,
647 (psc->sc_flags & TULIP_PCI_SHAREDINTR) ?
648 tlp_pci_shared_intr : tlp_intr, sc);
649 if (psc->sc_ih == NULL) {
650 printf("%s: unable to establish interrupt",
651 sc->sc_dev.dv_xname);
652 if (intrstr != NULL)
653 printf(" at %s", intrstr);
654 printf("\n");
655 return;
656 }
657 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
658 intrstr);
659 }
660
661 /*
662 * Finish off the attach.
663 */
664 tlp_attach(sc, enaddr);
665 }
666
667 int
668 tlp_pci_shared_intr(arg)
669 void *arg;
670 {
671 struct tulip_pci_softc *master = arg, *slave;
672 int rv = 0;
673
674 for (slave = LIST_FIRST(&master->sc_intrslaves);
675 slave != NULL;
676 slave = LIST_NEXT(slave, sc_intrq))
677 rv |= tlp_intr(&slave->sc_tulip);
678
679 return (rv);
680 }
681
682 void
683 tlp_pci_znyx_21040_quirks(psc, enaddr)
684 struct tulip_pci_softc *psc;
685 const u_int8_t *enaddr;
686 {
687 struct tulip_softc *sc = &psc->sc_tulip;
688 u_int16_t id = 0;
689
690 /*
691 * If we have a slaved ROM, just copy the bits from the master.
692 * This is in case we fail the ROM ID check (older boards) and
693 * need to fall back on Ethernet address model checking; that
694 * will fail for slave chips.
695 */
696 if (psc->sc_flags & TULIP_PCI_SLAVEROM) {
697 strcpy(sc->sc_name, psc->sc_master->sc_tulip.sc_name);
698 sc->sc_mediasw = psc->sc_master->sc_tulip.sc_mediasw;
699 psc->sc_flags |=
700 psc->sc_master->sc_flags & TULIP_PCI_SHAREDINTR;
701 return;
702 }
703
704 if (sc->sc_srom[32] == 0x4a && sc->sc_srom[33] == 0x52) {
705 id = sc->sc_srom[37] | (sc->sc_srom[36] << 8);
706 switch (id) {
707 zx312:
708 case 0x0602: /* ZX312 */
709 strcpy(sc->sc_name, "ZNYX ZX312");
710 return;
711
712 case 0x0622: /* ZX312T */
713 strcpy(sc->sc_name, "ZNYX ZX312T");
714 sc->sc_mediasw = &tlp_21040_tp_mediasw;
715 return;
716
717 zx314_inta:
718 case 0x0701: /* ZX314 INTA */
719 psc->sc_flags |= TULIP_PCI_SHAREDINTR;
720 /* FALLTHROUGH */
721 case 0x0711: /* ZX314 */
722 strcpy(sc->sc_name, "ZNYX ZX314");
723 psc->sc_flags |= TULIP_PCI_SHAREDROM;
724 sc->sc_mediasw = &tlp_21040_tp_mediasw;
725 return;
726
727 zx315_inta:
728 case 0x0801: /* ZX315 INTA */
729 psc->sc_flags |= TULIP_PCI_SHAREDINTR;
730 /* FALLTHROUGH */
731 case 0x0811: /* ZX315 */
732 strcpy(sc->sc_name, "ZNYX ZX315");
733 psc->sc_flags |= TULIP_PCI_SHAREDROM;
734 return;
735
736 default:
737 id = 0;
738 }
739 }
740
741 /*
742 * Deal with boards that have broken ROMs.
743 */
744 if (id == 0) {
745 if ((enaddr[3] & ~3) == 0xf0 && (enaddr[5] & 3) == 0x00)
746 goto zx314_inta;
747 if ((enaddr[3] & ~3) == 0xf4 && (enaddr[5] & 1) == 0x00)
748 goto zx315_inta;
749 if ((enaddr[3] & ~3) == 0xec)
750 goto zx312;
751 }
752
753 strcpy(sc->sc_name, "ZNYX ZX31x");
754 }
755
756 void
757 tlp_pci_smc_21040_quirks(psc, enaddr)
758 struct tulip_pci_softc *psc;
759 const u_int8_t *enaddr;
760 {
761 struct tulip_softc *sc = &psc->sc_tulip;
762 u_int16_t id1, id2, ei;
763 int auibnc = 0, utp = 0;
764 char *cp;
765
766 id1 = sc->sc_srom[0x60] | (sc->sc_srom[0x61] << 8);
767 id2 = sc->sc_srom[0x62] | (sc->sc_srom[0x63] << 8);
768 ei = sc->sc_srom[0x66] | (sc->sc_srom[0x67] << 8);
769
770 strcpy(sc->sc_name, "SMC 8432");
771 cp = &sc->sc_name[8];
772
773 if ((id1 & 1) == 0) {
774 *cp++ = 'B';
775 auibnc = 1;
776 }
777 if ((id1 & 0xff) > 0x32) {
778 *cp++ = 'T';
779 utp = 1;
780 }
781 if ((id1 & 0x4000) == 0) {
782 *cp++ = 'A';
783 auibnc = 1;
784 }
785 if (id2 == 0x15) {
786 sc->sc_name[7] = '4';
787 *cp++ = '-';
788 *cp++ = 'C';
789 *cp++ = 'H';
790 *cp++ = ei ? '2' : '1';
791 }
792 *cp = '\0';
793
794 if (utp != 0 && auibnc == 0)
795 sc->sc_mediasw = &tlp_21040_tp_mediasw;
796 else if (utp == 0 && auibnc != 0)
797 sc->sc_mediasw = &tlp_21040_auibnc_mediasw;
798 }
799
800 void
801 tlp_pci_cogent_21040_quirks(psc, enaddr)
802 struct tulip_pci_softc *psc;
803 const u_int8_t *enaddr;
804 {
805
806 strcpy(psc->sc_tulip.sc_name, "Cogent multi-port");
807 psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
808 }
809
810 void
811 tlp_pci_accton_21040_quirks(psc, enaddr)
812 struct tulip_pci_softc *psc;
813 const u_int8_t *enaddr;
814 {
815
816 strcpy(psc->sc_tulip.sc_name, "ACCTON EN1203");
817 }
818