if_le.c revision 1.13 1 1.13 mycroft /* $NetBSD: if_le.c,v 1.13 1998/08/15 10:18:19 mycroft Exp $ */
2 1.1 ragge
3 1.1 ragge /* #define LE_CHIP_IS_POKEY /* does VS2000 need this ??? */
4 1.1 ragge
5 1.1 ragge /*-
6 1.13 mycroft * Copyright (c) 1998 The NetBSD Foundation, Inc.
7 1.13 mycroft * All rights reserved.
8 1.13 mycroft *
9 1.13 mycroft * This code is derived from software contributed to The NetBSD Foundation
10 1.13 mycroft * by Charles M. Hannum.
11 1.13 mycroft *
12 1.13 mycroft * Redistribution and use in source and binary forms, with or without
13 1.13 mycroft * modification, are permitted provided that the following conditions
14 1.13 mycroft * are met:
15 1.13 mycroft * 1. Redistributions of source code must retain the above copyright
16 1.13 mycroft * notice, this list of conditions and the following disclaimer.
17 1.13 mycroft * 2. Redistributions in binary form must reproduce the above copyright
18 1.13 mycroft * notice, this list of conditions and the following disclaimer in the
19 1.13 mycroft * documentation and/or other materials provided with the distribution.
20 1.13 mycroft * 3. All advertising materials mentioning features or use of this software
21 1.13 mycroft * must display the following acknowledgement:
22 1.13 mycroft * This product includes software developed by the NetBSD
23 1.13 mycroft * Foundation, Inc. and its contributors.
24 1.13 mycroft * 4. Neither the name of The NetBSD Foundation nor the names of its
25 1.13 mycroft * contributors may be used to endorse or promote products derived
26 1.13 mycroft * from this software without specific prior written permission.
27 1.13 mycroft *
28 1.13 mycroft * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
29 1.13 mycroft * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
30 1.13 mycroft * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
31 1.13 mycroft * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
32 1.13 mycroft * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 1.13 mycroft * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 1.13 mycroft * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 1.13 mycroft * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 1.13 mycroft * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 1.13 mycroft * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 1.13 mycroft * POSSIBILITY OF SUCH DAMAGE.
39 1.13 mycroft */
40 1.13 mycroft
41 1.13 mycroft /*-
42 1.1 ragge * Copyright (c) 1992, 1993
43 1.1 ragge * The Regents of the University of California. All rights reserved.
44 1.1 ragge *
45 1.1 ragge * This code is derived from software contributed to Berkeley by
46 1.1 ragge * Ralph Campbell and Rick Macklem.
47 1.1 ragge *
48 1.1 ragge * Redistribution and use in source and binary forms, with or without
49 1.1 ragge * modification, are permitted provided that the following conditions
50 1.1 ragge * are met:
51 1.1 ragge * 1. Redistributions of source code must retain the above copyright
52 1.1 ragge * notice, this list of conditions and the following disclaimer.
53 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
54 1.1 ragge * notice, this list of conditions and the following disclaimer in the
55 1.1 ragge * documentation and/or other materials provided with the distribution.
56 1.1 ragge * 3. All advertising materials mentioning features or use of this software
57 1.1 ragge * must display the following acknowledgement:
58 1.1 ragge * This product includes software developed by the University of
59 1.1 ragge * California, Berkeley and its contributors.
60 1.1 ragge * 4. Neither the name of the University nor the names of its contributors
61 1.1 ragge * may be used to endorse or promote products derived from this software
62 1.1 ragge * without specific prior written permission.
63 1.1 ragge *
64 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
65 1.1 ragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
66 1.1 ragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
67 1.1 ragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
68 1.1 ragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
69 1.1 ragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
70 1.1 ragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
71 1.1 ragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
72 1.1 ragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
73 1.1 ragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 1.1 ragge * SUCH DAMAGE.
75 1.1 ragge *
76 1.1 ragge * @(#)if_le.c 8.2 (Berkeley) 11/16/93
77 1.1 ragge */
78 1.1 ragge
79 1.11 jonathan #include "opt_inet.h"
80 1.1 ragge #include "bpfilter.h"
81 1.1 ragge
82 1.1 ragge #include <sys/param.h>
83 1.1 ragge #include <sys/syslog.h>
84 1.1 ragge #include <sys/socket.h>
85 1.1 ragge #include <sys/device.h>
86 1.5 ragge #include <sys/reboot.h>
87 1.1 ragge
88 1.1 ragge #include <net/if.h>
89 1.6 is #include <net/if_ether.h>
90 1.7 thorpej #include <net/if_media.h>
91 1.1 ragge
92 1.1 ragge #if INET
93 1.1 ragge #include <netinet/in.h>
94 1.6 is #include <netinet/if_inarp.h>
95 1.1 ragge #endif
96 1.1 ragge
97 1.1 ragge /*
98 1.1 ragge * This would be nice, but it's not yet there...
99 1.1 ragge *
100 1.1 ragge * #include <machine/autoconf.h>
101 1.1 ragge */
102 1.1 ragge
103 1.1 ragge #include <machine/pte.h>
104 1.1 ragge #include <machine/cpu.h>
105 1.1 ragge #include <machine/mtpr.h>
106 1.1 ragge #include <machine/uvax.h>
107 1.1 ragge #include <machine/ka410.h>
108 1.1 ragge #include <machine/vsbus.h>
109 1.5 ragge #include <machine/rpb.h>
110 1.1 ragge
111 1.12 drochner #include <dev/ic/lancereg.h>
112 1.12 drochner #include <dev/ic/lancevar.h>
113 1.1 ragge #include <dev/ic/am7990reg.h>
114 1.1 ragge #define LE_NEED_BUF_CONTIG
115 1.1 ragge #include <dev/ic/am7990var.h>
116 1.1 ragge
117 1.1 ragge #include <dev/tc/if_levar.h>
118 1.1 ragge
119 1.1 ragge #define xdebug(x)
120 1.1 ragge
121 1.1 ragge #ifdef LE_CHIP_IS_POKEY
122 1.1 ragge /*
123 1.1 ragge * access LANCE registers and double-check their contents
124 1.1 ragge */
125 1.1 ragge #define wbflush() /* do nothing */
126 1.1 ragge void lewritereg();
127 1.1 ragge #define LERDWR(cntl, src, dst) { (dst) = (src); wbflush(); }
128 1.1 ragge #define LEWREG(src, dst) lewritereg(&(dst), (src))
129 1.1 ragge #endif
130 1.1 ragge
131 1.1 ragge #define LE_IOSIZE 64*1024 /* 64K of real-mem are reserved and already */
132 1.1 ragge extern void *le_iomem; /* mapped into virt-mem by cpu_steal_pages */
133 1.1 ragge extern u_long le_ioaddr; /* le_iomem is virt, le_ioaddr is phys */
134 1.1 ragge
135 1.1 ragge #define LE_SOFTC(unit) le_cd.cd_devs[unit]
136 1.1 ragge #define LE_DELAY(x) DELAY(x)
137 1.1 ragge
138 1.10 ragge int lematch __P((struct device *, struct cfdata *, void *));
139 1.1 ragge void leattach __P((struct device *, struct device *, void *));
140 1.1 ragge
141 1.1 ragge int leintr __P((void *sc));
142 1.1 ragge
143 1.1 ragge struct cfattach le_ca = {
144 1.1 ragge sizeof(struct le_softc), lematch, leattach
145 1.1 ragge };
146 1.9 thorpej
147 1.9 thorpej extern struct cfdriver le_cd;
148 1.1 ragge
149 1.12 drochner #if defined(_KERNEL) && !defined(_LKM)
150 1.12 drochner #include "opt_ddb.h"
151 1.12 drochner #endif
152 1.12 drochner
153 1.12 drochner #ifdef DDB
154 1.12 drochner #define integrate
155 1.12 drochner #define hide
156 1.12 drochner #else
157 1.12 drochner #define integrate static __inline
158 1.12 drochner #define hide static
159 1.12 drochner #endif
160 1.12 drochner
161 1.12 drochner hide void lewrcsr __P ((struct lance_softc *, u_int16_t, u_int16_t));
162 1.12 drochner hide u_int16_t lerdcsr __P ((struct lance_softc *, u_int16_t));
163 1.4 ragge
164 1.4 ragge hide void
165 1.1 ragge lewrcsr(sc, port, val)
166 1.12 drochner struct lance_softc *sc;
167 1.1 ragge u_int16_t port, val;
168 1.1 ragge {
169 1.4 ragge struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
170 1.1 ragge
171 1.1 ragge #ifdef LE_CHIP_IS_POKEY
172 1.1 ragge LEWREG(port, ler1->ler1_rap);
173 1.1 ragge LERDWR(port, val, ler1->ler1_rdp);
174 1.1 ragge #else
175 1.1 ragge ler1->ler1_rap = port;
176 1.1 ragge ler1->ler1_rdp = val;
177 1.1 ragge #endif
178 1.1 ragge }
179 1.1 ragge
180 1.4 ragge hide u_int16_t
181 1.1 ragge lerdcsr(sc, port)
182 1.12 drochner struct lance_softc *sc;
183 1.1 ragge u_int16_t port;
184 1.1 ragge {
185 1.4 ragge struct lereg1 *ler1 = ((struct le_softc *)sc)->sc_r1;
186 1.1 ragge u_int16_t val;
187 1.1 ragge
188 1.1 ragge #ifdef LE_CHIP_IS_POKEY
189 1.1 ragge LEWREG(port, ler1->ler1_rap);
190 1.1 ragge LERDWR(0, ler1->ler1_rdp, val);
191 1.1 ragge #else
192 1.1 ragge ler1->ler1_rap = port;
193 1.1 ragge val = ler1->ler1_rdp;
194 1.1 ragge #endif
195 1.1 ragge return (val);
196 1.1 ragge }
197 1.1 ragge
198 1.4 ragge integrate void
199 1.4 ragge lehwinit(sc)
200 1.12 drochner struct lance_softc *sc;
201 1.4 ragge {
202 1.4 ragge }
203 1.4 ragge
204 1.1 ragge int
205 1.10 ragge lematch(parent, cf, aux)
206 1.1 ragge struct device *parent;
207 1.10 ragge struct cfdata *cf;
208 1.10 ragge void *aux;
209 1.1 ragge {
210 1.1 ragge struct confargs *ca = aux;
211 1.1 ragge
212 1.1 ragge /*
213 1.1 ragge * There could/should be more checks, but for now...
214 1.1 ragge */
215 1.1 ragge if (strcmp(ca->ca_name, "le") &&
216 1.1 ragge strcmp(ca->ca_name, "am7990") &&
217 1.1 ragge strcmp(ca->ca_name, "AM7990"))
218 1.1 ragge return (0);
219 1.1 ragge
220 1.1 ragge return (1);
221 1.1 ragge }
222 1.1 ragge
223 1.1 ragge /*
224 1.1 ragge *
225 1.1 ragge */
226 1.1 ragge void
227 1.1 ragge leattach(parent, self, aux)
228 1.1 ragge struct device *parent, *self;
229 1.1 ragge void *aux;
230 1.1 ragge {
231 1.1 ragge register struct le_softc *sc = (void *)self;
232 1.1 ragge struct confargs *ca = aux;
233 1.1 ragge u_char *cp; /* pointer to MAC address */
234 1.1 ragge int i;
235 1.1 ragge
236 1.1 ragge sc->sc_r1 = (void*)uvax_phys2virt(ca->ca_ioaddr);
237 1.1 ragge
238 1.12 drochner sc->sc_am7990.lsc.sc_conf3 = 0;
239 1.12 drochner sc->sc_am7990.lsc.sc_mem = le_iomem;
240 1.12 drochner sc->sc_am7990.lsc.sc_addr = le_ioaddr;
241 1.12 drochner sc->sc_am7990.lsc.sc_memsize = LE_IOSIZE;
242 1.12 drochner sc->sc_am7990.lsc.sc_wrcsr = lewrcsr;
243 1.12 drochner sc->sc_am7990.lsc.sc_rdcsr = lerdcsr;
244 1.12 drochner sc->sc_am7990.lsc.sc_hwinit = lehwinit;
245 1.12 drochner sc->sc_am7990.lsc.sc_nocarrier = NULL;
246 1.1 ragge
247 1.1 ragge xdebug(("leattach: mem=%x, addr=%x, size=%x (%d)\n",
248 1.12 drochner sc->sc_am7990.lsc.sc_mem, sc->sc_am7990.lsc.sc_addr,
249 1.12 drochner sc->sc_am7990.lsc.sc_memsize, sc->sc_am7990.lsc.sc_memsize));
250 1.1 ragge
251 1.12 drochner sc->sc_am7990.lsc.sc_copytodesc = lance_copytobuf_contig;
252 1.12 drochner sc->sc_am7990.lsc.sc_copyfromdesc = lance_copyfrombuf_contig;
253 1.12 drochner sc->sc_am7990.lsc.sc_copytobuf = lance_copytobuf_contig;
254 1.12 drochner sc->sc_am7990.lsc.sc_copyfrombuf = lance_copyfrombuf_contig;
255 1.12 drochner sc->sc_am7990.lsc.sc_zerobuf = lance_zerobuf_contig;
256 1.1 ragge
257 1.1 ragge /*
258 1.1 ragge * Get the ethernet address out of rom
259 1.1 ragge */
260 1.12 drochner for (i = 0; i < sizeof(sc->sc_am7990.lsc.sc_enaddr); i++) {
261 1.1 ragge int *eaddr = (void*)uvax_phys2virt(ca->ca_enaddr);
262 1.12 drochner sc->sc_am7990.lsc.sc_enaddr[i] = (u_char)eaddr[i];
263 1.1 ragge }
264 1.1 ragge
265 1.12 drochner bcopy(self->dv_xname, sc->sc_am7990.lsc.sc_ethercom.ec_if.if_xname,
266 1.6 is IFNAMSIZ);
267 1.1 ragge am7990_config(&sc->sc_am7990);
268 1.1 ragge
269 1.1 ragge #ifdef LEDEBUG
270 1.12 drochner sc->sc_am7990.lsc.sc_debug = LEDEBUG;
271 1.1 ragge #endif
272 1.1 ragge
273 1.1 ragge vsbus_intr_register(ca, am7990_intr, &sc->sc_am7990);
274 1.1 ragge vsbus_intr_enable(ca);
275 1.5 ragge
276 1.5 ragge /*
277 1.5 ragge * Register this device as boot device if we booted from it.
278 1.5 ragge * This will fail if there are more than one le in a machine,
279 1.5 ragge * fortunately there may be only one.
280 1.5 ragge */
281 1.5 ragge if (B_TYPE(bootdev) == BDEV_LE)
282 1.5 ragge booted_from = self;
283 1.1 ragge }
284 1.1 ragge
285 1.1 ragge #ifdef LE_CHIP_IS_POKEY
286 1.1 ragge /*
287 1.1 ragge * Write a lance register port, reading it back to ensure success. This seems
288 1.1 ragge * to be necessary during initialization, since the chip appears to be a bit
289 1.1 ragge * pokey sometimes.
290 1.1 ragge */
291 1.1 ragge void
292 1.1 ragge lewritereg(regptr, val)
293 1.1 ragge register volatile u_short *regptr;
294 1.1 ragge register u_short val;
295 1.1 ragge {
296 1.1 ragge register int i = 0;
297 1.1 ragge
298 1.1 ragge while (*regptr != val) {
299 1.1 ragge *regptr = val;
300 1.1 ragge wbflush();
301 1.1 ragge if (++i > 10000) {
302 1.3 christos printf("le: Reg did not settle (to x%x): x%x\n", val,
303 1.1 ragge *regptr);
304 1.1 ragge return;
305 1.1 ragge }
306 1.1 ragge DELAY(100);
307 1.1 ragge }
308 1.1 ragge }
309 1.1 ragge #endif
310