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.
This commit is contained in:
Bill Paul 1999-08-10 17:15:20 +00:00
parent f0ebbc2985
commit 08339b4fa4
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=49610
16 changed files with 414 additions and 225 deletions

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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,26 +1270,36 @@ 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);
}
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;
}
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_adj(m_new, sizeof(u_int64_t));
c->vr_mbuf = m_new;
c->vr_ptr->vr_status = VR_RXSTAT;
@ -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);

View File

@ -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.

View File

@ -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"

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

28
sys/modules/vr/Makefile Normal file
View File

@ -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>

View File

@ -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

View File

@ -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,26 +1270,36 @@ 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);
}
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;
}
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_adj(m_new, sizeof(u_int64_t));
c->vr_mbuf = m_new;
c->vr_ptr->vr_status = VR_RXSTAT;
@ -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);

View File

@ -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.