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