am7990.c revision 1.65 1 1.65 agc /* $NetBSD: am7990.c,v 1.65 2003/08/07 16:30:58 agc Exp $ */
2 1.36 thorpej
3 1.36 thorpej /*-
4 1.54 mycroft * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 1.36 thorpej * All rights reserved.
6 1.36 thorpej *
7 1.36 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.54 mycroft * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9 1.54 mycroft * Simulation Facility, NASA Ames Research Center.
10 1.36 thorpej *
11 1.36 thorpej * Redistribution and use in source and binary forms, with or without
12 1.36 thorpej * modification, are permitted provided that the following conditions
13 1.36 thorpej * are met:
14 1.36 thorpej * 1. Redistributions of source code must retain the above copyright
15 1.36 thorpej * notice, this list of conditions and the following disclaimer.
16 1.36 thorpej * 2. Redistributions in binary form must reproduce the above copyright
17 1.36 thorpej * notice, this list of conditions and the following disclaimer in the
18 1.36 thorpej * documentation and/or other materials provided with the distribution.
19 1.36 thorpej * 3. All advertising materials mentioning features or use of this software
20 1.36 thorpej * must display the following acknowledgement:
21 1.36 thorpej * This product includes software developed by the NetBSD
22 1.36 thorpej * Foundation, Inc. and its contributors.
23 1.36 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
24 1.36 thorpej * contributors may be used to endorse or promote products derived
25 1.36 thorpej * from this software without specific prior written permission.
26 1.36 thorpej *
27 1.36 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
28 1.36 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29 1.36 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
30 1.36 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
31 1.36 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
32 1.36 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
33 1.36 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
34 1.36 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
35 1.36 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
36 1.36 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
37 1.36 thorpej * POSSIBILITY OF SUCH DAMAGE.
38 1.36 thorpej */
39 1.1 cgd
40 1.1 cgd /*-
41 1.1 cgd * Copyright (c) 1992, 1993
42 1.1 cgd * The Regents of the University of California. All rights reserved.
43 1.1 cgd *
44 1.1 cgd * This code is derived from software contributed to Berkeley by
45 1.1 cgd * Ralph Campbell and Rick Macklem.
46 1.1 cgd *
47 1.1 cgd * Redistribution and use in source and binary forms, with or without
48 1.1 cgd * modification, are permitted provided that the following conditions
49 1.1 cgd * are met:
50 1.1 cgd * 1. Redistributions of source code must retain the above copyright
51 1.1 cgd * notice, this list of conditions and the following disclaimer.
52 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
53 1.1 cgd * notice, this list of conditions and the following disclaimer in the
54 1.1 cgd * documentation and/or other materials provided with the distribution.
55 1.65 agc * 3. Neither the name of the University nor the names of its contributors
56 1.1 cgd * may be used to endorse or promote products derived from this software
57 1.1 cgd * without specific prior written permission.
58 1.1 cgd *
59 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1 cgd * SUCH DAMAGE.
70 1.1 cgd *
71 1.1 cgd * @(#)if_le.c 8.2 (Berkeley) 11/16/93
72 1.1 cgd */
73 1.64 lukem
74 1.64 lukem #include <sys/cdefs.h>
75 1.65 agc __KERNEL_RCSID(0, "$NetBSD: am7990.c,v 1.65 2003/08/07 16:30:58 agc Exp $");
76 1.1 cgd
77 1.19 thorpej #include "bpfilter.h"
78 1.38 explorer #include "rnd.h"
79 1.19 thorpej
80 1.19 thorpej #include <sys/param.h>
81 1.19 thorpej #include <sys/systm.h>
82 1.19 thorpej #include <sys/mbuf.h>
83 1.19 thorpej #include <sys/syslog.h>
84 1.19 thorpej #include <sys/socket.h>
85 1.19 thorpej #include <sys/device.h>
86 1.19 thorpej #include <sys/malloc.h>
87 1.1 cgd #include <sys/ioctl.h>
88 1.1 cgd #include <sys/errno.h>
89 1.38 explorer #if NRND > 0
90 1.37 explorer #include <sys/rnd.h>
91 1.38 explorer #endif
92 1.1 cgd
93 1.19 thorpej #include <net/if.h>
94 1.26 is #include <net/if_dl.h>
95 1.26 is #include <net/if_ether.h>
96 1.27 thorpej #include <net/if_media.h>
97 1.19 thorpej
98 1.1 cgd #if NBPFILTER > 0
99 1.1 cgd #include <net/bpf.h>
100 1.1 cgd #include <net/bpfdesc.h>
101 1.1 cgd #endif
102 1.1 cgd
103 1.51 drochner #include <dev/ic/lancereg.h>
104 1.51 drochner #include <dev/ic/lancevar.h>
105 1.19 thorpej #include <dev/ic/am7990reg.h>
106 1.19 thorpej #include <dev/ic/am7990var.h>
107 1.19 thorpej
108 1.51 drochner void am7990_meminit __P((struct lance_softc *));
109 1.51 drochner void am7990_start __P((struct ifnet *));
110 1.51 drochner
111 1.62 mrg #if defined(_KERNEL_OPT)
112 1.51 drochner #include "opt_ddb.h"
113 1.1 cgd #endif
114 1.1 cgd
115 1.51 drochner #ifdef DDB
116 1.51 drochner #define integrate
117 1.51 drochner #define hide
118 1.39 gwr #else
119 1.51 drochner #define integrate static __inline
120 1.51 drochner #define hide static
121 1.39 gwr #endif
122 1.39 gwr
123 1.51 drochner integrate void am7990_rint __P((struct lance_softc *));
124 1.51 drochner integrate void am7990_tint __P((struct lance_softc *));
125 1.19 thorpej
126 1.51 drochner #ifdef LEDEBUG
127 1.51 drochner void am7990_recv_print __P((struct lance_softc *, int));
128 1.51 drochner void am7990_xmit_print __P((struct lance_softc *, int));
129 1.51 drochner #endif
130 1.13 gwr
131 1.51 drochner #define ifp (&sc->sc_ethercom.ec_if)
132 1.19 thorpej
133 1.1 cgd void
134 1.19 thorpej am7990_config(sc)
135 1.19 thorpej struct am7990_softc *sc;
136 1.1 cgd {
137 1.25 leo int mem, i;
138 1.1 cgd
139 1.51 drochner sc->lsc.sc_meminit = am7990_meminit;
140 1.51 drochner sc->lsc.sc_start = am7990_start;
141 1.1 cgd
142 1.51 drochner lance_config(&sc->lsc);
143 1.19 thorpej
144 1.1 cgd mem = 0;
145 1.51 drochner sc->lsc.sc_initaddr = mem;
146 1.1 cgd mem += sizeof(struct leinit);
147 1.51 drochner sc->lsc.sc_rmdaddr = mem;
148 1.51 drochner mem += sizeof(struct lermd) * sc->lsc.sc_nrbuf;
149 1.51 drochner sc->lsc.sc_tmdaddr = mem;
150 1.51 drochner mem += sizeof(struct letmd) * sc->lsc.sc_ntbuf;
151 1.51 drochner for (i = 0; i < sc->lsc.sc_nrbuf; i++, mem += LEBLEN)
152 1.51 drochner sc->lsc.sc_rbufaddr[i] = mem;
153 1.51 drochner for (i = 0; i < sc->lsc.sc_ntbuf; i++, mem += LEBLEN)
154 1.51 drochner sc->lsc.sc_tbufaddr[i] = mem;
155 1.1 cgd #ifdef notyet
156 1.1 cgd if (mem > ...)
157 1.1 cgd panic(...);
158 1.1 cgd #endif
159 1.1 cgd }
160 1.1 cgd
161 1.1 cgd /*
162 1.1 cgd * Set up the initialization block and the descriptor rings.
163 1.1 cgd */
164 1.1 cgd void
165 1.19 thorpej am7990_meminit(sc)
166 1.57 augustss struct lance_softc *sc;
167 1.1 cgd {
168 1.1 cgd u_long a;
169 1.1 cgd int bix;
170 1.1 cgd struct leinit init;
171 1.1 cgd struct lermd rmd;
172 1.1 cgd struct letmd tmd;
173 1.28 is u_int8_t *myaddr;
174 1.1 cgd
175 1.1 cgd #if NBPFILTER > 0
176 1.1 cgd if (ifp->if_flags & IFF_PROMISC)
177 1.1 cgd init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM;
178 1.1 cgd else
179 1.1 cgd #endif
180 1.1 cgd init.init_mode = LE_MODE_NORMAL;
181 1.29 veego if (sc->sc_initmodemedia == 1)
182 1.29 veego init.init_mode |= LE_MODE_PSEL0;
183 1.28 is
184 1.39 gwr /*
185 1.39 gwr * Update our private copy of the Ethernet address.
186 1.39 gwr * We NEED the copy so we can ensure its alignment!
187 1.39 gwr */
188 1.63 thorpej memcpy(sc->sc_enaddr, LLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
189 1.39 gwr myaddr = sc->sc_enaddr;
190 1.39 gwr
191 1.28 is init.init_padr[0] = (myaddr[1] << 8) | myaddr[0];
192 1.28 is init.init_padr[1] = (myaddr[3] << 8) | myaddr[2];
193 1.28 is init.init_padr[2] = (myaddr[5] << 8) | myaddr[4];
194 1.51 drochner lance_setladrf(&sc->sc_ethercom, init.init_ladrf);
195 1.1 cgd
196 1.1 cgd sc->sc_last_rd = 0;
197 1.1 cgd sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0;
198 1.1 cgd
199 1.1 cgd a = sc->sc_addr + LE_RMDADDR(sc, 0);
200 1.1 cgd init.init_rdra = a;
201 1.1 cgd init.init_rlen = (a >> 16) | ((ffs(sc->sc_nrbuf) - 1) << 13);
202 1.1 cgd
203 1.1 cgd a = sc->sc_addr + LE_TMDADDR(sc, 0);
204 1.1 cgd init.init_tdra = a;
205 1.1 cgd init.init_tlen = (a >> 16) | ((ffs(sc->sc_ntbuf) - 1) << 13);
206 1.1 cgd
207 1.1 cgd (*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init));
208 1.1 cgd
209 1.1 cgd /*
210 1.1 cgd * Set up receive ring descriptors.
211 1.1 cgd */
212 1.1 cgd for (bix = 0; bix < sc->sc_nrbuf; bix++) {
213 1.1 cgd a = sc->sc_addr + LE_RBUFADDR(sc, bix);
214 1.1 cgd rmd.rmd0 = a;
215 1.1 cgd rmd.rmd1_hadr = a >> 16;
216 1.1 cgd rmd.rmd1_bits = LE_R1_OWN;
217 1.1 cgd rmd.rmd2 = -LEBLEN | LE_XMD2_ONES;
218 1.1 cgd rmd.rmd3 = 0;
219 1.1 cgd (*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix),
220 1.1 cgd sizeof(rmd));
221 1.1 cgd }
222 1.1 cgd
223 1.1 cgd /*
224 1.1 cgd * Set up transmit ring descriptors.
225 1.1 cgd */
226 1.1 cgd for (bix = 0; bix < sc->sc_ntbuf; bix++) {
227 1.1 cgd a = sc->sc_addr + LE_TBUFADDR(sc, bix);
228 1.1 cgd tmd.tmd0 = a;
229 1.1 cgd tmd.tmd1_hadr = a >> 16;
230 1.1 cgd tmd.tmd1_bits = 0;
231 1.1 cgd tmd.tmd2 = 0 | LE_XMD2_ONES;
232 1.1 cgd tmd.tmd3 = 0;
233 1.1 cgd (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix),
234 1.1 cgd sizeof(tmd));
235 1.1 cgd }
236 1.1 cgd }
237 1.1 cgd
238 1.1 cgd integrate void
239 1.19 thorpej am7990_rint(sc)
240 1.51 drochner struct lance_softc *sc;
241 1.1 cgd {
242 1.57 augustss int bix;
243 1.1 cgd int rp;
244 1.1 cgd struct lermd rmd;
245 1.1 cgd
246 1.1 cgd bix = sc->sc_last_rd;
247 1.1 cgd
248 1.1 cgd /* Process all buffers with valid data. */
249 1.1 cgd for (;;) {
250 1.1 cgd rp = LE_RMDADDR(sc, bix);
251 1.1 cgd (*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd));
252 1.1 cgd
253 1.1 cgd if (rmd.rmd1_bits & LE_R1_OWN)
254 1.1 cgd break;
255 1.1 cgd
256 1.1 cgd if (rmd.rmd1_bits & LE_R1_ERR) {
257 1.1 cgd if (rmd.rmd1_bits & LE_R1_ENP) {
258 1.6 mycroft #ifdef LEDEBUG
259 1.1 cgd if ((rmd.rmd1_bits & LE_R1_OFLO) == 0) {
260 1.1 cgd if (rmd.rmd1_bits & LE_R1_FRAM)
261 1.22 christos printf("%s: framing error\n",
262 1.1 cgd sc->sc_dev.dv_xname);
263 1.1 cgd if (rmd.rmd1_bits & LE_R1_CRC)
264 1.22 christos printf("%s: crc mismatch\n",
265 1.1 cgd sc->sc_dev.dv_xname);
266 1.1 cgd }
267 1.6 mycroft #endif
268 1.1 cgd } else {
269 1.1 cgd if (rmd.rmd1_bits & LE_R1_OFLO)
270 1.22 christos printf("%s: overflow\n",
271 1.1 cgd sc->sc_dev.dv_xname);
272 1.1 cgd }
273 1.1 cgd if (rmd.rmd1_bits & LE_R1_BUFF)
274 1.22 christos printf("%s: receive buffer error\n",
275 1.1 cgd sc->sc_dev.dv_xname);
276 1.7 mycroft ifp->if_ierrors++;
277 1.12 christos } else if ((rmd.rmd1_bits & (LE_R1_STP | LE_R1_ENP)) !=
278 1.1 cgd (LE_R1_STP | LE_R1_ENP)) {
279 1.22 christos printf("%s: dropping chained buffer\n",
280 1.1 cgd sc->sc_dev.dv_xname);
281 1.7 mycroft ifp->if_ierrors++;
282 1.1 cgd } else {
283 1.1 cgd #ifdef LEDEBUG
284 1.58 matt if (sc->sc_debug > 1)
285 1.19 thorpej am7990_recv_print(sc, sc->sc_last_rd);
286 1.1 cgd #endif
287 1.51 drochner lance_read(sc, LE_RBUFADDR(sc, bix),
288 1.51 drochner (int)rmd.rmd3 - 4);
289 1.1 cgd }
290 1.1 cgd
291 1.1 cgd rmd.rmd1_bits = LE_R1_OWN;
292 1.1 cgd rmd.rmd2 = -LEBLEN | LE_XMD2_ONES;
293 1.1 cgd rmd.rmd3 = 0;
294 1.1 cgd (*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd));
295 1.1 cgd
296 1.1 cgd #ifdef LEDEBUG
297 1.1 cgd if (sc->sc_debug)
298 1.22 christos printf("sc->sc_last_rd = %x, rmd: "
299 1.16 pk "ladr %04x, hadr %02x, flags %02x, "
300 1.16 pk "bcnt %04x, mcnt %04x\n",
301 1.16 pk sc->sc_last_rd,
302 1.16 pk rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits,
303 1.16 pk rmd.rmd2, rmd.rmd3);
304 1.1 cgd #endif
305 1.1 cgd
306 1.1 cgd if (++bix == sc->sc_nrbuf)
307 1.1 cgd bix = 0;
308 1.1 cgd }
309 1.1 cgd
310 1.1 cgd sc->sc_last_rd = bix;
311 1.1 cgd }
312 1.1 cgd
313 1.1 cgd integrate void
314 1.19 thorpej am7990_tint(sc)
315 1.57 augustss struct lance_softc *sc;
316 1.1 cgd {
317 1.57 augustss int bix;
318 1.1 cgd struct letmd tmd;
319 1.9 thorpej
320 1.1 cgd bix = sc->sc_first_td;
321 1.1 cgd
322 1.1 cgd for (;;) {
323 1.1 cgd if (sc->sc_no_td <= 0)
324 1.1 cgd break;
325 1.1 cgd
326 1.50 drochner (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix),
327 1.50 drochner sizeof(tmd));
328 1.50 drochner
329 1.1 cgd #ifdef LEDEBUG
330 1.1 cgd if (sc->sc_debug)
331 1.22 christos printf("trans tmd: "
332 1.21 christos "ladr %04x, hadr %02x, flags %02x, "
333 1.21 christos "bcnt %04x, mcnt %04x\n",
334 1.21 christos tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits,
335 1.21 christos tmd.tmd2, tmd.tmd3);
336 1.1 cgd #endif
337 1.1 cgd
338 1.1 cgd if (tmd.tmd1_bits & LE_T1_OWN)
339 1.1 cgd break;
340 1.1 cgd
341 1.1 cgd ifp->if_flags &= ~IFF_OACTIVE;
342 1.1 cgd
343 1.1 cgd if (tmd.tmd1_bits & LE_T1_ERR) {
344 1.1 cgd if (tmd.tmd3 & LE_T3_BUFF)
345 1.22 christos printf("%s: transmit buffer error\n",
346 1.19 thorpej sc->sc_dev.dv_xname);
347 1.1 cgd else if (tmd.tmd3 & LE_T3_UFLO)
348 1.22 christos printf("%s: underflow\n", sc->sc_dev.dv_xname);
349 1.1 cgd if (tmd.tmd3 & (LE_T3_BUFF | LE_T3_UFLO)) {
350 1.52 drochner lance_reset(sc);
351 1.1 cgd return;
352 1.1 cgd }
353 1.20 abrown if (tmd.tmd3 & LE_T3_LCAR) {
354 1.27 thorpej sc->sc_havecarrier = 0;
355 1.20 abrown if (sc->sc_nocarrier)
356 1.20 abrown (*sc->sc_nocarrier)(sc);
357 1.20 abrown else
358 1.22 christos printf("%s: lost carrier\n",
359 1.20 abrown sc->sc_dev.dv_xname);
360 1.20 abrown }
361 1.1 cgd if (tmd.tmd3 & LE_T3_LCOL)
362 1.1 cgd ifp->if_collisions++;
363 1.1 cgd if (tmd.tmd3 & LE_T3_RTRY) {
364 1.56 thorpej #ifdef LEDEBUG
365 1.22 christos printf("%s: excessive collisions, tdr %d\n",
366 1.19 thorpej sc->sc_dev.dv_xname,
367 1.19 thorpej tmd.tmd3 & LE_T3_TDR_MASK);
368 1.56 thorpej #endif
369 1.1 cgd ifp->if_collisions += 16;
370 1.1 cgd }
371 1.1 cgd ifp->if_oerrors++;
372 1.1 cgd } else {
373 1.1 cgd if (tmd.tmd1_bits & LE_T1_ONE)
374 1.1 cgd ifp->if_collisions++;
375 1.1 cgd else if (tmd.tmd1_bits & LE_T1_MORE)
376 1.1 cgd /* Real number is unknown. */
377 1.1 cgd ifp->if_collisions += 2;
378 1.1 cgd ifp->if_opackets++;
379 1.1 cgd }
380 1.1 cgd
381 1.1 cgd if (++bix == sc->sc_ntbuf)
382 1.1 cgd bix = 0;
383 1.1 cgd
384 1.1 cgd --sc->sc_no_td;
385 1.1 cgd }
386 1.1 cgd
387 1.1 cgd sc->sc_first_td = bix;
388 1.1 cgd
389 1.19 thorpej am7990_start(ifp);
390 1.1 cgd
391 1.1 cgd if (sc->sc_no_td == 0)
392 1.1 cgd ifp->if_timer = 0;
393 1.1 cgd }
394 1.1 cgd
395 1.1 cgd /*
396 1.1 cgd * Controller interrupt.
397 1.1 cgd */
398 1.1 cgd int
399 1.19 thorpej am7990_intr(arg)
400 1.57 augustss void *arg;
401 1.1 cgd {
402 1.57 augustss struct lance_softc *sc = arg;
403 1.57 augustss u_int16_t isr;
404 1.1 cgd
405 1.25 leo isr = (*sc->sc_rdcsr)(sc, LE_CSR0) | sc->sc_saved_csr0;
406 1.25 leo sc->sc_saved_csr0 = 0;
407 1.59 jdolecek #if defined(LEDEBUG) && LEDEBUG > 1
408 1.1 cgd if (sc->sc_debug)
409 1.22 christos printf("%s: am7990_intr entering with isr=%04x\n",
410 1.1 cgd sc->sc_dev.dv_xname, isr);
411 1.1 cgd #endif
412 1.1 cgd if ((isr & LE_C0_INTR) == 0)
413 1.1 cgd return (0);
414 1.1 cgd
415 1.55 ragge #ifdef __vax__
416 1.55 ragge /*
417 1.55 ragge * DEC needs this write order to the registers, don't know
418 1.55 ragge * the results on other arch's. Ragge 991029
419 1.55 ragge */
420 1.55 ragge isr &= ~LE_C0_INEA;
421 1.55 ragge (*sc->sc_wrcsr)(sc, LE_CSR0, isr);
422 1.55 ragge (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA);
423 1.55 ragge #else
424 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR0,
425 1.1 cgd isr & (LE_C0_INEA | LE_C0_BABL | LE_C0_MISS | LE_C0_MERR |
426 1.1 cgd LE_C0_RINT | LE_C0_TINT | LE_C0_IDON));
427 1.55 ragge #endif
428 1.1 cgd if (isr & LE_C0_ERR) {
429 1.1 cgd if (isr & LE_C0_BABL) {
430 1.6 mycroft #ifdef LEDEBUG
431 1.22 christos printf("%s: babble\n", sc->sc_dev.dv_xname);
432 1.6 mycroft #endif
433 1.7 mycroft ifp->if_oerrors++;
434 1.1 cgd }
435 1.1 cgd #if 0
436 1.1 cgd if (isr & LE_C0_CERR) {
437 1.22 christos printf("%s: collision error\n", sc->sc_dev.dv_xname);
438 1.7 mycroft ifp->if_collisions++;
439 1.1 cgd }
440 1.1 cgd #endif
441 1.6 mycroft if (isr & LE_C0_MISS) {
442 1.6 mycroft #ifdef LEDEBUG
443 1.22 christos printf("%s: missed packet\n", sc->sc_dev.dv_xname);
444 1.6 mycroft #endif
445 1.7 mycroft ifp->if_ierrors++;
446 1.6 mycroft }
447 1.1 cgd if (isr & LE_C0_MERR) {
448 1.22 christos printf("%s: memory error\n", sc->sc_dev.dv_xname);
449 1.51 drochner lance_reset(sc);
450 1.1 cgd return (1);
451 1.1 cgd }
452 1.1 cgd }
453 1.1 cgd
454 1.1 cgd if ((isr & LE_C0_RXON) == 0) {
455 1.22 christos printf("%s: receiver disabled\n", sc->sc_dev.dv_xname);
456 1.7 mycroft ifp->if_ierrors++;
457 1.51 drochner lance_reset(sc);
458 1.1 cgd return (1);
459 1.1 cgd }
460 1.1 cgd if ((isr & LE_C0_TXON) == 0) {
461 1.22 christos printf("%s: transmitter disabled\n", sc->sc_dev.dv_xname);
462 1.7 mycroft ifp->if_oerrors++;
463 1.51 drochner lance_reset(sc);
464 1.1 cgd return (1);
465 1.1 cgd }
466 1.1 cgd
467 1.27 thorpej /*
468 1.27 thorpej * Pretend we have carrier; if we don't this will be cleared
469 1.27 thorpej * shortly.
470 1.27 thorpej */
471 1.27 thorpej sc->sc_havecarrier = 1;
472 1.27 thorpej
473 1.1 cgd if (isr & LE_C0_RINT)
474 1.19 thorpej am7990_rint(sc);
475 1.1 cgd if (isr & LE_C0_TINT)
476 1.19 thorpej am7990_tint(sc);
477 1.37 explorer
478 1.38 explorer #if NRND > 0
479 1.37 explorer rnd_add_uint32(&sc->rnd_source, isr);
480 1.38 explorer #endif
481 1.1 cgd
482 1.1 cgd return (1);
483 1.1 cgd }
484 1.7 mycroft
485 1.51 drochner #undef ifp
486 1.27 thorpej
487 1.1 cgd /*
488 1.1 cgd * Setup output on interface.
489 1.1 cgd * Get another datagram to send off of the interface queue, and map it to the
490 1.1 cgd * interface before starting the output.
491 1.53 mycroft * Called only at splnet or interrupt level.
492 1.1 cgd */
493 1.1 cgd void
494 1.19 thorpej am7990_start(ifp)
495 1.57 augustss struct ifnet *ifp;
496 1.1 cgd {
497 1.57 augustss struct lance_softc *sc = ifp->if_softc;
498 1.57 augustss int bix;
499 1.57 augustss struct mbuf *m;
500 1.1 cgd struct letmd tmd;
501 1.1 cgd int rp;
502 1.1 cgd int len;
503 1.1 cgd
504 1.1 cgd if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
505 1.1 cgd return;
506 1.1 cgd
507 1.1 cgd bix = sc->sc_last_td;
508 1.1 cgd
509 1.1 cgd for (;;) {
510 1.1 cgd rp = LE_TMDADDR(sc, bix);
511 1.1 cgd (*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd));
512 1.1 cgd
513 1.1 cgd if (tmd.tmd1_bits & LE_T1_OWN) {
514 1.1 cgd ifp->if_flags |= IFF_OACTIVE;
515 1.22 christos printf("missing buffer, no_td = %d, last_td = %d\n",
516 1.1 cgd sc->sc_no_td, sc->sc_last_td);
517 1.1 cgd }
518 1.1 cgd
519 1.61 thorpej IFQ_DEQUEUE(&ifp->if_snd, m);
520 1.1 cgd if (m == 0)
521 1.1 cgd break;
522 1.1 cgd
523 1.1 cgd #if NBPFILTER > 0
524 1.1 cgd /*
525 1.1 cgd * If BPF is listening on this interface, let it see the packet
526 1.1 cgd * before we commit it to the wire.
527 1.1 cgd */
528 1.1 cgd if (ifp->if_bpf)
529 1.1 cgd bpf_mtap(ifp->if_bpf, m);
530 1.1 cgd #endif
531 1.1 cgd
532 1.1 cgd /*
533 1.1 cgd * Copy the mbuf chain into the transmit buffer.
534 1.1 cgd */
535 1.51 drochner len = lance_put(sc, LE_TBUFADDR(sc, bix), m);
536 1.1 cgd
537 1.1 cgd #ifdef LEDEBUG
538 1.3 mycroft if (len > ETHERMTU + sizeof(struct ether_header))
539 1.22 christos printf("packet length %d\n", len);
540 1.1 cgd #endif
541 1.1 cgd
542 1.1 cgd ifp->if_timer = 5;
543 1.1 cgd
544 1.1 cgd /*
545 1.1 cgd * Init transmit registers, and set transmit start flag.
546 1.1 cgd */
547 1.1 cgd tmd.tmd1_bits = LE_T1_OWN | LE_T1_STP | LE_T1_ENP;
548 1.1 cgd tmd.tmd2 = -len | LE_XMD2_ONES;
549 1.1 cgd tmd.tmd3 = 0;
550 1.1 cgd
551 1.1 cgd (*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd));
552 1.1 cgd
553 1.1 cgd #ifdef LEDEBUG
554 1.58 matt if (sc->sc_debug > 1)
555 1.19 thorpej am7990_xmit_print(sc, sc->sc_last_td);
556 1.1 cgd #endif
557 1.1 cgd
558 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD);
559 1.1 cgd
560 1.1 cgd if (++bix == sc->sc_ntbuf)
561 1.1 cgd bix = 0;
562 1.1 cgd
563 1.1 cgd if (++sc->sc_no_td == sc->sc_ntbuf) {
564 1.1 cgd ifp->if_flags |= IFF_OACTIVE;
565 1.1 cgd break;
566 1.1 cgd }
567 1.1 cgd
568 1.1 cgd }
569 1.1 cgd
570 1.1 cgd sc->sc_last_td = bix;
571 1.1 cgd }
572 1.1 cgd
573 1.1 cgd #ifdef LEDEBUG
574 1.1 cgd void
575 1.19 thorpej am7990_recv_print(sc, no)
576 1.51 drochner struct lance_softc *sc;
577 1.1 cgd int no;
578 1.1 cgd {
579 1.1 cgd struct lermd rmd;
580 1.1 cgd u_int16_t len;
581 1.1 cgd struct ether_header eh;
582 1.1 cgd
583 1.1 cgd (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd));
584 1.1 cgd len = rmd.rmd3;
585 1.22 christos printf("%s: receive buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,
586 1.1 cgd len);
587 1.22 christos printf("%s: status %04x\n", sc->sc_dev.dv_xname,
588 1.19 thorpej (*sc->sc_rdcsr)(sc, LE_CSR0));
589 1.22 christos printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n",
590 1.1 cgd sc->sc_dev.dv_xname,
591 1.1 cgd rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits, rmd.rmd2, rmd.rmd3);
592 1.1 cgd if (len >= sizeof(eh)) {
593 1.1 cgd (*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh));
594 1.22 christos printf("%s: dst %s", sc->sc_dev.dv_xname,
595 1.16 pk ether_sprintf(eh.ether_dhost));
596 1.22 christos printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),
597 1.16 pk ntohs(eh.ether_type));
598 1.1 cgd }
599 1.1 cgd }
600 1.1 cgd
601 1.1 cgd void
602 1.19 thorpej am7990_xmit_print(sc, no)
603 1.51 drochner struct lance_softc *sc;
604 1.1 cgd int no;
605 1.1 cgd {
606 1.1 cgd struct letmd tmd;
607 1.1 cgd u_int16_t len;
608 1.1 cgd struct ether_header eh;
609 1.1 cgd
610 1.1 cgd (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd));
611 1.1 cgd len = -tmd.tmd2;
612 1.22 christos printf("%s: transmit buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,
613 1.1 cgd len);
614 1.22 christos printf("%s: status %04x\n", sc->sc_dev.dv_xname,
615 1.19 thorpej (*sc->sc_rdcsr)(sc, LE_CSR0));
616 1.22 christos printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n",
617 1.1 cgd sc->sc_dev.dv_xname,
618 1.1 cgd tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, tmd.tmd2, tmd.tmd3);
619 1.1 cgd if (len >= sizeof(eh)) {
620 1.1 cgd (*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh));
621 1.22 christos printf("%s: dst %s", sc->sc_dev.dv_xname,
622 1.16 pk ether_sprintf(eh.ether_dhost));
623 1.22 christos printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),
624 1.1 cgd ntohs(eh.ether_type));
625 1.1 cgd }
626 1.1 cgd }
627 1.1 cgd #endif /* LEDEBUG */
628