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,
663 static void target_remove_from_state_list(struct se_cmd *cmd) in target_remove_from_state_list() argument
665 struct se_device *dev = cmd->se_dev; in target_remove_from_state_list()
671 spin_lock_irqsave(&dev->queues[cmd->cpuid].lock, flags); in target_remove_from_state_list()
672 if (cmd->state_active) { in target_remove_from_state_list()
673 list_del(&cmd->state_list); in target_remove_from_state_list()
674 cmd->state_active = false; in target_remove_from_state_list()
676 spin_unlock_irqrestore(&dev->queues[cmd->cpuid].lock, flags); in target_remove_from_state_list()
679 static void target_remove_from_tmr_list(struct se_cmd *cmd) in target_remove_from_tmr_list() argument
684 if (cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) in target_remove_from_tmr_list()
685 dev = cmd->se_tmr_req->tmr_dev; in target_remove_from_tmr_list()
689 if (cmd->se_tmr_req->tmr_dev) in target_remove_from_tmr_list()
690 list_del_init(&cmd->se_tmr_req->tmr_list); in target_remove_from_tmr_list()
701 static int transport_cmd_check_stop_to_fabric(struct se_cmd *cmd) in transport_cmd_check_stop_to_fabric() argument
705 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_cmd_check_stop_to_fabric()
710 if (cmd->transport_state & CMD_T_STOP) { in transport_cmd_check_stop_to_fabric()
712 __func__, __LINE__, cmd->tag); in transport_cmd_check_stop_to_fabric()
714 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_cmd_check_stop_to_fabric()
716 complete_all(&cmd->t_transport_stop_comp); in transport_cmd_check_stop_to_fabric()
719 cmd->transport_state &= ~CMD_T_ACTIVE; in transport_cmd_check_stop_to_fabric()
720 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_cmd_check_stop_to_fabric()
729 return cmd->se_tfo->check_stop_free(cmd); in transport_cmd_check_stop_to_fabric()
732 static void transport_lun_remove_cmd(struct se_cmd *cmd) in transport_lun_remove_cmd() argument
734 struct se_lun *lun = cmd->se_lun; in transport_lun_remove_cmd()
739 target_remove_from_state_list(cmd); in transport_lun_remove_cmd()
740 target_remove_from_tmr_list(cmd); in transport_lun_remove_cmd()
742 if (cmpxchg(&cmd->lun_ref_active, true, false)) in transport_lun_remove_cmd()
748 cmd->se_lun = NULL; in transport_lun_remove_cmd()
753 struct se_cmd *cmd = container_of(work, struct se_cmd, work); in target_complete_failure_work() local
755 transport_generic_request_failure(cmd, cmd->sense_reason); in target_complete_failure_work()
762 static unsigned char *transport_get_sense_buffer(struct se_cmd *cmd) in transport_get_sense_buffer() argument
764 struct se_device *dev = cmd->se_dev; in transport_get_sense_buffer()
766 WARN_ON(!cmd->se_lun); in transport_get_sense_buffer()
771 if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) in transport_get_sense_buffer()
774 cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER; in transport_get_sense_buffer()
777 dev->se_hba->hba_id, dev->transport->name, cmd->scsi_status); in transport_get_sense_buffer()
778 return cmd->sense_buffer; in transport_get_sense_buffer()
781 void transport_copy_sense_to_cmd(struct se_cmd *cmd, unsigned char *sense) in transport_copy_sense_to_cmd() argument
786 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_copy_sense_to_cmd()
787 cmd_sense_buf = transport_get_sense_buffer(cmd); in transport_copy_sense_to_cmd()
789 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_copy_sense_to_cmd()
793 cmd->se_cmd_flags |= SCF_TRANSPORT_TASK_SENSE; in transport_copy_sense_to_cmd()
794 memcpy(cmd_sense_buf, sense, cmd->scsi_sense_length); in transport_copy_sense_to_cmd()
795 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_copy_sense_to_cmd()
799 static void target_handle_abort(struct se_cmd *cmd) in target_handle_abort() argument
801 bool tas = cmd->transport_state & CMD_T_TAS; in target_handle_abort()
802 bool ack_kref = cmd->se_cmd_flags & SCF_ACK_KREF; in target_handle_abort()
805 pr_debug("tag %#llx: send_abort_response = %d\n", cmd->tag, tas); in target_handle_abort()
808 if (!(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) { in target_handle_abort()
809 cmd->scsi_status = SAM_STAT_TASK_ABORTED; in target_handle_abort()
811 cmd->t_task_cdb[0], cmd->tag); in target_handle_abort()
812 trace_target_cmd_complete(cmd); in target_handle_abort()
813 ret = cmd->se_tfo->queue_status(cmd); in target_handle_abort()
815 transport_handle_queue_full(cmd, cmd->se_dev, in target_handle_abort()
820 cmd->se_tmr_req->response = TMR_FUNCTION_REJECTED; in target_handle_abort()
821 cmd->se_tfo->queue_tm_rsp(cmd); in target_handle_abort()
828 cmd->se_tfo->aborted_task(cmd); in target_handle_abort()
830 WARN_ON_ONCE(target_put_sess_cmd(cmd) != 0); in target_handle_abort()
838 WARN_ON_ONCE(kref_read(&cmd->cmd_kref) == 0); in target_handle_abort()
840 transport_lun_remove_cmd(cmd); in target_handle_abort()
842 transport_cmd_check_stop_to_fabric(cmd); in target_handle_abort()
847 struct se_cmd *cmd = container_of(work, struct se_cmd, work); in target_abort_work() local
849 target_handle_abort(cmd); in target_abort_work()
852 static bool target_cmd_interrupted(struct se_cmd *cmd) in target_cmd_interrupted() argument
856 if (cmd->transport_state & CMD_T_ABORTED) { in target_cmd_interrupted()
857 if (cmd->transport_complete_callback) in target_cmd_interrupted()
858 cmd->transport_complete_callback(cmd, false, &post_ret); in target_cmd_interrupted()
859 INIT_WORK(&cmd->work, target_abort_work); in target_cmd_interrupted()
860 queue_work(target_completion_wq, &cmd->work); in target_cmd_interrupted()
862 } else if (cmd->transport_state & CMD_T_STOP) { in target_cmd_interrupted()
863 if (cmd->transport_complete_callback) in target_cmd_interrupted()
864 cmd->transport_complete_callback(cmd, false, &post_ret); in target_cmd_interrupted()
865 complete_all(&cmd->t_transport_stop_comp); in target_cmd_interrupted()
873 void target_complete_cmd_with_sense(struct se_cmd *cmd, u8 scsi_status, in target_complete_cmd_with_sense() argument
876 struct se_wwn *wwn = cmd->se_sess->se_tpg->se_tpg_wwn; in target_complete_cmd_with_sense()
880 if (target_cmd_interrupted(cmd)) in target_complete_cmd_with_sense()
883 cmd->scsi_status = scsi_status; in target_complete_cmd_with_sense()
884 cmd->sense_reason = sense_reason; in target_complete_cmd_with_sense()
886 spin_lock_irqsave(&cmd->t_state_lock, flags); in target_complete_cmd_with_sense()
887 switch (cmd->scsi_status) { in target_complete_cmd_with_sense()
889 if (cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) in target_complete_cmd_with_sense()
899 cmd->t_state = TRANSPORT_COMPLETE; in target_complete_cmd_with_sense()
900 cmd->transport_state |= (CMD_T_COMPLETE | CMD_T_ACTIVE); in target_complete_cmd_with_sense()
901 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in target_complete_cmd_with_sense()
903 INIT_WORK(&cmd->work, success ? target_complete_ok_work : in target_complete_cmd_with_sense()
907 cpu = cmd->cpuid; in target_complete_cmd_with_sense()
911 queue_work_on(cpu, target_completion_wq, &cmd->work); in target_complete_cmd_with_sense()
915 void target_complete_cmd(struct se_cmd *cmd, u8 scsi_status) in target_complete_cmd() argument
917 target_complete_cmd_with_sense(cmd, scsi_status, scsi_status ? in target_complete_cmd()
923 void target_set_cmd_data_length(struct se_cmd *cmd, int length) in target_set_cmd_data_length() argument
925 if (length < cmd->data_length) { in target_set_cmd_data_length()
926 if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { in target_set_cmd_data_length()
927 cmd->residual_count += cmd->data_length - length; in target_set_cmd_data_length()
929 cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT; in target_set_cmd_data_length()
930 cmd->residual_count = cmd->data_length - length; in target_set_cmd_data_length()
933 cmd->data_length = length; in target_set_cmd_data_length()
938 void target_complete_cmd_with_length(struct se_cmd *cmd, u8 scsi_status, int length) in target_complete_cmd_with_length() argument
941 cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) { in target_complete_cmd_with_length()
942 target_set_cmd_data_length(cmd, length); in target_complete_cmd_with_length()
945 target_complete_cmd(cmd, scsi_status); in target_complete_cmd_with_length()
949 static void target_add_to_state_list(struct se_cmd *cmd) in target_add_to_state_list() argument
951 struct se_device *dev = cmd->se_dev; in target_add_to_state_list()
954 spin_lock_irqsave(&dev->queues[cmd->cpuid].lock, flags); in target_add_to_state_list()
955 if (!cmd->state_active) { in target_add_to_state_list()
956 list_add_tail(&cmd->state_list, in target_add_to_state_list()
957 &dev->queues[cmd->cpuid].state_list); in target_add_to_state_list()
958 cmd->state_active = true; in target_add_to_state_list()
960 spin_unlock_irqrestore(&dev->queues[cmd->cpuid].lock, flags); in target_add_to_state_list()
966 static void transport_write_pending_qf(struct se_cmd *cmd);
967 static void transport_complete_qf(struct se_cmd *cmd);
974 struct se_cmd *cmd, *cmd_tmp; in target_qf_do_work() local
980 list_for_each_entry_safe(cmd, cmd_tmp, &qf_cmd_list, se_qf_node) { in target_qf_do_work()
981 list_del(&cmd->se_qf_node); in target_qf_do_work()
985 " context: %s\n", cmd->se_tfo->fabric_name, cmd, in target_qf_do_work()
986 (cmd->t_state == TRANSPORT_COMPLETE_QF_OK) ? "COMPLETE_OK" : in target_qf_do_work()
987 (cmd->t_state == TRANSPORT_COMPLETE_QF_WP) ? "WRITE_PENDING" in target_qf_do_work()
990 if (cmd->t_state == TRANSPORT_COMPLETE_QF_WP) in target_qf_do_work()
991 transport_write_pending_qf(cmd); in target_qf_do_work()
992 else if (cmd->t_state == TRANSPORT_COMPLETE_QF_OK || in target_qf_do_work()
993 cmd->t_state == TRANSPORT_COMPLETE_QF_ERR) in target_qf_do_work()
994 transport_complete_qf(cmd); in target_qf_do_work()
998 unsigned char *transport_dump_cmd_direction(struct se_cmd *cmd) in transport_dump_cmd_direction() argument
1000 switch (cmd->data_direction) { in transport_dump_cmd_direction()
1291 target_check_max_data_sg_nents(struct se_cmd *cmd, struct se_device *dev, in target_check_max_data_sg_nents() argument
1296 if (!cmd->se_tfo->max_data_sg_nents) in target_check_max_data_sg_nents()
1304 mtl = (cmd->se_tfo->max_data_sg_nents * PAGE_SIZE); in target_check_max_data_sg_nents()
1305 if (cmd->data_length > mtl) { in target_check_max_data_sg_nents()
1317 if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { in target_check_max_data_sg_nents()
1318 cmd->residual_count = (size - mtl); in target_check_max_data_sg_nents()
1319 } else if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) { in target_check_max_data_sg_nents()
1320 u32 orig_dl = size + cmd->residual_count; in target_check_max_data_sg_nents()
1321 cmd->residual_count = (orig_dl - mtl); in target_check_max_data_sg_nents()
1323 cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT; in target_check_max_data_sg_nents()
1324 cmd->residual_count = (cmd->data_length - mtl); in target_check_max_data_sg_nents()
1326 cmd->data_length = mtl; in target_check_max_data_sg_nents()
1331 if (cmd->prot_length) { in target_check_max_data_sg_nents()
1333 cmd->prot_length = dev->prot_length * sectors; in target_check_max_data_sg_nents()
1353 target_cmd_size_check(struct se_cmd *cmd, unsigned int size) in target_cmd_size_check() argument
1355 struct se_device *dev = cmd->se_dev; in target_cmd_size_check()
1357 if (cmd->unknown_data_length) { in target_cmd_size_check()
1358 cmd->data_length = size; in target_cmd_size_check()
1359 } else if (size != cmd->data_length) { in target_cmd_size_check()
1362 " 0x%02x\n", cmd->se_tfo->fabric_name, in target_cmd_size_check()
1363 cmd->data_length, size, cmd->t_task_cdb[0]); in target_cmd_size_check()
1370 if (size > cmd->data_length) { in target_cmd_size_check()
1371 cmd->se_cmd_flags |= SCF_OVERFLOW_BIT; in target_cmd_size_check()
1372 cmd->residual_count = (size - cmd->data_length); in target_cmd_size_check()
1374 cmd->se_cmd_flags |= SCF_UNDERFLOW_BIT; in target_cmd_size_check()
1375 cmd->residual_count = (cmd->data_length - size); in target_cmd_size_check()
1380 if (cmd->data_direction == DMA_FROM_DEVICE) { in target_cmd_size_check()
1381 cmd->data_length = size; in target_cmd_size_check()
1385 if (cmd->data_direction == DMA_TO_DEVICE) { in target_cmd_size_check()
1386 if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) { in target_cmd_size_check()
1397 if (size > cmd->data_length) { in target_cmd_size_check()
1405 return target_check_max_data_sg_nents(cmd, dev, size); in target_cmd_size_check()
1416 struct se_cmd *cmd, in __target_init_cmd() argument
1424 INIT_LIST_HEAD(&cmd->se_delayed_node); in __target_init_cmd()
1425 INIT_LIST_HEAD(&cmd->se_qf_node); in __target_init_cmd()
1426 INIT_LIST_HEAD(&cmd->state_list); in __target_init_cmd()
1427 init_completion(&cmd->t_transport_stop_comp); in __target_init_cmd()
1428 cmd->free_compl = NULL; in __target_init_cmd()
1429 cmd->abrt_compl = NULL; in __target_init_cmd()
1430 spin_lock_init(&cmd->t_state_lock); in __target_init_cmd()
1431 INIT_WORK(&cmd->work, NULL); in __target_init_cmd()
1432 kref_init(&cmd->cmd_kref); in __target_init_cmd()
1434 cmd->t_task_cdb = &cmd->__t_task_cdb[0]; in __target_init_cmd()
1435 cmd->se_tfo = tfo; in __target_init_cmd()
1436 cmd->se_sess = se_sess; in __target_init_cmd()
1437 cmd->data_length = data_length; in __target_init_cmd()
1438 cmd->data_direction = data_direction; in __target_init_cmd()
1439 cmd->sam_task_attr = task_attr; in __target_init_cmd()
1440 cmd->sense_buffer = sense_buffer; in __target_init_cmd()
1441 cmd->orig_fe_lun = unpacked_lun; in __target_init_cmd()
1443 if (!(cmd->se_cmd_flags & SCF_USE_CPUID)) in __target_init_cmd()
1444 cmd->cpuid = raw_smp_processor_id(); in __target_init_cmd()
1446 cmd->state_active = false; in __target_init_cmd()
1451 transport_check_alloc_task_attr(struct se_cmd *cmd) in transport_check_alloc_task_attr() argument
1453 struct se_device *dev = cmd->se_dev; in transport_check_alloc_task_attr()
1462 if (cmd->sam_task_attr == TCM_ACA_TAG) { in transport_check_alloc_task_attr()
1472 target_cmd_init_cdb(struct se_cmd *cmd, unsigned char *cdb, gfp_t gfp) in target_cmd_init_cdb() argument
1492 if (scsi_command_size(cdb) > sizeof(cmd->__t_task_cdb)) { in target_cmd_init_cdb()
1493 cmd->t_task_cdb = kzalloc(scsi_command_size(cdb), gfp); in target_cmd_init_cdb()
1494 if (!cmd->t_task_cdb) { in target_cmd_init_cdb()
1498 (unsigned long)sizeof(cmd->__t_task_cdb)); in target_cmd_init_cdb()
1506 memcpy(cmd->t_task_cdb, cdb, scsi_command_size(cdb)); in target_cmd_init_cdb()
1508 trace_target_sequencer_start(cmd); in target_cmd_init_cdb()
1516 memcpy(cmd->t_task_cdb, cdb, min(scsi_command_size(cdb), in target_cmd_init_cdb()
1523 target_cmd_parse_cdb(struct se_cmd *cmd) in target_cmd_parse_cdb() argument
1525 struct se_device *dev = cmd->se_dev; in target_cmd_parse_cdb()
1528 ret = dev->transport->parse_cdb(cmd); in target_cmd_parse_cdb()
1531 cmd->se_tfo->fabric_name, in target_cmd_parse_cdb()
1532 cmd->se_sess->se_node_acl->initiatorname, in target_cmd_parse_cdb()
1533 cmd->t_task_cdb[0]); in target_cmd_parse_cdb()
1537 ret = transport_check_alloc_task_attr(cmd); in target_cmd_parse_cdb()
1541 cmd->se_cmd_flags |= SCF_SUPPORTED_SAM_OPCODE; in target_cmd_parse_cdb()
1542 atomic_long_inc(&cmd->se_lun->lun_stats.cmd_pdus); in target_cmd_parse_cdb()
1552 struct se_cmd *cmd) in transport_handle_cdb_direct() argument
1558 if (!cmd->se_lun) { in transport_handle_cdb_direct()
1572 cmd->t_state = TRANSPORT_NEW_CMD; in transport_handle_cdb_direct()
1573 cmd->transport_state |= CMD_T_ACTIVE; in transport_handle_cdb_direct()
1580 ret = transport_generic_new_cmd(cmd); in transport_handle_cdb_direct()
1582 transport_generic_request_failure(cmd, ret); in transport_handle_cdb_direct()
1588 transport_generic_map_mem_to_cmd(struct se_cmd *cmd, struct scatterlist *sgl, in transport_generic_map_mem_to_cmd() argument
1599 if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT) { in transport_generic_map_mem_to_cmd()
1605 cmd->t_data_sg = sgl; in transport_generic_map_mem_to_cmd()
1606 cmd->t_data_nents = sgl_count; in transport_generic_map_mem_to_cmd()
1607 cmd->t_bidi_data_sg = sgl_bidi; in transport_generic_map_mem_to_cmd()
1608 cmd->t_bidi_data_nents = sgl_bidi_count; in transport_generic_map_mem_to_cmd()
1610 cmd->se_cmd_flags |= SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC; in transport_generic_map_mem_to_cmd()
1996 void transport_generic_request_failure(struct se_cmd *cmd, in transport_generic_request_failure() argument
2003 target_show_cmd("-----[ ", cmd); in transport_generic_request_failure()
2008 transport_complete_task_attr(cmd); in transport_generic_request_failure()
2010 if (cmd->transport_complete_callback) in transport_generic_request_failure()
2011 cmd->transport_complete_callback(cmd, false, &post_ret); in transport_generic_request_failure()
2013 if (cmd->transport_state & CMD_T_ABORTED) { in transport_generic_request_failure()
2014 INIT_WORK(&cmd->work, target_abort_work); in transport_generic_request_failure()
2015 queue_work(target_completion_wq, &cmd->work); in transport_generic_request_failure()
2046 cmd->scsi_status = SAM_STAT_TASK_SET_FULL; in transport_generic_request_failure()
2049 cmd->scsi_status = SAM_STAT_BUSY; in transport_generic_request_failure()
2058 cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT; in transport_generic_request_failure()
2066 if (cmd->se_sess && in transport_generic_request_failure()
2067 cmd->se_dev->dev_attrib.emulate_ua_intlck_ctrl in transport_generic_request_failure()
2069 target_ua_allocate_lun(cmd->se_sess->se_node_acl, in transport_generic_request_failure()
2070 cmd->orig_fe_lun, 0x2C, in transport_generic_request_failure()
2077 cmd->t_task_cdb[0], sense_reason); in transport_generic_request_failure()
2082 ret = transport_send_check_condition_and_sense(cmd, sense_reason, 0); in transport_generic_request_failure()
2087 transport_lun_remove_cmd(cmd); in transport_generic_request_failure()
2088 transport_cmd_check_stop_to_fabric(cmd); in transport_generic_request_failure()
2092 trace_target_cmd_complete(cmd); in transport_generic_request_failure()
2093 ret = cmd->se_tfo->queue_status(cmd); in transport_generic_request_failure()
2097 transport_handle_queue_full(cmd, cmd->se_dev, ret, false); in transport_generic_request_failure()
2101 void __target_execute_cmd(struct se_cmd *cmd, bool do_checks) in __target_execute_cmd() argument
2105 if (!cmd->execute_cmd) { in __target_execute_cmd()
2116 ret = target_scsi3_ua_check(cmd); in __target_execute_cmd()
2120 ret = target_alua_state_check(cmd); in __target_execute_cmd()
2124 ret = target_check_reservation(cmd); in __target_execute_cmd()
2126 cmd->scsi_status = SAM_STAT_RESERVATION_CONFLICT; in __target_execute_cmd()
2131 ret = cmd->execute_cmd(cmd); in __target_execute_cmd()
2135 spin_lock_irq(&cmd->t_state_lock); in __target_execute_cmd()
2136 cmd->transport_state &= ~CMD_T_SENT; in __target_execute_cmd()
2137 spin_unlock_irq(&cmd->t_state_lock); in __target_execute_cmd()
2139 transport_generic_request_failure(cmd, ret); in __target_execute_cmd()
2142 static int target_write_prot_action(struct se_cmd *cmd) in target_write_prot_action() argument
2150 switch (cmd->prot_op) { in target_write_prot_action()
2152 if (!(cmd->se_sess->sup_prot_ops & TARGET_PROT_DOUT_INSERT)) in target_write_prot_action()
2153 sbc_dif_generate(cmd); in target_write_prot_action()
2156 if (cmd->se_sess->sup_prot_ops & TARGET_PROT_DOUT_STRIP) in target_write_prot_action()
2159 sectors = cmd->data_length >> ilog2(cmd->se_dev->dev_attrib.block_size); in target_write_prot_action()
2160 cmd->pi_err = sbc_dif_verify(cmd, cmd->t_task_lba, in target_write_prot_action()
2161 sectors, 0, cmd->t_prot_sg, 0); in target_write_prot_action()
2162 if (unlikely(cmd->pi_err)) { in target_write_prot_action()
2163 spin_lock_irq(&cmd->t_state_lock); in target_write_prot_action()
2164 cmd->transport_state &= ~CMD_T_SENT; in target_write_prot_action()
2165 spin_unlock_irq(&cmd->t_state_lock); in target_write_prot_action()
2166 transport_generic_request_failure(cmd, cmd->pi_err); in target_write_prot_action()
2177 static bool target_handle_task_attr(struct se_cmd *cmd) in target_handle_task_attr() argument
2179 struct se_device *dev = cmd->se_dev; in target_handle_task_attr()
2184 cmd->se_cmd_flags |= SCF_TASK_ATTR_SET; in target_handle_task_attr()
2190 switch (cmd->sam_task_attr) { in target_handle_task_attr()
2194 cmd->t_task_cdb[0]); in target_handle_task_attr()
2200 cmd->t_task_cdb[0]); in target_handle_task_attr()
2213 if (cmd->sam_task_attr != TCM_ORDERED_TAG) { in target_handle_task_attr()
2222 spin_lock_irq(&cmd->t_state_lock); in target_handle_task_attr()
2223 cmd->transport_state &= ~CMD_T_SENT; in target_handle_task_attr()
2224 spin_unlock_irq(&cmd->t_state_lock); in target_handle_task_attr()
2227 list_add_tail(&cmd->se_delayed_node, &dev->delayed_cmd_list); in target_handle_task_attr()
2231 cmd->t_task_cdb[0], cmd->sam_task_attr); in target_handle_task_attr()
2241 void target_execute_cmd(struct se_cmd *cmd) in target_execute_cmd() argument
2249 if (target_cmd_interrupted(cmd)) in target_execute_cmd()
2252 spin_lock_irq(&cmd->t_state_lock); in target_execute_cmd()
2253 cmd->t_state = TRANSPORT_PROCESSING; in target_execute_cmd()
2254 cmd->transport_state |= CMD_T_ACTIVE | CMD_T_SENT; in target_execute_cmd()
2255 spin_unlock_irq(&cmd->t_state_lock); in target_execute_cmd()
2257 if (target_write_prot_action(cmd)) in target_execute_cmd()
2260 if (target_handle_task_attr(cmd)) in target_execute_cmd()
2263 __target_execute_cmd(cmd, true); in target_execute_cmd()
2278 struct se_cmd *cmd; in target_do_delayed_work() local
2283 cmd = list_entry(dev->delayed_cmd_list.next, in target_do_delayed_work()
2286 if (cmd->sam_task_attr == TCM_ORDERED_TAG) { in target_do_delayed_work()
2299 list_del(&cmd->se_delayed_node); in target_do_delayed_work()
2303 if (cmd->sam_task_attr != TCM_ORDERED_TAG) in target_do_delayed_work()
2306 cmd->transport_state |= CMD_T_SENT; in target_do_delayed_work()
2308 __target_execute_cmd(cmd, true); in target_do_delayed_work()
2319 static void transport_complete_task_attr(struct se_cmd *cmd) in transport_complete_task_attr() argument
2321 struct se_device *dev = cmd->se_dev; in transport_complete_task_attr()
2326 if (!(cmd->se_cmd_flags & SCF_TASK_ATTR_SET)) in transport_complete_task_attr()
2329 if (cmd->sam_task_attr == TCM_SIMPLE_TAG) { in transport_complete_task_attr()
2332 } else if (cmd->sam_task_attr == TCM_HEAD_TAG) { in transport_complete_task_attr()
2337 } else if (cmd->sam_task_attr == TCM_ORDERED_TAG) { in transport_complete_task_attr()
2346 cmd->se_cmd_flags &= ~SCF_TASK_ATTR_SET; in transport_complete_task_attr()
2353 static void transport_complete_qf(struct se_cmd *cmd) in transport_complete_qf() argument
2357 transport_complete_task_attr(cmd); in transport_complete_qf()
2367 if (cmd->t_state == TRANSPORT_COMPLETE_QF_ERR) { in transport_complete_qf()
2368 if (cmd->scsi_status) in transport_complete_qf()
2371 translate_sense_reason(cmd, TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE); in transport_complete_qf()
2384 if (!(cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) && in transport_complete_qf()
2385 cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) in transport_complete_qf()
2388 switch (cmd->data_direction) { in transport_complete_qf()
2391 if (cmd->scsi_status && in transport_complete_qf()
2392 !(cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL)) in transport_complete_qf()
2395 trace_target_cmd_complete(cmd); in transport_complete_qf()
2396 ret = cmd->se_tfo->queue_data_in(cmd); in transport_complete_qf()
2399 if (cmd->se_cmd_flags & SCF_BIDI) { in transport_complete_qf()
2400 ret = cmd->se_tfo->queue_data_in(cmd); in transport_complete_qf()
2406 trace_target_cmd_complete(cmd); in transport_complete_qf()
2407 ret = cmd->se_tfo->queue_status(cmd); in transport_complete_qf()
2414 transport_handle_queue_full(cmd, cmd->se_dev, ret, false); in transport_complete_qf()
2417 transport_lun_remove_cmd(cmd); in transport_complete_qf()
2418 transport_cmd_check_stop_to_fabric(cmd); in transport_complete_qf()
2421 static void transport_handle_queue_full(struct se_cmd *cmd, struct se_device *dev, in transport_handle_queue_full() argument
2433 cmd->t_state = (write_pending) ? TRANSPORT_COMPLETE_QF_WP : in transport_handle_queue_full()
2437 cmd->t_state = TRANSPORT_COMPLETE_QF_ERR; in transport_handle_queue_full()
2441 list_add_tail(&cmd->se_qf_node, &cmd->se_dev->qf_cmd_list); in transport_handle_queue_full()
2443 spin_unlock_irq(&cmd->se_dev->qf_cmd_lock); in transport_handle_queue_full()
2445 schedule_work(&cmd->se_dev->qf_work_queue); in transport_handle_queue_full()
2448 static bool target_read_prot_action(struct se_cmd *cmd) in target_read_prot_action() argument
2450 switch (cmd->prot_op) { in target_read_prot_action()
2452 if (!(cmd->se_sess->sup_prot_ops & TARGET_PROT_DIN_STRIP)) { in target_read_prot_action()
2453 u32 sectors = cmd->data_length >> in target_read_prot_action()
2454 ilog2(cmd->se_dev->dev_attrib.block_size); in target_read_prot_action()
2456 cmd->pi_err = sbc_dif_verify(cmd, cmd->t_task_lba, in target_read_prot_action()
2457 sectors, 0, cmd->t_prot_sg, in target_read_prot_action()
2459 if (cmd->pi_err) in target_read_prot_action()
2464 if (cmd->se_sess->sup_prot_ops & TARGET_PROT_DIN_INSERT) in target_read_prot_action()
2467 sbc_dif_generate(cmd); in target_read_prot_action()
2478 struct se_cmd *cmd = container_of(work, struct se_cmd, work); in target_complete_ok_work() local
2486 transport_complete_task_attr(cmd); in target_complete_ok_work()
2492 if (atomic_read(&cmd->se_dev->dev_qf_count) != 0) in target_complete_ok_work()
2493 schedule_work(&cmd->se_dev->qf_work_queue); in target_complete_ok_work()
2504 if (!(cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL) && in target_complete_ok_work()
2505 cmd->se_cmd_flags & SCF_TRANSPORT_TASK_SENSE) { in target_complete_ok_work()
2506 WARN_ON(!cmd->scsi_status); in target_complete_ok_work()
2508 cmd, 0, 1); in target_complete_ok_work()
2512 transport_lun_remove_cmd(cmd); in target_complete_ok_work()
2513 transport_cmd_check_stop_to_fabric(cmd); in target_complete_ok_work()
2520 if (cmd->transport_complete_callback) { in target_complete_ok_work()
2522 bool caw = (cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE); in target_complete_ok_work()
2523 bool zero_dl = !(cmd->data_length); in target_complete_ok_work()
2526 rc = cmd->transport_complete_callback(cmd, true, &post_ret); in target_complete_ok_work()
2533 ret = transport_send_check_condition_and_sense(cmd, in target_complete_ok_work()
2538 transport_lun_remove_cmd(cmd); in target_complete_ok_work()
2539 transport_cmd_check_stop_to_fabric(cmd); in target_complete_ok_work()
2545 switch (cmd->data_direction) { in target_complete_ok_work()
2557 if (cmd->scsi_status && in target_complete_ok_work()
2558 !(cmd->se_cmd_flags & SCF_TREAT_READ_AS_NORMAL)) in target_complete_ok_work()
2561 atomic_long_add(cmd->data_length, in target_complete_ok_work()
2562 &cmd->se_lun->lun_stats.tx_data_octets); in target_complete_ok_work()
2568 if (target_read_prot_action(cmd)) { in target_complete_ok_work()
2569 ret = transport_send_check_condition_and_sense(cmd, in target_complete_ok_work()
2570 cmd->pi_err, 0); in target_complete_ok_work()
2574 transport_lun_remove_cmd(cmd); in target_complete_ok_work()
2575 transport_cmd_check_stop_to_fabric(cmd); in target_complete_ok_work()
2579 trace_target_cmd_complete(cmd); in target_complete_ok_work()
2580 ret = cmd->se_tfo->queue_data_in(cmd); in target_complete_ok_work()
2585 atomic_long_add(cmd->data_length, in target_complete_ok_work()
2586 &cmd->se_lun->lun_stats.rx_data_octets); in target_complete_ok_work()
2590 if (cmd->se_cmd_flags & SCF_BIDI) { in target_complete_ok_work()
2591 atomic_long_add(cmd->data_length, in target_complete_ok_work()
2592 &cmd->se_lun->lun_stats.tx_data_octets); in target_complete_ok_work()
2593 ret = cmd->se_tfo->queue_data_in(cmd); in target_complete_ok_work()
2601 trace_target_cmd_complete(cmd); in target_complete_ok_work()
2602 ret = cmd->se_tfo->queue_status(cmd); in target_complete_ok_work()
2610 transport_lun_remove_cmd(cmd); in target_complete_ok_work()
2611 transport_cmd_check_stop_to_fabric(cmd); in target_complete_ok_work()
2616 " data_direction: %d\n", cmd, cmd->data_direction); in target_complete_ok_work()
2618 transport_handle_queue_full(cmd, cmd->se_dev, ret, false); in target_complete_ok_work()
2627 static inline void transport_reset_sgl_orig(struct se_cmd *cmd) in transport_reset_sgl_orig() argument
2633 if (!cmd->t_data_sg_orig) in transport_reset_sgl_orig()
2636 kfree(cmd->t_data_sg); in transport_reset_sgl_orig()
2637 cmd->t_data_sg = cmd->t_data_sg_orig; in transport_reset_sgl_orig()
2638 cmd->t_data_sg_orig = NULL; in transport_reset_sgl_orig()
2639 cmd->t_data_nents = cmd->t_data_nents_orig; in transport_reset_sgl_orig()
2640 cmd->t_data_nents_orig = 0; in transport_reset_sgl_orig()
2643 static inline void transport_free_pages(struct se_cmd *cmd) in transport_free_pages() argument
2645 if (!(cmd->se_cmd_flags & SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC)) { in transport_free_pages()
2646 target_free_sgl(cmd->t_prot_sg, cmd->t_prot_nents); in transport_free_pages()
2647 cmd->t_prot_sg = NULL; in transport_free_pages()
2648 cmd->t_prot_nents = 0; in transport_free_pages()
2651 if (cmd->se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC) { in transport_free_pages()
2656 if (cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE) { in transport_free_pages()
2657 target_free_sgl(cmd->t_bidi_data_sg, in transport_free_pages()
2658 cmd->t_bidi_data_nents); in transport_free_pages()
2659 cmd->t_bidi_data_sg = NULL; in transport_free_pages()
2660 cmd->t_bidi_data_nents = 0; in transport_free_pages()
2662 transport_reset_sgl_orig(cmd); in transport_free_pages()
2665 transport_reset_sgl_orig(cmd); in transport_free_pages()
2667 target_free_sgl(cmd->t_data_sg, cmd->t_data_nents); in transport_free_pages()
2668 cmd->t_data_sg = NULL; in transport_free_pages()
2669 cmd->t_data_nents = 0; in transport_free_pages()
2671 target_free_sgl(cmd->t_bidi_data_sg, cmd->t_bidi_data_nents); in transport_free_pages()
2672 cmd->t_bidi_data_sg = NULL; in transport_free_pages()
2673 cmd->t_bidi_data_nents = 0; in transport_free_pages()
2676 void *transport_kmap_data_sg(struct se_cmd *cmd) in transport_kmap_data_sg() argument
2678 struct scatterlist *sg = cmd->t_data_sg; in transport_kmap_data_sg()
2687 if (!cmd->t_data_nents) in transport_kmap_data_sg()
2691 if (cmd->t_data_nents == 1) in transport_kmap_data_sg()
2695 pages = kmalloc_array(cmd->t_data_nents, sizeof(*pages), GFP_KERNEL); in transport_kmap_data_sg()
2700 for_each_sg(cmd->t_data_sg, sg, cmd->t_data_nents, i) { in transport_kmap_data_sg()
2704 cmd->t_data_vmap = vmap(pages, cmd->t_data_nents, VM_MAP, PAGE_KERNEL); in transport_kmap_data_sg()
2706 if (!cmd->t_data_vmap) in transport_kmap_data_sg()
2709 return cmd->t_data_vmap + cmd->t_data_sg[0].offset; in transport_kmap_data_sg()
2713 void transport_kunmap_data_sg(struct se_cmd *cmd) in transport_kunmap_data_sg() argument
2715 if (!cmd->t_data_nents) { in transport_kunmap_data_sg()
2717 } else if (cmd->t_data_nents == 1) { in transport_kunmap_data_sg()
2718 kunmap(sg_page(cmd->t_data_sg)); in transport_kunmap_data_sg()
2722 vunmap(cmd->t_data_vmap); in transport_kunmap_data_sg()
2723 cmd->t_data_vmap = NULL; in transport_kunmap_data_sg()
2744 transport_generic_new_cmd(struct se_cmd *cmd) in transport_generic_new_cmd() argument
2748 bool zero_flag = !(cmd->se_cmd_flags & SCF_SCSI_DATA_CDB); in transport_generic_new_cmd()
2750 if (cmd->prot_op != TARGET_PROT_NORMAL && in transport_generic_new_cmd()
2751 !(cmd->se_cmd_flags & SCF_PASSTHROUGH_PROT_SG_TO_MEM_NOALLOC)) { in transport_generic_new_cmd()
2752 ret = target_alloc_sgl(&cmd->t_prot_sg, &cmd->t_prot_nents, in transport_generic_new_cmd()
2753 cmd->prot_length, true, false); in transport_generic_new_cmd()
2763 if (!(cmd->se_cmd_flags & SCF_PASSTHROUGH_SG_TO_MEM_NOALLOC) && in transport_generic_new_cmd()
2764 cmd->data_length) { in transport_generic_new_cmd()
2766 if ((cmd->se_cmd_flags & SCF_BIDI) || in transport_generic_new_cmd()
2767 (cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE)) { in transport_generic_new_cmd()
2770 if (cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE) in transport_generic_new_cmd()
2771 bidi_length = cmd->t_task_nolb * in transport_generic_new_cmd()
2772 cmd->se_dev->dev_attrib.block_size; in transport_generic_new_cmd()
2774 bidi_length = cmd->data_length; in transport_generic_new_cmd()
2776 ret = target_alloc_sgl(&cmd->t_bidi_data_sg, in transport_generic_new_cmd()
2777 &cmd->t_bidi_data_nents, in transport_generic_new_cmd()
2783 ret = target_alloc_sgl(&cmd->t_data_sg, &cmd->t_data_nents, in transport_generic_new_cmd()
2784 cmd->data_length, zero_flag, false); in transport_generic_new_cmd()
2787 } else if ((cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE) && in transport_generic_new_cmd()
2788 cmd->data_length) { in transport_generic_new_cmd()
2793 u32 caw_length = cmd->t_task_nolb * in transport_generic_new_cmd()
2794 cmd->se_dev->dev_attrib.block_size; in transport_generic_new_cmd()
2796 ret = target_alloc_sgl(&cmd->t_bidi_data_sg, in transport_generic_new_cmd()
2797 &cmd->t_bidi_data_nents, in transport_generic_new_cmd()
2807 target_add_to_state_list(cmd); in transport_generic_new_cmd()
2808 if (cmd->data_direction != DMA_TO_DEVICE || cmd->data_length == 0) { in transport_generic_new_cmd()
2809 target_execute_cmd(cmd); in transport_generic_new_cmd()
2813 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_generic_new_cmd()
2814 cmd->t_state = TRANSPORT_WRITE_PENDING; in transport_generic_new_cmd()
2819 if (cmd->transport_state & CMD_T_STOP && in transport_generic_new_cmd()
2820 !cmd->se_tfo->write_pending_must_be_called) { in transport_generic_new_cmd()
2822 __func__, __LINE__, cmd->tag); in transport_generic_new_cmd()
2824 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_generic_new_cmd()
2826 complete_all(&cmd->t_transport_stop_comp); in transport_generic_new_cmd()
2829 cmd->transport_state &= ~CMD_T_ACTIVE; in transport_generic_new_cmd()
2830 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_generic_new_cmd()
2832 ret = cmd->se_tfo->write_pending(cmd); in transport_generic_new_cmd()
2839 pr_debug("Handling write_pending QUEUE__FULL: se_cmd: %p\n", cmd); in transport_generic_new_cmd()
2840 transport_handle_queue_full(cmd, cmd->se_dev, ret, true); in transport_generic_new_cmd()
2845 static void transport_write_pending_qf(struct se_cmd *cmd) in transport_write_pending_qf() argument
2851 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_write_pending_qf()
2852 stop = (cmd->transport_state & (CMD_T_STOP | CMD_T_ABORTED)); in transport_write_pending_qf()
2853 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_write_pending_qf()
2857 __func__, __LINE__, cmd->tag); in transport_write_pending_qf()
2858 complete_all(&cmd->t_transport_stop_comp); in transport_write_pending_qf()
2862 ret = cmd->se_tfo->write_pending(cmd); in transport_write_pending_qf()
2865 cmd); in transport_write_pending_qf()
2866 transport_handle_queue_full(cmd, cmd->se_dev, ret, true); in transport_write_pending_qf()
2874 static void target_wait_free_cmd(struct se_cmd *cmd, bool *aborted, bool *tas) in target_wait_free_cmd() argument
2878 spin_lock_irqsave(&cmd->t_state_lock, flags); in target_wait_free_cmd()
2879 __transport_wait_for_tasks(cmd, true, aborted, tas, &flags); in target_wait_free_cmd()
2880 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in target_wait_free_cmd()
2887 void target_put_cmd_and_wait(struct se_cmd *cmd) in target_put_cmd_and_wait() argument
2891 WARN_ON_ONCE(cmd->abrt_compl); in target_put_cmd_and_wait()
2892 cmd->abrt_compl = &compl; in target_put_cmd_and_wait()
2893 target_put_sess_cmd(cmd); in target_put_cmd_and_wait()
2920 int transport_generic_free_cmd(struct se_cmd *cmd, int wait_for_tasks) in transport_generic_free_cmd() argument
2927 target_wait_free_cmd(cmd, &aborted, &tas); in transport_generic_free_cmd()
2929 if (cmd->se_cmd_flags & SCF_SE_LUN_CMD) { in transport_generic_free_cmd()
2935 if (cmd->state_active) in transport_generic_free_cmd()
2936 target_remove_from_state_list(cmd); in transport_generic_free_cmd()
2938 if (cmd->se_lun) in transport_generic_free_cmd()
2939 transport_lun_remove_cmd(cmd); in transport_generic_free_cmd()
2942 cmd->free_compl = &compl; in transport_generic_free_cmd()
2943 ret = target_put_sess_cmd(cmd); in transport_generic_free_cmd()
2945 pr_debug("Detected CMD_T_ABORTED for ITT: %llu\n", cmd->tag); in transport_generic_free_cmd()
2983 static void target_free_cmd_mem(struct se_cmd *cmd) in target_free_cmd_mem() argument
2985 transport_free_pages(cmd); in target_free_cmd_mem()
2987 if (cmd->se_cmd_flags & SCF_SCSI_TMR_CDB) in target_free_cmd_mem()
2988 core_tmr_release_req(cmd->se_tmr_req); in target_free_cmd_mem()
2989 if (cmd->t_task_cdb != cmd->__t_task_cdb) in target_free_cmd_mem()
2990 kfree(cmd->t_task_cdb); in target_free_cmd_mem()
3102 void target_show_cmd(const char *pfx, struct se_cmd *cmd) in target_show_cmd() argument
3104 char *ts_str = target_ts_to_str(cmd->transport_state); in target_show_cmd()
3105 const u8 *cdb = cmd->t_task_cdb; in target_show_cmd()
3106 struct se_tmr_req *tmf = cmd->se_tmr_req; in target_show_cmd()
3108 if (!(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) { in target_show_cmd()
3110 pfx, cdb[0], cdb[1], cmd->tag, in target_show_cmd()
3111 data_dir_name(cmd->data_direction), in target_show_cmd()
3112 cmd->se_tfo->get_cmd_state(cmd), in target_show_cmd()
3113 cmd_state_name(cmd->t_state), cmd->data_length, in target_show_cmd()
3114 kref_read(&cmd->cmd_kref), ts_str); in target_show_cmd()
3117 pfx, target_tmf_name(tmf->function), cmd->tag, in target_show_cmd()
3118 tmf->ref_task_tag, cmd->se_tfo->get_cmd_state(cmd), in target_show_cmd()
3119 cmd_state_name(cmd->t_state), in target_show_cmd()
3120 kref_read(&cmd->cmd_kref), ts_str); in target_show_cmd()
3179 __transport_wait_for_tasks(struct se_cmd *cmd, bool fabric_stop, in __transport_wait_for_tasks() argument
3181 __releases(&cmd->t_state_lock) in __transport_wait_for_tasks()
3182 __acquires(&cmd->t_state_lock) in __transport_wait_for_tasks()
3184 lockdep_assert_held(&cmd->t_state_lock); in __transport_wait_for_tasks()
3187 cmd->transport_state |= CMD_T_FABRIC_STOP; in __transport_wait_for_tasks()
3189 if (cmd->transport_state & CMD_T_ABORTED) in __transport_wait_for_tasks()
3192 if (cmd->transport_state & CMD_T_TAS) in __transport_wait_for_tasks()
3195 if (!(cmd->se_cmd_flags & SCF_SE_LUN_CMD) && in __transport_wait_for_tasks()
3196 !(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) in __transport_wait_for_tasks()
3199 if (!(cmd->se_cmd_flags & SCF_SUPPORTED_SAM_OPCODE) && in __transport_wait_for_tasks()
3200 !(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB)) in __transport_wait_for_tasks()
3203 if (!(cmd->transport_state & CMD_T_ACTIVE)) in __transport_wait_for_tasks()
3209 cmd->transport_state |= CMD_T_STOP; in __transport_wait_for_tasks()
3211 target_show_cmd("wait_for_tasks: Stopping ", cmd); in __transport_wait_for_tasks()
3213 spin_unlock_irqrestore(&cmd->t_state_lock, *flags); in __transport_wait_for_tasks()
3215 while (!wait_for_completion_timeout(&cmd->t_transport_stop_comp, in __transport_wait_for_tasks()
3217 target_show_cmd("wait for tasks: ", cmd); in __transport_wait_for_tasks()
3219 spin_lock_irqsave(&cmd->t_state_lock, *flags); in __transport_wait_for_tasks()
3220 cmd->transport_state &= ~(CMD_T_ACTIVE | CMD_T_STOP); in __transport_wait_for_tasks()
3223 "t_transport_stop_comp) for ITT: 0x%08llx\n", cmd->tag); in __transport_wait_for_tasks()
3232 bool transport_wait_for_tasks(struct se_cmd *cmd) in transport_wait_for_tasks() argument
3237 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_wait_for_tasks()
3238 ret = __transport_wait_for_tasks(cmd, false, &aborted, &tas, &flags); in transport_wait_for_tasks()
3239 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_wait_for_tasks()
3433 static void translate_sense_reason(struct se_cmd *cmd, sense_reason_t reason) in translate_sense_reason() argument
3436 u8 *buffer = cmd->sense_buffer; in translate_sense_reason()
3439 bool desc_format = target_sense_desc_format(cmd->se_dev); in translate_sense_reason()
3449 if (!core_scsi3_ua_for_check_condition(cmd, &key, &asc, in translate_sense_reason()
3451 cmd->scsi_status = SAM_STAT_BUSY; in translate_sense_reason()
3460 cmd->se_cmd_flags |= SCF_EMULATED_TASK_SENSE; in translate_sense_reason()
3461 cmd->scsi_status = SAM_STAT_CHECK_CONDITION; in translate_sense_reason()
3462 cmd->scsi_sense_length = TRANSPORT_SENSE_BUFFER; in translate_sense_reason()
3466 cmd->scsi_sense_length, in translate_sense_reason()
3467 cmd->sense_info) < 0); in translate_sense_reason()
3471 transport_send_check_condition_and_sense(struct se_cmd *cmd, in transport_send_check_condition_and_sense() argument
3476 WARN_ON_ONCE(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB); in transport_send_check_condition_and_sense()
3478 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_send_check_condition_and_sense()
3479 if (cmd->se_cmd_flags & SCF_SENT_CHECK_CONDITION) { in transport_send_check_condition_and_sense()
3480 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_send_check_condition_and_sense()
3483 cmd->se_cmd_flags |= SCF_SENT_CHECK_CONDITION; in transport_send_check_condition_and_sense()
3484 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_send_check_condition_and_sense()
3487 translate_sense_reason(cmd, reason); in transport_send_check_condition_and_sense()
3489 trace_target_cmd_complete(cmd); in transport_send_check_condition_and_sense()
3490 return cmd->se_tfo->queue_status(cmd); in transport_send_check_condition_and_sense()
3500 int target_send_busy(struct se_cmd *cmd) in target_send_busy() argument
3502 WARN_ON_ONCE(cmd->se_cmd_flags & SCF_SCSI_TMR_CDB); in target_send_busy()
3504 cmd->scsi_status = SAM_STAT_BUSY; in target_send_busy()
3505 trace_target_cmd_complete(cmd); in target_send_busy()
3506 return cmd->se_tfo->queue_status(cmd); in target_send_busy()
3512 struct se_cmd *cmd = container_of(work, struct se_cmd, work); in target_tmr_work() local
3513 struct se_device *dev = cmd->se_dev; in target_tmr_work()
3514 struct se_tmr_req *tmr = cmd->se_tmr_req; in target_tmr_work()
3517 if (cmd->transport_state & CMD_T_ABORTED) in target_tmr_work()
3522 core_tmr_abort_task(dev, tmr, cmd->se_sess); in target_tmr_work()
3551 if (cmd->transport_state & CMD_T_ABORTED) in target_tmr_work()
3554 cmd->se_tfo->queue_tm_rsp(cmd); in target_tmr_work()
3556 transport_lun_remove_cmd(cmd); in target_tmr_work()
3557 transport_cmd_check_stop_to_fabric(cmd); in target_tmr_work()
3561 target_handle_abort(cmd); in target_tmr_work()
3565 struct se_cmd *cmd) in transport_generic_handle_tmr() argument
3570 spin_lock_irqsave(&cmd->t_state_lock, flags); in transport_generic_handle_tmr()
3571 if (cmd->transport_state & CMD_T_ABORTED) { in transport_generic_handle_tmr()
3574 cmd->t_state = TRANSPORT_ISTATE_PROCESSING; in transport_generic_handle_tmr()
3575 cmd->transport_state |= CMD_T_ACTIVE; in transport_generic_handle_tmr()
3577 spin_unlock_irqrestore(&cmd->t_state_lock, flags); in transport_generic_handle_tmr()
3581 cmd->se_tmr_req->function, in transport_generic_handle_tmr()
3582 cmd->se_tmr_req->ref_task_tag, cmd->tag); in transport_generic_handle_tmr()
3583 target_handle_abort(cmd); in transport_generic_handle_tmr()
3587 INIT_WORK(&cmd->work, target_tmr_work); in transport_generic_handle_tmr()
3588 schedule_work(&cmd->work); in transport_generic_handle_tmr()