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