From f4636a7b2ab8288466b83a8459d47c43143a70dc Mon Sep 17 00:00:00 2001 From: Piotr Sawicki Date: Tue, 10 May 2011 23:50:32 +0000 Subject: isci: unify request start handlers Unify the implementation in scic_sds_request_start and kill the state handler. Reported-by: Christoph Hellwig Signed-off-by: Piotr Sawicki [remove scic_sds_request_constructed_state_start_handler] Signed-off-by: Dan Williams --- drivers/scsi/isci/remote_device.c | 6 +- drivers/scsi/isci/request.c | 156 +++++++++++++++++--------------------- drivers/scsi/isci/request.h | 6 -- 3 files changed, 74 insertions(+), 94 deletions(-) diff --git a/drivers/scsi/isci/remote_device.c b/drivers/scsi/isci/remote_device.c index 0bb639dfbada..606ee2be154e 100644 --- a/drivers/scsi/isci/remote_device.c +++ b/drivers/scsi/isci/remote_device.c @@ -515,7 +515,7 @@ enum sci_status scic_sds_remote_device_start_io(struct scic_sds_controller *scic if (status != SCI_SUCCESS) break; - status = sci_req->state_handlers->start_handler(sci_req); + status = scic_sds_request_start(sci_req); if (status != SCI_SUCCESS) break; @@ -540,7 +540,7 @@ enum sci_status scic_sds_remote_device_start_io(struct scic_sds_controller *scic if (status != SCI_SUCCESS) break; - status = sci_req->state_handlers->start_handler(sci_req); + status = scic_sds_request_start(sci_req); } else return SCI_FAILURE_INVALID_STATE; break; @@ -709,7 +709,7 @@ enum sci_status scic_sds_remote_device_start_task(struct scic_sds_controller *sc if (status != SCI_SUCCESS) goto out; - status = sci_req->state_handlers->start_handler(sci_req); + status = scic_sds_request_start(sci_req); if (status != SCI_SUCCESS) goto out; diff --git a/drivers/scsi/isci/request.c b/drivers/scsi/isci/request.c index 69688636347e..41a418d8b337 100644 --- a/drivers/scsi/isci/request.c +++ b/drivers/scsi/isci/request.c @@ -757,23 +757,80 @@ static u32 sci_req_tx_bytes(struct scic_sds_request *sci_req) return ret_val; } -enum sci_status -scic_sds_request_start(struct scic_sds_request *request) +enum sci_status scic_sds_request_start(struct scic_sds_request *sci_req) { - if (request->device_sequence != - scic_sds_remote_device_get_sequence(request->target_device)) + struct scic_sds_controller *scic = sci_req->owning_controller; + struct scu_task_context *task_context; + enum sci_base_request_states state; + + if (sci_req->device_sequence != + scic_sds_remote_device_get_sequence(sci_req->target_device)) return SCI_FAILURE; - if (request->state_handlers->start_handler) - return request->state_handlers->start_handler(request); + state = sci_req->state_machine.current_state_id; + if (state != SCI_BASE_REQUEST_STATE_CONSTRUCTED) { + dev_warn(scic_to_dev(scic), + "%s: SCIC IO Request requested to start while in wrong " + "state %d\n", __func__, state); + return SCI_FAILURE_INVALID_STATE; + } - dev_warn(scic_to_dev(request->owning_controller), - "%s: SCIC IO Request requested to start while in wrong " - "state %d\n", - __func__, - sci_base_state_machine_get_state(&request->state_machine)); + /* if necessary, allocate a TCi for the io request object and then will, + * if necessary, copy the constructed TC data into the actual TC buffer. + * If everything is successful the post context field is updated with + * the TCi so the controller can post the request to the hardware. + */ + if (sci_req->io_tag == SCI_CONTROLLER_INVALID_IO_TAG) + sci_req->io_tag = scic_controller_allocate_io_tag(scic); - return SCI_FAILURE_INVALID_STATE; + /* Record the IO Tag in the request */ + if (sci_req->io_tag != SCI_CONTROLLER_INVALID_IO_TAG) { + task_context = sci_req->task_context_buffer; + + task_context->task_index = scic_sds_io_tag_get_index(sci_req->io_tag); + + switch (task_context->protocol_type) { + case SCU_TASK_CONTEXT_PROTOCOL_SMP: + case SCU_TASK_CONTEXT_PROTOCOL_SSP: + /* SSP/SMP Frame */ + task_context->type.ssp.tag = sci_req->io_tag; + task_context->type.ssp.target_port_transfer_tag = + 0xFFFF; + break; + + case SCU_TASK_CONTEXT_PROTOCOL_STP: + /* STP/SATA Frame + * task_context->type.stp.ncq_tag = sci_req->ncq_tag; + */ + break; + + case SCU_TASK_CONTEXT_PROTOCOL_NONE: + /* / @todo When do we set no protocol type? */ + break; + + default: + /* This should never happen since we build the IO + * requests */ + break; + } + + /* + * Check to see if we need to copy the task context buffer + * or have been building into the task context buffer */ + if (sci_req->was_tag_assigned_by_user == false) + scic_sds_controller_copy_task_context(scic, sci_req); + + /* Add to the post_context the io tag value */ + sci_req->post_context |= scic_sds_io_tag_get_index(sci_req->io_tag); + + /* Everything is good go ahead and change state */ + sci_base_state_machine_change_state(&sci_req->state_machine, + SCI_BASE_REQUEST_STATE_STARTED); + + return SCI_SUCCESS; + } + + return SCI_FAILURE_INSUFFICIENT_RESOURCES; } enum sci_status @@ -903,75 +960,6 @@ static void scic_sds_io_request_copy_response(struct scic_sds_request *sci_req) memcpy(resp_buf, ssp_response->resp_data, len); } -/* - * This method implements the action taken when a constructed - * SCIC_SDS_IO_REQUEST_T object receives a scic_sds_request_start() request. - * This method will, if necessary, allocate a TCi for the io request object and - * then will, if necessary, copy the constructed TC data into the actual TC - * buffer. If everything is successful the post context field is updated with - * the TCi so the controller can post the request to the hardware. enum sci_status - * SCI_SUCCESS SCI_FAILURE_INSUFFICIENT_RESOURCES - */ -static enum sci_status scic_sds_request_constructed_state_start_handler( - struct scic_sds_request *request) -{ - struct scu_task_context *task_context; - - if (request->io_tag == SCI_CONTROLLER_INVALID_IO_TAG) { - request->io_tag = - scic_controller_allocate_io_tag(request->owning_controller); - } - - /* Record the IO Tag in the request */ - if (request->io_tag != SCI_CONTROLLER_INVALID_IO_TAG) { - task_context = request->task_context_buffer; - - task_context->task_index = scic_sds_io_tag_get_index(request->io_tag); - - switch (task_context->protocol_type) { - case SCU_TASK_CONTEXT_PROTOCOL_SMP: - case SCU_TASK_CONTEXT_PROTOCOL_SSP: - /* SSP/SMP Frame */ - task_context->type.ssp.tag = request->io_tag; - task_context->type.ssp.target_port_transfer_tag = 0xFFFF; - break; - - case SCU_TASK_CONTEXT_PROTOCOL_STP: - /* - * STP/SATA Frame - * task_context->type.stp.ncq_tag = request->ncq_tag; */ - break; - - case SCU_TASK_CONTEXT_PROTOCOL_NONE: - /* / @todo When do we set no protocol type? */ - break; - - default: - /* This should never happen since we build the IO requests */ - break; - } - - /* - * Check to see if we need to copy the task context buffer - * or have been building into the task context buffer */ - if (request->was_tag_assigned_by_user == false) { - scic_sds_controller_copy_task_context( - request->owning_controller, request); - } - - /* Add to the post_context the io tag value */ - request->post_context |= scic_sds_io_tag_get_index(request->io_tag); - - /* Everything is good go ahead and change state */ - sci_base_state_machine_change_state(&request->state_machine, - SCI_BASE_REQUEST_STATE_STARTED); - - return SCI_SUCCESS; - } - - return SCI_FAILURE_INSUFFICIENT_RESOURCES; -} - /* * scic_sds_request_started_state_tc_completion_handler() - This method process * TC (task context) completions for normal IO request (i.e. Task/Abort @@ -2529,10 +2517,8 @@ static enum sci_status scic_sds_stp_request_soft_reset_await_d2h_frame_handler( } static const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table[] = { - [SCI_BASE_REQUEST_STATE_INITIAL] = { }, - [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = { - .start_handler = scic_sds_request_constructed_state_start_handler, - }, + [SCI_BASE_REQUEST_STATE_INITIAL] = {}, + [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {}, [SCI_BASE_REQUEST_STATE_STARTED] = { .tc_completion_handler = scic_sds_request_started_state_tc_completion_handler, .frame_handler = scic_sds_request_started_state_frame_handler, diff --git a/drivers/scsi/isci/request.h b/drivers/scsi/isci/request.h index b17336952314..bf8ac1860850 100644 --- a/drivers/scsi/isci/request.h +++ b/drivers/scsi/isci/request.h @@ -438,12 +438,6 @@ typedef enum sci_status (*scic_sds_io_request_task_completion_handler_t) * */ struct scic_sds_io_request_state_handler { - /** - * The start_handler specifies the method invoked when a user attempts to - * start a request. - */ - scic_sds_io_request_handler_t start_handler; - /** * The complete_handler specifies the method invoked when a user attempts to * complete a request. -- cgit v1.2.3