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