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