1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef __LABEL_H__
14#define __LABEL_H__
15
16#include <linux/ndctl.h>
17#include <linux/sizes.h>
18#include <linux/uuid.h>
19#include <linux/io.h>
20
21enum {
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,
28 NSLABEL_FLAG_LOCAL = 0x2,
29 NSLABEL_FLAG_BTT = 0x4,
30 NSLABEL_FLAG_UPDATING = 0x8,
31 BTT_ALIGN = 4096,
32 BTTINFO_SIG_LEN = 16,
33 BTTINFO_UUID_LEN = 16,
34 BTTINFO_FLAG_ERROR = 0x1,
35 BTTINFO_MAJOR_VERSION = 1,
36 ND_LABEL_MIN_SIZE = 256 * 4,
37 ND_LABEL_ID_SIZE = 50,
38 ND_NSINDEX_INIT = 0x1,
39};
40
41static const char NSINDEX_SIGNATURE[] = "NAMESPACE_INDEX\0";
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62struct nd_namespace_index {
63 u8 sig[NSINDEX_SIG_LEN];
64 u8 flags[3];
65 u8 labelsize;
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
80
81
82
83
84
85
86
87
88
89
90
91
92struct 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;
103
104
105
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;
113};
114
115#define NVDIMM_BTT_GUID "8aed63a2-29a2-4c66-8b12-f05d15d3922a"
116#define NVDIMM_BTT2_GUID "18633bfc-1735-4217-8ac9-17239282d3f8"
117#define NVDIMM_PFN_GUID "266400ba-fb9f-4677-bcb0-968f11d0d225"
118#define NVDIMM_DAX_GUID "97a86d9c-3cdd-4eda-986f-5068b4f80088"
119
120
121
122
123
124struct nd_label_id {
125 char id[ND_LABEL_ID_SIZE];
126};
127
128
129
130
131
132static inline int nd_label_next_nsindex(int index)
133{
134 if (index < 0)
135 return -1;
136
137 return (index + 1) % 2;
138}
139
140struct nvdimm_drvdata;
141int nd_label_validate(struct nvdimm_drvdata *ndd);
142void nd_label_copy(struct nvdimm_drvdata *ndd, struct nd_namespace_index *dst,
143 struct nd_namespace_index *src);
144size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd);
145int nd_label_active_count(struct nvdimm_drvdata *ndd);
146struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n);
147u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd);
148bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot);
149u32 nd_label_nfree(struct nvdimm_drvdata *ndd);
150enum nvdimm_claim_class to_nvdimm_cclass(guid_t *guid);
151struct nd_region;
152struct nd_namespace_pmem;
153struct nd_namespace_blk;
154int nd_pmem_namespace_label_update(struct nd_region *nd_region,
155 struct nd_namespace_pmem *nspm, resource_size_t size);
156int nd_blk_namespace_label_update(struct nd_region *nd_region,
157 struct nd_namespace_blk *nsblk, resource_size_t size);
158#endif
159