if_ne_pcmcia.c revision 1.123 1 /* $NetBSD: if_ne_pcmcia.c,v 1.123 2004/07/17 19:55:03 mycroft 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/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: if_ne_pcmcia.c,v 1.123 2004/07/17 19:55:03 mycroft Exp $");
34
35 #include <sys/param.h>
36 #include <sys/systm.h>
37 #include <sys/select.h>
38 #include <sys/device.h>
39 #include <sys/socket.h>
40
41 #include <net/if_types.h>
42 #include <net/if.h>
43 #include <net/if_media.h>
44 #include <net/if_ether.h>
45
46 #include <machine/bus.h>
47 #include <machine/intr.h>
48
49 #include <dev/pcmcia/pcmciareg.h>
50 #include <dev/pcmcia/pcmciavar.h>
51 #include <dev/pcmcia/pcmciadevs.h>
52
53 #include <dev/ic/dp8390reg.h>
54 #include <dev/ic/dp8390var.h>
55
56 #include <dev/ic/ne2000reg.h>
57 #include <dev/ic/ne2000var.h>
58
59 #include <dev/ic/rtl80x9reg.h>
60 #include <dev/ic/rtl80x9var.h>
61
62 #include <dev/ic/dl10019var.h>
63
64 #include <dev/ic/ax88190reg.h>
65 #include <dev/ic/ax88190var.h>
66
67 int ne_pcmcia_match __P((struct device *, struct cfdata *, void *));
68 void ne_pcmcia_attach __P((struct device *, struct device *, void *));
69 int ne_pcmcia_detach __P((struct device *, int));
70
71 int ne_pcmcia_enable __P((struct dp8390_softc *));
72 void ne_pcmcia_disable __P((struct dp8390_softc *));
73
74 struct ne_pcmcia_softc {
75 struct ne2000_softc sc_ne2000; /* real "ne2000" softc */
76
77 /* PCMCIA-specific goo */
78 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o information */
79 int sc_asic_io_window; /* i/o window for ASIC */
80 int sc_nic_io_window; /* i/o window for NIC */
81 struct pcmcia_function *sc_pf; /* our PCMCIA function */
82 void *sc_ih; /* interrupt handle */
83 };
84
85 u_int8_t *
86 ne_pcmcia_get_enaddr __P((struct ne_pcmcia_softc *, int,
87 u_int8_t [ETHER_ADDR_LEN]));
88 u_int8_t *
89 ne_pcmcia_dl10019_get_enaddr __P((struct ne_pcmcia_softc *,
90 u_int8_t [ETHER_ADDR_LEN]));
91 int ne_pcmcia_ax88190_set_iobase __P((struct ne_pcmcia_softc *));
92
93 CFATTACH_DECL(ne_pcmcia, sizeof(struct ne_pcmcia_softc),
94 ne_pcmcia_match, ne_pcmcia_attach, ne_pcmcia_detach, dp8390_activate);
95
96 static const struct ne2000dev {
97 int32_t manufacturer;
98 int32_t product;
99 char *cis_info[4];
100 int function;
101 int enet_maddr;
102 unsigned char enet_vendor[3];
103 int flags;
104 #define NE2000DVF_DL10019 0x0001 /* chip is D-Link DL10019 */
105 #define NE2000DVF_AX88190 0x0002 /* chip is ASIX AX88190 */
106 } ne2000devs[] = {
107 { PCMCIA_VENDOR_EDIMAX, PCMCIA_PRODUCT_EDIMAX_EP4000A,
108 PCMCIA_CIS_INVALID,
109 0, -1, { 0x00, 0xa0, 0x0c } },
110
111 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
112 PCMCIA_CIS_SYNERGY21_S21810,
113 0, -1, { 0x00, 0x48, 0x54 } },
114
115 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
116 PCMCIA_CIS_AMBICOM_AMB8002T,
117 0, -1, { 0x00, 0x10, 0x7a } },
118
119 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
120 PCMCIA_CIS_AMBICOM_AMB8110,
121 0, -1, { 0x00, 0x10, 0x7a }, NE2000DVF_AX88190 },
122
123 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
124 PCMCIA_CIS_PREMAX_PE200,
125 0, 0x07f0, { 0x00, 0x20, 0xe0 } },
126
127 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
128 PCMCIA_CIS_PREMAX_PE200,
129 0, -1, { 0x00, 0x20, 0xe0 } },
130
131 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
132 PCMCIA_CIS_DIGITAL_DEPCMXX,
133 0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
134
135 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
136 PCMCIA_CIS_PLANET_SMARTCOM2000,
137 0, 0xff0, { 0x00, 0x00, 0xe8 } },
138
139 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
140 PCMCIA_CIS_DLINK_DE660,
141 0, -1, { 0x00, 0x80, 0xc8 } },
142
143 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
144 PCMCIA_CIS_DLINK_DE660PLUS,
145 0, -1, { 0x00, 0x80, 0xc8 } },
146
147 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
148 PCMCIA_CIS_RPTI_EP400,
149 0, 0x110, { 0x00, 0x40, 0x95 } },
150
151 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
152 PCMCIA_CIS_RPTI_EP401,
153 0, -1, { 0x00, 0x40, 0x95 } },
154
155 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
156 PCMCIA_CIS_ACCTON_EN2212,
157 0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
158
159 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
160 PCMCIA_CIS_ACCTON_EN2216,
161 0, -1, { 0x00, 0x00, 0xe8 } },
162
163 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
164 PCMCIA_CIS_SVEC_COMBOCARD,
165 0, -1, { 0x00, 0xe0, 0x98 } },
166
167 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
168 PCMCIA_CIS_SVEC_LANCARD,
169 0, 0x7f0, { 0x00, 0xc0, 0x6c } },
170
171 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_EPSON_EEN10B,
172 PCMCIA_CIS_EPSON_EEN10B,
173 0, 0xff0, { 0x00, 0x00, 0x48 } },
174
175 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
176 PCMCIA_CIS_TAMARACK_ETHERNET,
177 0, -1, { 0x00, 0x00, 0x00 } },
178
179 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
180 PCMCIA_CIS_CNET_NE2000,
181 0, -1, { 0x00, 0x80, 0xad } },
182
183 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
184 PCMCIA_CIS_GENIUS_ME3000II,
185 0, -1, { 0x00, 0x40, 0x95 } },
186
187
188 /*
189 * You have to add new entries which contains
190 * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID
191 * in front of this comment.
192 *
193 * There are cards which use a generic vendor and product id but needs
194 * a different handling depending on the cis_info, so ne2000_match
195 * needs a table where the exceptions comes first and then the normal
196 * product and vendor entries.
197 */
198
199 { PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
200 PCMCIA_CIS_INVALID,
201 0, 0x0ff0, { 0xff, 0xff, 0xff } },
202
203 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
204 PCMCIA_CIS_INVALID,
205 0, -1, { 0x00, 0x80, 0xc8 } },
206
207 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
208 PCMCIA_CIS_INVALID,
209 0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_DL10019 },
210
211 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
212 PCMCIA_CIS_INVALID,
213 0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_AX88190 },
214
215 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
216 PCMCIA_CIS_LANTECH_FASTNETTX,
217 0, -1, { 0x00, 0x04, 0x1c }, NE2000DVF_AX88190 },
218
219 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
220 PCMCIA_CIS_INVALID,
221 0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_DL10019 },
222
223 { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
224 PCMCIA_CIS_INVALID,
225 0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_DL10019 },
226
227 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
228 PCMCIA_CIS_DLINK_DFE670TXD,
229 0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_DL10019 },
230
231 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
232 PCMCIA_CIS_MELCO_LPC2_TX,
233 0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_DL10019 },
234
235 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
236 PCMCIA_CIS_INVALID,
237 0, -1, { 0x00, 0x80, 0xc8 } },
238
239 { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD,
240 PCMCIA_CIS_INVALID,
241 0, 0x0120, { 0x20, 0x04, 0x49 } },
242
243 /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs
244 above this list, we need to keep this one below the ECARD_1, or else
245 both will match the same more-generic entry rather than the more
246 specific one above with proper vendor and product IDs. */
247 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
248 PCMCIA_CIS_LINKSYS_ECARD_2,
249 0, -1, { 0x00, 0x80, 0xc8 } },
250
251 /*
252 * D-Link DE-650 has many minor versions:
253 *
254 * CIS information Manufacturer Product Note
255 * 1 "D-Link, DE-650" INVALID INVALID white card
256 * 2 "D-Link, DE-650, Ver 01.00" INVALID INVALID became bare metal
257 * 3 "D-Link, DE-650, Ver 01.00" 0x149 0x265 minor change in look
258 * 4 "D-Link, DE-650, Ver 01.00" 0x149 0x265 collision LED added
259 *
260 * While the 1st and the 2nd types should use the "D-Link DE-650" entry,
261 * the 3rd and the 4th types should use the "Linksys EtherCard" entry.
262 * Therefore, this enty must be below the LINKSYS_ECARD_1. --itohy
263 */
264 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
265 PCMCIA_CIS_DLINK_DE650,
266 0, 0x0040, { 0x00, 0x80, 0xc8 } },
267
268 /*
269 * IO-DATA PCLA/TE and later version of PCLA/T has valid
270 * vendor/product ID and it is possible to read MAC address
271 * using standard I/O ports. It also read from CIS offset 0x01c0.
272 * On the other hand, earlier version of PCLA/T doesn't have valid
273 * vendor/product ID and MAC address must be read from CIS offset
274 * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work).
275 * And CIS information of earlier and later version of PCLA/T are
276 * same except fourth element. So, for now, we place the entry for
277 * PCLA/TE (and later version of PCLA/T) followed by entry
278 * for the earlier version of PCLA/T (or, modify to match all CIS
279 * information and have three or more individual entries).
280 */
281 { PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE,
282 PCMCIA_CIS_INVALID,
283 0, -1, { 0x00, 0xa0, 0xb0 } },
284
285 /*
286 * This entry should be placed after above PCLA-TE entry.
287 * See above comments for detail.
288 */
289 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
290 PCMCIA_CIS_IODATA_PCLAT,
291 0, 0x0ff0, { 0x00, 0xa0, 0xb0 } },
292
293 { PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1,
294 PCMCIA_CIS_INVALID,
295 0, 0x0110, { 0x00, 0x80, 0x19 } },
296
297 { PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2,
298 PCMCIA_CIS_INVALID,
299 0, -1, { 0x00, 0x80, 0x19 } },
300
301 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
302 PCMCIA_CIS_COREGA_ETHER_PCC_T,
303 0, -1, { 0x00, 0x00, 0xf4 } },
304
305 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
306 PCMCIA_CIS_COREGA_ETHER_PCC_TD,
307 0, -1, { 0x00, 0x00, 0xf4 } },
308
309 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
310 PCMCIA_CIS_COREGA_ETHER_PCC_TL,
311 0, -1, { 0x00, 0x00, 0xf4 } },
312
313 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
314 PCMCIA_CIS_COREGA_ETHER_II_PCC_T,
315 0, -1, { 0x00, 0x00, 0xf4 } },
316
317 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
318 PCMCIA_CIS_COREGA_ETHER_II_PCC_TD,
319 0, -1, { 0x00, 0x00, 0xf4 } },
320
321 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
322 PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX,
323 0, -1, { 0x00, 0x00, 0xf4 }, NE2000DVF_DL10019 },
324
325 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
326 PCMCIA_CIS_COREGA_FETHER_PCC_TXF,
327 0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_DL10019 },
328
329 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
330 PCMCIA_CIS_COREGA_FETHER_PCC_TXD,
331 0, -1, { 0x00, 0x90, 0x99 } },
332
333 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
334 PCMCIA_CIS_COREGA_FETHER_II_PCC_TXD,
335 0, -1, { 0x00, 0x90, 0x99 }, NE2000DVF_AX88190 },
336
337 { PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B,
338 PCMCIA_CIS_INVALID,
339 0, 0x01c0, { 0xff, 0xff, 0xff } },
340
341 { PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD,
342 PCMCIA_CIS_INVALID,
343 0, 0x01c0, { 0x00, 0xe0, 0x29 } },
344
345 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
346 PCMCIA_CIS_SMC_8041,
347 0, -1, { 0x00, 0x04, 0xe2 } },
348
349 { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_EA_ETHER,
350 PCMCIA_CIS_INVALID,
351 0, -1, { 0x00, 0xc0, 0x1b } },
352
353 { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER_CF,
354 PCMCIA_CIS_INVALID,
355 0, -1, { 0x00, 0xc0, 0x1b } },
356
357 { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETH_10_100_CF,
358 PCMCIA_CIS_INVALID,
359 0, -1, { 0x00, 0xe0, 0x98 }, NE2000DVF_DL10019 },
360
361 { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER,
362 PCMCIA_CIS_INVALID,
363 0, -1, { 0x00, 0xc0, 0x1b } },
364
365 { PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE2,
366 PCMCIA_CIS_INVALID,
367 0, -1, { 0x00, 0xc0, 0xf0 } },
368
369 { PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10,
370 PCMCIA_CIS_INVALID,
371 0, -1, { 0x00, 0x10, 0xa4 } },
372
373 { PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX,
374 PCMCIA_CIS_INVALID,
375 0, -1, { 0xff, 0xff, 0xff }, NE2000DVF_AX88190 },
376
377 { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC_CF_CLT,
378 PCMCIA_CIS_INVALID,
379 0, -1, { 0x00, 0x07, 0x40 } },
380
381 { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC3_CLT,
382 PCMCIA_CIS_INVALID,
383 0, -1, { 0x00, 0x07, 0x40 } },
384
385 { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC4_CLX,
386 PCMCIA_CIS_INVALID,
387 0, -1, { 0x00, 0x40, 0xfa }, NE2000DVF_AX88190 },
388
389 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
390 PCMCIA_CIS_BILLIONTON_LNT10TN,
391 0, -1, { 0x00, 0x00, 0x00 } },
392
393 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
394 PCMCIA_CIS_BILLIONTON_CFLT10N,
395 0, -1, { 0x00, 0x00, 0x00 } },
396
397 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
398 PCMCIA_CIS_NDC_ND5100_E,
399 0, -1, { 0x00, 0x80, 0xc6 } },
400
401 { PCMCIA_VENDOR_TELECOMDEVICE, PCMCIA_PRODUCT_TELECOMDEVICE_TCD_HPC100,
402 PCMCIA_CIS_INVALID,
403 0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
404
405 { PCMCIA_VENDOR_MACNICA, PCMCIA_PRODUCT_MACNICA_ME1_JEIDA,
406 PCMCIA_CIS_INVALID,
407 0, 0x00b8, { 0x08, 0x00, 0x42 } },
408
409 { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA411,
410 PCMCIA_CIS_INVALID,
411 0, -1, { 0x00, 0x40, 0xf4 } },
412
413 { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
414 PCMCIA_CIS_DYNALINK_L10C,
415 0, -1, { 0x00, 0x00, 0x00 } },
416
417 { PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM,
418 PCMCIA_CIS_INVALID,
419 0, 0x0ff0, { 0x00, 0x00, 0xf4 } },
420
421 { PCMCIA_VENDOR_NEXTCOM, PCMCIA_PRODUCT_NEXTCOM_NEXTHAWK,
422 PCMCIA_CIS_INVALID,
423 0, -1, { 0x00, 0x40, 0xb4 } },
424
425 #if 0
426 /* the rest of these are stolen from the linux pcnet pcmcia device
427 driver. Since I don't know the manfid or cis info strings for
428 any of them, they're not compiled in until I do. */
429 { "APEX MultiCard",
430 0x0000, 0x0000, NULL, NULL, 0,
431 0x03f4, { 0x00, 0x20, 0xe5 } },
432 { "ASANTE FriendlyNet",
433 0x0000, 0x0000, NULL, NULL, 0,
434 0x4910, { 0x00, 0x00, 0x94 } },
435 { "Danpex EN-6200P2",
436 0x0000, 0x0000, NULL, NULL, 0,
437 0x0110, { 0x00, 0x40, 0xc7 } },
438 { "DataTrek NetCard",
439 0x0000, 0x0000, NULL, NULL, 0,
440 0x0ff0, { 0x00, 0x20, 0xe8 } },
441 { "EP-210 Ethernet",
442 0x0000, 0x0000, NULL, NULL, 0,
443 0x0110, { 0x00, 0x40, 0x33 } },
444 { "ELECOM Laneed LD-CDWA",
445 0x0000, 0x0000, NULL, NULL, 0,
446 0x00b8, { 0x08, 0x00, 0x42 } },
447 { "Grey Cell GCS2220",
448 0x0000, 0x0000, NULL, NULL, 0,
449 0x0000, { 0x00, 0x47, 0x43 } },
450 { "Hypertec Ethernet",
451 0x0000, 0x0000, NULL, NULL, 0,
452 0x01c0, { 0x00, 0x40, 0x4c } },
453 { "IBM CCAE",
454 0x0000, 0x0000, NULL, NULL, 0,
455 0x0ff0, { 0x08, 0x00, 0x5a } },
456 { "IBM CCAE",
457 0x0000, 0x0000, NULL, NULL, 0,
458 0x0ff0, { 0x00, 0x04, 0xac } },
459 { "IBM CCAE",
460 0x0000, 0x0000, NULL, NULL, 0,
461 0x0ff0, { 0x00, 0x06, 0x29 } },
462 { "IBM FME",
463 0x0000, 0x0000, NULL, NULL, 0,
464 0x0374, { 0x00, 0x04, 0xac } },
465 { "IBM FME",
466 0x0000, 0x0000, NULL, NULL, 0,
467 0x0374, { 0x08, 0x00, 0x5a } },
468 { "Katron PE-520",
469 0x0000, 0x0000, NULL, NULL, 0,
470 0x0110, { 0x00, 0x40, 0xf6 } },
471 { "Kingston KNE-PCM/x",
472 0x0000, 0x0000, NULL, NULL, 0,
473 0x0ff0, { 0x00, 0xc0, 0xf0 } },
474 { "Kingston KNE-PCM/x",
475 0x0000, 0x0000, NULL, NULL, 0,
476 0x0ff0, { 0xe2, 0x0c, 0x0f } },
477 { "Longshine LCS-8534",
478 0x0000, 0x0000, NULL, NULL, 0,
479 0x0000, { 0x08, 0x00, 0x00 } },
480 { "Maxtech PCN2000",
481 0x0000, 0x0000, NULL, NULL, 0,
482 0x5000, { 0x00, 0x00, 0xe8 } },
483 { "NDC Instant-Link",
484 0x0000, 0x0000, NULL, NULL, 0,
485 0x003a, { 0x00, 0x80, 0xc6 } },
486 { "NE2000 Compatible",
487 0x0000, 0x0000, NULL, NULL, 0,
488 0x0ff0, { 0x00, 0xa0, 0x0c } },
489 { "Network General Sniffer",
490 0x0000, 0x0000, NULL, NULL, 0,
491 0x0ff0, { 0x00, 0x00, 0x65 } },
492 { "Panasonic VEL211",
493 0x0000, 0x0000, NULL, NULL, 0,
494 0x0ff0, { 0x00, 0x80, 0x45 } },
495 { "SCM Ethernet",
496 0x0000, 0x0000, NULL, NULL, 0,
497 0x0ff0, { 0x00, 0x20, 0xcb } },
498 { "Volktek NPL-402CT",
499 0x0000, 0x0000, NULL, NULL, 0,
500 0x0060, { 0x00, 0x40, 0x05 } },
501 #endif
502 };
503
504 #define NE2000_NDEVS (sizeof(ne2000devs) / sizeof(ne2000devs[0]))
505
506 #define ne2000_match(card, fct, n) \
507 ((((((card)->manufacturer != PCMCIA_VENDOR_INVALID) && \
508 ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
509 ((card)->product != PCMCIA_PRODUCT_INVALID) && \
510 ((card)->product == ne2000devs[(n)].product)) || \
511 ((ne2000devs[(n)].cis_info[0]) && (ne2000devs[(n)].cis_info[1]) && \
512 (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis_info[0]) == 0) && \
513 (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis_info[1]) == 0))) && \
514 ((fct) == ne2000devs[(n)].function))? \
515 &ne2000devs[(n)]:NULL)
516
517 int
518 ne_pcmcia_match(parent, match, aux)
519 struct device *parent;
520 struct cfdata *match;
521 void *aux;
522 {
523 struct pcmcia_attach_args *pa = aux;
524 int i;
525
526 for (i = 0; i < NE2000_NDEVS; i++) {
527 if (ne2000_match(pa->card, pa->pf->number, i))
528 return (1);
529 }
530
531 return (0);
532 }
533
534 void
535 ne_pcmcia_attach(parent, self, aux)
536 struct device *parent, *self;
537 void *aux;
538 {
539 struct ne_pcmcia_softc *psc = (void *) self;
540 struct ne2000_softc *nsc = &psc->sc_ne2000;
541 struct dp8390_softc *dsc = &nsc->sc_dp8390;
542 struct pcmcia_attach_args *pa = aux;
543 struct pcmcia_config_entry *cfe;
544 const struct ne2000dev *ne_dev;
545 int i;
546 u_int8_t myea[6], *enaddr;
547 const char *typestr = "";
548
549 psc->sc_pf = pa->pf;
550
551 SIMPLEQ_FOREACH(cfe, &pa->pf->cfe_head, cfe_list) {
552 #if 0
553 /*
554 * Some ne2000 driver's claim to have memory; others don't.
555 * Since I don't care, I don't check.
556 */
557
558 if (cfe->num_memspace != 1) {
559 printf(": unexpected number of memory spaces "
560 " %d should be 1\n", cfe->num_memspace);
561 continue;
562 }
563 #endif
564
565 if (cfe->num_iospace == 1) {
566 if (cfe->iospace[0].length != NE2000_NPORTS) {
567 printf(": unexpected I/O space configuration"
568 " (continued)\n%s", dsc->sc_dev.dv_xname);
569 /* XXX really safe for all other cards? */
570 }
571 } else if (cfe->num_iospace == 2) {
572 /*
573 * Some cards report a separate space for NIC and ASIC.
574 * This make some sense, but we must allocate a single
575 * NE2000_NPORTS-sized chunk, due to brain damaged
576 * address decoders on some of these cards.
577 */
578 if (cfe->iospace[0].length + cfe->iospace[1].length !=
579 NE2000_NPORTS) {
580 #ifdef DIAGNOSTIC
581 printf(": unexpected I/O "
582 "space configuration; ignored\n%s",
583 dsc->sc_dev.dv_xname);
584 #endif
585 continue;
586 }
587 } else {
588 #ifdef DIAGNOSTIC
589 printf(": unexpected number of i/o spaces %d"
590 " should be 1 or 2; ignored\n%s",
591 cfe->num_iospace, dsc->sc_dev.dv_xname);
592 #endif
593 continue;
594 }
595
596 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
597 NE2000_NPORTS, NE2000_NPORTS, &psc->sc_pcioh)) {
598 #ifdef DIAGNOSTIC
599 printf(": can't allocate i/o space %lx; ignored\n%s",
600 cfe->iospace[0].start, dsc->sc_dev.dv_xname);
601 #endif
602 continue;
603 }
604
605 /* Ok, found. */
606 break;
607 }
608
609 if (cfe == NULL) {
610 printf(": no suitable config entry\n");
611 goto fail_1;
612 }
613
614 dsc->sc_regt = psc->sc_pcioh.iot;
615 dsc->sc_regh = psc->sc_pcioh.ioh;
616
617 nsc->sc_asict = psc->sc_pcioh.iot;
618 if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
619 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
620 &nsc->sc_asich)) {
621 printf(": can't get subregion for asic\n");
622 goto fail_2;
623 }
624
625 /* Set up power management hooks. */
626 dsc->sc_enable = ne_pcmcia_enable;
627 dsc->sc_disable = ne_pcmcia_disable;
628
629 /* Enable the card. */
630 pcmcia_function_init(pa->pf, cfe);
631 if (pcmcia_function_enable(pa->pf)) {
632 printf(": function enable failed\n");
633 goto fail_2;
634 }
635
636 /* some cards claim to be io16, but they're lying. */
637 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8,
638 NE2000_NIC_OFFSET, NE2000_NIC_NPORTS,
639 &psc->sc_pcioh, &psc->sc_nic_io_window)) {
640 printf(": can't map NIC i/o space\n");
641 goto fail_3;
642 }
643
644 if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16,
645 NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS,
646 &psc->sc_pcioh, &psc->sc_asic_io_window)) {
647 printf(": can't map ASIC i/o space\n");
648 goto fail_4;
649 }
650
651 aprint_normal("\n");
652
653 /*
654 * Read the station address from the board.
655 */
656 i = 0;
657 again:
658 enaddr = NULL; /* Ask ASIC by default */
659 typestr = ""; /* clear previous card-type */
660 for (; i < NE2000_NDEVS; i++) {
661 ne_dev = ne2000_match(pa->card, pa->pf->number, i);
662 if (ne_dev != NULL) {
663 if (ne_dev->enet_maddr >= 0) {
664 enaddr = ne_pcmcia_get_enaddr(psc,
665 ne_dev->enet_maddr, myea);
666 if (enaddr == NULL)
667 continue;
668 }
669 goto found;
670 }
671 }
672 aprint_error("%s: can't match ethernet vendor code\n", self->dv_xname);
673 if (enaddr != NULL)
674 aprint_error("%s: ethernet vendor code %02x:%02x:%02x\n",
675 self->dv_xname, enaddr[0], enaddr[1], enaddr[2]);
676 goto fail_5;
677
678 found:
679 if ((ne_dev->flags & NE2000DVF_DL10019) != 0) {
680 u_int8_t type;
681
682 enaddr = ne_pcmcia_dl10019_get_enaddr(psc, myea);
683 if (enaddr == NULL) {
684 ++i;
685 goto again;
686 }
687
688 dsc->sc_mediachange = dl10019_mediachange;
689 dsc->sc_mediastatus = dl10019_mediastatus;
690 dsc->init_card = dl10019_init_card;
691 dsc->stop_card = dl10019_stop_card;
692 dsc->sc_media_init = dl10019_media_init;
693 dsc->sc_media_fini = dl10019_media_fini;
694
695 /* Determine if this is a DL10019 or a DL10022. */
696 type = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x0f);
697 if (type == 0x91 || type == 0x99) {
698 nsc->sc_type = NE2000_TYPE_DL10022;
699 typestr = " (DL10022)";
700 } else {
701 nsc->sc_type = NE2000_TYPE_DL10019;
702 typestr = " (DL10019)";
703 }
704 }
705
706 if ((ne_dev->flags & NE2000DVF_AX88190) != 0) {
707 u_int8_t test;
708
709 if (ne_pcmcia_ax88190_set_iobase(psc)) {
710 ++i;
711 goto again;
712 }
713
714 dsc->sc_mediachange = ax88190_mediachange;
715 dsc->sc_mediastatus = ax88190_mediastatus;
716 dsc->init_card = ax88190_init_card;
717 dsc->stop_card = ax88190_stop_card;
718 dsc->sc_media_init = ax88190_media_init;
719 dsc->sc_media_fini = ax88190_media_fini;
720
721 test = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x05);
722 if (test != 0) {
723 nsc->sc_type = NE2000_TYPE_AX88790;
724 typestr = " (AX88790)";
725 } else {
726 nsc->sc_type = NE2000_TYPE_AX88190;
727 typestr = " (AX88190)";
728 }
729 }
730
731 if (enaddr != NULL &&
732 ne_dev->enet_vendor[0] != 0xff) {
733 /*
734 * Make sure this is what we expect.
735 */
736 if (enaddr[0] != ne_dev->enet_vendor[0] ||
737 enaddr[1] != ne_dev->enet_vendor[1] ||
738 enaddr[2] != ne_dev->enet_vendor[2]) {
739 ++i;
740 goto again;
741 }
742 }
743
744 /*
745 * Check for a Realtek 8019.
746 */
747 if (nsc->sc_type == 0) {
748 bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR,
749 ED_CR_PAGE_0 | ED_CR_STP);
750 if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
751 NERTL_RTL0_8019ID0) == RTL0_8019ID0 &&
752 bus_space_read_1(dsc->sc_regt, dsc->sc_regh,
753 NERTL_RTL0_8019ID1) == RTL0_8019ID1) {
754 typestr = " (RTL8019)";
755 dsc->sc_mediachange = rtl80x9_mediachange;
756 dsc->sc_mediastatus = rtl80x9_mediastatus;
757 dsc->init_card = rtl80x9_init_card;
758 dsc->sc_media_init = rtl80x9_media_init;
759 }
760 }
761
762 if (ne2000_attach(nsc, enaddr))
763 goto fail_5;
764
765 pcmcia_function_disable(pa->pf);
766 return;
767
768 fail_5:
769 /* Unmap ASIC i/o windows. */
770 pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
771
772 fail_4:
773 /* Unmap NIC i/o windows. */
774 pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
775
776 fail_3:
777 pcmcia_function_disable(pa->pf);
778
779 fail_2:
780 /* Free our i/o space. */
781 pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
782
783 fail_1:
784 psc->sc_nic_io_window = -1;
785 }
786
787 int
788 ne_pcmcia_detach(self, flags)
789 struct device *self;
790 int flags;
791 {
792 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)self;
793 int error;
794
795 if (psc->sc_nic_io_window == -1)
796 /* Nothing to detach. */
797 return (0);
798
799 error = ne2000_detach(&psc->sc_ne2000, flags);
800 if (error != 0)
801 return (error);
802
803 /* Unmap our i/o windows. */
804 pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
805 pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
806
807 /* Free our i/o space. */
808 pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
809
810 return (0);
811 }
812
813 int
814 ne_pcmcia_enable(dsc)
815 struct dp8390_softc *dsc;
816 {
817 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
818 struct ne2000_softc *nsc = &psc->sc_ne2000;
819 struct pcmcia_mem_handle pcmh;
820
821 /* set up the interrupt */
822 psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
823 dsc);
824 if (psc->sc_ih == NULL) {
825 printf("%s: couldn't establish interrupt\n",
826 dsc->sc_dev.dv_xname);
827 goto fail_1;
828 }
829
830 if (pcmcia_function_enable(psc->sc_pf))
831 goto fail_2;
832
833 if (nsc->sc_type == NE2000_TYPE_AX88190 ||
834 nsc->sc_type == NE2000_TYPE_AX88790) {
835 if (ne_pcmcia_ax88190_set_iobase(psc))
836 goto fail_3;
837 if (nsc->sc_type == NE2000_TYPE_AX88790) {
838 bus_size_t offset;
839 int mwindow;
840
841 if (pcmcia_mem_alloc(psc->sc_pf,
842 AX88790_CSR_SIZE, &pcmh)) {
843 printf("%s: can't alloc mem for CSR\n",
844 dsc->sc_dev.dv_xname);
845 goto fail_3;
846 }
847
848 if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
849 AX88790_CSR, AX88790_CSR_SIZE,
850 &pcmh, &offset, &mwindow)) {
851 printf("%s: can't map mem for CSR\n",
852 dsc->sc_dev.dv_xname);
853 goto fail_4;
854 }
855
856 bus_space_write_1(pcmh.memt, pcmh.memh, offset, 0x4);
857 pcmcia_mem_unmap(psc->sc_pf, mwindow);
858 pcmcia_mem_free(psc->sc_pf, &pcmh);
859 }
860 }
861
862 return (0);
863
864 fail_4:
865 pcmcia_mem_free(psc->sc_pf, &pcmh);
866 fail_3:
867 pcmcia_function_disable(psc->sc_pf);
868 fail_2:
869 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
870 fail_1:
871 return (1);
872 }
873
874 void
875 ne_pcmcia_disable(dsc)
876 struct dp8390_softc *dsc;
877 {
878 struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
879
880 pcmcia_function_disable(psc->sc_pf);
881 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
882 }
883
884 u_int8_t *
885 ne_pcmcia_get_enaddr(psc, maddr, myea)
886 struct ne_pcmcia_softc *psc;
887 int maddr;
888 u_int8_t myea[ETHER_ADDR_LEN];
889 {
890 struct ne2000_softc *nsc = &psc->sc_ne2000;
891 struct dp8390_softc *dsc = &nsc->sc_dp8390;
892 struct pcmcia_mem_handle pcmh;
893 bus_size_t offset;
894 u_int8_t *enaddr = NULL;
895 int j, mwindow;
896
897 if (maddr < 0)
898 return (NULL);
899
900 if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
901 printf("%s: can't alloc mem for enet addr\n",
902 dsc->sc_dev.dv_xname);
903 goto fail_1;
904 }
905 if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr,
906 ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
907 printf("%s: can't map mem for enet addr\n",
908 dsc->sc_dev.dv_xname);
909 goto fail_2;
910 }
911 for (j = 0; j < ETHER_ADDR_LEN; j++)
912 myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh,
913 offset + (j * 2));
914 enaddr = myea;
915
916 pcmcia_mem_unmap(psc->sc_pf, mwindow);
917 fail_2:
918 pcmcia_mem_free(psc->sc_pf, &pcmh);
919 fail_1:
920 return (enaddr);
921 }
922
923 u_int8_t *
924 ne_pcmcia_dl10019_get_enaddr(psc, myea)
925 struct ne_pcmcia_softc *psc;
926 u_int8_t myea[ETHER_ADDR_LEN];
927 {
928 struct ne2000_softc *nsc = &psc->sc_ne2000;
929 u_int8_t sum;
930 int j;
931
932 #define PAR0 0x04
933 for (j = 0, sum = 0; j < 8; j++)
934 sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich,
935 PAR0 + j);
936 if (sum != 0xff)
937 return (NULL);
938 for (j = 0; j < ETHER_ADDR_LEN; j++)
939 myea[j] = bus_space_read_1(nsc->sc_asict,
940 nsc->sc_asich, PAR0 + j);
941 #undef PAR0
942 return (myea);
943 }
944
945 int
946 ne_pcmcia_ax88190_set_iobase(psc)
947 struct ne_pcmcia_softc *psc;
948 {
949 struct ne2000_softc *nsc = &psc->sc_ne2000;
950 struct dp8390_softc *dsc = &nsc->sc_dp8390;
951 struct pcmcia_mem_handle pcmh;
952 bus_size_t offset;
953 int rv = 1, mwindow;
954 u_int last_liobase, new_liobase;
955
956 if (pcmcia_mem_alloc(psc->sc_pf, AX88190_LAN_IOSIZE, &pcmh)) {
957 #if 0
958 printf("%s: can't alloc mem for LAN iobase\n",
959 dsc->sc_dev.dv_xname);
960 #endif
961 goto fail_1;
962 }
963 if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
964 AX88190_LAN_IOBASE, AX88190_LAN_IOSIZE,
965 &pcmh, &offset, &mwindow)) {
966 printf("%s: can't map mem for LAN iobase\n",
967 dsc->sc_dev.dv_xname);
968 goto fail_2;
969 }
970
971 last_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
972 (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
973 #ifdef DIAGNOSTIC
974 printf("%s: LAN iobase 0x%x (0x%x) ->", dsc->sc_dev.dv_xname,
975 last_liobase, (u_int)psc->sc_pcioh.addr);
976 #endif
977 bus_space_write_1(pcmh.memt, pcmh.memh, offset,
978 psc->sc_pcioh.addr & 0xff);
979 bus_space_write_1(pcmh.memt, pcmh.memh, offset + 2,
980 psc->sc_pcioh.addr >> 8);
981
982 new_liobase = bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
983 (bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
984 #ifdef DIAGNOSTIC
985 printf(" 0x%x\n", new_liobase);
986 #endif
987 if ((last_liobase == psc->sc_pcioh.addr)
988 || (last_liobase != new_liobase))
989 rv = 0;
990
991 pcmcia_mem_unmap(psc->sc_pf, mwindow);
992 fail_2:
993 pcmcia_mem_free(psc->sc_pf, &pcmh);
994 fail_1:
995 return (rv);
996 }
997