isci: uplevel state machine
[pandora-kernel.git] / drivers / scsi / isci / core / scic_sds_ssp_request.c
1 /*
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
56 #include "host.h"
57 #include "state_machine.h"
58 #include "scic_sds_request.h"
59 #include "scu_completion_codes.h"
60 #include "scu_task_context.h"
61
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.
67  * @sci_req: This parameter specifies the request for which the TC
68  *    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  */
75 static enum sci_status scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler(
76         struct scic_sds_request *sci_req,
77         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(
82                         sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
83                         );
84
85                 sci_base_state_machine_change_state(
86                         &sci_req->started_substate_machine,
87                         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. */
97                 dev_warn(scic_to_dev(sci_req->owning_controller),
98                          "%s: TaskRequest:0x%p CompletionCode:%x - "
99                          "ACK/NAK timeout\n",
100                          __func__,
101                          sci_req,
102                          completion_code);
103
104                 sci_base_state_machine_change_state(
105                         &sci_req->started_substate_machine,
106                         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(
115                         sci_req,
116                         SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
117                         SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
118                         );
119
120                 sci_base_state_machine_change_state(&sci_req->state_machine,
121                         SCI_BASE_REQUEST_STATE_COMPLETED);
122                 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.
132  * @sci_req: This parameter specifies the request for which the
133  *    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  */
140 static enum sci_status scic_sds_ssp_task_request_await_tc_response_abort_handler(
141         struct scic_sds_request *request)
142 {
143         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);
147         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.
155  * @sci_req: This parameter specifies the request for which the
156  *    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  */
165 static enum sci_status scic_sds_ssp_task_request_await_tc_response_frame_handler(
166         struct scic_sds_request *request,
167         u32 frame_index)
168 {
169         scic_sds_io_request_copy_response(request);
170
171         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);
175         return SCI_SUCCESS;
176 }
177
178 static const struct scic_sds_io_request_state_handler scic_sds_ssp_task_request_started_substate_handler_table[] = {
179         [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION] = {
180                 .abort_handler          = scic_sds_request_started_state_abort_handler,
181                 .tc_completion_handler  = scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler,
182         },
183         [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE] = {
184                 .abort_handler          = scic_sds_ssp_task_request_await_tc_response_abort_handler,
185                 .frame_handler          = scic_sds_ssp_task_request_await_tc_response_frame_handler,
186         }
187 };
188
189 /**
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
195  *    change is occurring.
196  *
197  * none.
198  */
199 static void scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter(
200         void *object)
201 {
202         struct scic_sds_request *sci_req = object;
203
204         SET_STATE_HANDLER(
205                 sci_req,
206                 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
216  *    change is occurring.
217  *
218  * none.
219  */
220 static void scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter(
221         void *object)
222 {
223         struct scic_sds_request *sci_req = object;
224
225         SET_STATE_HANDLER(
226                 sci_req,
227                 scic_sds_ssp_task_request_started_substate_handler_table,
228                 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
229                 );
230 }
231
232 const 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