t10-pi.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_T10_PI_H
  3. #define _LINUX_T10_PI_H
  4. #include <linux/types.h>
  5. #include <linux/blk-mq.h>
  6. /*
  7. * A T10 PI-capable target device can be formatted with different
  8. * protection schemes. Currently 0 through 3 are defined:
  9. *
  10. * Type 0 is regular (unprotected) I/O
  11. *
  12. * Type 1 defines the contents of the guard and reference tags
  13. *
  14. * Type 2 defines the contents of the guard and reference tags and
  15. * uses 32-byte commands to seed the latter
  16. *
  17. * Type 3 defines the contents of the guard tag only
  18. */
  19. enum t10_dif_type {
  20. T10_PI_TYPE0_PROTECTION = 0x0,
  21. T10_PI_TYPE1_PROTECTION = 0x1,
  22. T10_PI_TYPE2_PROTECTION = 0x2,
  23. T10_PI_TYPE3_PROTECTION = 0x3,
  24. };
  25. /*
  26. * T10 Protection Information tuple.
  27. */
  28. struct t10_pi_tuple {
  29. __be16 guard_tag; /* Checksum */
  30. __be16 app_tag; /* Opaque storage */
  31. __be32 ref_tag; /* Target LBA or indirect LBA */
  32. };
  33. #define T10_PI_APP_ESCAPE cpu_to_be16(0xffff)
  34. #define T10_PI_REF_ESCAPE cpu_to_be32(0xffffffff)
  35. static inline u32 t10_pi_ref_tag(struct request *rq)
  36. {
  37. unsigned int shift = ilog2(queue_logical_block_size(rq->q));
  38. #ifdef CONFIG_BLK_DEV_INTEGRITY
  39. if (rq->q->integrity.interval_exp)
  40. shift = rq->q->integrity.interval_exp;
  41. #endif
  42. return blk_rq_pos(rq) >> (shift - SECTOR_SHIFT) & 0xffffffff;
  43. }
  44. extern const struct blk_integrity_profile t10_pi_type1_crc;
  45. extern const struct blk_integrity_profile t10_pi_type1_ip;
  46. extern const struct blk_integrity_profile t10_pi_type3_crc;
  47. extern const struct blk_integrity_profile t10_pi_type3_ip;
  48. struct crc64_pi_tuple {
  49. __be64 guard_tag;
  50. __be16 app_tag;
  51. __u8 ref_tag[6];
  52. };
  53. /**
  54. * lower_48_bits() - return bits 0-47 of a number
  55. * @n: the number we're accessing
  56. */
  57. static inline u64 lower_48_bits(u64 n)
  58. {
  59. return n & ((1ull << 48) - 1);
  60. }
  61. static inline u64 ext_pi_ref_tag(struct request *rq)
  62. {
  63. unsigned int shift = ilog2(queue_logical_block_size(rq->q));
  64. #ifdef CONFIG_BLK_DEV_INTEGRITY
  65. if (rq->q->integrity.interval_exp)
  66. shift = rq->q->integrity.interval_exp;
  67. #endif
  68. return lower_48_bits(blk_rq_pos(rq) >> (shift - SECTOR_SHIFT));
  69. }
  70. extern const struct blk_integrity_profile ext_pi_type1_crc64;
  71. extern const struct blk_integrity_profile ext_pi_type3_crc64;
  72. #endif