Skip to content

Commit

Permalink
scsi_cmnd: Introduce scsi_transfer_length helper
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Sagi Grimberg authored and Nicholas Bellinger committed Jun 11, 2014
1 parent 2426bd4 commit 8846bab
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions include/scsi/scsi_cmnd.h
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@
#include <linux/types.h>
#include <linux/timer.h>
#include <linux/scatterlist.h>
#include <scsi/scsi_device.h>

struct Scsi_Host;
struct scsi_device;
@@ -306,4 +307,20 @@ static inline void set_driver_byte(struct scsi_cmnd *cmd, char status)
cmd->result = (cmd->result & 0x00ffffff) | (status << 24);
}

static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
{
unsigned int xfer_len = blk_rq_bytes(scmd->request);
unsigned int prot_op = scsi_get_prot_op(scmd);
unsigned int sector_size = scmd->device->sector_size;

switch (prot_op) {
case SCSI_PROT_NORMAL:
case SCSI_PROT_WRITE_STRIP:
case SCSI_PROT_READ_INSERT:
return xfer_len;
}

return xfer_len + (xfer_len >> ilog2(sector_size)) * 8;
}

#endif /* _SCSI_SCSI_CMND_H */

0 comments on commit 8846bab

Please sign in to comment.