label.h 4.6 KB

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