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