xirc.c revision 1.27 1 1.27 dsl /* $NetBSD: xirc.c,v 1.27 2009/03/14 21:04:22 dsl Exp $ */
2 1.1 mycroft
3 1.1 mycroft /*-
4 1.1 mycroft * Copyright (c) 1999, 2000, 2004 The NetBSD Foundation, Inc.
5 1.1 mycroft * All rights reserved.
6 1.1 mycroft *
7 1.1 mycroft * This code is derived from software contributed to The NetBSD Foundation
8 1.1 mycroft * by Jason R. Thorpe of the Numerical Aerospace Simulation Facility,
9 1.1 mycroft * NASA Ames Research Center and by Charles M. Hannum.
10 1.1 mycroft *
11 1.1 mycroft * Redistribution and use in source and binary forms, with or without
12 1.1 mycroft * modification, are permitted provided that the following conditions
13 1.1 mycroft * are met:
14 1.1 mycroft * 1. Redistributions of source code must retain the above copyright
15 1.1 mycroft * notice, this list of conditions and the following disclaimer.
16 1.1 mycroft * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 mycroft * notice, this list of conditions and the following disclaimer in the
18 1.1 mycroft * documentation and/or other materials provided with the distribution.
19 1.1 mycroft *
20 1.1 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.1 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.1 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.1 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.1 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.1 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.1 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.1 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.1 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.1 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.1 mycroft * POSSIBILITY OF SUCH DAMAGE.
31 1.1 mycroft */
32 1.1 mycroft
33 1.1 mycroft #include <sys/cdefs.h>
34 1.27 dsl __KERNEL_RCSID(0, "$NetBSD: xirc.c,v 1.27 2009/03/14 21:04:22 dsl Exp $");
35 1.1 mycroft
36 1.13 perry #include "opt_inet.h"
37 1.1 mycroft #include "bpfilter.h"
38 1.1 mycroft
39 1.1 mycroft #include <sys/param.h>
40 1.1 mycroft #include <sys/systm.h>
41 1.1 mycroft #include <sys/mbuf.h>
42 1.1 mycroft #include <sys/socket.h>
43 1.1 mycroft #include <sys/ioctl.h>
44 1.1 mycroft #include <sys/errno.h>
45 1.1 mycroft #include <sys/syslog.h>
46 1.1 mycroft #include <sys/select.h>
47 1.1 mycroft #include <sys/tty.h>
48 1.1 mycroft #include <sys/device.h>
49 1.1 mycroft
50 1.13 perry #include <net/if.h>
51 1.13 perry #include <net/if_dl.h>
52 1.1 mycroft #include <net/if_ether.h>
53 1.13 perry #include <net/if_media.h>
54 1.1 mycroft
55 1.1 mycroft #ifdef INET
56 1.1 mycroft #include <netinet/in.h>
57 1.1 mycroft #include <netinet/in_systm.h>
58 1.1 mycroft #include <netinet/in_var.h>
59 1.1 mycroft #include <netinet/ip.h>
60 1.1 mycroft #include <netinet/if_inarp.h>
61 1.1 mycroft #endif
62 1.13 perry
63 1.1 mycroft
64 1.1 mycroft #if NBPFILTER > 0
65 1.1 mycroft #include <net/bpf.h>
66 1.1 mycroft #include <net/bpfdesc.h>
67 1.1 mycroft #endif
68 1.1 mycroft
69 1.21 ad #include <sys/intr.h>
70 1.21 ad #include <sys/bus.h>
71 1.1 mycroft
72 1.1 mycroft #include <dev/pcmcia/pcmciareg.h>
73 1.1 mycroft #include <dev/pcmcia/pcmciavar.h>
74 1.1 mycroft #include <dev/pcmcia/pcmciadevs.h>
75 1.1 mycroft
76 1.1 mycroft #include "xirc.h"
77 1.1 mycroft
78 1.1 mycroft #if NCOM_XIRC > 0
79 1.1 mycroft #include <dev/ic/comreg.h>
80 1.1 mycroft #include <dev/ic/comvar.h>
81 1.1 mycroft #endif
82 1.1 mycroft
83 1.1 mycroft #if NXI_XIRC > 0
84 1.1 mycroft #include <dev/mii/mii.h>
85 1.1 mycroft #include <dev/mii/miivar.h>
86 1.1 mycroft
87 1.1 mycroft #include <dev/pcmcia/if_xivar.h>
88 1.1 mycroft #endif
89 1.1 mycroft #include <dev/pcmcia/if_xireg.h>
90 1.1 mycroft
91 1.1 mycroft struct xirc_softc {
92 1.1 mycroft struct device sc_dev; /* generic device glue */
93 1.1 mycroft
94 1.1 mycroft struct pcmcia_function *sc_pf; /* our PCMCIA function */
95 1.1 mycroft void *sc_ih; /* interrupt handle */
96 1.1 mycroft
97 1.1 mycroft u_int16_t sc_id;
98 1.4 mycroft u_int8_t sc_mako_intmask;
99 1.1 mycroft int sc_chipset;
100 1.1 mycroft
101 1.1 mycroft /*
102 1.1 mycroft * Data for the Modem portion.
103 1.1 mycroft */
104 1.1 mycroft struct device *sc_modem;
105 1.1 mycroft struct pcmcia_io_handle sc_modem_pcioh;
106 1.1 mycroft int sc_modem_io_window;
107 1.1 mycroft
108 1.1 mycroft /*
109 1.1 mycroft * Data for the Ethernet portion.
110 1.1 mycroft */
111 1.1 mycroft struct device *sc_ethernet;
112 1.1 mycroft struct pcmcia_io_handle sc_ethernet_pcioh;
113 1.1 mycroft int sc_ethernet_io_window;
114 1.1 mycroft
115 1.1 mycroft int sc_flags;
116 1.1 mycroft #define XIRC_MODEM_MAPPED 0x01
117 1.1 mycroft #define XIRC_ETHERNET_MAPPED 0x02
118 1.1 mycroft #define XIRC_MODEM_ENABLED 0x04
119 1.1 mycroft #define XIRC_ETHERNET_ENABLED 0x08
120 1.1 mycroft #define XIRC_MODEM_ALLOCED 0x10
121 1.1 mycroft #define XIRC_ETHERNET_ALLOCED 0x20
122 1.1 mycroft };
123 1.1 mycroft
124 1.12 perry int xirc_match(struct device *, struct cfdata *, void *);
125 1.12 perry void xirc_attach(struct device *, struct device *, void *);
126 1.12 perry int xirc_detach(struct device *, int);
127 1.12 perry int xirc_activate(struct device *, enum devact);
128 1.1 mycroft
129 1.1 mycroft CFATTACH_DECL(xirc, sizeof(struct xirc_softc),
130 1.1 mycroft xirc_match, xirc_attach, xirc_detach, xirc_activate);
131 1.1 mycroft
132 1.12 perry int xirc_print(void *, const char *);
133 1.1 mycroft
134 1.12 perry int xirc_manfid_ciscallback(struct pcmcia_tuple *, void *);
135 1.1 mycroft struct pcmcia_config_entry *
136 1.12 perry xirc_mako_alloc(struct xirc_softc *);
137 1.1 mycroft struct pcmcia_config_entry *
138 1.12 perry xirc_dingo_alloc_modem(struct xirc_softc *);
139 1.1 mycroft struct pcmcia_config_entry *
140 1.12 perry xirc_dingo_alloc_ethernet(struct xirc_softc *);
141 1.1 mycroft
142 1.12 perry int xirc_enable(struct xirc_softc *, int, int);
143 1.12 perry void xirc_disable(struct xirc_softc *, int, int);
144 1.1 mycroft
145 1.12 perry int xirc_intr(void *);
146 1.1 mycroft
147 1.1 mycroft int
148 1.20 christos xirc_match(struct device *parent, struct cfdata *match,
149 1.19 christos void *aux)
150 1.1 mycroft {
151 1.1 mycroft struct pcmcia_attach_args *pa = aux;
152 1.1 mycroft
153 1.1 mycroft /* XXX Toshiba, Accton */
154 1.1 mycroft
155 1.1 mycroft if (pa->manufacturer == PCMCIA_VENDOR_COMPAQ2 &&
156 1.1 mycroft pa->product == PCMCIA_PRODUCT_COMPAQ2_CPQ_10_100)
157 1.1 mycroft return (1);
158 1.1 mycroft
159 1.1 mycroft if (pa->manufacturer == PCMCIA_VENDOR_INTEL &&
160 1.1 mycroft pa->product == PCMCIA_PRODUCT_INTEL_EEPRO100)
161 1.1 mycroft return (1);
162 1.1 mycroft
163 1.1 mycroft if (pa->manufacturer == PCMCIA_VENDOR_XIRCOM &&
164 1.4 mycroft (pa->product & (XIMEDIA_ETHER << 8)) != 0)
165 1.1 mycroft return (2);
166 1.1 mycroft
167 1.1 mycroft return (0);
168 1.1 mycroft }
169 1.1 mycroft
170 1.1 mycroft void
171 1.27 dsl xirc_attach(struct device *parent, struct device *self, void *aux)
172 1.1 mycroft {
173 1.1 mycroft struct xirc_softc *sc = (void *)self;
174 1.1 mycroft struct pcmcia_attach_args *pa = aux;
175 1.1 mycroft struct pcmcia_config_entry *cfe;
176 1.1 mycroft int rv;
177 1.9 mycroft int error;
178 1.1 mycroft
179 1.1 mycroft sc->sc_pf = pa->pf;
180 1.1 mycroft
181 1.1 mycroft pcmcia_socket_enable(parent);
182 1.1 mycroft rv = pcmcia_scan_cis(parent, xirc_manfid_ciscallback, &sc->sc_id);
183 1.1 mycroft pcmcia_socket_disable(parent);
184 1.1 mycroft if (!rv) {
185 1.23 cegger aprint_error_dev(self, "failed to find ID\n");
186 1.1 mycroft return;
187 1.1 mycroft }
188 1.1 mycroft
189 1.1 mycroft switch (sc->sc_id & 0x100f) {
190 1.1 mycroft case 0x0001: /* CE */
191 1.1 mycroft case 0x0002: /* CE2 */
192 1.1 mycroft sc->sc_chipset = XI_CHIPSET_SCIPPER;
193 1.1 mycroft break;
194 1.1 mycroft case 0x0003: /* CE3 */
195 1.1 mycroft sc->sc_chipset = XI_CHIPSET_MOHAWK;
196 1.1 mycroft break;
197 1.1 mycroft case 0x1001:
198 1.1 mycroft case 0x1002:
199 1.1 mycroft case 0x1003:
200 1.1 mycroft case 0x1004:
201 1.1 mycroft sc->sc_chipset = XI_CHIPSET_SCIPPER;
202 1.1 mycroft break;
203 1.1 mycroft case 0x1005:
204 1.1 mycroft sc->sc_chipset = XI_CHIPSET_MOHAWK;
205 1.1 mycroft break;
206 1.1 mycroft case 0x1006:
207 1.1 mycroft case 0x1007:
208 1.1 mycroft sc->sc_chipset = XI_CHIPSET_DINGO;
209 1.1 mycroft break;
210 1.1 mycroft default:
211 1.23 cegger aprint_error_dev(self, "unknown ID %04x\n",
212 1.1 mycroft sc->sc_id);
213 1.1 mycroft return;
214 1.1 mycroft }
215 1.1 mycroft
216 1.23 cegger aprint_normal_dev(self, "id=%04x\n", sc->sc_id);
217 1.1 mycroft
218 1.1 mycroft if (sc->sc_id & (XIMEDIA_MODEM << 8)) {
219 1.1 mycroft if (sc->sc_chipset >= XI_CHIPSET_DINGO) {
220 1.1 mycroft cfe = xirc_dingo_alloc_modem(sc);
221 1.5 mycroft if (cfe && sc->sc_id & (XIMEDIA_ETHER << 8)) {
222 1.5 mycroft if (!xirc_dingo_alloc_ethernet(sc)) {
223 1.5 mycroft pcmcia_io_free(pa->pf,
224 1.5 mycroft &sc->sc_modem_pcioh);
225 1.5 mycroft cfe = 0;
226 1.5 mycroft }
227 1.1 mycroft }
228 1.5 mycroft } else
229 1.4 mycroft cfe = xirc_mako_alloc(sc);
230 1.5 mycroft } else
231 1.1 mycroft cfe = xirc_dingo_alloc_ethernet(sc);
232 1.5 mycroft if (!cfe) {
233 1.23 cegger aprint_error_dev(self, "failed to allocate I/O space\n");
234 1.5 mycroft goto fail;
235 1.1 mycroft }
236 1.1 mycroft
237 1.1 mycroft /* Enable the card. */
238 1.1 mycroft pcmcia_function_init(pa->pf, cfe);
239 1.5 mycroft
240 1.7 mycroft if (sc->sc_id & (XIMEDIA_MODEM << 8)) {
241 1.7 mycroft if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_IO8,
242 1.7 mycroft &sc->sc_modem_pcioh, &sc->sc_modem_io_window)) {
243 1.23 cegger aprint_error_dev(self, "unable to map I/O space\n");
244 1.7 mycroft goto fail;
245 1.7 mycroft }
246 1.7 mycroft sc->sc_flags |= XIRC_MODEM_MAPPED;
247 1.7 mycroft }
248 1.7 mycroft
249 1.7 mycroft if (sc->sc_id & (XIMEDIA_ETHER << 8)) {
250 1.7 mycroft if (pcmcia_io_map(sc->sc_pf, PCMCIA_WIDTH_AUTO,
251 1.7 mycroft &sc->sc_ethernet_pcioh, &sc->sc_ethernet_io_window)) {
252 1.23 cegger aprint_error_dev(self, "unable to map I/O space\n");
253 1.7 mycroft goto fail;
254 1.7 mycroft }
255 1.7 mycroft sc->sc_flags |= XIRC_ETHERNET_MAPPED;
256 1.7 mycroft }
257 1.7 mycroft
258 1.9 mycroft error = xirc_enable(sc, XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED,
259 1.9 mycroft sc->sc_id & (XIMEDIA_MODEM|XIMEDIA_ETHER));
260 1.9 mycroft if (error)
261 1.1 mycroft goto fail;
262 1.1 mycroft
263 1.4 mycroft sc->sc_mako_intmask = 0xee;
264 1.4 mycroft
265 1.1 mycroft if (sc->sc_id & (XIMEDIA_MODEM << 8))
266 1.14 christos /*XXXUNCONST*/
267 1.14 christos sc->sc_modem = config_found(self, __UNCONST("com"), xirc_print);
268 1.1 mycroft if (sc->sc_id & (XIMEDIA_ETHER << 8))
269 1.14 christos /*XXXUNCONST*/
270 1.14 christos sc->sc_ethernet = config_found(self, __UNCONST("xi"),
271 1.14 christos xirc_print);
272 1.1 mycroft
273 1.5 mycroft xirc_disable(sc, XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED,
274 1.5 mycroft sc->sc_id & (XIMEDIA_MODEM|XIMEDIA_ETHER));
275 1.1 mycroft return;
276 1.1 mycroft
277 1.1 mycroft fail:
278 1.7 mycroft /* I/O spaces will be freed by detach. */
279 1.7 mycroft ;
280 1.1 mycroft }
281 1.1 mycroft
282 1.1 mycroft int
283 1.26 dsl xirc_manfid_ciscallback(struct pcmcia_tuple *tuple, void *arg)
284 1.1 mycroft {
285 1.1 mycroft u_int16_t *id = arg;
286 1.1 mycroft
287 1.1 mycroft if (tuple->code != PCMCIA_CISTPL_MANFID)
288 1.1 mycroft return (0);
289 1.1 mycroft
290 1.1 mycroft if (tuple->length < 5)
291 1.1 mycroft return (0);
292 1.1 mycroft
293 1.1 mycroft *id = (pcmcia_tuple_read_1(tuple, 3) << 8) |
294 1.1 mycroft pcmcia_tuple_read_1(tuple, 4);
295 1.1 mycroft return (1);
296 1.1 mycroft }
297 1.1 mycroft
298 1.1 mycroft struct pcmcia_config_entry *
299 1.26 dsl xirc_mako_alloc(struct xirc_softc *sc)
300 1.1 mycroft {
301 1.1 mycroft struct pcmcia_config_entry *cfe;
302 1.1 mycroft
303 1.1 mycroft SIMPLEQ_FOREACH(cfe, &sc->sc_pf->cfe_head, cfe_list) {
304 1.1 mycroft if (cfe->num_iospace != 1)
305 1.1 mycroft continue;
306 1.1 mycroft
307 1.1 mycroft if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start,
308 1.1 mycroft cfe->iospace[0].length, cfe->iospace[0].length,
309 1.1 mycroft &sc->sc_modem_pcioh))
310 1.1 mycroft continue;
311 1.1 mycroft
312 1.8 mycroft cfe->iospace[1].start = cfe->iospace[0].start+8;
313 1.8 mycroft cfe->iospace[1].length = 18;
314 1.8 mycroft if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[1].start,
315 1.8 mycroft cfe->iospace[1].length, 0x20,
316 1.8 mycroft &sc->sc_ethernet_pcioh)) {
317 1.8 mycroft cfe->iospace[1].start = cfe->iospace[0].start-24;
318 1.8 mycroft if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[1].start,
319 1.8 mycroft cfe->iospace[1].length, 0x20,
320 1.8 mycroft &sc->sc_ethernet_pcioh))
321 1.8 mycroft continue;
322 1.1 mycroft }
323 1.1 mycroft
324 1.1 mycroft /* Found one! */
325 1.1 mycroft sc->sc_flags |= XIRC_MODEM_ALLOCED;
326 1.1 mycroft sc->sc_flags |= XIRC_ETHERNET_ALLOCED;
327 1.1 mycroft return (cfe);
328 1.1 mycroft }
329 1.1 mycroft
330 1.1 mycroft return (0);
331 1.1 mycroft }
332 1.1 mycroft
333 1.1 mycroft struct pcmcia_config_entry *
334 1.26 dsl xirc_dingo_alloc_modem(struct xirc_softc *sc)
335 1.1 mycroft {
336 1.1 mycroft struct pcmcia_config_entry *cfe;
337 1.1 mycroft
338 1.1 mycroft SIMPLEQ_FOREACH(cfe, &sc->sc_pf->cfe_head, cfe_list) {
339 1.1 mycroft if (cfe->num_iospace != 1)
340 1.1 mycroft continue;
341 1.1 mycroft
342 1.1 mycroft if (pcmcia_io_alloc(sc->sc_pf, cfe->iospace[0].start,
343 1.1 mycroft cfe->iospace[0].length, cfe->iospace[0].length,
344 1.1 mycroft &sc->sc_modem_pcioh))
345 1.1 mycroft continue;
346 1.1 mycroft
347 1.1 mycroft /* Found one! */
348 1.1 mycroft sc->sc_flags |= XIRC_MODEM_ALLOCED;
349 1.1 mycroft return (cfe);
350 1.1 mycroft }
351 1.1 mycroft
352 1.1 mycroft return (0);
353 1.1 mycroft }
354 1.1 mycroft
355 1.1 mycroft struct pcmcia_config_entry *
356 1.26 dsl xirc_dingo_alloc_ethernet(struct xirc_softc *sc)
357 1.1 mycroft {
358 1.1 mycroft struct pcmcia_config_entry *cfe;
359 1.1 mycroft bus_addr_t port;
360 1.1 mycroft
361 1.1 mycroft for (port = 0x300; port < 0x400; port += XI_IOSIZE) {
362 1.1 mycroft if (pcmcia_io_alloc(sc->sc_pf, port,
363 1.1 mycroft XI_IOSIZE, XI_IOSIZE, &sc->sc_ethernet_pcioh))
364 1.1 mycroft continue;
365 1.1 mycroft
366 1.1 mycroft /* Found one for the ethernet! */
367 1.1 mycroft sc->sc_flags |= XIRC_ETHERNET_ALLOCED;
368 1.1 mycroft cfe = SIMPLEQ_FIRST(&sc->sc_pf->cfe_head);
369 1.1 mycroft return (cfe);
370 1.1 mycroft }
371 1.1 mycroft
372 1.1 mycroft return (0);
373 1.1 mycroft }
374 1.1 mycroft
375 1.1 mycroft int
376 1.26 dsl xirc_print(void *aux, const char *pnp)
377 1.1 mycroft {
378 1.1 mycroft const char *name = aux;
379 1.1 mycroft
380 1.1 mycroft if (pnp)
381 1.1 mycroft aprint_normal("%s at %s(*)", name, pnp);
382 1.1 mycroft
383 1.1 mycroft return (UNCONF);
384 1.1 mycroft }
385 1.1 mycroft
386 1.1 mycroft int
387 1.26 dsl xirc_detach(struct device *self, int flags)
388 1.1 mycroft {
389 1.1 mycroft struct xirc_softc *sc = (void *)self;
390 1.1 mycroft int rv;
391 1.1 mycroft
392 1.1 mycroft if (sc->sc_ethernet != NULL) {
393 1.1 mycroft rv = config_detach(sc->sc_ethernet, flags);
394 1.1 mycroft if (rv != 0)
395 1.1 mycroft return (rv);
396 1.1 mycroft sc->sc_ethernet = NULL;
397 1.1 mycroft }
398 1.1 mycroft
399 1.1 mycroft if (sc->sc_modem != NULL) {
400 1.1 mycroft rv = config_detach(sc->sc_modem, flags);
401 1.1 mycroft if (rv != 0)
402 1.1 mycroft return (rv);
403 1.1 mycroft sc->sc_modem = NULL;
404 1.1 mycroft }
405 1.1 mycroft
406 1.1 mycroft /* Unmap our i/o windows. */
407 1.1 mycroft if (sc->sc_flags & XIRC_ETHERNET_MAPPED)
408 1.1 mycroft pcmcia_io_unmap(sc->sc_pf, sc->sc_ethernet_io_window);
409 1.1 mycroft if (sc->sc_flags & XIRC_MODEM_MAPPED)
410 1.1 mycroft pcmcia_io_unmap(sc->sc_pf, sc->sc_modem_io_window);
411 1.1 mycroft
412 1.1 mycroft /* Free our i/o spaces. */
413 1.1 mycroft if (sc->sc_flags & XIRC_ETHERNET_ALLOCED)
414 1.1 mycroft pcmcia_io_free(sc->sc_pf, &sc->sc_ethernet_pcioh);
415 1.1 mycroft if (sc->sc_flags & XIRC_MODEM_ALLOCED)
416 1.1 mycroft pcmcia_io_free(sc->sc_pf, &sc->sc_modem_pcioh);
417 1.1 mycroft sc->sc_flags = 0;
418 1.1 mycroft
419 1.1 mycroft return (0);
420 1.1 mycroft }
421 1.1 mycroft
422 1.1 mycroft int
423 1.26 dsl xirc_activate(struct device *self, enum devact act)
424 1.1 mycroft {
425 1.1 mycroft struct xirc_softc *sc = (void *)self;
426 1.1 mycroft int s, rv = 0;
427 1.1 mycroft
428 1.1 mycroft s = splhigh();
429 1.1 mycroft switch (act) {
430 1.1 mycroft case DVACT_ACTIVATE:
431 1.1 mycroft rv = EOPNOTSUPP;
432 1.1 mycroft break;
433 1.1 mycroft
434 1.1 mycroft case DVACT_DEACTIVATE:
435 1.1 mycroft if (sc->sc_ethernet != NULL) {
436 1.1 mycroft rv = config_deactivate(sc->sc_ethernet);
437 1.1 mycroft if (rv != 0)
438 1.1 mycroft goto out;
439 1.1 mycroft }
440 1.1 mycroft
441 1.1 mycroft if (sc->sc_modem != NULL) {
442 1.1 mycroft rv = config_deactivate(sc->sc_modem);
443 1.1 mycroft if (rv != 0)
444 1.1 mycroft goto out;
445 1.1 mycroft }
446 1.1 mycroft break;
447 1.1 mycroft }
448 1.1 mycroft out:
449 1.1 mycroft splx(s);
450 1.1 mycroft return (rv);
451 1.1 mycroft }
452 1.1 mycroft
453 1.1 mycroft int
454 1.26 dsl xirc_intr(void *arg)
455 1.1 mycroft {
456 1.1 mycroft struct xirc_softc *sc = arg;
457 1.1 mycroft int rval = 0;
458 1.1 mycroft
459 1.1 mycroft #if NCOM_XIRC > 0
460 1.1 mycroft if (sc->sc_modem != NULL &&
461 1.1 mycroft (sc->sc_flags & XIRC_MODEM_ENABLED) != 0)
462 1.25 drochner rval |= comintr(device_private(sc->sc_modem));
463 1.1 mycroft #endif
464 1.1 mycroft
465 1.1 mycroft #if NXI_XIRC > 0
466 1.1 mycroft if (sc->sc_ethernet != NULL &&
467 1.1 mycroft (sc->sc_flags & XIRC_ETHERNET_ENABLED) != 0)
468 1.25 drochner rval |= xi_intr(device_private(sc->sc_ethernet));
469 1.1 mycroft #endif
470 1.1 mycroft
471 1.1 mycroft return (rval);
472 1.1 mycroft }
473 1.1 mycroft
474 1.1 mycroft int
475 1.27 dsl xirc_enable(struct xirc_softc *sc, int flag, int media)
476 1.1 mycroft {
477 1.9 mycroft int error;
478 1.1 mycroft
479 1.5 mycroft if ((sc->sc_flags & flag) == flag) {
480 1.23 cegger printf("%s: already enabled\n", device_xname(&sc->sc_dev));
481 1.5 mycroft return (0);
482 1.1 mycroft }
483 1.1 mycroft
484 1.1 mycroft if ((sc->sc_flags & (XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED)) != 0) {
485 1.1 mycroft sc->sc_flags |= flag;
486 1.1 mycroft return (0);
487 1.1 mycroft }
488 1.1 mycroft
489 1.1 mycroft /*
490 1.1 mycroft * Establish our interrupt handler.
491 1.1 mycroft *
492 1.1 mycroft * XXX Note, we establish this at IPL_NET. This is suboptimal
493 1.1 mycroft * XXX the Modem portion, but is necessary to make the Ethernet
494 1.1 mycroft * XXX portion have the correct interrupt level semantics.
495 1.1 mycroft *
496 1.1 mycroft * XXX Eventually we should use the `enabled' bits in the
497 1.1 mycroft * XXX flags word to determine which level we should be at.
498 1.1 mycroft */
499 1.9 mycroft sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET, xirc_intr, sc);
500 1.9 mycroft if (!sc->sc_ih)
501 1.2 mycroft return (EIO);
502 1.1 mycroft
503 1.9 mycroft error = pcmcia_function_enable(sc->sc_pf);
504 1.9 mycroft if (error) {
505 1.1 mycroft pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
506 1.10 mycroft sc->sc_ih = 0;
507 1.9 mycroft return (error);
508 1.1 mycroft }
509 1.1 mycroft
510 1.1 mycroft sc->sc_flags |= flag;
511 1.4 mycroft
512 1.4 mycroft if (sc->sc_chipset < XI_CHIPSET_DINGO &&
513 1.4 mycroft sc->sc_id & (XIMEDIA_MODEM << 8)) {
514 1.4 mycroft sc->sc_mako_intmask |= media;
515 1.4 mycroft bus_space_write_1(sc->sc_ethernet_pcioh.iot,
516 1.4 mycroft sc->sc_ethernet_pcioh.ioh, 0x10, sc->sc_mako_intmask);
517 1.4 mycroft }
518 1.4 mycroft
519 1.1 mycroft return (0);
520 1.1 mycroft }
521 1.1 mycroft
522 1.1 mycroft void
523 1.27 dsl xirc_disable(struct xirc_softc *sc, int flag, int media)
524 1.1 mycroft {
525 1.1 mycroft
526 1.5 mycroft if ((sc->sc_flags & flag) == 0) {
527 1.23 cegger printf("%s: already disabled\n", device_xname(&sc->sc_dev));
528 1.5 mycroft return;
529 1.5 mycroft }
530 1.5 mycroft
531 1.4 mycroft if (sc->sc_chipset < XI_CHIPSET_DINGO &&
532 1.4 mycroft sc->sc_id & (XIMEDIA_MODEM << 8)) {
533 1.4 mycroft sc->sc_mako_intmask &= ~media;
534 1.4 mycroft bus_space_write_1(sc->sc_ethernet_pcioh.iot,
535 1.4 mycroft sc->sc_ethernet_pcioh.ioh, 0x10, sc->sc_mako_intmask);
536 1.4 mycroft }
537 1.4 mycroft
538 1.1 mycroft sc->sc_flags &= ~flag;
539 1.1 mycroft if ((sc->sc_flags & (XIRC_MODEM_ENABLED|XIRC_ETHERNET_ENABLED)) != 0)
540 1.1 mycroft return;
541 1.1 mycroft
542 1.6 mycroft pcmcia_function_disable(sc->sc_pf);
543 1.1 mycroft pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
544 1.9 mycroft sc->sc_ih = 0;
545 1.1 mycroft }
546 1.1 mycroft
547 1.1 mycroft /****** Here begins the com attachment code. ******/
548 1.1 mycroft
549 1.1 mycroft #if NCOM_XIRC > 0
550 1.22 cube int com_xirc_match(device_t, cfdata_t , void *);
551 1.22 cube void com_xirc_attach(device_t, device_t, void *);
552 1.22 cube int com_xirc_detach(device_t, int);
553 1.1 mycroft
554 1.1 mycroft /* No xirc-specific goo in the softc; it's all in the parent. */
555 1.22 cube CFATTACH_DECL_NEW(com_xirc, sizeof(struct com_softc),
556 1.1 mycroft com_xirc_match, com_xirc_attach, com_detach, com_activate);
557 1.1 mycroft
558 1.12 perry int com_xirc_enable(struct com_softc *);
559 1.12 perry void com_xirc_disable(struct com_softc *);
560 1.1 mycroft
561 1.1 mycroft int
562 1.22 cube com_xirc_match(device_t parent, cfdata_t match, void *aux)
563 1.1 mycroft {
564 1.1 mycroft extern struct cfdriver com_cd;
565 1.1 mycroft const char *name = aux;
566 1.1 mycroft
567 1.1 mycroft if (strcmp(name, com_cd.cd_name) == 0)
568 1.1 mycroft return (1);
569 1.1 mycroft
570 1.1 mycroft return (0);
571 1.1 mycroft }
572 1.1 mycroft
573 1.1 mycroft void
574 1.22 cube com_xirc_attach(device_t parent, device_t self, void *aux)
575 1.1 mycroft {
576 1.22 cube struct com_softc *sc = device_private(self);
577 1.22 cube struct xirc_softc *msc = device_private(parent);
578 1.22 cube
579 1.22 cube sc->sc_dev = self;
580 1.1 mycroft
581 1.1 mycroft aprint_normal("\n");
582 1.1 mycroft
583 1.17 gdamore COM_INIT_REGS(sc->sc_regs,
584 1.17 gdamore msc->sc_modem_pcioh.iot,
585 1.17 gdamore msc->sc_modem_pcioh.ioh,
586 1.17 gdamore -1);
587 1.1 mycroft
588 1.1 mycroft sc->enabled = 1;
589 1.1 mycroft
590 1.1 mycroft sc->sc_frequency = COM_FREQ;
591 1.1 mycroft
592 1.1 mycroft sc->enable = com_xirc_enable;
593 1.1 mycroft sc->disable = com_xirc_disable;
594 1.1 mycroft
595 1.22 cube aprint_normal("%s", device_xname(self));
596 1.1 mycroft
597 1.1 mycroft com_attach_subr(sc);
598 1.1 mycroft
599 1.1 mycroft sc->enabled = 0;
600 1.1 mycroft }
601 1.1 mycroft
602 1.1 mycroft int
603 1.22 cube com_xirc_enable(struct com_softc *sc)
604 1.1 mycroft {
605 1.16 thorpej struct xirc_softc *msc =
606 1.22 cube device_private(device_parent(sc->sc_dev));
607 1.1 mycroft
608 1.4 mycroft return (xirc_enable(msc, XIRC_MODEM_ENABLED, XIMEDIA_MODEM));
609 1.1 mycroft }
610 1.1 mycroft
611 1.1 mycroft void
612 1.22 cube com_xirc_disable(struct com_softc *sc)
613 1.1 mycroft {
614 1.16 thorpej struct xirc_softc *msc =
615 1.22 cube device_private(device_parent(sc->sc_dev));
616 1.1 mycroft
617 1.4 mycroft xirc_disable(msc, XIRC_MODEM_ENABLED, XIMEDIA_MODEM);
618 1.1 mycroft }
619 1.1 mycroft
620 1.1 mycroft #endif /* NCOM_XIRC > 0 */
621 1.1 mycroft
622 1.1 mycroft /****** Here begins the xi attachment code. ******/
623 1.1 mycroft
624 1.1 mycroft #if NXI_XIRC > 0
625 1.12 perry int xi_xirc_match(struct device *, struct cfdata *, void *);
626 1.12 perry void xi_xirc_attach(struct device *, struct device *, void *);
627 1.1 mycroft
628 1.1 mycroft /* No xirc-specific goo in the softc; it's all in the parent. */
629 1.1 mycroft CFATTACH_DECL(xi_xirc, sizeof(struct xi_softc),
630 1.1 mycroft xi_xirc_match, xi_xirc_attach, xi_detach, xi_activate);
631 1.1 mycroft
632 1.12 perry int xi_xirc_enable(struct xi_softc *);
633 1.12 perry void xi_xirc_disable(struct xi_softc *);
634 1.12 perry int xi_xirc_lan_nid_ciscallback(struct pcmcia_tuple *, void *);
635 1.1 mycroft
636 1.1 mycroft int
637 1.20 christos xi_xirc_match(struct device *parent, struct cfdata *match,
638 1.19 christos void *aux)
639 1.1 mycroft {
640 1.1 mycroft extern struct cfdriver xi_cd;
641 1.1 mycroft const char *name = aux;
642 1.1 mycroft
643 1.1 mycroft if (strcmp(name, xi_cd.cd_name) == 0)
644 1.1 mycroft return (1);
645 1.1 mycroft
646 1.1 mycroft return (0);
647 1.1 mycroft }
648 1.1 mycroft
649 1.1 mycroft void
650 1.20 christos xi_xirc_attach(struct device *parent, struct device *self, void *aux)
651 1.1 mycroft {
652 1.1 mycroft struct xi_softc *sc = (void *)self;
653 1.1 mycroft struct xirc_softc *msc = (void *)parent;
654 1.1 mycroft u_int8_t myla[ETHER_ADDR_LEN];
655 1.1 mycroft
656 1.1 mycroft aprint_normal("\n");
657 1.1 mycroft
658 1.1 mycroft sc->sc_bst = msc->sc_ethernet_pcioh.iot;
659 1.1 mycroft sc->sc_bsh = msc->sc_ethernet_pcioh.ioh;
660 1.1 mycroft
661 1.1 mycroft sc->sc_chipset = msc->sc_chipset;
662 1.1 mycroft
663 1.1 mycroft sc->sc_enable = xi_xirc_enable;
664 1.1 mycroft sc->sc_disable = xi_xirc_disable;
665 1.1 mycroft
666 1.16 thorpej if (!pcmcia_scan_cis(device_parent(&msc->sc_dev),
667 1.16 thorpej xi_xirc_lan_nid_ciscallback, myla)) {
668 1.23 cegger aprint_error_dev(self, "can't find MAC address\n");
669 1.1 mycroft return;
670 1.1 mycroft }
671 1.1 mycroft
672 1.1 mycroft /* Perform generic initialization. */
673 1.1 mycroft xi_attach(sc, myla);
674 1.1 mycroft }
675 1.1 mycroft
676 1.1 mycroft int
677 1.26 dsl xi_xirc_enable(struct xi_softc *sc)
678 1.1 mycroft {
679 1.16 thorpej struct xirc_softc *msc =
680 1.16 thorpej (struct xirc_softc *)device_parent(&sc->sc_dev);
681 1.1 mycroft
682 1.4 mycroft return (xirc_enable(msc, XIRC_ETHERNET_ENABLED, XIMEDIA_ETHER));
683 1.1 mycroft }
684 1.1 mycroft
685 1.1 mycroft void
686 1.26 dsl xi_xirc_disable(struct xi_softc *sc)
687 1.1 mycroft {
688 1.16 thorpej struct xirc_softc *msc =
689 1.16 thorpej (struct xirc_softc *)device_parent(&sc->sc_dev);
690 1.1 mycroft
691 1.4 mycroft xirc_disable(msc, XIRC_ETHERNET_ENABLED, XIMEDIA_ETHER);
692 1.1 mycroft }
693 1.1 mycroft
694 1.1 mycroft int
695 1.26 dsl xi_xirc_lan_nid_ciscallback(struct pcmcia_tuple *tuple, void *arg)
696 1.1 mycroft {
697 1.1 mycroft u_int8_t *myla = arg;
698 1.1 mycroft int i;
699 1.1 mycroft
700 1.1 mycroft if (tuple->length < 2)
701 1.1 mycroft return (0);
702 1.1 mycroft
703 1.1 mycroft switch (tuple->code) {
704 1.1 mycroft case PCMCIA_CISTPL_FUNCE:
705 1.1 mycroft switch (pcmcia_tuple_read_1(tuple, 0)) {
706 1.1 mycroft case PCMCIA_TPLFE_TYPE_LAN_NID:
707 1.1 mycroft if (pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN)
708 1.1 mycroft return (0);
709 1.1 mycroft for (i = 0; i < ETHER_ADDR_LEN; i++)
710 1.1 mycroft myla[i] = pcmcia_tuple_read_1(tuple, i + 2);
711 1.1 mycroft return (1);
712 1.1 mycroft
713 1.1 mycroft case 0x02:
714 1.1 mycroft /*
715 1.1 mycroft * Not sure about this, I don't have a CE2
716 1.1 mycroft * that puts the ethernet addr here.
717 1.1 mycroft */
718 1.1 mycroft if (pcmcia_tuple_read_1(tuple, 1) != 0x01 ||
719 1.1 mycroft pcmcia_tuple_read_1(tuple, 2) != ETHER_ADDR_LEN)
720 1.1 mycroft return (0);
721 1.1 mycroft for (i = 0; i < ETHER_ADDR_LEN; i++)
722 1.1 mycroft myla[i] = pcmcia_tuple_read_1(tuple, i + 3);
723 1.1 mycroft return (1);
724 1.1 mycroft }
725 1.1 mycroft
726 1.1 mycroft case 0x89:
727 1.1 mycroft if (pcmcia_tuple_read_1(tuple, 0) != 0x04 ||
728 1.1 mycroft pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN)
729 1.1 mycroft return (0);
730 1.1 mycroft for (i = 0; i < ETHER_ADDR_LEN; i++)
731 1.1 mycroft myla[i] = pcmcia_tuple_read_1(tuple, i + 2);
732 1.1 mycroft return (1);
733 1.1 mycroft }
734 1.1 mycroft
735 1.1 mycroft return (0);
736 1.1 mycroft }
737 1.1 mycroft
738 1.1 mycroft #endif /* NXI_XIRC > 0 */
739