Re: [PATCH v1 1/3] scsi_cmnd: Introduce scsi_transfer_length helper

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6/10/2014 10:02 PM, Martin K. Petersen wrote:
"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;
}


No problem,

I'll send out v2 tomorrow (your tonight...)

Thanks,
Sagi.
--
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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [SCSI Target Devel]     [Linux SCSI Target Infrastructure]     [Kernel Newbies]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Linux IIO]     [Samba]     [Device Mapper]
  Powered by Linux