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