0001
0002
0003
0004
0005 #ifndef __LABEL_H__
0006 #define __LABEL_H__
0007
0008 #include <linux/ndctl.h>
0009 #include <linux/sizes.h>
0010 #include <linux/uuid.h>
0011 #include <linux/io.h>
0012
0013 enum {
0014 NSINDEX_SIG_LEN = 16,
0015 NSINDEX_ALIGN = 256,
0016 NSINDEX_SEQ_MASK = 0x3,
0017 NSLABEL_UUID_LEN = 16,
0018 NSLABEL_NAME_LEN = 64,
0019 NSLABEL_FLAG_ROLABEL = 0x1,
0020 NSLABEL_FLAG_LOCAL = 0x2,
0021 NSLABEL_FLAG_BTT = 0x4,
0022 NSLABEL_FLAG_UPDATING = 0x8,
0023 BTT_ALIGN = 4096,
0024 BTTINFO_SIG_LEN = 16,
0025 BTTINFO_UUID_LEN = 16,
0026 BTTINFO_FLAG_ERROR = 0x1,
0027 BTTINFO_MAJOR_VERSION = 1,
0028 ND_LABEL_MIN_SIZE = 256 * 4,
0029 ND_LABEL_ID_SIZE = 50,
0030 ND_NSINDEX_INIT = 0x1,
0031 };
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 struct nd_namespace_index {
0054 u8 sig[NSINDEX_SIG_LEN];
0055 u8 flags[3];
0056 u8 labelsize;
0057 __le32 seq;
0058 __le64 myoff;
0059 __le64 mysize;
0060 __le64 otheroff;
0061 __le64 labeloff;
0062 __le32 nslot;
0063 __le16 major;
0064 __le16 minor;
0065 __le64 checksum;
0066 u8 free[];
0067 };
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085 struct cxl_region_label {
0086 u8 type[NSLABEL_UUID_LEN];
0087 u8 uuid[NSLABEL_UUID_LEN];
0088 __le32 flags;
0089 __le16 nlabel;
0090 __le16 position;
0091 __le64 dpa;
0092 __le64 rawsize;
0093 __le64 hpa;
0094 __le32 slot;
0095 __le32 ig;
0096 __le32 align;
0097 u8 reserved[0xac];
0098 __le64 checksum;
0099 };
0100
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 struct nvdimm_efi_label {
0121 u8 uuid[NSLABEL_UUID_LEN];
0122 u8 name[NSLABEL_NAME_LEN];
0123 __le32 flags;
0124 __le16 nlabel;
0125 __le16 position;
0126 __le64 isetcookie;
0127 __le64 lbasize;
0128 __le64 dpa;
0129 __le64 rawsize;
0130 __le32 slot;
0131
0132
0133
0134
0135 u8 align;
0136 u8 reserved[3];
0137 guid_t type_guid;
0138 guid_t abstraction_guid;
0139 u8 reserved2[88];
0140 __le64 checksum;
0141 };
0142
0143
0144
0145
0146
0147
0148
0149
0150
0151
0152
0153
0154
0155
0156
0157
0158
0159
0160
0161 struct nvdimm_cxl_label {
0162 u8 type[NSLABEL_UUID_LEN];
0163 u8 uuid[NSLABEL_UUID_LEN];
0164 u8 name[NSLABEL_NAME_LEN];
0165 __le32 flags;
0166 __le16 nrange;
0167 __le16 position;
0168 __le64 dpa;
0169 __le64 rawsize;
0170 __le32 slot;
0171 __le32 align;
0172 u8 region_uuid[16];
0173 u8 abstraction_uuid[16];
0174 __le16 lbasize;
0175 u8 reserved[0x56];
0176 __le64 checksum;
0177 };
0178
0179 struct nd_namespace_label {
0180 union {
0181 struct nvdimm_cxl_label cxl;
0182 struct nvdimm_efi_label efi;
0183 };
0184 };
0185
0186 #define NVDIMM_BTT_GUID "8aed63a2-29a2-4c66-8b12-f05d15d3922a"
0187 #define NVDIMM_BTT2_GUID "18633bfc-1735-4217-8ac9-17239282d3f8"
0188 #define NVDIMM_PFN_GUID "266400ba-fb9f-4677-bcb0-968f11d0d225"
0189 #define NVDIMM_DAX_GUID "97a86d9c-3cdd-4eda-986f-5068b4f80088"
0190
0191 #define CXL_REGION_UUID "529d7c61-da07-47c4-a93f-ecdf2c06f444"
0192 #define CXL_NAMESPACE_UUID "68bb2c0a-5a77-4937-9f85-3caf41a0f93c"
0193
0194
0195
0196
0197
0198 struct nd_label_id {
0199 char id[ND_LABEL_ID_SIZE];
0200 };
0201
0202
0203
0204
0205
0206 static inline int nd_label_next_nsindex(int index)
0207 {
0208 if (index < 0)
0209 return -1;
0210
0211 return (index + 1) % 2;
0212 }
0213
0214 struct nvdimm_drvdata;
0215 int nd_label_data_init(struct nvdimm_drvdata *ndd);
0216 size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd);
0217 int nd_label_active_count(struct nvdimm_drvdata *ndd);
0218 struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n);
0219 u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd);
0220 bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot);
0221 u32 nd_label_nfree(struct nvdimm_drvdata *ndd);
0222 struct nd_region;
0223 struct nd_namespace_pmem;
0224 int nd_pmem_namespace_label_update(struct nd_region *nd_region,
0225 struct nd_namespace_pmem *nspm, resource_size_t size);
0226 #endif