diff --git a/sys/cam/cam_xpt.c b/sys/cam/cam_xpt.c index a1b3016c7695..3ce61e7f6198 100644 --- a/sys/cam/cam_xpt.c +++ b/sys/cam/cam_xpt.c @@ -3198,6 +3198,25 @@ xpt_action_default(union ccb *start_ccb) start_ccb->ccb_h.status)); } +/* + * Call the sim poll routine to allow the sim to complete + * any inflight requests, then call camisr_runqueue to + * complete any CCB that the polling completed. + */ +void +xpt_sim_poll(struct cam_sim *sim) +{ + struct mtx *mtx; + + mtx = sim->mtx; + if (mtx) + mtx_lock(mtx); + (*(sim->sim_poll))(sim); + if (mtx) + mtx_unlock(mtx); + camisr_runqueue(); +} + uint32_t xpt_poll_setup(union ccb *start_ccb) { @@ -3205,12 +3224,10 @@ xpt_poll_setup(union ccb *start_ccb) struct cam_sim *sim; struct cam_devq *devq; struct cam_ed *dev; - struct mtx *mtx; timeout = start_ccb->ccb_h.timeout * 10; sim = start_ccb->ccb_h.path->bus->sim; devq = sim->devq; - mtx = sim->mtx; dev = start_ccb->ccb_h.path->device; /* @@ -3223,12 +3240,7 @@ xpt_poll_setup(union ccb *start_ccb) (--timeout > 0)) { mtx_unlock(&devq->send_mtx); DELAY(100); - if (mtx) - mtx_lock(mtx); - (*(sim->sim_poll))(sim); - if (mtx) - mtx_unlock(mtx); - camisr_runqueue(); + xpt_sim_poll(sim); mtx_lock(&devq->send_mtx); } dev->ccbq.dev_openings++; @@ -3240,19 +3252,9 @@ xpt_poll_setup(union ccb *start_ccb) void xpt_pollwait(union ccb *start_ccb, uint32_t timeout) { - struct cam_sim *sim; - struct mtx *mtx; - - sim = start_ccb->ccb_h.path->bus->sim; - mtx = sim->mtx; while (--timeout > 0) { - if (mtx) - mtx_lock(mtx); - (*(sim->sim_poll))(sim); - if (mtx) - mtx_unlock(mtx); - camisr_runqueue(); + xpt_sim_poll(start_ccb->ccb_h.path->bus->sim); if ((start_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) break; diff --git a/sys/cam/cam_xpt.h b/sys/cam/cam_xpt.h index fb49c893d462..52af71fc44eb 100644 --- a/sys/cam/cam_xpt.h +++ b/sys/cam/cam_xpt.h @@ -148,6 +148,7 @@ void xpt_release_path(struct cam_path *path); const char * xpt_action_name(uint32_t action); void xpt_pollwait(union ccb *start_ccb, uint32_t timeout); uint32_t xpt_poll_setup(union ccb *start_ccb); +void xpt_sim_poll(struct cam_sim *sim); /* * Perform a path inquiry at the request priority. The bzero may be