block: move ref_tag calculation func to the block layer
authorMax Gurtovoy <maxg@mellanox.com>
Sun, 29 Jul 2018 21:15:31 +0000 (00:15 +0300)
committerJens Axboe <axboe@kernel.dk>
Mon, 30 Jul 2018 14:27:01 +0000 (08:27 -0600)
Currently this function is implemented in the scsi layer, but it's
actual place should be the block layer since T10-PI is a general
data integrity feature that is used in the nvme protocol as well.

Suggested-by: Christoph Hellwig <hch@lst.de>
Cc: Martin K. Petersen <martin.petersen@oracle.com>
Signed-off-by: Max Gurtovoy <maxg@mellanox.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/infiniband/ulp/iser/iser_memory.c
drivers/nvme/host/core.c
drivers/scsi/mpt3sas/mpt3sas_scsih.c
drivers/scsi/sd_dif.c
include/linux/t10-pi.h
include/scsi/scsi_cmnd.h

index ca844a926e6add96b8063a698304a50fa7a8ffa7..130bf163f06600083e08b58184b000150ff52496 100644 (file)
@@ -311,7 +311,7 @@ iser_set_dif_domain(struct scsi_cmnd *sc, struct ib_sig_attrs *sig_attrs,
 {
        domain->sig_type = IB_SIG_TYPE_T10_DIF;
        domain->sig.dif.pi_interval = scsi_prot_interval(sc);
-       domain->sig.dif.ref_tag = scsi_prot_ref_tag(sc);
+       domain->sig.dif.ref_tag = t10_pi_ref_tag(sc->request);
        /*
         * At the moment we hard code those, but in the future
         * we will take them from sc.
index e77e6418a21cb3f04d89e9f957ff14bb1ec3aae3..16c8b86fe95d3878e01a303514a7e2e77eee8489 100644 (file)
@@ -611,8 +611,7 @@ static inline blk_status_t nvme_setup_rw(struct nvme_ns *ns,
                case NVME_NS_DPS_PI_TYPE2:
                        control |= NVME_RW_PRINFO_PRCHK_GUARD |
                                        NVME_RW_PRINFO_PRCHK_REF;
-                       cmnd->rw.reftag = cpu_to_le32(
-                                       nvme_block_nr(ns, blk_rq_pos(req)));
+                       cmnd->rw.reftag = cpu_to_le32(t10_pi_ref_tag(req));
                        break;
                }
        }
index b8d131a455d01c207057d06d79c3d57ae2cdada5..dd738ae5c75bcd1418d6abf6a94a44bf8983b319 100644 (file)
@@ -4568,7 +4568,7 @@ _scsih_setup_eedp(struct MPT3SAS_ADAPTER *ioc, struct scsi_cmnd *scmd,
                    MPI2_SCSIIO_EEDPFLAGS_CHECK_REFTAG |
                    MPI2_SCSIIO_EEDPFLAGS_CHECK_GUARD;
                mpi_request->CDB.EEDP32.PrimaryReferenceTag =
-                   cpu_to_be32(scsi_prot_ref_tag(scmd));
+                   cpu_to_be32(t10_pi_ref_tag(scmd->request));
                break;
 
        case SCSI_PROT_DIF_TYPE3:
index 9035380c0ddabd3012788d4bf418eb0a9447fc29..d8de43d359ac6d9800ca9c0159ab831bb7a02663 100644 (file)
@@ -124,7 +124,7 @@ void sd_dif_prepare(struct scsi_cmnd *scmd)
        if (sdkp->protection_type == T10_PI_TYPE3_PROTECTION)
                return;
 
-       phys = scsi_prot_ref_tag(scmd);
+       phys = t10_pi_ref_tag(scmd->request);
 
        __rq_for_each_bio(bio, scmd->request) {
                struct bio_integrity_payload *bip = bio_integrity(bio);
@@ -176,7 +176,7 @@ void sd_dif_complete(struct scsi_cmnd *scmd, unsigned int good_bytes)
                return;
 
        intervals = good_bytes / scsi_prot_interval(scmd);
-       phys = scsi_prot_ref_tag(scmd);
+       phys = t10_pi_ref_tag(scmd->request);
 
        __rq_for_each_bio(bio, scmd->request) {
                struct bio_integrity_payload *bip = bio_integrity(bio);
index c6aa8a3c42ed9a0af7f0c6450da5f41992c4cefa..c40511f4e63d656d5f48169ee684fe7908bed700 100644 (file)
@@ -37,6 +37,16 @@ struct t10_pi_tuple {
 #define T10_PI_APP_ESCAPE cpu_to_be16(0xffff)
 #define T10_PI_REF_ESCAPE cpu_to_be32(0xffffffff)
 
+static inline u32 t10_pi_ref_tag(struct request *rq)
+{
+#ifdef CONFIG_BLK_DEV_INTEGRITY
+       return blk_rq_pos(rq) >>
+               (rq->q->integrity.interval_exp - 9) & 0xffffffff;
+#else
+       return -1U;
+#endif
+}
+
 extern const struct blk_integrity_profile t10_pi_type1_crc;
 extern const struct blk_integrity_profile t10_pi_type1_ip;
 extern const struct blk_integrity_profile t10_pi_type3_crc;
index aaf1e971c6a368d12dbc63e9f086e58bd0da0346..cae229b5395c8d252103a8b6d49d2d613605e18c 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <linux/dma-mapping.h>
 #include <linux/blkdev.h>
+#include <linux/t10-pi.h>
 #include <linux/list.h>
 #include <linux/types.h>
 #include <linux/timer.h>
@@ -313,12 +314,6 @@ static inline unsigned int scsi_prot_interval(struct scsi_cmnd *scmd)
        return scmd->device->sector_size;
 }
 
-static inline u32 scsi_prot_ref_tag(struct scsi_cmnd *scmd)
-{
-       return blk_rq_pos(scmd->request) >>
-               (ilog2(scsi_prot_interval(scmd)) - 9) & 0xffffffff;
-}
-
 static inline unsigned scsi_prot_sg_count(struct scsi_cmnd *cmd)
 {
        return cmd->prot_sdb ? cmd->prot_sdb->table.nents : 0;