if_ie_vme.c revision 1.6 1 /* $NetBSD: if_ie_vme.c,v 1.6 1996/12/17 21:10:46 gwr Exp $ */
2
3 /*-
4 * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Gordon W. Ross.
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 REGENTS OR CONTRIBUTORS BE
30 * 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 /*
40 * Machine-dependent glue for the Intel Ethernet (ie) driver.
41 */
42
43 #include <sys/param.h>
44 #include <sys/systm.h>
45 #include <sys/device.h>
46 #include <sys/protosw.h>
47 #include <sys/socket.h>
48 #include <net/if.h>
49
50 #ifdef INET
51 #include <netinet/in.h>
52 #include <netinet/in_systm.h>
53 #include <netinet/in_var.h>
54 #include <netinet/ip.h>
55 #include <netinet/if_ether.h>
56 #endif
57
58 #include <machine/autoconf.h>
59 #include <machine/cpu.h>
60 #include <machine/dvma.h>
61 #include <machine/idprom.h>
62 #include <machine/vmparam.h>
63
64 #include "i82586.h"
65 #include "if_iereg.h"
66 #include "if_ievar.h"
67
68 static void ie_vmereset __P((struct ie_softc *));
69 static void ie_vmeattend __P((struct ie_softc *));
70 static void ie_vmerun __P((struct ie_softc *));
71
72 /*
73 * zero/copy functions: OBIO can use the normal functions, but VME
74 * must do only byte or half-word (16 bit) accesses...
75 */
76 static void wcopy __P((const void *vb1, void *vb2, u_int l));
77 static void wzero __P((void *vb, u_int l));
78
79
80 /*
81 * New-style autoconfig attachment
82 */
83
84 static int ie_vmes_match __P((struct device *, struct cfdata *, void *));
85 static void ie_vmes_attach __P((struct device *, struct device *, void *));
86
87 struct cfattach ie_vmes_ca = {
88 sizeof(struct ie_softc), ie_vmes_match, ie_vmes_attach
89 };
90
91
92 static int
93 ie_vmes_match(parent, cf, args)
94 struct device *parent;
95 struct cfdata *cf;
96 void *args;
97 {
98 struct confargs *ca = args;
99 int x;
100
101 #ifdef DIAGNOSTIC
102 if (ca->ca_bustype != BUS_VME16) {
103 printf("ie_vmes_match: bustype %d?\n", ca->ca_bustype);
104 return (0);
105 }
106 #endif
107
108 /* No default VME address. */
109 if (ca->ca_paddr == -1)
110 return(0);
111
112 /* Default interrupt level. */
113 if (ca->ca_intpri == -1)
114 ca->ca_intpri = 3;
115
116 x = bus_peek(ca->ca_bustype, ca->ca_paddr, 2);
117 return (x != -1);
118 }
119
120 /*
121 * *note*: we don't detect the difference between a VME3E and
122 * a multibus/vme card. if you want to use a 3E you'll have
123 * to fix this.
124 */
125 void
126 ie_vmes_attach(parent, self, args)
127 struct device *parent;
128 struct device *self;
129 void *args;
130 {
131 struct ie_softc *sc = (void *) self;
132 struct confargs *ca = args;
133 volatile struct ievme *iev;
134 u_long rampaddr;
135 int lcv, off;
136
137 sc->hard_type = IE_VME;
138 sc->reset_586 = ie_vmereset;
139 sc->chan_attn = ie_vmeattend;
140 sc->run_586 = ie_vmerun;
141 sc->sc_bcopy = wcopy;
142 sc->sc_bzero = wzero;
143
144 /*
145 * There is 64K of memory on the VME board.
146 * (determined by hardware - NOT configurable!)
147 */
148 sc->sc_msize = 0x10000; /* MEMSIZE 64K */
149
150 /* Map in the board control regs. */
151 sc->sc_reg = bus_mapin(ca->ca_bustype, ca->ca_paddr,
152 sizeof(struct ievme));
153 iev = (volatile struct ievme *) sc->sc_reg;
154
155 /*
156 * Find and map in the board memory.
157 */
158 /* top 12 bits */
159 rampaddr = ca->ca_paddr & 0xfff00000;
160 /* 4 more */
161 rampaddr |= ((iev->status & IEVME_HADDR) << 16);
162 sc->sc_maddr = bus_mapin(ca->ca_bustype, rampaddr, sc->sc_msize);
163
164 /*
165 * On this hardware, the i82586 address is just
166 * masked to 16 bits, so sc_iobase == sc_maddr
167 */
168 sc->sc_iobase = sc->sc_maddr;
169
170 /*
171 * Set up on-board mapping registers for linear map.
172 */
173 iev->pectrl |= IEVME_PARACK; /* clear to start */
174 for (lcv = 0; lcv < IEVME_MAPSZ; lcv++)
175 iev->pgmap[lcv] = IEVME_SBORDR | IEVME_OBMEM | lcv;
176 (sc->sc_bzero)(sc->sc_maddr, sc->sc_msize);
177
178 /*
179 * Set the System Configuration Pointer (SCP).
180 * Its location is system-dependent because the
181 * i82586 reads it from a fixed physical address.
182 * On this hardware, the i82586 address is just
183 * masked down to 16 bits, so the SCP is found
184 * at the end of the RAM on the VME board.
185 */
186 off = IE_SCP_ADDR & 0xFFFF;
187 sc->scp = (volatile void *) (sc->sc_maddr + off);
188
189 /*
190 * The rest of ram is used for buffers, etc.
191 */
192 sc->buf_area = sc->sc_maddr;
193 sc->buf_area_sz = off;
194
195 /* Set the ethernet address. */
196 idprom_etheraddr(sc->sc_addr);
197
198 /* Do machine-independent parts of attach. */
199 ie_attach(sc);
200
201 /* Install interrupt handler. */
202 isr_add_vectored(ie_intr, (void *)sc,
203 ca->ca_intpri, ca->ca_intvec);
204 }
205
206
207 /*
208 * MULTIBUS/VME support
209 */
210 void
211 ie_vmereset(sc)
212 struct ie_softc *sc;
213 {
214 volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
215 iev->status = IEVME_RESET;
216 delay(100); /* XXX could be shorter? */
217 iev->status = 0;
218 }
219
220 void
221 ie_vmeattend(sc)
222 struct ie_softc *sc;
223 {
224 volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
225
226 iev->status |= IEVME_ATTEN; /* flag! */
227 iev->status &= ~IEVME_ATTEN; /* down. */
228 }
229
230 void
231 ie_vmerun(sc)
232 struct ie_softc *sc;
233 {
234 volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
235
236 iev->status |= (IEVME_ONAIR | IEVME_IENAB | IEVME_PEINT);
237 }
238
239 /*
240 * wcopy/wzero - like bcopy/bzero but largest access is 16-bits,
241 * and also does byte swaps...
242 * XXX - Would be nice to have asm versions in some library...
243 */
244
245 static void
246 wzero(vb, l)
247 void *vb;
248 u_int l;
249 {
250 u_char *b = vb;
251 u_char *be = b + l;
252 u_short *sp;
253
254 if (l == 0)
255 return;
256
257 /* front, */
258 if ((u_long)b & 1)
259 *b++ = 0;
260
261 /* back, */
262 if (b != be && ((u_long)be & 1) != 0) {
263 be--;
264 *be = 0;
265 }
266
267 /* and middle. */
268 sp = (u_short *)b;
269 while (sp != (u_short *)be)
270 *sp++ = 0;
271 }
272
273 static void
274 wcopy(vb1, vb2, l)
275 const void *vb1;
276 void *vb2;
277 u_int l;
278 {
279 const u_char *b1e, *b1 = vb1;
280 u_char *b2 = vb2;
281 u_short *sp;
282 int bstore = 0;
283
284 if (l == 0)
285 return;
286
287 /* front, */
288 if ((u_long)b1 & 1) {
289 *b2++ = *b1++;
290 l--;
291 }
292
293 /* middle, */
294 sp = (u_short *)b1;
295 b1e = b1 + l;
296 if (l & 1)
297 b1e--;
298 bstore = (u_long)b2 & 1;
299
300 while (sp < (u_short *)b1e) {
301 if (bstore) {
302 b2[1] = *sp & 0xff;
303 b2[0] = *sp >> 8;
304 } else
305 *((short *)b2) = *sp;
306 sp++;
307 b2 += 2;
308 }
309
310 /* and back. */
311 if (l & 1)
312 *b2 = *b1e;
313 }
314