Changeset View
Changeset View
Standalone View
Standalone View
sys/dev/mpt/mpt.c
Show First 20 Lines • Show All 1,314 Lines • ▼ Show 20 Lines | |||||
* 0 Request completed | * 0 Request completed | ||||
* non-0 Timeout fired before request completion. | * non-0 Timeout fired before request completion. | ||||
*/ | */ | ||||
int | int | ||||
mpt_wait_req(struct mpt_softc *mpt, request_t *req, | mpt_wait_req(struct mpt_softc *mpt, request_t *req, | ||||
mpt_req_state_t state, mpt_req_state_t mask, | mpt_req_state_t state, mpt_req_state_t mask, | ||||
int sleep_ok, int time_ms) | int sleep_ok, int time_ms) | ||||
{ | { | ||||
int error; | |||||
int timeout; | int timeout; | ||||
u_int saved_cnt; | u_int saved_cnt; | ||||
sbintime_t sbt; | |||||
/* | /* | ||||
* timeout is in ms. 0 indicates infinite wait. | * time_ms is in ms, 0 indicates infinite wait. | ||||
* Convert to ticks or 500us units depending on | * Convert to sbintime_t or 500us units depending on | ||||
* our sleep mode. | * our sleep mode. | ||||
*/ | */ | ||||
if (sleep_ok != 0) { | if (sleep_ok != 0) { | ||||
timeout = (time_ms * hz) / 1000; | sbt = SBT_1MS * time_ms; | ||||
/* Set timeout as well so final timeout check works. */ | |||||
timeout = time_ms; | |||||
} else { | } else { | ||||
timeout = time_ms * 2; | timeout = time_ms * 2; | ||||
} | } | ||||
req->state |= REQ_STATE_NEED_WAKEUP; | req->state |= REQ_STATE_NEED_WAKEUP; | ||||
mask &= ~REQ_STATE_NEED_WAKEUP; | mask &= ~REQ_STATE_NEED_WAKEUP; | ||||
saved_cnt = mpt->reset_cnt; | saved_cnt = mpt->reset_cnt; | ||||
while ((req->state & mask) != state && mpt->reset_cnt == saved_cnt) { | while ((req->state & mask) != state && mpt->reset_cnt == saved_cnt) { | ||||
if (sleep_ok != 0) { | if (sleep_ok != 0) { | ||||
error = mpt_sleep(mpt, req, PUSER, "mptreq", timeout); | if (mpt_sleep(mpt, req, PUSER, "mptreq", sbt) == | ||||
if (error == EWOULDBLOCK) { | EWOULDBLOCK) { | ||||
timeout = 0; | timeout = 0; | ||||
break; | break; | ||||
} | } | ||||
} else { | } else { | ||||
if (time_ms != 0 && --timeout == 0) { | if (time_ms != 0 && --timeout == 0) { | ||||
break; | break; | ||||
} | } | ||||
DELAY(500); | DELAY(500); | ||||
▲ Show 20 Lines • Show All 1,797 Lines • Show Last 20 Lines |