isci: Intel(R) C600 Series Chipset Storage Control Unit Driver
[platform/adaptation/renesas_rcar/renesas_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 /**
57  * This file contains the task management substate handlers for the
58  *    SCIC_SDS_IO_REQUEST object.
59  *
60  *
61  */
62
63 #include "intel_sas.h"
64 #include "sci_environment.h"
65 #include "scic_sds_request.h"
66 #include "scic_controller.h"
67 #include "scic_sds_controller.h"
68 #include "scu_completion_codes.h"
69 #include "scu_task_context.h"
70
71 /**
72  * This method processes the completions transport layer (TL) status to
73  *    determine if the RAW task management frame was sent successfully. If the
74  *    raw frame was sent successfully, then the state for the task request
75  *    transitions to waiting for a response frame.
76  * @this_request: This parameter specifies the request for which the TC
77  *    completion was received.
78  * @completion_code: This parameter indicates the completion status information
79  *    for the TC.
80  *
81  * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
82  * this method always returns success.
83  */
84 static enum sci_status scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler(
85         struct scic_sds_request *this_request,
86         u32 completion_code)
87 {
88         switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
89         case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
90                 scic_sds_request_set_status(
91                         this_request, SCU_TASK_DONE_GOOD, SCI_SUCCESS
92                         );
93
94                 sci_base_state_machine_change_state(
95                         &this_request->started_substate_machine,
96                         SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
97                         );
98                 break;
99
100         case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
101                 /*
102                  * Currently, the decision is to simply allow the task request to
103                  * timeout if the task IU wasn't received successfully.
104                  * There is a potential for receiving multiple task responses if we
105                  * decide to send the task IU again. */
106                 dev_warn(scic_to_dev(this_request->owning_controller),
107                          "%s: TaskRequest:0x%p CompletionCode:%x - "
108                          "ACK/NAK timeout\n",
109                          __func__,
110                          this_request,
111                          completion_code);
112
113                 sci_base_state_machine_change_state(
114                         &this_request->started_substate_machine,
115                         SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
116                         );
117                 break;
118
119         default:
120                 /*
121                  * All other completion status cause the IO to be complete.  If a NAK
122                  * was received, then it is up to the user to retry the request. */
123                 scic_sds_request_set_status(
124                         this_request,
125                         SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
126                         SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
127                         );
128
129                 sci_base_state_machine_change_state(
130                         &this_request->parent.state_machine,
131                         SCI_BASE_REQUEST_STATE_COMPLETED
132                         );
133                 break;
134         }
135
136         return SCI_SUCCESS;
137 }
138
139 /**
140  * This method is responsible for processing a terminate/abort request for this
141  *    TC while the request is waiting for the task management response
142  *    unsolicited frame.
143  * @this_request: This parameter specifies the request for which the
144  *    termination was requested.
145  *
146  * This method returns an indication as to whether the abort request was
147  * successfully handled. need to update to ensure the received UF doesn't cause
148  * damage to subsequent requests (i.e. put the extended tag in a holding
149  * pattern for this particular device).
150  */
151 static enum sci_status scic_sds_ssp_task_request_await_tc_response_abort_handler(
152         struct sci_base_request *request)
153 {
154         struct scic_sds_request *this_request = (struct scic_sds_request *)request;
155
156         sci_base_state_machine_change_state(
157                 &this_request->parent.state_machine,
158                 SCI_BASE_REQUEST_STATE_ABORTING
159                 );
160
161         sci_base_state_machine_change_state(
162                 &this_request->parent.state_machine,
163                 SCI_BASE_REQUEST_STATE_COMPLETED
164                 );
165
166         return SCI_SUCCESS;
167 }
168
169 /**
170  * This method processes an unsolicited frame while the task mgmt request is
171  *    waiting for a response frame.  It will copy the response data, release
172  *    the unsolicited frame, and transition the request to the
173  *    SCI_BASE_REQUEST_STATE_COMPLETED state.
174  * @this_request: This parameter specifies the request for which the
175  *    unsolicited frame was received.
176  * @frame_index: This parameter indicates the unsolicited frame index that
177  *    should contain the response.
178  *
179  * This method returns an indication of whether the TC response frame was
180  * handled successfully or not. SCI_SUCCESS Currently this value is always
181  * returned and indicates successful processing of the TC response. Should
182  * probably update to check frame type and make sure it is a response frame.
183  */
184 static enum sci_status scic_sds_ssp_task_request_await_tc_response_frame_handler(
185         struct scic_sds_request *this_request,
186         u32 frame_index)
187 {
188         scic_sds_io_request_copy_response(this_request);
189
190         sci_base_state_machine_change_state(
191                 &this_request->parent.state_machine,
192                 SCI_BASE_REQUEST_STATE_COMPLETED
193                 );
194
195         scic_sds_controller_release_frame(
196                 this_request->owning_controller, frame_index
197                 );
198
199         return SCI_SUCCESS;
200 }
201
202 const struct scic_sds_io_request_state_handler scic_sds_ssp_task_request_started_substate_handler_table[] = {
203         [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION] = {
204                 .parent.start_handler    = scic_sds_request_default_start_handler,
205                 .parent.abort_handler    = scic_sds_request_started_state_abort_handler,
206                 .parent.complete_handler = scic_sds_request_default_complete_handler,
207                 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
208                 .tc_completion_handler   = scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler,
209                 .event_handler           = scic_sds_request_default_event_handler,
210                 .frame_handler           = scic_sds_request_default_frame_handler,
211         },
212         [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE] = {
213                 .parent.start_handler    = scic_sds_request_default_start_handler,
214                 .parent.abort_handler    = scic_sds_ssp_task_request_await_tc_response_abort_handler,
215                 .parent.complete_handler = scic_sds_request_default_complete_handler,
216                 .parent.destruct_handler = scic_sds_request_default_destruct_handler,
217                 .tc_completion_handler   = scic_sds_request_default_tc_completion_handler,
218                 .event_handler           = scic_sds_request_default_event_handler,
219                 .frame_handler           = scic_sds_ssp_task_request_await_tc_response_frame_handler,
220         }
221 };
222
223 /*
224  * This file is provided under a dual BSD/GPLv2 license.  When using or
225  * redistributing this file, you may do so under either license.
226  *
227  * GPL LICENSE SUMMARY
228  *
229  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
230  *
231  * This program is free software; you can redistribute it and/or modify
232  * it under the terms of version 2 of the GNU General Public License as
233  * published by the Free Software Foundation.
234  *
235  * This program is distributed in the hope that it will be useful, but
236  * WITHOUT ANY WARRANTY; without even the implied warranty of
237  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
238  * General Public License for more details.
239  *
240  * You should have received a copy of the GNU General Public License
241  * along with this program; if not, write to the Free Software
242  * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
243  * The full GNU General Public License is included in this distribution
244  * in the file called LICENSE.GPL.
245  *
246  * BSD LICENSE
247  *
248  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
249  * All rights reserved.
250  *
251  * Redistribution and use in source and binary forms, with or without
252  * modification, are permitted provided that the following conditions
253  * are met:
254  *
255  *   * Redistributions of source code must retain the above copyright
256  *     notice, this list of conditions and the following disclaimer.
257  *   * Redistributions in binary form must reproduce the above copyright
258  *     notice, this list of conditions and the following disclaimer in
259  *     the documentation and/or other materials provided with the
260  *     distribution.
261  *   * Neither the name of Intel Corporation nor the names of its
262  *     contributors may be used to endorse or promote products derived
263  *     from this software without specific prior written permission.
264  *
265  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
266  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
267  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
268  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
269  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
270  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
271  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
272  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
273  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
274  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
275  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
276  */
277
278 /**
279  * This file contains the enter/exit methods associated with each of the task
280  *    management raw request states.  For more information on the task
281  *    management request state machine please refer to scic_sds_io_request.h
282  *
283  *
284  */
285
286 #include "scic_sds_request.h"
287 #include "sci_base_state_machine.h"
288
289 /**
290  * This method performs the actions required when entering the
291  *    SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
292  *    sub-state.  This includes setting the IO request state handlers for this
293  *    sub-state.
294  * @object: This parameter specifies the request object for which the sub-state
295  *    change is occuring.
296  *
297  * none.
298  */
299 static void scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter(
300         struct sci_base_object *object)
301 {
302         struct scic_sds_request *this_request = (struct scic_sds_request *)object;
303
304         SET_STATE_HANDLER(
305                 this_request,
306                 scic_sds_ssp_task_request_started_substate_handler_table,
307                 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
308                 );
309 }
310
311 /**
312  * This method performs the actions required when entering the
313  *    SCIC_SDS_IO_REQUEST_STARTED_SUBSTATE_AWAIT_TC_RESPONSE sub-state. This
314  *    includes setting the IO request state handlers for this sub-state.
315  * @object: This parameter specifies the request object for which the sub-state
316  *    change is occuring.
317  *
318  * none.
319  */
320 static void scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter(
321         struct sci_base_object *object)
322 {
323         struct scic_sds_request *this_request = (struct scic_sds_request *)object;
324
325         SET_STATE_HANDLER(
326                 this_request,
327                 scic_sds_ssp_task_request_started_substate_handler_table,
328                 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
329                 );
330 }
331
332 const struct sci_base_state scic_sds_io_request_started_task_mgmt_substate_table[] = {
333         [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION] = {
334                 .enter_state = scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter,
335         },
336         [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE] = {
337                 .enter_state = scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter,
338         },
339 };
340