if_mbe_pcmcia.c revision 1.1 1 /* $NetBSD: if_mbe_pcmcia.c,v 1.1 1998/03/22 04:32:27 enami Exp $ */
2
3 /*-
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Enami Tsugutomo.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/socket.h>
43
44 #include <net/if.h>
45 #include <net/if_ether.h>
46 #include <net/if_media.h>
47
48 #include <machine/intr.h>
49 #include <machine/bus.h>
50
51 #include <dev/ic/mb86960reg.h>
52 #include <dev/ic/mb86960var.h>
53
54 #include <dev/pcmcia/pcmciareg.h>
55 #include <dev/pcmcia/pcmciavar.h>
56
57
58 #define PCMCIA_MANUFACTURER_TDK 0x0105
59 #define PCMCIA_PRODUCT_TDK_LAK_CD021BX 0x0200
60 #define PCMCIA_PRODUCT_TDK_DFL9610 0x0d0a
61
62 #ifdef __BROKEN_INDIRECT_CONFIG
63 int mbe_pcmcia_match __P((struct device *, void *, void *));
64 #else
65 int mbe_pcmcia_match __P((struct device *, struct cfdata *, void *));
66 #endif
67 void mbe_pcmcia_attach __P((struct device *, struct device *, void *));
68
69 struct mbe_pcmcia_softc {
70 struct mb86960_softc sc_mb86960; /* real "mb" softc */
71
72 /* PCMCIA-specific goo. */
73 struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */
74 int sc_io_window; /* our i/o window */
75 void *sc_ih; /* interrupt cookie */
76 struct pcmcia_function *sc_pf; /* our PCMCIA function */
77 };
78
79 struct cfattach mbe_pcmcia_ca = {
80 sizeof(struct mbe_pcmcia_softc), mbe_pcmcia_match, mbe_pcmcia_attach
81 };
82
83 #if NetBSD <= 199712
84 struct cfdriver mbe_cd = { /* XXX shouldn't be here */
85 NULL, "mbe", DV_IFNET
86 };
87 #endif
88
89 int mbe_pcmcia_enable __P((struct mb86960_softc *));
90 void mbe_pcmcia_disable __P((struct mb86960_softc *));
91
92 struct mbe_pcmcia_get_enaddr_args {
93 int got_enaddr;
94 u_int8_t enaddr[ETHER_ADDR_LEN];
95 };
96 int mbe_pcmcia_get_enaddr __P((struct pcmcia_tuple *, void *));
97
98 int
99 mbe_pcmcia_match(parent, match, aux)
100 struct device *parent;
101 #ifdef __BROKEN_INDIRECT_CONFIG
102 void *match;
103 #else
104 struct cfdata *match;
105 #endif
106 void *aux;
107 {
108 struct pcmcia_attach_args *pa = aux;
109
110 if (pa->manufacturer == PCMCIA_MANUFACTURER_TDK) {
111 switch (pa->product) {
112 case PCMCIA_PRODUCT_TDK_LAK_CD021BX:
113 if (pa->pf->number == 0)
114 return (1);
115 break;
116 #if 0 /* XXX Is this card mb86960 based one? */
117 case PCMCIA_PRODUCT_TDK_DFL9610:
118 if (pa->pf->number == 1)
119 return (1);
120 break;
121 #endif
122 }
123 }
124
125 return (0);
126 }
127
128 void
129 mbe_pcmcia_attach(parent, self, aux)
130 struct device *parent, *self;
131 void *aux;
132 {
133 struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)self;
134 struct mb86960_softc *sc = &psc->sc_mb86960;
135 struct pcmcia_attach_args *pa = aux;
136 struct pcmcia_config_entry *cfe;
137 struct mbe_pcmcia_get_enaddr_args pgea;
138 const char *model;
139
140 psc->sc_pf = pa->pf;
141 cfe = pa->pf->cfe_head.sqh_first;
142
143 /* Enable the card. */
144 pcmcia_function_init(pa->pf, cfe);
145 if (pcmcia_function_enable(pa->pf)) {
146 printf(": function enable failed\n");
147 return;
148 }
149
150 /* Allocate and map i/o space for the card. */
151 if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
152 cfe->iospace[0].length, cfe->iospace[0].length, &psc->sc_pcioh)) {
153 printf(": can't allocate i/o space\n");
154 return;
155 }
156
157 sc->sc_bst = psc->sc_pcioh.iot;
158 sc->sc_bsh = psc->sc_pcioh.ioh;
159
160 sc->sc_enable = mbe_pcmcia_enable;
161 sc->sc_disable = mbe_pcmcia_disable;
162
163 if (pcmcia_io_map(pa->pf, (cfe->flags & PCMCIA_CFE_IO16) ?
164 PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8, 0, cfe->iospace[0].length,
165 &psc->sc_pcioh, &psc->sc_io_window)) {
166 printf(": can't map i/o space\n");
167 return;
168 }
169
170 switch (pa->product) {
171 case PCMCIA_PRODUCT_TDK_LAK_CD021BX:
172 model = "TDK LAK-CD021BX Ethernet";
173 break;
174 case PCMCIA_PRODUCT_TDK_DFL9610:
175 model = "TDK DFL9610 Ethernet & Digital Cellular";
176 break;
177
178 default:
179 printf("%s: Unknown MB86960 PCMCIA ethernet card (%d)\n",
180 sc->sc_dev.dv_xname, pa->product);
181 panic("unknown card");
182 }
183 printf(": %s\n", model);
184
185 /* Read station address. */
186 pgea.got_enaddr = 0;
187 if (pcmcia_scan_cis(parent, mbe_pcmcia_get_enaddr, &pgea) == -1) {
188 printf("%s: Couldn't read CIS to get ethernet address\n",
189 sc->sc_dev.dv_xname);
190 return;
191 } else if (!pgea.got_enaddr) {
192 printf("%s: Couldn't get ethernet address from CIS\n",
193 sc->sc_dev.dv_xname);
194 return;
195 } else
196 #ifdef DIAGNOSTIC
197 printf("%s: Ethernet address from CIS: %s\n",
198 sc->sc_dev.dv_xname, ether_sprintf(pgea.enaddr))
199 #endif
200 ;
201
202 /* Perform generic initialization. */
203 mb86960_attach(sc, MB86960_TYPE_86965, pgea.enaddr);
204
205 mb86960_config(sc, NULL, 0, 0);
206
207 pcmcia_function_disable(pa->pf);
208 }
209
210 int
211 mbe_pcmcia_enable(sc)
212 struct mb86960_softc *sc;
213 {
214 struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)sc;
215
216 /* Establish the interrupt handler. */
217 psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, mb86960_intr,
218 sc);
219 if (psc->sc_ih == NULL) {
220 printf("%s: couldn't establish interrupt handler\n",
221 sc->sc_dev.dv_xname);
222 return (1);
223 }
224
225 return (pcmcia_function_enable(psc->sc_pf));
226 }
227
228 void
229 mbe_pcmcia_disable(sc)
230 struct mb86960_softc *sc;
231 {
232 struct mbe_pcmcia_softc *psc = (struct mbe_pcmcia_softc *)sc;
233
234 pcmcia_function_disable(psc->sc_pf);
235
236 pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
237 }
238
239 int
240 mbe_pcmcia_get_enaddr(tuple, arg)
241 struct pcmcia_tuple *tuple;
242 void *arg;
243 {
244 struct mbe_pcmcia_get_enaddr_args *p = arg;
245 int i;
246
247 if (tuple->code == PCMCIA_CISTPL_FUNCE) {
248 if (tuple->length < 2) /* sub code and ether addr length */
249 return (0);
250
251 if ((pcmcia_tuple_read_1(tuple, 0) !=
252 PCMCIA_TPLFE_TYPE_LAN_NID) ||
253 (pcmcia_tuple_read_1(tuple, 1) != ETHER_ADDR_LEN))
254 return (0);
255
256 for (i = 0; i < ETHER_ADDR_LEN; i++)
257 p->enaddr[i] = pcmcia_tuple_read_1(tuple, i + 2);
258 p->got_enaddr = 1;
259 return (1);
260 }
261 return (0);
262 }
263