Lines Matching +full:write +full:- +full:protect
1 // SPDX-License-Identifier: GPL-2.0-or-later
5 * (c) Copyright 2002-2013 Datera, Inc.
13 #include <linux/crc-t10dif.h>
14 #include <linux/t10-pi.h>
34 struct se_device *dev = cmd->se_dev; in sbc_emulate_readcapacity()
35 unsigned char *cdb = cmd->t_task_cdb; in sbc_emulate_readcapacity()
36 unsigned long long blocks_long = dev->transport->get_blocks(dev); in sbc_emulate_readcapacity()
42 * SBC-2 says: in sbc_emulate_readcapacity()
49 * In SBC-3, these fields are obsolete, but some SCSI in sbc_emulate_readcapacity()
51 * follow SBC-2. in sbc_emulate_readcapacity()
62 put_unaligned_be32(dev->dev_attrib.block_size, &buf[4]); in sbc_emulate_readcapacity()
66 memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length)); in sbc_emulate_readcapacity()
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()
79 int pi_prot_type = dev->dev_attrib.pi_prot_type; in sbc_emulate_readcapacity_16()
83 unsigned long long blocks = dev->transport->get_blocks(dev); in sbc_emulate_readcapacity_16()
87 put_unaligned_be32(dev->dev_attrib.block_size, &buf[8]); in sbc_emulate_readcapacity_16()
91 if (sess->sup_prot_ops & (TARGET_PROT_DIN_PASS | TARGET_PROT_DOUT_PASS)) { in sbc_emulate_readcapacity_16()
93 * Only override a device's pi_prot_type if no T10-PI is in sbc_emulate_readcapacity_16()
97 pi_prot_type = sess->sess_prot_type; in sbc_emulate_readcapacity_16()
100 buf[12] = (pi_prot_type - 1) << 1 | 0x1; in sbc_emulate_readcapacity_16()
103 if (dev->transport->get_lbppbe) in sbc_emulate_readcapacity_16()
104 buf[13] = dev->transport->get_lbppbe(dev) & 0x0f; in sbc_emulate_readcapacity_16()
106 if (dev->transport->get_alignment_offset_lbas) { in sbc_emulate_readcapacity_16()
107 u16 lalba = dev->transport->get_alignment_offset_lbas(dev); in sbc_emulate_readcapacity_16()
116 if (dev->dev_attrib.emulate_tpu || dev->dev_attrib.emulate_tpws) { in sbc_emulate_readcapacity_16()
121 * an UNMAP or WRITE SAME w/ unmap bit (sbc3r36 5.16.2) in sbc_emulate_readcapacity_16()
123 if (dev->dev_attrib.unmap_zeroes_data) in sbc_emulate_readcapacity_16()
129 memcpy(rbuf, buf, min_t(u32, sizeof(buf), cmd->data_length)); in sbc_emulate_readcapacity_16()
140 unsigned char *cdb = cmd->t_task_cdb; in sbc_emulate_startstop()
152 * POWER CONDITION 0h START_VALID - process START and LOEJ in sbc_emulate_startstop()
159 * LOEJ 0h - nothing to load or unload in sbc_emulate_startstop()
160 * START 1h - we are ready in sbc_emulate_startstop()
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()
182 * the remaining range based on ->get_blocks() - starting LBA. 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()
195 struct exec_cmd_ops *ops = cmd->protocol_data; in sbc_execute_write_same_unmap()
200 ret = ops->execute_unmap(cmd, cmd->t_task_lba, nolb); in sbc_execute_write_same_unmap()
218 return cmd->se_dev->dev_attrib.block_size * sectors; in sbc_get_size()
224 * Use 8-bit sector value. SBC-3 says: in transport_get_sectors_6()
277 struct se_device *dev = cmd->se_dev; in sbc_setup_write_same()
278 sector_t end_lba = dev->transport->get_blocks(dev) + 1; 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()
305 pr_warn("WRITE SAME with ANCHOR not supported\n"); in sbc_setup_write_same()
310 pr_warn("WRITE SAME with NDOB not supported\n"); in sbc_setup_write_same()
319 if (!ops->execute_unmap) in sbc_setup_write_same()
322 if (!dev->dev_attrib.emulate_tpws) { in sbc_setup_write_same()
327 cmd->execute_cmd = sbc_execute_write_same_unmap; in sbc_setup_write_same()
330 if (!ops->execute_write_same) in sbc_setup_write_same()
337 cmd->execute_cmd = ops->execute_write_same; in sbc_setup_write_same()
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()
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()
366 * Unlock ->caw_sem originally obtained during sbc_compare_and_write() in compare_and_write_post()
369 up(&dev->caw_sem); in compare_and_write_post()
408 unsigned int len = min(sg->length, cmp_len); in compare_and_write_do_cmp()
426 cmp_len -= len; in compare_and_write_do_cmp()
430 pr_debug("COMPARE AND WRITE read data matches compare data\n"); in compare_and_write_do_cmp()
439 struct se_device *dev = cmd->se_dev; in compare_and_write_callback()
444 unsigned int block_size = dev->dev_attrib.block_size; in compare_and_write_callback()
445 unsigned int compare_len = (cmd->t_task_nolb * block_size); in compare_and_write_callback()
453 * which will not have taken ->caw_sem yet.. in compare_and_write_callback()
455 if (!cmd->t_data_sg || !cmd->t_bidi_data_sg) in compare_and_write_callback()
460 * we don't have to perform the write operation. in compare_and_write_callback()
462 WARN_ON(!(cmd->transport_state & in compare_and_write_callback()
467 * Handle special case for zero-length COMPARE_AND_WRITE in compare_and_write_callback()
469 if (!cmd->data_length) in compare_and_write_callback()
472 * Immediately exit + release dev->caw_sem if command has already in compare_and_write_callback()
473 * been failed with a non-zero SCSI status. 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()
492 * SBC-4 r15: 5.3 COMPARE AND WRITE command in compare_and_write_callback()
493 * In the sense data (see 4.18 and SPC-5) the offset from the in compare_and_write_callback()
494 * start of the Data-Out Buffer to the first byte of data that 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()
520 m.piter.sg->offset + block_size); in compare_and_write_callback()
524 m.piter.sg->offset); in compare_and_write_callback()
526 len -= block_size; in compare_and_write_callback()
532 * assignments, to be released in transport_free_pages() -> 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()
543 * Now reset ->execute_cmd() to the normal sbc_execute_rw() handler in compare_and_write_callback()
544 * for submitting the adjusted SGL to write instance user-data. 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()
559 * In the MISCOMPARE or failure case, unlock ->caw_sem obtained in in compare_and_write_callback()
562 up(&dev->caw_sem); in compare_and_write_callback()
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()
576 * comparision using SGLs at cmd->t_bidi_data_sg.. in sbc_compare_and_write()
578 rc = down_interruptible(&dev->caw_sem); in sbc_compare_and_write()
580 cmd->transport_complete_callback = NULL; in sbc_compare_and_write()
584 * Reset cmd->data_length to individual block_size in order to not 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()
594 up(&dev->caw_sem); in sbc_compare_and_write()
598 * Unlock of dev->caw_sem to occur in compare_and_write_callback() in sbc_compare_and_write()
600 * of WRITE instance user-data. in sbc_compare_and_write()
606 sbc_set_prot_op_checks(u8 protect, bool fabric_prot, enum target_prot_type prot_type, in sbc_set_prot_op_checks() argument
610 cmd->prot_op = fabric_prot ? TARGET_PROT_DOUT_STRIP : in sbc_set_prot_op_checks()
611 protect ? TARGET_PROT_DOUT_PASS : in sbc_set_prot_op_checks()
613 switch (protect) { 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()
632 pr_err("Unsupported protect field %d\n", protect); in sbc_set_prot_op_checks()
633 return -EINVAL; in sbc_set_prot_op_checks()
636 cmd->prot_op = fabric_prot ? TARGET_PROT_DIN_INSERT : in sbc_set_prot_op_checks()
637 protect ? TARGET_PROT_DIN_PASS : in sbc_set_prot_op_checks()
639 switch (protect) { 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()
658 pr_err("Unsupported protect field %d\n", protect); in sbc_set_prot_op_checks()
659 return -EINVAL; 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()
671 int pi_prot_type = dev->dev_attrib.pi_prot_type; in sbc_check_prot()
674 if (!cmd->t_prot_sg || !cmd->t_prot_nents) { in sbc_check_prot()
675 if (unlikely(protect && in sbc_check_prot()
676 !dev->dev_attrib.pi_prot_type && !cmd->se_sess->sess_prot_type)) { in sbc_check_prot()
677 pr_err("CDB contains protect bit, but device + fabric does" in sbc_check_prot()
678 " not advertise PROTECT=1 feature bit\n"); in sbc_check_prot()
681 if (cmd->prot_pto) in sbc_check_prot()
685 switch (dev->dev_attrib.pi_prot_type) { in sbc_check_prot()
687 cmd->reftag_seed = 0xffffffff; in sbc_check_prot()
690 if (protect) 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()
700 * See if the fabric supports T10-PI, and the session has been in sbc_check_prot()
701 * configured to allow export PROTECT=1 feature bit with backend in sbc_check_prot()
702 * devices that don't support T10-PI. 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()
712 if (!protect) 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()
733 if (protect) 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()
752 return -EINVAL; in sbc_check_dpofua()
758 " does not advertise support for FUA write\n", in sbc_check_dpofua()
760 return -EINVAL; in sbc_check_dpofua()
762 cmd->se_cmd_flags |= SCF_FUA; in sbc_check_dpofua()
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()
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()
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()
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()
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()
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()
874 cmd->se_cmd_flags |= SCF_SCSI_DATA_CDB; in sbc_parse_cdb()
875 cmd->execute_cmd = sbc_execute_rw; in sbc_parse_cdb()
890 cmd->t_task_lba = get_unaligned_be64(&cdb[12]); in sbc_parse_cdb()
904 if (!dev->dev_attrib.emulate_caw) { in sbc_parse_cdb()
906 dev->se_hba->backend->ops->name, in sbc_parse_cdb()
907 config_item_name(&dev->dev_group.cg_item), in sbc_parse_cdb()
908 dev->t10_wwn.unit_serial); 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()
962 if (ops->execute_sync_cache) { 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()
970 if (!ops->execute_unmap) in sbc_parse_cdb()
973 if (!dev->dev_attrib.emulate_tpu) { in sbc_parse_cdb()
979 cmd->execute_cmd = sbc_execute_unmap; in sbc_parse_cdb()
989 cmd->t_task_lba = get_unaligned_be64(&cdb[2]); in sbc_parse_cdb()
1003 cmd->t_task_lba = get_unaligned_be32(&cdb[2]); 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()
1029 * There are still clients out there which use these old SCSI-2 in sbc_parse_cdb()
1031 * guest systems, connected via SCSI command pass-through to 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()
1048 if (!cmd->execute_cmd) in sbc_parse_cdb()
1051 if (cmd->se_cmd_flags & SCF_SCSI_DATA_CDB) { in sbc_parse_cdb()
1054 end_lba = dev->transport->get_blocks(dev) + 1; 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()
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()
1098 if (cmd->data_length < 8) { in sbc_execute_unmap()
1100 cmd->data_length); in sbc_execute_unmap()
1111 size = cmd->data_length - 8; in sbc_execute_unmap()
1114 cmd->data_length, bd_dl); in sbc_execute_unmap()
1118 if (size / 16 > dev->dev_attrib.max_unmap_block_desc_count) { in sbc_execute_unmap()
1126 " ptr: %p\n", dev->transport->name, dl, bd_dl, size, ptr); in sbc_execute_unmap()
1134 if (range > dev->dev_attrib.max_unmap_lba_count) { in sbc_execute_unmap()
1139 if (lba + range > dev->transport->get_blocks(dev) + 1) { in sbc_execute_unmap()
1145 ret = ops->execute_unmap(cmd, lba, range); in sbc_execute_unmap()
1151 size -= 16; in sbc_execute_unmap()
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()
1170 unsigned int block_size = dev->dev_attrib.block_size; in sbc_dif_generate()
1172 for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) { in sbc_dif_generate()
1173 paddr = kmap_atomic(sg_page(psg)) + psg->offset; in sbc_dif_generate()
1174 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; in sbc_dif_generate()
1176 for (j = 0; j < psg->length; in sbc_dif_generate()
1181 if (offset >= dsg->length) { in sbc_dif_generate()
1182 offset -= dsg->length; in sbc_dif_generate()
1183 kunmap_atomic(daddr - dsg->offset); in sbc_dif_generate()
1186 kunmap_atomic(paddr - psg->offset); in sbc_dif_generate()
1189 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; in sbc_dif_generate()
1193 avail = min(block_size, dsg->length - offset); in sbc_dif_generate()
1196 kunmap_atomic(daddr - dsg->offset); in sbc_dif_generate()
1199 kunmap_atomic(paddr - psg->offset); in sbc_dif_generate()
1202 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; in sbc_dif_generate()
1203 offset = block_size - avail; in sbc_dif_generate()
1209 sdt->guard_tag = cpu_to_be16(crc); in sbc_dif_generate()
1210 if (cmd->prot_type == TARGET_DIF_TYPE1_PROT) in sbc_dif_generate()
1211 sdt->ref_tag = cpu_to_be32(sector & 0xffffffff); in sbc_dif_generate()
1212 sdt->app_tag = 0; in sbc_dif_generate()
1216 (cmd->data_direction == DMA_TO_DEVICE) ? in sbc_dif_generate()
1217 "WRITE" : "READ", (unsigned long long)sector, in sbc_dif_generate()
1218 sdt->guard_tag, sdt->app_tag, in sbc_dif_generate()
1219 be32_to_cpu(sdt->ref_tag)); in sbc_dif_generate()
1224 kunmap_atomic(daddr - dsg->offset); in sbc_dif_generate()
1225 kunmap_atomic(paddr - psg->offset); in sbc_dif_generate()
1235 if (!(cmd->prot_checks & TARGET_DIF_CHECK_GUARD)) in sbc_dif_v1_verify()
1240 if (sdt->guard_tag != csum) { in sbc_dif_v1_verify()
1243 be16_to_cpu(sdt->guard_tag), be16_to_cpu(csum)); 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()
1252 be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) { in sbc_dif_v1_verify()
1255 be32_to_cpu(sdt->ref_tag), (u32)(sector & 0xffffffff)); in sbc_dif_v1_verify()
1259 if (cmd->prot_type == TARGET_DIF_TYPE2_PROT && in sbc_dif_v1_verify()
1260 be32_to_cpu(sdt->ref_tag) != ei_lba) { in sbc_dif_v1_verify()
1263 be32_to_cpu(sdt->ref_tag), ei_lba); in sbc_dif_v1_verify()
1273 struct se_device *dev = cmd->se_dev; in sbc_dif_copy_prot()
1282 left = sectors * dev->prot_length; in sbc_dif_copy_prot()
1284 for_each_sg(cmd->t_prot_sg, psg, cmd->t_prot_nents, i) { in sbc_dif_copy_prot()
1287 paddr = kmap_atomic(sg_page(psg)) + psg->offset; in sbc_dif_copy_prot()
1288 psg_len = min(left, psg->length); in sbc_dif_copy_prot()
1290 len = min(psg_len, sg->length - offset); in sbc_dif_copy_prot()
1291 addr = kmap_atomic(sg_page(sg)) + sg->offset + offset; in sbc_dif_copy_prot()
1298 left -= len; in sbc_dif_copy_prot()
1301 psg_len -= len; in sbc_dif_copy_prot()
1303 kunmap_atomic(addr - sg->offset - offset); in sbc_dif_copy_prot()
1305 if (offset >= sg->length) { in sbc_dif_copy_prot()
1310 kunmap_atomic(paddr - psg->offset); in sbc_dif_copy_prot()
1319 struct se_device *dev = cmd->se_dev; in sbc_dif_verify()
1321 struct scatterlist *dsg = cmd->t_data_sg; in sbc_dif_verify()
1327 unsigned int block_size = dev->dev_attrib.block_size; in sbc_dif_verify()
1330 paddr = kmap_atomic(sg_page(psg)) + psg->offset; in sbc_dif_verify()
1331 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; in sbc_dif_verify()
1333 for (i = psg_off; i < psg->length && in sbc_dif_verify()
1339 if (dsg_off >= dsg->length) { in sbc_dif_verify()
1340 dsg_off -= dsg->length; in sbc_dif_verify()
1341 kunmap_atomic(daddr - dsg->offset); in sbc_dif_verify()
1344 kunmap_atomic(paddr - psg->offset); in sbc_dif_verify()
1347 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; in sbc_dif_verify()
1354 (unsigned long long)sector, sdt->guard_tag, in sbc_dif_verify()
1355 sdt->app_tag, be32_to_cpu(sdt->ref_tag)); in sbc_dif_verify()
1357 if (sdt->app_tag == T10_PI_APP_ESCAPE) { in sbc_dif_verify()
1362 avail = min(block_size, dsg->length - dsg_off); in sbc_dif_verify()
1365 kunmap_atomic(daddr - dsg->offset); in sbc_dif_verify()
1368 kunmap_atomic(paddr - psg->offset); in sbc_dif_verify()
1371 daddr = kmap_atomic(sg_page(dsg)) + dsg->offset; in sbc_dif_verify()
1372 dsg_off = block_size - avail; in sbc_dif_verify()
1380 kunmap_atomic(daddr - dsg->offset); in sbc_dif_verify()
1381 kunmap_atomic(paddr - psg->offset); in sbc_dif_verify()
1382 cmd->sense_info = sector; in sbc_dif_verify()
1391 kunmap_atomic(daddr - dsg->offset); in sbc_dif_verify()
1392 kunmap_atomic(paddr - psg->offset); in sbc_dif_verify()