summaryrefslogtreecommitdiffstats
path: root/sys/dev/vr
diff options
context:
space:
mode:
authorwpaul <wpaul@FreeBSD.org>1999-08-10 17:15:20 +0000
committerwpaul <wpaul@FreeBSD.org>1999-08-10 17:15:20 +0000
commit77daf56af9591a9c07c989b51b7511c07d8f3e47 (patch)
tree74c38b6d7a531b029089c457f5bcf3955ea31a5f /sys/dev/vr
parent6b0342e396ad0a1933d3d62ee656723ffb36fb18 (diff)
downloadFreeBSD-src-77daf56af9591a9c07c989b51b7511c07d8f3e47.zip
FreeBSD-src-77daf56af9591a9c07c989b51b7511c07d8f3e47.tar.gz
Convert the VIA Rhine driver to newbus and set it up to be compiled as
a module. Also modified the code to work on FreeBSD/alpha and added device vr0 to the alpha GENERIC config. While I was in the neighborhood, I noticed that I was still using #define NFPX 1 in all of the Makefiles that I'd copied from the fxp module. I don't really use #define Nfoo X so it didn't matter, but I decided to customize this correctly anyway.
Diffstat (limited to 'sys/dev/vr')
-rw-r--r--sys/dev/vr/if_vr.c279
-rw-r--r--sys/dev/vr/if_vrreg.h6
2 files changed, 182 insertions, 103 deletions
diff --git a/sys/dev/vr/if_vr.c b/sys/dev/vr/if_vr.c
index dfa293b..6e78de4 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 2859086..e1e4ae6 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.
OpenPOWER on IntegriCloud