smartmontools SVN Rev 5597
Utility to control and monitor storage systems with "S.M.A.R.T."
nvmecmds.h
Go to the documentation of this file.
1/*
2 * nvmecmds.h
3 *
4 * Home page of code is: https://www.smartmontools.org
5 *
6 * Copyright (C) 2016-23 Christian Franke
7 *
8 * Original code from <linux/nvme.h>:
9 * Copyright (C) 2011-2014 Intel Corporation
10 *
11 * SPDX-License-Identifier: GPL-2.0-or-later
12 */
13
14#ifndef NVMECMDS_H
15#define NVMECMDS_H
16
17#define NVMECMDS_H_CVSID "$Id: nvmecmds.h 5471 2023-05-29 12:22:41Z chrfranke $"
18
19#include "static_assert.h"
20
21#include <errno.h>
22#include <stddef.h>
23#include <stdint.h>
24
25// The code below was originally imported from <linux/nvme.h> include file from
26// Linux kernel sources. Types from <linux/types.h> were replaced.
27// Symbol names are unchanged but placed in a namespace to allow inclusion
28// of the original <linux/nvme.h>.
29namespace smartmontools {
30
31////////////////////////////////////////////////////////////////////////////
32// BEGIN: From <linux/nvme.h>
33
35 uint64_t error_count;
36 unsigned short sqid;
37 unsigned short cmdid;
38 unsigned short status_field;
39 unsigned short parm_error_location;
40 uint64_t lba;
41 unsigned int nsid;
42 unsigned char vs;
43 unsigned char resv[35];
44};
46
48 unsigned short max_power; // centiwatts
49 unsigned char rsvd2;
50 unsigned char flags;
51 unsigned int entry_lat; // microseconds
52 unsigned int exit_lat; // microseconds
53 unsigned char read_tput;
54 unsigned char read_lat;
55 unsigned char write_tput;
56 unsigned char write_lat;
57 unsigned short idle_power;
58 unsigned char idle_scale;
59 unsigned char rsvd19;
60 unsigned short active_power;
61 unsigned char active_work_scale;
62 unsigned char rsvd23[9];
63};
65
67 unsigned short vid;
68 unsigned short ssvid;
69 char sn[20];
70 char mn[40];
71 char fr[8];
72 unsigned char rab;
73 unsigned char ieee[3];
74 unsigned char cmic;
75 unsigned char mdts;
76 unsigned short cntlid;
77 unsigned int ver;
78 unsigned int rtd3r;
79 unsigned int rtd3e;
80 unsigned int oaes;
81 unsigned int ctratt;
82 unsigned char rsvd100[156];
83 unsigned short oacs;
84 unsigned char acl;
85 unsigned char aerl;
86 unsigned char frmw;
87 unsigned char lpa;
88 unsigned char elpe;
89 unsigned char npss;
90 unsigned char avscc;
91 unsigned char apsta;
92 unsigned short wctemp;
93 unsigned short cctemp;
94 unsigned short mtfa;
95 unsigned int hmpre;
96 unsigned int hmmin;
97 unsigned char tnvmcap[16];
98 unsigned char unvmcap[16];
99 unsigned int rpmbs;
100 unsigned short edstt;
101 unsigned char dsto;
102 unsigned char fwug;
103 unsigned short kas;
104 unsigned short hctma;
105 unsigned short mntmt;
106 unsigned short mxtmt;
107 unsigned int sanicap;
108 unsigned char rsvd332[180];
109 unsigned char sqes;
110 unsigned char cqes;
111 unsigned short maxcmd;
112 unsigned int nn;
113 unsigned short oncs;
114 unsigned short fuses;
115 unsigned char fna;
116 unsigned char vwc;
117 unsigned short awun;
118 unsigned short awupf;
119 unsigned char nvscc;
120 unsigned char rsvd531;
121 unsigned short acwu;
122 unsigned char rsvd534[2];
123 unsigned int sgls;
124 unsigned char rsvd540[228];
125 char subnqn[256];
126 unsigned char rsvd1024[768];
127 unsigned int ioccsz;
128 unsigned int iorcsz;
129 unsigned short icdoff;
130 unsigned char ctrattr;
131 unsigned char msdbd;
132 unsigned char rsvd1804[244];
134 unsigned char vs[1024];
135};
137
138struct nvme_lbaf {
139 unsigned short ms;
140 unsigned char ds;
141 unsigned char rp;
142};
144
146 uint64_t nsze;
147 uint64_t ncap;
148 uint64_t nuse;
149 unsigned char nsfeat;
150 unsigned char nlbaf;
151 unsigned char flbas;
152 unsigned char mc;
153 unsigned char dpc;
154 unsigned char dps;
155 unsigned char nmic;
156 unsigned char rescap;
157 unsigned char fpi;
158 unsigned char rsvd33;
159 unsigned short nawun;
160 unsigned short nawupf;
161 unsigned short nacwu;
162 unsigned short nabsn;
163 unsigned short nabo;
164 unsigned short nabspf;
165 unsigned char rsvd46[2];
166 unsigned char nvmcap[16];
167 unsigned char rsvd64[40];
168 unsigned char nguid[16];
169 unsigned char eui64[8];
170 struct nvme_lbaf lbaf[16];
171 unsigned char rsvd192[192];
172 unsigned char vs[3712];
173};
174STATIC_ASSERT(sizeof(nvme_id_ns) == 4096);
175
177 unsigned char critical_warning;
178 unsigned char temperature[2];
179 unsigned char avail_spare;
180 unsigned char spare_thresh;
181 unsigned char percent_used;
182 unsigned char rsvd6[26];
183 unsigned char data_units_read[16];
184 unsigned char data_units_written[16];
185 unsigned char host_reads[16];
186 unsigned char host_writes[16];
187 unsigned char ctrl_busy_time[16];
188 unsigned char power_cycles[16];
189 unsigned char power_on_hours[16];
190 unsigned char unsafe_shutdowns[16];
191 unsigned char media_errors[16];
192 unsigned char num_err_log_entries[16];
193 unsigned int warning_temp_time;
194 unsigned int critical_comp_time;
195 unsigned short temp_sensor[8];
200 unsigned char rsvd232[280];
201};
203
205//nvme_admin_delete_sq = 0x00,
206//nvme_admin_create_sq = 0x01,
208//nvme_admin_delete_cq = 0x04,
209//nvme_admin_create_cq = 0x05,
211//nvme_admin_abort_cmd = 0x08,
212//nvme_admin_set_features = 0x09,
213//nvme_admin_get_features = 0x0a,
214//nvme_admin_async_event = 0x0c,
215//nvme_admin_ns_mgmt = 0x0d,
216//nvme_admin_activate_fw = 0x10,
217//nvme_admin_download_fw = 0x11,
218 nvme_admin_dev_self_test = 0x14, // NVMe 1.3
219//nvme_admin_ns_attach = 0x15,
220//nvme_admin_format_nvm = 0x80,
221//nvme_admin_security_send = 0x81,
222//nvme_admin_security_recv = 0x82,
223};
224
225// END: From <linux/nvme.h>
226////////////////////////////////////////////////////////////////////////////
227
228// Figure 213 of NVM Express(TM) Base Specification, revision 2.0a, July 2021
231 uint8_t segment;
232 uint8_t valid;
233 uint8_t rsvd3;
234 uint8_t power_on_hours[8]; // unaligned LE 64
235 uint32_t nsid;
236 uint8_t lba[8]; // unaligned LE 64
238 uint8_t status_code;
239 uint8_t vendor_specific[2];
240};
242
243// Figure 212 of NVM Express(TM) Base Specification, revision 2.0a, July 2021
247 uint8_t rsvd2[2];
248 nvme_self_test_result results[20]; // [0] = newest
249};
251
252} // namespace smartmontools
253
254class nvme_device;
255
256// Print NVMe debug messages?
257extern unsigned char nvme_debugmode;
258
259// Read NVMe Identify Controller data structure.
261
262// Read NVMe Identify Namespace data structure for namespace NSID.
263bool nvme_read_id_ns(nvme_device * device, unsigned nsid, smartmontools::nvme_id_ns & id_ns);
264
265// Read NVMe log page with identifier LID.
266unsigned nvme_read_log_page(nvme_device * device, unsigned nsid, unsigned char lid,
267 void * data, unsigned size, bool lpo_sup, unsigned offset = 0);
268
269// Read NVMe Error Information Log.
271 unsigned num_entries, bool lpo_sup);
272
273// Read NVMe SMART/Health Information log.
275
276// Read NVMe Self-test Log.
277bool nvme_read_self_test_log(nvme_device * device, uint32_t nsid,
278 smartmontools::nvme_self_test_log & self_test_log);
279
280// Start Self-test
281bool nvme_self_test(nvme_device * device, uint8_t stc, uint32_t nsid);
282
283// Return true if NVMe status indicates an error.
284constexpr bool nvme_status_is_error(uint16_t status)
285 { return !!(status & 0x07ff); }
286
287// Return errno for NVMe status SCT/SC fields: 0, EINVAL or EIO.
288int nvme_status_to_errno(uint16_t status);
289
290// Return error message for NVMe status SCT/SC fields or nullptr if unknown.
291const char * nvme_status_to_str(uint16_t status);
292
293// Return error message for NVMe status SCT/SC fields or explanatory message if unknown.
294const char * nvme_status_to_info_str(char * buf, size_t bufsize, uint16_t status);
295
296// Version of above for fixed size buffers.
297template <size_t SIZE>
298inline const char * nvme_status_to_info_str(char (& buf)[SIZE], unsigned status)
299 { return nvme_status_to_info_str(buf, SIZE, status); }
300
301#endif // NVMECMDS_H
NVMe device access.
ptr_t data
Definition: megaraid.h:15
u32 size
Definition: megaraid.h:0
@ nvme_admin_identify
Definition: nvmecmds.h:210
@ nvme_admin_get_log_page
Definition: nvmecmds.h:207
@ nvme_admin_dev_self_test
Definition: nvmecmds.h:218
uint32_t nsid
bool nvme_read_self_test_log(nvme_device *device, uint32_t nsid, smartmontools::nvme_self_test_log &self_test_log)
Definition: nvmecmds.cpp:270
bool nvme_read_id_ns(nvme_device *device, unsigned nsid, smartmontools::nvme_id_ns &id_ns)
Definition: nvmecmds.cpp:169
int nvme_status_to_errno(uint16_t status)
Definition: nvmecmds.cpp:472
unsigned char nvme_debugmode
Definition: nvmecmds.cpp:27
bool nvme_read_smart_log(nvme_device *device, smartmontools::nvme_smart_log &smart_log)
Definition: nvmecmds.cpp:254
bool nvme_self_test(nvme_device *device, uint8_t stc, uint32_t nsid)
Definition: nvmecmds.cpp:285
unsigned nvme_read_error_log(nvme_device *device, smartmontools::nvme_error_log_page *error_log, unsigned num_entries, bool lpo_sup)
Definition: nvmecmds.cpp:231
constexpr bool nvme_status_is_error(uint16_t status)
Definition: nvmecmds.h:284
const char * nvme_status_to_str(uint16_t status)
Definition: nvmecmds.cpp:483
bool nvme_read_id_ctrl(nvme_device *device, smartmontools::nvme_id_ctrl &id_ctrl)
Definition: nvmecmds.cpp:132
unsigned nvme_read_log_page(nvme_device *device, unsigned nsid, unsigned char lid, void *data, unsigned size, bool lpo_sup, unsigned offset=0)
Definition: nvmecmds.cpp:208
const char * nvme_status_to_info_str(char *buf, size_t bufsize, uint16_t status)
Definition: nvmecmds.cpp:490
#define STATIC_ASSERT(x)
Definition: static_assert.h:24
unsigned short parm_error_location
Definition: nvmecmds.h:39
unsigned short wctemp
Definition: nvmecmds.h:92
unsigned short ssvid
Definition: nvmecmds.h:68
unsigned short mntmt
Definition: nvmecmds.h:105
unsigned short mxtmt
Definition: nvmecmds.h:106
unsigned short cntlid
Definition: nvmecmds.h:76
unsigned char rsvd1024[768]
Definition: nvmecmds.h:126
unsigned char vs[1024]
Definition: nvmecmds.h:134
unsigned short maxcmd
Definition: nvmecmds.h:111
unsigned short hctma
Definition: nvmecmds.h:104
unsigned char unvmcap[16]
Definition: nvmecmds.h:98
struct nvme_id_power_state psd[32]
Definition: nvmecmds.h:133
unsigned short fuses
Definition: nvmecmds.h:114
unsigned char rsvd534[2]
Definition: nvmecmds.h:122
unsigned char rsvd1804[244]
Definition: nvmecmds.h:132
unsigned short mtfa
Definition: nvmecmds.h:94
unsigned short edstt
Definition: nvmecmds.h:100
unsigned short icdoff
Definition: nvmecmds.h:129
unsigned char rsvd332[180]
Definition: nvmecmds.h:108
unsigned char rsvd100[156]
Definition: nvmecmds.h:82
unsigned char ieee[3]
Definition: nvmecmds.h:73
unsigned short vid
Definition: nvmecmds.h:67
unsigned char rsvd540[228]
Definition: nvmecmds.h:124
unsigned char tnvmcap[16]
Definition: nvmecmds.h:97
unsigned short oacs
Definition: nvmecmds.h:83
unsigned short awupf
Definition: nvmecmds.h:118
unsigned short cctemp
Definition: nvmecmds.h:93
unsigned char rsvd192[192]
Definition: nvmecmds.h:171
struct nvme_lbaf lbaf[16]
Definition: nvmecmds.h:170
unsigned char nsfeat
Definition: nvmecmds.h:149
unsigned char vs[3712]
Definition: nvmecmds.h:172
unsigned short nabspf
Definition: nvmecmds.h:164
unsigned char rsvd64[40]
Definition: nvmecmds.h:167
unsigned short nacwu
Definition: nvmecmds.h:161
unsigned short nawun
Definition: nvmecmds.h:159
unsigned short nabo
Definition: nvmecmds.h:163
unsigned char nvmcap[16]
Definition: nvmecmds.h:166
unsigned short nabsn
Definition: nvmecmds.h:162
unsigned short nawupf
Definition: nvmecmds.h:160
unsigned char rescap
Definition: nvmecmds.h:156
unsigned char nlbaf
Definition: nvmecmds.h:150
unsigned char flbas
Definition: nvmecmds.h:151
unsigned char rsvd33
Definition: nvmecmds.h:158
unsigned char nguid[16]
Definition: nvmecmds.h:168
unsigned char rsvd46[2]
Definition: nvmecmds.h:165
unsigned char eui64[8]
Definition: nvmecmds.h:169
unsigned char nmic
Definition: nvmecmds.h:155
unsigned short ms
Definition: nvmecmds.h:139
unsigned char ds
Definition: nvmecmds.h:140
unsigned char rp
Definition: nvmecmds.h:141
nvme_self_test_result results[20]
Definition: nvmecmds.h:248
unsigned char data_units_read[16]
Definition: nvmecmds.h:183
unsigned char spare_thresh
Definition: nvmecmds.h:180
unsigned char critical_warning
Definition: nvmecmds.h:177
unsigned char host_writes[16]
Definition: nvmecmds.h:186
unsigned char data_units_written[16]
Definition: nvmecmds.h:184
unsigned char power_on_hours[16]
Definition: nvmecmds.h:189
unsigned int thm_temp1_total_time
Definition: nvmecmds.h:198
unsigned char host_reads[16]
Definition: nvmecmds.h:185
unsigned char temperature[2]
Definition: nvmecmds.h:178
unsigned char power_cycles[16]
Definition: nvmecmds.h:188
unsigned char rsvd232[280]
Definition: nvmecmds.h:200
unsigned char media_errors[16]
Definition: nvmecmds.h:191
unsigned char percent_used
Definition: nvmecmds.h:181
unsigned int critical_comp_time
Definition: nvmecmds.h:194
unsigned char rsvd6[26]
Definition: nvmecmds.h:182
unsigned char num_err_log_entries[16]
Definition: nvmecmds.h:192
unsigned short temp_sensor[8]
Definition: nvmecmds.h:195
unsigned char unsafe_shutdowns[16]
Definition: nvmecmds.h:190
unsigned char ctrl_busy_time[16]
Definition: nvmecmds.h:187
unsigned int thm_temp2_total_time
Definition: nvmecmds.h:199
unsigned int thm_temp2_trans_count
Definition: nvmecmds.h:197
unsigned int warning_temp_time
Definition: nvmecmds.h:193
unsigned int thm_temp1_trans_count
Definition: nvmecmds.h:196