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.
7 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
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.
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.
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.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
27 * All rights reserved.
29 * Redistribution and use in source and binary forms, with or without
30 * modification, are permitted provided that the following conditions
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
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.
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.
58 #include "intel_sas.h"
59 #include "scic_controller.h"
60 #include "scic_io_request.h"
61 #include "scic_sds_controller.h"
62 #include "scu_registers.h"
63 #include "scic_sds_port.h"
64 #include "remote_device.h"
65 #include "scic_sds_request.h"
66 #include "scic_sds_smp_request.h"
67 #include "scic_sds_stp_request.h"
68 #include "scic_sds_unsolicited_frame_control.h"
69 #include "sci_environment.h"
71 #include "scu_completion_codes.h"
72 #include "scu_constants.h"
73 #include "scu_task_context.h"
76 * ****************************************************************************
77 * * SCIC SDS IO REQUEST CONSTANTS
78 * **************************************************************************** */
83 * We have no timer requirements for IO requests right now
85 #define SCIC_SDS_IO_REQUEST_MINIMUM_TIMER_COUNT (0)
86 #define SCIC_SDS_IO_REQUEST_MAXIMUM_TIMER_COUNT (0)
89 * ****************************************************************************
90 * * SCIC SDS IO REQUEST MACROS
91 * **************************************************************************** */
94 * scic_ssp_io_request_get_object_size() -
96 * This macro returns the sizeof memory required to store the an SSP IO
97 * request. This does not include the size of the SGL or SCU Task Context
100 #define scic_ssp_io_request_get_object_size() \
102 sizeof(struct ssp_cmd_iu) \
103 + sizeof(struct sci_ssp_response_iu) \
107 * scic_sds_ssp_request_get_command_buffer() -
109 * This macro returns the address of the ssp command buffer in the io request
112 #define scic_sds_ssp_request_get_command_buffer(memory) \
113 ((struct ssp_cmd_iu *)(\
114 ((char *)(memory)) + sizeof(struct scic_sds_request) \
118 * scic_sds_ssp_request_get_response_buffer() -
120 * This macro returns the address of the ssp response buffer in the io request
123 #define scic_sds_ssp_request_get_response_buffer(memory) \
124 ((struct sci_ssp_response_iu *)(\
125 ((char *)(scic_sds_ssp_request_get_command_buffer(memory))) \
126 + sizeof(struct ssp_cmd_iu) \
130 * scic_sds_ssp_request_get_task_context_buffer() -
132 * This macro returns the address of the task context buffer in the io request
135 #define scic_sds_ssp_request_get_task_context_buffer(memory) \
136 ((struct scu_task_context *)(\
137 ((char *)(scic_sds_ssp_request_get_response_buffer(memory))) \
138 + sizeof(struct sci_ssp_response_iu) \
142 * scic_sds_ssp_request_get_sgl_element_buffer() -
144 * This macro returns the address of the sgl elment pairs in the io request
147 #define scic_sds_ssp_request_get_sgl_element_buffer(memory) \
148 ((struct scu_sgl_element_pair *)(\
149 ((char *)(scic_sds_ssp_request_get_task_context_buffer(memory))) \
150 + sizeof(struct scu_task_context) \
155 * scic_ssp_task_request_get_object_size() -
157 * This macro returns the sizeof of memory required to store an SSP Task
158 * request. This does not include the size of the SCU Task Context memory.
160 #define scic_ssp_task_request_get_object_size() \
162 sizeof(struct ssp_task_iu) \
163 + sizeof(struct sci_ssp_response_iu) \
167 * scic_sds_ssp_task_request_get_command_buffer() -
169 * This macro returns the address of the ssp command buffer in the task request
170 * memory. Yes its the same as the above macro except for the name.
172 #define scic_sds_ssp_task_request_get_command_buffer(memory) \
173 ((struct ssp_task_iu *)(\
174 ((char *)(memory)) + sizeof(struct scic_sds_request) \
178 * scic_sds_ssp_task_request_get_response_buffer() -
180 * This macro returns the address of the ssp response buffer in the task
183 #define scic_sds_ssp_task_request_get_response_buffer(memory) \
184 ((struct sci_ssp_response_iu *)(\
185 ((char *)(scic_sds_ssp_task_request_get_command_buffer(memory))) \
186 + sizeof(struct ssp_task_iu) \
190 * scic_sds_ssp_task_request_get_task_context_buffer() -
192 * This macro returs the task context buffer for the SSP task request.
194 #define scic_sds_ssp_task_request_get_task_context_buffer(memory) \
195 ((struct scu_task_context *)(\
196 ((char *)(scic_sds_ssp_task_request_get_response_buffer(memory))) \
197 + sizeof(struct sci_ssp_response_iu) \
203 * ****************************************************************************
204 * * SCIC SDS IO REQUEST PRIVATE METHODS
205 * **************************************************************************** */
210 * This method returns the size required to store an SSP IO request object. u32
212 static u32
scic_sds_ssp_request_get_object_size(void)
214 return sizeof(struct scic_sds_request
)
215 + scic_ssp_io_request_get_object_size()
216 + sizeof(struct scu_task_context
)
218 + sizeof(struct scu_sgl_element_pair
) * SCU_MAX_SGL_ELEMENT_PAIRS
;
222 * This method returns the sgl element pair for the specificed sgl_pair index.
223 * @sci_req: This parameter specifies the IO request for which to retrieve
224 * the Scatter-Gather List element pair.
225 * @sgl_pair_index: This parameter specifies the index into the SGL element
226 * pair to be retrieved.
228 * This method returns a pointer to an struct scu_sgl_element_pair.
230 static struct scu_sgl_element_pair
*scic_sds_request_get_sgl_element_pair(
231 struct scic_sds_request
*sci_req
,
234 struct scu_task_context
*task_context
;
236 task_context
= (struct scu_task_context
*)sci_req
->task_context_buffer
;
238 if (sgl_pair_index
== 0) {
239 return &task_context
->sgl_pair_ab
;
240 } else if (sgl_pair_index
== 1) {
241 return &task_context
->sgl_pair_cd
;
244 return &sci_req
->sgl_element_pair_buffer
[sgl_pair_index
- 2];
248 * This function will build the SGL list for an IO request.
249 * @sci_req: This parameter specifies the IO request for which to build
250 * the Scatter-Gather List.
253 void scic_sds_request_build_sgl(struct scic_sds_request
*sds_request
)
255 struct isci_request
*isci_request
= sds_request
->ireq
;
256 struct isci_host
*isci_host
= isci_request
->isci_host
;
257 struct sas_task
*task
= isci_request_access_task(isci_request
);
258 struct scatterlist
*sg
= NULL
;
261 struct scu_sgl_element_pair
*scu_sg
= NULL
;
262 struct scu_sgl_element_pair
*prev_sg
= NULL
;
264 if (task
->num_scatter
> 0) {
268 scu_sg
= scic_sds_request_get_sgl_element_pair(
272 SCU_SGL_COPY(scu_sg
->A
, sg
);
277 SCU_SGL_COPY(scu_sg
->B
, sg
);
280 SCU_SGL_ZERO(scu_sg
->B
);
284 scic_io_request_get_dma_addr(
288 prev_sg
->next_pair_upper
=
289 upper_32_bits(dma_addr
);
290 prev_sg
->next_pair_lower
=
291 lower_32_bits(dma_addr
);
297 } else { /* handle when no sg */
298 scu_sg
= scic_sds_request_get_sgl_element_pair(sds_request
,
301 dma_addr
= dma_map_single(&isci_host
->pdev
->dev
,
303 task
->total_xfer_len
,
306 isci_request
->zero_scatter_daddr
= dma_addr
;
308 scu_sg
->A
.length
= task
->total_xfer_len
;
309 scu_sg
->A
.address_upper
= upper_32_bits(dma_addr
);
310 scu_sg
->A
.address_lower
= lower_32_bits(dma_addr
);
314 scu_sg
->next_pair_upper
= 0;
315 scu_sg
->next_pair_lower
= 0;
320 * This method build the remainder of the IO request object.
321 * @sci_req: This parameter specifies the request object being constructed.
323 * The scic_sds_general_request_construct() must be called before this call is
326 static void scic_sds_ssp_io_request_assign_buffers(
327 struct scic_sds_request
*sci_req
)
329 sci_req
->command_buffer
=
330 scic_sds_ssp_request_get_command_buffer(sci_req
);
331 sci_req
->response_buffer
=
332 scic_sds_ssp_request_get_response_buffer(sci_req
);
333 sci_req
->sgl_element_pair_buffer
=
334 scic_sds_ssp_request_get_sgl_element_buffer(sci_req
);
335 sci_req
->sgl_element_pair_buffer
=
336 PTR_ALIGN(sci_req
->sgl_element_pair_buffer
,
337 sizeof(struct scu_sgl_element_pair
));
339 if (sci_req
->was_tag_assigned_by_user
== false) {
340 sci_req
->task_context_buffer
=
341 scic_sds_ssp_request_get_task_context_buffer(sci_req
);
342 sci_req
->task_context_buffer
=
343 PTR_ALIGN(sci_req
->task_context_buffer
,
348 static void scic_sds_io_request_build_ssp_command_iu(struct scic_sds_request
*sci_req
)
350 struct ssp_cmd_iu
*cmd_iu
;
351 struct isci_request
*ireq
= sci_req
->ireq
;
352 struct sas_task
*task
= isci_request_access_task(ireq
);
354 cmd_iu
= sci_req
->command_buffer
;
356 memcpy(cmd_iu
->LUN
, task
->ssp_task
.LUN
, 8);
357 cmd_iu
->add_cdb_len
= 0;
360 cmd_iu
->en_fburst
= 0; /* unsupported */
361 cmd_iu
->task_prio
= task
->ssp_task
.task_prio
;
362 cmd_iu
->task_attr
= task
->ssp_task
.task_attr
;
365 scic_word_copy_with_swap(
366 (u32
*)(&cmd_iu
->cdb
),
367 (u32
*)task
->ssp_task
.cdb
,
368 sizeof(task
->ssp_task
.cdb
) / sizeof(u32
));
371 static void scic_sds_task_request_build_ssp_task_iu(struct scic_sds_request
*sci_req
)
373 struct ssp_task_iu
*task_iu
;
374 struct isci_request
*ireq
= sci_req
->ireq
;
375 struct sas_task
*task
= isci_request_access_task(ireq
);
376 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(ireq
);
378 task_iu
= sci_req
->command_buffer
;
380 memset(task_iu
, 0, sizeof(struct ssp_task_iu
));
382 memcpy(task_iu
->LUN
, task
->ssp_task
.LUN
, 8);
384 task_iu
->task_func
= isci_tmf
->tmf_code
;
386 (ireq
->ttype
== tmf_task
) ?
388 SCI_CONTROLLER_INVALID_IO_TAG
;
392 * This method is will fill in the SCU Task Context for any type of SSP request.
397 static void scu_ssp_reqeust_construct_task_context(
398 struct scic_sds_request
*sds_request
,
399 struct scu_task_context
*task_context
)
402 struct scic_sds_controller
*controller
;
403 struct scic_sds_remote_device
*target_device
;
404 struct scic_sds_port
*target_port
;
406 controller
= scic_sds_request_get_controller(sds_request
);
407 target_device
= scic_sds_request_get_device(sds_request
);
408 target_port
= scic_sds_request_get_port(sds_request
);
410 /* Fill in the TC with the its required data */
411 task_context
->abort
= 0;
412 task_context
->priority
= 0;
413 task_context
->initiator_request
= 1;
414 task_context
->connection_rate
= target_device
->connection_rate
;
415 task_context
->protocol_engine_index
=
416 scic_sds_controller_get_protocol_engine_group(controller
);
417 task_context
->logical_port_index
=
418 scic_sds_port_get_index(target_port
);
419 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
420 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
421 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
423 task_context
->remote_node_index
=
424 scic_sds_remote_device_get_index(sds_request
->target_device
);
425 task_context
->command_code
= 0;
427 task_context
->link_layer_control
= 0;
428 task_context
->do_not_dma_ssp_good_response
= 1;
429 task_context
->strict_ordering
= 0;
430 task_context
->control_frame
= 0;
431 task_context
->timeout_enable
= 0;
432 task_context
->block_guard_enable
= 0;
434 task_context
->address_modifier
= 0;
436 /* task_context->type.ssp.tag = sci_req->io_tag; */
437 task_context
->task_phase
= 0x01;
439 if (sds_request
->was_tag_assigned_by_user
) {
441 * Build the task context now since we have already read
444 sds_request
->post_context
=
445 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
446 (scic_sds_controller_get_protocol_engine_group(
448 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
) |
449 (scic_sds_port_get_index(target_port
) <<
450 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
) |
451 scic_sds_io_tag_get_index(sds_request
->io_tag
));
454 * Build the task context now since we have already read
457 * I/O tag index is not assigned because we have to wait
460 sds_request
->post_context
=
461 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
462 (scic_sds_controller_get_protocol_engine_group(
463 owning_controller
) <<
464 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
) |
465 (scic_sds_port_get_index(target_port
) <<
466 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
));
470 * Copy the physical address for the command buffer to the
473 dma_addr
= scic_io_request_get_dma_addr(sds_request
,
474 sds_request
->command_buffer
);
476 task_context
->command_iu_upper
= upper_32_bits(dma_addr
);
477 task_context
->command_iu_lower
= lower_32_bits(dma_addr
);
480 * Copy the physical address for the response buffer to the
483 dma_addr
= scic_io_request_get_dma_addr(sds_request
,
484 sds_request
->response_buffer
);
486 task_context
->response_iu_upper
= upper_32_bits(dma_addr
);
487 task_context
->response_iu_lower
= lower_32_bits(dma_addr
);
491 * This method is will fill in the SCU Task Context for a SSP IO request.
495 static void scu_ssp_io_request_construct_task_context(
496 struct scic_sds_request
*sci_req
,
497 enum dma_data_direction dir
,
500 struct scu_task_context
*task_context
;
502 task_context
= scic_sds_request_get_task_context(sci_req
);
504 scu_ssp_reqeust_construct_task_context(sci_req
, task_context
);
506 task_context
->ssp_command_iu_length
=
507 sizeof(struct ssp_cmd_iu
) / sizeof(u32
);
508 task_context
->type
.ssp
.frame_type
= SCI_SAS_COMMAND_FRAME
;
511 case DMA_FROM_DEVICE
:
514 task_context
->task_type
= SCU_TASK_TYPE_IOREAD
;
517 task_context
->task_type
= SCU_TASK_TYPE_IOWRITE
;
521 task_context
->transfer_length_bytes
= len
;
523 if (task_context
->transfer_length_bytes
> 0)
524 scic_sds_request_build_sgl(sci_req
);
529 * This method will fill in the remainder of the io request object for SSP Task
534 static void scic_sds_ssp_task_request_assign_buffers(
535 struct scic_sds_request
*sci_req
)
537 /* Assign all of the buffer pointers */
538 sci_req
->command_buffer
=
539 scic_sds_ssp_task_request_get_command_buffer(sci_req
);
540 sci_req
->response_buffer
=
541 scic_sds_ssp_task_request_get_response_buffer(sci_req
);
542 sci_req
->sgl_element_pair_buffer
= NULL
;
544 if (sci_req
->was_tag_assigned_by_user
== false) {
545 sci_req
->task_context_buffer
=
546 scic_sds_ssp_task_request_get_task_context_buffer(sci_req
);
547 sci_req
->task_context_buffer
=
548 PTR_ALIGN(sci_req
->task_context_buffer
, SMP_CACHE_BYTES
);
553 * This method will fill in the SCU Task Context for a SSP Task request. The
554 * following important settings are utilized: -# priority ==
555 * SCU_TASK_PRIORITY_HIGH. This ensures that the task request is issued
556 * ahead of other task destined for the same Remote Node. -# task_type ==
557 * SCU_TASK_TYPE_IOREAD. This simply indicates that a normal request type
558 * (i.e. non-raw frame) is being utilized to perform task management. -#
559 * control_frame == 1. This ensures that the proper endianess is set so
560 * that the bytes are transmitted in the right order for a task frame.
561 * @sci_req: This parameter specifies the task request object being
565 static void scu_ssp_task_request_construct_task_context(
566 struct scic_sds_request
*sci_req
)
568 struct scu_task_context
*task_context
;
570 task_context
= scic_sds_request_get_task_context(sci_req
);
572 scu_ssp_reqeust_construct_task_context(sci_req
, task_context
);
574 task_context
->control_frame
= 1;
575 task_context
->priority
= SCU_TASK_PRIORITY_HIGH
;
576 task_context
->task_type
= SCU_TASK_TYPE_RAW_FRAME
;
577 task_context
->transfer_length_bytes
= 0;
578 task_context
->type
.ssp
.frame_type
= SCI_SAS_TASK_FRAME
;
579 task_context
->ssp_command_iu_length
=
580 sizeof(struct ssp_task_iu
) / sizeof(u32
);
585 * This method constructs the SSP Command IU data for this ssp passthrough
586 * comand request object.
587 * @sci_req: This parameter specifies the request object for which the SSP
588 * command information unit is being built.
590 * enum sci_status, returns invalid parameter is cdb > 16
595 * This method constructs the SATA request object.
604 static enum sci_status
605 scic_io_request_construct_sata(struct scic_sds_request
*sci_req
,
607 enum dma_data_direction dir
,
610 enum sci_status status
= SCI_SUCCESS
;
611 struct isci_request
*ireq
= sci_req
->ireq
;
612 struct sas_task
*task
= isci_request_access_task(ireq
);
614 /* check for management protocols */
615 if (ireq
->ttype
== tmf_task
) {
616 struct isci_tmf
*tmf
= isci_request_access_tmf(ireq
);
618 if (tmf
->tmf_code
== isci_tmf_sata_srst_high
||
619 tmf
->tmf_code
== isci_tmf_sata_srst_low
)
620 return scic_sds_stp_soft_reset_request_construct(sci_req
);
622 dev_err(scic_to_dev(sci_req
->owning_controller
),
623 "%s: Request 0x%p received un-handled SAT "
624 "management protocol 0x%x.\n",
625 __func__
, sci_req
, tmf
->tmf_code
);
631 if (!sas_protocol_ata(task
->task_proto
)) {
632 dev_err(scic_to_dev(sci_req
->owning_controller
),
633 "%s: Non-ATA protocol in SATA path: 0x%x\n",
641 if (task
->data_dir
== DMA_NONE
)
642 return scic_sds_stp_non_data_request_construct(sci_req
);
645 if (task
->ata_task
.use_ncq
)
646 return scic_sds_stp_ncq_request_construct(sci_req
, len
, dir
);
649 if (task
->ata_task
.dma_xfer
)
650 return scic_sds_stp_udma_request_construct(sci_req
, len
, dir
);
652 return scic_sds_stp_pio_request_construct(sci_req
, copy
);
657 u32
scic_io_request_get_object_size(void)
659 u32 ssp_request_size
;
660 u32 stp_request_size
;
661 u32 smp_request_size
;
663 ssp_request_size
= scic_sds_ssp_request_get_object_size();
664 stp_request_size
= scic_sds_stp_request_get_object_size();
665 smp_request_size
= scic_sds_smp_request_get_object_size();
667 return max(ssp_request_size
, max(stp_request_size
, smp_request_size
));
670 enum sci_status
scic_io_request_construct_basic_ssp(
671 struct scic_sds_request
*sci_req
)
673 struct isci_request
*isci_request
= sci_req
->ireq
;
675 sci_req
->protocol
= SCIC_SSP_PROTOCOL
;
677 scu_ssp_io_request_construct_task_context(
679 isci_request_io_request_get_data_direction(isci_request
),
680 isci_request_io_request_get_transfer_length(isci_request
));
682 scic_sds_io_request_build_ssp_command_iu(sci_req
);
684 sci_base_state_machine_change_state(&sci_req
->state_machine
,
685 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
691 enum sci_status
scic_task_request_construct_ssp(
692 struct scic_sds_request
*sci_req
)
694 /* Construct the SSP Task SCU Task Context */
695 scu_ssp_task_request_construct_task_context(sci_req
);
697 /* Fill in the SSP Task IU */
698 scic_sds_task_request_build_ssp_task_iu(sci_req
);
700 sci_base_state_machine_change_state(&sci_req
->state_machine
,
701 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
707 enum sci_status
scic_io_request_construct_basic_sata(
708 struct scic_sds_request
*sci_req
)
710 enum sci_status status
;
711 struct scic_sds_stp_request
*stp_req
;
713 enum dma_data_direction dir
;
715 struct isci_request
*isci_request
= sci_req
->ireq
;
716 struct sas_task
*task
= isci_request_access_task(isci_request
);
718 stp_req
= container_of(sci_req
, typeof(*stp_req
), parent
);
720 sci_req
->protocol
= SCIC_STP_PROTOCOL
;
722 len
= isci_request_io_request_get_transfer_length(isci_request
);
723 dir
= isci_request_io_request_get_data_direction(isci_request
);
724 copy
= (task
->data_dir
== DMA_NONE
) ? false : true;
726 status
= scic_io_request_construct_sata(sci_req
, len
, dir
, copy
);
728 if (status
== SCI_SUCCESS
)
729 sci_base_state_machine_change_state(&sci_req
->state_machine
,
730 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
736 enum sci_status
scic_task_request_construct_sata(
737 struct scic_sds_request
*sci_req
)
739 enum sci_status status
= SCI_SUCCESS
;
740 struct isci_request
*ireq
= sci_req
->ireq
;
742 /* check for management protocols */
743 if (ireq
->ttype
== tmf_task
) {
744 struct isci_tmf
*tmf
= isci_request_access_tmf(ireq
);
746 if (tmf
->tmf_code
== isci_tmf_sata_srst_high
||
747 tmf
->tmf_code
== isci_tmf_sata_srst_low
) {
748 status
= scic_sds_stp_soft_reset_request_construct(sci_req
);
750 dev_err(scic_to_dev(sci_req
->owning_controller
),
751 "%s: Request 0x%p received un-handled SAT "
753 __func__
, sci_req
, tmf
->tmf_code
);
759 if (status
== SCI_SUCCESS
)
760 sci_base_state_machine_change_state(
761 &sci_req
->state_machine
,
762 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
768 u16
scic_io_request_get_io_tag(
769 struct scic_sds_request
*sci_req
)
771 return sci_req
->io_tag
;
775 u32
scic_request_get_controller_status(
776 struct scic_sds_request
*sci_req
)
778 return sci_req
->scu_status
;
782 void *scic_io_request_get_command_iu_address(
783 struct scic_sds_request
*sci_req
)
785 return sci_req
->command_buffer
;
789 void *scic_io_request_get_response_iu_address(
790 struct scic_sds_request
*sci_req
)
792 return sci_req
->response_buffer
;
796 #define SCU_TASK_CONTEXT_SRAM 0x200000
797 u32
scic_io_request_get_number_of_bytes_transferred(
798 struct scic_sds_request
*scic_sds_request
)
800 struct scic_sds_controller
*scic
= scic_sds_request
->owning_controller
;
803 if (readl(&scic
->smu_registers
->address_modifier
) == 0) {
804 void __iomem
*scu_reg_base
= scic
->scu_registers
;
806 * get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
807 * BAR1 is the scu_registers
808 * 0x20002C = 0x200000 + 0x2c
809 * = start of task context SRAM + offset of (type.ssp.data_offset)
810 * TCi is the io_tag of struct scic_sds_request */
811 ret_val
= readl(scu_reg_base
+
812 (SCU_TASK_CONTEXT_SRAM
+ offsetof(struct scu_task_context
, type
.ssp
.data_offset
)) +
813 ((sizeof(struct scu_task_context
)) * scic_sds_io_tag_get_index(scic_sds_request
->io_tag
)));
821 * ****************************************************************************
822 * * SCIC SDS Interface Implementation
823 * **************************************************************************** */
826 scic_sds_request_start(struct scic_sds_request
*request
)
828 if (request
->device_sequence
!=
829 scic_sds_remote_device_get_sequence(request
->target_device
))
832 if (request
->state_handlers
->start_handler
)
833 return request
->state_handlers
->start_handler(request
);
835 dev_warn(scic_to_dev(request
->owning_controller
),
836 "%s: SCIC IO Request requested to start while in wrong "
839 sci_base_state_machine_get_state(&request
->state_machine
));
841 return SCI_FAILURE_INVALID_STATE
;
845 scic_sds_io_request_terminate(struct scic_sds_request
*request
)
847 if (request
->state_handlers
->abort_handler
)
848 return request
->state_handlers
->abort_handler(request
);
850 dev_warn(scic_to_dev(request
->owning_controller
),
851 "%s: SCIC IO Request requested to abort while in wrong "
854 sci_base_state_machine_get_state(&request
->state_machine
));
856 return SCI_FAILURE_INVALID_STATE
;
860 scic_sds_io_request_complete(struct scic_sds_request
*request
)
862 if (request
->state_handlers
->complete_handler
)
863 return request
->state_handlers
->complete_handler(request
);
865 dev_warn(scic_to_dev(request
->owning_controller
),
866 "%s: SCIC IO Request requested to complete while in wrong "
869 sci_base_state_machine_get_state(&request
->state_machine
));
871 return SCI_FAILURE_INVALID_STATE
;
874 enum sci_status
scic_sds_io_request_event_handler(
875 struct scic_sds_request
*request
,
878 if (request
->state_handlers
->event_handler
)
879 return request
->state_handlers
->event_handler(request
, event_code
);
881 dev_warn(scic_to_dev(request
->owning_controller
),
882 "%s: SCIC IO Request given event code notification %x while "
883 "in wrong state %d\n",
886 sci_base_state_machine_get_state(&request
->state_machine
));
888 return SCI_FAILURE_INVALID_STATE
;
892 scic_sds_io_request_tc_completion(struct scic_sds_request
*request
, u32 completion_code
)
894 if (request
->state_machine
.current_state_id
== SCI_BASE_REQUEST_STATE_STARTED
&&
895 request
->has_started_substate_machine
== false)
896 return scic_sds_request_started_state_tc_completion_handler(request
, completion_code
);
897 else if (request
->state_handlers
->tc_completion_handler
)
898 return request
->state_handlers
->tc_completion_handler(request
, completion_code
);
900 dev_warn(scic_to_dev(request
->owning_controller
),
901 "%s: SCIC IO Request given task completion notification %x "
902 "while in wrong state %d\n",
905 sci_base_state_machine_get_state(&request
->state_machine
));
907 return SCI_FAILURE_INVALID_STATE
;
914 * @sci_req: The SCIC_SDS_IO_REQUEST_T object for which the start
915 * operation is to be executed.
916 * @frame_index: The frame index returned by the hardware for the reqeust
919 * This method invokes the core state frame handler for the
920 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
922 enum sci_status
scic_sds_io_request_frame_handler(
923 struct scic_sds_request
*request
,
926 if (request
->state_handlers
->frame_handler
)
927 return request
->state_handlers
->frame_handler(request
, frame_index
);
929 dev_warn(scic_to_dev(request
->owning_controller
),
930 "%s: SCIC IO Request given unexpected frame %x while in "
934 sci_base_state_machine_get_state(&request
->state_machine
));
936 scic_sds_controller_release_frame(request
->owning_controller
, frame_index
);
937 return SCI_FAILURE_INVALID_STATE
;
942 * @sci_req: The SCIC_SDS_IO_REQUEST_T object for which the task start
943 * operation is to be executed.
945 * This method invokes the core state task complete handler for the
946 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
950 * ****************************************************************************
951 * * SCIC SDS PROTECTED METHODS
952 * **************************************************************************** */
955 * This method copies response data for requests returning response data
956 * instead of sense data.
957 * @sci_req: This parameter specifies the request object for which to copy
961 void scic_sds_io_request_copy_response(struct scic_sds_request
*sds_request
)
963 void *response_buffer
;
964 u32 user_response_length
;
965 u32 core_response_length
;
966 struct sci_ssp_response_iu
*ssp_response
;
967 struct isci_request
*isci_request
= sds_request
->ireq
;
970 (struct sci_ssp_response_iu
*)sds_request
->response_buffer
;
973 isci_task_ssp_request_get_response_data_address(
976 user_response_length
=
977 isci_task_ssp_request_get_response_data_length(
980 core_response_length
= sci_ssp_get_response_data_length(
981 ssp_response
->response_data_length
);
983 user_response_length
= min(user_response_length
, core_response_length
);
985 memcpy(response_buffer
, ssp_response
->data
, user_response_length
);
989 * *****************************************************************************
990 * * CONSTRUCTED STATE HANDLERS
991 * ***************************************************************************** */
994 * This method implements the action taken when a constructed
995 * SCIC_SDS_IO_REQUEST_T object receives a scic_sds_request_start() request.
996 * This method will, if necessary, allocate a TCi for the io request object and
997 * then will, if necessary, copy the constructed TC data into the actual TC
998 * buffer. If everything is successful the post context field is updated with
999 * the TCi so the controller can post the request to the hardware. enum sci_status
1000 * SCI_SUCCESS SCI_FAILURE_INSUFFICIENT_RESOURCES
1002 static enum sci_status
scic_sds_request_constructed_state_start_handler(
1003 struct scic_sds_request
*request
)
1005 struct scu_task_context
*task_context
;
1007 if (request
->io_tag
== SCI_CONTROLLER_INVALID_IO_TAG
) {
1009 scic_controller_allocate_io_tag(request
->owning_controller
);
1012 /* Record the IO Tag in the request */
1013 if (request
->io_tag
!= SCI_CONTROLLER_INVALID_IO_TAG
) {
1014 task_context
= request
->task_context_buffer
;
1016 task_context
->task_index
= scic_sds_io_tag_get_index(request
->io_tag
);
1018 switch (task_context
->protocol_type
) {
1019 case SCU_TASK_CONTEXT_PROTOCOL_SMP
:
1020 case SCU_TASK_CONTEXT_PROTOCOL_SSP
:
1022 task_context
->type
.ssp
.tag
= request
->io_tag
;
1023 task_context
->type
.ssp
.target_port_transfer_tag
= 0xFFFF;
1026 case SCU_TASK_CONTEXT_PROTOCOL_STP
:
1029 * task_context->type.stp.ncq_tag = request->ncq_tag; */
1032 case SCU_TASK_CONTEXT_PROTOCOL_NONE
:
1033 /* / @todo When do we set no protocol type? */
1037 /* This should never happen since we build the IO requests */
1042 * Check to see if we need to copy the task context buffer
1043 * or have been building into the task context buffer */
1044 if (request
->was_tag_assigned_by_user
== false) {
1045 scic_sds_controller_copy_task_context(
1046 request
->owning_controller
, request
);
1049 /* Add to the post_context the io tag value */
1050 request
->post_context
|= scic_sds_io_tag_get_index(request
->io_tag
);
1052 /* Everything is good go ahead and change state */
1053 sci_base_state_machine_change_state(&request
->state_machine
,
1054 SCI_BASE_REQUEST_STATE_STARTED
);
1059 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1063 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1064 * object receives a scic_sds_request_terminate() request. Since the request
1065 * has not yet been posted to the hardware the request transitions to the
1066 * completed state. enum sci_status SCI_SUCCESS
1068 static enum sci_status
scic_sds_request_constructed_state_abort_handler(
1069 struct scic_sds_request
*request
)
1072 * This request has been terminated by the user make sure that the correct
1073 * status code is returned */
1074 scic_sds_request_set_status(request
,
1075 SCU_TASK_DONE_TASK_ABORT
,
1076 SCI_FAILURE_IO_TERMINATED
);
1078 sci_base_state_machine_change_state(&request
->state_machine
,
1079 SCI_BASE_REQUEST_STATE_COMPLETED
);
1084 * *****************************************************************************
1085 * * STARTED STATE HANDLERS
1086 * ***************************************************************************** */
1089 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1090 * object receives a scic_sds_request_terminate() request. Since the request
1091 * has been posted to the hardware the io request state is changed to the
1092 * aborting state. enum sci_status SCI_SUCCESS
1094 enum sci_status
scic_sds_request_started_state_abort_handler(
1095 struct scic_sds_request
*request
)
1097 if (request
->has_started_substate_machine
)
1098 sci_base_state_machine_stop(&request
->started_substate_machine
);
1100 sci_base_state_machine_change_state(&request
->state_machine
,
1101 SCI_BASE_REQUEST_STATE_ABORTING
);
1106 * scic_sds_request_started_state_tc_completion_handler() - This method process
1107 * TC (task context) completions for normal IO request (i.e. Task/Abort
1108 * Completions of type 0). This method will update the
1109 * SCIC_SDS_IO_REQUEST_T::status field.
1110 * @sci_req: This parameter specifies the request for which a completion
1112 * @completion_code: This parameter specifies the completion code received from
1116 enum sci_status
scic_sds_request_started_state_tc_completion_handler(
1117 struct scic_sds_request
*sci_req
,
1118 u32 completion_code
)
1121 struct sci_ssp_response_iu
*response_buffer
;
1124 * @todo Any SDMA return code of other than 0 is bad
1125 * decode 0x003C0000 to determine SDMA status
1127 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1128 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
1129 scic_sds_request_set_status(
1130 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
1134 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP
):
1137 * There are times when the SCU hardware will return an early response
1138 * because the io request specified more data than is returned by the
1139 * target device (mode pages, inquiry data, etc.). We must check the
1140 * response stats to see if this is truly a failed request or a good
1141 * request that just got completed early. */
1142 struct sci_ssp_response_iu
*response
= (struct sci_ssp_response_iu
*)
1143 sci_req
->response_buffer
;
1144 scic_word_copy_with_swap(
1145 sci_req
->response_buffer
,
1146 sci_req
->response_buffer
,
1147 sizeof(struct sci_ssp_response_iu
) / sizeof(u32
)
1150 if (response
->status
== 0) {
1151 scic_sds_request_set_status(
1152 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS_IO_DONE_EARLY
1155 scic_sds_request_set_status(
1157 SCU_TASK_DONE_CHECK_RESPONSE
,
1158 SCI_FAILURE_IO_RESPONSE_VALID
1164 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE
):
1165 scic_word_copy_with_swap(
1166 sci_req
->response_buffer
,
1167 sci_req
->response_buffer
,
1168 sizeof(struct sci_ssp_response_iu
) / sizeof(u32
)
1171 scic_sds_request_set_status(
1173 SCU_TASK_DONE_CHECK_RESPONSE
,
1174 SCI_FAILURE_IO_RESPONSE_VALID
1178 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR
):
1180 * / @todo With TASK_DONE_RESP_LEN_ERR is the response frame guaranteed
1181 * / to be received before this completion status is posted? */
1183 (struct sci_ssp_response_iu
*)sci_req
->response_buffer
;
1185 response_buffer
->data_present
& SCI_SSP_RESPONSE_IU_DATA_PRESENT_MASK
;
1187 if ((data_present
== 0x01) || (data_present
== 0x02)) {
1188 scic_sds_request_set_status(
1190 SCU_TASK_DONE_CHECK_RESPONSE
,
1191 SCI_FAILURE_IO_RESPONSE_VALID
1194 scic_sds_request_set_status(
1195 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
1200 /* only stp device gets suspended. */
1201 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO
):
1202 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR
):
1203 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR
):
1204 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR
):
1205 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR
):
1206 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN
):
1207 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR
):
1208 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP
):
1209 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS
):
1210 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR
):
1211 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR
):
1212 if (sci_req
->protocol
== SCIC_STP_PROTOCOL
) {
1213 scic_sds_request_set_status(
1215 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >> SCU_COMPLETION_TL_STATUS_SHIFT
,
1216 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
1219 scic_sds_request_set_status(
1221 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >> SCU_COMPLETION_TL_STATUS_SHIFT
,
1222 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1227 /* both stp/ssp device gets suspended */
1228 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR
):
1229 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION
):
1230 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1
):
1231 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2
):
1232 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3
):
1233 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION
):
1234 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION
):
1235 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY
):
1236 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED
):
1237 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED
):
1238 scic_sds_request_set_status(
1240 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >> SCU_COMPLETION_TL_STATUS_SHIFT
,
1241 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
1245 /* neither ssp nor stp gets suspended. */
1246 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR
):
1247 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR
):
1248 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR
):
1249 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR
):
1250 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR
):
1251 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA
):
1252 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR
):
1253 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR
):
1254 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR
):
1255 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR
):
1256 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA
):
1257 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL
):
1258 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV
):
1259 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV
):
1260 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND
):
1262 scic_sds_request_set_status(
1264 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >> SCU_COMPLETION_TL_STATUS_SHIFT
,
1265 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1271 * @todo This is probably wrong for ACK/NAK timeout conditions
1274 /* In all cases we will treat this as the completion of the IO request. */
1275 sci_base_state_machine_change_state(&sci_req
->state_machine
,
1276 SCI_BASE_REQUEST_STATE_COMPLETED
);
1281 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1282 * object receives a scic_sds_request_frame_handler() request. This method
1283 * first determines the frame type received. If this is a response frame then
1284 * the response data is copied to the io request response buffer for processing
1285 * at completion time. If the frame type is not a response buffer an error is
1286 * logged. enum sci_status SCI_SUCCESS SCI_FAILURE_INVALID_PARAMETER_VALUE
1288 static enum sci_status
scic_sds_request_started_state_frame_handler(
1289 struct scic_sds_request
*sci_req
,
1292 enum sci_status status
;
1293 struct sci_ssp_frame_header
*frame_header
;
1295 /* / @todo If this is a response frame we must record that we received it */
1296 status
= scic_sds_unsolicited_frame_control_get_header(
1297 &(scic_sds_request_get_controller(sci_req
)->uf_control
),
1299 (void **)&frame_header
1302 if (frame_header
->frame_type
== SCI_SAS_RESPONSE_FRAME
) {
1303 struct sci_ssp_response_iu
*response_buffer
;
1305 status
= scic_sds_unsolicited_frame_control_get_buffer(
1306 &(scic_sds_request_get_controller(sci_req
)->uf_control
),
1308 (void **)&response_buffer
1311 scic_word_copy_with_swap(
1312 sci_req
->response_buffer
,
1313 (u32
*)response_buffer
,
1314 sizeof(struct sci_ssp_response_iu
)
1317 response_buffer
= (struct sci_ssp_response_iu
*)sci_req
->response_buffer
;
1319 if ((response_buffer
->data_present
== 0x01) ||
1320 (response_buffer
->data_present
== 0x02)) {
1321 scic_sds_request_set_status(
1323 SCU_TASK_DONE_CHECK_RESPONSE
,
1324 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1327 scic_sds_request_set_status(
1328 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
1331 /* This was not a response frame why did it get forwarded? */
1332 dev_err(scic_to_dev(sci_req
->owning_controller
),
1333 "%s: SCIC IO Request 0x%p received unexpected "
1334 "frame %d type 0x%02x\n",
1338 frame_header
->frame_type
);
1341 * In any case we are done with this frame buffer return it to the
1343 scic_sds_controller_release_frame(
1344 sci_req
->owning_controller
, frame_index
1351 * *****************************************************************************
1352 * * COMPLETED STATE HANDLERS
1353 * ***************************************************************************** */
1357 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1358 * object receives a scic_sds_request_complete() request. This method frees up
1359 * any io request resources that have been allocated and transitions the
1360 * request to its final state. Consider stopping the state machine instead of
1361 * transitioning to the final state? enum sci_status SCI_SUCCESS
1363 static enum sci_status
scic_sds_request_completed_state_complete_handler(
1364 struct scic_sds_request
*request
)
1366 if (request
->was_tag_assigned_by_user
!= true) {
1367 scic_controller_free_io_tag(
1368 request
->owning_controller
, request
->io_tag
);
1371 if (request
->saved_rx_frame_index
!= SCU_INVALID_FRAME_INDEX
) {
1372 scic_sds_controller_release_frame(
1373 request
->owning_controller
, request
->saved_rx_frame_index
);
1376 sci_base_state_machine_change_state(&request
->state_machine
,
1377 SCI_BASE_REQUEST_STATE_FINAL
);
1382 * *****************************************************************************
1383 * * ABORTING STATE HANDLERS
1384 * ***************************************************************************** */
1387 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1388 * object receives a scic_sds_request_terminate() request. This method is the
1389 * io request aborting state abort handlers. On receipt of a multiple
1390 * terminate requests the io request will transition to the completed state.
1391 * This should not happen in normal operation. enum sci_status SCI_SUCCESS
1393 static enum sci_status
scic_sds_request_aborting_state_abort_handler(
1394 struct scic_sds_request
*request
)
1396 sci_base_state_machine_change_state(&request
->state_machine
,
1397 SCI_BASE_REQUEST_STATE_COMPLETED
);
1402 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1403 * object receives a scic_sds_request_task_completion() request. This method
1404 * decodes the completion type waiting for the abort task complete
1405 * notification. When the abort task complete is received the io request
1406 * transitions to the completed state. enum sci_status SCI_SUCCESS
1408 static enum sci_status
scic_sds_request_aborting_state_tc_completion_handler(
1409 struct scic_sds_request
*sci_req
,
1410 u32 completion_code
)
1412 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1413 case (SCU_TASK_DONE_GOOD
<< SCU_COMPLETION_TL_STATUS_SHIFT
):
1414 case (SCU_TASK_DONE_TASK_ABORT
<< SCU_COMPLETION_TL_STATUS_SHIFT
):
1415 scic_sds_request_set_status(
1416 sci_req
, SCU_TASK_DONE_TASK_ABORT
, SCI_FAILURE_IO_TERMINATED
1419 sci_base_state_machine_change_state(&sci_req
->state_machine
,
1420 SCI_BASE_REQUEST_STATE_COMPLETED
);
1425 * Unless we get some strange error wait for the task abort to complete
1426 * TODO: Should there be a state change for this completion? */
1434 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1435 * object receives a scic_sds_request_frame_handler() request. This method
1436 * discards the unsolicited frame since we are waiting for the abort task
1437 * completion. enum sci_status SCI_SUCCESS
1439 static enum sci_status
scic_sds_request_aborting_state_frame_handler(
1440 struct scic_sds_request
*sci_req
,
1443 /* TODO: Is it even possible to get an unsolicited frame in the aborting state? */
1445 scic_sds_controller_release_frame(
1446 sci_req
->owning_controller
, frame_index
);
1451 static const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table
[] = {
1452 [SCI_BASE_REQUEST_STATE_INITIAL
] = {
1454 [SCI_BASE_REQUEST_STATE_CONSTRUCTED
] = {
1455 .start_handler
= scic_sds_request_constructed_state_start_handler
,
1456 .abort_handler
= scic_sds_request_constructed_state_abort_handler
,
1458 [SCI_BASE_REQUEST_STATE_STARTED
] = {
1459 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1460 .tc_completion_handler
= scic_sds_request_started_state_tc_completion_handler
,
1461 .frame_handler
= scic_sds_request_started_state_frame_handler
,
1463 [SCI_BASE_REQUEST_STATE_COMPLETED
] = {
1464 .complete_handler
= scic_sds_request_completed_state_complete_handler
,
1466 [SCI_BASE_REQUEST_STATE_ABORTING
] = {
1467 .abort_handler
= scic_sds_request_aborting_state_abort_handler
,
1468 .tc_completion_handler
= scic_sds_request_aborting_state_tc_completion_handler
,
1469 .frame_handler
= scic_sds_request_aborting_state_frame_handler
,
1471 [SCI_BASE_REQUEST_STATE_FINAL
] = {
1476 * scic_sds_request_initial_state_enter() -
1477 * @object: This parameter specifies the base object for which the state
1478 * transition is occurring.
1480 * This method implements the actions taken when entering the
1481 * SCI_BASE_REQUEST_STATE_INITIAL state. This state is entered when the initial
1482 * base request is constructed. Entry into the initial state sets all handlers
1483 * for the io request object to their default handlers. none
1485 static void scic_sds_request_initial_state_enter(void *object
)
1487 struct scic_sds_request
*sci_req
= object
;
1491 scic_sds_request_state_handler_table
,
1492 SCI_BASE_REQUEST_STATE_INITIAL
1497 * scic_sds_request_constructed_state_enter() -
1498 * @object: The io request object that is to enter the constructed state.
1500 * This method implements the actions taken when entering the
1501 * SCI_BASE_REQUEST_STATE_CONSTRUCTED state. The method sets the state handlers
1502 * for the the constructed state. none
1504 static void scic_sds_request_constructed_state_enter(void *object
)
1506 struct scic_sds_request
*sci_req
= object
;
1510 scic_sds_request_state_handler_table
,
1511 SCI_BASE_REQUEST_STATE_CONSTRUCTED
1516 * scic_sds_request_started_state_enter() -
1517 * @object: This parameter specifies the base object for which the state
1518 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
1520 * This method implements the actions taken when entering the
1521 * SCI_BASE_REQUEST_STATE_STARTED state. If the io request object type is a
1522 * SCSI Task request we must enter the started substate machine. none
1524 static void scic_sds_request_started_state_enter(void *object
)
1526 struct scic_sds_request
*sci_req
= object
;
1530 scic_sds_request_state_handler_table
,
1531 SCI_BASE_REQUEST_STATE_STARTED
1535 * Most of the request state machines have a started substate machine so
1536 * start its execution on the entry to the started state. */
1537 if (sci_req
->has_started_substate_machine
== true)
1538 sci_base_state_machine_start(&sci_req
->started_substate_machine
);
1542 * scic_sds_request_started_state_exit() -
1543 * @object: This parameter specifies the base object for which the state
1544 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1547 * This method implements the actions taken when exiting the
1548 * SCI_BASE_REQUEST_STATE_STARTED state. For task requests the action will be
1549 * to stop the started substate machine. none
1551 static void scic_sds_request_started_state_exit(void *object
)
1553 struct scic_sds_request
*sci_req
= object
;
1555 if (sci_req
->has_started_substate_machine
== true)
1556 sci_base_state_machine_stop(&sci_req
->started_substate_machine
);
1560 * scic_sds_request_completed_state_enter() -
1561 * @object: This parameter specifies the base object for which the state
1562 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1565 * This method implements the actions taken when entering the
1566 * SCI_BASE_REQUEST_STATE_COMPLETED state. This state is entered when the
1567 * SCIC_SDS_IO_REQUEST has completed. The method will decode the request
1568 * completion status and convert it to an enum sci_status to return in the
1569 * completion callback function. none
1571 static void scic_sds_request_completed_state_enter(void *object
)
1573 struct scic_sds_request
*sci_req
= object
;
1574 struct scic_sds_controller
*scic
=
1575 scic_sds_request_get_controller(sci_req
);
1576 struct isci_host
*ihost
= scic
->ihost
;
1577 struct isci_request
*ireq
= sci_req
->ireq
;
1579 SET_STATE_HANDLER(sci_req
,
1580 scic_sds_request_state_handler_table
,
1581 SCI_BASE_REQUEST_STATE_COMPLETED
);
1583 /* Tell the SCI_USER that the IO request is complete */
1584 if (sci_req
->is_task_management_request
== false)
1585 isci_request_io_request_complete(ihost
,
1587 sci_req
->sci_status
);
1589 isci_task_request_complete(ihost
, ireq
, sci_req
->sci_status
);
1593 * scic_sds_request_aborting_state_enter() -
1594 * @object: This parameter specifies the base object for which the state
1595 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1598 * This method implements the actions taken when entering the
1599 * SCI_BASE_REQUEST_STATE_ABORTING state. none
1601 static void scic_sds_request_aborting_state_enter(void *object
)
1603 struct scic_sds_request
*sci_req
= object
;
1605 /* Setting the abort bit in the Task Context is required by the silicon. */
1606 sci_req
->task_context_buffer
->abort
= 1;
1610 scic_sds_request_state_handler_table
,
1611 SCI_BASE_REQUEST_STATE_ABORTING
1616 * scic_sds_request_final_state_enter() -
1617 * @object: This parameter specifies the base object for which the state
1618 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
1620 * This method implements the actions taken when entering the
1621 * SCI_BASE_REQUEST_STATE_FINAL state. The only action required is to put the
1622 * state handlers in place. none
1624 static void scic_sds_request_final_state_enter(void *object
)
1626 struct scic_sds_request
*sci_req
= object
;
1630 scic_sds_request_state_handler_table
,
1631 SCI_BASE_REQUEST_STATE_FINAL
1635 static const struct sci_base_state scic_sds_request_state_table
[] = {
1636 [SCI_BASE_REQUEST_STATE_INITIAL
] = {
1637 .enter_state
= scic_sds_request_initial_state_enter
,
1639 [SCI_BASE_REQUEST_STATE_CONSTRUCTED
] = {
1640 .enter_state
= scic_sds_request_constructed_state_enter
,
1642 [SCI_BASE_REQUEST_STATE_STARTED
] = {
1643 .enter_state
= scic_sds_request_started_state_enter
,
1644 .exit_state
= scic_sds_request_started_state_exit
1646 [SCI_BASE_REQUEST_STATE_COMPLETED
] = {
1647 .enter_state
= scic_sds_request_completed_state_enter
,
1649 [SCI_BASE_REQUEST_STATE_ABORTING
] = {
1650 .enter_state
= scic_sds_request_aborting_state_enter
,
1652 [SCI_BASE_REQUEST_STATE_FINAL
] = {
1653 .enter_state
= scic_sds_request_final_state_enter
,
1657 static void scic_sds_general_request_construct(struct scic_sds_controller
*scic
,
1658 struct scic_sds_remote_device
*sci_dev
,
1660 void *user_io_request_object
,
1661 struct scic_sds_request
*sci_req
)
1663 sci_base_state_machine_construct(&sci_req
->state_machine
, sci_req
,
1664 scic_sds_request_state_table
, SCI_BASE_REQUEST_STATE_INITIAL
);
1665 sci_base_state_machine_start(&sci_req
->state_machine
);
1667 sci_req
->io_tag
= io_tag
;
1668 sci_req
->user_request
= user_io_request_object
;
1669 sci_req
->owning_controller
= scic
;
1670 sci_req
->target_device
= sci_dev
;
1671 sci_req
->has_started_substate_machine
= false;
1672 sci_req
->protocol
= SCIC_NO_PROTOCOL
;
1673 sci_req
->saved_rx_frame_index
= SCU_INVALID_FRAME_INDEX
;
1674 sci_req
->device_sequence
= scic_sds_remote_device_get_sequence(sci_dev
);
1676 sci_req
->sci_status
= SCI_SUCCESS
;
1677 sci_req
->scu_status
= 0;
1678 sci_req
->post_context
= 0xFFFFFFFF;
1680 sci_req
->is_task_management_request
= false;
1682 if (io_tag
== SCI_CONTROLLER_INVALID_IO_TAG
) {
1683 sci_req
->was_tag_assigned_by_user
= false;
1684 sci_req
->task_context_buffer
= NULL
;
1686 sci_req
->was_tag_assigned_by_user
= true;
1688 sci_req
->task_context_buffer
=
1689 scic_sds_controller_get_task_context_buffer(scic
, io_tag
);
1693 enum sci_status
scic_io_request_construct(struct scic_sds_controller
*scic
,
1694 struct scic_sds_remote_device
*sci_dev
,
1696 void *user_io_request_object
,
1697 struct scic_sds_request
*sci_req
,
1698 struct scic_sds_request
**new_scic_io_request_handle
)
1700 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
1701 enum sci_status status
= SCI_SUCCESS
;
1703 /* Build the common part of the request */
1704 scic_sds_general_request_construct(scic
, sci_dev
, io_tag
,
1705 user_io_request_object
, sci_req
);
1707 if (sci_dev
->rnc
.remote_node_index
== SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
)
1708 return SCI_FAILURE_INVALID_REMOTE_DEVICE
;
1710 if (dev
->dev_type
== SAS_END_DEV
) {
1711 scic_sds_ssp_io_request_assign_buffers(sci_req
);
1712 } else if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
)) {
1713 scic_sds_stp_request_assign_buffers(sci_req
);
1714 memset(sci_req
->command_buffer
, 0, sizeof(struct host_to_dev_fis
));
1715 } else if (dev_is_expander(dev
)) {
1716 scic_sds_smp_request_assign_buffers(sci_req
);
1717 memset(sci_req
->command_buffer
, 0, sizeof(struct smp_request
));
1719 status
= SCI_FAILURE_UNSUPPORTED_PROTOCOL
;
1721 if (status
== SCI_SUCCESS
) {
1722 memset(sci_req
->task_context_buffer
, 0,
1723 SCI_FIELD_OFFSET(struct scu_task_context
, sgl_pair_ab
));
1724 *new_scic_io_request_handle
= sci_req
;
1730 enum sci_status
scic_task_request_construct(struct scic_sds_controller
*scic
,
1731 struct scic_sds_remote_device
*sci_dev
,
1733 void *user_io_request_object
,
1734 struct scic_sds_request
*sci_req
,
1735 struct scic_sds_request
**new_sci_req
)
1737 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
1738 enum sci_status status
= SCI_SUCCESS
;
1740 /* Build the common part of the request */
1741 scic_sds_general_request_construct(scic
, sci_dev
, io_tag
,
1742 user_io_request_object
,
1745 if (dev
->dev_type
== SAS_END_DEV
) {
1746 scic_sds_ssp_task_request_assign_buffers(sci_req
);
1748 sci_req
->has_started_substate_machine
= true;
1750 /* Construct the started sub-state machine. */
1751 sci_base_state_machine_construct(
1752 &sci_req
->started_substate_machine
,
1754 scic_sds_io_request_started_task_mgmt_substate_table
,
1755 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
1757 } else if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
))
1758 scic_sds_stp_request_assign_buffers(sci_req
);
1760 status
= SCI_FAILURE_UNSUPPORTED_PROTOCOL
;
1762 if (status
== SCI_SUCCESS
) {
1763 sci_req
->is_task_management_request
= true;
1764 memset(sci_req
->task_context_buffer
, 0, sizeof(struct scu_task_context
));
1765 *new_sci_req
= sci_req
;