if_ne_pcmcia.c revision 1.1.2.5 1 /* $NetBSD: if_ne_pcmcia.c,v 1.1.2.5 1997/10/16 22:43:41 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1997 Marc Horowitz. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Marc Horowitz.
17 * 4. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/select.h>
35 #include <sys/device.h>
36 #include <sys/socket.h>
37
38 #include <net/if_types.h>
39 #include <net/if.h>
40 #include <net/if_ether.h>
41
42 #include <machine/bus.h>
43 #include <machine/intr.h>
44
45 #include <dev/pcmcia/pcmciareg.h>
46 #include <dev/pcmcia/pcmciavar.h>
47
48 #include <dev/ic/dp8390reg.h>
49 #include <dev/ic/dp8390var.h>
50
51 #include <dev/ic/ne2000reg.h>
52 #include <dev/ic/ne2000var.h>
53
54 #ifdef __BROKEN_INDIRECT_CONFIG
55 int ne_pcmcia_match __P((struct device *, void *, void *));
56 #else
57 int ne_pcmcia_match __P((struct device *, struct cfdata *, void *));
58 #endif
59 void ne_pcmcia_attach __P((struct device *, struct device *, void *));
60
61 int ne_pcmcia_enable __P((struct dp8390_softc *));
62 void ne_pcmcia_disable __P((struct dp8390_softc *));
63
64 struct ne_pcmcia_softc {
65 struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
66
67 /* PCMCIA-specific goo */
68 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o information */
69 int sc_asic_io_window; /* i/o window for ASIC */
70 int sc_nic_io_window; /* i/o window for NIC */
71 struct pcmcia_function *sc_pf; /* our PCMCIA function */
72 void *sc_ih; /* interrupt handle */
73 };
74
75 struct cfattach ne_pcmcia_ca = {
76 sizeof(struct ne_pcmcia_softc), ne_pcmcia_match, ne_pcmcia_attach
77 };
78
79 struct ne2000dev {
80 char *name;
81 int manufacturer;
82 int product;
83 char *cis1_info0;
84 char *cis1_info1;
85 int function;
86 int enet_maddr;
87 unsigned char enet_vendor[3];
88 } ne2000devs[] = {
89 { "PreMax PE-200",
90 0xffff, 0xffff, "PMX ", "PE-200", 0,
91 0x07f0, { 0x00, 0x20, 0xe0 } },
92 { "National Semiconductor InfoMover",
93 0x00a4, 0x0002, NULL, NULL, 0,
94 0x0ff0, { 0x08, 0x00, 0x5a } },
95 { "DEC DEPCM-BA",
96 0x0000, 0x0000, "DIGITAL", "DEPCM-XX", 0,
97 0x0ff0, { 0x00, 0x00, 0xe8 } },
98 /* this card might need pcic_alloc_iobase < 0x400, and/or
99 CIRRUS_PD672X on TI TravelMate 5000 needs it: */
100 { "Linksys EthernetCard",
101 0x0149, 0x0265, "LINKSYS", "E-CARD",
102 0, -1, { 0x00, 0x80, 0xc8 } },
103 { "Planet SmartCOM 2000",
104 0xffffffff, 0xffff, "PCMCIA", "UE2212", 0,
105 0xff0, { 0x00, 0x00, 0xe8 } },
106 #if 0
107 /* the rest of these are stolen from the linux pcnet pcmcia device
108 driver. Since I don't know the manfid or cis info strings for
109 any of them, they're not compiled in until I do. */
110
111 { "Accton EN2212",
112 0x0000, 0x0000, NULL, NULL, 0,
113 0x0ff0, { 0x00, 0x00, 0xe8 } },
114 { "Allied Telesis LA-PCM",
115 0x0000, 0x0000, NULL, NULL, 0,
116 0x0ff0, { 0x00, 0x00, 0xf4 } },
117 { "APEX MultiCard",
118 0x0000, 0x0000, NULL, NULL, 0,
119 0x03f4, { 0x00, 0x20, 0xe5 } },
120 { "ASANTE FriendlyNet",
121 0x0000, 0x0000, NULL, NULL, 0,
122 0x4910, { 0x00, 0x00, 0x94 } },
123 { "Danpex EN-6200P2",
124 0x0000, 0x0000, NULL, NULL, 0,
125 0x0110, { 0x00, 0x40, 0xc7 } },
126 { "DataTrek NetCard",
127 0x0000, 0x0000, NULL, NULL, 0,
128 0x0ff0, { 0x00, 0x20, 0xe8 } },
129 { "Dayna CommuniCard E",
130 0x0000, 0x0000, NULL, NULL, 0,
131 0x0110, { 0x00, 0x80, 0x19 } },
132 { "D-Link DE-650",
133 0x0000, 0x0000, NULL, NULL, 0,
134 0x0040, { 0x00, 0x80, 0xc8 } },
135 { "EP-210 Ethernet",
136 0x0000, 0x0000, NULL, NULL, 0,
137 0x0110, { 0x00, 0x40, 0x33 } },
138 { "Epson EEN10B",
139 0x0000, 0x0000, NULL, NULL, 0,
140 0x0ff0, { 0x00, 0x00, 0x48 } },
141 { "ELECOM Laneed LD-CDWA",
142 0x0000, 0x0000, NULL, NULL, 0,
143 0x00b8, { 0x08, 0x00, 0x42 } },
144 { "Grey Cell GCS2220",
145 0x0000, 0x0000, NULL, NULL, 0,
146 0x0000, { 0x00, 0x47, 0x43 } },
147 { "Hypertec Ethernet",
148 0x0000, 0x0000, NULL, NULL, 0,
149 0x01c0, { 0x00, 0x40, 0x4c } },
150 { "IBM CCAE",
151 0x0000, 0x0000, NULL, NULL, 0,
152 0x0ff0, { 0x08, 0x00, 0x5a } },
153 { "IBM CCAE",
154 0x0000, 0x0000, NULL, NULL, 0,
155 0x0ff0, { 0x00, 0x04, 0xac } },
156 { "IBM CCAE",
157 0x0000, 0x0000, NULL, NULL, 0,
158 0x0ff0, { 0x00, 0x06, 0x29 } },
159 { "IBM FME",
160 0x0000, 0x0000, NULL, NULL, 0,
161 0x0374, { 0x00, 0x04, 0xac } },
162 { "IBM FME",
163 0x0000, 0x0000, NULL, NULL, 0,
164 0x0374, { 0x08, 0x00, 0x5a } },
165 { "I-O DATA PCLA/T",
166 0x0000, 0x0000, NULL, NULL, 0,
167 0x0ff0, { 0x00, 0xa0, 0xb0 } },
168 { "Katron PE-520",
169 0x0000, 0x0000, NULL, NULL, 0,
170 0x0110, { 0x00, 0x40, 0xf6 } },
171 { "Kingston KNE-PCM/x",
172 0x0000, 0x0000, NULL, NULL, 0,
173 0x0ff0, { 0x00, 0xc0, 0xf0 } },
174 { "Kingston KNE-PCM/x",
175 0x0000, 0x0000, NULL, NULL, 0,
176 0x0ff0, { 0xe2, 0x0c, 0x0f } },
177 { "Kingston KNE-PC2",
178 0x0000, 0x0000, NULL, NULL, 0,
179 0x0180, { 0x00, 0xc0, 0xf0 } },
180 { "Longshine LCS-8534",
181 0x0000, 0x0000, NULL, NULL, 0,
182 0x0000, { 0x08, 0x00, 0x00 } },
183 { "Maxtech PCN2000",
184 0x0000, 0x0000, NULL, NULL, 0,
185 0x5000, { 0x00, 0x00, 0xe8 } },
186 { "NDC Instant-Link",
187 0x0000, 0x0000, NULL, NULL, 0,
188 0x003a, { 0x00, 0x80, 0xc6 } },
189 { "NE2000 Compatible",
190 0x0000, 0x0000, NULL, NULL, 0,
191 0x0ff0, { 0x00, 0xa0, 0x0c } },
192 { "Network General Sniffer",
193 0x0000, 0x0000, NULL, NULL, 0,
194 0x0ff0, { 0x00, 0x00, 0x65 } },
195 { "Panasonic VEL211",
196 0x0000, 0x0000, NULL, NULL, 0,
197 0x0ff0, { 0x00, 0x80, 0x45 } },
198 { "RPTI EP400",
199 0x0000, 0x0000, NULL, NULL, 0,
200 0x0110, { 0x00, 0x40, 0x95 } },
201 { "SCM Ethernet",
202 0x0000, 0x0000, NULL, NULL, 0,
203 0x0ff0, { 0x00, 0x20, 0xcb } },
204 { "Socket EA",
205 0x0000, 0x0000, NULL, NULL, 0,
206 0x4000, { 0x00, 0xc0, 0x1b } },
207 { "Volktek NPL-402CT",
208 0x0000, 0x0000, NULL, NULL, 0,
209 0x0060, { 0x00, 0x40, 0x05 } },
210 #endif
211 };
212
213 #define NE2000_NDEVS (sizeof(ne2000devs) / sizeof(ne2000devs[0]))
214
215 #define ne2000_match(card, fct, n) \
216 ((((((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
217 ((card)->product == ne2000devs[(n)].product)) || \
218 ((ne2000devs[(n)].cis1_info0) && (ne2000devs[(n)].cis1_info1) && \
219 (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis1_info0) == 0) && \
220 (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis1_info1) == 0))) && \
221 (pa->pf->number == ne2000devs[(n)].function))? \
222 &ne2000devs[(n)]:NULL)
223
224 int
225 ne_pcmcia_match(parent, match, aux)
226 struct device *parent;
227 #ifdef __BROKEN_INDIRECT_CONFIG
228 void *match;
229 #else
230 struct cfdata *cf;
231 #endif
232 void *aux;
233 {
234 struct pcmcia_attach_args *pa = aux;
235 int i;
236
237 for (i = 0; i < NE2000_NDEVS; i++) {
238 if (ne2000_match(pa->card, pa->pf->number, i))
239 return (1);
240 }
241
242 return (0);
243 }
244
245 void
246 ne_pcmcia_attach(parent, self, aux)
247 struct device *parent, *self;
248 void *aux;
249 {
250 struct ne_pcmcia_softc *psc = (void *) self;
251 struct ne2000_softc *nsc = &psc->sc_ne2000;
252 struct dp8390_softc *dsc = &nsc->sc_dp8390;
253 struct pcmcia_attach_args *pa = aux;
254 struct pcmcia_config_entry *cfe;
255 struct ne2000dev *ne_dev;
256 struct pcmcia_mem_handle pcmh;
257 bus_addr_t offset;
258 int i, j, mwindow;
259 u_int8_t myea[6], *enaddr = NULL;
260
261 psc->sc_pf = pa->pf;
262 cfe = pa->pf->cfe_head.sqh_first;
263
264 #if 0
265 /*
266 * Some ne2000 driver's claim to have memory; others don't.
267 * Since I don't care, I don't check.
268 */
269
270 if (cfe->num_memspace != 1) {
271 printf(": unexpected number of memory spaces "
272 " %d should be 1\n", cfe->num_memspace);
273 return;
274 }
275 #endif
276
277 if (cfe->num_iospace == 1) {
278 if (cfe->iospace[0].length != NE2000_NPORTS) {
279 printf(": unexpected I/O space configuration\n");
280 return;
281 }
282 } else if (cfe->num_iospace == 2) {
283 /*
284 * Some cards report a separate space for NIC and ASIC.
285 * This make some sense, but we must allocate a single
286 * NE2000_NPORTS-sized chunk, due to brain damaged
287 * address decoders on some of these cards.
288 */
289 if ((cfe->iospace[0].length + cfe->iospace[1].length) !=
290 NE2000_NPORTS) {
291 printf(": unexpected I/O space configuration\n");
292 return;
293 }
294 } else {
295 printf(": unexpected number of i/o spaces %d"
296 " should be 1 or 2\n", cfe->num_iospace);
297 }
298
299 if (pcmcia_io_alloc(pa->pf, 0, NE2000_NPORTS, NE2000_NPORTS,
300 &psc->sc_pcioh)) {
301 printf(": can't alloc i/o space\n");
302 return;
303 }
304
305 dsc->sc_regt = psc->sc_pcioh.iot;
306 dsc->sc_regh = psc->sc_pcioh.ioh;
307
308 nsc->sc_asict = psc->sc_pcioh.iot;
309 if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
310 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
311 &nsc->sc_asich)) {
312 printf(": can't get subregion for asic\n");
313 return;
314 }
315
316 /* Set up power management hooks. */
317 dsc->sc_enable = ne_pcmcia_enable;
318 dsc->sc_disable = ne_pcmcia_disable;
319
320 /* Enable the card. */
321 pcmcia_function_init(pa->pf, cfe);
322 if (pcmcia_function_enable(pa->pf)) {
323 printf(": function enable failed\n");
324 return;
325 }
326
327 /* some cards claim to be io16, but they're lying. */
328 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
329 NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
330 &psc->sc_pcioh, &psc->sc_nic_io_window)) {
331 printf(": can't map NIC i/o space\n");
332 return;
333 }
334
335 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
336 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
337 &psc->sc_pcioh, &psc->sc_asic_io_window)) {
338 printf(": can't map ASIC i/o space\n");
339 return;
340 }
341
342 printf("\n");
343
344 /*
345 * Read the station address from the board.
346 */
347 for (i = 0; i < NE2000_NDEVS; i++) {
348 if ((ne_dev = ne2000_match(pa->card, pa->pf->number, i))
349 != NULL) {
350 if (ne_dev->enet_maddr >= 0) {
351 if (pcmcia_mem_alloc(pa->pf,
352 ETHER_ADDR_LEN * 2, &pcmh)) {
353 printf("%s: can't alloc mem for"
354 " enet addr\n",
355 dsc->sc_dev.dv_xname);
356 return;
357 }
358 if (pcmcia_mem_map(pa->pf, PCMCIA_MEM_ATTR,
359 ne_dev->enet_maddr, ETHER_ADDR_LEN * 2,
360 &pcmh, &offset, &mwindow)) {
361 printf("%s: can't map mem for"
362 " enet addr\n",
363 dsc->sc_dev.dv_xname);
364 return;
365 }
366 for (j = 0; j < ETHER_ADDR_LEN; j++)
367 myea[j] = bus_space_read_1(pcmh.memt,
368 pcmh.memh, offset + (j * 2));
369 pcmcia_mem_unmap(pa->pf, mwindow);
370 pcmcia_mem_free(pa->pf, &pcmh);
371 enaddr = myea;
372 }
373 break;
374 }
375 }
376
377 if (enaddr != NULL) {
378 /*
379 * Make sure this is what we expect.
380 */
381 if (enaddr[0] != ne_dev->enet_vendor[0] ||
382 enaddr[1] != ne_dev->enet_vendor[1] ||
383 enaddr[2] != ne_dev->enet_vendor[2]) {
384 printf("\n%s: enet addr has incorrect vendor code\n",
385 dsc->sc_dev.dv_xname);
386 printf("%s: (%02x:%02x:%02x should be "
387 "%02x:%02x:%02x)\n", dsc->sc_dev.dv_xname,
388 enaddr[0], enaddr[1], enaddr[2],
389 ne_dev->enet_vendor[0],
390 ne_dev->enet_vendor[1],
391 ne_dev->enet_vendor[2]);
392 return;
393 }
394 }
395
396 printf("%s: %s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name);
397
398 ne2000_attach(nsc, enaddr);
399
400 pcmcia_function_disable(pa->pf);
401 }
402
403 int
404 ne_pcmcia_enable(dsc)
405 struct dp8390_softc *dsc;
406 {
407 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
408
409 /* set up the interrupt */
410 psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
411 dsc);
412 if (psc->sc_ih == NULL) {
413 printf("%s: couldn't establish interrupt\n",
414 dsc->sc_dev.dv_xname);
415 return (1);
416 }
417
418 return (pcmcia_function_enable(psc->sc_pf));
419 }
420
421 void
422 ne_pcmcia_disable(dsc)
423 struct dp8390_softc *dsc;
424 {
425 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
426
427 pcmcia_function_disable(psc->sc_pf);
428
429 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
430 }
431