ata.h revision 144330
10SN/A/*- 2157SN/A * Copyright (c) 2000 - 2005 S�ren Schmidt <sos@FreeBSD.org> 30SN/A * All rights reserved. 40SN/A * 50SN/A * Redistribution and use in source and binary forms, with or without 60SN/A * modification, are permitted provided that the following conditions 7157SN/A * are met: 80SN/A * 1. Redistributions of source code must retain the above copyright 9157SN/A * notice, this list of conditions and the following disclaimer, 100SN/A * without modification, immediately at the beginning of the file. 110SN/A * 2. Redistributions in binary form must reproduce the above copyright 120SN/A * notice, this list of conditions and the following disclaimer in the 130SN/A * documentation and/or other materials provided with the distribution. 140SN/A * 3. The name of the author may not be used to endorse or promote products 150SN/A * derived from this software without specific prior written permission. 160SN/A * 170SN/A * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 180SN/A * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 190SN/A * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 200SN/A * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21157SN/A * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22157SN/A * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23157SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 240SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 250SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 260SN/A * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 270SN/A * 280SN/A * $FreeBSD: head/sys/sys/ata.h 144330 2005-03-30 12:03:40Z sos $ 290SN/A */ 300SN/A 310SN/A#ifndef _SYS_ATA_H_ 320SN/A#define _SYS_ATA_H_ 330SN/A 340SN/A#include <sys/ioccom.h> 350SN/A 360SN/A/* ATA/ATAPI device parameters */ 370SN/Astruct ata_params { 380SN/A/*000*/ u_int16_t config; /* configuration info */ 390SN/A#define ATA_PROTO_MASK 0x8003 400SN/A#define ATA_PROTO_ATA 0x0000 410SN/A#define ATA_PROTO_ATAPI_12 0x8000 420SN/A#define ATA_PROTO_ATAPI_16 0x8001 430SN/A#define ATA_ATAPI_TYPE_MASK 0x1f00 440SN/A#define ATA_ATAPI_TYPE_DIRECT 0x0000 /* disk/floppy */ 450SN/A#define ATA_ATAPI_TYPE_TAPE 0x0100 /* streaming tape */ 460SN/A#define ATA_ATAPI_TYPE_CDROM 0x0500 /* CD-ROM device */ 470SN/A#define ATA_ATAPI_TYPE_OPTICAL 0x0700 /* optical disk */ 480SN/A#define ATA_DRQ_MASK 0x0060 490SN/A#define ATA_DRQ_SLOW 0x0000 /* cpu 3 ms delay */ 500SN/A#define ATA_DRQ_INTR 0x0020 /* interrupt 10 ms delay */ 510SN/A#define ATA_DRQ_FAST 0x0040 /* accel 50 us delay */ 520SN/A 530SN/A/*001*/ u_int16_t cylinders; /* # of cylinders */ 540SN/A u_int16_t reserved2; 550SN/A/*003*/ u_int16_t heads; /* # heads */ 560SN/A u_int16_t obsolete4; 570SN/A u_int16_t obsolete5; 580SN/A/*006*/ u_int16_t sectors; /* # sectors/track */ 590SN/A/*007*/ u_int16_t vendor7[3]; 600SN/A/*010*/ u_int8_t serial[20]; /* serial number */ 610SN/A/*020*/ u_int16_t retired20; 620SN/A u_int16_t retired21; 630SN/A u_int16_t obsolete22; 640SN/A/*023*/ u_int8_t revision[8]; /* firmware revision */ 650SN/A/*027*/ u_int8_t model[40]; /* model name */ 660SN/A/*047*/ u_int16_t sectors_intr; /* sectors per interrupt */ 670SN/A/*048*/ u_int16_t usedmovsd; /* double word read/write? */ 680SN/A/*049*/ u_int16_t capabilities1; 690SN/A#define ATA_SUPPORT_DMA 0x0100 700SN/A#define ATA_SUPPORT_LBA 0x0200 710SN/A#define ATA_SUPPORT_OVERLAP 0x4000 720SN/A 730SN/A/*050*/ u_int16_t capabilities2; 740SN/A/*051*/ u_int16_t retired_piomode; /* PIO modes 0-2 */ 750SN/A#define ATA_RETIRED_PIO_MASK 0x0300 760SN/A 770SN/A/*052*/ u_int16_t retired_dmamode; /* DMA modes */ 780SN/A#define ATA_RETIRED_DMA_MASK 0x0003 790SN/A 800SN/A/*053*/ u_int16_t atavalid; /* fields valid */ 810SN/A#define ATA_FLAG_54_58 0x0001 /* words 54-58 valid */ 820SN/A#define ATA_FLAG_64_70 0x0002 /* words 64-70 valid */ 830SN/A#define ATA_FLAG_88 0x0004 /* word 88 valid */ 840SN/A 850SN/A/*054*/ u_int16_t current_cylinders; 860SN/A/*055*/ u_int16_t current_heads; 870SN/A/*056*/ u_int16_t current_sectors; 880SN/A/*057*/ u_int16_t current_size_1; 890SN/A/*058*/ u_int16_t current_size_2; 900SN/A/*059*/ u_int16_t multi; 910SN/A#define ATA_MULTI_VALID 0x0100 920SN/A 930SN/A/*060*/ u_int16_t lba_size_1; 940SN/A u_int16_t lba_size_2; 950SN/A u_int16_t obsolete62; 960SN/A/*063*/ u_int16_t mwdmamodes; /* multiword DMA modes */ 970SN/A/*064*/ u_int16_t apiomodes; /* advanced PIO modes */ 980SN/A 990SN/A/*065*/ u_int16_t mwdmamin; /* min. M/W DMA time/word ns */ 1000SN/A/*066*/ u_int16_t mwdmarec; /* rec. M/W DMA time ns */ 1010SN/A/*067*/ u_int16_t pioblind; /* min. PIO cycle w/o flow */ 1020SN/A/*068*/ u_int16_t pioiordy; /* min. PIO cycle IORDY flow */ 1030SN/A u_int16_t reserved69; 1040SN/A u_int16_t reserved70; 1050SN/A/*071*/ u_int16_t rlsovlap; /* rel time (us) for overlap */ 1060SN/A/*072*/ u_int16_t rlsservice; /* rel time (us) for service */ 1070SN/A u_int16_t reserved73; 1080SN/A u_int16_t reserved74; 1090SN/A/*075*/ u_int16_t queue; 1100SN/A#define ATA_QUEUE_LEN(x) ((x) & 0x001f) 1110SN/A 1120SN/A u_int16_t satacapabilities; 1130SN/A#define ATA_SATA_GEN1 0x0002 1140SN/A#define ATA_SATA_GEN2 0x0004 1150SN/A#define ATA_SUPPORT_NCQ 0x0100 1160SN/A#define ATA_SUPPORT_IFPWRMNGTRCV 0x0200 1170SN/A 1180SN/A u_int16_t reserved77; 1190SN/A u_int16_t satasupport; 1200SN/A#define ATA_SUPPORT_NONZERO 0x0002 1210SN/A#define ATA_SUPPORT_AUTOACTIVATE 0x0004 1220SN/A#define ATA_SUPPORT_IFPWRMNGT 0x0008 1230SN/A#define ATA_SUPPORT_INORDERDATA 0x0010 1240SN/A u_int16_t sataenabled; 1250SN/A 1260SN/A/*080*/ u_int16_t version_major; 1270SN/A/*081*/ u_int16_t version_minor; 1280SN/A 1290SN/A struct { 1300SN/A/*082/085*/ u_int16_t command1; 1310SN/A#define ATA_SUPPORT_SMART 0x0001 1320SN/A#define ATA_SUPPORT_SECURITY 0x0002 1330SN/A#define ATA_SUPPORT_REMOVABLE 0x0004 1340SN/A#define ATA_SUPPORT_POWERMGT 0x0008 1350SN/A#define ATA_SUPPORT_PACKET 0x0010 1360SN/A#define ATA_SUPPORT_WRITECACHE 0x0020 1370SN/A#define ATA_SUPPORT_LOOKAHEAD 0x0040 1380SN/A#define ATA_SUPPORT_RELEASEIRQ 0x0080 1390SN/A#define ATA_SUPPORT_SERVICEIRQ 0x0100 1400SN/A#define ATA_SUPPORT_RESET 0x0200 1410SN/A#define ATA_SUPPORT_PROTECTED 0x0400 1420SN/A#define ATA_SUPPORT_WRITEBUFFER 0x1000 1430SN/A#define ATA_SUPPORT_READBUFFER 0x2000 1440SN/A#define ATA_SUPPORT_NOP 0x4000 1450SN/A 1460SN/A/*083/086*/ u_int16_t command2; 1470SN/A#define ATA_SUPPORT_MICROCODE 0x0001 1480SN/A#define ATA_SUPPORT_QUEUED 0x0002 1490SN/A#define ATA_SUPPORT_CFA 0x0004 1500SN/A#define ATA_SUPPORT_APM 0x0008 1510SN/A#define ATA_SUPPORT_NOTIFY 0x0010 1520SN/A#define ATA_SUPPORT_STANDBY 0x0020 1530SN/A#define ATA_SUPPORT_SPINUP 0x0040 1540SN/A#define ATA_SUPPORT_MAXSECURITY 0x0100 1550SN/A#define ATA_SUPPORT_AUTOACOUSTIC 0x0200 1560SN/A#define ATA_SUPPORT_ADDRESS48 0x0400 1570SN/A#define ATA_SUPPORT_OVERLAY 0x0800 1580SN/A#define ATA_SUPPORT_FLUSHCACHE 0x1000 1590SN/A#define ATA_SUPPORT_FLUSHCACHE48 0x2000 1600SN/A 1610SN/A/*084/087*/ u_int16_t extension; 1620SN/A } __packed support, enabled; 1630SN/A 1640SN/A/*088*/ u_int16_t udmamodes; /* UltraDMA modes */ 1650SN/A/*089*/ u_int16_t erase_time; 1660SN/A/*090*/ u_int16_t enhanced_erase_time; 1670SN/A/*091*/ u_int16_t apm_value; 1680SN/A/*092*/ u_int16_t master_passwd_revision; 1690SN/A/*093*/ u_int16_t hwres; 1700SN/A#define ATA_CABLE_ID 0x2000 1710SN/A 1720SN/A/*094*/ u_int16_t acoustic; 1730SN/A#define ATA_ACOUSTIC_CURRENT(x) ((x) & 0x00ff) 1740SN/A#define ATA_ACOUSTIC_VENDOR(x) (((x) & 0xff00) >> 8) 1750SN/A 1760SN/A/*095*/ u_int16_t stream_min_req_size; 1770SN/A/*096*/ u_int16_t stream_transfer_time; 1780SN/A/*097*/ u_int16_t stream_access_latency; 1790SN/A/*098*/ u_int32_t stream_granularity; 1800SN/A/*100*/ u_int16_t lba_size48_1; 1810SN/A u_int16_t lba_size48_2; 1820SN/A u_int16_t lba_size48_3; 1830SN/A u_int16_t lba_size48_4; 1840SN/A u_int16_t reserved104[23]; 1850SN/A/*127*/ u_int16_t removable_status; 1860SN/A/*128*/ u_int16_t security_status; 1870SN/A u_int16_t reserved129[31]; 1880SN/A/*160*/ u_int16_t cfa_powermode1; 1890SN/A u_int16_t reserved161[15]; 1900SN/A/*176*/ u_int16_t media_serial[30]; 1910SN/A u_int16_t reserved206[49]; 1920SN/A/*255*/ u_int16_t integrity; 1930SN/A} __packed; 1940SN/A 1950SN/A/* ATA transfer modes */ 1960SN/A#define ATA_MODE_MASK 0x0f 1970SN/A#define ATA_DMA_MASK 0xf0 1980SN/A#define ATA_PIO 0x00 1990SN/A#define ATA_PIO0 0x08 2000SN/A#define ATA_PIO1 0x09 2010SN/A#define ATA_PIO2 0x0a 2020SN/A#define ATA_PIO3 0x0b 2030SN/A#define ATA_PIO4 0x0c 2040SN/A#define ATA_PIO_MAX 0x0f 2050SN/A#define ATA_DMA 0x10 2060SN/A#define ATA_WDMA0 0x20 2070SN/A#define ATA_WDMA1 0x21 2080SN/A#define ATA_WDMA2 0x22 2090SN/A#define ATA_UDMA0 0x40 2100SN/A#define ATA_UDMA1 0x41 2110SN/A#define ATA_UDMA2 0x42 2120SN/A#define ATA_UDMA3 0x43 2130SN/A#define ATA_UDMA4 0x44 2140SN/A#define ATA_UDMA5 0x45 2150SN/A#define ATA_UDMA6 0x46 2160SN/A#define ATA_SA150 0x47 2170SN/A#define ATA_DMA_MAX 0x4f 2180SN/A 2190SN/A/* ATA commands */ 2200SN/A#define ATA_NOP 0x00 /* NOP command */ 2210SN/A#define ATA_NF_FLUSHQUEUE 0x00 /* flush queued cmd's */ 2220SN/A#define ATA_NF_AUTOPOLL 0x01 /* start autopoll function */ 2230SN/A#define ATA_ATAPI_RESET 0x08 /* reset ATAPI device */ 2240SN/A#define ATA_READ 0x20 /* read command */ 2250SN/A#define ATA_READ48 0x24 /* read command */ 2260SN/A#define ATA_READ_DMA48 0x25 /* read w/DMA command */ 2270SN/A#define ATA_READ_DMA_QUEUED48 0x26 /* read w/DMA QUEUED command */ 2280SN/A#define ATA_READ_MUL48 0x29 /* read multi command */ 2290SN/A#define ATA_WRITE 0x30 /* write command */ 2300SN/A#define ATA_WRITE48 0x34 /* write command */ 2310SN/A#define ATA_WRITE_DMA48 0x35 /* write w/DMA command */ 2320SN/A#define ATA_WRITE_DMA_QUEUED48 0x36 /* write w/DMA QUEUED command */ 2330SN/A#define ATA_WRITE_MUL48 0x39 /* write multi command */ 2340SN/A#define ATA_PACKET_CMD 0xa0 /* packet command */ 2350SN/A#define ATA_ATAPI_IDENTIFY 0xa1 /* get ATAPI params*/ 2360SN/A#define ATA_SERVICE 0xa2 /* service command */ 2370SN/A#define ATA_READ_MUL 0xc4 /* read multi command */ 2380SN/A#define ATA_WRITE_MUL 0xc5 /* write multi command */ 2390SN/A#define ATA_SET_MULTI 0xc6 /* set multi size command */ 2400SN/A#define ATA_READ_DMA_QUEUED 0xc7 /* read w/DMA QUEUED command */ 2410SN/A#define ATA_READ_DMA 0xc8 /* read w/DMA command */ 2420SN/A#define ATA_WRITE_DMA 0xca /* write w/DMA command */ 2430SN/A#define ATA_WRITE_DMA_QUEUED 0xcc /* write w/DMA QUEUED command */ 2440SN/A#define ATA_SLEEP 0xe6 /* sleep command */ 2450SN/A#define ATA_FLUSHCACHE 0xe7 /* flush cache to disk */ 2460SN/A#define ATA_FLUSHCACHE48 0xea /* flush cache to disk */ 2470SN/A#define ATA_ATA_IDENTIFY 0xec /* get ATA params */ 2480SN/A#define ATA_SETFEATURES 0xef /* features command */ 2490SN/A#define ATA_SF_SETXFER 0x03 /* set transfer mode */ 2500SN/A#define ATA_SF_ENAB_WCACHE 0x02 /* enable write cache */ 2510SN/A#define ATA_SF_DIS_WCACHE 0x82 /* disable write cache */ 2520SN/A#define ATA_SF_ENAB_RCACHE 0xaa /* enable readahead cache */ 2530SN/A#define ATA_SF_DIS_RCACHE 0x55 /* disable readahead cache */ 2540SN/A#define ATA_SF_ENAB_RELIRQ 0x5d /* enable release interrupt */ 2550SN/A#define ATA_SF_DIS_RELIRQ 0xdd /* disable release interrupt */ 2560SN/A#define ATA_SF_ENAB_SRVIRQ 0x5e /* enable service interrupt */ 2570SN/A#define ATA_SF_DIS_SRVIRQ 0xde /* disable service interrupt */ 2580SN/A 2590SN/A/* ATAPI commands */ 2600SN/A#define ATAPI_TEST_UNIT_READY 0x00 /* check if device is ready */ 2610SN/A#define ATAPI_REZERO 0x01 /* rewind */ 2620SN/A#define ATAPI_REQUEST_SENSE 0x03 /* get sense data */ 2630SN/A#define ATAPI_FORMAT 0x04 /* format unit */ 2640SN/A#define ATAPI_READ 0x08 /* read data */ 2650SN/A#define ATAPI_WRITE 0x0a /* write data */ 2660SN/A#define ATAPI_WEOF 0x10 /* write filemark */ 2670SN/A#define ATAPI_WF_WRITE 0x01 2680SN/A#define ATAPI_SPACE 0x11 /* space command */ 2690SN/A#define ATAPI_SP_FM 0x01 2700SN/A#define ATAPI_SP_EOD 0x03 271#define ATAPI_MODE_SELECT 0x15 /* mode select */ 272#define ATAPI_ERASE 0x19 /* erase */ 273#define ATAPI_MODE_SENSE 0x1a /* mode sense */ 274#define ATAPI_START_STOP 0x1b /* start/stop unit */ 275#define ATAPI_SS_LOAD 0x01 276#define ATAPI_SS_RETENSION 0x02 277#define ATAPI_SS_EJECT 0x04 278#define ATAPI_PREVENT_ALLOW 0x1e /* media removal */ 279#define ATAPI_READ_FORMAT_CAPACITIES 0x23 /* get format capacities */ 280#define ATAPI_READ_CAPACITY 0x25 /* get volume capacity */ 281#define ATAPI_READ_BIG 0x28 /* read data */ 282#define ATAPI_WRITE_BIG 0x2a /* write data */ 283#define ATAPI_LOCATE 0x2b /* locate to position */ 284#define ATAPI_READ_POSITION 0x34 /* read position */ 285#define ATAPI_SYNCHRONIZE_CACHE 0x35 /* flush buf, close channel */ 286#define ATAPI_WRITE_BUFFER 0x3b /* write device buffer */ 287#define ATAPI_READ_BUFFER 0x3c /* read device buffer */ 288#define ATAPI_READ_SUBCHANNEL 0x42 /* get subchannel info */ 289#define ATAPI_READ_TOC 0x43 /* get table of contents */ 290#define ATAPI_PLAY_10 0x45 /* play by lba */ 291#define ATAPI_PLAY_MSF 0x47 /* play by MSF address */ 292#define ATAPI_PLAY_TRACK 0x48 /* play by track number */ 293#define ATAPI_PAUSE 0x4b /* pause audio operation */ 294#define ATAPI_READ_DISK_INFO 0x51 /* get disk info structure */ 295#define ATAPI_READ_TRACK_INFO 0x52 /* get track info structure */ 296#define ATAPI_RESERVE_TRACK 0x53 /* reserve track */ 297#define ATAPI_SEND_OPC_INFO 0x54 /* send OPC structurek */ 298#define ATAPI_MODE_SELECT_BIG 0x55 /* set device parameters */ 299#define ATAPI_REPAIR_TRACK 0x58 /* repair track */ 300#define ATAPI_READ_MASTER_CUE 0x59 /* read master CUE info */ 301#define ATAPI_MODE_SENSE_BIG 0x5a /* get device parameters */ 302#define ATAPI_CLOSE_TRACK 0x5b /* close track/session */ 303#define ATAPI_READ_BUFFER_CAPACITY 0x5c /* get buffer capicity */ 304#define ATAPI_SEND_CUE_SHEET 0x5d /* send CUE sheet */ 305#define ATAPI_BLANK 0xa1 /* blank the media */ 306#define ATAPI_SEND_KEY 0xa3 /* send DVD key structure */ 307#define ATAPI_REPORT_KEY 0xa4 /* get DVD key structure */ 308#define ATAPI_PLAY_12 0xa5 /* play by lba */ 309#define ATAPI_LOAD_UNLOAD 0xa6 /* changer control command */ 310#define ATAPI_READ_STRUCTURE 0xad /* get DVD structure */ 311#define ATAPI_PLAY_CD 0xb4 /* universal play command */ 312#define ATAPI_SET_SPEED 0xbb /* set drive speed */ 313#define ATAPI_MECH_STATUS 0xbd /* get changer status */ 314#define ATAPI_READ_CD 0xbe /* read data */ 315#define ATAPI_POLL_DSC 0xff /* poll DSC status bit */ 316 317struct ata_cmd { 318 int channel; 319 int device; 320 int cmd; 321#define ATAGMAXCHANNEL 0x0101 322#define ATAGPARM 0x0102 323#define ATAGMODE 0x0103 324#define ATASMODE 0x0104 325#define ATAREQUEST 0x0108 326#define ATAREINIT 0x0110 327#define ATAATTACH 0x0111 328#define ATADETACH 0x0112 329#define ATARAIDCREATE 0x0120 330#define ATARAIDDELETE 0x0121 331#define ATARAIDSTATUS 0x0122 332#define ATARAIDADDSPARE 0x0123 333#define ATARAIDREBUILD 0x0124 334#define ATAENCSTAT 0x0130 335 336 union { 337 int maxchan; 338 339 struct { 340 int type[2]; 341 char name[2][32]; 342 struct ata_params params[2]; 343 } param; 344 345 struct { 346 int mode[2]; 347 } mode; 348 349 struct { 350 union { 351 struct { 352 u_int8_t command; 353 u_int8_t feature; 354 u_int64_t lba; 355 u_int16_t count; 356 } ata; 357 struct { 358 char ccb[16]; 359 } atapi; 360 } u; 361 caddr_t data; 362 int count; 363 int flags; 364#define ATA_CMD_CONTROL 0x01 365#define ATA_CMD_READ 0x02 366#define ATA_CMD_WRITE 0x04 367#define ATA_CMD_ATAPI 0x08 368 369 int timeout; 370 int error; 371 } request; 372 373 struct raid_setup { 374 int type; 375#define AR_JBOD 0x01 376#define AR_SPAN 0x02 377#define AR_RAID0 0x04 378#define AR_RAID1 0x08 379#define AR_RAID01 0x10 380#define AR_RAID3 0x20 381#define AR_RAID4 0x40 382#define AR_RAID5 0x80 383 384 int total_disks; 385 int disks[16]; 386 int interleave; 387 int unit; 388 } raid_setup; 389 390 struct raid_status { 391 int type; 392 int total_disks; 393 int disks[16]; 394 int interleave; 395 int status; 396#define AR_READY 1 397#define AR_DEGRADED 2 398#define AR_REBUILDING 4 399 400 int progress; 401 } raid_status; 402 403 struct { 404 int disk; 405 } raid_spare; 406 407 struct { 408 int fan; 409 int temp; 410 int v05; 411 int v12; 412 } enclosure; 413 } u; 414}; 415 416#define IOCATA _IOWR('a', 1, struct ata_cmd) 417 418#endif /* _SYS_ATA_H_ */ 419