t10-pi.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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/blkdev.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. #ifdef CONFIG_BLK_DEV_INTEGRITY
  38. return blk_rq_pos(rq) >>
  39. (rq->q->integrity.interval_exp - 9) & 0xffffffff;
  40. #else
  41. return -1U;
  42. #endif
  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. extern void t10_pi_prepare(struct request *rq, u8 protection_type);
  49. extern void t10_pi_complete(struct request *rq, u8 protection_type,
  50. unsigned int intervals);
  51. #endif