[BACK]Return to atasmart.h CVS log [TXT][DIR] Up to [local] / src / sbin / atactl

File: [local] / src / sbin / atactl / atasmart.h (download)

Revision 1.3, Fri Jan 16 22:41:52 2004 UTC (20 years, 4 months ago) by grange
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, OPENBSD_7_4_BASE, OPENBSD_7_4, OPENBSD_7_3_BASE, OPENBSD_7_3, OPENBSD_7_2_BASE, OPENBSD_7_2, OPENBSD_7_1_BASE, OPENBSD_7_1, OPENBSD_7_0_BASE, OPENBSD_7_0, OPENBSD_6_9_BASE, OPENBSD_6_9, OPENBSD_6_8_BASE, OPENBSD_6_8, OPENBSD_6_7_BASE, OPENBSD_6_7, OPENBSD_6_6_BASE, OPENBSD_6_6, OPENBSD_6_5_BASE, OPENBSD_6_5, OPENBSD_6_4_BASE, OPENBSD_6_4, OPENBSD_6_3_BASE, OPENBSD_6_3, OPENBSD_6_2_BASE, OPENBSD_6_2, OPENBSD_6_1_BASE, OPENBSD_6_1, OPENBSD_6_0_BASE, OPENBSD_6_0, OPENBSD_5_9_BASE, OPENBSD_5_9, OPENBSD_5_8_BASE, OPENBSD_5_8, OPENBSD_5_7_BASE, OPENBSD_5_7, OPENBSD_5_6_BASE, OPENBSD_5_6, OPENBSD_5_5_BASE, OPENBSD_5_5, OPENBSD_5_4_BASE, OPENBSD_5_4, OPENBSD_5_3_BASE, OPENBSD_5_3, OPENBSD_5_2_BASE, OPENBSD_5_2, OPENBSD_5_1_BASE, OPENBSD_5_1, OPENBSD_5_0_BASE, OPENBSD_5_0, OPENBSD_4_9_BASE, OPENBSD_4_9, OPENBSD_4_8_BASE, OPENBSD_4_8, OPENBSD_4_7_BASE, OPENBSD_4_7, OPENBSD_4_6_BASE, OPENBSD_4_6, OPENBSD_4_5_BASE, OPENBSD_4_5, OPENBSD_4_4_BASE, OPENBSD_4_4, OPENBSD_4_3_BASE, OPENBSD_4_3, OPENBSD_4_2_BASE, OPENBSD_4_2, OPENBSD_4_1_BASE, OPENBSD_4_1, OPENBSD_4_0_BASE, OPENBSD_4_0, OPENBSD_3_9_BASE, OPENBSD_3_9, OPENBSD_3_8_BASE, OPENBSD_3_8, OPENBSD_3_7_BASE, OPENBSD_3_7, OPENBSD_3_6_BASE, OPENBSD_3_6, OPENBSD_3_5_BASE, OPENBSD_3_5, HEAD
Changes since 1.2: +2 -2 lines

Use __packed instead of __attribute__((packed)).

ok millert@

/*	$OpenBSD: atasmart.h,v 1.3 2004/01/16 22:41:52 grange Exp $	*/

/*
 * Copyright (c) 2002 Alexander Yurchenko <grange@rt.mipt.ru>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *    - Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *    - Redistributions in binary form must reproduce the above
 *      copyright notice, this list of conditions and the following
 *      disclaimer in the documentation and/or other materials provided
 *      with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

/* ATA SMART subcommands */
#define ATA_SMART_READ		0xd0 /* SMART read data */
#define ATA_SMART_THRESHOLD	0xd1 /* SMART read threshold */
#define ATA_SMART_AUTOSAVE	0xd2 /* SMART en-/disable attr. autosave */
#define ATA_SMART_SAVE		0xd3 /* SMART save attributes */
#define ATA_SMART_OFFLINE	0xd4 /* SMART execute offline immediately */
#define ATA_SMART_READLOG	0xd5 /* SMART read log */
#define ATA_SMART_WRITELOG	0xd6 /* SMART write log */
#define ATA_SMART_EN		0xd8 /* SMART enable operations */
#define ATA_SMART_DS		0xd9 /* SMART disable operations */
#define ATA_SMART_STATUS	0xda /* SMART return status */

/* device attribute */
struct attribute {
	u_int8_t  id;		/* Attribute ID */
	u_int16_t status;	/* Status flags */
	u_int8_t  value;	/* Attribute value */
	u_int8_t  raw[8];	/* Vendor specific */
} __packed;

