summaryrefslogtreecommitdiff
path: root/sys/arch/sparc/dev
diff options
context:
space:
mode:
authorJason Wright <jason@cvs.openbsd.org>2001-01-30 07:17:08 +0000
committerJason Wright <jason@cvs.openbsd.org>2001-01-30 07:17:08 +0000
commit394d9603b5aec314d2073fd8cdb746edc4753246 (patch)
tree13569401a84505774b60347c3e9e9bd5196991bf /sys/arch/sparc/dev
parent2d1565ea86417a77cedfd20e537a46de5a418f5c (diff)
- take advantage of the fact that qe's and be's require qec's and move
some common functionality into qec's driver (rx and tx frame fetching) - avoid modulus operations - some style
Diffstat (limited to 'sys/arch/sparc/dev')
-rw-r--r--sys/arch/sparc/dev/be.c110
-rw-r--r--sys/arch/sparc/dev/bereg.h11
-rw-r--r--sys/arch/sparc/dev/qe.c107
-rw-r--r--sys/arch/sparc/dev/qec.c101
-rw-r--r--sys/arch/sparc/dev/qecvar.h4
-rw-r--r--sys/arch/sparc/dev/qereg.h11
6 files changed, 138 insertions, 206 deletions
diff --git a/sys/arch/sparc/dev/be.c b/sys/arch/sparc/dev/be.c
index 1fc15a78254..62669c2c549 100644
--- a/sys/arch/sparc/dev/be.c
+++ b/sys/arch/sparc/dev/be.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: be.c,v 1.23 2000/06/18 17:37:02 jason Exp $ */
+/* $OpenBSD: be.c,v 1.24 2001/01/30 07:17:07 jason Exp $ */
/*
* Copyright (c) 1998 Theo de Raadt and Jason L. Wright.
@@ -85,9 +85,7 @@ int berint __P((struct besoftc *));
int betint __P((struct besoftc *));
int beqint __P((struct besoftc *, u_int32_t));
int beeint __P((struct besoftc *, u_int32_t));
-int be_put __P((struct besoftc *, int, struct mbuf *));
void be_read __P((struct besoftc *, int, int));
-struct mbuf * be_get __P((struct besoftc *, int, int));
void be_tcvr_idle __P((struct besoftc *));
void be_tcvr_init __P((struct besoftc *));
@@ -278,7 +276,7 @@ bestart(ifp)
/*
* Copy the mbuf chain into the transmit buffer.
*/
- len = be_put(sc, bix, m);
+ len = qec_put(sc->sc_bufs->tx_buf[bix & BE_TX_RING_MASK], m);
/*
* Initialize transmit registers and start transmission
@@ -498,7 +496,7 @@ berint(sc)
len = sc->sc_desc->be_rxd[bix].rx_flags & BE_RXD_LENGTH;
be_read(sc, bix, len);
- sc->sc_desc->be_rxd[(bix + BE_RX_RING_SIZE)%BE_RX_RING_MAXSIZE].rx_flags =
+ sc->sc_desc->be_rxd[(bix + BE_RX_RING_SIZE) & BE_RX_RING_MAXMASK].rx_flags =
BE_RXD_OWN | (BE_PKT_BUF_SZ & BE_RXD_LENGTH);
if (++bix == BE_RX_RING_MAXSIZE)
@@ -639,16 +637,15 @@ beinit(sc)
for (i = 0; i < BE_TX_RING_MAXSIZE; i++) {
sc->sc_desc->be_txd[i].tx_addr =
- (u_int32_t) &sc->sc_bufs_dva->tx_buf[i % BE_TX_RING_SIZE][0];
+ (u_int32_t)sc->sc_bufs_dva->tx_buf[i & BE_TX_RING_MASK];
sc->sc_desc->be_txd[i].tx_flags = 0;
}
for (i = 0; i < BE_RX_RING_MAXSIZE; i++) {
sc->sc_desc->be_rxd[i].rx_addr =
- (u_int32_t) &sc->sc_bufs_dva->rx_buf[i % BE_RX_RING_SIZE][0];
- if ((i / BE_RX_RING_SIZE) == 0)
+ (u_int32_t)sc->sc_bufs_dva->rx_buf[i & BE_RX_RING_MASK];
+ if (i < BE_RX_RING_SIZE)
sc->sc_desc->be_rxd[i].rx_flags =
- BE_RXD_OWN |
- (BE_PKT_BUF_SZ & BE_RXD_LENGTH);
+ BE_RXD_OWN | (BE_PKT_BUF_SZ & BE_RXD_LENGTH);
else
sc->sc_desc->be_rxd[i].rx_flags = 0;
}
@@ -680,8 +677,8 @@ beinit(sc)
br->xif_cfg = BE_BR_XCFG_ODENABLE | BE_BR_XCFG_RESV;
- cr->rxds = (u_int32_t) &sc->sc_desc_dva->be_rxd[0];
- cr->txds = (u_int32_t) &sc->sc_desc_dva->be_txd[0];
+ cr->rxds = (u_int32_t)sc->sc_desc_dva->be_rxd;
+ cr->txds = (u_int32_t)sc->sc_desc_dva->be_txd;
cr->rxwbufptr = cr->rxrbufptr = sc->sc_channel * qec->sc_msize;
cr->txwbufptr = cr->txrbufptr = cr->rxrbufptr + qec->sc_rsize;
@@ -965,34 +962,6 @@ be_tcvr_write_bit(sc, bit)
}
/*
- * Routine to copy from mbuf chain to transmit buffer in
- * network buffer memory.
- */
-int
-be_put(sc, idx, m)
- struct besoftc *sc;
- int idx;
- struct mbuf *m;
-{
- struct mbuf *n;
- int len, tlen = 0, boff = 0;
-
- for (; m; m = n) {
- len = m->m_len;
- if (len == 0) {
- MFREE(m, n);
- continue;
- }
- bcopy(mtod(m, caddr_t),
- &sc->sc_bufs->tx_buf[idx % BE_TX_RING_SIZE][boff], len);
- boff += len;
- tlen += len;
- MFREE(m, n);
- }
- return tlen;
-}
-
-/*
* Pass a packet to the higher levels.
*/
void
@@ -1017,7 +986,7 @@ be_read(sc, idx, len)
/*
* Pull packet off interface.
*/
- m = be_get(sc, idx, len);
+ m = qec_get(ifp, sc->sc_bufs->rx_buf[idx & BE_RX_RING_MASK], len);
if (m == NULL) {
ifp->if_ierrors++;
return;
@@ -1041,65 +1010,6 @@ be_read(sc, idx, len)
}
/*
- * Pull data off an interface.
- * Len is the length of data, with local net header stripped.
- * We copy the data into mbufs. When full cluster sized units are present,
- * we copy into clusters.
- */
-struct mbuf *
-be_get(sc, idx, totlen)
- struct besoftc *sc;
- int idx, totlen;
-{
- struct ifnet *ifp = &sc->sc_arpcom.ac_if;
- struct mbuf *m;
- struct mbuf *top, **mp;
- int len, pad, boff = 0;
-
- MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m == NULL)
- return (NULL);
- m->m_pkthdr.rcvif = ifp;
- m->m_pkthdr.len = totlen;
- pad = ALIGN(sizeof(struct ether_header)) - sizeof(struct ether_header);
- len = MHLEN;
- if (totlen >= MINCLSIZE) {
- MCLGET(m, M_DONTWAIT);
- if (m->m_flags & M_EXT)
- len = MCLBYTES;
- }
- m->m_data += pad;
- len -= pad;
- top = NULL;
- mp = &top;
-
- while (totlen > 0) {
- if (top) {
- MGET(m, M_DONTWAIT, MT_DATA);
- if (m == NULL) {
- m_freem(top);
- return NULL;
- }
- len = MLEN;
- }
- if (top && totlen >= MINCLSIZE) {
- MCLGET(m, M_DONTWAIT);
- if (m->m_flags & M_EXT)
- len = MCLBYTES;
- }
- m->m_len = len = min(totlen, len);
- bcopy(&sc->sc_bufs->rx_buf[idx % BE_RX_RING_SIZE][boff],
- mtod(m, caddr_t), len);
- boff += len;
- totlen -= len;
- *mp = m;
- mp = &m->m_next;
- }
-
- return (top);
-}
-
-/*
* Get current media settings.
*/
void
diff --git a/sys/arch/sparc/dev/bereg.h b/sys/arch/sparc/dev/bereg.h
index 1cab775c1da..be8d9e5c1cc 100644
--- a/sys/arch/sparc/dev/bereg.h
+++ b/sys/arch/sparc/dev/bereg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bereg.h,v 1.8 1999/01/07 03:14:42 jason Exp $ */
+/* $OpenBSD: bereg.h,v 1.9 2001/01/30 07:17:07 jason Exp $ */
/*
* Copyright (c) 1998 Theo de Raadt and Jason L. Wright.
@@ -257,10 +257,15 @@ struct be_txd {
/* Buffer and Ring sizes: fixed ring size */
#define BE_TX_RING_MAXSIZE 256 /* maximum tx ring size */
#define BE_RX_RING_MAXSIZE 256 /* maximum rx ring size */
-#define BE_TX_RING_SIZE 32
-#define BE_RX_RING_SIZE 32
+#define BE_TX_RING_SIZE 32 /* power of 2, <= MAXSIZE */
+#define BE_RX_RING_SIZE 32 /* power of 2, <= MAXSIZE */
#define BE_PKT_BUF_SZ 2048
+#define BE_TX_RING_MAXMASK (BE_TX_RING_MAXSIZE-1)
+#define BE_RX_RING_MAXMASK (BE_RX_RING_MAXSIZE-1)
+#define BE_TX_RING_MASK (BE_TX_RING_SIZE-1)
+#define BE_RX_RING_MASK (BE_RX_RING_SIZE-1)
+
/*
* BE descriptor rings
*/
diff --git a/sys/arch/sparc/dev/qe.c b/sys/arch/sparc/dev/qe.c
index 2404679e761..33984d790c3 100644
--- a/sys/arch/sparc/dev/qe.c
+++ b/sys/arch/sparc/dev/qe.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: qe.c,v 1.13 2000/11/17 17:38:32 jason Exp $ */
+/* $OpenBSD: qe.c,v 1.14 2001/01/30 07:17:07 jason Exp $ */
/*
* Copyright (c) 1998, 2000 Jason L. Wright.
@@ -93,9 +93,7 @@ int qeintr __P((void *));
int qe_eint __P((struct qesoftc *, u_int32_t));
int qe_rint __P((struct qesoftc *));
int qe_tint __P((struct qesoftc *));
-int qe_put __P((struct qesoftc *, int, struct mbuf *));
void qe_read __P((struct qesoftc *, int, int));
-struct mbuf * qe_get __P((struct qesoftc *, int, int));
void qe_mcreset __P((struct qesoftc *));
void qe_ifmedia_sts __P((struct ifnet *, struct ifmediareq *));
int qe_ifmedia_upd __P((struct ifnet *));
@@ -229,7 +227,7 @@ qestart(ifp)
/*
* Copy the mbuf chain into the transmit buffer.
*/
- len = qe_put(sc, bix, m);
+ len = qec_put(sc->sc_bufs->tx_buf[bix & QE_TX_RING_MASK], m);
/*
* Initialize transmit registers and start transmission
@@ -392,7 +390,7 @@ qe_rint(sc)
len = (sc->sc_desc->qe_rxd[bix].rx_flags & QE_RXD_LENGTH) - 4;
qe_read(sc, bix, len);
- sc->sc_desc->qe_rxd[(bix + QE_RX_RING_SIZE) % QE_RX_RING_MAXSIZE].rx_flags =
+ sc->sc_desc->qe_rxd[(bix + QE_RX_RING_SIZE) & QE_RX_RING_MAXMASK].rx_flags =
QE_RXD_OWN | QE_RXD_LENGTH;
if (++bix == QE_RX_RING_MAXSIZE)
@@ -710,17 +708,17 @@ qeinit(sc)
for (i = 0; i < QE_TX_RING_MAXSIZE; i++)
sc->sc_desc->qe_txd[i].tx_addr =
- (u_int32_t) &sc->sc_bufs_dva->tx_buf[i % QE_TX_RING_SIZE][0];
+ (u_int32_t)sc->sc_bufs_dva->tx_buf[i & QE_TX_RING_MASK];
for (i = 0; i < QE_RX_RING_MAXSIZE; i++) {
sc->sc_desc->qe_rxd[i].rx_addr =
- (u_int32_t) &sc->sc_bufs_dva->rx_buf[i % QE_RX_RING_SIZE][0];
- if ((i / QE_RX_RING_SIZE) == 0)
+ (u_int32_t)sc->sc_bufs_dva->rx_buf[i & QE_RX_RING_MASK];
+ if (i < QE_RX_RING_SIZE)
sc->sc_desc->qe_rxd[i].rx_flags =
QE_RXD_OWN | QE_RXD_LENGTH;
}
- cr->rxds = (u_int32_t) &sc->sc_desc_dva->qe_rxd[0];
- cr->txds = (u_int32_t) &sc->sc_desc_dva->qe_txd[0];
+ cr->rxds = (u_int32_t)sc->sc_desc_dva->qe_rxd;
+ cr->txds = (u_int32_t)sc->sc_desc_dva->qe_txd;
sc->sc_first_td = sc->sc_last_td = sc->sc_no_td = 0;
sc->sc_last_rd = 0;
@@ -778,34 +776,6 @@ qeinit(sc)
}
/*
- * Routine to copy from mbuf chain to transmit buffer in
- * network buffer memory.
- */
-int
-qe_put(sc, idx, m)
- struct qesoftc *sc;
- int idx;
- struct mbuf *m;
-{
- struct mbuf *n;
- int len, tlen = 0, boff = 0;
-
- for (; m; m = n) {
- len = m->m_len;
- if (len == 0) {
- MFREE(m, n);
- continue;
- }
- bcopy(mtod(m, caddr_t),
- &sc->sc_bufs->tx_buf[idx % QE_TX_RING_SIZE][boff], len);
- boff += len;
- tlen += len;
- MFREE(m, n);
- }
- return tlen;
-}
-
-/*
* Pass a packet to the higher levels.
*/
void
@@ -830,7 +800,7 @@ qe_read(sc, idx, len)
/*
* Pull packet off interface.
*/
- m = qe_get(sc, idx, len);
+ m = qec_get(ifp, sc->sc_bufs->rx_buf[idx & QE_RX_RING_MASK], len);
if (m == NULL) {
ifp->if_ierrors++;
return;
@@ -854,65 +824,6 @@ qe_read(sc, idx, len)
}
/*
- * Pull data off an interface.
- * Len is the length of data, with local net header stripped.
- * We copy the data into mbufs. When full cluster sized units are present,
- * we copy into clusters.
- */
-struct mbuf *
-qe_get(sc, idx, totlen)
- struct qesoftc *sc;
- int idx, totlen;
-{
- struct ifnet *ifp = &sc->sc_arpcom.ac_if;
- struct mbuf *m;
- struct mbuf *top, **mp;
- int len, pad, boff = 0;
-
- MGETHDR(m, M_DONTWAIT, MT_DATA);
- if (m == NULL)
- return (NULL);
- m->m_pkthdr.rcvif = ifp;
- m->m_pkthdr.len = totlen;
- pad = ALIGN(sizeof(struct ether_header)) - sizeof(struct ether_header);
- len = MHLEN;
- if (totlen >= MINCLSIZE) {
- MCLGET(m, M_DONTWAIT);
- if (m->m_flags & M_EXT)
- len = MCLBYTES;
- }
- m->m_data += pad;
- len -= pad;
- top = NULL;
- mp = &top;
-
- while (totlen > 0) {
- if (top) {
- MGET(m, M_DONTWAIT, MT_DATA);
- if (m == NULL) {
- m_freem(top);
- return NULL;
- }
- len = MLEN;
- }
- if (top && totlen >= MINCLSIZE) {
- MCLGET(m, M_DONTWAIT);
- if (m->m_flags & M_EXT)
- len = MCLBYTES;
- }
- m->m_len = len = min(totlen, len);
- bcopy(&sc->sc_bufs->rx_buf[idx % QE_RX_RING_SIZE][boff],
- mtod(m, caddr_t), len);
- boff += len;
- totlen -= len;
- *mp = m;
- mp = &m->m_next;
- }
-
- return (top);
-}
-
-/*
* Reset multicast filter.
*/
void
diff --git a/sys/arch/sparc/dev/qec.c b/sys/arch/sparc/dev/qec.c
index d9935ce2796..eeee47325c7 100644
--- a/sys/arch/sparc/dev/qec.c
+++ b/sys/arch/sparc/dev/qec.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: qec.c,v 1.12 1999/07/05 22:30:06 deraadt Exp $ */
+/* $OpenBSD: qec.c,v 1.13 2001/01/30 07:17:07 jason Exp $ */
/*
* Copyright (c) 1998 Theo de Raadt and Jason L. Wright.
@@ -38,6 +38,22 @@
#include <sys/buf.h>
#include <sys/proc.h>
#include <sys/user.h>
+#include <sys/mbuf.h>
+#include <sys/socket.h>
+
+#include <net/if.h>
+#include <net/if_dl.h>
+#include <net/if_types.h>
+#include <net/netisr.h>
+#include <net/if_media.h>
+
+#ifdef INET
+#include <netinet/in.h>
+#include <netinet/in_systm.h>
+#include <netinet/in_var.h>
+#include <netinet/ip.h>
+#include <netinet/if_ether.h>
+#endif
#include <sparc/autoconf.h>
#include <sparc/cpu.h>
@@ -288,3 +304,86 @@ qec_reset(sc)
qr->ctrl = (qr->ctrl & QEC_CTRL_MODEMASK) | i;
}
+
+/*
+ * Routine to copy from mbuf chain to transmit buffer in
+ * network buffer memory.
+ */
+int
+qec_put(buf, m)
+ u_int8_t *buf;
+ struct mbuf *m;
+{
+ struct mbuf *n;
+ int len, tlen = 0;
+
+ for (; m != NULL; m = n) {
+ len = m->m_len;
+ if (len == 0) {
+ MFREE(m, n);
+ continue;
+ }
+ bcopy(mtod(m, caddr_t), buf, len);
+ buf += len;
+ tlen += len;
+ MFREE(m, n);
+ }
+ return tlen;
+}
+
+/*
+ * Pull data off an interface.
+ * Len is the length of data, with local net header stripped.
+ * We copy the data into mbufs. When full cluster sized units are present,
+ * we copy into clusters.
+ */
+struct mbuf *
+qec_get(ifp, buf, totlen)
+ struct ifnet *ifp;
+ u_int8_t *buf;
+ int totlen;
+{
+ struct mbuf *m, *top, **mp;
+ int len, pad;
+
+ MGETHDR(m, M_DONTWAIT, MT_DATA);
+ if (m == NULL)
+ return (NULL);
+ m->m_pkthdr.rcvif = ifp;
+ m->m_pkthdr.len = totlen;
+ pad = ALIGN(sizeof(struct ether_header)) - sizeof(struct ether_header);
+ len = MHLEN;
+ if (totlen >= MINCLSIZE) {
+ MCLGET(m, M_DONTWAIT);
+ if (m->m_flags & M_EXT)
+ len = MCLBYTES;
+ }
+ m->m_data += pad;
+ len -= pad;
+ top = NULL;
+ mp = &top;
+
+ while (totlen > 0) {
+ if (top) {
+ MGET(m, M_DONTWAIT, MT_DATA);
+ if (m == NULL) {
+ m_freem(top);
+ return NULL;
+ }
+ len = MLEN;
+ }
+ if (top && totlen >= MINCLSIZE) {
+ MCLGET(m, M_DONTWAIT);
+ if (m->m_flags & M_EXT)
+ len = MCLBYTES;
+ }
+ m->m_len = len = min(totlen, len);
+ bcopy(buf, mtod(m, caddr_t), len);
+ buf += len;
+ totlen -= len;
+ *mp = m;
+ mp = &m->m_next;
+ }
+
+ return (top);
+}
diff --git a/sys/arch/sparc/dev/qecvar.h b/sys/arch/sparc/dev/qecvar.h
index 8a0237ddbc0..d6d47c75d62 100644
--- a/sys/arch/sparc/dev/qecvar.h
+++ b/sys/arch/sparc/dev/qecvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: qecvar.h,v 1.7 1999/07/05 21:55:09 deraadt Exp $ */
+/* $OpenBSD: qecvar.h,v 1.8 2001/01/30 07:17:07 jason Exp $ */
/*
* Copyright (c) 1998 Theo de Raadt and Jason L. Wright.
@@ -48,3 +48,5 @@ struct qec_softc {
};
void qec_reset __P((struct qec_softc *));
+int qec_put __P((u_int8_t *, struct mbuf *));
+struct mbuf *qec_get __P((struct ifnet *, u_int8_t *, int));
diff --git a/sys/arch/sparc/dev/qereg.h b/sys/arch/sparc/dev/qereg.h
index d43c594e58d..f1f152e17b6 100644
--- a/sys/arch/sparc/dev/qereg.h
+++ b/sys/arch/sparc/dev/qereg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: qereg.h,v 1.5 2000/11/16 15:47:57 jason Exp $ */
+/* $OpenBSD: qereg.h,v 1.6 2001/01/30 07:17:07 jason Exp $ */
/*
* Copyright (c) 1998, 2000 Jason L. Wright.
@@ -317,10 +317,15 @@ struct qe_txd {
/* Buffer and Ring sizes: fixed ring size */
#define QE_TX_RING_MAXSIZE 256 /* maximum tx ring size */
#define QE_RX_RING_MAXSIZE 256 /* maximum rx ring size */
-#define QE_TX_RING_SIZE 16
-#define QE_RX_RING_SIZE 16
+#define QE_TX_RING_SIZE 16 /* power of 2, <= MAXSIZE */
+#define QE_RX_RING_SIZE 16 /* power of 2, <= MAXSIZE */
#define QE_PKT_BUF_SZ 2048
+#define QE_TX_RING_MAXMASK (QE_TX_RING_MAXSIZE-1)
+#define QE_RX_RING_MAXMASK (QE_RX_RING_MAXSIZE-1)
+#define QE_TX_RING_MASK (QE_TX_RING_SIZE-1)
+#define QE_RX_RING_MASK (QE_RX_RING_SIZE-1)
+
/*
* QE descriptor rings
*/