if_ne_pcmcia.c revision 1.11 1 /* $NetBSD: if_ne_pcmcia.c,v 1.11 1998/03/06 20:00:28 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_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 #ifdef __BROKEN_INDIRECT_CONFIG
56 int ne_pcmcia_match __P((struct device *, void *, void *));
57 #else
58 int ne_pcmcia_match __P((struct device *, struct cfdata *, void *));
59 #endif
60 void ne_pcmcia_attach __P((struct device *, struct device *, void *));
61
62 int ne_pcmcia_enable __P((struct dp8390_softc *));
63 void ne_pcmcia_disable __P((struct dp8390_softc *));
64
65 struct ne_pcmcia_softc {
66 struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
67
68 /* PCMCIA-specific goo */
69 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o information */
70 int sc_asic_io_window; /* i/o window for ASIC */
71 int sc_nic_io_window; /* i/o window for NIC */
72 struct pcmcia_function *sc_pf; /* our PCMCIA function */
73 void *sc_ih; /* interrupt handle */
74 };
75
76 struct cfattach ne_pcmcia_ca = {
77 sizeof(struct ne_pcmcia_softc), ne_pcmcia_match, ne_pcmcia_attach
78 };
79
80 struct ne2000dev {
81 char *name;
82 int32_t manufacturer;
83 int32_t product;
84 char *cis1_info0;
85 char *cis1_info1;
86 int function;
87 int enet_maddr;
88 unsigned char enet_vendor[3];
89 } ne2000devs[] = {
90 { "PreMax PE-200",
91 0xffff, 0xffff, "PMX ", "PE-200", 0,
92 0x07f0, { 0x00, 0x20, 0xe0 } },
93 { "National Semiconductor InfoMover",
94 0x00a4, 0x0002, NULL, NULL, 0,
95 0x0ff0, { 0x08, 0x00, 0x5a } },
96 { "DEC DEPCM-BA",
97 0x0000, 0x0000, "DIGITAL", "DEPCM-XX", 0,
98 0x0ff0, { 0x00, 0x00, 0xe8 } },
99 { "Linksys EthernetCard",
100 0x0149, 0x0265, "LINKSYS", "E-CARD",
101 0, -1, { 0x00, 0x80, 0xc8 } },
102 { "Linksys Combo EthernetCard",
103 0x0149, 0xc1ab, NULL, NULL,
104 0, -1, { 0x00, 0x80, 0xc8 } },
105 { "Planet SmartCOM 2000",
106 PCMCIA_MANUFACTURER_INVALID, PCMCIA_PRODUCT_INVALID,
107 "PCMCIA", "UE2212", 0,
108 0xff0, { 0x00, 0x00, 0xe8 } },
109 { "D-Link DE-650",
110 PCMCIA_MANUFACTURER_INVALID, PCMCIA_PRODUCT_INVALID,
111 "D-Link", "DE-650", 0,
112 0x0040, { 0x00, 0x80, 0xc8 } },
113 { "I-O DATA PCLA/T",
114 0x01bf, 0x2216, NULL, NULL, 0,
115 -1 /* two possible location, 0x01c0 or 0x0ff0 */, { 0x00, 0xa0, 0xb0 } },
116 { "Dayna CommuniCard E",
117 0x0194, 0x002d,
118 "Dayna", "CommuniCard E", 0,
119 0x0110, { 0x00, 0x80, 0x19 } },
120 #if 0
121 /* the rest of these are stolen from the linux pcnet pcmcia device
122 driver. Since I don't know the manfid or cis info strings for
123 any of them, they're not compiled in until I do. */
124
125 { "Accton EN2212",
126 0x0000, 0x0000, NULL, NULL, 0,
127 0x0ff0, { 0x00, 0x00, 0xe8 } },
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 { "RPTI EP400",
207 0x0000, 0x0000, NULL, NULL, 0,
208 0x0110, { 0x00, 0x40, 0x95 } },
209 { "SCM Ethernet",
210 0x0000, 0x0000, NULL, NULL, 0,
211 0x0ff0, { 0x00, 0x20, 0xcb } },
212 { "Socket EA",
213 0x0000, 0x0000, NULL, NULL, 0,
214 0x4000, { 0x00, 0xc0, 0x1b } },
215 { "Volktek NPL-402CT",
216 0x0000, 0x0000, NULL, NULL, 0,
217 0x0060, { 0x00, 0x40, 0x05 } },
218 #endif
219 };
220
221 #define NE2000_NDEVS (sizeof(ne2000devs) / sizeof(ne2000devs[0]))
222
223 #define ne2000_match(card, fct, n) \
224 ((((((card)->manufacturer != PCMCIA_MANUFACTURER_INVALID) && \
225 ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
226 ((card)->product != PCMCIA_PRODUCT_INVALID) && \
227 ((card)->product == ne2000devs[(n)].product)) || \
228 ((ne2000devs[(n)].cis1_info0) && (ne2000devs[(n)].cis1_info1) && \
229 (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis1_info0) == 0) && \
230 (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis1_info1) == 0))) && \
231 ((fct) == ne2000devs[(n)].function))? \
232 &ne2000devs[(n)]:NULL)
233
234 int
235 ne_pcmcia_match(parent, match, aux)
236 struct device *parent;
237 #ifdef __BROKEN_INDIRECT_CONFIG
238 void *match;
239 #else
240 struct cfdata *match;
241 #endif
242 void *aux;
243 {
244 struct pcmcia_attach_args *pa = aux;
245 int i;
246
247 for (i = 0; i < NE2000_NDEVS; i++) {
248 if (ne2000_match(pa->card, pa->pf->number, i))
249 return (1);
250 }
251
252 return (0);
253 }
254
255 void
256 ne_pcmcia_attach(parent, self, aux)
257 struct device *parent, *self;
258 void *aux;
259 {
260 struct ne_pcmcia_softc *psc = (void *) self;
261 struct ne2000_softc *nsc = &psc->sc_ne2000;
262 struct dp8390_softc *dsc = &nsc->sc_dp8390;
263 struct pcmcia_attach_args *pa = aux;
264 struct pcmcia_config_entry *cfe;
265 struct ne2000dev *ne_dev;
266 struct pcmcia_mem_handle pcmh;
267 bus_addr_t offset;
268 int i, j, mwindow;
269 u_int8_t myea[6], *enaddr = NULL;
270
271 psc->sc_pf = pa->pf;
272 cfe = pa->pf->cfe_head.sqh_first;
273
274 #if 0
275 /*
276 * Some ne2000 driver's claim to have memory; others don't.
277 * Since I don't care, I don't check.
278 */
279
280 if (cfe->num_memspace != 1) {
281 printf(": unexpected number of memory spaces "
282 " %d should be 1\n", cfe->num_memspace);
283 return;
284 }
285 #endif
286
287 if (cfe->num_iospace == 1) {
288 if (cfe->iospace[0].length != NE2000_NPORTS) {
289 printf(": unexpected I/O space configuration\n");
290 return;
291 }
292 } else if (cfe->num_iospace == 2) {
293 /*
294 * Some cards report a separate space for NIC and ASIC.
295 * This make some sense, but we must allocate a single
296 * NE2000_NPORTS-sized chunk, due to brain damaged
297 * address decoders on some of these cards.
298 */
299 if ((cfe->iospace[0].length + cfe->iospace[1].length) !=
300 NE2000_NPORTS) {
301 printf(": unexpected I/O space configuration\n");
302 return;
303 }
304 } else {
305 printf(": unexpected number of i/o spaces %d"
306 " should be 1 or 2\n", cfe->num_iospace);
307 }
308
309 if (pcmcia_io_alloc(pa->pf, 0, NE2000_NPORTS, NE2000_NPORTS,
310 &psc->sc_pcioh)) {
311 printf(": can't alloc i/o space\n");
312 return;
313 }
314
315 dsc->sc_regt = psc->sc_pcioh.iot;
316 dsc->sc_regh = psc->sc_pcioh.ioh;
317
318 nsc->sc_asict = psc->sc_pcioh.iot;
319 if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
320 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
321 &nsc->sc_asich)) {
322 printf(": can't get subregion for asic\n");
323 return;
324 }
325
326 /* Set up power management hooks. */
327 dsc->sc_enable = ne_pcmcia_enable;
328 dsc->sc_disable = ne_pcmcia_disable;
329
330 /* Enable the card. */
331 pcmcia_function_init(pa->pf, cfe);
332 if (pcmcia_function_enable(pa->pf)) {
333 printf(": function enable failed\n");
334 return;
335 }
336
337 /* some cards claim to be io16, but they're lying. */
338 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
339 NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
340 &psc->sc_pcioh, &psc->sc_nic_io_window)) {
341 printf(": can't map NIC i/o space\n");
342 return;
343 }
344
345 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
346 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
347 &psc->sc_pcioh, &psc->sc_asic_io_window)) {
348 printf(": can't map ASIC i/o space\n");
349 return;
350 }
351
352 printf("\n");
353
354 /*
355 * Read the station address from the board.
356 */
357 for (i = 0; i < NE2000_NDEVS; i++) {
358 if ((ne_dev = ne2000_match(pa->card, pa->pf->number, i))
359 != NULL) {
360 if (ne_dev->enet_maddr >= 0) {
361 if (pcmcia_mem_alloc(pa->pf,
362 ETHER_ADDR_LEN * 2, &pcmh)) {
363 printf("%s: can't alloc mem for"
364 " enet addr\n",
365 dsc->sc_dev.dv_xname);
366 return;
367 }
368 if (pcmcia_mem_map(pa->pf, PCMCIA_MEM_ATTR,
369 ne_dev->enet_maddr, ETHER_ADDR_LEN * 2,
370 &pcmh, &offset, &mwindow)) {
371 printf("%s: can't map mem for"
372 " enet addr\n",
373 dsc->sc_dev.dv_xname);
374 return;
375 }
376 for (j = 0; j < ETHER_ADDR_LEN; j++)
377 myea[j] = bus_space_read_1(pcmh.memt,
378 pcmh.memh, offset + (j * 2));
379 pcmcia_mem_unmap(pa->pf, mwindow);
380 pcmcia_mem_free(pa->pf, &pcmh);
381 enaddr = myea;
382 }
383 break;
384 }
385 }
386
387 if (enaddr != NULL) {
388 /*
389 * Make sure this is what we expect.
390 */
391 if (enaddr[0] != ne_dev->enet_vendor[0] ||
392 enaddr[1] != ne_dev->enet_vendor[1] ||
393 enaddr[2] != ne_dev->enet_vendor[2]) {
394 printf("%s: enet addr has incorrect vendor code\n",
395 dsc->sc_dev.dv_xname);
396 printf("%s: (%02x:%02x:%02x should be "
397 "%02x:%02x:%02x)\n", dsc->sc_dev.dv_xname,
398 enaddr[0], enaddr[1], enaddr[2],
399 ne_dev->enet_vendor[0],
400 ne_dev->enet_vendor[1],
401 ne_dev->enet_vendor[2]);
402 return;
403 }
404 }
405
406 printf("%s: %s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name);
407
408 ne2000_attach(nsc, enaddr);
409
410 pcmcia_function_disable(pa->pf);
411 }
412
413 int
414 ne_pcmcia_enable(dsc)
415 struct dp8390_softc *dsc;
416 {
417 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
418
419 /* set up the interrupt */
420 psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
421 dsc);
422 if (psc->sc_ih == NULL) {
423 printf("%s: couldn't establish interrupt\n",
424 dsc->sc_dev.dv_xname);
425 return (1);
426 }
427
428 return (pcmcia_function_enable(psc->sc_pf));
429 }
430
431 void
432 ne_pcmcia_disable(dsc)
433 struct dp8390_softc *dsc;
434 {
435 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
436
437 pcmcia_function_disable(psc->sc_pf);
438
439 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
440 }
441