]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - nvmecmds.h
Closes #831504
[mirror_smartmontools-debian.git] / nvmecmds.h
1 /*
2 * nvmecmds.h
3 *
4 * Home page of code is: http://www.smartmontools.org
5 *
6 * Copyright (C) 2016 Christian Franke
7 *
8 * Original code from <linux/nvme.h>:
9 * Copyright (C) 2011-2014 Intel Corporation
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2, or (at your option)
14 * any later version.
15 *
16 * You should have received a copy of the GNU General Public License
17 * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
21 #ifndef NVMECMDS_H
22 #define NVMECMDS_H
23
24 #define NVMECMDS_H_CVSID "$Id: nvmecmds.h 4297 2016-04-16 16:48:01Z chrfranke $"
25
26 #include "int64.h"
27
28 // The code below was orginally imported from <linux/nvme.h> include file from
29 // Linux kernel sources. Types from <linux/types.h> were replaced.
30 // Symbol names are unchanged but placed in a namespace to allow inclusion
31 // of the original <linux/nvme.h>.
32 namespace smartmontools {
33
34 ////////////////////////////////////////////////////////////////////////////
35 // BEGIN: From <linux/nvme.h>
36 /*
37 * Definitions for the NVM Express interface
38 * Copyright (c) 2011-2014, Intel Corporation.
39 *
40 * This program is free software; you can redistribute it and/or modify it
41 * under the terms and conditions of the GNU General Public License,
42 * version 2, as published by the Free Software Foundation.
43 *
44 * This program is distributed in the hope it will be useful, but WITHOUT
45 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
46 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
47 * more details.
48 */
49
50 struct nvme_error_log_page {
51 uint64_t error_count;
52 unsigned short sqid;
53 unsigned short cmdid;
54 unsigned short status_field;
55 unsigned short parm_error_location;
56 uint64_t lba;
57 unsigned int nsid;
58 unsigned char vs;
59 unsigned char resv[35];
60 };
61
62 struct nvme_id_power_state {
63 unsigned short max_power; // centiwatts
64 unsigned char rsvd2;
65 unsigned char flags;
66 unsigned int entry_lat; // microseconds
67 unsigned int exit_lat; // microseconds
68 unsigned char read_tput;
69 unsigned char read_lat;
70 unsigned char write_tput;
71 unsigned char write_lat;
72 unsigned short idle_power;
73 unsigned char idle_scale;
74 unsigned char rsvd19;
75 unsigned short active_power;
76 unsigned char active_work_scale;
77 unsigned char rsvd23[9];
78 };
79
80 struct nvme_id_ctrl {
81 unsigned short vid;
82 unsigned short ssvid;
83 char sn[20];
84 char mn[40];
85 char fr[8];
86 unsigned char rab;
87 unsigned char ieee[3];
88 unsigned char cmic;
89 unsigned char mdts;
90 unsigned short cntlid;
91 unsigned int ver;
92 unsigned int rtd3r;
93 unsigned int rtd3e;
94 unsigned int oaes;
95 unsigned char rsvd96[160];
96 unsigned short oacs;
97 unsigned char acl;
98 unsigned char aerl;
99 unsigned char frmw;
100 unsigned char lpa;
101 unsigned char elpe;
102 unsigned char npss;
103 unsigned char avscc;
104 unsigned char apsta;
105 unsigned short wctemp;
106 unsigned short cctemp;
107 unsigned short mtfa;
108 unsigned int hmpre;
109 unsigned int hmmin;
110 unsigned char tnvmcap[16];
111 unsigned char unvmcap[16];
112 unsigned int rpmbs;
113 unsigned char rsvd316[196];
114 unsigned char sqes;
115 unsigned char cqes;
116 unsigned char rsvd514[2];
117 unsigned int nn;
118 unsigned short oncs;
119 unsigned short fuses;
120 unsigned char fna;
121 unsigned char vwc;
122 unsigned short awun;
123 unsigned short awupf;
124 unsigned char nvscc;
125 unsigned char rsvd531;
126 unsigned short acwu;
127 unsigned char rsvd534[2];
128 unsigned int sgls;
129 unsigned char rsvd540[1508];
130 struct nvme_id_power_state psd[32];
131 unsigned char vs[1024];
132 };
133
134 struct nvme_lbaf {
135 unsigned short ms;
136 unsigned char ds;
137 unsigned char rp;
138 };
139
140 struct nvme_id_ns {
141 uint64_t nsze;
142 uint64_t ncap;
143 uint64_t nuse;
144 unsigned char nsfeat;
145 unsigned char nlbaf;
146 unsigned char flbas;
147 unsigned char mc;
148 unsigned char dpc;
149 unsigned char dps;
150 unsigned char nmic;
151 unsigned char rescap;
152 unsigned char fpi;
153 unsigned char rsvd33;
154 unsigned short nawun;
155 unsigned short nawupf;
156 unsigned short nacwu;
157 unsigned short nabsn;
158 unsigned short nabo;
159 unsigned short nabspf;
160 unsigned char rsvd46[2];
161 unsigned char nvmcap[16];
162 unsigned char rsvd64[40];
163 unsigned char nguid[16];
164 unsigned char eui64[8];
165 struct nvme_lbaf lbaf[16];
166 unsigned char rsvd192[192];
167 unsigned char vs[3712];
168 };
169
170 struct nvme_smart_log {
171 unsigned char critical_warning;
172 unsigned char temperature[2];
173 unsigned char avail_spare;
174 unsigned char spare_thresh;
175 unsigned char percent_used;
176 unsigned char rsvd6[26];
177 unsigned char data_units_read[16];
178 unsigned char data_units_written[16];
179 unsigned char host_reads[16];
180 unsigned char host_writes[16];
181 unsigned char ctrl_busy_time[16];
182 unsigned char power_cycles[16];
183 unsigned char power_on_hours[16];
184 unsigned char unsafe_shutdowns[16];
185 unsigned char media_errors[16];
186 unsigned char num_err_log_entries[16];
187 unsigned int warning_temp_time;
188 unsigned int critical_comp_time;
189 unsigned short temp_sensor[8];
190 unsigned char rsvd216[296];
191 };
192
193 enum nvme_admin_opcode {
194 //nvme_admin_delete_sq = 0x00,
195 //nvme_admin_create_sq = 0x01,
196 nvme_admin_get_log_page = 0x02,
197 //nvme_admin_delete_cq = 0x04,
198 //nvme_admin_create_cq = 0x05,
199 nvme_admin_identify = 0x06,
200 //nvme_admin_abort_cmd = 0x08,
201 //nvme_admin_set_features = 0x09,
202 //nvme_admin_get_features = 0x0a,
203 //nvme_admin_async_event = 0x0c,
204 //nvme_admin_ns_mgmt = 0x0d,
205 //nvme_admin_activate_fw = 0x10,
206 //nvme_admin_download_fw = 0x11,
207 //nvme_admin_ns_attach = 0x15,
208 //nvme_admin_format_nvm = 0x80,
209 //nvme_admin_security_send = 0x81,
210 //nvme_admin_security_recv = 0x82,
211 };
212
213 // END: From <linux/nvme.h>
214 ////////////////////////////////////////////////////////////////////////////
215
216 } // namespace smartmontools
217
218 class nvme_device;
219
220 // Print NVMe debug messages?
221 extern unsigned char nvme_debugmode;
222
223 // Read NVMe Identify Controller data structure.
224 bool nvme_read_id_ctrl(nvme_device * device, smartmontools::nvme_id_ctrl & id_ctrl);
225
226 // Read NVMe Identify Namespace data structure for namespace NSID.
227 bool nvme_read_id_ns(nvme_device * device, unsigned nsid, smartmontools::nvme_id_ns & id_ns);
228
229 // Read NVMe log page with identifier LID.
230 bool nvme_read_log_page(nvme_device * device, unsigned char lid, void * data, unsigned size);
231
232 // Read NVMe Error Information Log.
233 bool nvme_read_error_log(nvme_device * device, smartmontools::nvme_error_log_page * error_log,
234 unsigned num_entries);
235
236 // Read NVMe SMART/Health Information log.
237 bool nvme_read_smart_log(nvme_device * device, smartmontools::nvme_smart_log & smart_log);
238
239 #endif // NVMECMDS_H