mhzc.c revision 1.1 1 /* $NetBSD: mhzc.c,v 1.1 1999/09/28 17:58:55 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 * Perform any special enable magic necessary.
468 */
469 if (sc->sc_product->mp_enable != NULL &&
470 (*sc->sc_product->mp_enable)(sc) != 0)
471 return (1);
472
473 /*
474 * Establish our interrupt handler.
475 *
476 * XXX Note, we establish this at IPL_NET. This is suboptimal
477 * XXX the Modem portion, but is necessary to make the Ethernet
478 * XXX portion have the correct interrupt level semantics.
479 *
480 * XXX Eventually we should use the `enabled' bits in the
481 * XXX flags word to determine which level we should be at.
482 */
483 sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET,
484 mhzc_intr, sc);
485 if (sc->sc_ih == NULL) {
486 printf("%s: unable to establish interrupt\n",
487 sc->sc_dev.dv_xname);
488 return (1);
489 }
490
491 if (pcmcia_function_enable(sc->sc_pf)) {
492 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
493 return (1);
494 }
495
496 sc->sc_flags |= flag;
497 return (0);
498 }
499
500 void
501 mhzc_disable(sc, flag)
502 struct mhzc_softc *sc;
503 int flag;
504 {
505
506 if ((sc->sc_flags & flag) == 0) {
507 printf("%s: %s already disabled\n", sc->sc_dev.dv_xname,
508 (flag & MHZC_MODEM_ENABLED) ? "modem" : "ethernet");
509 panic("mhzc_disable");
510 }
511
512 sc->sc_flags &= ~flag;
513 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0)
514 return;
515
516 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
517 pcmcia_function_disable(sc->sc_pf);
518 }
519
520 /*****************************************************************************
521 * Megahertz EM3336 (and compatibles) support
522 *****************************************************************************/
523
524 int mhzc_em3336_lannid_ciscallback __P((struct pcmcia_tuple *, void *));
525 int mhzc_em3336_ascii_enaddr __P((const char *cisstr, u_int8_t *));
526
527 int
528 mhzc_em3336_enaddr(sc, myla)
529 struct mhzc_softc *sc;
530 u_int8_t *myla;
531 {
532
533 /* Get the station address from CIS tuple 0x81. */
534 if (pcmcia_scan_cis(sc->sc_dev.dv_parent,
535 mhzc_em3336_lannid_ciscallback, myla) != 1) {
536 printf("%s: unable to get Ethernet address from CIS\n",
537 sc->sc_dev.dv_xname);
538 return (0);
539 }
540
541 return (1);
542 }
543
544 int
545 mhzc_em3336_enable(sc)
546 struct mhzc_softc *sc;
547 {
548 struct pcmcia_mem_handle memh;
549 bus_addr_t memoff;
550 int memwin, reg;
551
552 /*
553 * Bring the chip to live by touching its registers in the correct
554 * way (as per my reference... the Linux smc91c92_cs.c driver by
555 * David A. Hinds).
556 */
557
558 /* Map the ISRPOWEREG. */
559 if (pcmcia_mem_alloc(sc->sc_pf, 0x1000, &memh) != 0) {
560 printf("%s: unable to allocate memory space\n",
561 sc->sc_dev.dv_xname);
562 return (1);
563 }
564
565 if (pcmcia_mem_map(sc->sc_pf, PCMCIA_MEM_ATTR, 0, 0x1000,
566 &memh, &memoff, &memwin)) {
567 printf("%s: unable to map memory space\n",
568 sc->sc_dev.dv_xname);
569 pcmcia_mem_free(sc->sc_pf, &memh);
570 return (1);
571 }
572
573 /*
574 * The magic sequence:
575 *
576 * - read/write the CCR option register.
577 * - read the ISRPOWEREG 2 times.
578 * - read/write the CCR option register again.
579 */
580
581 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
582 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
583
584 reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
585 delay(5);
586 reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
587
588 delay(200000);
589
590 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
591 delay(5);
592 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
593
594 pcmcia_mem_unmap(sc->sc_pf, memwin);
595 pcmcia_mem_free(sc->sc_pf, &memh);
596
597 return (0);
598 }
599
600 int
601 mhzc_em3336_lannid_ciscallback(tuple, arg)
602 struct pcmcia_tuple *tuple;
603 void *arg;
604 {
605 u_int8_t *myla = arg, addr_str[ETHER_ADDR_LEN * 2];
606 int i;
607
608 if (tuple->code == 0x81) {
609 /*
610 * We have a string-encoded address. Length includes
611 * terminating 0xff.
612 */
613 if (tuple->length != (ETHER_ADDR_LEN * 2) + 1)
614 return (0);
615
616 for (i = 0; i < tuple->length - 1; i++)
617 addr_str[i] = pcmcia_tuple_read_1(tuple, i);
618
619 /*
620 * Decode the string into `myla'.
621 */
622 return (mhzc_em3336_ascii_enaddr(addr_str, myla));
623 }
624 return (0);
625 }
626
627 /* XXX This should be shared w/ if_sm_pcmcia.c */
628 int
629 mhzc_em3336_ascii_enaddr(cisstr, myla)
630 const char *cisstr;
631 u_int8_t *myla;
632 {
633 u_int8_t digit;
634 int i;
635
636 memset(myla, 0, ETHER_ADDR_LEN);
637
638 for (i = 0, digit = 0; i < (ETHER_ADDR_LEN * 2); i++) {
639 if (cisstr[i] >= '0' && cisstr[i] <= '9')
640 digit |= cisstr[i] - '0';
641 else if (cisstr[i] >= 'a' && cisstr[i] <= 'f')
642 digit |= (cisstr[i] - 'a') + 10;
643 else if (cisstr[i] >= 'A' && cisstr[i] <= 'F')
644 digit |= (cisstr[i] - 'A') + 10;
645 else {
646 /* Bogus digit!! */
647 return (0);
648 }
649
650 /* Compensate for ordering of digits. */
651 if (i & 1) {
652 myla[i >> 1] = digit;
653 digit = 0;
654 } else
655 digit <<= 4;
656 }
657
658 return (1);
659 }
660
661 /****** Here begins the com attachment code. ******/
662
663 #if NCOM_MHZC > 0
664 int com_mhzc_match __P((struct device *, struct cfdata *, void *));
665 void com_mhzc_attach __P((struct device *, struct device *, void *));
666
667 /* No mhzc-specific goo in the softc; it's all in the parent. */
668 struct cfattach com_mhzc_ca = {
669 sizeof(struct com_softc), com_mhzc_match, com_mhzc_attach,
670 com_detach, com_activate
671 };
672
673 int com_mhzc_enable __P((struct com_softc *));
674 void com_mhzc_disable __P((struct com_softc *));
675
676 int
677 com_mhzc_match(parent, match, aux)
678 struct device *parent;
679 struct cfdata *match;
680 void *aux;
681 {
682 extern struct cfdriver com_cd;
683 const char *name = aux;
684
685 /* Device is always present. */
686 if (strcmp(name, com_cd.cd_name) == 0)
687 return (1);
688
689 return (0);
690 }
691
692 void
693 com_mhzc_attach(parent, self, aux)
694 struct device *parent, *self;
695 void *aux;
696 {
697 struct com_softc *sc = (void *)self;
698 struct mhzc_softc *msc = (void *)parent;
699
700 printf(":");
701 if (pcmcia_io_map(msc->sc_pf, PCMCIA_WIDTH_IO8, 0,
702 msc->sc_modem_pcioh.size, &msc->sc_modem_pcioh,
703 &msc->sc_modem_io_window)) {
704 printf("unable to map I/O space\n");
705 return;
706 }
707
708 msc->sc_flags |= MHZC_MODEM_MAPPED;
709
710 sc->sc_iot = msc->sc_modem_pcioh.iot;
711 sc->sc_ioh = msc->sc_modem_pcioh.ioh;
712
713 sc->enabled = 1;
714
715 sc->sc_iobase = -1;
716 sc->sc_frequency = COM_FREQ;
717
718 sc->enable = com_mhzc_enable;
719 sc->disable = com_mhzc_disable;
720
721 com_attach_subr(sc);
722
723 sc->enabled = 0;
724 }
725
726 int
727 com_mhzc_enable(sc)
728 struct com_softc *sc;
729 {
730
731 return (mhzc_enable((struct mhzc_softc *)sc->sc_dev.dv_parent,
732 MHZC_MODEM_ENABLED));
733 }
734
735 void
736 com_mhzc_disable(sc)
737 struct com_softc *sc;
738 {
739
740 mhzc_disable((struct mhzc_softc *)sc->sc_dev.dv_parent,
741 MHZC_MODEM_ENABLED);
742 }
743
744 #endif /* NCOM_MHZC > 0 */
745
746 /****** Here begins the sm attachment code. ******/
747
748 #if NSM_MHZC > 0
749 int sm_mhzc_match __P((struct device *, struct cfdata *, void *));
750 void sm_mhzc_attach __P((struct device *, struct device *, void *));
751 int sm_mhzc_detach __P((struct device *, int));
752
753 /* No mhzc-specific goo in the softc; it's all in the parent. */
754 struct cfattach sm_mhzc_ca = {
755 sizeof(struct smc91cxx_softc), sm_mhzc_match, sm_mhzc_attach,
756 sm_mhzc_detach, smc91cxx_activate
757 };
758
759 int sm_mhzc_enable __P((struct smc91cxx_softc *));
760 void sm_mhzc_disable __P((struct smc91cxx_softc *));
761
762 int
763 sm_mhzc_match(parent, match, aux)
764 struct device *parent;
765 struct cfdata *match;
766 void *aux;
767 {
768 extern struct cfdriver sm_cd;
769 const char *name = aux;
770
771 /* Device is always present. */
772 if (strcmp(name, sm_cd.cd_name) == 0)
773 return (1);
774
775 return (0);
776 }
777
778 void
779 sm_mhzc_attach(parent, self, aux)
780 struct device *parent, *self;
781 void *aux;
782 {
783 struct smc91cxx_softc *sc = (void *)self;
784 struct mhzc_softc *msc = (void *)parent;
785 u_int8_t myla[ETHER_ADDR_LEN];
786
787 printf(":");
788 if (pcmcia_io_map(msc->sc_pf, PCMCIA_WIDTH_IO16, 0,
789 msc->sc_ethernet_pcioh.size, &msc->sc_ethernet_pcioh,
790 &msc->sc_ethernet_io_window)) {
791 printf("unable to map I/O space\n");
792 return;
793 }
794 printf("\n");
795
796 msc->sc_flags |= MHZC_ETHERNET_MAPPED;
797
798 sc->sc_bst = msc->sc_ethernet_pcioh.iot;
799 sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
800
801 sc->sc_enable = sm_mhzc_enable;
802 sc->sc_disable = sm_mhzc_disable;
803
804 if ((*msc->sc_product->mp_enaddr)(msc, myla) != 1)
805 return;
806
807 /* Perform generic initialization. */
808 smc91cxx_attach(sc, myla);
809 }
810
811 int
812 sm_mhzc_detach(self, flags)
813 struct device *self;
814 int flags;
815 {
816 #ifdef notyet
817 struct smc91cxx_softc *sc = (void *)self;
818
819 /*
820 * Our softc is about to go away, so drop our reference
821 * to the ifnet.
822 */
823 if_delref(sc->sc_ec.ec_if);
824 return (0);
825 #else
826 return (EBUSY);
827 #endif
828 }
829
830 int
831 sm_mhzc_enable(sc)
832 struct smc91cxx_softc *sc;
833 {
834
835 return (mhzc_enable((struct mhzc_softc *)sc->sc_dev.dv_parent,
836 MHZC_ETHERNET_ENABLED));
837 }
838
839 void
840 sm_mhzc_disable(sc)
841 struct smc91cxx_softc *sc;
842 {
843
844 mhzc_disable((struct mhzc_softc *)sc->sc_dev.dv_parent,
845 MHZC_ETHERNET_ENABLED);
846 }
847
848 #endif /* NSM_MHZC > 0 */
849