isci: move stp request info to scic_sds_request
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / scsi / isci / core / scic_sds_request.c
blobfd7bd334fa4b27b64c5fe24f4fd5fe2bb9196401
1 /*
2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
5 * GPL LICENSE SUMMARY
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.
24 * BSD LICENSE
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
31 * are met:
33 * * Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * * Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in
37 * the documentation and/or other materials provided with the
38 * distribution.
39 * * Neither the name of Intel Corporation nor the names of its
40 * contributors may be used to endorse or promote products derived
41 * from this software without specific prior written permission.
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.
56 #include <scsi/sas.h>
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"
68 #include "sci_util.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 * **************************************************************************** */
78 /**
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 * **************************************************************************** */
91 /**
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
96 * memory.
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
108 * memory
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
119 * memory
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
131 * memory
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
143 * memory buffer
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
179 * request memory.
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)
215 + SMP_CACHE_BYTES
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,
230 u32 sgl_pair_index
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;
257 dma_addr_t dma_addr;
258 u32 sg_idx = 0;
259 struct scu_sgl_element_pair *scu_sg = NULL;
260 struct scu_sgl_element_pair *prev_sg = NULL;
262 if (task->num_scatter > 0) {
263 sg = task->scatter;
265 while (sg) {
266 scu_sg = scic_sds_request_get_sgl_element_pair(
267 sds_request,
268 sg_idx);
270 SCU_SGL_COPY(scu_sg->A, sg);
272 sg = sg_next(sg);
274 if (sg) {
275 SCU_SGL_COPY(scu_sg->B, sg);
276 sg = sg_next(sg);
277 } else
278 SCU_SGL_ZERO(scu_sg->B);
280 if (prev_sg) {
281 dma_addr =
282 scic_io_request_get_dma_addr(
283 sds_request,
284 scu_sg);
286 prev_sg->next_pair_upper =
287 upper_32_bits(dma_addr);
288 prev_sg->next_pair_lower =
289 lower_32_bits(dma_addr);
292 prev_sg = scu_sg;
293 sg_idx++;
295 } else { /* handle when no sg */
296 scu_sg = scic_sds_request_get_sgl_element_pair(sds_request,
297 sg_idx);
299 dma_addr = dma_map_single(&isci_host->pdev->dev,
300 task->scatter,
301 task->total_xfer_len,
302 task->data_dir);
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);
311 if (scu_sg) {
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
322 * valid. none
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,
342 SMP_CACHE_BYTES);
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;
356 cmd_iu->_r_a = 0;
357 cmd_iu->_r_b = 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;
361 cmd_iu->_r_c = 0;
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;
381 task_iu->task_tag =
382 (ireq->ttype == tmf_task) ?
383 isci_tmf->io_tag :
384 SCI_CONTROLLER_INVALID_IO_TAG;
388 * This method is will fill in the SCU Task Context for any type of SSP request.
389 * @sci_req:
390 * @task_context:
393 static void scu_ssp_reqeust_construct_task_context(
394 struct scic_sds_request *sds_request,
395 struct scu_task_context *task_context)
397 dma_addr_t dma_addr;
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
438 * the data
440 sds_request->post_context =
441 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
442 (scic_sds_controller_get_protocol_engine_group(
443 controller) <<
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));
448 } else {
450 * Build the task context now since we have already read
451 * the data
453 * I/O tag index is not assigned because we have to wait
454 * until we get a TCi
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
467 * SCU Task Context
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
477 * SCU Task Context
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.
488 * @sci_req:
491 static void scu_ssp_io_request_construct_task_context(
492 struct scic_sds_request *sci_req,
493 enum dma_data_direction dir,
494 u32 len)
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;
506 switch (dir) {
507 case DMA_FROM_DEVICE:
508 case DMA_NONE:
509 default:
510 task_context->task_type = SCU_TASK_TYPE_IOREAD;
511 break;
512 case DMA_TO_DEVICE:
513 task_context->task_type = SCU_TASK_TYPE_IOWRITE;
514 break;
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
526 * requests.
527 * @sci_req:
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
558 * constructed.
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.
592 * @sci_req:
593 * @sat_protocol:
594 * @transfer_length:
595 * @data_direction:
596 * @copy_rx_frame:
598 * enum sci_status
600 static enum sci_status
601 scic_io_request_construct_sata(struct scic_sds_request *sci_req,
602 u32 len,
603 enum dma_data_direction dir,
604 bool copy)
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);
617 else {
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);
623 return SCI_FAILURE;
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",
630 __func__,
631 task->task_proto);
632 return SCI_FAILURE;
636 /* non data */
637 if (task->data_dir == DMA_NONE)
638 return scic_sds_stp_non_data_request_construct(sci_req);
640 /* NCQ */
641 if (task->ata_task.use_ncq)
642 return scic_sds_stp_ncq_request_construct(sci_req, len, dir);
644 /* DMA */
645 if (task->ata_task.dma_xfer)
646 return scic_sds_stp_udma_request_construct(sci_req, len, dir);
647 else /* PIO */
648 return scic_sds_stp_pio_request_construct(sci_req, copy);
650 return status;
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 *ireq = sci_req->ireq;
670 struct sas_task *task = isci_request_access_task(ireq);
672 sci_req->protocol = SCIC_SSP_PROTOCOL;
674 scu_ssp_io_request_construct_task_context(sci_req,
675 task->data_dir,
676 task->total_xfer_len);
678 scic_sds_io_request_build_ssp_command_iu(sci_req);
680 sci_base_state_machine_change_state(
681 &sci_req->state_machine,
682 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
684 return SCI_SUCCESS;
688 enum sci_status scic_task_request_construct_ssp(
689 struct scic_sds_request *sci_req)
691 /* Construct the SSP Task SCU Task Context */
692 scu_ssp_task_request_construct_task_context(sci_req);
694 /* Fill in the SSP Task IU */
695 scic_sds_task_request_build_ssp_task_iu(sci_req);
697 sci_base_state_machine_change_state(&sci_req->state_machine,
698 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
700 return SCI_SUCCESS;
704 enum sci_status scic_io_request_construct_basic_sata(
705 struct scic_sds_request *sci_req)
707 enum sci_status status;
708 struct scic_sds_stp_request *stp_req;
709 bool copy = false;
710 struct isci_request *isci_request = sci_req->ireq;
711 struct sas_task *task = isci_request_access_task(isci_request);
713 stp_req = &sci_req->stp.req;
714 sci_req->protocol = SCIC_STP_PROTOCOL;
716 copy = (task->data_dir == DMA_NONE) ? false : true;
718 status = scic_io_request_construct_sata(sci_req,
719 task->total_xfer_len,
720 task->data_dir,
721 copy);
723 if (status == SCI_SUCCESS)
724 sci_base_state_machine_change_state(&sci_req->state_machine,
725 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
727 return status;
731 enum sci_status scic_task_request_construct_sata(
732 struct scic_sds_request *sci_req)
734 enum sci_status status = SCI_SUCCESS;
735 struct isci_request *ireq = sci_req->ireq;
737 /* check for management protocols */
738 if (ireq->ttype == tmf_task) {
739 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
741 if (tmf->tmf_code == isci_tmf_sata_srst_high ||
742 tmf->tmf_code == isci_tmf_sata_srst_low) {
743 status = scic_sds_stp_soft_reset_request_construct(sci_req);
744 } else {
745 dev_err(scic_to_dev(sci_req->owning_controller),
746 "%s: Request 0x%p received un-handled SAT "
747 "Protocol 0x%x.\n",
748 __func__, sci_req, tmf->tmf_code);
750 return SCI_FAILURE;
754 if (status == SCI_SUCCESS)
755 sci_base_state_machine_change_state(
756 &sci_req->state_machine,
757 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
759 return status;
763 u16 scic_io_request_get_io_tag(
764 struct scic_sds_request *sci_req)
766 return sci_req->io_tag;
770 u32 scic_request_get_controller_status(
771 struct scic_sds_request *sci_req)
773 return sci_req->scu_status;
777 void *scic_io_request_get_command_iu_address(
778 struct scic_sds_request *sci_req)
780 return sci_req->command_buffer;
784 void *scic_io_request_get_response_iu_address(
785 struct scic_sds_request *sci_req)
787 return sci_req->response_buffer;
791 #define SCU_TASK_CONTEXT_SRAM 0x200000
792 u32 scic_io_request_get_number_of_bytes_transferred(
793 struct scic_sds_request *scic_sds_request)
795 struct scic_sds_controller *scic = scic_sds_request->owning_controller;
796 u32 ret_val = 0;
798 if (readl(&scic->smu_registers->address_modifier) == 0) {
799 void __iomem *scu_reg_base = scic->scu_registers;
801 * get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
802 * BAR1 is the scu_registers
803 * 0x20002C = 0x200000 + 0x2c
804 * = start of task context SRAM + offset of (type.ssp.data_offset)
805 * TCi is the io_tag of struct scic_sds_request */
806 ret_val = readl(scu_reg_base +
807 (SCU_TASK_CONTEXT_SRAM + offsetof(struct scu_task_context, type.ssp.data_offset)) +
808 ((sizeof(struct scu_task_context)) * scic_sds_io_tag_get_index(scic_sds_request->io_tag)));
811 return ret_val;
816 * ****************************************************************************
817 * * SCIC SDS Interface Implementation
818 * **************************************************************************** */
820 enum sci_status
821 scic_sds_request_start(struct scic_sds_request *request)
823 if (request->device_sequence !=
824 scic_sds_remote_device_get_sequence(request->target_device))
825 return SCI_FAILURE;
827 if (request->state_handlers->start_handler)
828 return request->state_handlers->start_handler(request);
830 dev_warn(scic_to_dev(request->owning_controller),
831 "%s: SCIC IO Request requested to start while in wrong "
832 "state %d\n",
833 __func__,
834 sci_base_state_machine_get_state(&request->state_machine));
836 return SCI_FAILURE_INVALID_STATE;
839 enum sci_status
840 scic_sds_io_request_terminate(struct scic_sds_request *request)
842 if (request->state_handlers->abort_handler)
843 return request->state_handlers->abort_handler(request);
845 dev_warn(scic_to_dev(request->owning_controller),
846 "%s: SCIC IO Request requested to abort while in wrong "
847 "state %d\n",
848 __func__,
849 sci_base_state_machine_get_state(&request->state_machine));
851 return SCI_FAILURE_INVALID_STATE;
854 enum sci_status
855 scic_sds_io_request_complete(struct scic_sds_request *request)
857 if (request->state_handlers->complete_handler)
858 return request->state_handlers->complete_handler(request);
860 dev_warn(scic_to_dev(request->owning_controller),
861 "%s: SCIC IO Request requested to complete while in wrong "
862 "state %d\n",
863 __func__,
864 sci_base_state_machine_get_state(&request->state_machine));
866 return SCI_FAILURE_INVALID_STATE;
869 enum sci_status scic_sds_io_request_event_handler(
870 struct scic_sds_request *request,
871 u32 event_code)
873 if (request->state_handlers->event_handler)
874 return request->state_handlers->event_handler(request, event_code);
876 dev_warn(scic_to_dev(request->owning_controller),
877 "%s: SCIC IO Request given event code notification %x while "
878 "in wrong state %d\n",
879 __func__,
880 event_code,
881 sci_base_state_machine_get_state(&request->state_machine));
883 return SCI_FAILURE_INVALID_STATE;
886 enum sci_status
887 scic_sds_io_request_tc_completion(struct scic_sds_request *request, u32 completion_code)
889 if (request->state_machine.current_state_id == SCI_BASE_REQUEST_STATE_STARTED &&
890 request->has_started_substate_machine == false)
891 return scic_sds_request_started_state_tc_completion_handler(request, completion_code);
892 else if (request->state_handlers->tc_completion_handler)
893 return request->state_handlers->tc_completion_handler(request, completion_code);
895 dev_warn(scic_to_dev(request->owning_controller),
896 "%s: SCIC IO Request given task completion notification %x "
897 "while in wrong state %d\n",
898 __func__,
899 completion_code,
900 sci_base_state_machine_get_state(&request->state_machine));
902 return SCI_FAILURE_INVALID_STATE;
909 * @sci_req: The SCIC_SDS_IO_REQUEST_T object for which the start
910 * operation is to be executed.
911 * @frame_index: The frame index returned by the hardware for the reqeust
912 * object.
914 * This method invokes the core state frame handler for the
915 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
917 enum sci_status scic_sds_io_request_frame_handler(
918 struct scic_sds_request *request,
919 u32 frame_index)
921 if (request->state_handlers->frame_handler)
922 return request->state_handlers->frame_handler(request, frame_index);
924 dev_warn(scic_to_dev(request->owning_controller),
925 "%s: SCIC IO Request given unexpected frame %x while in "
926 "state %d\n",
927 __func__,
928 frame_index,
929 sci_base_state_machine_get_state(&request->state_machine));
931 scic_sds_controller_release_frame(request->owning_controller, frame_index);
932 return SCI_FAILURE_INVALID_STATE;
936 * This function copies response data for requests returning response data
937 * instead of sense data.
938 * @sci_req: This parameter specifies the request object for which to copy
939 * the response data.
941 void scic_sds_io_request_copy_response(struct scic_sds_request *sci_req)
943 void *resp_buf;
944 u32 len;
945 struct ssp_response_iu *ssp_response;
946 struct isci_request *ireq = sci_req->ireq;
947 struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq);
949 ssp_response = sci_req->response_buffer;
951 resp_buf = &isci_tmf->resp.resp_iu;
953 len = min_t(u32,
954 SSP_RESP_IU_MAX_SIZE,
955 be32_to_cpu(ssp_response->response_data_len));
957 memcpy(resp_buf, ssp_response->resp_data, len);
961 * *****************************************************************************
962 * * CONSTRUCTED STATE HANDLERS
963 * ***************************************************************************** */
966 * This method implements the action taken when a constructed
967 * SCIC_SDS_IO_REQUEST_T object receives a scic_sds_request_start() request.
968 * This method will, if necessary, allocate a TCi for the io request object and
969 * then will, if necessary, copy the constructed TC data into the actual TC
970 * buffer. If everything is successful the post context field is updated with
971 * the TCi so the controller can post the request to the hardware. enum sci_status
972 * SCI_SUCCESS SCI_FAILURE_INSUFFICIENT_RESOURCES
974 static enum sci_status scic_sds_request_constructed_state_start_handler(
975 struct scic_sds_request *request)
977 struct scu_task_context *task_context;
979 if (request->io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
980 request->io_tag =
981 scic_controller_allocate_io_tag(request->owning_controller);
984 /* Record the IO Tag in the request */
985 if (request->io_tag != SCI_CONTROLLER_INVALID_IO_TAG) {
986 task_context = request->task_context_buffer;
988 task_context->task_index = scic_sds_io_tag_get_index(request->io_tag);
990 switch (task_context->protocol_type) {
991 case SCU_TASK_CONTEXT_PROTOCOL_SMP:
992 case SCU_TASK_CONTEXT_PROTOCOL_SSP:
993 /* SSP/SMP Frame */
994 task_context->type.ssp.tag = request->io_tag;
995 task_context->type.ssp.target_port_transfer_tag = 0xFFFF;
996 break;
998 case SCU_TASK_CONTEXT_PROTOCOL_STP:
1000 * STP/SATA Frame
1001 * task_context->type.stp.ncq_tag = request->ncq_tag; */
1002 break;
1004 case SCU_TASK_CONTEXT_PROTOCOL_NONE:
1005 /* / @todo When do we set no protocol type? */
1006 break;
1008 default:
1009 /* This should never happen since we build the IO requests */
1010 break;
1014 * Check to see if we need to copy the task context buffer
1015 * or have been building into the task context buffer */
1016 if (request->was_tag_assigned_by_user == false) {
1017 scic_sds_controller_copy_task_context(
1018 request->owning_controller, request);
1021 /* Add to the post_context the io tag value */
1022 request->post_context |= scic_sds_io_tag_get_index(request->io_tag);
1024 /* Everything is good go ahead and change state */
1025 sci_base_state_machine_change_state(&request->state_machine,
1026 SCI_BASE_REQUEST_STATE_STARTED);
1028 return SCI_SUCCESS;
1031 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
1035 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1036 * object receives a scic_sds_request_terminate() request. Since the request
1037 * has not yet been posted to the hardware the request transitions to the
1038 * completed state. enum sci_status SCI_SUCCESS
1040 static enum sci_status scic_sds_request_constructed_state_abort_handler(
1041 struct scic_sds_request *request)
1044 * This request has been terminated by the user make sure that the correct
1045 * status code is returned */
1046 scic_sds_request_set_status(request,
1047 SCU_TASK_DONE_TASK_ABORT,
1048 SCI_FAILURE_IO_TERMINATED);
1050 sci_base_state_machine_change_state(&request->state_machine,
1051 SCI_BASE_REQUEST_STATE_COMPLETED);
1052 return SCI_SUCCESS;
1056 * *****************************************************************************
1057 * * STARTED STATE HANDLERS
1058 * ***************************************************************************** */
1061 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1062 * object receives a scic_sds_request_terminate() request. Since the request
1063 * has been posted to the hardware the io request state is changed to the
1064 * aborting state. enum sci_status SCI_SUCCESS
1066 enum sci_status scic_sds_request_started_state_abort_handler(
1067 struct scic_sds_request *request)
1069 if (request->has_started_substate_machine)
1070 sci_base_state_machine_stop(&request->started_substate_machine);
1072 sci_base_state_machine_change_state(&request->state_machine,
1073 SCI_BASE_REQUEST_STATE_ABORTING);
1074 return SCI_SUCCESS;
1078 * scic_sds_request_started_state_tc_completion_handler() - This method process
1079 * TC (task context) completions for normal IO request (i.e. Task/Abort
1080 * Completions of type 0). This method will update the
1081 * SCIC_SDS_IO_REQUEST_T::status field.
1082 * @sci_req: This parameter specifies the request for which a completion
1083 * occurred.
1084 * @completion_code: This parameter specifies the completion code received from
1085 * the SCU.
1088 enum sci_status
1089 scic_sds_request_started_state_tc_completion_handler(
1090 struct scic_sds_request *sci_req,
1091 u32 completion_code)
1093 u8 datapres;
1094 struct ssp_response_iu *resp_iu;
1097 * TODO: Any SDMA return code of other than 0 is bad
1098 * decode 0x003C0000 to determine SDMA status
1100 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1101 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1102 scic_sds_request_set_status(sci_req,
1103 SCU_TASK_DONE_GOOD,
1104 SCI_SUCCESS);
1105 break;
1107 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP):
1110 * There are times when the SCU hardware will return an early
1111 * response because the io request specified more data than is
1112 * returned by the target device (mode pages, inquiry data,
1113 * etc.). We must check the response stats to see if this is
1114 * truly a failed request or a good request that just got
1115 * completed early.
1117 struct ssp_response_iu *resp = sci_req->response_buffer;
1118 ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
1120 sci_swab32_cpy(sci_req->response_buffer,
1121 sci_req->response_buffer,
1122 word_cnt);
1124 if (resp->status == 0) {
1125 scic_sds_request_set_status(
1126 sci_req,
1127 SCU_TASK_DONE_GOOD,
1128 SCI_SUCCESS_IO_DONE_EARLY);
1129 } else {
1130 scic_sds_request_set_status(
1131 sci_req,
1132 SCU_TASK_DONE_CHECK_RESPONSE,
1133 SCI_FAILURE_IO_RESPONSE_VALID);
1136 break;
1138 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE):
1140 ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
1142 sci_swab32_cpy(sci_req->response_buffer,
1143 sci_req->response_buffer,
1144 word_cnt);
1146 scic_sds_request_set_status(sci_req,
1147 SCU_TASK_DONE_CHECK_RESPONSE,
1148 SCI_FAILURE_IO_RESPONSE_VALID);
1149 break;
1152 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR):
1154 * / @todo With TASK_DONE_RESP_LEN_ERR is the response frame
1155 * guaranteed to be received before this completion status is
1156 * posted?
1158 resp_iu = sci_req->response_buffer;
1159 datapres = resp_iu->datapres;
1161 if ((datapres == 0x01) || (datapres == 0x02)) {
1162 scic_sds_request_set_status(
1163 sci_req,
1164 SCU_TASK_DONE_CHECK_RESPONSE,
1165 SCI_FAILURE_IO_RESPONSE_VALID);
1166 } else
1167 scic_sds_request_set_status(
1168 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
1169 break;
1171 /* only stp device gets suspended. */
1172 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
1173 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR):
1174 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR):
1175 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR):
1176 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR):
1177 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN):
1178 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
1179 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP):
1180 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS):
1181 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
1182 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR):
1183 if (sci_req->protocol == SCIC_STP_PROTOCOL) {
1184 scic_sds_request_set_status(
1185 sci_req,
1186 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
1187 SCU_COMPLETION_TL_STATUS_SHIFT,
1188 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
1189 } else {
1190 scic_sds_request_set_status(
1191 sci_req,
1192 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
1193 SCU_COMPLETION_TL_STATUS_SHIFT,
1194 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
1196 break;
1198 /* both stp/ssp device gets suspended */
1199 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR):
1200 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION):
1201 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1):
1202 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2):
1203 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3):
1204 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION):
1205 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION):
1206 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY):
1207 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED):
1208 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED):
1209 scic_sds_request_set_status(
1210 sci_req,
1211 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
1212 SCU_COMPLETION_TL_STATUS_SHIFT,
1213 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
1214 break;
1216 /* neither ssp nor stp gets suspended. */
1217 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR):
1218 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR):
1219 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR):
1220 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR):
1221 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR):
1222 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA):
1223 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
1224 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
1225 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
1226 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
1227 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA):
1228 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL):
1229 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV):
1230 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV):
1231 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND):
1232 default:
1233 scic_sds_request_set_status(
1234 sci_req,
1235 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
1236 SCU_COMPLETION_TL_STATUS_SHIFT,
1237 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
1238 break;
1242 * TODO: This is probably wrong for ACK/NAK timeout conditions
1245 /* In all cases we will treat this as the completion of the IO req. */
1246 sci_base_state_machine_change_state(
1247 &sci_req->state_machine,
1248 SCI_BASE_REQUEST_STATE_COMPLETED);
1249 return SCI_SUCCESS;
1253 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1254 * object receives a scic_sds_request_frame_handler() request. This method
1255 * first determines the frame type received. If this is a response frame then
1256 * the response data is copied to the io request response buffer for processing
1257 * at completion time. If the frame type is not a response buffer an error is
1258 * logged. enum sci_status SCI_SUCCESS SCI_FAILURE_INVALID_PARAMETER_VALUE
1260 static enum sci_status
1261 scic_sds_request_started_state_frame_handler(struct scic_sds_request *sci_req,
1262 u32 frame_index)
1264 enum sci_status status;
1265 u32 *frame_header;
1266 struct ssp_frame_hdr ssp_hdr;
1267 ssize_t word_cnt;
1269 status = scic_sds_unsolicited_frame_control_get_header(
1270 &(scic_sds_request_get_controller(sci_req)->uf_control),
1271 frame_index,
1272 (void **)&frame_header);
1274 word_cnt = sizeof(struct ssp_frame_hdr) / sizeof(u32);
1275 sci_swab32_cpy(&ssp_hdr, frame_header, word_cnt);
1277 if (ssp_hdr.frame_type == SSP_RESPONSE) {
1278 struct ssp_response_iu *resp_iu;
1279 ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
1281 status = scic_sds_unsolicited_frame_control_get_buffer(
1282 &(scic_sds_request_get_controller(sci_req)->uf_control),
1283 frame_index,
1284 (void **)&resp_iu);
1286 sci_swab32_cpy(sci_req->response_buffer,
1287 resp_iu, word_cnt);
1289 resp_iu = sci_req->response_buffer;
1291 if ((resp_iu->datapres == 0x01) ||
1292 (resp_iu->datapres == 0x02)) {
1293 scic_sds_request_set_status(
1294 sci_req,
1295 SCU_TASK_DONE_CHECK_RESPONSE,
1296 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
1297 } else
1298 scic_sds_request_set_status(
1299 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
1300 } else {
1301 /* This was not a response frame why did it get forwarded? */
1302 dev_err(scic_to_dev(sci_req->owning_controller),
1303 "%s: SCIC IO Request 0x%p received unexpected "
1304 "frame %d type 0x%02x\n",
1305 __func__,
1306 sci_req,
1307 frame_index,
1308 ssp_hdr.frame_type);
1312 * In any case we are done with this frame buffer return it to the
1313 * controller
1315 scic_sds_controller_release_frame(
1316 sci_req->owning_controller, frame_index);
1318 return SCI_SUCCESS;
1322 * *****************************************************************************
1323 * * COMPLETED STATE HANDLERS
1324 * ***************************************************************************** */
1328 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1329 * object receives a scic_sds_request_complete() request. This method frees up
1330 * any io request resources that have been allocated and transitions the
1331 * request to its final state. Consider stopping the state machine instead of
1332 * transitioning to the final state? enum sci_status SCI_SUCCESS
1334 static enum sci_status scic_sds_request_completed_state_complete_handler(
1335 struct scic_sds_request *request)
1337 if (request->was_tag_assigned_by_user != true) {
1338 scic_controller_free_io_tag(
1339 request->owning_controller, request->io_tag);
1342 if (request->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX) {
1343 scic_sds_controller_release_frame(
1344 request->owning_controller, request->saved_rx_frame_index);
1347 sci_base_state_machine_change_state(&request->state_machine,
1348 SCI_BASE_REQUEST_STATE_FINAL);
1349 return SCI_SUCCESS;
1353 * *****************************************************************************
1354 * * ABORTING STATE HANDLERS
1355 * ***************************************************************************** */
1358 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1359 * object receives a scic_sds_request_terminate() request. This method is the
1360 * io request aborting state abort handlers. On receipt of a multiple
1361 * terminate requests the io request will transition to the completed state.
1362 * This should not happen in normal operation. enum sci_status SCI_SUCCESS
1364 static enum sci_status scic_sds_request_aborting_state_abort_handler(
1365 struct scic_sds_request *request)
1367 sci_base_state_machine_change_state(&request->state_machine,
1368 SCI_BASE_REQUEST_STATE_COMPLETED);
1369 return SCI_SUCCESS;
1373 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1374 * object receives a scic_sds_request_task_completion() request. This method
1375 * decodes the completion type waiting for the abort task complete
1376 * notification. When the abort task complete is received the io request
1377 * transitions to the completed state. enum sci_status SCI_SUCCESS
1379 static enum sci_status scic_sds_request_aborting_state_tc_completion_handler(
1380 struct scic_sds_request *sci_req,
1381 u32 completion_code)
1383 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1384 case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT):
1385 case (SCU_TASK_DONE_TASK_ABORT << SCU_COMPLETION_TL_STATUS_SHIFT):
1386 scic_sds_request_set_status(
1387 sci_req, SCU_TASK_DONE_TASK_ABORT, SCI_FAILURE_IO_TERMINATED
1390 sci_base_state_machine_change_state(&sci_req->state_machine,
1391 SCI_BASE_REQUEST_STATE_COMPLETED);
1392 break;
1394 default:
1396 * Unless we get some strange error wait for the task abort to complete
1397 * TODO: Should there be a state change for this completion? */
1398 break;
1401 return SCI_SUCCESS;
1405 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1406 * object receives a scic_sds_request_frame_handler() request. This method
1407 * discards the unsolicited frame since we are waiting for the abort task
1408 * completion. enum sci_status SCI_SUCCESS
1410 static enum sci_status scic_sds_request_aborting_state_frame_handler(
1411 struct scic_sds_request *sci_req,
1412 u32 frame_index)
1414 /* TODO: Is it even possible to get an unsolicited frame in the aborting state? */
1416 scic_sds_controller_release_frame(
1417 sci_req->owning_controller, frame_index);
1419 return SCI_SUCCESS;
1422 static const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table[] = {
1423 [SCI_BASE_REQUEST_STATE_INITIAL] = {
1425 [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
1426 .start_handler = scic_sds_request_constructed_state_start_handler,
1427 .abort_handler = scic_sds_request_constructed_state_abort_handler,
1429 [SCI_BASE_REQUEST_STATE_STARTED] = {
1430 .abort_handler = scic_sds_request_started_state_abort_handler,
1431 .tc_completion_handler = scic_sds_request_started_state_tc_completion_handler,
1432 .frame_handler = scic_sds_request_started_state_frame_handler,
1434 [SCI_BASE_REQUEST_STATE_COMPLETED] = {
1435 .complete_handler = scic_sds_request_completed_state_complete_handler,
1437 [SCI_BASE_REQUEST_STATE_ABORTING] = {
1438 .abort_handler = scic_sds_request_aborting_state_abort_handler,
1439 .tc_completion_handler = scic_sds_request_aborting_state_tc_completion_handler,
1440 .frame_handler = scic_sds_request_aborting_state_frame_handler,
1442 [SCI_BASE_REQUEST_STATE_FINAL] = {
1447 * scic_sds_request_initial_state_enter() -
1448 * @object: This parameter specifies the base object for which the state
1449 * transition is occurring.
1451 * This method implements the actions taken when entering the
1452 * SCI_BASE_REQUEST_STATE_INITIAL state. This state is entered when the initial
1453 * base request is constructed. Entry into the initial state sets all handlers
1454 * for the io request object to their default handlers. none
1456 static void scic_sds_request_initial_state_enter(void *object)
1458 struct scic_sds_request *sci_req = object;
1460 SET_STATE_HANDLER(
1461 sci_req,
1462 scic_sds_request_state_handler_table,
1463 SCI_BASE_REQUEST_STATE_INITIAL
1468 * scic_sds_request_constructed_state_enter() -
1469 * @object: The io request object that is to enter the constructed state.
1471 * This method implements the actions taken when entering the
1472 * SCI_BASE_REQUEST_STATE_CONSTRUCTED state. The method sets the state handlers
1473 * for the the constructed state. none
1475 static void scic_sds_request_constructed_state_enter(void *object)
1477 struct scic_sds_request *sci_req = object;
1479 SET_STATE_HANDLER(
1480 sci_req,
1481 scic_sds_request_state_handler_table,
1482 SCI_BASE_REQUEST_STATE_CONSTRUCTED
1487 * scic_sds_request_started_state_enter() -
1488 * @object: This parameter specifies the base object for which the state
1489 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
1491 * This method implements the actions taken when entering the
1492 * SCI_BASE_REQUEST_STATE_STARTED state. If the io request object type is a
1493 * SCSI Task request we must enter the started substate machine. none
1495 static void scic_sds_request_started_state_enter(void *object)
1497 struct scic_sds_request *sci_req = object;
1499 SET_STATE_HANDLER(
1500 sci_req,
1501 scic_sds_request_state_handler_table,
1502 SCI_BASE_REQUEST_STATE_STARTED
1506 * Most of the request state machines have a started substate machine so
1507 * start its execution on the entry to the started state. */
1508 if (sci_req->has_started_substate_machine == true)
1509 sci_base_state_machine_start(&sci_req->started_substate_machine);
1513 * scic_sds_request_started_state_exit() -
1514 * @object: This parameter specifies the base object for which the state
1515 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1516 * object.
1518 * This method implements the actions taken when exiting the
1519 * SCI_BASE_REQUEST_STATE_STARTED state. For task requests the action will be
1520 * to stop the started substate machine. none
1522 static void scic_sds_request_started_state_exit(void *object)
1524 struct scic_sds_request *sci_req = object;
1526 if (sci_req->has_started_substate_machine == true)
1527 sci_base_state_machine_stop(&sci_req->started_substate_machine);
1531 * scic_sds_request_completed_state_enter() -
1532 * @object: This parameter specifies the base object for which the state
1533 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1534 * object.
1536 * This method implements the actions taken when entering the
1537 * SCI_BASE_REQUEST_STATE_COMPLETED state. This state is entered when the
1538 * SCIC_SDS_IO_REQUEST has completed. The method will decode the request
1539 * completion status and convert it to an enum sci_status to return in the
1540 * completion callback function. none
1542 static void scic_sds_request_completed_state_enter(void *object)
1544 struct scic_sds_request *sci_req = object;
1545 struct scic_sds_controller *scic =
1546 scic_sds_request_get_controller(sci_req);
1547 struct isci_host *ihost = scic_to_ihost(scic);
1548 struct isci_request *ireq = sci_req->ireq;
1550 SET_STATE_HANDLER(sci_req,
1551 scic_sds_request_state_handler_table,
1552 SCI_BASE_REQUEST_STATE_COMPLETED);
1554 /* Tell the SCI_USER that the IO request is complete */
1555 if (sci_req->is_task_management_request == false)
1556 isci_request_io_request_complete(ihost,
1557 ireq,
1558 sci_req->sci_status);
1559 else
1560 isci_task_request_complete(ihost, ireq, sci_req->sci_status);
1564 * scic_sds_request_aborting_state_enter() -
1565 * @object: This parameter specifies the base object for which the state
1566 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
1567 * object.
1569 * This method implements the actions taken when entering the
1570 * SCI_BASE_REQUEST_STATE_ABORTING state. none
1572 static void scic_sds_request_aborting_state_enter(void *object)
1574 struct scic_sds_request *sci_req = object;
1576 /* Setting the abort bit in the Task Context is required by the silicon. */
1577 sci_req->task_context_buffer->abort = 1;
1579 SET_STATE_HANDLER(
1580 sci_req,
1581 scic_sds_request_state_handler_table,
1582 SCI_BASE_REQUEST_STATE_ABORTING
1587 * scic_sds_request_final_state_enter() -
1588 * @object: This parameter specifies the base object for which the state
1589 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
1591 * This method implements the actions taken when entering the
1592 * SCI_BASE_REQUEST_STATE_FINAL state. The only action required is to put the
1593 * state handlers in place. none
1595 static void scic_sds_request_final_state_enter(void *object)
1597 struct scic_sds_request *sci_req = object;
1599 SET_STATE_HANDLER(
1600 sci_req,
1601 scic_sds_request_state_handler_table,
1602 SCI_BASE_REQUEST_STATE_FINAL
1606 static const struct sci_base_state scic_sds_request_state_table[] = {
1607 [SCI_BASE_REQUEST_STATE_INITIAL] = {
1608 .enter_state = scic_sds_request_initial_state_enter,
1610 [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
1611 .enter_state = scic_sds_request_constructed_state_enter,
1613 [SCI_BASE_REQUEST_STATE_STARTED] = {
1614 .enter_state = scic_sds_request_started_state_enter,
1615 .exit_state = scic_sds_request_started_state_exit
1617 [SCI_BASE_REQUEST_STATE_COMPLETED] = {
1618 .enter_state = scic_sds_request_completed_state_enter,
1620 [SCI_BASE_REQUEST_STATE_ABORTING] = {
1621 .enter_state = scic_sds_request_aborting_state_enter,
1623 [SCI_BASE_REQUEST_STATE_FINAL] = {
1624 .enter_state = scic_sds_request_final_state_enter,
1628 static void scic_sds_general_request_construct(struct scic_sds_controller *scic,
1629 struct scic_sds_remote_device *sci_dev,
1630 u16 io_tag,
1631 void *user_io_request_object,
1632 struct scic_sds_request *sci_req)
1634 sci_base_state_machine_construct(&sci_req->state_machine, sci_req,
1635 scic_sds_request_state_table, SCI_BASE_REQUEST_STATE_INITIAL);
1636 sci_base_state_machine_start(&sci_req->state_machine);
1638 sci_req->io_tag = io_tag;
1639 sci_req->user_request = user_io_request_object;
1640 sci_req->owning_controller = scic;
1641 sci_req->target_device = sci_dev;
1642 sci_req->has_started_substate_machine = false;
1643 sci_req->protocol = SCIC_NO_PROTOCOL;
1644 sci_req->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX;
1645 sci_req->device_sequence = scic_sds_remote_device_get_sequence(sci_dev);
1647 sci_req->sci_status = SCI_SUCCESS;
1648 sci_req->scu_status = 0;
1649 sci_req->post_context = 0xFFFFFFFF;
1651 sci_req->is_task_management_request = false;
1653 if (io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
1654 sci_req->was_tag_assigned_by_user = false;
1655 sci_req->task_context_buffer = NULL;
1656 } else {
1657 sci_req->was_tag_assigned_by_user = true;
1659 sci_req->task_context_buffer =
1660 scic_sds_controller_get_task_context_buffer(scic, io_tag);
1664 enum sci_status
1665 scic_io_request_construct(struct scic_sds_controller *scic,
1666 struct scic_sds_remote_device *sci_dev,
1667 u16 io_tag,
1668 void *user_req,
1669 struct scic_sds_request *sci_req,
1670 struct scic_sds_request **new_sci_req)
1672 struct domain_device *dev = sci_dev_to_domain(sci_dev);
1673 enum sci_status status = SCI_SUCCESS;
1675 /* Build the common part of the request */
1676 scic_sds_general_request_construct(scic,
1677 sci_dev,
1678 io_tag,
1679 user_req,
1680 sci_req);
1682 if (sci_dev->rnc.remote_node_index ==
1683 SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
1684 return SCI_FAILURE_INVALID_REMOTE_DEVICE;
1686 if (dev->dev_type == SAS_END_DEV)
1687 scic_sds_ssp_io_request_assign_buffers(sci_req);
1688 else if ((dev->dev_type == SATA_DEV) ||
1689 (dev->tproto & SAS_PROTOCOL_STP)) {
1690 scic_sds_stp_request_assign_buffers(sci_req);
1691 memset(sci_req->command_buffer,
1693 sizeof(struct host_to_dev_fis));
1694 } else if (dev_is_expander(dev)) {
1695 scic_sds_smp_request_assign_buffers(sci_req);
1696 memset(sci_req->command_buffer, 0, sizeof(struct smp_req));
1697 } else
1698 status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
1700 if (status == SCI_SUCCESS) {
1701 memset(sci_req->task_context_buffer,
1703 SCI_FIELD_OFFSET(struct scu_task_context, sgl_pair_ab));
1704 *new_sci_req = sci_req;
1707 return status;
1710 enum sci_status scic_task_request_construct(struct scic_sds_controller *scic,
1711 struct scic_sds_remote_device *sci_dev,
1712 u16 io_tag,
1713 void *user_io_request_object,
1714 struct scic_sds_request *sci_req,
1715 struct scic_sds_request **new_sci_req)
1717 struct domain_device *dev = sci_dev_to_domain(sci_dev);
1718 enum sci_status status = SCI_SUCCESS;
1720 /* Build the common part of the request */
1721 scic_sds_general_request_construct(scic, sci_dev, io_tag,
1722 user_io_request_object,
1723 sci_req);
1725 if (dev->dev_type == SAS_END_DEV) {
1726 scic_sds_ssp_task_request_assign_buffers(sci_req);
1728 sci_req->has_started_substate_machine = true;
1730 /* Construct the started sub-state machine. */
1731 sci_base_state_machine_construct(
1732 &sci_req->started_substate_machine,
1733 sci_req,
1734 scic_sds_io_request_started_task_mgmt_substate_table,
1735 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
1737 } else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))
1738 scic_sds_stp_request_assign_buffers(sci_req);
1739 else
1740 status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
1742 if (status == SCI_SUCCESS) {
1743 sci_req->is_task_management_request = true;
1744 memset(sci_req->task_context_buffer, 0, sizeof(struct scu_task_context));
1745 *new_sci_req = sci_req;
1748 return status;