Increase receive ring to 128 entries and handle both endian devices.

This commit is contained in:
eeh 2001-10-01 23:39:57 +00:00
parent 0fcb9b7701
commit ef420318e0
2 changed files with 24 additions and 94 deletions
sys/dev/ic

@ -1,4 +1,4 @@
/* $NetBSD: gem.c,v 1.1 2001/09/16 00:11:43 eeh Exp $ */
/* $NetBSD: gem.c,v 1.2 2001/10/01 23:39:57 eeh Exp $ */
/*
*
@ -224,7 +224,6 @@ gem_config(sc)
* before this point releases all resources that may have been
* allocated.
*/
sc->sc_flags |= GEMF_ATTACHED;
/* Announce ourselves. */
printf("%s: Ethernet address %s\n", sc->sc_dev.dv_xname,
@ -1075,7 +1074,7 @@ bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_TX_KICK));
* to do it.
*/
sc->sc_txdescs[nexttx].gd_addr =
htole64(dmamap->dm_segs[seg].ds_addr);
GEM_DMA_WRITE(sc, dmamap->dm_segs[seg].ds_addr);
flags = dmamap->dm_segs[seg].ds_len & GEM_TD_BUFSIZE;
if (nexttx == firsttx) {
flags |= GEM_TD_START_OF_PACKET;
@ -1084,7 +1083,7 @@ bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_TX_KICK));
flags |= GEM_TD_END_OF_PACKET;
}
sc->sc_txdescs[nexttx].gd_flags =
htole64(flags);
GEM_DMA_WRITE(sc, flags);
lasttx = nexttx;
}
@ -1094,9 +1093,9 @@ bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_TX_KICK));
for (seg = sc->sc_txnext;; seg = GEM_NEXTTX(seg)) {
printf("descriptor %d:\t", seg);
printf("gd_flags: 0x%016llx\t", (long long)
le64toh(sc->sc_txdescs[seg].gd_flags));
GEM_DMA_READ(sc, sc->sc_txdescs[seg].gd_flags));
printf("gd_addr: 0x%016llx\n", (long long)
le64toh(sc->sc_txdescs[seg].gd_addr));
GEM_DMA_READ(sc, sc->sc_txdescs[seg].gd_addr));
if (seg == lasttx)
break;
}
@ -1143,15 +1142,6 @@ bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_TX_KICK));
if (sc->sc_txfree != ofree) {
DPRINTF(sc, ("%s: packets enqueued, IC on %d, OWN on %d\n",
sc->sc_dev.dv_xname, lasttx, firsttx));
#if 0
/*
* Cause a transmit interrupt to happen on the
* last packet we enqueued.
*/
sc->sc_txdescs[lasttx].gd_flags |= htole64(GEM_TD_INTERRUPT_ME);
GEM_CDTXSYNC(sc, lasttx, 1,
BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE);
#endif
/*
* The entire packet chain is set up.
* Kick the transmitter.
@ -1168,8 +1158,8 @@ if (gem_opdebug) {
(long long)bus_space_read_8(sc->sc_bustag, sc->sc_h, GEM_TX_RING_PTR));
printf("descriptor %d: ", (i = lasttx));
printf("gd_flags: 0x%016llx\t", (long long)
le64toh(sc->sc_txdescs[i].gd_flags));
pa = le64toh(sc->sc_txdescs[i].gd_addr);
GEM_DMA_READ(sc, sc->sc_txdescs[i].gd_flags));
pa = GEM_DMA_READ(sc, sc->sc_txdescs[i].gd_addr);
printf("gd_addr: 0x%016llx\n", (long long) pa);
printf("GEM_TX_CONFIG %x GEM_MAC_XIF_CONFIG %x GEM_MAC_TX_CONFIG %x\n",
bus_space_read_4(sc->sc_bustag, sc->sc_h, GEM_TX_CONFIG),
@ -1202,8 +1192,7 @@ gem_tint(sc)
int txlast;
DPRINTF(sc, ("%s: gem_tint: sc_flags 0x%08x\n",
sc->sc_dev.dv_xname, sc->sc_flags));
DPRINTF(sc, ("%s: gem_tint\n", sc->sc_dev.dv_xname));
/*
* Unload collision counters
@ -1238,9 +1227,9 @@ gem_tint(sc)
for (i = txs->txs_firstdesc;; i = GEM_NEXTTX(i)) {
printf("descriptor %d: ", i);
printf("gd_flags: 0x%016llx\t", (long long)
le64toh(sc->sc_txdescs[i].gd_flags));
GEM_DMA_READ(sc, sc->sc_txdescs[i].gd_flags));
printf("gd_addr: 0x%016llx\n", (long long)
le64toh(sc->sc_txdescs[i].gd_addr));
GEM_DMA_READ(sc, sc->sc_txdescs[i].gd_addr));
if (i == txs->txs_lastdesc)
break;
}
@ -1326,8 +1315,7 @@ gem_rint(sc)
u_int64_t rxstat;
int i, len;
DPRINTF(sc, ("%s: gem_rint: sc_flags 0x%08x\n",
sc->sc_dev.dv_xname, sc->sc_flags));
DPRINTF(sc, ("%s: gem_rint\n", sc->sc_dev.dv_xname));
/*
* XXXX Read the lastrx only once at the top for speed.
*/
@ -1340,7 +1328,7 @@ gem_rint(sc)
GEM_CDRXSYNC(sc, i,
BUS_DMASYNC_POSTREAD|BUS_DMASYNC_POSTWRITE);
rxstat = le64toh(sc->sc_rxdescs[i].gd_flags);
rxstat = GEM_DMA_READ(sc, sc->sc_rxdescs[i].gd_flags);
if (rxstat & GEM_RD_OWN) {
printf("gem_rint: completed descriptor "
@ -1364,9 +1352,9 @@ gem_rint(sc)
if (ifp->if_flags & IFF_DEBUG) {
printf(" rxsoft %p descriptor %d: ", rxs, i);
printf("gd_flags: 0x%016llx\t", (long long)
le64toh(sc->sc_rxdescs[i].gd_flags));
GEM_DMA_READ(sc, sc->sc_rxdescs[i].gd_flags));
printf("gd_addr: 0x%016llx\n", (long long)
le64toh(sc->sc_rxdescs[i].gd_addr));
GEM_DMA_READ(sc, sc->sc_rxdescs[i].gd_addr));
}
#endif
@ -1376,12 +1364,6 @@ gem_rint(sc)
*/
len = GEM_RD_BUFLEN(rxstat);
/*
* We align the mbuf data in gem_add_rxbuf() so
* we can use __NO_STRICT_ALIGNMENT here
*/
#define __NO_STRICT_ALIGNMENT
#ifdef __NO_STRICT_ALIGNMENT
/*
* Allocate a new mbuf cluster. If that fails, we are
* out of memory, and must drop the packet and recycle
@ -1396,42 +1378,6 @@ gem_rint(sc)
continue;
}
m->m_data += 2; /* We're already off by two */
#else
/*
* The Gem's receive buffers must be 4-byte aligned.
* But this means that the data after the Ethernet header
* is misaligned. We must allocate a new buffer and
* copy the data, shifted forward 2 bytes.
*/
MGETHDR(m, M_DONTWAIT, MT_DATA);
if (m == NULL) {
dropit:
ifp->if_ierrors++;
GEM_INIT_RXDESC(sc, i);
bus_dmamap_sync(sc->sc_dmatag, rxs->rxs_dmamap, 0,
rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
continue;
}
if (len > (MHLEN - 2)) {
MCLGET(m, M_DONTWAIT);
if ((m->m_flags & M_EXT) == 0) {
m_freem(m);
goto dropit;
}
}
m->m_data += 2;
/*
* Note that we use clusters for incoming frames, so the
* buffer is virtually contiguous.
*/
memcpy(mtod(m, caddr_t), mtod(rxs->rxs_mbuf, caddr_t), len);
/* Allow the receive descriptor to continue using its mbuf. */
GEM_INIT_RXDESC(sc, i);
bus_dmamap_sync(sc->sc_dmatag, rxs->rxs_dmamap, 0,
rxs->rxs_dmamap->dm_mapsize, BUS_DMASYNC_PREREAD);
#endif /* __NO_STRICT_ALIGNMENT */
ifp->if_ipackets++;
eh = mtod(m, struct ether_header *);
@ -1576,8 +1522,8 @@ if (gem_opdebug && (status & GEM_INTR_TX_DONE)) {
(long long)bus_space_read_8(t, seb, GEM_TX_RING_PTR));
printf("descriptor %d: ", --i);
printf("gd_flags: 0x%016llx\t", (long long)
le64toh(sc->sc_txdescs[i].gd_flags));
pa = le64toh(sc->sc_txdescs[i].gd_addr);
GEM_DMA_READ(sc, sc->sc_txdescs[i].gd_flags));
pa = GEM_DMA_READ(sc, sc->sc_txdescs[i].gd_addr);
printf("gd_addr: 0x%016llx\n", (long long) pa);
printf("GEM_TX_CONFIG %x GEM_MAC_XIF_CONFIG %x GEM_MAC_TX_CONFIG %x "
"GEM_MAC_TX_STATUS %x\n",
@ -1629,7 +1575,6 @@ gem_watchdog(ifp)
++ifp->if_oerrors;
/* Try to get more packets going. */
// gem_reset(sc);
gem_start(ifp);
}

@ -1,4 +1,4 @@
/* $NetBSD: gemvar.h,v 1.1 2001/09/16 00:11:43 eeh Exp $ */
/* $NetBSD: gemvar.h,v 1.2 2001/10/01 23:39:57 eeh Exp $ */
/*
*
@ -62,7 +62,7 @@
* Receive descriptor list size. We have one Rx buffer per incoming
* packet, so this logic is a little simpler.
*/
#define GEM_NRXDESC 64
#define GEM_NRXDESC 128
#define GEM_NRXDESC_MASK (GEM_NRXDESC - 1)
#define GEM_NEXTRX(x) ((x + 1) & GEM_NRXDESC_MASK)
@ -201,7 +201,6 @@ struct gem_softc {
/* ========== */
int sc_inited;
int sc_flags;
int sc_debug;
void *sc_sh; /* shutdownhook cookie */
u_int8_t sc_enaddr[ETHER_ADDR_LEN]; /* MAC address */
@ -215,24 +214,9 @@ struct gem_softc {
#endif
};
/* sc_flags */
#define GEMF_WANT_SETUP 0x00000001 /* want filter setup */
#define GEMF_DOING_SETUP 0x00000002 /* doing multicast setup */
#define GEMF_HAS_MII 0x00000004 /* has media on MII */
#define GEMF_IC_FS 0x00000008 /* IC bit on first tx seg */
#define GEMF_MRL 0x00000010 /* memory read line okay */
#define GEMF_MRM 0x00000020 /* memory read multi okay */
#define GEMF_MWI 0x00000040 /* memory write inval okay */
#define GEMF_AUTOPOLL 0x00000080 /* chip supports auto-poll */
#define GEMF_LINK_UP 0x00000100 /* link is up (non-MII) */
#define GEMF_LINK_VALID 0x00000200 /* link state valid */
#define GEMF_DOINGAUTO 0x00000400 /* doing autoneg (non-MII) */
#define GEMF_ATTACHED 0x00000800 /* attach has succeeded */
#define GEMF_ENABLED 0x00001000 /* chip is enabled */
#define GEMF_BLE 0x00002000 /* data is big endian */
#define GEMF_DBO 0x00004000 /* descriptor is big endian */
#define GEM_IS_ENABLED(sc) ((sc)->sc_flags & GEMF_ENABLED)
#define GEM_DMA_READ(sc, v) (((sc)->sc_pci) ? le64toh(v) : be64toh(v))
#define GEM_DMA_WRITE(sc, v) (((sc)->sc_pci) ? htole64(v) : htobe64(v))
/*
* This macro returns the current media entry for *non-MII* media.
@ -291,10 +275,11 @@ do { \
\
__m->m_data = __m->m_ext.ext_buf; \
__rxd->gd_addr = \
htole64(__rxs->rxs_dmamap->dm_segs[0].ds_addr); \
GEM_DMA_WRITE((sc), __rxs->rxs_dmamap->dm_segs[0].ds_addr); \
__rxd->gd_flags = \
htole64((((__m->m_ext.ext_size)<<GEM_RD_BUFSHIFT) \
& GEM_RD_BUFSIZE) | GEM_RD_OWN); \
GEM_DMA_WRITE((sc), \
(((__m->m_ext.ext_size)<<GEM_RD_BUFSHIFT) \
& GEM_RD_BUFSIZE) | GEM_RD_OWN); \
GEM_CDRXSYNC((sc), (x), BUS_DMASYNC_PREREAD|BUS_DMASYNC_PREWRITE); \
} while (0)