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