From patchwork Sun Jun 8 10:27:06 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sagi Grimberg X-Patchwork-Id: 4316831 Return-Path: X-Original-To: patchwork-linux-rdma@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 0EB4C9F314 for ; Sun, 8 Jun 2014 10:27:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 160FD2025A for ; Sun, 8 Jun 2014 10:27:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1042A20270 for ; Sun, 8 Jun 2014 10:27:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752730AbaFHK1P (ORCPT ); Sun, 8 Jun 2014 06:27:15 -0400 Received: from mailp.voltaire.com ([193.47.165.129]:58400 "EHLO mellanox.co.il" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751584AbaFHK1N (ORCPT ); Sun, 8 Jun 2014 06:27:13 -0400 Received: from Internal Mail-Server by MTLPINE2 (envelope-from sagig@mellanox.com) with SMTP; 8 Jun 2014 13:27:10 +0300 Received: from r-vnc05.mtr.labs.mlnx (r-vnc05.mtr.labs.mlnx [10.208.0.115]) by labmailer.mlnx (8.13.8/8.13.8) with ESMTP id s58ARAgJ002737; Sun, 8 Jun 2014 13:27:10 +0300 Received: from r-vnc05.mtr.labs.mlnx (localhost [127.0.0.1]) by r-vnc05.mtr.labs.mlnx (8.14.4/8.14.4) with ESMTP id s58ARAtG023834; Sun, 8 Jun 2014 13:27:10 +0300 Received: (from sagig@localhost) by r-vnc05.mtr.labs.mlnx (8.14.4/8.14.4/Submit) id s58ARAbB023833; Sun, 8 Jun 2014 13:27:10 +0300 From: Sagi Grimberg To: michaelc@cs.wisc.edu, martin.petersen@oracle.com, nab@linux-iscsi.org, roland@kernel.org Cc: linux-scsi@vger.kernel.org, target-devel@vger.kernel.org, linux-rdma@vger.kernel.org Subject: [PATCH v1 1/3] scsi_cmnd: Introduce scsi_transfer_length helper Date: Sun, 8 Jun 2014 13:27:06 +0300 Message-Id: <1402223228-23768-2-git-send-email-sagig@mellanox.com> X-Mailer: git-send-email 1.8.4.3 In-Reply-To: <1402223228-23768-1-git-send-email-sagig@mellanox.com> References: <1402223228-23768-1-git-send-email-sagig@mellanox.com> Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- include/scsi/scsi_cmnd.h | 39 +++++++++++++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) 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 #include #include +#include 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 */