/* read data sector */
struct smart_read {
	u_int16_t revision;	/* Data structure revision */
	struct attribute attribute[30];	/* Device attribute */
	u_int8_t  offstat;	/* Off-line data collection status */
#define SMART_OFFSTAT_NOTSTART	0x00
#define SMART_OFFSTAT_COMPLETE	0x02
#define SMART_OFFSTAT_SUSPEND	0x04
#define SMART_OFFSTAT_INTR	0x05
#define SMART_OFFSTAT_ERROR	0x06
	u_int8_t  selfstat;	/* Self-test execution status */
#define SMART_SELFSTAT_COMPLETE	0x00
#define SMART_SELFSTAT_ABORT	0x01
#define SMART_SELFSTAT_INTR	0x02
#define SMART_SELFSTAT_ERROR	0x03
#define SMART_SELFSTAT_UNKFAIL	0x04
#define SMART_SELFSTAT_ELFAIL	0x05
#define SMART_SELFSTAT_SRVFAIL	0x06
#define SMART_SELFSTAT_RDFAIL	0x07
#define SMART_SELFSTAT_PROGRESS	0x0f
	u_int16_t time;		/* Time	to complete data collection activity */
	u_int8_t  vendor1;	/* Vendor specific */
	u_int8_t  offcap;	/* Off-line data collection capability */
#define SMART_OFFCAP_EXEC	0x01
#define SMART_OFFCAP_ABORT	0x04
#define SMART_OFFCAP_READSCAN	0x08
#define SMART_OFFCAP_SELFTEST	0x10
	u_int16_t smartcap;	/* SMART capability */
#define SMART_SMARTCAP_SAVE	0x01
#define SMART_SMARTCAP_AUTOSAVE	0x02
	u_int8_t  errcap;	/* Error logging capability */
#define SMART_ERRCAP_ERRLOG	0x01
	u_int8_t  vendor2;	/* Vendor specific */
	u_int8_t  shtime;	/* Short self-test polling time */
	u_int8_t  extime;	/* Extended self-test polling time */
	u_int8_t  res[12];	/* Reserved */
	u_int8_t  vendor3[125];	/* Vendor specific */
	u_int8_t  cksum;	/* Data structure checksum */
};

/* threshold entry */
struct threshold {
	u_int8_t  id;		/* Threshold ID */
	u_int8_t  value;	/* Threshold value */
	u_int8_t  reserve[10];
};

/* read thresholds sector */
struct smart_threshold {
	u_int16_t revision;	/* Data structure revision */
	struct threshold threshold[30];
	u_int8_t  reserve[18];
	u_int8_t  vendor[131];
	u_int8_t  cksum;	/* Data structure checksum */
};

/* log directory entry */
struct smart_log_dir_entry {
	u_int8_t  sec_num;
	u_int8_t  res;
};

/* log directory sector */
struct smart_log_dir {
	u_int16_t version;
	struct    smart_log_dir_entry entry[255];
};

/* command data structure */
struct smart_log_cmd {
	u_int8_t reg_ctl;
	u_int8_t reg_feat;
	u_int8_t reg_seccnt;
	u_int8_t reg_lbalo;
	u_int8_t reg_lbamid;
	u_int8_t reg_lbahi;
	u_int8_t reg_dev;
	u_int8_t reg_cmd;
	u_int8_t time1;
	u_int8_t time2;
	u_int8_t time3;
	u_int8_t time4;
};

/* error data structure */
struct smart_log_err {
	u_int8_t res;
	u_int8_t reg_err;
	u_int8_t reg_seccnt;
	u_int8_t reg_lbalo;
	u_int8_t reg_lbamid;
	u_int8_t reg_lbahi;
	u_int8_t reg_dev;
	u_int8_t reg_stat;
	u_int8_t ext[19];
	u_int8_t state;
#define SMART_LOG_STATE_UNK	0x0
#define SMART_LOG_STATE_SLEEP	0x1
#define SMART_LOG_STATE_ACTIDL	0x2
#define SMART_LOG_STATE_OFFSELF	0x3
	u_int8_t time1;
	u_int8_t time2;
};

/* error log data structure */
struct smart_log_errdata {
	struct smart_log_cmd cmd[5];
	struct smart_log_err err;
};

/* summary error log sector */
struct smart_log_sum {
	u_int8_t  version;
	u_int8_t  index;
	struct    smart_log_errdata errdata[5];
	u_int16_t err_cnt;
	u_int8_t  res[57];
	u_int8_t  cksum;
};

/* comprehensive error log sector */
struct smart_log_comp {
	u_int8_t  version;
	u_int8_t  index;
	struct    smart_log_errdata errdata[5];
	u_int16_t err_cnt;
	u_int8_t  res[57];
	u_int8_t  cksum;
};

/* self-test descriptor entry */
struct smart_log_self_desc {
	u_int8_t  reg_lbalo;
	u_int8_t  selfstat;
	u_int8_t  time1;
	u_int8_t  time2;
	u_int8_t  chkpnt;
	u_int8_t  lbafail1;
	u_int8_t  lbafail2;
	u_int8_t  lbafail3;
	u_int8_t  lbafail4;
	u_int8_t  vendor[15];
};

/* self-test log sector */
struct smart_log_self {
	u_int16_t rev;
	struct    smart_log_self_desc desc[21];
	u_int8_t  vendor[2];
	u_int8_t  index;
	u_int8_t  res[2];
	u_int8_t  cksum;
};

#define SMART_SELFSTAT_PCNT(s) ((s & 0x0f) * 10)
#define SMART_SELFSTAT_STAT(s) (s >> 4)

#define SMART_OFFLINE_COLLECT	0
#define SMART_OFFLINE_SHORTOFF	1
#define SMART_OFFLINE_EXTENOFF	2
#define SMART_OFFLINE_ABORT	127
#define SMART_OFFLINE_SHORTCAP	129
#define SMART_OFFLINE_EXTENCAP	130

#define SMART_AUTOSAVE_DS	0x00
#define SMART_AUTOSAVE_EN	0xf1

#define SMART_READLOG_DIR	0x00
#define SMART_READLOG_SUM	0x01
#define SMART_READLOG_COMP	0x02
#define SMART_READLOG_ECOMP	0x03
#define SMART_READLOG_SELF	0x06
#define SMART_READLOG_ESELF	0x07

#define SMART_LOG_MSECT		0x01