fix qwx(4) not coming up on first try if firmware was missing from disk at boot
authorstsp <stsp@openbsd.org>
Fri, 16 Feb 2024 14:18:36 +0000 (14:18 +0000)
committerstsp <stsp@openbsd.org>
Fri, 16 Feb 2024 14:18:36 +0000 (14:18 +0000)
sys/dev/ic/qwx.c

index 8d0c26f..fcbae62 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: qwx.c,v 1.43 2024/02/16 14:16:16 stsp Exp $   */
+/*     $OpenBSD: qwx.c,v 1.44 2024/02/16 14:18:36 stsp Exp $   */
 
 /*
  * Copyright 2023 Stefan Sperling <stsp@openbsd.org>
@@ -211,29 +211,13 @@ qwx_init(struct ifnet *ifp)
        ieee80211_media_init(ifp, qwx_media_change, ieee80211_media_status);
 
        if (sc->attached) {
-               /*
-                * We are either going up for the first time or qwx_stop() ran
-                * before us and has waited for any stale tasks to finish up.
-                */
-               KASSERT(sc->task_refs.r_refs == 0);
-               refcnt_init(&sc->task_refs);
-
-               ifq_clr_oactive(&ifp->if_snd);
-               ifp->if_flags |= IFF_RUNNING;
-
                /* Update MAC in case the upper layers changed it. */
                IEEE80211_ADDR_COPY(ic->ic_myaddr,
                    ((struct arpcom *)ifp)->ac_enaddr);
-
-               error = qwx_mac_start(sc);
-               if (error)
-                       return error;
-
-               ieee80211_begin_scan(ifp);
        } else {
                sc->attached = 1;
 
-               /* Configure MAC address at boot-time. */
+               /* Configure initial MAC address. */
                error = if_setlladdr(ifp, ic->ic_myaddr);
                if (error)
                        printf("%s: could not set MAC address %s: %d\n",
@@ -241,6 +225,19 @@ qwx_init(struct ifnet *ifp)
                            error);
        }
 
+       if (ifp->if_flags & IFF_UP) {
+               refcnt_init(&sc->task_refs);
+
+               ifq_clr_oactive(&ifp->if_snd);
+               ifp->if_flags |= IFF_RUNNING;
+
+               error = qwx_mac_start(sc);
+               if (error)
+                       return error;
+
+               ieee80211_begin_scan(ifp);
+       }
+
        return 0;
 }