mhzc.c revision 1.2 1 /* $NetBSD: mhzc.c,v 1.2 1999/09/28 22:46:43 thorpej Exp $ */
2
3 /*-
4 * Copyright (c) 1999 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 * NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*
41 * 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 struct mhzc_product {
146 u_int32_t mp_vendor; /* PCMCIA vendor ID */
147 u_int32_t mp_product; /* PCMCIA product ID */
148 int mp_expfunc; /* expected function number */
149 const char *mp_name; /* device name */
150
151 /* Get the Ethernet address for this card. */
152 int (*mp_enaddr) __P((struct mhzc_softc *, u_int8_t *));
153
154 /* Perform any special `enable' magic. */
155 int (*mp_enable) __P((struct mhzc_softc *));
156 } mhzc_products[] = {
157 { PCMCIA_VENDOR_MEGAHERTZ, PCMCIA_PRODUCT_MEGAHERTZ_XJEM3336,
158 0, PCMCIA_STR_MEGAHERTZ_XJEM3336,
159 mhzc_em3336_enaddr, mhzc_em3336_enable },
160
161 /*
162 * Eventually we could add support for other Ethernet/Modem
163 * combo cards, even if they're aren't Megahertz, because
164 * most of them work more or less the same way.
165 */
166
167 { 0, 0,
168 0, NULL,
169 NULL, NULL },
170 };
171
172 int mhzc_print __P((void *, const char *));
173
174 int mhzc_check_cfe __P((struct mhzc_softc *, struct pcmcia_config_entry *));
175 int mhzc_alloc_ethernet __P((struct mhzc_softc *));
176
177 int mhzc_enable __P((struct mhzc_softc *, int));
178 void mhzc_disable __P((struct mhzc_softc *, int));
179
180 int mhzc_intr __P((void *));
181
182 const struct mhzc_product *mhzc_lookup __P((const struct pcmcia_attach_args *));
183
184 const struct mhzc_product *
185 mhzc_lookup(pa)
186 const struct pcmcia_attach_args *pa;
187 {
188 const struct mhzc_product *mp;
189
190 for (mp = mhzc_products; mp->mp_name != NULL; mp++) {
191 if (pa->manufacturer == mp->mp_vendor &&
192 pa->product == mp->mp_product &&
193 pa->pf->number == mp->mp_expfunc)
194 return (mp);
195 }
196 return (NULL);
197 }
198
199 int
200 mhzc_match(parent, match, aux)
201 struct device *parent;
202 struct cfdata *match;
203 void *aux;
204 {
205 struct pcmcia_attach_args *pa = aux;
206
207 if (mhzc_lookup(pa) != NULL)
208 return (10); /* beat `com' */
209
210 return (0);
211 }
212
213 void
214 mhzc_attach(parent, self, aux)
215 struct device *parent, *self;
216 void *aux;
217 {
218 struct mhzc_softc *sc = (void *)self;
219 struct pcmcia_attach_args *pa = aux;
220 struct pcmcia_config_entry *cfe;
221
222 sc->sc_pf = pa->pf;
223
224 sc->sc_product = mhzc_lookup(pa);
225 if (sc->sc_product == NULL) {
226 printf("\n");
227 panic("mhzc_attach: impossible");
228 }
229
230 printf(": %s\n", sc->sc_product->mp_name);
231
232 /*
233 * The address decoders on these cards are wacky. The configuration
234 * entries are set up to look like serial ports, and have no
235 * information about the Ethernet portion. In order to talk to
236 * the Modem portion, the I/O address must have bit 0x80 set.
237 * In order to talk to the Ethernet portion, the I/O address must
238 * have the 0x80 bit clear.
239 *
240 * The standard configuration entries conveniently have 0x80 set
241 * in them, and have a length of 8 (a 16550's size, convenient!),
242 * so we use those to set up the Modem portion.
243 *
244 * Once we have the Modem's address established, we search for
245 * an address suitable for the Ethernet portion. We do this by
246 * rounding up to the next 16-byte aligned address where 0x80
247 * isn't set (the SMC Ethernet chip has a 16-byte address size)
248 * and attemping to allocate a 16-byte region until we succeed.
249 *
250 * Sure would have been nice if Megahertz had made the card a
251 * proper multi-function device.
252 */
253 for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
254 cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
255 if (mhzc_check_cfe(sc, cfe)) {
256 /* Found one! */
257 break;
258 }
259 }
260 if (cfe == NULL) {
261 printf("%s: unable to find suitable config table entry\n",
262 sc->sc_dev.dv_xname);
263 return;
264 }
265
266 if (mhzc_alloc_ethernet(sc) == 0) {
267 printf("%s: unable to allocate space for Ethernet portion\n",
268 sc->sc_dev.dv_xname);
269 return;
270 }
271
272 /* Enable the card. */
273 pcmcia_function_init(pa->pf, cfe);
274 if (pcmcia_function_enable(pa->pf)) {
275 printf(": function enable failed\n");
276 return;
277 }
278
279 if (sc->sc_product->mp_enable != NULL)
280 (*sc->sc_product->mp_enable)(sc);
281
282 sc->sc_modem = config_found(&sc->sc_dev, "com", mhzc_print);
283 sc->sc_ethernet = config_found(&sc->sc_dev, "sm", mhzc_print);
284
285 pcmcia_function_disable(pa->pf);
286 }
287
288 int
289 mhzc_check_cfe(sc, cfe)
290 struct mhzc_softc *sc;
291 struct pcmcia_config_entry *cfe;
292 {
293
294 if (cfe->num_memspace != 0)
295 return (0);
296
297 if (cfe->num_iospace != 1)
298 return (0);
299
300 if (pcmcia_io_alloc(sc->sc_pf,
301 cfe->iospace[0].start,
302 cfe->iospace[0].length,
303 cfe->iospace[0].length,
304 &sc->sc_modem_pcioh) == 0) {
305 /* Found one for the modem! */
306 return (1);
307 }
308
309 return (0);
310 }
311
312 int
313 mhzc_alloc_ethernet(sc)
314 struct mhzc_softc *sc;
315 {
316 bus_addr_t addr, maxaddr;
317
318 maxaddr = sc->sc_pf->sc->iobase + sc->sc_pf->sc->iosize;
319
320 /*
321 * Start with the first address past the Modem.
322 */
323 addr = sc->sc_modem_pcioh.addr + sc->sc_modem_pcioh.size;
324
325 /*
326 * Now round it up so that it starts on a 16-byte boundary.
327 */
328 addr = roundup(addr, 0x10);
329
330 for (; (addr + 0x10) < maxaddr; addr += 0x10) {
331 if (addr & 0x80)
332 continue;
333 if (pcmcia_io_alloc(sc->sc_pf, addr, 0x10, 0x10,
334 &sc->sc_ethernet_pcioh) == 0) {
335 /* Found one for the ethernet! */
336 return (1);
337 }
338 }
339
340 /*
341 * Weren't able to allocate space for the Ethernet, so we
342 * free the Modem's I/O space.
343 */
344 pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
345 return (0);
346 }
347
348 int
349 mhzc_print(aux, pnp)
350 void *aux;
351 const char *pnp;
352 {
353 const char *name = aux;
354
355 if (pnp)
356 printf("%s at %s", name, pnp);
357
358 return (UNCONF);
359 }
360
361 int
362 mhzc_detach(self, flags)
363 struct device *self;
364 int flags;
365 {
366 struct mhzc_softc *sc = (void *)self;
367 int rv;
368
369 if (sc->sc_ethernet != NULL) {
370 rv = config_detach(sc->sc_ethernet, flags);
371 if (rv != 0)
372 return (rv);
373 }
374
375 if (sc->sc_modem != NULL) {
376 rv = config_detach(sc->sc_modem, flags);
377 if (rv != 0)
378 return (rv);
379 }
380
381 /* Unmap our i/o windows. */
382 if (sc->sc_flags & MHZC_MODEM_MAPPED)
383 pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window);
384 if (sc->sc_flags & MHZC_ETHERNET_MAPPED)
385 pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window);
386
387 /* Free our i/o spaces. */
388 pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
389 pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
390
391 return (0);
392 }
393
394 int
395 mhzc_activate(self, act)
396 struct device *self;
397 enum devact act;
398 {
399 struct mhzc_softc *sc = (void *)self;
400 int s, rv = 0;
401
402 s = splhigh();
403 switch (act) {
404 case DVACT_ACTIVATE:
405 rv = EOPNOTSUPP;
406 break;
407
408 case DVACT_DEACTIVATE:
409 if (sc->sc_ethernet != NULL) {
410 rv = config_deactivate(sc->sc_ethernet);
411 if (rv != 0)
412 goto out;
413 }
414
415 if (sc->sc_modem != NULL) {
416 rv = config_deactivate(sc->sc_modem);
417 if (rv != 0)
418 goto out;
419 }
420 break;
421 }
422 out:
423 splx(s);
424 return (rv);
425 }
426
427 int
428 mhzc_intr(arg)
429 void *arg;
430 {
431 struct mhzc_softc *sc = arg;
432 int rval = 0;
433
434 #if NCOM_MHZC > 0
435 if (sc->sc_modem != NULL &&
436 (sc->sc_flags & MHZC_MODEM_ENABLED) != 0)
437 rval |= comintr(sc->sc_modem);
438 #endif
439
440 #if NSM_MHZC > 0
441 if (sc->sc_ethernet != NULL &&
442 (sc->sc_flags & MHZC_ETHERNET_ENABLED) != 0)
443 rval |= smc91cxx_intr(sc->sc_ethernet);
444 #endif
445
446 return (rval);
447 }
448
449 int
450 mhzc_enable(sc, flag)
451 struct mhzc_softc *sc;
452 int flag;
453 {
454
455 if (sc->sc_flags & flag) {
456 printf("%s: %s already enabled\n", sc->sc_dev.dv_xname,
457 (flag & MHZC_MODEM_ENABLED) ? "modem" : "ethernet");
458 panic("mhzc_enable");
459 }
460
461 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0) {
462 sc->sc_flags |= flag;
463 return (0);
464 }
465
466 /*
467 * Establish our interrupt handler.
468 *
469 * XXX Note, we establish this at IPL_NET. This is suboptimal
470 * XXX the Modem portion, but is necessary to make the Ethernet
471 * XXX portion have the correct interrupt level semantics.
472 *
473 * XXX Eventually we should use the `enabled' bits in the
474 * XXX flags word to determine which level we should be at.
475 */
476 sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET,
477 mhzc_intr, sc);
478 if (sc->sc_ih == NULL) {
479 printf("%s: unable to establish interrupt\n",
480 sc->sc_dev.dv_xname);
481 return (1);
482 }
483
484 if (pcmcia_function_enable(sc->sc_pf)) {
485 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
486 return (1);
487 }
488
489 /*
490 * Perform any special enable magic necessary.
491 */
492 if (sc->sc_product->mp_enable != NULL &&
493 (*sc->sc_product->mp_enable)(sc) != 0) {
494 pcmcia_function_disable(sc->sc_pf);
495 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
496 return (1);
497 }
498
499 sc->sc_flags |= flag;
500 return (0);
501 }
502
503 void
504 mhzc_disable(sc, flag)
505 struct mhzc_softc *sc;
506 int flag;
507 {
508
509 if ((sc->sc_flags & flag) == 0) {
510 printf("%s: %s already disabled\n", sc->sc_dev.dv_xname,
511 (flag & MHZC_MODEM_ENABLED) ? "modem" : "ethernet");
512 panic("mhzc_disable");
513 }
514
515 sc->sc_flags &= ~flag;
516 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0)
517 return;
518
519 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
520 pcmcia_function_disable(sc->sc_pf);
521 }
522
523 /*****************************************************************************
524 * Megahertz EM3336 (and compatibles) support
525 *****************************************************************************/
526
527 int mhzc_em3336_lannid_ciscallback __P((struct pcmcia_tuple *, void *));
528 int mhzc_em3336_ascii_enaddr __P((const char *cisstr, u_int8_t *));
529
530 int
531 mhzc_em3336_enaddr(sc, myla)
532 struct mhzc_softc *sc;
533 u_int8_t *myla;
534 {
535
536 /* Get the station address from CIS tuple 0x81. */
537 if (pcmcia_scan_cis(sc->sc_dev.dv_parent,
538 mhzc_em3336_lannid_ciscallback, myla) != 1) {
539 printf("%s: unable to get Ethernet address from CIS\n",
540 sc->sc_dev.dv_xname);
541 return (0);
542 }
543
544 return (1);
545 }
546
547 int
548 mhzc_em3336_enable(sc)
549 struct mhzc_softc *sc;
550 {
551 struct pcmcia_mem_handle memh;
552 bus_addr_t memoff;
553 int memwin, reg;
554
555 /*
556 * Bring the chip to live by touching its registers in the correct
557 * way (as per my reference... the Linux smc91c92_cs.c driver by
558 * David A. Hinds).
559 */
560
561 /* Map the ISRPOWEREG. */
562 if (pcmcia_mem_alloc(sc->sc_pf, 0x1000, &memh) != 0) {
563 printf("%s: unable to allocate memory space\n",
564 sc->sc_dev.dv_xname);
565 return (1);
566 }
567
568 if (pcmcia_mem_map(sc->sc_pf, PCMCIA_MEM_ATTR, 0, 0x1000,
569 &memh, &memoff, &memwin)) {
570 printf("%s: unable to map memory space\n",
571 sc->sc_dev.dv_xname);
572 pcmcia_mem_free(sc->sc_pf, &memh);
573 return (1);
574 }
575
576 /*
577 * The magic sequence:
578 *
579 * - read/write the CCR option register.
580 * - read the ISRPOWEREG 2 times.
581 * - read/write the CCR option register again.
582 */
583
584 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
585 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
586
587 reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
588 delay(5);
589 reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
590
591 delay(200000);
592
593 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
594 delay(5);
595 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
596
597 pcmcia_mem_unmap(sc->sc_pf, memwin);
598 pcmcia_mem_free(sc->sc_pf, &memh);
599
600 return (0);
601 }
602
603 int
604 mhzc_em3336_lannid_ciscallback(tuple, arg)
605 struct pcmcia_tuple *tuple;
606 void *arg;
607 {
608 u_int8_t *myla = arg, addr_str[ETHER_ADDR_LEN * 2];
609 int i;
610
611 if (tuple->code == 0x81) {
612 /*
613 * We have a string-encoded address. Length includes
614 * terminating 0xff.
615 */
616 if (tuple->length != (ETHER_ADDR_LEN * 2) + 1)
617 return (0);
618
619 for (i = 0; i < tuple->length - 1; i++)
620 addr_str[i] = pcmcia_tuple_read_1(tuple, i);
621
622 /*
623 * Decode the string into `myla'.
624 */
625 return (mhzc_em3336_ascii_enaddr(addr_str, myla));
626 }
627 return (0);
628 }
629
630 /* XXX This should be shared w/ if_sm_pcmcia.c */
631 int
632 mhzc_em3336_ascii_enaddr(cisstr, myla)
633 const char *cisstr;
634 u_int8_t *myla;
635 {
636 u_int8_t digit;
637 int i;
638
639 memset(myla, 0, ETHER_ADDR_LEN);
640
641 for (i = 0, digit = 0; i < (ETHER_ADDR_LEN * 2); i++) {
642 if (cisstr[i] >= '0' && cisstr[i] <= '9')
643 digit |= cisstr[i] - '0';
644 else if (cisstr[i] >= 'a' && cisstr[i] <= 'f')
645 digit |= (cisstr[i] - 'a') + 10;
646 else if (cisstr[i] >= 'A' && cisstr[i] <= 'F')
647 digit |= (cisstr[i] - 'A') + 10;
648 else {
649 /* Bogus digit!! */
650 return (0);
651 }
652
653 /* Compensate for ordering of digits. */
654 if (i & 1) {
655 myla[i >> 1] = digit;
656 digit = 0;
657 } else
658 digit <<= 4;
659 }
660
661 return (1);
662 }
663
664 /****** Here begins the com attachment code. ******/
665
666 #if NCOM_MHZC > 0
667 int com_mhzc_match __P((struct device *, struct cfdata *, void *));
668 void com_mhzc_attach __P((struct device *, struct device *, void *));
669
670 /* No mhzc-specific goo in the softc; it's all in the parent. */
671 struct cfattach com_mhzc_ca = {
672 sizeof(struct com_softc), com_mhzc_match, com_mhzc_attach,
673 com_detach, com_activate
674 };
675
676 int com_mhzc_enable __P((struct com_softc *));
677 void com_mhzc_disable __P((struct com_softc *));
678
679 int
680 com_mhzc_match(parent, match, aux)
681 struct device *parent;
682 struct cfdata *match;
683 void *aux;
684 {
685 extern struct cfdriver com_cd;
686 const char *name = aux;
687
688 /* Device is always present. */
689 if (strcmp(name, com_cd.cd_name) == 0)
690 return (1);
691
692 return (0);
693 }
694
695 void
696 com_mhzc_attach(parent, self, aux)
697 struct device *parent, *self;
698 void *aux;
699 {
700 struct com_softc *sc = (void *)self;
701 struct mhzc_softc *msc = (void *)parent;
702
703 printf(":");
704 if (pcmcia_io_map(msc->sc_pf, PCMCIA_WIDTH_IO8, 0,
705 msc->sc_modem_pcioh.size, &msc->sc_modem_pcioh,
706 &msc->sc_modem_io_window)) {
707 printf("unable to map I/O space\n");
708 return;
709 }
710
711 msc->sc_flags |= MHZC_MODEM_MAPPED;
712
713 sc->sc_iot = msc->sc_modem_pcioh.iot;
714 sc->sc_ioh = msc->sc_modem_pcioh.ioh;
715
716 sc->enabled = 1;
717
718 sc->sc_iobase = -1;
719 sc->sc_frequency = COM_FREQ;
720
721 sc->enable = com_mhzc_enable;
722 sc->disable = com_mhzc_disable;
723
724 com_attach_subr(sc);
725
726 sc->enabled = 0;
727 }
728
729 int
730 com_mhzc_enable(sc)
731 struct com_softc *sc;
732 {
733
734 return (mhzc_enable((struct mhzc_softc *)sc->sc_dev.dv_parent,
735 MHZC_MODEM_ENABLED));
736 }
737
738 void
739 com_mhzc_disable(sc)
740 struct com_softc *sc;
741 {
742
743 mhzc_disable((struct mhzc_softc *)sc->sc_dev.dv_parent,
744 MHZC_MODEM_ENABLED);
745 }
746
747 #endif /* NCOM_MHZC > 0 */
748
749 /****** Here begins the sm attachment code. ******/
750
751 #if NSM_MHZC > 0
752 int sm_mhzc_match __P((struct device *, struct cfdata *, void *));
753 void sm_mhzc_attach __P((struct device *, struct device *, void *));
754 int sm_mhzc_detach __P((struct device *, int));
755
756 /* No mhzc-specific goo in the softc; it's all in the parent. */
757 struct cfattach sm_mhzc_ca = {
758 sizeof(struct smc91cxx_softc), sm_mhzc_match, sm_mhzc_attach,
759 sm_mhzc_detach, smc91cxx_activate
760 };
761
762 int sm_mhzc_enable __P((struct smc91cxx_softc *));
763 void sm_mhzc_disable __P((struct smc91cxx_softc *));
764
765 int
766 sm_mhzc_match(parent, match, aux)
767 struct device *parent;
768 struct cfdata *match;
769 void *aux;
770 {
771 extern struct cfdriver sm_cd;
772 const char *name = aux;
773
774 /* Device is always present. */
775 if (strcmp(name, sm_cd.cd_name) == 0)
776 return (1);
777
778 return (0);
779 }
780
781 void
782 sm_mhzc_attach(parent, self, aux)
783 struct device *parent, *self;
784 void *aux;
785 {
786 struct smc91cxx_softc *sc = (void *)self;
787 struct mhzc_softc *msc = (void *)parent;
788 u_int8_t myla[ETHER_ADDR_LEN];
789
790 printf(":");
791 if (pcmcia_io_map(msc->sc_pf, PCMCIA_WIDTH_IO16, 0,
792 msc->sc_ethernet_pcioh.size, &msc->sc_ethernet_pcioh,
793 &msc->sc_ethernet_io_window)) {
794 printf("unable to map I/O space\n");
795 return;
796 }
797 printf("\n");
798
799 msc->sc_flags |= MHZC_ETHERNET_MAPPED;
800
801 sc->sc_bst = msc->sc_ethernet_pcioh.iot;
802 sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
803
804 sc->sc_enable = sm_mhzc_enable;
805 sc->sc_disable = sm_mhzc_disable;
806
807 if ((*msc->sc_product->mp_enaddr)(msc, myla) != 1)
808 return;
809
810 /* Perform generic initialization. */
811 smc91cxx_attach(sc, myla);
812 }
813
814 int
815 sm_mhzc_detach(self, flags)
816 struct device *self;
817 int flags;
818 {
819 #ifdef notyet
820 struct smc91cxx_softc *sc = (void *)self;
821
822 /*
823 * Our softc is about to go away, so drop our reference
824 * to the ifnet.
825 */
826 if_delref(sc->sc_ec.ec_if);
827 return (0);
828 #else
829 return (EBUSY);
830 #endif
831 }
832
833 int
834 sm_mhzc_enable(sc)
835 struct smc91cxx_softc *sc;
836 {
837
838 return (mhzc_enable((struct mhzc_softc *)sc->sc_dev.dv_parent,
839 MHZC_ETHERNET_ENABLED));
840 }
841
842 void
843 sm_mhzc_disable(sc)
844 struct smc91cxx_softc *sc;
845 {
846
847 mhzc_disable((struct mhzc_softc *)sc->sc_dev.dv_parent,
848 MHZC_ETHERNET_ENABLED);
849 }
850
851 #endif /* NSM_MHZC > 0 */
852