isci: kill smp_discover_response
[pandora-kernel.git] / drivers / scsi / isci / core / scic_sds_smp_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 "intel_sas.h"
57 #include "sci_base_state_machine.h"
58 #include "scic_controller.h"
59 #include "scic_sds_controller.h"
60 #include "remote_device.h"
61 #include "scic_sds_request.h"
62 #include "scic_sds_smp_request.h"
63 #include "sci_environment.h"
64 #include "sci_util.h"
65 #include "scu_completion_codes.h"
66 #include "scu_task_context.h"
67
68 static void scu_smp_request_construct_task_context(
69         struct scic_sds_request *sci_req,
70         struct smp_request *smp_request);
71
72 /**
73  *
74  *
75  * This method return the memory space required for STP PIO requests. u32
76  */
77 u32 scic_sds_smp_request_get_object_size(void)
78 {
79         return sizeof(struct scic_sds_request)
80                + sizeof(struct smp_request)
81                + sizeof(struct smp_response)
82                + sizeof(struct scu_task_context)
83                + SMP_CACHE_BYTES;
84 }
85
86 /**
87  * scic_sds_smp_request_get_command_buffer() -
88  *
89  * This macro returns the address of the smp command buffer in the smp request
90  * memory. No need to cast to SMP request type.
91  */
92 #define scic_sds_smp_request_get_command_buffer(memory) \
93         (((char *)(memory)) + sizeof(struct scic_sds_request))
94
95 /**
96  * scic_sds_smp_request_get_response_buffer() -
97  *
98  * This macro returns the address of the smp response buffer in the smp request
99  * memory.
100  */
101 #define scic_sds_smp_request_get_response_buffer(memory) \
102         (((char *)(scic_sds_smp_request_get_command_buffer(memory))) \
103          + sizeof(struct smp_request))
104
105 /**
106  * scic_sds_smp_request_get_task_context_buffer() -
107  *
108  * This macro returs the task context buffer for the SMP request.
109  */
110 #define scic_sds_smp_request_get_task_context_buffer(memory) \
111         ((struct scu_task_context *)(\
112                  ((char *)(scic_sds_smp_request_get_response_buffer(memory))) \
113                  + sizeof(struct smp_response) \
114                  ))
115
116
117
118 /**
119  * This method build the remainder of the IO request object.
120  * @sci_req: This parameter specifies the request object being constructed.
121  *
122  * The scic_sds_general_request_construct() must be called before this call is
123  * valid. none
124  */
125
126 void scic_sds_smp_request_assign_buffers(
127         struct scic_sds_request *sci_req)
128 {
129         /* Assign all of the buffer pointers */
130         sci_req->command_buffer =
131                 scic_sds_smp_request_get_command_buffer(sci_req);
132         sci_req->response_buffer =
133                 scic_sds_smp_request_get_response_buffer(sci_req);
134         sci_req->sgl_element_pair_buffer = NULL;
135
136         if (sci_req->was_tag_assigned_by_user == false) {
137                 sci_req->task_context_buffer =
138                         scic_sds_smp_request_get_task_context_buffer(sci_req);
139                 sci_req->task_context_buffer =
140                         PTR_ALIGN(sci_req->task_context_buffer, SMP_CACHE_BYTES);
141         }
142
143 }
144
145 /**
146  * This method is called by the SCI user to build an SMP pass-through IO
147  *    request.
148  * @scic_smp_request: This parameter specifies the handle to the io request
149  *    object to be built.
150  * @passthru_cb: This parameter specifies the pointer to the callback structure
151  *    that contains the function pointers
152  *
153  * - The user must have previously called scic_io_request_construct() on the
154  * supplied IO request. Indicate if the controller successfully built the IO
155  * request.
156  */
157
158 /**
159  * This method will fill in the SCU Task Context for a SMP request. The
160  *    following important settings are utilized: -# task_type ==
161  *    SCU_TASK_TYPE_SMP.  This simply indicates that a normal request type
162  *    (i.e. non-raw frame) is being utilized to perform task management. -#
163  *    control_frame == 1.  This ensures that the proper endianess is set so
164  *    that the bytes are transmitted in the right order for a smp request frame.
165  * @sci_req: This parameter specifies the smp request object being
166  *    constructed.
167  *
168  */
169 static void scu_smp_request_construct_task_context(
170         struct scic_sds_request *sds_request,
171         struct smp_request *smp_request)
172 {
173         dma_addr_t dma_addr;
174         struct scic_sds_controller *controller;
175         struct scic_sds_remote_device *sci_dev;
176         struct scic_sds_port *target_port;
177         struct scu_task_context *task_context;
178
179         /* byte swap the smp request. */
180         scic_word_copy_with_swap(sds_request->command_buffer,
181                                  (u32 *)smp_request,
182                                  sizeof(struct smp_request) / sizeof(u32));
183
184         task_context = scic_sds_request_get_task_context(sds_request);
185
186         controller = scic_sds_request_get_controller(sds_request);
187         sci_dev = scic_sds_request_get_device(sds_request);
188         target_port = scic_sds_request_get_port(sds_request);
189
190         /*
191          * Fill in the TC with the its required data
192          * 00h
193          */
194         task_context->priority = 0;
195         task_context->initiator_request = 1;
196         task_context->connection_rate =
197                 scic_remote_device_get_connection_rate(sci_dev);
198         task_context->protocol_engine_index =
199                 scic_sds_controller_get_protocol_engine_group(controller);
200         task_context->logical_port_index =
201                 scic_sds_port_get_index(target_port);
202         task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SMP;
203         task_context->abort = 0;
204         task_context->valid = SCU_TASK_CONTEXT_VALID;
205         task_context->context_type = SCU_TASK_CONTEXT_TYPE;
206
207         /* 04h */
208         task_context->remote_node_index = sci_dev->rnc.remote_node_index;
209         task_context->command_code = 0;
210         task_context->task_type = SCU_TASK_TYPE_SMP_REQUEST;
211
212         /* 08h */
213         task_context->link_layer_control = 0;
214         task_context->do_not_dma_ssp_good_response = 1;
215         task_context->strict_ordering = 0;
216         task_context->control_frame = 1;
217         task_context->timeout_enable = 0;
218         task_context->block_guard_enable = 0;
219
220         /* 0ch */
221         task_context->address_modifier = 0;
222
223         /* 10h */
224         task_context->ssp_command_iu_length =
225                 smp_request->header.request_length;
226
227         /* 14h */
228         task_context->transfer_length_bytes = 0;
229
230         /*
231          * 18h ~ 30h, protocol specific
232          * since commandIU has been build by framework at this point, we just
233          * copy the frist DWord from command IU to this location. */
234         memcpy((void *)(&task_context->type.smp),
235                sds_request->command_buffer,
236                sizeof(u32));
237
238         /*
239          * 40h
240          * "For SMP you could program it to zero. We would prefer that way
241          * so that done code will be consistent." - Venki
242          */
243         task_context->task_phase = 0;
244
245         if (sds_request->was_tag_assigned_by_user) {
246                 /*
247                  * Build the task context now since we have already read
248                  * the data
249                  */
250                 sds_request->post_context =
251                         (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
252                          (scic_sds_controller_get_protocol_engine_group(
253                                                         controller) <<
254                           SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
255                          (scic_sds_port_get_index(target_port) <<
256                           SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
257                          scic_sds_io_tag_get_index(sds_request->io_tag));
258         } else {
259                 /*
260                  * Build the task context now since we have already read
261                  * the data.
262                  * I/O tag index is not assigned because we have to wait
263                  * until we get a TCi.
264                  */
265                 sds_request->post_context =
266                         (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
267                          (scic_sds_controller_get_protocol_engine_group(
268                                                         controller) <<
269                           SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
270                          (scic_sds_port_get_index(target_port) <<
271                           SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
272         }
273
274         /*
275          * Copy the physical address for the command buffer to the SCU Task
276          * Context command buffer should not contain command header.
277          */
278         dma_addr = scic_io_request_get_dma_addr(sds_request,
279                                                 (char *)
280                                                 (sds_request->command_buffer) +
281                                                 sizeof(u32));
282
283         task_context->command_iu_upper = upper_32_bits(dma_addr);
284         task_context->command_iu_lower = lower_32_bits(dma_addr);
285
286         /* SMP response comes as UF, so no need to set response IU address. */
287         task_context->response_iu_upper = 0;
288         task_context->response_iu_lower = 0;
289 }
290
291 /**
292  * This method processes an unsolicited frame while the SMP request is waiting
293  *    for a response frame.  It will copy the response data, release the
294  *    unsolicited frame, and transition the request to the
295  *    SCI_BASE_REQUEST_STATE_COMPLETED state.
296  * @sci_req: This parameter specifies the request for which the
297  *    unsolicited frame was received.
298  * @frame_index: This parameter indicates the unsolicited frame index that
299  *    should contain the response.
300  *
301  * This method returns an indication of whether the response frame was handled
302  * successfully or not. SCI_SUCCESS Currently this value is always returned and
303  * indicates successful processing of the TC response.
304  */
305 static enum sci_status scic_sds_smp_request_await_response_frame_handler(
306         struct scic_sds_request *sci_req,
307         u32 frame_index)
308 {
309         enum sci_status status;
310         void *frame_header;
311         struct smp_response_header *rsp_hdr;
312         u8 *user_smp_buffer = sci_req->response_buffer;
313
314         status = scic_sds_unsolicited_frame_control_get_header(
315                 &(scic_sds_request_get_controller(sci_req)->uf_control),
316                 frame_index,
317                 &frame_header
318                 );
319
320         /* byte swap the header. */
321         scic_word_copy_with_swap(
322                 (u32 *)user_smp_buffer,
323                 frame_header,
324                 sizeof(struct smp_response_header) / sizeof(u32)
325                 );
326         rsp_hdr = (struct smp_response_header *)user_smp_buffer;
327
328         if (rsp_hdr->smp_frame_type == SMP_FRAME_TYPE_RESPONSE) {
329                 void *smp_response_buffer;
330
331                 status = scic_sds_unsolicited_frame_control_get_buffer(
332                         &(scic_sds_request_get_controller(sci_req)->uf_control),
333                         frame_index,
334                         &smp_response_buffer
335                         );
336
337                 scic_word_copy_with_swap(
338                         (u32 *)(user_smp_buffer + sizeof(struct smp_response_header)),
339                         smp_response_buffer,
340                         sizeof(union smp_response_body) / sizeof(u32)
341                         );
342                 /*
343                  * Don't need to copy to user space. User instead will refer to
344                  * core request's response buffer. */
345
346                 /*
347                  * copy the smp response to framework smp request's response buffer.
348                  * scic_sds_smp_request_copy_response(sci_req); */
349
350                 scic_sds_request_set_status(
351                         sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
352                         );
353
354                 sci_base_state_machine_change_state(
355                         &sci_req->started_substate_machine,
356                         SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION
357                         );
358         } else {
359                 /* This was not a response frame why did it get forwarded? */
360                 dev_err(scic_to_dev(sci_req->owning_controller),
361                         "%s: SCIC SMP Request 0x%p received unexpected frame "
362                         "%d type 0x%02x\n",
363                         __func__,
364                         sci_req,
365                         frame_index,
366                         rsp_hdr->smp_frame_type);
367
368                 scic_sds_request_set_status(
369                         sci_req,
370                         SCU_TASK_DONE_SMP_FRM_TYPE_ERR,
371                         SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
372                         );
373
374                 sci_base_state_machine_change_state(
375                         &sci_req->state_machine,
376                         SCI_BASE_REQUEST_STATE_COMPLETED
377                         );
378         }
379
380         scic_sds_controller_release_frame(
381                 sci_req->owning_controller, frame_index
382                 );
383
384         return SCI_SUCCESS;
385 }
386
387
388 /**
389  * This method processes an abnormal TC completion while the SMP request is
390  *    waiting for a response frame.  It decides what happened to the IO based
391  *    on TC completion status.
392  * @sci_req: This parameter specifies the request for which the TC
393  *    completion was received.
394  * @completion_code: This parameter indicates the completion status information
395  *    for the TC.
396  *
397  * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
398  * this method always returns success.
399  */
400 static enum sci_status scic_sds_smp_request_await_response_tc_completion_handler(
401         struct scic_sds_request *sci_req,
402         u32 completion_code)
403 {
404         switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
405         case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
406                 /*
407                  * In the AWAIT RESPONSE state, any TC completion is unexpected.
408                  * but if the TC has success status, we complete the IO anyway. */
409                 scic_sds_request_set_status(
410                         sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
411                         );
412
413                 sci_base_state_machine_change_state(
414                         &sci_req->state_machine,
415                         SCI_BASE_REQUEST_STATE_COMPLETED);
416                 break;
417
418         case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
419         case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
420         case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
421         case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
422                 /*
423                  * These status has been seen in a specific LSI expander, which sometimes
424                  * is not able to send smp response within 2 ms. This causes our hardware
425                  * break the connection and set TC completion with one of these SMP_XXX_XX_ERR
426                  * status. For these type of error, we ask scic user to retry the request. */
427                 scic_sds_request_set_status(
428                         sci_req, SCU_TASK_DONE_SMP_RESP_TO_ERR, SCI_FAILURE_RETRY_REQUIRED
429                         );
430
431                 sci_base_state_machine_change_state(
432                         &sci_req->state_machine,
433                         SCI_BASE_REQUEST_STATE_COMPLETED);
434                 break;
435
436         default:
437                 /*
438                  * All other completion status cause the IO to be complete.  If a NAK
439                  * was received, then it is up to the user to retry the request. */
440                 scic_sds_request_set_status(
441                         sci_req,
442                         SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
443                         SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
444                         );
445
446                 sci_base_state_machine_change_state(
447                         &sci_req->state_machine,
448                         SCI_BASE_REQUEST_STATE_COMPLETED);
449                 break;
450         }
451
452         return SCI_SUCCESS;
453 }
454
455
456 /**
457  * This method processes the completions transport layer (TL) status to
458  *    determine if the SMP request was sent successfully. If the SMP request
459  *    was sent successfully, then the state for the SMP request transits to
460  *    waiting for a response frame.
461  * @sci_req: This parameter specifies the request for which the TC
462  *    completion was received.
463  * @completion_code: This parameter indicates the completion status information
464  *    for the TC.
465  *
466  * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
467  * this method always returns success.
468  */
469 static enum sci_status scic_sds_smp_request_await_tc_completion_tc_completion_handler(
470         struct scic_sds_request *sci_req,
471         u32 completion_code)
472 {
473         switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
474         case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
475                 scic_sds_request_set_status(
476                         sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
477                         );
478
479                 sci_base_state_machine_change_state(
480                         &sci_req->state_machine,
481                         SCI_BASE_REQUEST_STATE_COMPLETED);
482                 break;
483
484         default:
485                 /*
486                  * All other completion status cause the IO to be complete.  If a NAK
487                  * was received, then it is up to the user to retry the request. */
488                 scic_sds_request_set_status(
489                         sci_req,
490                         SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
491                         SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
492                         );
493
494                 sci_base_state_machine_change_state(
495                         &sci_req->state_machine,
496                         SCI_BASE_REQUEST_STATE_COMPLETED);
497                 break;
498         }
499
500         return SCI_SUCCESS;
501 }
502
503
504 static const struct scic_sds_io_request_state_handler scic_sds_smp_request_started_substate_handler_table[] = {
505         [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = {
506                 .abort_handler          = scic_sds_request_started_state_abort_handler,
507                 .tc_completion_handler  = scic_sds_smp_request_await_response_tc_completion_handler,
508                 .frame_handler          = scic_sds_smp_request_await_response_frame_handler,
509         },
510         [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = {
511                 .abort_handler          = scic_sds_request_started_state_abort_handler,
512                 .tc_completion_handler  =  scic_sds_smp_request_await_tc_completion_tc_completion_handler,
513         }
514 };
515
516 /**
517  * This method performs the actions required when entering the
518  *    SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_RESPONSE sub-state. This
519  *    includes setting the IO request state handlers for this sub-state.
520  * @object: This parameter specifies the request object for which the sub-state
521  *    change is occuring.
522  *
523  * none.
524  */
525 static void scic_sds_smp_request_started_await_response_substate_enter(
526         struct sci_base_object *object)
527 {
528         struct scic_sds_request *sci_req = (struct scic_sds_request *)object;
529
530         SET_STATE_HANDLER(
531                 sci_req,
532                 scic_sds_smp_request_started_substate_handler_table,
533                 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE
534                 );
535 }
536
537 /**
538  * This method performs the actions required when entering the
539  *    SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION sub-state.
540  *    This includes setting the SMP request state handlers for this sub-state.
541  * @object: This parameter specifies the request object for which the sub-state
542  *    change is occuring.
543  *
544  * none.
545  */
546 static void scic_sds_smp_request_started_await_tc_completion_substate_enter(
547         struct sci_base_object *object)
548 {
549         struct scic_sds_request *sci_req = (struct scic_sds_request *)object;
550
551         SET_STATE_HANDLER(
552                 sci_req,
553                 scic_sds_smp_request_started_substate_handler_table,
554                 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION
555                 );
556 }
557
558 static const struct sci_base_state scic_sds_smp_request_started_substate_table[] = {
559         [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = {
560                 .enter_state = scic_sds_smp_request_started_await_response_substate_enter,
561         },
562         [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = {
563                 .enter_state = scic_sds_smp_request_started_await_tc_completion_substate_enter,
564         },
565 };
566
567 /**
568  * This method is called by the SCI user to build an SMP IO request.
569  *
570  * - The user must have previously called scic_io_request_construct() on the
571  * supplied IO request. Indicate if the controller successfully built the IO
572  * request. SCI_SUCCESS This value is returned if the IO request was
573  * successfully built. SCI_FAILURE_UNSUPPORTED_PROTOCOL This value is returned
574  * if the remote_device does not support the SMP protocol.
575  * SCI_FAILURE_INVALID_ASSOCIATION This value is returned if the user did not
576  * properly set the association between the SCIC IO request and the user's IO
577  * request.  Please refer to the sci_object_set_association() routine for more
578  * information.
579  */
580 enum sci_status scic_io_request_construct_smp(struct scic_sds_request *sci_req)
581 {
582         struct smp_request *smp_req = kmalloc(sizeof(*smp_req), GFP_KERNEL);
583
584         if (!smp_req)
585                 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
586
587         sci_req->protocol                     = SCIC_SMP_PROTOCOL;
588         sci_req->has_started_substate_machine = true;
589
590         /* Construct the started sub-state machine. */
591         sci_base_state_machine_construct(
592                 &sci_req->started_substate_machine,
593                 &sci_req->parent,
594                 scic_sds_smp_request_started_substate_table,
595                 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE
596                 );
597
598         /* Construct the SMP SCU Task Context */
599         memcpy(smp_req, sci_req->command_buffer, sizeof(*smp_req));
600
601         /*
602          * Look at the SMP requests' header fields; for certain SAS 1.x SMP
603          * functions under SAS 2.0, a zero request length really indicates
604          * a non-zero default length. */
605         if (smp_req->header.request_length == 0) {
606                 switch (smp_req->header.function) {
607                 case SMP_FUNCTION_DISCOVER:
608                 case SMP_FUNCTION_REPORT_PHY_ERROR_LOG:
609                 case SMP_FUNCTION_REPORT_PHY_SATA:
610                 case SMP_FUNCTION_REPORT_ROUTE_INFORMATION:
611                         smp_req->header.request_length = 2;
612                         break;
613                 case SMP_FUNCTION_CONFIGURE_ROUTE_INFORMATION:
614                 case SMP_FUNCTION_PHY_CONTROL:
615                 case SMP_FUNCTION_PHY_TEST:
616                         smp_req->header.request_length = 9;
617                         break;
618                         /* Default - zero is a valid default for 2.0. */
619                 }
620         }
621
622         scu_smp_request_construct_task_context(sci_req, smp_req);
623
624         sci_base_state_machine_change_state(&sci_req->state_machine,
625                 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
626
627         kfree(smp_req);
628
629         return SCI_SUCCESS;
630 }