Thomas Gleixner | 5b497af | 2019-05-29 07:18:09 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 2 | /* |
| 3 | * Copyright(c) 2013-2015 Intel Corporation. All rights reserved. |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 4 | */ |
| 5 | #ifndef __ND_H__ |
| 6 | #define __ND_H__ |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 7 | #include <linux/libnvdimm.h> |
Dan Williams | 200c79d | 2016-03-22 00:22:16 -0700 | [diff] [blame] | 8 | #include <linux/badblocks.h> |
Dan Williams | f0dc089 | 2015-05-16 12:28:53 -0400 | [diff] [blame] | 9 | #include <linux/blkdev.h> |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 10 | #include <linux/device.h> |
| 11 | #include <linux/mutex.h> |
| 12 | #include <linux/ndctl.h> |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 13 | #include <linux/types.h> |
Dan Williams | 7199946 | 2016-02-18 10:29:49 -0800 | [diff] [blame] | 14 | #include <linux/nd.h> |
Dan Williams | 4a826c8 | 2015-06-09 16:09:36 -0400 | [diff] [blame] | 15 | #include "label.h" |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 16 | |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 17 | enum { |
Vishal Verma | 5212e11 | 2015-06-25 04:20:32 -0400 | [diff] [blame] | 18 | /* |
| 19 | * Limits the maximum number of block apertures a dimm can |
| 20 | * support and is an input to the geometry/on-disk-format of a |
| 21 | * BTT instance |
| 22 | */ |
| 23 | ND_MAX_LANES = 256, |
Vishal Verma | fcae695 | 2015-06-25 04:22:39 -0400 | [diff] [blame] | 24 | INT_LBASIZE_ALIGNMENT = 64, |
Vishal Verma | 3ae3d67 | 2017-05-10 15:01:30 -0600 | [diff] [blame] | 25 | NVDIMM_IO_ATOMIC = 1, |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 26 | }; |
| 27 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 28 | struct nvdimm_drvdata { |
| 29 | struct device *dev; |
Dan Williams | 02881768 | 2017-08-29 18:28:18 -0700 | [diff] [blame] | 30 | int nslabel_size; |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 31 | struct nd_cmd_get_config_size nsarea; |
| 32 | void *data; |
Dan Williams | 4a826c8 | 2015-06-09 16:09:36 -0400 | [diff] [blame] | 33 | int ns_current, ns_next; |
| 34 | struct resource dpa; |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 35 | struct kref kref; |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 36 | }; |
| 37 | |
Dan Williams | b4366a8 | 2021-08-24 09:05:30 -0700 | [diff] [blame] | 38 | static inline const u8 *nsl_ref_name(struct nvdimm_drvdata *ndd, |
| 39 | struct nd_namespace_label *nd_label) |
| 40 | { |
| 41 | return nd_label->name; |
| 42 | } |
| 43 | |
| 44 | static inline u8 *nsl_get_name(struct nvdimm_drvdata *ndd, |
| 45 | struct nd_namespace_label *nd_label, u8 *name) |
| 46 | { |
| 47 | return memcpy(name, nd_label->name, NSLABEL_NAME_LEN); |
| 48 | } |
| 49 | |
Dan Williams | 8176f14 | 2021-08-24 09:05:41 -0700 | [diff] [blame] | 50 | static inline u8 *nsl_set_name(struct nvdimm_drvdata *ndd, |
| 51 | struct nd_namespace_label *nd_label, u8 *name) |
| 52 | { |
| 53 | if (!name) |
| 54 | return NULL; |
| 55 | return memcpy(nd_label->name, name, NSLABEL_NAME_LEN); |
| 56 | } |
| 57 | |
Dan Williams | b4366a8 | 2021-08-24 09:05:30 -0700 | [diff] [blame] | 58 | static inline u32 nsl_get_slot(struct nvdimm_drvdata *ndd, |
| 59 | struct nd_namespace_label *nd_label) |
| 60 | { |
| 61 | return __le32_to_cpu(nd_label->slot); |
| 62 | } |
| 63 | |
Dan Williams | 8176f14 | 2021-08-24 09:05:41 -0700 | [diff] [blame] | 64 | static inline void nsl_set_slot(struct nvdimm_drvdata *ndd, |
| 65 | struct nd_namespace_label *nd_label, u32 slot) |
| 66 | { |
| 67 | nd_label->slot = __cpu_to_le32(slot); |
| 68 | } |
| 69 | |
Dan Williams | b4366a8 | 2021-08-24 09:05:30 -0700 | [diff] [blame] | 70 | static inline u64 nsl_get_checksum(struct nvdimm_drvdata *ndd, |
| 71 | struct nd_namespace_label *nd_label) |
| 72 | { |
| 73 | return __le64_to_cpu(nd_label->checksum); |
| 74 | } |
| 75 | |
Dan Williams | 8176f14 | 2021-08-24 09:05:41 -0700 | [diff] [blame] | 76 | static inline void nsl_set_checksum(struct nvdimm_drvdata *ndd, |
| 77 | struct nd_namespace_label *nd_label, |
| 78 | u64 checksum) |
| 79 | { |
| 80 | nd_label->checksum = __cpu_to_le64(checksum); |
| 81 | } |
| 82 | |
Dan Williams | b4366a8 | 2021-08-24 09:05:30 -0700 | [diff] [blame] | 83 | static inline u32 nsl_get_flags(struct nvdimm_drvdata *ndd, |
| 84 | struct nd_namespace_label *nd_label) |
| 85 | { |
| 86 | return __le32_to_cpu(nd_label->flags); |
| 87 | } |
| 88 | |
Dan Williams | 8176f14 | 2021-08-24 09:05:41 -0700 | [diff] [blame] | 89 | static inline void nsl_set_flags(struct nvdimm_drvdata *ndd, |
| 90 | struct nd_namespace_label *nd_label, u32 flags) |
| 91 | { |
| 92 | nd_label->flags = __cpu_to_le32(flags); |
| 93 | } |
| 94 | |
Dan Williams | b4366a8 | 2021-08-24 09:05:30 -0700 | [diff] [blame] | 95 | static inline u64 nsl_get_dpa(struct nvdimm_drvdata *ndd, |
| 96 | struct nd_namespace_label *nd_label) |
| 97 | { |
| 98 | return __le64_to_cpu(nd_label->dpa); |
| 99 | } |
| 100 | |
Dan Williams | 8176f14 | 2021-08-24 09:05:41 -0700 | [diff] [blame] | 101 | static inline void nsl_set_dpa(struct nvdimm_drvdata *ndd, |
| 102 | struct nd_namespace_label *nd_label, u64 dpa) |
| 103 | { |
| 104 | nd_label->dpa = __cpu_to_le64(dpa); |
| 105 | } |
| 106 | |
Dan Williams | b4366a8 | 2021-08-24 09:05:30 -0700 | [diff] [blame] | 107 | static inline u64 nsl_get_rawsize(struct nvdimm_drvdata *ndd, |
| 108 | struct nd_namespace_label *nd_label) |
| 109 | { |
| 110 | return __le64_to_cpu(nd_label->rawsize); |
| 111 | } |
| 112 | |
Dan Williams | 8176f14 | 2021-08-24 09:05:41 -0700 | [diff] [blame] | 113 | static inline void nsl_set_rawsize(struct nvdimm_drvdata *ndd, |
| 114 | struct nd_namespace_label *nd_label, |
| 115 | u64 rawsize) |
| 116 | { |
| 117 | nd_label->rawsize = __cpu_to_le64(rawsize); |
| 118 | } |
| 119 | |
Dan Williams | b4366a8 | 2021-08-24 09:05:30 -0700 | [diff] [blame] | 120 | static inline u64 nsl_get_isetcookie(struct nvdimm_drvdata *ndd, |
| 121 | struct nd_namespace_label *nd_label) |
| 122 | { |
| 123 | return __le64_to_cpu(nd_label->isetcookie); |
| 124 | } |
| 125 | |
Dan Williams | 8176f14 | 2021-08-24 09:05:41 -0700 | [diff] [blame] | 126 | static inline void nsl_set_isetcookie(struct nvdimm_drvdata *ndd, |
| 127 | struct nd_namespace_label *nd_label, |
| 128 | u64 isetcookie) |
| 129 | { |
| 130 | nd_label->isetcookie = __cpu_to_le64(isetcookie); |
| 131 | } |
| 132 | |
Dan Williams | 9761b02 | 2021-08-24 09:05:35 -0700 | [diff] [blame] | 133 | static inline bool nsl_validate_isetcookie(struct nvdimm_drvdata *ndd, |
| 134 | struct nd_namespace_label *nd_label, |
| 135 | u64 cookie) |
| 136 | { |
| 137 | return cookie == __le64_to_cpu(nd_label->isetcookie); |
| 138 | } |
| 139 | |
Dan Williams | b4366a8 | 2021-08-24 09:05:30 -0700 | [diff] [blame] | 140 | static inline u16 nsl_get_position(struct nvdimm_drvdata *ndd, |
| 141 | struct nd_namespace_label *nd_label) |
| 142 | { |
| 143 | return __le16_to_cpu(nd_label->position); |
| 144 | } |
| 145 | |
Dan Williams | 8176f14 | 2021-08-24 09:05:41 -0700 | [diff] [blame] | 146 | static inline void nsl_set_position(struct nvdimm_drvdata *ndd, |
| 147 | struct nd_namespace_label *nd_label, |
| 148 | u16 position) |
| 149 | { |
| 150 | nd_label->position = __cpu_to_le16(position); |
| 151 | } |
| 152 | |
| 153 | |
Dan Williams | b4366a8 | 2021-08-24 09:05:30 -0700 | [diff] [blame] | 154 | static inline u16 nsl_get_nlabel(struct nvdimm_drvdata *ndd, |
| 155 | struct nd_namespace_label *nd_label) |
| 156 | { |
| 157 | return __le16_to_cpu(nd_label->nlabel); |
| 158 | } |
| 159 | |
Dan Williams | 8176f14 | 2021-08-24 09:05:41 -0700 | [diff] [blame] | 160 | static inline void nsl_set_nlabel(struct nvdimm_drvdata *ndd, |
| 161 | struct nd_namespace_label *nd_label, |
| 162 | u16 nlabel) |
| 163 | { |
| 164 | nd_label->nlabel = __cpu_to_le16(nlabel); |
| 165 | } |
| 166 | |
Dan Williams | b4366a8 | 2021-08-24 09:05:30 -0700 | [diff] [blame] | 167 | static inline u64 nsl_get_lbasize(struct nvdimm_drvdata *ndd, |
| 168 | struct nd_namespace_label *nd_label) |
| 169 | { |
| 170 | return __le64_to_cpu(nd_label->lbasize); |
| 171 | } |
| 172 | |
Dan Williams | 8176f14 | 2021-08-24 09:05:41 -0700 | [diff] [blame] | 173 | static inline void nsl_set_lbasize(struct nvdimm_drvdata *ndd, |
| 174 | struct nd_namespace_label *nd_label, |
| 175 | u64 lbasize) |
| 176 | { |
| 177 | nd_label->lbasize = __cpu_to_le64(lbasize); |
| 178 | } |
| 179 | |
Dan Williams | d1c6e08 | 2021-09-08 22:11:37 -0700 | [diff] [blame] | 180 | static inline const uuid_t *nsl_get_uuid(struct nvdimm_drvdata *ndd, |
| 181 | struct nd_namespace_label *nd_label, |
| 182 | uuid_t *uuid) |
| 183 | { |
| 184 | import_uuid(uuid, nd_label->uuid); |
| 185 | return uuid; |
| 186 | } |
| 187 | |
| 188 | static inline const uuid_t *nsl_set_uuid(struct nvdimm_drvdata *ndd, |
| 189 | struct nd_namespace_label *nd_label, |
| 190 | const uuid_t *uuid) |
| 191 | { |
| 192 | export_uuid(nd_label->uuid, uuid); |
| 193 | return uuid; |
| 194 | } |
| 195 | |
| 196 | static inline bool nsl_uuid_equal(struct nvdimm_drvdata *ndd, |
| 197 | struct nd_namespace_label *nd_label, |
| 198 | const uuid_t *uuid) |
| 199 | { |
| 200 | uuid_t tmp; |
| 201 | |
| 202 | import_uuid(&tmp, nd_label->uuid); |
| 203 | return uuid_equal(&tmp, uuid); |
| 204 | } |
| 205 | |
| 206 | static inline const u8 *nsl_uuid_raw(struct nvdimm_drvdata *ndd, |
| 207 | struct nd_namespace_label *nd_label) |
| 208 | { |
| 209 | return nd_label->uuid; |
| 210 | } |
| 211 | |
Dan Williams | f56541a | 2021-08-24 09:05:51 -0700 | [diff] [blame] | 212 | bool nsl_validate_blk_isetcookie(struct nvdimm_drvdata *ndd, |
| 213 | struct nd_namespace_label *nd_label, |
| 214 | u64 isetcookie); |
Dan Williams | 8b03aa0 | 2021-08-24 09:06:02 -0700 | [diff] [blame] | 215 | bool nsl_validate_type_guid(struct nvdimm_drvdata *ndd, |
| 216 | struct nd_namespace_label *nd_label, guid_t *guid); |
Dan Williams | a6e6d72 | 2021-08-24 09:06:07 -0700 | [diff] [blame] | 217 | enum nvdimm_claim_class nsl_get_claim_class(struct nvdimm_drvdata *ndd, |
| 218 | struct nd_namespace_label *nd_label); |
Dan Williams | f56541a | 2021-08-24 09:05:51 -0700 | [diff] [blame] | 219 | |
Dan Williams | e5ae3b2 | 2016-06-07 17:00:04 -0700 | [diff] [blame] | 220 | struct nd_region_data { |
| 221 | int ns_count; |
| 222 | int ns_active; |
Dan Williams | 595c730 | 2016-09-23 17:53:52 -0700 | [diff] [blame] | 223 | unsigned int hints_shift; |
Gustavo A. R. Silva | 9106137 | 2020-03-19 18:09:37 -0500 | [diff] [blame] | 224 | void __iomem *flush_wpq[]; |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 225 | }; |
| 226 | |
Dan Williams | 595c730 | 2016-09-23 17:53:52 -0700 | [diff] [blame] | 227 | static inline void __iomem *ndrd_get_flush_wpq(struct nd_region_data *ndrd, |
| 228 | int dimm, int hint) |
| 229 | { |
| 230 | unsigned int num = 1 << ndrd->hints_shift; |
| 231 | unsigned int mask = num - 1; |
| 232 | |
| 233 | return ndrd->flush_wpq[dimm * num + (hint & mask)]; |
| 234 | } |
| 235 | |
| 236 | static inline void ndrd_set_flush_wpq(struct nd_region_data *ndrd, int dimm, |
| 237 | int hint, void __iomem *flush) |
| 238 | { |
| 239 | unsigned int num = 1 << ndrd->hints_shift; |
| 240 | unsigned int mask = num - 1; |
| 241 | |
| 242 | ndrd->flush_wpq[dimm * num + (hint & mask)] = flush; |
| 243 | } |
| 244 | |
Dan Williams | 4a826c8 | 2015-06-09 16:09:36 -0400 | [diff] [blame] | 245 | static inline struct nd_namespace_index *to_namespace_index( |
| 246 | struct nvdimm_drvdata *ndd, int i) |
| 247 | { |
| 248 | if (i < 0) |
| 249 | return NULL; |
| 250 | |
| 251 | return ndd->data + sizeof_namespace_index(ndd) * i; |
| 252 | } |
| 253 | |
| 254 | static inline struct nd_namespace_index *to_current_namespace_index( |
| 255 | struct nvdimm_drvdata *ndd) |
| 256 | { |
| 257 | return to_namespace_index(ndd, ndd->ns_current); |
| 258 | } |
| 259 | |
| 260 | static inline struct nd_namespace_index *to_next_namespace_index( |
| 261 | struct nvdimm_drvdata *ndd) |
| 262 | { |
| 263 | return to_namespace_index(ndd, ndd->ns_next); |
| 264 | } |
| 265 | |
Dan Williams | 564e871 | 2017-06-03 18:30:43 +0900 | [diff] [blame] | 266 | unsigned sizeof_namespace_label(struct nvdimm_drvdata *ndd); |
| 267 | |
| 268 | #define namespace_label_has(ndd, field) \ |
| 269 | (offsetof(struct nd_namespace_label, field) \ |
| 270 | < sizeof_namespace_label(ndd)) |
| 271 | |
Dan Williams | 4a826c8 | 2015-06-09 16:09:36 -0400 | [diff] [blame] | 272 | #define nd_dbg_dpa(r, d, res, fmt, arg...) \ |
| 273 | dev_dbg((r) ? &(r)->dev : (d)->dev, "%s: %.13s: %#llx @ %#llx " fmt, \ |
| 274 | (r) ? dev_name((d)->dev) : "", res ? res->name : "null", \ |
| 275 | (unsigned long long) (res ? resource_size(res) : 0), \ |
| 276 | (unsigned long long) (res ? res->start : 0), ##arg) |
| 277 | |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 278 | #define for_each_dpa_resource(ndd, res) \ |
| 279 | for (res = (ndd)->dpa.child; res; res = res->sibling) |
| 280 | |
Dan Williams | 4a826c8 | 2015-06-09 16:09:36 -0400 | [diff] [blame] | 281 | #define for_each_dpa_resource_safe(ndd, res, next) \ |
| 282 | for (res = (ndd)->dpa.child, next = res ? res->sibling : NULL; \ |
| 283 | res; res = next, next = next ? next->sibling : NULL) |
| 284 | |
Vishal Verma | 5212e11 | 2015-06-25 04:20:32 -0400 | [diff] [blame] | 285 | struct nd_percpu_lane { |
| 286 | int count; |
| 287 | spinlock_t lock; |
| 288 | }; |
| 289 | |
Dan Williams | c4703ce | 2019-04-30 21:51:21 -0700 | [diff] [blame] | 290 | enum nd_label_flags { |
| 291 | ND_LABEL_REAP, |
| 292 | }; |
Dan Williams | ae8219f | 2016-09-19 16:04:21 -0700 | [diff] [blame] | 293 | struct nd_label_ent { |
| 294 | struct list_head list; |
Dan Williams | c4703ce | 2019-04-30 21:51:21 -0700 | [diff] [blame] | 295 | unsigned long flags; |
Dan Williams | ae8219f | 2016-09-19 16:04:21 -0700 | [diff] [blame] | 296 | struct nd_namespace_label *label; |
| 297 | }; |
| 298 | |
| 299 | enum nd_mapping_lock_class { |
| 300 | ND_MAPPING_CLASS0, |
| 301 | ND_MAPPING_UUID_SCAN, |
| 302 | }; |
| 303 | |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 304 | struct nd_mapping { |
| 305 | struct nvdimm *nvdimm; |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 306 | u64 start; |
| 307 | u64 size; |
Dan Williams | 401c0a1 | 2017-08-04 17:20:16 -0700 | [diff] [blame] | 308 | int position; |
Dan Williams | ae8219f | 2016-09-19 16:04:21 -0700 | [diff] [blame] | 309 | struct list_head labels; |
| 310 | struct mutex lock; |
Dan Williams | 44c462e | 2016-09-19 16:38:50 -0700 | [diff] [blame] | 311 | /* |
| 312 | * @ndd is for private use at region enable / disable time for |
| 313 | * get_ndd() + put_ndd(), all other nd_mapping to ndd |
| 314 | * conversions use to_ndd() which respects enabled state of the |
| 315 | * nvdimm. |
| 316 | */ |
| 317 | struct nvdimm_drvdata *ndd; |
| 318 | }; |
| 319 | |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 320 | struct nd_region { |
| 321 | struct device dev; |
Dan Williams | 1b40e09 | 2015-05-01 13:34:01 -0400 | [diff] [blame] | 322 | struct ida ns_ida; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 323 | struct ida btt_ida; |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 324 | struct ida pfn_ida; |
Dan Williams | cd03412 | 2016-03-11 10:15:36 -0800 | [diff] [blame] | 325 | struct ida dax_ida; |
Dan Williams | 004f1af | 2015-08-24 19:20:23 -0400 | [diff] [blame] | 326 | unsigned long flags; |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 327 | struct device *ns_seed; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 328 | struct device *btt_seed; |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 329 | struct device *pfn_seed; |
Dan Williams | cd03412 | 2016-03-11 10:15:36 -0800 | [diff] [blame] | 330 | struct device *dax_seed; |
Dan Williams | 2522afb | 2020-01-30 12:06:23 -0800 | [diff] [blame] | 331 | unsigned long align; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 332 | u16 ndr_mappings; |
| 333 | u64 ndr_size; |
| 334 | u64 ndr_start; |
Dan Williams | 8fc5c73 | 2018-11-09 12:43:07 -0800 | [diff] [blame] | 335 | int id, num_lanes, ro, numa_node, target_node; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 336 | void *provider_data; |
Toshi Kani | 975750a | 2017-06-12 16:25:11 -0600 | [diff] [blame] | 337 | struct kernfs_node *bb_state; |
Dave Jiang | 6a6bef9 | 2017-04-07 15:33:20 -0700 | [diff] [blame] | 338 | struct badblocks bb; |
Dan Williams | eaf9615 | 2015-05-01 13:11:27 -0400 | [diff] [blame] | 339 | struct nd_interleave_set *nd_set; |
Vishal Verma | 5212e11 | 2015-06-25 04:20:32 -0400 | [diff] [blame] | 340 | struct nd_percpu_lane __percpu *lane; |
Pankaj Gupta | c5d4355 | 2019-07-05 19:33:22 +0530 | [diff] [blame] | 341 | int (*flush)(struct nd_region *nd_region, struct bio *bio); |
Gustavo A. R. Silva | 9106137 | 2020-03-19 18:09:37 -0500 | [diff] [blame] | 342 | struct nd_mapping mapping[]; |
Dan Williams | 1f7df6f | 2015-06-09 20:13:14 -0400 | [diff] [blame] | 343 | }; |
| 344 | |
Dan Williams | 8172db9 | 2021-09-08 22:11:42 -0700 | [diff] [blame^] | 345 | static inline bool nsl_validate_nlabel(struct nd_region *nd_region, |
| 346 | struct nvdimm_drvdata *ndd, |
| 347 | struct nd_namespace_label *nd_label) |
| 348 | { |
| 349 | return nsl_get_nlabel(ndd, nd_label) == nd_region->ndr_mappings; |
| 350 | } |
| 351 | |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 352 | struct nd_blk_region { |
| 353 | int (*enable)(struct nvdimm_bus *nvdimm_bus, struct device *dev); |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 354 | int (*do_io)(struct nd_blk_region *ndbr, resource_size_t dpa, |
| 355 | void *iobuf, u64 len, int rw); |
| 356 | void *blk_provider_data; |
| 357 | struct nd_region nd_region; |
| 358 | }; |
| 359 | |
Dan Williams | 4a826c8 | 2015-06-09 16:09:36 -0400 | [diff] [blame] | 360 | /* |
| 361 | * Lookup next in the repeating sequence of 01, 10, and 11. |
| 362 | */ |
| 363 | static inline unsigned nd_inc_seq(unsigned seq) |
| 364 | { |
| 365 | static const unsigned next[] = { 0, 2, 3, 1 }; |
| 366 | |
| 367 | return next[seq & 3]; |
| 368 | } |
Dan Williams | f524bf2 | 2015-05-30 12:36:02 -0400 | [diff] [blame] | 369 | |
Vishal Verma | 5212e11 | 2015-06-25 04:20:32 -0400 | [diff] [blame] | 370 | struct btt; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 371 | struct nd_btt { |
| 372 | struct device dev; |
| 373 | struct nd_namespace_common *ndns; |
Vishal Verma | 5212e11 | 2015-06-25 04:20:32 -0400 | [diff] [blame] | 374 | struct btt *btt; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 375 | unsigned long lbasize; |
Vishal Verma | abe8b4e | 2016-07-27 16:38:59 -0600 | [diff] [blame] | 376 | u64 size; |
Dan Williams | d1c6e08 | 2021-09-08 22:11:37 -0700 | [diff] [blame] | 377 | uuid_t *uuid; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 378 | int id; |
Vishal Verma | 14e4945 | 2017-06-28 14:25:00 -0600 | [diff] [blame] | 379 | int initial_offset; |
| 380 | u16 version_major; |
| 381 | u16 version_minor; |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 382 | }; |
| 383 | |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 384 | enum nd_pfn_mode { |
| 385 | PFN_MODE_NONE, |
| 386 | PFN_MODE_RAM, |
| 387 | PFN_MODE_PMEM, |
| 388 | }; |
| 389 | |
| 390 | struct nd_pfn { |
| 391 | int id; |
Dan Williams | d1c6e08 | 2021-09-08 22:11:37 -0700 | [diff] [blame] | 392 | uuid_t *uuid; |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 393 | struct device dev; |
Dan Williams | 315c562 | 2015-12-10 14:45:23 -0800 | [diff] [blame] | 394 | unsigned long align; |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 395 | unsigned long npfns; |
| 396 | enum nd_pfn_mode mode; |
| 397 | struct nd_pfn_sb *pfn_sb; |
| 398 | struct nd_namespace_common *ndns; |
| 399 | }; |
| 400 | |
Dan Williams | cd03412 | 2016-03-11 10:15:36 -0800 | [diff] [blame] | 401 | struct nd_dax { |
| 402 | struct nd_pfn nd_pfn; |
| 403 | }; |
| 404 | |
Aneesh Kumar K.V | 8f4b01f | 2019-10-31 16:27:41 +0530 | [diff] [blame] | 405 | static inline u32 nd_info_block_reserve(void) |
| 406 | { |
| 407 | return ALIGN(SZ_8K, PAGE_SIZE); |
| 408 | } |
| 409 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 410 | enum nd_async_mode { |
| 411 | ND_SYNC, |
| 412 | ND_ASYNC, |
| 413 | }; |
| 414 | |
Vishal Verma | 41cd8b7 | 2015-06-25 04:21:52 -0400 | [diff] [blame] | 415 | int nd_integrity_init(struct gendisk *disk, unsigned long meta_size); |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 416 | void wait_nvdimm_bus_probe_idle(struct device *dev); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 417 | void nd_device_register(struct device *dev); |
| 418 | void nd_device_unregister(struct device *dev, enum nd_async_mode mode); |
Dan Williams | 7199946 | 2016-02-18 10:29:49 -0800 | [diff] [blame] | 419 | void nd_device_notify(struct device *dev, enum nvdimm_event event); |
Dan Williams | d1c6e08 | 2021-09-08 22:11:37 -0700 | [diff] [blame] | 420 | int nd_uuid_store(struct device *dev, uuid_t **uuid_out, const char *buf, |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 421 | size_t len); |
Dan Williams | b2c48f9 | 2017-08-11 17:36:54 -0700 | [diff] [blame] | 422 | ssize_t nd_size_select_show(unsigned long current_size, |
Dan Williams | 1b40e09 | 2015-05-01 13:34:01 -0400 | [diff] [blame] | 423 | const unsigned long *supported, char *buf); |
Dan Williams | b2c48f9 | 2017-08-11 17:36:54 -0700 | [diff] [blame] | 424 | ssize_t nd_size_select_store(struct device *dev, const char *buf, |
| 425 | unsigned long *current_size, const unsigned long *supported); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 426 | int __init nvdimm_init(void); |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 427 | int __init nd_region_init(void); |
Dan Williams | b3fde74 | 2017-06-04 10:18:39 +0900 | [diff] [blame] | 428 | int __init nd_label_init(void); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 429 | void nvdimm_exit(void); |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 430 | void nd_region_exit(void); |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 431 | struct nvdimm; |
Dan Williams | adbb682 | 2019-11-12 17:00:24 -0800 | [diff] [blame] | 432 | extern const struct attribute_group nd_device_attribute_group; |
Dan Williams | e2f6a0e | 2019-11-19 09:51:54 -0800 | [diff] [blame] | 433 | extern const struct attribute_group nd_numa_attribute_group; |
Dan Williams | e755799a | 2019-11-12 17:08:56 -0800 | [diff] [blame] | 434 | extern const struct attribute_group *nvdimm_bus_attribute_groups[]; |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 435 | struct nvdimm_drvdata *to_ndd(struct nd_mapping *nd_mapping); |
Toshi Kani | aee6598 | 2016-08-16 13:08:40 -0600 | [diff] [blame] | 436 | int nvdimm_check_config_data(struct device *dev); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 437 | int nvdimm_init_nsarea(struct nvdimm_drvdata *ndd); |
| 438 | int nvdimm_init_config_data(struct nvdimm_drvdata *ndd); |
Alexander Duyck | 2d657d1 | 2018-10-10 16:39:20 -0700 | [diff] [blame] | 439 | int nvdimm_get_config_data(struct nvdimm_drvdata *ndd, void *buf, |
| 440 | size_t offset, size_t len); |
Dan Williams | f524bf2 | 2015-05-30 12:36:02 -0400 | [diff] [blame] | 441 | int nvdimm_set_config_data(struct nvdimm_drvdata *ndd, size_t offset, |
| 442 | void *buf, size_t len); |
Dan Williams | 59e6473 | 2016-03-08 07:16:07 -0800 | [diff] [blame] | 443 | long nvdimm_clear_poison(struct device *dev, phys_addr_t phys, |
| 444 | unsigned int len); |
Dan Williams | a0e3745 | 2020-01-30 12:06:18 -0800 | [diff] [blame] | 445 | void nvdimm_set_labeling(struct device *dev); |
Dan Williams | 8f078b3 | 2017-05-04 14:01:24 -0700 | [diff] [blame] | 446 | void nvdimm_set_locked(struct device *dev); |
Dan Williams | d34cb80 | 2017-09-25 11:01:31 -0700 | [diff] [blame] | 447 | void nvdimm_clear_locked(struct device *dev); |
Dan Williams | 1cd7386 | 2019-01-19 08:45:56 -0800 | [diff] [blame] | 448 | int nvdimm_security_setup_events(struct device *dev); |
Dave Jiang | 4c6926a | 2018-12-06 12:40:01 -0800 | [diff] [blame] | 449 | #if IS_ENABLED(CONFIG_NVDIMM_KEYS) |
| 450 | int nvdimm_security_unlock(struct device *dev); |
| 451 | #else |
| 452 | static inline int nvdimm_security_unlock(struct device *dev) |
| 453 | { |
| 454 | return 0; |
| 455 | } |
| 456 | #endif |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 457 | struct nd_btt *to_nd_btt(struct device *dev); |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 458 | |
| 459 | struct nd_gen_sb { |
| 460 | char reserved[SZ_4K - 8]; |
| 461 | __le64 checksum; |
| 462 | }; |
| 463 | |
| 464 | u64 nd_sb_checksum(struct nd_gen_sb *sb); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 465 | #if IS_ENABLED(CONFIG_BTT) |
Dan Williams | 200c79d | 2016-03-22 00:22:16 -0700 | [diff] [blame] | 466 | int nd_btt_probe(struct device *dev, struct nd_namespace_common *ndns); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 467 | bool is_nd_btt(struct device *dev); |
| 468 | struct device *nd_btt_create(struct nd_region *nd_region); |
| 469 | #else |
Dan Williams | e32bc72 | 2016-03-17 18:23:09 -0700 | [diff] [blame] | 470 | static inline int nd_btt_probe(struct device *dev, |
Dan Williams | 200c79d | 2016-03-22 00:22:16 -0700 | [diff] [blame] | 471 | struct nd_namespace_common *ndns) |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 472 | { |
| 473 | return -ENODEV; |
| 474 | } |
| 475 | |
| 476 | static inline bool is_nd_btt(struct device *dev) |
| 477 | { |
| 478 | return false; |
| 479 | } |
| 480 | |
| 481 | static inline struct device *nd_btt_create(struct nd_region *nd_region) |
| 482 | { |
| 483 | return NULL; |
| 484 | } |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 485 | #endif |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 486 | |
| 487 | struct nd_pfn *to_nd_pfn(struct device *dev); |
| 488 | #if IS_ENABLED(CONFIG_NVDIMM_PFN) |
Oliver O'Halloran | 0dd6964 | 2017-06-27 19:56:33 +1000 | [diff] [blame] | 489 | |
Aneesh Kumar K.V | f537669 | 2019-09-05 21:16:03 +0530 | [diff] [blame] | 490 | #define MAX_NVDIMM_ALIGN 4 |
Oliver O'Halloran | 0dd6964 | 2017-06-27 19:56:33 +1000 | [diff] [blame] | 491 | |
Dan Williams | 200c79d | 2016-03-22 00:22:16 -0700 | [diff] [blame] | 492 | int nd_pfn_probe(struct device *dev, struct nd_namespace_common *ndns); |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 493 | bool is_nd_pfn(struct device *dev); |
| 494 | struct device *nd_pfn_create(struct nd_region *nd_region); |
Dan Williams | cd03412 | 2016-03-11 10:15:36 -0800 | [diff] [blame] | 495 | struct device *nd_pfn_devinit(struct nd_pfn *nd_pfn, |
| 496 | struct nd_namespace_common *ndns); |
Dan Williams | c5ed926 | 2016-05-18 14:50:12 -0700 | [diff] [blame] | 497 | int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig); |
Dan Williams | 78c81cc | 2019-11-06 19:56:41 -0800 | [diff] [blame] | 498 | extern const struct attribute_group *nd_pfn_attribute_groups[]; |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 499 | #else |
Dan Williams | 200c79d | 2016-03-22 00:22:16 -0700 | [diff] [blame] | 500 | static inline int nd_pfn_probe(struct device *dev, |
| 501 | struct nd_namespace_common *ndns) |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 502 | { |
| 503 | return -ENODEV; |
| 504 | } |
| 505 | |
| 506 | static inline bool is_nd_pfn(struct device *dev) |
| 507 | { |
| 508 | return false; |
| 509 | } |
| 510 | |
| 511 | static inline struct device *nd_pfn_create(struct nd_region *nd_region) |
| 512 | { |
| 513 | return NULL; |
| 514 | } |
Dan Williams | 32ab0a3f | 2015-08-01 02:16:37 -0400 | [diff] [blame] | 515 | |
Dan Williams | c5ed926 | 2016-05-18 14:50:12 -0700 | [diff] [blame] | 516 | static inline int nd_pfn_validate(struct nd_pfn *nd_pfn, const char *sig) |
Dan Williams | 32ab0a3f | 2015-08-01 02:16:37 -0400 | [diff] [blame] | 517 | { |
| 518 | return -ENODEV; |
| 519 | } |
Dan Williams | e145574 | 2015-07-30 17:57:47 -0400 | [diff] [blame] | 520 | #endif |
| 521 | |
Dan Williams | cd03412 | 2016-03-11 10:15:36 -0800 | [diff] [blame] | 522 | struct nd_dax *to_nd_dax(struct device *dev); |
| 523 | #if IS_ENABLED(CONFIG_NVDIMM_DAX) |
Dan Williams | c5ed926 | 2016-05-18 14:50:12 -0700 | [diff] [blame] | 524 | int nd_dax_probe(struct device *dev, struct nd_namespace_common *ndns); |
Dan Williams | cd03412 | 2016-03-11 10:15:36 -0800 | [diff] [blame] | 525 | bool is_nd_dax(struct device *dev); |
| 526 | struct device *nd_dax_create(struct nd_region *nd_region); |
| 527 | #else |
Dan Williams | c5ed926 | 2016-05-18 14:50:12 -0700 | [diff] [blame] | 528 | static inline int nd_dax_probe(struct device *dev, |
| 529 | struct nd_namespace_common *ndns) |
| 530 | { |
| 531 | return -ENODEV; |
| 532 | } |
| 533 | |
Dan Williams | cd03412 | 2016-03-11 10:15:36 -0800 | [diff] [blame] | 534 | static inline bool is_nd_dax(struct device *dev) |
| 535 | { |
| 536 | return false; |
| 537 | } |
| 538 | |
| 539 | static inline struct device *nd_dax_create(struct nd_region *nd_region) |
| 540 | { |
| 541 | return NULL; |
| 542 | } |
| 543 | #endif |
| 544 | |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 545 | int nd_region_to_nstype(struct nd_region *nd_region); |
| 546 | int nd_region_register_namespaces(struct nd_region *nd_region, int *err); |
Dan Williams | c12c48c | 2017-06-04 10:59:15 +0900 | [diff] [blame] | 547 | u64 nd_region_interleave_set_cookie(struct nd_region *nd_region, |
| 548 | struct nd_namespace_index *nsindex); |
Dan Williams | 86ef58a | 2017-02-28 18:32:48 -0800 | [diff] [blame] | 549 | u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region); |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 550 | void nvdimm_bus_lock(struct device *dev); |
| 551 | void nvdimm_bus_unlock(struct device *dev); |
| 552 | bool is_nvdimm_bus_locked(struct device *dev); |
Christoph Hellwig | 32f61d6 | 2020-09-01 17:57:47 +0200 | [diff] [blame] | 553 | void nvdimm_check_and_set_ro(struct gendisk *disk); |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 554 | void nvdimm_drvdata_release(struct kref *kref); |
| 555 | void put_ndd(struct nvdimm_drvdata *ndd); |
Dan Williams | 4a826c8 | 2015-06-09 16:09:36 -0400 | [diff] [blame] | 556 | int nd_label_reserve_dpa(struct nvdimm_drvdata *ndd); |
| 557 | void nvdimm_free_dpa(struct nvdimm_drvdata *ndd, struct resource *res); |
| 558 | struct resource *nvdimm_allocate_dpa(struct nvdimm_drvdata *ndd, |
| 559 | struct nd_label_id *label_id, resource_size_t start, |
| 560 | resource_size_t n); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 561 | resource_size_t nvdimm_namespace_capacity(struct nd_namespace_common *ndns); |
Dan Williams | 08e6b3c | 2018-06-13 09:08:36 -0700 | [diff] [blame] | 562 | bool nvdimm_namespace_locked(struct nd_namespace_common *ndns); |
Dan Williams | 8c2f7e8 | 2015-06-25 04:20:04 -0400 | [diff] [blame] | 563 | struct nd_namespace_common *nvdimm_namespace_common_probe(struct device *dev); |
Vishal Verma | 5212e11 | 2015-06-25 04:20:32 -0400 | [diff] [blame] | 564 | int nvdimm_namespace_attach_btt(struct nd_namespace_common *ndns); |
Dan Williams | 298f2bc | 2016-03-15 16:41:04 -0700 | [diff] [blame] | 565 | int nvdimm_namespace_detach_btt(struct nd_btt *nd_btt); |
Vishal Verma | 5212e11 | 2015-06-25 04:20:32 -0400 | [diff] [blame] | 566 | const char *nvdimm_namespace_disk_name(struct nd_namespace_common *ndns, |
| 567 | char *name); |
Dan Williams | f979b13 | 2017-06-04 12:12:07 +0900 | [diff] [blame] | 568 | unsigned int pmem_sector_size(struct nd_namespace_common *ndns); |
Dan Williams | a4574f6 | 2020-10-13 16:50:29 -0700 | [diff] [blame] | 569 | struct range; |
Dan Williams | a390180 | 2016-04-07 20:02:06 -0700 | [diff] [blame] | 570 | void nvdimm_badblocks_populate(struct nd_region *nd_region, |
Dan Williams | a4574f6 | 2020-10-13 16:50:29 -0700 | [diff] [blame] | 571 | struct badblocks *bb, const struct range *range); |
Aneesh Kumar K.V | 8f4b01f | 2019-10-31 16:27:41 +0530 | [diff] [blame] | 572 | int devm_namespace_enable(struct device *dev, struct nd_namespace_common *ndns, |
| 573 | resource_size_t size); |
| 574 | void devm_namespace_disable(struct device *dev, |
| 575 | struct nd_namespace_common *ndns); |
Dan Williams | 200c79d | 2016-03-22 00:22:16 -0700 | [diff] [blame] | 576 | #if IS_ENABLED(CONFIG_ND_CLAIM) |
Aneesh Kumar K.V | e96f0bf | 2019-09-05 21:15:59 +0530 | [diff] [blame] | 577 | /* max struct page size independent of kernel config */ |
| 578 | #define MAX_STRUCT_PAGE_SIZE 64 |
Christoph Hellwig | e8d5134 | 2017-12-29 08:54:05 +0100 | [diff] [blame] | 579 | int nvdimm_setup_pfn(struct nd_pfn *nd_pfn, struct dev_pagemap *pgmap); |
Dan Williams | 200c79d | 2016-03-22 00:22:16 -0700 | [diff] [blame] | 580 | #else |
Christoph Hellwig | e8d5134 | 2017-12-29 08:54:05 +0100 | [diff] [blame] | 581 | static inline int nvdimm_setup_pfn(struct nd_pfn *nd_pfn, |
| 582 | struct dev_pagemap *pgmap) |
Dan Williams | ac515c0 | 2016-03-22 00:29:43 -0700 | [diff] [blame] | 583 | { |
Christoph Hellwig | e8d5134 | 2017-12-29 08:54:05 +0100 | [diff] [blame] | 584 | return -ENXIO; |
Dan Williams | ac515c0 | 2016-03-22 00:29:43 -0700 | [diff] [blame] | 585 | } |
Dan Williams | 200c79d | 2016-03-22 00:22:16 -0700 | [diff] [blame] | 586 | #endif |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 587 | int nd_blk_region_init(struct nd_region *nd_region); |
Dan Williams | e5ae3b2 | 2016-06-07 17:00:04 -0700 | [diff] [blame] | 588 | int nd_region_activate(struct nd_region *nd_region); |
Dan Williams | 200c79d | 2016-03-22 00:22:16 -0700 | [diff] [blame] | 589 | static inline bool is_bad_pmem(struct badblocks *bb, sector_t sector, |
| 590 | unsigned int len) |
| 591 | { |
| 592 | if (bb->count) { |
| 593 | sector_t first_bad; |
| 594 | int num_bad; |
| 595 | |
| 596 | return !!badblocks_check(bb, sector, len / 512, &first_bad, |
| 597 | &num_bad); |
| 598 | } |
| 599 | |
| 600 | return false; |
| 601 | } |
Ross Zwisler | 047fc8a | 2015-06-25 04:21:02 -0400 | [diff] [blame] | 602 | resource_size_t nd_namespace_blk_validate(struct nd_namespace_blk *nsblk); |
Dan Williams | d1c6e08 | 2021-09-08 22:11:37 -0700 | [diff] [blame] | 603 | const uuid_t *nd_dev_to_uuid(struct device *dev); |
Dan Williams | 004f1af | 2015-08-24 19:20:23 -0400 | [diff] [blame] | 604 | bool pmem_should_map_pages(struct device *dev); |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 605 | #endif /* __ND_H__ */ |