Source-Changes-HG archive

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

[src-draft/trunk]: src/sys/dev/pci tsleep to kpause conversion.



details:   https://anonhg.NetBSD.org/src-all/rev/897c5cc3ffdc
branches:  trunk
changeset: 377149:897c5cc3ffdc
user:      Nathanial Sloss <nat%netbsd.org@localhost>
date:      Thu Apr 27 23:44:42 2023 +1000

description:
tsleep to kpause conversion.

diffstat:

 sys/dev/pci/if_iwn.c    |  60 ++++++++++++++++++++++++++++++++++++++----------
 sys/dev/pci/if_iwnvar.h |   1 +
 2 files changed, 48 insertions(+), 13 deletions(-)

diffs (153 lines):

diff -r 2eb92f1a2e1c -r 897c5cc3ffdc sys/dev/pci/if_iwn.c
--- a/sys/dev/pci/if_iwn.c      Thu Apr 27 22:21:06 2023 +1000
+++ b/sys/dev/pci/if_iwn.c      Thu Apr 27 23:44:42 2023 +1000
@@ -501,6 +501,7 @@ iwn_attach(device_t parent __unused, dev
        sc->sc_pcitag = pa->pa_tag;
        sc->sc_dmat = pa->pa_dmat;
        mutex_init(&sc->sc_mtx, MUTEX_DEFAULT, IPL_NONE);
+       cv_init(&sc->t_event, "sleep");
 
        callout_init(&sc->calib_to, 0);
        callout_setfunc(&sc->calib_to, iwn_calib_timeout, sc);
@@ -1225,6 +1226,7 @@ iwn_detach(device_t self, int flags __un
 
        ieee80211_ifdetach(ic);
 
+       cv_destroy(&sc->t_event);
        return 0;
 }
 
@@ -2822,7 +2824,9 @@ iwn_cmd_done(struct iwn_softc *sc, struc
                m_freem(data->m);
                data->m = NULL;
        }
-       wakeup(&ring->desc[desc->idx]);
+       mutex_enter(&sc->sc_mtx);
+       cv_broadcast(&sc->t_event);
+       mutex_exit(&sc->sc_mtx);
 }
 
 /*
@@ -2984,7 +2988,9 @@ iwn_notif_intr(struct ieee80211vap *vap)
 
                case IWN5000_CALIBRATION_DONE:
                        sc->sc_flags |= IWN_FLAG_CALIB_DONE;
-                       wakeup(sc);
+                       mutex_enter(&sc->sc_mtx);
+                       cv_broadcast(&sc->t_event);
+                       mutex_exit(&sc->sc_mtx);
                        break;
                }
 
@@ -3175,11 +3181,18 @@ iwn_softintr(void *arg)
        if ((r1 & IWN_INT_FH_TX) || (r2 & IWN_FH_INT_TX)) {
                if (sc->sc_flags & IWN_FLAG_USE_ICT)
                        IWN_WRITE(sc, IWN_FH_INT, IWN_FH_INT_TX);
-               wakeup(sc);     /* FH DMA transfer completed. */
-       }
-
-       if (r1 & IWN_INT_ALIVE)
-               wakeup(sc);     /* Firmware is alive. */
+               mutex_enter(&sc->sc_mtx);
+               cv_broadcast(&sc->t_event);
+               mutex_exit(&sc->sc_mtx);
+               /* FH DMA transfer completed. */
+       }
+
+       if (r1 & IWN_INT_ALIVE) {
+               mutex_enter(&sc->sc_mtx);
+               cv_broadcast(&sc->t_event);
+               mutex_exit(&sc->sc_mtx);
+               /* Firmware is alive. */
+       }
 
        if (r1 & IWN_INT_WAKEUP)
                iwn_wakeup_intr(sc);
