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