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