Skip to content

Commit 8846bab

Browse files
Sagi GrimbergNicholas Bellinger
authored andcommitted
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>
1 parent 2426bd4 commit 8846bab

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎include/scsi/scsi_cmnd.h‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include <linux/types.h>
88
#include <linux/timer.h>
99
#include <linux/scatterlist.h>
10+
#include <scsi/scsi_device.h>
1011

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

310+
static inline unsigned scsi_transfer_length(struct scsi_cmnd *scmd)
311+
{
312+
unsigned int xfer_len = blk_rq_bytes(scmd->request);
313+
unsigned int prot_op = scsi_get_prot_op(scmd);
314+
unsigned int sector_size = scmd->device->sector_size;
315+
316+
switch (prot_op) {
317+
case SCSI_PROT_NORMAL:
318+
case SCSI_PROT_WRITE_STRIP:
319+
case SCSI_PROT_READ_INSERT:
320+
return xfer_len;
321+
}
322+
323+
return xfer_len + (xfer_len >> ilog2(sector_size)) * 8;
324+
}
325+
309326
#endif /* _SCSI_SCSI_CMND_H */

0 commit comments

Comments
 (0)