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