From 8eba34dd85d07cd346770bd44e7da86c16f4bf6b Mon Sep 17 00:00:00 2001 From: jason Date: Tue, 18 Apr 2000 18:44:22 +0000 Subject: [PATCH] split fxp into bus independent and dependent (pci) parts (cardbus to come) --- sys/conf/files | 7 +- sys/dev/{pci/if_fxp.c => ic/fxp.c} | 225 +++++++---------------- sys/dev/{pci/if_fxpreg.h => ic/fxpreg.h} | 2 +- sys/dev/{pci/if_fxpvar.h => ic/fxpvar.h} | 5 +- sys/dev/pci/files.pci | 11 +- sys/dev/pci/if_fxp_pci.c | 178 ++++++++++++++++++ 6 files changed, 265 insertions(+), 163 deletions(-) rename sys/dev/{pci/if_fxp.c => ic/fxp.c} (95%) rename sys/dev/{pci/if_fxpreg.h => ic/fxpreg.h} (99%) rename sys/dev/{pci/if_fxpvar.h => ic/fxpvar.h} (95%) create mode 100644 sys/dev/pci/if_fxp_pci.c diff --git a/sys/conf/files b/sys/conf/files index 6715a328cd8..3ad86bd51db 100644 --- a/sys/conf/files +++ b/sys/conf/files @@ -1,4 +1,4 @@ -# $OpenBSD: files,v 1.157 2000/04/08 05:50:50 aaron Exp $ +# $OpenBSD: files,v 1.158 2000/04/18 18:44:22 jason Exp $ # $NetBSD: files,v 1.87 1996/05/19 17:17:50 jonathan Exp $ # @(#)files.newconf 7.5 (Berkeley) 5/10/93 @@ -116,9 +116,14 @@ file dev/ic/rlnsubr.c rln device le: ether, ifnet, ifmedia file dev/ic/am7990.c le +# 3Com 3c9xx device xl: ether, ifnet, ifmedia, mii file dev/ic/xl.c xl +# Intel EtherExpress PRO 10/100B +device fxp: ether, ifnet, ifmedia, mii +file dev/ic/fxp.c fxp + # SMC 91Cxx Ethernet Controller device sm: ether, ifnet, ifmedia file dev/ic/smc91cxx.c sm diff --git a/sys/dev/pci/if_fxp.c b/sys/dev/ic/fxp.c similarity index 95% rename from sys/dev/pci/if_fxp.c rename to sys/dev/ic/fxp.c index 2fa3bce3236..a5adc1da376 100644 --- a/sys/dev/pci/if_fxp.c +++ b/sys/dev/ic/fxp.c @@ -1,4 +1,4 @@ -/* $OpenBSD: if_fxp.c,v 1.26 2000/04/18 03:40:55 jason Exp $ */ +/* $OpenBSD: fxp.c,v 1.1 2000/04/18 18:44:26 jason Exp $ */ /* $NetBSD: if_fxp.c,v 1.2 1997/06/05 02:01:55 thorpej Exp $ */ /* @@ -88,8 +88,8 @@ #include -#include -#include +#include +#include #include #include @@ -173,7 +173,6 @@ struct fxp_supported_media { int fxp_mediachange __P((struct ifnet *)); void fxp_mediastatus __P((struct ifnet *, struct ifmediareq *)); static inline void fxp_scb_wait __P((struct fxp_softc *)); -int fxp_intr __P((void *)); void fxp_start __P((struct ifnet *)); int fxp_ioctl __P((struct ifnet *, u_long, caddr_t)); void fxp_init __P((void *)); @@ -186,8 +185,6 @@ void fxp_autosize_eeprom __P((struct fxp_softc *)); void fxp_statchg __P((struct device *)); void fxp_read_eeprom __P((struct fxp_softc *, u_int16_t *, int, int)); -int fxp_attach_common __P((struct fxp_softc *, u_int8_t *)); - void fxp_stats_update __P((void *)); void fxp_mc_setup __P((struct fxp_softc *)); @@ -250,7 +247,6 @@ fxp_scb_wait(sc) * Operating system-specific autoconfiguration glue *************************************************************/ -int fxp_match __P((struct device *, void *, void *)); void fxp_attach __P((struct device *, struct device *, void *)); void fxp_shutdown __P((void *)); @@ -260,156 +256,10 @@ void fxp_power __P((int, void *)); int fxp_ether_ioctl __P((struct ifnet *, u_long, caddr_t)); #define ether_ioctl fxp_ether_ioctl -struct cfattach fxp_ca = { - sizeof(struct fxp_softc), fxp_match, fxp_attach -}; - struct cfdriver fxp_cd = { NULL, "fxp", DV_IFNET }; -/* - * Check if a device is an 82557. - */ -int -fxp_match(parent, match, aux) - struct device *parent; - void *match; - void *aux; -{ - struct pci_attach_args *pa = aux; - - if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL) - return (0); - - switch (PCI_PRODUCT(pa->pa_id)) { - case PCI_PRODUCT_INTEL_82557: - case PCI_PRODUCT_INTEL_82559: - return (1); - } - - return (0); -} - -void -fxp_attach(parent, self, aux) - struct device *parent, *self; - void *aux; -{ - struct fxp_softc *sc = (struct fxp_softc *)self; - struct pci_attach_args *pa = aux; - pci_chipset_tag_t pc = pa->pa_pc; - pci_intr_handle_t ih; - const char *intrstr = NULL; - u_int8_t enaddr[6]; - struct ifnet *ifp; - bus_space_tag_t iot = pa->pa_iot; - bus_addr_t iobase; - bus_size_t iosize; - - if (pci_io_find(pc, pa->pa_tag, FXP_PCI_IOBA, &iobase, &iosize)) { - printf(": can't find i/o space\n"); - return; - } - - if (bus_space_map(iot, iobase, iosize, 0, &sc->sc_sh)) { - printf(": can't map i/o space\n"); - return; - } - sc->sc_st = iot; - - /* - * Allocate our interrupt. - */ - if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, - pa->pa_intrline, &ih)) { - printf(": couldn't map interrupt\n"); - return; - } - - intrstr = pci_intr_string(pc, ih); - sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc, - self->dv_xname); - if (sc->sc_ih == NULL) { - printf(": couldn't establish interrupt"); - if (intrstr != NULL) - printf(" at %s", intrstr); - printf("\n"); - return; - } - - /* Do generic parts of attach. */ - if (fxp_attach_common(sc, enaddr)) { - /* Failed! */ - return; - } - - - ifp = &sc->arpcom.ac_if; - bcopy(enaddr, sc->arpcom.ac_enaddr, sizeof(enaddr)); - bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ); - ifp->if_softc = sc; - ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; - ifp->if_ioctl = fxp_ioctl; - ifp->if_start = fxp_start; - ifp->if_watchdog = fxp_watchdog; - - printf(": %s, address %s\n", intrstr, - ether_sprintf(sc->arpcom.ac_enaddr)); - - /* - * Initialize our media structures and probe the MII. - */ - sc->sc_mii.mii_ifp = ifp; - sc->sc_mii.mii_readreg = fxp_mdi_read; - sc->sc_mii.mii_writereg = fxp_mdi_write; - sc->sc_mii.mii_statchg = fxp_statchg; - ifmedia_init(&sc->sc_mii.mii_media, 0, fxp_mediachange, - fxp_mediastatus); - mii_phy_probe(self, &sc->sc_mii, 0xffffffff); - /* If no phy found, just use auto mode */ - if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) { - ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_MANUAL, - 0, NULL); - printf("%s: no phy found, using manual mode\n", - sc->sc_dev.dv_xname); - } - - if (ifmedia_match(&sc->sc_mii.mii_media, IFM_ETHER|IFM_MANUAL, 0)) - ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_MANUAL); - else if (ifmedia_match(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO, 0)) - ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO); - else - ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T); - - /* - * Attach the interface. - */ - if_attach(ifp); - /* - * Let the system queue as many packets as we have available - * TX descriptors. - */ - ifp->if_snd.ifq_maxlen = FXP_NTXCB - 1; - ether_ifattach(ifp); -#if NBPFILTER > 0 - bpfattach(&sc->arpcom.ac_if.if_bpf, ifp, DLT_EN10MB, - sizeof(struct ether_header)); -#endif - - /* - * Add shutdown hook so that DMA is disabled prior to reboot. Not - * doing do could allow DMA to corrupt kernel memory during the - * reboot before the driver initializes. - */ - shutdownhook_establish(fxp_shutdown, sc); - - /* - * Add suspend hook, for similiar reasons.. - */ - powerhook_establish(fxp_power, sc); -} - /* * Device shutdown routine. Called at system shutdown after sync. The * main purpose of this routine is to shut off receiver DMA so that @@ -505,10 +355,12 @@ fxp_ether_ioctl(ifp, cmd, data) * Do generic parts of attach. */ int -fxp_attach_common(sc, enaddr) +fxp_attach_common(sc, enaddr, intrstr) struct fxp_softc *sc; u_int8_t *enaddr; + const char *intrstr; { + struct ifnet *ifp; u_int16_t data; int i; @@ -558,6 +410,71 @@ fxp_attach_common(sc, enaddr) * Read MAC address. */ fxp_read_eeprom(sc, (u_int16_t *)enaddr, 0, 3); + + ifp = &sc->arpcom.ac_if; + bcopy(enaddr, sc->arpcom.ac_enaddr, sizeof(enaddr)); + bcopy(sc->sc_dev.dv_xname, ifp->if_xname, IFNAMSIZ); + ifp->if_softc = sc; + ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX | IFF_MULTICAST; + ifp->if_ioctl = fxp_ioctl; + ifp->if_start = fxp_start; + ifp->if_watchdog = fxp_watchdog; + + printf(": %s, address %s\n", intrstr, + ether_sprintf(sc->arpcom.ac_enaddr)); + + /* + * Initialize our media structures and probe the MII. + */ + sc->sc_mii.mii_ifp = ifp; + sc->sc_mii.mii_readreg = fxp_mdi_read; + sc->sc_mii.mii_writereg = fxp_mdi_write; + sc->sc_mii.mii_statchg = fxp_statchg; + ifmedia_init(&sc->sc_mii.mii_media, 0, fxp_mediachange, + fxp_mediastatus); + mii_phy_probe(&sc->sc_dev, &sc->sc_mii, 0xffffffff); + /* If no phy found, just use auto mode */ + if (LIST_FIRST(&sc->sc_mii.mii_phys) == NULL) { + ifmedia_add(&sc->sc_mii.mii_media, IFM_ETHER|IFM_MANUAL, + 0, NULL); + printf("%s: no phy found, using manual mode\n", + sc->sc_dev.dv_xname); + } + + if (ifmedia_match(&sc->sc_mii.mii_media, IFM_ETHER|IFM_MANUAL, 0)) + ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_MANUAL); + else if (ifmedia_match(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO, 0)) + ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_AUTO); + else + ifmedia_set(&sc->sc_mii.mii_media, IFM_ETHER|IFM_10_T); + + /* + * Attach the interface. + */ + if_attach(ifp); + /* + * Let the system queue as many packets as we have available + * TX descriptors. + */ + ifp->if_snd.ifq_maxlen = FXP_NTXCB - 1; + ether_ifattach(ifp); +#if NBPFILTER > 0 + bpfattach(&sc->arpcom.ac_if.if_bpf, ifp, DLT_EN10MB, + sizeof(struct ether_header)); +#endif + + /* + * Add shutdown hook so that DMA is disabled prior to reboot. Not + * doing do could allow DMA to corrupt kernel memory during the + * reboot before the driver initializes. + */ + shutdownhook_establish(fxp_shutdown, sc); + + /* + * Add suspend hook, for similiar reasons.. + */ + powerhook_establish(fxp_power, sc); + return (0); fail: diff --git a/sys/dev/pci/if_fxpreg.h b/sys/dev/ic/fxpreg.h similarity index 99% rename from sys/dev/pci/if_fxpreg.h rename to sys/dev/ic/fxpreg.h index 38a2ac5fe2e..68cbd61b047 100644 --- a/sys/dev/pci/if_fxpreg.h +++ b/sys/dev/ic/fxpreg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_fxpreg.h,v 1.5 1998/07/02 21:15:46 downsj Exp $ */ +/* $OpenBSD: fxpreg.h,v 1.1 2000/04/18 18:44:27 jason Exp $ */ /* * Copyright (c) 1995, David Greenman diff --git a/sys/dev/pci/if_fxpvar.h b/sys/dev/ic/fxpvar.h similarity index 95% rename from sys/dev/pci/if_fxpvar.h rename to sys/dev/ic/fxpvar.h index 783a0912aee..4918342a218 100644 --- a/sys/dev/pci/if_fxpvar.h +++ b/sys/dev/ic/fxpvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: if_fxpvar.h,v 1.8 2000/04/18 03:40:55 jason Exp $ */ +/* $OpenBSD: fxpvar.h,v 1.1 2000/04/18 18:44:27 jason Exp $ */ /* $NetBSD: if_fxpvar.h,v 1.1 1997/06/05 02:01:58 thorpej Exp $ */ /* @@ -78,3 +78,6 @@ struct fxp_softc { bus_space_write_2((sc)->sc_st, (sc)->sc_sh, (reg), (val)) #define CSR_WRITE_4(sc, reg, val) \ bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (reg), (val)) + +extern int fxp_intr __P((void *)); +extern int fxp_attach_common __P((struct fxp_softc *, u_int8_t *, const char *)); diff --git a/sys/dev/pci/files.pci b/sys/dev/pci/files.pci index 16aed13dada..bda71e4342c 100644 --- a/sys/dev/pci/files.pci +++ b/sys/dev/pci/files.pci @@ -1,4 +1,4 @@ -# $OpenBSD: files.pci,v 1.70 2000/04/13 00:10:52 csapuntz Exp $ +# $OpenBSD: files.pci,v 1.71 2000/04/18 18:44:31 jason Exp $ # $NetBSD: files.pci,v 1.20 1996/09/24 17:47:15 christos Exp $ # # Config file and device description for machine-independent PCI code. @@ -130,11 +130,6 @@ file dev/pci/if_lmc_common.c lmc file dev/pci/if_lmc_media.c lmc file dev/pci/if_lmc_obsd.c lmc -# Intel EtherExpress PRO 10/100B -device fxp: ether, ifnet, mii, ifmedia -attach fxp at pci -file dev/pci/if_fxp.c fxp - # RealTek 8129/8139 device rl: ether, ifnet, mii, ifmedia attach rl at pci @@ -169,6 +164,10 @@ file dev/pci/brooktree848.c bktr needs-count attach xl at pci with xl_pci file dev/pci/if_xl_pci.c xl_pci +# Intel EtherExpress PRO 10/100B +attach fxp at pci with fxp_pci +file dev/pci/if_fxp_pci.c fxp_pci + # SMC EPIC, 83c170 device tx: ether, ifnet, ifmedia attach tx at pci diff --git a/sys/dev/pci/if_fxp_pci.c b/sys/dev/pci/if_fxp_pci.c new file mode 100644 index 00000000000..61b4aa1d0fc --- /dev/null +++ b/sys/dev/pci/if_fxp_pci.c @@ -0,0 +1,178 @@ +/* $OpenBSD: if_fxp_pci.c,v 1.1 2000/04/18 18:44:31 jason Exp $ */ + +/* + * Copyright (c) 1995, David Greenman + * All rights reserved. + * + * Modifications to support NetBSD: + * Copyright (c) 1997 Jason R. Thorpe. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice unmodified, this list of conditions, and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Id: if_fxp.c,v 1.55 1998/08/04 08:53:12 dg Exp + */ + +/* + * Intel EtherExpress Pro/100B PCI Fast Ethernet driver + */ + +#include "bpfilter.h" + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include + +#ifdef INET +#include +#include +#include +#include +#endif + +#ifdef IPX +#include +#include +#endif + +#ifdef NS +#include +#include +#endif + +#if NBPFILTER > 0 +#include +#include +#endif + +#include +#include +#include + +#include + +#include + +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include + +int fxp_pci_match __P((struct device *, void *, void *)); +void fxp_pci_attach __P((struct device *, struct device *, void *)); + +struct cfattach fxp_pci_ca = { + sizeof(struct fxp_softc), fxp_pci_match, fxp_pci_attach +}; + +/* + * Check if a device is an 82557. + */ +int +fxp_pci_match(parent, match, aux) + struct device *parent; + void *match; + void *aux; +{ + struct pci_attach_args *pa = aux; + + if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL) + return (0); + + switch (PCI_PRODUCT(pa->pa_id)) { + case PCI_PRODUCT_INTEL_82557: + case PCI_PRODUCT_INTEL_82559: + return (1); + } + + return (0); +} + +void +fxp_pci_attach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct fxp_softc *sc = (struct fxp_softc *)self; + struct pci_attach_args *pa = aux; + pci_chipset_tag_t pc = pa->pa_pc; + pci_intr_handle_t ih; + const char *intrstr = NULL; + u_int8_t enaddr[6]; + bus_space_tag_t iot = pa->pa_iot; + bus_addr_t iobase; + bus_size_t iosize; + + if (pci_io_find(pc, pa->pa_tag, FXP_PCI_IOBA, &iobase, &iosize)) { + printf(": can't find i/o space\n"); + return; + } + + if (bus_space_map(iot, iobase, iosize, 0, &sc->sc_sh)) { + printf(": can't map i/o space\n"); + return; + } + sc->sc_st = iot; + + /* + * Allocate our interrupt. + */ + if (pci_intr_map(pc, pa->pa_intrtag, pa->pa_intrpin, + pa->pa_intrline, &ih)) { + printf(": couldn't map interrupt\n"); + return; + } + + intrstr = pci_intr_string(pc, ih); + sc->sc_ih = pci_intr_establish(pc, ih, IPL_NET, fxp_intr, sc, + self->dv_xname); + if (sc->sc_ih == NULL) { + printf(": couldn't establish interrupt"); + if (intrstr != NULL) + printf(" at %s", intrstr); + printf("\n"); + return; + } + + /* Do generic parts of attach. */ + if (fxp_attach_common(sc, enaddr, intrstr)) { + /* Failed! */ + return; + } +} -- 2.20.1