if_le.c revision 1.48.8.2 1 1.48.8.2 nathanw /* $NetBSD: if_le.c,v 1.48.8.2 2002/04/01 07:39:52 nathanw Exp $ */
2 1.48.8.2 nathanw
3 1.48.8.2 nathanw /*-
4 1.48.8.2 nathanw * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 1.48.8.2 nathanw * All rights reserved.
6 1.48.8.2 nathanw *
7 1.48.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.48.8.2 nathanw * by Charles M. Hannum and by Jason R. Thorpe.
9 1.48.8.2 nathanw *
10 1.48.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.48.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.48.8.2 nathanw * are met:
13 1.48.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.48.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.48.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.48.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.48.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.48.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.48.8.2 nathanw * must display the following acknowledgement:
20 1.48.8.2 nathanw * This product includes software developed by the NetBSD
21 1.48.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.48.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.48.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.48.8.2 nathanw * from this software without specific prior written permission.
25 1.48.8.2 nathanw *
26 1.48.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.48.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.48.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.48.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.48.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.48.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.48.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.48.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.48.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.48.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.48.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.48.8.2 nathanw */
38 1.48.8.2 nathanw
39 1.48.8.2 nathanw /*-
40 1.48.8.2 nathanw * Copyright (c) 1992, 1993
41 1.48.8.2 nathanw * The Regents of the University of California. All rights reserved.
42 1.48.8.2 nathanw *
43 1.48.8.2 nathanw * This code is derived from software contributed to Berkeley by
44 1.48.8.2 nathanw * Ralph Campbell and Rick Macklem.
45 1.48.8.2 nathanw *
46 1.48.8.2 nathanw * Redistribution and use in source and binary forms, with or without
47 1.48.8.2 nathanw * modification, are permitted provided that the following conditions
48 1.48.8.2 nathanw * are met:
49 1.48.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
50 1.48.8.2 nathanw * notice, this list of conditions and the following disclaimer.
51 1.48.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
52 1.48.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
53 1.48.8.2 nathanw * documentation and/or other materials provided with the distribution.
54 1.48.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
55 1.48.8.2 nathanw * must display the following acknowledgement:
56 1.48.8.2 nathanw * This product includes software developed by the University of
57 1.48.8.2 nathanw * California, Berkeley and its contributors.
58 1.48.8.2 nathanw * 4. Neither the name of the University nor the names of its contributors
59 1.48.8.2 nathanw * may be used to endorse or promote products derived from this software
60 1.48.8.2 nathanw * without specific prior written permission.
61 1.48.8.2 nathanw *
62 1.48.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 1.48.8.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 1.48.8.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 1.48.8.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 1.48.8.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 1.48.8.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 1.48.8.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 1.48.8.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 1.48.8.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 1.48.8.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
72 1.48.8.2 nathanw * SUCH DAMAGE.
73 1.48.8.2 nathanw *
74 1.48.8.2 nathanw * @(#)if_le.c 8.2 (Berkeley) 11/16/93
75 1.48.8.2 nathanw */
76 1.48.8.2 nathanw
77 1.48.8.2 nathanw #include <sys/cdefs.h>
78 1.48.8.2 nathanw __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.48.8.2 2002/04/01 07:39:52 nathanw Exp $");
79 1.48.8.2 nathanw
80 1.48.8.2 nathanw #include "opt_inet.h"
81 1.48.8.2 nathanw #include "bpfilter.h"
82 1.48.8.2 nathanw
83 1.48.8.2 nathanw #include <sys/param.h>
84 1.48.8.2 nathanw #include <sys/systm.h>
85 1.48.8.2 nathanw #include <sys/mbuf.h>
86 1.48.8.2 nathanw #include <sys/syslog.h>
87 1.48.8.2 nathanw #include <sys/socket.h>
88 1.48.8.2 nathanw #include <sys/device.h>
89 1.48.8.2 nathanw
90 1.48.8.2 nathanw #include <net/if.h>
91 1.48.8.2 nathanw #include <net/if_ether.h>
92 1.48.8.2 nathanw #include <net/if_media.h>
93 1.48.8.2 nathanw
94 1.48.8.2 nathanw #ifdef INET
95 1.48.8.2 nathanw #include <netinet/in.h>
96 1.48.8.2 nathanw #include <netinet/if_inarp.h>
97 1.48.8.2 nathanw #endif
98 1.48.8.2 nathanw
99 1.48.8.2 nathanw #include <machine/autoconf.h>
100 1.48.8.2 nathanw #include <machine/cpu.h>
101 1.48.8.2 nathanw #include <machine/intr.h>
102 1.48.8.2 nathanw
103 1.48.8.2 nathanw #include <dev/ic/lancereg.h>
104 1.48.8.2 nathanw #include <dev/ic/lancevar.h>
105 1.48.8.2 nathanw #include <dev/ic/am7990reg.h>
106 1.48.8.2 nathanw #include <dev/ic/am7990var.h>
107 1.48.8.2 nathanw
108 1.48.8.2 nathanw #include <hp300/dev/dioreg.h>
109 1.48.8.2 nathanw #include <hp300/dev/diovar.h>
110 1.48.8.2 nathanw #include <hp300/dev/diodevs.h>
111 1.48.8.2 nathanw #include <hp300/dev/if_lereg.h>
112 1.48.8.2 nathanw #include <hp300/dev/if_levar.h>
113 1.48.8.2 nathanw
114 1.48.8.2 nathanw #include "opt_useleds.h"
115 1.48.8.2 nathanw
116 1.48.8.2 nathanw #ifdef USELEDS
117 1.48.8.2 nathanw #include <hp300/hp300/leds.h>
118 1.48.8.2 nathanw #endif
119 1.48.8.2 nathanw
120 1.48.8.2 nathanw int lematch __P((struct device *, struct cfdata *, void *));
121 1.48.8.2 nathanw void leattach __P((struct device *, struct device *, void *));
122 1.48.8.2 nathanw
123 1.48.8.2 nathanw struct cfattach le_ca = {
124 1.48.8.2 nathanw sizeof(struct le_softc), lematch, leattach
125 1.48.8.2 nathanw };
126 1.48.8.2 nathanw
127 1.48.8.2 nathanw int leintr __P((void *));
128 1.48.8.2 nathanw
129 1.48.8.2 nathanw #if defined(_KERNEL_OPT)
130 1.48.8.2 nathanw #include "opt_ddb.h"
131 1.48.8.2 nathanw #endif
132 1.48.8.2 nathanw
133 1.48.8.2 nathanw #ifdef DDB
134 1.48.8.2 nathanw #define integrate
135 1.48.8.2 nathanw #define hide
136 1.48.8.2 nathanw #else
137 1.48.8.2 nathanw #define integrate static __inline
138 1.48.8.2 nathanw #define hide static
139 1.48.8.2 nathanw #endif
140 1.48.8.2 nathanw
141 1.48.8.2 nathanw hide void le_copytobuf __P((struct lance_softc *, void *, int, int));
142 1.48.8.2 nathanw hide void le_copyfrombuf __P((struct lance_softc *, void *, int, int));
143 1.48.8.2 nathanw hide void le_zerobuf __P((struct lance_softc *, int, int));
144 1.48.8.2 nathanw
145 1.48.8.2 nathanw /* offsets for: ID, REGS, MEM, NVRAM */
146 1.48.8.2 nathanw int lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
147 1.48.8.2 nathanw
148 1.48.8.2 nathanw hide void lewrcsr __P((struct lance_softc *, u_int16_t, u_int16_t));
149 1.48.8.2 nathanw hide u_int16_t lerdcsr __P((struct lance_softc *, u_int16_t));
150 1.48.8.2 nathanw
151 1.48.8.2 nathanw hide void
152 1.48.8.2 nathanw lewrcsr(sc, port, val)
153 1.48.8.2 nathanw struct lance_softc *sc;
154 1.48.8.2 nathanw u_int16_t port, val;
155 1.48.8.2 nathanw {
156 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)sc;
157 1.48.8.2 nathanw bus_space_tag_t bst = lesc->sc_bst;
158 1.48.8.2 nathanw bus_space_handle_t bsh0 = lesc->sc_bsh0;
159 1.48.8.2 nathanw bus_space_handle_t bsh1 = lesc->sc_bsh1;
160 1.48.8.2 nathanw
161 1.48.8.2 nathanw do {
162 1.48.8.2 nathanw bus_space_write_2(bst, bsh1, LER1_RAP, port);
163 1.48.8.2 nathanw } while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
164 1.48.8.2 nathanw do {
165 1.48.8.2 nathanw bus_space_write_2(bst, bsh1, LER1_RDP, val);
166 1.48.8.2 nathanw } while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
167 1.48.8.2 nathanw }
168 1.48.8.2 nathanw
169 1.48.8.2 nathanw hide u_int16_t
170 1.48.8.2 nathanw lerdcsr(sc, port)
171 1.48.8.2 nathanw struct lance_softc *sc;
172 1.48.8.2 nathanw u_int16_t port;
173 1.48.8.2 nathanw {
174 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)sc;
175 1.48.8.2 nathanw bus_space_tag_t bst = lesc->sc_bst;
176 1.48.8.2 nathanw bus_space_handle_t bsh0 = lesc->sc_bsh0;
177 1.48.8.2 nathanw bus_space_handle_t bsh1 = lesc->sc_bsh1;
178 1.48.8.2 nathanw u_int16_t val;
179 1.48.8.2 nathanw
180 1.48.8.2 nathanw do {
181 1.48.8.2 nathanw bus_space_write_2(bst, bsh1, LER1_RAP, port);
182 1.48.8.2 nathanw } while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
183 1.48.8.2 nathanw do {
184 1.48.8.2 nathanw val = bus_space_read_2(bst, bsh1, LER1_RDP);
185 1.48.8.2 nathanw } while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
186 1.48.8.2 nathanw
187 1.48.8.2 nathanw return (val);
188 1.48.8.2 nathanw }
189 1.48.8.2 nathanw
190 1.48.8.2 nathanw int
191 1.48.8.2 nathanw lematch(parent, match, aux)
192 1.48.8.2 nathanw struct device *parent;
193 1.48.8.2 nathanw struct cfdata *match;
194 1.48.8.2 nathanw void *aux;
195 1.48.8.2 nathanw {
196 1.48.8.2 nathanw struct dio_attach_args *da = aux;
197 1.48.8.2 nathanw
198 1.48.8.2 nathanw if (da->da_id == DIO_DEVICE_ID_LAN)
199 1.48.8.2 nathanw return (1);
200 1.48.8.2 nathanw return (0);
201 1.48.8.2 nathanw }
202 1.48.8.2 nathanw
203 1.48.8.2 nathanw /*
204 1.48.8.2 nathanw * Interface exists: make available by filling in network interface
205 1.48.8.2 nathanw * record. System will initialize the interface when it is ready
206 1.48.8.2 nathanw * to accept packets.
207 1.48.8.2 nathanw */
208 1.48.8.2 nathanw void
209 1.48.8.2 nathanw leattach(parent, self, aux)
210 1.48.8.2 nathanw struct device *parent, *self;
211 1.48.8.2 nathanw void *aux;
212 1.48.8.2 nathanw {
213 1.48.8.2 nathanw struct dio_attach_args *da = aux;
214 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)self;
215 1.48.8.2 nathanw struct lance_softc *sc = &lesc->sc_am7990.lsc;
216 1.48.8.2 nathanw bus_space_tag_t bst = da->da_bst;
217 1.48.8.2 nathanw bus_space_handle_t bsh0, bsh1, bsh2;
218 1.48.8.2 nathanw bus_size_t offset;
219 1.48.8.2 nathanw int i, ipl;
220 1.48.8.2 nathanw
221 1.48.8.2 nathanw if (bus_space_map(bst, (bus_addr_t)dio_scodetopa(da->da_scode),
222 1.48.8.2 nathanw da->da_size, 0, &bsh0)) {
223 1.48.8.2 nathanw printf("\n%s: can't map LANCE registers\n",
224 1.48.8.2 nathanw sc->sc_dev.dv_xname);
225 1.48.8.2 nathanw return;
226 1.48.8.2 nathanw }
227 1.48.8.2 nathanw
228 1.48.8.2 nathanw if (bus_space_subregion(bst, bsh0, lestd[1], LER1_SIZE, &bsh1)) {
229 1.48.8.2 nathanw printf("\n%s: can't subregion LANCE space\n",
230 1.48.8.2 nathanw sc->sc_dev.dv_xname);
231 1.48.8.2 nathanw return;
232 1.48.8.2 nathanw }
233 1.48.8.2 nathanw
234 1.48.8.2 nathanw if (bus_space_subregion(bst, bsh0, lestd[2], LE_BUFSIZE, &bsh2)) {
235 1.48.8.2 nathanw printf("\n%s: can't subregion buffer space\n",
236 1.48.8.2 nathanw sc->sc_dev.dv_xname);
237 1.48.8.2 nathanw return;
238 1.48.8.2 nathanw }
239 1.48.8.2 nathanw
240 1.48.8.2 nathanw lesc->sc_bst = bst;
241 1.48.8.2 nathanw lesc->sc_bsh0 = bsh0;
242 1.48.8.2 nathanw lesc->sc_bsh1 = bsh1;
243 1.48.8.2 nathanw lesc->sc_bsh2 = bsh2;
244 1.48.8.2 nathanw
245 1.48.8.2 nathanw bus_space_write_1(bst, bsh0, LER0_ID, 0xff);
246 1.48.8.2 nathanw DELAY(100);
247 1.48.8.2 nathanw
248 1.48.8.2 nathanw ipl = DIO_IPL((caddr_t)bsh0); /* XXX */
249 1.48.8.2 nathanw printf(" ipl %d", ipl);
250 1.48.8.2 nathanw
251 1.48.8.2 nathanw sc->sc_conf3 = LE_C3_BSWP;
252 1.48.8.2 nathanw sc->sc_addr = 0;
253 1.48.8.2 nathanw sc->sc_memsize = LE_BUFSIZE;
254 1.48.8.2 nathanw
255 1.48.8.2 nathanw /*
256 1.48.8.2 nathanw * Read the ethernet address off the board, one nibble at a time.
257 1.48.8.2 nathanw */
258 1.48.8.2 nathanw offset = lestd[3];
259 1.48.8.2 nathanw for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
260 1.48.8.2 nathanw sc->sc_enaddr[i] =
261 1.48.8.2 nathanw (bus_space_read_1(bst, bsh0, ++offset) & 0xf) << 4;
262 1.48.8.2 nathanw offset++;
263 1.48.8.2 nathanw sc->sc_enaddr[i] |=
264 1.48.8.2 nathanw (bus_space_read_1(bst, bsh0, ++offset) & 0xf);
265 1.48.8.2 nathanw offset++;
266 1.48.8.2 nathanw }
267 1.48.8.2 nathanw
268 1.48.8.2 nathanw sc->sc_copytodesc = le_copytobuf;
269 1.48.8.2 nathanw sc->sc_copyfromdesc = le_copyfrombuf;
270 1.48.8.2 nathanw sc->sc_copytobuf = le_copytobuf;
271 1.48.8.2 nathanw sc->sc_copyfrombuf = le_copyfrombuf;
272 1.48.8.2 nathanw sc->sc_zerobuf = le_zerobuf;
273 1.48.8.2 nathanw
274 1.48.8.2 nathanw sc->sc_rdcsr = lerdcsr;
275 1.48.8.2 nathanw sc->sc_wrcsr = lewrcsr;
276 1.48.8.2 nathanw sc->sc_hwinit = NULL;
277 1.48.8.2 nathanw
278 1.48.8.2 nathanw am7990_config(&lesc->sc_am7990);
279 1.48.8.2 nathanw
280 1.48.8.2 nathanw /* Establish the interrupt handler. */
281 1.48.8.2 nathanw (void) dio_intr_establish(leintr, sc, ipl, IPL_NET);
282 1.48.8.2 nathanw bus_space_write_1(bst, bsh0, LER0_STATUS, LE_IE);
283 1.48.8.2 nathanw }
284 1.48.8.2 nathanw
285 1.48.8.2 nathanw int
286 1.48.8.2 nathanw leintr(arg)
287 1.48.8.2 nathanw void *arg;
288 1.48.8.2 nathanw {
289 1.48.8.2 nathanw struct lance_softc *sc = arg;
290 1.48.8.2 nathanw #ifdef USELEDS
291 1.48.8.2 nathanw u_int16_t isr;
292 1.48.8.2 nathanw
293 1.48.8.2 nathanw isr = lerdcsr(sc, LE_CSR0);
294 1.48.8.2 nathanw
295 1.48.8.2 nathanw if ((isr & LE_C0_INTR) == 0)
296 1.48.8.2 nathanw return (0);
297 1.48.8.2 nathanw
298 1.48.8.2 nathanw if (isr & LE_C0_RINT)
299 1.48.8.2 nathanw ledcontrol(0, 0, LED_LANRCV);
300 1.48.8.2 nathanw
301 1.48.8.2 nathanw if (isr & LE_C0_TINT)
302 1.48.8.2 nathanw ledcontrol(0, 0, LED_LANXMT);
303 1.48.8.2 nathanw #endif /* USELEDS */
304 1.48.8.2 nathanw
305 1.48.8.2 nathanw return (am7990_intr(sc));
306 1.48.8.2 nathanw }
307 1.48.8.2 nathanw
308 1.48.8.2 nathanw hide void
309 1.48.8.2 nathanw le_copytobuf(sc, from, boff, len)
310 1.48.8.2 nathanw struct lance_softc *sc;
311 1.48.8.2 nathanw void *from;
312 1.48.8.2 nathanw int boff, len;
313 1.48.8.2 nathanw {
314 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)sc;
315 1.48.8.2 nathanw
316 1.48.8.2 nathanw bus_space_write_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, from, len);
317 1.48.8.2 nathanw }
318 1.48.8.2 nathanw
319 1.48.8.2 nathanw hide void
320 1.48.8.2 nathanw le_copyfrombuf(sc, to, boff, len)
321 1.48.8.2 nathanw struct lance_softc *sc;
322 1.48.8.2 nathanw void *to;
323 1.48.8.2 nathanw int boff, len;
324 1.48.8.2 nathanw {
325 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)sc;
326 1.48.8.2 nathanw
327 1.48.8.2 nathanw bus_space_read_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, to, len);
328 1.48.8.2 nathanw }
329 1.48.8.2 nathanw
330 1.48.8.2 nathanw hide void
331 1.48.8.2 nathanw le_zerobuf(sc, boff, len)
332 1.48.8.2 nathanw struct lance_softc *sc;
333 1.48.8.2 nathanw int boff, len;
334 1.48.8.2 nathanw {
335 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)sc;
336 1.48.8.2 nathanw
337 1.48.8.2 nathanw bus_space_set_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, 0, len);
338 1.48.8.2 nathanw }
339