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