xref: /openbsd/sys/dev/ata/atareg.h (revision 1189f60e)
1*1189f60eSjsg /*	$OpenBSD: atareg.h,v 1.14 2010/07/23 07:47:13 jsg Exp $	*/
27481efa2Scsapuntz /*	$NetBSD: atareg.h,v 1.5 1999/01/18 20:06:24 bouyer Exp $	*/
37481efa2Scsapuntz 
4b27bafdfSgrange /*
5b27bafdfSgrange  * Copyright (c) 1998, 2001 Manuel Bouyer.
6b27bafdfSgrange  *
7b27bafdfSgrange  * Redistribution and use in source and binary forms, with or without
8b27bafdfSgrange  * modification, are permitted provided that the following conditions
9b27bafdfSgrange  * are met:
10b27bafdfSgrange  * 1. Redistributions of source code must retain the above copyright
11b27bafdfSgrange  *    notice, this list of conditions and the following disclaimer.
12b27bafdfSgrange  * 2. Redistributions in binary form must reproduce the above copyright
13b27bafdfSgrange  *    notice, this list of conditions and the following disclaimer in the
14b27bafdfSgrange  *    documentation and/or other materials provided with the distribution.
15b27bafdfSgrange  *
16b27bafdfSgrange  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17b27bafdfSgrange  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18b27bafdfSgrange  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19b27bafdfSgrange  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20b27bafdfSgrange  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21b27bafdfSgrange  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22b27bafdfSgrange  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23b27bafdfSgrange  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24b27bafdfSgrange  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25b27bafdfSgrange  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26b27bafdfSgrange  */
27b27bafdfSgrange 
28b27bafdfSgrange #ifndef _DEV_ATA_ATAREG_H_
29b27bafdfSgrange #define _DEV_ATA_ATAREG_H_
305252c952Scsapuntz 
317481efa2Scsapuntz /*
327481efa2Scsapuntz  * Drive parameter structure for ATA/ATAPI.
337481efa2Scsapuntz  * Bit fields: WDC_* : common to ATA/ATAPI
347481efa2Scsapuntz  *             ATA_* : ATA only
357481efa2Scsapuntz  *             ATAPI_* : ATAPI only.
367481efa2Scsapuntz  */
377481efa2Scsapuntz struct ataparams {
387481efa2Scsapuntz     /* drive info */
397481efa2Scsapuntz     u_int16_t	atap_config;		/* 0: general configuration */
407481efa2Scsapuntz #define WDC_CFG_ATAPI_MASK		0xc000
417481efa2Scsapuntz #define WDC_CFG_ATAPI			0x8000
427481efa2Scsapuntz #define ATA_CFG_REMOVABLE		0x0080
437481efa2Scsapuntz #define ATA_CFG_FIXED			0x0040
447481efa2Scsapuntz #define ATAPI_CFG_TYPE_MASK		0x1f00
457481efa2Scsapuntz #define ATAPI_CFG_TYPE(x)		(((x) & ATAPI_CFG_TYPE_MASK) >> 8)
46ec62f1edSniklas #define ATAPI_CFG_TYPE_DIRECT		0x00
47ec62f1edSniklas #define ATAPI_CFG_TYPE_SEQUENTIAL	0x01
48ec62f1edSniklas #define ATAPI_CFG_TYPE_CDROM		0x05
49ec62f1edSniklas #define ATAPI_CFG_TYPE_OPTICAL		0x07
50ec62f1edSniklas #define ATAPI_CFG_TYPE_NODEVICE		0x1F
517481efa2Scsapuntz #define ATAPI_CFG_REMOV			0x0080
527481efa2Scsapuntz #define ATAPI_CFG_DRQ_MASK		0x0060
537481efa2Scsapuntz #define ATAPI_CFG_STD_DRQ		0x0000
547481efa2Scsapuntz #define ATAPI_CFG_IRQ_DRQ		0x0020
557481efa2Scsapuntz #define ATAPI_CFG_ACCEL_DRQ		0x0040
567481efa2Scsapuntz #define ATAPI_CFG_CMD_MASK		0x0003
577481efa2Scsapuntz #define ATAPI_CFG_CMD_12		0x0000
587481efa2Scsapuntz #define ATAPI_CFG_CMD_16		0x0001
597481efa2Scsapuntz /* words 1-9 are ATA only */
607481efa2Scsapuntz     u_int16_t	atap_cylinders;		/* 1: # of non-removable cylinders */
617481efa2Scsapuntz     u_int16_t	__reserved1;
627481efa2Scsapuntz     u_int16_t	atap_heads;		/* 3: # of heads */
637481efa2Scsapuntz     u_int16_t	__retired1[2];		/* 4-5: # of unform. bytes/track */
647481efa2Scsapuntz     u_int16_t	atap_sectors;		/* 6: # of sectors */
657481efa2Scsapuntz     u_int16_t	__retired2[3];
667481efa2Scsapuntz 
677481efa2Scsapuntz     u_int8_t	atap_serial[20];	/* 10-19: serial number */
687481efa2Scsapuntz     u_int16_t	__retired3[2];
697481efa2Scsapuntz     u_int16_t	__obsolete1;
707481efa2Scsapuntz     u_int8_t	atap_revision[8];	/* 23-26: firmware revision */
717481efa2Scsapuntz     u_int8_t	atap_model[40];		/* 27-46: model number */
727481efa2Scsapuntz     u_int16_t	atap_multi;		/* 47: maximum sectors per irq (ATA) */
737481efa2Scsapuntz     u_int16_t	__reserved2;
747481efa2Scsapuntz     u_int16_t	atap_capabilities1;	/* 49: capability flags */
757481efa2Scsapuntz #define WDC_CAP_IORDY	0x0800
767481efa2Scsapuntz #define WDC_CAP_IORDY_DSBL 0x0400
777481efa2Scsapuntz #define WDC_CAP_LBA	0x0200
787481efa2Scsapuntz #define WDC_CAP_DMA	0x0100
797481efa2Scsapuntz #define ATA_CAP_STBY	0x2000
807481efa2Scsapuntz #define ATAPI_CAP_INTERL_DMA	0x8000
817481efa2Scsapuntz #define ATAPI_CAP_CMD_QUEUE	0x4000
82ec62f1edSniklas #define ATAPI_CAP_OVERLP	0x2000
837481efa2Scsapuntz #define ATAPI_CAP_ATA_RST	0x1000
847481efa2Scsapuntz     u_int16_t	atap_capabilities2;	/* 50: capability flags (ATA) */
857481efa2Scsapuntz #if BYTE_ORDER == LITTLE_ENDIAN
867481efa2Scsapuntz     u_int8_t	__junk2;
877481efa2Scsapuntz     u_int8_t	atap_oldpiotiming;	/* 51: old PIO timing mode */
887481efa2Scsapuntz     u_int8_t	__junk3;
897481efa2Scsapuntz     u_int8_t	atap_olddmatiming;	/* 52: old DMA timing mode (ATA) */
907481efa2Scsapuntz #else
917481efa2Scsapuntz     u_int8_t	atap_oldpiotiming;	/* 51: old PIO timing mode */
927481efa2Scsapuntz     u_int8_t	__junk2;
937481efa2Scsapuntz     u_int8_t	atap_olddmatiming;	/* 52: old DMA timing mode (ATA) */
947481efa2Scsapuntz     u_int8_t	__junk3;
957481efa2Scsapuntz #endif
9659a52720Sjmc     u_int16_t	atap_extensions;	/* 53: extensions supported */
977481efa2Scsapuntz #define WDC_EXT_UDMA_MODES	0x0004
987481efa2Scsapuntz #define WDC_EXT_MODES		0x0002
997481efa2Scsapuntz #define WDC_EXT_GEOM		0x0001
1007481efa2Scsapuntz /* words 54-62 are ATA only */
10159a52720Sjmc     u_int16_t	atap_curcylinders;	/* 54: current logical cylinders */
1027481efa2Scsapuntz     u_int16_t	atap_curheads;		/* 55: current logical heads */
1037481efa2Scsapuntz     u_int16_t	atap_cursectors;	/* 56: current logical sectors/tracks */
1047481efa2Scsapuntz     u_int16_t	atap_curcapacity[2];	/* 57-58: current capacity */
1057481efa2Scsapuntz     u_int16_t	atap_curmulti;		/* 59: current multi-sector setting */
1067481efa2Scsapuntz #define WDC_MULTI_VALID 0x0100
1077481efa2Scsapuntz #define WDC_MULTI_MASK  0x00ff
1087481efa2Scsapuntz     u_int16_t	atap_capacity[2];	/* 60-61: total capacity (LBA only) */
1097481efa2Scsapuntz     u_int16_t	__retired4;
1107481efa2Scsapuntz #if BYTE_ORDER == LITTLE_ENDIAN
1117481efa2Scsapuntz     u_int8_t	atap_dmamode_supp;	/* 63: multiword DMA mode supported */
1127481efa2Scsapuntz     u_int8_t	atap_dmamode_act;	/*     multiword DMA mode active */
1137481efa2Scsapuntz     u_int8_t	atap_piomode_supp;	/* 64: PIO mode supported */
1147481efa2Scsapuntz     u_int8_t	__junk4;
1157481efa2Scsapuntz #else
1167481efa2Scsapuntz     u_int8_t	atap_dmamode_act;	/*     multiword DMA mode active */
1177481efa2Scsapuntz     u_int8_t	atap_dmamode_supp;	/* 63: multiword DMA mode supported */
1187481efa2Scsapuntz     u_int8_t	__junk4;
1197481efa2Scsapuntz     u_int8_t	atap_piomode_supp;	/* 64: PIO mode supported */
1207481efa2Scsapuntz #endif
1217481efa2Scsapuntz     u_int16_t	atap_dmatiming_mimi;	/* 65: minimum DMA cycle time */
12259a52720Sjmc     u_int16_t	atap_dmatiming_recom;	/* 66: recommended DMA cycle time */
1237481efa2Scsapuntz     u_int16_t	atap_piotiming;		/* 67: mini PIO cycle time without FC */
1247481efa2Scsapuntz     u_int16_t	atap_piotiming_iordy;	/* 68: mini PIO cycle time with IORDY FC */
1257481efa2Scsapuntz     u_int16_t	__reserved3[2];
1267481efa2Scsapuntz /* words 71-72 are ATAPI only */
1277481efa2Scsapuntz     u_int16_t	atap_pkt_br;		/* 71: time (ns) to bus release */
1287481efa2Scsapuntz     u_int16_t	atap_pkt_bsyclr;	/* 72: tme to clear BSY after service */
1297481efa2Scsapuntz     u_int16_t	__reserved4[2];
1307481efa2Scsapuntz     u_int16_t	atap_queuedepth;	/* 75: */
1312832b9fdSgluk #define WDC_QUEUE_DEPTH_MASK 0x1f
1320609ddd4Sgrange     u_int16_t	atap_sata_caps;		/* 76: SATA capabilities */
1330609ddd4Sgrange #define SATA_SIGNAL_GEN1	0x0002	/* SATA Gen-1 signaling speed */
1340609ddd4Sgrange #define SATA_SIGNAL_GEN2	0x0004	/* SATA Gen-2 signaling speed */
1350609ddd4Sgrange #define SATA_NATIVE_CMDQ	0x0100	/* native command queuing */
1360609ddd4Sgrange #define SATA_HOST_PWR_MGMT	0x0200	/* power management (host) */
1370609ddd4Sgrange     u_int16_t	atap_sata_reserved;	/* 77: reserved */
1380609ddd4Sgrange     u_int16_t	atap_sata_features_supp;/* 78: SATA features supported */
1390609ddd4Sgrange #define SATA_NONZERO_OFFSETS	0x0002	/* non-zero buffer offsets */
1400609ddd4Sgrange #define SATA_DMA_SETUP_AUTO	0x0004	/* DMA setup auto-activate */
1410609ddd4Sgrange #define SATA_DRIVE_PWR_MGMT	0x0008	/* power management (device) */
1420609ddd4Sgrange     u_int16_t	atap_sata_features_en;	/* 79: SATA features enabled */
1437481efa2Scsapuntz     u_int16_t	atap_ata_major;		/* 80: Major version number */
1447481efa2Scsapuntz #define WDC_VER_ATA1	0x0002
1457481efa2Scsapuntz #define WDC_VER_ATA2	0x0004
1467481efa2Scsapuntz #define WDC_VER_ATA3	0x0008
1477481efa2Scsapuntz #define WDC_VER_ATA4	0x0010
1487481efa2Scsapuntz #define WDC_VER_ATA5	0x0020
1493ded539eSderaadt #define WDC_VER_ATA6	0x0040
1503ded539eSderaadt #define WDC_VER_ATA7	0x0080
1513ded539eSderaadt #define WDC_VER_ATA8	0x0100
1523ded539eSderaadt #define WDC_VER_ATA9	0x0200
1533ded539eSderaadt #define WDC_VER_ATA10	0x0400
1543ded539eSderaadt #define WDC_VER_ATA11	0x0800
1553ded539eSderaadt #define WDC_VER_ATA12	0x1000
1563ded539eSderaadt #define WDC_VER_ATA13	0x2000
1573ded539eSderaadt #define WDC_VER_ATA14	0x4000
1587481efa2Scsapuntz     u_int16_t	atap_ata_minor;		/* 81: Minor version number */
159e4d25771Stodd     u_int16_t	atap_cmd_set1;		/* 82: command set supported */
1607481efa2Scsapuntz #define WDC_CMD1_NOP	0x4000
1617481efa2Scsapuntz #define WDC_CMD1_RB	0x2000
1627481efa2Scsapuntz #define WDC_CMD1_WB	0x1000
1637481efa2Scsapuntz #define WDC_CMD1_HPA	0x0400
1647481efa2Scsapuntz #define WDC_CMD1_DVRST	0x0200
1657481efa2Scsapuntz #define WDC_CMD1_SRV	0x0100
1667481efa2Scsapuntz #define WDC_CMD1_RLSE	0x0080
1677481efa2Scsapuntz #define WDC_CMD1_AHEAD	0x0040
1687481efa2Scsapuntz #define WDC_CMD1_CACHE	0x0020
1697481efa2Scsapuntz #define WDC_CMD1_PKT	0x0010
1707481efa2Scsapuntz #define WDC_CMD1_PM	0x0008
1717481efa2Scsapuntz #define WDC_CMD1_REMOV	0x0004
1727481efa2Scsapuntz #define WDC_CMD1_SEC	0x0002
1737481efa2Scsapuntz #define WDC_CMD1_SMART	0x0001
174e4d25771Stodd     u_int16_t	atap_cmd_set2;		/* 83: command set supported */
1753ded539eSderaadt #define ATAPI_CMD2_FCE	0x2000 /* Flush Cache Ext supported */
1763ded539eSderaadt #define ATAPI_CMD2_FC	0x1000 /* Flush Cache supported */
1773ded539eSderaadt #define ATAPI_CMD2_DCO	0x0800 /* Device Configuration Overlay supported */
1783ded539eSderaadt #define ATAPI_CMD2_48AD	0x0400 /* 48bit address supported */
1793ded539eSderaadt #define ATAPI_CMD2_AAM	0x0200 /* Automatic Acoustic Management supported */
1803ded539eSderaadt #define ATAPI_CMD2_SM	0x0100 /* Set Max security extension supported */
1813ded539eSderaadt #define ATAPI_CMD2_SF	0x0040 /* Set Features subcommand required */
1823ded539eSderaadt #define ATAPI_CMD2_PUIS	0x0020 /* Power up in standby supported */
1837481efa2Scsapuntz #define WDC_CMD2_RMSN	0x0010
1847481efa2Scsapuntz #define ATA_CMD2_APM	0x0008
1857481efa2Scsapuntz #define ATA_CMD2_CFA	0x0004
1867481efa2Scsapuntz #define ATA_CMD2_RWQ	0x0002
1873ded539eSderaadt #define WDC_CMD2_DM	0x0001 /* Download Microcode supported */
1887481efa2Scsapuntz     u_int16_t	atap_cmd_ext;		/* 84: command/features supp. ext. */
189abceec7cSjsg #define ATAPI_CMDE_IIUF	0x2000 /* IDLE IMMEDIATE with UNLOAD FEATURE */
1903ded539eSderaadt #define ATAPI_CMDE_MSER	0x0004 /* Media serial number supported */
1913ded539eSderaadt #define ATAPI_CMDE_TEST	0x0002 /* SMART self-test supported */
1923ded539eSderaadt #define ATAPI_CMDE_SLOG	0x0001 /* SMART error logging supported */
1937481efa2Scsapuntz     u_int16_t	atap_cmd1_en;		/* 85: cmd/features enabled */
1947481efa2Scsapuntz /* bits are the same as atap_cmd_set1 */
1957481efa2Scsapuntz     u_int16_t	atap_cmd2_en;		/* 86: cmd/features enabled */
1967481efa2Scsapuntz /* bits are the same as atap_cmd_set2 */
1977481efa2Scsapuntz     u_int16_t	atap_cmd_def;		/* 87: cmd/features default */
1983ded539eSderaadt /* bits are NOT the same as atap_cmd_ext */
1997481efa2Scsapuntz #if BYTE_ORDER == LITTLE_ENDIAN
2007481efa2Scsapuntz     u_int8_t	atap_udmamode_supp;	/* 88: Ultra-DMA mode supported */
2017481efa2Scsapuntz     u_int8_t	atap_udmamode_act;	/*     Ultra-DMA mode active */
2027481efa2Scsapuntz #else
2037481efa2Scsapuntz     u_int8_t	atap_udmamode_act;	/*     Ultra-DMA mode active */
2047481efa2Scsapuntz     u_int8_t	atap_udmamode_supp;	/* 88: Ultra-DMA mode supported */
2057481efa2Scsapuntz #endif
2067481efa2Scsapuntz /* 89-92 are ATA-only */
2077481efa2Scsapuntz     u_int16_t	atap_seu_time;		/* 89: Sec. Erase Unit compl. time */
2087481efa2Scsapuntz     u_int16_t	atap_eseu_time;		/* 90: Enhanced SEU compl. time */
2097481efa2Scsapuntz     u_int16_t	atap_apm_val;		/* 91: current APM value */
2103ded539eSderaadt     u_int16_t	atap_mpasswd_rev;	/* 92: Master Password revision */
2113ded539eSderaadt     u_int16_t	atap_hwreset_res;	/* 93: Hardware reset value */
2123ded539eSderaadt #define ATA_HWRES_CBLID    0x2000  /* CBLID above Vih */
2133ded539eSderaadt #define ATA_HWRES_D1_PDIAG 0x0800  /* Device 1 PDIAG detect OK */
2143ded539eSderaadt #define ATA_HWRES_D1_CSEL  0x0400  /* Device 1 used CSEL for address */
2153ded539eSderaadt #define ATA_HWRES_D1_JUMP  0x0200  /* Device 1 jumpered to address */
2163ded539eSderaadt #define ATA_HWRES_D0_SEL   0x0040  /* Device 0 responds when Dev 1 selected */
2173ded539eSderaadt #define ATA_HWRES_D0_DASP  0x0020  /* Device 0 DASP detect OK */
2183ded539eSderaadt #define ATA_HWRES_D0_PDIAG 0x0010  /* Device 0 PDIAG detect OK */
2193ded539eSderaadt #define ATA_HWRES_D0_DIAG  0x0008  /* Device 0 diag OK */
2203ded539eSderaadt #define ATA_HWRES_D0_CSEL  0x0004  /* Device 0 used CSEL for address */
2213ded539eSderaadt #define ATA_HWRES_D0_JUMP  0x0002  /* Device 0 jumpered to address */
2223ded539eSderaadt #if BYTE_ORDER == LITTLE_ENDIAN
2233ded539eSderaadt     u_int8_t	atap_acoustic_val;	/* 94: Current acoustic level */
2243ded539eSderaadt     u_int8_t	atap_acoustic_def;	/*     recommended level */
2253ded539eSderaadt #else
2263ded539eSderaadt     u_int8_t	atap_acoustic_def;	/*     recommended level */
2273ded539eSderaadt     u_int8_t	atap_acoustic_val;	/* 94: Current acoustic level */
2283ded539eSderaadt #endif
2293ded539eSderaadt     u_int16_t	__reserved6[5];		/* 95-99: reserved */
2303ded539eSderaadt     u_int16_t	atap_max_lba[4];	/* 100-103: Max. user LBA add */
2313ded539eSderaadt     u_int16_t	__reserved7[23];	/* 104-126: reserved */
2327481efa2Scsapuntz     u_int16_t	atap_rmsn_supp;		/* 127: remov. media status notif. */
2337481efa2Scsapuntz #define WDC_RMSN_SUPP_MASK 0x0003
2347481efa2Scsapuntz #define WDC_RMSN_SUPP 0x0001
2357481efa2Scsapuntz     u_int16_t	atap_sec_st;		/* 128: security status */
2367481efa2Scsapuntz #define WDC_SEC_LEV_MAX	0x0100
2377481efa2Scsapuntz #define WDC_SEC_ESE_SUPP 0x0020
2387481efa2Scsapuntz #define WDC_SEC_EXP	0x0010
2397481efa2Scsapuntz #define WDC_SEC_FROZEN	0x0008
2407481efa2Scsapuntz #define WDC_SEC_LOCKED	0x0004
2417481efa2Scsapuntz #define WDC_SEC_EN	0x0002
2427481efa2Scsapuntz #define WDC_SEC_SUPP	0x0001
2433ded539eSderaadt     u_int16_t	__reserved8[31];	/* 129-159: vendor specific */
2443ded539eSderaadt     u_int16_t	atap_cfa_power;		/* 160: CFA powermode */
2453ded539eSderaadt #define ATAPI_CFA_MAX_MASK  0x0FFF
2463ded539eSderaadt #define ATAPI_CFA_MODE1_DIS 0x1000 /* CFA Mode 1 Disabled */
2473ded539eSderaadt #define ATAPI_CFA_MODE1_REQ 0x2000 /* CFA Mode 1 Required */
2483ded539eSderaadt #define ATAPI_CFA_WORD160   0x8000 /* Word 160 supported */
2494eda27e7Sgrange     u_int16_t	__reserved9[15];	/* 161-175: reserved for CFA */
2503ded539eSderaadt     u_int8_t	atap_media_serial[60];	/* 176-205: media serial number */
2513ded539eSderaadt     u_int16_t	__reserved10[49];	/* 206-254: reserved */
2523ded539eSderaadt #if BYTE_ORDER == LITTLE_ENDIAN
2533ded539eSderaadt     u_int8_t	atap_signature;		/* 255: Signature */
2543ded539eSderaadt     u_int8_t	atap_checksum;		/*      Checksum */
2553ded539eSderaadt #else
2563ded539eSderaadt     u_int8_t	atap_checksum;		/*      Checksum */
2573ded539eSderaadt     u_int8_t	atap_signature;		/* 255: Signature */
2583ded539eSderaadt #endif
2597481efa2Scsapuntz };
2605252c952Scsapuntz 
261b27bafdfSgrange #endif	/* !_DEV_ATA_ATAREG_H_ */
262