if_le.c revision 1.15 1 1.15 gwr /* $NetBSD: if_le.c,v 1.15 1994/12/12 18:59:12 gwr Exp $ */
2 1.12 cgd
3 1.10 gwr /*-
4 1.10 gwr * Copyright (c) 1982, 1992, 1993
5 1.10 gwr * The Regents of the University of California. All rights reserved.
6 1.1 glass *
7 1.1 glass * Redistribution and use in source and binary forms, with or without
8 1.1 glass * modification, are permitted provided that the following conditions
9 1.1 glass * are met:
10 1.1 glass * 1. Redistributions of source code must retain the above copyright
11 1.1 glass * notice, this list of conditions and the following disclaimer.
12 1.1 glass * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 glass * notice, this list of conditions and the following disclaimer in the
14 1.1 glass * documentation and/or other materials provided with the distribution.
15 1.1 glass * 3. All advertising materials mentioning features or use of this software
16 1.1 glass * must display the following acknowledgement:
17 1.1 glass * This product includes software developed by the University of
18 1.1 glass * California, Berkeley and its contributors.
19 1.1 glass * 4. Neither the name of the University nor the names of its contributors
20 1.1 glass * may be used to endorse or promote products derived from this software
21 1.1 glass * without specific prior written permission.
22 1.1 glass *
23 1.1 glass * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.1 glass * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.1 glass * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.1 glass * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.1 glass * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.1 glass * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.1 glass * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.1 glass * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.1 glass * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.1 glass * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.1 glass * SUCH DAMAGE.
34 1.1 glass *
35 1.15 gwr * @(#)if_le.c 8.2 (Berkeley) 10/30/93
36 1.1 glass */
37 1.1 glass
38 1.1 glass #include "bpfilter.h"
39 1.1 glass
40 1.1 glass /*
41 1.1 glass * AMD 7990 LANCE
42 1.1 glass */
43 1.8 glass #include <sys/param.h>
44 1.10 gwr #include <sys/device.h>
45 1.8 glass #include <sys/systm.h>
46 1.10 gwr #include <sys/kernel.h>
47 1.8 glass #include <sys/mbuf.h>
48 1.8 glass #include <sys/buf.h>
49 1.8 glass #include <sys/socket.h>
50 1.8 glass #include <sys/syslog.h>
51 1.8 glass #include <sys/ioctl.h>
52 1.10 gwr #include <sys/malloc.h>
53 1.8 glass #include <sys/errno.h>
54 1.8 glass
55 1.8 glass #include <net/if.h>
56 1.8 glass #include <net/netisr.h>
57 1.8 glass #include <net/route.h>
58 1.1 glass
59 1.10 gwr #if NBPFILTER > 0
60 1.10 gwr #include <sys/select.h>
61 1.10 gwr #include <net/bpf.h>
62 1.10 gwr #include <net/bpfdesc.h>
63 1.10 gwr #endif
64 1.10 gwr
65 1.1 glass #ifdef INET
66 1.8 glass #include <netinet/in.h>
67 1.8 glass #include <netinet/in_systm.h>
68 1.8 glass #include <netinet/in_var.h>
69 1.8 glass #include <netinet/ip.h>
70 1.8 glass #include <netinet/if_ether.h>
71 1.1 glass #endif
72 1.1 glass
73 1.1 glass #ifdef NS
74 1.8 glass #include <netns/ns.h>
75 1.8 glass #include <netns/ns_if.h>
76 1.1 glass #endif
77 1.1 glass
78 1.10 gwr #ifdef APPLETALK
79 1.10 gwr #include <netddp/atalk.h>
80 1.1 glass #endif
81 1.1 glass
82 1.8 glass #include <machine/autoconf.h>
83 1.10 gwr #include <machine/cpu.h>
84 1.1 glass
85 1.1 glass #include "if_lereg.h"
86 1.1 glass #include "if_le.h"
87 1.1 glass #include "if_le_subr.h"
88 1.1 glass
89 1.10 gwr /*
90 1.10 gwr * The lance has only 24 address lines. When it accesses memory,
91 1.10 gwr * the high address lines are hard-wired to 0xFF, so we must:
92 1.10 gwr * (1) put what we want the LANCE to see above 0xFF000000, and
93 1.10 gwr * (2) mask our CPU addresses down to 24 bits for the LANCE.
94 1.10 gwr */
95 1.10 gwr #define LANCE_ADDR(x) ((u_int)(x) & 0xFFffff)
96 1.1 glass
97 1.10 gwr /* console error messages */
98 1.10 gwr int ledebug = 0;
99 1.1 glass
100 1.10 gwr #ifdef PACKETSTATS
101 1.10 gwr long lexpacketsizes[LEMTU+1];
102 1.10 gwr long lerpacketsizes[LEMTU+1];
103 1.10 gwr #endif
104 1.10 gwr
105 1.10 gwr /* autoconfiguration driver */
106 1.15 gwr void le_attach(struct device *, struct device *, void *);
107 1.10 gwr
108 1.10 gwr struct cfdriver lecd = {
109 1.15 gwr NULL, "le", le_md_match, le_attach,
110 1.10 gwr DV_IFNET, sizeof(struct le_softc),
111 1.10 gwr };
112 1.10 gwr
113 1.10 gwr /* Forwards */
114 1.10 gwr void lesetladrf(struct le_softc *);
115 1.10 gwr void lereset(struct device *);
116 1.10 gwr int leinit(int);
117 1.10 gwr int lestart(struct ifnet *);
118 1.10 gwr void lexint(struct le_softc *);
119 1.10 gwr void lerint(struct le_softc *);
120 1.10 gwr void leread(struct le_softc *, char *, int);
121 1.10 gwr int leput(char *, struct mbuf *);
122 1.10 gwr struct mbuf *leget(char *, int, int, struct ifnet *);
123 1.14 gwr int leioctl(struct ifnet *, u_long, caddr_t);
124 1.10 gwr void leerror(struct le_softc *, int);
125 1.10 gwr void lererror(struct le_softc *, char *);
126 1.10 gwr void lexerror(struct le_softc *);
127 1.10 gwr int lewatchdog(int); /* XXX */
128 1.1 glass
129 1.1 glass /*
130 1.1 glass * Interface exists: make available by filling in network interface
131 1.1 glass * record. System will initialize the interface when it is ready
132 1.1 glass * to accept packets.
133 1.1 glass */
134 1.10 gwr void
135 1.15 gwr le_attach(parent, self, aux)
136 1.10 gwr struct device *parent;
137 1.10 gwr struct device *self;
138 1.15 gwr void *aux;
139 1.10 gwr {
140 1.15 gwr struct le_softc *sc = (void *) self;
141 1.10 gwr volatile struct lereg2 *ler2;
142 1.10 gwr struct ifnet *ifp = &sc->sc_if;
143 1.10 gwr int pri;
144 1.10 gwr u_int a;
145 1.15 gwr caddr_t dvma_malloc();
146 1.10 gwr
147 1.15 gwr le_md_attach(parent, self, aux);
148 1.15 gwr printf(" hwaddr %s\n", ether_sprintf(sc->sc_addr));
149 1.1 glass
150 1.1 glass /*
151 1.1 glass * Setup for transmit/receive
152 1.10 gwr *
153 1.10 gwr * According to Van, some versions of the Lance only use this
154 1.10 gwr * address to receive packets; it doesn't put them in
155 1.10 gwr * output packets. We'll want to make sure that lestart()
156 1.10 gwr * installs the address.
157 1.1 glass */
158 1.10 gwr ler2 = sc->sc_r2;
159 1.10 gwr ler2->ler2_padr[0] = sc->sc_addr[1];
160 1.10 gwr ler2->ler2_padr[1] = sc->sc_addr[0];
161 1.10 gwr ler2->ler2_padr[2] = sc->sc_addr[3];
162 1.10 gwr ler2->ler2_padr[3] = sc->sc_addr[2];
163 1.10 gwr ler2->ler2_padr[4] = sc->sc_addr[5];
164 1.10 gwr ler2->ler2_padr[5] = sc->sc_addr[4];
165 1.3 glass a = LANCE_ADDR(ler2->ler2_rmd);
166 1.3 glass ler2->ler2_rlen = LE_RLEN | (a >> 16);
167 1.10 gwr ler2->ler2_rdra = a;
168 1.3 glass a = LANCE_ADDR(ler2->ler2_tmd);
169 1.3 glass ler2->ler2_tlen = LE_TLEN | (a >> 16);
170 1.10 gwr ler2->ler2_tdra = a;
171 1.10 gwr
172 1.10 gwr /*
173 1.10 gwr * Set up event counters.
174 1.10 gwr */
175 1.10 gwr evcnt_attach(&sc->sc_dev, "intr", &sc->sc_intrcnt);
176 1.10 gwr evcnt_attach(&sc->sc_dev, "errs", &sc->sc_errcnt);
177 1.1 glass
178 1.15 gwr /*
179 1.15 gwr * Initialize and attach S/W interface
180 1.15 gwr */
181 1.10 gwr ifp->if_unit = sc->sc_dev.dv_unit;
182 1.15 gwr ifp->if_name = lecd.cd_name;
183 1.1 glass ifp->if_ioctl = leioctl;
184 1.1 glass ifp->if_output = ether_output;
185 1.1 glass ifp->if_start = lestart;
186 1.10 gwr ifp->if_watchdog = lewatchdog; /* XXX */
187 1.10 gwr ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST;
188 1.10 gwr #ifdef IFF_NOTRAILERS
189 1.10 gwr /* XXX still compile when the blasted things are gone... */
190 1.10 gwr ifp->if_flags |= IFF_NOTRAILERS;
191 1.10 gwr #endif
192 1.15 gwr if_attach(ifp);
193 1.15 gwr ether_ifattach(ifp);
194 1.1 glass #if NBPFILTER > 0
195 1.15 gwr bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB,
196 1.15 gwr sizeof(struct ether_header));
197 1.1 glass #endif
198 1.1 glass }
199 1.1 glass
200 1.10 gwr /*
201 1.10 gwr * Setup the logical address filter
202 1.10 gwr */
203 1.10 gwr void
204 1.10 gwr lesetladrf(sc)
205 1.10 gwr register struct le_softc *sc;
206 1.10 gwr {
207 1.10 gwr register volatile struct lereg2 *ler2 = sc->sc_r2;
208 1.10 gwr register struct ifnet *ifp = &sc->sc_if;
209 1.10 gwr register struct ether_multi *enm;
210 1.10 gwr register u_char *cp, c;
211 1.10 gwr register u_long crc;
212 1.10 gwr register int i, len;
213 1.10 gwr struct ether_multistep step;
214 1.10 gwr
215 1.10 gwr /*
216 1.10 gwr * Set up multicast address filter by passing all multicast
217 1.10 gwr * addresses through a crc generator, and then using the high
218 1.10 gwr * order 6 bits as a index into the 64 bit logical address
219 1.10 gwr * filter. The high order two bits select the word, while the
220 1.10 gwr * rest of the bits select the bit within the word.
221 1.10 gwr */
222 1.10 gwr
223 1.10 gwr ler2->ler2_ladrf[0] = 0;
224 1.10 gwr ler2->ler2_ladrf[1] = 0;
225 1.10 gwr ler2->ler2_ladrf[2] = 0;
226 1.10 gwr ler2->ler2_ladrf[3] = 0;
227 1.10 gwr ifp->if_flags &= ~IFF_ALLMULTI;
228 1.10 gwr ETHER_FIRST_MULTI(step, &sc->sc_ac, enm);
229 1.10 gwr while (enm != NULL) {
230 1.10 gwr if (bcmp((caddr_t)&enm->enm_addrlo,
231 1.10 gwr (caddr_t)&enm->enm_addrhi, sizeof(enm->enm_addrlo)) != 0) {
232 1.10 gwr /*
233 1.10 gwr * We must listen to a range of multicast
234 1.10 gwr * addresses. For now, just accept all
235 1.10 gwr * multicasts, rather than trying to set only
236 1.10 gwr * those filter bits needed to match the range.
237 1.10 gwr * (At this time, the only use of address
238 1.10 gwr * ranges is for IP multicast routing, for
239 1.10 gwr * which the range is big enough to require all
240 1.10 gwr * bits set.)
241 1.10 gwr */
242 1.10 gwr ler2->ler2_ladrf[0] = 0xffff;
243 1.10 gwr ler2->ler2_ladrf[1] = 0xffff;
244 1.10 gwr ler2->ler2_ladrf[2] = 0xffff;
245 1.10 gwr ler2->ler2_ladrf[3] = 0xffff;
246 1.10 gwr ifp->if_flags |= IFF_ALLMULTI;
247 1.10 gwr return;
248 1.10 gwr }
249 1.10 gwr
250 1.10 gwr /*
251 1.10 gwr * One would think, given the AM7990 document's polynomial
252 1.10 gwr * of 0x04c11db6, that this should be 0x6db88320 (the bit
253 1.10 gwr * reversal of the AMD value), but that is not right. See
254 1.10 gwr * the BASIC listing: bit 0 (our bit 31) must then be set.
255 1.10 gwr */
256 1.10 gwr cp = (unsigned char *)&enm->enm_addrlo;
257 1.10 gwr crc = 0xffffffff;
258 1.10 gwr for (len = 6; --len >= 0;) {
259 1.10 gwr c = *cp++;
260 1.10 gwr for (i = 0; i < 8; i++) {
261 1.10 gwr if ((c & 0x01) ^ (crc & 0x01)) {
262 1.10 gwr crc >>= 1;
263 1.10 gwr crc = crc ^ 0xedb88320;
264 1.10 gwr } else
265 1.10 gwr crc >>= 1;
266 1.10 gwr c >>= 1;
267 1.10 gwr }
268 1.10 gwr }
269 1.10 gwr /* Just want the 6 most significant bits. */
270 1.10 gwr crc = crc >> 26;
271 1.10 gwr
272 1.10 gwr /* Turn on the corresponding bit in the filter. */
273 1.10 gwr ler2->ler2_ladrf[crc >> 4] |= 1 << (crc & 0xf);
274 1.10 gwr
275 1.10 gwr ETHER_NEXT_MULTI(step, enm);
276 1.10 gwr }
277 1.10 gwr }
278 1.10 gwr
279 1.10 gwr void
280 1.10 gwr lereset(dev)
281 1.10 gwr struct device *dev;
282 1.1 glass {
283 1.10 gwr struct le_softc *sc = (struct le_softc *)dev;
284 1.10 gwr volatile struct lereg1 *ler1 = sc->sc_r1;
285 1.10 gwr volatile struct lereg2 *ler2 = sc->sc_r2;
286 1.10 gwr int i, timo, stat;
287 1.10 gwr u_int a;
288 1.1 glass
289 1.10 gwr if (ledebug)
290 1.10 gwr printf("%s: resetting, reg %x, ram %x\n",
291 1.10 gwr sc->sc_dev.dv_xname, sc->sc_r1, sc->sc_r2);
292 1.10 gwr
293 1.10 gwr #ifdef DIAGNOSTIC
294 1.10 gwr i = getsr();
295 1.10 gwr if ((i & PSL_IPL) < PSL_IPL3)
296 1.10 gwr panic("lereset at low ipl, sr=%x", i);
297 1.10 gwr #endif
298 1.10 gwr
299 1.10 gwr #if NBPFILTER > 0
300 1.10 gwr if (sc->sc_if.if_flags & IFF_PROMISC)
301 1.10 gwr ler2->ler2_mode = LE_MODE_NORMAL | LE_MODE_PROM;
302 1.10 gwr else
303 1.10 gwr #endif
304 1.10 gwr ler2->ler2_mode = LE_MODE_NORMAL;
305 1.10 gwr ler1->ler1_rap = LE_CSR0;
306 1.10 gwr ler1->ler1_rdp = LE_C0_STOP;
307 1.10 gwr
308 1.10 gwr /* Setup the logical address filter */
309 1.10 gwr lesetladrf(sc);
310 1.10 gwr
311 1.10 gwr /* init receive and transmit rings */
312 1.1 glass for (i = 0; i < LERBUF; i++) {
313 1.10 gwr a = LANCE_ADDR(&ler2->ler2_rbuf[i][0]);
314 1.10 gwr ler2->ler2_rmd[i].rmd0 = a;
315 1.3 glass ler2->ler2_rmd[i].rmd1_hadr = a >> 16;
316 1.10 gwr ler2->ler2_rmd[i].rmd1_bits = LE_R1_OWN;
317 1.11 gwr ler2->ler2_rmd[i].rmd2 = -LEMTU | LE_XMD2_ONES;
318 1.1 glass ler2->ler2_rmd[i].rmd3 = 0;
319 1.1 glass }
320 1.1 glass for (i = 0; i < LETBUF; i++) {
321 1.10 gwr a = LANCE_ADDR(&ler2->ler2_tbuf[i][0]);
322 1.10 gwr ler2->ler2_tmd[i].tmd0 = a;
323 1.10 gwr ler2->ler2_tmd[i].tmd1_hadr = a >> 16;
324 1.3 glass ler2->ler2_tmd[i].tmd1_bits = 0;
325 1.11 gwr ler2->ler2_tmd[i].tmd2 = LE_XMD2_ONES;
326 1.1 glass ler2->ler2_tmd[i].tmd3 = 0;
327 1.1 glass }
328 1.10 gwr
329 1.10 gwr bzero(&ler2->ler2_rbuf[0][0], (LERBUF + LETBUF) * LEMTU);
330 1.10 gwr
331 1.10 gwr /* lance will stuff packet into receive buffer 0 next */
332 1.10 gwr sc->sc_rmd = 0;
333 1.10 gwr
334 1.10 gwr /*
335 1.10 gwr * Tell the chip where to find the initialization block.
336 1.10 gwr * Note that CSR1, CSR2, and CSR3 may only be accessed
337 1.10 gwr * while the STOP bit is set in CSR0.
338 1.10 gwr */
339 1.10 gwr a = LANCE_ADDR(&ler2->ler2_mode);
340 1.10 gwr ler1->ler1_rap = LE_CSR1;
341 1.10 gwr ler1->ler1_rdp = a;
342 1.10 gwr ler1->ler1_rap = LE_CSR2;
343 1.10 gwr ler1->ler1_rdp = a >> 16;
344 1.10 gwr ler1->ler1_rap = LE_CSR3;
345 1.10 gwr ler1->ler1_rdp = LE_C3_CONFIG;
346 1.10 gwr ler1->ler1_rap = LE_CSR0;
347 1.10 gwr ler1->ler1_rdp = LE_C0_INIT;
348 1.10 gwr timo = 10000;
349 1.10 gwr while (((stat = ler1->ler1_rdp) & (LE_C0_ERR | LE_C0_IDON)) == 0) {
350 1.10 gwr delay(100); /* XXX */
351 1.10 gwr if (--timo == 0) {
352 1.10 gwr printf("%s: init timeout, stat=%b\n",
353 1.10 gwr sc->sc_dev.dv_xname, stat, LE_C0_BITS);
354 1.10 gwr break;
355 1.10 gwr }
356 1.10 gwr }
357 1.10 gwr if (stat & LE_C0_ERR) {
358 1.10 gwr printf("%s: init failed, stat=%b\n",
359 1.10 gwr sc->sc_dev.dv_xname, stat, LE_C0_BITS);
360 1.10 gwr sc->sc_if.if_flags &= ~IFF_RUNNING; /* XXX */
361 1.10 gwr return;
362 1.10 gwr }
363 1.10 gwr ler1->ler1_rdp = LE_C0_IDON; /* clear IDON */
364 1.10 gwr ler1->ler1_rdp = LE_C0_STRT | LE_C0_INEA;
365 1.10 gwr sc->sc_if.if_flags &= ~IFF_OACTIVE;
366 1.10 gwr delay(100); /* XXX */
367 1.1 glass }
368 1.1 glass
369 1.10 gwr /*
370 1.10 gwr * Device timeout/watchdog routine. Entered if the device neglects to
371 1.10 gwr * generate an interrupt after a transmit has been started on it.
372 1.10 gwr */
373 1.10 gwr int
374 1.10 gwr lewatchdog(unit)
375 1.10 gwr int unit;
376 1.1 glass {
377 1.10 gwr struct le_softc *sc = lecd.cd_devs[unit];
378 1.10 gwr int s;
379 1.10 gwr
380 1.15 gwr log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
381 1.10 gwr sc->sc_if.if_oerrors++;
382 1.1 glass
383 1.10 gwr #ifdef DIAGNOSTIC
384 1.10 gwr s = getsr();
385 1.10 gwr if ((s & PSL_IPL) > PSL_IPL3)
386 1.10 gwr panic("lewatchdog would lower spl, sr=%x", s);
387 1.1 glass #endif
388 1.10 gwr
389 1.10 gwr s = splimp(); /* XXX - Can this lower the IPL? */
390 1.10 gwr lereset(&sc->sc_dev);
391 1.10 gwr lestart(&sc->sc_if);
392 1.10 gwr splx(s);
393 1.1 glass }
394 1.1 glass
395 1.1 glass /*
396 1.1 glass * Initialization of interface
397 1.1 glass */
398 1.10 gwr int
399 1.10 gwr leinit(unit)
400 1.1 glass int unit;
401 1.1 glass {
402 1.10 gwr struct le_softc *sc = lecd.cd_devs[unit];
403 1.10 gwr struct ifnet *ifp = &sc->sc_if;
404 1.1 glass int s;
405 1.1 glass
406 1.1 glass /* not yet, if address still unknown */
407 1.10 gwr if (ifp->if_addrlist == (struct ifaddr *)0) {
408 1.10 gwr if (ledebug)
409 1.10 gwr printf("leinit: no address yet\n");
410 1.10 gwr return (0);
411 1.10 gwr }
412 1.1 glass if ((ifp->if_flags & IFF_RUNNING) == 0) {
413 1.1 glass s = splimp();
414 1.3 glass if (ledebug)
415 1.3 glass printf("le: initializing unit %d, reg %x, ram %x\n",
416 1.10 gwr unit, sc->sc_r1, sc->sc_r2);
417 1.1 glass ifp->if_flags |= IFF_RUNNING;
418 1.10 gwr lereset(&sc->sc_dev);
419 1.15 gwr lestart(ifp);
420 1.1 glass splx(s);
421 1.1 glass }
422 1.10 gwr return (0);
423 1.1 glass }
424 1.1 glass
425 1.1 glass /*
426 1.1 glass * Start output on interface. Get another datagram to send
427 1.1 glass * off of the interface queue, and copy it to the interface
428 1.1 glass * before starting the output.
429 1.1 glass */
430 1.10 gwr int
431 1.10 gwr lestart(ifp)
432 1.10 gwr register struct ifnet *ifp;
433 1.1 glass {
434 1.10 gwr register struct le_softc *sc = lecd.cd_devs[ifp->if_unit];
435 1.10 gwr register volatile struct letmd *tmd;
436 1.1 glass register struct mbuf *m;
437 1.10 gwr register int len;
438 1.10 gwr
439 1.10 gwr #ifdef DIAGNOSTIC
440 1.10 gwr int s = getsr();
441 1.10 gwr if ((s & PSL_IPL) < PSL_IPL3)
442 1.10 gwr panic("lestart at low ipl, sr=%x", s);
443 1.10 gwr #endif
444 1.1 glass
445 1.10 gwr if ((sc->sc_if.if_flags & IFF_RUNNING) == 0) {
446 1.10 gwr if (ledebug)
447 1.10 gwr printf("lestart: not running\n");
448 1.10 gwr return (0);
449 1.10 gwr }
450 1.10 gwr IF_DEQUEUE(&sc->sc_if.if_snd, m);
451 1.10 gwr if (m == 0) {
452 1.10 gwr if (ledebug & 2)
453 1.10 gwr printf("lestart: send queue empty\n");
454 1.10 gwr return (0);
455 1.10 gwr }
456 1.10 gwr len = leput(sc->sc_r2->ler2_tbuf[0], m);
457 1.1 glass #if NBPFILTER > 0
458 1.1 glass /*
459 1.1 glass * If bpf is listening on this interface, let it
460 1.1 glass * see the packet before we commit it to the wire.
461 1.1 glass */
462 1.10 gwr if (sc->sc_if.if_bpf)
463 1.10 gwr bpf_tap(sc->sc_if.if_bpf, sc->sc_r2->ler2_tbuf[0], len);
464 1.10 gwr #endif
465 1.10 gwr
466 1.10 gwr #ifdef PACKETSTATS
467 1.10 gwr if (len <= LEMTU)
468 1.10 gwr lexpacketsizes[len]++;
469 1.1 glass #endif
470 1.10 gwr tmd = sc->sc_r2->ler2_tmd;
471 1.1 glass tmd->tmd3 = 0;
472 1.11 gwr tmd->tmd2 = -len | LE_XMD2_ONES;
473 1.10 gwr tmd->tmd1_bits = LE_T1_OWN | LE_T1_STP | LE_T1_ENP;
474 1.10 gwr sc->sc_if.if_flags |= IFF_OACTIVE;
475 1.10 gwr
476 1.10 gwr /* Set a timer just in case we never hear from the board again. */
477 1.10 gwr ifp->if_timer = 2;
478 1.10 gwr
479 1.10 gwr return (0);
480 1.10 gwr }
481 1.10 gwr
482 1.10 gwr int
483 1.15 gwr le_intr(arg)
484 1.15 gwr register void *arg;
485 1.10 gwr {
486 1.15 gwr register struct le_softc *sc = arg;
487 1.10 gwr register volatile struct lereg1 *ler1 = sc->sc_r1;
488 1.10 gwr register int csr0;
489 1.10 gwr
490 1.10 gwr csr0 = ler1->ler1_rdp;
491 1.15 gwr
492 1.15 gwr if ((csr0 & LE_C0_INTR) == 0)
493 1.15 gwr return (0);
494 1.15 gwr
495 1.10 gwr if (ledebug & 2)
496 1.10 gwr printf("[%s: intr, stat %b]\n",
497 1.10 gwr sc->sc_dev.dv_xname, csr0, LE_C0_BITS);
498 1.10 gwr
499 1.10 gwr sc->sc_intrcnt.ev_count++;
500 1.10 gwr
501 1.10 gwr if (csr0 & LE_C0_ERR) {
502 1.10 gwr sc->sc_errcnt.ev_count++;
503 1.10 gwr leerror(sc, csr0);
504 1.10 gwr if (csr0 & LE_C0_MERR) {
505 1.10 gwr sc->sc_merr++;
506 1.10 gwr lereset(&sc->sc_dev);
507 1.10 gwr return (1);
508 1.1 glass }
509 1.10 gwr if (csr0 & LE_C0_BABL)
510 1.10 gwr sc->sc_babl++;
511 1.10 gwr if (csr0 & LE_C0_CERR)
512 1.10 gwr sc->sc_cerr++;
513 1.10 gwr if (csr0 & LE_C0_MISS)
514 1.10 gwr sc->sc_miss++;
515 1.10 gwr ler1->ler1_rdp = LE_C0_BABL|LE_C0_CERR|LE_C0_MISS|LE_C0_INEA;
516 1.10 gwr }
517 1.10 gwr if ((csr0 & LE_C0_RXON) == 0) {
518 1.10 gwr sc->sc_rxoff++;
519 1.10 gwr lereset(&sc->sc_dev);
520 1.10 gwr return (1);
521 1.10 gwr }
522 1.10 gwr if ((csr0 & LE_C0_TXON) == 0) {
523 1.10 gwr sc->sc_txoff++;
524 1.10 gwr lereset(&sc->sc_dev);
525 1.10 gwr return (1);
526 1.1 glass }
527 1.10 gwr if (csr0 & LE_C0_RINT) {
528 1.1 glass /* interrupt is cleared in lerint */
529 1.10 gwr lerint(sc);
530 1.1 glass }
531 1.10 gwr if (csr0 & LE_C0_TINT) {
532 1.10 gwr ler1->ler1_rdp = LE_C0_TINT|LE_C0_INEA;
533 1.10 gwr lexint(sc);
534 1.1 glass }
535 1.10 gwr return (1);
536 1.1 glass }
537 1.1 glass
538 1.1 glass /*
539 1.1 glass * Ethernet interface transmitter interrupt.
540 1.1 glass * Start another output if more data to send.
541 1.1 glass */
542 1.10 gwr void
543 1.10 gwr lexint(sc)
544 1.10 gwr register struct le_softc *sc;
545 1.10 gwr {
546 1.10 gwr register volatile struct letmd *tmd = sc->sc_r2->ler2_tmd;
547 1.10 gwr
548 1.10 gwr sc->sc_lestats.lexints++;
549 1.10 gwr if ((sc->sc_if.if_flags & IFF_OACTIVE) == 0) {
550 1.10 gwr sc->sc_xint++;
551 1.1 glass return;
552 1.1 glass }
553 1.10 gwr if (tmd->tmd1_bits & LE_T1_OWN) {
554 1.10 gwr sc->sc_xown++;
555 1.1 glass return;
556 1.1 glass }
557 1.10 gwr if (tmd->tmd1_bits & LE_T1_ERR) {
558 1.1 glass err:
559 1.10 gwr lexerror(sc);
560 1.10 gwr sc->sc_if.if_oerrors++;
561 1.10 gwr if (tmd->tmd3 & (LE_T3_BUFF|LE_T3_UFLO)) {
562 1.10 gwr sc->sc_uflo++;
563 1.10 gwr lereset(&sc->sc_dev);
564 1.10 gwr } else if (tmd->tmd3 & LE_T3_LCOL)
565 1.10 gwr sc->sc_if.if_collisions++;
566 1.10 gwr else if (tmd->tmd3 & LE_T3_RTRY)
567 1.10 gwr sc->sc_if.if_collisions += 16;
568 1.1 glass }
569 1.10 gwr else if (tmd->tmd3 & LE_T3_BUFF)
570 1.1 glass /* XXX documentation says BUFF not included in ERR */
571 1.1 glass goto err;
572 1.10 gwr else if (tmd->tmd1_bits & LE_T1_ONE)
573 1.10 gwr sc->sc_if.if_collisions++;
574 1.10 gwr else if (tmd->tmd1_bits & LE_T1_MORE)
575 1.1 glass /* what is the real number? */
576 1.10 gwr sc->sc_if.if_collisions += 2;
577 1.1 glass else
578 1.10 gwr sc->sc_if.if_opackets++;
579 1.10 gwr sc->sc_if.if_flags &= ~IFF_OACTIVE;
580 1.10 gwr sc->sc_if.if_timer = 0; /* XXX */
581 1.10 gwr lestart(&sc->sc_if);
582 1.1 glass }
583 1.1 glass
584 1.1 glass #define LENEXTRMP \
585 1.10 gwr if (++bix == LERBUF) bix = 0, rmd = sc->sc_r2->ler2_rmd; else ++rmd
586 1.1 glass
587 1.1 glass /*
588 1.1 glass * Ethernet interface receiver interrupt.
589 1.1 glass * If input error just drop packet.
590 1.1 glass * Decapsulate packet based on type and pass to type specific
591 1.1 glass * higher-level input routine.
592 1.1 glass */
593 1.10 gwr void
594 1.10 gwr lerint(sc)
595 1.10 gwr register struct le_softc *sc;
596 1.1 glass {
597 1.10 gwr register int bix = sc->sc_rmd;
598 1.10 gwr register volatile struct lermd *rmd = &sc->sc_r2->ler2_rmd[bix];
599 1.1 glass
600 1.10 gwr sc->sc_lestats.lerints++;
601 1.1 glass /*
602 1.1 glass * Out of sync with hardware, should never happen?
603 1.1 glass */
604 1.10 gwr if (rmd->rmd1_bits & LE_R1_OWN) {
605 1.10 gwr do {
606 1.10 gwr sc->sc_lestats.lerscans++;
607 1.10 gwr LENEXTRMP;
608 1.10 gwr } while ((rmd->rmd1_bits & LE_R1_OWN) && bix != sc->sc_rmd);
609 1.10 gwr if (bix == sc->sc_rmd)
610 1.10 gwr printf("%s: RINT with no buffer\n",
611 1.10 gwr sc->sc_dev.dv_xname);
612 1.10 gwr } else
613 1.10 gwr sc->sc_lestats.lerhits++;
614 1.1 glass
615 1.1 glass /*
616 1.1 glass * Process all buffers with valid data
617 1.1 glass */
618 1.10 gwr while ((rmd->rmd1_bits & LE_R1_OWN) == 0) {
619 1.1 glass int len = rmd->rmd3;
620 1.1 glass
621 1.1 glass /* Clear interrupt to avoid race condition */
622 1.10 gwr sc->sc_r1->ler1_rdp = LE_C0_RINT|LE_C0_INEA;
623 1.1 glass
624 1.10 gwr if (rmd->rmd1_bits & LE_R1_ERR) {
625 1.10 gwr sc->sc_rmd = bix;
626 1.10 gwr lererror(sc, "bad packet");
627 1.10 gwr sc->sc_if.if_ierrors++;
628 1.10 gwr } else if ((rmd->rmd1_bits & (LE_R1_STP|LE_R1_ENP)) !=
629 1.10 gwr (LE_R1_STP|LE_R1_ENP)) {
630 1.10 gwr /* XXX make a define for LE_R1_STP|LE_R1_ENP? */
631 1.1 glass /*
632 1.1 glass * Find the end of the packet so we can see how long
633 1.1 glass * it was. We still throw it away.
634 1.1 glass */
635 1.1 glass do {
636 1.10 gwr sc->sc_r1->ler1_rdp = LE_C0_RINT|LE_C0_INEA;
637 1.1 glass rmd->rmd3 = 0;
638 1.10 gwr rmd->rmd1_bits = LE_R1_OWN;
639 1.1 glass LENEXTRMP;
640 1.10 gwr } while (!(rmd->rmd1_bits &
641 1.10 gwr (LE_R1_OWN|LE_R1_ERR|LE_R1_STP|LE_R1_ENP)));
642 1.10 gwr sc->sc_rmd = bix;
643 1.10 gwr lererror(sc, "chained buffer");
644 1.10 gwr sc->sc_rxlen++;
645 1.1 glass /*
646 1.1 glass * If search terminated without successful completion
647 1.1 glass * we reset the hardware (conservative).
648 1.1 glass */
649 1.10 gwr if ((rmd->rmd1_bits &
650 1.10 gwr (LE_R1_OWN|LE_R1_ERR|LE_R1_STP|LE_R1_ENP)) !=
651 1.10 gwr LE_R1_ENP) {
652 1.10 gwr lereset(&sc->sc_dev);
653 1.1 glass return;
654 1.1 glass }
655 1.10 gwr } else {
656 1.10 gwr leread(sc, sc->sc_r2->ler2_rbuf[bix], len);
657 1.10 gwr #ifdef PACKETSTATS
658 1.10 gwr lerpacketsizes[len]++;
659 1.10 gwr #endif
660 1.10 gwr sc->sc_lestats.lerbufs++;
661 1.10 gwr }
662 1.1 glass rmd->rmd3 = 0;
663 1.10 gwr rmd->rmd1_bits = LE_R1_OWN;
664 1.1 glass LENEXTRMP;
665 1.1 glass }
666 1.10 gwr sc->sc_rmd = bix;
667 1.1 glass }
668 1.1 glass
669 1.10 gwr void
670 1.10 gwr leread(sc, pkt, len)
671 1.10 gwr register struct le_softc *sc;
672 1.10 gwr char *pkt;
673 1.1 glass int len;
674 1.1 glass {
675 1.1 glass register struct ether_header *et;
676 1.10 gwr register struct ifnet *ifp = &sc->sc_if;
677 1.10 gwr struct mbuf *m;
678 1.10 gwr struct ifqueue *inq;
679 1.10 gwr int flags;
680 1.1 glass
681 1.10 gwr ifp->if_ipackets++;
682 1.10 gwr et = (struct ether_header *)pkt;
683 1.1 glass et->ether_type = ntohs((u_short)et->ether_type);
684 1.1 glass /* adjust input length to account for header and CRC */
685 1.10 gwr len -= sizeof(struct ether_header) + 4;
686 1.1 glass
687 1.1 glass if (len <= 0) {
688 1.1 glass if (ledebug)
689 1.1 glass log(LOG_WARNING,
690 1.10 gwr "%s: ierror(runt packet): from %s: len=%d\n",
691 1.10 gwr sc->sc_dev.dv_xname,
692 1.10 gwr ether_sprintf(et->ether_shost), len);
693 1.10 gwr sc->sc_runt++;
694 1.10 gwr ifp->if_ierrors++;
695 1.1 glass return;
696 1.1 glass }
697 1.10 gwr
698 1.10 gwr /* Setup mbuf flags we'll need later */
699 1.10 gwr flags = 0;
700 1.10 gwr if (bcmp((caddr_t)etherbroadcastaddr,
701 1.10 gwr (caddr_t)et->ether_dhost, sizeof(etherbroadcastaddr)) == 0)
702 1.10 gwr flags |= M_BCAST;
703 1.10 gwr if (et->ether_dhost[0] & 1)
704 1.10 gwr flags |= M_MCAST;
705 1.10 gwr
706 1.1 glass #if NBPFILTER > 0
707 1.1 glass /*
708 1.1 glass * Check if there's a bpf filter listening on this interface.
709 1.10 gwr * If so, hand off the raw packet to enet, then discard things
710 1.10 gwr * not destined for us (but be sure to keep broadcast/multicast).
711 1.1 glass */
712 1.10 gwr if (ifp->if_bpf) {
713 1.10 gwr bpf_tap(ifp->if_bpf, pkt,
714 1.10 gwr len + sizeof(struct ether_header));
715 1.10 gwr if ((flags & (M_BCAST | M_MCAST)) == 0 &&
716 1.10 gwr bcmp(et->ether_dhost, sc->sc_addr,
717 1.1 glass sizeof(et->ether_dhost)) != 0)
718 1.1 glass return;
719 1.1 glass }
720 1.1 glass #endif
721 1.10 gwr m = leget(pkt, len, 0, ifp);
722 1.1 glass if (m == 0)
723 1.1 glass return;
724 1.1 glass
725 1.10 gwr ether_input(ifp, et, m);
726 1.1 glass }
727 1.1 glass
728 1.1 glass /*
729 1.1 glass * Routine to copy from mbuf chain to transmit
730 1.1 glass * buffer in board local memory.
731 1.10 gwr *
732 1.10 gwr * ### this can be done by remapping in some cases
733 1.1 glass */
734 1.10 gwr int
735 1.1 glass leput(lebuf, m)
736 1.1 glass register char *lebuf;
737 1.1 glass register struct mbuf *m;
738 1.1 glass {
739 1.1 glass register struct mbuf *mp;
740 1.1 glass register int len, tlen = 0;
741 1.1 glass
742 1.1 glass for (mp = m; mp; mp = mp->m_next) {
743 1.1 glass len = mp->m_len;
744 1.1 glass if (len == 0)
745 1.1 glass continue;
746 1.1 glass tlen += len;
747 1.1 glass bcopy(mtod(mp, char *), lebuf, len);
748 1.1 glass lebuf += len;
749 1.1 glass }
750 1.1 glass m_freem(m);
751 1.1 glass if (tlen < LEMINSIZE) {
752 1.1 glass bzero(lebuf, LEMINSIZE - tlen);
753 1.1 glass tlen = LEMINSIZE;
754 1.1 glass }
755 1.10 gwr return (tlen);
756 1.1 glass }
757 1.1 glass
758 1.1 glass /*
759 1.1 glass * Routine to copy from board local memory into mbufs.
760 1.1 glass */
761 1.1 glass struct mbuf *
762 1.1 glass leget(lebuf, totlen, off0, ifp)
763 1.1 glass char *lebuf;
764 1.1 glass int totlen, off0;
765 1.1 glass struct ifnet *ifp;
766 1.1 glass {
767 1.1 glass register struct mbuf *m;
768 1.1 glass struct mbuf *top = 0, **mp = ⊤
769 1.1 glass register int off = off0, len;
770 1.1 glass register char *cp;
771 1.1 glass char *epkt;
772 1.1 glass
773 1.10 gwr lebuf += sizeof(struct ether_header);
774 1.1 glass cp = lebuf;
775 1.1 glass epkt = cp + totlen;
776 1.1 glass if (off) {
777 1.1 glass cp += off + 2 * sizeof(u_short);
778 1.1 glass totlen -= 2 * sizeof(u_short);
779 1.1 glass }
780 1.1 glass
781 1.1 glass MGETHDR(m, M_DONTWAIT, MT_DATA);
782 1.1 glass if (m == 0)
783 1.1 glass return (0);
784 1.1 glass m->m_pkthdr.rcvif = ifp;
785 1.1 glass m->m_pkthdr.len = totlen;
786 1.1 glass m->m_len = MHLEN;
787 1.1 glass
788 1.1 glass while (totlen > 0) {
789 1.1 glass if (top) {
790 1.1 glass MGET(m, M_DONTWAIT, MT_DATA);
791 1.1 glass if (m == 0) {
792 1.1 glass m_freem(top);
793 1.1 glass return (0);
794 1.1 glass }
795 1.1 glass m->m_len = MLEN;
796 1.1 glass }
797 1.1 glass len = min(totlen, epkt - cp);
798 1.1 glass if (len >= MINCLSIZE) {
799 1.1 glass MCLGET(m, M_DONTWAIT);
800 1.1 glass if (m->m_flags & M_EXT)
801 1.1 glass m->m_len = len = min(len, MCLBYTES);
802 1.1 glass else
803 1.1 glass len = m->m_len;
804 1.1 glass } else {
805 1.1 glass /*
806 1.1 glass * Place initial small packet/header at end of mbuf.
807 1.1 glass */
808 1.1 glass if (len < m->m_len) {
809 1.1 glass if (top == 0 && len + max_linkhdr <= m->m_len)
810 1.1 glass m->m_data += max_linkhdr;
811 1.1 glass m->m_len = len;
812 1.1 glass } else
813 1.1 glass len = m->m_len;
814 1.1 glass }
815 1.1 glass bcopy(cp, mtod(m, caddr_t), (unsigned)len);
816 1.1 glass cp += len;
817 1.1 glass *mp = m;
818 1.1 glass mp = &m->m_next;
819 1.1 glass totlen -= len;
820 1.1 glass if (cp == epkt)
821 1.1 glass cp = lebuf;
822 1.1 glass }
823 1.1 glass return (top);
824 1.1 glass }
825 1.1 glass
826 1.1 glass /*
827 1.1 glass * Process an ioctl request.
828 1.1 glass */
829 1.10 gwr int
830 1.1 glass leioctl(ifp, cmd, data)
831 1.1 glass register struct ifnet *ifp;
832 1.14 gwr u_long cmd;
833 1.1 glass caddr_t data;
834 1.1 glass {
835 1.10 gwr register struct ifaddr *ifa;
836 1.10 gwr register struct le_softc *sc = lecd.cd_devs[ifp->if_unit];
837 1.10 gwr register volatile struct lereg1 *ler1;
838 1.10 gwr int s, error;
839 1.10 gwr
840 1.10 gwr /* Make sure attach was called. */
841 1.10 gwr if (sc->sc_r1 == NULL)
842 1.10 gwr return (ENXIO);
843 1.1 glass
844 1.10 gwr error = 0;
845 1.10 gwr s = splimp();
846 1.1 glass switch (cmd) {
847 1.1 glass
848 1.1 glass case SIOCSIFADDR:
849 1.10 gwr ifa = (struct ifaddr *)data;
850 1.1 glass ifp->if_flags |= IFF_UP;
851 1.1 glass switch (ifa->ifa_addr->sa_family) {
852 1.1 glass #ifdef INET
853 1.1 glass case AF_INET:
854 1.10 gwr /* before arpwhohas */
855 1.10 gwr if ((ifp->if_flags & IFF_RUNNING) == 0) /* XXX */
856 1.10 gwr (void)leinit(ifp->if_unit);
857 1.1 glass ((struct arpcom *)ifp)->ac_ipaddr =
858 1.1 glass IA_SIN(ifa)->sin_addr;
859 1.1 glass arpwhohas((struct arpcom *)ifp, &IA_SIN(ifa)->sin_addr);
860 1.1 glass break;
861 1.1 glass #endif
862 1.1 glass #ifdef NS
863 1.1 glass case AF_NS:
864 1.1 glass {
865 1.1 glass register struct ns_addr *ina = &(IA_SNS(ifa)->sns_addr);
866 1.1 glass
867 1.1 glass if (ns_nullhost(*ina))
868 1.10 gwr ina->x_host = *(union ns_host *)(sc->sc_addr);
869 1.1 glass else {
870 1.10 gwr /*
871 1.10 gwr * The manual says we can't change the address
872 1.1 glass * while the receiver is armed,
873 1.1 glass * so reset everything
874 1.1 glass */
875 1.10 gwr ifp->if_flags &= ~IFF_RUNNING;
876 1.1 glass bcopy((caddr_t)ina->x_host.c_host,
877 1.10 gwr (caddr_t)sc->sc_addr, sizeof(sc->sc_addr));
878 1.1 glass }
879 1.10 gwr (void)leinit(ifp->if_unit); /* does le_setaddr() */
880 1.1 glass break;
881 1.1 glass }
882 1.1 glass #endif
883 1.1 glass default:
884 1.10 gwr (void)leinit(ifp->if_unit);
885 1.1 glass break;
886 1.1 glass }
887 1.1 glass break;
888 1.1 glass
889 1.1 glass case SIOCSIFFLAGS:
890 1.10 gwr ler1 = sc->sc_r1;
891 1.1 glass if ((ifp->if_flags & IFF_UP) == 0 &&
892 1.1 glass ifp->if_flags & IFF_RUNNING) {
893 1.10 gwr ler1->ler1_rdp = LE_C0_STOP;
894 1.1 glass ifp->if_flags &= ~IFF_RUNNING;
895 1.1 glass } else if (ifp->if_flags & IFF_UP &&
896 1.1 glass (ifp->if_flags & IFF_RUNNING) == 0)
897 1.10 gwr (void)leinit(ifp->if_unit);
898 1.1 glass /*
899 1.1 glass * If the state of the promiscuous bit changes, the interface
900 1.1 glass * must be reset to effect the change.
901 1.1 glass */
902 1.10 gwr if (((ifp->if_flags ^ sc->sc_iflags) & IFF_PROMISC) &&
903 1.1 glass (ifp->if_flags & IFF_RUNNING)) {
904 1.10 gwr sc->sc_iflags = ifp->if_flags;
905 1.10 gwr lereset(&sc->sc_dev);
906 1.10 gwr lestart(ifp);
907 1.10 gwr }
908 1.10 gwr break;
909 1.10 gwr
910 1.10 gwr case SIOCADDMULTI:
911 1.10 gwr error = ether_addmulti((struct ifreq *)data, &sc->sc_ac);
912 1.10 gwr goto update_multicast;
913 1.10 gwr
914 1.10 gwr case SIOCDELMULTI:
915 1.10 gwr error = ether_delmulti((struct ifreq *)data, &sc->sc_ac);
916 1.10 gwr update_multicast:
917 1.10 gwr if (error == ENETRESET) {
918 1.10 gwr /*
919 1.10 gwr * Multicast list has changed; set the hardware
920 1.10 gwr * filter accordingly.
921 1.10 gwr */
922 1.10 gwr lereset(&sc->sc_dev);
923 1.10 gwr lestart(ifp); /* XXX */
924 1.10 gwr error = 0;
925 1.1 glass }
926 1.1 glass break;
927 1.1 glass
928 1.1 glass default:
929 1.1 glass error = EINVAL;
930 1.1 glass }
931 1.1 glass splx(s);
932 1.1 glass return (error);
933 1.1 glass }
934 1.1 glass
935 1.10 gwr void
936 1.10 gwr leerror(sc, stat)
937 1.10 gwr register struct le_softc *sc;
938 1.1 glass int stat;
939 1.1 glass {
940 1.1 glass if (!ledebug)
941 1.1 glass return;
942 1.1 glass
943 1.1 glass /*
944 1.1 glass * Not all transceivers implement heartbeat
945 1.1 glass * so we only log CERR once.
946 1.1 glass */
947 1.10 gwr if ((stat & LE_C0_CERR) && sc->sc_cerr)
948 1.1 glass return;
949 1.10 gwr log(LOG_WARNING, "%s: error: stat=%b\n",
950 1.10 gwr sc->sc_dev.dv_xname, stat, LE_C0_BITS);
951 1.1 glass }
952 1.1 glass
953 1.10 gwr void
954 1.10 gwr lererror(sc, msg)
955 1.10 gwr register struct le_softc *sc;
956 1.1 glass char *msg;
957 1.1 glass {
958 1.10 gwr register volatile struct lermd *rmd;
959 1.1 glass int len;
960 1.1 glass
961 1.1 glass if (!ledebug)
962 1.1 glass return;
963 1.1 glass
964 1.10 gwr rmd = &sc->sc_r2->ler2_rmd[sc->sc_rmd];
965 1.1 glass len = rmd->rmd3;
966 1.10 gwr log(LOG_WARNING, "%s: ierror(%s): from %s: buf=%d, len=%d, rmd1=%b\n",
967 1.10 gwr sc->sc_dev.dv_xname, msg, len > 11 ?
968 1.10 gwr ether_sprintf((u_char *)&sc->sc_r2->ler2_rbuf[sc->sc_rmd][6]) :
969 1.10 gwr "unknown",
970 1.10 gwr sc->sc_rmd, len, rmd->rmd1_bits, LE_R1_BITS);
971 1.1 glass }
972 1.1 glass
973 1.10 gwr void
974 1.10 gwr lexerror(sc)
975 1.10 gwr register struct le_softc *sc;
976 1.1 glass {
977 1.10 gwr register volatile struct letmd *tmd;
978 1.10 gwr register int len, tmd3, tdr;
979 1.1 glass
980 1.1 glass if (!ledebug)
981 1.1 glass return;
982 1.1 glass
983 1.10 gwr tmd = sc->sc_r2->ler2_tmd;
984 1.10 gwr tmd3 = tmd->tmd3;
985 1.10 gwr tdr = tmd3 & LE_T3_TDR_MASK;
986 1.11 gwr len = -(tmd->tmd2 & ~LE_XMD2_ONES);
987 1.1 glass log(LOG_WARNING,
988 1.10 gwr "%s: oerror: to %s: buf=%d, len=%d, tmd1=%b, tmd3=%b, tdr=%d (%d nsecs)\n",
989 1.10 gwr sc->sc_dev.dv_xname, len > 5 ?
990 1.10 gwr ether_sprintf((u_char *)&sc->sc_r2->ler2_tbuf[0][0]) : "unknown",
991 1.1 glass 0, len,
992 1.10 gwr tmd->tmd1_bits, LE_T1_BITS,
993 1.10 gwr tmd3, LE_T3_BITS, tdr, tdr * 100);
994 1.1 glass }
995