Blame view

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