2 * Copyright (c) 1998,1999 Søren Schmidt
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 /* ATAPI misc defines */
32 #define ATAPI_MAGIC_LSB 0x14
33 #define ATAPI_MAGIC_MSB 0xeb
34 #define ATAPI_P_READ (ATA_S_DRQ | ATA_I_IN)
35 #define ATAPI_P_WRITE (ATA_S_DRQ)
36 #define ATAPI_P_CMDOUT (ATA_S_DRQ | ATA_I_CMD)
37 #define ATAPI_P_ABORT 0
38 #define ATAPI_P_DONE (ATA_I_IN | ATA_I_CMD)
40 /* error register bits */
41 #define ATAPI_E_MASK 0x0f /* error mask */
42 #define ATAPI_E_ILI 0x01 /* illegal length indication */
43 #define ATAPI_E_EOM 0x02 /* end of media detected */
44 #define ATAPI_E_ABRT 0x04 /* command aborted */
45 #define ATAPI_E_MCR 0x08 /* media change requested */
46 #define ATAPI_SK_MASK 0xf0 /* sense key mask */
47 #define ATAPI_SK_NO_SENSE 0x00 /* no specific sense key info */
48 #define ATAPI_SK_RECOVERED_ERROR 0x10 /* command OK, data recovered */
49 #define ATAPI_SK_NOT_READY 0x20 /* no access to drive */
50 #define ATAPI_SK_MEDIUM_ERROR 0x30 /* non-recovered data error */
51 #define ATAPI_SK_HARDWARE_ERROR 0x40 /* non-recoverable HW failure */
52 #define ATAPI_SK_ILLEGAL_REQUEST 0x50 /* invalid command param(s) */
53 #define ATAPI_SK_UNIT_ATTENTION 0x60 /* media changed */
54 #define ATAPI_SK_DATA_PROTECT 0x70 /* write protect */
55 #define ATAPI_SK_BLANK_CHECK 0x80 /* blank check */
56 #define ATAPI_SK_VENDOR_SPECIFIC 0x90 /* vendor specific skey */
57 #define ATAPI_SK_COPY_ABORTED 0xa0 /* copy aborted */
58 #define ATAPI_SK_ABORTED_COMMAND 0xb0 /* command aborted, try again */
59 #define ATAPI_SK_EQUAL 0xc0 /* equal */
60 #define ATAPI_SK_VOLUME_OVERFLOW 0xd0 /* volume overflow */
61 #define ATAPI_SK_MISCOMPARE 0xe0 /* data dont match the medium */
62 #define ATAPI_SK_RESERVED 0xf0
65 #define ATAPI_TEST_UNIT_READY 0x00 /* check if device is ready */
66 #define ATAPI_REWIND 0x01 /* rewind */
67 #define ATAPI_REQUEST_SENSE 0x03 /* get sense data */
68 #define ATAPI_READ 0x08 /* read data */
69 #define ATAPI_WRITE 0x0a /* write data */
70 #define ATAPI_WEOF 0x10 /* write filemark */
72 #define ATAPI_SPACE 0x11 /* space command */
75 #define ATAPI_MODE_SELECT 0x15 /* mode select */
76 #define ATAPI_ERASE 0x19 /* erase */
77 #define ATAPI_MODE_SENSE 0x1a /* mode sense */
78 #define ATAPI_START_STOP 0x1b /* start/stop unit */
80 #define SS_RETENSION 0x02
82 #define ATAPI_PREVENT_ALLOW 0x1e /* media removal */
83 #define ATAPI_READ_CAPACITY 0x25 /* get volume capacity */
84 #define ATAPI_READ_BIG 0x28 /* read data */
85 #define ATAPI_WRITE_BIG 0x2a /* write data */
86 #define ATAPI_LOCATE 0x2b /* locate to position */
87 #define ATAPI_READ_POSITION 0x34 /* read position */
88 #define ATAPI_SYNCHRONIZE_CACHE 0x35 /* flush buf, close channel */
89 #define ATAPI_WRITE_BUFFER 0x3b /* write device buffer */
90 #define ATAPI_READ_BUFFER 0x3c /* read device buffer */
91 #define ATAPI_READ_SUBCHANNEL 0x42 /* get subchannel info */
92 #define ATAPI_READ_TOC 0x43 /* get table of contents */
93 #define ATAPI_PLAY_MSF 0x47 /* play by MSF address */
94 #define ATAPI_PLAY_TRACK 0x48 /* play by track number */
95 #define ATAPI_PAUSE 0x4b /* pause audio operation */
96 #define ATAPI_READ_TRACK_INFO 0x52 /* get track info structure */
97 #define ATAPI_MODE_SELECT_BIG 0x55 /* set device parameters */
98 #define ATAPI_MODE_SENSE_BIG 0x5a /* get device parameters */
99 #define ATAPI_CLOSE_TRACK 0x5b /* close track/session */
100 #define ATAPI_BLANK 0xa1 /* blank the media */
101 #define ATAPI_PLAY_BIG 0xa5 /* play by lba */
102 #define ATAPI_LOAD_UNLOAD 0xa6 /* changer control command */
103 #define ATAPI_PLAY_CD 0xb4 /* universal play command */
104 #define ATAPI_SET_SPEED 0xbb /* set drive speed */
105 #define ATAPI_MECH_STATUS 0xbd /* get changer status */
106 #define ATAPI_READ_CD 0xbe /* read data */
108 /* ATAPI device parameter information */
109 struct atapi_params {
110 u_int8_t cmdsize :2; /* packet command size */
111 #define ATAPI_PSIZE_12 0 /* 12 bytes */
112 #define ATAPI_PSIZE_16 1 /* 16 bytes */
115 u_int8_t drqtype :2; /* DRQ type */
116 #define ATAPI_DRQT_MPROC 0 /* cpu 3 ms delay */
117 #define ATAPI_DRQT_INTR 1 /* intr 10 ms delay */
118 #define ATAPI_DRQT_ACCEL 2 /* accel 50 us delay */
120 u_int8_t removable :1; /* device is removable */
121 u_int8_t device_type :5; /* device type */
122 #define ATAPI_TYPE_DIRECT 0 /* disk/floppy */
123 #define ATAPI_TYPE_TAPE 1 /* streaming tape */
124 #define ATAPI_TYPE_CDROM 5 /* CD-ROM device */
125 #define ATAPI_TYPE_OPTICAL 7 /* optical disk */
128 u_int8_t proto :2; /* command protocol */
129 #define ATAPI_PROTO_ATAPI 2
140 int8_t serial[20]; /* serial number */
144 int8_t revision[8]; /* firmware revision */
145 int8_t model[40]; /* model name */
149 u_int8_t vendorcap; /* vendor capabilities */
150 u_int8_t dmaflag :1; /* DMA supported */
151 u_int8_t lbaflag :1; /* LBA supported - always 1 */
152 u_int8_t iordydis :1; /* IORDY can be disabled */
153 u_int8_t iordyflag :1; /* IORDY supported */
155 u_int8_t ovlapflag :1; /* overlap supported */
157 u_int8_t idmaflag :1; /* interleaved DMA supported */
158 int16_t capvalidate; /* validation for above */
160 u_int16_t piotiming; /* PIO cycle timing */
161 u_int16_t dmatiming; /* DMA cycle timing */
163 u_int16_t atavalid; /* fields valid */
164 #define ATAPI_FLAG_54_58 1 /* words 54-58 valid */
165 #define ATAPI_FLAG_64_70 2 /* words 64-70 valid */
167 int16_t reserved54[8];
169 int16_t sdmamodes; /* singleword DMA modes */
170 int16_t wdmamodes; /* multiword DMA modes */
171 int16_t apiomodes; /* advanced PIO modes */
173 u_int16_t mwdmamin; /* min. M/W DMA time/word ns */
174 u_int16_t mwdmarec; /* rec. M/W DMA time ns */
175 u_int16_t pioblind; /* min. PIO cycle w/o flow */
176 u_int16_t pioiordy; /* min. PIO cycle IORDY flow */
180 u_int16_t rlsovlap; /* rel time (us) for overlap */
181 u_int16_t rlsservice; /* rel time (us) for service */
197 int16_t udmamodes; /* UltraDMA modes */
199 int16_t enherasetime;
201 int16_t reserved92[34];
206 /* ATAPI request sense structure */
207 struct atapi_reqsense {
208 u_int8_t error_code :7; /* current or deferred errors */
209 u_int8_t valid :1; /* follows ATAPI spec */
210 u_int8_t segment; /* Segment number */
211 u_int8_t sense_key :4; /* sense key */
212 u_int8_t reserved2_4 :1; /* reserved */
213 u_int8_t ili :1; /* incorrect length indicator */
214 u_int8_t eom :1; /* end of medium */
215 u_int8_t filemark :1; /* filemark */
216 /* cmd information */
217 u_int32_t cmd_info __attribute__((packed));
218 u_int8_t sense_length; /* additional sense len (n-7) */
219 /* additional cmd spec info */
220 u_int32_t cmd_specific_info __attribute__((packed));
221 u_int8_t asc; /* additional sense code */
222 u_int8_t ascq; /* additional sense code qual */
223 u_int8_t replaceable_unit_code; /* replaceable unit code */
224 u_int8_t sk_specific1 :7; /* sense key specific */
225 u_int8_t sksv :1; /* sense key specific info OK */
226 u_int8_t sk_specific2; /* sense key specific */
227 u_int8_t sk_specific3; /* sense key specific */
231 struct ata_softc *controller; /* ptr to parent ctrl */
232 struct atapi_params *atapi_parm; /* ata device params */
233 int32_t unit; /* ATA_MASTER or ATA_SLAVE */
234 int8_t cmd; /* last cmd executed */
235 u_int32_t flags; /* drive flags */
236 #define ATAPI_F_DMA_ENABLED 0x0001
237 #define ATAPI_F_DMA_USED 0x0002
238 #define ATAPI_F_DSC_USED 0x0004
239 #define ATAPI_F_MEDIA_CHANGED 0x0008
243 typedef int32_t atapi_callback_t(struct atapi_request *);
245 struct atapi_request {
246 struct atapi_softc *device; /* ptr to parent device */
247 void *driver; /* ptr to calling driver */
248 u_int8_t ccb[16]; /* command control block */
249 int32_t ccbsize; /* size of ccb (12 | 16) */
250 u_int32_t bytecount; /* bytes to transfer */
251 int32_t timeout; /* timeout for this cmd */
252 struct callout_handle timeout_handle; /* handle for untimeout */
253 int32_t retries; /* retry count */
254 int32_t result; /* result of this cmd */
255 struct atapi_reqsense sense; /* sense data if error */
257 #define A_READ 0x0001
259 int8_t *data; /* pointer to data buf */
260 struct buf *bp; /* associated buf ptr */
261 atapi_callback_t *callback; /* ptr to callback func */
262 TAILQ_ENTRY(atapi_request) chain; /* list management */
265 void atapi_transfer(struct atapi_request *);
266 int32_t atapi_interrupt(struct atapi_request *);
267 int32_t atapi_queue_cmd(struct atapi_softc *, int8_t [], void *, int32_t, int32_t, int32_t, atapi_callback_t, void *, struct buf *);
268 void atapi_reinit(struct atapi_softc *);
269 int32_t atapi_test_ready(struct atapi_softc *);
270 int32_t atapi_wait_ready(struct atapi_softc *, int32_t);
271 void atapi_request_sense(struct atapi_softc *, struct atapi_reqsense *);
272 void atapi_dump(int8_t *, void *, int32_t);