Switch from timeout(9) to callout(9). In addition, do not teardown the

IRQ handler while resetting the controller and add some missing teardown
actions in detach.

Reviewed by:	delphij
This commit is contained in:
John Baldwin 2014-09-22 20:38:01 +00:00
parent e444e04b67
commit 166a4e4701
6 changed files with 27 additions and 21 deletions

View File

@ -198,6 +198,7 @@ tws_attach(device_t dev)
mtx_init( &sc->sim_lock, "tws_sim_lock", NULL, MTX_DEF);
mtx_init( &sc->gen_lock, "tws_gen_lock", NULL, MTX_DEF);
mtx_init( &sc->io_lock, "tws_io_lock", NULL, MTX_DEF | MTX_RECURSE);
callout_init(&sc->stats_timer, CALLOUT_MPSAFE);
if ( tws_init_trace_q(sc) == FAILURE )
printf("trace init failure\n");
@ -408,11 +409,20 @@ tws_detach(device_t dev)
TWS_TRACE(sc, "bus release mem resource", 0, sc->reg_res_id);
}
for ( i=0; i< tws_queue_depth; i++) {
if (sc->reqs[i].dma_map)
bus_dmamap_destroy(sc->data_tag, sc->reqs[i].dma_map);
callout_drain(&sc->reqs[i].timeout);
}
callout_drain(&sc->stats_timer);
free(sc->reqs, M_TWS);
free(sc->sense_bufs, M_TWS);
free(sc->scan_ccb, M_TWS);
if (sc->ioctl_data_mem)
bus_dmamem_free(sc->data_tag, sc->ioctl_data_mem, sc->ioctl_data_map);
if (sc->data_tag)
bus_dma_tag_destroy(sc->data_tag);
free(sc->aen_q.q, M_TWS);
free(sc->trace_q.q, M_TWS);
mtx_destroy(&sc->q_lock);
@ -709,7 +719,7 @@ tws_init_reqs(struct tws_softc *sc, u_int32_t dma_mem_size)
sc->reqs[i].cmd_pkt->hdr.header_desc.size_header = 128;
callout_handle_init(&sc->reqs[i].thandle);
callout_init(&sc->reqs[i].timeout, CALLOUT_MPSAFE);
sc->reqs[i].state = TWS_REQ_STATE_FREE;
if ( i >= TWS_RESERVED_REQS )
tws_q_insert_tail(sc, &sc->reqs[i], TWS_FREE_Q);
@ -859,7 +869,7 @@ tws_get_request(struct tws_softc *sc, u_int16_t type)
r->error_code = TWS_REQ_RET_INVALID;
r->cb = NULL;
r->ccb_ptr = NULL;
r->thandle.callout = NULL;
callout_stop(&r->timeout);
r->next = r->prev = NULL;
r->state = ((type == TWS_REQ_TYPE_SCSI_IO) ? TWS_REQ_STATE_TRAN : TWS_REQ_STATE_BUSY);

View File

@ -268,4 +268,5 @@ struct tws_softc {
union ccb *scan_ccb; /* pointer to a ccb */
struct tws_request *q_head[TWS_MAX_QS]; /* head pointers to q's */
struct tws_request *q_tail[TWS_MAX_QS]; /* tail pointers to q's */
struct callout stats_timer;
};

View File

