if_tlp_pci.c revision 1.84.6.1 1 /* $NetBSD: if_tlp_pci.c,v 1.84.6.1 2006/04/22 11:39:14 simonb Exp $ */
2
3 /*-
4 * Copyright (c) 1998, 1999, 2000, 2002 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; and Charles M. Hannum.
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 <sys/cdefs.h>
46 __KERNEL_RCSID(0, "$NetBSD: if_tlp_pci.c,v 1.84.6.1 2006/04/22 11:39:14 simonb Exp $");
47
48 #include <sys/param.h>
49 #include <sys/systm.h>
50 #include <sys/mbuf.h>
51 #include <sys/malloc.h>
52 #include <sys/kernel.h>
53 #include <sys/socket.h>
54 #include <sys/ioctl.h>
55 #include <sys/errno.h>
56 #include <sys/device.h>
57
58 #include <machine/endian.h>
59
60 #include <net/if.h>
61 #include <net/if_dl.h>
62 #include <net/if_media.h>
63 #include <net/if_ether.h>
64
65 #include <machine/bus.h>
66 #include <machine/intr.h>
67 #ifdef __sparc__
68 #include <machine/promlib.h>
69 #endif
70
71 #include <dev/mii/miivar.h>
72 #include <dev/mii/mii_bitbang.h>
73
74 #include <dev/ic/tulipreg.h>
75 #include <dev/ic/tulipvar.h>
76
77 #include <dev/pci/pcivar.h>
78 #include <dev/pci/pcireg.h>
79 #include <dev/pci/pcidevs.h>
80
81 /*
82 * PCI configuration space registers used by the Tulip.
83 */
84 #define TULIP_PCI_IOBA 0x10 /* i/o mapped base */
85 #define TULIP_PCI_MMBA 0x14 /* memory mapped base */
86 #define TULIP_PCI_CFDA 0x40 /* configuration driver area */
87
88 #define CFDA_SLEEP 0x80000000 /* sleep mode */
89 #define CFDA_SNOOZE 0x40000000 /* snooze mode */
90
91 struct tulip_pci_softc {
92 struct tulip_softc sc_tulip; /* real Tulip softc */
93
94 /* PCI-specific goo. */
95 void *sc_ih; /* interrupt handle */
96
97 pci_chipset_tag_t sc_pc; /* our PCI chipset */
98 pcitag_t sc_pcitag; /* our PCI tag */
99
100 int sc_flags; /* flags; see below */
101
102 LIST_HEAD(, tulip_pci_softc) sc_intrslaves;
103 LIST_ENTRY(tulip_pci_softc) sc_intrq;
104
105 /* Our {ROM,interrupt} master. */
106 struct tulip_pci_softc *sc_master;
107 };
108
109 /* sc_flags */
110 #define TULIP_PCI_SHAREDINTR 0x01 /* interrupt is shared */
111 #define TULIP_PCI_SLAVEINTR 0x02 /* interrupt is slave */
112 #define TULIP_PCI_SHAREDROM 0x04 /* ROM is shared */
113 #define TULIP_PCI_SLAVEROM 0x08 /* slave of shared ROM */
114
115 static int tlp_pci_match(struct device *, struct cfdata *, void *);
116 static void tlp_pci_attach(struct device *, struct device *, void *);
117
118 CFATTACH_DECL(tlp_pci, sizeof(struct tulip_pci_softc),
119 tlp_pci_match, tlp_pci_attach, NULL, NULL);
120
121 static const struct tulip_pci_product {
122 u_int32_t tpp_vendor; /* PCI vendor ID */
123 u_int32_t tpp_product; /* PCI product ID */
124 tulip_chip_t tpp_chip; /* base Tulip chip type */
125 } tlp_pci_products[] = {
126 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21040,
127 TULIP_CHIP_21040 },
128 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21041,
129 TULIP_CHIP_21041 },
130 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21140,
131 TULIP_CHIP_21140 },
132 { PCI_VENDOR_DEC, PCI_PRODUCT_DEC_21142,
133 TULIP_CHIP_21142 },
134
135 { PCI_VENDOR_LITEON, PCI_PRODUCT_LITEON_82C168,
136 TULIP_CHIP_82C168 },
137
138 /*
139 * Note: This is like a MX98725 with Wake-On-LAN and a
140 * 128-bit multicast hash table.
141 */
142 { PCI_VENDOR_LITEON, PCI_PRODUCT_LITEON_82C115,
143 TULIP_CHIP_82C115 },
144
145 { PCI_VENDOR_MACRONIX, PCI_PRODUCT_MACRONIX_MX98713,
146 TULIP_CHIP_MX98713 },
147 { PCI_VENDOR_MACRONIX, PCI_PRODUCT_MACRONIX_MX987x5,
148 TULIP_CHIP_MX98715 },
149
150 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_RL100TX,
151 TULIP_CHIP_MX98713 },
152
153 { PCI_VENDOR_WINBOND, PCI_PRODUCT_WINBOND_W89C840F,
154 TULIP_CHIP_WB89C840F },
155 { PCI_VENDOR_COMPEX, PCI_PRODUCT_COMPEX_RL100ATX,
156 TULIP_CHIP_WB89C840F },
157
158 { PCI_VENDOR_DAVICOM, PCI_PRODUCT_DAVICOM_DM9102,
159 TULIP_CHIP_DM9102 },
160
161 { PCI_VENDOR_ADMTEK, PCI_PRODUCT_ADMTEK_AL981,
162 TULIP_CHIP_AL981 },
163
164 { PCI_VENDOR_ADMTEK, PCI_PRODUCT_ADMTEK_AN985,
165 TULIP_CHIP_AN985 },
166 { PCI_VENDOR_ACCTON, PCI_PRODUCT_ACCTON_EN2242,
167 TULIP_CHIP_AN985 },
168
169 { PCI_VENDOR_3COM, PCI_PRODUCT_3COM_3C910SOHOB,
170 TULIP_CHIP_AN985 },
171
172 { PCI_VENDOR_ASIX, PCI_PRODUCT_ASIX_AX88140A,
173 TULIP_CHIP_AX88140 },
174
175 { PCI_VENDOR_CONEXANT, PCI_PRODUCT_CONEXANT_LANFINITY,
176 TULIP_CHIP_RS7112 },
177
178 { 0, 0,
179 TULIP_CHIP_INVALID },
180 };
181
182 struct tlp_pci_quirks {
183 void (*tpq_func)(struct tulip_pci_softc *,
184 const u_int8_t *);
185 u_int8_t tpq_oui[3];
186 };
187
188 static void tlp_pci_dec_quirks(struct tulip_pci_softc *,
189 const u_int8_t *);
190
191 static void tlp_pci_znyx_21040_quirks(struct tulip_pci_softc *,
192 const u_int8_t *);
193 static void tlp_pci_smc_21040_quirks(struct tulip_pci_softc *,
194 const u_int8_t *);
195 static void tlp_pci_cogent_21040_quirks(struct tulip_pci_softc *,
196 const u_int8_t *);
197 static void tlp_pci_accton_21040_quirks(struct tulip_pci_softc *,
198 const u_int8_t *);
199
200 static void tlp_pci_cobalt_21142_quirks(struct tulip_pci_softc *,
201 const u_int8_t *);
202 static void tlp_pci_algor_21142_quirks(struct tulip_pci_softc *,
203 const u_int8_t *);
204 static void tlp_pci_netwinder_21142_quirks(struct tulip_pci_softc *,
205 const u_int8_t *);
206 static void tlp_pci_znyx_21142_quirks(struct tulip_pci_softc *,
207 const u_int8_t *);
208
209 static void tlp_pci_adaptec_quirks(struct tulip_pci_softc *,
210 const u_int8_t *);
211
212 static const struct tlp_pci_quirks tlp_pci_21040_quirks[] = {
213 { tlp_pci_znyx_21040_quirks, { 0x00, 0xc0, 0x95 } },
214 { tlp_pci_smc_21040_quirks, { 0x00, 0x00, 0xc0 } },
215 { tlp_pci_cogent_21040_quirks, { 0x00, 0x00, 0x92 } },
216 { tlp_pci_accton_21040_quirks, { 0x00, 0x00, 0xe8 } },
217 { NULL, { 0, 0, 0 } }
218 };
219
220 static const struct tlp_pci_quirks tlp_pci_21041_quirks[] = {
221 { tlp_pci_dec_quirks, { 0x08, 0x00, 0x2b } },
222 { tlp_pci_dec_quirks, { 0x00, 0x00, 0xf8 } },
223 { NULL, { 0, 0, 0 } }
224 };
225
226 static void tlp_pci_asante_21140_quirks(struct tulip_pci_softc *,
227 const u_int8_t *);
228 static void tlp_pci_smc_21140_quirks(struct tulip_pci_softc *,
229 const u_int8_t *);
230 static void tlp_pci_vpc_21140_quirks(struct tulip_pci_softc *,
231 const u_int8_t *);
232
233 static const struct tlp_pci_quirks tlp_pci_21140_quirks[] = {
234 { tlp_pci_dec_quirks, { 0x08, 0x00, 0x2b } },
235 { tlp_pci_dec_quirks, { 0x00, 0x00, 0xf8 } },
236 { tlp_pci_asante_21140_quirks, { 0x00, 0x00, 0x94 } },
237 { tlp_pci_adaptec_quirks, { 0x00, 0x00, 0x92 } },
238 { tlp_pci_adaptec_quirks, { 0x00, 0x00, 0xd1 } },
239 { tlp_pci_smc_21140_quirks, { 0x00, 0x00, 0xc0 } },
240 { tlp_pci_vpc_21140_quirks, { 0x00, 0x03, 0xff } },
241 { NULL, { 0, 0, 0 } }
242 };
243
244 static const struct tlp_pci_quirks tlp_pci_21142_quirks[] = {
245 { tlp_pci_dec_quirks, { 0x08, 0x00, 0x2b } },
246 { tlp_pci_dec_quirks, { 0x00, 0x00, 0xf8 } },
247 { tlp_pci_cobalt_21142_quirks, { 0x00, 0x10, 0xe0 } },
248 { tlp_pci_algor_21142_quirks, { 0x00, 0x40, 0xbc } },
249 { tlp_pci_adaptec_quirks, { 0x00, 0x00, 0xd1 } },
250 { tlp_pci_netwinder_21142_quirks,{ 0x00, 0x10, 0x57 } },
251 { tlp_pci_znyx_21142_quirks, { 0x00, 0xc0, 0x95 } },
252 { NULL, { 0, 0, 0 } }
253 };
254
255 static int tlp_pci_shared_intr(void *);
256
257 static const struct tulip_pci_product *
258 tlp_pci_lookup(const struct pci_attach_args *pa)
259 {
260 const struct tulip_pci_product *tpp;
261
262 /* Don't match lmc cards */
263 if (PCI_VENDOR(pci_conf_read(pa->pa_pc, pa->pa_tag,
264 PCI_SUBSYS_ID_REG)) == PCI_VENDOR_LMC)
265 return 0;
266
267 for (tpp = tlp_pci_products;
268 tlp_chip_names[tpp->tpp_chip] != NULL;
269 tpp++) {
270 if (PCI_VENDOR(pa->pa_id) == tpp->tpp_vendor &&
271 PCI_PRODUCT(pa->pa_id) == tpp->tpp_product)
272 return (tpp);
273 }
274 return (NULL);
275 }
276
277 static void
278 tlp_pci_get_quirks(struct tulip_pci_softc *psc, 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 static void
293 tlp_pci_check_slaved(struct tulip_pci_softc *psc, int shared, int 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 (device_parent(&cur->sc_tulip.sc_dev) !=
308 device_parent(&sc->sc_dev))
309 continue;
310 if ((cur->sc_flags & shared) == 0)
311 continue;
312 if (cur == psc)
313 continue;
314 if (best == NULL ||
315 best->sc_tulip.sc_devno > cur->sc_tulip.sc_devno)
316 best = cur;
317 }
318
319 if (best != NULL) {
320 psc->sc_master = best;
321 psc->sc_flags |= (shared | slaved);
322 }
323 }
324
325 static int
326 tlp_pci_match(struct device *parent, struct cfdata *match, void *aux)
327 {
328 struct pci_attach_args *pa = aux;
329
330 if (tlp_pci_lookup(pa) != NULL)
331 return (10); /* beat if_de.c */
332
333 return (0);
334 }
335
336 static void
337 tlp_pci_attach(struct device *parent, struct device *self, void *aux)
338 {
339 struct tulip_pci_softc *psc = (void *) self;
340 struct tulip_softc *sc = &psc->sc_tulip;
341 struct pci_attach_args *pa = aux;
342 pci_chipset_tag_t pc = pa->pa_pc;
343 pci_intr_handle_t ih;
344 const char *intrstr = NULL;
345 bus_space_tag_t iot, memt;
346 bus_space_handle_t ioh, memh;
347 int ioh_valid, memh_valid, i, j;
348 const struct tulip_pci_product *tpp;
349 u_int8_t enaddr[ETHER_ADDR_LEN];
350 u_int32_t val = 0;
351 pcireg_t reg;
352 int pmreg;
353
354 sc->sc_devno = pa->pa_device;
355 psc->sc_pc = pa->pa_pc;
356 psc->sc_pcitag = pa->pa_tag;
357
358 LIST_INIT(&psc->sc_intrslaves);
359
360 tpp = tlp_pci_lookup(pa);
361 if (tpp == NULL) {
362 printf("\n");
363 panic("tlp_pci_attach: impossible");
364 }
365 sc->sc_chip = tpp->tpp_chip;
366
367 /*
368 * By default, Tulip registers are 8 bytes long (4 bytes
369 * followed by a 4 byte pad).
370 */
371 sc->sc_regshift = 3;
372
373 /*
374 * No power management hooks.
375 * XXX Maybe we should add some!
376 */
377 sc->sc_flags |= TULIPF_ENABLED;
378
379 /*
380 * Get revision info, and set some chip-specific variables.
381 */
382 sc->sc_rev = PCI_REVISION(pa->pa_class);
383 switch (sc->sc_chip) {
384 case TULIP_CHIP_21140:
385 if (sc->sc_rev >= 0x20)
386 sc->sc_chip = TULIP_CHIP_21140A;
387 break;
388
389 case TULIP_CHIP_21142:
390 if (sc->sc_rev >= 0x20)
391 sc->sc_chip = TULIP_CHIP_21143;
392 break;
393
394 case TULIP_CHIP_82C168:
395 if (sc->sc_rev >= 0x20)
396 sc->sc_chip = TULIP_CHIP_82C169;
397 break;
398
399 case TULIP_CHIP_MX98713:
400 if (sc->sc_rev >= 0x10)
401 sc->sc_chip = TULIP_CHIP_MX98713A;
402 break;
403
404 case TULIP_CHIP_MX98715:
405 if (sc->sc_rev >= 0x20)
406 sc->sc_chip = TULIP_CHIP_MX98715A;
407 if (sc->sc_rev >= 0x25)
408 sc->sc_chip = TULIP_CHIP_MX98715AEC_X;
409 if (sc->sc_rev >= 0x30)
410 sc->sc_chip = TULIP_CHIP_MX98725;
411 break;
412
413 case TULIP_CHIP_WB89C840F:
414 sc->sc_regshift = 2;
415 break;
416
417 case TULIP_CHIP_AN985:
418 /*
419 * The AN983 and AN985 are very similar, and are
420 * differentiated by a "signature" register that
421 * is like, but not identical, to a PCI ID register.
422 */
423 reg = pci_conf_read(pc, pa->pa_tag, 0x80);
424 switch (reg) {
425 case 0x09811317:
426 sc->sc_chip = TULIP_CHIP_AN985;
427 break;
428
429 case 0x09851317:
430 sc->sc_chip = TULIP_CHIP_AN983;
431 break;
432
433 default:
434 /* Unknown -- use default. */
435 break;
436 }
437 break;
438
439 case TULIP_CHIP_AX88140:
440 if (sc->sc_rev >= 0x10)
441 sc->sc_chip = TULIP_CHIP_AX88141;
442 break;
443
444 case TULIP_CHIP_DM9102:
445 if (sc->sc_rev >= 0x30)
446 sc->sc_chip = TULIP_CHIP_DM9102A;
447 break;
448
449 default:
450 /* Nothing. */
451 break;
452 }
453
454 printf(": %s Ethernet, pass %d.%d\n",
455 tlp_chip_names[sc->sc_chip],
456 (sc->sc_rev >> 4) & 0xf, sc->sc_rev & 0xf);
457
458 switch (sc->sc_chip) {
459 case TULIP_CHIP_21040:
460 if (sc->sc_rev < 0x20) {
461 printf("%s: 21040 must be at least pass 2.0\n",
462 sc->sc_dev.dv_xname);
463 return;
464 }
465 break;
466
467 case TULIP_CHIP_21140:
468 if (sc->sc_rev < 0x11) {
469 printf("%s: 21140 must be at least pass 1.1\n",
470 sc->sc_dev.dv_xname);
471 return;
472 }
473 break;
474
475 default:
476 /* Nothing. */
477 break;
478 }
479
480 /*
481 * Check to see if the device is in power-save mode, and
482 * being it out if necessary.
483 */
484 switch (sc->sc_chip) {
485 case TULIP_CHIP_21140:
486 case TULIP_CHIP_21140A:
487 case TULIP_CHIP_21142:
488 case TULIP_CHIP_21143:
489 case TULIP_CHIP_MX98713A:
490 case TULIP_CHIP_MX98715:
491 case TULIP_CHIP_MX98715A:
492 case TULIP_CHIP_MX98715AEC_X:
493 case TULIP_CHIP_MX98725:
494 case TULIP_CHIP_DM9102:
495 case TULIP_CHIP_DM9102A:
496 case TULIP_CHIP_AX88140:
497 case TULIP_CHIP_AX88141:
498 case TULIP_CHIP_RS7112:
499 /*
500 * Clear the "sleep mode" bit in the CFDA register.
501 */
502 reg = pci_conf_read(pc, pa->pa_tag, TULIP_PCI_CFDA);
503 if (reg & (CFDA_SLEEP|CFDA_SNOOZE))
504 pci_conf_write(pc, pa->pa_tag, TULIP_PCI_CFDA,
505 reg & ~(CFDA_SLEEP|CFDA_SNOOZE));
506 break;
507
508 default:
509 /* Nothing. */
510 break;
511 }
512
513 if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PWRMGMT, &pmreg, 0)) {
514 reg = pci_conf_read(pc, pa->pa_tag, pmreg + PCI_PMCSR);
515 switch (reg & PCI_PMCSR_STATE_MASK) {
516 case PCI_PMCSR_STATE_D1:
517 case PCI_PMCSR_STATE_D2:
518 printf("%s: waking up from power state D%d\n%s",
519 sc->sc_dev.dv_xname,
520 reg & PCI_PMCSR_STATE_MASK, sc->sc_dev.dv_xname);
521 pci_conf_write(pc, pa->pa_tag, pmreg + PCI_PMCSR,
522 (reg & ~PCI_PMCSR_STATE_MASK) |
523 PCI_PMCSR_STATE_D0);
524 break;
525 case PCI_PMCSR_STATE_D3:
526 /*
527 * The card has lost all configuration data in
528 * this state, so punt.
529 */
530 printf("%s: unable to wake up from power state D3, "
531 "reboot required.\n", sc->sc_dev.dv_xname);
532 pci_conf_write(pc, pa->pa_tag, pmreg + PCI_PMCSR,
533 (reg & ~PCI_PMCSR_STATE_MASK) |
534 PCI_PMCSR_STATE_D0);
535 return;
536 }
537 }
538
539 /*
540 * Map the device.
541 */
542 ioh_valid = (pci_mapreg_map(pa, TULIP_PCI_IOBA,
543 PCI_MAPREG_TYPE_IO, 0,
544 &iot, &ioh, NULL, NULL) == 0);
545 memh_valid = (pci_mapreg_map(pa, TULIP_PCI_MMBA,
546 PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT, 0,
547 &memt, &memh, NULL, NULL) == 0);
548
549 if (memh_valid) {
550 sc->sc_st = memt;
551 sc->sc_sh = memh;
552 } else if (ioh_valid) {
553 sc->sc_st = iot;
554 sc->sc_sh = ioh;
555 } else {
556 printf("%s: unable to map device registers\n",
557 sc->sc_dev.dv_xname);
558 return;
559 }
560
561 sc->sc_dmat = pa->pa_dmat;
562
563 /*
564 * Make sure bus mastering is enabled.
565 */
566 pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
567 pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG) |
568 PCI_COMMAND_MASTER_ENABLE);
569
570 /*
571 * Get the cacheline size.
572 */
573 sc->sc_cacheline = PCI_CACHELINE(pci_conf_read(pc, pa->pa_tag,
574 PCI_BHLC_REG));
575
576 /*
577 * Get PCI data moving command info.
578 */
579 if (pa->pa_flags & PCI_FLAGS_MRL_OKAY)
580 sc->sc_flags |= TULIPF_MRL;
581 if (pa->pa_flags & PCI_FLAGS_MRM_OKAY)
582 sc->sc_flags |= TULIPF_MRM;
583 if (pa->pa_flags & PCI_FLAGS_MWI_OKAY)
584 sc->sc_flags |= TULIPF_MWI;
585
586 /*
587 * Read the contents of the Ethernet Address ROM/SROM.
588 */
589 switch (sc->sc_chip) {
590 case TULIP_CHIP_21040:
591 sc->sc_srom_addrbits = 6;
592 sc->sc_srom = malloc(TULIP_ROM_SIZE(6), M_DEVBUF, M_NOWAIT);
593 TULIP_WRITE(sc, CSR_MIIROM, MIIROM_SROMCS);
594 for (i = 0; i < TULIP_ROM_SIZE(6); i++) {
595 for (j = 0; j < 10000; j++) {
596 val = TULIP_READ(sc, CSR_MIIROM);
597 if ((val & MIIROM_DN) == 0)
598 break;
599 }
600 sc->sc_srom[i] = val & MIIROM_DATA;
601 }
602 break;
603
604 case TULIP_CHIP_82C168:
605 case TULIP_CHIP_82C169:
606 {
607 sc->sc_srom_addrbits = 2;
608 sc->sc_srom = malloc(TULIP_ROM_SIZE(2), M_DEVBUF, M_NOWAIT);
609
610 /*
611 * The Lite-On PNIC stores the Ethernet address in
612 * the first 3 words of the EEPROM. EEPROM access
613 * is not like the other Tulip chips.
614 */
615 for (i = 0; i < 6; i += 2) {
616 TULIP_WRITE(sc, CSR_PNIC_SROMCTL,
617 PNIC_SROMCTL_READ | (i >> 1));
618 for (j = 0; j < 500; j++) {
619 delay(2);
620 val = TULIP_READ(sc, CSR_MIIROM);
621 if ((val & PNIC_MIIROM_BUSY) == 0)
622 break;
623 }
624 if (val & PNIC_MIIROM_BUSY) {
625 printf("%s: EEPROM timed out\n",
626 sc->sc_dev.dv_xname);
627 return;
628 }
629 val &= PNIC_MIIROM_DATA;
630 sc->sc_srom[i] = val >> 8;
631 sc->sc_srom[i + 1] = val & 0xff;
632 }
633 break;
634 }
635
636 default:
637 /*
638 * XXX This isn't quite the right way to do this; we should
639 * XXX be attempting to fetch the mac-addr property in the
640 * XXX bus-agnostic part of the driver independently. But
641 * XXX that requires a larger change in the SROM handling
642 * XXX logic, and for now we can at least remove a machine-
643 * XXX dependent wart from the PCI front-end.
644 */
645 if (devprop_get(&sc->sc_dev, "mac-addr",
646 enaddr, sizeof(enaddr), NULL) == sizeof(enaddr)) {
647 extern int tlp_srom_debug;
648 sc->sc_srom_addrbits = 6;
649 sc->sc_srom = malloc(TULIP_ROM_SIZE(6), M_DEVBUF,
650 M_NOWAIT|M_ZERO);
651 memcpy(sc->sc_srom, enaddr, sizeof(enaddr));
652 if (tlp_srom_debug) {
653 printf("SROM CONTENTS:");
654 for (i = 0; i < TULIP_ROM_SIZE(6); i++) {
655 if ((i % 8) == 0)
656 printf("\n\t");
657 printf("0x%02x ", sc->sc_srom[i]);
658 }
659 printf("\n");
660 }
661 break;
662 }
663
664 /* Check for a slaved ROM on a multi-port board. */
665 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDROM,
666 TULIP_PCI_SLAVEROM);
667 if (psc->sc_flags & TULIP_PCI_SLAVEROM) {
668 sc->sc_srom_addrbits =
669 psc->sc_master->sc_tulip.sc_srom_addrbits;
670 sc->sc_srom = psc->sc_master->sc_tulip.sc_srom;
671 enaddr[5] +=
672 sc->sc_devno - psc->sc_master->sc_tulip.sc_devno;
673 }
674 else if (tlp_read_srom(sc) == 0)
675 goto cant_cope;
676 break;
677 }
678
679 /*
680 * Deal with chip/board quirks. This includes setting up
681 * the mediasw, and extracting the Ethernet address from
682 * the rombuf.
683 */
684 switch (sc->sc_chip) {
685 case TULIP_CHIP_21040:
686 /*
687 * Parse the Ethernet Address ROM.
688 */
689 if (tlp_parse_old_srom(sc, enaddr) == 0)
690 goto cant_cope;
691
692
693 /*
694 * All 21040 boards start out with the same
695 * media switch.
696 */
697 sc->sc_mediasw = &tlp_21040_mediasw;
698
699 /*
700 * Deal with any quirks this board might have.
701 */
702 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21040_quirks);
703 break;
704
705 case TULIP_CHIP_21041:
706 /* Check for new format SROM. */
707 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
708 /*
709 * Not an ISV SROM; try the old DEC Ethernet Address
710 * ROM format.
711 */
712 if (tlp_parse_old_srom(sc, enaddr) == 0)
713 goto cant_cope;
714 }
715
716 /*
717 * All 21041 boards use the same media switch; they all
718 * work basically the same! Yippee!
719 */
720 sc->sc_mediasw = &tlp_21041_mediasw;
721
722 /*
723 * Deal with any quirks this board might have.
724 */
725 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21041_quirks);
726 break;
727
728 case TULIP_CHIP_21140:
729 case TULIP_CHIP_21140A:
730 /* Check for new format SROM. */
731 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
732 /*
733 * Not an ISV SROM; try the old DEC Ethernet Address
734 * ROM format.
735 */
736 if (tlp_parse_old_srom(sc, enaddr) == 0)
737 goto cant_cope;
738 } else {
739 /*
740 * We start out with the 2114x ISV media switch.
741 * When we search for quirks, we may change to
742 * a different switch.
743 */
744 sc->sc_mediasw = &tlp_2114x_isv_mediasw;
745 }
746
747 /*
748 * Deal with any quirks this board might have.
749 */
750 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21140_quirks);
751
752 /*
753 * Bail out now if we can't deal with this board.
754 */
755 if (sc->sc_mediasw == NULL)
756 goto cant_cope;
757 break;
758
759 case TULIP_CHIP_21142:
760 case TULIP_CHIP_21143:
761 /* Check for new format SROM. */
762 if (tlp_isv_srom_enaddr(sc, enaddr) == 0) {
763 /*
764 * Not an ISV SROM; try the old DEC Ethernet Address
765 * ROM format.
766 */
767 if (tlp_parse_old_srom(sc, enaddr) == 0) {
768 /*
769 * One last try: just copy the address
770 * from offset 20 and try to look
771 * up quirks.
772 */
773 memcpy(enaddr, &sc->sc_srom[20],
774 ETHER_ADDR_LEN);
775 }
776 } else {
777 /*
778 * We start out with the 2114x ISV media switch.
779 * When we search for quirks, we may change to
780 * a different switch.
781 */
782 sc->sc_mediasw = &tlp_2114x_isv_mediasw;
783 }
784
785 /*
786 * Deal with any quirks this board might have.
787 */
788 tlp_pci_get_quirks(psc, enaddr, tlp_pci_21142_quirks);
789
790 /*
791 * Bail out now if we can't deal with this board.
792 */
793 if (sc->sc_mediasw == NULL)
794 goto cant_cope;
795 break;
796
797 case TULIP_CHIP_82C168:
798 case TULIP_CHIP_82C169:
799 /*
800 * Lite-On PNIC's Ethernet address is the first 6
801 * bytes of its EEPROM.
802 */
803 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
804
805 /*
806 * Lite-On PNICs always use the same mediasw; we
807 * select MII vs. internal NWAY automatically.
808 */
809 sc->sc_mediasw = &tlp_pnic_mediasw;
810 break;
811
812 case TULIP_CHIP_MX98713:
813 /*
814 * The Macronix MX98713 has an MII and GPIO, but no
815 * internal Nway block. This chip is basically a
816 * perfect 21140A clone, with the exception of the
817 * a magic register frobbing in order to make the
818 * interface function.
819 */
820 if (tlp_isv_srom_enaddr(sc, enaddr)) {
821 sc->sc_mediasw = &tlp_2114x_isv_mediasw;
822 break;
823 }
824 /* FALLTHROUGH */
825
826 case TULIP_CHIP_82C115:
827 /*
828 * Yippee! The Lite-On 82C115 is a clone of
829 * the MX98725 (the data sheet even says `MXIC'
830 * on it)! Imagine that, a clone of a clone.
831 *
832 * The differences are really minimal:
833 *
834 * - Wake-On-LAN support
835 * - 128-bit multicast hash table, rather than
836 * the standard 512-bit hash table
837 */
838 /* FALLTHROUGH */
839
840 case TULIP_CHIP_MX98713A:
841 case TULIP_CHIP_MX98715A:
842 case TULIP_CHIP_MX98715AEC_X:
843 case TULIP_CHIP_MX98725:
844 /*
845 * The MX98713A has an MII as well as an internal Nway block,
846 * but no GPIO. The MX98715 and MX98725 have an internal
847 * Nway block only.
848 *
849 * The internal Nway block, unlike the Lite-On PNIC's, does
850 * just that - performs Nway. Once autonegotiation completes,
851 * we must program the GPR media information into the chip.
852 *
853 * The byte offset of the Ethernet address is stored at
854 * offset 0x70.
855 */
856 memcpy(enaddr, &sc->sc_srom[sc->sc_srom[0x70]], ETHER_ADDR_LEN);
857 sc->sc_mediasw = &tlp_pmac_mediasw;
858 break;
859
860 case TULIP_CHIP_WB89C840F:
861 /*
862 * Winbond 89C840F's Ethernet address is the first
863 * 6 bytes of its EEPROM.
864 */
865 memcpy(enaddr, sc->sc_srom, ETHER_ADDR_LEN);
866
867 /*
868 * Winbond 89C840F has an MII attached to the SIO.
869 */
870 sc->sc_mediasw = &tlp_sio_mii_mediasw;
871 break;
872
873 case TULIP_CHIP_AL981:
874 /*
875 * The ADMtek AL981's Ethernet address is located
876 * at offset 8 of its EEPROM.
877 */
878 memcpy(enaddr, &sc->sc_srom[8], ETHER_ADDR_LEN);
879
880 /*
881 * ADMtek AL981 has a built-in PHY accessed through
882 * special registers.
883 */
884 sc->sc_mediasw = &tlp_al981_mediasw;
885 break;
886
887 case TULIP_CHIP_AN983:
888 case TULIP_CHIP_AN985:
889 /*
890 * The ADMtek AN985's Ethernet address is located
891 * at offset 8 of its EEPROM.
892 */
893 memcpy(enaddr, &sc->sc_srom[8], ETHER_ADDR_LEN);
894
895 /*
896 * The ADMtek AN985 can be configured in Single-Chip
897 * mode or MAC-only mode. Single-Chip uses the built-in
898 * PHY, MAC-only has an external PHY (usually HomePNA).
899 * The selection is based on an EEPROM setting, and both
900 * PHYs are accessed via MII attached to SIO.
901 *
902 * The AN985 "ghosts" the internal PHY onto all
903 * MII addresses, so we have to use a media init
904 * routine that limits the search.
905 * XXX How does this work with MAC-only mode?
906 */
907 sc->sc_mediasw = &tlp_an985_mediasw;
908 break;
909
910 case TULIP_CHIP_DM9102:
911 case TULIP_CHIP_DM9102A:
912 /*
913 * Some boards with the Davicom chip have an ISV
914 * SROM (mostly DM9102A boards -- trying to describe
915 * the HomePNA PHY, probably) although the data in
916 * them is generally wrong. Check for ISV format
917 * and grab the Ethernet address that way, and if
918 * that fails, fall back on grabbing it from an
919 * observed offset of 20 (which is where it would
920 * be in an ISV SROM anyhow, tho ISV can cope with
921 * multi-port boards).
922 */
923 if (!tlp_isv_srom_enaddr(sc, enaddr)) {
924 #ifdef __sparc__
925 if ((sc->sc_srom[20] == 0 &&
926 sc->sc_srom[21] == 0 &&
927 sc->sc_srom[22] == 0) ||
928 (sc->sc_srom[20] == 0xff &&
929 sc->sc_srom[21] == 0xff &&
930 sc->sc_srom[22] == 0xff)) {
931 prom_getether(PCITAG_NODE(pa->pa_tag), enaddr);
932 } else
933 #endif
934 memcpy(enaddr, &sc->sc_srom[20], ETHER_ADDR_LEN);
935 }
936
937 /*
938 * Davicom chips all have an internal MII interface
939 * and a built-in PHY. DM9102A also has a an external
940 * MII interface, usually with a HomePNA PHY attached
941 * to it.
942 */
943 sc->sc_mediasw = &tlp_dm9102_mediasw;
944 break;
945
946 case TULIP_CHIP_AX88140:
947 case TULIP_CHIP_AX88141:
948 /*
949 * ASIX AX88140/AX88141 Ethernet Address is located at offset
950 * 20 of the SROM.
951 */
952 memcpy(enaddr, &sc->sc_srom[20], ETHER_ADDR_LEN);
953
954 /*
955 * ASIX AX88140A/AX88141 chip can have a built-in PHY or
956 * an external MII interface.
957 */
958 sc->sc_mediasw = &tlp_asix_mediasw;
959 break;
960
961 case TULIP_CHIP_RS7112:
962 /*
963 * RS7112 Ethernet Address is located of offset 0x19a
964 * of the SROM
965 */
966 memcpy(enaddr, &sc->sc_srom[0x19a], ETHER_ADDR_LEN);
967
968 /* RS7112 chip has a PHY at MII address 1 */
969 sc->sc_mediasw = &tlp_rs7112_mediasw;
970 break;
971
972 default:
973 cant_cope:
974 printf("%s: sorry, unable to handle your board\n",
975 sc->sc_dev.dv_xname);
976 return;
977 }
978
979 /*
980 * Handle shared interrupts.
981 */
982 if (psc->sc_flags & TULIP_PCI_SHAREDINTR) {
983 if (psc->sc_master)
984 psc->sc_flags |= TULIP_PCI_SLAVEINTR;
985 else {
986 tlp_pci_check_slaved(psc, TULIP_PCI_SHAREDINTR,
987 TULIP_PCI_SLAVEINTR);
988 if (psc->sc_master == NULL)
989 psc->sc_master = psc;
990 }
991 LIST_INSERT_HEAD(&psc->sc_master->sc_intrslaves,
992 psc, sc_intrq);
993 }
994
995 if (psc->sc_flags & TULIP_PCI_SLAVEINTR) {
996 printf("%s: sharing interrupt with %s\n",
997 sc->sc_dev.dv_xname,
998 psc->sc_master->sc_tulip.sc_dev.dv_xname);
999 } else {
1000 /*
1001 * Map and establish our interrupt.
1002 */
1003 if (pci_intr_map(pa, &ih)) {
1004 printf("%s: unable to map interrupt\n",
1005 sc->sc_dev.dv_xname);
1006 return;
1007 }
1008 intrstr = pci_intr_string(pc, ih);
1009 psc->sc_ih = pci_intr_establish(pc, ih, IPL_NET,
1010 (psc->sc_flags & TULIP_PCI_SHAREDINTR) ?
1011 tlp_pci_shared_intr : tlp_intr, sc);
1012 if (psc->sc_ih == NULL) {
1013 printf("%s: unable to establish interrupt",
1014 sc->sc_dev.dv_xname);
1015 if (intrstr != NULL)
1016 printf(" at %s", intrstr);
1017 printf("\n");
1018 return;
1019 }
1020 printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname,
1021 intrstr);
1022 }
1023
1024 /*
1025 * Finish off the attach.
1026 */
1027 tlp_attach(sc, enaddr);
1028 }
1029
1030 static int
1031 tlp_pci_shared_intr(void *arg)
1032 {
1033 struct tulip_pci_softc *master = arg, *slave;
1034 int rv = 0;
1035
1036 for (slave = LIST_FIRST(&master->sc_intrslaves);
1037 slave != NULL;
1038 slave = LIST_NEXT(slave, sc_intrq))
1039 rv |= tlp_intr(&slave->sc_tulip);
1040
1041 return (rv);
1042 }
1043
1044 static void
1045 tlp_pci_dec_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1046 {
1047 struct tulip_softc *sc = &psc->sc_tulip;
1048
1049 /*
1050 * This isn't really a quirk-gathering device, really. We
1051 * just want to get the spiffy DEC board name from the SROM.
1052 */
1053 strcpy(sc->sc_name, "DEC ");
1054
1055 if (memcmp(&sc->sc_srom[29], "DE500", 5) == 0 ||
1056 memcmp(&sc->sc_srom[29], "DE450", 5) == 0)
1057 memcpy(&sc->sc_name[4], &sc->sc_srom[29], 8);
1058 else
1059 sc->sc_name[3] = '\0';
1060 }
1061
1062 static void
1063 tlp_pci_znyx_21040_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1064 {
1065 struct tulip_softc *sc = &psc->sc_tulip;
1066 u_int16_t id = 0;
1067
1068 /*
1069 * If we have a slaved ROM, just copy the bits from the master.
1070 * This is in case we fail the ROM ID check (older boards) and
1071 * need to fall back on Ethernet address model checking; that
1072 * will fail for slave chips.
1073 */
1074 if (psc->sc_flags & TULIP_PCI_SLAVEROM) {
1075 strcpy(sc->sc_name, psc->sc_master->sc_tulip.sc_name);
1076 sc->sc_mediasw = psc->sc_master->sc_tulip.sc_mediasw;
1077 psc->sc_flags |=
1078 psc->sc_master->sc_flags & TULIP_PCI_SHAREDINTR;
1079 return;
1080 }
1081
1082 if (sc->sc_srom[32] == 0x4a && sc->sc_srom[33] == 0x52) {
1083 id = sc->sc_srom[37] | (sc->sc_srom[36] << 8);
1084 switch (id) {
1085 zx312:
1086 case 0x0602: /* ZX312 */
1087 strcpy(sc->sc_name, "ZNYX ZX312");
1088 return;
1089
1090 case 0x0622: /* ZX312T */
1091 strcpy(sc->sc_name, "ZNYX ZX312T");
1092 sc->sc_mediasw = &tlp_21040_tp_mediasw;
1093 return;
1094
1095 zx314_inta:
1096 case 0x0701: /* ZX314 INTA */
1097 psc->sc_flags |= TULIP_PCI_SHAREDINTR;
1098 /* FALLTHROUGH */
1099 case 0x0711: /* ZX314 */
1100 strcpy(sc->sc_name, "ZNYX ZX314");
1101 psc->sc_flags |= TULIP_PCI_SHAREDROM;
1102 sc->sc_mediasw = &tlp_21040_tp_mediasw;
1103 return;
1104
1105 zx315_inta:
1106 case 0x0801: /* ZX315 INTA */
1107 psc->sc_flags |= TULIP_PCI_SHAREDINTR;
1108 /* FALLTHROUGH */
1109 case 0x0811: /* ZX315 */
1110 strcpy(sc->sc_name, "ZNYX ZX315");
1111 psc->sc_flags |= TULIP_PCI_SHAREDROM;
1112 return;
1113
1114 default:
1115 id = 0;
1116 break;
1117 }
1118 }
1119
1120 /*
1121 * Deal with boards that have broken ROMs.
1122 */
1123 if (id == 0) {
1124 if ((enaddr[3] & ~3) == 0xf0 && (enaddr[5] & 3) == 0x00)
1125 goto zx314_inta;
1126 if ((enaddr[3] & ~3) == 0xf4 && (enaddr[5] & 1) == 0x00)
1127 goto zx315_inta;
1128 if ((enaddr[3] & ~3) == 0xec)
1129 goto zx312;
1130 }
1131
1132 strcpy(sc->sc_name, "ZNYX ZX31x");
1133 }
1134
1135 static void tlp_pci_znyx_21142_qs6611_reset(struct tulip_softc *);
1136
1137 static void
1138 tlp_pci_znyx_21142_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1139 {
1140 struct tulip_softc *sc = &psc->sc_tulip;
1141 pcireg_t subid;
1142
1143 subid = pci_conf_read(psc->sc_pc, psc->sc_pcitag, PCI_SUBSYS_ID_REG);
1144
1145 if (PCI_VENDOR(subid) != PCI_VENDOR_ZNYX)
1146 return; /* ? */
1147
1148 switch (PCI_PRODUCT(subid) & 0xff) {
1149 /*
1150 * ZNYX 21143 boards with QS6611 PHY
1151 */
1152 case 0x12: /* ZX345Q */
1153 case 0x13: /* ZX346Q */
1154 case 0x14: /* ZX348Q */
1155 case 0x18: /* ZX414 */
1156 case 0x19: /* ZX412 */
1157 case 0x1a: /* ZX444 */
1158 case 0x1b: /* ZX442 */
1159 case 0x23: /* ZX212 */
1160 case 0x24: /* ZX214 */
1161 case 0x29: /* ZX374 */
1162 case 0x2d: /* ZX372 */
1163 case 0x2b: /* ZX244 */
1164 case 0x2c: /* ZX424 */
1165 case 0x2e: /* ZX422 */
1166 printf("%s: QS6611 PHY\n", sc->sc_dev.dv_xname);
1167 sc->sc_reset = tlp_pci_znyx_21142_qs6611_reset;
1168 break;
1169 }
1170 }
1171
1172 static void
1173 tlp_pci_znyx_21142_qs6611_reset(struct tulip_softc *sc)
1174 {
1175
1176 /*
1177 * Reset QS6611 PHY.
1178 */
1179 TULIP_WRITE(sc, CSR_SIAGEN,
1180 SIAGEN_CWE | SIAGEN_LGS1 | SIAGEN_ABM | (0xf << 16));
1181 delay(200);
1182 TULIP_WRITE(sc, CSR_SIAGEN, (0x4 << 16));
1183 delay(10000);
1184 }
1185
1186 static void
1187 tlp_pci_smc_21040_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1188 {
1189 struct tulip_softc *sc = &psc->sc_tulip;
1190 u_int16_t id1, id2, ei;
1191 int auibnc = 0, utp = 0;
1192 char *cp;
1193
1194 id1 = sc->sc_srom[0x60] | (sc->sc_srom[0x61] << 8);
1195 id2 = sc->sc_srom[0x62] | (sc->sc_srom[0x63] << 8);
1196 ei = sc->sc_srom[0x66] | (sc->sc_srom[0x67] << 8);
1197
1198 strcpy(sc->sc_name, "SMC 8432");
1199 cp = &sc->sc_name[8];
1200
1201 if ((id1 & 1) == 0) {
1202 *cp++ = 'B';
1203 auibnc = 1;
1204 }
1205 if ((id1 & 0xff) > 0x32) {
1206 *cp++ = 'T';
1207 utp = 1;
1208 }
1209 if ((id1 & 0x4000) == 0) {
1210 *cp++ = 'A';
1211 auibnc = 1;
1212 }
1213 if (id2 == 0x15) {
1214 sc->sc_name[7] = '4';
1215 *cp++ = '-';
1216 *cp++ = 'C';
1217 *cp++ = 'H';
1218 *cp++ = ei ? '2' : '1';
1219 }
1220 *cp = '\0';
1221
1222 if (utp != 0 && auibnc == 0)
1223 sc->sc_mediasw = &tlp_21040_tp_mediasw;
1224 else if (utp == 0 && auibnc != 0)
1225 sc->sc_mediasw = &tlp_21040_auibnc_mediasw;
1226 }
1227
1228 static void
1229 tlp_pci_cogent_21040_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1230 {
1231
1232 strcpy(psc->sc_tulip.sc_name, "Cogent multi-port");
1233 psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
1234 }
1235
1236 static void
1237 tlp_pci_accton_21040_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1238 {
1239
1240 strcpy(psc->sc_tulip.sc_name, "ACCTON EN1203");
1241 }
1242
1243 static void tlp_pci_asante_21140_reset(struct tulip_softc *);
1244
1245 static void
1246 tlp_pci_asante_21140_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1247 {
1248 struct tulip_softc *sc = &psc->sc_tulip;
1249
1250 /*
1251 * Some Asante boards don't use the ISV SROM format. For
1252 * those that don't, we initialize the GPIO direction bits,
1253 * and provide our own reset hook, which resets the MII.
1254 *
1255 * All of these boards use SIO-attached-MII media.
1256 */
1257 if (sc->sc_mediasw == &tlp_2114x_isv_mediasw)
1258 return;
1259
1260 strcpy(sc->sc_name, "Asante");
1261
1262 sc->sc_gp_dir = 0xbf;
1263 sc->sc_reset = tlp_pci_asante_21140_reset;
1264 sc->sc_mediasw = &tlp_sio_mii_mediasw;
1265 }
1266
1267 static void
1268 tlp_pci_asante_21140_reset(struct tulip_softc *sc)
1269 {
1270
1271 TULIP_WRITE(sc, CSR_GPP, GPP_GPC | sc->sc_gp_dir);
1272 TULIP_WRITE(sc, CSR_GPP, 0x8);
1273 delay(100);
1274 TULIP_WRITE(sc, CSR_GPP, 0);
1275 }
1276
1277 /*
1278 * SMC 9332DST media switch.
1279 */
1280 static void tlp_smc9332dst_tmsw_init(struct tulip_softc *);
1281
1282 static const struct tulip_mediasw tlp_smc9332dst_mediasw = {
1283 tlp_smc9332dst_tmsw_init,
1284 tlp_21140_gpio_get,
1285 tlp_21140_gpio_set
1286 };
1287
1288 static void
1289 tlp_pci_smc_21140_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1290 {
1291 struct tulip_softc *sc = &psc->sc_tulip;
1292
1293 if (sc->sc_mediasw != NULL) {
1294 return;
1295 }
1296 strcpy(psc->sc_tulip.sc_name, "SMC 9332DST");
1297 sc->sc_mediasw = &tlp_smc9332dst_mediasw;
1298 }
1299
1300 static void
1301 tlp_smc9332dst_tmsw_init(struct tulip_softc *sc)
1302 {
1303 struct tulip_21x4x_media *tm;
1304 const char *sep = "";
1305 uint32_t reg;
1306 int i, cnt;
1307
1308 sc->sc_gp_dir = GPP_SMC9332DST_PINS;
1309 sc->sc_opmode = OPMODE_MBO | OPMODE_PS;
1310 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
1311
1312 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
1313 tlp_mediastatus);
1314 printf("%s: ", sc->sc_dev.dv_xname);
1315
1316 #define ADD(m, c) \
1317 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO); \
1318 tm->tm_opmode = (c); \
1319 tm->tm_gpdata = GPP_SMC9332DST_INIT; \
1320 ifmedia_add(&sc->sc_mii.mii_media, (m), 0, tm)
1321 #define PRINT(str) printf("%s%s", sep, str); sep = ", "
1322
1323 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, 0, 0), OPMODE_TTM);
1324 PRINT("10baseT");
1325
1326 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_10_T, IFM_FDX, 0),
1327 OPMODE_TTM | OPMODE_FD);
1328 PRINT("10baseT-FDX");
1329
1330 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, 0, 0),
1331 OPMODE_PS | OPMODE_PCS | OPMODE_SCR);
1332 PRINT("100baseTX");
1333
1334 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, IFM_FDX, 0),
1335 OPMODE_PS | OPMODE_PCS | OPMODE_SCR | OPMODE_FD);
1336 PRINT("100baseTX-FDX");
1337
1338 #undef ADD
1339 #undef PRINT
1340
1341 printf("\n");
1342
1343 tlp_reset(sc);
1344 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode | OPMODE_PCS | OPMODE_SCR);
1345 TULIP_WRITE(sc, CSR_GPP, GPP_GPC | sc->sc_gp_dir);
1346 delay(10);
1347 TULIP_WRITE(sc, CSR_GPP, GPP_SMC9332DST_INIT);
1348 delay(200000);
1349 cnt = 0;
1350 for (i = 1000; i > 0; i--) {
1351 reg = TULIP_READ(sc, CSR_GPP);
1352 if ((~reg & (GPP_SMC9332DST_OK10 |
1353 GPP_SMC9332DST_OK100)) == 0) {
1354 if (cnt++ > 100) {
1355 break;
1356 }
1357 } else if ((reg & GPP_SMC9332DST_OK10) == 0) {
1358 break;
1359 } else {
1360 cnt = 0;
1361 }
1362 delay(1000);
1363 }
1364 if (cnt > 100) {
1365 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_100_TX);
1366 } else {
1367 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T);
1368 }
1369 }
1370
1371 static void
1372 tlp_pci_vpc_21140_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1373 {
1374 struct tulip_softc *sc = &psc->sc_tulip;
1375 char *p1 = (char *) &sc->sc_srom[32];
1376 char *p2 = &sc->sc_name[0];
1377
1378 do {
1379 if ((unsigned char) *p1 & 0x80)
1380 *p2++ = ' ';
1381 else
1382 *p2++ = *p1;
1383 } while (*p1++);
1384 }
1385
1386 static void tlp_pci_cobalt_21142_reset(struct tulip_softc *);
1387
1388 static void
1389 tlp_pci_cobalt_21142_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1390 {
1391 struct tulip_softc *sc = &psc->sc_tulip;
1392
1393 /*
1394 * Cobalt Networks interfaces are just MII-on-SIO.
1395 */
1396 sc->sc_reset = tlp_pci_cobalt_21142_reset;
1397 sc->sc_mediasw = &tlp_sio_mii_mediasw;
1398
1399 /*
1400 * The Cobalt systems tend to fall back to store-and-forward
1401 * pretty quickly, so we select that from the beginning to
1402 * avoid initial timeouts.
1403 */
1404 sc->sc_txthresh = TXTH_SF;
1405 }
1406
1407 static void
1408 tlp_pci_cobalt_21142_reset(struct tulip_softc *sc)
1409 {
1410 /*
1411 * Reset PHY.
1412 */
1413 TULIP_WRITE(sc, CSR_SIAGEN, SIAGEN_CWE | (1 << 16));
1414 delay(10);
1415 TULIP_WRITE(sc, CSR_SIAGEN, SIAGEN_CWE);
1416 delay(10);
1417 }
1418
1419 static void
1420 tlp_pci_algor_21142_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1421 {
1422 struct tulip_softc *sc = &psc->sc_tulip;
1423
1424 /*
1425 * Algorithmics boards just have MII-on-SIO.
1426 *
1427 * XXX They also have AUI on the serial interface.
1428 * XXX Deal with this.
1429 */
1430 sc->sc_mediasw = &tlp_sio_mii_mediasw;
1431 }
1432
1433 /*
1434 * Cogent EM1x0 (aka. Adaptec ANA-6910) media switch.
1435 */
1436 static void tlp_cogent_em1x0_tmsw_init(struct tulip_softc *);
1437
1438 static const struct tulip_mediasw tlp_cogent_em1x0_mediasw = {
1439 tlp_cogent_em1x0_tmsw_init,
1440 tlp_21140_gpio_get,
1441 tlp_21140_gpio_set
1442 };
1443
1444 static void
1445 tlp_pci_adaptec_quirks(struct tulip_pci_softc *psc, const u_int8_t *enaddr)
1446 {
1447 struct tulip_softc *sc = &psc->sc_tulip;
1448 uint8_t *srom = sc->sc_srom, id0;
1449 uint16_t id1, id2;
1450
1451 if (sc->sc_mediasw == NULL) {
1452 id0 = srom[32];
1453 switch (id0) {
1454 case 0x12:
1455 strcpy(psc->sc_tulip.sc_name, "Cogent EM100TX");
1456 sc->sc_mediasw = &tlp_cogent_em1x0_mediasw;
1457 break;
1458
1459 case 0x15:
1460 strcpy(psc->sc_tulip.sc_name, "Cogent EM100FX");
1461 sc->sc_mediasw = &tlp_cogent_em1x0_mediasw;
1462 break;
1463
1464 #if 0
1465 case XXX:
1466 strcpy(psc->sc_tulip.sc_name, "Cogent EM110TX");
1467 sc->sc_mediasw = &tlp_cogent_em1x0_mediasw;
1468 break;
1469 #endif
1470
1471 default:
1472 printf("%s: unknown Cogent board ID 0x%02x\n",
1473 sc->sc_dev.dv_xname, id0);
1474 }
1475 return;
1476 }
1477
1478 id1 = TULIP_ROM_GETW(srom, 0);
1479 id2 = TULIP_ROM_GETW(srom, 2);
1480 if (id1 != 0x1109) {
1481 goto unknown;
1482 }
1483
1484 switch (id2) {
1485 case 0x1900:
1486 strcpy(psc->sc_tulip.sc_name, "Adaptec ANA-6911");
1487 break;
1488
1489 case 0x2400:
1490 strcpy(psc->sc_tulip.sc_name, "Adaptec ANA-6944A");
1491 psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
1492 break;
1493
1494 case 0x2b00:
1495 strcpy(psc->sc_tulip.sc_name, "Adaptec ANA-6911A");
1496 break;
1497
1498 case 0x3000:
1499 strcpy(psc->sc_tulip.sc_name, "Adaptec ANA-6922");
1500 psc->sc_flags |= TULIP_PCI_SHAREDINTR|TULIP_PCI_SHAREDROM;
1501 break;
1502
1503 default:
1504 unknown:
1505 printf("%s: unknown Adaptec/Cogent board ID 0x%04x/0x%04x\n",
1506 sc->sc_dev.dv_xname, id1, id2);
1507 }
1508 }
1509
1510 static void
1511 tlp_cogent_em1x0_tmsw_init(struct tulip_softc *sc)
1512 {
1513 struct tulip_21x4x_media *tm;
1514 const char *sep = "";
1515
1516 sc->sc_gp_dir = GPP_COGENT_EM1x0_PINS;
1517 sc->sc_opmode = OPMODE_MBO | OPMODE_PS;
1518 TULIP_WRITE(sc, CSR_OPMODE, sc->sc_opmode);
1519
1520 ifmedia_init(&sc->sc_mii.mii_media, 0, tlp_mediachange,
1521 tlp_mediastatus);
1522 printf("%s: ", sc->sc_dev.dv_xname);
1523
1524 #define ADD(m, c) \
1525 tm = malloc(sizeof(*tm), M_DEVBUF, M_WAITOK|M_ZERO); \
1526 tm->tm_opmode = (c); \
1527 tm->tm_gpdata = GPP_COGENT_EM1x0_INIT; \
1528 ifmedia_add(&sc->sc_mii.mii_media, (m), 0, tm)
1529 #define PRINT(str) printf("%s%s", sep, str); sep = ", "
1530
1531 if (sc->sc_srom[32] == 0x15) {
1532 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, 0, 0),
1533 OPMODE_PS | OPMODE_PCS);
1534 PRINT("100baseFX");
1535
1536 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, IFM_FDX, 0),
1537 OPMODE_PS | OPMODE_PCS | OPMODE_FD);
1538 PRINT("100baseFX-FDX");
1539 printf("\n");
1540
1541 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_100_FX);
1542 } else {
1543 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_TX, 0, 0),
1544 OPMODE_PS | OPMODE_PCS | OPMODE_SCR);
1545 PRINT("100baseTX");
1546
1547 ADD(IFM_MAKEWORD(IFM_ETHER, IFM_100_FX, IFM_FDX, 0),
1548 OPMODE_PS | OPMODE_PCS | OPMODE_SCR | OPMODE_FD);
1549 PRINT("100baseTX-FDX");
1550 printf("\n");
1551
1552 ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_100_TX);
1553 }
1554
1555 #undef ADD
1556 #undef PRINT
1557 }
1558
1559 static void tlp_pci_netwinder_21142_reset(struct tulip_softc *);
1560
1561 static void
1562 tlp_pci_netwinder_21142_quirks(struct tulip_pci_softc *psc,
1563 const u_int8_t *enaddr)
1564 {
1565 struct tulip_softc *sc = &psc->sc_tulip;
1566
1567 /*
1568 * Netwinders just use MII-on_SIO.
1569 */
1570 sc->sc_mediasw = &tlp_sio_mii_mediasw;
1571 sc->sc_reset = tlp_pci_netwinder_21142_reset;
1572 }
1573
1574 void
1575 tlp_pci_netwinder_21142_reset(struct tulip_softc *sc)
1576 {
1577
1578 /*
1579 * Reset the PHY.
1580 */
1581 TULIP_WRITE(sc, CSR_SIAGEN, 0x0821 << 16);
1582 delay(10);
1583 TULIP_WRITE(sc, CSR_SIAGEN, 0x0000 << 16);
1584 delay(10);
1585 TULIP_WRITE(sc, CSR_SIAGEN, 0x0001 << 16);
1586 delay(10);
1587 }
1588