summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorJonathan Gray <jsg@cvs.openbsd.org>2009-06-02 16:50:21 +0000
committerJonathan Gray <jsg@cvs.openbsd.org>2009-06-02 16:50:21 +0000
commitb3284db37f807ede1a336a6386d90497400711fd (patch)
tree0ed8e6e68fdb6e94746074ac95248bbf5b7ec680 /sys/dev
parentcaba12193a3fbed4b1793760f627ce31a39716f3 (diff)
Make fxp at pci detachable; untested.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/cardbus/if_fxp_cardbus.c30
-rw-r--r--sys/dev/ic/fxp.c28
-rw-r--r--sys/dev/ic/fxpvar.h3
-rw-r--r--sys/dev/pci/if_fxp_pci.c43
4 files changed, 65 insertions, 39 deletions
diff --git a/sys/dev/cardbus/if_fxp_cardbus.c b/sys/dev/cardbus/if_fxp_cardbus.c
index c9bd29fa8fd..3d7a0c02074 100644
--- a/sys/dev/cardbus/if_fxp_cardbus.c
+++ b/sys/dev/cardbus/if_fxp_cardbus.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_fxp_cardbus.c,v 1.22 2008/06/26 05:42:14 ray Exp $ */
+/* $OpenBSD: if_fxp_cardbus.c,v 1.23 2009/06/02 16:50:20 jsg Exp $ */
/* $NetBSD: if_fxp_cardbus.c,v 1.12 2000/05/08 18:23:36 thorpej Exp $ */
/*
@@ -213,34 +213,6 @@ fxp_cardbus_setup(struct fxp_softc *sc)
cardbus_conf_write(cc, cf, csc->ct_tag, CARDBUS_COMMAND_STATUS_REG, command);
}
-int fxp_detach(struct fxp_softc *);
-
-int
-fxp_detach(struct fxp_softc *sc)
-{
- struct ifnet *ifp = &sc->sc_arpcom.ac_if;
-
- /* Unhook our tick handler. */
- timeout_del(&sc->stats_update_to);
-
- /* Detach any PHYs we might have. */
- if (LIST_FIRST(&sc->sc_mii.mii_phys) != NULL)
- mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
-
- /* Delete any remaining media. */
- ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY);
-
- ether_ifdetach(ifp);
- if_detach(ifp);
-
- if (sc->sc_sdhook != NULL)
- shutdownhook_disestablish(sc->sc_sdhook);
- if (sc->sc_powerhook != NULL)
- powerhook_disestablish(sc->sc_powerhook);
-
- return (0);
-}
-
int
fxp_cardbus_detach(struct device *self, int flags)
{
diff --git a/sys/dev/ic/fxp.c b/sys/dev/ic/fxp.c
index e60ebab5b49..8d7f6256207 100644
--- a/sys/dev/ic/fxp.c
+++ b/sys/dev/ic/fxp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fxp.c,v 1.94 2008/11/28 02:44:17 brad Exp $ */
+/* $OpenBSD: fxp.c,v 1.95 2009/06/02 16:50:20 jsg Exp $ */
/* $NetBSD: if_fxp.c,v 1.2 1997/06/05 02:01:55 thorpej Exp $ */
/*
@@ -1052,6 +1052,32 @@ fxp_stats_update(void *arg)
timeout_add_sec(&sc->stats_update_to, 1);
}
+int
+fxp_detach(struct fxp_softc *sc)
+{
+ struct ifnet *ifp = &sc->sc_arpcom.ac_if;
+
+ /* Unhook our tick handler. */
+ timeout_del(&sc->stats_update_to);
+
+ /* Detach any PHYs we might have. */
+ if (LIST_FIRST(&sc->sc_mii.mii_phys) != NULL)
+ mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
+
+ /* Delete any remaining media. */
+ ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY);
+
+ ether_ifdetach(ifp);
+ if_detach(ifp);
+
+ if (sc->sc_sdhook != NULL)
+ shutdownhook_disestablish(sc->sc_sdhook);
+ if (sc->sc_powerhook != NULL)
+ powerhook_disestablish(sc->sc_powerhook);
+
+ return (0);
+}
+
/*
* Stop the interface. Cancels the statistics updater and resets
* the interface.
diff --git a/sys/dev/ic/fxpvar.h b/sys/dev/ic/fxpvar.h
index 358e8e3f697..e88d580ec8c 100644
--- a/sys/dev/ic/fxpvar.h
+++ b/sys/dev/ic/fxpvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: fxpvar.h,v 1.28 2008/02/21 03:58:07 brad Exp $ */
+/* $OpenBSD: fxpvar.h,v 1.29 2009/06/02 16:50:20 jsg Exp $ */
/* $NetBSD: if_fxpvar.h,v 1.1 1997/06/05 02:01:58 thorpej Exp $ */
/*
@@ -157,6 +157,7 @@ struct fxp_softc {
extern int fxp_intr(void *);
extern int fxp_attach(struct fxp_softc *, const char *);
+int fxp_detach(struct fxp_softc *);
#define FXP_RXMAP_GET(sc) ((sc)->sc_rxmaps[(sc)->sc_rxfree++])
#define FXP_RXMAP_PUT(sc,map) ((sc)->sc_rxmaps[--(sc)->sc_rxfree] = (map))
diff --git a/sys/dev/pci/if_fxp_pci.c b/sys/dev/pci/if_fxp_pci.c
index 725fedb2614..fa1e11ff514 100644
--- a/sys/dev/pci/if_fxp_pci.c
+++ b/sys/dev/pci/if_fxp_pci.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: if_fxp_pci.c,v 1.49 2006/11/05 02:47:01 brad Exp $ */
+/* $OpenBSD: if_fxp_pci.c,v 1.50 2009/06/02 16:50:20 jsg Exp $ */
/*
* Copyright (c) 1995, David Greenman
@@ -80,9 +80,17 @@
int fxp_pci_match(struct device *, void *, void *);
void fxp_pci_attach(struct device *, struct device *, void *);
+int fxp_pci_detach(struct device *, int);
+
+struct fxp_pci_softc {
+ struct fxp_softc psc_softc;
+ pci_chipset_tag_t psc_pc;
+ bus_size_t psc_mapsize;
+};
struct cfattach fxp_pci_ca = {
- sizeof(struct fxp_softc), fxp_pci_match, fxp_pci_attach
+ sizeof(struct fxp_pci_softc), fxp_pci_match, fxp_pci_attach,
+ fxp_pci_detach
};
const struct pci_matchid fxp_pci_devices[] = {
@@ -144,19 +152,20 @@ fxp_pci_match(struct device *parent, void *match, void *aux)
void
fxp_pci_attach(struct device *parent, struct device *self, void *aux)
{
- struct fxp_softc *sc = (struct fxp_softc *)self;
+ struct fxp_pci_softc *psc = (void *)self;
+ struct fxp_softc *sc = &psc->psc_softc;
struct pci_attach_args *pa = aux;
pci_chipset_tag_t pc = pa->pa_pc;
pci_intr_handle_t ih;
const char *chipname = NULL;
const char *intrstr = NULL;
- bus_size_t iosize;
if (pci_mapreg_map(pa, FXP_PCI_IOBA, PCI_MAPREG_TYPE_IO, 0,
- &sc->sc_st, &sc->sc_sh, NULL, &iosize, 0)) {
+ &sc->sc_st, &sc->sc_sh, NULL, &psc->psc_mapsize, 0)) {
printf(": can't map i/o space\n");
return;
}
+ psc->psc_pc = pa->pa_pc;
sc->sc_dmat = pa->pa_dmat;
sc->sc_revision = PCI_REVISION(pa->pa_class);
@@ -166,7 +175,7 @@ fxp_pci_attach(struct device *parent, struct device *self, void *aux)
*/
if (pci_intr_map(pa, &ih)) {
printf(": couldn't map interrupt\n");
- bus_space_unmap(sc->sc_st, sc->sc_sh, iosize);
+ bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize);
return;
}
@@ -178,7 +187,7 @@ fxp_pci_attach(struct device *parent, struct device *self, void *aux)
if (intrstr != NULL)
printf(" at %s", intrstr);
printf("\n");
- bus_space_unmap(sc->sc_st, sc->sc_sh, iosize);
+ bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize);
return;
}
@@ -245,7 +254,25 @@ fxp_pci_attach(struct device *parent, struct device *self, void *aux)
if (fxp_attach(sc, intrstr)) {
/* Failed! */
pci_intr_disestablish(pc, sc->sc_ih);
- bus_space_unmap(sc->sc_st, sc->sc_sh, iosize);
+ bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize);
return;
}
}
+
+int
+fxp_pci_detach(struct device *self, int flags)
+{
+ struct fxp_pci_softc *psc = (void *)self;
+ struct fxp_softc *sc = &psc->psc_softc;
+ int rv;
+
+ rv = fxp_detach(sc);
+ if (rv == 0) {
+ if (sc->sc_ih != NULL)
+ pci_intr_disestablish(psc->psc_pc, sc->sc_ih);
+
+ bus_space_unmap(sc->sc_st, sc->sc_sh, psc->psc_mapsize);
+ }
+
+ return (rv);
+}