diff options
Diffstat (limited to 'sys/dev/ips/ips_commands.c')
-rw-r--r-- | sys/dev/ips/ips_commands.c | 53 |
1 files changed, 23 insertions, 30 deletions
diff --git a/sys/dev/ips/ips_commands.c b/sys/dev/ips/ips_commands.c index 8d3b367..b139287 100644 --- a/sys/dev/ips/ips_commands.c +++ b/sys/dev/ips/ips_commands.c @@ -44,9 +44,7 @@ static void ips_wakeup_callback(ips_command_t *command) status->value = command->status.value; bus_dmamap_sync(command->sc->command_dmatag, command->command_dmamap, BUS_DMASYNC_POSTWRITE); - mtx_lock(&command->sc->cmd_mtx); - wakeup(status); - mtx_unlock(&command->sc->cmd_mtx); + sema_post(&command->cmd_sema); } /* Below are a series of functions for sending an IO request * to the adapter. The flow order is: start, send, callback, finish. @@ -163,15 +161,24 @@ static int ips_send_io_request(ips_command_t *command) return 0; } -void ips_start_io_request(ips_softc_t *sc, struct bio *iobuf) +void ips_start_io_request(ips_softc_t *sc) { - if(ips_get_free_cmd(sc, ips_send_io_request, iobuf, 0)){ - device_printf(sc->dev, "no mem for command slots!\n"); - iobuf->bio_flags |= BIO_ERROR; - iobuf->bio_error = ENOMEM; - ipsd_finish(iobuf); + struct bio *iobuf; + + mtx_lock(&sc->queue_mtx); + iobuf = bioq_first(&sc->queue); + if(!iobuf) { + mtx_unlock(&sc->queue_mtx); + return; + } + + if(ips_get_free_cmd(sc, ips_send_io_request, iobuf, IPS_NOWAIT_FLAG)){ + mtx_unlock(&sc->queue_mtx); return; } + + bioq_remove(&sc->queue, iobuf); + mtx_unlock(&sc->queue_mtx); return; } @@ -236,15 +243,13 @@ static int ips_send_adapter_info_cmd(ips_command_t *command) goto exit; } command->callback = ips_wakeup_callback; - mtx_lock(&sc->cmd_mtx); bus_dmamap_load(command->data_dmatag, command->data_dmamap, command->data_buffer,IPS_ADAPTER_INFO_LEN, ips_adapter_info_callback, command, BUS_DMA_NOWAIT); if ((status->value == IPS_ERROR_STATUS) || - (msleep(status, &sc->cmd_mtx, 0, "ips", 30*hz) == EWOULDBLOCK)) + (sema_timedwait(&command->cmd_sema, 30*hz) == 0)) error = ETIMEDOUT; - mtx_unlock(&sc->cmd_mtx); if (error == 0) { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, @@ -343,14 +348,12 @@ static int ips_send_drive_info_cmd(ips_command_t *command) goto exit; } command->callback = ips_wakeup_callback; - mtx_lock(&sc->cmd_mtx); bus_dmamap_load(command->data_dmatag, command->data_dmamap, command->data_buffer,IPS_DRIVE_INFO_LEN, ips_drive_info_callback, command, BUS_DMA_NOWAIT); if ((status->value == IPS_ERROR_STATUS) || - (msleep(status, &sc->cmd_mtx, 0, "ips", 10*hz) == EWOULDBLOCK)) + (sema_timedwait(&command->cmd_sema, 10*hz) == 0)) error = ETIMEDOUT; - mtx_unlock(&sc->cmd_mtx); if (error == 0) { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, @@ -406,11 +409,9 @@ static int ips_send_flush_cache_cmd(ips_command_t *command) command_struct->id = command->id; bus_dmamap_sync(sc->command_dmatag, command->command_dmamap, BUS_DMASYNC_PREWRITE); - mtx_lock(&sc->cmd_mtx); sc->ips_issue_cmd(command); if (status->value != IPS_ERROR_STATUS) - msleep(status, &sc->cmd_mtx, 0, "flush2", 0); - mtx_unlock(&sc->cmd_mtx); + sema_wait(&command->cmd_sema); ips_insert_free_cmd(sc, command); return 0; } @@ -494,11 +495,9 @@ static int ips_send_ffdc_reset_cmd(ips_command_t *command) bus_dmamap_sync(sc->command_dmatag, command->command_dmamap, BUS_DMASYNC_PREWRITE); - mtx_lock(&sc->cmd_mtx); sc->ips_issue_cmd(command); if (status->value != IPS_ERROR_STATUS) - msleep(status, &sc->cmd_mtx, 0, "ffdc", 0); - mtx_unlock(&sc->cmd_mtx); + sema_wait(&command->cmd_sema); ips_insert_free_cmd(sc, command); return 0; } @@ -603,14 +602,12 @@ static int ips_read_nvram(ips_command_t *command){ goto exit; } command->callback = ips_write_nvram; - mtx_lock(&sc->cmd_mtx); bus_dmamap_load(command->data_dmatag, command->data_dmamap, command->data_buffer,IPS_NVRAM_PAGE_SIZE, ips_read_nvram_callback, command, BUS_DMA_NOWAIT); if ((status->value == IPS_ERROR_STATUS) || - (msleep(status, &sc->cmd_mtx, 0, "ips", 0) == EWOULDBLOCK)) + (sema_timedwait(&command->cmd_sema, 30*hz) == 0)) error = ETIMEDOUT; - mtx_unlock(&sc->cmd_mtx); if (error == 0) { bus_dmamap_sync(command->data_dmatag, command->data_dmamap, @@ -661,11 +658,9 @@ static int ips_send_config_sync_cmd(ips_command_t *command) command_struct->reserve2 = IPS_POCL; bus_dmamap_sync(sc->command_dmatag, command->command_dmamap, BUS_DMASYNC_PREWRITE); - mtx_lock(&sc->cmd_mtx); sc->ips_issue_cmd(command); if (status->value != IPS_ERROR_STATUS) - msleep(status, &sc->cmd_mtx, 0, "ipssyn", 0); - mtx_unlock(&sc->cmd_mtx); + sema_wait(&command->cmd_sema); ips_insert_free_cmd(sc, command); return 0; } @@ -684,11 +679,9 @@ static int ips_send_error_table_cmd(ips_command_t *command) command_struct->reserve2 = IPS_CSL; bus_dmamap_sync(sc->command_dmatag, command->command_dmamap, BUS_DMASYNC_PREWRITE); - mtx_lock(&sc->cmd_mtx); sc->ips_issue_cmd(command); if (status->value != IPS_ERROR_STATUS) - msleep(status, &sc->cmd_mtx, 0, "ipsetc", 0); - mtx_unlock(&sc->cmd_mtx); + sema_wait(&command->cmd_sema); ips_insert_free_cmd(sc, command); return 0; } |