ata.h revision 296421
162856Sdcs/*- 262856Sdcs * Copyright (c) 2000 - 2008 S��ren Schmidt <sos@FreeBSD.org> 362856Sdcs * All rights reserved. 462856Sdcs * 562856Sdcs * Redistribution and use in source and binary forms, with or without 662856Sdcs * modification, are permitted provided that the following conditions 762856Sdcs * are met: 8313221Sngie * 1. Redistributions of source code must retain the above copyright 962872Sgreen * notice, this list of conditions and the following disclaimer, 1062872Sgreen * without modification, immediately at the beginning of the file. 11292481Sngie * 2. Redistributions in binary form must reproduce the above copyright 1262872Sgreen * notice, this list of conditions and the following disclaimer in the 1362872Sgreen * documentation and/or other materials provided with the distribution. 1462872Sgreen * 1562872Sgreen * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 1662856Sdcs * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1762856Sdcs * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1862856Sdcs * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 1962856Sdcs * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2062856Sdcs * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2162856Sdcs * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2262856Sdcs * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2362856Sdcs * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2462856Sdcs * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2562856Sdcs * 2662856Sdcs * $FreeBSD: stable/10/sys/sys/ata.h 296421 2016-03-06 02:33:02Z rpokala $ 27132389Stjr */ 2862856Sdcs 2962856Sdcs#ifndef _SYS_ATA_H_ 3062856Sdcs#define _SYS_ATA_H_ 3162856Sdcs 3262856Sdcs#include <sys/ioccom.h> 3362856Sdcs 3462856Sdcs/* ATA/ATAPI device parameters */ 3562856Sdcsstruct ata_params { 3662856Sdcs/*000*/ u_int16_t config; /* configuration info */ 3762856Sdcs#define ATA_PROTO_MASK 0x8003 3862856Sdcs#define ATA_PROTO_ATAPI 0x8000 3962856Sdcs#define ATA_PROTO_ATAPI_12 0x8000 4062856Sdcs#define ATA_PROTO_ATAPI_16 0x8001 4162856Sdcs#define ATA_PROTO_CFA 0x848a 42132389Stjr#define ATA_ATAPI_TYPE_MASK 0x1f00 4362856Sdcs#define ATA_ATAPI_TYPE_DIRECT 0x0000 /* disk/floppy */ 4462856Sdcs#define ATA_ATAPI_TYPE_TAPE 0x0100 /* streaming tape */ 4562856Sdcs#define ATA_ATAPI_TYPE_CDROM 0x0500 /* CD-ROM device */ 4662856Sdcs#define ATA_ATAPI_TYPE_OPTICAL 0x0700 /* optical disk */ 4762856Sdcs#define ATA_DRQ_MASK 0x0060 4862856Sdcs#define ATA_DRQ_SLOW 0x0000 /* cpu 3 ms delay */ 4962856Sdcs#define ATA_DRQ_INTR 0x0020 /* interrupt 10 ms delay */ 5062856Sdcs#define ATA_DRQ_FAST 0x0040 /* accel 50 us delay */ 51132390Stjr#define ATA_RESP_INCOMPLETE 0x0004 5262856Sdcs 53132389Stjr/*001*/ u_int16_t cylinders; /* # of cylinders */ 5462856Sdcs/*002*/ u_int16_t specconf; /* specific configuration */ 5562856Sdcs/*003*/ u_int16_t heads; /* # heads */ 5662856Sdcs u_int16_t obsolete4; 57132390Stjr u_int16_t obsolete5; 58132390Stjr/*006*/ u_int16_t sectors; /* # sectors/track */ 5962856Sdcs/*007*/ u_int16_t vendor7[3]; 60132389Stjr/*010*/ u_int8_t serial[20]; /* serial number */ 6162856Sdcs/*020*/ u_int16_t retired20; 6262856Sdcs u_int16_t retired21; 6362856Sdcs u_int16_t obsolete22; 6462856Sdcs/*023*/ u_int8_t revision[8]; /* firmware revision */ 65292170Sngie/*027*/ u_int8_t model[40]; /* model name */ 66292170Sngie/*047*/ u_int16_t sectors_intr; /* sectors per interrupt */ 6762856Sdcs/*048*/ u_int16_t usedmovsd; /* double word read/write? */ 6862856Sdcs/*049*/ u_int16_t capabilities1; 6962856Sdcs#define ATA_SUPPORT_DMA 0x0100 7062856Sdcs#define ATA_SUPPORT_LBA 0x0200 7162856Sdcs#define ATA_SUPPORT_IORDY 0x0400 7262856Sdcs#define ATA_SUPPORT_IORDYDIS 0x0800 7362856Sdcs#define ATA_SUPPORT_OVERLAP 0x4000 7462856Sdcs 7562856Sdcs/*050*/ u_int16_t capabilities2; 7662856Sdcs/*051*/ u_int16_t retired_piomode; /* PIO modes 0-2 */ 7762856Sdcs#define ATA_RETIRED_PIO_MASK 0x0300 7862856Sdcs 7962856Sdcs/*052*/ u_int16_t retired_dmamode; /* DMA modes */ 8062856Sdcs#define ATA_RETIRED_DMA_MASK 0x0003 8162856Sdcs 8262856Sdcs/*053*/ u_int16_t atavalid; /* fields valid */ 8362856Sdcs#define ATA_FLAG_54_58 0x0001 /* words 54-58 valid */ 8462856Sdcs#define ATA_FLAG_64_70 0x0002 /* words 64-70 valid */ 8562856Sdcs#define ATA_FLAG_88 0x0004 /* word 88 valid */ 8662856Sdcs 8762856Sdcs/*054*/ u_int16_t current_cylinders; 8862856Sdcs/*055*/ u_int16_t current_heads; 8962856Sdcs/*056*/ u_int16_t current_sectors; 9062856Sdcs/*057*/ u_int16_t current_size_1; 9162856Sdcs/*058*/ u_int16_t current_size_2; 9262856Sdcs/*059*/ u_int16_t multi; 9362856Sdcs#define ATA_MULTI_VALID 0x0100 9462856Sdcs 9562856Sdcs/*060*/ u_int16_t lba_size_1; 96132389Stjr u_int16_t lba_size_2; 9762856Sdcs u_int16_t obsolete62; 9862856Sdcs/*063*/ u_int16_t mwdmamodes; /* multiword DMA modes */ 99132389Stjr/*064*/ u_int16_t apiomodes; /* advanced PIO modes */ 100 101/*065*/ u_int16_t mwdmamin; /* min. M/W DMA time/word ns */ 102/*066*/ u_int16_t mwdmarec; /* rec. M/W DMA time ns */ 103/*067*/ u_int16_t pioblind; /* min. PIO cycle w/o flow */ 104/*068*/ u_int16_t pioiordy; /* min. PIO cycle IORDY flow */ 105/*069*/ u_int16_t support3; 106#define ATA_SUPPORT_RZAT 0x0020 107#define ATA_SUPPORT_DRAT 0x4000 108 u_int16_t reserved70; 109/*071*/ u_int16_t rlsovlap; /* rel time (us) for overlap */ 110/*072*/ u_int16_t rlsservice; /* rel time (us) for service */ 111 u_int16_t reserved73; 112 u_int16_t reserved74; 113/*075*/ u_int16_t queue; 114#define ATA_QUEUE_LEN(x) ((x) & 0x001f) 115 116/*76*/ u_int16_t satacapabilities; 117#define ATA_SATA_GEN1 0x0002 118#define ATA_SATA_GEN2 0x0004 119#define ATA_SATA_GEN3 0x0008 120#define ATA_SUPPORT_NCQ 0x0100 121#define ATA_SUPPORT_IFPWRMNGTRCV 0x0200 122#define ATA_SUPPORT_PHYEVENTCNT 0x0400 123#define ATA_SUPPORT_NCQ_UNLOAD 0x0800 124#define ATA_SUPPORT_NCQ_PRIO 0x1000 125#define ATA_SUPPORT_HAPST 0x2000 126#define ATA_SUPPORT_DAPST 0x4000 127#define ATA_SUPPORT_READLOGDMAEXT 0x8000 128 129/*77*/ u_int16_t satacapabilities2; 130#define ATA_SATA_CURR_GEN_MASK 0x0006 131#define ATA_SUPPORT_NCQ_STREAM 0x0010 132#define ATA_SUPPORT_NCQ_QMANAGEMENT 0x0020 133#define ATA_SUPPORT_RCVSND_FPDMA_QUEUED 0x0040 134/*78*/ u_int16_t satasupport; 135#define ATA_SUPPORT_NONZERO 0x0002 136#define ATA_SUPPORT_AUTOACTIVATE 0x0004 137#define ATA_SUPPORT_IFPWRMNGT 0x0008 138#define ATA_SUPPORT_INORDERDATA 0x0010 139#define ATA_SUPPORT_ASYNCNOTIF 0x0020 140#define ATA_SUPPORT_SOFTSETPRESERVE 0x0040 141/*79*/ u_int16_t sataenabled; 142#define ATA_ENABLED_DAPST 0x0080 143 144/*080*/ u_int16_t version_major; 145/*081*/ u_int16_t version_minor; 146 147 struct { 148/*082/085*/ u_int16_t command1; 149#define ATA_SUPPORT_SMART 0x0001 150#define ATA_SUPPORT_SECURITY 0x0002 151#define ATA_SUPPORT_REMOVABLE 0x0004 152#define ATA_SUPPORT_POWERMGT 0x0008 153#define ATA_SUPPORT_PACKET 0x0010 154#define ATA_SUPPORT_WRITECACHE 0x0020 155#define ATA_SUPPORT_LOOKAHEAD 0x0040 156#define ATA_SUPPORT_RELEASEIRQ 0x0080 157#define ATA_SUPPORT_SERVICEIRQ 0x0100 158#define ATA_SUPPORT_RESET 0x0200 159#define ATA_SUPPORT_PROTECTED 0x0400 160#define ATA_SUPPORT_WRITEBUFFER 0x1000 161#define ATA_SUPPORT_READBUFFER 0x2000 162#define ATA_SUPPORT_NOP 0x4000 163 164/*083/086*/ u_int16_t command2; 165#define ATA_SUPPORT_MICROCODE 0x0001 166#define ATA_SUPPORT_QUEUED 0x0002 167#define ATA_SUPPORT_CFA 0x0004 168#define ATA_SUPPORT_APM 0x0008 169#define ATA_SUPPORT_NOTIFY 0x0010 170#define ATA_SUPPORT_STANDBY 0x0020 171#define ATA_SUPPORT_SPINUP 0x0040 172#define ATA_SUPPORT_MAXSECURITY 0x0100 173#define ATA_SUPPORT_AUTOACOUSTIC 0x0200 174#define ATA_SUPPORT_ADDRESS48 0x0400 175#define ATA_SUPPORT_OVERLAY 0x0800 176#define ATA_SUPPORT_FLUSHCACHE 0x1000 177#define ATA_SUPPORT_FLUSHCACHE48 0x2000 178 179/*084/087*/ u_int16_t extension; 180#define ATA_SUPPORT_SMARTLOG 0x0001 181#define ATA_SUPPORT_SMARTTEST 0x0002 182#define ATA_SUPPORT_MEDIASN 0x0004 183#define ATA_SUPPORT_MEDIAPASS 0x0008 184#define ATA_SUPPORT_STREAMING 0x0010 185#define ATA_SUPPORT_GENLOG 0x0020 186#define ATA_SUPPORT_WRITEDMAFUAEXT 0x0040 187#define ATA_SUPPORT_WRITEDMAQFUAEXT 0x0080 188#define ATA_SUPPORT_64BITWWN 0x0100 189#define ATA_SUPPORT_UNLOAD 0x2000 190 } __packed support, enabled; 191 192/*088*/ u_int16_t udmamodes; /* UltraDMA modes */ 193/*089*/ u_int16_t erase_time; /* time req'd in 2min units */ 194/*090*/ u_int16_t enhanced_erase_time; /* time req'd in 2min units */ 195/*091*/ u_int16_t apm_value; 196/*092*/ u_int16_t master_passwd_revision; /* password revision code */ 197/*093*/ u_int16_t hwres; 198#define ATA_CABLE_ID 0x2000 199 200/*094*/ u_int16_t acoustic; 201#define ATA_ACOUSTIC_CURRENT(x) ((x) & 0x00ff) 202#define ATA_ACOUSTIC_VENDOR(x) (((x) & 0xff00) >> 8) 203 204/*095*/ u_int16_t stream_min_req_size; 205/*096*/ u_int16_t stream_transfer_time; 206/*097*/ u_int16_t stream_access_latency; 207/*098*/ u_int32_t stream_granularity; 208/*100*/ u_int16_t lba_size48_1; 209 u_int16_t lba_size48_2; 210 u_int16_t lba_size48_3; 211 u_int16_t lba_size48_4; 212 u_int16_t reserved104; 213/*105*/ u_int16_t max_dsm_blocks; 214/*106*/ u_int16_t pss; 215#define ATA_PSS_LSPPS 0x000F 216#define ATA_PSS_LSSABOVE512 0x1000 217#define ATA_PSS_MULTLS 0x2000 218#define ATA_PSS_VALID_MASK 0xC000 219#define ATA_PSS_VALID_VALUE 0x4000 220/*107*/ u_int16_t isd; 221/*108*/ u_int16_t wwn[4]; 222 u_int16_t reserved112[5]; 223/*117*/ u_int16_t lss_1; 224/*118*/ u_int16_t lss_2; 225/*119*/ u_int16_t support2; 226#define ATA_SUPPORT_WRITEREADVERIFY 0x0002 227#define ATA_SUPPORT_WRITEUNCORREXT 0x0004 228#define ATA_SUPPORT_RWLOGDMAEXT 0x0008 229#define ATA_SUPPORT_MICROCODE3 0x0010 230#define ATA_SUPPORT_FREEFALL 0x0020 231/*120*/ u_int16_t enabled2; 232 u_int16_t reserved121[6]; 233/*127*/ u_int16_t removable_status; 234/*128*/ u_int16_t security_status; 235#define ATA_SECURITY_LEVEL 0x0100 /* 0: high, 1: maximum */ 236#define ATA_SECURITY_ENH_SUPP 0x0020 /* enhanced erase supported */ 237#define ATA_SECURITY_COUNT_EXP 0x0010 /* count expired */ 238#define ATA_SECURITY_FROZEN 0x0008 /* security config is frozen */ 239#define ATA_SECURITY_LOCKED 0x0004 /* drive is locked */ 240#define ATA_SECURITY_ENABLED 0x0002 /* ATA Security is enabled */ 241#define ATA_SECURITY_SUPPORTED 0x0001 /* ATA Security is supported */ 242 243 u_int16_t reserved129[31]; 244/*160*/ u_int16_t cfa_powermode1; 245 u_int16_t reserved161; 246/*162*/ u_int16_t cfa_kms_support; 247/*163*/ u_int16_t cfa_trueide_modes; 248/*164*/ u_int16_t cfa_memory_modes; 249 u_int16_t reserved165[4]; 250/*169*/ u_int16_t support_dsm; 251#define ATA_SUPPORT_DSM_TRIM 0x0001 252 u_int16_t reserved170[6]; 253/*176*/ u_int8_t media_serial[60]; 254/*206*/ u_int16_t sct; 255 u_int16_t reserved206[2]; 256/*209*/ u_int16_t lsalign; 257/*210*/ u_int16_t wrv_sectors_m3_1; 258 u_int16_t wrv_sectors_m3_2; 259/*212*/ u_int16_t wrv_sectors_m2_1; 260 u_int16_t wrv_sectors_m2_2; 261/*214*/ u_int16_t nv_cache_caps; 262/*215*/ u_int16_t nv_cache_size_1; 263 u_int16_t nv_cache_size_2; 264/*217*/ u_int16_t media_rotation_rate; 265#define ATA_RATE_NOT_REPORTED 0x0000 266#define ATA_RATE_NON_ROTATING 0x0001 267 u_int16_t reserved218; 268/*219*/ u_int16_t nv_cache_opt; 269/*220*/ u_int16_t wrv_mode; 270 u_int16_t reserved221; 271/*222*/ u_int16_t transport_major; 272/*223*/ u_int16_t transport_minor; 273 u_int16_t reserved224[31]; 274/*255*/ u_int16_t integrity; 275} __packed; 276 277/* ATA Dataset Management */ 278#define ATA_DSM_BLK_SIZE 512 279#define ATA_DSM_BLK_RANGES 64 280#define ATA_DSM_RANGE_SIZE 8 281#define ATA_DSM_RANGE_MAX 65535 282 283/* 284 * ATA Device Register 285 * 286 * bit 7 Obsolete (was 1 in early ATA specs) 287 * bit 6 Sets LBA/CHS mode. 1=LBA, 0=CHS 288 * bit 5 Obsolete (was 1 in early ATA specs) 289 * bit 4 1 = Slave Drive, 0 = Master Drive 290 * bit 3-0 In LBA mode, 27-24 of address. In CHS mode, head number 291*/ 292 293#define ATA_DEV_MASTER 0x00 294#define ATA_DEV_SLAVE 0x10 295#define ATA_DEV_LBA 0x40 296 297/* ATA limits */ 298#define ATA_MAX_28BIT_LBA 268435455UL 299 300/* ATA Status Register */ 301#define ATA_STATUS_ERROR 0x01 302#define ATA_STATUS_DEVICE_FAULT 0x20 303 304/* ATA Error Register */ 305#define ATA_ERROR_ABORT 0x04 306#define ATA_ERROR_ID_NOT_FOUND 0x10 307 308/* ATA HPA Features */ 309#define ATA_HPA_FEAT_MAX_ADDR 0x00 310#define ATA_HPA_FEAT_SET_PWD 0x01 311#define ATA_HPA_FEAT_LOCK 0x02 312#define ATA_HPA_FEAT_UNLOCK 0x03 313#define ATA_HPA_FEAT_FREEZE 0x04 314 315/* ATA transfer modes */ 316#define ATA_MODE_MASK 0x0f 317#define ATA_DMA_MASK 0xf0 318#define ATA_PIO 0x00 319#define ATA_PIO0 0x08 320#define ATA_PIO1 0x09 321#define ATA_PIO2 0x0a 322#define ATA_PIO3 0x0b 323#define ATA_PIO4 0x0c 324#define ATA_PIO_MAX 0x0f 325#define ATA_DMA 0x10 326#define ATA_WDMA0 0x20 327#define ATA_WDMA1 0x21 328#define ATA_WDMA2 0x22 329#define ATA_UDMA0 0x40 330#define ATA_UDMA1 0x41 331#define ATA_UDMA2 0x42 332#define ATA_UDMA3 0x43 333#define ATA_UDMA4 0x44 334#define ATA_UDMA5 0x45 335#define ATA_UDMA6 0x46 336#define ATA_SA150 0x47 337#define ATA_SA300 0x48 338#define ATA_SA600 0x49 339#define ATA_DMA_MAX 0x4f 340 341 342/* ATA commands */ 343#define ATA_NOP 0x00 /* NOP */ 344#define ATA_NF_FLUSHQUEUE 0x00 /* flush queued cmd's */ 345#define ATA_NF_AUTOPOLL 0x01 /* start autopoll function */ 346#define ATA_DATA_SET_MANAGEMENT 0x06 347#define ATA_DSM_TRIM 0x01 348#define ATA_DEVICE_RESET 0x08 /* reset device */ 349#define ATA_READ 0x20 /* read */ 350#define ATA_READ48 0x24 /* read 48bit LBA */ 351#define ATA_READ_DMA48 0x25 /* read DMA 48bit LBA */ 352#define ATA_READ_DMA_QUEUED48 0x26 /* read DMA QUEUED 48bit LBA */ 353#define ATA_READ_NATIVE_MAX_ADDRESS48 0x27 /* read native max addr 48bit */ 354#define ATA_READ_MUL48 0x29 /* read multi 48bit LBA */ 355#define ATA_READ_STREAM_DMA48 0x2a /* read DMA stream 48bit LBA */ 356#define ATA_READ_LOG_EXT 0x2f /* read log ext - PIO Data-In */ 357#define ATA_READ_STREAM48 0x2b /* read stream 48bit LBA */ 358#define ATA_WRITE 0x30 /* write */ 359#define ATA_WRITE48 0x34 /* write 48bit LBA */ 360#define ATA_WRITE_DMA48 0x35 /* write DMA 48bit LBA */ 361#define ATA_WRITE_DMA_QUEUED48 0x36 /* write DMA QUEUED 48bit LBA*/ 362#define ATA_SET_MAX_ADDRESS48 0x37 /* set max address 48bit */ 363#define ATA_WRITE_MUL48 0x39 /* write multi 48bit LBA */ 364#define ATA_WRITE_STREAM_DMA48 0x3a 365#define ATA_WRITE_STREAM48 0x3b 366#define ATA_WRITE_DMA_FUA48 0x3d 367#define ATA_WRITE_DMA_QUEUED_FUA48 0x3e 368#define ATA_WRITE_LOG_EXT 0x3f 369#define ATA_READ_VERIFY 0x40 370#define ATA_READ_VERIFY48 0x42 371#define ATA_WRITE_UNCORRECTABLE48 0x45 /* write uncorrectable 48bit LBA */ 372#define ATA_WU_PSEUDO 0x55 /* pseudo-uncorrectable error */ 373#define ATA_WU_FLAGGED 0xaa /* flagged-uncorrectable error */ 374#define ATA_READ_LOG_DMA_EXT 0x47 /* read log DMA ext - PIO Data-In */ 375#define ATA_READ_FPDMA_QUEUED 0x60 /* read DMA NCQ */ 376#define ATA_WRITE_FPDMA_QUEUED 0x61 /* write DMA NCQ */ 377#define ATA_NCQ_NON_DATA 0x63 /* NCQ non-data command */ 378#define ATA_SEND_FPDMA_QUEUED 0x64 /* send DMA NCQ */ 379#define ATA_SFPDMA_DSM 0x00 /* Data set management */ 380#define ATA_SFPDMA_DSM_TRIM 0x01 /* Set trim bit in auxilary */ 381#define ATA_SFPDMA_HYBRID_EVICT 0x01 /* Hybrid Evict */ 382#define ATA_SFPDMA_WLDMA 0x02 /* Write Log DMA EXT */ 383#define ATA_RECV_FPDMA_QUEUED 0x65 /* recieve DMA NCQ */ 384#define ATA_SEP_ATTN 0x67 /* SEP request */ 385#define ATA_SEEK 0x70 /* seek */ 386#define ATA_PACKET_CMD 0xa0 /* packet command */ 387#define ATA_ATAPI_IDENTIFY 0xa1 /* get ATAPI params*/ 388#define ATA_SERVICE 0xa2 /* service command */ 389#define ATA_SMART_CMD 0xb0 /* SMART command */ 390#define ATA_CFA_ERASE 0xc0 /* CFA erase */ 391#define ATA_READ_MUL 0xc4 /* read multi */ 392#define ATA_WRITE_MUL 0xc5 /* write multi */ 393#define ATA_SET_MULTI 0xc6 /* set multi size */ 394#define ATA_READ_DMA_QUEUED 0xc7 /* read DMA QUEUED */ 395#define ATA_READ_DMA 0xc8 /* read DMA */ 396#define ATA_WRITE_DMA 0xca /* write DMA */ 397#define ATA_WRITE_DMA_QUEUED 0xcc /* write DMA QUEUED */ 398#define ATA_WRITE_MUL_FUA48 0xce 399#define ATA_STANDBY_IMMEDIATE 0xe0 /* standby immediate */ 400#define ATA_IDLE_IMMEDIATE 0xe1 /* idle immediate */ 401#define ATA_STANDBY_CMD 0xe2 /* standby */ 402#define ATA_IDLE_CMD 0xe3 /* idle */ 403#define ATA_READ_BUFFER 0xe4 /* read buffer */ 404#define ATA_READ_PM 0xe4 /* read portmultiplier */ 405#define ATA_CHECK_POWER_MODE 0xe5 /* device power mode */ 406#define ATA_SLEEP 0xe6 /* sleep */ 407#define ATA_FLUSHCACHE 0xe7 /* flush cache to disk */ 408#define ATA_WRITE_PM 0xe8 /* write portmultiplier */ 409#define ATA_FLUSHCACHE48 0xea /* flush cache to disk */ 410#define ATA_ATA_IDENTIFY 0xec /* get ATA params */ 411#define ATA_SETFEATURES 0xef /* features command */ 412#define ATA_SF_SETXFER 0x03 /* set transfer mode */ 413#define ATA_SF_ENAB_WCACHE 0x02 /* enable write cache */ 414#define ATA_SF_DIS_WCACHE 0x82 /* disable write cache */ 415#define ATA_SF_ENAB_PUIS 0x06 /* enable PUIS */ 416#define ATA_SF_DIS_PUIS 0x86 /* disable PUIS */ 417#define ATA_SF_PUIS_SPINUP 0x07 /* PUIS spin-up */ 418#define ATA_SF_ENAB_RCACHE 0xaa /* enable readahead cache */ 419#define ATA_SF_DIS_RCACHE 0x55 /* disable readahead cache */ 420#define ATA_SF_ENAB_RELIRQ 0x5d /* enable release interrupt */ 421#define ATA_SF_DIS_RELIRQ 0xdd /* disable release interrupt */ 422#define ATA_SF_ENAB_SRVIRQ 0x5e /* enable service interrupt */ 423#define ATA_SF_DIS_SRVIRQ 0xde /* disable service interrupt */ 424#define ATA_SECURITY_SET_PASSWORD 0xf1 /* set drive password */ 425#define ATA_SECURITY_UNLOCK 0xf2 /* unlock drive using passwd */ 426#define ATA_SECURITY_ERASE_PREPARE 0xf3 /* prepare to erase drive */ 427#define ATA_SECURITY_ERASE_UNIT 0xf4 /* erase all blocks on drive */ 428#define ATA_SECURITY_FREEZE_LOCK 0xf5 /* freeze security config */ 429#define ATA_SECURITY_DISABLE_PASSWORD 0xf6 /* disable drive password */ 430#define ATA_READ_NATIVE_MAX_ADDRESS 0xf8 /* read native max address */ 431#define ATA_SET_MAX_ADDRESS 0xf9 /* set max address */ 432 433 434/* ATAPI commands */ 435#define ATAPI_TEST_UNIT_READY 0x00 /* check if device is ready */ 436#define ATAPI_REZERO 0x01 /* rewind */ 437#define ATAPI_REQUEST_SENSE 0x03 /* get sense data */ 438#define ATAPI_FORMAT 0x04 /* format unit */ 439#define ATAPI_READ 0x08 /* read data */ 440#define ATAPI_WRITE 0x0a /* write data */ 441#define ATAPI_WEOF 0x10 /* write filemark */ 442#define ATAPI_WF_WRITE 0x01 443#define ATAPI_SPACE 0x11 /* space command */ 444#define ATAPI_SP_FM 0x01 445#define ATAPI_SP_EOD 0x03 446#define ATAPI_INQUIRY 0x12 /* get inquiry data */ 447#define ATAPI_MODE_SELECT 0x15 /* mode select */ 448#define ATAPI_ERASE 0x19 /* erase */ 449#define ATAPI_MODE_SENSE 0x1a /* mode sense */ 450#define ATAPI_START_STOP 0x1b /* start/stop unit */ 451#define ATAPI_SS_LOAD 0x01 452#define ATAPI_SS_RETENSION 0x02 453#define ATAPI_SS_EJECT 0x04 454#define ATAPI_PREVENT_ALLOW 0x1e /* media removal */ 455#define ATAPI_READ_FORMAT_CAPACITIES 0x23 /* get format capacities */ 456#define ATAPI_READ_CAPACITY 0x25 /* get volume capacity */ 457#define ATAPI_READ_BIG 0x28 /* read data */ 458#define ATAPI_WRITE_BIG 0x2a /* write data */ 459#define ATAPI_LOCATE 0x2b /* locate to position */ 460#define ATAPI_READ_POSITION 0x34 /* read position */ 461#define ATAPI_SYNCHRONIZE_CACHE 0x35 /* flush buf, close channel */ 462#define ATAPI_WRITE_BUFFER 0x3b /* write device buffer */ 463#define ATAPI_READ_BUFFER 0x3c /* read device buffer */ 464#define ATAPI_READ_SUBCHANNEL 0x42 /* get subchannel info */ 465#define ATAPI_READ_TOC 0x43 /* get table of contents */ 466#define ATAPI_PLAY_10 0x45 /* play by lba */ 467#define ATAPI_PLAY_MSF 0x47 /* play by MSF address */ 468#define ATAPI_PLAY_TRACK 0x48 /* play by track number */ 469#define ATAPI_PAUSE 0x4b /* pause audio operation */ 470#define ATAPI_READ_DISK_INFO 0x51 /* get disk info structure */ 471#define ATAPI_READ_TRACK_INFO 0x52 /* get track info structure */ 472#define ATAPI_RESERVE_TRACK 0x53 /* reserve track */ 473#define ATAPI_SEND_OPC_INFO 0x54 /* send OPC structurek */ 474#define ATAPI_MODE_SELECT_BIG 0x55 /* set device parameters */ 475#define ATAPI_REPAIR_TRACK 0x58 /* repair track */ 476#define ATAPI_READ_MASTER_CUE 0x59 /* read master CUE info */ 477#define ATAPI_MODE_SENSE_BIG 0x5a /* get device parameters */ 478#define ATAPI_CLOSE_TRACK 0x5b /* close track/session */ 479#define ATAPI_READ_BUFFER_CAPACITY 0x5c /* get buffer capicity */ 480#define ATAPI_SEND_CUE_SHEET 0x5d /* send CUE sheet */ 481#define ATAPI_SERVICE_ACTION_IN 0x96 /* get service data */ 482#define ATAPI_BLANK 0xa1 /* blank the media */ 483#define ATAPI_SEND_KEY 0xa3 /* send DVD key structure */ 484#define ATAPI_REPORT_KEY 0xa4 /* get DVD key structure */ 485#define ATAPI_PLAY_12 0xa5 /* play by lba */ 486#define ATAPI_LOAD_UNLOAD 0xa6 /* changer control command */ 487#define ATAPI_READ_STRUCTURE 0xad /* get DVD structure */ 488#define ATAPI_PLAY_CD 0xb4 /* universal play command */ 489#define ATAPI_SET_SPEED 0xbb /* set drive speed */ 490#define ATAPI_MECH_STATUS 0xbd /* get changer status */ 491#define ATAPI_READ_CD 0xbe /* read data */ 492#define ATAPI_POLL_DSC 0xff /* poll DSC status bit */ 493 494 495struct ata_ioc_devices { 496 int channel; 497 char name[2][32]; 498 struct ata_params params[2]; 499}; 500 501/* pr channel ATA ioctl calls */ 502#define IOCATAGMAXCHANNEL _IOR('a', 1, int) 503#define IOCATAREINIT _IOW('a', 2, int) 504#define IOCATAATTACH _IOW('a', 3, int) 505#define IOCATADETACH _IOW('a', 4, int) 506#define IOCATADEVICES _IOWR('a', 5, struct ata_ioc_devices) 507 508/* ATAPI request sense structure */ 509struct atapi_sense { 510 u_int8_t error; /* current or deferred errors */ 511#define ATA_SENSE_VALID 0x80 512 513 u_int8_t segment; /* segment number */ 514 u_int8_t key; /* sense key */ 515#define ATA_SENSE_KEY_MASK 0x0f /* sense key mask */ 516#define ATA_SENSE_NO_SENSE 0x00 /* no specific sense key info */ 517#define ATA_SENSE_RECOVERED_ERROR 0x01 /* command OK, data recovered */ 518#define ATA_SENSE_NOT_READY 0x02 /* no access to drive */ 519#define ATA_SENSE_MEDIUM_ERROR 0x03 /* non-recovered data error */ 520#define ATA_SENSE_HARDWARE_ERROR 0x04 /* non-recoverable HW failure */ 521#define ATA_SENSE_ILLEGAL_REQUEST 0x05 /* invalid command param(s) */ 522#define ATA_SENSE_UNIT_ATTENTION 0x06 /* media changed */ 523#define ATA_SENSE_DATA_PROTECT 0x07 /* write protect */ 524#define ATA_SENSE_BLANK_CHECK 0x08 /* blank check */ 525#define ATA_SENSE_VENDOR_SPECIFIC 0x09 /* vendor specific skey */ 526#define ATA_SENSE_COPY_ABORTED 0x0a /* copy aborted */ 527#define ATA_SENSE_ABORTED_COMMAND 0x0b /* command aborted, try again */ 528#define ATA_SENSE_EQUAL 0x0c /* equal */ 529#define ATA_SENSE_VOLUME_OVERFLOW 0x0d /* volume overflow */ 530#define ATA_SENSE_MISCOMPARE 0x0e /* data dont match the medium */ 531#define ATA_SENSE_RESERVED 0x0f 532#define ATA_SENSE_ILI 0x20; 533#define ATA_SENSE_EOM 0x40; 534#define ATA_SENSE_FILEMARK 0x80; 535 536 u_int32_t cmd_info; /* cmd information */ 537 u_int8_t sense_length; /* additional sense len (n-7) */ 538 u_int32_t cmd_specific_info; /* additional cmd spec info */ 539 u_int8_t asc; /* additional sense code */ 540 u_int8_t ascq; /* additional sense code qual */ 541 u_int8_t replaceable_unit_code; /* replaceable unit code */ 542 u_int8_t specific; /* sense key specific */ 543#define ATA_SENSE_SPEC_VALID 0x80 544#define ATA_SENSE_SPEC_MASK 0x7f 545 546 u_int8_t specific1; /* sense key specific */ 547 u_int8_t specific2; /* sense key specific */ 548} __packed; 549 550struct ata_ioc_request { 551 union { 552 struct { 553 u_int8_t command; 554 u_int8_t feature; 555 u_int64_t lba; 556 u_int16_t count; 557 } ata; 558 struct { 559 char ccb[16]; 560 struct atapi_sense sense; 561 } atapi; 562 } u; 563 caddr_t data; 564 int count; 565 int flags; 566#define ATA_CMD_CONTROL 0x01 567#define ATA_CMD_READ 0x02 568#define ATA_CMD_WRITE 0x04 569#define ATA_CMD_ATAPI 0x08 570 571 int timeout; 572 int error; 573}; 574 575struct ata_security_password { 576 u_int16_t ctrl; 577#define ATA_SECURITY_PASSWORD_USER 0x0000 578#define ATA_SECURITY_PASSWORD_MASTER 0x0001 579#define ATA_SECURITY_ERASE_NORMAL 0x0000 580#define ATA_SECURITY_ERASE_ENHANCED 0x0002 581#define ATA_SECURITY_LEVEL_HIGH 0x0000 582#define ATA_SECURITY_LEVEL_MAXIMUM 0x0100 583 584 u_int8_t password[32]; 585 u_int16_t revision; 586 u_int16_t reserved[238]; 587}; 588 589/* pr device ATA ioctl calls */ 590#define IOCATAREQUEST _IOWR('a', 100, struct ata_ioc_request) 591#define IOCATAGPARM _IOR('a', 101, struct ata_params) 592#define IOCATAGMODE _IOR('a', 102, int) 593#define IOCATASMODE _IOW('a', 103, int) 594 595#define IOCATAGSPINDOWN _IOR('a', 104, int) 596#define IOCATASSPINDOWN _IOW('a', 105, int) 597 598 599struct ata_ioc_raid_config { 600 int lun; 601 int type; 602#define AR_JBOD 0x0001 603#define AR_SPAN 0x0002 604#define AR_RAID0 0x0004 605#define AR_RAID1 0x0008 606#define AR_RAID01 0x0010 607#define AR_RAID3 0x0020 608#define AR_RAID4 0x0040 609#define AR_RAID5 0x0080 610 611 int interleave; 612 int status; 613#define AR_READY 1 614#define AR_DEGRADED 2 615#define AR_REBUILDING 4 616 617 int progress; 618 int total_disks; 619 int disks[16]; 620}; 621 622struct ata_ioc_raid_status { 623 int lun; 624 int type; 625 int interleave; 626 int status; 627 int progress; 628 int total_disks; 629 struct { 630 int state; 631#define AR_DISK_ONLINE 0x01 632#define AR_DISK_PRESENT 0x02 633#define AR_DISK_SPARE 0x04 634 int lun; 635 } disks[16]; 636}; 637 638/* ATA RAID ioctl calls */ 639#define IOCATARAIDCREATE _IOWR('a', 200, struct ata_ioc_raid_config) 640#define IOCATARAIDDELETE _IOW('a', 201, int) 641#define IOCATARAIDSTATUS _IOWR('a', 202, struct ata_ioc_raid_status) 642#define IOCATARAIDADDSPARE _IOW('a', 203, struct ata_ioc_raid_config) 643#define IOCATARAIDREBUILD _IOW('a', 204, int) 644 645#endif /* _SYS_ATA_H_ */ 646