if_le.c revision 1.13 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.13 mycroft * $Id: if_le.c,v 1.13 1994/07/06 01:36:23 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.13 mycroft
85 1.13 mycroft #define ETHER_MIN_LEN 64
86 1.13 mycroft #define ETHER_MAX_LEN 1518
87 1.13 mycroft #define ETHER_ADDR_LEN 6
88 1.13 mycroft
89 1.13 mycroft
90 1.1 cgd /* offsets for: ID, REGS, MEM, NVRAM */
91 1.1 cgd int lestd[] = { 0, 0x4000, 0x8000, 0xC008 };
92 1.1 cgd
93 1.1 cgd struct isr le_isr[NLE];
94 1.1 cgd
95 1.1 cgd /*
96 1.1 cgd * Ethernet software status per interface.
97 1.1 cgd *
98 1.1 cgd * Each interface is referenced by a network interface structure,
99 1.13 mycroft * arpcom.ac_if, which the routing code uses to locate the interface.
100 1.1 cgd * This structure contains the output queue for the interface, its address, ...
101 1.1 cgd */
102 1.1 cgd struct le_softc {
103 1.13 mycroft struct arpcom sc_arpcom; /* common Ethernet structures */
104 1.13 mycroft struct lereg0 *sc_r0; /* DIO registers */
105 1.13 mycroft struct lereg1 *sc_r1; /* LANCE registers */
106 1.13 mycroft void *sc_mem;
107 1.13 mycroft struct init_block *sc_init;
108 1.13 mycroft struct mds *sc_rd, *sc_td;
109 1.13 mycroft u_char *sc_rbuf, *sc_tbuf;
110 1.13 mycroft int sc_last_rd, sc_last_td;
111 1.13 mycroft int sc_no_td;
112 1.13 mycroft #ifdef LEDEBUG
113 1.13 mycroft int sc_debug;
114 1.13 mycroft #endif
115 1.1 cgd } le_softc[NLE];
116 1.1 cgd
117 1.13 mycroft int leintr __P((int));
118 1.13 mycroft int leioctl __P((struct ifnet *, int, caddr_t));
119 1.13 mycroft int lestart __P((struct ifnet *));
120 1.13 mycroft int lewatchdog __P((/* short */));
121 1.13 mycroft static inline void lewrcsr __P((/* struct le_softc *, u_short, u_short */));
122 1.13 mycroft static inline u_short lerdcsr __P((/* struct le_softc *, u_short */));
123 1.13 mycroft void leinit __P((struct le_softc *));
124 1.13 mycroft void lememinit __P((struct le_softc *));
125 1.13 mycroft void lereset __P((struct le_softc *));
126 1.13 mycroft void lestop __P((struct le_softc *));
127 1.13 mycroft void letint __P((int));
128 1.13 mycroft void lerint __P((int));
129 1.13 mycroft void leread __P((struct le_softc *, u_char *, int));
130 1.13 mycroft struct mbuf *leget __P((u_char *, int, struct ifnet *));
131 1.13 mycroft #ifdef LEDEBUG
132 1.13 mycroft void recv_print __P((struct le_softc *, int));
133 1.13 mycroft void xmit_print __P((struct le_softc *, int));
134 1.13 mycroft #endif
135 1.13 mycroft void lesetladrf __P((struct arpcom *, u_long *));
136 1.1 cgd
137 1.8 mycroft int leattach __P((struct hp_device *));
138 1.8 mycroft
139 1.8 mycroft struct driver ledriver = {
140 1.8 mycroft leattach, "le",
141 1.8 mycroft };
142 1.8 mycroft
143 1.13 mycroft static inline void
144 1.13 mycroft lewrcsr(sc, port, val)
145 1.13 mycroft struct le_softc *sc;
146 1.13 mycroft register u_short port;
147 1.13 mycroft register u_short val;
148 1.13 mycroft {
149 1.13 mycroft register struct lereg0 *ler0 = sc->sc_r0;
150 1.13 mycroft register struct lereg1 *ler1 = sc->sc_r1;
151 1.13 mycroft
152 1.13 mycroft do {
153 1.13 mycroft ler1->ler1_rap = port;
154 1.13 mycroft } while ((ler0->ler0_status & LE_ACK) == 0);
155 1.13 mycroft do {
156 1.13 mycroft ler1->ler1_rdp = val;
157 1.13 mycroft } while ((ler0->ler0_status & LE_ACK) == 0);
158 1.13 mycroft }
159 1.13 mycroft
160 1.13 mycroft static inline u_short
161 1.13 mycroft lerdcsr(sc, port)
162 1.13 mycroft struct le_softc *sc;
163 1.13 mycroft register u_short port;
164 1.13 mycroft {
165 1.13 mycroft register struct lereg0 *ler0 = sc->sc_r0;
166 1.13 mycroft register struct lereg1 *ler1 = sc->sc_r1;
167 1.13 mycroft register u_short val;
168 1.13 mycroft
169 1.13 mycroft do {
170 1.13 mycroft ler1->ler1_rap = port;
171 1.13 mycroft } while ((ler0->ler0_status & LE_ACK) == 0);
172 1.13 mycroft do {
173 1.13 mycroft val = ler1->ler1_rdp;
174 1.13 mycroft } while ((ler0->ler0_status & LE_ACK) == 0);
175 1.13 mycroft return (val);
176 1.13 mycroft }
177 1.13 mycroft
178 1.1 cgd /*
179 1.1 cgd * Interface exists: make available by filling in network interface
180 1.1 cgd * record. System will initialize the interface when it is ready
181 1.1 cgd * to accept packets.
182 1.1 cgd */
183 1.8 mycroft int
184 1.1 cgd leattach(hd)
185 1.1 cgd struct hp_device *hd;
186 1.1 cgd {
187 1.1 cgd register struct lereg0 *ler0;
188 1.5 mycroft struct le_softc *sc = &le_softc[hd->hp_unit];
189 1.13 mycroft struct ifnet *ifp = &sc->sc_arpcom.ac_if;
190 1.1 cgd char *cp;
191 1.1 cgd int i;
192 1.1 cgd
193 1.5 mycroft ler0 = sc->sc_r0 = (struct lereg0 *)(lestd[0] + (int)hd->hp_addr);
194 1.1 cgd if (ler0->ler0_id != LEID)
195 1.1 cgd return(0);
196 1.13 mycroft sc->sc_r1 = (struct lereg1 *)(lestd[1] + (int)hd->hp_addr);
197 1.13 mycroft sc->sc_mem = (void *)(lestd[2] + (int)hd->hp_addr);
198 1.1 cgd le_isr[hd->hp_unit].isr_intr = leintr;
199 1.1 cgd hd->hp_ipl = le_isr[hd->hp_unit].isr_ipl = LE_IPL(ler0->ler0_status);
200 1.1 cgd le_isr[hd->hp_unit].isr_arg = hd->hp_unit;
201 1.1 cgd ler0->ler0_id = 0xFF;
202 1.1 cgd DELAY(100);
203 1.1 cgd
204 1.1 cgd /*
205 1.1 cgd * Read the ethernet address off the board, one nibble at a time.
206 1.1 cgd */
207 1.1 cgd cp = (char *)(lestd[3] + (int)hd->hp_addr);
208 1.13 mycroft for (i = 0; i < sizeof(sc->sc_arpcom.ac_enaddr); i++) {
209 1.13 mycroft sc->sc_arpcom.ac_enaddr[i] = (*++cp & 0xF) << 4;
210 1.1 cgd cp++;
211 1.13 mycroft sc->sc_arpcom.ac_enaddr[i] |= *++cp & 0xF;
212 1.1 cgd cp++;
213 1.1 cgd }
214 1.1 cgd printf("le%d: hardware address %s\n", hd->hp_unit,
215 1.13 mycroft ether_sprintf(sc->sc_arpcom.ac_enaddr));
216 1.1 cgd
217 1.1 cgd isrlink(&le_isr[hd->hp_unit]);
218 1.1 cgd ler0->ler0_status = LE_IE;
219 1.1 cgd
220 1.1 cgd ifp->if_unit = hd->hp_unit;
221 1.1 cgd ifp->if_name = "le";
222 1.1 cgd ifp->if_output = ether_output;
223 1.1 cgd ifp->if_start = lestart;
224 1.13 mycroft ifp->if_ioctl = leioctl;
225 1.13 mycroft ifp->if_watchdog = lewatchdog;
226 1.10 mycroft ifp->if_flags =
227 1.10 mycroft IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
228 1.13 mycroft
229 1.12 mycroft if_attach(ifp);
230 1.12 mycroft ether_ifattach(ifp);
231 1.13 mycroft
232 1.1 cgd #if NBPFILTER > 0
233 1.12 mycroft bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
234 1.1 cgd #endif
235 1.1 cgd return (1);
236 1.1 cgd }
237 1.1 cgd
238 1.5 mycroft void
239 1.13 mycroft lereset(sc)
240 1.13 mycroft struct le_softc *sc;
241 1.13 mycroft {
242 1.13 mycroft
243 1.13 mycroft leinit(sc);
244 1.13 mycroft }
245 1.13 mycroft
246 1.13 mycroft int
247 1.13 mycroft lewatchdog(unit)
248 1.13 mycroft short unit;
249 1.5 mycroft {
250 1.13 mycroft struct le_softc *sc = &le_softc[unit];
251 1.5 mycroft
252 1.13 mycroft log(LOG_ERR, "le%d: device timeout\n", unit);
253 1.13 mycroft ++sc->sc_arpcom.ac_if.if_oerrors;
254 1.13 mycroft lereset(sc);
255 1.13 mycroft }
256 1.5 mycroft
257 1.13 mycroft #define LANCE_ADDR(sc, a) \
258 1.13 mycroft ((u_long)(a) - (u_long)sc->sc_mem)
259 1.9 mycroft
260 1.13 mycroft /* LANCE initialization block set up. */
261 1.13 mycroft void
262 1.13 mycroft lememinit(sc)
263 1.13 mycroft register struct le_softc *sc;
264 1.13 mycroft {
265 1.13 mycroft struct ifnet *ifp = &sc->sc_arpcom.ac_if;
266 1.13 mycroft int i;
267 1.13 mycroft void *mem;
268 1.13 mycroft u_long a;
269 1.5 mycroft
270 1.13 mycroft /*
271 1.13 mycroft * At this point we assume that the memory allocated to the Lance is
272 1.13 mycroft * quadword aligned. If it isn't then the initialisation is going
273 1.13 mycroft * fail later on.
274 1.13 mycroft */
275 1.13 mycroft mem = sc->sc_mem;
276 1.5 mycroft
277 1.13 mycroft sc->sc_init = mem;
278 1.13 mycroft #if NBPFILTER > 0
279 1.13 mycroft if (ifp->if_flags & IFF_PROMISC)
280 1.13 mycroft sc->sc_init->mode = LE_NORMAL | LE_PROM;
281 1.13 mycroft else
282 1.13 mycroft #endif
283 1.13 mycroft sc->sc_init->mode = LE_NORMAL;
284 1.13 mycroft for (i = 0; i < ETHER_ADDR_LEN; i++)
285 1.13 mycroft sc->sc_init->padr[i] = sc->sc_arpcom.ac_enaddr[i^1];
286 1.13 mycroft lesetladrf(&sc->sc_arpcom, sc->sc_init->ladrf);
287 1.13 mycroft mem += sizeof(struct init_block);
288 1.13 mycroft
289 1.13 mycroft sc->sc_rd = mem;
290 1.13 mycroft a = LANCE_ADDR(sc, mem);
291 1.13 mycroft sc->sc_init->rdra = a;
292 1.13 mycroft sc->sc_init->rlen = ((a >> 16) & 0xff) | (RLEN << 13);
293 1.13 mycroft mem += NRBUF * sizeof(struct mds);
294 1.13 mycroft
295 1.13 mycroft sc->sc_td = mem;
296 1.13 mycroft a = LANCE_ADDR(sc, mem);
297 1.13 mycroft sc->sc_init->tdra = a;
298 1.13 mycroft sc->sc_init->tlen = ((a >> 16) & 0xff) | (TLEN << 13);
299 1.13 mycroft mem += NTBUF * sizeof(struct mds);
300 1.5 mycroft
301 1.13 mycroft /*
302 1.13 mycroft * Set up receive ring descriptors.
303 1.13 mycroft */
304 1.13 mycroft sc->sc_rbuf = mem;
305 1.13 mycroft for (i = 0; i < NRBUF; i++) {
306 1.13 mycroft a = LANCE_ADDR(sc, mem);
307 1.13 mycroft sc->sc_rd[i].addr = a;
308 1.13 mycroft sc->sc_rd[i].flags = ((a >> 16) & 0xff) | LE_OWN;
309 1.13 mycroft sc->sc_rd[i].bcnt = -BUFSIZE;
310 1.13 mycroft sc->sc_rd[i].mcnt = 0;
311 1.13 mycroft mem += BUFSIZE;
312 1.5 mycroft }
313 1.5 mycroft
314 1.13 mycroft /*
315 1.13 mycroft * Set up transmit ring descriptors.
316 1.13 mycroft */
317 1.13 mycroft sc->sc_tbuf = mem;
318 1.13 mycroft for (i = 0; i < NTBUF; i++) {
319 1.13 mycroft a = LANCE_ADDR(sc, mem);
320 1.13 mycroft sc->sc_td[i].addr = a;
321 1.13 mycroft sc->sc_td[i].flags= ((a >> 16) & 0xff);
322 1.13 mycroft sc->sc_td[i].bcnt = 0xf000;
323 1.13 mycroft sc->sc_td[i].mcnt = 0;
324 1.13 mycroft mem += BUFSIZE;
325 1.6 mycroft }
326 1.6 mycroft }
327 1.6 mycroft
328 1.8 mycroft void
329 1.13 mycroft lestop(sc)
330 1.13 mycroft struct le_softc *sc;
331 1.1 cgd {
332 1.1 cgd
333 1.13 mycroft lewrcsr(sc, 0, LE_STOP);
334 1.1 cgd }
335 1.1 cgd
336 1.1 cgd /*
337 1.13 mycroft * Initialization of interface; set up initialization block
338 1.13 mycroft * and transmit/receive descriptor rings.
339 1.1 cgd */
340 1.8 mycroft void
341 1.13 mycroft leinit(sc)
342 1.13 mycroft register struct le_softc *sc;
343 1.1 cgd {
344 1.13 mycroft struct ifnet *ifp = &sc->sc_arpcom.ac_if;
345 1.1 cgd int s;
346 1.13 mycroft register int timo;
347 1.13 mycroft u_long a;
348 1.1 cgd
349 1.13 mycroft /* Address not known. */
350 1.13 mycroft if (!ifp->if_addrlist)
351 1.1 cgd return;
352 1.13 mycroft
353 1.13 mycroft s = splimp();
354 1.13 mycroft
355 1.13 mycroft /* Don't want to get in a weird state. */
356 1.13 mycroft lewrcsr(sc, 0, LE_STOP);
357 1.13 mycroft DELAY(100);
358 1.13 mycroft
359 1.13 mycroft sc->sc_last_rd = sc->sc_last_td = sc->sc_no_td = 0;
360 1.13 mycroft
361 1.13 mycroft /* Set up LANCE init block. */
362 1.13 mycroft lememinit(sc);
363 1.13 mycroft
364 1.13 mycroft /* Turn on byte swapping. */
365 1.13 mycroft lewrcsr(sc, 3, LE_BSWP);
366 1.13 mycroft
367 1.13 mycroft /* Give LANCE the physical address of its init block. */
368 1.13 mycroft a = LANCE_ADDR(sc, sc->sc_init);
369 1.13 mycroft lewrcsr(sc, 1, a);
370 1.13 mycroft lewrcsr(sc, 2, (a >> 16) & 0xff);
371 1.13 mycroft
372 1.13 mycroft /* Try to initialize the LANCE. */
373 1.13 mycroft DELAY(100);
374 1.13 mycroft lewrcsr(sc, 0, LE_INIT);
375 1.13 mycroft
376 1.13 mycroft /* Wait for initialization to finish. */
377 1.13 mycroft for (timo = 100000; timo; timo--)
378 1.13 mycroft if (lerdcsr(sc, 0) & LE_IDON)
379 1.13 mycroft break;
380 1.13 mycroft
381 1.13 mycroft if (lerdcsr(sc, 0) & LE_IDON) {
382 1.13 mycroft /* Start the LANCE. */
383 1.13 mycroft lewrcsr(sc, 0, LE_INEA | LE_STRT | LE_IDON);
384 1.1 cgd ifp->if_flags |= IFF_RUNNING;
385 1.13 mycroft ifp->if_flags &= ~IFF_OACTIVE;
386 1.13 mycroft lestart(ifp);
387 1.13 mycroft } else
388 1.13 mycroft printf("le%d: card failed to initialize\n", ifp->if_unit);
389 1.13 mycroft
390 1.13 mycroft (void) splx(s);
391 1.1 cgd }
392 1.1 cgd
393 1.1 cgd /*
394 1.13 mycroft * Setup output on interface.
395 1.13 mycroft * Get another datagram to send off of the interface queue, and map it to the
396 1.13 mycroft * interface before starting the output.
397 1.13 mycroft * Called only at splimp or interrupt level.
398 1.1 cgd */
399 1.8 mycroft int
400 1.1 cgd lestart(ifp)
401 1.1 cgd struct ifnet *ifp;
402 1.1 cgd {
403 1.5 mycroft register struct le_softc *sc = &le_softc[ifp->if_unit];
404 1.13 mycroft struct mbuf *m0, *m;
405 1.13 mycroft u_char *buffer;
406 1.13 mycroft int len;
407 1.13 mycroft int i;
408 1.13 mycroft struct mds *cdm;
409 1.13 mycroft
410 1.13 mycroft if ((sc->sc_arpcom.ac_if.if_flags ^ IFF_RUNNING) &
411 1.13 mycroft (IFF_RUNNING | IFF_OACTIVE))
412 1.13 mycroft return;
413 1.13 mycroft
414 1.13 mycroft outloop:
415 1.13 mycroft if (sc->sc_no_td >= NTBUF) {
416 1.13 mycroft sc->sc_arpcom.ac_if.if_flags |= IFF_OACTIVE;
417 1.13 mycroft #ifdef LEDEBUG
418 1.13 mycroft if (sc->sc_debug)
419 1.13 mycroft printf("no_td = %x, last_td = %x\n", sc->sc_no_td,
420 1.13 mycroft sc->sc_last_td);
421 1.13 mycroft #endif
422 1.13 mycroft return;
423 1.13 mycroft }
424 1.13 mycroft
425 1.13 mycroft cdm = &sc->sc_td[sc->sc_last_td];
426 1.13 mycroft #if 0 /* XXX redundant */
427 1.13 mycroft if (cdm->flags & LE_OWN)
428 1.13 mycroft return;
429 1.13 mycroft #endif
430 1.13 mycroft
431 1.13 mycroft IF_DEQUEUE(&sc->sc_arpcom.ac_if.if_snd, m);
432 1.13 mycroft if (!m)
433 1.13 mycroft return;
434 1.13 mycroft
435 1.13 mycroft ++sc->sc_no_td;
436 1.13 mycroft
437 1.13 mycroft /*
438 1.13 mycroft * Copy the mbuf chain into the transmit buffer.
439 1.13 mycroft */
440 1.13 mycroft buffer = sc->sc_tbuf + (BUFSIZE * sc->sc_last_td);
441 1.13 mycroft len = 0;
442 1.13 mycroft for (m0 = m; m; m = m->m_next) {
443 1.13 mycroft bcopy(mtod(m, caddr_t), buffer, m->m_len);
444 1.13 mycroft buffer += m->m_len;
445 1.13 mycroft len += m->m_len;
446 1.13 mycroft }
447 1.13 mycroft
448 1.1 cgd #if NBPFILTER > 0
449 1.13 mycroft if (sc->sc_arpcom.ac_if.if_bpf)
450 1.13 mycroft bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m0);
451 1.13 mycroft #endif
452 1.13 mycroft
453 1.13 mycroft m_freem(m0);
454 1.13 mycroft len = max(len, ETHER_MIN_LEN);
455 1.13 mycroft
456 1.13 mycroft /*
457 1.13 mycroft * Init transmit registers, and set transmit start flag.
458 1.13 mycroft */
459 1.13 mycroft cdm->bcnt = -len;
460 1.13 mycroft cdm->mcnt = 0;
461 1.13 mycroft cdm->flags |= LE_OWN | LE_STP | LE_ENP;
462 1.13 mycroft
463 1.13 mycroft #ifdef LEDEBUG
464 1.13 mycroft if (sc->sc_debug)
465 1.13 mycroft xmit_print(sc, sc->sc_last_td);
466 1.1 cgd #endif
467 1.13 mycroft
468 1.13 mycroft lewrcsr(sc, 0, LE_INEA | LE_TDMD);
469 1.13 mycroft
470 1.13 mycroft /* possible more packets */
471 1.13 mycroft if (++sc->sc_last_td >= NTBUF)
472 1.13 mycroft sc->sc_last_td = 0;
473 1.13 mycroft goto outloop;
474 1.1 cgd }
475 1.1 cgd
476 1.13 mycroft /*
477 1.13 mycroft * Controller interrupt.
478 1.13 mycroft */
479 1.8 mycroft int
480 1.1 cgd leintr(unit)
481 1.13 mycroft int unit;
482 1.1 cgd {
483 1.5 mycroft register struct le_softc *sc = &le_softc[unit];
484 1.13 mycroft register u_short isr;
485 1.13 mycroft
486 1.13 mycroft isr = lerdcsr(sc, 0);
487 1.13 mycroft #ifdef LEDEBUG
488 1.13 mycroft if (sc->sc_debug)
489 1.13 mycroft printf("le%d: leintr entering with isr=%04x\n",
490 1.13 mycroft unit, isr);
491 1.13 mycroft #endif
492 1.13 mycroft if ((isr & LE_INTR) == 0)
493 1.13 mycroft return 0;
494 1.13 mycroft
495 1.13 mycroft do {
496 1.13 mycroft lewrcsr(sc, 0,
497 1.13 mycroft isr & (LE_INEA | LE_BABL | LE_MISS | LE_MERR |
498 1.13 mycroft LE_RINT | LE_TINT | LE_IDON));
499 1.13 mycroft if (isr & (LE_BABL | LE_CERR | LE_MISS | LE_MERR)) {
500 1.13 mycroft if (isr & LE_BABL) {
501 1.13 mycroft printf("le%d: BABL\n", unit);
502 1.13 mycroft sc->sc_arpcom.ac_if.if_oerrors++;
503 1.13 mycroft }
504 1.13 mycroft #if 0
505 1.13 mycroft if (isr & LE_CERR) {
506 1.13 mycroft printf("le%d: CERR\n", unit);
507 1.13 mycroft sc->sc_arpcom.ac_if.if_collisions++;
508 1.13 mycroft }
509 1.13 mycroft #endif
510 1.13 mycroft if (isr & LE_MISS) {
511 1.13 mycroft printf("le%d: MISS\n", unit);
512 1.13 mycroft sc->sc_arpcom.ac_if.if_ierrors++;
513 1.13 mycroft }
514 1.13 mycroft if (isr & LE_MERR) {
515 1.13 mycroft printf("le%d: MERR\n", unit);
516 1.13 mycroft lereset(sc);
517 1.13 mycroft goto out;
518 1.13 mycroft }
519 1.13 mycroft }
520 1.1 cgd
521 1.13 mycroft if ((isr & LE_RXON) == 0) {
522 1.13 mycroft printf("le%d: receiver disabled\n", unit);
523 1.13 mycroft sc->sc_arpcom.ac_if.if_ierrors++;
524 1.13 mycroft lereset(sc);
525 1.13 mycroft goto out;
526 1.13 mycroft }
527 1.13 mycroft if ((isr & LE_TXON) == 0) {
528 1.13 mycroft printf("le%d: transmitter disabled\n", unit);
529 1.13 mycroft sc->sc_arpcom.ac_if.if_oerrors++;
530 1.5 mycroft lereset(sc);
531 1.13 mycroft goto out;
532 1.13 mycroft }
533 1.13 mycroft
534 1.13 mycroft if (isr & LE_RINT) {
535 1.13 mycroft /* Reset watchdog timer. */
536 1.13 mycroft sc->sc_arpcom.ac_if.if_timer = 0;
537 1.13 mycroft lerint(unit);
538 1.13 mycroft }
539 1.13 mycroft if (isr & LE_TINT) {
540 1.13 mycroft /* Reset watchdog timer. */
541 1.13 mycroft sc->sc_arpcom.ac_if.if_timer = 0;
542 1.13 mycroft letint(unit);
543 1.1 cgd }
544 1.13 mycroft
545 1.13 mycroft isr = lerdcsr(sc, 0);
546 1.13 mycroft } while ((isr & LE_INTR) != 0);
547 1.13 mycroft
548 1.13 mycroft #ifdef LEDEBUG
549 1.13 mycroft if (sc->sc_debug)
550 1.13 mycroft printf("le%d: leintr returning with isr=%04x\n",
551 1.13 mycroft unit, isr);
552 1.13 mycroft #endif
553 1.13 mycroft
554 1.13 mycroft out:
555 1.13 mycroft return 1;
556 1.1 cgd }
557 1.1 cgd
558 1.13 mycroft #define NEXTTDS \
559 1.13 mycroft if (++tmd == NTBUF) tmd=0, cdm=sc->sc_td; else ++cdm
560 1.13 mycroft
561 1.8 mycroft void
562 1.13 mycroft letint(unit)
563 1.13 mycroft int unit;
564 1.1 cgd {
565 1.13 mycroft register struct le_softc *sc = &le_softc[unit];
566 1.13 mycroft register int tmd = (sc->sc_last_td - sc->sc_no_td + NTBUF) % NTBUF;
567 1.13 mycroft struct mds *cdm = &sc->sc_td[tmd];
568 1.1 cgd
569 1.13 mycroft if (cdm->flags & LE_OWN) {
570 1.13 mycroft /* Race condition with loop below. */
571 1.13 mycroft #ifdef LEDEBUG
572 1.13 mycroft if (sc->sc_debug)
573 1.13 mycroft printf("le%d: extra tint\n", unit);
574 1.13 mycroft #endif
575 1.1 cgd return;
576 1.1 cgd }
577 1.13 mycroft
578 1.13 mycroft sc->sc_arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
579 1.13 mycroft
580 1.6 mycroft do {
581 1.13 mycroft if (sc->sc_no_td <= 0)
582 1.13 mycroft break;
583 1.13 mycroft #ifdef LEDEBUG
584 1.13 mycroft if (sc->sc_debug)
585 1.13 mycroft printf("trans cdm = %x\n", cdm);
586 1.13 mycroft #endif
587 1.13 mycroft sc->sc_arpcom.ac_if.if_opackets++;
588 1.13 mycroft --sc->sc_no_td;
589 1.13 mycroft if (cdm->flags & (LE_TBUFF | LE_UFLO | LE_LCOL | LE_LCAR | LE_RTRY)) {
590 1.13 mycroft if (cdm->flags & LE_TBUFF)
591 1.13 mycroft printf("le%d: TBUFF\n", unit);
592 1.13 mycroft if ((cdm->flags & (LE_TBUFF | LE_UFLO)) == LE_UFLO)
593 1.13 mycroft printf("le%d: UFLO\n", unit);
594 1.13 mycroft if (cdm->flags & LE_UFLO) {
595 1.13 mycroft lereset(sc);
596 1.13 mycroft return;
597 1.13 mycroft }
598 1.13 mycroft #if 0
599 1.13 mycroft if (cdm->flags & LE_LCOL) {
600 1.13 mycroft printf("le%d: late collision\n", unit);
601 1.13 mycroft sc->sc_arpcom.ac_if.if_collisions++;
602 1.13 mycroft }
603 1.13 mycroft if (cdm->flags & LE_LCAR)
604 1.13 mycroft printf("le%d: lost carrier\n", unit);
605 1.13 mycroft if (cdm->flags & LE_RTRY) {
606 1.13 mycroft printf("le%d: excessive collisions, tdr %d\n",
607 1.13 mycroft unit, cdm->flags & 0x1ff);
608 1.13 mycroft sc->sc_arpcom.ac_if.if_collisions++;
609 1.13 mycroft }
610 1.13 mycroft #endif
611 1.6 mycroft }
612 1.13 mycroft NEXTTDS;
613 1.13 mycroft } while ((cdm->flags & LE_OWN) == 0);
614 1.6 mycroft
615 1.13 mycroft lestart(&sc->sc_arpcom.ac_if);
616 1.13 mycroft }
617 1.6 mycroft
618 1.13 mycroft #define NEXTRDS \
619 1.13 mycroft if (++rmd == NRBUF) rmd=0, cdm=sc->sc_rd; else ++cdm
620 1.13 mycroft
621 1.13 mycroft /* only called from one place, so may as well integrate */
622 1.8 mycroft void
623 1.13 mycroft lerint(unit)
624 1.13 mycroft int unit;
625 1.1 cgd {
626 1.13 mycroft register struct le_softc *sc = &le_softc[unit];
627 1.13 mycroft register int rmd = sc->sc_last_rd;
628 1.13 mycroft struct mds *cdm = &sc->sc_rd[rmd];
629 1.1 cgd
630 1.13 mycroft if (cdm->flags & LE_OWN) {
631 1.13 mycroft /* Race condition with loop below. */
632 1.13 mycroft #ifdef LEDEBUG
633 1.13 mycroft if (sc->sc_debug)
634 1.13 mycroft printf("le%d: extra rint\n", unit);
635 1.13 mycroft #endif
636 1.13 mycroft return;
637 1.1 cgd }
638 1.1 cgd
639 1.13 mycroft /* Process all buffers with valid data. */
640 1.13 mycroft do {
641 1.13 mycroft if (cdm->flags & (LE_FRAM | LE_OFLO | LE_CRC | LE_RBUFF)) {
642 1.13 mycroft if ((cdm->flags & (LE_FRAM | LE_OFLO | LE_ENP)) == (LE_FRAM | LE_ENP))
643 1.13 mycroft printf("le%d: FRAM\n", unit);
644 1.13 mycroft if ((cdm->flags & (LE_OFLO | LE_ENP)) == LE_OFLO)
645 1.13 mycroft printf("le%d: OFLO\n", unit);
646 1.13 mycroft if ((cdm->flags & (LE_CRC | LE_OFLO | LE_ENP)) == (LE_CRC | LE_ENP))
647 1.13 mycroft printf("le%d: CRC\n", unit);
648 1.13 mycroft if (cdm->flags & LE_RBUFF)
649 1.13 mycroft printf("le%d: RBUFF\n", unit);
650 1.13 mycroft } else if (cdm->flags & (LE_STP | LE_ENP) != (LE_STP | LE_ENP)) {
651 1.1 cgd do {
652 1.13 mycroft cdm->mcnt = 0;
653 1.13 mycroft cdm->flags |= LE_OWN;
654 1.13 mycroft NEXTRDS;
655 1.13 mycroft } while ((cdm->flags & (LE_OWN | LE_ERR | LE_STP | LE_ENP)) == 0);
656 1.13 mycroft sc->sc_last_rd = rmd;
657 1.13 mycroft printf("le%d: chained buffer\n", unit);
658 1.13 mycroft if ((cdm->flags & (LE_OWN | LE_ERR | LE_STP | LE_ENP)) != LE_ENP) {
659 1.5 mycroft lereset(sc);
660 1.1 cgd return;
661 1.1 cgd }
662 1.13 mycroft } else {
663 1.13 mycroft #ifdef LEDEBUG
664 1.13 mycroft if (sc->sc_debug)
665 1.13 mycroft recv_print(sc, sc->sc_last_rd);
666 1.13 mycroft #endif
667 1.13 mycroft leread(sc, sc->sc_rbuf + (BUFSIZE * rmd),
668 1.13 mycroft (int)cdm->mcnt);
669 1.13 mycroft sc->sc_arpcom.ac_if.if_ipackets++;
670 1.13 mycroft }
671 1.13 mycroft
672 1.13 mycroft cdm->mcnt = 0;
673 1.13 mycroft cdm->flags |= LE_OWN;
674 1.13 mycroft NEXTRDS;
675 1.13 mycroft #ifdef LEDEBUG
676 1.13 mycroft if (sc->sc_debug)
677 1.13 mycroft printf("sc->sc_last_rd = %x, cdm = %x\n",
678 1.13 mycroft sc->sc_last_rd, cdm);
679 1.13 mycroft #endif
680 1.13 mycroft } while ((cdm->flags & LE_OWN) == 0);
681 1.13 mycroft
682 1.13 mycroft sc->sc_last_rd = rmd;
683 1.1 cgd }
684 1.1 cgd
685 1.13 mycroft /*
686 1.13 mycroft * Pass a packet to the higher levels.
687 1.13 mycroft */
688 1.8 mycroft void
689 1.5 mycroft leread(sc, buf, len)
690 1.5 mycroft register struct le_softc *sc;
691 1.13 mycroft u_char *buf;
692 1.1 cgd int len;
693 1.1 cgd {
694 1.13 mycroft struct ether_header *eh;
695 1.13 mycroft struct mbuf *m;
696 1.13 mycroft
697 1.13 mycroft eh = (struct ether_header *)buf;
698 1.5 mycroft len -= sizeof(struct ether_header) + 4;
699 1.13 mycroft if (len <= 0)
700 1.13 mycroft return;
701 1.1 cgd
702 1.13 mycroft /* Pull packet off interface. */
703 1.13 mycroft m = leget(buf, len, &sc->sc_arpcom.ac_if);
704 1.13 mycroft if (m == 0)
705 1.1 cgd return;
706 1.5 mycroft
707 1.1 cgd #if NBPFILTER > 0
708 1.1 cgd /*
709 1.13 mycroft * Check if there's a BPF listener on this interface.
710 1.13 mycroft * If so, hand off the raw packet to BPF.
711 1.1 cgd */
712 1.13 mycroft if (sc->sc_arpcom.ac_if.if_bpf) {
713 1.13 mycroft bpf_mtap(sc->sc_arpcom.ac_if.if_bpf, m);
714 1.13 mycroft
715 1.13 mycroft /*
716 1.13 mycroft * Note that the interface cannot be in promiscuous mode if
717 1.13 mycroft * there are no BPF listeners. And if we are in promiscuous
718 1.13 mycroft * mode, we have to check if this packet is really ours.
719 1.13 mycroft */
720 1.13 mycroft if ((sc->sc_arpcom.ac_if.if_flags & IFF_PROMISC) &&
721 1.13 mycroft (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
722 1.13 mycroft bcmp(eh->ether_dhost, sc->sc_arpcom.ac_enaddr,
723 1.13 mycroft sizeof(eh->ether_dhost)) != 0) {
724 1.13 mycroft m_freem(m);
725 1.1 cgd return;
726 1.13 mycroft }
727 1.1 cgd }
728 1.1 cgd #endif
729 1.5 mycroft
730 1.13 mycroft ether_input(&sc->sc_arpcom.ac_if, eh, m);
731 1.1 cgd }
732 1.1 cgd
733 1.1 cgd /*
734 1.13 mycroft * Supporting routines
735 1.1 cgd */
736 1.1 cgd
737 1.1 cgd /*
738 1.13 mycroft * Pull data off an interface.
739 1.13 mycroft * Len is length of data, with local net header stripped.
740 1.13 mycroft * We copy the data into mbufs. When full cluster sized units are present
741 1.13 mycroft * we copy into clusters.
742 1.1 cgd */
743 1.1 cgd struct mbuf *
744 1.13 mycroft leget(buf, totlen, ifp)
745 1.13 mycroft u_char *buf;
746 1.13 mycroft int totlen;
747 1.1 cgd struct ifnet *ifp;
748 1.1 cgd {
749 1.13 mycroft struct mbuf *top, **mp, *m, *p;
750 1.13 mycroft int len;
751 1.13 mycroft register caddr_t cp = buf;
752 1.1 cgd char *epkt;
753 1.1 cgd
754 1.13 mycroft buf += sizeof(struct ether_header);
755 1.13 mycroft cp = buf;
756 1.1 cgd epkt = cp + totlen;
757 1.1 cgd
758 1.1 cgd MGETHDR(m, M_DONTWAIT, MT_DATA);
759 1.1 cgd if (m == 0)
760 1.13 mycroft return 0;
761 1.1 cgd m->m_pkthdr.rcvif = ifp;
762 1.1 cgd m->m_pkthdr.len = totlen;
763 1.1 cgd m->m_len = MHLEN;
764 1.13 mycroft top = 0;
765 1.13 mycroft mp = ⊤
766 1.1 cgd
767 1.1 cgd while (totlen > 0) {
768 1.1 cgd if (top) {
769 1.1 cgd MGET(m, M_DONTWAIT, MT_DATA);
770 1.1 cgd if (m == 0) {
771 1.1 cgd m_freem(top);
772 1.13 mycroft return 0;
773 1.1 cgd }
774 1.1 cgd m->m_len = MLEN;
775 1.1 cgd }
776 1.1 cgd len = min(totlen, epkt - cp);
777 1.1 cgd if (len >= MINCLSIZE) {
778 1.1 cgd MCLGET(m, M_DONTWAIT);
779 1.1 cgd if (m->m_flags & M_EXT)
780 1.1 cgd m->m_len = len = min(len, MCLBYTES);
781 1.1 cgd else
782 1.1 cgd len = m->m_len;
783 1.1 cgd } else {
784 1.1 cgd /*
785 1.1 cgd * Place initial small packet/header at end of mbuf.
786 1.1 cgd */
787 1.1 cgd if (len < m->m_len) {
788 1.1 cgd if (top == 0 && len + max_linkhdr <= m->m_len)
789 1.1 cgd m->m_data += max_linkhdr;
790 1.1 cgd m->m_len = len;
791 1.1 cgd } else
792 1.1 cgd len = m->m_len;
793 1.1 cgd }
794 1.1 cgd bcopy(cp, mtod(m, caddr_t), (unsigned)len);
795 1.1 cgd cp += len;
796 1.1 cgd *mp = m;
797 1.1 cgd mp = &m->m_next;
798 1.1 cgd totlen -= len;
799 1.1 cgd if (cp == epkt)
800 1.13 mycroft cp = buf;
801 1.1 cgd }
802 1.13 mycroft
803 1.13 mycroft return top;
804 1.1 cgd }
805 1.1 cgd
806 1.1 cgd /*
807 1.1 cgd * Process an ioctl request.
808 1.1 cgd */
809 1.8 mycroft int
810 1.1 cgd leioctl(ifp, cmd, data)
811 1.1 cgd register struct ifnet *ifp;
812 1.1 cgd int cmd;
813 1.1 cgd caddr_t data;
814 1.1 cgd {
815 1.5 mycroft struct le_softc *sc = &le_softc[ifp->if_unit];
816 1.13 mycroft struct ifaddr *ifa = (struct ifaddr *)data;
817 1.13 mycroft struct ifreq *ifr = (struct ifreq *)data;
818 1.13 mycroft int s, error = 0;
819 1.13 mycroft
820 1.13 mycroft s = splimp();
821 1.1 cgd
822 1.1 cgd switch (cmd) {
823 1.1 cgd
824 1.1 cgd case SIOCSIFADDR:
825 1.1 cgd ifp->if_flags |= IFF_UP;
826 1.13 mycroft
827 1.1 cgd switch (ifa->ifa_addr->sa_family) {
828 1.1 cgd #ifdef INET
829 1.1 cgd case AF_INET:
830 1.13 mycroft leinit(sc); /* before arpwhohas */
831 1.13 mycroft /*
832 1.13 mycroft * See if another station has *our* IP address.
833 1.13 mycroft * i.e.: There is an address conflict! If a
834 1.13 mycroft * conflict exists, a message is sent to the
835 1.13 mycroft * console.
836 1.13 mycroft */
837 1.13 mycroft sc->sc_arpcom.ac_ipaddr = IA_SIN(ifa)->sin_addr;
838 1.13 mycroft arpwhohas(&sc->sc_arpcom, &IA_SIN(ifa)->sin_addr);
839 1.1 cgd break;
840 1.1 cgd #endif
841 1.1 cgd #ifdef NS
842 1.13 mycroft /* XXX - This code is probably wrong. */
843 1.1 cgd case AF_NS:
844 1.1 cgd {
845 1.13 mycroft register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
846 1.1 cgd
847 1.1 cgd if (ns_nullhost(*ina))
848 1.13 mycroft ina->x_host =
849 1.13 mycroft *(union ns_host *)(sc->sc_arpcom.ac_enaddr);
850 1.13 mycroft else
851 1.13 mycroft bcopy(ina->x_host.c_host,
852 1.13 mycroft sc->sc_arpcom.ac_enaddr,
853 1.13 mycroft sizeof(sc->sc_arpcom.ac_enaddr));
854 1.13 mycroft /* Set new address. */
855 1.13 mycroft leinit(sc);
856 1.1 cgd break;
857 1.1 cgd }
858 1.1 cgd #endif
859 1.1 cgd default:
860 1.13 mycroft leinit(sc);
861 1.1 cgd break;
862 1.1 cgd }
863 1.1 cgd break;
864 1.1 cgd
865 1.1 cgd case SIOCSIFFLAGS:
866 1.13 mycroft /*
867 1.13 mycroft * If interface is marked down and it is running, then stop it
868 1.13 mycroft */
869 1.1 cgd if ((ifp->if_flags & IFF_UP) == 0 &&
870 1.13 mycroft (ifp->if_flags & IFF_RUNNING) != 0) {
871 1.13 mycroft /*
872 1.13 mycroft * If interface is marked down and it is running, then
873 1.13 mycroft * stop it.
874 1.13 mycroft */
875 1.13 mycroft lestop(sc);
876 1.6 mycroft ifp->if_flags &= ~IFF_RUNNING;
877 1.13 mycroft } else if ((ifp->if_flags & IFF_UP) != 0 &&
878 1.13 mycroft (ifp->if_flags & IFF_RUNNING) == 0) {
879 1.13 mycroft /*
880 1.13 mycroft * If interface is marked up and it is stopped, then
881 1.13 mycroft * start it.
882 1.13 mycroft */
883 1.13 mycroft leinit(sc);
884 1.13 mycroft } else {
885 1.13 mycroft /*
886 1.13 mycroft * Reset the interface to pick up changes in any other
887 1.13 mycroft * flags that affect hardware registers.
888 1.13 mycroft */
889 1.13 mycroft /*lestop(sc);*/
890 1.13 mycroft leinit(sc);
891 1.1 cgd }
892 1.13 mycroft #ifdef LEDEBUG
893 1.13 mycroft if (ifp->if_flags & IFF_DEBUG)
894 1.13 mycroft sc->sc_debug = 1;
895 1.13 mycroft else
896 1.13 mycroft sc->sc_debug = 0;
897 1.13 mycroft #endif
898 1.1 cgd break;
899 1.1 cgd
900 1.5 mycroft case SIOCADDMULTI:
901 1.13 mycroft case SIOCDELMULTI:
902 1.13 mycroft error = (cmd == SIOCADDMULTI) ?
903 1.13 mycroft ether_addmulti(ifr, &sc->sc_arpcom):
904 1.13 mycroft ether_delmulti(ifr, &sc->sc_arpcom);
905 1.5 mycroft
906 1.5 mycroft if (error == ENETRESET) {
907 1.5 mycroft /*
908 1.13 mycroft * Multicast list has changed; set the hardware filter
909 1.13 mycroft * accordingly.
910 1.5 mycroft */
911 1.13 mycroft leinit(sc);
912 1.5 mycroft error = 0;
913 1.5 mycroft }
914 1.5 mycroft break;
915 1.5 mycroft
916 1.1 cgd default:
917 1.1 cgd error = EINVAL;
918 1.1 cgd }
919 1.13 mycroft (void) splx(s);
920 1.13 mycroft return error;
921 1.1 cgd }
922 1.1 cgd
923 1.13 mycroft #ifdef LEDEBUG
924 1.8 mycroft void
925 1.13 mycroft recv_print(sc, no)
926 1.13 mycroft struct le_softc *sc;
927 1.13 mycroft int no;
928 1.13 mycroft {
929 1.13 mycroft struct mds *rmd;
930 1.13 mycroft int i, printed = 0;
931 1.13 mycroft u_short len;
932 1.13 mycroft
933 1.13 mycroft rmd = &sc->sc_rd[no];
934 1.13 mycroft len = rmd->mcnt;
935 1.13 mycroft printf("%s: receive buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,
936 1.13 mycroft len);
937 1.13 mycroft printf("%s: status %x\n", sc->sc_dev.dv_xname, lerdcsr(sc, 0));
938 1.13 mycroft for (i = 0; i < len; i++) {
939 1.13 mycroft if (!printed) {
940 1.13 mycroft printed = 1;
941 1.13 mycroft printf("%s: data: ", sc->sc_dev.dv_xname);
942 1.13 mycroft }
943 1.13 mycroft printf("%x ", *(sc->sc_rbuf + (BUFSIZE*no) + i));
944 1.13 mycroft }
945 1.13 mycroft if (printed)
946 1.13 mycroft printf("\n");
947 1.13 mycroft }
948 1.13 mycroft
949 1.13 mycroft void
950 1.13 mycroft xmit_print(sc, no)
951 1.13 mycroft struct le_softc *sc;
952 1.13 mycroft int no;
953 1.13 mycroft {
954 1.13 mycroft struct mds *rmd;
955 1.13 mycroft int i, printed=0;
956 1.13 mycroft u_short len;
957 1.13 mycroft
958 1.13 mycroft rmd = &sc->sc_td[no];
959 1.13 mycroft len = -rmd->bcnt;
960 1.13 mycroft printf("%s: transmit buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,
961 1.13 mycroft len);
962 1.13 mycroft printf("%s: status %x\n", sc->sc_dev.dv_xname, lerdcsr(sc, 0));
963 1.13 mycroft printf("%s: addr %x, flags %x, bcnt %x, mcnt %x\n",
964 1.13 mycroft sc->sc_dev.dv_xname, rmd->addr, rmd->flags, rmd->bcnt, rmd->mcnt);
965 1.13 mycroft for (i = 0; i < len; i++) {
966 1.13 mycroft if (!printed) {
967 1.13 mycroft printed = 1;
968 1.13 mycroft printf("%s: data: ", sc->sc_dev.dv_xname);
969 1.13 mycroft }
970 1.13 mycroft printf("%x ", *(sc->sc_tbuf + (BUFSIZE*no) + i));
971 1.13 mycroft }
972 1.13 mycroft if (printed)
973 1.13 mycroft printf("\n");
974 1.13 mycroft }
975 1.13 mycroft #endif /* LEDEBUG */
976 1.13 mycroft
977 1.13 mycroft /*
978 1.13 mycroft * Set up the logical address filter.
979 1.13 mycroft */
980 1.13 mycroft void
981 1.13 mycroft lesetladrf(ac, af)
982 1.13 mycroft struct arpcom *ac;
983 1.13 mycroft u_long *af;
984 1.1 cgd {
985 1.13 mycroft struct ifnet *ifp = &ac->ac_if;
986 1.13 mycroft struct ether_multi *enm;
987 1.13 mycroft register u_char *cp, c;
988 1.13 mycroft register u_long crc;
989 1.13 mycroft register int i, len;
990 1.13 mycroft struct ether_multistep step;
991 1.1 cgd
992 1.1 cgd /*
993 1.13 mycroft * Set up multicast address filter by passing all multicast addresses
994 1.13 mycroft * through a crc generator, and then using the high order 6 bits as an
995 1.13 mycroft * index into the 64 bit logical address filter. The high order bit
996 1.13 mycroft * selects the word, while the rest of the bits select the bit within
997 1.13 mycroft * the word.
998 1.1 cgd */
999 1.1 cgd
1000 1.13 mycroft if (ifp->if_flags & IFF_PROMISC) {
1001 1.13 mycroft ifp->if_flags |= IFF_ALLMULTI;
1002 1.13 mycroft af[0] = af[1] = 0xffffffff;
1003 1.1 cgd return;
1004 1.13 mycroft }
1005 1.1 cgd
1006 1.13 mycroft af[0] = af[1] = 0;
1007 1.13 mycroft ETHER_FIRST_MULTI(step, ac, enm);
1008 1.13 mycroft while (enm != NULL) {
1009 1.13 mycroft if (bcmp(enm->enm_addrlo, enm->enm_addrhi,
1010 1.13 mycroft sizeof(enm->enm_addrlo)) != 0) {
1011 1.13 mycroft /*
1012 1.13 mycroft * We must listen to a range of multicast addresses.
1013 1.13 mycroft * For now, just accept all multicasts, rather than
1014 1.13 mycroft * trying to set only those filter bits needed to match
1015 1.13 mycroft * the range. (At this time, the only use of address
1016 1.13 mycroft * ranges is for IP multicast routing, for which the
1017 1.13 mycroft * range is big enough to require all bits set.)
1018 1.13 mycroft */
1019 1.13 mycroft ifp->if_flags |= IFF_ALLMULTI;
1020 1.13 mycroft af[0] = af[1] = 0xffffffff;
1021 1.13 mycroft return;
1022 1.13 mycroft }
1023 1.1 cgd
1024 1.13 mycroft cp = enm->enm_addrlo;
1025 1.13 mycroft crc = 0xffffffff;
1026 1.13 mycroft for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
1027 1.13 mycroft c = *cp++;
1028 1.13 mycroft for (i = 8; --i >= 0;) {
1029 1.13 mycroft if ((crc & 0x01) ^ (c & 0x01)) {
1030 1.13 mycroft crc >>= 1;
1031 1.13 mycroft crc ^= 0x6db88320 | 0x80000000;
1032 1.13 mycroft } else
1033 1.13 mycroft crc >>= 1;
1034 1.13 mycroft c >>= 1;
1035 1.13 mycroft }
1036 1.13 mycroft }
1037 1.13 mycroft /* Just want the 6 most significant bits. */
1038 1.13 mycroft crc >>= 26;
1039 1.1 cgd
1040 1.13 mycroft /* Turn on the corresponding bit in the filter. */
1041 1.13 mycroft af[crc >> 5] |= 1 << (crc & 0x1f);
1042 1.1 cgd
1043 1.13 mycroft ETHER_NEXT_MULTI(step, enm);
1044 1.13 mycroft }
1045 1.13 mycroft ifp->if_flags &= ~IFF_ALLMULTI;
1046 1.1 cgd }
1047