No empty .Rs/.Re
[netbsd-mini2440.git] / sys / dev / ic / lance.c
blobd260f371545132082a702ebf1783aba105be9792
1 /* $NetBSD: lance.c,v 1.42 2008/11/07 00:20:02 dyoung Exp $ */
3 /*-
4 * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
9 * Simulation Facility, NASA Ames Research Center.
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.
20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
33 /*-
34 * Copyright (c) 1992, 1993
35 * The Regents of the University of California. All rights reserved.
37 * This code is derived from software contributed to Berkeley by
38 * Ralph Campbell and Rick Macklem.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
42 * are met:
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. Neither the name of the University nor the names of its contributors
49 * may be used to endorse or promote products derived from this software
50 * without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
53 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
54 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
55 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
56 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
57 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
58 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
59 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
60 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
61 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
62 * SUCH DAMAGE.
64 * @(#)if_le.c 8.2 (Berkeley) 11/16/93
67 #include <sys/cdefs.h>
68 __KERNEL_RCSID(0, "$NetBSD: lance.c,v 1.42 2008/11/07 00:20:02 dyoung Exp $");
70 #include "bpfilter.h"
71 #include "rnd.h"
73 #include <sys/param.h>
74 #include <sys/systm.h>
75 #include <sys/mbuf.h>
76 #include <sys/syslog.h>
77 #include <sys/socket.h>
78 #include <sys/device.h>
79 #include <sys/malloc.h>
80 #include <sys/ioctl.h>
81 #include <sys/errno.h>
82 #if NRND > 0
83 #include <sys/rnd.h>
84 #endif
86 #include <net/if.h>
87 #include <net/if_dl.h>
88 #include <net/if_ether.h>
89 #include <net/if_media.h>
92 #if NBPFILTER > 0
93 #include <net/bpf.h>
94 #include <net/bpfdesc.h>
95 #endif
97 #include <dev/ic/lancereg.h>
98 #include <dev/ic/lancevar.h>
100 #if defined(_KERNEL_OPT)
101 #include "opt_ddb.h"
102 #endif
104 #ifdef DDB
105 #define integrate
106 #define hide
107 #else
108 #define integrate static inline
109 #define hide static
110 #endif
112 integrate struct mbuf *lance_get(struct lance_softc *, int, int);
114 hide bool lance_shutdown(device_t, int);
116 int lance_mediachange(struct ifnet *);
117 void lance_mediastatus(struct ifnet *, struct ifmediareq *);
119 static inline u_int16_t ether_cmp(void *, void *);
121 void lance_stop(struct ifnet *, int);
122 int lance_ioctl(struct ifnet *, u_long, void *);
123 void lance_watchdog(struct ifnet *);
126 * Compare two Ether/802 addresses for equality, inlined and
127 * unrolled for speed. Use this like memcmp().
129 * XXX: Add <machine/inlines.h> for stuff like this?
130 * XXX: or maybe add it to libkern.h instead?
132 * "I'd love to have an inline assembler version of this."
133 * XXX: Who wanted that? mycroft? I wrote one, but this
134 * version in C is as good as hand-coded assembly. -gwr
136 * Please do NOT tweak this without looking at the actual
137 * assembly code generated before and after your tweaks!
139 static inline uint16_t
140 ether_cmp(void *one, void *two)
142 uint16_t *a = (uint16_t *)one;
143 uint16_t *b = (uint16_t *)two;
144 uint16_t diff;
146 #ifdef m68k
148 * The post-increment-pointer form produces the best
149 * machine code for m68k. This was carefully tuned
150 * so it compiles to just 8 short (2-byte) op-codes!
152 diff = *a++ - *b++;
153 diff |= *a++ - *b++;
154 diff |= *a++ - *b++;
155 #else
157 * Most modern CPUs do better with a single expresion.
158 * Note that short-cut evaluation is NOT helpful here,
159 * because it just makes the code longer, not faster!
161 diff = (a[0] - b[0]) | (a[1] - b[1]) | (a[2] - b[2]);
162 #endif
164 return (diff);
167 #define ETHER_CMP ether_cmp
169 #ifdef LANCE_REVC_BUG
170 /* Make sure this is short-aligned, for ether_cmp(). */
171 static uint16_t bcast_enaddr[3] = { ~0, ~0, ~0 };
172 #endif
174 void
175 lance_config(struct lance_softc *sc)
177 int i, nbuf;
178 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
180 /* Initialize ifnet structure. */
181 strcpy(ifp->if_xname, device_xname(sc->sc_dev));
182 ifp->if_softc = sc;
183 ifp->if_start = sc->sc_start;
184 ifp->if_ioctl = lance_ioctl;
185 ifp->if_watchdog = lance_watchdog;
186 ifp->if_init = lance_init;
187 ifp->if_stop = lance_stop;
188 ifp->if_flags =
189 IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
190 #ifdef LANCE_REVC_BUG
191 ifp->if_flags &= ~IFF_MULTICAST;
192 #endif
193 IFQ_SET_READY(&ifp->if_snd);
195 /* Initialize ifmedia structures. */
196 ifmedia_init(&sc->sc_media, 0, lance_mediachange, lance_mediastatus);
197 if (sc->sc_supmedia != NULL) {
198 for (i = 0; i < sc->sc_nsupmedia; i++)
199 ifmedia_add(&sc->sc_media, sc->sc_supmedia[i],
200 0, NULL);
201 ifmedia_set(&sc->sc_media, sc->sc_defaultmedia);
202 } else {
203 ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
204 ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
207 switch (sc->sc_memsize) {
208 case 8192:
209 sc->sc_nrbuf = 4;
210 sc->sc_ntbuf = 1;
211 break;
212 case 16384:
213 sc->sc_nrbuf = 8;
214 sc->sc_ntbuf = 2;
215 break;
216 case 32768:
217 sc->sc_nrbuf = 16;
218 sc->sc_ntbuf = 4;
219 break;
220 case 65536:
221 sc->sc_nrbuf = 32;
222 sc->sc_ntbuf = 8;
223 break;
224 case 131072:
225 sc->sc_nrbuf = 64;
226 sc->sc_ntbuf = 16;
227 break;
228 case 262144:
229 sc->sc_nrbuf = 128;
230 sc->sc_ntbuf = 32;
231 break;
232 default:
233 /* weird memory size; cope with it */
234 nbuf = sc->sc_memsize / LEBLEN;
235 sc->sc_ntbuf = nbuf / 5;
236 sc->sc_nrbuf = nbuf - sc->sc_ntbuf;
239 aprint_normal(": address %s\n", ether_sprintf(sc->sc_enaddr));
240 aprint_normal_dev(sc->sc_dev,
241 "%d receive buffers, %d transmit buffers\n",
242 sc->sc_nrbuf, sc->sc_ntbuf);
244 /* Make sure the chip is stopped. */
245 lance_stop(ifp, 0);
247 /* claim 802.1q capability */
248 sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
249 /* Attach the interface. */
250 if_attach(ifp);
251 ether_ifattach(ifp, sc->sc_enaddr);
253 if (pmf_device_register1(sc->sc_dev, NULL, NULL, lance_shutdown))
254 pmf_class_network_register(sc->sc_dev, ifp);
255 else
256 aprint_error_dev(sc->sc_dev,
257 "couldn't establish power handler\n");
259 sc->sc_rbufaddr = malloc(sc->sc_nrbuf * sizeof(int), M_DEVBUF,
260 M_WAITOK);
261 sc->sc_tbufaddr = malloc(sc->sc_ntbuf * sizeof(int), M_DEVBUF,
262 M_WAITOK);
264 #if NRND > 0
265 rnd_attach_source(&sc->rnd_source, device_xname(sc->sc_dev),
266 RND_TYPE_NET, 0);
267 #endif
270 void
271 lance_reset(struct lance_softc *sc)
273 int s;
275 s = splnet();
276 lance_init(&sc->sc_ethercom.ec_if);
277 splx(s);
280 void
281 lance_stop(struct ifnet *ifp, int disable)
283 struct lance_softc *sc = ifp->if_softc;
285 (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP);
289 * Initialization of interface; set up initialization block
290 * and transmit/receive descriptor rings.
293 lance_init(struct ifnet *ifp)
295 struct lance_softc *sc = ifp->if_softc;
296 int timo;
297 u_long a;
299 (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP);
300 DELAY(100);
302 /* Newer LANCE chips have a reset register */
303 if (sc->sc_hwreset)
304 (*sc->sc_hwreset)(sc);
306 /* Set the correct byte swapping mode, etc. */
307 (*sc->sc_wrcsr)(sc, LE_CSR3, sc->sc_conf3);
309 /* Set up LANCE init block. */
310 (*sc->sc_meminit)(sc);
312 /* Give LANCE the physical address of its init block. */
313 a = sc->sc_addr + LE_INITADDR(sc);
314 (*sc->sc_wrcsr)(sc, LE_CSR1, a);
315 (*sc->sc_wrcsr)(sc, LE_CSR2, a >> 16);
317 /* Try to initialize the LANCE. */
318 DELAY(100);
319 (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INIT);
321 /* Wait for initialization to finish. */
322 for (timo = 100000; timo; timo--)
323 if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON)
324 break;
326 if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) {
327 /* Start the LANCE. */
328 (*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_STRT);
329 ifp->if_flags |= IFF_RUNNING;
330 ifp->if_flags &= ~IFF_OACTIVE;
331 ifp->if_timer = 0;
332 (*sc->sc_start)(ifp);
333 } else
334 printf("%s: controller failed to initialize\n",
335 device_xname(sc->sc_dev));
336 if (sc->sc_hwinit)
337 (*sc->sc_hwinit)(sc);
339 return (0);
343 * Routine to copy from mbuf chain to transmit buffer in
344 * network buffer memory.
347 lance_put(struct lance_softc *sc, int boff, struct mbuf *m)
349 struct mbuf *n;
350 int len, tlen = 0;
352 for (; m; m = n) {
353 len = m->m_len;
354 if (len == 0) {
355 MFREE(m, n);
356 continue;
358 (*sc->sc_copytobuf)(sc, mtod(m, void *), boff, len);
359 boff += len;
360 tlen += len;
361 MFREE(m, n);
363 if (tlen < LEMINSIZE) {
364 (*sc->sc_zerobuf)(sc, boff, LEMINSIZE - tlen);
365 tlen = LEMINSIZE;
367 return (tlen);
371 * Pull data off an interface.
372 * Len is length of data, with local net header stripped.
373 * We copy the data into mbufs. When full cluster sized units are present
374 * we copy into clusters.
376 integrate struct mbuf *
377 lance_get(struct lance_softc *sc, int boff, int totlen)
379 struct mbuf *m, *m0, *newm;
380 int len;
382 MGETHDR(m0, M_DONTWAIT, MT_DATA);
383 if (m0 == 0)
384 return (0);
385 m0->m_pkthdr.rcvif = &sc->sc_ethercom.ec_if;
386 m0->m_pkthdr.len = totlen;
387 len = MHLEN;
388 m = m0;
390 while (totlen > 0) {
391 if (totlen >= MINCLSIZE) {
392 MCLGET(m, M_DONTWAIT);
393 if ((m->m_flags & M_EXT) == 0)
394 goto bad;
395 len = MCLBYTES;
398 if (m == m0) {
399 char *newdata = (char *)
400 ALIGN(m->m_data + sizeof(struct ether_header)) -
401 sizeof(struct ether_header);
402 len -= newdata - m->m_data;
403 m->m_data = newdata;
406 m->m_len = len = min(totlen, len);
407 (*sc->sc_copyfrombuf)(sc, mtod(m, void *), boff, len);
408 boff += len;
410 totlen -= len;
411 if (totlen > 0) {
412 MGET(newm, M_DONTWAIT, MT_DATA);
413 if (newm == 0)
414 goto bad;
415 len = MLEN;
416 m = m->m_next = newm;
420 return (m0);
422 bad:
423 m_freem(m0);
424 return (0);
428 * Pass a packet to the higher levels.
430 void
431 lance_read(struct lance_softc *sc, int boff, int len)
433 struct mbuf *m;
434 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
435 struct ether_header *eh;
437 if (len <= sizeof(struct ether_header) ||
438 len > ((sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) ?
439 ETHER_VLAN_ENCAP_LEN + ETHERMTU + sizeof(struct ether_header) :
440 ETHERMTU + sizeof(struct ether_header))) {
441 #ifdef LEDEBUG
442 printf("%s: invalid packet size %d; dropping\n",
443 device_xname(sc->sc_dev), len);
444 #endif
445 ifp->if_ierrors++;
446 return;
449 /* Pull packet off interface. */
450 m = lance_get(sc, boff, len);
451 if (m == 0) {
452 ifp->if_ierrors++;
453 return;
456 ifp->if_ipackets++;
458 eh = mtod(m, struct ether_header *);
460 #ifdef LANCE_REVC_BUG
462 * The old LANCE (Rev. C) chips have a bug which causes
463 * garbage to be inserted in front of the received packet.
464 * The work-around is to ignore packets with an invalid
465 * destination address (garbage will usually not match).
466 * Of course, this precludes multicast support...
468 if (ETHER_CMP(eh->ether_dhost, sc->sc_enaddr) &&
469 ETHER_CMP(eh->ether_dhost, bcast_enaddr)) {
470 m_freem(m);
471 return;
473 #endif
476 * Some lance device does not present IFF_SIMPLEX behavior on multicast
477 * packets. Make sure to drop it if it is from ourselves.
479 if (!ETHER_CMP(eh->ether_shost, sc->sc_enaddr)) {
480 m_freem(m);
481 return;
484 #if NBPFILTER > 0
486 * Check if there's a BPF listener on this interface.
487 * If so, hand off the raw packet to BPF.
489 if (ifp->if_bpf)
490 bpf_mtap(ifp->if_bpf, m);
491 #endif
493 /* Pass the packet up. */
494 (*ifp->if_input)(ifp, m);
497 #undef ifp
499 void
500 lance_watchdog(struct ifnet *ifp)
502 struct lance_softc *sc = ifp->if_softc;
504 log(LOG_ERR, "%s: device timeout\n", device_xname(sc->sc_dev));
505 ++ifp->if_oerrors;
507 lance_reset(sc);
511 lance_mediachange(struct ifnet *ifp)
513 struct lance_softc *sc = ifp->if_softc;
515 if (sc->sc_mediachange)
516 return ((*sc->sc_mediachange)(sc));
517 return (0);
520 void
521 lance_mediastatus(struct ifnet *ifp, struct ifmediareq *ifmr)
523 struct lance_softc *sc = ifp->if_softc;
525 if ((ifp->if_flags & IFF_UP) == 0)
526 return;
528 ifmr->ifm_status = IFM_AVALID;
529 if (sc->sc_havecarrier)
530 ifmr->ifm_status |= IFM_ACTIVE;
532 if (sc->sc_mediastatus)
533 (*sc->sc_mediastatus)(sc, ifmr);
537 * Process an ioctl request.
540 lance_ioctl(struct ifnet *ifp, u_long cmd, void *data)
542 struct lance_softc *sc = ifp->if_softc;
543 struct ifreq *ifr = (struct ifreq *)data;
544 int s, error = 0;
546 s = splnet();
548 switch (cmd) {
549 case SIOCGIFMEDIA:
550 case SIOCSIFMEDIA:
551 error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
552 break;
553 default:
554 if ((error = ether_ioctl(ifp, cmd, data)) != ENETRESET)
555 break;
556 error = 0;
557 if (cmd != SIOCADDMULTI && cmd != SIOCDELMULTI)
558 break;
559 if (ifp->if_flags & IFF_RUNNING) {
561 * Multicast list has changed; set the hardware filter
562 * accordingly.
564 lance_reset(sc);
566 break;
570 splx(s);
571 return (error);
574 hide bool
575 lance_shutdown(device_t self, int howto)
577 struct lance_softc *sc = device_private(self);
578 struct ifnet *ifp = &sc->sc_ethercom.ec_if;
580 lance_stop(ifp, 0);
582 return true;
586 * Set up the logical address filter.
588 void
589 lance_setladrf(struct ethercom *ac, uint16_t *af)
591 struct ifnet *ifp = &ac->ec_if;
592 struct ether_multi *enm;
593 uint32_t crc;
594 struct ether_multistep step;
597 * Set up multicast address filter by passing all multicast addresses
598 * through a crc generator, and then using the high order 6 bits as an
599 * index into the 64 bit logical address filter. The high order bit
600 * selects the word, while the rest of the bits select the bit within
601 * the word.
604 if (ifp->if_flags & IFF_PROMISC)
605 goto allmulti;
607 af[0] = af[1] = af[2] = af[3] = 0x0000;
608 ETHER_FIRST_MULTI(step, ac, enm);
609 while (enm != NULL) {
610 if (ETHER_CMP(enm->enm_addrlo, enm->enm_addrhi)) {
612 * We must listen to a range of multicast addresses.
613 * For now, just accept all multicasts, rather than
614 * trying to set only those filter bits needed to match
615 * the range. (At this time, the only use of address
616 * ranges is for IP multicast routing, for which the
617 * range is big enough to require all bits set.)
619 goto allmulti;
622 crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
624 /* Just want the 6 most significant bits. */
625 crc >>= 26;
627 /* Set the corresponding bit in the filter. */
628 af[crc >> 4] |= 1 << (crc & 0xf);
630 ETHER_NEXT_MULTI(step, enm);
632 ifp->if_flags &= ~IFF_ALLMULTI;
633 return;
635 allmulti:
636 ifp->if_flags |= IFF_ALLMULTI;
637 af[0] = af[1] = af[2] = af[3] = 0xffff;
641 * Routines for accessing the transmit and receive buffers.
642 * The various CPU and adapter configurations supported by this
643 * driver require three different access methods for buffers
644 * and descriptors:
645 * (1) contig (contiguous data; no padding),
646 * (2) gap2 (two bytes of data followed by two bytes of padding),
647 * (3) gap16 (16 bytes of data followed by 16 bytes of padding).
651 * contig: contiguous data with no padding.
653 * Buffers may have any alignment.
656 void
657 lance_copytobuf_contig(struct lance_softc *sc, void *from, int boff, int len)
659 uint8_t *buf = sc->sc_mem;
662 * Just call memcpy() to do the work.
664 memcpy(buf + boff, from, len);
667 void
668 lance_copyfrombuf_contig(struct lance_softc *sc, void *to, int boff, int len)
670 uint8_t *buf = sc->sc_mem;
673 * Just call memcpy() to do the work.
675 memcpy(to, buf + boff, len);
678 void
679 lance_zerobuf_contig(struct lance_softc *sc, int boff, int len)
681 uint8_t *buf = sc->sc_mem;
684 * Just let memset() do the work
686 memset(buf + boff, 0, len);
689 #if 0
691 * Examples only; duplicate these and tweak (if necessary) in
692 * machine-specific front-ends.
696 * gap2: two bytes of data followed by two bytes of pad.
698 * Buffers must be 4-byte aligned. The code doesn't worry about
699 * doing an extra byte.
702 void
703 lance_copytobuf_gap2(struct lance_softc *sc, void *fromv, int boff, int len)
705 volatile void *buf = sc->sc_mem;
706 void *from = fromv;
707 volatile uint16_t *bptr;
709 if (boff & 0x1) {
710 /* handle unaligned first byte */
711 bptr = ((volatile uint16_t *)buf) + (boff - 1);
712 *bptr = (*from++ << 8) | (*bptr & 0xff);
713 bptr += 2;
714 len--;
715 } else
716 bptr = ((volatile uint16_t *)buf) + boff;
717 while (len > 1) {
718 *bptr = (from[1] << 8) | (from[0] & 0xff);
719 bptr += 2;
720 from += 2;
721 len -= 2;
723 if (len == 1)
724 *bptr = (uint16_t)*from;
727 void
728 lance_copyfrombuf_gap2(struct lance_softc *sc, void *tov, int boff, int len)
730 volatile void *buf = sc->sc_mem;
731 void *to = tov;
732 volatile uint16_t *bptr;
733 uint16_t tmp;
735 if (boff & 0x1) {
736 /* handle unaligned first byte */
737 bptr = ((volatile uint16_t *)buf) + (boff - 1);
738 *to++ = (*bptr >> 8) & 0xff;
739 bptr += 2;
740 len--;
741 } else
742 bptr = ((volatile uint16_t *)buf) + boff;
743 while (len > 1) {
744 tmp = *bptr;
745 *to++ = tmp & 0xff;
746 *to++ = (tmp >> 8) & 0xff;
747 bptr += 2;
748 len -= 2;
750 if (len == 1)
751 *to = *bptr & 0xff;
754 void
755 lance_zerobuf_gap2(struct lance_softc *sc, int boff, int len)
757 volatile void *buf = sc->sc_mem;
758 volatile uint16_t *bptr;
760 if ((unsigned int)boff & 0x1) {
761 bptr = ((volatile uint16_t *)buf) + (boff - 1);
762 *bptr &= 0xff;
763 bptr += 2;
764 len--;
765 } else
766 bptr = ((volatile uint16_t *)buf) + boff;
767 while (len > 0) {
768 *bptr = 0;
769 bptr += 2;
770 len -= 2;
775 * gap16: 16 bytes of data followed by 16 bytes of pad.
777 * Buffers must be 32-byte aligned.
780 void
781 lance_copytobuf_gap16(struct lance_softc *sc, void *fromv, int boff, int len)
783 volatile uint8_t *buf = sc->sc_mem;
784 void *from = fromv;
785 uint8_t *bptr;
786 int xfer;
788 bptr = buf + ((boff << 1) & ~0x1f);
789 boff &= 0xf;
790 xfer = min(len, 16 - boff);
791 while (len > 0) {
792 memcpy(bptr + boff, from, xfer);
793 from += xfer;
794 bptr += 32;
795 boff = 0;
796 len -= xfer;
797 xfer = min(len, 16);
801 void
802 lance_copyfrombuf_gap16(struct lance_softc *sc, void *tov, int boff, int len)
804 volatile uint8_t *buf = sc->sc_mem;
805 void *to = tov;
806 uint8_t *bptr;
807 int xfer;
809 bptr = buf + ((boff << 1) & ~0x1f);
810 boff &= 0xf;
811 xfer = min(len, 16 - boff);
812 while (len > 0) {
813 memcpy(to, bptr + boff, xfer);
814 to += xfer;
815 bptr += 32;
816 boff = 0;
817 len -= xfer;
818 xfer = min(len, 16);
822 void
823 lance_zerobuf_gap16(struct lance_softc *sc, int boff, int len)
825 volatile uint8_t *buf = sc->sc_mem;
826 uint8_t *bptr;
827 int xfer;
829 bptr = buf + ((boff << 1) & ~0x1f);
830 boff &= 0xf;
831 xfer = min(len, 16 - boff);
832 while (len > 0) {
833 memset(bptr + boff, 0, xfer);
834 bptr += 32;
835 boff = 0;
836 len -= xfer;
837 xfer = min(len, 16);
840 #endif /* Example only */