Source-Changes-HG archive

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

[src/trunk]: src/sys/dev if_detach for sm/pcmcia.



details:   https://anonhg.NetBSD.org/src/rev/b36277f5401d
branches:  trunk
changeset: 481609:b36277f5401d
user:      itojun <itojun%NetBSD.org@localhost>
date:      Wed Feb 02 16:04:40 2000 +0000

description:
if_detach for sm/pcmcia.
with addition of resource allocation flags in softc (to DTRT on detach).

diffstat:

 sys/dev/ic/smc91cxx.c         |  33 ++++++++++++++++++++++++++-
 sys/dev/ic/smc91cxxvar.h      |   3 +-
 sys/dev/pcmcia/if_sm_pcmcia.c |  51 ++++++++++++++++++++++++++++--------------
 3 files changed, 67 insertions(+), 20 deletions(-)

diffs (189 lines):

diff -r c00ea781c0b7 -r b36277f5401d sys/dev/ic/smc91cxx.c
--- a/sys/dev/ic/smc91cxx.c     Wed Feb 02 15:54:33 2000 +0000
+++ b/sys/dev/ic/smc91cxx.c     Wed Feb 02 16:04:40 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: smc91cxx.c,v 1.21 2000/01/17 07:06:57 itojun Exp $     */
+/*     $NetBSD: smc91cxx.c,v 1.22 2000/02/02 16:04:42 itojun Exp $     */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -661,7 +661,8 @@
        u_int8_t mask, interrupts, status;
        u_int16_t packetno, tx_status, card_stats;
 
-       if (sc->sc_enabled == 0)
+       if (sc->sc_enabled == 0 ||
+           (sc->sc_dev.dv_flags & DVF_ACTIVE) == 0)
                return (0);
 
        SMC_SELECT_BANK(sc, 2);
@@ -1231,3 +1232,31 @@
        splx(s);
        return (rv);
 }
+
+int
+smc91cxx_detach(self, flags)
+       struct device *self;
+       int flags;
+{
+       struct smc91cxx_softc *sc = (struct smc91cxx_softc *)self;
+       struct ifnet *ifp = &sc->sc_ec.ec_if;
+
+       /* dp8390_disable() checks sc->sc_enabled */
+       smc91cxx_disable(sc);
+
+       /* smc91cxx_attach() never fails */
+
+       /* Delete all media. */
+       ifmedia_delete_instance(&sc->sc_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);
+
+       return (0);
+}
diff -r c00ea781c0b7 -r b36277f5401d sys/dev/ic/smc91cxxvar.h
--- a/sys/dev/ic/smc91cxxvar.h  Wed Feb 02 15:54:33 2000 +0000
+++ b/sys/dev/ic/smc91cxxvar.h  Wed Feb 02 16:04:40 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: smc91cxxvar.h,v 1.6 1998/11/18 18:34:52 thorpej Exp $  */
+/*     $NetBSD: smc91cxxvar.h,v 1.7 2000/02/02 16:04:42 itojun Exp $   */
 
 /*-
  * Copyright (c) 1997 The NetBSD Foundation, Inc.
@@ -71,3 +71,4 @@
 int    smc91cxx_enable __P((struct smc91cxx_softc *));
 void   smc91cxx_disable __P((struct smc91cxx_softc *));
 int    smc91cxx_activate __P((struct device *, enum devact));
+int    smc91cxx_detach __P((struct device *, int));
diff -r c00ea781c0b7 -r b36277f5401d sys/dev/pcmcia/if_sm_pcmcia.c
--- a/sys/dev/pcmcia/if_sm_pcmcia.c     Wed Feb 02 15:54:33 2000 +0000
+++ b/sys/dev/pcmcia/if_sm_pcmcia.c     Wed Feb 02 16:04:40 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_sm_pcmcia.c,v 1.18 1999/09/28 23:20:42 thorpej Exp $        */
+/*     $NetBSD: if_sm_pcmcia.c,v 1.19 2000/02/02 16:04:40 itojun Exp $ */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -96,6 +96,9 @@
        int     sc_io_window;                   /* our i/o window */
        void    *sc_ih;                         /* interrupt cookie */
        struct  pcmcia_function *sc_pf;         /* our PCMCIA function */
