sd_dif.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * sd_dif.c - SCSI Data Integrity Field
  3. *
  4. * Copyright (C) 2007, 2008 Oracle Corporation
  5. * Written by: Martin K. Petersen <martin.petersen@oracle.com>
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version
  9. * 2 as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; see the file COPYING. If not, write to
  18. * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
  19. * USA.
  20. *
  21. */
  22. #include <linux/blkdev.h>
  23. #include <linux/t10-pi.h>
  24. #include <scsi/scsi.h>
  25. #include <scsi/scsi_cmnd.h>
  26. #include <scsi/scsi_dbg.h>
  27. #include <scsi/scsi_device.h>
  28. #include <scsi/scsi_driver.h>
  29. #include <scsi/scsi_eh.h>
  30. #include <scsi/scsi_host.h>
  31. #include <scsi/scsi_ioctl.h>
  32. #include <scsi/scsicam.h>
  33. #include "sd.h"
  34. /*
  35. * Configure exchange of protection information between OS and HBA.
  36. */
  37. void sd_dif_config_host(struct scsi_disk *sdkp)
  38. {
  39. struct scsi_device *sdp = sdkp->device;
  40. struct gendisk *disk = sdkp->disk;
  41. u8 type = sdkp->protection_type;
  42. struct blk_integrity bi;
  43. int dif, dix;
  44. dif = scsi_host_dif_capable(sdp->host, type);
  45. dix = scsi_host_dix_capable(sdp->host, type);
  46. if (!dix && scsi_host_dix_capable(sdp->host, 0)) {
  47. dif = 0; dix = 1;
  48. }
  49. if (!dix)
  50. return;
  51. memset(&bi, 0, sizeof(bi));
  52. /* Enable DMA of protection information */
  53. if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP) {
  54. if (type == T10_PI_TYPE3_PROTECTION)
  55. bi.profile = &t10_pi_type3_ip;
  56. else
  57. bi.profile = &t10_pi_type1_ip;
  58. bi.flags |= BLK_INTEGRITY_IP_CHECKSUM;
  59. } else
  60. if (type == T10_PI_TYPE3_PROTECTION)
  61. bi.profile = &t10_pi_type3_crc;
  62. else
  63. bi.profile = &t10_pi_type1_crc;
  64. bi.tuple_size = sizeof(struct t10_pi_tuple);
  65. sd_printk(KERN_NOTICE, sdkp,
  66. "Enabling DIX %s protection\n", bi.profile->name);
  67. if (dif && type) {
  68. bi.flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
  69. if (!sdkp->ATO)
  70. goto out;
  71. if (type == T10_PI_TYPE3_PROTECTION)
  72. bi.tag_size = sizeof(u16) + sizeof(u32);
  73. else
  74. bi.tag_size = sizeof(u16);
  75. sd_printk(KERN_NOTICE, sdkp, "DIF application tag size %u\n",
  76. bi.tag_size);
  77. }
  78. out:
  79. blk_integrity_register(disk, &bi);
  80. }