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