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