2 * Copyright (c) 2007 David Gwynne <dlg@openbsd.org>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 * $OpenBSD: atascsi.h,v 1.33 2009/02/16 21:19:06 miod Exp $
26 #define ATA_C_READDMA_EXT 0x25
27 #define ATA_C_READ_LOG_EXT 0x2f
28 #define ATA_C_WRITEDMA_EXT 0x35
29 #define ATA_C_READ_FPDMA 0x60
30 #define ATA_C_WRITE_FPDMA 0x61
31 #define ATA_C_PACKET 0xa0
32 #define ATA_C_READDMA 0xc8
33 #define ATA_C_WRITEDMA 0xca
34 #define ATA_C_FLUSH_CACHE 0xe7
35 #define ATA_C_FLUSH_CACHE_EXT 0xea /* lba48 */
36 #define ATA_C_IDENTIFY 0xec
37 #define ATA_C_SET_FEATURES 0xef
38 #define ATA_C_SEC_FREEZE_LOCK 0xf5
41 * ATA SET FEATURES subcommands
43 #define ATA_SF_WRITECACHE_EN 0x02
44 #define ATA_SF_LOOKAHEAD_EN 0xaa
47 u_int16_t config; /* 0 */
48 u_int16_t ncyls; /* 1 */
49 u_int16_t reserved1; /* 2 */
50 u_int16_t nheads; /* 3 */
51 u_int16_t track_size; /* 4 */
52 u_int16_t sector_size; /* 5 */
53 u_int16_t nsectors; /* 6 */
54 u_int16_t reserved2[3]; /* 7 vendor unique */
55 u_int8_t serial[20]; /* 10 */
56 u_int16_t buffer_type; /* 20 */
57 u_int16_t buffer_size; /* 21 */
58 u_int16_t ecc; /* 22 */
59 u_int8_t firmware[8]; /* 23 */
60 u_int8_t model[40]; /* 27 */
61 u_int16_t multi; /* 47 */
62 u_int16_t dwcap; /* 48 */
63 u_int16_t cap; /* 49 */
64 u_int16_t reserved3; /* 50 */
65 u_int16_t piomode; /* 51 */
66 u_int16_t dmamode; /* 52 */
67 u_int16_t validinfo; /* 53 */
68 u_int16_t curcyls; /* 54 */
69 u_int16_t curheads; /* 55 */
70 u_int16_t cursectrk; /* 56 */
71 u_int16_t curseccp[2]; /* 57 */
72 u_int16_t mult2; /* 59 */
73 u_int16_t addrsec[2]; /* 60 */
74 u_int16_t worddma; /* 62 */
75 u_int16_t dworddma; /* 63 */
76 u_int16_t advpiomode; /* 64 */
77 u_int16_t minmwdma; /* 65 */
78 u_int16_t recmwdma; /* 66 */
79 u_int16_t minpio; /* 67 */
80 u_int16_t minpioflow; /* 68 */
81 u_int16_t reserved4[2]; /* 69 */
82 u_int16_t typtime[2]; /* 71 */
83 u_int16_t reserved5[2]; /* 73 */
84 u_int16_t qdepth; /* 75 */
85 u_int16_t satacap; /* 76 */
86 u_int16_t reserved6; /* 77 */
87 u_int16_t satafsup; /* 78 */
88 u_int16_t satafen; /* 79 */
89 u_int16_t majver; /* 80 */
90 u_int16_t minver; /* 81 */
91 u_int16_t cmdset82; /* 82 */
92 u_int16_t cmdset83; /* 83 */
93 u_int16_t cmdset84; /* 84 */
94 u_int16_t features85; /* 85 */
95 u_int16_t features86; /* 86 */
96 u_int16_t features87; /* 87 */
97 #define ATA_ID_F87_WWN (1<<8)
98 u_int16_t ultradma; /* 88 */
99 u_int16_t erasetime; /* 89 */
100 u_int16_t erasetimex; /* 90 */
101 u_int16_t apm; /* 91 */
102 u_int16_t masterpw; /* 92 */
103 u_int16_t hwreset; /* 93 */
104 u_int16_t acoustic; /* 94 */
105 u_int16_t stream_min; /* 95 */
106 u_int16_t stream_xfer_d; /* 96 */
107 u_int16_t stream_lat; /* 97 */
108 u_int16_t streamperf[2]; /* 98 */
109 u_int16_t addrsecxt[4]; /* 100 */
110 u_int16_t stream_xfer_p; /* 104 */
111 u_int16_t padding1; /* 105 */
112 u_int16_t phys_sect_sz; /* 106 */
113 u_int16_t seek_delay; /* 107 */
114 u_int16_t naa_ieee_oui; /* 108 */
115 u_int16_t ieee_oui_uid; /* 109 */
116 u_int16_t uid_mid; /* 110 */
117 u_int16_t uid_low; /* 111 */
118 u_int16_t resv_wwn[4]; /* 112 */
119 u_int16_t incits; /* 116 */
120 u_int16_t words_lsec[2]; /* 117 */
121 u_int16_t cmdset119; /* 119 */
122 u_int16_t features120; /* 120 */
123 u_int16_t padding2[6];
124 u_int16_t rmsn; /* 127 */
125 u_int16_t securestatus; /* 128 */
126 u_int16_t vendor[31]; /* 129 */
127 u_int16_t padding3[16]; /* 160 */
128 u_int16_t curmedser[30]; /* 176 */
129 u_int16_t sctsupport; /* 206 */
130 u_int16_t padding4[48]; /* 207 */
131 u_int16_t integrity; /* 255 */
135 * IDENTIFY DEVICE data
137 #define ATA_IDENTIFY_WRITECACHE (1 << 5)
138 #define ATA_IDENTIFY_LOOKAHEAD (1 << 6)
141 * Frame Information Structures
144 #define ATA_FIS_LENGTH 20
148 #define ATA_FIS_TYPE_H2D 0x27
150 #define ATA_H2D_FLAGS_CMD (1<<7)
153 #define ATA_H2D_FEATURES_DMA (1<<0)
154 #define ATA_H2D_FEATURES_DIR (1<<2)
155 #define ATA_H2D_FEATURES_DIR_READ (1<<2)
156 #define ATA_H2D_FEATURES_DIR_WRITE (0<<2)
162 #define ATA_H2D_DEVICE_LBA 0x40
164 u_int8_t lba_low_exp;
165 u_int8_t lba_mid_exp;
166 u_int8_t lba_high_exp;
167 u_int8_t features_exp;
169 u_int8_t sector_count;
170 u_int8_t sector_count_exp;
182 #define ATA_FIS_TYPE_D2H 0x34
184 #define ATA_D2H_FLAGS_INTR (1<<6)
193 u_int8_t lba_low_exp;
194 u_int8_t lba_mid_exp;
195 u_int8_t lba_high_exp;
198 u_int8_t sector_count;
199 u_int8_t sector_count_exp;
210 * SATA log page 10h -
211 * looks like a D2H FIS, with errored tag number in first byte.
213 struct ata_log_page_10h {
214 struct ata_fis_d2h err_regs;
215 #define ATA_LOG_10H_TYPE_NOTQUEUED 0x80
216 #define ATA_LOG_10H_TYPE_TAG_MASK 0x1f
217 u_int8_t reserved[256 - sizeof(struct ata_fis_d2h)];
218 u_int8_t vendor_specific[255];
226 #define SATA_SStatus_DET 0x00f
227 #define SATA_SStatus_DET_NODEV 0x000
228 #define SATA_SStatus_DET_NOPHY 0x001
229 #define SATA_SStatus_DET_DEV 0x003
230 #define SATA_SStatus_DET_OFFLINE 0x008
232 #define SATA_SStatus_SPD 0x0f0
233 #define SATA_SStatus_SPD_NONE 0x000
234 #define SATA_SStatus_SPD_1_5 0x010
235 #define SATA_SStatus_SPD_3_0 0x020
237 #define SATA_SStatus_IPM 0xf00
238 #define SATA_SStatus_IPM_NODEV 0x000
239 #define SATA_SStatus_IPM_ACTIVE 0x100
240 #define SATA_SStatus_IPM_PARTIAL 0x200
241 #define SATA_SStatus_IPM_SLUMBER 0x600
243 #define SATA_SIGNATURE_PORT_MULTIPLIER 0x96690101
244 #define SATA_SIGNATURE_ATAPI 0xeb140101
245 #define SATA_SIGNATURE_DISK 0x00000101
252 struct ata_identify ap_identify; /* only if ATA_PORT_T_DISK */
253 struct atascsi *ap_as;
255 #define ATA_PORT_T_NONE 0
256 #define ATA_PORT_T_DISK 1
257 #define ATA_PORT_T_ATAPI 2
259 #define ATA_PORT_F_PROBED (1 << 0)
260 #define ATA_PORT_F_WCACHE (1 << 1)
261 #define ATA_PORT_F_RAHEAD (1 << 2)
262 #define ATA_PORT_F_FRZLCK (1 << 3)
264 u_int64_t ap_capacity; /* only if ATA_PORT_T_DISK */
268 struct ata_fis_h2d *fis;
269 struct ata_fis_d2h rfis;
277 void (*complete)(struct ata_xfer *);
281 #define ATA_F_READ (1<<0)
282 #define ATA_F_WRITE (1<<1)
283 #define ATA_F_NOWAIT (1<<2)
284 #define ATA_F_POLL (1<<3)
285 #define ATA_F_PIO (1<<4)
286 #define ATA_F_PACKET (1<<5)
287 #define ATA_F_NCQ (1<<6)
288 #define ATA_F_TIMEOUT_RUNNING (1<<7)
289 #define ATA_FMT_FLAGS "\020" "\010TRUNNING" \
290 "\007NCQ" "\006PACKET" \
291 "\005PIO" "\004POLL" "\003NOWAIT" \
292 "\002WRITE" "\001READ"
295 #define ATA_S_SETUP 0
296 #define ATA_S_PENDING 1
297 #define ATA_S_COMPLETE 2
298 #define ATA_S_ERROR 3
299 #define ATA_S_TIMEOUT 4
300 #define ATA_S_ONCHIP 5
303 void *atascsi_private;
305 void (*ata_put_xfer)(struct ata_xfer *);
309 #define ATA_COMPLETE 1