174298Ssos/*-
2230132Suqs * Copyright (c) 2000 - 2008 S��ren Schmidt <sos@FreeBSD.org>
374298Ssos * All rights reserved.
474298Ssos *
574298Ssos * Redistribution and use in source and binary forms, with or without
674298Ssos * modification, are permitted provided that the following conditions
774298Ssos * are met:
874298Ssos * 1. Redistributions of source code must retain the above copyright
974298Ssos *    notice, this list of conditions and the following disclaimer,
1074298Ssos *    without modification, immediately at the beginning of the file.
1174298Ssos * 2. Redistributions in binary form must reproduce the above copyright
1274298Ssos *    notice, this list of conditions and the following disclaimer in the
1374298Ssos *    documentation and/or other materials provided with the distribution.
1474298Ssos *
1574298Ssos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1674298Ssos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1774298Ssos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
1874298Ssos * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
1974298Ssos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2074298Ssos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2174298Ssos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2274298Ssos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2374298Ssos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2474298Ssos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2574298Ssos *
2674298Ssos * $FreeBSD$
2774298Ssos */
2874298Ssos
2974298Ssos#ifndef _SYS_ATA_H_
3074298Ssos#define _SYS_ATA_H_
3174298Ssos
3274298Ssos#include <sys/ioccom.h>
3374298Ssos
34119404Ssos/* ATA/ATAPI device parameters */
3593881Ssosstruct ata_params {
36146266Ssos/*000*/ u_int16_t       config;         /* configuration info */
37146266Ssos#define ATA_PROTO_MASK                  0x8003
38146266Ssos#define ATA_PROTO_ATAPI                 0x8000
39146266Ssos#define ATA_PROTO_ATAPI_12              0x8000
40146266Ssos#define ATA_PROTO_ATAPI_16              0x8001
41174682Sphk#define ATA_PROTO_CFA                   0x848a
42146266Ssos#define ATA_ATAPI_TYPE_MASK             0x1f00
43146266Ssos#define ATA_ATAPI_TYPE_DIRECT           0x0000  /* disk/floppy */
44146266Ssos#define ATA_ATAPI_TYPE_TAPE             0x0100  /* streaming tape */
45146266Ssos#define ATA_ATAPI_TYPE_CDROM            0x0500  /* CD-ROM device */
46146266Ssos#define ATA_ATAPI_TYPE_OPTICAL          0x0700  /* optical disk */
47146266Ssos#define ATA_DRQ_MASK                    0x0060
48146266Ssos#define ATA_DRQ_SLOW                    0x0000  /* cpu 3 ms delay */
49146266Ssos#define ATA_DRQ_INTR                    0x0020  /* interrupt 10 ms delay */
50146266Ssos#define ATA_DRQ_FAST                    0x0040  /* accel 50 us delay */
51203421Smav#define ATA_RESP_INCOMPLETE             0x0004
5293881Ssos
53146266Ssos/*001*/ u_int16_t       cylinders;              /* # of cylinders */
54204354Smav/*002*/ u_int16_t       specconf;		/* specific configuration */
55146266Ssos/*003*/ u_int16_t       heads;                  /* # heads */
56146266Ssos	u_int16_t       obsolete4;
57146266Ssos	u_int16_t       obsolete5;
58146266Ssos/*006*/ u_int16_t       sectors;                /* # sectors/track */
59146266Ssos/*007*/ u_int16_t       vendor7[3];
60146266Ssos/*010*/ u_int8_t        serial[20];             /* serial number */
61146266Ssos/*020*/ u_int16_t       retired20;
62146266Ssos	u_int16_t       retired21;
63146266Ssos	u_int16_t       obsolete22;
64146266Ssos/*023*/ u_int8_t        revision[8];            /* firmware revision */
65146266Ssos/*027*/ u_int8_t        model[40];              /* model name */
66146266Ssos/*047*/ u_int16_t       sectors_intr;           /* sectors per interrupt */
67146266Ssos/*048*/ u_int16_t       usedmovsd;              /* double word read/write? */
68146266Ssos/*049*/ u_int16_t       capabilities1;
69146266Ssos#define ATA_SUPPORT_DMA                 0x0100
70146266Ssos#define ATA_SUPPORT_LBA                 0x0200
71197540Smav#define ATA_SUPPORT_IORDY               0x0400
72197540Smav#define ATA_SUPPORT_IORDYDIS            0x0800
73146266Ssos#define ATA_SUPPORT_OVERLAP             0x4000
7493881Ssos
75146266Ssos/*050*/ u_int16_t       capabilities2;
76146266Ssos/*051*/ u_int16_t       retired_piomode;        /* PIO modes 0-2 */
77146266Ssos#define ATA_RETIRED_PIO_MASK            0x0300
7874298Ssos
79146266Ssos/*052*/ u_int16_t       retired_dmamode;        /* DMA modes */
80146266Ssos#define ATA_RETIRED_DMA_MASK            0x0003
8174298Ssos
82146266Ssos/*053*/ u_int16_t       atavalid;               /* fields valid */
83146266Ssos#define ATA_FLAG_54_58                  0x0001  /* words 54-58 valid */
84146266Ssos#define ATA_FLAG_64_70                  0x0002  /* words 64-70 valid */
85146266Ssos#define ATA_FLAG_88                     0x0004  /* word 88 valid */
8674298Ssos
87146266Ssos/*054*/ u_int16_t       current_cylinders;
88146266Ssos/*055*/ u_int16_t       current_heads;
89146266Ssos/*056*/ u_int16_t       current_sectors;
90146266Ssos/*057*/ u_int16_t       current_size_1;
91146266Ssos/*058*/ u_int16_t       current_size_2;
92146266Ssos/*059*/ u_int16_t       multi;
93146266Ssos#define ATA_MULTI_VALID                 0x0100
9493881Ssos
95146266Ssos/*060*/ u_int16_t       lba_size_1;
96146266Ssos	u_int16_t       lba_size_2;
97146266Ssos	u_int16_t       obsolete62;
98146266Ssos/*063*/ u_int16_t       mwdmamodes;             /* multiword DMA modes */
99146266Ssos/*064*/ u_int16_t       apiomodes;              /* advanced PIO modes */
10074298Ssos
101146266Ssos/*065*/ u_int16_t       mwdmamin;               /* min. M/W DMA time/word ns */
102146266Ssos/*066*/ u_int16_t       mwdmarec;               /* rec. M/W DMA time ns */
103146266Ssos/*067*/ u_int16_t       pioblind;               /* min. PIO cycle w/o flow */
104146266Ssos/*068*/ u_int16_t       pioiordy;               /* min. PIO cycle IORDY flow */
105201139Smav/*069*/ u_int16_t       support3;
106201139Smav#define ATA_SUPPORT_RZAT                0x0020
107201139Smav#define ATA_SUPPORT_DRAT                0x4000
108146266Ssos	u_int16_t       reserved70;
109146266Ssos/*071*/ u_int16_t       rlsovlap;               /* rel time (us) for overlap */
110146266Ssos/*072*/ u_int16_t       rlsservice;             /* rel time (us) for service */
111146266Ssos	u_int16_t       reserved73;
112146266Ssos	u_int16_t       reserved74;
113146266Ssos/*075*/ u_int16_t       queue;
114146266Ssos#define ATA_QUEUE_LEN(x)                ((x) & 0x001f)
11574298Ssos
116197540Smav/*76*/  u_int16_t       satacapabilities;
117146266Ssos#define ATA_SATA_GEN1                   0x0002
118146266Ssos#define ATA_SATA_GEN2                   0x0004
119197540Smav#define ATA_SATA_GEN3                   0x0008
120146266Ssos#define ATA_SUPPORT_NCQ                 0x0100
121146266Ssos#define ATA_SUPPORT_IFPWRMNGTRCV        0x0200
122194902Smav#define ATA_SUPPORT_PHYEVENTCNT         0x0400
123194902Smav#define ATA_SUPPORT_NCQ_UNLOAD          0x0800
124194902Smav#define ATA_SUPPORT_NCQ_PRIO            0x1000
125197540Smav#define ATA_SUPPORT_HAPST               0x2000
126197540Smav#define ATA_SUPPORT_DAPST               0x4000
127197540Smav#define ATA_SUPPORT_READLOGDMAEXT       0x8000
128127021Ssos
129197540Smav/*77*/  u_int16_t       satacapabilities2;
130197540Smav#define ATA_SATA_CURR_GEN_MASK          0x0006
131197540Smav#define ATA_SUPPORT_NCQ_STREAM          0x0010
132197540Smav#define ATA_SUPPORT_NCQ_QMANAGEMENT     0x0020
133265659Ssmh#define ATA_SUPPORT_RCVSND_FPDMA_QUEUED 0x0040
134197540Smav/*78*/  u_int16_t       satasupport;
135146266Ssos#define ATA_SUPPORT_NONZERO             0x0002
136146266Ssos#define ATA_SUPPORT_AUTOACTIVATE        0x0004
137146266Ssos#define ATA_SUPPORT_IFPWRMNGT           0x0008
138146266Ssos#define ATA_SUPPORT_INORDERDATA         0x0010
139220602Smav#define ATA_SUPPORT_ASYNCNOTIF          0x0020
140197540Smav#define ATA_SUPPORT_SOFTSETPRESERVE     0x0040
141197540Smav/*79*/  u_int16_t       sataenabled;
142197540Smav#define ATA_ENABLED_DAPST               0x0080
143127021Ssos
144146266Ssos/*080*/ u_int16_t       version_major;
145146266Ssos/*081*/ u_int16_t       version_minor;
146119404Ssos
14784584Ssos	struct {
148146266Ssos/*082/085*/ u_int16_t   command1;
149146266Ssos#define ATA_SUPPORT_SMART               0x0001
150146266Ssos#define ATA_SUPPORT_SECURITY            0x0002
151146266Ssos#define ATA_SUPPORT_REMOVABLE           0x0004
152146266Ssos#define ATA_SUPPORT_POWERMGT            0x0008
153146266Ssos#define ATA_SUPPORT_PACKET              0x0010
154146266Ssos#define ATA_SUPPORT_WRITECACHE          0x0020
155146266Ssos#define ATA_SUPPORT_LOOKAHEAD           0x0040
156146266Ssos#define ATA_SUPPORT_RELEASEIRQ          0x0080
157146266Ssos#define ATA_SUPPORT_SERVICEIRQ          0x0100
158146266Ssos#define ATA_SUPPORT_RESET               0x0200
159146266Ssos#define ATA_SUPPORT_PROTECTED           0x0400
160146266Ssos#define ATA_SUPPORT_WRITEBUFFER         0x1000
161146266Ssos#define ATA_SUPPORT_READBUFFER          0x2000
162146266Ssos#define ATA_SUPPORT_NOP                 0x4000
16384584Ssos
164146266Ssos/*083/086*/ u_int16_t   command2;
165146266Ssos#define ATA_SUPPORT_MICROCODE           0x0001
166146266Ssos#define ATA_SUPPORT_QUEUED              0x0002
167146266Ssos#define ATA_SUPPORT_CFA                 0x0004
168146266Ssos#define ATA_SUPPORT_APM                 0x0008
169146266Ssos#define ATA_SUPPORT_NOTIFY              0x0010
170146266Ssos#define ATA_SUPPORT_STANDBY             0x0020
171146266Ssos#define ATA_SUPPORT_SPINUP              0x0040
172146266Ssos#define ATA_SUPPORT_MAXSECURITY         0x0100
173146266Ssos#define ATA_SUPPORT_AUTOACOUSTIC        0x0200
174146266Ssos#define ATA_SUPPORT_ADDRESS48           0x0400
175146266Ssos#define ATA_SUPPORT_OVERLAY             0x0800
176146266Ssos#define ATA_SUPPORT_FLUSHCACHE          0x1000
177146266Ssos#define ATA_SUPPORT_FLUSHCACHE48        0x2000
17884584Ssos
179146266Ssos/*084/087*/ u_int16_t   extension;
180197540Smav#define ATA_SUPPORT_SMARTLOG		0x0001
181197540Smav#define ATA_SUPPORT_SMARTTEST		0x0002
182172606Sscottl#define ATA_SUPPORT_MEDIASN		0x0004
183172606Sscottl#define ATA_SUPPORT_MEDIAPASS		0x0008
184172606Sscottl#define ATA_SUPPORT_STREAMING		0x0010
185172606Sscottl#define ATA_SUPPORT_GENLOG		0x0020
186172606Sscottl#define ATA_SUPPORT_WRITEDMAFUAEXT	0x0040
187172606Sscottl#define ATA_SUPPORT_WRITEDMAQFUAEXT	0x0080
188172606Sscottl#define ATA_SUPPORT_64BITWWN		0x0100
189197540Smav#define ATA_SUPPORT_UNLOAD		0x2000
190144330Ssos	} __packed support, enabled;
19184584Ssos
192146266Ssos/*088*/ u_int16_t       udmamodes;              /* UltraDMA modes */
193249115Ssmh/*089*/ u_int16_t       erase_time;             /* time req'd in 2min units */
194249115Ssmh/*090*/ u_int16_t       enhanced_erase_time;    /* time req'd in 2min units */
195146266Ssos/*091*/ u_int16_t       apm_value;
196249115Ssmh/*092*/ u_int16_t       master_passwd_revision; /* password revision code */
197146266Ssos/*093*/ u_int16_t       hwres;
198146266Ssos#define ATA_CABLE_ID                    0x2000
19984584Ssos
200146266Ssos/*094*/ u_int16_t       acoustic;
201146266Ssos#define ATA_ACOUSTIC_CURRENT(x)         ((x) & 0x00ff)
202146266Ssos#define ATA_ACOUSTIC_VENDOR(x)          (((x) & 0xff00) >> 8)
20384584Ssos
204146266Ssos/*095*/ u_int16_t       stream_min_req_size;
205146266Ssos/*096*/ u_int16_t       stream_transfer_time;
206146266Ssos/*097*/ u_int16_t       stream_access_latency;
207146266Ssos/*098*/ u_int32_t       stream_granularity;
208146266Ssos/*100*/ u_int16_t       lba_size48_1;
209146266Ssos	u_int16_t       lba_size48_2;
210146266Ssos	u_int16_t       lba_size48_3;
211146266Ssos	u_int16_t       lba_size48_4;
212201139Smav	u_int16_t       reserved104;
213201139Smav/*105*/	u_int16_t       max_dsm_blocks;
214197540Smav/*106*/	u_int16_t       pss;
215197540Smav#define ATA_PSS_LSPPS			0x000F
216198865Smav#define ATA_PSS_LSSABOVE512		0x1000
217198865Smav#define ATA_PSS_MULTLS			0x2000
218263156Smav#define ATA_PSS_VALID_MASK		0xC000
219263156Smav#define ATA_PSS_VALID_VALUE		0x4000
220197540Smav/*107*/ u_int16_t       isd;
221197540Smav/*108*/ u_int16_t       wwn[4];
222197540Smav	u_int16_t       reserved112[5];
223197540Smav/*117*/ u_int16_t       lss_1;
224197540Smav/*118*/ u_int16_t       lss_2;
225197540Smav/*119*/ u_int16_t       support2;
226197540Smav#define ATA_SUPPORT_WRITEREADVERIFY	0x0002
227197540Smav#define ATA_SUPPORT_WRITEUNCORREXT	0x0004
228197540Smav#define ATA_SUPPORT_RWLOGDMAEXT		0x0008
229197540Smav#define ATA_SUPPORT_MICROCODE3		0x0010
230197540Smav#define ATA_SUPPORT_FREEFALL		0x0020
231197540Smav/*120*/ u_int16_t       enabled2;
232197540Smav	u_int16_t       reserved121[6];
233146266Ssos/*127*/ u_int16_t       removable_status;
234146266Ssos/*128*/ u_int16_t       security_status;
235249115Ssmh#define ATA_SECURITY_LEVEL		0x0100	/* 0: high, 1: maximum */
236249115Ssmh#define ATA_SECURITY_ENH_SUPP		0x0020	/* enhanced erase supported */
237249115Ssmh#define ATA_SECURITY_COUNT_EXP		0x0010	/* count expired */
238249115Ssmh#define ATA_SECURITY_FROZEN		0x0008	/* security config is frozen */
239249115Ssmh#define ATA_SECURITY_LOCKED		0x0004	/* drive is locked */
240249115Ssmh#define ATA_SECURITY_ENABLED		0x0002	/* ATA Security is enabled */
241249115Ssmh#define ATA_SECURITY_SUPPORTED		0x0001	/* ATA Security is supported */
242249115Ssmh
243146266Ssos	u_int16_t       reserved129[31];
244146266Ssos/*160*/ u_int16_t       cfa_powermode1;
245198587Smav	u_int16_t       reserved161;
246198587Smav/*162*/ u_int16_t       cfa_kms_support;
247198587Smav/*163*/ u_int16_t       cfa_trueide_modes;
248198587Smav/*164*/ u_int16_t       cfa_memory_modes;
249201139Smav	u_int16_t       reserved165[4];
250201139Smav/*169*/	u_int16_t       support_dsm;
251201139Smav#define ATA_SUPPORT_DSM_TRIM		0x0001
252201139Smav	u_int16_t       reserved170[6];
253197540Smav/*176*/ u_int8_t        media_serial[60];
254197540Smav/*206*/ u_int16_t       sct;
255197540Smav	u_int16_t       reserved206[2];
256198897Smav/*209*/ u_int16_t       lsalign;
257197540Smav/*210*/ u_int16_t       wrv_sectors_m3_1;
258197540Smav	u_int16_t       wrv_sectors_m3_2;
259197540Smav/*212*/ u_int16_t       wrv_sectors_m2_1;
260197540Smav	u_int16_t       wrv_sectors_m2_2;
261197540Smav/*214*/ u_int16_t       nv_cache_caps;
262197540Smav/*215*/ u_int16_t       nv_cache_size_1;
263197540Smav	u_int16_t       nv_cache_size_2;
264197540Smav/*217*/ u_int16_t       media_rotation_rate;
265271238Ssmh#define ATA_RATE_NOT_REPORTED		0x0000
266271238Ssmh#define ATA_RATE_NON_ROTATING		0x0001
267197540Smav	u_int16_t       reserved218;
268197540Smav/*219*/ u_int16_t       nv_cache_opt;
269197540Smav/*220*/ u_int16_t       wrv_mode;
270197540Smav	u_int16_t       reserved221;
271197540Smav/*222*/ u_int16_t       transport_major;
272197540Smav/*223*/ u_int16_t       transport_minor;
273197540Smav	u_int16_t       reserved224[31];
274146266Ssos/*255*/ u_int16_t       integrity;
275144330Ssos} __packed;
27674298Ssos
277249931Ssmh/* ATA Dataset Management */
278249931Ssmh#define ATA_DSM_BLK_SIZE	512
279249931Ssmh#define ATA_DSM_BLK_RANGES	64
280249931Ssmh#define ATA_DSM_RANGE_SIZE	8
281249931Ssmh#define ATA_DSM_RANGE_MAX	65535
282249931Ssmh
283238393Sbrueffer/*
284238393Sbrueffer * ATA Device Register
285238393Sbrueffer *
286238393Sbrueffer * bit 7 Obsolete (was 1 in early ATA specs)
287238393Sbrueffer * bit 6 Sets LBA/CHS mode. 1=LBA, 0=CHS
288238393Sbrueffer * bit 5 Obsolete (was 1 in early ATA specs)
289238393Sbrueffer * bit 4 1 = Slave Drive, 0 = Master Drive
290238393Sbrueffer * bit 3-0 In LBA mode, 27-24 of address. In CHS mode, head number
291238393Sbrueffer*/
292146266Ssos
293238393Sbrueffer#define ATA_DEV_MASTER		0x00
294238393Sbrueffer#define ATA_DEV_SLAVE		0x10
295238393Sbrueffer#define ATA_DEV_LBA		0x40
296238393Sbrueffer
297249895Ssmh/* ATA limits */
298249895Ssmh#define ATA_MAX_28BIT_LBA	268435455UL
299238393Sbrueffer
300249895Ssmh/* ATA Status Register */
301249895Ssmh#define ATA_STATUS_ERROR	0x01
302249895Ssmh#define ATA_STATUS_DEVICE_FAULT	0x20
303249895Ssmh
304249895Ssmh/* ATA Error Register */
305249895Ssmh#define ATA_ERROR_ABORT		0x04
306249895Ssmh#define ATA_ERROR_ID_NOT_FOUND	0x10
307249895Ssmh
308249895Ssmh/* ATA HPA Features */
309249895Ssmh#define ATA_HPA_FEAT_MAX_ADDR	0x00
310249895Ssmh#define ATA_HPA_FEAT_SET_PWD	0x01
311249895Ssmh#define ATA_HPA_FEAT_LOCK	0x02
312249895Ssmh#define ATA_HPA_FEAT_UNLOCK	0x03
313249895Ssmh#define ATA_HPA_FEAT_FREEZE	0x04
314249895Ssmh
315119404Ssos/* ATA transfer modes */
316146266Ssos#define ATA_MODE_MASK           0x0f
317146266Ssos#define ATA_DMA_MASK            0xf0
318146266Ssos#define ATA_PIO                 0x00
319146266Ssos#define ATA_PIO0                0x08
320146266Ssos#define ATA_PIO1                0x09
321146266Ssos#define ATA_PIO2                0x0a
322146266Ssos#define ATA_PIO3                0x0b
323146266Ssos#define ATA_PIO4                0x0c
324146266Ssos#define ATA_PIO_MAX             0x0f
325146266Ssos#define ATA_DMA                 0x10
326146266Ssos#define ATA_WDMA0               0x20
327146266Ssos#define ATA_WDMA1               0x21
328146266Ssos#define ATA_WDMA2               0x22
329146266Ssos#define ATA_UDMA0               0x40
330146266Ssos#define ATA_UDMA1               0x41
331146266Ssos#define ATA_UDMA2               0x42
332146266Ssos#define ATA_UDMA3               0x43
333146266Ssos#define ATA_UDMA4               0x44
334146266Ssos#define ATA_UDMA5               0x45
335146266Ssos#define ATA_UDMA6               0x46
336146266Ssos#define ATA_SA150               0x47
337148991Ssos#define ATA_SA300               0x48
338146266Ssos#define ATA_DMA_MAX             0x4f
33974298Ssos
340146266Ssos
341119404Ssos/* ATA commands */
342146266Ssos#define ATA_NOP                         0x00    /* NOP */
343146266Ssos#define         ATA_NF_FLUSHQUEUE       0x00    /* flush queued cmd's */
344146266Ssos#define         ATA_NF_AUTOPOLL         0x01    /* start autopoll function */
345201139Smav#define ATA_DATA_SET_MANAGEMENT		0x06
346201139Smav#define 	ATA_DSM_TRIM		0x01
347146266Ssos#define ATA_DEVICE_RESET                0x08    /* reset device */
348146266Ssos#define ATA_READ                        0x20    /* read */
349146266Ssos#define ATA_READ48                      0x24    /* read 48bit LBA */
350146266Ssos#define ATA_READ_DMA48                  0x25    /* read DMA 48bit LBA */
351146266Ssos#define ATA_READ_DMA_QUEUED48           0x26    /* read DMA QUEUED 48bit LBA */
352178067Ssos#define ATA_READ_NATIVE_MAX_ADDRESS48   0x27    /* read native max addr 48bit */
353146266Ssos#define ATA_READ_MUL48                  0x29    /* read multi 48bit LBA */
354200008Smav#define ATA_READ_STREAM_DMA48           0x2a    /* read DMA stream 48bit LBA */
355265659Ssmh#define ATA_READ_LOG_EXT                0x2f    /* read log ext - PIO Data-In */
356200008Smav#define ATA_READ_STREAM48               0x2b    /* read stream 48bit LBA */
357146266Ssos#define ATA_WRITE                       0x30    /* write */
358146266Ssos#define ATA_WRITE48                     0x34    /* write 48bit LBA */
359146266Ssos#define ATA_WRITE_DMA48                 0x35    /* write DMA 48bit LBA */
360146266Ssos#define ATA_WRITE_DMA_QUEUED48          0x36    /* write DMA QUEUED 48bit LBA*/
361152270Ssos#define ATA_SET_MAX_ADDRESS48           0x37    /* set max address 48bit */
362146266Ssos#define ATA_WRITE_MUL48                 0x39    /* write multi 48bit LBA */
363200008Smav#define ATA_WRITE_STREAM_DMA48          0x3a
364200008Smav#define ATA_WRITE_STREAM48              0x3b
365200008Smav#define ATA_WRITE_DMA_FUA48             0x3d
366200008Smav#define ATA_WRITE_DMA_QUEUED_FUA48      0x3e
367200008Smav#define ATA_WRITE_LOG_EXT               0x3f
368200008Smav#define ATA_READ_VERIFY                 0x40
369200008Smav#define ATA_READ_VERIFY48               0x42
370265659Ssmh#define ATA_READ_LOG_DMA_EXT            0x47    /* read log DMA ext - PIO Data-In */
371146266Ssos#define ATA_READ_FPDMA_QUEUED           0x60    /* read DMA NCQ */
372146266Ssos#define ATA_WRITE_FPDMA_QUEUED          0x61    /* write DMA NCQ */
373265659Ssmh#define ATA_SEND_FPDMA_QUEUED           0x64    /* send DMA NCQ */
374265659Ssmh#define ATA_RECV_FPDMA_QUEUED           0x65    /* recieve DMA NCQ */
375235897Smav#define ATA_SEP_ATTN                    0x67    /* SEP request */
376146266Ssos#define ATA_SEEK                        0x70    /* seek */
377146266Ssos#define ATA_PACKET_CMD                  0xa0    /* packet command */
378146266Ssos#define ATA_ATAPI_IDENTIFY              0xa1    /* get ATAPI params*/
379146266Ssos#define ATA_SERVICE                     0xa2    /* service command */
380166287Sremko#define ATA_SMART_CMD                   0xb0    /* SMART command */
381146266Ssos#define ATA_CFA_ERASE                   0xc0    /* CFA erase */
382146266Ssos#define ATA_READ_MUL                    0xc4    /* read multi */
383146266Ssos#define ATA_WRITE_MUL                   0xc5    /* write multi */
384146266Ssos#define ATA_SET_MULTI                   0xc6    /* set multi size */
385146266Ssos#define ATA_READ_DMA_QUEUED             0xc7    /* read DMA QUEUED */
386146266Ssos#define ATA_READ_DMA                    0xc8    /* read DMA */
387146266Ssos#define ATA_WRITE_DMA                   0xca    /* write DMA */
388146266Ssos#define ATA_WRITE_DMA_QUEUED            0xcc    /* write DMA QUEUED */
389200008Smav#define ATA_WRITE_MUL_FUA48             0xce
390146266Ssos#define ATA_STANDBY_IMMEDIATE           0xe0    /* standby immediate */
391146266Ssos#define ATA_IDLE_IMMEDIATE              0xe1    /* idle immediate */
392146266Ssos#define ATA_STANDBY_CMD                 0xe2    /* standby */
393146266Ssos#define ATA_IDLE_CMD                    0xe3    /* idle */
394146266Ssos#define ATA_READ_BUFFER                 0xe4    /* read buffer */
395178067Ssos#define ATA_READ_PM                     0xe4    /* read portmultiplier */
396146266Ssos#define ATA_SLEEP                       0xe6    /* sleep */
397146266Ssos#define ATA_FLUSHCACHE                  0xe7    /* flush cache to disk */
398178067Ssos#define ATA_WRITE_PM                    0xe8    /* write portmultiplier */
399146266Ssos#define ATA_FLUSHCACHE48                0xea    /* flush cache to disk */
400146266Ssos#define ATA_ATA_IDENTIFY                0xec    /* get ATA params */
401146266Ssos#define ATA_SETFEATURES                 0xef    /* features command */
402146266Ssos#define         ATA_SF_SETXFER          0x03    /* set transfer mode */
403146266Ssos#define         ATA_SF_ENAB_WCACHE      0x02    /* enable write cache */
404146266Ssos#define         ATA_SF_DIS_WCACHE       0x82    /* disable write cache */
405203421Smav#define         ATA_SF_ENAB_PUIS        0x06    /* enable PUIS */
406203421Smav#define         ATA_SF_DIS_PUIS         0x86    /* disable PUIS */
407203421Smav#define         ATA_SF_PUIS_SPINUP      0x07    /* PUIS spin-up */
408146266Ssos#define         ATA_SF_ENAB_RCACHE      0xaa    /* enable readahead cache */
409146266Ssos#define         ATA_SF_DIS_RCACHE       0x55    /* disable readahead cache */
410146266Ssos#define         ATA_SF_ENAB_RELIRQ      0x5d    /* enable release interrupt */
411146266Ssos#define         ATA_SF_DIS_RELIRQ       0xdd    /* disable release interrupt */
412146266Ssos#define         ATA_SF_ENAB_SRVIRQ      0x5e    /* enable service interrupt */
413146266Ssos#define         ATA_SF_DIS_SRVIRQ       0xde    /* disable service interrupt */
414249115Ssmh#define ATA_SECURITY_SET_PASSWORD       0xf1    /* set drive password */
415249115Ssmh#define ATA_SECURITY_UNLOCK             0xf2    /* unlock drive using passwd */
416249115Ssmh#define ATA_SECURITY_ERASE_PREPARE      0xf3    /* prepare to erase drive */
417249115Ssmh#define ATA_SECURITY_ERASE_UNIT         0xf4    /* erase all blocks on drive */
418249115Ssmh#define ATA_SECURITY_FREEZE_LOCK        0xf5    /* freeze security config */
419249115Ssmh#define ATA_SECURITY_DISABLE_PASSWORD   0xf6    /* disable drive password */
420178067Ssos#define ATA_READ_NATIVE_MAX_ADDRESS     0xf8    /* read native max address */
421146266Ssos#define ATA_SET_MAX_ADDRESS             0xf9    /* set max address */
422119404Ssos
423146266Ssos
424119404Ssos/* ATAPI commands */
425146266Ssos#define ATAPI_TEST_UNIT_READY           0x00    /* check if device is ready */
426146266Ssos#define ATAPI_REZERO                    0x01    /* rewind */
427146266Ssos#define ATAPI_REQUEST_SENSE             0x03    /* get sense data */
428146266Ssos#define ATAPI_FORMAT                    0x04    /* format unit */
429146266Ssos#define ATAPI_READ                      0x08    /* read data */
430146266Ssos#define ATAPI_WRITE                     0x0a    /* write data */
431146266Ssos#define ATAPI_WEOF                      0x10    /* write filemark */
432146266Ssos#define         ATAPI_WF_WRITE          0x01
433146266Ssos#define ATAPI_SPACE                     0x11    /* space command */
434146266Ssos#define         ATAPI_SP_FM             0x01
435146266Ssos#define         ATAPI_SP_EOD            0x03
436156317Ssos#define ATAPI_INQUIRY			0x12	/* get inquiry data */
437146266Ssos#define ATAPI_MODE_SELECT               0x15    /* mode select */
438146266Ssos#define ATAPI_ERASE                     0x19    /* erase */
439146266Ssos#define ATAPI_MODE_SENSE                0x1a    /* mode sense */
440146266Ssos#define ATAPI_START_STOP                0x1b    /* start/stop unit */
441146266Ssos#define         ATAPI_SS_LOAD           0x01
442146266Ssos#define         ATAPI_SS_RETENSION      0x02
443146266Ssos#define         ATAPI_SS_EJECT          0x04
444146266Ssos#define ATAPI_PREVENT_ALLOW             0x1e    /* media removal */
445146266Ssos#define ATAPI_READ_FORMAT_CAPACITIES    0x23    /* get format capacities */
446146266Ssos#define ATAPI_READ_CAPACITY             0x25    /* get volume capacity */
447146266Ssos#define ATAPI_READ_BIG                  0x28    /* read data */
448146266Ssos#define ATAPI_WRITE_BIG                 0x2a    /* write data */
449146266Ssos#define ATAPI_LOCATE                    0x2b    /* locate to position */
450146266Ssos#define ATAPI_READ_POSITION             0x34    /* read position */
451146266Ssos#define ATAPI_SYNCHRONIZE_CACHE         0x35    /* flush buf, close channel */
452146266Ssos#define ATAPI_WRITE_BUFFER              0x3b    /* write device buffer */
453146266Ssos#define ATAPI_READ_BUFFER               0x3c    /* read device buffer */
454146266Ssos#define ATAPI_READ_SUBCHANNEL           0x42    /* get subchannel info */
455146266Ssos#define ATAPI_READ_TOC                  0x43    /* get table of contents */
456146266Ssos#define ATAPI_PLAY_10                   0x45    /* play by lba */
457146266Ssos#define ATAPI_PLAY_MSF                  0x47    /* play by MSF address */
458146266Ssos#define ATAPI_PLAY_TRACK                0x48    /* play by track number */
459146266Ssos#define ATAPI_PAUSE                     0x4b    /* pause audio operation */
460146266Ssos#define ATAPI_READ_DISK_INFO            0x51    /* get disk info structure */
461146266Ssos#define ATAPI_READ_TRACK_INFO           0x52    /* get track info structure */
462146266Ssos#define ATAPI_RESERVE_TRACK             0x53    /* reserve track */
463146266Ssos#define ATAPI_SEND_OPC_INFO             0x54    /* send OPC structurek */
464146266Ssos#define ATAPI_MODE_SELECT_BIG           0x55    /* set device parameters */
465146266Ssos#define ATAPI_REPAIR_TRACK              0x58    /* repair track */
466146266Ssos#define ATAPI_READ_MASTER_CUE           0x59    /* read master CUE info */
467146266Ssos#define ATAPI_MODE_SENSE_BIG            0x5a    /* get device parameters */
468146266Ssos#define ATAPI_CLOSE_TRACK               0x5b    /* close track/session */
469146266Ssos#define ATAPI_READ_BUFFER_CAPACITY      0x5c    /* get buffer capicity */
470146266Ssos#define ATAPI_SEND_CUE_SHEET            0x5d    /* send CUE sheet */
471156317Ssos#define ATAPI_SERVICE_ACTION_IN         0x96	/* get service data */
472146266Ssos#define ATAPI_BLANK                     0xa1    /* blank the media */
473146266Ssos#define ATAPI_SEND_KEY                  0xa3    /* send DVD key structure */
474146266Ssos#define ATAPI_REPORT_KEY                0xa4    /* get DVD key structure */
475146266Ssos#define ATAPI_PLAY_12                   0xa5    /* play by lba */
476146266Ssos#define ATAPI_LOAD_UNLOAD               0xa6    /* changer control command */
477146266Ssos#define ATAPI_READ_STRUCTURE            0xad    /* get DVD structure */
478146266Ssos#define ATAPI_PLAY_CD                   0xb4    /* universal play command */
479146266Ssos#define ATAPI_SET_SPEED                 0xbb    /* set drive speed */
480146266Ssos#define ATAPI_MECH_STATUS               0xbd    /* get changer status */
481146266Ssos#define ATAPI_READ_CD                   0xbe    /* read data */
482146266Ssos#define ATAPI_POLL_DSC                  0xff    /* poll DSC status bit */
483119404Ssos
48474298Ssos
485146266Ssosstruct ata_ioc_devices {
486146266Ssos    int                 channel;
487146266Ssos    char                name[2][32];
488146266Ssos    struct ata_params   params[2];
489146266Ssos};
490119404Ssos
491146266Ssos/* pr channel ATA ioctl calls */
492146266Ssos#define IOCATAGMAXCHANNEL       _IOR('a',  1, int)
493146266Ssos#define IOCATAREINIT            _IOW('a',  2, int)
494146266Ssos#define IOCATAATTACH            _IOW('a',  3, int)
495146266Ssos#define IOCATADETACH            _IOW('a',  4, int)
496146266Ssos#define IOCATADEVICES           _IOWR('a',  5, struct ata_ioc_devices)
497119404Ssos
498157329Ssos/* ATAPI request sense structure */
499157329Ssosstruct atapi_sense {
500157329Ssos    u_int8_t	error;				/* current or deferred errors */
501157329Ssos#define	ATA_SENSE_VALID			0x80
502157329Ssos
503157329Ssos    u_int8_t	segment;			/* segment number */
504157329Ssos    u_int8_t	key;				/* sense key */
505157329Ssos#define ATA_SENSE_KEY_MASK		0x0f    /* sense key mask */
506157329Ssos#define ATA_SENSE_NO_SENSE		0x00    /* no specific sense key info */
507157329Ssos#define ATA_SENSE_RECOVERED_ERROR 	0x01    /* command OK, data recovered */
508157329Ssos#define ATA_SENSE_NOT_READY		0x02    /* no access to drive */
509157329Ssos#define ATA_SENSE_MEDIUM_ERROR		0x03    /* non-recovered data error */
510157329Ssos#define ATA_SENSE_HARDWARE_ERROR	0x04    /* non-recoverable HW failure */
511157329Ssos#define ATA_SENSE_ILLEGAL_REQUEST	0x05    /* invalid command param(s) */
512157329Ssos#define ATA_SENSE_UNIT_ATTENTION	0x06    /* media changed */
513157329Ssos#define ATA_SENSE_DATA_PROTECT		0x07    /* write protect */
514157329Ssos#define ATA_SENSE_BLANK_CHECK		0x08    /* blank check */
515157329Ssos#define ATA_SENSE_VENDOR_SPECIFIC	0x09    /* vendor specific skey */
516157329Ssos#define ATA_SENSE_COPY_ABORTED		0x0a    /* copy aborted */
517157329Ssos#define ATA_SENSE_ABORTED_COMMAND	0x0b    /* command aborted, try again */
518157329Ssos#define ATA_SENSE_EQUAL			0x0c    /* equal */
519157329Ssos#define ATA_SENSE_VOLUME_OVERFLOW	0x0d    /* volume overflow */
520157329Ssos#define ATA_SENSE_MISCOMPARE		0x0e    /* data dont match the medium */
521157329Ssos#define ATA_SENSE_RESERVED		0x0f
522157329Ssos#define	ATA_SENSE_ILI			0x20;
523157329Ssos#define	ATA_SENSE_EOM			0x40;
524157329Ssos#define	ATA_SENSE_FILEMARK		0x80;
525157329Ssos
526157329Ssos    u_int32_t   cmd_info;		/* cmd information */
527157329Ssos    u_int8_t	sense_length;		/* additional sense len (n-7) */
528157329Ssos    u_int32_t   cmd_specific_info;	/* additional cmd spec info */
529157329Ssos    u_int8_t    asc;			/* additional sense code */
530157329Ssos    u_int8_t    ascq;			/* additional sense code qual */
531157329Ssos    u_int8_t    replaceable_unit_code;	/* replaceable unit code */
532157329Ssos    u_int8_t	specific;		/* sense key specific */
533157329Ssos#define	ATA_SENSE_SPEC_VALID	0x80
534157329Ssos#define	ATA_SENSE_SPEC_MASK	0x7f
535157329Ssos
536157329Ssos    u_int8_t	specific1;		/* sense key specific */
537157329Ssos    u_int8_t	specific2;		/* sense key specific */
538157329Ssos} __packed;
539157329Ssos
540146266Ssosstruct ata_ioc_request {
541146266Ssos    union {
542119404Ssos	struct {
543146266Ssos	    u_int8_t            command;
544146266Ssos	    u_int8_t            feature;
545146266Ssos	    u_int64_t           lba;
546146266Ssos	    u_int16_t           count;
547146266Ssos	} ata;
548119404Ssos	struct {
549146266Ssos	    char                ccb[16];
550157329Ssos	    struct atapi_sense	sense;
551146266Ssos	} atapi;
552146266Ssos    } u;
553146266Ssos    caddr_t             data;
554146266Ssos    int                 count;
555146266Ssos    int                 flags;
556146266Ssos#define ATA_CMD_CONTROL                 0x01
557146266Ssos#define ATA_CMD_READ                    0x02
558146266Ssos#define ATA_CMD_WRITE                   0x04
559146266Ssos#define ATA_CMD_ATAPI                   0x08
560119404Ssos
561146266Ssos    int                 timeout;
562146266Ssos    int                 error;
563146266Ssos};
564119404Ssos
565249115Ssmhstruct ata_security_password {
566249115Ssmh	u_int16_t		ctrl;
567249115Ssmh#define ATA_SECURITY_PASSWORD_USER	0x0000
568249115Ssmh#define ATA_SECURITY_PASSWORD_MASTER	0x0001
569249115Ssmh#define ATA_SECURITY_ERASE_NORMAL	0x0000
570249115Ssmh#define ATA_SECURITY_ERASE_ENHANCED	0x0002
571249115Ssmh#define ATA_SECURITY_LEVEL_HIGH		0x0000
572249115Ssmh#define ATA_SECURITY_LEVEL_MAXIMUM	0x0100
573249115Ssmh
574249115Ssmh	u_int8_t		password[32];
575249115Ssmh	u_int16_t		revision;
576249115Ssmh	u_int16_t		reserved[238];
577249115Ssmh};
578249115Ssmh
579146266Ssos/* pr device ATA ioctl calls */
580146266Ssos#define IOCATAREQUEST           _IOWR('a', 100, struct ata_ioc_request)
581146266Ssos#define IOCATAGPARM             _IOR('a', 101, struct ata_params)
582146266Ssos#define IOCATAGMODE             _IOR('a', 102, int)
583146266Ssos#define IOCATASMODE             _IOW('a', 103, int)
58493662Ssos
585177298Sphk#define IOCATAGSPINDOWN		_IOR('a', 104, int)
586177298Sphk#define IOCATASSPINDOWN		_IOW('a', 105, int)
587119404Ssos
588177298Sphk
589146266Ssosstruct ata_ioc_raid_config {
590146266Ssos	    int                 lun;
591146266Ssos	    int                 type;
592146266Ssos#define AR_JBOD                         0x0001
593146266Ssos#define AR_SPAN                         0x0002
594146266Ssos#define AR_RAID0                        0x0004
595146266Ssos#define AR_RAID1                        0x0008
596146266Ssos#define AR_RAID01                       0x0010
597146266Ssos#define AR_RAID3                        0x0020
598146266Ssos#define AR_RAID4                        0x0040
599146266Ssos#define AR_RAID5                        0x0080
60093662Ssos
601146266Ssos	    int                 interleave;
602146266Ssos	    int                 status;
603146266Ssos#define AR_READY                        1
604146266Ssos#define AR_DEGRADED                     2
605146266Ssos#define AR_REBUILDING                   4
606119404Ssos
607146266Ssos	    int                 progress;
608146266Ssos	    int                 total_disks;
609146266Ssos	    int                 disks[16];
61074298Ssos};
61174298Ssos
612171819Sjhbstruct ata_ioc_raid_status {
613171819Sjhb	    int                 lun;
614171819Sjhb	    int                 type;
615171819Sjhb	    int                 interleave;
616171819Sjhb	    int                 status;
617171819Sjhb	    int                 progress;
618171819Sjhb	    int                 total_disks;
619171819Sjhb	    struct {
620171819Sjhb		    int		state;
621171819Sjhb#define AR_DISK_ONLINE			0x01
622171819Sjhb#define AR_DISK_PRESENT			0x02
623171819Sjhb#define AR_DISK_SPARE			0x04
624171819Sjhb		    int		lun;
625171819Sjhb	    } disks[16];
626171819Sjhb};
627171819Sjhb
628146266Ssos/* ATA RAID ioctl calls */
629148737Ssos#define IOCATARAIDCREATE        _IOWR('a', 200, struct ata_ioc_raid_config)
630146266Ssos#define IOCATARAIDDELETE        _IOW('a', 201, int)
631171819Sjhb#define IOCATARAIDSTATUS        _IOWR('a', 202, struct ata_ioc_raid_status)
632146266Ssos#define IOCATARAIDADDSPARE      _IOW('a', 203, struct ata_ioc_raid_config)
633146266Ssos#define IOCATARAIDREBUILD       _IOW('a', 204, int)
63474298Ssos
63574298Ssos#endif /* _SYS_ATA_H_ */
636