1997-03-15 21:09:08 +03:00
|
|
|
/* $NetBSD: if_ie.c,v 1.20 1997/03/15 18:10:49 is Exp $ */
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*-
|
1995-01-27 02:23:34 +03:00
|
|
|
* Copyright (c) 1993, 1994, 1995 Charles Hannum.
|
1994-12-12 21:58:45 +03:00
|
|
|
* Copyright (c) 1992, 1993, University of Vermont and State
|
|
|
|
* Agricultural College.
|
|
|
|
* Copyright (c) 1992, 1993, Garrett A. Wollman.
|
|
|
|
*
|
|
|
|
* Portions:
|
1995-01-27 02:23:34 +03:00
|
|
|
* Copyright (c) 1994, 1995, Rafal K. Boni
|
1994-12-12 21:58:45 +03:00
|
|
|
* Copyright (c) 1990, 1991, William F. Jolitz
|
|
|
|
* Copyright (c) 1990, The Regents of the University of California
|
|
|
|
*
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 Charles Hannum, by the
|
|
|
|
* University of Vermont and State Agricultural College and Garrett A.
|
|
|
|
* Wollman, by William F. Jolitz, and by the University of California,
|
|
|
|
* Berkeley, Lawrence Berkeley Laboratory, and its contributors.
|
|
|
|
* 4. Neither the names of the Universities nor the names of the authors
|
|
|
|
* 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 UNIVERSITY OR AUTHORS 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.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Intel 82586 Ethernet chip
|
|
|
|
* Register, bit, and structure definitions.
|
|
|
|
*
|
|
|
|
* Original StarLAN driver written by Garrett Wollman with reference to the
|
|
|
|
* Clarkson Packet Driver code for this chip written by Russ Nelson and others.
|
|
|
|
*
|
|
|
|
* BPF support code taken from hpdev/if_le.c, supplied with tcpdump.
|
|
|
|
*
|
|
|
|
* 3C507 support is loosely based on code donated to NetBSD by Rafal Boni.
|
|
|
|
*
|
|
|
|
* Majorly cleaned up and 3C507 code merged by Charles Hannum.
|
|
|
|
*
|
1995-01-27 02:23:34 +03:00
|
|
|
* Converted to SUN ie driver by Charles D. Cranor,
|
|
|
|
* October 1994, January 1995.
|
|
|
|
* This sun version based on i386 version 1.30.
|
1997-02-13 23:48:36 +03:00
|
|
|
* [ see sys/dev/isa/if_ie.c ]
|
1994-12-12 21:58:45 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The i82586 is a very painful chip, found in sun3's, sun-4/100's
|
|
|
|
* sun-4/200's, and VME based suns. The byte order is all wrong for a
|
|
|
|
* SUN, making life difficult. Programming this chip is mostly the same,
|
|
|
|
* but certain details differ from system to system. This driver is
|
|
|
|
* written so that different "ie" interfaces can be controled by the same
|
|
|
|
* driver.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
Mode of operation:
|
|
|
|
|
|
|
|
We run the 82586 in a standard Ethernet mode. We keep NFRAMES
|
|
|
|
received frame descriptors around for the receiver to use, and
|
|
|
|
NRXBUF associated receive buffer descriptors, both in a circular
|
|
|
|
list. Whenever a frame is received, we rotate both lists as
|
|
|
|
necessary. (The 586 treats both lists as a simple queue.) We also
|
|
|
|
keep a transmit command around so that packets can be sent off
|
|
|
|
quickly.
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
We configure the adapter in AL-LOC = 1 mode, which means that the
|
|
|
|
Ethernet/802.3 MAC header is placed at the beginning of the receive
|
|
|
|
buffer rather than being split off into various fields in the RFD.
|
|
|
|
This also means that we must include this header in the transmit
|
|
|
|
buffer as well.
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
By convention, all transmit commands, and only transmit commands,
|
|
|
|
shall have the I (IE_CMD_INTR) bit set in the command. This way,
|
|
|
|
when an interrupt arrives at ieintr(), it is immediately possible
|
|
|
|
to tell what precisely caused it. ANY OTHER command-sending
|
1995-12-24 05:29:35 +03:00
|
|
|
routines should run at splnet(), and should post an acknowledgement
|
1994-12-12 21:58:45 +03:00
|
|
|
to every interrupt they generate.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "bpfilter.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/buf.h>
|
|
|
|
#include <sys/protosw.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/ioctl.h>
|
1995-01-27 02:23:34 +03:00
|
|
|
#include <sys/errno.h>
|
1994-12-12 21:58:45 +03:00
|
|
|
#include <sys/syslog.h>
|
1995-01-27 02:23:34 +03:00
|
|
|
#include <sys/device.h>
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
#include <net/if.h>
|
|
|
|
#include <net/if_types.h>
|
|
|
|
#include <net/if_dl.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <net/if_ether.h>
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
#include <net/bpf.h>
|
|
|
|
#include <net/bpfdesc.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef INET
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/in_systm.h>
|
|
|
|
#include <netinet/in_var.h>
|
|
|
|
#include <netinet/ip.h>
|
1997-03-15 21:09:08 +03:00
|
|
|
#include <netinet/if_inarp.h>
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NS
|
|
|
|
#include <netns/ns.h>
|
|
|
|
#include <netns/ns_if.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
|
1996-12-18 00:10:35 +03:00
|
|
|
#include <machine/autoconf.h>
|
|
|
|
#include <machine/cpu.h>
|
|
|
|
#include <machine/pmap.h>
|
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
/*
|
|
|
|
* ugly byte-order hack for SUNs
|
|
|
|
*/
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
#define XSWAP(y) ( (((y)&0xff00) >> 8) | (((y)&0xff) << 8) )
|
1996-12-18 00:10:35 +03:00
|
|
|
#define SWAP(x) ((u_short)(XSWAP((u_short)(x))))
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
#include "i82586.h"
|
1996-03-27 01:04:14 +03:00
|
|
|
#include "if_iereg.h"
|
|
|
|
#include "if_ievar.h"
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-28 20:17:22 +03:00
|
|
|
/* #define IEDEBUG XXX */
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* IED: ie debug flags
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define IED_RINT 0x01
|
|
|
|
#define IED_TINT 0x02
|
|
|
|
#define IED_RNR 0x04
|
|
|
|
#define IED_CNA 0x08
|
|
|
|
#define IED_READFRAME 0x10
|
1997-02-13 23:48:36 +03:00
|
|
|
#define IED_ENQ 0x20
|
|
|
|
#define IED_XMIT 0x40
|
|
|
|
#define IED_ALL 0x7f
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
#define ETHER_MIN_LEN 64
|
|
|
|
#define ETHER_MAX_LEN 1518
|
|
|
|
#define ETHER_ADDR_LEN 6
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
#ifdef IEDEBUG
|
|
|
|
#define inline /* not */
|
|
|
|
void print_rbd __P((volatile struct ie_recv_buf_desc *));
|
|
|
|
int in_ierint = 0;
|
|
|
|
int in_ietint = 0;
|
|
|
|
int ie_debug_flags = 0;
|
|
|
|
#endif
|
|
|
|
|
1997-02-28 20:17:22 +03:00
|
|
|
/* XXX - Skip TDR for now - it always complains... */
|
|
|
|
int ie_run_tdr = 0;
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
static void iewatchdog __P((struct ifnet *));
|
|
|
|
static int ieinit __P((struct ie_softc *));
|
|
|
|
static int ieioctl __P((struct ifnet *, u_long, caddr_t));
|
|
|
|
static void iestart __P((struct ifnet *));
|
|
|
|
static void iereset __P((struct ie_softc *));
|
|
|
|
static int ie_setupram __P((struct ie_softc *sc));
|
1996-12-18 00:10:35 +03:00
|
|
|
|
|
|
|
static int cmd_and_wait __P((struct ie_softc *, int, void *, int));
|
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
static void ie_drop_packet_buffer __P((struct ie_softc *));
|
1996-12-18 00:10:35 +03:00
|
|
|
static void ie_readframe __P((struct ie_softc *, int));
|
1997-02-13 23:48:36 +03:00
|
|
|
static inline void ie_setup_config __P((struct ie_config_cmd *, int, int));
|
1996-12-18 00:10:35 +03:00
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
static void ierint __P((struct ie_softc *));
|
1996-12-18 00:10:35 +03:00
|
|
|
static void iestop __P((struct ie_softc *));
|
1995-01-27 02:23:34 +03:00
|
|
|
static void ietint __P((struct ie_softc *));
|
1996-12-18 00:10:35 +03:00
|
|
|
static void iexmit __P((struct ie_softc *));
|
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
static int mc_setup __P((struct ie_softc *, void *));
|
|
|
|
static void mc_reset __P((struct ie_softc *));
|
1996-12-18 00:10:35 +03:00
|
|
|
static void run_tdr __P((struct ie_softc *, struct ie_tdr_cmd *));
|
1997-02-13 23:48:36 +03:00
|
|
|
static void iememinit __P((struct ie_softc *));
|
|
|
|
|
|
|
|
static inline char * Align __P((char *));
|
|
|
|
static inline u_int Swap32 __P((u_int x));
|
|
|
|
static inline u_int vtop24 __P((struct ie_softc *, void *));
|
|
|
|
static inline u_short vtop16sw __P((struct ie_softc *, void *));
|
1996-12-18 00:10:35 +03:00
|
|
|
|
|
|
|
static inline void ie_ack __P((struct ie_softc *, u_int));
|
|
|
|
static inline u_short ether_cmp __P((u_char *, u_char *));
|
|
|
|
static inline int check_eh __P((struct ie_softc *,
|
|
|
|
struct ether_header *eh, int *));
|
|
|
|
static inline int ie_buflen __P((struct ie_softc *, int));
|
|
|
|
static inline int ie_packet_len __P((struct ie_softc *));
|
1997-02-13 23:48:36 +03:00
|
|
|
static inline struct mbuf * ieget __P((struct ie_softc *sc,
|
|
|
|
struct ether_header *ehp, int *to_bpf));
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1996-03-17 05:00:30 +03:00
|
|
|
|
|
|
|
struct cfdriver ie_cd = {
|
|
|
|
NULL, "ie", DV_IFNET
|
1994-12-12 21:58:45 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Here are a few useful functions. We could have done these as macros,
|
|
|
|
* but since we have the inline facility, it makes sense to use that
|
|
|
|
* instead.
|
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
|
|
|
|
/* KVA to 24 bit device address */
|
|
|
|
static inline u_int
|
|
|
|
vtop24(sc, ptr)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
void *ptr;
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
1997-02-13 23:48:36 +03:00
|
|
|
u_int pa;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
pa = ((caddr_t)ptr) - sc->sc_iobase;
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
if (pa & ~0xffFFff)
|
|
|
|
panic("ie:vtop24");
|
|
|
|
#endif
|
|
|
|
return (pa);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* KVA to 16 bit offset, swapped */
|
|
|
|
static inline u_short
|
|
|
|
vtop16sw(sc, ptr)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
void *ptr;
|
|
|
|
{
|
|
|
|
u_int pa;
|
|
|
|
|
|
|
|
pa = ((caddr_t)ptr) - sc->sc_maddr;
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
if (pa & ~0xFFff)
|
|
|
|
panic("ie:vtop16");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return (SWAP(pa));
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline u_int
|
|
|
|
Swap32(x)
|
|
|
|
u_int x;
|
|
|
|
{
|
|
|
|
u_int y;
|
|
|
|
|
|
|
|
y = x & 0xFF;
|
|
|
|
y <<= 8; x >>= 8;
|
|
|
|
y |= x & 0xFF;
|
|
|
|
y <<= 8; x >>= 8;
|
|
|
|
y |= x & 0xFF;
|
|
|
|
y <<= 8; x >>= 8;
|
|
|
|
y |= x & 0xFF;
|
|
|
|
|
|
|
|
return (y);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline char *
|
1994-12-12 21:58:45 +03:00
|
|
|
Align(ptr)
|
|
|
|
caddr_t ptr;
|
|
|
|
{
|
|
|
|
u_long l = (u_long)ptr;
|
|
|
|
|
|
|
|
l = (l + 3) & ~3L;
|
1997-02-13 23:48:36 +03:00
|
|
|
return ((char *)l);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
static inline void
|
|
|
|
ie_ack(sc, mask)
|
|
|
|
struct ie_softc *sc;
|
1997-02-13 23:48:36 +03:00
|
|
|
u_int mask;
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
|
|
|
volatile struct ie_sys_ctl_block *scb = sc->scb;
|
|
|
|
|
1996-12-18 00:10:35 +03:00
|
|
|
cmd_and_wait(sc, scb->ie_status & mask, 0, 0);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Taken almost exactly from Bill's if_is.c,
|
|
|
|
* then modified beyond recognition...
|
|
|
|
*/
|
|
|
|
void
|
1996-03-26 17:38:29 +03:00
|
|
|
ie_attach(sc)
|
|
|
|
struct ie_softc *sc;
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
|
|
|
struct ifnet *ifp = &sc->sc_if;
|
|
|
|
|
1996-03-26 17:38:29 +03:00
|
|
|
/* MD code has done its part before calling this. */
|
1997-02-13 23:48:36 +03:00
|
|
|
printf(": macaddr %s\n", ether_sprintf(sc->sc_addr));
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/*
|
|
|
|
* Compute number of transmit and receive buffers.
|
|
|
|
* Tx buffers take 1536 bytes, and fixed in number.
|
|
|
|
* Rx buffers are 512 bytes each, variable number.
|
|
|
|
* Need at least 1 frame for each 3 rx buffers.
|
|
|
|
* The ratio 3bufs:2frames is a compromise.
|
|
|
|
*/
|
|
|
|
sc->ntxbuf = NTXBUF; /* XXX - Fix me... */
|
|
|
|
switch (sc->sc_msize) {
|
|
|
|
case 16384:
|
|
|
|
sc->nframes = 8 * 4;
|
|
|
|
sc->nrxbuf = 8 * 6;
|
|
|
|
break;
|
|
|
|
case 32768:
|
|
|
|
sc->nframes = 16 * 4;
|
|
|
|
sc->nrxbuf = 16 * 6;
|
|
|
|
break;
|
|
|
|
case 65536:
|
|
|
|
sc->nframes = 32 * 4;
|
|
|
|
sc->nrxbuf = 32 * 6;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
sc->nframes = 0;
|
|
|
|
}
|
|
|
|
if (sc->nframes > MXFRAMES)
|
|
|
|
sc->nframes = MXFRAMES;
|
|
|
|
if (sc->nrxbuf > MXRXBUF)
|
|
|
|
sc->nrxbuf = MXRXBUF;
|
1996-03-26 17:38:29 +03:00
|
|
|
|
1997-02-28 20:17:22 +03:00
|
|
|
#ifdef IEDEBUG
|
1997-02-13 23:48:36 +03:00
|
|
|
printf("%s: %dK memory, %d tx frames, %d rx frames, %d rx bufs\n",
|
|
|
|
sc->sc_dev.dv_xname, (sc->sc_msize >> 10),
|
|
|
|
sc->ntxbuf, sc->nframes, sc->nrxbuf);
|
1997-02-28 20:17:22 +03:00
|
|
|
#endif
|
1996-03-26 17:38:29 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
if ((sc->nframes <= 0) || (sc->nrxbuf <= 0))
|
|
|
|
panic("ie_attach: weird memory size");
|
1996-03-26 17:38:29 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
/*
|
1996-03-26 17:38:29 +03:00
|
|
|
* Setup RAM for transmit/receive
|
1994-12-12 21:58:45 +03:00
|
|
|
*/
|
|
|
|
if (ie_setupram(sc) == 0) {
|
1996-10-13 07:47:25 +04:00
|
|
|
printf(": RAM CONFIG FAILED!\n");
|
1994-12-12 21:58:45 +03:00
|
|
|
/* XXX should reclaim resources? */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize and attach S/W interface
|
|
|
|
*/
|
1996-05-07 05:35:48 +04:00
|
|
|
bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ);
|
|
|
|
ifp->if_softc = sc;
|
1994-12-12 21:58:45 +03:00
|
|
|
ifp->if_start = iestart;
|
|
|
|
ifp->if_ioctl = ieioctl;
|
|
|
|
ifp->if_watchdog = iewatchdog;
|
1995-04-11 10:03:36 +04:00
|
|
|
ifp->if_flags =
|
|
|
|
IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/* Attach the interface. */
|
|
|
|
if_attach(ifp);
|
1997-03-15 21:09:08 +03:00
|
|
|
ether_ifattach(ifp, sc->sc_addr);
|
1994-12-12 21:58:45 +03:00
|
|
|
#if NBPFILTER > 0
|
1995-04-11 10:03:36 +04:00
|
|
|
bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB, sizeof(struct ether_header));
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/*
|
|
|
|
* Setup IE's ram space.
|
|
|
|
*/
|
|
|
|
static int
|
|
|
|
ie_setupram(sc)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
|
|
|
volatile struct ie_sys_conf_ptr *scp;
|
|
|
|
volatile struct ie_int_sys_conf_ptr *iscp;
|
|
|
|
volatile struct ie_sys_ctl_block *scb;
|
|
|
|
int off;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate from end of buffer space for
|
|
|
|
* ISCP, SCB, and other small stuff.
|
|
|
|
*/
|
|
|
|
off = sc->buf_area_sz;
|
|
|
|
off &= ~3;
|
|
|
|
|
|
|
|
/* SCP (address already chosen). */
|
|
|
|
scp = sc->scp;
|
|
|
|
(sc->sc_bzero)((char *) scp, sizeof(*scp));
|
|
|
|
|
|
|
|
/* ISCP */
|
|
|
|
off -= sizeof(*iscp);
|
|
|
|
iscp = (volatile void *) (sc->buf_area + off);
|
|
|
|
(sc->sc_bzero)((char *) iscp, sizeof(*iscp));
|
|
|
|
sc->iscp = iscp;
|
|
|
|
|
|
|
|
/* SCB */
|
|
|
|
off -= sizeof(*scb);
|
|
|
|
scb = (volatile void *) (sc->buf_area + off);
|
|
|
|
(sc->sc_bzero)((char *) scb, sizeof(*scb));
|
|
|
|
sc->scb = scb;
|
|
|
|
|
|
|
|
/* Remainder is for buffers, etc. */
|
|
|
|
sc->buf_area_sz = off;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now fill in the structures we just allocated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* SCP: main thing is 24-bit ptr to ISCP */
|
|
|
|
scp->ie_bus_use = 0; /* 16-bit */
|
|
|
|
scp->ie_iscp_ptr = Swap32(vtop24(sc, (void*)iscp));
|
|
|
|
|
|
|
|
/* ISCP */
|
|
|
|
iscp->ie_busy = 1; /* ie_busy == char */
|
|
|
|
iscp->ie_scb_offset = vtop16sw(sc, (void*)scb);
|
|
|
|
iscp->ie_base = Swap32(vtop24(sc, sc->sc_maddr));
|
|
|
|
|
|
|
|
/* SCB */
|
|
|
|
scb->ie_command_list = SWAP(0xffff);
|
|
|
|
scb->ie_recv_list = SWAP(0xffff);
|
|
|
|
|
|
|
|
/* Other stuff is done in ieinit() */
|
|
|
|
(sc->reset_586) (sc);
|
|
|
|
(sc->chan_attn) (sc);
|
|
|
|
|
|
|
|
delay(100); /* wait a while... */
|
|
|
|
|
|
|
|
if (iscp->ie_busy) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Acknowledge any interrupts we may have caused...
|
|
|
|
*/
|
|
|
|
ie_ack(sc, IE_ST_WHENCE);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
/*
|
|
|
|
* Device timeout/watchdog routine. Entered if the device neglects to
|
|
|
|
* generate an interrupt after a transmit has been started on it.
|
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
static void
|
1996-05-07 05:35:48 +04:00
|
|
|
iewatchdog(ifp)
|
|
|
|
struct ifnet *ifp;
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
1996-05-10 01:15:47 +04:00
|
|
|
struct ie_softc *sc = ifp->if_softc;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
log(LOG_ERR, "%s: device timeout\n", sc->sc_dev.dv_xname);
|
1997-03-15 21:09:08 +03:00
|
|
|
++ifp->if_oerrors;
|
1994-12-12 21:58:45 +03:00
|
|
|
iereset(sc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* What to do upon receipt of an interrupt.
|
|
|
|
*/
|
|
|
|
int
|
1997-02-13 23:48:36 +03:00
|
|
|
ie_intr(arg)
|
|
|
|
void *arg;
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
1997-02-13 23:48:36 +03:00
|
|
|
struct ie_softc *sc = arg;
|
1994-12-12 21:58:45 +03:00
|
|
|
register u_short status;
|
1997-02-13 23:48:36 +03:00
|
|
|
int loopcnt;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check for parity error
|
|
|
|
*/
|
|
|
|
if (sc->hard_type == IE_VME) {
|
|
|
|
volatile struct ievme *iev = (volatile struct ievme *)sc->sc_reg;
|
|
|
|
if (iev->status & IEVME_PERR) {
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: parity error (ctrl %x @ %02x%04x)\n",
|
1996-12-18 00:10:35 +03:00
|
|
|
sc->sc_dev.dv_xname, iev->pectrl,
|
|
|
|
iev->pectrl & IEVME_HADDR, iev->peaddr);
|
1994-12-12 21:58:45 +03:00
|
|
|
iev->pectrl = iev->pectrl | IEVME_PARACK;
|
|
|
|
}
|
|
|
|
}
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
status = sc->scb->ie_status & IE_ST_WHENCE;
|
|
|
|
if (status == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
loopcnt = 5;
|
1994-12-12 21:58:45 +03:00
|
|
|
loop:
|
1995-01-27 02:23:34 +03:00
|
|
|
/* Ack interrupts FIRST in case we receive more during the ISR. */
|
1997-02-13 23:48:36 +03:00
|
|
|
ie_ack(sc, status);
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
if (status & (IE_ST_RECV | IE_ST_RNR)) {
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
in_ierint++;
|
|
|
|
if (sc->sc_debug & IED_RINT)
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: rint\n", sc->sc_dev.dv_xname);
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
ierint(sc);
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
in_ierint--;
|
|
|
|
#endif
|
|
|
|
}
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
if (status & IE_ST_DONE) {
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
in_ietint++;
|
|
|
|
if (sc->sc_debug & IED_TINT)
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: tint\n", sc->sc_dev.dv_xname);
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
ietint(sc);
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
in_ietint--;
|
|
|
|
#endif
|
|
|
|
}
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/*
|
1997-02-28 20:17:22 +03:00
|
|
|
* Receiver not ready (RNR) just means it has
|
|
|
|
* run out of resources (buffers or frames).
|
|
|
|
* One can easily cause this with (i.e.) spray.
|
1997-03-11 00:45:01 +03:00
|
|
|
* This is not a serious error, so be silent.
|
1997-02-13 23:48:36 +03:00
|
|
|
*/
|
1994-12-12 21:58:45 +03:00
|
|
|
if (status & IE_ST_RNR) {
|
1997-02-28 20:17:22 +03:00
|
|
|
#ifdef IEDEBUG
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: receiver not ready\n", sc->sc_dev.dv_xname);
|
1997-02-28 20:17:22 +03:00
|
|
|
#endif
|
1997-03-11 00:45:01 +03:00
|
|
|
sc->sc_if.if_ierrors++;
|
1995-01-27 02:23:34 +03:00
|
|
|
iereset(sc);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
#ifdef IEDEBUG
|
|
|
|
if ((status & IE_ST_ALLDONE) && (sc->sc_debug & IED_CNA))
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: cna\n", sc->sc_dev.dv_xname);
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
status = sc->scb->ie_status & IE_ST_WHENCE;
|
|
|
|
if (status) {
|
|
|
|
if (--loopcnt > 0)
|
|
|
|
goto loop;
|
|
|
|
printf("%s: interrupt stuck?\n", sc->sc_dev.dv_xname);
|
|
|
|
iereset(sc);
|
|
|
|
}
|
1994-12-12 21:58:45 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process a received-frame interrupt.
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
ierint(sc)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
|
|
|
volatile struct ie_sys_ctl_block *scb = sc->scb;
|
1997-02-13 23:48:36 +03:00
|
|
|
int i, status;
|
1994-12-12 21:58:45 +03:00
|
|
|
static int timesthru = 1024;
|
|
|
|
|
|
|
|
i = sc->rfhead;
|
|
|
|
for (;;) {
|
|
|
|
status = sc->rframes[i]->ie_fd_status;
|
|
|
|
|
|
|
|
if ((status & IE_FD_COMPLETE) && (status & IE_FD_OK)) {
|
|
|
|
if (!--timesthru) {
|
1997-03-11 00:45:01 +03:00
|
|
|
sc->sc_if.if_ierrors +=
|
1994-12-12 21:58:45 +03:00
|
|
|
SWAP(scb->ie_err_crc) +
|
|
|
|
SWAP(scb->ie_err_align) +
|
|
|
|
SWAP(scb->ie_err_resource) +
|
|
|
|
SWAP(scb->ie_err_overrun);
|
1995-01-27 02:23:34 +03:00
|
|
|
scb->ie_err_crc = 0;
|
|
|
|
scb->ie_err_align = 0;
|
1994-12-12 21:58:45 +03:00
|
|
|
scb->ie_err_resource = 0;
|
|
|
|
scb->ie_err_overrun = 0;
|
|
|
|
timesthru = 1024;
|
|
|
|
}
|
|
|
|
ie_readframe(sc, i);
|
|
|
|
} else {
|
|
|
|
if ((status & IE_FD_RNR) != 0 &&
|
|
|
|
(scb->ie_status & IE_RU_READY) == 0) {
|
1995-01-27 02:23:34 +03:00
|
|
|
sc->rframes[0]->ie_fd_buf_desc =
|
1997-02-13 23:48:36 +03:00
|
|
|
vtop16sw(sc, (void*) sc->rbuffs[0]);
|
1994-12-16 00:08:06 +03:00
|
|
|
scb->ie_recv_list =
|
1997-02-13 23:48:36 +03:00
|
|
|
vtop16sw(sc, (void*) sc->rframes[0]);
|
1996-12-18 00:10:35 +03:00
|
|
|
cmd_and_wait(sc, IE_RU_START, 0, 0);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i = (i + 1) % sc->nframes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-02-13 23:48:36 +03:00
|
|
|
* Process a command-complete interrupt. These are only generated by the
|
|
|
|
* transmission of frames. This routine is deceptively simple, since most
|
|
|
|
* of the real work is done by iestart().
|
1994-12-12 21:58:45 +03:00
|
|
|
*/
|
|
|
|
void
|
|
|
|
ietint(sc)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp;
|
1997-02-13 23:48:36 +03:00
|
|
|
int status;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
ifp = &sc->sc_if;
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
ifp->if_timer = 0;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
status = sc->xmit_cmds[sc->xctail]->ie_xmit_status;
|
|
|
|
|
|
|
|
if (!(status & IE_STAT_COMPL) || (status & IE_STAT_BUSY))
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("ietint: command still busy!\n");
|
1995-01-27 02:23:34 +03:00
|
|
|
|
|
|
|
if (status & IE_STAT_OK) {
|
1997-02-13 23:48:36 +03:00
|
|
|
ifp->if_opackets++;
|
|
|
|
ifp->if_collisions +=
|
1995-01-27 02:23:34 +03:00
|
|
|
SWAP(status & IE_XS_MAXCOLL);
|
1997-02-13 23:48:36 +03:00
|
|
|
} else {
|
|
|
|
ifp->if_oerrors++;
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* Check SQE and DEFERRED?
|
|
|
|
* What if more than one bit is set?
|
|
|
|
*/
|
|
|
|
if (status & IE_STAT_ABORT)
|
|
|
|
printf("%s: send aborted\n", sc->sc_dev.dv_xname);
|
|
|
|
if (status & IE_XS_LATECOLL)
|
|
|
|
printf("%s: late collision\n", sc->sc_dev.dv_xname);
|
|
|
|
if (status & IE_XS_NOCARRIER)
|
|
|
|
printf("%s: no carrier\n", sc->sc_dev.dv_xname);
|
|
|
|
if (status & IE_XS_LOSTCTS)
|
|
|
|
printf("%s: lost CTS\n", sc->sc_dev.dv_xname);
|
|
|
|
if (status & IE_XS_UNDERRUN)
|
|
|
|
printf("%s: DMA underrun\n", sc->sc_dev.dv_xname);
|
|
|
|
if (status & IE_XS_EXCMAX) {
|
|
|
|
printf("%s: too many collisions\n", sc->sc_dev.dv_xname);
|
|
|
|
ifp->if_collisions += 16;
|
|
|
|
}
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If multicast addresses were added or deleted while we
|
|
|
|
* were transmitting, mc_reset() set the want_mcsetup flag
|
|
|
|
* indicating that we should do it.
|
|
|
|
*/
|
|
|
|
if (sc->want_mcsetup) {
|
1995-01-27 02:23:34 +03:00
|
|
|
mc_setup(sc, (caddr_t)sc->xmit_cbuffs[sc->xctail]);
|
1994-12-12 21:58:45 +03:00
|
|
|
sc->want_mcsetup = 0;
|
|
|
|
}
|
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
/* Done with the buffer. */
|
1997-02-13 23:48:36 +03:00
|
|
|
sc->xmit_busy--;
|
1995-01-27 02:23:34 +03:00
|
|
|
sc->xctail = (sc->xctail + 1) % NTXBUF;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Start the next packet, if any, transmitting. */
|
|
|
|
if (sc->xmit_busy > 0)
|
|
|
|
iexmit(sc);
|
|
|
|
|
|
|
|
iestart(ifp);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Compare two Ether/802 addresses for equality, inlined and
|
|
|
|
* unrolled for speed. I'd love to have an inline assembler
|
1996-03-26 17:38:29 +03:00
|
|
|
* version of this... XXX: Who wanted that? mycroft?
|
|
|
|
* I wrote one, but the following is just as efficient.
|
|
|
|
* This expands to 10 short m68k instructions! -gwr
|
|
|
|
* Note: use this like bcmp()
|
1994-12-12 21:58:45 +03:00
|
|
|
*/
|
1996-03-26 17:38:29 +03:00
|
|
|
static inline u_short
|
|
|
|
ether_cmp(one, two)
|
1994-12-12 21:58:45 +03:00
|
|
|
u_char *one, *two;
|
|
|
|
{
|
1996-03-26 17:38:29 +03:00
|
|
|
register u_short *a = (u_short *) one;
|
|
|
|
register u_short *b = (u_short *) two;
|
|
|
|
register u_short diff;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1996-03-26 17:38:29 +03:00
|
|
|
diff = *a++ - *b++;
|
|
|
|
diff |= *a++ - *b++;
|
|
|
|
diff |= *a++ - *b++;
|
|
|
|
|
|
|
|
return (diff);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
1996-03-26 17:38:29 +03:00
|
|
|
#define ether_equal !ether_cmp
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for a valid address. to_bpf is filled in with one of the following:
|
|
|
|
* 0 -> BPF doesn't get this packet
|
|
|
|
* 1 -> BPF does get this packet
|
|
|
|
* 2 -> BPF does get this packet, but we don't
|
|
|
|
* Return value is true if the packet is for us, and false otherwise.
|
|
|
|
*
|
|
|
|
* This routine is a mess, but it's also critical that it be as fast
|
|
|
|
* as possible. It could be made cleaner if we can assume that the
|
|
|
|
* only client which will fiddle with IFF_PROMISC is BPF. This is
|
|
|
|
* probably a good assumption, but we do not make it here. (Yet.)
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
check_eh(sc, eh, to_bpf)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
struct ether_header *eh;
|
1997-02-13 23:48:36 +03:00
|
|
|
int *to_bpf;
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp;
|
1997-02-13 23:48:36 +03:00
|
|
|
int i;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
ifp = &sc->sc_if;
|
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
switch (sc->promisc) {
|
|
|
|
case IFF_ALLMULTI:
|
|
|
|
/*
|
|
|
|
* Receiving all multicasts, but no unicasts except those
|
|
|
|
* destined for us.
|
|
|
|
*/
|
|
|
|
#if NBPFILTER > 0
|
1995-01-27 02:23:34 +03:00
|
|
|
/* BPF gets this packet if anybody cares */
|
1997-03-15 21:09:08 +03:00
|
|
|
*to_bpf = (ifp->if_bpf != 0);
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
if (eh->ether_dhost[0] & 1)
|
|
|
|
return 1;
|
1997-03-15 21:09:08 +03:00
|
|
|
if (ether_equal(eh->ether_dhost, LLADDR(ifp->if_sadl)))
|
1994-12-12 21:58:45 +03:00
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
case IFF_PROMISC:
|
|
|
|
/*
|
|
|
|
* Receiving all packets. These need to be passed on to BPF.
|
|
|
|
*/
|
|
|
|
#if NBPFILTER > 0
|
1997-03-15 21:09:08 +03:00
|
|
|
*to_bpf = (ifp->if_bpf != 0);
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
/* If for us, accept and hand up to BPF */
|
1997-03-15 21:09:08 +03:00
|
|
|
if (ether_equal(eh->ether_dhost, LLADDR(ifp->if_sadl)))
|
1994-12-12 21:58:45 +03:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (*to_bpf)
|
|
|
|
*to_bpf = 2; /* we don't need to see it */
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Not a multicast, so BPF wants to see it but we don't.
|
|
|
|
*/
|
|
|
|
if (!(eh->ether_dhost[0] & 1))
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If it's one of our multicast groups, accept it and pass it
|
|
|
|
* up.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < sc->mcast_count; i++) {
|
|
|
|
if (ether_equal(eh->ether_dhost,
|
|
|
|
(u_char *)&sc->mcast_addrs[i])) {
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (*to_bpf)
|
|
|
|
*to_bpf = 1;
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
case IFF_ALLMULTI | IFF_PROMISC:
|
|
|
|
/*
|
|
|
|
* Acting as a multicast router, and BPF running at the same
|
|
|
|
* time. Whew! (Hope this is a fast machine...)
|
|
|
|
*/
|
|
|
|
#if NBPFILTER > 0
|
1997-03-15 21:09:08 +03:00
|
|
|
*to_bpf = (ifp->if_bpf != 0);
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
/* We want to see multicasts. */
|
|
|
|
if (eh->ether_dhost[0] & 1)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* We want to see our own packets */
|
1997-03-15 21:09:08 +03:00
|
|
|
if (ether_equal(eh->ether_dhost, LLADDR(ifp->if_sadl)))
|
1994-12-12 21:58:45 +03:00
|
|
|
return 1;
|
|
|
|
|
|
|
|
/* Anything else goes to BPF but nothing else. */
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
if (*to_bpf)
|
|
|
|
*to_bpf = 2;
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
case 0:
|
1994-12-12 21:58:45 +03:00
|
|
|
/*
|
|
|
|
* Only accept unicast packets destined for us, or multicasts
|
|
|
|
* for groups that we belong to. For now, we assume that the
|
|
|
|
* '586 will only return packets that we asked it for. This
|
|
|
|
* isn't strictly true (it uses hashing for the multicast filter),
|
|
|
|
* but it will do in this case, and we want to get out of here
|
|
|
|
* as quickly as possible.
|
|
|
|
*/
|
|
|
|
#if NBPFILTER > 0
|
1997-03-15 21:09:08 +03:00
|
|
|
*to_bpf = (ifp->if_bpf != 0);
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
1997-02-13 23:48:36 +03:00
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
panic("ie: check_eh, impossible");
|
|
|
|
#endif
|
1994-12-12 21:58:45 +03:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We want to isolate the bits that have meaning... This assumes that
|
|
|
|
* IE_RBUF_SIZE is an even power of two. If somehow the act_len exceeds
|
|
|
|
* the size of the buffer, then we are screwed anyway.
|
|
|
|
*/
|
|
|
|
static inline int
|
|
|
|
ie_buflen(sc, head)
|
|
|
|
struct ie_softc *sc;
|
1997-02-13 23:48:36 +03:00
|
|
|
int head;
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
1997-02-13 23:48:36 +03:00
|
|
|
register int len;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
len = SWAP(sc->rbuffs[head]->ie_rbd_actual);
|
|
|
|
len &= (IE_RBUF_SIZE | (IE_RBUF_SIZE - 1));
|
|
|
|
return (len);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline int
|
|
|
|
ie_packet_len(sc)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
1997-02-13 23:48:36 +03:00
|
|
|
int i;
|
|
|
|
int head = sc->rbhead;
|
|
|
|
int acc = 0;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
do {
|
|
|
|
if (!(sc->rbuffs[sc->rbhead]->ie_rbd_actual & IE_RBD_USED)) {
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
print_rbd(sc->rbuffs[sc->rbhead]);
|
|
|
|
#endif
|
|
|
|
log(LOG_ERR, "%s: receive descriptors out of sync at %d\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->rbhead);
|
|
|
|
iereset(sc);
|
|
|
|
return -1;
|
|
|
|
}
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
i = sc->rbuffs[head]->ie_rbd_actual & IE_RBD_LAST;
|
|
|
|
|
|
|
|
acc += ie_buflen(sc, head);
|
|
|
|
head = (head + 1) % sc->nrxbuf;
|
|
|
|
} while (!i);
|
|
|
|
|
|
|
|
return acc;
|
|
|
|
}
|
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
/*
|
|
|
|
* Setup all necessary artifacts for an XMIT command, and then pass the XMIT
|
|
|
|
* command to the chip to be executed. On the way, if we have a BPF listener
|
|
|
|
* also give him a copy.
|
|
|
|
*/
|
1996-12-18 00:10:35 +03:00
|
|
|
static void
|
1995-01-27 02:23:34 +03:00
|
|
|
iexmit(sc)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
ifp = &sc->sc_if;
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
#ifdef IEDEBUG
|
|
|
|
if (sc->sc_debug & IED_XMIT)
|
|
|
|
printf("%s: xmit buffer %d\n", sc->sc_dev.dv_xname,
|
|
|
|
sc->xctail);
|
|
|
|
#endif
|
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* If BPF is listening on this interface, let it see the packet before
|
|
|
|
* we push it on the wire.
|
|
|
|
*/
|
1997-03-15 21:09:08 +03:00
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_tap(ifp->if_bpf,
|
1995-01-27 02:23:34 +03:00
|
|
|
sc->xmit_cbuffs[sc->xctail],
|
|
|
|
SWAP(sc->xmit_buffs[sc->xctail]->ie_xmit_flags));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
sc->xmit_buffs[sc->xctail]->ie_xmit_flags |= IE_XMIT_LAST;
|
|
|
|
sc->xmit_buffs[sc->xctail]->ie_xmit_next = SWAP(0xffff);
|
1997-02-13 23:48:36 +03:00
|
|
|
sc->xmit_buffs[sc->xctail]->ie_xmit_buf =
|
|
|
|
Swap32(vtop24(sc, sc->xmit_cbuffs[sc->xctail]));
|
1995-01-27 02:23:34 +03:00
|
|
|
|
|
|
|
sc->xmit_cmds[sc->xctail]->com.ie_cmd_link = SWAP(0xffff);
|
|
|
|
sc->xmit_cmds[sc->xctail]->com.ie_cmd_cmd =
|
1997-02-13 23:48:36 +03:00
|
|
|
IE_CMD_XMIT | IE_CMD_INTR | IE_CMD_LAST;
|
1995-01-27 02:23:34 +03:00
|
|
|
|
|
|
|
sc->xmit_cmds[sc->xctail]->ie_xmit_status = SWAP(0);
|
|
|
|
sc->xmit_cmds[sc->xctail]->ie_xmit_desc =
|
1997-02-13 23:48:36 +03:00
|
|
|
vtop16sw(sc, (void*) sc->xmit_buffs[sc->xctail]);
|
1995-01-27 02:23:34 +03:00
|
|
|
|
|
|
|
sc->scb->ie_command_list =
|
1997-02-13 23:48:36 +03:00
|
|
|
vtop16sw(sc, (void*) sc->xmit_cmds[sc->xctail]);
|
1996-12-18 00:10:35 +03:00
|
|
|
cmd_and_wait(sc, IE_CU_START, 0, 0);
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
ifp->if_timer = 5;
|
1995-01-27 02:23:34 +03:00
|
|
|
}
|
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
/*
|
|
|
|
* Read data off the interface, and turn it into an mbuf chain.
|
|
|
|
*
|
|
|
|
* This code is DRAMATICALLY different from the previous version; this
|
|
|
|
* version tries to allocate the entire mbuf chain up front, given the
|
|
|
|
* length of the data available. This enables us to allocate mbuf
|
|
|
|
* clusters in many situations where before we would have had a long
|
|
|
|
* chain of partially-full mbufs. This should help to speed up the
|
|
|
|
* operation considerably. (Provided that it works, of course.)
|
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
static inline struct mbuf *
|
|
|
|
ieget(sc, ehp, to_bpf)
|
1994-12-12 21:58:45 +03:00
|
|
|
struct ie_softc *sc;
|
|
|
|
struct ether_header *ehp;
|
1997-02-13 23:48:36 +03:00
|
|
|
int *to_bpf;
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
1997-02-13 23:48:36 +03:00
|
|
|
struct mbuf *top, **mp, *m;
|
|
|
|
int len, totlen, resid;
|
|
|
|
int thisrboff, thismboff;
|
|
|
|
int head;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
totlen = ie_packet_len(sc);
|
|
|
|
if (totlen <= 0)
|
1997-02-13 23:48:36 +03:00
|
|
|
return 0;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
head = sc->rbhead;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Snarf the Ethernet header.
|
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
(sc->sc_bcopy)((caddr_t)sc->cbuffs[head], (caddr_t)ehp, sizeof *ehp);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* As quickly as possible, check if this packet is for us.
|
|
|
|
* If not, don't waste a single cycle copying the rest of the
|
|
|
|
* packet in.
|
|
|
|
* This is only a consideration when FILTER is defined; i.e., when
|
|
|
|
* we are either running BPF or doing multicasting.
|
|
|
|
*/
|
|
|
|
if (!check_eh(sc, ehp, to_bpf)) {
|
1995-01-27 02:23:34 +03:00
|
|
|
/* just this case, it's not an error */
|
1997-03-11 00:45:01 +03:00
|
|
|
sc->sc_if.if_ierrors--;
|
1997-02-13 23:48:36 +03:00
|
|
|
return 0;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
resid = totlen -= (thisrboff = sizeof *ehp);
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0)
|
|
|
|
return 0;
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1997-03-11 00:45:01 +03:00
|
|
|
m->m_pkthdr.rcvif = &sc->sc_if;
|
1997-02-13 23:48:36 +03:00
|
|
|
m->m_pkthdr.len = totlen;
|
|
|
|
len = MHLEN;
|
1994-12-12 21:58:45 +03:00
|
|
|
top = 0;
|
1997-02-13 23:48:36 +03:00
|
|
|
mp = ⊤
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This loop goes through and allocates mbufs for all the data we will
|
|
|
|
* be copying in. It does not actually do the copying yet.
|
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
while (totlen > 0) {
|
1994-12-12 21:58:45 +03:00
|
|
|
if (top) {
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
1997-02-13 23:48:36 +03:00
|
|
|
if (m == 0) {
|
1994-12-12 21:58:45 +03:00
|
|
|
m_freem(top);
|
1997-02-13 23:48:36 +03:00
|
|
|
return 0;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
1997-02-13 23:48:36 +03:00
|
|
|
len = MLEN;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
1997-02-13 23:48:36 +03:00
|
|
|
if (totlen >= MINCLSIZE) {
|
1994-12-12 21:58:45 +03:00
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if (m->m_flags & M_EXT)
|
1997-02-13 23:48:36 +03:00
|
|
|
len = MCLBYTES;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
1997-02-13 23:48:36 +03:00
|
|
|
m->m_len = len = min(totlen, len);
|
|
|
|
totlen -= len;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_next;
|
|
|
|
}
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
m = top;
|
|
|
|
thismboff = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now we take the mbuf chain (hopefully only one mbuf most of the
|
|
|
|
* time) and stuff the data into it. There are no possible failures
|
|
|
|
* at or after this point.
|
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
while (resid > 0) {
|
|
|
|
int thisrblen = ie_buflen(sc, head) - thisrboff;
|
|
|
|
int thismblen = m->m_len - thismboff;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
len = min(thisrblen, thismblen);
|
|
|
|
(sc->sc_bcopy)((caddr_t)(sc->cbuffs[head] + thisrboff),
|
|
|
|
mtod(m, caddr_t) + thismboff, (u_int)len);
|
|
|
|
resid -= len;
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
if (len == thismblen) {
|
|
|
|
m = m->m_next;
|
|
|
|
thismboff = 0;
|
|
|
|
} else
|
|
|
|
thismboff += len;
|
|
|
|
|
|
|
|
if (len == thisrblen) {
|
|
|
|
head = (head + 1) % sc->nrxbuf;
|
|
|
|
thisrboff = 0;
|
|
|
|
} else
|
|
|
|
thisrboff += len;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Unless something changed strangely while we were doing the copy,
|
|
|
|
* we have now copied everything in from the shared memory.
|
|
|
|
* This means that we are done.
|
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
return top;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Read frame NUM from unit UNIT (pre-cached as IE).
|
|
|
|
*
|
|
|
|
* This routine reads the RFD at NUM, and copies in the buffers from
|
|
|
|
* the list of RBD, then rotates the RBD and RFD lists so that the receiver
|
|
|
|
* doesn't start complaining. Trailers are DROPPED---there's no point
|
|
|
|
* in wasting time on confusing code to deal with them. Hopefully,
|
|
|
|
* this machine will never ARP for trailers anyway.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ie_readframe(sc, num)
|
|
|
|
struct ie_softc *sc;
|
1997-02-13 23:48:36 +03:00
|
|
|
int num; /* frame number to read */
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
1995-01-27 02:23:34 +03:00
|
|
|
int status;
|
1994-12-12 21:58:45 +03:00
|
|
|
struct mbuf *m = 0;
|
|
|
|
struct ether_header eh;
|
|
|
|
#if NBPFILTER > 0
|
1997-02-13 23:48:36 +03:00
|
|
|
int bpf_gets_it = 0;
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
status = sc->rframes[num]->ie_fd_status;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Advance the RFD list, since we're done with this descriptor. */
|
1994-12-12 21:58:45 +03:00
|
|
|
sc->rframes[num]->ie_fd_status = SWAP(0);
|
|
|
|
sc->rframes[num]->ie_fd_last |= IE_FD_LAST;
|
|
|
|
sc->rframes[sc->rftail]->ie_fd_last &= ~IE_FD_LAST;
|
|
|
|
sc->rftail = (sc->rftail + 1) % sc->nframes;
|
|
|
|
sc->rfhead = (sc->rfhead + 1) % sc->nframes;
|
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
if (status & IE_FD_OK) {
|
1994-12-12 21:58:45 +03:00
|
|
|
#if NBPFILTER > 0
|
1997-02-13 23:48:36 +03:00
|
|
|
m = ieget(sc, &eh, &bpf_gets_it);
|
1994-12-12 21:58:45 +03:00
|
|
|
#else
|
1997-02-13 23:48:36 +03:00
|
|
|
m = ieget(sc, &eh, 0);
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
1997-02-13 23:48:36 +03:00
|
|
|
ie_drop_packet_buffer(sc);
|
|
|
|
}
|
|
|
|
if (m == 0) {
|
1997-03-11 00:45:01 +03:00
|
|
|
sc->sc_if.if_ierrors++;
|
1997-02-13 23:48:36 +03:00
|
|
|
return;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
#ifdef IEDEBUG
|
|
|
|
if (sc->sc_debug & IED_READFRAME)
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: frame from ether %s type %x\n", sc->sc_dev.dv_xname,
|
1994-12-12 21:58:45 +03:00
|
|
|
ether_sprintf(eh.ether_shost), (u_int)eh.ether_type);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if NBPFILTER > 0
|
|
|
|
/*
|
|
|
|
* Check for a BPF filter; if so, hand it up.
|
|
|
|
* Note that we have to stick an extra mbuf up front, because
|
|
|
|
* bpf_mtap expects to have the ether header at the front.
|
|
|
|
* It doesn't matter that this results in an ill-formatted mbuf chain,
|
|
|
|
* since BPF just looks at the data. (It doesn't try to free the mbuf,
|
|
|
|
* tho' it will make a copy for tcpdump.)
|
|
|
|
*/
|
|
|
|
if (bpf_gets_it) {
|
|
|
|
struct mbuf m0;
|
|
|
|
m0.m_len = sizeof eh;
|
|
|
|
m0.m_data = (caddr_t)&eh;
|
|
|
|
m0.m_next = m;
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Pass it up. */
|
1997-03-11 00:45:01 +03:00
|
|
|
bpf_mtap(sc->sc_if.if_bpf, &m0);
|
1997-02-13 23:48:36 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* A signal passed up from the filtering code indicating that
|
|
|
|
* the packet is intended for BPF but not for the protocol
|
|
|
|
* machinery. We can save a few cycles by not handing it off
|
|
|
|
* to them.
|
|
|
|
*/
|
|
|
|
if (bpf_gets_it == 2) {
|
|
|
|
m_freem(m);
|
|
|
|
return;
|
|
|
|
}
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
1995-01-27 02:23:34 +03:00
|
|
|
#endif /* NBPFILTER > 0 */
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* In here there used to be code to check destination addresses upon
|
|
|
|
* receipt of a packet. We have deleted that code, and replaced it
|
|
|
|
* with code to check the address much earlier in the cycle, before
|
|
|
|
* copying the data in; this saves us valuable cycles when operating
|
|
|
|
* as a multicast router or when using BPF.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Finally pass this packet up to higher layers.
|
|
|
|
*/
|
1997-03-11 00:45:01 +03:00
|
|
|
ether_input(&sc->sc_if, &eh, m);
|
|
|
|
sc->sc_if.if_ipackets++;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ie_drop_packet_buffer(sc)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
1995-01-27 02:23:34 +03:00
|
|
|
int i;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
do {
|
|
|
|
/*
|
|
|
|
* This means we are somehow out of sync. So, we reset the
|
|
|
|
* adapter.
|
|
|
|
*/
|
|
|
|
if (!(sc->rbuffs[sc->rbhead]->ie_rbd_actual & IE_RBD_USED)) {
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
print_rbd(sc->rbuffs[sc->rbhead]);
|
|
|
|
#endif
|
|
|
|
log(LOG_ERR, "%s: receive descriptors out of sync at %d\n",
|
|
|
|
sc->sc_dev.dv_xname, sc->rbhead);
|
|
|
|
iereset(sc);
|
|
|
|
return;
|
|
|
|
}
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
i = sc->rbuffs[sc->rbhead]->ie_rbd_actual & IE_RBD_LAST;
|
|
|
|
|
|
|
|
sc->rbuffs[sc->rbhead]->ie_rbd_length |= IE_RBD_LAST;
|
|
|
|
sc->rbuffs[sc->rbhead]->ie_rbd_actual = SWAP(0);
|
|
|
|
sc->rbhead = (sc->rbhead + 1) % sc->nrxbuf;
|
|
|
|
sc->rbuffs[sc->rbtail]->ie_rbd_length &= ~IE_RBD_LAST;
|
|
|
|
sc->rbtail = (sc->rbtail + 1) % sc->nrxbuf;
|
|
|
|
} while (!i);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start transmission on an interface.
|
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
static void
|
1994-12-12 21:58:45 +03:00
|
|
|
iestart(ifp)
|
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
1996-05-07 05:35:48 +04:00
|
|
|
struct ie_softc *sc = ifp->if_softc;
|
1994-12-12 21:58:45 +03:00
|
|
|
struct mbuf *m0, *m;
|
|
|
|
u_char *buffer;
|
|
|
|
u_short len;
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING)
|
1995-04-09 09:08:33 +04:00
|
|
|
return;
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
for (;;) {
|
|
|
|
if (sc->xmit_busy == sc->ntxbuf) {
|
|
|
|
ifp->if_flags |= IFF_OACTIVE;
|
|
|
|
break;
|
|
|
|
}
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
IF_DEQUEUE(&ifp->if_snd, m0);
|
|
|
|
if (m0 == 0)
|
1994-12-12 21:58:45 +03:00
|
|
|
break;
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* We need to use m->m_pkthdr.len, so require the header */
|
|
|
|
if ((m0->m_flags & M_PKTHDR) == 0)
|
|
|
|
panic("iestart: no header mbuf");
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
#if NBPFILTER > 0
|
|
|
|
/* Tap off here if there is a BPF listener. */
|
|
|
|
if (ifp->if_bpf)
|
|
|
|
bpf_mtap(ifp->if_bpf, m0);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
if (sc->sc_debug & IED_ENQ)
|
|
|
|
printf("%s: fill buffer %d\n", sc->sc_dev.dv_xname,
|
|
|
|
sc->xchead);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
buffer = sc->xmit_cbuffs[sc->xchead];
|
|
|
|
for (m = m0; m != 0; m = m->m_next) {
|
1995-01-27 02:23:34 +03:00
|
|
|
(sc->sc_bcopy)(mtod(m, caddr_t), buffer, m->m_len);
|
1994-12-12 21:58:45 +03:00
|
|
|
buffer += m->m_len;
|
|
|
|
}
|
1997-02-13 23:48:36 +03:00
|
|
|
len = max(m0->m_pkthdr.len, ETHER_MIN_LEN);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
m_freem(m0);
|
1995-01-27 02:23:34 +03:00
|
|
|
sc->xmit_buffs[sc->xchead]->ie_xmit_flags = SWAP(len);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Start the first packet transmitting. */
|
|
|
|
if (sc->xmit_busy == 0)
|
|
|
|
iexmit(sc);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
sc->xchead = (sc->xchead + 1) % sc->ntxbuf;
|
|
|
|
sc->xmit_busy++;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
static void
|
1994-12-12 21:58:45 +03:00
|
|
|
iereset(sc)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
1995-12-24 05:29:35 +03:00
|
|
|
int s = splnet();
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-28 20:17:22 +03:00
|
|
|
/* No message here. The caller does that. */
|
1997-02-13 23:48:36 +03:00
|
|
|
iestop(sc);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Stop i82586 dead in its tracks.
|
|
|
|
*/
|
1996-12-18 00:10:35 +03:00
|
|
|
if (cmd_and_wait(sc, IE_RU_ABORT | IE_CU_ABORT, 0, 0))
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: abort commands timed out\n", sc->sc_dev.dv_xname);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1996-12-18 00:10:35 +03:00
|
|
|
if (cmd_and_wait(sc, IE_RU_DISABLE | IE_CU_STOP, 0, 0))
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: disable commands timed out\n", sc->sc_dev.dv_xname);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
ieinit(sc);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a command to the controller and wait for it to either
|
|
|
|
* complete or be accepted, depending on the command. If the
|
|
|
|
* command pointer is null, then pretend that the command is
|
|
|
|
* not an action command. If the command pointer is not null,
|
|
|
|
* and the command is an action command, wait for
|
|
|
|
* ((volatile struct ie_cmd_common *)pcmd)->ie_cmd_status & MASK
|
|
|
|
* to become true.
|
|
|
|
*/
|
|
|
|
static int
|
1996-12-18 00:10:35 +03:00
|
|
|
cmd_and_wait(sc, cmd, pcmd, mask)
|
1994-12-12 21:58:45 +03:00
|
|
|
struct ie_softc *sc;
|
1997-02-13 23:48:36 +03:00
|
|
|
int cmd;
|
|
|
|
void *pcmd; /* XXX - Was volatile */
|
|
|
|
int mask;
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
|
|
|
volatile struct ie_cmd_common *cc = pcmd;
|
|
|
|
volatile struct ie_sys_ctl_block *scb = sc->scb;
|
1997-02-13 23:48:36 +03:00
|
|
|
int tmo;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
scb->ie_command = (u_short)cmd;
|
1997-02-13 23:48:36 +03:00
|
|
|
(sc->chan_attn)(sc);
|
|
|
|
|
|
|
|
/* Wait for the command to be accepted by the CU. */
|
|
|
|
tmo = 10;
|
|
|
|
while (scb->ie_command && --tmo)
|
|
|
|
delay(10);
|
|
|
|
if (scb->ie_command) {
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
printf("%s: cmd_and_wait, CU stuck (1)\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
#endif
|
|
|
|
return -1; /* timed out */
|
|
|
|
}
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/*
|
|
|
|
* If asked, also wait for it to finish.
|
|
|
|
*/
|
1994-12-12 21:58:45 +03:00
|
|
|
if (IE_ACTION_COMMAND(cmd) && pcmd) {
|
|
|
|
|
|
|
|
/*
|
1997-02-13 23:48:36 +03:00
|
|
|
* According to the packet driver, the minimum timeout should
|
|
|
|
* be .369 seconds, which we round up to .4.
|
1994-12-12 21:58:45 +03:00
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
tmo = 36900;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now spin-lock waiting for status. This is not a very nice
|
|
|
|
* thing to do, but I haven't figured out how, or indeed if, we
|
|
|
|
* can put the process waiting for action to sleep. (We may
|
|
|
|
* be getting called through some other timeout running in the
|
|
|
|
* kernel.)
|
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
while (((cc->ie_cmd_status & mask) == 0) && --tmo)
|
|
|
|
delay(10);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
if ((cc->ie_cmd_status & mask) == 0) {
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
printf("%s: cmd_and_wait, CU stuck (2)\n",
|
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
#endif
|
|
|
|
return -1; /* timed out */
|
|
|
|
}
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
1997-02-13 23:48:36 +03:00
|
|
|
return 0;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-02-13 23:48:36 +03:00
|
|
|
* Run the time-domain reflectometer.
|
1994-12-12 21:58:45 +03:00
|
|
|
*/
|
1995-01-27 02:23:34 +03:00
|
|
|
static void
|
1994-12-12 21:58:45 +03:00
|
|
|
run_tdr(sc, cmd)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
struct ie_tdr_cmd *cmd;
|
|
|
|
{
|
1995-01-27 02:23:34 +03:00
|
|
|
int result;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
cmd->com.ie_cmd_status = SWAP(0);
|
|
|
|
cmd->com.ie_cmd_cmd = IE_CMD_TDR | IE_CMD_LAST;
|
|
|
|
cmd->com.ie_cmd_link = SWAP(0xffff);
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
sc->scb->ie_command_list = vtop16sw(sc, cmd);
|
1994-12-12 21:58:45 +03:00
|
|
|
cmd->ie_tdr_time = SWAP(0);
|
|
|
|
|
1996-12-18 00:10:35 +03:00
|
|
|
if (cmd_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL) ||
|
1994-12-12 21:58:45 +03:00
|
|
|
!(cmd->com.ie_cmd_status & IE_STAT_OK))
|
1997-02-13 23:48:36 +03:00
|
|
|
result = 0x10000; /* impossible value */
|
1994-12-12 21:58:45 +03:00
|
|
|
else
|
|
|
|
result = cmd->ie_tdr_time;
|
|
|
|
|
|
|
|
ie_ack(sc, IE_ST_WHENCE);
|
|
|
|
|
|
|
|
if (result & IE_TDR_SUCCESS)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (result & 0x10000) {
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: TDR command failed\n", sc->sc_dev.dv_xname);
|
1994-12-12 21:58:45 +03:00
|
|
|
} else if (result & IE_TDR_XCVR) {
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: transceiver problem\n", sc->sc_dev.dv_xname);
|
1994-12-12 21:58:45 +03:00
|
|
|
} else if (result & IE_TDR_OPEN) {
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: TDR detected an open %d clocks away\n",
|
1994-12-12 21:58:45 +03:00
|
|
|
sc->sc_dev.dv_xname, SWAP(result & IE_TDR_TIME));
|
|
|
|
} else if (result & IE_TDR_SHORT) {
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: TDR detected a short %d clocks away\n",
|
1994-12-12 21:58:45 +03:00
|
|
|
sc->sc_dev.dv_xname, SWAP(result & IE_TDR_TIME));
|
|
|
|
} else {
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: TDR returned unknown status %x\n",
|
1994-12-12 21:58:45 +03:00
|
|
|
sc->sc_dev.dv_xname, result);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1997-02-13 23:48:36 +03:00
|
|
|
* iememinit: set up the buffers
|
1994-12-12 21:58:45 +03:00
|
|
|
*
|
|
|
|
* we have a block of KVA at sc->buf_area which is of size sc->buf_area_sz.
|
|
|
|
* this is to be used for the buffers. the chip indexs its control data
|
|
|
|
* structures with 16 bit offsets, and it indexes actual buffers with
|
|
|
|
* 24 bit addresses. so we should allocate control buffers first so that
|
|
|
|
* we don't overflow the 16 bit offset field. The number of transmit
|
|
|
|
* buffers is fixed at compile time.
|
|
|
|
*
|
|
|
|
* note: this function was written to be easy to understand, rather than
|
|
|
|
* highly efficient (it isn't in the critical path).
|
1997-02-13 23:48:36 +03:00
|
|
|
*
|
|
|
|
* The memory layout is: tbufs, rbufs, (gap), control blocks
|
|
|
|
* [tbuf0, tbuf1] [rbuf0,...rbufN] gap [rframes] [tframes]
|
|
|
|
* XXX - This needs review...
|
1994-12-12 21:58:45 +03:00
|
|
|
*/
|
|
|
|
static void
|
1997-02-13 23:48:36 +03:00
|
|
|
iememinit(sc)
|
1994-12-12 21:58:45 +03:00
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
1997-02-13 23:48:36 +03:00
|
|
|
char *ptr;
|
|
|
|
int i;
|
|
|
|
u_short nxt;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* First, zero all the memory. */
|
|
|
|
ptr = sc->buf_area;
|
1995-01-27 02:23:34 +03:00
|
|
|
(sc->sc_bzero)(ptr, sc->buf_area_sz);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Allocate tx/rx buffers. */
|
|
|
|
for (i = 0; i < NTXBUF; i++) {
|
|
|
|
sc->xmit_cbuffs[i] = ptr;
|
|
|
|
ptr += IE_TBUF_SIZE;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
1997-02-13 23:48:36 +03:00
|
|
|
for (i = 0; i < sc->nrxbuf; i++) {
|
|
|
|
sc->cbuffs[i] = ptr;
|
|
|
|
ptr += IE_RBUF_SIZE;
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Small pad (Don't trust the chip...) */
|
|
|
|
ptr += 16;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Allocate and fill in xmit buffer descriptors. */
|
|
|
|
for (i = 0; i < NTXBUF; i++) {
|
|
|
|
sc->xmit_buffs[i] = (volatile void *) ptr;
|
|
|
|
ptr = Align(ptr + sizeof(*sc->xmit_buffs[i]));
|
|
|
|
sc->xmit_buffs[i]->ie_xmit_buf =
|
|
|
|
Swap32(vtop24(sc, sc->xmit_cbuffs[i]));
|
|
|
|
sc->xmit_buffs[i]->ie_xmit_next = SWAP(0xffff);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Allocate and fill in recv buffer descriptors. */
|
|
|
|
for (i = 0; i < sc->nrxbuf; i++) {
|
|
|
|
sc->rbuffs[i] = (volatile void *) ptr;
|
|
|
|
ptr = Align(ptr + sizeof(*sc->rbuffs[i]));
|
|
|
|
sc->rbuffs[i]->ie_rbd_buffer =
|
|
|
|
Swap32(vtop24(sc, sc->cbuffs[i]));
|
|
|
|
sc->rbuffs[i]->ie_rbd_length = SWAP(IE_RBUF_SIZE);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* link together recv bufs and set EOL on last */
|
|
|
|
i = sc->nrxbuf - 1;
|
|
|
|
sc->rbuffs[i]->ie_rbd_length |= IE_RBD_LAST;
|
|
|
|
nxt = vtop16sw(sc, (void*) sc->rbuffs[0]);
|
|
|
|
do {
|
|
|
|
sc->rbuffs[i]->ie_rbd_next = nxt;
|
|
|
|
nxt = vtop16sw(sc, (void*) sc->rbuffs[i]);
|
|
|
|
} while (--i >= 0);
|
|
|
|
|
|
|
|
/* Allocate transmit commands. */
|
|
|
|
for (i = 0; i < NTXBUF; i++) {
|
|
|
|
sc->xmit_cmds[i] = (volatile void *) ptr;
|
|
|
|
ptr = Align(ptr + sizeof(*sc->xmit_cmds[i]));
|
|
|
|
sc->xmit_cmds[i]->com.ie_cmd_link = SWAP(0xffff);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Allocate receive frames. */
|
|
|
|
for (i = 0; i < sc->nframes; i++) {
|
|
|
|
sc->rframes[i] = (volatile void *) ptr;
|
|
|
|
ptr = Align(ptr + sizeof(*sc->rframes[i]));
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Link together recv frames and set EOL on last */
|
|
|
|
i = sc->nframes - 1;
|
|
|
|
sc->rframes[i]->ie_fd_last |= IE_FD_LAST;
|
|
|
|
nxt = vtop16sw(sc, (void*) sc->rframes[0]);
|
|
|
|
do {
|
|
|
|
sc->rframes[i]->ie_fd_next = nxt;
|
|
|
|
nxt = vtop16sw(sc, (void*) sc->rframes[i]);
|
|
|
|
} while (--i >= 0);
|
|
|
|
|
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
/* Pointers to last packet sent and next available transmit buffer. */
|
|
|
|
sc->xchead = sc->xctail = 0;
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
/* Clear transmit-busy flag. */
|
1995-01-27 02:23:34 +03:00
|
|
|
sc->xmit_busy = 0;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
1997-02-13 23:48:36 +03:00
|
|
|
* Set the head and tail pointers on receive to keep track of
|
|
|
|
* the order in which RFDs and RBDs are used. link the
|
|
|
|
* recv frames and buffer into the scb.
|
1994-12-12 21:58:45 +03:00
|
|
|
*/
|
|
|
|
sc->rfhead = 0;
|
|
|
|
sc->rftail = sc->nframes - 1;
|
|
|
|
sc->rbhead = 0;
|
|
|
|
sc->rbtail = sc->nrxbuf - 1;
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
sc->scb->ie_recv_list =
|
|
|
|
vtop16sw(sc, (void*) sc->rframes[0]);
|
|
|
|
sc->rframes[0]->ie_fd_buf_desc =
|
|
|
|
vtop16sw(sc, (void*) sc->rbuffs[0]);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
i = (ptr - sc->buf_area);
|
1994-12-12 21:58:45 +03:00
|
|
|
#ifdef IEDEBUG
|
1997-02-13 23:48:36 +03:00
|
|
|
printf("IE_DEBUG: used %d of %d bytes\n", i, sc->buf_area_sz);
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
1997-02-13 23:48:36 +03:00
|
|
|
if (i > sc->buf_area_sz)
|
|
|
|
panic("ie: iememinit, out of space");
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Run the multicast setup command.
|
1995-12-24 05:29:35 +03:00
|
|
|
* Called at splnet().
|
1994-12-12 21:58:45 +03:00
|
|
|
*/
|
|
|
|
static int
|
|
|
|
mc_setup(sc, ptr)
|
|
|
|
struct ie_softc *sc;
|
1995-01-27 02:23:34 +03:00
|
|
|
void *ptr;
|
1994-12-12 21:58:45 +03:00
|
|
|
{
|
1997-02-13 23:48:36 +03:00
|
|
|
struct ie_mcast_cmd *cmd = ptr; /* XXX - Was volatile */
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
cmd->com.ie_cmd_status = SWAP(0);
|
|
|
|
cmd->com.ie_cmd_cmd = IE_CMD_MCAST | IE_CMD_LAST;
|
|
|
|
cmd->com.ie_cmd_link = SWAP(0xffff);
|
|
|
|
|
1995-01-27 02:23:34 +03:00
|
|
|
(sc->sc_bcopy)((caddr_t)sc->mcast_addrs, (caddr_t)cmd->ie_mcast_addrs,
|
1994-12-12 21:58:45 +03:00
|
|
|
sc->mcast_count * sizeof *sc->mcast_addrs);
|
|
|
|
|
|
|
|
cmd->ie_mcast_bytes =
|
1995-01-27 02:23:34 +03:00
|
|
|
SWAP(sc->mcast_count * ETHER_ADDR_LEN); /* grrr... */
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
sc->scb->ie_command_list = vtop16sw(sc, cmd);
|
1996-12-18 00:10:35 +03:00
|
|
|
if (cmd_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL) ||
|
1994-12-12 21:58:45 +03:00
|
|
|
!(cmd->com.ie_cmd_status & IE_STAT_OK)) {
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: multicast address setup command failed\n",
|
1994-12-12 21:58:45 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
static inline void
|
|
|
|
ie_setup_config(cmd, promiscuous, manchester)
|
|
|
|
struct ie_config_cmd *cmd; /* XXX - was volatile */
|
|
|
|
int promiscuous, manchester;
|
|
|
|
{
|
|
|
|
|
|
|
|
/*
|
|
|
|
* these are all char's so no need to byte-swap
|
|
|
|
*/
|
|
|
|
cmd->ie_config_count = 0x0c;
|
|
|
|
cmd->ie_fifo = 8;
|
|
|
|
cmd->ie_save_bad = 0x40;
|
|
|
|
cmd->ie_addr_len = 0x2e;
|
|
|
|
cmd->ie_priority = 0;
|
|
|
|
cmd->ie_ifs = 0x60;
|
|
|
|
cmd->ie_slot_low = 0;
|
|
|
|
cmd->ie_slot_high = 0xf2;
|
|
|
|
cmd->ie_promisc = promiscuous | manchester << 2;
|
|
|
|
cmd->ie_crs_cdt = 0;
|
|
|
|
cmd->ie_min_len = 64;
|
|
|
|
cmd->ie_junk = 0xff;
|
|
|
|
}
|
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
/*
|
|
|
|
* This routine inits the ie.
|
|
|
|
* This includes executing the CONFIGURE, IA-SETUP, and MC-SETUP commands,
|
|
|
|
* starting the receiver unit, and clearing interrupts.
|
|
|
|
*
|
1995-12-24 05:29:35 +03:00
|
|
|
* THIS ROUTINE MUST BE CALLED AT splnet() OR HIGHER.
|
1994-12-12 21:58:45 +03:00
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
static int
|
1994-12-12 21:58:45 +03:00
|
|
|
ieinit(sc)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
|
|
|
volatile struct ie_sys_ctl_block *scb = sc->scb;
|
1995-01-27 02:23:34 +03:00
|
|
|
void *ptr;
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
ifp = &sc->sc_if;
|
1997-02-13 23:48:36 +03:00
|
|
|
ptr = sc->buf_area; /* XXX - Use scb instead? */
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the configure command first.
|
|
|
|
*/
|
|
|
|
{
|
1997-02-13 23:48:36 +03:00
|
|
|
struct ie_config_cmd *cmd = ptr; /* XXX - Was volatile */
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
scb->ie_command_list = vtop16sw(sc, cmd);
|
1994-12-12 21:58:45 +03:00
|
|
|
cmd->com.ie_cmd_status = SWAP(0);
|
|
|
|
cmd->com.ie_cmd_cmd = IE_CMD_CONFIG | IE_CMD_LAST;
|
|
|
|
cmd->com.ie_cmd_link = SWAP(0xffff);
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
ie_setup_config(cmd, (sc->promisc != 0), 0);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1996-12-18 00:10:35 +03:00
|
|
|
if (cmd_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL) ||
|
1994-12-12 21:58:45 +03:00
|
|
|
!(cmd->com.ie_cmd_status & IE_STAT_OK)) {
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: configure command failed\n",
|
1994-12-12 21:58:45 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1994-12-12 21:58:45 +03:00
|
|
|
/*
|
|
|
|
* Now send the Individual Address Setup command.
|
|
|
|
*/
|
|
|
|
{
|
1997-02-13 23:48:36 +03:00
|
|
|
struct ie_iasetup_cmd *cmd = ptr; /* XXX - Was volatile */
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
scb->ie_command_list = vtop16sw(sc, cmd);
|
1994-12-12 21:58:45 +03:00
|
|
|
cmd->com.ie_cmd_status = SWAP(0);
|
|
|
|
cmd->com.ie_cmd_cmd = IE_CMD_IASETUP | IE_CMD_LAST;
|
|
|
|
cmd->com.ie_cmd_link = SWAP(0xffff);
|
|
|
|
|
1997-03-15 21:09:08 +03:00
|
|
|
(sc->sc_bcopy)(LLADDR(ifp->if_sadl),
|
1997-02-13 23:48:36 +03:00
|
|
|
(caddr_t)&cmd->ie_address, sizeof(cmd->ie_address));
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1996-12-18 00:10:35 +03:00
|
|
|
if (cmd_and_wait(sc, IE_CU_START, cmd, IE_STAT_COMPL) ||
|
1994-12-12 21:58:45 +03:00
|
|
|
!(cmd->com.ie_cmd_status & IE_STAT_OK)) {
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("%s: individual address setup command failed\n",
|
1994-12-12 21:58:45 +03:00
|
|
|
sc->sc_dev.dv_xname);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Now run the time-domain reflectometer.
|
|
|
|
*/
|
1997-02-28 20:17:22 +03:00
|
|
|
if (ie_run_tdr)
|
|
|
|
run_tdr(sc, ptr);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Acknowledge any interrupts we have generated thus far.
|
|
|
|
*/
|
|
|
|
ie_ack(sc, IE_ST_WHENCE);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set up the transmit and recv buffers.
|
|
|
|
*/
|
1997-02-13 23:48:36 +03:00
|
|
|
iememinit(sc);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/* tell higher levels that we are here */
|
1997-03-15 21:09:08 +03:00
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
1995-01-27 02:23:34 +03:00
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
sc->scb->ie_recv_list =
|
|
|
|
vtop16sw(sc, (void*) sc->rframes[0]);
|
1996-12-18 00:10:35 +03:00
|
|
|
cmd_and_wait(sc, IE_RU_START, 0, 0);
|
1995-01-27 02:23:34 +03:00
|
|
|
|
|
|
|
ie_ack(sc, IE_ST_WHENCE);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
if (sc->run_586)
|
1995-01-27 02:23:34 +03:00
|
|
|
(sc->run_586)(sc);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
iestop(sc)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
|
|
|
|
1996-12-18 00:10:35 +03:00
|
|
|
cmd_and_wait(sc, IE_RU_DISABLE, 0, 0);
|
1994-12-12 21:58:45 +03:00
|
|
|
}
|
|
|
|
|
1997-02-13 23:48:36 +03:00
|
|
|
static int
|
1994-12-12 21:58:45 +03:00
|
|
|
ieioctl(ifp, cmd, data)
|
|
|
|
register struct ifnet *ifp;
|
1997-02-13 23:48:36 +03:00
|
|
|
u_long cmd;
|
1994-12-12 21:58:45 +03:00
|
|
|
caddr_t data;
|
|
|
|
{
|
1996-05-07 05:35:48 +04:00
|
|
|
struct ie_softc *sc = ifp->if_softc;
|
1997-02-13 23:48:36 +03:00
|
|
|
struct ifaddr *ifa = (struct ifaddr *)data;
|
|
|
|
struct ifreq *ifr = (struct ifreq *)data;
|
|
|
|
int s, error = 0;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
1995-12-24 05:29:35 +03:00
|
|
|
s = splnet();
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
switch (cmd) {
|
|
|
|
|
|
|
|
case SIOCSIFADDR:
|
|
|
|
ifp->if_flags |= IFF_UP;
|
|
|
|
|
|
|
|
switch (ifa->ifa_addr->sa_family) {
|
|
|
|
#ifdef INET
|
|
|
|
case AF_INET:
|
|
|
|
ieinit(sc);
|
1997-03-15 21:09:08 +03:00
|
|
|
arp_ifinit(ifp, ifa);
|
1994-12-12 21:58:45 +03:00
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
#ifdef NS
|
|
|
|
/* XXX - This code is probably wrong. */
|
|
|
|
case AF_NS:
|
|
|
|
{
|
|
|
|
struct ns_addr *ina = &IA_SNS(ifa)->sns_addr;
|
|
|
|
|
|
|
|
if (ns_nullhost(*ina))
|
|
|
|
ina->x_host =
|
1997-03-15 21:09:08 +03:00
|
|
|
*(union ns_host *)LLADDR(ifp->if_sadl);
|
1994-12-12 21:58:45 +03:00
|
|
|
else
|
|
|
|
bcopy(ina->x_host.c_host,
|
1997-03-15 21:09:08 +03:00
|
|
|
LLADDR(ifp->if_sadl), ETHER_ADDR_LEN);
|
1994-12-12 21:58:45 +03:00
|
|
|
/* Set new address. */
|
|
|
|
ieinit(sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#endif /* NS */
|
|
|
|
default:
|
|
|
|
ieinit(sc);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
sc->promisc = ifp->if_flags & (IFF_PROMISC | IFF_ALLMULTI);
|
|
|
|
|
|
|
|
if ((ifp->if_flags & IFF_UP) == 0 &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING) != 0) {
|
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then
|
|
|
|
* stop it.
|
|
|
|
*/
|
|
|
|
iestop(sc);
|
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
} else if ((ifp->if_flags & IFF_UP) != 0 &&
|
1995-01-27 02:23:34 +03:00
|
|
|
(ifp->if_flags & IFF_RUNNING) == 0) {
|
1994-12-12 21:58:45 +03:00
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then
|
|
|
|
* start it.
|
|
|
|
*/
|
|
|
|
ieinit(sc);
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Reset the interface to pick up changes in any other
|
|
|
|
* flags that affect hardware registers.
|
|
|
|
*/
|
|
|
|
iestop(sc);
|
|
|
|
ieinit(sc);
|
|
|
|
}
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
if (ifp->if_flags & IFF_DEBUG)
|
|
|
|
sc->sc_debug = IED_ALL;
|
|
|
|
else
|
1997-02-13 23:48:36 +03:00
|
|
|
sc->sc_debug = ie_debug_flags;
|
1994-12-12 21:58:45 +03:00
|
|
|
#endif
|
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCADDMULTI:
|
|
|
|
case SIOCDELMULTI:
|
|
|
|
error = (cmd == SIOCADDMULTI) ?
|
1997-03-15 21:09:08 +03:00
|
|
|
ether_addmulti(ifr, &sc->sc_ethercom) :
|
|
|
|
ether_delmulti(ifr, &sc->sc_ethercom);
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
if (error == ENETRESET) {
|
|
|
|
/*
|
|
|
|
* Multicast list has changed; set the hardware filter
|
|
|
|
* accordingly.
|
|
|
|
*/
|
|
|
|
mc_reset(sc);
|
|
|
|
error = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
mc_reset(sc)
|
|
|
|
struct ie_softc *sc;
|
|
|
|
{
|
|
|
|
struct ether_multi *enm;
|
|
|
|
struct ether_multistep step;
|
1997-03-15 21:09:08 +03:00
|
|
|
struct ifnet *ifp;
|
|
|
|
|
|
|
|
ifp = &sc->sc_if;
|
1994-12-12 21:58:45 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Step through the list of addresses.
|
|
|
|
*/
|
|
|
|
sc->mcast_count = 0;
|
1997-03-15 21:09:08 +03:00
|
|
|
ETHER_FIRST_MULTI(step, &sc->sc_ethercom, enm);
|
1994-12-12 21:58:45 +03:00
|
|
|
while (enm) {
|
|
|
|
if (sc->mcast_count >= MAXMCAST ||
|
|
|
|
bcmp(enm->enm_addrlo, enm->enm_addrhi, 6) != 0) {
|
1997-03-15 21:09:08 +03:00
|
|
|
ifp->if_flags |= IFF_ALLMULTI;
|
|
|
|
ieioctl(ifp, SIOCSIFFLAGS, (void *)0);
|
1994-12-12 21:58:45 +03:00
|
|
|
goto setflag;
|
|
|
|
}
|
|
|
|
bcopy(enm->enm_addrlo, &sc->mcast_addrs[sc->mcast_count], 6);
|
|
|
|
sc->mcast_count++;
|
|
|
|
ETHER_NEXT_MULTI(step, enm);
|
|
|
|
}
|
|
|
|
setflag:
|
|
|
|
sc->want_mcsetup = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef IEDEBUG
|
|
|
|
void
|
|
|
|
print_rbd(rbd)
|
|
|
|
volatile struct ie_recv_buf_desc *rbd;
|
|
|
|
{
|
|
|
|
|
1996-10-13 07:47:25 +04:00
|
|
|
printf("RBD at %08lx:\nactual %04x, next %04x, buffer %08x\n"
|
1994-12-12 21:58:45 +03:00
|
|
|
"length %04x, mbz %04x\n", (u_long)rbd, rbd->ie_rbd_actual,
|
|
|
|
rbd->ie_rbd_next, rbd->ie_rbd_buffer, rbd->ie_rbd_length,
|
|
|
|
rbd->mbz);
|
|
|
|
}
|
|
|
|
#endif
|