Home | History | Annotate | Line # | Download | only in ata
atareg.h revision 1.43.18.3
      1  1.43.18.3  jdolecek /*	$NetBSD: atareg.h,v 1.43.18.3 2017/07/19 19:39:28 jdolecek Exp $	*/
      2       1.15   thorpej 
      3       1.15   thorpej /*
      4       1.15   thorpej  * Copyright (c) 1998, 2001 Manuel Bouyer.
      5       1.15   thorpej  *
      6       1.15   thorpej  * Redistribution and use in source and binary forms, with or without
      7       1.15   thorpej  * modification, are permitted provided that the following conditions
      8       1.15   thorpej  * are met:
      9       1.15   thorpej  * 1. Redistributions of source code must retain the above copyright
     10       1.15   thorpej  *    notice, this list of conditions and the following disclaimer.
     11       1.15   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     12       1.15   thorpej  *    notice, this list of conditions and the following disclaimer in the
     13       1.15   thorpej  *    documentation and/or other materials provided with the distribution.
     14       1.15   thorpej  *
     15       1.15   thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     16       1.15   thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     17       1.15   thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     18       1.22     perry  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     19       1.15   thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     20       1.15   thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     21       1.15   thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     22       1.15   thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     23       1.15   thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     24       1.15   thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     25       1.15   thorpej  */
     26       1.15   thorpej 
     27       1.16   thorpej /*-
     28       1.16   thorpej  * Copyright (c) 1991 The Regents of the University of California.
     29       1.16   thorpej  * All rights reserved.
     30       1.16   thorpej  *
     31       1.16   thorpej  * This code is derived from software contributed to Berkeley by
     32       1.16   thorpej  * William Jolitz.
     33       1.16   thorpej  *
     34       1.16   thorpej  * Redistribution and use in source and binary forms, with or without
     35       1.16   thorpej  * modification, are permitted provided that the following conditions
     36       1.16   thorpej  * are met:
     37       1.16   thorpej  * 1. Redistributions of source code must retain the above copyright
     38       1.16   thorpej  *    notice, this list of conditions and the following disclaimer.
     39       1.16   thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     40       1.16   thorpej  *    notice, this list of conditions and the following disclaimer in the
     41       1.16   thorpej  *    documentation and/or other materials provided with the distribution.
     42       1.16   thorpej  * 3. Neither the name of the University nor the names of its contributors
     43       1.16   thorpej  *    may be used to endorse or promote products derived from this software
     44       1.16   thorpej  *    without specific prior written permission.
     45       1.16   thorpej  *
     46       1.16   thorpej  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     47       1.16   thorpej  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     48       1.16   thorpej  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     49       1.16   thorpej  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     50       1.16   thorpej  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     51       1.16   thorpej  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     52       1.16   thorpej  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     53       1.16   thorpej  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     54       1.16   thorpej  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     55       1.16   thorpej  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     56       1.16   thorpej  * SUCH DAMAGE.
     57       1.16   thorpej  *
     58       1.16   thorpej  *	@(#)wdreg.h	7.1 (Berkeley) 5/9/91
     59       1.16   thorpej  */
     60       1.16   thorpej 
     61       1.15   thorpej #ifndef _DEV_ATA_ATAREG_H_
     62       1.15   thorpej #define	_DEV_ATA_ATAREG_H_
     63        1.2    bouyer 
     64        1.2    bouyer /*
     65       1.16   thorpej  * ATA Task File register definitions.
     66       1.16   thorpej  */
     67       1.16   thorpej 
     68       1.16   thorpej /* Status bits. */
     69       1.16   thorpej #define	WDCS_BSY		0x80    /* busy */
     70       1.16   thorpej #define	WDCS_DRDY		0x40    /* drive ready */
     71       1.16   thorpej #define	WDCS_DWF		0x20    /* drive write fault */
     72       1.16   thorpej #define	WDCS_DSC		0x10    /* drive seek complete */
     73       1.16   thorpej #define	WDCS_DRQ		0x08    /* data request */
     74       1.16   thorpej #define	WDCS_CORR		0x04    /* corrected data */
     75       1.16   thorpej #define	WDCS_IDX		0x02    /* index */
     76       1.16   thorpej #define	WDCS_ERR		0x01    /* error */
     77       1.16   thorpej #define	WDCS_BITS \
     78       1.16   thorpej     "\020\010bsy\007drdy\006dwf\005dsc\004drq\003corr\002idx\001err"
     79       1.16   thorpej 
     80       1.16   thorpej /* Error bits. */
     81       1.16   thorpej #define	WDCE_BBK		0x80	/* bad block detected */
     82       1.16   thorpej #define	WDCE_CRC		0x80	/* CRC error (Ultra-DMA only) */
     83       1.16   thorpej #define	WDCE_UNC		0x40	/* uncorrectable data error */
     84       1.16   thorpej #define	WDCE_MC			0x20	/* media changed */
     85       1.16   thorpej #define	WDCE_IDNF		0x10	/* id not found */
     86       1.16   thorpej #define	WDCE_MCR		0x08	/* media change requested */
     87       1.16   thorpej #define	WDCE_ABRT		0x04	/* aborted command */
     88       1.16   thorpej #define	WDCE_TK0NF		0x02	/* track 0 not found */
     89       1.16   thorpej #define	WDCE_AMNF		0x01	/* address mark not found */
     90       1.16   thorpej 
     91       1.16   thorpej /* Commands for Disk Controller. */
     92       1.16   thorpej #define	WDCC_NOP		0x00	/* Always fail with "aborted command" */
     93       1.41  drochner #define ATA_DATA_SET_MANAGEMENT	0x06
     94       1.16   thorpej #define	WDCC_RECAL		0x10	/* disk restore code -- resets cntlr */
     95       1.16   thorpej 
     96       1.16   thorpej #define	WDCC_READ		0x20	/* disk read code */
     97  1.43.18.3  jdolecek 
     98  1.43.18.3  jdolecek #define	WDCC_READ_LOG_EXT	0x2f
     99  1.43.18.3  jdolecek #define	 WDCC_LOG_PAGE_NCQ	0x10
    100  1.43.18.3  jdolecek #define	 WDCC_LOG_NQ		__BIT(7)
    101  1.43.18.3  jdolecek 
    102       1.16   thorpej #define	WDCC_WRITE		0x30	/* disk write code */
    103       1.16   thorpej #define	 WDCC__LONG		 0x02	/* modifier -- access ecc bytes */
    104       1.16   thorpej #define	 WDCC__NORETRY		 0x01	/* modifier -- no retrys */
    105       1.16   thorpej 
    106  1.43.18.3  jdolecek #define	WDCC_READ_LOG_DMA_EXT	0x47	/* DMA variant of READ_LOG_EXT */
    107  1.43.18.3  jdolecek 
    108       1.16   thorpej #define	WDCC_FORMAT		0x50	/* disk format code */
    109       1.16   thorpej #define	WDCC_DIAGNOSE		0x90	/* controller diagnostic */
    110       1.16   thorpej #define	WDCC_IDP		0x91	/* initialize drive parameters */
    111       1.16   thorpej 
    112       1.16   thorpej #define	WDCC_SMART		0xb0	/* Self Mon, Analysis, Reporting Tech */
    113       1.16   thorpej 
    114       1.16   thorpej #define	WDCC_READMULTI		0xc4	/* read multiple */
    115       1.16   thorpej #define	WDCC_WRITEMULTI		0xc5	/* write multiple */
    116       1.16   thorpej #define	WDCC_SETMULTI		0xc6	/* set multiple mode */
    117       1.16   thorpej 
    118       1.16   thorpej #define	WDCC_READDMA		0xc8	/* read with DMA */
    119       1.16   thorpej #define	WDCC_WRITEDMA		0xca	/* write with DMA */
    120       1.16   thorpej 
    121       1.16   thorpej #define	WDCC_ACKMC		0xdb	/* acknowledge media change */
    122       1.16   thorpej #define	WDCC_LOCK		0xde	/* lock drawer */
    123       1.16   thorpej #define	WDCC_UNLOCK		0xdf	/* unlock drawer */
    124       1.16   thorpej 
    125       1.16   thorpej #define	WDCC_FLUSHCACHE		0xe7	/* Flush cache */
    126       1.18    bouyer #define	WDCC_FLUSHCACHE_EXT	0xea	/* Flush cache ext */
    127       1.16   thorpej #define	WDCC_IDENTIFY		0xec	/* read parameters from controller */
    128       1.16   thorpej #define	SET_FEATURES		0xef	/* set features */
    129       1.16   thorpej 
    130       1.16   thorpej #define	WDCC_IDLE		0xe3	/* set idle timer & enter idle mode */
    131       1.16   thorpej #define	WDCC_IDLE_IMMED		0xe1	/* enter idle mode */
    132       1.16   thorpej #define	WDCC_SLEEP		0xe6	/* enter sleep mode */
    133       1.16   thorpej #define	WDCC_STANDBY		0xe2	/* set standby timer & enter standby */
    134       1.16   thorpej #define	WDCC_STANDBY_IMMED	0xe0	/* enter standby mode */
    135       1.16   thorpej #define	WDCC_CHECK_PWR		0xe5	/* check power mode */
    136       1.16   thorpej 
    137       1.42  riastrad /* Security feature set */
    138       1.42  riastrad #define	WDCC_SECURITY_SET_PASSWORD	0xf1
    139       1.42  riastrad #define	WDCC_SECURITY_UNLOCK		0xf2
    140       1.42  riastrad #define	WDCC_SECURITY_ERASE_PREPARE	0xf3
    141       1.42  riastrad #define	WDCC_SECURITY_ERASE_UNIT	0xf4
    142       1.42  riastrad #define	WDCC_SECURITY_FREEZE		0xf5
    143       1.42  riastrad #define	WDCC_SECURITY_DISABLE_PASSWORD	0xf6
    144       1.23  drochner 
    145       1.16   thorpej /* Big Drive support */
    146       1.16   thorpej #define	WDCC_READ_EXT		0x24	/* read 48-bit addressing */
    147       1.16   thorpej #define	WDCC_WRITE_EXT		0x34	/* write 48-bit addressing */
    148       1.16   thorpej 
    149       1.16   thorpej #define	WDCC_READMULTI_EXT	0x29	/* read multiple 48-bit addressing */
    150       1.16   thorpej #define	WDCC_WRITEMULTI_EXT	0x39	/* write multiple 48-bit addressing */
    151       1.16   thorpej 
    152       1.16   thorpej #define	WDCC_READDMA_EXT	0x25	/* read 48-bit addressing with DMA */
    153       1.16   thorpej #define	WDCC_WRITEDMA_EXT	0x35	/* write 48-bit addressing with DMA */
    154  1.43.18.1  jdolecek #define	WDCC_WRITEDMA_FUA_EXT	0x3d	/* write 48-bit addr with DMA & FUA */
    155       1.16   thorpej 
    156       1.35   tsutsui #if defined(_KERNEL) || defined(_STANDALONE)
    157       1.28     itohy #include <dev/ata/ataconf.h>
    158       1.28     itohy 
    159       1.20   thorpej /* Convert a 32-bit command to a 48-bit command. */
    160       1.29  christos static __inline int
    161       1.20   thorpej atacmd_to48(int cmd32)
    162       1.20   thorpej {
    163       1.20   thorpej 	switch (cmd32) {
    164       1.20   thorpej 	case WDCC_READ:
    165       1.20   thorpej 		return WDCC_READ_EXT;
    166       1.20   thorpej 	case WDCC_WRITE:
    167       1.20   thorpej 		return WDCC_WRITE_EXT;
    168       1.20   thorpej 	case WDCC_READMULTI:
    169       1.20   thorpej 		return WDCC_READMULTI_EXT;
    170       1.20   thorpej 	case WDCC_WRITEMULTI:
    171       1.20   thorpej 		return WDCC_WRITEMULTI_EXT;
    172       1.28     itohy #if NATA_DMA
    173       1.20   thorpej 	case WDCC_READDMA:
    174       1.20   thorpej 		return WDCC_READDMA_EXT;
    175       1.20   thorpej 	case WDCC_WRITEDMA:
    176       1.20   thorpej 		return WDCC_WRITEDMA_EXT;
    177       1.28     itohy #endif
    178       1.20   thorpej 	default:
    179       1.20   thorpej 		panic("atacmd_to48: illegal 32-bit command: %d", cmd32);
    180       1.20   thorpej 		/* NOTREACHED */
    181       1.20   thorpej 	}
    182       1.20   thorpej }
    183       1.35   tsutsui #endif /* _KERNEL || _STANDALONE */
    184       1.20   thorpej 
    185       1.19   thorpej /* Native SATA command queueing */
    186       1.19   thorpej #define	WDCC_READ_FPDMA_QUEUED	0x60	/* SATA native queued read (48bit) */
    187       1.19   thorpej #define	WDCC_WRITE_FPDMA_QUEUED	0x61	/* SATA native queued write (48bit) */
    188       1.19   thorpej 
    189       1.21        he #ifdef _KERNEL
    190       1.20   thorpej /* Convert a 32-bit command to a Native SATA Queued command. */
    191       1.29  christos static __inline int
    192       1.20   thorpej atacmd_tostatq(int cmd32)
    193       1.20   thorpej {
    194       1.20   thorpej 	switch (cmd32) {
    195       1.20   thorpej 	case WDCC_READDMA:
    196       1.20   thorpej 		return WDCC_READ_FPDMA_QUEUED;
    197       1.20   thorpej 	case WDCC_WRITEDMA:
    198       1.20   thorpej 		return WDCC_WRITE_FPDMA_QUEUED;
    199       1.20   thorpej 	default:
    200       1.20   thorpej 		panic("atacmd_tosataq: illegal 32-bit command: %d", cmd32);
    201       1.20   thorpej 		/* NOTREACHED */
    202       1.20   thorpej 	}
    203       1.20   thorpej }
    204       1.21        he #endif /* _KERNEL */
    205       1.20   thorpej 
    206       1.16   thorpej /* Subcommands for SET_FEATURES (features register) */
    207       1.31  christos #define	WDSF_8BIT_PIO_EN	0x01
    208       1.16   thorpej #define	WDSF_WRITE_CACHE_EN	0x02
    209       1.16   thorpej #define	WDSF_SET_MODE		0x03
    210       1.16   thorpej #define	WDSF_REASSIGN_EN	0x04
    211       1.31  christos #define	WDSF_APM_EN		0x05
    212       1.39  jakllsch #define	WDSF_PUIS_EN		0x06
    213       1.39  jakllsch #define	WDSF_PUIS_SPIN_UP	0x07
    214       1.39  jakllsch #define	WDSF_SATA_EN		0x10
    215       1.16   thorpej #define	WDSF_RETRY_DS		0x33
    216       1.39  jakllsch #define	WDSF_AAM_EN		0x42
    217       1.16   thorpej #define	WDSF_SET_CACHE_SGMT	0x54
    218       1.16   thorpej #define	WDSF_READAHEAD_DS	0x55
    219       1.16   thorpej #define	WDSF_POD_DS		0x66
    220       1.16   thorpej #define	WDSF_ECC_DS		0x77
    221       1.16   thorpej #define	WDSF_WRITE_CACHE_DS	0x82
    222       1.16   thorpej #define	WDSF_REASSIGN_DS	0x84
    223       1.31  christos #define	WDSF_APM_DS		0x85
    224       1.39  jakllsch #define	WDSF_PUIS_DS		0x86
    225       1.16   thorpej #define	WDSF_ECC_EN		0x88
    226       1.39  jakllsch #define	WDSF_SATA_DS		0x90
    227       1.16   thorpej #define	WDSF_RETRY_EN		0x99
    228       1.16   thorpej #define	WDSF_SET_CURRENT	0x9a
    229       1.16   thorpej #define	WDSF_READAHEAD_EN	0xaa
    230       1.16   thorpej #define	WDSF_PREFETCH_SET	0xab
    231       1.39  jakllsch #define	WDSF_AAM_DS		0xc2
    232       1.16   thorpej #define	WDSF_POD_EN		0xcc
    233       1.16   thorpej 
    234       1.39  jakllsch /* Subcommands for WDSF_SATA (count register) */
    235       1.39  jakllsch #define	WDSF_SATA_NONZERO_OFFSETS	0x01
    236       1.39  jakllsch #define	WDSF_SATA_DMA_SETUP_AUTO	0x02
    237       1.39  jakllsch #define	WDSF_SATA_DRIVE_PWR_MGMT	0x03
    238       1.39  jakllsch #define	WDSF_SATA_IN_ORDER_DATA		0x04
    239       1.39  jakllsch #define	WDSF_SATA_ASYNC_NOTIFY		0x05
    240       1.39  jakllsch #define	WDSF_SATA_SW_STTNGS_PRS		0x06
    241       1.39  jakllsch 
    242       1.16   thorpej /* Subcommands for SMART (features register) */
    243       1.16   thorpej #define	WDSM_RD_DATA		0xd0
    244       1.16   thorpej #define	WDSM_RD_THRESHOLDS	0xd1
    245       1.16   thorpej #define	WDSM_ATTR_AUTOSAVE_EN	0xd2
    246       1.16   thorpej #define	WDSM_SAVE_ATTR		0xd3
    247       1.16   thorpej #define	WDSM_EXEC_OFFL_IMM	0xd4
    248       1.16   thorpej #define	WDSM_RD_LOG		0xd5
    249       1.16   thorpej #define	WDSM_ENABLE_OPS		0xd8
    250       1.16   thorpej #define	WDSM_DISABLE_OPS	0xd9
    251       1.16   thorpej #define	WDSM_STATUS		0xda
    252       1.16   thorpej 
    253       1.16   thorpej #define WDSMART_CYL		0xc24f
    254       1.16   thorpej 
    255  1.43.18.2  jdolecek /* parameters uploaded to count register for NCQ */
    256  1.43.18.2  jdolecek #define WDSC_PRIO_HIGH		__BIT(15)
    257  1.43.18.2  jdolecek #define WDSC_PRIO_ISOCHRONOUS	__BIT(14)
    258  1.43.18.2  jdolecek #define WDSC_PRIO_NORMAL	0x0000
    259  1.43.18.2  jdolecek 
    260       1.16   thorpej /* parameters uploaded to device/heads register */
    261       1.16   thorpej #define	WDSD_IBM		0xa0	/* forced to 512 byte sector, ecc */
    262       1.16   thorpej #define	WDSD_CHS		0x00	/* cylinder/head/sector addressing */
    263       1.16   thorpej #define	WDSD_LBA		0x40	/* logical block addressing */
    264  1.43.18.1  jdolecek #define	WDSD_FUA		0x80	/* Forced Unit Access (FUA) */
    265       1.16   thorpej 
    266       1.16   thorpej /* Commands for ATAPI devices */
    267       1.16   thorpej #define	ATAPI_CHECK_POWER_MODE	0xe5
    268       1.16   thorpej #define	ATAPI_EXEC_DRIVE_DIAGS	0x90
    269       1.16   thorpej #define	ATAPI_IDLE_IMMEDIATE	0xe1
    270       1.16   thorpej #define	ATAPI_NOP		0x00
    271       1.16   thorpej #define	ATAPI_PKT_CMD		0xa0
    272       1.16   thorpej #define	ATAPI_IDENTIFY_DEVICE	0xa1
    273       1.16   thorpej #define	ATAPI_SOFT_RESET	0x08
    274       1.16   thorpej #define	ATAPI_SLEEP		0xe6
    275       1.16   thorpej #define	ATAPI_STANDBY_IMMEDIATE	0xe0
    276       1.16   thorpej 
    277       1.16   thorpej /* Bytes used by ATAPI_PACKET_COMMAND (feature register) */
    278       1.16   thorpej #define	ATAPI_PKT_CMD_FTRE_DMA	0x01
    279       1.16   thorpej #define	ATAPI_PKT_CMD_FTRE_OVL	0x02
    280       1.16   thorpej 
    281       1.16   thorpej /* ireason */
    282       1.16   thorpej #define	WDCI_CMD		0x01	/* command(1) or data(0) */
    283       1.16   thorpej #define	WDCI_IN			0x02	/* transfer to(1) or from(0) the host */
    284       1.16   thorpej #define	WDCI_RELEASE		0x04	/* bus released until completion */
    285       1.16   thorpej 
    286       1.16   thorpej #define	PHASE_CMDOUT		(WDCS_DRQ | WDCI_CMD)
    287       1.16   thorpej #define	PHASE_DATAIN		(WDCS_DRQ | WDCI_IN)
    288       1.16   thorpej #define	PHASE_DATAOUT		(WDCS_DRQ)
    289       1.16   thorpej #define	PHASE_COMPLETED		(WDCI_IN | WDCI_CMD)
    290       1.16   thorpej #define	PHASE_ABORTED		(0)
    291       1.16   thorpej 
    292       1.16   thorpej /*
    293        1.2    bouyer  * Drive parameter structure for ATA/ATAPI.
    294        1.2    bouyer  * Bit fields: WDC_* : common to ATA/ATAPI
    295        1.2    bouyer  *             ATA_* : ATA only
    296        1.2    bouyer  *             ATAPI_* : ATAPI only.
    297        1.2    bouyer  */
    298        1.2    bouyer struct ataparams {
    299        1.2    bouyer     /* drive info */
    300       1.36  jakllsch     uint16_t	atap_config;		/* 0: general configuration */
    301       1.43  drochner #define WDC_CFG_CFA_MAGIC	0x848a
    302        1.2    bouyer #define WDC_CFG_ATAPI    	0x8000
    303        1.2    bouyer #define	ATA_CFG_REMOVABLE	0x0080
    304        1.2    bouyer #define	ATA_CFG_FIXED		0x0040
    305        1.2    bouyer #define ATAPI_CFG_TYPE_MASK	0x1f00
    306        1.2    bouyer #define ATAPI_CFG_TYPE(x) (((x) & ATAPI_CFG_TYPE_MASK) >> 8)
    307        1.2    bouyer #define	ATAPI_CFG_REMOV		0x0080
    308        1.2    bouyer #define ATAPI_CFG_DRQ_MASK	0x0060
    309        1.2    bouyer #define ATAPI_CFG_STD_DRQ	0x0000
    310        1.2    bouyer #define ATAPI_CFG_IRQ_DRQ	0x0020
    311        1.2    bouyer #define ATAPI_CFG_ACCEL_DRQ	0x0040
    312        1.2    bouyer #define ATAPI_CFG_CMD_MASK	0x0003
    313        1.2    bouyer #define ATAPI_CFG_CMD_12	0x0000
    314        1.2    bouyer #define ATAPI_CFG_CMD_16	0x0001
    315        1.2    bouyer /* words 1-9 are ATA only */
    316       1.36  jakllsch     uint16_t	atap_cylinders;		/* 1: # of non-removable cylinders */
    317       1.36  jakllsch     uint16_t	__reserved1;
    318       1.36  jakllsch     uint16_t	atap_heads;		/* 3: # of heads */
    319       1.36  jakllsch     uint16_t	__retired1[2];		/* 4-5: # of unform. bytes/track */
    320       1.36  jakllsch     uint16_t	atap_sectors;		/* 6: # of sectors */
    321       1.36  jakllsch     uint16_t	__retired2[3];
    322       1.36  jakllsch 
    323       1.36  jakllsch     uint8_t	atap_serial[20];	/* 10-19: serial number */
    324       1.36  jakllsch     uint16_t	__retired3[2];
    325       1.36  jakllsch     uint16_t	__obsolete1;
    326       1.36  jakllsch     uint8_t	atap_revision[8];	/* 23-26: firmware revision */
    327       1.36  jakllsch     uint8_t	atap_model[40];		/* 27-46: model number */
    328       1.36  jakllsch     uint16_t	atap_multi;		/* 47: maximum sectors per irq (ATA) */
    329       1.36  jakllsch     uint16_t	__reserved2;
    330       1.36  jakllsch     uint16_t	atap_capabilities1;	/* 49: capability flags */
    331        1.2    bouyer #define WDC_CAP_IORDY	0x0800
    332        1.2    bouyer #define WDC_CAP_IORDY_DSBL 0x0400
    333        1.2    bouyer #define	WDC_CAP_LBA	0x0200
    334        1.2    bouyer #define	WDC_CAP_DMA	0x0100
    335        1.2    bouyer #define ATA_CAP_STBY	0x2000
    336        1.2    bouyer #define ATAPI_CAP_INTERL_DMA	0x8000
    337        1.2    bouyer #define ATAPI_CAP_CMD_QUEUE	0x4000
    338        1.2    bouyer #define	ATAPI_CAP_OVERLP	0X2000
    339        1.2    bouyer #define ATAPI_CAP_ATA_RST	0x1000
    340       1.36  jakllsch     uint16_t	atap_capabilities2;	/* 50: capability flags (ATA) */
    341        1.4    tsubai #if BYTE_ORDER == LITTLE_ENDIAN
    342       1.36  jakllsch     uint8_t	__junk2;
    343       1.36  jakllsch     uint8_t	atap_oldpiotiming;	/* 51: old PIO timing mode */
    344       1.36  jakllsch     uint8_t	__junk3;
    345       1.36  jakllsch     uint8_t	atap_olddmatiming;	/* 52: old DMA timing mode (ATA) */
    346        1.4    tsubai #else
    347       1.36  jakllsch     uint8_t	atap_oldpiotiming;	/* 51: old PIO timing mode */
    348       1.36  jakllsch     uint8_t	__junk2;
    349       1.36  jakllsch     uint8_t	atap_olddmatiming;	/* 52: old DMA timing mode (ATA) */
    350       1.36  jakllsch     uint8_t	__junk3;
    351        1.4    tsubai #endif
    352       1.36  jakllsch     uint16_t	atap_extensions;	/* 53: extensions supported */
    353        1.2    bouyer #define WDC_EXT_UDMA_MODES	0x0004
    354        1.2    bouyer #define WDC_EXT_MODES		0x0002
    355        1.2    bouyer #define WDC_EXT_GEOM		0x0001
    356        1.2    bouyer /* words 54-62 are ATA only */
    357       1.36  jakllsch     uint16_t	atap_curcylinders;	/* 54: current logical cylinders */
    358       1.36  jakllsch     uint16_t	atap_curheads;		/* 55: current logical heads */
    359       1.36  jakllsch     uint16_t	atap_cursectors;	/* 56: current logical sectors/tracks */
    360       1.36  jakllsch     uint16_t	atap_curcapacity[2];	/* 57-58: current capacity */
    361       1.36  jakllsch     uint16_t	atap_curmulti;		/* 59: current multi-sector setting */
    362        1.2    bouyer #define WDC_MULTI_VALID 0x0100
    363        1.2    bouyer #define WDC_MULTI_MASK  0x00ff
    364       1.36  jakllsch     uint16_t	atap_capacity[2];  	/* 60-61: total capacity (LBA only) */
    365       1.36  jakllsch     uint16_t	__retired4;
    366        1.4    tsubai #if BYTE_ORDER == LITTLE_ENDIAN
    367       1.36  jakllsch     uint8_t	atap_dmamode_supp; 	/* 63: multiword DMA mode supported */
    368       1.36  jakllsch     uint8_t	atap_dmamode_act; 	/*     multiword DMA mode active */
    369       1.36  jakllsch     uint8_t	atap_piomode_supp;	/* 64: PIO mode supported */
    370       1.36  jakllsch     uint8_t	__junk4;
    371        1.4    tsubai #else
    372       1.36  jakllsch     uint8_t	atap_dmamode_act; 	/*     multiword DMA mode active */
    373       1.36  jakllsch     uint8_t	atap_dmamode_supp; 	/* 63: multiword DMA mode supported */
    374       1.36  jakllsch     uint8_t	__junk4;
    375       1.36  jakllsch     uint8_t	atap_piomode_supp;	/* 64: PIO mode supported */
    376        1.4    tsubai #endif
    377       1.36  jakllsch     uint16_t	atap_dmatiming_mimi;	/* 65: minimum DMA cycle time */
    378       1.36  jakllsch     uint16_t	atap_dmatiming_recom;	/* 66: recommended DMA cycle time */
    379       1.36  jakllsch     uint16_t	atap_piotiming;		/* 67: mini PIO cycle time without FC */
    380       1.36  jakllsch     uint16_t	atap_piotiming_iordy;	/* 68: mini PIO cycle time with IORDY FC */
    381       1.36  jakllsch     uint16_t	__reserved3[2];
    382        1.2    bouyer /* words 71-72 are ATAPI only */
    383       1.36  jakllsch     uint16_t	atap_pkt_br;		/* 71: time (ns) to bus release */
    384       1.36  jakllsch     uint16_t	atap_pkt_bsyclr;	/* 72: tme to clear BSY after service */
    385       1.36  jakllsch     uint16_t	__reserved4[2];
    386       1.36  jakllsch     uint16_t	atap_queuedepth;	/* 75: */
    387       1.30    bouyer #define WDC_QUEUE_DEPTH_MASK 0x1F
    388       1.36  jakllsch     uint16_t	atap_sata_caps;		/* 76: */
    389       1.10       skd #define SATA_SIGNAL_GEN1	0x02
    390       1.10       skd #define SATA_SIGNAL_GEN2	0x04
    391       1.40  jakllsch #define SATA_SIGNAL_GEN3	0x08
    392  1.43.18.2  jdolecek #define SATA_NATIVE_CMDQ	0x0100	/* supp. NCQ feature set */
    393  1.43.18.2  jdolecek #define SATA_HOST_PWR_MGMT	0x0200	/* supp. host-init. pwr mngmt reqs */
    394  1.43.18.2  jdolecek #define SATA_PHY_EVNT_CNT	0x0400	/* supp. SATA Phy Event Counters log */
    395  1.43.18.2  jdolecek #define SATA_UNLOAD_W_NCQ	0x0800	/* supp. unload w/ NCQ commands act */
    396  1.43.18.2  jdolecek #define SATA_NCQ_PRIO		0x1000	/* supp. NCQ priority information */
    397       1.36  jakllsch     uint16_t	atap_sata_reserved;	/* 77: */
    398       1.36  jakllsch     uint16_t	atap_sata_features_supp; /* 78: */
    399       1.10       skd #define SATA_NONZERO_OFFSETS	0x02
    400       1.10       skd #define SATA_DMA_SETUP_AUTO	0x04
    401       1.10       skd #define SATA_DRIVE_PWR_MGMT	0x08
    402       1.30    bouyer #define SATA_IN_ORDER_DATA	0x10
    403       1.30    bouyer #define SATA_SW_STTNGS_PRS	0x40
    404       1.36  jakllsch     uint16_t	atap_sata_features_en;	/* 79: */
    405       1.36  jakllsch     uint16_t	atap_ata_major;  	/* 80: Major version number */
    406        1.2    bouyer #define	WDC_VER_ATA1	0x0002
    407        1.2    bouyer #define	WDC_VER_ATA2	0x0004
    408        1.2    bouyer #define	WDC_VER_ATA3	0x0008
    409        1.2    bouyer #define	WDC_VER_ATA4	0x0010
    410        1.5    bouyer #define	WDC_VER_ATA5	0x0020
    411       1.10       skd #define	WDC_VER_ATA6	0x0040
    412       1.14      yamt #define	WDC_VER_ATA7	0x0080
    413       1.41  drochner #define	WDC_VER_ATA8	0x0100
    414       1.36  jakllsch     uint16_t	atap_ata_minor;		/* 81: Minor version number */
    415       1.36  jakllsch     uint16_t	atap_cmd_set1;		/* 82: command set supported */
    416       1.14      yamt #define	WDC_CMD1_NOP	0x4000		/*	NOP */
    417       1.14      yamt #define	WDC_CMD1_RB	0x2000		/*	READ BUFFER */
    418       1.14      yamt #define	WDC_CMD1_WB	0x1000		/*	WRITE BUFFER */
    419       1.14      yamt /*			0x0800			Obsolete */
    420       1.14      yamt #define	WDC_CMD1_HPA	0x0400		/*	Host Protected Area */
    421       1.14      yamt #define	WDC_CMD1_DVRST	0x0200		/*	DEVICE RESET */
    422       1.14      yamt #define	WDC_CMD1_SRV	0x0100		/*	SERVICE */
    423       1.14      yamt #define	WDC_CMD1_RLSE	0x0080		/*	release interrupt */
    424       1.14      yamt #define	WDC_CMD1_AHEAD	0x0040		/*	look-ahead */
    425       1.14      yamt #define	WDC_CMD1_CACHE	0x0020		/*	write cache */
    426       1.14      yamt #define	WDC_CMD1_PKT	0x0010		/*	PACKET */
    427       1.14      yamt #define	WDC_CMD1_PM	0x0008		/*	Power Management */
    428       1.14      yamt #define	WDC_CMD1_REMOV	0x0004		/*	Removable Media */
    429       1.14      yamt #define	WDC_CMD1_SEC	0x0002		/*	Security Mode */
    430       1.14      yamt #define	WDC_CMD1_SMART	0x0001		/*	SMART */
    431       1.36  jakllsch     uint16_t	atap_cmd_set2;		/* 83: command set supported */
    432       1.14      yamt #define	ATA_CMD2_FCE	0x2000		/*	FLUSH CACHE EXT */
    433       1.14      yamt #define	WDC_CMD2_FC	0x1000		/*	FLUSH CACHE */
    434       1.14      yamt #define	WDC_CMD2_DCO	0x0800		/*	Device Configuration Overlay */
    435       1.14      yamt #define	ATA_CMD2_LBA48	0x0400		/*	48-bit Address */
    436       1.14      yamt #define	WDC_CMD2_AAM	0x0200		/*	Automatic Acoustic Management */
    437       1.17       wiz #define	WDC_CMD2_SM	0x0100		/*	SET MAX security extension */
    438       1.14      yamt #define	WDC_CMD2_SFREQ	0x0040		/*	SET FEATURE is required
    439       1.14      yamt 						to spin-up after power-up */
    440       1.14      yamt #define	WDC_CMD2_PUIS	0x0020		/*	Power-Up In Standby */
    441       1.14      yamt #define	WDC_CMD2_RMSN	0x0010		/*	Removable Media Status Notify */
    442       1.14      yamt #define	ATA_CMD2_APM	0x0008		/*	Advanced Power Management */
    443       1.14      yamt #define	ATA_CMD2_CFA	0x0004		/*	CFA */
    444       1.14      yamt #define	ATA_CMD2_RWQ	0x0002		/*	READ/WRITE DMA QUEUED */
    445       1.14      yamt #define	WDC_CMD2_DM	0x0001		/*	DOWNLOAD MICROCODE */
    446       1.36  jakllsch     uint16_t	atap_cmd_ext;		/* 84: command/features supp. ext. */
    447       1.14      yamt #define	ATA_CMDE_TLCONT	0x1000		/*	Time-limited R/W Continuous */
    448       1.14      yamt #define	ATA_CMDE_TL	0x0800		/*	Time-limited R/W */
    449       1.14      yamt #define	ATA_CMDE_URGW	0x0400		/*	URG for WRITE STREAM DMA/PIO */
    450       1.14      yamt #define	ATA_CMDE_URGR	0x0200		/*	URG for READ STREAM DMA/PIO */
    451       1.14      yamt #define	ATA_CMDE_WWN	0x0100		/*	World Wide name */
    452       1.14      yamt #define	ATA_CMDE_WQFE	0x0080		/*	WRITE DMA QUEUED FUA EXT */
    453       1.14      yamt #define	ATA_CMDE_WFE	0x0040		/*	WRITE DMA/MULTIPLE FUA EXT */
    454       1.14      yamt #define	ATA_CMDE_GPL	0x0020		/*	General Purpose Logging */
    455       1.14      yamt #define	ATA_CMDE_STREAM	0x0010		/*	Streaming */
    456       1.14      yamt #define	ATA_CMDE_MCPTC	0x0008		/*	Media Card Pass Through Cmd */
    457       1.14      yamt #define	ATA_CMDE_MS	0x0004		/*	Media serial number */
    458       1.14      yamt #define	ATA_CMDE_SST	0x0002		/*	SMART self-test */
    459       1.14      yamt #define	ATA_CMDE_SEL	0x0001		/*	SMART error logging */
    460       1.36  jakllsch     uint16_t	atap_cmd1_en;		/* 85: cmd/features enabled */
    461        1.2    bouyer /* bits are the same as atap_cmd_set1 */
    462       1.36  jakllsch     uint16_t	atap_cmd2_en;		/* 86: cmd/features enabled */
    463        1.2    bouyer /* bits are the same as atap_cmd_set2 */
    464       1.36  jakllsch     uint16_t	atap_cmd_def;		/* 87: cmd/features default */
    465        1.4    tsubai #if BYTE_ORDER == LITTLE_ENDIAN
    466       1.36  jakllsch     uint8_t	atap_udmamode_supp; 	/* 88: Ultra-DMA mode supported */
    467       1.36  jakllsch     uint8_t	atap_udmamode_act; 	/*     Ultra-DMA mode active */
    468        1.4    tsubai #else
    469       1.36  jakllsch     uint8_t	atap_udmamode_act; 	/*     Ultra-DMA mode active */
    470       1.36  jakllsch     uint8_t	atap_udmamode_supp; 	/* 88: Ultra-DMA mode supported */
    471        1.4    tsubai #endif
    472        1.2    bouyer /* 89-92 are ATA-only */
    473       1.36  jakllsch     uint16_t	atap_seu_time;		/* 89: Sec. Erase Unit compl. time */
    474       1.36  jakllsch     uint16_t	atap_eseu_time;		/* 90: Enhanced SEU compl. time */
    475       1.36  jakllsch     uint16_t	atap_apm_val;		/* 91: current APM value */
    476       1.36  jakllsch     uint16_t	__reserved5[8];		/* 92-99: reserved */
    477       1.36  jakllsch     uint16_t	atap_max_lba[4];	/* 100-103: Max. user LBA addr */
    478       1.41  drochner     uint16_t	__reserved6;		/* 104: reserved */
    479       1.41  drochner     uint16_t	max_dsm_blocks;		/* 105: DSM (ATA-8/ACS-2) */
    480       1.38  jakllsch     uint16_t	atap_secsz;		/* 106: physical/logical sector size */
    481       1.38  jakllsch #define ATA_SECSZ_VALID_MASK 0xc000
    482       1.38  jakllsch #define ATA_SECSZ_VALID      0x4000
    483       1.38  jakllsch #define ATA_SECSZ_LPS        0x2000	/* long physical sectors */
    484       1.38  jakllsch #define ATA_SECSZ_LLS        0x1000	/* long logical sectors */
    485       1.38  jakllsch #define ATA_SECSZ_LPS_SZMSK  0x000f	/* 2**N logical per physical */
    486       1.38  jakllsch     uint16_t	atap_iso7779_isd;	/* 107: ISO 7779 inter-seek delay */
    487       1.36  jakllsch     uint16_t 	atap_wwn[4];		/* 108-111: World Wide Name */
    488       1.38  jakllsch     uint16_t	__reserved7[5];		/* 112-116 */
    489       1.38  jakllsch     uint16_t	atap_lls_secsz[2];	/* 117-118: long logical sector size */
    490       1.38  jakllsch     uint16_t	__reserved8[8];		/* 119-126 */
    491       1.36  jakllsch     uint16_t	atap_rmsn_supp;		/* 127: remov. media status notif. */
    492        1.2    bouyer #define WDC_RMSN_SUPP_MASK 0x0003
    493        1.2    bouyer #define WDC_RMSN_SUPP 0x0001
    494       1.36  jakllsch     uint16_t	atap_sec_st;		/* 128: security status */
    495        1.2    bouyer #define WDC_SEC_LEV_MAX	0x0100
    496        1.2    bouyer #define WDC_SEC_ESE_SUPP 0x0020
    497        1.2    bouyer #define WDC_SEC_EXP	0x0010
    498        1.2    bouyer #define WDC_SEC_FROZEN	0x0008
    499        1.2    bouyer #define WDC_SEC_LOCKED	0x0004
    500        1.2    bouyer #define WDC_SEC_EN	0x0002
    501        1.2    bouyer #define WDC_SEC_SUPP	0x0001
    502       1.38  jakllsch     uint16_t	__reserved9[31];	/* 129-159: vendor specific */
    503       1.38  jakllsch     uint16_t	atap_cfa_power;		/* 160: CFA powermode */
    504       1.38  jakllsch #define ATA_CFA_MAX_MASK  0x0fff
    505       1.38  jakllsch #define ATA_CFA_MODE1_DIS 0x1000	/* CFA Mode 1 Disabled */
    506       1.38  jakllsch #define ATA_CFA_MODE1_REQ 0x2000	/* CFA Mode 1 Required */
    507       1.38  jakllsch #define ATA_CFA_WORD160   0x8000	/* Word 160 supported */
    508       1.41  drochner     uint16_t	__reserved10[8];	/* 161-168: reserved for CFA */
    509       1.41  drochner     uint16_t	support_dsm;		/* 169: DSM (ATA-8/ACS-2) */
    510       1.41  drochner #define ATA_SUPPORT_DSM_TRIM	0x0001
    511       1.41  drochner     uint16_t	__reserved10a[6];	/* 170-175: reserved for CFA */
    512       1.38  jakllsch     uint8_t	atap_media_serial[60];	/* 176-205: media serial number */
    513       1.38  jakllsch     uint16_t	__reserved11[3];	/* 206-208: */
    514       1.38  jakllsch     uint16_t	atap_logical_align;	/* 209: logical/physical alignment */
    515       1.38  jakllsch #define ATA_LA_VALID_MASK 0xc000
    516       1.38  jakllsch #define ATA_LA_VALID      0x4000
    517       1.38  jakllsch #define ATA_LA_MASK       0x3fff	/* offset of sector LBA 0 in PBA 0 */
    518       1.38  jakllsch     uint16_t	__reserved12[45];	/* 210-254: */
    519       1.38  jakllsch     uint16_t	atap_integrity;		/* 255: Integrity word */
    520       1.38  jakllsch #define WDC_INTEGRITY_MAGIC_MASK 0x00ff
    521       1.38  jakllsch #define WDC_INTEGRITY_MAGIC      0x00a5
    522        1.2    bouyer };
    523       1.15   thorpej 
    524       1.15   thorpej /*
    525       1.15   thorpej  * If WDSM_ATTR_ADVISORY, device exceeded intended design life period.
    526       1.15   thorpej  * If not WDSM_ATTR_ADVISORY, imminent data loss predicted.
    527       1.15   thorpej  */
    528       1.15   thorpej #define WDSM_ATTR_ADVISORY	1
    529       1.15   thorpej 
    530       1.15   thorpej /*
    531       1.15   thorpej  * If WDSM_ATTR_COLLECTIVE, attribute only updated in off-line testing.
    532       1.15   thorpej  * If not WDSM_ATTR_COLLECTIVE, attribute updated also in on-line testing.
    533       1.15   thorpej  */
    534       1.15   thorpej #define WDSM_ATTR_COLLECTIVE	2
    535       1.15   thorpej 
    536       1.16   thorpej /*
    537       1.16   thorpej  * ATA SMART attributes
    538       1.16   thorpej  */
    539       1.16   thorpej 
    540       1.15   thorpej struct ata_smart_attr {
    541       1.36  jakllsch 	uint8_t		id;		/* attribute id number */
    542       1.36  jakllsch 	uint16_t	flags;
    543       1.36  jakllsch 	uint8_t		value;		/* attribute value */
    544       1.36  jakllsch 	uint8_t		worst;
    545       1.36  jakllsch 	uint8_t		raw[6];
    546       1.36  jakllsch 	uint8_t		reserved;
    547       1.32     perry } __packed;
    548       1.15   thorpej 
    549       1.15   thorpej struct ata_smart_attributes {
    550       1.36  jakllsch 	uint16_t	data_structure_revision;
    551       1.36  jakllsch 	struct ata_smart_attr attributes[30];
    552       1.36  jakllsch 	uint8_t		offline_data_collection_status;
    553       1.36  jakllsch 	uint8_t		self_test_exec_status;
    554       1.36  jakllsch 	uint16_t	total_time_to_complete_off_line;
    555       1.36  jakllsch 	uint8_t		vendor_specific_366;
    556       1.36  jakllsch 	uint8_t		offline_data_collection_capability;
    557       1.36  jakllsch 	uint16_t	smart_capability;
    558       1.36  jakllsch 	uint8_t		errorlog_capability;
    559       1.36  jakllsch 	uint8_t		vendor_specific_371;
    560       1.36  jakllsch 	uint8_t		short_test_completion_time;
    561       1.36  jakllsch 	uint8_t		extend_test_completion_time;
    562       1.36  jakllsch 	uint8_t		reserved_374_385[12];
    563       1.36  jakllsch 	uint8_t		vendor_specific_386_509[125];
    564       1.36  jakllsch 	int8_t		checksum;
    565       1.32     perry } __packed;
    566       1.15   thorpej 
    567       1.15   thorpej struct ata_smart_thresh {
    568       1.36  jakllsch 	uint8_t		id;
    569       1.36  jakllsch 	uint8_t		value;
    570       1.36  jakllsch 	uint8_t		reserved[10];
    571       1.32     perry } __packed;
    572       1.15   thorpej 
    573       1.15   thorpej struct ata_smart_thresholds {
    574       1.37  jakllsch 	uint16_t	data_structure_revision;
    575       1.15   thorpej 	struct ata_smart_thresh	thresholds[30];
    576       1.36  jakllsch 	uint8_t		reserved[18];
    577       1.36  jakllsch 	uint8_t		vendor_specific[131];
    578       1.36  jakllsch 	int8_t		checksum;
    579       1.32     perry } __packed;
    580       1.15   thorpej 
    581       1.15   thorpej struct ata_smart_selftest {
    582       1.36  jakllsch 	uint8_t		number;
    583       1.36  jakllsch 	uint8_t		status;
    584       1.36  jakllsch 	uint16_t	time_stamp;
    585       1.36  jakllsch 	uint8_t		failure_check_point;
    586       1.36  jakllsch 	uint32_t	lba_first_error;
    587       1.36  jakllsch 	uint8_t		vendor_specific[15];
    588       1.32     perry } __packed;
    589       1.15   thorpej 
    590       1.15   thorpej struct ata_smart_selftestlog {
    591       1.36  jakllsch 	uint16_t	data_structure_revision;
    592       1.15   thorpej 	struct ata_smart_selftest log_entries[21];
    593       1.36  jakllsch 	uint8_t		vendorspecific[2];
    594       1.36  jakllsch 	uint8_t		mostrecenttest;
    595       1.36  jakllsch 	uint8_t		reserved[2];
    596       1.36  jakllsch 	uint8_t		checksum;
    597       1.32     perry } __packed;
    598       1.15   thorpej 
    599       1.15   thorpej #endif /* _DEV_ATA_ATAREG_H_ */
    600