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