label.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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. * @labelsize: log2 size (v1 labels 128 bytes v2 labels 256 bytes)
  35. * @seq: sequence number for this index
  36. * @myoff: offset of this index in label area
  37. * @mysize: size of this index struct
  38. * @otheroff: offset of other index
  39. * @labeloff: offset of first label slot
  40. * @nslot: total number of label slots
  41. * @major: label area major version
  42. * @minor: label area minor version
  43. * @checksum: fletcher64 of all fields
  44. * @free: bitmap, nlabel bits
  45. *
  46. * The size of free[] is rounded up so the total struct size is a
  47. * multiple of NSINDEX_ALIGN bytes. Any bits this allocates beyond
  48. * nlabel bits must be zero.
  49. */
  50. struct nd_namespace_index {
  51. u8 sig[NSINDEX_SIG_LEN];
  52. u8 flags[3];
  53. u8 labelsize;
  54. __le32 seq;
  55. __le64 myoff;
  56. __le64 mysize;
  57. __le64 otheroff;
  58. __le64 labeloff;
  59. __le32 nslot;
  60. __le16 major;
  61. __le16 minor;
  62. __le64 checksum;
  63. u8 free[];
  64. };
  65. /**
  66. * struct cxl_region_label - CXL 2.0 Table 211
  67. * @type: uuid identifying this label format (region)
  68. * @uuid: uuid for the region this label describes
  69. * @flags: NSLABEL_FLAG_UPDATING (all other flags reserved)
  70. * @nlabel: 1 per interleave-way in the region
  71. * @position: this label's position in the set
  72. * @dpa: start address in device-local capacity for this label
  73. * @rawsize: size of this label's contribution to region
  74. * @hpa: mandatory system physical address to map this region
  75. * @slot: slot id of this label in label area
  76. * @ig: interleave granularity (1 << @ig) * 256 bytes
  77. * @align: alignment in SZ_256M blocks
  78. * @reserved: reserved
  79. * @checksum: fletcher64 sum of this label
  80. */
  81. struct cxl_region_label {
  82. u8 type[NSLABEL_UUID_LEN];
  83. u8 uuid[NSLABEL_UUID_LEN];
  84. __le32 flags;
  85. __le16 nlabel;
  86. __le16 position;
  87. __le64 dpa;
  88. __le64 rawsize;
  89. __le64 hpa;
  90. __le32 slot;
  91. __le32 ig;
  92. __le32 align;
  93. u8 reserved[0xac];
  94. __le64 checksum;
  95. };
  96. /**
  97. * struct nvdimm_efi_label - namespace superblock
  98. * @uuid: UUID per RFC 4122
  99. * @name: optional name (NULL-terminated)
  100. * @flags: see NSLABEL_FLAG_*
  101. * @nlabel: num labels to describe this ns
  102. * @position: labels position in set
  103. * @isetcookie: interleave set cookie
  104. * @lbasize: LBA size in bytes or 0 for pmem
  105. * @dpa: DPA of NVM range on this DIMM
  106. * @rawsize: size of namespace
  107. * @slot: slot of this label in label area
  108. * @align: physical address alignment of the namespace
  109. * @reserved: reserved
  110. * @type_guid: copy of struct acpi_nfit_system_address.range_guid
  111. * @abstraction_guid: personality id (btt, btt2, fsdax, devdax....)
  112. * @reserved2: reserved
  113. * @checksum: fletcher64 sum of this object
  114. */
  115. struct nvdimm_efi_label {
  116. u8 uuid[NSLABEL_UUID_LEN];
  117. u8 name[NSLABEL_NAME_LEN];
  118. __le32 flags;
  119. __le16 nlabel;
  120. __le16 position;
  121. __le64 isetcookie;
  122. __le64 lbasize;
  123. __le64 dpa;
  124. __le64 rawsize;
  125. __le32 slot;
  126. /*
  127. * Accessing fields past this point should be gated by a
  128. * efi_namespace_label_has() check.
  129. */
  130. u8 align;
  131. u8 reserved[3];
  132. guid_t type_guid;
  133. guid_t abstraction_guid;
  134. u8 reserved2[88];
  135. __le64 checksum;
  136. };
  137. /**
  138. * struct nvdimm_cxl_label - CXL 2.0 Table 212
  139. * @type: uuid identifying this label format (namespace)
  140. * @uuid: uuid for the namespace this label describes
  141. * @name: friendly name for the namespace
  142. * @flags: NSLABEL_FLAG_UPDATING (all other flags reserved)
  143. * @nrange: discontiguous namespace support
  144. * @position: this label's position in the set
  145. * @dpa: start address in device-local capacity for this label
  146. * @rawsize: size of this label's contribution to namespace
  147. * @slot: slot id of this label in label area
  148. * @align: alignment in SZ_256M blocks
  149. * @region_uuid: host interleave set identifier
  150. * @abstraction_uuid: personality driver for this namespace
  151. * @lbasize: address geometry for disk-like personalities
  152. * @reserved: reserved
  153. * @checksum: fletcher64 sum of this label
  154. */
  155. struct nvdimm_cxl_label {
  156. u8 type[NSLABEL_UUID_LEN];
  157. u8 uuid[NSLABEL_UUID_LEN];
  158. u8 name[NSLABEL_NAME_LEN];
  159. __le32 flags;
  160. __le16 nrange;
  161. __le16 position;
  162. __le64 dpa;
  163. __le64 rawsize;
  164. __le32 slot;
  165. __le32 align;
  166. u8 region_uuid[16];
  167. u8 abstraction_uuid[16];
  168. __le16 lbasize;
  169. u8 reserved[0x56];
  170. __le64 checksum;
  171. };
  172. struct nd_namespace_label {
  173. union {
  174. struct nvdimm_cxl_label cxl;
  175. struct nvdimm_efi_label efi;
  176. };
  177. };
  178. #define NVDIMM_BTT_GUID "8aed63a2-29a2-4c66-8b12-f05d15d3922a"
  179. #define NVDIMM_BTT2_GUID "18633bfc-1735-4217-8ac9-17239282d3f8"
  180. #define NVDIMM_PFN_GUID "266400ba-fb9f-4677-bcb0-968f11d0d225"
  181. #define NVDIMM_DAX_GUID "97a86d9c-3cdd-4eda-986f-5068b4f80088"
  182. #define CXL_REGION_UUID "529d7c61-da07-47c4-a93f-ecdf2c06f444"
  183. #define CXL_NAMESPACE_UUID "68bb2c0a-5a77-4937-9f85-3caf41a0f93c"
  184. /**
  185. * struct nd_label_id - identifier string for dpa allocation
  186. * @id: "pmem-<namespace uuid>"
  187. */
  188. struct nd_label_id {
  189. char id[ND_LABEL_ID_SIZE];
  190. };
  191. /*
  192. * If the 'best' index is invalid, so is the 'next' index. Otherwise,
  193. * the next index is MOD(index+1, 2)
  194. */
  195. static inline int nd_label_next_nsindex(int index)
  196. {
  197. if (index < 0)
  198. return -1;
  199. return (index + 1) % 2;
  200. }
  201. struct nvdimm_drvdata;
  202. int nd_label_data_init(struct nvdimm_drvdata *ndd);
  203. size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd);
  204. int nd_label_active_count(struct nvdimm_drvdata *ndd);
  205. struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n);
  206. u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd);
  207. bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot);
  208. u32 nd_label_nfree(struct nvdimm_drvdata *ndd);
  209. struct nd_region;
  210. struct nd_namespace_pmem;
  211. int nd_pmem_namespace_label_update(struct nd_region *nd_region,
  212. struct nd_namespace_pmem *nspm, resource_size_t size);
  213. #endif /* __LABEL_H__ */