2003-01-31 20:40:05 +03:00
|
|
|
/* $NetBSD: lance.c,v 1.28 2003/01/31 17:40:05 pk Exp $ */
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
/*-
|
1998-08-15 14:51:16 +04:00
|
|
|
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
|
1998-07-21 21:26:45 +04:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
1998-08-15 14:51:16 +04:00
|
|
|
* by Charles M. Hannum and by Jason R. Thorpe of the Numerical Aerospace
|
|
|
|
* Simulation Facility, NASA Ames Research Center.
|
1998-07-21 21:26:45 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 1992, 1993
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to Berkeley by
|
|
|
|
* Ralph Campbell and Rick Macklem.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the University of
|
|
|
|
* California, Berkeley and its contributors.
|
|
|
|
* 4. Neither the name of the University nor the names of its contributors
|
|
|
|
* may be used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* @(#)if_le.c 8.2 (Berkeley) 11/16/93
|
|
|
|
*/
|
|
|
|
|
2001-11-13 16:14:31 +03:00
|
|
|
#include <sys/cdefs.h>
|
2003-01-31 20:40:05 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: lance.c,v 1.28 2003/01/31 17:40:05 pk Exp $");
|
2001-11-13 16:14:31 +03:00
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
#include "opt_ccitt.h"
|
|
|
|
#include "opt_llc.h"
|
|
|
|
#include "bpfilter.h"
|
|
|
|
#include "rnd.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/errno.h>
|
|
|
|
#if NRND > 0
|
|
|
|
#include <sys/rnd.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_dl.h>
|
|
|
|
#include <net/if_ether.h>
|
|
|
|
#include <net/if_media.h>
|
|
|
|
|
|
|
|
#if defined(CCITT) && defined(LLC)
|
|
|
|
#include <sys/socketvar.h>
|
|
|
|
#include <netccitt/x25.h>
|
|
|
|
#include <netccitt/pk.h>
|
|
|
|
#include <netccitt/pk_var.h>
|
|
|
|
#include <netccitt/pk_extern.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <dev/ic/lancereg.h>
|
|
|
|
#include <dev/ic/lancevar.h>
|
|
|
|
|
2001-05-30 15:40:35 +04:00
|
|
|
#if defined(_KERNEL_OPT)
|
1998-07-21 21:26:45 +04:00
|
|
|
#include "opt_ddb.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef DDB
|
|
|
|
#define integrate
|
|
|
|
#define hide
|
|
|
|
#else
|
|
|
|
#define integrate static __inline
|
|
|
|
#define hide static
|
|
|
|
#endif
|
|
|
|
|
|
|
|
integrate struct mbuf *lance_get __P((struct lance_softc *, int, int));
|
|
|
|
|
|
|
|
hide void lance_shutdown __P((void *));
|
|
|
|
|
|
|
|
int lance_mediachange __P((struct ifnet *));
|
|
|
|
void lance_mediastatus __P((struct ifnet *, struct ifmediareq *));
|
|
|
|
|
|
|
|
static inline u_int16_t ether_cmp __P((void *, void *));
|
|
|
|
|
2001-06-18 15:06:26 +04:00
|
|
|
void lance_stop __P((struct ifnet *, int));
|
1998-07-21 21:26:45 +04:00
|
|
|
int lance_ioctl __P((struct ifnet *, u_long, caddr_t));
|
|
|
|
void lance_watchdog __P((struct ifnet *));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare two Ether/802 addresses for equality, inlined and
|
2001-07-07 09:35:39 +04:00
|
|
|
* unrolled for speed. Use this like memcmp().
|
1998-07-21 21:26:45 +04:00
|
|
|
*
|
|
|
|
* XXX: Add <machine/inlines.h> for stuff like this?
|
|
|
|
* XXX: or maybe add it to libkern.h instead?
|
|
|
|
*
|
|
|
|
* "I'd love to have an inline assembler version of this."
|
|
|
|
* XXX: Who wanted that? mycroft? I wrote one, but this
|
|
|
|
* version in C is as good as hand-coded assembly. -gwr
|
|
|
|
*
|
|
|
|
* Please do NOT tweak this without looking at the actual
|
|
|
|
* assembly code generated before and after your tweaks!
|
|
|
|
*/
|
|
|
|
static inline u_int16_t
|
|
|
|
ether_cmp(one, two)
|
|
|
|
void *one, *two;
|
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
u_int16_t *a = (u_short *) one;
|
|
|
|
u_int16_t *b = (u_short *) two;
|
|
|
|
u_int16_t diff;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
#ifdef m68k
|
|
|
|
/*
|
|
|
|
* The post-increment-pointer form produces the best
|
|
|
|
* machine code for m68k. This was carefully tuned
|
|
|
|
* so it compiles to just 8 short (2-byte) op-codes!
|
|
|
|
*/
|
|
|
|
diff = *a++ - *b++;
|
|
|
|
diff |= *a++ - *b++;
|
|
|
|
diff |= *a++ - *b++;
|
|
|
|
#else
|
|
|
|
/*
|
|
|
|
* Most modern CPUs do better with a single expresion.
|
|
|
|
* Note that short-cut evaluation is NOT helpful here,
|
|
|
|
* because it just makes the code longer, not faster!
|
|
|
|
*/
|
|
|
|
diff = (a[0] - b[0]) | (a[1] - b[1]) | (a[2] - b[2]);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (diff);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ETHER_CMP ether_cmp
|
|
|
|
|
|
|
|
#ifdef LANCE_REVC_BUG
|
|
|
|
/* Make sure this is short-aligned, for ether_cmp(). */
|
|
|
|
static u_int16_t bcast_enaddr[3] = { ~0, ~0, ~0 };
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_config(sc)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
{
|
2001-04-27 21:08:02 +04:00
|
|
|
int i, nbuf;
|
2001-06-18 15:06:26 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
/* Initialize ifnet structure. */
|
2001-07-07 19:59:37 +04:00
|
|
|
strcpy(ifp->if_xname, sc->sc_dev.dv_xname);
|
1998-07-21 21:26:45 +04:00
|
|
|
ifp->if_softc = sc;
|
|
|
|
ifp->if_start = sc->sc_start;
|
|
|
|
ifp->if_ioctl = lance_ioctl;
|
|
|
|
ifp->if_watchdog = lance_watchdog;
|
2001-06-18 15:06:26 +04:00
|
|
|
ifp->if_init = lance_init;
|
|
|
|
ifp->if_stop = lance_stop;
|
1998-07-21 21:26:45 +04:00
|
|
|
ifp->if_flags =
|
|
|
|
IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
|
|
|
|
#ifdef LANCE_REVC_BUG
|
|
|
|
ifp->if_flags &= ~IFF_MULTICAST;
|
|
|
|
#endif
|
2000-12-14 09:27:23 +03:00
|
|
|
IFQ_SET_READY(&ifp->if_snd);
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
/* Initialize ifmedia structures. */
|
|
|
|
ifmedia_init(&sc->sc_media, 0, lance_mediachange, lance_mediastatus);
|
|
|
|
if (sc->sc_supmedia != NULL) {
|
|
|
|
for (i = 0; i < sc->sc_nsupmedia; i++)
|
|
|
|
ifmedia_add(&sc->sc_media, sc->sc_supmedia[i],
|
|
|
|
0, NULL);
|
|
|
|
ifmedia_set(&sc->sc_media, sc->sc_defaultmedia);
|
|
|
|
} else {
|
|
|
|
ifmedia_add(&sc->sc_media, IFM_ETHER|IFM_MANUAL, 0, NULL);
|
|
|
|
ifmedia_set(&sc->sc_media, IFM_ETHER|IFM_MANUAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (sc->sc_memsize) {
|
|
|
|
case 8192:
|
|
|
|
sc->sc_nrbuf = 4;
|
|
|
|
sc->sc_ntbuf = 1;
|
|
|
|
break;
|
|
|
|
case 16384:
|
|
|
|
sc->sc_nrbuf = 8;
|
|
|
|
sc->sc_ntbuf = 2;
|
|
|
|
break;
|
|
|
|
case 32768:
|
|
|
|
sc->sc_nrbuf = 16;
|
|
|
|
sc->sc_ntbuf = 4;
|
|
|
|
break;
|
|
|
|
case 65536:
|
|
|
|
sc->sc_nrbuf = 32;
|
|
|
|
sc->sc_ntbuf = 8;
|
|
|
|
break;
|
|
|
|
case 131072:
|
|
|
|
sc->sc_nrbuf = 64;
|
|
|
|
sc->sc_ntbuf = 16;
|
|
|
|
break;
|
1998-12-09 10:33:59 +03:00
|
|
|
case 262144:
|
|
|
|
sc->sc_nrbuf = 128;
|
|
|
|
sc->sc_ntbuf = 32;
|
|
|
|
break;
|
1998-07-21 21:26:45 +04:00
|
|
|
default:
|
2001-04-27 21:08:02 +04:00
|
|
|
/* weird memory size; cope with it */
|
|
|
|
nbuf = sc->sc_memsize / LEBLEN;
|
|
|
|
sc->sc_ntbuf = nbuf / 5;
|
|
|
|
sc->sc_nrbuf = nbuf - sc->sc_ntbuf;
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
printf(": address %s\n", ether_sprintf(sc->sc_enaddr));
|
|
|
|
printf("%s: %d receive buffers, %d transmit buffers\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->sc_nrbuf, sc->sc_ntbuf);
|
|
|
|
|
2001-06-18 15:06:26 +04:00
|
|
|
/* Make sure the chip is stopped. */
|
|
|
|
lance_stop(ifp, 0);
|
|
|
|
|
2000-10-20 13:40:26 +04:00
|
|
|
/* claim 802.1q capability */
|
|
|
|
sc->sc_ethercom.ec_capabilities |= ETHERCAP_VLAN_MTU;
|
1999-11-17 06:42:24 +03:00
|
|
|
/* Attach the interface. */
|
|
|
|
if_attach(ifp);
|
|
|
|
ether_ifattach(ifp, sc->sc_enaddr);
|
|
|
|
|
2001-06-18 15:06:26 +04:00
|
|
|
sc->sc_sh = shutdownhook_establish(lance_shutdown, ifp);
|
1998-07-21 21:26:45 +04:00
|
|
|
if (sc->sc_sh == NULL)
|
|
|
|
panic("lance_config: can't establish shutdownhook");
|
|
|
|
sc->sc_rbufaddr = malloc(sc->sc_nrbuf * sizeof(int), M_DEVBUF,
|
|
|
|
M_WAITOK);
|
|
|
|
sc->sc_tbufaddr = malloc(sc->sc_ntbuf * sizeof(int), M_DEVBUF,
|
|
|
|
M_WAITOK);
|
|
|
|
|
|
|
|
#if NRND > 0
|
|
|
|
rnd_attach_source(&sc->rnd_source, sc->sc_dev.dv_xname,
|
1999-02-28 20:08:05 +03:00
|
|
|
RND_TYPE_NET, 0);
|
1998-07-21 21:26:45 +04:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_reset(sc)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
{
|
|
|
|
int s;
|
|
|
|
|
1998-08-09 03:51:39 +04:00
|
|
|
s = splnet();
|
2001-06-18 15:06:26 +04:00
|
|
|
lance_init(&sc->sc_ethercom.ec_if);
|
1998-07-21 21:26:45 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-06-18 15:06:26 +04:00
|
|
|
lance_stop(ifp, disable)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
int disable;
|
1998-07-21 21:26:45 +04:00
|
|
|
{
|
2001-06-18 15:06:26 +04:00
|
|
|
struct lance_softc *sc = ifp->if_softc;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialization of interface; set up initialization block
|
|
|
|
* and transmit/receive descriptor rings.
|
|
|
|
*/
|
2001-06-18 15:06:26 +04:00
|
|
|
int
|
|
|
|
lance_init(ifp)
|
|
|
|
struct ifnet *ifp;
|
1998-07-21 21:26:45 +04:00
|
|
|
{
|
2001-06-18 15:06:26 +04:00
|
|
|
struct lance_softc *sc = ifp->if_softc;
|
2000-03-30 16:41:09 +04:00
|
|
|
int timo;
|
1998-07-21 21:26:45 +04:00
|
|
|
u_long a;
|
|
|
|
|
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_STOP);
|
|
|
|
DELAY(100);
|
|
|
|
|
|
|
|
/* Newer LANCE chips have a reset register */
|
|
|
|
if (sc->sc_hwreset)
|
|
|
|
(*sc->sc_hwreset)(sc);
|
|
|
|
|
|
|
|
/* Set the correct byte swapping mode, etc. */
|
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR3, sc->sc_conf3);
|
|
|
|
|
|
|
|
/* Set up LANCE init block. */
|
|
|
|
(*sc->sc_meminit)(sc);
|
|
|
|
|
|
|
|
/* Give LANCE the physical address of its init block. */
|
|
|
|
a = sc->sc_addr + LE_INITADDR(sc);
|
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR1, a);
|
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR2, a >> 16);
|
|
|
|
|
|
|
|
/* Try to initialize the LANCE. */
|
|
|
|
DELAY(100);
|
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INIT);
|
|
|
|
|
|
|
|
/* Wait for initialization to finish. */
|
|
|
|
for (timo = 100000; timo; timo--)
|
|
|
|
if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if ((*sc->sc_rdcsr)(sc, LE_CSR0) & LE_C0_IDON) {
|
|
|
|
/* Start the LANCE. */
|
2003-01-31 20:40:05 +03:00
|
|
|
(*sc->sc_wrcsr)(sc, LE_CSR0, LE_C0_INEA | LE_C0_STRT);
|
1998-07-21 21:26:45 +04:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
ifp->if_timer = 0;
|
|
|
|
(*sc->sc_start)(ifp);
|
|
|
|
} else
|
|
|
|
printf("%s: controller failed to initialize\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
if (sc->sc_hwinit)
|
|
|
|
(*sc->sc_hwinit)(sc);
|
2001-06-18 15:06:26 +04:00
|
|
|
|
|
|
|
return (0);
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routine to copy from mbuf chain to transmit buffer in
|
|
|
|
* network buffer memory.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lance_put(sc, boff, m)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
int boff;
|
2000-03-30 16:41:09 +04:00
|
|
|
struct mbuf *m;
|
1998-07-21 21:26:45 +04:00
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct mbuf *n;
|
|
|
|
int len, tlen = 0;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
for (; m; m = n) {
|
|
|
|
len = m->m_len;
|
|
|
|
if (len == 0) {
|
|
|
|
MFREE(m, n);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
(*sc->sc_copytobuf)(sc, mtod(m, caddr_t), boff, len);
|
|
|
|
boff += len;
|
|
|
|
tlen += len;
|
|
|
|
MFREE(m, n);
|
|
|
|
}
|
|
|
|
if (tlen < LEMINSIZE) {
|
|
|
|
(*sc->sc_zerobuf)(sc, boff, LEMINSIZE - tlen);
|
|
|
|
tlen = LEMINSIZE;
|
|
|
|
}
|
|
|
|
return (tlen);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull data off an interface.
|
|
|
|
* Len is length of data, with local net header stripped.
|
|
|
|
* We copy the data into mbufs. When full cluster sized units are present
|
|
|
|
* we copy into clusters.
|
|
|
|
*/
|
|
|
|
integrate struct mbuf *
|
|
|
|
lance_get(sc, boff, totlen)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
int boff, totlen;
|
|
|
|
{
|
1998-12-12 19:58:10 +03:00
|
|
|
struct mbuf *m, *m0, *newm;
|
1998-07-21 21:26:45 +04:00
|
|
|
int len;
|
|
|
|
|
1998-12-12 19:58:10 +03:00
|
|
|
MGETHDR(m0, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m0 == 0)
|
1998-07-21 21:26:45 +04:00
|
|
|
return (0);
|
2001-06-18 15:06:26 +04:00
|
|
|
m0->m_pkthdr.rcvif = &sc->sc_ethercom.ec_if;
|
1998-12-12 19:58:10 +03:00
|
|
|
m0->m_pkthdr.len = totlen;
|
1998-07-21 21:26:45 +04:00
|
|
|
len = MHLEN;
|
1998-12-12 19:58:10 +03:00
|
|
|
m = m0;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
while (totlen > 0) {
|
|
|
|
if (totlen >= MINCLSIZE) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
1998-12-12 19:58:10 +03:00
|
|
|
if ((m->m_flags & M_EXT) == 0)
|
|
|
|
goto bad;
|
1998-07-21 21:26:45 +04:00
|
|
|
len = MCLBYTES;
|
|
|
|
}
|
1998-12-12 19:58:10 +03:00
|
|
|
|
|
|
|
if (m == m0) {
|
|
|
|
caddr_t newdata = (caddr_t)
|
|
|
|
ALIGN(m->m_data + sizeof(struct ether_header)) -
|
|
|
|
sizeof(struct ether_header);
|
|
|
|
len -= newdata - m->m_data;
|
|
|
|
m->m_data = newdata;
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
1998-12-12 19:58:10 +03:00
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
m->m_len = len = min(totlen, len);
|
|
|
|
(*sc->sc_copyfrombuf)(sc, mtod(m, caddr_t), boff, len);
|
|
|
|
boff += len;
|
1998-12-12 19:58:10 +03:00
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
totlen -= len;
|
1998-12-12 19:58:10 +03:00
|
|
|
if (totlen > 0) {
|
|
|
|
MGET(newm, M_DONTWAIT, MT_DATA);
|
|
|
|
if (newm == 0)
|
|
|
|
goto bad;
|
|
|
|
len = MLEN;
|
|
|
|
m = m->m_next = newm;
|
|
|
|
}
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
1998-12-12 19:58:10 +03:00
|
|
|
return (m0);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
m_freem(m0);
|
|
|
|
return (0);
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pass a packet to the higher levels.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lance_read(sc, boff, len)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct lance_softc *sc;
|
1998-07-21 21:26:45 +04:00
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
struct mbuf *m;
|
2001-06-18 15:06:26 +04:00
|
|
|
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
|
2000-11-03 09:21:32 +03:00
|
|
|
struct ether_header *eh;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
if (len <= sizeof(struct ether_header) ||
|
2000-10-20 13:40:26 +04:00
|
|
|
len > ((sc->sc_ethercom.ec_capenable & ETHERCAP_VLAN_MTU) ?
|
|
|
|
ETHER_VLAN_ENCAP_LEN + ETHERMTU + sizeof(struct ether_header) :
|
|
|
|
ETHERMTU + sizeof(struct ether_header))) {
|
1998-07-21 21:26:45 +04:00
|
|
|
#ifdef LEDEBUG
|
|
|
|
printf("%s: invalid packet size %d; dropping\n",
|
|
|
|
sc->sc_dev.dv_xname, len);
|
|
|
|
#endif
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Pull packet off interface. */
|
|
|
|
m = lance_get(sc, boff, len);
|
|
|
|
if (m == 0) {
|
|
|
|
ifp->if_ierrors++;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ifp->if_ipackets++;
|
|
|
|
|
2002-09-03 18:48:16 +04:00
|
|
|
eh = mtod(m, struct ether_header *);
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
#ifdef LANCE_REVC_BUG
|
|
|
|
/*
|
|
|
|
* The old LANCE (Rev. C) chips have a bug which causes
|
|
|
|
* garbage to be inserted in front of the received packet.
|
|
|
|
* The work-around is to ignore packets with an invalid
|
|
|
|
* destination address (garbage will usually not match).
|
|
|
|
* Of course, this precludes multicast support...
|
|
|
|
*/
|
|
|
|
if (ETHER_CMP(eh->ether_dhost, sc->sc_enaddr) &&
|
|
|
|
ETHER_CMP(eh->ether_dhost, bcast_enaddr)) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-09-03 18:48:16 +04:00
|
|
|
/*
|
|
|
|
* Some lance device does not present IFF_SIMPLEX behavior on multicast
|
|
|
|
* packets. Make sure to drop it if it is from ourselves.
|
|
|
|
*/
|
|
|
|
if (!ETHER_CMP(eh->ether_shost, sc->sc_enaddr)) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* Check if there's a BPF listener on this interface.
|
|
|
|
* If so, hand off the raw packet to BPF.
|
|
|
|
*/
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m);
|
|
|
|
#endif
|
|
|
|
|
1999-05-19 03:52:51 +04:00
|
|
|
/* Pass the packet up. */
|
|
|
|
(*ifp->if_input)(ifp, m);
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#undef ifp
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_watchdog(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct lance_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
|
|
|
|
++ifp->if_oerrors;
|
|
|
|
|
|
|
|
lance_reset(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
lance_mediachange(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
|
|
|
struct lance_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
if (sc->sc_mediachange)
|
|
|
|
return ((*sc->sc_mediachange)(sc));
|
1999-04-30 22:15:04 +04:00
|
|
|
return (0);
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_mediastatus(ifp, ifmr)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
struct ifmediareq *ifmr;
|
|
|
|
{
|
|
|
|
struct lance_softc *sc = ifp->if_softc;
|
|
|
|
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ifmr->ifm_status = IFM_AVALID;
|
|
|
|
if (sc->sc_havecarrier)
|
|
|
|
ifmr->ifm_status |= IFM_ACTIVE;
|
|
|
|
|
|
|
|
if (sc->sc_mediastatus)
|
|
|
|
(*sc->sc_mediastatus)(sc, ifmr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
lance_ioctl(ifp, cmd, data)
|
2000-03-30 16:41:09 +04:00
|
|
|
struct ifnet *ifp;
|
1998-07-21 21:26:45 +04:00
|
|
|
u_long cmd;
|
|
|
|
caddr_t data;
|
|
|
|
{
|
2000-03-30 16:41:09 +04:00
|
|
|
struct lance_softc *sc = ifp->if_softc;
|
1998-07-21 21:26:45 +04:00
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
int s, error = 0;
|
|
|
|
|
1998-08-09 03:51:39 +04:00
|
|
|
s = splnet();
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
2001-06-18 15:06:26 +04:00
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
error = ether_ioctl(ifp, cmd, data);
|
1998-07-21 21:26:45 +04:00
|
|
|
break;
|
|
|
|
|
|
|
|
#if defined(CCITT) && defined(LLC)
|
|
|
|
case SIOCSIFCONF_X25:
|
2001-06-19 11:19:35 +04:00
|
|
|
{
|
|
|
|
struct ifaddr *ifa = (struct ifaddr *) data;
|
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
ifa->ifa_rtrequest = cons_rtrequest; /* XXX */
|
|
|
|
error = x25_llcglue(PRC_IFUP, ifa->ifa_addr);
|
|
|
|
if (error == 0)
|
2001-06-18 15:06:26 +04:00
|
|
|
lance_init(&sc->sc_ethercom.ec_if);
|
1998-07-21 21:26:45 +04:00
|
|
|
break;
|
2001-06-19 11:19:35 +04:00
|
|
|
}
|
1998-07-21 21:26:45 +04:00
|
|
|
#endif /* CCITT && LLC */
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
error = (cmd == SIOCADDMULTI) ?
|
|
|
|
ether_addmulti(ifr, &sc->sc_ethercom) :
|
|
|
|
ether_delmulti(ifr, &sc->sc_ethercom);
|
|
|
|
|
|
|
|
if (error == ENETRESET) {
|
|
|
|
/*
|
|
|
|
* Multicast list has changed; set the hardware filter
|
|
|
|
* accordingly.
|
|
|
|
*/
|
|
|
|
lance_reset(sc);
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCGIFMEDIA:
|
|
|
|
case SIOCSIFMEDIA:
|
|
|
|
error = ifmedia_ioctl(ifp, ifr, &sc->sc_media, cmd);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
hide void
|
|
|
|
lance_shutdown(arg)
|
|
|
|
void *arg;
|
|
|
|
{
|
|
|
|
|
2001-06-18 15:06:26 +04:00
|
|
|
lance_stop((struct ifnet *)arg, 0);
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the logical address filter.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
lance_setladrf(ac, af)
|
|
|
|
struct ethercom *ac;
|
|
|
|
u_int16_t *af;
|
|
|
|
{
|
|
|
|
struct ifnet *ifp = &ac->ec_if;
|
|
|
|
struct ether_multi *enm;
|
2000-03-30 16:41:09 +04:00
|
|
|
u_int32_t crc;
|
1998-07-21 21:26:45 +04:00
|
|
|
struct ether_multistep step;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up multicast address filter by passing all multicast addresses
|
|
|
|
* through a crc generator, and then using the high order 6 bits as an
|
|
|
|
* index into the 64 bit logical address filter. The high order bit
|
|
|
|
* selects the word, while the rest of the bits select the bit within
|
|
|
|
* the word.
|
|
|
|
*/
|
|
|
|
|
|
|
|
if (ifp->if_flags & IFF_PROMISC)
|
|
|
|
goto allmulti;
|
|
|
|
|
|
|
|
af[0] = af[1] = af[2] = af[3] = 0x0000;
|
|
|
|
ETHER_FIRST_MULTI(step, ac, enm);
|
|
|
|
while (enm != NULL) {
|
|
|
|
if (ETHER_CMP(enm->enm_addrlo, enm->enm_addrhi)) {
|
|
|
|
/*
|
|
|
|
* We must listen to a range of multicast addresses.
|
|
|
|
* For now, just accept all multicasts, rather than
|
|
|
|
* trying to set only those filter bits needed to match
|
|
|
|
* the range. (At this time, the only use of address
|
|
|
|
* ranges is for IP multicast routing, for which the
|
|
|
|
* range is big enough to require all bits set.)
|
|
|
|
*/
|
|
|
|
goto allmulti;
|
|
|
|
}
|
|
|
|
|
2000-05-12 20:45:42 +04:00
|
|
|
crc = ether_crc32_le(enm->enm_addrlo, ETHER_ADDR_LEN);
|
|
|
|
|
1998-07-21 21:26:45 +04:00
|
|
|
/* Just want the 6 most significant bits. */
|
|
|
|
crc >>= 26;
|
|
|
|
|
|
|
|
/* Set the corresponding bit in the filter. */
|
|
|
|
af[crc >> 4] |= 1 << (crc & 0xf);
|
|
|
|
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
ifp->if_flags &= ~IFF_ALLMULTI;
|
|
|
|
return;
|
|
|
|
|
|
|
|
allmulti:
|
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
af[0] = af[1] = af[2] = af[3] = 0xffff;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Routines for accessing the transmit and receive buffers.
|
|
|
|
* The various CPU and adapter configurations supported by this
|
|
|
|
* driver require three different access methods for buffers
|
|
|
|
* and descriptors:
|
|
|
|
* (1) contig (contiguous data; no padding),
|
|
|
|
* (2) gap2 (two bytes of data followed by two bytes of padding),
|
|
|
|
* (3) gap16 (16 bytes of data followed by 16 bytes of padding).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* contig: contiguous data with no padding.
|
|
|
|
*
|
|
|
|
* Buffers may have any alignment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_copytobuf_contig(sc, from, boff, len)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
void *from;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
|
|
|
|
|
|
|
/*
|
2001-07-07 19:59:37 +04:00
|
|
|
* Just call memcpy() to do the work.
|
1998-07-21 21:26:45 +04:00
|
|
|
*/
|
2001-07-07 19:59:37 +04:00
|
|
|
memcpy(buf + boff, from, len);
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_copyfrombuf_contig(sc, to, boff, len)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
void *to;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
|
|
|
|
|
|
|
/*
|
2001-07-07 19:59:37 +04:00
|
|
|
* Just call memcpy() to do the work.
|
1998-07-21 21:26:45 +04:00
|
|
|
*/
|
2001-07-07 19:59:37 +04:00
|
|
|
memcpy(to, buf + boff, len);
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_zerobuf_contig(sc, boff, len)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
|
|
|
|
|
|
|
/*
|
2001-07-07 20:13:44 +04:00
|
|
|
* Just let memset() do the work
|
1998-07-21 21:26:45 +04:00
|
|
|
*/
|
2001-07-07 20:13:44 +04:00
|
|
|
memset(buf + boff, 0, len);
|
1998-07-21 21:26:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Examples only; duplicate these and tweak (if necessary) in
|
|
|
|
* machine-specific front-ends.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gap2: two bytes of data followed by two bytes of pad.
|
|
|
|
*
|
|
|
|
* Buffers must be 4-byte aligned. The code doesn't worry about
|
|
|
|
* doing an extra byte.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_copytobuf_gap2(sc, fromv, boff, len)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
void *fromv;
|
|
|
|
int boff;
|
2000-03-30 16:41:09 +04:00
|
|
|
int len;
|
1998-07-21 21:26:45 +04:00
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
2000-03-30 16:41:09 +04:00
|
|
|
caddr_t from = fromv;
|
|
|
|
volatile u_int16_t *bptr;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
if (boff & 0x1) {
|
|
|
|
/* handle unaligned first byte */
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + (boff - 1);
|
|
|
|
*bptr = (*from++ << 8) | (*bptr & 0xff);
|
|
|
|
bptr += 2;
|
|
|
|
len--;
|
|
|
|
} else
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + boff;
|
|
|
|
while (len > 1) {
|
|
|
|
*bptr = (from[1] << 8) | (from[0] & 0xff);
|
|
|
|
bptr += 2;
|
|
|
|
from += 2;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
if (len == 1)
|
|
|
|
*bptr = (u_int16_t)*from;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_copyfrombuf_gap2(sc, tov, boff, len)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
void *tov;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
2000-03-30 16:41:09 +04:00
|
|
|
caddr_t to = tov;
|
|
|
|
volatile u_int16_t *bptr;
|
|
|
|
u_int16_t tmp;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
if (boff & 0x1) {
|
|
|
|
/* handle unaligned first byte */
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + (boff - 1);
|
|
|
|
*to++ = (*bptr >> 8) & 0xff;
|
|
|
|
bptr += 2;
|
|
|
|
len--;
|
|
|
|
} else
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + boff;
|
|
|
|
while (len > 1) {
|
|
|
|
tmp = *bptr;
|
|
|
|
*to++ = tmp & 0xff;
|
|
|
|
*to++ = (tmp >> 8) & 0xff;
|
|
|
|
bptr += 2;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
if (len == 1)
|
|
|
|
*to = *bptr & 0xff;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_zerobuf_gap2(sc, boff, len)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
2000-03-30 16:41:09 +04:00
|
|
|
volatile u_int16_t *bptr;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
if ((unsigned)boff & 0x1) {
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + (boff - 1);
|
|
|
|
*bptr &= 0xff;
|
|
|
|
bptr += 2;
|
|
|
|
len--;
|
|
|
|
} else
|
|
|
|
bptr = ((volatile u_int16_t *)buf) + boff;
|
|
|
|
while (len > 0) {
|
|
|
|
*bptr = 0;
|
|
|
|
bptr += 2;
|
|
|
|
len -= 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* gap16: 16 bytes of data followed by 16 bytes of pad.
|
|
|
|
*
|
|
|
|
* Buffers must be 32-byte aligned.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_copytobuf_gap16(sc, fromv, boff, len)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
void *fromv;
|
|
|
|
int boff;
|
2000-03-30 16:41:09 +04:00
|
|
|
int len;
|
1998-07-21 21:26:45 +04:00
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
2000-03-30 16:41:09 +04:00
|
|
|
caddr_t from = fromv;
|
|
|
|
caddr_t bptr;
|
|
|
|
int xfer;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
bptr = buf + ((boff << 1) & ~0x1f);
|
|
|
|
boff &= 0xf;
|
|
|
|
xfer = min(len, 16 - boff);
|
|
|
|
while (len > 0) {
|
2001-07-07 19:59:37 +04:00
|
|
|
memcpy(bptr + boff, from, xfer);
|
1998-07-21 21:26:45 +04:00
|
|
|
from += xfer;
|
|
|
|
bptr += 32;
|
|
|
|
boff = 0;
|
|
|
|
len -= xfer;
|
|
|
|
xfer = min(len, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_copyfrombuf_gap16(sc, tov, boff, len)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
void *tov;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
2000-03-30 16:41:09 +04:00
|
|
|
caddr_t to = tov;
|
|
|
|
caddr_t bptr;
|
|
|
|
int xfer;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
bptr = buf + ((boff << 1) & ~0x1f);
|
|
|
|
boff &= 0xf;
|
|
|
|
xfer = min(len, 16 - boff);
|
|
|
|
while (len > 0) {
|
2001-07-07 19:59:37 +04:00
|
|
|
memcpy(to, bptr + boff, xfer);
|
1998-07-21 21:26:45 +04:00
|
|
|
to += xfer;
|
|
|
|
bptr += 32;
|
|
|
|
boff = 0;
|
|
|
|
len -= xfer;
|
|
|
|
xfer = min(len, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
lance_zerobuf_gap16(sc, boff, len)
|
|
|
|
struct lance_softc *sc;
|
|
|
|
int boff, len;
|
|
|
|
{
|
|
|
|
volatile caddr_t buf = sc->sc_mem;
|
2000-03-30 16:41:09 +04:00
|
|
|
caddr_t bptr;
|
|
|
|
int xfer;
|
1998-07-21 21:26:45 +04:00
|
|
|
|
|
|
|
bptr = buf + ((boff << 1) & ~0x1f);
|
|
|
|
boff &= 0xf;
|
|
|
|
xfer = min(len, 16 - boff);
|
|
|
|
while (len > 0) {
|
2001-07-07 20:13:44 +04:00
|
|
|
memset(bptr + boff, 0, xfer);
|
1998-07-21 21:26:45 +04:00
|
|
|
bptr += 32;
|
|
|
|
boff = 0;
|
|
|
|
len -= xfer;
|
|
|
|
xfer = min(len, 16);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* Example only */
|