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