Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

scsi_cmnd: Introduce scsi_transfer_length helper

In case protection information exists on the wire
scsi transports should include it in the transfer
byte count (even if protection information does not
exist in the host memory space). This helper will
compute the total transfer length from the scsi
command data length and protection attributes.

Signed-off-by: Sagi Grimberg <sagig@mellanox.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
Cc: stable@vger.kernel.org # 3.15+
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Sagi Grimberg and committed by
Nicholas Bellinger
8846bab1 2426bd45

+17
+17
include/scsi/scsi_cmnd.h
··· 7 7 #include <linux/types.h> 8 8 #include <linux/timer.h> 9 9 #include <linux/scatterlist.h> 10 + #include <scsi/scsi_device.h> 10 11 11 12 struct Scsi_Host; 12 13 struct scsi_device; ··· 305 304 static inline void set_driver_byte(struct scsi_cmnd *cmd, char status) 306 305 { 307 306 cmd->result = (cmd->result & 0x00ffffff) | (status << 24); 307 + } 308 + 309 + static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd) 310 + { 311 + unsigned int xfer_len = blk_rq_bytes(scmd->request); 312 + unsigned int prot_op = scsi_get_prot_op(scmd); 313 + unsigned int sector_size = scmd->device->sector_size; 314 + 315 + switch (prot_op) { 316 + case SCSI_PROT_NORMAL: 317 + case SCSI_PROT_WRITE_STRIP: 318 + case SCSI_PROT_READ_INSERT: 319 + return xfer_len; 320 + } 321 + 322 + return xfer_len + (xfer_len >> ilog2(sector_size)) * 8; 308 323 } 309 324 310 325 #endif /* _SCSI_SCSI_CMND_H */