Make iwm(4) wait for the PHY calibration result notification during HW init.
authorstsp <stsp@openbsd.org>
Wed, 14 Jun 2017 16:56:04 +0000 (16:56 +0000)
committerstsp <stsp@openbsd.org>
Wed, 14 Jun 2017 16:56:04 +0000 (16:56 +0000)
Code inspection revealed that Linux does this, and so should we.
ok deraadt@

sys/dev/pci/if_iwm.c
sys/dev/pci/if_iwmvar.h

index 062919b..9478ce7 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: if_iwm.c,v 1.192 2017/06/09 13:47:26 stsp Exp $       */
+/*     $OpenBSD: if_iwm.c,v 1.193 2017/06/14 16:56:04 stsp Exp $       */
 
 /*
  * Copyright (c) 2014, 2016 genua gmbh <info@genua.de>
@@ -3126,6 +3126,7 @@ iwm_load_ucode_wait_alive(struct iwm_softc *sc,
 int
 iwm_run_init_mvm_ucode(struct iwm_softc *sc, int justnvm)
 {
+       const int wait_flags = (IWM_INIT_COMPLETE | IWM_CALIB_COMPLETE);
        int err;
 
        if ((sc->sc_flags & IWM_FLAG_RFKILL) && !justnvm) {
@@ -3177,10 +3178,10 @@ iwm_run_init_mvm_ucode(struct iwm_softc *sc, int justnvm)
                return err;
 
        /*
-        * Nothing to do but wait for the init complete notification
-        * from the firmware
+        * Nothing to do but wait for the init complete and phy DB
+        * notifications from the firmware.
         */
-       while (!sc->sc_init_complete) {
+       while ((sc->sc_init_complete & wait_flags) != wait_flags) {
                err = tsleep(&sc->sc_init_complete, 0, "iwminit", 2*hz);
                if (err)
                        break;
@@ -6680,6 +6681,8 @@ iwm_notif_intr(struct iwm_softc *sc)
                        struct iwm_calib_res_notif_phy_db *phy_db_notif;
                        SYNC_RESP_STRUCT(phy_db_notif, pkt);
                        iwm_phy_db_set_section(sc, phy_db_notif);
+                       sc->sc_init_complete |= IWM_CALIB_COMPLETE;
+                       wakeup(&sc->sc_init_complete);
                        break;
                }
 
@@ -6746,7 +6749,7 @@ iwm_notif_intr(struct iwm_softc *sc)
                        break;
 
                case IWM_INIT_COMPLETE_NOTIF:
-                       sc->sc_init_complete = 1;
+                       sc->sc_init_complete |= IWM_INIT_COMPLETE;
                        wakeup(&sc->sc_init_complete);
                        break;
 
index a78c5ed..23f27c9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: if_iwmvar.h,v 1.27 2017/05/28 09:59:58 stsp Exp $     */
+/*     $OpenBSD: if_iwmvar.h,v 1.28 2017/06/14 16:56:04 stsp Exp $     */
 
 /*
  * Copyright (c) 2014 genua mbh <info@genua.de>
@@ -407,6 +407,8 @@ struct iwm_softc {
 
        int sc_fw_chunk_done;
        int sc_init_complete;
+#define IWM_INIT_COMPLETE      0x01
+#define IWM_CALIB_COMPLETE     0x02
 
        struct iwm_ucode_status sc_uc;
        enum iwm_ucode_type sc_uc_current;