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