1 /* $NetBSD: mhzc.c,v 1.56 2023/05/10 00:12:05 riastradh 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 *
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Device driver for the Megaherz X-JACK Ethernet/Modem combo cards.
35 *
36 * Many thanks to Chuck Cranor for having the patience to sift through
37 * the Linux smc91c92_cs.c driver to find the magic details to get this
38 * working!
39 */
40
41 #include <sys/cdefs.h>
42 __KERNEL_RCSID(0, "$NetBSD: mhzc.c,v 1.56 2023/05/10 00:12:05 riastradh Exp $");
43
44 #include "opt_inet.h"
45
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/mbuf.h>
49 #include <sys/socket.h>
50 #include <sys/ioctl.h>
51 #include <sys/errno.h>
52 #include <sys/syslog.h>
53 #include <sys/select.h>
54 #include <sys/tty.h>
55 #include <sys/device.h>
56 #include <sys/kernel.h>
57 #include <sys/proc.h>
58
59 #include <net/if.h>
60 #include <net/if_dl.h>
61 #include <net/if_ether.h>
62 #include <net/if_media.h>
63 #include <net/bpf.h>
64
65 #ifdef INET
66 #include <netinet/in.h>
67 #include <netinet/in_systm.h>
68 #include <netinet/in_var.h>
69 #include <netinet/ip.h>
70 #include <netinet/if_inarp.h>
71 #endif
72
73 #include <sys/intr.h>
74 #include <sys/bus.h>
75
76 #include <dev/ic/comreg.h>
77 #include <dev/ic/comvar.h>
78
79 #include <dev/mii/mii.h>
80 #include <dev/mii/miivar.h>
81
82 #include <dev/ic/smc91cxxreg.h>
83 #include <dev/ic/smc91cxxvar.h>
84
85 #include <dev/pcmcia/pcmciareg.h>
86 #include <dev/pcmcia/pcmciavar.h>
87 #include <dev/pcmcia/pcmciadevs.h>
88
89 #include "mhzc.h"
90
91 struct mhzc_softc {
92 device_t sc_dev; /* generic device glue */
93
94 struct pcmcia_function *sc_pf; /* our PCMCIA function */
95 void *sc_ih; /* interrupt handle */
96
97 const struct mhzc_product *sc_product;
98
99 /*
100 * Data for the Modem portion.
101 */
102 device_t sc_modem;
103 struct pcmcia_io_handle sc_modem_pcioh;
104 int sc_modem_io_window;
105
106 /*
107 * Data for the Ethernet portion.
108 */
109 device_t sc_ethernet;
110 struct pcmcia_io_handle sc_ethernet_pcioh;
111 int sc_ethernet_io_window;
112
113 int sc_flags;
114 };
115
116 /* sc_flags */
117 #define MHZC_MODEM_MAPPED 0x01
118 #define MHZC_ETHERNET_MAPPED 0x02
119 #define MHZC_MODEM_ENABLED 0x04
120 #define MHZC_ETHERNET_ENABLED 0x08
121 #define MHZC_MODEM_ALLOCED 0x10
122 #define MHZC_ETHERNET_ALLOCED 0x20
123
124 int mhzc_match(device_t, cfdata_t, void *);
125 void mhzc_attach(device_t, device_t, void *);
126 void mhzc_childdet(device_t, device_t);
127 int mhzc_detach(device_t, int);
128
129 CFATTACH_DECL2_NEW(mhzc, sizeof(struct mhzc_softc),
130 mhzc_match, mhzc_attach, mhzc_detach, NULL, NULL, mhzc_childdet);
131
132 int mhzc_em3336_enaddr(struct mhzc_softc *, u_int8_t *);
133 int mhzc_em3336_enable(struct mhzc_softc *);
134
135 const struct mhzc_product {
136 struct pcmcia_product mp_product;
137
138 /* Get the Ethernet address for this card. */
139 int (*mp_enaddr)(struct mhzc_softc *, u_int8_t *);
140
141 /* Perform any special `enable' magic. */
142 int (*mp_enable)(struct mhzc_softc *);
143 } mhzc_products[] = {
144 { { PCMCIA_VENDOR_MEGAHERTZ, PCMCIA_PRODUCT_MEGAHERTZ_EM3336,
145 PCMCIA_CIS_INVALID },
146 mhzc_em3336_enaddr, mhzc_em3336_enable },
147 };
148 static const size_t mhzc_nproducts =
149 sizeof(mhzc_products) / sizeof(mhzc_products[0]);
150
151 int mhzc_print(void *, const char *);
152
153 int mhzc_check_cfe(struct mhzc_softc *, struct pcmcia_config_entry *);
154 int mhzc_alloc_ethernet(struct mhzc_softc *, struct pcmcia_config_entry *);
155
156 int mhzc_enable(struct mhzc_softc *, int);
157 void mhzc_disable(struct mhzc_softc *, int);
158
159 int mhzc_intr(void *);
160
161 int
mhzc_match(device_t parent,cfdata_t match,void * aux)162 mhzc_match(device_t parent, cfdata_t match, void *aux)
163 {
164 struct pcmcia_attach_args *pa = aux;
165
166 if (pcmcia_product_lookup(pa, mhzc_products, mhzc_nproducts,
167 sizeof(mhzc_products[0]), NULL))
168 return (2); /* beat `com' */
169 return (0);
170 }
171
172 void
mhzc_attach(device_t parent,device_t self,void * aux)173 mhzc_attach(device_t parent, device_t self, void *aux)
174 {
175 struct mhzc_softc *sc = device_private(self);
176 struct pcmcia_attach_args *pa = aux;
177 struct pcmcia_config_entry *cfe;
178 int error;
179
180 sc->sc_dev = self;
181 sc->sc_pf = pa->pf;
182
183 sc->sc_product = pcmcia_product_lookup(pa, mhzc_products,
184 mhzc_nproducts, sizeof(mhzc_products[0]), NULL);
185 if (!sc->sc_product)
186 panic("mhzc_attach: impossible");
187
188 /*
189 * The address decoders on these cards are wacky. The configuration
190 * entries are set up to look like serial ports, and have no
191 * information about the Ethernet portion. In order to talk to
192 * the Modem portion, the I/O address must have bit 0x80 set.
193 * In order to talk to the Ethernet portion, the I/O address must
194 * have the 0x80 bit clear.
195 *
196 * The standard configuration entries conveniently have 0x80 set
197 * in them, and have a length of 8 (a 16550's size, convenient!),
198 * so we use those to set up the Modem portion.
199 *
200 * Once we have the Modem's address established, we search for
201 * an address suitable for the Ethernet portion. We do this by
202 * rounding up to the next 16-byte aligned address where 0x80
203 * isn't set (the SMC Ethernet chip has a 16-byte address size)
204 * and attempting to allocate a 16-byte region until we succeed.
205 *
206 * Sure would have been nice if Megahertz had made the card a
207 * proper multi-function device.
208 */
209 SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
210 if (mhzc_check_cfe(sc, cfe)) {
211 /* Found one! */
212 break;
213 }
214 }
215 if (cfe == NULL) {
216 aprint_error_dev(self, "unable to find suitable config table entry\n");
217 goto fail;
218 }
219
220 if (mhzc_alloc_ethernet(sc, cfe) == 0) {
221 aprint_error_dev(self, "unable to allocate space for Ethernet portion\n");
222 goto fail;
223 }
224
225 /* Enable the card. */
226 pcmcia_function_init(pa->pf, cfe);
227
228 if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_IO8, &sc->sc_modem_pcioh,
229 &sc->sc_modem_io_window)) {
230 aprint_error_dev(sc->sc_dev, "unable to map I/O space\n");
231 goto fail;
232 }
233 sc->sc_flags |= MHZC_MODEM_MAPPED;
234
235 if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_AUTO, &sc->sc_ethernet_pcioh,
236 &sc->sc_ethernet_io_window)) {
237 aprint_error_dev(sc->sc_dev, "unable to map I/O space\n");
238 goto fail;
239 }
240 sc->sc_flags |= MHZC_ETHERNET_MAPPED;
241
242 error = mhzc_enable(sc, MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED);
243 if (error)
244 goto fail;
245
246 /*XXXUNCONST*/
247 sc->sc_modem = config_found(self, __UNCONST("com"), mhzc_print,
248 CFARGS_NONE);
249 /*XXXUNCONST*/
250 sc->sc_ethernet = config_found(self, __UNCONST("sm"), mhzc_print,
251 CFARGS_NONE);
252
253 mhzc_disable(sc, MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED);
254 return;
255
256 fail:
257 /* I/O spaces will be freed by detach. */
258 ;
259 }
260
261 int
mhzc_check_cfe(struct mhzc_softc * sc,struct pcmcia_config_entry * cfe)262 mhzc_check_cfe(struct mhzc_softc *sc, struct pcmcia_config_entry *cfe)
263 {
264
265 if (cfe->num_memspace != 0)
266 return (0);
267
268 if (cfe->num_iospace != 1)
269 return (0);
270
271 if (pcmcia_io_alloc(sc->sc_pf,
272 cfe->iospace[0].start,
273 cfe->iospace[0].length,
274 cfe->iospace[0].length,
275 &sc->sc_modem_pcioh) == 0) {
276 /* Found one for the modem! */
277 sc->sc_flags |= MHZC_MODEM_ALLOCED;
278 return (1);
279 }
280
281 return (0);
282 }
283
284 int
mhzc_alloc_ethernet(struct mhzc_softc * sc,struct pcmcia_config_entry * cfe)285 mhzc_alloc_ethernet(struct mhzc_softc *sc, struct pcmcia_config_entry *cfe)
286 {
287 bus_addr_t addr, maxaddr;
288
289 addr = cfe->iospace[0].start + cfe->iospace[0].length;
290 maxaddr = 0x1000;
291
292 /*
293 * Now round it up so that it starts on a 16-byte boundary.
294 */
295 addr = roundup(addr, 0x10);
296
297 for (; (addr + 0x10) < maxaddr; addr += 0x10) {
298 if (addr & 0x80)
299 continue;
300 if (pcmcia_io_alloc(sc->sc_pf, addr, 0x10, 0x10,
301 &sc->sc_ethernet_pcioh) == 0) {
302 /* Found one for the ethernet! */
303 sc->sc_flags |= MHZC_ETHERNET_ALLOCED;
304 return (1);
305 }
306 }
307
308 return (0);
309 }
310
311 int
mhzc_print(void * aux,const char * pnp)312 mhzc_print(void *aux, const char *pnp)
313 {
314 const char *name = aux;
315
316 if (pnp)
317 aprint_normal("%s at %s(*)", name, pnp);
318
319 return (UNCONF);
320 }
321
322 void
mhzc_childdet(device_t self,device_t child)323 mhzc_childdet(device_t self, device_t child)
324 {
325 struct mhzc_softc *sc = device_private(self);
326
327 if (sc->sc_ethernet == child)
328 sc->sc_ethernet = NULL;
329 if (sc->sc_modem == child)
330 sc->sc_modem = NULL;
331 }
332
333 int
mhzc_detach(device_t self,int flags)334 mhzc_detach(device_t self, int flags)
335 {
336 struct mhzc_softc *sc = device_private(self);
337 int error;
338
339 error = config_detach_children(self, flags);
340 if (error)
341 return error;
342
343 /* Unmap our i/o windows. */
344 if (sc->sc_flags & MHZC_MODEM_MAPPED)
345 pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window);
346 if (sc->sc_flags & MHZC_ETHERNET_MAPPED)
347 pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window);
348
349 /* Free our i/o spaces. */
350 if (sc->sc_flags & MHZC_ETHERNET_ALLOCED)
351 pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
352 if (sc->sc_flags & MHZC_MODEM_ALLOCED)
353 pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
354
355 sc->sc_flags = 0;
356
357 return 0;
358 }
359
360 int
mhzc_intr(void * arg)361 mhzc_intr(void *arg)
362 {
363 struct mhzc_softc *sc = arg;
364 int rval = 0;
365
366 #if NCOM_MHZC > 0
367 if (sc->sc_modem != NULL &&
368 (sc->sc_flags & MHZC_MODEM_ENABLED) != 0)
369 rval |= comintr(sc->sc_modem);
370 #endif
371
372 #if NSM_MHZC > 0
373 if (sc->sc_ethernet != NULL &&
374 (sc->sc_flags & MHZC_ETHERNET_ENABLED) != 0)
375 rval |= smc91cxx_intr(sc->sc_ethernet);
376 #endif
377
378 return (rval);
379 }
380
381 int
mhzc_enable(struct mhzc_softc * sc,int flag)382 mhzc_enable(struct mhzc_softc *sc, int flag)
383 {
384 int error;
385
386 if ((sc->sc_flags & flag) == flag) {
387 printf("%s: already enabled\n", device_xname(sc->sc_dev));
388 return (0);
389 }
390
391 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0) {
392 sc->sc_flags |= flag;
393 return (0);
394 }
395
396 /*
397 * Establish our interrupt handler.
398 *
399 * XXX Note, we establish this at IPL_NET. This is suboptimal
400 * XXX the Modem portion, but is necessary to make the Ethernet
401 * XXX portion have the correct interrupt level semantics.
402 *
403 * XXX Eventually we should use the `enabled' bits in the
404 * XXX flags word to determine which level we should be at.
405 */
406 sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET,
407 mhzc_intr, sc);
408 if (!sc->sc_ih)
409 return (EIO);
410
411 error = pcmcia_function_enable(sc->sc_pf);
412 if (error) {
413 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
414 sc->sc_ih = 0;
415 return (error);
416 }
417
418 /*
419 * Perform any special enable magic necessary.
420 */
421 if (sc->sc_product->mp_enable != NULL &&
422 (*sc->sc_product->mp_enable)(sc) != 0) {
423 pcmcia_function_disable(sc->sc_pf);
424 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
425 return (1);
426 }
427
428 sc->sc_flags |= flag;
429 return (0);
430 }
431
432 void
mhzc_disable(struct mhzc_softc * sc,int flag)433 mhzc_disable(struct mhzc_softc *sc, int flag)
434 {
435
436 if ((sc->sc_flags & flag) == 0) {
437 printf("%s: already disabled\n", device_xname(sc->sc_dev));
438 return;
439 }
440
441 sc->sc_flags &= ~flag;
442 if ((sc->sc_flags & (MHZC_MODEM_ENABLED|MHZC_ETHERNET_ENABLED)) != 0)
443 return;
444
445 pcmcia_function_disable(sc->sc_pf);
446 pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
447 sc->sc_ih = 0;
448 }
449
450 /*****************************************************************************
451 * Megahertz EM3336 (and compatibles) support
452 *****************************************************************************/
453
454 int mhzc_em3336_lannid_ciscallback(struct pcmcia_tuple *, void *);
455 int mhzc_em3336_ascii_enaddr(const char *cisstr, u_int8_t *);
456
457 int
mhzc_em3336_enaddr(struct mhzc_softc * sc,u_int8_t * myla)458 mhzc_em3336_enaddr(struct mhzc_softc *sc, u_int8_t *myla)
459 {
460
461 /* Get the station address from CIS tuple 0x81. */
462 if (pcmcia_scan_cis(device_parent(sc->sc_dev),
463 mhzc_em3336_lannid_ciscallback, myla) != 1) {
464 printf("%s: unable to get Ethernet address from CIS\n",
465 device_xname(sc->sc_dev));
466 return (0);
467 }
468
469 return (1);
470 }
471
472 int
mhzc_em3336_enable(struct mhzc_softc * sc)473 mhzc_em3336_enable(struct mhzc_softc *sc)
474 {
475 struct pcmcia_mem_handle memh;
476 bus_size_t memoff;
477 int memwin, reg;
478
479 /*
480 * Bring the chip to live by touching its registers in the correct
481 * way (as per my reference... the Linux smc91c92_cs.c driver by
482 * David A. Hinds).
483 */
484
485 /* Map the ISRPOWEREG. */
486 if (pcmcia_mem_alloc(sc->sc_pf, 0x1000, &memh) != 0) {
487 aprint_error_dev(sc->sc_dev, "unable to allocate memory space\n");
488 return (1);
489 }
490
491 if (pcmcia_mem_map(sc->sc_pf, PCMCIA_MEM_ATTR, 0, 0x1000,
492 &memh, &memoff, &memwin)) {
493 aprint_error_dev(sc->sc_dev, "unable to map memory space\n");
494 pcmcia_mem_free(sc->sc_pf, &memh);
495 return (1);
496 }
497
498 /*
499 * The magic sequence:
500 *
501 * - read/write the CCR option register.
502 * - read the ISRPOWEREG 2 times.
503 * - read/write the CCR option register again.
504 */
505
506 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
507 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
508
509 reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
510 delay(5);
511 reg = bus_space_read_1(memh.memt, memh.memh, 0x380);
512
513 tsleep(&mhzc_em3336_enable, PWAIT, "mhz3en", hz * 200 / 1000);
514
515 reg = pcmcia_ccr_read(sc->sc_pf, PCMCIA_CCR_OPTION);
516 delay(5);
517 pcmcia_ccr_write(sc->sc_pf, PCMCIA_CCR_OPTION, reg);
518
519 pcmcia_mem_unmap(sc->sc_pf, memwin);
520 pcmcia_mem_free(sc->sc_pf, &memh);
521
522 return (0);
523 }
524
525 int
mhzc_em3336_lannid_ciscallback(struct pcmcia_tuple * tuple,void * arg)526 mhzc_em3336_lannid_ciscallback(struct pcmcia_tuple *tuple, void *arg)
527 {
528 u_int8_t *myla = arg, addr_str[ETHER_ADDR_LEN * 2];
529 int i;
530
531 if (tuple->code == 0x81) {
532 /*
533 * We have a string-encoded address. Length includes
534 * terminating 0xff.
535 */
536 if (tuple->length != (ETHER_ADDR_LEN * 2) + 1)
537 return (0);
538
539 for (i = 0; i < tuple->length - 1; i++)
540 addr_str[i] = pcmcia_tuple_read_1(tuple, i);
541
542 /*
543 * Decode the string into `myla'.
544 */
545 return (mhzc_em3336_ascii_enaddr(addr_str, myla));
546 }
547 return (0);
548 }
549
550 /* XXX This should be shared w/ if_sm_pcmcia.c */
551 int
mhzc_em3336_ascii_enaddr(const char * cisstr,u_int8_t * myla)552 mhzc_em3336_ascii_enaddr(const char *cisstr, u_int8_t *myla)
553 {
554 u_int8_t digit;
555 int i;
556
557 memset(myla, 0, ETHER_ADDR_LEN);
558
559 for (i = 0, digit = 0; i < (ETHER_ADDR_LEN * 2); i++) {
560 if (cisstr[i] >= '0' && cisstr[i] <= '9')
561 digit |= cisstr[i] - '0';
562 else if (cisstr[i] >= 'a' && cisstr[i] <= 'f')
563 digit |= (cisstr[i] - 'a') + 10;
564 else if (cisstr[i] >= 'A' && cisstr[i] <= 'F')
565 digit |= (cisstr[i] - 'A') + 10;
566 else {
567 /* Bogus digit!! */
568 return (0);
569 }
570
571 /* Compensate for ordering of digits. */
572 if (i & 1) {
573 myla[i >> 1] = digit;
574 digit = 0;
575 } else
576 digit <<= 4;
577 }
578
579 return (1);
580 }
581
582 /****** Here begins the com attachment code. ******/
583
584 #if NCOM_MHZC > 0
585 int com_mhzc_match(device_t, cfdata_t , void *);
586 void com_mhzc_attach(device_t, device_t, void *);
587 int com_mhzc_detach(device_t, int);
588
589 /* No mhzc-specific goo in the softc; it's all in the parent. */
590 CFATTACH_DECL_NEW(com_mhzc, sizeof(struct com_softc),
591 com_mhzc_match, com_mhzc_attach, com_detach, NULL);
592
593 int com_mhzc_enable(struct com_softc *);
594 void com_mhzc_disable(struct com_softc *);
595
596 int
com_mhzc_match(device_t parent,cfdata_t match,void * aux)597 com_mhzc_match(device_t parent, cfdata_t match, void *aux)
598 {
599 extern struct cfdriver com_cd;
600 const char *name = aux;
601
602 /* Device is always present. */
603 if (strcmp(name, com_cd.cd_name) == 0)
604 return (1);
605
606 return (0);
607 }
608
609 void
com_mhzc_attach(device_t parent,device_t self,void * aux)610 com_mhzc_attach(device_t parent, device_t self, void *aux)
611 {
612 struct com_softc *sc = device_private(self);
613 struct mhzc_softc *msc = device_private(parent);
614
615 sc->sc_dev = self;
616 aprint_normal("\n");
617
618 com_init_regs(&sc->sc_regs,
619 msc->sc_modem_pcioh.iot,
620 msc->sc_modem_pcioh.ioh,
621 -1);
622
623 sc->enabled = 1;
624
625 sc->sc_frequency = COM_FREQ;
626
627 sc->enable = com_mhzc_enable;
628 sc->disable = com_mhzc_disable;
629
630 aprint_normal("%s", device_xname(self));
631
632 com_attach_subr(sc);
633
634 sc->enabled = 0;
635 }
636
637 int
com_mhzc_enable(struct com_softc * sc)638 com_mhzc_enable(struct com_softc *sc)
639 {
640
641 return (mhzc_enable(device_private(device_parent(sc->sc_dev)),
642 MHZC_MODEM_ENABLED));
643 }
644
645 void
com_mhzc_disable(struct com_softc * sc)646 com_mhzc_disable(struct com_softc *sc)
647 {
648
649 mhzc_disable(device_private(device_parent(sc->sc_dev)),
650 MHZC_MODEM_ENABLED);
651 }
652
653 #endif /* NCOM_MHZC > 0 */
654
655 /****** Here begins the sm attachment code. ******/
656
657 #if NSM_MHZC > 0
658 int sm_mhzc_match(device_t, cfdata_t, void *);
659 void sm_mhzc_attach(device_t, device_t, void *);
660
661 /* No mhzc-specific goo in the softc; it's all in the parent. */
662 CFATTACH_DECL_NEW(sm_mhzc, sizeof(struct smc91cxx_softc),
663 sm_mhzc_match, sm_mhzc_attach, smc91cxx_detach, smc91cxx_activate);
664
665 int sm_mhzc_enable(struct smc91cxx_softc *);
666 void sm_mhzc_disable(struct smc91cxx_softc *);
667
668 int
sm_mhzc_match(device_t parent,cfdata_t match,void * aux)669 sm_mhzc_match(device_t parent, cfdata_t match, void *aux)
670 {
671 extern struct cfdriver sm_cd;
672 const char *name = aux;
673
674 /* Device is always present. */
675 if (strcmp(name, sm_cd.cd_name) == 0)
676 return (1);
677
678 return (0);
679 }
680
681 void
sm_mhzc_attach(device_t parent,device_t self,void * aux)682 sm_mhzc_attach(device_t parent, device_t self, void *aux)
683 {
684 struct smc91cxx_softc *sc = device_private(self);
685 struct mhzc_softc *msc = device_private(parent);
686 u_int8_t myla[ETHER_ADDR_LEN];
687
688 aprint_normal("\n");
689
690 sc->sc_dev = self;
691 sc->sc_bst = msc->sc_ethernet_pcioh.iot;
692 sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
693
694 sc->sc_enable = sm_mhzc_enable;
695 sc->sc_disable = sm_mhzc_disable;
696
697 if ((*msc->sc_product->mp_enaddr)(msc, myla) != 1)
698 return;
699
700 /* Perform generic initialization. */
701 smc91cxx_attach(sc, myla);
702 }
703
704 int
sm_mhzc_enable(struct smc91cxx_softc * sc)705 sm_mhzc_enable(struct smc91cxx_softc *sc)
706 {
707 struct mhzc_softc *xsc = device_private(device_parent(sc->sc_dev));
708
709 return mhzc_enable(xsc, MHZC_ETHERNET_ENABLED);
710 }
711
712 void
sm_mhzc_disable(struct smc91cxx_softc * sc)713 sm_mhzc_disable(struct smc91cxx_softc *sc)
714 {
715 struct mhzc_softc *xsc = device_private(device_parent(sc->sc_dev));
716
717 mhzc_disable(xsc, MHZC_ETHERNET_ENABLED);
718 }
719
720 #endif /* NSM_MHZC > 0 */
721