aboutsummaryrefslogtreecommitdiff
path: root/sys/pci
diff options
context:
space:
mode:
authorMatt Jacob <mjacob@FreeBSD.org>2000-12-06 00:52:28 +0000
committerMatt Jacob <mjacob@FreeBSD.org>2000-12-06 00:52:28 +0000
commit61e1a8f478d5ebf34306aef4257e01f50776634e (patch)
tree0e50d44a871c7e4f7184a2a36737cee77c695ad1 /sys/pci
parent5c43d35fd79dfe5e7b6c79b0a24b0626475594c6 (diff)
downloadsrc-61e1a8f478d5ebf34306aef4257e01f50776634e.tar.gz
src-61e1a8f478d5ebf34306aef4257e01f50776634e.zip
Restore a sense of cleanly supporting multiple platforms. That is,
place the LOCKing macros within the areas within if_wxvar.h that is set aside for them. Put any platform specific data also in those areas. For ease of maintenance purposes, merge in the OpenBSD version codebase here.
Notes
Notes: svn path=/head/; revision=69649
Diffstat (limited to 'sys/pci')
-rw-r--r--sys/pci/if_wx.c92
-rw-r--r--sys/pci/if_wxvar.h39
2 files changed, 95 insertions, 36 deletions
diff --git a/sys/pci/if_wx.c b/sys/pci/if_wx.c
index 893f2c12e6c7..51ff687c15ea 100644
--- a/sys/pci/if_wx.c
+++ b/sys/pci/if_wx.c
@@ -1,3 +1,4 @@
+/* $FreeBSD$ */
/*
* Copyright (c) 1999, Traakan Software
* All rights reserved.
@@ -24,7 +25,6 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
*/
/*
@@ -56,7 +56,7 @@
* Since the includes are a mess, they'll all be in if_wxvar.h
*/
-#if defined(__NetBSD__)
+#if defined(__NetBSD__) || defined(__OpenBSD__)
#include <dev/pci/if_wxvar.h>
#elif defined(__FreeBSD__)
#include <pci/if_wxvar.h>
@@ -115,8 +115,8 @@ static void wx_dring_teardown __P((wx_softc_t *));
#define WX_MAXMTU ETHERMTU
#endif
-#if defined(__NetBSD__)
-#ifdef __BROKEN_INDIRECT_CONFIG
+#if defined(__NetBSD__) || defined(__OpenBSD__)
+#if defined(__BROKEN_INDIRECT_CONFIG) || defined(__OpenBSD__)
#define MATCHARG void *
#else
#define MATCHARG struct cfdata *
@@ -161,6 +161,12 @@ struct cfattach wx_ca = {
sizeof (wx_softc_t), wx_match, wx_attach
};
+#ifdef __OpenBSD__
+struct cfdriver wx_cd = {
+ 0, "wx", DV_IFNET
+};
+#endif
+
/*
* Check if a device is an 82452.
*/
@@ -220,7 +226,12 @@ wx_attach(parent, self, aux)
return;
}
intrstr = pci_intr_string(pc, ih);
+#if defined(__OpenBSD__)
+ sc->w.ih = pci_intr_establish(pc, ih, IPL_NET, wx_intr, sc,
+ self->dv_xname);
+#else
sc->w.ih = pci_intr_establish(pc, ih, IPL_NET, wx_intr, sc);
+#endif
if (sc->w.ih == NULL) {
printf("%s: couldn't establish interrupt", sc->wx_name);
if (intrstr != NULL)
@@ -230,7 +241,7 @@ wx_attach(parent, self, aux)
}
printf("%s: interrupting at %s\n", sc->wx_name, intrstr);
sc->wx_idnrev = (PCI_PRODUCT(pa->pa_id) << 16) |
- pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG) & 0xff;
+ (pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_CLASS_REG) & 0xff);
data = pci_conf_read(pa->pa_pc, pa->pa_tag, PCI_BHLC_REG);
data &= ~(PCI_CACHELINE_MASK << PCI_CACHELINE_SHIFT);
@@ -244,7 +255,7 @@ wx_attach(parent, self, aux)
printf("%s: Ethernet address %s\n",
sc->wx_name, ether_sprintf(sc->wx_enaddr));
- ifp = &sc->w.ethercom.ec_if;
+ ifp = &sc->wx_if;
bcopy(sc->wx_name, ifp->if_xname, IFNAMSIZ);
ifp->if_mtu = WX_MAXMTU;
ifp->if_softc = sc;
@@ -256,8 +267,17 @@ wx_attach(parent, self, aux)
/*
* Attach the interface.
*/
+ if_attach(ifp);
+#ifdef __OpenBSD__
+ ether_ifattach(ifp);
+#else
ether_ifattach(ifp, sc->wx_enaddr);
+#endif
+#if NBPFILTER > 0
+ bpfattach(&ifp->if_bpf, ifp, DLT_EN10MB,
+ sizeof (struct ether_header));
+#endif
/*
* Add shutdown hook so that DMA is disabled prior to reboot. Not
* doing do could allow DMA to corrupt kernel memory during the
@@ -308,7 +328,11 @@ wx_ether_ioctl(ifp, cmd, data)
switch (ifa->ifa_addr->sa_family) {
#ifdef INET
case AF_INET:
+#ifdef __OpenBSD__
+ arp_ifinit(&sc->w.arpcom, ifa);
+#else
arp_ifinit(ifp, ifa);
+#endif
break;
#endif
#ifdef NS
@@ -365,7 +389,12 @@ wx_mc_setup(sc)
return (wx_init(sc));
}
+#ifdef __OpenBSD__
+ ETHER_FIRST_MULTI(step, &sc->w.arpcom, enm);
+#else
ETHER_FIRST_MULTI(step, &sc->w.ethercom, enm);
+#endif
+
while (enm != NULL) {
if (memcmp(enm->enm_addrlo, enm->enm_addrhi, 6) != 0)
continue;
@@ -567,7 +596,10 @@ wx_attach(device_t dev)
}
}
- mtx_init(&sc->wx_mtx, device_get_nameunit(dev), MTX_DEF);
+#ifdef SMPNG
+ mtx_init(&sc->wx_mtx, device_get_nameunit(dev), MTX_DEF);
+#endif
+
WX_LOCK(sc);
/*
* get revision && id...
@@ -1190,7 +1222,7 @@ wx_intr(arg)
wx_softc_t *sc = arg;
int claimed = 0;
- WX_LOCK(sc);
+ WX_ILOCK(sc);
/*
* Read interrupt cause register. Reading it clears bits.
*/
@@ -1211,7 +1243,7 @@ wx_intr(arg)
}
WX_ENABLE_INT(sc);
}
- WX_UNLOCK(sc);
+ WX_IUNLK(sc);
return (claimed);
}
@@ -1247,11 +1279,13 @@ wx_handle_link_intr(sc)
if (sc->wx_icr & WXISR_LSC) {
if (READ_CSR(sc, WXREG_DSR) & WXDSR_LU) {
- printf("%s: gigabit link now up\n", sc->wx_name);
+ if (sc->wx_debug)
+ printf("%s: gigabit link up\n", sc->wx_name);
sc->linkup = 1;
sc->wx_dcr |= (WXDCR_SWDPIO0|WXDCR_SWDPIN0);
} else {
- printf("%s: gigabit link now down\n", sc->wx_name);
+ if (sc->wx_debug)
+ printf("%s: gigabit link down\n", sc->wx_name);
sc->linkup = 0;
sc->wx_dcr &= ~(WXDCR_SWDPIO0|WXDCR_SWDPIN0);
}
@@ -1437,17 +1471,12 @@ wx_handle_rxint(sc)
mb->m_len -= WX_CRC_LENGTH;
eh = mtod(m0, struct ether_header *);
- if ((ifp->if_flags & IFF_PROMISC) &&
- (bcmp(eh->ether_dhost, sc->wx_enaddr, ETHER_ADDR_LEN) &&
- (eh->ether_dhost[0] & 1) == 0)) {
- m_freem(m0);
- if (sc->rpending) {
- m_freem(sc->rpending);
- sc->rpending = NULL;
- }
- } else {
- pending[npkts++] = m0;
- }
+ /*
+ * No need to check for promiscous mode since
+ * the decision to keep or drop the packet is
+ * handled by ether_input()
+ */
+ pending[npkts++] = m0;
m0 = NULL;
tlen = 0;
}
@@ -1463,17 +1492,15 @@ wx_handle_rxint(sc)
for (idx = 0; idx < npkts; idx++) {
mb = pending[idx];
-#ifndef __FreeBSD__
if (ifp->if_bpf) {
bpf_mtap(WX_BPFTAP_ARG(ifp), mb);
}
-#endif
ifp->if_ipackets++;
if (sc->wx_debug) {
printf("%s: RECV packet length %d\n",
sc->wx_name, mb->m_pkthdr.len);
}
-#ifdef __FreeBSD__
+#if defined(__FreeBSD__) || defined(__OpenBSD__)
eh = mtod(mb, struct ether_header *);
m_adj(mb, sizeof (struct ether_header));
ether_input(ifp, eh, mb);
@@ -1542,12 +1569,16 @@ wx_gc(sc)
td = &sc->tdescriptors[cidx];
if (td->status & TXSTS_EC) {
- printf("%s: excess collisions\n", sc->wx_name);
+ if (sc->wx_debug)
+ printf("%s: excess collisions\n",
+ sc->wx_name);
ifp->if_collisions++;
ifp->if_oerrors++;
}
if (td->status & TXSTS_LC) {
- printf("%s: lost carrier\n", sc->wx_name);
+ if (sc->wx_debug)
+ printf("%s: lost carrier\n",
+ sc->wx_name);
ifp->if_oerrors++;
}
tmp = &sc->tbase[cidx];
@@ -1593,7 +1624,7 @@ wx_watchdog(arg)
/*
* Schedule another timeout one second from now.
*/
- TIMEOUT(sc, wx_watchdog, sc, hz);
+ VTIMEOUT(sc, wx_watchdog, sc, hz);
}
/*
@@ -1913,7 +1944,6 @@ wx_init(xsc)
WRITE_CSR(sc, WXREG_RDT1, 0);
if (ifp->if_mtu > ETHERMTU) {
- printf("%s: enabling for jumbo packets\n", sc->wx_name);
bflags = WXRCTL_EN | WXRCTL_LPE | WXRCTL_2KRBUF;
} else {
bflags = WXRCTL_EN | WXRCTL_2KRBUF;
@@ -2008,13 +2038,13 @@ wx_ioctl(ifp, command, data)
WX_LOCK(sc);
switch (command) {
case SIOCSIFADDR:
-#if !defined(__NetBSD__)
+#if !defined(__NetBSD__) && !defined(__OpenBSD__)
case SIOCGIFADDR:
#endif
error = ether_ioctl(ifp, command, data);
break;
-#ifdef SIOCGIFMTU
+#ifdef SIOCSIFMTU
case SIOCSIFMTU:
if (ifr->ifr_mtu > WX_MAXMTU || ifr->ifr_mtu < ETHERMIN) {
error = EINVAL;
diff --git a/sys/pci/if_wxvar.h b/sys/pci/if_wxvar.h
index c665ef0c8cc3..09e65945bfbe 100644
--- a/sys/pci/if_wxvar.h
+++ b/sys/pci/if_wxvar.h
@@ -1,3 +1,4 @@
+/* $FreeBSD$ */
/*
* Copyright (c) 1999, Traakan Software
* All rights reserved.
@@ -24,7 +25,6 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD$
*/
/*
@@ -102,6 +102,7 @@ struct wxmdvar {
bus_space_handle_t sh; /* bus space handle */
struct ifmedia ifm;
struct wx_softc * next;
+ int spl;
};
#define wx_dev w.dev
#define wx_enaddr w.enaddr
@@ -121,6 +122,10 @@ struct wxmdvar {
#define VTIMEOUT(sc, func, arg, time) timeout(func, arg, time)
#define UNTIMEOUT(f, arg, sc) untimeout(f, arg)
#define INLINE inline
+#define WX_LOCK(_sc) _sc->w.spl = splimp()
+#define WX_UNLOCK(_sc) splx(_sc->w.spl)
+#define WX_ILOCK(_sc)
+#define WX_IUNLK(_sc)
#define vm_offset_t vaddr_t
#ifndef IFM_1000_SX
@@ -130,6 +135,11 @@ struct wxmdvar {
#define WRITE_CSR _write_csr
#elif defined(__FreeBSD__)
+/*
+ * Enable for FreeBSD 5.0 SMP code
+ */
+/* #define SMPNG 1 */
+
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/mbuf.h>
@@ -178,6 +188,11 @@ struct wxmdvar {
bus_space_handle_t sh; /* bus space handle */
struct ifmedia ifm;
struct wx_softc * next;
+#ifdef SMPNG
+ struct mtx wxmtx;
+#else
+ int spl;
+#endif
};
#define wx_dev w.dev
#define wx_enaddr w.arpcom.ac_enaddr
@@ -187,6 +202,7 @@ struct wxmdvar {
#define wx_if w.arpcom.ac_if
#define wx_name w.name
+#define wx_mtx w.wxmtx
#define IOCTL_CMD_TYPE u_long
#define WXMALLOC(len) malloc(len, M_DEVBUF, M_NOWAIT)
@@ -197,6 +213,18 @@ struct wxmdvar {
#define TIMEOUT(sc, func, arg, time) (sc)->w.sch = timeout(func, arg, time)
#define UNTIMEOUT(f, arg, sc) untimeout(f, arg, (sc)->w.sch)
#define INLINE __inline
+#ifdef SMPNG
+#define WX_LOCK(_sc) mtx_enter(&(_sc)->wx_mtx, MTX_DEF)
+#define WX_UNLOCK(_sc) mtx_exit(&(_sc)->wx_mtx, MTX_DEF)
+#define WX_ILOCK(_sc) mtx_enter(&(_sc)->wx_mtx, MTX_DEF)
+#define WX_IUNLK(_sc) mtx_exit(&(_sc)->wx_mtx, MTX_DEF)
+#else
+#define WX_LOCK(_sc) _sc->w.spl = splimp()
+#define WX_UNLOCK(_sc) splx(_sc->w.spl)
+#define WX_ILOCK(_sc)
+#define WX_IUNLK(_sc)
+#endif
+
#define READ_CSR(sc, reg) \
bus_space_read_4((sc)->w.st, (sc)->w.sh, (reg))
@@ -260,6 +288,7 @@ struct wxmdvar {
bus_space_handle_t sh; /* bus space handle */
struct ifmedia ifm;
struct wx_softc * next;
+ int spl;
};
#define wx_dev w.dev
#define wx_enaddr w.arpcom.ac_enaddr
@@ -279,6 +308,10 @@ struct wxmdvar {
#define VTIMEOUT(sc, func, arg, time) timeout(func, arg, time)
#define UNTIMEOUT(f, arg, sc) untimeout(f, arg)
#define INLINE inline
+#define WX_LOCK(_sc) _sc->w.spl = splimp()
+#define WX_UNLOCK(_sc) splx(_sc->w.spl)
+#define WX_ILOCK(_sc)
+#define WX_IUNLK(_sc)
#define vm_offset_t vaddr_t
#define READ_CSR _read_csr
@@ -375,12 +408,8 @@ typedef struct wx_softc {
wxtd_t *tdescriptors; /* transmit descriptor ring */
u_int16_t tnxtfree; /* next free index (circular) */
u_int16_t tactive; /* # active */
- struct mtx wx_mtx;
} wx_softc_t;
-#define WX_LOCK(_sc) mtx_enter(&(_sc)->wx_mtx, MTX_DEF)
-#define WX_UNLOCK(_sc) mtx_exit(&(_sc)->wx_mtx, MTX_DEF)
-
/*
* We offset the the receive frame header by two bytes so that the actual
* payload is 32 bit aligned. On platforms that require strict structure