if_elmc_mca.c revision 1.3.2.3 1 1.3.2.3 bouyer /* $NetBSD: if_elmc_mca.c,v 1.3.2.3 2001/04/21 17:48:53 bouyer Exp $ */
2 1.3.2.2 bouyer
3 1.3.2.2 bouyer /*-
4 1.3.2.2 bouyer * Copyright (c) 2001 The NetBSD Foundation, Inc.
5 1.3.2.2 bouyer * All rights reserved.
6 1.3.2.2 bouyer *
7 1.3.2.2 bouyer * This code is derived from software contributed to The NetBSD Foundation
8 1.3.2.2 bouyer * by Rafal K. Boni and Jaromir Dolecek.
9 1.3.2.2 bouyer *
10 1.3.2.2 bouyer * Redistribution and use in source and binary forms, with or without
11 1.3.2.2 bouyer * modification, are permitted provided that the following conditions
12 1.3.2.2 bouyer * are met:
13 1.3.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
14 1.3.2.2 bouyer * notice, this list of conditions and the following disclaimer.
15 1.3.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
16 1.3.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
17 1.3.2.2 bouyer * documentation and/or other materials provided with the distribution.
18 1.3.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
19 1.3.2.2 bouyer * must display the following acknowledgement:
20 1.3.2.2 bouyer * This product includes software developed by the NetBSD
21 1.3.2.2 bouyer * Foundation, Inc. and its contributors.
22 1.3.2.2 bouyer * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.3.2.2 bouyer * contributors may be used to endorse or promote products derived
24 1.3.2.2 bouyer * from this software without specific prior written permission.
25 1.3.2.2 bouyer *
26 1.3.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.3.2.2 bouyer * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.3.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.3.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.3.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.3.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.3.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.3.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.3.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.3.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.3.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
37 1.3.2.2 bouyer */
38 1.3.2.2 bouyer
39 1.3.2.2 bouyer /*
40 1.3.2.2 bouyer * 3Com 3c523 EtherLink/MC Ethernet card driver (uses i82586 Ethernet chip).
41 1.3.2.2 bouyer *
42 1.3.2.2 bouyer * The 3c523-specific hooks were derived from Linux driver (file
43 1.3.2.2 bouyer * drivers/net/3c523.[ch]).
44 1.3.2.2 bouyer *
45 1.3.2.2 bouyer * This driver uses generic i82586 stuff. See also ai(4), ef(4), ix(4).
46 1.3.2.2 bouyer */
47 1.3.2.2 bouyer
48 1.3.2.2 bouyer #include <sys/param.h>
49 1.3.2.2 bouyer #include <sys/systm.h>
50 1.3.2.2 bouyer #include <sys/mbuf.h>
51 1.3.2.2 bouyer #include <sys/errno.h>
52 1.3.2.2 bouyer #include <sys/device.h>
53 1.3.2.2 bouyer #include <sys/protosw.h>
54 1.3.2.2 bouyer #include <sys/socket.h>
55 1.3.2.2 bouyer
56 1.3.2.2 bouyer #include <net/if.h>
57 1.3.2.2 bouyer #include <net/if_types.h>
58 1.3.2.2 bouyer #include <net/if_media.h>
59 1.3.2.2 bouyer #include <net/if_ether.h>
60 1.3.2.2 bouyer
61 1.3.2.2 bouyer #include <machine/bus.h>
62 1.3.2.2 bouyer
63 1.3.2.2 bouyer #include <dev/ic/i82586reg.h>
64 1.3.2.2 bouyer #include <dev/ic/i82586var.h>
65 1.3.2.2 bouyer #include <dev/mca/mcadevs.h>
66 1.3.2.2 bouyer #include <dev/mca/mcavar.h>
67 1.3.2.2 bouyer
68 1.3.2.2 bouyer #include <dev/mca/3c523reg.h>
69 1.3.2.2 bouyer
70 1.3.2.2 bouyer struct elmc_mca_softc {
71 1.3.2.2 bouyer struct ie_softc sc_ie;
72 1.3.2.2 bouyer
73 1.3.2.2 bouyer bus_space_tag_t sc_regt; /* space tag for registers */
74 1.3.2.2 bouyer bus_space_handle_t sc_regh; /* space handle for registers */
75 1.3.2.2 bouyer
76 1.3.2.2 bouyer void *sc_ih; /* interrupt handle */
77 1.3.2.2 bouyer };
78 1.3.2.2 bouyer
79 1.3.2.2 bouyer int elmc_mca_match __P((struct device *, struct cfdata *, void *));
80 1.3.2.2 bouyer void elmc_mca_attach __P((struct device *, struct device *, void *));
81 1.3.2.2 bouyer
82 1.3.2.2 bouyer static void elmc_mca_copyin __P((struct ie_softc *, void *, int, size_t));
83 1.3.2.2 bouyer static void elmc_mca_copyout __P((struct ie_softc *, const void *, int, size_t));
84 1.3.2.2 bouyer static u_int16_t elmc_mca_read_16 __P((struct ie_softc *, int));
85 1.3.2.2 bouyer static void elmc_mca_write_16 __P((struct ie_softc *, int, u_int16_t));
86 1.3.2.2 bouyer static void elmc_mca_write_24 __P((struct ie_softc *, int, int));
87 1.3.2.2 bouyer static void elmc_mca_attn __P((struct ie_softc *, int));
88 1.3.2.2 bouyer static void elmc_mca_hwreset __P((struct ie_softc *, int));
89 1.3.2.2 bouyer static int elmc_mca_intrhook __P((struct ie_softc *, int));
90 1.3.2.2 bouyer
91 1.3.2.2 bouyer int
92 1.3.2.2 bouyer elmc_mca_match(struct device *parent, struct cfdata *cf, void *aux)
93 1.3.2.2 bouyer {
94 1.3.2.2 bouyer struct mca_attach_args *ma = aux;
95 1.3.2.2 bouyer
96 1.3.2.2 bouyer switch (ma->ma_id) {
97 1.3.2.2 bouyer case MCA_PRODUCT_3C523:
98 1.3.2.2 bouyer return 1;
99 1.3.2.2 bouyer }
100 1.3.2.2 bouyer
101 1.3.2.2 bouyer return 0;
102 1.3.2.2 bouyer }
103 1.3.2.2 bouyer
104 1.3.2.2 bouyer void
105 1.3.2.2 bouyer elmc_mca_attach(struct device *parent, struct device *self, void *aux)
106 1.3.2.2 bouyer {
107 1.3.2.2 bouyer struct elmc_mca_softc *asc = (void *) self;
108 1.3.2.2 bouyer struct ie_softc *sc = &asc->sc_ie;
109 1.3.2.2 bouyer struct mca_attach_args *ma = aux;
110 1.3.2.2 bouyer int pos2, pos3, i, revision;
111 1.3.2.2 bouyer int iobase, irq, pbram_addr;
112 1.3.2.2 bouyer bus_space_handle_t ioh, memh;
113 1.3.2.2 bouyer u_int8_t myaddr[ETHER_ADDR_LEN];
114 1.3.2.2 bouyer
115 1.3.2.2 bouyer printf(" slot %d: 3Com EtherLink/MC Ethernet Adapter (3C523)\n",
116 1.3.2.2 bouyer ma->ma_slot + 1);
117 1.3.2.2 bouyer
118 1.3.2.2 bouyer pos2 = mca_conf_read(ma->ma_mc, ma->ma_slot, 2);
119 1.3.2.2 bouyer pos3 = mca_conf_read(ma->ma_mc, ma->ma_slot, 3);
120 1.3.2.2 bouyer
121 1.3.2.2 bouyer /*
122 1.3.2.2 bouyer * POS register 2: (adf pos0)
123 1.3.2.2 bouyer *
124 1.3.2.2 bouyer * 7 6 5 4 3 2 1 0
125 1.3.2.2 bouyer * \ \_/ \_/ \__ enable: 0=adapter disabled, 1=adapter enabled
126 1.3.2.2 bouyer * \ \ \____ I/O Address Range: 00=300-307, 01=1300-1307,
127 1.3.2.2 bouyer * \ \ 10=2300-2307, 11=3300-3307
128 1.3.2.2 bouyer * \ \______ Packet Buffer RAM Address Range:
129 1.3.2.2 bouyer * \ 00=0x0c0000-0x0c5fff 01=0x0c8000-0x0cdfff
130 1.3.2.2 bouyer * \ 10=0x0d0000-0x0d5fff 11=0x0d8000-0x0ddfff
131 1.3.2.2 bouyer * \______ Transceiver Type: 0=onboard(BNC) 1=ext(DIX)
132 1.3.2.2 bouyer *
133 1.3.2.2 bouyer * POS register 3: (adf pos1)
134 1.3.2.2 bouyer *
135 1.3.2.2 bouyer * 7 6 5 4 3 2 1 0
136 1.3.2.2 bouyer * \____/
137 1.3.2.2 bouyer * \__ Interrupt level: 0100=3, 0010=7, 1000=9, 0001=12
138 1.3.2.2 bouyer */
139 1.3.2.2 bouyer
140 1.3.2.2 bouyer iobase = ELMC_IOADDR_BASE + (0x1000 * ((pos2 & 0x6) >> 1));
141 1.3.2.2 bouyer
142 1.3.2.2 bouyer /* get irq */
143 1.3.2.2 bouyer switch (pos3 & 0x1f) {
144 1.3.2.2 bouyer case 4: irq = 3; break;
145 1.3.2.2 bouyer case 2: irq = 7; break;
146 1.3.2.2 bouyer case 8: irq = 9; break;
147 1.3.2.2 bouyer case 1: irq = 12; break;
148 1.3.2.2 bouyer }
149 1.3.2.2 bouyer
150 1.3.2.2 bouyer pbram_addr = ELMC_MADDR_BASE + (((pos2 & 24) >> 3) * 0x8000);
151 1.3.2.2 bouyer
152 1.3.2.2 bouyer /* map the pio registers */
153 1.3.2.2 bouyer if (bus_space_map(ma->ma_iot, iobase, ELMC_IOADDR_SIZE, 0, &ioh)) {
154 1.3.2.2 bouyer printf("%s: unable to map i/o space\n", sc->sc_dev.dv_xname);
155 1.3.2.2 bouyer return;
156 1.3.2.2 bouyer }
157 1.3.2.2 bouyer
158 1.3.2.2 bouyer /*
159 1.3.2.2 bouyer * 3c523 has a 24K memory. The first 16K is the shared memory, while
160 1.3.2.2 bouyer * the last 8K is for the EtherStart BIOS ROM, which we don't care
161 1.3.2.2 bouyer * about. Just use the first 16K.
162 1.3.2.2 bouyer */
163 1.3.2.2 bouyer if (bus_space_map(ma->ma_memt, pbram_addr, ELMC_MADDR_SIZE, 0, &memh)) {
164 1.3.2.2 bouyer printf("%s: unable to map memory space\n", sc->sc_dev.dv_xname);
165 1.3.2.2 bouyer if (pbram_addr == 0xc0000) {
166 1.3.2.2 bouyer printf("%s: memory space 0xc0000 may conflict with vga\n",
167 1.3.2.2 bouyer sc->sc_dev.dv_xname);
168 1.3.2.2 bouyer }
169 1.3.2.2 bouyer
170 1.3.2.2 bouyer bus_space_unmap(ma->ma_iot, ioh, ELMC_IOADDR_SIZE);
171 1.3.2.2 bouyer return;
172 1.3.2.2 bouyer }
173 1.3.2.2 bouyer
174 1.3.2.2 bouyer asc->sc_regt = ma->ma_iot;
175 1.3.2.2 bouyer asc->sc_regh = ioh;
176 1.3.2.2 bouyer
177 1.3.2.2 bouyer sc->hwinit = NULL;
178 1.3.2.2 bouyer sc->intrhook = elmc_mca_intrhook;
179 1.3.2.2 bouyer sc->hwreset = elmc_mca_hwreset;
180 1.3.2.2 bouyer sc->chan_attn = elmc_mca_attn;
181 1.3.2.2 bouyer
182 1.3.2.2 bouyer sc->ie_bus_barrier = NULL;
183 1.3.2.2 bouyer
184 1.3.2.2 bouyer sc->memcopyin = elmc_mca_copyin;
185 1.3.2.2 bouyer sc->memcopyout = elmc_mca_copyout;
186 1.3.2.2 bouyer sc->ie_bus_read16 = elmc_mca_read_16;
187 1.3.2.2 bouyer sc->ie_bus_write16 = elmc_mca_write_16;
188 1.3.2.2 bouyer sc->ie_bus_write24 = elmc_mca_write_24;
189 1.3.2.2 bouyer
190 1.3.2.2 bouyer sc->do_xmitnopchain = 0;
191 1.3.2.2 bouyer
192 1.3.2.2 bouyer sc->sc_mediachange = NULL;
193 1.3.2.2 bouyer sc->sc_mediastatus = NULL;
194 1.3.2.2 bouyer
195 1.3.2.2 bouyer sc->bt = ma->ma_memt;
196 1.3.2.2 bouyer sc->bh = memh;
197 1.3.2.2 bouyer
198 1.3.2.2 bouyer /* Map i/o space. */
199 1.3.2.2 bouyer sc->sc_msize = ELMC_MADDR_SIZE;
200 1.3.2.2 bouyer sc->sc_maddr = (void *)memh;
201 1.3.2.2 bouyer sc->sc_iobase = (char *)sc->sc_maddr + sc->sc_msize - (1 << 24);
202 1.3.2.2 bouyer
203 1.3.2.2 bouyer /* set up pointers to important on-card control structures */
204 1.3.2.2 bouyer sc->iscp = 0;
205 1.3.2.2 bouyer sc->scb = IE_ISCP_SZ;
206 1.3.2.2 bouyer sc->scp = sc->sc_msize + IE_SCP_ADDR - (1 << 24);
207 1.3.2.2 bouyer
208 1.3.2.2 bouyer sc->buf_area = sc->scb + IE_SCB_SZ;
209 1.3.2.2 bouyer sc->buf_area_sz = sc->sc_msize - IE_ISCP_SZ - IE_SCB_SZ - IE_SCP_SZ;
210 1.3.2.2 bouyer
211 1.3.2.2 bouyer /*
212 1.3.2.2 bouyer * According to docs, we might need to read the interrupt number and
213 1.3.2.2 bouyer * write it back to the IRQ select register, since the POST might not
214 1.3.2.2 bouyer * configure the IRQ properly.
215 1.3.2.2 bouyer */
216 1.3.2.2 bouyer (void) mca_conf_write(ma->ma_mc, ma->ma_slot, 3, pos3 & 0x1f);
217 1.3.2.2 bouyer
218 1.3.2.2 bouyer /* reset the card first */
219 1.3.2.2 bouyer elmc_mca_hwreset(sc, CARD_RESET);
220 1.3.2.2 bouyer delay(1000000 / ( 1<< 5));
221 1.3.2.2 bouyer
222 1.3.2.2 bouyer /* zero card memory */
223 1.3.2.2 bouyer bus_space_set_region_1(sc->bt, sc->bh, 0, 0, sc->sc_msize);
224 1.3.2.2 bouyer
225 1.3.2.2 bouyer /* set card to 16-bit bus mode */
226 1.3.2.2 bouyer bus_space_write_1(sc->bt, sc->bh, IE_SCP_BUS_USE((u_long)sc->scp), 0);
227 1.3.2.2 bouyer
228 1.3.2.2 bouyer /* set up pointers to key structures */
229 1.3.2.2 bouyer elmc_mca_write_24(sc, IE_SCP_ISCP((u_long)sc->scp), (u_long) sc->iscp);
230 1.3.2.2 bouyer elmc_mca_write_16(sc, IE_ISCP_SCB((u_long)sc->iscp), (u_long) sc->scb);
231 1.3.2.2 bouyer elmc_mca_write_24(sc, IE_ISCP_BASE((u_long)sc->iscp), (u_long) sc->iscp);
232 1.3.2.2 bouyer
233 1.3.2.2 bouyer /* flush setup of pointers, check if chip answers */
234 1.3.2.2 bouyer bus_space_barrier(sc->bt, sc->bh, 0, sc->sc_msize,
235 1.3.2.2 bouyer BUS_SPACE_BARRIER_WRITE);
236 1.3.2.2 bouyer if (!i82586_proberam(sc)) {
237 1.3.2.2 bouyer printf("%s: can't talk to i82586!\n", sc->sc_dev.dv_xname);
238 1.3.2.2 bouyer
239 1.3.2.2 bouyer bus_space_unmap(asc->sc_regt, asc->sc_regh, ELMC_IOADDR_SIZE);
240 1.3.2.2 bouyer bus_space_unmap(sc->bt, sc->bh, ELMC_MADDR_SIZE);
241 1.3.2.2 bouyer return;
242 1.3.2.2 bouyer }
243 1.3.2.2 bouyer
244 1.3.2.2 bouyer /* revision is stored in the first 4 bits of the revision register */
245 1.3.2.2 bouyer revision = (int) bus_space_read_1(asc->sc_regt, asc->sc_regh,
246 1.3.2.2 bouyer ELMC_REVISION) & ELMC_REVISION_MASK;
247 1.3.2.2 bouyer
248 1.3.2.2 bouyer /* dump known info */
249 1.3.2.2 bouyer printf("%s: rev %d, i/o %#04x-%#04x, mem %#06x-%#06x, %sternal xcvr\n",
250 1.3.2.2 bouyer sc->sc_dev.dv_xname, revision,
251 1.3.2.2 bouyer iobase, iobase + ELMC_IOADDR_SIZE - 1,
252 1.3.2.2 bouyer pbram_addr, pbram_addr + ELMC_MADDR_SIZE - 1,
253 1.3.2.2 bouyer (pos2 & 0x20) ? "ex" : "in");
254 1.3.2.2 bouyer
255 1.3.2.2 bouyer /*
256 1.3.2.2 bouyer * Hardware ethernet address is stored in the first six bytes
257 1.3.2.2 bouyer * of the IO space.
258 1.3.2.2 bouyer */
259 1.3.2.2 bouyer for(i=0; i < MIN(6, ETHER_ADDR_LEN); i++)
260 1.3.2.2 bouyer myaddr[i] = bus_space_read_1(asc->sc_regt, asc->sc_regh, i);
261 1.3.2.2 bouyer
262 1.3.2.2 bouyer printf("%s:", sc->sc_dev.dv_xname);
263 1.3.2.2 bouyer i82586_attach((void *)sc, "3C523", myaddr, NULL, 0, 0);
264 1.3.2.2 bouyer
265 1.3.2.2 bouyer /* establish interrupt handler */
266 1.3.2.2 bouyer asc->sc_ih = mca_intr_establish(ma->ma_mc, irq, IPL_NET, i82586_intr,
267 1.3.2.2 bouyer sc);
268 1.3.2.2 bouyer if (asc->sc_ih == NULL)
269 1.3.2.2 bouyer printf("%s: couldn't establish interrupt handler\n",
270 1.3.2.2 bouyer sc->sc_dev.dv_xname);
271 1.3.2.2 bouyer else
272 1.3.2.2 bouyer printf("%s: interrupting at irq %d\n", sc->sc_dev.dv_xname,irq);
273 1.3.2.2 bouyer
274 1.3.2.2 bouyer return;
275 1.3.2.2 bouyer }
276 1.3.2.2 bouyer
277 1.3.2.2 bouyer static void
278 1.3.2.2 bouyer elmc_mca_copyin (sc, dst, offset, size)
279 1.3.2.2 bouyer struct ie_softc *sc;
280 1.3.2.2 bouyer void *dst;
281 1.3.2.2 bouyer int offset;
282 1.3.2.2 bouyer size_t size;
283 1.3.2.2 bouyer {
284 1.3.2.2 bouyer int dribble;
285 1.3.2.2 bouyer u_int8_t* bptr = dst;
286 1.3.2.2 bouyer
287 1.3.2.2 bouyer bus_space_barrier(sc->bt, sc->bh, offset, size,
288 1.3.2.2 bouyer BUS_SPACE_BARRIER_READ);
289 1.3.2.2 bouyer
290 1.3.2.2 bouyer if (offset % 2) {
291 1.3.2.2 bouyer *bptr = bus_space_read_1(sc->bt, sc->bh, offset);
292 1.3.2.2 bouyer offset++; bptr++; size--;
293 1.3.2.2 bouyer }
294 1.3.2.2 bouyer
295 1.3.2.2 bouyer dribble = size % 2;
296 1.3.2.2 bouyer bus_space_read_region_2(sc->bt, sc->bh, offset, (u_int16_t *) bptr,
297 1.3.2.2 bouyer size >> 1);
298 1.3.2.2 bouyer
299 1.3.2.2 bouyer if (dribble) {
300 1.3.2.2 bouyer bptr += size - 1;
301 1.3.2.2 bouyer offset += size - 1;
302 1.3.2.2 bouyer *bptr = bus_space_read_1(sc->bt, sc->bh, offset);
303 1.3.2.2 bouyer }
304 1.3.2.2 bouyer }
305 1.3.2.2 bouyer
306 1.3.2.2 bouyer static void
307 1.3.2.2 bouyer elmc_mca_copyout (sc, src, offset, size)
308 1.3.2.2 bouyer struct ie_softc *sc;
309 1.3.2.2 bouyer const void *src;
310 1.3.2.2 bouyer int offset;
311 1.3.2.2 bouyer size_t size;
312 1.3.2.2 bouyer {
313 1.3.2.2 bouyer int dribble;
314 1.3.2.2 bouyer int osize = size;
315 1.3.2.2 bouyer int ooffset = offset;
316 1.3.2.2 bouyer const u_int8_t* bptr = src;
317 1.3.2.2 bouyer
318 1.3.2.2 bouyer if (offset % 2) {
319 1.3.2.2 bouyer bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
320 1.3.2.2 bouyer offset++; bptr++; size--;
321 1.3.2.2 bouyer }
322 1.3.2.2 bouyer
323 1.3.2.2 bouyer dribble = size % 2;
324 1.3.2.2 bouyer bus_space_write_region_2(sc->bt, sc->bh, offset, (u_int16_t *)bptr,
325 1.3.2.2 bouyer size >> 1);
326 1.3.2.2 bouyer if (dribble) {
327 1.3.2.2 bouyer bptr += size - 1;
328 1.3.2.2 bouyer offset += size - 1;
329 1.3.2.2 bouyer bus_space_write_1(sc->bt, sc->bh, offset, *bptr);
330 1.3.2.2 bouyer }
331 1.3.2.2 bouyer
332 1.3.2.2 bouyer bus_space_barrier(sc->bt, sc->bh, ooffset, osize,
333 1.3.2.2 bouyer BUS_SPACE_BARRIER_WRITE);
334 1.3.2.2 bouyer }
335 1.3.2.2 bouyer
336 1.3.2.2 bouyer static u_int16_t
337 1.3.2.2 bouyer elmc_mca_read_16 (sc, offset)
338 1.3.2.2 bouyer struct ie_softc *sc;
339 1.3.2.2 bouyer int offset;
340 1.3.2.2 bouyer {
341 1.3.2.2 bouyer bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_READ);
342 1.3.2.2 bouyer return bus_space_read_2(sc->bt, sc->bh, offset);
343 1.3.2.2 bouyer }
344 1.3.2.2 bouyer
345 1.3.2.2 bouyer static void
346 1.3.2.2 bouyer elmc_mca_write_16 (sc, offset, value)
347 1.3.2.2 bouyer struct ie_softc *sc;
348 1.3.2.2 bouyer int offset;
349 1.3.2.2 bouyer u_int16_t value;
350 1.3.2.2 bouyer {
351 1.3.2.2 bouyer bus_space_write_2(sc->bt, sc->bh, offset, value);
352 1.3.2.2 bouyer bus_space_barrier(sc->bt, sc->bh, offset, 2, BUS_SPACE_BARRIER_WRITE);
353 1.3.2.2 bouyer }
354 1.3.2.2 bouyer
355 1.3.2.2 bouyer static void
356 1.3.2.2 bouyer elmc_mca_write_24 (sc, offset, addr)
357 1.3.2.2 bouyer struct ie_softc *sc;
358 1.3.2.2 bouyer int offset, addr;
359 1.3.2.2 bouyer {
360 1.3.2.2 bouyer bus_space_write_4(sc->bt, sc->bh, offset, addr +
361 1.3.2.2 bouyer (u_long) sc->sc_maddr - (u_long) sc->sc_iobase);
362 1.3.2.2 bouyer bus_space_barrier(sc->bt, sc->bh, offset, 4, BUS_SPACE_BARRIER_WRITE);
363 1.3.2.2 bouyer }
364 1.3.2.2 bouyer
365 1.3.2.2 bouyer /*
366 1.3.2.2 bouyer * Channel attention hook.
367 1.3.2.2 bouyer */
368 1.3.2.2 bouyer static void
369 1.3.2.2 bouyer elmc_mca_attn(sc, why)
370 1.3.2.2 bouyer struct ie_softc *sc;
371 1.3.2.2 bouyer int why;
372 1.3.2.2 bouyer {
373 1.3.2.2 bouyer struct elmc_mca_softc* asc = (struct elmc_mca_softc *) sc;
374 1.3.2.2 bouyer int intr = 0;
375 1.3.2.2 bouyer
376 1.3.2.2 bouyer switch (why) {
377 1.3.2.2 bouyer case CHIP_PROBE:
378 1.3.2.2 bouyer intr = 0;
379 1.3.2.2 bouyer break;
380 1.3.2.2 bouyer case CARD_RESET:
381 1.3.2.2 bouyer intr = ELMC_CTRL_INT;
382 1.3.2.2 bouyer break;
383 1.3.2.2 bouyer }
384 1.3.2.2 bouyer
385 1.3.2.2 bouyer bus_space_write_1(asc->sc_regt, asc->sc_regh, ELMC_CTRL,
386 1.3.2.2 bouyer ELMC_CTRL_RST | ELMC_CTRL_BS3 | ELMC_CTRL_CHA | intr);
387 1.3.2.2 bouyer delay(16); /* should be > 500 ns */
388 1.3.2.2 bouyer bus_space_write_1(asc->sc_regt, asc->sc_regh, ELMC_CTRL,
389 1.3.2.2 bouyer ELMC_CTRL_RST | ELMC_CTRL_BS3 | intr);
390 1.3.2.2 bouyer }
391 1.3.2.2 bouyer
392 1.3.2.2 bouyer /*
393 1.3.2.2 bouyer * Do full card hardware reset.
394 1.3.2.2 bouyer */
395 1.3.2.2 bouyer static void
396 1.3.2.2 bouyer elmc_mca_hwreset(sc, why)
397 1.3.2.2 bouyer struct ie_softc *sc;
398 1.3.2.2 bouyer int why;
399 1.3.2.2 bouyer {
400 1.3.2.2 bouyer struct elmc_mca_softc* asc = (struct elmc_mca_softc *) sc;
401 1.3.2.2 bouyer int intr = 0;
402 1.3.2.2 bouyer
403 1.3.2.2 bouyer switch (why) {
404 1.3.2.2 bouyer case CHIP_PROBE:
405 1.3.2.2 bouyer intr = 0;
406 1.3.2.2 bouyer break;
407 1.3.2.2 bouyer case CARD_RESET:
408 1.3.2.2 bouyer intr = ELMC_CTRL_INT;
409 1.3.2.2 bouyer break;
410 1.3.2.2 bouyer }
411 1.3.2.2 bouyer
412 1.3.2.2 bouyer /* toggle the RST bit low then high */
413 1.3.2.2 bouyer bus_space_write_1(asc->sc_regt, asc->sc_regh, ELMC_CTRL,
414 1.3.2.2 bouyer ELMC_CTRL_BS3 | ELMC_CTRL_LOOP);
415 1.3.2.2 bouyer delay(16); /* should be > 500 ns */
416 1.3.2.2 bouyer bus_space_write_1(asc->sc_regt, asc->sc_regh, ELMC_CTRL,
417 1.3.2.2 bouyer ELMC_CTRL_BS3 | ELMC_CTRL_LOOP | ELMC_CTRL_RST);
418 1.3.2.2 bouyer
419 1.3.2.2 bouyer elmc_mca_attn(sc, why);
420 1.3.2.2 bouyer }
421 1.3.2.2 bouyer
422 1.3.2.2 bouyer /*
423 1.3.2.2 bouyer * Interrupt hook.
424 1.3.2.2 bouyer */
425 1.3.2.2 bouyer static int
426 1.3.2.2 bouyer elmc_mca_intrhook(sc, why)
427 1.3.2.2 bouyer struct ie_softc *sc;
428 1.3.2.2 bouyer int why;
429 1.3.2.2 bouyer {
430 1.3.2.2 bouyer switch (why) {
431 1.3.2.2 bouyer case INTR_ACK:
432 1.3.2.2 bouyer elmc_mca_attn(sc, CHIP_PROBE);
433 1.3.2.2 bouyer break;
434 1.3.2.2 bouyer default:
435 1.3.2.2 bouyer /* do nothing */
436 1.3.2.2 bouyer break;
437 1.3.2.2 bouyer }
438 1.3.2.2 bouyer
439 1.3.2.2 bouyer return (0);
440 1.3.2.2 bouyer }
441 1.3.2.2 bouyer
442 1.3.2.2 bouyer struct cfattach elmc_mca_ca = {
443 1.3.2.2 bouyer sizeof(struct elmc_mca_softc), elmc_mca_match, elmc_mca_attach
444 1.3.2.2 bouyer };
445