if_ie_vme.c revision 1.1 1 /* $NetBSD: if_ie_vme.c,v 1.1 1997/11/01 22:56:21 pk Exp $ */
2
3 /*-
4 * Copyright (c) 1995 Charles D. Cranor
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by Charles D. Cranor.
18 * 4. The name of the author may not be used to endorse or promote products
19 * derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 */
32
33 /*
34 * Converted to SUN ie driver by Charles D. Cranor,
35 * October 1994, January 1995.
36 */
37
38 /*
39 * The i82586 is a very painful chip, found in sun3's, sun-4/100's
40 * sun-4/200's, and VME based suns. The byte order is all wrong for a
41 * SUN, making life difficult. Programming this chip is mostly the same,
42 * but certain details differ from system to system. This driver is
43 * written so that different "ie" interfaces can be controled by the same
44 * driver.
45 */
46
47 /*
48 * programming notes:
49 *
50 * the ie chip operates in a 24 bit address space.
51 *
52 * most ie interfaces appear to be divided into two parts:
53 * - generic 586 stuff
54 * - board specific
55 *
56 * generic:
57 * the generic stuff of the ie chip is all done with data structures
58 * that live in the chip's memory address space. the chip expects
59 * its main data structure (the sys conf ptr -- SCP) to be at a fixed
60 * address in its 24 bit space: 0xfffff4
61 *
62 * the SCP points to another structure called the ISCP.
63 * the ISCP points to another structure called the SCB.
64 * the SCB has a status field, a linked list of "commands", and
65 * a linked list of "receive buffers". these are data structures that
66 * live in memory, not registers.
67 *
68 * board:
69 * to get the chip to do anything, you first put a command in the
70 * command data structure list. then you have to signal "attention"
71 * to the chip to get it to look at the command. how you
72 * signal attention depends on what board you have... on PC's
73 * there is an i/o port number to do this, on sun's there is a
74 * register bit you toggle.
75 *
76 * to get data from the chip you program it to interrupt...
77 *
78 *
79 * sun issues:
80 *
81 * there are 3 kinds of sun "ie" interfaces:
82 * 1 - a VME/multibus card
83 * 2 - an on-board interface (sun3's, sun-4/100's, and sun-4/200's)
84 * 3 - another VME board called the 3E
85 *
86 * the VME boards lives in vme16 space. only 16 and 8 bit accesses
87 * are allowed, so functions that copy data must be aware of this.
88 *
89 * the chip is an intel chip. this means that the byte order
90 * on all the "short"s in the chip's data structures is wrong.
91 * so, constants described in the intel docs are swapped for the sun.
92 * that means that any buffer pointers you give the chip must be
93 * swapped to intel format. yuck.
94 *
95 * VME/multibus interface:
96 * for the multibus interface the board ignores the top 4 bits
97 * of the chip address. the multibus interface seems to have its
98 * own MMU like page map (without protections or valid bits, etc).
99 * there are 256 pages of physical memory on the board (each page
100 * is 1024 bytes). there are 1024 slots in the page map. so,
101 * a 1024 byte page takes up 10 bits of address for the offset,
102 * and if there are 1024 slots in the page that is another 10 bits
103 * of the address. that makes a 20 bit address, and as stated
104 * earlier the board ignores the top 4 bits, so that accounts
105 * for all 24 bits of address.
106 *
107 * note that the last entry of the page map maps the top of the
108 * 24 bit address space and that the SCP is supposed to be at
109 * 0xfffff4 (taking into account allignment). so,
110 * for multibus, that entry in the page map has to be used for the SCP.
111 *
112 * the page map effects BOTH how the ie chip sees the
113 * memory, and how the host sees it.
114 *
115 * the page map is part of the "register" area of the board
116 *
117 * on-board interface:
118 *
119 * <fill in useful info later>
120 *
121 *
122 * VME3E interface:
123 *
124 * <fill in useful info later>
125 *
126 */
127
128 #include <sys/param.h>
129 #include <sys/systm.h>
130 #include <sys/errno.h>
131 #include <sys/device.h>
132 #include <sys/protosw.h>
133 #include <sys/socket.h>
134
135 #include <net/if.h>
136 #include <net/if_types.h>
137 #include <net/if_dl.h>
138 #include <net/if_ether.h>
139
140 #include <vm/vm.h>
141
142 #include <machine/bus.h>
143 #include <dev/vme/vmevar.h>
144
145 #include <dev/ic/i82586reg.h>
146 #include <dev/ic/i82586var.h>
147
148
149 /*
150 * VME/multibus definitions
151 */
152 #define IEVME_PAGESIZE 1024 /* bytes */
153 #define IEVME_PAGSHIFT 10 /* bits */
154 #define IEVME_NPAGES 256 /* number of pages on chip */
155 #define IEVME_MAPSZ 1024 /* number of entries in the map */
156
157 /*
158 * PTE for the page map
159 */
160 #define IEVME_SBORDR 0x8000 /* sun byte order */
161 #define IEVME_IBORDR 0x0000 /* intel byte ordr */
162
163 #define IEVME_P2MEM 0x2000 /* memory is on P2 */
164 #define IEVME_OBMEM 0x0000 /* memory is on board */
165
166 #define IEVME_PGMASK 0x0fff /* gives the physical page frame number */
167
168 struct ievme {
169 u_int16_t pgmap[IEVME_MAPSZ];
170 u_int16_t xxx[32]; /* prom */
171 u_int16_t status; /* see below for bits */
172 u_int16_t xxx2; /* filler */
173 u_int16_t pectrl; /* parity control (see below) */
174 u_int16_t peaddr; /* low 16 bits of address */
175 };
176
177 /*
178 * status bits
179 */
180 #define IEVME_RESET 0x8000 /* reset board */
181 #define IEVME_ONAIR 0x4000 /* go out of loopback 'on-air' */
182 #define IEVME_ATTEN 0x2000 /* attention */
183 #define IEVME_IENAB 0x1000 /* interrupt enable */
184 #define IEVME_PEINT 0x0800 /* parity error interrupt enable */
185 #define IEVME_PERR 0x0200 /* parity error flag */
186 #define IEVME_INT 0x0100 /* interrupt flag */
187 #define IEVME_P2EN 0x0020 /* enable p2 bus */
188 #define IEVME_256K 0x0010 /* 256kb rams */
189 #define IEVME_HADDR 0x000f /* mask for bits 17-20 of address */
190
191 /*
192 * parity control
193 */
194 #define IEVME_PARACK 0x0100 /* parity error ack */
195 #define IEVME_PARSRC 0x0080 /* parity error source */
196 #define IEVME_PAREND 0x0040 /* which end of the data got the error */
197 #define IEVME_PARADR 0x000f /* mask to get bits 17-20 of parity address */
198
199
200 /*
201 * the 3E board not supported (yet?)
202 */
203
204
205 static void ie_vmereset __P((struct ie_softc *));
206 static void ie_vmeattend __P((struct ie_softc *));
207 static void ie_vmerun __P((struct ie_softc *));
208 static int ie_vmeintr __P((struct ie_softc *));
209 static caddr_t ie_align __P((caddr_t));
210
211 int ie_vme_match __P((struct device *, struct cfdata *, void *));
212 void ie_vme_attach __P((struct device *, struct device *, void *));
213
214 struct cfattach ie_vme_ca = {
215 sizeof(struct ie_softc), ie_vme_match, ie_vme_attach
216 };
217
218 /*
219 * MULTIBUS/VME support routines
220 */
221 void
222 ie_vmereset(sc)
223 struct ie_softc *sc;
224 {
225 volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
226 iev->status = IEVME_RESET;
227 delay(100); /* XXX could be shorter? */
228 iev->status = 0;
229 }
230
231 void
232 ie_vmeattend(sc)
233 struct ie_softc *sc;
234 {
235 volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
236
237 iev->status |= IEVME_ATTEN; /* flag! */
238 iev->status &= ~IEVME_ATTEN; /* down. */
239 }
240
241 void
242 ie_vmerun(sc)
243 struct ie_softc *sc;
244 {
245 volatile struct ievme *iev = (struct ievme *) sc->sc_reg;
246
247 iev->status |= (IEVME_ONAIR | IEVME_IENAB | IEVME_PEINT);
248 }
249
250 int
251 ie_vmeintr(sc)
252 struct ie_softc *sc;
253 {
254 volatile struct ievme *iev = (volatile struct ievme *)sc->sc_reg;
255
256 /*
257 * check for parity error
258 */
259 if (iev->status & IEVME_PERR) {
260 printf("%s: parity error (ctrl 0x%x @ 0x%02x%04x)\n",
261 sc->sc_dev.dv_xname, iev->pectrl,
262 iev->pectrl & IEVME_HADDR, iev->peaddr);
263 iev->pectrl = iev->pectrl | IEVME_PARACK;
264 }
265 return (0);
266 }
267
268 caddr_t
269 ie_align(ptr)
270 caddr_t ptr;
271 {
272 u_long l = (u_long)ptr;
273
274 l = (l + 3) & ~3L;
275 return (caddr_t)l;
276 }
277
278 int
279 ie_vme_match(parent, cf, aux)
280 struct device *parent;
281 struct cfdata *cf;
282 void *aux;
283 {
284 struct vme_attach_args *va = aux;
285 vme_chipset_tag_t ct = va->vma_chipset_tag;
286 bus_space_tag_t bt = va->vma_bustag;
287 int mod;
288
289 mod = VMEMOD_A24 | VMEMOD_S | VMEMOD_D;
290 if (vme_bus_probe(ct, bt, va->vma_reg[0], 2, mod))
291 return (1);
292
293 return (0);
294 }
295
296 void
297 ie_vme_attach(parent, self, aux)
298 struct device *parent;
299 struct device *self;
300 void *aux;
301 {
302 u_int8_t myaddr[ETHER_ADDR_LEN];
303 extern void myetheraddr(u_char *); /* should be elsewhere */
304 struct ie_softc *sc = (void *) self;
305 struct vme_attach_args *va = aux;
306 vme_chipset_tag_t ct = va->vma_chipset_tag;
307 bus_space_tag_t bt = va->vma_bustag;
308 bus_space_handle_t bh;
309 vme_intr_handle_t ih;
310 volatile struct ievme *iev;
311 u_long rampaddr;
312 int lcv;
313 vme_size_t sz;
314
315 int mod;
316
317 /*
318 * *note*: we don't detect the difference between a VME3E and
319 * a multibus/vme card. if you want to use a 3E you'll have
320 * to fix this.
321 */
322 mod = VMEMOD_A24 | VMEMOD_S | VMEMOD_D;
323
324 #if 0
325 sc->dmat = va->vma_dmatag;
326 #endif
327 sc->bt = bt;
328
329 sc->hwreset = ie_vmereset;
330 sc->hwinit = ie_vmerun;
331 sc->chan_attn = ie_vmeattend;
332 sc->align = ie_align;
333 sc->intrhook = ie_vmeintr;
334 sc->memcopy = wcopy;
335 sc->memzero = wzero;
336 sc->sc_msize = 4*65536; /* XXX */
337
338 sz = sizeof(struct ievme);
339 if (vme_bus_map(ct, va->vma_reg[0], sz, mod, bt, &bh) != 0)
340 panic("if_ie: vme_map");
341 sc->sc_reg = (caddr_t)bh;
342
343 iev = (volatile struct ievme *) sc->sc_reg;
344 /* top 12 bits */
345 rampaddr = (u_long)va->vma_reg[0] & 0xfff00000;
346
347 /* 4 more */
348 rampaddr = rampaddr | ((iev->status & IEVME_HADDR) << 16);
349 sz = sc->sc_msize;
350 if (vme_bus_map(ct, rampaddr, sz, mod, bt, &bh) != 0)
351 panic("if_ie: vme_map");
352
353 sc->sc_maddr = (caddr_t)bh;
354 sc->sc_iobase = sc->sc_maddr;
355
356 iev->pectrl = iev->pectrl | IEVME_PARACK; /* clear to start */
357
358 /*
359 * Set up mappings, direct map except for last page
360 * which is mapped at zero and at high address (for scp)
361 */
362 for (lcv = 0; lcv < IEVME_MAPSZ - 1; lcv++)
363 iev->pgmap[lcv] = IEVME_SBORDR | IEVME_OBMEM | lcv;
364 iev->pgmap[IEVME_MAPSZ - 1] = IEVME_SBORDR | IEVME_OBMEM | 0;
365
366 /* Clear all ram */
367 (sc->memzero)(sc->sc_maddr, sc->sc_msize);
368
369 /*
370 * set up pointers to data structures and buffer area.
371 * scp is in double mapped page... get offset into page
372 * and add to sc_maddr.
373 */
374 sc->scp = (volatile struct ie_sys_conf_ptr *)
375 (sc->sc_maddr + (IE_SCP_ADDR & (IEVME_PAGESIZE - 1)));
376
377 /* iscp at location zero */
378 sc->iscp = (volatile struct ie_int_sys_conf_ptr *)sc->sc_maddr;
379
380 /* scb follows iscp */
381 sc->scb = (volatile struct ie_sys_ctl_block *)
382 sc->sc_maddr + sizeof(struct ie_int_sys_conf_ptr);
383
384 /*
385 * Rest of first page is unused; rest of ram for buffers.
386 */
387 sc->buf_area = sc->sc_maddr + IEVME_PAGESIZE;
388 sc->buf_area_sz = sc->sc_msize - IEVME_PAGESIZE;
389
390 myetheraddr(myaddr);
391 ie_attach(sc, "multibus/vme", myaddr);
392
393 vme_intr_map(ct, va->vma_vec, va->vma_pri, &ih);
394 vme_intr_establish(ct, ih, ieintr, sc);
395 }
396