Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev add detach code



details:   https://anonhg.NetBSD.org/src/rev/7d3b1191ac9d
branches:  trunk
changeset: 481941:7d3b1191ac9d
user:      joda <joda%NetBSD.org@localhost>
date:      Wed Feb 09 22:15:57 2000 +0000

description:
add detach code

diffstat:

 sys/dev/cardbus/if_fxp_cardbus.c |  65 ++++++++++++++++++++++++++++++++--------
 sys/dev/ic/i82557.c              |  58 +++++++++++++++++++++++++++++++++++-
 sys/dev/ic/i82557var.h           |   8 +++-
 3 files changed, 115 insertions(+), 16 deletions(-)

diffs (234 lines):

diff -r 6092e03fe94d -r 7d3b1191ac9d sys/dev/cardbus/if_fxp_cardbus.c
--- a/sys/dev/cardbus/if_fxp_cardbus.c  Wed Feb 09 20:26:53 2000 +0000
+++ b/sys/dev/cardbus/if_fxp_cardbus.c  Wed Feb 09 22:15:57 2000 +0000
@@ -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 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 @@
      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 @@
      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 @@
        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 @@
     
     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);
+}
diff -r 6092e03fe94d -r 7d3b1191ac9d sys/dev/ic/i82557.c
--- a/sys/dev/ic/i82557.c       Wed Feb 09 20:26:53 2000 +0000
+++ b/sys/dev/ic/i82557.c       Wed Feb 09 22:15:57 2000 +0000
@@ -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 @@
                    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 @@
        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 @@
                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);
+}
diff -r 6092e03fe94d -r 7d3b1191ac9d sys/dev/ic/i82557var.h
--- a/sys/dev/ic/i82557var.h    Wed Feb 09 20:26:53 2000 +0000
+++ b/sys/dev/ic/i82557var.h    Wed Feb 09 22:15:57 2000 +0000
@@ -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_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 @@
        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 @@
        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*));



Home | Main Index | Thread Index | Old Index