mhzc.c revision 1.4 1 /* $NetBSD: mhzc.c,v 1.4 2000/02/04 01:27:13 cgd Exp $ */
2
3 /*-
4 * Copyright (c) 1999, 2000 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 * Device driver for the Megaherz X-JACK Ethernet/Modem combo cards.
42 *
43 * Many thanks to Chuck Cranor for having the patience to sift through
44 * the Linux smc91c92_cs.c driver to find the magic details to get this
45 * working!
46 */
47
48 #include "opt_inet.h"
49 #include "opt_ns.h"
50 #include "bpfilter.h"
51
52 #include <sys/param.h>
53 #include <sys/systm.h>
54 #include <sys/mbuf.h>
55 #include <sys/socket.h>
56 #include <sys/ioctl.h>
57 #include <sys/errno.h>
58 #include <sys/syslog.h>
59 #include <sys/select.h>
60 #include <sys/tty.h>
61 #include <sys/device.h>
62
63 #include <net/if.h>
64 #include <net/if_dl.h>
65 #include <net/if_ether.h>
66 #include <net/if_media.h>
67
68 #ifdef INET
69 #include <netinet/in.h>
70 #include <netinet/in_systm.h>
71 #include <netinet/in_var.h>
72 #include <netinet/ip.h>
73 #include <netinet/if_inarp.h>
74 #endif
75
76 #ifdef NS
77 #include <netns/ns.h>
78 #include <netns/ns_if.h>
79 #endif
80
81 #if NBPFILTER > 0
82 #include <net/bpf.h>
83 #include <net/bpfdesc.h>
84 #endif
85
86 #include <machine/intr.h>
87 #include <machine/bus.h>
88
89 #include <dev/ic/comreg.h>
90 #include <dev/ic/comvar.h>
91
92 #include <dev/ic/smc91cxxreg.h>
93 #include <dev/ic/smc91cxxvar.h>
94
95 #include <dev/pcmcia/pcmciareg.h>
96 #include <dev/pcmcia/pcmciavar.h>
97 #include <dev/pcmcia/pcmciadevs.h>
98
99 #include "mhzc.h"
100
101 struct mhzc_softc {
102 struct device sc_dev; /* generic device glue */
103
104 struct pcmcia_function *sc_pf; /* our PCMCIA function */
105 void *sc_ih; /* interrupt handle */
106
107 const struct mhzc_product *sc_product;
108
109 /*
110 * Data for the Modem portion.
111 */
112 struct device *sc_modem;
113 struct pcmcia_io_handle sc_modem_pcioh;
114 int sc_modem_io_window;
115
116 /*
117 * Data for the Ethernet portion.
118 */
119 struct device *sc_ethernet;
120 struct pcmcia_io_handle sc_ethernet_pcioh;
121 int sc_ethernet_io_window;
122
123 int sc_flags;
124 };
125
126 /* sc_flags */
127 #define MHZC_MODEM_MAPPED 0x01
128 #define MHZC_ETHERNET_MAPPED 0x02
129 #define MHZC_MODEM_ENABLED 0x04
130 #define MHZC_ETHERNET_ENABLED 0x08
131
132 int mhzc_match __P((struct device *, struct cfdata *, void *));
133 void mhzc_attach __P((struct device *, struct device *, void *));
134 int mhzc_detach __P((struct device *, int));
135 int mhzc_activate __P((struct device *, enum devact));
136
137 struct cfattach mhzc_ca = {
138 sizeof(struct mhzc_softc), mhzc_match, mhzc_attach,
139 mhzc_detach, mhzc_activate
140 };
141
142 int mhzc_em3336_enaddr __P((struct mhzc_softc *, u_int8_t *));
143 int mhzc_em3336_enable __P((struct mhzc_softc *));
144
145 const struct mhzc_product {
146 struct pcmcia_product mp_product;
147
148 /* Get the Ethernet address for this card. */
149 int (*mp_enaddr) __P((struct mhzc_softc *, u_int8_t *));
150
151 /* Perform any special `enable' magic. */
152 int (*mp_enable) __P((struct mhzc_softc *));
153 } mhzc_products[] = {
154 { { PCMCIA_STR_MEGAHERTZ_XJEM3336, PCMCIA_VENDOR_MEGAHERTZ,
155 PCMCIA_PRODUCT_MEGAHERTZ_XJEM3336, 0 },
156 mhzc_em3336_enaddr, mhzc_em3336_enable },
157
158 /*
159 * Eventually we could add support for other Ethernet/Modem
160 * combo cards, even if they're aren't Megahertz, because
161 * most of them work more or less the same way.
162 */
163
164 { { NULL } }
165 };
166
167 int mhzc_print __P((void *, const char *));
168
169 int mhzc_check_cfe __P((struct mhzc_softc *, struct pcmcia_config_entry *));
170 int mhzc_alloc_ethernet __P((struct mhzc_softc *));
171
172 int mhzc_enable __P((struct mhzc_softc *, int));
173 void mhzc_disable __P((struct mhzc_softc *, int));
174
175 int mhzc_intr __P((void *));
176
177 int
178 mhzc_match(parent, match, aux)
179 struct device *parent;
180 struct cfdata *match;
181 void *aux;
182 {
183 struct pcmcia_attach_args *pa = aux;
184
185 if (pcmcia_product_lookup(pa,
186 (const struct pcmcia_product *)mhzc_products,
187 sizeof mhzc_products[0], NULL) != NULL)
188 return (10); /* beat `com' */
189
190 return (0);
191 }
192
193 void
194 mhzc_attach(parent, self, aux)
195 struct device *parent, *self;
196 void *aux;
197 {
198 struct mhzc_softc *sc = (void *)self;
199 struct pcmcia_attach_args *pa = aux;
200 struct pcmcia_config_entry *cfe;
201
202 sc->sc_pf = pa->pf;
203
204 sc->sc_product = (const struct mhzc_product *)pcmcia_product_lookup(pa,
205 (const struct pcmcia_product *)mhzc_products,
206 sizeof mhzc_products[0], NULL);
207 if (sc->sc_product == NULL) {
208 printf("\n");
209 panic("mhzc_attach: impossible");
210 }
211
212 printf(": %s\n", sc->sc_product->mp_product.pp_name);
213
214 /*
215 * The address decoders on these cards are wacky. The configuration
216 * entries are set up to look like serial ports, and have no
217 * information about the Ethernet portion. In order to talk to
218 * the Modem portion, the I/O address must have bit 0x80 set.
219 * In order to talk to the Ethernet portion, the I/O address must
220 * have the 0x80 bit clear.
221 *
222 * The standard configuration entries conveniently have 0x80 set
223 * in them, and have a length of 8 (a 16550's size, convenient!),
224 * so we use those to set up the Modem portion.
225 *
226 * Once we have the Modem's address established, we search for
227 * an address suitable for the Ethernet portion. We do this by
228 * rounding up to the next 16-byte aligned address where 0x80
229 * isn't set (the SMC Ethernet chip has a 16-byte address size)
230 * and attemping to allocate a 16-byte region until we succeed.
231 *
232 * Sure would have been nice if Megahertz had made the card a
233 * proper multi-function device.
234 */
235 for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
236 cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
237 if (mhzc_check_cfe(sc, cfe)) {
238 /* Found one! */
239 break;
240 }
241 }
242 if (cfe == NULL) {
243 printf("%s: unable to find suitable config table entry\n",
244 sc->sc_dev.dv_xname);
245 return;
246 }
247
248 if (mhzc_alloc_ethernet(sc) == 0) {
249 printf("%s: unable to allocate space for Ethernet portion\n",
250 sc->sc_dev.dv_xname);
251 return;
252 }
253
254 /* Enable the card. */
255 pcmcia_function_init(pa->pf, cfe);
256 if (pcmcia_function_enable(pa->pf)) {
257 printf(": function enable failed\n");
258 return;
259 }
260
261 if (sc->sc_product->mp_enable != NULL)
262 (*sc->sc_product->mp_enable)(sc);
263
264 sc->sc_modem = config_found(&sc->sc_dev, "com", mhzc_print);
265 sc->sc_ethernet = config_found(&sc->sc_dev, "sm", mhzc_print);
266
267 pcmcia_function_disable(pa->pf);
268 }
269
270 int
271 mhzc_check_cfe(sc, cfe)
272 struct mhzc_softc *sc;
273 struct pcmcia_config_entry *cfe;
274 {
275
276 if (cfe->num_memspace != 0)
277 return (0);
278
279 if (cfe->num_iospace != 1)
280 return (0);
281
282 if (pcmcia_io_alloc(sc->sc_pf,
283 cfe->iospace[0].start,
284 cfe->iospace[0].length,
285 cfe->iospace[0].length,
286 &sc->sc_modem_pcioh) == 0) {
287 /* Found one for the modem! */
288 return (1);
289 }
290
291 return (0);
292 }
293
294 int
295 mhzc_alloc_ethernet(sc)
296 struct mhzc_softc *sc;
297 {
298 bus_addr_t addr, maxaddr;
299
300 maxaddr = sc->sc_pf->sc->iobase + sc->sc_pf->sc->iosize;
301 addr = sc->sc_pf->sc->iobase;
302
303 /*
304 * Now round it up so that it starts on a 16-byte boundary.
305 */
306 addr = roundup(addr, 0x10);
307
308 for (; (addr + 0x10) < maxaddr; addr += 0x10) {
309 if (addr & 0x80)
310 continue;
311 if (pcmcia_io_alloc(sc->sc_pf, addr, 0x10, 0x10,
312 &sc->sc_ethernet_pcioh) == 0) {
313 /* Found one for the ethernet! */
314 return (1);
315 }
316 }
317
318 /*
319 * Weren't able to allocate space for the Ethernet, so we
320 * free the Modem's I/O space.
321 */
322 pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
323 return (0);
324 }
325
326 int
327 mhzc_print(aux, pnp)
328 void *aux;
329 const char *pnp;
330 {
331 const char *name = aux;
332
333 if (pnp)
334 printf("%s at %s", name, pnp);
335
336 return (UNCONF);
337 }
338
339 int
340 mhzc_detach(self, flags)
341 struct device *self;
342 int flags;
343 {
344 struct mhzc_softc *sc = (void *)self;
345 int rv;
346
347 if (sc->sc_ethernet != NULL) {
348 rv = config_detach(sc->sc_ethernet, flags);
349 if (rv != 0)
350 return (rv);
351 }
352
353 if (sc->sc_modem != NULL) {
354 rv = config_detach(sc->sc_modem, flags);
355 if (rv != 0)
356 return (rv);
357 }
358
359 /* Unmap our i/o windows. */
360 if (sc->sc_flags & MHZC_MODEM_MAPPED)
361 pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window);
362 if (sc->sc_flags & MHZC_ETHERNET_MAPPED)
363 pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window);
364
365 /* Free our i/o spaces. */
366 pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
367 pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
368
369 return (0);
370 }
371
372 int
373 mhzc_activate(self, act)
374 struct device *self;
375 enum devact act;
376 {
377 struct mhzc_softc *sc = (void *)self;
378 int s, rv = 0;
379
380 s = splhigh();
381 switch (act) {
382 case DVACT_ACTIVATE:
383 rv = EOPNOTSUPP;
384 break;
385
386 case DVACT_DEACTIVATE:
387 if (sc->sc_ethernet != NULL) {
388 rv = config_deactivate(sc->sc_ethernet);
389 if (rv != 0)
390 goto out;
391 }
392
393 if (sc->sc_modem != NULL) {
394 rv = config_deactivate(sc->sc_modem);
395 if (rv != 0)
396 goto out;
397 }
398 break;
399 }
400 out:
401 splx(s);
402 return (rv);
403 }
404
405 int
406 mhzc_intr(arg)
407 void *arg;
408 {
409 struct mhzc_softc *sc = arg;
410 int rval = 0;
411
412 #if NCOM_MHZC > 0
413 if (sc->sc_modem != NULL &&
414 (sc->sc_flags & MHZC_MODEM_ENABLED) != 0)
415 rval |= comintr(sc->sc_modem);
416 #endif
417
418 #if NSM_MHZC > 0
419 if (sc->sc_ethernet != NULL &&
420 (sc->sc_flags & MHZC_ETHERNET_ENABLED) != 0)
421 rval |= smc91cxx_intr(sc->sc_ethernet);
422 #endif
423
424 return (rval);
425 }
426
427 int
428 mhzc_enable(sc, flag)
429 struct mhzc_softc *sc;
430 int flag;
431 {
432
433 if (sc->sc_flags & flag) {
434 printf("%s: %s already enabled\n", sc->sc_dev.dv_xname,
435 (flag & MHZC_MODEM_ENABLED) ? "modem" : "ethernet");
436 panic("mhzc_enable");
437 }
438
439 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0) {
440 sc->sc_flags |= flag;
441 return (0);
442 }
443
444 /*
445 * Establish our interrupt handler.
446 *
447 * XXX Note, we establish this at IPL_NET. This is suboptimal
448 * XXX the Modem portion, but is necessary to make the Ethernet
449 * XXX portion have the correct interrupt level semantics.
450 *
451 * XXX Eventually we should use the `enabled' bits in the
452 * XXX flags word to determine which level we should be at.
453 */
454 sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET,
455 mhzc_intr, sc);
456 if (sc->sc_ih == NULL) {
457 printf("%s: unable to establish interrupt\n",
458 sc->sc_dev.dv_xname);
459 return (1);
460 }
461
462 if (pcmcia_function_enable(sc->sc_pf)) {
463 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
464 return (1);
465 }
466
467 /*
468 * Perform any special enable magic necessary.
469 */
470 if (sc->sc_product->mp_enable != NULL &&
471 (*sc->sc_product->mp_enable)(sc) != 0) {
472 pcmcia_function_disable(sc->sc_pf);
473 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
474 return (1);
475 }
476
477 sc->sc_flags |= flag;
478 return (0);
479 }
480
481 void
482 mhzc_disable(sc, flag)
483 struct mhzc_softc *sc;
484 int flag;
485 {
486
487 if ((sc->sc_flags & flag) == 0) {
488 printf("%s: %s already disabled\n", sc->sc_dev.dv_xname,
489 (flag & MHZC_MODEM_ENABLED) ? "modem" : "ethernet");
490 panic("mhzc_disable");
491 }
492
493 sc->sc_flags &= ~flag;
494 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0)
495 return;
496
497 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
498 pcmcia_function_disable(sc->sc_pf);
499 }
500
501 /*****************************************************************************
502 * Megahertz EM3336 (and compatibles) support
503 *****************************************************************************/
504
505 int mhzc_em3336_lannid_ciscallback __P((struct pcmcia_tuple *, void *));
506 int mhzc_em3336_ascii_enaddr __P((const char *cisstr, u_int8_t *));
507
508 int
509 mhzc_em3336_enaddr(sc, myla)
510 struct mhzc_softc *sc;
511 u_int8_t *myla;
512 {
513
514 /* Get the station address from CIS tuple 0x81. */
515 if (pcmcia_scan_cis(sc->sc_dev.dv_parent,
516 mhzc_em3336_lannid_ciscallback, myla) != 1) {
517 printf("%s: unable to get Ethernet address from CIS\n",
518 sc->sc_dev.dv_xname);
519 return (0);
520 }
521
522 return (1);
523 }
524
525 int
526 mhzc_em3336_enable(sc)
527 struct mhzc_softc *sc;
528 {
529 struct pcmcia_mem_handle memh;
530 bus_addr_t memoff;
531 int memwin, reg;
532
533 /*
534 * Bring the chip to live by touching its registers in the correct
535 * way (as per my reference... the Linux smc91c92_cs.c driver by
536 * David A. Hinds).
537 */
538
539 /* Map the ISRPOWEREG. */
540 if (pcmcia_mem_alloc(sc->sc_pf, 0x1000, &memh) != 0) {
541 printf("%s: unable to allocate memory space\n",
542 sc->sc_dev.dv_xname);
543 return (1);
544 }
545
546 if (pcmcia_mem_map(sc->sc_pf, PCMCIA_MEM_ATTR, 0, 0x1000,
547 &memh, &memoff, &memwin)) {
548 printf("%s: unable to map memory space\n",
549 sc->sc_dev.dv_xname);
550 pcmcia_mem_free(sc->sc_pf, &memh);
551 return (1);
552 }
553
554 /*
555 * The magic sequence:
556 *
557 * - read/write the CCR option register.
558 * - read the ISRPOWEREG 2 times.
559 * - read/write the CCR option register again.
560 */
561
562 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
563 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
564
565 reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
566 delay(5);
567 reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
568
569 delay(200000);
570
571 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
572 delay(5);
573 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
574
575 pcmcia_mem_unmap(sc->sc_pf, memwin);
576 pcmcia_mem_free(sc->sc_pf, &memh);
577
578 return (0);
579 }
580
581 int
582 mhzc_em3336_lannid_ciscallback(tuple, arg)
583 struct pcmcia_tuple *tuple;
584 void *arg;
585 {
586 u_int8_t *myla = arg, addr_str[ETHER_ADDR_LEN * 2];
587 int i;
588
589 if (tuple->code == 0x81) {
590 /*
591 * We have a string-encoded address. Length includes
592 * terminating 0xff.
593 */
594 if (tuple->length != (ETHER_ADDR_LEN * 2) + 1)
595 return (0);
596
597 for (i = 0; i < tuple->length - 1; i++)
598 addr_str[i] = pcmcia_tuple_read_1(tuple, i);
599
600 /*
601 * Decode the string into `myla'.
602 */
603 return (mhzc_em3336_ascii_enaddr(addr_str, myla));
604 }
605 return (0);
606 }
607
608 /* XXX This should be shared w/ if_sm_pcmcia.c */
609 int
610 mhzc_em3336_ascii_enaddr(cisstr, myla)
611 const char *cisstr;
612 u_int8_t *myla;
613 {
614 u_int8_t digit;
615 int i;
616
617 memset(myla, 0, ETHER_ADDR_LEN);
618
619 for (i = 0, digit = 0; i < (ETHER_ADDR_LEN * 2); i++) {
620 if (cisstr[i] >= '0' && cisstr[i] <= '9')
621 digit |= cisstr[i] - '0';
622 else if (cisstr[i] >= 'a' && cisstr[i] <= 'f')
623 digit |= (cisstr[i] - 'a') + 10;
624 else if (cisstr[i] >= 'A' && cisstr[i] <= 'F')
625 digit |= (cisstr[i] - 'A') + 10;
626 else {
627 /* Bogus digit!! */
628 return (0);
629 }
630
631 /* Compensate for ordering of digits. */
632 if (i & 1) {
633 myla[i >> 1] = digit;
634 digit = 0;
635 } else
636 digit <<= 4;
637 }
638
639 return (1);
640 }
641
642 /****** Here begins the com attachment code. ******/
643
644 #if NCOM_MHZC > 0
645 int com_mhzc_match __P((struct device *, struct cfdata *, void *));
646 void com_mhzc_attach __P((struct device *, struct device *, void *));
647
648 /* No mhzc-specific goo in the softc; it's all in the parent. */
649 struct cfattach com_mhzc_ca = {
650 sizeof(struct com_softc), com_mhzc_match, com_mhzc_attach,
651 com_detach, com_activate
652 };
653
654 int com_mhzc_enable __P((struct com_softc *));
655 void com_mhzc_disable __P((struct com_softc *));
656
657 int
658 com_mhzc_match(parent, match, aux)
659 struct device *parent;
660 struct cfdata *match;
661 void *aux;
662 {
663 extern struct cfdriver com_cd;
664 const char *name = aux;
665
666 /* Device is always present. */
667 if (strcmp(name, com_cd.cd_name) == 0)
668 return (1);
669
670 return (0);
671 }
672
673 void
674 com_mhzc_attach(parent, self, aux)
675 struct device *parent, *self;
676 void *aux;
677 {
678 struct com_softc *sc = (void *)self;
679 struct mhzc_softc *msc = (void *)parent;
680
681 printf(":");
682 if (pcmcia_io_map(msc->sc_pf, PCMCIA_WIDTH_IO8, 0,
683 msc->sc_modem_pcioh.size, &msc->sc_modem_pcioh,
684 &msc->sc_modem_io_window)) {
685 printf("unable to map I/O space\n");
686 return;
687 }
688
689 msc->sc_flags |= MHZC_MODEM_MAPPED;
690
691 sc->sc_iot = msc->sc_modem_pcioh.iot;
692 sc->sc_ioh = msc->sc_modem_pcioh.ioh;
693
694 sc->enabled = 1;
695
696 sc->sc_iobase = -1;
697 sc->sc_frequency = COM_FREQ;
698
699 sc->enable = com_mhzc_enable;
700 sc->disable = com_mhzc_disable;
701
702 com_attach_subr(sc);
703
704 sc->enabled = 0;
705 }
706
707 int
708 com_mhzc_enable(sc)
709 struct com_softc *sc;
710 {
711
712 return (mhzc_enable((struct mhzc_softc *)sc->sc_dev.dv_parent,
713 MHZC_MODEM_ENABLED));
714 }
715
716 void
717 com_mhzc_disable(sc)
718 struct com_softc *sc;
719 {
720
721 mhzc_disable((struct mhzc_softc *)sc->sc_dev.dv_parent,
722 MHZC_MODEM_ENABLED);
723 }
724
725 #endif /* NCOM_MHZC > 0 */
726
727 /****** Here begins the sm attachment code. ******/
728
729 #if NSM_MHZC > 0
730 int sm_mhzc_match __P((struct device *, struct cfdata *, void *));
731 void sm_mhzc_attach __P((struct device *, struct device *, void *));
732 int sm_mhzc_detach __P((struct device *, int));
733
734 /* No mhzc-specific goo in the softc; it's all in the parent. */
735 struct cfattach sm_mhzc_ca = {
736 sizeof(struct smc91cxx_softc), sm_mhzc_match, sm_mhzc_attach,
737 sm_mhzc_detach, smc91cxx_activate
738 };
739
740 int sm_mhzc_enable __P((struct smc91cxx_softc *));
741 void sm_mhzc_disable __P((struct smc91cxx_softc *));
742
743 int
744 sm_mhzc_match(parent, match, aux)
745 struct device *parent;
746 struct cfdata *match;
747 void *aux;
748 {
749 extern struct cfdriver sm_cd;
750 const char *name = aux;
751
752 /* Device is always present. */
753 if (strcmp(name, sm_cd.cd_name) == 0)
754 return (1);
755
756 return (0);
757 }
758
759 void
760 sm_mhzc_attach(parent, self, aux)
761 struct device *parent, *self;
762 void *aux;
763 {
764 struct smc91cxx_softc *sc = (void *)self;
765 struct mhzc_softc *msc = (void *)parent;
766 u_int8_t myla[ETHER_ADDR_LEN];
767
768 printf(":");
769 if (pcmcia_io_map(msc->sc_pf, PCMCIA_WIDTH_IO16, 0,
770 msc->sc_ethernet_pcioh.size, &msc->sc_ethernet_pcioh,
771 &msc->sc_ethernet_io_window)) {
772 printf("unable to map I/O space\n");
773 return;
774 }
775 printf("\n");
776
777 msc->sc_flags |= MHZC_ETHERNET_MAPPED;
778
779 sc->sc_bst = msc->sc_ethernet_pcioh.iot;
780 sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
781
782 sc->sc_enable = sm_mhzc_enable;
783 sc->sc_disable = sm_mhzc_disable;
784
785 if ((*msc->sc_product->mp_enaddr)(msc, myla) != 1)
786 return;
787
788 /* Perform generic initialization. */
789 smc91cxx_attach(sc, myla);
790 }
791
792 int
793 sm_mhzc_detach(self, flags)
794 struct device *self;
795 int flags;
796 {
797 #ifdef notyet
798 struct smc91cxx_softc *sc = (void *)self;
799
800 /*
801 * Our softc is about to go away, so drop our reference
802 * to the ifnet.
803 */
804 if_delref(sc->sc_ec.ec_if);
805 return (0);
806 #else
807 return (EBUSY);
808 #endif
809 }
810
811 int
812 sm_mhzc_enable(sc)
813 struct smc91cxx_softc *sc;
814 {
815
816 return (mhzc_enable((struct mhzc_softc *)sc->sc_dev.dv_parent,
817 MHZC_ETHERNET_ENABLED));
818 }
819
820 void
821 sm_mhzc_disable(sc)
822 struct smc91cxx_softc *sc;
823 {
824
825 mhzc_disable((struct mhzc_softc *)sc->sc_dev.dv_parent,
826 MHZC_ETHERNET_ENABLED);
827 }
828
829 #endif /* NSM_MHZC > 0 */
830