Dan Williams | 4a826c8 | 2015-06-09 16:09:36 -0400 | [diff] [blame] | 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> |
| 18 | #include <linux/io.h> |
| 19 | |
| 20 | enum { |
| 21 | NSINDEX_SIG_LEN = 16, |
| 22 | NSINDEX_ALIGN = 256, |
| 23 | NSINDEX_SEQ_MASK = 0x3, |
| 24 | NSLABEL_UUID_LEN = 16, |
| 25 | NSLABEL_NAME_LEN = 64, |
| 26 | NSLABEL_FLAG_ROLABEL = 0x1, /* read-only label */ |
| 27 | NSLABEL_FLAG_LOCAL = 0x2, /* DIMM-local namespace */ |
| 28 | NSLABEL_FLAG_BTT = 0x4, /* namespace contains a BTT */ |
| 29 | NSLABEL_FLAG_UPDATING = 0x8, /* label being updated */ |
| 30 | BTT_ALIGN = 4096, /* all btt structures */ |
| 31 | BTTINFO_SIG_LEN = 16, |
| 32 | BTTINFO_UUID_LEN = 16, |
| 33 | BTTINFO_FLAG_ERROR = 0x1, /* error state (read-only) */ |
| 34 | BTTINFO_MAJOR_VERSION = 1, |
| 35 | ND_LABEL_MIN_SIZE = 512 * 129, /* see sizeof_namespace_index() */ |
| 36 | ND_LABEL_ID_SIZE = 50, |
| 37 | }; |
| 38 | |
| 39 | static const char NSINDEX_SIGNATURE[] = "NAMESPACE_INDEX\0"; |
| 40 | |
| 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]; |
| 62 | __le32 flags; |
| 63 | __le32 seq; |
| 64 | __le64 myoff; |
| 65 | __le64 mysize; |
| 66 | __le64 otheroff; |
| 67 | __le64 labeloff; |
| 68 | __le32 nslot; |
| 69 | __le16 major; |
| 70 | __le16 minor; |
| 71 | __le64 checksum; |
| 72 | u8 free[0]; |
| 73 | }; |
| 74 | |
| 75 | /** |
| 76 | * struct nd_namespace_label - namespace superblock |
| 77 | * @uuid: UUID per RFC 4122 |
| 78 | * @name: optional name (NULL-terminated) |
| 79 | * @flags: see NSLABEL_FLAG_* |
| 80 | * @nlabel: num labels to describe this ns |
| 81 | * @position: labels position in set |
| 82 | * @isetcookie: interleave set cookie |
| 83 | * @lbasize: LBA size in bytes or 0 for pmem |
| 84 | * @dpa: DPA of NVM range on this DIMM |
| 85 | * @rawsize: size of namespace |
| 86 | * @slot: slot of this label in label area |
| 87 | * @unused: must be zero |
| 88 | */ |
| 89 | struct nd_namespace_label { |
| 90 | u8 uuid[NSLABEL_UUID_LEN]; |
| 91 | u8 name[NSLABEL_NAME_LEN]; |
| 92 | __le32 flags; |
| 93 | __le16 nlabel; |
| 94 | __le16 position; |
| 95 | __le64 isetcookie; |
| 96 | __le64 lbasize; |
| 97 | __le64 dpa; |
| 98 | __le64 rawsize; |
| 99 | __le32 slot; |
| 100 | __le32 unused; |
| 101 | }; |
| 102 | |
| 103 | /** |
| 104 | * struct nd_label_id - identifier string for dpa allocation |
| 105 | * @id: "{blk|pmem}-<namespace uuid>" |
| 106 | */ |
| 107 | struct nd_label_id { |
| 108 | char id[ND_LABEL_ID_SIZE]; |
| 109 | }; |
| 110 | |
| 111 | /* |
| 112 | * If the 'best' index is invalid, so is the 'next' index. Otherwise, |
| 113 | * the next index is MOD(index+1, 2) |
| 114 | */ |
| 115 | static inline int nd_label_next_nsindex(int index) |
| 116 | { |
| 117 | if (index < 0) |
| 118 | return -1; |
| 119 | |
| 120 | return (index + 1) % 2; |
| 121 | } |
| 122 | |
| 123 | struct nvdimm_drvdata; |
| 124 | int nd_label_validate(struct nvdimm_drvdata *ndd); |
| 125 | void nd_label_copy(struct nvdimm_drvdata *ndd, struct nd_namespace_index *dst, |
| 126 | struct nd_namespace_index *src); |
| 127 | size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd); |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame^] | 128 | int nd_label_active_count(struct nvdimm_drvdata *ndd); |
| 129 | struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n); |
Dan Williams | 4a826c8 | 2015-06-09 16:09:36 -0400 | [diff] [blame] | 130 | #endif /* __LABEL_H__ */ |