Index: arch/mac68k/conf/GENERIC =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/conf/GENERIC,v retrieving revision 1.179 diff -u -r1.179 GENERIC --- arch/mac68k/conf/GENERIC 6 Mar 2007 11:28:47 -0000 1.179 +++ arch/mac68k/conf/GENERIC 31 May 2007 11:27:12 -0000 @@ -201,8 +201,6 @@ mainbus0 at root -fpu0 at mainbus? # Floating-Point Coprocessor support - # Basic Bus Support Index: arch/mac68k/conf/INSTALL =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/conf/INSTALL,v retrieving revision 1.40 diff -u -r1.40 INSTALL --- arch/mac68k/conf/INSTALL 29 Dec 2006 21:49:03 -0000 1.40 +++ arch/mac68k/conf/INSTALL 31 May 2007 11:27:12 -0000 @@ -95,8 +95,6 @@ mainbus0 at root -fpu0 at mainbus? # Floating-Point Coprocessor support - # Basic Bus Support Index: arch/mac68k/conf/SMALLRAM =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/conf/SMALLRAM,v retrieving revision 1.27 diff -u -r1.27 SMALLRAM --- arch/mac68k/conf/SMALLRAM 26 Aug 2006 20:26:55 -0000 1.27 +++ arch/mac68k/conf/SMALLRAM 31 May 2007 11:27:12 -0000 @@ -169,8 +169,6 @@ mainbus0 at root -fpu0 at mainbus? # Floating-Point Coprocessor support - # Basic Bus Support Index: arch/mac68k/conf/files.mac68k =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/conf/files.mac68k,v retrieving revision 1.116 diff -u -r1.116 files.mac68k --- arch/mac68k/conf/files.mac68k 8 Mar 2007 02:24:39 -0000 1.116 +++ arch/mac68k/conf/files.mac68k 31 May 2007 11:27:13 -0000 @@ -82,10 +82,11 @@ file arch/mac68k/obio/if_mc_obio.c mc_obio device sn: ifnet, ether, arp -attach sn at obio with sn_obio -attach sn at nubus with sn_nubus +file dev/ic/dp83932.c sn file arch/mac68k/dev/if_sn.c sn +attach sn at obio with sn_obio file arch/mac68k/obio/if_sn_obio.c sn_obio +attach sn at nubus with sn_nubus file arch/mac68k/nubus/if_sn_nubus.c sn_nubus attach sm at nubus with sm_nubus @@ -143,22 +144,18 @@ file dev/ic/z8530tty.c zstty needs-flag file arch/mac68k/dev/zs_kgdb.c kgdb -# This one is out of alphabetical order -device fpu -attach fpu at mainbus -file arch/mac68k/mac68k/fpu.c fpu - -include "arch/m68k/fpe/files.fpe" - # legitimate pseudo-devices defpseudo grf defpseudo ite +include "arch/m68k/fpe/files.fpe" + file arch/mac68k/mac68k/autoconf.c file arch/mac68k/mac68k/bus_space.c file arch/mac68k/mac68k/clock.c file arch/mac68k/mac68k/conf.c file arch/mac68k/mac68k/disksubr.c disk +file arch/mac68k/mac68k/fpu.c file arch/mac68k/mac68k/intr.c file arch/mac68k/mac68k/iop.c file arch/mac68k/mac68k/machdep.c Index: arch/mac68k/dev/if_sn.c =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/dev/if_sn.c,v retrieving revision 1.45 diff -u -r1.45 if_sn.c --- arch/mac68k/dev/if_sn.c 8 Mar 2007 12:57:20 -0000 1.45 +++ arch/mac68k/dev/if_sn.c 31 May 2007 11:27:13 -0000 @@ -18,1173 +18,20 @@ #include __KERNEL_RCSID(0, "$NetBSD: if_sn.c,v 1.45 2007/03/08 12:57:20 tsutsui Exp $"); -#include "opt_inet.h" - #include #include -#include -#include -#include -#include -#include -#include -#include -#include - -#include #include -#include #include -#ifdef INET -#include -#include -#include -#include -#include -#endif - -#include "bpfilter.h" -#if NBPFILTER > 0 -#include -#include -#endif - #include -#include -#include -#include -#include - -static void snwatchdog(struct ifnet *); -static int sninit(struct sn_softc *); -static int snstop(struct sn_softc *); -static int snioctl(struct ifnet *, u_long, void *); -static void snstart(struct ifnet *); -static void snreset(struct sn_softc *); - -static void caminitialise(struct sn_softc *); -static void camentry(struct sn_softc *, int, u_char *); -static void camprogram(struct sn_softc *); -static void initialise_tda(struct sn_softc *); -static void initialise_rda(struct sn_softc *); -static void initialise_rra(struct sn_softc *); -#ifdef SNDEBUG -static void camdump(struct sn_softc *); -#endif - -static void sonictxint(struct sn_softc *); -static void sonicrxint(struct sn_softc *); - -static inline u_int sonicput(struct sn_softc *, struct mbuf *, int); -static inline int sonic_read(struct sn_softc *, void *, int); -static inline struct mbuf *sonic_get(struct sn_softc *, void *, int); - -#undef assert -#undef _assert - -#ifdef NDEBUG -#define assert(e) ((void)0) -#define _assert(e) ((void)0) -#else -#define _assert(e) assert(e) -#ifdef __STDC__ -#define assert(e) ((e) ? (void)0 : __assert("sn ", __FILE__, __LINE__, #e)) -#else /* PCC */ -#define assert(e) ((e) ? (void)0 : __assert("sn "__FILE__, __LINE__, "e")) -#endif -#endif - -int sndebug = 0; - -/* - * SONIC buffers need to be aligned 16 or 32 bit aligned. - * These macros calculate and verify alignment. - */ -#define SOALIGN(m, array) (m ? (roundup((int)array, 4)) : \ - (roundup((int)array, 2))) - -#define LOWER(x) ((unsigned)(x) & 0xffff) -#define UPPER(x) ((unsigned)(x) >> 16) - -/* - * Interface exists: make available by filling in network interface - * record. System will initialize the interface when it is ready - * to accept packets. - */ -int -snsetup(struct sn_softc *sc, u_int8_t *lladdr) -{ - struct ifnet *ifp = &sc->sc_if; - u_char *p; - u_char *pp; - int i; - int offset; - - /* - * XXX if_sn.c is intended to be MI. Should it allocate memory - * for its descriptor areas, or expect the MD attach code - * to do that? - */ - sc->space = malloc((SN_NPAGES + 1) * PAGE_SIZE, M_DEVBUF, M_WAITOK); - if (sc->space == NULL) { - printf ("%s: memory allocation for descriptors failed\n", - sc->sc_dev.dv_xname); - return (1); - } - - /* - * Put the pup in reset mode (sninit() will fix it later), - * stop the timer, disable all interrupts and clear any interrupts. - */ - NIC_PUT(sc, SNR_CR, CR_STP); - wbflush(); - NIC_PUT(sc, SNR_CR, CR_RST); - wbflush(); - NIC_PUT(sc, SNR_IMR, 0); - wbflush(); - NIC_PUT(sc, SNR_ISR, ISR_ALL); - wbflush(); - - /* - * because the SONIC is basically 16bit device it 'concatenates' - * a higher buffer address to a 16 bit offset--this will cause wrap - * around problems near the end of 64k !! - */ - p = sc->space; - pp = (u_char *)roundup((int)p, PAGE_SIZE); - p = pp; - - /* - * Disable caching on the SONIC's data space. - * The pages might not be physically contiguous, so set - * each page individually. - */ - for (i = 0; i < SN_NPAGES; i++) { - physaccess (p, (void *)SONIC_GETDMA(p), PAGE_SIZE, - PG_V | PG_RW | PG_CI); - p += PAGE_SIZE; - } - p = pp; - - for (i = 0; i < NRRA; i++) { - sc->p_rra[i] = (void *)p; - sc->v_rra[i] = SONIC_GETDMA(p); - p += RXRSRC_SIZE(sc); - } - sc->v_rea = SONIC_GETDMA(p); - - p = (u_char *)SOALIGN(sc, p); - - sc->p_cda = (void *)(p); - sc->v_cda = SONIC_GETDMA(p); - p += CDA_SIZE(sc); - - p = (u_char *)SOALIGN(sc, p); - - for (i = 0; i < NTDA; i++) { - struct mtd *mtdp = &sc->mtda[i]; - mtdp->mtd_txp = (void *)p; - mtdp->mtd_vtxp = SONIC_GETDMA(p); - p += TXP_SIZE(sc); - } - - p = (u_char *)SOALIGN(sc, p); - - if ((p - pp) > PAGE_SIZE) { - printf ("%s: sizeof RRA (%ld) + CDA (%ld) +" - "TDA (%ld) > PAGE_SIZE (%d). Punt!\n", - sc->sc_dev.dv_xname, - (ulong)sc->p_cda - (ulong)sc->p_rra[0], - (ulong)sc->mtda[0].mtd_txp - (ulong)sc->p_cda, - (ulong)p - (ulong)sc->mtda[0].mtd_txp, - PAGE_SIZE); - return(1); - } - - p = pp + PAGE_SIZE; - pp = p; - - sc->sc_nrda = PAGE_SIZE / RXPKT_SIZE(sc); - sc->p_rda = (void *) p; - sc->v_rda = SONIC_GETDMA(p); - - p = pp + PAGE_SIZE; - - for (i = 0; i < NRBA; i++) { - sc->rbuf[i] = (void *)p; - p += PAGE_SIZE; - } - - pp = p; - offset = TXBSIZE; - for (i = 0; i < NTDA; i++) { - struct mtd *mtdp = &sc->mtda[i]; - - mtdp->mtd_buf = p; - mtdp->mtd_vbuf = SONIC_GETDMA(p); - offset += TXBSIZE; - if (offset < PAGE_SIZE) { - p += TXBSIZE; - } else { - p = pp + PAGE_SIZE; - pp = p; - offset = TXBSIZE; - } - } - -#ifdef SNDEBUG - camdump(sc); -#endif - printf("%s: Ethernet address %s\n", - sc->sc_dev.dv_xname, ether_sprintf(lladdr)); - -#ifdef SNDEBUG - printf("%s: buffers: rra=%p cda=%p rda=%p tda=%p\n", - sc->sc_dev.dv_xname, sc->p_rra[0], sc->p_cda, - sc->p_rda, sc->mtda[0].mtd_txp); -#endif - - memcpy(ifp->if_xname, sc->sc_dev.dv_xname, IFNAMSIZ); - ifp->if_softc = sc; - ifp->if_ioctl = snioctl; - ifp->if_start = snstart; - ifp->if_flags = - IFF_BROADCAST | IFF_SIMPLEX | IFF_NOTRAILERS | IFF_MULTICAST; - ifp->if_watchdog = snwatchdog; - - if_attach(ifp); - ether_ifattach(ifp, lladdr); - - return (0); -} - -static int -snioctl(struct ifnet *ifp, u_long cmd, void *data) -{ - struct ifaddr *ifa; - struct ifreq *ifr; - struct sn_softc *sc = ifp->if_softc; - int s, err = 0; - int temp; - - s = splnet(); - - switch (cmd) { - - case SIOCSIFADDR: - ifa = (struct ifaddr *)data; - ifp->if_flags |= IFF_UP; - switch (ifa->ifa_addr->sa_family) { -#ifdef INET - case AF_INET: - (void)sninit(sc); - arp_ifinit(ifp, ifa); - break; -#endif - default: - (void)sninit(sc); - break; - } - break; - - case SIOCSIFFLAGS: - 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. - */ - snstop(sc); - ifp->if_flags &= ~IFF_RUNNING; - } else if ((ifp->if_flags & IFF_UP) != 0 && - (ifp->if_flags & IFF_RUNNING) == 0) { - /* - * If interface is marked up and it is stopped, - * then start it. - */ - (void)sninit(sc); - } else { - /* - * reset the interface to pick up any other changes - * in flags - */ - temp = ifp->if_flags & IFF_UP; - snreset(sc); - ifp->if_flags |= temp; - snstart(ifp); - } - break; - - case SIOCADDMULTI: - case SIOCDELMULTI: - ifr = (struct ifreq *) data; - if (cmd == SIOCADDMULTI) - err = ether_addmulti(ifr, &sc->sc_ethercom); - else - err = ether_delmulti(ifr, &sc->sc_ethercom); - - if (err == ENETRESET) { - /* - * Multicast list has changed; set the hardware - * filter accordingly. But remember UP flag! - */ - if (ifp->if_flags & IFF_RUNNING) { - temp = ifp->if_flags & IFF_UP; - snreset(sc); - ifp->if_flags |= temp; - } - err = 0; - } - break; - default: - err = EINVAL; - } - splx(s); - return (err); -} - -/* - * Encapsulate a packet of type family for the local net. - */ -static void -snstart(struct ifnet *ifp) -{ - struct sn_softc *sc = ifp->if_softc; - struct mbuf *m; - int mtd_next; - if ((ifp->if_flags & (IFF_RUNNING | IFF_OACTIVE)) != IFF_RUNNING) - return; - -outloop: - /* Check for room in the xmit buffer. */ - if ((mtd_next = (sc->mtd_free + 1)) == NTDA) - mtd_next = 0; - - if (mtd_next == sc->mtd_hw) { - ifp->if_flags |= IFF_OACTIVE; - return; - } - - IF_DEQUEUE(&ifp->if_snd, m); - if (m == 0) - return; - - /* We need the header for m_pkthdr.len. */ - if ((m->m_flags & M_PKTHDR) == 0) - panic("%s: snstart: no header mbuf", sc->sc_dev.dv_xname); - -#if NBPFILTER > 0 - /* - * If bpf is listening on this interface, let it - * see the packet before we commit it to the wire. - */ - if (ifp->if_bpf) - bpf_mtap(ifp->if_bpf, m); -#endif - - /* - * If there is nothing in the o/p queue, and there is room in - * the Tx ring, then send the packet directly. Otherwise append - * it to the o/p queue. - */ - if ((sonicput(sc, m, mtd_next)) == 0) { - IF_PREPEND(&ifp->if_snd, m); - return; - } - - sc->mtd_prev = sc->mtd_free; - sc->mtd_free = mtd_next; - - ifp->if_opackets++; /* # of pkts */ - - /* Jump back for possibly more punishment. */ - goto outloop; -} - -/* - * reset and restart the SONIC. Called in case of fatal - * hardware/software errors. - */ -static void -snreset(struct sn_softc *sc) -{ - snstop(sc); - sninit(sc); -} - -static int -sninit(struct sn_softc *sc) -{ - u_long s_rcr; - int s; - - if (sc->sc_if.if_flags & IFF_RUNNING) - /* already running */ - return (0); - - s = splnet(); - - NIC_PUT(sc, SNR_CR, CR_RST); /* DCR only accessible in reset mode! */ - - /* config it */ - NIC_PUT(sc, SNR_DCR, (sc->snr_dcr | - (sc->bitmode ? DCR_DW32 : DCR_DW16))); - NIC_PUT(sc, SNR_DCR2, sc->snr_dcr2); - - s_rcr = RCR_BRD | RCR_LBNONE; - if (sc->sc_if.if_flags & IFF_PROMISC) - s_rcr |= RCR_PRO; - if (sc->sc_if.if_flags & IFF_ALLMULTI) - s_rcr |= RCR_AMC; - NIC_PUT(sc, SNR_RCR, s_rcr); - - NIC_PUT(sc, SNR_IMR, (IMR_PRXEN | IMR_PTXEN | IMR_TXEREN | IMR_LCDEN)); - - /* clear pending interrupts */ - NIC_PUT(sc, SNR_ISR, ISR_ALL); - - /* clear tally counters */ - NIC_PUT(sc, SNR_CRCT, -1); - NIC_PUT(sc, SNR_FAET, -1); - NIC_PUT(sc, SNR_MPT, -1); - - initialise_tda(sc); - initialise_rda(sc); - initialise_rra(sc); - - /* enable the chip */ - NIC_PUT(sc, SNR_CR, 0); - wbflush(); - - /* program the CAM */ - camprogram(sc); - - /* get it to read resource descriptors */ - NIC_PUT(sc, SNR_CR, CR_RRRA); - wbflush(); - while ((NIC_GET(sc, SNR_CR)) & CR_RRRA) - continue; - - /* enable rx */ - NIC_PUT(sc, SNR_CR, CR_RXEN); - wbflush(); - - /* flag interface as "running" */ - sc->sc_if.if_flags |= IFF_RUNNING; - sc->sc_if.if_flags &= ~IFF_OACTIVE; - - splx(s); - return (0); -} - -/* - * close down an interface and free its buffers - * Called on final close of device, or if sninit() fails - * part way through. - */ -static int -snstop(struct sn_softc *sc) -{ - struct mtd *mtd; - int s; - - s = splnet(); - - /* stick chip in reset */ - NIC_PUT(sc, SNR_CR, CR_RST); - wbflush(); - - /* free all receive buffers (currently static so nothing to do) */ - - /* free all pending transmit mbufs */ - while (sc->mtd_hw != sc->mtd_free) { - mtd = &sc->mtda[sc->mtd_hw]; - if (mtd->mtd_mbuf) - m_freem(mtd->mtd_mbuf); - if (++sc->mtd_hw == NTDA) sc->mtd_hw = 0; - } - - sc->sc_if.if_timer = 0; - sc->sc_if.if_flags &= ~(IFF_RUNNING | IFF_UP); - - splx(s); - return (0); -} - -/* - * Called if any Tx packets remain unsent after 5 seconds, - * In all cases we just reset the chip, and any retransmission - * will be handled by higher level protocol timeouts. - */ -static void -snwatchdog(struct ifnet *ifp) -{ - struct sn_softc *sc = ifp->if_softc; - struct mtd *mtd; - int temp; - - if (sc->mtd_hw != sc->mtd_free) { - /* something still pending for transmit */ - mtd = &sc->mtda[sc->mtd_hw]; - if (SRO(sc->bitmode, mtd->mtd_txp, TXP_STATUS) == 0) - log(LOG_ERR, "%s: Tx - timeout\n", - sc->sc_dev.dv_xname); - else - log(LOG_ERR, "%s: Tx - lost interrupt\n", - sc->sc_dev.dv_xname); - temp = ifp->if_flags & IFF_UP; - snreset(sc); - ifp->if_flags |= temp; - } -} - -/* - * stuff packet into sonic (at splnet) - */ -static inline u_int -sonicput(struct sn_softc *sc, struct mbuf *m0, int mtd_next) -{ - struct mtd *mtdp; - struct mbuf *m; - u_char *buff; - void *txp; - u_int len = 0; - u_int totlen = 0; - -#ifdef whyonearthwouldyoudothis - if (NIC_GET(sc, SNR_CR) & CR_TXP) - return (0); -#endif - - /* grab the replacement mtd */ - mtdp = &sc->mtda[sc->mtd_free]; - - buff = mtdp->mtd_buf; - - /* this packet goes to mtdnext fill in the TDA */ - mtdp->mtd_mbuf = m0; - txp = mtdp->mtd_txp; - - /* Write to the config word. Every (NTDA/2)+1 packets we set an intr */ - if (sc->mtd_pint == 0) { - sc->mtd_pint = NTDA/2; - SWO(sc->bitmode, txp, TXP_CONFIG, TCR_PINT); - } else { - sc->mtd_pint--; - SWO(sc->bitmode, txp, TXP_CONFIG, 0); - } - - for (m = m0; m; m = m->m_next) { - u_char *data = mtod(m, u_char *); - len = m->m_len; - totlen += len; - memcpy(buff, data, len); - buff += len; - } - if (totlen >= TXBSIZE) { - panic("%s: sonicput: packet overflow", sc->sc_dev.dv_xname); - } - - SWO(sc->bitmode, txp, TXP_FRAGOFF + (0 * TXP_FRAGSIZE) + TXP_FPTRLO, - LOWER(mtdp->mtd_vbuf)); - SWO(sc->bitmode, txp, TXP_FRAGOFF + (0 * TXP_FRAGSIZE) + TXP_FPTRHI, - UPPER(mtdp->mtd_vbuf)); - - if (totlen < ETHERMIN + ETHER_HDR_LEN) { - int pad = ETHERMIN + ETHER_HDR_LEN - totlen; - memset((char*)mtdp->mtd_buf + totlen, 0, pad); - totlen = ETHERMIN + ETHER_HDR_LEN; - } +#include +#include - SWO(sc->bitmode, txp, TXP_FRAGOFF + (0 * TXP_FRAGSIZE) + TXP_FSIZE, - totlen); - SWO(sc->bitmode, txp, TXP_FRAGCNT, 1); - SWO(sc->bitmode, txp, TXP_PKTSIZE, totlen); +#include - /* link onto the next mtd that will be used */ - SWO(sc->bitmode, txp, TXP_FRAGOFF + (1 * TXP_FRAGSIZE) + TXP_FPTRLO, - LOWER(sc->mtda[mtd_next].mtd_vtxp) | EOL); - - /* - * The previous txp.tlink currently contains a pointer to - * our txp | EOL. Want to clear the EOL, so write our - * pointer to the previous txp. - */ - SWO(sc->bitmode, sc->mtda[sc->mtd_prev].mtd_txp, sc->mtd_tlinko, - LOWER(mtdp->mtd_vtxp)); - - /* make sure chip is running */ - wbflush(); - NIC_PUT(sc, SNR_CR, CR_TXP); - wbflush(); - sc->sc_if.if_timer = 5; /* 5 seconds to watch for failing to transmit */ - - return (totlen); -} - -/* - * These are called from sonicioctl() when /etc/ifconfig is run to set - * the address or switch the i/f on. - */ -/* - * CAM support - */ -static void -caminitialise(struct sn_softc *sc) -{ - void *p_cda = sc->p_cda; - int i; - int bitmode = sc->bitmode; - int camoffset; - - for (i = 0; i < MAXCAM; i++) { - camoffset = i * CDA_CAMDESC; - SWO(bitmode, p_cda, (camoffset + CDA_CAMEP), i); - SWO(bitmode, p_cda, (camoffset + CDA_CAMAP2), 0); - SWO(bitmode, p_cda, (camoffset + CDA_CAMAP1), 0); - SWO(bitmode, p_cda, (camoffset + CDA_CAMAP0), 0); - } - SWO(bitmode, p_cda, CDA_ENABLE, 0); -} - -static void -camentry(struct sn_softc *sc, int entry, u_char *ea) -{ - void *p_cda = sc->p_cda; - int bitmode = sc->bitmode; - int camoffset = entry * CDA_CAMDESC; - - SWO(bitmode, p_cda, camoffset + CDA_CAMEP, entry); - SWO(bitmode, p_cda, camoffset + CDA_CAMAP2, (ea[5] << 8) | ea[4]); - SWO(bitmode, p_cda, camoffset + CDA_CAMAP1, (ea[3] << 8) | ea[2]); - SWO(bitmode, p_cda, camoffset + CDA_CAMAP0, (ea[1] << 8) | ea[0]); - SWO(bitmode, p_cda, CDA_ENABLE, - (SRO(bitmode, p_cda, CDA_ENABLE) | (1 << entry))); -} - -static void -camprogram(struct sn_softc *sc) -{ - struct ether_multistep step; - struct ether_multi *enm; - struct ifnet *ifp; - int timeout; - int mcount = 0; - - caminitialise(sc); - - ifp = &sc->sc_if; - - /* Always load our own address first. */ - camentry (sc, mcount, LLADDR(ifp->if_sadl)); - mcount++; - - /* Assume we won't need allmulti bit. */ - ifp->if_flags &= ~IFF_ALLMULTI; - - /* Loop through multicast addresses */ - ETHER_FIRST_MULTI(step, &sc->sc_ethercom, enm); - while (enm != NULL) { - if (mcount == MAXCAM) { - ifp->if_flags |= IFF_ALLMULTI; - break; - } - - if (bcmp(enm->enm_addrlo, enm->enm_addrhi, - sizeof(enm->enm_addrlo)) != 0) { - /* - * SONIC's CAM is programmed with specific - * addresses. It has no way to specify a range. - * (Well, thats not exactly true. If the - * range is small one could program each addr - * within the range as a separate CAM entry) - */ - ifp->if_flags |= IFF_ALLMULTI; - break; - } - - /* program the CAM with the specified entry */ - camentry(sc, mcount, enm->enm_addrlo); - mcount++; - - ETHER_NEXT_MULTI(step, enm); - } - - NIC_PUT(sc, SNR_CDP, LOWER(sc->v_cda)); - NIC_PUT(sc, SNR_CDC, MAXCAM); - NIC_PUT(sc, SNR_CR, CR_LCAM); - wbflush(); - - timeout = 10000; - while ((NIC_GET(sc, SNR_CR) & CR_LCAM) && timeout--) - continue; - if (timeout == 0) { - /* XXX */ - panic("%s: CAM initialisation failed", sc->sc_dev.dv_xname); - } - timeout = 10000; - while (((NIC_GET(sc, SNR_ISR) & ISR_LCD) == 0) && timeout--) - continue; - - if (NIC_GET(sc, SNR_ISR) & ISR_LCD) - NIC_PUT(sc, SNR_ISR, ISR_LCD); - else - printf("%s: CAM initialisation without interrupt\n", - sc->sc_dev.dv_xname); -} - -#ifdef SNDEBUG -static void -camdump(struct sn_softc *sc) -{ - int i; - - printf("CAM entries:\n"); - NIC_PUT(sc, SNR_CR, CR_RST); - wbflush(); - - for (i = 0; i < 16; i++) { - ushort ap2, ap1, ap0; - NIC_PUT(sc, SNR_CEP, i); - wbflush(); - ap2 = NIC_GET(sc, SNR_CAP2); - ap1 = NIC_GET(sc, SNR_CAP1); - ap0 = NIC_GET(sc, SNR_CAP0); - printf("%d: ap2=0x%x ap1=0x%x ap0=0x%x\n", i, ap2, ap1, ap0); - } - printf("CAM enable 0x%x\n", NIC_GET(sc, SNR_CEP)); - - NIC_PUT(sc, SNR_CR, 0); - wbflush(); -} -#endif - -static void -initialise_tda(struct sn_softc *sc) -{ - struct mtd *mtd; - int i; - - for (i = 0; i < NTDA; i++) { - mtd = &sc->mtda[i]; - mtd->mtd_mbuf = 0; - } - - sc->mtd_hw = 0; - sc->mtd_prev = NTDA - 1; - sc->mtd_free = 0; - sc->mtd_tlinko = TXP_FRAGOFF + 1*TXP_FRAGSIZE + TXP_FPTRLO; - sc->mtd_pint = NTDA/2; - - NIC_PUT(sc, SNR_UTDA, UPPER(sc->mtda[0].mtd_vtxp)); - NIC_PUT(sc, SNR_CTDA, LOWER(sc->mtda[0].mtd_vtxp)); -} - -static void -initialise_rda(struct sn_softc *sc) -{ - int bitmode = sc->bitmode; - int i; - void *p_rda = 0; - u_int32_t v_rda = 0; - - /* link the RDA's together into a circular list */ - for (i = 0; i < (sc->sc_nrda - 1); i++) { - p_rda = (char*)sc->p_rda + (i * RXPKT_SIZE(sc)); - v_rda = sc->v_rda + ((i+1) * RXPKT_SIZE(sc)); - SWO(bitmode, p_rda, RXPKT_RLINK, LOWER(v_rda)); - SWO(bitmode, p_rda, RXPKT_INUSE, 1); - } - p_rda = (char*)sc->p_rda + ((sc->sc_nrda - 1) * RXPKT_SIZE(sc)); - SWO(bitmode, p_rda, RXPKT_RLINK, LOWER(sc->v_rda) | EOL); - SWO(bitmode, p_rda, RXPKT_INUSE, 1); - - /* mark end of receive descriptor list */ - sc->sc_rdamark = sc->sc_nrda - 1; - - sc->sc_rxmark = 0; - - NIC_PUT(sc, SNR_URDA, UPPER(sc->v_rda)); - NIC_PUT(sc, SNR_CRDA, LOWER(sc->v_rda)); - wbflush(); -} - -static void -initialise_rra(struct sn_softc *sc) -{ - int i; - u_int v; - int bitmode = sc->bitmode; - - if (bitmode) - NIC_PUT(sc, SNR_EOBC, RBASIZE(sc) / 2 - 2); - else - NIC_PUT(sc, SNR_EOBC, RBASIZE(sc) / 2 - 1); - - NIC_PUT(sc, SNR_URRA, UPPER(sc->v_rra[0])); - NIC_PUT(sc, SNR_RSA, LOWER(sc->v_rra[0])); - /* rea must point just past the end of the rra space */ - NIC_PUT(sc, SNR_REA, LOWER(sc->v_rea)); - NIC_PUT(sc, SNR_RRP, LOWER(sc->v_rra[0])); - NIC_PUT(sc, SNR_RSC, 0); - - /* fill up SOME of the rra with buffers */ - for (i = 0; i < NRBA; i++) { - v = SONIC_GETDMA(sc->rbuf[i]); - SWO(bitmode, sc->p_rra[i], RXRSRC_PTRHI, UPPER(v)); - SWO(bitmode, sc->p_rra[i], RXRSRC_PTRLO, LOWER(v)); - SWO(bitmode, sc->p_rra[i], RXRSRC_WCHI, UPPER(PAGE_SIZE/2)); - SWO(bitmode, sc->p_rra[i], RXRSRC_WCLO, LOWER(PAGE_SIZE/2)); - } - sc->sc_rramark = NRBA; - NIC_PUT(sc, SNR_RWP, LOWER(sc->v_rra[sc->sc_rramark])); - wbflush(); -} - -void -snintr(void *arg) -{ - struct sn_softc *sc = (struct sn_softc *)arg; - int isr, handled, wantinit; - - handled = 0; - wantinit = 0; - while (wantinit == 0) { - isr = NIC_GET(sc, SNR_ISR) & ISR_ALL; - if (isr == 0) - break; - /* scrub the interrupts that we are going to service */ - NIC_PUT(sc, SNR_ISR, isr); - wbflush(); - - handled = 1; - - if (isr & (ISR_BR | ISR_LCD | ISR_TC)) { - printf("%s: unexpected interrupt status 0x%x\n", - sc->sc_dev.dv_xname, isr); - wantinit = 1; - } - - if (isr & (ISR_TXDN | ISR_TXER | ISR_PINT)) - sonictxint(sc); - - if (isr & ISR_PKTRX) - sonicrxint(sc); - - if (isr & (ISR_HBL | ISR_RDE | ISR_RBE | ISR_RBAE | ISR_RFO)) { - if (isr & ISR_HBL) - /* - * The repeater is not providing a heartbeat. - * In itself this isn't harmful, lots of the - * cheap repeater hubs don't supply a heartbeat. - * So ignore the lack of heartbeat. Its only - * if we can't detect a carrier that we have a - * problem. - */ - ; - if (isr & ISR_RDE) { - printf("%s: receive descriptors exhausted\n", - sc->sc_dev.dv_xname); - wantinit = 1; - } - if (isr & ISR_RBE) { - printf("%s: receive buffers exhausted\n", - sc->sc_dev.dv_xname); - wantinit = 1; - } - if (isr & ISR_RBAE) { - printf("%s: receive buffer area exhausted\n", - sc->sc_dev.dv_xname); - wantinit = 1; - } - if (isr & ISR_RFO) { - printf("%s: receive FIFO overrun\n", - sc->sc_dev.dv_xname); - wantinit = 1; - } - } - if (isr & (ISR_CRC | ISR_FAE | ISR_MP)) { -#ifdef notdef - if (isr & ISR_CRC) - sc->sc_crctally++; - if (isr & ISR_FAE) - sc->sc_faetally++; - if (isr & ISR_MP) - sc->sc_mptally++; -#endif - } - } - - if (handled) { - if (wantinit) - snreset(sc); - snstart(&sc->sc_if); - } -} - -/* - * Transmit interrupt routine - */ -static void -sonictxint(struct sn_softc *sc) -{ - struct mtd *mtd; - struct ifnet *ifp = &sc->sc_if; - void *txp; - int mtd_hw; - unsigned short txp_status; - - mtd_hw = sc->mtd_hw; - - if (mtd_hw == sc->mtd_free) - return; - - while (mtd_hw != sc->mtd_free) { - mtd = &sc->mtda[mtd_hw]; - - txp = mtd->mtd_txp; - - if (SRO(sc->bitmode, txp, TXP_STATUS) == 0) { - break; /* it hasn't really gone yet */ - } - -#ifdef SNDEBUG - { - struct ether_header *eh; - - eh = (struct ether_header *) mtd->mtd_buf; - printf("%s: xmit status=0x%x len=%d type=0x%x from %s", - sc->sc_dev.dv_xname, - SRO(sc->bitmode, txp, TXP_STATUS), - SRO(sc->bitmode, txp, TXP_PKTSIZE), - htons(eh->ether_type), - ether_sprintf(eh->ether_shost)); - printf(" (to %s)\n", ether_sprintf(eh->ether_dhost)); - } -#endif /* SNDEBUG */ - - ifp->if_flags &= ~IFF_OACTIVE; - - if (mtd->mtd_mbuf != 0) { - m_freem(mtd->mtd_mbuf); - mtd->mtd_mbuf = 0; - } - if (++mtd_hw == NTDA) mtd_hw = 0; - - txp_status = SRO(sc->bitmode, txp, TXP_STATUS); - - ifp->if_collisions += (txp_status & TCR_EXC) ? 16 : - ((txp_status & TCR_NC) >> 12); - - if ((txp_status & TCR_PTX) == 0) { - ifp->if_oerrors++; - printf("%s: Tx packet status=0x%x\n", - sc->sc_dev.dv_xname, txp_status); - - /* XXX - DG This looks bogus */ - if (mtd_hw != sc->mtd_free) { - printf("resubmitting remaining packets\n"); - mtd = &sc->mtda[mtd_hw]; - NIC_PUT(sc, SNR_CTDA, LOWER(mtd->mtd_vtxp)); - NIC_PUT(sc, SNR_CR, CR_TXP); - wbflush(); - break; - } - } - } - - sc->mtd_hw = mtd_hw; - return; -} - -/* - * Receive interrupt routine - */ -static void -sonicrxint(struct sn_softc *sc) -{ - void *rda; - int orra; - int len; - int rramark; - int rdamark; - int bitmode = sc->bitmode; - u_int16_t rxpkt_ptr; - - rda = (char*)sc->p_rda + (sc->sc_rxmark * RXPKT_SIZE(sc)); - - while (SRO(bitmode, rda, RXPKT_INUSE) == 0) { - u_int status = SRO(bitmode, rda, RXPKT_STATUS); - - orra = RBASEQ(SRO(bitmode, rda, RXPKT_SEQNO)) & RRAMASK; - rxpkt_ptr = SRO(bitmode, rda, RXPKT_PTRLO); - len = SRO(bitmode, rda, RXPKT_BYTEC) - FCSSIZE; - if (status & RCR_PRX) { - void *pkt = (char*)sc->rbuf[orra & RBAMASK] + - m68k_page_offset(rxpkt_ptr); - if (sonic_read(sc, pkt, len)) - sc->sc_if.if_ipackets++; - else - sc->sc_if.if_ierrors++; - } else - sc->sc_if.if_ierrors++; - - /* - * give receive buffer area back to chip. - * - * If this was the last packet in the RRA, give the RRA to - * the chip again. - * If sonic read didnt copy it out then we would have to - * wait !! - * (dont bother add it back in again straight away) - * - * Really, we're doing p_rra[rramark] = p_rra[orra] but - * we have to use the macros because SONIC might be in - * 16 or 32 bit mode. - */ - if (status & RCR_LPKT) { - void *tmp1, *tmp2; - - rramark = sc->sc_rramark; - tmp1 = sc->p_rra[rramark]; - tmp2 = sc->p_rra[orra]; - SWO(bitmode, tmp1, RXRSRC_PTRLO, - SRO(bitmode, tmp2, RXRSRC_PTRLO)); - SWO(bitmode, tmp1, RXRSRC_PTRHI, - SRO(bitmode, tmp2, RXRSRC_PTRHI)); - SWO(bitmode, tmp1, RXRSRC_WCLO, - SRO(bitmode, tmp2, RXRSRC_WCLO)); - SWO(bitmode, tmp1, RXRSRC_WCHI, - SRO(bitmode, tmp2, RXRSRC_WCHI)); - - /* zap old rra for fun */ - SWO(bitmode, tmp2, RXRSRC_WCHI, 0); - SWO(bitmode, tmp2, RXRSRC_WCLO, 0); - - sc->sc_rramark = (++rramark) & RRAMASK; - NIC_PUT(sc, SNR_RWP, LOWER(sc->v_rra[rramark])); - wbflush(); - } - - /* - * give receive descriptor back to chip simple - * list is circular - */ - rdamark = sc->sc_rdamark; - SWO(bitmode, rda, RXPKT_INUSE, 1); - SWO(bitmode, rda, RXPKT_RLINK, - SRO(bitmode, rda, RXPKT_RLINK) | EOL); - SWO(bitmode, ((char*)sc->p_rda + (rdamark * RXPKT_SIZE(sc))), - RXPKT_RLINK, - SRO(bitmode, ((char*)sc->p_rda + - (rdamark * RXPKT_SIZE(sc))), - RXPKT_RLINK) & ~EOL); - sc->sc_rdamark = sc->sc_rxmark; - - if (++sc->sc_rxmark >= sc->sc_nrda) - sc->sc_rxmark = 0; - rda = (char*)sc->p_rda + (sc->sc_rxmark * RXPKT_SIZE(sc)); - } -} - -/* - * sonic_read -- pull packet off interface and forward to - * appropriate protocol handler - */ -static inline int -sonic_read(struct sn_softc *sc, void *pkt, int len) -{ - struct ifnet *ifp = &sc->sc_if; - struct mbuf *m; - -#ifdef SNDEBUG - { - printf("%s: rcvd %p len=%d type=0x%x from %s", - sc->sc_dev.dv_xname, et, len, htons(et->ether_type), - ether_sprintf(et->ether_shost)); - printf(" (to %s)\n", ether_sprintf(et->ether_dhost)); - } -#endif /* SNDEBUG */ - - if (len < (ETHER_MIN_LEN - ETHER_CRC_LEN) || - len > (ETHER_MAX_LEN - ETHER_CRC_LEN)) { - printf("%s: invalid packet length %d bytes\n", - sc->sc_dev.dv_xname, len); - return (0); - } - - m = sonic_get(sc, pkt, len); - if (m == NULL) - return (0); -#if NBPFILTER > 0 - /* Pass this up to any BPF listeners. */ - if (ifp->if_bpf) - bpf_mtap(ifp->if_bpf, m); -#endif - (*ifp->if_input)(ifp, m); - return (1); -} - -/* - * munge the received packet into an mbuf chain - */ -static inline struct mbuf * -sonic_get(struct sn_softc *sc, void *pkt, int datalen) -{ - struct mbuf *m, *top, **mp; - int len; - - MGETHDR(m, M_DONTWAIT, MT_DATA); - if (m == 0) - return (0); - m->m_pkthdr.rcvif = &sc->sc_if; - m->m_pkthdr.len = datalen; - len = MHLEN; - top = 0; - mp = ⊤ - - while (datalen > 0) { - if (top) { - MGET(m, M_DONTWAIT, MT_DATA); - if (m == 0) { - m_freem(top); - return (0); - } - len = MLEN; - } - if (datalen >= MINCLSIZE) { - MCLGET(m, M_DONTWAIT); - if ((m->m_flags & M_EXT) == 0) { - if (top) m_freem(top); - return (0); - } - len = MCLBYTES; - } - - if (mp == &top) { - char *newdata = (char *) - ALIGN(m->m_data + sizeof(struct ether_header)) - - sizeof(struct ether_header); - len -= newdata - m->m_data; - m->m_data = newdata; - } - - m->m_len = len = min(datalen, len); - - memcpy(mtod(m, void *), pkt, len); - pkt = (char*)pkt + len; - datalen -= len; - *mp = m; - mp = &m->m_next; - } - - return (top); -} - -static u_char bbr4[] = {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15}; +static const uint8_t bbr4[] = {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15}; #define bbr(v) ((bbr4[(v)&0xf] << 4) | bbr4[((v)>>4) & 0xf]) void @@ -1235,3 +82,17 @@ dst[i] = (do_bbr) ? bbr(b) : b; } } + +void +sonic_md_reset(struct sonic_softc *sc) +{ + + /* + * make sure all interrupts are disabled since + * interrupts are enabled during cpu_configure(9) on mac68k. + */ + CSR_WRITE(sc, SONIC_CR, CR_STP); + CSR_WRITE(sc, SONIC_CR, CR_RST); + CSR_WRITE(sc, SONIC_IMR, 0); + CSR_WRITE(sc, SONIC_ISR, IMR_ALL); +} Index: arch/mac68k/dev/if_snvar.h =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/dev/if_snvar.h,v retrieving revision 1.19 diff -u -r1.19 if_snvar.h --- arch/mac68k/dev/if_snvar.h 8 Mar 2007 12:54:15 -0000 1.19 +++ arch/mac68k/dev/if_snvar.h 31 May 2007 11:27:13 -0000 @@ -19,202 +19,6 @@ #define SN_VENDOR_APPLE16 0x02 /* Apple Twisted Pair NB */ #define SN_VENDOR_ASANTELC 0x09 /* Asante Macintosh LC Ethernet */ -/* - * Memory access macros. Since we handle SONIC in 16 bit mode (PB5X0) - * and 32 bit mode (everything else) using a single GENERIC kernel - * binary, all structures have to be accessed using macros which can - * adjust the offsets appropriately. - */ -#define SWO(m, a, o, x) (m ? \ - (*(volatile u_int32_t *)((u_int32_t *)(a) + (o)) = (x)) : \ - (*(volatile u_int16_t *)((u_int16_t *)(a) + (o)) = (x))) -#define SRO(m, a, o) (m ? \ - (*(volatile u_int32_t *)((u_int32_t *)(a) + (o)) & 0xffff) : \ - (*(volatile u_int16_t *)((u_int16_t *)(a) + (o)) & 0xffff)) - -/* - * Register access macros. We use bus_space_* to talk to the Sonic - * registers. A mapping table is used in case a particular configuration - * hooked the regs up at non-word offsets. - */ -#define NIC_GET(sc, reg) (bus_space_read_2((sc)->sc_regt, \ - (sc)->sc_regh, \ - ((sc)->sc_reg_map[(reg)]))) -#define NIC_PUT(sc, reg, val) (bus_space_write_2((sc)->sc_regt, \ - (sc)->sc_regh, \ - ((sc)->sc_reg_map[reg]), \ - (val))) - -#define SONIC_GETDMA(p) (u_int32_t)(kvtop((void *)(p))) - -#define SN_REGSIZE SN_NREGS*4 - -/* mac68k does not have any write buffers to flush... */ -#define wbflush() - -/* - * buffer sizes in 32 bit mode - * 1 TXpkt is 4 hdr words + (3 * FRAGMAX) + 1 link word == 23 words == 92 bytes - * - * 1 RxPkt is 7 words == 28 bytes - * 1 Rda is 4 words == 16 bytes - * - * The CDA is 17 words == 68 bytes - * - * total space in page 0 = NTDA * 92 + NRRA * 16 + NRDA * 28 + 68 - */ - -#define NRBA 32 /* # receive buffers < NRRA */ -#define RBAMASK (NRBA-1) -#define NTDA 16 /* # transmit descriptors */ -#define NRRA 64 /* # receive resource descriptors */ -#define RRAMASK (NRRA-1) /* the reason why NRRA must be power of two */ - -#define FCSSIZE 4 /* size of FCS appended to packets */ - -/* - * maximum receive packet size plus 2 byte pad to make each - * one aligned. 4 byte slop (required for eobc) - */ -#define RBASIZE(sc) (sizeof(struct ether_header) + ETHERMTU + FCSSIZE + \ - ((sc)->bitmode ? 6 : 2)) - -/* - * transmit buffer area - */ -#define TXBSIZE 1536 /* 6*2^8 -- the same size as the 8390 TXBUF */ - -#define SN_NPAGES 2 + NRBA + (NTDA/2) - -typedef struct mtd { - void *mtd_txp; - u_int32_t mtd_vtxp; - void * mtd_buf; - u_int32_t mtd_vbuf; - struct mbuf *mtd_mbuf; -} mtd_t; - -/* - * The sn_softc for Mac68k if_sn. - */ -typedef struct sn_softc { - struct device sc_dev; - struct ethercom sc_ethercom; -#define sc_if sc_ethercom.ec_if /* network visible interface */ - - bus_space_tag_t sc_regt; - bus_space_handle_t sc_regh; - - int bitmode; /* 32 bit mode == 1, 16 == 0 */ - bus_size_t sc_reg_map[SN_NREGS]; /* register offsets */ - - u_int16_t snr_dcr; /* DCR for this instance */ - u_int16_t snr_dcr2; /* DCR2 for this instance */ - int slotno; /* Slot number */ - - int sc_rramark; /* index into p_rra of wp */ - void *p_rra[NRRA]; /* RX resource descs */ - u_int32_t v_rra[NRRA]; /* DMA addresses of p_rra */ - u_int32_t v_rea; /* ptr to the end of the rra space */ - - int sc_rxmark; /* current hw pos in rda ring */ - int sc_rdamark; /* current sw pos in rda ring */ - int sc_nrda; /* total number of RDAs */ - void * p_rda; - u_int32_t v_rda; - - void * rbuf[NRBA]; - - struct mtd mtda[NTDA]; - int mtd_hw; /* idx of first mtd given to hw */ - int mtd_prev; /* idx of last mtd given to hardware */ - int mtd_free; /* next free mtd to use */ - int mtd_tlinko; /* - * offset of tlink of last txp given - * to SONIC. Need to clear EOL on - * this word to add a desc. - */ - int mtd_pint; /* Counter to set TXP_PINT */ - - void *p_cda; - u_int32_t v_cda; - - unsigned char *space; -} sn_softc_t; - -/* - * Accessing SONIC data structures and registers as 32 bit values - * makes code endianess independent. The SONIC is however always in - * bigendian mode so it is necessary to ensure that data structures shared - * between the CPU and the SONIC are always in bigendian order. - */ - -/* - * Receive Resource Descriptor - * This structure describes the buffers into which packets - * will be received. Note that more than one packet may be - * packed into a single buffer if constraints permit. - */ -#define RXRSRC_PTRLO 0 /* buffer address LO */ -#define RXRSRC_PTRHI 1 /* buffer address HI */ -#define RXRSRC_WCLO 2 /* buffer size (16bit words) LO */ -#define RXRSRC_WCHI 3 /* buffer size (16bit words) HI */ - -#define RXRSRC_SIZE(sc) (sc->bitmode ? (4 * 4) : (4 * 2)) - -/* - * Receive Descriptor - * This structure holds information about packets received. - */ -#define RXPKT_STATUS 0 -#define RXPKT_BYTEC 1 -#define RXPKT_PTRLO 2 -#define RXPKT_PTRHI 3 -#define RXPKT_SEQNO 4 -#define RXPKT_RLINK 5 -#define RXPKT_INUSE 6 -#define RXPKT_SIZE(sc) (sc->bitmode ? (7 * 4) : (7 * 2)) - -#define RBASEQ(x) (((x)>>8)&0xff) -#define PSNSEQ(x) ((x) & 0xff) - -/* - * Transmit Descriptor - * This structure holds information about packets to be transmitted. - */ -#define FRAGMAX 8 /* maximum number of fragments in a packet */ - -#define TXP_STATUS 0 /* + transmitted packet status */ -#define TXP_CONFIG 1 /* transmission configuration */ -#define TXP_PKTSIZE 2 /* entire packet size in bytes */ -#define TXP_FRAGCNT 3 /* # fragments in packet */ - -#define TXP_FRAGOFF 4 /* offset to first fragment */ -#define TXP_FRAGSIZE 3 /* size of each fragment desc */ -#define TXP_FPTRLO 0 /* ptr to packet fragment LO */ -#define TXP_FPTRHI 1 /* ptr to packet fragment HI */ -#define TXP_FSIZE 2 /* fragment size */ - -#define TXP_WORDS TXP_FRAGOFF + (FRAGMAX*TXP_FRAGSIZE) + 1 /* 1 for tlink */ -#define TXP_SIZE(sc) ((sc->bitmode) ? (TXP_WORDS*4) : (TXP_WORDS*2)) - -#define EOL 0x0001 /* end of list marker for link fields */ - -/* - * CDA, the CAM descriptor area. The SONIC has a 16 entry CAM to - * match incoming addresses against. It is programmed via DMA - * from a memory region. - */ -#define MAXCAM 16 /* number of user entries in CAM */ -#define CDA_CAMDESC 4 /* # words i na descriptor */ -#define CDA_CAMEP 0 /* CAM Address Port 0 xx-xx-xx-xx-YY-YY */ -#define CDA_CAMAP0 1 /* CAM Address Port 1 xx-xx-YY-YY-xx-xx */ -#define CDA_CAMAP1 2 /* CAM Address Port 2 YY-YY-xx-xx-xx-xx */ -#define CDA_CAMAP2 3 -#define CDA_ENABLE 64 /* mask enabling CAM entries */ -#define CDA_SIZE(sc) ((4*16 + 1) * ((sc->bitmode) ? 4 : 2)) - -int snsetup(struct sn_softc *, u_int8_t *); -void snintr(void *); void sn_get_enaddr(bus_space_tag_t, bus_space_handle_t, bus_size_t, - u_char *); + uint8_t *); +void sonic_md_reset(struct sonic_softc *); Index: arch/mac68k/include/cpu.h =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/include/cpu.h,v retrieving revision 1.86 diff -u -r1.86 cpu.h --- arch/mac68k/include/cpu.h 21 May 2007 16:37:03 -0000 1.86 +++ arch/mac68k/include/cpu.h 31 May 2007 11:27:13 -0000 @@ -358,6 +358,9 @@ int suline(void *, void *); void loadustp(int); +/* fpu.c */ +void initfpu(void); + #endif #endif /* _CPU_MACHINE_ */ Index: arch/mac68k/mac68k/fpu.c =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/mac68k/fpu.c,v retrieving revision 1.35 diff -u -r1.35 fpu.c --- arch/mac68k/mac68k/fpu.c 24 Dec 2005 22:45:35 -0000 1.35 +++ arch/mac68k/mac68k/fpu.c 31 May 2007 11:27:13 -0000 @@ -47,12 +47,7 @@ */ #include -#include -#include -#include -#include -#include #include #include @@ -62,19 +57,8 @@ extern label_t *nofault; -static int fpu_match(struct device *, struct cfdata *, void *); -static void fpu_attach(struct device *, struct device *, void *); static int fpu_probe(void); -CFATTACH_DECL(fpu, sizeof(struct device), - fpu_match, fpu_attach, NULL, NULL); - -static int -fpu_match(struct device *parent, struct cfdata *cf, void *aux) -{ - return 1; -} - static const char *fpu_descr[] = { #ifdef FPU_EMULATE "emulator", /* 0 */ @@ -87,8 +71,8 @@ "mc68060", /* 4 */ "unknown" }; -static void -fpu_attach(struct device *parent, struct device *self, void *args) +void +initfpu(void) { const char *descr; @@ -103,7 +87,7 @@ else descr = "unknown type"; - printf(" (%s)\n", descr); + printf("fpu: %s\n", descr); } static int Index: arch/mac68k/mac68k/machdep.c =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/mac68k/machdep.c,v retrieving revision 1.315 diff -u -r1.315 machdep.c --- arch/mac68k/mac68k/machdep.c 21 May 2007 15:22:22 -0000 1.315 +++ arch/mac68k/mac68k/machdep.c 31 May 2007 11:27:14 -0000 @@ -2010,6 +2010,7 @@ mpu); printf("%s\n", cpu_model); printf("cpu: delay factor %d\n", delay_factor); + initfpu(); } static void get_machine_info(void); Index: arch/mac68k/nubus/if_sn_nubus.c =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/nubus/if_sn_nubus.c,v retrieving revision 1.26 diff -u -r1.26 if_sn_nubus.c --- arch/mac68k/nubus/if_sn_nubus.c 11 Dec 2005 12:18:03 -0000 1.26 +++ arch/mac68k/nubus/if_sn_nubus.c 31 May 2007 11:27:14 -0000 @@ -36,28 +36,20 @@ #include "opt_inet.h" #include +#include #include -#include #include -#include -#include -#include #include #include -#if 0 /* XXX this shouldn't be necessary; else reinsert */ -#ifdef INET -#include -#include -#endif -#endif - #include #include +#include +#include + #include -#include #include static int sn_nubus_match(struct device *, struct cfdata *, void *); @@ -65,7 +57,7 @@ static int sn_nb_card_vendor(bus_space_tag_t, bus_space_handle_t, struct nubus_attach_args *); -CFATTACH_DECL(sn_nubus, sizeof(struct sn_softc), +CFATTACH_DECL(sn_nubus, sizeof(struct sonic_softc), sn_nubus_match, sn_nubus_attach, NULL, NULL); @@ -108,39 +100,36 @@ static void sn_nubus_attach(struct device *parent, struct device *self, void *aux) { - struct sn_softc *sc = (void *)self; + struct sonic_softc *sc = (void *)self; struct nubus_attach_args *na = (struct nubus_attach_args *)aux; int i, success, offset; bus_space_tag_t bst; bus_space_handle_t bsh, tmp_bsh; - u_int8_t myaddr[ETHER_ADDR_LEN]; + uint8_t myaddr[ETHER_ADDR_LEN]; const char *cardtype; - (void)(&offset); /* Work around lame gcc initialization bug */ - bst = na->na_tag; if (bus_space_map(bst, NUBUS_SLOT2PA(na->slot), NBMEMSIZE, 0, &bsh)) { printf(": failed to map memory space.\n"); return; } - sc->sc_regt = bst; + sc->sc_st = bst; + sc->sc_dmat = na->na_dmat; cardtype = nubus_get_card_name(bst, bsh, na->fmt); success = 0; - - sc->slotno = na->slot; + offset = 0; switch (sn_nb_card_vendor(bst, bsh, na)) { case SN_VENDOR_DAYNA: - sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | - DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16; - sc->snr_dcr2 = 0; - sc->bitmode = 1; /* 32 bit card */ + sc->sc_dcr = DCR_BMS | DCR_RFT1 | DCR_TFT0; + sc->sc_dcr2 = 0; + sc->sc_32bit = 1; /* 32 bit card */ if (bus_space_subregion(bst, bsh, - 0x00180000, SN_REGSIZE, &sc->sc_regh)) { + 0x00180000, SONIC_NREGS * 4, &sc->sc_sh)) { printf(": failed to map register space.\n"); break; } @@ -158,13 +147,12 @@ break; case SN_VENDOR_APPLE: - sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | - DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16; - sc->snr_dcr2 = 0; - sc->bitmode = 1; /* 32 bit card */ + sc->sc_dcr = DCR_BMS | DCR_RFT1 | DCR_TFT0; + sc->sc_dcr2 = 0; + sc->sc_32bit = 1; /* 32 bit card */ if (bus_space_subregion(bst, bsh, - 0x0, SN_REGSIZE, &sc->sc_regh)) { + 0x0, SONIC_NREGS * 4, &sc->sc_sh)) { printf(": failed to map register space.\n"); break; } @@ -182,13 +170,13 @@ break; case SN_VENDOR_APPLE16: - sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | DCR_EXBUS | - DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16; - sc->snr_dcr2 = 0; - sc->bitmode = 0; /* 16 bit card */ + sc->sc_dcr = DCR_EXBUS | DCR_BMS | DCR_PO1 | + DCR_RFT1 | DCR_TFT0; + sc->sc_dcr2 = 0; + sc->sc_32bit = 0; /* 16 bit card */ if (bus_space_subregion(bst, bsh, - 0x0, SN_REGSIZE, &sc->sc_regh)) { + 0x0, SONIC_NREGS * 4, &sc->sc_sh)) { printf(": failed to map register space.\n"); break; } @@ -206,13 +194,12 @@ break; case SN_VENDOR_ASANTELC: /* Macintosh LC Ethernet Adapter */ - sc->snr_dcr = DCR_ASYNC | DCR_WAIT0 | - DCR_DMABLOCK | DCR_PO1 | DCR_RFT16 | DCR_TFT16; - sc->snr_dcr2 = 0; - sc->bitmode = 0; /* 16 bit card */ + sc->sc_dcr = DCR_BMS | DCR_PO1 | DCR_RFT1 | DCR_TFT0; + sc->sc_dcr2 = 0; + sc->sc_32bit = 0; /* 16 bit card */ if (bus_space_subregion(bst, bsh, - 0x0, SN_REGSIZE, &sc->sc_regh)) { + 0x0, SONIC_NREGS * 4, &sc->sc_sh)) { printf(": failed to map register space.\n"); break; } @@ -236,9 +223,8 @@ * for a new card, the following defaults are a * good starting point. */ - sc->snr_dcr = DCR_SYNC | DCR_WAIT0 | DCR_DW32 | - DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16; - sc->snr_dcr2 = 0; + sc->sc_dcr = DCR_SBUS | DCR_DW | DCR_BMS | DCR_RFT1 | DCR_TFT0; + sc->sc_dcr2 = 0; success = 0; printf(": unknown card: attachment incomplete.\n"); } @@ -249,19 +235,19 @@ } /* Regs are addressed as words, big endian. */ - for (i = 0; i < SN_NREGS; i++) { - sc->sc_reg_map[i] = (bus_size_t)((i * 4) + offset); + for (i = 0; i < SONIC_NREGS; i++) { + sc->sc_regmap[i] = (bus_size_t)((i * 4) + offset); } + sc->sc_bigendian = 1; + printf(": %s\n", cardtype); - /* snsetup returns 1 if something fails */ - if (snsetup(sc, myaddr)) { - bus_space_unmap(bst, bsh, NBMEMSIZE); - return; - } + sonic_md_reset(sc); + + add_nubus_intr(na->slot, (void (*)(void *))sonic_intr, (void *)sc); - add_nubus_intr(sc->slotno, snintr, (void *)sc); + sonic_attach(sc, myaddr); return; } Index: arch/mac68k/obio/if_sn_obio.c =================================================================== RCS file: /cvsroot/src/sys/arch/mac68k/obio/if_sn_obio.c,v retrieving revision 1.25 diff -u -r1.25 if_sn_obio.c --- arch/mac68k/obio/if_sn_obio.c 11 Dec 2005 12:18:03 -0000 1.25 +++ arch/mac68k/obio/if_sn_obio.c 31 May 2007 11:27:14 -0000 @@ -37,41 +37,32 @@ #include #include -#include -#include -#include -#include #include - -#include +#include #include #include -#if 0 /* XXX this shouldn't be necessary... else reinsert */ -#ifdef INET -#include -#include -#endif -#endif - #include #include #include +#include +#include + #include -#include #include #define SONIC_REG_BASE 0x50F0A000 #define SONIC_PROM_BASE 0x50F08000 +#define SONIC_SLOTNO 9 static int sn_obio_match(struct device *, struct cfdata *, void *); static void sn_obio_attach(struct device *, struct device *, void *); -static int sn_obio_getaddr(struct sn_softc *, u_int8_t *); -static int sn_obio_getaddr_kludge(struct sn_softc *, u_int8_t *); +static int sn_obio_getaddr(struct sonic_softc *, uint8_t *); +static int sn_obio_getaddr_kludge(struct sonic_softc *, uint8_t *); -CFATTACH_DECL(sn_obio, sizeof(struct sn_softc), +CFATTACH_DECL(sn_obio, sizeof(struct sonic_softc), sn_obio_match, sn_obio_attach, NULL, NULL); static int @@ -85,13 +76,13 @@ return 0; if (bus_space_map(oa->oa_tag, - SONIC_REG_BASE, SN_REGSIZE, 0, &bsh)) + SONIC_REG_BASE, SONIC_NREGS * 4, 0, &bsh)) return 0; if (mac68k_bus_space_probe(oa->oa_tag, bsh, 0, 4)) found = 1; - bus_space_unmap(oa->oa_tag, bsh, SN_REGSIZE); + bus_space_unmap(oa->oa_tag, bsh, SONIC_NREGS * 4); return found; } @@ -103,14 +94,28 @@ sn_obio_attach(struct device *parent, struct device *self, void *aux) { struct obio_attach_args *oa = (struct obio_attach_args *)aux; - struct sn_softc *sc = (void *)self; - u_int8_t myaddr[ETHER_ADDR_LEN]; + struct sonic_softc *sc = (void *)self; + uint8_t myaddr[ETHER_ADDR_LEN]; int i; - sc->snr_dcr = DCR_WAIT0 | DCR_DMABLOCK | DCR_RFT16 | DCR_TFT16; - sc->snr_dcr2 = 0; + sc->sc_st = oa->oa_tag; + sc->sc_dmat = oa->oa_dmat; - sc->slotno = 9; + if (bus_space_map(sc->sc_st, + SONIC_REG_BASE, SONIC_NREGS * 4, 0, &sc->sc_sh)) { + printf(": failed to map space for SONIC regs.\n"); + return; + } + + /* regs are addressed as words, big-endian. */ + for (i = 0; i < SONIC_NREGS; i++) { + sc->sc_regmap[i] = (bus_size_t)((i * 4) + 2); + } + + sc->sc_bigendian = 1; + + sc->sc_dcr = DCR_BMS | DCR_RFT1 | DCR_TFT0; + sc->sc_dcr2 = 0; switch (current_mac_model->machineid) { case MACH_MACC610: @@ -121,18 +126,21 @@ case MACH_MACQ800: case MACH_MACQ900: case MACH_MACQ950: - sc->snr_dcr |= DCR_EXBUS; - sc->bitmode = 1; + sc->sc_dcr |= DCR_EXBUS; + sc->sc_32bit = 1; break; case MACH_MACLC575: case MACH_MACP580: case MACH_MACQ630: + /* Apple Comm Slot cards; assume they are 32 bit */ + sc->sc_dcr |= DCR_EXBUS | DCR_USR1 | DCR_USR0; + sc->sc_32bit = 1; break; case MACH_MACPB500: - sc->snr_dcr |= DCR_SYNC | DCR_LBR; - sc->bitmode = 0; /* 16 bit interface */ + sc->sc_dcr |= DCR_SBUS | DCR_LBR; + sc->sc_32bit = 0; /* 16 bit interface */ break; default: @@ -140,79 +148,50 @@ return; } - sc->sc_regt = oa->oa_tag; - - if (bus_space_map(sc->sc_regt, - SONIC_REG_BASE, SN_REGSIZE, 0, &sc->sc_regh)) { - printf(": failed to map space for SONIC regs.\n"); - return; - } - - /* regs are addressed as words, big-endian. */ - for (i = 0; i < SN_NREGS; i++) { - sc->sc_reg_map[i] = (bus_size_t)((i * 4) + 2); - } - - /* - * Kind of kludge this. Comm-slot cards do not really - * have a visible type, as far as I can tell at this time, - * so assume that MacOS had it properly configured and use - * that configuration. - */ - switch (current_mac_model->machineid) { - case MACH_MACLC575: - case MACH_MACP580: - case MACH_MACQ630: - NIC_PUT(sc, SNR_CR, CR_RST); wbflush(); - i = NIC_GET(sc, SNR_DCR); - sc->snr_dcr |= (i & 0xfff0); - sc->bitmode = (i & DCR_DW) ? 1 : 0; - break; - default: - break; - } - if (sn_obio_getaddr(sc, myaddr) && sn_obio_getaddr_kludge(sc, myaddr)) { /* XXX kludge for PB */ printf(": failed to get MAC address.\n"); - bus_space_unmap(sc->sc_regt, sc->sc_regh, SN_REGSIZE); + bus_space_unmap(sc->sc_st, sc->sc_sh, SONIC_NREGS * 4); return; } - printf(": integrated Ethernet adapter\n"); + printf(": integrated SONIC Ethernet adapter\n"); +#if 1 + printf("%s: %s bit mode, DCR=0x%04x\n", sc->sc_dev.dv_xname, + sc->sc_32bit ? "32" : "16", sc->sc_dcr); +#endif - /* snsetup returns 1 if something fails */ - if (snsetup(sc, myaddr)) { - bus_space_unmap(sc->sc_regt, sc->sc_regh, SN_REGSIZE); - return; - } + sonic_md_reset(sc); if (mac68k_machine.aux_interrupts) { - intr_establish((int (*)(void *))snintr, (void *)sc, 3); + intr_establish(sonic_intr, (void *)sc, 3); } else { - add_nubus_intr(sc->slotno, snintr, (void *)sc); + add_nubus_intr(SONIC_SLOTNO, (void (*)(void *))sonic_intr, + (void *)sc); } + + sonic_attach(sc, myaddr); } static int -sn_obio_getaddr(struct sn_softc *sc, u_int8_t *lladdr) +sn_obio_getaddr(struct sonic_softc *sc, uint8_t *lladdr) { bus_space_handle_t bsh; - if (bus_space_map(sc->sc_regt, SONIC_PROM_BASE, PAGE_SIZE, 0, &bsh)) { + if (bus_space_map(sc->sc_st, SONIC_PROM_BASE, PAGE_SIZE, 0, &bsh)) { printf(": failed to map space to read SONIC address.\n%s", sc->sc_dev.dv_xname); return (-1); } - if (!mac68k_bus_space_probe(sc->sc_regt, bsh, 0, 1)) { - bus_space_unmap(sc->sc_regt, bsh, PAGE_SIZE); + if (!mac68k_bus_space_probe(sc->sc_st, bsh, 0, 1)) { + bus_space_unmap(sc->sc_st, bsh, PAGE_SIZE); return (-1); } - sn_get_enaddr(sc->sc_regt, bsh, 0, lladdr); + sn_get_enaddr(sc->sc_st, bsh, 0, lladdr); - bus_space_unmap(sc->sc_regt, bsh, PAGE_SIZE); + bus_space_unmap(sc->sc_st, bsh, PAGE_SIZE); return 0; } @@ -222,39 +201,35 @@ * when we can properly get the MAC address on the PBs. */ static int -sn_obio_getaddr_kludge(struct sn_softc *sc, u_int8_t *lladdr) +sn_obio_getaddr_kludge(struct sonic_softc *sc, u_int8_t *lladdr) { int i, ors = 0; /* Shut down NIC */ - NIC_PUT(sc, SNR_CR, CR_RST); - wbflush(); + CSR_WRITE(sc, SONIC_CR, CR_RST); + + /* For some reason, Apple fills top first. */ + CSR_WRITE(sc, SONIC_CEP, 15); - NIC_PUT(sc, SNR_CEP, 15); /* For some reason, Apple fills top first. */ - wbflush(); - i = NIC_GET(sc, SNR_CAP2); - wbflush(); + i = CSR_READ(sc, SONIC_CAP2); ors |= i; lladdr[5] = i >> 8; lladdr[4] = i; - i = NIC_GET(sc, SNR_CAP1); - wbflush(); + i = CSR_READ(sc, SONIC_CAP1); ors |= i; lladdr[3] = i >> 8; lladdr[2] = i; - i = NIC_GET(sc, SNR_CAP0); - wbflush(); + i = CSR_READ(sc, SONIC_CAP0); ors |= i; lladdr[1] = i >> 8; lladdr[0] = i; - NIC_PUT(sc, SNR_CR, 0); - wbflush(); + CSR_WRITE(sc, SONIC_CR, 0); if (ors == 0) return -1; Index: dev/ic/dp83932reg.h =================================================================== RCS file: /cvsroot/src/sys/dev/ic/dp83932reg.h,v retrieving revision 1.4 diff -u -r1.4 dp83932reg.h --- dev/ic/dp83932reg.h 11 Dec 2005 12:21:26 -0000 1.4 +++ dev/ic/dp83932reg.h 31 May 2007 11:27:14 -0000 @@ -247,6 +247,8 @@ #define IMR_HBL (1U << 13) /* Heartbeat Lost */ #define IMR_BR (1U << 14) /* Bus Retry Occurred */ +#define IMR_ALL 0x7fff + #define SONIC_ISR 0x05 /* Interrupt Status Register */ /* See IMR bits. */