if_ie_mvme.c revision 1.1 1 1.1 scw /* $NetBSD: if_ie_mvme.c,v 1.1 2002/02/12 20:38:43 scw 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.1 scw
39 1.1 scw #include <sys/param.h>
40 1.1 scw #include <sys/systm.h>
41 1.1 scw #include <sys/mbuf.h>
42 1.1 scw #include <sys/errno.h>
43 1.1 scw #include <sys/device.h>
44 1.1 scw #include <sys/protosw.h>
45 1.1 scw #include <sys/socket.h>
46 1.1 scw
47 1.1 scw #include <net/if.h>
48 1.1 scw #include <net/if_dl.h>
49 1.1 scw #include <net/if_types.h>
50 1.1 scw #include <net/if_ether.h>
51 1.1 scw #include <net/if_media.h>
52 1.1 scw
53 1.1 scw #include <uvm/uvm_extern.h>
54 1.1 scw
55 1.1 scw #include <machine/autoconf.h>
56 1.1 scw #include <machine/cpu.h>
57 1.1 scw #include <machine/bus.h>
58 1.1 scw
59 1.1 scw #include <dev/ic/i82586reg.h>
60 1.1 scw #include <dev/ic/i82586var.h>
61 1.1 scw
62 1.1 scw #include <dev/mvme/if_iereg.h>
63 1.1 scw #include <dev/mvme/pcctwovar.h>
64 1.1 scw #include <dev/mvme/pcctworeg.h>
65 1.1 scw
66 1.1 scw
67 1.1 scw int ie_pcctwo_match __P((struct device *, struct cfdata *, void *));
68 1.1 scw void ie_pcctwo_attach __P((struct device *, struct device *, void *));
69 1.1 scw
70 1.1 scw struct ie_pcctwo_softc {
71 1.1 scw struct ie_softc ps_ie;
72 1.1 scw bus_space_tag_t ps_bust;
73 1.1 scw bus_space_handle_t ps_bush;
74 1.1 scw struct evcnt ps_evcnt;
75 1.1 scw };
76 1.1 scw
77 1.1 scw struct cfattach ie_pcctwo_ca = {
78 1.1 scw sizeof(struct ie_pcctwo_softc), ie_pcctwo_match, ie_pcctwo_attach
79 1.1 scw };
80 1.1 scw
81 1.1 scw extern struct cfdriver ie_cd;
82 1.1 scw
83 1.1 scw
84 1.1 scw /* Functions required by the i82586 MI driver */
85 1.1 scw static void ie_reset __P((struct ie_softc *, int));
86 1.1 scw static int ie_intrhook __P((struct ie_softc *, int));
87 1.1 scw static void ie_hwinit __P((struct ie_softc *));
88 1.1 scw static void ie_atten __P((struct ie_softc *, int));
89 1.1 scw
90 1.1 scw static void ie_copyin __P((struct ie_softc *, void *, int, size_t));
91 1.1 scw static void ie_copyout __P((struct ie_softc *, const void *, int, size_t));
92 1.1 scw
93 1.1 scw static u_int16_t ie_read_16 __P((struct ie_softc *, int));
94 1.1 scw static void ie_write_16 __P((struct ie_softc *, int, u_int16_t));
95 1.1 scw static void ie_write_24 __P((struct ie_softc *, int, int));
96 1.1 scw
97 1.1 scw /*
98 1.1 scw * i82596 Support Routines for MVME1[67][27] and MVME187 Boards
99 1.1 scw */
100 1.1 scw static void
101 1.1 scw ie_reset(sc, why)
102 1.1 scw struct ie_softc *sc;
103 1.1 scw int why;
104 1.1 scw {
105 1.1 scw struct ie_pcctwo_softc *ps;
106 1.1 scw u_int32_t scp_addr;
107 1.1 scw
108 1.1 scw ps = (struct ie_pcctwo_softc *) sc;
109 1.1 scw
110 1.1 scw switch (why) {
111 1.1 scw case CHIP_PROBE:
112 1.1 scw case CARD_RESET:
113 1.1 scw bus_space_write_2(ps->ps_bust, ps->ps_bush, IE_MPUREG_UPPER,
114 1.1 scw IE_PORT_RESET);
115 1.1 scw bus_space_write_2(ps->ps_bust, ps->ps_bush, IE_MPUREG_LOWER, 0);
116 1.1 scw delay(1000);
117 1.1 scw
118 1.1 scw /*
119 1.1 scw * Set the BUSY and BUS_USE bytes here, since the MI code
120 1.1 scw * incorrectly assumes it can use byte addressing to set it.
121 1.1 scw * (due to wrong-endianess of the chip)
122 1.1 scw */
123 1.1 scw ie_write_16(sc, IE_ISCP_BUSY(sc->iscp), 1);
124 1.1 scw ie_write_16(sc, IE_SCP_BUS_USE(sc->scp), IE_BUS_USE);
125 1.1 scw
126 1.1 scw scp_addr = sc->scp + (u_int) sc->sc_iobase;
127 1.1 scw scp_addr |= IE_PORT_ALT_SCP;
128 1.1 scw
129 1.1 scw bus_space_write_2(ps->ps_bust, ps->ps_bush, IE_MPUREG_UPPER,
130 1.1 scw scp_addr & 0xffff);
131 1.1 scw bus_space_write_2(ps->ps_bust, ps->ps_bush, IE_MPUREG_LOWER,
132 1.1 scw (scp_addr >> 16) & 0xffff);
133 1.1 scw delay(1000);
134 1.1 scw break;
135 1.1 scw }
136 1.1 scw }
137 1.1 scw
138 1.1 scw /* ARGSUSED */
139 1.1 scw static int
140 1.1 scw ie_intrhook(sc, when)
141 1.1 scw struct ie_softc *sc;
142 1.1 scw int when;
143 1.1 scw {
144 1.1 scw struct ie_pcctwo_softc *ps;
145 1.1 scw u_int8_t reg;
146 1.1 scw
147 1.1 scw ps = (struct ie_pcctwo_softc *) sc;
148 1.1 scw
149 1.1 scw if (when == INTR_EXIT) {
150 1.1 scw reg = pcc2_reg_read(sys_pcctwo, PCC2REG_ETH_ICSR);
151 1.1 scw reg |= PCCTWO_ICR_ICLR;
152 1.1 scw pcc2_reg_write(sys_pcctwo, PCC2REG_ETH_ICSR, reg);
153 1.1 scw }
154 1.1 scw return (0);
155 1.1 scw }
156 1.1 scw
157 1.1 scw /* ARGSUSED */
158 1.1 scw static void
159 1.1 scw ie_hwinit(sc)
160 1.1 scw struct ie_softc *sc;
161 1.1 scw {
162 1.1 scw u_int8_t reg;
163 1.1 scw
164 1.1 scw reg = pcc2_reg_read(sys_pcctwo, PCC2REG_ETH_ICSR);
165 1.1 scw reg |= PCCTWO_ICR_IEN | PCCTWO_ICR_ICLR;
166 1.1 scw pcc2_reg_write(sys_pcctwo, PCC2REG_ETH_ICSR, reg);
167 1.1 scw }
168 1.1 scw
169 1.1 scw /* ARGSUSED */
170 1.1 scw static void
171 1.1 scw ie_atten(sc, reason)
172 1.1 scw struct ie_softc *sc;
173 1.1 scw int reason;
174 1.1 scw {
175 1.1 scw struct ie_pcctwo_softc *ps;
176 1.1 scw
177 1.1 scw ps = (struct ie_pcctwo_softc *) sc;
178 1.1 scw bus_space_write_4(ps->ps_bust, ps->ps_bush, IE_MPUREG_CA, 0);
179 1.1 scw }
180 1.1 scw
181 1.1 scw static void
182 1.1 scw ie_copyin(sc, dst, offset, size)
183 1.1 scw struct ie_softc *sc;
184 1.1 scw void *dst;
185 1.1 scw int offset;
186 1.1 scw size_t size;
187 1.1 scw {
188 1.1 scw if (size == 0) /* This *can* happen! */
189 1.1 scw return;
190 1.1 scw
191 1.1 scw #if 0
192 1.1 scw bus_space_read_region_1(sc->bt, sc->bh, offset, dst, size);
193 1.1 scw #else
194 1.1 scw /* A minor optimisation ;-) */
195 1.1 scw memcpy(dst, (void *) ((u_long) sc->bh + (u_long) offset), size);
196 1.1 scw #endif
197 1.1 scw }
198 1.1 scw
199 1.1 scw static void
200 1.1 scw ie_copyout(sc, src, offset, size)
201 1.1 scw struct ie_softc *sc;
202 1.1 scw const void *src;
203 1.1 scw int offset;
204 1.1 scw size_t size;
205 1.1 scw {
206 1.1 scw if (size == 0) /* This *can* happen! */
207 1.1 scw return;
208 1.1 scw
209 1.1 scw #if 0
210 1.1 scw bus_space_write_region_1(sc->bt, sc->bh, offset, src, size);
211 1.1 scw #else
212 1.1 scw /* A minor optimisation ;-) */
213 1.1 scw memcpy((void *) ((u_long) sc->bh + (u_long) offset), src, size);
214 1.1 scw #endif
215 1.1 scw }
216 1.1 scw
217 1.1 scw static u_int16_t
218 1.1 scw ie_read_16(sc, offset)
219 1.1 scw struct ie_softc *sc;
220 1.1 scw int offset;
221 1.1 scw {
222 1.1 scw
223 1.1 scw return (bus_space_read_2(sc->bt, sc->bh, offset));
224 1.1 scw }
225 1.1 scw
226 1.1 scw static void
227 1.1 scw ie_write_16(sc, offset, value)
228 1.1 scw struct ie_softc *sc;
229 1.1 scw int offset;
230 1.1 scw u_int16_t value;
231 1.1 scw {
232 1.1 scw
233 1.1 scw bus_space_write_2(sc->bt, sc->bh, offset, value);
234 1.1 scw }
235 1.1 scw
236 1.1 scw static void
237 1.1 scw ie_write_24(sc, offset, addr)
238 1.1 scw struct ie_softc *sc;
239 1.1 scw int offset;
240 1.1 scw int addr;
241 1.1 scw {
242 1.1 scw
243 1.1 scw addr += (int) sc->sc_iobase;
244 1.1 scw
245 1.1 scw bus_space_write_2(sc->bt, sc->bh, offset, addr & 0xffff);
246 1.1 scw bus_space_write_2(sc->bt, sc->bh, offset + 2, (addr >> 16) & 0x00ff);
247 1.1 scw }
248 1.1 scw
249 1.1 scw /* ARGSUSED */
250 1.1 scw int
251 1.1 scw ie_pcctwo_match(parent, cf, args)
252 1.1 scw struct device *parent;
253 1.1 scw struct cfdata *cf;
254 1.1 scw void *args;
255 1.1 scw {
256 1.1 scw struct pcctwo_attach_args *pa;
257 1.1 scw
258 1.1 scw pa = args;
259 1.1 scw
260 1.1 scw if (strcmp(pa->pa_name, ie_cd.cd_name))
261 1.1 scw return (0);
262 1.1 scw
263 1.1 scw pa->pa_ipl = cf->pcctwocf_ipl;
264 1.1 scw
265 1.1 scw return (1);
266 1.1 scw }
267 1.1 scw
268 1.1 scw /* ARGSUSED */
269 1.1 scw void
270 1.1 scw ie_pcctwo_attach(parent, self, args)
271 1.1 scw struct device *parent;
272 1.1 scw struct device *self;
273 1.1 scw void *args;
274 1.1 scw {
275 1.1 scw struct pcctwo_attach_args *pa;
276 1.1 scw struct ie_pcctwo_softc *ps;
277 1.1 scw struct ie_softc *sc;
278 1.1 scw bus_dma_segment_t seg;
279 1.1 scw int rseg;
280 1.1 scw
281 1.1 scw pa = (struct pcctwo_attach_args *) args;
282 1.1 scw ps = (struct ie_pcctwo_softc *) self;
283 1.1 scw sc = (struct ie_softc *) self;
284 1.1 scw
285 1.1 scw /* Map the MPU controller registers in PCCTWO space */
286 1.1 scw ps->ps_bust = pa->pa_bust;
287 1.1 scw bus_space_map(pa->pa_bust, pa->pa_offset, IE_MPUREG_SIZE,
288 1.1 scw 0, &ps->ps_bush);
289 1.1 scw
290 1.1 scw /* Get contiguous DMA-able memory for the IE chip */
291 1.1 scw if (bus_dmamem_alloc(pa->pa_dmat, ether_data_buff_size, NBPG, 0,
292 1.1 scw &seg, 1, &rseg,
293 1.1 scw BUS_DMA_NOWAIT | BUS_DMA_ONBOARD_RAM | BUS_DMA_24BIT) != 0) {
294 1.1 scw printf("%s: Failed to allocate ether buffer\n", self->dv_xname);
295 1.1 scw return;
296 1.1 scw }
297 1.1 scw if (bus_dmamem_map(pa->pa_dmat, &seg, rseg, ether_data_buff_size,
298 1.1 scw (caddr_t *) & sc->sc_maddr, BUS_DMA_NOWAIT | BUS_DMA_COHERENT)) {
299 1.1 scw printf("%s: Failed to map ether buffer\n", self->dv_xname);
300 1.1 scw bus_dmamem_free(pa->pa_dmat, &seg, rseg);
301 1.1 scw return;
302 1.1 scw }
303 1.1 scw sc->bt = pa->pa_bust;
304 1.1 scw sc->bh = (bus_space_handle_t) sc->sc_maddr; /* XXXSCW Better way? */
305 1.1 scw sc->sc_iobase = (void *) seg.ds_addr;
306 1.1 scw sc->sc_msize = ether_data_buff_size;
307 1.1 scw memset(sc->sc_maddr, 0, ether_data_buff_size);
308 1.1 scw
309 1.1 scw sc->hwreset = ie_reset;
310 1.1 scw sc->hwinit = ie_hwinit;
311 1.1 scw sc->chan_attn = ie_atten;
312 1.1 scw sc->intrhook = ie_intrhook;
313 1.1 scw sc->memcopyin = ie_copyin;
314 1.1 scw sc->memcopyout = ie_copyout;
315 1.1 scw sc->ie_bus_barrier = NULL;
316 1.1 scw sc->ie_bus_read16 = ie_read_16;
317 1.1 scw sc->ie_bus_write16 = ie_write_16;
318 1.1 scw sc->ie_bus_write24 = ie_write_24;
319 1.1 scw sc->sc_mediachange = NULL;
320 1.1 scw sc->sc_mediastatus = NULL;
321 1.1 scw
322 1.1 scw sc->scp = 0;
323 1.1 scw sc->iscp = sc->scp + ((IE_SCP_SZ + 15) & ~15);
324 1.1 scw sc->scb = sc->iscp + IE_ISCP_SZ;
325 1.1 scw sc->buf_area = sc->scb + IE_SCB_SZ;
326 1.1 scw sc->buf_area_sz = sc->sc_msize - (sc->buf_area - sc->scp);
327 1.1 scw
328 1.1 scw /*
329 1.1 scw * BUS_USE -> Interrupt Active High (edge-triggered),
330 1.1 scw * Lock function enabled,
331 1.1 scw * Internal bus throttle timer triggering,
332 1.1 scw * 82586 operating mode.
333 1.1 scw */
334 1.1 scw ie_write_16(sc, IE_SCP_BUS_USE(sc->scp), IE_BUS_USE);
335 1.1 scw ie_write_24(sc, IE_SCP_ISCP(sc->scp), sc->iscp);
336 1.1 scw ie_write_16(sc, IE_ISCP_SCB(sc->iscp), sc->scb);
337 1.1 scw ie_write_24(sc, IE_ISCP_BASE(sc->iscp), sc->scp);
338 1.1 scw
339 1.1 scw /* This has the side-effect of resetting the chip */
340 1.1 scw i82586_proberam(sc);
341 1.1 scw
342 1.1 scw /* Attach the MI back-end */
343 1.1 scw i82586_attach(sc, "onboard", mvme_ea, NULL, 0, 0);
344 1.1 scw
345 1.1 scw /* Register the event counter */
346 1.1 scw evcnt_attach_dynamic(&ps->ps_evcnt, EVCNT_TYPE_INTR,
347 1.1 scw pcctwointr_evcnt(pa->pa_ipl), "ether", sc->sc_dev.dv_xname);
348 1.1 scw
349 1.1 scw /* Finally, hook the hardware interrupt */
350 1.1 scw pcctwointr_establish(PCCTWOV_LANC_IRQ, i82586_intr, pa->pa_ipl, sc,
351 1.1 scw &ps->ps_evcnt);
352 1.1 scw }
353