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