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 "intel_sas.h"
58 #include "intel_sata.h"
59 #include "intel_sat.h"
60 #include "scic_controller.h"
61 #include "scic_io_request.h"
62 #include "scic_sds_controller.h"
63 #include "scu_registers.h"
64 #include "scic_sds_port.h"
65 #include "remote_device.h"
66 #include "scic_sds_request.h"
67 #include "scic_sds_smp_request.h"
68 #include "scic_sds_stp_request.h"
69 #include "scic_sds_unsolicited_frame_control.h"
70 #include "sci_environment.h"
72 #include "scu_completion_codes.h"
73 #include "scu_constants.h"
74 #include "scu_task_context.h"
77 * ****************************************************************************
78 * * SCIC SDS IO REQUEST CONSTANTS
79 * **************************************************************************** */
84 * We have no timer requirements for IO requests right now
86 #define SCIC_SDS_IO_REQUEST_MINIMUM_TIMER_COUNT (0)
87 #define SCIC_SDS_IO_REQUEST_MAXIMUM_TIMER_COUNT (0)
90 * ****************************************************************************
91 * * SCIC SDS IO REQUEST MACROS
92 * **************************************************************************** */
95 * scic_ssp_io_request_get_object_size() -
97 * This macro returns the sizeof memory required to store the an SSP IO
98 * request. This does not include the size of the SGL or SCU Task Context
101 #define scic_ssp_io_request_get_object_size() \
103 sizeof(struct sci_ssp_command_iu) \
104 + sizeof(struct sci_ssp_response_iu) \
108 * scic_sds_ssp_request_get_command_buffer() -
110 * This macro returns the address of the ssp command buffer in the io request
113 #define scic_sds_ssp_request_get_command_buffer(memory) \
114 ((struct sci_ssp_command_iu *)(\
115 ((char *)(memory)) + sizeof(struct scic_sds_request) \
119 * scic_sds_ssp_request_get_response_buffer() -
121 * This macro returns the address of the ssp response buffer in the io request
124 #define scic_sds_ssp_request_get_response_buffer(memory) \
125 ((struct sci_ssp_response_iu *)(\
126 ((char *)(scic_sds_ssp_request_get_command_buffer(memory))) \
127 + sizeof(struct sci_ssp_command_iu) \
131 * scic_sds_ssp_request_get_task_context_buffer() -
133 * This macro returns the address of the task context buffer in the io request
136 #define scic_sds_ssp_request_get_task_context_buffer(memory) \
137 ((struct scu_task_context *)(\
138 ((char *)(scic_sds_ssp_request_get_response_buffer(memory))) \
139 + sizeof(struct sci_ssp_response_iu) \
143 * scic_sds_ssp_request_get_sgl_element_buffer() -
145 * This macro returns the address of the sgl elment pairs in the io request
148 #define scic_sds_ssp_request_get_sgl_element_buffer(memory) \
149 ((struct scu_sgl_element_pair *)(\
150 ((char *)(scic_sds_ssp_request_get_task_context_buffer(memory))) \
151 + sizeof(struct scu_task_context) \
156 * scic_ssp_task_request_get_object_size() -
158 * This macro returns the sizeof of memory required to store an SSP Task
159 * request. This does not include the size of the SCU Task Context memory.
161 #define scic_ssp_task_request_get_object_size() \
163 sizeof(struct sci_ssp_task_iu) \
164 + sizeof(struct sci_ssp_response_iu) \
168 * scic_sds_ssp_task_request_get_command_buffer() -
170 * This macro returns the address of the ssp command buffer in the task request
171 * memory. Yes its the same as the above macro except for the name.
173 #define scic_sds_ssp_task_request_get_command_buffer(memory) \
174 ((struct sci_ssp_task_iu *)(\
175 ((char *)(memory)) + sizeof(struct scic_sds_request) \
179 * scic_sds_ssp_task_request_get_response_buffer() -
181 * This macro returns the address of the ssp response buffer in the task
184 #define scic_sds_ssp_task_request_get_response_buffer(memory) \
185 ((struct sci_ssp_response_iu *)(\
186 ((char *)(scic_sds_ssp_task_request_get_command_buffer(memory))) \
187 + sizeof(struct sci_ssp_task_iu) \
191 * scic_sds_ssp_task_request_get_task_context_buffer() -
193 * This macro returs the task context buffer for the SSP task request.
195 #define scic_sds_ssp_task_request_get_task_context_buffer(memory) \
196 ((struct scu_task_context *)(\
197 ((char *)(scic_sds_ssp_task_request_get_response_buffer(memory))) \
198 + sizeof(struct sci_ssp_response_iu) \
204 * ****************************************************************************
205 * * SCIC SDS IO REQUEST PRIVATE METHODS
206 * **************************************************************************** */
211 * This method returns the size required to store an SSP IO request object. u32
213 static u32 scic_sds_ssp_request_get_object_size(void)
215 return sizeof(struct scic_sds_request)
216 + scic_ssp_io_request_get_object_size()
217 + sizeof(struct scu_task_context)
219 + sizeof(struct scu_sgl_element_pair) * SCU_MAX_SGL_ELEMENT_PAIRS;
223 * This method returns the sgl element pair for the specificed sgl_pair index.
224 * @sci_req: This parameter specifies the IO request for which to retrieve
225 * the Scatter-Gather List element pair.
226 * @sgl_pair_index: This parameter specifies the index into the SGL element
227 * pair to be retrieved.
229 * This method returns a pointer to an struct scu_sgl_element_pair.
231 static struct scu_sgl_element_pair *scic_sds_request_get_sgl_element_pair(
232 struct scic_sds_request *sci_req,
235 struct scu_task_context *task_context;
237 task_context = (struct scu_task_context *)sci_req->task_context_buffer;
239 if (sgl_pair_index == 0) {
240 return &task_context->sgl_pair_ab;
241 } else if (sgl_pair_index == 1) {
242 return &task_context->sgl_pair_cd;
245 return &sci_req->sgl_element_pair_buffer[sgl_pair_index - 2];
249 * This function will build the SGL list for an IO request.
250 * @sci_req: This parameter specifies the IO request for which to build
251 * the Scatter-Gather List.
254 void scic_sds_request_build_sgl(struct scic_sds_request *sds_request)
256 struct isci_request *isci_request = sds_request->ireq;
257 struct isci_host *isci_host = isci_request->isci_host;
258 struct sas_task *task = isci_request_access_task(isci_request);
259 struct scatterlist *sg = NULL;
262 struct scu_sgl_element_pair *scu_sg = NULL;
263 struct scu_sgl_element_pair *prev_sg = NULL;
265 if (task->num_scatter > 0) {
269 scu_sg = scic_sds_request_get_sgl_element_pair(
273 SCU_SGL_COPY(scu_sg->A, sg);
278 SCU_SGL_COPY(scu_sg->B, sg);
281 SCU_SGL_ZERO(scu_sg->B);
285 scic_io_request_get_dma_addr(
289 prev_sg->next_pair_upper =
290 upper_32_bits(dma_addr);
291 prev_sg->next_pair_lower =
292 lower_32_bits(dma_addr);
298 } else { /* handle when no sg */
299 scu_sg = scic_sds_request_get_sgl_element_pair(sds_request,
302 dma_addr = dma_map_single(&isci_host->pdev->dev,
304 task->total_xfer_len,
307 isci_request->zero_scatter_daddr = dma_addr;
309 scu_sg->A.length = task->total_xfer_len;
310 scu_sg->A.address_upper = upper_32_bits(dma_addr);
311 scu_sg->A.address_lower = lower_32_bits(dma_addr);
315 scu_sg->next_pair_upper = 0;
316 scu_sg->next_pair_lower = 0;
321 * This method build the remainder of the IO request object.
322 * @sci_req: This parameter specifies the request object being constructed.
324 * The scic_sds_general_request_construct() must be called before this call is
327 static void scic_sds_ssp_io_request_assign_buffers(
328 struct scic_sds_request *sci_req)
330 sci_req->command_buffer =
331 scic_sds_ssp_request_get_command_buffer(sci_req);
332 sci_req->response_buffer =
333 scic_sds_ssp_request_get_response_buffer(sci_req);
334 sci_req->sgl_element_pair_buffer =
335 scic_sds_ssp_request_get_sgl_element_buffer(sci_req);
336 sci_req->sgl_element_pair_buffer =
337 PTR_ALIGN(sci_req->sgl_element_pair_buffer,
338 sizeof(struct scu_sgl_element_pair));
340 if (sci_req->was_tag_assigned_by_user == false) {
341 sci_req->task_context_buffer =
342 scic_sds_ssp_request_get_task_context_buffer(sci_req);
343 sci_req->task_context_buffer =
344 PTR_ALIGN(sci_req->task_context_buffer,
350 * This method constructs the SSP Command IU data for this io request object.
351 * @sci_req: This parameter specifies the request object for which the SSP
352 * command information unit is being built.
355 static void scic_sds_io_request_build_ssp_command_iu(
356 struct scic_sds_request *sds_request)
358 struct sci_ssp_command_iu *command_frame;
361 struct isci_request *isci_request = sds_request->ireq;
364 (struct sci_ssp_command_iu *)sds_request->command_buffer;
366 command_frame->lun_upper = 0;
367 command_frame->lun_lower =
368 isci_request_ssp_io_request_get_lun(isci_request);
370 ((u32 *)command_frame)[2] = 0;
372 cdb_length = isci_request_ssp_io_request_get_cdb_length(isci_request);
373 cdb_buffer = (u32 *)isci_request_ssp_io_request_get_cdb_address(
376 if (cdb_length > 16) {
377 command_frame->additional_cdb_length = cdb_length - 16;
380 /* / @todo Is it ok to leave junk at the end of the cdb buffer? */
381 scic_word_copy_with_swap(
382 (u32 *)(&command_frame->cdb),
384 (cdb_length + 3) / sizeof(u32)
387 command_frame->enable_first_burst = 0;
388 command_frame->task_priority =
389 isci_request_ssp_io_request_get_command_priority(isci_request);
390 command_frame->task_attribute =
391 isci_request_ssp_io_request_get_task_attribute(isci_request);
396 * This method constructs the SSP Task IU data for this io request object.
400 static void scic_sds_task_request_build_ssp_task_iu(
401 struct scic_sds_request *sds_request)
403 struct sci_ssp_task_iu *command_frame;
404 struct isci_request *isci_request = sds_request->ireq;
407 (struct sci_ssp_task_iu *)sds_request->command_buffer;
409 command_frame->lun_upper = 0;
410 command_frame->lun_lower = isci_request_ssp_io_request_get_lun(
413 ((u32 *)command_frame)[2] = 0;
415 command_frame->task_function =
416 isci_task_ssp_request_get_function(isci_request);
417 command_frame->task_tag =
418 isci_task_ssp_request_get_io_tag_to_manage(
424 * This method is will fill in the SCU Task Context for any type of SSP request.
429 static void scu_ssp_reqeust_construct_task_context(
430 struct scic_sds_request *sds_request,
431 struct scu_task_context *task_context)
434 struct scic_sds_controller *controller;
435 struct scic_sds_remote_device *target_device;
436 struct scic_sds_port *target_port;
438 controller = scic_sds_request_get_controller(sds_request);
439 target_device = scic_sds_request_get_device(sds_request);
440 target_port = scic_sds_request_get_port(sds_request);
442 /* Fill in the TC with the its required data */
443 task_context->abort = 0;
444 task_context->priority = 0;
445 task_context->initiator_request = 1;
446 task_context->connection_rate = target_device->connection_rate;
447 task_context->protocol_engine_index =
448 scic_sds_controller_get_protocol_engine_group(controller);
449 task_context->logical_port_index =
450 scic_sds_port_get_index(target_port);
451 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
452 task_context->valid = SCU_TASK_CONTEXT_VALID;
453 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
455 task_context->remote_node_index =
456 scic_sds_remote_device_get_index(sds_request->target_device);
457 task_context->command_code = 0;
459 task_context->link_layer_control = 0;
460 task_context->do_not_dma_ssp_good_response = 1;
461 task_context->strict_ordering = 0;
462 task_context->control_frame = 0;
463 task_context->timeout_enable = 0;
464 task_context->block_guard_enable = 0;
466 task_context->address_modifier = 0;
468 /* task_context->type.ssp.tag = sci_req->io_tag; */
469 task_context->task_phase = 0x01;
471 if (sds_request->was_tag_assigned_by_user) {
473 * Build the task context now since we have already read
476 sds_request->post_context =
477 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
478 (scic_sds_controller_get_protocol_engine_group(
480 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
481 (scic_sds_port_get_index(target_port) <<
482 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
483 scic_sds_io_tag_get_index(sds_request->io_tag));
486 * Build the task context now since we have already read
489 * I/O tag index is not assigned because we have to wait
492 sds_request->post_context =
493 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
494 (scic_sds_controller_get_protocol_engine_group(
495 owning_controller) <<
496 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
497 (scic_sds_port_get_index(target_port) <<
498 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
502 * Copy the physical address for the command buffer to the
505 dma_addr = scic_io_request_get_dma_addr(sds_request,
506 sds_request->command_buffer);
508 task_context->command_iu_upper = upper_32_bits(dma_addr);
509 task_context->command_iu_lower = lower_32_bits(dma_addr);
512 * Copy the physical address for the response buffer to the
515 dma_addr = scic_io_request_get_dma_addr(sds_request,
516 sds_request->response_buffer);
518 task_context->response_iu_upper = upper_32_bits(dma_addr);
519 task_context->response_iu_lower = lower_32_bits(dma_addr);
523 * This method is will fill in the SCU Task Context for a SSP IO request.
527 static void scu_ssp_io_request_construct_task_context(
528 struct scic_sds_request *sci_req,
529 enum dma_data_direction dir,
532 struct scu_task_context *task_context;
534 task_context = scic_sds_request_get_task_context(sci_req);
536 scu_ssp_reqeust_construct_task_context(sci_req, task_context);
538 task_context->ssp_command_iu_length = sizeof(struct sci_ssp_command_iu) / sizeof(u32);
539 task_context->type.ssp.frame_type = SCI_SAS_COMMAND_FRAME;
542 case DMA_FROM_DEVICE:
545 task_context->task_type = SCU_TASK_TYPE_IOREAD;
548 task_context->task_type = SCU_TASK_TYPE_IOWRITE;
552 task_context->transfer_length_bytes = len;
554 if (task_context->transfer_length_bytes > 0)
555 scic_sds_request_build_sgl(sci_req);
560 * This method will fill in the remainder of the io request object for SSP Task
565 static void scic_sds_ssp_task_request_assign_buffers(
566 struct scic_sds_request *sci_req)
568 /* Assign all of the buffer pointers */
569 sci_req->command_buffer =
570 scic_sds_ssp_task_request_get_command_buffer(sci_req);
571 sci_req->response_buffer =
572 scic_sds_ssp_task_request_get_response_buffer(sci_req);
573 sci_req->sgl_element_pair_buffer = NULL;
575 if (sci_req->was_tag_assigned_by_user == false) {
576 sci_req->task_context_buffer =
577 scic_sds_ssp_task_request_get_task_context_buffer(sci_req);
578 sci_req->task_context_buffer =
579 PTR_ALIGN(sci_req->task_context_buffer, SMP_CACHE_BYTES);
584 * This method will fill in the SCU Task Context for a SSP Task request. The
585 * following important settings are utilized: -# priority ==
586 * SCU_TASK_PRIORITY_HIGH. This ensures that the task request is issued
587 * ahead of other task destined for the same Remote Node. -# task_type ==
588 * SCU_TASK_TYPE_IOREAD. This simply indicates that a normal request type
589 * (i.e. non-raw frame) is being utilized to perform task management. -#
590 * control_frame == 1. This ensures that the proper endianess is set so
591 * that the bytes are transmitted in the right order for a task frame.
592 * @sci_req: This parameter specifies the task request object being
596 static void scu_ssp_task_request_construct_task_context(
597 struct scic_sds_request *sci_req)
599 struct scu_task_context *task_context;
601 task_context = scic_sds_request_get_task_context(sci_req);
603 scu_ssp_reqeust_construct_task_context(sci_req, task_context);
605 task_context->control_frame = 1;
606 task_context->priority = SCU_TASK_PRIORITY_HIGH;
607 task_context->task_type = SCU_TASK_TYPE_RAW_FRAME;
608 task_context->transfer_length_bytes = 0;
609 task_context->type.ssp.frame_type = SCI_SAS_TASK_FRAME;
610 task_context->ssp_command_iu_length = sizeof(struct sci_ssp_task_iu) / sizeof(u32);
615 * This method constructs the SSP Command IU data for this ssp passthrough
616 * comand request object.
617 * @sci_req: This parameter specifies the request object for which the SSP
618 * command information unit is being built.
620 * enum sci_status, returns invalid parameter is cdb > 16
625 * This method constructs the SATA request object.
634 static enum sci_status scic_io_request_construct_sata(struct scic_sds_request *sci_req,
636 enum dma_data_direction dir,
639 enum sci_status status = SCI_SUCCESS;
642 case SAT_PROTOCOL_PIO_DATA_IN:
643 case SAT_PROTOCOL_PIO_DATA_OUT:
644 status = scic_sds_stp_pio_request_construct(sci_req, proto, copy);
647 case SAT_PROTOCOL_UDMA_DATA_IN:
648 case SAT_PROTOCOL_UDMA_DATA_OUT:
649 status = scic_sds_stp_udma_request_construct(sci_req, len, dir);
652 case SAT_PROTOCOL_ATA_HARD_RESET:
653 case SAT_PROTOCOL_SOFT_RESET:
654 status = scic_sds_stp_soft_reset_request_construct(sci_req);
657 case SAT_PROTOCOL_NON_DATA:
658 status = scic_sds_stp_non_data_request_construct(sci_req);
661 case SAT_PROTOCOL_FPDMA:
662 status = scic_sds_stp_ncq_request_construct(sci_req, len, dir);
665 case SAT_PROTOCOL_DMA_QUEUED:
666 case SAT_PROTOCOL_DMA:
667 case SAT_PROTOCOL_DEVICE_DIAGNOSTIC:
668 case SAT_PROTOCOL_DEVICE_RESET:
669 case SAT_PROTOCOL_RETURN_RESPONSE_INFO:
671 dev_err(scic_to_dev(sci_req->owning_controller),
672 "%s: SCIC IO Request 0x%p received un-handled "
674 __func__, sci_req, proto);
676 status = SCI_FAILURE;
683 u32 scic_io_request_get_object_size(void)
685 u32 ssp_request_size;
686 u32 stp_request_size;
687 u32 smp_request_size;
689 ssp_request_size = scic_sds_ssp_request_get_object_size();
690 stp_request_size = scic_sds_stp_request_get_object_size();
691 smp_request_size = scic_sds_smp_request_get_object_size();
693 return max(ssp_request_size, max(stp_request_size, smp_request_size));
696 enum sci_status scic_io_request_construct_basic_ssp(
697 struct scic_sds_request *sci_req)
699 struct isci_request *isci_request = sci_req->ireq;
701 sci_req->protocol = SCIC_SSP_PROTOCOL;
703 scu_ssp_io_request_construct_task_context(
705 isci_request_io_request_get_data_direction(isci_request),
706 isci_request_io_request_get_transfer_length(isci_request));
708 scic_sds_io_request_build_ssp_command_iu(sci_req);
710 sci_base_state_machine_change_state(&sci_req->state_machine,
711 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
717 enum sci_status scic_task_request_construct_ssp(
718 struct scic_sds_request *sci_req)
720 /* Construct the SSP Task SCU Task Context */
721 scu_ssp_task_request_construct_task_context(sci_req);
723 /* Fill in the SSP Task IU */
724 scic_sds_task_request_build_ssp_task_iu(sci_req);
726 sci_base_state_machine_change_state(&sci_req->state_machine,
727 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
733 enum sci_status scic_io_request_construct_basic_sata(
734 struct scic_sds_request *sci_req)
736 enum sci_status status;
737 struct scic_sds_stp_request *stp_req;
740 enum dma_data_direction dir;
742 struct isci_request *isci_request = sci_req->ireq;
743 struct sas_task *task = isci_request_access_task(isci_request);
745 stp_req = container_of(sci_req, typeof(*stp_req), parent);
747 sci_req->protocol = SCIC_STP_PROTOCOL;
749 len = isci_request_io_request_get_transfer_length(isci_request);
750 dir = isci_request_io_request_get_data_direction(isci_request);
751 proto = isci_sata_get_sat_protocol(isci_request);
752 copy = (task->data_dir == DMA_NONE) ? false : true;
754 status = scic_io_request_construct_sata(sci_req, proto, len, dir, copy);
756 if (status == SCI_SUCCESS)
757 sci_base_state_machine_change_state(&sci_req->state_machine,
758 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
764 enum sci_status scic_task_request_construct_sata(
765 struct scic_sds_request *sci_req)
767 enum sci_status status;
769 struct isci_request *isci_request = sci_req->ireq;
771 sat_protocol = isci_sata_get_sat_protocol(isci_request);
773 switch (sat_protocol) {
774 case SAT_PROTOCOL_ATA_HARD_RESET:
775 case SAT_PROTOCOL_SOFT_RESET:
776 status = scic_sds_stp_soft_reset_request_construct(sci_req);
780 dev_err(scic_to_dev(sci_req->owning_controller),
781 "%s: SCIC IO Request 0x%p received un-handled SAT "
787 status = SCI_FAILURE;
791 if (status == SCI_SUCCESS)
792 sci_base_state_machine_change_state(&sci_req->state_machine,
793 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
799 u16 scic_io_request_get_io_tag(
800 struct scic_sds_request *sci_req)
802 return sci_req->io_tag;
806 u32 scic_request_get_controller_status(
807 struct scic_sds_request *sci_req)
809 return sci_req->scu_status;
813 void *scic_io_request_get_command_iu_address(
814 struct scic_sds_request *sci_req)
816 return sci_req->command_buffer;
820 void *scic_io_request_get_response_iu_address(
821 struct scic_sds_request *sci_req)
823 return sci_req->response_buffer;
827 #define SCU_TASK_CONTEXT_SRAM 0x200000
828 u32 scic_io_request_get_number_of_bytes_transferred(
829 struct scic_sds_request *scic_sds_request)
831 struct scic_sds_controller *scic = scic_sds_request->owning_controller;
834 if (readl(&scic->smu_registers->address_modifier) == 0) {
835 void __iomem *scu_reg_base = scic->scu_registers;
837 * get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
838 * BAR1 is the scu_registers
839 * 0x20002C = 0x200000 + 0x2c
840 * = start of task context SRAM + offset of (type.ssp.data_offset)
841 * TCi is the io_tag of struct scic_sds_request */
842 ret_val = readl(scu_reg_base +
843 (SCU_TASK_CONTEXT_SRAM + offsetof(struct scu_task_context, type.ssp.data_offset)) +
844 ((sizeof(struct scu_task_context)) * scic_sds_io_tag_get_index(scic_sds_request->io_tag)));
852 * ****************************************************************************
853 * * SCIC SDS Interface Implementation
854 * **************************************************************************** */
857 scic_sds_request_start(struct scic_sds_request *request)
859 if (request->device_sequence !=
860 scic_sds_remote_device_get_sequence(request->target_device))
863 if (request->state_handlers->start_handler)
864 return request->state_handlers->start_handler(request);
866 dev_warn(scic_to_dev(request->owning_controller),
867 "%s: SCIC IO Request requested to start while in wrong "
870 sci_base_state_machine_get_state(&request->state_machine));
872 return SCI_FAILURE_INVALID_STATE;
876 scic_sds_io_request_terminate(struct scic_sds_request *request)
878 if (request->state_handlers->abort_handler)
879 return request->state_handlers->abort_handler(request);
881 dev_warn(scic_to_dev(request->owning_controller),
882 "%s: SCIC IO Request requested to abort while in wrong "
885 sci_base_state_machine_get_state(&request->state_machine));
887 return SCI_FAILURE_INVALID_STATE;
891 scic_sds_io_request_complete(struct scic_sds_request *request)
893 if (request->state_handlers->complete_handler)
894 return request->state_handlers->complete_handler(request);
896 dev_warn(scic_to_dev(request->owning_controller),
897 "%s: SCIC IO Request requested to complete while in wrong "
900 sci_base_state_machine_get_state(&request->state_machine));
902 return SCI_FAILURE_INVALID_STATE;
905 enum sci_status scic_sds_io_request_event_handler(
906 struct scic_sds_request *request,
909 if (request->state_handlers->event_handler)
910 return request->state_handlers->event_handler(request, event_code);
912 dev_warn(scic_to_dev(request->owning_controller),
913 "%s: SCIC IO Request given event code notification %x while "
914 "in wrong state %d\n",
917 sci_base_state_machine_get_state(&request->state_machine));
919 return SCI_FAILURE_INVALID_STATE;
923 scic_sds_io_request_tc_completion(struct scic_sds_request *request, u32 completion_code)
925 if (request->state_machine.current_state_id == SCI_BASE_REQUEST_STATE_STARTED &&
926 request->has_started_substate_machine == false)
927 return scic_sds_request_started_state_tc_completion_handler(request, completion_code);
928 else if (request->state_handlers->tc_completion_handler)
929 return request->state_handlers->tc_completion_handler(request, completion_code);
931 dev_warn(scic_to_dev(request->owning_controller),
932 "%s: SCIC IO Request given task completion notification %x "
933 "while in wrong state %d\n",
936 sci_base_state_machine_get_state(&request->state_machine));
938 return SCI_FAILURE_INVALID_STATE;
945 * @sci_req: The SCIC_SDS_IO_REQUEST_T object for which the start
946 * operation is to be executed.
947 * @frame_index: The frame index returned by the hardware for the reqeust
950 * This method invokes the core state frame handler for the
951 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
953 enum sci_status scic_sds_io_request_frame_handler(
954 struct scic_sds_request *request,
957 if (request->state_handlers->frame_handler)
958 return request->state_handlers->frame_handler(request, frame_index);
960 dev_warn(scic_to_dev(request->owning_controller),
961 "%s: SCIC IO Request given unexpected frame %x while in "
965 sci_base_state_machine_get_state(&request->state_machine));
967 scic_sds_controller_release_frame(request->owning_controller, frame_index);
968 return SCI_FAILURE_INVALID_STATE;
973 * @sci_req: The SCIC_SDS_IO_REQUEST_T object for which the task start
974 * operation is to be executed.
976 * This method invokes the core state task complete handler for the
977 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
981 * ****************************************************************************
982 * * SCIC SDS PROTECTED METHODS
983 * **************************************************************************** */
986 * This method copies response data for requests returning response data
987 * instead of sense data.
988 * @sci_req: This parameter specifies the request object for which to copy
992 void scic_sds_io_request_copy_response(struct scic_sds_request *sds_request)
994 void *response_buffer;
995 u32 user_response_length;
996 u32 core_response_length;
997 struct sci_ssp_response_iu *ssp_response;
998 struct isci_request *isci_request = sds_request->ireq;
1001 (struct sci_ssp_response_iu *)sds_request->response_buffer;
1004 isci_task_ssp_request_get_response_data_address(
1007 user_response_length =
1008 isci_task_ssp_request_get_response_data_length(
1011 core_response_length = sci_ssp_get_response_data_length(
1012 ssp_response->response_data_length);
1014 user_response_length = min(user_response_length, core_response_length);
1016 memcpy(response_buffer, ssp_response->data, user_response_length);
1020 * *****************************************************************************
1021 * * CONSTRUCTED STATE HANDLERS
1022 * ***************************************************************************** */
1025 * This method implements the action taken when a constructed
1026 * SCIC_SDS_IO_REQUEST_T object receives a scic_sds_request_start() request.
1027 * This method will, if necessary, allocate a TCi for the io request object and
1028 * then will, if necessary, copy the constructed TC data into the actual TC
1029 * buffer. If everything is successful the post context field is updated with
1030 * the TCi so the controller can post the request to the hardware. enum sci_status
1031 * SCI_SUCCESS SCI_FAILURE_INSUFFICIENT_RESOURCES
1033 static enum sci_status scic_sds_request_constructed_state_start_handler(
1034 struct scic_sds_request *request)
1036 struct scu_task_context *task_context;
1038 if (request->io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
1040 scic_controller_allocate_io_tag(request->owning_controller);
1043 /* Record the IO Tag in the request */
1044 if (request->io_tag != SCI_CONTROLLER_INVALID_IO_TAG) {
1045 task_context = request->task_context_buffer;
1047 task_context->task_index = scic_sds_io_tag_get_index(request->io_tag);
1049 switch (task_context->protocol_type) {
1050 case SCU_TASK_CONTEXT_PROTOCOL_SMP:
1051 case SCU_TASK_CONTEXT_PROTOCOL_SSP:
1053 task_context->type.ssp.tag = request->io_tag;
1054 task_context->type.ssp.target_port_transfer_tag = 0xFFFF;
1057 case SCU_TASK_CONTEXT_PROTOCOL_STP:
1060 * task_context->type.stp.ncq_tag = request->ncq_tag; */
1063 case SCU_TASK_CONTEXT_PROTOCOL_NONE:
1064 /* / @todo When do we set no protocol type? */
1068 /* This should never happen since we build the IO requests */
1073 * Check to see if we need to copy the task context buffer
1074 * or have been building into the task context buffer */
1075 if (request->was_tag_assigned_by_user == false) {
1076 scic_sds_controller_copy_task_context(
1077 request->owning_controller, request);
1080 /* Add to the post_context the io tag value */
1081 request->post_context |= scic_sds_io_tag_get_index(request->io_tag);
1083 /* Everything is good go ahead and change state */
1084 sci_base_state_machine_change_state(&request->state_machine,
1085 SCI_BASE_REQUEST_STATE_STARTED);
1090 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
1094 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1095 * object receives a scic_sds_request_terminate() request. Since the request
1096 * has not yet been posted to the hardware the request transitions to the
1097 * completed state. enum sci_status SCI_SUCCESS
1099 static enum sci_status scic_sds_request_constructed_state_abort_handler(
1100 struct scic_sds_request *request)
1103 * This request has been terminated by the user make sure that the correct
1104 * status code is returned */
1105 scic_sds_request_set_status(request,
1106 SCU_TASK_DONE_TASK_ABORT,
1107 SCI_FAILURE_IO_TERMINATED);
1109 sci_base_state_machine_change_state(&request->state_machine,
1110 SCI_BASE_REQUEST_STATE_COMPLETED);
1115 * *****************************************************************************
1116 * * STARTED STATE HANDLERS
1117 * ***************************************************************************** */
1120 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1121 * object receives a scic_sds_request_terminate() request. Since the request
1122 * has been posted to the hardware the io request state is changed to the
1123 * aborting state. enum sci_status SCI_SUCCESS
1125 enum sci_status scic_sds_request_started_state_abort_handler(
1126 struct scic_sds_request *request)
1128 if (request->has_started_substate_machine)
1129 sci_base_state_machine_stop(&request->started_substate_machine);
1131 sci_base_state_machine_change_state(&request->state_machine,
1132 SCI_BASE_REQUEST_STATE_ABORTING);
1137 * scic_sds_request_started_state_tc_completion_handler() - This method process
1138 * TC (task context) completions for normal IO request (i.e. Task/Abort
1139 * Completions of type 0). This method will update the
1140 * SCIC_SDS_IO_REQUEST_T::status field.
1141 * @sci_req: This parameter specifies the request for which a completion
1143 * @completion_code: This parameter specifies the completion code received from
1147 enum sci_status scic_sds_request_started_state_tc_completion_handler(
1148 struct scic_sds_request *sci_req,
1149 u32 completion_code)
1152 struct sci_ssp_response_iu *response_buffer;
1155 * @todo Any SDMA return code of other than 0 is bad
1156 * decode 0x003C0000 to determine SDMA status
1158 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1159 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1160 scic_sds_request_set_status(
1161 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1165 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP):
1168 * There are times when the SCU hardware will return an early response
1169 * because the io request specified more data than is returned by the
1170 * target device (mode pages, inquiry data, etc.). We must check the
1171 * response stats to see if this is truly a failed request or a good
1172 * request that just got completed early. */
1173 struct sci_ssp_response_iu *response = (struct sci_ssp_response_iu *)
1174 sci_req->response_buffer;
1175 scic_word_copy_with_swap(
1176 sci_req->response_buffer,
1177 sci_req->response_buffer,
1178 sizeof(struct sci_ssp_response_iu) / sizeof(u32)
1181 if (response->status == 0) {
1182 scic_sds_request_set_status(
1183 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS_IO_DONE_EARLY
1186 scic_sds_request_set_status(
1188 SCU_TASK_DONE_CHECK_RESPONSE,
1189 SCI_FAILURE_IO_RESPONSE_VALID
1195 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE):
1196 scic_word_copy_with_swap(
1197 sci_req->response_buffer,
1198 sci_req->response_buffer,
1199 sizeof(struct sci_ssp_response_iu) / sizeof(u32)
1202 scic_sds_request_set_status(
1204 SCU_TASK_DONE_CHECK_RESPONSE,
1205 SCI_FAILURE_IO_RESPONSE_VALID
1209 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR):
1211 * / @todo With TASK_DONE_RESP_LEN_ERR is the response frame guaranteed
1212 * / to be received before this completion status is posted? */
1214 (struct sci_ssp_response_iu *)sci_req->response_buffer;
1216 response_buffer->data_present & SCI_SSP_RESPONSE_IU_DATA_PRESENT_MASK;
1218 if ((data_present == 0x01) || (data_present == 0x02)) {
1219 scic_sds_request_set_status(
1221 SCU_TASK_DONE_CHECK_RESPONSE,
1222 SCI_FAILURE_IO_RESPONSE_VALID
1225 scic_sds_request_set_status(
1226 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1231 /* only stp device gets suspended. */
1232 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
1233 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR):
1234 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR):
1235 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR):
1236 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR):
1237 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN):
1238 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
1239 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP):
1240 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS):
1241 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
1242 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR):
1243 if (sci_req->protocol == SCIC_STP_PROTOCOL) {
1244 scic_sds_request_set_status(
1246 SCU_GET_COMPLETION_TL_STATUS(completion_code) >> SCU_COMPLETION_TL_STATUS_SHIFT,
1247 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
1250 scic_sds_request_set_status(
1252 SCU_GET_COMPLETION_TL_STATUS(completion_code) >> SCU_COMPLETION_TL_STATUS_SHIFT,
1253 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1258 /* both stp/ssp device gets suspended */
1259 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR):
1260 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION):
1261 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1):
1262 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2):
1263 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3):
1264 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION):
1265 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION):
1266 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY):
1267 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED):
1268 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED):
1269 scic_sds_request_set_status(
1271 SCU_GET_COMPLETION_TL_STATUS(completion_code) >> SCU_COMPLETION_TL_STATUS_SHIFT,
1272 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED
1276 /* neither ssp nor stp gets suspended. */
1277 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR):
1278 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR):
1279 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR):
1280 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR):
1281 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR):
1282 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA):
1283 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
1284 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
1285 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
1286 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
1287 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA):
1288 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL):
1289 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV):
1290 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV):
1291 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND):
1293 scic_sds_request_set_status(
1295 SCU_GET_COMPLETION_TL_STATUS(completion_code) >> SCU_COMPLETION_TL_STATUS_SHIFT,
1296 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1302 * @todo This is probably wrong for ACK/NAK timeout conditions
1305 /* In all cases we will treat this as the completion of the IO request. */
1306 sci_base_state_machine_change_state(&sci_req->state_machine,
1307 SCI_BASE_REQUEST_STATE_COMPLETED);
1312 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1313 * object receives a scic_sds_request_frame_handler() request. This method
1314 * first determines the frame type received. If this is a response frame then
1315 * the response data is copied to the io request response buffer for processing
1316 * at completion time. If the frame type is not a response buffer an error is
1317 * logged. enum sci_status SCI_SUCCESS SCI_FAILURE_INVALID_PARAMETER_VALUE
1319 static enum sci_status scic_sds_request_started_state_frame_handler(
1320 struct scic_sds_request *sci_req,
1323 enum sci_status status;
1324 struct sci_ssp_frame_header *frame_header;
1326 /* / @todo If this is a response frame we must record that we received it */
1327 status = scic_sds_unsolicited_frame_control_get_header(
1328 &(scic_sds_request_get_controller(sci_req)->uf_control),
1330 (void **)&frame_header
1333 if (frame_header->frame_type == SCI_SAS_RESPONSE_FRAME) {
1334 struct sci_ssp_response_iu *response_buffer;
1336 status = scic_sds_unsolicited_frame_control_get_buffer(
1337 &(scic_sds_request_get_controller(sci_req)->uf_control),
1339 (void **)&response_buffer
1342 scic_word_copy_with_swap(
1343 sci_req->response_buffer,
1344 (u32 *)response_buffer,
1345 sizeof(struct sci_ssp_response_iu)
1348 response_buffer = (struct sci_ssp_response_iu *)sci_req->response_buffer;
1350 if ((response_buffer->data_present == 0x01) ||
1351 (response_buffer->data_present == 0x02)) {
1352 scic_sds_request_set_status(
1354 SCU_TASK_DONE_CHECK_RESPONSE,
1355 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1358 scic_sds_request_set_status(
1359 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1362 /* This was not a response frame why did it get forwarded? */
1363 dev_err(scic_to_dev(sci_req->owning_controller),
1364 "%s: SCIC IO Request 0x%p received unexpected "
1365 "frame %d type 0x%02x\n",
1369 frame_header->frame_type);
1372 * In any case we are done with this frame buffer return it to the
1374 scic_sds_controller_release_frame(
1375 sci_req->owning_controller, frame_index
1382 * *****************************************************************************
1383 * * COMPLETED STATE HANDLERS
1384 * ***************************************************************************** */
1388 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1389 * object receives a scic_sds_request_complete() request. This method frees up
1390 * any io request resources that have been allocated and transitions the
1391 * request to its final state. Consider stopping the state machine instead of
1392 * transitioning to the final state? enum sci_status SCI_SUCCESS
1394 static enum sci_status scic_sds_request_completed_state_complete_handler(
1395 struct scic_sds_request *request)
1397 if (request->was_tag_assigned_by_user != true) {
1398 scic_controller_free_io_tag(
1399 request->owning_controller, request->io_tag);
1402 if (request->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX) {
1403 scic_sds_controller_release_frame(
1404 request->owning_controller, request->saved_rx_frame_index);
1407 sci_base_state_machine_change_state(&request->state_machine,
1408 SCI_BASE_REQUEST_STATE_FINAL);
1413 * *****************************************************************************
1414 * * ABORTING STATE HANDLERS
1415 * ***************************************************************************** */
1418 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1419 * object receives a scic_sds_request_terminate() request. This method is the
1420 * io request aborting state abort handlers. On receipt of a multiple
1421 * terminate requests the io request will transition to the completed state.
1422 * This should not happen in normal operation. enum sci_status SCI_SUCCESS
1424 static enum sci_status scic_sds_request_aborting_state_abort_handler(
1425 struct scic_sds_request *request)
1427 sci_base_state_machine_change_state(&request->state_machine,
1428 SCI_BASE_REQUEST_STATE_COMPLETED);
1433 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1434 * object receives a scic_sds_request_task_completion() request. This method
1435 * decodes the completion type waiting for the abort task complete
1436 * notification. When the abort task complete is received the io request
1437 * transitions to the completed state. enum sci_status SCI_SUCCESS
1439 static enum sci_status scic_sds_request_aborting_state_tc_completion_handler(
1440 struct scic_sds_request *sci_req,
1441 u32 completion_code)
1443 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1444 case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT):
1445 case (SCU_TASK_DONE_TASK_ABORT << SCU_COMPLETION_TL_STATUS_SHIFT):
1446 scic_sds_request_set_status(
1447 sci_req, SCU_TASK_DONE_TASK_ABORT, SCI_FAILURE_IO_TERMINATED
1450 sci_base_state_machine_change_state(&sci_req->state_machine,
1451 SCI_BASE_REQUEST_STATE_COMPLETED);
1456 * Unless we get some strange error wait for the task abort to complete
1457 * TODO: Should there be a state change for this completion? */
1465 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1466 * object receives a scic_sds_request_frame_handler() request. This method
1467 * discards the unsolicited frame since we are waiting for the abort task
1468 * completion. enum sci_status SCI_SUCCESS
1470 static enum sci_status scic_sds_request_aborting_state_frame_handler(
1471 struct scic_sds_request *sci_req,
1474 /* TODO: Is it even possible to get an unsolicited frame in the aborting state? */
1476 scic_sds_controller_release_frame(
1477 sci_req->owning_controller, frame_index);
1482 static const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table[] = {
1483 [SCI_BASE_REQUEST_STATE_INITIAL] = {
1485 [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
1486 .start_handler = scic_sds_request_constructed_state_start_handler,
1487 .abort_handler = scic_sds_request_constructed_state_abort_handler,
1489 [SCI_BASE_REQUEST_STATE_STARTED] = {
1490 .abort_handler = scic_sds_request_started_state_abort_handler,
1491 .tc_completion_handler = scic_sds_request_started_state_tc_completion_handler,
1492 .frame_handler = scic_sds_request_started_state_frame_handler,
1494 [SCI_BASE_REQUEST_STATE_COMPLETED] = {
1495 .complete_handler = scic_sds_request_completed_state_complete_handler,
1497 [SCI_BASE_REQUEST_STATE_ABORTING] = {
1498 .abort_handler = scic_sds_request_aborting_state_abort_handler,
1499 .tc_completion_handler = scic_sds_request_aborting_state_tc_completion_handler,
1500 .frame_handler = scic_sds_request_aborting_state_frame_handler,
1502 [SCI_BASE_REQUEST_STATE_FINAL] = {
1507 * scic_sds_request_initial_state_enter() -
1508 * @object: This parameter specifies the base object for which the state
1509 * transition is occurring.
1511 * This method implements the actions taken when entering the
1512 * SCI_BASE_REQUEST_STATE_INITIAL state. This state is entered when the initial
1513 * base request is constructed. Entry into the initial state sets all handlers
1514 * for the io request object to their default handlers. none
1516 static void scic_sds_request_initial_state_enter(void *object)
1518 struct scic_sds_request *sci_req = object;
1522 scic_sds_request_state_handler_table,
1523 SCI_BASE_REQUEST_STATE_INITIAL
1528 * scic_sds_request_constructed_state_enter() -
1529 * @object: The io request object that is to enter the constructed state.
1531 * This method implements the actions taken when entering the
1532 * SCI_BASE_REQUEST_STATE_CONSTRUCTED state. The method sets the state handlers
1533 * for the the constructed state. none
1535 static void scic_sds_request_constructed_state_enter(void *object)
1537 struct scic_sds_request *sci_req = object;
1541 scic_sds_request_state_handler_table,
1542 SCI_BASE_REQUEST_STATE_CONSTRUCTED
1547 * scic_sds_request_started_state_enter() -
1548 * @object: This parameter specifies the base object for which the state
1549 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
1551 * This method implements the actions taken when entering the
1552 * SCI_BASE_REQUEST_STATE_STARTED state. If the io request object type is a
1553 * SCSI Task request we must enter the started substate machine. none
1555 static void scic_sds_request_started_state_enter(void *object)
1557 struct scic_sds_request *sci_req = object;
1561 scic_sds_request_state_handler_table,
1562 SCI_BASE_REQUEST_STATE_STARTED
1566 * Most of the request state machines have a started substate machine so
1567 * start its execution on the entry to the started state. */
1568 if (sci_req->has_started_substate_machine == true)
1569 sci_base_state_machine_start(&sci_req->started_substate_machine);
1573 * scic_sds_request_started_state_exit() -
1574 * @object: This parameter specifies the base object for which the state
1575 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1578 * This method implements the actions taken when exiting the
1579 * SCI_BASE_REQUEST_STATE_STARTED state. For task requests the action will be
1580 * to stop the started substate machine. none
1582 static void scic_sds_request_started_state_exit(void *object)
1584 struct scic_sds_request *sci_req = object;
1586 if (sci_req->has_started_substate_machine == true)
1587 sci_base_state_machine_stop(&sci_req->started_substate_machine);
1591 * scic_sds_request_completed_state_enter() -
1592 * @object: This parameter specifies the base object for which the state
1593 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1596 * This method implements the actions taken when entering the
1597 * SCI_BASE_REQUEST_STATE_COMPLETED state. This state is entered when the
1598 * SCIC_SDS_IO_REQUEST has completed. The method will decode the request
1599 * completion status and convert it to an enum sci_status to return in the
1600 * completion callback function. none
1602 static void scic_sds_request_completed_state_enter(void *object)
1604 struct scic_sds_request *sci_req = object;
1605 struct scic_sds_controller *scic =
1606 scic_sds_request_get_controller(sci_req);
1607 struct isci_host *ihost = scic->ihost;
1608 struct isci_request *ireq = sci_req->ireq;
1610 SET_STATE_HANDLER(sci_req,
1611 scic_sds_request_state_handler_table,
1612 SCI_BASE_REQUEST_STATE_COMPLETED);
1614 /* Tell the SCI_USER that the IO request is complete */
1615 if (sci_req->is_task_management_request == false)
1616 isci_request_io_request_complete(ihost,
1618 sci_req->sci_status);
1620 isci_task_request_complete(ihost, ireq, sci_req->sci_status);
1624 * scic_sds_request_aborting_state_enter() -
1625 * @object: This parameter specifies the base object for which the state
1626 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1629 * This method implements the actions taken when entering the
1630 * SCI_BASE_REQUEST_STATE_ABORTING state. none
1632 static void scic_sds_request_aborting_state_enter(void *object)
1634 struct scic_sds_request *sci_req = object;
1636 /* Setting the abort bit in the Task Context is required by the silicon. */
1637 sci_req->task_context_buffer->abort = 1;
1641 scic_sds_request_state_handler_table,
1642 SCI_BASE_REQUEST_STATE_ABORTING
1647 * scic_sds_request_final_state_enter() -
1648 * @object: This parameter specifies the base object for which the state
1649 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
1651 * This method implements the actions taken when entering the
1652 * SCI_BASE_REQUEST_STATE_FINAL state. The only action required is to put the
1653 * state handlers in place. none
1655 static void scic_sds_request_final_state_enter(void *object)
1657 struct scic_sds_request *sci_req = object;
1661 scic_sds_request_state_handler_table,
1662 SCI_BASE_REQUEST_STATE_FINAL
1666 static const struct sci_base_state scic_sds_request_state_table[] = {
1667 [SCI_BASE_REQUEST_STATE_INITIAL] = {
1668 .enter_state = scic_sds_request_initial_state_enter,
1670 [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
1671 .enter_state = scic_sds_request_constructed_state_enter,
1673 [SCI_BASE_REQUEST_STATE_STARTED] = {
1674 .enter_state = scic_sds_request_started_state_enter,
1675 .exit_state = scic_sds_request_started_state_exit
1677 [SCI_BASE_REQUEST_STATE_COMPLETED] = {
1678 .enter_state = scic_sds_request_completed_state_enter,
1680 [SCI_BASE_REQUEST_STATE_ABORTING] = {
1681 .enter_state = scic_sds_request_aborting_state_enter,
1683 [SCI_BASE_REQUEST_STATE_FINAL] = {
1684 .enter_state = scic_sds_request_final_state_enter,
1688 static void scic_sds_general_request_construct(struct scic_sds_controller *scic,
1689 struct scic_sds_remote_device *sci_dev,
1691 void *user_io_request_object,
1692 struct scic_sds_request *sci_req)
1694 sci_base_state_machine_construct(&sci_req->state_machine, sci_req,
1695 scic_sds_request_state_table, SCI_BASE_REQUEST_STATE_INITIAL);
1696 sci_base_state_machine_start(&sci_req->state_machine);
1698 sci_req->io_tag = io_tag;
1699 sci_req->user_request = user_io_request_object;
1700 sci_req->owning_controller = scic;
1701 sci_req->target_device = sci_dev;
1702 sci_req->has_started_substate_machine = false;
1703 sci_req->protocol = SCIC_NO_PROTOCOL;
1704 sci_req->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX;
1705 sci_req->device_sequence = scic_sds_remote_device_get_sequence(sci_dev);
1707 sci_req->sci_status = SCI_SUCCESS;
1708 sci_req->scu_status = 0;
1709 sci_req->post_context = 0xFFFFFFFF;
1711 sci_req->is_task_management_request = false;
1713 if (io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
1714 sci_req->was_tag_assigned_by_user = false;
1715 sci_req->task_context_buffer = NULL;
1717 sci_req->was_tag_assigned_by_user = true;
1719 sci_req->task_context_buffer =
1720 scic_sds_controller_get_task_context_buffer(scic, io_tag);
1724 enum sci_status scic_io_request_construct(struct scic_sds_controller *scic,
1725 struct scic_sds_remote_device *sci_dev,
1727 void *user_io_request_object,
1728 struct scic_sds_request *sci_req,
1729 struct scic_sds_request **new_scic_io_request_handle)
1731 struct domain_device *dev = sci_dev_to_domain(sci_dev);
1732 enum sci_status status = SCI_SUCCESS;
1734 /* Build the common part of the request */
1735 scic_sds_general_request_construct(scic, sci_dev, io_tag,
1736 user_io_request_object, sci_req);
1738 if (sci_dev->rnc.remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
1739 return SCI_FAILURE_INVALID_REMOTE_DEVICE;
1741 if (dev->dev_type == SAS_END_DEV) {
1742 scic_sds_ssp_io_request_assign_buffers(sci_req);
1743 } else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
1744 scic_sds_stp_request_assign_buffers(sci_req);
1745 memset(sci_req->command_buffer, 0, sizeof(struct host_to_dev_fis));
1746 } else if (dev_is_expander(dev)) {
1747 scic_sds_smp_request_assign_buffers(sci_req);
1748 memset(sci_req->command_buffer, 0, sizeof(struct smp_request));
1750 status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
1752 if (status == SCI_SUCCESS) {
1753 memset(sci_req->task_context_buffer, 0,
1754 SCI_FIELD_OFFSET(struct scu_task_context, sgl_pair_ab));
1755 *new_scic_io_request_handle = sci_req;
1761 enum sci_status scic_task_request_construct(struct scic_sds_controller *scic,
1762 struct scic_sds_remote_device *sci_dev,
1764 void *user_io_request_object,
1765 struct scic_sds_request *sci_req,
1766 struct scic_sds_request **new_sci_req)
1768 struct domain_device *dev = sci_dev_to_domain(sci_dev);
1769 enum sci_status status = SCI_SUCCESS;
1771 /* Build the common part of the request */
1772 scic_sds_general_request_construct(scic, sci_dev, io_tag,
1773 user_io_request_object,
1776 if (dev->dev_type == SAS_END_DEV) {
1777 scic_sds_ssp_task_request_assign_buffers(sci_req);
1779 sci_req->has_started_substate_machine = true;
1781 /* Construct the started sub-state machine. */
1782 sci_base_state_machine_construct(
1783 &sci_req->started_substate_machine,
1785 scic_sds_io_request_started_task_mgmt_substate_table,
1786 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
1788 } else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))
1789 scic_sds_stp_request_assign_buffers(sci_req);
1791 status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
1793 if (status == SCI_SUCCESS) {
1794 sci_req->is_task_management_request = true;
1795 memset(sci_req->task_context_buffer, 0, sizeof(struct scu_task_context));
1796 *new_sci_req = sci_req;