2 * Copyright (c) 1998,1999,2000,2001,2002 Søren Schmidt <sos@FreeBSD.org>
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.
28 * $FreeBSD: src/sys/dev/ata/atapi-all.h,v 1.22.2.10 2002/10/31 23:10:33 thomas Exp $
29 * $DragonFly: src/sys/dev/disk/ata/atapi-all.h,v 1.5 2004/09/18 18:33:38 dillon Exp $
32 /* ATAPI misc defines */
33 #define ATAPI_MAGIC_LSB 0x14
34 #define ATAPI_MAGIC_MSB 0xeb
35 #define ATAPI_P_READ (ATA_S_DRQ | ATA_I_IN)
36 #define ATAPI_P_WRITE (ATA_S_DRQ)
37 #define ATAPI_P_CMDOUT (ATA_S_DRQ | ATA_I_CMD)
38 #define ATAPI_P_DONEDRQ (ATA_S_DRQ | ATA_I_CMD | ATA_I_IN)
39 #define ATAPI_P_DONE (ATA_I_CMD | ATA_I_IN)
40 #define ATAPI_P_ABORT 0
42 /* error register bits */
43 #define ATAPI_E_MASK 0x0f /* error mask */
44 #define ATAPI_E_ILI 0x01 /* illegal length indication */
45 #define ATAPI_E_EOM 0x02 /* end of media detected */
46 #define ATAPI_E_ABRT 0x04 /* command aborted */
47 #define ATAPI_E_MCR 0x08 /* media change requested */
48 #define ATAPI_SK_MASK 0xf0 /* sense key mask */
49 #define ATAPI_SK_NO_SENSE 0x00 /* no specific sense key info */
50 #define ATAPI_SK_RECOVERED_ERROR 0x10 /* command OK, data recovered */
51 #define ATAPI_SK_NOT_READY 0x20 /* no access to drive */
52 #define ATAPI_SK_MEDIUM_ERROR 0x30 /* non-recovered data error */
53 #define ATAPI_SK_HARDWARE_ERROR 0x40 /* non-recoverable HW failure */
54 #define ATAPI_SK_ILLEGAL_REQUEST 0x50 /* invalid command param(s) */
55 #define ATAPI_SK_UNIT_ATTENTION 0x60 /* media changed */
56 #define ATAPI_SK_DATA_PROTECT 0x70 /* write protect */
57 #define ATAPI_SK_BLANK_CHECK 0x80 /* blank check */
58 #define ATAPI_SK_VENDOR_SPECIFIC 0x90 /* vendor specific skey */
59 #define ATAPI_SK_COPY_ABORTED 0xa0 /* copy aborted */
60 #define ATAPI_SK_ABORTED_COMMAND 0xb0 /* command aborted, try again */
61 #define ATAPI_SK_EQUAL 0xc0 /* equal */
62 #define ATAPI_SK_VOLUME_OVERFLOW 0xd0 /* volume overflow */
63 #define ATAPI_SK_MISCOMPARE 0xe0 /* data dont match the medium */
64 #define ATAPI_SK_RESERVED 0xf0
67 #define ATAPI_TEST_UNIT_READY 0x00 /* check if device is ready */
68 #define ATAPI_REZERO 0x01 /* rewind */
69 #define ATAPI_REQUEST_SENSE 0x03 /* get sense data */
70 #define ATAPI_FORMAT 0x04 /* format unit */
71 #define ATAPI_READ 0x08 /* read data */
72 #define ATAPI_WRITE 0x0a /* write data */
73 #define ATAPI_WEOF 0x10 /* write filemark */
75 #define ATAPI_SPACE 0x11 /* space command */
78 #define ATAPI_MODE_SELECT 0x15 /* mode select */
79 #define ATAPI_ERASE 0x19 /* erase */
80 #define ATAPI_MODE_SENSE 0x1a /* mode sense */
81 #define ATAPI_START_STOP 0x1b /* start/stop unit */
83 #define SS_RETENSION 0x02
85 #define ATAPI_PREVENT_ALLOW 0x1e /* media removal */
86 #define ATAPI_READ_CAPACITY 0x25 /* get volume capacity */
87 #define ATAPI_READ_BIG 0x28 /* read data */
88 #define ATAPI_WRITE_BIG 0x2a /* write data */
89 #define ATAPI_LOCATE 0x2b /* locate to position */
90 #define ATAPI_READ_POSITION 0x34 /* read position */
91 #define ATAPI_SYNCHRONIZE_CACHE 0x35 /* flush buf, close channel */
92 #define ATAPI_WRITE_BUFFER 0x3b /* write device buffer */
93 #define ATAPI_READ_BUFFER 0x3c /* read device buffer */
94 #define ATAPI_READ_SUBCHANNEL 0x42 /* get subchannel info */
95 #define ATAPI_READ_TOC 0x43 /* get table of contents */
96 #define ATAPI_PLAY_10 0x45 /* play by lba */
97 #define ATAPI_PLAY_MSF 0x47 /* play by MSF address */
98 #define ATAPI_PLAY_TRACK 0x48 /* play by track number */
99 #define ATAPI_PAUSE 0x4b /* pause audio operation */
100 #define ATAPI_READ_DISK_INFO 0x51 /* get disk info structure */
101 #define ATAPI_READ_TRACK_INFO 0x52 /* get track info structure */
102 #define ATAPI_RESERVE_TRACK 0x53 /* reserve track */
103 #define ATAPI_SEND_OPC_INFO 0x54 /* send OPC structurek */
104 #define ATAPI_MODE_SELECT_BIG 0x55 /* set device parameters */
105 #define ATAPI_REPAIR_TRACK 0x58 /* repair track */
106 #define ATAPI_READ_MASTER_CUE 0x59 /* read master CUE info */
107 #define ATAPI_MODE_SENSE_BIG 0x5a /* get device parameters */
108 #define ATAPI_CLOSE_TRACK 0x5b /* close track/session */
109 #define ATAPI_READ_BUFFER_CAPACITY 0x5c /* get buffer capicity */
110 #define ATAPI_SEND_CUE_SHEET 0x5d /* send CUE sheet */
111 #define ATAPI_BLANK 0xa1 /* blank the media */
112 #define ATAPI_SEND_KEY 0xa3 /* send DVD key structure */
113 #define ATAPI_REPORT_KEY 0xa4 /* get DVD key structure */
114 #define ATAPI_PLAY_12 0xa5 /* play by lba */
115 #define ATAPI_LOAD_UNLOAD 0xa6 /* changer control command */
116 #define ATAPI_READ_STRUCTURE 0xad /* get DVD structure */
117 #define ATAPI_PLAY_CD 0xb4 /* universal play command */
118 #define ATAPI_SET_SPEED 0xbb /* set drive speed */
119 #define ATAPI_MECH_STATUS 0xbd /* get changer status */
120 #define ATAPI_READ_CD 0xbe /* read data */
121 #define ATAPI_POLL_DSC 0xff /* poll DSC status bit */
123 /* ATAPI request sense structure */
124 struct atapi_reqsense {
125 u_int8_t error_code :7; /* current or deferred errors */
126 u_int8_t valid :1; /* follows ATAPI spec */
127 u_int8_t segment; /* Segment number */
128 u_int8_t sense_key :4; /* sense key */
129 u_int8_t reserved2_4 :1; /* reserved */
130 u_int8_t ili :1; /* incorrect length indicator */
131 u_int8_t eom :1; /* end of medium */
132 u_int8_t filemark :1; /* filemark */
133 /* cmd information */
134 u_int32_t cmd_info __attribute__((packed));
135 u_int8_t sense_length; /* additional sense len (n-7) */
136 /* additional cmd spec info */
137 u_int32_t cmd_specific_info __attribute__((packed));
138 u_int8_t asc; /* additional sense code */
139 u_int8_t ascq; /* additional sense code qual */
140 u_int8_t replaceable_unit_code; /* replaceable unit code */
141 u_int8_t sk_specific :7; /* sense key specific */
142 u_int8_t sksv :1; /* sense key specific info OK */
143 u_int8_t sk_specific1; /* sense key specific */
144 u_int8_t sk_specific2; /* sense key specific */
147 typedef int atapi_callback_t(struct atapi_request *);
149 struct atapi_request {
150 struct ata_device *device; /* ptr to parent softc */
151 u_int8_t ccb[16]; /* command control block */
152 int ccbsize; /* size of ccb (12 | 16) */
153 u_int32_t bytecount; /* bytes to transfer */
154 u_int32_t donecount; /* bytes transferred */
155 int timeout; /* timeout for this cmd */
156 struct callout callout;
157 int retries; /* retry count */
158 int result; /* result of this cmd */
159 int error; /* result translated to errno */
160 struct atapi_reqsense sense; /* sense data if error */
162 #define ATPR_F_READ 0x0001
163 #define ATPR_F_DMA_USED 0x0002
164 #define ATPR_F_AT_HEAD 0x0004
165 #define ATPR_F_INTERNAL 0x0008
166 #define ATPR_F_QUIET 0x0010
168 caddr_t data; /* pointer to data buf */
169 atapi_callback_t *callback; /* ptr to callback func */
170 void *driver; /* driver specific */
171 TAILQ_ENTRY(atapi_request) chain; /* list management */
174 void atapi_attach(struct ata_device *, int);
175 void atapi_cam_attach_bus(struct ata_channel *);
176 void atapi_detach(struct ata_device *);
177 void atapi_cam_detach_bus(struct ata_channel *);
178 void atapi_cam_reinit_bus(struct ata_channel *);
179 void atapi_reinit(struct ata_device *);
180 void atapi_start(struct ata_device *);
181 int atapi_transfer(struct atapi_request *);
182 int atapi_interrupt(struct atapi_request *);
183 int atapi_queue_cmd(struct ata_device *, int8_t [], caddr_t, int, int, int, atapi_callback_t, void *);
184 int atapi_test_ready(struct ata_device *);
185 int atapi_wait_dsc(struct ata_device *, int);
186 void atapi_request_sense(struct ata_device *, struct atapi_reqsense *);
187 void atapi_dump(char *, void *, int);
188 int acdattach(struct ata_device *);
189 void acddetach(struct ata_device *);
190 void acd_start(struct ata_device *);
191 int afdattach(struct ata_device *);
192 void afddetach(struct ata_device *);
193 void afd_start(struct ata_device *);
194 int astattach(struct ata_device *);
195 void astdetach(struct ata_device *);
196 void ast_start(struct ata_device *);