Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pcmcia on attach, check if we've got meaningful mac ...



details:   https://anonhg.NetBSD.org/src/rev/9e53144b5992
branches:  trunk
changeset: 482079:9e53144b5992
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sun Feb 13 06:17:58 2000 +0000

description:
on attach, check if we've got meaningful mac address or not,
to detect io mapping problem.

on detach, handle resource deallocations more carefully.

diffstat:

 sys/dev/pcmcia/if_wi.c    |  37 ++++++++++++++++++++++++++++---------
 sys/dev/pcmcia/if_wivar.h |   8 ++++++--
 2 files changed, 34 insertions(+), 11 deletions(-)

diffs (125 lines):

diff -r 847e5b5059a2 -r 9e53144b5992 sys/dev/pcmcia/if_wi.c
--- a/sys/dev/pcmcia/if_wi.c    Sun Feb 13 05:40:36 2000 +0000
+++ b/sys/dev/pcmcia/if_wi.c    Sun Feb 13 06:17:58 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wi.c,v 1.6 2000/02/12 23:35:28 enami Exp $  */
+/*     $NetBSD: if_wi.c,v 1.7 2000/02/13 06:17:58 itojun Exp $ */
 
 /*
  * Copyright (c) 1997, 1998, 1999
@@ -31,7 +31,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- *     $Id: if_wi.c,v 1.6 2000/02/12 23:35:28 enami Exp $
+ *     $Id: if_wi.c,v 1.7 2000/02/13 06:17:58 itojun Exp $
  */
 
 /*
@@ -115,7 +115,7 @@
 
 #if !defined(lint)
 static const char rcsid[] =
-       "$Id: if_wi.c,v 1.6 2000/02/12 23:35:28 enami Exp $";
+       "$Id: if_wi.c,v 1.7 2000/02/13 06:17:58 itojun Exp $";
 #endif
 
 #ifdef foo
@@ -229,8 +229,10 @@
        struct ifnet *ifp = &sc->sc_ethercom.ec_if;
        struct wi_ltv_macaddr   mac;
        struct wi_ltv_gen       gen;
+       u_int8_t empty_macaddr[ETHER_ADDR_LEN];
 
        ifp = &sc->sc_ethercom.ec_if;
+       sc->wi_resource = 0;
 
        /* Enable the card */
        sc->sc_pf = pa->pf;
@@ -255,6 +257,7 @@
                pcmcia_function_disable(sc->sc_pf);
                return;
        }
+       sc->wi_resource |= WI_RES_IO;
        sc->wi_btag = sc->sc_pcioh.iot;
        sc->wi_bhandle = sc->sc_pcioh.ioh;
 
@@ -272,6 +275,17 @@
        wi_read_record(sc, (struct wi_ltv_gen *)&mac);
        memcpy(sc->sc_macaddr, mac.wi_mac_addr, ETHER_ADDR_LEN);
 
+       /* check if we got anything meaningful */
+       bzero(empty_macaddr, sizeof(empty_macaddr));
+       if (bcmp(sc->sc_macaddr, empty_macaddr, ETHER_ADDR_LEN) == 0) {
+               printf(": could not get mac address, attach failed\n");
+               pcmcia_io_unmap(sc->sc_pf, sc->sc_iowin);
+               pcmcia_io_free(sc->sc_pf, &sc->sc_pcioh);
+               pcmcia_function_disable(sc->sc_pf);
+               sc->wi_resource &= ~WI_RES_IO;
+               return;
+       }
+
        printf("\n%s: address %s\n", sc->sc_dev.dv_xname,
            ether_sprintf(sc->sc_macaddr));
 
@@ -339,6 +353,7 @@
        bpfattach(&sc->sc_ethercom.ec_if.if_bpf, ifp, DLT_EN10MB,
            sizeof(struct ether_header));
 #endif
+       sc->wi_resource |= WI_RES_NET;
 
        sc->sc_sdhook = shutdownhook_establish(wi_shutdown, sc);
 
@@ -1440,15 +1455,19 @@
                untimeout(wi_inquire, sc);
        wi_disable(sc);
 
+       if (sc->wi_resource & WI_RES_NET) {
 #if NBPFILTER > 0
-       bpfdetach(ifp);
+               bpfdetach(ifp);
 #endif
-       ether_ifdetach(ifp);
-       if_detach(ifp);
+               ether_ifdetach(ifp);
+               if_detach(ifp);
+       }
 
-       /* unmap and free our i/o windows */
-       pcmcia_io_unmap(sc->sc_pf, sc->sc_iowin);
-       pcmcia_io_free(sc->sc_pf, &sc->sc_pcioh);
+       if (sc->wi_resource & WI_RES_IO) {
+               /* unmap and free our i/o windows */
+               pcmcia_io_unmap(sc->sc_pf, sc->sc_iowin);
+               pcmcia_io_free(sc->sc_pf, &sc->sc_pcioh);
+       }
 
        return (0);
 }
diff -r 847e5b5059a2 -r 9e53144b5992 sys/dev/pcmcia/if_wivar.h
--- a/sys/dev/pcmcia/if_wivar.h Sun Feb 13 05:40:36 2000 +0000
+++ b/sys/dev/pcmcia/if_wivar.h Sun Feb 13 06:17:58 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: if_wivar.h,v 1.3 2000/02/04 07:48:29 explorer Exp $    */
+/*     $NetBSD: if_wivar.h,v 1.4 2000/02/13 06:17:58 itojun Exp $      */
 
 /*
  * Copyright (c) 1997, 1998, 1999
@@ -31,7 +31,7 @@
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
  * THE POSSIBILITY OF SUCH DAMAGE.
  *
- *     $Id: if_wivar.h,v 1.3 2000/02/04 07:48:29 explorer Exp $
+ *     $Id: if_wivar.h,v 1.4 2000/02/13 06:17:58 itojun Exp $
  */
 
 
@@ -79,4 +79,8 @@
        int                     wi_tx_key;
        struct wi_ltv_keys      wi_keys;
        struct wi_counters      wi_stats;
+
+       int                     wi_resource; /* Resources alloc'ed on attach */
+#define WI_RES_IO      1
+#define WI_RES_NET     2
 };



Home | Main Index | Thread Index | Old Index