@ -341,7 +341,7 @@ tws_scsi_complete(struct tws_request *req)
tws_q_remove_request(sc, req, TWS_BUSY_Q);
mtx_unlock(&sc->q_lock);
untimeout(tws_timeout, req, req->thandle);
callout_stop(&req->timeout);
tws_unmap_request(req->sc, req);
@ -362,7 +362,7 @@ tws_getset_param_complete(struct tws_request *req)
TWS_TRACE_DEBUG(sc, "getset complete", req, req->request_id);
untimeout(tws_timeout, req, req->thandle);
callout_stop(&req->timeout);
tws_unmap_request(sc, req);
free(req->data, M_TWS);
@ -380,7 +380,7 @@ tws_aen_complete(struct tws_request *req)
TWS_TRACE_DEBUG(sc, "aen complete", 0, req->request_id);
untimeout(tws_timeout, req, req->thandle);
callout_stop(&req->timeout);
tws_unmap_request(sc, req);
sense = (struct tws_command_header *)req->data;
@ -454,7 +454,7 @@ tws_cmd_complete(struct tws_request *req)
{
struct tws_softc *sc = req->sc;
untimeout(tws_timeout, req, req->thandle);
callout_stop(&req->timeout);
tws_unmap_request(sc, req);
}
@ -561,7 +561,7 @@ tws_scsi_err_complete(struct tws_request *req, struct tws_command_header *hdr)
xpt_done(ccb);
mtx_unlock(&sc->sim_lock);
untimeout(tws_timeout, req, req->thandle);
callout_stop(&req->timeout);
tws_unmap_request(req->sc, req);
mtx_lock(&sc->q_lock);
tws_q_remove_request(sc, req, TWS_BUSY_Q);
@ -591,7 +591,7 @@ tws_drain_busy_queue(struct tws_softc *sc)
mtx_unlock(&sc->q_lock);
while ( req ) {
TWS_TRACE_DEBUG(sc, "moved to TWS_COMPLETE_Q", 0, req->request_id);
untimeout(tws_timeout, req, req->thandle);
callout_stop(&req->timeout);
req->error_code = TWS_REQ_RET_RESET;
ccb = (union ccb *)(req->ccb_ptr);
@ -622,7 +622,7 @@ tws_drain_reserved_reqs(struct tws_softc *sc)
r = &sc->reqs[TWS_REQ_TYPE_AEN_FETCH];
if ( r->state != TWS_REQ_STATE_FREE ) {
TWS_TRACE_DEBUG(sc, "reset aen req", 0, 0);
untimeout(tws_timeout, r, r->thandle);
callout_stop(&r->timeout);
tws_unmap_request(sc, r);
free(r->data, M_TWS);
r->state = TWS_REQ_STATE_FREE;
@ -638,7 +638,7 @@ tws_drain_reserved_reqs(struct tws_softc *sc)
r = &sc->reqs[TWS_REQ_TYPE_GETSET_PARAM];
if ( r->state != TWS_REQ_STATE_FREE ) {
TWS_TRACE_DEBUG(sc, "reset setparam req", 0, 0);
untimeout(tws_timeout, r, r->thandle);
callout_stop(&r->timeout);
tws_unmap_request(sc, r);
free(r->data, M_TWS);
r->state = TWS_REQ_STATE_FREE;
@ -747,7 +747,7 @@ tws_execute_scsi(struct tws_softc *sc, union ccb *ccb)
* and submit the I/O.
*/
sc->stats.scsi_ios++;
req->thandle = timeout(tws_timeout, req, (ccb_h->timeout * hz)/1000);
callout_reset(&req->timeout, (ccb_h->timeout * hz) / 1000, tws_timeout, req);
error = tws_map_request(sc, req);
return(error);
}
@ -785,7 +785,7 @@ tws_send_scsi_cmd(struct tws_softc *sc, int cmd)
bzero(req->data, TWS_SECTOR_SIZE);
req->flags = TWS_DIR_IN;
req->thandle = timeout(tws_timeout, req, (TWS_IO_TIMEOUT * hz));
callout_reset(&req->timeout, (TWS_IO_TIMEOUT * hz), tws_timeout, req);
error = tws_map_request(sc, req);
return(error);
@ -832,7 +832,7 @@ tws_set_param(struct tws_softc *sc, u_int32_t table_id, u_int32_t param_id,
param->parameter_size_bytes = (u_int16_t)param_size;
memcpy(param->data, data, param_size);
req->thandle = timeout(tws_timeout, req, (TWS_IOCTL_TIMEOUT * hz));
callout_reset(&req->timeout, (TWS_IOCTL_TIMEOUT * hz), tws_timeout, req);
error = tws_map_request(sc, req);
return(error);
@ -1168,7 +1168,6 @@ tws_timeout(void *arg)
return;
}
tws_teardown_intr(sc);
xpt_freeze_simq(sc->sim, 1);
tws_send_event(sc, TWS_RESET_START);
@ -1191,7 +1190,6 @@ tws_timeout(void *arg)
mtx_unlock(&sc->gen_lock);
xpt_release_simq(sc->sim, 1);
tws_setup_intr(sc, sc->irqs);
}
void
@ -1205,7 +1203,6 @@ tws_reset(void *arg)
return;
}
tws_teardown_intr(sc);
xpt_freeze_simq(sc->sim, 1);
tws_send_event(sc, TWS_RESET_START);
@ -1222,7 +1219,6 @@ tws_reset(void *arg)
mtx_unlock(&sc->gen_lock);
xpt_release_simq(sc->sim, 1);
tws_setup_intr(sc, sc->irqs);
}
static void

View File

@ -161,7 +161,7 @@ tws_init_connect(struct tws_softc *sc, u_int16_t mcreadits )
req->error_code = TWS_REQ_RET_INVALID;
req->cb = NULL;
req->ccb_ptr = NULL;
req->thandle.callout = NULL;
callout_stop(&req->timeout);
req->next = req->prev = NULL;
req->state = TWS_REQ_STATE_BUSY;
#endif // 0

View File

@ -410,7 +410,7 @@ struct tws_request {
void (*cb)(struct tws_request *); /* callback func */
bus_dmamap_t dma_map; /* dma map */
union ccb *ccb_ptr; /* pointer to ccb */
struct callout_handle thandle; /* handle to req timeout */
struct callout timeout; /* request timeout timer */
struct tws_softc *sc; /* pointer back to ctlr softc */
struct tws_request *next; /* pointer to next request */

View File

@ -395,7 +395,6 @@ tws_print_stats(void *arg)
, sc->stats.num_intrs);
TWS_TRACE(sc, "reqs(ioctls, scsi)", sc->stats.ioctls
, sc->stats.scsi_ios);
timeout(tws_print_stats, sc, 300*hz);
callout_reset(&sc->stats_timer, 300 * hz, tws_print_stats, sc);
}
/* --------------------- misc service end --------------------- */