Lines Matching refs:cmd
29 static sense_reason_t sbc_execute_unmap(struct se_cmd *cmd);
32 sbc_emulate_readcapacity(struct se_cmd *cmd) in sbc_emulate_readcapacity() argument
34 struct se_device *dev = cmd->se_dev; in sbc_emulate_readcapacity()
35 unsigned char *cdb = cmd->t_task_cdb; in sbc_emulate_readcapacity()
64 rbuf = transport_kmap_data_sg(cmd); in sbc_emulate_readcapacity()
66 memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length)); in sbc_emulate_readcapacity()
67 transport_kunmap_data_sg(cmd); in sbc_emulate_readcapacity()
70 target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, 8); in sbc_emulate_readcapacity()
75 sbc_emulate_readcapacity_16(struct se_cmd *cmd) in sbc_emulate_readcapacity_16() argument
77 struct se_device *dev = cmd->se_dev; in sbc_emulate_readcapacity_16()
78 struct se_session *sess = cmd->se_sess; in sbc_emulate_readcapacity_16()
127 rbuf = transport_kmap_data_sg(cmd); in sbc_emulate_readcapacity_16()
129 memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length)); in sbc_emulate_readcapacity_16()
130 transport_kunmap_data_sg(cmd); in sbc_emulate_readcapacity_16()
133 target_complete_cmd_with_length(cmd, SAM_STAT_GOOD, 32); in sbc_emulate_readcapacity_16()
138 sbc_emulate_startstop(struct se_cmd *cmd) in sbc_emulate_startstop() argument
140 unsigned char *cdb = cmd->t_task_cdb; in sbc_emulate_startstop()
165 target_complete_cmd(cmd, SAM_STAT_GOOD); in sbc_emulate_startstop()
169 sector_t sbc_get_write_same_sectors(struct se_cmd *cmd) in sbc_get_write_same_sectors() argument
173 if (cmd->t_task_cdb[0] == WRITE_SAME) in sbc_get_write_same_sectors()
174 num_blocks = get_unaligned_be16(&cmd->t_task_cdb[7]); in sbc_get_write_same_sectors()
175 else if (cmd->t_task_cdb[0] == WRITE_SAME_16) in sbc_get_write_same_sectors()
176 num_blocks = get_unaligned_be32(&cmd->t_task_cdb[10]); in sbc_get_write_same_sectors()
178 num_blocks = get_unaligned_be32(&cmd->t_task_cdb[28]); in sbc_get_write_same_sectors()
187 return cmd->se_dev->transport->get_blocks(cmd->se_dev) - in sbc_get_write_same_sectors()
188 cmd->t_task_lba + 1; in sbc_get_write_same_sectors()
193 sbc_execute_write_same_unmap(struct se_cmd *cmd) in sbc_execute_write_same_unmap() argument
195 struct exec_cmd_ops *ops = cmd->protocol_data; in sbc_execute_write_same_unmap()
196 sector_t nolb = sbc_get_write_same_sectors(cmd); in sbc_execute_write_same_unmap()
200 ret = ops->execute_unmap(cmd, cmd->t_task_lba, nolb); in sbc_execute_write_same_unmap()
205 target_complete_cmd(cmd, SAM_STAT_GOOD); in sbc_execute_write_same_unmap()
210 sbc_emulate_noop(struct se_cmd *cmd) in sbc_emulate_noop() argument
212 target_complete_cmd(cmd, SAM_STAT_GOOD); in sbc_emulate_noop()
216 static inline u32 sbc_get_size(struct se_cmd *cmd, u32 sectors) in sbc_get_size() argument
218 return cmd->se_dev->dev_attrib.block_size * sectors; in sbc_get_size()
274 sbc_setup_write_same(struct se_cmd *cmd, unsigned char flags, in sbc_setup_write_same() argument
277 struct se_device *dev = cmd->se_dev; in sbc_setup_write_same()
279 unsigned int sectors = sbc_get_write_same_sectors(cmd); in sbc_setup_write_same()
288 if (sectors > cmd->se_dev->dev_attrib.max_write_same_len) { in sbc_setup_write_same()
290 sectors, cmd->se_dev->dev_attrib.max_write_same_len); in sbc_setup_write_same()
296 if (((cmd->t_task_lba + sectors) < cmd->t_task_lba) || in sbc_setup_write_same()
297 ((cmd->t_task_lba + sectors) > end_lba)) { in sbc_setup_write_same()
299 (unsigned long long)end_lba, cmd->t_task_lba, sectors); in sbc_setup_write_same()
327 cmd->execute_cmd = sbc_execute_write_same_unmap; in sbc_setup_write_same()
333 ret = sbc_check_prot(dev, cmd, flags >> 5, sectors, true); in sbc_setup_write_same()
337 cmd->execute_cmd = ops->execute_write_same; in sbc_setup_write_same()
342 sbc_execute_rw(struct se_cmd *cmd) in sbc_execute_rw() argument
344 struct exec_cmd_ops *ops = cmd->protocol_data; in sbc_execute_rw()
346 return ops->execute_rw(cmd, cmd->t_data_sg, cmd->t_data_nents, in sbc_execute_rw()
347 cmd->data_direction); in sbc_execute_rw()
350 static sense_reason_t compare_and_write_post(struct se_cmd *cmd, bool success, in compare_and_write_post() argument
353 struct se_device *dev = cmd->se_dev; in compare_and_write_post()
356 spin_lock_irq(&cmd->t_state_lock); in compare_and_write_post()
360 if (cmd->scsi_status == SAM_STAT_CHECK_CONDITION) in compare_and_write_post()
363 spin_unlock_irq(&cmd->t_state_lock); in compare_and_write_post()
436 static sense_reason_t compare_and_write_callback(struct se_cmd *cmd, bool success, in compare_and_write_callback() argument
439 struct se_device *dev = cmd->se_dev; in compare_and_write_callback()
445 unsigned int compare_len = (cmd->t_task_nolb * block_size); in compare_and_write_callback()
455 if (!cmd->t_data_sg || !cmd->t_bidi_data_sg) in compare_and_write_callback()
462 WARN_ON(!(cmd->transport_state & in compare_and_write_callback()
469 if (!cmd->data_length) in compare_and_write_callback()
475 if (cmd->scsi_status) { in compare_and_write_callback()
477 " 0x%02x\n", cmd->scsi_status); in compare_and_write_callback()
479 if (cmd->scsi_status == SAM_STAT_CHECK_CONDITION) in compare_and_write_callback()
484 ret = compare_and_write_do_cmp(cmd->t_bidi_data_sg, in compare_and_write_callback()
485 cmd->t_bidi_data_nents, in compare_and_write_callback()
486 cmd->t_data_sg, in compare_and_write_callback()
487 cmd->t_data_nents, in compare_and_write_callback()
497 cmd->sense_info = miscmp_off; in compare_and_write_callback()
502 if (sg_alloc_table(&write_tbl, cmd->t_data_nents, GFP_KERNEL) < 0) { in compare_and_write_callback()
511 sg_miter_start(&m, cmd->t_data_sg, cmd->t_data_nents, SG_MITER_TO_SG); in compare_and_write_callback()
535 cmd->t_data_sg_orig = cmd->t_data_sg; in compare_and_write_callback()
536 cmd->t_data_sg = write_sg; in compare_and_write_callback()
537 cmd->t_data_nents_orig = cmd->t_data_nents; in compare_and_write_callback()
538 cmd->t_data_nents = 1; in compare_and_write_callback()
540 cmd->sam_task_attr = TCM_HEAD_TAG; in compare_and_write_callback()
541 cmd->transport_complete_callback = compare_and_write_post; in compare_and_write_callback()
546 cmd->execute_cmd = sbc_execute_rw; in compare_and_write_callback()
548 spin_lock_irq(&cmd->t_state_lock); in compare_and_write_callback()
549 cmd->t_state = TRANSPORT_PROCESSING; in compare_and_write_callback()
550 cmd->transport_state |= CMD_T_ACTIVE | CMD_T_SENT; in compare_and_write_callback()
551 spin_unlock_irq(&cmd->t_state_lock); in compare_and_write_callback()
553 __target_execute_cmd(cmd, false); in compare_and_write_callback()
568 sbc_compare_and_write(struct se_cmd *cmd) in sbc_compare_and_write() argument
570 struct exec_cmd_ops *ops = cmd->protocol_data; in sbc_compare_and_write()
571 struct se_device *dev = cmd->se_dev; in sbc_compare_and_write()
580 cmd->transport_complete_callback = NULL; in sbc_compare_and_write()
588 cmd->data_length = cmd->t_task_nolb * dev->dev_attrib.block_size; in sbc_compare_and_write()
590 ret = ops->execute_rw(cmd, cmd->t_bidi_data_sg, cmd->t_bidi_data_nents, in sbc_compare_and_write()
593 cmd->transport_complete_callback = NULL; in sbc_compare_and_write()
607 bool is_write, struct se_cmd *cmd) in sbc_set_prot_op_checks() argument
610 cmd->prot_op = fabric_prot ? TARGET_PROT_DOUT_STRIP : in sbc_set_prot_op_checks()
616 cmd->prot_checks = 0; in sbc_set_prot_op_checks()
620 cmd->prot_checks = TARGET_DIF_CHECK_GUARD; in sbc_set_prot_op_checks()
622 cmd->prot_checks |= TARGET_DIF_CHECK_REFTAG; in sbc_set_prot_op_checks()
626 cmd->prot_checks = TARGET_DIF_CHECK_REFTAG; in sbc_set_prot_op_checks()
629 cmd->prot_checks = TARGET_DIF_CHECK_GUARD; in sbc_set_prot_op_checks()
636 cmd->prot_op = fabric_prot ? TARGET_PROT_DIN_INSERT : in sbc_set_prot_op_checks()
643 cmd->prot_checks = TARGET_DIF_CHECK_GUARD; in sbc_set_prot_op_checks()
645 cmd->prot_checks |= TARGET_DIF_CHECK_REFTAG; in sbc_set_prot_op_checks()
649 cmd->prot_checks = TARGET_DIF_CHECK_REFTAG; in sbc_set_prot_op_checks()
652 cmd->prot_checks = 0; in sbc_set_prot_op_checks()
655 cmd->prot_checks = TARGET_DIF_CHECK_GUARD; in sbc_set_prot_op_checks()
667 sbc_check_prot(struct se_device *dev, struct se_cmd *cmd, unsigned char protect, in sbc_check_prot() argument
670 int sp_ops = cmd->se_sess->sup_prot_ops; in sbc_check_prot()
674 if (!cmd->t_prot_sg || !cmd->t_prot_nents) { in sbc_check_prot()
676 !dev->dev_attrib.pi_prot_type && !cmd->se_sess->sess_prot_type)) { in sbc_check_prot()
681 if (cmd->prot_pto) in sbc_check_prot()
687 cmd->reftag_seed = 0xffffffff; in sbc_check_prot()
693 cmd->reftag_seed = cmd->t_task_lba; in sbc_check_prot()
696 cmd->reftag_seed = cmd->t_task_lba; in sbc_check_prot()
708 if (fabric_prot && cmd->se_sess->sess_prot_type) { in sbc_check_prot()
709 pi_prot_type = cmd->se_sess->sess_prot_type; in sbc_check_prot()
717 "PROTECT: 0x%02x\n", cmd->t_task_cdb[0], protect); in sbc_check_prot()
721 if (sbc_set_prot_op_checks(protect, fabric_prot, pi_prot_type, is_write, cmd)) in sbc_check_prot()
724 cmd->prot_type = pi_prot_type; in sbc_check_prot()
725 cmd->prot_length = dev->prot_length * sectors; in sbc_check_prot()
734 cmd->data_length = sectors * dev->dev_attrib.block_size; in sbc_check_prot()
738 __func__, cmd->prot_type, cmd->data_length, cmd->prot_length, in sbc_check_prot()
739 cmd->prot_op, cmd->prot_checks); in sbc_check_prot()
745 sbc_check_dpofua(struct se_device *dev, struct se_cmd *cmd, unsigned char *cdb) in sbc_check_dpofua() argument
762 cmd->se_cmd_flags |= SCF_FUA; in sbc_check_dpofua()
768 sbc_parse_cdb(struct se_cmd *cmd, struct exec_cmd_ops *ops) in sbc_parse_cdb() argument
770 struct se_device *dev = cmd->se_dev; in sbc_parse_cdb()
771 unsigned char *cdb = cmd->t_task_cdb; in sbc_parse_cdb()
776 cmd->protocol_data = ops; in sbc_parse_cdb()
781 cmd->t_task_lba = transport_lba_21(cdb); in sbc_parse_cdb()
782 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; in sbc_parse_cdb()
783 cmd->execute_cmd = sbc_execute_rw; in sbc_parse_cdb()
787 cmd->t_task_lba = transport_lba_32(cdb); in sbc_parse_cdb()
789 if (sbc_check_dpofua(dev, cmd, cdb)) in sbc_parse_cdb()
792 ret = sbc_check_prot(dev, cmd, cdb[1] >> 5, sectors, false); in sbc_parse_cdb()
796 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; in sbc_parse_cdb()
797 cmd->execute_cmd = sbc_execute_rw; in sbc_parse_cdb()
801 cmd->t_task_lba = transport_lba_32(cdb); in sbc_parse_cdb()
803 if (sbc_check_dpofua(dev, cmd, cdb)) in sbc_parse_cdb()
806 ret = sbc_check_prot(dev, cmd, cdb[1] >> 5, sectors, false); in sbc_parse_cdb()
810 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; in sbc_parse_cdb()
811 cmd->execute_cmd = sbc_execute_rw; in sbc_parse_cdb()
815 cmd->t_task_lba = transport_lba_64(cdb); in sbc_parse_cdb()
817 if (sbc_check_dpofua(dev, cmd, cdb)) in sbc_parse_cdb()
820 ret = sbc_check_prot(dev, cmd, cdb[1] >> 5, sectors, false); in sbc_parse_cdb()
824 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; in sbc_parse_cdb()
825 cmd->execute_cmd = sbc_execute_rw; in sbc_parse_cdb()
829 cmd->t_task_lba = transport_lba_21(cdb); in sbc_parse_cdb()
830 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; in sbc_parse_cdb()
831 cmd->execute_cmd = sbc_execute_rw; in sbc_parse_cdb()
836 cmd->t_task_lba = transport_lba_32(cdb); in sbc_parse_cdb()
838 if (sbc_check_dpofua(dev, cmd, cdb)) in sbc_parse_cdb()
841 ret = sbc_check_prot(dev, cmd, cdb[1] >> 5, sectors, true); in sbc_parse_cdb()
845 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; in sbc_parse_cdb()
846 cmd->execute_cmd = sbc_execute_rw; in sbc_parse_cdb()
850 cmd->t_task_lba = transport_lba_32(cdb); in sbc_parse_cdb()
852 if (sbc_check_dpofua(dev, cmd, cdb)) in sbc_parse_cdb()
855 ret = sbc_check_prot(dev, cmd, cdb[1] >> 5, sectors, true); in sbc_parse_cdb()
859 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; in sbc_parse_cdb()
860 cmd->execute_cmd = sbc_execute_rw; in sbc_parse_cdb()
865 cmd->t_task_lba = transport_lba_64(cdb); in sbc_parse_cdb()
867 if (sbc_check_dpofua(dev, cmd, cdb)) in sbc_parse_cdb()
870 ret = sbc_check_prot(dev, cmd, cdb[1] >> 5, sectors, true); in sbc_parse_cdb()
874 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; in sbc_parse_cdb()
875 cmd->execute_cmd = sbc_execute_rw; in sbc_parse_cdb()
889 size = sbc_get_size(cmd, 1); in sbc_parse_cdb()
890 cmd->t_task_lba = get_unaligned_be64(&cdb[12]); in sbc_parse_cdb()
892 ret = sbc_setup_write_same(cmd, cdb[10], ops); in sbc_parse_cdb()
920 if (sbc_check_dpofua(dev, cmd, cdb)) in sbc_parse_cdb()
927 size = 2 * sbc_get_size(cmd, sectors); in sbc_parse_cdb()
928 cmd->t_task_lba = get_unaligned_be64(&cdb[2]); in sbc_parse_cdb()
929 cmd->t_task_nolb = sectors; in sbc_parse_cdb()
930 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB | SCF_COMPARE_AND_WRITE; in sbc_parse_cdb()
931 cmd->execute_cmd = sbc_compare_and_write; in sbc_parse_cdb()
932 cmd->transport_complete_callback = compare_and_write_callback; in sbc_parse_cdb()
936 cmd->execute_cmd = sbc_emulate_readcapacity; in sbc_parse_cdb()
939 switch (cmd->t_task_cdb[1] & 0x1f) { in sbc_parse_cdb()
941 cmd->execute_cmd = sbc_emulate_readcapacity_16; in sbc_parse_cdb()
944 cmd->execute_cmd = target_emulate_report_referrals; in sbc_parse_cdb()
948 cmd->t_task_cdb[1] & 0x1f); in sbc_parse_cdb()
957 cmd->t_task_lba = transport_lba_32(cdb); in sbc_parse_cdb()
960 cmd->t_task_lba = transport_lba_64(cdb); in sbc_parse_cdb()
963 cmd->execute_cmd = ops->execute_sync_cache; in sbc_parse_cdb()
967 cmd->execute_cmd = sbc_emulate_noop; in sbc_parse_cdb()
979 cmd->execute_cmd = sbc_execute_unmap; in sbc_parse_cdb()
988 size = sbc_get_size(cmd, 1); in sbc_parse_cdb()
989 cmd->t_task_lba = get_unaligned_be64(&cdb[2]); in sbc_parse_cdb()
991 ret = sbc_setup_write_same(cmd, cdb[1], ops); in sbc_parse_cdb()
1002 size = sbc_get_size(cmd, 1); in sbc_parse_cdb()
1003 cmd->t_task_lba = get_unaligned_be32(&cdb[2]); in sbc_parse_cdb()
1009 ret = sbc_setup_write_same(cmd, cdb[1], ops); in sbc_parse_cdb()
1018 cmd->t_task_lba = transport_lba_32(cdb); in sbc_parse_cdb()
1021 cmd->t_task_lba = transport_lba_64(cdb); in sbc_parse_cdb()
1023 cmd->execute_cmd = sbc_emulate_noop; in sbc_parse_cdb()
1035 cmd->execute_cmd = sbc_emulate_noop; in sbc_parse_cdb()
1039 cmd->execute_cmd = sbc_emulate_startstop; in sbc_parse_cdb()
1042 ret = spc_parse_cdb(cmd, &size); in sbc_parse_cdb()
1048 if (!cmd->execute_cmd) in sbc_parse_cdb()
1051 if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) { in sbc_parse_cdb()
1055 if (((cmd->t_task_lba + sectors) < cmd->t_task_lba) || in sbc_parse_cdb()
1056 ((cmd->t_task_lba + sectors) > end_lba)) { in sbc_parse_cdb()
1059 end_lba, cmd->t_task_lba, sectors); in sbc_parse_cdb()
1063 if (!(cmd->se_cmd_flags & SCF_COMPARE_AND_WRITE)) in sbc_parse_cdb()
1064 size = sbc_get_size(cmd, sectors); in sbc_parse_cdb()
1067 return target_cmd_size_check(cmd, size); in sbc_parse_cdb()
1078 sbc_execute_unmap(struct se_cmd *cmd) in sbc_execute_unmap() argument
1080 struct exec_cmd_ops *ops = cmd->protocol_data; in sbc_execute_unmap()
1081 struct se_device *dev = cmd->se_dev; in sbc_execute_unmap()
1090 if (cmd->t_task_cdb[1]) in sbc_execute_unmap()
1093 if (cmd->data_length == 0) { in sbc_execute_unmap()
1094 target_complete_cmd(cmd, SAM_STAT_GOOD); in sbc_execute_unmap()
1098 if (cmd->data_length < 8) { in sbc_execute_unmap()
1100 cmd->data_length); in sbc_execute_unmap()
1104 buf = transport_kmap_data_sg(cmd); in sbc_execute_unmap()
1111 size = cmd->data_length - 8; in sbc_execute_unmap()
1114 cmd->data_length, bd_dl); in sbc_execute_unmap()
1145 ret = ops->execute_unmap(cmd, lba, range); in sbc_execute_unmap()
1155 transport_kunmap_data_sg(cmd); in sbc_execute_unmap()
1157 target_complete_cmd(cmd, SAM_STAT_GOOD); in sbc_execute_unmap()
1162 sbc_dif_generate(struct se_cmd *cmd) in sbc_dif_generate() argument
1164 struct se_device *dev = cmd->se_dev; in sbc_dif_generate()
1166 struct scatterlist *dsg = cmd->t_data_sg, *psg; in sbc_dif_generate()
1167 sector_t sector = cmd->t_task_lba; in sbc_dif_generate()
1172 for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) { in sbc_dif_generate()
1210 if (cmd->prot_type == TARGET_DIF_TYPE1_PROT) in sbc_dif_generate()
1216 (cmd->data_direction == DMA_TO_DEVICE) ? in sbc_dif_generate()
1230 sbc_dif_v1_verify(struct se_cmd *cmd, struct t10_pi_tuple *sdt, in sbc_dif_v1_verify() argument
1235 if (!(cmd->prot_checks & TARGET_DIF_CHECK_GUARD)) in sbc_dif_v1_verify()
1248 if (!(cmd->prot_checks & TARGET_DIF_CHECK_REFTAG)) in sbc_dif_v1_verify()
1251 if (cmd->prot_type == TARGET_DIF_TYPE1_PROT && in sbc_dif_v1_verify()
1259 if (cmd->prot_type == TARGET_DIF_TYPE2_PROT && in sbc_dif_v1_verify()
1270 void sbc_dif_copy_prot(struct se_cmd *cmd, unsigned int sectors, bool read, in sbc_dif_copy_prot() argument
1273 struct se_device *dev = cmd->se_dev; in sbc_dif_copy_prot()
1284 for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) { in sbc_dif_copy_prot()
1316 sbc_dif_verify(struct se_cmd *cmd, sector_t start, unsigned int sectors, in sbc_dif_verify() argument
1319 struct se_device *dev = cmd->se_dev; in sbc_dif_verify()
1321 struct scatterlist *dsg = cmd->t_data_sg; in sbc_dif_verify()
1378 rc = sbc_dif_v1_verify(cmd, sdt, crc, sector, ei_lba); in sbc_dif_verify()
1382 cmd->sense_info = sector; in sbc_dif_verify()