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