if_ie_vme.c revision 1.4 1 1.4 christos /* $NetBSD: if_ie_vme.c,v 1.4 1996/10/13 03:47:30 christos Exp $ */
2 1.1 gwr
3 1.1 gwr /*
4 1.1 gwr * Copyright (c) 1994 Gordon W. Ross
5 1.1 gwr * All rights reserved.
6 1.1 gwr *
7 1.1 gwr * Redistribution and use in source and binary forms, with or without
8 1.1 gwr * modification, are permitted provided that the following conditions
9 1.1 gwr * are met:
10 1.1 gwr * 1. Redistributions of source code must retain the above copyright
11 1.1 gwr * notice, this list of conditions and the following disclaimer.
12 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 gwr * notice, this list of conditions and the following disclaimer in the
14 1.1 gwr * documentation and/or other materials provided with the distribution.
15 1.1 gwr * 3. All advertising materials mentioning features or use of this software
16 1.1 gwr * must display the following acknowledgement:
17 1.1 gwr * This product includes software developed by Gordon Ross
18 1.1 gwr * 4. The name of the Author may not be used to endorse or promote products
19 1.1 gwr * derived from this software without specific prior written permission.
20 1.1 gwr *
21 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.1 gwr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.1 gwr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.1 gwr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.1 gwr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.1 gwr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.1 gwr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.1 gwr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.1 gwr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.1 gwr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 gwr */
32 1.1 gwr
33 1.1 gwr /*
34 1.1 gwr * Machine-dependent glue for the Intel Ethernet (ie) driver.
35 1.1 gwr */
36 1.1 gwr
37 1.1 gwr #include <sys/param.h>
38 1.1 gwr #include <sys/systm.h>
39 1.1 gwr #include <sys/device.h>
40 1.1 gwr #include <sys/protosw.h>
41 1.1 gwr #include <sys/socket.h>
42 1.1 gwr #include <net/if.h>
43 1.1 gwr
44 1.1 gwr #ifdef INET
45 1.1 gwr #include <netinet/in.h>
46 1.1 gwr #include <netinet/in_systm.h>
47 1.1 gwr #include <netinet/in_var.h>
48 1.1 gwr #include <netinet/ip.h>
49 1.1 gwr #include <netinet/if_ether.h>
50 1.1 gwr #endif
51 1.1 gwr
52 1.1 gwr #include <machine/autoconf.h>
53 1.1 gwr #include <machine/cpu.h>
54 1.1 gwr #include <machine/dvma.h>
55 1.1 gwr #include <machine/isr.h>
56 1.1 gwr #include <machine/idprom.h>
57 1.1 gwr #include <machine/vmparam.h>
58 1.1 gwr
59 1.1 gwr #include "i82586.h"
60 1.2 gwr #include "if_iereg.h"
61 1.2 gwr #include "if_ievar.h"
62 1.1 gwr
63 1.1 gwr static void ie_vmereset __P((struct ie_softc *));
64 1.1 gwr static void ie_vmeattend __P((struct ie_softc *));
65 1.1 gwr static void ie_vmerun __P((struct ie_softc *));
66 1.1 gwr
67 1.1 gwr /*
68 1.1 gwr * zero/copy functions: OBIO can use the normal functions, but VME
69 1.1 gwr * must do only byte or half-word (16 bit) accesses...
70 1.1 gwr */
71 1.1 gwr static void wcopy(), wzero();
72 1.1 gwr
73 1.1 gwr /*
74 1.1 gwr * New-style autoconfig attachment
75 1.1 gwr */
76 1.1 gwr
77 1.1 gwr static int ie_vmes_match __P((struct device *, void *, void *));
78 1.1 gwr static void ie_vmes_attach __P((struct device *, struct device *, void *));
79 1.1 gwr
80 1.1 gwr struct cfattach ie_vmes_ca = {
81 1.1 gwr sizeof(struct ie_softc), ie_vmes_match, ie_vmes_attach
82 1.1 gwr };
83 1.1 gwr
84 1.1 gwr
85 1.1 gwr static int
86 1.1 gwr ie_vmes_match(parent, vcf, args)
87 1.1 gwr struct device *parent;
88 1.1 gwr void *vcf, *args;
89 1.1 gwr {
90 1.1 gwr struct confargs *ca = args;
91 1.1 gwr int x, sz;
92 1.1 gwr
93 1.1 gwr #ifdef DIAGNOSTIC
94 1.1 gwr if (ca->ca_bustype != BUS_VME16) {
95 1.4 christos printf("ie_vmes_match: bustype %d?\n", ca->ca_bustype);
96 1.1 gwr return (0);
97 1.1 gwr }
98 1.1 gwr #endif
99 1.1 gwr
100 1.1 gwr /* No default VME address. */
101 1.1 gwr if (ca->ca_paddr == -1)
102 1.1 gwr return(0);
103 1.1 gwr
104 1.1 gwr /* Default interrupt level. */
105 1.1 gwr if (ca->ca_intpri == -1)
106 1.1 gwr ca->ca_intpri = 3;
107 1.1 gwr
108 1.1 gwr x = bus_peek(ca->ca_bustype, ca->ca_paddr, 2);
109 1.1 gwr return (x != -1);
110 1.1 gwr }
111 1.1 gwr
112 1.1 gwr /*
113 1.1 gwr * *note*: we don't detect the difference between a VME3E and
114 1.1 gwr * a multibus/vme card. if you want to use a 3E you'll have
115 1.1 gwr * to fix this.
116 1.1 gwr */
117 1.1 gwr void
118 1.1 gwr ie_vmes_attach(parent, self, args)
119 1.1 gwr struct device *parent;
120 1.1 gwr struct device *self;
121 1.1 gwr void *args;
122 1.1 gwr {
123 1.1 gwr struct ie_softc *sc = (void *) self;
124 1.1 gwr struct confargs *ca = args;
125 1.1 gwr volatile struct ievme *iev;
126 1.1 gwr u_long rampaddr;
127 1.1 gwr int lcv, off;
128 1.1 gwr
129 1.1 gwr sc->hard_type = IE_VME;
130 1.1 gwr sc->reset_586 = ie_vmereset;
131 1.1 gwr sc->chan_attn = ie_vmeattend;
132 1.1 gwr sc->run_586 = ie_vmerun;
133 1.1 gwr sc->sc_bcopy = wcopy;
134 1.1 gwr sc->sc_bzero = wzero;
135 1.1 gwr
136 1.1 gwr /*
137 1.1 gwr * There is 64K of memory on the VME board.
138 1.1 gwr * (determined by hardware - NOT configurable!)
139 1.1 gwr */
140 1.1 gwr sc->sc_msize = 0x10000; /* MEMSIZE 64K */
141 1.1 gwr
142 1.1 gwr /* Map in the board control regs. */
143 1.1 gwr sc->sc_reg = bus_mapin(ca->ca_bustype, ca->ca_paddr,
144 1.1 gwr sizeof(struct ievme));
145 1.1 gwr iev = (volatile struct ievme *) sc->sc_reg;
146 1.1 gwr
147 1.1 gwr /*
148 1.1 gwr * Find and map in the board memory.
149 1.1 gwr */
150 1.1 gwr /* top 12 bits */
151 1.1 gwr rampaddr = ca->ca_paddr & 0xfff00000;
152 1.1 gwr /* 4 more */
153 1.1 gwr rampaddr |= ((iev->status & IEVME_HADDR) << 16);
154 1.1 gwr sc->sc_maddr = bus_mapin(ca->ca_bustype, rampaddr, sc->sc_msize);
155 1.1 gwr
156 1.1 gwr /*
157 1.1 gwr * On this hardware, the i82586 address is just
158 1.1 gwr * masked to 16 bits, so sc_iobase == sc_maddr
159 1.1 gwr */
160 1.1 gwr sc->sc_iobase = sc->sc_maddr;
161 1.1 gwr
162 1.1 gwr /*
163 1.1 gwr * Set up on-board mapping registers for linear map.
164 1.1 gwr */
165 1.1 gwr iev->pectrl |= IEVME_PARACK; /* clear to start */
166 1.1 gwr for (lcv = 0; lcv < IEVME_MAPSZ; lcv++)
167 1.1 gwr iev->pgmap[lcv] = IEVME_SBORDR | IEVME_OBMEM | lcv;
168 1.1 gwr (sc->sc_bzero)(sc->sc_maddr, sc->sc_msize);
169 1.1 gwr
170 1.1 gwr /*
171 1.1 gwr * Set the System Configuration Pointer (SCP).
172 1.1 gwr * Its location is system-dependent because the
173 1.1 gwr * i82586 reads it from a fixed physical address.
174 1.1 gwr * On this hardware, the i82586 address is just
175 1.1 gwr * masked down to 16 bits, so the SCP is found
176 1.1 gwr * at the end of the RAM on the VME board.
177 1.1 gwr */
178 1.1 gwr off = IE_SCP_ADDR & 0xFFFF;
179 1.1 gwr sc->scp = (volatile void *) (sc->sc_maddr + off);
180 1.1 gwr
181 1.1 gwr /*
182 1.1 gwr * The rest of ram is used for buffers, etc.
183 1.1 gwr */
184 1.1 gwr sc->buf_area = sc->sc_maddr;
185 1.1 gwr sc->buf_area_sz = off;
186 1.1 gwr
187 1.1 gwr /* Set the ethernet address. */
188 1.1 gwr idprom_etheraddr(sc->sc_addr);
189 1.1 gwr
190 1.1 gwr /* Do machine-independent parts of attach. */
191 1.1 gwr ie_attach(sc);
192 1.1 gwr
193 1.1 gwr /* Install interrupt handler. */
194 1.1 gwr isr_add_vectored(ie_intr, (void *)sc,
195 1.1 gwr ca->ca_intpri, ca->ca_intvec);
196 1.1 gwr }
197 1.1 gwr
198 1.1 gwr
199 1.1 gwr /*
200 1.1 gwr * MULTIBUS/VME support
201 1.1 gwr */
202 1.1 gwr void
203 1.1 gwr ie_vmereset(sc)
204 1.1 gwr struct ie_softc *sc;
205 1.1 gwr {
206 1.1 gwr volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
207 1.1 gwr iev->status = IEVME_RESET;
208 1.1 gwr delay(100); /* XXX could be shorter? */
209 1.1 gwr iev->status = 0;
210 1.1 gwr }
211 1.1 gwr
212 1.1 gwr void
213 1.1 gwr ie_vmeattend(sc)
214 1.1 gwr struct ie_softc *sc;
215 1.1 gwr {
216 1.1 gwr volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
217 1.1 gwr
218 1.1 gwr iev->status |= IEVME_ATTEN; /* flag! */
219 1.1 gwr iev->status &= ~IEVME_ATTEN; /* down. */
220 1.1 gwr }
221 1.1 gwr
222 1.1 gwr void
223 1.1 gwr ie_vmerun(sc)
224 1.1 gwr struct ie_softc *sc;
225 1.1 gwr {
226 1.1 gwr volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
227 1.1 gwr
228 1.1 gwr iev->status |= (IEVME_ONAIR | IEVME_IENAB | IEVME_PEINT);
229 1.1 gwr }
230 1.1 gwr
231 1.1 gwr /*
232 1.1 gwr * wcopy/wzero - like bcopy/bzero but largest access is 16-bits,
233 1.1 gwr * and also does byte swaps...
234 1.1 gwr * XXX - Would be nice to have asm versions in some library...
235 1.1 gwr */
236 1.1 gwr
237 1.1 gwr static void
238 1.1 gwr wzero(vb, l)
239 1.1 gwr void *vb;
240 1.1 gwr u_int l;
241 1.1 gwr {
242 1.1 gwr u_char *b = vb;
243 1.1 gwr u_char *be = b + l;
244 1.1 gwr u_short *sp;
245 1.1 gwr
246 1.1 gwr if (l == 0)
247 1.1 gwr return;
248 1.1 gwr
249 1.1 gwr /* front, */
250 1.1 gwr if ((u_long)b & 1)
251 1.1 gwr *b++ = 0;
252 1.1 gwr
253 1.1 gwr /* back, */
254 1.1 gwr if (b != be && ((u_long)be & 1) != 0) {
255 1.1 gwr be--;
256 1.1 gwr *be = 0;
257 1.1 gwr }
258 1.1 gwr
259 1.1 gwr /* and middle. */
260 1.1 gwr sp = (u_short *)b;
261 1.1 gwr while (sp != (u_short *)be)
262 1.1 gwr *sp++ = 0;
263 1.1 gwr }
264 1.1 gwr
265 1.1 gwr static void
266 1.1 gwr wcopy(vb1, vb2, l)
267 1.1 gwr const void *vb1;
268 1.1 gwr void *vb2;
269 1.1 gwr u_int l;
270 1.1 gwr {
271 1.1 gwr const u_char *b1e, *b1 = vb1;
272 1.1 gwr u_char *b2 = vb2;
273 1.1 gwr u_short *sp;
274 1.1 gwr int bstore = 0;
275 1.1 gwr
276 1.1 gwr if (l == 0)
277 1.1 gwr return;
278 1.1 gwr
279 1.1 gwr /* front, */
280 1.1 gwr if ((u_long)b1 & 1) {
281 1.1 gwr *b2++ = *b1++;
282 1.1 gwr l--;
283 1.1 gwr }
284 1.1 gwr
285 1.1 gwr /* middle, */
286 1.1 gwr sp = (u_short *)b1;
287 1.1 gwr b1e = b1 + l;
288 1.1 gwr if (l & 1)
289 1.1 gwr b1e--;
290 1.1 gwr bstore = (u_long)b2 & 1;
291 1.1 gwr
292 1.1 gwr while (sp < (u_short *)b1e) {
293 1.1 gwr if (bstore) {
294 1.1 gwr b2[1] = *sp & 0xff;
295 1.1 gwr b2[0] = *sp >> 8;
296 1.1 gwr } else
297 1.1 gwr *((short *)b2) = *sp;
298 1.1 gwr sp++;
299 1.1 gwr b2 += 2;
300 1.1 gwr }
301 1.1 gwr
302 1.1 gwr /* and back. */
303 1.1 gwr if (l & 1)
304 1.1 gwr *b2 = *b1e;
305 1.1 gwr }
306