Message ID | 1402223228-23768-2-git-send-email-sagig@mellanox.com (mailing list archive) |
---|---|
State | Not Applicable, archived |
Headers | show |
>>>>> "Sagi" == Sagi Grimberg <sagig@mellanox.com> 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;
}
On 6/10/2014 10:02 PM, Martin K. Petersen wrote: >>>>>> "Sagi" == Sagi Grimberg <sagig@mellanox.com> 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-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
On Tue, Jun 10, 2014 at 10:02 PM, Martin K. Petersen <martin.petersen@oracle.com> wrote: >>>>>> "Sagi" == Sagi Grimberg <sagig@mellanox.com> 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: Just to make sure, by 3.16 you also mean 3.15.y, right? -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
>>>>> "Or" == Or Gerlitz <or.gerlitz@gmail.com> writes:
Or> Just to make sure, by 3.16 you also mean 3.15.y, right?
Yes.
diff --git a/include/scsi/scsi_cmnd.h b/include/scsi/scsi_cmnd.h index dd7c998..84d9593 100644 --- a/include/scsi/scsi_cmnd.h +++ b/include/scsi/scsi_cmnd.h @@ -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,42 @@ static inline void set_driver_byte(struct scsi_cmnd *cmd, char status) cmd->result = (cmd->result & 0x00ffffff) | (status << 24); } +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); +} + #endif /* _SCSI_SCSI_CMND_H */
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> --- include/scsi/scsi_cmnd.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-)