/*
* Copyright (c) 1982, 1986, 1989 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. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)if_de.c 7.12 (Berkeley) 12/16/90
*/
/*
* Copyright (c) 2000 Ludd, University of Lule}, Sweden.
* 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.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* DEC DEUNA interface
*
* Lou Salkind
* New York University
*
* Rewritten by Ragge 30 April 2000 to match new world.
*
* TODO:
* timeout routine (get statistics)
*/
/*
* Be careful with transmit/receive buffers, each entry steals 4 map
* registers, and there is only 496 on one unibus...
*/
#define NRCV 7 /* number of receive buffers (must be > 1) */
#define NXMT 3 /* number of transmit buffers */
/*
* Structure containing the elements that must be in DMA-safe memory.
*/
struct de_cdata {
/* the following structures are always mapped in */
struct de_pcbb dc_pcbb; /* port control block */
struct de_ring dc_xrent[NXMT]; /* transmit ring entrys */
struct de_ring dc_rrent[NRCV]; /* receive ring entrys */
struct de_udbbuf dc_udbbuf; /* UNIBUS data buffer */
/* end mapped area */
};
/*
* Ethernet software status per interface.
*
* Each interface is referenced by a network interface structure,
* ds_if, which the routing code uses to locate the interface.
* This structure contains the output queue for the interface, its address, ...
* We also have, for each interface, a UBA interface structure, which
* contains information about the UNIBUS resources held by the interface:
* map registers, buffered data paths, etc. Information is cached in this
* structure for use by the if_uba.c routines in running the interface
* efficiently.
*/
struct de_softc {
device_t sc_dev; /* Configuration common part */
struct uba_softc *sc_uh; /* our parent */
struct evcnt sc_intrcnt; /* Interrupt counting */
struct ethercom sc_ec; /* Ethernet common part */
#define sc_if sc_ec.ec_if /* network-visible interface */
bus_space_tag_t sc_iot;
bus_addr_t sc_ioh;
bus_dma_tag_t sc_dmat;
int sc_flags;
#define DSF_MAPPED 1
struct ubinfo sc_ui;
struct de_cdata *sc_dedata; /* Control structure */
struct de_cdata *sc_pdedata; /* Bus-mapped control structure */
struct ifubinfo sc_ifuba; /* UNIBUS resources */
struct ifrw sc_ifr[NRCV]; /* UNIBUS receive buffer maps */
struct ifxmt sc_ifw[NXMT]; /* UNIBUS receive buffer maps */
int sc_xindex; /* UNA index into transmit chain */
int sc_rindex; /* UNA index into receive chain */
int sc_xfree; /* index for next transmit buffer */
int sc_nxmit; /* # of transmits in progress */
void *sc_sh; /* shutdownhook cookie */
};
/*
* What kind of a board is this?
* The error bits 4-6 in pcsr1 are a device id as long as
* the high byte is zero.
*/
csr1 = DE_RCSR(DE_PCSR1);
if (csr1 & 0xff60)
c = "broken";
else if (csr1 & 0x10)
c = "delua";
else
c = "deuna";
/*
* Reset the board and temporarily map
* the pcbb buffer onto the Unibus.
*/
DE_WCSR(DE_PCSR0, 0); /* reset INTE */
DELAY(100);
DE_WCSR(DE_PCSR0, PCSR0_RSET);
dewait(sc, "reset");
/*
* Tell the DEUNA about our PCB
*/
DE_WCSR(DE_PCSR2, LOWORD(sc->sc_pdedata));
DE_WCSR(DE_PCSR3, HIWORD(sc->sc_pdedata));
DE_WLOW(0); /* reset INTE */
DELAY(500);
DE_WLOW(CMD_GETPCBB);
dewait(sc, "pcbb");
dc = sc->sc_dedata;
pdc = sc->sc_pdedata;
/* set the transmit and receive ring header addresses */
dc->dc_pcbb.pcbb0 = FC_WTRING;
dc->dc_pcbb.pcbb2 = LOWORD(&pdc->dc_udbbuf);
dc->dc_pcbb.pcbb4 = HIWORD(&pdc->dc_udbbuf);
/*
* Setup output on interface.
* Get another datagram to send off of the interface queue,
* and map it to the interface before starting the output.
* Must be called from ipl >= our interrupt level.
*/
void
destart(struct ifnet *ifp)
{
struct de_softc *sc = ifp->if_softc;
struct de_cdata *dc;
struct de_ring *rp;
struct mbuf *m;
int nxmit, len;
/*
* the following test is necessary, since
* the code is not reentrant and we have
* multiple transmission buffers.
*/
if (sc->sc_if.if_flags & IFF_OACTIVE)
return;
dc = sc->sc_dedata;
for (nxmit = sc->sc_nxmit; nxmit < NXMT; nxmit++) {
IFQ_DEQUEUE(&ifp->if_snd, m);
if (m == 0)
break;
rp = &dc->dc_xrent[sc->sc_xfree];
if (rp->r_flags & XFLG_OWN)
panic("deuna xmit in progress");
bpf_mtap(ifp, m, BPF_D_OUT);
/* save flags right away - clear out interrupt bits */
csr0 = DE_RCSR(DE_PCSR0);
DE_WHIGH(csr0 >> 8);
sc->sc_if.if_flags |= IFF_OACTIVE; /* prevent entering destart */
/*
* if receive, put receive buffer on mbuf
* and hang the request again
*/
derecv(sc);
/*
* Poll transmit ring and check status.
* Be careful about loopback requests.
* Then free buffer space and check for
* more transmit requests.
*/
dc = sc->sc_dedata;
for ( ; sc->sc_nxmit > 0; sc->sc_nxmit--) {
rp = &dc->dc_xrent[sc->sc_xindex];
if (rp->r_flags & XFLG_OWN)
break;
if_statinc(&sc->sc_if, if_opackets);
ifxp = &sc->sc_ifw[sc->sc_xindex];
/* check for unusual conditions */
if (rp->r_flags & (XFLG_ERRS|XFLG_MTCH|XFLG_ONE|XFLG_MORE)) {
if (rp->r_flags & XFLG_ERRS) {
/* output error */
if_statinc(&sc->sc_if, if_oerrors);
} else if (rp->r_flags & XFLG_ONE) {
/* one collision */
if_statinc(&sc->sc_if, if_collisions);
} else if (rp->r_flags & XFLG_MORE) {
/* more than one collision (guess...) */
if_statadd(&sc->sc_if, if_collisions, 2);
}
}
if_ubaend(&sc->sc_ifuba, ifxp);
/* check if next transmit buffer also finished */
sc->sc_xindex++;
if (sc->sc_xindex == NXMT)
sc->sc_xindex = 0;
}
sc->sc_if.if_flags &= ~IFF_OACTIVE;
destart(&sc->sc_if);
if (csr0 & PCSR0_RCBI) {
DE_WLOW(PCSR0_INTE|CMD_PDMD);
}
}
/*
* Ethernet interface receiver interface.
* If input error just drop packet.
* Otherwise purge input buffered data path and examine
* packet to determine type. If can't determine length
* from type, then have to drop packet. Otherwise decapsulate
* packet based on type and pass to type specific higher-level
* input routine.
*/
void
derecv(struct de_softc *sc)
{
struct ifnet *ifp = &sc->sc_if;
struct de_ring *rp;
struct de_cdata *dc;
struct mbuf *m;
int len;
dc = sc->sc_dedata;
rp = &dc->dc_rrent[sc->sc_rindex];
while ((rp->r_flags & RFLG_OWN) == 0) {
len = (rp->r_lenerr&RERR_MLEN) - ETHER_CRC_LEN;
/* check for errors */
if ((rp->r_flags & (RFLG_ERRS|RFLG_FRAM|RFLG_OFLO|RFLG_CRC)) ||
(rp->r_lenerr & (RERR_BUFL|RERR_UBTO))) {
if_statinc(&sc->sc_if, if_ierrors);
goto next;
}
m = if_ubaget(&sc->sc_ifuba, &sc->sc_ifr[sc->sc_rindex],
ifp, len);
if (m == 0) {
if_statinc(&sc->sc_if, if_ierrors);
goto next;
}
if_percpuq_enqueue(ifp->if_percpuq, m);
/* hang the receive buffer again */
next: rp->r_lenerr = 0;
rp->r_flags = RFLG_OWN;
/* check next receive buffer */
sc->sc_rindex++;
if (sc->sc_rindex == NRCV)
sc->sc_rindex = 0;
rp = &dc->dc_rrent[sc->sc_rindex];
}
}
/*
* Process an ioctl request.
*/
int
deioctl(struct ifnet *ifp, u_long cmd, void *data)
{
int s, error = 0;
sc->sc_iot = ua->ua_iot;
sc->sc_ioh = ua->ua_ioh;
/*
* Make sure self-test is finished before we screw with the board.
* Self-test on a DELUA can take 15 seconds (argh).
*/
for (i = 0;
(i < 160) &&
(DE_RCSR(DE_PCSR0) & PCSR0_FATI) == 0 &&
(DE_RCSR(DE_PCSR1) & PCSR1_STMASK) == STAT_RESET;
++i)
DELAY(50000);
if (((DE_RCSR(DE_PCSR0) & PCSR0_FATI) != 0) ||
(((DE_RCSR(DE_PCSR1) & PCSR1_STMASK) != STAT_READY) &&
((DE_RCSR(DE_PCSR1) & PCSR1_STMASK) != STAT_RUN)))
return(0);
DE_WCSR(DE_PCSR0, 0);
DELAY(5000);
DE_WCSR(DE_PCSR0, PCSR0_RSET);
while ((DE_RCSR(DE_PCSR0) & PCSR0_INTR) == 0)
;
/* make board interrupt by executing a GETPCBB command */
DE_WCSR(DE_PCSR0, PCSR0_INTE);
DE_WCSR(DE_PCSR2, 0);
DE_WCSR(DE_PCSR3, 0);
DE_WCSR(DE_PCSR0, PCSR0_INTE|CMD_GETPCBB);
DELAY(50000);