if_mbe_pcmcia.c revision 1.28 1 1.28 thorpej /* $NetBSD: if_mbe_pcmcia.c,v 1.28 2002/09/30 22:27:00 thorpej Exp $ */
2 1.1 enami
3 1.1 enami /*-
4 1.13 cgd * Copyright (c) 1998, 2000 The NetBSD Foundation, Inc.
5 1.1 enami * All rights reserved.
6 1.1 enami *
7 1.1 enami * This code is derived from software contributed to The NetBSD Foundation
8 1.1 enami * by Enami Tsugutomo.
9 1.1 enami *
10 1.1 enami * Redistribution and use in source and binary forms, with or without
11 1.1 enami * modification, are permitted provided that the following conditions
12 1.1 enami * are met:
13 1.1 enami * 1. Redistributions of source code must retain the above copyright
14 1.1 enami * notice, this list of conditions and the following disclaimer.
15 1.1 enami * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 enami * notice, this list of conditions and the following disclaimer in the
17 1.1 enami * documentation and/or other materials provided with the distribution.
18 1.1 enami * 3. All advertising materials mentioning features or use of this software
19 1.1 enami * must display the following acknowledgement:
20 1.1 enami * This product includes software developed by the NetBSD
21 1.1 enami * Foundation, Inc. and its contributors.
22 1.1 enami * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 enami * contributors may be used to endorse or promote products derived
24 1.1 enami * from this software without specific prior written permission.
25 1.1 enami *
26 1.1 enami * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 enami * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 enami * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 enami * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 enami * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 enami * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 enami * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 enami * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 enami * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 enami * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 enami * POSSIBILITY OF SUCH DAMAGE.
37 1.1 enami */
38 1.21 lukem
39 1.21 lukem #include <sys/cdefs.h>
40 1.28 thorpej __KERNEL_RCSID(0, "$NetBSD: if_mbe_pcmcia.c,v 1.28 2002/09/30 22:27:00 thorpej Exp $");
41 1.1 enami
42 1.1 enami #include <sys/param.h>
43 1.1 enami #include <sys/systm.h>
44 1.1 enami #include <sys/device.h>
45 1.1 enami #include <sys/socket.h>
46 1.1 enami
47 1.1 enami #include <net/if.h>
48 1.1 enami #include <net/if_ether.h>
49 1.1 enami #include <net/if_media.h>
50 1.1 enami
51 1.1 enami #include <machine/intr.h>
52 1.1 enami #include <machine/bus.h>
53 1.1 enami
54 1.1 enami #include <dev/ic/mb86960reg.h>
55 1.1 enami #include <dev/ic/mb86960var.h>
56 1.1 enami
57 1.1 enami #include <dev/pcmcia/pcmciareg.h>
58 1.1 enami #include <dev/pcmcia/pcmciavar.h>
59 1.3 christos #include <dev/pcmcia/pcmciadevs.h>
60 1.1 enami
61 1.1 enami int mbe_pcmcia_match __P((struct device *, struct cfdata *, void *));
62 1.1 enami void mbe_pcmcia_attach __P((struct device *, struct device *, void *));
63 1.4 thorpej int mbe_pcmcia_detach __P((struct device *, int));
64 1.1 enami
65 1.24 ichiro static const struct mbe_pcmcia_product
66 1.24 ichiro *mbe_pcmcia_lookup __P((struct pcmcia_attach_args *pa));
67 1.24 ichiro
68 1.1 enami struct mbe_pcmcia_softc {
69 1.1 enami struct mb86960_softc sc_mb86960; /* real "mb" softc */
70 1.1 enami
71 1.1 enami /* PCMCIA-specific goo. */
72 1.1 enami struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */
73 1.1 enami int sc_io_window; /* our i/o window */
74 1.1 enami void *sc_ih; /* interrupt cookie */
75 1.1 enami struct pcmcia_function *sc_pf; /* our PCMCIA function */
76 1.1 enami };
77 1.1 enami
78 1.28 thorpej CFATTACH_DECL(mbe_pcmcia, sizeof(struct mbe_pcmcia_softc),
79 1.28 thorpej mbe_pcmcia_match, mbe_pcmcia_attach, mbe_pcmcia_detach, mb86960_activate)
80 1.1 enami
81 1.1 enami int mbe_pcmcia_enable __P((struct mb86960_softc *));
82 1.1 enami void mbe_pcmcia_disable __P((struct mb86960_softc *));
83 1.1 enami
84 1.1 enami struct mbe_pcmcia_get_enaddr_args {
85 1.1 enami u_int8_t enaddr[ETHER_ADDR_LEN];
86 1.18 is int maddr;
87 1.1 enami };
88 1.18 is int mbe_pcmcia_get_enaddr_from_cis __P((struct pcmcia_tuple *, void *));
89 1.18 is int mbe_pcmcia_get_enaddr_from_mem __P((struct mbe_pcmcia_softc *,
90 1.19 enami struct mbe_pcmcia_get_enaddr_args *));
91 1.25 ichiro int mbe_pcmcia_get_enaddr_from_io __P((struct mbe_pcmcia_softc *,
92 1.25 ichiro struct mbe_pcmcia_get_enaddr_args *));
93 1.1 enami
94 1.24 ichiro static const struct mbe_pcmcia_product {
95 1.24 ichiro const char *mpp_name; /* product name */
96 1.24 ichiro u_int32_t mpp_vendor; /* vendor ID */
97 1.24 ichiro u_int32_t mpp_product; /* product ID */
98 1.24 ichiro const char *mpp_cisinfo[4]; /* CIS information */
99 1.24 ichiro u_int32_t mpp_ioalign; /* required alignment */
100 1.24 ichiro int mpp_enet_maddr;
101 1.25 ichiro int flags;
102 1.25 ichiro #define MBH10302 0x0001 /* FUJITSU MBH10302 */
103 1.7 thorpej } mbe_pcmcia_products[] = {
104 1.24 ichiro { PCMCIA_STR_TDK_LAK_CD021BX, PCMCIA_VENDOR_TDK,
105 1.24 ichiro PCMCIA_PRODUCT_TDK_LAK_CD021BX, PCMCIA_CIS_TDK_LAK_CD021BX,
106 1.19 enami 0, -1 },
107 1.13 cgd
108 1.24 ichiro { PCMCIA_STR_TDK_LAK_CF010, PCMCIA_VENDOR_TDK,
109 1.24 ichiro PCMCIA_PRODUCT_TDK_LAK_CF010, PCMCIA_CIS_TDK_LAK_CF010,
110 1.19 enami 0, -1 },
111 1.19 enami
112 1.7 thorpej #if 0 /* XXX 86960-based? */
113 1.24 ichiro { PCMCIA_STR_TDK_LAK_DFL9610, PCMCIA_VENDOR_TDK,
114 1.24 ichiro PCMCIA_PRODUCT_TDK_LAK_DFL9610, PCMCIA_CIS_TDK_DFL9610,
115 1.25 ichiro 0, -1, MBH10302 /* XXX */ },
116 1.7 thorpej #endif
117 1.8 tron
118 1.24 ichiro { PCMCIA_STR_CONTEC_CNETPC, PCMCIA_VENDOR_CONTEC,
119 1.24 ichiro PCMCIA_PRODUCT_CONTEC_CNETPC, PCMCIA_CIS_CONTEC_CNETPC,
120 1.18 is 0, -1 },
121 1.13 cgd
122 1.24 ichiro { PCMCIA_STR_FUJITSU_LA501, PCMCIA_VENDOR_FUJITSU,
123 1.24 ichiro PCMCIA_PRODUCT_FUJITSU_LA501, PCMCIA_CIS_FUJITSU_LA501,
124 1.18 is 0x20, -1 },
125 1.13 cgd
126 1.25 ichiro { PCMCIA_STR_FUJITSU_FMV_J181, PCMCIA_VENDOR_FUJITSU,
127 1.25 ichiro PCMCIA_PRODUCT_FUJITSU_FMV_J181, PCMCIA_CIS_FUJITSU_FMV_J181,
128 1.25 ichiro 0x20, -1, MBH10302 },
129 1.25 ichiro
130 1.25 ichiro { PCMCIA_STR_FUJITSU_FMV_J182, PCMCIA_VENDOR_FUJITSU,
131 1.25 ichiro PCMCIA_PRODUCT_FUJITSU_FMV_J182, PCMCIA_CIS_FUJITSU_FMV_J182,
132 1.25 ichiro 0, 0xf2c },
133 1.25 ichiro
134 1.25 ichiro { PCMCIA_STR_FUJITSU_FMV_J182A, PCMCIA_VENDOR_FUJITSU,
135 1.25 ichiro PCMCIA_PRODUCT_FUJITSU_FMV_J182A, PCMCIA_CIS_FUJITSU_FMV_J182A,
136 1.25 ichiro 0, 0x1cc },
137 1.23 ichiro
138 1.24 ichiro { PCMCIA_STR_FUJITSU_ITCFJ182A, PCMCIA_VENDOR_FUJITSU,
139 1.24 ichiro PCMCIA_PRODUCT_FUJITSU_ITCFJ182A, PCMCIA_CIS_FUJITSU_ITCFJ182A,
140 1.23 ichiro 0, 0x1cc },
141 1.18 is
142 1.25 ichiro { PCMCIA_STR_FUJITSU_LA10S, PCMCIA_VENDOR_FUJITSU,
143 1.25 ichiro PCMCIA_PRODUCT_FUJITSU_LA10S, PCMCIA_CIS_FUJITSU_LA10S,
144 1.25 ichiro 0, -1 },
145 1.25 ichiro
146 1.24 ichiro { PCMCIA_STR_RATOC_REX_R280, PCMCIA_VENDOR_RATOC,
147 1.24 ichiro PCMCIA_PRODUCT_RATOC_REX_R280, PCMCIA_CIS_RATOC_REX_R280,
148 1.18 is 0, 0x1fc },
149 1.13 cgd
150 1.24 ichiro { NULL, 0,
151 1.24 ichiro 0, { NULL, NULL, NULL, NULL },
152 1.24 ichiro 0, 0 }
153 1.7 thorpej };
154 1.7 thorpej
155 1.24 ichiro static const struct mbe_pcmcia_product *
156 1.24 ichiro mbe_pcmcia_lookup(pa)
157 1.24 ichiro struct pcmcia_attach_args *pa;
158 1.24 ichiro {
159 1.24 ichiro const struct mbe_pcmcia_product *mpp;
160 1.24 ichiro
161 1.24 ichiro for (mpp = mbe_pcmcia_products; mpp->mpp_name != NULL; mpp++) {
162 1.24 ichiro /* match by CIS information */
163 1.24 ichiro if (pa->card->cis1_info[0] != NULL &&
164 1.24 ichiro mpp->mpp_cisinfo[0] != NULL &&
165 1.24 ichiro strcmp(pa->card->cis1_info[0], mpp->mpp_cisinfo[0]) == 0 &&
166 1.24 ichiro pa->card->cis1_info[1] != NULL &&
167 1.24 ichiro mpp->mpp_cisinfo[1] != NULL &&
168 1.25 ichiro strcmp(pa->card->cis1_info[1], mpp->mpp_cisinfo[1]) == 0 &&
169 1.25 ichiro (mpp->mpp_cisinfo[2] == NULL ||
170 1.25 ichiro strcmp(pa->card->cis1_info[2], mpp->mpp_cisinfo[2]) == 0))
171 1.24 ichiro return (mpp);
172 1.24 ichiro
173 1.24 ichiro /* match by vendor/product id */
174 1.24 ichiro if (pa->manufacturer != PCMCIA_VENDOR_INVALID &&
175 1.24 ichiro pa->manufacturer == mpp->mpp_vendor &&
176 1.24 ichiro pa->product != PCMCIA_PRODUCT_INVALID &&
177 1.24 ichiro pa->product == mpp->mpp_product)
178 1.24 ichiro return (mpp);
179 1.24 ichiro }
180 1.24 ichiro
181 1.24 ichiro return (NULL);
182 1.24 ichiro }
183 1.24 ichiro
184 1.1 enami int
185 1.1 enami mbe_pcmcia_match(parent, match, aux)
186 1.1 enami struct device *parent;
187 1.1 enami struct cfdata *match;
188 1.1 enami void *aux;
189 1.1 enami {
190 1.1 enami struct pcmcia_attach_args *pa = aux;
191 1.1 enami
192 1.24 ichiro if (mbe_pcmcia_lookup(pa) != NULL)
193 1.7 thorpej return (1);
194 1.1 enami return (0);
195 1.1 enami }
196 1.1 enami
197 1.1 enami void
198 1.1 enami mbe_pcmcia_attach(parent, self, aux)
199 1.1 enami struct device *parent, *self;
200 1.1 enami void *aux;
201 1.1 enami {
202 1.1 enami struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)self;
203 1.1 enami struct mb86960_softc *sc = &psc->sc_mb86960;
204 1.1 enami struct pcmcia_attach_args *pa = aux;
205 1.1 enami struct pcmcia_config_entry *cfe;
206 1.1 enami struct mbe_pcmcia_get_enaddr_args pgea;
207 1.7 thorpej const struct mbe_pcmcia_product *mpp;
208 1.10 enami int rv;
209 1.7 thorpej
210 1.24 ichiro mpp = mbe_pcmcia_lookup(pa);
211 1.7 thorpej if (mpp == NULL) {
212 1.7 thorpej printf("\n");
213 1.7 thorpej panic("mbe_pcmcia_attach: impossible");
214 1.7 thorpej }
215 1.1 enami
216 1.1 enami psc->sc_pf = pa->pf;
217 1.26 lukem cfe = SIMPLEQ_FIRST(&pa->pf->cfe_head);
218 1.1 enami
219 1.1 enami /* Enable the card. */
220 1.1 enami pcmcia_function_init(pa->pf, cfe);
221 1.1 enami if (pcmcia_function_enable(pa->pf)) {
222 1.1 enami printf(": function enable failed\n");
223 1.17 enami goto enable_failed;
224 1.1 enami }
225 1.1 enami
226 1.1 enami /* Allocate and map i/o space for the card. */
227 1.1 enami if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
228 1.7 thorpej cfe->iospace[0].length,
229 1.7 thorpej mpp->mpp_ioalign ? mpp->mpp_ioalign : cfe->iospace[0].length,
230 1.7 thorpej &psc->sc_pcioh)) {
231 1.1 enami printf(": can't allocate i/o space\n");
232 1.14 enami goto ioalloc_failed;
233 1.1 enami }
234 1.1 enami
235 1.1 enami sc->sc_bst = psc->sc_pcioh.iot;
236 1.1 enami sc->sc_bsh = psc->sc_pcioh.ioh;
237 1.1 enami
238 1.1 enami sc->sc_enable = mbe_pcmcia_enable;
239 1.1 enami sc->sc_disable = mbe_pcmcia_disable;
240 1.1 enami
241 1.7 thorpej /*
242 1.7 thorpej * Don't bother checking flags; the back-end sets the chip
243 1.7 thorpej * into 16-bit mode.
244 1.7 thorpej */
245 1.25 ichiro if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_IO16, 0,
246 1.25 ichiro mpp->mpp_ioalign ? mpp->mpp_ioalign : cfe->iospace[0].length,
247 1.1 enami &psc->sc_pcioh, &psc->sc_io_window)) {
248 1.1 enami printf(": can't map i/o space\n");
249 1.14 enami goto iomap_failed;
250 1.1 enami }
251 1.1 enami
252 1.24 ichiro printf(": %s\n", mpp->mpp_name);
253 1.1 enami
254 1.25 ichiro /* Read station address from io/mem or CIS. */
255 1.19 enami if (mpp->mpp_enet_maddr >= 0) {
256 1.19 enami pgea.maddr = mpp->mpp_enet_maddr;
257 1.18 is if (mbe_pcmcia_get_enaddr_from_mem(psc, &pgea) != 0) {
258 1.18 is printf("%s: Couldn't get ethernet address "
259 1.19 enami "from mem\n", sc->sc_dev.dv_xname);
260 1.18 is goto no_enaddr;
261 1.18 is }
262 1.25 ichiro } else if ((mpp->flags & MBH10302) != 0) {
263 1.25 ichiro bus_space_write_1(sc->sc_bst, sc->sc_bsh, FE_MBH0 ,
264 1.25 ichiro FE_MBH0_MASK | FE_MBH0_INTR_ENABLE);
265 1.25 ichiro if (mbe_pcmcia_get_enaddr_from_io(psc, &pgea) != 0) {
266 1.25 ichiro printf("%s: Couldn't get ethernet address "
267 1.25 ichiro "from io\n", sc->sc_dev.dv_xname);
268 1.25 ichiro goto no_enaddr;
269 1.25 ichiro }
270 1.18 is } else {
271 1.19 enami rv = pcmcia_scan_cis(parent,
272 1.19 enami mbe_pcmcia_get_enaddr_from_cis, &pgea);
273 1.18 is if (rv == -1) {
274 1.18 is printf("%s: Couldn't read CIS to get ethernet "
275 1.19 enami "address\n", sc->sc_dev.dv_xname);
276 1.18 is goto no_enaddr;
277 1.18 is } else if (rv == 0) {
278 1.18 is printf("%s: Couldn't get ethernet address "
279 1.19 enami "from CIS\n", sc->sc_dev.dv_xname);
280 1.18 is goto no_enaddr;
281 1.18 is }
282 1.1 enami #ifdef DIAGNOSTIC
283 1.18 is if (rv != 1) {
284 1.18 is printf("%s: pcmcia_scan_cis returns %d\n",
285 1.19 enami sc->sc_dev.dv_xname, rv);
286 1.18 is panic("mbe_pcmcia_attach");
287 1.18 is }
288 1.18 is printf("%s: Ethernet address from CIS: %s\n",
289 1.19 enami sc->sc_dev.dv_xname, ether_sprintf(pgea.enaddr));
290 1.18 is #endif
291 1.10 enami }
292 1.1 enami
293 1.1 enami /* Perform generic initialization. */
294 1.25 ichiro if ((mpp->flags & MBH10302) != 0)
295 1.25 ichiro mb86960_attach(sc, MB86960_TYPE_86960, pgea.enaddr);
296 1.25 ichiro else
297 1.25 ichiro mb86960_attach(sc, MB86960_TYPE_86965, pgea.enaddr);
298 1.1 enami
299 1.1 enami mb86960_config(sc, NULL, 0, 0);
300 1.1 enami
301 1.1 enami pcmcia_function_disable(pa->pf);
302 1.14 enami return;
303 1.14 enami
304 1.14 enami no_enaddr:
305 1.14 enami /* Unmap our i/o window. */
306 1.14 enami pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
307 1.14 enami
308 1.14 enami iomap_failed:
309 1.14 enami /* Free our i/o space. */
310 1.14 enami pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
311 1.14 enami
312 1.14 enami ioalloc_failed:
313 1.14 enami pcmcia_function_disable(pa->pf);
314 1.17 enami
315 1.17 enami enable_failed:
316 1.17 enami psc->sc_io_window = -1;
317 1.4 thorpej }
318 1.4 thorpej
319 1.4 thorpej int
320 1.4 thorpej mbe_pcmcia_detach(self, flags)
321 1.4 thorpej struct device *self;
322 1.4 thorpej int flags;
323 1.4 thorpej {
324 1.5 thorpej struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)self;
325 1.12 enami int error;
326 1.12 enami
327 1.14 enami if (psc->sc_io_window == -1)
328 1.19 enami /* Nothing to detach. */
329 1.14 enami return (0);
330 1.14 enami
331 1.14 enami error = mb86960_detach(&psc->sc_mb86960);
332 1.12 enami if (error != 0)
333 1.12 enami return (error);
334 1.5 thorpej
335 1.5 thorpej /* Unmap our i/o window. */
336 1.5 thorpej pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
337 1.5 thorpej
338 1.5 thorpej /* Free our i/o space. */
339 1.5 thorpej pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
340 1.5 thorpej
341 1.4 thorpej return (0);
342 1.1 enami }
343 1.1 enami
344 1.1 enami int
345 1.1 enami mbe_pcmcia_enable(sc)
346 1.1 enami struct mb86960_softc *sc;
347 1.1 enami {
348 1.1 enami struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)sc;
349 1.1 enami
350 1.1 enami /* Establish the interrupt handler. */
351 1.1 enami psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, mb86960_intr,
352 1.1 enami sc);
353 1.1 enami if (psc->sc_ih == NULL) {
354 1.1 enami printf("%s: couldn't establish interrupt handler\n",
355 1.1 enami sc->sc_dev.dv_xname);
356 1.1 enami return (1);
357 1.1 enami }
358 1.1 enami
359 1.17 enami if (pcmcia_function_enable(psc->sc_pf)) {
360 1.17 enami pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
361 1.17 enami return (1);
362 1.17 enami }
363 1.16 enami
364 1.17 enami return (0);
365 1.1 enami }
366 1.1 enami
367 1.1 enami void
368 1.1 enami mbe_pcmcia_disable(sc)
369 1.1 enami struct mb86960_softc *sc;
370 1.1 enami {
371 1.1 enami struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)sc;
372 1.1 enami
373 1.1 enami pcmcia_function_disable(psc->sc_pf);
374 1.17 enami pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
375 1.1 enami }
376 1.1 enami
377 1.1 enami int
378 1.18 is mbe_pcmcia_get_enaddr_from_cis(tuple, arg)
379 1.1 enami struct pcmcia_tuple *tuple;
380 1.1 enami void *arg;
381 1.1 enami {
382 1.1 enami struct mbe_pcmcia_get_enaddr_args *p = arg;
383 1.1 enami int i;
384 1.1 enami
385 1.1 enami if (tuple->code == PCMCIA_CISTPL_FUNCE) {
386 1.1 enami if (tuple->length < 2) /* sub code and ether addr length */
387 1.1 enami return (0);
388 1.1 enami
389 1.1 enami if ((pcmcia_tuple_read_1(tuple, 0) !=
390 1.1 enami PCMCIA_TPLFE_TYPE_LAN_NID) ||
391 1.1 enami (pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN))
392 1.1 enami return (0);
393 1.1 enami
394 1.1 enami for (i = 0; i < ETHER_ADDR_LEN; i++)
395 1.1 enami p->enaddr[i] = pcmcia_tuple_read_1(tuple, i + 2);
396 1.1 enami return (1);
397 1.1 enami }
398 1.25 ichiro return (0);
399 1.25 ichiro }
400 1.25 ichiro
401 1.25 ichiro int
402 1.25 ichiro mbe_pcmcia_get_enaddr_from_io(psc, ea)
403 1.25 ichiro struct mbe_pcmcia_softc *psc;
404 1.25 ichiro struct mbe_pcmcia_get_enaddr_args *ea;
405 1.25 ichiro {
406 1.25 ichiro int i;
407 1.25 ichiro
408 1.25 ichiro for (i = 0; i < ETHER_ADDR_LEN; i++)
409 1.25 ichiro ea->enaddr[i] = bus_space_read_1(psc->sc_pcioh.iot,
410 1.25 ichiro psc->sc_pcioh.ioh, FE_MBH_ENADDR + i);
411 1.25 ichiro
412 1.25 ichiro if (ea->enaddr == NULL)
413 1.25 ichiro return (1);
414 1.18 is return (0);
415 1.18 is }
416 1.18 is
417 1.18 is int
418 1.18 is mbe_pcmcia_get_enaddr_from_mem(psc, ea)
419 1.18 is struct mbe_pcmcia_softc *psc;
420 1.18 is struct mbe_pcmcia_get_enaddr_args *ea;
421 1.18 is {
422 1.18 is struct mb86960_softc *sc = &psc->sc_mb86960;
423 1.18 is struct pcmcia_mem_handle pcmh;
424 1.22 soren bus_size_t offset;
425 1.20 enami int i, mwindow, rv = 1;
426 1.18 is
427 1.18 is if (ea->maddr < 0)
428 1.20 enami goto bad_memaddr;
429 1.18 is
430 1.18 is if (pcmcia_mem_alloc(psc->sc_pf, ETHER_ADDR_LEN * 2, &pcmh)) {
431 1.18 is printf("%s: can't alloc mem for enet addr\n",
432 1.19 enami sc->sc_dev.dv_xname);
433 1.20 enami goto memalloc_failed;
434 1.18 is }
435 1.18 is
436 1.18 is if (pcmcia_mem_map(psc->sc_pf, PCMCIA_MEM_ATTR, ea->maddr,
437 1.19 enami ETHER_ADDR_LEN * 2, &pcmh, &offset, &mwindow)) {
438 1.18 is printf("%s: can't map mem for enet addr\n",
439 1.19 enami sc->sc_dev.dv_xname);
440 1.20 enami goto memmap_failed;
441 1.18 is }
442 1.18 is
443 1.18 is for (i = 0; i < ETHER_ADDR_LEN; i++)
444 1.18 is ea->enaddr[i] = bus_space_read_1(pcmh.memt, pcmh.memh,
445 1.19 enami offset + (i * 2));
446 1.18 is
447 1.20 enami rv = 0;
448 1.18 is pcmcia_mem_unmap(psc->sc_pf, mwindow);
449 1.20 enami memmap_failed:
450 1.18 is pcmcia_mem_free(psc->sc_pf, &pcmh);
451 1.20 enami memalloc_failed:
452 1.20 enami bad_memaddr:
453 1.18 is
454 1.20 enami return (rv);
455 1.1 enami }
456