am7990.c revision 1.19 1 1.19 thorpej /* $NetBSD: am7990.c,v 1.19 1996/05/07 01:38:35 thorpej Exp $ */
2 1.1 cgd
3 1.1 cgd /*-
4 1.1 cgd * Copyright (c) 1995 Charles M. Hannum. All rights reserved.
5 1.1 cgd * Copyright (c) 1992, 1993
6 1.1 cgd * The Regents of the University of California. All rights reserved.
7 1.1 cgd *
8 1.1 cgd * This code is derived from software contributed to Berkeley by
9 1.1 cgd * Ralph Campbell and Rick Macklem.
10 1.1 cgd *
11 1.1 cgd * Redistribution and use in source and binary forms, with or without
12 1.1 cgd * modification, are permitted provided that the following conditions
13 1.1 cgd * are met:
14 1.1 cgd * 1. Redistributions of source code must retain the above copyright
15 1.1 cgd * notice, this list of conditions and the following disclaimer.
16 1.1 cgd * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 cgd * notice, this list of conditions and the following disclaimer in the
18 1.1 cgd * documentation and/or other materials provided with the distribution.
19 1.1 cgd * 3. All advertising materials mentioning features or use of this software
20 1.1 cgd * must display the following acknowledgement:
21 1.1 cgd * This product includes software developed by the University of
22 1.1 cgd * California, Berkeley and its contributors.
23 1.1 cgd * 4. Neither the name of the University nor the names of its contributors
24 1.1 cgd * may be used to endorse or promote products derived from this software
25 1.1 cgd * without specific prior written permission.
26 1.1 cgd *
27 1.1 cgd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
28 1.1 cgd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
29 1.1 cgd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
30 1.1 cgd * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
31 1.1 cgd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
32 1.1 cgd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 1.1 cgd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
34 1.1 cgd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
35 1.1 cgd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
36 1.1 cgd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37 1.1 cgd * SUCH DAMAGE.
38 1.1 cgd *
39 1.1 cgd * @(#)if_le.c 8.2 (Berkeley) 11/16/93
40 1.1 cgd */
41 1.1 cgd
42 1.19 thorpej #include "bpfilter.h"
43 1.19 thorpej
44 1.19 thorpej #include <sys/param.h>
45 1.19 thorpej #include <sys/systm.h>
46 1.19 thorpej #include <sys/mbuf.h>
47 1.19 thorpej #include <sys/syslog.h>
48 1.19 thorpej #include <sys/socket.h>
49 1.19 thorpej #include <sys/device.h>
50 1.19 thorpej #include <sys/malloc.h>
51 1.1 cgd #include <sys/ioctl.h>
52 1.1 cgd #include <sys/errno.h>
53 1.1 cgd
54 1.19 thorpej #include <net/if.h>
55 1.19 thorpej
56 1.1 cgd #ifdef INET
57 1.19 thorpej #include <netinet/in.h>
58 1.19 thorpej #include <netinet/if_ether.h>
59 1.1 cgd #include <netinet/in_systm.h>
60 1.1 cgd #include <netinet/in_var.h>
61 1.1 cgd #include <netinet/ip.h>
62 1.1 cgd #endif
63 1.1 cgd
64 1.1 cgd #ifdef NS
65 1.1 cgd #include <netns/ns.h>
66 1.1 cgd #include <netns/ns_if.h>
67 1.1 cgd #endif
68 1.1 cgd
69 1.1 cgd #if defined(CCITT) && defined(LLC)
70 1.1 cgd #include <sys/socketvar.h>
71 1.1 cgd #include <netccitt/x25.h>
72 1.11 christos #include <netccitt/pk.h>
73 1.11 christos #include <netccitt/pk_var.h>
74 1.11 christos #include <netccitt/pk_extern.h>
75 1.1 cgd #endif
76 1.1 cgd
77 1.1 cgd #if NBPFILTER > 0
78 1.1 cgd #include <net/bpf.h>
79 1.1 cgd #include <net/bpfdesc.h>
80 1.1 cgd #endif
81 1.1 cgd
82 1.19 thorpej #include <dev/ic/am7990reg.h>
83 1.19 thorpej #include <dev/ic/am7990var.h>
84 1.19 thorpej
85 1.1 cgd #ifdef LEDEBUG
86 1.19 thorpej void am7990_recv_print __P((struct am7990_softc *, int));
87 1.19 thorpej void am7990_xmit_print __P((struct am7990_softc *, int));
88 1.1 cgd #endif
89 1.1 cgd
90 1.19 thorpej integrate void am7990_rint __P((struct am7990_softc *));
91 1.19 thorpej integrate void am7990_tint __P((struct am7990_softc *));
92 1.19 thorpej
93 1.19 thorpej integrate int am7990_put __P((struct am7990_softc *, int, struct mbuf *));
94 1.19 thorpej integrate struct mbuf *am7990_get __P((struct am7990_softc *, int, int));
95 1.19 thorpej integrate void am7990_read __P((struct am7990_softc *, int, int));
96 1.19 thorpej
97 1.19 thorpej hide void am7990_shutdown __P((void *));
98 1.19 thorpej
99 1.7 mycroft #define ifp (&sc->sc_arpcom.ac_if)
100 1.7 mycroft
101 1.19 thorpej #if 0 /* XXX what do we do about this?! --thorpej */
102 1.19 thorpej static inline u_int16_t ether_cmp __P((void *, void *));
103 1.19 thorpej
104 1.19 thorpej /*
105 1.19 thorpej * Compare two Ether/802 addresses for equality, inlined and
106 1.19 thorpej * unrolled for speed. I'd love to have an inline assembler
107 1.19 thorpej * version of this... XXX: Who wanted that? mycroft?
108 1.19 thorpej * I wrote one, but the following is just as efficient.
109 1.19 thorpej * This expands to 10 short m68k instructions! -gwr
110 1.19 thorpej * Note: use this like bcmp()
111 1.19 thorpej */
112 1.19 thorpej static inline u_short
113 1.19 thorpej ether_cmp(one, two)
114 1.19 thorpej void *one, *two;
115 1.19 thorpej {
116 1.19 thorpej register u_int16_t *a = (u_short *) one;
117 1.19 thorpej register u_int16_t *b = (u_short *) two;
118 1.19 thorpej register u_int16_t diff;
119 1.19 thorpej
120 1.19 thorpej diff = *a++ - *b++;
121 1.19 thorpej diff |= *a++ - *b++;
122 1.19 thorpej diff |= *a++ - *b++;
123 1.19 thorpej
124 1.19 thorpej return (diff);
125 1.19 thorpej }
126 1.19 thorpej
127 1.19 thorpej #define ETHER_CMP ether_cmp
128 1.19 thorpej #endif /* XXX */
129 1.19 thorpej
130 1.13 gwr #ifndef ETHER_CMP
131 1.13 gwr #define ETHER_CMP(a, b) bcmp((a), (b), ETHER_ADDR_LEN)
132 1.13 gwr #endif
133 1.13 gwr
134 1.19 thorpej /*
135 1.19 thorpej * am7990 configuration driver. Attachments are provided by
136 1.19 thorpej * machine-dependent driver front-ends.
137 1.19 thorpej */
138 1.19 thorpej struct cfdriver le_cd = {
139 1.19 thorpej NULL, "le", DV_IFNET
140 1.19 thorpej };
141 1.19 thorpej
142 1.1 cgd void
143 1.19 thorpej am7990_config(sc)
144 1.19 thorpej struct am7990_softc *sc;
145 1.1 cgd {
146 1.1 cgd int mem;
147 1.1 cgd
148 1.1 cgd /* Make sure the chip is stopped. */
149 1.19 thorpej am7990_stop(sc);
150 1.1 cgd
151 1.1 cgd /* Initialize ifnet structure. */
152 1.19 thorpej bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
153 1.19 thorpej ifp->if_softc = sc;
154 1.19 thorpej ifp->if_start = am7990_start;
155 1.19 thorpej ifp->if_ioctl = am7990_ioctl;
156 1.19 thorpej ifp->if_watchdog = am7990_watchdog;
157 1.1 cgd ifp->if_flags =
158 1.1 cgd IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
159 1.5 mycroft #ifdef LANCE_REVC_BUG
160 1.5 mycroft ifp->if_flags &= ~IFF_MULTICAST;
161 1.5 mycroft #endif
162 1.1 cgd
163 1.1 cgd /* Attach the interface. */
164 1.1 cgd if_attach(ifp);
165 1.1 cgd ether_ifattach(ifp);
166 1.1 cgd
167 1.1 cgd #if NBPFILTER > 0
168 1.1 cgd bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
169 1.1 cgd #endif
170 1.1 cgd
171 1.1 cgd switch (sc->sc_memsize) {
172 1.1 cgd case 8192:
173 1.1 cgd sc->sc_nrbuf = 4;
174 1.1 cgd sc->sc_ntbuf = 1;
175 1.1 cgd break;
176 1.1 cgd case 16384:
177 1.1 cgd sc->sc_nrbuf = 8;
178 1.1 cgd sc->sc_ntbuf = 2;
179 1.1 cgd break;
180 1.1 cgd case 32768:
181 1.1 cgd sc->sc_nrbuf = 16;
182 1.1 cgd sc->sc_ntbuf = 4;
183 1.1 cgd break;
184 1.1 cgd case 65536:
185 1.1 cgd sc->sc_nrbuf = 32;
186 1.1 cgd sc->sc_ntbuf = 8;
187 1.1 cgd break;
188 1.1 cgd default:
189 1.19 thorpej panic("am7990_config: weird memory size");
190 1.1 cgd }
191 1.1 cgd
192 1.13 gwr printf(": address %s\n", ether_sprintf(sc->sc_arpcom.ac_enaddr));
193 1.13 gwr printf("%s: %d receive buffers, %d transmit buffers\n",
194 1.5 mycroft sc->sc_dev.dv_xname, sc->sc_nrbuf, sc->sc_ntbuf);
195 1.1 cgd
196 1.19 thorpej sc->sc_sh = shutdownhook_establish(am7990_shutdown, sc);
197 1.19 thorpej if (sc->sc_sh == NULL)
198 1.19 thorpej panic("am7990_config: can't establish shutdownhook");
199 1.19 thorpej
200 1.1 cgd mem = 0;
201 1.1 cgd sc->sc_initaddr = mem;
202 1.1 cgd mem += sizeof(struct leinit);
203 1.1 cgd sc->sc_rmdaddr = mem;
204 1.1 cgd mem += sizeof(struct lermd) * sc->sc_nrbuf;
205 1.1 cgd sc->sc_tmdaddr = mem;
206 1.1 cgd mem += sizeof(struct letmd) * sc->sc_ntbuf;
207 1.1 cgd sc->sc_rbufaddr = mem;
208 1.1 cgd mem += LEBLEN * sc->sc_nrbuf;
209 1.1 cgd sc->sc_tbufaddr = mem;
210 1.1 cgd mem += LEBLEN * sc->sc_ntbuf;
211 1.1 cgd #ifdef notyet
212 1.1 cgd if (mem > ...)
213 1.1 cgd panic(...);
214 1.1 cgd #endif
215 1.1 cgd }
216 1.1 cgd
217 1.1 cgd void
218 1.19 thorpej am7990_reset(sc)
219 1.19 thorpej struct am7990_softc *sc;
220 1.1 cgd {
221 1.2 mycroft int s;
222 1.1 cgd
223 1.2 mycroft s = splimp();
224 1.19 thorpej am7990_init(sc);
225 1.2 mycroft splx(s);
226 1.1 cgd }
227 1.1 cgd
228 1.1 cgd /*
229 1.1 cgd * Set up the initialization block and the descriptor rings.
230 1.1 cgd */
231 1.1 cgd void
232 1.19 thorpej am7990_meminit(sc)
233 1.19 thorpej register struct am7990_softc *sc;
234 1.1 cgd {
235 1.1 cgd u_long a;
236 1.1 cgd int bix;
237 1.1 cgd struct leinit init;
238 1.1 cgd struct lermd rmd;
239 1.1 cgd struct letmd tmd;
240 1.1 cgd
241 1.1 cgd #if NBPFILTER > 0
242 1.1 cgd if (ifp->if_flags & IFF_PROMISC)
243 1.1 cgd init.init_mode = LE_MODE_NORMAL | LE_MODE_PROM;
244 1.1 cgd else
245 1.1 cgd #endif
246 1.1 cgd init.init_mode = LE_MODE_NORMAL;
247 1.1 cgd init.init_padr[0] =
248 1.1 cgd (sc->sc_arpcom.ac_enaddr[1] << 8) | sc->sc_arpcom.ac_enaddr[0];
249 1.1 cgd init.init_padr[1] =
250 1.1 cgd (sc->sc_arpcom.ac_enaddr[3] << 8) | sc->sc_arpcom.ac_enaddr[2];
251 1.1 cgd init.init_padr[2] =
252 1.1 cgd (sc->sc_arpcom.ac_enaddr[5] << 8) | sc->sc_arpcom.ac_enaddr[4];
253 1.19 thorpej am7990_setladrf(&sc->sc_arpcom, init.init_ladrf);
254 1.1 cgd
255 1.1 cgd sc->sc_last_rd = 0;
256 1.1 cgd sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0;
257 1.1 cgd
258 1.1 cgd a = sc->sc_addr + LE_RMDADDR(sc, 0);
259 1.1 cgd init.init_rdra = a;
260 1.1 cgd init.init_rlen = (a >> 16) | ((ffs(sc->sc_nrbuf) - 1) << 13);
261 1.1 cgd
262 1.1 cgd a = sc->sc_addr + LE_TMDADDR(sc, 0);
263 1.1 cgd init.init_tdra = a;
264 1.1 cgd init.init_tlen = (a >> 16) | ((ffs(sc->sc_ntbuf) - 1) << 13);
265 1.1 cgd
266 1.1 cgd (*sc->sc_copytodesc)(sc, &init, LE_INITADDR(sc), sizeof(init));
267 1.1 cgd
268 1.1 cgd /*
269 1.1 cgd * Set up receive ring descriptors.
270 1.1 cgd */
271 1.1 cgd for (bix = 0; bix < sc->sc_nrbuf; bix++) {
272 1.1 cgd a = sc->sc_addr + LE_RBUFADDR(sc, bix);
273 1.1 cgd rmd.rmd0 = a;
274 1.1 cgd rmd.rmd1_hadr = a >> 16;
275 1.1 cgd rmd.rmd1_bits = LE_R1_OWN;
276 1.1 cgd rmd.rmd2 = -LEBLEN | LE_XMD2_ONES;
277 1.1 cgd rmd.rmd3 = 0;
278 1.1 cgd (*sc->sc_copytodesc)(sc, &rmd, LE_RMDADDR(sc, bix),
279 1.1 cgd sizeof(rmd));
280 1.1 cgd }
281 1.1 cgd
282 1.1 cgd /*
283 1.1 cgd * Set up transmit ring descriptors.
284 1.1 cgd */
285 1.1 cgd for (bix = 0; bix < sc->sc_ntbuf; bix++) {
286 1.1 cgd a = sc->sc_addr + LE_TBUFADDR(sc, bix);
287 1.1 cgd tmd.tmd0 = a;
288 1.1 cgd tmd.tmd1_hadr = a >> 16;
289 1.1 cgd tmd.tmd1_bits = 0;
290 1.1 cgd tmd.tmd2 = 0 | LE_XMD2_ONES;
291 1.1 cgd tmd.tmd3 = 0;
292 1.1 cgd (*sc->sc_copytodesc)(sc, &tmd, LE_TMDADDR(sc, bix),
293 1.1 cgd sizeof(tmd));
294 1.1 cgd }
295 1.1 cgd }
296 1.1 cgd
297 1.1 cgd void
298 1.19 thorpej am7990_stop(sc)
299 1.19 thorpej struct am7990_softc *sc;
300 1.1 cgd {
301 1.1 cgd
302 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP);
303 1.1 cgd }
304 1.1 cgd
305 1.1 cgd /*
306 1.1 cgd * Initialization of interface; set up initialization block
307 1.1 cgd * and transmit/receive descriptor rings.
308 1.1 cgd */
309 1.1 cgd void
310 1.19 thorpej am7990_init(sc)
311 1.19 thorpej register struct am7990_softc *sc;
312 1.1 cgd {
313 1.1 cgd register int timo;
314 1.1 cgd u_long a;
315 1.1 cgd
316 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP);
317 1.19 thorpej DELAY(100);
318 1.1 cgd
319 1.1 cgd /* Set the correct byte swapping mode, etc. */
320 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR3, sc->sc_conf3);
321 1.1 cgd
322 1.1 cgd /* Set up LANCE init block. */
323 1.19 thorpej am7990_meminit(sc);
324 1.1 cgd
325 1.1 cgd /* Give LANCE the physical address of its init block. */
326 1.1 cgd a = sc->sc_addr + LE_INITADDR(sc);
327 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR1, a);
328 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR2, a >> 16);
329 1.1 cgd
330 1.1 cgd /* Try to initialize the LANCE. */
331 1.19 thorpej DELAY(100);
332 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INIT);
333 1.1 cgd
334 1.1 cgd /* Wait for initialization to finish. */
335 1.1 cgd for (timo = 100000; timo; timo--)
336 1.19 thorpej if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON)
337 1.1 cgd break;
338 1.1 cgd
339 1.19 thorpej if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) {
340 1.1 cgd /* Start the LANCE. */
341 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_STRT |
342 1.19 thorpej LE_C0_IDON);
343 1.1 cgd ifp->if_flags |= IFF_RUNNING;
344 1.1 cgd ifp->if_flags &= ~IFF_OACTIVE;
345 1.1 cgd ifp->if_timer = 0;
346 1.19 thorpej am7990_start(ifp);
347 1.1 cgd } else
348 1.1 cgd printf("%s: card failed to initialize\n", sc->sc_dev.dv_xname);
349 1.19 thorpej if (sc->sc_hwinit)
350 1.19 thorpej (*sc->sc_hwinit)(sc);
351 1.1 cgd }
352 1.1 cgd
353 1.1 cgd /*
354 1.1 cgd * Routine to copy from mbuf chain to transmit buffer in
355 1.1 cgd * network buffer memory.
356 1.1 cgd */
357 1.1 cgd integrate int
358 1.19 thorpej am7990_put(sc, boff, m)
359 1.19 thorpej struct am7990_softc *sc;
360 1.1 cgd int boff;
361 1.1 cgd register struct mbuf *m;
362 1.1 cgd {
363 1.1 cgd register struct mbuf *n;
364 1.1 cgd register int len, tlen = 0;
365 1.1 cgd
366 1.1 cgd for (; m; m = n) {
367 1.1 cgd len = m->m_len;
368 1.1 cgd if (len == 0) {
369 1.1 cgd MFREE(m, n);
370 1.1 cgd continue;
371 1.1 cgd }
372 1.1 cgd (*sc->sc_copytobuf)(sc, mtod(m, caddr_t), boff, len);
373 1.1 cgd boff += len;
374 1.1 cgd tlen += len;
375 1.1 cgd MFREE(m, n);
376 1.1 cgd }
377 1.1 cgd if (tlen < LEMINSIZE) {
378 1.1 cgd (*sc->sc_zerobuf)(sc, boff, LEMINSIZE - tlen);
379 1.1 cgd tlen = LEMINSIZE;
380 1.1 cgd }
381 1.1 cgd return (tlen);
382 1.1 cgd }
383 1.1 cgd
384 1.1 cgd /*
385 1.1 cgd * Pull data off an interface.
386 1.1 cgd * Len is length of data, with local net header stripped.
387 1.1 cgd * We copy the data into mbufs. When full cluster sized units are present
388 1.1 cgd * we copy into clusters.
389 1.1 cgd */
390 1.1 cgd integrate struct mbuf *
391 1.19 thorpej am7990_get(sc, boff, totlen)
392 1.19 thorpej struct am7990_softc *sc;
393 1.1 cgd int boff, totlen;
394 1.1 cgd {
395 1.1 cgd register struct mbuf *m;
396 1.1 cgd struct mbuf *top, **mp;
397 1.1 cgd int len, pad;
398 1.1 cgd
399 1.1 cgd MGETHDR(m, M_DONTWAIT, MT_DATA);
400 1.1 cgd if (m == 0)
401 1.1 cgd return (0);
402 1.7 mycroft m->m_pkthdr.rcvif = ifp;
403 1.1 cgd m->m_pkthdr.len = totlen;
404 1.1 cgd pad = ALIGN(sizeof(struct ether_header)) - sizeof(struct ether_header);
405 1.1 cgd m->m_data += pad;
406 1.1 cgd len = MHLEN - pad;
407 1.1 cgd top = 0;
408 1.1 cgd mp = ⊤
409 1.1 cgd
410 1.1 cgd while (totlen > 0) {
411 1.1 cgd if (top) {
412 1.1 cgd MGET(m, M_DONTWAIT, MT_DATA);
413 1.1 cgd if (m == 0) {
414 1.1 cgd m_freem(top);
415 1.1 cgd return 0;
416 1.1 cgd }
417 1.1 cgd len = MLEN;
418 1.1 cgd }
419 1.1 cgd if (top && totlen >= MINCLSIZE) {
420 1.1 cgd MCLGET(m, M_DONTWAIT);
421 1.1 cgd if (m->m_flags & M_EXT)
422 1.1 cgd len = MCLBYTES;
423 1.1 cgd }
424 1.1 cgd m->m_len = len = min(totlen, len);
425 1.1 cgd (*sc->sc_copyfrombuf)(sc, mtod(m, caddr_t), boff, len);
426 1.1 cgd boff += len;
427 1.1 cgd totlen -= len;
428 1.1 cgd *mp = m;
429 1.1 cgd mp = &m->m_next;
430 1.1 cgd }
431 1.1 cgd
432 1.1 cgd return (top);
433 1.1 cgd }
434 1.1 cgd
435 1.1 cgd /*
436 1.1 cgd * Pass a packet to the higher levels.
437 1.1 cgd */
438 1.1 cgd integrate void
439 1.19 thorpej am7990_read(sc, boff, len)
440 1.19 thorpej register struct am7990_softc *sc;
441 1.1 cgd int boff, len;
442 1.1 cgd {
443 1.1 cgd struct mbuf *m;
444 1.1 cgd struct ether_header *eh;
445 1.1 cgd
446 1.2 mycroft if (len <= sizeof(struct ether_header) ||
447 1.3 mycroft len > ETHERMTU + sizeof(struct ether_header)) {
448 1.6 mycroft #ifdef LEDEBUG
449 1.2 mycroft printf("%s: invalid packet size %d; dropping\n",
450 1.2 mycroft sc->sc_dev.dv_xname, len);
451 1.6 mycroft #endif
452 1.2 mycroft ifp->if_ierrors++;
453 1.1 cgd return;
454 1.2 mycroft }
455 1.1 cgd
456 1.1 cgd /* Pull packet off interface. */
457 1.19 thorpej m = am7990_get(sc, boff, len);
458 1.2 mycroft if (m == 0) {
459 1.2 mycroft ifp->if_ierrors++;
460 1.1 cgd return;
461 1.2 mycroft }
462 1.2 mycroft
463 1.2 mycroft ifp->if_ipackets++;
464 1.1 cgd
465 1.1 cgd /* We assume that the header fit entirely in one mbuf. */
466 1.1 cgd eh = mtod(m, struct ether_header *);
467 1.1 cgd
468 1.1 cgd #if NBPFILTER > 0
469 1.1 cgd /*
470 1.1 cgd * Check if there's a BPF listener on this interface.
471 1.1 cgd * If so, hand off the raw packet to BPF.
472 1.1 cgd */
473 1.1 cgd if (ifp->if_bpf) {
474 1.1 cgd bpf_mtap(ifp->if_bpf, m);
475 1.1 cgd
476 1.5 mycroft #ifndef LANCE_REVC_BUG
477 1.1 cgd /*
478 1.1 cgd * Note that the interface cannot be in promiscuous mode if
479 1.1 cgd * there are no BPF listeners. And if we are in promiscuous
480 1.1 cgd * mode, we have to check if this packet is really ours.
481 1.1 cgd */
482 1.1 cgd if ((ifp->if_flags & IFF_PROMISC) != 0 &&
483 1.1 cgd (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */
484 1.14 mycroft ETHER_CMP(eh->ether_dhost, sc->sc_arpcom.ac_enaddr)) {
485 1.1 cgd m_freem(m);
486 1.1 cgd return;
487 1.1 cgd }
488 1.5 mycroft #endif
489 1.5 mycroft }
490 1.5 mycroft #endif
491 1.5 mycroft
492 1.5 mycroft #ifdef LANCE_REVC_BUG
493 1.13 gwr /*
494 1.13 gwr * The old LANCE (Rev. C) chips have a bug which causes
495 1.13 gwr * garbage to be inserted in front of the received packet.
496 1.13 gwr * The work-around is to ignore packets with an invalid
497 1.13 gwr * destination address (garbage will usually not match).
498 1.13 gwr * Of course, this precludes multicast support...
499 1.13 gwr */
500 1.13 gwr if (ETHER_CMP(eh->ether_dhost, sc->sc_arpcom.ac_enaddr) &&
501 1.14 mycroft ETHER_CMP(eh->ether_dhost, etherbroadcastaddr)) {
502 1.5 mycroft m_freem(m);
503 1.5 mycroft return;
504 1.1 cgd }
505 1.1 cgd #endif
506 1.1 cgd
507 1.1 cgd /* Pass the packet up, with the ether header sort-of removed. */
508 1.1 cgd m_adj(m, sizeof(struct ether_header));
509 1.1 cgd ether_input(ifp, eh, m);
510 1.1 cgd }
511 1.1 cgd
512 1.1 cgd integrate void
513 1.19 thorpej am7990_rint(sc)
514 1.19 thorpej struct am7990_softc *sc;
515 1.1 cgd {
516 1.1 cgd register int bix;
517 1.1 cgd int rp;
518 1.1 cgd struct lermd rmd;
519 1.1 cgd
520 1.1 cgd bix = sc->sc_last_rd;
521 1.1 cgd
522 1.1 cgd /* Process all buffers with valid data. */
523 1.1 cgd for (;;) {
524 1.1 cgd rp = LE_RMDADDR(sc, bix);
525 1.1 cgd (*sc->sc_copyfromdesc)(sc, &rmd, rp, sizeof(rmd));
526 1.1 cgd
527 1.1 cgd if (rmd.rmd1_bits & LE_R1_OWN)
528 1.1 cgd break;
529 1.1 cgd
530 1.1 cgd if (rmd.rmd1_bits & LE_R1_ERR) {
531 1.1 cgd if (rmd.rmd1_bits & LE_R1_ENP) {
532 1.6 mycroft #ifdef LEDEBUG
533 1.1 cgd if ((rmd.rmd1_bits & LE_R1_OFLO) == 0) {
534 1.1 cgd if (rmd.rmd1_bits & LE_R1_FRAM)
535 1.1 cgd printf("%s: framing error\n",
536 1.1 cgd sc->sc_dev.dv_xname);
537 1.1 cgd if (rmd.rmd1_bits & LE_R1_CRC)
538 1.1 cgd printf("%s: crc mismatch\n",
539 1.1 cgd sc->sc_dev.dv_xname);
540 1.1 cgd }
541 1.6 mycroft #endif
542 1.1 cgd } else {
543 1.1 cgd if (rmd.rmd1_bits & LE_R1_OFLO)
544 1.1 cgd printf("%s: overflow\n",
545 1.1 cgd sc->sc_dev.dv_xname);
546 1.1 cgd }
547 1.1 cgd if (rmd.rmd1_bits & LE_R1_BUFF)
548 1.1 cgd printf("%s: receive buffer error\n",
549 1.1 cgd sc->sc_dev.dv_xname);
550 1.7 mycroft ifp->if_ierrors++;
551 1.12 christos } else if ((rmd.rmd1_bits & (LE_R1_STP | LE_R1_ENP)) !=
552 1.1 cgd (LE_R1_STP | LE_R1_ENP)) {
553 1.1 cgd printf("%s: dropping chained buffer\n",
554 1.1 cgd sc->sc_dev.dv_xname);
555 1.7 mycroft ifp->if_ierrors++;
556 1.1 cgd } else {
557 1.1 cgd #ifdef LEDEBUG
558 1.1 cgd if (sc->sc_debug)
559 1.19 thorpej am7990_recv_print(sc, sc->sc_last_rd);
560 1.1 cgd #endif
561 1.19 thorpej am7990_read(sc, LE_RBUFADDR(sc, bix),
562 1.19 thorpej (int)rmd.rmd3 - 4);
563 1.1 cgd }
564 1.1 cgd
565 1.1 cgd rmd.rmd1_bits = LE_R1_OWN;
566 1.1 cgd rmd.rmd2 = -LEBLEN | LE_XMD2_ONES;
567 1.1 cgd rmd.rmd3 = 0;
568 1.1 cgd (*sc->sc_copytodesc)(sc, &rmd, rp, sizeof(rmd));
569 1.1 cgd
570 1.1 cgd #ifdef LEDEBUG
571 1.1 cgd if (sc->sc_debug)
572 1.16 pk printf("sc->sc_last_rd = %x, rmd: "
573 1.16 pk "ladr %04x, hadr %02x, flags %02x, "
574 1.16 pk "bcnt %04x, mcnt %04x\n",
575 1.16 pk sc->sc_last_rd,
576 1.16 pk rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits,
577 1.16 pk rmd.rmd2, rmd.rmd3);
578 1.1 cgd #endif
579 1.1 cgd
580 1.1 cgd if (++bix == sc->sc_nrbuf)
581 1.1 cgd bix = 0;
582 1.1 cgd }
583 1.1 cgd
584 1.1 cgd sc->sc_last_rd = bix;
585 1.1 cgd }
586 1.1 cgd
587 1.1 cgd integrate void
588 1.19 thorpej am7990_tint(sc)
589 1.19 thorpej register struct am7990_softc *sc;
590 1.1 cgd {
591 1.1 cgd register int bix;
592 1.1 cgd struct letmd tmd;
593 1.9 thorpej
594 1.1 cgd bix = sc->sc_first_td;
595 1.1 cgd
596 1.1 cgd for (;;) {
597 1.1 cgd if (sc->sc_no_td <= 0)
598 1.1 cgd break;
599 1.1 cgd
600 1.1 cgd #ifdef LEDEBUG
601 1.1 cgd if (sc->sc_debug)
602 1.16 pk printf("trans tmd: "
603 1.16 pk "ladr %04x, hadr %02x, flags %02x, "
604 1.16 pk "bcnt %04x, mcnt %04x\n",
605 1.16 pk tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits,
606 1.16 pk tmd.tmd2, tmd.tmd3);
607 1.1 cgd #endif
608 1.1 cgd
609 1.1 cgd (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, bix),
610 1.1 cgd sizeof(tmd));
611 1.1 cgd
612 1.1 cgd if (tmd.tmd1_bits & LE_T1_OWN)
613 1.1 cgd break;
614 1.1 cgd
615 1.1 cgd ifp->if_flags &= ~IFF_OACTIVE;
616 1.1 cgd
617 1.1 cgd if (tmd.tmd1_bits & LE_T1_ERR) {
618 1.1 cgd if (tmd.tmd3 & LE_T3_BUFF)
619 1.19 thorpej printf("%s: transmit buffer error\n",
620 1.19 thorpej sc->sc_dev.dv_xname);
621 1.1 cgd else if (tmd.tmd3 & LE_T3_UFLO)
622 1.1 cgd printf("%s: underflow\n", sc->sc_dev.dv_xname);
623 1.1 cgd if (tmd.tmd3 & (LE_T3_BUFF | LE_T3_UFLO)) {
624 1.19 thorpej am7990_reset(sc);
625 1.1 cgd return;
626 1.1 cgd }
627 1.1 cgd if (tmd.tmd3 & LE_T3_LCAR)
628 1.19 thorpej printf("%s: lost carrier\n",
629 1.19 thorpej sc->sc_dev.dv_xname);
630 1.1 cgd if (tmd.tmd3 & LE_T3_LCOL)
631 1.1 cgd ifp->if_collisions++;
632 1.1 cgd if (tmd.tmd3 & LE_T3_RTRY) {
633 1.1 cgd printf("%s: excessive collisions, tdr %d\n",
634 1.19 thorpej sc->sc_dev.dv_xname,
635 1.19 thorpej tmd.tmd3 & LE_T3_TDR_MASK);
636 1.1 cgd ifp->if_collisions += 16;
637 1.1 cgd }
638 1.1 cgd ifp->if_oerrors++;
639 1.1 cgd } else {
640 1.1 cgd if (tmd.tmd1_bits & LE_T1_ONE)
641 1.1 cgd ifp->if_collisions++;
642 1.1 cgd else if (tmd.tmd1_bits & LE_T1_MORE)
643 1.1 cgd /* Real number is unknown. */
644 1.1 cgd ifp->if_collisions += 2;
645 1.1 cgd ifp->if_opackets++;
646 1.1 cgd }
647 1.1 cgd
648 1.1 cgd if (++bix == sc->sc_ntbuf)
649 1.1 cgd bix = 0;
650 1.1 cgd
651 1.1 cgd --sc->sc_no_td;
652 1.1 cgd }
653 1.1 cgd
654 1.1 cgd sc->sc_first_td = bix;
655 1.1 cgd
656 1.19 thorpej am7990_start(ifp);
657 1.1 cgd
658 1.1 cgd if (sc->sc_no_td == 0)
659 1.1 cgd ifp->if_timer = 0;
660 1.1 cgd }
661 1.1 cgd
662 1.1 cgd /*
663 1.1 cgd * Controller interrupt.
664 1.1 cgd */
665 1.1 cgd int
666 1.19 thorpej am7990_intr(arg)
667 1.1 cgd register void *arg;
668 1.1 cgd {
669 1.19 thorpej register struct am7990_softc *sc = arg;
670 1.1 cgd register u_int16_t isr;
671 1.1 cgd
672 1.19 thorpej isr = (*sc->sc_rdcsr)(sc, LE_CSR0);
673 1.1 cgd #ifdef LEDEBUG
674 1.1 cgd if (sc->sc_debug)
675 1.19 thorpej printf("%s: am7990_intr entering with isr=%04x\n",
676 1.1 cgd sc->sc_dev.dv_xname, isr);
677 1.1 cgd #endif
678 1.1 cgd if ((isr & LE_C0_INTR) == 0)
679 1.1 cgd return (0);
680 1.1 cgd
681 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR0,
682 1.1 cgd isr & (LE_C0_INEA | LE_C0_BABL | LE_C0_MISS | LE_C0_MERR |
683 1.1 cgd LE_C0_RINT | LE_C0_TINT | LE_C0_IDON));
684 1.1 cgd if (isr & LE_C0_ERR) {
685 1.1 cgd if (isr & LE_C0_BABL) {
686 1.6 mycroft #ifdef LEDEBUG
687 1.1 cgd printf("%s: babble\n", sc->sc_dev.dv_xname);
688 1.6 mycroft #endif
689 1.7 mycroft ifp->if_oerrors++;
690 1.1 cgd }
691 1.1 cgd #if 0
692 1.1 cgd if (isr & LE_C0_CERR) {
693 1.1 cgd printf("%s: collision error\n", sc->sc_dev.dv_xname);
694 1.7 mycroft ifp->if_collisions++;
695 1.1 cgd }
696 1.1 cgd #endif
697 1.6 mycroft if (isr & LE_C0_MISS) {
698 1.6 mycroft #ifdef LEDEBUG
699 1.6 mycroft printf("%s: missed packet\n", sc->sc_dev.dv_xname);
700 1.6 mycroft #endif
701 1.7 mycroft ifp->if_ierrors++;
702 1.6 mycroft }
703 1.1 cgd if (isr & LE_C0_MERR) {
704 1.1 cgd printf("%s: memory error\n", sc->sc_dev.dv_xname);
705 1.19 thorpej am7990_reset(sc);
706 1.1 cgd return (1);
707 1.1 cgd }
708 1.1 cgd }
709 1.1 cgd
710 1.1 cgd if ((isr & LE_C0_RXON) == 0) {
711 1.1 cgd printf("%s: receiver disabled\n", sc->sc_dev.dv_xname);
712 1.7 mycroft ifp->if_ierrors++;
713 1.19 thorpej am7990_reset(sc);
714 1.1 cgd return (1);
715 1.1 cgd }
716 1.1 cgd if ((isr & LE_C0_TXON) == 0) {
717 1.1 cgd printf("%s: transmitter disabled\n", sc->sc_dev.dv_xname);
718 1.7 mycroft ifp->if_oerrors++;
719 1.19 thorpej am7990_reset(sc);
720 1.1 cgd return (1);
721 1.1 cgd }
722 1.1 cgd
723 1.1 cgd if (isr & LE_C0_RINT)
724 1.19 thorpej am7990_rint(sc);
725 1.1 cgd if (isr & LE_C0_TINT)
726 1.19 thorpej am7990_tint(sc);
727 1.1 cgd
728 1.1 cgd return (1);
729 1.1 cgd }
730 1.7 mycroft
731 1.7 mycroft #undef ifp
732 1.1 cgd
733 1.19 thorpej void
734 1.19 thorpej am7990_watchdog(ifp)
735 1.19 thorpej struct ifnet *ifp;
736 1.19 thorpej {
737 1.19 thorpej struct am7990_softc *sc = ifp->if_softc;
738 1.19 thorpej
739 1.19 thorpej log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
740 1.19 thorpej ++ifp->if_oerrors;
741 1.19 thorpej
742 1.19 thorpej am7990_reset(sc);
743 1.19 thorpej }
744 1.19 thorpej
745 1.1 cgd /*
746 1.1 cgd * Setup output on interface.
747 1.1 cgd * Get another datagram to send off of the interface queue, and map it to the
748 1.1 cgd * interface before starting the output.
749 1.1 cgd * Called only at splimp or interrupt level.
750 1.1 cgd */
751 1.1 cgd void
752 1.19 thorpej am7990_start(ifp)
753 1.1 cgd register struct ifnet *ifp;
754 1.1 cgd {
755 1.19 thorpej register struct am7990_softc *sc = ifp->if_softc;
756 1.1 cgd register int bix;
757 1.1 cgd register struct mbuf *m;
758 1.1 cgd struct letmd tmd;
759 1.1 cgd int rp;
760 1.1 cgd int len;
761 1.1 cgd
762 1.1 cgd if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
763 1.1 cgd return;
764 1.1 cgd
765 1.1 cgd bix = sc->sc_last_td;
766 1.1 cgd
767 1.1 cgd for (;;) {
768 1.1 cgd rp = LE_TMDADDR(sc, bix);
769 1.1 cgd (*sc->sc_copyfromdesc)(sc, &tmd, rp, sizeof(tmd));
770 1.1 cgd
771 1.1 cgd if (tmd.tmd1_bits & LE_T1_OWN) {
772 1.1 cgd ifp->if_flags |= IFF_OACTIVE;
773 1.1 cgd printf("missing buffer, no_td = %d, last_td = %d\n",
774 1.1 cgd sc->sc_no_td, sc->sc_last_td);
775 1.1 cgd }
776 1.1 cgd
777 1.1 cgd IF_DEQUEUE(&ifp->if_snd, m);
778 1.1 cgd if (m == 0)
779 1.1 cgd break;
780 1.1 cgd
781 1.1 cgd #if NBPFILTER > 0
782 1.1 cgd /*
783 1.1 cgd * If BPF is listening on this interface, let it see the packet
784 1.1 cgd * before we commit it to the wire.
785 1.1 cgd */
786 1.1 cgd if (ifp->if_bpf)
787 1.1 cgd bpf_mtap(ifp->if_bpf, m);
788 1.1 cgd #endif
789 1.1 cgd
790 1.1 cgd /*
791 1.1 cgd * Copy the mbuf chain into the transmit buffer.
792 1.1 cgd */
793 1.19 thorpej len = am7990_put(sc, LE_TBUFADDR(sc, bix), m);
794 1.1 cgd
795 1.1 cgd #ifdef LEDEBUG
796 1.3 mycroft if (len > ETHERMTU + sizeof(struct ether_header))
797 1.1 cgd printf("packet length %d\n", len);
798 1.1 cgd #endif
799 1.1 cgd
800 1.1 cgd ifp->if_timer = 5;
801 1.1 cgd
802 1.1 cgd /*
803 1.1 cgd * Init transmit registers, and set transmit start flag.
804 1.1 cgd */
805 1.1 cgd tmd.tmd1_bits = LE_T1_OWN | LE_T1_STP | LE_T1_ENP;
806 1.1 cgd tmd.tmd2 = -len | LE_XMD2_ONES;
807 1.1 cgd tmd.tmd3 = 0;
808 1.1 cgd
809 1.1 cgd (*sc->sc_copytodesc)(sc, &tmd, rp, sizeof(tmd));
810 1.1 cgd
811 1.1 cgd #ifdef LEDEBUG
812 1.1 cgd if (sc->sc_debug)
813 1.19 thorpej am7990_xmit_print(sc, sc->sc_last_td);
814 1.1 cgd #endif
815 1.1 cgd
816 1.19 thorpej (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_TDMD);
817 1.1 cgd
818 1.1 cgd if (++bix == sc->sc_ntbuf)
819 1.1 cgd bix = 0;
820 1.1 cgd
821 1.1 cgd if (++sc->sc_no_td == sc->sc_ntbuf) {
822 1.1 cgd ifp->if_flags |= IFF_OACTIVE;
823 1.1 cgd break;
824 1.1 cgd }
825 1.1 cgd
826 1.1 cgd }
827 1.1 cgd
828 1.1 cgd sc->sc_last_td = bix;
829 1.1 cgd }
830 1.1 cgd
831 1.1 cgd /*
832 1.1 cgd * Process an ioctl request.
833 1.1 cgd */
834 1.1 cgd int
835 1.19 thorpej am7990_ioctl(ifp, cmd, data)
836 1.1 cgd register struct ifnet *ifp;
837 1.1 cgd u_long cmd;
838 1.1 cgd caddr_t data;
839 1.1 cgd {
840 1.19 thorpej register struct am7990_softc *sc = ifp->if_softc;
841 1.1 cgd struct ifaddr *ifa = (struct ifaddr *)data;
842 1.1 cgd struct ifreq *ifr = (struct ifreq *)data;
843 1.1 cgd int s, error = 0;
844 1.1 cgd
845 1.1 cgd s = splimp();
846 1.1 cgd
847 1.1 cgd switch (cmd) {
848 1.1 cgd
849 1.1 cgd case SIOCSIFADDR:
850 1.1 cgd ifp->if_flags |= IFF_UP;
851 1.1 cgd
852 1.1 cgd switch (ifa->ifa_addr->sa_family) {
853 1.1 cgd #ifdef INET
854 1.1 cgd case AF_INET:
855 1.19 thorpej am7990_init(sc);
856 1.1 cgd arp_ifinit(&sc->sc_arpcom, ifa);
857 1.1 cgd break;
858 1.1 cgd #endif
859 1.1 cgd #ifdef NS
860 1.1 cgd case AF_NS:
861 1.1 cgd {
862 1.1 cgd register struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
863 1.1 cgd
864 1.1 cgd if (ns_nullhost(*ina))
865 1.1 cgd ina->x_host =
866 1.1 cgd *(union ns_host *)(sc->sc_arpcom.ac_enaddr);
867 1.1 cgd else
868 1.1 cgd bcopy(ina->x_host.c_host,
869 1.1 cgd sc->sc_arpcom.ac_enaddr,
870 1.1 cgd sizeof(sc->sc_arpcom.ac_enaddr));
871 1.1 cgd /* Set new address. */
872 1.19 thorpej am7990_init(sc);
873 1.1 cgd break;
874 1.1 cgd }
875 1.1 cgd #endif
876 1.1 cgd default:
877 1.19 thorpej am7990_init(sc);
878 1.1 cgd break;
879 1.1 cgd }
880 1.1 cgd break;
881 1.1 cgd
882 1.1 cgd #if defined(CCITT) && defined(LLC)
883 1.1 cgd case SIOCSIFCONF_X25:
884 1.1 cgd ifp->if_flags |= IFF_UP;
885 1.11 christos ifa->ifa_rtrequest = cons_rtrequest; /* XXX */
886 1.1 cgd error = x25_llcglue(PRC_IFUP, ifa->ifa_addr);
887 1.1 cgd if (error == 0)
888 1.19 thorpej am7990_init(sc);
889 1.1 cgd break;
890 1.1 cgd #endif /* CCITT && LLC */
891 1.1 cgd
892 1.1 cgd case SIOCSIFFLAGS:
893 1.1 cgd if ((ifp->if_flags & IFF_UP) == 0 &&
894 1.1 cgd (ifp->if_flags & IFF_RUNNING) != 0) {
895 1.1 cgd /*
896 1.1 cgd * If interface is marked down and it is running, then
897 1.1 cgd * stop it.
898 1.1 cgd */
899 1.19 thorpej am7990_stop(sc);
900 1.1 cgd ifp->if_flags &= ~IFF_RUNNING;
901 1.1 cgd } else if ((ifp->if_flags & IFF_UP) != 0 &&
902 1.1 cgd (ifp->if_flags & IFF_RUNNING) == 0) {
903 1.1 cgd /*
904 1.1 cgd * If interface is marked up and it is stopped, then
905 1.1 cgd * start it.
906 1.1 cgd */
907 1.19 thorpej am7990_init(sc);
908 1.1 cgd } else {
909 1.1 cgd /*
910 1.1 cgd * Reset the interface to pick up changes in any other
911 1.1 cgd * flags that affect hardware registers.
912 1.1 cgd */
913 1.19 thorpej /*am7990_stop(sc);*/
914 1.19 thorpej am7990_init(sc);
915 1.1 cgd }
916 1.1 cgd #ifdef LEDEBUG
917 1.1 cgd if (ifp->if_flags & IFF_DEBUG)
918 1.1 cgd sc->sc_debug = 1;
919 1.1 cgd else
920 1.1 cgd sc->sc_debug = 0;
921 1.1 cgd #endif
922 1.1 cgd break;
923 1.1 cgd
924 1.1 cgd case SIOCADDMULTI:
925 1.1 cgd case SIOCDELMULTI:
926 1.1 cgd error = (cmd == SIOCADDMULTI) ?
927 1.2 mycroft ether_addmulti(ifr, &sc->sc_arpcom) :
928 1.1 cgd ether_delmulti(ifr, &sc->sc_arpcom);
929 1.1 cgd
930 1.1 cgd if (error == ENETRESET) {
931 1.1 cgd /*
932 1.1 cgd * Multicast list has changed; set the hardware filter
933 1.1 cgd * accordingly.
934 1.1 cgd */
935 1.19 thorpej am7990_reset(sc);
936 1.1 cgd error = 0;
937 1.1 cgd }
938 1.1 cgd break;
939 1.1 cgd
940 1.1 cgd default:
941 1.1 cgd error = EINVAL;
942 1.2 mycroft break;
943 1.1 cgd }
944 1.1 cgd
945 1.1 cgd splx(s);
946 1.1 cgd return (error);
947 1.1 cgd }
948 1.1 cgd
949 1.19 thorpej hide void
950 1.19 thorpej am7990_shutdown(arg)
951 1.19 thorpej void *arg;
952 1.19 thorpej {
953 1.19 thorpej
954 1.19 thorpej am7990_stop((struct am7990_softc *)arg);
955 1.19 thorpej }
956 1.19 thorpej
957 1.1 cgd #ifdef LEDEBUG
958 1.1 cgd void
959 1.19 thorpej am7990_recv_print(sc, no)
960 1.19 thorpej struct am7990_softc *sc;
961 1.1 cgd int no;
962 1.1 cgd {
963 1.1 cgd struct lermd rmd;
964 1.1 cgd u_int16_t len;
965 1.1 cgd struct ether_header eh;
966 1.1 cgd
967 1.1 cgd (*sc->sc_copyfromdesc)(sc, &rmd, LE_RMDADDR(sc, no), sizeof(rmd));
968 1.1 cgd len = rmd.rmd3;
969 1.1 cgd printf("%s: receive buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,
970 1.1 cgd len);
971 1.19 thorpej printf("%s: status %04x\n", sc->sc_dev.dv_xname,
972 1.19 thorpej (*sc->sc_rdcsr)(sc, LE_CSR0));
973 1.1 cgd printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n",
974 1.1 cgd sc->sc_dev.dv_xname,
975 1.1 cgd rmd.rmd0, rmd.rmd1_hadr, rmd.rmd1_bits, rmd.rmd2, rmd.rmd3);
976 1.1 cgd if (len >= sizeof(eh)) {
977 1.1 cgd (*sc->sc_copyfrombuf)(sc, &eh, LE_RBUFADDR(sc, no), sizeof(eh));
978 1.16 pk printf("%s: dst %s", sc->sc_dev.dv_xname,
979 1.16 pk ether_sprintf(eh.ether_dhost));
980 1.1 cgd printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),
981 1.16 pk ntohs(eh.ether_type));
982 1.1 cgd }
983 1.1 cgd }
984 1.1 cgd
985 1.1 cgd void
986 1.19 thorpej am7990_xmit_print(sc, no)
987 1.19 thorpej struct am7990_softc *sc;
988 1.1 cgd int no;
989 1.1 cgd {
990 1.1 cgd struct letmd tmd;
991 1.1 cgd u_int16_t len;
992 1.1 cgd struct ether_header eh;
993 1.1 cgd
994 1.1 cgd (*sc->sc_copyfromdesc)(sc, &tmd, LE_TMDADDR(sc, no), sizeof(tmd));
995 1.1 cgd len = -tmd.tmd2;
996 1.1 cgd printf("%s: transmit buffer %d, len = %d\n", sc->sc_dev.dv_xname, no,
997 1.1 cgd len);
998 1.19 thorpej printf("%s: status %04x\n", sc->sc_dev.dv_xname,
999 1.19 thorpej (*sc->sc_rdcsr)(sc, LE_CSR0));
1000 1.1 cgd printf("%s: ladr %04x, hadr %02x, flags %02x, bcnt %04x, mcnt %04x\n",
1001 1.1 cgd sc->sc_dev.dv_xname,
1002 1.1 cgd tmd.tmd0, tmd.tmd1_hadr, tmd.tmd1_bits, tmd.tmd2, tmd.tmd3);
1003 1.1 cgd if (len >= sizeof(eh)) {
1004 1.1 cgd (*sc->sc_copyfrombuf)(sc, &eh, LE_TBUFADDR(sc, no), sizeof(eh));
1005 1.16 pk printf("%s: dst %s", sc->sc_dev.dv_xname,
1006 1.16 pk ether_sprintf(eh.ether_dhost));
1007 1.1 cgd printf(" src %s type %04x\n", ether_sprintf(eh.ether_shost),
1008 1.1 cgd ntohs(eh.ether_type));
1009 1.1 cgd }
1010 1.1 cgd }
1011 1.1 cgd #endif /* LEDEBUG */
1012 1.1 cgd
1013 1.1 cgd /*
1014 1.1 cgd * Set up the logical address filter.
1015 1.1 cgd */
1016 1.1 cgd void
1017 1.19 thorpej am7990_setladrf(ac, af)
1018 1.1 cgd struct arpcom *ac;
1019 1.1 cgd u_int16_t *af;
1020 1.1 cgd {
1021 1.1 cgd struct ifnet *ifp = &ac->ac_if;
1022 1.1 cgd struct ether_multi *enm;
1023 1.1 cgd register u_char *cp, c;
1024 1.1 cgd register u_int32_t crc;
1025 1.1 cgd register int i, len;
1026 1.1 cgd struct ether_multistep step;
1027 1.1 cgd
1028 1.1 cgd /*
1029 1.1 cgd * Set up multicast address filter by passing all multicast addresses
1030 1.1 cgd * through a crc generator, and then using the high order 6 bits as an
1031 1.1 cgd * index into the 64 bit logical address filter. The high order bit
1032 1.1 cgd * selects the word, while the rest of the bits select the bit within
1033 1.1 cgd * the word.
1034 1.1 cgd */
1035 1.1 cgd
1036 1.1 cgd if (ifp->if_flags & IFF_PROMISC)
1037 1.1 cgd goto allmulti;
1038 1.1 cgd
1039 1.1 cgd af[0] = af[1] = af[2] = af[3] = 0x0000;
1040 1.1 cgd ETHER_FIRST_MULTI(step, ac, enm);
1041 1.1 cgd while (enm != NULL) {
1042 1.13 gwr if (ETHER_CMP(enm->enm_addrlo, enm->enm_addrhi)) {
1043 1.1 cgd /*
1044 1.1 cgd * We must listen to a range of multicast addresses.
1045 1.1 cgd * For now, just accept all multicasts, rather than
1046 1.1 cgd * trying to set only those filter bits needed to match
1047 1.1 cgd * the range. (At this time, the only use of address
1048 1.1 cgd * ranges is for IP multicast routing, for which the
1049 1.1 cgd * range is big enough to require all bits set.)
1050 1.1 cgd */
1051 1.1 cgd goto allmulti;
1052 1.1 cgd }
1053 1.1 cgd
1054 1.1 cgd cp = enm->enm_addrlo;
1055 1.1 cgd crc = 0xffffffff;
1056 1.1 cgd for (len = sizeof(enm->enm_addrlo); --len >= 0;) {
1057 1.1 cgd c = *cp++;
1058 1.1 cgd for (i = 8; --i >= 0;) {
1059 1.1 cgd if ((crc & 0x01) ^ (c & 0x01)) {
1060 1.1 cgd crc >>= 1;
1061 1.1 cgd crc ^= 0xedb88320;
1062 1.1 cgd } else
1063 1.1 cgd crc >>= 1;
1064 1.1 cgd c >>= 1;
1065 1.1 cgd }
1066 1.1 cgd }
1067 1.1 cgd /* Just want the 6 most significant bits. */
1068 1.1 cgd crc >>= 26;
1069 1.1 cgd
1070 1.1 cgd /* Set the corresponding bit in the filter. */
1071 1.1 cgd af[crc >> 4] |= 1 << (crc & 0xf);
1072 1.1 cgd
1073 1.1 cgd ETHER_NEXT_MULTI(step, enm);
1074 1.1 cgd }
1075 1.1 cgd ifp->if_flags &= ~IFF_ALLMULTI;
1076 1.1 cgd return;
1077 1.1 cgd
1078 1.1 cgd allmulti:
1079 1.1 cgd ifp->if_flags |= IFF_ALLMULTI;
1080 1.1 cgd af[0] = af[1] = af[2] = af[3] = 0xffff;
1081 1.1 cgd }
1082 1.1 cgd
1083 1.1 cgd
1084 1.1 cgd /*
1085 1.4 cgd * Routines for accessing the transmit and receive buffers.
1086 1.4 cgd * The various CPU and adapter configurations supported by this
1087 1.4 cgd * driver require three different access methods for buffers
1088 1.4 cgd * and descriptors:
1089 1.4 cgd * (1) contig (contiguous data; no padding),
1090 1.4 cgd * (2) gap2 (two bytes of data followed by two bytes of padding),
1091 1.4 cgd * (3) gap16 (16 bytes of data followed by 16 bytes of padding).
1092 1.1 cgd */
1093 1.1 cgd
1094 1.4 cgd /*
1095 1.4 cgd * contig: contiguous data with no padding.
1096 1.4 cgd *
1097 1.4 cgd * Buffers may have any alignment.
1098 1.4 cgd */
1099 1.1 cgd
1100 1.17 cgd void
1101 1.17 cgd am7990_copytobuf_contig(sc, from, boff, len)
1102 1.19 thorpej struct am7990_softc *sc;
1103 1.4 cgd void *from;
1104 1.1 cgd int boff, len;
1105 1.1 cgd {
1106 1.1 cgd volatile caddr_t buf = sc->sc_mem;
1107 1.1 cgd
1108 1.1 cgd /*
1109 1.1 cgd * Just call bcopy() to do the work.
1110 1.1 cgd */
1111 1.1 cgd bcopy(from, buf + boff, len);
1112 1.1 cgd }
1113 1.1 cgd
1114 1.17 cgd void
1115 1.17 cgd am7990_copyfrombuf_contig(sc, to, boff, len)
1116 1.19 thorpej struct am7990_softc *sc;
1117 1.4 cgd void *to;
1118 1.1 cgd int boff, len;
1119 1.1 cgd {
1120 1.1 cgd volatile caddr_t buf = sc->sc_mem;
1121 1.1 cgd
1122 1.1 cgd /*
1123 1.1 cgd * Just call bcopy() to do the work.
1124 1.1 cgd */
1125 1.1 cgd bcopy(buf + boff, to, len);
1126 1.1 cgd }
1127 1.1 cgd
1128 1.17 cgd void
1129 1.17 cgd am7990_zerobuf_contig(sc, boff, len)
1130 1.19 thorpej struct am7990_softc *sc;
1131 1.1 cgd int boff, len;
1132 1.1 cgd {
1133 1.1 cgd volatile caddr_t buf = sc->sc_mem;
1134 1.1 cgd
1135 1.1 cgd /*
1136 1.1 cgd * Just let bzero() do the work
1137 1.1 cgd */
1138 1.1 cgd bzero(buf + boff, len);
1139 1.1 cgd }
1140 1.1 cgd
1141 1.19 thorpej #if 0
1142 1.19 thorpej /*
1143 1.19 thorpej * Examples only; duplicate these and tweak (if necessary) in
1144 1.19 thorpej * machine-specific front-ends.
1145 1.19 thorpej */
1146 1.19 thorpej
1147 1.1 cgd /*
1148 1.4 cgd * gap2: two bytes of data followed by two bytes of pad.
1149 1.4 cgd *
1150 1.4 cgd * Buffers must be 4-byte aligned. The code doesn't worry about
1151 1.4 cgd * doing an extra byte.
1152 1.1 cgd */
1153 1.4 cgd
1154 1.17 cgd void
1155 1.17 cgd am7990_copytobuf_gap2(sc, fromv, boff, len)
1156 1.19 thorpej struct am7990_softc *sc;
1157 1.4 cgd void *fromv;
1158 1.1 cgd int boff;
1159 1.1 cgd register int len;
1160 1.1 cgd {
1161 1.1 cgd volatile caddr_t buf = sc->sc_mem;
1162 1.4 cgd register caddr_t from = fromv;
1163 1.4 cgd register volatile u_int16_t *bptr;
1164 1.1 cgd
1165 1.1 cgd if (boff & 0x1) {
1166 1.1 cgd /* handle unaligned first byte */
1167 1.4 cgd bptr = ((volatile u_int16_t *)buf) + (boff - 1);
1168 1.1 cgd *bptr = (*from++ << 8) | (*bptr & 0xff);
1169 1.1 cgd bptr += 2;
1170 1.1 cgd len--;
1171 1.1 cgd } else
1172 1.4 cgd bptr = ((volatile u_int16_t *)buf) + boff;
1173 1.4 cgd while (len > 1) {
1174 1.4 cgd *bptr = (from[1] << 8) | (from[0] & 0xff);
1175 1.4 cgd bptr += 2;
1176 1.4 cgd from += 2;
1177 1.4 cgd len -= 2;
1178 1.1 cgd }
1179 1.1 cgd if (len == 1)
1180 1.4 cgd *bptr = (u_int16_t)*from;
1181 1.1 cgd }
1182 1.1 cgd
1183 1.17 cgd void
1184 1.17 cgd am7990_copyfrombuf_gap2(sc, tov, boff, len)
1185 1.19 thorpej struct am7990_softc *sc;
1186 1.4 cgd void *tov;
1187 1.1 cgd int boff, len;
1188 1.1 cgd {
1189 1.1 cgd volatile caddr_t buf = sc->sc_mem;
1190 1.4 cgd register caddr_t to = tov;
1191 1.4 cgd register volatile u_int16_t *bptr;
1192 1.4 cgd register u_int16_t tmp;
1193 1.1 cgd
1194 1.1 cgd if (boff & 0x1) {
1195 1.1 cgd /* handle unaligned first byte */
1196 1.4 cgd bptr = ((volatile u_int16_t *)buf) + (boff - 1);
1197 1.1 cgd *to++ = (*bptr >> 8) & 0xff;
1198 1.1 cgd bptr += 2;
1199 1.1 cgd len--;
1200 1.1 cgd } else
1201 1.4 cgd bptr = ((volatile u_int16_t *)buf) + boff;
1202 1.4 cgd while (len > 1) {
1203 1.4 cgd tmp = *bptr;
1204 1.4 cgd *to++ = tmp & 0xff;
1205 1.4 cgd *to++ = (tmp >> 8) & 0xff;
1206 1.4 cgd bptr += 2;
1207 1.4 cgd len -= 2;
1208 1.1 cgd }
1209 1.1 cgd if (len == 1)
1210 1.1 cgd *to = *bptr & 0xff;
1211 1.1 cgd }
1212 1.1 cgd
1213 1.17 cgd void
1214 1.17 cgd am7990_zerobuf_gap2(sc, boff, len)
1215 1.19 thorpej struct am7990_softc *sc;
1216 1.1 cgd int boff, len;
1217 1.1 cgd {
1218 1.1 cgd volatile caddr_t buf = sc->sc_mem;
1219 1.4 cgd register volatile u_int16_t *bptr;
1220 1.1 cgd
1221 1.1 cgd if ((unsigned)boff & 0x1) {
1222 1.4 cgd bptr = ((volatile u_int16_t *)buf) + (boff - 1);
1223 1.1 cgd *bptr &= 0xff;
1224 1.1 cgd bptr += 2;
1225 1.1 cgd len--;
1226 1.1 cgd } else
1227 1.4 cgd bptr = ((volatile u_int16_t *)buf) + boff;
1228 1.1 cgd while (len > 0) {
1229 1.1 cgd *bptr = 0;
1230 1.1 cgd bptr += 2;
1231 1.1 cgd len -= 2;
1232 1.1 cgd }
1233 1.1 cgd }
1234 1.1 cgd
1235 1.1 cgd /*
1236 1.4 cgd * gap16: 16 bytes of data followed by 16 bytes of pad.
1237 1.4 cgd *
1238 1.4 cgd * Buffers must be 32-byte aligned.
1239 1.1 cgd */
1240 1.4 cgd
1241 1.17 cgd void
1242 1.17 cgd am7990_copytobuf_gap16(sc, fromv, boff, len)
1243 1.19 thorpej struct am7990_softc *sc;
1244 1.4 cgd void *fromv;
1245 1.1 cgd int boff;
1246 1.1 cgd register int len;
1247 1.1 cgd {
1248 1.1 cgd volatile caddr_t buf = sc->sc_mem;
1249 1.4 cgd register caddr_t from = fromv;
1250 1.1 cgd register caddr_t bptr;
1251 1.1 cgd register int xfer;
1252 1.1 cgd
1253 1.1 cgd bptr = buf + ((boff << 1) & ~0x1f);
1254 1.1 cgd boff &= 0xf;
1255 1.1 cgd xfer = min(len, 16 - boff);
1256 1.1 cgd while (len > 0) {
1257 1.1 cgd bcopy(from, bptr + boff, xfer);
1258 1.1 cgd from += xfer;
1259 1.1 cgd bptr += 32;
1260 1.1 cgd boff = 0;
1261 1.1 cgd len -= xfer;
1262 1.1 cgd xfer = min(len, 16);
1263 1.1 cgd }
1264 1.1 cgd }
1265 1.1 cgd
1266 1.17 cgd void
1267 1.17 cgd am7990_copyfrombuf_gap16(sc, tov, boff, len)
1268 1.19 thorpej struct am7990_softc *sc;
1269 1.4 cgd void *tov;
1270 1.1 cgd int boff, len;
1271 1.1 cgd {
1272 1.1 cgd volatile caddr_t buf = sc->sc_mem;
1273 1.4 cgd register caddr_t to = tov;
1274 1.1 cgd register caddr_t bptr;
1275 1.1 cgd register int xfer;
1276 1.1 cgd
1277 1.1 cgd bptr = buf + ((boff << 1) & ~0x1f);
1278 1.1 cgd boff &= 0xf;
1279 1.1 cgd xfer = min(len, 16 - boff);
1280 1.1 cgd while (len > 0) {
1281 1.1 cgd bcopy(bptr + boff, to, xfer);
1282 1.1 cgd to += xfer;
1283 1.1 cgd bptr += 32;
1284 1.1 cgd boff = 0;
1285 1.1 cgd len -= xfer;
1286 1.1 cgd xfer = min(len, 16);
1287 1.1 cgd }
1288 1.1 cgd }
1289 1.1 cgd
1290 1.17 cgd void
1291 1.17 cgd am7990_zerobuf_gap16(sc, boff, len)
1292 1.19 thorpej struct am7990_softc *sc;
1293 1.1 cgd int boff, len;
1294 1.1 cgd {
1295 1.1 cgd volatile caddr_t buf = sc->sc_mem;
1296 1.1 cgd register caddr_t bptr;
1297 1.1 cgd register int xfer;
1298 1.1 cgd
1299 1.1 cgd bptr = buf + ((boff << 1) & ~0x1f);
1300 1.1 cgd boff &= 0xf;
1301 1.1 cgd xfer = min(len, 16 - boff);
1302 1.1 cgd while (len > 0) {
1303 1.1 cgd bzero(bptr + boff, xfer);
1304 1.1 cgd bptr += 32;
1305 1.1 cgd boff = 0;
1306 1.1 cgd len -= xfer;
1307 1.1 cgd xfer = min(len, 16);
1308 1.1 cgd }
1309 1.1 cgd }
1310 1.19 thorpej #endif /* Example only */
1311