if_le.c revision 1.19 1 /* $NetBSD: if_le.c,v 1.19 2000/06/26 14:21:04 mrg Exp $ */
2
3 /*-
4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9 * Simulation Facility, NASA Ames Research Center.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. All advertising materials mentioning features or use of this software
20 * must display the following acknowledgement:
21 * This product includes software developed by the NetBSD
22 * Foundation, Inc. and its contributors.
23 * 4. Neither the name of The NetBSD Foundation nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 * POSSIBILITY OF SUCH DAMAGE.
38 */
39
40 /*-
41 * Copyright (c) 1992, 1993
42 * The Regents of the University of California. All rights reserved.
43 *
44 * This code is derived from software contributed to Berkeley by
45 * Ralph Campbell and Rick Macklem.
46 *
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
49 * are met:
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. All advertising materials mentioning features or use of this software
56 * must display the following acknowledgement:
57 * This product includes software developed by the University of
58 * California, Berkeley and its contributors.
59 * 4. Neither the name of the University nor the names of its contributors
60 * may be used to endorse or promote products derived from this software
61 * without specific prior written permission.
62 *
63 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
64 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
66 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
67 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
68 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
69 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
70 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
71 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
72 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
73 * SUCH DAMAGE.
74 *
75 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
76 */
77
78 #include "opt_inet.h"
79 #include "bpfilter.h"
80
81 #include <sys/param.h>
82 #include <sys/syslog.h>
83 #include <sys/socket.h>
84 #include <sys/device.h>
85 #include <sys/reboot.h>
86
87 #include <vm/vm.h>
88
89 #include <uvm/uvm_extern.h>
90
91 #include <net/if.h>
92 #include <net/if_ether.h>
93 #include <net/if_media.h>
94
95 #if INET
96 #include <netinet/in.h>
97 #include <netinet/if_inarp.h>
98 #endif
99
100 #include <machine/cpu.h>
101 #include <machine/nexus.h>
102 #include <machine/scb.h>
103
104 #include <dev/ic/lancereg.h>
105 #include <dev/ic/lancevar.h>
106 #include <dev/ic/am7990reg.h>
107 #include <dev/ic/am7990var.h>
108
109 #include "ioconf.h"
110
111 #define LEVEC 0xd4 /* Interrupt vector on 3300/3400 */
112
113 struct le_softc {
114 struct am7990_softc sc_am7990; /* Must be first */
115 struct evcnt sc_intrcnt;
116 volatile u_short *sc_rap;
117 volatile u_short *sc_rdp;
118 };
119
120 int le_ibus_match __P((struct device *, struct cfdata *, void *));
121 void le_ibus_attach __P((struct device *, struct device *, void *));
122 void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
123 u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
124 void lance_copytobuf_gap2 __P((struct lance_softc *, void *, int, int));
125 void lance_copyfrombuf_gap2 __P((struct lance_softc *, void *, int, int));
126 void lance_zerobuf_gap2 __P((struct lance_softc *, int, int));
127
128 struct cfattach le_ibus_ca = {
129 sizeof(struct le_softc), le_ibus_match, le_ibus_attach
130 };
131
132 void
133 lewrcsr(ls, port, val)
134 struct lance_softc *ls;
135 u_int16_t port, val;
136 {
137 struct le_softc *sc = (void *)ls;
138
139 *sc->sc_rap = port;
140 *sc->sc_rdp = val;
141 }
142
143 u_int16_t
144 lerdcsr(ls, port)
145 struct lance_softc *ls;
146 u_int16_t port;
147 {
148 struct le_softc *sc = (void *)ls;
149
150 *sc->sc_rap = port;
151 return *sc->sc_rdp;
152 }
153
154 int
155 le_ibus_match(parent, cf, aux)
156 struct device *parent;
157 struct cfdata *cf;
158 void *aux;
159 {
160 struct bp_conf *bp = aux;
161
162 if (strcmp("lance", bp->type))
163 return 0;
164 return 1;
165 }
166
167 void
168 le_ibus_attach(parent, self, aux)
169 struct device *parent, *self;
170 void *aux;
171 {
172 struct le_softc *sc = (void *)self;
173 int *lance_addr;
174 int i, vec, br;
175
176 sc->sc_rdp = (short *)vax_map_physmem(0x20084400, 1);
177 sc->sc_rap = sc->sc_rdp + 2;
178
179 /*
180 * Set interrupt vector, by forcing an interrupt.
181 */
182 scb_vecref(0, 0); /* Clear vector ref */
183 *sc->sc_rap = LE_CSR0;
184 *sc->sc_rdp = LE_C0_STOP;
185 DELAY(100);
186 *sc->sc_rdp = LE_C0_INIT|LE_C0_INEA;
187 DELAY(100000);
188 i = scb_vecref(&vec, &br);
189 if (i == 0 || vec == 0)
190 return;
191 scb_vecalloc(vec, (void (*)(void *))am7990_intr, sc,
192 SCB_ISTACK, &sc->sc_intrcnt);
193 evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
194 self->dv_xname, "intr");
195
196 printf(": vec %o ipl %x\n%s", vec, br, self->dv_xname);
197 /*
198 * MD functions.
199 */
200 sc->sc_am7990.lsc.sc_rdcsr = lerdcsr;
201 sc->sc_am7990.lsc.sc_wrcsr = lewrcsr;
202 sc->sc_am7990.lsc.sc_nocarrier = NULL;
203
204 sc->sc_am7990.lsc.sc_mem =
205 (void *)uvm_km_valloc(kernel_map, (128 * 1024));
206 if (sc->sc_am7990.lsc.sc_mem == 0)
207 return;
208
209 ioaccess((vaddr_t)sc->sc_am7990.lsc.sc_mem, 0x20120000,
210 (128 * 1024) >> VAX_PGSHIFT);
211
212
213 sc->sc_am7990.lsc.sc_addr = 0;
214 sc->sc_am7990.lsc.sc_memsize = (64 * 1024);
215
216 sc->sc_am7990.lsc.sc_copytodesc = lance_copytobuf_gap2;
217 sc->sc_am7990.lsc.sc_copyfromdesc = lance_copyfrombuf_gap2;
218 sc->sc_am7990.lsc.sc_copytobuf = lance_copytobuf_gap2;
219 sc->sc_am7990.lsc.sc_copyfrombuf = lance_copyfrombuf_gap2;
220 sc->sc_am7990.lsc.sc_zerobuf = lance_zerobuf_gap2;
221
222 /*
223 * Get the ethernet address out of rom
224 */
225 lance_addr = (int *)vax_map_physmem(0x20084200, 1);
226 for (i = 0; i < 6; i++)
227 sc->sc_am7990.lsc.sc_enaddr[i] = (u_char)lance_addr[i];
228 vax_unmap_physmem((vaddr_t)lance_addr, 1);
229
230 bcopy(self->dv_xname, sc->sc_am7990.lsc.sc_ethercom.ec_if.if_xname,
231 IFNAMSIZ);
232 am7990_config(&sc->sc_am7990);
233 }
234
235 /*
236 * gap2: two bytes of data followed by two bytes of pad.
237 *
238 * Buffers must be 4-byte aligned. The code doesn't worry about
239 * doing an extra byte.
240 */
241
242 void
243 lance_copytobuf_gap2(sc, fromv, boff, len)
244 struct lance_softc *sc;
245 void *fromv;
246 int boff;
247 register int len;
248 {
249 volatile caddr_t buf = sc->sc_mem;
250 register caddr_t from = fromv;
251 register volatile u_int16_t *bptr;
252
253 if (boff & 0x1) {
254 /* handle unaligned first byte */
255 bptr = ((volatile u_int16_t *)buf) + (boff - 1);
256 *bptr = (*from++ << 8) | (*bptr & 0xff);
257 bptr += 2;
258 len--;
259 } else
260 bptr = ((volatile u_int16_t *)buf) + boff;
261 while (len > 1) {
262 *bptr = (from[1] << 8) | (from[0] & 0xff);
263 bptr += 2;
264 from += 2;
265 len -= 2;
266 }
267 if (len == 1)
268 *bptr = (u_int16_t)*from;
269 }
270
271 void
272 lance_copyfrombuf_gap2(sc, tov, boff, len)
273 struct lance_softc *sc;
274 void *tov;
275 int boff, len;
276 {
277 volatile caddr_t buf = sc->sc_mem;
278 register caddr_t to = tov;
279 register volatile u_int16_t *bptr;
280 register u_int16_t tmp;
281
282 if (boff & 0x1) {
283 /* handle unaligned first byte */
284 bptr = ((volatile u_int16_t *)buf) + (boff - 1);
285 *to++ = (*bptr >> 8) & 0xff;
286 bptr += 2;
287 len--;
288 } else
289 bptr = ((volatile u_int16_t *)buf) + boff;
290 while (len > 1) {
291 tmp = *bptr;
292 *to++ = tmp & 0xff;
293 *to++ = (tmp >> 8) & 0xff;
294 bptr += 2;
295 len -= 2;
296 }
297 if (len == 1)
298 *to = *bptr & 0xff;
299 }
300
301 void
302 lance_zerobuf_gap2(sc, boff, len)
303 struct lance_softc *sc;
304 int boff, len;
305 {
306 volatile caddr_t buf = sc->sc_mem;
307 register volatile u_int16_t *bptr;
308
309 if ((unsigned)boff & 0x1) {
310 bptr = ((volatile u_int16_t *)buf) + (boff - 1);
311 *bptr &= 0xff;
312 bptr += 2;
313 len--;
314 } else
315 bptr = ((volatile u_int16_t *)buf) + boff;
316 while (len > 0) {
317 *bptr = 0;
318 bptr += 2;
319 len -= 2;
320 }
321 }
322