blob: 59c61e018a869eaf2d009f2eb917e0e42f81329b [file] [log] [blame]
Dan Williams62232e452015-06-08 14:27:06 -04001/*
Dan Williamsbaa51272016-04-05 17:40:52 -07002 * Copyright (c) 2014-2016, Intel Corporation.
Dan Williams62232e452015-06-08 14:27:06 -04003 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU Lesser General Public License,
6 * version 2.1, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT ANY
9 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
10 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
11 * more details.
12 */
13#ifndef __NDCTL_H__
14#define __NDCTL_H__
15
16#include <linux/types.h>
17
18struct nd_cmd_smart {
19 __u32 status;
20 __u8 data[128];
21} __packed;
22
Dan Williamsbaa51272016-04-05 17:40:52 -070023#define ND_SMART_HEALTH_VALID (1 << 0)
24#define ND_SMART_TEMP_VALID (1 << 1)
25#define ND_SMART_SPARES_VALID (1 << 2)
26#define ND_SMART_ALARM_VALID (1 << 3)
27#define ND_SMART_USED_VALID (1 << 4)
28#define ND_SMART_SHUTDOWN_VALID (1 << 5)
29#define ND_SMART_VENDOR_VALID (1 << 6)
30#define ND_SMART_TEMP_TRIP (1 << 0)
31#define ND_SMART_SPARE_TRIP (1 << 1)
32#define ND_SMART_NON_CRITICAL_HEALTH (1 << 0)
33#define ND_SMART_CRITICAL_HEALTH (1 << 1)
34#define ND_SMART_FATAL_HEALTH (1 << 2)
35
36struct nd_smart_payload {
37 __u32 flags;
38 __u8 reserved0[4];
39 __u8 health;
40 __u16 temperature;
41 __u8 spares;
42 __u8 alarm_flags;
43 __u8 life_used;
44 __u8 shutdown_state;
45 __u8 reserved1;
46 __u32 vendor_size;
47 __u8 vendor_data[108];
48} __packed;
49
Dan Williams62232e452015-06-08 14:27:06 -040050struct nd_cmd_smart_threshold {
51 __u32 status;
52 __u8 data[8];
53} __packed;
54
Dan Williamsbaa51272016-04-05 17:40:52 -070055struct nd_smart_threshold_payload {
56 __u16 alarm_control;
57 __u16 temperature;
58 __u8 spares;
59 __u8 reserved[3];
60} __packed;
61
Dan Williams62232e452015-06-08 14:27:06 -040062struct nd_cmd_dimm_flags {
63 __u32 status;
64 __u32 flags;
65} __packed;
66
67struct nd_cmd_get_config_size {
68 __u32 status;
69 __u32 config_size;
70 __u32 max_xfer;
71} __packed;
72
73struct nd_cmd_get_config_data_hdr {
74 __u32 in_offset;
75 __u32 in_length;
76 __u32 status;
77 __u8 out_buf[0];
78} __packed;
79
80struct nd_cmd_set_config_hdr {
81 __u32 in_offset;
82 __u32 in_length;
83 __u8 in_buf[0];
84} __packed;
85
86struct nd_cmd_vendor_hdr {
87 __u32 opcode;
88 __u32 in_length;
89 __u8 in_buf[0];
90} __packed;
91
92struct nd_cmd_vendor_tail {
93 __u32 status;
94 __u32 out_length;
95 __u8 out_buf[0];
96} __packed;
97
98struct nd_cmd_ars_cap {
99 __u64 address;
100 __u64 length;
101 __u32 status;
102 __u32 max_ars_out;
Dan Williams4577b062016-02-17 13:08:58 -0800103 __u32 clear_err_unit;
104 __u32 reserved;
Dan Williams62232e452015-06-08 14:27:06 -0400105} __packed;
106
107struct nd_cmd_ars_start {
108 __u64 address;
109 __u64 length;
110 __u16 type;
Dan Williams4577b062016-02-17 13:08:58 -0800111 __u8 flags;
112 __u8 reserved[5];
Dan Williams62232e452015-06-08 14:27:06 -0400113 __u32 status;
Dan Williams4577b062016-02-17 13:08:58 -0800114 __u32 scrub_time;
Dan Williams62232e452015-06-08 14:27:06 -0400115} __packed;
116
117struct nd_cmd_ars_status {
118 __u32 status;
119 __u32 out_length;
120 __u64 address;
121 __u64 length;
Dan Williams4577b062016-02-17 13:08:58 -0800122 __u64 restart_address;
123 __u64 restart_length;
Dan Williams62232e452015-06-08 14:27:06 -0400124 __u16 type;
Dan Williams4577b062016-02-17 13:08:58 -0800125 __u16 flags;
Dan Williams62232e452015-06-08 14:27:06 -0400126 __u32 num_records;
127 struct nd_ars_record {
128 __u32 handle;
Dan Williams4577b062016-02-17 13:08:58 -0800129 __u32 reserved;
Dan Williams62232e452015-06-08 14:27:06 -0400130 __u64 err_address;
Vishal Vermaec927772015-07-09 13:25:35 -0600131 __u64 length;
Dan Williams62232e452015-06-08 14:27:06 -0400132 } __packed records[0];
133} __packed;
134
Dan Williamsd4f32362016-03-03 16:08:54 -0800135struct nd_cmd_clear_error {
136 __u64 address;
137 __u64 length;
138 __u32 status;
139 __u8 reserved[4];
140 __u64 cleared;
141} __packed;
142
Dan Williams62232e452015-06-08 14:27:06 -0400143enum {
144 ND_CMD_IMPLEMENTED = 0,
145
146 /* bus commands */
147 ND_CMD_ARS_CAP = 1,
148 ND_CMD_ARS_START = 2,
149 ND_CMD_ARS_STATUS = 3,
Dan Williamsd4f32362016-03-03 16:08:54 -0800150 ND_CMD_CLEAR_ERROR = 4,
Dan Williams62232e452015-06-08 14:27:06 -0400151
152 /* per-dimm commands */
153 ND_CMD_SMART = 1,
154 ND_CMD_SMART_THRESHOLD = 2,
155 ND_CMD_DIMM_FLAGS = 3,
156 ND_CMD_GET_CONFIG_SIZE = 4,
157 ND_CMD_GET_CONFIG_DATA = 5,
158 ND_CMD_SET_CONFIG_DATA = 6,
159 ND_CMD_VENDOR_EFFECT_LOG_SIZE = 7,
160 ND_CMD_VENDOR_EFFECT_LOG = 8,
161 ND_CMD_VENDOR = 9,
162};
163
Vishal Verma39c686b2015-07-09 13:25:36 -0600164enum {
165 ND_ARS_VOLATILE = 1,
166 ND_ARS_PERSISTENT = 2,
167};
168
Dan Williams62232e452015-06-08 14:27:06 -0400169static inline const char *nvdimm_bus_cmd_name(unsigned cmd)
170{
171 static const char * const names[] = {
172 [ND_CMD_ARS_CAP] = "ars_cap",
173 [ND_CMD_ARS_START] = "ars_start",
174 [ND_CMD_ARS_STATUS] = "ars_status",
Dan Williamsd4f32362016-03-03 16:08:54 -0800175 [ND_CMD_CLEAR_ERROR] = "clear_error",
Dan Williams62232e452015-06-08 14:27:06 -0400176 };
177
178 if (cmd < ARRAY_SIZE(names) && names[cmd])
179 return names[cmd];
180 return "unknown";
181}
182
183static inline const char *nvdimm_cmd_name(unsigned cmd)
184{
185 static const char * const names[] = {
186 [ND_CMD_SMART] = "smart",
187 [ND_CMD_SMART_THRESHOLD] = "smart_thresh",
188 [ND_CMD_DIMM_FLAGS] = "flags",
189 [ND_CMD_GET_CONFIG_SIZE] = "get_size",
190 [ND_CMD_GET_CONFIG_DATA] = "get_data",
191 [ND_CMD_SET_CONFIG_DATA] = "set_data",
192 [ND_CMD_VENDOR_EFFECT_LOG_SIZE] = "effect_size",
193 [ND_CMD_VENDOR_EFFECT_LOG] = "effect_log",
194 [ND_CMD_VENDOR] = "vendor",
195 };
196
197 if (cmd < ARRAY_SIZE(names) && names[cmd])
198 return names[cmd];
199 return "unknown";
200}
201
202#define ND_IOCTL 'N'
203
204#define ND_IOCTL_SMART _IOWR(ND_IOCTL, ND_CMD_SMART,\
205 struct nd_cmd_smart)
206
207#define ND_IOCTL_SMART_THRESHOLD _IOWR(ND_IOCTL, ND_CMD_SMART_THRESHOLD,\
208 struct nd_cmd_smart_threshold)
209
210#define ND_IOCTL_DIMM_FLAGS _IOWR(ND_IOCTL, ND_CMD_DIMM_FLAGS,\
211 struct nd_cmd_dimm_flags)
212
213#define ND_IOCTL_GET_CONFIG_SIZE _IOWR(ND_IOCTL, ND_CMD_GET_CONFIG_SIZE,\
214 struct nd_cmd_get_config_size)
215
216#define ND_IOCTL_GET_CONFIG_DATA _IOWR(ND_IOCTL, ND_CMD_GET_CONFIG_DATA,\
217 struct nd_cmd_get_config_data_hdr)
218
219#define ND_IOCTL_SET_CONFIG_DATA _IOWR(ND_IOCTL, ND_CMD_SET_CONFIG_DATA,\
220 struct nd_cmd_set_config_hdr)
221
222#define ND_IOCTL_VENDOR _IOWR(ND_IOCTL, ND_CMD_VENDOR,\
223 struct nd_cmd_vendor_hdr)
224
225#define ND_IOCTL_ARS_CAP _IOWR(ND_IOCTL, ND_CMD_ARS_CAP,\
226 struct nd_cmd_ars_cap)
227
228#define ND_IOCTL_ARS_START _IOWR(ND_IOCTL, ND_CMD_ARS_START,\
229 struct nd_cmd_ars_start)
230
231#define ND_IOCTL_ARS_STATUS _IOWR(ND_IOCTL, ND_CMD_ARS_STATUS,\
232 struct nd_cmd_ars_status)
233
Dan Williamsd4f32362016-03-03 16:08:54 -0800234#define ND_IOCTL_CLEAR_ERROR _IOWR(ND_IOCTL, ND_CMD_CLEAR_ERROR,\
235 struct nd_cmd_clear_error)
236
Dan Williams4d88a972015-05-31 14:41:48 -0400237#define ND_DEVICE_DIMM 1 /* nd_dimm: container for "config data" */
Dan Williams3d880022015-05-31 15:02:11 -0400238#define ND_DEVICE_REGION_PMEM 2 /* nd_region: (parent of PMEM namespaces) */
239#define ND_DEVICE_REGION_BLK 3 /* nd_region: (parent of BLK namespaces) */
240#define ND_DEVICE_NAMESPACE_IO 4 /* legacy persistent memory */
241#define ND_DEVICE_NAMESPACE_PMEM 5 /* PMEM namespace (may alias with BLK) */
242#define ND_DEVICE_NAMESPACE_BLK 6 /* BLK namespace (may alias with PMEM) */
Dan Williams4d88a972015-05-31 14:41:48 -0400243
244enum nd_driver_flags {
245 ND_DRIVER_DIMM = 1 << ND_DEVICE_DIMM,
Dan Williams3d880022015-05-31 15:02:11 -0400246 ND_DRIVER_REGION_PMEM = 1 << ND_DEVICE_REGION_PMEM,
247 ND_DRIVER_REGION_BLK = 1 << ND_DEVICE_REGION_BLK,
248 ND_DRIVER_NAMESPACE_IO = 1 << ND_DEVICE_NAMESPACE_IO,
249 ND_DRIVER_NAMESPACE_PMEM = 1 << ND_DEVICE_NAMESPACE_PMEM,
250 ND_DRIVER_NAMESPACE_BLK = 1 << ND_DEVICE_NAMESPACE_BLK,
Dan Williams4d88a972015-05-31 14:41:48 -0400251};
Dan Williamsbf9bccc2015-06-17 17:14:46 -0400252
253enum {
254 ND_MIN_NAMESPACE_SIZE = 0x00400000,
255};
Vishal Verma39c686b2015-07-09 13:25:36 -0600256
257enum ars_masks {
258 ARS_STATUS_MASK = 0x0000FFFF,
259 ARS_EXT_STATUS_SHIFT = 16,
260};
Dan Williams62232e452015-06-08 14:27:06 -0400261#endif /* __NDCTL_H__ */