Blame view
drivers/nvdimm/nd.h
11.1 KB
5b497af42
|
1 |
/* SPDX-License-Identifier: GPL-2.0-only */ |
4d88a97aa
|
2 3 |
/* * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. |
4d88a97aa
|
4 5 6 |
*/ #ifndef __ND_H__ #define __ND_H__ |
1f7df6f88
|
7 |
#include <linux/libnvdimm.h> |
200c79da8
|
8 |
#include <linux/badblocks.h> |
f0dc089ce
|
9 |
#include <linux/blkdev.h> |
4d88a97aa
|
10 11 12 |
#include <linux/device.h> #include <linux/mutex.h> #include <linux/ndctl.h> |
bf9bccc14
|
13 |
#include <linux/types.h> |
719994660
|
14 |
#include <linux/nd.h> |
4a826c83d
|
15 |
#include "label.h" |
4d88a97aa
|
16 |
|
8c2f7e865
|
17 |
enum { |
5212e11fd
|
18 19 20 21 22 23 |
/* * Limits the maximum number of block apertures a dimm can * support and is an input to the geometry/on-disk-format of a * BTT instance */ ND_MAX_LANES = 256, |
fcae69573
|
24 |
INT_LBASIZE_ALIGNMENT = 64, |
3ae3d67ba
|
25 |
NVDIMM_IO_ATOMIC = 1, |
8c2f7e865
|
26 |
}; |
4d88a97aa
|
27 28 |
struct nvdimm_drvdata { struct device *dev; |
028817686
|
29 |
int nslabel_size; |
4d88a97aa
|
30 31 |
struct nd_cmd_get_config_size nsarea; void *data; |
4a826c83d
|
32 33 |
int ns_current, ns_next; struct resource dpa; |
bf9bccc14
|
34 |
struct kref kref; |
4d88a97aa
|
35 |
}; |
e5ae3b252
|
36 37 38 |
struct nd_region_data { int ns_count; int ns_active; |
595c73071
|
39 |
unsigned int hints_shift; |
9106137c6
|
40 |
void __iomem *flush_wpq[]; |
3d88002e4
|
41 |
}; |
595c73071
|
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
static inline void __iomem *ndrd_get_flush_wpq(struct nd_region_data *ndrd, int dimm, int hint) { unsigned int num = 1 << ndrd->hints_shift; unsigned int mask = num - 1; return ndrd->flush_wpq[dimm * num + (hint & mask)]; } static inline void ndrd_set_flush_wpq(struct nd_region_data *ndrd, int dimm, int hint, void __iomem *flush) { unsigned int num = 1 << ndrd->hints_shift; unsigned int mask = num - 1; ndrd->flush_wpq[dimm * num + (hint & mask)] = flush; } |
4a826c83d
|
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
static inline struct nd_namespace_index *to_namespace_index( struct nvdimm_drvdata *ndd, int i) { if (i < 0) return NULL; return ndd->data + sizeof_namespace_index(ndd) * i; } static inline struct nd_namespace_index *to_current_namespace_index( struct nvdimm_drvdata *ndd) { return to_namespace_index(ndd, ndd->ns_current); } static inline struct nd_namespace_index *to_next_namespace_index( struct nvdimm_drvdata *ndd) { return to_namespace_index(ndd, ndd->ns_next); } |
564e871aa
|
79 80 81 82 83 |
unsigned sizeof_namespace_label(struct nvdimm_drvdata *ndd); #define namespace_label_has(ndd, field) \ (offsetof(struct nd_namespace_label, field) \ < sizeof_namespace_label(ndd)) |
4a826c83d
|
84 85 86 87 88 |
#define nd_dbg_dpa(r, d, res, fmt, arg...) \ dev_dbg((r) ? &(r)->dev : (d)->dev, "%s: %.13s: %#llx @ %#llx " fmt, \ (r) ? dev_name((d)->dev) : "", res ? res->name : "null", \ (unsigned long long) (res ? resource_size(res) : 0), \ (unsigned long long) (res ? res->start : 0), ##arg) |
bf9bccc14
|
89 90 |
#define for_each_dpa_resource(ndd, res) \ for (res = (ndd)->dpa.child; res; res = res->sibling) |
4a826c83d
|
91 92 93 |
#define for_each_dpa_resource_safe(ndd, res, next) \ for (res = (ndd)->dpa.child, next = res ? res->sibling : NULL; \ res; res = next, next = next ? next->sibling : NULL) |
5212e11fd
|
94 95 96 97 |
struct nd_percpu_lane { int count; spinlock_t lock; }; |
c4703ce11
|
98 99 100 |
enum nd_label_flags { ND_LABEL_REAP, }; |
ae8219f18
|
101 102 |
struct nd_label_ent { struct list_head list; |
c4703ce11
|
103 |
unsigned long flags; |
ae8219f18
|
104 105 106 107 108 109 110 |
struct nd_namespace_label *label; }; enum nd_mapping_lock_class { ND_MAPPING_CLASS0, ND_MAPPING_UUID_SCAN, }; |
44c462eb9
|
111 112 |
struct nd_mapping { struct nvdimm *nvdimm; |
44c462eb9
|
113 114 |
u64 start; u64 size; |
401c0a19c
|
115 |
int position; |
ae8219f18
|
116 117 |
struct list_head labels; struct mutex lock; |
44c462eb9
|
118 119 120 121 122 123 124 125 |
/* * @ndd is for private use at region enable / disable time for * get_ndd() + put_ndd(), all other nd_mapping to ndd * conversions use to_ndd() which respects enabled state of the * nvdimm. */ struct nvdimm_drvdata *ndd; }; |
1f7df6f88
|
126 127 |
struct nd_region { struct device dev; |
1b40e09a1
|
128 |
struct ida ns_ida; |
8c2f7e865
|
129 |
struct ida btt_ida; |
e1455744b
|
130 |
struct ida pfn_ida; |
cd03412a5
|
131 |
struct ida dax_ida; |
004f1afbe
|
132 |
unsigned long flags; |
bf9bccc14
|
133 |
struct device *ns_seed; |
8c2f7e865
|
134 |
struct device *btt_seed; |
e1455744b
|
135 |
struct device *pfn_seed; |
cd03412a5
|
136 |
struct device *dax_seed; |
2522afb86
|
137 |
unsigned long align; |
1f7df6f88
|
138 139 140 |
u16 ndr_mappings; u64 ndr_size; u64 ndr_start; |
8fc5c7355
|
141 |
int id, num_lanes, ro, numa_node, target_node; |
1f7df6f88
|
142 |
void *provider_data; |
975750a98
|
143 |
struct kernfs_node *bb_state; |
6a6bef904
|
144 |
struct badblocks bb; |
eaf961536
|
145 |
struct nd_interleave_set *nd_set; |
5212e11fd
|
146 |
struct nd_percpu_lane __percpu *lane; |
c5d4355d1
|
147 |
int (*flush)(struct nd_region *nd_region, struct bio *bio); |
9106137c6
|
148 |
struct nd_mapping mapping[]; |
1f7df6f88
|
149 |
}; |
047fc8a1f
|
150 151 |
struct nd_blk_region { int (*enable)(struct nvdimm_bus *nvdimm_bus, struct device *dev); |
047fc8a1f
|
152 153 154 155 156 |
int (*do_io)(struct nd_blk_region *ndbr, resource_size_t dpa, void *iobuf, u64 len, int rw); void *blk_provider_data; struct nd_region nd_region; }; |
4a826c83d
|
157 158 159 160 161 162 163 164 165 |
/* * Lookup next in the repeating sequence of 01, 10, and 11. */ static inline unsigned nd_inc_seq(unsigned seq) { static const unsigned next[] = { 0, 2, 3, 1 }; return next[seq & 3]; } |
f524bf271
|
166 |
|
5212e11fd
|
167 |
struct btt; |
8c2f7e865
|
168 169 170 |
struct nd_btt { struct device dev; struct nd_namespace_common *ndns; |
5212e11fd
|
171 |
struct btt *btt; |
8c2f7e865
|
172 |
unsigned long lbasize; |
abe8b4e3c
|
173 |
u64 size; |
8c2f7e865
|
174 175 |
u8 *uuid; int id; |
14e494542
|
176 177 178 |
int initial_offset; u16 version_major; u16 version_minor; |
8c2f7e865
|
179 |
}; |
e1455744b
|
180 181 182 183 184 185 186 187 188 189 |
enum nd_pfn_mode { PFN_MODE_NONE, PFN_MODE_RAM, PFN_MODE_PMEM, }; struct nd_pfn { int id; u8 *uuid; struct device dev; |
315c56253
|
190 |
unsigned long align; |
e1455744b
|
191 192 193 194 195 |
unsigned long npfns; enum nd_pfn_mode mode; struct nd_pfn_sb *pfn_sb; struct nd_namespace_common *ndns; }; |
cd03412a5
|
196 197 198 |
struct nd_dax { struct nd_pfn nd_pfn; }; |
8f4b01fcd
|
199 200 201 202 |
static inline u32 nd_info_block_reserve(void) { return ALIGN(SZ_8K, PAGE_SIZE); } |
4d88a97aa
|
203 204 205 206 |
enum nd_async_mode { ND_SYNC, ND_ASYNC, }; |
41cd8b70c
|
207 |
int nd_integrity_init(struct gendisk *disk, unsigned long meta_size); |
bf9bccc14
|
208 |
void wait_nvdimm_bus_probe_idle(struct device *dev); |
4d88a97aa
|
209 210 |
void nd_device_register(struct device *dev); void nd_device_unregister(struct device *dev, enum nd_async_mode mode); |
719994660
|
211 |
void nd_device_notify(struct device *dev, enum nvdimm_event event); |
bf9bccc14
|
212 213 |
int nd_uuid_store(struct device *dev, u8 **uuid_out, const char *buf, size_t len); |
b2c48f9f9
|
214 |
ssize_t nd_size_select_show(unsigned long current_size, |
1b40e09a1
|
215 |
const unsigned long *supported, char *buf); |
b2c48f9f9
|
216 217 |
ssize_t nd_size_select_store(struct device *dev, const char *buf, unsigned long *current_size, const unsigned long *supported); |
4d88a97aa
|
218 |
int __init nvdimm_init(void); |
3d88002e4
|
219 |
int __init nd_region_init(void); |
b3fde74ea
|
220 |
int __init nd_label_init(void); |
4d88a97aa
|
221 |
void nvdimm_exit(void); |
3d88002e4
|
222 |
void nd_region_exit(void); |
bf9bccc14
|
223 |
struct nvdimm; |
adbb68293
|
224 |
extern const struct attribute_group nd_device_attribute_group; |
e2f6a0e34
|
225 |
extern const struct attribute_group nd_numa_attribute_group; |
e755799ae
|
226 |
extern const struct attribute_group *nvdimm_bus_attribute_groups[]; |
bf9bccc14
|
227 |
struct nvdimm_drvdata *to_ndd(struct nd_mapping *nd_mapping); |
aee659874
|
228 |
int nvdimm_check_config_data(struct device *dev); |
4d88a97aa
|
229 230 |
int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd); int nvdimm_init_config_data(struct nvdimm_drvdata *ndd); |
2d657d17f
|
231 232 |
int nvdimm_get_config_data(struct nvdimm_drvdata *ndd, void *buf, size_t offset, size_t len); |
f524bf271
|
233 234 |
int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset, void *buf, size_t len); |
59e647398
|
235 236 |
long nvdimm_clear_poison(struct device *dev, phys_addr_t phys, unsigned int len); |
a0e374525
|
237 |
void nvdimm_set_labeling(struct device *dev); |
8f078b38d
|
238 |
void nvdimm_set_locked(struct device *dev); |
d34cb8084
|
239 |
void nvdimm_clear_locked(struct device *dev); |
1cd738654
|
240 |
int nvdimm_security_setup_events(struct device *dev); |
4c6926a23
|
241 242 243 244 245 246 247 248 |
#if IS_ENABLED(CONFIG_NVDIMM_KEYS) int nvdimm_security_unlock(struct device *dev); #else static inline int nvdimm_security_unlock(struct device *dev) { return 0; } #endif |
8c2f7e865
|
249 |
struct nd_btt *to_nd_btt(struct device *dev); |
e1455744b
|
250 251 252 253 254 255 256 |
struct nd_gen_sb { char reserved[SZ_4K - 8]; __le64 checksum; }; u64 nd_sb_checksum(struct nd_gen_sb *sb); |
8c2f7e865
|
257 |
#if IS_ENABLED(CONFIG_BTT) |
200c79da8
|
258 |
int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns); |
8c2f7e865
|
259 260 261 |
bool is_nd_btt(struct device *dev); struct device *nd_btt_create(struct nd_region *nd_region); #else |
e32bc729a
|
262 |
static inline int nd_btt_probe(struct device *dev, |
200c79da8
|
263 |
struct nd_namespace_common *ndns) |
8c2f7e865
|
264 265 266 267 268 269 270 271 272 273 274 275 276 |
{ return -ENODEV; } static inline bool is_nd_btt(struct device *dev) { return false; } static inline struct device *nd_btt_create(struct nd_region *nd_region) { return NULL; } |
e1455744b
|
277 |
#endif |
8c2f7e865
|
278 |
|
e1455744b
|
279 280 |
struct nd_pfn *to_nd_pfn(struct device *dev); #if IS_ENABLED(CONFIG_NVDIMM_PFN) |
0dd696430
|
281 |
|
f53766997
|
282 |
#define MAX_NVDIMM_ALIGN 4 |
0dd696430
|
283 |
|
200c79da8
|
284 |
int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns); |
e1455744b
|
285 286 |
bool is_nd_pfn(struct device *dev); struct device *nd_pfn_create(struct nd_region *nd_region); |
cd03412a5
|
287 288 |
struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn, struct nd_namespace_common *ndns); |
c5ed92686
|
289 |
int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig); |
78c81cc89
|
290 |
extern const struct attribute_group *nd_pfn_attribute_groups[]; |
e1455744b
|
291 |
#else |
200c79da8
|
292 293 |
static inline int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns) |
e1455744b
|
294 295 296 297 298 299 300 301 302 303 304 305 306 |
{ return -ENODEV; } static inline bool is_nd_pfn(struct device *dev) { return false; } static inline struct device *nd_pfn_create(struct nd_region *nd_region) { return NULL; } |
32ab0a3f5
|
307 |
|
c5ed92686
|
308 |
static inline int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig) |
32ab0a3f5
|
309 310 311 |
{ return -ENODEV; } |
8c2f7e865
|
312 |
#endif |
e1455744b
|
313 |
|
cd03412a5
|
314 315 |
struct nd_dax *to_nd_dax(struct device *dev); #if IS_ENABLED(CONFIG_NVDIMM_DAX) |
c5ed92686
|
316 |
int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns); |
cd03412a5
|
317 318 319 |
bool is_nd_dax(struct device *dev); struct device *nd_dax_create(struct nd_region *nd_region); #else |
c5ed92686
|
320 321 322 323 324 |
static inline int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns) { return -ENODEV; } |
cd03412a5
|
325 326 327 328 329 330 331 332 333 334 |
static inline bool is_nd_dax(struct device *dev) { return false; } static inline struct device *nd_dax_create(struct nd_region *nd_region) { return NULL; } #endif |
3d88002e4
|
335 336 |
int nd_region_to_nstype(struct nd_region *nd_region); int nd_region_register_namespaces(struct nd_region *nd_region, int *err); |
c12c48ce8
|
337 338 |
u64 nd_region_interleave_set_cookie(struct nd_region *nd_region, struct nd_namespace_index *nsindex); |
86ef58a4e
|
339 |
u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region); |
3d88002e4
|
340 341 342 |
void nvdimm_bus_lock(struct device *dev); void nvdimm_bus_unlock(struct device *dev); bool is_nvdimm_bus_locked(struct device *dev); |
32f61d675
|
343 |
void nvdimm_check_and_set_ro(struct gendisk *disk); |
bf9bccc14
|
344 345 |
void nvdimm_drvdata_release(struct kref *kref); void put_ndd(struct nvdimm_drvdata *ndd); |
4a826c83d
|
346 347 348 349 350 |
int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd); void nvdimm_free_dpa(struct nvdimm_drvdata *ndd, struct resource *res); struct resource *nvdimm_allocate_dpa(struct nvdimm_drvdata *ndd, struct nd_label_id *label_id, resource_size_t start, resource_size_t n); |
8c2f7e865
|
351 |
resource_size_t nvdimm_namespace_capacity(struct nd_namespace_common *ndns); |
08e6b3c6e
|
352 |
bool nvdimm_namespace_locked(struct nd_namespace_common *ndns); |
8c2f7e865
|
353 |
struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev); |
5212e11fd
|
354 |
int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns); |
298f2bc5d
|
355 |
int nvdimm_namespace_detach_btt(struct nd_btt *nd_btt); |
5212e11fd
|
356 357 |
const char *nvdimm_namespace_disk_name(struct nd_namespace_common *ndns, char *name); |
f979b13c3
|
358 |
unsigned int pmem_sector_size(struct nd_namespace_common *ndns); |
a4574f63e
|
359 |
struct range; |
a39018029
|
360 |
void nvdimm_badblocks_populate(struct nd_region *nd_region, |
a4574f63e
|
361 |
struct badblocks *bb, const struct range *range); |
8f4b01fcd
|
362 363 364 365 |
int devm_namespace_enable(struct device *dev, struct nd_namespace_common *ndns, resource_size_t size); void devm_namespace_disable(struct device *dev, struct nd_namespace_common *ndns); |
200c79da8
|
366 |
#if IS_ENABLED(CONFIG_ND_CLAIM) |
e96f0bf2e
|
367 368 |
/* max struct page size independent of kernel config */ #define MAX_STRUCT_PAGE_SIZE 64 |
e8d513483
|
369 |
int nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap); |
200c79da8
|
370 |
#else |
e8d513483
|
371 372 |
static inline int nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap) |
ac515c084
|
373 |
{ |
e8d513483
|
374 |
return -ENXIO; |
ac515c084
|
375 |
} |
200c79da8
|
376 |
#endif |
047fc8a1f
|
377 |
int nd_blk_region_init(struct nd_region *nd_region); |
e5ae3b252
|
378 |
int nd_region_activate(struct nd_region *nd_region); |
200c79da8
|
379 380 381 382 383 384 385 386 387 388 389 390 391 |
static inline bool is_bad_pmem(struct badblocks *bb, sector_t sector, unsigned int len) { if (bb->count) { sector_t first_bad; int num_bad; return !!badblocks_check(bb, sector, len / 512, &first_bad, &num_bad); } return false; } |
047fc8a1f
|
392 |
resource_size_t nd_namespace_blk_validate(struct nd_namespace_blk *nsblk); |
6ec689542
|
393 |
const u8 *nd_dev_to_uuid(struct device *dev); |
004f1afbe
|
394 |
bool pmem_should_map_pages(struct device *dev); |
4d88a97aa
|
395 |
#endif /* __ND_H__ */ |