]> git.proxmox.com Git - mirror_smartmontools-debian.git/blob - ataidentify.cpp
c56ba888a31190c7bb2762f1f515dac14a068de4
[mirror_smartmontools-debian.git] / ataidentify.cpp
1 /*
2 * ataidentify.cpp
3 *
4 * Home page of code is: http://www.smartmontools.org
5 *
6 * Copyright (C) 2012-17 Christian Franke
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2, or (at your option)
11 * any later version.
12 *
13 * You should have received a copy of the GNU General Public License
14 * (for example COPYING); If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17
18 #include "config.h"
19 #include "ataidentify.h"
20
21 const char * ataidentify_cpp_cvsid = "$Id: ataidentify.cpp 4573 2017-10-29 15:13:58Z chrfranke $"
22 ATAIDENTIFY_H_CVSID;
23
24 #include "int64.h"
25 #include "utility.h"
26
27
28 // Table 12 of X3T10/0948D (ATA-2) Revision 4c, March 18, 1996
29 // Table 9 of X3T13/2008D (ATA-3) Revision 7b, January 27, 1997
30 // Tables 11 and 13 of T13/1153D (ATA/ATAPI-4) revision 18, August 19, 1998
31 // Tables 20 and 22 of T13/1321D (ATA/ATAPI-5) Revision 3, February 29, 2000
32 // Tables 27 and 29 of T13/1410D (ATA/ATAPI-6) Revision 3b, February 26, 2002
33 // Tables 16 and 18 of T13/1532D (ATA/ATAPI-7) Volume 1 Revision 4b, April 21, 2004
34 // Tables 29 and 39 of T13/1699-D (ATA8-ACS) Revision 6a, September 6, 2008
35 // Tables 50 and 61 of T13/2015-D (ACS-2) Revision 7, June 22, 2011
36 // Tables 45 and 50 of T13/2161-D (ACS-3) Revision 5, October 28, 2013
37 // Table 55 of T13/BSR INCITS 529 (ACS-4) Revision 20, October 26, 2017 (ATAPI removed)
38
39 const char * const identify_descriptions[] = {
40 " 0 General configuration",
41 ". 15 Device identifier: 0 = ATA, 1 = ATAPI",
42 ". 14:8 ATA: Vendor specific [RET-3]",
43 ". 14 ATAPI: Must be set to 0",
44 ". 13 ATAPI: Reserved",
45 ". 12:8 ATAPI: Command set: 0x05 = CD/DVD",
46 ". 7 Removable media device [OBS-8]",
47 ". 6 ATA: Not removable controller and/or device [OBS-6]",
48 ". 5:3 ATA: Vendor specific [RET-3]",
49 ". 6:5 ATAPI: DRQ after PACKET cmd: 0x0 = 3ms, 0x2 = 50us",
50 ". 4:3 ATAPI: Reserved",
51 ". 2 Response incomplete",
52 ". 1 ATA: Vendor specific [RET-3]",
53 ". 0 ATA: Reserved",
54 ". 1:0 ATAPI: Packet size: 0x0 = 12 byte, 0x1 = 16 byte",
55
56 " 1 Cylinders [OBS-6]",
57 " 2 Specific configuration (0x37c8/738c/8c73/c837)",
58 " 3 Heads [OBS-6]",
59 " 4 Vendor specific [RET-3]",
60 " 5 Vendor specific [RET-3]",
61 " 6 Sectors per track [OBS-6]",
62 " 7-8 Reserved for CFA (Sectors per card)",
63 " 9 Vendor specific [RET-4]",
64 " 10-19 Serial number (String)",
65 " 20 Vendor specific [RET-3]",
66 " 21 Vendor specific [RET-3]",
67 " 22 Vendor specific bytes on READ/WRITE LONG [OBS-4]",
68 " 23-26 Firmware revision (String)",
69 " 27-46 Model number (String)",
70
71 " 47 READ/WRITE MULTIPLE support",
72 ". 15:8 Must be set to 0x80",
73 ". 7:0 Maximum sectors per DRQ on READ/WRITE MULTIPLE",
74
75 " 48 Trusted Computing feature set options",
76 ". 15:14 Must be set to 0x1",
77 ". 13:1 Reserved for the Trusted Computing Group",
78 ". 0 Trusted Computing feature set supported",
79
80 " 49 Capabilities",
81 ". 15:14 ATA: Reserved for IDENTIFY PACKET DEVICE",
82 ". 15 ATAPI: Interleaved DMA supported [OBS-8]",
83 ". 14 ATAPI: Command queuing supported [OBS-8]",
84 ". 13 ATA: Standard standby timer values supported",
85 ". 13 ATAPI: Overlap operation supported [OBS-8]",
86 ". 12 ATA: Reserved for IDENTIFY PACKET DEVICE",
87 ". 12 ATAPI: ATA software reset required [OBS-5]",
88 ". 11 IORDY supported",
89 ". 10 IORDY may be disabled",
90 ". 9 LBA supported",
91 ". 8 DMA supported",
92 ". 7:2 Reserved", // ATA-3: Vendor specific, ATA-8: Retired
93 ". 1:0 Long Phy Sector Alignment Error reporting", // ACS-2
94
95 " 50 Capabilities",
96 ". 15:14 Must be set to 0x1",
97 ". 13:2 Reserved",
98 ". 1 Reserved [OBS-6]",
99 ". 0 Vendor specific minimum standby timer value",
100
101 " 51 PIO data transfer mode [OBS-5]",
102 " 52 Single Word DMA data transfer mode [OBS-3]",
103
104 " 53 Field validity / Free-fall Control",
105 ". 15:8 Free-fall Control sensitivity",
106 ". 7:3 Reserved",
107 ". 2 Word 88 (Ultra DMA modes) is valid",
108 ". 1 Words 64-70 (PIO modes) are valid",
109 ". 0 Words 54-58 (CHS) are valid [OBS-6]",
110
111 " 54 Current cylinders [OBS-6]",
112 " 55 Current heads [OBS-6]",
113 " 56 Current sectors per track [OBS-6]",
114 " 57-58 Current capacity in sectors (DWord) [OBS-6]",
115
116 " 59 Sanitize Device - READ/WRITE MULTIPLE support",
117 ". 15 BLOCK ERASE EXT supported",
118 ". 14 OVERWRITE EXT supported",
119 ". 13 CRYPTO SCRAMBLE EXT supported",
120 ". 12 Sanitize Device feature set supported",
121 ". 11 Cmds during sanitize as specified by this standard", // ACS-3
122 ". 10 SANITIZE ANTIFREEZE LOCK EXT supported", // ACS-3
123 ". 9 Reserved",
124 ". 8 Bits 7:0 are valid [OBS-ACS-4]",
125 ". 7:0 Current number of sectors per DRQ [OBS-ACS-4]",
126
127 " 60-61 User addressable sectors for 28-bit commands (DWord)",
128 " 62 Single Word DMA modes [OBS-3]",
129
130 " 63 Multiword DMA modes",
131 ". 15:11 Reserved",
132 ". 10 Multiword DMA mode 2 selected",
133 ". 9 Multiword DMA mode 1 selected",
134 ". 8 Multiword DMA mode 0 selected",
135 ". 7:3 Reserved",
136 ". 2 Multiword DMA mode 2 and below supported",
137 ". 1 Multiword DMA mode 1 and below supported",
138 ". 0 Multiword DMA mode 0 supported",
139
140 " 64 PIO modes",
141 ". 15:2 Reserved",
142 ". 1 PIO mode 4 supported",
143 ". 0 PIO mode 3 supported",
144
145 " 65 Minimum Multiword DMA cycle time per word in ns",
146 " 66 Recommended Multiword DMA cycle time in ns",
147 " 67 Minimum PIO cycle time without flow control in ns",
148 " 68 Minimum PIO cycle time with IORDY flow control in ns",
149
150 " 69 Additional support",
151 ". 15 CFast specification supported",
152 ". 14 Deterministic data after trim supported",
153 ". 13 LPS Alignment Error Reporting Control supported",
154 ". 12 DCO IDENTIFY/SET DMA supported [OBS-ACS-3]",
155 ". 11 READ BUFFER DMA supported",
156 ". 10 WRITE BUFFER DMA supported",
157 ". 9 SET MAX SET PASSWORD/UNLOCK DMA supported [OBS-ACS-3]",
158 ". 8 DOWNLOAD MICROCODE DMA supported",
159 ". 7 Reserved for IEEE 1667",
160 ". 6 Optional ATA device 28-bit commands supported",
161 ". 5 Trimmed LBA range(s) returning zeroed data supported",
162 ". 4 Device encrypts all user data",
163 ". 3 Extended number of user addressable sectors supported",
164 ". 2 All write cache is non-volatile", // ACS-3
165 ". 1:0 Zoned Capabilities", // ACS-4
166
167 " 70 Reserved",
168 " 71-74 ATA: Reserved for IDENTIFY PACKET DEVICE",
169 " 71 ATAPI: Time in ns from PACKET to bus release [OBS-8]",
170 " 72 ATAPI: Time in ns from SERVICE to BSY cleared [OBS-8]",
171 " 73-74 ATAPI: Reserved",
172
173 " 75 Queue depth",
174 ". 15:5 Reserved",
175 ". 4:0 Maximum queue depth - 1",
176
177 " 76 Serial ATA capabilities",
178 ". 15 READ LOG DMA EXT as equiv to READ LOG EXT supported",
179 ". 14 Device Auto Partial to Slumber transitions supported",
180 ". 13 Host Auto Partial to Slumber transitions supported",
181 ". 12 NCQ priority information supported",
182 ". 11 Unload while NCQ commands are outstanding supported",
183 ". 10 Phy Event Counters supported",
184 ". 9 Receipt of host initiated PM requests supported",
185 ". 8 NCQ feature set supported",
186 ". 7:4 Reserved for Serial ATA",
187 ". 3 SATA Gen3 signaling speed (6.0 Gb/s) supported",
188 ". 2 SATA Gen2 signaling speed (3.0 Gb/s) supported",
189 ". 1 SATA Gen1 signaling speed (1.5 Gb/s) supported",
190 ". 0 Must be set to 0",
191
192 " 77 Serial ATA additional capabilities", // ACS-3
193 ". 15:9 Reserved for Serial ATA",
194 ". 8 Power Disable feature always enabled", // ACS-4
195 ". 7 DevSleep to ReducedPwrState supported", // ACS-4
196 ". 6 RECEIVE/SEND FPDMA QUEUED supported",
197 ". 5 NCQ Queue Management supported",
198 ". 4 NCQ Streaming supported",
199 ". 3:1 Current Serial ATA signal speed",
200 ". 0 Must be set to 0",
201
202 " 78 Serial ATA features supported",
203 ". 15:13 Reserved for Serial ATA",
204 ". 12 Power Disable feature supported", // ACS-4
205 ". 11 Rebuild Assist feature set supported", // ACS-4
206 ". 10 Reserved for Serial ATA",
207 ". 9 Hybrid Information supported", // ACS-4
208 ". 8 Device Sleep feature supported", // ACS-4
209 ". 7 NCQ Autosense supported", // ACS-3
210 ". 6 Software Settings Preservation supported",
211 ". 5 Hardware Feature Control supported", // ACS-3
212 ". 4 In-order data delivery supported",
213 ". 3 Device initiated power management supported",
214 ". 2 DMA Setup auto-activation supported",
215 ". 1 Non-zero buffer offsets supported",
216 ". 0 Must be set to 0",
217
218 " 79 Serial ATA features enabled",
219 ". 15:12 Reserved for Serial ATA",
220 ". 11 Rebuild Assist feature set enabled", // ACS-4
221 ". 10 Power Disable feature enabled", // ACS-4
222 ". 9 Hybrid Information enabled", // ACS-4
223 ". 8 Device Sleep feature enabled", // ACS-4
224 ". 7 Automatic Partial to Slumber transitions enabled", // ACS-3
225 ". 6 Software Settings Preservation enabled",
226 ". 5 Hardware Feature Control enabled", // ACS-3
227 ". 4 In-order data delivery enabled",
228 ". 3 Device initiated power management enabled",
229 ". 2 DMA Setup auto-activation enabled",
230 ". 1 Non-zero buffer offsets enabled",
231 ". 0 Must be set to 0",
232
233 " 80 Major version number",
234 ". 15:12 Reserved",
235 ". 11 ACS-4 supported",
236 ". 10 ACS-3 supported",
237 ". 9 ACS-2 supported",
238 ". 8 ATA8-ACS supported",
239 ". 7 ATA/ATAPI-7 supported [OBS-ACS-4]",
240 ". 6 ATA/ATAPI-6 supported [OBS-ACS-4]",
241 ". 5 ATA/ATAPI-5 supported [OBS-ACS-4]",
242 ". 4 ATA/ATAPI-4 supported [OBS-8]",
243 ". 3 ATA-3 supported [OBS-7]",
244 ". 2 ATA-2 supported [OBS-6]",
245 ". 1 ATA-1 supported [OBS-5]",
246 ". 0 Reserved",
247
248 " 81 Minor version number",
249
250 " 82 Commands and feature sets supported",
251 ". 15 IDENTIFY DEVICE DMA supported [OBS-4]", // ATA-4 r07-r14 only
252 ". 14 NOP supported",
253 ". 13 READ BUFFER supported",
254 ". 12 WRITE BUFFER supported",
255 ". 11 WRITE VERIFY supported [OBS-4]", // ATA-4 r07-r13 only
256 ". 10 HPA feature set supported [OBS-ACS-3]",
257 ". 9 DEVICE RESET supported", // ATA:0, ATAPI:1
258 ". 8 SERVICE interrupt supported [OBS-ACS-2]",
259 ". 7 Release interrupt supported [OBS-ACS-2]",
260 ". 6 Read look-ahead supported",
261 ". 5 Volatile write cache supported",
262 ". 4 PACKET feature set supported", // ATA:0, ATAPI:1
263 ". 3 Power Management feature set supported",
264 ". 2 Removable Media feature set supported [OBS-8]",
265 ". 1 Security feature set supported",
266 ". 0 SMART feature set supported",
267
268 " 83 Commands and feature sets supported",
269 ". 15:14 Must be set to 0x1",
270 ". 13 FLUSH CACHE EXT supported",
271 ". 12 FLUSH CACHE supported",
272 ". 11 DCO feature set supported [OBS-ACS-3]",
273 ". 10 48-bit Address feature set supported",
274 ". 9 AAM feature set supported [OBS-ACS-2]",
275 ". 8 SET MAX security extension supported [OBS-ACS-3]",
276 ". 7 Reserved for Addr Offset Resvd Area Boot [OBS-ACS-3]",
277 ". 6 SET FEATURES subcommand required to spin-up",
278 ". 5 PUIS feature set supported",
279 ". 4 Removable Media Status Notification supported [OBS-8]",
280 ". 3 APM feature set supported",
281 ". 2 CFA feature set supported",
282 ". 1 TCQ feature set supported [OBS-ACS-2]",
283 ". 0 DOWNLOAD MICROCODE supported",
284
285 " 84 Commands and feature sets supported",
286 ". 15:14 Must be set to 0x1",
287 ". 13 IDLE IMMEDIATE with UNLOAD feature supported",
288 ". 12:11 Reserved for TLC [OBS-ACS-3]",
289 ". 10 URG bit for WRITE STREAM (DMA) EXT supported [OBS-8]",
290 ". 9 URG bit for READ STREAM (DMA) EXT supported [OBS-8]",
291 ". 8 64-bit World Wide Name supported",
292 ". 7 WRITE DMA QUEUED FUA EXT supported [OBS-ACS-2]",
293 ". 6 WRITE DMA/MULTIPLE FUA EXT supported",
294 ". 5 GPL feature set supported",
295 ". 4 Streaming feature set supported",
296 ". 3 Media Card Pass Through Command supported [OBS-ACS-2]",
297 ". 2 Media serial number supported [RES-ACS-3]",
298 ". 1 SMART self-test supported",
299 ". 0 SMART error logging supported",
300
301 " 85 Commands and feature sets supported or enabled",
302 ". 15 IDENTIFY DEVICE DMA supported [OBS-4]", // ATA-4 r07-r14 only
303 ". 14 NOP supported",
304 ". 13 READ BUFFER supported",
305 ". 12 WRITE BUFFER supported",
306 ". 11 WRITE VERIFY supported [OBS-4]", // ATA-4 r07-r13 only
307 ". 10 HPA feature set supported [OBS-ACS-3]",
308 ". 9 DEVICE RESET supported", // ATA:0, ATAPI:1
309 ". 8 SERVICE interrupt enabled [OBS-ACS-2]",
310 ". 7 Release interrupt enabled [OBS-ACS-2]",
311 ". 6 Read look-ahead enabled",
312 ". 5 Write cache enabled",
313 ". 4 PACKET feature set supported", // ATA:0, ATAPI:1
314 ". 3 Power Management feature set supported",
315 ". 2 Removable Media feature set supported [OBS-8]",
316 ". 1 Security feature set enabled",
317 ". 0 SMART feature set enabled",
318
319 " 86 Commands and feature sets supported or enabled",
320 ". 15 Words 119-120 are valid",
321 ". 14 Reserved",
322 ". 13 FLUSH CACHE EXT supported",
323 ". 12 FLUSH CACHE supported",
324 ". 11 DCO feature set supported [OBS-ACS-3]",
325 ". 10 48-bit Address features set supported",
326 ". 9 AAM feature set enabled [OBS-ACS-2]",
327 ". 8 SET MAX security extension enabled [OBS-ACS-3]",
328 ". 7 Reserved for Addr Offset Resvd Area Boot [OBS-ACS-3]",
329 ". 6 SET FEATURES subcommand required to spin-up",
330 ". 5 PUIS feature set enabled",
331 ". 4 Removable Media Status Notification enabled [OBS-8]",
332 ". 3 APM feature set enabled",
333 ". 2 CFA feature set supported",
334 ". 1 TCQ feature set supported [OBS-ACS-2]",
335 ". 0 DOWNLOAD MICROCODE supported",
336
337 " 87 Commands and feature sets supported or enabled",
338 ". 15:14 Must be set to 0x1",
339 ". 13 IDLE IMMEDIATE with UNLOAD FEATURE supported",
340 ". 12:11 Reserved for TLC [OBS-ACS-3]",
341 ". 10 URG bit for WRITE STREAM (DMA) EXT supported [OBS-8]",
342 ". 9 URG bit for READ STREAM (DMA) EXT supported [OBS-8]",
343 ". 8 64-bit World Wide Name supported",
344 ". 7 WRITE DMA QUEUED FUA EXT supported [OBS-ACS-2]",
345 ". 6 WRITE DMA/MULTIPLE FUA EXT supported",
346 ". 5 GPL feature set supported",
347 ". 4 Valid CONFIGURE STREAM has been executed [OBS-8]",
348 ". 3 Media Card Pass Through Command supported [OBS-ACS-2]",
349 ". 2 Media serial number is valid",
350 ". 1 SMART self-test supported",
351 ". 0 SMART error logging supported",
352
353 " 88 Ultra DMA modes",
354 ". 15 Reserved",
355 ". 14 Ultra DMA mode 6 selected",
356 ". 13 Ultra DMA mode 5 selected",
357 ". 12 Ultra DMA mode 4 selected",
358 ". 11 Ultra DMA mode 3 selected",
359 ". 10 Ultra DMA mode 2 selected",
360 ". 9 Ultra DMA mode 1 selected",
361 ". 8 Ultra DMA mode 0 selected",
362 ". 7 Reserved",
363 ". 6 Ultra DMA mode 6 and below supported",
364 ". 5 Ultra DMA mode 5 and below supported",
365 ". 4 Ultra DMA mode 4 and below supported",
366 ". 3 Ultra DMA mode 3 and below supported",
367 ". 2 Ultra DMA mode 2 and below supported",
368 ". 1 Ultra DMA mode 1 and below supported",
369 ". 0 Ultra DMA mode 0 supported",
370
371 " 89 SECURITY ERASE UNIT time",
372 ". 15 Bits 14:8 of value are valid", // ACS-3
373 ". 14:0 SECURITY ERASE UNIT time value", // value*2 minutes
374
375 " 90 ENHANCED SECURITY ERASE UNIT time",
376 ". 15 Bits 14:8 of value are valid", // ACS-3
377 ". 14:0 ENHANCED SECURITY ERASE UNIT time value", // value*2 minutes
378
379 " 91 Current APM level",
380 ". 15:8 Reserved", // ACS-3
381 ". 7:0 Current APM level value",
382
383 " 92 Master Password Identifier", // ATA-7: Master Password Revision Code
384
385 " 93 Hardware reset result (PATA)",
386 ". 15:14 Must be set to 0x1",
387 ". 13 Device detected CBLID- above(1)/below(0) ViHB",
388 ". 12 Reserved",
389 ". 11 Device 1 asserted PDIAG-",
390 ". 10:9 Device 1 detection method: -, Jumper, CSEL, other",
391 ". 8 Must be set to 1",
392 ". 7 Reserved",
393 ". 6 Device 0 responds when device 1 selected",
394 ". 5 Device 0 detected the assertion of DASP-",
395 ". 4 Device 0 detected the assertion of PDIAG-",
396 ". 3 Device 0 passed diagnostics",
397 ". 2:1 Device 0 detection method: -, Jumper, CSEL, other",
398 ". 0 Must be set to 1",
399
400 " 94 AAM level [OBS-ACS-2]",
401 ". 15:8 Recommended AAM level [OBS-ACS-2]",
402 ". 7:0 Current AAM level [OBS-ACS-2]",
403
404 " 95 Stream Minimum Request Size",
405 " 96 Streaming Transfer Time - DMA",
406 " 97 Streaming Access Latency - DMA and PIO",
407 " 98-99 Streaming Performance Granularity (DWord)",
408 "100-103 User addressable sectors for 48-bit commands (QWord)",
409 "104 Streaming Transfer Time - PIO",
410 "105 Max blocks of LBA Range Entries per DS MANAGEMENT cmd",
411
412 "106 Physical sector size / logical sector size",
413 ". 15:14 Must be set to 0x1",
414 ". 13 Multiple logical sectors per physical sector",
415 ". 12 Logical Sector longer than 256 words",
416 ". 11:4 Reserved",
417 ". 3:0 2^X logical sectors per physical sector",
418
419 "107 Inter-seek delay for ISO 7779 acoustic testing",
420 "108-111 World Wide Name",
421 "112-115 Reserved", // ATA-7: Reserved for world wide name extension to 128 bits
422 "116 Reserved for TLC [OBS-ACS-3]",
423 "117-118 Logical sector size (DWord)",
424
425 "119 Commands and feature sets supported",
426 ". 15:14 Must be set to 0x1",
427 ". 13:10 Reserved",
428 ". 9 DSN feature set supported", // ACS-3
429 ". 8 Accessible Max Address Config feature set supported", // ACS-3
430 ". 7 Extended Power Conditions feature set supported",
431 ". 6 Sense Data Reporting feature set supported",
432 ". 5 Free-fall Control feature set supported",
433 ". 4 DOWNLOAD MICROCODE with mode 3 supported",
434 ". 3 READ/WRITE LOG DMA EXT supported",
435 ". 2 WRITE UNCORRECTABLE EXT supported",
436 ". 1 Write-Read-Verify feature set supported",
437 ". 0 Reserved for DDT [OBS-ACS-3]",
438
439 "120 Commands and feature sets supported or enabled",
440 ". 15:14 Must be set to 0x1",
441 ". 13:10 Reserved",
442 ". 9 DSN feature set enabled", // ACS-3
443 ". 8 Reserved",
444 ". 7 Extended Power Conditions feature set enabled",
445 ". 6 Sense Data Reporting feature set enabled",
446 ". 5 Free-fall Control feature set enabled",
447 ". 4 DOWNLOAD MICROCODE with mode 3 supported",
448 ". 3 READ/WRITE LOG DMA EXT supported",
449 ". 2 WRITE UNCORRECTABLE EXT supported",
450 ". 1 Write-Read-Verify feature set enabled",
451 ". 0 Reserved for DDT [OBS-ACS-3]",
452
453 "121-126 ATA: Reserved",
454 "121-124 ATAPI: Reserved",
455 "125 ATAPI: Byte count = 0 behavior",
456 "126 ATAPI: Byte count = 0 behavior [OBS-6]",
457
458 "127 Removable Media Status Notification [OBS-8]",
459 ". 15:1 Reserved",
460 ". 0 Removable Media Status Notification supported",
461
462 "128 Security status",
463 ". 15:9 Reserved",
464 ". 8 Master password capability: 0 = High, 1 = Maximum",
465 ". 7:6 Reserved",
466 ". 5 Enhanced security erase supported",
467 ". 4 Security count expired",
468 ". 3 Security frozen",
469 ". 2 Security locked",
470 ". 1 Security enabled",
471 ". 0 Security supported",
472
473 "129-159 Vendor specific",
474
475 "160 CFA power mode",
476 // ". 15 Word 160 supported",
477 // ". 14 Reserved",
478 // ". 13 CFA power mode 1 is required for some commands",
479 // ". 12 CFA power mode 1 disabled",
480 // ". 11:0 Maximum current in mA",
481 "161-167 Reserved for CFA",
482
483 "168 Form factor",
484 ". 15:4 Reserved",
485 ". 3:0 Nominal form factor: -, 5.25, 3.5, 2.5, 1.8, ...", // <1.8, ACS-4: mSATA, M.2, ...
486
487 "169 DATA SET MANAGEMENT command support",
488 ". 15:1 Reserved",
489 ". 0 Trim bit in DATA SET MANAGEMENT command supported",
490
491 "170-173 Additional product identifier (String)",
492 "174-175 Reserved",
493 "176-205 Current media serial number (String)",
494
495 "206 SCT Command Transport",
496 ". 15:12 Vendor specific",
497 ". 11:8 Reserved",
498 ". 7 Reserved for Serial ATA",
499 ". 6 Reserved",
500 ". 5 SCT Data Tables supported",
501 ". 4 SCT Feature Control supported",
502 ". 3 SCT Error Recovery Control supported",
503 ". 2 SCT Write Same supported",
504 ". 1 SCT Read/Write Long supported [OBS-ACS-2]",
505 ". 0 SCT Command Transport supported",
506
507 "207-208 Reserved", // ATA-8: Reserved for CE-ATA
508
509 "209 Alignment of logical sectors",
510 ". 15:14 Must be set to 0x1",
511 ". 13:0 Logical sector offset",
512
513 "210-211 Write-Read-Verify sector count mode 3 (DWord)",
514 "212-213 Write-Read-Verify sector count mode 2 (DWord)",
515
516 "214 NV Cache capabilities [OBS-ACS-3]",
517 ". 15:12 NV Cache feature set version [OBS-ACS-3]",
518 ". 11:8 NV Cache Power Mode feature set version [OBS-ACS-3]",
519 ". 7:5 Reserved [OBS-ACS-3]",
520 ". 4 NV Cache feature set enabled [OBS-ACS-3]",
521 ". 3:2 Reserved",
522 ". 1 NV Cache Power Mode feature set enabled [OBS-ACS-3]",
523 ". 0 NV Cache Power Mode feature set supported [OBS-ACS-3]",
524
525 "215-216 NV Cache size in logical blocks (DWord) [OBS-ACS-3]",
526 "217 Nominal media rotation rate",
527 "218 Reserved",
528
529 "219 NV Cache options [OBS-ACS-3]",
530 ". 15:8 Reserved [OBS-ACS-3]",
531 ". 7:0 Estimated time to spin up in seconds [OBS-ACS-3]",
532
533 "220 Write-Read-Verify mode",
534 ". 15:8 Reserved",
535 ". 7:0 Write-Read-Verify feature set current mode",
536
537 "221 Reserved",
538
539 "222 Transport major version number",
540 ". 15:12 Transport: 0x0 = Parallel, 0x1 = Serial, 0xe = PCIe", // PCIe: ACS-4
541 ". 11:9 Reserved | Reserved",
542 ". 8 Reserved | SATA 3.3", // ACS-4
543 ". 7 Reserved | SATA 3.2", // ACS-4
544 ". 6 Reserved | SATA 3.1", // ACS-3
545 ". 5 Reserved | SATA 3.0", // ACS-2
546 ". 4 Reserved | SATA 2.6",
547 ". 3 Reserved | SATA 2.5",
548 ". 2 Reserved | SATA II: Extensions",
549 ". 1 ATA/ATAPI-7 | SATA 1.0a",
550 ". 0 ATA8-APT | ATA8-AST",
551
552 "223 Transport minor version number",
553 "224-229 Reserved",
554 "230-233 Extended number of user addressable sectors (QWord)",
555 "234 Minimum blocks per DOWNLOAD MICROCODE mode 3 command",
556 "235 Maximum blocks per DOWNLOAD MICROCODE mode 3 command",
557 "236-254 Reserved",
558
559 "255 Integrity word",
560 ". 15:8 Checksum",
561 ". 7:0 Signature"
562 };
563
564 const int num_identify_descriptions = sizeof(identify_descriptions)/sizeof(identify_descriptions[0]);
565
566 static inline unsigned short get_word(const void * id, int word)
567 {
568 const unsigned char * p = ((const unsigned char *)id) + 2 * word;
569 return p[0] + (p[1] << 8);
570 }
571
572 void ata_print_identify_data(const void * id, bool all_words, int bit_level)
573 {
574 // ATA or ATAPI ?
575 unsigned short w = get_word(id, 0);
576 bool is_atapi = ((w & 0x8000) && (w != 0x848a/*CompactFlash Signature*/));
577
578 int prev_word = -1, prev_bit = -1;
579 pout("Word %s Value Description\n", (bit_level >= 0 ? "Bit " : " "));
580
581 for (int i = 0; i < num_identify_descriptions; i++) {
582 // Parse table entry
583 const char * desc = identify_descriptions[i];
584
585 int word = prev_word, word2 = -1;
586 int bit = -1, bit2 = -1;
587
588 int nc;
589 unsigned v1, v2;
590 if (word >= 0 && sscanf(desc, ". %u:%u %n", &v1, &v2, (nc=-1, &nc)) == 2 && nc > 0 && 16 > v1 && v1 > v2) {
591 bit = v1; bit2 = v2;
592 }
593 else if (word >= 0 && sscanf(desc, ". %u %n", &v1, (nc=-1, &nc)) == 1 && nc > 0 && v1 < 16) {
594 bit = v1;
595 }
596 else if (sscanf(desc, "%u-%u %n", &v1, &v2, (nc=-1, &nc)) == 2 && nc > 0 && v1 < v2 && v2 < 256) {
597 word = v1, word2 = v2;
598 }
599 else if (sscanf(desc, "%u %n", &v1, (nc=-1, &nc)) == 1 && nc > 0 && v1 < 256) {
600 word = v1;
601 }
602 else {
603 pout("Error: #%d: Syntax\n", i);
604 continue;
605 }
606 desc += nc;
607
608 // Check for ATA/ATAPI specific entries
609 if (str_starts_with(desc, "ATA: ")) {
610 if (is_atapi)
611 continue;
612 desc += sizeof("ATA: ")-1;
613 }
614 else if (str_starts_with(desc, "ATAPI: ")) {
615 if (!is_atapi)
616 continue;
617 }
618
619 // Check table entry
620 if (bit < 0) {
621 if (word != prev_word+1) {
622 pout("Error: #%d: Missing word %d\n", i, prev_word+1);
623 return;
624 }
625 else if (prev_bit > 0) {
626 pout("Error: #%d: Missing bit 0 from word %d\n", i, prev_word);
627 return;
628 }
629 }
630 else if (!((prev_bit < 0 && bit == 15) || bit == prev_bit-1)) {
631 pout("Error: #%d: Missing bit %d from word %d\n", i, bit+1, word);
632 return;
633 }
634
635 w = get_word(id, word);
636 bool w_is_set = (w != 0x0000 && w != 0xffff);
637
638 if (bit >= 0) {
639 int b;
640 if (bit2 >= 0)
641 b = (w >> bit2) & ~(~0U << (bit-bit2+1));
642 else
643 b = (w >> bit) & 1;
644
645 if ( (bit_level >= 0 && b)
646 || (bit_level >= 1 && w_is_set)
647 || (bit_level >= 2 && all_words)) {
648 if (bit2 >= 0) {
649 // Print bitfield
650 char valstr[20];
651 snprintf(valstr, sizeof(valstr), "0x%0*x", (bit - bit2 + 4) >> 2, b);
652 pout("%4d %2d:%-2d %6s %s\n", word, bit, bit2, valstr, desc);
653 }
654 else {
655 // Print bit
656 pout("%4d %2d %u %s\n", word, bit, b, desc);
657 }
658 }
659
660 prev_bit = (bit2 >= 0 ? bit2 : bit);
661 }
662 else {
663 if (word2 >= 0) {
664 for (int j = word+1; !w_is_set && j <= word2; j++) {
665 if (get_word(id, j) != w)
666 w_is_set = true;
667 }
668
669 // Print word array
670 if (all_words || w_is_set) {
671 pout("%s%4d-%-3d %s",
672 (bit_level >= 0 ? "\n" : ""), word, word2,
673 (bit_level >= 0 ? "- " : ""));
674
675 if (!w_is_set) {
676 pout("0x%02x... %s\n", w & 0xff, desc);
677 }
678 else {
679 bool is_str = !!strstr(desc, "(String)");
680 pout(". %s", desc);
681
682 for (int j = word; j <= word2; j += 4) {
683 if (j + 2*4 < word2 && !nonempty((const unsigned char *)id + 2*j, 2*(word2-j+1))) {
684 // Remaining words are null
685 pout("\n%4d-%-3d %s0x0000:0000:0000:00...", j, word2,
686 (bit_level >= 0 ? ". " : ""));
687 break;
688 }
689 // Print 4 words in a row
690 pout("\n%4d-%-3d %s0x", j, (j+3 <= word2 ? j+3 : word2),
691 (bit_level >= 0 ? ". " : ""));
692 int k;
693 for (k = 0; k < 4 && j+k <= word2; k++)
694 pout("%s%04x", (k == 0 ? "" : ":"), get_word(id, j+k));
695
696 if (is_str) {
697 // Append little endian string
698 pout("%*s \"", 20 - 5 * k, "");
699 for (k = 0; k < 4 && j+k <= word2; k++) {
700 char c2 = ((const char *)id)[2*(j+k) ];
701 char c1 = ((const char *)id)[2*(j+k) + 1];
702 pout("%c%c", (' ' <= c1 && c1 <= '~' ? c1 : '.'),
703 (' ' <= c2 && c2 <= '~' ? c2 : '.') );
704 }
705 pout("\"");
706 }
707 }
708
709 // Print decimal value of D/QWords
710 if (word + 1 == word2 && strstr(desc, "(DWord)"))
711 pout(" (%u)\n", ((unsigned)get_word(id, word2) << 16) | w);
712 else if (word + 3 == word2 && strstr(desc, "(QWord)"))
713 pout(" (%" PRIu64 ")\n", ((uint64_t)get_word(id, word + 3) << 48)
714 | ((uint64_t)get_word(id, word + 2) << 32)
715 | ((unsigned)get_word(id, word + 1) << 16) | (unsigned)w);
716 else
717 pout("\n");
718 }
719 }
720 }
721 else {
722 // Print word
723 if (all_words || w_is_set)
724 pout("%s%4d %s0x%04x %s\n",
725 (bit_level >= 0 ? "\n" : ""), word,
726 (bit_level >= 0 ? "- " : ""), w, desc);
727 }
728
729 prev_word = (word2 >= 0 ? word2 : word);
730 prev_bit = -1;
731 }
732 }
733
734 pout("\n");
735 }