xirc.c revision 1.9 1 /* $NetBSD: xirc.c,v 1.9 2004/08/10 15:29:56 mycroft Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2000, 2004 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 by 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 #include <sys/cdefs.h>
41 __KERNEL_RCSID(0, "$NetBSD: xirc.c,v 1.9 2004/08/10 15:29:56 mycroft Exp $");
42
43 #include "opt_inet.h"
44 #include "opt_ns.h"
45 #include "bpfilter.h"
46
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/mbuf.h>
50 #include <sys/socket.h>
51 #include <sys/ioctl.h>
52 #include <sys/errno.h>
53 #include <sys/syslog.h>
54 #include <sys/select.h>
55 #include <sys/tty.h>
56 #include <sys/device.h>
57
58 #include <net/if.h>
59 #include <net/if_dl.h>
60 #include <net/if_ether.h>
61 #include <net/if_media.h>
62
63 #ifdef INET
64 #include <netinet/in.h>
65 #include <netinet/in_systm.h>
66 #include <netinet/in_var.h>
67 #include <netinet/ip.h>
68 #include <netinet/if_inarp.h>
69 #endif
70
71 #ifdef NS
72 #include <netns/ns.h>
73 #include <netns/ns_if.h>
74 #endif
75
76 #if NBPFILTER > 0
77 #include <net/bpf.h>
78 #include <net/bpfdesc.h>
79 #endif
80
81 #include <machine/intr.h>
82 #include <machine/bus.h>
83
84 #include <dev/pcmcia/pcmciareg.h>
85 #include <dev/pcmcia/pcmciavar.h>
86 #include <dev/pcmcia/pcmciadevs.h>
87
88 #include "xirc.h"
89
90 #if NCOM_XIRC > 0
91 #include <dev/ic/comreg.h>
92 #include <dev/ic/comvar.h>
93 #endif
94
95 #if NXI_XIRC > 0
96 #include <dev/mii/mii.h>
97 #include <dev/mii/miivar.h>
98
99 #include <dev/pcmcia/if_xivar.h>
100 #endif
101 #include <dev/pcmcia/if_xireg.h>
102
103 struct xirc_softc {
104 struct device sc_dev; /* generic device glue */
105
106 struct pcmcia_function *sc_pf; /* our PCMCIA function */
107 void *sc_ih; /* interrupt handle */
108
109 u_int16_t sc_id;
110 u_int8_t sc_mako_intmask;
111 int sc_chipset;
112
113 /*
114 * Data for the Modem portion.
115 */
116 struct device *sc_modem;
117 struct pcmcia_io_handle sc_modem_pcioh;
118 int sc_modem_io_window;
119
120 /*
121 * Data for the Ethernet portion.
122 */
123 struct device *sc_ethernet;
124 struct pcmcia_io_handle sc_ethernet_pcioh;
125 int sc_ethernet_io_window;
126
127 int sc_flags;
128 #define XIRC_MODEM_MAPPED 0x01
129 #define XIRC_ETHERNET_MAPPED 0x02
130 #define XIRC_MODEM_ENABLED 0x04
131 #define XIRC_ETHERNET_ENABLED 0x08
132 #define XIRC_MODEM_ALLOCED 0x10
133 #define XIRC_ETHERNET_ALLOCED 0x20
134 };
135
136 int xirc_match __P((struct device *, struct cfdata *, void *));
137 void xirc_attach __P((struct device *, struct device *, void *));
138 int xirc_detach __P((struct device *, int));
139 int xirc_activate __P((struct device *, enum devact));
140
141 CFATTACH_DECL(xirc, sizeof(struct xirc_softc),
142 xirc_match, xirc_attach, xirc_detach, xirc_activate);
143
144 int xirc_print __P((void *, const char *));
145
146 int xirc_manfid_ciscallback __P((struct pcmcia_tuple *, void *));
147 struct pcmcia_config_entry *
148 xirc_mako_alloc __P((struct xirc_softc *));
149 struct pcmcia_config_entry *
150 xirc_dingo_alloc_modem __P((struct xirc_softc *));
151 struct pcmcia_config_entry *
152 xirc_dingo_alloc_ethernet __P((struct xirc_softc *));
153
154 int xirc_enable __P((struct xirc_softc *, int, int));
155 void xirc_disable __P((struct xirc_softc *, int, int));
156
157 int xirc_intr __P((void *));
158
159 int
160 xirc_match(parent, match, aux)
161 struct device *parent;
162 struct cfdata *match;
163 void *aux;
164 {
165 struct pcmcia_attach_args *pa = aux;
166
167 /* XXX Toshiba, Accton */
168
169 if (pa->manufacturer == PCMCIA_VENDOR_COMPAQ2 &&
170 pa->product == PCMCIA_PRODUCT_COMPAQ2_CPQ_10_100)
171 return (1);
172
173 if (pa->manufacturer == PCMCIA_VENDOR_INTEL &&
174 pa->product == PCMCIA_PRODUCT_INTEL_EEPRO100)
175 return (1);
176
177 if (pa->manufacturer == PCMCIA_VENDOR_XIRCOM &&
178 (pa->product & (XIMEDIA_ETHER << 8)) != 0)
179 return (2);
180
181 return (0);
182 }
183
184 void
185 xirc_attach(parent, self, aux)
186 struct device *parent, *self;
187 void *aux;
188 {
189 struct xirc_softc *sc = (void *)self;
190 struct pcmcia_attach_args *pa = aux;
191 struct pcmcia_config_entry *cfe;
192 int rv;
193 int error;
194
195 aprint_normal("\n");
196 sc->sc_pf = pa->pf;
197
198 pcmcia_socket_enable(parent);
199 rv = pcmcia_scan_cis(parent, xirc_manfid_ciscallback, &sc->sc_id);
200 pcmcia_socket_disable(parent);
201 if (!rv) {
202 aprint_error("%s: failed to find ID\n", self->dv_xname);
203 return;
204 }
205
206 switch (sc->sc_id & 0x100f) {
207 case 0x0001: /* CE */
208 case 0x0002: /* CE2 */
209 sc->sc_chipset = XI_CHIPSET_SCIPPER;
210 break;
211 case 0x0003: /* CE3 */
212 sc->sc_chipset = XI_CHIPSET_MOHAWK;
213 break;
214 case 0x1001:
215 case 0x1002:
216 case 0x1003:
217 case 0x1004:
218 sc->sc_chipset = XI_CHIPSET_SCIPPER;
219 break;
220 case 0x1005:
221 sc->sc_chipset = XI_CHIPSET_MOHAWK;
222 break;
223 case 0x1006:
224 case 0x1007:
225 sc->sc_chipset = XI_CHIPSET_DINGO;
226 break;
227 default:
228 aprint_error("%s: unknown ID %04x\n", self->dv_xname,
229 sc->sc_id);
230 return;
231 }
232
233 aprint_normal("%s: id=%04x\n", self->dv_xname, sc->sc_id);
234
235 if (sc->sc_id & (XIMEDIA_MODEM << 8)) {
236 if (sc->sc_chipset >= XI_CHIPSET_DINGO) {
237 cfe = xirc_dingo_alloc_modem(sc);
238 if (cfe && sc->sc_id & (XIMEDIA_ETHER << 8)) {
239 if (!xirc_dingo_alloc_ethernet(sc)) {
240 pcmcia_io_free(pa->pf,
241 &sc->sc_modem_pcioh);
242 cfe = 0;
243 }
244 }
245 } else
246 cfe = xirc_mako_alloc(sc);
247 } else
248 cfe = xirc_dingo_alloc_ethernet(sc);
249 if (!cfe) {
250 aprint_error("%s: failed to allocate I/O space\n",
251 self->dv_xname);
252 goto fail;
253 }
254
255 /* Enable the card. */
256 pcmcia_function_init(pa->pf, cfe);
257
258 if (sc->sc_id & (XIMEDIA_MODEM << 8)) {
259 if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_IO8,
260 &sc->sc_modem_pcioh, &sc->sc_modem_io_window)) {
261 aprint_error("%s: unable to map I/O space\n",
262 self->dv_xname);
263 goto fail;
264 }
265 sc->sc_flags |= XIRC_MODEM_MAPPED;
266 }
267
268 if (sc->sc_id & (XIMEDIA_ETHER << 8)) {
269 if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_AUTO,
270 &sc->sc_ethernet_pcioh, &sc->sc_ethernet_io_window)) {
271 aprint_error("%s: unable to map I/O space\n",
272 self->dv_xname);
273 goto fail;
274 }
275 sc->sc_flags |= XIRC_ETHERNET_MAPPED;
276 }
277
278 error = xirc_enable(sc, XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED,
279 sc->sc_id & (XIMEDIA_MODEM|XIMEDIA_ETHER));
280 if (error)
281 goto fail;
282
283 sc->sc_mako_intmask = 0xee;
284
285 if (sc->sc_id & (XIMEDIA_MODEM << 8))
286 sc->sc_modem = config_found(self, "com", xirc_print);
287 if (sc->sc_id & (XIMEDIA_ETHER << 8))
288 sc->sc_ethernet = config_found(self, "xi", xirc_print);
289
290 xirc_disable(sc, XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED,
291 sc->sc_id & (XIMEDIA_MODEM|XIMEDIA_ETHER));
292 return;
293
294 fail:
295 /* I/O spaces will be freed by detach. */
296 ;
297 }
298
299 int
300 xirc_manfid_ciscallback(tuple, arg)
301 struct pcmcia_tuple *tuple;
302 void *arg;
303 {
304 u_int16_t *id = arg;
305
306 if (tuple->code != PCMCIA_CISTPL_MANFID)
307 return (0);
308
309 if (tuple->length < 5)
310 return (0);
311
312 *id = (pcmcia_tuple_read_1(tuple, 3) << 8) |
313 pcmcia_tuple_read_1(tuple, 4);
314 return (1);
315 }
316
317 struct pcmcia_config_entry *
318 xirc_mako_alloc(sc)
319 struct xirc_softc *sc;
320 {
321 struct pcmcia_config_entry *cfe;
322
323 SIMPLEQ_FOREACH(cfe, &sc->sc_pf->cfe_head, cfe_list) {
324 if (cfe->num_iospace != 1)
325 continue;
326
327 if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start,
328 cfe->iospace[0].length, cfe->iospace[0].length,
329 &sc->sc_modem_pcioh))
330 continue;
331
332 cfe->iospace[1].start = cfe->iospace[0].start+8;
333 cfe->iospace[1].length = 18;
334 if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[1].start,
335 cfe->iospace[1].length, 0x20,
336 &sc->sc_ethernet_pcioh)) {
337 cfe->iospace[1].start = cfe->iospace[0].start-24;
338 if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[1].start,
339 cfe->iospace[1].length, 0x20,
340 &sc->sc_ethernet_pcioh))
341 continue;
342 }
343
344 /* Found one! */
345 sc->sc_flags |= XIRC_MODEM_ALLOCED;
346 sc->sc_flags |= XIRC_ETHERNET_ALLOCED;
347 return (cfe);
348 }
349
350 return (0);
351 }
352
353 struct pcmcia_config_entry *
354 xirc_dingo_alloc_modem(sc)
355 struct xirc_softc *sc;
356 {
357 struct pcmcia_config_entry *cfe;
358
359 SIMPLEQ_FOREACH(cfe, &sc->sc_pf->cfe_head, cfe_list) {
360 if (cfe->num_iospace != 1)
361 continue;
362
363 if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start,
364 cfe->iospace[0].length, cfe->iospace[0].length,
365 &sc->sc_modem_pcioh))
366 continue;
367
368 /* Found one! */
369 sc->sc_flags |= XIRC_MODEM_ALLOCED;
370 return (cfe);
371 }
372
373 return (0);
374 }
375
376 struct pcmcia_config_entry *
377 xirc_dingo_alloc_ethernet(sc)
378 struct xirc_softc *sc;
379 {
380 struct pcmcia_config_entry *cfe;
381 bus_addr_t port;
382
383 for (port = 0x300; port < 0x400; port += XI_IOSIZE) {
384 if (pcmcia_io_alloc(sc->sc_pf, port,
385 XI_IOSIZE, XI_IOSIZE, &sc->sc_ethernet_pcioh))
386 continue;
387
388 /* Found one for the ethernet! */
389 sc->sc_flags |= XIRC_ETHERNET_ALLOCED;
390 cfe = SIMPLEQ_FIRST(&sc->sc_pf->cfe_head);
391 return (cfe);
392 }
393
394 return (0);
395 }
396
397 int
398 xirc_print(aux, pnp)
399 void *aux;
400 const char *pnp;
401 {
402 const char *name = aux;
403
404 if (pnp)
405 aprint_normal("%s at %s(*)", name, pnp);
406
407 return (UNCONF);
408 }
409
410 int
411 xirc_detach(self, flags)
412 struct device *self;
413 int flags;
414 {
415 struct xirc_softc *sc = (void *)self;
416 int rv;
417
418 if (sc->sc_ethernet != NULL) {
419 rv = config_detach(sc->sc_ethernet, flags);
420 if (rv != 0)
421 return (rv);
422 sc->sc_ethernet = NULL;
423 }
424
425 if (sc->sc_modem != NULL) {
426 rv = config_detach(sc->sc_modem, flags);
427 if (rv != 0)
428 return (rv);
429 sc->sc_modem = NULL;
430 }
431
432 /* Unmap our i/o windows. */
433 if (sc->sc_flags & XIRC_ETHERNET_MAPPED)
434 pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window);
435 if (sc->sc_flags & XIRC_MODEM_MAPPED)
436 pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window);
437
438 /* Free our i/o spaces. */
439 if (sc->sc_flags & XIRC_ETHERNET_ALLOCED)
440 pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
441 if (sc->sc_flags & XIRC_MODEM_ALLOCED)
442 pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
443 sc->sc_flags = 0;
444
445 return (0);
446 }
447
448 int
449 xirc_activate(self, act)
450 struct device *self;
451 enum devact act;
452 {
453 struct xirc_softc *sc = (void *)self;
454 int s, rv = 0;
455
456 s = splhigh();
457 switch (act) {
458 case DVACT_ACTIVATE:
459 rv = EOPNOTSUPP;
460 break;
461
462 case DVACT_DEACTIVATE:
463 if (sc->sc_ethernet != NULL) {
464 rv = config_deactivate(sc->sc_ethernet);
465 if (rv != 0)
466 goto out;
467 }
468
469 if (sc->sc_modem != NULL) {
470 rv = config_deactivate(sc->sc_modem);
471 if (rv != 0)
472 goto out;
473 }
474 break;
475 }
476 out:
477 splx(s);
478 return (rv);
479 }
480
481 int
482 xirc_intr(arg)
483 void *arg;
484 {
485 struct xirc_softc *sc = arg;
486 int rval = 0;
487
488 #if NCOM_XIRC > 0
489 if (sc->sc_modem != NULL &&
490 (sc->sc_flags & XIRC_MODEM_ENABLED) != 0)
491 rval |= comintr(sc->sc_modem);
492 #endif
493
494 #if NXI_XIRC > 0
495 if (sc->sc_ethernet != NULL &&
496 (sc->sc_flags & XIRC_ETHERNET_ENABLED) != 0)
497 rval |= xi_intr(sc->sc_ethernet);
498 #endif
499
500 return (rval);
501 }
502
503 int
504 xirc_enable(sc, flag, media)
505 struct xirc_softc *sc;
506 int flag, media;
507 {
508 int error;
509
510 if ((sc->sc_flags & flag) == flag) {
511 printf("%s: already enabled\n", sc->sc_dev.dv_xname);
512 return (0);
513 }
514
515 if ((sc->sc_flags & (XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED)) != 0) {
516 sc->sc_flags |= flag;
517 return (0);
518 }
519
520 /*
521 * Establish our interrupt handler.
522 *
523 * XXX Note, we establish this at IPL_NET. This is suboptimal
524 * XXX the Modem portion, but is necessary to make the Ethernet
525 * XXX portion have the correct interrupt level semantics.
526 *
527 * XXX Eventually we should use the `enabled' bits in the
528 * XXX flags word to determine which level we should be at.
529 */
530 sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET, xirc_intr, sc);
531 if (!sc->sc_ih)
532 return (EIO);
533
534 error = pcmcia_function_enable(sc->sc_pf);
535 if (error) {
536 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
537 return (error);
538 }
539
540 sc->sc_flags |= flag;
541
542 if (sc->sc_chipset < XI_CHIPSET_DINGO &&
543 sc->sc_id & (XIMEDIA_MODEM << 8)) {
544 sc->sc_mako_intmask |= media;
545 bus_space_write_1(sc->sc_ethernet_pcioh.iot,
546 sc->sc_ethernet_pcioh.ioh, 0x10, sc->sc_mako_intmask);
547 }
548
549 return (0);
550 }
551
552 void
553 xirc_disable(sc, flag, media)
554 struct xirc_softc *sc;
555 int flag, media;
556 {
557
558 if ((sc->sc_flags & flag) == 0) {
559 printf("%s: already disabled\n", sc->sc_dev.dv_xname);
560 return;
561 }
562
563 if (sc->sc_chipset < XI_CHIPSET_DINGO &&
564 sc->sc_id & (XIMEDIA_MODEM << 8)) {
565 sc->sc_mako_intmask &= ~media;
566 bus_space_write_1(sc->sc_ethernet_pcioh.iot,
567 sc->sc_ethernet_pcioh.ioh, 0x10, sc->sc_mako_intmask);
568 }
569
570 sc->sc_flags &= ~flag;
571 if ((sc->sc_flags & (XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED)) != 0)
572 return;
573
574 pcmcia_function_disable(sc->sc_pf);
575 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
576 sc->sc_ih = 0;
577 }
578
579 /****** Here begins the com attachment code. ******/
580
581 #if NCOM_XIRC > 0
582 int com_xirc_match __P((struct device *, struct cfdata *, void *));
583 void com_xirc_attach __P((struct device *, struct device *, void *));
584 int com_xirc_detach __P((struct device *, int));
585
586 /* No xirc-specific goo in the softc; it's all in the parent. */
587 CFATTACH_DECL(com_xirc, sizeof(struct com_softc),
588 com_xirc_match, com_xirc_attach, com_detach, com_activate);
589
590 int com_xirc_enable __P((struct com_softc *));
591 void com_xirc_disable __P((struct com_softc *));
592
593 int
594 com_xirc_match(parent, match, aux)
595 struct device *parent;
596 struct cfdata *match;
597 void *aux;
598 {
599 extern struct cfdriver com_cd;
600 const char *name = aux;
601
602 if (strcmp(name, com_cd.cd_name) == 0)
603 return (1);
604
605 return (0);
606 }
607
608 void
609 com_xirc_attach(parent, self, aux)
610 struct device *parent, *self;
611 void *aux;
612 {
613 struct com_softc *sc = (void *)self;
614 struct xirc_softc *msc = (void *)parent;
615
616 aprint_normal("\n");
617
618 sc->sc_iot = msc->sc_modem_pcioh.iot;
619 sc->sc_ioh = msc->sc_modem_pcioh.ioh;
620
621 sc->enabled = 1;
622
623 sc->sc_iobase = -1;
624 sc->sc_frequency = COM_FREQ;
625
626 sc->enable = com_xirc_enable;
627 sc->disable = com_xirc_disable;
628
629 aprint_normal("%s", self->dv_xname);
630
631 com_attach_subr(sc);
632
633 sc->enabled = 0;
634 }
635
636 int
637 com_xirc_enable(sc)
638 struct com_softc *sc;
639 {
640 struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
641
642 return (xirc_enable(msc, XIRC_MODEM_ENABLED, XIMEDIA_MODEM));
643 }
644
645 void
646 com_xirc_disable(sc)
647 struct com_softc *sc;
648 {
649 struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
650
651 xirc_disable(msc, XIRC_MODEM_ENABLED, XIMEDIA_MODEM);
652 }
653
654 #endif /* NCOM_XIRC > 0 */
655
656 /****** Here begins the xi attachment code. ******/
657
658 #if NXI_XIRC > 0
659 int xi_xirc_match __P((struct device *, struct cfdata *, void *));
660 void xi_xirc_attach __P((struct device *, struct device *, void *));
661
662 /* No xirc-specific goo in the softc; it's all in the parent. */
663 CFATTACH_DECL(xi_xirc, sizeof(struct xi_softc),
664 xi_xirc_match, xi_xirc_attach, xi_detach, xi_activate);
665
666 int xi_xirc_enable __P((struct xi_softc *));
667 void xi_xirc_disable __P((struct xi_softc *));
668 int xi_xirc_lan_nid_ciscallback __P((struct pcmcia_tuple *, void *));
669
670 int
671 xi_xirc_match(parent, match, aux)
672 struct device *parent;
673 struct cfdata *match;
674 void *aux;
675 {
676 extern struct cfdriver xi_cd;
677 const char *name = aux;
678
679 if (strcmp(name, xi_cd.cd_name) == 0)
680 return (1);
681
682 return (0);
683 }
684
685 void
686 xi_xirc_attach(parent, self, aux)
687 struct device *parent, *self;
688 void *aux;
689 {
690 struct xi_softc *sc = (void *)self;
691 struct xirc_softc *msc = (void *)parent;
692 u_int8_t myla[ETHER_ADDR_LEN];
693
694 aprint_normal("\n");
695
696 sc->sc_bst = msc->sc_ethernet_pcioh.iot;
697 sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
698
699 sc->sc_chipset = msc->sc_chipset;
700
701 sc->sc_enable = xi_xirc_enable;
702 sc->sc_disable = xi_xirc_disable;
703
704 if (!pcmcia_scan_cis(msc->sc_dev.dv_parent, xi_xirc_lan_nid_ciscallback,
705 myla)) {
706 aprint_error("%s: can't find MAC address\n", self->dv_xname);
707 return;
708 }
709
710 /* Perform generic initialization. */
711 xi_attach(sc, myla);
712 }
713
714 int
715 xi_xirc_enable(sc)
716 struct xi_softc *sc;
717 {
718 struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
719
720 return (xirc_enable(msc, XIRC_ETHERNET_ENABLED, XIMEDIA_ETHER));
721 }
722
723 void
724 xi_xirc_disable(sc)
725 struct xi_softc *sc;
726 {
727 struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
728
729 xirc_disable(msc, XIRC_ETHERNET_ENABLED, XIMEDIA_ETHER);
730 }
731
732 int
733 xi_xirc_lan_nid_ciscallback(tuple, arg)
734 struct pcmcia_tuple *tuple;
735 void *arg;
736 {
737 u_int8_t *myla = arg;
738 int i;
739
740 if (tuple->length < 2)
741 return (0);
742
743 switch (tuple->code) {
744 case PCMCIA_CISTPL_FUNCE:
745 switch (pcmcia_tuple_read_1(tuple, 0)) {
746 case PCMCIA_TPLFE_TYPE_LAN_NID:
747 if (pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN)
748 return (0);
749 for (i = 0; i < ETHER_ADDR_LEN; i++)
750 myla[i] = pcmcia_tuple_read_1(tuple, i + 2);
751 return (1);
752
753 case 0x02:
754 /*
755 * Not sure about this, I don't have a CE2
756 * that puts the ethernet addr here.
757 */
758 if (pcmcia_tuple_read_1(tuple, 1) != 0x01 ||
759 pcmcia_tuple_read_1(tuple, 2) != ETHER_ADDR_LEN)
760 return (0);
761 for (i = 0; i < ETHER_ADDR_LEN; i++)
762 myla[i] = pcmcia_tuple_read_1(tuple, i + 3);
763 return (1);
764 }
765
766 case 0x89:
767 if (pcmcia_tuple_read_1(tuple, 0) != 0x04 ||
768 pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN)
769 return (0);
770 for (i = 0; i < ETHER_ADDR_LEN; i++)
771 myla[i] = pcmcia_tuple_read_1(tuple, i + 2);
772 return (1);
773 }
774
775 return (0);
776 }
777
778 #endif /* NXI_XIRC > 0 */
779