summaryrefslogtreecommitdiff
path: root/sys/dev/ic
diff options
context:
space:
mode:
authorcheloha <cheloha@cvs.openbsd.org>2020-01-20 07:28:04 +0000
committercheloha <cheloha@cvs.openbsd.org>2020-01-20 07:28:04 +0000
commit0a21fcafeb2763bf23a49cca2c88f53a7223db60 (patch)
tree3c473b81815673f3f68d053de38f0811347771ef /sys/dev/ic
parentbf2c24aeeec4d05bc1240471464df5a4e2a0f743 (diff)
ciss(4): de-indent polling logic
Should make untangling the polling logic simpler. "Sure." krw@
Diffstat (limited to 'sys/dev/ic')
-rw-r--r--sys/dev/ic/ciss.c142
1 files changed, 72 insertions, 70 deletions
diff --git a/sys/dev/ic/ciss.c b/sys/dev/ic/ciss.c
index 670f4cc0091..5b6f69d7f04 100644
--- a/sys/dev/ic/ciss.c
+++ b/sys/dev/ic/ciss.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ciss.c,v 1.75 2016/08/14 04:08:03 dlg Exp $ */
+/* $OpenBSD: ciss.c,v 1.76 2020/01/20 07:28:03 cheloha Exp $ */
/*
* Copyright (c) 2005,2006 Michael Shalayeff
@@ -518,88 +518,90 @@ ciss_cmd(struct ciss_ccb *ccb, int flags, int wait)
} else
bus_space_write_4(sc->iot, sc->ioh, CISS_INQ, ccb->ccb_cmdpa);
- if (wait & SCSI_POLL) {
- struct timeval tv;
- int etick;
- CISS_DPRINTF(CISS_D_CMD, ("waiting "));
-
- i = ccb->ccb_xs? ccb->ccb_xs->timeout : 60000;
- tv.tv_sec = i / 1000;
- tv.tv_usec = (i % 1000) * 1000;
- tohz = tvtohz(&tv);
- if (tohz == 0)
- tohz = 1;
- for (i *= 100, etick = tick + tohz; i--; ) {
- if (!(wait & SCSI_NOSLEEP)) {
- ccb->ccb_state = CISS_CCB_POLL;
- CISS_DPRINTF(CISS_D_CMD, ("tsleep(%d) ", tohz));
- if (tsleep(ccb, PRIBIO + 1, "ciss_cmd",
- tohz) == EWOULDBLOCK) {
+ /* If we're not waiting for completion we're done. */
+ if (!(wait & SCSI_POLL))
+ return (error);
+
+ struct timeval tv;
+ int etick;
+ CISS_DPRINTF(CISS_D_CMD, ("waiting "));
+
+ i = ccb->ccb_xs? ccb->ccb_xs->timeout : 60000;
+ tv.tv_sec = i / 1000;
+ tv.tv_usec = (i % 1000) * 1000;
+ tohz = tvtohz(&tv);
+ if (tohz == 0)
+ tohz = 1;
+ for (i *= 100, etick = tick + tohz; i--; ) {
+ if (!(wait & SCSI_NOSLEEP)) {
+ ccb->ccb_state = CISS_CCB_POLL;
+ CISS_DPRINTF(CISS_D_CMD, ("tsleep(%d) ", tohz));
+ if (tsleep(ccb, PRIBIO + 1, "ciss_cmd",
+ tohz) == EWOULDBLOCK) {
+ break;
+ }
+ if (ccb->ccb_state != CISS_CCB_ONQ) {
+ tohz = etick - tick;
+ if (tohz <= 0)
break;
+ CISS_DPRINTF(CISS_D_CMD, ("T"));
+ continue;
+ }
+ ccb1 = ccb;
+ } else {
+ DELAY(10);
+
+ if (!(bus_space_read_4(sc->iot, sc->ioh,
+ CISS_ISR) & sc->iem)) {
+ CISS_DPRINTF(CISS_D_CMD, ("N"));
+ continue;
+ }
+
+ if (sc->cfg.methods & CISS_METH_FIFO64) {
+ if (bus_space_read_4(sc->iot, sc->ioh,
+ CISS_OUTQ64_HI) == 0xffffffff) {
+ CISS_DPRINTF(CISS_D_CMD, ("Q"));
+ continue;
}
- if (ccb->ccb_state != CISS_CCB_ONQ) {
- tohz = etick - tick;
- if (tohz <= 0)
- break;
- CISS_DPRINTF(CISS_D_CMD, ("T"));
+ id = bus_space_read_4(sc->iot, sc->ioh,
+ CISS_OUTQ64_LO);
+ } else if (sc->cfg.methods &
+ CISS_METH_FIFO64_RRO) {
+ id = bus_space_read_4(sc->iot, sc->ioh,
+ CISS_OUTQ64_LO);
+ if (id == 0xffffffff) {
+ CISS_DPRINTF(CISS_D_CMD, ("Q"));
continue;
}
- ccb1 = ccb;
+ (void)bus_space_read_4(sc->iot,
+ sc->ioh, CISS_OUTQ64_HI);
} else {
- DELAY(10);
-
- if (!(bus_space_read_4(sc->iot, sc->ioh,
- CISS_ISR) & sc->iem)) {
- CISS_DPRINTF(CISS_D_CMD, ("N"));
+ id = bus_space_read_4(sc->iot, sc->ioh,
+ CISS_OUTQ);
+ if (id == 0xffffffff) {
+ CISS_DPRINTF(CISS_D_CMD, ("Q"));
continue;
}
-
- if (sc->cfg.methods & CISS_METH_FIFO64) {
- if (bus_space_read_4(sc->iot, sc->ioh,
- CISS_OUTQ64_HI) == 0xffffffff) {
- CISS_DPRINTF(CISS_D_CMD, ("Q"));
- continue;
- }
- id = bus_space_read_4(sc->iot, sc->ioh,
- CISS_OUTQ64_LO);
- } else if (sc->cfg.methods &
- CISS_METH_FIFO64_RRO) {
- id = bus_space_read_4(sc->iot, sc->ioh,
- CISS_OUTQ64_LO);
- if (id == 0xffffffff) {
- CISS_DPRINTF(CISS_D_CMD, ("Q"));
- continue;
- }
- (void)bus_space_read_4(sc->iot,
- sc->ioh, CISS_OUTQ64_HI);
- } else {
- id = bus_space_read_4(sc->iot, sc->ioh,
- CISS_OUTQ);
- if (id == 0xffffffff) {
- CISS_DPRINTF(CISS_D_CMD, ("Q"));
- continue;
- }
- }
-
- CISS_DPRINTF(CISS_D_CMD, ("got=0x%x ", id));
- ccb1 = sc->ccbs + (id >> 2) * sc->ccblen;
- ccb1->ccb_cmd.id = htole32(id);
- ccb1->ccb_cmd.id_hi = htole32(0);
}
- error = ciss_done(ccb1);
- if (ccb1 == ccb)
- return (error);
+ CISS_DPRINTF(CISS_D_CMD, ("got=0x%x ", id));
+ ccb1 = sc->ccbs + (id >> 2) * sc->ccblen;
+ ccb1->ccb_cmd.id = htole32(id);
+ ccb1->ccb_cmd.id_hi = htole32(0);
}
- /* if never got a chance to be done above... */
- ccb->ccb_err.cmd_stat = CISS_ERR_TMO;
- error = ciss_done(ccb);
-
- CISS_DPRINTF(CISS_D_CMD, ("done %d:%d",
- ccb->ccb_err.cmd_stat, ccb->ccb_err.scsi_stat));
+ error = ciss_done(ccb1);
+ if (ccb1 == ccb)
+ return (error);
}
+ /* if never got a chance to be done above... */
+ ccb->ccb_err.cmd_stat = CISS_ERR_TMO;
+ error = ciss_done(ccb);
+
+ CISS_DPRINTF(CISS_D_CMD, ("done %d:%d",
+ ccb->ccb_err.cmd_stat, ccb->ccb_err.scsi_stat));
+
return (error);
}