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