change log updated
[public/netxms.git] / include / ata.h
1 /*
2 ** NetXMS - Network Management System
3 ** This file is based on atacmds.h from smartmontools
4 **
5 ** Home page of smartmontools is: http://smartmontools.sourceforge.net
6 **
7 ** Copyright (C) 2002-2004 Bruce Allen <smartmontools-support@lists.sourceforge.net>
8 ** Copyright (C) 1999-2000 Michael Cornwell <cornwell@acm.org>
9 **
10 ** Adopted for NetXMS by Victor Kirhenshtein (victor@netxms.org)
11 **
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License as published by
14 ** the Free Software Foundation; either version 2 of the License, or
15 ** (at your option) any later version.
16 **
17 ** This program is distributed in the hope that it will be useful,
18 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ** GNU General Public License for more details.
21 **
22 ** You should have received a copy of the GNU General Public License
23 ** along with this program; if not, write to the Free Software
24 ** Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 **
26 ** $module: ata.h
27 **
28 **/
29
30 #ifndef _ata_h_
31 #define _ata_h_
32
33 // ATA Specification Command Register Values (Commands)
34 #define ATA_IDENTIFY_DEVICE 0xec
35 #define ATA_IDENTIFY_PACKET_DEVICE 0xa1
36 #define ATA_SMART_CMD 0xb0
37 #define ATA_CHECK_POWER_MODE 0xe5
38
39 // ATA Specification Feature Register Values (SMART Subcommands).
40 // Note that some are obsolete as of ATA-7.
41 #define ATA_SMART_READ_VALUES 0xd0
42 #define ATA_SMART_READ_THRESHOLDS 0xd1
43 #define ATA_SMART_AUTOSAVE 0xd2
44 #define ATA_SMART_SAVE 0xd3
45 #define ATA_SMART_IMMEDIATE_OFFLINE 0xd4
46 #define ATA_SMART_READ_LOG_SECTOR 0xd5
47 #define ATA_SMART_WRITE_LOG_SECTOR 0xd6
48 #define ATA_SMART_WRITE_THRESHOLDS 0xd7
49 #define ATA_SMART_ENABLE 0xd8
50 #define ATA_SMART_DISABLE 0xd9
51 #define ATA_SMART_STATUS 0xda
52 // SFF 8035i Revision 2 Specification Feature Register Value (SMART
53 // Subcommand)
54 #define ATA_SMART_AUTO_OFFLINE 0xdb
55
56 // Sector Number values for ATA_SMART_IMMEDIATE_OFFLINE Subcommand
57 #define OFFLINE_FULL_SCAN 0
58 #define SHORT_SELF_TEST 1
59 #define EXTEND_SELF_TEST 2
60 #define CONVEYANCE_SELF_TEST 3
61 #define SELECTIVE_SELF_TEST 4
62 #define ABORT_SELF_TEST 127
63 #define SHORT_CAPTIVE_SELF_TEST 129
64 #define EXTEND_CAPTIVE_SELF_TEST 130
65 #define CONVEYANCE_CAPTIVE_SELF_TEST 131
66 #define SELECTIVE_CAPTIVE_SELF_TEST 132
67 #define CAPTIVE_MASK (0x01<<7)
68
69 // Maximum allowed number of SMART Attributes
70 #define NUMBER_ATA_SMART_ATTRIBUTES 30
71
72 /* ata_smart_attribute is the vendor specific in SFF-8035 spec */
73 #pragma pack(1)
74 typedef struct ata_smart_attribute
75 {
76 unsigned char id;
77 // meaning of flag bits: see MACROS just below
78 // WARNING: MISALIGNED!
79 unsigned short flags;
80 unsigned char current;
81 unsigned char worst;
82 unsigned char raw[6];
83 unsigned char reserv;
84 } ATA_SMART_ATTRIBUTE;
85 #pragma pack()
86
87 // MACROS to interpret the flags bits in the previous structure.
88 // These have not been implemented using bitflags and a union, to make
89 // it portable across bit/little endian and different platforms.
90
91 // 0: Prefailure bit
92
93 // From SFF 8035i Revision 2 page 19: Bit 0 (pre-failure/advisory bit)
94 // - If the value of this bit equals zero, an attribute value less
95 // than or equal to its corresponding attribute threshold indicates an
96 // advisory condition where the usage or age of the device has
97 // exceeded its intended design life period. If the value of this bit
98 // equals one, an attribute value less than or equal to its
99 // corresponding attribute threshold indicates a prefailure condition
100 // where imminent loss of data is being predicted.
101 #define ATTRIBUTE_FLAGS_PREFAILURE(x) (x & 0x01)
102
103 // 1: Online bit
104
105 // From SFF 8035i Revision 2 page 19: Bit 1 (on-line data collection
106 // bit) - If the value of this bit equals zero, then the attribute
107 // value is updated only during off-line data collection
108 // activities. If the value of this bit equals one, then the attribute
109 // value is updated during normal operation of the device or during
110 // both normal operation and off-line testing.
111 #define ATTRIBUTE_FLAGS_ONLINE(x) (x & 0x02)
112
113
114 // The following are (probably) IBM's, Maxtors and Quantum's definitions for the
115 // vendor-specific bits:
116 // 2: Performance type bit
117 #define ATTRIBUTE_FLAGS_PERFORMANCE(x) (x & 0x04)
118
119 // 3: Errorrate type bit
120 #define ATTRIBUTE_FLAGS_ERRORRATE(x) (x & 0x08)
121
122 // 4: Eventcount bit
123 #define ATTRIBUTE_FLAGS_EVENTCOUNT(x) (x & 0x10)
124
125 // 5: Selfpereserving bit
126 #define ATTRIBUTE_FLAGS_SELFPRESERVING(x) (x & 0x20)
127
128
129 // Last ten bits are reserved for future use
130
131
132 /* ata_smart_values is format of the read drive Attribute command */
133 /* see Table 34 of T13/1321D Rev 1 spec (Device SMART data structure) for *some* info */
134 #pragma pack(1)
135 typedef struct ata_smart_values
136 {
137 unsigned short int revnumber;
138 struct ata_smart_attribute vendor_attributes [NUMBER_ATA_SMART_ATTRIBUTES];
139 unsigned char offline_data_collection_status;
140 unsigned char self_test_exec_status; //IBM # segments for offline collection
141 unsigned short int total_time_to_complete_off_line; // IBM different
142 unsigned char vendor_specific_366; // Maxtor & IBM curent segment pointer
143 unsigned char offline_data_collection_capability;
144 unsigned short int smart_capability;
145 unsigned char errorlog_capability;
146 unsigned char vendor_specific_371; // Maxtor, IBM: self-test failure checkpoint see below!
147 unsigned char short_test_completion_time;
148 unsigned char extend_test_completion_time;
149 unsigned char conveyance_test_completion_time;
150 unsigned char reserved_375_385[11];
151 unsigned char vendor_specific_386_510[125]; // Maxtor bytes 508-509 Attribute/Threshold Revision #
152 unsigned char chksum;
153 } ATA_SMART_VALUES;
154 #pragma pack()
155
156
157 //
158 // Default values for SMART registers
159 //
160
161 #ifndef SMART_CYL_LOW
162 #define SMART_CYL_LOW 0xC2
163 #endif
164
165 #ifndef SMART_CYL_HI
166 #define SMART_CYL_HI 0x4F
167 #endif
168
169
170 // Needed parts of the ATA DRIVE IDENTIFY Structure. Those labeled
171 // word* are NOT used.
172 #pragma pack(1)
173 typedef struct ata_identify_device_data
174 {
175 unsigned short words000_009[10];
176 unsigned char serial_no[20];
177 unsigned short words020_022[3];
178 unsigned char fw_rev[8];
179 unsigned char model[40];
180 unsigned short words047_079[33];
181 unsigned short major_rev_num;
182 unsigned short minor_rev_num;
183 unsigned short command_set_1;
184 unsigned short command_set_2;
185 unsigned short command_set_extension;
186 unsigned short cfs_enable_1;
187 unsigned short word086;
188 unsigned short csf_default;
189 unsigned short words088_255[168];
190 } ATA_IDENTIFY_DEVICE_DATA;
191 #pragma pack()
192
193
194 #endif