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