blob: a59ef6eef2a376b871b3c70e33f890c973dc7744 [file] [log] [blame]
Dan Williams4a826c82015-06-09 16:09:36 -04001/*
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
20enum {
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,
Dan Williamsf524bf22015-05-30 12:36:02 -040037 ND_NSINDEX_INIT = 0x1,
Dan Williams4a826c82015-06-09 16:09:36 -040038};
39
40static const char NSINDEX_SIGNATURE[] = "NAMESPACE_INDEX\0";
41
42/**
43 * struct nd_namespace_index - label set superblock
44 * @sig: NAMESPACE_INDEX\0
45 * @flags: placeholder
46 * @seq: sequence number for this index
47 * @myoff: offset of this index in label area
48 * @mysize: size of this index struct
49 * @otheroff: offset of other index
50 * @labeloff: offset of first label slot
51 * @nslot: total number of label slots
52 * @major: label area major version
53 * @minor: label area minor version
54 * @checksum: fletcher64 of all fields
55 * @free[0]: bitmap, nlabel bits
56 *
57 * The size of free[] is rounded up so the total struct size is a
58 * multiple of NSINDEX_ALIGN bytes. Any bits this allocates beyond
59 * nlabel bits must be zero.
60 */
61struct nd_namespace_index {
62 u8 sig[NSINDEX_SIG_LEN];
63 __le32 flags;
64 __le32 seq;
65 __le64 myoff;
66 __le64 mysize;
67 __le64 otheroff;
68 __le64 labeloff;
69 __le32 nslot;
70 __le16 major;
71 __le16 minor;
72 __le64 checksum;
73 u8 free[0];
74};
75
76/**
77 * struct nd_namespace_label - namespace superblock
78 * @uuid: UUID per RFC 4122
79 * @name: optional name (NULL-terminated)
80 * @flags: see NSLABEL_FLAG_*
81 * @nlabel: num labels to describe this ns
82 * @position: labels position in set
83 * @isetcookie: interleave set cookie
84 * @lbasize: LBA size in bytes or 0 for pmem
85 * @dpa: DPA of NVM range on this DIMM
86 * @rawsize: size of namespace
87 * @slot: slot of this label in label area
88 * @unused: must be zero
89 */
90struct nd_namespace_label {
91 u8 uuid[NSLABEL_UUID_LEN];
92 u8 name[NSLABEL_NAME_LEN];
93 __le32 flags;
94 __le16 nlabel;
95 __le16 position;
96 __le64 isetcookie;
97 __le64 lbasize;
98 __le64 dpa;
99 __le64 rawsize;
100 __le32 slot;
101 __le32 unused;
102};
103
104/**
105 * struct nd_label_id - identifier string for dpa allocation
106 * @id: "{blk|pmem}-<namespace uuid>"
107 */
108struct nd_label_id {
109 char id[ND_LABEL_ID_SIZE];
110};
111
112/*
113 * If the 'best' index is invalid, so is the 'next' index. Otherwise,
114 * the next index is MOD(index+1, 2)
115 */
116static inline int nd_label_next_nsindex(int index)
117{
118 if (index < 0)
119 return -1;
120
121 return (index + 1) % 2;
122}
123
124struct nvdimm_drvdata;
125int nd_label_validate(struct nvdimm_drvdata *ndd);
126void nd_label_copy(struct nvdimm_drvdata *ndd, struct nd_namespace_index *dst,
127 struct nd_namespace_index *src);
128size_t sizeof_namespace_index(struct nvdimm_drvdata *ndd);
Dan Williamsbf9bccc2015-06-17 17:14:46 -0400129int nd_label_active_count(struct nvdimm_drvdata *ndd);
130struct nd_namespace_label *nd_label_active(struct nvdimm_drvdata *ndd, int n);
Dan Williams0ba1c632015-05-30 12:35:36 -0400131u32 nd_label_alloc_slot(struct nvdimm_drvdata *ndd);
132bool nd_label_free_slot(struct nvdimm_drvdata *ndd, u32 slot);
Dan Williamsf524bf22015-05-30 12:36:02 -0400133u32 nd_label_nfree(struct nvdimm_drvdata *ndd);
134struct nd_region;
135struct nd_namespace_pmem;
Dan Williams0ba1c632015-05-30 12:35:36 -0400136struct nd_namespace_blk;
Dan Williamsf524bf22015-05-30 12:36:02 -0400137int nd_pmem_namespace_label_update(struct nd_region *nd_region,
138 struct nd_namespace_pmem *nspm, resource_size_t size);
Dan Williams0ba1c632015-05-30 12:35:36 -0400139int nd_blk_namespace_label_update(struct nd_region *nd_region,
140 struct nd_namespace_blk *nsblk, resource_size_t size);
Dan Williams4a826c82015-06-09 16:09:36 -0400141#endif /* __LABEL_H__ */