xirc.c revision 1.10 1 /* $NetBSD: xirc.c,v 1.10 2004/08/10 16:04:16 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.10 2004/08/10 16:04:16 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 sc->sc_ih = 0;
538 return (error);
539 }
540
541 sc->sc_flags |= flag;
542
543 if (sc->sc_chipset < XI_CHIPSET_DINGO &&
544 sc->sc_id & (XIMEDIA_MODEM << 8)) {
545 sc->sc_mako_intmask |= media;
546 bus_space_write_1(sc->sc_ethernet_pcioh.iot,
547 sc->sc_ethernet_pcioh.ioh, 0x10, sc->sc_mako_intmask);
548 }
549
550 return (0);
551 }
552
553 void
554 xirc_disable(sc, flag, media)
555 struct xirc_softc *sc;
556 int flag, media;
557 {
558
559 if ((sc->sc_flags & flag) == 0) {
560 printf("%s: already disabled\n", sc->sc_dev.dv_xname);
561 return;
562 }
563
564 if (sc->sc_chipset < XI_CHIPSET_DINGO &&
565 sc->sc_id & (XIMEDIA_MODEM << 8)) {
566 sc->sc_mako_intmask &= ~media;
567 bus_space_write_1(sc->sc_ethernet_pcioh.iot,
568 sc->sc_ethernet_pcioh.ioh, 0x10, sc->sc_mako_intmask);
569 }
570
571 sc->sc_flags &= ~flag;
572 if ((sc->sc_flags & (XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED)) != 0)
573 return;
574
575 pcmcia_function_disable(sc->sc_pf);
576 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
577 sc->sc_ih = 0;
578 }
579
580 /****** Here begins the com attachment code. ******/
581
582 #if NCOM_XIRC > 0
583 int com_xirc_match __P((struct device *, struct cfdata *, void *));
584 void com_xirc_attach __P((struct device *, struct device *, void *));
585 int com_xirc_detach __P((struct device *, int));
586
587 /* No xirc-specific goo in the softc; it's all in the parent. */
588 CFATTACH_DECL(com_xirc, sizeof(struct com_softc),
589 com_xirc_match, com_xirc_attach, com_detach, com_activate);
590
591 int com_xirc_enable __P((struct com_softc *));
592 void com_xirc_disable __P((struct com_softc *));
593
594 int
595 com_xirc_match(parent, match, aux)
596 struct device *parent;
597 struct cfdata *match;
598 void *aux;
599 {
600 extern struct cfdriver com_cd;
601 const char *name = aux;
602
603 if (strcmp(name, com_cd.cd_name) == 0)
604 return (1);
605
606 return (0);
607 }
608
609 void
610 com_xirc_attach(parent, self, aux)
611 struct device *parent, *self;
612 void *aux;
613 {
614 struct com_softc *sc = (void *)self;
615 struct xirc_softc *msc = (void *)parent;
616
617 aprint_normal("\n");
618
619 sc->sc_iot = msc->sc_modem_pcioh.iot;
620 sc->sc_ioh = msc->sc_modem_pcioh.ioh;
621
622 sc->enabled = 1;
623
624 sc->sc_iobase = -1;
625 sc->sc_frequency = COM_FREQ;
626
627 sc->enable = com_xirc_enable;
628 sc->disable = com_xirc_disable;
629
630 aprint_normal("%s", self->dv_xname);
631
632 com_attach_subr(sc);
633
634 sc->enabled = 0;
635 }
636
637 int
638 com_xirc_enable(sc)
639 struct com_softc *sc;
640 {
641 struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
642
643 return (xirc_enable(msc, XIRC_MODEM_ENABLED, XIMEDIA_MODEM));
644 }
645
646 void
647 com_xirc_disable(sc)
648 struct com_softc *sc;
649 {
650 struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
651
652 xirc_disable(msc, XIRC_MODEM_ENABLED, XIMEDIA_MODEM);
653 }
654
655 #endif /* NCOM_XIRC > 0 */
656
657 /****** Here begins the xi attachment code. ******/
658
659 #if NXI_XIRC > 0
660 int xi_xirc_match __P((struct device *, struct cfdata *, void *));
661 void xi_xirc_attach __P((struct device *, struct device *, void *));
662
663 /* No xirc-specific goo in the softc; it's all in the parent. */
664 CFATTACH_DECL(xi_xirc, sizeof(struct xi_softc),
665 xi_xirc_match, xi_xirc_attach, xi_detach, xi_activate);
666
667 int xi_xirc_enable __P((struct xi_softc *));
668 void xi_xirc_disable __P((struct xi_softc *));
669 int xi_xirc_lan_nid_ciscallback __P((struct pcmcia_tuple *, void *));
670
671 int
672 xi_xirc_match(parent, match, aux)
673 struct device *parent;
674 struct cfdata *match;
675 void *aux;
676 {
677 extern struct cfdriver xi_cd;
678 const char *name = aux;
679
680 if (strcmp(name, xi_cd.cd_name) == 0)
681 return (1);
682
683 return (0);
684 }
685
686 void
687 xi_xirc_attach(parent, self, aux)
688 struct device *parent, *self;
689 void *aux;
690 {
691 struct xi_softc *sc = (void *)self;
692 struct xirc_softc *msc = (void *)parent;
693 u_int8_t myla[ETHER_ADDR_LEN];
694
695 aprint_normal("\n");
696
697 sc->sc_bst = msc->sc_ethernet_pcioh.iot;
698 sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
699
700 sc->sc_chipset = msc->sc_chipset;
701
702 sc->sc_enable = xi_xirc_enable;
703 sc->sc_disable = xi_xirc_disable;
704
705 if (!pcmcia_scan_cis(msc->sc_dev.dv_parent, xi_xirc_lan_nid_ciscallback,
706 myla)) {
707 aprint_error("%s: can't find MAC address\n", self->dv_xname);
708 return;
709 }
710
711 /* Perform generic initialization. */
712 xi_attach(sc, myla);
713 }
714
715 int
716 xi_xirc_enable(sc)
717 struct xi_softc *sc;
718 {
719 struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
720
721 return (xirc_enable(msc, XIRC_ETHERNET_ENABLED, XIMEDIA_ETHER));
722 }
723
724 void
725 xi_xirc_disable(sc)
726 struct xi_softc *sc;
727 {
728 struct xirc_softc *msc = (struct xirc_softc *)sc->sc_dev.dv_parent;
729
730 xirc_disable(msc, XIRC_ETHERNET_ENABLED, XIMEDIA_ETHER);
731 }
732
733 int
734 xi_xirc_lan_nid_ciscallback(tuple, arg)
735 struct pcmcia_tuple *tuple;
736 void *arg;
737 {
738 u_int8_t *myla = arg;
739 int i;
740
741 if (tuple->length < 2)
742 return (0);
743
744 switch (tuple->code) {
745 case PCMCIA_CISTPL_FUNCE:
746 switch (pcmcia_tuple_read_1(tuple, 0)) {
747 case PCMCIA_TPLFE_TYPE_LAN_NID:
748 if (pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN)
749 return (0);
750 for (i = 0; i < ETHER_ADDR_LEN; i++)
751 myla[i] = pcmcia_tuple_read_1(tuple, i + 2);
752 return (1);
753
754 case 0x02:
755 /*
756 * Not sure about this, I don't have a CE2
757 * that puts the ethernet addr here.
758 */
759 if (pcmcia_tuple_read_1(tuple, 1) != 0x01 ||
760 pcmcia_tuple_read_1(tuple, 2) != ETHER_ADDR_LEN)
761 return (0);
762 for (i = 0; i < ETHER_ADDR_LEN; i++)
763 myla[i] = pcmcia_tuple_read_1(tuple, i + 3);
764 return (1);
765 }
766
767 case 0x89:
768 if (pcmcia_tuple_read_1(tuple, 0) != 0x04 ||
769 pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN)
770 return (0);
771 for (i = 0; i < ETHER_ADDR_LEN; i++)
772 myla[i] = pcmcia_tuple_read_1(tuple, i + 2);
773 return (1);
774 }
775
776 return (0);
777 }
778
779 #endif /* NXI_XIRC > 0 */
780