Lines Matching refs:cmd
54 static void transport_complete_task_attr(struct se_cmd *cmd);
55 static void translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason);
56 static void transport_handle_queue_full(struct se_cmd *cmd,
696 static void target_remove_from_state_list(struct se_cmd *cmd) in target_remove_from_state_list() argument
698 struct se_device *dev = cmd->se_dev; in target_remove_from_state_list()
704 spin_lock_irqsave(&dev->queues[cmd->cpuid].lock, flags); in target_remove_from_state_list()
705 if (cmd->state_active) { in target_remove_from_state_list()
706 list_del(&cmd->state_list); in target_remove_from_state_list()
707 cmd->state_active = false; in target_remove_from_state_list()
709 spin_unlock_irqrestore(&dev->queues[cmd->cpuid].lock, flags); in target_remove_from_state_list()
712 static void target_remove_from_tmr_list(struct se_cmd *cmd) in target_remove_from_tmr_list() argument
717 if (cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) in target_remove_from_tmr_list()
718 dev = cmd->se_tmr_req->tmr_dev; in target_remove_from_tmr_list()
722 if (cmd->se_tmr_req->tmr_dev) in target_remove_from_tmr_list()
723 list_del_init(&cmd->se_tmr_req->tmr_list); in target_remove_from_tmr_list()
734 static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd) in transport_cmd_check_stop_to_fabric() argument
738 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_cmd_check_stop_to_fabric()
743 if (cmd->transport_state & CMD_T_STOP) { in transport_cmd_check_stop_to_fabric()
745 __func__, __LINE__, cmd->tag); in transport_cmd_check_stop_to_fabric()
747 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_cmd_check_stop_to_fabric()
749 complete_all(&cmd->t_transport_stop_comp); in transport_cmd_check_stop_to_fabric()
752 cmd->transport_state &= ~CMD_T_ACTIVE; in transport_cmd_check_stop_to_fabric()
753 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_cmd_check_stop_to_fabric()
762 return cmd->se_tfo->check_stop_free(cmd); in transport_cmd_check_stop_to_fabric()
765 static void transport_lun_remove_cmd(struct se_cmd *cmd) in transport_lun_remove_cmd() argument
767 struct se_lun *lun = cmd->se_lun; in transport_lun_remove_cmd()
772 target_remove_from_state_list(cmd); in transport_lun_remove_cmd()
773 target_remove_from_tmr_list(cmd); in transport_lun_remove_cmd()
775 if (cmpxchg(&cmd->lun_ref_active, true, false)) in transport_lun_remove_cmd()
781 cmd->se_lun = NULL; in transport_lun_remove_cmd()
786 struct se_cmd *cmd = container_of(work, struct se_cmd, work); in target_complete_failure_work() local
788 transport_generic_request_failure(cmd, cmd->sense_reason); in target_complete_failure_work()
795 static unsigned char *transport_get_sense_buffer(struct se_cmd *cmd) in transport_get_sense_buffer() argument
797 struct se_device *dev = cmd->se_dev; in transport_get_sense_buffer()
799 WARN_ON(!cmd->se_lun); in transport_get_sense_buffer()
804 if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) in transport_get_sense_buffer()
807 cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER; in transport_get_sense_buffer()
810 dev->se_hba->hba_id, dev->transport->name, cmd->scsi_status); in transport_get_sense_buffer()
811 return cmd->sense_buffer; in transport_get_sense_buffer()
814 void transport_copy_sense_to_cmd(struct se_cmd *cmd, unsigned char *sense) in transport_copy_sense_to_cmd() argument
819 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_copy_sense_to_cmd()
820 cmd_sense_buf = transport_get_sense_buffer(cmd); in transport_copy_sense_to_cmd()
822 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_copy_sense_to_cmd()
826 cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE; in transport_copy_sense_to_cmd()
827 memcpy(cmd_sense_buf, sense, cmd->scsi_sense_length); in transport_copy_sense_to_cmd()
828 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_copy_sense_to_cmd()
832 static void target_handle_abort(struct se_cmd *cmd) in target_handle_abort() argument
834 bool tas = cmd->transport_state & CMD_T_TAS; in target_handle_abort()
835 bool ack_kref = cmd->se_cmd_flags & SCF_ACK_KREF; in target_handle_abort()
838 pr_debug("tag %#llx: send_abort_response = %d\n", cmd->tag, tas); in target_handle_abort()
841 if (!(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) { in target_handle_abort()
842 cmd->scsi_status = SAM_STAT_TASK_ABORTED; in target_handle_abort()
844 cmd->t_task_cdb[0], cmd->tag); in target_handle_abort()
845 trace_target_cmd_complete(cmd); in target_handle_abort()
846 ret = cmd->se_tfo->queue_status(cmd); in target_handle_abort()
848 transport_handle_queue_full(cmd, cmd->se_dev, in target_handle_abort()
853 cmd->se_tmr_req->response = TMR_FUNCTION_REJECTED; in target_handle_abort()
854 cmd->se_tfo->queue_tm_rsp(cmd); in target_handle_abort()
861 cmd->se_tfo->aborted_task(cmd); in target_handle_abort()
863 WARN_ON_ONCE(target_put_sess_cmd(cmd) != 0); in target_handle_abort()
871 WARN_ON_ONCE(kref_read(&cmd->cmd_kref) == 0); in target_handle_abort()
873 transport_lun_remove_cmd(cmd); in target_handle_abort()
875 transport_cmd_check_stop_to_fabric(cmd); in target_handle_abort()
880 struct se_cmd *cmd = container_of(work, struct se_cmd, work); in target_abort_work() local
882 target_handle_abort(cmd); in target_abort_work()
885 static bool target_cmd_interrupted(struct se_cmd *cmd) in target_cmd_interrupted() argument
889 if (cmd->transport_state & CMD_T_ABORTED) { in target_cmd_interrupted()
890 if (cmd->transport_complete_callback) in target_cmd_interrupted()
891 cmd->transport_complete_callback(cmd, false, &post_ret); in target_cmd_interrupted()
892 INIT_WORK(&cmd->work, target_abort_work); in target_cmd_interrupted()
893 queue_work(target_completion_wq, &cmd->work); in target_cmd_interrupted()
895 } else if (cmd->transport_state & CMD_T_STOP) { in target_cmd_interrupted()
896 if (cmd->transport_complete_callback) in target_cmd_interrupted()
897 cmd->transport_complete_callback(cmd, false, &post_ret); in target_cmd_interrupted()
898 complete_all(&cmd->t_transport_stop_comp); in target_cmd_interrupted()
906 void target_complete_cmd_with_sense(struct se_cmd *cmd, u8 scsi_status, in target_complete_cmd_with_sense() argument
909 struct se_wwn *wwn = cmd->se_sess->se_tpg->se_tpg_wwn; in target_complete_cmd_with_sense()
913 if (target_cmd_interrupted(cmd)) in target_complete_cmd_with_sense()
916 cmd->scsi_status = scsi_status; in target_complete_cmd_with_sense()
917 cmd->sense_reason = sense_reason; in target_complete_cmd_with_sense()
919 spin_lock_irqsave(&cmd->t_state_lock, flags); in target_complete_cmd_with_sense()
920 switch (cmd->scsi_status) { in target_complete_cmd_with_sense()
922 if (cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) in target_complete_cmd_with_sense()
932 cmd->t_state = TRANSPORT_COMPLETE; in target_complete_cmd_with_sense()
933 cmd->transport_state |= (CMD_T_COMPLETE | CMD_T_ACTIVE); in target_complete_cmd_with_sense()
934 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in target_complete_cmd_with_sense()
936 INIT_WORK(&cmd->work, success ? target_complete_ok_work : in target_complete_cmd_with_sense()
940 cpu = cmd->cpuid; in target_complete_cmd_with_sense()
944 queue_work_on(cpu, target_completion_wq, &cmd->work); in target_complete_cmd_with_sense()
948 void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) in target_complete_cmd() argument
950 target_complete_cmd_with_sense(cmd, scsi_status, scsi_status ? in target_complete_cmd()
956 void target_set_cmd_data_length(struct se_cmd *cmd, int length) in target_set_cmd_data_length() argument
958 if (length < cmd->data_length) { in target_set_cmd_data_length()
959 if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { in target_set_cmd_data_length()
960 cmd->residual_count += cmd->data_length - length; in target_set_cmd_data_length()
962 cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT; in target_set_cmd_data_length()
963 cmd->residual_count = cmd->data_length - length; in target_set_cmd_data_length()
966 cmd->data_length = length; in target_set_cmd_data_length()
971 void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length) in target_complete_cmd_with_length() argument
974 cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) { in target_complete_cmd_with_length()
975 target_set_cmd_data_length(cmd, length); in target_complete_cmd_with_length()
978 target_complete_cmd(cmd, scsi_status); in target_complete_cmd_with_length()
982 static void target_add_to_state_list(struct se_cmd *cmd) in target_add_to_state_list() argument
984 struct se_device *dev = cmd->se_dev; in target_add_to_state_list()
987 spin_lock_irqsave(&dev->queues[cmd->cpuid].lock, flags); in target_add_to_state_list()
988 if (!cmd->state_active) { in target_add_to_state_list()
989 list_add_tail(&cmd->state_list, in target_add_to_state_list()
990 &dev->queues[cmd->cpuid].state_list); in target_add_to_state_list()
991 cmd->state_active = true; in target_add_to_state_list()
993 spin_unlock_irqrestore(&dev->queues[cmd->cpuid].lock, flags); in target_add_to_state_list()
999 static void transport_write_pending_qf(struct se_cmd *cmd);
1000 static void transport_complete_qf(struct se_cmd *cmd);
1007 struct se_cmd *cmd, *cmd_tmp; in target_qf_do_work() local
1013 list_for_each_entry_safe(cmd, cmd_tmp, &qf_cmd_list, se_qf_node) { in target_qf_do_work()
1014 list_del(&cmd->se_qf_node); in target_qf_do_work()
1018 " context: %s\n", cmd->se_tfo->fabric_name, cmd, in target_qf_do_work()
1019 (cmd->t_state == TRANSPORT_COMPLETE_QF_OK) ? "COMPLETE_OK" : in target_qf_do_work()
1020 (cmd->t_state == TRANSPORT_COMPLETE_QF_WP) ? "WRITE_PENDING" in target_qf_do_work()
1023 if (cmd->t_state == TRANSPORT_COMPLETE_QF_WP) in target_qf_do_work()
1024 transport_write_pending_qf(cmd); in target_qf_do_work()
1025 else if (cmd->t_state == TRANSPORT_COMPLETE_QF_OK || in target_qf_do_work()
1026 cmd->t_state == TRANSPORT_COMPLETE_QF_ERR) in target_qf_do_work()
1027 transport_complete_qf(cmd); in target_qf_do_work()
1031 unsigned char *transport_dump_cmd_direction(struct se_cmd *cmd) in transport_dump_cmd_direction() argument
1033 switch (cmd->data_direction) { in transport_dump_cmd_direction()
1324 target_check_max_data_sg_nents(struct se_cmd *cmd, struct se_device *dev, in target_check_max_data_sg_nents() argument
1329 if (!cmd->se_tfo->max_data_sg_nents) in target_check_max_data_sg_nents()
1337 mtl = (cmd->se_tfo->max_data_sg_nents * PAGE_SIZE); in target_check_max_data_sg_nents()
1338 if (cmd->data_length > mtl) { in target_check_max_data_sg_nents()
1350 if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { in target_check_max_data_sg_nents()
1351 cmd->residual_count = (size - mtl); in target_check_max_data_sg_nents()
1352 } else if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { in target_check_max_data_sg_nents()
1353 u32 orig_dl = size + cmd->residual_count; in target_check_max_data_sg_nents()
1354 cmd->residual_count = (orig_dl - mtl); in target_check_max_data_sg_nents()
1356 cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT; in target_check_max_data_sg_nents()
1357 cmd->residual_count = (cmd->data_length - mtl); in target_check_max_data_sg_nents()
1359 cmd->data_length = mtl; in target_check_max_data_sg_nents()
1364 if (cmd->prot_length) { in target_check_max_data_sg_nents()
1366 cmd->prot_length = dev->prot_length * sectors; in target_check_max_data_sg_nents()
1386 target_cmd_size_check(struct se_cmd *cmd, unsigned int size) in target_cmd_size_check() argument
1388 struct se_device *dev = cmd->se_dev; in target_cmd_size_check()
1390 if (cmd->unknown_data_length) { in target_cmd_size_check()
1391 cmd->data_length = size; in target_cmd_size_check()
1392 } else if (size != cmd->data_length) { in target_cmd_size_check()
1395 " 0x%02x\n", cmd->se_tfo->fabric_name, in target_cmd_size_check()
1396 cmd->data_length, size, cmd->t_task_cdb[0]); in target_cmd_size_check()
1403 if (size > cmd->data_length) { in target_cmd_size_check()
1404 cmd->se_cmd_flags |= SCF_OVERFLOW_BIT; in target_cmd_size_check()
1405 cmd->residual_count = (size - cmd->data_length); in target_cmd_size_check()
1407 cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT; in target_cmd_size_check()
1408 cmd->residual_count = (cmd->data_length - size); in target_cmd_size_check()
1413 if (cmd->data_direction == DMA_FROM_DEVICE) { in target_cmd_size_check()
1414 cmd->data_length = size; in target_cmd_size_check()
1418 if (cmd->data_direction == DMA_TO_DEVICE) { in target_cmd_size_check()
1419 if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) { in target_cmd_size_check()
1430 if (size > cmd->data_length) { in target_cmd_size_check()
1438 return target_check_max_data_sg_nents(cmd, dev, size); in target_cmd_size_check()
1448 void __target_init_cmd(struct se_cmd *cmd, in __target_init_cmd() argument
1455 INIT_LIST_HEAD(&cmd->se_delayed_node); in __target_init_cmd()
1456 INIT_LIST_HEAD(&cmd->se_qf_node); in __target_init_cmd()
1457 INIT_LIST_HEAD(&cmd->state_list); in __target_init_cmd()
1458 init_completion(&cmd->t_transport_stop_comp); in __target_init_cmd()
1459 cmd->free_compl = NULL; in __target_init_cmd()
1460 cmd->abrt_compl = NULL; in __target_init_cmd()
1461 spin_lock_init(&cmd->t_state_lock); in __target_init_cmd()
1462 INIT_WORK(&cmd->work, NULL); in __target_init_cmd()
1463 kref_init(&cmd->cmd_kref); in __target_init_cmd()
1465 cmd->t_task_cdb = &cmd->__t_task_cdb[0]; in __target_init_cmd()
1466 cmd->se_tfo = tfo; in __target_init_cmd()
1467 cmd->se_sess = se_sess; in __target_init_cmd()
1468 cmd->data_length = data_length; in __target_init_cmd()
1469 cmd->data_direction = data_direction; in __target_init_cmd()
1470 cmd->sam_task_attr = task_attr; in __target_init_cmd()
1471 cmd->sense_buffer = sense_buffer; in __target_init_cmd()
1472 cmd->orig_fe_lun = unpacked_lun; in __target_init_cmd()
1473 cmd->cmd_cnt = cmd_cnt; in __target_init_cmd()
1475 if (!(cmd->se_cmd_flags & SCF_USE_CPUID)) in __target_init_cmd()
1476 cmd->cpuid = raw_smp_processor_id(); in __target_init_cmd()
1478 cmd->state_active = false; in __target_init_cmd()
1483 transport_check_alloc_task_attr(struct se_cmd *cmd) in transport_check_alloc_task_attr() argument
1485 struct se_device *dev = cmd->se_dev; in transport_check_alloc_task_attr()
1494 if (cmd->sam_task_attr == TCM_ACA_TAG) { in transport_check_alloc_task_attr()
1504 target_cmd_init_cdb(struct se_cmd *cmd, unsigned char *cdb, gfp_t gfp) in target_cmd_init_cdb() argument
1524 if (scsi_command_size(cdb) > sizeof(cmd->__t_task_cdb)) { in target_cmd_init_cdb()
1525 cmd->t_task_cdb = kzalloc(scsi_command_size(cdb), gfp); in target_cmd_init_cdb()
1526 if (!cmd->t_task_cdb) { in target_cmd_init_cdb()
1530 (unsigned long)sizeof(cmd->__t_task_cdb)); in target_cmd_init_cdb()
1538 memcpy(cmd->t_task_cdb, cdb, scsi_command_size(cdb)); in target_cmd_init_cdb()
1540 trace_target_sequencer_start(cmd); in target_cmd_init_cdb()
1548 memcpy(cmd->t_task_cdb, cdb, min(scsi_command_size(cdb), in target_cmd_init_cdb()
1555 target_cmd_parse_cdb(struct se_cmd *cmd) in target_cmd_parse_cdb() argument
1557 struct se_device *dev = cmd->se_dev; in target_cmd_parse_cdb()
1560 ret = dev->transport->parse_cdb(cmd); in target_cmd_parse_cdb()
1563 cmd->se_tfo->fabric_name, in target_cmd_parse_cdb()
1564 cmd->se_sess->se_node_acl->initiatorname, in target_cmd_parse_cdb()
1565 cmd->t_task_cdb[0]); in target_cmd_parse_cdb()
1569 ret = transport_check_alloc_task_attr(cmd); in target_cmd_parse_cdb()
1573 cmd->se_cmd_flags |= SCF_SUPPORTED_SAM_OPCODE; in target_cmd_parse_cdb()
1574 atomic_long_inc(&cmd->se_lun->lun_stats.cmd_pdus); in target_cmd_parse_cdb()
1584 struct se_cmd *cmd) in transport_handle_cdb_direct() argument
1590 if (!cmd->se_lun) { in transport_handle_cdb_direct()
1604 cmd->t_state = TRANSPORT_NEW_CMD; in transport_handle_cdb_direct()
1605 cmd->transport_state |= CMD_T_ACTIVE; in transport_handle_cdb_direct()
1612 ret = transport_generic_new_cmd(cmd); in transport_handle_cdb_direct()
1614 transport_generic_request_failure(cmd, ret); in transport_handle_cdb_direct()
1620 transport_generic_map_mem_to_cmd(struct se_cmd *cmd, struct scatterlist *sgl, in transport_generic_map_mem_to_cmd() argument
1631 if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { in transport_generic_map_mem_to_cmd()
1637 cmd->t_data_sg = sgl; in transport_generic_map_mem_to_cmd()
1638 cmd->t_data_nents = sgl_count; in transport_generic_map_mem_to_cmd()
1639 cmd->t_bidi_data_sg = sgl_bidi; in transport_generic_map_mem_to_cmd()
1640 cmd->t_bidi_data_nents = sgl_bidi_count; in transport_generic_map_mem_to_cmd()
1642 cmd->se_cmd_flags |= SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC; in transport_generic_map_mem_to_cmd()
2030 void transport_generic_request_failure(struct se_cmd *cmd, in transport_generic_request_failure() argument
2037 target_show_cmd("-----[ ", cmd); in transport_generic_request_failure()
2042 transport_complete_task_attr(cmd); in transport_generic_request_failure()
2044 if (cmd->transport_complete_callback) in transport_generic_request_failure()
2045 cmd->transport_complete_callback(cmd, false, &post_ret); in transport_generic_request_failure()
2047 if (cmd->transport_state & CMD_T_ABORTED) { in transport_generic_request_failure()
2048 INIT_WORK(&cmd->work, target_abort_work); in transport_generic_request_failure()
2049 queue_work(target_completion_wq, &cmd->work); in transport_generic_request_failure()
2080 cmd->scsi_status = SAM_STAT_TASK_SET_FULL; in transport_generic_request_failure()
2083 cmd->scsi_status = SAM_STAT_BUSY; in transport_generic_request_failure()
2092 cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT; in transport_generic_request_failure()
2100 if (cmd->se_sess && in transport_generic_request_failure()
2101 cmd->se_dev->dev_attrib.emulate_ua_intlck_ctrl in transport_generic_request_failure()
2103 target_ua_allocate_lun(cmd->se_sess->se_node_acl, in transport_generic_request_failure()
2104 cmd->orig_fe_lun, 0x2C, in transport_generic_request_failure()
2111 cmd->t_task_cdb[0], sense_reason); in transport_generic_request_failure()
2116 ret = transport_send_check_condition_and_sense(cmd, sense_reason, 0); in transport_generic_request_failure()
2121 transport_lun_remove_cmd(cmd); in transport_generic_request_failure()
2122 transport_cmd_check_stop_to_fabric(cmd); in transport_generic_request_failure()
2126 trace_target_cmd_complete(cmd); in transport_generic_request_failure()
2127 ret = cmd->se_tfo->queue_status(cmd); in transport_generic_request_failure()
2131 transport_handle_queue_full(cmd, cmd->se_dev, ret, false); in transport_generic_request_failure()
2135 void __target_execute_cmd(struct se_cmd *cmd, bool do_checks) in __target_execute_cmd() argument
2139 if (!cmd->execute_cmd) { in __target_execute_cmd()
2150 ret = target_scsi3_ua_check(cmd); in __target_execute_cmd()
2154 ret = target_alua_state_check(cmd); in __target_execute_cmd()
2158 ret = target_check_reservation(cmd); in __target_execute_cmd()
2160 cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT; in __target_execute_cmd()
2165 ret = cmd->execute_cmd(cmd); in __target_execute_cmd()
2169 spin_lock_irq(&cmd->t_state_lock); in __target_execute_cmd()
2170 cmd->transport_state &= ~CMD_T_SENT; in __target_execute_cmd()
2171 spin_unlock_irq(&cmd->t_state_lock); in __target_execute_cmd()
2173 transport_generic_request_failure(cmd, ret); in __target_execute_cmd()
2176 static int target_write_prot_action(struct se_cmd *cmd) in target_write_prot_action() argument
2184 switch (cmd->prot_op) { in target_write_prot_action()
2186 if (!(cmd->se_sess->sup_prot_ops & TARGET_PROT_DOUT_INSERT)) in target_write_prot_action()
2187 sbc_dif_generate(cmd); in target_write_prot_action()
2190 if (cmd->se_sess->sup_prot_ops & TARGET_PROT_DOUT_STRIP) in target_write_prot_action()
2193 sectors = cmd->data_length >> ilog2(cmd->se_dev->dev_attrib.block_size); in target_write_prot_action()
2194 cmd->pi_err = sbc_dif_verify(cmd, cmd->t_task_lba, in target_write_prot_action()
2195 sectors, 0, cmd->t_prot_sg, 0); in target_write_prot_action()
2196 if (unlikely(cmd->pi_err)) { in target_write_prot_action()
2197 spin_lock_irq(&cmd->t_state_lock); in target_write_prot_action()
2198 cmd->transport_state &= ~CMD_T_SENT; in target_write_prot_action()
2199 spin_unlock_irq(&cmd->t_state_lock); in target_write_prot_action()
2200 transport_generic_request_failure(cmd, cmd->pi_err); in target_write_prot_action()
2211 static bool target_handle_task_attr(struct se_cmd *cmd) in target_handle_task_attr() argument
2213 struct se_device *dev = cmd->se_dev; in target_handle_task_attr()
2218 cmd->se_cmd_flags |= SCF_TASK_ATTR_SET; in target_handle_task_attr()
2224 switch (cmd->sam_task_attr) { in target_handle_task_attr()
2228 cmd->t_task_cdb[0]); in target_handle_task_attr()
2234 cmd->t_task_cdb[0]); in target_handle_task_attr()
2247 if (cmd->sam_task_attr != TCM_ORDERED_TAG) { in target_handle_task_attr()
2256 spin_lock_irq(&cmd->t_state_lock); in target_handle_task_attr()
2257 cmd->transport_state &= ~CMD_T_SENT; in target_handle_task_attr()
2258 spin_unlock_irq(&cmd->t_state_lock); in target_handle_task_attr()
2261 list_add_tail(&cmd->se_delayed_node, &dev->delayed_cmd_list); in target_handle_task_attr()
2265 cmd->t_task_cdb[0], cmd->sam_task_attr); in target_handle_task_attr()
2275 void target_execute_cmd(struct se_cmd *cmd) in target_execute_cmd() argument
2283 if (target_cmd_interrupted(cmd)) in target_execute_cmd()
2286 spin_lock_irq(&cmd->t_state_lock); in target_execute_cmd()
2287 cmd->t_state = TRANSPORT_PROCESSING; in target_execute_cmd()
2288 cmd->transport_state |= CMD_T_ACTIVE | CMD_T_SENT; in target_execute_cmd()
2289 spin_unlock_irq(&cmd->t_state_lock); in target_execute_cmd()
2291 if (target_write_prot_action(cmd)) in target_execute_cmd()
2294 if (target_handle_task_attr(cmd)) in target_execute_cmd()
2297 __target_execute_cmd(cmd, true); in target_execute_cmd()
2312 struct se_cmd *cmd; in target_do_delayed_work() local
2317 cmd = list_entry(dev->delayed_cmd_list.next, in target_do_delayed_work()
2320 if (cmd->sam_task_attr == TCM_ORDERED_TAG) { in target_do_delayed_work()
2333 list_del(&cmd->se_delayed_node); in target_do_delayed_work()
2337 if (cmd->sam_task_attr != TCM_ORDERED_TAG) in target_do_delayed_work()
2340 cmd->transport_state |= CMD_T_SENT; in target_do_delayed_work()
2342 __target_execute_cmd(cmd, true); in target_do_delayed_work()
2353 static void transport_complete_task_attr(struct se_cmd *cmd) in transport_complete_task_attr() argument
2355 struct se_device *dev = cmd->se_dev; in transport_complete_task_attr()
2360 if (!(cmd->se_cmd_flags & SCF_TASK_ATTR_SET)) in transport_complete_task_attr()
2363 if (cmd->sam_task_attr == TCM_SIMPLE_TAG) { in transport_complete_task_attr()
2366 } else if (cmd->sam_task_attr == TCM_HEAD_TAG) { in transport_complete_task_attr()
2371 } else if (cmd->sam_task_attr == TCM_ORDERED_TAG) { in transport_complete_task_attr()
2380 cmd->se_cmd_flags &= ~SCF_TASK_ATTR_SET; in transport_complete_task_attr()
2387 static void transport_complete_qf(struct se_cmd *cmd) in transport_complete_qf() argument
2391 transport_complete_task_attr(cmd); in transport_complete_qf()
2401 if (cmd->t_state == TRANSPORT_COMPLETE_QF_ERR) { in transport_complete_qf()
2402 if (cmd->scsi_status) in transport_complete_qf()
2405 translate_sense_reason(cmd, TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE); in transport_complete_qf()
2418 if (!(cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) && in transport_complete_qf()
2419 cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) in transport_complete_qf()
2422 switch (cmd->data_direction) { in transport_complete_qf()
2425 if (cmd->scsi_status && in transport_complete_qf()
2426 !(cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL)) in transport_complete_qf()
2429 trace_target_cmd_complete(cmd); in transport_complete_qf()
2430 ret = cmd->se_tfo->queue_data_in(cmd); in transport_complete_qf()
2433 if (cmd->se_cmd_flags & SCF_BIDI) { in transport_complete_qf()
2434 ret = cmd->se_tfo->queue_data_in(cmd); in transport_complete_qf()
2440 trace_target_cmd_complete(cmd); in transport_complete_qf()
2441 ret = cmd->se_tfo->queue_status(cmd); in transport_complete_qf()
2448 transport_handle_queue_full(cmd, cmd->se_dev, ret, false); in transport_complete_qf()
2451 transport_lun_remove_cmd(cmd); in transport_complete_qf()
2452 transport_cmd_check_stop_to_fabric(cmd); in transport_complete_qf()
2455 static void transport_handle_queue_full(struct se_cmd *cmd, struct se_device *dev, in transport_handle_queue_full() argument
2467 cmd->t_state = (write_pending) ? TRANSPORT_COMPLETE_QF_WP : in transport_handle_queue_full()
2471 cmd->t_state = TRANSPORT_COMPLETE_QF_ERR; in transport_handle_queue_full()
2475 list_add_tail(&cmd->se_qf_node, &cmd->se_dev->qf_cmd_list); in transport_handle_queue_full()
2477 spin_unlock_irq(&cmd->se_dev->qf_cmd_lock); in transport_handle_queue_full()
2479 schedule_work(&cmd->se_dev->qf_work_queue); in transport_handle_queue_full()
2482 static bool target_read_prot_action(struct se_cmd *cmd) in target_read_prot_action() argument
2484 switch (cmd->prot_op) { in target_read_prot_action()
2486 if (!(cmd->se_sess->sup_prot_ops & TARGET_PROT_DIN_STRIP)) { in target_read_prot_action()
2487 u32 sectors = cmd->data_length >> in target_read_prot_action()
2488 ilog2(cmd->se_dev->dev_attrib.block_size); in target_read_prot_action()
2490 cmd->pi_err = sbc_dif_verify(cmd, cmd->t_task_lba, in target_read_prot_action()
2491 sectors, 0, cmd->t_prot_sg, in target_read_prot_action()
2493 if (cmd->pi_err) in target_read_prot_action()
2498 if (cmd->se_sess->sup_prot_ops & TARGET_PROT_DIN_INSERT) in target_read_prot_action()
2501 sbc_dif_generate(cmd); in target_read_prot_action()
2512 struct se_cmd *cmd = container_of(work, struct se_cmd, work); in target_complete_ok_work() local
2520 transport_complete_task_attr(cmd); in target_complete_ok_work()
2526 if (atomic_read(&cmd->se_dev->dev_qf_count) != 0) in target_complete_ok_work()
2527 schedule_work(&cmd->se_dev->qf_work_queue); in target_complete_ok_work()
2538 if (!(cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) && in target_complete_ok_work()
2539 cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) { in target_complete_ok_work()
2540 WARN_ON(!cmd->scsi_status); in target_complete_ok_work()
2542 cmd, 0, 1); in target_complete_ok_work()
2546 transport_lun_remove_cmd(cmd); in target_complete_ok_work()
2547 transport_cmd_check_stop_to_fabric(cmd); in target_complete_ok_work()
2554 if (cmd->transport_complete_callback) { in target_complete_ok_work()
2556 bool caw = (cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE); in target_complete_ok_work()
2557 bool zero_dl = !(cmd->data_length); in target_complete_ok_work()
2560 rc = cmd->transport_complete_callback(cmd, true, &post_ret); in target_complete_ok_work()
2567 ret = transport_send_check_condition_and_sense(cmd, in target_complete_ok_work()
2572 transport_lun_remove_cmd(cmd); in target_complete_ok_work()
2573 transport_cmd_check_stop_to_fabric(cmd); in target_complete_ok_work()
2579 switch (cmd->data_direction) { in target_complete_ok_work()
2591 if (cmd->scsi_status && in target_complete_ok_work()
2592 !(cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL)) in target_complete_ok_work()
2595 atomic_long_add(cmd->data_length, in target_complete_ok_work()
2596 &cmd->se_lun->lun_stats.tx_data_octets); in target_complete_ok_work()
2602 if (target_read_prot_action(cmd)) { in target_complete_ok_work()
2603 ret = transport_send_check_condition_and_sense(cmd, in target_complete_ok_work()
2604 cmd->pi_err, 0); in target_complete_ok_work()
2608 transport_lun_remove_cmd(cmd); in target_complete_ok_work()
2609 transport_cmd_check_stop_to_fabric(cmd); in target_complete_ok_work()
2613 trace_target_cmd_complete(cmd); in target_complete_ok_work()
2614 ret = cmd->se_tfo->queue_data_in(cmd); in target_complete_ok_work()
2619 atomic_long_add(cmd->data_length, in target_complete_ok_work()
2620 &cmd->se_lun->lun_stats.rx_data_octets); in target_complete_ok_work()
2624 if (cmd->se_cmd_flags & SCF_BIDI) { in target_complete_ok_work()
2625 atomic_long_add(cmd->data_length, in target_complete_ok_work()
2626 &cmd->se_lun->lun_stats.tx_data_octets); in target_complete_ok_work()
2627 ret = cmd->se_tfo->queue_data_in(cmd); in target_complete_ok_work()
2635 trace_target_cmd_complete(cmd); in target_complete_ok_work()
2636 ret = cmd->se_tfo->queue_status(cmd); in target_complete_ok_work()
2644 transport_lun_remove_cmd(cmd); in target_complete_ok_work()
2645 transport_cmd_check_stop_to_fabric(cmd); in target_complete_ok_work()
2650 " data_direction: %d\n", cmd, cmd->data_direction); in target_complete_ok_work()
2652 transport_handle_queue_full(cmd, cmd->se_dev, ret, false); in target_complete_ok_work()
2661 static inline void transport_reset_sgl_orig(struct se_cmd *cmd) in transport_reset_sgl_orig() argument
2667 if (!cmd->t_data_sg_orig) in transport_reset_sgl_orig()
2670 kfree(cmd->t_data_sg); in transport_reset_sgl_orig()
2671 cmd->t_data_sg = cmd->t_data_sg_orig; in transport_reset_sgl_orig()
2672 cmd->t_data_sg_orig = NULL; in transport_reset_sgl_orig()
2673 cmd->t_data_nents = cmd->t_data_nents_orig; in transport_reset_sgl_orig()
2674 cmd->t_data_nents_orig = 0; in transport_reset_sgl_orig()
2677 static inline void transport_free_pages(struct se_cmd *cmd) in transport_free_pages() argument
2679 if (!(cmd->se_cmd_flags & SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC)) { in transport_free_pages()
2680 target_free_sgl(cmd->t_prot_sg, cmd->t_prot_nents); in transport_free_pages()
2681 cmd->t_prot_sg = NULL; in transport_free_pages()
2682 cmd->t_prot_nents = 0; in transport_free_pages()
2685 if (cmd->se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC) { in transport_free_pages()
2690 if (cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE) { in transport_free_pages()
2691 target_free_sgl(cmd->t_bidi_data_sg, in transport_free_pages()
2692 cmd->t_bidi_data_nents); in transport_free_pages()
2693 cmd->t_bidi_data_sg = NULL; in transport_free_pages()
2694 cmd->t_bidi_data_nents = 0; in transport_free_pages()
2696 transport_reset_sgl_orig(cmd); in transport_free_pages()
2699 transport_reset_sgl_orig(cmd); in transport_free_pages()
2701 target_free_sgl(cmd->t_data_sg, cmd->t_data_nents); in transport_free_pages()
2702 cmd->t_data_sg = NULL; in transport_free_pages()
2703 cmd->t_data_nents = 0; in transport_free_pages()
2705 target_free_sgl(cmd->t_bidi_data_sg, cmd->t_bidi_data_nents); in transport_free_pages()
2706 cmd->t_bidi_data_sg = NULL; in transport_free_pages()
2707 cmd->t_bidi_data_nents = 0; in transport_free_pages()
2710 void *transport_kmap_data_sg(struct se_cmd *cmd) in transport_kmap_data_sg() argument
2712 struct scatterlist *sg = cmd->t_data_sg; in transport_kmap_data_sg()
2721 if (!cmd->t_data_nents) in transport_kmap_data_sg()
2725 if (cmd->t_data_nents == 1) in transport_kmap_data_sg()
2729 pages = kmalloc_array(cmd->t_data_nents, sizeof(*pages), GFP_KERNEL); in transport_kmap_data_sg()
2734 for_each_sg(cmd->t_data_sg, sg, cmd->t_data_nents, i) { in transport_kmap_data_sg()
2738 cmd->t_data_vmap = vmap(pages, cmd->t_data_nents, VM_MAP, PAGE_KERNEL); in transport_kmap_data_sg()
2740 if (!cmd->t_data_vmap) in transport_kmap_data_sg()
2743 return cmd->t_data_vmap + cmd->t_data_sg[0].offset; in transport_kmap_data_sg()
2747 void transport_kunmap_data_sg(struct se_cmd *cmd) in transport_kunmap_data_sg() argument
2749 if (!cmd->t_data_nents) { in transport_kunmap_data_sg()
2751 } else if (cmd->t_data_nents == 1) { in transport_kunmap_data_sg()
2752 kunmap(sg_page(cmd->t_data_sg)); in transport_kunmap_data_sg()
2756 vunmap(cmd->t_data_vmap); in transport_kunmap_data_sg()
2757 cmd->t_data_vmap = NULL; in transport_kunmap_data_sg()
2778 transport_generic_new_cmd(struct se_cmd *cmd) in transport_generic_new_cmd() argument
2782 bool zero_flag = !(cmd->se_cmd_flags & SCF_SCSI_DATA_CDB); in transport_generic_new_cmd()
2784 if (cmd->prot_op != TARGET_PROT_NORMAL && in transport_generic_new_cmd()
2785 !(cmd->se_cmd_flags & SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC)) { in transport_generic_new_cmd()
2786 ret = target_alloc_sgl(&cmd->t_prot_sg, &cmd->t_prot_nents, in transport_generic_new_cmd()
2787 cmd->prot_length, true, false); in transport_generic_new_cmd()
2797 if (!(cmd->se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC) && in transport_generic_new_cmd()
2798 cmd->data_length) { in transport_generic_new_cmd()
2800 if ((cmd->se_cmd_flags & SCF_BIDI) || in transport_generic_new_cmd()
2801 (cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE)) { in transport_generic_new_cmd()
2804 if (cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE) in transport_generic_new_cmd()
2805 bidi_length = cmd->t_task_nolb * in transport_generic_new_cmd()
2806 cmd->se_dev->dev_attrib.block_size; in transport_generic_new_cmd()
2808 bidi_length = cmd->data_length; in transport_generic_new_cmd()
2810 ret = target_alloc_sgl(&cmd->t_bidi_data_sg, in transport_generic_new_cmd()
2811 &cmd->t_bidi_data_nents, in transport_generic_new_cmd()
2817 ret = target_alloc_sgl(&cmd->t_data_sg, &cmd->t_data_nents, in transport_generic_new_cmd()
2818 cmd->data_length, zero_flag, false); in transport_generic_new_cmd()
2821 } else if ((cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE) && in transport_generic_new_cmd()
2822 cmd->data_length) { in transport_generic_new_cmd()
2827 u32 caw_length = cmd->t_task_nolb * in transport_generic_new_cmd()
2828 cmd->se_dev->dev_attrib.block_size; in transport_generic_new_cmd()
2830 ret = target_alloc_sgl(&cmd->t_bidi_data_sg, in transport_generic_new_cmd()
2831 &cmd->t_bidi_data_nents, in transport_generic_new_cmd()
2841 target_add_to_state_list(cmd); in transport_generic_new_cmd()
2842 if (cmd->data_direction != DMA_TO_DEVICE || cmd->data_length == 0) { in transport_generic_new_cmd()
2843 target_execute_cmd(cmd); in transport_generic_new_cmd()
2847 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_generic_new_cmd()
2848 cmd->t_state = TRANSPORT_WRITE_PENDING; in transport_generic_new_cmd()
2853 if (cmd->transport_state & CMD_T_STOP && in transport_generic_new_cmd()
2854 !cmd->se_tfo->write_pending_must_be_called) { in transport_generic_new_cmd()
2856 __func__, __LINE__, cmd->tag); in transport_generic_new_cmd()
2858 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_generic_new_cmd()
2860 complete_all(&cmd->t_transport_stop_comp); in transport_generic_new_cmd()
2863 cmd->transport_state &= ~CMD_T_ACTIVE; in transport_generic_new_cmd()
2864 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_generic_new_cmd()
2866 ret = cmd->se_tfo->write_pending(cmd); in transport_generic_new_cmd()
2873 pr_debug("Handling write_pending QUEUE__FULL: se_cmd: %p\n", cmd); in transport_generic_new_cmd()
2874 transport_handle_queue_full(cmd, cmd->se_dev, ret, true); in transport_generic_new_cmd()
2879 static void transport_write_pending_qf(struct se_cmd *cmd) in transport_write_pending_qf() argument
2885 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_write_pending_qf()
2886 stop = (cmd->transport_state & (CMD_T_STOP | CMD_T_ABORTED)); in transport_write_pending_qf()
2887 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_write_pending_qf()
2891 __func__, __LINE__, cmd->tag); in transport_write_pending_qf()
2892 complete_all(&cmd->t_transport_stop_comp); in transport_write_pending_qf()
2896 ret = cmd->se_tfo->write_pending(cmd); in transport_write_pending_qf()
2899 cmd); in transport_write_pending_qf()
2900 transport_handle_queue_full(cmd, cmd->se_dev, ret, true); in transport_write_pending_qf()
2908 static void target_wait_free_cmd(struct se_cmd *cmd, bool *aborted, bool *tas) in target_wait_free_cmd() argument
2912 spin_lock_irqsave(&cmd->t_state_lock, flags); in target_wait_free_cmd()
2913 __transport_wait_for_tasks(cmd, true, aborted, tas, &flags); in target_wait_free_cmd()
2914 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in target_wait_free_cmd()
2921 void target_put_cmd_and_wait(struct se_cmd *cmd) in target_put_cmd_and_wait() argument
2925 WARN_ON_ONCE(cmd->abrt_compl); in target_put_cmd_and_wait()
2926 cmd->abrt_compl = &compl; in target_put_cmd_and_wait()
2927 target_put_sess_cmd(cmd); in target_put_cmd_and_wait()
2954 int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) in transport_generic_free_cmd() argument
2961 target_wait_free_cmd(cmd, &aborted, &tas); in transport_generic_free_cmd()
2963 if (cmd->se_cmd_flags & SCF_SE_LUN_CMD) { in transport_generic_free_cmd()
2969 if (cmd->state_active) in transport_generic_free_cmd()
2970 target_remove_from_state_list(cmd); in transport_generic_free_cmd()
2972 if (cmd->se_lun) in transport_generic_free_cmd()
2973 transport_lun_remove_cmd(cmd); in transport_generic_free_cmd()
2976 cmd->free_compl = &compl; in transport_generic_free_cmd()
2977 ret = target_put_sess_cmd(cmd); in transport_generic_free_cmd()
2979 pr_debug("Detected CMD_T_ABORTED for ITT: %llu\n", cmd->tag); in transport_generic_free_cmd()
3021 static void target_free_cmd_mem(struct se_cmd *cmd) in target_free_cmd_mem() argument
3023 transport_free_pages(cmd); in target_free_cmd_mem()
3025 if (cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) in target_free_cmd_mem()
3026 core_tmr_release_req(cmd->se_tmr_req); in target_free_cmd_mem()
3027 if (cmd->t_task_cdb != cmd->__t_task_cdb) in target_free_cmd_mem()
3028 kfree(cmd->t_task_cdb); in target_free_cmd_mem()
3141 void target_show_cmd(const char *pfx, struct se_cmd *cmd) in target_show_cmd() argument
3143 char *ts_str = target_ts_to_str(cmd->transport_state); in target_show_cmd()
3144 const u8 *cdb = cmd->t_task_cdb; in target_show_cmd()
3145 struct se_tmr_req *tmf = cmd->se_tmr_req; in target_show_cmd()
3147 if (!(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) { in target_show_cmd()
3149 pfx, cdb[0], cdb[1], cmd->tag, in target_show_cmd()
3150 data_dir_name(cmd->data_direction), in target_show_cmd()
3151 cmd->se_tfo->get_cmd_state(cmd), in target_show_cmd()
3152 cmd_state_name(cmd->t_state), cmd->data_length, in target_show_cmd()
3153 kref_read(&cmd->cmd_kref), ts_str); in target_show_cmd()
3156 pfx, target_tmf_name(tmf->function), cmd->tag, in target_show_cmd()
3157 tmf->ref_task_tag, cmd->se_tfo->get_cmd_state(cmd), in target_show_cmd()
3158 cmd_state_name(cmd->t_state), in target_show_cmd()
3159 kref_read(&cmd->cmd_kref), ts_str); in target_show_cmd()
3239 __transport_wait_for_tasks(struct se_cmd *cmd, bool fabric_stop, in __transport_wait_for_tasks() argument
3241 __releases(&cmd->t_state_lock) in __transport_wait_for_tasks()
3242 __acquires(&cmd->t_state_lock) in __transport_wait_for_tasks()
3244 lockdep_assert_held(&cmd->t_state_lock); in __transport_wait_for_tasks()
3247 cmd->transport_state |= CMD_T_FABRIC_STOP; in __transport_wait_for_tasks()
3249 if (cmd->transport_state & CMD_T_ABORTED) in __transport_wait_for_tasks()
3252 if (cmd->transport_state & CMD_T_TAS) in __transport_wait_for_tasks()
3255 if (!(cmd->se_cmd_flags & SCF_SE_LUN_CMD) && in __transport_wait_for_tasks()
3256 !(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) in __transport_wait_for_tasks()
3259 if (!(cmd->se_cmd_flags & SCF_SUPPORTED_SAM_OPCODE) && in __transport_wait_for_tasks()
3260 !(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) in __transport_wait_for_tasks()
3263 if (!(cmd->transport_state & CMD_T_ACTIVE)) in __transport_wait_for_tasks()
3269 cmd->transport_state |= CMD_T_STOP; in __transport_wait_for_tasks()
3271 target_show_cmd("wait_for_tasks: Stopping ", cmd); in __transport_wait_for_tasks()
3273 spin_unlock_irqrestore(&cmd->t_state_lock, *flags); in __transport_wait_for_tasks()
3275 while (!wait_for_completion_timeout(&cmd->t_transport_stop_comp, in __transport_wait_for_tasks()
3277 target_show_cmd("wait for tasks: ", cmd); in __transport_wait_for_tasks()
3279 spin_lock_irqsave(&cmd->t_state_lock, *flags); in __transport_wait_for_tasks()
3280 cmd->transport_state &= ~(CMD_T_ACTIVE | CMD_T_STOP); in __transport_wait_for_tasks()
3283 "t_transport_stop_comp) for ITT: 0x%08llx\n", cmd->tag); in __transport_wait_for_tasks()
3292 bool transport_wait_for_tasks(struct se_cmd *cmd) in transport_wait_for_tasks() argument
3297 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_wait_for_tasks()
3298 ret = __transport_wait_for_tasks(cmd, false, &aborted, &tas, &flags); in transport_wait_for_tasks()
3299 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_wait_for_tasks()
3493 static void translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason) in translate_sense_reason() argument
3496 u8 *buffer = cmd->sense_buffer; in translate_sense_reason()
3499 bool desc_format = target_sense_desc_format(cmd->se_dev); in translate_sense_reason()
3509 if (!core_scsi3_ua_for_check_condition(cmd, &key, &asc, in translate_sense_reason()
3511 cmd->scsi_status = SAM_STAT_BUSY; in translate_sense_reason()
3520 cmd->se_cmd_flags |= SCF_EMULATED_TASK_SENSE; in translate_sense_reason()
3521 cmd->scsi_status = SAM_STAT_CHECK_CONDITION; in translate_sense_reason()
3522 cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER; in translate_sense_reason()
3526 cmd->scsi_sense_length, in translate_sense_reason()
3527 cmd->sense_info) < 0); in translate_sense_reason()
3531 transport_send_check_condition_and_sense(struct se_cmd *cmd, in transport_send_check_condition_and_sense() argument
3536 WARN_ON_ONCE(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB); in transport_send_check_condition_and_sense()
3538 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_send_check_condition_and_sense()
3539 if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) { in transport_send_check_condition_and_sense()
3540 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_send_check_condition_and_sense()
3543 cmd->se_cmd_flags |= SCF_SENT_CHECK_CONDITION; in transport_send_check_condition_and_sense()
3544 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_send_check_condition_and_sense()
3547 translate_sense_reason(cmd, reason); in transport_send_check_condition_and_sense()
3549 trace_target_cmd_complete(cmd); in transport_send_check_condition_and_sense()
3550 return cmd->se_tfo->queue_status(cmd); in transport_send_check_condition_and_sense()
3560 int target_send_busy(struct se_cmd *cmd) in target_send_busy() argument
3562 WARN_ON_ONCE(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB); in target_send_busy()
3564 cmd->scsi_status = SAM_STAT_BUSY; in target_send_busy()
3565 trace_target_cmd_complete(cmd); in target_send_busy()
3566 return cmd->se_tfo->queue_status(cmd); in target_send_busy()
3572 struct se_cmd *cmd = container_of(work, struct se_cmd, work); in target_tmr_work() local
3573 struct se_device *dev = cmd->se_dev; in target_tmr_work()
3574 struct se_tmr_req *tmr = cmd->se_tmr_req; in target_tmr_work()
3577 if (cmd->transport_state & CMD_T_ABORTED) in target_tmr_work()
3582 core_tmr_abort_task(dev, tmr, cmd->se_sess); in target_tmr_work()
3611 if (cmd->transport_state & CMD_T_ABORTED) in target_tmr_work()
3614 cmd->se_tfo->queue_tm_rsp(cmd); in target_tmr_work()
3616 transport_lun_remove_cmd(cmd); in target_tmr_work()
3617 transport_cmd_check_stop_to_fabric(cmd); in target_tmr_work()
3621 target_handle_abort(cmd); in target_tmr_work()
3625 struct se_cmd *cmd) in transport_generic_handle_tmr() argument
3630 spin_lock_irqsave(&cmd->se_dev->se_tmr_lock, flags); in transport_generic_handle_tmr()
3631 list_add_tail(&cmd->se_tmr_req->tmr_list, &cmd->se_dev->dev_tmr_list); in transport_generic_handle_tmr()
3632 spin_unlock_irqrestore(&cmd->se_dev->se_tmr_lock, flags); in transport_generic_handle_tmr()
3634 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_generic_handle_tmr()
3635 if (cmd->transport_state & CMD_T_ABORTED) { in transport_generic_handle_tmr()
3638 cmd->t_state = TRANSPORT_ISTATE_PROCESSING; in transport_generic_handle_tmr()
3639 cmd->transport_state |= CMD_T_ACTIVE; in transport_generic_handle_tmr()
3641 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_generic_handle_tmr()
3645 cmd->se_tmr_req->function, in transport_generic_handle_tmr()
3646 cmd->se_tmr_req->ref_task_tag, cmd->tag); in transport_generic_handle_tmr()
3647 target_handle_abort(cmd); in transport_generic_handle_tmr()
3651 INIT_WORK(&cmd->work, target_tmr_work); in transport_generic_handle_tmr()
3652 schedule_work(&cmd->work); in transport_generic_handle_tmr()