1/*	$OpenBSD: atasmart.h,v 1.3 2004/01/16 22:41:52 grange Exp $	*/
2
3/*
4 * Copyright (c) 2002 Alexander Yurchenko <grange@rt.mipt.ru>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 *    - Redistributions of source code must retain the above copyright
12 *      notice, this list of conditions and the following disclaimer.
13 *    - Redistributions in binary form must reproduce the above
14 *      copyright notice, this list of conditions and the following
15 *      disclaimer in the documentation and/or other materials provided
16 *      with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33/* ATA SMART subcommands */
34#define ATA_SMART_READ		0xd0 /* SMART read data */
35#define ATA_SMART_THRESHOLD	0xd1 /* SMART read threshold */
36#define ATA_SMART_AUTOSAVE	0xd2 /* SMART en-/disable attr. autosave */
37#define ATA_SMART_SAVE		0xd3 /* SMART save attributes */
38#define ATA_SMART_OFFLINE	0xd4 /* SMART execute offline immediately */
39#define ATA_SMART_READLOG	0xd5 /* SMART read log */
40#define ATA_SMART_WRITELOG	0xd6 /* SMART write log */
41#define ATA_SMART_EN		0xd8 /* SMART enable operations */
42#define ATA_SMART_DS		0xd9 /* SMART disable operations */
43#define ATA_SMART_STATUS	0xda /* SMART return status */
44
45/* device attribute */
46struct attribute {
47	u_int8_t  id;		/* Attribute ID */
48	u_int16_t status;	/* Status flags */
49	u_int8_t  value;	/* Attribute value */
50	u_int8_t  raw[8];	/* Vendor specific */
51} __packed;
52
53/* read data sector */
54struct smart_read {
55	u_int16_t revision;	/* Data structure revision */
56	struct attribute attribute[30];	/* Device attribute */
57	u_int8_t  offstat;	/* Off-line data collection status */
58#define SMART_OFFSTAT_NOTSTART	0x00
59#define SMART_OFFSTAT_COMPLETE	0x02
60#define SMART_OFFSTAT_SUSPEND	0x04
61#define SMART_OFFSTAT_INTR	0x05
62#define SMART_OFFSTAT_ERROR	0x06
63	u_int8_t  selfstat;	/* Self-test execution status */
64#define SMART_SELFSTAT_COMPLETE	0x00
65#define SMART_SELFSTAT_ABORT	0x01
66#define SMART_SELFSTAT_INTR	0x02
67#define SMART_SELFSTAT_ERROR	0x03
68#define SMART_SELFSTAT_UNKFAIL	0x04
69#define SMART_SELFSTAT_ELFAIL	0x05
70#define SMART_SELFSTAT_SRVFAIL	0x06
71#define SMART_SELFSTAT_RDFAIL	0x07
72#define SMART_SELFSTAT_PROGRESS	0x0f
73	u_int16_t time;		/* Time	to complete data collection activity */
74	u_int8_t  vendor1;	/* Vendor specific */
75	u_int8_t  offcap;	/* Off-line data collection capability */
76#define SMART_OFFCAP_EXEC	0x01
77#define SMART_OFFCAP_ABORT	0x04
78#define SMART_OFFCAP_READSCAN	0x08
79#define SMART_OFFCAP_SELFTEST	0x10
80	u_int16_t smartcap;	/* SMART capability */
81#define SMART_SMARTCAP_SAVE	0x01
82#define SMART_SMARTCAP_AUTOSAVE	0x02
83	u_int8_t  errcap;	/* Error logging capability */
84#define SMART_ERRCAP_ERRLOG	0x01
85	u_int8_t  vendor2;	/* Vendor specific */
86	u_int8_t  shtime;	/* Short self-test polling time */
87	u_int8_t  extime;	/* Extended self-test polling time */
88	u_int8_t  res[12];	/* Reserved */
89	u_int8_t  vendor3[125];	/* Vendor specific */
90	u_int8_t  cksum;	/* Data structure checksum */
91};
92
93/* threshold entry */
94struct threshold {
95	u_int8_t  id;		/* Threshold ID */
96	u_int8_t  value;	/* Threshold value */
97	u_int8_t  reserve[10];
98};
99
100/* read thresholds sector */
101struct smart_threshold {
102	u_int16_t revision;	/* Data structure revision */
103	struct threshold threshold[30];
104	u_int8_t  reserve[18];
105	u_int8_t  vendor[131];
106	u_int8_t  cksum;	/* Data structure checksum */
107};
108
109/* log directory entry */
110struct smart_log_dir_entry {
111	u_int8_t  sec_num;
112	u_int8_t  res;
113};
114
115/* log directory sector */
116struct smart_log_dir {
117	u_int16_t version;
118	struct    smart_log_dir_entry entry[255];
119};
120
121/* command data structure */
122struct smart_log_cmd {
123	u_int8_t reg_ctl;
124	u_int8_t reg_feat;
125	u_int8_t reg_seccnt;
126	u_int8_t reg_lbalo;
127	u_int8_t reg_lbamid;
128	u_int8_t reg_lbahi;
129	u_int8_t reg_dev;
130	u_int8_t reg_cmd;
131	u_int8_t time1;
132	u_int8_t time2;
133	u_int8_t time3;
134	u_int8_t time4;
135};
136
137/* error data structure */
138struct smart_log_err {
139	u_int8_t res;
140	u_int8_t reg_err;
141	u_int8_t reg_seccnt;
142	u_int8_t reg_lbalo;
143	u_int8_t reg_lbamid;
144	u_int8_t reg_lbahi;
145	u_int8_t reg_dev;
146	u_int8_t reg_stat;
147	u_int8_t ext[19];
148	u_int8_t state;
149#define SMART_LOG_STATE_UNK	0x0
150#define SMART_LOG_STATE_SLEEP	0x1
151#define SMART_LOG_STATE_ACTIDL	0x2
152#define SMART_LOG_STATE_OFFSELF	0x3
153	u_int8_t time1;
154	u_int8_t time2;
155};
156
157/* error log data structure */
158struct smart_log_errdata {
159	struct smart_log_cmd cmd[5];
160	struct smart_log_err err;
161};
162
163/* summary error log sector */
164struct smart_log_sum {
165	u_int8_t  version;
166	u_int8_t  index;
167	struct    smart_log_errdata errdata[5];
168	u_int16_t err_cnt;
169	u_int8_t  res[57];
170	u_int8_t  cksum;
171};
172
173/* comprehensive error log sector */
174struct smart_log_comp {
175	u_int8_t  version;
176	u_int8_t  index;
177	struct    smart_log_errdata errdata[5];
178	u_int16_t err_cnt;
179	u_int8_t  res[57];
180	u_int8_t  cksum;
181};
182
183/* self-test descriptor entry */
184struct smart_log_self_desc {
185	u_int8_t  reg_lbalo;
186	u_int8_t  selfstat;
187	u_int8_t  time1;
188	u_int8_t  time2;
189	u_int8_t  chkpnt;
190	u_int8_t  lbafail1;
191	u_int8_t  lbafail2;
192	u_int8_t  lbafail3;
193	u_int8_t  lbafail4;
194	u_int8_t  vendor[15];
195};
196
197/* self-test log sector */
198struct smart_log_self {
199	u_int16_t rev;
200	struct    smart_log_self_desc desc[21];
201	u_int8_t  vendor[2];
202	u_int8_t  index;
203	u_int8_t  res[2];
204	u_int8_t  cksum;
205};
206
207#define SMART_SELFSTAT_PCNT(s) ((s & 0x0f) * 10)
208#define SMART_SELFSTAT_STAT(s) (s >> 4)
209
210#define SMART_OFFLINE_COLLECT	0
211#define SMART_OFFLINE_SHORTOFF	1
212#define SMART_OFFLINE_EXTENOFF	2
213#define SMART_OFFLINE_ABORT	127
214#define SMART_OFFLINE_SHORTCAP	129
215#define SMART_OFFLINE_EXTENCAP	130
216
217#define SMART_AUTOSAVE_DS	0x00
218#define SMART_AUTOSAVE_EN	0xf1
219
220#define SMART_READLOG_DIR	0x00
221#define SMART_READLOG_SUM	0x01
222#define SMART_READLOG_COMP	0x02
223#define SMART_READLOG_ECOMP	0x03
224#define SMART_READLOG_SELF	0x06
225#define SMART_READLOG_ESELF	0x07
226
227#define SMART_LOG_MSECT		0x01
228