aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2016-09-11 13:35:41 -0400
committerMartin K. Petersen <martin.petersen@oracle.com>2016-09-15 09:51:14 -0400
commit8475c8118551f806176b5af4d0e8657a5f015b95 (patch)
tree64d1f724585a7baef043f6163764d021f2e2f01c
parent27c0e83b273a637d5cb56f02550c31d803bafc10 (diff)
scsi: sd: Move DIF protection types to t10-pi.h
These should go together with the rest of the T10 protection information defintions. [mkp: s/T10_DIF/T10_PI/] Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Bart Van Assche <bart.vanassche@sandisk.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
-rw-r--r--drivers/scsi/scsi_debug.c39
-rw-r--r--drivers/scsi/sd.c11
-rw-r--r--drivers/scsi/sd.h21
-rw-r--r--drivers/scsi/sd_dif.c10
-rw-r--r--include/linux/t10-pi.h20
5 files changed, 50 insertions, 51 deletions
diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
index 044fc939043f..c905709707f0 100644
--- a/drivers/scsi/scsi_debug.c
+++ b/drivers/scsi/scsi_debug.c
@@ -1350,7 +1350,7 @@ static int resp_inquiry(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
1350 } else if (0x86 == cmd[2]) { /* extended inquiry */ 1350 } else if (0x86 == cmd[2]) { /* extended inquiry */
1351 arr[1] = cmd[2]; /*sanity */ 1351 arr[1] = cmd[2]; /*sanity */
1352 arr[3] = 0x3c; /* number of following entries */ 1352 arr[3] = 0x3c; /* number of following entries */
1353 if (sdebug_dif == SD_DIF_TYPE3_PROTECTION) 1353 if (sdebug_dif == T10_PI_TYPE3_PROTECTION)
1354 arr[4] = 0x4; /* SPT: GRD_CHK:1 */ 1354 arr[4] = 0x4; /* SPT: GRD_CHK:1 */
1355 else if (have_dif_prot) 1355 else if (have_dif_prot)
1356 arr[4] = 0x5; /* SPT: GRD_CHK:1, REF_CHK:1 */ 1356 arr[4] = 0x5; /* SPT: GRD_CHK:1, REF_CHK:1 */
@@ -2443,13 +2443,13 @@ static int dif_verify(struct t10_pi_tuple *sdt, const void *data,
2443 be16_to_cpu(csum)); 2443 be16_to_cpu(csum));
2444 return 0x01; 2444 return 0x01;
2445 } 2445 }
2446 if (sdebug_dif == SD_DIF_TYPE1_PROTECTION && 2446 if (sdebug_dif == T10_PI_TYPE1_PROTECTION &&
2447 be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) { 2447 be32_to_cpu(sdt->ref_tag) != (sector & 0xffffffff)) {
2448 pr_err("REF check failed on sector %lu\n", 2448 pr_err("REF check failed on sector %lu\n",
2449 (unsigned long)sector); 2449 (unsigned long)sector);
2450 return 0x03; 2450 return 0x03;
2451 } 2451 }
2452 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION && 2452 if (sdebug_dif == T10_PI_TYPE2_PROTECTION &&
2453 be32_to_cpu(sdt->ref_tag) != ei_lba) { 2453 be32_to_cpu(sdt->ref_tag) != ei_lba) {
2454 pr_err("REF check failed on sector %lu\n", 2454 pr_err("REF check failed on sector %lu\n",
2455 (unsigned long)sector); 2455 (unsigned long)sector);
@@ -2581,13 +2581,13 @@ static int resp_read_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2581 break; 2581 break;
2582 } 2582 }
2583 if (unlikely(have_dif_prot && check_prot)) { 2583 if (unlikely(have_dif_prot && check_prot)) {
2584 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION && 2584 if (sdebug_dif == T10_PI_TYPE2_PROTECTION &&
2585 (cmd[1] & 0xe0)) { 2585 (cmd[1] & 0xe0)) {
2586 mk_sense_invalid_opcode(scp); 2586 mk_sense_invalid_opcode(scp);
2587 return check_condition_result; 2587 return check_condition_result;
2588 } 2588 }
2589 if ((sdebug_dif == SD_DIF_TYPE1_PROTECTION || 2589 if ((sdebug_dif == T10_PI_TYPE1_PROTECTION ||
2590 sdebug_dif == SD_DIF_TYPE3_PROTECTION) && 2590 sdebug_dif == T10_PI_TYPE3_PROTECTION) &&
2591 (cmd[1] & 0xe0) == 0) 2591 (cmd[1] & 0xe0) == 0)
2592 sdev_printk(KERN_ERR, scp->device, "Unprotected RD " 2592 sdev_printk(KERN_ERR, scp->device, "Unprotected RD "
2593 "to DIF device\n"); 2593 "to DIF device\n");
@@ -2894,13 +2894,13 @@ static int resp_write_dt0(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
2894 break; 2894 break;
2895 } 2895 }
2896 if (unlikely(have_dif_prot && check_prot)) { 2896 if (unlikely(have_dif_prot && check_prot)) {
2897 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION && 2897 if (sdebug_dif == T10_PI_TYPE2_PROTECTION &&
2898 (cmd[1] & 0xe0)) { 2898 (cmd[1] & 0xe0)) {
2899 mk_sense_invalid_opcode(scp); 2899 mk_sense_invalid_opcode(scp);
2900 return check_condition_result; 2900 return check_condition_result;
2901 } 2901 }
2902 if ((sdebug_dif == SD_DIF_TYPE1_PROTECTION || 2902 if ((sdebug_dif == T10_PI_TYPE1_PROTECTION ||
2903 sdebug_dif == SD_DIF_TYPE3_PROTECTION) && 2903 sdebug_dif == T10_PI_TYPE3_PROTECTION) &&
2904 (cmd[1] & 0xe0) == 0) 2904 (cmd[1] & 0xe0) == 0)
2905 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " 2905 sdev_printk(KERN_ERR, scp->device, "Unprotected WR "
2906 "to DIF device\n"); 2906 "to DIF device\n");
@@ -3136,13 +3136,13 @@ static int resp_comp_write(struct scsi_cmnd *scp,
3136 num = cmd[13]; /* 1 to a maximum of 255 logical blocks */ 3136 num = cmd[13]; /* 1 to a maximum of 255 logical blocks */
3137 if (0 == num) 3137 if (0 == num)
3138 return 0; /* degenerate case, not an error */ 3138 return 0; /* degenerate case, not an error */
3139 if (sdebug_dif == SD_DIF_TYPE2_PROTECTION && 3139 if (sdebug_dif == T10_PI_TYPE2_PROTECTION &&
3140 (cmd[1] & 0xe0)) { 3140 (cmd[1] & 0xe0)) {
3141 mk_sense_invalid_opcode(scp); 3141 mk_sense_invalid_opcode(scp);
3142 return check_condition_result; 3142 return check_condition_result;
3143 } 3143 }
3144 if ((sdebug_dif == SD_DIF_TYPE1_PROTECTION || 3144 if ((sdebug_dif == T10_PI_TYPE1_PROTECTION ||
3145 sdebug_dif == SD_DIF_TYPE3_PROTECTION) && 3145 sdebug_dif == T10_PI_TYPE3_PROTECTION) &&
3146 (cmd[1] & 0xe0) == 0) 3146 (cmd[1] & 0xe0) == 0)
3147 sdev_printk(KERN_ERR, scp->device, "Unprotected WR " 3147 sdev_printk(KERN_ERR, scp->device, "Unprotected WR "
3148 "to DIF device\n"); 3148 "to DIF device\n");
@@ -4940,12 +4940,11 @@ static int __init scsi_debug_init(void)
4940 } 4940 }
4941 4941
4942 switch (sdebug_dif) { 4942 switch (sdebug_dif) {
4943 4943 case T10_PI_TYPE0_PROTECTION:
4944 case SD_DIF_TYPE0_PROTECTION:
4945 break; 4944 break;
4946 case SD_DIF_TYPE1_PROTECTION: 4945 case T10_PI_TYPE1_PROTECTION:
4947 case SD_DIF_TYPE2_PROTECTION: 4946 case T10_PI_TYPE2_PROTECTION:
4948 case SD_DIF_TYPE3_PROTECTION: 4947 case T10_PI_TYPE3_PROTECTION:
4949 have_dif_prot = true; 4948 have_dif_prot = true;
4950 break; 4949 break;
4951 4950
@@ -5481,19 +5480,19 @@ static int sdebug_driver_probe(struct device * dev)
5481 5480
5482 switch (sdebug_dif) { 5481 switch (sdebug_dif) {
5483 5482
5484 case SD_DIF_TYPE1_PROTECTION: 5483 case T10_PI_TYPE1_PROTECTION:
5485 hprot = SHOST_DIF_TYPE1_PROTECTION; 5484 hprot = SHOST_DIF_TYPE1_PROTECTION;
5486 if (sdebug_dix) 5485 if (sdebug_dix)
5487 hprot |= SHOST_DIX_TYPE1_PROTECTION; 5486 hprot |= SHOST_DIX_TYPE1_PROTECTION;
5488 break; 5487 break;
5489 5488
5490 case SD_DIF_TYPE2_PROTECTION: 5489 case T10_PI_TYPE2_PROTECTION:
5491 hprot = SHOST_DIF_TYPE2_PROTECTION; 5490 hprot = SHOST_DIF_TYPE2_PROTECTION;
5492 if (sdebug_dix) 5491 if (sdebug_dix)
5493 hprot |= SHOST_DIX_TYPE2_PROTECTION; 5492 hprot |= SHOST_DIX_TYPE2_PROTECTION;
5494 break; 5493 break;
5495 5494
5496 case SD_DIF_TYPE3_PROTECTION: 5495 case T10_PI_TYPE3_PROTECTION:
5497 hprot = SHOST_DIF_TYPE3_PROTECTION; 5496 hprot = SHOST_DIF_TYPE3_PROTECTION;
5498 if (sdebug_dix) 5497 if (sdebug_dix)
5499 hprot |= SHOST_DIX_TYPE3_PROTECTION; 5498 hprot |= SHOST_DIX_TYPE3_PROTECTION;
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
index d3e852ad5aa3..51e56296f465 100644
--- a/drivers/scsi/sd.c
+++ b/drivers/scsi/sd.c
@@ -52,6 +52,7 @@
52#include <linux/slab.h> 52#include <linux/slab.h>
53#include <linux/pm_runtime.h> 53#include <linux/pm_runtime.h>
54#include <linux/pr.h> 54#include <linux/pr.h>
55#include <linux/t10-pi.h>
55#include <asm/uaccess.h> 56#include <asm/uaccess.h>
56#include <asm/unaligned.h> 57#include <asm/unaligned.h>
57 58
@@ -314,7 +315,7 @@ protection_type_store(struct device *dev, struct device_attribute *attr,
314 if (err) 315 if (err)
315 return err; 316 return err;
316 317
317 if (val >= 0 && val <= SD_DIF_TYPE3_PROTECTION) 318 if (val >= 0 && val <= T10_PI_TYPE3_PROTECTION)
318 sdkp->protection_type = val; 319 sdkp->protection_type = val;
319 320
320 return count; 321 return count;
@@ -332,7 +333,7 @@ protection_mode_show(struct device *dev, struct device_attribute *attr,
332 dif = scsi_host_dif_capable(sdp->host, sdkp->protection_type); 333 dif = scsi_host_dif_capable(sdp->host, sdkp->protection_type);
333 dix = scsi_host_dix_capable(sdp->host, sdkp->protection_type); 334 dix = scsi_host_dix_capable(sdp->host, sdkp->protection_type);
334 335
335 if (!dix && scsi_host_dix_capable(sdp->host, SD_DIF_TYPE0_PROTECTION)) { 336 if (!dix && scsi_host_dix_capable(sdp->host, T10_PI_TYPE0_PROTECTION)) {
336 dif = 0; 337 dif = 0;
337 dix = 1; 338 dix = 1;
338 } 339 }
@@ -608,7 +609,7 @@ static unsigned char sd_setup_protect_cmnd(struct scsi_cmnd *scmd,
608 scmd->prot_flags |= SCSI_PROT_GUARD_CHECK; 609 scmd->prot_flags |= SCSI_PROT_GUARD_CHECK;
609 } 610 }
610 611
611 if (dif != SD_DIF_TYPE3_PROTECTION) { /* DIX/DIF Type 0, 1, 2 */ 612 if (dif != T10_PI_TYPE3_PROTECTION) { /* DIX/DIF Type 0, 1, 2 */
612 scmd->prot_flags |= SCSI_PROT_REF_INCREMENT; 613 scmd->prot_flags |= SCSI_PROT_REF_INCREMENT;
613 614
614 if (bio_integrity_flagged(bio, BIP_CTRL_NOCHECK) == false) 615 if (bio_integrity_flagged(bio, BIP_CTRL_NOCHECK) == false)
@@ -1031,7 +1032,7 @@ static int sd_setup_read_write_cmnd(struct scsi_cmnd *SCpnt)
1031 else 1032 else
1032 protect = 0; 1033 protect = 0;
1033 1034
1034 if (protect && sdkp->protection_type == SD_DIF_TYPE2_PROTECTION) { 1035 if (protect && sdkp->protection_type == T10_PI_TYPE2_PROTECTION) {
1035 SCpnt->cmnd = mempool_alloc(sd_cdb_pool, GFP_ATOMIC); 1036 SCpnt->cmnd = mempool_alloc(sd_cdb_pool, GFP_ATOMIC);
1036 1037
1037 if (unlikely(SCpnt->cmnd == NULL)) { 1038 if (unlikely(SCpnt->cmnd == NULL)) {
@@ -1997,7 +1998,7 @@ static int sd_read_protection_type(struct scsi_disk *sdkp, unsigned char *buffer
1997 1998
1998 type = ((buffer[12] >> 1) & 7) + 1; /* P_TYPE 0 = Type 1 */ 1999 type = ((buffer[12] >> 1) & 7) + 1; /* P_TYPE 0 = Type 1 */
1999 2000
2000 if (type > SD_DIF_TYPE3_PROTECTION) 2001 if (type > T10_PI_TYPE3_PROTECTION)
2001 ret = -ENODEV; 2002 ret = -ENODEV;
2002 else if (scsi_host_dif_capable(sdp->host, type)) 2003 else if (scsi_host_dif_capable(sdp->host, type))
2003 ret = 1; 2004 ret = 1;
diff --git a/drivers/scsi/sd.h b/drivers/scsi/sd.h
index d00966d6b41e..c8d986368da9 100644
--- a/drivers/scsi/sd.h
+++ b/drivers/scsi/sd.h
@@ -157,27 +157,6 @@ static inline unsigned int logical_to_bytes(struct scsi_device *sdev, sector_t b
157} 157}
158 158
159/* 159/*
160 * A DIF-capable target device can be formatted with different
161 * protection schemes. Currently 0 through 3 are defined:
162 *
163 * Type 0 is regular (unprotected) I/O
164 *
165 * Type 1 defines the contents of the guard and reference tags
166 *
167 * Type 2 defines the contents of the guard and reference tags and
168 * uses 32-byte commands to seed the latter
169 *
170 * Type 3 defines the contents of the guard tag only
171 */
172
173enum sd_dif_target_protection_types {
174 SD_DIF_TYPE0_PROTECTION = 0x0,
175 SD_DIF_TYPE1_PROTECTION = 0x1,
176 SD_DIF_TYPE2_PROTECTION = 0x2,
177 SD_DIF_TYPE3_PROTECTION = 0x3,
178};
179
180/*
181 * Look up the DIX operation based on whether the command is read or 160 * Look up the DIX operation based on whether the command is read or
182 * write and whether dix and dif are enabled. 161 * write and whether dix and dif are enabled.
183 */ 162 */
diff --git a/drivers/scsi/sd_dif.c b/drivers/scsi/sd_dif.c
index 987bf392c336..9035380c0dda 100644
--- a/drivers/scsi/sd_dif.c
+++ b/drivers/scsi/sd_dif.c
@@ -60,14 +60,14 @@ void sd_dif_config_host(struct scsi_disk *sdkp)
60 60
61 /* Enable DMA of protection information */ 61 /* Enable DMA of protection information */
62 if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP) { 62 if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP) {
63 if (type == SD_DIF_TYPE3_PROTECTION) 63 if (type == T10_PI_TYPE3_PROTECTION)
64 bi.profile = &t10_pi_type3_ip; 64 bi.profile = &t10_pi_type3_ip;
65 else 65 else
66 bi.profile = &t10_pi_type1_ip; 66 bi.profile = &t10_pi_type1_ip;
67 67
68 bi.flags |= BLK_INTEGRITY_IP_CHECKSUM; 68 bi.flags |= BLK_INTEGRITY_IP_CHECKSUM;
69 } else 69 } else
70 if (type == SD_DIF_TYPE3_PROTECTION) 70 if (type == T10_PI_TYPE3_PROTECTION)
71 bi.profile = &t10_pi_type3_crc; 71 bi.profile = &t10_pi_type3_crc;
72 else 72 else
73 bi.profile = &t10_pi_type1_crc; 73 bi.profile = &t10_pi_type1_crc;
@@ -82,7 +82,7 @@ void sd_dif_config_host(struct scsi_disk *sdkp)
82 if (!sdkp->ATO) 82 if (!sdkp->ATO)
83 goto out; 83 goto out;
84 84
85 if (type == SD_DIF_TYPE3_PROTECTION) 85 if (type == T10_PI_TYPE3_PROTECTION)
86 bi.tag_size = sizeof(u16) + sizeof(u32); 86 bi.tag_size = sizeof(u16) + sizeof(u32);
87 else 87 else
88 bi.tag_size = sizeof(u16); 88 bi.tag_size = sizeof(u16);
@@ -121,7 +121,7 @@ void sd_dif_prepare(struct scsi_cmnd *scmd)
121 121
122 sdkp = scsi_disk(scmd->request->rq_disk); 122 sdkp = scsi_disk(scmd->request->rq_disk);
123 123
124 if (sdkp->protection_type == SD_DIF_TYPE3_PROTECTION) 124 if (sdkp->protection_type == T10_PI_TYPE3_PROTECTION)
125 return; 125 return;
126 126
127 phys = scsi_prot_ref_tag(scmd); 127 phys = scsi_prot_ref_tag(scmd);
@@ -172,7 +172,7 @@ void sd_dif_complete(struct scsi_cmnd *scmd, unsigned int good_bytes)
172 172
173 sdkp = scsi_disk(scmd->request->rq_disk); 173 sdkp = scsi_disk(scmd->request->rq_disk);
174 174
175 if (sdkp->protection_type == SD_DIF_TYPE3_PROTECTION || good_bytes == 0) 175 if (sdkp->protection_type == T10_PI_TYPE3_PROTECTION || good_bytes == 0)
176 return; 176 return;
177 177
178 intervals = good_bytes / scsi_prot_interval(scmd); 178 intervals = good_bytes / scsi_prot_interval(scmd);
diff --git a/include/linux/t10-pi.h b/include/linux/t10-pi.h
index dd8de82cf5b5..9fba9dd33544 100644
--- a/include/linux/t10-pi.h
+++ b/include/linux/t10-pi.h
@@ -5,6 +5,26 @@
5#include <linux/blkdev.h> 5#include <linux/blkdev.h>
6 6
7/* 7/*
8 * A T10 PI-capable target device can be formatted with different
9 * protection schemes. Currently 0 through 3 are defined:
10 *
11 * Type 0 is regular (unprotected) I/O
12 *
13 * Type 1 defines the contents of the guard and reference tags
14 *
15 * Type 2 defines the contents of the guard and reference tags and
16 * uses 32-byte commands to seed the latter
17 *
18 * Type 3 defines the contents of the guard tag only
19 */
20enum t10_dif_type {
21 T10_PI_TYPE0_PROTECTION = 0x0,
22 T10_PI_TYPE1_PROTECTION = 0x1,
23 T10_PI_TYPE2_PROTECTION = 0x2,
24 T10_PI_TYPE3_PROTECTION = 0x3,
25};
26
27/*
8 * T10 Protection Information tuple. 28 * T10 Protection Information tuple.
9 */ 29 */
10struct t10_pi_tuple { 30struct t10_pi_tuple {