if_ie_mvme.c revision 1.6 1 1.6 lukem /* $NetBSD: if_ie_mvme.c,v 1.6 2003/07/14 15:47:19 lukem Exp $ */
2 1.1 scw
3 1.1 scw /*-
4 1.1 scw * Copyright (c) 1999, 2002 The NetBSD Foundation, Inc.
5 1.1 scw * All rights reserved.
6 1.1 scw *
7 1.1 scw * This code is derived from software contributed to The NetBSD Foundation
8 1.1 scw * by Steve C. Woodford.
9 1.1 scw *
10 1.1 scw * Redistribution and use in source and binary forms, with or without
11 1.1 scw * modification, are permitted provided that the following conditions
12 1.1 scw * are met:
13 1.1 scw * 1. Redistributions of source code must retain the above copyright
14 1.1 scw * notice, this list of conditions and the following disclaimer.
15 1.1 scw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 scw * notice, this list of conditions and the following disclaimer in the
17 1.1 scw * documentation and/or other materials provided with the distribution.
18 1.1 scw * 3. All advertising materials mentioning features or use of this software
19 1.1 scw * must display the following acknowledgement:
20 1.1 scw * This product includes software developed by the NetBSD
21 1.1 scw * Foundation, Inc. and its contributors.
22 1.1 scw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 scw * contributors may be used to endorse or promote products derived
24 1.1 scw * from this software without specific prior written permission.
25 1.1 scw *
26 1.1 scw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 scw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 scw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 scw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 scw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 scw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 scw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 scw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 scw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 scw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 scw * POSSIBILITY OF SUCH DAMAGE.
37 1.1 scw */
38 1.6 lukem
39 1.6 lukem #include <sys/cdefs.h>
40 1.6 lukem __KERNEL_RCSID(0, "$NetBSD: if_ie_mvme.c,v 1.6 2003/07/14 15:47:19 lukem Exp $");
41 1.1 scw
42 1.1 scw #include <sys/param.h>
43 1.1 scw #include <sys/systm.h>
44 1.1 scw #include <sys/mbuf.h>
45 1.1 scw #include <sys/errno.h>
46 1.1 scw #include <sys/device.h>
47 1.1 scw #include <sys/protosw.h>
48 1.1 scw #include <sys/socket.h>
49 1.1 scw
50 1.1 scw #include <net/if.h>
51 1.1 scw #include <net/if_dl.h>
52 1.1 scw #include <net/if_types.h>
53 1.1 scw #include <net/if_ether.h>
54 1.1 scw #include <net/if_media.h>
55 1.1 scw
56 1.1 scw #include <uvm/uvm_extern.h>
57 1.1 scw
58 1.1 scw #include <machine/autoconf.h>
59 1.1 scw #include <machine/cpu.h>
60 1.1 scw #include <machine/bus.h>
61 1.1 scw
62 1.1 scw #include <dev/ic/i82586reg.h>
63 1.1 scw #include <dev/ic/i82586var.h>
64 1.1 scw
65 1.1 scw #include <dev/mvme/if_iereg.h>
66 1.1 scw #include <dev/mvme/pcctwovar.h>
67 1.1 scw #include <dev/mvme/pcctworeg.h>
68 1.1 scw
69 1.1 scw
70 1.1 scw int ie_pcctwo_match __P((struct device *, struct cfdata *, void *));
71 1.1 scw void ie_pcctwo_attach __P((struct device *, struct device *, void *));
72 1.1 scw
73 1.1 scw struct ie_pcctwo_softc {
74 1.1 scw struct ie_softc ps_ie;
75 1.1 scw bus_space_tag_t ps_bust;
76 1.1 scw bus_space_handle_t ps_bush;
77 1.1 scw struct evcnt ps_evcnt;
78 1.1 scw };
79 1.1 scw
80 1.3 thorpej CFATTACH_DECL(ie_pcctwo, sizeof(struct ie_pcctwo_softc),
81 1.4 thorpej ie_pcctwo_match, ie_pcctwo_attach, NULL, NULL);
82 1.1 scw
83 1.1 scw extern struct cfdriver ie_cd;
84 1.1 scw
85 1.1 scw
86 1.1 scw /* Functions required by the i82586 MI driver */
87 1.1 scw static void ie_reset __P((struct ie_softc *, int));
88 1.1 scw static int ie_intrhook __P((struct ie_softc *, int));
89 1.1 scw static void ie_hwinit __P((struct ie_softc *));
90 1.1 scw static void ie_atten __P((struct ie_softc *, int));
91 1.1 scw
92 1.1 scw static void ie_copyin __P((struct ie_softc *, void *, int, size_t));
93 1.1 scw static void ie_copyout __P((struct ie_softc *, const void *, int, size_t));
94 1.1 scw
95 1.1 scw static u_int16_t ie_read_16 __P((struct ie_softc *, int));
96 1.1 scw static void ie_write_16 __P((struct ie_softc *, int, u_int16_t));
97 1.1 scw static void ie_write_24 __P((struct ie_softc *, int, int));
98 1.1 scw
99 1.1 scw /*
100 1.1 scw * i82596 Support Routines for MVME1[67][27] and MVME187 Boards
101 1.1 scw */
102 1.1 scw static void
103 1.1 scw ie_reset(sc, why)
104 1.1 scw struct ie_softc *sc;
105 1.1 scw int why;
106 1.1 scw {
107 1.1 scw struct ie_pcctwo_softc *ps;
108 1.1 scw u_int32_t scp_addr;
109 1.1 scw
110 1.1 scw ps = (struct ie_pcctwo_softc *) sc;
111 1.1 scw
112 1.1 scw switch (why) {
113 1.1 scw case CHIP_PROBE:
114 1.1 scw case CARD_RESET:
115 1.1 scw bus_space_write_2(ps->ps_bust, ps->ps_bush, IE_MPUREG_UPPER,
116 1.1 scw IE_PORT_RESET);
117 1.1 scw bus_space_write_2(ps->ps_bust, ps->ps_bush, IE_MPUREG_LOWER, 0);
118 1.1 scw delay(1000);
119 1.1 scw
120 1.1 scw /*
121 1.1 scw * Set the BUSY and BUS_USE bytes here, since the MI code
122 1.1 scw * incorrectly assumes it can use byte addressing to set it.
123 1.1 scw * (due to wrong-endianess of the chip)
124 1.1 scw */
125 1.1 scw ie_write_16(sc, IE_ISCP_BUSY(sc->iscp), 1);
126 1.1 scw ie_write_16(sc, IE_SCP_BUS_USE(sc->scp), IE_BUS_USE);
127 1.1 scw
128 1.1 scw scp_addr = sc->scp + (u_int) sc->sc_iobase;
129 1.1 scw scp_addr |= IE_PORT_ALT_SCP;
130 1.1 scw
131 1.1 scw bus_space_write_2(ps->ps_bust, ps->ps_bush, IE_MPUREG_UPPER,
132 1.1 scw scp_addr & 0xffff);
133 1.1 scw bus_space_write_2(ps->ps_bust, ps->ps_bush, IE_MPUREG_LOWER,
134 1.1 scw (scp_addr >> 16) & 0xffff);
135 1.1 scw delay(1000);
136 1.1 scw break;
137 1.1 scw }
138 1.1 scw }
139 1.1 scw
140 1.1 scw /* ARGSUSED */
141 1.1 scw static int
142 1.1 scw ie_intrhook(sc, when)
143 1.1 scw struct ie_softc *sc;
144 1.1 scw int when;
145 1.1 scw {
146 1.1 scw struct ie_pcctwo_softc *ps;
147 1.1 scw u_int8_t reg;
148 1.1 scw
149 1.1 scw ps = (struct ie_pcctwo_softc *) sc;
150 1.1 scw
151 1.1 scw if (when == INTR_EXIT) {
152 1.1 scw reg = pcc2_reg_read(sys_pcctwo, PCC2REG_ETH_ICSR);
153 1.1 scw reg |= PCCTWO_ICR_ICLR;
154 1.1 scw pcc2_reg_write(sys_pcctwo, PCC2REG_ETH_ICSR, reg);
155 1.1 scw }
156 1.1 scw return (0);
157 1.1 scw }
158 1.1 scw
159 1.1 scw /* ARGSUSED */
160 1.1 scw static void
161 1.1 scw ie_hwinit(sc)
162 1.1 scw struct ie_softc *sc;
163 1.1 scw {
164 1.1 scw u_int8_t reg;
165 1.1 scw
166 1.1 scw reg = pcc2_reg_read(sys_pcctwo, PCC2REG_ETH_ICSR);
167 1.1 scw reg |= PCCTWO_ICR_IEN | PCCTWO_ICR_ICLR;
168 1.1 scw pcc2_reg_write(sys_pcctwo, PCC2REG_ETH_ICSR, reg);
169 1.1 scw }
170 1.1 scw
171 1.1 scw /* ARGSUSED */
172 1.1 scw static void
173 1.1 scw ie_atten(sc, reason)
174 1.1 scw struct ie_softc *sc;
175 1.1 scw int reason;
176 1.1 scw {
177 1.1 scw struct ie_pcctwo_softc *ps;
178 1.1 scw
179 1.1 scw ps = (struct ie_pcctwo_softc *) sc;
180 1.1 scw bus_space_write_4(ps->ps_bust, ps->ps_bush, IE_MPUREG_CA, 0);
181 1.1 scw }
182 1.1 scw
183 1.1 scw static void
184 1.1 scw ie_copyin(sc, dst, offset, size)
185 1.1 scw struct ie_softc *sc;
186 1.1 scw void *dst;
187 1.1 scw int offset;
188 1.1 scw size_t size;
189 1.1 scw {
190 1.1 scw if (size == 0) /* This *can* happen! */
191 1.1 scw return;
192 1.1 scw
193 1.1 scw #if 0
194 1.1 scw bus_space_read_region_1(sc->bt, sc->bh, offset, dst, size);
195 1.1 scw #else
196 1.1 scw /* A minor optimisation ;-) */
197 1.1 scw memcpy(dst, (void *) ((u_long) sc->bh + (u_long) offset), size);
198 1.1 scw #endif
199 1.1 scw }
200 1.1 scw
201 1.1 scw static void
202 1.1 scw ie_copyout(sc, src, offset, size)
203 1.1 scw struct ie_softc *sc;
204 1.1 scw const void *src;
205 1.1 scw int offset;
206 1.1 scw size_t size;
207 1.1 scw {
208 1.1 scw if (size == 0) /* This *can* happen! */
209 1.1 scw return;
210 1.1 scw
211 1.1 scw #if 0
212 1.1 scw bus_space_write_region_1(sc->bt, sc->bh, offset, src, size);
213 1.1 scw #else
214 1.1 scw /* A minor optimisation ;-) */
215 1.1 scw memcpy((void *) ((u_long) sc->bh + (u_long) offset), src, size);
216 1.1 scw #endif
217 1.1 scw }
218 1.1 scw
219 1.1 scw static u_int16_t
220 1.1 scw ie_read_16(sc, offset)
221 1.1 scw struct ie_softc *sc;
222 1.1 scw int offset;
223 1.1 scw {
224 1.1 scw
225 1.1 scw return (bus_space_read_2(sc->bt, sc->bh, offset));
226 1.1 scw }
227 1.1 scw
228 1.1 scw static void
229 1.1 scw ie_write_16(sc, offset, value)
230 1.1 scw struct ie_softc *sc;
231 1.1 scw int offset;
232 1.1 scw u_int16_t value;
233 1.1 scw {
234 1.1 scw
235 1.1 scw bus_space_write_2(sc->bt, sc->bh, offset, value);
236 1.1 scw }
237 1.1 scw
238 1.1 scw static void
239 1.1 scw ie_write_24(sc, offset, addr)
240 1.1 scw struct ie_softc *sc;
241 1.1 scw int offset;
242 1.1 scw int addr;
243 1.1 scw {
244 1.1 scw
245 1.1 scw addr += (int) sc->sc_iobase;
246 1.1 scw
247 1.1 scw bus_space_write_2(sc->bt, sc->bh, offset, addr & 0xffff);
248 1.1 scw bus_space_write_2(sc->bt, sc->bh, offset + 2, (addr >> 16) & 0x00ff);
249 1.1 scw }
250 1.1 scw
251 1.1 scw /* ARGSUSED */
252 1.1 scw int
253 1.1 scw ie_pcctwo_match(parent, cf, args)
254 1.1 scw struct device *parent;
255 1.1 scw struct cfdata *cf;
256 1.1 scw void *args;
257 1.1 scw {
258 1.1 scw struct pcctwo_attach_args *pa;
259 1.1 scw
260 1.1 scw pa = args;
261 1.1 scw
262 1.1 scw if (strcmp(pa->pa_name, ie_cd.cd_name))
263 1.1 scw return (0);
264 1.1 scw
265 1.1 scw pa->pa_ipl = cf->pcctwocf_ipl;
266 1.1 scw
267 1.1 scw return (1);
268 1.1 scw }
269 1.1 scw
270 1.1 scw /* ARGSUSED */
271 1.1 scw void
272 1.1 scw ie_pcctwo_attach(parent, self, args)
273 1.1 scw struct device *parent;
274 1.1 scw struct device *self;
275 1.1 scw void *args;
276 1.1 scw {
277 1.1 scw struct pcctwo_attach_args *pa;
278 1.1 scw struct ie_pcctwo_softc *ps;
279 1.1 scw struct ie_softc *sc;
280 1.1 scw bus_dma_segment_t seg;
281 1.1 scw int rseg;
282 1.1 scw
283 1.1 scw pa = (struct pcctwo_attach_args *) args;
284 1.1 scw ps = (struct ie_pcctwo_softc *) self;
285 1.1 scw sc = (struct ie_softc *) self;
286 1.1 scw
287 1.1 scw /* Map the MPU controller registers in PCCTWO space */
288 1.1 scw ps->ps_bust = pa->pa_bust;
289 1.1 scw bus_space_map(pa->pa_bust, pa->pa_offset, IE_MPUREG_SIZE,
290 1.1 scw 0, &ps->ps_bush);
291 1.1 scw
292 1.1 scw /* Get contiguous DMA-able memory for the IE chip */
293 1.5 thorpej if (bus_dmamem_alloc(pa->pa_dmat, ether_data_buff_size, PAGE_SIZE, 0,
294 1.1 scw &seg, 1, &rseg,
295 1.1 scw BUS_DMA_NOWAIT | BUS_DMA_ONBOARD_RAM | BUS_DMA_24BIT) != 0) {
296 1.1 scw printf("%s: Failed to allocate ether buffer\n", self->dv_xname);
297 1.1 scw return;
298 1.1 scw }
299 1.1 scw if (bus_dmamem_map(pa->pa_dmat, &seg, rseg, ether_data_buff_size,
300 1.1 scw (caddr_t *) & sc->sc_maddr, BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) {
301 1.1 scw printf("%s: Failed to map ether buffer\n", self->dv_xname);
302 1.1 scw bus_dmamem_free(pa->pa_dmat, &seg, rseg);
303 1.1 scw return;
304 1.1 scw }
305 1.1 scw sc->bt = pa->pa_bust;
306 1.1 scw sc->bh = (bus_space_handle_t) sc->sc_maddr; /* XXXSCW Better way? */
307 1.1 scw sc->sc_iobase = (void *) seg.ds_addr;
308 1.1 scw sc->sc_msize = ether_data_buff_size;
309 1.1 scw memset(sc->sc_maddr, 0, ether_data_buff_size);
310 1.1 scw
311 1.1 scw sc->hwreset = ie_reset;
312 1.1 scw sc->hwinit = ie_hwinit;
313 1.1 scw sc->chan_attn = ie_atten;
314 1.1 scw sc->intrhook = ie_intrhook;
315 1.1 scw sc->memcopyin = ie_copyin;
316 1.1 scw sc->memcopyout = ie_copyout;
317 1.1 scw sc->ie_bus_barrier = NULL;
318 1.1 scw sc->ie_bus_read16 = ie_read_16;
319 1.1 scw sc->ie_bus_write16 = ie_write_16;
320 1.1 scw sc->ie_bus_write24 = ie_write_24;
321 1.1 scw sc->sc_mediachange = NULL;
322 1.1 scw sc->sc_mediastatus = NULL;
323 1.1 scw
324 1.1 scw sc->scp = 0;
325 1.1 scw sc->iscp = sc->scp + ((IE_SCP_SZ + 15) & ~15);
326 1.1 scw sc->scb = sc->iscp + IE_ISCP_SZ;
327 1.1 scw sc->buf_area = sc->scb + IE_SCB_SZ;
328 1.1 scw sc->buf_area_sz = sc->sc_msize - (sc->buf_area - sc->scp);
329 1.1 scw
330 1.1 scw /*
331 1.1 scw * BUS_USE -> Interrupt Active High (edge-triggered),
332 1.1 scw * Lock function enabled,
333 1.1 scw * Internal bus throttle timer triggering,
334 1.1 scw * 82586 operating mode.
335 1.1 scw */
336 1.1 scw ie_write_16(sc, IE_SCP_BUS_USE(sc->scp), IE_BUS_USE);
337 1.1 scw ie_write_24(sc, IE_SCP_ISCP(sc->scp), sc->iscp);
338 1.1 scw ie_write_16(sc, IE_ISCP_SCB(sc->iscp), sc->scb);
339 1.1 scw ie_write_24(sc, IE_ISCP_BASE(sc->iscp), sc->scp);
340 1.1 scw
341 1.1 scw /* This has the side-effect of resetting the chip */
342 1.1 scw i82586_proberam(sc);
343 1.1 scw
344 1.1 scw /* Attach the MI back-end */
345 1.1 scw i82586_attach(sc, "onboard", mvme_ea, NULL, 0, 0);
346 1.1 scw
347 1.1 scw /* Register the event counter */
348 1.1 scw evcnt_attach_dynamic(&ps->ps_evcnt, EVCNT_TYPE_INTR,
349 1.1 scw pcctwointr_evcnt(pa->pa_ipl), "ether", sc->sc_dev.dv_xname);
350 1.1 scw
351 1.1 scw /* Finally, hook the hardware interrupt */
352 1.1 scw pcctwointr_establish(PCCTWOV_LANC_IRQ, i82586_intr, pa->pa_ipl, sc,
353 1.1 scw &ps->ps_evcnt);
354 1.1 scw }
355