if_le.c revision 1.48.8.4 1 1.48.8.4 nathanw /* $NetBSD: if_le.c,v 1.48.8.4 2002/11/11 21:58:15 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.4 nathanw __KERNEL_RCSID(0, "$NetBSD: if_le.c,v 1.48.8.4 2002/11/11 21:58:15 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/device.h>
86 1.48.8.2 nathanw
87 1.48.8.2 nathanw #include <net/if.h>
88 1.48.8.2 nathanw #include <net/if_ether.h>
89 1.48.8.2 nathanw #include <net/if_media.h>
90 1.48.8.2 nathanw
91 1.48.8.2 nathanw #include <dev/ic/lancereg.h>
92 1.48.8.2 nathanw #include <dev/ic/lancevar.h>
93 1.48.8.2 nathanw #include <dev/ic/am7990var.h>
94 1.48.8.2 nathanw
95 1.48.8.2 nathanw #include <hp300/dev/dioreg.h>
96 1.48.8.2 nathanw #include <hp300/dev/diovar.h>
97 1.48.8.2 nathanw #include <hp300/dev/diodevs.h>
98 1.48.8.2 nathanw #include <hp300/dev/if_lereg.h>
99 1.48.8.2 nathanw
100 1.48.8.2 nathanw #include "opt_useleds.h"
101 1.48.8.2 nathanw
102 1.48.8.2 nathanw #ifdef USELEDS
103 1.48.8.2 nathanw #include <hp300/hp300/leds.h>
104 1.48.8.2 nathanw #endif
105 1.48.8.2 nathanw
106 1.48.8.4 nathanw struct le_softc {
107 1.48.8.4 nathanw struct am7990_softc sc_am7990; /* glue to MI code */
108 1.48.8.4 nathanw
109 1.48.8.4 nathanw bus_space_tag_t sc_bst;
110 1.48.8.4 nathanw
111 1.48.8.4 nathanw bus_space_handle_t sc_bsh0; /* DIO registers */
112 1.48.8.4 nathanw bus_space_handle_t sc_bsh1; /* LANCE registers */
113 1.48.8.4 nathanw bus_space_handle_t sc_bsh2; /* buffer area */
114 1.48.8.4 nathanw };
115 1.48.8.4 nathanw
116 1.48.8.4 nathanw int lematch(struct device *, struct cfdata *, void *);
117 1.48.8.4 nathanw void leattach(struct device *, struct device *, void *);
118 1.48.8.2 nathanw
119 1.48.8.3 nathanw CFATTACH_DECL(le, sizeof(struct le_softc),
120 1.48.8.3 nathanw lematch, leattach, NULL, NULL);
121 1.48.8.2 nathanw
122 1.48.8.4 nathanw int leintr(void *);
123 1.48.8.2 nathanw
124 1.48.8.2 nathanw #if defined(_KERNEL_OPT)
125 1.48.8.2 nathanw #include "opt_ddb.h"
126 1.48.8.2 nathanw #endif
127 1.48.8.2 nathanw
128 1.48.8.2 nathanw #ifdef DDB
129 1.48.8.2 nathanw #define integrate
130 1.48.8.2 nathanw #define hide
131 1.48.8.2 nathanw #else
132 1.48.8.2 nathanw #define integrate static __inline
133 1.48.8.2 nathanw #define hide static
134 1.48.8.2 nathanw #endif
135 1.48.8.2 nathanw
136 1.48.8.4 nathanw hide void le_copytobuf(struct lance_softc *, void *, int, int);
137 1.48.8.4 nathanw hide void le_copyfrombuf(struct lance_softc *, void *, int, int);
138 1.48.8.4 nathanw hide void le_zerobuf(struct lance_softc *, int, int);
139 1.48.8.2 nathanw
140 1.48.8.2 nathanw /* offsets for: ID, REGS, MEM, NVRAM */
141 1.48.8.2 nathanw int lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
142 1.48.8.2 nathanw
143 1.48.8.4 nathanw hide void lewrcsr(struct lance_softc *, u_int16_t, u_int16_t);
144 1.48.8.4 nathanw hide u_int16_t lerdcsr(struct lance_softc *, u_int16_t);
145 1.48.8.2 nathanw
146 1.48.8.2 nathanw hide void
147 1.48.8.4 nathanw lewrcsr(struct lance_softc *sc, u_int16_t port, u_int16_t val)
148 1.48.8.2 nathanw {
149 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)sc;
150 1.48.8.2 nathanw bus_space_tag_t bst = lesc->sc_bst;
151 1.48.8.2 nathanw bus_space_handle_t bsh0 = lesc->sc_bsh0;
152 1.48.8.2 nathanw bus_space_handle_t bsh1 = lesc->sc_bsh1;
153 1.48.8.2 nathanw
154 1.48.8.2 nathanw do {
155 1.48.8.2 nathanw bus_space_write_2(bst, bsh1, LER1_RAP, port);
156 1.48.8.2 nathanw } while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
157 1.48.8.2 nathanw do {
158 1.48.8.2 nathanw bus_space_write_2(bst, bsh1, LER1_RDP, val);
159 1.48.8.2 nathanw } while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
160 1.48.8.2 nathanw }
161 1.48.8.2 nathanw
162 1.48.8.2 nathanw hide u_int16_t
163 1.48.8.4 nathanw lerdcsr(struct lance_softc *sc, u_int16_t port)
164 1.48.8.2 nathanw {
165 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)sc;
166 1.48.8.2 nathanw bus_space_tag_t bst = lesc->sc_bst;
167 1.48.8.2 nathanw bus_space_handle_t bsh0 = lesc->sc_bsh0;
168 1.48.8.2 nathanw bus_space_handle_t bsh1 = lesc->sc_bsh1;
169 1.48.8.2 nathanw u_int16_t val;
170 1.48.8.2 nathanw
171 1.48.8.2 nathanw do {
172 1.48.8.2 nathanw bus_space_write_2(bst, bsh1, LER1_RAP, port);
173 1.48.8.2 nathanw } while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
174 1.48.8.2 nathanw do {
175 1.48.8.2 nathanw val = bus_space_read_2(bst, bsh1, LER1_RDP);
176 1.48.8.2 nathanw } while ((bus_space_read_1(bst, bsh0, LER0_STATUS) & LE_ACK) == 0);
177 1.48.8.2 nathanw
178 1.48.8.2 nathanw return (val);
179 1.48.8.2 nathanw }
180 1.48.8.2 nathanw
181 1.48.8.2 nathanw int
182 1.48.8.4 nathanw lematch(struct device *parent, struct cfdata *match, void *aux)
183 1.48.8.2 nathanw {
184 1.48.8.2 nathanw struct dio_attach_args *da = aux;
185 1.48.8.2 nathanw
186 1.48.8.2 nathanw if (da->da_id == DIO_DEVICE_ID_LAN)
187 1.48.8.2 nathanw return (1);
188 1.48.8.2 nathanw return (0);
189 1.48.8.2 nathanw }
190 1.48.8.2 nathanw
191 1.48.8.2 nathanw /*
192 1.48.8.2 nathanw * Interface exists: make available by filling in network interface
193 1.48.8.2 nathanw * record. System will initialize the interface when it is ready
194 1.48.8.2 nathanw * to accept packets.
195 1.48.8.2 nathanw */
196 1.48.8.2 nathanw void
197 1.48.8.4 nathanw leattach(struct device *parent, struct device *self, void *aux)
198 1.48.8.2 nathanw {
199 1.48.8.2 nathanw struct dio_attach_args *da = aux;
200 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)self;
201 1.48.8.2 nathanw struct lance_softc *sc = &lesc->sc_am7990.lsc;
202 1.48.8.2 nathanw bus_space_tag_t bst = da->da_bst;
203 1.48.8.2 nathanw bus_space_handle_t bsh0, bsh1, bsh2;
204 1.48.8.2 nathanw bus_size_t offset;
205 1.48.8.2 nathanw int i, ipl;
206 1.48.8.2 nathanw
207 1.48.8.2 nathanw if (bus_space_map(bst, (bus_addr_t)dio_scodetopa(da->da_scode),
208 1.48.8.2 nathanw da->da_size, 0, &bsh0)) {
209 1.48.8.2 nathanw printf("\n%s: can't map LANCE registers\n",
210 1.48.8.2 nathanw sc->sc_dev.dv_xname);
211 1.48.8.2 nathanw return;
212 1.48.8.2 nathanw }
213 1.48.8.2 nathanw
214 1.48.8.2 nathanw if (bus_space_subregion(bst, bsh0, lestd[1], LER1_SIZE, &bsh1)) {
215 1.48.8.2 nathanw printf("\n%s: can't subregion LANCE space\n",
216 1.48.8.2 nathanw sc->sc_dev.dv_xname);
217 1.48.8.2 nathanw return;
218 1.48.8.2 nathanw }
219 1.48.8.2 nathanw
220 1.48.8.2 nathanw if (bus_space_subregion(bst, bsh0, lestd[2], LE_BUFSIZE, &bsh2)) {
221 1.48.8.2 nathanw printf("\n%s: can't subregion buffer space\n",
222 1.48.8.2 nathanw sc->sc_dev.dv_xname);
223 1.48.8.2 nathanw return;
224 1.48.8.2 nathanw }
225 1.48.8.2 nathanw
226 1.48.8.2 nathanw lesc->sc_bst = bst;
227 1.48.8.2 nathanw lesc->sc_bsh0 = bsh0;
228 1.48.8.2 nathanw lesc->sc_bsh1 = bsh1;
229 1.48.8.2 nathanw lesc->sc_bsh2 = bsh2;
230 1.48.8.2 nathanw
231 1.48.8.2 nathanw bus_space_write_1(bst, bsh0, LER0_ID, 0xff);
232 1.48.8.2 nathanw DELAY(100);
233 1.48.8.2 nathanw
234 1.48.8.2 nathanw ipl = DIO_IPL((caddr_t)bsh0); /* XXX */
235 1.48.8.2 nathanw printf(" ipl %d", ipl);
236 1.48.8.2 nathanw
237 1.48.8.2 nathanw sc->sc_conf3 = LE_C3_BSWP;
238 1.48.8.2 nathanw sc->sc_addr = 0;
239 1.48.8.2 nathanw sc->sc_memsize = LE_BUFSIZE;
240 1.48.8.2 nathanw
241 1.48.8.2 nathanw /*
242 1.48.8.2 nathanw * Read the ethernet address off the board, one nibble at a time.
243 1.48.8.2 nathanw */
244 1.48.8.2 nathanw offset = lestd[3];
245 1.48.8.2 nathanw for (i = 0; i < sizeof(sc->sc_enaddr); i++) {
246 1.48.8.2 nathanw sc->sc_enaddr[i] =
247 1.48.8.2 nathanw (bus_space_read_1(bst, bsh0, ++offset) & 0xf) << 4;
248 1.48.8.2 nathanw offset++;
249 1.48.8.2 nathanw sc->sc_enaddr[i] |=
250 1.48.8.2 nathanw (bus_space_read_1(bst, bsh0, ++offset) & 0xf);
251 1.48.8.2 nathanw offset++;
252 1.48.8.2 nathanw }
253 1.48.8.2 nathanw
254 1.48.8.2 nathanw sc->sc_copytodesc = le_copytobuf;
255 1.48.8.2 nathanw sc->sc_copyfromdesc = le_copyfrombuf;
256 1.48.8.2 nathanw sc->sc_copytobuf = le_copytobuf;
257 1.48.8.2 nathanw sc->sc_copyfrombuf = le_copyfrombuf;
258 1.48.8.2 nathanw sc->sc_zerobuf = le_zerobuf;
259 1.48.8.2 nathanw
260 1.48.8.2 nathanw sc->sc_rdcsr = lerdcsr;
261 1.48.8.2 nathanw sc->sc_wrcsr = lewrcsr;
262 1.48.8.2 nathanw sc->sc_hwinit = NULL;
263 1.48.8.2 nathanw
264 1.48.8.2 nathanw am7990_config(&lesc->sc_am7990);
265 1.48.8.2 nathanw
266 1.48.8.2 nathanw /* Establish the interrupt handler. */
267 1.48.8.2 nathanw (void) dio_intr_establish(leintr, sc, ipl, IPL_NET);
268 1.48.8.2 nathanw bus_space_write_1(bst, bsh0, LER0_STATUS, LE_IE);
269 1.48.8.2 nathanw }
270 1.48.8.2 nathanw
271 1.48.8.2 nathanw int
272 1.48.8.4 nathanw leintr(void *arg)
273 1.48.8.2 nathanw {
274 1.48.8.2 nathanw struct lance_softc *sc = arg;
275 1.48.8.2 nathanw #ifdef USELEDS
276 1.48.8.2 nathanw u_int16_t isr;
277 1.48.8.2 nathanw
278 1.48.8.2 nathanw isr = lerdcsr(sc, LE_CSR0);
279 1.48.8.2 nathanw
280 1.48.8.2 nathanw if ((isr & LE_C0_INTR) == 0)
281 1.48.8.2 nathanw return (0);
282 1.48.8.2 nathanw
283 1.48.8.2 nathanw if (isr & LE_C0_RINT)
284 1.48.8.2 nathanw ledcontrol(0, 0, LED_LANRCV);
285 1.48.8.2 nathanw
286 1.48.8.2 nathanw if (isr & LE_C0_TINT)
287 1.48.8.2 nathanw ledcontrol(0, 0, LED_LANXMT);
288 1.48.8.2 nathanw #endif /* USELEDS */
289 1.48.8.2 nathanw
290 1.48.8.2 nathanw return (am7990_intr(sc));
291 1.48.8.2 nathanw }
292 1.48.8.2 nathanw
293 1.48.8.2 nathanw hide void
294 1.48.8.4 nathanw le_copytobuf(struct lance_softc *sc, void *from, int boff, int len)
295 1.48.8.2 nathanw {
296 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)sc;
297 1.48.8.2 nathanw
298 1.48.8.2 nathanw bus_space_write_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, from, len);
299 1.48.8.2 nathanw }
300 1.48.8.2 nathanw
301 1.48.8.2 nathanw hide void
302 1.48.8.4 nathanw le_copyfrombuf(struct lance_softc *sc, void *to, int boff, int len)
303 1.48.8.2 nathanw {
304 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)sc;
305 1.48.8.2 nathanw
306 1.48.8.2 nathanw bus_space_read_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, to, len);
307 1.48.8.2 nathanw }
308 1.48.8.2 nathanw
309 1.48.8.2 nathanw hide void
310 1.48.8.4 nathanw le_zerobuf(struct lance_softc *sc, int boff, int len)
311 1.48.8.2 nathanw {
312 1.48.8.2 nathanw struct le_softc *lesc = (struct le_softc *)sc;
313 1.48.8.2 nathanw
314 1.48.8.2 nathanw bus_space_set_region_1(lesc->sc_bst, lesc->sc_bsh2, boff, 0, len);
315 1.48.8.2 nathanw }
316