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