xref: /openbsd-src/sbin/atactl/atasmart.h (revision 52fff0a7ef0a316a89e09b055c0cca897b5f520d)
1*52fff0a7Sgrange /*	$OpenBSD: atasmart.h,v 1.3 2004/01/16 22:41:52 grange Exp $	*/
230520cf8Sgluk 
330520cf8Sgluk /*
430520cf8Sgluk  * Copyright (c) 2002 Alexander Yurchenko <grange@rt.mipt.ru>
530520cf8Sgluk  * All rights reserved.
630520cf8Sgluk  *
730520cf8Sgluk  * Redistribution and use in source and binary forms, with or without
830520cf8Sgluk  * modification, are permitted provided that the following conditions
930520cf8Sgluk  * are met:
1030520cf8Sgluk  *
1130520cf8Sgluk  *    - Redistributions of source code must retain the above copyright
1230520cf8Sgluk  *      notice, this list of conditions and the following disclaimer.
1330520cf8Sgluk  *    - Redistributions in binary form must reproduce the above
1430520cf8Sgluk  *      copyright notice, this list of conditions and the following
1530520cf8Sgluk  *      disclaimer in the documentation and/or other materials provided
1630520cf8Sgluk  *      with the distribution.
1730520cf8Sgluk  *
1830520cf8Sgluk  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1930520cf8Sgluk  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2030520cf8Sgluk  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2130520cf8Sgluk  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
2230520cf8Sgluk  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
2330520cf8Sgluk  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
2430520cf8Sgluk  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
2530520cf8Sgluk  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2630520cf8Sgluk  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2730520cf8Sgluk  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
2830520cf8Sgluk  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2930520cf8Sgluk  * POSSIBILITY OF SUCH DAMAGE.
3030520cf8Sgluk  *
3130520cf8Sgluk  */
3230520cf8Sgluk 
3347f8c6e8Sgluk /* ATA SMART subcommands */
3447f8c6e8Sgluk #define ATA_SMART_READ		0xd0 /* SMART read data */
3547f8c6e8Sgluk #define ATA_SMART_THRESHOLD	0xd1 /* SMART read threshold */
3647f8c6e8Sgluk #define ATA_SMART_AUTOSAVE	0xd2 /* SMART en-/disable attr. autosave */
3747f8c6e8Sgluk #define ATA_SMART_SAVE		0xd3 /* SMART save attributes */
3847f8c6e8Sgluk #define ATA_SMART_OFFLINE	0xd4 /* SMART execute offline immediately */
3947f8c6e8Sgluk #define ATA_SMART_READLOG	0xd5 /* SMART read log */
4047f8c6e8Sgluk #define ATA_SMART_WRITELOG	0xd6 /* SMART write log */
4147f8c6e8Sgluk #define ATA_SMART_EN		0xd8 /* SMART enable operations */
4247f8c6e8Sgluk #define ATA_SMART_DS		0xd9 /* SMART disable operations */
4347f8c6e8Sgluk #define ATA_SMART_STATUS	0xda /* SMART return status */
4430520cf8Sgluk 
4530520cf8Sgluk /* device attribute */
4630520cf8Sgluk struct attribute {
4730520cf8Sgluk 	u_int8_t  id;		/* Attribute ID */
4830520cf8Sgluk 	u_int16_t status;	/* Status flags */
4930520cf8Sgluk 	u_int8_t  value;	/* Attribute value */
5030520cf8Sgluk 	u_int8_t  raw[8];	/* Vendor specific */
51*52fff0a7Sgrange } __packed;
5230520cf8Sgluk 
5330520cf8Sgluk /* read data sector */
5430520cf8Sgluk struct smart_read {
5530520cf8Sgluk 	u_int16_t revision;	/* Data structure revision */
5630520cf8Sgluk 	struct attribute attribute[30];	/* Device attribute */
5730520cf8Sgluk 	u_int8_t  offstat;	/* Off-line data collection status */
5830520cf8Sgluk #define SMART_OFFSTAT_NOTSTART	0x00
5930520cf8Sgluk #define SMART_OFFSTAT_COMPLETE	0x02
6030520cf8Sgluk #define SMART_OFFSTAT_SUSPEND	0x04
6130520cf8Sgluk #define SMART_OFFSTAT_INTR	0x05
6230520cf8Sgluk #define SMART_OFFSTAT_ERROR	0x06
6330520cf8Sgluk 	u_int8_t  selfstat;	/* Self-test execution status */
6430520cf8Sgluk #define SMART_SELFSTAT_COMPLETE	0x00
6530520cf8Sgluk #define SMART_SELFSTAT_ABORT	0x01
6630520cf8Sgluk #define SMART_SELFSTAT_INTR	0x02
6730520cf8Sgluk #define SMART_SELFSTAT_ERROR	0x03
6830520cf8Sgluk #define SMART_SELFSTAT_UNKFAIL	0x04
6930520cf8Sgluk #define SMART_SELFSTAT_ELFAIL	0x05
7030520cf8Sgluk #define SMART_SELFSTAT_SRVFAIL	0x06
7130520cf8Sgluk #define SMART_SELFSTAT_RDFAIL	0x07
7230520cf8Sgluk #define SMART_SELFSTAT_PROGRESS	0x0f
7330520cf8Sgluk 	u_int16_t time;		/* Time	to complete data collection activity */
7430520cf8Sgluk 	u_int8_t  vendor1;	/* Vendor specific */
7530520cf8Sgluk 	u_int8_t  offcap;	/* Off-line data collection capability */
7630520cf8Sgluk #define SMART_OFFCAP_EXEC	0x01
7730520cf8Sgluk #define SMART_OFFCAP_ABORT	0x04
7830520cf8Sgluk #define SMART_OFFCAP_READSCAN	0x08
7930520cf8Sgluk #define SMART_OFFCAP_SELFTEST	0x10
8030520cf8Sgluk 	u_int16_t smartcap;	/* SMART capability */
8130520cf8Sgluk #define SMART_SMARTCAP_SAVE	0x01
8230520cf8Sgluk #define SMART_SMARTCAP_AUTOSAVE	0x02
8330520cf8Sgluk 	u_int8_t  errcap;	/* Error logging capability */
8430520cf8Sgluk #define SMART_ERRCAP_ERRLOG	0x01
8530520cf8Sgluk 	u_int8_t  vendor2;	/* Vendor specific */
8630520cf8Sgluk 	u_int8_t  shtime;	/* Short self-test polling time */
8730520cf8Sgluk 	u_int8_t  extime;	/* Extended self-test polling time */
8830520cf8Sgluk 	u_int8_t  res[12];	/* Reserved */
8930520cf8Sgluk 	u_int8_t  vendor3[125];	/* Vendor specific */
9030520cf8Sgluk 	u_int8_t  cksum;	/* Data structure checksum */
9130520cf8Sgluk };
9230520cf8Sgluk 
9330520cf8Sgluk /* threshold entry */
9430520cf8Sgluk struct threshold {
9530520cf8Sgluk 	u_int8_t  id;		/* Threshold ID */
9630520cf8Sgluk 	u_int8_t  value;	/* Threshold value */
9730520cf8Sgluk 	u_int8_t  reserve[10];
9830520cf8Sgluk };
9930520cf8Sgluk 
10030520cf8Sgluk /* read thresholds sector */
10130520cf8Sgluk struct smart_threshold {
10230520cf8Sgluk 	u_int16_t revision;	/* Data structure revision */
10330520cf8Sgluk 	struct threshold threshold[30];
10430520cf8Sgluk 	u_int8_t  reserve[18];
10530520cf8Sgluk 	u_int8_t  vendor[131];
10630520cf8Sgluk 	u_int8_t  cksum;	/* Data structure checksum */
10730520cf8Sgluk };
10830520cf8Sgluk 
10930520cf8Sgluk /* log directory entry */
11030520cf8Sgluk struct smart_log_dir_entry {
11130520cf8Sgluk 	u_int8_t  sec_num;
11230520cf8Sgluk 	u_int8_t  res;
11330520cf8Sgluk };
11430520cf8Sgluk 
11530520cf8Sgluk /* log directory sector */
11630520cf8Sgluk struct smart_log_dir {
11730520cf8Sgluk 	u_int16_t version;
11830520cf8Sgluk 	struct    smart_log_dir_entry entry[255];
11930520cf8Sgluk };
12030520cf8Sgluk 
12130520cf8Sgluk /* command data structure */
12230520cf8Sgluk struct smart_log_cmd {
12330520cf8Sgluk 	u_int8_t reg_ctl;
12430520cf8Sgluk 	u_int8_t reg_feat;
12530520cf8Sgluk 	u_int8_t reg_seccnt;
12630520cf8Sgluk 	u_int8_t reg_lbalo;
12730520cf8Sgluk 	u_int8_t reg_lbamid;
12830520cf8Sgluk 	u_int8_t reg_lbahi;
12930520cf8Sgluk 	u_int8_t reg_dev;
13030520cf8Sgluk 	u_int8_t reg_cmd;
13130520cf8Sgluk 	u_int8_t time1;
13230520cf8Sgluk 	u_int8_t time2;
13330520cf8Sgluk 	u_int8_t time3;
13430520cf8Sgluk 	u_int8_t time4;
13530520cf8Sgluk };
13630520cf8Sgluk 
13730520cf8Sgluk /* error data structure */
13830520cf8Sgluk struct smart_log_err {
13930520cf8Sgluk 	u_int8_t res;
14030520cf8Sgluk 	u_int8_t reg_err;
14130520cf8Sgluk 	u_int8_t reg_seccnt;
14230520cf8Sgluk 	u_int8_t reg_lbalo;
14330520cf8Sgluk 	u_int8_t reg_lbamid;
14430520cf8Sgluk 	u_int8_t reg_lbahi;
14530520cf8Sgluk 	u_int8_t reg_dev;
14630520cf8Sgluk 	u_int8_t reg_stat;
14730520cf8Sgluk 	u_int8_t ext[19];
14830520cf8Sgluk 	u_int8_t state;
14930520cf8Sgluk #define SMART_LOG_STATE_UNK	0x0
15030520cf8Sgluk #define SMART_LOG_STATE_SLEEP	0x1
15130520cf8Sgluk #define SMART_LOG_STATE_ACTIDL	0x2
15230520cf8Sgluk #define SMART_LOG_STATE_OFFSELF	0x3
15330520cf8Sgluk 	u_int8_t time1;
15430520cf8Sgluk 	u_int8_t time2;
15530520cf8Sgluk };
15630520cf8Sgluk 
15730520cf8Sgluk /* error log data structure */
15830520cf8Sgluk struct smart_log_errdata {
15930520cf8Sgluk 	struct smart_log_cmd cmd[5];
16030520cf8Sgluk 	struct smart_log_err err;
16130520cf8Sgluk };
16230520cf8Sgluk 
16330520cf8Sgluk /* summary error log sector */
16430520cf8Sgluk struct smart_log_sum {
16530520cf8Sgluk 	u_int8_t  version;
16630520cf8Sgluk 	u_int8_t  index;
16730520cf8Sgluk 	struct    smart_log_errdata errdata[5];
16830520cf8Sgluk 	u_int16_t err_cnt;
16930520cf8Sgluk 	u_int8_t  res[57];
17030520cf8Sgluk 	u_int8_t  cksum;
17130520cf8Sgluk };
17230520cf8Sgluk 
17330520cf8Sgluk /* comprehensive error log sector */
17430520cf8Sgluk struct smart_log_comp {
17530520cf8Sgluk 	u_int8_t  version;
17630520cf8Sgluk 	u_int8_t  index;
17730520cf8Sgluk 	struct    smart_log_errdata errdata[5];
17830520cf8Sgluk 	u_int16_t err_cnt;
17930520cf8Sgluk 	u_int8_t  res[57];
18030520cf8Sgluk 	u_int8_t  cksum;
18130520cf8Sgluk };
18230520cf8Sgluk 
18330520cf8Sgluk /* self-test descriptor entry */
18430520cf8Sgluk struct smart_log_self_desc {
18530520cf8Sgluk 	u_int8_t  reg_lbalo;
18630520cf8Sgluk 	u_int8_t  selfstat;
18730520cf8Sgluk 	u_int8_t  time1;
18830520cf8Sgluk 	u_int8_t  time2;
18930520cf8Sgluk 	u_int8_t  chkpnt;
19030520cf8Sgluk 	u_int8_t  lbafail1;
19130520cf8Sgluk 	u_int8_t  lbafail2;
19230520cf8Sgluk 	u_int8_t  lbafail3;
19330520cf8Sgluk 	u_int8_t  lbafail4;
19430520cf8Sgluk 	u_int8_t  vendor[15];
19530520cf8Sgluk };
19630520cf8Sgluk 
19730520cf8Sgluk /* self-test log sector */
19830520cf8Sgluk struct smart_log_self {
19930520cf8Sgluk 	u_int16_t rev;
20030520cf8Sgluk 	struct    smart_log_self_desc desc[21];
20130520cf8Sgluk 	u_int8_t  vendor[2];
20230520cf8Sgluk 	u_int8_t  index;
20330520cf8Sgluk 	u_int8_t  res[2];
20430520cf8Sgluk 	u_int8_t  cksum;
20530520cf8Sgluk };
20630520cf8Sgluk 
20730520cf8Sgluk #define SMART_SELFSTAT_PCNT(s) ((s & 0x0f) * 10)
20830520cf8Sgluk #define SMART_SELFSTAT_STAT(s) (s >> 4)
20930520cf8Sgluk 
21030520cf8Sgluk #define SMART_OFFLINE_COLLECT	0
21130520cf8Sgluk #define SMART_OFFLINE_SHORTOFF	1
21230520cf8Sgluk #define SMART_OFFLINE_EXTENOFF	2
21330520cf8Sgluk #define SMART_OFFLINE_ABORT	127
21430520cf8Sgluk #define SMART_OFFLINE_SHORTCAP	129
21530520cf8Sgluk #define SMART_OFFLINE_EXTENCAP	130
21630520cf8Sgluk 
21730520cf8Sgluk #define SMART_AUTOSAVE_DS	0x00
21847f8c6e8Sgluk #define SMART_AUTOSAVE_EN	0xf1
21930520cf8Sgluk 
22030520cf8Sgluk #define SMART_READLOG_DIR	0x00
22130520cf8Sgluk #define SMART_READLOG_SUM	0x01
22230520cf8Sgluk #define SMART_READLOG_COMP	0x02
22330520cf8Sgluk #define SMART_READLOG_ECOMP	0x03
22430520cf8Sgluk #define SMART_READLOG_SELF	0x06
22530520cf8Sgluk #define SMART_READLOG_ESELF	0x07
22630520cf8Sgluk 
22730520cf8Sgluk #define SMART_LOG_MSECT		0x01
228