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.
57 #include "scic_controller.h"
58 #include "scic_io_request.h"
59 #include "scic_sds_controller.h"
60 #include "scu_registers.h"
61 #include "scic_sds_port.h"
62 #include "remote_device.h"
63 #include "scic_sds_request.h"
64 #include "scic_sds_smp_request.h"
65 #include "scic_sds_stp_request.h"
66 #include "scic_sds_unsolicited_frame_control.h"
67 #include "sci_environment.h"
69 #include "scu_completion_codes.h"
70 #include "scu_constants.h"
71 #include "scu_task_context.h"
74 * ****************************************************************************
75 * * SCIC SDS IO REQUEST CONSTANTS
76 * **************************************************************************** */
81 * We have no timer requirements for IO requests right now
83 #define SCIC_SDS_IO_REQUEST_MINIMUM_TIMER_COUNT (0)
84 #define SCIC_SDS_IO_REQUEST_MAXIMUM_TIMER_COUNT (0)
87 * ****************************************************************************
88 * * SCIC SDS IO REQUEST MACROS
89 * **************************************************************************** */
92 * scic_ssp_io_request_get_object_size() -
94 * This macro returns the sizeof memory required to store the an SSP IO
95 * request. This does not include the size of the SGL or SCU Task Context
98 #define scic_ssp_io_request_get_object_size() \
100 sizeof(struct ssp_cmd_iu) \
101 + SSP_RESP_IU_MAX_SIZE \
105 * scic_sds_ssp_request_get_command_buffer() -
107 * This macro returns the address of the ssp command buffer in the io request
110 #define scic_sds_ssp_request_get_command_buffer(memory) \
111 ((struct ssp_cmd_iu *)(\
112 ((char *)(memory)) + sizeof(struct scic_sds_request) \
116 * scic_sds_ssp_request_get_response_buffer() -
118 * This macro returns the address of the ssp response buffer in the io request
121 #define scic_sds_ssp_request_get_response_buffer(memory) \
122 ((struct ssp_response_iu *)(\
123 ((char *)(scic_sds_ssp_request_get_command_buffer(memory))) \
124 + sizeof(struct ssp_cmd_iu) \
128 * scic_sds_ssp_request_get_task_context_buffer() -
130 * This macro returns the address of the task context buffer in the io request
133 #define scic_sds_ssp_request_get_task_context_buffer(memory) \
134 ((struct scu_task_context *)(\
135 ((char *)(scic_sds_ssp_request_get_response_buffer(memory))) \
136 + SSP_RESP_IU_MAX_SIZE \
140 * scic_sds_ssp_request_get_sgl_element_buffer() -
142 * This macro returns the address of the sgl elment pairs in the io request
145 #define scic_sds_ssp_request_get_sgl_element_buffer(memory) \
146 ((struct scu_sgl_element_pair *)(\
147 ((char *)(scic_sds_ssp_request_get_task_context_buffer(memory))) \
148 + sizeof(struct scu_task_context) \
153 * scic_ssp_task_request_get_object_size() -
155 * This macro returns the sizeof of memory required to store an SSP Task
156 * request. This does not include the size of the SCU Task Context memory.
158 #define scic_ssp_task_request_get_object_size() \
160 sizeof(struct ssp_task_iu) \
161 + SSP_RESP_IU_MAX_SIZE \
165 * scic_sds_ssp_task_request_get_command_buffer() -
167 * This macro returns the address of the ssp command buffer in the task request
168 * memory. Yes its the same as the above macro except for the name.
170 #define scic_sds_ssp_task_request_get_command_buffer(memory) \
171 ((struct ssp_task_iu *)(\
172 ((char *)(memory)) + sizeof(struct scic_sds_request) \
176 * scic_sds_ssp_task_request_get_response_buffer() -
178 * This macro returns the address of the ssp response buffer in the task
181 #define scic_sds_ssp_task_request_get_response_buffer(memory) \
182 ((struct ssp_response_iu *)(\
183 ((char *)(scic_sds_ssp_task_request_get_command_buffer(memory))) \
184 + sizeof(struct ssp_task_iu) \
188 * scic_sds_ssp_task_request_get_task_context_buffer() -
190 * This macro returs the task context buffer for the SSP task request.
192 #define scic_sds_ssp_task_request_get_task_context_buffer(memory) \
193 ((struct scu_task_context *)(\
194 ((char *)(scic_sds_ssp_task_request_get_response_buffer(memory))) \
195 + SSP_RESP_IU_MAX_SIZE \
201 * ****************************************************************************
202 * * SCIC SDS IO REQUEST PRIVATE METHODS
203 * **************************************************************************** */
208 * This method returns the size required to store an SSP IO request object. u32
210 static u32
scic_sds_ssp_request_get_object_size(void)
212 return sizeof(struct scic_sds_request
)
213 + scic_ssp_io_request_get_object_size()
214 + sizeof(struct scu_task_context
)
216 + sizeof(struct scu_sgl_element_pair
) * SCU_MAX_SGL_ELEMENT_PAIRS
;
220 * This method returns the sgl element pair for the specificed sgl_pair index.
221 * @sci_req: This parameter specifies the IO request for which to retrieve
222 * the Scatter-Gather List element pair.
223 * @sgl_pair_index: This parameter specifies the index into the SGL element
224 * pair to be retrieved.
226 * This method returns a pointer to an struct scu_sgl_element_pair.
228 static struct scu_sgl_element_pair
*scic_sds_request_get_sgl_element_pair(
229 struct scic_sds_request
*sci_req
,
232 struct scu_task_context
*task_context
;
234 task_context
= (struct scu_task_context
*)sci_req
->task_context_buffer
;
236 if (sgl_pair_index
== 0) {
237 return &task_context
->sgl_pair_ab
;
238 } else if (sgl_pair_index
== 1) {
239 return &task_context
->sgl_pair_cd
;
242 return &sci_req
->sgl_element_pair_buffer
[sgl_pair_index
- 2];
246 * This function will build the SGL list for an IO request.
247 * @sci_req: This parameter specifies the IO request for which to build
248 * the Scatter-Gather List.
251 void scic_sds_request_build_sgl(struct scic_sds_request
*sds_request
)
253 struct isci_request
*isci_request
= sds_request
->ireq
;
254 struct isci_host
*isci_host
= isci_request
->isci_host
;
255 struct sas_task
*task
= isci_request_access_task(isci_request
);
256 struct scatterlist
*sg
= NULL
;
259 struct scu_sgl_element_pair
*scu_sg
= NULL
;
260 struct scu_sgl_element_pair
*prev_sg
= NULL
;
262 if (task
->num_scatter
> 0) {
266 scu_sg
= scic_sds_request_get_sgl_element_pair(
270 SCU_SGL_COPY(scu_sg
->A
, sg
);
275 SCU_SGL_COPY(scu_sg
->B
, sg
);
278 SCU_SGL_ZERO(scu_sg
->B
);
282 scic_io_request_get_dma_addr(
286 prev_sg
->next_pair_upper
=
287 upper_32_bits(dma_addr
);
288 prev_sg
->next_pair_lower
=
289 lower_32_bits(dma_addr
);
295 } else { /* handle when no sg */
296 scu_sg
= scic_sds_request_get_sgl_element_pair(sds_request
,
299 dma_addr
= dma_map_single(&isci_host
->pdev
->dev
,
301 task
->total_xfer_len
,
304 isci_request
->zero_scatter_daddr
= dma_addr
;
306 scu_sg
->A
.length
= task
->total_xfer_len
;
307 scu_sg
->A
.address_upper
= upper_32_bits(dma_addr
);
308 scu_sg
->A
.address_lower
= lower_32_bits(dma_addr
);
312 scu_sg
->next_pair_upper
= 0;
313 scu_sg
->next_pair_lower
= 0;
318 * This method build the remainder of the IO request object.
319 * @sci_req: This parameter specifies the request object being constructed.
321 * The scic_sds_general_request_construct() must be called before this call is
324 static void scic_sds_ssp_io_request_assign_buffers(
325 struct scic_sds_request
*sci_req
)
327 sci_req
->command_buffer
=
328 scic_sds_ssp_request_get_command_buffer(sci_req
);
329 sci_req
->response_buffer
=
330 scic_sds_ssp_request_get_response_buffer(sci_req
);
331 sci_req
->sgl_element_pair_buffer
=
332 scic_sds_ssp_request_get_sgl_element_buffer(sci_req
);
333 sci_req
->sgl_element_pair_buffer
=
334 PTR_ALIGN(sci_req
->sgl_element_pair_buffer
,
335 sizeof(struct scu_sgl_element_pair
));
337 if (sci_req
->was_tag_assigned_by_user
== false) {
338 sci_req
->task_context_buffer
=
339 scic_sds_ssp_request_get_task_context_buffer(sci_req
);
340 sci_req
->task_context_buffer
=
341 PTR_ALIGN(sci_req
->task_context_buffer
,
346 static void scic_sds_io_request_build_ssp_command_iu(struct scic_sds_request
*sci_req
)
348 struct ssp_cmd_iu
*cmd_iu
;
349 struct isci_request
*ireq
= sci_req
->ireq
;
350 struct sas_task
*task
= isci_request_access_task(ireq
);
352 cmd_iu
= sci_req
->command_buffer
;
354 memcpy(cmd_iu
->LUN
, task
->ssp_task
.LUN
, 8);
355 cmd_iu
->add_cdb_len
= 0;
358 cmd_iu
->en_fburst
= 0; /* unsupported */
359 cmd_iu
->task_prio
= task
->ssp_task
.task_prio
;
360 cmd_iu
->task_attr
= task
->ssp_task
.task_attr
;
363 sci_swab32_cpy(&cmd_iu
->cdb
, task
->ssp_task
.cdb
,
364 sizeof(task
->ssp_task
.cdb
) / sizeof(u32
));
367 static void scic_sds_task_request_build_ssp_task_iu(struct scic_sds_request
*sci_req
)
369 struct ssp_task_iu
*task_iu
;
370 struct isci_request
*ireq
= sci_req
->ireq
;
371 struct sas_task
*task
= isci_request_access_task(ireq
);
372 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(ireq
);
374 task_iu
= sci_req
->command_buffer
;
376 memset(task_iu
, 0, sizeof(struct ssp_task_iu
));
378 memcpy(task_iu
->LUN
, task
->ssp_task
.LUN
, 8);
380 task_iu
->task_func
= isci_tmf
->tmf_code
;
382 (ireq
->ttype
== tmf_task
) ?
384 SCI_CONTROLLER_INVALID_IO_TAG
;
388 * This method is will fill in the SCU Task Context for any type of SSP request.
393 static void scu_ssp_reqeust_construct_task_context(
394 struct scic_sds_request
*sds_request
,
395 struct scu_task_context
*task_context
)
398 struct scic_sds_controller
*controller
;
399 struct scic_sds_remote_device
*target_device
;
400 struct scic_sds_port
*target_port
;
402 controller
= scic_sds_request_get_controller(sds_request
);
403 target_device
= scic_sds_request_get_device(sds_request
);
404 target_port
= scic_sds_request_get_port(sds_request
);
406 /* Fill in the TC with the its required data */
407 task_context
->abort
= 0;
408 task_context
->priority
= 0;
409 task_context
->initiator_request
= 1;
410 task_context
->connection_rate
= target_device
->connection_rate
;
411 task_context
->protocol_engine_index
=
412 scic_sds_controller_get_protocol_engine_group(controller
);
413 task_context
->logical_port_index
=
414 scic_sds_port_get_index(target_port
);
415 task_context
->protocol_type
= SCU_TASK_CONTEXT_PROTOCOL_SSP
;
416 task_context
->valid
= SCU_TASK_CONTEXT_VALID
;
417 task_context
->context_type
= SCU_TASK_CONTEXT_TYPE
;
419 task_context
->remote_node_index
=
420 scic_sds_remote_device_get_index(sds_request
->target_device
);
421 task_context
->command_code
= 0;
423 task_context
->link_layer_control
= 0;
424 task_context
->do_not_dma_ssp_good_response
= 1;
425 task_context
->strict_ordering
= 0;
426 task_context
->control_frame
= 0;
427 task_context
->timeout_enable
= 0;
428 task_context
->block_guard_enable
= 0;
430 task_context
->address_modifier
= 0;
432 /* task_context->type.ssp.tag = sci_req->io_tag; */
433 task_context
->task_phase
= 0x01;
435 if (sds_request
->was_tag_assigned_by_user
) {
437 * Build the task context now since we have already read
440 sds_request
->post_context
=
441 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
442 (scic_sds_controller_get_protocol_engine_group(
444 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
) |
445 (scic_sds_port_get_index(target_port
) <<
446 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
) |
447 scic_sds_io_tag_get_index(sds_request
->io_tag
));
450 * Build the task context now since we have already read
453 * I/O tag index is not assigned because we have to wait
456 sds_request
->post_context
=
457 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC
|
458 (scic_sds_controller_get_protocol_engine_group(
459 owning_controller
) <<
460 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT
) |
461 (scic_sds_port_get_index(target_port
) <<
462 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT
));
466 * Copy the physical address for the command buffer to the
469 dma_addr
= scic_io_request_get_dma_addr(sds_request
,
470 sds_request
->command_buffer
);
472 task_context
->command_iu_upper
= upper_32_bits(dma_addr
);
473 task_context
->command_iu_lower
= lower_32_bits(dma_addr
);
476 * Copy the physical address for the response buffer to the
479 dma_addr
= scic_io_request_get_dma_addr(sds_request
,
480 sds_request
->response_buffer
);
482 task_context
->response_iu_upper
= upper_32_bits(dma_addr
);
483 task_context
->response_iu_lower
= lower_32_bits(dma_addr
);
487 * This method is will fill in the SCU Task Context for a SSP IO request.
491 static void scu_ssp_io_request_construct_task_context(
492 struct scic_sds_request
*sci_req
,
493 enum dma_data_direction dir
,
496 struct scu_task_context
*task_context
;
498 task_context
= scic_sds_request_get_task_context(sci_req
);
500 scu_ssp_reqeust_construct_task_context(sci_req
, task_context
);
502 task_context
->ssp_command_iu_length
=
503 sizeof(struct ssp_cmd_iu
) / sizeof(u32
);
504 task_context
->type
.ssp
.frame_type
= SSP_COMMAND
;
507 case DMA_FROM_DEVICE
:
510 task_context
->task_type
= SCU_TASK_TYPE_IOREAD
;
513 task_context
->task_type
= SCU_TASK_TYPE_IOWRITE
;
517 task_context
->transfer_length_bytes
= len
;
519 if (task_context
->transfer_length_bytes
> 0)
520 scic_sds_request_build_sgl(sci_req
);
525 * This method will fill in the remainder of the io request object for SSP Task
530 static void scic_sds_ssp_task_request_assign_buffers(
531 struct scic_sds_request
*sci_req
)
533 /* Assign all of the buffer pointers */
534 sci_req
->command_buffer
=
535 scic_sds_ssp_task_request_get_command_buffer(sci_req
);
536 sci_req
->response_buffer
=
537 scic_sds_ssp_task_request_get_response_buffer(sci_req
);
538 sci_req
->sgl_element_pair_buffer
= NULL
;
540 if (sci_req
->was_tag_assigned_by_user
== false) {
541 sci_req
->task_context_buffer
=
542 scic_sds_ssp_task_request_get_task_context_buffer(sci_req
);
543 sci_req
->task_context_buffer
=
544 PTR_ALIGN(sci_req
->task_context_buffer
, SMP_CACHE_BYTES
);
549 * This method will fill in the SCU Task Context for a SSP Task request. The
550 * following important settings are utilized: -# priority ==
551 * SCU_TASK_PRIORITY_HIGH. This ensures that the task request is issued
552 * ahead of other task destined for the same Remote Node. -# task_type ==
553 * SCU_TASK_TYPE_IOREAD. This simply indicates that a normal request type
554 * (i.e. non-raw frame) is being utilized to perform task management. -#
555 * control_frame == 1. This ensures that the proper endianess is set so
556 * that the bytes are transmitted in the right order for a task frame.
557 * @sci_req: This parameter specifies the task request object being
561 static void scu_ssp_task_request_construct_task_context(
562 struct scic_sds_request
*sci_req
)
564 struct scu_task_context
*task_context
;
566 task_context
= scic_sds_request_get_task_context(sci_req
);
568 scu_ssp_reqeust_construct_task_context(sci_req
, task_context
);
570 task_context
->control_frame
= 1;
571 task_context
->priority
= SCU_TASK_PRIORITY_HIGH
;
572 task_context
->task_type
= SCU_TASK_TYPE_RAW_FRAME
;
573 task_context
->transfer_length_bytes
= 0;
574 task_context
->type
.ssp
.frame_type
= SSP_TASK
;
575 task_context
->ssp_command_iu_length
=
576 sizeof(struct ssp_task_iu
) / sizeof(u32
);
581 * This method constructs the SSP Command IU data for this ssp passthrough
582 * comand request object.
583 * @sci_req: This parameter specifies the request object for which the SSP
584 * command information unit is being built.
586 * enum sci_status, returns invalid parameter is cdb > 16
591 * This method constructs the SATA request object.
600 static enum sci_status
601 scic_io_request_construct_sata(struct scic_sds_request
*sci_req
,
603 enum dma_data_direction dir
,
606 enum sci_status status
= SCI_SUCCESS
;
607 struct isci_request
*ireq
= sci_req
->ireq
;
608 struct sas_task
*task
= isci_request_access_task(ireq
);
610 /* check for management protocols */
611 if (ireq
->ttype
== tmf_task
) {
612 struct isci_tmf
*tmf
= isci_request_access_tmf(ireq
);
614 if (tmf
->tmf_code
== isci_tmf_sata_srst_high
||
615 tmf
->tmf_code
== isci_tmf_sata_srst_low
)
616 return scic_sds_stp_soft_reset_request_construct(sci_req
);
618 dev_err(scic_to_dev(sci_req
->owning_controller
),
619 "%s: Request 0x%p received un-handled SAT "
620 "management protocol 0x%x.\n",
621 __func__
, sci_req
, tmf
->tmf_code
);
627 if (!sas_protocol_ata(task
->task_proto
)) {
628 dev_err(scic_to_dev(sci_req
->owning_controller
),
629 "%s: Non-ATA protocol in SATA path: 0x%x\n",
637 if (task
->data_dir
== DMA_NONE
)
638 return scic_sds_stp_non_data_request_construct(sci_req
);
641 if (task
->ata_task
.use_ncq
)
642 return scic_sds_stp_ncq_request_construct(sci_req
, len
, dir
);
645 if (task
->ata_task
.dma_xfer
)
646 return scic_sds_stp_udma_request_construct(sci_req
, len
, dir
);
648 return scic_sds_stp_pio_request_construct(sci_req
, copy
);
653 u32
scic_io_request_get_object_size(void)
655 u32 ssp_request_size
;
656 u32 stp_request_size
;
657 u32 smp_request_size
;
659 ssp_request_size
= scic_sds_ssp_request_get_object_size();
660 stp_request_size
= scic_sds_stp_request_get_object_size();
661 smp_request_size
= scic_sds_smp_request_get_object_size();
663 return max(ssp_request_size
, max(stp_request_size
, smp_request_size
));
666 enum sci_status
scic_io_request_construct_basic_ssp(
667 struct scic_sds_request
*sci_req
)
669 struct isci_request
*isci_request
= sci_req
->ireq
;
671 sci_req
->protocol
= SCIC_SSP_PROTOCOL
;
673 scu_ssp_io_request_construct_task_context(
675 isci_request_io_request_get_data_direction(isci_request
),
676 isci_request_io_request_get_transfer_length(isci_request
));
678 scic_sds_io_request_build_ssp_command_iu(sci_req
);
680 sci_base_state_machine_change_state(&sci_req
->state_machine
,
681 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
687 enum sci_status
scic_task_request_construct_ssp(
688 struct scic_sds_request
*sci_req
)
690 /* Construct the SSP Task SCU Task Context */
691 scu_ssp_task_request_construct_task_context(sci_req
);
693 /* Fill in the SSP Task IU */
694 scic_sds_task_request_build_ssp_task_iu(sci_req
);
696 sci_base_state_machine_change_state(&sci_req
->state_machine
,
697 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
703 enum sci_status
scic_io_request_construct_basic_sata(
704 struct scic_sds_request
*sci_req
)
706 enum sci_status status
;
707 struct scic_sds_stp_request
*stp_req
;
709 enum dma_data_direction dir
;
711 struct isci_request
*isci_request
= sci_req
->ireq
;
712 struct sas_task
*task
= isci_request_access_task(isci_request
);
714 stp_req
= container_of(sci_req
, typeof(*stp_req
), parent
);
716 sci_req
->protocol
= SCIC_STP_PROTOCOL
;
718 len
= isci_request_io_request_get_transfer_length(isci_request
);
719 dir
= isci_request_io_request_get_data_direction(isci_request
);
720 copy
= (task
->data_dir
== DMA_NONE
) ? false : true;
722 status
= scic_io_request_construct_sata(sci_req
, len
, dir
, copy
);
724 if (status
== SCI_SUCCESS
)
725 sci_base_state_machine_change_state(&sci_req
->state_machine
,
726 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
732 enum sci_status
scic_task_request_construct_sata(
733 struct scic_sds_request
*sci_req
)
735 enum sci_status status
= SCI_SUCCESS
;
736 struct isci_request
*ireq
= sci_req
->ireq
;
738 /* check for management protocols */
739 if (ireq
->ttype
== tmf_task
) {
740 struct isci_tmf
*tmf
= isci_request_access_tmf(ireq
);
742 if (tmf
->tmf_code
== isci_tmf_sata_srst_high
||
743 tmf
->tmf_code
== isci_tmf_sata_srst_low
) {
744 status
= scic_sds_stp_soft_reset_request_construct(sci_req
);
746 dev_err(scic_to_dev(sci_req
->owning_controller
),
747 "%s: Request 0x%p received un-handled SAT "
749 __func__
, sci_req
, tmf
->tmf_code
);
755 if (status
== SCI_SUCCESS
)
756 sci_base_state_machine_change_state(
757 &sci_req
->state_machine
,
758 SCI_BASE_REQUEST_STATE_CONSTRUCTED
);
764 u16
scic_io_request_get_io_tag(
765 struct scic_sds_request
*sci_req
)
767 return sci_req
->io_tag
;
771 u32
scic_request_get_controller_status(
772 struct scic_sds_request
*sci_req
)
774 return sci_req
->scu_status
;
778 void *scic_io_request_get_command_iu_address(
779 struct scic_sds_request
*sci_req
)
781 return sci_req
->command_buffer
;
785 void *scic_io_request_get_response_iu_address(
786 struct scic_sds_request
*sci_req
)
788 return sci_req
->response_buffer
;
792 #define SCU_TASK_CONTEXT_SRAM 0x200000
793 u32
scic_io_request_get_number_of_bytes_transferred(
794 struct scic_sds_request
*scic_sds_request
)
796 struct scic_sds_controller
*scic
= scic_sds_request
->owning_controller
;
799 if (readl(&scic
->smu_registers
->address_modifier
) == 0) {
800 void __iomem
*scu_reg_base
= scic
->scu_registers
;
802 * get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
803 * BAR1 is the scu_registers
804 * 0x20002C = 0x200000 + 0x2c
805 * = start of task context SRAM + offset of (type.ssp.data_offset)
806 * TCi is the io_tag of struct scic_sds_request */
807 ret_val
= readl(scu_reg_base
+
808 (SCU_TASK_CONTEXT_SRAM
+ offsetof(struct scu_task_context
, type
.ssp
.data_offset
)) +
809 ((sizeof(struct scu_task_context
)) * scic_sds_io_tag_get_index(scic_sds_request
->io_tag
)));
817 * ****************************************************************************
818 * * SCIC SDS Interface Implementation
819 * **************************************************************************** */
822 scic_sds_request_start(struct scic_sds_request
*request
)
824 if (request
->device_sequence
!=
825 scic_sds_remote_device_get_sequence(request
->target_device
))
828 if (request
->state_handlers
->start_handler
)
829 return request
->state_handlers
->start_handler(request
);
831 dev_warn(scic_to_dev(request
->owning_controller
),
832 "%s: SCIC IO Request requested to start while in wrong "
835 sci_base_state_machine_get_state(&request
->state_machine
));
837 return SCI_FAILURE_INVALID_STATE
;
841 scic_sds_io_request_terminate(struct scic_sds_request
*request
)
843 if (request
->state_handlers
->abort_handler
)
844 return request
->state_handlers
->abort_handler(request
);
846 dev_warn(scic_to_dev(request
->owning_controller
),
847 "%s: SCIC IO Request requested to abort while in wrong "
850 sci_base_state_machine_get_state(&request
->state_machine
));
852 return SCI_FAILURE_INVALID_STATE
;
856 scic_sds_io_request_complete(struct scic_sds_request
*request
)
858 if (request
->state_handlers
->complete_handler
)
859 return request
->state_handlers
->complete_handler(request
);
861 dev_warn(scic_to_dev(request
->owning_controller
),
862 "%s: SCIC IO Request requested to complete while in wrong "
865 sci_base_state_machine_get_state(&request
->state_machine
));
867 return SCI_FAILURE_INVALID_STATE
;
870 enum sci_status
scic_sds_io_request_event_handler(
871 struct scic_sds_request
*request
,
874 if (request
->state_handlers
->event_handler
)
875 return request
->state_handlers
->event_handler(request
, event_code
);
877 dev_warn(scic_to_dev(request
->owning_controller
),
878 "%s: SCIC IO Request given event code notification %x while "
879 "in wrong state %d\n",
882 sci_base_state_machine_get_state(&request
->state_machine
));
884 return SCI_FAILURE_INVALID_STATE
;
888 scic_sds_io_request_tc_completion(struct scic_sds_request
*request
, u32 completion_code
)
890 if (request
->state_machine
.current_state_id
== SCI_BASE_REQUEST_STATE_STARTED
&&
891 request
->has_started_substate_machine
== false)
892 return scic_sds_request_started_state_tc_completion_handler(request
, completion_code
);
893 else if (request
->state_handlers
->tc_completion_handler
)
894 return request
->state_handlers
->tc_completion_handler(request
, completion_code
);
896 dev_warn(scic_to_dev(request
->owning_controller
),
897 "%s: SCIC IO Request given task completion notification %x "
898 "while in wrong state %d\n",
901 sci_base_state_machine_get_state(&request
->state_machine
));
903 return SCI_FAILURE_INVALID_STATE
;
910 * @sci_req: The SCIC_SDS_IO_REQUEST_T object for which the start
911 * operation is to be executed.
912 * @frame_index: The frame index returned by the hardware for the reqeust
915 * This method invokes the core state frame handler for the
916 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
918 enum sci_status
scic_sds_io_request_frame_handler(
919 struct scic_sds_request
*request
,
922 if (request
->state_handlers
->frame_handler
)
923 return request
->state_handlers
->frame_handler(request
, frame_index
);
925 dev_warn(scic_to_dev(request
->owning_controller
),
926 "%s: SCIC IO Request given unexpected frame %x while in "
930 sci_base_state_machine_get_state(&request
->state_machine
));
932 scic_sds_controller_release_frame(request
->owning_controller
, frame_index
);
933 return SCI_FAILURE_INVALID_STATE
;
937 * This function copies response data for requests returning response data
938 * instead of sense data.
939 * @sci_req: This parameter specifies the request object for which to copy
942 void scic_sds_io_request_copy_response(struct scic_sds_request
*sci_req
)
946 struct ssp_response_iu
*ssp_response
;
947 struct isci_request
*ireq
= sci_req
->ireq
;
948 struct isci_tmf
*isci_tmf
= isci_request_access_tmf(ireq
);
950 ssp_response
= sci_req
->response_buffer
;
952 resp_buf
= &isci_tmf
->resp
.resp_iu
;
955 SSP_RESP_IU_MAX_SIZE
,
956 be32_to_cpu(ssp_response
->response_data_len
));
958 memcpy(resp_buf
, ssp_response
->resp_data
, len
);
962 * *****************************************************************************
963 * * CONSTRUCTED STATE HANDLERS
964 * ***************************************************************************** */
967 * This method implements the action taken when a constructed
968 * SCIC_SDS_IO_REQUEST_T object receives a scic_sds_request_start() request.
969 * This method will, if necessary, allocate a TCi for the io request object and
970 * then will, if necessary, copy the constructed TC data into the actual TC
971 * buffer. If everything is successful the post context field is updated with
972 * the TCi so the controller can post the request to the hardware. enum sci_status
973 * SCI_SUCCESS SCI_FAILURE_INSUFFICIENT_RESOURCES
975 static enum sci_status
scic_sds_request_constructed_state_start_handler(
976 struct scic_sds_request
*request
)
978 struct scu_task_context
*task_context
;
980 if (request
->io_tag
== SCI_CONTROLLER_INVALID_IO_TAG
) {
982 scic_controller_allocate_io_tag(request
->owning_controller
);
985 /* Record the IO Tag in the request */
986 if (request
->io_tag
!= SCI_CONTROLLER_INVALID_IO_TAG
) {
987 task_context
= request
->task_context_buffer
;
989 task_context
->task_index
= scic_sds_io_tag_get_index(request
->io_tag
);
991 switch (task_context
->protocol_type
) {
992 case SCU_TASK_CONTEXT_PROTOCOL_SMP
:
993 case SCU_TASK_CONTEXT_PROTOCOL_SSP
:
995 task_context
->type
.ssp
.tag
= request
->io_tag
;
996 task_context
->type
.ssp
.target_port_transfer_tag
= 0xFFFF;
999 case SCU_TASK_CONTEXT_PROTOCOL_STP
:
1002 * task_context->type.stp.ncq_tag = request->ncq_tag; */
1005 case SCU_TASK_CONTEXT_PROTOCOL_NONE
:
1006 /* / @todo When do we set no protocol type? */
1010 /* This should never happen since we build the IO requests */
1015 * Check to see if we need to copy the task context buffer
1016 * or have been building into the task context buffer */
1017 if (request
->was_tag_assigned_by_user
== false) {
1018 scic_sds_controller_copy_task_context(
1019 request
->owning_controller
, request
);
1022 /* Add to the post_context the io tag value */
1023 request
->post_context
|= scic_sds_io_tag_get_index(request
->io_tag
);
1025 /* Everything is good go ahead and change state */
1026 sci_base_state_machine_change_state(&request
->state_machine
,
1027 SCI_BASE_REQUEST_STATE_STARTED
);
1032 return SCI_FAILURE_INSUFFICIENT_RESOURCES
;
1036 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1037 * object receives a scic_sds_request_terminate() request. Since the request
1038 * has not yet been posted to the hardware the request transitions to the
1039 * completed state. enum sci_status SCI_SUCCESS
1041 static enum sci_status
scic_sds_request_constructed_state_abort_handler(
1042 struct scic_sds_request
*request
)
1045 * This request has been terminated by the user make sure that the correct
1046 * status code is returned */
1047 scic_sds_request_set_status(request
,
1048 SCU_TASK_DONE_TASK_ABORT
,
1049 SCI_FAILURE_IO_TERMINATED
);
1051 sci_base_state_machine_change_state(&request
->state_machine
,
1052 SCI_BASE_REQUEST_STATE_COMPLETED
);
1057 * *****************************************************************************
1058 * * STARTED STATE HANDLERS
1059 * ***************************************************************************** */
1062 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1063 * object receives a scic_sds_request_terminate() request. Since the request
1064 * has been posted to the hardware the io request state is changed to the
1065 * aborting state. enum sci_status SCI_SUCCESS
1067 enum sci_status
scic_sds_request_started_state_abort_handler(
1068 struct scic_sds_request
*request
)
1070 if (request
->has_started_substate_machine
)
1071 sci_base_state_machine_stop(&request
->started_substate_machine
);
1073 sci_base_state_machine_change_state(&request
->state_machine
,
1074 SCI_BASE_REQUEST_STATE_ABORTING
);
1079 * scic_sds_request_started_state_tc_completion_handler() - This method process
1080 * TC (task context) completions for normal IO request (i.e. Task/Abort
1081 * Completions of type 0). This method will update the
1082 * SCIC_SDS_IO_REQUEST_T::status field.
1083 * @sci_req: This parameter specifies the request for which a completion
1085 * @completion_code: This parameter specifies the completion code received from
1090 scic_sds_request_started_state_tc_completion_handler(
1091 struct scic_sds_request
*sci_req
,
1092 u32 completion_code
)
1095 struct ssp_response_iu
*resp_iu
;
1098 * TODO: Any SDMA return code of other than 0 is bad
1099 * decode 0x003C0000 to determine SDMA status
1101 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1102 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD
):
1103 scic_sds_request_set_status(sci_req
,
1108 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP
):
1111 * There are times when the SCU hardware will return an early
1112 * response because the io request specified more data than is
1113 * returned by the target device (mode pages, inquiry data,
1114 * etc.). We must check the response stats to see if this is
1115 * truly a failed request or a good request that just got
1118 struct ssp_response_iu
*resp
= sci_req
->response_buffer
;
1119 ssize_t word_cnt
= SSP_RESP_IU_MAX_SIZE
/ sizeof(u32
);
1121 sci_swab32_cpy(sci_req
->response_buffer
,
1122 sci_req
->response_buffer
,
1125 if (resp
->status
== 0) {
1126 scic_sds_request_set_status(
1129 SCI_SUCCESS_IO_DONE_EARLY
);
1131 scic_sds_request_set_status(
1133 SCU_TASK_DONE_CHECK_RESPONSE
,
1134 SCI_FAILURE_IO_RESPONSE_VALID
);
1139 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE
):
1141 ssize_t word_cnt
= SSP_RESP_IU_MAX_SIZE
/ sizeof(u32
);
1143 sci_swab32_cpy(sci_req
->response_buffer
,
1144 sci_req
->response_buffer
,
1147 scic_sds_request_set_status(sci_req
,
1148 SCU_TASK_DONE_CHECK_RESPONSE
,
1149 SCI_FAILURE_IO_RESPONSE_VALID
);
1153 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR
):
1155 * / @todo With TASK_DONE_RESP_LEN_ERR is the response frame
1156 * guaranteed to be received before this completion status is
1159 resp_iu
= sci_req
->response_buffer
;
1160 datapres
= resp_iu
->datapres
;
1162 if ((datapres
== 0x01) || (datapres
== 0x02)) {
1163 scic_sds_request_set_status(
1165 SCU_TASK_DONE_CHECK_RESPONSE
,
1166 SCI_FAILURE_IO_RESPONSE_VALID
);
1168 scic_sds_request_set_status(
1169 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
);
1172 /* only stp device gets suspended. */
1173 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO
):
1174 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR
):
1175 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR
):
1176 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR
):
1177 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR
):
1178 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN
):
1179 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR
):
1180 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP
):
1181 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS
):
1182 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR
):
1183 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR
):
1184 if (sci_req
->protocol
== SCIC_STP_PROTOCOL
) {
1185 scic_sds_request_set_status(
1187 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >>
1188 SCU_COMPLETION_TL_STATUS_SHIFT
,
1189 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
);
1191 scic_sds_request_set_status(
1193 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >>
1194 SCU_COMPLETION_TL_STATUS_SHIFT
,
1195 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
);
1199 /* both stp/ssp device gets suspended */
1200 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR
):
1201 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION
):
1202 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1
):
1203 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2
):
1204 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3
):
1205 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION
):
1206 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION
):
1207 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY
):
1208 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED
):
1209 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED
):
1210 scic_sds_request_set_status(
1212 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >>
1213 SCU_COMPLETION_TL_STATUS_SHIFT
,
1214 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
);
1217 /* neither ssp nor stp gets suspended. */
1218 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR
):
1219 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR
):
1220 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR
):
1221 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR
):
1222 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR
):
1223 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA
):
1224 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR
):
1225 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR
):
1226 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR
):
1227 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR
):
1228 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA
):
1229 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL
):
1230 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV
):
1231 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV
):
1232 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND
):
1234 scic_sds_request_set_status(
1236 SCU_GET_COMPLETION_TL_STATUS(completion_code
) >>
1237 SCU_COMPLETION_TL_STATUS_SHIFT
,
1238 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
);
1243 * TODO: This is probably wrong for ACK/NAK timeout conditions
1246 /* In all cases we will treat this as the completion of the IO req. */
1247 sci_base_state_machine_change_state(
1248 &sci_req
->state_machine
,
1249 SCI_BASE_REQUEST_STATE_COMPLETED
);
1254 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1255 * object receives a scic_sds_request_frame_handler() request. This method
1256 * first determines the frame type received. If this is a response frame then
1257 * the response data is copied to the io request response buffer for processing
1258 * at completion time. If the frame type is not a response buffer an error is
1259 * logged. enum sci_status SCI_SUCCESS SCI_FAILURE_INVALID_PARAMETER_VALUE
1261 static enum sci_status
1262 scic_sds_request_started_state_frame_handler(struct scic_sds_request
*sci_req
,
1265 enum sci_status status
;
1267 struct ssp_frame_hdr ssp_hdr
;
1270 status
= scic_sds_unsolicited_frame_control_get_header(
1271 &(scic_sds_request_get_controller(sci_req
)->uf_control
),
1273 (void **)&frame_header
);
1275 word_cnt
= sizeof(struct ssp_frame_hdr
) / sizeof(u32
);
1276 sci_swab32_cpy(&ssp_hdr
, frame_header
, word_cnt
);
1278 if (ssp_hdr
.frame_type
== SSP_RESPONSE
) {
1279 struct ssp_response_iu
*resp_iu
;
1280 ssize_t word_cnt
= SSP_RESP_IU_MAX_SIZE
/ sizeof(u32
);
1282 status
= scic_sds_unsolicited_frame_control_get_buffer(
1283 &(scic_sds_request_get_controller(sci_req
)->uf_control
),
1287 sci_swab32_cpy(sci_req
->response_buffer
,
1290 resp_iu
= sci_req
->response_buffer
;
1292 if ((resp_iu
->datapres
== 0x01) ||
1293 (resp_iu
->datapres
== 0x02)) {
1294 scic_sds_request_set_status(
1296 SCU_TASK_DONE_CHECK_RESPONSE
,
1297 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
);
1299 scic_sds_request_set_status(
1300 sci_req
, SCU_TASK_DONE_GOOD
, SCI_SUCCESS
);
1302 /* This was not a response frame why did it get forwarded? */
1303 dev_err(scic_to_dev(sci_req
->owning_controller
),
1304 "%s: SCIC IO Request 0x%p received unexpected "
1305 "frame %d type 0x%02x\n",
1309 ssp_hdr
.frame_type
);
1313 * In any case we are done with this frame buffer return it to the
1316 scic_sds_controller_release_frame(
1317 sci_req
->owning_controller
, frame_index
);
1323 * *****************************************************************************
1324 * * COMPLETED STATE HANDLERS
1325 * ***************************************************************************** */
1329 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1330 * object receives a scic_sds_request_complete() request. This method frees up
1331 * any io request resources that have been allocated and transitions the
1332 * request to its final state. Consider stopping the state machine instead of
1333 * transitioning to the final state? enum sci_status SCI_SUCCESS
1335 static enum sci_status
scic_sds_request_completed_state_complete_handler(
1336 struct scic_sds_request
*request
)
1338 if (request
->was_tag_assigned_by_user
!= true) {
1339 scic_controller_free_io_tag(
1340 request
->owning_controller
, request
->io_tag
);
1343 if (request
->saved_rx_frame_index
!= SCU_INVALID_FRAME_INDEX
) {
1344 scic_sds_controller_release_frame(
1345 request
->owning_controller
, request
->saved_rx_frame_index
);
1348 sci_base_state_machine_change_state(&request
->state_machine
,
1349 SCI_BASE_REQUEST_STATE_FINAL
);
1354 * *****************************************************************************
1355 * * ABORTING STATE HANDLERS
1356 * ***************************************************************************** */
1359 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1360 * object receives a scic_sds_request_terminate() request. This method is the
1361 * io request aborting state abort handlers. On receipt of a multiple
1362 * terminate requests the io request will transition to the completed state.
1363 * This should not happen in normal operation. enum sci_status SCI_SUCCESS
1365 static enum sci_status
scic_sds_request_aborting_state_abort_handler(
1366 struct scic_sds_request
*request
)
1368 sci_base_state_machine_change_state(&request
->state_machine
,
1369 SCI_BASE_REQUEST_STATE_COMPLETED
);
1374 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1375 * object receives a scic_sds_request_task_completion() request. This method
1376 * decodes the completion type waiting for the abort task complete
1377 * notification. When the abort task complete is received the io request
1378 * transitions to the completed state. enum sci_status SCI_SUCCESS
1380 static enum sci_status
scic_sds_request_aborting_state_tc_completion_handler(
1381 struct scic_sds_request
*sci_req
,
1382 u32 completion_code
)
1384 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code
)) {
1385 case (SCU_TASK_DONE_GOOD
<< SCU_COMPLETION_TL_STATUS_SHIFT
):
1386 case (SCU_TASK_DONE_TASK_ABORT
<< SCU_COMPLETION_TL_STATUS_SHIFT
):
1387 scic_sds_request_set_status(
1388 sci_req
, SCU_TASK_DONE_TASK_ABORT
, SCI_FAILURE_IO_TERMINATED
1391 sci_base_state_machine_change_state(&sci_req
->state_machine
,
1392 SCI_BASE_REQUEST_STATE_COMPLETED
);
1397 * Unless we get some strange error wait for the task abort to complete
1398 * TODO: Should there be a state change for this completion? */
1406 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1407 * object receives a scic_sds_request_frame_handler() request. This method
1408 * discards the unsolicited frame since we are waiting for the abort task
1409 * completion. enum sci_status SCI_SUCCESS
1411 static enum sci_status
scic_sds_request_aborting_state_frame_handler(
1412 struct scic_sds_request
*sci_req
,
1415 /* TODO: Is it even possible to get an unsolicited frame in the aborting state? */
1417 scic_sds_controller_release_frame(
1418 sci_req
->owning_controller
, frame_index
);
1423 static const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table
[] = {
1424 [SCI_BASE_REQUEST_STATE_INITIAL
] = {
1426 [SCI_BASE_REQUEST_STATE_CONSTRUCTED
] = {
1427 .start_handler
= scic_sds_request_constructed_state_start_handler
,
1428 .abort_handler
= scic_sds_request_constructed_state_abort_handler
,
1430 [SCI_BASE_REQUEST_STATE_STARTED
] = {
1431 .abort_handler
= scic_sds_request_started_state_abort_handler
,
1432 .tc_completion_handler
= scic_sds_request_started_state_tc_completion_handler
,
1433 .frame_handler
= scic_sds_request_started_state_frame_handler
,
1435 [SCI_BASE_REQUEST_STATE_COMPLETED
] = {
1436 .complete_handler
= scic_sds_request_completed_state_complete_handler
,
1438 [SCI_BASE_REQUEST_STATE_ABORTING
] = {
1439 .abort_handler
= scic_sds_request_aborting_state_abort_handler
,
1440 .tc_completion_handler
= scic_sds_request_aborting_state_tc_completion_handler
,
1441 .frame_handler
= scic_sds_request_aborting_state_frame_handler
,
1443 [SCI_BASE_REQUEST_STATE_FINAL
] = {
1448 * scic_sds_request_initial_state_enter() -
1449 * @object: This parameter specifies the base object for which the state
1450 * transition is occurring.
1452 * This method implements the actions taken when entering the
1453 * SCI_BASE_REQUEST_STATE_INITIAL state. This state is entered when the initial
1454 * base request is constructed. Entry into the initial state sets all handlers
1455 * for the io request object to their default handlers. none
1457 static void scic_sds_request_initial_state_enter(void *object
)
1459 struct scic_sds_request
*sci_req
= object
;
1463 scic_sds_request_state_handler_table
,
1464 SCI_BASE_REQUEST_STATE_INITIAL
1469 * scic_sds_request_constructed_state_enter() -
1470 * @object: The io request object that is to enter the constructed state.
1472 * This method implements the actions taken when entering the
1473 * SCI_BASE_REQUEST_STATE_CONSTRUCTED state. The method sets the state handlers
1474 * for the the constructed state. none
1476 static void scic_sds_request_constructed_state_enter(void *object
)
1478 struct scic_sds_request
*sci_req
= object
;
1482 scic_sds_request_state_handler_table
,
1483 SCI_BASE_REQUEST_STATE_CONSTRUCTED
1488 * scic_sds_request_started_state_enter() -
1489 * @object: This parameter specifies the base object for which the state
1490 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
1492 * This method implements the actions taken when entering the
1493 * SCI_BASE_REQUEST_STATE_STARTED state. If the io request object type is a
1494 * SCSI Task request we must enter the started substate machine. none
1496 static void scic_sds_request_started_state_enter(void *object
)
1498 struct scic_sds_request
*sci_req
= object
;
1502 scic_sds_request_state_handler_table
,
1503 SCI_BASE_REQUEST_STATE_STARTED
1507 * Most of the request state machines have a started substate machine so
1508 * start its execution on the entry to the started state. */
1509 if (sci_req
->has_started_substate_machine
== true)
1510 sci_base_state_machine_start(&sci_req
->started_substate_machine
);
1514 * scic_sds_request_started_state_exit() -
1515 * @object: This parameter specifies the base object for which the state
1516 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1519 * This method implements the actions taken when exiting the
1520 * SCI_BASE_REQUEST_STATE_STARTED state. For task requests the action will be
1521 * to stop the started substate machine. none
1523 static void scic_sds_request_started_state_exit(void *object
)
1525 struct scic_sds_request
*sci_req
= object
;
1527 if (sci_req
->has_started_substate_machine
== true)
1528 sci_base_state_machine_stop(&sci_req
->started_substate_machine
);
1532 * scic_sds_request_completed_state_enter() -
1533 * @object: This parameter specifies the base object for which the state
1534 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1537 * This method implements the actions taken when entering the
1538 * SCI_BASE_REQUEST_STATE_COMPLETED state. This state is entered when the
1539 * SCIC_SDS_IO_REQUEST has completed. The method will decode the request
1540 * completion status and convert it to an enum sci_status to return in the
1541 * completion callback function. none
1543 static void scic_sds_request_completed_state_enter(void *object
)
1545 struct scic_sds_request
*sci_req
= object
;
1546 struct scic_sds_controller
*scic
=
1547 scic_sds_request_get_controller(sci_req
);
1548 struct isci_host
*ihost
= scic
->ihost
;
1549 struct isci_request
*ireq
= sci_req
->ireq
;
1551 SET_STATE_HANDLER(sci_req
,
1552 scic_sds_request_state_handler_table
,
1553 SCI_BASE_REQUEST_STATE_COMPLETED
);
1555 /* Tell the SCI_USER that the IO request is complete */
1556 if (sci_req
->is_task_management_request
== false)
1557 isci_request_io_request_complete(ihost
,
1559 sci_req
->sci_status
);
1561 isci_task_request_complete(ihost
, ireq
, sci_req
->sci_status
);
1565 * scic_sds_request_aborting_state_enter() -
1566 * @object: This parameter specifies the base object for which the state
1567 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1570 * This method implements the actions taken when entering the
1571 * SCI_BASE_REQUEST_STATE_ABORTING state. none
1573 static void scic_sds_request_aborting_state_enter(void *object
)
1575 struct scic_sds_request
*sci_req
= object
;
1577 /* Setting the abort bit in the Task Context is required by the silicon. */
1578 sci_req
->task_context_buffer
->abort
= 1;
1582 scic_sds_request_state_handler_table
,
1583 SCI_BASE_REQUEST_STATE_ABORTING
1588 * scic_sds_request_final_state_enter() -
1589 * @object: This parameter specifies the base object for which the state
1590 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
1592 * This method implements the actions taken when entering the
1593 * SCI_BASE_REQUEST_STATE_FINAL state. The only action required is to put the
1594 * state handlers in place. none
1596 static void scic_sds_request_final_state_enter(void *object
)
1598 struct scic_sds_request
*sci_req
= object
;
1602 scic_sds_request_state_handler_table
,
1603 SCI_BASE_REQUEST_STATE_FINAL
1607 static const struct sci_base_state scic_sds_request_state_table
[] = {
1608 [SCI_BASE_REQUEST_STATE_INITIAL
] = {
1609 .enter_state
= scic_sds_request_initial_state_enter
,
1611 [SCI_BASE_REQUEST_STATE_CONSTRUCTED
] = {
1612 .enter_state
= scic_sds_request_constructed_state_enter
,
1614 [SCI_BASE_REQUEST_STATE_STARTED
] = {
1615 .enter_state
= scic_sds_request_started_state_enter
,
1616 .exit_state
= scic_sds_request_started_state_exit
1618 [SCI_BASE_REQUEST_STATE_COMPLETED
] = {
1619 .enter_state
= scic_sds_request_completed_state_enter
,
1621 [SCI_BASE_REQUEST_STATE_ABORTING
] = {
1622 .enter_state
= scic_sds_request_aborting_state_enter
,
1624 [SCI_BASE_REQUEST_STATE_FINAL
] = {
1625 .enter_state
= scic_sds_request_final_state_enter
,
1629 static void scic_sds_general_request_construct(struct scic_sds_controller
*scic
,
1630 struct scic_sds_remote_device
*sci_dev
,
1632 void *user_io_request_object
,
1633 struct scic_sds_request
*sci_req
)
1635 sci_base_state_machine_construct(&sci_req
->state_machine
, sci_req
,
1636 scic_sds_request_state_table
, SCI_BASE_REQUEST_STATE_INITIAL
);
1637 sci_base_state_machine_start(&sci_req
->state_machine
);
1639 sci_req
->io_tag
= io_tag
;
1640 sci_req
->user_request
= user_io_request_object
;
1641 sci_req
->owning_controller
= scic
;
1642 sci_req
->target_device
= sci_dev
;
1643 sci_req
->has_started_substate_machine
= false;
1644 sci_req
->protocol
= SCIC_NO_PROTOCOL
;
1645 sci_req
->saved_rx_frame_index
= SCU_INVALID_FRAME_INDEX
;
1646 sci_req
->device_sequence
= scic_sds_remote_device_get_sequence(sci_dev
);
1648 sci_req
->sci_status
= SCI_SUCCESS
;
1649 sci_req
->scu_status
= 0;
1650 sci_req
->post_context
= 0xFFFFFFFF;
1652 sci_req
->is_task_management_request
= false;
1654 if (io_tag
== SCI_CONTROLLER_INVALID_IO_TAG
) {
1655 sci_req
->was_tag_assigned_by_user
= false;
1656 sci_req
->task_context_buffer
= NULL
;
1658 sci_req
->was_tag_assigned_by_user
= true;
1660 sci_req
->task_context_buffer
=
1661 scic_sds_controller_get_task_context_buffer(scic
, io_tag
);
1666 scic_io_request_construct(struct scic_sds_controller
*scic
,
1667 struct scic_sds_remote_device
*sci_dev
,
1670 struct scic_sds_request
*sci_req
,
1671 struct scic_sds_request
**new_sci_req
)
1673 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
1674 enum sci_status status
= SCI_SUCCESS
;
1676 /* Build the common part of the request */
1677 scic_sds_general_request_construct(scic
,
1683 if (sci_dev
->rnc
.remote_node_index
==
1684 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX
)
1685 return SCI_FAILURE_INVALID_REMOTE_DEVICE
;
1687 if (dev
->dev_type
== SAS_END_DEV
)
1688 scic_sds_ssp_io_request_assign_buffers(sci_req
);
1689 else if ((dev
->dev_type
== SATA_DEV
) ||
1690 (dev
->tproto
& SAS_PROTOCOL_STP
)) {
1691 scic_sds_stp_request_assign_buffers(sci_req
);
1692 memset(sci_req
->command_buffer
,
1694 sizeof(struct host_to_dev_fis
));
1695 } else if (dev_is_expander(dev
)) {
1696 scic_sds_smp_request_assign_buffers(sci_req
);
1697 memset(sci_req
->command_buffer
, 0, sizeof(struct smp_req
));
1699 status
= SCI_FAILURE_UNSUPPORTED_PROTOCOL
;
1701 if (status
== SCI_SUCCESS
) {
1702 memset(sci_req
->task_context_buffer
,
1704 SCI_FIELD_OFFSET(struct scu_task_context
, sgl_pair_ab
));
1705 *new_sci_req
= sci_req
;
1711 enum sci_status
scic_task_request_construct(struct scic_sds_controller
*scic
,
1712 struct scic_sds_remote_device
*sci_dev
,
1714 void *user_io_request_object
,
1715 struct scic_sds_request
*sci_req
,
1716 struct scic_sds_request
**new_sci_req
)
1718 struct domain_device
*dev
= sci_dev_to_domain(sci_dev
);
1719 enum sci_status status
= SCI_SUCCESS
;
1721 /* Build the common part of the request */
1722 scic_sds_general_request_construct(scic
, sci_dev
, io_tag
,
1723 user_io_request_object
,
1726 if (dev
->dev_type
== SAS_END_DEV
) {
1727 scic_sds_ssp_task_request_assign_buffers(sci_req
);
1729 sci_req
->has_started_substate_machine
= true;
1731 /* Construct the started sub-state machine. */
1732 sci_base_state_machine_construct(
1733 &sci_req
->started_substate_machine
,
1735 scic_sds_io_request_started_task_mgmt_substate_table
,
1736 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
1738 } else if (dev
->dev_type
== SATA_DEV
|| (dev
->tproto
& SAS_PROTOCOL_STP
))
1739 scic_sds_stp_request_assign_buffers(sci_req
);
1741 status
= SCI_FAILURE_UNSUPPORTED_PROTOCOL
;
1743 if (status
== SCI_SUCCESS
) {
1744 sci_req
->is_task_management_request
= true;
1745 memset(sci_req
->task_context_buffer
, 0, sizeof(struct scu_task_context
));
1746 *new_sci_req
= sci_req
;