1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * SCSI Block Commands (SBC) parsing and emulation.
5 * (c) Copyright 2002-2013 Datera, Inc.
7 * Nicholas A. Bellinger <nab@kernel.org>
10 #include <linux/kernel.h>
11 #include <linux/module.h>
12 #include <linux/ratelimit.h>
13 #include <linux/crc-t10dif.h>
14 #include <linux/t10-pi.h>
15 #include <asm/unaligned.h>
16 #include <scsi/scsi_proto.h>
17 #include <scsi/scsi_tcq.h>
19 #include <target/target_core_base.h>
20 #include <target/target_core_backend.h>
21 #include <target/target_core_fabric.h>
23 #include "target_core_internal.h"
24 #include "target_core_ua.h"
25 #include "target_core_alua.h"
28 sbc_check_prot(struct se_device
*, struct se_cmd
*, unsigned char *, u32
, bool);
29 static sense_reason_t
sbc_execute_unmap(struct se_cmd
*cmd
);
32 sbc_emulate_readcapacity(struct se_cmd
*cmd
)
34 struct se_device
*dev
= cmd
->se_dev
;
35 unsigned char *cdb
= cmd
->t_task_cdb
;
36 unsigned long long blocks_long
= dev
->transport
->get_blocks(dev
);
43 * If the PMI bit is set to zero and the LOGICAL BLOCK
44 * ADDRESS field is not set to zero, the device server shall
45 * terminate the command with CHECK CONDITION status with
46 * the sense key set to ILLEGAL REQUEST and the additional
47 * sense code set to INVALID FIELD IN CDB.
49 * In SBC-3, these fields are obsolete, but some SCSI
50 * compliance tests actually check this, so we might as well
53 if (!(cdb
[8] & 1) && !!(cdb
[2] | cdb
[3] | cdb
[4] | cdb
[5]))
54 return TCM_INVALID_CDB_FIELD
;
56 if (blocks_long
>= 0x00000000ffffffff)
59 blocks
= (u32
)blocks_long
;
61 put_unaligned_be32(blocks
, &buf
[0]);
62 put_unaligned_be32(dev
->dev_attrib
.block_size
, &buf
[4]);
64 rbuf
= transport_kmap_data_sg(cmd
);
66 memcpy(rbuf
, buf
, min_t(u32
, sizeof(buf
), cmd
->data_length
));
67 transport_kunmap_data_sg(cmd
);
70 target_complete_cmd_with_length(cmd
, GOOD
, 8);
75 sbc_emulate_readcapacity_16(struct se_cmd
*cmd
)
77 struct se_device
*dev
= cmd
->se_dev
;
78 struct se_session
*sess
= cmd
->se_sess
;
79 int pi_prot_type
= dev
->dev_attrib
.pi_prot_type
;
82 unsigned char buf
[32];
83 unsigned long long blocks
= dev
->transport
->get_blocks(dev
);
85 memset(buf
, 0, sizeof(buf
));
86 put_unaligned_be64(blocks
, &buf
[0]);
87 put_unaligned_be32(dev
->dev_attrib
.block_size
, &buf
[8]);
89 * Set P_TYPE and PROT_EN bits for DIF support
91 if (sess
->sup_prot_ops
& (TARGET_PROT_DIN_PASS
| TARGET_PROT_DOUT_PASS
)) {
93 * Only override a device's pi_prot_type if no T10-PI is
94 * available, and sess_prot_type has been explicitly enabled.
97 pi_prot_type
= sess
->sess_prot_type
;
100 buf
[12] = (pi_prot_type
- 1) << 1 | 0x1;
103 if (dev
->transport
->get_lbppbe
)
104 buf
[13] = dev
->transport
->get_lbppbe(dev
) & 0x0f;
106 if (dev
->transport
->get_alignment_offset_lbas
) {
107 u16 lalba
= dev
->transport
->get_alignment_offset_lbas(dev
);
109 put_unaligned_be16(lalba
, &buf
[14]);
113 * Set Thin Provisioning Enable bit following sbc3r22 in section
114 * READ CAPACITY (16) byte 14 if emulate_tpu or emulate_tpws is enabled.
116 if (dev
->dev_attrib
.emulate_tpu
|| dev
->dev_attrib
.emulate_tpws
) {
120 * LBPRZ signifies that zeroes will be read back from an LBA after
121 * an UNMAP or WRITE SAME w/ unmap bit (sbc3r36 5.16.2)
123 if (dev
->dev_attrib
.unmap_zeroes_data
)
127 rbuf
= transport_kmap_data_sg(cmd
);
129 memcpy(rbuf
, buf
, min_t(u32
, sizeof(buf
), cmd
->data_length
));
130 transport_kunmap_data_sg(cmd
);
133 target_complete_cmd_with_length(cmd
, GOOD
, 32);
137 static sense_reason_t
138 sbc_emulate_startstop(struct se_cmd
*cmd
)
140 unsigned char *cdb
= cmd
->t_task_cdb
;
143 * See sbc3r36 section 5.25
144 * Immediate bit should be set since there is nothing to complete
145 * POWER CONDITION MODIFIER 0h
147 if (!(cdb
[1] & 1) || cdb
[2] || cdb
[3])
148 return TCM_INVALID_CDB_FIELD
;
151 * See sbc3r36 section 5.25
152 * POWER CONDITION 0h START_VALID - process START and LOEJ
154 if (cdb
[4] >> 4 & 0xf)
155 return TCM_INVALID_CDB_FIELD
;
158 * See sbc3r36 section 5.25
159 * LOEJ 0h - nothing to load or unload
160 * START 1h - we are ready
162 if (!(cdb
[4] & 1) || (cdb
[4] & 2) || (cdb
[4] & 4))
163 return TCM_INVALID_CDB_FIELD
;
165 target_complete_cmd(cmd
, SAM_STAT_GOOD
);
169 sector_t
sbc_get_write_same_sectors(struct se_cmd
*cmd
)
173 if (cmd
->t_task_cdb
[0] == WRITE_SAME
)
174 num_blocks
= get_unaligned_be16(&cmd
->t_task_cdb
[7]);
175 else if (cmd
->t_task_cdb
[0] == WRITE_SAME_16
)
176 num_blocks
= get_unaligned_be32(&cmd
->t_task_cdb
[10]);
177 else /* WRITE_SAME_32 via VARIABLE_LENGTH_CMD */
178 num_blocks
= get_unaligned_be32(&cmd
->t_task_cdb
[28]);
181 * Use the explicit range when non zero is supplied, otherwise calculate
182 * the remaining range based on ->get_blocks() - starting LBA.
187 return cmd
->se_dev
->transport
->get_blocks(cmd
->se_dev
) -
190 EXPORT_SYMBOL(sbc_get_write_same_sectors
);
192 static sense_reason_t
193 sbc_execute_write_same_unmap(struct se_cmd
*cmd
)
195 struct sbc_ops
*ops
= cmd
->protocol_data
;
196 sector_t nolb
= sbc_get_write_same_sectors(cmd
);
200 ret
= ops
->execute_unmap(cmd
, cmd
->t_task_lba
, nolb
);
205 target_complete_cmd(cmd
, GOOD
);
209 static sense_reason_t
210 sbc_emulate_noop(struct se_cmd
*cmd
)
212 target_complete_cmd(cmd
, GOOD
);
216 static inline u32
sbc_get_size(struct se_cmd
*cmd
, u32 sectors
)
218 return cmd
->se_dev
->dev_attrib
.block_size
* sectors
;
221 static inline u32
transport_get_sectors_6(unsigned char *cdb
)
224 * Use 8-bit sector value. SBC-3 says:
226 * A TRANSFER LENGTH field set to zero specifies that 256
227 * logical blocks shall be written. Any other value
228 * specifies the number of logical blocks that shall be
231 return cdb
[4] ? : 256;
234 static inline u32
transport_get_sectors_10(unsigned char *cdb
)
236 return get_unaligned_be16(&cdb
[7]);
239 static inline u32
transport_get_sectors_12(unsigned char *cdb
)
241 return get_unaligned_be32(&cdb
[6]);
244 static inline u32
transport_get_sectors_16(unsigned char *cdb
)
246 return get_unaligned_be32(&cdb
[10]);
250 * Used for VARIABLE_LENGTH_CDB WRITE_32 and READ_32 variants
252 static inline u32
transport_get_sectors_32(unsigned char *cdb
)
254 return get_unaligned_be32(&cdb
[28]);
258 static inline u32
transport_lba_21(unsigned char *cdb
)
260 return get_unaligned_be24(&cdb
[1]) & 0x1fffff;
263 static inline u32
transport_lba_32(unsigned char *cdb
)
265 return get_unaligned_be32(&cdb
[2]);
268 static inline unsigned long long transport_lba_64(unsigned char *cdb
)
270 return get_unaligned_be64(&cdb
[2]);
274 * For VARIABLE_LENGTH_CDB w/ 32 byte extended CDBs
276 static inline unsigned long long transport_lba_64_ext(unsigned char *cdb
)
278 return get_unaligned_be64(&cdb
[12]);
281 static sense_reason_t
282 sbc_setup_write_same(struct se_cmd
*cmd
, unsigned char *flags
, struct sbc_ops
*ops
)
284 struct se_device
*dev
= cmd
->se_dev
;
285 sector_t end_lba
= dev
->transport
->get_blocks(dev
) + 1;
286 unsigned int sectors
= sbc_get_write_same_sectors(cmd
);
289 if ((flags
[0] & 0x04) || (flags
[0] & 0x02)) {
290 pr_err("WRITE_SAME PBDATA and LBDATA"
291 " bits not supported for Block Discard"
293 return TCM_UNSUPPORTED_SCSI_OPCODE
;
295 if (sectors
> cmd
->se_dev
->dev_attrib
.max_write_same_len
) {
296 pr_warn("WRITE_SAME sectors: %u exceeds max_write_same_len: %u\n",
297 sectors
, cmd
->se_dev
->dev_attrib
.max_write_same_len
);
298 return TCM_INVALID_CDB_FIELD
;
301 * Sanity check for LBA wrap and request past end of device.
303 if (((cmd
->t_task_lba
+ sectors
) < cmd
->t_task_lba
) ||
304 ((cmd
->t_task_lba
+ sectors
) > end_lba
)) {
305 pr_err("WRITE_SAME exceeds last lba %llu (lba %llu, sectors %u)\n",
306 (unsigned long long)end_lba
, cmd
->t_task_lba
, sectors
);
307 return TCM_ADDRESS_OUT_OF_RANGE
;
310 /* We always have ANC_SUP == 0 so setting ANCHOR is always an error */
311 if (flags
[0] & 0x10) {
312 pr_warn("WRITE SAME with ANCHOR not supported\n");
313 return TCM_INVALID_CDB_FIELD
;
316 * Special case for WRITE_SAME w/ UNMAP=1 that ends up getting
317 * translated into block discard requests within backend code.
319 if (flags
[0] & 0x08) {
320 if (!ops
->execute_unmap
)
321 return TCM_UNSUPPORTED_SCSI_OPCODE
;
323 if (!dev
->dev_attrib
.emulate_tpws
) {
324 pr_err("Got WRITE_SAME w/ UNMAP=1, but backend device"
325 " has emulate_tpws disabled\n");
326 return TCM_UNSUPPORTED_SCSI_OPCODE
;
328 cmd
->execute_cmd
= sbc_execute_write_same_unmap
;
331 if (!ops
->execute_write_same
)
332 return TCM_UNSUPPORTED_SCSI_OPCODE
;
334 ret
= sbc_check_prot(dev
, cmd
, &cmd
->t_task_cdb
[0], sectors
, true);
338 cmd
->execute_cmd
= ops
->execute_write_same
;
342 static sense_reason_t
xdreadwrite_callback(struct se_cmd
*cmd
, bool success
,
345 unsigned char *buf
, *addr
;
346 struct scatterlist
*sg
;
348 sense_reason_t ret
= TCM_NO_SENSE
;
355 * From sbc3r22.pdf section 5.48 XDWRITEREAD (10) command
357 * 1) read the specified logical block(s);
358 * 2) transfer logical blocks from the data-out buffer;
359 * 3) XOR the logical blocks transferred from the data-out buffer with
360 * the logical blocks read, storing the resulting XOR data in a buffer;
361 * 4) if the DISABLE WRITE bit is set to zero, then write the logical
362 * blocks transferred from the data-out buffer; and
363 * 5) transfer the resulting XOR data to the data-in buffer.
365 buf
= kmalloc(cmd
->data_length
, GFP_KERNEL
);
367 pr_err("Unable to allocate xor_callback buf\n");
368 return TCM_OUT_OF_RESOURCES
;
371 * Copy the scatterlist WRITE buffer located at cmd->t_data_sg
372 * into the locally allocated *buf
374 sg_copy_to_buffer(cmd
->t_data_sg
,
380 * Now perform the XOR against the BIDI read memory located at
381 * cmd->t_mem_bidi_list
385 for_each_sg(cmd
->t_bidi_data_sg
, sg
, cmd
->t_bidi_data_nents
, count
) {
386 addr
= kmap_atomic(sg_page(sg
));
388 ret
= TCM_OUT_OF_RESOURCES
;
392 for (i
= 0; i
< sg
->length
; i
++)
393 *(addr
+ sg
->offset
+ i
) ^= *(buf
+ offset
+ i
);
395 offset
+= sg
->length
;
404 static sense_reason_t
405 sbc_execute_rw(struct se_cmd
*cmd
)
407 struct sbc_ops
*ops
= cmd
->protocol_data
;
409 return ops
->execute_rw(cmd
, cmd
->t_data_sg
, cmd
->t_data_nents
,
410 cmd
->data_direction
);
413 static sense_reason_t
compare_and_write_post(struct se_cmd
*cmd
, bool success
,
416 struct se_device
*dev
= cmd
->se_dev
;
417 sense_reason_t ret
= TCM_NO_SENSE
;
419 spin_lock_irq(&cmd
->t_state_lock
);
423 if (cmd
->scsi_status
== SAM_STAT_CHECK_CONDITION
)
424 ret
= TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
426 spin_unlock_irq(&cmd
->t_state_lock
);
429 * Unlock ->caw_sem originally obtained during sbc_compare_and_write()
430 * before the original READ I/O submission.
438 * compare @cmp_len bytes of @read_sgl with @cmp_sgl. On miscompare, fill
439 * @miscmp_off and return TCM_MISCOMPARE_VERIFY.
441 static sense_reason_t
442 compare_and_write_do_cmp(struct scatterlist
*read_sgl
, unsigned int read_nents
,
443 struct scatterlist
*cmp_sgl
, unsigned int cmp_nents
,
444 unsigned int cmp_len
, unsigned int *miscmp_off
)
446 unsigned char *buf
= NULL
;
447 struct scatterlist
*sg
;
453 buf
= kzalloc(cmp_len
, GFP_KERNEL
);
455 ret
= TCM_OUT_OF_RESOURCES
;
459 rc
= sg_copy_to_buffer(cmp_sgl
, cmp_nents
, buf
, cmp_len
);
461 pr_err("sg_copy_to_buffer() failed for compare_and_write\n");
462 ret
= TCM_OUT_OF_RESOURCES
;
466 * Compare SCSI READ payload against verify payload
470 for_each_sg(read_sgl
, sg
, read_nents
, i
) {
471 unsigned int len
= min(sg
->length
, cmp_len
);
472 unsigned char *addr
= kmap_atomic(sg_page(sg
));
474 if (memcmp(addr
, buf
+ offset
, len
)) {
477 for (i
= 0; i
< len
&& addr
[i
] == buf
[offset
+ i
]; i
++)
479 *miscmp_off
= offset
+ i
;
480 pr_warn("Detected MISCOMPARE at offset %u\n",
482 ret
= TCM_MISCOMPARE_VERIFY
;
485 if (ret
!= TCM_NO_SENSE
)
493 pr_debug("COMPARE AND WRITE read data matches compare data\n");
499 static sense_reason_t
compare_and_write_callback(struct se_cmd
*cmd
, bool success
,
502 struct se_device
*dev
= cmd
->se_dev
;
503 struct sg_table write_tbl
= { };
504 struct scatterlist
*write_sg
;
505 struct sg_mapping_iter m
;
507 unsigned int block_size
= dev
->dev_attrib
.block_size
;
508 unsigned int compare_len
= (cmd
->t_task_nolb
* block_size
);
509 unsigned int miscmp_off
= 0;
510 sense_reason_t ret
= TCM_NO_SENSE
;
514 * Handle early failure in transport_generic_request_failure(),
515 * which will not have taken ->caw_sem yet..
517 if (!success
&& (!cmd
->t_data_sg
|| !cmd
->t_bidi_data_sg
))
520 * Handle special case for zero-length COMPARE_AND_WRITE
522 if (!cmd
->data_length
)
525 * Immediately exit + release dev->caw_sem if command has already
526 * been failed with a non-zero SCSI status.
528 if (cmd
->scsi_status
) {
529 pr_debug("compare_and_write_callback: non zero scsi_status:"
530 " 0x%02x\n", cmd
->scsi_status
);
532 if (cmd
->scsi_status
== SAM_STAT_CHECK_CONDITION
)
533 ret
= TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
537 ret
= compare_and_write_do_cmp(cmd
->t_bidi_data_sg
,
538 cmd
->t_bidi_data_nents
,
543 if (ret
== TCM_MISCOMPARE_VERIFY
) {
545 * SBC-4 r15: 5.3 COMPARE AND WRITE command
546 * In the sense data (see 4.18 and SPC-5) the offset from the
547 * start of the Data-Out Buffer to the first byte of data that
548 * was not equal shall be reported in the INFORMATION field.
550 cmd
->sense_info
= miscmp_off
;
555 if (sg_alloc_table(&write_tbl
, cmd
->t_data_nents
, GFP_KERNEL
) < 0) {
556 pr_err("Unable to allocate compare_and_write sg\n");
557 ret
= TCM_OUT_OF_RESOURCES
;
560 write_sg
= write_tbl
.sgl
;
564 sg_miter_start(&m
, cmd
->t_data_sg
, cmd
->t_data_nents
, SG_MITER_TO_SG
);
566 * Currently assumes NoLB=1 and SGLs are PAGE_SIZE..
571 if (block_size
< PAGE_SIZE
) {
572 sg_set_page(&write_sg
[i
], m
.page
, block_size
,
573 m
.piter
.sg
->offset
+ block_size
);
576 sg_set_page(&write_sg
[i
], m
.page
, block_size
,
584 * Save the original SGL + nents values before updating to new
585 * assignments, to be released in transport_free_pages() ->
586 * transport_reset_sgl_orig()
588 cmd
->t_data_sg_orig
= cmd
->t_data_sg
;
589 cmd
->t_data_sg
= write_sg
;
590 cmd
->t_data_nents_orig
= cmd
->t_data_nents
;
591 cmd
->t_data_nents
= 1;
593 cmd
->sam_task_attr
= TCM_HEAD_TAG
;
594 cmd
->transport_complete_callback
= compare_and_write_post
;
596 * Now reset ->execute_cmd() to the normal sbc_execute_rw() handler
597 * for submitting the adjusted SGL to write instance user-data.
599 cmd
->execute_cmd
= sbc_execute_rw
;
601 spin_lock_irq(&cmd
->t_state_lock
);
602 cmd
->t_state
= TRANSPORT_PROCESSING
;
603 cmd
->transport_state
|= CMD_T_ACTIVE
| CMD_T_SENT
;
604 spin_unlock_irq(&cmd
->t_state_lock
);
606 __target_execute_cmd(cmd
, false);
612 * In the MISCOMPARE or failure case, unlock ->caw_sem obtained in
613 * sbc_compare_and_write() before the original READ I/O submission.
616 sg_free_table(&write_tbl
);
620 static sense_reason_t
621 sbc_compare_and_write(struct se_cmd
*cmd
)
623 struct sbc_ops
*ops
= cmd
->protocol_data
;
624 struct se_device
*dev
= cmd
->se_dev
;
628 * Submit the READ first for COMPARE_AND_WRITE to perform the
629 * comparision using SGLs at cmd->t_bidi_data_sg..
631 rc
= down_interruptible(&dev
->caw_sem
);
633 cmd
->transport_complete_callback
= NULL
;
634 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
637 * Reset cmd->data_length to individual block_size in order to not
638 * confuse backend drivers that depend on this value matching the
639 * size of the I/O being submitted.
641 cmd
->data_length
= cmd
->t_task_nolb
* dev
->dev_attrib
.block_size
;
643 ret
= ops
->execute_rw(cmd
, cmd
->t_bidi_data_sg
, cmd
->t_bidi_data_nents
,
646 cmd
->transport_complete_callback
= NULL
;
651 * Unlock of dev->caw_sem to occur in compare_and_write_callback()
652 * upon MISCOMPARE, or in compare_and_write_done() upon completion
653 * of WRITE instance user-data.
659 sbc_set_prot_op_checks(u8 protect
, bool fabric_prot
, enum target_prot_type prot_type
,
660 bool is_write
, struct se_cmd
*cmd
)
663 cmd
->prot_op
= fabric_prot
? TARGET_PROT_DOUT_STRIP
:
664 protect
? TARGET_PROT_DOUT_PASS
:
665 TARGET_PROT_DOUT_INSERT
;
669 cmd
->prot_checks
= 0;
673 cmd
->prot_checks
= TARGET_DIF_CHECK_GUARD
;
674 if (prot_type
== TARGET_DIF_TYPE1_PROT
)
675 cmd
->prot_checks
|= TARGET_DIF_CHECK_REFTAG
;
678 if (prot_type
== TARGET_DIF_TYPE1_PROT
)
679 cmd
->prot_checks
= TARGET_DIF_CHECK_REFTAG
;
682 cmd
->prot_checks
= TARGET_DIF_CHECK_GUARD
;
685 pr_err("Unsupported protect field %d\n", protect
);
689 cmd
->prot_op
= fabric_prot
? TARGET_PROT_DIN_INSERT
:
690 protect
? TARGET_PROT_DIN_PASS
:
691 TARGET_PROT_DIN_STRIP
;
696 cmd
->prot_checks
= TARGET_DIF_CHECK_GUARD
;
697 if (prot_type
== TARGET_DIF_TYPE1_PROT
)
698 cmd
->prot_checks
|= TARGET_DIF_CHECK_REFTAG
;
701 if (prot_type
== TARGET_DIF_TYPE1_PROT
)
702 cmd
->prot_checks
= TARGET_DIF_CHECK_REFTAG
;
705 cmd
->prot_checks
= 0;
708 cmd
->prot_checks
= TARGET_DIF_CHECK_GUARD
;
711 pr_err("Unsupported protect field %d\n", protect
);
719 static sense_reason_t
720 sbc_check_prot(struct se_device
*dev
, struct se_cmd
*cmd
, unsigned char *cdb
,
721 u32 sectors
, bool is_write
)
723 u8 protect
= cdb
[1] >> 5;
724 int sp_ops
= cmd
->se_sess
->sup_prot_ops
;
725 int pi_prot_type
= dev
->dev_attrib
.pi_prot_type
;
726 bool fabric_prot
= false;
728 if (!cmd
->t_prot_sg
|| !cmd
->t_prot_nents
) {
729 if (unlikely(protect
&&
730 !dev
->dev_attrib
.pi_prot_type
&& !cmd
->se_sess
->sess_prot_type
)) {
731 pr_err("CDB contains protect bit, but device + fabric does"
732 " not advertise PROTECT=1 feature bit\n");
733 return TCM_INVALID_CDB_FIELD
;
739 switch (dev
->dev_attrib
.pi_prot_type
) {
740 case TARGET_DIF_TYPE3_PROT
:
741 cmd
->reftag_seed
= 0xffffffff;
743 case TARGET_DIF_TYPE2_PROT
:
745 return TCM_INVALID_CDB_FIELD
;
747 cmd
->reftag_seed
= cmd
->t_task_lba
;
749 case TARGET_DIF_TYPE1_PROT
:
750 cmd
->reftag_seed
= cmd
->t_task_lba
;
752 case TARGET_DIF_TYPE0_PROT
:
754 * See if the fabric supports T10-PI, and the session has been
755 * configured to allow export PROTECT=1 feature bit with backend
756 * devices that don't support T10-PI.
758 fabric_prot
= is_write
?
759 !!(sp_ops
& (TARGET_PROT_DOUT_PASS
| TARGET_PROT_DOUT_STRIP
)) :
760 !!(sp_ops
& (TARGET_PROT_DIN_PASS
| TARGET_PROT_DIN_INSERT
));
762 if (fabric_prot
&& cmd
->se_sess
->sess_prot_type
) {
763 pi_prot_type
= cmd
->se_sess
->sess_prot_type
;
770 pr_err("Unable to determine pi_prot_type for CDB: 0x%02x "
771 "PROTECT: 0x%02x\n", cdb
[0], protect
);
772 return TCM_INVALID_CDB_FIELD
;
775 if (sbc_set_prot_op_checks(protect
, fabric_prot
, pi_prot_type
, is_write
, cmd
))
776 return TCM_INVALID_CDB_FIELD
;
778 cmd
->prot_type
= pi_prot_type
;
779 cmd
->prot_length
= dev
->prot_length
* sectors
;
782 * In case protection information exists over the wire
783 * we modify command data length to describe pure data.
784 * The actual transfer length is data length + protection
788 cmd
->data_length
= sectors
* dev
->dev_attrib
.block_size
;
790 pr_debug("%s: prot_type=%d, data_length=%d, prot_length=%d "
791 "prot_op=%d prot_checks=%d\n",
792 __func__
, cmd
->prot_type
, cmd
->data_length
, cmd
->prot_length
,
793 cmd
->prot_op
, cmd
->prot_checks
);
799 sbc_check_dpofua(struct se_device
*dev
, struct se_cmd
*cmd
, unsigned char *cdb
)
802 /* see explanation in spc_emulate_modesense */
803 if (!target_check_fua(dev
)) {
804 pr_err("Got CDB: 0x%02x with DPO bit set, but device"
805 " does not advertise support for DPO\n", cdb
[0]);
810 if (!target_check_fua(dev
)) {
811 pr_err("Got CDB: 0x%02x with FUA bit set, but device"
812 " does not advertise support for FUA write\n",
816 cmd
->se_cmd_flags
|= SCF_FUA
;
822 sbc_parse_cdb(struct se_cmd
*cmd
, struct sbc_ops
*ops
)
824 struct se_device
*dev
= cmd
->se_dev
;
825 unsigned char *cdb
= cmd
->t_task_cdb
;
830 cmd
->protocol_data
= ops
;
834 sectors
= transport_get_sectors_6(cdb
);
835 cmd
->t_task_lba
= transport_lba_21(cdb
);
836 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
;
837 cmd
->execute_cmd
= sbc_execute_rw
;
840 sectors
= transport_get_sectors_10(cdb
);
841 cmd
->t_task_lba
= transport_lba_32(cdb
);
843 if (sbc_check_dpofua(dev
, cmd
, cdb
))
844 return TCM_INVALID_CDB_FIELD
;
846 ret
= sbc_check_prot(dev
, cmd
, cdb
, sectors
, false);
850 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
;
851 cmd
->execute_cmd
= sbc_execute_rw
;
854 sectors
= transport_get_sectors_12(cdb
);
855 cmd
->t_task_lba
= transport_lba_32(cdb
);
857 if (sbc_check_dpofua(dev
, cmd
, cdb
))
858 return TCM_INVALID_CDB_FIELD
;
860 ret
= sbc_check_prot(dev
, cmd
, cdb
, sectors
, false);
864 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
;
865 cmd
->execute_cmd
= sbc_execute_rw
;
868 sectors
= transport_get_sectors_16(cdb
);
869 cmd
->t_task_lba
= transport_lba_64(cdb
);
871 if (sbc_check_dpofua(dev
, cmd
, cdb
))
872 return TCM_INVALID_CDB_FIELD
;
874 ret
= sbc_check_prot(dev
, cmd
, cdb
, sectors
, false);
878 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
;
879 cmd
->execute_cmd
= sbc_execute_rw
;
882 sectors
= transport_get_sectors_6(cdb
);
883 cmd
->t_task_lba
= transport_lba_21(cdb
);
884 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
;
885 cmd
->execute_cmd
= sbc_execute_rw
;
889 sectors
= transport_get_sectors_10(cdb
);
890 cmd
->t_task_lba
= transport_lba_32(cdb
);
892 if (sbc_check_dpofua(dev
, cmd
, cdb
))
893 return TCM_INVALID_CDB_FIELD
;
895 ret
= sbc_check_prot(dev
, cmd
, cdb
, sectors
, true);
899 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
;
900 cmd
->execute_cmd
= sbc_execute_rw
;
903 sectors
= transport_get_sectors_12(cdb
);
904 cmd
->t_task_lba
= transport_lba_32(cdb
);
906 if (sbc_check_dpofua(dev
, cmd
, cdb
))
907 return TCM_INVALID_CDB_FIELD
;
909 ret
= sbc_check_prot(dev
, cmd
, cdb
, sectors
, true);
913 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
;
914 cmd
->execute_cmd
= sbc_execute_rw
;
917 case WRITE_VERIFY_16
:
918 sectors
= transport_get_sectors_16(cdb
);
919 cmd
->t_task_lba
= transport_lba_64(cdb
);
921 if (sbc_check_dpofua(dev
, cmd
, cdb
))
922 return TCM_INVALID_CDB_FIELD
;
924 ret
= sbc_check_prot(dev
, cmd
, cdb
, sectors
, true);
928 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
;
929 cmd
->execute_cmd
= sbc_execute_rw
;
932 if (cmd
->data_direction
!= DMA_TO_DEVICE
||
933 !(cmd
->se_cmd_flags
& SCF_BIDI
))
934 return TCM_INVALID_CDB_FIELD
;
935 sectors
= transport_get_sectors_10(cdb
);
937 if (sbc_check_dpofua(dev
, cmd
, cdb
))
938 return TCM_INVALID_CDB_FIELD
;
940 cmd
->t_task_lba
= transport_lba_32(cdb
);
941 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
;
944 * Setup BIDI XOR callback to be run after I/O completion.
946 cmd
->execute_cmd
= sbc_execute_rw
;
947 cmd
->transport_complete_callback
= &xdreadwrite_callback
;
949 case VARIABLE_LENGTH_CMD
:
951 u16 service_action
= get_unaligned_be16(&cdb
[8]);
952 switch (service_action
) {
954 sectors
= transport_get_sectors_32(cdb
);
956 if (sbc_check_dpofua(dev
, cmd
, cdb
))
957 return TCM_INVALID_CDB_FIELD
;
959 * Use WRITE_32 and READ_32 opcodes for the emulated
960 * XDWRITE_READ_32 logic.
962 cmd
->t_task_lba
= transport_lba_64_ext(cdb
);
963 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
;
966 * Setup BIDI XOR callback to be run during after I/O
969 cmd
->execute_cmd
= sbc_execute_rw
;
970 cmd
->transport_complete_callback
= &xdreadwrite_callback
;
973 sectors
= transport_get_sectors_32(cdb
);
975 pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not"
977 return TCM_INVALID_CDB_FIELD
;
980 size
= sbc_get_size(cmd
, 1);
981 cmd
->t_task_lba
= get_unaligned_be64(&cdb
[12]);
983 ret
= sbc_setup_write_same(cmd
, &cdb
[10], ops
);
988 pr_err("VARIABLE_LENGTH_CMD service action"
989 " 0x%04x not supported\n", service_action
);
990 return TCM_UNSUPPORTED_SCSI_OPCODE
;
994 case COMPARE_AND_WRITE
:
995 if (!dev
->dev_attrib
.emulate_caw
) {
996 pr_err_ratelimited("se_device %s/%s (vpd_unit_serial %s) reject COMPARE_AND_WRITE\n",
997 dev
->se_hba
->backend
->ops
->name
,
998 config_item_name(&dev
->dev_group
.cg_item
),
999 dev
->t10_wwn
.unit_serial
);
1000 return TCM_UNSUPPORTED_SCSI_OPCODE
;
1004 * Currently enforce COMPARE_AND_WRITE for a single sector
1007 pr_err("COMPARE_AND_WRITE contains NoLB: %u greater"
1008 " than 1\n", sectors
);
1009 return TCM_INVALID_CDB_FIELD
;
1011 if (sbc_check_dpofua(dev
, cmd
, cdb
))
1012 return TCM_INVALID_CDB_FIELD
;
1015 * Double size because we have two buffers, note that
1016 * zero is not an error..
1018 size
= 2 * sbc_get_size(cmd
, sectors
);
1019 cmd
->t_task_lba
= get_unaligned_be64(&cdb
[2]);
1020 cmd
->t_task_nolb
= sectors
;
1021 cmd
->se_cmd_flags
|= SCF_SCSI_DATA_CDB
| SCF_COMPARE_AND_WRITE
;
1022 cmd
->execute_cmd
= sbc_compare_and_write
;
1023 cmd
->transport_complete_callback
= compare_and_write_callback
;
1026 size
= READ_CAP_LEN
;
1027 cmd
->execute_cmd
= sbc_emulate_readcapacity
;
1029 case SERVICE_ACTION_IN_16
:
1030 switch (cmd
->t_task_cdb
[1] & 0x1f) {
1031 case SAI_READ_CAPACITY_16
:
1032 cmd
->execute_cmd
= sbc_emulate_readcapacity_16
;
1034 case SAI_REPORT_REFERRALS
:
1035 cmd
->execute_cmd
= target_emulate_report_referrals
;
1038 pr_err("Unsupported SA: 0x%02x\n",
1039 cmd
->t_task_cdb
[1] & 0x1f);
1040 return TCM_INVALID_CDB_FIELD
;
1042 size
= get_unaligned_be32(&cdb
[10]);
1044 case SYNCHRONIZE_CACHE
:
1045 case SYNCHRONIZE_CACHE_16
:
1046 if (cdb
[0] == SYNCHRONIZE_CACHE
) {
1047 sectors
= transport_get_sectors_10(cdb
);
1048 cmd
->t_task_lba
= transport_lba_32(cdb
);
1050 sectors
= transport_get_sectors_16(cdb
);
1051 cmd
->t_task_lba
= transport_lba_64(cdb
);
1053 if (ops
->execute_sync_cache
) {
1054 cmd
->execute_cmd
= ops
->execute_sync_cache
;
1058 cmd
->execute_cmd
= sbc_emulate_noop
;
1061 if (!ops
->execute_unmap
)
1062 return TCM_UNSUPPORTED_SCSI_OPCODE
;
1064 if (!dev
->dev_attrib
.emulate_tpu
) {
1065 pr_err("Got UNMAP, but backend device has"
1066 " emulate_tpu disabled\n");
1067 return TCM_UNSUPPORTED_SCSI_OPCODE
;
1069 size
= get_unaligned_be16(&cdb
[7]);
1070 cmd
->execute_cmd
= sbc_execute_unmap
;
1073 sectors
= transport_get_sectors_16(cdb
);
1075 pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n");
1076 return TCM_INVALID_CDB_FIELD
;
1079 size
= sbc_get_size(cmd
, 1);
1080 cmd
->t_task_lba
= get_unaligned_be64(&cdb
[2]);
1082 ret
= sbc_setup_write_same(cmd
, &cdb
[1], ops
);
1087 sectors
= transport_get_sectors_10(cdb
);
1089 pr_err("WSNZ=1, WRITE_SAME w/sectors=0 not supported\n");
1090 return TCM_INVALID_CDB_FIELD
;
1093 size
= sbc_get_size(cmd
, 1);
1094 cmd
->t_task_lba
= get_unaligned_be32(&cdb
[2]);
1097 * Follow sbcr26 with WRITE_SAME (10) and check for the existence
1098 * of byte 1 bit 3 UNMAP instead of original reserved field
1100 ret
= sbc_setup_write_same(cmd
, &cdb
[1], ops
);
1107 if (cdb
[0] == VERIFY
) {
1108 sectors
= transport_get_sectors_10(cdb
);
1109 cmd
->t_task_lba
= transport_lba_32(cdb
);
1111 sectors
= transport_get_sectors_16(cdb
);
1112 cmd
->t_task_lba
= transport_lba_64(cdb
);
1114 cmd
->execute_cmd
= sbc_emulate_noop
;
1120 * There are still clients out there which use these old SCSI-2
1121 * commands. This mainly happens when running VMs with legacy
1122 * guest systems, connected via SCSI command pass-through to
1123 * iSCSI targets. Make them happy and return status GOOD.
1126 cmd
->execute_cmd
= sbc_emulate_noop
;
1130 cmd
->execute_cmd
= sbc_emulate_startstop
;
1133 ret
= spc_parse_cdb(cmd
, &size
);
1138 /* reject any command that we don't have a handler for */
1139 if (!cmd
->execute_cmd
)
1140 return TCM_UNSUPPORTED_SCSI_OPCODE
;
1142 if (cmd
->se_cmd_flags
& SCF_SCSI_DATA_CDB
) {
1143 unsigned long long end_lba
;
1145 end_lba
= dev
->transport
->get_blocks(dev
) + 1;
1146 if (((cmd
->t_task_lba
+ sectors
) < cmd
->t_task_lba
) ||
1147 ((cmd
->t_task_lba
+ sectors
) > end_lba
)) {
1148 pr_err("cmd exceeds last lba %llu "
1149 "(lba %llu, sectors %u)\n",
1150 end_lba
, cmd
->t_task_lba
, sectors
);
1151 return TCM_ADDRESS_OUT_OF_RANGE
;
1154 if (!(cmd
->se_cmd_flags
& SCF_COMPARE_AND_WRITE
))
1155 size
= sbc_get_size(cmd
, sectors
);
1158 return target_cmd_size_check(cmd
, size
);
1160 EXPORT_SYMBOL(sbc_parse_cdb
);
1162 u32
sbc_get_device_type(struct se_device
*dev
)
1166 EXPORT_SYMBOL(sbc_get_device_type
);
1168 static sense_reason_t
1169 sbc_execute_unmap(struct se_cmd
*cmd
)
1171 struct sbc_ops
*ops
= cmd
->protocol_data
;
1172 struct se_device
*dev
= cmd
->se_dev
;
1173 unsigned char *buf
, *ptr
= NULL
;
1177 sense_reason_t ret
= 0;
1180 /* We never set ANC_SUP */
1181 if (cmd
->t_task_cdb
[1])
1182 return TCM_INVALID_CDB_FIELD
;
1184 if (cmd
->data_length
== 0) {
1185 target_complete_cmd(cmd
, SAM_STAT_GOOD
);
1189 if (cmd
->data_length
< 8) {
1190 pr_warn("UNMAP parameter list length %u too small\n",
1192 return TCM_PARAMETER_LIST_LENGTH_ERROR
;
1195 buf
= transport_kmap_data_sg(cmd
);
1197 return TCM_LOGICAL_UNIT_COMMUNICATION_FAILURE
;
1199 dl
= get_unaligned_be16(&buf
[0]);
1200 bd_dl
= get_unaligned_be16(&buf
[2]);
1202 size
= cmd
->data_length
- 8;
1204 pr_warn("UNMAP parameter list length %u too small, ignoring bd_dl %u\n",
1205 cmd
->data_length
, bd_dl
);
1209 if (size
/ 16 > dev
->dev_attrib
.max_unmap_block_desc_count
) {
1210 ret
= TCM_INVALID_PARAMETER_LIST
;
1214 /* First UNMAP block descriptor starts at 8 byte offset */
1216 pr_debug("UNMAP: Sub: %s Using dl: %u bd_dl: %u size: %u"
1217 " ptr: %p\n", dev
->transport
->name
, dl
, bd_dl
, size
, ptr
);
1219 while (size
>= 16) {
1220 lba
= get_unaligned_be64(&ptr
[0]);
1221 range
= get_unaligned_be32(&ptr
[8]);
1222 pr_debug("UNMAP: Using lba: %llu and range: %u\n",
1223 (unsigned long long)lba
, range
);
1225 if (range
> dev
->dev_attrib
.max_unmap_lba_count
) {
1226 ret
= TCM_INVALID_PARAMETER_LIST
;
1230 if (lba
+ range
> dev
->transport
->get_blocks(dev
) + 1) {
1231 ret
= TCM_ADDRESS_OUT_OF_RANGE
;
1236 ret
= ops
->execute_unmap(cmd
, lba
, range
);
1246 transport_kunmap_data_sg(cmd
);
1248 target_complete_cmd(cmd
, GOOD
);
1253 sbc_dif_generate(struct se_cmd
*cmd
)
1255 struct se_device
*dev
= cmd
->se_dev
;
1256 struct t10_pi_tuple
*sdt
;
1257 struct scatterlist
*dsg
= cmd
->t_data_sg
, *psg
;
1258 sector_t sector
= cmd
->t_task_lba
;
1259 void *daddr
, *paddr
;
1260 int i
, j
, offset
= 0;
1261 unsigned int block_size
= dev
->dev_attrib
.block_size
;
1263 for_each_sg(cmd
->t_prot_sg
, psg
, cmd
->t_prot_nents
, i
) {
1264 paddr
= kmap_atomic(sg_page(psg
)) + psg
->offset
;
1265 daddr
= kmap_atomic(sg_page(dsg
)) + dsg
->offset
;
1267 for (j
= 0; j
< psg
->length
;
1268 j
+= sizeof(*sdt
)) {
1272 if (offset
>= dsg
->length
) {
1273 offset
-= dsg
->length
;
1274 kunmap_atomic(daddr
- dsg
->offset
);
1277 kunmap_atomic(paddr
- psg
->offset
);
1280 daddr
= kmap_atomic(sg_page(dsg
)) + dsg
->offset
;
1284 avail
= min(block_size
, dsg
->length
- offset
);
1285 crc
= crc_t10dif(daddr
+ offset
, avail
);
1286 if (avail
< block_size
) {
1287 kunmap_atomic(daddr
- dsg
->offset
);
1290 kunmap_atomic(paddr
- psg
->offset
);
1293 daddr
= kmap_atomic(sg_page(dsg
)) + dsg
->offset
;
1294 offset
= block_size
- avail
;
1295 crc
= crc_t10dif_update(crc
, daddr
, offset
);
1297 offset
+= block_size
;
1300 sdt
->guard_tag
= cpu_to_be16(crc
);
1301 if (cmd
->prot_type
== TARGET_DIF_TYPE1_PROT
)
1302 sdt
->ref_tag
= cpu_to_be32(sector
& 0xffffffff);
1305 pr_debug("DIF %s INSERT sector: %llu guard_tag: 0x%04x"
1306 " app_tag: 0x%04x ref_tag: %u\n",
1307 (cmd
->data_direction
== DMA_TO_DEVICE
) ?
1308 "WRITE" : "READ", (unsigned long long)sector
,
1309 sdt
->guard_tag
, sdt
->app_tag
,
1310 be32_to_cpu(sdt
->ref_tag
));
1315 kunmap_atomic(daddr
- dsg
->offset
);
1316 kunmap_atomic(paddr
- psg
->offset
);
1320 static sense_reason_t
1321 sbc_dif_v1_verify(struct se_cmd
*cmd
, struct t10_pi_tuple
*sdt
,
1322 __u16 crc
, sector_t sector
, unsigned int ei_lba
)
1326 if (!(cmd
->prot_checks
& TARGET_DIF_CHECK_GUARD
))
1329 csum
= cpu_to_be16(crc
);
1331 if (sdt
->guard_tag
!= csum
) {
1332 pr_err("DIFv1 checksum failed on sector %llu guard tag 0x%04x"
1333 " csum 0x%04x\n", (unsigned long long)sector
,
1334 be16_to_cpu(sdt
->guard_tag
), be16_to_cpu(csum
));
1335 return TCM_LOGICAL_BLOCK_GUARD_CHECK_FAILED
;
1339 if (!(cmd
->prot_checks
& TARGET_DIF_CHECK_REFTAG
))
1342 if (cmd
->prot_type
== TARGET_DIF_TYPE1_PROT
&&
1343 be32_to_cpu(sdt
->ref_tag
) != (sector
& 0xffffffff)) {
1344 pr_err("DIFv1 Type 1 reference failed on sector: %llu tag: 0x%08x"
1345 " sector MSB: 0x%08x\n", (unsigned long long)sector
,
1346 be32_to_cpu(sdt
->ref_tag
), (u32
)(sector
& 0xffffffff));
1347 return TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED
;
1350 if (cmd
->prot_type
== TARGET_DIF_TYPE2_PROT
&&
1351 be32_to_cpu(sdt
->ref_tag
) != ei_lba
) {
1352 pr_err("DIFv1 Type 2 reference failed on sector: %llu tag: 0x%08x"
1353 " ei_lba: 0x%08x\n", (unsigned long long)sector
,
1354 be32_to_cpu(sdt
->ref_tag
), ei_lba
);
1355 return TCM_LOGICAL_BLOCK_REF_TAG_CHECK_FAILED
;
1361 void sbc_dif_copy_prot(struct se_cmd
*cmd
, unsigned int sectors
, bool read
,
1362 struct scatterlist
*sg
, int sg_off
)
1364 struct se_device
*dev
= cmd
->se_dev
;
1365 struct scatterlist
*psg
;
1367 unsigned int i
, len
, left
;
1368 unsigned int offset
= sg_off
;
1373 left
= sectors
* dev
->prot_length
;
1375 for_each_sg(cmd
->t_prot_sg
, psg
, cmd
->t_prot_nents
, i
) {
1376 unsigned int psg_len
, copied
= 0;
1378 paddr
= kmap_atomic(sg_page(psg
)) + psg
->offset
;
1379 psg_len
= min(left
, psg
->length
);
1381 len
= min(psg_len
, sg
->length
- offset
);
1382 addr
= kmap_atomic(sg_page(sg
)) + sg
->offset
+ offset
;
1385 memcpy(paddr
+ copied
, addr
, len
);
1387 memcpy(addr
, paddr
+ copied
, len
);
1394 kunmap_atomic(addr
- sg
->offset
- offset
);
1396 if (offset
>= sg
->length
) {
1401 kunmap_atomic(paddr
- psg
->offset
);
1404 EXPORT_SYMBOL(sbc_dif_copy_prot
);
1407 sbc_dif_verify(struct se_cmd
*cmd
, sector_t start
, unsigned int sectors
,
1408 unsigned int ei_lba
, struct scatterlist
*psg
, int psg_off
)
1410 struct se_device
*dev
= cmd
->se_dev
;
1411 struct t10_pi_tuple
*sdt
;
1412 struct scatterlist
*dsg
= cmd
->t_data_sg
;
1413 sector_t sector
= start
;
1414 void *daddr
, *paddr
;
1418 unsigned int block_size
= dev
->dev_attrib
.block_size
;
1420 for (; psg
&& sector
< start
+ sectors
; psg
= sg_next(psg
)) {
1421 paddr
= kmap_atomic(sg_page(psg
)) + psg
->offset
;
1422 daddr
= kmap_atomic(sg_page(dsg
)) + dsg
->offset
;
1424 for (i
= psg_off
; i
< psg
->length
&&
1425 sector
< start
+ sectors
;
1426 i
+= sizeof(*sdt
)) {
1430 if (dsg_off
>= dsg
->length
) {
1431 dsg_off
-= dsg
->length
;
1432 kunmap_atomic(daddr
- dsg
->offset
);
1435 kunmap_atomic(paddr
- psg
->offset
);
1438 daddr
= kmap_atomic(sg_page(dsg
)) + dsg
->offset
;
1443 pr_debug("DIF READ sector: %llu guard_tag: 0x%04x"
1444 " app_tag: 0x%04x ref_tag: %u\n",
1445 (unsigned long long)sector
, sdt
->guard_tag
,
1446 sdt
->app_tag
, be32_to_cpu(sdt
->ref_tag
));
1448 if (sdt
->app_tag
== T10_PI_APP_ESCAPE
) {
1449 dsg_off
+= block_size
;
1453 avail
= min(block_size
, dsg
->length
- dsg_off
);
1454 crc
= crc_t10dif(daddr
+ dsg_off
, avail
);
1455 if (avail
< block_size
) {
1456 kunmap_atomic(daddr
- dsg
->offset
);
1459 kunmap_atomic(paddr
- psg
->offset
);
1462 daddr
= kmap_atomic(sg_page(dsg
)) + dsg
->offset
;
1463 dsg_off
= block_size
- avail
;
1464 crc
= crc_t10dif_update(crc
, daddr
, dsg_off
);
1466 dsg_off
+= block_size
;
1469 rc
= sbc_dif_v1_verify(cmd
, sdt
, crc
, sector
, ei_lba
);
1471 kunmap_atomic(daddr
- dsg
->offset
);
1472 kunmap_atomic(paddr
- psg
->offset
);
1473 cmd
->sense_info
= sector
;
1482 kunmap_atomic(daddr
- dsg
->offset
);
1483 kunmap_atomic(paddr
- psg
->offset
);
1488 EXPORT_SYMBOL(sbc_dif_verify
);