]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - include/linux/nd.h
Merge tag '5.15-rc1-smb3' of git://git.samba.org/sfrench/cifs-2.6
[mirror_ubuntu-jammy-kernel.git] / include / linux / nd.h
CommitLineData
5b497af4 1/* SPDX-License-Identifier: GPL-2.0-only */
4d88a97a
DW
2/*
3 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
4d88a97a
DW
4 */
5#ifndef __LINUX_ND_H__
6#define __LINUX_ND_H__
8c2f7e86 7#include <linux/fs.h>
4d88a97a
DW
8#include <linux/ndctl.h>
9#include <linux/device.h>
200c79da 10#include <linux/badblocks.h>
4d88a97a 11
71999466
DW
12enum nvdimm_event {
13 NVDIMM_REVALIDATE_POISON,
2361db89 14 NVDIMM_REVALIDATE_REGION,
71999466
DW
15};
16
b3fde74e
DW
17enum nvdimm_claim_class {
18 NVDIMM_CCLASS_NONE,
19 NVDIMM_CCLASS_BTT,
14e49454 20 NVDIMM_CCLASS_BTT2,
b3fde74e
DW
21 NVDIMM_CCLASS_PFN,
22 NVDIMM_CCLASS_DAX,
23 NVDIMM_CCLASS_UNKNOWN,
24};
25
4d88a97a
DW
26struct nd_device_driver {
27 struct device_driver drv;
28 unsigned long type;
29 int (*probe)(struct device *dev);
1f975074 30 void (*remove)(struct device *dev);
476f848a 31 void (*shutdown)(struct device *dev);
71999466 32 void (*notify)(struct device *dev, enum nvdimm_event event);
4d88a97a
DW
33};
34
35static inline struct nd_device_driver *to_nd_device_driver(
36 struct device_driver *drv)
37{
38 return container_of(drv, struct nd_device_driver, drv);
3d88002e
DW
39};
40
8c2f7e86
DW
41/**
42 * struct nd_namespace_common - core infrastructure of a namespace
43 * @force_raw: ignore other personalities for the namespace (e.g. btt)
44 * @dev: device model node
45 * @claim: when set a another personality has taken ownership of the namespace
b3fde74e 46 * @claim_class: restrict claim type to a given class
8c2f7e86
DW
47 * @rw_bytes: access the raw namespace capacity with byte-aligned transfers
48 */
49struct nd_namespace_common {
50 int force_raw;
51 struct device dev;
52 struct device *claim;
b3fde74e 53 enum nvdimm_claim_class claim_class;
8c2f7e86 54 int (*rw_bytes)(struct nd_namespace_common *, resource_size_t offset,
3ae3d67b 55 void *buf, size_t size, int rw, unsigned long flags);
8c2f7e86
DW
56};
57
58static inline struct nd_namespace_common *to_ndns(struct device *dev)
59{
60 return container_of(dev, struct nd_namespace_common, dev);
61}
62
bf9bccc1 63/**
200c79da 64 * struct nd_namespace_io - device representation of a persistent memory range
bf9bccc1
DW
65 * @dev: namespace device created by the nd region driver
66 * @res: struct resource conversion of a NFIT SPA table
200c79da
DW
67 * @size: cached resource_size(@res) for fast path size checks
68 * @addr: virtual address to access the namespace range
69 * @bb: badblocks list for the namespace range
bf9bccc1 70 */
3d88002e 71struct nd_namespace_io {
8c2f7e86 72 struct nd_namespace_common common;
3d88002e 73 struct resource res;
200c79da 74 resource_size_t size;
7a9eb206 75 void *addr;
200c79da 76 struct badblocks bb;
3d88002e
DW
77};
78
bf9bccc1
DW
79/**
80 * struct nd_namespace_pmem - namespace device for dimm-backed interleaved memory
81 * @nsio: device and system physical address range to drive
f979b13c 82 * @lbasize: logical sector size for the namespace in block-device-mode
bf9bccc1
DW
83 * @alt_name: namespace name supplied in the dimm label
84 * @uuid: namespace name supplied in the dimm label
0e3b0d12 85 * @id: ida allocated id
bf9bccc1
DW
86 */
87struct nd_namespace_pmem {
88 struct nd_namespace_io nsio;
f979b13c 89 unsigned long lbasize;
bf9bccc1
DW
90 char *alt_name;
91 u8 *uuid;
0e3b0d12 92 int id;
bf9bccc1
DW
93};
94
1b40e09a
DW
95/**
96 * struct nd_namespace_blk - namespace for dimm-bounded persistent memory
1b40e09a
DW
97 * @alt_name: namespace name supplied in the dimm label
98 * @uuid: namespace name supplied in the dimm label
99 * @id: ida allocated id
100 * @lbasize: blk namespaces have a native sector size when btt not present
9d90725d 101 * @size: sum of all the resource ranges allocated to this namespace
1b40e09a
DW
102 * @num_resources: number of dpa extents to claim
103 * @res: discontiguous dpa extents for given dimm
104 */
105struct nd_namespace_blk {
8c2f7e86 106 struct nd_namespace_common common;
1b40e09a
DW
107 char *alt_name;
108 u8 *uuid;
109 int id;
110 unsigned long lbasize;
9d90725d 111 resource_size_t size;
1b40e09a
DW
112 int num_resources;
113 struct resource **res;
114};
115
6ff3e912 116static inline struct nd_namespace_io *to_nd_namespace_io(const struct device *dev)
3d88002e 117{
8c2f7e86 118 return container_of(dev, struct nd_namespace_io, common.dev);
4d88a97a
DW
119}
120
6ff3e912 121static inline struct nd_namespace_pmem *to_nd_namespace_pmem(const struct device *dev)
bf9bccc1
DW
122{
123 struct nd_namespace_io *nsio = to_nd_namespace_io(dev);
124
125 return container_of(nsio, struct nd_namespace_pmem, nsio);
126}
127
6ff3e912 128static inline struct nd_namespace_blk *to_nd_namespace_blk(const struct device *dev)
1b40e09a 129{
8c2f7e86
DW
130 return container_of(dev, struct nd_namespace_blk, common.dev);
131}
132
133/**
134 * nvdimm_read_bytes() - synchronously read bytes from an nvdimm namespace
135 * @ndns: device to read
136 * @offset: namespace-relative starting offset
137 * @buf: buffer to fill
138 * @size: transfer length
139 *
140 * @buf is up-to-date upon return from this routine.
141 */
142static inline int nvdimm_read_bytes(struct nd_namespace_common *ndns,
3ae3d67b
VV
143 resource_size_t offset, void *buf, size_t size,
144 unsigned long flags)
8c2f7e86 145{
3ae3d67b 146 return ndns->rw_bytes(ndns, offset, buf, size, READ, flags);
8c2f7e86
DW
147}
148
149/**
150 * nvdimm_write_bytes() - synchronously write bytes to an nvdimm namespace
2f474149 151 * @ndns: device to write
8c2f7e86
DW
152 * @offset: namespace-relative starting offset
153 * @buf: buffer to drain
154 * @size: transfer length
155 *
156 * NVDIMM Namepaces disks do not implement sectors internally. Depending on
157 * the @ndns, the contents of @buf may be in cpu cache, platform buffers,
158 * or on backing memory media upon return from this routine. Flushing
159 * to media is handled internal to the @ndns driver, if at all.
160 */
161static inline int nvdimm_write_bytes(struct nd_namespace_common *ndns,
3ae3d67b
VV
162 resource_size_t offset, void *buf, size_t size,
163 unsigned long flags)
8c2f7e86 164{
3ae3d67b 165 return ndns->rw_bytes(ndns, offset, buf, size, WRITE, flags);
1b40e09a
DW
166}
167
4d88a97a
DW
168#define MODULE_ALIAS_ND_DEVICE(type) \
169 MODULE_ALIAS("nd:t" __stringify(type) "*")
170#define ND_DEVICE_MODALIAS_FMT "nd:t%d"
171
71999466
DW
172struct nd_region;
173void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event);
4d88a97a
DW
174int __must_check __nd_driver_register(struct nd_device_driver *nd_drv,
175 struct module *module, const char *mod_name);
71cfdd0b
JT
176static inline void nd_driver_unregister(struct nd_device_driver *drv)
177{
178 driver_unregister(&drv->drv);
179}
4d88a97a
DW
180#define nd_driver_register(driver) \
181 __nd_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
71cfdd0b
JT
182#define module_nd_driver(driver) \
183 module_driver(driver, nd_driver_register, nd_driver_unregister)
4d88a97a 184#endif /* __LINUX_ND_H__ */