@@ -3883,7 +3896,14 @@ iwn_cmd(struct iwn_softc *sc, int code, 
        ring->cur = (ring->cur + 1) % IWN_TX_RING_COUNT;
        IWN_WRITE(sc, IWN_HBUS_TARG_WRPTR, ring->qid << 8 | ring->cur);
 
-       return async ? 0 : tsleep(desc, PCATCH, "iwncmd", hz);
+       if (async)
+               return 0;
+
+       mutex_enter(&sc->sc_mtx);
+       error = cv_timedwait_sig(&sc->t_event, &sc->sc_mtx, hz);
+       mutex_exit(&sc->sc_mtx);
+
+       return error;
 }
 
 static int
@@ -5798,8 +5818,11 @@ iwn5000_query_calibration(struct iwn_sof
                return error;
 
        /* Wait at most two seconds for calibration to complete. */
-       if (!(sc->sc_flags & IWN_FLAG_CALIB_DONE))
-               error = tsleep(sc, PCATCH, "iwncal", 2 * hz);
+       if (!(sc->sc_flags & IWN_FLAG_CALIB_DONE)) {
+               mutex_enter(&sc->sc_mtx);
+               error = cv_timedwait_sig(&sc->t_event, &sc->sc_mtx, hz * 2);
+               mutex_exit(&sc->sc_mtx);
+       }
        return error;
 }
 
@@ -6130,11 +6153,14 @@ iwn4965_load_firmware(struct iwn_softc *
        IWN_WRITE(sc, IWN_RESET, 0);
 
        /* Wait at most one second for first alive notification. */
-       if ((error = tsleep(sc, PCATCH, "iwninit", hz)) != 0) {
+       mutex_enter(&sc->sc_mtx);
+       if ((error = cv_timedwait_sig(&sc->t_event, &sc->sc_mtx, hz)) != 0) {
+               mutex_exit(&sc->sc_mtx);
                aprint_error_dev(sc->sc_dev,
                    "timeout waiting for adapter to initialize\n");
                return error;
        }
+       mutex_exit(&sc->sc_mtx);
 
        /* Retrieve current temperature for initial TX power calibration. */
        sc->rawtemp = sc->ucode_info.temp[3].chan20MHz;
@@ -6197,7 +6223,11 @@ iwn5000_load_firmware_section(struct iwn
        iwn_nic_unlock(sc);
 
        /* Wait at most five seconds for FH DMA transfer to complete. */
-       return tsleep(sc, PCATCH, "iwninit", 5 * hz);
+       mutex_enter(&sc->sc_mtx);
+       error = cv_timedwait_sig(&sc->t_event, &sc->sc_mtx, hz * 5);
+       mutex_exit(&sc->sc_mtx);
+
+       return error;
 }
 
 static int
@@ -6785,12 +6815,16 @@ iwn_hw_init(struct iwn_softc *sc)
                    "could not load firmware\n");
                return error;
        }
+       mutex_enter(&sc->sc_mtx);
        /* Wait at most one second for firmware alive notification. */
-       if ((error = tsleep(sc, PCATCH, "iwninit", hz)) != 0) {
+       if ((error = cv_timedwait_sig(&sc->t_event, &sc->sc_mtx, hz)) != 0) {
+               mutex_exit(&sc->sc_mtx);
                aprint_error_dev(sc->sc_dev,
                    "timeout waiting for adapter to initialize\n");
                return error;
        }
+       mutex_exit(&sc->sc_mtx);
+
        /* Do post-firmware initialization. */
        return ops->post_alive(sc);
 }
diff -r 2eb92f1a2e1c -r 897c5cc3ffdc sys/dev/pci/if_iwnvar.h
--- a/sys/dev/pci/if_iwnvar.h   Thu Apr 27 22:21:06 2023 +1000
+++ b/sys/dev/pci/if_iwnvar.h   Thu Apr 27 23:44:42 2023 +1000
@@ -339,6 +339,7 @@ struct iwn_softc {
        uint32_t                ucode_rev;
 
        kmutex_t                sc_mtx;         /* mutex for init/stop */
+       kcondvar_t              t_event;        
 
        int                     sc_beacon_wait; /* defer/skip sending */
 };



Home | Main Index | Thread Index | Old Index