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.
60 #include "scu_completion_codes.h"
61 #include "scu_event_codes.h"
65 * This method returns the sgl element pair for the specificed sgl_pair index.
66 * @sci_req: This parameter specifies the IO request for which to retrieve
67 * the Scatter-Gather List element pair.
68 * @sgl_pair_index: This parameter specifies the index into the SGL element
69 * pair to be retrieved.
71 * This method returns a pointer to an struct scu_sgl_element_pair.
73 static struct scu_sgl_element_pair *scic_sds_request_get_sgl_element_pair(
74 struct scic_sds_request *sci_req,
77 struct scu_task_context *task_context;
79 task_context = (struct scu_task_context *)sci_req->task_context_buffer;
81 if (sgl_pair_index == 0) {
82 return &task_context->sgl_pair_ab;
83 } else if (sgl_pair_index == 1) {
84 return &task_context->sgl_pair_cd;
87 return &sci_req->sg_table[sgl_pair_index - 2];
91 * This function will build the SGL list for an IO request.
92 * @sci_req: This parameter specifies the IO request for which to build
93 * the Scatter-Gather List.
96 static void scic_sds_request_build_sgl(struct scic_sds_request *sds_request)
98 struct isci_request *isci_request = sci_req_to_ireq(sds_request);
99 struct isci_host *isci_host = isci_request->isci_host;
100 struct sas_task *task = isci_request_access_task(isci_request);
101 struct scatterlist *sg = NULL;
104 struct scu_sgl_element_pair *scu_sg = NULL;
105 struct scu_sgl_element_pair *prev_sg = NULL;
107 if (task->num_scatter > 0) {
111 scu_sg = scic_sds_request_get_sgl_element_pair(
115 SCU_SGL_COPY(scu_sg->A, sg);
120 SCU_SGL_COPY(scu_sg->B, sg);
123 SCU_SGL_ZERO(scu_sg->B);
127 scic_io_request_get_dma_addr(
131 prev_sg->next_pair_upper =
132 upper_32_bits(dma_addr);
133 prev_sg->next_pair_lower =
134 lower_32_bits(dma_addr);
140 } else { /* handle when no sg */
141 scu_sg = scic_sds_request_get_sgl_element_pair(sds_request,
144 dma_addr = dma_map_single(&isci_host->pdev->dev,
146 task->total_xfer_len,
149 isci_request->zero_scatter_daddr = dma_addr;
151 scu_sg->A.length = task->total_xfer_len;
152 scu_sg->A.address_upper = upper_32_bits(dma_addr);
153 scu_sg->A.address_lower = lower_32_bits(dma_addr);
157 scu_sg->next_pair_upper = 0;
158 scu_sg->next_pair_lower = 0;
162 static void scic_sds_io_request_build_ssp_command_iu(struct scic_sds_request *sci_req)
164 struct ssp_cmd_iu *cmd_iu;
165 struct isci_request *ireq = sci_req_to_ireq(sci_req);
166 struct sas_task *task = isci_request_access_task(ireq);
168 cmd_iu = &sci_req->ssp.cmd;
170 memcpy(cmd_iu->LUN, task->ssp_task.LUN, 8);
171 cmd_iu->add_cdb_len = 0;
174 cmd_iu->en_fburst = 0; /* unsupported */
175 cmd_iu->task_prio = task->ssp_task.task_prio;
176 cmd_iu->task_attr = task->ssp_task.task_attr;
179 sci_swab32_cpy(&cmd_iu->cdb, task->ssp_task.cdb,
180 sizeof(task->ssp_task.cdb) / sizeof(u32));
183 static void scic_sds_task_request_build_ssp_task_iu(struct scic_sds_request *sci_req)
185 struct ssp_task_iu *task_iu;
186 struct isci_request *ireq = sci_req_to_ireq(sci_req);
187 struct sas_task *task = isci_request_access_task(ireq);
188 struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq);
190 task_iu = &sci_req->ssp.tmf;
192 memset(task_iu, 0, sizeof(struct ssp_task_iu));
194 memcpy(task_iu->LUN, task->ssp_task.LUN, 8);
196 task_iu->task_func = isci_tmf->tmf_code;
198 (ireq->ttype == tmf_task) ?
200 SCI_CONTROLLER_INVALID_IO_TAG;
204 * This method is will fill in the SCU Task Context for any type of SSP request.
209 static void scu_ssp_reqeust_construct_task_context(
210 struct scic_sds_request *sds_request,
211 struct scu_task_context *task_context)
214 struct scic_sds_controller *controller;
215 struct scic_sds_remote_device *target_device;
216 struct scic_sds_port *target_port;
218 controller = scic_sds_request_get_controller(sds_request);
219 target_device = scic_sds_request_get_device(sds_request);
220 target_port = scic_sds_request_get_port(sds_request);
222 /* Fill in the TC with the its required data */
223 task_context->abort = 0;
224 task_context->priority = 0;
225 task_context->initiator_request = 1;
226 task_context->connection_rate = target_device->connection_rate;
227 task_context->protocol_engine_index =
228 scic_sds_controller_get_protocol_engine_group(controller);
229 task_context->logical_port_index =
230 scic_sds_port_get_index(target_port);
231 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP;
232 task_context->valid = SCU_TASK_CONTEXT_VALID;
233 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
235 task_context->remote_node_index =
236 scic_sds_remote_device_get_index(sds_request->target_device);
237 task_context->command_code = 0;
239 task_context->link_layer_control = 0;
240 task_context->do_not_dma_ssp_good_response = 1;
241 task_context->strict_ordering = 0;
242 task_context->control_frame = 0;
243 task_context->timeout_enable = 0;
244 task_context->block_guard_enable = 0;
246 task_context->address_modifier = 0;
248 /* task_context->type.ssp.tag = sci_req->io_tag; */
249 task_context->task_phase = 0x01;
251 if (sds_request->was_tag_assigned_by_user) {
253 * Build the task context now since we have already read
256 sds_request->post_context =
257 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
258 (scic_sds_controller_get_protocol_engine_group(
260 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
261 (scic_sds_port_get_index(target_port) <<
262 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
263 scic_sds_io_tag_get_index(sds_request->io_tag));
266 * Build the task context now since we have already read
269 * I/O tag index is not assigned because we have to wait
272 sds_request->post_context =
273 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
274 (scic_sds_controller_get_protocol_engine_group(
275 owning_controller) <<
276 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
277 (scic_sds_port_get_index(target_port) <<
278 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
282 * Copy the physical address for the command buffer to the
285 dma_addr = scic_io_request_get_dma_addr(sds_request,
286 &sds_request->ssp.cmd);
288 task_context->command_iu_upper = upper_32_bits(dma_addr);
289 task_context->command_iu_lower = lower_32_bits(dma_addr);
292 * Copy the physical address for the response buffer to the
295 dma_addr = scic_io_request_get_dma_addr(sds_request,
296 &sds_request->ssp.rsp);
298 task_context->response_iu_upper = upper_32_bits(dma_addr);
299 task_context->response_iu_lower = lower_32_bits(dma_addr);
303 * This method is will fill in the SCU Task Context for a SSP IO request.
307 static void scu_ssp_io_request_construct_task_context(
308 struct scic_sds_request *sci_req,
309 enum dma_data_direction dir,
312 struct scu_task_context *task_context;
314 task_context = scic_sds_request_get_task_context(sci_req);
316 scu_ssp_reqeust_construct_task_context(sci_req, task_context);
318 task_context->ssp_command_iu_length =
319 sizeof(struct ssp_cmd_iu) / sizeof(u32);
320 task_context->type.ssp.frame_type = SSP_COMMAND;
323 case DMA_FROM_DEVICE:
326 task_context->task_type = SCU_TASK_TYPE_IOREAD;
329 task_context->task_type = SCU_TASK_TYPE_IOWRITE;
333 task_context->transfer_length_bytes = len;
335 if (task_context->transfer_length_bytes > 0)
336 scic_sds_request_build_sgl(sci_req);
340 * This method will fill in the SCU Task Context for a SSP Task request. The
341 * following important settings are utilized: -# priority ==
342 * SCU_TASK_PRIORITY_HIGH. This ensures that the task request is issued
343 * ahead of other task destined for the same Remote Node. -# task_type ==
344 * SCU_TASK_TYPE_IOREAD. This simply indicates that a normal request type
345 * (i.e. non-raw frame) is being utilized to perform task management. -#
346 * control_frame == 1. This ensures that the proper endianess is set so
347 * that the bytes are transmitted in the right order for a task frame.
348 * @sci_req: This parameter specifies the task request object being
352 static void scu_ssp_task_request_construct_task_context(
353 struct scic_sds_request *sci_req)
355 struct scu_task_context *task_context;
357 task_context = scic_sds_request_get_task_context(sci_req);
359 scu_ssp_reqeust_construct_task_context(sci_req, task_context);
361 task_context->control_frame = 1;
362 task_context->priority = SCU_TASK_PRIORITY_HIGH;
363 task_context->task_type = SCU_TASK_TYPE_RAW_FRAME;
364 task_context->transfer_length_bytes = 0;
365 task_context->type.ssp.frame_type = SSP_TASK;
366 task_context->ssp_command_iu_length =
367 sizeof(struct ssp_task_iu) / sizeof(u32);
371 * This method is will fill in the SCU Task Context for any type of SATA
372 * request. This is called from the various SATA constructors.
373 * @sci_req: The general IO request object which is to be used in
374 * constructing the SCU task context.
375 * @task_context: The buffer pointer for the SCU task context which is being
378 * The general io request construction is complete. The buffer assignment for
379 * the command buffer is complete. none Revisit task context construction to
380 * determine what is common for SSP/SMP/STP task context structures.
382 static void scu_sata_reqeust_construct_task_context(
383 struct scic_sds_request *sci_req,
384 struct scu_task_context *task_context)
387 struct scic_sds_controller *controller;
388 struct scic_sds_remote_device *target_device;
389 struct scic_sds_port *target_port;
391 controller = scic_sds_request_get_controller(sci_req);
392 target_device = scic_sds_request_get_device(sci_req);
393 target_port = scic_sds_request_get_port(sci_req);
395 /* Fill in the TC with the its required data */
396 task_context->abort = 0;
397 task_context->priority = SCU_TASK_PRIORITY_NORMAL;
398 task_context->initiator_request = 1;
399 task_context->connection_rate = target_device->connection_rate;
400 task_context->protocol_engine_index =
401 scic_sds_controller_get_protocol_engine_group(controller);
402 task_context->logical_port_index =
403 scic_sds_port_get_index(target_port);
404 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_STP;
405 task_context->valid = SCU_TASK_CONTEXT_VALID;
406 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
408 task_context->remote_node_index =
409 scic_sds_remote_device_get_index(sci_req->target_device);
410 task_context->command_code = 0;
412 task_context->link_layer_control = 0;
413 task_context->do_not_dma_ssp_good_response = 1;
414 task_context->strict_ordering = 0;
415 task_context->control_frame = 0;
416 task_context->timeout_enable = 0;
417 task_context->block_guard_enable = 0;
419 task_context->address_modifier = 0;
420 task_context->task_phase = 0x01;
422 task_context->ssp_command_iu_length =
423 (sizeof(struct host_to_dev_fis) - sizeof(u32)) / sizeof(u32);
425 /* Set the first word of the H2D REG FIS */
426 task_context->type.words[0] = *(u32 *)&sci_req->stp.cmd;
428 if (sci_req->was_tag_assigned_by_user) {
430 * Build the task context now since we have already read
433 sci_req->post_context =
434 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
435 (scic_sds_controller_get_protocol_engine_group(
437 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
438 (scic_sds_port_get_index(target_port) <<
439 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
440 scic_sds_io_tag_get_index(sci_req->io_tag));
443 * Build the task context now since we have already read
445 * I/O tag index is not assigned because we have to wait
446 * until we get a TCi.
448 sci_req->post_context =
449 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
450 (scic_sds_controller_get_protocol_engine_group(
452 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
453 (scic_sds_port_get_index(target_port) <<
454 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
458 * Copy the physical address for the command buffer to the SCU Task
459 * Context. We must offset the command buffer by 4 bytes because the
460 * first 4 bytes are transfered in the body of the TC.
462 dma_addr = scic_io_request_get_dma_addr(sci_req,
463 ((char *) &sci_req->stp.cmd) +
466 task_context->command_iu_upper = upper_32_bits(dma_addr);
467 task_context->command_iu_lower = lower_32_bits(dma_addr);
469 /* SATA Requests do not have a response buffer */
470 task_context->response_iu_upper = 0;
471 task_context->response_iu_lower = 0;
477 * scu_stp_raw_request_construct_task_context -
478 * @sci_req: This parameter specifies the STP request object for which to
479 * construct a RAW command frame task context.
480 * @task_context: This parameter specifies the SCU specific task context buffer
483 * This method performs the operations common to all SATA/STP requests
484 * utilizing the raw frame method. none
486 static void scu_stp_raw_request_construct_task_context(struct scic_sds_stp_request *stp_req,
487 struct scu_task_context *task_context)
489 struct scic_sds_request *sci_req = to_sci_req(stp_req);
491 scu_sata_reqeust_construct_task_context(sci_req, task_context);
493 task_context->control_frame = 0;
494 task_context->priority = SCU_TASK_PRIORITY_NORMAL;
495 task_context->task_type = SCU_TASK_TYPE_SATA_RAW_FRAME;
496 task_context->type.stp.fis_type = FIS_REGH2D;
497 task_context->transfer_length_bytes = sizeof(struct host_to_dev_fis) - sizeof(u32);
500 static enum sci_status
501 scic_sds_stp_pio_request_construct(struct scic_sds_request *sci_req,
504 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
505 struct scic_sds_stp_pio_request *pio = &stp_req->type.pio;
507 scu_stp_raw_request_construct_task_context(stp_req,
508 sci_req->task_context_buffer);
510 pio->current_transfer_bytes = 0;
511 pio->ending_error = 0;
512 pio->ending_status = 0;
514 pio->request_current.sgl_offset = 0;
515 pio->request_current.sgl_set = SCU_SGL_ELEMENT_PAIR_A;
518 scic_sds_request_build_sgl(sci_req);
519 /* Since the IO request copy of the TC contains the same data as
520 * the actual TC this pointer is vaild for either.
522 pio->request_current.sgl_pair = &sci_req->task_context_buffer->sgl_pair_ab;
524 /* The user does not want the data copied to the SGL buffer location */
525 pio->request_current.sgl_pair = NULL;
533 * @sci_req: This parameter specifies the request to be constructed as an
535 * @optimized_task_type: This parameter specifies whether the request is to be
536 * an UDMA request or a NCQ request. - A value of 0 indicates UDMA. - A
537 * value of 1 indicates NCQ.
539 * This method will perform request construction common to all types of STP
540 * requests that are optimized by the silicon (i.e. UDMA, NCQ). This method
541 * returns an indication as to whether the construction was successful.
543 static void scic_sds_stp_optimized_request_construct(struct scic_sds_request *sci_req,
544 u8 optimized_task_type,
546 enum dma_data_direction dir)
548 struct scu_task_context *task_context = sci_req->task_context_buffer;
550 /* Build the STP task context structure */
551 scu_sata_reqeust_construct_task_context(sci_req, task_context);
553 /* Copy over the SGL elements */
554 scic_sds_request_build_sgl(sci_req);
556 /* Copy over the number of bytes to be transfered */
557 task_context->transfer_length_bytes = len;
559 if (dir == DMA_TO_DEVICE) {
561 * The difference between the DMA IN and DMA OUT request task type
562 * values are consistent with the difference between FPDMA READ
563 * and FPDMA WRITE values. Add the supplied task type parameter
564 * to this difference to set the task type properly for this
565 * DATA OUT (WRITE) case. */
566 task_context->task_type = optimized_task_type + (SCU_TASK_TYPE_DMA_OUT
567 - SCU_TASK_TYPE_DMA_IN);
570 * For the DATA IN (READ) case, simply save the supplied
571 * optimized task type. */
572 task_context->task_type = optimized_task_type;
578 static enum sci_status
579 scic_io_request_construct_sata(struct scic_sds_request *sci_req,
581 enum dma_data_direction dir,
584 enum sci_status status = SCI_SUCCESS;
585 struct isci_request *ireq = sci_req_to_ireq(sci_req);
586 struct sas_task *task = isci_request_access_task(ireq);
588 /* check for management protocols */
589 if (ireq->ttype == tmf_task) {
590 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
592 if (tmf->tmf_code == isci_tmf_sata_srst_high ||
593 tmf->tmf_code == isci_tmf_sata_srst_low) {
594 scu_stp_raw_request_construct_task_context(&sci_req->stp.req,
595 sci_req->task_context_buffer);
598 dev_err(scic_to_dev(sci_req->owning_controller),
599 "%s: Request 0x%p received un-handled SAT "
600 "management protocol 0x%x.\n",
601 __func__, sci_req, tmf->tmf_code);
607 if (!sas_protocol_ata(task->task_proto)) {
608 dev_err(scic_to_dev(sci_req->owning_controller),
609 "%s: Non-ATA protocol in SATA path: 0x%x\n",
617 if (task->data_dir == DMA_NONE) {
618 scu_stp_raw_request_construct_task_context(&sci_req->stp.req,
619 sci_req->task_context_buffer);
624 if (task->ata_task.use_ncq) {
625 scic_sds_stp_optimized_request_construct(sci_req,
626 SCU_TASK_TYPE_FPDMAQ_READ,
632 if (task->ata_task.dma_xfer) {
633 scic_sds_stp_optimized_request_construct(sci_req,
634 SCU_TASK_TYPE_DMA_IN,
638 return scic_sds_stp_pio_request_construct(sci_req, copy);
643 static enum sci_status scic_io_request_construct_basic_ssp(struct scic_sds_request *sci_req)
645 struct isci_request *ireq = sci_req_to_ireq(sci_req);
646 struct sas_task *task = isci_request_access_task(ireq);
648 sci_req->protocol = SCIC_SSP_PROTOCOL;
650 scu_ssp_io_request_construct_task_context(sci_req,
652 task->total_xfer_len);
654 scic_sds_io_request_build_ssp_command_iu(sci_req);
656 sci_base_state_machine_change_state(&sci_req->state_machine,
657 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
662 enum sci_status scic_task_request_construct_ssp(
663 struct scic_sds_request *sci_req)
665 /* Construct the SSP Task SCU Task Context */
666 scu_ssp_task_request_construct_task_context(sci_req);
668 /* Fill in the SSP Task IU */
669 scic_sds_task_request_build_ssp_task_iu(sci_req);
671 sci_base_state_machine_change_state(&sci_req->state_machine,
672 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
677 static enum sci_status scic_io_request_construct_basic_sata(struct scic_sds_request *sci_req)
679 enum sci_status status;
680 struct scic_sds_stp_request *stp_req;
682 struct isci_request *isci_request = sci_req_to_ireq(sci_req);
683 struct sas_task *task = isci_request_access_task(isci_request);
685 stp_req = &sci_req->stp.req;
686 sci_req->protocol = SCIC_STP_PROTOCOL;
688 copy = (task->data_dir == DMA_NONE) ? false : true;
690 status = scic_io_request_construct_sata(sci_req,
691 task->total_xfer_len,
695 if (status == SCI_SUCCESS)
696 sci_base_state_machine_change_state(&sci_req->state_machine,
697 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
702 enum sci_status scic_task_request_construct_sata(struct scic_sds_request *sci_req)
704 enum sci_status status = SCI_SUCCESS;
705 struct isci_request *ireq = sci_req_to_ireq(sci_req);
707 /* check for management protocols */
708 if (ireq->ttype == tmf_task) {
709 struct isci_tmf *tmf = isci_request_access_tmf(ireq);
711 if (tmf->tmf_code == isci_tmf_sata_srst_high ||
712 tmf->tmf_code == isci_tmf_sata_srst_low) {
713 scu_stp_raw_request_construct_task_context(&sci_req->stp.req,
714 sci_req->task_context_buffer);
716 dev_err(scic_to_dev(sci_req->owning_controller),
717 "%s: Request 0x%p received un-handled SAT "
719 __func__, sci_req, tmf->tmf_code);
725 if (status != SCI_SUCCESS)
727 sci_base_state_machine_change_state(&sci_req->state_machine,
728 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
734 * sci_req_tx_bytes - bytes transferred when reply underruns request
735 * @sci_req: request that was terminated early
737 #define SCU_TASK_CONTEXT_SRAM 0x200000
738 static u32 sci_req_tx_bytes(struct scic_sds_request *sci_req)
740 struct scic_sds_controller *scic = sci_req->owning_controller;
743 if (readl(&scic->smu_registers->address_modifier) == 0) {
744 void __iomem *scu_reg_base = scic->scu_registers;
746 /* get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where
747 * BAR1 is the scu_registers
748 * 0x20002C = 0x200000 + 0x2c
749 * = start of task context SRAM + offset of (type.ssp.data_offset)
750 * TCi is the io_tag of struct scic_sds_request
752 ret_val = readl(scu_reg_base +
753 (SCU_TASK_CONTEXT_SRAM + offsetof(struct scu_task_context, type.ssp.data_offset)) +
754 ((sizeof(struct scu_task_context)) * scic_sds_io_tag_get_index(sci_req->io_tag)));
761 scic_sds_request_start(struct scic_sds_request *request)
763 if (request->device_sequence !=
764 scic_sds_remote_device_get_sequence(request->target_device))
767 if (request->state_handlers->start_handler)
768 return request->state_handlers->start_handler(request);
770 dev_warn(scic_to_dev(request->owning_controller),
771 "%s: SCIC IO Request requested to start while in wrong "
774 sci_base_state_machine_get_state(&request->state_machine));
776 return SCI_FAILURE_INVALID_STATE;
780 scic_sds_io_request_terminate(struct scic_sds_request *sci_req)
782 enum sci_base_request_states state;
784 state = sci_req->state_machine.current_state_id;
787 case SCI_BASE_REQUEST_STATE_CONSTRUCTED:
788 scic_sds_request_set_status(sci_req,
789 SCU_TASK_DONE_TASK_ABORT,
790 SCI_FAILURE_IO_TERMINATED);
792 sci_base_state_machine_change_state(&sci_req->state_machine,
793 SCI_BASE_REQUEST_STATE_COMPLETED);
795 case SCI_BASE_REQUEST_STATE_STARTED:
796 case SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION:
797 case SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE:
798 case SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION:
799 case SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE:
800 case SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE:
801 case SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE:
802 case SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE:
803 case SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE:
804 case SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE:
805 case SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE:
806 case SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE:
807 case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE:
808 case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE:
809 case SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE:
810 sci_base_state_machine_change_state(&sci_req->state_machine,
811 SCI_BASE_REQUEST_STATE_ABORTING);
813 case SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE:
814 sci_base_state_machine_change_state(&sci_req->state_machine,
815 SCI_BASE_REQUEST_STATE_ABORTING);
816 sci_base_state_machine_change_state(&sci_req->state_machine,
817 SCI_BASE_REQUEST_STATE_COMPLETED);
819 case SCI_BASE_REQUEST_STATE_ABORTING:
820 sci_base_state_machine_change_state(&sci_req->state_machine,
821 SCI_BASE_REQUEST_STATE_COMPLETED);
823 case SCI_BASE_REQUEST_STATE_COMPLETED:
825 dev_warn(scic_to_dev(sci_req->owning_controller),
826 "%s: SCIC IO Request requested to abort while in wrong "
829 sci_base_state_machine_get_state(&sci_req->state_machine));
833 return SCI_FAILURE_INVALID_STATE;
836 enum sci_status scic_sds_io_request_event_handler(
837 struct scic_sds_request *request,
840 if (request->state_handlers->event_handler)
841 return request->state_handlers->event_handler(request, event_code);
843 dev_warn(scic_to_dev(request->owning_controller),
844 "%s: SCIC IO Request given event code notification %x while "
845 "in wrong state %d\n",
848 sci_base_state_machine_get_state(&request->state_machine));
850 return SCI_FAILURE_INVALID_STATE;
855 * @sci_req: The SCIC_SDS_IO_REQUEST_T object for which the start
856 * operation is to be executed.
857 * @frame_index: The frame index returned by the hardware for the reqeust
860 * This method invokes the core state frame handler for the
861 * SCIC_SDS_IO_REQUEST_T object. enum sci_status
863 enum sci_status scic_sds_io_request_frame_handler(
864 struct scic_sds_request *request,
867 if (request->state_handlers->frame_handler)
868 return request->state_handlers->frame_handler(request, frame_index);
870 dev_warn(scic_to_dev(request->owning_controller),
871 "%s: SCIC IO Request given unexpected frame %x while in "
875 sci_base_state_machine_get_state(&request->state_machine));
877 scic_sds_controller_release_frame(request->owning_controller, frame_index);
878 return SCI_FAILURE_INVALID_STATE;
882 * This function copies response data for requests returning response data
883 * instead of sense data.
884 * @sci_req: This parameter specifies the request object for which to copy
887 static void scic_sds_io_request_copy_response(struct scic_sds_request *sci_req)
891 struct ssp_response_iu *ssp_response;
892 struct isci_request *ireq = sci_req_to_ireq(sci_req);
893 struct isci_tmf *isci_tmf = isci_request_access_tmf(ireq);
895 ssp_response = &sci_req->ssp.rsp;
897 resp_buf = &isci_tmf->resp.resp_iu;
900 SSP_RESP_IU_MAX_SIZE,
901 be32_to_cpu(ssp_response->response_data_len));
903 memcpy(resp_buf, ssp_response->resp_data, len);
907 * This method implements the action taken when a constructed
908 * SCIC_SDS_IO_REQUEST_T object receives a scic_sds_request_start() request.
909 * This method will, if necessary, allocate a TCi for the io request object and
910 * then will, if necessary, copy the constructed TC data into the actual TC
911 * buffer. If everything is successful the post context field is updated with
912 * the TCi so the controller can post the request to the hardware. enum sci_status
913 * SCI_SUCCESS SCI_FAILURE_INSUFFICIENT_RESOURCES
915 static enum sci_status scic_sds_request_constructed_state_start_handler(
916 struct scic_sds_request *request)
918 struct scu_task_context *task_context;
920 if (request->io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
922 scic_controller_allocate_io_tag(request->owning_controller);
925 /* Record the IO Tag in the request */
926 if (request->io_tag != SCI_CONTROLLER_INVALID_IO_TAG) {
927 task_context = request->task_context_buffer;
929 task_context->task_index = scic_sds_io_tag_get_index(request->io_tag);
931 switch (task_context->protocol_type) {
932 case SCU_TASK_CONTEXT_PROTOCOL_SMP:
933 case SCU_TASK_CONTEXT_PROTOCOL_SSP:
935 task_context->type.ssp.tag = request->io_tag;
936 task_context->type.ssp.target_port_transfer_tag = 0xFFFF;
939 case SCU_TASK_CONTEXT_PROTOCOL_STP:
942 * task_context->type.stp.ncq_tag = request->ncq_tag; */
945 case SCU_TASK_CONTEXT_PROTOCOL_NONE:
946 /* / @todo When do we set no protocol type? */
950 /* This should never happen since we build the IO requests */
955 * Check to see if we need to copy the task context buffer
956 * or have been building into the task context buffer */
957 if (request->was_tag_assigned_by_user == false) {
958 scic_sds_controller_copy_task_context(
959 request->owning_controller, request);
962 /* Add to the post_context the io tag value */
963 request->post_context |= scic_sds_io_tag_get_index(request->io_tag);
965 /* Everything is good go ahead and change state */
966 sci_base_state_machine_change_state(&request->state_machine,
967 SCI_BASE_REQUEST_STATE_STARTED);
972 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
976 * scic_sds_request_started_state_tc_completion_handler() - This method process
977 * TC (task context) completions for normal IO request (i.e. Task/Abort
978 * Completions of type 0). This method will update the
979 * SCIC_SDS_IO_REQUEST_T::status field.
980 * @sci_req: This parameter specifies the request for which a completion
982 * @completion_code: This parameter specifies the completion code received from
986 static enum sci_status
987 scic_sds_request_started_state_tc_completion_handler(struct scic_sds_request *sci_req,
991 struct ssp_response_iu *resp_iu;
994 * TODO: Any SDMA return code of other than 0 is bad
995 * decode 0x003C0000 to determine SDMA status
997 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
998 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
999 scic_sds_request_set_status(sci_req,
1004 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EARLY_RESP):
1007 * There are times when the SCU hardware will return an early
1008 * response because the io request specified more data than is
1009 * returned by the target device (mode pages, inquiry data,
1010 * etc.). We must check the response stats to see if this is
1011 * truly a failed request or a good request that just got
1014 struct ssp_response_iu *resp = &sci_req->ssp.rsp;
1015 ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
1017 sci_swab32_cpy(&sci_req->ssp.rsp,
1021 if (resp->status == 0) {
1022 scic_sds_request_set_status(
1025 SCI_SUCCESS_IO_DONE_EARLY);
1027 scic_sds_request_set_status(
1029 SCU_TASK_DONE_CHECK_RESPONSE,
1030 SCI_FAILURE_IO_RESPONSE_VALID);
1035 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CHECK_RESPONSE):
1037 ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
1039 sci_swab32_cpy(&sci_req->ssp.rsp,
1043 scic_sds_request_set_status(sci_req,
1044 SCU_TASK_DONE_CHECK_RESPONSE,
1045 SCI_FAILURE_IO_RESPONSE_VALID);
1049 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RESP_LEN_ERR):
1051 * / @todo With TASK_DONE_RESP_LEN_ERR is the response frame
1052 * guaranteed to be received before this completion status is
1055 resp_iu = &sci_req->ssp.rsp;
1056 datapres = resp_iu->datapres;
1058 if ((datapres == 0x01) || (datapres == 0x02)) {
1059 scic_sds_request_set_status(
1061 SCU_TASK_DONE_CHECK_RESPONSE,
1062 SCI_FAILURE_IO_RESPONSE_VALID);
1064 scic_sds_request_set_status(
1065 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
1068 /* only stp device gets suspended. */
1069 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
1070 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_PERR):
1071 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_ERR):
1072 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_DATA_LEN_ERR):
1073 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_ABORT_ERR):
1074 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_WD_LEN):
1075 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
1076 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_RESP):
1077 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_SDBFIS):
1078 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
1079 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDB_ERR):
1080 if (sci_req->protocol == SCIC_STP_PROTOCOL) {
1081 scic_sds_request_set_status(
1083 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
1084 SCU_COMPLETION_TL_STATUS_SHIFT,
1085 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
1087 scic_sds_request_set_status(
1089 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
1090 SCU_COMPLETION_TL_STATUS_SHIFT,
1091 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
1095 /* both stp/ssp device gets suspended */
1096 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LF_ERR):
1097 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_WRONG_DESTINATION):
1098 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1):
1099 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2):
1100 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3):
1101 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_BAD_DESTINATION):
1102 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_ZONE_VIOLATION):
1103 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY):
1104 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED):
1105 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED):
1106 scic_sds_request_set_status(
1108 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
1109 SCU_COMPLETION_TL_STATUS_SHIFT,
1110 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED);
1113 /* neither ssp nor stp gets suspended. */
1114 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_NAK_CMD_ERR):
1115 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_XR):
1116 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_XR_IU_LEN_ERR):
1117 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SDMA_ERR):
1118 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OFFSET_ERR):
1119 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_EXCESS_DATA):
1120 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
1121 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
1122 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
1123 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
1124 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_DATA):
1125 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_OPEN_FAIL):
1126 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_VIIT_ENTRY_NV):
1127 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_IIT_ENTRY_NV):
1128 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_RNCNV_OUTBOUND):
1130 scic_sds_request_set_status(
1132 SCU_GET_COMPLETION_TL_STATUS(completion_code) >>
1133 SCU_COMPLETION_TL_STATUS_SHIFT,
1134 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
1139 * TODO: This is probably wrong for ACK/NAK timeout conditions
1142 /* In all cases we will treat this as the completion of the IO req. */
1143 sci_base_state_machine_change_state(&sci_req->state_machine,
1144 SCI_BASE_REQUEST_STATE_COMPLETED);
1149 scic_sds_io_request_tc_completion(struct scic_sds_request *request, u32 completion_code)
1151 if (request->state_handlers->tc_completion_handler)
1152 return request->state_handlers->tc_completion_handler(request, completion_code);
1154 dev_warn(scic_to_dev(request->owning_controller),
1155 "%s: SCIC IO Request given task completion notification %x "
1156 "while in wrong state %d\n",
1159 sci_base_state_machine_get_state(&request->state_machine));
1161 return SCI_FAILURE_INVALID_STATE;
1165 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1166 * object receives a scic_sds_request_frame_handler() request. This method
1167 * first determines the frame type received. If this is a response frame then
1168 * the response data is copied to the io request response buffer for processing
1169 * at completion time. If the frame type is not a response buffer an error is
1170 * logged. enum sci_status SCI_SUCCESS SCI_FAILURE_INVALID_PARAMETER_VALUE
1172 static enum sci_status
1173 scic_sds_request_started_state_frame_handler(struct scic_sds_request *sci_req,
1176 enum sci_status status;
1178 struct ssp_frame_hdr ssp_hdr;
1181 status = scic_sds_unsolicited_frame_control_get_header(
1182 &(scic_sds_request_get_controller(sci_req)->uf_control),
1184 (void **)&frame_header);
1186 word_cnt = sizeof(struct ssp_frame_hdr) / sizeof(u32);
1187 sci_swab32_cpy(&ssp_hdr, frame_header, word_cnt);
1189 if (ssp_hdr.frame_type == SSP_RESPONSE) {
1190 struct ssp_response_iu *resp_iu;
1191 ssize_t word_cnt = SSP_RESP_IU_MAX_SIZE / sizeof(u32);
1193 status = scic_sds_unsolicited_frame_control_get_buffer(
1194 &(scic_sds_request_get_controller(sci_req)->uf_control),
1198 sci_swab32_cpy(&sci_req->ssp.rsp,
1201 resp_iu = &sci_req->ssp.rsp;
1203 if ((resp_iu->datapres == 0x01) ||
1204 (resp_iu->datapres == 0x02)) {
1205 scic_sds_request_set_status(
1207 SCU_TASK_DONE_CHECK_RESPONSE,
1208 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
1210 scic_sds_request_set_status(
1211 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
1213 /* This was not a response frame why did it get forwarded? */
1214 dev_err(scic_to_dev(sci_req->owning_controller),
1215 "%s: SCIC IO Request 0x%p received unexpected "
1216 "frame %d type 0x%02x\n",
1220 ssp_hdr.frame_type);
1224 * In any case we are done with this frame buffer return it to the
1227 scic_sds_controller_release_frame(
1228 sci_req->owning_controller, frame_index);
1234 * *****************************************************************************
1235 * * COMPLETED STATE HANDLERS
1236 * ***************************************************************************** */
1240 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1241 * object receives a scic_sds_request_complete() request. This method frees up
1242 * any io request resources that have been allocated and transitions the
1243 * request to its final state. Consider stopping the state machine instead of
1244 * transitioning to the final state? enum sci_status SCI_SUCCESS
1246 static enum sci_status scic_sds_request_completed_state_complete_handler(
1247 struct scic_sds_request *request)
1249 if (request->was_tag_assigned_by_user != true) {
1250 scic_controller_free_io_tag(
1251 request->owning_controller, request->io_tag);
1254 if (request->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX) {
1255 scic_sds_controller_release_frame(
1256 request->owning_controller, request->saved_rx_frame_index);
1259 sci_base_state_machine_change_state(&request->state_machine,
1260 SCI_BASE_REQUEST_STATE_FINAL);
1265 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1266 * object receives a scic_sds_request_task_completion() request. This method
1267 * decodes the completion type waiting for the abort task complete
1268 * notification. When the abort task complete is received the io request
1269 * transitions to the completed state. enum sci_status SCI_SUCCESS
1271 static enum sci_status scic_sds_request_aborting_state_tc_completion_handler(
1272 struct scic_sds_request *sci_req,
1273 u32 completion_code)
1275 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1276 case (SCU_TASK_DONE_GOOD << SCU_COMPLETION_TL_STATUS_SHIFT):
1277 case (SCU_TASK_DONE_TASK_ABORT << SCU_COMPLETION_TL_STATUS_SHIFT):
1278 scic_sds_request_set_status(
1279 sci_req, SCU_TASK_DONE_TASK_ABORT, SCI_FAILURE_IO_TERMINATED
1282 sci_base_state_machine_change_state(&sci_req->state_machine,
1283 SCI_BASE_REQUEST_STATE_COMPLETED);
1288 * Unless we get some strange error wait for the task abort to complete
1289 * TODO: Should there be a state change for this completion? */
1297 * This method implements the action to be taken when an SCIC_SDS_IO_REQUEST_T
1298 * object receives a scic_sds_request_frame_handler() request. This method
1299 * discards the unsolicited frame since we are waiting for the abort task
1300 * completion. enum sci_status SCI_SUCCESS
1302 static enum sci_status scic_sds_request_aborting_state_frame_handler(
1303 struct scic_sds_request *sci_req,
1306 /* TODO: Is it even possible to get an unsolicited frame in the aborting state? */
1308 scic_sds_controller_release_frame(
1309 sci_req->owning_controller, frame_index);
1315 * This method processes the completions transport layer (TL) status to
1316 * determine if the RAW task management frame was sent successfully. If the
1317 * raw frame was sent successfully, then the state for the task request
1318 * transitions to waiting for a response frame.
1319 * @sci_req: This parameter specifies the request for which the TC
1320 * completion was received.
1321 * @completion_code: This parameter indicates the completion status information
1324 * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
1325 * this method always returns success.
1327 static enum sci_status scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler(
1328 struct scic_sds_request *sci_req,
1329 u32 completion_code)
1331 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1332 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1333 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
1336 sci_base_state_machine_change_state(&sci_req->state_machine,
1337 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE);
1340 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_ACK_NAK_TO):
1342 * Currently, the decision is to simply allow the task request to
1343 * timeout if the task IU wasn't received successfully.
1344 * There is a potential for receiving multiple task responses if we
1345 * decide to send the task IU again. */
1346 dev_warn(scic_to_dev(sci_req->owning_controller),
1347 "%s: TaskRequest:0x%p CompletionCode:%x - "
1348 "ACK/NAK timeout\n",
1353 sci_base_state_machine_change_state(&sci_req->state_machine,
1354 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE);
1359 * All other completion status cause the IO to be complete. If a NAK
1360 * was received, then it is up to the user to retry the request. */
1361 scic_sds_request_set_status(
1363 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1364 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1367 sci_base_state_machine_change_state(&sci_req->state_machine,
1368 SCI_BASE_REQUEST_STATE_COMPLETED);
1376 * This method processes an unsolicited frame while the task mgmt request is
1377 * waiting for a response frame. It will copy the response data, release
1378 * the unsolicited frame, and transition the request to the
1379 * SCI_BASE_REQUEST_STATE_COMPLETED state.
1380 * @sci_req: This parameter specifies the request for which the
1381 * unsolicited frame was received.
1382 * @frame_index: This parameter indicates the unsolicited frame index that
1383 * should contain the response.
1385 * This method returns an indication of whether the TC response frame was
1386 * handled successfully or not. SCI_SUCCESS Currently this value is always
1387 * returned and indicates successful processing of the TC response. Should
1388 * probably update to check frame type and make sure it is a response frame.
1390 static enum sci_status scic_sds_ssp_task_request_await_tc_response_frame_handler(
1391 struct scic_sds_request *request,
1394 scic_sds_io_request_copy_response(request);
1396 sci_base_state_machine_change_state(&request->state_machine,
1397 SCI_BASE_REQUEST_STATE_COMPLETED);
1398 scic_sds_controller_release_frame(request->owning_controller,
1404 * This method processes an abnormal TC completion while the SMP request is
1405 * waiting for a response frame. It decides what happened to the IO based
1406 * on TC completion status.
1407 * @sci_req: This parameter specifies the request for which the TC
1408 * completion was received.
1409 * @completion_code: This parameter indicates the completion status information
1412 * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
1413 * this method always returns success.
1415 static enum sci_status scic_sds_smp_request_await_response_tc_completion_handler(
1416 struct scic_sds_request *sci_req,
1417 u32 completion_code)
1419 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1420 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1422 * In the AWAIT RESPONSE state, any TC completion is unexpected.
1423 * but if the TC has success status, we complete the IO anyway. */
1424 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
1427 sci_base_state_machine_change_state(&sci_req->state_machine,
1428 SCI_BASE_REQUEST_STATE_COMPLETED);
1431 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_RESP_TO_ERR):
1432 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_UFI_ERR):
1433 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_FRM_TYPE_ERR):
1434 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_SMP_LL_RX_ERR):
1436 * These status has been seen in a specific LSI expander, which sometimes
1437 * is not able to send smp response within 2 ms. This causes our hardware
1438 * break the connection and set TC completion with one of these SMP_XXX_XX_ERR
1439 * status. For these type of error, we ask scic user to retry the request. */
1440 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_SMP_RESP_TO_ERR,
1441 SCI_FAILURE_RETRY_REQUIRED);
1443 sci_base_state_machine_change_state(&sci_req->state_machine,
1444 SCI_BASE_REQUEST_STATE_COMPLETED);
1449 * All other completion status cause the IO to be complete. If a NAK
1450 * was received, then it is up to the user to retry the request. */
1451 scic_sds_request_set_status(
1453 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1454 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1457 sci_base_state_machine_change_state(&sci_req->state_machine,
1458 SCI_BASE_REQUEST_STATE_COMPLETED);
1466 * This function processes an unsolicited frame while the SMP request is waiting
1467 * for a response frame. It will copy the response data, release the
1468 * unsolicited frame, and transition the request to the
1469 * SCI_BASE_REQUEST_STATE_COMPLETED state.
1470 * @sci_req: This parameter specifies the request for which the
1471 * unsolicited frame was received.
1472 * @frame_index: This parameter indicates the unsolicited frame index that
1473 * should contain the response.
1475 * This function returns an indication of whether the response frame was handled
1476 * successfully or not. SCI_SUCCESS Currently this value is always returned and
1477 * indicates successful processing of the TC response.
1479 static enum sci_status
1480 scic_sds_smp_request_await_response_frame_handler(struct scic_sds_request *sci_req,
1483 enum sci_status status;
1485 struct smp_resp *rsp_hdr = &sci_req->smp.rsp;
1486 ssize_t word_cnt = SMP_RESP_HDR_SZ / sizeof(u32);
1488 status = scic_sds_unsolicited_frame_control_get_header(
1489 &(scic_sds_request_get_controller(sci_req)->uf_control),
1493 /* byte swap the header. */
1494 sci_swab32_cpy(rsp_hdr, frame_header, word_cnt);
1496 if (rsp_hdr->frame_type == SMP_RESPONSE) {
1499 status = scic_sds_unsolicited_frame_control_get_buffer(
1500 &(scic_sds_request_get_controller(sci_req)->uf_control),
1504 word_cnt = (sizeof(struct smp_req) - SMP_RESP_HDR_SZ) /
1507 sci_swab32_cpy(((u8 *) rsp_hdr) + SMP_RESP_HDR_SZ,
1508 smp_resp, word_cnt);
1510 scic_sds_request_set_status(
1511 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS);
1513 sci_base_state_machine_change_state(&sci_req->state_machine,
1514 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION);
1516 /* This was not a response frame why did it get forwarded? */
1517 dev_err(scic_to_dev(sci_req->owning_controller),
1518 "%s: SCIC SMP Request 0x%p received unexpected frame "
1523 rsp_hdr->frame_type);
1525 scic_sds_request_set_status(
1527 SCU_TASK_DONE_SMP_FRM_TYPE_ERR,
1528 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
1530 sci_base_state_machine_change_state(&sci_req->state_machine,
1531 SCI_BASE_REQUEST_STATE_COMPLETED);
1534 scic_sds_controller_release_frame(sci_req->owning_controller,
1541 * This method processes the completions transport layer (TL) status to
1542 * determine if the SMP request was sent successfully. If the SMP request
1543 * was sent successfully, then the state for the SMP request transits to
1544 * waiting for a response frame.
1545 * @sci_req: This parameter specifies the request for which the TC
1546 * completion was received.
1547 * @completion_code: This parameter indicates the completion status information
1550 * Indicate if the tc completion handler was successful. SCI_SUCCESS currently
1551 * this method always returns success.
1553 static enum sci_status scic_sds_smp_request_await_tc_completion_tc_completion_handler(
1554 struct scic_sds_request *sci_req,
1555 u32 completion_code)
1557 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1558 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1559 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
1562 sci_base_state_machine_change_state(&sci_req->state_machine,
1563 SCI_BASE_REQUEST_STATE_COMPLETED);
1568 * All other completion status cause the IO to be complete. If a NAK
1569 * was received, then it is up to the user to retry the request. */
1570 scic_sds_request_set_status(
1572 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1573 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1576 sci_base_state_machine_change_state(
1577 &sci_req->state_machine,
1578 SCI_BASE_REQUEST_STATE_COMPLETED);
1585 void scic_stp_io_request_set_ncq_tag(struct scic_sds_request *req,
1589 * @note This could be made to return an error to the user if the user
1590 * attempts to set the NCQ tag in the wrong state.
1592 req->task_context_buffer->type.stp.ncq_tag = ncq_tag;
1599 * Get the next SGL element from the request. - Check on which SGL element pair
1600 * we are working - if working on SLG pair element A - advance to element B -
1601 * else - check to see if there are more SGL element pairs for this IO request
1602 * - if there are more SGL element pairs - advance to the next pair and return
1603 * element A struct scu_sgl_element*
1605 static struct scu_sgl_element *scic_sds_stp_request_pio_get_next_sgl(struct scic_sds_stp_request *stp_req)
1607 struct scu_sgl_element *current_sgl;
1608 struct scic_sds_request *sci_req = to_sci_req(stp_req);
1609 struct scic_sds_request_pio_sgl *pio_sgl = &stp_req->type.pio.request_current;
1611 if (pio_sgl->sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
1612 if (pio_sgl->sgl_pair->B.address_lower == 0 &&
1613 pio_sgl->sgl_pair->B.address_upper == 0) {
1616 pio_sgl->sgl_set = SCU_SGL_ELEMENT_PAIR_B;
1617 current_sgl = &pio_sgl->sgl_pair->B;
1620 if (pio_sgl->sgl_pair->next_pair_lower == 0 &&
1621 pio_sgl->sgl_pair->next_pair_upper == 0) {
1626 phys_addr = pio_sgl->sgl_pair->next_pair_upper;
1628 phys_addr |= pio_sgl->sgl_pair->next_pair_lower;
1630 pio_sgl->sgl_pair = scic_request_get_virt_addr(sci_req, phys_addr);
1631 pio_sgl->sgl_set = SCU_SGL_ELEMENT_PAIR_A;
1632 current_sgl = &pio_sgl->sgl_pair->A;
1644 * This method processes a TC completion. The expected TC completion is for
1645 * the transmission of the H2D register FIS containing the SATA/STP non-data
1646 * request. This method always successfully processes the TC completion.
1647 * SCI_SUCCESS This value is always returned.
1649 static enum sci_status scic_sds_stp_request_non_data_await_h2d_tc_completion_handler(
1650 struct scic_sds_request *sci_req,
1651 u32 completion_code)
1653 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1654 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1655 scic_sds_request_set_status(
1656 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1659 sci_base_state_machine_change_state(
1660 &sci_req->state_machine,
1661 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
1667 * All other completion status cause the IO to be complete. If a NAK
1668 * was received, then it is up to the user to retry the request. */
1669 scic_sds_request_set_status(
1671 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1672 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1675 sci_base_state_machine_change_state(
1676 &sci_req->state_machine, SCI_BASE_REQUEST_STATE_COMPLETED);
1685 * @request: This parameter specifies the request for which a frame has been
1687 * @frame_index: This parameter specifies the index of the frame that has been
1690 * This method processes frames received from the target while waiting for a
1691 * device to host register FIS. If a non-register FIS is received during this
1692 * time, it is treated as a protocol violation from an IO perspective. Indicate
1693 * if the received frame was processed successfully.
1695 static enum sci_status scic_sds_stp_request_non_data_await_d2h_frame_handler(
1696 struct scic_sds_request *sci_req,
1699 enum sci_status status;
1700 struct dev_to_host_fis *frame_header;
1702 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
1703 struct scic_sds_controller *scic = sci_req->owning_controller;
1705 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1707 (void **)&frame_header);
1709 if (status != SCI_SUCCESS) {
1710 dev_err(scic_to_dev(sci_req->owning_controller),
1711 "%s: SCIC IO Request 0x%p could not get frame header "
1712 "for frame index %d, status %x\n",
1713 __func__, stp_req, frame_index, status);
1718 switch (frame_header->fis_type) {
1720 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1722 (void **)&frame_buffer);
1724 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
1728 /* The command has completed with error */
1729 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_CHECK_RESPONSE,
1730 SCI_FAILURE_IO_RESPONSE_VALID);
1734 dev_warn(scic_to_dev(scic),
1735 "%s: IO Request:0x%p Frame Id:%d protocol "
1736 "violation occurred\n", __func__, stp_req,
1739 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_UNEXP_FIS,
1740 SCI_FAILURE_PROTOCOL_VIOLATION);
1744 sci_base_state_machine_change_state(&sci_req->state_machine,
1745 SCI_BASE_REQUEST_STATE_COMPLETED);
1747 /* Frame has been decoded return it to the controller */
1748 scic_sds_controller_release_frame(scic, frame_index);
1753 #define SCU_MAX_FRAME_BUFFER_SIZE 0x400 /* 1K is the maximum SCU frame data payload */
1755 /* transmit DATA_FIS from (current sgl + offset) for input
1756 * parameter length. current sgl and offset is alreay stored in the IO request
1758 static enum sci_status scic_sds_stp_request_pio_data_out_trasmit_data_frame(
1759 struct scic_sds_request *sci_req,
1762 struct scic_sds_controller *scic = sci_req->owning_controller;
1763 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
1764 struct scu_task_context *task_context;
1765 struct scu_sgl_element *current_sgl;
1767 /* Recycle the TC and reconstruct it for sending out DATA FIS containing
1768 * for the data from current_sgl+offset for the input length
1770 task_context = scic_sds_controller_get_task_context_buffer(scic,
1773 if (stp_req->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A)
1774 current_sgl = &stp_req->type.pio.request_current.sgl_pair->A;
1776 current_sgl = &stp_req->type.pio.request_current.sgl_pair->B;
1779 task_context->command_iu_upper = current_sgl->address_upper;
1780 task_context->command_iu_lower = current_sgl->address_lower;
1781 task_context->transfer_length_bytes = length;
1782 task_context->type.stp.fis_type = FIS_DATA;
1784 /* send the new TC out. */
1785 return scic_controller_continue_io(sci_req);
1788 static enum sci_status scic_sds_stp_request_pio_data_out_transmit_data(struct scic_sds_request *sci_req)
1791 struct scu_sgl_element *current_sgl;
1793 u32 remaining_bytes_in_current_sgl = 0;
1794 enum sci_status status = SCI_SUCCESS;
1795 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
1797 sgl_offset = stp_req->type.pio.request_current.sgl_offset;
1799 if (stp_req->type.pio.request_current.sgl_set == SCU_SGL_ELEMENT_PAIR_A) {
1800 current_sgl = &(stp_req->type.pio.request_current.sgl_pair->A);
1801 remaining_bytes_in_current_sgl = stp_req->type.pio.request_current.sgl_pair->A.length - sgl_offset;
1803 current_sgl = &(stp_req->type.pio.request_current.sgl_pair->B);
1804 remaining_bytes_in_current_sgl = stp_req->type.pio.request_current.sgl_pair->B.length - sgl_offset;
1808 if (stp_req->type.pio.pio_transfer_bytes > 0) {
1809 if (stp_req->type.pio.pio_transfer_bytes >= remaining_bytes_in_current_sgl) {
1810 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = remaining_bytes_in_current_sgl */
1811 status = scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req, remaining_bytes_in_current_sgl);
1812 if (status == SCI_SUCCESS) {
1813 stp_req->type.pio.pio_transfer_bytes -= remaining_bytes_in_current_sgl;
1815 /* update the current sgl, sgl_offset and save for future */
1816 current_sgl = scic_sds_stp_request_pio_get_next_sgl(stp_req);
1819 } else if (stp_req->type.pio.pio_transfer_bytes < remaining_bytes_in_current_sgl) {
1820 /* recycle the TC and send the H2D Data FIS from (current sgl + sgl_offset) and length = type.pio.pio_transfer_bytes */
1821 scic_sds_stp_request_pio_data_out_trasmit_data_frame(sci_req, stp_req->type.pio.pio_transfer_bytes);
1823 if (status == SCI_SUCCESS) {
1824 /* Sgl offset will be adjusted and saved for future */
1825 sgl_offset += stp_req->type.pio.pio_transfer_bytes;
1826 current_sgl->address_lower += stp_req->type.pio.pio_transfer_bytes;
1827 stp_req->type.pio.pio_transfer_bytes = 0;
1832 if (status == SCI_SUCCESS) {
1833 stp_req->type.pio.request_current.sgl_offset = sgl_offset;
1841 * @stp_request: The request that is used for the SGL processing.
1842 * @data_buffer: The buffer of data to be copied.
1843 * @length: The length of the data transfer.
1845 * Copy the data from the buffer for the length specified to the IO reqeust SGL
1846 * specified data region. enum sci_status
1848 static enum sci_status
1849 scic_sds_stp_request_pio_data_in_copy_data_buffer(struct scic_sds_stp_request *stp_req,
1850 u8 *data_buf, u32 len)
1852 struct scic_sds_request *sci_req;
1853 struct isci_request *ireq;
1856 struct sas_task *task;
1857 struct scatterlist *sg;
1859 int total_len = len;
1861 sci_req = to_sci_req(stp_req);
1862 ireq = sci_req_to_ireq(sci_req);
1863 task = isci_request_access_task(ireq);
1864 src_addr = data_buf;
1866 if (task->num_scatter > 0) {
1869 while (total_len > 0) {
1870 struct page *page = sg_page(sg);
1872 copy_len = min_t(int, total_len, sg_dma_len(sg));
1873 kaddr = kmap_atomic(page, KM_IRQ0);
1874 memcpy(kaddr + sg->offset, src_addr, copy_len);
1875 kunmap_atomic(kaddr, KM_IRQ0);
1876 total_len -= copy_len;
1877 src_addr += copy_len;
1881 BUG_ON(task->total_xfer_len < total_len);
1882 memcpy(task->scatter, src_addr, total_len);
1890 * @sci_req: The PIO DATA IN request that is to receive the data.
1891 * @data_buffer: The buffer to copy from.
1893 * Copy the data buffer to the io request data region. enum sci_status
1895 static enum sci_status scic_sds_stp_request_pio_data_in_copy_data(
1896 struct scic_sds_stp_request *sci_req,
1899 enum sci_status status;
1902 * If there is less than 1K remaining in the transfer request
1903 * copy just the data for the transfer */
1904 if (sci_req->type.pio.pio_transfer_bytes < SCU_MAX_FRAME_BUFFER_SIZE) {
1905 status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
1906 sci_req, data_buffer, sci_req->type.pio.pio_transfer_bytes);
1908 if (status == SCI_SUCCESS)
1909 sci_req->type.pio.pio_transfer_bytes = 0;
1911 /* We are transfering the whole frame so copy */
1912 status = scic_sds_stp_request_pio_data_in_copy_data_buffer(
1913 sci_req, data_buffer, SCU_MAX_FRAME_BUFFER_SIZE);
1915 if (status == SCI_SUCCESS)
1916 sci_req->type.pio.pio_transfer_bytes -= SCU_MAX_FRAME_BUFFER_SIZE;
1929 static enum sci_status scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler(
1930 struct scic_sds_request *sci_req,
1931 u32 completion_code)
1933 enum sci_status status = SCI_SUCCESS;
1935 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
1936 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
1937 scic_sds_request_set_status(
1938 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
1941 sci_base_state_machine_change_state(
1942 &sci_req->state_machine,
1943 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
1949 * All other completion status cause the IO to be complete. If a NAK
1950 * was received, then it is up to the user to retry the request. */
1951 scic_sds_request_set_status(
1953 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
1954 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
1957 sci_base_state_machine_change_state(
1958 &sci_req->state_machine,
1959 SCI_BASE_REQUEST_STATE_COMPLETED
1967 static enum sci_status scic_sds_stp_request_pio_await_frame_frame_handler(struct scic_sds_request *sci_req,
1970 struct scic_sds_controller *scic = sci_req->owning_controller;
1971 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
1972 struct isci_request *ireq = sci_req_to_ireq(sci_req);
1973 struct sas_task *task = isci_request_access_task(ireq);
1974 struct dev_to_host_fis *frame_header;
1975 enum sci_status status;
1978 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
1980 (void **)&frame_header);
1982 if (status != SCI_SUCCESS) {
1983 dev_err(scic_to_dev(scic),
1984 "%s: SCIC IO Request 0x%p could not get frame header "
1985 "for frame index %d, status %x\n",
1986 __func__, stp_req, frame_index, status);
1990 switch (frame_header->fis_type) {
1992 /* Get from the frame buffer the PIO Setup Data */
1993 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
1995 (void **)&frame_buffer);
1997 /* Get the data from the PIO Setup The SCU Hardware returns
1998 * first word in the frame_header and the rest of the data is in
1999 * the frame buffer so we need to back up one dword
2002 /* transfer_count: first 16bits in the 4th dword */
2003 stp_req->type.pio.pio_transfer_bytes = frame_buffer[3] & 0xffff;
2005 /* ending_status: 4th byte in the 3rd dword */
2006 stp_req->type.pio.ending_status = (frame_buffer[2] >> 24) & 0xff;
2008 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
2012 sci_req->stp.rsp.status = stp_req->type.pio.ending_status;
2014 /* The next state is dependent on whether the
2015 * request was PIO Data-in or Data out
2017 if (task->data_dir == DMA_FROM_DEVICE) {
2018 sci_base_state_machine_change_state(&sci_req->state_machine,
2019 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE);
2020 } else if (task->data_dir == DMA_TO_DEVICE) {
2022 status = scic_sds_stp_request_pio_data_out_transmit_data(sci_req);
2023 if (status != SCI_SUCCESS)
2025 sci_base_state_machine_change_state(&sci_req->state_machine,
2026 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE);
2029 case FIS_SETDEVBITS:
2030 sci_base_state_machine_change_state(&sci_req->state_machine,
2031 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE);
2034 if (frame_header->status & ATA_BUSY) {
2035 /* Now why is the drive sending a D2H Register FIS when
2036 * it is still busy? Do nothing since we are still in
2039 dev_dbg(scic_to_dev(scic),
2040 "%s: SCIC PIO Request 0x%p received "
2041 "D2H Register FIS with BSY status "
2042 "0x%x\n", __func__, stp_req,
2043 frame_header->status);
2047 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
2049 (void **)&frame_buffer);
2051 scic_sds_controller_copy_sata_response(&sci_req->stp.req,
2055 scic_sds_request_set_status(sci_req,
2056 SCU_TASK_DONE_CHECK_RESPONSE,
2057 SCI_FAILURE_IO_RESPONSE_VALID);
2059 sci_base_state_machine_change_state(&sci_req->state_machine,
2060 SCI_BASE_REQUEST_STATE_COMPLETED);
2063 /* FIXME: what do we do here? */
2067 /* Frame is decoded return it to the controller */
2068 scic_sds_controller_release_frame(scic, frame_index);
2073 static enum sci_status scic_sds_stp_request_pio_data_in_await_data_frame_handler(struct scic_sds_request *sci_req,
2076 enum sci_status status;
2077 struct dev_to_host_fis *frame_header;
2078 struct sata_fis_data *frame_buffer;
2079 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
2080 struct scic_sds_controller *scic = sci_req->owning_controller;
2082 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
2084 (void **)&frame_header);
2086 if (status != SCI_SUCCESS) {
2087 dev_err(scic_to_dev(scic),
2088 "%s: SCIC IO Request 0x%p could not get frame header "
2089 "for frame index %d, status %x\n",
2090 __func__, stp_req, frame_index, status);
2094 if (frame_header->fis_type == FIS_DATA) {
2095 if (stp_req->type.pio.request_current.sgl_pair == NULL) {
2096 sci_req->saved_rx_frame_index = frame_index;
2097 stp_req->type.pio.pio_transfer_bytes = 0;
2099 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
2101 (void **)&frame_buffer);
2103 status = scic_sds_stp_request_pio_data_in_copy_data(stp_req,
2104 (u8 *)frame_buffer);
2106 /* Frame is decoded return it to the controller */
2107 scic_sds_controller_release_frame(scic, frame_index);
2110 /* Check for the end of the transfer, are there more
2111 * bytes remaining for this data transfer
2113 if (status != SCI_SUCCESS ||
2114 stp_req->type.pio.pio_transfer_bytes != 0)
2117 if ((stp_req->type.pio.ending_status & ATA_BUSY) == 0) {
2118 scic_sds_request_set_status(sci_req,
2119 SCU_TASK_DONE_CHECK_RESPONSE,
2120 SCI_FAILURE_IO_RESPONSE_VALID);
2122 sci_base_state_machine_change_state(&sci_req->state_machine,
2123 SCI_BASE_REQUEST_STATE_COMPLETED);
2125 sci_base_state_machine_change_state(&sci_req->state_machine,
2126 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE);
2129 dev_err(scic_to_dev(scic),
2130 "%s: SCIC PIO Request 0x%p received frame %d "
2131 "with fis type 0x%02x when expecting a data "
2132 "fis.\n", __func__, stp_req, frame_index,
2133 frame_header->fis_type);
2135 scic_sds_request_set_status(sci_req,
2137 SCI_FAILURE_IO_REQUIRES_SCSI_ABORT);
2139 sci_base_state_machine_change_state(&sci_req->state_machine,
2140 SCI_BASE_REQUEST_STATE_COMPLETED);
2142 /* Frame is decoded return it to the controller */
2143 scic_sds_controller_release_frame(scic, frame_index);
2157 static enum sci_status scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler(
2159 struct scic_sds_request *sci_req,
2160 u32 completion_code)
2162 enum sci_status status = SCI_SUCCESS;
2163 bool all_frames_transferred = false;
2164 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
2166 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
2167 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
2169 if (stp_req->type.pio.pio_transfer_bytes != 0) {
2170 status = scic_sds_stp_request_pio_data_out_transmit_data(sci_req);
2171 if (status == SCI_SUCCESS) {
2172 if (stp_req->type.pio.pio_transfer_bytes == 0)
2173 all_frames_transferred = true;
2175 } else if (stp_req->type.pio.pio_transfer_bytes == 0) {
2177 * this will happen if the all data is written at the
2178 * first time after the pio setup fis is received
2180 all_frames_transferred = true;
2183 /* all data transferred. */
2184 if (all_frames_transferred) {
2186 * Change the state to SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_FRAME_SUBSTATE
2187 * and wait for PIO_SETUP fis / or D2H REg fis. */
2188 sci_base_state_machine_change_state(
2189 &sci_req->state_machine,
2190 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
2197 * All other completion status cause the IO to be complete. If a NAK
2198 * was received, then it is up to the user to retry the request. */
2199 scic_sds_request_set_status(
2201 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
2202 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
2205 sci_base_state_machine_change_state(
2206 &sci_req->state_machine,
2207 SCI_BASE_REQUEST_STATE_COMPLETED
2217 * @request: This is the request which is receiving the event.
2218 * @event_code: This is the event code that the request on which the request is
2219 * expected to take action.
2221 * This method will handle any link layer events while waiting for the data
2222 * frame. enum sci_status SCI_SUCCESS SCI_FAILURE
2224 static enum sci_status scic_sds_stp_request_pio_data_in_await_data_event_handler(
2225 struct scic_sds_request *request,
2228 enum sci_status status;
2230 switch (scu_get_event_specifier(event_code)) {
2231 case SCU_TASK_DONE_CRC_ERR << SCU_EVENT_SPECIFIC_CODE_SHIFT:
2233 * We are waiting for data and the SCU has R_ERR the data frame.
2234 * Go back to waiting for the D2H Register FIS */
2235 sci_base_state_machine_change_state(
2236 &request->state_machine,
2237 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
2240 status = SCI_SUCCESS;
2244 dev_err(scic_to_dev(request->owning_controller),
2245 "%s: SCIC PIO Request 0x%p received unexpected "
2247 __func__, request, event_code);
2249 /* / @todo Should we fail the PIO request when we get an unexpected event? */
2250 status = SCI_FAILURE;
2257 static void scic_sds_stp_request_udma_complete_request(
2258 struct scic_sds_request *request,
2260 enum sci_status sci_status)
2262 scic_sds_request_set_status(request, scu_status, sci_status);
2263 sci_base_state_machine_change_state(&request->state_machine,
2264 SCI_BASE_REQUEST_STATE_COMPLETED);
2267 static enum sci_status scic_sds_stp_request_udma_general_frame_handler(struct scic_sds_request *sci_req,
2270 struct scic_sds_controller *scic = sci_req->owning_controller;
2271 struct dev_to_host_fis *frame_header;
2272 enum sci_status status;
2275 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
2277 (void **)&frame_header);
2279 if ((status == SCI_SUCCESS) &&
2280 (frame_header->fis_type == FIS_REGD2H)) {
2281 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
2283 (void **)&frame_buffer);
2285 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
2290 scic_sds_controller_release_frame(scic, frame_index);
2295 static enum sci_status scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler(
2296 struct scic_sds_request *sci_req,
2297 u32 completion_code)
2299 enum sci_status status = SCI_SUCCESS;
2301 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
2302 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
2303 scic_sds_stp_request_udma_complete_request(sci_req,
2307 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_UNEXP_FIS):
2308 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_REG_ERR):
2310 * We must check ther response buffer to see if the D2H Register FIS was
2311 * received before we got the TC completion. */
2312 if (sci_req->stp.rsp.fis_type == FIS_REGD2H) {
2313 scic_sds_remote_device_suspend(sci_req->target_device,
2314 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
2316 scic_sds_stp_request_udma_complete_request(sci_req,
2317 SCU_TASK_DONE_CHECK_RESPONSE,
2318 SCI_FAILURE_IO_RESPONSE_VALID);
2321 * If we have an error completion status for the TC then we can expect a
2322 * D2H register FIS from the device so we must change state to wait for it */
2323 sci_base_state_machine_change_state(&sci_req->state_machine,
2324 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE);
2329 * / @todo Check to see if any of these completion status need to wait for
2330 * / the device to host register fis. */
2331 /* / @todo We can retry the command for SCU_TASK_DONE_CMD_LL_R_ERR - this comes only for B0 */
2332 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_INV_FIS_LEN):
2333 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_MAX_PLD_ERR):
2334 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_LL_R_ERR):
2335 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CMD_LL_R_ERR):
2336 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_CRC_ERR):
2337 scic_sds_remote_device_suspend(sci_req->target_device,
2338 SCU_EVENT_SPECIFIC(SCU_NORMALIZE_COMPLETION_STATUS(completion_code)));
2339 /* Fall through to the default case */
2341 /* All other completion status cause the IO to be complete. */
2342 scic_sds_stp_request_udma_complete_request(sci_req,
2343 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
2344 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR);
2351 static enum sci_status scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler(
2352 struct scic_sds_request *sci_req,
2355 enum sci_status status;
2357 /* Use the general frame handler to copy the resposne data */
2358 status = scic_sds_stp_request_udma_general_frame_handler(sci_req, frame_index);
2360 if (status != SCI_SUCCESS)
2363 scic_sds_stp_request_udma_complete_request(sci_req,
2364 SCU_TASK_DONE_CHECK_RESPONSE,
2365 SCI_FAILURE_IO_RESPONSE_VALID);
2370 enum sci_status scic_sds_stp_udma_request_construct(struct scic_sds_request *sci_req,
2372 enum dma_data_direction dir)
2382 * This method processes a TC completion. The expected TC completion is for
2383 * the transmission of the H2D register FIS containing the SATA/STP non-data
2384 * request. This method always successfully processes the TC completion.
2385 * SCI_SUCCESS This value is always returned.
2387 static enum sci_status scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler(
2388 struct scic_sds_request *sci_req,
2389 u32 completion_code)
2391 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
2392 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
2393 scic_sds_request_set_status(
2394 sci_req, SCU_TASK_DONE_GOOD, SCI_SUCCESS
2397 sci_base_state_machine_change_state(
2398 &sci_req->state_machine,
2399 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
2405 * All other completion status cause the IO to be complete. If a NAK
2406 * was received, then it is up to the user to retry the request. */
2407 scic_sds_request_set_status(
2409 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
2410 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
2413 sci_base_state_machine_change_state(
2414 &sci_req->state_machine, SCI_BASE_REQUEST_STATE_COMPLETED);
2426 * This method processes a TC completion. The expected TC completion is for
2427 * the transmission of the H2D register FIS containing the SATA/STP non-data
2428 * request. This method always successfully processes the TC completion.
2429 * SCI_SUCCESS This value is always returned.
2431 static enum sci_status scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler(
2432 struct scic_sds_request *sci_req,
2433 u32 completion_code)
2435 switch (SCU_GET_COMPLETION_TL_STATUS(completion_code)) {
2436 case SCU_MAKE_COMPLETION_STATUS(SCU_TASK_DONE_GOOD):
2437 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_GOOD,
2440 sci_base_state_machine_change_state(&sci_req->state_machine,
2441 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE);
2446 * All other completion status cause the IO to be complete. If a NAK
2447 * was received, then it is up to the user to retry the request. */
2448 scic_sds_request_set_status(
2450 SCU_NORMALIZE_COMPLETION_STATUS(completion_code),
2451 SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR
2454 sci_base_state_machine_change_state(&sci_req->state_machine,
2455 SCI_BASE_REQUEST_STATE_COMPLETED);
2464 * @request: This parameter specifies the request for which a frame has been
2466 * @frame_index: This parameter specifies the index of the frame that has been
2469 * This method processes frames received from the target while waiting for a
2470 * device to host register FIS. If a non-register FIS is received during this
2471 * time, it is treated as a protocol violation from an IO perspective. Indicate
2472 * if the received frame was processed successfully.
2474 static enum sci_status scic_sds_stp_request_soft_reset_await_d2h_frame_handler(
2475 struct scic_sds_request *sci_req,
2478 enum sci_status status;
2479 struct dev_to_host_fis *frame_header;
2481 struct scic_sds_stp_request *stp_req = &sci_req->stp.req;
2482 struct scic_sds_controller *scic = sci_req->owning_controller;
2484 status = scic_sds_unsolicited_frame_control_get_header(&scic->uf_control,
2486 (void **)&frame_header);
2487 if (status != SCI_SUCCESS) {
2488 dev_err(scic_to_dev(scic),
2489 "%s: SCIC IO Request 0x%p could not get frame header "
2490 "for frame index %d, status %x\n",
2491 __func__, stp_req, frame_index, status);
2495 switch (frame_header->fis_type) {
2497 scic_sds_unsolicited_frame_control_get_buffer(&scic->uf_control,
2499 (void **)&frame_buffer);
2501 scic_sds_controller_copy_sata_response(&sci_req->stp.rsp,
2505 /* The command has completed with error */
2506 scic_sds_request_set_status(sci_req,
2507 SCU_TASK_DONE_CHECK_RESPONSE,
2508 SCI_FAILURE_IO_RESPONSE_VALID);
2512 dev_warn(scic_to_dev(scic),
2513 "%s: IO Request:0x%p Frame Id:%d protocol "
2514 "violation occurred\n", __func__, stp_req,
2517 scic_sds_request_set_status(sci_req, SCU_TASK_DONE_UNEXP_FIS,
2518 SCI_FAILURE_PROTOCOL_VIOLATION);
2522 sci_base_state_machine_change_state(&sci_req->state_machine,
2523 SCI_BASE_REQUEST_STATE_COMPLETED);
2525 /* Frame has been decoded return it to the controller */
2526 scic_sds_controller_release_frame(scic, frame_index);
2531 static const struct scic_sds_io_request_state_handler scic_sds_request_state_handler_table[] = {
2532 [SCI_BASE_REQUEST_STATE_INITIAL] = { },
2533 [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
2534 .start_handler = scic_sds_request_constructed_state_start_handler,
2536 [SCI_BASE_REQUEST_STATE_STARTED] = {
2537 .tc_completion_handler = scic_sds_request_started_state_tc_completion_handler,
2538 .frame_handler = scic_sds_request_started_state_frame_handler,
2540 [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION] = {
2541 .tc_completion_handler = scic_sds_ssp_task_request_await_tc_completion_tc_completion_handler,
2543 [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE] = {
2544 .frame_handler = scic_sds_ssp_task_request_await_tc_response_frame_handler,
2546 [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = {
2547 .tc_completion_handler = scic_sds_smp_request_await_response_tc_completion_handler,
2548 .frame_handler = scic_sds_smp_request_await_response_frame_handler,
2550 [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = {
2551 .tc_completion_handler = scic_sds_smp_request_await_tc_completion_tc_completion_handler,
2553 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE] = {
2554 .tc_completion_handler = scic_sds_stp_request_udma_await_tc_completion_tc_completion_handler,
2555 .frame_handler = scic_sds_stp_request_udma_general_frame_handler,
2557 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE] = {
2558 .frame_handler = scic_sds_stp_request_udma_await_d2h_reg_fis_frame_handler,
2560 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE] = {
2561 .tc_completion_handler = scic_sds_stp_request_non_data_await_h2d_tc_completion_handler,
2563 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE] = {
2564 .frame_handler = scic_sds_stp_request_non_data_await_d2h_frame_handler,
2566 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE] = {
2567 .tc_completion_handler = scic_sds_stp_request_pio_await_h2d_completion_tc_completion_handler,
2569 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE] = {
2570 .frame_handler = scic_sds_stp_request_pio_await_frame_frame_handler
2572 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE] = {
2573 .event_handler = scic_sds_stp_request_pio_data_in_await_data_event_handler,
2574 .frame_handler = scic_sds_stp_request_pio_data_in_await_data_frame_handler
2576 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE] = {
2577 .tc_completion_handler = scic_sds_stp_request_pio_data_out_await_data_transmit_completion_tc_completion_handler,
2579 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE] = {
2580 .tc_completion_handler = scic_sds_stp_request_soft_reset_await_h2d_asserted_tc_completion_handler,
2582 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE] = {
2583 .tc_completion_handler = scic_sds_stp_request_soft_reset_await_h2d_diagnostic_tc_completion_handler,
2585 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE] = {
2586 .frame_handler = scic_sds_stp_request_soft_reset_await_d2h_frame_handler,
2588 [SCI_BASE_REQUEST_STATE_COMPLETED] = {
2589 .complete_handler = scic_sds_request_completed_state_complete_handler,
2591 [SCI_BASE_REQUEST_STATE_ABORTING] = {
2592 .tc_completion_handler = scic_sds_request_aborting_state_tc_completion_handler,
2593 .frame_handler = scic_sds_request_aborting_state_frame_handler,
2595 [SCI_BASE_REQUEST_STATE_FINAL] = { },
2600 * isci_request_process_response_iu() - This function sets the status and
2601 * response iu, in the task struct, from the request object for the upper
2603 * @sas_task: This parameter is the task struct from the upper layer driver.
2604 * @resp_iu: This parameter points to the response iu of the completed request.
2605 * @dev: This parameter specifies the linux device struct.
2609 static void isci_request_process_response_iu(
2610 struct sas_task *task,
2611 struct ssp_response_iu *resp_iu,
2616 "resp_iu->status = 0x%x,\nresp_iu->datapres = %d "
2617 "resp_iu->response_data_len = %x, "
2618 "resp_iu->sense_data_len = %x\nrepsonse data: ",
2623 resp_iu->response_data_len,
2624 resp_iu->sense_data_len);
2626 task->task_status.stat = resp_iu->status;
2628 /* libsas updates the task status fields based on the response iu. */
2629 sas_ssp_task_response(dev, task, resp_iu);
2633 * isci_request_set_open_reject_status() - This function prepares the I/O
2634 * completion for OPEN_REJECT conditions.
2635 * @request: This parameter is the completed isci_request object.
2636 * @response_ptr: This parameter specifies the service response for the I/O.
2637 * @status_ptr: This parameter specifies the exec status for the I/O.
2638 * @complete_to_host_ptr: This parameter specifies the action to be taken by
2639 * the LLDD with respect to completing this request or forcing an abort
2640 * condition on the I/O.
2641 * @open_rej_reason: This parameter specifies the encoded reason for the
2642 * abandon-class reject.
2646 static void isci_request_set_open_reject_status(
2647 struct isci_request *request,
2648 struct sas_task *task,
2649 enum service_response *response_ptr,
2650 enum exec_status *status_ptr,
2651 enum isci_completion_selection *complete_to_host_ptr,
2652 enum sas_open_rej_reason open_rej_reason)
2654 /* Task in the target is done. */
2655 request->complete_in_target = true;
2656 *response_ptr = SAS_TASK_UNDELIVERED;
2657 *status_ptr = SAS_OPEN_REJECT;
2658 *complete_to_host_ptr = isci_perform_normal_io_completion;
2659 task->task_status.open_rej_reason = open_rej_reason;
2663 * isci_request_handle_controller_specific_errors() - This function decodes
2664 * controller-specific I/O completion error conditions.
2665 * @request: This parameter is the completed isci_request object.
2666 * @response_ptr: This parameter specifies the service response for the I/O.
2667 * @status_ptr: This parameter specifies the exec status for the I/O.
2668 * @complete_to_host_ptr: This parameter specifies the action to be taken by
2669 * the LLDD with respect to completing this request or forcing an abort
2670 * condition on the I/O.
2674 static void isci_request_handle_controller_specific_errors(
2675 struct isci_remote_device *isci_device,
2676 struct isci_request *request,
2677 struct sas_task *task,
2678 enum service_response *response_ptr,
2679 enum exec_status *status_ptr,
2680 enum isci_completion_selection *complete_to_host_ptr)
2682 unsigned int cstatus;
2684 cstatus = request->sci.scu_status;
2686 dev_dbg(&request->isci_host->pdev->dev,
2687 "%s: %p SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR "
2688 "- controller status = 0x%x\n",
2689 __func__, request, cstatus);
2691 /* Decode the controller-specific errors; most
2692 * important is to recognize those conditions in which
2693 * the target may still have a task outstanding that
2696 * Note that there are SCU completion codes being
2697 * named in the decode below for which SCIC has already
2698 * done work to handle them in a way other than as
2699 * a controller-specific completion code; these are left
2700 * in the decode below for completeness sake.
2703 case SCU_TASK_DONE_DMASETUP_DIRERR:
2704 /* Also SCU_TASK_DONE_SMP_FRM_TYPE_ERR: */
2705 case SCU_TASK_DONE_XFERCNT_ERR:
2706 /* Also SCU_TASK_DONE_SMP_UFI_ERR: */
2707 if (task->task_proto == SAS_PROTOCOL_SMP) {
2708 /* SCU_TASK_DONE_SMP_UFI_ERR == Task Done. */
2709 *response_ptr = SAS_TASK_COMPLETE;
2711 /* See if the device has been/is being stopped. Note
2712 * that we ignore the quiesce state, since we are
2713 * concerned about the actual device state.
2715 if ((isci_device->status == isci_stopping) ||
2716 (isci_device->status == isci_stopped))
2717 *status_ptr = SAS_DEVICE_UNKNOWN;
2719 *status_ptr = SAS_ABORTED_TASK;
2721 request->complete_in_target = true;
2723 *complete_to_host_ptr =
2724 isci_perform_normal_io_completion;
2726 /* Task in the target is not done. */
2727 *response_ptr = SAS_TASK_UNDELIVERED;
2729 if ((isci_device->status == isci_stopping) ||
2730 (isci_device->status == isci_stopped))
2731 *status_ptr = SAS_DEVICE_UNKNOWN;
2733 *status_ptr = SAM_STAT_TASK_ABORTED;
2735 request->complete_in_target = false;
2737 *complete_to_host_ptr =
2738 isci_perform_error_io_completion;
2743 case SCU_TASK_DONE_CRC_ERR:
2744 case SCU_TASK_DONE_NAK_CMD_ERR:
2745 case SCU_TASK_DONE_EXCESS_DATA:
2746 case SCU_TASK_DONE_UNEXP_FIS:
2747 /* Also SCU_TASK_DONE_UNEXP_RESP: */
2748 case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */
2749 case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */
2750 case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */
2751 /* These are conditions in which the target
2752 * has completed the task, so that no cleanup
2755 *response_ptr = SAS_TASK_COMPLETE;
2757 /* See if the device has been/is being stopped. Note
2758 * that we ignore the quiesce state, since we are
2759 * concerned about the actual device state.
2761 if ((isci_device->status == isci_stopping) ||
2762 (isci_device->status == isci_stopped))
2763 *status_ptr = SAS_DEVICE_UNKNOWN;
2765 *status_ptr = SAS_ABORTED_TASK;
2767 request->complete_in_target = true;
2769 *complete_to_host_ptr = isci_perform_normal_io_completion;
2773 /* Note that the only open reject completion codes seen here will be
2774 * abandon-class codes; all others are automatically retried in the SCU.
2776 case SCU_TASK_OPEN_REJECT_WRONG_DESTINATION:
2778 isci_request_set_open_reject_status(
2779 request, task, response_ptr, status_ptr,
2780 complete_to_host_ptr, SAS_OREJ_WRONG_DEST);
2783 case SCU_TASK_OPEN_REJECT_ZONE_VIOLATION:
2785 /* Note - the return of AB0 will change when
2786 * libsas implements detection of zone violations.
2788 isci_request_set_open_reject_status(
2789 request, task, response_ptr, status_ptr,
2790 complete_to_host_ptr, SAS_OREJ_RESV_AB0);
2793 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_1:
2795 isci_request_set_open_reject_status(
2796 request, task, response_ptr, status_ptr,
2797 complete_to_host_ptr, SAS_OREJ_RESV_AB1);
2800 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_2:
2802 isci_request_set_open_reject_status(
2803 request, task, response_ptr, status_ptr,
2804 complete_to_host_ptr, SAS_OREJ_RESV_AB2);
2807 case SCU_TASK_OPEN_REJECT_RESERVED_ABANDON_3:
2809 isci_request_set_open_reject_status(
2810 request, task, response_ptr, status_ptr,
2811 complete_to_host_ptr, SAS_OREJ_RESV_AB3);
2814 case SCU_TASK_OPEN_REJECT_BAD_DESTINATION:
2816 isci_request_set_open_reject_status(
2817 request, task, response_ptr, status_ptr,
2818 complete_to_host_ptr, SAS_OREJ_BAD_DEST);
2821 case SCU_TASK_OPEN_REJECT_STP_RESOURCES_BUSY:
2823 isci_request_set_open_reject_status(
2824 request, task, response_ptr, status_ptr,
2825 complete_to_host_ptr, SAS_OREJ_STP_NORES);
2828 case SCU_TASK_OPEN_REJECT_PROTOCOL_NOT_SUPPORTED:
2830 isci_request_set_open_reject_status(
2831 request, task, response_ptr, status_ptr,
2832 complete_to_host_ptr, SAS_OREJ_EPROTO);
2835 case SCU_TASK_OPEN_REJECT_CONNECTION_RATE_NOT_SUPPORTED:
2837 isci_request_set_open_reject_status(
2838 request, task, response_ptr, status_ptr,
2839 complete_to_host_ptr, SAS_OREJ_CONN_RATE);
2842 case SCU_TASK_DONE_LL_R_ERR:
2843 /* Also SCU_TASK_DONE_ACK_NAK_TO: */
2844 case SCU_TASK_DONE_LL_PERR:
2845 case SCU_TASK_DONE_LL_SY_TERM:
2846 /* Also SCU_TASK_DONE_NAK_ERR:*/
2847 case SCU_TASK_DONE_LL_LF_TERM:
2848 /* Also SCU_TASK_DONE_DATA_LEN_ERR: */
2849 case SCU_TASK_DONE_LL_ABORT_ERR:
2850 case SCU_TASK_DONE_SEQ_INV_TYPE:
2851 /* Also SCU_TASK_DONE_UNEXP_XR: */
2852 case SCU_TASK_DONE_XR_IU_LEN_ERR:
2853 case SCU_TASK_DONE_INV_FIS_LEN:
2854 /* Also SCU_TASK_DONE_XR_WD_LEN: */
2855 case SCU_TASK_DONE_SDMA_ERR:
2856 case SCU_TASK_DONE_OFFSET_ERR:
2857 case SCU_TASK_DONE_MAX_PLD_ERR:
2858 case SCU_TASK_DONE_LF_ERR:
2859 case SCU_TASK_DONE_SMP_RESP_TO_ERR: /* Escalate to dev reset? */
2860 case SCU_TASK_DONE_SMP_LL_RX_ERR:
2861 case SCU_TASK_DONE_UNEXP_DATA:
2862 case SCU_TASK_DONE_UNEXP_SDBFIS:
2863 case SCU_TASK_DONE_REG_ERR:
2864 case SCU_TASK_DONE_SDB_ERR:
2865 case SCU_TASK_DONE_TASK_ABORT:
2867 /* Task in the target is not done. */
2868 *response_ptr = SAS_TASK_UNDELIVERED;
2869 *status_ptr = SAM_STAT_TASK_ABORTED;
2870 request->complete_in_target = false;
2872 *complete_to_host_ptr = isci_perform_error_io_completion;
2878 * isci_task_save_for_upper_layer_completion() - This function saves the
2879 * request for later completion to the upper layer driver.
2880 * @host: This parameter is a pointer to the host on which the the request
2881 * should be queued (either as an error or success).
2882 * @request: This parameter is the completed request.
2883 * @response: This parameter is the response code for the completed task.
2884 * @status: This parameter is the status code for the completed task.
2888 static void isci_task_save_for_upper_layer_completion(
2889 struct isci_host *host,
2890 struct isci_request *request,
2891 enum service_response response,
2892 enum exec_status status,
2893 enum isci_completion_selection task_notification_selection)
2895 struct sas_task *task = isci_request_access_task(request);
2897 task_notification_selection
2898 = isci_task_set_completion_status(task, response, status,
2899 task_notification_selection);
2901 /* Tasks aborted specifically by a call to the lldd_abort_task
2902 * function should not be completed to the host in the regular path.
2904 switch (task_notification_selection) {
2906 case isci_perform_normal_io_completion:
2908 /* Normal notification (task_done) */
2909 dev_dbg(&host->pdev->dev,
2910 "%s: Normal - task = %p, response=%d (%d), status=%d (%d)\n",
2913 task->task_status.resp, response,
2914 task->task_status.stat, status);
2915 /* Add to the completed list. */
2916 list_add(&request->completed_node,
2917 &host->requests_to_complete);
2919 /* Take the request off the device's pending request list. */
2920 list_del_init(&request->dev_node);
2923 case isci_perform_aborted_io_completion:
2924 /* No notification to libsas because this request is
2925 * already in the abort path.
2927 dev_warn(&host->pdev->dev,
2928 "%s: Aborted - task = %p, response=%d (%d), status=%d (%d)\n",
2931 task->task_status.resp, response,
2932 task->task_status.stat, status);
2934 /* Wake up whatever process was waiting for this
2935 * request to complete.
2937 WARN_ON(request->io_request_completion == NULL);
2939 if (request->io_request_completion != NULL) {
2941 /* Signal whoever is waiting that this
2942 * request is complete.
2944 complete(request->io_request_completion);
2948 case isci_perform_error_io_completion:
2949 /* Use sas_task_abort */
2950 dev_warn(&host->pdev->dev,
2951 "%s: Error - task = %p, response=%d (%d), status=%d (%d)\n",
2954 task->task_status.resp, response,
2955 task->task_status.stat, status);
2956 /* Add to the aborted list. */
2957 list_add(&request->completed_node,
2958 &host->requests_to_errorback);
2962 dev_warn(&host->pdev->dev,
2963 "%s: Unknown - task = %p, response=%d (%d), status=%d (%d)\n",
2966 task->task_status.resp, response,
2967 task->task_status.stat, status);
2969 /* Add to the error to libsas list. */
2970 list_add(&request->completed_node,
2971 &host->requests_to_errorback);
2976 static void isci_request_io_request_complete(struct isci_host *isci_host,
2977 struct isci_request *request,
2978 enum sci_io_status completion_status)
2980 struct sas_task *task = isci_request_access_task(request);
2981 struct ssp_response_iu *resp_iu;
2983 unsigned long task_flags;
2984 struct isci_remote_device *isci_device = request->isci_device;
2985 enum service_response response = SAS_TASK_UNDELIVERED;
2986 enum exec_status status = SAS_ABORTED_TASK;
2987 enum isci_request_status request_status;
2988 enum isci_completion_selection complete_to_host
2989 = isci_perform_normal_io_completion;
2991 dev_dbg(&isci_host->pdev->dev,
2992 "%s: request = %p, task = %p,\n"
2993 "task->data_dir = %d completion_status = 0x%x\n",
3000 spin_lock(&request->state_lock);
3001 request_status = isci_request_get_state(request);
3003 /* Decode the request status. Note that if the request has been
3004 * aborted by a task management function, we don't care
3005 * what the status is.
3007 switch (request_status) {
3010 /* "aborted" indicates that the request was aborted by a task
3011 * management function, since once a task management request is
3012 * perfomed by the device, the request only completes because
3013 * of the subsequent driver terminate.
3015 * Aborted also means an external thread is explicitly managing
3016 * this request, so that we do not complete it up the stack.
3018 * The target is still there (since the TMF was successful).
3020 request->complete_in_target = true;
3021 response = SAS_TASK_COMPLETE;
3023 /* See if the device has been/is being stopped. Note
3024 * that we ignore the quiesce state, since we are
3025 * concerned about the actual device state.
3027 if ((isci_device->status == isci_stopping)
3028 || (isci_device->status == isci_stopped)
3030 status = SAS_DEVICE_UNKNOWN;
3032 status = SAS_ABORTED_TASK;
3034 complete_to_host = isci_perform_aborted_io_completion;
3035 /* This was an aborted request. */
3037 spin_unlock(&request->state_lock);
3041 /* aborting means that the task management function tried and
3042 * failed to abort the request. We need to note the request
3043 * as SAS_TASK_UNDELIVERED, so that the scsi mid layer marks the
3046 * Aborting also means an external thread is explicitly managing
3047 * this request, so that we do not complete it up the stack.
3049 request->complete_in_target = true;
3050 response = SAS_TASK_UNDELIVERED;
3052 if ((isci_device->status == isci_stopping) ||
3053 (isci_device->status == isci_stopped))
3054 /* The device has been /is being stopped. Note that
3055 * we ignore the quiesce state, since we are
3056 * concerned about the actual device state.
3058 status = SAS_DEVICE_UNKNOWN;
3060 status = SAS_PHY_DOWN;
3062 complete_to_host = isci_perform_aborted_io_completion;
3064 /* This was an aborted request. */
3066 spin_unlock(&request->state_lock);
3071 /* This was an terminated request. This happens when
3072 * the I/O is being terminated because of an action on
3073 * the device (reset, tear down, etc.), and the I/O needs
3074 * to be completed up the stack.
3076 request->complete_in_target = true;
3077 response = SAS_TASK_UNDELIVERED;
3079 /* See if the device has been/is being stopped. Note
3080 * that we ignore the quiesce state, since we are
3081 * concerned about the actual device state.
3083 if ((isci_device->status == isci_stopping) ||
3084 (isci_device->status == isci_stopped))
3085 status = SAS_DEVICE_UNKNOWN;
3087 status = SAS_ABORTED_TASK;
3089 complete_to_host = isci_perform_aborted_io_completion;
3091 /* This was a terminated request. */
3093 spin_unlock(&request->state_lock);
3098 /* The request is done from an SCU HW perspective. */
3099 request->status = completed;
3101 spin_unlock(&request->state_lock);
3103 /* This is an active request being completed from the core. */
3104 switch (completion_status) {
3106 case SCI_IO_FAILURE_RESPONSE_VALID:
3107 dev_dbg(&isci_host->pdev->dev,
3108 "%s: SCI_IO_FAILURE_RESPONSE_VALID (%p/%p)\n",
3113 if (sas_protocol_ata(task->task_proto)) {
3114 resp_buf = &request->sci.stp.rsp;
3115 isci_request_process_stp_response(task,
3117 } else if (SAS_PROTOCOL_SSP == task->task_proto) {
3119 /* crack the iu response buffer. */
3120 resp_iu = &request->sci.ssp.rsp;
3121 isci_request_process_response_iu(task, resp_iu,
3122 &isci_host->pdev->dev);
3124 } else if (SAS_PROTOCOL_SMP == task->task_proto) {
3126 dev_err(&isci_host->pdev->dev,
3127 "%s: SCI_IO_FAILURE_RESPONSE_VALID: "
3128 "SAS_PROTOCOL_SMP protocol\n",
3132 dev_err(&isci_host->pdev->dev,
3133 "%s: unknown protocol\n", __func__);
3135 /* use the task status set in the task struct by the
3136 * isci_request_process_response_iu call.
3138 request->complete_in_target = true;
3139 response = task->task_status.resp;
3140 status = task->task_status.stat;
3143 case SCI_IO_SUCCESS:
3144 case SCI_IO_SUCCESS_IO_DONE_EARLY:
3146 response = SAS_TASK_COMPLETE;
3147 status = SAM_STAT_GOOD;
3148 request->complete_in_target = true;
3150 if (task->task_proto == SAS_PROTOCOL_SMP) {
3151 void *rsp = &request->sci.smp.rsp;
3153 dev_dbg(&isci_host->pdev->dev,
3154 "%s: SMP protocol completion\n",
3157 sg_copy_from_buffer(
3158 &task->smp_task.smp_resp, 1,
3159 rsp, sizeof(struct smp_resp));
3160 } else if (completion_status
3161 == SCI_IO_SUCCESS_IO_DONE_EARLY) {
3163 /* This was an SSP / STP / SATA transfer.
3164 * There is a possibility that less data than
3165 * the maximum was transferred.
3167 u32 transferred_length = sci_req_tx_bytes(&request->sci);
3169 task->task_status.residual
3170 = task->total_xfer_len - transferred_length;
3172 /* If there were residual bytes, call this an
3175 if (task->task_status.residual != 0)
3176 status = SAS_DATA_UNDERRUN;
3178 dev_dbg(&isci_host->pdev->dev,
3179 "%s: SCI_IO_SUCCESS_IO_DONE_EARLY %d\n",
3184 dev_dbg(&isci_host->pdev->dev,
3185 "%s: SCI_IO_SUCCESS\n",
3190 case SCI_IO_FAILURE_TERMINATED:
3191 dev_dbg(&isci_host->pdev->dev,
3192 "%s: SCI_IO_FAILURE_TERMINATED (%p/%p)\n",
3197 /* The request was terminated explicitly. No handling
3198 * is needed in the SCSI error handler path.
3200 request->complete_in_target = true;
3201 response = SAS_TASK_UNDELIVERED;
3203 /* See if the device has been/is being stopped. Note
3204 * that we ignore the quiesce state, since we are
3205 * concerned about the actual device state.
3207 if ((isci_device->status == isci_stopping) ||
3208 (isci_device->status == isci_stopped))
3209 status = SAS_DEVICE_UNKNOWN;
3211 status = SAS_ABORTED_TASK;
3213 complete_to_host = isci_perform_normal_io_completion;
3216 case SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR:
3218 isci_request_handle_controller_specific_errors(
3219 isci_device, request, task, &response, &status,
3224 case SCI_IO_FAILURE_REMOTE_DEVICE_RESET_REQUIRED:
3225 /* This is a special case, in that the I/O completion
3226 * is telling us that the device needs a reset.
3227 * In order for the device reset condition to be
3228 * noticed, the I/O has to be handled in the error
3229 * handler. Set the reset flag and cause the
3230 * SCSI error thread to be scheduled.
3232 spin_lock_irqsave(&task->task_state_lock, task_flags);
3233 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
3234 spin_unlock_irqrestore(&task->task_state_lock, task_flags);
3237 response = SAS_TASK_UNDELIVERED;
3238 status = SAM_STAT_TASK_ABORTED;
3240 complete_to_host = isci_perform_error_io_completion;
3241 request->complete_in_target = false;
3245 /* Catch any otherwise unhandled error codes here. */
3246 dev_warn(&isci_host->pdev->dev,
3247 "%s: invalid completion code: 0x%x - "
3248 "isci_request = %p\n",
3249 __func__, completion_status, request);
3251 response = SAS_TASK_UNDELIVERED;
3253 /* See if the device has been/is being stopped. Note
3254 * that we ignore the quiesce state, since we are
3255 * concerned about the actual device state.
3257 if ((isci_device->status == isci_stopping) ||
3258 (isci_device->status == isci_stopped))
3259 status = SAS_DEVICE_UNKNOWN;
3261 status = SAS_ABORTED_TASK;
3263 complete_to_host = isci_perform_error_io_completion;
3264 request->complete_in_target = false;
3270 isci_request_unmap_sgl(request, isci_host->pdev);
3272 /* Put the completed request on the correct list */
3273 isci_task_save_for_upper_layer_completion(isci_host, request, response,
3274 status, complete_to_host
3277 /* complete the io request to the core. */
3278 scic_controller_complete_io(&isci_host->sci,
3281 /* set terminated handle so it cannot be completed or
3282 * terminated again, and to cause any calls into abort
3283 * task to recognize the already completed case.
3285 request->terminated = true;
3287 isci_host_can_dequeue(isci_host, 1);
3291 * scic_sds_request_initial_state_enter() -
3292 * @object: This parameter specifies the base object for which the state
3293 * transition is occurring.
3295 * This method implements the actions taken when entering the
3296 * SCI_BASE_REQUEST_STATE_INITIAL state. This state is entered when the initial
3297 * base request is constructed. Entry into the initial state sets all handlers
3298 * for the io request object to their default handlers. none
3300 static void scic_sds_request_initial_state_enter(void *object)
3302 struct scic_sds_request *sci_req = object;
3306 scic_sds_request_state_handler_table,
3307 SCI_BASE_REQUEST_STATE_INITIAL
3312 * scic_sds_request_constructed_state_enter() -
3313 * @object: The io request object that is to enter the constructed state.
3315 * This method implements the actions taken when entering the
3316 * SCI_BASE_REQUEST_STATE_CONSTRUCTED state. The method sets the state handlers
3317 * for the the constructed state. none
3319 static void scic_sds_request_constructed_state_enter(void *object)
3321 struct scic_sds_request *sci_req = object;
3325 scic_sds_request_state_handler_table,
3326 SCI_BASE_REQUEST_STATE_CONSTRUCTED
3330 static void scic_sds_request_started_state_enter(void *object)
3332 struct scic_sds_request *sci_req = object;
3333 struct sci_base_state_machine *sm = &sci_req->state_machine;
3334 struct isci_request *ireq = sci_req_to_ireq(sci_req);
3335 struct domain_device *dev = sci_dev_to_domain(sci_req->target_device);
3336 struct sas_task *task;
3338 /* XXX as hch said always creating an internal sas_task for tmf
3339 * requests would simplify the driver
3341 task = ireq->ttype == io_task ? isci_request_access_task(ireq) : NULL;
3345 scic_sds_request_state_handler_table,
3346 SCI_BASE_REQUEST_STATE_STARTED
3349 /* all unaccelerated request types (non ssp or ncq) handled with
3352 if (!task && dev->dev_type == SAS_END_DEV) {
3353 sci_base_state_machine_change_state(sm,
3354 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION);
3356 (isci_request_access_tmf(ireq)->tmf_code == isci_tmf_sata_srst_high ||
3357 isci_request_access_tmf(ireq)->tmf_code == isci_tmf_sata_srst_low)) {
3358 sci_base_state_machine_change_state(sm,
3359 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE);
3360 } else if (task && task->task_proto == SAS_PROTOCOL_SMP) {
3361 sci_base_state_machine_change_state(sm,
3362 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE);
3363 } else if (task && sas_protocol_ata(task->task_proto) &&
3364 !task->ata_task.use_ncq) {
3367 if (task->data_dir == DMA_NONE)
3368 state = SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE;
3369 else if (task->ata_task.dma_xfer)
3370 state = SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE;
3372 state = SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE;
3374 sci_base_state_machine_change_state(sm, state);
3379 * scic_sds_request_completed_state_enter() -
3380 * @object: This parameter specifies the base object for which the state
3381 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
3384 * This method implements the actions taken when entering the
3385 * SCI_BASE_REQUEST_STATE_COMPLETED state. This state is entered when the
3386 * SCIC_SDS_IO_REQUEST has completed. The method will decode the request
3387 * completion status and convert it to an enum sci_status to return in the
3388 * completion callback function. none
3390 static void scic_sds_request_completed_state_enter(void *object)
3392 struct scic_sds_request *sci_req = object;
3393 struct scic_sds_controller *scic =
3394 scic_sds_request_get_controller(sci_req);
3395 struct isci_host *ihost = scic_to_ihost(scic);
3396 struct isci_request *ireq = sci_req_to_ireq(sci_req);
3398 SET_STATE_HANDLER(sci_req,
3399 scic_sds_request_state_handler_table,
3400 SCI_BASE_REQUEST_STATE_COMPLETED);
3402 /* Tell the SCI_USER that the IO request is complete */
3403 if (sci_req->is_task_management_request == false)
3404 isci_request_io_request_complete(ihost, ireq,
3405 sci_req->sci_status);
3407 isci_task_request_complete(ihost, ireq, sci_req->sci_status);
3411 * scic_sds_request_aborting_state_enter() -
3412 * @object: This parameter specifies the base object for which the state
3413 * transition is occurring. This object is cast into a SCIC_SDS_IO_REQUEST
3416 * This method implements the actions taken when entering the
3417 * SCI_BASE_REQUEST_STATE_ABORTING state. none
3419 static void scic_sds_request_aborting_state_enter(void *object)
3421 struct scic_sds_request *sci_req = object;
3423 /* Setting the abort bit in the Task Context is required by the silicon. */
3424 sci_req->task_context_buffer->abort = 1;
3428 scic_sds_request_state_handler_table,
3429 SCI_BASE_REQUEST_STATE_ABORTING
3434 * scic_sds_request_final_state_enter() -
3435 * @object: This parameter specifies the base object for which the state
3436 * transition is occurring. This is cast into a SCIC_SDS_IO_REQUEST object.
3438 * This method implements the actions taken when entering the
3439 * SCI_BASE_REQUEST_STATE_FINAL state. The only action required is to put the
3440 * state handlers in place. none
3442 static void scic_sds_request_final_state_enter(void *object)
3444 struct scic_sds_request *sci_req = object;
3448 scic_sds_request_state_handler_table,
3449 SCI_BASE_REQUEST_STATE_FINAL
3453 static void scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter(
3456 struct scic_sds_request *sci_req = object;
3460 scic_sds_request_state_handler_table,
3461 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION
3465 static void scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter(
3468 struct scic_sds_request *sci_req = object;
3472 scic_sds_request_state_handler_table,
3473 SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE
3477 static void scic_sds_smp_request_started_await_response_substate_enter(void *object)
3479 struct scic_sds_request *sci_req = object;
3483 scic_sds_request_state_handler_table,
3484 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE
3488 static void scic_sds_smp_request_started_await_tc_completion_substate_enter(void *object)
3490 struct scic_sds_request *sci_req = object;
3494 scic_sds_request_state_handler_table,
3495 SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION
3499 static void scic_sds_stp_request_started_non_data_await_h2d_completion_enter(
3502 struct scic_sds_request *sci_req = object;
3506 scic_sds_request_state_handler_table,
3507 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE
3510 scic_sds_remote_device_set_working_request(
3511 sci_req->target_device, sci_req
3515 static void scic_sds_stp_request_started_non_data_await_d2h_enter(void *object)
3517 struct scic_sds_request *sci_req = object;
3521 scic_sds_request_state_handler_table,
3522 SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE
3528 static void scic_sds_stp_request_started_pio_await_h2d_completion_enter(
3531 struct scic_sds_request *sci_req = object;
3535 scic_sds_request_state_handler_table,
3536 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE
3539 scic_sds_remote_device_set_working_request(
3540 sci_req->target_device, sci_req);
3543 static void scic_sds_stp_request_started_pio_await_frame_enter(void *object)
3545 struct scic_sds_request *sci_req = object;
3549 scic_sds_request_state_handler_table,
3550 SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE
3554 static void scic_sds_stp_request_started_pio_data_in_await_data_enter(
3557 struct scic_sds_request *sci_req = object;
3561 scic_sds_request_state_handler_table,
3562 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE
3566 static void scic_sds_stp_request_started_pio_data_out_transmit_data_enter(
3569 struct scic_sds_request *sci_req = object;
3573 scic_sds_request_state_handler_table,
3574 SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE
3580 static void scic_sds_stp_request_started_udma_await_tc_completion_enter(
3583 struct scic_sds_request *sci_req = object;
3587 scic_sds_request_state_handler_table,
3588 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE
3595 * This state is entered when there is an TC completion failure. The hardware
3596 * received an unexpected condition while processing the IO request and now
3597 * will UF the D2H register FIS to complete the IO.
3599 static void scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter(
3602 struct scic_sds_request *sci_req = object;
3606 scic_sds_request_state_handler_table,
3607 SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE
3613 static void scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter(
3616 struct scic_sds_request *sci_req = object;
3620 scic_sds_request_state_handler_table,
3621 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE
3624 scic_sds_remote_device_set_working_request(
3625 sci_req->target_device, sci_req
3629 static void scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter(
3632 struct scic_sds_request *sci_req = object;
3633 struct scu_task_context *task_context;
3634 struct host_to_dev_fis *h2d_fis;
3635 enum sci_status status;
3637 /* Clear the SRST bit */
3638 h2d_fis = &sci_req->stp.cmd;
3639 h2d_fis->control = 0;
3641 /* Clear the TC control bit */
3642 task_context = scic_sds_controller_get_task_context_buffer(
3643 sci_req->owning_controller, sci_req->io_tag);
3644 task_context->control_frame = 0;
3646 status = scic_controller_continue_io(sci_req);
3647 if (status == SCI_SUCCESS) {
3650 scic_sds_request_state_handler_table,
3651 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE
3656 static void scic_sds_stp_request_started_soft_reset_await_d2h_response_enter(
3659 struct scic_sds_request *sci_req = object;
3663 scic_sds_request_state_handler_table,
3664 SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE
3668 static const struct sci_base_state scic_sds_request_state_table[] = {
3669 [SCI_BASE_REQUEST_STATE_INITIAL] = {
3670 .enter_state = scic_sds_request_initial_state_enter,
3672 [SCI_BASE_REQUEST_STATE_CONSTRUCTED] = {
3673 .enter_state = scic_sds_request_constructed_state_enter,
3675 [SCI_BASE_REQUEST_STATE_STARTED] = {
3676 .enter_state = scic_sds_request_started_state_enter,
3678 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_H2D_COMPLETION_SUBSTATE] = {
3679 .enter_state = scic_sds_stp_request_started_non_data_await_h2d_completion_enter,
3681 [SCIC_SDS_STP_REQUEST_STARTED_NON_DATA_AWAIT_D2H_SUBSTATE] = {
3682 .enter_state = scic_sds_stp_request_started_non_data_await_d2h_enter,
3684 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_H2D_COMPLETION_SUBSTATE] = {
3685 .enter_state = scic_sds_stp_request_started_pio_await_h2d_completion_enter,
3687 [SCIC_SDS_STP_REQUEST_STARTED_PIO_AWAIT_FRAME_SUBSTATE] = {
3688 .enter_state = scic_sds_stp_request_started_pio_await_frame_enter,
3690 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_IN_AWAIT_DATA_SUBSTATE] = {
3691 .enter_state = scic_sds_stp_request_started_pio_data_in_await_data_enter,
3693 [SCIC_SDS_STP_REQUEST_STARTED_PIO_DATA_OUT_TRANSMIT_DATA_SUBSTATE] = {
3694 .enter_state = scic_sds_stp_request_started_pio_data_out_transmit_data_enter,
3696 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_TC_COMPLETION_SUBSTATE] = {
3697 .enter_state = scic_sds_stp_request_started_udma_await_tc_completion_enter,
3699 [SCIC_SDS_STP_REQUEST_STARTED_UDMA_AWAIT_D2H_REG_FIS_SUBSTATE] = {
3700 .enter_state = scic_sds_stp_request_started_udma_await_d2h_reg_fis_enter,
3702 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_ASSERTED_COMPLETION_SUBSTATE] = {
3703 .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_asserted_completion_enter,
3705 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_H2D_DIAGNOSTIC_COMPLETION_SUBSTATE] = {
3706 .enter_state = scic_sds_stp_request_started_soft_reset_await_h2d_diagnostic_completion_enter,
3708 [SCIC_SDS_STP_REQUEST_STARTED_SOFT_RESET_AWAIT_D2H_RESPONSE_FRAME_SUBSTATE] = {
3709 .enter_state = scic_sds_stp_request_started_soft_reset_await_d2h_response_enter,
3711 [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_COMPLETION] = {
3712 .enter_state = scic_sds_io_request_started_task_mgmt_await_tc_completion_substate_enter,
3714 [SCIC_SDS_IO_REQUEST_STARTED_TASK_MGMT_SUBSTATE_AWAIT_TC_RESPONSE] = {
3715 .enter_state = scic_sds_io_request_started_task_mgmt_await_task_response_substate_enter,
3717 [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_RESPONSE] = {
3718 .enter_state = scic_sds_smp_request_started_await_response_substate_enter,
3720 [SCIC_SDS_SMP_REQUEST_STARTED_SUBSTATE_AWAIT_TC_COMPLETION] = {
3721 .enter_state = scic_sds_smp_request_started_await_tc_completion_substate_enter,
3723 [SCI_BASE_REQUEST_STATE_COMPLETED] = {
3724 .enter_state = scic_sds_request_completed_state_enter,
3726 [SCI_BASE_REQUEST_STATE_ABORTING] = {
3727 .enter_state = scic_sds_request_aborting_state_enter,
3729 [SCI_BASE_REQUEST_STATE_FINAL] = {
3730 .enter_state = scic_sds_request_final_state_enter,
3734 static void scic_sds_general_request_construct(struct scic_sds_controller *scic,
3735 struct scic_sds_remote_device *sci_dev,
3736 u16 io_tag, struct scic_sds_request *sci_req)
3738 sci_base_state_machine_construct(&sci_req->state_machine, sci_req,
3739 scic_sds_request_state_table, SCI_BASE_REQUEST_STATE_INITIAL);
3740 sci_base_state_machine_start(&sci_req->state_machine);
3742 sci_req->io_tag = io_tag;
3743 sci_req->owning_controller = scic;
3744 sci_req->target_device = sci_dev;
3745 sci_req->protocol = SCIC_NO_PROTOCOL;
3746 sci_req->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX;
3747 sci_req->device_sequence = scic_sds_remote_device_get_sequence(sci_dev);
3749 sci_req->sci_status = SCI_SUCCESS;
3750 sci_req->scu_status = 0;
3751 sci_req->post_context = 0xFFFFFFFF;
3753 sci_req->is_task_management_request = false;
3755 if (io_tag == SCI_CONTROLLER_INVALID_IO_TAG) {
3756 sci_req->was_tag_assigned_by_user = false;
3757 sci_req->task_context_buffer = &sci_req->tc;
3759 sci_req->was_tag_assigned_by_user = true;
3761 sci_req->task_context_buffer =
3762 scic_sds_controller_get_task_context_buffer(scic, io_tag);
3766 static enum sci_status
3767 scic_io_request_construct(struct scic_sds_controller *scic,
3768 struct scic_sds_remote_device *sci_dev,
3769 u16 io_tag, struct scic_sds_request *sci_req)
3771 struct domain_device *dev = sci_dev_to_domain(sci_dev);
3772 enum sci_status status = SCI_SUCCESS;
3774 /* Build the common part of the request */
3775 scic_sds_general_request_construct(scic, sci_dev, io_tag, sci_req);
3777 if (sci_dev->rnc.remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX)
3778 return SCI_FAILURE_INVALID_REMOTE_DEVICE;
3780 if (dev->dev_type == SAS_END_DEV)
3782 else if (dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP))
3783 memset(&sci_req->stp.cmd, 0, sizeof(sci_req->stp.cmd));
3784 else if (dev_is_expander(dev))
3785 memset(&sci_req->smp.cmd, 0, sizeof(sci_req->smp.cmd));
3787 return SCI_FAILURE_UNSUPPORTED_PROTOCOL;
3789 memset(sci_req->task_context_buffer, 0,
3790 offsetof(struct scu_task_context, sgl_pair_ab));
3795 enum sci_status scic_task_request_construct(struct scic_sds_controller *scic,
3796 struct scic_sds_remote_device *sci_dev,
3797 u16 io_tag, struct scic_sds_request *sci_req)
3799 struct domain_device *dev = sci_dev_to_domain(sci_dev);
3800 enum sci_status status = SCI_SUCCESS;
3802 /* Build the common part of the request */
3803 scic_sds_general_request_construct(scic, sci_dev, io_tag, sci_req);
3805 if (dev->dev_type == SAS_END_DEV ||
3806 dev->dev_type == SATA_DEV || (dev->tproto & SAS_PROTOCOL_STP)) {
3807 sci_req->is_task_management_request = true;
3808 memset(sci_req->task_context_buffer, 0, sizeof(struct scu_task_context));
3810 status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
3815 static enum sci_status isci_request_ssp_request_construct(
3816 struct isci_request *request)
3818 enum sci_status status;
3820 dev_dbg(&request->isci_host->pdev->dev,
3821 "%s: request = %p\n",
3824 status = scic_io_request_construct_basic_ssp(&request->sci);
3828 static enum sci_status isci_request_stp_request_construct(
3829 struct isci_request *request)
3831 struct sas_task *task = isci_request_access_task(request);
3832 enum sci_status status;
3833 struct host_to_dev_fis *register_fis;
3835 dev_dbg(&request->isci_host->pdev->dev,
3836 "%s: request = %p\n",
3840 /* Get the host_to_dev_fis from the core and copy
3841 * the fis from the task into it.
3843 register_fis = isci_sata_task_to_fis_copy(task);
3845 status = scic_io_request_construct_basic_sata(&request->sci);
3847 /* Set the ncq tag in the fis, from the queue
3848 * command in the task.
3850 if (isci_sata_is_task_ncq(task)) {
3852 isci_sata_set_ncq_tag(
3862 * This function will fill in the SCU Task Context for a SMP request. The
3863 * following important settings are utilized: -# task_type ==
3864 * SCU_TASK_TYPE_SMP. This simply indicates that a normal request type
3865 * (i.e. non-raw frame) is being utilized to perform task management. -#
3866 * control_frame == 1. This ensures that the proper endianess is set so
3867 * that the bytes are transmitted in the right order for a smp request frame.
3868 * @sci_req: This parameter specifies the smp request object being
3873 scu_smp_request_construct_task_context(struct scic_sds_request *sci_req,
3874 struct smp_req *smp_req)
3876 dma_addr_t dma_addr;
3877 struct scic_sds_controller *scic;
3878 struct scic_sds_remote_device *sci_dev;
3879 struct scic_sds_port *sci_port;
3880 struct scu_task_context *task_context;
3881 ssize_t word_cnt = sizeof(struct smp_req) / sizeof(u32);
3883 /* byte swap the smp request. */
3884 sci_swab32_cpy(&sci_req->smp.cmd, smp_req,
3887 task_context = scic_sds_request_get_task_context(sci_req);
3889 scic = scic_sds_request_get_controller(sci_req);
3890 sci_dev = scic_sds_request_get_device(sci_req);
3891 sci_port = scic_sds_request_get_port(sci_req);
3894 * Fill in the TC with the its required data
3897 task_context->priority = 0;
3898 task_context->initiator_request = 1;
3899 task_context->connection_rate = sci_dev->connection_rate;
3900 task_context->protocol_engine_index =
3901 scic_sds_controller_get_protocol_engine_group(scic);
3902 task_context->logical_port_index = scic_sds_port_get_index(sci_port);
3903 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SMP;
3904 task_context->abort = 0;
3905 task_context->valid = SCU_TASK_CONTEXT_VALID;
3906 task_context->context_type = SCU_TASK_CONTEXT_TYPE;
3909 task_context->remote_node_index = sci_dev->rnc.remote_node_index;
3910 task_context->command_code = 0;
3911 task_context->task_type = SCU_TASK_TYPE_SMP_REQUEST;
3914 task_context->link_layer_control = 0;
3915 task_context->do_not_dma_ssp_good_response = 1;
3916 task_context->strict_ordering = 0;
3917 task_context->control_frame = 1;
3918 task_context->timeout_enable = 0;
3919 task_context->block_guard_enable = 0;
3922 task_context->address_modifier = 0;
3925 task_context->ssp_command_iu_length = smp_req->req_len;
3928 task_context->transfer_length_bytes = 0;
3931 * 18h ~ 30h, protocol specific
3932 * since commandIU has been build by framework at this point, we just
3933 * copy the frist DWord from command IU to this location. */
3934 memcpy(&task_context->type.smp, &sci_req->smp.cmd, sizeof(u32));
3938 * "For SMP you could program it to zero. We would prefer that way
3939 * so that done code will be consistent." - Venki
3941 task_context->task_phase = 0;
3943 if (sci_req->was_tag_assigned_by_user) {
3945 * Build the task context now since we have already read
3948 sci_req->post_context =
3949 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
3950 (scic_sds_controller_get_protocol_engine_group(scic) <<
3951 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
3952 (scic_sds_port_get_index(sci_port) <<
3953 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT) |
3954 scic_sds_io_tag_get_index(sci_req->io_tag));
3957 * Build the task context now since we have already read
3959 * I/O tag index is not assigned because we have to wait
3960 * until we get a TCi.
3962 sci_req->post_context =
3963 (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC |
3964 (scic_sds_controller_get_protocol_engine_group(scic) <<
3965 SCU_CONTEXT_COMMAND_PROTOCOL_ENGINE_GROUP_SHIFT) |
3966 (scic_sds_port_get_index(sci_port) <<
3967 SCU_CONTEXT_COMMAND_LOGICAL_PORT_SHIFT));
3971 * Copy the physical address for the command buffer to the SCU Task
3972 * Context command buffer should not contain command header.
3974 dma_addr = scic_io_request_get_dma_addr(sci_req,
3975 ((char *) &sci_req->smp.cmd) +
3978 task_context->command_iu_upper = upper_32_bits(dma_addr);
3979 task_context->command_iu_lower = lower_32_bits(dma_addr);
3981 /* SMP response comes as UF, so no need to set response IU address. */
3982 task_context->response_iu_upper = 0;
3983 task_context->response_iu_lower = 0;
3986 static enum sci_status scic_io_request_construct_smp(struct scic_sds_request *sci_req)
3988 struct smp_req *smp_req = kmalloc(sizeof(*smp_req), GFP_KERNEL);
3991 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
3993 sci_req->protocol = SCIC_SMP_PROTOCOL;
3995 /* Construct the SMP SCU Task Context */
3996 memcpy(smp_req, &sci_req->smp.cmd, sizeof(*smp_req));
3999 * Look at the SMP requests' header fields; for certain SAS 1.x SMP
4000 * functions under SAS 2.0, a zero request length really indicates
4001 * a non-zero default length. */
4002 if (smp_req->req_len == 0) {
4003 switch (smp_req->func) {
4005 case SMP_REPORT_PHY_ERR_LOG:
4006 case SMP_REPORT_PHY_SATA:
4007 case SMP_REPORT_ROUTE_INFO:
4008 smp_req->req_len = 2;
4010 case SMP_CONF_ROUTE_INFO:
4011 case SMP_PHY_CONTROL:
4012 case SMP_PHY_TEST_FUNCTION:
4013 smp_req->req_len = 9;
4015 /* Default - zero is a valid default for 2.0. */
4019 scu_smp_request_construct_task_context(sci_req, smp_req);
4021 sci_base_state_machine_change_state(&sci_req->state_machine,
4022 SCI_BASE_REQUEST_STATE_CONSTRUCTED);
4030 * isci_smp_request_build() - This function builds the smp request.
4031 * @ireq: This parameter points to the isci_request allocated in the
4032 * request construct function.
4034 * SCI_SUCCESS on successfull completion, or specific failure code.
4036 static enum sci_status isci_smp_request_build(struct isci_request *ireq)
4038 enum sci_status status = SCI_FAILURE;
4039 struct sas_task *task = isci_request_access_task(ireq);
4040 struct scic_sds_request *sci_req = &ireq->sci;
4042 dev_dbg(&ireq->isci_host->pdev->dev,
4043 "%s: request = %p\n", __func__, ireq);
4045 dev_dbg(&ireq->isci_host->pdev->dev,
4046 "%s: smp_req len = %d\n",
4048 task->smp_task.smp_req.length);
4050 /* copy the smp_command to the address; */
4051 sg_copy_to_buffer(&task->smp_task.smp_req, 1,
4053 sizeof(struct smp_req));
4055 status = scic_io_request_construct_smp(sci_req);
4056 if (status != SCI_SUCCESS)
4057 dev_warn(&ireq->isci_host->pdev->dev,
4058 "%s: failed with status = %d\n",
4066 * isci_io_request_build() - This function builds the io request object.
4067 * @isci_host: This parameter specifies the ISCI host object
4068 * @request: This parameter points to the isci_request object allocated in the
4069 * request construct function.
4070 * @sci_device: This parameter is the handle for the sci core's remote device
4071 * object that is the destination for this request.
4073 * SCI_SUCCESS on successfull completion, or specific failure code.
4075 static enum sci_status isci_io_request_build(
4076 struct isci_host *isci_host,
4077 struct isci_request *request,
4078 struct isci_remote_device *isci_device)
4080 enum sci_status status = SCI_SUCCESS;
4081 struct sas_task *task = isci_request_access_task(request);
4082 struct scic_sds_remote_device *sci_device = &isci_device->sci;
4084 dev_dbg(&isci_host->pdev->dev,
4085 "%s: isci_device = 0x%p; request = %p, "
4086 "num_scatter = %d\n",
4092 /* map the sgl addresses, if present.
4093 * libata does the mapping for sata devices
4094 * before we get the request.
4096 if (task->num_scatter &&
4097 !sas_protocol_ata(task->task_proto) &&
4098 !(SAS_PROTOCOL_SMP & task->task_proto)) {
4100 request->num_sg_entries = dma_map_sg(
4101 &isci_host->pdev->dev,
4107 if (request->num_sg_entries == 0)
4108 return SCI_FAILURE_INSUFFICIENT_RESOURCES;
4111 /* build the common request object. For now,
4112 * we will let the core allocate the IO tag.
4114 status = scic_io_request_construct(&isci_host->sci, sci_device,
4115 SCI_CONTROLLER_INVALID_IO_TAG,
4118 if (status != SCI_SUCCESS) {
4119 dev_warn(&isci_host->pdev->dev,
4120 "%s: failed request construct\n",
4125 switch (task->task_proto) {
4126 case SAS_PROTOCOL_SMP:
4127 status = isci_smp_request_build(request);
4129 case SAS_PROTOCOL_SSP:
4130 status = isci_request_ssp_request_construct(request);
4132 case SAS_PROTOCOL_SATA:
4133 case SAS_PROTOCOL_STP:
4134 case SAS_PROTOCOL_SATA | SAS_PROTOCOL_STP:
4135 status = isci_request_stp_request_construct(request);
4138 dev_warn(&isci_host->pdev->dev,
4139 "%s: unknown protocol\n", __func__);
4147 * isci_request_alloc_core() - This function gets the request object from the
4148 * isci_host dma cache.
4149 * @isci_host: This parameter specifies the ISCI host object
4150 * @isci_request: This parameter will contain the pointer to the new
4151 * isci_request object.
4152 * @isci_device: This parameter is the pointer to the isci remote device object
4153 * that is the destination for this request.
4154 * @gfp_flags: This parameter specifies the os allocation flags.
4156 * SCI_SUCCESS on successfull completion, or specific failure code.
4158 static int isci_request_alloc_core(
4159 struct isci_host *isci_host,
4160 struct isci_request **isci_request,
4161 struct isci_remote_device *isci_device,
4166 struct isci_request *request;
4169 /* get pointer to dma memory. This actually points
4170 * to both the isci_remote_device object and the
4171 * sci object. The isci object is at the beginning
4172 * of the memory allocated here.
4174 request = dma_pool_alloc(isci_host->dma_pool, gfp_flags, &handle);
4176 dev_warn(&isci_host->pdev->dev,
4177 "%s: dma_pool_alloc returned NULL\n", __func__);
4181 /* initialize the request object. */
4182 spin_lock_init(&request->state_lock);
4183 request->request_daddr = handle;
4184 request->isci_host = isci_host;
4185 request->isci_device = isci_device;
4186 request->io_request_completion = NULL;
4187 request->terminated = false;
4189 request->num_sg_entries = 0;
4191 request->complete_in_target = false;
4193 INIT_LIST_HEAD(&request->completed_node);
4194 INIT_LIST_HEAD(&request->dev_node);
4196 *isci_request = request;
4197 isci_request_change_state(request, allocated);
4202 static int isci_request_alloc_io(
4203 struct isci_host *isci_host,
4204 struct sas_task *task,
4205 struct isci_request **isci_request,
4206 struct isci_remote_device *isci_device,
4209 int retval = isci_request_alloc_core(isci_host, isci_request,
4210 isci_device, gfp_flags);
4213 (*isci_request)->ttype_ptr.io_task_ptr = task;
4214 (*isci_request)->ttype = io_task;
4216 task->lldd_task = *isci_request;
4222 * isci_request_alloc_tmf() - This function gets the request object from the
4223 * isci_host dma cache and initializes the relevant fields as a sas_task.
4224 * @isci_host: This parameter specifies the ISCI host object
4225 * @sas_task: This parameter is the task struct from the upper layer driver.
4226 * @isci_request: This parameter will contain the pointer to the new
4227 * isci_request object.
4228 * @isci_device: This parameter is the pointer to the isci remote device object
4229 * that is the destination for this request.
4230 * @gfp_flags: This parameter specifies the os allocation flags.
4232 * SCI_SUCCESS on successfull completion, or specific failure code.
4234 int isci_request_alloc_tmf(
4235 struct isci_host *isci_host,
4236 struct isci_tmf *isci_tmf,
4237 struct isci_request **isci_request,
4238 struct isci_remote_device *isci_device,
4241 int retval = isci_request_alloc_core(isci_host, isci_request,
4242 isci_device, gfp_flags);
4246 (*isci_request)->ttype_ptr.tmf_task_ptr = isci_tmf;
4247 (*isci_request)->ttype = tmf_task;
4253 * isci_request_execute() - This function allocates the isci_request object,
4254 * all fills in some common fields.
4255 * @isci_host: This parameter specifies the ISCI host object
4256 * @sas_task: This parameter is the task struct from the upper layer driver.
4257 * @isci_request: This parameter will contain the pointer to the new
4258 * isci_request object.
4259 * @gfp_flags: This parameter specifies the os allocation flags.
4261 * SCI_SUCCESS on successfull completion, or specific failure code.
4263 int isci_request_execute(
4264 struct isci_host *isci_host,
4265 struct sas_task *task,
4266 struct isci_request **isci_request,
4270 struct scic_sds_remote_device *sci_device;
4271 enum sci_status status = SCI_FAILURE_UNSUPPORTED_PROTOCOL;
4272 struct isci_remote_device *isci_device;
4273 struct isci_request *request;
4274 unsigned long flags;
4276 isci_device = task->dev->lldd_dev;
4277 sci_device = &isci_device->sci;
4279 /* do common allocation and init of request object. */
4280 ret = isci_request_alloc_io(
4291 status = isci_io_request_build(isci_host, request, isci_device);
4292 if (status != SCI_SUCCESS) {
4293 dev_warn(&isci_host->pdev->dev,
4294 "%s: request_construct failed - status = 0x%x\n",
4300 spin_lock_irqsave(&isci_host->scic_lock, flags);
4302 /* send the request, let the core assign the IO TAG. */
4303 status = scic_controller_start_io(&isci_host->sci, sci_device,
4305 SCI_CONTROLLER_INVALID_IO_TAG);
4306 if (status != SCI_SUCCESS &&
4307 status != SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
4308 dev_warn(&isci_host->pdev->dev,
4309 "%s: failed request start (0x%x)\n",
4311 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
4315 /* Either I/O started OK, or the core has signaled that
4316 * the device needs a target reset.
4318 * In either case, hold onto the I/O for later.
4320 * Update it's status and add it to the list in the
4321 * remote device object.
4323 isci_request_change_state(request, started);
4324 list_add(&request->dev_node, &isci_device->reqs_in_process);
4326 if (status == SCI_SUCCESS) {
4327 /* Save the tag for possible task mgmt later. */
4328 request->io_tag = request->sci.io_tag;
4330 /* The request did not really start in the
4331 * hardware, so clear the request handle
4332 * here so no terminations will be done.
4334 request->terminated = true;
4336 spin_unlock_irqrestore(&isci_host->scic_lock, flags);
4339 SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED) {
4340 /* Signal libsas that we need the SCSI error
4341 * handler thread to work on this I/O and that
4342 * we want a device reset.
4344 spin_lock_irqsave(&task->task_state_lock, flags);
4345 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET;
4346 spin_unlock_irqrestore(&task->task_state_lock, flags);
4348 /* Cause this task to be scheduled in the SCSI error
4351 isci_execpath_callback(isci_host, task,
4354 /* Change the status, since we are holding
4355 * the I/O until it is managed by the SCSI
4358 status = SCI_SUCCESS;
4362 if (status != SCI_SUCCESS) {
4363 /* release dma memory on failure. */
4364 isci_request_free(isci_host, request);
4369 *isci_request = request;