>>>>> "Sagi" == Sagi Grimberg <sagig@xxxxxxxxxxxx> writes: +static inline unsigned scsi_prot_length(unsigned data_length, + unsigned sector_size) +{ + switch (sector_size) { + case 512: + return (data_length >> 9) * 8; + case 1024: + return (data_length >> 10) * 8; + case 2048: + return (data_length >> 11) * 8; + case 4096: + return (data_length >> 12) * 8; + default: + return (data_length >> ilog2(sector_size)) * 8; + } +} + +static inline unsigned scsi_transfer_length(struct scsi_cmnd *cmd) +{ + unsigned data_length; + + if (cmd->sc_data_direction == DMA_FROM_DEVICE) { + data_length = scsi_in(cmd)->length; + if (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL || + scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) + return data_length; + } else { + data_length = scsi_out(cmd)->length; + if (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL || + scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP) + return data_length; + } + + /* Protection information exists on the wire */ + return data_length + scsi_prot_length(data_length, + cmd->device->sector_size); +} Let's do this for 3.16: static inline unsigned int 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); 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; } And then in 3.17 we'll have: static inline unsigned int scsi_transfer_length(struct scsi_cmnd *scmd) { unsigned int xfer_len = blk_rq_bytes(scmd->request); if (scsi_prot_flagged(SCSI_PROT_TRANSFER_PI)) xfer_len += (xfer_len >> ilog2(scsi_prot_interval(scmd))) * 8; return xfer_len; } -- Martin K. Petersen Oracle Linux Engineering -- To unsubscribe from this list: send the line "unsubscribe linux-scsi" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html