if_ne_pcmcia.c revision 1.4.2.2 1 /* $NetBSD: if_ne_pcmcia.c,v 1.4.2.2 1997/11/20 04:03:47 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 /* this card might need pcic_alloc_iobase < 0x400, and/or
100 CIRRUS_PD672X on TI TravelMate 5000 needs it: */
101 { "Linksys EthernetCard",
102 0x0149, 0x0265, "LINKSYS", "E-CARD",
103 0, -1, { 0x00, 0x80, 0xc8 } },
104 { "Planet SmartCOM 2000",
105 /* This card doesn't have manufacturer and product id in CIS. */
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 #if 0
114 /* the rest of these are stolen from the linux pcnet pcmcia device
115 driver. Since I don't know the manfid or cis info strings for
116 any of them, they're not compiled in until I do. */
117
118 { "Accton EN2212",
119 0x0000, 0x0000, NULL, NULL, 0,
120 0x0ff0, { 0x00, 0x00, 0xe8 } },
121 { "Allied Telesis LA-PCM",
122 0x0000, 0x0000, NULL, NULL, 0,
123 0x0ff0, { 0x00, 0x00, 0xf4 } },
124 { "APEX MultiCard",
125 0x0000, 0x0000, NULL, NULL, 0,
126 0x03f4, { 0x00, 0x20, 0xe5 } },
127 { "ASANTE FriendlyNet",
128 0x0000, 0x0000, NULL, NULL, 0,
129 0x4910, { 0x00, 0x00, 0x94 } },
130 { "Danpex EN-6200P2",
131 0x0000, 0x0000, NULL, NULL, 0,
132 0x0110, { 0x00, 0x40, 0xc7 } },
133 { "DataTrek NetCard",
134 0x0000, 0x0000, NULL, NULL, 0,
135 0x0ff0, { 0x00, 0x20, 0xe8 } },
136 { "Dayna CommuniCard E",
137 0x0000, 0x0000, NULL, NULL, 0,
138 0x0110, { 0x00, 0x80, 0x19 } },
139 { "EP-210 Ethernet",
140 0x0000, 0x0000, NULL, NULL, 0,
141 0x0110, { 0x00, 0x40, 0x33 } },
142 { "Epson EEN10B",
143 0x0000, 0x0000, NULL, NULL, 0,
144 0x0ff0, { 0x00, 0x00, 0x48 } },
145 { "ELECOM Laneed LD-CDWA",
146 0x0000, 0x0000, NULL, NULL, 0,
147 0x00b8, { 0x08, 0x00, 0x42 } },
148 { "Grey Cell GCS2220",
149 0x0000, 0x0000, NULL, NULL, 0,
150 0x0000, { 0x00, 0x47, 0x43 } },
151 { "Hypertec Ethernet",
152 0x0000, 0x0000, NULL, NULL, 0,
153 0x01c0, { 0x00, 0x40, 0x4c } },
154 { "IBM CCAE",
155 0x0000, 0x0000, NULL, NULL, 0,
156 0x0ff0, { 0x08, 0x00, 0x5a } },
157 { "IBM CCAE",
158 0x0000, 0x0000, NULL, NULL, 0,
159 0x0ff0, { 0x00, 0x04, 0xac } },
160 { "IBM CCAE",
161 0x0000, 0x0000, NULL, NULL, 0,
162 0x0ff0, { 0x00, 0x06, 0x29 } },
163 { "IBM FME",
164 0x0000, 0x0000, NULL, NULL, 0,
165 0x0374, { 0x00, 0x04, 0xac } },
166 { "IBM FME",
167 0x0000, 0x0000, NULL, NULL, 0,
168 0x0374, { 0x08, 0x00, 0x5a } },
169 { "I-O DATA PCLA/T",
170 0x0000, 0x0000, NULL, NULL, 0,
171 0x0ff0, { 0x00, 0xa0, 0xb0 } },
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 #ifdef __BROKEN_INDIRECT_CONFIG
234 void *match;
235 #else
236 struct cfdata *cf;
237 #endif
238 void *aux;
239 {
240 struct pcmcia_attach_args *pa = aux;
241 int i;
242
243 for (i = 0; i < NE2000_NDEVS; i++) {
244 if (ne2000_match(pa->card, pa->pf->number, i))
245 return (1);
246 }
247
248 return (0);
249 }
250
251 void
252 ne_pcmcia_attach(parent, self, aux)
253 struct device *parent, *self;
254 void *aux;
255 {
256 struct ne_pcmcia_softc *psc = (void *) self;
257 struct ne2000_softc *nsc = &psc->sc_ne2000;
258 struct dp8390_softc *dsc = &nsc->sc_dp8390;
259 struct pcmcia_attach_args *pa = aux;
260 struct pcmcia_config_entry *cfe;
261 struct ne2000dev *ne_dev;
262 struct pcmcia_mem_handle pcmh;
263 bus_addr_t offset;
264 int i, j, mwindow;
265 u_int8_t myea[6], *enaddr = NULL;
266
267 psc->sc_pf = pa->pf;
268 cfe = pa->pf->cfe_head.sqh_first;
269
270 #if 0
271 /*
272 * Some ne2000 driver's claim to have memory; others don't.
273 * Since I don't care, I don't check.
274 */
275
276 if (cfe->num_memspace != 1) {
277 printf(": unexpected number of memory spaces "
278 " %d should be 1\n", cfe->num_memspace);
279 return;
280 }
281 #endif
282
283 if (cfe->num_iospace == 1) {
284 if (cfe->iospace[0].length != NE2000_NPORTS) {
285 printf(": unexpected I/O space configuration\n");
286 return;
287 }
288 } else if (cfe->num_iospace == 2) {
289 /*
290 * Some cards report a separate space for NIC and ASIC.
291 * This make some sense, but we must allocate a single
292 * NE2000_NPORTS-sized chunk, due to brain damaged
293 * address decoders on some of these cards.
294 */
295 if ((cfe->iospace[0].length + cfe->iospace[1].length) !=
296 NE2000_NPORTS) {
297 printf(": unexpected I/O space configuration\n");
298 return;
299 }
300 } else {
301 printf(": unexpected number of i/o spaces %d"
302 " should be 1 or 2\n", cfe->num_iospace);
303 }
304
305 if (pcmcia_io_alloc(pa->pf, 0, NE2000_NPORTS, NE2000_NPORTS,
306 &psc->sc_pcioh)) {
307 printf(": can't alloc i/o space\n");
308 return;
309 }
310
311 dsc->sc_regt = psc->sc_pcioh.iot;
312 dsc->sc_regh = psc->sc_pcioh.ioh;
313
314 nsc->sc_asict = psc->sc_pcioh.iot;
315 if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
316 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
317 &nsc->sc_asich)) {
318 printf(": can't get subregion for asic\n");
319 return;
320 }
321
322 /* Set up power management hooks. */
323 dsc->sc_enable = ne_pcmcia_enable;
324 dsc->sc_disable = ne_pcmcia_disable;
325
326 /* Enable the card. */
327 pcmcia_function_init(pa->pf, cfe);
328 if (pcmcia_function_enable(pa->pf)) {
329 printf(": function enable failed\n");
330 return;
331 }
332
333 /* some cards claim to be io16, but they're lying. */
334 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
335 NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
336 &psc->sc_pcioh, &psc->sc_nic_io_window)) {
337 printf(": can't map NIC i/o space\n");
338 return;
339 }
340
341 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
342 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
343 &psc->sc_pcioh, &psc->sc_asic_io_window)) {
344 printf(": can't map ASIC i/o space\n");
345 return;
346 }
347
348 printf("\n");
349
350 /*
351 * Read the station address from the board.
352 */
353 for (i = 0; i < NE2000_NDEVS; i++) {
354 if ((ne_dev = ne2000_match(pa->card, pa->pf->number, i))
355 != NULL) {
356 if (ne_dev->enet_maddr >= 0) {
357 if (pcmcia_mem_alloc(pa->pf,
358 ETHER_ADDR_LEN * 2, &pcmh)) {
359 printf("%s: can't alloc mem for"
360 " enet addr\n",
361 dsc->sc_dev.dv_xname);
362 return;
363 }
364 if (pcmcia_mem_map(pa->pf, PCMCIA_MEM_ATTR,
365 ne_dev->enet_maddr, ETHER_ADDR_LEN * 2,
366 &pcmh, &offset, &mwindow)) {
367 printf("%s: can't map mem for"
368 " enet addr\n",
369 dsc->sc_dev.dv_xname);
370 return;
371 }
372 for (j = 0; j < ETHER_ADDR_LEN; j++)
373 myea[j] = bus_space_read_1(pcmh.memt,
374 pcmh.memh, offset + (j * 2));
375 pcmcia_mem_unmap(pa->pf, mwindow);
376 pcmcia_mem_free(pa->pf, &pcmh);
377 enaddr = myea;
378 }
379 break;
380 }
381 }
382
383 if (enaddr != NULL) {
384 /*
385 * Make sure this is what we expect.
386 */
387 if (enaddr[0] != ne_dev->enet_vendor[0] ||
388 enaddr[1] != ne_dev->enet_vendor[1] ||
389 enaddr[2] != ne_dev->enet_vendor[2]) {
390 printf("\n%s: enet addr has incorrect vendor code\n",
391 dsc->sc_dev.dv_xname);
392 printf("%s: (%02x:%02x:%02x should be "
393 "%02x:%02x:%02x)\n", dsc->sc_dev.dv_xname,
394 enaddr[0], enaddr[1], enaddr[2],
395 ne_dev->enet_vendor[0],
396 ne_dev->enet_vendor[1],
397 ne_dev->enet_vendor[2]);
398 return;
399 }
400 }
401
402 printf("%s: %s Ethernet\n", dsc->sc_dev.dv_xname, ne_dev->name);
403
404 ne2000_attach(nsc, enaddr);
405
406 pcmcia_function_disable(pa->pf);
407 }
408
409 int
410 ne_pcmcia_enable(dsc)
411 struct dp8390_softc *dsc;
412 {
413 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
414
415 /* set up the interrupt */
416 psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
417 dsc);
418 if (psc->sc_ih == NULL) {
419 printf("%s: couldn't establish interrupt\n",
420 dsc->sc_dev.dv_xname);
421 return (1);
422 }
423
424 return (pcmcia_function_enable(psc->sc_pf));
425 }
426
427 void
428 ne_pcmcia_disable(dsc)
429 struct dp8390_softc *dsc;
430 {
431 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
432
433 pcmcia_function_disable(psc->sc_pf);
434
435 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
436 }
437