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