From 6a2207962296b0bb1511d70a21840c049ea9d2de Mon Sep 17 00:00:00 2001 From: wpaul Date: Tue, 10 Aug 1999 21:09:12 +0000 Subject: Convert the Winbond driver to newbus and have it compiled as a module. --- sys/boot/forth/loader.conf | 3 +- sys/modules/Makefile | 4 +- sys/modules/wb/Makefile | 28 ++++++ sys/pci/if_wb.c | 222 ++++++++++++++++++++++++++++----------------- sys/pci/if_wbreg.h | 7 +- 5 files changed, 178 insertions(+), 86 deletions(-) create mode 100644 sys/modules/wb/Makefile diff --git a/sys/boot/forth/loader.conf b/sys/boot/forth/loader.conf index 67ce79e..8bc0ec5 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.8 1999/08/04 17:44:07 green Exp $ +# $Id: loader.conf,v 1.9 1999/08/10 17:15:20 wpaul Exp $ ############################################################## ### Basic configuration options ############################ @@ -149,6 +149,7 @@ 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 +wb_load="NO" # Winbond W89C840F xl_load="NO" # 3Com Etherlink XL (3c900, 3c905, 3c905B) diff --git a/sys/modules/Makefile b/sys/modules/Makefile index 431bacb..3d7e96e 100644 --- a/sys/modules/Makefile +++ b/sys/modules/Makefile @@ -1,10 +1,10 @@ -# $Id: Makefile,v 1.69 1999/07/28 02:21:55 wpaul Exp $ +# $Id: Makefile,v 1.70 1999/08/10 17:15:11 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 vr xl + tl umapfs union vn vr wb xl # XXX some of these can move to the general case when de-i386'ed .if ${MACHINE_ARCH} == "i386" diff --git a/sys/modules/wb/Makefile b/sys/modules/wb/Makefile new file mode 100644 index 0000000..862449c --- /dev/null +++ b/sys/modules/wb/Makefile @@ -0,0 +1,28 @@ +# $Id: Makefile,v 1.1 1999/07/23 05:48:01 wpaul Exp $ + +S = ${.CURDIR}/../.. +.PATH: $S/pci +KMOD = wb +SRCS = if_wb.c wb.h bpf.h opt_bdg.h device_if.h bus_if.h pci_if.h +CLEANFILES += wb.h bpf.h opt_bdg.h device_if.h bus_if.h pci_if.h +CFLAGS += ${DEBUG_FLAGS} + +wb.h: + echo "#define NWB 1" > wb.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 diff --git a/sys/pci/if_wb.c b/sys/pci/if_wb.c index 073b60c..1ea58f4 100644 --- a/sys/pci/if_wb.c +++ b/sys/pci/if_wb.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_wb.c,v 1.6.2.2 1999/05/13 21:19:31 wpaul Exp $ + * $Id: if_wb.c,v 1.13 1999/07/11 00:56:07 wpaul Exp $ */ /* @@ -114,6 +114,9 @@ #include #include #include +#include +#include +#include #include #include @@ -126,7 +129,7 @@ #ifndef lint static const char rcsid[] = - "$Id: if_wb.c,v 1.6.2.2 1999/05/13 21:19:31 wpaul Exp $"; + "$Id: if_wb.c,v 1.13 1999/07/11 00:56:07 wpaul Exp $"; #endif /* @@ -156,9 +159,9 @@ static struct wb_type wb_phys[] = { { 0, 0, "" } }; -static unsigned long wb_count = 0; -static const char *wb_probe __P((pcici_t, pcidi_t)); -static void wb_attach __P((pcici_t, int)); +static int wb_probe __P((device_t)); +static int wb_attach __P((device_t)); +static int wb_detach __P((device_t)); static int wb_newbuf __P((struct wb_softc *, struct wb_chain_onefrag *, @@ -176,7 +179,7 @@ static int wb_ioctl __P((struct ifnet *, u_long, caddr_t)); static void wb_init __P((void *)); static void wb_stop __P((struct wb_softc *)); static void wb_watchdog __P((struct ifnet *)); -static void wb_shutdown __P((int, void *)); +static void wb_shutdown __P((device_t)); static int wb_ifmedia_upd __P((struct ifnet *)); static void wb_ifmedia_sts __P((struct ifnet *, struct ifmediareq *)); @@ -202,6 +205,33 @@ static void wb_reset __P((struct wb_softc *)); static int wb_list_rx_init __P((struct wb_softc *)); static int wb_list_tx_init __P((struct wb_softc *)); +#ifdef WB_USEIOSPACE +#define WB_RES SYS_RES_IOPORT +#define WB_RID WB_PCI_LOIO +#else +#define WB_RES SYS_RES_MEMORY +#define WB_RID WB_PCI_LOMEM +#endif + +static device_method_t wb_methods[] = { + /* Device interface */ + DEVMETHOD(device_probe, wb_probe), + DEVMETHOD(device_attach, wb_attach), + DEVMETHOD(device_detach, wb_detach), + DEVMETHOD(device_shutdown, wb_shutdown), + { 0, 0 } +}; + +static driver_t wb_driver = { + "wb", + wb_methods, + sizeof(struct wb_softc) +}; + +static devclass_t wb_devclass; + +DRIVER_MODULE(wb, pci, wb_driver, wb_devclass, 0, 0); + #define WB_SETBIT(sc, reg, x) \ CSR_WRITE_4(sc, reg, \ CSR_READ_4(sc, reg) | x) @@ -1001,39 +1031,33 @@ static void wb_reset(sc) * Probe for a Winbond chip. Check the PCI vendor and device * IDs against our list and return a device name if we find a match. */ -static const char * -wb_probe(config_id, device_id) - pcici_t config_id; - pcidi_t device_id; +static int wb_probe(dev) + device_t dev; { struct wb_type *t; t = wb_devs; while(t->wb_name != NULL) { - if ((device_id & 0xFFFF) == t->wb_vid && - ((device_id >> 16) & 0xFFFF) == t->wb_did) { - return(t->wb_name); + if ((pci_get_vendor(dev) == t->wb_vid) && + (pci_get_device(dev) == t->wb_did)) { + device_set_desc(dev, t->wb_name); + return(0); } t++; } - return(NULL); + return(ENXIO); } /* * Attach the interface. Allocate softc structures, do ifmedia * setup and ethernet/BPF attach. */ -static void -wb_attach(config_id, unit) - pcici_t config_id; - int unit; +static int wb_attach(dev) + device_t dev; { int s, i; -#ifndef WB_USEIOSPACE - vm_offset_t pbase, vbase; -#endif u_char eaddr[ETHER_ADDR_LEN]; u_int32_t command; struct wb_softc *sc; @@ -1043,96 +1067,100 @@ wb_attach(config_id, unit) caddr_t roundptr; struct wb_type *p; u_int16_t phy_vid, phy_did, phy_sts; + int unit, error = 0, rid; s = splimp(); - sc = malloc(sizeof(struct wb_softc), M_DEVBUF, M_NOWAIT); - if (sc == NULL) { - printf("wb%d: no memory for softc struct!\n", unit); - return; - } + sc = device_get_softc(dev); + unit = device_get_unit(dev); bzero(sc, sizeof(struct wb_softc)); /* * Handle power management nonsense. */ - command = pci_conf_read(config_id, WB_PCI_CAPID) & 0x000000FF; + command = pci_read_config(dev, WB_PCI_CAPID, 4) & 0x000000FF; if (command == 0x01) { - command = pci_conf_read(config_id, WB_PCI_PWRMGMTCTRL); + command = pci_read_config(dev, WB_PCI_PWRMGMTCTRL, 4); if (command & WB_PSTATE_MASK) { u_int32_t iobase, membase, irq; /* Save important PCI config data. */ - iobase = pci_conf_read(config_id, WB_PCI_LOIO); - membase = pci_conf_read(config_id, WB_PCI_LOMEM); - irq = pci_conf_read(config_id, WB_PCI_INTLINE); + iobase = pci_read_config(dev, WB_PCI_LOIO, 4); + membase = pci_read_config(dev, WB_PCI_LOMEM, 4); + irq = pci_read_config(dev, WB_PCI_INTLINE, 4); /* Reset the power state. */ printf("wb%d: chip is in D%d power mode " "-- setting to D0\n", unit, command & WB_PSTATE_MASK); command &= 0xFFFFFFFC; - pci_conf_write(config_id, WB_PCI_PWRMGMTCTRL, command); + pci_write_config(dev, WB_PCI_PWRMGMTCTRL, command, 4); /* Restore PCI config data. */ - pci_conf_write(config_id, WB_PCI_LOIO, iobase); - pci_conf_write(config_id, WB_PCI_LOMEM, membase); - pci_conf_write(config_id, WB_PCI_INTLINE, irq); + pci_write_config(dev, WB_PCI_LOIO, iobase, 4); + pci_write_config(dev, WB_PCI_LOMEM, membase, 4); + pci_write_config(dev, WB_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 WB_USEIOSPACE if (!(command & PCIM_CMD_PORTEN)) { printf("wb%d: failed to enable I/O ports!\n", unit); - free(sc, M_DEVBUF); - goto fail; - } - - if (!pci_map_port(config_id, WB_PCI_LOIO, - (pci_port_t *)&(sc->wb_bhandle))) { - printf ("wb%d: couldn't map ports\n", unit); + error = ENXIO; goto fail; } -#ifdef __i386__ - sc->wb_btag = I386_BUS_SPACE_IO; -#endif -#ifdef __alpha__ - sc->wb_btag = ALPHA_BUS_SPACE_IO; -#endif #else if (!(command & PCIM_CMD_MEMEN)) { printf("wb%d: failed to enable memory mapping!\n", unit); + error = ENXIO; goto fail; } +#endif - if (!pci_map_mem(config_id, WB_PCI_LOMEM, &vbase, &pbase)) { - printf ("wb%d: couldn't map memory\n", unit); + rid = WB_RID; + sc->wb_res = bus_alloc_resource(dev, WB_RES, &rid, + 0, ~0, 1, RF_ACTIVE); + + if (sc->wb_res == NULL) { + printf("wb%d: couldn't map ports/memory\n", unit); + error = ENXIO; goto fail; } -#ifdef __i386__ - sc->wb_btag = I386_BUS_SPACE_MEM; -#endif -#ifdef __alpha__ - sc->wb_btag = I386_BUS_SPACE_MEM; -#endif - sc->wb_bhandle = vbase; -#endif + + sc->wb_btag = rman_get_bustag(sc->wb_res); + sc->wb_bhandle = rman_get_bushandle(sc->wb_res); /* Allocate interrupt */ - if (!pci_map_int(config_id, wb_intr, sc, &net_imask)) { + rid = 0; + sc->wb_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, + RF_SHAREABLE | RF_ACTIVE); + + if (sc->wb_irq == NULL) { printf("wb%d: couldn't map interrupt\n", unit); + bus_release_resource(dev, WB_RES, WB_RID, sc->wb_res); + error = ENXIO; goto fail; } + error = bus_setup_intr(dev, sc->wb_irq, INTR_TYPE_NET, + wb_intr, sc, &sc->wb_intrhand); + + if (error) { + bus_release_resource(dev, SYS_RES_IRQ, 0, sc->wb_irq); + bus_release_resource(dev, WB_RES, WB_RID, sc->wb_res); + printf("wb%d: couldn't set up irq\n", unit); + goto fail; + } + /* Reset the adapter. */ wb_reset(sc); @@ -1152,9 +1180,12 @@ wb_attach(config_id, unit) sc->wb_ldata_ptr = malloc(sizeof(struct wb_list_data) + 8, M_DEVBUF, M_NOWAIT); if (sc->wb_ldata_ptr == NULL) { - free(sc, M_DEVBUF); printf("wb%d: no memory for list buffers!\n", unit); - return; + bus_teardown_intr(dev, sc->wb_irq, sc->wb_intrhand); + bus_release_resource(dev, SYS_RES_IRQ, 0, sc->wb_irq); + bus_release_resource(dev, WB_RES, WB_RID, sc->wb_res); + error = ENXIO; + goto fail; } sc->wb_ldata = (struct wb_list_data *)sc->wb_ldata_ptr; @@ -1223,6 +1254,11 @@ wb_attach(config_id, unit) sc->wb_unit, sc->wb_pinfo->wb_name); } else { printf("wb%d: MII without any phy!\n", sc->wb_unit); + bus_teardown_intr(dev, sc->wb_irq, sc->wb_intrhand); + bus_release_resource(dev, SYS_RES_IRQ, 0, sc->wb_irq); + bus_release_resource(dev, WB_RES, WB_RID, sc->wb_res); + free(sc->wb_ldata_ptr, M_DEVBUF); + error = ENXIO; goto fail; } @@ -1232,9 +1268,14 @@ wb_attach(config_id, unit) ifmedia_init(&sc->ifmedia, 0, wb_ifmedia_upd, wb_ifmedia_sts); wb_getmode_mii(sc); - wb_autoneg_mii(sc, WB_FLAG_FORCEDELAY, 1); + if (cold) { + wb_autoneg_mii(sc, WB_FLAG_FORCEDELAY, 1); + wb_stop(sc); + } else { + wb_init(sc); + wb_autoneg_mii(sc, WB_FLAG_SCHEDDELAY, 1); + } media = sc->ifmedia.ifm_media; - wb_stop(sc); ifmedia_set(&sc->ifmedia, media); @@ -1247,11 +1288,37 @@ wb_attach(config_id, unit) #if NBPF > 0 bpfattach(ifp, DLT_EN10MB, sizeof(struct ether_header)); #endif - at_shutdown(wb_shutdown, sc, SHUTDOWN_POST_SYNC); fail: splx(s); - return; + return(error); +} + +static int wb_detach(dev) + device_t dev; +{ + struct wb_softc *sc; + struct ifnet *ifp; + int s; + + s = splimp(); + + sc = device_get_softc(dev); + ifp = &sc->arpcom.ac_if; + + wb_stop(sc); + if_detach(ifp); + + bus_teardown_intr(dev, sc->wb_irq, sc->wb_intrhand); + bus_release_resource(dev, SYS_RES_IRQ, 0, sc->wb_irq); + bus_release_resource(dev, WB_RES, WB_RID, sc->wb_res); + + free(sc->wb_ldata_ptr, M_DEVBUF); + ifmedia_removeall(&sc->ifmedia); + + splx(s); + + return(0); } /* @@ -2079,6 +2146,8 @@ static void wb_watchdog(ifp) if (sc->wb_autoneg) { wb_autoneg_mii(sc, WB_FLAG_DELAYTIMEO, 1); + if (!(ifp->if_flags & IFF_UP)) + wb_stop(sc); return; } @@ -2151,22 +2220,13 @@ static void wb_stop(sc) * Stop all chip I/O so that the kernel's probe routines don't * get confused by errant DMAs when rebooting. */ -static void wb_shutdown(howto, arg) - int howto; - void *arg; +static void wb_shutdown(dev) + device_t dev; { - struct wb_softc *sc = (struct wb_softc *)arg; + struct wb_softc *sc; + sc = device_get_softc(dev); wb_stop(sc); return; } - -static struct pci_device wb_device = { - "wb", - wb_probe, - wb_attach, - &wb_count, - NULL -}; -COMPAT_PCI_DRIVER(wb, wb_device); diff --git a/sys/pci/if_wbreg.h b/sys/pci/if_wbreg.h index 38cac55..ed8b35a 100644 --- a/sys/pci/if_wbreg.h +++ b/sys/pci/if_wbreg.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_wbreg.h,v 1.3 1999/05/06 15:32:52 wpaul Exp $ + * $Id: if_wbreg.h,v 1.4 1999/07/11 00:56:07 wpaul Exp $ */ /* @@ -360,7 +360,10 @@ struct wb_softc { struct ifmedia ifmedia; /* media info */ bus_space_handle_t wb_bhandle; bus_space_tag_t wb_btag; - struct wb_type *wb_info; /* 3Com adapter info */ + struct resource *wb_res; + struct resource *wb_irq; + void *wb_intrhand; + struct wb_type *wb_info; /* Winbond adapter info */ struct wb_type *wb_pinfo; /* phy info */ u_int8_t wb_unit; /* interface number */ u_int8_t wb_type; -- cgit v1.1