+
+       int     sc_configured;                  /* bool; attached or not */
+       int     sc_enabled;                     /* bool; enabled or not */
 };
 
 struct cfattach sm_pcmcia_ca = {
@@ -173,6 +176,8 @@
        u_int8_t myla[ETHER_ADDR_LEN], *enaddr = NULL;
        struct sm_pcmcia_product *spp;
 
+       psc->sc_configured = 0;
+
        psc->sc_pf = pa->pf;
        cfe = pa->pf->cfe_head.sqh_first;
 
@@ -189,6 +194,7 @@
        if (pcmcia_io_alloc(pa->pf, 0, cfe->iospace[0].length,
            cfe->iospace[0].length, &psc->sc_pcioh)) {
                printf(": can't allocate i/o space\n");
+               pcmcia_function_disable(pa->pf);
                return;
        }
 
@@ -202,6 +208,8 @@
            PCMCIA_WIDTH_IO16 : PCMCIA_WIDTH_IO8, 0, cfe->iospace[0].length,
            &psc->sc_pcioh, &psc->sc_io_window)) {
                printf(": can't map i/o space\n");
+               pcmcia_io_free(pa->pf, &psc->sc_pcioh);
+               pcmcia_function_disable(pa->pf);
                return;
        }
 
@@ -246,6 +254,8 @@
        smc91cxx_attach(sc, enaddr);
 
        pcmcia_function_disable(pa->pf);
+
+       psc->sc_configured = 1;
 }
 
 int
@@ -254,23 +264,20 @@
        int flags;
 {
        struct sm_pcmcia_softc *psc = (struct sm_pcmcia_softc *)self;
+       int rv;
 
-       /* Unmap our i/o window. */
-       pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
-
-       /* Free our i/o space. */
-       pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
+       if (psc->sc_configured == 0)
+               return 0;
 
-#ifdef notyet
-       /*
-        * Our softc is about to go away, so drop our reference
-        * to the ifnet.
-        */
-       if_delref(psc->sc_smc.sc_ec.ec_if);
-       return (0);
-#else
-       return (EBUSY);
-#endif
+       rv = smc91cxx_detach((struct device *)&psc->sc_smc, flags);
+       if (rv == 0) {
+               /* Unmap our i/o window. */
+               pcmcia_io_unmap(psc->sc_pf, psc->sc_io_window);
+
+               /* Free our i/o space. */
+               pcmcia_io_free(psc->sc_pf, &psc->sc_pcioh);
+       }
+       return rv;
 }
 
 int
@@ -345,6 +352,10 @@
        struct smc91cxx_softc *sc;
 {
        struct sm_pcmcia_softc *psc = (struct sm_pcmcia_softc *)sc;
+       int rv;
+
+       if (sc->sc_enabled != 0)
+               return 0;
 
        /* Establish the interrupt handler. */
        psc->sc_ih = pcmcia_intr_establish(psc->sc_pf, IPL_NET, smc91cxx_intr,
@@ -355,7 +366,9 @@
                return (1);
        }
 
-       return (pcmcia_function_enable(psc->sc_pf));
+       rv = pcmcia_function_enable(psc->sc_pf);
+       sc->sc_enabled = 1;
+       return (rv);
 }
 
 void
@@ -364,7 +377,11 @@
 {
        struct sm_pcmcia_softc *psc = (struct sm_pcmcia_softc *)sc;
 
+       if (sc->sc_enabled == 0)
+               return;
+
        pcmcia_function_disable(psc->sc_pf);
 
        pcmcia_intr_disestablish(psc->sc_pf, psc->sc_ih);
+       sc->sc_enabled = 0;
 }



Home | Main Index | Thread Index | Old Index