1 | /******************************************************************************
|
---|
2 | * atapi.h - ATAPI structures and macros for os2ahci driver
|
---|
3 | *
|
---|
4 | * Copyright (c) 2011 thi.guten Software Development
|
---|
5 | * Copyright (c) 2011 Mensys B.V.
|
---|
6 | *
|
---|
7 | * Authors: Christian Mueller, Markus Thielen
|
---|
8 | *
|
---|
9 | * Parts copied from/inspired by the Linux AHCI driver;
|
---|
10 | * those parts are (c) Linux AHCI/ATA maintainers
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or modify
|
---|
13 | * it under the terms of the GNU General Public License as published by
|
---|
14 | * the Free Software Foundation; either version 2 of the License, or
|
---|
15 | * (at your option) any later version.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful,
|
---|
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
20 | * GNU General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, write to the Free Software
|
---|
24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
25 | */
|
---|
26 |
|
---|
27 | /* -------------------------- macros and constants ------------------------- */
|
---|
28 |
|
---|
29 | #define ATAPI_MIN_CDB_LEN 12 /* minimum ATAPI CDB len acc to AHCI spec */
|
---|
30 | #define ATAPI_MAX_CDB_LEN 16
|
---|
31 |
|
---|
32 | /******************************************************************************
|
---|
33 | * macros to fill in ATAPI CDB values
|
---|
34 | */
|
---|
35 | #define SET_CDB_16(_t, _v) (_t)[0] = (u8) ((_v) >> 8); \
|
---|
36 | (_t)[1] = (u8) (_v)
|
---|
37 | #define SET_CDB_24(_t, _v) (_t)[0] = (u8) ((_v) >> 16); \
|
---|
38 | (_t)[1] = (u8) ((_v) >> 8); \
|
---|
39 | (_t)[2] = (u8) (_v)
|
---|
40 | #define SET_CDB_32(_t, _v) (_t)[0] = (u8) ((_v) >> 24); \
|
---|
41 | (_t)[1] = (u8) ((_v) >> 16); \
|
---|
42 | (_t)[2] = (u8) ((_v) >> 8); \
|
---|
43 | (_t)[3] = (u8) (_v)
|
---|
44 |
|
---|
45 | #define GET_CDB_16(_f) ((u16) (_f)[0] << 8 | \
|
---|
46 | (u16) (_f)[1])
|
---|
47 | #define GET_CDB_24(_f) ((u32) (_f)[0] << 16 | \
|
---|
48 | (u32) (_f)[1] << 8 | \
|
---|
49 | (u32) (_f)[2])
|
---|
50 | #define GET_CDB_32(_f) ((u32) (_f)[0] << 24 | \
|
---|
51 | (u32) (_f)[1] << 16 | \
|
---|
52 | (u32) (_f)[2] << 24 | \
|
---|
53 | (u32) (_f)[3])
|
---|
54 |
|
---|
55 |
|
---|
56 | /******************************************************************************
|
---|
57 | * ATAPI/MMC command codes (as far as relevant for us)
|
---|
58 | */
|
---|
59 | #define ATAPI_CMD_READ_6 0x08
|
---|
60 | #define ATAPI_CMD_READ_10 0x28
|
---|
61 | #define ATAPI_CMD_READ_12 0xa8
|
---|
62 | #define ATAPI_CMD_READ_16 0x88
|
---|
63 | #define ATAPI_CMD_WRITE_6 0x0a
|
---|
64 | #define ATAPI_CMD_WRITE_10 0x2a
|
---|
65 | #define ATAPI_CMD_WRITE_12 0xaa
|
---|
66 | #define ATAPI_CMD_WRITE_16 0x8a
|
---|
67 | #define ATAPI_CMD_REQUEST_SENSE 0x03
|
---|
68 |
|
---|
69 | /******************************************************************************
|
---|
70 | * ATAPI command flag bits
|
---|
71 | */
|
---|
72 | #define ATAPI_FLAG_FUA 0x80
|
---|
73 | #define ATAPI_FLAG_DPO 0x10
|
---|
74 |
|
---|
75 | #define ATAPI_FEAT_DMA 0x0001
|
---|
76 | #define ATAPI_FEAT_DMA_TO_HOST 0x0004
|
---|
77 |
|
---|
78 | /******************************************************************************
|
---|
79 | * ATAPI sense data
|
---|
80 | */
|
---|
81 | #define ATAPI_SENSE_LEN 96
|
---|
82 |
|
---|
83 | #define ASENSE_NO_SENSE 0x00 /* no sense -> success */
|
---|
84 | #define ASENSE_RECOVERED_ERROR 0x01 /* recovered error -> success */
|
---|
85 | #define ASENSE_NOT_READY 0x02 /* device not ready */
|
---|
86 | #define ASENSE_MEDIUM_ERROR 0x03 /* medium/CRC error */
|
---|
87 | #define ASENSE_HARDWARE_ERROR 0x04 /* device error */
|
---|
88 | #define ASENSE_ILLEGAL_REQUEST 0x05 /* invalid command/parameters issued */
|
---|
89 | #define ASENSE_UNIT_ATTENTION 0x06 /* new medium */
|
---|
90 | #define ASENSE_DATA_PROTECT 0x07 /* protected LBA */
|
---|
91 | #define ASENSE_BLANK_CHECK 0x08 /* unformatted or write protected */
|
---|
92 | #define ASENSE_VENDOR_SPECIFIC 0x09 /* vendor specific sense data */
|
---|
93 | #define ASENSE_COPY_ABORTED 0x0a /* copy, ...command aborted */
|
---|
94 | #define ASENSE_ABORTED_COMMAND 0x0b /* command has been aborted */
|
---|
95 | #define ASENSE_EQUAL 0x0c
|
---|
96 | #define ASENSE_VOLUME_OVERFLOW 0x0d /* out of space */
|
---|
97 | #define ASENSE_MISCOMPARE 0x0e /* verification failed */
|
---|
98 | #define ASENSE_RESERVED 0x0f
|
---|
99 |
|
---|
100 | /******************************************************************************
|
---|
101 | * macro to get sense key from ATAPI_SENSE_DATA pointer
|
---|
102 | */
|
---|
103 | #define ATAPI_GET_SENSE(p_) (u8)(p_->sense.sense_key & 0x0f)
|
---|
104 |
|
---|
105 | /* ------------------------ typedefs and structures ------------------------ */
|
---|
106 |
|
---|
107 | /******************************************************************************
|
---|
108 | * ATAPI_SENSE_DATA - define layout of ATAPI sense data
|
---|
109 | */
|
---|
110 | typedef union _ATAPI_SENSE_DATA {
|
---|
111 | struct {
|
---|
112 | u8 valid_respc; /* valid bit (bit 7), response code (bits 6:0) */
|
---|
113 | u8 segment; /* segment number (obsolete) */
|
---|
114 | u8 sense_key; /* some flags (bits 7:4), sense key (bits 3:0) */
|
---|
115 | u8 info[4]; /* information (?) */
|
---|
116 | u8 adl_len; /* additional sense info length */
|
---|
117 | u8 cmd_specific[4]; /* command specific stuff (ignored) */
|
---|
118 | u8 asc; /* additional sense code */
|
---|
119 | u8 ascq; /* additional sense code qualifier */
|
---|
120 | u8 fruc; /* field replaceable unit code */
|
---|
121 | u8 flags; /* vendor-specific flags */
|
---|
122 | u8 field_off[2]; /* offset to invalid field in parm list */
|
---|
123 | } sense;
|
---|
124 |
|
---|
125 | u8 padding[ATAPI_SENSE_LEN]; /* pad to 64 bytes */
|
---|
126 |
|
---|
127 | } ATAPI_SENSE_DATA;
|
---|
128 |
|
---|
129 | /******************************************************************************Ã
|
---|
130 | * ATAPI_CDB_6 - describes 6 byte ATAPI command
|
---|
131 | */
|
---|
132 | typedef struct _ATAPI_CDB_6 {
|
---|
133 | u8 cmd; /* command code */
|
---|
134 | u8 lun; /* SCSI lun (ignored) */
|
---|
135 | u8 resvd[2];
|
---|
136 | u8 trans_len; /* transfer length */
|
---|
137 | u8 control;
|
---|
138 | } ATAPI_CDB_6;
|
---|
139 |
|
---|
140 | /******************************************************************************
|
---|
141 | * ATAPI_CDB_10 - describes layout of generic 10 byte ATAPI command
|
---|
142 | */
|
---|
143 | typedef struct _ATAPI_CDB_10 {
|
---|
144 | u8 cmd; /* SCSI/ATAPI command code */
|
---|
145 | u8 flags; /* flags (DPO, FUA) */
|
---|
146 | u8 lba[4]; /* logical block address */
|
---|
147 | u8 trans_len[2]; /* number of blocks to transfer */
|
---|
148 | u8 control; /* (nothing much) */
|
---|
149 | } ATAPI_CDB_10;
|
---|
150 |
|
---|
151 | /******************************************************************************
|
---|
152 | * ATAPI_CDB_12 - describes layout of generic 12 byte ATAPI command
|
---|
153 | */
|
---|
154 | typedef struct _ATAPI_CDB_12 {
|
---|
155 | u8 cmd; /* SCSI/ATAPI command code */
|
---|
156 | u8 flags; /* flags (DPO, FUA) */
|
---|
157 | u8 lba[4]; /* logical block address */
|
---|
158 | u8 trans_len[4]; /* number of blocks to transfer */
|
---|
159 | u8 reserved;
|
---|
160 | u8 control; /* (nothing much) */
|
---|
161 | } ATAPI_CDB_12;
|
---|
162 |
|
---|
163 |
|
---|
164 | /* ---------------------------- global variables --------------------------- */
|
---|
165 |
|
---|
166 | /* -------------------------- function prototypes -------------------------- */
|
---|
167 |
|
---|
168 | extern int atapi_get_geometry (IORBH _far *iorb, int slot);
|
---|
169 | extern int atapi_unit_ready (IORBH _far *iorb, int slot);
|
---|
170 | extern int atapi_read (IORBH _far *iorb, int slot);
|
---|
171 | extern int atapi_verify (IORBH _far *iorb, int slot);
|
---|
172 | extern int atapi_write (IORBH _far *iorb, int slot);
|
---|
173 | extern int atapi_execute_cdb (IORBH _far *iorb, int slot);
|
---|
174 | extern int atapi_req_sense (IORBH _far *iorb, int slot);
|
---|
175 |
|
---|