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