blob: d4750a761c586912508b38d1c5113ef2f2b01e14 [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
Dave Jiangd20930a2011-05-04 18:07:09 -070056#include <scsi/sas.h>
Dan Williams3bff9d52011-05-08 22:15:10 -070057#include "state_machine.h"
Dan Williams88f3b622011-04-22 19:18:03 -070058#include "remote_device.h"
Dan Williamsf1f52e72011-05-10 02:28:45 -070059#include "request.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070060#include "scu_completion_codes.h"
61#include "scu_task_context.h"
Dan Williamscc9203b2011-05-08 17:34:44 -070062#include "host.h"
Dan Williams6f231dd2011-07-02 22:56:22 -070063
64static void scu_smp_request_construct_task_context(
Dave Jiange2023b82011-04-21 05:34:49 +000065 struct scic_sds_request *sci_req,
Dave Jiang2ec53eb2011-05-04 18:01:22 -070066 struct smp_req *smp_req);
Dan Williams6f231dd2011-07-02 22:56:22 -070067
Dan Williams26298262011-05-07 19:07:14 -070068void scic_sds_smp_request_assign_buffers(struct scic_sds_request *sci_req)
Dan Williams6f231dd2011-07-02 22:56:22 -070069{
Dan Williams26298262011-05-07 19:07:14 -070070 if (sci_req->was_tag_assigned_by_user == false)
71 sci_req->task_context_buffer = &sci_req->tc;
Dan Williams6f231dd2011-07-02 22:56:22 -070072}
Dan Williams6f231dd2011-07-02 22:56:22 -070073
Dave Jiang2ec53eb2011-05-04 18:01:22 -070074/*
75 * This function will fill in the SCU Task Context for a SMP request. The
Dan Williams6f231dd2011-07-02 22:56:22 -070076 * following important settings are utilized: -# task_type ==
77 * SCU_TASK_TYPE_SMP. This simply indicates that a normal request type
78 * (i.e. non-raw frame) is being utilized to perform task management. -#
79 * control_frame == 1. This ensures that the proper endianess is set so
80 * that the bytes are transmitted in the right order for a smp request frame.
Dave Jiange2023b82011-04-21 05:34:49 +000081 * @sci_req: This parameter specifies the smp request object being
Dan Williams6f231dd2011-07-02 22:56:22 -070082 * constructed.
83 *
84 */
Dave Jiang2ec53eb2011-05-04 18:01:22 -070085static void
86scu_smp_request_construct_task_context(struct scic_sds_request *sci_req,
87 struct smp_req *smp_req)
Dan Williams6f231dd2011-07-02 22:56:22 -070088{
Dave Jiang6389a772011-02-23 15:57:27 -080089 dma_addr_t dma_addr;
Dave Jiang2ec53eb2011-05-04 18:01:22 -070090 struct scic_sds_controller *scic;
Dan Williams7ab92c92011-04-19 13:48:49 -070091 struct scic_sds_remote_device *sci_dev;
Dave Jiang2ec53eb2011-05-04 18:01:22 -070092 struct scic_sds_port *sci_port;
Dan Williams6f231dd2011-07-02 22:56:22 -070093 struct scu_task_context *task_context;
Dave Jiang51a57cf2011-05-04 18:28:32 -070094 ssize_t word_cnt = sizeof(struct smp_req) / sizeof(u32);
Dan Williams6f231dd2011-07-02 22:56:22 -070095
96 /* byte swap the smp request. */
Dan Williamsb7645812011-05-08 02:35:32 -070097 sci_swab32_cpy(&sci_req->smp.cmd, smp_req,
Dave Jiang51a57cf2011-05-04 18:28:32 -070098 word_cnt);
Dan Williams6f231dd2011-07-02 22:56:22 -070099
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700100 task_context = scic_sds_request_get_task_context(sci_req);
Dan Williams6f231dd2011-07-02 22:56:22 -0700101
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700102 scic = scic_sds_request_get_controller(sci_req);
103 sci_dev = scic_sds_request_get_device(sci_req);
104 sci_port = scic_sds_request_get_port(sci_req);
Dan Williams6f231dd2011-07-02 22:56:22 -0700105
106 /*
107 * Fill in the TC with the its required data
Dave Jiang6389a772011-02-23 15:57:27 -0800108 * 00h
109 */
Dan Williams6f231dd2011-07-02 22:56:22 -0700110 task_context->priority = 0;
111 task_context->initiator_request = 1;
Dan Williams8f304c32011-04-29 13:20:30 -0700112 task_context->connection_rate = sci_dev->connection_rate;
Dan Williams6f231dd2011-07-02 22:56:22 -0700113 task_context->protocol_engine_index =
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700114 scic_sds_controller_get_protocol_engine_group(scic);
115 task_context->logical_port_index = scic_sds_port_get_index(sci_port);
Dan Williams6f231dd2011-07-02 22:56:22 -0700116 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SMP;
117 task_context->abort = 0;
118 task_context->valid = SCU_TASK_CONTEXT_VALID;
119 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
120
121 /* 04h */
Dan Williams7ab92c92011-04-19 13:48:49 -0700122 task_context->remote_node_index = sci_dev->rnc.remote_node_index;
Dan Williams6f231dd2011-07-02 22:56:22 -0700123 task_context->command_code = 0;
124 task_context->task_type = SCU_TASK_TYPE_SMP_REQUEST;
125
126 /* 08h */
127 task_context->link_layer_control = 0;
128 task_context->do_not_dma_ssp_good_response = 1;
129 task_context->strict_ordering = 0;
130 task_context->control_frame = 1;
131 task_context->timeout_enable = 0;
132 task_context->block_guard_enable = 0;
133
134 /* 0ch */
135 task_context->address_modifier = 0;
136
137 /* 10h */
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700138 task_context->ssp_command_iu_length = smp_req->req_len;
Dan Williams6f231dd2011-07-02 22:56:22 -0700139
140 /* 14h */
141 task_context->transfer_length_bytes = 0;
142
143 /*
144 * 18h ~ 30h, protocol specific
145 * since commandIU has been build by framework at this point, we just
146 * copy the frist DWord from command IU to this location. */
Dan Williamsb7645812011-05-08 02:35:32 -0700147 memcpy(&task_context->type.smp, &sci_req->smp.cmd, sizeof(u32));
Dan Williams6f231dd2011-07-02 22:56:22 -0700148
149 /*
150 * 40h
Dave Jiang6389a772011-02-23 15:57:27 -0800151 * "For SMP you could program it to zero. We would prefer that way
152 * so that done code will be consistent." - Venki
153 */
Dan Williams6f231dd2011-07-02 22:56:22 -0700154 task_context->task_phase = 0;
155
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700156 if (sci_req->was_tag_assigned_by_user) {
Dave Jiang6389a772011-02-23 15:57:27 -0800157 /*
158 * Build the task context now since we have already read
159 * the data
160 */
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700161 sci_req->post_context =
Dave Jiang6389a772011-02-23 15:57:27 -0800162 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700163 (scic_sds_controller_get_protocol_engine_group(scic) <<
Dave Jiang6389a772011-02-23 15:57:27 -0800164 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700165 (scic_sds_port_get_index(sci_port) <<
Dave Jiang6389a772011-02-23 15:57:27 -0800166 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700167 scic_sds_io_tag_get_index(sci_req->io_tag));
Dan Williams6f231dd2011-07-02 22:56:22 -0700168 } else {
Dave Jiang6389a772011-02-23 15:57:27 -0800169 /*
170 * Build the task context now since we have already read
171 * the data.
172 * I/O tag index is not assigned because we have to wait
173 * until we get a TCi.
174 */
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700175 sci_req->post_context =
Dave Jiang6389a772011-02-23 15:57:27 -0800176 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700177 (scic_sds_controller_get_protocol_engine_group(scic) <<
Dave Jiang6389a772011-02-23 15:57:27 -0800178 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700179 (scic_sds_port_get_index(sci_port) <<
Dave Jiang6389a772011-02-23 15:57:27 -0800180 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
Dan Williams6f231dd2011-07-02 22:56:22 -0700181 }
182
183 /*
Dave Jiang6389a772011-02-23 15:57:27 -0800184 * Copy the physical address for the command buffer to the SCU Task
185 * Context command buffer should not contain command header.
186 */
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700187 dma_addr = scic_io_request_get_dma_addr(sci_req,
Dan Williamsb7645812011-05-08 02:35:32 -0700188 ((char *) &sci_req->smp.cmd) +
Dave Jiang6389a772011-02-23 15:57:27 -0800189 sizeof(u32));
Dan Williams6f231dd2011-07-02 22:56:22 -0700190
Dave Jiang6389a772011-02-23 15:57:27 -0800191 task_context->command_iu_upper = upper_32_bits(dma_addr);
192 task_context->command_iu_lower = lower_32_bits(dma_addr);
Dan Williams6f231dd2011-07-02 22:56:22 -0700193
194 /* SMP response comes as UF, so no need to set response IU address. */
195 task_context->response_iu_upper = 0;
196 task_context->response_iu_lower = 0;
197}
198
Dave Jiangd20930a2011-05-04 18:07:09 -0700199/*
200 * This function processes an unsolicited frame while the SMP request is waiting
Dan Williams6f231dd2011-07-02 22:56:22 -0700201 * for a response frame. It will copy the response data, release the
202 * unsolicited frame, and transition the request to the
203 * SCI_BASE_REQUEST_STATE_COMPLETED state.
Dave Jiange2023b82011-04-21 05:34:49 +0000204 * @sci_req: This parameter specifies the request for which the
Dan Williams6f231dd2011-07-02 22:56:22 -0700205 * unsolicited frame was received.
206 * @frame_index: This parameter indicates the unsolicited frame index that
207 * should contain the response.
208 *
Dave Jiangd20930a2011-05-04 18:07:09 -0700209 * This function returns an indication of whether the response frame was handled
Dan Williams6f231dd2011-07-02 22:56:22 -0700210 * successfully or not. SCI_SUCCESS Currently this value is always returned and
211 * indicates successful processing of the TC response.
212 */
Dave Jiangd20930a2011-05-04 18:07:09 -0700213static enum sci_status
Dan Williamsb7645812011-05-08 02:35:32 -0700214scic_sds_smp_request_await_response_frame_handler(struct scic_sds_request *sci_req,
215 u32 frame_index)
Dan Williams6f231dd2011-07-02 22:56:22 -0700216{
217 enum sci_status status;
218 void *frame_header;
Dan Williamsb7645812011-05-08 02:35:32 -0700219 struct smp_resp *rsp_hdr = &sci_req->smp.rsp;
Dave Jiang51a57cf2011-05-04 18:28:32 -0700220 ssize_t word_cnt = SMP_RESP_HDR_SZ / sizeof(u32);
Dan Williams6f231dd2011-07-02 22:56:22 -0700221
222 status = scic_sds_unsolicited_frame_control_get_header(
Dave Jiange2023b82011-04-21 05:34:49 +0000223 &(scic_sds_request_get_controller(sci_req)->uf_control),
Dan Williams6f231dd2011-07-02 22:56:22 -0700224 frame_index,
Dave Jiangd20930a2011-05-04 18:07:09 -0700225 &frame_header);
Dan Williams6f231dd2011-07-02 22:56:22 -0700226
227 /* byte swap the header. */
Dan Williamsb7645812011-05-08 02:35:32 -0700228 sci_swab32_cpy(rsp_hdr, frame_header, word_cnt);
Dave Jiangd20930a2011-05-04 18:07:09 -0700229
230 if (rsp_hdr->frame_type == SMP_RESPONSE) {
231 void *smp_resp;
Dan Williams6f231dd2011-07-02 22:56:22 -0700232
233 status = scic_sds_unsolicited_frame_control_get_buffer(
Dave Jiange2023b82011-04-21 05:34:49 +0000234 &(scic_sds_request_get_controller(sci_req)->uf_control),
Dan Williams6f231dd2011-07-02 22:56:22 -0700235 frame_index,
Dave Jiangd20930a2011-05-04 18:07:09 -0700236 &smp_resp);
Dan Williams6f231dd2011-07-02 22:56:22 -0700237
Dave Jiang51a57cf2011-05-04 18:28:32 -0700238 word_cnt = (sizeof(struct smp_req) - SMP_RESP_HDR_SZ) /
239 sizeof(u32);
240
Dan Williamsb7645812011-05-08 02:35:32 -0700241 sci_swab32_cpy(((u8 *) rsp_hdr) + SMP_RESP_HDR_SZ,
Dave Jiang51a57cf2011-05-04 18:28:32 -0700242 smp_resp, word_cnt);
Dan Williams6f231dd2011-07-02 22:56:22 -0700243
244 scic_sds_request_set_status(
Dave Jiangd20930a2011-05-04 18:07:09 -0700245 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
Dan Williams6f231dd2011-07-02 22:56:22 -0700246
247 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000248 &sci_req->started_substate_machine,
Dave Jiangd20930a2011-05-04 18:07:09 -0700249 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION);
Dan Williams6f231dd2011-07-02 22:56:22 -0700250 } else {
251 /* This was not a response frame why did it get forwarded? */
Dave Jiange2023b82011-04-21 05:34:49 +0000252 dev_err(scic_to_dev(sci_req->owning_controller),
Dan Williams6f231dd2011-07-02 22:56:22 -0700253 "%s: SCIC SMP Request 0x%p received unexpected frame "
254 "%d type 0x%02x\n",
255 __func__,
Dave Jiange2023b82011-04-21 05:34:49 +0000256 sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700257 frame_index,
Dave Jiangd20930a2011-05-04 18:07:09 -0700258 rsp_hdr->frame_type);
Dan Williams6f231dd2011-07-02 22:56:22 -0700259
260 scic_sds_request_set_status(
Dave Jiange2023b82011-04-21 05:34:49 +0000261 sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700262 SCU_TASK_DONE_SMP_FRM_TYPE_ERR,
Dave Jiangd20930a2011-05-04 18:07:09 -0700263 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
Dan Williams6f231dd2011-07-02 22:56:22 -0700264
265 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000266 &sci_req->state_machine,
Dave Jiangd20930a2011-05-04 18:07:09 -0700267 SCI_BASE_REQUEST_STATE_COMPLETED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700268 }
269
Dave Jiangd20930a2011-05-04 18:07:09 -0700270 scic_sds_controller_release_frame(sci_req->owning_controller,
271 frame_index);
Dan Williams6f231dd2011-07-02 22:56:22 -0700272
273 return SCI_SUCCESS;
274}
275
276
277/**
278 * This method processes an abnormal TC completion while the SMP request is
279 * waiting for a response frame. It decides what happened to the IO based
280 * on TC completion status.
Dave Jiange2023b82011-04-21 05:34:49 +0000281 * @sci_req: This parameter specifies the request for which the TC
Dan Williams6f231dd2011-07-02 22:56:22 -0700282 * completion was received.
283 * @completion_code: This parameter indicates the completion status information
284 * for the TC.
285 *
286 * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
287 * this method always returns success.
288 */
289static enum sci_status scic_sds_smp_request_await_response_tc_completion_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000290 struct scic_sds_request *sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700291 u32 completion_code)
292{
293 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
294 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
295 /*
296 * In the AWAIT RESPONSE state, any TC completion is unexpected.
297 * but if the TC has success status, we complete the IO anyway. */
298 scic_sds_request_set_status(
Dave Jiange2023b82011-04-21 05:34:49 +0000299 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
Dan Williams6f231dd2011-07-02 22:56:22 -0700300 );
301
302 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000303 &sci_req->state_machine,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400304 SCI_BASE_REQUEST_STATE_COMPLETED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700305 break;
306
307 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
308 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
309 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
310 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
311 /*
312 * These status has been seen in a specific LSI expander, which sometimes
313 * is not able to send smp response within 2 ms. This causes our hardware
314 * break the connection and set TC completion with one of these SMP_XXX_XX_ERR
315 * status. For these type of error, we ask scic user to retry the request. */
316 scic_sds_request_set_status(
Dave Jiange2023b82011-04-21 05:34:49 +0000317 sci_req, SCU_TASK_DONE_SMP_RESP_TO_ERR, SCI_FAILURE_RETRY_REQUIRED
Dan Williams6f231dd2011-07-02 22:56:22 -0700318 );
319
320 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000321 &sci_req->state_machine,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400322 SCI_BASE_REQUEST_STATE_COMPLETED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700323 break;
324
325 default:
326 /*
327 * All other completion status cause the IO to be complete. If a NAK
328 * was received, then it is up to the user to retry the request. */
329 scic_sds_request_set_status(
Dave Jiange2023b82011-04-21 05:34:49 +0000330 sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700331 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
332 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
333 );
334
335 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000336 &sci_req->state_machine,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400337 SCI_BASE_REQUEST_STATE_COMPLETED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700338 break;
339 }
340
341 return SCI_SUCCESS;
342}
343
344
345/**
346 * This method processes the completions transport layer (TL) status to
347 * determine if the SMP request was sent successfully. If the SMP request
348 * was sent successfully, then the state for the SMP request transits to
349 * waiting for a response frame.
Dave Jiange2023b82011-04-21 05:34:49 +0000350 * @sci_req: This parameter specifies the request for which the TC
Dan Williams6f231dd2011-07-02 22:56:22 -0700351 * completion was received.
352 * @completion_code: This parameter indicates the completion status information
353 * for the TC.
354 *
355 * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
356 * this method always returns success.
357 */
358static enum sci_status scic_sds_smp_request_await_tc_completion_tc_completion_handler(
Dave Jiange2023b82011-04-21 05:34:49 +0000359 struct scic_sds_request *sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700360 u32 completion_code)
361{
362 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
363 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
364 scic_sds_request_set_status(
Dave Jiange2023b82011-04-21 05:34:49 +0000365 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
Dan Williams6f231dd2011-07-02 22:56:22 -0700366 );
367
368 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000369 &sci_req->state_machine,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400370 SCI_BASE_REQUEST_STATE_COMPLETED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700371 break;
372
373 default:
374 /*
375 * All other completion status cause the IO to be complete. If a NAK
376 * was received, then it is up to the user to retry the request. */
377 scic_sds_request_set_status(
Dave Jiange2023b82011-04-21 05:34:49 +0000378 sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700379 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
380 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
381 );
382
383 sci_base_state_machine_change_state(
Dave Jiange2023b82011-04-21 05:34:49 +0000384 &sci_req->state_machine,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400385 SCI_BASE_REQUEST_STATE_COMPLETED);
Dan Williams6f231dd2011-07-02 22:56:22 -0700386 break;
387 }
388
389 return SCI_SUCCESS;
390}
391
392
Dan Williams35173d52011-03-26 16:43:01 -0700393static const struct scic_sds_io_request_state_handler scic_sds_smp_request_started_substate_handler_table[] = {
Dan Williams6f231dd2011-07-02 22:56:22 -0700394 [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = {
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400395 .abort_handler = scic_sds_request_started_state_abort_handler,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400396 .tc_completion_handler = scic_sds_smp_request_await_response_tc_completion_handler,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400397 .frame_handler = scic_sds_smp_request_await_response_frame_handler,
Dan Williams6f231dd2011-07-02 22:56:22 -0700398 },
399 [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = {
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400400 .abort_handler = scic_sds_request_started_state_abort_handler,
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400401 .tc_completion_handler = scic_sds_smp_request_await_tc_completion_tc_completion_handler,
Dan Williams6f231dd2011-07-02 22:56:22 -0700402 }
403};
404
405/**
406 * This method performs the actions required when entering the
407 * SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_RESPONSE sub-state. This
408 * includes setting the IO request state handlers for this sub-state.
409 * @object: This parameter specifies the request object for which the sub-state
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000410 * change is occurring.
Dan Williams6f231dd2011-07-02 22:56:22 -0700411 *
412 * none.
413 */
414static void scic_sds_smp_request_started_await_response_substate_enter(
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000415 void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -0700416{
Maciej Patelczyk890cae92011-04-28 22:06:31 +0000417 struct scic_sds_request *sci_req = object;
Dan Williams6f231dd2011-07-02 22:56:22 -0700418
419 SET_STATE_HANDLER(
Dave Jiange2023b82011-04-21 05:34:49 +0000420 sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700421 scic_sds_smp_request_started_substate_handler_table,
422 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE
423 );
424}
425
426/**
427 * This method performs the actions required when entering the
428 * SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION sub-state.
429 * This includes setting the SMP request state handlers for this sub-state.
430 * @object: This parameter specifies the request object for which the sub-state
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000431 * change is occurring.
Dan Williams6f231dd2011-07-02 22:56:22 -0700432 *
433 * none.
434 */
435static void scic_sds_smp_request_started_await_tc_completion_substate_enter(
Maciej Patelczyk9a0fff72011-04-28 22:06:01 +0000436 void *object)
Dan Williams6f231dd2011-07-02 22:56:22 -0700437{
Maciej Patelczyk890cae92011-04-28 22:06:31 +0000438 struct scic_sds_request *sci_req = object;
Dan Williams6f231dd2011-07-02 22:56:22 -0700439
440 SET_STATE_HANDLER(
Dave Jiange2023b82011-04-21 05:34:49 +0000441 sci_req,
Dan Williams6f231dd2011-07-02 22:56:22 -0700442 scic_sds_smp_request_started_substate_handler_table,
443 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION
444 );
445}
446
Dan Williams35173d52011-03-26 16:43:01 -0700447static const struct sci_base_state scic_sds_smp_request_started_substate_table[] = {
Dan Williams6f231dd2011-07-02 22:56:22 -0700448 [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = {
449 .enter_state = scic_sds_smp_request_started_await_response_substate_enter,
450 },
451 [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = {
452 .enter_state = scic_sds_smp_request_started_await_tc_completion_substate_enter,
453 },
454};
455
Dan Williams35173d52011-03-26 16:43:01 -0700456/**
457 * This method is called by the SCI user to build an SMP IO request.
458 *
459 * - The user must have previously called scic_io_request_construct() on the
460 * supplied IO request. Indicate if the controller successfully built the IO
461 * request. SCI_SUCCESS This value is returned if the IO request was
462 * successfully built. SCI_FAILURE_UNSUPPORTED_PROTOCOL This value is returned
463 * if the remote_device does not support the SMP protocol.
464 * SCI_FAILURE_INVALID_ASSOCIATION This value is returned if the user did not
465 * properly set the association between the SCIC IO request and the user's IO
Maciej Patelczykbe2f41c2011-04-28 22:06:36 +0000466 * request.
Dan Williams35173d52011-03-26 16:43:01 -0700467 */
468enum sci_status scic_io_request_construct_smp(struct scic_sds_request *sci_req)
469{
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700470 struct smp_req *smp_req = kmalloc(sizeof(*smp_req), GFP_KERNEL);
Dan Williams35173d52011-03-26 16:43:01 -0700471
472 if (!smp_req)
473 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
474
475 sci_req->protocol = SCIC_SMP_PROTOCOL;
476 sci_req->has_started_substate_machine = true;
477
478 /* Construct the started sub-state machine. */
479 sci_base_state_machine_construct(
480 &sci_req->started_substate_machine,
Maciej Patelczyk890cae92011-04-28 22:06:31 +0000481 sci_req,
Dan Williams35173d52011-03-26 16:43:01 -0700482 scic_sds_smp_request_started_substate_table,
483 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE
484 );
485
486 /* Construct the SMP SCU Task Context */
Dan Williamsb7645812011-05-08 02:35:32 -0700487 memcpy(smp_req, &sci_req->smp.cmd, sizeof(*smp_req));
Dan Williams35173d52011-03-26 16:43:01 -0700488
489 /*
490 * Look at the SMP requests' header fields; for certain SAS 1.x SMP
491 * functions under SAS 2.0, a zero request length really indicates
492 * a non-zero default length. */
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700493 if (smp_req->req_len == 0) {
494 switch (smp_req->func) {
495 case SMP_DISCOVER:
496 case SMP_REPORT_PHY_ERR_LOG:
497 case SMP_REPORT_PHY_SATA:
498 case SMP_REPORT_ROUTE_INFO:
499 smp_req->req_len = 2;
Dan Williams35173d52011-03-26 16:43:01 -0700500 break;
Dave Jiang2ec53eb2011-05-04 18:01:22 -0700501 case SMP_CONF_ROUTE_INFO:
502 case SMP_PHY_CONTROL:
503 case SMP_PHY_TEST_FUNCTION:
504 smp_req->req_len = 9;
Dan Williams35173d52011-03-26 16:43:01 -0700505 break;
506 /* Default - zero is a valid default for 2.0. */
507 }
508 }
509
510 scu_smp_request_construct_task_context(sci_req, smp_req);
511
Christoph Hellwig38aa74e2011-03-28 09:21:14 -0400512 sci_base_state_machine_change_state(&sci_req->state_machine,
513 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
Dan Williams35173d52011-03-26 16:43:01 -0700514
515 kfree(smp_req);
516
517 return SCI_SUCCESS;
518}