Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 1 | /* |
Dan Williams | baa5127 | 2016-04-05 17:40:52 -0700 | [diff] [blame] | 2 | * Copyright (c) 2014-2016, Intel Corporation. |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 3 | * |
| 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 | |
| 18 | struct nd_cmd_smart { |
| 19 | __u32 status; |
| 20 | __u8 data[128]; |
| 21 | } __packed; |
| 22 | |
Dan Williams | baa5127 | 2016-04-05 17:40:52 -0700 | [diff] [blame] | 23 | #define ND_SMART_HEALTH_VALID (1 << 0) |
Dan Williams | 02486c2 | 2016-08-11 17:36:20 -0700 | [diff] [blame] | 24 | #define ND_SMART_SPARES_VALID (1 << 1) |
| 25 | #define ND_SMART_USED_VALID (1 << 2) |
| 26 | #define ND_SMART_TEMP_VALID (1 << 3) |
| 27 | #define ND_SMART_CTEMP_VALID (1 << 4) |
| 28 | #define ND_SMART_ALARM_VALID (1 << 9) |
| 29 | #define ND_SMART_SHUTDOWN_VALID (1 << 10) |
| 30 | #define ND_SMART_VENDOR_VALID (1 << 11) |
| 31 | #define ND_SMART_SPARE_TRIP (1 << 0) |
| 32 | #define ND_SMART_TEMP_TRIP (1 << 1) |
| 33 | #define ND_SMART_CTEMP_TRIP (1 << 2) |
Dan Williams | baa5127 | 2016-04-05 17:40:52 -0700 | [diff] [blame] | 34 | #define ND_SMART_NON_CRITICAL_HEALTH (1 << 0) |
| 35 | #define ND_SMART_CRITICAL_HEALTH (1 << 1) |
| 36 | #define ND_SMART_FATAL_HEALTH (1 << 2) |
| 37 | |
| 38 | struct nd_smart_payload { |
| 39 | __u32 flags; |
| 40 | __u8 reserved0[4]; |
| 41 | __u8 health; |
Dan Williams | baa5127 | 2016-04-05 17:40:52 -0700 | [diff] [blame] | 42 | __u8 spares; |
Dan Williams | baa5127 | 2016-04-05 17:40:52 -0700 | [diff] [blame] | 43 | __u8 life_used; |
Dan Williams | 02486c2 | 2016-08-11 17:36:20 -0700 | [diff] [blame] | 44 | __u8 alarm_flags; |
| 45 | __u16 temperature; |
| 46 | __u16 ctrl_temperature; |
| 47 | __u8 reserved1[15]; |
Dan Williams | baa5127 | 2016-04-05 17:40:52 -0700 | [diff] [blame] | 48 | __u8 shutdown_state; |
Dan Williams | baa5127 | 2016-04-05 17:40:52 -0700 | [diff] [blame] | 49 | __u32 vendor_size; |
Dan Williams | 02486c2 | 2016-08-11 17:36:20 -0700 | [diff] [blame] | 50 | __u8 vendor_data[92]; |
Dan Williams | baa5127 | 2016-04-05 17:40:52 -0700 | [diff] [blame] | 51 | } __packed; |
| 52 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 53 | struct nd_cmd_smart_threshold { |
| 54 | __u32 status; |
| 55 | __u8 data[8]; |
| 56 | } __packed; |
| 57 | |
Dan Williams | baa5127 | 2016-04-05 17:40:52 -0700 | [diff] [blame] | 58 | struct nd_smart_threshold_payload { |
Dan Williams | 02486c2 | 2016-08-11 17:36:20 -0700 | [diff] [blame] | 59 | __u8 alarm_control; |
| 60 | __u8 reserved0; |
Dan Williams | baa5127 | 2016-04-05 17:40:52 -0700 | [diff] [blame] | 61 | __u16 temperature; |
| 62 | __u8 spares; |
| 63 | __u8 reserved[3]; |
| 64 | } __packed; |
| 65 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 66 | struct nd_cmd_dimm_flags { |
| 67 | __u32 status; |
| 68 | __u32 flags; |
| 69 | } __packed; |
| 70 | |
| 71 | struct nd_cmd_get_config_size { |
| 72 | __u32 status; |
| 73 | __u32 config_size; |
| 74 | __u32 max_xfer; |
| 75 | } __packed; |
| 76 | |
| 77 | struct nd_cmd_get_config_data_hdr { |
| 78 | __u32 in_offset; |
| 79 | __u32 in_length; |
| 80 | __u32 status; |
| 81 | __u8 out_buf[0]; |
| 82 | } __packed; |
| 83 | |
| 84 | struct nd_cmd_set_config_hdr { |
| 85 | __u32 in_offset; |
| 86 | __u32 in_length; |
| 87 | __u8 in_buf[0]; |
| 88 | } __packed; |
| 89 | |
| 90 | struct nd_cmd_vendor_hdr { |
| 91 | __u32 opcode; |
| 92 | __u32 in_length; |
| 93 | __u8 in_buf[0]; |
| 94 | } __packed; |
| 95 | |
| 96 | struct nd_cmd_vendor_tail { |
| 97 | __u32 status; |
| 98 | __u32 out_length; |
| 99 | __u8 out_buf[0]; |
| 100 | } __packed; |
| 101 | |
| 102 | struct nd_cmd_ars_cap { |
| 103 | __u64 address; |
| 104 | __u64 length; |
| 105 | __u32 status; |
| 106 | __u32 max_ars_out; |
Dan Williams | 4577b06 | 2016-02-17 13:08:58 -0800 | [diff] [blame] | 107 | __u32 clear_err_unit; |
| 108 | __u32 reserved; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 109 | } __packed; |
| 110 | |
| 111 | struct nd_cmd_ars_start { |
| 112 | __u64 address; |
| 113 | __u64 length; |
| 114 | __u16 type; |
Dan Williams | 4577b06 | 2016-02-17 13:08:58 -0800 | [diff] [blame] | 115 | __u8 flags; |
| 116 | __u8 reserved[5]; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 117 | __u32 status; |
Dan Williams | 4577b06 | 2016-02-17 13:08:58 -0800 | [diff] [blame] | 118 | __u32 scrub_time; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 119 | } __packed; |
| 120 | |
| 121 | struct nd_cmd_ars_status { |
| 122 | __u32 status; |
| 123 | __u32 out_length; |
| 124 | __u64 address; |
| 125 | __u64 length; |
Dan Williams | 4577b06 | 2016-02-17 13:08:58 -0800 | [diff] [blame] | 126 | __u64 restart_address; |
| 127 | __u64 restart_length; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 128 | __u16 type; |
Dan Williams | 4577b06 | 2016-02-17 13:08:58 -0800 | [diff] [blame] | 129 | __u16 flags; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 130 | __u32 num_records; |
| 131 | struct nd_ars_record { |
| 132 | __u32 handle; |
Dan Williams | 4577b06 | 2016-02-17 13:08:58 -0800 | [diff] [blame] | 133 | __u32 reserved; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 134 | __u64 err_address; |
Vishal Verma | ec92777 | 2015-07-09 13:25:35 -0600 | [diff] [blame] | 135 | __u64 length; |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 136 | } __packed records[0]; |
| 137 | } __packed; |
| 138 | |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame] | 139 | struct nd_cmd_clear_error { |
| 140 | __u64 address; |
| 141 | __u64 length; |
| 142 | __u32 status; |
| 143 | __u8 reserved[4]; |
| 144 | __u64 cleared; |
| 145 | } __packed; |
| 146 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 147 | enum { |
| 148 | ND_CMD_IMPLEMENTED = 0, |
| 149 | |
| 150 | /* bus commands */ |
| 151 | ND_CMD_ARS_CAP = 1, |
| 152 | ND_CMD_ARS_START = 2, |
| 153 | ND_CMD_ARS_STATUS = 3, |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame] | 154 | ND_CMD_CLEAR_ERROR = 4, |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 155 | |
| 156 | /* per-dimm commands */ |
| 157 | ND_CMD_SMART = 1, |
| 158 | ND_CMD_SMART_THRESHOLD = 2, |
| 159 | ND_CMD_DIMM_FLAGS = 3, |
| 160 | ND_CMD_GET_CONFIG_SIZE = 4, |
| 161 | ND_CMD_GET_CONFIG_DATA = 5, |
| 162 | ND_CMD_SET_CONFIG_DATA = 6, |
| 163 | ND_CMD_VENDOR_EFFECT_LOG_SIZE = 7, |
| 164 | ND_CMD_VENDOR_EFFECT_LOG = 8, |
| 165 | ND_CMD_VENDOR = 9, |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 166 | ND_CMD_CALL = 10, |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 167 | }; |
| 168 | |
Vishal Verma | 39c686b | 2015-07-09 13:25:36 -0600 | [diff] [blame] | 169 | enum { |
| 170 | ND_ARS_VOLATILE = 1, |
| 171 | ND_ARS_PERSISTENT = 2, |
Dan Williams | 9d62ed9 | 2017-05-04 11:47:22 -0700 | [diff] [blame] | 172 | ND_CONFIG_LOCKED = 1, |
Vishal Verma | 39c686b | 2015-07-09 13:25:36 -0600 | [diff] [blame] | 173 | }; |
| 174 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 175 | static inline const char *nvdimm_bus_cmd_name(unsigned cmd) |
| 176 | { |
| 177 | static const char * const names[] = { |
| 178 | [ND_CMD_ARS_CAP] = "ars_cap", |
| 179 | [ND_CMD_ARS_START] = "ars_start", |
| 180 | [ND_CMD_ARS_STATUS] = "ars_status", |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame] | 181 | [ND_CMD_CLEAR_ERROR] = "clear_error", |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 182 | }; |
| 183 | |
| 184 | if (cmd < ARRAY_SIZE(names) && names[cmd]) |
| 185 | return names[cmd]; |
| 186 | return "unknown"; |
| 187 | } |
| 188 | |
| 189 | static inline const char *nvdimm_cmd_name(unsigned cmd) |
| 190 | { |
| 191 | static const char * const names[] = { |
| 192 | [ND_CMD_SMART] = "smart", |
| 193 | [ND_CMD_SMART_THRESHOLD] = "smart_thresh", |
| 194 | [ND_CMD_DIMM_FLAGS] = "flags", |
| 195 | [ND_CMD_GET_CONFIG_SIZE] = "get_size", |
| 196 | [ND_CMD_GET_CONFIG_DATA] = "get_data", |
| 197 | [ND_CMD_SET_CONFIG_DATA] = "set_data", |
| 198 | [ND_CMD_VENDOR_EFFECT_LOG_SIZE] = "effect_size", |
| 199 | [ND_CMD_VENDOR_EFFECT_LOG] = "effect_log", |
| 200 | [ND_CMD_VENDOR] = "vendor", |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 201 | [ND_CMD_CALL] = "cmd_call", |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 202 | }; |
| 203 | |
| 204 | if (cmd < ARRAY_SIZE(names) && names[cmd]) |
| 205 | return names[cmd]; |
| 206 | return "unknown"; |
| 207 | } |
| 208 | |
| 209 | #define ND_IOCTL 'N' |
| 210 | |
| 211 | #define ND_IOCTL_SMART _IOWR(ND_IOCTL, ND_CMD_SMART,\ |
| 212 | struct nd_cmd_smart) |
| 213 | |
| 214 | #define ND_IOCTL_SMART_THRESHOLD _IOWR(ND_IOCTL, ND_CMD_SMART_THRESHOLD,\ |
| 215 | struct nd_cmd_smart_threshold) |
| 216 | |
| 217 | #define ND_IOCTL_DIMM_FLAGS _IOWR(ND_IOCTL, ND_CMD_DIMM_FLAGS,\ |
| 218 | struct nd_cmd_dimm_flags) |
| 219 | |
| 220 | #define ND_IOCTL_GET_CONFIG_SIZE _IOWR(ND_IOCTL, ND_CMD_GET_CONFIG_SIZE,\ |
| 221 | struct nd_cmd_get_config_size) |
| 222 | |
| 223 | #define ND_IOCTL_GET_CONFIG_DATA _IOWR(ND_IOCTL, ND_CMD_GET_CONFIG_DATA,\ |
| 224 | struct nd_cmd_get_config_data_hdr) |
| 225 | |
| 226 | #define ND_IOCTL_SET_CONFIG_DATA _IOWR(ND_IOCTL, ND_CMD_SET_CONFIG_DATA,\ |
| 227 | struct nd_cmd_set_config_hdr) |
| 228 | |
| 229 | #define ND_IOCTL_VENDOR _IOWR(ND_IOCTL, ND_CMD_VENDOR,\ |
| 230 | struct nd_cmd_vendor_hdr) |
| 231 | |
| 232 | #define ND_IOCTL_ARS_CAP _IOWR(ND_IOCTL, ND_CMD_ARS_CAP,\ |
| 233 | struct nd_cmd_ars_cap) |
| 234 | |
| 235 | #define ND_IOCTL_ARS_START _IOWR(ND_IOCTL, ND_CMD_ARS_START,\ |
| 236 | struct nd_cmd_ars_start) |
| 237 | |
| 238 | #define ND_IOCTL_ARS_STATUS _IOWR(ND_IOCTL, ND_CMD_ARS_STATUS,\ |
| 239 | struct nd_cmd_ars_status) |
| 240 | |
Dan Williams | d4f3236 | 2016-03-03 16:08:54 -0800 | [diff] [blame] | 241 | #define ND_IOCTL_CLEAR_ERROR _IOWR(ND_IOCTL, ND_CMD_CLEAR_ERROR,\ |
| 242 | struct nd_cmd_clear_error) |
| 243 | |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 244 | #define ND_DEVICE_DIMM 1 /* nd_dimm: container for "config data" */ |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 245 | #define ND_DEVICE_REGION_PMEM 2 /* nd_region: (parent of PMEM namespaces) */ |
| 246 | #define ND_DEVICE_REGION_BLK 3 /* nd_region: (parent of BLK namespaces) */ |
| 247 | #define ND_DEVICE_NAMESPACE_IO 4 /* legacy persistent memory */ |
| 248 | #define ND_DEVICE_NAMESPACE_PMEM 5 /* PMEM namespace (may alias with BLK) */ |
| 249 | #define ND_DEVICE_NAMESPACE_BLK 6 /* BLK namespace (may alias with PMEM) */ |
Dan Williams | cd03412 | 2016-03-11 10:15:36 -0800 | [diff] [blame] | 250 | #define ND_DEVICE_DAX_PMEM 7 /* Device DAX interface to pmem */ |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 251 | |
| 252 | enum nd_driver_flags { |
| 253 | ND_DRIVER_DIMM = 1 << ND_DEVICE_DIMM, |
Dan Williams | 3d88002 | 2015-05-31 15:02:11 -0400 | [diff] [blame] | 254 | ND_DRIVER_REGION_PMEM = 1 << ND_DEVICE_REGION_PMEM, |
| 255 | ND_DRIVER_REGION_BLK = 1 << ND_DEVICE_REGION_BLK, |
| 256 | ND_DRIVER_NAMESPACE_IO = 1 << ND_DEVICE_NAMESPACE_IO, |
| 257 | ND_DRIVER_NAMESPACE_PMEM = 1 << ND_DEVICE_NAMESPACE_PMEM, |
| 258 | ND_DRIVER_NAMESPACE_BLK = 1 << ND_DEVICE_NAMESPACE_BLK, |
Dan Williams | cd03412 | 2016-03-11 10:15:36 -0800 | [diff] [blame] | 259 | ND_DRIVER_DAX_PMEM = 1 << ND_DEVICE_DAX_PMEM, |
Dan Williams | 4d88a97 | 2015-05-31 14:41:48 -0400 | [diff] [blame] | 260 | }; |
Dan Williams | bf9bccc | 2015-06-17 17:14:46 -0400 | [diff] [blame] | 261 | |
| 262 | enum { |
| 263 | ND_MIN_NAMESPACE_SIZE = 0x00400000, |
| 264 | }; |
Vishal Verma | 39c686b | 2015-07-09 13:25:36 -0600 | [diff] [blame] | 265 | |
| 266 | enum ars_masks { |
| 267 | ARS_STATUS_MASK = 0x0000FFFF, |
| 268 | ARS_EXT_STATUS_SHIFT = 16, |
| 269 | }; |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 270 | |
| 271 | /* |
| 272 | * struct nd_cmd_pkg |
| 273 | * |
| 274 | * is a wrapper to a quasi pass thru interface for invoking firmware |
| 275 | * associated with nvdimms. |
| 276 | * |
| 277 | * INPUT PARAMETERS |
| 278 | * |
| 279 | * nd_family corresponds to the firmware (e.g. DSM) interface. |
| 280 | * |
| 281 | * nd_command are the function index advertised by the firmware. |
| 282 | * |
| 283 | * nd_size_in is the size of the input parameters being passed to firmware |
| 284 | * |
| 285 | * OUTPUT PARAMETERS |
| 286 | * |
| 287 | * nd_fw_size is the size of the data firmware wants to return for |
| 288 | * the call. If nd_fw_size is greater than size of nd_size_out, only |
| 289 | * the first nd_size_out bytes are returned. |
| 290 | */ |
| 291 | |
| 292 | struct nd_cmd_pkg { |
| 293 | __u64 nd_family; /* family of commands */ |
| 294 | __u64 nd_command; |
| 295 | __u32 nd_size_in; /* INPUT: size of input args */ |
| 296 | __u32 nd_size_out; /* INPUT: size of payload */ |
| 297 | __u32 nd_reserved2[9]; /* reserved must be zero */ |
| 298 | __u32 nd_fw_size; /* OUTPUT: size fw wants to return */ |
| 299 | unsigned char nd_payload[]; /* Contents of call */ |
| 300 | }; |
| 301 | |
| 302 | /* These NVDIMM families represent pre-standardization command sets */ |
| 303 | #define NVDIMM_FAMILY_INTEL 0 |
| 304 | #define NVDIMM_FAMILY_HPE1 1 |
| 305 | #define NVDIMM_FAMILY_HPE2 2 |
stuart hayes | e02fb72 | 2016-05-26 11:38:41 -0500 | [diff] [blame] | 306 | #define NVDIMM_FAMILY_MSFT 3 |
Dan Williams | 31eca76 | 2016-04-28 16:23:43 -0700 | [diff] [blame] | 307 | |
| 308 | #define ND_IOCTL_CALL _IOWR(ND_IOCTL, ND_CMD_CALL,\ |
| 309 | struct nd_cmd_pkg) |
| 310 | |
Dan Williams | 62232e45 | 2015-06-08 14:27:06 -0400 | [diff] [blame] | 311 | #endif /* __NDCTL_H__ */ |