add detach code

This commit is contained in:
joda 2000-02-09 22:15:57 +00:00
parent 9fcfbaea4d
commit d40e2b51ee
3 changed files with 115 additions and 16 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: if_fxp_cardbus.c,v 1.5 1999/12/12 17:46:37 thorpej Exp $ */
/* $NetBSD: if_fxp_cardbus.c,v 1.6 2000/02/09 22:15:59 joda Exp $ */
/*
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@ -93,6 +93,7 @@
static int fxp_cardbus_match __P((struct device *, struct cfdata *, void *));
static void fxp_cardbus_attach __P((struct device *, struct device *, void *));
static int fxp_cardbus_detach __P((struct device *self, int flags));
static void fxp_cardbus_setup __P((struct fxp_softc *sc));
static int fxp_cardbus_enable __P((struct fxp_softc *sc));
static void fxp_cardbus_disable __P((struct fxp_softc *sc));
@ -106,7 +107,8 @@ struct fxp_cardbus_softc {
};
struct cfattach fxp_cardbus_ca = {
sizeof(struct fxp_cardbus_softc), fxp_cardbus_match, fxp_cardbus_attach
sizeof(struct fxp_cardbus_softc), fxp_cardbus_match, fxp_cardbus_attach,
fxp_cardbus_detach
};
#ifdef CBB_DEBUG
@ -121,18 +123,12 @@ fxp_cardbus_match(parent, match, aux)
struct cfdata *match;
void *aux;
{
/* should check CIS */
struct cardbus_attach_args *ca = aux;
if (CARDBUS_VENDOR(ca->ca_id) != CARDBUS_VENDOR_INTEL)
return (0);
switch (CARDBUS_PRODUCT(ca->ca_id)) {
case CARDBUS_PRODUCT_INTEL_82557:
return (1);
}
return (0);
if(CARDBUS_VENDOR(ca->ca_id) != CARDBUS_VENDOR_INTEL &&
CARDBUS_PRODUCT(ca->ca_id) != CARDBUS_PRODUCT_INTEL_82557)
return 0;
return 1;
}
static void
@ -140,6 +136,8 @@ fxp_cardbus_attach(parent, self, aux)
struct device *parent, *self;
void *aux;
{
static const char __func__[] = "fxp_cardbus_attach";
struct fxp_softc *sc = (struct fxp_softc*)self;
struct fxp_cardbus_softc *csc = (struct fxp_cardbus_softc*)self;
struct cardbus_attach_args *ca = aux;
@ -169,9 +167,13 @@ fxp_cardbus_attach(parent, self, aux)
sc->sc_sh = ioh;
csc->size = size;
} else
panic("%s: failed to allocate mem and io space", __FUNCTION__);
panic("%s: failed to allocate mem and io space", __func__);
if(ca->ca_cis.cis1_info[0] && ca->ca_cis.cis1_info[1])
printf(": %s %s\n", ca->ca_cis.cis1_info[0], ca->ca_cis.cis1_info[1]);
else
printf("\n");
sc->sc_dmat = ca->ca_dmat;
sc->sc_enable = fxp_cardbus_enable;
sc->sc_disable = fxp_cardbus_disable;
@ -249,3 +251,40 @@ fxp_cardbus_disable(struct fxp_softc *sc)
Cardbus_function_disable(((struct fxp_cardbus_softc*)sc)->ct);
}
static int
fxp_cardbus_detach(self, flags)
struct device *self;
int flags;
{
struct fxp_softc *sc = (struct fxp_softc*)self;
struct fxp_cardbus_softc *csc = (struct fxp_cardbus_softc*)self;
struct cardbus_devfunc *ct = csc->ct;
int rv;
int reg;
#ifdef DIAGNOSTIC
if (ct == NULL) {
panic("%s: data structure lacks\n", sc->sc_dev.dv_xname);
}
#endif
rv = fxp_detach(sc);
if (rv == 0) {
/*
* Unhook the interrupt handler.
*/
cardbus_intr_disestablish(ct->ct_cc, ct->ct_cf, sc->sc_ih);
/*
* release bus space and close window
*/
if(csc->base0_reg) {
reg = CARDBUS_BASE0_REG;
} else {
reg = CARDBUS_BASE1_REG;
}
Cardbus_mapreg_unmap(ct, reg, sc->sc_st, sc->sc_sh, csc->size);
}
return (rv);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: i82557.c,v 1.17 2000/02/02 17:09:47 thorpej Exp $ */
/* $NetBSD: i82557.c,v 1.18 2000/02/09 22:15:57 joda Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@ -261,6 +261,9 @@ fxp_attach(sc)
sc->sc_dev.dv_xname, error);
goto fail_1;
}
sc->sc_cdseg = seg;
sc->sc_cdnseg = rseg;
bzero(sc->sc_control_data, sizeof(struct fxp_control_data));
if ((error = bus_dmamap_create(sc->sc_dmat,
@ -867,6 +870,8 @@ fxp_intr(arg)
u_int16_t len, rxstat, txstat;
u_int8_t statack;
if ((sc->sc_dev.dv_flags & DVF_ACTIVE) == 0)
return 0;
/*
* If the interface isn't running, don't try to
* service the interrupt.. just ack it and bail.
@ -1862,3 +1867,54 @@ fxp_disable(sc)
sc->sc_enabled = 0;
}
}
int
fxp_detach(sc)
struct fxp_softc *sc;
{
struct ifnet *ifp = &sc->sc_ethercom.ec_if;
int i;
/* Unhook our tick handler. */
untimeout(fxp_tick, sc);
if (sc->sc_flags & FXPF_MII) {
/* Detach all PHYs */
mii_detach(&sc->sc_mii, MII_PHY_ANY, MII_OFFSET_ANY);
}
/* Delete all remaining media. */
ifmedia_delete_instance(&sc->sc_mii.mii_media, IFM_INST_ANY);
#if NRND > 0
rnd_detach_source(&sc->rnd_source);
#endif
#if NBPFILTER > 0
bpfdetach(ifp);
#endif
ether_ifdetach(ifp);
if_detach(ifp);
for (i = 0; i < FXP_NRFABUFS; i++) {
bus_dmamap_unload(sc->sc_dmat, sc->sc_rxmaps[i]);
bus_dmamap_destroy(sc->sc_dmat, sc->sc_rxmaps[i]);
}
for (i = 0; i < FXP_NTXCB; i++) {
bus_dmamap_unload(sc->sc_dmat, FXP_DSTX(sc, i)->txs_dmamap);
bus_dmamap_destroy(sc->sc_dmat, FXP_DSTX(sc, i)->txs_dmamap);
}
bus_dmamap_unload(sc->sc_dmat, sc->sc_dmamap);
bus_dmamap_destroy(sc->sc_dmat, sc->sc_dmamap);
bus_dmamem_unmap(sc->sc_dmat, (caddr_t)sc->sc_control_data,
sizeof(struct fxp_control_data));
bus_dmamem_free(sc->sc_dmat, &sc->sc_cdseg, sc->sc_cdnseg);
shutdownhook_disestablish(sc->sc_sdhook);
return (0);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: i82557var.h,v 1.9 1999/12/12 17:46:36 thorpej Exp $ */
/* $NetBSD: i82557var.h,v 1.10 2000/02/09 22:15:58 joda Exp $ */
/*-
* Copyright (c) 1997, 1998, 1999 The NetBSD Foundation, Inc.
@ -187,6 +187,9 @@ struct fxp_softc {
*/
struct fxp_control_data *sc_control_data;
bus_dma_segment_t sc_cdseg; /* control dma segment */
int sc_cdnseg;
int sc_flags; /* misc. flags */
#define FXPF_WANTINIT 0x01 /* want a re-init */
@ -204,7 +207,7 @@ struct fxp_softc {
int (*sc_enable) __P((struct fxp_softc *));
void (*sc_disable) __P((struct fxp_softc *));
int sc_eeprom_size; /* log2 size of EEPROM */
int sc_eeprom_size; /* log2 size of EEPROM */
#if NRND > 0
rndsource_element_t rnd_source; /* random source */
#endif
@ -317,6 +320,7 @@ do { \
bus_space_write_4((sc)->sc_st, (sc)->sc_sh, (reg), (val))
void fxp_attach __P((struct fxp_softc *));
int fxp_detach __P((struct fxp_softc *));
int fxp_intr __P((void *));
int fxp_enable __P((struct fxp_softc*));