label.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
  4. */
  5. #ifndef __LABEL_H__
  6. #define __LABEL_H__
  7. #include <linux/ndctl.h>
  8. #include <linux/sizes.h>
  9. #include <linux/uuid.h>
  10. #include <linux/io.h>
  11. enum {
  12. NSINDEX_SIG_LEN = 16,
  13. NSINDEX_ALIGN = 256,
  14. NSINDEX_SEQ_MASK = 0x3,
  15. NSLABEL_UUID_LEN = 16,
  16. NSLABEL_NAME_LEN = 64,
  17. NSLABEL_FLAG_ROLABEL = 0x1, /* read-only label */
  18. NSLABEL_FLAG_LOCAL = 0x2, /* DIMM-local namespace */
  19. NSLABEL_FLAG_BTT = 0x4, /* namespace contains a BTT */
  20. NSLABEL_FLAG_UPDATING = 0x8, /* label being updated */
  21. BTT_ALIGN = 4096, /* all btt structures */
  22. BTTINFO_SIG_LEN = 16,
  23. BTTINFO_UUID_LEN = 16,
  24. BTTINFO_FLAG_ERROR = 0x1, /* error state (read-only) */
  25. BTTINFO_MAJOR_VERSION = 1,
  26. ND_LABEL_MIN_SIZE = 256 * 4, /* see sizeof_namespace_index() */
  27. ND_LABEL_ID_SIZE = 50,
  28. ND_NSINDEX_INIT = 0x1,
  29. };
  30. /**
  31. * struct nd_namespace_index - label set superblock
  32. * @sig: NAMESPACE_INDEX\0
  33. * @flags: placeholder
  34. * @seq: sequence number for this index
  35. * @myoff: offset of this index in label area
  36. * @mysize: size of this index struct
  37. * @otheroff: offset of other index
  38. * @labeloff: offset of first label slot
  39. * @nslot: total number of label slots
  40. * @major: label area major version
  41. * @minor: label area minor version
  42. * @checksum: fletcher64 of all fields
  43. * @free[0]: bitmap, nlabel bits
  44. *
  45. * The size of free[] is rounded up so the total struct size is a
  46. * multiple of NSINDEX_ALIGN bytes. Any bits this allocates beyond
  47. * nlabel bits must be zero.
  48. */
  49. struct nd_namespace_index {
  50. u8 sig[NSINDEX_SIG_LEN];
  51. u8 flags[3];
  52. u8 labelsize;
  53. __le32 seq;
  54. __le64 myoff;
  55. __le64 mysize;
  56. __le64 otheroff;
  57. __le64 labeloff;
  58. __le32 nslot;
  59. __le16 major;
  60. __le16 minor;
  61. __le64 checksum;
  62. u8 free[];
  63. };
  64. /**
  65. * struct nd_namespace_label - namespace superblock
  66. * @uuid: UUID per RFC 4122
  67. * @name: optional name (NULL-terminated)
  68. * @flags: see NSLABEL_FLAG_*
  69. * @nlabel: num labels to describe this ns
  70. * @position: labels position in set
  71. * @isetcookie: interleave set cookie
  72. * @lbasize: LBA size in bytes or 0 for pmem
  73. * @dpa: DPA of NVM range on this DIMM
  74. * @rawsize: size of namespace
  75. * @slot: slot of this label in label area
  76. * @unused: must be zero
  77. */
  78. struct nd_namespace_label {
  79. u8 uuid[NSLABEL_UUID_LEN];
  80. u8 name[NSLABEL_NAME_LEN];
  81. __le32 flags;
  82. __le16 nlabel;
  83. __le16 position;
  84. __le64 isetcookie;
  85. __le64 lbasize;
  86. __le64 dpa;
  87. __le64 rawsize;
  88. __le32 slot;
  89. /*
  90. * Accessing fields past this point should be gated by a
  91. * namespace_label_has() check.
  92. */
  93. u8 align;
  94. u8 reserved[3];
  95. guid_t type_guid;
  96. guid_t abstraction_guid;
  97. u8 reserved2[88];
  98. __le64 checksum;
  99. };
  100. #define NVDIMM_BTT_GUID "8aed63a2-29a2-4c66-8b12-f05d15d3922a"
  101. #define NVDIMM_BTT2_GUID "18633bfc-1735-4217-8ac9-17239282d3f8"
  102. #define NVDIMM_PFN_GUID "266400ba-fb9f-4677-bcb0-968f11d0d225"
  103. #define NVDIMM_DAX_GUID "97a86d9c-3cdd-4eda-986f-5068b4f80088"
  104. /**
  105. * struct nd_label_id - identifier string for dpa allocation
  106. * @id: "{blk|pmem}-<namespace uuid>"
  107. */
  108. struct nd_label_id {
  109. char id[ND_LABEL_ID_SIZE];
  110. };
  111. /*
  112. * If the 'best' index is invalid, so is the 'next' index. Otherwise,
  113. * the next index is MOD(index+1, 2)
  114. */
  115. static inline int nd_label_next_nsindex(int index)
  116. {
  117. if (index < 0)
  118. return -1;
  119. return (index + 1) % 2;
  120. }
  121. struct nvdimm_drvdata;
  122. int nd_label_data_init(struct nvdimm_drvdata *ndd);
  123. size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd);
  124. int nd_label_active_count(struct nvdimm_drvdata *ndd);
  125. struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n);
  126. u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd);
  127. bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot);
  128. u32 nd_label_nfree(struct nvdimm_drvdata *ndd);
  129. enum nvdimm_claim_class to_nvdimm_cclass(guid_t *guid);
  130. struct nd_region;
  131. struct nd_namespace_pmem;
  132. struct nd_namespace_blk;
  133. int nd_pmem_namespace_label_update(struct nd_region *nd_region,
  134. struct nd_namespace_pmem *nspm, resource_size_t size);
  135. int nd_blk_namespace_label_update(struct nd_region *nd_region,
  136. struct nd_namespace_blk *nsblk, resource_size_t size);
  137. #endif /* __LABEL_H__ */