Blame view

drivers/scsi/sd_dif.c 1.85 KB
a98c5b196   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-only
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
2
3
4
5
6
  /*
   * sd_dif.c - SCSI Data Integrity Field
   *
   * Copyright (C) 2007, 2008 Oracle Corporation
   * Written by: Martin K. Petersen <martin.petersen@oracle.com>
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
7
8
9
   */
  
  #include <linux/blkdev.h>
2341c2f8c   Martin K. Petersen   block: Add T10 Pr...
10
  #include <linux/t10-pi.h>
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
11
12
13
14
15
16
17
18
19
20
  
  #include <scsi/scsi.h>
  #include <scsi/scsi_cmnd.h>
  #include <scsi/scsi_dbg.h>
  #include <scsi/scsi_device.h>
  #include <scsi/scsi_driver.h>
  #include <scsi/scsi_eh.h>
  #include <scsi/scsi_host.h>
  #include <scsi/scsi_ioctl.h>
  #include <scsi/scsicam.h>
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
21
  #include "sd.h"
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
22
23
24
25
26
27
28
29
  /*
   * Configure exchange of protection information between OS and HBA.
   */
  void sd_dif_config_host(struct scsi_disk *sdkp)
  {
  	struct scsi_device *sdp = sdkp->device;
  	struct gendisk *disk = sdkp->disk;
  	u8 type = sdkp->protection_type;
0f8087ecd   Martin K. Petersen   block: Consolidat...
30
  	struct blk_integrity bi;
9e06688e7   Martin K. Petersen   [SCSI] sd: Correc...
31
  	int dif, dix;
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
32

9e06688e7   Martin K. Petersen   [SCSI] sd: Correc...
33
34
  	dif = scsi_host_dif_capable(sdp->host, type);
  	dix = scsi_host_dix_capable(sdp->host, type);
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
35

9e06688e7   Martin K. Petersen   [SCSI] sd: Correc...
36
37
38
  	if (!dix && scsi_host_dix_capable(sdp->host, 0)) {
  		dif = 0; dix = 1;
  	}
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
39

9e06688e7   Martin K. Petersen   [SCSI] sd: Correc...
40
  	if (!dix)
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
41
  		return;
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
42

0f8087ecd   Martin K. Petersen   block: Consolidat...
43
  	memset(&bi, 0, sizeof(bi));
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
44
  	/* Enable DMA of protection information */
aae7df501   Martin K. Petersen   block: Integrity ...
45
  	if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP) {
8475c8118   Christoph Hellwig   scsi: sd: Move DI...
46
  		if (type == T10_PI_TYPE3_PROTECTION)
0f8087ecd   Martin K. Petersen   block: Consolidat...
47
  			bi.profile = &t10_pi_type3_ip;
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
48
  		else
0f8087ecd   Martin K. Petersen   block: Consolidat...
49
  			bi.profile = &t10_pi_type1_ip;
aae7df501   Martin K. Petersen   block: Integrity ...
50

0f8087ecd   Martin K. Petersen   block: Consolidat...
51
  		bi.flags |= BLK_INTEGRITY_IP_CHECKSUM;
aae7df501   Martin K. Petersen   block: Integrity ...
52
  	} else
8475c8118   Christoph Hellwig   scsi: sd: Move DI...
53
  		if (type == T10_PI_TYPE3_PROTECTION)
0f8087ecd   Martin K. Petersen   block: Consolidat...
54
  			bi.profile = &t10_pi_type3_crc;
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
55
  		else
0f8087ecd   Martin K. Petersen   block: Consolidat...
56
  			bi.profile = &t10_pi_type1_crc;
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
57

0f8087ecd   Martin K. Petersen   block: Consolidat...
58
  	bi.tuple_size = sizeof(struct t10_pi_tuple);
cbdc14459   Martin K. Petersen   [SCSI] sd: Switch...
59
  	sd_printk(KERN_NOTICE, sdkp,
0f8087ecd   Martin K. Petersen   block: Consolidat...
60
61
  		  "Enabling DIX %s protection
  ", bi.profile->name);
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
62

3aec2f41a   Martin K. Petersen   block: Add a disk...
63
  	if (dif && type) {
0f8087ecd   Martin K. Petersen   block: Consolidat...
64
  		bi.flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
3aec2f41a   Martin K. Petersen   block: Add a disk...
65

e557990e3   Martin K. Petersen   sd: Fix missing A...
66
  		if (!sdkp->ATO)
0f8087ecd   Martin K. Petersen   block: Consolidat...
67
  			goto out;
3aec2f41a   Martin K. Petersen   block: Add a disk...
68

8475c8118   Christoph Hellwig   scsi: sd: Move DI...
69
  		if (type == T10_PI_TYPE3_PROTECTION)
0f8087ecd   Martin K. Petersen   block: Consolidat...
70
  			bi.tag_size = sizeof(u16) + sizeof(u32);
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
71
  		else
0f8087ecd   Martin K. Petersen   block: Consolidat...
72
  			bi.tag_size = sizeof(u16);
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
73

cbdc14459   Martin K. Petersen   [SCSI] sd: Switch...
74
75
  		sd_printk(KERN_NOTICE, sdkp, "DIF application tag size %u
  ",
0f8087ecd   Martin K. Petersen   block: Consolidat...
76
  			  bi.tag_size);
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
77
  	}
0f8087ecd   Martin K. Petersen   block: Consolidat...
78
79
80
  
  out:
  	blk_integrity_register(disk, &bi);
af55ff675   Martin K. Petersen   [SCSI] sd: Suppor...
81
  }