blob: 4b6317aeef7dc6a6027fca38506eaababf15d3a8 [file] [log] [blame]
Dan Williams6f231dd2011-07-02 22:56:22 -07001/*
2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
4 *
5 * GPL LICENSE SUMMARY
6 *
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of version 2 of the GNU General Public License as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
23 *
24 * BSD LICENSE
25 *
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
28 *
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
31 * are met:
32 *
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
38 * distribution.
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
42 *
43 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
44 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
45 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
46 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
47 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
48 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
49 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
50 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
51 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
52 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
53 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
54 */
55
Dan Williamscc9203b2011-05-08 17:34:44 -070056#include "host.h"
Dan Williamsf1f52e72011-05-10 02:28:45 -070057#include "request.h"
Dan Williams3bff9d52011-05-08 22:15:10 -070058#include "state_machine.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070059#include "scu_task_context.h"
Dan Williamsf1f52e72011-05-10 02:28:45 -070060#include "scu_completion_codes.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070061
62/**
63 * This method processes the completions transport layer (TL) status to
64 * determine if the RAW task management frame was sent successfully. If the
65 * raw frame was sent successfully, then the state for the task request
66 * transitions to waiting for a response frame.
Dave Jiange2023b82011-04-21 05:34:49 +000067 * @sci_req: This parameter specifies the request for which the TC
Dan Williams6f231dd2011-07-02 22:56:22 -070068 * completion was received.
69 * @completion_code: This parameter indicates the completion status information
70 * for the TC.
71 *
72 * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
73 * this method always returns success.
74 */
75static enum sci_status scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler(
Dave Jiange2023b82011-04-21 05:34:49 +000076 struct scic_sds_request *sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -070077 u32 completion_code)
78{
79 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
80 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
81 scic_sds_request_set_status(
Dave Jiange2023b82011-04-21 05:34:49 +000082 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
Dan Williams6f231dd2011-07-02 22:56:22 -070083 );
84
85 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +000086 &sci_req->started_substate_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -070087 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
88 );
89 break;
90
91 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
92 /*
93 * Currently, the decision is to simply allow the task request to
94 * timeout if the task IU wasn't received successfully.
95 * There is a potential for receiving multiple task responses if we
96 * decide to send the task IU again. */
Dave Jiange2023b82011-04-21 05:34:49 +000097 dev_warn(scic_to_dev(sci_req->owning_controller),
Dan Williams6f231dd2011-07-02 22:56:22 -070098 "%s: TaskRequest:0x%p CompletionCode:%x - "
99 "ACK/NAK timeout\n",
100 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000101 sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700102 completion_code);
103
104 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000105 &sci_req->started_substate_machine,
Dan Williams6f231dd2011-07-02 22:56:22 -0700106 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
107 );
108 break;
109
110 default:
111 /*
112 * All other completion status cause the IO to be complete. If a NAK
113 * was received, then it is up to the user to retry the request. */
114 scic_sds_request_set_status(
Dave Jiange2023b82011-04-21 05:34:49 +0000115 sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700116 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
117 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
118 );
119
Dave Jiange2023b82011-04-21 05:34:49 +0000120 sci_base_state_machine_change_state(&sci_req->state_machine,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400121 SCI_BASE_REQUEST_STATE_COMPLETED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700122 break;
123 }
124
125 return SCI_SUCCESS;
126}
127
128/**
129 * This method is responsible for processing a terminate/abort request for this
130 * TC while the request is waiting for the task management response
131 * unsolicited frame.
Dave Jiange2023b82011-04-21 05:34:49 +0000132 * @sci_req: This parameter specifies the request for which the
Dan Williams6f231dd2011-07-02 22:56:22 -0700133 * termination was requested.
134 *
135 * This method returns an indication as to whether the abort request was
136 * successfully handled. need to update to ensure the received UF doesn't cause
137 * damage to subsequent requests (i.e. put the extended tag in a holding
138 * pattern for this particular device).
139 */
140static enum sci_status scic_sds_ssp_task_request_await_tc_response_abort_handler(
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400141 struct scic_sds_request *request)
Dan Williams6f231dd2011-07-02 22:56:22 -0700142{
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400143 sci_base_state_machine_change_state(&request->state_machine,
144 SCI_BASE_REQUEST_STATE_ABORTING);
145 sci_base_state_machine_change_state(&request->state_machine,
146 SCI_BASE_REQUEST_STATE_COMPLETED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700147 return SCI_SUCCESS;
148}
149
150/**
151 * This method processes an unsolicited frame while the task mgmt request is
152 * waiting for a response frame. It will copy the response data, release
153 * the unsolicited frame, and transition the request to the
154 * SCI_BASE_REQUEST_STATE_COMPLETED state.
Dave Jiange2023b82011-04-21 05:34:49 +0000155 * @sci_req: This parameter specifies the request for which the
Dan Williams6f231dd2011-07-02 22:56:22 -0700156 * unsolicited frame was received.
157 * @frame_index: This parameter indicates the unsolicited frame index that
158 * should contain the response.
159 *
160 * This method returns an indication of whether the TC response frame was
161 * handled successfully or not. SCI_SUCCESS Currently this value is always
162 * returned and indicates successful processing of the TC response. Should
163 * probably update to check frame type and make sure it is a response frame.
164 */
165static enum sci_status scic_sds_ssp_task_request_await_tc_response_frame_handler(
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400166 struct scic_sds_request *request,
Dan Williams6f231dd2011-07-02 22:56:22 -0700167 u32 frame_index)
168{
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400169 scic_sds_io_request_copy_response(request);
Dan Williams6f231dd2011-07-02 22:56:22 -0700170
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400171 sci_base_state_machine_change_state(&request->state_machine,
172 SCI_BASE_REQUEST_STATE_COMPLETED);
173 scic_sds_controller_release_frame(request->owning_controller,
174 frame_index);
Dan Williams6f231dd2011-07-02 22:56:22 -0700175 return SCI_SUCCESS;
176}
177
Dan Williams35173d52011-03-26 16:43:01 -0700178static const struct scic_sds_io_request_state_handler scic_sds_ssp_task_request_started_substate_handler_table[] = {
Dan Williams6f231dd2011-07-02 22:56:22 -0700179 [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION] = {
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400180 .abort_handler = scic_sds_request_started_state_abort_handler,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400181 .tc_completion_handler = scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler,
Dan Williams6f231dd2011-07-02 22:56:22 -0700182 },
183 [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE] = {
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400184 .abort_handler = scic_sds_ssp_task_request_await_tc_response_abort_handler,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400185 .frame_handler = scic_sds_ssp_task_request_await_tc_response_frame_handler,
Dan Williams6f231dd2011-07-02 22:56:22 -0700186 }
187};
188
Dan Williams6f231dd2011-07-02 22:56:22 -0700189/**
190 * This method performs the actions required when entering the
191 * SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
192 * sub-state. This includes setting the IO request state handlers for this
193 * sub-state.
194 * @object: This parameter specifies the request object for which the sub-state
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000195 * change is occurring.
Dan Williams6f231dd2011-07-02 22:56:22 -0700196 *
197 * none.
198 */
199static void scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter(
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000200 void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -0700201{
Maciej Patelczyk890cae92011-04-28 22:06:31 +0000202 struct scic_sds_request *sci_req = object;
Dan Williams6f231dd2011-07-02 22:56:22 -0700203
204 SET_STATE_HANDLER(
Dave Jiange2023b82011-04-21 05:34:49 +0000205 sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700206 scic_sds_ssp_task_request_started_substate_handler_table,
207 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
208 );
209}
210
211/**
212 * This method performs the actions required when entering the
213 * SCIC_SDS_IO_REQUEST_STARTED_SUBSTATE_AWAIT_TC_RESPONSE sub-state. This
214 * includes setting the IO request state handlers for this sub-state.
215 * @object: This parameter specifies the request object for which the sub-state
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000216 * change is occurring.
Dan Williams6f231dd2011-07-02 22:56:22 -0700217 *
218 * none.
219 */
220static void scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter(
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000221 void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -0700222{
Maciej Patelczyk890cae92011-04-28 22:06:31 +0000223 struct scic_sds_request *sci_req = object;
Dan Williams6f231dd2011-07-02 22:56:22 -0700224
225 SET_STATE_HANDLER(
Dave Jiange2023b82011-04-21 05:34:49 +0000226 sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700227 scic_sds_ssp_task_request_started_substate_handler_table,
228 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
229 );
230}
231
232const struct sci_base_state scic_sds_io_request_started_task_mgmt_substate_table[] = {
233 [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION] = {
234 .enter_state = scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter,
235 },
236 [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE] = {
237 .enter_state = scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter,
238 },
239};
240