summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Paul <wpaul@FreeBSD.org>1999-08-10 17:15:20 +0000
committerBill Paul <wpaul@FreeBSD.org>1999-08-10 17:15:20 +0000
commit08339b4fa4529ed2e039bd30084000c225588988 (patch)
treec81d3f39a66c38de5c48dc518fee73c9fc89f4c4
parentf0ebbc29854d25a88f584c7333104c502df4a2d2 (diff)
downloadsrc-test2-08339b4fa4529ed2e039bd30084000c225588988.tar.gz
src-test2-08339b4fa4529ed2e039bd30084000c225588988.zip
Notes
-rw-r--r--sys/alpha/conf/GENERIC3
-rw-r--r--sys/alpha/conf/NOTES3
-rw-r--r--sys/boot/forth/loader.conf3
-rw-r--r--sys/dev/vr/if_vr.c279
-rw-r--r--sys/dev/vr/if_vrreg.h6
-rw-r--r--sys/modules/Makefile4
-rw-r--r--sys/modules/ax/Makefile4
-rw-r--r--sys/modules/mx/Makefile4
-rw-r--r--sys/modules/sf/Makefile4
-rw-r--r--sys/modules/sk/Makefile4
-rw-r--r--sys/modules/ti/Makefile4
-rw-r--r--sys/modules/tl/Makefile4
-rw-r--r--sys/modules/vr/Makefile28
-rw-r--r--sys/modules/xl/Makefile4
-rw-r--r--sys/pci/if_vr.c279
-rw-r--r--sys/pci/if_vrreg.h6
16 files changed, 414 insertions, 225 deletions
diff --git a/sys/alpha/conf/GENERIC b/sys/alpha/conf/GENERIC
index 931b0ae6a73c..64ebe5331478 100644
--- a/sys/alpha/conf/GENERIC
+++ b/sys/alpha/conf/GENERIC
@@ -11,7 +11,7 @@
# device lines is present in the ./LINT configuration file. If you are
# in doubt as to the purpose or necessity of a line, check first in LINT.
#
-# $Id: GENERIC,v 1.32 1999/07/25 04:32:47 wpaul Exp $
+# $Id: GENERIC,v 1.33 1999/08/08 19:28:56 phk Exp $
machine alpha
cpu EV4
@@ -120,6 +120,7 @@ device pn0
device rl0
device sf0
device tl0
+device vr0
device wb0
device xl0
diff --git a/sys/alpha/conf/NOTES b/sys/alpha/conf/NOTES
index 931b0ae6a73c..64ebe5331478 100644
--- a/sys/alpha/conf/NOTES
+++ b/sys/alpha/conf/NOTES
@@ -11,7 +11,7 @@
# device lines is present in the ./LINT configuration file. If you are
# in doubt as to the purpose or necessity of a line, check first in LINT.
#
-# $Id: GENERIC,v 1.32 1999/07/25 04:32:47 wpaul Exp $
+# $Id: GENERIC,v 1.33 1999/08/08 19:28:56 phk Exp $
machine alpha
cpu EV4
@@ -120,6 +120,7 @@ device pn0
device rl0
device sf0
device tl0
+device vr0
device wb0
device xl0
diff --git a/sys/boot/forth/loader.conf b/sys/boot/forth/loader.conf
index d2e8732c80d1..67ce79eca29e 100644
--- a/sys/boot/forth/loader.conf
+++ b/sys/boot/forth/loader.conf
@@ -6,7 +6,7 @@
#
# All arguments must be in double quotes.
#
-# $Id: loader.conf,v 1.7 1999/06/13 15:45:49 roger Exp $
+# $Id: loader.conf,v 1.8 1999/08/04 17:44:07 green Exp $
##############################################################
### Basic configuration options ############################
@@ -148,6 +148,7 @@ sf_load="NO" # Adaptec Duralink PCI (AIC-6915 "starfire")
sk_load="NO" # SysKonnect SK-984x series PCI gigabit ethernet
ti_load="NO" # Alteon Networks Tigon 1 and Tigon 2
tl_load="NO" # Texas Instruments TNETE100 ("ThunderLAN")
+vr_load="NO" # VIA Rhine I and Rhine II
xl_load="NO" # 3Com Etherlink XL (3c900, 3c905, 3c905B)
diff --git a/sys/dev/vr/if_vr.c b/sys/dev/vr/if_vr.c
index dfa293b9537c..6e78de4b6221 100644
--- a/sys/dev/vr/if_vr.c
+++ b/sys/dev/vr/if_vr.c
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: if_vr.c,v 1.12 1999/07/02 04:17:15 peter Exp $
+ * $Id: if_vr.c,v 1.13 1999/07/06 19:23:31 des Exp $
*/
/*
@@ -85,6 +85,9 @@
#include <machine/bus_pio.h>
#include <machine/bus_memio.h>
#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/bus.h>
+#include <sys/rman.h>
#include <pci/pcireg.h>
#include <pci/pcivar.h>
@@ -97,7 +100,7 @@
#ifndef lint
static const char rcsid[] =
- "$Id: if_vr.c,v 1.12 1999/07/02 04:17:15 peter Exp $";
+ "$Id: if_vr.c,v 1.13 1999/07/06 19:23:31 des Exp $";
#endif
/*
@@ -131,12 +134,13 @@ static struct vr_type vr_phys[] = {
{ 0, 0, "<MII-compliant physical interface>" }
};
-static unsigned long vr_count = 0;
-static const char *vr_probe __P((pcici_t, pcidi_t));
-static void vr_attach __P((pcici_t, int));
+static int vr_probe __P((device_t));
+static int vr_attach __P((device_t));
+static int vr_detach __P((device_t));
static int vr_newbuf __P((struct vr_softc *,
- struct vr_chain_onefrag *));
+ struct vr_chain_onefrag *,
+ struct mbuf *));
static int vr_encap __P((struct vr_softc *, struct vr_chain *,
struct mbuf * ));
@@ -150,7 +154,7 @@ static int vr_ioctl __P((struct ifnet *, u_long, caddr_t));
static void vr_init __P((void *));
static void vr_stop __P((struct vr_softc *));
static void vr_watchdog __P((struct ifnet *));
-static void vr_shutdown __P((int, void *));
+static void vr_shutdown __P((device_t));
static int vr_ifmedia_upd __P((struct ifnet *));
static void vr_ifmedia_sts __P((struct ifnet *, struct ifmediareq *));
@@ -172,6 +176,33 @@ static void vr_reset __P((struct vr_softc *));
static int vr_list_rx_init __P((struct vr_softc *));
static int vr_list_tx_init __P((struct vr_softc *));
+#ifdef VR_USEIOSPACE
+#define VR_RES SYS_RES_IOPORT
+#define VR_RID VR_PCI_LOIO
+#else
+#define VR_RES SYS_RES_MEMORY
+#define VR_RID VR_PCI_LOMEM
+#endif
+
+static device_method_t vr_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, vr_probe),
+ DEVMETHOD(device_attach, vr_attach),
+ DEVMETHOD(device_detach, vr_detach),
+ DEVMETHOD(device_shutdown, vr_shutdown),
+ { 0, 0 }
+};
+
+static driver_t vr_driver = {
+ "vr",
+ vr_methods,
+ sizeof(struct vr_softc)
+};
+
+static devclass_t vr_devclass;
+
+DRIVER_MODULE(vr, pci, vr_driver, vr_devclass, 0, 0);
+
#define VR_SETBIT(sc, reg, x) \
CSR_WRITE_1(sc, reg, \
CSR_READ_1(sc, reg) | x)
@@ -869,39 +900,33 @@ static void vr_reset(sc)
* Probe for a VIA Rhine chip. Check the PCI vendor and device
* IDs against our list and return a device name if we find a match.
*/
-static const char *
-vr_probe(config_id, device_id)
- pcici_t config_id;
- pcidi_t device_id;
+static int vr_probe(dev)
+ device_t dev;
{
struct vr_type *t;
t = vr_devs;
while(t->vr_name != NULL) {
- if ((device_id & 0xFFFF) == t->vr_vid &&
- ((device_id >> 16) & 0xFFFF) == t->vr_did) {
- return(t->vr_name);
+ if ((pci_get_vendor(dev) == t->vr_vid) &&
+ (pci_get_device(dev) == t->vr_did)) {
+ device_set_desc(dev, t->vr_name);
+ return(0);
}
t++;
}
- return(NULL);
+ return(ENXIO);
}
/*
* Attach the interface. Allocate softc structures, do ifmedia
* setup and ethernet/BPF attach.
*/
-static void
-vr_attach(config_id, unit)
- pcici_t config_id;
- int unit;
+static int vr_attach(dev)
+ device_t dev;
{
int s, i;
-#ifndef VR_USEIOSPACE
- vm_offset_t pbase, vbase;
-#endif
u_char eaddr[ETHER_ADDR_LEN];
u_int32_t command;
struct vr_softc *sc;
@@ -911,52 +936,50 @@ vr_attach(config_id, unit)
caddr_t roundptr;
struct vr_type *p;
u_int16_t phy_vid, phy_did, phy_sts;
+ int unit, error = 0, rid;
s = splimp();
- sc = malloc(sizeof(struct vr_softc), M_DEVBUF, M_NOWAIT);
- if (sc == NULL) {
- printf("vr%d: no memory for softc struct!\n", unit);
- return;
- }
- bzero(sc, sizeof(struct vr_softc));
+ sc = device_get_softc(dev);
+ unit = device_get_unit(dev);
+ bzero(sc, sizeof(struct vr_softc *));
/*
* Handle power management nonsense.
*/
- command = pci_conf_read(config_id, VR_PCI_CAPID) & 0x000000FF;
+ command = pci_read_config(dev, VR_PCI_CAPID, 4) & 0x000000FF;
if (command == 0x01) {
- command = pci_conf_read(config_id, VR_PCI_PWRMGMTCTRL);
+ command = pci_read_config(dev, VR_PCI_PWRMGMTCTRL, 4);
if (command & VR_PSTATE_MASK) {
u_int32_t iobase, membase, irq;
/* Save important PCI config data. */
- iobase = pci_conf_read(config_id, VR_PCI_LOIO);
- membase = pci_conf_read(config_id, VR_PCI_LOMEM);
- irq = pci_conf_read(config_id, VR_PCI_INTLINE);
+ iobase = pci_read_config(dev, VR_PCI_LOIO, 4);
+ membase = pci_read_config(dev, VR_PCI_LOMEM, 4);
+ irq = pci_read_config(dev, VR_PCI_INTLINE, 4);
/* Reset the power state. */
printf("vr%d: chip is in D%d power mode "
"-- setting to D0\n", unit, command & VR_PSTATE_MASK);
command &= 0xFFFFFFFC;
- pci_conf_write(config_id, VR_PCI_PWRMGMTCTRL, command);
+ pci_write_config(dev, VR_PCI_PWRMGMTCTRL, command, 4);
/* Restore PCI config data. */
- pci_conf_write(config_id, VR_PCI_LOIO, iobase);
- pci_conf_write(config_id, VR_PCI_LOMEM, membase);
- pci_conf_write(config_id, VR_PCI_INTLINE, irq);
+ pci_write_config(dev, VR_PCI_LOIO, iobase, 4);
+ pci_write_config(dev, VR_PCI_LOMEM, membase, 4);
+ pci_write_config(dev, VR_PCI_INTLINE, irq, 4);
}
}
/*
* Map control/status registers.
*/
- command = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
+ command = pci_read_config(dev, PCI_COMMAND_STATUS_REG, 4);
command |= (PCIM_CMD_PORTEN|PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN);
- pci_conf_write(config_id, PCI_COMMAND_STATUS_REG, command);
- command = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
+ pci_write_config(dev, PCI_COMMAND_STATUS_REG, command, 4);
+ command = pci_read_config(dev, PCI_COMMAND_STATUS_REG, 4);
#ifdef VR_USEIOSPACE
if (!(command & PCIM_CMD_PORTEN)) {
@@ -964,31 +987,45 @@ vr_attach(config_id, unit)
free(sc, M_DEVBUF);
goto fail;
}
-
- if (!pci_map_port(config_id, VR_PCI_LOIO,
- (pci_port_t *)(&sc->vr_bhandle))) {
- printf ("vr%d: couldn't map ports\n", unit);
- goto fail;
- }
- sc->vr_btag = I386_BUS_SPACE_IO;
#else
if (!(command & PCIM_CMD_MEMEN)) {
printf("vr%d: failed to enable memory mapping!\n", unit);
goto fail;
}
+#endif
- if (!pci_map_mem(config_id, VR_PCI_LOMEM, &vbase, &pbase)) {
- printf ("vr%d: couldn't map memory\n", unit);
+ rid = VR_RID;
+ sc->vr_res = bus_alloc_resource(dev, VR_RES, &rid,
+ 0, ~0, 1, RF_ACTIVE);
+
+ if (sc->vr_res == NULL) {
+ printf("vr%d: couldn't map ports/memory\n", unit);
+ error = ENXIO;
goto fail;
}
- sc->vr_bhandle = vbase;
- sc->vr_btag = I386_BUS_SPACE_MEM;
-#endif
+ sc->vr_btag = rman_get_bustag(sc->vr_res);
+ sc->vr_bhandle = rman_get_bushandle(sc->vr_res);
/* Allocate interrupt */
- if (!pci_map_int(config_id, vr_intr, sc, &net_imask)) {
+ rid = 0;
+ sc->vr_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
+ RF_SHAREABLE | RF_ACTIVE);
+
+ if (sc->vr_irq == NULL) {
printf("vr%d: couldn't map interrupt\n", unit);
+ bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
+ error = ENXIO;
+ goto fail;
+ }
+
+ error = bus_setup_intr(dev, sc->vr_irq, INTR_TYPE_NET,
+ vr_intr, sc, &sc->vr_intrhand);
+
+ if (error) {
+ bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq);
+ bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
+ printf("vr%d: couldn't set up irq\n", unit);
goto fail;
}
@@ -1018,9 +1055,12 @@ vr_attach(config_id, unit)
sc->vr_ldata_ptr = malloc(sizeof(struct vr_list_data) + 8,
M_DEVBUF, M_NOWAIT);
if (sc->vr_ldata_ptr == NULL) {
- free(sc, M_DEVBUF);
printf("vr%d: no memory for list buffers!\n", unit);
- return;
+ bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand);
+ bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq);
+ bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
+ error = ENXIO;
+ goto fail;
}
sc->vr_ldata = (struct vr_list_data *)sc->vr_ldata_ptr;
@@ -1089,6 +1129,10 @@ vr_attach(config_id, unit)
sc->vr_unit, sc->vr_pinfo->vr_name);
} else {
printf("vr%d: MII without any phy!\n", sc->vr_unit);
+ bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand);
+ bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq);
+ bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
+ error = ENXIO;
goto fail;
}
@@ -1098,9 +1142,15 @@ vr_attach(config_id, unit)
ifmedia_init(&sc->ifmedia, 0, vr_ifmedia_upd, vr_ifmedia_sts);
vr_getmode_mii(sc);
- vr_autoneg_mii(sc, VR_FLAG_FORCEDELAY, 1);
+ if (cold) {
+ vr_autoneg_mii(sc, VR_FLAG_FORCEDELAY, 1);
+ vr_stop(sc);
+ } else {
+ vr_init(sc);
+ vr_autoneg_mii(sc, VR_FLAG_SCHEDDELAY, 1);
+ }
+
media = sc->ifmedia.ifm_media;
- vr_stop(sc);
ifmedia_set(&sc->ifmedia, media);
@@ -1114,11 +1164,36 @@ vr_attach(config_id, unit)
bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
#endif
- at_shutdown(vr_shutdown, sc, SHUTDOWN_POST_SYNC);
-
fail:
splx(s);
- return;
+ return(error);
+}
+
+static int vr_detach(dev)
+ device_t dev;
+{
+ struct vr_softc *sc;
+ struct ifnet *ifp;
+ int s;
+
+ s = splimp();
+
+ sc = device_get_softc(dev);
+ ifp = &sc->arpcom.ac_if;
+
+ vr_stop(sc);
+ if_detach(ifp);
+
+ bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand);
+ bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq);
+ bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
+
+ free(sc->vr_ldata_ptr, M_DEVBUF);
+ ifmedia_removeall(&sc->ifmedia);
+
+ splx(s);
+
+ return(0);
}
/*
@@ -1168,7 +1243,7 @@ static int vr_list_rx_init(sc)
for (i = 0; i < VR_RX_LIST_CNT; i++) {
cd->vr_rx_chain[i].vr_ptr =
(struct vr_desc *)&ld->vr_rx_list[i];
- if (vr_newbuf(sc, &cd->vr_rx_chain[i]) == ENOBUFS)
+ if (vr_newbuf(sc, &cd->vr_rx_chain[i], NULL) == ENOBUFS)
return(ENOBUFS);
if (i == (VR_RX_LIST_CNT - 1)) {
cd->vr_rx_chain[i].vr_nextdesc =
@@ -1195,27 +1270,37 @@ static int vr_list_rx_init(sc)
* MCLBYTES is 2048, so we have to subtract one otherwise we'll
* overflow the field and make a mess.
*/
-static int vr_newbuf(sc, c)
+static int vr_newbuf(sc, c, m)
struct vr_softc *sc;
struct vr_chain_onefrag *c;
+ struct mbuf *m;
{
struct mbuf *m_new = NULL;
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL) {
- printf("vr%d: no memory for rx list -- packet dropped!\n",
- sc->vr_unit);
- return(ENOBUFS);
- }
+ if (m == NULL) {
+ MGETHDR(m_new, M_DONTWAIT, MT_DATA);
+ if (m_new == NULL) {
+ printf("vr%d: no memory for rx list "
+ "-- packet dropped!\n", sc->vr_unit);
+ return(ENOBUFS);
+ }
- MCLGET(m_new, M_DONTWAIT);
- if (!(m_new->m_flags & M_EXT)) {
- printf("vr%d: no memory for rx list -- packet dropped!\n",
- sc->vr_unit);
- m_freem(m_new);
- return(ENOBUFS);
+ MCLGET(m_new, M_DONTWAIT);
+ if (!(m_new->m_flags & M_EXT)) {
+ printf("vr%d: no memory for rx list "
+ "-- packet dropped!\n", sc->vr_unit);
+ 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->vr_mbuf = m_new;
c->vr_ptr->vr_status = VR_RXSTAT;
c->vr_ptr->vr_data = vtophys(mtod(m_new, caddr_t));
@@ -1242,8 +1327,11 @@ static void vr_rxeof(sc)
while(!((rxstat = sc->vr_cdata.vr_rx_head->vr_ptr->vr_status) &
VR_RXSTAT_OWN)) {
+ struct mbuf *m0 = NULL;
+
cur_rx = sc->vr_cdata.vr_rx_head;
sc->vr_cdata.vr_rx_head = cur_rx->vr_nextdesc;
+ m = cur_rx->vr_mbuf;
/*
* If an error occurs, update stats, clear the
@@ -1280,13 +1368,11 @@ static void vr_rxeof(sc)
printf("unknown rx error\n");
break;
}
- cur_rx->vr_ptr->vr_status = VR_RXSTAT;
- cur_rx->vr_ptr->vr_ctl = VR_RXCTL|VR_RXLEN;
+ vr_newbuf(sc, cur_rx, m);
continue;
}
/* No errors; receive the packet. */
- m = cur_rx->vr_mbuf;
total_len = VR_RXBYTES(cur_rx->vr_ptr->vr_status);
/*
@@ -1298,24 +1384,19 @@ static void vr_rxeof(sc)
*/
total_len -= ETHER_CRC_LEN;
- /*
- * 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 (vr_newbuf(sc, cur_rx) == ENOBUFS) {
+ m0 = m_devget(mtod(m, char *) - ETHER_ALIGN,
+ total_len + ETHER_ALIGN, 0, ifp, NULL);
+ vr_newbuf(sc, cur_rx, m);
+ if (m0 == NULL) {
ifp->if_ierrors++;
- cur_rx->vr_ptr->vr_status = VR_RXSTAT;
- cur_rx->vr_ptr->vr_ctl = VR_RXCTL|VR_RXLEN;
continue;
}
+ m_adj(m0, ETHER_ALIGN);
+ m = m0;
ifp->if_ipackets++;
eh = mtod(m, struct ether_header *);
- m->m_pkthdr.rcvif = ifp;
- m->m_pkthdr.len = m->m_len = total_len;
+
#if NBPF > 0
/*
* Handle BPF listeners. Let the BPF user see the packet, but
@@ -1868,6 +1949,8 @@ static void vr_watchdog(ifp)
if (sc->vr_autoneg) {
vr_autoneg_mii(sc, VR_FLAG_DELAYTIMEO, 1);
+ if (!(ifp->if_flags & IFF_UP))
+ vr_stop(sc);
return;
}
@@ -1941,22 +2024,14 @@ static void vr_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 vr_shutdown(howto, arg)
- int howto;
- void *arg;
+static void vr_shutdown(dev)
+ device_t dev;
{
- struct vr_softc *sc = (struct vr_softc *)arg;
+ struct vr_softc *sc;
+
+ sc = device_get_softc(dev);
vr_stop(sc);
return;
}
-
-static struct pci_device vr_device = {
- "vr",
- vr_probe,
- vr_attach,
- &vr_count,
- NULL
-};
-COMPAT_PCI_DRIVER(vr, vr_device);
diff --git a/sys/dev/vr/if_vrreg.h b/sys/dev/vr/if_vrreg.h
index 2859086a6788..e1e4ae6d1cfc 100644
--- a/sys/dev/vr/if_vrreg.h
+++ b/sys/dev/vr/if_vrreg.h
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: if_vrreg.h,v 1.3 1999/02/23 15:38:24 wpaul Exp $
+ * $Id: if_vrreg.h,v 1.4 1999/05/06 15:32:50 wpaul Exp $
*/
/*
@@ -402,6 +402,9 @@ struct vr_softc {
struct ifmedia ifmedia; /* media info */
bus_space_handle_t vr_bhandle; /* bus space handle */
bus_space_tag_t vr_btag; /* bus space tag */
+ struct resource *vr_res;
+ struct resource *vr_irq;
+ void *vr_intrhand;
struct vr_type *vr_info; /* Rhine adapter info */
struct vr_type *vr_pinfo; /* phy info */
u_int8_t vr_unit; /* interface number */
@@ -433,6 +436,7 @@ struct vr_softc {
bus_space_read_1(sc->vr_btag, sc->vr_bhandle, reg)
#define VR_TIMEOUT 1000
+#define ETHER_ALIGN 2
/*
* General constants that are fun to know.
diff --git a/sys/modules/Makefile b/sys/modules/Makefile
index 031d507e59cc..431bacb5d4c7 100644
--- a/sys/modules/Makefile
+++ b/sys/modules/Makefile
@@ -1,10 +1,10 @@
-# $Id: Makefile,v 1.68 1999/07/25 04:32:37 wpaul Exp $
+# $Id: Makefile,v 1.69 1999/07/28 02:21:55 wpaul Exp $
# XXX present but broken: atapi ip_mroute_mod joy pcic
SUBDIR= ax ccd cd9660 coda fdesc fxp if_disc if_ppp if_sl if_tun ipfw \
kernfs mfs msdos mx nfs ntfs nullfs pn portal procfs sf sk ti \
- tl umapfs union vn xl
+ tl umapfs union vn vr xl
# XXX some of these can move to the general case when de-i386'ed
.if ${MACHINE_ARCH} == "i386"
diff --git a/sys/modules/ax/Makefile b/sys/modules/ax/Makefile
index 0f55ead4f28e..0d320364369b 100644
--- a/sys/modules/ax/Makefile
+++ b/sys/modules/ax/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.1 1999/07/23 05:48:01 wpaul Exp $
+# $Id: Makefile,v 1.1 1999/07/24 20:55:04 wpaul Exp $
S = ${.CURDIR}/../..
.PATH: $S/pci
@@ -8,7 +8,7 @@ CLEANFILES += ax.h bpf.h opt_bdg.h device_if.h bus_if.h pci_if.h
CFLAGS += ${DEBUG_FLAGS}
ax.h:
- echo "#define NFXP 1" > ax.h
+ echo "#define NAX 1" > ax.h
bpf.h:
echo "#define NBPF 1" > bpf.h
diff --git a/sys/modules/mx/Makefile b/sys/modules/mx/Makefile
index d1e2261a7e37..ae4ea4f67c77 100644
--- a/sys/modules/mx/Makefile
+++ b/sys/modules/mx/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.1 1999/07/23 05:48:01 wpaul Exp $
+# $Id: Makefile,v 1.1 1999/07/24 20:55:05 wpaul Exp $
S = ${.CURDIR}/../..
.PATH: $S/pci
@@ -8,7 +8,7 @@ CLEANFILES += mx.h bpf.h opt_bdg.h device_if.h bus_if.h pci_if.h
CFLAGS += ${DEBUG_FLAGS}
mx.h:
- echo "#define NFXP 1" > mx.h
+ echo "#define NMX 1" > mx.h
bpf.h:
echo "#define NBPF 1" > bpf.h
diff --git a/sys/modules/sf/Makefile b/sys/modules/sf/Makefile
index aa3df4c2e614..d2de96eb0f67 100644
--- a/sys/modules/sf/Makefile
+++ b/sys/modules/sf/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.1 1999/07/23 05:48:01 wpaul Exp $
+# $Id: Makefile,v 1.1 1999/07/25 04:32:38 wpaul Exp $
S = ${.CURDIR}/../..
.PATH: $S/pci
@@ -8,7 +8,7 @@ CLEANFILES += sf.h bpf.h opt_bdg.h device_if.h bus_if.h pci_if.h
CFLAGS += ${DEBUG_FLAGS}
sf.h:
- echo "#define NFXP 1" > sf.h
+ echo "#define NSF 1" > sf.h
bpf.h:
echo "#define NBPF 1" > bpf.h
diff --git a/sys/modules/sk/Makefile b/sys/modules/sk/Makefile
index 9c3b9ebfb50c..3aefa89cd13c 100644
--- a/sys/modules/sk/Makefile
+++ b/sys/modules/sk/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.3 1999/07/06 19:23:01 des Exp $
+# $Id: Makefile,v 1.1 1999/07/23 05:47:56 wpaul Exp $
S = ${.CURDIR}/../..
.PATH: $S/pci
@@ -8,7 +8,7 @@ CLEANFILES += sk.h bpf.h opt_bdg.h device_if.h bus_if.h pci_if.h
CFLAGS += ${DEBUG_FLAGS}
sk.h:
- echo "#define NFXP 1" > sk.h
+ echo "#define NSK 1" > sk.h
bpf.h:
echo "#define NBPF 1" > bpf.h
diff --git a/sys/modules/ti/Makefile b/sys/modules/ti/Makefile
index b3d2064fcff6..9fd0b6b0fc37 100644
--- a/sys/modules/ti/Makefile
+++ b/sys/modules/ti/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.3 1999/07/06 19:23:01 des Exp $
+# $Id: Makefile,v 1.1 1999/07/23 05:47:58 wpaul Exp $
S = ${.CURDIR}/../..
.PATH: $S/pci
@@ -8,7 +8,7 @@ CLEANFILES += ti.h bpf.h opt_bdg.h vlan.h device_if.h bus_if.h pci_if.h
CFLAGS += ${DEBUG_FLAGS}
ti.h:
- echo "#define NFXP 1" > ti.h
+ echo "#define NTI 1" > ti.h
bpf.h:
echo "#define NBPF 1" > bpf.h
diff --git a/sys/modules/tl/Makefile b/sys/modules/tl/Makefile
index 515026854aeb..d4108d1cac51 100644
--- a/sys/modules/tl/Makefile
+++ b/sys/modules/tl/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.3 1999/07/06 19:23:01 des Exp $
+# $Id: Makefile,v 1.1 1999/07/23 05:47:59 wpaul Exp $
S = ${.CURDIR}/../..
.PATH: $S/pci
@@ -8,7 +8,7 @@ CLEANFILES += tl.h bpf.h opt_bdg.h device_if.h bus_if.h pci_if.h
CFLAGS += ${DEBUG_FLAGS}
tl.h:
- echo "#define NFXP 1" > tl.h
+ echo "#define NTL 1" > tl.h
bpf.h:
echo "#define NBPF 1" > bpf.h
diff --git a/sys/modules/vr/Makefile b/sys/modules/vr/Makefile
new file mode 100644
index 000000000000..468419ae9d65
--- /dev/null
+++ b/sys/modules/vr/Makefile
@@ -0,0 +1,28 @@
+# $Id: Makefile,v 1.1 1999/07/23 05:48:01 wpaul Exp $
+
+S = ${.CURDIR}/../..
+.PATH: $S/pci
+KMOD = vr
+SRCS = if_vr.c vr.h bpf.h opt_bdg.h device_if.h bus_if.h pci_if.h
+CLEANFILES += vr.h bpf.h opt_bdg.h device_if.h bus_if.h pci_if.h
+CFLAGS += ${DEBUG_FLAGS}
+
+vr.h:
+ echo "#define NVR 1" > vr.h
+
+bpf.h:
+ echo "#define NBPF 1" > bpf.h
+
+opt_bdg.h:
+ touch opt_bdg.h
+
+device_if.h: $S/kern/makedevops.pl $S/kern/device_if.m
+ perl $S/kern/makedevops.pl -h $S/kern/device_if.m
+
+bus_if.h: $S/kern/makedevops.pl $S/kern/bus_if.m
+ perl $S/kern/makedevops.pl -h $S/kern/bus_if.m
+
+pci_if.h: $S/kern/makedevops.pl $S/pci/pci_if.m
+ perl $S/kern/makedevops.pl -h $S/pci/pci_if.m
+
+.include <bsd.kmod.mk>
diff --git a/sys/modules/xl/Makefile b/sys/modules/xl/Makefile
index d0658493e299..544cc4814948 100644
--- a/sys/modules/xl/Makefile
+++ b/sys/modules/xl/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.3 1999/07/06 19:23:01 des Exp $
+# $Id: Makefile,v 1.1 1999/07/23 05:48:01 wpaul Exp $
S = ${.CURDIR}/../..
.PATH: $S/pci
@@ -8,7 +8,7 @@ CLEANFILES += xl.h bpf.h opt_bdg.h device_if.h bus_if.h pci_if.h
CFLAGS += ${DEBUG_FLAGS}
xl.h:
- echo "#define NFXP 1" > xl.h
+ echo "#define NXL 1" > xl.h
bpf.h:
echo "#define NBPF 1" > bpf.h
diff --git a/sys/pci/if_vr.c b/sys/pci/if_vr.c
index dfa293b9537c..6e78de4b6221 100644
--- a/sys/pci/if_vr.c
+++ b/sys/pci/if_vr.c
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: if_vr.c,v 1.12 1999/07/02 04:17:15 peter Exp $
+ * $Id: if_vr.c,v 1.13 1999/07/06 19:23:31 des Exp $
*/
/*
@@ -85,6 +85,9 @@
#include <machine/bus_pio.h>
#include <machine/bus_memio.h>
#include <machine/bus.h>
+#include <machine/resource.h>
+#include <sys/bus.h>
+#include <sys/rman.h>
#include <pci/pcireg.h>
#include <pci/pcivar.h>
@@ -97,7 +100,7 @@
#ifndef lint
static const char rcsid[] =
- "$Id: if_vr.c,v 1.12 1999/07/02 04:17:15 peter Exp $";
+ "$Id: if_vr.c,v 1.13 1999/07/06 19:23:31 des Exp $";
#endif
/*
@@ -131,12 +134,13 @@ static struct vr_type vr_phys[] = {
{ 0, 0, "<MII-compliant physical interface>" }
};
-static unsigned long vr_count = 0;
-static const char *vr_probe __P((pcici_t, pcidi_t));
-static void vr_attach __P((pcici_t, int));
+static int vr_probe __P((device_t));
+static int vr_attach __P((device_t));
+static int vr_detach __P((device_t));
static int vr_newbuf __P((struct vr_softc *,
- struct vr_chain_onefrag *));
+ struct vr_chain_onefrag *,
+ struct mbuf *));
static int vr_encap __P((struct vr_softc *, struct vr_chain *,
struct mbuf * ));
@@ -150,7 +154,7 @@ static int vr_ioctl __P((struct ifnet *, u_long, caddr_t));
static void vr_init __P((void *));
static void vr_stop __P((struct vr_softc *));
static void vr_watchdog __P((struct ifnet *));
-static void vr_shutdown __P((int, void *));
+static void vr_shutdown __P((device_t));
static int vr_ifmedia_upd __P((struct ifnet *));
static void vr_ifmedia_sts __P((struct ifnet *, struct ifmediareq *));
@@ -172,6 +176,33 @@ static void vr_reset __P((struct vr_softc *));
static int vr_list_rx_init __P((struct vr_softc *));
static int vr_list_tx_init __P((struct vr_softc *));
+#ifdef VR_USEIOSPACE
+#define VR_RES SYS_RES_IOPORT
+#define VR_RID VR_PCI_LOIO
+#else
+#define VR_RES SYS_RES_MEMORY
+#define VR_RID VR_PCI_LOMEM
+#endif
+
+static device_method_t vr_methods[] = {
+ /* Device interface */
+ DEVMETHOD(device_probe, vr_probe),
+ DEVMETHOD(device_attach, vr_attach),
+ DEVMETHOD(device_detach, vr_detach),
+ DEVMETHOD(device_shutdown, vr_shutdown),
+ { 0, 0 }
+};
+
+static driver_t vr_driver = {
+ "vr",
+ vr_methods,
+ sizeof(struct vr_softc)
+};
+
+static devclass_t vr_devclass;
+
+DRIVER_MODULE(vr, pci, vr_driver, vr_devclass, 0, 0);
+
#define VR_SETBIT(sc, reg, x) \
CSR_WRITE_1(sc, reg, \
CSR_READ_1(sc, reg) | x)
@@ -869,39 +900,33 @@ static void vr_reset(sc)
* Probe for a VIA Rhine chip. Check the PCI vendor and device
* IDs against our list and return a device name if we find a match.
*/
-static const char *
-vr_probe(config_id, device_id)
- pcici_t config_id;
- pcidi_t device_id;
+static int vr_probe(dev)
+ device_t dev;
{
struct vr_type *t;
t = vr_devs;
while(t->vr_name != NULL) {
- if ((device_id & 0xFFFF) == t->vr_vid &&
- ((device_id >> 16) & 0xFFFF) == t->vr_did) {
- return(t->vr_name);
+ if ((pci_get_vendor(dev) == t->vr_vid) &&
+ (pci_get_device(dev) == t->vr_did)) {
+ device_set_desc(dev, t->vr_name);
+ return(0);
}
t++;
}
- return(NULL);
+ return(ENXIO);
}
/*
* Attach the interface. Allocate softc structures, do ifmedia
* setup and ethernet/BPF attach.
*/
-static void
-vr_attach(config_id, unit)
- pcici_t config_id;
- int unit;
+static int vr_attach(dev)
+ device_t dev;
{
int s, i;
-#ifndef VR_USEIOSPACE
- vm_offset_t pbase, vbase;
-#endif
u_char eaddr[ETHER_ADDR_LEN];
u_int32_t command;
struct vr_softc *sc;
@@ -911,52 +936,50 @@ vr_attach(config_id, unit)
caddr_t roundptr;
struct vr_type *p;
u_int16_t phy_vid, phy_did, phy_sts;
+ int unit, error = 0, rid;
s = splimp();
- sc = malloc(sizeof(struct vr_softc), M_DEVBUF, M_NOWAIT);
- if (sc == NULL) {
- printf("vr%d: no memory for softc struct!\n", unit);
- return;
- }
- bzero(sc, sizeof(struct vr_softc));
+ sc = device_get_softc(dev);
+ unit = device_get_unit(dev);
+ bzero(sc, sizeof(struct vr_softc *));
/*
* Handle power management nonsense.
*/
- command = pci_conf_read(config_id, VR_PCI_CAPID) & 0x000000FF;
+ command = pci_read_config(dev, VR_PCI_CAPID, 4) & 0x000000FF;
if (command == 0x01) {
- command = pci_conf_read(config_id, VR_PCI_PWRMGMTCTRL);
+ command = pci_read_config(dev, VR_PCI_PWRMGMTCTRL, 4);
if (command & VR_PSTATE_MASK) {
u_int32_t iobase, membase, irq;
/* Save important PCI config data. */
- iobase = pci_conf_read(config_id, VR_PCI_LOIO);
- membase = pci_conf_read(config_id, VR_PCI_LOMEM);
- irq = pci_conf_read(config_id, VR_PCI_INTLINE);
+ iobase = pci_read_config(dev, VR_PCI_LOIO, 4);
+ membase = pci_read_config(dev, VR_PCI_LOMEM, 4);
+ irq = pci_read_config(dev, VR_PCI_INTLINE, 4);
/* Reset the power state. */
printf("vr%d: chip is in D%d power mode "
"-- setting to D0\n", unit, command & VR_PSTATE_MASK);
command &= 0xFFFFFFFC;
- pci_conf_write(config_id, VR_PCI_PWRMGMTCTRL, command);
+ pci_write_config(dev, VR_PCI_PWRMGMTCTRL, command, 4);
/* Restore PCI config data. */
- pci_conf_write(config_id, VR_PCI_LOIO, iobase);
- pci_conf_write(config_id, VR_PCI_LOMEM, membase);
- pci_conf_write(config_id, VR_PCI_INTLINE, irq);
+ pci_write_config(dev, VR_PCI_LOIO, iobase, 4);
+ pci_write_config(dev, VR_PCI_LOMEM, membase, 4);
+ pci_write_config(dev, VR_PCI_INTLINE, irq, 4);
}
}
/*
* Map control/status registers.
*/
- command = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
+ command = pci_read_config(dev, PCI_COMMAND_STATUS_REG, 4);
command |= (PCIM_CMD_PORTEN|PCIM_CMD_MEMEN|PCIM_CMD_BUSMASTEREN);
- pci_conf_write(config_id, PCI_COMMAND_STATUS_REG, command);
- command = pci_conf_read(config_id, PCI_COMMAND_STATUS_REG);
+ pci_write_config(dev, PCI_COMMAND_STATUS_REG, command, 4);
+ command = pci_read_config(dev, PCI_COMMAND_STATUS_REG, 4);
#ifdef VR_USEIOSPACE
if (!(command & PCIM_CMD_PORTEN)) {
@@ -964,31 +987,45 @@ vr_attach(config_id, unit)
free(sc, M_DEVBUF);
goto fail;
}
-
- if (!pci_map_port(config_id, VR_PCI_LOIO,
- (pci_port_t *)(&sc->vr_bhandle))) {
- printf ("vr%d: couldn't map ports\n", unit);
- goto fail;
- }
- sc->vr_btag = I386_BUS_SPACE_IO;
#else
if (!(command & PCIM_CMD_MEMEN)) {
printf("vr%d: failed to enable memory mapping!\n", unit);
goto fail;
}
+#endif
- if (!pci_map_mem(config_id, VR_PCI_LOMEM, &vbase, &pbase)) {
- printf ("vr%d: couldn't map memory\n", unit);
+ rid = VR_RID;
+ sc->vr_res = bus_alloc_resource(dev, VR_RES, &rid,
+ 0, ~0, 1, RF_ACTIVE);
+
+ if (sc->vr_res == NULL) {
+ printf("vr%d: couldn't map ports/memory\n", unit);
+ error = ENXIO;
goto fail;
}
- sc->vr_bhandle = vbase;
- sc->vr_btag = I386_BUS_SPACE_MEM;
-#endif
+ sc->vr_btag = rman_get_bustag(sc->vr_res);
+ sc->vr_bhandle = rman_get_bushandle(sc->vr_res);
/* Allocate interrupt */
- if (!pci_map_int(config_id, vr_intr, sc, &net_imask)) {
+ rid = 0;
+ sc->vr_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
+ RF_SHAREABLE | RF_ACTIVE);
+
+ if (sc->vr_irq == NULL) {
printf("vr%d: couldn't map interrupt\n", unit);
+ bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
+ error = ENXIO;
+ goto fail;
+ }
+
+ error = bus_setup_intr(dev, sc->vr_irq, INTR_TYPE_NET,
+ vr_intr, sc, &sc->vr_intrhand);
+
+ if (error) {
+ bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq);
+ bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
+ printf("vr%d: couldn't set up irq\n", unit);
goto fail;
}
@@ -1018,9 +1055,12 @@ vr_attach(config_id, unit)
sc->vr_ldata_ptr = malloc(sizeof(struct vr_list_data) + 8,
M_DEVBUF, M_NOWAIT);
if (sc->vr_ldata_ptr == NULL) {
- free(sc, M_DEVBUF);
printf("vr%d: no memory for list buffers!\n", unit);
- return;
+ bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand);
+ bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq);
+ bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
+ error = ENXIO;
+ goto fail;
}
sc->vr_ldata = (struct vr_list_data *)sc->vr_ldata_ptr;
@@ -1089,6 +1129,10 @@ vr_attach(config_id, unit)
sc->vr_unit, sc->vr_pinfo->vr_name);
} else {
printf("vr%d: MII without any phy!\n", sc->vr_unit);
+ bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand);
+ bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq);
+ bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
+ error = ENXIO;
goto fail;
}
@@ -1098,9 +1142,15 @@ vr_attach(config_id, unit)
ifmedia_init(&sc->ifmedia, 0, vr_ifmedia_upd, vr_ifmedia_sts);
vr_getmode_mii(sc);
- vr_autoneg_mii(sc, VR_FLAG_FORCEDELAY, 1);
+ if (cold) {
+ vr_autoneg_mii(sc, VR_FLAG_FORCEDELAY, 1);
+ vr_stop(sc);
+ } else {
+ vr_init(sc);
+ vr_autoneg_mii(sc, VR_FLAG_SCHEDDELAY, 1);
+ }
+
media = sc->ifmedia.ifm_media;
- vr_stop(sc);
ifmedia_set(&sc->ifmedia, media);
@@ -1114,11 +1164,36 @@ vr_attach(config_id, unit)
bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header));
#endif
- at_shutdown(vr_shutdown, sc, SHUTDOWN_POST_SYNC);
-
fail:
splx(s);
- return;
+ return(error);
+}
+
+static int vr_detach(dev)
+ device_t dev;
+{
+ struct vr_softc *sc;
+ struct ifnet *ifp;
+ int s;
+
+ s = splimp();
+
+ sc = device_get_softc(dev);
+ ifp = &sc->arpcom.ac_if;
+
+ vr_stop(sc);
+ if_detach(ifp);
+
+ bus_teardown_intr(dev, sc->vr_irq, sc->vr_intrhand);
+ bus_release_resource(dev, SYS_RES_IRQ, 0, sc->vr_irq);
+ bus_release_resource(dev, VR_RES, VR_RID, sc->vr_res);
+
+ free(sc->vr_ldata_ptr, M_DEVBUF);
+ ifmedia_removeall(&sc->ifmedia);
+
+ splx(s);
+
+ return(0);
}
/*
@@ -1168,7 +1243,7 @@ static int vr_list_rx_init(sc)
for (i = 0; i < VR_RX_LIST_CNT; i++) {
cd->vr_rx_chain[i].vr_ptr =
(struct vr_desc *)&ld->vr_rx_list[i];
- if (vr_newbuf(sc, &cd->vr_rx_chain[i]) == ENOBUFS)
+ if (vr_newbuf(sc, &cd->vr_rx_chain[i], NULL) == ENOBUFS)
return(ENOBUFS);
if (i == (VR_RX_LIST_CNT - 1)) {
cd->vr_rx_chain[i].vr_nextdesc =
@@ -1195,27 +1270,37 @@ static int vr_list_rx_init(sc)
* MCLBYTES is 2048, so we have to subtract one otherwise we'll
* overflow the field and make a mess.
*/
-static int vr_newbuf(sc, c)
+static int vr_newbuf(sc, c, m)
struct vr_softc *sc;
struct vr_chain_onefrag *c;
+ struct mbuf *m;
{
struct mbuf *m_new = NULL;
- MGETHDR(m_new, M_DONTWAIT, MT_DATA);
- if (m_new == NULL) {
- printf("vr%d: no memory for rx list -- packet dropped!\n",
- sc->vr_unit);
- return(ENOBUFS);
- }
+ if (m == NULL) {
+ MGETHDR(m_new, M_DONTWAIT, MT_DATA);
+ if (m_new == NULL) {
+ printf("vr%d: no memory for rx list "
+ "-- packet dropped!\n", sc->vr_unit);
+ return(ENOBUFS);
+ }
- MCLGET(m_new, M_DONTWAIT);
- if (!(m_new->m_flags & M_EXT)) {
- printf("vr%d: no memory for rx list -- packet dropped!\n",
- sc->vr_unit);
- m_freem(m_new);
- return(ENOBUFS);
+ MCLGET(m_new, M_DONTWAIT);
+ if (!(m_new->m_flags & M_EXT)) {
+ printf("vr%d: no memory for rx list "
+ "-- packet dropped!\n", sc->vr_unit);
+ 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->vr_mbuf = m_new;
c->vr_ptr->vr_status = VR_RXSTAT;
c->vr_ptr->vr_data = vtophys(mtod(m_new, caddr_t));
@@ -1242,8 +1327,11 @@ static void vr_rxeof(sc)
while(!((rxstat = sc->vr_cdata.vr_rx_head->vr_ptr->vr_status) &
VR_RXSTAT_OWN)) {
+ struct mbuf *m0 = NULL;
+
cur_rx = sc->vr_cdata.vr_rx_head;
sc->vr_cdata.vr_rx_head = cur_rx->vr_nextdesc;
+ m = cur_rx->vr_mbuf;
/*
* If an error occurs, update stats, clear the
@@ -1280,13 +1368,11 @@ static void vr_rxeof(sc)
printf("unknown rx error\n");
break;
}
- cur_rx->vr_ptr->vr_status = VR_RXSTAT;
- cur_rx->vr_ptr->vr_ctl = VR_RXCTL|VR_RXLEN;
+ vr_newbuf(sc, cur_rx, m);
continue;
}
/* No errors; receive the packet. */
- m = cur_rx->vr_mbuf;
total_len = VR_RXBYTES(cur_rx->vr_ptr->vr_status);
/*
@@ -1298,24 +1384,19 @@ static void vr_rxeof(sc)
*/
total_len -= ETHER_CRC_LEN;
- /*
- * 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 (vr_newbuf(sc, cur_rx) == ENOBUFS) {
+ m0 = m_devget(mtod(m, char *) - ETHER_ALIGN,
+ total_len + ETHER_ALIGN, 0, ifp, NULL);
+ vr_newbuf(sc, cur_rx, m);
+ if (m0 == NULL) {
ifp->if_ierrors++;
- cur_rx->vr_ptr->vr_status = VR_RXSTAT;
- cur_rx->vr_ptr->vr_ctl = VR_RXCTL|VR_RXLEN;
continue;
}
+ m_adj(m0, ETHER_ALIGN);
+ m = m0;
ifp->if_ipackets++;
eh = mtod(m, struct ether_header *);
- m->m_pkthdr.rcvif = ifp;
- m->m_pkthdr.len = m->m_len = total_len;
+
#if NBPF > 0
/*
* Handle BPF listeners. Let the BPF user see the packet, but
@@ -1868,6 +1949,8 @@ static void vr_watchdog(ifp)
if (sc->vr_autoneg) {
vr_autoneg_mii(sc, VR_FLAG_DELAYTIMEO, 1);
+ if (!(ifp->if_flags & IFF_UP))
+ vr_stop(sc);
return;
}
@@ -1941,22 +2024,14 @@ static void vr_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 vr_shutdown(howto, arg)
- int howto;
- void *arg;
+static void vr_shutdown(dev)
+ device_t dev;
{
- struct vr_softc *sc = (struct vr_softc *)arg;
+ struct vr_softc *sc;
+
+ sc = device_get_softc(dev);
vr_stop(sc);
return;
}
-
-static struct pci_device vr_device = {
- "vr",
- vr_probe,
- vr_attach,
- &vr_count,
- NULL
-};
-COMPAT_PCI_DRIVER(vr, vr_device);
diff --git a/sys/pci/if_vrreg.h b/sys/pci/if_vrreg.h
index 2859086a6788..e1e4ae6d1cfc 100644
--- a/sys/pci/if_vrreg.h
+++ b/sys/pci/if_vrreg.h
@@ -29,7 +29,7 @@
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*
- * $Id: if_vrreg.h,v 1.3 1999/02/23 15:38:24 wpaul Exp $
+ * $Id: if_vrreg.h,v 1.4 1999/05/06 15:32:50 wpaul Exp $
*/
/*
@@ -402,6 +402,9 @@ struct vr_softc {
struct ifmedia ifmedia; /* media info */
bus_space_handle_t vr_bhandle; /* bus space handle */
bus_space_tag_t vr_btag; /* bus space tag */
+ struct resource *vr_res;
+ struct resource *vr_irq;
+ void *vr_intrhand;
struct vr_type *vr_info; /* Rhine adapter info */
struct vr_type *vr_pinfo; /* phy info */
u_int8_t vr_unit; /* interface number */
@@ -433,6 +436,7 @@ struct vr_softc {
bus_space_read_1(sc->vr_btag, sc->vr_bhandle, reg)
#define VR_TIMEOUT 1000
+#define ETHER_ALIGN 2
/*
* General constants that are fun to know.