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