hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/drivers/nvdimm/nd-core.h
....@@ -1,27 +1,20 @@
1
+/* SPDX-License-Identifier: GPL-2.0-only */
12 /*
23 * 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.
124 */
135 #ifndef __ND_CORE_H__
146 #define __ND_CORE_H__
157 #include <linux/libnvdimm.h>
168 #include <linux/device.h>
17
-#include <linux/libnvdimm.h>
189 #include <linux/sizes.h>
1910 #include <linux/mutex.h>
2011 #include <linux/nd.h>
12
+#include "nd.h"
2113
2214 extern struct list_head nvdimm_bus_list;
2315 extern struct mutex nvdimm_bus_list_mutex;
2416 extern int nvdimm_major;
17
+extern struct workqueue_struct *nvdimm_wq;
2518
2619 struct nvdimm_bus {
2720 struct nvdimm_bus_descriptor *nd_desc;
....@@ -43,7 +36,51 @@
4336 atomic_t busy;
4437 int id, num_flush;
4538 struct resource *flush_wpq;
39
+ const char *dimm_id;
40
+ struct {
41
+ const struct nvdimm_security_ops *ops;
42
+ unsigned long flags;
43
+ unsigned long ext_flags;
44
+ unsigned int overwrite_tmo;
45
+ struct kernfs_node *overwrite_state;
46
+ } sec;
47
+ struct delayed_work dwork;
48
+ const struct nvdimm_fw_ops *fw_ops;
4649 };
50
+
51
+static inline unsigned long nvdimm_security_flags(
52
+ struct nvdimm *nvdimm, enum nvdimm_passphrase_type ptype)
53
+{
54
+ u64 flags;
55
+ const u64 state_flags = 1UL << NVDIMM_SECURITY_DISABLED
56
+ | 1UL << NVDIMM_SECURITY_LOCKED
57
+ | 1UL << NVDIMM_SECURITY_UNLOCKED
58
+ | 1UL << NVDIMM_SECURITY_OVERWRITE;
59
+
60
+ if (!nvdimm->sec.ops)
61
+ return 0;
62
+
63
+ flags = nvdimm->sec.ops->get_flags(nvdimm, ptype);
64
+ /* disabled, locked, unlocked, and overwrite are mutually exclusive */
65
+ dev_WARN_ONCE(&nvdimm->dev, hweight64(flags & state_flags) > 1,
66
+ "reported invalid security state: %#llx\n",
67
+ (unsigned long long) flags);
68
+ return flags;
69
+}
70
+int nvdimm_security_freeze(struct nvdimm *nvdimm);
71
+#if IS_ENABLED(CONFIG_NVDIMM_KEYS)
72
+ssize_t nvdimm_security_store(struct device *dev, const char *buf, size_t len);
73
+void nvdimm_security_overwrite_query(struct work_struct *work);
74
+#else
75
+static inline ssize_t nvdimm_security_store(struct device *dev,
76
+ const char *buf, size_t len)
77
+{
78
+ return -EOPNOTSUPP;
79
+}
80
+static inline void nvdimm_security_overwrite_query(struct work_struct *work)
81
+{
82
+}
83
+#endif
4784
4885 /**
4986 * struct blk_alloc_info - tracking info for BLK dpa scanning
....@@ -78,22 +115,16 @@
78115 int __init nvdimm_bus_init(void);
79116 void nvdimm_bus_exit(void);
80117 void nvdimm_devs_exit(void);
81
-void nd_region_devs_exit(void);
82
-void nd_region_probe_success(struct nvdimm_bus *nvdimm_bus, struct device *dev);
83118 struct nd_region;
119
+void nd_region_advance_seeds(struct nd_region *nd_region, struct device *dev);
84120 void nd_region_create_ns_seed(struct nd_region *nd_region);
85121 void nd_region_create_btt_seed(struct nd_region *nd_region);
86122 void nd_region_create_pfn_seed(struct nd_region *nd_region);
87123 void nd_region_create_dax_seed(struct nd_region *nd_region);
88
-void nd_region_disable(struct nvdimm_bus *nvdimm_bus, struct device *dev);
89124 int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus);
90125 void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus);
91126 void nd_synchronize(void);
92
-int nvdimm_bus_register_dimms(struct nvdimm_bus *nvdimm_bus);
93
-int nvdimm_bus_register_regions(struct nvdimm_bus *nvdimm_bus);
94
-int nvdimm_bus_init_interleave_sets(struct nvdimm_bus *nvdimm_bus);
95127 void __nd_device_register(struct device *dev);
96
-int nd_match_dimm(struct device *dev, void *data);
97128 struct nd_label_id;
98129 char *nd_label_gen_id(struct nd_label_id *label_id, u8 *uuid, u32 flags);
99130 bool nd_is_uuid_unique(struct device *dev, u8 *uuid);
....@@ -134,4 +165,88 @@
134165 struct nd_namespace_common **_ndns, const char *buf,
135166 size_t len);
136167 struct nd_pfn *to_nd_pfn_safe(struct device *dev);
168
+bool is_nvdimm_bus(struct device *dev);
169
+
170
+#if IS_ENABLED(CONFIG_ND_CLAIM)
171
+int devm_nsio_enable(struct device *dev, struct nd_namespace_io *nsio,
172
+ resource_size_t size);
173
+void devm_nsio_disable(struct device *dev, struct nd_namespace_io *nsio);
174
+#else
175
+static inline int devm_nsio_enable(struct device *dev,
176
+ struct nd_namespace_io *nsio, resource_size_t size)
177
+{
178
+ return -ENXIO;
179
+}
180
+
181
+static inline void devm_nsio_disable(struct device *dev,
182
+ struct nd_namespace_io *nsio)
183
+{
184
+}
185
+#endif
186
+
187
+#ifdef CONFIG_PROVE_LOCKING
188
+extern struct class *nd_class;
189
+
190
+enum {
191
+ LOCK_BUS,
192
+ LOCK_NDCTL,
193
+ LOCK_REGION,
194
+ LOCK_DIMM = LOCK_REGION,
195
+ LOCK_NAMESPACE,
196
+ LOCK_CLAIM,
197
+};
198
+
199
+static inline void debug_nvdimm_lock(struct device *dev)
200
+{
201
+ if (is_nd_region(dev))
202
+ mutex_lock_nested(&dev->lockdep_mutex, LOCK_REGION);
203
+ else if (is_nvdimm(dev))
204
+ mutex_lock_nested(&dev->lockdep_mutex, LOCK_DIMM);
205
+ else if (is_nd_btt(dev) || is_nd_pfn(dev) || is_nd_dax(dev))
206
+ mutex_lock_nested(&dev->lockdep_mutex, LOCK_CLAIM);
207
+ else if (dev->parent && (is_nd_region(dev->parent)))
208
+ mutex_lock_nested(&dev->lockdep_mutex, LOCK_NAMESPACE);
209
+ else if (is_nvdimm_bus(dev))
210
+ mutex_lock_nested(&dev->lockdep_mutex, LOCK_BUS);
211
+ else if (dev->class && dev->class == nd_class)
212
+ mutex_lock_nested(&dev->lockdep_mutex, LOCK_NDCTL);
213
+ else
214
+ dev_WARN(dev, "unknown lock level\n");
215
+}
216
+
217
+static inline void debug_nvdimm_unlock(struct device *dev)
218
+{
219
+ mutex_unlock(&dev->lockdep_mutex);
220
+}
221
+
222
+static inline void nd_device_lock(struct device *dev)
223
+{
224
+ device_lock(dev);
225
+ debug_nvdimm_lock(dev);
226
+}
227
+
228
+static inline void nd_device_unlock(struct device *dev)
229
+{
230
+ debug_nvdimm_unlock(dev);
231
+ device_unlock(dev);
232
+}
233
+#else
234
+static inline void nd_device_lock(struct device *dev)
235
+{
236
+ device_lock(dev);
237
+}
238
+
239
+static inline void nd_device_unlock(struct device *dev)
240
+{
241
+ device_unlock(dev);
242
+}
243
+
244
+static inline void debug_nvdimm_lock(struct device *dev)
245
+{
246
+}
247
+
248
+static inline void debug_nvdimm_unlock(struct device *dev)
249
+{
250
+}
251
+#endif
137252 #endif /* __ND_CORE_H__ */