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