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