sd_dif.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * sd_dif.c - SCSI Data Integrity Field
  4. *
  5. * Copyright (C) 2007, 2008 Oracle Corporation
  6. * Written by: Martin K. Petersen <martin.petersen@oracle.com>
  7. */
  8. #include <linux/blk-integrity.h>
  9. #include <linux/t10-pi.h>
  10. #include <scsi/scsi.h>
  11. #include <scsi/scsi_cmnd.h>
  12. #include <scsi/scsi_dbg.h>
  13. #include <scsi/scsi_device.h>
  14. #include <scsi/scsi_driver.h>
  15. #include <scsi/scsi_eh.h>
  16. #include <scsi/scsi_host.h>
  17. #include <scsi/scsi_ioctl.h>
  18. #include <scsi/scsicam.h>
  19. #include "sd.h"
  20. /*
  21. * Configure exchange of protection information between OS and HBA.
  22. */
  23. void sd_dif_config_host(struct scsi_disk *sdkp, struct queue_limits *lim)
  24. {
  25. struct scsi_device *sdp = sdkp->device;
  26. u8 type = sdkp->protection_type;
  27. struct blk_integrity *bi = &lim->integrity;
  28. int dif, dix;
  29. memset(bi, 0, sizeof(*bi));
  30. dif = scsi_host_dif_capable(sdp->host, type);
  31. dix = scsi_host_dix_capable(sdp->host, type);
  32. if (!dix && scsi_host_dix_capable(sdp->host, 0)) {
  33. dif = 0; dix = 1;
  34. }
  35. if (!dix)
  36. return;
  37. /* Enable DMA of protection information */
  38. if (scsi_host_get_guard(sdkp->device->host) & SHOST_DIX_GUARD_IP)
  39. bi->csum_type = BLK_INTEGRITY_CSUM_IP;
  40. else
  41. bi->csum_type = BLK_INTEGRITY_CSUM_CRC;
  42. if (type != T10_PI_TYPE3_PROTECTION)
  43. bi->flags |= BLK_INTEGRITY_REF_TAG;
  44. bi->metadata_size = sizeof(struct t10_pi_tuple);
  45. bi->pi_tuple_size = bi->metadata_size;
  46. if (dif && type) {
  47. bi->flags |= BLK_INTEGRITY_DEVICE_CAPABLE;
  48. if (!sdkp->ATO)
  49. return;
  50. if (type == T10_PI_TYPE3_PROTECTION)
  51. bi->tag_size = sizeof(u16) + sizeof(u32);
  52. else
  53. bi->tag_size = sizeof(u16);
  54. }
  55. sd_first_printk(KERN_NOTICE, sdkp,
  56. "Enabling DIX %s, application tag size %u bytes\n",
  57. blk_integrity_profile_name(bi), bi->tag_size);
  58. }