]>
Commit | Line | Data |
---|---|---|
4a826c83 DW |
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> | |
564e871a | 18 | #include <linux/uuid.h> |
4a826c83 DW |
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, | |
36 | ND_LABEL_MIN_SIZE = 512 * 129, /* see sizeof_namespace_index() */ | |
37 | ND_LABEL_ID_SIZE = 50, | |
f524bf27 | 38 | ND_NSINDEX_INIT = 0x1, |
4a826c83 DW |
39 | }; |
40 | ||
4a826c83 DW |
41 | /** |
42 | * struct nd_namespace_index - label set superblock | |
43 | * @sig: NAMESPACE_INDEX\0 | |
44 | * @flags: placeholder | |
45 | * @seq: sequence number for this index | |
46 | * @myoff: offset of this index in label area | |
47 | * @mysize: size of this index struct | |
48 | * @otheroff: offset of other index | |
49 | * @labeloff: offset of first label slot | |
50 | * @nslot: total number of label slots | |
51 | * @major: label area major version | |
52 | * @minor: label area minor version | |
53 | * @checksum: fletcher64 of all fields | |
54 | * @free[0]: bitmap, nlabel bits | |
55 | * | |
56 | * The size of free[] is rounded up so the total struct size is a | |
57 | * multiple of NSINDEX_ALIGN bytes. Any bits this allocates beyond | |
58 | * nlabel bits must be zero. | |
59 | */ | |
60 | struct nd_namespace_index { | |
61 | u8 sig[NSINDEX_SIG_LEN]; | |
564e871a DW |
62 | u8 flags[3]; |
63 | u8 labelsize; | |
4a826c83 DW |
64 | __le32 seq; |
65 | __le64 myoff; | |
66 | __le64 mysize; | |
67 | __le64 otheroff; | |
68 | __le64 labeloff; | |
69 | __le32 nslot; | |
70 | __le16 major; | |
71 | __le16 minor; | |
72 | __le64 checksum; | |
73 | u8 free[0]; | |
74 | }; | |
75 | ||
76 | /** | |
77 | * struct nd_namespace_label - namespace superblock | |
78 | * @uuid: UUID per RFC 4122 | |
79 | * @name: optional name (NULL-terminated) | |
80 | * @flags: see NSLABEL_FLAG_* | |
81 | * @nlabel: num labels to describe this ns | |
82 | * @position: labels position in set | |
83 | * @isetcookie: interleave set cookie | |
84 | * @lbasize: LBA size in bytes or 0 for pmem | |
85 | * @dpa: DPA of NVM range on this DIMM | |
86 | * @rawsize: size of namespace | |
87 | * @slot: slot of this label in label area | |
88 | * @unused: must be zero | |
89 | */ | |
90 | struct nd_namespace_label { | |
91 | u8 uuid[NSLABEL_UUID_LEN]; | |
92 | u8 name[NSLABEL_NAME_LEN]; | |
93 | __le32 flags; | |
94 | __le16 nlabel; | |
95 | __le16 position; | |
96 | __le64 isetcookie; | |
97 | __le64 lbasize; | |
98 | __le64 dpa; | |
99 | __le64 rawsize; | |
100 | __le32 slot; | |
564e871a DW |
101 | /* |
102 | * Accessing fields past this point should be gated by a | |
103 | * namespace_label_has() check. | |
104 | */ | |
105 | u8 align; | |
106 | u8 reserved[3]; | |
107 | guid_t type_guid; | |
108 | guid_t abstraction_guid; | |
109 | u8 reserved2[88]; | |
110 | __le64 checksum; | |
4a826c83 DW |
111 | }; |
112 | ||
b3fde74e | 113 | #define NVDIMM_BTT_GUID "8aed63a2-29a2-4c66-8b12-f05d15d3922a" |
14e49454 | 114 | #define NVDIMM_BTT2_GUID "18633bfc-1735-4217-8ac9-17239282d3f8" |
b3fde74e DW |
115 | #define NVDIMM_PFN_GUID "266400ba-fb9f-4677-bcb0-968f11d0d225" |
116 | #define NVDIMM_DAX_GUID "97a86d9c-3cdd-4eda-986f-5068b4f80088" | |
117 | ||
4a826c83 DW |
118 | /** |
119 | * struct nd_label_id - identifier string for dpa allocation | |
120 | * @id: "{blk|pmem}-<namespace uuid>" | |
121 | */ | |
122 | struct nd_label_id { | |
123 | char id[ND_LABEL_ID_SIZE]; | |
124 | }; | |
125 | ||
126 | /* | |
127 | * If the 'best' index is invalid, so is the 'next' index. Otherwise, | |
128 | * the next index is MOD(index+1, 2) | |
129 | */ | |
130 | static inline int nd_label_next_nsindex(int index) | |
131 | { | |
132 | if (index < 0) | |
133 | return -1; | |
134 | ||
135 | return (index + 1) % 2; | |
136 | } | |
137 | ||
138 | struct nvdimm_drvdata; | |
139 | int nd_label_validate(struct nvdimm_drvdata *ndd); | |
140 | void nd_label_copy(struct nvdimm_drvdata *ndd, struct nd_namespace_index *dst, | |
141 | struct nd_namespace_index *src); | |
142 | size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd); | |
bf9bccc1 DW |
143 | int nd_label_active_count(struct nvdimm_drvdata *ndd); |
144 | struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n); | |
0ba1c634 DW |
145 | u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd); |
146 | bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot); | |
f524bf27 | 147 | u32 nd_label_nfree(struct nvdimm_drvdata *ndd); |
b3fde74e | 148 | enum nvdimm_claim_class to_nvdimm_cclass(guid_t *guid); |
f524bf27 DW |
149 | struct nd_region; |
150 | struct nd_namespace_pmem; | |
0ba1c634 | 151 | struct nd_namespace_blk; |
f524bf27 DW |
152 | int nd_pmem_namespace_label_update(struct nd_region *nd_region, |
153 | struct nd_namespace_pmem *nspm, resource_size_t size); | |
0ba1c634 DW |
154 | int nd_blk_namespace_label_update(struct nd_region *nd_region, |
155 | struct nd_namespace_blk *nsblk, resource_size_t size); | |
4a826c83 | 156 | #endif /* __LABEL_H__ */ |