smartmontools  SVN Rev 4115
Utility to control and monitor storage systems with "S.M.A.R.T."
ataidentify.cpp
Go to the documentation of this file.
1 /*
2  * ataidentify.cpp
3  *
4  * Home page of code is: http://smartmontools.sourceforge.net
5  *
6  * Copyright (C) 2012-15 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 4074 2015-05-01 16:03:50Z chrfranke $"
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 44 of T13/BSR INCITS 529 (ACS-4) Revision 08, April 28, 2015 (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",
125  ". 7:0 Current sectors per DRQ on READ/WRITE MULTIPLE",
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:7 Reserved for Serial ATA",
194  ". 6 RECEIVE/SEND FPDMA QUEUED supported",
195  ". 5 NCQ Queue Management supported",
196  ". 4 NCQ Streaming supported",
197  ". 3:1 Current Serial ATA signal speed",
198  ". 0 Must be set to 0",
199 
200  " 78 Serial ATA features supported",
201  ". 15:8 Reserved for Serial ATA",
202  ". 7 NCQ Autosense supported", // ACS-3
203  ". 6 Software Settings Preservation supported",
204  ". 5 Hardware Feature Control supported", // ACS-3
205  ". 4 In-order data delivery supported",
206  ". 3 Device initiated power management supported",
207  ". 2 DMA Setup auto-activation supported",
208  ". 1 Non-zero buffer offsets supported",
209  ". 0 Must be set to 0",
210 
211  " 79 Serial ATA features enabled",
212  ". 15:8 Reserved for Serial ATA",
213  ". 7 Automatic Partial to Slumber transitions enabled", // ACS-3
214  ". 6 Software Settings Preservation enabled",
215  ". 5 Hardware Feature Control enabled", // ACS-3
216  ". 4 In-order data delivery enabled",
217  ". 3 Device initiated power management enabled",
218  ". 2 DMA Setup auto-activation enabled",
219  ". 1 Non-zero buffer offsets enabled",
220  ". 0 Must be set to 0",
221 
222  " 80 Major version number",
223  ". 15:12 Reserved",
224  ". 11 ACS-4 supported",
225  ". 10 ACS-3 supported",
226  ". 9 ACS-2 supported",
227  ". 8 ATA8-ACS supported",
228  ". 7 ATA/ATAPI-7 supported",
229  ". 6 ATA/ATAPI-6 supported",
230  ". 5 ATA/ATAPI-5 supported",
231  ". 4 ATA/ATAPI-4 supported [OBS-8]",
232  ". 3 ATA-3 supported [OBS-7]",
233  ". 2 ATA-2 supported [OBS-6]",
234  ". 1 ATA-1 supported [OBS-5]",
235  ". 0 Reserved",
236 
237  " 81 Minor version number",
238 
239  " 82 Commands and feature sets supported",
240  ". 15 IDENTIFY DEVICE DMA supported [OBS-4]", // ATA-4 r07-r14 only
241  ". 14 NOP supported",
242  ". 13 READ BUFFER supported",
243  ". 12 WRITE BUFFER supported",
244  ". 11 WRITE VERIFY supported [OBS-4]", // ATA-4 r07-r13 only
245  ". 10 HPA feature set supported [OBS-ACS-3]",
246  ". 9 DEVICE RESET supported", // ATA:0, ATAPI:1
247  ". 8 SERVICE interrupt supported [OBS-ACS-2]",
248  ". 7 Release interrupt supported [OBS-ACS-2]",
249  ". 6 Read look-ahead supported",
250  ". 5 Volatile write cache supported",
251  ". 4 PACKET feature set supported", // ATA:0, ATAPI:1
252  ". 3 Power Management feature set supported",
253  ". 2 Removable Media feature set supported [OBS-8]",
254  ". 1 Security feature set supported",
255  ". 0 SMART feature set supported",
256 
257  " 83 Commands and feature sets supported",
258  ". 15:14 Must be set to 0x1",
259  ". 13 FLUSH CACHE EXT supported",
260  ". 12 FLUSH CACHE supported",
261  ". 11 DCO feature set supported [OBS-ACS-3]",
262  ". 10 48-bit Address feature set supported",
263  ". 9 AAM feature set supported [OBS-ACS-2]",
264  ". 8 SET MAX security extension supported [OBS-ACS-3]",
265  ". 7 Reserved for Addr Offset Resvd Area Boot [OBS-ACS-3]",
266  ". 6 SET FEATURES subcommand required to spin-up",
267  ". 5 PUIS feature set supported",
268  ". 4 Removable Media Status Notification supported [OBS-8]",
269  ". 3 APM feature set supported",
270  ". 2 CFA feature set supported",
271  ". 1 TCQ feature set supported [OBS-ACS-2]",
272  ". 0 DOWNLOAD MICROCODE supported",
273 
274  " 84 Commands and feature sets supported",
275  ". 15:14 Must be set to 0x1",
276  ". 13 IDLE IMMEDIATE with UNLOAD feature supported",
277  ". 12:11 Reserved for TLC [OBS-ACS-3]",
278  ". 10 URG bit for WRITE STREAM (DMA) EXT supported [OBS-8]",
279  ". 9 URG bit for READ STREAM (DMA) EXT supported [OBS-8]",
280  ". 8 64-bit World Wide Name supported",
281  ". 7 WRITE DMA QUEUED FUA EXT supported",
282  ". 6 WRITE DMA/MULTIPLE FUA EXT supported",
283  ". 5 GPL feature set supported",
284  ". 4 Streaming feature set supported [OBS-ACS-3]",
285  ". 3 Media Card Pass Through Command supported [OBS-ACS-2]",
286  ". 2 Media serial number supported [RES-ACS-3]",
287  ". 1 SMART self-test supported",
288  ". 0 SMART error logging supported",
289 
290  " 85 Commands and feature sets supported or enabled",
291  ". 15 IDENTIFY DEVICE DMA supported [OBS-4]", // ATA-4 r07-r14 only
292  ". 14 NOP supported",
293  ". 13 READ BUFFER supported",
294  ". 12 WRITE BUFFER supported",
295  ". 11 WRITE VERIFY supported [OBS-4]", // ATA-4 r07-r13 only
296  ". 10 HPA feature set supported [OBS-ACS-3]",
297  ". 9 DEVICE RESET supported", // ATA:0, ATAPI:1
298  ". 8 SERVICE interrupt enabled [OBS-ACS-2]",
299  ". 7 Release interrupt enabled [OBS-ACS-2]",
300  ". 6 Read look-ahead enabled",
301  ". 5 Write cache enabled",
302  ". 4 PACKET feature set supported", // ATA:0, ATAPI:1
303  ". 3 Power Management feature set supported",
304  ". 2 Removable Media feature set supported [OBS-8]",
305  ". 1 Security feature set enabled",
306  ". 0 SMART feature set enabled",
307 
308  " 86 Commands and feature sets supported or enabled",
309  ". 15 Words 119-120 are valid",
310  ". 14 Reserved",
311  ". 13 FLUSH CACHE EXT supported",
312  ". 12 FLUSH CACHE supported",
313  ". 11 DCO feature set supported [OBS-ACS-3]",
314  ". 10 48-bit Address features set supported",
315  ". 9 AAM feature set enabled [OBS-ACS-2]",
316  ". 8 SET MAX security extension enabled [OBS-ACS-3]",
317  ". 7 Reserved for Addr Offset Resvd Area Boot [OBS-ACS-3]",
318  ". 6 SET FEATURES subcommand required to spin-up",
319  ". 5 PUIS feature set enabled",
320  ". 4 Removable Media Status Notification enabled [OBS-8]",
321  ". 3 APM feature set enabled",
322  ". 2 CFA feature set supported",
323  ". 1 TCQ feature set supported [OBS-ACS-2]",
324  ". 0 DOWNLOAD MICROCODE supported",
325 
326  " 87 Commands and feature sets supported or enabled",
327  ". 15:14 Must be set to 0x1",
328  ". 13 IDLE IMMEDIATE with UNLOAD FEATURE supported",
329  ". 12:11 Reserved for TLC [OBS-ACS-3]",
330  ". 10 URG bit for WRITE STREAM (DMA) EXT supported [OBS-8]",
331  ". 9 URG bit for READ STREAM (DMA) EXT supported [OBS-8]",
332  ". 8 64-bit World Wide Name supported",
333  ". 7 WRITE DMA QUEUED FUA EXT supported [OBS-ACS-2]",
334  ". 6 WRITE DMA/MULTIPLE FUA EXT supported",
335  ". 5 GPL feature set supported",
336  ". 4 Valid CONFIGURE STREAM has been executed [OBS-8]",
337  ". 3 Media Card Pass Through Command supported [OBS-ACS-2]",
338  ". 2 Media serial number is valid",
339  ". 1 SMART self-test supported",
340  ". 0 SMART error logging supported",
341 
342  " 88 Ultra DMA modes",
343  ". 15 Reserved",
344  ". 14 Ultra DMA mode 6 selected",
345  ". 13 Ultra DMA mode 5 selected",
346  ". 12 Ultra DMA mode 4 selected",
347  ". 11 Ultra DMA mode 3 selected",
348  ". 10 Ultra DMA mode 2 selected",
349  ". 9 Ultra DMA mode 1 selected",
350  ". 8 Ultra DMA mode 0 selected",
351  ". 7 Reserved",
352  ". 6 Ultra DMA mode 6 and below supported",
353  ". 5 Ultra DMA mode 5 and below supported",
354  ". 4 Ultra DMA mode 4 and below supported",
355  ". 3 Ultra DMA mode 3 and below supported",
356  ". 2 Ultra DMA mode 2 and below supported",
357  ". 1 Ultra DMA mode 1 and below supported",
358  ". 0 Ultra DMA mode 0 supported",
359 
360  " 89 SECURITY ERASE UNIT time",
361  ". 15 Bits 14:8 of value are valid", // ACS-3
362  ". 14:0 SECURITY ERASE UNIT time value", // value*2 minutes
363 
364  " 90 ENHANCED SECURITY ERASE UNIT time",
365  ". 15 Bits 14:8 of value are valid", // ACS-3
366  ". 14:0 ENHANCED SECURITY ERASE UNIT time value", // value*2 minutes
367 
368  " 91 Current APM level",
369  ". 15:8 Reserved", // ACS-3
370  ". 7:0 Current APM level value",
371 
372  " 92 Master Password Identifier", // ATA-7: Master Password Revision Code
373 
374  " 93 Hardware reset result (PATA)",
375  ". 15:14 Must be set to 0x1",
376  ". 13 Device detected CBLID- above(1)/below(0) ViHB",
377  ". 12 Reserved",
378  ". 11 Device 1 asserted PDIAG-",
379  ". 10:9 Device 1 detection method: -, Jumper, CSEL, other",
380  ". 8 Must be set to 1",
381  ". 7 Reserved",
382  ". 6 Device 0 responds when device 1 selected",
383  ". 5 Device 0 detected the assertion of DASP-",
384  ". 4 Device 0 detected the assertion of PDIAG-",
385  ". 3 Device 0 passed diagnostics",
386  ". 2:1 Device 0 detection method: -, Jumper, CSEL, other",
387  ". 0 Must be set to 1",
388 
389  " 94 AAM level [OBS-ACS-2]",
390  ". 15:8 Recommended AAM level [OBS-ACS-2]",
391  ". 7:0 Current AAM level [OBS-ACS-2]",
392 
393  " 95 Stream Minimum Request Size",
394  " 96 Streaming Transfer Time - DMA",
395  " 97 Streaming Access Latency - DMA and PIO",
396  " 98-99 Streaming Performance Granularity (DWord)",
397  "100-103 User addressable sectors for 48-bit commands (QWord)",
398  "104 Streaming Transfer Time - PIO",
399  "105 Max blocks of LBA Range Entries per DS MANAGEMENT cmd",
400 
401  "106 Physical sector size / logical sector size",
402  ". 15:14 Must be set to 0x1",
403  ". 13 Multiple logical sectors per physical sector",
404  ". 12 Logical Sector longer than 256 words",
405  ". 11:4 Reserved",
406  ". 3:0 2^X logical sectors per physical sector",
407 
408  "107 Inter-seek delay for ISO 7779 acoustic testing",
409  "108-111 64-bit World Wide Name",
410  "112-115 Reserved", // ATA-7: Reserved for world wide name extension to 128 bits
411  "116 Reserved for TLC [OBS-ACS-3]",
412  "117-118 Logical sector size (DWord)",
413 
414  "119 Commands and feature sets supported",
415  ". 15:14 Must be set to 0x1",
416  ". 13:10 Reserved",
417  ". 9 DSN feature set supported", // ACS-3
418  ". 8 Accessible Max Address Config feature set supported", // ACS-3
419  ". 7 Extended Power Conditions feature set supported",
420  ". 6 Sense Data Reporting feature set supported",
421  ". 5 Free-fall Control feature set supported",
422  ". 4 DOWNLOAD MICROCODE with mode 3 supported",
423  ". 3 READ/WRITE LOG DMA EXT supported",
424  ". 2 WRITE UNCORRECTABLE EXT supported",
425  ". 1 Write-Read-Verify feature set supported",
426  ". 0 Reserved for DDT [OBS-ACS-3]",
427 
428  "120 Commands and feature sets supported or enabled",
429  ". 15:14 Must be set to 0x1",
430  ". 13:10 Reserved",
431  ". 9 DSN feature set enabled", // ACS-3
432  ". 8 Reserved",
433  ". 7 Extended Power Conditions feature set enabled",
434  ". 6 Sense Data Reporting feature set enabled",
435  ". 5 Free-fall Control feature set enabled",
436  ". 4 DOWNLOAD MICROCODE with mode 3 supported",
437  ". 3 READ/WRITE LOG DMA EXT supported",
438  ". 2 WRITE UNCORRECTABLE EXT supported",
439  ". 1 Write-Read-Verify feature set enabled",
440  ". 0 Reserved for DDT [OBS-ACS-3]",
441 
442  "121-126 ATA: Reserved",
443  "121-124 ATAPI: Reserved",
444  "125 ATAPI: Byte count = 0 behavior",
445  "126 ATAPI: Byte count = 0 behavior [OBS-6]",
446 
447  "127 Removable Media Status Notification [OBS-8]",
448  ". 15:1 Reserved",
449  ". 0 Removable Media Status Notification supported",
450 
451  "128 Security status",
452  ". 15:9 Reserved",
453  ". 8 Master password capability: 0 = High, 1 = Maximum",
454  ". 7:6 Reserved",
455  ". 5 Enhanced security erase supported",
456  ". 4 Security count expired",
457  ". 3 Security frozen",
458  ". 2 Security locked",
459  ". 1 Security enabled",
460  ". 0 Security supported",
461 
462  "129-159 Vendor specific",
463 
464  "160 CFA power mode",
465  // ". 15 Word 160 supported",
466  // ". 14 Reserved",
467  // ". 13 CFA power mode 1 is required for some commands",
468  // ". 12 CFA power mode 1 disabled",
469  // ". 11:0 Maximum current in mA",
470  "161-167 Reserved for CFA",
471 
472  "168 Form factor",
473  ". 15:4 Reserved",
474  ". 3:0 Nominal form factor: -, 5.25, 3.5, 2.5, 1.8, <1.8",
475 
476  "169 DATA SET MANAGEMENT command support",
477  ". 15:1 Reserved",
478  ". 0 Trim bit in DATA SET MANAGEMENT command supported",
479 
480  "170-173 Additional product identifier (String)",
481  "174-175 Reserved",
482  "176-205 Current media serial number (String)",
483 
484  "206 SCT Command Transport",
485  ". 15:12 Vendor specific",
486  ". 11:8 Reserved",
487  ". 7 Reserved for Serial ATA",
488  ". 6 Reserved",
489  ". 5 SCT Data Tables supported",
490  ". 4 SCT Feature Control supported",
491  ". 3 SCT Error Recovery Control supported",
492  ". 2 SCT Write Same supported",
493  ". 1 SCT Read/Write Long supported [OBS-ACS-2]",
494  ". 0 SCT Command Transport supported",
495 
496  "207-208 Reserved", // ATA-8: Reserved for CE-ATA
497 
498  "209 Alignment of logical sectors",
499  ". 15:14 Must be set to 0x1",
500  ". 13:0 Logical sector offset",
501 
502  "210-211 Write-Read-Verify sector count mode 3 (DWord)",
503  "212-213 Write-Read-Verify sector count mode 2 (DWord)",
504 
505  "214 NV Cache capabilities [OBS-ACS-3]",
506  ". 15:12 NV Cache feature set version [OBS-ACS-3]",
507  ". 11:8 NV Cache Power Mode feature set version [OBS-ACS-3]",
508  ". 7:5 Reserved [OBS-ACS-3]",
509  ". 4 NV Cache feature set enabled [OBS-ACS-3]",
510  ". 3:2 Reserved",
511  ". 1 NV Cache Power Mode feature set enabled [OBS-ACS-3]",
512  ". 0 NV Cache Power Mode feature set supported [OBS-ACS-3]",
513 
514  "215-216 NV Cache size in logical blocks (DWord) [OBS-ACS-3]",
515  "217 Nominal media rotation rate",
516  "218 Reserved",
517 
518  "219 NV Cache options [OBS-ACS-3]",
519  ". 15:8 Reserved [OBS-ACS-3]",
520  ". 7:0 Estimated time to spin up in seconds [OBS-ACS-3]",
521 
522  "220 Write-Read-Verify mode",
523  ". 15:8 Reserved",
524  ". 7:0 Write-Read-Verify feature set current mode",
525 
526  "221 Reserved",
527 
528  "222 Transport major version number",
529  ". 15:12 Transport: 0x0 = Parallel, 0x1 = Serial, 0xe = PCIe", // PCIe: ACS-4
530  ". 11:8 Reserved | Reserved",
531  ". 7 Reserved | SATA 3.2",
532  ". 6 Reserved | SATA 3.1",
533  ". 5 Reserved | SATA 3.0",
534  ". 4 Reserved | SATA 2.6",
535  ". 3 Reserved | SATA 2.5",
536  ". 2 Reserved | SATA II: Extensions",
537  ". 1 ATA/ATAPI-7 | SATA 1.0a",
538  ". 0 ATA8-APT | ATA8-AST",
539 
540  "223 Transport minor version number",
541  "224-229 Reserved",
542  "230-233 Extended number of user addressable sectors (QWord)",
543  "234 Minimum blocks per DOWNLOAD MICROCODE mode 3 command",
544  "235 Maximum blocks per DOWNLOAD MICROCODE mode 3 command",
545  "236-254 Reserved",
546 
547  "255 Integrity word",
548  ". 15:8 Checksum",
549  ". 7:0 Signature"
550 };
551 
553 
554 static inline unsigned short get_word(const void * id, int word)
555 {
556  const unsigned char * p = ((const unsigned char *)id) + 2 * word;
557  return p[0] + (p[1] << 8);
558 }
559 
560 void ata_print_identify_data(const void * id, bool all_words, int bit_level)
561 {
562  // ATA or ATAPI ?
563  unsigned short w = get_word(id, 0);
564  bool is_atapi = ((w & 0x8000) && (w != 0x848a/*CompactFlash Signature*/));
565 
566  int prev_word = -1, prev_bit = -1;
567  pout("Word %s Value Description\n", (bit_level >= 0 ? "Bit " : " "));
568 
569  for (int i = 0; i < num_identify_descriptions; i++) {
570  // Parse table entry
571  const char * desc = identify_descriptions[i];
572 
573  int word = prev_word, word2 = -1;
574  int bit = -1, bit2 = -1;
575 
576  int nc;
577  unsigned v1, v2;
578  if (word >= 0 && sscanf(desc, ". %u:%u %n", &v1, &v2, (nc=-1, &nc)) == 2 && nc > 0 && 16 > v1 && v1 > v2) {
579  bit = v1; bit2 = v2;
580  }
581  else if (word >= 0 && sscanf(desc, ". %u %n", &v1, (nc=-1, &nc)) == 1 && nc > 0 && v1 < 16) {
582  bit = v1;
583  }
584  else if (sscanf(desc, "%u-%u %n", &v1, &v2, (nc=-1, &nc)) == 2 && nc > 0 && v1 < v2 && v2 < 256) {
585  word = v1, word2 = v2;
586  }
587  else if (sscanf(desc, "%u %n", &v1, (nc=-1, &nc)) == 1 && nc > 0 && v1 < 256) {
588  word = v1;
589  }
590  else {
591  pout("Error: #%d: Syntax\n", i);
592  continue;
593  }
594  desc += nc;
595 
596  // Check for ATA/ATAPI specific entries
597  if (str_starts_with(desc, "ATA: ")) {
598  if (is_atapi)
599  continue;
600  desc += sizeof("ATA: ")-1;
601  }
602  else if (str_starts_with(desc, "ATAPI: ")) {
603  if (!is_atapi)
604  continue;
605  }
606 
607  // Check table entry
608  if (bit < 0) {
609  if (word != prev_word+1) {
610  pout("Error: #%d: Missing word %d\n", i, prev_word+1);
611  return;
612  }
613  else if (prev_bit > 0) {
614  pout("Error: #%d: Missing bit 0 from word %d\n", i, prev_word);
615  return;
616  }
617  }
618  else if (!((prev_bit < 0 && bit == 15) || bit == prev_bit-1)) {
619  pout("Error: #%d: Missing bit %d from word %d\n", i, bit+1, word);
620  return;
621  }
622 
623  w = get_word(id, word);
624  bool w_is_set = (w != 0x0000 && w != 0xffff);
625 
626  if (bit >= 0) {
627  int b;
628  if (bit2 >= 0)
629  b = (w >> bit2) & ~(~0 << (bit-bit2+1));
630  else
631  b = (w >> bit) & 1;
632 
633  if ( (bit_level >= 0 && b)
634  || (bit_level >= 1 && w_is_set)
635  || (bit_level >= 2 && all_words)) {
636  if (bit2 >= 0) {
637  // Print bitfield
638  char valstr[20];
639  snprintf(valstr, sizeof(valstr), "0x%0*x", (bit - bit2 + 4) >> 2, b);
640  pout("%4d %2d:%-2d %6s %s\n", word, bit, bit2, valstr, desc);
641  }
642  else {
643  // Print bit
644  pout("%4d %2d %u %s\n", word, bit, b, desc);
645  }
646  }
647 
648  prev_bit = (bit2 >= 0 ? bit2 : bit);
649  }
650  else {
651  if (word2 >= 0) {
652  for (int j = word+1; !w_is_set && j <= word2; j++) {
653  if (get_word(id, j) != w)
654  w_is_set = true;
655  }
656 
657  // Print word array
658  if (all_words || w_is_set) {
659  pout("%s%4d-%-3d %s",
660  (bit_level >= 0 ? "\n" : ""), word, word2,
661  (bit_level >= 0 ? "- " : ""));
662 
663  if (!w_is_set) {
664  pout("0x%02x... %s\n", w & 0xff, desc);
665  }
666  else {
667  bool is_str = !!strstr(desc, "(String)");
668  pout(". %s", desc);
669 
670  for (int j = word; j <= word2; j += 4) {
671  if (j + 2*4 < word2 && !nonempty((const unsigned char *)id + 2*j, 2*(word2-j+1))) {
672  // Remaining words are null
673  pout("\n%4d-%-3d %s0x0000:0000:0000:00...", j, word2,
674  (bit_level >= 0 ? ". " : ""));
675  break;
676  }
677  // Print 4 words in a row
678  pout("\n%4d-%-3d %s0x", j, (j+3 <= word2 ? j+3 : word2),
679  (bit_level >= 0 ? ". " : ""));
680  int k;
681  for (k = 0; k < 4 && j+k <= word2; k++)
682  pout("%s%04x", (k == 0 ? "" : ":"), get_word(id, j+k));
683 
684  if (is_str) {
685  // Append little endian string
686  pout("%*s \"", 20 - 5 * k, "");
687  for (k = 0; k < 4 && j+k <= word2; k++) {
688  char c2 = ((const char *)id)[2*(j+k) ];
689  char c1 = ((const char *)id)[2*(j+k) + 1];
690  pout("%c%c", (' ' <= c1 && c1 <= '~' ? c1 : '.'),
691  (' ' <= c2 && c2 <= '~' ? c2 : '.') );
692  }
693  pout("\"");
694  }
695  }
696 
697  // Print decimal value of D/QWords
698  if (word + 1 == word2 && strstr(desc, "(DWord)"))
699  pout(" (%u)\n", ((unsigned)get_word(id, word2) << 16) | w);
700  else if (word + 3 == word2 && strstr(desc, "(QWord)"))
701  pout(" (%" PRIu64 ")\n", ((uint64_t)get_word(id, word + 3) << 48)
702  | ((uint64_t)get_word(id, word + 2) << 32)
703  | ((unsigned)get_word(id, word + 1) << 16) | (unsigned)w);
704  else
705  pout("\n");
706  }
707  }
708  }
709  else {
710  // Print word
711  if (all_words || w_is_set)
712  pout("%s%4d %s0x%04x %s\n",
713  (bit_level >= 0 ? "\n" : ""), word,
714  (bit_level >= 0 ? "- " : ""), w, desc);
715  }
716 
717  prev_word = (word2 >= 0 ? word2 : word);
718  prev_bit = -1;
719  }
720  }
721 
722  pout("\n");
723 }
#define PRIu64
Definition: int64.h:76
bool str_starts_with(const char *str, const char *prefix)
Definition: utility.h:57
#define ATAIDENTIFY_H_CVSID
Definition: ataidentify.h:21
#define snprintf
Definition: utility.h:68
const int num_identify_descriptions
bool nonempty(const void *data, int size)
Definition: utility.cpp:695
void ata_print_identify_data(const void *id, bool all_words, int bit_level)
void pout(const char *fmt,...)
Definition: smartctl.cpp:1095
u8 b[12]
Definition: megaraid.h:96
u32 w[3]
Definition: megaraid.h:98
static unsigned short get_word(const void *id, int word)
const char *const identify_descriptions[]
Definition: ataidentify.cpp:39
unsigned long long uint64_t
Definition: int64.h:54
const char * ataidentify_cpp_cvsid
Definition: ataidentify.cpp:21