1994-04-07 12:10:31 +00:00
|
|
|
/* Copyright (c) 1994, Matthew E. Kimmel. Permission is hereby granted
|
|
|
|
* to use, copy, modify and distribute this software provided that both
|
|
|
|
* the copyright notice and this permission notice appear in all copies
|
|
|
|
* of the software, derivative works or modified versions, and any
|
|
|
|
* portions thereof.
|
|
|
|
*
|
|
|
|
* Questions, comments, bug reports and fixes to kimmel@cs.umass.edu.
|
1995-05-30 08:16:23 +00:00
|
|
|
*
|
1999-08-28 01:08:13 +00:00
|
|
|
* $FreeBSD$
|
1994-04-07 12:10:31 +00:00
|
|
|
*/
|
|
|
|
/* Except of course for the portions of code lifted from other FreeBSD
|
|
|
|
* drivers (mainly elread, elget and el_ioctl)
|
|
|
|
*/
|
|
|
|
/* 3COM Etherlink 3C501 device driver for FreeBSD */
|
|
|
|
/* Yeah, I know these cards suck, but you can also get them for free
|
|
|
|
* really easily...
|
|
|
|
*/
|
|
|
|
/* Bugs/possible improvements:
|
|
|
|
* - Does not currently support DMA
|
|
|
|
* - Does not currently support multicasts
|
|
|
|
*/
|
|
|
|
#include "el.h"
|
1998-01-08 23:42:31 +00:00
|
|
|
#include "opt_inet.h"
|
1997-12-15 20:31:25 +00:00
|
|
|
#include "opt_ipx.h"
|
1994-04-07 12:10:31 +00:00
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
2000-05-28 13:40:48 +00:00
|
|
|
#include <sys/kernel.h>
|
1997-03-24 11:33:46 +00:00
|
|
|
#include <sys/sockio.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <sys/mbuf.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <sys/syslog.h>
|
2000-05-28 13:40:48 +00:00
|
|
|
#include <sys/bus.h>
|
1994-04-07 12:10:31 +00:00
|
|
|
|
1999-08-18 22:14:24 +00:00
|
|
|
#include <net/ethernet.h>
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <net/if.h>
|
1994-04-07 12:10:31 +00:00
|
|
|
|
1999-08-18 22:14:24 +00:00
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <net/bpf.h>
|
1994-04-07 12:10:31 +00:00
|
|
|
|
1995-03-28 07:58:53 +00:00
|
|
|
#include <machine/clock.h>
|
|
|
|
|
1994-08-13 03:50:34 +00:00
|
|
|
#include <i386/isa/isa_device.h>
|
|
|
|
#include <i386/isa/if_elreg.h>
|
1994-04-07 12:10:31 +00:00
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
#ifndef COMPAT_OLDISA
|
|
|
|
#error "The el device requires the old isa compatibility shims"
|
|
|
|
#endif
|
|
|
|
|
1994-04-07 12:10:31 +00:00
|
|
|
/* For debugging convenience */
|
|
|
|
#ifdef EL_DEBUG
|
|
|
|
#define dprintf(x) printf x
|
|
|
|
#else
|
|
|
|
#define dprintf(x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* el_softc: per line info and status */
|
1995-12-10 13:40:44 +00:00
|
|
|
static struct el_softc {
|
1994-04-07 12:10:31 +00:00
|
|
|
struct arpcom arpcom; /* Ethernet common */
|
|
|
|
u_short el_base; /* Base I/O addr */
|
|
|
|
char el_pktbuf[EL_BUFSIZ]; /* Frame buffer */
|
|
|
|
} el_softc[NEL];
|
|
|
|
|
|
|
|
/* Prototypes */
|
1995-12-10 13:40:44 +00:00
|
|
|
static int el_attach(struct isa_device *);
|
1999-08-20 14:12:14 +00:00
|
|
|
static void el_init(void *);
|
1998-06-07 17:13:14 +00:00
|
|
|
static int el_ioctl(struct ifnet *,u_long,caddr_t);
|
1995-12-10 13:40:44 +00:00
|
|
|
static int el_probe(struct isa_device *);
|
|
|
|
static void el_start(struct ifnet *);
|
1999-08-20 14:12:14 +00:00
|
|
|
static void el_reset(void *);
|
1995-12-10 13:40:44 +00:00
|
|
|
static void el_watchdog(struct ifnet *);
|
1994-04-07 12:10:31 +00:00
|
|
|
|
1999-08-20 14:12:14 +00:00
|
|
|
static void el_stop(void *);
|
1994-04-07 12:10:31 +00:00
|
|
|
static int el_xmit(struct el_softc *,int);
|
1998-10-22 05:58:45 +00:00
|
|
|
static ointhand2_t elintr;
|
1998-04-15 17:47:40 +00:00
|
|
|
static __inline void elread(struct el_softc *,caddr_t,int);
|
2000-05-14 02:18:43 +00:00
|
|
|
static struct mbuf *elget(caddr_t,int,struct ifnet *);
|
1999-08-20 14:12:14 +00:00
|
|
|
static __inline void el_hardreset(void *);
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
/* isa_driver structure for autoconf */
|
|
|
|
struct isa_driver eldriver = {
|
2000-05-28 13:40:48 +00:00
|
|
|
INTR_TYPE_NET,
|
|
|
|
el_probe,
|
|
|
|
el_attach,
|
|
|
|
"el"
|
1994-04-07 12:10:31 +00:00
|
|
|
};
|
2000-05-28 13:40:48 +00:00
|
|
|
COMPAT_ISA_DRIVER(el, eldriver);
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
/* Probe routine. See if the card is there and at the right place. */
|
1995-12-10 13:40:44 +00:00
|
|
|
static int
|
|
|
|
el_probe(struct isa_device *idev)
|
1994-04-07 12:10:31 +00:00
|
|
|
{
|
|
|
|
struct el_softc *sc;
|
|
|
|
u_short base; /* Just for convenience */
|
|
|
|
u_char station_addr[ETHER_ADDR_LEN];
|
|
|
|
int i;
|
|
|
|
|
|
|
|
/* Grab some info for our structure */
|
|
|
|
sc = &el_softc[idev->id_unit];
|
|
|
|
sc->el_base = idev->id_iobase;
|
|
|
|
base = sc->el_base;
|
|
|
|
|
|
|
|
/* First check the base */
|
|
|
|
if((base < 0x280) || (base > 0x3f0)) {
|
|
|
|
printf("el%d: ioaddr must be between 0x280 and 0x3f0\n",
|
|
|
|
idev->id_unit);
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now attempt to grab the station address from the PROM
|
|
|
|
* and see if it contains the 3com vendor code.
|
|
|
|
*/
|
|
|
|
dprintf(("Probing 3c501 at 0x%x...\n",base));
|
|
|
|
|
|
|
|
/* Reset the board */
|
|
|
|
dprintf(("Resetting board...\n"));
|
|
|
|
outb(base+EL_AC,EL_AC_RESET);
|
|
|
|
DELAY(5);
|
|
|
|
outb(base+EL_AC,0);
|
|
|
|
dprintf(("Reading station address...\n"));
|
|
|
|
/* Now read the address */
|
|
|
|
for(i=0;i<ETHER_ADDR_LEN;i++) {
|
|
|
|
outb(base+EL_GPBL,i);
|
|
|
|
station_addr[i] = inb(base+EL_EAW);
|
|
|
|
}
|
1996-01-26 09:29:29 +00:00
|
|
|
dprintf(("Address is %6D\n",station_addr, ":"));
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
/* If the vendor code is ok, return a 1. We'll assume that
|
|
|
|
* whoever configured this system is right about the IRQ.
|
|
|
|
*/
|
|
|
|
if((station_addr[0] != 0x02) || (station_addr[1] != 0x60)
|
|
|
|
|| (station_addr[2] != 0x8c)) {
|
|
|
|
dprintf(("Bad vendor code.\n"));
|
|
|
|
return(0);
|
|
|
|
} else {
|
|
|
|
dprintf(("Vendor code ok.\n"));
|
|
|
|
/* Copy the station address into the arpcom structure */
|
|
|
|
bcopy(station_addr,sc->arpcom.ac_enaddr,ETHER_ADDR_LEN);
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-01-12 01:29:45 +00:00
|
|
|
/* Do a hardware reset of the 3c501. Do not call until after el_probe()! */
|
|
|
|
static __inline void
|
1999-08-20 14:12:14 +00:00
|
|
|
el_hardreset(xsc)
|
|
|
|
void *xsc;
|
1999-01-12 01:29:45 +00:00
|
|
|
{
|
1999-08-20 14:12:14 +00:00
|
|
|
register struct el_softc *sc = xsc;
|
1999-01-12 01:29:45 +00:00
|
|
|
register int base;
|
|
|
|
register int j;
|
|
|
|
|
|
|
|
base = sc->el_base;
|
|
|
|
|
|
|
|
/* First reset the board */
|
|
|
|
outb(base+EL_AC,EL_AC_RESET);
|
|
|
|
DELAY(5);
|
|
|
|
outb(base+EL_AC,0);
|
|
|
|
|
|
|
|
/* Then give it back its ethernet address. Thanks to the mach
|
|
|
|
* source code for this undocumented goodie...
|
|
|
|
*/
|
|
|
|
for(j=0;j<ETHER_ADDR_LEN;j++)
|
|
|
|
outb(base+j,sc->arpcom.ac_enaddr[j]);
|
|
|
|
}
|
|
|
|
|
1994-04-07 12:10:31 +00:00
|
|
|
/* Attach the interface to the kernel data structures. By the time
|
|
|
|
* this is called, we know that the card exists at the given I/O address.
|
|
|
|
* We still assume that the IRQ given is correct.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static int
|
|
|
|
el_attach(struct isa_device *idev)
|
1994-04-07 12:10:31 +00:00
|
|
|
{
|
|
|
|
struct el_softc *sc;
|
|
|
|
struct ifnet *ifp;
|
|
|
|
u_short base;
|
|
|
|
|
|
|
|
dprintf(("Attaching el%d...\n",idev->id_unit));
|
|
|
|
|
|
|
|
/* Get things pointing to the right places. */
|
1998-10-22 05:58:45 +00:00
|
|
|
idev->id_ointr = elintr;
|
1994-04-07 12:10:31 +00:00
|
|
|
sc = &el_softc[idev->id_unit];
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
base = sc->el_base;
|
|
|
|
|
|
|
|
/* Now reset the board */
|
|
|
|
dprintf(("Resetting board...\n"));
|
1999-08-20 14:12:14 +00:00
|
|
|
el_hardreset(sc);
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
/* Initialize ifnet structure */
|
1996-02-06 18:51:28 +00:00
|
|
|
ifp->if_softc = sc;
|
1994-04-07 12:10:31 +00:00
|
|
|
ifp->if_unit = idev->id_unit;
|
|
|
|
ifp->if_name = "el";
|
|
|
|
ifp->if_mtu = ETHERMTU;
|
|
|
|
ifp->if_output = ether_output;
|
|
|
|
ifp->if_start = el_start;
|
|
|
|
ifp->if_ioctl = el_ioctl;
|
|
|
|
ifp->if_watchdog = el_watchdog;
|
1999-08-20 14:12:14 +00:00
|
|
|
ifp->if_init = el_init;
|
1995-10-13 19:48:06 +00:00
|
|
|
ifp->if_flags = (IFF_BROADCAST | IFF_SIMPLEX);
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
/* Now we can attach the interface */
|
|
|
|
dprintf(("Attaching interface...\n"));
|
2000-07-13 22:54:34 +00:00
|
|
|
ether_ifattach(ifp, ETHER_BPF_SUPPORTED);
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
/* Print out some information for the user */
|
1996-01-26 09:29:29 +00:00
|
|
|
printf("el%d: 3c501 address %6D\n",idev->id_unit,
|
|
|
|
sc->arpcom.ac_enaddr, ":");
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
dprintf(("el_attach() finished.\n"));
|
|
|
|
return(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This routine resets the interface. */
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1999-08-20 14:12:14 +00:00
|
|
|
el_reset(xsc)
|
|
|
|
void *xsc;
|
1994-04-07 12:10:31 +00:00
|
|
|
{
|
1999-08-20 14:12:14 +00:00
|
|
|
struct el_softc *sc = xsc;
|
1994-04-07 12:10:31 +00:00
|
|
|
int s;
|
|
|
|
|
|
|
|
dprintf(("elreset()\n"));
|
|
|
|
s = splimp();
|
1999-08-20 14:12:14 +00:00
|
|
|
el_stop(sc);
|
|
|
|
el_init(sc);
|
1994-04-07 12:10:31 +00:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
1999-08-20 14:12:14 +00:00
|
|
|
static void el_stop(xsc)
|
|
|
|
void *xsc;
|
1994-04-07 12:10:31 +00:00
|
|
|
{
|
1999-08-20 14:12:14 +00:00
|
|
|
struct el_softc *sc = xsc;
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
outb(sc->el_base+EL_AC,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Initialize interface. */
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
1999-08-20 14:36:40 +00:00
|
|
|
el_init(xsc)
|
1999-08-20 14:12:14 +00:00
|
|
|
void *xsc;
|
1994-04-07 12:10:31 +00:00
|
|
|
{
|
1999-08-20 14:12:14 +00:00
|
|
|
struct el_softc *sc = xsc;
|
1994-04-07 12:10:31 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
int s;
|
|
|
|
u_short base;
|
|
|
|
|
|
|
|
/* Set up pointers */
|
|
|
|
ifp = &sc->arpcom.ac_if;
|
|
|
|
base = sc->el_base;
|
|
|
|
|
|
|
|
/* If address not known, do nothing. */
|
1996-12-13 21:29:07 +00:00
|
|
|
if(TAILQ_EMPTY(&ifp->if_addrhead)) /* XXX unlikely */
|
1994-04-07 12:10:31 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
|
|
|
/* First, reset the board. */
|
|
|
|
dprintf(("Resetting board...\n"));
|
1999-08-20 14:12:14 +00:00
|
|
|
el_hardreset(sc);
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
/* Configure rx */
|
|
|
|
dprintf(("Configuring rx...\n"));
|
|
|
|
if(ifp->if_flags & IFF_PROMISC)
|
|
|
|
outb(base+EL_RXC,(EL_RXC_PROMISC|EL_RXC_AGF|EL_RXC_DSHORT|EL_RXC_DDRIB|EL_RXC_DOFLOW));
|
|
|
|
else
|
|
|
|
outb(base+EL_RXC,(EL_RXC_ABROAD|EL_RXC_AGF|EL_RXC_DSHORT|EL_RXC_DDRIB|EL_RXC_DOFLOW));
|
|
|
|
outb(base+EL_RBC,0);
|
|
|
|
|
|
|
|
/* Configure TX */
|
|
|
|
dprintf(("Configuring tx...\n"));
|
|
|
|
outb(base+EL_TXC,0);
|
|
|
|
|
|
|
|
/* Start reception */
|
|
|
|
dprintf(("Starting reception...\n"));
|
|
|
|
outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX));
|
|
|
|
|
|
|
|
/* Set flags appropriately */
|
|
|
|
ifp->if_flags |= IFF_RUNNING;
|
|
|
|
ifp->if_flags &= ~IFF_OACTIVE;
|
|
|
|
|
|
|
|
/* And start output. */
|
|
|
|
el_start(ifp);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Start output on interface. Get datagrams from the queue and output
|
|
|
|
* them, giving the receiver a chance between datagrams. Call only
|
|
|
|
* from splimp or interrupt level!
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
|
|
|
el_start(struct ifnet *ifp)
|
1994-04-07 12:10:31 +00:00
|
|
|
{
|
|
|
|
struct el_softc *sc;
|
|
|
|
u_short base;
|
|
|
|
struct mbuf *m, *m0;
|
|
|
|
int s, i, len, retries, done;
|
|
|
|
|
|
|
|
/* Get things pointing in the right directions */
|
1996-02-06 18:51:28 +00:00
|
|
|
sc = ifp->if_softc;
|
1994-04-07 12:10:31 +00:00
|
|
|
base = sc->el_base;
|
|
|
|
|
|
|
|
dprintf(("el_start()...\n"));
|
|
|
|
s = splimp();
|
|
|
|
|
|
|
|
/* Don't do anything if output is active */
|
|
|
|
if(sc->arpcom.ac_if.if_flags & IFF_OACTIVE)
|
|
|
|
return;
|
|
|
|
sc->arpcom.ac_if.if_flags |= IFF_OACTIVE;
|
|
|
|
|
|
|
|
/* The main loop. They warned me against endless loops, but
|
|
|
|
* would I listen? NOOO....
|
|
|
|
*/
|
|
|
|
while(1) {
|
|
|
|
/* Dequeue the next datagram */
|
|
|
|
IF_DEQUEUE(&sc->arpcom.ac_if.if_snd,m0);
|
|
|
|
|
|
|
|
/* If there's nothing to send, return. */
|
|
|
|
if(m0 == NULL) {
|
|
|
|
sc->arpcom.ac_if.if_flags &= ~IFF_OACTIVE;
|
|
|
|
splx(s);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable the receiver */
|
|
|
|
outb(base+EL_AC,EL_AC_HOST);
|
|
|
|
outb(base+EL_RBC,0);
|
|
|
|
|
|
|
|
/* Copy the datagram to the buffer. */
|
|
|
|
len = 0;
|
|
|
|
for(m = m0; m != NULL; m = m->m_next) {
|
|
|
|
if(m->m_len == 0)
|
|
|
|
continue;
|
|
|
|
bcopy(mtod(m,caddr_t),sc->el_pktbuf+len,m->m_len);
|
|
|
|
len += m->m_len;
|
|
|
|
}
|
|
|
|
m_freem(m0);
|
|
|
|
|
1994-05-26 13:30:20 +00:00
|
|
|
len = max(len,ETHER_MIN_LEN);
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
/* Give the packet to the bpf, if any */
|
1996-02-06 18:51:28 +00:00
|
|
|
if(sc->arpcom.ac_if.if_bpf)
|
|
|
|
bpf_tap(&sc->arpcom.ac_if, sc->el_pktbuf, len);
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
/* Transfer datagram to board */
|
|
|
|
dprintf(("el: xfr pkt length=%d...\n",len));
|
|
|
|
i = EL_BUFSIZ - len;
|
|
|
|
outb(base+EL_GPBL,(i & 0xff));
|
|
|
|
outb(base+EL_GPBH,((i>>8)&0xff));
|
|
|
|
outsb(base+EL_BUF,sc->el_pktbuf,len);
|
|
|
|
|
|
|
|
/* Now transmit the datagram */
|
|
|
|
retries=0;
|
|
|
|
done=0;
|
|
|
|
while(!done) {
|
|
|
|
if(el_xmit(sc,len)) { /* Something went wrong */
|
|
|
|
done = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* Check out status */
|
|
|
|
i = inb(base+EL_TXS);
|
|
|
|
dprintf(("tx status=0x%x\n",i));
|
|
|
|
if(!(i & EL_TXS_READY)) {
|
|
|
|
dprintf(("el: err txs=%x\n",i));
|
|
|
|
sc->arpcom.ac_if.if_oerrors++;
|
|
|
|
if(i & (EL_TXS_COLL|EL_TXS_COLL16)) {
|
|
|
|
if((!(i & EL_TXC_DCOLL16)) && retries < 15) {
|
|
|
|
retries++;
|
|
|
|
outb(base+EL_AC,EL_AC_HOST);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
done = 1;
|
1995-05-30 08:16:23 +00:00
|
|
|
}
|
1994-04-07 12:10:31 +00:00
|
|
|
else {
|
|
|
|
sc->arpcom.ac_if.if_opackets++;
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(done == -1) /* Packet not transmitted */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Now give the card a chance to receive.
|
|
|
|
* Gotta love 3c501s...
|
|
|
|
*/
|
|
|
|
(void)inb(base+EL_AS);
|
|
|
|
outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX));
|
|
|
|
splx(s);
|
|
|
|
/* Interrupt here */
|
|
|
|
s = splimp();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This function actually attempts to transmit a datagram downloaded
|
|
|
|
* to the board. Call at splimp or interrupt, after downloading data!
|
|
|
|
* Returns 0 on success, non-0 on failure
|
|
|
|
*/
|
1999-01-12 01:29:45 +00:00
|
|
|
static int
|
|
|
|
el_xmit(struct el_softc *sc,int len)
|
1994-04-07 12:10:31 +00:00
|
|
|
{
|
|
|
|
int gpl;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
gpl = EL_BUFSIZ - len;
|
|
|
|
dprintf(("el: xmit..."));
|
|
|
|
outb((sc->el_base)+EL_GPBL,(gpl & 0xff));
|
|
|
|
outb((sc->el_base)+EL_GPBH,((gpl>>8)&0xff));
|
|
|
|
outb((sc->el_base)+EL_AC,EL_AC_TXFRX);
|
|
|
|
i = 20000;
|
|
|
|
while((inb((sc->el_base)+EL_AS) & EL_AS_TXBUSY) && (i>0))
|
|
|
|
i--;
|
|
|
|
if(i == 0) {
|
|
|
|
dprintf(("tx not ready\n"));
|
|
|
|
sc->arpcom.ac_if.if_oerrors++;
|
|
|
|
return(-1);
|
|
|
|
}
|
|
|
|
dprintf(("%d cycles.\n",(20000-i)));
|
|
|
|
return(0);
|
|
|
|
}
|
|
|
|
|
1999-01-12 01:29:45 +00:00
|
|
|
/* Pass a packet up to the higher levels. */
|
|
|
|
static __inline void
|
|
|
|
elread(struct el_softc *sc,caddr_t buf,int len)
|
|
|
|
{
|
|
|
|
register struct ether_header *eh;
|
|
|
|
struct mbuf *m;
|
|
|
|
|
|
|
|
eh = (struct ether_header *)buf;
|
|
|
|
|
|
|
|
/*
|
2000-05-14 02:18:43 +00:00
|
|
|
* Put packet into an mbuf chain
|
1999-01-12 01:29:45 +00:00
|
|
|
*/
|
2000-05-14 02:18:43 +00:00
|
|
|
m = elget(buf,len,&sc->arpcom.ac_if);
|
1999-01-12 01:29:45 +00:00
|
|
|
if(m == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
ether_input(&sc->arpcom.ac_if,eh,m);
|
|
|
|
}
|
|
|
|
|
1994-04-07 12:10:31 +00:00
|
|
|
/* controller interrupt */
|
1999-01-12 01:29:45 +00:00
|
|
|
static void
|
|
|
|
elintr(int unit)
|
1994-04-07 12:10:31 +00:00
|
|
|
{
|
|
|
|
register struct el_softc *sc;
|
1998-06-21 15:54:11 +00:00
|
|
|
register int base;
|
1994-04-07 12:10:31 +00:00
|
|
|
int stat, rxstat, len, done;
|
|
|
|
|
|
|
|
/* Get things pointing properly */
|
|
|
|
sc = &el_softc[unit];
|
|
|
|
base = sc->el_base;
|
|
|
|
|
|
|
|
dprintf(("elintr: "));
|
|
|
|
|
|
|
|
/* Check board status */
|
|
|
|
stat = inb(base+EL_AS);
|
|
|
|
if(stat & EL_AS_RXBUSY) {
|
|
|
|
(void)inb(base+EL_RXC);
|
|
|
|
outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
done = 0;
|
|
|
|
while(!done) {
|
|
|
|
rxstat = inb(base+EL_RXS);
|
|
|
|
if(rxstat & EL_RXS_STALE) {
|
|
|
|
(void)inb(base+EL_RXC);
|
|
|
|
outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If there's an overflow, reinit the board. */
|
|
|
|
if(!(rxstat & EL_RXS_NOFLOW)) {
|
|
|
|
dprintf(("overflow.\n"));
|
1999-08-20 14:12:14 +00:00
|
|
|
el_hardreset(sc);
|
1994-04-07 12:10:31 +00:00
|
|
|
/* Put board back into receive mode */
|
|
|
|
if(sc->arpcom.ac_if.if_flags & IFF_PROMISC)
|
|
|
|
outb(base+EL_RXC,(EL_RXC_PROMISC|EL_RXC_AGF|EL_RXC_DSHORT|EL_RXC_DDRIB|EL_RXC_DOFLOW));
|
|
|
|
else
|
|
|
|
outb(base+EL_RXC,(EL_RXC_ABROAD|EL_RXC_AGF|EL_RXC_DSHORT|EL_RXC_DDRIB|EL_RXC_DOFLOW));
|
|
|
|
(void)inb(base+EL_AS);
|
|
|
|
outb(base+EL_RBC,0);
|
|
|
|
(void)inb(base+EL_RXC);
|
|
|
|
outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Incoming packet */
|
|
|
|
len = inb(base+EL_RBL);
|
|
|
|
len |= inb(base+EL_RBH) << 8;
|
|
|
|
dprintf(("receive len=%d rxstat=%x ",len,rxstat));
|
|
|
|
outb(base+EL_AC,EL_AC_HOST);
|
|
|
|
|
|
|
|
/* If packet too short or too long, restore rx mode and return
|
|
|
|
*/
|
|
|
|
if((len <= sizeof(struct ether_header)) || (len > ETHER_MAX_LEN)) {
|
|
|
|
if(sc->arpcom.ac_if.if_flags & IFF_PROMISC)
|
|
|
|
outb(base+EL_RXC,(EL_RXC_PROMISC|EL_RXC_AGF|EL_RXC_DSHORT|EL_RXC_DDRIB|EL_RXC_DOFLOW));
|
|
|
|
else
|
|
|
|
outb(base+EL_RXC,(EL_RXC_ABROAD|EL_RXC_AGF|EL_RXC_DSHORT|EL_RXC_DDRIB|EL_RXC_DOFLOW));
|
|
|
|
(void)inb(base+EL_AS);
|
|
|
|
outb(base+EL_RBC,0);
|
|
|
|
(void)inb(base+EL_RXC);
|
|
|
|
outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sc->arpcom.ac_if.if_ipackets++;
|
|
|
|
|
|
|
|
/* Copy the data into our buffer */
|
|
|
|
outb(base+EL_GPBL,0);
|
|
|
|
outb(base+EL_GPBH,0);
|
|
|
|
insb(base+EL_BUF,sc->el_pktbuf,len);
|
|
|
|
outb(base+EL_RBC,0);
|
|
|
|
outb(base+EL_AC,EL_AC_RX);
|
1996-01-26 09:29:29 +00:00
|
|
|
dprintf(("%6D-->",sc->el_pktbuf+6,":"));
|
|
|
|
dprintf(("%6D\n",sc->el_pktbuf,":"));
|
1994-04-07 12:10:31 +00:00
|
|
|
|
|
|
|
/* Pass data up to upper levels */
|
|
|
|
len -= sizeof(struct ether_header);
|
|
|
|
elread(sc,(caddr_t)(sc->el_pktbuf),len);
|
|
|
|
|
|
|
|
/* Is there another packet? */
|
|
|
|
stat = inb(base+EL_AS);
|
|
|
|
|
|
|
|
/* If so, do it all again (i.e. don't set done to 1) */
|
1995-05-30 08:16:23 +00:00
|
|
|
if(!(stat & EL_AS_RXBUSY))
|
1994-04-07 12:10:31 +00:00
|
|
|
dprintf(("<rescan> "));
|
|
|
|
else
|
|
|
|
done = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
(void)inb(base+EL_RXC);
|
|
|
|
outb(base+EL_AC,(EL_AC_IRQE|EL_AC_RX));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull read data off a interface.
|
|
|
|
* Len is length of data, with local net header stripped.
|
|
|
|
*/
|
2000-05-14 02:18:43 +00:00
|
|
|
static struct mbuf *
|
|
|
|
elget(buf, totlen, ifp)
|
1994-04-07 12:10:31 +00:00
|
|
|
caddr_t buf;
|
2000-05-14 02:18:43 +00:00
|
|
|
int totlen;
|
1994-04-07 12:10:31 +00:00
|
|
|
struct ifnet *ifp;
|
|
|
|
{
|
1995-10-28 15:39:31 +00:00
|
|
|
struct mbuf *top, **mp, *m;
|
2000-05-14 02:18:43 +00:00
|
|
|
int len;
|
|
|
|
register caddr_t cp;
|
1994-04-07 12:10:31 +00:00
|
|
|
char *epkt;
|
|
|
|
|
|
|
|
buf += sizeof(struct ether_header);
|
|
|
|
cp = buf;
|
|
|
|
epkt = cp + totlen;
|
|
|
|
|
|
|
|
MGETHDR(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0)
|
|
|
|
return (0);
|
|
|
|
m->m_pkthdr.rcvif = ifp;
|
|
|
|
m->m_pkthdr.len = totlen;
|
|
|
|
m->m_len = MHLEN;
|
|
|
|
top = 0;
|
|
|
|
mp = ⊤
|
|
|
|
while (totlen > 0) {
|
|
|
|
if (top) {
|
|
|
|
MGET(m, M_DONTWAIT, MT_DATA);
|
|
|
|
if (m == 0) {
|
|
|
|
m_freem(top);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
m->m_len = MLEN;
|
|
|
|
}
|
|
|
|
len = min(totlen, epkt - cp);
|
|
|
|
if (len >= MINCLSIZE) {
|
|
|
|
MCLGET(m, M_DONTWAIT);
|
|
|
|
if (m->m_flags & M_EXT)
|
|
|
|
m->m_len = len = min(len, MCLBYTES);
|
|
|
|
else
|
|
|
|
len = m->m_len;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Place initial small packet/header at end of mbuf.
|
|
|
|
*/
|
|
|
|
if (len < m->m_len) {
|
|
|
|
if (top == 0 && len + max_linkhdr <= m->m_len)
|
|
|
|
m->m_data += max_linkhdr;
|
|
|
|
m->m_len = len;
|
|
|
|
} else
|
|
|
|
len = m->m_len;
|
|
|
|
}
|
|
|
|
bcopy(cp, mtod(m, caddr_t), (unsigned)len);
|
|
|
|
cp += len;
|
|
|
|
*mp = m;
|
|
|
|
mp = &m->m_next;
|
|
|
|
totlen -= len;
|
|
|
|
if (cp == epkt)
|
|
|
|
cp = buf;
|
|
|
|
}
|
|
|
|
return (top);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Process an ioctl request. This code needs some work - it looks
|
|
|
|
* pretty ugly.
|
|
|
|
*/
|
1995-12-10 13:40:44 +00:00
|
|
|
static int
|
1994-04-07 12:10:31 +00:00
|
|
|
el_ioctl(ifp, command, data)
|
|
|
|
register struct ifnet *ifp;
|
1998-06-07 17:13:14 +00:00
|
|
|
u_long command;
|
1994-04-07 12:10:31 +00:00
|
|
|
caddr_t data;
|
|
|
|
{
|
|
|
|
int s, error = 0;
|
|
|
|
|
|
|
|
s = splimp();
|
|
|
|
|
|
|
|
switch (command) {
|
1999-08-18 06:12:00 +00:00
|
|
|
case SIOCSIFADDR:
|
1994-04-07 12:10:31 +00:00
|
|
|
case SIOCGIFADDR:
|
1999-08-18 06:12:00 +00:00
|
|
|
case SIOCSIFMTU:
|
|
|
|
error = ether_ioctl(ifp, command, data);
|
1994-04-07 12:10:31 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SIOCSIFFLAGS:
|
|
|
|
/*
|
|
|
|
* If interface is marked down and it is running, then stop it
|
|
|
|
*/
|
|
|
|
if (((ifp->if_flags & IFF_UP) == 0) &&
|
|
|
|
(ifp->if_flags & IFF_RUNNING)) {
|
1999-08-20 14:12:14 +00:00
|
|
|
el_stop(ifp->if_softc);
|
1994-04-07 12:10:31 +00:00
|
|
|
ifp->if_flags &= ~IFF_RUNNING;
|
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* If interface is marked up and it is stopped, then start it
|
|
|
|
*/
|
|
|
|
if ((ifp->if_flags & IFF_UP) &&
|
|
|
|
((ifp->if_flags & IFF_RUNNING) == 0))
|
1999-08-20 14:12:14 +00:00
|
|
|
el_init(ifp->if_softc);
|
1994-04-07 12:10:31 +00:00
|
|
|
}
|
1995-06-11 19:33:05 +00:00
|
|
|
break;
|
1994-04-07 12:10:31 +00:00
|
|
|
default:
|
|
|
|
error = EINVAL;
|
|
|
|
}
|
|
|
|
(void) splx(s);
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Device timeout routine */
|
1995-12-10 13:40:44 +00:00
|
|
|
static void
|
|
|
|
el_watchdog(struct ifnet *ifp)
|
1994-04-07 12:10:31 +00:00
|
|
|
{
|
1996-02-06 18:51:28 +00:00
|
|
|
log(LOG_ERR,"el%d: device timeout\n", ifp->if_unit);
|
1995-12-05 02:01:59 +00:00
|
|
|
ifp->if_oerrors++;
|
1999-08-20 14:12:14 +00:00
|
|
|
el_reset(ifp->if_softc);
|
1994-04-07 12:10:31 +00:00
|
|
|
}
|