xref: /openbsd/sys/dev/pcmcia/if_ne_pcmcia.c (revision 8b4b0e59)
1 /*	$OpenBSD: if_ne_pcmcia.c,v 1.103 2024/05/26 08:46:28 jsg Exp $	*/
2 /*	$NetBSD: if_ne_pcmcia.c,v 1.17 1998/08/15 19:00:04 thorpej Exp $	*/
3 
4 /*
5  * Copyright (c) 1997 Marc Horowitz.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  * 3. All advertising materials mentioning features or use of this software
16  *    must display the following acknowledgement:
17  *	This product includes software developed by Marc Horowitz.
18  * 4. The name of the author may not be used to endorse or promote products
19  *    derived from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32 
33 #include <sys/param.h>
34 #include <sys/systm.h>
35 #include <sys/device.h>
36 
37 #include <net/if.h>
38 #include <net/if_media.h>
39 #include <netinet/in.h>
40 #include <netinet/if_ether.h>
41 
42 #include <machine/bus.h>
43 
44 #include <dev/pcmcia/pcmciavar.h>
45 #include <dev/pcmcia/pcmciadevs.h>
46 
47 #include <dev/mii/miivar.h>
48 
49 #include <dev/ic/dp8390reg.h>
50 #include <dev/ic/dp8390var.h>
51 
52 #include <dev/ic/ne2000reg.h>
53 #include <dev/ic/ne2000var.h>
54 
55 #include <dev/ic/dl10019var.h>
56 
57 #include <dev/ic/rtl80x9reg.h>
58 #include <dev/ic/rtl80x9var.h>
59 
60 #include <dev/ic/ax88190reg.h>
61 #include <dev/ic/ax88190var.h>
62 
63 int	ne_pcmcia_match(struct device *, void *, void *);
64 void	ne_pcmcia_attach(struct device *, struct device *, void *);
65 int	ne_pcmcia_detach(struct device *, int);
66 int	ne_pcmcia_activate(struct device *, int);
67 
68 int	ne_pcmcia_enable(struct dp8390_softc *);
69 void	ne_pcmcia_disable(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(struct ne_pcmcia_softc *, int,
84 	    u_int8_t[ETHER_ADDR_LEN]);
85 u_int8_t *
86 	ne_pcmcia_dl10019_get_enaddr(struct ne_pcmcia_softc *,
87 	    u_int8_t[ETHER_ADDR_LEN]);
88 int	ne_pcmcia_ax88190_set_iobase(struct ne_pcmcia_softc *);
89 
90 const struct cfattach ne_pcmcia_ca = {
91 	sizeof(struct ne_pcmcia_softc), ne_pcmcia_match, ne_pcmcia_attach,
92 	ne_pcmcia_detach, ne_pcmcia_activate
93 };
94 
95 const struct ne2000dev {
96     u_int16_t manufacturer;
97     u_int16_t product;
98     char *cis_info[4];
99     int function;
100     int enet_maddr;
101     unsigned char enet_vendor[3];
102     int flags;
103 #define NE2000DVF_AX88190	0x0002	/* chip is ASIX AX88190 */
104 } ne2000devs[] = {
105     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
106       PCMCIA_CIS_AMBICOM_AMB8002T,
107       0, -1, { 0x00, 0x10, 0x7a } },
108 
109     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
110       PCMCIA_CIS_PREMAX_PE200,
111       0, 0x07f0, { 0x00, 0x20, 0xe0 } },
112 
113     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
114       PCMCIA_CIS_DIGITAL_DEPCMXX,
115       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
116 
117     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
118       PCMCIA_CIS_PLANET_SMARTCOM2000,
119       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
120 
121     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
122       PCMCIA_CIS_DLINK_DE660,
123       0, -1, { 0x00, 0x80, 0xc8 } },
124 
125     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
126       PCMCIA_CIS_DLINK_DE660PLUS,
127       0, -1, { 0x00, 0x80, 0xc8 } },
128 
129     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
130       PCMCIA_CIS_RPTI_EP400,
131       0, -1, { 0x00, 0x40, 0x95 } },
132 
133     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
134       PCMCIA_CIS_RPTI_EP401,
135       0, -1, { 0x00, 0x40, 0x95 } },
136 
137     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
138       PCMCIA_CIS_ACCTON_EN2212,
139       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
140 
141     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
142       PCMCIA_CIS_ADDTRON_W89C926,
143       0, -1, { 0x00, 0x40, 0x33 } },
144 
145     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
146       PCMCIA_CIS_SVEC_COMBOCARD,
147       0, -1, { 0x00, 0xe0, 0x98 } },
148 
149     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
150       PCMCIA_CIS_SVEC_LANCARD,
151       0, 0x07f0, { 0x00, 0xc0, 0x6c } },
152 
153     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_EPSON_EEN10B,
154       PCMCIA_CIS_EPSON_EEN10B,
155       0, 0x0ff0, { 0x00, 0x00, 0x48 } },
156 
157     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
158       PCMCIA_CIS_EDIMAX_NE2000,
159       0, -1, { 0x00, 0x00, 0xb4 } },
160 
161     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
162       PCMCIA_CIS_CNET_NE2000,
163       0, -1, { 0x00, 0x80, 0xad } },
164 
165     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_CNET_CNF301,
166       PCMCIA_CIS_CNET_CNF301,
167       0, -1, { 0x00, 0x10, 0x60 } },
168 
169     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
170       PCMCIA_CIS_BILLIONTON_LNT10TN,
171       0, -1, { 0x00, 0x00, 0x00 } },
172 
173     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
174       PCMCIA_CIS_NDC_ND5100_E,
175       0, -1, { 0x00, 0x80, 0xc6 } },
176 
177     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
178       PCMCIA_CIS_SYNERGY21_S21810,
179       0, -1, { 0x00, 0x48, 0x54 } },
180 
181     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
182       PCMCIA_CIS_TAMARACK_NE2000,
183       0, -1, { 0x00, 0x47, 0x43 } },
184 
185     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
186       PCMCIA_CIS_GVC_NIC2000P,
187       0, 0x0ff0, { 0x00, 0x00, 0xe8 } },
188 
189     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
190       PCMCIA_CIS_WISECOM_T210CT,
191       0, -1, { 0x00, 0x20, 0x18 } },
192 
193     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
194       PCMCIA_CIS_WISECOM_IPORT,
195       0, -1, { 0x00, 0x02, 0xdd } },
196 
197     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
198       PCMCIA_CIS_AROWANA_FE,
199       0, -1, { 0x00, 0x48, 0x54 }, NE2000DVF_AX88190 },
200 
201     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
202       PCMCIA_CIS_GVC_NP0335,
203       0, -1, { 0x00, 0x40, 0x05 } },
204 
205     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
206       PCMCIA_CIS_RELIA_RE2408T,
207       0, -1, { 0x00, 0xc0, 0x0c } },
208 
209     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
210       PCMCIA_CIS_BILLIONTON_CFLT2,
211       0, -1, { 0x00, 0x10, 0x60 } },
212 
213     /*
214      * You have to add new entries which contains
215      * PCMCIA_VENDOR_INVALID and/or PCMCIA_PRODUCT_INVALID
216      * in front of this comment.
217      *
218      * There are cards which use a generic vendor and product id but needs
219      * a different handling depending on the cis_info, so ne2000_match
220      * needs a table where the exceptions comes first and then the normal
221      * product and vendor entries.
222      */
223 
224     { PCMCIA_VENDOR_GREYCELL, PCMCIA_PRODUCT_GREYCELL_GCS2000,
225       PCMCIA_CIS_GREYCELL_GCS2000,
226       0, -1, { 0x00, 0x47, 0x43 } },
227 
228     { PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
229       PCMCIA_CIS_IBM_INFOMOVER,
230       0, 0x0ff0, { 0x08, 0x00, 0x5a } },
231 
232     { PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
233       PCMCIA_CIS_IBM_INFOMOVER,
234       0, 0x0ff0, { 0x00, 0x04, 0xac } },
235 
236     { PCMCIA_VENDOR_IBM, PCMCIA_PRODUCT_IBM_INFOMOVER,
237       PCMCIA_CIS_IBM_INFOMOVER,
238       0, 0x0ff0, { 0x00, 0x06, 0x29 } },
239 
240     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ECARD_1,
241       PCMCIA_CIS_LINKSYS_ECARD_1,
242       0, -1, { 0x00, 0x80, 0xc8 } },
243 
244     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_PCM100,
245       PCMCIA_CIS_LINKSYS_PCM100,
246       0, -1, { 0x00, 0x04, 0x5a } },
247 
248     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
249       PCMCIA_CIS_LINKSYS_COMBO_ECARD,
250       0, -1, { 0x00, 0x04, 0x5a }, NE2000DVF_AX88190 },
251 
252     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
253       PCMCIA_CIS_LINKSYS_COMBO_ECARD,
254       0, -1, { 0x00, 0x80, 0xc8 } },
255 
256     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
257       PCMCIA_CIS_PLANEX_FNW3600T,
258       0, -1, { 0x00, 0x90, 0xcc } },
259 
260     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
261       PCMCIA_CIS_SVEC_PN650TX,
262       0, -1, { 0x00, 0xe0, 0x98 } },
263 
264     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
265       PCMCIA_CIS_TRENDNET_TECF100,
266       0, -1, { 0x00, 0x12, 0x0e } },
267 
268     /*
269      * This entry should be here so that above two cards doesn't
270      * match with this.  FNW-3700T won't match above entries due to
271      * MAC address check.
272      */
273     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_COMBO_ECARD,
274       PCMCIA_CIS_PLANEX_FNW3700T,
275       0, -1, { 0x00, 0x90, 0xcc }, NE2000DVF_AX88190 },
276 
277     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
278       PCMCIA_CIS_LINKSYS_ETHERFAST,
279       0, -1, { 0x00, 0x80, 0xc8 } },
280 
281     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
282       PCMCIA_CIS_LINKSYS_ETHERFAST,
283       0, -1, { 0x00, 0x50, 0xba } },
284 
285     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
286       PCMCIA_CIS_DLINK_DE650,
287       0, -1, { 0x00, 0xe0, 0x98 } },
288 
289     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_ETHERFAST,
290       PCMCIA_CIS_IODATA_PCETTXR,
291       0, -1, { 0x00, 0xa0, 0xb0 } },
292 
293     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
294       PCMCIA_CIS_DLINK_DFE670TXD,
295       0, -1, { 0x00, 0x05, 0x5d } },
296 
297     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
298       PCMCIA_CIS_DLINK_DFE670TXD,
299       0, -1, { 0x00, 0x50, 0xba } },
300 
301      { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
302        PCMCIA_CIS_DLINK_DFE670TXD,
303        0, -1, { 0x00, 0x0d, 0x88 } },
304 
305     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
306       PCMCIA_CIS_DLINK_DFE670TXD,
307       0, -1, { 0x00, 0x13, 0x46 } },
308 
309     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
310       PCMCIA_CIS_DLINK_DFE670TXD,
311       0, -1, { 0x00, 0x40, 0x05 } },
312 
313     { PCMCIA_VENDOR_LINKSYS, PCMCIA_PRODUCT_LINKSYS_TRUST_COMBO_ECARD,
314       PCMCIA_CIS_LINKSYS_TRUST_COMBO_ECARD,
315       0, 0x0120, { 0x20, 0x04, 0x49 } },
316 
317     /* Although the comments above say to put VENDOR/PRODUCT INVALID IDs
318        above this list, we need to keep this one below the ECARD_1, or else
319        both will match the same more-generic entry rather than the more
320        specific one above with proper vendor and product IDs. */
321     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
322       PCMCIA_CIS_LINKSYS_ECARD_2,
323       0, -1, { 0x00, 0x80, 0xc8 } },
324 
325     /*
326      * D-Link DE-650 has many minor versions:
327      *
328      *   CIS information          Manufacturer Product  Note
329      * 1 "D-Link, DE-650"             INVALID  INVALID  white card
330      * 2 "D-Link, DE-650, Ver 01.00"  INVALID  INVALID  became bare metal
331      * 3 "D-Link, DE-650, Ver 01.00"   0x149    0x265   minor change in look
332      * 4 "D-Link, DE-650, Ver 01.00"   0x149    0x265   collision LED added
333      *
334      * While the 1st and the 2nd types should use the "D-Link DE-650" entry,
335      * the 3rd and the 4th types should use the "Linksys EtherCard" entry.
336      * Therefore, this entry must be below the LINKSYS_ECARD_1.  --itohy
337      */
338     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
339       PCMCIA_CIS_DLINK_DE650,
340       0, 0x0040, { 0x00, 0x80, 0xc8 } },
341 
342     /*
343      * IO-DATA PCLA/TE and later version of PCLA/T has valid
344      * vendor/product ID and it is possible to read MAC address
345      * using standard I/O ports.  It also read from CIS offset 0x01c0.
346      * On the other hand, earlier version of PCLA/T doesn't have valid
347      * vendor/product ID and MAC address must be read from CIS offset
348      * 0x0ff0 (i.e., usual ne2000 way to read it doesn't work).
349      * And CIS information of earlier and later version of PCLA/T are
350      * same except fourth element.  So, for now, we place the entry for
351      * PCLA/TE (and later version of PCLA/T) followed by entry
352      * for the earlier version of PCLA/T (or, modify to match all CIS
353      * information and have three or more individual entries).
354      */
355     { PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_PCLATE,
356       PCMCIA_CIS_IODATA_PCLATE,
357       0, -1, { 0x00, 0xa0, 0xb0 } },
358 
359     /*
360      * This entry should be placed after above PCLA-TE entry.
361      * See above comments for detail.
362      */
363     { PCMCIA_VENDOR_INVALID, PCMCIA_PRODUCT_INVALID,
364       PCMCIA_CIS_IODATA_PCLAT,
365       0, 0x0ff0, { 0x00, 0xa0, 0xb0 } },
366 
367     { PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_1,
368       PCMCIA_CIS_DAYNA_COMMUNICARD_E_1,
369       0, 0x0110, { 0x00, 0x80, 0x19 } },
370 
371     { PCMCIA_VENDOR_DAYNA, PCMCIA_PRODUCT_DAYNA_COMMUNICARD_E_2,
372       PCMCIA_CIS_DAYNA_COMMUNICARD_E_2,
373       0, -1, { 0x00, 0x80, 0x19 } },
374 
375     { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_T,
376       PCMCIA_CIS_COREGA_ETHER_PCC_T,
377       0, -1, { 0x00, 0x00, 0xf4 } },
378 
379     { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_PCC_TD,
380       PCMCIA_CIS_COREGA_ETHER_PCC_TD,
381       0, -1, { 0x00, 0x00, 0xf4 } },
382 
383     { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_T,
384       PCMCIA_CIS_COREGA_ETHER_II_PCC_T,
385       0, -1, { 0x00, 0x00, 0xf4 } },
386 
387     { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_ETHER_II_PCC_TD,
388       PCMCIA_CIS_COREGA_ETHER_II_PCC_TD,
389       0, -1, { 0x00, 0x00, 0xf4 } },
390 
391     { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FAST_ETHER_PCC_TX,
392       PCMCIA_CIS_COREGA_FAST_ETHER_PCC_TX,
393       0, -1, { 0x00, 0x00, 0xf4 } },
394 
395     { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXF,
396       PCMCIA_CIS_COREGA_FETHER_PCC_TXF,
397       0, -1, { 0x00, 0x90, 0x99 } },
398 
399     { PCMCIA_VENDOR_COREGA, PCMCIA_PRODUCT_COREGA_FETHER_PCC_TXD,
400       PCMCIA_CIS_COREGA_FETHER_PCC_TXD,
401       0, -1, { 0x00, 0x90, 0x99 } },
402 
403     { PCMCIA_VENDOR_COMPEX, PCMCIA_PRODUCT_COMPEX_LINKPORT_ENET_B,
404       PCMCIA_CIS_COMPEX_LINKPORT_ENET_B,
405       0, 0x01c0, { 0x00, 0xa0, 0x0c } },
406 
407     { PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_EZCARD,
408       PCMCIA_CIS_SMC_EZCARD,
409       0, 0x01c0, { 0x00, 0xe0, 0x29 } },
410 
411     { PCMCIA_VENDOR_IODATA, PCMCIA_PRODUCT_IODATA_8041TX,
412       PCMCIA_CIS_IODATA_8041TX,
413       0, -1, { 0x00, 0x04, 0xe2 } },
414 
415     { PCMCIA_VENDOR_SMC, PCMCIA_PRODUCT_SMC_8041,
416       PCMCIA_CIS_SMC_8041,
417       0, -1, { 0x00, 0x04, 0xe2 } },
418 
419     { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER_CF,
420       PCMCIA_CIS_SOCKET_LP_ETHER_CF,
421       0, -1, { 0x00, 0xc0, 0x1b} },
422 
423     { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_LP_ETHER,
424       PCMCIA_CIS_SOCKET_LP_ETHER,
425       0, -1, { 0x00, 0xc0, 0x1b } },
426 
427     { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_ETHER_CF_10_100,
428       PCMCIA_CIS_SOCKET_ETHER_CF_10_100,
429       0, -1, { 0x00, 0x12, 0x0e } },
430 
431     { PCMCIA_VENDOR_SOCKET, PCMCIA_PRODUCT_SOCKET_ETHER_CF_10_100,
432       PCMCIA_CIS_SOCKET_ETHER_CF_10_100,
433       0, -1, { 0x00, 0xe0, 0x98 } },
434 
435     { PCMCIA_VENDOR_XIRCOM, PCMCIA_PRODUCT_XIRCOM_CFE_10,
436       PCMCIA_CIS_XIRCOM_CFE_10,
437       0, -1, { 0x00, 0x10, 0xa4 } },
438 
439     { PCMCIA_VENDOR_MELCO, PCMCIA_PRODUCT_MELCO_LPC3_TX,
440       PCMCIA_CIS_MELCO_LPC3_TX,
441       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
442 
443     { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC_CF_CLT,
444       PCMCIA_CIS_INVALID,
445       0, -1, { 0x00, 0x07, 0x40 } },
446 
447     { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC3_CLT,
448       PCMCIA_CIS_INVALID,
449       0, -1, { 0x00, 0x07, 0x40 } },
450 
451     { PCMCIA_VENDOR_BUFFALO, PCMCIA_PRODUCT_BUFFALO_LPC4_CLX,
452       PCMCIA_CIS_INVALID,
453       0, -1, { 0x00, 0x40, 0xfa }, NE2000DVF_AX88190 },
454 
455     { PCMCIA_VENDOR_DUAL, PCMCIA_PRODUCT_DUAL_NE2000,
456       PCMCIA_CIS_DUAL_NE2000,
457       0, 0x0ff0, { 0x00, 0xa0, 0x0c } },
458 
459     { PCMCIA_VENDOR_ALLIEDTELESIS, PCMCIA_PRODUCT_ALLIEDTELESIS_LA_PCM,
460       PCMCIA_CIS_ALLIEDTELESIS_LA_PCM,
461       0, 0x0ff0, { 0x00, 0x00, 0xf4 } },
462 
463     { PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE_PCM,
464       PCMCIA_CIS_KINGSTON_KNE_PCM,
465       0, 0x0ff0, { 0xe2, 0x0c, 0x0f } },
466 
467     { PCMCIA_VENDOR_KINGSTON, PCMCIA_PRODUCT_KINGSTON_KNE_PC2,
468       PCMCIA_CIS_KINGSTON_KNE_PC2,
469       0, 0x0180, { 0x00, 0xc0, 0xf0 } },
470 
471     { PCMCIA_VENDOR_TELECOMDEVICE, PCMCIA_PRODUCT_TELECOMDEVICE_TCD_HPC100,
472       PCMCIA_CIS_TELECOMDEVICE_TCD_HPC100,
473       0, -1, { 0x00, 0x40, 0x26 }, NE2000DVF_AX88190 },
474 
475     { PCMCIA_VENDOR_MACNICA, PCMCIA_PRODUCT_MACNICA_ME1_JEIDA,
476       PCMCIA_CIS_MACNICA_ME1_JEIDA,
477       0, 0x00b8, { 0x08, 0x00, 0x42 } },
478 
479     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
480       PCMCIA_CIS_NETGEAR_FA410TXC,
481       0, -1, { 0x00, 0x40, 0xf4 } },
482 
483     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
484       PCMCIA_CIS_NETGEAR_FA410TXC,
485       0, -1, { 0x00, 0x48, 0x54 } },
486 
487     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
488       PCMCIA_CIS_DLINK_DFE670TXD,
489       0, -1, { 0x00, 0x40, 0x05 } },
490 
491     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
492       PCMCIA_CIS_DLINK_DFE670TXD,
493       0, -1, { 0x00, 0x11, 0x95 } },
494 
495      { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA410TXC,
496        PCMCIA_CIS_DLINK_DFE670TXD,
497        0, -1, { 0x00, 0x0d, 0x88 } },
498 
499     { PCMCIA_VENDOR_NETGEAR, PCMCIA_PRODUCT_NETGEAR_FA411,
500       PCMCIA_CIS_NETGEAR_FA411,
501       0, -1, { 0x00, 0x40, 0xf4 } },
502 
503     { PCMCIA_VENDOR_BELKIN, PCMCIA_PRODUCT_BELKIN_F5D5020,
504       PCMCIA_CIS_BELKIN_F5D5020,
505       0, -1, { 0x00, 0x30, 0xbd } },
506 
507 #if 0
508     /* the rest of these are stolen from the linux pcnet pcmcia device
509        driver.  Since I don't know the manfid or cis info strings for
510        any of them, they're not compiled in until I do. */
511     { "APEX MultiCard",
512       0x0000, 0x0000, NULL, NULL, 0,
513       0x03f4, { 0x00, 0x20, 0xe5 } },
514     { "ASANTE FriendlyNet",
515       0x0000, 0x0000, NULL, NULL, 0,
516       0x4910, { 0x00, 0x00, 0x94 } },
517     { "Danpex EN-6200P2",
518       0x0000, 0x0000, NULL, NULL, 0,
519       0x0110, { 0x00, 0x40, 0xc7 } },
520     { "DataTrek NetCard",
521       0x0000, 0x0000, NULL, NULL, 0,
522       0x0ff0, { 0x00, 0x20, 0xe8 } },
523     { "EP-210 Ethernet",
524       0x0000, 0x0000, NULL, NULL, 0,
525       0x0110, { 0x00, 0x40, 0x33 } },
526     { "ELECOM Laneed LD-CDWA",
527       0x0000, 0x0000, NULL, NULL, 0,
528       0x00b8, { 0x08, 0x00, 0x42 } },
529     { "Grey Cell GCS2220",
530       0x0000, 0x0000, NULL, NULL, 0,
531       0x0000, { 0x00, 0x47, 0x43 } },
532     { "Hypertec Ethernet",
533       0x0000, 0x0000, NULL, NULL, 0,
534       0x01c0, { 0x00, 0x40, 0x4c } },
535     { "IBM FME",
536       0x0000, 0x0000, NULL, NULL, 0,
537       0x0374, { 0x00, 0x04, 0xac } },
538     { "IBM FME",
539       0x0000, 0x0000, NULL, NULL, 0,
540       0x0374, { 0x08, 0x00, 0x5a } },
541     { "Katron PE-520",
542       0x0000, 0x0000, NULL, NULL, 0,
543       0x0110, { 0x00, 0x40, 0xf6 } },
544     { "Kingston KNE-PCM/x",
545       0x0000, 0x0000, NULL, NULL, 0,
546       0x0ff0, { 0x00, 0xc0, 0xf0 } },
547     { "Longshine LCS-8534",
548       0x0000, 0x0000, NULL, NULL, 0,
549       0x0000, { 0x08, 0x00, 0x00 } },
550     { "Maxtech PCN2000",
551       0x0000, 0x0000, NULL, NULL, 0,
552       0x5000, { 0x00, 0x00, 0xe8 } },
553     { "NDC Instant-Link",
554       0x0000, 0x0000, NULL, NULL, 0,
555       0x003a, { 0x00, 0x80, 0xc6 } },
556     { "Network General Sniffer",
557       0x0000, 0x0000, NULL, NULL, 0,
558       0x0ff0, { 0x00, 0x00, 0x65 } },
559     { "Panasonic VEL211",
560       0x0000, 0x0000, NULL, NULL, 0,
561       0x0ff0, { 0x00, 0x80, 0x45 } },
562     { "SCM Ethernet",
563       0x0000, 0x0000, NULL, NULL, 0,
564       0x0ff0, { 0x00, 0x20, 0xcb } },
565     { "Socket EA",
566       0x0000, 0x0000, NULL, NULL, 0,
567       0x4000, { 0x00, 0xc0, 0x1b } },
568     { "Volktek NPL-402CT",
569       0x0000, 0x0000, NULL, NULL, 0,
570       0x0060, { 0x00, 0x40, 0x05 } },
571 #endif
572 };
573 
574 #define	NE2000_NDEVS	(sizeof(ne2000devs) / sizeof(ne2000devs[0]))
575 
576 #define ne2000_match(card, fct, n) \
577 ((((((card)->manufacturer != PCMCIA_VENDOR_INVALID) && \
578     ((card)->manufacturer == ne2000devs[(n)].manufacturer) && \
579     ((card)->product != PCMCIA_PRODUCT_INVALID) && \
580     ((card)->product == ne2000devs[(n)].product)) || \
581    ((ne2000devs[(n)].cis_info[0]) && (ne2000devs[(n)].cis_info[1]) && \
582     ((card)->cis1_info[0]) && ((card)->cis1_info[1]) && \
583     (strcmp((card)->cis1_info[0], ne2000devs[(n)].cis_info[0]) == 0) && \
584     (strcmp((card)->cis1_info[1], ne2000devs[(n)].cis_info[1]) == 0))) && \
585   ((fct) == ne2000devs[(n)].function))? \
586  &ne2000devs[(n)]:NULL)
587 
588 int
ne_pcmcia_match(struct device * parent,void * match,void * aux)589 ne_pcmcia_match(struct device *parent, void *match, void *aux)
590 {
591 	struct pcmcia_attach_args *pa = aux;
592 	int i;
593 
594 	for (i = 0; i < NE2000_NDEVS; i++) {
595 		if (ne2000_match(pa->card, pa->pf->number, i))
596 			return (1);
597 	}
598 
599 	return (0);
600 }
601 
602 void
ne_pcmcia_attach(struct device * parent,struct device * self,void * aux)603 ne_pcmcia_attach(struct device *parent, struct device *self, void *aux)
604 {
605 	struct ne_pcmcia_softc *psc = (void *) self;
606 	struct ne2000_softc *nsc = &psc->sc_ne2000;
607 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
608 	struct pcmcia_attach_args *pa = aux;
609 	struct pcmcia_config_entry *cfe;
610 	const struct ne2000dev *ne_dev;
611 	const char *intrstr;
612 	int i;
613 	u_int8_t myea[6], *enaddr;
614 
615 	psc->sc_pf = pa->pf;
616 
617 	for (cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head); cfe != NULL;
618 	    cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
619 #if 0
620 		/*
621 		 * Some ne2000 driver's claim to have memory; others don't.
622 		 * Since I don't care, I don't check.
623 		 */
624 
625 		if (cfe->num_memspace != 1) {
626 			printf(": unexpected number of memory spaces, "
627 			    " %d should be 1\n", cfe->num_memspace);
628 			return;
629 		}
630 #endif
631 
632 		if (cfe->num_iospace == 1) {
633 			if (cfe->iospace[0].length != NE2000_NPORTS) {
634 				printf(": unexpected I/O space "
635 				    "configuration\n");
636 				continue;
637 			}
638 		} else if (cfe->num_iospace == 2) {
639 			/*
640 			 * Some cards report a separate space for NIC and ASIC.
641 			 * This make some sense, but we must allocate a single
642 			 * NE2000_NPORTS-sized chunk, due to brain damaged
643 			 * address decoders on some of these cards.
644 			 */
645 			if (cfe->iospace[0].length + cfe->iospace[1].length !=
646 			    NE2000_NPORTS) {
647 #ifdef DIAGNOSTIC
648 				printf(": unexpected I/O space "
649 				    "configuration\n");
650 #endif
651 				continue;
652 			}
653 		} else {
654 #ifdef DIAGNOSTIC
655 			printf(": unexpected number of i/o spaces %d"
656 			    " should be 1 or 2\n", cfe->num_iospace);
657 #endif
658 			continue;
659 		}
660 
661 		if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
662 		    NE2000_NPORTS, NE2000_NPORTS, &psc->sc_pcioh)) {
663 #ifdef DIAGNOSTIC
664 			printf(": can't allocate I/O space\n");
665 #endif
666 			continue;
667 		}
668 
669 		break;
670 	}
671 
672 	if (cfe == NULL) {
673 		printf(": no suitable config entry\n");
674 		goto fail_1;
675 	}
676 
677 	dsc->sc_regt = psc->sc_pcioh.iot;
678 	dsc->sc_regh = psc->sc_pcioh.ioh;
679 
680 	nsc->sc_asict = psc->sc_pcioh.iot;
681 	if (bus_space_subregion(dsc->sc_regt, dsc->sc_regh,
682 	    NE2000_ASIC_OFFSET, NE2000_ASIC_NPORTS, &nsc->sc_asich)) {
683 		printf(": can't get subregion for asic\n");
684 		goto fail_2;
685 	}
686 
687 #ifdef notyet
688 	/* Set up power management hooks. */
689 	dsc->sc_enable = ne_pcmcia_enable;
690 	dsc->sc_disable = ne_pcmcia_disable;
691 #endif
692 
693 	/* Enable the card. */
694 	pcmcia_function_init(pa->pf, cfe);
695 	if (pcmcia_function_enable(pa->pf)) {
696 		printf(": function enable failed\n");
697 		goto fail_2;
698 	}
699 
700 	dsc->sc_enabled = 1;
701 
702 	/* some cards claim to be io16, but they're lying. */
703 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO8, NE2000_NIC_OFFSET,
704 	    NE2000_NIC_NPORTS, &psc->sc_pcioh, &psc->sc_nic_io_window)) {
705 		printf(": can't map NIC I/O space\n");
706 		goto fail_3;
707 	}
708 
709 	if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16, NE2000_ASIC_OFFSET,
710 	    NE2000_ASIC_NPORTS, &psc->sc_pcioh, &psc->sc_asic_io_window)) {
711 		printf(": can't map ASIC I/O space\n");
712 		goto fail_4;
713 	}
714 
715 	printf(" port 0x%lx/%d", psc->sc_pcioh.addr, NE2000_NPORTS);
716 
717 	/*
718 	 * Read the station address from the board.
719 	 */
720 	i = 0;
721 again:
722 	enaddr = NULL;			/* Ask ASIC by default */
723 	for (; i < NE2000_NDEVS; i++) {
724 		ne_dev = ne2000_match(pa->card, pa->pf->number, i);
725 		if (ne_dev != NULL) {
726 			if (ne_dev->enet_maddr >= 0) {
727 				enaddr = ne_pcmcia_get_enaddr(psc,
728 				    ne_dev->enet_maddr, myea);
729 				if (enaddr == NULL)
730 					continue;
731 			} else {
732 				enaddr = ne_pcmcia_dl10019_get_enaddr(psc,
733 				    myea);
734 			}
735 			break;
736 		}
737 	}
738 	if (i == NE2000_NDEVS) {
739 		printf(": can't match ethernet vendor code\n");
740 		goto fail_5;
741 	}
742 
743 	if (enaddr != NULL) {
744 		/*
745 		 * Make sure this is what we expect.
746 		 */
747 		if (enaddr[0] != ne_dev->enet_vendor[0] ||
748 		    enaddr[1] != ne_dev->enet_vendor[1] ||
749 		    enaddr[2] != ne_dev->enet_vendor[2]) {
750 			++i;
751 			goto again;
752 		}
753 	}
754 
755 	if ((ne_dev->flags & NE2000DVF_AX88190) != 0) {
756 		if (ne_pcmcia_ax88190_set_iobase(psc))
757 			goto fail_5;
758 
759 		dsc->sc_mediachange = ax88190_mediachange;
760 		dsc->sc_mediastatus = ax88190_mediastatus;
761 		dsc->init_card = ax88190_init_card;
762 		dsc->stop_card = ax88190_stop_card;
763 		dsc->sc_media_init = ax88190_media_init;
764 		dsc->sc_media_fini = ax88190_media_fini;
765 
766 		nsc->sc_type = NE2000_TYPE_AX88190;
767 	}
768 
769 	/*
770 	 * Check for a Realtek 8019.
771 	 */
772 	bus_space_write_1(dsc->sc_regt, dsc->sc_regh, ED_P0_CR,
773 	    ED_CR_PAGE_0 | ED_CR_STP);
774 	if (bus_space_read_1(dsc->sc_regt, dsc->sc_regh, NERTL_RTL0_8019ID0)
775 		== RTL0_8019ID0 &&
776 	    bus_space_read_1(dsc->sc_regt, dsc->sc_regh, NERTL_RTL0_8019ID1)
777 		== RTL0_8019ID1) {
778 		dsc->sc_mediachange = rtl80x9_mediachange;
779 		dsc->sc_mediastatus = rtl80x9_mediastatus;
780 		dsc->init_card = rtl80x9_init_card;
781 		dsc->sc_media_init = rtl80x9_media_init;
782 	}
783 
784 	if (nsc->sc_type == NE2000_TYPE_DL10019 ||
785 	    nsc->sc_type == NE2000_TYPE_DL10022) {
786 		dsc->sc_mediachange = dl10019_mediachange;
787 		dsc->sc_mediastatus = dl10019_mediastatus;
788 		dsc->init_card = dl10019_init_card;
789 		dsc->stop_card = dl10019_stop_card;
790 		dsc->sc_media_init = dl10019_media_init;
791 		dsc->sc_media_fini = dl10019_media_fini;
792 	}
793 
794 	/* set up the interrupt */
795 	psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
796 	    dsc, dsc->sc_dev.dv_xname);
797 	intrstr = pcmcia_intr_string(psc->sc_pf, psc->sc_ih);
798 	if (*intrstr)
799 		printf(", %s", intrstr);
800 
801 	if (ne2000_attach(nsc, enaddr))
802 		goto fail_5;
803 
804 #if notyet
805 	pcmcia_function_disable(pa->pf);
806 #endif
807 	return;
808 
809 fail_5:
810 	/* Unmap ASIC I/O windows. */
811 	pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
812 
813 fail_4:
814 	/* Unmap NIC I/O windows. */
815 	pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
816 
817 fail_3:
818 	pcmcia_function_disable(pa->pf);
819 
820 fail_2:
821 	/* Free our I/O space. */
822 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
823 
824 fail_1:
825 	psc->sc_nic_io_window = -1;
826 }
827 
828 int
ne_pcmcia_detach(struct device * dev,int flags)829 ne_pcmcia_detach(struct device *dev, int flags)
830 {
831 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dev;
832 	int error;
833 
834 	if (psc->sc_nic_io_window == -1)
835 		/* Nothing to detach. */
836 		return (0);
837 
838 	error = ne2000_detach(&psc->sc_ne2000, flags);
839 	if (error != 0)
840 		return (error);
841 
842 	/* Unmap our i/o windows. */
843 	pcmcia_io_unmap(psc->sc_pf, psc->sc_asic_io_window);
844 	pcmcia_io_unmap(psc->sc_pf, psc->sc_nic_io_window);
845 
846 	/* Free our i/o space. */
847 	pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
848 
849 	return (0);
850 }
851 
852 int
ne_pcmcia_activate(struct device * dev,int act)853 ne_pcmcia_activate(struct device *dev, int act)
854 {
855 	struct ne_pcmcia_softc *sc = (struct ne_pcmcia_softc *)dev;
856 	struct dp8390_softc *esc = &sc->sc_ne2000.sc_dp8390;
857 	struct ifnet *ifp = &esc->sc_arpcom.ac_if;
858 
859 	switch (act) {
860 	case DVACT_SUSPEND:
861 		ifp->if_timer = 0;
862 		if (ifp->if_flags & IFF_RUNNING) {
863 			dp8390_stop(esc);
864 			ifp->if_flags &= ~IFF_RUNNING;
865 		}
866 		if (sc->sc_ih != NULL)
867 			pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
868 		sc->sc_ih = NULL;
869 		pcmcia_function_disable(sc->sc_pf);
870 		break;
871 	case DVACT_RESUME:
872 		pcmcia_function_enable(sc->sc_pf);
873 		sc->sc_ih = pcmcia_intr_establish(sc->sc_pf, IPL_NET,
874 		    dp8390_intr, sc, esc->sc_dev.dv_xname);
875 		dp8390_enable(esc);
876 		if (ifp->if_flags & IFF_UP)
877 			dp8390_init(esc);
878 		break;
879 	case DVACT_DEACTIVATE:
880 		ifp->if_timer = 0;
881 		if (ifp->if_flags & IFF_RUNNING) {
882 			dp8390_stop(esc);
883 			ifp->if_flags &= ~IFF_RUNNING;
884 		}
885 		if (sc->sc_ih != NULL)
886 			pcmcia_intr_disestablish(sc->sc_pf, sc->sc_ih);
887 		sc->sc_ih = NULL;
888 		pcmcia_function_disable(sc->sc_pf);
889 		break;
890 	}
891 	return (0);
892 }
893 
894 #ifdef notyet
895 int
ne_pcmcia_enable(struct dp8390_softc * dsc)896 ne_pcmcia_enable(struct dp8390_softc *dsc)
897 {
898 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
899 
900 	/* set up the interrupt */
901 	psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, dp8390_intr,
902 	    dsc, dsc->sc_dev.dv_xname);
903 	if (psc->sc_ih == NULL) {
904 		printf("%s: couldn't establish interrupt\n",
905 		    dsc->sc_dev.dv_xname);
906 		return (1);
907 	}
908 
909 	return (pcmcia_function_enable(psc->sc_pf));
910 }
911 
912 void
ne_pcmcia_disable(struct dp8390_softc * dsc)913 ne_pcmcia_disable(struct dp8390_softc *dsc)
914 {
915 	struct ne_pcmcia_softc *psc = (struct ne_pcmcia_softc *)dsc;
916 
917 	pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
918 	pcmcia_function_disable(psc->sc_pf);
919 }
920 #endif
921 
922 u_int8_t *
ne_pcmcia_get_enaddr(struct ne_pcmcia_softc * psc,int maddr,u_int8_t myea[ETHER_ADDR_LEN])923 ne_pcmcia_get_enaddr(struct ne_pcmcia_softc *psc, int maddr,
924     u_int8_t myea[ETHER_ADDR_LEN])
925 {
926 	struct ne2000_softc *nsc = &psc->sc_ne2000;
927 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
928 	struct pcmcia_mem_handle pcmh;
929 	bus_size_t offset;
930 	u_int8_t *enaddr = NULL;
931 	int j, mwindow;
932 
933 	if (maddr < 0)
934 		return (NULL);
935 
936 	if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
937 		printf("%s: can't alloc mem for enet addr\n",
938 		    dsc->sc_dev.dv_xname);
939 		goto fail_1;
940 	}
941 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, maddr,
942 	    ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
943 		printf("%s: can't map mem for enet addr\n",
944 		    dsc->sc_dev.dv_xname);
945 		goto fail_2;
946 	}
947 	for (j = 0; j < ETHER_ADDR_LEN; j++)
948 		myea[j] = bus_space_read_1(pcmh.memt, pcmh.memh,
949 		    offset + (j * 2));
950 	enaddr = myea;
951 
952 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
953  fail_2:
954 	pcmcia_mem_free(psc->sc_pf, &pcmh);
955  fail_1:
956 	return (enaddr);
957 }
958 
959 u_int8_t *
ne_pcmcia_dl10019_get_enaddr(struct ne_pcmcia_softc * psc,u_int8_t myea[ETHER_ADDR_LEN])960 ne_pcmcia_dl10019_get_enaddr(struct ne_pcmcia_softc *psc,
961     u_int8_t myea[ETHER_ADDR_LEN])
962 {
963 	struct ne2000_softc *nsc = &psc->sc_ne2000;
964 	u_int8_t sum;
965 	int j, type;
966 
967 	for (j = 0, sum = 0; j < 8; j++) {
968 		sum += bus_space_read_1(nsc->sc_asict, nsc->sc_asich,
969 		    0x04 + j);
970 	}
971 	if (sum != 0xff)
972 		return (NULL);
973 
974 	for (j = 0; j < ETHER_ADDR_LEN; j++) {
975 		myea[j] = bus_space_read_1(nsc->sc_asict,
976 		    nsc->sc_asich, 0x04 + j);
977 	}
978 
979 	/* XXX - magic values from Linux */
980 	type = bus_space_read_1(nsc->sc_asict, nsc->sc_asich, 0x0f);
981 	if (type == 0x91 || type == 0x99)
982 		nsc->sc_type = NE2000_TYPE_DL10022;
983 	else
984 		nsc->sc_type = NE2000_TYPE_DL10019;
985 
986 	return (myea);
987 }
988 
989 int
ne_pcmcia_ax88190_set_iobase(struct ne_pcmcia_softc * psc)990 ne_pcmcia_ax88190_set_iobase(struct ne_pcmcia_softc *psc)
991 {
992 	struct ne2000_softc *nsc = &psc->sc_ne2000;
993 	struct dp8390_softc *dsc = &nsc->sc_dp8390;
994 	struct pcmcia_mem_handle pcmh;
995 	bus_size_t offset;
996 	int rv = 1, mwindow;
997 
998 	if (pcmcia_mem_alloc(psc->sc_pf, AX88190_LAN_IOSIZE, &pcmh)) {
999 		printf("%s: can't alloc mem for LAN iobase\n",
1000 		    dsc->sc_dev.dv_xname);
1001 		goto fail_1;
1002 	}
1003 	if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR,
1004 	    AX88190_LAN_IOBASE, AX88190_LAN_IOSIZE, &pcmh, &offset,
1005 	    &mwindow)) {
1006 		printf("%s: can't map mem for LAN iobase\n",
1007 		    dsc->sc_dev.dv_xname);
1008 		goto fail_2;
1009 	}
1010 
1011 #ifdef NE_DEBUG
1012 	printf(": LAN iobase 0x%x (0x%x) ->",
1013 	    bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
1014 	    bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8,
1015 	    (u_int)psc->sc_pcioh.addr);
1016 #endif
1017 	bus_space_write_1(pcmh.memt, pcmh.memh, offset,
1018 	    psc->sc_pcioh.addr & 0xff);
1019 	bus_space_write_1(pcmh.memt, pcmh.memh, offset + 2,
1020 	    psc->sc_pcioh.addr >> 8);
1021 #ifdef NE_DEBUG
1022 	printf(" 0x%x", bus_space_read_1(pcmh.memt, pcmh.memh, offset + 0) |
1023 	    bus_space_read_1(pcmh.memt, pcmh.memh, offset + 2) << 8);
1024 #endif
1025 	rv = 0;
1026 
1027 	pcmcia_mem_unmap(psc->sc_pf, mwindow);
1028  fail_2:
1029 	pcmcia_mem_free(psc->sc_pf, &pcmh);
1030  fail_1:
1031 	return (rv);
1032 }
1033