Lines Matching +full:build +full:- +full:tci

7  * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
20 * Foundation, Inc., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
26 * Copyright(c) 2008 - 2011 Intel Corporation. All rights reserved.
78 return &ireq->tc->sgl_pair_ab; in to_sgl_element_pair()
80 return &ireq->tc->sgl_pair_cd; in to_sgl_element_pair()
84 return &ireq->sg_table[idx - 2]; in to_sgl_element_pair()
93 offset = (void *) &ireq->tc->sgl_pair_ab - in to_sgl_element_pair_dma()
94 (void *) &ihost->task_context_table[0]; in to_sgl_element_pair_dma()
95 return ihost->tc_dma + offset; in to_sgl_element_pair_dma()
97 offset = (void *) &ireq->tc->sgl_pair_cd - in to_sgl_element_pair_dma()
98 (void *) &ihost->task_context_table[0]; in to_sgl_element_pair_dma()
99 return ihost->tc_dma + offset; in to_sgl_element_pair_dma()
102 return sci_io_request_get_dma_addr(ireq, &ireq->sg_table[idx - 2]); in to_sgl_element_pair_dma()
107 e->length = sg_dma_len(sg); in init_sgl_element()
108 e->address_upper = upper_32_bits(sg_dma_address(sg)); in init_sgl_element()
109 e->address_lower = lower_32_bits(sg_dma_address(sg)); in init_sgl_element()
110 e->address_modifier = 0; in init_sgl_element()
115 struct isci_host *ihost = ireq->isci_host; in sci_request_build_sgl()
123 if (task->num_scatter > 0) { in sci_request_build_sgl()
124 sg = task->scatter; in sci_request_build_sgl()
128 init_sgl_element(&scu_sg->A, sg); in sci_request_build_sgl()
131 init_sgl_element(&scu_sg->B, sg); in sci_request_build_sgl()
134 memset(&scu_sg->B, 0, sizeof(scu_sg->B)); in sci_request_build_sgl()
141 prev_sg->next_pair_upper = in sci_request_build_sgl()
143 prev_sg->next_pair_lower = in sci_request_build_sgl()
153 dma_addr = dma_map_single(&ihost->pdev->dev, in sci_request_build_sgl()
154 task->scatter, in sci_request_build_sgl()
155 task->total_xfer_len, in sci_request_build_sgl()
156 task->data_dir); in sci_request_build_sgl()
158 ireq->zero_scatter_daddr = dma_addr; in sci_request_build_sgl()
160 scu_sg->A.length = task->total_xfer_len; in sci_request_build_sgl()
161 scu_sg->A.address_upper = upper_32_bits(dma_addr); in sci_request_build_sgl()
162 scu_sg->A.address_lower = lower_32_bits(dma_addr); in sci_request_build_sgl()
166 scu_sg->next_pair_upper = 0; in sci_request_build_sgl()
167 scu_sg->next_pair_lower = 0; in sci_request_build_sgl()
176 cmd_iu = &ireq->ssp.cmd; in sci_io_request_build_ssp_command_iu()
178 memcpy(cmd_iu->LUN, task->ssp_task.LUN, 8); in sci_io_request_build_ssp_command_iu()
179 cmd_iu->add_cdb_len = 0; in sci_io_request_build_ssp_command_iu()
180 cmd_iu->_r_a = 0; in sci_io_request_build_ssp_command_iu()
181 cmd_iu->_r_b = 0; in sci_io_request_build_ssp_command_iu()
182 cmd_iu->en_fburst = 0; /* unsupported */ in sci_io_request_build_ssp_command_iu()
183 cmd_iu->task_prio = 0; in sci_io_request_build_ssp_command_iu()
184 cmd_iu->task_attr = task->ssp_task.task_attr; in sci_io_request_build_ssp_command_iu()
185 cmd_iu->_r_c = 0; in sci_io_request_build_ssp_command_iu()
187 sci_swab32_cpy(&cmd_iu->cdb, task->ssp_task.cmd->cmnd, in sci_io_request_build_ssp_command_iu()
188 (task->ssp_task.cmd->cmd_len+3) / sizeof(u32)); in sci_io_request_build_ssp_command_iu()
197 task_iu = &ireq->ssp.tmf; in sci_task_request_build_ssp_task_iu()
201 memcpy(task_iu->LUN, task->ssp_task.LUN, 8); in sci_task_request_build_ssp_task_iu()
203 task_iu->task_func = isci_tmf->tmf_code; in sci_task_request_build_ssp_task_iu()
204 task_iu->task_tag = in sci_task_request_build_ssp_task_iu()
205 (test_bit(IREQ_TMF, &ireq->flags)) ? in sci_task_request_build_ssp_task_iu()
206 isci_tmf->io_tag : in sci_task_request_build_ssp_task_iu()
221 idev = ireq->target_device; in scu_ssp_request_construct_task_context()
222 iport = idev->owning_port; in scu_ssp_request_construct_task_context()
225 task_context->abort = 0; in scu_ssp_request_construct_task_context()
226 task_context->priority = 0; in scu_ssp_request_construct_task_context()
227 task_context->initiator_request = 1; in scu_ssp_request_construct_task_context()
228 task_context->connection_rate = idev->connection_rate; in scu_ssp_request_construct_task_context()
229 task_context->protocol_engine_index = ISCI_PEG; in scu_ssp_request_construct_task_context()
230 task_context->logical_port_index = iport->physical_port_index; in scu_ssp_request_construct_task_context()
231 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SSP; in scu_ssp_request_construct_task_context()
232 task_context->valid = SCU_TASK_CONTEXT_VALID; in scu_ssp_request_construct_task_context()
233 task_context->context_type = SCU_TASK_CONTEXT_TYPE; in scu_ssp_request_construct_task_context()
235 task_context->remote_node_index = idev->rnc.remote_node_index; in scu_ssp_request_construct_task_context()
236 task_context->command_code = 0; in scu_ssp_request_construct_task_context()
238 task_context->link_layer_control = 0; in scu_ssp_request_construct_task_context()
239 task_context->do_not_dma_ssp_good_response = 1; in scu_ssp_request_construct_task_context()
240 task_context->strict_ordering = 0; in scu_ssp_request_construct_task_context()
241 task_context->control_frame = 0; in scu_ssp_request_construct_task_context()
242 task_context->timeout_enable = 0; in scu_ssp_request_construct_task_context()
243 task_context->block_guard_enable = 0; in scu_ssp_request_construct_task_context()
245 task_context->address_modifier = 0; in scu_ssp_request_construct_task_context()
247 /* task_context->type.ssp.tag = ireq->io_tag; */ in scu_ssp_request_construct_task_context()
248 task_context->task_phase = 0x01; in scu_ssp_request_construct_task_context()
250 ireq->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | in scu_ssp_request_construct_task_context()
252 (iport->physical_port_index << in scu_ssp_request_construct_task_context()
254 ISCI_TAG_TCI(ireq->io_tag)); in scu_ssp_request_construct_task_context()
260 dma_addr = sci_io_request_get_dma_addr(ireq, &ireq->ssp.cmd); in scu_ssp_request_construct_task_context()
262 task_context->command_iu_upper = upper_32_bits(dma_addr); in scu_ssp_request_construct_task_context()
263 task_context->command_iu_lower = lower_32_bits(dma_addr); in scu_ssp_request_construct_task_context()
269 dma_addr = sci_io_request_get_dma_addr(ireq, &ireq->ssp.rsp); in scu_ssp_request_construct_task_context()
271 task_context->response_iu_upper = upper_32_bits(dma_addr); in scu_ssp_request_construct_task_context()
272 task_context->response_iu_lower = lower_32_bits(dma_addr); in scu_ssp_request_construct_task_context()
277 switch (sdp->sector_size) { in scu_bg_blk_size()
296 struct scu_task_context *tc = ireq->tc; in scu_ssp_ireq_dif_insert()
297 struct scsi_cmnd *scmd = ireq->ttype_ptr.io_task_ptr->uldd_task; in scu_ssp_ireq_dif_insert()
298 u8 blk_sz = scu_bg_blk_size(scmd->device); in scu_ssp_ireq_dif_insert()
300 tc->block_guard_enable = 1; in scu_ssp_ireq_dif_insert()
301 tc->blk_prot_en = 1; in scu_ssp_ireq_dif_insert()
302 tc->blk_sz = blk_sz; in scu_ssp_ireq_dif_insert()
304 tc->blk_prot_func = 0x2; in scu_ssp_ireq_dif_insert()
306 tc->transfer_length_bytes += scu_dif_bytes(tc->transfer_length_bytes, in scu_ssp_ireq_dif_insert()
307 scmd->device->sector_size); in scu_ssp_ireq_dif_insert()
310 tc->interm_crc_val = 0; in scu_ssp_ireq_dif_insert()
312 tc->init_crc_seed = 0; in scu_ssp_ireq_dif_insert()
313 tc->app_tag_verify = 0; in scu_ssp_ireq_dif_insert()
314 tc->app_tag_gen = 0; in scu_ssp_ireq_dif_insert()
315 tc->ref_tag_seed_verify = 0; in scu_ssp_ireq_dif_insert()
318 tc->UD_bytes_immed_val = scmd->device->sector_size; in scu_ssp_ireq_dif_insert()
320 tc->reserved_DC_0 = 0; in scu_ssp_ireq_dif_insert()
323 tc->DIF_bytes_immed_val = 8; in scu_ssp_ireq_dif_insert()
325 tc->reserved_DC_1 = 0; in scu_ssp_ireq_dif_insert()
326 tc->bgc_blk_sz = scmd->device->sector_size; in scu_ssp_ireq_dif_insert()
327 tc->reserved_E0_0 = 0; in scu_ssp_ireq_dif_insert()
328 tc->app_tag_gen_mask = 0; in scu_ssp_ireq_dif_insert()
331 tc->bgctl = 0; in scu_ssp_ireq_dif_insert()
334 tc->bgctl_f.op = 0x2; in scu_ssp_ireq_dif_insert()
336 tc->app_tag_verify_mask = 0; in scu_ssp_ireq_dif_insert()
339 tc->blk_guard_err = 0; in scu_ssp_ireq_dif_insert()
341 tc->reserved_E8_0 = 0; in scu_ssp_ireq_dif_insert()
344 tc->ref_tag_seed_gen = scsi_prot_ref_tag(scmd); in scu_ssp_ireq_dif_insert()
346 tc->ref_tag_seed_gen = 0; in scu_ssp_ireq_dif_insert()
351 struct scu_task_context *tc = ireq->tc; in scu_ssp_ireq_dif_strip()
352 struct scsi_cmnd *scmd = ireq->ttype_ptr.io_task_ptr->uldd_task; in scu_ssp_ireq_dif_strip()
353 u8 blk_sz = scu_bg_blk_size(scmd->device); in scu_ssp_ireq_dif_strip()
355 tc->block_guard_enable = 1; in scu_ssp_ireq_dif_strip()
356 tc->blk_prot_en = 1; in scu_ssp_ireq_dif_strip()
357 tc->blk_sz = blk_sz; in scu_ssp_ireq_dif_strip()
359 tc->blk_prot_func = 0x1; in scu_ssp_ireq_dif_strip()
361 tc->transfer_length_bytes += scu_dif_bytes(tc->transfer_length_bytes, in scu_ssp_ireq_dif_strip()
362 scmd->device->sector_size); in scu_ssp_ireq_dif_strip()
365 tc->interm_crc_val = 0; in scu_ssp_ireq_dif_strip()
367 tc->init_crc_seed = 0; in scu_ssp_ireq_dif_strip()
368 tc->app_tag_verify = 0; in scu_ssp_ireq_dif_strip()
369 tc->app_tag_gen = 0; in scu_ssp_ireq_dif_strip()
372 tc->ref_tag_seed_verify = scsi_prot_ref_tag(scmd); in scu_ssp_ireq_dif_strip()
374 tc->ref_tag_seed_verify = 0; in scu_ssp_ireq_dif_strip()
377 tc->UD_bytes_immed_val = scmd->device->sector_size; in scu_ssp_ireq_dif_strip()
379 tc->reserved_DC_0 = 0; in scu_ssp_ireq_dif_strip()
382 tc->DIF_bytes_immed_val = 8; in scu_ssp_ireq_dif_strip()
384 tc->reserved_DC_1 = 0; in scu_ssp_ireq_dif_strip()
385 tc->bgc_blk_sz = scmd->device->sector_size; in scu_ssp_ireq_dif_strip()
386 tc->reserved_E0_0 = 0; in scu_ssp_ireq_dif_strip()
387 tc->app_tag_gen_mask = 0; in scu_ssp_ireq_dif_strip()
390 tc->bgctl = 0; in scu_ssp_ireq_dif_strip()
393 tc->bgctl_f.crc_verify = 1; in scu_ssp_ireq_dif_strip()
394 tc->bgctl_f.op = 0x1; in scu_ssp_ireq_dif_strip()
396 tc->bgctl_f.ref_tag_chk = 1; in scu_ssp_ireq_dif_strip()
397 tc->bgctl_f.app_f_detect = 1; in scu_ssp_ireq_dif_strip()
399 tc->bgctl_f.app_ref_f_detect = 1; in scu_ssp_ireq_dif_strip()
401 tc->app_tag_verify_mask = 0; in scu_ssp_ireq_dif_strip()
404 tc->blk_guard_err = 0; in scu_ssp_ireq_dif_strip()
406 tc->reserved_E8_0 = 0; in scu_ssp_ireq_dif_strip()
407 tc->ref_tag_seed_gen = 0; in scu_ssp_ireq_dif_strip()
417 struct scu_task_context *task_context = ireq->tc; in scu_ssp_io_request_construct_task_context()
418 struct sas_task *sas_task = ireq->ttype_ptr.io_task_ptr; in scu_ssp_io_request_construct_task_context()
419 struct scsi_cmnd *scmd = sas_task->uldd_task; in scu_ssp_io_request_construct_task_context()
425 task_context->ssp_command_iu_length = in scu_ssp_io_request_construct_task_context()
427 task_context->type.ssp.frame_type = SSP_COMMAND; in scu_ssp_io_request_construct_task_context()
433 task_context->task_type = SCU_TASK_TYPE_IOREAD; in scu_ssp_io_request_construct_task_context()
436 task_context->task_type = SCU_TASK_TYPE_IOWRITE; in scu_ssp_io_request_construct_task_context()
440 task_context->transfer_length_bytes = len; in scu_ssp_io_request_construct_task_context()
442 if (task_context->transfer_length_bytes > 0) in scu_ssp_io_request_construct_task_context()
454 * scu_ssp_task_request_construct_task_context() - This method will fill in
456 * settings are utilized: -# priority == SCU_TASK_PRIORITY_HIGH. This
458 * for the same Remote Node. -# task_type == SCU_TASK_TYPE_IOREAD. This
459 * simply indicates that a normal request type (i.e. non-raw frame) is
460 * being utilized to perform task management. -#control_frame == 1. This
467 struct scu_task_context *task_context = ireq->tc; in scu_ssp_task_request_construct_task_context()
471 task_context->control_frame = 1; in scu_ssp_task_request_construct_task_context()
472 task_context->priority = SCU_TASK_PRIORITY_HIGH; in scu_ssp_task_request_construct_task_context()
473 task_context->task_type = SCU_TASK_TYPE_RAW_FRAME; in scu_ssp_task_request_construct_task_context()
474 task_context->transfer_length_bytes = 0; in scu_ssp_task_request_construct_task_context()
475 task_context->type.ssp.frame_type = SSP_TASK; in scu_ssp_task_request_construct_task_context()
476 task_context->ssp_command_iu_length = in scu_ssp_task_request_construct_task_context()
501 idev = ireq->target_device; in scu_sata_request_construct_task_context()
502 iport = idev->owning_port; in scu_sata_request_construct_task_context()
505 task_context->abort = 0; in scu_sata_request_construct_task_context()
506 task_context->priority = SCU_TASK_PRIORITY_NORMAL; in scu_sata_request_construct_task_context()
507 task_context->initiator_request = 1; in scu_sata_request_construct_task_context()
508 task_context->connection_rate = idev->connection_rate; in scu_sata_request_construct_task_context()
509 task_context->protocol_engine_index = ISCI_PEG; in scu_sata_request_construct_task_context()
510 task_context->logical_port_index = iport->physical_port_index; in scu_sata_request_construct_task_context()
511 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_STP; in scu_sata_request_construct_task_context()
512 task_context->valid = SCU_TASK_CONTEXT_VALID; in scu_sata_request_construct_task_context()
513 task_context->context_type = SCU_TASK_CONTEXT_TYPE; in scu_sata_request_construct_task_context()
515 task_context->remote_node_index = idev->rnc.remote_node_index; in scu_sata_request_construct_task_context()
516 task_context->command_code = 0; in scu_sata_request_construct_task_context()
518 task_context->link_layer_control = 0; in scu_sata_request_construct_task_context()
519 task_context->do_not_dma_ssp_good_response = 1; in scu_sata_request_construct_task_context()
520 task_context->strict_ordering = 0; in scu_sata_request_construct_task_context()
521 task_context->control_frame = 0; in scu_sata_request_construct_task_context()
522 task_context->timeout_enable = 0; in scu_sata_request_construct_task_context()
523 task_context->block_guard_enable = 0; in scu_sata_request_construct_task_context()
525 task_context->address_modifier = 0; in scu_sata_request_construct_task_context()
526 task_context->task_phase = 0x01; in scu_sata_request_construct_task_context()
528 task_context->ssp_command_iu_length = in scu_sata_request_construct_task_context()
529 (sizeof(struct host_to_dev_fis) - sizeof(u32)) / sizeof(u32); in scu_sata_request_construct_task_context()
532 task_context->type.words[0] = *(u32 *)&ireq->stp.cmd; in scu_sata_request_construct_task_context()
534 ireq->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | in scu_sata_request_construct_task_context()
536 (iport->physical_port_index << in scu_sata_request_construct_task_context()
538 ISCI_TAG_TCI(ireq->io_tag)); in scu_sata_request_construct_task_context()
545 ((char *) &ireq->stp.cmd) + in scu_sata_request_construct_task_context()
548 task_context->command_iu_upper = upper_32_bits(dma_addr); in scu_sata_request_construct_task_context()
549 task_context->command_iu_lower = lower_32_bits(dma_addr); in scu_sata_request_construct_task_context()
552 task_context->response_iu_upper = 0; in scu_sata_request_construct_task_context()
553 task_context->response_iu_lower = 0; in scu_sata_request_construct_task_context()
558 struct scu_task_context *task_context = ireq->tc; in scu_stp_raw_request_construct_task_context()
562 task_context->control_frame = 0; in scu_stp_raw_request_construct_task_context()
563 task_context->priority = SCU_TASK_PRIORITY_NORMAL; in scu_stp_raw_request_construct_task_context()
564 task_context->task_type = SCU_TASK_TYPE_SATA_RAW_FRAME; in scu_stp_raw_request_construct_task_context()
565 task_context->type.stp.fis_type = FIS_REGH2D; in scu_stp_raw_request_construct_task_context()
566 task_context->transfer_length_bytes = sizeof(struct host_to_dev_fis) - sizeof(u32); in scu_stp_raw_request_construct_task_context()
572 struct isci_stp_request *stp_req = &ireq->stp.req; in sci_stp_pio_request_construct()
576 stp_req->status = 0; in sci_stp_pio_request_construct()
577 stp_req->sgl.offset = 0; in sci_stp_pio_request_construct()
578 stp_req->sgl.set = SCU_SGL_ELEMENT_PAIR_A; in sci_stp_pio_request_construct()
582 stp_req->sgl.index = 0; in sci_stp_pio_request_construct()
585 stp_req->sgl.index = -1; in sci_stp_pio_request_construct()
596 * an UDMA request or a NCQ request. - A value of 0 indicates UDMA. - A
608 struct scu_task_context *task_context = ireq->tc; in sci_stp_optimized_request_construct()
610 /* Build the STP task context structure */ in sci_stp_optimized_request_construct()
617 task_context->transfer_length_bytes = len; in sci_stp_optimized_request_construct()
626 task_context->task_type = optimized_task_type + (SCU_TASK_TYPE_DMA_OUT in sci_stp_optimized_request_construct()
627 - SCU_TASK_TYPE_DMA_IN); in sci_stp_optimized_request_construct()
632 task_context->task_type = optimized_task_type; in sci_stp_optimized_request_construct()
638 struct host_to_dev_fis *h2d_fis = &ireq->stp.cmd; in sci_atapi_construct()
646 h2d_fis->features |= ATAPI_PKT_DMA; in sci_atapi_construct()
651 if (task->data_dir == DMA_NONE) in sci_atapi_construct()
652 task->total_xfer_len = 0; in sci_atapi_construct()
657 ireq->stp.rsp.fis_type = 0; in sci_atapi_construct()
668 struct domain_device *dev = ireq->target_device->domain_dev; in sci_io_request_construct_sata()
671 if (test_bit(IREQ_TMF, &ireq->flags)) { in sci_io_request_construct_sata()
674 dev_err(&ireq->owning_controller->pdev->dev, in sci_io_request_construct_sata()
675 "%s: Request 0x%p received un-handled SAT " in sci_io_request_construct_sata()
677 __func__, ireq, tmf->tmf_code); in sci_io_request_construct_sata()
682 if (!sas_protocol_ata(task->task_proto)) { in sci_io_request_construct_sata()
683 dev_err(&ireq->owning_controller->pdev->dev, in sci_io_request_construct_sata()
684 "%s: Non-ATA protocol in SATA path: 0x%x\n", in sci_io_request_construct_sata()
686 task->task_proto); in sci_io_request_construct_sata()
692 if (dev->sata_dev.class == ATA_DEV_ATAPI && in sci_io_request_construct_sata()
693 task->ata_task.fis.command == ATA_CMD_PACKET) { in sci_io_request_construct_sata()
699 if (task->data_dir == DMA_NONE) { in sci_io_request_construct_sata()
705 if (task->ata_task.use_ncq) { in sci_io_request_construct_sata()
713 if (task->ata_task.dma_xfer) { in sci_io_request_construct_sata()
728 ireq->protocol = SAS_PROTOCOL_SSP; in sci_io_request_construct_basic_ssp()
731 task->data_dir, in sci_io_request_construct_basic_ssp()
732 task->total_xfer_len); in sci_io_request_construct_basic_ssp()
736 sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); in sci_io_request_construct_basic_ssp()
750 sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); in sci_task_request_construct_ssp()
761 ireq->protocol = SAS_PROTOCOL_STP; in sci_io_request_construct_basic_sata()
763 copy = (task->data_dir == DMA_NONE) ? false : true; in sci_io_request_construct_basic_sata()
766 task->total_xfer_len, in sci_io_request_construct_basic_sata()
767 task->data_dir, in sci_io_request_construct_basic_sata()
771 sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); in sci_io_request_construct_basic_sata()
778 * sci_req_tx_bytes - bytes transferred when reply underruns request
783 struct isci_host *ihost = ireq->owning_controller; in sci_req_tx_bytes()
786 if (readl(&ihost->smu_registers->address_modifier) == 0) { in sci_req_tx_bytes()
787 void __iomem *scu_reg_base = ihost->scu_registers; in sci_req_tx_bytes()
789 /* get the bytes of data from the Address == BAR1 + 20002Ch + (256*TCi) where in sci_req_tx_bytes()
793 * TCi is the io_tag of struct sci_request in sci_req_tx_bytes()
797 ((sizeof(struct scu_task_context)) * ISCI_TAG_TCI(ireq->io_tag))); in sci_req_tx_bytes()
806 struct scu_task_context *tc = ireq->tc; in sci_request_start()
807 struct isci_host *ihost = ireq->owning_controller; in sci_request_start()
809 state = ireq->sm.current_state_id; in sci_request_start()
811 dev_warn(&ihost->pdev->dev, in sci_request_start()
817 tc->task_index = ISCI_TAG_TCI(ireq->io_tag); in sci_request_start()
819 switch (tc->protocol_type) { in sci_request_start()
823 tc->type.ssp.tag = ireq->io_tag; in sci_request_start()
824 tc->type.ssp.target_port_transfer_tag = 0xFFFF; in sci_request_start()
829 * tc->type.stp.ncq_tag = ireq->ncq_tag; in sci_request_start()
838 /* This should never happen since we build the IO in sci_request_start()
844 ireq->post_context |= ISCI_TAG_TCI(ireq->io_tag); in sci_request_start()
847 sci_change_state(&ireq->sm, SCI_REQ_STARTED); in sci_request_start()
857 state = ireq->sm.current_state_id; in sci_io_request_terminate()
862 set_bit(IREQ_TC_ABORT_POSTED, &ireq->flags); in sci_io_request_terminate()
863 ireq->scu_status = SCU_TASK_DONE_TASK_ABORT; in sci_io_request_terminate()
864 ireq->sci_status = SCI_FAILURE_IO_TERMINATED; in sci_io_request_terminate()
865 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in sci_io_request_terminate()
891 sci_change_state(&ireq->sm, SCI_REQ_ABORTING); in sci_io_request_terminate()
894 if (!isci_remote_device_is_safe_to_abort(ireq->target_device)) in sci_io_request_terminate()
895 set_bit(IREQ_PENDING_ABORT, &ireq->flags); in sci_io_request_terminate()
897 clear_bit(IREQ_PENDING_ABORT, &ireq->flags); in sci_io_request_terminate()
904 dev_warn(&ireq->owning_controller->pdev->dev, in sci_io_request_terminate()
906 "state %d\n", __func__, ireq->sm.current_state_id); in sci_io_request_terminate()
916 struct isci_host *ihost = ireq->owning_controller; in sci_request_complete()
918 state = ireq->sm.current_state_id; in sci_request_complete()
924 if (ireq->saved_rx_frame_index != SCU_INVALID_FRAME_INDEX) in sci_request_complete()
926 ireq->saved_rx_frame_index); in sci_request_complete()
929 sci_change_state(&ireq->sm, SCI_REQ_FINAL); in sci_request_complete()
937 struct isci_host *ihost = ireq->owning_controller; in sci_io_request_event_handler()
939 state = ireq->sm.current_state_id; in sci_io_request_event_handler()
942 dev_warn(&ihost->pdev->dev, "%s: (%x) in wrong state %s\n", in sci_io_request_event_handler()
953 sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); in sci_io_request_event_handler()
956 dev_err(&ihost->pdev->dev, in sci_io_request_event_handler()
980 ssp_response = &ireq->ssp.rsp; in sci_io_request_copy_response()
982 resp_buf = &isci_tmf->resp.resp_iu; in sci_io_request_copy_response()
986 be32_to_cpu(ssp_response->response_data_len)); in sci_io_request_copy_response()
988 memcpy(resp_buf, ssp_response->resp_data, len); in sci_io_request_copy_response()
1003 ireq->scu_status = SCU_TASK_DONE_GOOD; in request_started_state_tc_event()
1004 ireq->sci_status = SCI_SUCCESS; in request_started_state_tc_event()
1014 struct ssp_response_iu *resp = &ireq->ssp.rsp; in request_started_state_tc_event()
1017 sci_swab32_cpy(&ireq->ssp.rsp, in request_started_state_tc_event()
1018 &ireq->ssp.rsp, in request_started_state_tc_event()
1021 if (resp->status == 0) { in request_started_state_tc_event()
1022 ireq->scu_status = SCU_TASK_DONE_GOOD; in request_started_state_tc_event()
1023 ireq->sci_status = SCI_SUCCESS_IO_DONE_EARLY; in request_started_state_tc_event()
1025 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in request_started_state_tc_event()
1026 ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; in request_started_state_tc_event()
1033 sci_swab32_cpy(&ireq->ssp.rsp, in request_started_state_tc_event()
1034 &ireq->ssp.rsp, in request_started_state_tc_event()
1037 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in request_started_state_tc_event()
1038 ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; in request_started_state_tc_event()
1047 resp_iu = &ireq->ssp.rsp; in request_started_state_tc_event()
1048 datapres = resp_iu->datapres; in request_started_state_tc_event()
1052 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in request_started_state_tc_event()
1053 ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; in request_started_state_tc_event()
1055 ireq->scu_status = SCU_TASK_DONE_GOOD; in request_started_state_tc_event()
1056 ireq->sci_status = SCI_SUCCESS; in request_started_state_tc_event()
1071 if (ireq->protocol == SAS_PROTOCOL_STP) { in request_started_state_tc_event()
1072 ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> in request_started_state_tc_event()
1074 ireq->sci_status = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; in request_started_state_tc_event()
1076 ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> in request_started_state_tc_event()
1078 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in request_started_state_tc_event()
1093 ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> in request_started_state_tc_event()
1095 ireq->sci_status = SCI_FAILURE_REMOTE_DEVICE_RESET_REQUIRED; in request_started_state_tc_event()
1115 ireq->scu_status = SCU_GET_COMPLETION_TL_STATUS(completion_code) >> in request_started_state_tc_event()
1117 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in request_started_state_tc_event()
1126 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in request_started_state_tc_event()
1137 ireq->scu_status = SCU_TASK_DONE_TASK_ABORT; in request_aborting_state_tc_event()
1138 ireq->sci_status = SCI_FAILURE_IO_TERMINATED; in request_aborting_state_tc_event()
1139 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in request_aborting_state_tc_event()
1157 ireq->scu_status = SCU_TASK_DONE_GOOD; in ssp_task_request_await_tc_event()
1158 ireq->sci_status = SCI_SUCCESS; in ssp_task_request_await_tc_event()
1159 sci_change_state(&ireq->sm, SCI_REQ_TASK_WAIT_TC_RESP); in ssp_task_request_await_tc_event()
1167 dev_warn(&ireq->owning_controller->pdev->dev, in ssp_task_request_await_tc_event()
1168 "%s: TaskRequest:0x%p CompletionCode:%x - " in ssp_task_request_await_tc_event()
1172 sci_change_state(&ireq->sm, SCI_REQ_TASK_WAIT_TC_RESP); in ssp_task_request_await_tc_event()
1180 ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); in ssp_task_request_await_tc_event()
1181 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in ssp_task_request_await_tc_event()
1182 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in ssp_task_request_await_tc_event()
1199 ireq->scu_status = SCU_TASK_DONE_GOOD; in smp_request_await_response_tc_event()
1200 ireq->sci_status = SCI_SUCCESS; in smp_request_await_response_tc_event()
1201 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in smp_request_await_response_tc_event()
1214 ireq->scu_status = SCU_TASK_DONE_SMP_RESP_TO_ERR; in smp_request_await_response_tc_event()
1215 ireq->sci_status = SCI_FAILURE_RETRY_REQUIRED; in smp_request_await_response_tc_event()
1216 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in smp_request_await_response_tc_event()
1222 ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); in smp_request_await_response_tc_event()
1223 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in smp_request_await_response_tc_event()
1224 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in smp_request_await_response_tc_event()
1237 ireq->scu_status = SCU_TASK_DONE_GOOD; in smp_request_await_tc_event()
1238 ireq->sci_status = SCI_SUCCESS; in smp_request_await_tc_event()
1239 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in smp_request_await_tc_event()
1246 ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); in smp_request_await_tc_event()
1247 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in smp_request_await_tc_event()
1248 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in smp_request_await_tc_event()
1260 struct isci_stp_pio_sgl *pio_sgl = &stp_req->sgl; in pio_sgl_next()
1262 sgl_pair = to_sgl_element_pair(ireq, pio_sgl->index); in pio_sgl_next()
1265 else if (pio_sgl->set == SCU_SGL_ELEMENT_PAIR_A) { in pio_sgl_next()
1266 if (sgl_pair->B.address_lower == 0 && in pio_sgl_next()
1267 sgl_pair->B.address_upper == 0) { in pio_sgl_next()
1270 pio_sgl->set = SCU_SGL_ELEMENT_PAIR_B; in pio_sgl_next()
1271 sgl = &sgl_pair->B; in pio_sgl_next()
1274 if (sgl_pair->next_pair_lower == 0 && in pio_sgl_next()
1275 sgl_pair->next_pair_upper == 0) { in pio_sgl_next()
1278 pio_sgl->index++; in pio_sgl_next()
1279 pio_sgl->set = SCU_SGL_ELEMENT_PAIR_A; in pio_sgl_next()
1280 sgl_pair = to_sgl_element_pair(ireq, pio_sgl->index); in pio_sgl_next()
1281 sgl = &sgl_pair->A; in pio_sgl_next()
1294 ireq->scu_status = SCU_TASK_DONE_GOOD; in stp_request_non_data_await_h2d_tc_event()
1295 ireq->sci_status = SCI_SUCCESS; in stp_request_non_data_await_h2d_tc_event()
1296 sci_change_state(&ireq->sm, SCI_REQ_STP_NON_DATA_WAIT_D2H); in stp_request_non_data_await_h2d_tc_event()
1304 ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); in stp_request_non_data_await_h2d_tc_event()
1305 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in stp_request_non_data_await_h2d_tc_event()
1306 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in stp_request_non_data_await_h2d_tc_event()
1322 struct isci_stp_request *stp_req = &ireq->stp.req; in sci_stp_request_pio_data_out_trasmit_data_frame()
1323 struct scu_task_context *task_context = ireq->tc; in sci_stp_request_pio_data_out_trasmit_data_frame()
1330 sgl_pair = to_sgl_element_pair(ireq, stp_req->sgl.index); in sci_stp_request_pio_data_out_trasmit_data_frame()
1331 if (stp_req->sgl.set == SCU_SGL_ELEMENT_PAIR_A) in sci_stp_request_pio_data_out_trasmit_data_frame()
1332 current_sgl = &sgl_pair->A; in sci_stp_request_pio_data_out_trasmit_data_frame()
1334 current_sgl = &sgl_pair->B; in sci_stp_request_pio_data_out_trasmit_data_frame()
1337 task_context->command_iu_upper = current_sgl->address_upper; in sci_stp_request_pio_data_out_trasmit_data_frame()
1338 task_context->command_iu_lower = current_sgl->address_lower; in sci_stp_request_pio_data_out_trasmit_data_frame()
1339 task_context->transfer_length_bytes = length; in sci_stp_request_pio_data_out_trasmit_data_frame()
1340 task_context->type.stp.fis_type = FIS_DATA; in sci_stp_request_pio_data_out_trasmit_data_frame()
1348 struct isci_stp_request *stp_req = &ireq->stp.req; in sci_stp_request_pio_data_out_transmit_data()
1355 offset = stp_req->sgl.offset; in sci_stp_request_pio_data_out_transmit_data()
1356 sgl_pair = to_sgl_element_pair(ireq, stp_req->sgl.index); in sci_stp_request_pio_data_out_transmit_data()
1360 if (stp_req->sgl.set == SCU_SGL_ELEMENT_PAIR_A) { in sci_stp_request_pio_data_out_transmit_data()
1361 sgl = &sgl_pair->A; in sci_stp_request_pio_data_out_transmit_data()
1362 len = sgl_pair->A.length - offset; in sci_stp_request_pio_data_out_transmit_data()
1364 sgl = &sgl_pair->B; in sci_stp_request_pio_data_out_transmit_data()
1365 len = sgl_pair->B.length - offset; in sci_stp_request_pio_data_out_transmit_data()
1368 if (stp_req->pio_len == 0) in sci_stp_request_pio_data_out_transmit_data()
1371 if (stp_req->pio_len >= len) { in sci_stp_request_pio_data_out_transmit_data()
1375 stp_req->pio_len -= len; in sci_stp_request_pio_data_out_transmit_data()
1380 } else if (stp_req->pio_len < len) { in sci_stp_request_pio_data_out_transmit_data()
1381 sci_stp_request_pio_data_out_trasmit_data_frame(ireq, stp_req->pio_len); in sci_stp_request_pio_data_out_transmit_data()
1384 offset += stp_req->pio_len; in sci_stp_request_pio_data_out_transmit_data()
1385 sgl->address_lower += stp_req->pio_len; in sci_stp_request_pio_data_out_transmit_data()
1386 stp_req->pio_len = 0; in sci_stp_request_pio_data_out_transmit_data()
1389 stp_req->sgl.offset = offset; in sci_stp_request_pio_data_out_transmit_data()
1419 if (task->num_scatter > 0) { in sci_stp_request_pio_data_in_copy_data_buffer()
1420 sg = task->scatter; in sci_stp_request_pio_data_in_copy_data_buffer()
1427 memcpy(kaddr + sg->offset, src_addr, copy_len); in sci_stp_request_pio_data_in_copy_data_buffer()
1429 total_len -= copy_len; in sci_stp_request_pio_data_in_copy_data_buffer()
1434 BUG_ON(task->total_xfer_len < total_len); in sci_stp_request_pio_data_in_copy_data_buffer()
1435 memcpy(task->scatter, src_addr, total_len); in sci_stp_request_pio_data_in_copy_data_buffer()
1457 if (stp_req->pio_len < SCU_MAX_FRAME_BUFFER_SIZE) { in sci_stp_request_pio_data_in_copy_data()
1459 stp_req, data_buffer, stp_req->pio_len); in sci_stp_request_pio_data_in_copy_data()
1462 stp_req->pio_len = 0; in sci_stp_request_pio_data_in_copy_data()
1469 stp_req->pio_len -= SCU_MAX_FRAME_BUFFER_SIZE; in sci_stp_request_pio_data_in_copy_data()
1481 ireq->scu_status = SCU_TASK_DONE_GOOD; in stp_request_pio_await_h2d_completion_tc_event()
1482 ireq->sci_status = SCI_SUCCESS; in stp_request_pio_await_h2d_completion_tc_event()
1483 sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); in stp_request_pio_await_h2d_completion_tc_event()
1491 ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); in stp_request_pio_await_h2d_completion_tc_event()
1492 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in stp_request_pio_await_h2d_completion_tc_event()
1493 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in stp_request_pio_await_h2d_completion_tc_event()
1506 struct isci_stp_request *stp_req = &ireq->stp.req; in pio_data_out_tx_done_tc_event()
1511 if (stp_req->pio_len != 0) { in pio_data_out_tx_done_tc_event()
1514 if (stp_req->pio_len == 0) in pio_data_out_tx_done_tc_event()
1517 } else if (stp_req->pio_len == 0) { in pio_data_out_tx_done_tc_event()
1530 sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); in pio_data_out_tx_done_tc_event()
1540 ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); in pio_data_out_tx_done_tc_event()
1541 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in pio_data_out_tx_done_tc_event()
1542 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in pio_data_out_tx_done_tc_event()
1552 struct isci_host *ihost = ireq->owning_controller; in sci_stp_request_udma_general_frame_handler()
1557 status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, in sci_stp_request_udma_general_frame_handler()
1562 (frame_header->fis_type == FIS_REGD2H)) { in sci_stp_request_udma_general_frame_handler()
1563 sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, in sci_stp_request_udma_general_frame_handler()
1567 sci_controller_copy_sata_response(&ireq->stp.rsp, in sci_stp_request_udma_general_frame_handler()
1580 struct isci_host *ihost = ireq->owning_controller; in process_unsolicited_fis()
1585 status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, in process_unsolicited_fis()
1592 if (frame_header->fis_type != FIS_REGD2H) { in process_unsolicited_fis()
1593 dev_err(&ireq->isci_host->pdev->dev, in process_unsolicited_fis()
1595 __func__, frame_header->fis_type); in process_unsolicited_fis()
1599 sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, in process_unsolicited_fis()
1603 sci_controller_copy_sata_response(&ireq->stp.rsp, in process_unsolicited_fis()
1622 if (ireq->stp.rsp.status & ATA_ERR) in atapi_d2h_reg_frame_handler()
1629 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in atapi_d2h_reg_frame_handler()
1630 ireq->sci_status = status; in atapi_d2h_reg_frame_handler()
1632 ireq->scu_status = SCU_TASK_DONE_GOOD; in atapi_d2h_reg_frame_handler()
1633 ireq->sci_status = SCI_SUCCESS; in atapi_d2h_reg_frame_handler()
1636 /* the d2h ufi is the end of non-data commands */ in atapi_d2h_reg_frame_handler()
1637 if (task->data_dir == DMA_NONE) in atapi_d2h_reg_frame_handler()
1638 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in atapi_d2h_reg_frame_handler()
1645 struct ata_device *dev = sas_to_ata_dev(ireq->target_device->domain_dev); in scu_atapi_reconstruct_raw_frame_task_context()
1646 void *atapi_cdb = ireq->ttype_ptr.io_task_ptr->ata_task.atapi_packet; in scu_atapi_reconstruct_raw_frame_task_context()
1647 struct scu_task_context *task_context = ireq->tc; in scu_atapi_reconstruct_raw_frame_task_context()
1653 memset(&ireq->stp.cmd, 0, sizeof(struct host_to_dev_fis)); in scu_atapi_reconstruct_raw_frame_task_context()
1654 memcpy(((u8 *)&ireq->stp.cmd + sizeof(u32)), atapi_cdb, ATAPI_CDB_LEN); in scu_atapi_reconstruct_raw_frame_task_context()
1655 memset(&(task_context->type.stp), 0, sizeof(struct stp_task_context)); in scu_atapi_reconstruct_raw_frame_task_context()
1656 task_context->type.stp.fis_type = FIS_DATA; in scu_atapi_reconstruct_raw_frame_task_context()
1657 task_context->transfer_length_bytes = dev->cdb_len; in scu_atapi_reconstruct_raw_frame_task_context()
1662 struct ata_device *dev = sas_to_ata_dev(ireq->target_device->domain_dev); in scu_atapi_construct_task_context()
1664 struct scu_task_context *task_context = ireq->tc; in scu_atapi_construct_task_context()
1665 int cdb_len = dev->cdb_len; in scu_atapi_construct_task_context()
1670 if (task->data_dir == DMA_TO_DEVICE) { in scu_atapi_construct_task_context()
1671 task_context->task_type = SCU_TASK_TYPE_PACKET_DMA_OUT; in scu_atapi_construct_task_context()
1672 task_context->sata_direction = 0; in scu_atapi_construct_task_context()
1675 task_context->task_type = SCU_TASK_TYPE_PACKET_DMA_IN; in scu_atapi_construct_task_context()
1676 task_context->sata_direction = 1; in scu_atapi_construct_task_context()
1679 memset(&task_context->type.stp, 0, sizeof(task_context->type.stp)); in scu_atapi_construct_task_context()
1680 task_context->type.stp.fis_type = FIS_DATA; in scu_atapi_construct_task_context()
1682 memset(&ireq->stp.cmd, 0, sizeof(ireq->stp.cmd)); in scu_atapi_construct_task_context()
1683 memcpy(&ireq->stp.cmd.lbal, task->ata_task.atapi_packet, cdb_len); in scu_atapi_construct_task_context()
1684 task_context->ssp_command_iu_length = cdb_len / sizeof(u32); in scu_atapi_construct_task_context()
1687 task_context->task_phase = 0x1; in scu_atapi_construct_task_context()
1690 task_context->stp_retry_count = 0; in scu_atapi_construct_task_context()
1693 task_context->transfer_length_bytes = task->total_xfer_len; in scu_atapi_construct_task_context()
1703 struct isci_host *ihost = ireq->owning_controller; in sci_io_request_frame_handler()
1704 struct isci_stp_request *stp_req = &ireq->stp.req; in sci_io_request_frame_handler()
1709 state = ireq->sm.current_state_id; in sci_io_request_frame_handler()
1715 sci_unsolicited_frame_control_get_header(&ihost->uf_control, in sci_io_request_frame_handler()
1726 sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, in sci_io_request_frame_handler()
1730 sci_swab32_cpy(&ireq->ssp.rsp, resp_iu, word_cnt); in sci_io_request_frame_handler()
1732 resp_iu = &ireq->ssp.rsp; in sci_io_request_frame_handler()
1734 if (resp_iu->datapres == SAS_DATAPRES_RESPONSE_DATA || in sci_io_request_frame_handler()
1735 resp_iu->datapres == SAS_DATAPRES_SENSE_DATA) { in sci_io_request_frame_handler()
1736 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in sci_io_request_frame_handler()
1737 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in sci_io_request_frame_handler()
1739 ireq->scu_status = SCU_TASK_DONE_GOOD; in sci_io_request_frame_handler()
1740 ireq->sci_status = SCI_SUCCESS; in sci_io_request_frame_handler()
1744 dev_err(&ihost->pdev->dev, in sci_io_request_frame_handler()
1761 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in sci_io_request_frame_handler()
1767 struct scatterlist *sg = &task->smp_task.smp_resp; in sci_io_request_frame_handler()
1771 sci_unsolicited_frame_control_get_header(&ihost->uf_control, in sci_io_request_frame_handler()
1775 rsp = kaddr + sg->offset; in sci_io_request_frame_handler()
1781 sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, in sci_io_request_frame_handler()
1785 word_cnt = (sg->length/4)-1; in sci_io_request_frame_handler()
1791 ireq->scu_status = SCU_TASK_DONE_GOOD; in sci_io_request_frame_handler()
1792 ireq->sci_status = SCI_SUCCESS; in sci_io_request_frame_handler()
1793 sci_change_state(&ireq->sm, SCI_REQ_SMP_WAIT_TC_COMP); in sci_io_request_frame_handler()
1799 dev_err(&ihost->pdev->dev, in sci_io_request_frame_handler()
1807 ireq->scu_status = SCU_TASK_DONE_SMP_FRM_TYPE_ERR; in sci_io_request_frame_handler()
1808 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in sci_io_request_frame_handler()
1809 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in sci_io_request_frame_handler()
1829 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in sci_io_request_frame_handler()
1830 ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; in sci_io_request_frame_handler()
1831 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in sci_io_request_frame_handler()
1838 status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, in sci_io_request_frame_handler()
1843 dev_err(&ihost->pdev->dev, in sci_io_request_frame_handler()
1854 switch (frame_header->fis_type) { in sci_io_request_frame_handler()
1856 sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, in sci_io_request_frame_handler()
1860 sci_controller_copy_sata_response(&ireq->stp.rsp, in sci_io_request_frame_handler()
1865 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in sci_io_request_frame_handler()
1866 ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; in sci_io_request_frame_handler()
1870 dev_warn(&ihost->pdev->dev, in sci_io_request_frame_handler()
1875 ireq->scu_status = SCU_TASK_DONE_UNEXP_FIS; in sci_io_request_frame_handler()
1876 ireq->sci_status = SCI_FAILURE_PROTOCOL_VIOLATION; in sci_io_request_frame_handler()
1880 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in sci_io_request_frame_handler()
1893 status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, in sci_io_request_frame_handler()
1898 dev_err(&ihost->pdev->dev, in sci_io_request_frame_handler()
1905 switch (frame_header->fis_type) { in sci_io_request_frame_handler()
1908 sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, in sci_io_request_frame_handler()
1919 stp_req->pio_len = frame_buffer[3] & 0xffff; in sci_io_request_frame_handler()
1922 stp_req->status = (frame_buffer[2] >> 24) & 0xff; in sci_io_request_frame_handler()
1924 sci_controller_copy_sata_response(&ireq->stp.rsp, in sci_io_request_frame_handler()
1928 ireq->stp.rsp.status = stp_req->status; in sci_io_request_frame_handler()
1931 * request was PIO Data-in or Data out in sci_io_request_frame_handler()
1933 if (task->data_dir == DMA_FROM_DEVICE) { in sci_io_request_frame_handler()
1934 sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_DATA_IN); in sci_io_request_frame_handler()
1935 } else if (task->data_dir == DMA_TO_DEVICE) { in sci_io_request_frame_handler()
1940 sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_DATA_OUT); in sci_io_request_frame_handler()
1945 sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); in sci_io_request_frame_handler()
1949 if (frame_header->status & ATA_BUSY) { in sci_io_request_frame_handler()
1955 dev_dbg(&ihost->pdev->dev, in sci_io_request_frame_handler()
1961 frame_header->status); in sci_io_request_frame_handler()
1965 sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, in sci_io_request_frame_handler()
1969 sci_controller_copy_sata_response(&ireq->stp.rsp, in sci_io_request_frame_handler()
1973 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in sci_io_request_frame_handler()
1974 ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; in sci_io_request_frame_handler()
1975 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in sci_io_request_frame_handler()
1993 status = sci_unsolicited_frame_control_get_header(&ihost->uf_control, in sci_io_request_frame_handler()
1998 dev_err(&ihost->pdev->dev, in sci_io_request_frame_handler()
2008 if (frame_header->fis_type != FIS_DATA) { in sci_io_request_frame_handler()
2009 dev_err(&ihost->pdev->dev, in sci_io_request_frame_handler()
2016 frame_header->fis_type); in sci_io_request_frame_handler()
2018 ireq->scu_status = SCU_TASK_DONE_GOOD; in sci_io_request_frame_handler()
2019 ireq->sci_status = SCI_FAILURE_IO_REQUIRES_SCSI_ABORT; in sci_io_request_frame_handler()
2020 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in sci_io_request_frame_handler()
2027 if (stp_req->sgl.index < 0) { in sci_io_request_frame_handler()
2028 ireq->saved_rx_frame_index = frame_index; in sci_io_request_frame_handler()
2029 stp_req->pio_len = 0; in sci_io_request_frame_handler()
2031 sci_unsolicited_frame_control_get_buffer(&ihost->uf_control, in sci_io_request_frame_handler()
2045 if (status != SCI_SUCCESS || stp_req->pio_len != 0) in sci_io_request_frame_handler()
2048 if ((stp_req->status & ATA_BUSY) == 0) { in sci_io_request_frame_handler()
2049 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in sci_io_request_frame_handler()
2050 ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; in sci_io_request_frame_handler()
2051 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in sci_io_request_frame_handler()
2053 sci_change_state(&ireq->sm, SCI_REQ_STP_PIO_WAIT_FRAME); in sci_io_request_frame_handler()
2062 ireq->target_device->working_request = ireq; in sci_io_request_frame_handler()
2063 if (task->data_dir == DMA_NONE) { in sci_io_request_frame_handler()
2064 sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_TC_COMP); in sci_io_request_frame_handler()
2067 sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_D2H); in sci_io_request_frame_handler()
2085 dev_warn(&ihost->pdev->dev, in sci_io_request_frame_handler()
2102 ireq->scu_status = SCU_TASK_DONE_GOOD; in stp_request_udma_await_tc_event()
2103 ireq->sci_status = SCI_SUCCESS; in stp_request_udma_await_tc_event()
2104 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in stp_request_udma_await_tc_event()
2112 if (ireq->stp.rsp.fis_type == FIS_REGD2H) { in stp_request_udma_await_tc_event()
2113 sci_remote_device_suspend(ireq->target_device, in stp_request_udma_await_tc_event()
2116 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in stp_request_udma_await_tc_event()
2117 ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; in stp_request_udma_await_tc_event()
2118 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in stp_request_udma_await_tc_event()
2125 sci_change_state(&ireq->sm, SCI_REQ_STP_UDMA_WAIT_D2H); in stp_request_udma_await_tc_event()
2133 * - this comes only for B0 in stp_request_udma_await_tc_event()
2137 ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); in stp_request_udma_await_tc_event()
2138 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in stp_request_udma_await_tc_event()
2139 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in stp_request_udma_await_tc_event()
2151 ireq->scu_status = SCU_TASK_DONE_GOOD; in atapi_raw_completion()
2152 ireq->sci_status = SCI_SUCCESS; in atapi_raw_completion()
2153 sci_change_state(&ireq->sm, next); in atapi_raw_completion()
2160 ireq->scu_status = SCU_NORMALIZE_COMPLETION_STATUS(completion_code); in atapi_raw_completion()
2161 ireq->sci_status = SCI_FAILURE_CONTROLLER_SPECIFIC_IO_ERR; in atapi_raw_completion()
2163 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in atapi_raw_completion()
2173 struct isci_remote_device *idev = ireq->target_device; in atapi_data_tc_completion_handler()
2174 struct dev_to_host_fis *d2h = &ireq->stp.rsp; in atapi_data_tc_completion_handler()
2179 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in atapi_data_tc_completion_handler()
2185 /* likely non-error data underrun, workaround missing in atapi_data_tc_completion_handler()
2188 if (d2h->fis_type != FIS_REGD2H) { in atapi_data_tc_completion_handler()
2189 d2h->fis_type = FIS_REGD2H; in atapi_data_tc_completion_handler()
2190 d2h->flags = (1 << 6); in atapi_data_tc_completion_handler()
2191 d2h->status = 0x50; in atapi_data_tc_completion_handler()
2192 d2h->error = 0; in atapi_data_tc_completion_handler()
2193 d2h->lbal = 0; in atapi_data_tc_completion_handler()
2194 d2h->byte_count_low = len & 0xff; in atapi_data_tc_completion_handler()
2195 d2h->byte_count_high = len >> 8; in atapi_data_tc_completion_handler()
2196 d2h->device = 0xa0; in atapi_data_tc_completion_handler()
2197 d2h->lbal_exp = 0; in atapi_data_tc_completion_handler()
2198 d2h->lbam_exp = 0; in atapi_data_tc_completion_handler()
2199 d2h->lbah_exp = 0; in atapi_data_tc_completion_handler()
2200 d2h->_r_a = 0; in atapi_data_tc_completion_handler()
2201 d2h->sector_count = 0x3; in atapi_data_tc_completion_handler()
2202 d2h->sector_count_exp = 0; in atapi_data_tc_completion_handler()
2203 d2h->_r_b = 0; in atapi_data_tc_completion_handler()
2204 d2h->_r_c = 0; in atapi_data_tc_completion_handler()
2205 d2h->_r_d = 0; in atapi_data_tc_completion_handler()
2208 ireq->scu_status = SCU_TASK_DONE_GOOD; in atapi_data_tc_completion_handler()
2209 ireq->sci_status = SCI_SUCCESS_IO_DONE_EARLY; in atapi_data_tc_completion_handler()
2210 status = ireq->sci_status; in atapi_data_tc_completion_handler()
2215 sci_change_state(&idev->sm, SCI_STP_DEV_ATAPI_ERROR); in atapi_data_tc_completion_handler()
2222 ireq->scu_status = SCU_TASK_DONE_GOOD; in atapi_data_tc_completion_handler()
2223 ireq->sci_status = SCI_SUCCESS; in atapi_data_tc_completion_handler()
2224 sci_change_state(&ireq->sm, SCI_REQ_COMPLETED); in atapi_data_tc_completion_handler()
2228 if (d2h->fis_type == FIS_REGD2H) { in atapi_data_tc_completion_handler()
2230 status = ireq->sci_status; in atapi_data_tc_completion_handler()
2231 sci_change_state(&idev->sm, SCI_STP_DEV_ATAPI_ERROR); in atapi_data_tc_completion_handler()
2233 /* If receiving any non-success TC status, no UF in atapi_data_tc_completion_handler()
2239 ireq->scu_status = SCU_TASK_DONE_CHECK_RESPONSE; in atapi_data_tc_completion_handler()
2240 ireq->sci_status = SCI_FAILURE_IO_RESPONSE_VALID; in atapi_data_tc_completion_handler()
2242 sci_change_state(&ireq->sm, SCI_REQ_ATAPI_WAIT_D2H); in atapi_data_tc_completion_handler()
2345 switch (ireq->protocol) { in sci_request_handle_suspending_completions()
2366 dev_warn(&ireq->isci_host->pdev->dev, in sci_request_handle_suspending_completions()
2375 &ireq->target_device->rnc, in sci_request_handle_suspending_completions()
2387 struct isci_host *ihost = ireq->owning_controller; in sci_io_request_tc_completion()
2389 state = ireq->sm.current_state_id; in sci_io_request_tc_completion()
2441 dev_warn(&ihost->pdev->dev, "%s: %x in wrong state %s\n", in sci_io_request_tc_completion()
2448 * isci_request_process_response_iu() - This function sets the status and
2464 "resp_iu->status = 0x%x,\nresp_iu->datapres = %d " in isci_request_process_response_iu()
2465 "resp_iu->response_data_len = %x, " in isci_request_process_response_iu()
2466 "resp_iu->sense_data_len = %x\nresponse data: ", in isci_request_process_response_iu()
2469 resp_iu->status, in isci_request_process_response_iu()
2470 resp_iu->datapres, in isci_request_process_response_iu()
2471 resp_iu->response_data_len, in isci_request_process_response_iu()
2472 resp_iu->sense_data_len); in isci_request_process_response_iu()
2474 task->task_status.stat = resp_iu->status; in isci_request_process_response_iu()
2481 * isci_request_set_open_reject_status() - This function prepares the I/O
2488 * abandon-class reject.
2500 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_set_open_reject_status()
2503 task->task_status.open_rej_reason = open_rej_reason; in isci_request_set_open_reject_status()
2507 * isci_request_handle_controller_specific_errors() - This function decodes
2508 * controller-specific I/O completion error conditions.
2526 cstatus = request->scu_status; in isci_request_handle_controller_specific_errors()
2528 dev_dbg(&request->isci_host->pdev->dev, in isci_request_handle_controller_specific_errors()
2530 "- controller status = 0x%x\n", in isci_request_handle_controller_specific_errors()
2533 /* Decode the controller-specific errors; most in isci_request_handle_controller_specific_errors()
2541 * a controller-specific completion code; these are left in isci_request_handle_controller_specific_errors()
2549 if (task->task_proto == SAS_PROTOCOL_SMP) { in isci_request_handle_controller_specific_errors()
2562 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_handle_controller_specific_errors()
2572 clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_handle_controller_specific_errors()
2582 case SCU_TASK_DONE_VIIT_ENTRY_NV: /* TODO - conditions? */ in isci_request_handle_controller_specific_errors()
2583 case SCU_TASK_DONE_IIT_ENTRY_NV: /* TODO - conditions? */ in isci_request_handle_controller_specific_errors()
2584 case SCU_TASK_DONE_RNCNV_OUTBOUND: /* TODO - conditions? */ in isci_request_handle_controller_specific_errors()
2600 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_handle_controller_specific_errors()
2605 * abandon-class codes; all others are automatically retried in the SCU. in isci_request_handle_controller_specific_errors()
2616 /* Note - the return of AB0 will change when in isci_request_handle_controller_specific_errors()
2702 if (task->task_proto == SAS_PROTOCOL_SMP) in isci_request_handle_controller_specific_errors()
2703 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_handle_controller_specific_errors()
2705 clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_handle_controller_specific_errors()
2712 struct task_status_struct *ts = &task->task_status; in isci_process_stp_response()
2713 struct ata_task_resp *resp = (void *)&ts->buf[0]; in isci_process_stp_response()
2715 resp->frame_len = sizeof(*fis); in isci_process_stp_response()
2716 memcpy(resp->ending_fis, fis, sizeof(*fis)); in isci_process_stp_response()
2717 ts->buf_valid_size = sizeof(*resp); in isci_process_stp_response()
2720 if (ac_err_mask(fis->status)) in isci_process_stp_response()
2721 ts->stat = SAS_PROTO_RESPONSE; in isci_process_stp_response()
2723 ts->stat = SAS_SAM_STAT_GOOD; in isci_process_stp_response()
2725 ts->resp = SAS_TASK_COMPLETE; in isci_process_stp_response()
2735 struct isci_remote_device *idev = request->target_device; in isci_request_io_request_complete()
2739 dev_dbg(&ihost->pdev->dev, in isci_request_io_request_complete()
2741 "task->data_dir = %d completion_status = 0x%x\n", in isci_request_io_request_complete()
2742 __func__, request, task, task->data_dir, completion_status); in isci_request_io_request_complete()
2750 dev_dbg(&ihost->pdev->dev, in isci_request_io_request_complete()
2754 if (sas_protocol_ata(task->task_proto)) { in isci_request_io_request_complete()
2755 isci_process_stp_response(task, &request->stp.rsp); in isci_request_io_request_complete()
2756 } else if (SAS_PROTOCOL_SSP == task->task_proto) { in isci_request_io_request_complete()
2759 resp_iu = &request->ssp.rsp; in isci_request_io_request_complete()
2761 &ihost->pdev->dev); in isci_request_io_request_complete()
2763 } else if (SAS_PROTOCOL_SMP == task->task_proto) { in isci_request_io_request_complete()
2765 dev_err(&ihost->pdev->dev, in isci_request_io_request_complete()
2771 dev_err(&ihost->pdev->dev, in isci_request_io_request_complete()
2777 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_io_request_complete()
2778 response = task->task_status.resp; in isci_request_io_request_complete()
2779 status = task->task_status.stat; in isci_request_io_request_complete()
2787 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_io_request_complete()
2797 task->task_status.residual in isci_request_io_request_complete()
2798 = task->total_xfer_len - transferred_length; in isci_request_io_request_complete()
2803 if (task->task_status.residual != 0) in isci_request_io_request_complete()
2806 dev_dbg(&ihost->pdev->dev, in isci_request_io_request_complete()
2811 dev_dbg(&ihost->pdev->dev, "%s: SCI_IO_SUCCESS\n", in isci_request_io_request_complete()
2817 dev_dbg(&ihost->pdev->dev, in isci_request_io_request_complete()
2822 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_io_request_complete()
2850 spin_lock_irqsave(&task->task_state_lock, task_flags); in isci_request_io_request_complete()
2851 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; in isci_request_io_request_complete()
2852 spin_unlock_irqrestore(&task->task_state_lock, task_flags); in isci_request_io_request_complete()
2858 clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_io_request_complete()
2870 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_io_request_complete()
2876 dev_dbg(&ihost->pdev->dev, in isci_request_io_request_complete()
2877 "%s: invalid completion code: 0x%x - " in isci_request_io_request_complete()
2892 if (SAS_PROTOCOL_SMP == task->task_proto) in isci_request_io_request_complete()
2893 set_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_io_request_complete()
2895 clear_bit(IREQ_COMPLETE_IN_TARGET, &request->flags); in isci_request_io_request_complete()
2899 switch (task->task_proto) { in isci_request_io_request_complete()
2901 if (task->data_dir == DMA_NONE) in isci_request_io_request_complete()
2903 if (task->num_scatter == 0) in isci_request_io_request_complete()
2905 dma_unmap_single(&ihost->pdev->dev, in isci_request_io_request_complete()
2906 request->zero_scatter_daddr, in isci_request_io_request_complete()
2907 task->total_xfer_len, task->data_dir); in isci_request_io_request_complete()
2909 dma_unmap_sg(&ihost->pdev->dev, task->scatter, in isci_request_io_request_complete()
2910 request->num_sg_entries, task->data_dir); in isci_request_io_request_complete()
2913 struct scatterlist *sg = &task->smp_task.smp_req; in isci_request_io_request_complete()
2917 dma_unmap_sg(&ihost->pdev->dev, sg, 1, DMA_TO_DEVICE); in isci_request_io_request_complete()
2919 /* need to swab it back in case the command buffer is re-used */ in isci_request_io_request_complete()
2921 smp_req = kaddr + sg->offset; in isci_request_io_request_complete()
2922 sci_swab32_cpy(smp_req, smp_req, sg->length / sizeof(u32)); in isci_request_io_request_complete()
2930 spin_lock_irqsave(&task->task_state_lock, task_flags); in isci_request_io_request_complete()
2932 task->task_status.resp = response; in isci_request_io_request_complete()
2933 task->task_status.stat = status; in isci_request_io_request_complete()
2935 if (test_bit(IREQ_COMPLETE_IN_TARGET, &request->flags)) { in isci_request_io_request_complete()
2937 task->task_state_flags |= SAS_TASK_STATE_DONE; in isci_request_io_request_complete()
2938 task->task_state_flags &= ~SAS_TASK_STATE_PENDING; in isci_request_io_request_complete()
2940 spin_unlock_irqrestore(&task->task_state_lock, task_flags); in isci_request_io_request_complete()
2943 sci_controller_complete_io(ihost, request->target_device, request); in isci_request_io_request_complete()
2949 set_bit(IREQ_TERMINATED, &request->flags); in isci_request_io_request_complete()
2957 struct domain_device *dev = ireq->target_device->domain_dev; in sci_request_started_state_enter()
2964 task = (test_bit(IREQ_TMF, &ireq->flags)) ? NULL : isci_request_access_task(ireq); in sci_request_started_state_enter()
2969 if (!task && dev->dev_type == SAS_END_DEVICE) { in sci_request_started_state_enter()
2971 } else if (task && task->task_proto == SAS_PROTOCOL_SMP) { in sci_request_started_state_enter()
2973 } else if (task && sas_protocol_ata(task->task_proto) && in sci_request_started_state_enter()
2974 !task->ata_task.use_ncq) { in sci_request_started_state_enter()
2975 if (dev->sata_dev.class == ATA_DEV_ATAPI && in sci_request_started_state_enter()
2976 task->ata_task.fis.command == ATA_CMD_PACKET) { in sci_request_started_state_enter()
2978 } else if (task->data_dir == DMA_NONE) { in sci_request_started_state_enter()
2980 } else if (task->ata_task.dma_xfer) { in sci_request_started_state_enter()
2995 struct isci_host *ihost = ireq->owning_controller; in sci_request_completed_state_enter()
2998 if (!test_bit(IREQ_TMF, &ireq->flags)) in sci_request_completed_state_enter()
3000 ireq->sci_status); in sci_request_completed_state_enter()
3002 isci_task_request_complete(ihost, ireq, ireq->sci_status); in sci_request_completed_state_enter()
3010 ireq->tc->abort = 1; in sci_request_aborting_state_enter()
3017 ireq->target_device->working_request = ireq; in sci_stp_request_started_non_data_await_h2d_completion_enter()
3024 ireq->target_device->working_request = ireq; in sci_stp_request_started_pio_await_h2d_completion_enter()
3067 sci_init_sm(&ireq->sm, sci_request_state_table, SCI_REQ_INIT); in sci_general_request_construct()
3069 ireq->target_device = idev; in sci_general_request_construct()
3070 ireq->protocol = SAS_PROTOCOL_NONE; in sci_general_request_construct()
3071 ireq->saved_rx_frame_index = SCU_INVALID_FRAME_INDEX; in sci_general_request_construct()
3073 ireq->sci_status = SCI_SUCCESS; in sci_general_request_construct()
3074 ireq->scu_status = 0; in sci_general_request_construct()
3075 ireq->post_context = 0xFFFFFFFF; in sci_general_request_construct()
3083 struct domain_device *dev = idev->domain_dev; in sci_io_request_construct()
3086 /* Build the common part of the request */ in sci_io_request_construct()
3089 if (idev->rnc.remote_node_index == SCIC_SDS_REMOTE_NODE_CONTEXT_INVALID_INDEX) in sci_io_request_construct()
3092 if (dev->dev_type == SAS_END_DEVICE) in sci_io_request_construct()
3095 memset(&ireq->stp.cmd, 0, sizeof(ireq->stp.cmd)); in sci_io_request_construct()
3096 else if (dev_is_expander(dev->dev_type)) in sci_io_request_construct()
3101 memset(ireq->tc, 0, offsetof(struct scu_task_context, sgl_pair_ab)); in sci_io_request_construct()
3110 struct domain_device *dev = idev->domain_dev; in sci_task_request_construct()
3113 /* Build the common part of the request */ in sci_task_request_construct()
3116 if (dev->dev_type == SAS_END_DEVICE || dev_is_sata(dev)) { in sci_task_request_construct()
3117 set_bit(IREQ_TMF, &ireq->flags); in sci_task_request_construct()
3118 memset(ireq->tc, 0, sizeof(struct scu_task_context)); in sci_task_request_construct()
3122 ireq->protocol = SAS_PROTOCOL_STP; in sci_task_request_construct()
3124 ireq->protocol = SAS_PROTOCOL_SSP; in sci_task_request_construct()
3136 dev_dbg(&request->isci_host->pdev->dev, in isci_request_ssp_request_construct()
3147 struct host_to_dev_fis *fis = &ireq->stp.cmd; in isci_request_stp_request_construct()
3148 struct ata_queued_cmd *qc = task->uldd_task; in isci_request_stp_request_construct()
3151 dev_dbg(&ireq->isci_host->pdev->dev, in isci_request_stp_request_construct()
3156 memcpy(fis, &task->ata_task.fis, sizeof(struct host_to_dev_fis)); in isci_request_stp_request_construct()
3157 if (!task->ata_task.device_control_reg_update) in isci_request_stp_request_construct()
3158 fis->flags |= 0x80; in isci_request_stp_request_construct()
3159 fis->flags &= 0xF0; in isci_request_stp_request_construct()
3163 if (qc && (qc->tf.command == ATA_CMD_FPDMA_WRITE || in isci_request_stp_request_construct()
3164 qc->tf.command == ATA_CMD_FPDMA_READ || in isci_request_stp_request_construct()
3165 qc->tf.command == ATA_CMD_FPDMA_RECV || in isci_request_stp_request_construct()
3166 qc->tf.command == ATA_CMD_FPDMA_SEND || in isci_request_stp_request_construct()
3167 qc->tf.command == ATA_CMD_NCQ_NON_DATA)) { in isci_request_stp_request_construct()
3168 fis->sector_count = qc->tag << 3; in isci_request_stp_request_construct()
3169 ireq->tc->type.stp.ncq_tag = qc->tag; in isci_request_stp_request_construct()
3180 struct scatterlist *sg = &task->smp_task.smp_req; in sci_io_request_construct_smp()
3190 smp_req = kaddr + sg->offset; in sci_io_request_construct_smp()
3194 * a non-zero default length. in sci_io_request_construct_smp()
3196 if (smp_req->req_len == 0) { in sci_io_request_construct_smp()
3197 switch (smp_req->func) { in sci_io_request_construct_smp()
3202 smp_req->req_len = 2; in sci_io_request_construct_smp()
3207 smp_req->req_len = 9; in sci_io_request_construct_smp()
3209 /* Default - zero is a valid default for 2.0. */ in sci_io_request_construct_smp()
3212 req_len = smp_req->req_len; in sci_io_request_construct_smp()
3213 sci_swab32_cpy(smp_req, smp_req, sg->length / sizeof(u32)); in sci_io_request_construct_smp()
3220 ireq->protocol = SAS_PROTOCOL_SMP; in sci_io_request_construct_smp()
3224 task_context = ireq->tc; in sci_io_request_construct_smp()
3226 idev = ireq->target_device; in sci_io_request_construct_smp()
3227 iport = idev->owning_port; in sci_io_request_construct_smp()
3233 task_context->priority = 0; in sci_io_request_construct_smp()
3234 task_context->initiator_request = 1; in sci_io_request_construct_smp()
3235 task_context->connection_rate = idev->connection_rate; in sci_io_request_construct_smp()
3236 task_context->protocol_engine_index = ISCI_PEG; in sci_io_request_construct_smp()
3237 task_context->logical_port_index = iport->physical_port_index; in sci_io_request_construct_smp()
3238 task_context->protocol_type = SCU_TASK_CONTEXT_PROTOCOL_SMP; in sci_io_request_construct_smp()
3239 task_context->abort = 0; in sci_io_request_construct_smp()
3240 task_context->valid = SCU_TASK_CONTEXT_VALID; in sci_io_request_construct_smp()
3241 task_context->context_type = SCU_TASK_CONTEXT_TYPE; in sci_io_request_construct_smp()
3244 task_context->remote_node_index = idev->rnc.remote_node_index; in sci_io_request_construct_smp()
3245 task_context->command_code = 0; in sci_io_request_construct_smp()
3246 task_context->task_type = SCU_TASK_TYPE_SMP_REQUEST; in sci_io_request_construct_smp()
3249 task_context->link_layer_control = 0; in sci_io_request_construct_smp()
3250 task_context->do_not_dma_ssp_good_response = 1; in sci_io_request_construct_smp()
3251 task_context->strict_ordering = 0; in sci_io_request_construct_smp()
3252 task_context->control_frame = 1; in sci_io_request_construct_smp()
3253 task_context->timeout_enable = 0; in sci_io_request_construct_smp()
3254 task_context->block_guard_enable = 0; in sci_io_request_construct_smp()
3257 task_context->address_modifier = 0; in sci_io_request_construct_smp()
3260 task_context->ssp_command_iu_length = req_len; in sci_io_request_construct_smp()
3263 task_context->transfer_length_bytes = 0; in sci_io_request_construct_smp()
3267 * since commandIU has been build by framework at this point, we just in sci_io_request_construct_smp()
3269 memcpy(&task_context->type.smp, &cmd, sizeof(u32)); in sci_io_request_construct_smp()
3274 * so that done code will be consistent." - Venki in sci_io_request_construct_smp()
3276 task_context->task_phase = 0; in sci_io_request_construct_smp()
3278 ireq->post_context = (SCU_CONTEXT_COMMAND_REQUEST_TYPE_POST_TC | in sci_io_request_construct_smp()
3280 (iport->physical_port_index << in sci_io_request_construct_smp()
3282 ISCI_TAG_TCI(ireq->io_tag)); in sci_io_request_construct_smp()
3287 task_context->command_iu_upper = upper_32_bits(sg_dma_address(sg)); in sci_io_request_construct_smp()
3288 task_context->command_iu_lower = lower_32_bits(sg_dma_address(sg) + sizeof(u32)); in sci_io_request_construct_smp()
3291 task_context->response_iu_upper = 0; in sci_io_request_construct_smp()
3292 task_context->response_iu_lower = 0; in sci_io_request_construct_smp()
3294 sci_change_state(&ireq->sm, SCI_REQ_CONSTRUCTED); in sci_io_request_construct_smp()
3300 * isci_smp_request_build() - This function builds the smp request.
3309 struct device *dev = &ireq->isci_host->pdev->dev; in isci_smp_request_build()
3314 dev_dbg(&ireq->isci_host->pdev->dev, in isci_smp_request_build()
3323 * isci_io_request_build() - This function builds the io request object.
3339 dev_dbg(&ihost->pdev->dev, in isci_io_request_build()
3345 task->num_scatter); in isci_io_request_build()
3351 if (task->num_scatter && in isci_io_request_build()
3352 !sas_protocol_ata(task->task_proto) && in isci_io_request_build()
3353 !(SAS_PROTOCOL_SMP & task->task_proto)) { in isci_io_request_build()
3355 request->num_sg_entries = dma_map_sg( in isci_io_request_build()
3356 &ihost->pdev->dev, in isci_io_request_build()
3357 task->scatter, in isci_io_request_build()
3358 task->num_scatter, in isci_io_request_build()
3359 task->data_dir in isci_io_request_build()
3362 if (request->num_sg_entries == 0) in isci_io_request_build()
3369 dev_dbg(&ihost->pdev->dev, in isci_io_request_build()
3375 switch (task->task_proto) { in isci_io_request_build()
3388 dev_dbg(&ihost->pdev->dev, in isci_io_request_build()
3400 ireq = ihost->reqs[ISCI_TAG_TCI(tag)]; in isci_request_from_tag()
3401 ireq->io_tag = tag; in isci_request_from_tag()
3402 ireq->io_request_completion = NULL; in isci_request_from_tag()
3403 ireq->flags = 0; in isci_request_from_tag()
3404 ireq->num_sg_entries = 0; in isci_request_from_tag()
3416 ireq->ttype_ptr.io_task_ptr = task; in isci_io_request_from_tag()
3417 clear_bit(IREQ_TMF, &ireq->flags); in isci_io_request_from_tag()
3418 task->lldd_task = ireq; in isci_io_request_from_tag()
3430 ireq->ttype_ptr.tmf_task_ptr = isci_tmf; in isci_tmf_request_from_tag()
3431 set_bit(IREQ_TMF, &ireq->flags); in isci_tmf_request_from_tag()
3445 dev_dbg(&ihost->pdev->dev, in isci_request_execute()
3446 "%s: request_construct failed - status = 0x%x\n", in isci_request_execute()
3452 spin_lock_irqsave(&ihost->scic_lock, flags); in isci_request_execute()
3454 if (test_bit(IDEV_IO_NCQERROR, &idev->flags)) { in isci_request_execute()
3462 * ireq->is_task_management_request is false). in isci_request_execute()
3478 dev_dbg(&ihost->pdev->dev, in isci_request_execute()
3481 spin_unlock_irqrestore(&ihost->scic_lock, flags); in isci_request_execute()
3492 set_bit(IREQ_TERMINATED, &ireq->flags); in isci_request_execute()
3494 spin_unlock_irqrestore(&ihost->scic_lock, flags); in isci_request_execute()
3502 spin_lock_irqsave(&task->task_state_lock, flags); in isci_request_execute()
3503 task->task_state_flags |= SAS_TASK_NEED_DEV_RESET; in isci_request_execute()
3504 spin_unlock_irqrestore(&task->task_state_lock, flags); in isci_request_execute()