]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/dev/ata/atapi-all.h
This commit was generated by cvs2svn to compensate for changes in r60573,
[FreeBSD/FreeBSD.git] / sys / dev / ata / atapi-all.h
1 /*-
2  * Copyright (c) 1998,1999,2000 Søren Schmidt
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
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.
16  *
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.
27  *
28  * $FreeBSD$
29  */
30
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_DONEDRQ                 (ATA_S_DRQ | ATA_I_CMD | ATA_I_IN)
38 #define ATAPI_P_DONE                    (ATA_I_CMD | ATA_I_IN)
39 #define ATAPI_P_ABORT                   0
40
41 /* error register bits */
42 #define ATAPI_E_MASK                    0x0f    /* error mask */
43 #define ATAPI_E_ILI                     0x01    /* illegal length indication */
44 #define ATAPI_E_EOM                     0x02    /* end of media detected */
45 #define ATAPI_E_ABRT                    0x04    /* command aborted */
46 #define ATAPI_E_MCR                     0x08    /* media change requested */
47 #define ATAPI_SK_MASK                   0xf0    /* sense key mask */
48 #define ATAPI_SK_NO_SENSE               0x00    /* no specific sense key info */
49 #define ATAPI_SK_RECOVERED_ERROR        0x10    /* command OK, data recovered */
50 #define ATAPI_SK_NOT_READY              0x20    /* no access to drive */
51 #define ATAPI_SK_MEDIUM_ERROR           0x30    /* non-recovered data error */
52 #define ATAPI_SK_HARDWARE_ERROR         0x40    /* non-recoverable HW failure */
53 #define ATAPI_SK_ILLEGAL_REQUEST        0x50    /* invalid command param(s) */
54 #define ATAPI_SK_UNIT_ATTENTION         0x60    /* media changed */
55 #define ATAPI_SK_DATA_PROTECT           0x70    /* write protect */
56 #define ATAPI_SK_BLANK_CHECK            0x80    /* blank check */
57 #define ATAPI_SK_VENDOR_SPECIFIC        0x90    /* vendor specific skey */
58 #define ATAPI_SK_COPY_ABORTED           0xa0    /* copy aborted */
59 #define ATAPI_SK_ABORTED_COMMAND        0xb0    /* command aborted, try again */
60 #define ATAPI_SK_EQUAL                  0xc0    /* equal */
61 #define ATAPI_SK_VOLUME_OVERFLOW        0xd0    /* volume overflow */
62 #define ATAPI_SK_MISCOMPARE             0xe0    /* data dont match the medium */
63 #define ATAPI_SK_RESERVED               0xf0
64
65 /* ATAPI commands */
66 #define ATAPI_TEST_UNIT_READY           0x00    /* check if device is ready */
67 #define ATAPI_REWIND                    0x01    /* rewind */
68 #define ATAPI_REQUEST_SENSE             0x03    /* get sense data */
69 #define ATAPI_FORMAT                    0x04    /* format unit */
70 #define ATAPI_READ                      0x08    /* read data */
71 #define ATAPI_WRITE                     0x0a    /* write data */
72 #define ATAPI_WEOF                      0x10    /* write filemark */
73 #define     WF_WRITE                            0x01
74 #define ATAPI_SPACE                     0x11    /* space command */
75 #define     SP_FM                               0x01
76 #define     SP_EOD                              0x03
77 #define ATAPI_MODE_SELECT               0x15    /* mode select */
78 #define ATAPI_ERASE                     0x19    /* erase */
79 #define ATAPI_MODE_SENSE                0x1a    /* mode sense */
80 #define ATAPI_START_STOP                0x1b    /* start/stop unit */
81 #define     SS_LOAD                             0x01
82 #define     SS_RETENSION                        0x02
83 #define     SS_EJECT                            0x04
84 #define ATAPI_PREVENT_ALLOW             0x1e    /* media removal */
85 #define ATAPI_READ_CAPACITY             0x25    /* get volume capacity */
86 #define ATAPI_READ_BIG                  0x28    /* read data */
87 #define ATAPI_WRITE_BIG                 0x2a    /* write data */
88 #define ATAPI_LOCATE                    0x2b    /* locate to position */
89 #define ATAPI_READ_POSITION             0x34    /* read position */
90 #define ATAPI_SYNCHRONIZE_CACHE         0x35    /* flush buf, close channel */
91 #define ATAPI_WRITE_BUFFER              0x3b    /* write device buffer */
92 #define ATAPI_READ_BUFFER               0x3c    /* read device buffer */
93 #define ATAPI_READ_SUBCHANNEL           0x42    /* get subchannel info */
94 #define ATAPI_READ_TOC                  0x43    /* get table of contents */
95 #define ATAPI_PLAY_MSF                  0x47    /* play by MSF address */
96 #define ATAPI_PLAY_TRACK                0x48    /* play by track number */
97 #define ATAPI_PAUSE                     0x4b    /* pause audio operation */
98 #define ATAPI_READ_DISK_INFO            0x51    /* get disk info structure */
99 #define ATAPI_READ_TRACK_INFO           0x52    /* get track info structure */
100 #define ATAPI_RESERVE_TRACK             0x53    /* reserve track */
101 #define ATAPI_SEND_OPC_INFO             0x54    /* send OPC structurek */
102 #define ATAPI_MODE_SELECT_BIG           0x55    /* set device parameters */
103 #define ATAPI_REPAIR_TRACK              0x58    /* repair track */
104 #define ATAPI_READ_MASTER_CUE           0x59    /* read master CUE info */
105 #define ATAPI_MODE_SENSE_BIG            0x5a    /* get device parameters */
106 #define ATAPI_CLOSE_TRACK               0x5b    /* close track/session */
107 #define ATAPI_READ_BUFFER_CAPACITY      0x5c    /* get buffer capicity */
108 #define ATAPI_SEND_CUE_SHEET            0x5d    /* send CUE sheet */
109 #define ATAPI_BLANK                     0xa1    /* blank the media */
110 #define ATAPI_SEND_KEY                  0xa3    /* send DVD key structure */
111 #define ATAPI_REPORT_KEY                0xa4    /* get DVD key structure */
112 #define ATAPI_PLAY_BIG                  0xa5    /* play by lba */
113 #define ATAPI_LOAD_UNLOAD               0xa6    /* changer control command */
114 #define ATAPI_READ_STRUCTURE            0xad    /* get DVD structure */
115 #define ATAPI_PLAY_CD                   0xb4    /* universal play command */
116 #define ATAPI_SET_SPEED                 0xbb    /* set drive speed */
117 #define ATAPI_MECH_STATUS               0xbd    /* get changer status */
118 #define ATAPI_READ_CD                   0xbe    /* read data */
119
120 /* ATAPI request sense structure */   
121 struct atapi_reqsense {
122     u_int8_t    error_code      :7;             /* current or deferred errors */
123     u_int8_t    valid           :1;             /* follows ATAPI spec */
124     u_int8_t    segment;                        /* Segment number */
125     u_int8_t    sense_key       :4;             /* sense key */
126     u_int8_t    reserved2_4     :1;             /* reserved */
127     u_int8_t    ili             :1;             /* incorrect length indicator */
128     u_int8_t    eom             :1;             /* end of medium */
129     u_int8_t    filemark        :1;             /* filemark */
130                                                 /* cmd information */
131     u_int32_t   cmd_info __attribute__((packed));
132     u_int8_t    sense_length;                   /* additional sense len (n-7) */
133                                                 /* additional cmd spec info */
134     u_int32_t   cmd_specific_info __attribute__((packed));
135     u_int8_t    asc;                            /* additional sense code */
136     u_int8_t    ascq;                           /* additional sense code qual */
137     u_int8_t    replaceable_unit_code;          /* replaceable unit code */
138     u_int8_t    sk_specific1    :7;             /* sense key specific */
139     u_int8_t    sksv            :1;             /* sense key specific info OK */
140     u_int8_t    sk_specific2;                   /* sense key specific */
141     u_int8_t    sk_specific3;                   /* sense key specific */
142 };  
143
144 struct atapi_softc {
145     struct ata_softc            *controller;    /* ptr to controller softc */
146     int32_t                     unit;           /* ATA_MASTER or ATA_SLAVE */
147     void                        *driver;        /* ptr to subdriver softc */
148     int8_t                      *devname;       /* this devices name */
149     int8_t                      cmd;            /* last cmd executed */
150     u_int32_t                   flags;          /* drive flags */
151 #define         ATAPI_F_MEDIA_CHANGED   0x0001
152
153 };
154
155 typedef int32_t atapi_callback_t(struct atapi_request *);
156
157 struct atapi_request {
158     struct atapi_softc          *device;        /* ptr to parent device */
159     u_int8_t                    ccb[16];        /* command control block */
160     int32_t                     ccbsize;        /* size of ccb (12 | 16) */
161     u_int32_t                   bytecount;      /* bytes to transfer */
162     u_int32_t                   donecount;      /* bytes transferred */
163     int32_t                     timeout;        /* timeout for this cmd */
164     struct callout_handle       timeout_handle; /* handle for untimeout */
165     int32_t                     retries;        /* retry count */
166     int32_t                     result;         /* result of this cmd */
167     int32_t                     error;          /* result translated to errno */
168     struct atapi_reqsense       sense;          /* sense data if error */
169     int32_t                     flags;          
170 #define         ATPR_F_READ             0x0001
171 #define         ATPR_F_DMA_USED         0x0002
172 #define         ATPR_F_AT_HEAD          0x0004
173
174     int8_t                      *data;          /* pointer to data buf */
175     atapi_callback_t            *callback;      /* ptr to callback func */
176     void                        *driver;        /* driver specific */
177     TAILQ_ENTRY(atapi_request)  chain;          /* list management */
178 };
179
180 void atapi_attach(struct ata_softc *, int32_t);
181 void atapi_detach(struct atapi_softc *);
182 void atapi_start(struct atapi_softc *);
183 void atapi_transfer(struct atapi_request *);
184 int32_t atapi_interrupt(struct atapi_request *);
185 int32_t atapi_queue_cmd(struct atapi_softc *, int8_t [], void *, int32_t, int32_t, int32_t, atapi_callback_t, void *);
186 void atapi_reinit(struct atapi_softc *);
187 int32_t atapi_test_ready(struct atapi_softc *);
188 int32_t atapi_wait_ready(struct atapi_softc *, int32_t);
189 void atapi_request_sense(struct atapi_softc *, struct atapi_reqsense *);
190 void atapi_dump(int8_t *, void *, int32_t);
191 int32_t acdattach(struct atapi_softc *);
192 void acddetach(struct atapi_softc *);
193 void acd_start(struct atapi_softc *);
194 int32_t afdattach(struct atapi_softc *);
195 void afddetach(struct atapi_softc *);
196 void afd_start(struct atapi_softc *);
197 int32_t astattach(struct atapi_softc *);
198 void astdetach(struct atapi_softc *);
199 void ast_start(struct atapi_softc *);