summaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorJason Wright <jason@cvs.openbsd.org>1999-09-03 01:48:40 +0000
committerJason Wright <jason@cvs.openbsd.org>1999-09-03 01:48:40 +0000
commite7bba369270be4970e14ade700d432e3dfc05f41 (patch)
tree3a451413c50ac99d78a82dc6906c133414c280ab /sys
parent0d14089618f70bc7a99f8af5c4ed211438e799dc (diff)
o make this look more like an OpenBSD driver (removed static's)
o partial merge with freebsd, alpha support (currently untested)
Diffstat (limited to 'sys')
-rw-r--r--sys/dev/pci/if_wb.c243
-rw-r--r--sys/dev/pci/if_wbreg.h12
2 files changed, 130 insertions, 125 deletions
diff --git a/sys/dev/pci/if_wb.c b/sys/dev/pci/if_wb.c
index 6513bc460f6..f79b263eef6 100644
--- a/sys/dev/pci/if_wb.c
+++ b/sys/dev/pci/if_wb.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_wb.c,v 1.1 1999/03/11 18:20:13 jason Exp $ */
+/* $OpenBSD: if_wb.c,v 1.2 1999/09/03 01:48:38 jason Exp $ */
/*
* Copyright (c) 1997, 1998
@@ -31,7 +31,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: if_wb.c,v 1.7 1999/02/01 21:25:52 wpaul Exp $
+ * $FreeBSD: if_wb.c,v 1.13 1999/07/11 00:56:07 wpaul Exp $
*/
/*
@@ -135,7 +135,7 @@
* so failure to positively identify the chip is not a fatal error.
*/
-static struct wb_type wb_phys[] = {
+struct wb_type wb_phys[] = {
{ TI_PHY_VENDORID, TI_PHY_10BT, "<TI ThunderLAN 10BT (internal)>" },
{ TI_PHY_VENDORID, TI_PHY_100VGPMI, "<TI TNETE211 100VG Any-LAN>" },
{ NS_PHY_VENDORID, NS_PHY_83840A, "<National Semiconductor DP83840A>"},
@@ -145,49 +145,49 @@ static struct wb_type wb_phys[] = {
{ 0, 0, "<MII-compliant physical interface>" }
};
-static int wb_probe __P((struct device *, void *, void *));
-static void wb_attach __P((struct device *, struct device *, void *));
-
-static int wb_newbuf __P((struct wb_softc *,
- struct wb_chain_onefrag *));
-static int wb_encap __P((struct wb_softc *, struct wb_chain *,
- struct mbuf *));
-
-static void wb_rxeof __P((struct wb_softc *));
-static void wb_rxeoc __P((struct wb_softc *));
-static void wb_txeof __P((struct wb_softc *));
-static void wb_txeoc __P((struct wb_softc *));
-static int wb_intr __P((void *));
-static void wb_start __P((struct ifnet *));
-static int wb_ioctl __P((struct ifnet *, u_long, caddr_t));
-static void wb_init __P((void *));
-static void wb_stop __P((struct wb_softc *));
-static void wb_watchdog __P((struct ifnet *));
-static void wb_shutdown __P((void *));
-static int wb_ifmedia_upd __P((struct ifnet *));
-static void wb_ifmedia_sts __P((struct ifnet *, struct ifmediareq *));
-
-static void wb_eeprom_putbyte __P((struct wb_softc *, int));
-static void wb_eeprom_getword __P((struct wb_softc *, int, u_int16_t *));
-static void wb_read_eeprom __P((struct wb_softc *, caddr_t, int,
+int wb_probe __P((struct device *, void *, void *));
+void wb_attach __P((struct device *, struct device *, void *));
+
+int wb_newbuf __P((struct wb_softc *, struct wb_chain_onefrag *,
+ struct mbuf *));
+int wb_encap __P((struct wb_softc *, struct wb_chain *,
+ struct mbuf *));
+
+void wb_rxeof __P((struct wb_softc *));
+void wb_rxeoc __P((struct wb_softc *));
+void wb_txeof __P((struct wb_softc *));
+void wb_txeoc __P((struct wb_softc *));
+int wb_intr __P((void *));
+void wb_start __P((struct ifnet *));
+int wb_ioctl __P((struct ifnet *, u_long, caddr_t));
+void wb_init __P((void *));
+void wb_stop __P((struct wb_softc *));
+void wb_watchdog __P((struct ifnet *));
+void wb_shutdown __P((void *));
+int wb_ifmedia_upd __P((struct ifnet *));
+void wb_ifmedia_sts __P((struct ifnet *, struct ifmediareq *));
+
+void wb_eeprom_putbyte __P((struct wb_softc *, int));
+void wb_eeprom_getword __P((struct wb_softc *, int, u_int16_t *));
+void wb_read_eeprom __P((struct wb_softc *, caddr_t, int,
int, int));
-static void wb_mii_sync __P((struct wb_softc *));
-static void wb_mii_send __P((struct wb_softc *, u_int32_t, int));
-static int wb_mii_readreg __P((struct wb_softc *, struct wb_mii_frame *));
-static int wb_mii_writereg __P((struct wb_softc *, struct wb_mii_frame *));
-static u_int16_t wb_phy_readreg __P((struct wb_softc *, int));
-static void wb_phy_writereg __P((struct wb_softc *, int, int));
-
-static void wb_autoneg_xmit __P((struct wb_softc *));
-static void wb_autoneg_mii __P((struct wb_softc *, int, int));
-static void wb_setmode_mii __P((struct wb_softc *, int));
-static void wb_getmode_mii __P((struct wb_softc *));
-static void wb_setcfg __P((struct wb_softc *, int));
-static u_int8_t wb_calchash __P((caddr_t));
-static void wb_setmulti __P((struct wb_softc *));
-static void wb_reset __P((struct wb_softc *));
-static int wb_list_rx_init __P((struct wb_softc *));
-static int wb_list_tx_init __P((struct wb_softc *));
+void wb_mii_sync __P((struct wb_softc *));
+void wb_mii_send __P((struct wb_softc *, u_int32_t, int));
+int wb_mii_readreg __P((struct wb_softc *, struct wb_mii_frame *));
+int wb_mii_writereg __P((struct wb_softc *, struct wb_mii_frame *));
+u_int16_t wb_phy_readreg __P((struct wb_softc *, int));
+void wb_phy_writereg __P((struct wb_softc *, int, int));
+
+void wb_autoneg_xmit __P((struct wb_softc *));
+void wb_autoneg_mii __P((struct wb_softc *, int, int));
+void wb_setmode_mii __P((struct wb_softc *, int));
+void wb_getmode_mii __P((struct wb_softc *));
+void wb_setcfg __P((struct wb_softc *, int));
+u_int8_t wb_calchash __P((caddr_t));
+void wb_setmulti __P((struct wb_softc *));
+void wb_reset __P((struct wb_softc *));
+int wb_list_rx_init __P((struct wb_softc *));
+int wb_list_tx_init __P((struct wb_softc *));
#define WB_SETBIT(sc, reg, x) \
CSR_WRITE_4(sc, reg, \
@@ -208,7 +208,7 @@ static int wb_list_tx_init __P((struct wb_softc *));
/*
* Send a read command and address to the EEPROM, check for ACK.
*/
-static void wb_eeprom_putbyte(sc, addr)
+void wb_eeprom_putbyte(sc, addr)
struct wb_softc *sc;
int addr;
{
@@ -238,7 +238,7 @@ static void wb_eeprom_putbyte(sc, addr)
/*
* Read a word of data stored in the EEPROM at address 'addr.'
*/
-static void wb_eeprom_getword(sc, addr, dest)
+void wb_eeprom_getword(sc, addr, dest)
struct wb_softc *sc;
int addr;
u_int16_t *dest;
@@ -279,7 +279,7 @@ static void wb_eeprom_getword(sc, addr, dest)
/*
* Read a sequence of words from the EEPROM.
*/
-static void wb_read_eeprom(sc, dest, off, cnt, swap)
+void wb_read_eeprom(sc, dest, off, cnt, swap)
struct wb_softc *sc;
caddr_t dest;
int off;
@@ -304,7 +304,7 @@ static void wb_read_eeprom(sc, dest, off, cnt, swap)
/*
* Sync the PHYs by setting data bit and strobing the clock 32 times.
*/
-static void wb_mii_sync(sc)
+void wb_mii_sync(sc)
struct wb_softc *sc;
{
register int i;
@@ -324,7 +324,7 @@ static void wb_mii_sync(sc)
/*
* Clock a series of bits through the MII.
*/
-static void wb_mii_send(sc, bits, cnt)
+void wb_mii_send(sc, bits, cnt)
struct wb_softc *sc;
u_int32_t bits;
int cnt;
@@ -349,7 +349,7 @@ static void wb_mii_send(sc, bits, cnt)
/*
* Read an PHY register through the MII.
*/
-static int wb_mii_readreg(sc, frame)
+int wb_mii_readreg(sc, frame)
struct wb_softc *sc;
struct wb_mii_frame *frame;
@@ -445,7 +445,7 @@ fail:
/*
* Write to a PHY register through the MII.
*/
-static int wb_mii_writereg(sc, frame)
+int wb_mii_writereg(sc, frame)
struct wb_softc *sc;
struct wb_mii_frame *frame;
@@ -491,7 +491,7 @@ static int wb_mii_writereg(sc, frame)
return(0);
}
-static u_int16_t wb_phy_readreg(sc, reg)
+u_int16_t wb_phy_readreg(sc, reg)
struct wb_softc *sc;
int reg;
{
@@ -506,7 +506,7 @@ static u_int16_t wb_phy_readreg(sc, reg)
return(frame.mii_data);
}
-static void wb_phy_writereg(sc, reg, data)
+void wb_phy_writereg(sc, reg, data)
struct wb_softc *sc;
int reg;
int data;
@@ -524,7 +524,7 @@ static void wb_phy_writereg(sc, reg, data)
return;
}
-static u_int8_t wb_calchash(addr)
+u_int8_t wb_calchash(addr)
caddr_t addr;
{
u_int32_t crc, carry;
@@ -558,7 +558,7 @@ static u_int8_t wb_calchash(addr)
/*
* Program the 64-bit multicast hash filter.
*/
-static void wb_setmulti(sc)
+void wb_setmulti(sc)
struct wb_softc *sc;
{
struct ifnet *ifp;
@@ -613,7 +613,7 @@ static void wb_setmulti(sc)
/*
* Initiate an autonegotiation session.
*/
-static void wb_autoneg_xmit(sc)
+void wb_autoneg_xmit(sc)
struct wb_softc *sc;
{
u_int16_t phy_sts;
@@ -633,7 +633,7 @@ static void wb_autoneg_xmit(sc)
/*
* Invoke autonegotiation on a PHY.
*/
-static void wb_autoneg_mii(sc, flag, verbose)
+void wb_autoneg_mii(sc, flag, verbose)
struct wb_softc *sc;
int flag;
int verbose;
@@ -778,7 +778,7 @@ static void wb_autoneg_mii(sc, flag, verbose)
return;
}
-static void wb_getmode_mii(sc)
+void wb_getmode_mii(sc)
struct wb_softc *sc;
{
u_int16_t bmsr;
@@ -840,7 +840,7 @@ static void wb_getmode_mii(sc)
/*
* Set speed and duplex mode.
*/
-static void wb_setmode_mii(sc, media)
+void wb_setmode_mii(sc, media)
struct wb_softc *sc;
int media;
{
@@ -902,7 +902,7 @@ static void wb_setmode_mii(sc, media)
* 'full-duplex' and '100Mbps' bits in the netconfig register, we
* first have to put the transmit and/or receive logic in the idle state.
*/
-static void wb_setcfg(sc, bmcr)
+void wb_setcfg(sc, bmcr)
struct wb_softc *sc;
int bmcr;
{
@@ -940,7 +940,7 @@ static void wb_setcfg(sc, bmcr)
return;
}
-static void wb_reset(sc)
+void wb_reset(sc)
struct wb_softc *sc;
{
register int i;
@@ -969,7 +969,7 @@ static void wb_reset(sc)
* Probe for a Winbond chip. Check the PCI vendor and device
* IDs against our list and return a device name if we find a match.
*/
-static int
+int
wb_probe(parent, match, aux)
struct device *parent;
void *match, *aux;
@@ -997,7 +997,7 @@ wb_probe(parent, match, aux)
* Attach the interface. Allocate softc structures, do ifmedia
* setup and ethernet/BPF attach.
*/
-static void
+void
wb_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
@@ -1011,7 +1011,7 @@ wb_attach(parent, self, aux)
bus_addr_t iobase;
bus_size_t iosize;
int i, media = IFM_ETHER|IFM_100_TX|IFM_FDX;
- unsigned int round;
+ u_int round;
caddr_t roundptr;
u_int16_t phy_vid, phy_did, phy_sts;
struct wb_type *p;
@@ -1128,7 +1128,12 @@ wb_attach(parent, self, aux)
}
sc->wb_ldata = (struct wb_list_data *)sc->wb_ldata_ptr;
- round = (unsigned int)sc->wb_ldata_ptr & 0xF;
+#ifdef __alpha__
+ round = (u_int64_t)sc->wb_ldata_ptr & 0xF;
+#endif
+#ifdef __i386__
+ round = (u_int32_t)sc->wb_ldata_ptr & 0xF;
+#endif
roundptr = sc->wb_ldata_ptr;
for (i = 0; i < 8; i++) {
if (round % 8) {
@@ -1213,7 +1218,7 @@ fail:
/*
* Initialize the transmit descriptors.
*/
-static int wb_list_tx_init(sc)
+int wb_list_tx_init(sc)
struct wb_softc *sc;
{
struct wb_chain_data *cd;
@@ -1246,7 +1251,7 @@ static int wb_list_tx_init(sc)
* we arrange the descriptors in a closed ring, so that the last descriptor
* points back to the first.
*/
-static int wb_list_rx_init(sc)
+int wb_list_rx_init(sc)
struct wb_softc *sc;
{
struct wb_chain_data *cd;
@@ -1259,7 +1264,7 @@ static int wb_list_rx_init(sc)
for (i = 0; i < WB_RX_LIST_CNT; i++) {
cd->wb_rx_chain[i].wb_ptr =
(struct wb_desc *)&ld->wb_rx_list[i];
- if (wb_newbuf(sc, &cd->wb_rx_chain[i]) == ENOBUFS)
+ if (wb_newbuf(sc, &cd->wb_rx_chain[i], NULL) == ENOBUFS)
return(ENOBUFS);
if (i == (WB_RX_LIST_CNT - 1)) {
cd->wb_rx_chain[i].wb_nextdesc = &cd->wb_rx_chain[0];
@@ -1281,22 +1286,33 @@ static int wb_list_rx_init(sc)
/*
* Initialize an RX descriptor and attach an MBUF cluster.
*/
-static int wb_newbuf(sc, c)
- struct wb_softc *sc;
- struct wb_chain_onefrag *c;
+int
+wb_newbuf(sc, c, m)
+ struct wb_softc *sc;
+ struct wb_chain_onefrag *c;
+ struct mbuf *m;
{
struct mbuf *m_new = NULL;
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL)
- return(ENOBUFS);
+ if (m == NULL) {
+ MGETHDR(m_new, M_DONTWAIT, MT_DATA);
+ if (m_new == NULL)
+ return(ENOBUFS);
- MCLGET(m_new, M_DONTWAIT);
- if (!(m_new->m_flags & M_EXT)) {
- m_freem(m_new);
- return(ENOBUFS);
+ MCLGET(m_new, M_DONTWAIT);
+ if (!(m_new->m_flags & M_EXT)) {
+ m_freem(m_new);
+ return(ENOBUFS);
+ }
+ m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
+ } else {
+ m_new = m;
+ m_new->m_len = m_new->m_pkthdr.len = MCLBYTES;
+ m_new->m_data = m_new->m_ext.ext_buf;
}
+ m_adj(m_new, sizeof(u_int64_t));
+
c->wb_mbuf = m_new;
c->wb_ptr->wb_data = vtophys(mtod(m_new, caddr_t));
c->wb_ptr->wb_ctl = WB_RXCTL_RLINK | (MCLBYTES - 1);
@@ -1309,7 +1325,7 @@ static int wb_newbuf(sc, c)
* A frame has been uploaded: pass the resulting mbuf chain up to
* the higher level protocols.
*/
-static void wb_rxeof(sc)
+void wb_rxeof(sc)
struct wb_softc *sc;
{
struct ether_header *eh;
@@ -1323,8 +1339,11 @@ static void wb_rxeof(sc)
while(!((rxstat = sc->wb_cdata.wb_rx_head->wb_ptr->wb_status) &
WB_RXSTAT_OWN)) {
+ struct mbuf *m0 = NULL;
+
cur_rx = sc->wb_cdata.wb_rx_head;
sc->wb_cdata.wb_rx_head = cur_rx->wb_nextdesc;
+ m = cur_rx->wb_mbuf;
if ((rxstat & WB_RXSTAT_MIIERR)
|| WB_RXBYTES(cur_rx->wb_ptr->wb_status) == 0) {
@@ -1339,9 +1358,7 @@ static void wb_rxeof(sc)
if (rxstat & WB_RXSTAT_RXERR) {
ifp->if_ierrors++;
- cur_rx->wb_ptr->wb_ctl =
- WB_RXCTL_RLINK | (MCLBYTES - 1);
- cur_rx->wb_ptr->wb_status = WB_RXSTAT;
+ wb_newbuf(sc, cur_rx, m);
continue;
}
@@ -1357,35 +1374,15 @@ static void wb_rxeof(sc)
*/
total_len -= ETHER_CRC_LEN;
- if (total_len < MINCLSIZE) {
- m = m_devget(mtod(cur_rx->wb_mbuf, char *),
- total_len, 0, ifp, NULL);
- cur_rx->wb_ptr->wb_ctl =
- WB_RXCTL_RLINK | (MCLBYTES - 1);
- cur_rx->wb_ptr->wb_status = WB_RXSTAT;
- if (m == NULL) {
- ifp->if_ierrors++;
- continue;
- }
- } else {
- m = cur_rx->wb_mbuf;
- /*
- * Try to conjure up a new mbuf cluster. If that
- * fails, it means we have an out of memory condition and
- * should leave the buffer in place and continue. This will
- * result in a lost packet, but there's little else we
- * can do in this situation.
- */
- if (wb_newbuf(sc, cur_rx) == ENOBUFS) {
- ifp->if_ierrors++;
- cur_rx->wb_ptr->wb_ctl =
- WB_RXCTL_RLINK | (MCLBYTES - 1);
- cur_rx->wb_ptr->wb_status = WB_RXSTAT;
- continue;
- }
- m->m_pkthdr.rcvif = ifp;
- m->m_pkthdr.len = m->m_len = total_len;
+ m0 = m_devget(mtod(m, char *) - ETHER_ALIGN,
+ total_len + ETHER_ALIGN, 0, ifp, NULL);
+ wb_newbuf(sc, cur_rx, m);
+ if (m0 == NULL) {
+ ifp->if_ierrors++;
+ continue;
}
+ m_adj(m0, ETHER_ALIGN);
+ m = m0;
ifp->if_ipackets++;
eh = mtod(m, struct ether_header *);
@@ -1423,7 +1420,7 @@ void wb_rxeoc(sc)
* A frame was downloaded to the chip. It's safe for us to clean up
* the list buffers.
*/
-static void wb_txeof(sc)
+void wb_txeof(sc)
struct wb_softc *sc;
{
struct wb_chain *cur_tx;
@@ -1479,7 +1476,7 @@ static void wb_txeof(sc)
/*
* TX 'end of channel' interrupt handler.
*/
-static void wb_txeoc(sc)
+void wb_txeoc(sc)
struct wb_softc *sc;
{
struct ifnet *ifp;
@@ -1504,7 +1501,7 @@ static void wb_txeoc(sc)
return;
}
-static int wb_intr(arg)
+int wb_intr(arg)
void *arg;
{
struct wb_softc *sc;
@@ -1593,7 +1590,7 @@ static int wb_intr(arg)
* Encapsulate an mbuf chain in a descriptor by coupling the mbuf data
* pointers to the fragment pointers.
*/
-static int wb_encap(sc, c, m_head)
+int wb_encap(sc, c, m_head)
struct wb_softc *sc;
struct wb_chain *c;
struct mbuf *m_head;
@@ -1687,7 +1684,7 @@ static int wb_encap(sc, c, m_head)
* physical addresses.
*/
-static void wb_start(ifp)
+void wb_start(ifp)
struct ifnet *ifp;
{
struct wb_softc *sc;
@@ -1782,7 +1779,7 @@ static void wb_start(ifp)
return;
}
-static void wb_init(xsc)
+void wb_init(xsc)
void *xsc;
{
struct wb_softc *sc = xsc;
@@ -1891,7 +1888,7 @@ static void wb_init(xsc)
/*
* Set media options.
*/
-static int wb_ifmedia_upd(ifp)
+int wb_ifmedia_upd(ifp)
struct ifnet *ifp;
{
struct wb_softc *sc;
@@ -1914,7 +1911,7 @@ static int wb_ifmedia_upd(ifp)
/*
* Report current media status.
*/
-static void wb_ifmedia_sts(ifp, ifmr)
+void wb_ifmedia_sts(ifp, ifmr)
struct ifnet *ifp;
struct ifmediareq *ifmr;
{
@@ -1959,7 +1956,7 @@ static void wb_ifmedia_sts(ifp, ifmr)
return;
}
-static int wb_ioctl(ifp, command, data)
+int wb_ioctl(ifp, command, data)
struct ifnet *ifp;
u_long command;
caddr_t data;
@@ -2017,7 +2014,7 @@ static int wb_ioctl(ifp, command, data)
return(error);
}
-static void wb_watchdog(ifp)
+void wb_watchdog(ifp)
struct ifnet *ifp;
{
struct wb_softc *sc;
@@ -2050,7 +2047,7 @@ static void wb_watchdog(ifp)
* Stop the adapter and free any mbufs allocated to the
* RX and TX lists.
*/
-static void wb_stop(sc)
+void wb_stop(sc)
struct wb_softc *sc;
{
register int i;
@@ -2098,7 +2095,7 @@ static void wb_stop(sc)
* Stop all chip I/O so that the kernel's probe routines don't
* get confused by errant DMAs when rebooting.
*/
-static void wb_shutdown(arg)
+void wb_shutdown(arg)
void *arg;
{
struct wb_softc *sc = (struct wb_softc *)arg;
diff --git a/sys/dev/pci/if_wbreg.h b/sys/dev/pci/if_wbreg.h
index 6a51029125b..7de8a70f0df 100644
--- a/sys/dev/pci/if_wbreg.h
+++ b/sys/dev/pci/if_wbreg.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_wbreg.h,v 1.1 1999/03/11 18:20:13 jason Exp $ */
+/* $OpenBSD: if_wbreg.h,v 1.2 1999/09/03 01:48:39 jason Exp $ */
/*
* Copyright (c) 1997, 1998
@@ -31,7 +31,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
- * $FreeBSD: if_wbreg.h,v 1.2 1999/01/16 06:25:59 wpaul Exp $
+ * $FreeBSD: if_wbreg.h,v 1.4 1999/07/11 00:56:07 wpaul Exp $
*/
/*
@@ -589,3 +589,11 @@ struct wb_softc {
#ifndef ETHER_CRC_LEN
#define ETHER_CRC_LEN 4
#endif
+#ifndef ETHER_ALIGN
+#define ETHER_ALIGN 2
+#endif
+
+#ifdef __alpha__
+#undef vtophys
+#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)va)
+#endif