Module Name: src Committed By: skrll Date: Sat Apr 30 08:45:13 UTC 2016
Modified Files: src/sys/dev/usb [nick-nhusb]: if_otus.c if_otusvar.h Log Message: Convert from spl(9)/tsleep(9) to mutex(9)/condvar(9) To generate a diff of this commit: cvs rdiff -u -r1.25.6.5 -r1.25.6.6 src/sys/dev/usb/if_otus.c cvs rdiff -u -r1.7.12.4 -r1.7.12.5 src/sys/dev/usb/if_otusvar.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/dev/usb/if_otus.c diff -u src/sys/dev/usb/if_otus.c:1.25.6.5 src/sys/dev/usb/if_otus.c:1.25.6.6 --- src/sys/dev/usb/if_otus.c:1.25.6.5 Tue Oct 6 21:32:15 2015 +++ src/sys/dev/usb/if_otus.c Sat Apr 30 08:45:13 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: if_otus.c,v 1.25.6.5 2015/10/06 21:32:15 skrll Exp $ */ +/* $NetBSD: if_otus.c,v 1.25.6.6 2016/04/30 08:45:13 skrll Exp $ */ /* $OpenBSD: if_otus.c,v 1.18 2010/08/27 17:08:00 jsg Exp $ */ /*- @@ -23,7 +23,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.25.6.5 2015/10/06 21:32:15 skrll Exp $"); +__KERNEL_RCSID(0, "$NetBSD: if_otus.c,v 1.25.6.6 2016/04/30 08:45:13 skrll Exp $"); #include <sys/param.h> #include <sys/sockio.h> @@ -626,6 +626,8 @@ otus_attach(device_t parent, device_t se aprint_normal_dev(sc->sc_dev, "%s\n", devinfop); usbd_devinfo_free(devinfop); + cv_init(&sc->sc_task_cv, "otustsk"); + cv_init(&sc->sc_cmd_cv, "otuscmd"); mutex_init(&sc->sc_cmd_mtx, MUTEX_DEFAULT, IPL_NONE); mutex_init(&sc->sc_task_mtx, MUTEX_DEFAULT, IPL_NET); mutex_init(&sc->sc_tx_mtx, MUTEX_DEFAULT, IPL_NONE); @@ -674,8 +676,10 @@ otus_wait_async(struct otus_softc *sc) DPRINTFN(DBG_FN, sc, "\n"); + mutex_spin_enter(&sc->sc_task_mtx); while (sc->sc_cmdq.queued > 0) - tsleep(&sc->sc_cmdq, 0, "sc_cmdq", 0); + cv_wait(&sc->sc_task_cv, &sc->sc_task_mtx); + mutex_spin_exit(&sc->sc_task_mtx); } Static int @@ -716,6 +720,9 @@ otus_detach(device_t self, int flags) mutex_destroy(&sc->sc_tx_mtx); mutex_destroy(&sc->sc_task_mtx); mutex_destroy(&sc->sc_cmd_mtx); + cv_destroy(&sc->sc_task_cv); + cv_destroy(&sc->sc_cmd_cv); + return 0; } @@ -1234,34 +1241,29 @@ otus_task(void *arg) struct otus_softc *sc; struct otus_host_cmd_ring *ring; struct otus_host_cmd *cmd; - int s; sc = arg; DPRINTFN(DBG_FN, sc, "\n"); /* Process host commands. */ - s = splusb(); mutex_spin_enter(&sc->sc_task_mtx); ring = &sc->sc_cmdq; while (ring->next != ring->cur) { cmd = &ring->cmd[ring->next]; mutex_spin_exit(&sc->sc_task_mtx); - splx(s); /* Callback. */ DPRINTFN(DBG_CMD, sc, "cb=%p queued=%d\n", cmd->cb, ring->queued); cmd->cb(sc, cmd->data); - s = splusb(); mutex_spin_enter(&sc->sc_task_mtx); ring->queued--; ring->next = (ring->next + 1) % OTUS_HOST_CMD_RING_COUNT; } + cv_signal(&sc->sc_task_cv); mutex_spin_exit(&sc->sc_task_mtx); - wakeup(ring); - splx(s); } Static void @@ -1270,12 +1272,10 @@ otus_do_async(struct otus_softc *sc, voi { struct otus_host_cmd_ring *ring; struct otus_host_cmd *cmd; - int s; + bool sched = false; DPRINTFN(DBG_FN, sc, "cb=%p\n", cb); - - s = splusb(); mutex_spin_enter(&sc->sc_task_mtx); ring = &sc->sc_cmdq; cmd = &ring->cmd[ring->cur]; @@ -1286,13 +1286,12 @@ otus_do_async(struct otus_softc *sc, voi /* If there is no pending command already, schedule a task. */ if (++ring->queued == 1) { - mutex_spin_exit(&sc->sc_task_mtx); - usb_add_task(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER); + sched = true; } - else - mutex_spin_exit(&sc->sc_task_mtx); - wakeup(ring); - splx(s); + cv_signal(&sc->sc_task_cv); + mutex_spin_exit(&sc->sc_task_mtx); + if (sched) + usb_add_task(sc->sc_udev, &sc->sc_task, USB_TASKQ_DRIVER); } Static int @@ -1393,7 +1392,7 @@ otus_cmd(struct otus_softc *sc, uint8_t { struct otus_tx_cmd *cmd; struct ar_cmd_hdr *hdr; - int s, xferlen, error; + int xferlen, error; DPRINTFN(DBG_FN, sc, "\n"); @@ -1419,14 +1418,12 @@ otus_cmd(struct otus_softc *sc, uint8_t DPRINTFN(DBG_CMD, sc, "sending command code=0x%02x len=%d token=%d\n", code, ilen, hdr->token); - s = splusb(); cmd->odata = odata; cmd->done = 0; usbd_setup_xfer(cmd->xfer, cmd, cmd->buf, xferlen, USBD_FORCE_SHORT_XFER, OTUS_CMD_TIMEOUT, NULL); error = usbd_sync_transfer(cmd->xfer); if (error != 0) { - splx(s); mutex_exit(&sc->sc_cmd_mtx); #if defined(DIAGNOSTIC) || defined(OTUS_DEBUG) /* XXX: kill some noise */ aprint_error_dev(sc->sc_dev, @@ -1436,9 +1433,8 @@ otus_cmd(struct otus_softc *sc, uint8_t return EIO; } if (!cmd->done) - error = tsleep(cmd, PCATCH, "otuscmd", hz); + error = cv_timedwait_sig(&sc->sc_cmd_cv, &sc->sc_cmd_mtx, hz); cmd->odata = NULL; /* In case answer is received too late. */ - splx(s); mutex_exit(&sc->sc_cmd_mtx); if (error != 0) { aprint_error_dev(sc->sc_dev, @@ -1639,14 +1635,18 @@ otus_cmd_rxeof(struct otus_softc *sc, ui if ((hdr->code & 0xc0) != 0xc0) { DPRINTFN(DBG_RX, sc, "received reply code=0x%02x len=%d token=%d\n", hdr->code, hdr->len, hdr->token); + mutex_enter(&sc->sc_cmd_mtx); cmd = &sc->sc_tx_cmd; - if (__predict_false(hdr->token != cmd->token)) + if (__predict_false(hdr->token != cmd->token)) { + mutex_exit(&sc->sc_cmd_mtx); return; + } /* Copy answer into caller's supplied buffer. */ if (cmd->odata != NULL) memcpy(cmd->odata, &hdr[1], hdr->len); cmd->done = 1; - wakeup(cmd); + cv_signal(&sc->sc_cmd_cv); + mutex_exit(&sc->sc_cmd_mtx); return; } Index: src/sys/dev/usb/if_otusvar.h diff -u src/sys/dev/usb/if_otusvar.h:1.7.12.4 src/sys/dev/usb/if_otusvar.h:1.7.12.5 --- src/sys/dev/usb/if_otusvar.h:1.7.12.4 Sun Mar 20 08:42:19 2016 +++ src/sys/dev/usb/if_otusvar.h Sat Apr 30 08:45:13 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: if_otusvar.h,v 1.7.12.4 2016/03/20 08:42:19 skrll Exp $ */ +/* $NetBSD: if_otusvar.h,v 1.7.12.5 2016/04/30 08:45:13 skrll Exp $ */ /* $OpenBSD: if_otusreg.h,v 1.6 2009/04/06 18:17:01 damien Exp $ */ /*- @@ -199,6 +199,8 @@ struct otus_softc { unsigned int sc_write_idx; uint32_t sc_led_state; + kcondvar_t sc_task_cv; + kcondvar_t sc_cmd_cv; kmutex_t sc_cmd_mtx; kmutex_t sc_task_mtx; kmutex_t sc_write_mtx;