1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 2007, 2010, Oracle and/or its affiliates. All rights reserved. 24 * Copyright 2013 Nexenta Systems, Inc. All rights reserved. 25 * Copyright 2019 Joyent, Inc. 26 * Copyright 2024 RackTop Systems, Inc. 27 */ 28 29 #ifndef _SATA_DEFS_H 30 #define _SATA_DEFS_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 #include <sys/scsi/generic/mode.h> 37 38 /* 39 * Common ATA commands (subset) 40 */ 41 #define SATAC_DIAG 0x90 /* diagnose command */ 42 #define SATAC_RECAL 0x10 /* restore cmd, 4 bits step rate */ 43 #define SATAC_FORMAT 0x50 /* format track command */ 44 #define SATAC_SET_FEATURES 0xef /* set features */ 45 #define SATAC_IDLE_IM 0xe1 /* idle immediate */ 46 #define SATAC_STANDBY_IM 0xe0 /* standby immediate */ 47 #define SATAC_DOOR_LOCK 0xde /* door lock */ 48 #define SATAC_DOOR_UNLOCK 0xdf /* door unlock */ 49 #define SATAC_IDLE 0xe3 /* idle */ 50 #define SATAC_STANDBY 0xe2 /* standby */ 51 52 /* 53 * ATA/ATAPI disk commands (subset) 54 */ 55 #define SATAC_DSM 0x06 /* Data Set Management */ 56 #define SATAC_DEVICE_RESET 0x08 /* ATAPI device reset */ 57 #define SATAC_DOWNLOAD_MICROCODE 0x92 /* Download microcode */ 58 #define SATAC_EJECT 0xed /* media eject */ 59 #define SATAC_FLUSH_CACHE 0xe7 /* flush write-cache */ 60 #define SATAC_ID_DEVICE 0xec /* IDENTIFY DEVICE */ 61 #define SATAC_ID_PACKET_DEVICE 0xa1 /* ATAPI identify packet device */ 62 #define SATAC_INIT_DEVPARMS 0x91 /* initialize device parameters */ 63 #define SATAC_PACKET 0xa0 /* ATAPI packet */ 64 #define SATAC_RDMULT 0xc4 /* read multiple w/DMA */ 65 #define SATAC_RDSEC 0x20 /* read sector */ 66 #define SATAC_RDVER 0x40 /* read verify */ 67 #define SATAC_READ_DMA 0xc8 /* read DMA */ 68 #define SATAC_SEEK 0x70 /* seek */ 69 #define SATAC_SERVICE 0xa2 /* queued/overlap service */ 70 #define SATAC_SETMULT 0xc6 /* set multiple mode */ 71 #define SATAC_WRITE_DMA 0xca /* write (multiple) w/DMA */ 72 #define SATAC_WRMULT 0xc5 /* write multiple */ 73 #define SATAC_WRSEC 0x30 /* write sector */ 74 #define SATAC_RDSEC_EXT 0x24 /* read sector extended (LBA48) */ 75 #define SATAC_READ_DMA_EXT 0x25 /* read DMA extended (LBA48) */ 76 #define SATAC_RDMULT_EXT 0x29 /* read multiple extended (LBA48) */ 77 #define SATAC_WRSEC_EXT 0x34 /* read sector extended (LBA48) */ 78 #define SATAC_WRITE_DMA_EXT 0x35 /* read DMA extended (LBA48) */ 79 #define SATAC_WRMULT_EXT 0x39 /* read multiple extended (LBA48) */ 80 81 #define SATAC_READ_DMA_QUEUED 0xc7 /* read DMA / may be queued */ 82 #define SATAC_READ_DMA_QUEUED_EXT 0x26 /* read DMA ext / may be queued */ 83 #define SATAC_WRITE_DMA_QUEUED 0xcc /* read DMA / may be queued */ 84 #define SATAC_WRITE_DMA_QUEUED_EXT 0x36 /* read DMA ext / may be queued */ 85 #define SATAC_READ_PM_REG 0xe4 /* read port mult reg */ 86 #define SATAC_WRITE_PM_REG 0xe8 /* write port mult reg */ 87 88 #define SATAC_READ_FPDMA_QUEUED 0x60 /* First-Party-DMA read queued */ 89 #define SATAC_WRITE_FPDMA_QUEUED 0x61 /* First-Party-DMA write queued */ 90 91 #define SATAC_READ_LOG_EXT 0x2f /* read log */ 92 93 #define SATAC_SMART 0xb0 /* SMART */ 94 95 #define SATA_LOG_PAGE_10 0x10 /* log page 0x10 - SATA error */ 96 /* 97 * Port Multiplier Commands 98 */ 99 #define SATAC_READ_PORTMULT 0xe4 /* read port multiplier */ 100 #define SATAC_WRITE_PORTMULT 0xe8 /* write port multiplier */ 101 102 /* 103 * Power Managment Commands (subset) 104 */ 105 #define SATAC_CHECK_POWER_MODE 0xe5 /* check power mode */ 106 107 #define SATA_PWRMODE_STANDBY 0 /* standby mode */ 108 #define SATA_PWRMODE_IDLE 0x80 /* idle mode */ 109 #define SATA_PWRMODE_ACTIVE_SPINDOWN 0x40 /* PM0 and spinning down */ 110 #define SATA_PWRMODE_ACTIVE_SPINUP 0x41 /* PM0 and spinning up */ 111 #define SATA_PWRMODE_ACTIVE 0xFF /* active or idle mode */ 112 113 114 /* 115 * SMART FEATURES Subcommands 116 */ 117 #define SATA_SMART_READ_DATA 0xd0 118 #define SATA_SMART_ATTR_AUTOSAVE 0xd2 119 #define SATA_SMART_EXECUTE_OFFLINE_IMM 0xd4 120 #define SATA_SMART_READ_LOG 0xd5 121 #define SATA_SMART_WRITE_LOG 0xd6 122 #define SATA_SMART_ENABLE_OPS 0xd8 123 #define SATA_SMART_DISABLE_OPS 0xd9 124 #define SATA_SMART_RETURN_STATUS 0xda 125 126 /* 127 * SET FEATURES Subcommands 128 */ 129 #define SATAC_SF_ENABLE_WRITE_CACHE 0x02 130 #define SATAC_SF_TRANSFER_MODE 0x03 131 #define SATAC_SF_DISABLE_RMSN 0x31 132 #define SATAC_SF_ENABLE_ACOUSTIC 0x42 133 #define SATAC_SF_DISABLE_READ_AHEAD 0x55 134 #define SATAC_SF_DISABLE_WRITE_CACHE 0x82 135 #define SATAC_SF_ENABLE_READ_AHEAD 0xaa 136 #define SATAC_SF_DISABLE_ACOUSTIC 0xc2 137 #define SATAC_SF_ENABLE_RMSN 0x95 138 139 /* 140 * SET FEATURES transfer mode values 141 */ 142 #define SATAC_TRANSFER_MODE_PIO_DEFAULT 0x00 143 #define SATAC_TRANSFER_MODE_PIO_DISABLE_IODRY 0x01 144 #define SATAC_TRANSFER_MODE_PIO_FLOW_CONTROL 0x08 145 #define SATAC_TRANSFER_MODE_MULTI_WORD_DMA 0x20 146 #define SATAC_TRANSFER_MODE_ULTRA_DMA 0x40 147 148 /* 149 * Download microcode subcommands 150 */ 151 #define SATA_DOWNLOAD_MCODE_TEMP 1 /* Revert on/ reset/pwr cycle */ 152 #define SATA_DOWNLOAD_MCODE_SAVE 7 /* No offset, keep mcode */ 153 154 155 /* Generic ATA definitions */ 156 157 #define SATA_TAG_QUEUING_SHIFT 3 158 #define SATA_TAG_QUEUING_MASK 0x1f 159 /* 160 * Identify Device data 161 * Although both ATA and ATAPI devices' Identify Data have the same length, 162 * some words have different meaning/content and/or are irrelevant for 163 * other type of device. 164 * Following is the ATA Device Identify data layout 165 */ 166 typedef struct sata_id { 167 /* WORD */ 168 /* OFFSET COMMENT */ 169 ushort_t ai_config; /* 0 general configuration bits */ 170 ushort_t ai_fixcyls; /* 1 # of cylinders (obsolete) */ 171 ushort_t ai_resv0; /* 2 # reserved */ 172 ushort_t ai_heads; /* 3 # of heads (obsolete) */ 173 ushort_t ai_trksiz; /* 4 # of bytes/track (retired) */ 174 ushort_t ai_secsiz; /* 5 # of bytes/sector (retired) */ 175 ushort_t ai_sectors; /* 6 # of sectors/track (obsolete) */ 176 ushort_t ai_resv1[3]; /* 7 "Vendor Unique" */ 177 char ai_drvser[20]; /* 10 Serial number */ 178 ushort_t ai_buftype; /* 20 Buffer type */ 179 ushort_t ai_bufsz; /* 21 Buffer size in 512 byte incr */ 180 ushort_t ai_ecc; /* 22 # of ecc bytes avail on rd/wr */ 181 char ai_fw[8]; /* 23 Firmware revision */ 182 char ai_model[40]; /* 27 Model # */ 183 ushort_t ai_mult1; /* 47 Multiple command flags */ 184 ushort_t ai_dwcap; /* 48 Doubleword capabilities */ 185 ushort_t ai_cap; /* 49 Capabilities */ 186 ushort_t ai_resv2; /* 50 Reserved */ 187 ushort_t ai_piomode; /* 51 PIO timing mode */ 188 ushort_t ai_dmamode; /* 52 DMA timing mode */ 189 ushort_t ai_validinfo; /* 53 bit0: wds 54-58, bit1: 64-70 */ 190 ushort_t ai_curcyls; /* 54 # of current cylinders */ 191 ushort_t ai_curheads; /* 55 # of current heads */ 192 ushort_t ai_cursectrk; /* 56 # of current sectors/track */ 193 ushort_t ai_cursccp[2]; /* 57 current sectors capacity */ 194 ushort_t ai_mult2; /* 59 multiple sectors info */ 195 ushort_t ai_addrsec[2]; /* 60 LBA only: no of addr secs */ 196 ushort_t ai_dirdma; /* 62 valid in ATA/ATAPI7, DMADIR */ 197 ushort_t ai_dworddma; /* 63 multi word dma modes */ 198 ushort_t ai_advpiomode; /* 64 advanced PIO modes supported */ 199 ushort_t ai_minmwdma; /* 65 min multi-word dma cycle info */ 200 ushort_t ai_recmwdma; /* 66 rec multi-word dma cycle info */ 201 ushort_t ai_minpio; /* 67 min PIO cycle info */ 202 ushort_t ai_minpioflow; /* 68 min PIO cycle info w/flow ctl */ 203 ushort_t ai_addsupported; /* 69 additional supported */ 204 ushort_t ai_resv3; /* 70 reserved */ 205 ushort_t ai_typtime[2]; /* 71-72 timing */ 206 ushort_t ai_resv4[2]; /* 73-74 reserved */ 207 ushort_t ai_qdepth; /* 75 queue depth */ 208 ushort_t ai_satacap; /* 76 SATA capabilities */ 209 ushort_t ai_resv5; /* 77 reserved */ 210 ushort_t ai_satafsup; /* 78 SATA features supported */ 211 ushort_t ai_satafenbl; /* 79 SATA features enabled */ 212 ushort_t ai_majorversion; /* 80 major versions supported */ 213 ushort_t ai_minorversion; /* 81 minor version number supported */ 214 ushort_t ai_cmdset82; /* 82 command set supported */ 215 ushort_t ai_cmdset83; /* 83 more command sets supported */ 216 ushort_t ai_cmdset84; /* 84 more command sets supported */ 217 ushort_t ai_features85; /* 85 enabled features */ 218 ushort_t ai_features86; /* 86 enabled features */ 219 ushort_t ai_features87; /* 87 enabled features */ 220 ushort_t ai_ultradma; /* 88 Ultra DMA mode */ 221 ushort_t ai_erasetime; /* 89 security erase time */ 222 ushort_t ai_erasetimex; /* 90 enhanced security erase time */ 223 ushort_t ai_adv_pwr_mgmt; /* 91 advanced power management time */ 224 ushort_t ai_master_pwd; /* 92 master password revision code */ 225 ushort_t ai_hrdwre_reset; /* 93 hardware reset result */ 226 ushort_t ai_acoustic; /* 94 accoustic management values */ 227 ushort_t ai_stream_min_sz; /* 95 stream minimum request size */ 228 ushort_t ai_stream_xfer_d; /* 96 streaming transfer time (DMA) */ 229 ushort_t ai_stream_lat; /* 97 streaming access latency */ 230 ushort_t ai_streamperf[2]; /* 98-99 streaming performance gran. */ 231 ushort_t ai_addrsecxt[4]; /* 100 extended max LBA sector */ 232 ushort_t ai_stream_xfer_p; /* 104 streaming transfer time (PIO) */ 233 ushort_t ai_maxcount; /* 105 max count of 512-byte blocks of */ 234 /* LBA range entries */ 235 ushort_t ai_phys_sect_sz; /* 106 physical sector size */ 236 ushort_t ai_seek_delay; /* 107 inter-seek delay time (usecs) */ 237 ushort_t ai_naa_ieee_oui; /* 108 NAA/IEEE OUI */ 238 ushort_t ai_ieee_oui_uid; /* 109 IEEE OUT/unique id */ 239 ushort_t ai_uid_mid; /* 110 unique id (mid) */ 240 ushort_t ai_uid_low; /* 111 unique id (low) */ 241 ushort_t ai_resv_wwn[4]; /* 112-115 reserved for WWN ext. */ 242 ushort_t ai_incits; /* 116 reserved for INCITS TR-37-2004 */ 243 ushort_t ai_words_lsec[2]; /* 117-118 words per logical sector */ 244 ushort_t ai_cmdset119; /* 119 more command sets supported */ 245 ushort_t ai_features120; /* 120 enabled features */ 246 ushort_t ai_padding1[6]; /* pad to 126 */ 247 ushort_t ai_rmsn; /* 127 removable media notification */ 248 ushort_t ai_securestatus; /* 128 security status */ 249 ushort_t ai_vendor[31]; /* 129-159 vendor specific */ 250 ushort_t ai_padding2[8]; /* 160 pad to 168 */ 251 ushort_t ai_nomformfactor; /* 168 nominal form factor */ 252 ushort_t ai_dsm; /* 169 data set management */ 253 ushort_t ai_padding3[6]; /* 170 pad to 176 */ 254 ushort_t ai_curmedser[30]; /* 176-205 current media serial # */ 255 ushort_t ai_sctsupport; /* 206 SCT command transport */ 256 ushort_t ai_padding4[10]; /* 207 pad to 217 */ 257 ushort_t ai_medrotrate; /* 217 nominal media rotation rate */ 258 ushort_t ai_padding5[37]; /* 218 pad to 255 */ 259 ushort_t ai_integrity; /* 255 integrity word */ 260 } sata_id_t; 261 262 263 /* Identify Device: general config bits - word 0 */ 264 265 #define SATA_ATA_TYPE_MASK 0x8001 /* ATA Device type mask */ 266 #define SATA_ATA_TYPE 0x0000 /* ATA device */ 267 #define SATA_REM_MEDIA 0x0080 /* Removable media */ 268 #define SATA_INCOMPLETE_DATA 0x0004 /* Incomplete Identify Device data */ 269 #define SATA_CFA_TYPE 0x848a /* CFA feature set device */ 270 271 #define SATA_ID_SERIAL_OFFSET 10 272 #define SATA_ID_SERIAL_LEN 20 273 #define SATA_ID_MODEL_OFFSET 27 274 #define SATA_ID_MODEL_LEN 40 275 #define SATA_ID_FW_LEN 8 276 #define SATA_ID_BDC_LEN 0x3c 277 #define SATA_ID_ATA_INFO_LEN 0x238 278 279 /* Identify Device: common capability bits - word 49 */ 280 281 #define SATA_DMA_SUPPORT 0x0100 282 #define SATA_LBA_SUPPORT 0x0200 283 #define SATA_IORDY_DISABLE 0x0400 284 #define SATA_IORDY_SUPPORT 0x0800 285 #define SATA_STANDBYTIMER 0x2000 286 287 /* Identify Device: ai_validinfo (word 53) */ 288 289 #define SATA_VALIDINFO_88 0x0004 /* word 88 supported fields valid */ 290 #define SATA_VALIDINFO_70_64 0x0004 /* words 70-64 fields valid */ 291 292 /* Identify Device: ai_addsupported (word 69) */ 293 294 #define SATA_DETERMINISTIC_READ 0x4000 /* word 69 deterministic read supp. */ 295 #define SATA_READ_ZERO 0x0020 /* word 69 read zero after TRIM supp. */ 296 297 /* Identify Device: ai_majorversion (word 80) */ 298 299 #define SATA_MAJVER_7 0x0080 /* ATA/ATAPI-7 version supported */ 300 #define SATA_MAJVER_654 0x0070 /* ATA/ATAPI-6,5 or 4 ver supported */ 301 #define SATA_MAJVER_6 0x0040 /* ATA/ATAPI-6 version supported */ 302 #define SATA_MAJVER_5 0x0020 /* ATA/ATAPI-7 version supported */ 303 #define SATA_MAJVER_4 0x0010 /* ATA/ATAPI-4 version supported */ 304 305 /* Identify Device: command set supported/enabled bits - words 83 and 86 */ 306 307 #define SATA_EXT48 0x0400 /* 48 bit address feature */ 308 #define SATA_PWRUP_IN_STANDBY 0x0020 /* Power-up in standby mode supp/en */ 309 #define SATA_RM_STATUS_NOTIFIC 0x0010 /* Removable Media Stat Notification */ 310 #define SATA_RW_DMA_QUEUED_CMD 0x0002 /* R/W DMA Queued supported */ 311 #define SATA_DWNLOAD_MCODE_CMD 0x0001 /* Download Microcode CMD supp/enbld */ 312 #define SATA_ACOUSTIC_MGMT 0x0200 /* Acoustic Management features */ 313 314 /* Identify Device: command set supported/enabled bits - words 82 and 85 */ 315 316 #define SATA_SMART_SUPPORTED 0x0001 /* SMART feature set is supported */ 317 #define SATA_WRITE_CACHE 0x0020 /* Write Cache supported/enabled */ 318 #define SATA_LOOK_AHEAD 0x0040 /* Look Ahead supported/enabled */ 319 #define SATA_DEVICE_RESET_CMD 0x0200 /* Device Reset CMD supported/enbld */ 320 #define SATA_READ_BUFFER_CMD 0x2000 /* Read Buffer CMD supported/enbld */ 321 #define SATA_WRITE_BUFFER_CMD 0x1000 /* Write Buffer CMD supported/enbld */ 322 #define SATA_SMART_ENABLED 0x0001 /* SMART feature set is enabled */ 323 324 /* Identify Device: command set supported/enabled bits - words 84 & 87 */ 325 #define SATA_SMART_SELF_TEST_SUPPORTED 0x0002 /* SMART self-test supported */ 326 /* IDLE IMMEDIATE with UNLOAD FEATURE supported */ 327 #define SATA_IDLE_UNLOAD_SUPPORTED 0x2000 328 #define SATA_GPL_SUPPORTED 0x0020 /* General Purpose Logging supported */ 329 330 /* Identify Device: physical sector size - word 106 */ 331 #define SATA_L2PS_CHECK_BIT 0x4000 /* Set when this word valid */ 332 #define SATA_L2PS_HAS_MULT 0x2000 /* Multiple logical sectors per phys */ 333 #define SATA_L2PS_BIG_SECTORS 0x1000 /* Logical sector size > 512 */ 334 #define SATA_L2PS_EXP_MASK 0x000f /* Logical sectors per phys exponent */ 335 336 /* Identify (Packet) Device word 63, ATA/ATAPI-6 & 7 */ 337 #define SATA_MDMA_SEL_MASK 0x0700 /* Multiword DMA selected */ 338 #define SATA_MDMA_2_SEL 0x0400 /* Multiword DMA mode 2 selected */ 339 #define SATA_MDMA_1_SEL 0x0200 /* Multiword DMA mode 1 selected */ 340 #define SATA_MDMA_0_SEL 0x0100 /* Multiword DMA mode 0 selected */ 341 #define SATA_MDMA_2_SUP 0x0004 /* Multiword DMA mode 2 supported */ 342 #define SATA_MDMA_1_SUP 0x0002 /* Multiword DMA mode 1 supported */ 343 #define SATA_MDMA_0_SUP 0x0001 /* Multiword DMA mode 0 supported */ 344 #define SATA_MDMA_SUP_MASK 0x0007 /* Multiword DMA supported */ 345 346 /* Identify (Packet) Device Word 88 */ 347 #define SATA_UDMA_SUP_MASK 0x007f /* UDMA modes supported */ 348 #define SATA_UDMA_SEL_MASK 0x7f00 /* UDMA modes selected */ 349 350 /* Data Set Management: word 169 */ 351 #define SATA_DSM_TRIM 0x0001 /* Set when TRIM is supported */ 352 353 /* Identify Device: command set supported/enabled bits - word 206 */ 354 355 /* All are SCT Command Transport support */ 356 #define SATA_SCT_CMD_TRANS_SUP 0x0001 /* anything */ 357 #define SATA_SCT_CMD_TRANS_LNG_SECT_SUP 0x0002 /* Long Sector Access */ 358 #define SATA_SCT_CMD_TRANS_WR_SAME_SUP 0x0004 /* Write Same */ 359 #define SATA_SCT_CMD_TRANS_ERR_RCOV_SUP 0x0008 /* Error Recovery Control */ 360 #define SATA_SCT_CMD_TRANS_FEAT_CTL_SUP 0x0010 /* Features Control */ 361 #define SATA_SCT_CMD_TRANS_DATA_TBL_SUP 0x0020 /* Data Tables supported */ 362 363 #define SATA_DISK_SECTOR_SIZE 512 /* HD physical sector size */ 364 365 /* Identify Packet Device data definitions (ATAPI devices) */ 366 367 /* Identify Packet Device: general config bits - word 0 */ 368 369 #define SATA_ATAPI_TYPE_MASK 0xc000 370 #define SATA_ATAPI_TYPE 0x8000 /* ATAPI device */ 371 #define SATA_ATAPI_ID_PKT_SZ 0x0003 /* Packet size mask */ 372 #define SATA_ATAPI_ID_PKT_12B 0x0000 /* Packet size 12 bytes */ 373 #define SATA_ATAPI_ID_PKT_16B 0x0001 /* Packet size 16 bytes */ 374 #define SATA_ATAPI_ID_DRQ_TYPE 0x0060 /* DRQ asserted in 3ms after pkt */ 375 #define SATA_ATAPI_ID_DRQ_INTR 0x0020 /* Obsolete in ATA/ATAPI 7 */ 376 377 #define SATA_ATAPI_ID_DEV_TYPE 0x1f00 /* device type/command set mask */ 378 #define SATA_ATAPI_ID_DEV_SHFT 8 379 #define SATA_ATAPI_DIRACC_DEV 0x0000 /* Direct Access device */ 380 #define SATA_ATAPI_SQACC_DEV 0x0100 /* Sequential access dev (tape ?) */ 381 #define SATA_ATAPI_PROC_DEV 0x0300 /* Processor device */ 382 #define SATA_ATAPI_CDROM_DEV 0x0500 /* CD_ROM device */ 383 384 /* 385 * Status bits from ATAPI Interrupt reason register (AT_COUNT) register 386 */ 387 #define SATA_ATAPI_I_COD 0x01 /* Command or Data */ 388 #define SATA_ATAPI_I_IO 0x02 /* IO direction */ 389 #define SATA_ATAPI_I_RELEASE 0x04 /* Release for ATAPI overlap */ 390 391 /* ATAPI feature reg definitions */ 392 393 #define SATA_ATAPI_F_DATA_DIR_READ 0x04 /* DMA transfer to the host */ 394 #define SATA_ATAPI_F_OVERLAP 0x02 /* Not used by Sun drivers */ 395 #define SATA_ATAPI_F_DMA 0x01 /* Packet DMA command */ 396 397 398 /* ATAPI IDENTIFY_DRIVE capabilities word (49) */ 399 400 #define SATA_ATAPI_ID_CAP_DMA 0x0100 /* if zero, check word 62 */ 401 #define SATA_ATAPI_ID_CAP_OVERLAP 0x2000 402 403 /* 404 * ATAPI Identify Packet Device word 62 405 * Word 62 is not valid for ATA/ATAPI-6 406 * Defs below are for ATA/ATAPI-7 407 */ 408 #define SATA_ATAPI_ID_DMADIR_REQ 0x8000 /* DMA direction required */ 409 #define SATA_ATAPI_ID_DMA_SUP 0x0400 /* DMA is supported */ 410 411 /* 412 * ATAPI signature bits 413 */ 414 #define SATA_ATAPI_SIG_HI 0xeb /* in high cylinder register */ 415 #define SATA_ATAPI_SIG_LO 0x14 /* in low cylinder register */ 416 417 /* These values are pre-set for CD_ROM/DVD ? */ 418 419 #define SATA_ATAPI_SECTOR_SIZE 2048 420 #define SATA_ATAPI_MAX_BYTES_PER_DRQ 0xf800 /* 16 bits - 2KB ie 62KB */ 421 #define SATA_ATAPI_HEADS 64 422 #define SATA_ATAPI_SECTORS_PER_TRK 32 423 424 /* SATA Capabilites bits (word 76) */ 425 426 #define SATA_NCQ 0x100 427 #define SATA_3_SPEED 0x008 428 #define SATA_2_SPEED 0x004 429 #define SATA_1_SPEED 0x002 430 431 /* SATA Features Supported (word 78) - not used */ 432 433 /* SATA Features Enabled (word 79) - not used */ 434 435 #define SATA_READ_AHEAD_SUPPORTED(x) ((x).ai_cmdset82 & SATA_LOOK_AHEAD) 436 #define SATA_READ_AHEAD_ENABLED(x) ((x).ai_features85 & SATA_LOOK_AHEAD) 437 #define SATA_WRITE_CACHE_SUPPORTED(x) ((x).ai_cmdset82 & SATA_WRITE_CACHE) 438 #define SATA_WRITE_CACHE_ENABLED(x) ((x).ai_features85 & SATA_WRITE_CACHE) 439 #define SATA_RM_NOTIFIC_SUPPORTED(x) \ 440 ((x).ai_cmdset83 & SATA_RM_STATUS_NOTIFIC) 441 #define SATA_RM_NOTIFIC_ENABLED(x) \ 442 ((x).ai_features86 & SATA_RM_STATUS_NOTIFIC) 443 444 /* 445 * Generic NCQ related defines 446 */ 447 448 #define NQ 0x80 /* Not a queued cmd - tag not valid */ 449 #define NCQ_TAG_MASK 0x1f /* NCQ command tag mask */ 450 #define FIS_TYPE_REG_H2D 0x27 /* Reg FIS - Host to Device */ 451 #define FIS_CMD_UPDATE 0x80 452 /* 453 * Status bits from AT_STATUS register 454 */ 455 #define SATA_STATUS_BSY 0x80 /* controller busy */ 456 #define SATA_STATUS_DRDY 0x40 /* drive ready */ 457 #define SATA_STATUS_DF 0x20 /* device fault */ 458 #define SATA_STATUS_DSC 0x10 /* seek operation complete */ 459 #define SATA_STATUS_DRQ 0x08 /* data request */ 460 #define SATA_STATUS_CORR 0x04 /* obsolete */ 461 #define SATA_STATUS_IDX 0x02 /* obsolete */ 462 #define SATA_STATUS_ERR 0x01 /* error flag */ 463 464 /* 465 * Status bits from AT_ERROR register 466 */ 467 #define SATA_ERROR_ICRC 0x80 /* CRC data transfer error detected */ 468 #define SATA_ERROR_UNC 0x40 /* uncorrectable data error */ 469 #define SATA_ERROR_MC 0x20 /* Media change */ 470 #define SATA_ERROR_IDNF 0x10 /* ID/Address not found */ 471 #define SATA_ERROR_MCR 0x08 /* media change request */ 472 #define SATA_ERROR_ABORT 0x04 /* aborted command */ 473 #define SATA_ERROR_NM 0x02 /* no media */ 474 #define SATA_ERROR_EOM 0x02 /* end of media (Packet cmds) */ 475 #define SATA_ERROR_ILI 0x01 /* cmd sepcific */ 476 477 478 /* 479 * Bits from the device control register 480 */ 481 #define SATA_DEVCTL_NIEN 0x02 /* not interrupt enabled */ 482 #define SATA_DEVCTL_SRST 0x04 /* software reset */ 483 #define SATA_DEVCTL_HOB 0x80 /* high order bit */ 484 485 /* device_reg */ 486 #define SATA_ADH_LBA 0x40 /* addressing in LBA mode not chs */ 487 488 /* ATAPI transport version-in Inquiry data */ 489 #define SATA_ATAPI_TRANS_VERSION(inq) \ 490 (*((uint8_t *)(inq) + 3) >> 4) 491 492 #define SCSI_LOG_PAGE_HDR_LEN 4 /* # bytes of a SCSI log page header */ 493 #define SCSI_LOG_PARAM_HDR_LEN 4 /* # byttes of a SCSI log param hdr */ 494 495 /* Number of log entries per extended selftest log block */ 496 #define ENTRIES_PER_EXT_SELFTEST_LOG_BLK 19 497 498 /* Number of entries per SCSI LOG SENSE SELFTEST RESULTS page */ 499 #define SCSI_ENTRIES_IN_LOG_SENSE_SELFTEST_RESULTS 20 500 501 /* Length of a SCSI LOG SENSE SELFTEST RESULTS parameter */ 502 #define SCSI_LOG_SENSE_SELFTEST_PARAM_LEN 0x10 503 504 #define DIAGNOSTIC_FAILURE_ON_COMPONENT 0x40 505 506 #define SCSI_COMPONENT_81 0x81 507 #define SCSI_COMPONENT_82 0x82 508 #define SCSI_COMPONENT_83 0x83 509 #define SCSI_COMPONENT_84 0x84 510 #define SCSI_COMPONENT_85 0x85 511 #define SCSI_COMPONENT_86 0x86 512 #define SCSI_COMPONENT_87 0x87 513 #define SCSI_COMPONENT_88 0x88 514 515 #define SCSI_ASC_ATA_DEV_FEAT_NOT_ENABLED 0x67 516 #define SCSI_ASCQ_ATA_DEV_FEAT_NOT_ENABLED 0x0b 517 518 #define SCSI_PREDICTED_FAILURE 0x5d 519 #define SCSI_GENERAL_HD_FAILURE 0x10 520 521 #define SCSI_INFO_EXCEPTIONS_PARAM_LEN 4 522 523 #define READ_LOG_EXT_LOG_DIRECTORY 0x00 524 #define DEVICE_STATS_LOG 0x04 525 #define DEVSTAT_GENERAL_STATS 0x01 526 #define DEVSTAT_ROTATING_MEDIA_PAGE 0x03 527 #define DEVSTAT_GENERAL_ERRORS_PAGE 0x04 528 #define DEVSTAT_TEMP_PAGE 0x05 529 #define DEVSTAT_SSD_PAGE 0x07 530 #define SMART_SELFTEST_LOG_PAGE 0x06 531 #define EXT_SMART_SELFTEST_LOG_PAGE 0x07 532 #define READ_LOG_EXT_NCQ_ERROR_RECOVERY 0x10 533 534 535 #define SATA_STAT_SUPPORTED(x) ((x) & (1ULL << 63)) 536 #define SATA_STAT_VALID(x) ((x) & (1ULL << 62)) 537 #define SATA_STAT_VALUE(x) ((x) & ((1ULL << 59) - 1)) 538 539 /* 540 * SATA NCQ error recovery page (0x10) 541 */ 542 struct sata_ncq_error_recovery_page { 543 uint8_t ncq_tag; 544 uint8_t reserved1; 545 uint8_t ncq_status; 546 uint8_t ncq_error; 547 uint8_t ncq_sector_number; 548 uint8_t ncq_cyl_low; 549 uint8_t ncq_cyl_high; 550 uint8_t ncq_dev_head; 551 uint8_t ncq_sector_number_ext; 552 uint8_t ncq_cyl_low_ext; 553 uint8_t ncq_cyl_high_ext; 554 uint8_t reserved2; 555 uint8_t ncq_sector_count; 556 uint8_t ncq_sector_count_ext; 557 uint8_t reserved3[242]; 558 uint8_t ncq_vendor_unique[255]; 559 uint8_t ncq_checksum; 560 }; 561 562 /* SMART attribute of Start/Stop Count */ 563 #define SMART_START_STOP_COUNT_ID 0x4 564 565 /* 566 * SMART data structures 567 */ 568 struct smart_data { 569 uint8_t smart_vendor_specific[362]; 570 uint8_t smart_offline_data_collection_status; 571 uint8_t smart_selftest_exec_status; 572 uint8_t smart_secs_to_complete_offline_data[2]; 573 uint8_t smart_vendor_specific2; 574 uint8_t smart_offline_data_collection_capability; 575 uint8_t smart_capability[2]; 576 uint8_t smart_error_logging_capability; 577 uint8_t smart_vendor_specific3; 578 uint8_t smart_short_selftest_polling_time; 579 uint8_t smart_extended_selftest_polling_time; 580 uint8_t smart_conveyance_selftest_polling_time; 581 uint8_t smart_reserved[11]; 582 uint8_t smart_vendor_specific4[125]; 583 uint8_t smart_checksum; 584 }; 585 586 struct smart_selftest_log_entry { 587 uint8_t smart_selftest_log_lba_low; 588 uint8_t smart_selftest_log_status; 589 uint8_t smart_selftest_log_timestamp[2]; 590 uint8_t smart_selftest_log_checkpoint; 591 uint8_t smart_selftest_log_failing_lba[4]; /* from LSB to MSB */ 592 uint8_t smart_selftest_log_vendor_specific[15]; 593 }; 594 595 #define NUM_SMART_SELFTEST_LOG_ENTRIES 21 596 struct smart_selftest_log { 597 uint8_t smart_selftest_log_revision[2]; 598 struct smart_selftest_log_entry 599 smart_selftest_log_entries[NUM_SMART_SELFTEST_LOG_ENTRIES]; 600 uint8_t smart_selftest_log_vendor_specific[2]; 601 uint8_t smart_selftest_log_index; 602 uint8_t smart_selftest_log_reserved[2]; 603 uint8_t smart_selftest_log_checksum; 604 }; 605 606 struct smart_ext_selftest_log_entry { 607 uint8_t smart_ext_selftest_log_lba_low; 608 uint8_t smart_ext_selftest_log_status; 609 uint8_t smart_ext_selftest_log_timestamp[2]; 610 uint8_t smart_ext_selftest_log_checkpoint; 611 uint8_t smart_ext_selftest_log_failing_lba[6]; 612 uint8_t smart_ext_selftest_log_vendor_specific[15]; 613 }; 614 615 struct smart_ext_selftest_log { 616 uint8_t smart_ext_selftest_log_rev; 617 uint8_t smart_ext_selftest_log_reserved; 618 uint8_t smart_ext_selftest_log_index[2]; 619 struct smart_ext_selftest_log_entry smart_ext_selftest_log_entries[19]; 620 uint8_t smart_ext_selftest_log_vendor_specific[2]; 621 uint8_t smart_ext_selftest_log_reserved2[11]; 622 uint8_t smart_ext_selftest_log_checksum; 623 }; 624 625 struct read_log_ext_directory { 626 uint8_t read_log_ext_vers[2]; /* general purpose log version */ 627 uint8_t read_log_ext_nblks[255][2]; /* # of blks @ log addr index+1 */ 628 }; 629 630 /* 631 * The definition of CONTROL byte field in SCSI command 632 * according to SAM 5 633 */ 634 #define CTL_BYTE_VENDOR_MASK 0xc0 635 #define CTL_BYTE_NACA_MASK 0x04 636 637 /* 638 * The definition of mask in START STOP UNIT command 639 */ 640 #define START_STOP_IMMED_MASK 0x01 641 #define START_STOP_POWER_COND_MASK 0xF0 642 #define START_STOP_START_MASK 0x01 643 #define START_STOP_LOEJ_MASK 0x02 644 #define START_STOP_NOFLUSH_MASK 0x04 645 #define START_STOP_MODIFIER_MASK 0x0f 646 #define START_STOP_POWER_COND_SHIFT 4 647 648 /* 649 * SMART specific data 650 * These eventually need to go to a generic scsi header file 651 * for now they will reside here 652 */ 653 #define PC_CUMULATIVE_VALUES 0x01 654 #define PAGE_CODE_GET_SUPPORTED_LOG_PAGES 0x00 655 #define PAGE_CODE_READ_ERRORS 0x03 656 #define PAGE_CODE_TEMPERATURE 0x0d 657 #define PAGE_CODE_START_STOP_CYCLE_COUNTER 0x0e 658 #define PAGE_CODE_SELF_TEST_RESULTS 0x10 659 #define PAGE_CODE_SOLID_STATE_MEDIA 0x11 660 #define PAGE_CODE_GENERAL_STATS 0x19 661 #define PAGE_CODE_INFORMATION_EXCEPTIONS 0x2f 662 #define PAGE_CODE_SMART_READ_DATA 0x30 663 664 665 struct log_parameter { 666 uint8_t param_code[2]; /* parameter dependant */ 667 uint8_t param_ctrl_flags; /* see defines below */ 668 uint8_t param_len; /* # of bytes following */ 669 uint8_t param_values[]; /* # of bytes defined by param_len */ 670 }; 671 672 /* param_ctrl_flag fields */ 673 #define LOG_CTRL_LP 0x01 /* list parameter */ 674 #define LOG_CTRL_LBIN 0x02 /* list is binary */ 675 #define LOG_CTRL_TMC 0x0c /* threshold met criteria */ 676 #define LOG_CTRL_ETC 0x10 /* enable threshold comparison */ 677 #define LOG_CTRL_TSD 0x20 /* target save disable */ 678 #define LOG_CTRL_DS 0x40 /* disable save */ 679 #define LOG_CTRL_DU 0x80 /* disable update */ 680 681 #define SMART_MAGIC_VAL_1 0x4f 682 #define SMART_MAGIC_VAL_2 0xc2 683 #define SMART_MAGIC_VAL_3 0xf4 684 #define SMART_MAGIC_VAL_4 0x2c 685 686 #define SCT_STATUS_LOG_PAGE 0xe0 687 688 #define SCSI_NO_TEMP 0xff 689 690 /* 691 * Acoustic management 692 */ 693 694 struct mode_acoustic_management { 695 struct mode_page mode_page; /* common mode page header */ 696 uchar_t acoustic_manag_enable; /* Set to 1 enable, Set 0 disable */ 697 uchar_t acoustic_manag_level; /* Acoustic management level */ 698 uchar_t vendor_recommended_value; /* Vendor recommended value */ 699 }; 700 701 #define PAGELENGTH_DAD_MODE_ACOUSTIC_MANAGEMENT 3 /* Acoustic manag pg len */ 702 #define P_CNTRL_CURRENT 0 703 #define P_CNTRL_CHANGEABLE 1 704 #define P_CNTRL_DEFAULT 2 705 #define P_CNTRL_SAVED 3 706 707 #define ACOUSTIC_DISABLED 0 708 #define ACOUSTIC_ENABLED 1 709 710 #define MODEPAGE_ACOUSTIC_MANAG 0x30 711 712 /* 713 * Port Multiplier registers' offsets 714 */ 715 #define SATA_PMULT_GSCR0 0x0 716 #define SATA_PMULT_GSCR1 0x1 717 #define SATA_PMULT_GSCR2 0x2 718 #define SATA_PMULT_GSCR32 0x20 719 #define SATA_PMULT_GSCR33 0x21 720 #define SATA_PMULT_GSCR64 0x40 721 #define SATA_PMULT_GSCR96 0x60 722 723 #define SATA_PMULT_PORTNUM_MASK 0xf 724 725 #define SATA_PMULT_PSCR0 0x0 726 #define SATA_PMULT_PSCR1 0x1 727 #define SATA_PMULT_PSCR2 0x2 728 #define SATA_PMULT_PSCR3 0x3 729 #define SATA_PMULT_PSCR4 0x4 730 731 #define SATA_PMULT_REG_SSTS (SATA_PMULT_PSCR0) 732 #define SATA_PMULT_REG_SERR (SATA_PMULT_PSCR1) 733 #define SATA_PMULT_REG_SCTL (SATA_PMULT_PSCR2) 734 #define SATA_PMULT_REG_SACT (SATA_PMULT_PSCR3) 735 #define SATA_PMULT_REG_SNTF (SATA_PMULT_PSCR4) 736 737 /* 738 * Port Multiplier capabilities 739 * (Indicated by GSCR64, and enabled by GSCR96) 740 */ 741 #define SATA_PMULT_CAP_BIST (1 << 0) 742 #define SATA_PMULT_CAP_PMREQ (1 << 1) 743 #define SATA_PMULT_CAP_SSC (1 << 2) 744 #define SATA_PMULT_CAP_SNOTIF (1 << 3) 745 #define SATA_PMULT_CAP_PHYEVENT (1 << 4) 746 747 /* 748 * sstatus field definitions 749 */ 750 #define SSTATUS_DET_SHIFT 0 751 #define SSTATUS_SPD_SHIFT 4 752 #define SSTATUS_IPM_SHIFT 8 753 754 #define SSTATUS_DET (0xf << SSTATUS_DET_SHIFT) 755 #define SSTATUS_SPD (0xf << SSTATUS_SPD_SHIFT) 756 #define SSTATUS_IPM (0xf << SSTATUS_IPM_SHIFT) 757 758 /* 759 * sstatus DET values 760 */ 761 #define SSTATUS_DET_NODEV 0 /* No dev detected */ 762 #define SSTATUS_DET_DEVPRE_NOPHYCOM 1 /* dev detected */ 763 #define SSTATUS_DET_DEVPRE_PHYCOM 3 /* dev detected */ 764 #define SSTATUS_DET_PHYOFFLINE 4 /* PHY is in offline */ 765 766 #define SSTATUS_GET_DET(x) \ 767 (x & SSTATUS_DET) 768 769 #define SSTATUS_SET_DET(x, new_val) \ 770 (x = (x & ~SSTATUS_DET) | (new_val & SSTATUS_DET)) 771 772 #define SSTATUS_SPD_NODEV 0 /* No device present */ 773 #define SSTATUS_SPD_GEN1 1 /* Gen 1 rate negotiated */ 774 #define SSTATUS_SPD_GEN2 2 /* Gen 2 rate negotiated */ 775 #define SSTATUS_SPD_GEN3 3 /* Gen 3 rate negotiated */ 776 777 /* 778 * sstatus IPM values 779 */ 780 #define SSTATUS_IPM_NODEV_NOPHYCOM 0x0 /* No dev, no PHY */ 781 #define SSTATUS_IPM_ACTIVE 0x1 /* Interface active */ 782 #define SSTATUS_IPM_POWERPARTIAL 0x2 /* partial power mgmnt */ 783 #define SSTATUS_IPM_POWERSLUMBER 0x6 /* slumber power mgmt */ 784 785 #define SSTATUS_GET_IPM(x) \ 786 ((x & SSTATUS_IPM) >> SSTATUS_IPM_SHIFT) 787 788 #define SSTATUS_SET_IPM(x, new_val) \ 789 (x = (x & ~SSTATUS_IPM) | \ 790 ((new_val << SSTATUS_IPM_SHIFT) & SSTATUS_IPM)) 791 792 793 /* 794 * serror register fields 795 */ 796 #define SERROR_DATA_ERR_FIXED (1 << 0) /* D integrity err */ 797 #define SERROR_COMM_ERR_FIXED (1 << 1) /* comm err recov */ 798 #define SERROR_DATA_ERR (1 << 8) /* D integrity err */ 799 #define SERROR_PERSISTENT_ERR (1 << 9) /* norecov com err */ 800 #define SERROR_PROTOCOL_ERR (1 << 10) /* protocol err */ 801 #define SERROR_INT_ERR (1 << 11) /* internal err */ 802 #define SERROR_PHY_RDY_CHG (1 << 16) /* PHY state change */ 803 #define SERROR_PHY_INT_ERR (1 << 17) /* PHY internal err */ 804 #define SERROR_COMM_WAKE (1 << 18) /* COM wake */ 805 #define SERROR_10B_TO_8B_ERR (1 << 19) /* 10B-to-8B decode */ 806 #define SERROR_DISPARITY_ERR (1 << 20) /* disparity err */ 807 #define SERROR_CRC_ERR (1 << 21) /* CRC err */ 808 #define SERROR_HANDSHAKE_ERR (1 << 22) /* Handshake err */ 809 #define SERROR_LINK_SEQ_ERR (1 << 23) /* Link seq err */ 810 #define SERROR_TRANS_ERR (1 << 24) /* Tran state err */ 811 #define SERROR_FIS_TYPE (1 << 25) /* FIS type err */ 812 #define SERROR_EXCHANGED_ERR (1 << 26) /* Device exchanged */ 813 814 /* 815 * S-Control Bridge port x register fields 816 */ 817 #define SCONTROL_DET_SHIFT 0 818 #define SCONTROL_SPD_SHIFT 4 819 #define SCONTROL_IPM_SHIFT 8 820 #define SCONTROL_SPM_SHIFT 12 821 822 #define SCONTROL_DET (0xf << SCONTROL_DET_SHIFT) 823 #define SCONTROL_SPD (0xf << SCONTROL_SPD_SHIFT) 824 #define SCONTROL_IPM (0xf << SCONTROL_IPM_SHIFT) 825 #define SCONTROL_SPM (0xf << SCONTROL_SPM_SHIFT) 826 827 #define SCONTROL_GET_DET(x) \ 828 (x & SCONTROL_DET) 829 830 #define SCONTROL_SET_DET(x, new_val) \ 831 (x = (x & ~SCONTROL_DET) | (new_val & SCONTROL_DET)) 832 833 #define SCONTROL_DET_NOACTION 0 /* Do nothing to port */ 834 #define SCONTROL_DET_COMRESET 1 /* Re-initialize port */ 835 #define SCONTROL_DET_DISABLE 4 /* Disable port */ 836 837 #define SCONTROL_SPD_NOLIMIT 0 /* No speed limit */ 838 #define SCONTROL_SPD_GEN1 1 /* Limit Gen 1 rate */ 839 #define SCONTROL_SPD_GEN2 2 /* Limit Gen 2 rate */ 840 #define SCONTROL_SPD_GEN3 3 /* Limit Gen 3 rate */ 841 842 #define SCONTROL_GET_IPM(x) \ 843 ((x & SCONTROL_IPM) >> SCONTROL_IPM_SHIFT) 844 845 #define SCONTROL_SET_IPM(x, new_val) \ 846 (x = (x & ~SCONTROL_IPM) | \ 847 ((new_val << SCONTROL_IPM_SHIFT) & SCONTROL_IPM)) 848 849 /* NB: IPM disable value is a bit-field (though not described) */ 850 #define SCONTROL_IPM_NORESTRICT 0 /* No PM limit */ 851 #define SCONTROL_IPM_DISABLE_PARTIAL 1 /* Disable partial */ 852 #define SCONTROL_IPM_DISABLE_SLUMBER 2 /* Disable slumber */ 853 #define SCONTROL_IPM_DISABLE_BOTH 3 /* Disable both */ 854 #define SCONTROL_IPM_DISABLE_DEVSLEEP 4 /* Disable devsleep */ 855 #define SCONTROL_IPM_DISABLE_ALL 7 /* Disable all PM */ 856 857 #define SCONTROL_SPM_NORESTRICT 0 /* No PM limits */ 858 #define SCONTROL_SPM_DO_PARTIAL 1 /* Go to partial */ 859 #define SCONTROL_SPM_DO_SLUMBER 2 /* Go to slumber */ 860 #define SCONTROL_SPM_DO_ACTIVE 4 /* Go to active */ 861 862 #ifdef __cplusplus 863 } 864 #endif 865 866 #endif /* _SATA_DEFS_H */ 867