Commit f20f258603ebc5da91e76884cf0c0d7ac9804b1c
Committed by
Bartlomiej Zolnierkiewicz
1 parent
fec6ed1d1f
Exists in
master
and in
4 other branches
ide-cd: temporary tray close fix
This one fixes http://bugzilla.kernel.org/show_bug.cgi?id=11602. A more generic fix for drives which cannot autoclose tray will follow. Signed-off-by: Borislav Petkov <petkovbb@gmail.com> Cc: Jens Axboe <jens.axboe@oracle.com> [bart: add an extra parentheses for consistency with the rest of kernel code] Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Showing 2 changed files with 7 additions and 2 deletions Inline Diff
drivers/ide/ide-cd.c
1 | /* | 1 | /* |
2 | * ATAPI CD-ROM driver. | 2 | * ATAPI CD-ROM driver. |
3 | * | 3 | * |
4 | * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov> | 4 | * Copyright (C) 1994-1996 Scott Snyder <snyder@fnald0.fnal.gov> |
5 | * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org> | 5 | * Copyright (C) 1996-1998 Erik Andersen <andersee@debian.org> |
6 | * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de> | 6 | * Copyright (C) 1998-2000 Jens Axboe <axboe@suse.de> |
7 | * Copyright (C) 2005, 2007 Bartlomiej Zolnierkiewicz | 7 | * Copyright (C) 2005, 2007 Bartlomiej Zolnierkiewicz |
8 | * | 8 | * |
9 | * May be copied or modified under the terms of the GNU General Public | 9 | * May be copied or modified under the terms of the GNU General Public |
10 | * License. See linux/COPYING for more information. | 10 | * License. See linux/COPYING for more information. |
11 | * | 11 | * |
12 | * See Documentation/cdrom/ide-cd for usage information. | 12 | * See Documentation/cdrom/ide-cd for usage information. |
13 | * | 13 | * |
14 | * Suggestions are welcome. Patches that work are more welcome though. ;-) | 14 | * Suggestions are welcome. Patches that work are more welcome though. ;-) |
15 | * For those wishing to work on this driver, please be sure you download | 15 | * For those wishing to work on this driver, please be sure you download |
16 | * and comply with the latest Mt. Fuji (SFF8090 version 4) and ATAPI | 16 | * and comply with the latest Mt. Fuji (SFF8090 version 4) and ATAPI |
17 | * (SFF-8020i rev 2.6) standards. These documents can be obtained by | 17 | * (SFF-8020i rev 2.6) standards. These documents can be obtained by |
18 | * anonymous ftp from: | 18 | * anonymous ftp from: |
19 | * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps | 19 | * ftp://fission.dt.wdc.com/pub/standards/SFF_atapi/spec/SFF8020-r2.6/PS/8020r26.ps |
20 | * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf | 20 | * ftp://ftp.avc-pioneer.com/Mtfuji4/Spec/Fuji4r10.pdf |
21 | * | 21 | * |
22 | * For historical changelog please see: | 22 | * For historical changelog please see: |
23 | * Documentation/ide/ChangeLog.ide-cd.1994-2004 | 23 | * Documentation/ide/ChangeLog.ide-cd.1994-2004 |
24 | */ | 24 | */ |
25 | 25 | ||
26 | #define IDECD_VERSION "5.00" | 26 | #define IDECD_VERSION "5.00" |
27 | 27 | ||
28 | #include <linux/module.h> | 28 | #include <linux/module.h> |
29 | #include <linux/types.h> | 29 | #include <linux/types.h> |
30 | #include <linux/kernel.h> | 30 | #include <linux/kernel.h> |
31 | #include <linux/delay.h> | 31 | #include <linux/delay.h> |
32 | #include <linux/timer.h> | 32 | #include <linux/timer.h> |
33 | #include <linux/slab.h> | 33 | #include <linux/slab.h> |
34 | #include <linux/interrupt.h> | 34 | #include <linux/interrupt.h> |
35 | #include <linux/errno.h> | 35 | #include <linux/errno.h> |
36 | #include <linux/cdrom.h> | 36 | #include <linux/cdrom.h> |
37 | #include <linux/ide.h> | 37 | #include <linux/ide.h> |
38 | #include <linux/completion.h> | 38 | #include <linux/completion.h> |
39 | #include <linux/mutex.h> | 39 | #include <linux/mutex.h> |
40 | #include <linux/bcd.h> | 40 | #include <linux/bcd.h> |
41 | 41 | ||
42 | /* For SCSI -> ATAPI command conversion */ | 42 | /* For SCSI -> ATAPI command conversion */ |
43 | #include <scsi/scsi.h> | 43 | #include <scsi/scsi.h> |
44 | 44 | ||
45 | #include <linux/irq.h> | 45 | #include <linux/irq.h> |
46 | #include <linux/io.h> | 46 | #include <linux/io.h> |
47 | #include <asm/byteorder.h> | 47 | #include <asm/byteorder.h> |
48 | #include <linux/uaccess.h> | 48 | #include <linux/uaccess.h> |
49 | #include <asm/unaligned.h> | 49 | #include <asm/unaligned.h> |
50 | 50 | ||
51 | #include "ide-cd.h" | 51 | #include "ide-cd.h" |
52 | 52 | ||
53 | static DEFINE_MUTEX(idecd_ref_mutex); | 53 | static DEFINE_MUTEX(idecd_ref_mutex); |
54 | 54 | ||
55 | #define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) | 55 | #define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref) |
56 | 56 | ||
57 | #define ide_cd_g(disk) \ | 57 | #define ide_cd_g(disk) \ |
58 | container_of((disk)->private_data, struct cdrom_info, driver) | 58 | container_of((disk)->private_data, struct cdrom_info, driver) |
59 | 59 | ||
60 | static void ide_cd_release(struct kref *); | 60 | static void ide_cd_release(struct kref *); |
61 | 61 | ||
62 | static struct cdrom_info *ide_cd_get(struct gendisk *disk) | 62 | static struct cdrom_info *ide_cd_get(struct gendisk *disk) |
63 | { | 63 | { |
64 | struct cdrom_info *cd = NULL; | 64 | struct cdrom_info *cd = NULL; |
65 | 65 | ||
66 | mutex_lock(&idecd_ref_mutex); | 66 | mutex_lock(&idecd_ref_mutex); |
67 | cd = ide_cd_g(disk); | 67 | cd = ide_cd_g(disk); |
68 | if (cd) { | 68 | if (cd) { |
69 | if (ide_device_get(cd->drive)) | 69 | if (ide_device_get(cd->drive)) |
70 | cd = NULL; | 70 | cd = NULL; |
71 | else | 71 | else |
72 | kref_get(&cd->kref); | 72 | kref_get(&cd->kref); |
73 | 73 | ||
74 | } | 74 | } |
75 | mutex_unlock(&idecd_ref_mutex); | 75 | mutex_unlock(&idecd_ref_mutex); |
76 | return cd; | 76 | return cd; |
77 | } | 77 | } |
78 | 78 | ||
79 | static void ide_cd_put(struct cdrom_info *cd) | 79 | static void ide_cd_put(struct cdrom_info *cd) |
80 | { | 80 | { |
81 | ide_drive_t *drive = cd->drive; | 81 | ide_drive_t *drive = cd->drive; |
82 | 82 | ||
83 | mutex_lock(&idecd_ref_mutex); | 83 | mutex_lock(&idecd_ref_mutex); |
84 | kref_put(&cd->kref, ide_cd_release); | 84 | kref_put(&cd->kref, ide_cd_release); |
85 | ide_device_put(drive); | 85 | ide_device_put(drive); |
86 | mutex_unlock(&idecd_ref_mutex); | 86 | mutex_unlock(&idecd_ref_mutex); |
87 | } | 87 | } |
88 | 88 | ||
89 | /* | 89 | /* |
90 | * Generic packet command support and error handling routines. | 90 | * Generic packet command support and error handling routines. |
91 | */ | 91 | */ |
92 | 92 | ||
93 | /* Mark that we've seen a media change and invalidate our internal buffers. */ | 93 | /* Mark that we've seen a media change and invalidate our internal buffers. */ |
94 | static void cdrom_saw_media_change(ide_drive_t *drive) | 94 | static void cdrom_saw_media_change(ide_drive_t *drive) |
95 | { | 95 | { |
96 | drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED; | 96 | drive->atapi_flags |= IDE_AFLAG_MEDIA_CHANGED; |
97 | drive->atapi_flags &= ~IDE_AFLAG_TOC_VALID; | 97 | drive->atapi_flags &= ~IDE_AFLAG_TOC_VALID; |
98 | } | 98 | } |
99 | 99 | ||
100 | static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, | 100 | static int cdrom_log_sense(ide_drive_t *drive, struct request *rq, |
101 | struct request_sense *sense) | 101 | struct request_sense *sense) |
102 | { | 102 | { |
103 | int log = 0; | 103 | int log = 0; |
104 | 104 | ||
105 | if (!sense || !rq || (rq->cmd_flags & REQ_QUIET)) | 105 | if (!sense || !rq || (rq->cmd_flags & REQ_QUIET)) |
106 | return 0; | 106 | return 0; |
107 | 107 | ||
108 | switch (sense->sense_key) { | 108 | switch (sense->sense_key) { |
109 | case NO_SENSE: | 109 | case NO_SENSE: |
110 | case RECOVERED_ERROR: | 110 | case RECOVERED_ERROR: |
111 | break; | 111 | break; |
112 | case NOT_READY: | 112 | case NOT_READY: |
113 | /* | 113 | /* |
114 | * don't care about tray state messages for e.g. capacity | 114 | * don't care about tray state messages for e.g. capacity |
115 | * commands or in-progress or becoming ready | 115 | * commands or in-progress or becoming ready |
116 | */ | 116 | */ |
117 | if (sense->asc == 0x3a || sense->asc == 0x04) | 117 | if (sense->asc == 0x3a || sense->asc == 0x04) |
118 | break; | 118 | break; |
119 | log = 1; | 119 | log = 1; |
120 | break; | 120 | break; |
121 | case ILLEGAL_REQUEST: | 121 | case ILLEGAL_REQUEST: |
122 | /* | 122 | /* |
123 | * don't log START_STOP unit with LoEj set, since we cannot | 123 | * don't log START_STOP unit with LoEj set, since we cannot |
124 | * reliably check if drive can auto-close | 124 | * reliably check if drive can auto-close |
125 | */ | 125 | */ |
126 | if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24) | 126 | if (rq->cmd[0] == GPCMD_START_STOP_UNIT && sense->asc == 0x24) |
127 | break; | 127 | break; |
128 | log = 1; | 128 | log = 1; |
129 | break; | 129 | break; |
130 | case UNIT_ATTENTION: | 130 | case UNIT_ATTENTION: |
131 | /* | 131 | /* |
132 | * Make good and sure we've seen this potential media change. | 132 | * Make good and sure we've seen this potential media change. |
133 | * Some drives (i.e. Creative) fail to present the correct sense | 133 | * Some drives (i.e. Creative) fail to present the correct sense |
134 | * key in the error register. | 134 | * key in the error register. |
135 | */ | 135 | */ |
136 | cdrom_saw_media_change(drive); | 136 | cdrom_saw_media_change(drive); |
137 | break; | 137 | break; |
138 | default: | 138 | default: |
139 | log = 1; | 139 | log = 1; |
140 | break; | 140 | break; |
141 | } | 141 | } |
142 | return log; | 142 | return log; |
143 | } | 143 | } |
144 | 144 | ||
145 | static void cdrom_analyze_sense_data(ide_drive_t *drive, | 145 | static void cdrom_analyze_sense_data(ide_drive_t *drive, |
146 | struct request *failed_command, | 146 | struct request *failed_command, |
147 | struct request_sense *sense) | 147 | struct request_sense *sense) |
148 | { | 148 | { |
149 | unsigned long sector; | 149 | unsigned long sector; |
150 | unsigned long bio_sectors; | 150 | unsigned long bio_sectors; |
151 | struct cdrom_info *info = drive->driver_data; | 151 | struct cdrom_info *info = drive->driver_data; |
152 | 152 | ||
153 | if (!cdrom_log_sense(drive, failed_command, sense)) | 153 | if (!cdrom_log_sense(drive, failed_command, sense)) |
154 | return; | 154 | return; |
155 | 155 | ||
156 | /* | 156 | /* |
157 | * If a read toc is executed for a CD-R or CD-RW medium where the first | 157 | * If a read toc is executed for a CD-R or CD-RW medium where the first |
158 | * toc has not been recorded yet, it will fail with 05/24/00 (which is a | 158 | * toc has not been recorded yet, it will fail with 05/24/00 (which is a |
159 | * confusing error) | 159 | * confusing error) |
160 | */ | 160 | */ |
161 | if (failed_command && failed_command->cmd[0] == GPCMD_READ_TOC_PMA_ATIP) | 161 | if (failed_command && failed_command->cmd[0] == GPCMD_READ_TOC_PMA_ATIP) |
162 | if (sense->sense_key == 0x05 && sense->asc == 0x24) | 162 | if (sense->sense_key == 0x05 && sense->asc == 0x24) |
163 | return; | 163 | return; |
164 | 164 | ||
165 | /* current error */ | 165 | /* current error */ |
166 | if (sense->error_code == 0x70) { | 166 | if (sense->error_code == 0x70) { |
167 | switch (sense->sense_key) { | 167 | switch (sense->sense_key) { |
168 | case MEDIUM_ERROR: | 168 | case MEDIUM_ERROR: |
169 | case VOLUME_OVERFLOW: | 169 | case VOLUME_OVERFLOW: |
170 | case ILLEGAL_REQUEST: | 170 | case ILLEGAL_REQUEST: |
171 | if (!sense->valid) | 171 | if (!sense->valid) |
172 | break; | 172 | break; |
173 | if (failed_command == NULL || | 173 | if (failed_command == NULL || |
174 | !blk_fs_request(failed_command)) | 174 | !blk_fs_request(failed_command)) |
175 | break; | 175 | break; |
176 | sector = (sense->information[0] << 24) | | 176 | sector = (sense->information[0] << 24) | |
177 | (sense->information[1] << 16) | | 177 | (sense->information[1] << 16) | |
178 | (sense->information[2] << 8) | | 178 | (sense->information[2] << 8) | |
179 | (sense->information[3]); | 179 | (sense->information[3]); |
180 | 180 | ||
181 | if (drive->queue->hardsect_size == 2048) | 181 | if (drive->queue->hardsect_size == 2048) |
182 | /* device sector size is 2K */ | 182 | /* device sector size is 2K */ |
183 | sector <<= 2; | 183 | sector <<= 2; |
184 | 184 | ||
185 | bio_sectors = max(bio_sectors(failed_command->bio), 4U); | 185 | bio_sectors = max(bio_sectors(failed_command->bio), 4U); |
186 | sector &= ~(bio_sectors - 1); | 186 | sector &= ~(bio_sectors - 1); |
187 | 187 | ||
188 | if (sector < get_capacity(info->disk) && | 188 | if (sector < get_capacity(info->disk) && |
189 | drive->probed_capacity - sector < 4 * 75) | 189 | drive->probed_capacity - sector < 4 * 75) |
190 | set_capacity(info->disk, sector); | 190 | set_capacity(info->disk, sector); |
191 | } | 191 | } |
192 | } | 192 | } |
193 | 193 | ||
194 | ide_cd_log_error(drive->name, failed_command, sense); | 194 | ide_cd_log_error(drive->name, failed_command, sense); |
195 | } | 195 | } |
196 | 196 | ||
197 | static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense, | 197 | static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense, |
198 | struct request *failed_command) | 198 | struct request *failed_command) |
199 | { | 199 | { |
200 | struct cdrom_info *info = drive->driver_data; | 200 | struct cdrom_info *info = drive->driver_data; |
201 | struct request *rq = &info->request_sense_request; | 201 | struct request *rq = &info->request_sense_request; |
202 | 202 | ||
203 | if (sense == NULL) | 203 | if (sense == NULL) |
204 | sense = &info->sense_data; | 204 | sense = &info->sense_data; |
205 | 205 | ||
206 | /* stuff the sense request in front of our current request */ | 206 | /* stuff the sense request in front of our current request */ |
207 | blk_rq_init(NULL, rq); | 207 | blk_rq_init(NULL, rq); |
208 | rq->cmd_type = REQ_TYPE_ATA_PC; | 208 | rq->cmd_type = REQ_TYPE_ATA_PC; |
209 | rq->rq_disk = info->disk; | 209 | rq->rq_disk = info->disk; |
210 | 210 | ||
211 | rq->data = sense; | 211 | rq->data = sense; |
212 | rq->cmd[0] = GPCMD_REQUEST_SENSE; | 212 | rq->cmd[0] = GPCMD_REQUEST_SENSE; |
213 | rq->cmd[4] = 18; | 213 | rq->cmd[4] = 18; |
214 | rq->data_len = 18; | 214 | rq->data_len = 18; |
215 | 215 | ||
216 | rq->cmd_type = REQ_TYPE_SENSE; | 216 | rq->cmd_type = REQ_TYPE_SENSE; |
217 | rq->cmd_flags |= REQ_PREEMPT; | 217 | rq->cmd_flags |= REQ_PREEMPT; |
218 | 218 | ||
219 | /* NOTE! Save the failed command in "rq->buffer" */ | 219 | /* NOTE! Save the failed command in "rq->buffer" */ |
220 | rq->buffer = (void *) failed_command; | 220 | rq->buffer = (void *) failed_command; |
221 | 221 | ||
222 | ide_do_drive_cmd(drive, rq); | 222 | ide_do_drive_cmd(drive, rq); |
223 | } | 223 | } |
224 | 224 | ||
225 | static void cdrom_end_request(ide_drive_t *drive, int uptodate) | 225 | static void cdrom_end_request(ide_drive_t *drive, int uptodate) |
226 | { | 226 | { |
227 | struct request *rq = HWGROUP(drive)->rq; | 227 | struct request *rq = HWGROUP(drive)->rq; |
228 | int nsectors = rq->hard_cur_sectors; | 228 | int nsectors = rq->hard_cur_sectors; |
229 | 229 | ||
230 | if (blk_sense_request(rq) && uptodate) { | 230 | if (blk_sense_request(rq) && uptodate) { |
231 | /* | 231 | /* |
232 | * For REQ_TYPE_SENSE, "rq->buffer" points to the original | 232 | * For REQ_TYPE_SENSE, "rq->buffer" points to the original |
233 | * failed request | 233 | * failed request |
234 | */ | 234 | */ |
235 | struct request *failed = (struct request *) rq->buffer; | 235 | struct request *failed = (struct request *) rq->buffer; |
236 | struct cdrom_info *info = drive->driver_data; | 236 | struct cdrom_info *info = drive->driver_data; |
237 | void *sense = &info->sense_data; | 237 | void *sense = &info->sense_data; |
238 | unsigned long flags; | 238 | unsigned long flags; |
239 | 239 | ||
240 | if (failed) { | 240 | if (failed) { |
241 | if (failed->sense) { | 241 | if (failed->sense) { |
242 | sense = failed->sense; | 242 | sense = failed->sense; |
243 | failed->sense_len = rq->sense_len; | 243 | failed->sense_len = rq->sense_len; |
244 | } | 244 | } |
245 | cdrom_analyze_sense_data(drive, failed, sense); | 245 | cdrom_analyze_sense_data(drive, failed, sense); |
246 | /* | 246 | /* |
247 | * now end the failed request | 247 | * now end the failed request |
248 | */ | 248 | */ |
249 | if (blk_fs_request(failed)) { | 249 | if (blk_fs_request(failed)) { |
250 | if (ide_end_dequeued_request(drive, failed, 0, | 250 | if (ide_end_dequeued_request(drive, failed, 0, |
251 | failed->hard_nr_sectors)) | 251 | failed->hard_nr_sectors)) |
252 | BUG(); | 252 | BUG(); |
253 | } else { | 253 | } else { |
254 | spin_lock_irqsave(&ide_lock, flags); | 254 | spin_lock_irqsave(&ide_lock, flags); |
255 | if (__blk_end_request(failed, -EIO, | 255 | if (__blk_end_request(failed, -EIO, |
256 | failed->data_len)) | 256 | failed->data_len)) |
257 | BUG(); | 257 | BUG(); |
258 | spin_unlock_irqrestore(&ide_lock, flags); | 258 | spin_unlock_irqrestore(&ide_lock, flags); |
259 | } | 259 | } |
260 | } else | 260 | } else |
261 | cdrom_analyze_sense_data(drive, NULL, sense); | 261 | cdrom_analyze_sense_data(drive, NULL, sense); |
262 | } | 262 | } |
263 | 263 | ||
264 | if (!rq->current_nr_sectors && blk_fs_request(rq)) | 264 | if (!rq->current_nr_sectors && blk_fs_request(rq)) |
265 | uptodate = 1; | 265 | uptodate = 1; |
266 | /* make sure it's fully ended */ | 266 | /* make sure it's fully ended */ |
267 | if (blk_pc_request(rq)) | 267 | if (blk_pc_request(rq)) |
268 | nsectors = (rq->data_len + 511) >> 9; | 268 | nsectors = (rq->data_len + 511) >> 9; |
269 | if (!nsectors) | 269 | if (!nsectors) |
270 | nsectors = 1; | 270 | nsectors = 1; |
271 | 271 | ||
272 | ide_end_request(drive, uptodate, nsectors); | 272 | ide_end_request(drive, uptodate, nsectors); |
273 | } | 273 | } |
274 | 274 | ||
275 | static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 st) | 275 | static void ide_dump_status_no_sense(ide_drive_t *drive, const char *msg, u8 st) |
276 | { | 276 | { |
277 | if (st & 0x80) | 277 | if (st & 0x80) |
278 | return; | 278 | return; |
279 | ide_dump_status(drive, msg, st); | 279 | ide_dump_status(drive, msg, st); |
280 | } | 280 | } |
281 | 281 | ||
282 | /* | 282 | /* |
283 | * Returns: | 283 | * Returns: |
284 | * 0: if the request should be continued. | 284 | * 0: if the request should be continued. |
285 | * 1: if the request was ended. | 285 | * 1: if the request was ended. |
286 | */ | 286 | */ |
287 | static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) | 287 | static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret) |
288 | { | 288 | { |
289 | ide_hwif_t *hwif = drive->hwif; | 289 | ide_hwif_t *hwif = drive->hwif; |
290 | struct request *rq = hwif->hwgroup->rq; | 290 | struct request *rq = hwif->hwgroup->rq; |
291 | int stat, err, sense_key; | 291 | int stat, err, sense_key; |
292 | 292 | ||
293 | /* check for errors */ | 293 | /* check for errors */ |
294 | stat = hwif->tp_ops->read_status(hwif); | 294 | stat = hwif->tp_ops->read_status(hwif); |
295 | 295 | ||
296 | if (stat_ret) | 296 | if (stat_ret) |
297 | *stat_ret = stat; | 297 | *stat_ret = stat; |
298 | 298 | ||
299 | if (OK_STAT(stat, good_stat, BAD_R_STAT)) | 299 | if (OK_STAT(stat, good_stat, BAD_R_STAT)) |
300 | return 0; | 300 | return 0; |
301 | 301 | ||
302 | /* get the IDE error register */ | 302 | /* get the IDE error register */ |
303 | err = ide_read_error(drive); | 303 | err = ide_read_error(drive); |
304 | sense_key = err >> 4; | 304 | sense_key = err >> 4; |
305 | 305 | ||
306 | if (rq == NULL) { | 306 | if (rq == NULL) { |
307 | printk(KERN_ERR "%s: missing rq in %s\n", | 307 | printk(KERN_ERR "%s: missing rq in %s\n", |
308 | drive->name, __func__); | 308 | drive->name, __func__); |
309 | return 1; | 309 | return 1; |
310 | } | 310 | } |
311 | 311 | ||
312 | if (blk_sense_request(rq)) { | 312 | if (blk_sense_request(rq)) { |
313 | /* | 313 | /* |
314 | * We got an error trying to get sense info from the drive | 314 | * We got an error trying to get sense info from the drive |
315 | * (probably while trying to recover from a former error). | 315 | * (probably while trying to recover from a former error). |
316 | * Just give up. | 316 | * Just give up. |
317 | */ | 317 | */ |
318 | rq->cmd_flags |= REQ_FAILED; | 318 | rq->cmd_flags |= REQ_FAILED; |
319 | cdrom_end_request(drive, 0); | 319 | cdrom_end_request(drive, 0); |
320 | ide_error(drive, "request sense failure", stat); | 320 | ide_error(drive, "request sense failure", stat); |
321 | return 1; | 321 | return 1; |
322 | 322 | ||
323 | } else if (blk_pc_request(rq) || rq->cmd_type == REQ_TYPE_ATA_PC) { | 323 | } else if (blk_pc_request(rq) || rq->cmd_type == REQ_TYPE_ATA_PC) { |
324 | /* All other functions, except for READ. */ | 324 | /* All other functions, except for READ. */ |
325 | 325 | ||
326 | /* | 326 | /* |
327 | * if we have an error, pass back CHECK_CONDITION as the | 327 | * if we have an error, pass back CHECK_CONDITION as the |
328 | * scsi status byte | 328 | * scsi status byte |
329 | */ | 329 | */ |
330 | if (blk_pc_request(rq) && !rq->errors) | 330 | if (blk_pc_request(rq) && !rq->errors) |
331 | rq->errors = SAM_STAT_CHECK_CONDITION; | 331 | rq->errors = SAM_STAT_CHECK_CONDITION; |
332 | 332 | ||
333 | /* check for tray open */ | 333 | /* check for tray open */ |
334 | if (sense_key == NOT_READY) { | 334 | if (sense_key == NOT_READY) { |
335 | cdrom_saw_media_change(drive); | 335 | cdrom_saw_media_change(drive); |
336 | } else if (sense_key == UNIT_ATTENTION) { | 336 | } else if (sense_key == UNIT_ATTENTION) { |
337 | /* check for media change */ | 337 | /* check for media change */ |
338 | cdrom_saw_media_change(drive); | 338 | cdrom_saw_media_change(drive); |
339 | return 0; | 339 | return 0; |
340 | } else if (sense_key == ILLEGAL_REQUEST && | 340 | } else if (sense_key == ILLEGAL_REQUEST && |
341 | rq->cmd[0] == GPCMD_START_STOP_UNIT) { | 341 | rq->cmd[0] == GPCMD_START_STOP_UNIT) { |
342 | /* | 342 | /* |
343 | * Don't print error message for this condition-- | 343 | * Don't print error message for this condition-- |
344 | * SFF8090i indicates that 5/24/00 is the correct | 344 | * SFF8090i indicates that 5/24/00 is the correct |
345 | * response to a request to close the tray if the | 345 | * response to a request to close the tray if the |
346 | * drive doesn't have that capability. | 346 | * drive doesn't have that capability. |
347 | * cdrom_log_sense() knows this! | 347 | * cdrom_log_sense() knows this! |
348 | */ | 348 | */ |
349 | } else if (!(rq->cmd_flags & REQ_QUIET)) { | 349 | } else if (!(rq->cmd_flags & REQ_QUIET)) { |
350 | /* otherwise, print an error */ | 350 | /* otherwise, print an error */ |
351 | ide_dump_status(drive, "packet command error", stat); | 351 | ide_dump_status(drive, "packet command error", stat); |
352 | } | 352 | } |
353 | 353 | ||
354 | rq->cmd_flags |= REQ_FAILED; | 354 | rq->cmd_flags |= REQ_FAILED; |
355 | 355 | ||
356 | /* | 356 | /* |
357 | * instead of playing games with moving completions around, | 357 | * instead of playing games with moving completions around, |
358 | * remove failed request completely and end it when the | 358 | * remove failed request completely and end it when the |
359 | * request sense has completed | 359 | * request sense has completed |
360 | */ | 360 | */ |
361 | goto end_request; | 361 | goto end_request; |
362 | 362 | ||
363 | } else if (blk_fs_request(rq)) { | 363 | } else if (blk_fs_request(rq)) { |
364 | int do_end_request = 0; | 364 | int do_end_request = 0; |
365 | 365 | ||
366 | /* handle errors from READ and WRITE requests */ | 366 | /* handle errors from READ and WRITE requests */ |
367 | 367 | ||
368 | if (blk_noretry_request(rq)) | 368 | if (blk_noretry_request(rq)) |
369 | do_end_request = 1; | 369 | do_end_request = 1; |
370 | 370 | ||
371 | if (sense_key == NOT_READY) { | 371 | if (sense_key == NOT_READY) { |
372 | /* tray open */ | 372 | /* tray open */ |
373 | if (rq_data_dir(rq) == READ) { | 373 | if (rq_data_dir(rq) == READ) { |
374 | cdrom_saw_media_change(drive); | 374 | cdrom_saw_media_change(drive); |
375 | 375 | ||
376 | /* fail the request */ | 376 | /* fail the request */ |
377 | printk(KERN_ERR "%s: tray open\n", drive->name); | 377 | printk(KERN_ERR "%s: tray open\n", drive->name); |
378 | do_end_request = 1; | 378 | do_end_request = 1; |
379 | } else { | 379 | } else { |
380 | struct cdrom_info *info = drive->driver_data; | 380 | struct cdrom_info *info = drive->driver_data; |
381 | 381 | ||
382 | /* | 382 | /* |
383 | * Allow the drive 5 seconds to recover, some | 383 | * Allow the drive 5 seconds to recover, some |
384 | * devices will return this error while flushing | 384 | * devices will return this error while flushing |
385 | * data from cache. | 385 | * data from cache. |
386 | */ | 386 | */ |
387 | if (!rq->errors) | 387 | if (!rq->errors) |
388 | info->write_timeout = jiffies + | 388 | info->write_timeout = jiffies + |
389 | ATAPI_WAIT_WRITE_BUSY; | 389 | ATAPI_WAIT_WRITE_BUSY; |
390 | rq->errors = 1; | 390 | rq->errors = 1; |
391 | if (time_after(jiffies, info->write_timeout)) | 391 | if (time_after(jiffies, info->write_timeout)) |
392 | do_end_request = 1; | 392 | do_end_request = 1; |
393 | else { | 393 | else { |
394 | unsigned long flags; | 394 | unsigned long flags; |
395 | 395 | ||
396 | /* | 396 | /* |
397 | * take a breather relying on the unplug | 397 | * take a breather relying on the unplug |
398 | * timer to kick us again | 398 | * timer to kick us again |
399 | */ | 399 | */ |
400 | spin_lock_irqsave(&ide_lock, flags); | 400 | spin_lock_irqsave(&ide_lock, flags); |
401 | blk_plug_device(drive->queue); | 401 | blk_plug_device(drive->queue); |
402 | spin_unlock_irqrestore(&ide_lock, | 402 | spin_unlock_irqrestore(&ide_lock, |
403 | flags); | 403 | flags); |
404 | return 1; | 404 | return 1; |
405 | } | 405 | } |
406 | } | 406 | } |
407 | } else if (sense_key == UNIT_ATTENTION) { | 407 | } else if (sense_key == UNIT_ATTENTION) { |
408 | /* media change */ | 408 | /* media change */ |
409 | cdrom_saw_media_change(drive); | 409 | cdrom_saw_media_change(drive); |
410 | 410 | ||
411 | /* | 411 | /* |
412 | * Arrange to retry the request but be sure to give up | 412 | * Arrange to retry the request but be sure to give up |
413 | * if we've retried too many times. | 413 | * if we've retried too many times. |
414 | */ | 414 | */ |
415 | if (++rq->errors > ERROR_MAX) | 415 | if (++rq->errors > ERROR_MAX) |
416 | do_end_request = 1; | 416 | do_end_request = 1; |
417 | } else if (sense_key == ILLEGAL_REQUEST || | 417 | } else if (sense_key == ILLEGAL_REQUEST || |
418 | sense_key == DATA_PROTECT) { | 418 | sense_key == DATA_PROTECT) { |
419 | /* | 419 | /* |
420 | * No point in retrying after an illegal request or data | 420 | * No point in retrying after an illegal request or data |
421 | * protect error. | 421 | * protect error. |
422 | */ | 422 | */ |
423 | ide_dump_status_no_sense(drive, "command error", stat); | 423 | ide_dump_status_no_sense(drive, "command error", stat); |
424 | do_end_request = 1; | 424 | do_end_request = 1; |
425 | } else if (sense_key == MEDIUM_ERROR) { | 425 | } else if (sense_key == MEDIUM_ERROR) { |
426 | /* | 426 | /* |
427 | * No point in re-trying a zillion times on a bad | 427 | * No point in re-trying a zillion times on a bad |
428 | * sector. If we got here the error is not correctable. | 428 | * sector. If we got here the error is not correctable. |
429 | */ | 429 | */ |
430 | ide_dump_status_no_sense(drive, | 430 | ide_dump_status_no_sense(drive, |
431 | "media error (bad sector)", | 431 | "media error (bad sector)", |
432 | stat); | 432 | stat); |
433 | do_end_request = 1; | 433 | do_end_request = 1; |
434 | } else if (sense_key == BLANK_CHECK) { | 434 | } else if (sense_key == BLANK_CHECK) { |
435 | /* disk appears blank ?? */ | 435 | /* disk appears blank ?? */ |
436 | ide_dump_status_no_sense(drive, "media error (blank)", | 436 | ide_dump_status_no_sense(drive, "media error (blank)", |
437 | stat); | 437 | stat); |
438 | do_end_request = 1; | 438 | do_end_request = 1; |
439 | } else if ((err & ~ABRT_ERR) != 0) { | 439 | } else if ((err & ~ABRT_ERR) != 0) { |
440 | /* go to the default handler for other errors */ | 440 | /* go to the default handler for other errors */ |
441 | ide_error(drive, "cdrom_decode_status", stat); | 441 | ide_error(drive, "cdrom_decode_status", stat); |
442 | return 1; | 442 | return 1; |
443 | } else if ((++rq->errors > ERROR_MAX)) { | 443 | } else if ((++rq->errors > ERROR_MAX)) { |
444 | /* we've racked up too many retries, abort */ | 444 | /* we've racked up too many retries, abort */ |
445 | do_end_request = 1; | 445 | do_end_request = 1; |
446 | } | 446 | } |
447 | 447 | ||
448 | /* | 448 | /* |
449 | * End a request through request sense analysis when we have | 449 | * End a request through request sense analysis when we have |
450 | * sense data. We need this in order to perform end of media | 450 | * sense data. We need this in order to perform end of media |
451 | * processing. | 451 | * processing. |
452 | */ | 452 | */ |
453 | if (do_end_request) | 453 | if (do_end_request) |
454 | goto end_request; | 454 | goto end_request; |
455 | 455 | ||
456 | /* | 456 | /* |
457 | * If we got a CHECK_CONDITION status, queue | 457 | * If we got a CHECK_CONDITION status, queue |
458 | * a request sense command. | 458 | * a request sense command. |
459 | */ | 459 | */ |
460 | if (stat & ERR_STAT) | 460 | if (stat & ERR_STAT) |
461 | cdrom_queue_request_sense(drive, NULL, NULL); | 461 | cdrom_queue_request_sense(drive, NULL, NULL); |
462 | } else { | 462 | } else { |
463 | blk_dump_rq_flags(rq, "ide-cd: bad rq"); | 463 | blk_dump_rq_flags(rq, "ide-cd: bad rq"); |
464 | cdrom_end_request(drive, 0); | 464 | cdrom_end_request(drive, 0); |
465 | } | 465 | } |
466 | 466 | ||
467 | /* retry, or handle the next request */ | 467 | /* retry, or handle the next request */ |
468 | return 1; | 468 | return 1; |
469 | 469 | ||
470 | end_request: | 470 | end_request: |
471 | if (stat & ERR_STAT) { | 471 | if (stat & ERR_STAT) { |
472 | unsigned long flags; | 472 | unsigned long flags; |
473 | 473 | ||
474 | spin_lock_irqsave(&ide_lock, flags); | 474 | spin_lock_irqsave(&ide_lock, flags); |
475 | blkdev_dequeue_request(rq); | 475 | blkdev_dequeue_request(rq); |
476 | HWGROUP(drive)->rq = NULL; | 476 | HWGROUP(drive)->rq = NULL; |
477 | spin_unlock_irqrestore(&ide_lock, flags); | 477 | spin_unlock_irqrestore(&ide_lock, flags); |
478 | 478 | ||
479 | cdrom_queue_request_sense(drive, rq->sense, rq); | 479 | cdrom_queue_request_sense(drive, rq->sense, rq); |
480 | } else | 480 | } else |
481 | cdrom_end_request(drive, 0); | 481 | cdrom_end_request(drive, 0); |
482 | 482 | ||
483 | return 1; | 483 | return 1; |
484 | } | 484 | } |
485 | 485 | ||
486 | static int cdrom_timer_expiry(ide_drive_t *drive) | 486 | static int cdrom_timer_expiry(ide_drive_t *drive) |
487 | { | 487 | { |
488 | struct request *rq = HWGROUP(drive)->rq; | 488 | struct request *rq = HWGROUP(drive)->rq; |
489 | unsigned long wait = 0; | 489 | unsigned long wait = 0; |
490 | 490 | ||
491 | /* | 491 | /* |
492 | * Some commands are *slow* and normally take a long time to complete. | 492 | * Some commands are *slow* and normally take a long time to complete. |
493 | * Usually we can use the ATAPI "disconnect" to bypass this, but not all | 493 | * Usually we can use the ATAPI "disconnect" to bypass this, but not all |
494 | * commands/drives support that. Let ide_timer_expiry keep polling us | 494 | * commands/drives support that. Let ide_timer_expiry keep polling us |
495 | * for these. | 495 | * for these. |
496 | */ | 496 | */ |
497 | switch (rq->cmd[0]) { | 497 | switch (rq->cmd[0]) { |
498 | case GPCMD_BLANK: | 498 | case GPCMD_BLANK: |
499 | case GPCMD_FORMAT_UNIT: | 499 | case GPCMD_FORMAT_UNIT: |
500 | case GPCMD_RESERVE_RZONE_TRACK: | 500 | case GPCMD_RESERVE_RZONE_TRACK: |
501 | case GPCMD_CLOSE_TRACK: | 501 | case GPCMD_CLOSE_TRACK: |
502 | case GPCMD_FLUSH_CACHE: | 502 | case GPCMD_FLUSH_CACHE: |
503 | wait = ATAPI_WAIT_PC; | 503 | wait = ATAPI_WAIT_PC; |
504 | break; | 504 | break; |
505 | default: | 505 | default: |
506 | if (!(rq->cmd_flags & REQ_QUIET)) | 506 | if (!(rq->cmd_flags & REQ_QUIET)) |
507 | printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", | 507 | printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n", |
508 | rq->cmd[0]); | 508 | rq->cmd[0]); |
509 | wait = 0; | 509 | wait = 0; |
510 | break; | 510 | break; |
511 | } | 511 | } |
512 | return wait; | 512 | return wait; |
513 | } | 513 | } |
514 | 514 | ||
515 | /* | 515 | /* |
516 | * Set up the device registers for transferring a packet command on DEV, | 516 | * Set up the device registers for transferring a packet command on DEV, |
517 | * expecting to later transfer XFERLEN bytes. HANDLER is the routine | 517 | * expecting to later transfer XFERLEN bytes. HANDLER is the routine |
518 | * which actually transfers the command to the drive. If this is a | 518 | * which actually transfers the command to the drive. If this is a |
519 | * drq_interrupt device, this routine will arrange for HANDLER to be | 519 | * drq_interrupt device, this routine will arrange for HANDLER to be |
520 | * called when the interrupt from the drive arrives. Otherwise, HANDLER | 520 | * called when the interrupt from the drive arrives. Otherwise, HANDLER |
521 | * will be called immediately after the drive is prepared for the transfer. | 521 | * will be called immediately after the drive is prepared for the transfer. |
522 | */ | 522 | */ |
523 | static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive, | 523 | static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive, |
524 | int xferlen, | 524 | int xferlen, |
525 | ide_handler_t *handler) | 525 | ide_handler_t *handler) |
526 | { | 526 | { |
527 | struct cdrom_info *info = drive->driver_data; | 527 | struct cdrom_info *info = drive->driver_data; |
528 | ide_hwif_t *hwif = drive->hwif; | 528 | ide_hwif_t *hwif = drive->hwif; |
529 | 529 | ||
530 | /* FIXME: for Virtual DMA we must check harder */ | 530 | /* FIXME: for Virtual DMA we must check harder */ |
531 | if (info->dma) | 531 | if (info->dma) |
532 | info->dma = !hwif->dma_ops->dma_setup(drive); | 532 | info->dma = !hwif->dma_ops->dma_setup(drive); |
533 | 533 | ||
534 | /* set up the controller registers */ | 534 | /* set up the controller registers */ |
535 | ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL, | 535 | ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL, |
536 | xferlen, info->dma); | 536 | xferlen, info->dma); |
537 | 537 | ||
538 | if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { | 538 | if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { |
539 | /* waiting for CDB interrupt, not DMA yet. */ | 539 | /* waiting for CDB interrupt, not DMA yet. */ |
540 | if (info->dma) | 540 | if (info->dma) |
541 | drive->waiting_for_dma = 0; | 541 | drive->waiting_for_dma = 0; |
542 | 542 | ||
543 | /* packet command */ | 543 | /* packet command */ |
544 | ide_execute_command(drive, WIN_PACKETCMD, handler, | 544 | ide_execute_command(drive, WIN_PACKETCMD, handler, |
545 | ATAPI_WAIT_PC, cdrom_timer_expiry); | 545 | ATAPI_WAIT_PC, cdrom_timer_expiry); |
546 | return ide_started; | 546 | return ide_started; |
547 | } else { | 547 | } else { |
548 | ide_execute_pkt_cmd(drive); | 548 | ide_execute_pkt_cmd(drive); |
549 | 549 | ||
550 | return (*handler) (drive); | 550 | return (*handler) (drive); |
551 | } | 551 | } |
552 | } | 552 | } |
553 | 553 | ||
554 | /* | 554 | /* |
555 | * Send a packet command to DRIVE described by CMD_BUF and CMD_LEN. The device | 555 | * Send a packet command to DRIVE described by CMD_BUF and CMD_LEN. The device |
556 | * registers must have already been prepared by cdrom_start_packet_command. | 556 | * registers must have already been prepared by cdrom_start_packet_command. |
557 | * HANDLER is the interrupt handler to call when the command completes or | 557 | * HANDLER is the interrupt handler to call when the command completes or |
558 | * there's data ready. | 558 | * there's data ready. |
559 | */ | 559 | */ |
560 | #define ATAPI_MIN_CDB_BYTES 12 | 560 | #define ATAPI_MIN_CDB_BYTES 12 |
561 | static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive, | 561 | static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive, |
562 | struct request *rq, | 562 | struct request *rq, |
563 | ide_handler_t *handler) | 563 | ide_handler_t *handler) |
564 | { | 564 | { |
565 | ide_hwif_t *hwif = drive->hwif; | 565 | ide_hwif_t *hwif = drive->hwif; |
566 | int cmd_len; | 566 | int cmd_len; |
567 | struct cdrom_info *info = drive->driver_data; | 567 | struct cdrom_info *info = drive->driver_data; |
568 | ide_startstop_t startstop; | 568 | ide_startstop_t startstop; |
569 | 569 | ||
570 | if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { | 570 | if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { |
571 | /* | 571 | /* |
572 | * Here we should have been called after receiving an interrupt | 572 | * Here we should have been called after receiving an interrupt |
573 | * from the device. DRQ should how be set. | 573 | * from the device. DRQ should how be set. |
574 | */ | 574 | */ |
575 | 575 | ||
576 | /* check for errors */ | 576 | /* check for errors */ |
577 | if (cdrom_decode_status(drive, DRQ_STAT, NULL)) | 577 | if (cdrom_decode_status(drive, DRQ_STAT, NULL)) |
578 | return ide_stopped; | 578 | return ide_stopped; |
579 | 579 | ||
580 | /* ok, next interrupt will be DMA interrupt */ | 580 | /* ok, next interrupt will be DMA interrupt */ |
581 | if (info->dma) | 581 | if (info->dma) |
582 | drive->waiting_for_dma = 1; | 582 | drive->waiting_for_dma = 1; |
583 | } else { | 583 | } else { |
584 | /* otherwise, we must wait for DRQ to get set */ | 584 | /* otherwise, we must wait for DRQ to get set */ |
585 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, | 585 | if (ide_wait_stat(&startstop, drive, DRQ_STAT, |
586 | BUSY_STAT, WAIT_READY)) | 586 | BUSY_STAT, WAIT_READY)) |
587 | return startstop; | 587 | return startstop; |
588 | } | 588 | } |
589 | 589 | ||
590 | /* arm the interrupt handler */ | 590 | /* arm the interrupt handler */ |
591 | ide_set_handler(drive, handler, rq->timeout, cdrom_timer_expiry); | 591 | ide_set_handler(drive, handler, rq->timeout, cdrom_timer_expiry); |
592 | 592 | ||
593 | /* ATAPI commands get padded out to 12 bytes minimum */ | 593 | /* ATAPI commands get padded out to 12 bytes minimum */ |
594 | cmd_len = COMMAND_SIZE(rq->cmd[0]); | 594 | cmd_len = COMMAND_SIZE(rq->cmd[0]); |
595 | if (cmd_len < ATAPI_MIN_CDB_BYTES) | 595 | if (cmd_len < ATAPI_MIN_CDB_BYTES) |
596 | cmd_len = ATAPI_MIN_CDB_BYTES; | 596 | cmd_len = ATAPI_MIN_CDB_BYTES; |
597 | 597 | ||
598 | /* send the command to the device */ | 598 | /* send the command to the device */ |
599 | hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len); | 599 | hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len); |
600 | 600 | ||
601 | /* start the DMA if need be */ | 601 | /* start the DMA if need be */ |
602 | if (info->dma) | 602 | if (info->dma) |
603 | hwif->dma_ops->dma_start(drive); | 603 | hwif->dma_ops->dma_start(drive); |
604 | 604 | ||
605 | return ide_started; | 605 | return ide_started; |
606 | } | 606 | } |
607 | 607 | ||
608 | /* | 608 | /* |
609 | * Check the contents of the interrupt reason register from the cdrom | 609 | * Check the contents of the interrupt reason register from the cdrom |
610 | * and attempt to recover if there are problems. Returns 0 if everything's | 610 | * and attempt to recover if there are problems. Returns 0 if everything's |
611 | * ok; nonzero if the request has been terminated. | 611 | * ok; nonzero if the request has been terminated. |
612 | */ | 612 | */ |
613 | static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq, | 613 | static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq, |
614 | int len, int ireason, int rw) | 614 | int len, int ireason, int rw) |
615 | { | 615 | { |
616 | ide_hwif_t *hwif = drive->hwif; | 616 | ide_hwif_t *hwif = drive->hwif; |
617 | 617 | ||
618 | /* | 618 | /* |
619 | * ireason == 0: the drive wants to receive data from us | 619 | * ireason == 0: the drive wants to receive data from us |
620 | * ireason == 2: the drive is expecting to transfer data to us | 620 | * ireason == 2: the drive is expecting to transfer data to us |
621 | */ | 621 | */ |
622 | if (ireason == (!rw << 1)) | 622 | if (ireason == (!rw << 1)) |
623 | return 0; | 623 | return 0; |
624 | else if (ireason == (rw << 1)) { | 624 | else if (ireason == (rw << 1)) { |
625 | 625 | ||
626 | /* whoops... */ | 626 | /* whoops... */ |
627 | printk(KERN_ERR "%s: %s: wrong transfer direction!\n", | 627 | printk(KERN_ERR "%s: %s: wrong transfer direction!\n", |
628 | drive->name, __func__); | 628 | drive->name, __func__); |
629 | 629 | ||
630 | ide_pad_transfer(drive, rw, len); | 630 | ide_pad_transfer(drive, rw, len); |
631 | } else if (rw == 0 && ireason == 1) { | 631 | } else if (rw == 0 && ireason == 1) { |
632 | /* | 632 | /* |
633 | * Some drives (ASUS) seem to tell us that status info is | 633 | * Some drives (ASUS) seem to tell us that status info is |
634 | * available. Just get it and ignore. | 634 | * available. Just get it and ignore. |
635 | */ | 635 | */ |
636 | (void)hwif->tp_ops->read_status(hwif); | 636 | (void)hwif->tp_ops->read_status(hwif); |
637 | return 0; | 637 | return 0; |
638 | } else { | 638 | } else { |
639 | /* drive wants a command packet, or invalid ireason... */ | 639 | /* drive wants a command packet, or invalid ireason... */ |
640 | printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n", | 640 | printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n", |
641 | drive->name, __func__, ireason); | 641 | drive->name, __func__, ireason); |
642 | } | 642 | } |
643 | 643 | ||
644 | if (rq->cmd_type == REQ_TYPE_ATA_PC) | 644 | if (rq->cmd_type == REQ_TYPE_ATA_PC) |
645 | rq->cmd_flags |= REQ_FAILED; | 645 | rq->cmd_flags |= REQ_FAILED; |
646 | 646 | ||
647 | cdrom_end_request(drive, 0); | 647 | cdrom_end_request(drive, 0); |
648 | return -1; | 648 | return -1; |
649 | } | 649 | } |
650 | 650 | ||
651 | /* | 651 | /* |
652 | * Assume that the drive will always provide data in multiples of at least | 652 | * Assume that the drive will always provide data in multiples of at least |
653 | * SECTOR_SIZE, as it gets hairy to keep track of the transfers otherwise. | 653 | * SECTOR_SIZE, as it gets hairy to keep track of the transfers otherwise. |
654 | */ | 654 | */ |
655 | static int ide_cd_check_transfer_size(ide_drive_t *drive, int len) | 655 | static int ide_cd_check_transfer_size(ide_drive_t *drive, int len) |
656 | { | 656 | { |
657 | if ((len % SECTOR_SIZE) == 0) | 657 | if ((len % SECTOR_SIZE) == 0) |
658 | return 0; | 658 | return 0; |
659 | 659 | ||
660 | printk(KERN_ERR "%s: %s: Bad transfer size %d\n", | 660 | printk(KERN_ERR "%s: %s: Bad transfer size %d\n", |
661 | drive->name, __func__, len); | 661 | drive->name, __func__, len); |
662 | 662 | ||
663 | if (drive->atapi_flags & IDE_AFLAG_LIMIT_NFRAMES) | 663 | if (drive->atapi_flags & IDE_AFLAG_LIMIT_NFRAMES) |
664 | printk(KERN_ERR " This drive is not supported by " | 664 | printk(KERN_ERR " This drive is not supported by " |
665 | "this version of the driver\n"); | 665 | "this version of the driver\n"); |
666 | else { | 666 | else { |
667 | printk(KERN_ERR " Trying to limit transfer sizes\n"); | 667 | printk(KERN_ERR " Trying to limit transfer sizes\n"); |
668 | drive->atapi_flags |= IDE_AFLAG_LIMIT_NFRAMES; | 668 | drive->atapi_flags |= IDE_AFLAG_LIMIT_NFRAMES; |
669 | } | 669 | } |
670 | 670 | ||
671 | return 1; | 671 | return 1; |
672 | } | 672 | } |
673 | 673 | ||
674 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *); | 674 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *); |
675 | 675 | ||
676 | static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive, | 676 | static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive, |
677 | struct request *rq) | 677 | struct request *rq) |
678 | { | 678 | { |
679 | if (rq_data_dir(rq) == READ) { | 679 | if (rq_data_dir(rq) == READ) { |
680 | unsigned short sectors_per_frame = | 680 | unsigned short sectors_per_frame = |
681 | queue_hardsect_size(drive->queue) >> SECTOR_BITS; | 681 | queue_hardsect_size(drive->queue) >> SECTOR_BITS; |
682 | int nskip = rq->sector & (sectors_per_frame - 1); | 682 | int nskip = rq->sector & (sectors_per_frame - 1); |
683 | 683 | ||
684 | /* | 684 | /* |
685 | * If the requested sector doesn't start on a frame boundary, | 685 | * If the requested sector doesn't start on a frame boundary, |
686 | * we must adjust the start of the transfer so that it does, | 686 | * we must adjust the start of the transfer so that it does, |
687 | * and remember to skip the first few sectors. | 687 | * and remember to skip the first few sectors. |
688 | * | 688 | * |
689 | * If the rq->current_nr_sectors field is larger than the size | 689 | * If the rq->current_nr_sectors field is larger than the size |
690 | * of the buffer, it will mean that we're to skip a number of | 690 | * of the buffer, it will mean that we're to skip a number of |
691 | * sectors equal to the amount by which rq->current_nr_sectors | 691 | * sectors equal to the amount by which rq->current_nr_sectors |
692 | * is larger than the buffer size. | 692 | * is larger than the buffer size. |
693 | */ | 693 | */ |
694 | if (nskip > 0) { | 694 | if (nskip > 0) { |
695 | /* sanity check... */ | 695 | /* sanity check... */ |
696 | if (rq->current_nr_sectors != | 696 | if (rq->current_nr_sectors != |
697 | bio_cur_sectors(rq->bio)) { | 697 | bio_cur_sectors(rq->bio)) { |
698 | printk(KERN_ERR "%s: %s: buffer botch (%u)\n", | 698 | printk(KERN_ERR "%s: %s: buffer botch (%u)\n", |
699 | drive->name, __func__, | 699 | drive->name, __func__, |
700 | rq->current_nr_sectors); | 700 | rq->current_nr_sectors); |
701 | cdrom_end_request(drive, 0); | 701 | cdrom_end_request(drive, 0); |
702 | return ide_stopped; | 702 | return ide_stopped; |
703 | } | 703 | } |
704 | rq->current_nr_sectors += nskip; | 704 | rq->current_nr_sectors += nskip; |
705 | } | 705 | } |
706 | } | 706 | } |
707 | #if 0 | 707 | #if 0 |
708 | else | 708 | else |
709 | /* the immediate bit */ | 709 | /* the immediate bit */ |
710 | rq->cmd[1] = 1 << 3; | 710 | rq->cmd[1] = 1 << 3; |
711 | #endif | 711 | #endif |
712 | /* set up the command */ | 712 | /* set up the command */ |
713 | rq->timeout = ATAPI_WAIT_PC; | 713 | rq->timeout = ATAPI_WAIT_PC; |
714 | 714 | ||
715 | return ide_started; | 715 | return ide_started; |
716 | } | 716 | } |
717 | 717 | ||
718 | /* | 718 | /* |
719 | * Routine to send a read/write packet command to the drive. This is usually | 719 | * Routine to send a read/write packet command to the drive. This is usually |
720 | * called directly from cdrom_start_{read,write}(). However, for drq_interrupt | 720 | * called directly from cdrom_start_{read,write}(). However, for drq_interrupt |
721 | * devices, it is called from an interrupt when the drive is ready to accept | 721 | * devices, it is called from an interrupt when the drive is ready to accept |
722 | * the command. | 722 | * the command. |
723 | */ | 723 | */ |
724 | static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) | 724 | static ide_startstop_t cdrom_start_rw_cont(ide_drive_t *drive) |
725 | { | 725 | { |
726 | struct request *rq = drive->hwif->hwgroup->rq; | 726 | struct request *rq = drive->hwif->hwgroup->rq; |
727 | 727 | ||
728 | /* send the command to the drive and return */ | 728 | /* send the command to the drive and return */ |
729 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); | 729 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); |
730 | } | 730 | } |
731 | 731 | ||
732 | #define IDECD_SEEK_THRESHOLD (1000) /* 1000 blocks */ | 732 | #define IDECD_SEEK_THRESHOLD (1000) /* 1000 blocks */ |
733 | #define IDECD_SEEK_TIMER (5 * WAIT_MIN_SLEEP) /* 100 ms */ | 733 | #define IDECD_SEEK_TIMER (5 * WAIT_MIN_SLEEP) /* 100 ms */ |
734 | #define IDECD_SEEK_TIMEOUT (2 * WAIT_CMD) /* 20 sec */ | 734 | #define IDECD_SEEK_TIMEOUT (2 * WAIT_CMD) /* 20 sec */ |
735 | 735 | ||
736 | static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive) | 736 | static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive) |
737 | { | 737 | { |
738 | struct cdrom_info *info = drive->driver_data; | 738 | struct cdrom_info *info = drive->driver_data; |
739 | int stat; | 739 | int stat; |
740 | static int retry = 10; | 740 | static int retry = 10; |
741 | 741 | ||
742 | if (cdrom_decode_status(drive, 0, &stat)) | 742 | if (cdrom_decode_status(drive, 0, &stat)) |
743 | return ide_stopped; | 743 | return ide_stopped; |
744 | 744 | ||
745 | drive->atapi_flags |= IDE_AFLAG_SEEKING; | 745 | drive->atapi_flags |= IDE_AFLAG_SEEKING; |
746 | 746 | ||
747 | if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) { | 747 | if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) { |
748 | if (--retry == 0) | 748 | if (--retry == 0) |
749 | drive->dsc_overlap = 0; | 749 | drive->dsc_overlap = 0; |
750 | } | 750 | } |
751 | return ide_stopped; | 751 | return ide_stopped; |
752 | } | 752 | } |
753 | 753 | ||
754 | static void ide_cd_prepare_seek_request(ide_drive_t *drive, struct request *rq) | 754 | static void ide_cd_prepare_seek_request(ide_drive_t *drive, struct request *rq) |
755 | { | 755 | { |
756 | sector_t frame = rq->sector; | 756 | sector_t frame = rq->sector; |
757 | 757 | ||
758 | sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS); | 758 | sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS); |
759 | 759 | ||
760 | memset(rq->cmd, 0, BLK_MAX_CDB); | 760 | memset(rq->cmd, 0, BLK_MAX_CDB); |
761 | rq->cmd[0] = GPCMD_SEEK; | 761 | rq->cmd[0] = GPCMD_SEEK; |
762 | put_unaligned(cpu_to_be32(frame), (unsigned int *) &rq->cmd[2]); | 762 | put_unaligned(cpu_to_be32(frame), (unsigned int *) &rq->cmd[2]); |
763 | 763 | ||
764 | rq->timeout = ATAPI_WAIT_PC; | 764 | rq->timeout = ATAPI_WAIT_PC; |
765 | } | 765 | } |
766 | 766 | ||
767 | static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive) | 767 | static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive) |
768 | { | 768 | { |
769 | struct request *rq = drive->hwif->hwgroup->rq; | 769 | struct request *rq = drive->hwif->hwgroup->rq; |
770 | 770 | ||
771 | return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr); | 771 | return cdrom_transfer_packet_command(drive, rq, &cdrom_seek_intr); |
772 | } | 772 | } |
773 | 773 | ||
774 | /* | 774 | /* |
775 | * Fix up a possibly partially-processed request so that we can start it over | 775 | * Fix up a possibly partially-processed request so that we can start it over |
776 | * entirely, or even put it back on the request queue. | 776 | * entirely, or even put it back on the request queue. |
777 | */ | 777 | */ |
778 | static void restore_request(struct request *rq) | 778 | static void restore_request(struct request *rq) |
779 | { | 779 | { |
780 | if (rq->buffer != bio_data(rq->bio)) { | 780 | if (rq->buffer != bio_data(rq->bio)) { |
781 | sector_t n = | 781 | sector_t n = |
782 | (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE; | 782 | (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE; |
783 | 783 | ||
784 | rq->buffer = bio_data(rq->bio); | 784 | rq->buffer = bio_data(rq->bio); |
785 | rq->nr_sectors += n; | 785 | rq->nr_sectors += n; |
786 | rq->sector -= n; | 786 | rq->sector -= n; |
787 | } | 787 | } |
788 | rq->current_nr_sectors = bio_cur_sectors(rq->bio); | 788 | rq->current_nr_sectors = bio_cur_sectors(rq->bio); |
789 | rq->hard_cur_sectors = rq->current_nr_sectors; | 789 | rq->hard_cur_sectors = rq->current_nr_sectors; |
790 | rq->hard_nr_sectors = rq->nr_sectors; | 790 | rq->hard_nr_sectors = rq->nr_sectors; |
791 | rq->hard_sector = rq->sector; | 791 | rq->hard_sector = rq->sector; |
792 | rq->q->prep_rq_fn(rq->q, rq); | 792 | rq->q->prep_rq_fn(rq->q, rq); |
793 | } | 793 | } |
794 | 794 | ||
795 | /* | 795 | /* |
796 | * All other packet commands. | 796 | * All other packet commands. |
797 | */ | 797 | */ |
798 | static void ide_cd_request_sense_fixup(struct request *rq) | 798 | static void ide_cd_request_sense_fixup(struct request *rq) |
799 | { | 799 | { |
800 | /* | 800 | /* |
801 | * Some of the trailing request sense fields are optional, | 801 | * Some of the trailing request sense fields are optional, |
802 | * and some drives don't send them. Sigh. | 802 | * and some drives don't send them. Sigh. |
803 | */ | 803 | */ |
804 | if (rq->cmd[0] == GPCMD_REQUEST_SENSE && | 804 | if (rq->cmd[0] == GPCMD_REQUEST_SENSE && |
805 | rq->data_len > 0 && rq->data_len <= 5) | 805 | rq->data_len > 0 && rq->data_len <= 5) |
806 | while (rq->data_len > 0) { | 806 | while (rq->data_len > 0) { |
807 | *(u8 *)rq->data++ = 0; | 807 | *(u8 *)rq->data++ = 0; |
808 | --rq->data_len; | 808 | --rq->data_len; |
809 | } | 809 | } |
810 | } | 810 | } |
811 | 811 | ||
812 | int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd, | 812 | int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd, |
813 | int write, void *buffer, unsigned *bufflen, | 813 | int write, void *buffer, unsigned *bufflen, |
814 | struct request_sense *sense, int timeout, | 814 | struct request_sense *sense, int timeout, |
815 | unsigned int cmd_flags) | 815 | unsigned int cmd_flags) |
816 | { | 816 | { |
817 | struct cdrom_info *info = drive->driver_data; | 817 | struct cdrom_info *info = drive->driver_data; |
818 | struct request_sense local_sense; | 818 | struct request_sense local_sense; |
819 | int retries = 10; | 819 | int retries = 10; |
820 | unsigned int flags = 0; | 820 | unsigned int flags = 0; |
821 | 821 | ||
822 | if (!sense) | 822 | if (!sense) |
823 | sense = &local_sense; | 823 | sense = &local_sense; |
824 | 824 | ||
825 | /* start of retry loop */ | 825 | /* start of retry loop */ |
826 | do { | 826 | do { |
827 | struct request *rq; | 827 | struct request *rq; |
828 | int error; | 828 | int error; |
829 | 829 | ||
830 | rq = blk_get_request(drive->queue, write, __GFP_WAIT); | 830 | rq = blk_get_request(drive->queue, write, __GFP_WAIT); |
831 | 831 | ||
832 | memcpy(rq->cmd, cmd, BLK_MAX_CDB); | 832 | memcpy(rq->cmd, cmd, BLK_MAX_CDB); |
833 | rq->cmd_type = REQ_TYPE_ATA_PC; | 833 | rq->cmd_type = REQ_TYPE_ATA_PC; |
834 | rq->sense = sense; | 834 | rq->sense = sense; |
835 | rq->cmd_flags |= cmd_flags; | 835 | rq->cmd_flags |= cmd_flags; |
836 | rq->timeout = timeout; | 836 | rq->timeout = timeout; |
837 | if (buffer) { | 837 | if (buffer) { |
838 | rq->data = buffer; | 838 | rq->data = buffer; |
839 | rq->data_len = *bufflen; | 839 | rq->data_len = *bufflen; |
840 | } | 840 | } |
841 | 841 | ||
842 | error = blk_execute_rq(drive->queue, info->disk, rq, 0); | 842 | error = blk_execute_rq(drive->queue, info->disk, rq, 0); |
843 | 843 | ||
844 | if (buffer) | 844 | if (buffer) |
845 | *bufflen = rq->data_len; | 845 | *bufflen = rq->data_len; |
846 | 846 | ||
847 | flags = rq->cmd_flags; | 847 | flags = rq->cmd_flags; |
848 | blk_put_request(rq); | 848 | blk_put_request(rq); |
849 | 849 | ||
850 | /* | 850 | /* |
851 | * FIXME: we should probably abort/retry or something in case of | 851 | * FIXME: we should probably abort/retry or something in case of |
852 | * failure. | 852 | * failure. |
853 | */ | 853 | */ |
854 | if (flags & REQ_FAILED) { | 854 | if (flags & REQ_FAILED) { |
855 | /* | 855 | /* |
856 | * The request failed. Retry if it was due to a unit | 856 | * The request failed. Retry if it was due to a unit |
857 | * attention status (usually means media was changed). | 857 | * attention status (usually means media was changed). |
858 | */ | 858 | */ |
859 | struct request_sense *reqbuf = sense; | 859 | struct request_sense *reqbuf = sense; |
860 | 860 | ||
861 | if (reqbuf->sense_key == UNIT_ATTENTION) | 861 | if (reqbuf->sense_key == UNIT_ATTENTION) |
862 | cdrom_saw_media_change(drive); | 862 | cdrom_saw_media_change(drive); |
863 | else if (reqbuf->sense_key == NOT_READY && | 863 | else if (reqbuf->sense_key == NOT_READY && |
864 | reqbuf->asc == 4 && reqbuf->ascq != 4) { | 864 | reqbuf->asc == 4 && reqbuf->ascq != 4) { |
865 | /* | 865 | /* |
866 | * The drive is in the process of loading | 866 | * The drive is in the process of loading |
867 | * a disk. Retry, but wait a little to give | 867 | * a disk. Retry, but wait a little to give |
868 | * the drive time to complete the load. | 868 | * the drive time to complete the load. |
869 | */ | 869 | */ |
870 | ssleep(2); | 870 | ssleep(2); |
871 | } else { | 871 | } else { |
872 | /* otherwise, don't retry */ | 872 | /* otherwise, don't retry */ |
873 | retries = 0; | 873 | retries = 0; |
874 | } | 874 | } |
875 | --retries; | 875 | --retries; |
876 | } | 876 | } |
877 | 877 | ||
878 | /* end of retry loop */ | 878 | /* end of retry loop */ |
879 | } while ((flags & REQ_FAILED) && retries >= 0); | 879 | } while ((flags & REQ_FAILED) && retries >= 0); |
880 | 880 | ||
881 | /* return an error if the command failed */ | 881 | /* return an error if the command failed */ |
882 | return (flags & REQ_FAILED) ? -EIO : 0; | 882 | return (flags & REQ_FAILED) ? -EIO : 0; |
883 | } | 883 | } |
884 | 884 | ||
885 | /* | 885 | /* |
886 | * Called from blk_end_request_callback() after the data of the request is | 886 | * Called from blk_end_request_callback() after the data of the request is |
887 | * completed and before the request itself is completed. By returning value '1', | 887 | * completed and before the request itself is completed. By returning value '1', |
888 | * blk_end_request_callback() returns immediately without completing it. | 888 | * blk_end_request_callback() returns immediately without completing it. |
889 | */ | 889 | */ |
890 | static int cdrom_newpc_intr_dummy_cb(struct request *rq) | 890 | static int cdrom_newpc_intr_dummy_cb(struct request *rq) |
891 | { | 891 | { |
892 | return 1; | 892 | return 1; |
893 | } | 893 | } |
894 | 894 | ||
895 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) | 895 | static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) |
896 | { | 896 | { |
897 | ide_hwif_t *hwif = drive->hwif; | 897 | ide_hwif_t *hwif = drive->hwif; |
898 | struct cdrom_info *info = drive->driver_data; | 898 | struct cdrom_info *info = drive->driver_data; |
899 | struct request *rq = HWGROUP(drive)->rq; | 899 | struct request *rq = HWGROUP(drive)->rq; |
900 | xfer_func_t *xferfunc; | 900 | xfer_func_t *xferfunc; |
901 | ide_expiry_t *expiry = NULL; | 901 | ide_expiry_t *expiry = NULL; |
902 | int dma_error = 0, dma, stat, thislen, uptodate = 0; | 902 | int dma_error = 0, dma, stat, thislen, uptodate = 0; |
903 | int write = (rq_data_dir(rq) == WRITE) ? 1 : 0; | 903 | int write = (rq_data_dir(rq) == WRITE) ? 1 : 0; |
904 | unsigned int timeout; | 904 | unsigned int timeout; |
905 | u16 len; | 905 | u16 len; |
906 | u8 ireason; | 906 | u8 ireason; |
907 | 907 | ||
908 | /* check for errors */ | 908 | /* check for errors */ |
909 | dma = info->dma; | 909 | dma = info->dma; |
910 | if (dma) { | 910 | if (dma) { |
911 | info->dma = 0; | 911 | info->dma = 0; |
912 | dma_error = hwif->dma_ops->dma_end(drive); | 912 | dma_error = hwif->dma_ops->dma_end(drive); |
913 | if (dma_error) { | 913 | if (dma_error) { |
914 | printk(KERN_ERR "%s: DMA %s error\n", drive->name, | 914 | printk(KERN_ERR "%s: DMA %s error\n", drive->name, |
915 | write ? "write" : "read"); | 915 | write ? "write" : "read"); |
916 | ide_dma_off(drive); | 916 | ide_dma_off(drive); |
917 | } | 917 | } |
918 | } | 918 | } |
919 | 919 | ||
920 | if (cdrom_decode_status(drive, 0, &stat)) | 920 | if (cdrom_decode_status(drive, 0, &stat)) |
921 | return ide_stopped; | 921 | return ide_stopped; |
922 | 922 | ||
923 | /* using dma, transfer is complete now */ | 923 | /* using dma, transfer is complete now */ |
924 | if (dma) { | 924 | if (dma) { |
925 | if (dma_error) | 925 | if (dma_error) |
926 | return ide_error(drive, "dma error", stat); | 926 | return ide_error(drive, "dma error", stat); |
927 | if (blk_fs_request(rq)) { | 927 | if (blk_fs_request(rq)) { |
928 | ide_end_request(drive, 1, rq->nr_sectors); | 928 | ide_end_request(drive, 1, rq->nr_sectors); |
929 | return ide_stopped; | 929 | return ide_stopped; |
930 | } | 930 | } |
931 | goto end_request; | 931 | goto end_request; |
932 | } | 932 | } |
933 | 933 | ||
934 | ide_read_bcount_and_ireason(drive, &len, &ireason); | 934 | ide_read_bcount_and_ireason(drive, &len, &ireason); |
935 | 935 | ||
936 | thislen = blk_fs_request(rq) ? len : rq->data_len; | 936 | thislen = blk_fs_request(rq) ? len : rq->data_len; |
937 | if (thislen > len) | 937 | if (thislen > len) |
938 | thislen = len; | 938 | thislen = len; |
939 | 939 | ||
940 | /* If DRQ is clear, the command has completed. */ | 940 | /* If DRQ is clear, the command has completed. */ |
941 | if ((stat & DRQ_STAT) == 0) { | 941 | if ((stat & DRQ_STAT) == 0) { |
942 | if (blk_fs_request(rq)) { | 942 | if (blk_fs_request(rq)) { |
943 | /* | 943 | /* |
944 | * If we're not done reading/writing, complain. | 944 | * If we're not done reading/writing, complain. |
945 | * Otherwise, complete the command normally. | 945 | * Otherwise, complete the command normally. |
946 | */ | 946 | */ |
947 | uptodate = 1; | 947 | uptodate = 1; |
948 | if (rq->current_nr_sectors > 0) { | 948 | if (rq->current_nr_sectors > 0) { |
949 | printk(KERN_ERR "%s: %s: data underrun " | 949 | printk(KERN_ERR "%s: %s: data underrun " |
950 | "(%d blocks)\n", | 950 | "(%d blocks)\n", |
951 | drive->name, __func__, | 951 | drive->name, __func__, |
952 | rq->current_nr_sectors); | 952 | rq->current_nr_sectors); |
953 | if (!write) | 953 | if (!write) |
954 | rq->cmd_flags |= REQ_FAILED; | 954 | rq->cmd_flags |= REQ_FAILED; |
955 | uptodate = 0; | 955 | uptodate = 0; |
956 | } | 956 | } |
957 | cdrom_end_request(drive, uptodate); | 957 | cdrom_end_request(drive, uptodate); |
958 | return ide_stopped; | 958 | return ide_stopped; |
959 | } else if (!blk_pc_request(rq)) { | 959 | } else if (!blk_pc_request(rq)) { |
960 | ide_cd_request_sense_fixup(rq); | 960 | ide_cd_request_sense_fixup(rq); |
961 | /* complain if we still have data left to transfer */ | 961 | /* complain if we still have data left to transfer */ |
962 | uptodate = rq->data_len ? 0 : 1; | 962 | uptodate = rq->data_len ? 0 : 1; |
963 | } | 963 | } |
964 | goto end_request; | 964 | goto end_request; |
965 | } | 965 | } |
966 | 966 | ||
967 | /* check which way to transfer data */ | 967 | /* check which way to transfer data */ |
968 | if (ide_cd_check_ireason(drive, rq, len, ireason, write)) | 968 | if (ide_cd_check_ireason(drive, rq, len, ireason, write)) |
969 | return ide_stopped; | 969 | return ide_stopped; |
970 | 970 | ||
971 | if (blk_fs_request(rq)) { | 971 | if (blk_fs_request(rq)) { |
972 | if (write == 0) { | 972 | if (write == 0) { |
973 | int nskip; | 973 | int nskip; |
974 | 974 | ||
975 | if (ide_cd_check_transfer_size(drive, len)) { | 975 | if (ide_cd_check_transfer_size(drive, len)) { |
976 | cdrom_end_request(drive, 0); | 976 | cdrom_end_request(drive, 0); |
977 | return ide_stopped; | 977 | return ide_stopped; |
978 | } | 978 | } |
979 | 979 | ||
980 | /* | 980 | /* |
981 | * First, figure out if we need to bit-bucket | 981 | * First, figure out if we need to bit-bucket |
982 | * any of the leading sectors. | 982 | * any of the leading sectors. |
983 | */ | 983 | */ |
984 | nskip = min_t(int, rq->current_nr_sectors | 984 | nskip = min_t(int, rq->current_nr_sectors |
985 | - bio_cur_sectors(rq->bio), | 985 | - bio_cur_sectors(rq->bio), |
986 | thislen >> 9); | 986 | thislen >> 9); |
987 | if (nskip > 0) { | 987 | if (nskip > 0) { |
988 | ide_pad_transfer(drive, write, nskip << 9); | 988 | ide_pad_transfer(drive, write, nskip << 9); |
989 | rq->current_nr_sectors -= nskip; | 989 | rq->current_nr_sectors -= nskip; |
990 | thislen -= (nskip << 9); | 990 | thislen -= (nskip << 9); |
991 | } | 991 | } |
992 | } | 992 | } |
993 | } | 993 | } |
994 | 994 | ||
995 | if (ireason == 0) { | 995 | if (ireason == 0) { |
996 | write = 1; | 996 | write = 1; |
997 | xferfunc = hwif->tp_ops->output_data; | 997 | xferfunc = hwif->tp_ops->output_data; |
998 | } else { | 998 | } else { |
999 | write = 0; | 999 | write = 0; |
1000 | xferfunc = hwif->tp_ops->input_data; | 1000 | xferfunc = hwif->tp_ops->input_data; |
1001 | } | 1001 | } |
1002 | 1002 | ||
1003 | /* transfer data */ | 1003 | /* transfer data */ |
1004 | while (thislen > 0) { | 1004 | while (thislen > 0) { |
1005 | u8 *ptr = blk_fs_request(rq) ? NULL : rq->data; | 1005 | u8 *ptr = blk_fs_request(rq) ? NULL : rq->data; |
1006 | int blen = rq->data_len; | 1006 | int blen = rq->data_len; |
1007 | 1007 | ||
1008 | /* bio backed? */ | 1008 | /* bio backed? */ |
1009 | if (rq->bio) { | 1009 | if (rq->bio) { |
1010 | if (blk_fs_request(rq)) { | 1010 | if (blk_fs_request(rq)) { |
1011 | ptr = rq->buffer; | 1011 | ptr = rq->buffer; |
1012 | blen = rq->current_nr_sectors << 9; | 1012 | blen = rq->current_nr_sectors << 9; |
1013 | } else { | 1013 | } else { |
1014 | ptr = bio_data(rq->bio); | 1014 | ptr = bio_data(rq->bio); |
1015 | blen = bio_iovec(rq->bio)->bv_len; | 1015 | blen = bio_iovec(rq->bio)->bv_len; |
1016 | } | 1016 | } |
1017 | } | 1017 | } |
1018 | 1018 | ||
1019 | if (!ptr) { | 1019 | if (!ptr) { |
1020 | if (blk_fs_request(rq) && !write) | 1020 | if (blk_fs_request(rq) && !write) |
1021 | /* | 1021 | /* |
1022 | * If the buffers are full, pipe the rest into | 1022 | * If the buffers are full, pipe the rest into |
1023 | * oblivion. | 1023 | * oblivion. |
1024 | */ | 1024 | */ |
1025 | ide_pad_transfer(drive, 0, thislen); | 1025 | ide_pad_transfer(drive, 0, thislen); |
1026 | else { | 1026 | else { |
1027 | printk(KERN_ERR "%s: confused, missing data\n", | 1027 | printk(KERN_ERR "%s: confused, missing data\n", |
1028 | drive->name); | 1028 | drive->name); |
1029 | blk_dump_rq_flags(rq, rq_data_dir(rq) | 1029 | blk_dump_rq_flags(rq, rq_data_dir(rq) |
1030 | ? "cdrom_newpc_intr, write" | 1030 | ? "cdrom_newpc_intr, write" |
1031 | : "cdrom_newpc_intr, read"); | 1031 | : "cdrom_newpc_intr, read"); |
1032 | } | 1032 | } |
1033 | break; | 1033 | break; |
1034 | } | 1034 | } |
1035 | 1035 | ||
1036 | if (blen > thislen) | 1036 | if (blen > thislen) |
1037 | blen = thislen; | 1037 | blen = thislen; |
1038 | 1038 | ||
1039 | xferfunc(drive, NULL, ptr, blen); | 1039 | xferfunc(drive, NULL, ptr, blen); |
1040 | 1040 | ||
1041 | thislen -= blen; | 1041 | thislen -= blen; |
1042 | len -= blen; | 1042 | len -= blen; |
1043 | 1043 | ||
1044 | if (blk_fs_request(rq)) { | 1044 | if (blk_fs_request(rq)) { |
1045 | rq->buffer += blen; | 1045 | rq->buffer += blen; |
1046 | rq->nr_sectors -= (blen >> 9); | 1046 | rq->nr_sectors -= (blen >> 9); |
1047 | rq->current_nr_sectors -= (blen >> 9); | 1047 | rq->current_nr_sectors -= (blen >> 9); |
1048 | rq->sector += (blen >> 9); | 1048 | rq->sector += (blen >> 9); |
1049 | 1049 | ||
1050 | if (rq->current_nr_sectors == 0 && rq->nr_sectors) | 1050 | if (rq->current_nr_sectors == 0 && rq->nr_sectors) |
1051 | cdrom_end_request(drive, 1); | 1051 | cdrom_end_request(drive, 1); |
1052 | } else { | 1052 | } else { |
1053 | rq->data_len -= blen; | 1053 | rq->data_len -= blen; |
1054 | 1054 | ||
1055 | /* | 1055 | /* |
1056 | * The request can't be completed until DRQ is cleared. | 1056 | * The request can't be completed until DRQ is cleared. |
1057 | * So complete the data, but don't complete the request | 1057 | * So complete the data, but don't complete the request |
1058 | * using the dummy function for the callback feature | 1058 | * using the dummy function for the callback feature |
1059 | * of blk_end_request_callback(). | 1059 | * of blk_end_request_callback(). |
1060 | */ | 1060 | */ |
1061 | if (rq->bio) | 1061 | if (rq->bio) |
1062 | blk_end_request_callback(rq, 0, blen, | 1062 | blk_end_request_callback(rq, 0, blen, |
1063 | cdrom_newpc_intr_dummy_cb); | 1063 | cdrom_newpc_intr_dummy_cb); |
1064 | else | 1064 | else |
1065 | rq->data += blen; | 1065 | rq->data += blen; |
1066 | } | 1066 | } |
1067 | if (!write && blk_sense_request(rq)) | 1067 | if (!write && blk_sense_request(rq)) |
1068 | rq->sense_len += blen; | 1068 | rq->sense_len += blen; |
1069 | } | 1069 | } |
1070 | 1070 | ||
1071 | /* pad, if necessary */ | 1071 | /* pad, if necessary */ |
1072 | if (!blk_fs_request(rq) && len > 0) | 1072 | if (!blk_fs_request(rq) && len > 0) |
1073 | ide_pad_transfer(drive, write, len); | 1073 | ide_pad_transfer(drive, write, len); |
1074 | 1074 | ||
1075 | if (blk_pc_request(rq)) { | 1075 | if (blk_pc_request(rq)) { |
1076 | timeout = rq->timeout; | 1076 | timeout = rq->timeout; |
1077 | } else { | 1077 | } else { |
1078 | timeout = ATAPI_WAIT_PC; | 1078 | timeout = ATAPI_WAIT_PC; |
1079 | if (!blk_fs_request(rq)) | 1079 | if (!blk_fs_request(rq)) |
1080 | expiry = cdrom_timer_expiry; | 1080 | expiry = cdrom_timer_expiry; |
1081 | } | 1081 | } |
1082 | 1082 | ||
1083 | ide_set_handler(drive, cdrom_newpc_intr, timeout, expiry); | 1083 | ide_set_handler(drive, cdrom_newpc_intr, timeout, expiry); |
1084 | return ide_started; | 1084 | return ide_started; |
1085 | 1085 | ||
1086 | end_request: | 1086 | end_request: |
1087 | if (blk_pc_request(rq)) { | 1087 | if (blk_pc_request(rq)) { |
1088 | unsigned long flags; | 1088 | unsigned long flags; |
1089 | unsigned int dlen = rq->data_len; | 1089 | unsigned int dlen = rq->data_len; |
1090 | 1090 | ||
1091 | if (dma) | 1091 | if (dma) |
1092 | rq->data_len = 0; | 1092 | rq->data_len = 0; |
1093 | 1093 | ||
1094 | spin_lock_irqsave(&ide_lock, flags); | 1094 | spin_lock_irqsave(&ide_lock, flags); |
1095 | if (__blk_end_request(rq, 0, dlen)) | 1095 | if (__blk_end_request(rq, 0, dlen)) |
1096 | BUG(); | 1096 | BUG(); |
1097 | HWGROUP(drive)->rq = NULL; | 1097 | HWGROUP(drive)->rq = NULL; |
1098 | spin_unlock_irqrestore(&ide_lock, flags); | 1098 | spin_unlock_irqrestore(&ide_lock, flags); |
1099 | } else { | 1099 | } else { |
1100 | if (!uptodate) | 1100 | if (!uptodate) |
1101 | rq->cmd_flags |= REQ_FAILED; | 1101 | rq->cmd_flags |= REQ_FAILED; |
1102 | cdrom_end_request(drive, uptodate); | 1102 | cdrom_end_request(drive, uptodate); |
1103 | } | 1103 | } |
1104 | return ide_stopped; | 1104 | return ide_stopped; |
1105 | } | 1105 | } |
1106 | 1106 | ||
1107 | static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) | 1107 | static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq) |
1108 | { | 1108 | { |
1109 | struct cdrom_info *cd = drive->driver_data; | 1109 | struct cdrom_info *cd = drive->driver_data; |
1110 | int write = rq_data_dir(rq) == WRITE; | 1110 | int write = rq_data_dir(rq) == WRITE; |
1111 | unsigned short sectors_per_frame = | 1111 | unsigned short sectors_per_frame = |
1112 | queue_hardsect_size(drive->queue) >> SECTOR_BITS; | 1112 | queue_hardsect_size(drive->queue) >> SECTOR_BITS; |
1113 | 1113 | ||
1114 | if (write) { | 1114 | if (write) { |
1115 | /* disk has become write protected */ | 1115 | /* disk has become write protected */ |
1116 | if (cd->disk->policy) { | 1116 | if (cd->disk->policy) { |
1117 | cdrom_end_request(drive, 0); | 1117 | cdrom_end_request(drive, 0); |
1118 | return ide_stopped; | 1118 | return ide_stopped; |
1119 | } | 1119 | } |
1120 | } else { | 1120 | } else { |
1121 | /* | 1121 | /* |
1122 | * We may be retrying this request after an error. Fix up any | 1122 | * We may be retrying this request after an error. Fix up any |
1123 | * weirdness which might be present in the request packet. | 1123 | * weirdness which might be present in the request packet. |
1124 | */ | 1124 | */ |
1125 | restore_request(rq); | 1125 | restore_request(rq); |
1126 | } | 1126 | } |
1127 | 1127 | ||
1128 | /* use DMA, if possible / writes *must* be hardware frame aligned */ | 1128 | /* use DMA, if possible / writes *must* be hardware frame aligned */ |
1129 | if ((rq->nr_sectors & (sectors_per_frame - 1)) || | 1129 | if ((rq->nr_sectors & (sectors_per_frame - 1)) || |
1130 | (rq->sector & (sectors_per_frame - 1))) { | 1130 | (rq->sector & (sectors_per_frame - 1))) { |
1131 | if (write) { | 1131 | if (write) { |
1132 | cdrom_end_request(drive, 0); | 1132 | cdrom_end_request(drive, 0); |
1133 | return ide_stopped; | 1133 | return ide_stopped; |
1134 | } | 1134 | } |
1135 | cd->dma = 0; | 1135 | cd->dma = 0; |
1136 | } else | 1136 | } else |
1137 | cd->dma = drive->using_dma; | 1137 | cd->dma = drive->using_dma; |
1138 | 1138 | ||
1139 | if (write) | 1139 | if (write) |
1140 | cd->devinfo.media_written = 1; | 1140 | cd->devinfo.media_written = 1; |
1141 | 1141 | ||
1142 | return ide_started; | 1142 | return ide_started; |
1143 | } | 1143 | } |
1144 | 1144 | ||
1145 | static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive) | 1145 | static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive) |
1146 | { | 1146 | { |
1147 | struct request *rq = HWGROUP(drive)->rq; | 1147 | struct request *rq = HWGROUP(drive)->rq; |
1148 | 1148 | ||
1149 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); | 1149 | return cdrom_transfer_packet_command(drive, rq, cdrom_newpc_intr); |
1150 | } | 1150 | } |
1151 | 1151 | ||
1152 | static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) | 1152 | static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq) |
1153 | { | 1153 | { |
1154 | struct cdrom_info *info = drive->driver_data; | 1154 | struct cdrom_info *info = drive->driver_data; |
1155 | 1155 | ||
1156 | if (blk_pc_request(rq)) | 1156 | if (blk_pc_request(rq)) |
1157 | rq->cmd_flags |= REQ_QUIET; | 1157 | rq->cmd_flags |= REQ_QUIET; |
1158 | else | 1158 | else |
1159 | rq->cmd_flags &= ~REQ_FAILED; | 1159 | rq->cmd_flags &= ~REQ_FAILED; |
1160 | 1160 | ||
1161 | info->dma = 0; | 1161 | info->dma = 0; |
1162 | 1162 | ||
1163 | /* sg request */ | 1163 | /* sg request */ |
1164 | if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) { | 1164 | if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) { |
1165 | struct request_queue *q = drive->queue; | 1165 | struct request_queue *q = drive->queue; |
1166 | unsigned int alignment; | 1166 | unsigned int alignment; |
1167 | unsigned long addr; | 1167 | unsigned long addr; |
1168 | unsigned long stack_mask = ~(THREAD_SIZE - 1); | 1168 | unsigned long stack_mask = ~(THREAD_SIZE - 1); |
1169 | 1169 | ||
1170 | if (rq->bio) | 1170 | if (rq->bio) |
1171 | addr = (unsigned long)bio_data(rq->bio); | 1171 | addr = (unsigned long)bio_data(rq->bio); |
1172 | else | 1172 | else |
1173 | addr = (unsigned long)rq->data; | 1173 | addr = (unsigned long)rq->data; |
1174 | 1174 | ||
1175 | info->dma = drive->using_dma; | 1175 | info->dma = drive->using_dma; |
1176 | 1176 | ||
1177 | /* | 1177 | /* |
1178 | * check if dma is safe | 1178 | * check if dma is safe |
1179 | * | 1179 | * |
1180 | * NOTE! The "len" and "addr" checks should possibly have | 1180 | * NOTE! The "len" and "addr" checks should possibly have |
1181 | * separate masks. | 1181 | * separate masks. |
1182 | */ | 1182 | */ |
1183 | alignment = queue_dma_alignment(q) | q->dma_pad_mask; | 1183 | alignment = queue_dma_alignment(q) | q->dma_pad_mask; |
1184 | if (addr & alignment || rq->data_len & alignment) | 1184 | if (addr & alignment || rq->data_len & alignment) |
1185 | info->dma = 0; | 1185 | info->dma = 0; |
1186 | 1186 | ||
1187 | if (!((addr & stack_mask) ^ | 1187 | if (!((addr & stack_mask) ^ |
1188 | ((unsigned long)current->stack & stack_mask))) | 1188 | ((unsigned long)current->stack & stack_mask))) |
1189 | info->dma = 0; | 1189 | info->dma = 0; |
1190 | } | 1190 | } |
1191 | } | 1191 | } |
1192 | 1192 | ||
1193 | /* | 1193 | /* |
1194 | * cdrom driver request routine. | 1194 | * cdrom driver request routine. |
1195 | */ | 1195 | */ |
1196 | static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq, | 1196 | static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq, |
1197 | sector_t block) | 1197 | sector_t block) |
1198 | { | 1198 | { |
1199 | struct cdrom_info *info = drive->driver_data; | 1199 | struct cdrom_info *info = drive->driver_data; |
1200 | ide_handler_t *fn; | 1200 | ide_handler_t *fn; |
1201 | int xferlen; | 1201 | int xferlen; |
1202 | 1202 | ||
1203 | if (blk_fs_request(rq)) { | 1203 | if (blk_fs_request(rq)) { |
1204 | if (drive->atapi_flags & IDE_AFLAG_SEEKING) { | 1204 | if (drive->atapi_flags & IDE_AFLAG_SEEKING) { |
1205 | ide_hwif_t *hwif = drive->hwif; | 1205 | ide_hwif_t *hwif = drive->hwif; |
1206 | unsigned long elapsed = jiffies - info->start_seek; | 1206 | unsigned long elapsed = jiffies - info->start_seek; |
1207 | int stat = hwif->tp_ops->read_status(hwif); | 1207 | int stat = hwif->tp_ops->read_status(hwif); |
1208 | 1208 | ||
1209 | if ((stat & SEEK_STAT) != SEEK_STAT) { | 1209 | if ((stat & SEEK_STAT) != SEEK_STAT) { |
1210 | if (elapsed < IDECD_SEEK_TIMEOUT) { | 1210 | if (elapsed < IDECD_SEEK_TIMEOUT) { |
1211 | ide_stall_queue(drive, | 1211 | ide_stall_queue(drive, |
1212 | IDECD_SEEK_TIMER); | 1212 | IDECD_SEEK_TIMER); |
1213 | return ide_stopped; | 1213 | return ide_stopped; |
1214 | } | 1214 | } |
1215 | printk(KERN_ERR "%s: DSC timeout\n", | 1215 | printk(KERN_ERR "%s: DSC timeout\n", |
1216 | drive->name); | 1216 | drive->name); |
1217 | } | 1217 | } |
1218 | drive->atapi_flags &= ~IDE_AFLAG_SEEKING; | 1218 | drive->atapi_flags &= ~IDE_AFLAG_SEEKING; |
1219 | } | 1219 | } |
1220 | if (rq_data_dir(rq) == READ && | 1220 | if (rq_data_dir(rq) == READ && |
1221 | IDE_LARGE_SEEK(info->last_block, block, | 1221 | IDE_LARGE_SEEK(info->last_block, block, |
1222 | IDECD_SEEK_THRESHOLD) && | 1222 | IDECD_SEEK_THRESHOLD) && |
1223 | drive->dsc_overlap) { | 1223 | drive->dsc_overlap) { |
1224 | xferlen = 0; | 1224 | xferlen = 0; |
1225 | fn = cdrom_start_seek_continuation; | 1225 | fn = cdrom_start_seek_continuation; |
1226 | 1226 | ||
1227 | info->dma = 0; | 1227 | info->dma = 0; |
1228 | info->start_seek = jiffies; | 1228 | info->start_seek = jiffies; |
1229 | 1229 | ||
1230 | ide_cd_prepare_seek_request(drive, rq); | 1230 | ide_cd_prepare_seek_request(drive, rq); |
1231 | } else { | 1231 | } else { |
1232 | xferlen = 32768; | 1232 | xferlen = 32768; |
1233 | fn = cdrom_start_rw_cont; | 1233 | fn = cdrom_start_rw_cont; |
1234 | 1234 | ||
1235 | if (cdrom_start_rw(drive, rq) == ide_stopped) | 1235 | if (cdrom_start_rw(drive, rq) == ide_stopped) |
1236 | return ide_stopped; | 1236 | return ide_stopped; |
1237 | 1237 | ||
1238 | if (ide_cd_prepare_rw_request(drive, rq) == ide_stopped) | 1238 | if (ide_cd_prepare_rw_request(drive, rq) == ide_stopped) |
1239 | return ide_stopped; | 1239 | return ide_stopped; |
1240 | } | 1240 | } |
1241 | info->last_block = block; | 1241 | info->last_block = block; |
1242 | } else if (blk_sense_request(rq) || blk_pc_request(rq) || | 1242 | } else if (blk_sense_request(rq) || blk_pc_request(rq) || |
1243 | rq->cmd_type == REQ_TYPE_ATA_PC) { | 1243 | rq->cmd_type == REQ_TYPE_ATA_PC) { |
1244 | xferlen = rq->data_len; | 1244 | xferlen = rq->data_len; |
1245 | fn = cdrom_do_newpc_cont; | 1245 | fn = cdrom_do_newpc_cont; |
1246 | 1246 | ||
1247 | if (!rq->timeout) | 1247 | if (!rq->timeout) |
1248 | rq->timeout = ATAPI_WAIT_PC; | 1248 | rq->timeout = ATAPI_WAIT_PC; |
1249 | 1249 | ||
1250 | cdrom_do_block_pc(drive, rq); | 1250 | cdrom_do_block_pc(drive, rq); |
1251 | } else if (blk_special_request(rq)) { | 1251 | } else if (blk_special_request(rq)) { |
1252 | /* right now this can only be a reset... */ | 1252 | /* right now this can only be a reset... */ |
1253 | cdrom_end_request(drive, 1); | 1253 | cdrom_end_request(drive, 1); |
1254 | return ide_stopped; | 1254 | return ide_stopped; |
1255 | } else { | 1255 | } else { |
1256 | blk_dump_rq_flags(rq, "ide-cd bad flags"); | 1256 | blk_dump_rq_flags(rq, "ide-cd bad flags"); |
1257 | cdrom_end_request(drive, 0); | 1257 | cdrom_end_request(drive, 0); |
1258 | return ide_stopped; | 1258 | return ide_stopped; |
1259 | } | 1259 | } |
1260 | 1260 | ||
1261 | return cdrom_start_packet_command(drive, xferlen, fn); | 1261 | return cdrom_start_packet_command(drive, xferlen, fn); |
1262 | } | 1262 | } |
1263 | 1263 | ||
1264 | /* | 1264 | /* |
1265 | * Ioctl handling. | 1265 | * Ioctl handling. |
1266 | * | 1266 | * |
1267 | * Routines which queue packet commands take as a final argument a pointer to a | 1267 | * Routines which queue packet commands take as a final argument a pointer to a |
1268 | * request_sense struct. If execution of the command results in an error with a | 1268 | * request_sense struct. If execution of the command results in an error with a |
1269 | * CHECK CONDITION status, this structure will be filled with the results of the | 1269 | * CHECK CONDITION status, this structure will be filled with the results of the |
1270 | * subsequent request sense command. The pointer can also be NULL, in which case | 1270 | * subsequent request sense command. The pointer can also be NULL, in which case |
1271 | * no sense information is returned. | 1271 | * no sense information is returned. |
1272 | */ | 1272 | */ |
1273 | static void msf_from_bcd(struct atapi_msf *msf) | 1273 | static void msf_from_bcd(struct atapi_msf *msf) |
1274 | { | 1274 | { |
1275 | msf->minute = bcd2bin(msf->minute); | 1275 | msf->minute = bcd2bin(msf->minute); |
1276 | msf->second = bcd2bin(msf->second); | 1276 | msf->second = bcd2bin(msf->second); |
1277 | msf->frame = bcd2bin(msf->frame); | 1277 | msf->frame = bcd2bin(msf->frame); |
1278 | } | 1278 | } |
1279 | 1279 | ||
1280 | int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense) | 1280 | int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense) |
1281 | { | 1281 | { |
1282 | struct cdrom_info *info = drive->driver_data; | 1282 | struct cdrom_info *info = drive->driver_data; |
1283 | struct cdrom_device_info *cdi = &info->devinfo; | 1283 | struct cdrom_device_info *cdi = &info->devinfo; |
1284 | unsigned char cmd[BLK_MAX_CDB]; | 1284 | unsigned char cmd[BLK_MAX_CDB]; |
1285 | 1285 | ||
1286 | memset(cmd, 0, BLK_MAX_CDB); | 1286 | memset(cmd, 0, BLK_MAX_CDB); |
1287 | cmd[0] = GPCMD_TEST_UNIT_READY; | 1287 | cmd[0] = GPCMD_TEST_UNIT_READY; |
1288 | 1288 | ||
1289 | /* | 1289 | /* |
1290 | * Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to switch CDs | 1290 | * Sanyo 3 CD changer uses byte 7 of TEST_UNIT_READY to switch CDs |
1291 | * instead of supporting the LOAD_UNLOAD opcode. | 1291 | * instead of supporting the LOAD_UNLOAD opcode. |
1292 | */ | 1292 | */ |
1293 | cmd[7] = cdi->sanyo_slot % 3; | 1293 | cmd[7] = cdi->sanyo_slot % 3; |
1294 | 1294 | ||
1295 | return ide_cd_queue_pc(drive, cmd, 0, NULL, NULL, sense, 0, REQ_QUIET); | 1295 | return ide_cd_queue_pc(drive, cmd, 0, NULL, NULL, sense, 0, REQ_QUIET); |
1296 | } | 1296 | } |
1297 | 1297 | ||
1298 | static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity, | 1298 | static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity, |
1299 | unsigned long *sectors_per_frame, | 1299 | unsigned long *sectors_per_frame, |
1300 | struct request_sense *sense) | 1300 | struct request_sense *sense) |
1301 | { | 1301 | { |
1302 | struct { | 1302 | struct { |
1303 | __be32 lba; | 1303 | __be32 lba; |
1304 | __be32 blocklen; | 1304 | __be32 blocklen; |
1305 | } capbuf; | 1305 | } capbuf; |
1306 | 1306 | ||
1307 | int stat; | 1307 | int stat; |
1308 | unsigned char cmd[BLK_MAX_CDB]; | 1308 | unsigned char cmd[BLK_MAX_CDB]; |
1309 | unsigned len = sizeof(capbuf); | 1309 | unsigned len = sizeof(capbuf); |
1310 | u32 blocklen; | 1310 | u32 blocklen; |
1311 | 1311 | ||
1312 | memset(cmd, 0, BLK_MAX_CDB); | 1312 | memset(cmd, 0, BLK_MAX_CDB); |
1313 | cmd[0] = GPCMD_READ_CDVD_CAPACITY; | 1313 | cmd[0] = GPCMD_READ_CDVD_CAPACITY; |
1314 | 1314 | ||
1315 | stat = ide_cd_queue_pc(drive, cmd, 0, &capbuf, &len, sense, 0, | 1315 | stat = ide_cd_queue_pc(drive, cmd, 0, &capbuf, &len, sense, 0, |
1316 | REQ_QUIET); | 1316 | REQ_QUIET); |
1317 | if (stat) | 1317 | if (stat) |
1318 | return stat; | 1318 | return stat; |
1319 | 1319 | ||
1320 | /* | 1320 | /* |
1321 | * Sanity check the given block size | 1321 | * Sanity check the given block size |
1322 | */ | 1322 | */ |
1323 | blocklen = be32_to_cpu(capbuf.blocklen); | 1323 | blocklen = be32_to_cpu(capbuf.blocklen); |
1324 | switch (blocklen) { | 1324 | switch (blocklen) { |
1325 | case 512: | 1325 | case 512: |
1326 | case 1024: | 1326 | case 1024: |
1327 | case 2048: | 1327 | case 2048: |
1328 | case 4096: | 1328 | case 4096: |
1329 | break; | 1329 | break; |
1330 | default: | 1330 | default: |
1331 | printk(KERN_ERR "%s: weird block size %u\n", | 1331 | printk(KERN_ERR "%s: weird block size %u\n", |
1332 | drive->name, blocklen); | 1332 | drive->name, blocklen); |
1333 | printk(KERN_ERR "%s: default to 2kb block size\n", | 1333 | printk(KERN_ERR "%s: default to 2kb block size\n", |
1334 | drive->name); | 1334 | drive->name); |
1335 | blocklen = 2048; | 1335 | blocklen = 2048; |
1336 | break; | 1336 | break; |
1337 | } | 1337 | } |
1338 | 1338 | ||
1339 | *capacity = 1 + be32_to_cpu(capbuf.lba); | 1339 | *capacity = 1 + be32_to_cpu(capbuf.lba); |
1340 | *sectors_per_frame = blocklen >> SECTOR_BITS; | 1340 | *sectors_per_frame = blocklen >> SECTOR_BITS; |
1341 | return 0; | 1341 | return 0; |
1342 | } | 1342 | } |
1343 | 1343 | ||
1344 | static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag, | 1344 | static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag, |
1345 | int format, char *buf, int buflen, | 1345 | int format, char *buf, int buflen, |
1346 | struct request_sense *sense) | 1346 | struct request_sense *sense) |
1347 | { | 1347 | { |
1348 | unsigned char cmd[BLK_MAX_CDB]; | 1348 | unsigned char cmd[BLK_MAX_CDB]; |
1349 | 1349 | ||
1350 | memset(cmd, 0, BLK_MAX_CDB); | 1350 | memset(cmd, 0, BLK_MAX_CDB); |
1351 | 1351 | ||
1352 | cmd[0] = GPCMD_READ_TOC_PMA_ATIP; | 1352 | cmd[0] = GPCMD_READ_TOC_PMA_ATIP; |
1353 | cmd[6] = trackno; | 1353 | cmd[6] = trackno; |
1354 | cmd[7] = (buflen >> 8); | 1354 | cmd[7] = (buflen >> 8); |
1355 | cmd[8] = (buflen & 0xff); | 1355 | cmd[8] = (buflen & 0xff); |
1356 | cmd[9] = (format << 6); | 1356 | cmd[9] = (format << 6); |
1357 | 1357 | ||
1358 | if (msf_flag) | 1358 | if (msf_flag) |
1359 | cmd[1] = 2; | 1359 | cmd[1] = 2; |
1360 | 1360 | ||
1361 | return ide_cd_queue_pc(drive, cmd, 0, buf, &buflen, sense, 0, REQ_QUIET); | 1361 | return ide_cd_queue_pc(drive, cmd, 0, buf, &buflen, sense, 0, REQ_QUIET); |
1362 | } | 1362 | } |
1363 | 1363 | ||
1364 | /* Try to read the entire TOC for the disk into our internal buffer. */ | 1364 | /* Try to read the entire TOC for the disk into our internal buffer. */ |
1365 | int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) | 1365 | int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense) |
1366 | { | 1366 | { |
1367 | int stat, ntracks, i; | 1367 | int stat, ntracks, i; |
1368 | struct cdrom_info *info = drive->driver_data; | 1368 | struct cdrom_info *info = drive->driver_data; |
1369 | struct cdrom_device_info *cdi = &info->devinfo; | 1369 | struct cdrom_device_info *cdi = &info->devinfo; |
1370 | struct atapi_toc *toc = info->toc; | 1370 | struct atapi_toc *toc = info->toc; |
1371 | struct { | 1371 | struct { |
1372 | struct atapi_toc_header hdr; | 1372 | struct atapi_toc_header hdr; |
1373 | struct atapi_toc_entry ent; | 1373 | struct atapi_toc_entry ent; |
1374 | } ms_tmp; | 1374 | } ms_tmp; |
1375 | long last_written; | 1375 | long last_written; |
1376 | unsigned long sectors_per_frame = SECTORS_PER_FRAME; | 1376 | unsigned long sectors_per_frame = SECTORS_PER_FRAME; |
1377 | 1377 | ||
1378 | if (toc == NULL) { | 1378 | if (toc == NULL) { |
1379 | /* try to allocate space */ | 1379 | /* try to allocate space */ |
1380 | toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL); | 1380 | toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL); |
1381 | if (toc == NULL) { | 1381 | if (toc == NULL) { |
1382 | printk(KERN_ERR "%s: No cdrom TOC buffer!\n", | 1382 | printk(KERN_ERR "%s: No cdrom TOC buffer!\n", |
1383 | drive->name); | 1383 | drive->name); |
1384 | return -ENOMEM; | 1384 | return -ENOMEM; |
1385 | } | 1385 | } |
1386 | info->toc = toc; | 1386 | info->toc = toc; |
1387 | } | 1387 | } |
1388 | 1388 | ||
1389 | /* | 1389 | /* |
1390 | * Check to see if the existing data is still valid. If it is, | 1390 | * Check to see if the existing data is still valid. If it is, |
1391 | * just return. | 1391 | * just return. |
1392 | */ | 1392 | */ |
1393 | (void) cdrom_check_status(drive, sense); | 1393 | (void) cdrom_check_status(drive, sense); |
1394 | 1394 | ||
1395 | if (drive->atapi_flags & IDE_AFLAG_TOC_VALID) | 1395 | if (drive->atapi_flags & IDE_AFLAG_TOC_VALID) |
1396 | return 0; | 1396 | return 0; |
1397 | 1397 | ||
1398 | /* try to get the total cdrom capacity and sector size */ | 1398 | /* try to get the total cdrom capacity and sector size */ |
1399 | stat = cdrom_read_capacity(drive, &toc->capacity, §ors_per_frame, | 1399 | stat = cdrom_read_capacity(drive, &toc->capacity, §ors_per_frame, |
1400 | sense); | 1400 | sense); |
1401 | if (stat) | 1401 | if (stat) |
1402 | toc->capacity = 0x1fffff; | 1402 | toc->capacity = 0x1fffff; |
1403 | 1403 | ||
1404 | set_capacity(info->disk, toc->capacity * sectors_per_frame); | 1404 | set_capacity(info->disk, toc->capacity * sectors_per_frame); |
1405 | /* save a private copy of the TOC capacity for error handling */ | 1405 | /* save a private copy of the TOC capacity for error handling */ |
1406 | drive->probed_capacity = toc->capacity * sectors_per_frame; | 1406 | drive->probed_capacity = toc->capacity * sectors_per_frame; |
1407 | 1407 | ||
1408 | blk_queue_hardsect_size(drive->queue, | 1408 | blk_queue_hardsect_size(drive->queue, |
1409 | sectors_per_frame << SECTOR_BITS); | 1409 | sectors_per_frame << SECTOR_BITS); |
1410 | 1410 | ||
1411 | /* first read just the header, so we know how long the TOC is */ | 1411 | /* first read just the header, so we know how long the TOC is */ |
1412 | stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr, | 1412 | stat = cdrom_read_tocentry(drive, 0, 1, 0, (char *) &toc->hdr, |
1413 | sizeof(struct atapi_toc_header), sense); | 1413 | sizeof(struct atapi_toc_header), sense); |
1414 | if (stat) | 1414 | if (stat) |
1415 | return stat; | 1415 | return stat; |
1416 | 1416 | ||
1417 | if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { | 1417 | if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { |
1418 | toc->hdr.first_track = bcd2bin(toc->hdr.first_track); | 1418 | toc->hdr.first_track = bcd2bin(toc->hdr.first_track); |
1419 | toc->hdr.last_track = bcd2bin(toc->hdr.last_track); | 1419 | toc->hdr.last_track = bcd2bin(toc->hdr.last_track); |
1420 | } | 1420 | } |
1421 | 1421 | ||
1422 | ntracks = toc->hdr.last_track - toc->hdr.first_track + 1; | 1422 | ntracks = toc->hdr.last_track - toc->hdr.first_track + 1; |
1423 | if (ntracks <= 0) | 1423 | if (ntracks <= 0) |
1424 | return -EIO; | 1424 | return -EIO; |
1425 | if (ntracks > MAX_TRACKS) | 1425 | if (ntracks > MAX_TRACKS) |
1426 | ntracks = MAX_TRACKS; | 1426 | ntracks = MAX_TRACKS; |
1427 | 1427 | ||
1428 | /* now read the whole schmeer */ | 1428 | /* now read the whole schmeer */ |
1429 | stat = cdrom_read_tocentry(drive, toc->hdr.first_track, 1, 0, | 1429 | stat = cdrom_read_tocentry(drive, toc->hdr.first_track, 1, 0, |
1430 | (char *)&toc->hdr, | 1430 | (char *)&toc->hdr, |
1431 | sizeof(struct atapi_toc_header) + | 1431 | sizeof(struct atapi_toc_header) + |
1432 | (ntracks + 1) * | 1432 | (ntracks + 1) * |
1433 | sizeof(struct atapi_toc_entry), sense); | 1433 | sizeof(struct atapi_toc_entry), sense); |
1434 | 1434 | ||
1435 | if (stat && toc->hdr.first_track > 1) { | 1435 | if (stat && toc->hdr.first_track > 1) { |
1436 | /* | 1436 | /* |
1437 | * Cds with CDI tracks only don't have any TOC entries, despite | 1437 | * Cds with CDI tracks only don't have any TOC entries, despite |
1438 | * of this the returned values are | 1438 | * of this the returned values are |
1439 | * first_track == last_track = number of CDI tracks + 1, | 1439 | * first_track == last_track = number of CDI tracks + 1, |
1440 | * so that this case is indistinguishable from the same layout | 1440 | * so that this case is indistinguishable from the same layout |
1441 | * plus an additional audio track. If we get an error for the | 1441 | * plus an additional audio track. If we get an error for the |
1442 | * regular case, we assume a CDI without additional audio | 1442 | * regular case, we assume a CDI without additional audio |
1443 | * tracks. In this case the readable TOC is empty (CDI tracks | 1443 | * tracks. In this case the readable TOC is empty (CDI tracks |
1444 | * are not included) and only holds the Leadout entry. | 1444 | * are not included) and only holds the Leadout entry. |
1445 | * | 1445 | * |
1446 | * Heiko Eiรfeldt. | 1446 | * Heiko Eiรfeldt. |
1447 | */ | 1447 | */ |
1448 | ntracks = 0; | 1448 | ntracks = 0; |
1449 | stat = cdrom_read_tocentry(drive, CDROM_LEADOUT, 1, 0, | 1449 | stat = cdrom_read_tocentry(drive, CDROM_LEADOUT, 1, 0, |
1450 | (char *)&toc->hdr, | 1450 | (char *)&toc->hdr, |
1451 | sizeof(struct atapi_toc_header) + | 1451 | sizeof(struct atapi_toc_header) + |
1452 | (ntracks + 1) * | 1452 | (ntracks + 1) * |
1453 | sizeof(struct atapi_toc_entry), | 1453 | sizeof(struct atapi_toc_entry), |
1454 | sense); | 1454 | sense); |
1455 | if (stat) | 1455 | if (stat) |
1456 | return stat; | 1456 | return stat; |
1457 | 1457 | ||
1458 | if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { | 1458 | if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { |
1459 | toc->hdr.first_track = (u8)bin2bcd(CDROM_LEADOUT); | 1459 | toc->hdr.first_track = (u8)bin2bcd(CDROM_LEADOUT); |
1460 | toc->hdr.last_track = (u8)bin2bcd(CDROM_LEADOUT); | 1460 | toc->hdr.last_track = (u8)bin2bcd(CDROM_LEADOUT); |
1461 | } else { | 1461 | } else { |
1462 | toc->hdr.first_track = CDROM_LEADOUT; | 1462 | toc->hdr.first_track = CDROM_LEADOUT; |
1463 | toc->hdr.last_track = CDROM_LEADOUT; | 1463 | toc->hdr.last_track = CDROM_LEADOUT; |
1464 | } | 1464 | } |
1465 | } | 1465 | } |
1466 | 1466 | ||
1467 | if (stat) | 1467 | if (stat) |
1468 | return stat; | 1468 | return stat; |
1469 | 1469 | ||
1470 | toc->hdr.toc_length = be16_to_cpu(toc->hdr.toc_length); | 1470 | toc->hdr.toc_length = be16_to_cpu(toc->hdr.toc_length); |
1471 | 1471 | ||
1472 | if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { | 1472 | if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) { |
1473 | toc->hdr.first_track = bcd2bin(toc->hdr.first_track); | 1473 | toc->hdr.first_track = bcd2bin(toc->hdr.first_track); |
1474 | toc->hdr.last_track = bcd2bin(toc->hdr.last_track); | 1474 | toc->hdr.last_track = bcd2bin(toc->hdr.last_track); |
1475 | } | 1475 | } |
1476 | 1476 | ||
1477 | for (i = 0; i <= ntracks; i++) { | 1477 | for (i = 0; i <= ntracks; i++) { |
1478 | if (drive->atapi_flags & IDE_AFLAG_TOCADDR_AS_BCD) { | 1478 | if (drive->atapi_flags & IDE_AFLAG_TOCADDR_AS_BCD) { |
1479 | if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) | 1479 | if (drive->atapi_flags & IDE_AFLAG_TOCTRACKS_AS_BCD) |
1480 | toc->ent[i].track = bcd2bin(toc->ent[i].track); | 1480 | toc->ent[i].track = bcd2bin(toc->ent[i].track); |
1481 | msf_from_bcd(&toc->ent[i].addr.msf); | 1481 | msf_from_bcd(&toc->ent[i].addr.msf); |
1482 | } | 1482 | } |
1483 | toc->ent[i].addr.lba = msf_to_lba(toc->ent[i].addr.msf.minute, | 1483 | toc->ent[i].addr.lba = msf_to_lba(toc->ent[i].addr.msf.minute, |
1484 | toc->ent[i].addr.msf.second, | 1484 | toc->ent[i].addr.msf.second, |
1485 | toc->ent[i].addr.msf.frame); | 1485 | toc->ent[i].addr.msf.frame); |
1486 | } | 1486 | } |
1487 | 1487 | ||
1488 | if (toc->hdr.first_track != CDROM_LEADOUT) { | 1488 | if (toc->hdr.first_track != CDROM_LEADOUT) { |
1489 | /* read the multisession information */ | 1489 | /* read the multisession information */ |
1490 | stat = cdrom_read_tocentry(drive, 0, 0, 1, (char *)&ms_tmp, | 1490 | stat = cdrom_read_tocentry(drive, 0, 0, 1, (char *)&ms_tmp, |
1491 | sizeof(ms_tmp), sense); | 1491 | sizeof(ms_tmp), sense); |
1492 | if (stat) | 1492 | if (stat) |
1493 | return stat; | 1493 | return stat; |
1494 | 1494 | ||
1495 | toc->last_session_lba = be32_to_cpu(ms_tmp.ent.addr.lba); | 1495 | toc->last_session_lba = be32_to_cpu(ms_tmp.ent.addr.lba); |
1496 | } else { | 1496 | } else { |
1497 | ms_tmp.hdr.last_track = CDROM_LEADOUT; | 1497 | ms_tmp.hdr.last_track = CDROM_LEADOUT; |
1498 | ms_tmp.hdr.first_track = ms_tmp.hdr.last_track; | 1498 | ms_tmp.hdr.first_track = ms_tmp.hdr.last_track; |
1499 | toc->last_session_lba = msf_to_lba(0, 2, 0); /* 0m 2s 0f */ | 1499 | toc->last_session_lba = msf_to_lba(0, 2, 0); /* 0m 2s 0f */ |
1500 | } | 1500 | } |
1501 | 1501 | ||
1502 | if (drive->atapi_flags & IDE_AFLAG_TOCADDR_AS_BCD) { | 1502 | if (drive->atapi_flags & IDE_AFLAG_TOCADDR_AS_BCD) { |
1503 | /* re-read multisession information using MSF format */ | 1503 | /* re-read multisession information using MSF format */ |
1504 | stat = cdrom_read_tocentry(drive, 0, 1, 1, (char *)&ms_tmp, | 1504 | stat = cdrom_read_tocentry(drive, 0, 1, 1, (char *)&ms_tmp, |
1505 | sizeof(ms_tmp), sense); | 1505 | sizeof(ms_tmp), sense); |
1506 | if (stat) | 1506 | if (stat) |
1507 | return stat; | 1507 | return stat; |
1508 | 1508 | ||
1509 | msf_from_bcd(&ms_tmp.ent.addr.msf); | 1509 | msf_from_bcd(&ms_tmp.ent.addr.msf); |
1510 | toc->last_session_lba = msf_to_lba(ms_tmp.ent.addr.msf.minute, | 1510 | toc->last_session_lba = msf_to_lba(ms_tmp.ent.addr.msf.minute, |
1511 | ms_tmp.ent.addr.msf.second, | 1511 | ms_tmp.ent.addr.msf.second, |
1512 | ms_tmp.ent.addr.msf.frame); | 1512 | ms_tmp.ent.addr.msf.frame); |
1513 | } | 1513 | } |
1514 | 1514 | ||
1515 | toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track); | 1515 | toc->xa_flag = (ms_tmp.hdr.first_track != ms_tmp.hdr.last_track); |
1516 | 1516 | ||
1517 | /* now try to get the total cdrom capacity */ | 1517 | /* now try to get the total cdrom capacity */ |
1518 | stat = cdrom_get_last_written(cdi, &last_written); | 1518 | stat = cdrom_get_last_written(cdi, &last_written); |
1519 | if (!stat && (last_written > toc->capacity)) { | 1519 | if (!stat && (last_written > toc->capacity)) { |
1520 | toc->capacity = last_written; | 1520 | toc->capacity = last_written; |
1521 | set_capacity(info->disk, toc->capacity * sectors_per_frame); | 1521 | set_capacity(info->disk, toc->capacity * sectors_per_frame); |
1522 | drive->probed_capacity = toc->capacity * sectors_per_frame; | 1522 | drive->probed_capacity = toc->capacity * sectors_per_frame; |
1523 | } | 1523 | } |
1524 | 1524 | ||
1525 | /* Remember that we've read this stuff. */ | 1525 | /* Remember that we've read this stuff. */ |
1526 | drive->atapi_flags |= IDE_AFLAG_TOC_VALID; | 1526 | drive->atapi_flags |= IDE_AFLAG_TOC_VALID; |
1527 | 1527 | ||
1528 | return 0; | 1528 | return 0; |
1529 | } | 1529 | } |
1530 | 1530 | ||
1531 | int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf) | 1531 | int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf) |
1532 | { | 1532 | { |
1533 | struct cdrom_info *info = drive->driver_data; | 1533 | struct cdrom_info *info = drive->driver_data; |
1534 | struct cdrom_device_info *cdi = &info->devinfo; | 1534 | struct cdrom_device_info *cdi = &info->devinfo; |
1535 | struct packet_command cgc; | 1535 | struct packet_command cgc; |
1536 | int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE; | 1536 | int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE; |
1537 | 1537 | ||
1538 | if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0) | 1538 | if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0) |
1539 | size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE; | 1539 | size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE; |
1540 | 1540 | ||
1541 | init_cdrom_command(&cgc, buf, size, CGC_DATA_UNKNOWN); | 1541 | init_cdrom_command(&cgc, buf, size, CGC_DATA_UNKNOWN); |
1542 | do { | 1542 | do { |
1543 | /* we seem to get stat=0x01,err=0x00 the first time (??) */ | 1543 | /* we seem to get stat=0x01,err=0x00 the first time (??) */ |
1544 | stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0); | 1544 | stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CAPABILITIES_PAGE, 0); |
1545 | if (!stat) | 1545 | if (!stat) |
1546 | break; | 1546 | break; |
1547 | } while (--attempts); | 1547 | } while (--attempts); |
1548 | return stat; | 1548 | return stat; |
1549 | } | 1549 | } |
1550 | 1550 | ||
1551 | void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf) | 1551 | void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf) |
1552 | { | 1552 | { |
1553 | struct cdrom_info *cd = drive->driver_data; | 1553 | struct cdrom_info *cd = drive->driver_data; |
1554 | u16 curspeed, maxspeed; | 1554 | u16 curspeed, maxspeed; |
1555 | 1555 | ||
1556 | if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) { | 1556 | if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) { |
1557 | curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]); | 1557 | curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]); |
1558 | maxspeed = le16_to_cpup((__le16 *)&buf[8 + 8]); | 1558 | maxspeed = le16_to_cpup((__le16 *)&buf[8 + 8]); |
1559 | } else { | 1559 | } else { |
1560 | curspeed = be16_to_cpup((__be16 *)&buf[8 + 14]); | 1560 | curspeed = be16_to_cpup((__be16 *)&buf[8 + 14]); |
1561 | maxspeed = be16_to_cpup((__be16 *)&buf[8 + 8]); | 1561 | maxspeed = be16_to_cpup((__be16 *)&buf[8 + 8]); |
1562 | } | 1562 | } |
1563 | 1563 | ||
1564 | cd->current_speed = (curspeed + (176/2)) / 176; | 1564 | cd->current_speed = (curspeed + (176/2)) / 176; |
1565 | cd->max_speed = (maxspeed + (176/2)) / 176; | 1565 | cd->max_speed = (maxspeed + (176/2)) / 176; |
1566 | } | 1566 | } |
1567 | 1567 | ||
1568 | #define IDE_CD_CAPABILITIES \ | 1568 | #define IDE_CD_CAPABILITIES \ |
1569 | (CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_SELECT_SPEED | \ | 1569 | (CDC_CLOSE_TRAY | CDC_OPEN_TRAY | CDC_LOCK | CDC_SELECT_SPEED | \ |
1570 | CDC_SELECT_DISC | CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED | \ | 1570 | CDC_SELECT_DISC | CDC_MULTI_SESSION | CDC_MCN | CDC_MEDIA_CHANGED | \ |
1571 | CDC_PLAY_AUDIO | CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R | \ | 1571 | CDC_PLAY_AUDIO | CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R | \ |
1572 | CDC_CD_RW | CDC_DVD | CDC_DVD_R | CDC_DVD_RAM | CDC_GENERIC_PACKET | \ | 1572 | CDC_CD_RW | CDC_DVD | CDC_DVD_R | CDC_DVD_RAM | CDC_GENERIC_PACKET | \ |
1573 | CDC_MO_DRIVE | CDC_MRW | CDC_MRW_W | CDC_RAM) | 1573 | CDC_MO_DRIVE | CDC_MRW | CDC_MRW_W | CDC_RAM) |
1574 | 1574 | ||
1575 | static struct cdrom_device_ops ide_cdrom_dops = { | 1575 | static struct cdrom_device_ops ide_cdrom_dops = { |
1576 | .open = ide_cdrom_open_real, | 1576 | .open = ide_cdrom_open_real, |
1577 | .release = ide_cdrom_release_real, | 1577 | .release = ide_cdrom_release_real, |
1578 | .drive_status = ide_cdrom_drive_status, | 1578 | .drive_status = ide_cdrom_drive_status, |
1579 | .media_changed = ide_cdrom_check_media_change_real, | 1579 | .media_changed = ide_cdrom_check_media_change_real, |
1580 | .tray_move = ide_cdrom_tray_move, | 1580 | .tray_move = ide_cdrom_tray_move, |
1581 | .lock_door = ide_cdrom_lock_door, | 1581 | .lock_door = ide_cdrom_lock_door, |
1582 | .select_speed = ide_cdrom_select_speed, | 1582 | .select_speed = ide_cdrom_select_speed, |
1583 | .get_last_session = ide_cdrom_get_last_session, | 1583 | .get_last_session = ide_cdrom_get_last_session, |
1584 | .get_mcn = ide_cdrom_get_mcn, | 1584 | .get_mcn = ide_cdrom_get_mcn, |
1585 | .reset = ide_cdrom_reset, | 1585 | .reset = ide_cdrom_reset, |
1586 | .audio_ioctl = ide_cdrom_audio_ioctl, | 1586 | .audio_ioctl = ide_cdrom_audio_ioctl, |
1587 | .capability = IDE_CD_CAPABILITIES, | 1587 | .capability = IDE_CD_CAPABILITIES, |
1588 | .generic_packet = ide_cdrom_packet, | 1588 | .generic_packet = ide_cdrom_packet, |
1589 | }; | 1589 | }; |
1590 | 1590 | ||
1591 | static int ide_cdrom_register(ide_drive_t *drive, int nslots) | 1591 | static int ide_cdrom_register(ide_drive_t *drive, int nslots) |
1592 | { | 1592 | { |
1593 | struct cdrom_info *info = drive->driver_data; | 1593 | struct cdrom_info *info = drive->driver_data; |
1594 | struct cdrom_device_info *devinfo = &info->devinfo; | 1594 | struct cdrom_device_info *devinfo = &info->devinfo; |
1595 | 1595 | ||
1596 | devinfo->ops = &ide_cdrom_dops; | 1596 | devinfo->ops = &ide_cdrom_dops; |
1597 | devinfo->speed = info->current_speed; | 1597 | devinfo->speed = info->current_speed; |
1598 | devinfo->capacity = nslots; | 1598 | devinfo->capacity = nslots; |
1599 | devinfo->handle = drive; | 1599 | devinfo->handle = drive; |
1600 | strcpy(devinfo->name, drive->name); | 1600 | strcpy(devinfo->name, drive->name); |
1601 | 1601 | ||
1602 | if (drive->atapi_flags & IDE_AFLAG_NO_SPEED_SELECT) | 1602 | if (drive->atapi_flags & IDE_AFLAG_NO_SPEED_SELECT) |
1603 | devinfo->mask |= CDC_SELECT_SPEED; | 1603 | devinfo->mask |= CDC_SELECT_SPEED; |
1604 | 1604 | ||
1605 | devinfo->disk = info->disk; | 1605 | devinfo->disk = info->disk; |
1606 | return register_cdrom(devinfo); | 1606 | return register_cdrom(devinfo); |
1607 | } | 1607 | } |
1608 | 1608 | ||
1609 | static int ide_cdrom_probe_capabilities(ide_drive_t *drive) | 1609 | static int ide_cdrom_probe_capabilities(ide_drive_t *drive) |
1610 | { | 1610 | { |
1611 | struct cdrom_info *cd = drive->driver_data; | 1611 | struct cdrom_info *cd = drive->driver_data; |
1612 | struct cdrom_device_info *cdi = &cd->devinfo; | 1612 | struct cdrom_device_info *cdi = &cd->devinfo; |
1613 | u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE]; | 1613 | u8 buf[ATAPI_CAPABILITIES_PAGE_SIZE]; |
1614 | mechtype_t mechtype; | 1614 | mechtype_t mechtype; |
1615 | int nslots = 1; | 1615 | int nslots = 1; |
1616 | 1616 | ||
1617 | cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | | 1617 | cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R | |
1618 | CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO | | 1618 | CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO | |
1619 | CDC_MO_DRIVE | CDC_RAM); | 1619 | CDC_MO_DRIVE | CDC_RAM); |
1620 | 1620 | ||
1621 | if (drive->media == ide_optical) { | 1621 | if (drive->media == ide_optical) { |
1622 | cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM); | 1622 | cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM); |
1623 | printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", | 1623 | printk(KERN_ERR "%s: ATAPI magneto-optical drive\n", |
1624 | drive->name); | 1624 | drive->name); |
1625 | return nslots; | 1625 | return nslots; |
1626 | } | 1626 | } |
1627 | 1627 | ||
1628 | if (drive->atapi_flags & IDE_AFLAG_PRE_ATAPI12) { | 1628 | if (drive->atapi_flags & IDE_AFLAG_PRE_ATAPI12) { |
1629 | drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT; | 1629 | drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT; |
1630 | cdi->mask &= ~CDC_PLAY_AUDIO; | 1630 | cdi->mask &= ~CDC_PLAY_AUDIO; |
1631 | return nslots; | 1631 | return nslots; |
1632 | } | 1632 | } |
1633 | 1633 | ||
1634 | /* | 1634 | /* |
1635 | * We have to cheat a little here. the packet will eventually be queued | 1635 | * We have to cheat a little here. the packet will eventually be queued |
1636 | * with ide_cdrom_packet(), which extracts the drive from cdi->handle. | 1636 | * with ide_cdrom_packet(), which extracts the drive from cdi->handle. |
1637 | * Since this device hasn't been registered with the Uniform layer yet, | 1637 | * Since this device hasn't been registered with the Uniform layer yet, |
1638 | * it can't do this. Same goes for cdi->ops. | 1638 | * it can't do this. Same goes for cdi->ops. |
1639 | */ | 1639 | */ |
1640 | cdi->handle = drive; | 1640 | cdi->handle = drive; |
1641 | cdi->ops = &ide_cdrom_dops; | 1641 | cdi->ops = &ide_cdrom_dops; |
1642 | 1642 | ||
1643 | if (ide_cdrom_get_capabilities(drive, buf)) | 1643 | if (ide_cdrom_get_capabilities(drive, buf)) |
1644 | return 0; | 1644 | return 0; |
1645 | 1645 | ||
1646 | if ((buf[8 + 6] & 0x01) == 0) | 1646 | if ((buf[8 + 6] & 0x01) == 0) |
1647 | drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK; | 1647 | drive->atapi_flags |= IDE_AFLAG_NO_DOORLOCK; |
1648 | if (buf[8 + 6] & 0x08) | 1648 | if (buf[8 + 6] & 0x08) |
1649 | drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT; | 1649 | drive->atapi_flags &= ~IDE_AFLAG_NO_EJECT; |
1650 | if (buf[8 + 3] & 0x01) | 1650 | if (buf[8 + 3] & 0x01) |
1651 | cdi->mask &= ~CDC_CD_R; | 1651 | cdi->mask &= ~CDC_CD_R; |
1652 | if (buf[8 + 3] & 0x02) | 1652 | if (buf[8 + 3] & 0x02) |
1653 | cdi->mask &= ~(CDC_CD_RW | CDC_RAM); | 1653 | cdi->mask &= ~(CDC_CD_RW | CDC_RAM); |
1654 | if (buf[8 + 2] & 0x38) | 1654 | if (buf[8 + 2] & 0x38) |
1655 | cdi->mask &= ~CDC_DVD; | 1655 | cdi->mask &= ~CDC_DVD; |
1656 | if (buf[8 + 3] & 0x20) | 1656 | if (buf[8 + 3] & 0x20) |
1657 | cdi->mask &= ~(CDC_DVD_RAM | CDC_RAM); | 1657 | cdi->mask &= ~(CDC_DVD_RAM | CDC_RAM); |
1658 | if (buf[8 + 3] & 0x10) | 1658 | if (buf[8 + 3] & 0x10) |
1659 | cdi->mask &= ~CDC_DVD_R; | 1659 | cdi->mask &= ~CDC_DVD_R; |
1660 | if ((buf[8 + 4] & 0x01) || (drive->atapi_flags & IDE_AFLAG_PLAY_AUDIO_OK)) | 1660 | if ((buf[8 + 4] & 0x01) || (drive->atapi_flags & IDE_AFLAG_PLAY_AUDIO_OK)) |
1661 | cdi->mask &= ~CDC_PLAY_AUDIO; | 1661 | cdi->mask &= ~CDC_PLAY_AUDIO; |
1662 | 1662 | ||
1663 | mechtype = buf[8 + 6] >> 5; | 1663 | mechtype = buf[8 + 6] >> 5; |
1664 | if (mechtype == mechtype_caddy || mechtype == mechtype_popup) | 1664 | if (mechtype == mechtype_caddy || |
1665 | mechtype == mechtype_popup || | ||
1666 | (drive->atapi_flags & IDE_AFLAG_NO_AUTOCLOSE)) | ||
1665 | cdi->mask |= CDC_CLOSE_TRAY; | 1667 | cdi->mask |= CDC_CLOSE_TRAY; |
1666 | 1668 | ||
1667 | if (cdi->sanyo_slot > 0) { | 1669 | if (cdi->sanyo_slot > 0) { |
1668 | cdi->mask &= ~CDC_SELECT_DISC; | 1670 | cdi->mask &= ~CDC_SELECT_DISC; |
1669 | nslots = 3; | 1671 | nslots = 3; |
1670 | } else if (mechtype == mechtype_individual_changer || | 1672 | } else if (mechtype == mechtype_individual_changer || |
1671 | mechtype == mechtype_cartridge_changer) { | 1673 | mechtype == mechtype_cartridge_changer) { |
1672 | nslots = cdrom_number_of_slots(cdi); | 1674 | nslots = cdrom_number_of_slots(cdi); |
1673 | if (nslots > 1) | 1675 | if (nslots > 1) |
1674 | cdi->mask &= ~CDC_SELECT_DISC; | 1676 | cdi->mask &= ~CDC_SELECT_DISC; |
1675 | } | 1677 | } |
1676 | 1678 | ||
1677 | ide_cdrom_update_speed(drive, buf); | 1679 | ide_cdrom_update_speed(drive, buf); |
1678 | 1680 | ||
1679 | printk(KERN_INFO "%s: ATAPI", drive->name); | 1681 | printk(KERN_INFO "%s: ATAPI", drive->name); |
1680 | 1682 | ||
1681 | /* don't print speed if the drive reported 0 */ | 1683 | /* don't print speed if the drive reported 0 */ |
1682 | if (cd->max_speed) | 1684 | if (cd->max_speed) |
1683 | printk(KERN_CONT " %dX", cd->max_speed); | 1685 | printk(KERN_CONT " %dX", cd->max_speed); |
1684 | 1686 | ||
1685 | printk(KERN_CONT " %s", (cdi->mask & CDC_DVD) ? "CD-ROM" : "DVD-ROM"); | 1687 | printk(KERN_CONT " %s", (cdi->mask & CDC_DVD) ? "CD-ROM" : "DVD-ROM"); |
1686 | 1688 | ||
1687 | if ((cdi->mask & CDC_DVD_R) == 0 || (cdi->mask & CDC_DVD_RAM) == 0) | 1689 | if ((cdi->mask & CDC_DVD_R) == 0 || (cdi->mask & CDC_DVD_RAM) == 0) |
1688 | printk(KERN_CONT " DVD%s%s", | 1690 | printk(KERN_CONT " DVD%s%s", |
1689 | (cdi->mask & CDC_DVD_R) ? "" : "-R", | 1691 | (cdi->mask & CDC_DVD_R) ? "" : "-R", |
1690 | (cdi->mask & CDC_DVD_RAM) ? "" : "-RAM"); | 1692 | (cdi->mask & CDC_DVD_RAM) ? "" : "-RAM"); |
1691 | 1693 | ||
1692 | if ((cdi->mask & CDC_CD_R) == 0 || (cdi->mask & CDC_CD_RW) == 0) | 1694 | if ((cdi->mask & CDC_CD_R) == 0 || (cdi->mask & CDC_CD_RW) == 0) |
1693 | printk(KERN_CONT " CD%s%s", | 1695 | printk(KERN_CONT " CD%s%s", |
1694 | (cdi->mask & CDC_CD_R) ? "" : "-R", | 1696 | (cdi->mask & CDC_CD_R) ? "" : "-R", |
1695 | (cdi->mask & CDC_CD_RW) ? "" : "/RW"); | 1697 | (cdi->mask & CDC_CD_RW) ? "" : "/RW"); |
1696 | 1698 | ||
1697 | if ((cdi->mask & CDC_SELECT_DISC) == 0) | 1699 | if ((cdi->mask & CDC_SELECT_DISC) == 0) |
1698 | printk(KERN_CONT " changer w/%d slots", nslots); | 1700 | printk(KERN_CONT " changer w/%d slots", nslots); |
1699 | else | 1701 | else |
1700 | printk(KERN_CONT " drive"); | 1702 | printk(KERN_CONT " drive"); |
1701 | 1703 | ||
1702 | printk(KERN_CONT ", %dkB Cache\n", be16_to_cpup((__be16 *)&buf[8 + 12])); | 1704 | printk(KERN_CONT ", %dkB Cache\n", be16_to_cpup((__be16 *)&buf[8 + 12])); |
1703 | 1705 | ||
1704 | return nslots; | 1706 | return nslots; |
1705 | } | 1707 | } |
1706 | 1708 | ||
1707 | /* standard prep_rq_fn that builds 10 byte cmds */ | 1709 | /* standard prep_rq_fn that builds 10 byte cmds */ |
1708 | static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq) | 1710 | static int ide_cdrom_prep_fs(struct request_queue *q, struct request *rq) |
1709 | { | 1711 | { |
1710 | int hard_sect = queue_hardsect_size(q); | 1712 | int hard_sect = queue_hardsect_size(q); |
1711 | long block = (long)rq->hard_sector / (hard_sect >> 9); | 1713 | long block = (long)rq->hard_sector / (hard_sect >> 9); |
1712 | unsigned long blocks = rq->hard_nr_sectors / (hard_sect >> 9); | 1714 | unsigned long blocks = rq->hard_nr_sectors / (hard_sect >> 9); |
1713 | 1715 | ||
1714 | memset(rq->cmd, 0, BLK_MAX_CDB); | 1716 | memset(rq->cmd, 0, BLK_MAX_CDB); |
1715 | 1717 | ||
1716 | if (rq_data_dir(rq) == READ) | 1718 | if (rq_data_dir(rq) == READ) |
1717 | rq->cmd[0] = GPCMD_READ_10; | 1719 | rq->cmd[0] = GPCMD_READ_10; |
1718 | else | 1720 | else |
1719 | rq->cmd[0] = GPCMD_WRITE_10; | 1721 | rq->cmd[0] = GPCMD_WRITE_10; |
1720 | 1722 | ||
1721 | /* | 1723 | /* |
1722 | * fill in lba | 1724 | * fill in lba |
1723 | */ | 1725 | */ |
1724 | rq->cmd[2] = (block >> 24) & 0xff; | 1726 | rq->cmd[2] = (block >> 24) & 0xff; |
1725 | rq->cmd[3] = (block >> 16) & 0xff; | 1727 | rq->cmd[3] = (block >> 16) & 0xff; |
1726 | rq->cmd[4] = (block >> 8) & 0xff; | 1728 | rq->cmd[4] = (block >> 8) & 0xff; |
1727 | rq->cmd[5] = block & 0xff; | 1729 | rq->cmd[5] = block & 0xff; |
1728 | 1730 | ||
1729 | /* | 1731 | /* |
1730 | * and transfer length | 1732 | * and transfer length |
1731 | */ | 1733 | */ |
1732 | rq->cmd[7] = (blocks >> 8) & 0xff; | 1734 | rq->cmd[7] = (blocks >> 8) & 0xff; |
1733 | rq->cmd[8] = blocks & 0xff; | 1735 | rq->cmd[8] = blocks & 0xff; |
1734 | rq->cmd_len = 10; | 1736 | rq->cmd_len = 10; |
1735 | return BLKPREP_OK; | 1737 | return BLKPREP_OK; |
1736 | } | 1738 | } |
1737 | 1739 | ||
1738 | /* | 1740 | /* |
1739 | * Most of the SCSI commands are supported directly by ATAPI devices. | 1741 | * Most of the SCSI commands are supported directly by ATAPI devices. |
1740 | * This transform handles the few exceptions. | 1742 | * This transform handles the few exceptions. |
1741 | */ | 1743 | */ |
1742 | static int ide_cdrom_prep_pc(struct request *rq) | 1744 | static int ide_cdrom_prep_pc(struct request *rq) |
1743 | { | 1745 | { |
1744 | u8 *c = rq->cmd; | 1746 | u8 *c = rq->cmd; |
1745 | 1747 | ||
1746 | /* transform 6-byte read/write commands to the 10-byte version */ | 1748 | /* transform 6-byte read/write commands to the 10-byte version */ |
1747 | if (c[0] == READ_6 || c[0] == WRITE_6) { | 1749 | if (c[0] == READ_6 || c[0] == WRITE_6) { |
1748 | c[8] = c[4]; | 1750 | c[8] = c[4]; |
1749 | c[5] = c[3]; | 1751 | c[5] = c[3]; |
1750 | c[4] = c[2]; | 1752 | c[4] = c[2]; |
1751 | c[3] = c[1] & 0x1f; | 1753 | c[3] = c[1] & 0x1f; |
1752 | c[2] = 0; | 1754 | c[2] = 0; |
1753 | c[1] &= 0xe0; | 1755 | c[1] &= 0xe0; |
1754 | c[0] += (READ_10 - READ_6); | 1756 | c[0] += (READ_10 - READ_6); |
1755 | rq->cmd_len = 10; | 1757 | rq->cmd_len = 10; |
1756 | return BLKPREP_OK; | 1758 | return BLKPREP_OK; |
1757 | } | 1759 | } |
1758 | 1760 | ||
1759 | /* | 1761 | /* |
1760 | * it's silly to pretend we understand 6-byte sense commands, just | 1762 | * it's silly to pretend we understand 6-byte sense commands, just |
1761 | * reject with ILLEGAL_REQUEST and the caller should take the | 1763 | * reject with ILLEGAL_REQUEST and the caller should take the |
1762 | * appropriate action | 1764 | * appropriate action |
1763 | */ | 1765 | */ |
1764 | if (c[0] == MODE_SENSE || c[0] == MODE_SELECT) { | 1766 | if (c[0] == MODE_SENSE || c[0] == MODE_SELECT) { |
1765 | rq->errors = ILLEGAL_REQUEST; | 1767 | rq->errors = ILLEGAL_REQUEST; |
1766 | return BLKPREP_KILL; | 1768 | return BLKPREP_KILL; |
1767 | } | 1769 | } |
1768 | 1770 | ||
1769 | return BLKPREP_OK; | 1771 | return BLKPREP_OK; |
1770 | } | 1772 | } |
1771 | 1773 | ||
1772 | static int ide_cdrom_prep_fn(struct request_queue *q, struct request *rq) | 1774 | static int ide_cdrom_prep_fn(struct request_queue *q, struct request *rq) |
1773 | { | 1775 | { |
1774 | if (blk_fs_request(rq)) | 1776 | if (blk_fs_request(rq)) |
1775 | return ide_cdrom_prep_fs(q, rq); | 1777 | return ide_cdrom_prep_fs(q, rq); |
1776 | else if (blk_pc_request(rq)) | 1778 | else if (blk_pc_request(rq)) |
1777 | return ide_cdrom_prep_pc(rq); | 1779 | return ide_cdrom_prep_pc(rq); |
1778 | 1780 | ||
1779 | return 0; | 1781 | return 0; |
1780 | } | 1782 | } |
1781 | 1783 | ||
1782 | struct cd_list_entry { | 1784 | struct cd_list_entry { |
1783 | const char *id_model; | 1785 | const char *id_model; |
1784 | const char *id_firmware; | 1786 | const char *id_firmware; |
1785 | unsigned int cd_flags; | 1787 | unsigned int cd_flags; |
1786 | }; | 1788 | }; |
1787 | 1789 | ||
1788 | #ifdef CONFIG_IDE_PROC_FS | 1790 | #ifdef CONFIG_IDE_PROC_FS |
1789 | static sector_t ide_cdrom_capacity(ide_drive_t *drive) | 1791 | static sector_t ide_cdrom_capacity(ide_drive_t *drive) |
1790 | { | 1792 | { |
1791 | unsigned long capacity, sectors_per_frame; | 1793 | unsigned long capacity, sectors_per_frame; |
1792 | 1794 | ||
1793 | if (cdrom_read_capacity(drive, &capacity, §ors_per_frame, NULL)) | 1795 | if (cdrom_read_capacity(drive, &capacity, §ors_per_frame, NULL)) |
1794 | return 0; | 1796 | return 0; |
1795 | 1797 | ||
1796 | return capacity * sectors_per_frame; | 1798 | return capacity * sectors_per_frame; |
1797 | } | 1799 | } |
1798 | 1800 | ||
1799 | static int proc_idecd_read_capacity(char *page, char **start, off_t off, | 1801 | static int proc_idecd_read_capacity(char *page, char **start, off_t off, |
1800 | int count, int *eof, void *data) | 1802 | int count, int *eof, void *data) |
1801 | { | 1803 | { |
1802 | ide_drive_t *drive = data; | 1804 | ide_drive_t *drive = data; |
1803 | int len; | 1805 | int len; |
1804 | 1806 | ||
1805 | len = sprintf(page, "%llu\n", (long long)ide_cdrom_capacity(drive)); | 1807 | len = sprintf(page, "%llu\n", (long long)ide_cdrom_capacity(drive)); |
1806 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | 1808 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); |
1807 | } | 1809 | } |
1808 | 1810 | ||
1809 | static ide_proc_entry_t idecd_proc[] = { | 1811 | static ide_proc_entry_t idecd_proc[] = { |
1810 | { "capacity", S_IFREG|S_IRUGO, proc_idecd_read_capacity, NULL }, | 1812 | { "capacity", S_IFREG|S_IRUGO, proc_idecd_read_capacity, NULL }, |
1811 | { NULL, 0, NULL, NULL } | 1813 | { NULL, 0, NULL, NULL } |
1812 | }; | 1814 | }; |
1813 | 1815 | ||
1814 | static void ide_cdrom_add_settings(ide_drive_t *drive) | 1816 | static void ide_cdrom_add_settings(ide_drive_t *drive) |
1815 | { | 1817 | { |
1816 | ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, | 1818 | ide_add_setting(drive, "dsc_overlap", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, |
1817 | &drive->dsc_overlap, NULL); | 1819 | &drive->dsc_overlap, NULL); |
1818 | } | 1820 | } |
1819 | #else | 1821 | #else |
1820 | static inline void ide_cdrom_add_settings(ide_drive_t *drive) { ; } | 1822 | static inline void ide_cdrom_add_settings(ide_drive_t *drive) { ; } |
1821 | #endif | 1823 | #endif |
1822 | 1824 | ||
1823 | static const struct cd_list_entry ide_cd_quirks_list[] = { | 1825 | static const struct cd_list_entry ide_cd_quirks_list[] = { |
1824 | /* Limit transfer size per interrupt. */ | 1826 | /* Limit transfer size per interrupt. */ |
1825 | { "SAMSUNG CD-ROM SCR-2430", NULL, IDE_AFLAG_LIMIT_NFRAMES }, | 1827 | { "SAMSUNG CD-ROM SCR-2430", NULL, IDE_AFLAG_LIMIT_NFRAMES }, |
1826 | { "SAMSUNG CD-ROM SCR-2432", NULL, IDE_AFLAG_LIMIT_NFRAMES }, | 1828 | { "SAMSUNG CD-ROM SCR-2432", NULL, IDE_AFLAG_LIMIT_NFRAMES }, |
1827 | /* SCR-3231 doesn't support the SET_CD_SPEED command. */ | 1829 | /* SCR-3231 doesn't support the SET_CD_SPEED command. */ |
1828 | { "SAMSUNG CD-ROM SCR-3231", NULL, IDE_AFLAG_NO_SPEED_SELECT }, | 1830 | { "SAMSUNG CD-ROM SCR-3231", NULL, IDE_AFLAG_NO_SPEED_SELECT }, |
1829 | /* Old NEC260 (not R) was released before ATAPI 1.2 spec. */ | 1831 | /* Old NEC260 (not R) was released before ATAPI 1.2 spec. */ |
1830 | { "NEC CD-ROM DRIVE:260", "1.01", IDE_AFLAG_TOCADDR_AS_BCD | | 1832 | { "NEC CD-ROM DRIVE:260", "1.01", IDE_AFLAG_TOCADDR_AS_BCD | |
1831 | IDE_AFLAG_PRE_ATAPI12, }, | 1833 | IDE_AFLAG_PRE_ATAPI12, }, |
1832 | /* Vertos 300, some versions of this drive like to talk BCD. */ | 1834 | /* Vertos 300, some versions of this drive like to talk BCD. */ |
1833 | { "V003S0DS", NULL, IDE_AFLAG_VERTOS_300_SSD, }, | 1835 | { "V003S0DS", NULL, IDE_AFLAG_VERTOS_300_SSD, }, |
1834 | /* Vertos 600 ESD. */ | 1836 | /* Vertos 600 ESD. */ |
1835 | { "V006E0DS", NULL, IDE_AFLAG_VERTOS_600_ESD, }, | 1837 | { "V006E0DS", NULL, IDE_AFLAG_VERTOS_600_ESD, }, |
1836 | /* | 1838 | /* |
1837 | * Sanyo 3 CD changer uses a non-standard command for CD changing | 1839 | * Sanyo 3 CD changer uses a non-standard command for CD changing |
1838 | * (by default standard ATAPI support for CD changers is used). | 1840 | * (by default standard ATAPI support for CD changers is used). |
1839 | */ | 1841 | */ |
1840 | { "CD-ROM CDR-C3 G", NULL, IDE_AFLAG_SANYO_3CD }, | 1842 | { "CD-ROM CDR-C3 G", NULL, IDE_AFLAG_SANYO_3CD }, |
1841 | { "CD-ROM CDR-C3G", NULL, IDE_AFLAG_SANYO_3CD }, | 1843 | { "CD-ROM CDR-C3G", NULL, IDE_AFLAG_SANYO_3CD }, |
1842 | { "CD-ROM CDR_C36", NULL, IDE_AFLAG_SANYO_3CD }, | 1844 | { "CD-ROM CDR_C36", NULL, IDE_AFLAG_SANYO_3CD }, |
1843 | /* Stingray 8X CD-ROM. */ | 1845 | /* Stingray 8X CD-ROM. */ |
1844 | { "STINGRAY 8422 IDE 8X CD-ROM 7-27-95", NULL, IDE_AFLAG_PRE_ATAPI12 }, | 1846 | { "STINGRAY 8422 IDE 8X CD-ROM 7-27-95", NULL, IDE_AFLAG_PRE_ATAPI12 }, |
1845 | /* | 1847 | /* |
1846 | * ACER 50X CD-ROM and WPI 32X CD-ROM require the full spec length | 1848 | * ACER 50X CD-ROM and WPI 32X CD-ROM require the full spec length |
1847 | * mode sense page capabilities size, but older drives break. | 1849 | * mode sense page capabilities size, but older drives break. |
1848 | */ | 1850 | */ |
1849 | { "ATAPI CD ROM DRIVE 50X MAX", NULL, IDE_AFLAG_FULL_CAPS_PAGE }, | 1851 | { "ATAPI CD ROM DRIVE 50X MAX", NULL, IDE_AFLAG_FULL_CAPS_PAGE }, |
1850 | { "WPI CDS-32X", NULL, IDE_AFLAG_FULL_CAPS_PAGE }, | 1852 | { "WPI CDS-32X", NULL, IDE_AFLAG_FULL_CAPS_PAGE }, |
1851 | /* ACER/AOpen 24X CD-ROM has the speed fields byte-swapped. */ | 1853 | /* ACER/AOpen 24X CD-ROM has the speed fields byte-swapped. */ |
1852 | { "", "241N", IDE_AFLAG_LE_SPEED_FIELDS }, | 1854 | { "", "241N", IDE_AFLAG_LE_SPEED_FIELDS }, |
1853 | /* | 1855 | /* |
1854 | * Some drives used by Apple don't advertise audio play | 1856 | * Some drives used by Apple don't advertise audio play |
1855 | * but they do support reading TOC & audio datas. | 1857 | * but they do support reading TOC & audio datas. |
1856 | */ | 1858 | */ |
1857 | { "MATSHITADVD-ROM SR-8187", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, | 1859 | { "MATSHITADVD-ROM SR-8187", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, |
1858 | { "MATSHITADVD-ROM SR-8186", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, | 1860 | { "MATSHITADVD-ROM SR-8186", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, |
1859 | { "MATSHITADVD-ROM SR-8176", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, | 1861 | { "MATSHITADVD-ROM SR-8176", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, |
1860 | { "MATSHITADVD-ROM SR-8174", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, | 1862 | { "MATSHITADVD-ROM SR-8174", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, |
1861 | { "Optiarc DVD RW AD-5200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, | 1863 | { "Optiarc DVD RW AD-5200A", NULL, IDE_AFLAG_PLAY_AUDIO_OK }, |
1864 | { "Optiarc DVD RW AD-7543A", NULL, IDE_AFLAG_NO_AUTOCLOSE }, | ||
1862 | { NULL, NULL, 0 } | 1865 | { NULL, NULL, 0 } |
1863 | }; | 1866 | }; |
1864 | 1867 | ||
1865 | static unsigned int ide_cd_flags(struct hd_driveid *id) | 1868 | static unsigned int ide_cd_flags(struct hd_driveid *id) |
1866 | { | 1869 | { |
1867 | const struct cd_list_entry *cle = ide_cd_quirks_list; | 1870 | const struct cd_list_entry *cle = ide_cd_quirks_list; |
1868 | 1871 | ||
1869 | while (cle->id_model) { | 1872 | while (cle->id_model) { |
1870 | if (strcmp(cle->id_model, id->model) == 0 && | 1873 | if (strcmp(cle->id_model, id->model) == 0 && |
1871 | (cle->id_firmware == NULL || | 1874 | (cle->id_firmware == NULL || |
1872 | strstr(id->fw_rev, cle->id_firmware))) | 1875 | strstr(id->fw_rev, cle->id_firmware))) |
1873 | return cle->cd_flags; | 1876 | return cle->cd_flags; |
1874 | cle++; | 1877 | cle++; |
1875 | } | 1878 | } |
1876 | 1879 | ||
1877 | return 0; | 1880 | return 0; |
1878 | } | 1881 | } |
1879 | 1882 | ||
1880 | static int ide_cdrom_setup(ide_drive_t *drive) | 1883 | static int ide_cdrom_setup(ide_drive_t *drive) |
1881 | { | 1884 | { |
1882 | struct cdrom_info *cd = drive->driver_data; | 1885 | struct cdrom_info *cd = drive->driver_data; |
1883 | struct cdrom_device_info *cdi = &cd->devinfo; | 1886 | struct cdrom_device_info *cdi = &cd->devinfo; |
1884 | struct hd_driveid *id = drive->id; | 1887 | struct hd_driveid *id = drive->id; |
1885 | int nslots; | 1888 | int nslots; |
1886 | 1889 | ||
1887 | blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); | 1890 | blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn); |
1888 | blk_queue_dma_alignment(drive->queue, 31); | 1891 | blk_queue_dma_alignment(drive->queue, 31); |
1889 | blk_queue_update_dma_pad(drive->queue, 15); | 1892 | blk_queue_update_dma_pad(drive->queue, 15); |
1890 | drive->queue->unplug_delay = (1 * HZ) / 1000; | 1893 | drive->queue->unplug_delay = (1 * HZ) / 1000; |
1891 | if (!drive->queue->unplug_delay) | 1894 | if (!drive->queue->unplug_delay) |
1892 | drive->queue->unplug_delay = 1; | 1895 | drive->queue->unplug_delay = 1; |
1893 | 1896 | ||
1894 | drive->special.all = 0; | 1897 | drive->special.all = 0; |
1895 | 1898 | ||
1896 | drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT | | 1899 | drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT | |
1897 | ide_cd_flags(id); | 1900 | ide_cd_flags(id); |
1898 | 1901 | ||
1899 | if ((id->config & 0x0060) == 0x20) | 1902 | if ((id->config & 0x0060) == 0x20) |
1900 | drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT; | 1903 | drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT; |
1901 | 1904 | ||
1902 | if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) && | 1905 | if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) && |
1903 | id->fw_rev[4] == '1' && id->fw_rev[6] <= '2') | 1906 | id->fw_rev[4] == '1' && id->fw_rev[6] <= '2') |
1904 | drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD | | 1907 | drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD | |
1905 | IDE_AFLAG_TOCADDR_AS_BCD); | 1908 | IDE_AFLAG_TOCADDR_AS_BCD); |
1906 | else if ((drive->atapi_flags & IDE_AFLAG_VERTOS_600_ESD) && | 1909 | else if ((drive->atapi_flags & IDE_AFLAG_VERTOS_600_ESD) && |
1907 | id->fw_rev[4] == '1' && id->fw_rev[6] <= '2') | 1910 | id->fw_rev[4] == '1' && id->fw_rev[6] <= '2') |
1908 | drive->atapi_flags |= IDE_AFLAG_TOCTRACKS_AS_BCD; | 1911 | drive->atapi_flags |= IDE_AFLAG_TOCTRACKS_AS_BCD; |
1909 | else if (drive->atapi_flags & IDE_AFLAG_SANYO_3CD) | 1912 | else if (drive->atapi_flags & IDE_AFLAG_SANYO_3CD) |
1910 | /* 3 => use CD in slot 0 */ | 1913 | /* 3 => use CD in slot 0 */ |
1911 | cdi->sanyo_slot = 3; | 1914 | cdi->sanyo_slot = 3; |
1912 | 1915 | ||
1913 | nslots = ide_cdrom_probe_capabilities(drive); | 1916 | nslots = ide_cdrom_probe_capabilities(drive); |
1914 | 1917 | ||
1915 | /* set correct block size */ | 1918 | /* set correct block size */ |
1916 | blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE); | 1919 | blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE); |
1917 | 1920 | ||
1918 | drive->dsc_overlap = (drive->next != drive); | 1921 | drive->dsc_overlap = (drive->next != drive); |
1919 | 1922 | ||
1920 | if (ide_cdrom_register(drive, nslots)) { | 1923 | if (ide_cdrom_register(drive, nslots)) { |
1921 | printk(KERN_ERR "%s: %s failed to register device with the" | 1924 | printk(KERN_ERR "%s: %s failed to register device with the" |
1922 | " cdrom driver.\n", drive->name, __func__); | 1925 | " cdrom driver.\n", drive->name, __func__); |
1923 | cd->devinfo.handle = NULL; | 1926 | cd->devinfo.handle = NULL; |
1924 | return 1; | 1927 | return 1; |
1925 | } | 1928 | } |
1926 | ide_cdrom_add_settings(drive); | 1929 | ide_cdrom_add_settings(drive); |
1927 | return 0; | 1930 | return 0; |
1928 | } | 1931 | } |
1929 | 1932 | ||
1930 | static void ide_cd_remove(ide_drive_t *drive) | 1933 | static void ide_cd_remove(ide_drive_t *drive) |
1931 | { | 1934 | { |
1932 | struct cdrom_info *info = drive->driver_data; | 1935 | struct cdrom_info *info = drive->driver_data; |
1933 | 1936 | ||
1934 | ide_proc_unregister_driver(drive, info->driver); | 1937 | ide_proc_unregister_driver(drive, info->driver); |
1935 | 1938 | ||
1936 | del_gendisk(info->disk); | 1939 | del_gendisk(info->disk); |
1937 | 1940 | ||
1938 | ide_cd_put(info); | 1941 | ide_cd_put(info); |
1939 | } | 1942 | } |
1940 | 1943 | ||
1941 | static void ide_cd_release(struct kref *kref) | 1944 | static void ide_cd_release(struct kref *kref) |
1942 | { | 1945 | { |
1943 | struct cdrom_info *info = to_ide_cd(kref); | 1946 | struct cdrom_info *info = to_ide_cd(kref); |
1944 | struct cdrom_device_info *devinfo = &info->devinfo; | 1947 | struct cdrom_device_info *devinfo = &info->devinfo; |
1945 | ide_drive_t *drive = info->drive; | 1948 | ide_drive_t *drive = info->drive; |
1946 | struct gendisk *g = info->disk; | 1949 | struct gendisk *g = info->disk; |
1947 | 1950 | ||
1948 | kfree(info->toc); | 1951 | kfree(info->toc); |
1949 | if (devinfo->handle == drive) | 1952 | if (devinfo->handle == drive) |
1950 | unregister_cdrom(devinfo); | 1953 | unregister_cdrom(devinfo); |
1951 | drive->dsc_overlap = 0; | 1954 | drive->dsc_overlap = 0; |
1952 | drive->driver_data = NULL; | 1955 | drive->driver_data = NULL; |
1953 | blk_queue_prep_rq(drive->queue, NULL); | 1956 | blk_queue_prep_rq(drive->queue, NULL); |
1954 | g->private_data = NULL; | 1957 | g->private_data = NULL; |
1955 | put_disk(g); | 1958 | put_disk(g); |
1956 | kfree(info); | 1959 | kfree(info); |
1957 | } | 1960 | } |
1958 | 1961 | ||
1959 | static int ide_cd_probe(ide_drive_t *); | 1962 | static int ide_cd_probe(ide_drive_t *); |
1960 | 1963 | ||
1961 | static ide_driver_t ide_cdrom_driver = { | 1964 | static ide_driver_t ide_cdrom_driver = { |
1962 | .gen_driver = { | 1965 | .gen_driver = { |
1963 | .owner = THIS_MODULE, | 1966 | .owner = THIS_MODULE, |
1964 | .name = "ide-cdrom", | 1967 | .name = "ide-cdrom", |
1965 | .bus = &ide_bus_type, | 1968 | .bus = &ide_bus_type, |
1966 | }, | 1969 | }, |
1967 | .probe = ide_cd_probe, | 1970 | .probe = ide_cd_probe, |
1968 | .remove = ide_cd_remove, | 1971 | .remove = ide_cd_remove, |
1969 | .version = IDECD_VERSION, | 1972 | .version = IDECD_VERSION, |
1970 | .media = ide_cdrom, | 1973 | .media = ide_cdrom, |
1971 | .supports_dsc_overlap = 1, | 1974 | .supports_dsc_overlap = 1, |
1972 | .do_request = ide_cd_do_request, | 1975 | .do_request = ide_cd_do_request, |
1973 | .end_request = ide_end_request, | 1976 | .end_request = ide_end_request, |
1974 | .error = __ide_error, | 1977 | .error = __ide_error, |
1975 | #ifdef CONFIG_IDE_PROC_FS | 1978 | #ifdef CONFIG_IDE_PROC_FS |
1976 | .proc = idecd_proc, | 1979 | .proc = idecd_proc, |
1977 | #endif | 1980 | #endif |
1978 | }; | 1981 | }; |
1979 | 1982 | ||
1980 | static int idecd_open(struct inode *inode, struct file *file) | 1983 | static int idecd_open(struct inode *inode, struct file *file) |
1981 | { | 1984 | { |
1982 | struct gendisk *disk = inode->i_bdev->bd_disk; | 1985 | struct gendisk *disk = inode->i_bdev->bd_disk; |
1983 | struct cdrom_info *info; | 1986 | struct cdrom_info *info; |
1984 | int rc = -ENOMEM; | 1987 | int rc = -ENOMEM; |
1985 | 1988 | ||
1986 | info = ide_cd_get(disk); | 1989 | info = ide_cd_get(disk); |
1987 | if (!info) | 1990 | if (!info) |
1988 | return -ENXIO; | 1991 | return -ENXIO; |
1989 | 1992 | ||
1990 | rc = cdrom_open(&info->devinfo, inode, file); | 1993 | rc = cdrom_open(&info->devinfo, inode, file); |
1991 | 1994 | ||
1992 | if (rc < 0) | 1995 | if (rc < 0) |
1993 | ide_cd_put(info); | 1996 | ide_cd_put(info); |
1994 | 1997 | ||
1995 | return rc; | 1998 | return rc; |
1996 | } | 1999 | } |
1997 | 2000 | ||
1998 | static int idecd_release(struct inode *inode, struct file *file) | 2001 | static int idecd_release(struct inode *inode, struct file *file) |
1999 | { | 2002 | { |
2000 | struct gendisk *disk = inode->i_bdev->bd_disk; | 2003 | struct gendisk *disk = inode->i_bdev->bd_disk; |
2001 | struct cdrom_info *info = ide_cd_g(disk); | 2004 | struct cdrom_info *info = ide_cd_g(disk); |
2002 | 2005 | ||
2003 | cdrom_release(&info->devinfo, file); | 2006 | cdrom_release(&info->devinfo, file); |
2004 | 2007 | ||
2005 | ide_cd_put(info); | 2008 | ide_cd_put(info); |
2006 | 2009 | ||
2007 | return 0; | 2010 | return 0; |
2008 | } | 2011 | } |
2009 | 2012 | ||
2010 | static int idecd_set_spindown(struct cdrom_device_info *cdi, unsigned long arg) | 2013 | static int idecd_set_spindown(struct cdrom_device_info *cdi, unsigned long arg) |
2011 | { | 2014 | { |
2012 | struct packet_command cgc; | 2015 | struct packet_command cgc; |
2013 | char buffer[16]; | 2016 | char buffer[16]; |
2014 | int stat; | 2017 | int stat; |
2015 | char spindown; | 2018 | char spindown; |
2016 | 2019 | ||
2017 | if (copy_from_user(&spindown, (void __user *)arg, sizeof(char))) | 2020 | if (copy_from_user(&spindown, (void __user *)arg, sizeof(char))) |
2018 | return -EFAULT; | 2021 | return -EFAULT; |
2019 | 2022 | ||
2020 | init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN); | 2023 | init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN); |
2021 | 2024 | ||
2022 | stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0); | 2025 | stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0); |
2023 | if (stat) | 2026 | if (stat) |
2024 | return stat; | 2027 | return stat; |
2025 | 2028 | ||
2026 | buffer[11] = (buffer[11] & 0xf0) | (spindown & 0x0f); | 2029 | buffer[11] = (buffer[11] & 0xf0) | (spindown & 0x0f); |
2027 | return cdrom_mode_select(cdi, &cgc); | 2030 | return cdrom_mode_select(cdi, &cgc); |
2028 | } | 2031 | } |
2029 | 2032 | ||
2030 | static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg) | 2033 | static int idecd_get_spindown(struct cdrom_device_info *cdi, unsigned long arg) |
2031 | { | 2034 | { |
2032 | struct packet_command cgc; | 2035 | struct packet_command cgc; |
2033 | char buffer[16]; | 2036 | char buffer[16]; |
2034 | int stat; | 2037 | int stat; |
2035 | char spindown; | 2038 | char spindown; |
2036 | 2039 | ||
2037 | init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN); | 2040 | init_cdrom_command(&cgc, buffer, sizeof(buffer), CGC_DATA_UNKNOWN); |
2038 | 2041 | ||
2039 | stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0); | 2042 | stat = cdrom_mode_sense(cdi, &cgc, GPMODE_CDROM_PAGE, 0); |
2040 | if (stat) | 2043 | if (stat) |
2041 | return stat; | 2044 | return stat; |
2042 | 2045 | ||
2043 | spindown = buffer[11] & 0x0f; | 2046 | spindown = buffer[11] & 0x0f; |
2044 | if (copy_to_user((void __user *)arg, &spindown, sizeof(char))) | 2047 | if (copy_to_user((void __user *)arg, &spindown, sizeof(char))) |
2045 | return -EFAULT; | 2048 | return -EFAULT; |
2046 | return 0; | 2049 | return 0; |
2047 | } | 2050 | } |
2048 | 2051 | ||
2049 | static int idecd_ioctl(struct inode *inode, struct file *file, | 2052 | static int idecd_ioctl(struct inode *inode, struct file *file, |
2050 | unsigned int cmd, unsigned long arg) | 2053 | unsigned int cmd, unsigned long arg) |
2051 | { | 2054 | { |
2052 | struct block_device *bdev = inode->i_bdev; | 2055 | struct block_device *bdev = inode->i_bdev; |
2053 | struct cdrom_info *info = ide_cd_g(bdev->bd_disk); | 2056 | struct cdrom_info *info = ide_cd_g(bdev->bd_disk); |
2054 | int err; | 2057 | int err; |
2055 | 2058 | ||
2056 | switch (cmd) { | 2059 | switch (cmd) { |
2057 | case CDROMSETSPINDOWN: | 2060 | case CDROMSETSPINDOWN: |
2058 | return idecd_set_spindown(&info->devinfo, arg); | 2061 | return idecd_set_spindown(&info->devinfo, arg); |
2059 | case CDROMGETSPINDOWN: | 2062 | case CDROMGETSPINDOWN: |
2060 | return idecd_get_spindown(&info->devinfo, arg); | 2063 | return idecd_get_spindown(&info->devinfo, arg); |
2061 | default: | 2064 | default: |
2062 | break; | 2065 | break; |
2063 | } | 2066 | } |
2064 | 2067 | ||
2065 | err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg); | 2068 | err = generic_ide_ioctl(info->drive, file, bdev, cmd, arg); |
2066 | if (err == -EINVAL) | 2069 | if (err == -EINVAL) |
2067 | err = cdrom_ioctl(file, &info->devinfo, inode, cmd, arg); | 2070 | err = cdrom_ioctl(file, &info->devinfo, inode, cmd, arg); |
2068 | 2071 | ||
2069 | return err; | 2072 | return err; |
2070 | } | 2073 | } |
2071 | 2074 | ||
2072 | static int idecd_media_changed(struct gendisk *disk) | 2075 | static int idecd_media_changed(struct gendisk *disk) |
2073 | { | 2076 | { |
2074 | struct cdrom_info *info = ide_cd_g(disk); | 2077 | struct cdrom_info *info = ide_cd_g(disk); |
2075 | return cdrom_media_changed(&info->devinfo); | 2078 | return cdrom_media_changed(&info->devinfo); |
2076 | } | 2079 | } |
2077 | 2080 | ||
2078 | static int idecd_revalidate_disk(struct gendisk *disk) | 2081 | static int idecd_revalidate_disk(struct gendisk *disk) |
2079 | { | 2082 | { |
2080 | struct cdrom_info *info = ide_cd_g(disk); | 2083 | struct cdrom_info *info = ide_cd_g(disk); |
2081 | struct request_sense sense; | 2084 | struct request_sense sense; |
2082 | 2085 | ||
2083 | ide_cd_read_toc(info->drive, &sense); | 2086 | ide_cd_read_toc(info->drive, &sense); |
2084 | 2087 | ||
2085 | return 0; | 2088 | return 0; |
2086 | } | 2089 | } |
2087 | 2090 | ||
2088 | static struct block_device_operations idecd_ops = { | 2091 | static struct block_device_operations idecd_ops = { |
2089 | .owner = THIS_MODULE, | 2092 | .owner = THIS_MODULE, |
2090 | .open = idecd_open, | 2093 | .open = idecd_open, |
2091 | .release = idecd_release, | 2094 | .release = idecd_release, |
2092 | .ioctl = idecd_ioctl, | 2095 | .ioctl = idecd_ioctl, |
2093 | .media_changed = idecd_media_changed, | 2096 | .media_changed = idecd_media_changed, |
2094 | .revalidate_disk = idecd_revalidate_disk | 2097 | .revalidate_disk = idecd_revalidate_disk |
2095 | }; | 2098 | }; |
2096 | 2099 | ||
2097 | /* module options */ | 2100 | /* module options */ |
2098 | static char *ignore; | 2101 | static char *ignore; |
2099 | 2102 | ||
2100 | module_param(ignore, charp, 0400); | 2103 | module_param(ignore, charp, 0400); |
2101 | MODULE_DESCRIPTION("ATAPI CD-ROM Driver"); | 2104 | MODULE_DESCRIPTION("ATAPI CD-ROM Driver"); |
2102 | 2105 | ||
2103 | static int ide_cd_probe(ide_drive_t *drive) | 2106 | static int ide_cd_probe(ide_drive_t *drive) |
2104 | { | 2107 | { |
2105 | struct cdrom_info *info; | 2108 | struct cdrom_info *info; |
2106 | struct gendisk *g; | 2109 | struct gendisk *g; |
2107 | struct request_sense sense; | 2110 | struct request_sense sense; |
2108 | 2111 | ||
2109 | if (!strstr("ide-cdrom", drive->driver_req)) | 2112 | if (!strstr("ide-cdrom", drive->driver_req)) |
2110 | goto failed; | 2113 | goto failed; |
2111 | if (!drive->present) | 2114 | if (!drive->present) |
2112 | goto failed; | 2115 | goto failed; |
2113 | if (drive->media != ide_cdrom && drive->media != ide_optical) | 2116 | if (drive->media != ide_cdrom && drive->media != ide_optical) |
2114 | goto failed; | 2117 | goto failed; |
2115 | /* skip drives that we were told to ignore */ | 2118 | /* skip drives that we were told to ignore */ |
2116 | if (ignore != NULL) { | 2119 | if (ignore != NULL) { |
2117 | if (strstr(ignore, drive->name)) { | 2120 | if (strstr(ignore, drive->name)) { |
2118 | printk(KERN_INFO "ide-cd: ignoring drive %s\n", | 2121 | printk(KERN_INFO "ide-cd: ignoring drive %s\n", |
2119 | drive->name); | 2122 | drive->name); |
2120 | goto failed; | 2123 | goto failed; |
2121 | } | 2124 | } |
2122 | } | 2125 | } |
2123 | info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL); | 2126 | info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL); |
2124 | if (info == NULL) { | 2127 | if (info == NULL) { |
2125 | printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", | 2128 | printk(KERN_ERR "%s: Can't allocate a cdrom structure\n", |
2126 | drive->name); | 2129 | drive->name); |
2127 | goto failed; | 2130 | goto failed; |
2128 | } | 2131 | } |
2129 | 2132 | ||
2130 | g = alloc_disk(1 << PARTN_BITS); | 2133 | g = alloc_disk(1 << PARTN_BITS); |
2131 | if (!g) | 2134 | if (!g) |
2132 | goto out_free_cd; | 2135 | goto out_free_cd; |
2133 | 2136 | ||
2134 | ide_init_disk(g, drive); | 2137 | ide_init_disk(g, drive); |
2135 | 2138 | ||
2136 | ide_proc_register_driver(drive, &ide_cdrom_driver); | 2139 | ide_proc_register_driver(drive, &ide_cdrom_driver); |
2137 | 2140 | ||
2138 | kref_init(&info->kref); | 2141 | kref_init(&info->kref); |
2139 | 2142 | ||
2140 | info->drive = drive; | 2143 | info->drive = drive; |
2141 | info->driver = &ide_cdrom_driver; | 2144 | info->driver = &ide_cdrom_driver; |
2142 | info->disk = g; | 2145 | info->disk = g; |
2143 | 2146 | ||
2144 | g->private_data = &info->driver; | 2147 | g->private_data = &info->driver; |
2145 | 2148 | ||
2146 | drive->driver_data = info; | 2149 | drive->driver_data = info; |
2147 | 2150 | ||
2148 | g->minors = 1; | 2151 | g->minors = 1; |
2149 | g->driverfs_dev = &drive->gendev; | 2152 | g->driverfs_dev = &drive->gendev; |
2150 | g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE; | 2153 | g->flags = GENHD_FL_CD | GENHD_FL_REMOVABLE; |
2151 | if (ide_cdrom_setup(drive)) { | 2154 | if (ide_cdrom_setup(drive)) { |
2152 | ide_proc_unregister_driver(drive, &ide_cdrom_driver); | 2155 | ide_proc_unregister_driver(drive, &ide_cdrom_driver); |
2153 | ide_cd_release(&info->kref); | 2156 | ide_cd_release(&info->kref); |
2154 | goto failed; | 2157 | goto failed; |
2155 | } | 2158 | } |
2156 | 2159 | ||
2157 | ide_cd_read_toc(drive, &sense); | 2160 | ide_cd_read_toc(drive, &sense); |
2158 | g->fops = &idecd_ops; | 2161 | g->fops = &idecd_ops; |
2159 | g->flags |= GENHD_FL_REMOVABLE; | 2162 | g->flags |= GENHD_FL_REMOVABLE; |
2160 | add_disk(g); | 2163 | add_disk(g); |
2161 | return 0; | 2164 | return 0; |
2162 | 2165 | ||
2163 | out_free_cd: | 2166 | out_free_cd: |
2164 | kfree(info); | 2167 | kfree(info); |
2165 | failed: | 2168 | failed: |
2166 | return -ENODEV; | 2169 | return -ENODEV; |
2167 | } | 2170 | } |
2168 | 2171 | ||
2169 | static void __exit ide_cdrom_exit(void) | 2172 | static void __exit ide_cdrom_exit(void) |
2170 | { | 2173 | { |
2171 | driver_unregister(&ide_cdrom_driver.gen_driver); | 2174 | driver_unregister(&ide_cdrom_driver.gen_driver); |
2172 | } | 2175 | } |
2173 | 2176 | ||
2174 | static int __init ide_cdrom_init(void) | 2177 | static int __init ide_cdrom_init(void) |
2175 | { | 2178 | { |
2176 | return driver_register(&ide_cdrom_driver.gen_driver); | 2179 | return driver_register(&ide_cdrom_driver.gen_driver); |
2177 | } | 2180 | } |
2178 | 2181 | ||
2179 | MODULE_ALIAS("ide:*m-cdrom*"); | 2182 | MODULE_ALIAS("ide:*m-cdrom*"); |
2180 | MODULE_ALIAS("ide-cd"); | 2183 | MODULE_ALIAS("ide-cd"); |
2181 | module_init(ide_cdrom_init); | 2184 | module_init(ide_cdrom_init); |
2182 | module_exit(ide_cdrom_exit); | 2185 | module_exit(ide_cdrom_exit); |
2183 | MODULE_LICENSE("GPL"); | 2186 | MODULE_LICENSE("GPL"); |
2184 | 2187 |
include/linux/ide.h
1 | #ifndef _IDE_H | 1 | #ifndef _IDE_H |
2 | #define _IDE_H | 2 | #define _IDE_H |
3 | /* | 3 | /* |
4 | * linux/include/linux/ide.h | 4 | * linux/include/linux/ide.h |
5 | * | 5 | * |
6 | * Copyright (C) 1994-2002 Linus Torvalds & authors | 6 | * Copyright (C) 1994-2002 Linus Torvalds & authors |
7 | */ | 7 | */ |
8 | 8 | ||
9 | #include <linux/init.h> | 9 | #include <linux/init.h> |
10 | #include <linux/ioport.h> | 10 | #include <linux/ioport.h> |
11 | #include <linux/hdreg.h> | 11 | #include <linux/hdreg.h> |
12 | #include <linux/blkdev.h> | 12 | #include <linux/blkdev.h> |
13 | #include <linux/proc_fs.h> | 13 | #include <linux/proc_fs.h> |
14 | #include <linux/interrupt.h> | 14 | #include <linux/interrupt.h> |
15 | #include <linux/bitops.h> | 15 | #include <linux/bitops.h> |
16 | #include <linux/bio.h> | 16 | #include <linux/bio.h> |
17 | #include <linux/device.h> | 17 | #include <linux/device.h> |
18 | #include <linux/pci.h> | 18 | #include <linux/pci.h> |
19 | #include <linux/completion.h> | 19 | #include <linux/completion.h> |
20 | #ifdef CONFIG_BLK_DEV_IDEACPI | 20 | #ifdef CONFIG_BLK_DEV_IDEACPI |
21 | #include <acpi/acpi.h> | 21 | #include <acpi/acpi.h> |
22 | #endif | 22 | #endif |
23 | #include <asm/byteorder.h> | 23 | #include <asm/byteorder.h> |
24 | #include <asm/system.h> | 24 | #include <asm/system.h> |
25 | #include <asm/io.h> | 25 | #include <asm/io.h> |
26 | #include <asm/mutex.h> | 26 | #include <asm/mutex.h> |
27 | 27 | ||
28 | #if defined(CONFIG_CRIS) || defined(CONFIG_FRV) | 28 | #if defined(CONFIG_CRIS) || defined(CONFIG_FRV) |
29 | # define SUPPORT_VLB_SYNC 0 | 29 | # define SUPPORT_VLB_SYNC 0 |
30 | #else | 30 | #else |
31 | # define SUPPORT_VLB_SYNC 1 | 31 | # define SUPPORT_VLB_SYNC 1 |
32 | #endif | 32 | #endif |
33 | 33 | ||
34 | /* | 34 | /* |
35 | * Used to indicate "no IRQ", should be a value that cannot be an IRQ | 35 | * Used to indicate "no IRQ", should be a value that cannot be an IRQ |
36 | * number. | 36 | * number. |
37 | */ | 37 | */ |
38 | 38 | ||
39 | #define IDE_NO_IRQ (-1) | 39 | #define IDE_NO_IRQ (-1) |
40 | 40 | ||
41 | typedef unsigned char byte; /* used everywhere */ | 41 | typedef unsigned char byte; /* used everywhere */ |
42 | 42 | ||
43 | /* | 43 | /* |
44 | * Probably not wise to fiddle with these | 44 | * Probably not wise to fiddle with these |
45 | */ | 45 | */ |
46 | #define ERROR_MAX 8 /* Max read/write errors per sector */ | 46 | #define ERROR_MAX 8 /* Max read/write errors per sector */ |
47 | #define ERROR_RESET 3 /* Reset controller every 4th retry */ | 47 | #define ERROR_RESET 3 /* Reset controller every 4th retry */ |
48 | #define ERROR_RECAL 1 /* Recalibrate every 2nd retry */ | 48 | #define ERROR_RECAL 1 /* Recalibrate every 2nd retry */ |
49 | 49 | ||
50 | /* | 50 | /* |
51 | * state flags | 51 | * state flags |
52 | */ | 52 | */ |
53 | 53 | ||
54 | #define DMA_PIO_RETRY 1 /* retrying in PIO */ | 54 | #define DMA_PIO_RETRY 1 /* retrying in PIO */ |
55 | 55 | ||
56 | #define HWIF(drive) ((ide_hwif_t *)((drive)->hwif)) | 56 | #define HWIF(drive) ((ide_hwif_t *)((drive)->hwif)) |
57 | #define HWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup)) | 57 | #define HWGROUP(drive) ((ide_hwgroup_t *)(HWIF(drive)->hwgroup)) |
58 | 58 | ||
59 | /* | 59 | /* |
60 | * Definitions for accessing IDE controller registers | 60 | * Definitions for accessing IDE controller registers |
61 | */ | 61 | */ |
62 | #define IDE_NR_PORTS (10) | 62 | #define IDE_NR_PORTS (10) |
63 | 63 | ||
64 | struct ide_io_ports { | 64 | struct ide_io_ports { |
65 | unsigned long data_addr; | 65 | unsigned long data_addr; |
66 | 66 | ||
67 | union { | 67 | union { |
68 | unsigned long error_addr; /* read: error */ | 68 | unsigned long error_addr; /* read: error */ |
69 | unsigned long feature_addr; /* write: feature */ | 69 | unsigned long feature_addr; /* write: feature */ |
70 | }; | 70 | }; |
71 | 71 | ||
72 | unsigned long nsect_addr; | 72 | unsigned long nsect_addr; |
73 | unsigned long lbal_addr; | 73 | unsigned long lbal_addr; |
74 | unsigned long lbam_addr; | 74 | unsigned long lbam_addr; |
75 | unsigned long lbah_addr; | 75 | unsigned long lbah_addr; |
76 | 76 | ||
77 | unsigned long device_addr; | 77 | unsigned long device_addr; |
78 | 78 | ||
79 | union { | 79 | union { |
80 | unsigned long status_addr; /* ย read: status ย */ | 80 | unsigned long status_addr; /* ย read: status ย */ |
81 | unsigned long command_addr; /* write: command */ | 81 | unsigned long command_addr; /* write: command */ |
82 | }; | 82 | }; |
83 | 83 | ||
84 | unsigned long ctl_addr; | 84 | unsigned long ctl_addr; |
85 | 85 | ||
86 | unsigned long irq_addr; | 86 | unsigned long irq_addr; |
87 | }; | 87 | }; |
88 | 88 | ||
89 | #define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good)) | 89 | #define OK_STAT(stat,good,bad) (((stat)&((good)|(bad)))==(good)) |
90 | #define BAD_R_STAT (BUSY_STAT | ERR_STAT) | 90 | #define BAD_R_STAT (BUSY_STAT | ERR_STAT) |
91 | #define BAD_W_STAT (BAD_R_STAT | WRERR_STAT) | 91 | #define BAD_W_STAT (BAD_R_STAT | WRERR_STAT) |
92 | #define BAD_STAT (BAD_R_STAT | DRQ_STAT) | 92 | #define BAD_STAT (BAD_R_STAT | DRQ_STAT) |
93 | #define DRIVE_READY (READY_STAT | SEEK_STAT) | 93 | #define DRIVE_READY (READY_STAT | SEEK_STAT) |
94 | 94 | ||
95 | #define BAD_CRC (ABRT_ERR | ICRC_ERR) | 95 | #define BAD_CRC (ABRT_ERR | ICRC_ERR) |
96 | 96 | ||
97 | #define SATA_NR_PORTS (3) /* 16 possible ?? */ | 97 | #define SATA_NR_PORTS (3) /* 16 possible ?? */ |
98 | 98 | ||
99 | #define SATA_STATUS_OFFSET (0) | 99 | #define SATA_STATUS_OFFSET (0) |
100 | #define SATA_ERROR_OFFSET (1) | 100 | #define SATA_ERROR_OFFSET (1) |
101 | #define SATA_CONTROL_OFFSET (2) | 101 | #define SATA_CONTROL_OFFSET (2) |
102 | 102 | ||
103 | /* | 103 | /* |
104 | * Our Physical Region Descriptor (PRD) table should be large enough | 104 | * Our Physical Region Descriptor (PRD) table should be large enough |
105 | * to handle the biggest I/O request we are likely to see. Since requests | 105 | * to handle the biggest I/O request we are likely to see. Since requests |
106 | * can have no more than 256 sectors, and since the typical blocksize is | 106 | * can have no more than 256 sectors, and since the typical blocksize is |
107 | * two or more sectors, we could get by with a limit of 128 entries here for | 107 | * two or more sectors, we could get by with a limit of 128 entries here for |
108 | * the usual worst case. Most requests seem to include some contiguous blocks, | 108 | * the usual worst case. Most requests seem to include some contiguous blocks, |
109 | * further reducing the number of table entries required. | 109 | * further reducing the number of table entries required. |
110 | * | 110 | * |
111 | * The driver reverts to PIO mode for individual requests that exceed | 111 | * The driver reverts to PIO mode for individual requests that exceed |
112 | * this limit (possible with 512 byte blocksizes, eg. MSDOS f/s), so handling | 112 | * this limit (possible with 512 byte blocksizes, eg. MSDOS f/s), so handling |
113 | * 100% of all crazy scenarios here is not necessary. | 113 | * 100% of all crazy scenarios here is not necessary. |
114 | * | 114 | * |
115 | * As it turns out though, we must allocate a full 4KB page for this, | 115 | * As it turns out though, we must allocate a full 4KB page for this, |
116 | * so the two PRD tables (ide0 & ide1) will each get half of that, | 116 | * so the two PRD tables (ide0 & ide1) will each get half of that, |
117 | * allowing each to have about 256 entries (8 bytes each) from this. | 117 | * allowing each to have about 256 entries (8 bytes each) from this. |
118 | */ | 118 | */ |
119 | #define PRD_BYTES 8 | 119 | #define PRD_BYTES 8 |
120 | #define PRD_ENTRIES 256 | 120 | #define PRD_ENTRIES 256 |
121 | 121 | ||
122 | /* | 122 | /* |
123 | * Some more useful definitions | 123 | * Some more useful definitions |
124 | */ | 124 | */ |
125 | #define PARTN_BITS 6 /* number of minor dev bits for partitions */ | 125 | #define PARTN_BITS 6 /* number of minor dev bits for partitions */ |
126 | #define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */ | 126 | #define MAX_DRIVES 2 /* per interface; 2 assumed by lots of code */ |
127 | #define SECTOR_SIZE 512 | 127 | #define SECTOR_SIZE 512 |
128 | #define SECTOR_WORDS (SECTOR_SIZE / 4) /* number of 32bit words per sector */ | 128 | #define SECTOR_WORDS (SECTOR_SIZE / 4) /* number of 32bit words per sector */ |
129 | #define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t))) | 129 | #define IDE_LARGE_SEEK(b1,b2,t) (((b1) > (b2) + (t)) || ((b2) > (b1) + (t))) |
130 | 130 | ||
131 | /* | 131 | /* |
132 | * Timeouts for various operations: | 132 | * Timeouts for various operations: |
133 | */ | 133 | */ |
134 | #define WAIT_DRQ (HZ/10) /* 100msec - spec allows up to 20ms */ | 134 | #define WAIT_DRQ (HZ/10) /* 100msec - spec allows up to 20ms */ |
135 | #define WAIT_READY (5*HZ) /* 5sec - some laptops are very slow */ | 135 | #define WAIT_READY (5*HZ) /* 5sec - some laptops are very slow */ |
136 | #define WAIT_PIDENTIFY (10*HZ) /* 10sec - should be less than 3ms (?), if all ATAPI CD is closed at boot */ | 136 | #define WAIT_PIDENTIFY (10*HZ) /* 10sec - should be less than 3ms (?), if all ATAPI CD is closed at boot */ |
137 | #define WAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */ | 137 | #define WAIT_WORSTCASE (30*HZ) /* 30sec - worst case when spinning up */ |
138 | #define WAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */ | 138 | #define WAIT_CMD (10*HZ) /* 10sec - maximum wait for an IRQ to happen */ |
139 | #define WAIT_MIN_SLEEP (2*HZ/100) /* 20msec - minimum sleep time */ | 139 | #define WAIT_MIN_SLEEP (2*HZ/100) /* 20msec - minimum sleep time */ |
140 | 140 | ||
141 | /* | 141 | /* |
142 | * Op codes for special requests to be handled by ide_special_rq(). | 142 | * Op codes for special requests to be handled by ide_special_rq(). |
143 | * Values should be in the range of 0x20 to 0x3f. | 143 | * Values should be in the range of 0x20 to 0x3f. |
144 | */ | 144 | */ |
145 | #define REQ_DRIVE_RESET 0x20 | 145 | #define REQ_DRIVE_RESET 0x20 |
146 | 146 | ||
147 | /* | 147 | /* |
148 | * Check for an interrupt and acknowledge the interrupt status | 148 | * Check for an interrupt and acknowledge the interrupt status |
149 | */ | 149 | */ |
150 | struct hwif_s; | 150 | struct hwif_s; |
151 | typedef int (ide_ack_intr_t)(struct hwif_s *); | 151 | typedef int (ide_ack_intr_t)(struct hwif_s *); |
152 | 152 | ||
153 | /* | 153 | /* |
154 | * hwif_chipset_t is used to keep track of the specific hardware | 154 | * hwif_chipset_t is used to keep track of the specific hardware |
155 | * chipset used by each IDE interface, if known. | 155 | * chipset used by each IDE interface, if known. |
156 | */ | 156 | */ |
157 | enum { ide_unknown, ide_generic, ide_pci, | 157 | enum { ide_unknown, ide_generic, ide_pci, |
158 | ide_cmd640, ide_dtc2278, ide_ali14xx, | 158 | ide_cmd640, ide_dtc2278, ide_ali14xx, |
159 | ide_qd65xx, ide_umc8672, ide_ht6560b, | 159 | ide_qd65xx, ide_umc8672, ide_ht6560b, |
160 | ide_rz1000, ide_trm290, | 160 | ide_rz1000, ide_trm290, |
161 | ide_cmd646, ide_cy82c693, ide_4drives, | 161 | ide_cmd646, ide_cy82c693, ide_4drives, |
162 | ide_pmac, ide_acorn, | 162 | ide_pmac, ide_acorn, |
163 | ide_au1xxx, ide_palm3710 | 163 | ide_au1xxx, ide_palm3710 |
164 | }; | 164 | }; |
165 | 165 | ||
166 | typedef u8 hwif_chipset_t; | 166 | typedef u8 hwif_chipset_t; |
167 | 167 | ||
168 | /* | 168 | /* |
169 | * Structure to hold all information about the location of this port | 169 | * Structure to hold all information about the location of this port |
170 | */ | 170 | */ |
171 | typedef struct hw_regs_s { | 171 | typedef struct hw_regs_s { |
172 | union { | 172 | union { |
173 | struct ide_io_ports io_ports; | 173 | struct ide_io_ports io_ports; |
174 | unsigned long io_ports_array[IDE_NR_PORTS]; | 174 | unsigned long io_ports_array[IDE_NR_PORTS]; |
175 | }; | 175 | }; |
176 | 176 | ||
177 | int irq; /* our irq number */ | 177 | int irq; /* our irq number */ |
178 | ide_ack_intr_t *ack_intr; /* acknowledge interrupt */ | 178 | ide_ack_intr_t *ack_intr; /* acknowledge interrupt */ |
179 | hwif_chipset_t chipset; | 179 | hwif_chipset_t chipset; |
180 | struct device *dev, *parent; | 180 | struct device *dev, *parent; |
181 | unsigned long config; | 181 | unsigned long config; |
182 | } hw_regs_t; | 182 | } hw_regs_t; |
183 | 183 | ||
184 | void ide_init_port_data(struct hwif_s *, unsigned int); | 184 | void ide_init_port_data(struct hwif_s *, unsigned int); |
185 | void ide_init_port_hw(struct hwif_s *, hw_regs_t *); | 185 | void ide_init_port_hw(struct hwif_s *, hw_regs_t *); |
186 | 186 | ||
187 | static inline void ide_std_init_ports(hw_regs_t *hw, | 187 | static inline void ide_std_init_ports(hw_regs_t *hw, |
188 | unsigned long io_addr, | 188 | unsigned long io_addr, |
189 | unsigned long ctl_addr) | 189 | unsigned long ctl_addr) |
190 | { | 190 | { |
191 | unsigned int i; | 191 | unsigned int i; |
192 | 192 | ||
193 | for (i = 0; i <= 7; i++) | 193 | for (i = 0; i <= 7; i++) |
194 | hw->io_ports_array[i] = io_addr++; | 194 | hw->io_ports_array[i] = io_addr++; |
195 | 195 | ||
196 | hw->io_ports.ctl_addr = ctl_addr; | 196 | hw->io_ports.ctl_addr = ctl_addr; |
197 | } | 197 | } |
198 | 198 | ||
199 | /* for IDE PCI controllers in legacy mode, temporary */ | 199 | /* for IDE PCI controllers in legacy mode, temporary */ |
200 | static inline int __ide_default_irq(unsigned long base) | 200 | static inline int __ide_default_irq(unsigned long base) |
201 | { | 201 | { |
202 | switch (base) { | 202 | switch (base) { |
203 | #ifdef CONFIG_IA64 | 203 | #ifdef CONFIG_IA64 |
204 | case 0x1f0: return isa_irq_to_vector(14); | 204 | case 0x1f0: return isa_irq_to_vector(14); |
205 | case 0x170: return isa_irq_to_vector(15); | 205 | case 0x170: return isa_irq_to_vector(15); |
206 | #else | 206 | #else |
207 | case 0x1f0: return 14; | 207 | case 0x1f0: return 14; |
208 | case 0x170: return 15; | 208 | case 0x170: return 15; |
209 | #endif | 209 | #endif |
210 | } | 210 | } |
211 | return 0; | 211 | return 0; |
212 | } | 212 | } |
213 | 213 | ||
214 | #if defined(CONFIG_ARM) || defined(CONFIG_FRV) || defined(CONFIG_M68K) || \ | 214 | #if defined(CONFIG_ARM) || defined(CONFIG_FRV) || defined(CONFIG_M68K) || \ |
215 | defined(CONFIG_MIPS) || defined(CONFIG_MN10300) || defined(CONFIG_PARISC) \ | 215 | defined(CONFIG_MIPS) || defined(CONFIG_MN10300) || defined(CONFIG_PARISC) \ |
216 | || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || defined(CONFIG_SPARC64) | 216 | || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || defined(CONFIG_SPARC64) |
217 | #include <asm/ide.h> | 217 | #include <asm/ide.h> |
218 | #else | 218 | #else |
219 | #include <asm-generic/ide_iops.h> | 219 | #include <asm-generic/ide_iops.h> |
220 | #endif | 220 | #endif |
221 | 221 | ||
222 | #define MAX_HWIFS 10 | 222 | #define MAX_HWIFS 10 |
223 | 223 | ||
224 | /* Currently only m68k, apus and m8xx need it */ | 224 | /* Currently only m68k, apus and m8xx need it */ |
225 | #ifndef IDE_ARCH_ACK_INTR | 225 | #ifndef IDE_ARCH_ACK_INTR |
226 | # define ide_ack_intr(hwif) (1) | 226 | # define ide_ack_intr(hwif) (1) |
227 | #endif | 227 | #endif |
228 | 228 | ||
229 | /* Currently only Atari needs it */ | 229 | /* Currently only Atari needs it */ |
230 | #ifndef IDE_ARCH_LOCK | 230 | #ifndef IDE_ARCH_LOCK |
231 | # define ide_release_lock() do {} while (0) | 231 | # define ide_release_lock() do {} while (0) |
232 | # define ide_get_lock(hdlr, data) do {} while (0) | 232 | # define ide_get_lock(hdlr, data) do {} while (0) |
233 | #endif /* IDE_ARCH_LOCK */ | 233 | #endif /* IDE_ARCH_LOCK */ |
234 | 234 | ||
235 | /* | 235 | /* |
236 | * Now for the data we need to maintain per-drive: ide_drive_t | 236 | * Now for the data we need to maintain per-drive: ide_drive_t |
237 | */ | 237 | */ |
238 | 238 | ||
239 | #define ide_scsi 0x21 | 239 | #define ide_scsi 0x21 |
240 | #define ide_disk 0x20 | 240 | #define ide_disk 0x20 |
241 | #define ide_optical 0x7 | 241 | #define ide_optical 0x7 |
242 | #define ide_cdrom 0x5 | 242 | #define ide_cdrom 0x5 |
243 | #define ide_tape 0x1 | 243 | #define ide_tape 0x1 |
244 | #define ide_floppy 0x0 | 244 | #define ide_floppy 0x0 |
245 | 245 | ||
246 | /* | 246 | /* |
247 | * Special Driver Flags | 247 | * Special Driver Flags |
248 | * | 248 | * |
249 | * set_geometry : respecify drive geometry | 249 | * set_geometry : respecify drive geometry |
250 | * recalibrate : seek to cyl 0 | 250 | * recalibrate : seek to cyl 0 |
251 | * set_multmode : set multmode count | 251 | * set_multmode : set multmode count |
252 | * set_tune : tune interface for drive | 252 | * set_tune : tune interface for drive |
253 | * serviced : service command | 253 | * serviced : service command |
254 | * reserved : unused | 254 | * reserved : unused |
255 | */ | 255 | */ |
256 | typedef union { | 256 | typedef union { |
257 | unsigned all : 8; | 257 | unsigned all : 8; |
258 | struct { | 258 | struct { |
259 | unsigned set_geometry : 1; | 259 | unsigned set_geometry : 1; |
260 | unsigned recalibrate : 1; | 260 | unsigned recalibrate : 1; |
261 | unsigned set_multmode : 1; | 261 | unsigned set_multmode : 1; |
262 | unsigned set_tune : 1; | 262 | unsigned set_tune : 1; |
263 | unsigned serviced : 1; | 263 | unsigned serviced : 1; |
264 | unsigned reserved : 3; | 264 | unsigned reserved : 3; |
265 | } b; | 265 | } b; |
266 | } special_t; | 266 | } special_t; |
267 | 267 | ||
268 | /* | 268 | /* |
269 | * ATA-IDE Select Register, aka Device-Head | 269 | * ATA-IDE Select Register, aka Device-Head |
270 | * | 270 | * |
271 | * head : always zeros here | 271 | * head : always zeros here |
272 | * unit : drive select number: 0/1 | 272 | * unit : drive select number: 0/1 |
273 | * bit5 : always 1 | 273 | * bit5 : always 1 |
274 | * lba : using LBA instead of CHS | 274 | * lba : using LBA instead of CHS |
275 | * bit7 : always 1 | 275 | * bit7 : always 1 |
276 | */ | 276 | */ |
277 | typedef union { | 277 | typedef union { |
278 | unsigned all : 8; | 278 | unsigned all : 8; |
279 | struct { | 279 | struct { |
280 | #if defined(__LITTLE_ENDIAN_BITFIELD) | 280 | #if defined(__LITTLE_ENDIAN_BITFIELD) |
281 | unsigned head : 4; | 281 | unsigned head : 4; |
282 | unsigned unit : 1; | 282 | unsigned unit : 1; |
283 | unsigned bit5 : 1; | 283 | unsigned bit5 : 1; |
284 | unsigned lba : 1; | 284 | unsigned lba : 1; |
285 | unsigned bit7 : 1; | 285 | unsigned bit7 : 1; |
286 | #elif defined(__BIG_ENDIAN_BITFIELD) | 286 | #elif defined(__BIG_ENDIAN_BITFIELD) |
287 | unsigned bit7 : 1; | 287 | unsigned bit7 : 1; |
288 | unsigned lba : 1; | 288 | unsigned lba : 1; |
289 | unsigned bit5 : 1; | 289 | unsigned bit5 : 1; |
290 | unsigned unit : 1; | 290 | unsigned unit : 1; |
291 | unsigned head : 4; | 291 | unsigned head : 4; |
292 | #else | 292 | #else |
293 | #error "Please fix <asm/byteorder.h>" | 293 | #error "Please fix <asm/byteorder.h>" |
294 | #endif | 294 | #endif |
295 | } b; | 295 | } b; |
296 | } select_t, ata_select_t; | 296 | } select_t, ata_select_t; |
297 | 297 | ||
298 | /* | 298 | /* |
299 | * Status returned from various ide_ functions | 299 | * Status returned from various ide_ functions |
300 | */ | 300 | */ |
301 | typedef enum { | 301 | typedef enum { |
302 | ide_stopped, /* no drive operation was started */ | 302 | ide_stopped, /* no drive operation was started */ |
303 | ide_started, /* a drive operation was started, handler was set */ | 303 | ide_started, /* a drive operation was started, handler was set */ |
304 | } ide_startstop_t; | 304 | } ide_startstop_t; |
305 | 305 | ||
306 | struct ide_driver_s; | 306 | struct ide_driver_s; |
307 | struct ide_settings_s; | 307 | struct ide_settings_s; |
308 | 308 | ||
309 | #ifdef CONFIG_BLK_DEV_IDEACPI | 309 | #ifdef CONFIG_BLK_DEV_IDEACPI |
310 | struct ide_acpi_drive_link; | 310 | struct ide_acpi_drive_link; |
311 | struct ide_acpi_hwif_link; | 311 | struct ide_acpi_hwif_link; |
312 | #endif | 312 | #endif |
313 | 313 | ||
314 | /* ATAPI device flags */ | 314 | /* ATAPI device flags */ |
315 | enum { | 315 | enum { |
316 | IDE_AFLAG_DRQ_INTERRUPT = (1 << 0), | 316 | IDE_AFLAG_DRQ_INTERRUPT = (1 << 0), |
317 | IDE_AFLAG_MEDIA_CHANGED = (1 << 1), | 317 | IDE_AFLAG_MEDIA_CHANGED = (1 << 1), |
318 | 318 | ||
319 | /* ide-cd */ | 319 | /* ide-cd */ |
320 | /* Drive cannot lock the door. */ | 320 | /* Drive cannot lock the door. */ |
321 | IDE_AFLAG_NO_DOORLOCK = (1 << 2), | 321 | IDE_AFLAG_NO_DOORLOCK = (1 << 2), |
322 | /* Drive cannot eject the disc. */ | 322 | /* Drive cannot eject the disc. */ |
323 | IDE_AFLAG_NO_EJECT = (1 << 3), | 323 | IDE_AFLAG_NO_EJECT = (1 << 3), |
324 | /* Drive is a pre ATAPI 1.2 drive. */ | 324 | /* Drive is a pre ATAPI 1.2 drive. */ |
325 | IDE_AFLAG_PRE_ATAPI12 = (1 << 4), | 325 | IDE_AFLAG_PRE_ATAPI12 = (1 << 4), |
326 | /* TOC addresses are in BCD. */ | 326 | /* TOC addresses are in BCD. */ |
327 | IDE_AFLAG_TOCADDR_AS_BCD = (1 << 5), | 327 | IDE_AFLAG_TOCADDR_AS_BCD = (1 << 5), |
328 | /* TOC track numbers are in BCD. */ | 328 | /* TOC track numbers are in BCD. */ |
329 | IDE_AFLAG_TOCTRACKS_AS_BCD = (1 << 6), | 329 | IDE_AFLAG_TOCTRACKS_AS_BCD = (1 << 6), |
330 | /* | 330 | /* |
331 | * Drive does not provide data in multiples of SECTOR_SIZE | 331 | * Drive does not provide data in multiples of SECTOR_SIZE |
332 | * when more than one interrupt is needed. | 332 | * when more than one interrupt is needed. |
333 | */ | 333 | */ |
334 | IDE_AFLAG_LIMIT_NFRAMES = (1 << 7), | 334 | IDE_AFLAG_LIMIT_NFRAMES = (1 << 7), |
335 | /* Seeking in progress. */ | 335 | /* Seeking in progress. */ |
336 | IDE_AFLAG_SEEKING = (1 << 8), | 336 | IDE_AFLAG_SEEKING = (1 << 8), |
337 | /* Saved TOC information is current. */ | 337 | /* Saved TOC information is current. */ |
338 | IDE_AFLAG_TOC_VALID = (1 << 9), | 338 | IDE_AFLAG_TOC_VALID = (1 << 9), |
339 | /* We think that the drive door is locked. */ | 339 | /* We think that the drive door is locked. */ |
340 | IDE_AFLAG_DOOR_LOCKED = (1 << 10), | 340 | IDE_AFLAG_DOOR_LOCKED = (1 << 10), |
341 | /* SET_CD_SPEED command is unsupported. */ | 341 | /* SET_CD_SPEED command is unsupported. */ |
342 | IDE_AFLAG_NO_SPEED_SELECT = (1 << 11), | 342 | IDE_AFLAG_NO_SPEED_SELECT = (1 << 11), |
343 | IDE_AFLAG_VERTOS_300_SSD = (1 << 12), | 343 | IDE_AFLAG_VERTOS_300_SSD = (1 << 12), |
344 | IDE_AFLAG_VERTOS_600_ESD = (1 << 13), | 344 | IDE_AFLAG_VERTOS_600_ESD = (1 << 13), |
345 | IDE_AFLAG_SANYO_3CD = (1 << 14), | 345 | IDE_AFLAG_SANYO_3CD = (1 << 14), |
346 | IDE_AFLAG_FULL_CAPS_PAGE = (1 << 15), | 346 | IDE_AFLAG_FULL_CAPS_PAGE = (1 << 15), |
347 | IDE_AFLAG_PLAY_AUDIO_OK = (1 << 16), | 347 | IDE_AFLAG_PLAY_AUDIO_OK = (1 << 16), |
348 | IDE_AFLAG_LE_SPEED_FIELDS = (1 << 17), | 348 | IDE_AFLAG_LE_SPEED_FIELDS = (1 << 17), |
349 | 349 | ||
350 | /* ide-floppy */ | 350 | /* ide-floppy */ |
351 | /* Format in progress */ | 351 | /* Format in progress */ |
352 | IDE_AFLAG_FORMAT_IN_PROGRESS = (1 << 18), | 352 | IDE_AFLAG_FORMAT_IN_PROGRESS = (1 << 18), |
353 | /* Avoid commands not supported in Clik drive */ | 353 | /* Avoid commands not supported in Clik drive */ |
354 | IDE_AFLAG_CLIK_DRIVE = (1 << 19), | 354 | IDE_AFLAG_CLIK_DRIVE = (1 << 19), |
355 | /* Requires BH algorithm for packets */ | 355 | /* Requires BH algorithm for packets */ |
356 | IDE_AFLAG_ZIP_DRIVE = (1 << 20), | 356 | IDE_AFLAG_ZIP_DRIVE = (1 << 20), |
357 | 357 | ||
358 | /* ide-tape */ | 358 | /* ide-tape */ |
359 | IDE_AFLAG_IGNORE_DSC = (1 << 21), | 359 | IDE_AFLAG_IGNORE_DSC = (1 << 21), |
360 | /* 0 When the tape position is unknown */ | 360 | /* 0 When the tape position is unknown */ |
361 | IDE_AFLAG_ADDRESS_VALID = (1 << 22), | 361 | IDE_AFLAG_ADDRESS_VALID = (1 << 22), |
362 | /* Device already opened */ | 362 | /* Device already opened */ |
363 | IDE_AFLAG_BUSY = (1 << 23), | 363 | IDE_AFLAG_BUSY = (1 << 23), |
364 | /* Attempt to auto-detect the current user block size */ | 364 | /* Attempt to auto-detect the current user block size */ |
365 | IDE_AFLAG_DETECT_BS = (1 << 24), | 365 | IDE_AFLAG_DETECT_BS = (1 << 24), |
366 | /* Currently on a filemark */ | 366 | /* Currently on a filemark */ |
367 | IDE_AFLAG_FILEMARK = (1 << 25), | 367 | IDE_AFLAG_FILEMARK = (1 << 25), |
368 | /* 0 = no tape is loaded, so we don't rewind after ejecting */ | 368 | /* 0 = no tape is loaded, so we don't rewind after ejecting */ |
369 | IDE_AFLAG_MEDIUM_PRESENT = (1 << 26) | 369 | IDE_AFLAG_MEDIUM_PRESENT = (1 << 26), |
370 | |||
371 | IDE_AFLAG_NO_AUTOCLOSE = (1 << 27), | ||
370 | }; | 372 | }; |
371 | 373 | ||
372 | struct ide_drive_s { | 374 | struct ide_drive_s { |
373 | char name[4]; /* drive name, such as "hda" */ | 375 | char name[4]; /* drive name, such as "hda" */ |
374 | char driver_req[10]; /* requests specific driver */ | 376 | char driver_req[10]; /* requests specific driver */ |
375 | 377 | ||
376 | struct request_queue *queue; /* request queue */ | 378 | struct request_queue *queue; /* request queue */ |
377 | 379 | ||
378 | struct request *rq; /* current request */ | 380 | struct request *rq; /* current request */ |
379 | struct ide_drive_s *next; /* circular list of hwgroup drives */ | 381 | struct ide_drive_s *next; /* circular list of hwgroup drives */ |
380 | void *driver_data; /* extra driver data */ | 382 | void *driver_data; /* extra driver data */ |
381 | struct hd_driveid *id; /* drive model identification info */ | 383 | struct hd_driveid *id; /* drive model identification info */ |
382 | #ifdef CONFIG_IDE_PROC_FS | 384 | #ifdef CONFIG_IDE_PROC_FS |
383 | struct proc_dir_entry *proc; /* /proc/ide/ directory entry */ | 385 | struct proc_dir_entry *proc; /* /proc/ide/ directory entry */ |
384 | struct ide_settings_s *settings;/* /proc/ide/ drive settings */ | 386 | struct ide_settings_s *settings;/* /proc/ide/ drive settings */ |
385 | #endif | 387 | #endif |
386 | struct hwif_s *hwif; /* actually (ide_hwif_t *) */ | 388 | struct hwif_s *hwif; /* actually (ide_hwif_t *) */ |
387 | 389 | ||
388 | unsigned long sleep; /* sleep until this time */ | 390 | unsigned long sleep; /* sleep until this time */ |
389 | unsigned long service_start; /* time we started last request */ | 391 | unsigned long service_start; /* time we started last request */ |
390 | unsigned long service_time; /* service time of last request */ | 392 | unsigned long service_time; /* service time of last request */ |
391 | unsigned long timeout; /* max time to wait for irq */ | 393 | unsigned long timeout; /* max time to wait for irq */ |
392 | 394 | ||
393 | special_t special; /* special action flags */ | 395 | special_t special; /* special action flags */ |
394 | select_t select; /* basic drive/head select reg value */ | 396 | select_t select; /* basic drive/head select reg value */ |
395 | 397 | ||
396 | u8 keep_settings; /* restore settings after drive reset */ | 398 | u8 keep_settings; /* restore settings after drive reset */ |
397 | u8 using_dma; /* disk is using dma for read/write */ | 399 | u8 using_dma; /* disk is using dma for read/write */ |
398 | u8 retry_pio; /* retrying dma capable host in pio */ | 400 | u8 retry_pio; /* retrying dma capable host in pio */ |
399 | u8 state; /* retry state */ | 401 | u8 state; /* retry state */ |
400 | u8 waiting_for_dma; /* dma currently in progress */ | 402 | u8 waiting_for_dma; /* dma currently in progress */ |
401 | u8 unmask; /* okay to unmask other irqs */ | 403 | u8 unmask; /* okay to unmask other irqs */ |
402 | u8 noflush; /* don't attempt flushes */ | 404 | u8 noflush; /* don't attempt flushes */ |
403 | u8 dsc_overlap; /* DSC overlap */ | 405 | u8 dsc_overlap; /* DSC overlap */ |
404 | u8 nice1; /* give potential excess bandwidth */ | 406 | u8 nice1; /* give potential excess bandwidth */ |
405 | 407 | ||
406 | unsigned present : 1; /* drive is physically present */ | 408 | unsigned present : 1; /* drive is physically present */ |
407 | unsigned dead : 1; /* device ejected hint */ | 409 | unsigned dead : 1; /* device ejected hint */ |
408 | unsigned id_read : 1; /* 1=id read from disk 0 = synthetic */ | 410 | unsigned id_read : 1; /* 1=id read from disk 0 = synthetic */ |
409 | unsigned noprobe : 1; /* from: hdx=noprobe */ | 411 | unsigned noprobe : 1; /* from: hdx=noprobe */ |
410 | unsigned removable : 1; /* 1 if need to do check_media_change */ | 412 | unsigned removable : 1; /* 1 if need to do check_media_change */ |
411 | unsigned attach : 1; /* needed for removable devices */ | 413 | unsigned attach : 1; /* needed for removable devices */ |
412 | unsigned forced_geom : 1; /* 1 if hdx=c,h,s was given at boot */ | 414 | unsigned forced_geom : 1; /* 1 if hdx=c,h,s was given at boot */ |
413 | unsigned no_unmask : 1; /* disallow setting unmask bit */ | 415 | unsigned no_unmask : 1; /* disallow setting unmask bit */ |
414 | unsigned no_io_32bit : 1; /* disallow enabling 32bit I/O */ | 416 | unsigned no_io_32bit : 1; /* disallow enabling 32bit I/O */ |
415 | unsigned atapi_overlap : 1; /* ATAPI overlap (not supported) */ | 417 | unsigned atapi_overlap : 1; /* ATAPI overlap (not supported) */ |
416 | unsigned doorlocking : 1; /* for removable only: door lock/unlock works */ | 418 | unsigned doorlocking : 1; /* for removable only: door lock/unlock works */ |
417 | unsigned nodma : 1; /* disallow DMA */ | 419 | unsigned nodma : 1; /* disallow DMA */ |
418 | unsigned remap_0_to_1 : 1; /* 0=noremap, 1=remap 0->1 (for EZDrive) */ | 420 | unsigned remap_0_to_1 : 1; /* 0=noremap, 1=remap 0->1 (for EZDrive) */ |
419 | unsigned blocked : 1; /* 1=powermanagment told us not to do anything, so sleep nicely */ | 421 | unsigned blocked : 1; /* 1=powermanagment told us not to do anything, so sleep nicely */ |
420 | unsigned scsi : 1; /* 0=default, 1=ide-scsi emulation */ | 422 | unsigned scsi : 1; /* 0=default, 1=ide-scsi emulation */ |
421 | unsigned sleeping : 1; /* 1=sleeping & sleep field valid */ | 423 | unsigned sleeping : 1; /* 1=sleeping & sleep field valid */ |
422 | unsigned post_reset : 1; | 424 | unsigned post_reset : 1; |
423 | unsigned udma33_warned : 1; | 425 | unsigned udma33_warned : 1; |
424 | 426 | ||
425 | u8 addressing; /* 0=28-bit, 1=48-bit, 2=48-bit doing 28-bit */ | 427 | u8 addressing; /* 0=28-bit, 1=48-bit, 2=48-bit doing 28-bit */ |
426 | u8 quirk_list; /* considered quirky, set for a specific host */ | 428 | u8 quirk_list; /* considered quirky, set for a specific host */ |
427 | u8 init_speed; /* transfer rate set at boot */ | 429 | u8 init_speed; /* transfer rate set at boot */ |
428 | u8 current_speed; /* current transfer rate set */ | 430 | u8 current_speed; /* current transfer rate set */ |
429 | u8 desired_speed; /* desired transfer rate set */ | 431 | u8 desired_speed; /* desired transfer rate set */ |
430 | u8 dn; /* now wide spread use */ | 432 | u8 dn; /* now wide spread use */ |
431 | u8 wcache; /* status of write cache */ | 433 | u8 wcache; /* status of write cache */ |
432 | u8 acoustic; /* acoustic management */ | 434 | u8 acoustic; /* acoustic management */ |
433 | u8 media; /* disk, cdrom, tape, floppy, ... */ | 435 | u8 media; /* disk, cdrom, tape, floppy, ... */ |
434 | u8 ready_stat; /* min status value for drive ready */ | 436 | u8 ready_stat; /* min status value for drive ready */ |
435 | u8 mult_count; /* current multiple sector setting */ | 437 | u8 mult_count; /* current multiple sector setting */ |
436 | u8 mult_req; /* requested multiple sector setting */ | 438 | u8 mult_req; /* requested multiple sector setting */ |
437 | u8 tune_req; /* requested drive tuning setting */ | 439 | u8 tune_req; /* requested drive tuning setting */ |
438 | u8 io_32bit; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */ | 440 | u8 io_32bit; /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */ |
439 | u8 bad_wstat; /* used for ignoring WRERR_STAT */ | 441 | u8 bad_wstat; /* used for ignoring WRERR_STAT */ |
440 | u8 nowerr; /* used for ignoring WRERR_STAT */ | 442 | u8 nowerr; /* used for ignoring WRERR_STAT */ |
441 | u8 sect0; /* offset of first sector for DM6:DDO */ | 443 | u8 sect0; /* offset of first sector for DM6:DDO */ |
442 | u8 head; /* "real" number of heads */ | 444 | u8 head; /* "real" number of heads */ |
443 | u8 sect; /* "real" sectors per track */ | 445 | u8 sect; /* "real" sectors per track */ |
444 | u8 bios_head; /* BIOS/fdisk/LILO number of heads */ | 446 | u8 bios_head; /* BIOS/fdisk/LILO number of heads */ |
445 | u8 bios_sect; /* BIOS/fdisk/LILO sectors per track */ | 447 | u8 bios_sect; /* BIOS/fdisk/LILO sectors per track */ |
446 | 448 | ||
447 | unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */ | 449 | unsigned int bios_cyl; /* BIOS/fdisk/LILO number of cyls */ |
448 | unsigned int cyl; /* "real" number of cyls */ | 450 | unsigned int cyl; /* "real" number of cyls */ |
449 | unsigned int drive_data; /* used by set_pio_mode/selectproc */ | 451 | unsigned int drive_data; /* used by set_pio_mode/selectproc */ |
450 | unsigned int failures; /* current failure count */ | 452 | unsigned int failures; /* current failure count */ |
451 | unsigned int max_failures; /* maximum allowed failure count */ | 453 | unsigned int max_failures; /* maximum allowed failure count */ |
452 | u64 probed_capacity;/* initial reported media capacity (ide-cd only currently) */ | 454 | u64 probed_capacity;/* initial reported media capacity (ide-cd only currently) */ |
453 | 455 | ||
454 | u64 capacity64; /* total number of sectors */ | 456 | u64 capacity64; /* total number of sectors */ |
455 | 457 | ||
456 | int lun; /* logical unit */ | 458 | int lun; /* logical unit */ |
457 | int crc_count; /* crc counter to reduce drive speed */ | 459 | int crc_count; /* crc counter to reduce drive speed */ |
458 | #ifdef CONFIG_BLK_DEV_IDEACPI | 460 | #ifdef CONFIG_BLK_DEV_IDEACPI |
459 | struct ide_acpi_drive_link *acpidata; | 461 | struct ide_acpi_drive_link *acpidata; |
460 | #endif | 462 | #endif |
461 | struct list_head list; | 463 | struct list_head list; |
462 | struct device gendev; | 464 | struct device gendev; |
463 | struct completion gendev_rel_comp; /* to deal with device release() */ | 465 | struct completion gendev_rel_comp; /* to deal with device release() */ |
464 | 466 | ||
465 | /* callback for packet commands */ | 467 | /* callback for packet commands */ |
466 | void (*pc_callback)(struct ide_drive_s *); | 468 | void (*pc_callback)(struct ide_drive_s *); |
467 | 469 | ||
468 | unsigned long atapi_flags; | 470 | unsigned long atapi_flags; |
469 | }; | 471 | }; |
470 | 472 | ||
471 | typedef struct ide_drive_s ide_drive_t; | 473 | typedef struct ide_drive_s ide_drive_t; |
472 | 474 | ||
473 | #define to_ide_device(dev)container_of(dev, ide_drive_t, gendev) | 475 | #define to_ide_device(dev)container_of(dev, ide_drive_t, gendev) |
474 | 476 | ||
475 | #define IDE_CHIPSET_PCI_MASK \ | 477 | #define IDE_CHIPSET_PCI_MASK \ |
476 | ((1<<ide_pci)|(1<<ide_cmd646)|(1<<ide_ali14xx)) | 478 | ((1<<ide_pci)|(1<<ide_cmd646)|(1<<ide_ali14xx)) |
477 | #define IDE_CHIPSET_IS_PCI(c) ((IDE_CHIPSET_PCI_MASK >> (c)) & 1) | 479 | #define IDE_CHIPSET_IS_PCI(c) ((IDE_CHIPSET_PCI_MASK >> (c)) & 1) |
478 | 480 | ||
479 | struct ide_task_s; | 481 | struct ide_task_s; |
480 | struct ide_port_info; | 482 | struct ide_port_info; |
481 | 483 | ||
482 | struct ide_tp_ops { | 484 | struct ide_tp_ops { |
483 | void (*exec_command)(struct hwif_s *, u8); | 485 | void (*exec_command)(struct hwif_s *, u8); |
484 | u8 (*read_status)(struct hwif_s *); | 486 | u8 (*read_status)(struct hwif_s *); |
485 | u8 (*read_altstatus)(struct hwif_s *); | 487 | u8 (*read_altstatus)(struct hwif_s *); |
486 | u8 (*read_sff_dma_status)(struct hwif_s *); | 488 | u8 (*read_sff_dma_status)(struct hwif_s *); |
487 | 489 | ||
488 | void (*set_irq)(struct hwif_s *, int); | 490 | void (*set_irq)(struct hwif_s *, int); |
489 | 491 | ||
490 | void (*tf_load)(ide_drive_t *, struct ide_task_s *); | 492 | void (*tf_load)(ide_drive_t *, struct ide_task_s *); |
491 | void (*tf_read)(ide_drive_t *, struct ide_task_s *); | 493 | void (*tf_read)(ide_drive_t *, struct ide_task_s *); |
492 | 494 | ||
493 | void (*input_data)(ide_drive_t *, struct request *, void *, | 495 | void (*input_data)(ide_drive_t *, struct request *, void *, |
494 | unsigned int); | 496 | unsigned int); |
495 | void (*output_data)(ide_drive_t *, struct request *, void *, | 497 | void (*output_data)(ide_drive_t *, struct request *, void *, |
496 | unsigned int); | 498 | unsigned int); |
497 | }; | 499 | }; |
498 | 500 | ||
499 | extern const struct ide_tp_ops default_tp_ops; | 501 | extern const struct ide_tp_ops default_tp_ops; |
500 | 502 | ||
501 | /** | 503 | /** |
502 | * struct ide_port_ops - IDE port operations | 504 | * struct ide_port_ops - IDE port operations |
503 | * | 505 | * |
504 | * @init_dev: host specific initialization of a device | 506 | * @init_dev: host specific initialization of a device |
505 | * @set_pio_mode: routine to program host for PIO mode | 507 | * @set_pio_mode: routine to program host for PIO mode |
506 | * @set_dma_mode: routine to program host for DMA mode | 508 | * @set_dma_mode: routine to program host for DMA mode |
507 | * @selectproc: tweaks hardware to select drive | 509 | * @selectproc: tweaks hardware to select drive |
508 | * @reset_poll: chipset polling based on hba specifics | 510 | * @reset_poll: chipset polling based on hba specifics |
509 | * @pre_reset: chipset specific changes to default for device-hba resets | 511 | * @pre_reset: chipset specific changes to default for device-hba resets |
510 | * @resetproc: routine to reset controller after a disk reset | 512 | * @resetproc: routine to reset controller after a disk reset |
511 | * @maskproc: special host masking for drive selection | 513 | * @maskproc: special host masking for drive selection |
512 | * @quirkproc: check host's drive quirk list | 514 | * @quirkproc: check host's drive quirk list |
513 | * | 515 | * |
514 | * @mdma_filter: filter MDMA modes | 516 | * @mdma_filter: filter MDMA modes |
515 | * @udma_filter: filter UDMA modes | 517 | * @udma_filter: filter UDMA modes |
516 | * | 518 | * |
517 | * @cable_detect: detect cable type | 519 | * @cable_detect: detect cable type |
518 | */ | 520 | */ |
519 | struct ide_port_ops { | 521 | struct ide_port_ops { |
520 | void (*init_dev)(ide_drive_t *); | 522 | void (*init_dev)(ide_drive_t *); |
521 | void (*set_pio_mode)(ide_drive_t *, const u8); | 523 | void (*set_pio_mode)(ide_drive_t *, const u8); |
522 | void (*set_dma_mode)(ide_drive_t *, const u8); | 524 | void (*set_dma_mode)(ide_drive_t *, const u8); |
523 | void (*selectproc)(ide_drive_t *); | 525 | void (*selectproc)(ide_drive_t *); |
524 | int (*reset_poll)(ide_drive_t *); | 526 | int (*reset_poll)(ide_drive_t *); |
525 | void (*pre_reset)(ide_drive_t *); | 527 | void (*pre_reset)(ide_drive_t *); |
526 | void (*resetproc)(ide_drive_t *); | 528 | void (*resetproc)(ide_drive_t *); |
527 | void (*maskproc)(ide_drive_t *, int); | 529 | void (*maskproc)(ide_drive_t *, int); |
528 | void (*quirkproc)(ide_drive_t *); | 530 | void (*quirkproc)(ide_drive_t *); |
529 | 531 | ||
530 | u8 (*mdma_filter)(ide_drive_t *); | 532 | u8 (*mdma_filter)(ide_drive_t *); |
531 | u8 (*udma_filter)(ide_drive_t *); | 533 | u8 (*udma_filter)(ide_drive_t *); |
532 | 534 | ||
533 | u8 (*cable_detect)(struct hwif_s *); | 535 | u8 (*cable_detect)(struct hwif_s *); |
534 | }; | 536 | }; |
535 | 537 | ||
536 | struct ide_dma_ops { | 538 | struct ide_dma_ops { |
537 | void (*dma_host_set)(struct ide_drive_s *, int); | 539 | void (*dma_host_set)(struct ide_drive_s *, int); |
538 | int (*dma_setup)(struct ide_drive_s *); | 540 | int (*dma_setup)(struct ide_drive_s *); |
539 | void (*dma_exec_cmd)(struct ide_drive_s *, u8); | 541 | void (*dma_exec_cmd)(struct ide_drive_s *, u8); |
540 | void (*dma_start)(struct ide_drive_s *); | 542 | void (*dma_start)(struct ide_drive_s *); |
541 | int (*dma_end)(struct ide_drive_s *); | 543 | int (*dma_end)(struct ide_drive_s *); |
542 | int (*dma_test_irq)(struct ide_drive_s *); | 544 | int (*dma_test_irq)(struct ide_drive_s *); |
543 | void (*dma_lost_irq)(struct ide_drive_s *); | 545 | void (*dma_lost_irq)(struct ide_drive_s *); |
544 | void (*dma_timeout)(struct ide_drive_s *); | 546 | void (*dma_timeout)(struct ide_drive_s *); |
545 | }; | 547 | }; |
546 | 548 | ||
547 | struct ide_host; | 549 | struct ide_host; |
548 | 550 | ||
549 | typedef struct hwif_s { | 551 | typedef struct hwif_s { |
550 | struct hwif_s *next; /* for linked-list in ide_hwgroup_t */ | 552 | struct hwif_s *next; /* for linked-list in ide_hwgroup_t */ |
551 | struct hwif_s *mate; /* other hwif from same PCI chip */ | 553 | struct hwif_s *mate; /* other hwif from same PCI chip */ |
552 | struct hwgroup_s *hwgroup; /* actually (ide_hwgroup_t *) */ | 554 | struct hwgroup_s *hwgroup; /* actually (ide_hwgroup_t *) */ |
553 | struct proc_dir_entry *proc; /* /proc/ide/ directory entry */ | 555 | struct proc_dir_entry *proc; /* /proc/ide/ directory entry */ |
554 | 556 | ||
555 | struct ide_host *host; | 557 | struct ide_host *host; |
556 | 558 | ||
557 | char name[6]; /* name of interface, eg. "ide0" */ | 559 | char name[6]; /* name of interface, eg. "ide0" */ |
558 | 560 | ||
559 | struct ide_io_ports io_ports; | 561 | struct ide_io_ports io_ports; |
560 | 562 | ||
561 | unsigned long sata_scr[SATA_NR_PORTS]; | 563 | unsigned long sata_scr[SATA_NR_PORTS]; |
562 | 564 | ||
563 | ide_drive_t drives[MAX_DRIVES]; /* drive info */ | 565 | ide_drive_t drives[MAX_DRIVES]; /* drive info */ |
564 | 566 | ||
565 | u8 major; /* our major number */ | 567 | u8 major; /* our major number */ |
566 | u8 index; /* 0 for ide0; 1 for ide1; ... */ | 568 | u8 index; /* 0 for ide0; 1 for ide1; ... */ |
567 | u8 channel; /* for dual-port chips: 0=primary, 1=secondary */ | 569 | u8 channel; /* for dual-port chips: 0=primary, 1=secondary */ |
568 | u8 bus_state; /* power state of the IDE bus */ | 570 | u8 bus_state; /* power state of the IDE bus */ |
569 | 571 | ||
570 | u32 host_flags; | 572 | u32 host_flags; |
571 | 573 | ||
572 | u8 pio_mask; | 574 | u8 pio_mask; |
573 | 575 | ||
574 | u8 ultra_mask; | 576 | u8 ultra_mask; |
575 | u8 mwdma_mask; | 577 | u8 mwdma_mask; |
576 | u8 swdma_mask; | 578 | u8 swdma_mask; |
577 | 579 | ||
578 | u8 cbl; /* cable type */ | 580 | u8 cbl; /* cable type */ |
579 | 581 | ||
580 | hwif_chipset_t chipset; /* sub-module for tuning.. */ | 582 | hwif_chipset_t chipset; /* sub-module for tuning.. */ |
581 | 583 | ||
582 | struct device *dev; | 584 | struct device *dev; |
583 | 585 | ||
584 | ide_ack_intr_t *ack_intr; | 586 | ide_ack_intr_t *ack_intr; |
585 | 587 | ||
586 | void (*rw_disk)(ide_drive_t *, struct request *); | 588 | void (*rw_disk)(ide_drive_t *, struct request *); |
587 | 589 | ||
588 | const struct ide_tp_ops *tp_ops; | 590 | const struct ide_tp_ops *tp_ops; |
589 | const struct ide_port_ops *port_ops; | 591 | const struct ide_port_ops *port_ops; |
590 | const struct ide_dma_ops *dma_ops; | 592 | const struct ide_dma_ops *dma_ops; |
591 | 593 | ||
592 | void (*ide_dma_clear_irq)(ide_drive_t *drive); | 594 | void (*ide_dma_clear_irq)(ide_drive_t *drive); |
593 | 595 | ||
594 | /* dma physical region descriptor table (cpu view) */ | 596 | /* dma physical region descriptor table (cpu view) */ |
595 | unsigned int *dmatable_cpu; | 597 | unsigned int *dmatable_cpu; |
596 | /* dma physical region descriptor table (dma view) */ | 598 | /* dma physical region descriptor table (dma view) */ |
597 | dma_addr_t dmatable_dma; | 599 | dma_addr_t dmatable_dma; |
598 | /* Scatter-gather list used to build the above */ | 600 | /* Scatter-gather list used to build the above */ |
599 | struct scatterlist *sg_table; | 601 | struct scatterlist *sg_table; |
600 | int sg_max_nents; /* Maximum number of entries in it */ | 602 | int sg_max_nents; /* Maximum number of entries in it */ |
601 | int sg_nents; /* Current number of entries in it */ | 603 | int sg_nents; /* Current number of entries in it */ |
602 | int sg_dma_direction; /* dma transfer direction */ | 604 | int sg_dma_direction; /* dma transfer direction */ |
603 | 605 | ||
604 | /* data phase of the active command (currently only valid for PIO/DMA) */ | 606 | /* data phase of the active command (currently only valid for PIO/DMA) */ |
605 | int data_phase; | 607 | int data_phase; |
606 | 608 | ||
607 | unsigned int nsect; | 609 | unsigned int nsect; |
608 | unsigned int nleft; | 610 | unsigned int nleft; |
609 | struct scatterlist *cursg; | 611 | struct scatterlist *cursg; |
610 | unsigned int cursg_ofs; | 612 | unsigned int cursg_ofs; |
611 | 613 | ||
612 | int rqsize; /* max sectors per request */ | 614 | int rqsize; /* max sectors per request */ |
613 | int irq; /* our irq number */ | 615 | int irq; /* our irq number */ |
614 | 616 | ||
615 | unsigned long dma_base; /* base addr for dma ports */ | 617 | unsigned long dma_base; /* base addr for dma ports */ |
616 | 618 | ||
617 | unsigned long config_data; /* for use by chipset-specific code */ | 619 | unsigned long config_data; /* for use by chipset-specific code */ |
618 | unsigned long select_data; /* for use by chipset-specific code */ | 620 | unsigned long select_data; /* for use by chipset-specific code */ |
619 | 621 | ||
620 | unsigned long extra_base; /* extra addr for dma ports */ | 622 | unsigned long extra_base; /* extra addr for dma ports */ |
621 | unsigned extra_ports; /* number of extra dma ports */ | 623 | unsigned extra_ports; /* number of extra dma ports */ |
622 | 624 | ||
623 | unsigned present : 1; /* this interface exists */ | 625 | unsigned present : 1; /* this interface exists */ |
624 | unsigned serialized : 1; /* serialized all channel operation */ | 626 | unsigned serialized : 1; /* serialized all channel operation */ |
625 | unsigned sharing_irq: 1; /* 1 = sharing irq with another hwif */ | 627 | unsigned sharing_irq: 1; /* 1 = sharing irq with another hwif */ |
626 | unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */ | 628 | unsigned sg_mapped : 1; /* sg_table and sg_nents are ready */ |
627 | 629 | ||
628 | struct device gendev; | 630 | struct device gendev; |
629 | struct device *portdev; | 631 | struct device *portdev; |
630 | 632 | ||
631 | struct completion gendev_rel_comp; /* To deal with device release() */ | 633 | struct completion gendev_rel_comp; /* To deal with device release() */ |
632 | 634 | ||
633 | void *hwif_data; /* extra hwif data */ | 635 | void *hwif_data; /* extra hwif data */ |
634 | 636 | ||
635 | unsigned dma; | 637 | unsigned dma; |
636 | 638 | ||
637 | #ifdef CONFIG_BLK_DEV_IDEACPI | 639 | #ifdef CONFIG_BLK_DEV_IDEACPI |
638 | struct ide_acpi_hwif_link *acpidata; | 640 | struct ide_acpi_hwif_link *acpidata; |
639 | #endif | 641 | #endif |
640 | } ____cacheline_internodealigned_in_smp ide_hwif_t; | 642 | } ____cacheline_internodealigned_in_smp ide_hwif_t; |
641 | 643 | ||
642 | struct ide_host { | 644 | struct ide_host { |
643 | ide_hwif_t *ports[MAX_HWIFS]; | 645 | ide_hwif_t *ports[MAX_HWIFS]; |
644 | unsigned int n_ports; | 646 | unsigned int n_ports; |
645 | struct device *dev[2]; | 647 | struct device *dev[2]; |
646 | unsigned long host_flags; | 648 | unsigned long host_flags; |
647 | void *host_priv; | 649 | void *host_priv; |
648 | }; | 650 | }; |
649 | 651 | ||
650 | /* | 652 | /* |
651 | * internal ide interrupt handler type | 653 | * internal ide interrupt handler type |
652 | */ | 654 | */ |
653 | typedef ide_startstop_t (ide_handler_t)(ide_drive_t *); | 655 | typedef ide_startstop_t (ide_handler_t)(ide_drive_t *); |
654 | typedef int (ide_expiry_t)(ide_drive_t *); | 656 | typedef int (ide_expiry_t)(ide_drive_t *); |
655 | 657 | ||
656 | /* used by ide-cd, ide-floppy, etc. */ | 658 | /* used by ide-cd, ide-floppy, etc. */ |
657 | typedef void (xfer_func_t)(ide_drive_t *, struct request *rq, void *, unsigned); | 659 | typedef void (xfer_func_t)(ide_drive_t *, struct request *rq, void *, unsigned); |
658 | 660 | ||
659 | typedef struct hwgroup_s { | 661 | typedef struct hwgroup_s { |
660 | /* irq handler, if active */ | 662 | /* irq handler, if active */ |
661 | ide_startstop_t (*handler)(ide_drive_t *); | 663 | ide_startstop_t (*handler)(ide_drive_t *); |
662 | 664 | ||
663 | /* BOOL: protects all fields below */ | 665 | /* BOOL: protects all fields below */ |
664 | volatile int busy; | 666 | volatile int busy; |
665 | /* BOOL: wake us up on timer expiry */ | 667 | /* BOOL: wake us up on timer expiry */ |
666 | unsigned int sleeping : 1; | 668 | unsigned int sleeping : 1; |
667 | /* BOOL: polling active & poll_timeout field valid */ | 669 | /* BOOL: polling active & poll_timeout field valid */ |
668 | unsigned int polling : 1; | 670 | unsigned int polling : 1; |
669 | 671 | ||
670 | /* current drive */ | 672 | /* current drive */ |
671 | ide_drive_t *drive; | 673 | ide_drive_t *drive; |
672 | /* ptr to current hwif in linked-list */ | 674 | /* ptr to current hwif in linked-list */ |
673 | ide_hwif_t *hwif; | 675 | ide_hwif_t *hwif; |
674 | 676 | ||
675 | /* current request */ | 677 | /* current request */ |
676 | struct request *rq; | 678 | struct request *rq; |
677 | 679 | ||
678 | /* failsafe timer */ | 680 | /* failsafe timer */ |
679 | struct timer_list timer; | 681 | struct timer_list timer; |
680 | /* timeout value during long polls */ | 682 | /* timeout value during long polls */ |
681 | unsigned long poll_timeout; | 683 | unsigned long poll_timeout; |
682 | /* queried upon timeouts */ | 684 | /* queried upon timeouts */ |
683 | int (*expiry)(ide_drive_t *); | 685 | int (*expiry)(ide_drive_t *); |
684 | 686 | ||
685 | int req_gen; | 687 | int req_gen; |
686 | int req_gen_timer; | 688 | int req_gen_timer; |
687 | } ide_hwgroup_t; | 689 | } ide_hwgroup_t; |
688 | 690 | ||
689 | typedef struct ide_driver_s ide_driver_t; | 691 | typedef struct ide_driver_s ide_driver_t; |
690 | 692 | ||
691 | extern struct mutex ide_setting_mtx; | 693 | extern struct mutex ide_setting_mtx; |
692 | 694 | ||
693 | int set_io_32bit(ide_drive_t *, int); | 695 | int set_io_32bit(ide_drive_t *, int); |
694 | int set_pio_mode(ide_drive_t *, int); | 696 | int set_pio_mode(ide_drive_t *, int); |
695 | int set_using_dma(ide_drive_t *, int); | 697 | int set_using_dma(ide_drive_t *, int); |
696 | 698 | ||
697 | /* ATAPI packet command flags */ | 699 | /* ATAPI packet command flags */ |
698 | enum { | 700 | enum { |
699 | /* set when an error is considered normal - no retry (ide-tape) */ | 701 | /* set when an error is considered normal - no retry (ide-tape) */ |
700 | PC_FLAG_ABORT = (1 << 0), | 702 | PC_FLAG_ABORT = (1 << 0), |
701 | PC_FLAG_SUPPRESS_ERROR = (1 << 1), | 703 | PC_FLAG_SUPPRESS_ERROR = (1 << 1), |
702 | PC_FLAG_WAIT_FOR_DSC = (1 << 2), | 704 | PC_FLAG_WAIT_FOR_DSC = (1 << 2), |
703 | PC_FLAG_DMA_OK = (1 << 3), | 705 | PC_FLAG_DMA_OK = (1 << 3), |
704 | PC_FLAG_DMA_IN_PROGRESS = (1 << 4), | 706 | PC_FLAG_DMA_IN_PROGRESS = (1 << 4), |
705 | PC_FLAG_DMA_ERROR = (1 << 5), | 707 | PC_FLAG_DMA_ERROR = (1 << 5), |
706 | PC_FLAG_WRITING = (1 << 6), | 708 | PC_FLAG_WRITING = (1 << 6), |
707 | /* command timed out */ | 709 | /* command timed out */ |
708 | PC_FLAG_TIMEDOUT = (1 << 7), | 710 | PC_FLAG_TIMEDOUT = (1 << 7), |
709 | }; | 711 | }; |
710 | 712 | ||
711 | struct ide_atapi_pc { | 713 | struct ide_atapi_pc { |
712 | /* actual packet bytes */ | 714 | /* actual packet bytes */ |
713 | u8 c[12]; | 715 | u8 c[12]; |
714 | /* incremented on each retry */ | 716 | /* incremented on each retry */ |
715 | int retries; | 717 | int retries; |
716 | int error; | 718 | int error; |
717 | 719 | ||
718 | /* bytes to transfer */ | 720 | /* bytes to transfer */ |
719 | int req_xfer; | 721 | int req_xfer; |
720 | /* bytes actually transferred */ | 722 | /* bytes actually transferred */ |
721 | int xferred; | 723 | int xferred; |
722 | 724 | ||
723 | /* data buffer */ | 725 | /* data buffer */ |
724 | u8 *buf; | 726 | u8 *buf; |
725 | /* current buffer position */ | 727 | /* current buffer position */ |
726 | u8 *cur_pos; | 728 | u8 *cur_pos; |
727 | int buf_size; | 729 | int buf_size; |
728 | /* missing/available data on the current buffer */ | 730 | /* missing/available data on the current buffer */ |
729 | int b_count; | 731 | int b_count; |
730 | 732 | ||
731 | /* the corresponding request */ | 733 | /* the corresponding request */ |
732 | struct request *rq; | 734 | struct request *rq; |
733 | 735 | ||
734 | unsigned long flags; | 736 | unsigned long flags; |
735 | 737 | ||
736 | /* | 738 | /* |
737 | * those are more or less driver-specific and some of them are subject | 739 | * those are more or less driver-specific and some of them are subject |
738 | * to change/removal later. | 740 | * to change/removal later. |
739 | */ | 741 | */ |
740 | u8 pc_buf[256]; | 742 | u8 pc_buf[256]; |
741 | 743 | ||
742 | /* idetape only */ | 744 | /* idetape only */ |
743 | struct idetape_bh *bh; | 745 | struct idetape_bh *bh; |
744 | char *b_data; | 746 | char *b_data; |
745 | 747 | ||
746 | /* idescsi only for now */ | 748 | /* idescsi only for now */ |
747 | struct scatterlist *sg; | 749 | struct scatterlist *sg; |
748 | unsigned int sg_cnt; | 750 | unsigned int sg_cnt; |
749 | 751 | ||
750 | struct scsi_cmnd *scsi_cmd; | 752 | struct scsi_cmnd *scsi_cmd; |
751 | void (*done) (struct scsi_cmnd *); | 753 | void (*done) (struct scsi_cmnd *); |
752 | 754 | ||
753 | unsigned long timeout; | 755 | unsigned long timeout; |
754 | }; | 756 | }; |
755 | 757 | ||
756 | #ifdef CONFIG_IDE_PROC_FS | 758 | #ifdef CONFIG_IDE_PROC_FS |
757 | /* | 759 | /* |
758 | * configurable drive settings | 760 | * configurable drive settings |
759 | */ | 761 | */ |
760 | 762 | ||
761 | #define TYPE_INT 0 | 763 | #define TYPE_INT 0 |
762 | #define TYPE_BYTE 1 | 764 | #define TYPE_BYTE 1 |
763 | #define TYPE_SHORT 2 | 765 | #define TYPE_SHORT 2 |
764 | 766 | ||
765 | #define SETTING_READ (1 << 0) | 767 | #define SETTING_READ (1 << 0) |
766 | #define SETTING_WRITE (1 << 1) | 768 | #define SETTING_WRITE (1 << 1) |
767 | #define SETTING_RW (SETTING_READ | SETTING_WRITE) | 769 | #define SETTING_RW (SETTING_READ | SETTING_WRITE) |
768 | 770 | ||
769 | typedef int (ide_procset_t)(ide_drive_t *, int); | 771 | typedef int (ide_procset_t)(ide_drive_t *, int); |
770 | typedef struct ide_settings_s { | 772 | typedef struct ide_settings_s { |
771 | char *name; | 773 | char *name; |
772 | int rw; | 774 | int rw; |
773 | int data_type; | 775 | int data_type; |
774 | int min; | 776 | int min; |
775 | int max; | 777 | int max; |
776 | int mul_factor; | 778 | int mul_factor; |
777 | int div_factor; | 779 | int div_factor; |
778 | void *data; | 780 | void *data; |
779 | ide_procset_t *set; | 781 | ide_procset_t *set; |
780 | int auto_remove; | 782 | int auto_remove; |
781 | struct ide_settings_s *next; | 783 | struct ide_settings_s *next; |
782 | } ide_settings_t; | 784 | } ide_settings_t; |
783 | 785 | ||
784 | int ide_add_setting(ide_drive_t *, const char *, int, int, int, int, int, int, void *, ide_procset_t *set); | 786 | int ide_add_setting(ide_drive_t *, const char *, int, int, int, int, int, int, void *, ide_procset_t *set); |
785 | 787 | ||
786 | /* | 788 | /* |
787 | * /proc/ide interface | 789 | * /proc/ide interface |
788 | */ | 790 | */ |
789 | typedef struct { | 791 | typedef struct { |
790 | const char *name; | 792 | const char *name; |
791 | mode_t mode; | 793 | mode_t mode; |
792 | read_proc_t *read_proc; | 794 | read_proc_t *read_proc; |
793 | write_proc_t *write_proc; | 795 | write_proc_t *write_proc; |
794 | } ide_proc_entry_t; | 796 | } ide_proc_entry_t; |
795 | 797 | ||
796 | void proc_ide_create(void); | 798 | void proc_ide_create(void); |
797 | void proc_ide_destroy(void); | 799 | void proc_ide_destroy(void); |
798 | void ide_proc_register_port(ide_hwif_t *); | 800 | void ide_proc_register_port(ide_hwif_t *); |
799 | void ide_proc_port_register_devices(ide_hwif_t *); | 801 | void ide_proc_port_register_devices(ide_hwif_t *); |
800 | void ide_proc_unregister_device(ide_drive_t *); | 802 | void ide_proc_unregister_device(ide_drive_t *); |
801 | void ide_proc_unregister_port(ide_hwif_t *); | 803 | void ide_proc_unregister_port(ide_hwif_t *); |
802 | void ide_proc_register_driver(ide_drive_t *, ide_driver_t *); | 804 | void ide_proc_register_driver(ide_drive_t *, ide_driver_t *); |
803 | void ide_proc_unregister_driver(ide_drive_t *, ide_driver_t *); | 805 | void ide_proc_unregister_driver(ide_drive_t *, ide_driver_t *); |
804 | 806 | ||
805 | void ide_add_generic_settings(ide_drive_t *); | 807 | void ide_add_generic_settings(ide_drive_t *); |
806 | 808 | ||
807 | read_proc_t proc_ide_read_capacity; | 809 | read_proc_t proc_ide_read_capacity; |
808 | read_proc_t proc_ide_read_geometry; | 810 | read_proc_t proc_ide_read_geometry; |
809 | 811 | ||
810 | /* | 812 | /* |
811 | * Standard exit stuff: | 813 | * Standard exit stuff: |
812 | */ | 814 | */ |
813 | #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \ | 815 | #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) \ |
814 | { \ | 816 | { \ |
815 | len -= off; \ | 817 | len -= off; \ |
816 | if (len < count) { \ | 818 | if (len < count) { \ |
817 | *eof = 1; \ | 819 | *eof = 1; \ |
818 | if (len <= 0) \ | 820 | if (len <= 0) \ |
819 | return 0; \ | 821 | return 0; \ |
820 | } else \ | 822 | } else \ |
821 | len = count; \ | 823 | len = count; \ |
822 | *start = page + off; \ | 824 | *start = page + off; \ |
823 | return len; \ | 825 | return len; \ |
824 | } | 826 | } |
825 | #else | 827 | #else |
826 | static inline void proc_ide_create(void) { ; } | 828 | static inline void proc_ide_create(void) { ; } |
827 | static inline void proc_ide_destroy(void) { ; } | 829 | static inline void proc_ide_destroy(void) { ; } |
828 | static inline void ide_proc_register_port(ide_hwif_t *hwif) { ; } | 830 | static inline void ide_proc_register_port(ide_hwif_t *hwif) { ; } |
829 | static inline void ide_proc_port_register_devices(ide_hwif_t *hwif) { ; } | 831 | static inline void ide_proc_port_register_devices(ide_hwif_t *hwif) { ; } |
830 | static inline void ide_proc_unregister_device(ide_drive_t *drive) { ; } | 832 | static inline void ide_proc_unregister_device(ide_drive_t *drive) { ; } |
831 | static inline void ide_proc_unregister_port(ide_hwif_t *hwif) { ; } | 833 | static inline void ide_proc_unregister_port(ide_hwif_t *hwif) { ; } |
832 | static inline void ide_proc_register_driver(ide_drive_t *drive, ide_driver_t *driver) { ; } | 834 | static inline void ide_proc_register_driver(ide_drive_t *drive, ide_driver_t *driver) { ; } |
833 | static inline void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver) { ; } | 835 | static inline void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *driver) { ; } |
834 | static inline void ide_add_generic_settings(ide_drive_t *drive) { ; } | 836 | static inline void ide_add_generic_settings(ide_drive_t *drive) { ; } |
835 | #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0; | 837 | #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0; |
836 | #endif | 838 | #endif |
837 | 839 | ||
838 | /* | 840 | /* |
839 | * Power Management step value (rq->pm->pm_step). | 841 | * Power Management step value (rq->pm->pm_step). |
840 | * | 842 | * |
841 | * The step value starts at 0 (ide_pm_state_start_suspend) for a | 843 | * The step value starts at 0 (ide_pm_state_start_suspend) for a |
842 | * suspend operation or 1000 (ide_pm_state_start_resume) for a | 844 | * suspend operation or 1000 (ide_pm_state_start_resume) for a |
843 | * resume operation. | 845 | * resume operation. |
844 | * | 846 | * |
845 | * For each step, the core calls the subdriver start_power_step() first. | 847 | * For each step, the core calls the subdriver start_power_step() first. |
846 | * This can return: | 848 | * This can return: |
847 | * - ide_stopped : In this case, the core calls us back again unless | 849 | * - ide_stopped : In this case, the core calls us back again unless |
848 | * step have been set to ide_power_state_completed. | 850 | * step have been set to ide_power_state_completed. |
849 | * - ide_started : In this case, the channel is left busy until an | 851 | * - ide_started : In this case, the channel is left busy until an |
850 | * async event (interrupt) occurs. | 852 | * async event (interrupt) occurs. |
851 | * Typically, start_power_step() will issue a taskfile request with | 853 | * Typically, start_power_step() will issue a taskfile request with |
852 | * do_rw_taskfile(). | 854 | * do_rw_taskfile(). |
853 | * | 855 | * |
854 | * Upon reception of the interrupt, the core will call complete_power_step() | 856 | * Upon reception of the interrupt, the core will call complete_power_step() |
855 | * with the error code if any. This routine should update the step value | 857 | * with the error code if any. This routine should update the step value |
856 | * and return. It should not start a new request. The core will call | 858 | * and return. It should not start a new request. The core will call |
857 | * start_power_step for the new step value, unless step have been set to | 859 | * start_power_step for the new step value, unless step have been set to |
858 | * ide_power_state_completed. | 860 | * ide_power_state_completed. |
859 | * | 861 | * |
860 | * Subdrivers are expected to define their own additional power | 862 | * Subdrivers are expected to define their own additional power |
861 | * steps from 1..999 for suspend and from 1001..1999 for resume, | 863 | * steps from 1..999 for suspend and from 1001..1999 for resume, |
862 | * other values are reserved for future use. | 864 | * other values are reserved for future use. |
863 | */ | 865 | */ |
864 | 866 | ||
865 | enum { | 867 | enum { |
866 | ide_pm_state_completed = -1, | 868 | ide_pm_state_completed = -1, |
867 | ide_pm_state_start_suspend = 0, | 869 | ide_pm_state_start_suspend = 0, |
868 | ide_pm_state_start_resume = 1000, | 870 | ide_pm_state_start_resume = 1000, |
869 | }; | 871 | }; |
870 | 872 | ||
871 | /* | 873 | /* |
872 | * Subdrivers support. | 874 | * Subdrivers support. |
873 | * | 875 | * |
874 | * The gendriver.owner field should be set to the module owner of this driver. | 876 | * The gendriver.owner field should be set to the module owner of this driver. |
875 | * The gendriver.name field should be set to the name of this driver | 877 | * The gendriver.name field should be set to the name of this driver |
876 | */ | 878 | */ |
877 | struct ide_driver_s { | 879 | struct ide_driver_s { |
878 | const char *version; | 880 | const char *version; |
879 | u8 media; | 881 | u8 media; |
880 | unsigned supports_dsc_overlap : 1; | 882 | unsigned supports_dsc_overlap : 1; |
881 | ide_startstop_t (*do_request)(ide_drive_t *, struct request *, sector_t); | 883 | ide_startstop_t (*do_request)(ide_drive_t *, struct request *, sector_t); |
882 | int (*end_request)(ide_drive_t *, int, int); | 884 | int (*end_request)(ide_drive_t *, int, int); |
883 | ide_startstop_t (*error)(ide_drive_t *, struct request *rq, u8, u8); | 885 | ide_startstop_t (*error)(ide_drive_t *, struct request *rq, u8, u8); |
884 | struct device_driver gen_driver; | 886 | struct device_driver gen_driver; |
885 | int (*probe)(ide_drive_t *); | 887 | int (*probe)(ide_drive_t *); |
886 | void (*remove)(ide_drive_t *); | 888 | void (*remove)(ide_drive_t *); |
887 | void (*resume)(ide_drive_t *); | 889 | void (*resume)(ide_drive_t *); |
888 | void (*shutdown)(ide_drive_t *); | 890 | void (*shutdown)(ide_drive_t *); |
889 | #ifdef CONFIG_IDE_PROC_FS | 891 | #ifdef CONFIG_IDE_PROC_FS |
890 | ide_proc_entry_t *proc; | 892 | ide_proc_entry_t *proc; |
891 | #endif | 893 | #endif |
892 | }; | 894 | }; |
893 | 895 | ||
894 | #define to_ide_driver(drv) container_of(drv, ide_driver_t, gen_driver) | 896 | #define to_ide_driver(drv) container_of(drv, ide_driver_t, gen_driver) |
895 | 897 | ||
896 | int ide_device_get(ide_drive_t *); | 898 | int ide_device_get(ide_drive_t *); |
897 | void ide_device_put(ide_drive_t *); | 899 | void ide_device_put(ide_drive_t *); |
898 | 900 | ||
899 | int generic_ide_ioctl(ide_drive_t *, struct file *, struct block_device *, unsigned, unsigned long); | 901 | int generic_ide_ioctl(ide_drive_t *, struct file *, struct block_device *, unsigned, unsigned long); |
900 | 902 | ||
901 | extern int ide_vlb_clk; | 903 | extern int ide_vlb_clk; |
902 | extern int ide_pci_clk; | 904 | extern int ide_pci_clk; |
903 | 905 | ||
904 | extern int ide_end_request (ide_drive_t *drive, int uptodate, int nrsecs); | 906 | extern int ide_end_request (ide_drive_t *drive, int uptodate, int nrsecs); |
905 | int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq, | 907 | int ide_end_dequeued_request(ide_drive_t *drive, struct request *rq, |
906 | int uptodate, int nr_sectors); | 908 | int uptodate, int nr_sectors); |
907 | 909 | ||
908 | extern void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry); | 910 | extern void ide_set_handler (ide_drive_t *drive, ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry); |
909 | 911 | ||
910 | void ide_execute_command(ide_drive_t *, u8, ide_handler_t *, unsigned int, | 912 | void ide_execute_command(ide_drive_t *, u8, ide_handler_t *, unsigned int, |
911 | ide_expiry_t *); | 913 | ide_expiry_t *); |
912 | 914 | ||
913 | void ide_execute_pkt_cmd(ide_drive_t *); | 915 | void ide_execute_pkt_cmd(ide_drive_t *); |
914 | 916 | ||
915 | void ide_pad_transfer(ide_drive_t *, int, int); | 917 | void ide_pad_transfer(ide_drive_t *, int, int); |
916 | 918 | ||
917 | ide_startstop_t __ide_error(ide_drive_t *, struct request *, u8, u8); | 919 | ide_startstop_t __ide_error(ide_drive_t *, struct request *, u8, u8); |
918 | 920 | ||
919 | ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, byte stat); | 921 | ide_startstop_t ide_error (ide_drive_t *drive, const char *msg, byte stat); |
920 | 922 | ||
921 | extern void ide_fix_driveid(struct hd_driveid *); | 923 | extern void ide_fix_driveid(struct hd_driveid *); |
922 | 924 | ||
923 | extern void ide_fixstring(u8 *, const int, const int); | 925 | extern void ide_fixstring(u8 *, const int, const int); |
924 | 926 | ||
925 | int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long); | 927 | int ide_wait_stat(ide_startstop_t *, ide_drive_t *, u8, u8, unsigned long); |
926 | 928 | ||
927 | extern ide_startstop_t ide_do_reset (ide_drive_t *); | 929 | extern ide_startstop_t ide_do_reset (ide_drive_t *); |
928 | 930 | ||
929 | extern void ide_do_drive_cmd(ide_drive_t *, struct request *); | 931 | extern void ide_do_drive_cmd(ide_drive_t *, struct request *); |
930 | 932 | ||
931 | extern void ide_end_drive_cmd(ide_drive_t *, u8, u8); | 933 | extern void ide_end_drive_cmd(ide_drive_t *, u8, u8); |
932 | 934 | ||
933 | enum { | 935 | enum { |
934 | IDE_TFLAG_LBA48 = (1 << 0), | 936 | IDE_TFLAG_LBA48 = (1 << 0), |
935 | IDE_TFLAG_FLAGGED = (1 << 2), | 937 | IDE_TFLAG_FLAGGED = (1 << 2), |
936 | IDE_TFLAG_OUT_DATA = (1 << 3), | 938 | IDE_TFLAG_OUT_DATA = (1 << 3), |
937 | IDE_TFLAG_OUT_HOB_FEATURE = (1 << 4), | 939 | IDE_TFLAG_OUT_HOB_FEATURE = (1 << 4), |
938 | IDE_TFLAG_OUT_HOB_NSECT = (1 << 5), | 940 | IDE_TFLAG_OUT_HOB_NSECT = (1 << 5), |
939 | IDE_TFLAG_OUT_HOB_LBAL = (1 << 6), | 941 | IDE_TFLAG_OUT_HOB_LBAL = (1 << 6), |
940 | IDE_TFLAG_OUT_HOB_LBAM = (1 << 7), | 942 | IDE_TFLAG_OUT_HOB_LBAM = (1 << 7), |
941 | IDE_TFLAG_OUT_HOB_LBAH = (1 << 8), | 943 | IDE_TFLAG_OUT_HOB_LBAH = (1 << 8), |
942 | IDE_TFLAG_OUT_HOB = IDE_TFLAG_OUT_HOB_FEATURE | | 944 | IDE_TFLAG_OUT_HOB = IDE_TFLAG_OUT_HOB_FEATURE | |
943 | IDE_TFLAG_OUT_HOB_NSECT | | 945 | IDE_TFLAG_OUT_HOB_NSECT | |
944 | IDE_TFLAG_OUT_HOB_LBAL | | 946 | IDE_TFLAG_OUT_HOB_LBAL | |
945 | IDE_TFLAG_OUT_HOB_LBAM | | 947 | IDE_TFLAG_OUT_HOB_LBAM | |
946 | IDE_TFLAG_OUT_HOB_LBAH, | 948 | IDE_TFLAG_OUT_HOB_LBAH, |
947 | IDE_TFLAG_OUT_FEATURE = (1 << 9), | 949 | IDE_TFLAG_OUT_FEATURE = (1 << 9), |
948 | IDE_TFLAG_OUT_NSECT = (1 << 10), | 950 | IDE_TFLAG_OUT_NSECT = (1 << 10), |
949 | IDE_TFLAG_OUT_LBAL = (1 << 11), | 951 | IDE_TFLAG_OUT_LBAL = (1 << 11), |
950 | IDE_TFLAG_OUT_LBAM = (1 << 12), | 952 | IDE_TFLAG_OUT_LBAM = (1 << 12), |
951 | IDE_TFLAG_OUT_LBAH = (1 << 13), | 953 | IDE_TFLAG_OUT_LBAH = (1 << 13), |
952 | IDE_TFLAG_OUT_TF = IDE_TFLAG_OUT_FEATURE | | 954 | IDE_TFLAG_OUT_TF = IDE_TFLAG_OUT_FEATURE | |
953 | IDE_TFLAG_OUT_NSECT | | 955 | IDE_TFLAG_OUT_NSECT | |
954 | IDE_TFLAG_OUT_LBAL | | 956 | IDE_TFLAG_OUT_LBAL | |
955 | IDE_TFLAG_OUT_LBAM | | 957 | IDE_TFLAG_OUT_LBAM | |
956 | IDE_TFLAG_OUT_LBAH, | 958 | IDE_TFLAG_OUT_LBAH, |
957 | IDE_TFLAG_OUT_DEVICE = (1 << 14), | 959 | IDE_TFLAG_OUT_DEVICE = (1 << 14), |
958 | IDE_TFLAG_WRITE = (1 << 15), | 960 | IDE_TFLAG_WRITE = (1 << 15), |
959 | IDE_TFLAG_FLAGGED_SET_IN_FLAGS = (1 << 16), | 961 | IDE_TFLAG_FLAGGED_SET_IN_FLAGS = (1 << 16), |
960 | IDE_TFLAG_IN_DATA = (1 << 17), | 962 | IDE_TFLAG_IN_DATA = (1 << 17), |
961 | IDE_TFLAG_CUSTOM_HANDLER = (1 << 18), | 963 | IDE_TFLAG_CUSTOM_HANDLER = (1 << 18), |
962 | IDE_TFLAG_DMA_PIO_FALLBACK = (1 << 19), | 964 | IDE_TFLAG_DMA_PIO_FALLBACK = (1 << 19), |
963 | IDE_TFLAG_IN_HOB_FEATURE = (1 << 20), | 965 | IDE_TFLAG_IN_HOB_FEATURE = (1 << 20), |
964 | IDE_TFLAG_IN_HOB_NSECT = (1 << 21), | 966 | IDE_TFLAG_IN_HOB_NSECT = (1 << 21), |
965 | IDE_TFLAG_IN_HOB_LBAL = (1 << 22), | 967 | IDE_TFLAG_IN_HOB_LBAL = (1 << 22), |
966 | IDE_TFLAG_IN_HOB_LBAM = (1 << 23), | 968 | IDE_TFLAG_IN_HOB_LBAM = (1 << 23), |
967 | IDE_TFLAG_IN_HOB_LBAH = (1 << 24), | 969 | IDE_TFLAG_IN_HOB_LBAH = (1 << 24), |
968 | IDE_TFLAG_IN_HOB_LBA = IDE_TFLAG_IN_HOB_LBAL | | 970 | IDE_TFLAG_IN_HOB_LBA = IDE_TFLAG_IN_HOB_LBAL | |
969 | IDE_TFLAG_IN_HOB_LBAM | | 971 | IDE_TFLAG_IN_HOB_LBAM | |
970 | IDE_TFLAG_IN_HOB_LBAH, | 972 | IDE_TFLAG_IN_HOB_LBAH, |
971 | IDE_TFLAG_IN_HOB = IDE_TFLAG_IN_HOB_FEATURE | | 973 | IDE_TFLAG_IN_HOB = IDE_TFLAG_IN_HOB_FEATURE | |
972 | IDE_TFLAG_IN_HOB_NSECT | | 974 | IDE_TFLAG_IN_HOB_NSECT | |
973 | IDE_TFLAG_IN_HOB_LBA, | 975 | IDE_TFLAG_IN_HOB_LBA, |
974 | IDE_TFLAG_IN_FEATURE = (1 << 1), | 976 | IDE_TFLAG_IN_FEATURE = (1 << 1), |
975 | IDE_TFLAG_IN_NSECT = (1 << 25), | 977 | IDE_TFLAG_IN_NSECT = (1 << 25), |
976 | IDE_TFLAG_IN_LBAL = (1 << 26), | 978 | IDE_TFLAG_IN_LBAL = (1 << 26), |
977 | IDE_TFLAG_IN_LBAM = (1 << 27), | 979 | IDE_TFLAG_IN_LBAM = (1 << 27), |
978 | IDE_TFLAG_IN_LBAH = (1 << 28), | 980 | IDE_TFLAG_IN_LBAH = (1 << 28), |
979 | IDE_TFLAG_IN_LBA = IDE_TFLAG_IN_LBAL | | 981 | IDE_TFLAG_IN_LBA = IDE_TFLAG_IN_LBAL | |
980 | IDE_TFLAG_IN_LBAM | | 982 | IDE_TFLAG_IN_LBAM | |
981 | IDE_TFLAG_IN_LBAH, | 983 | IDE_TFLAG_IN_LBAH, |
982 | IDE_TFLAG_IN_TF = IDE_TFLAG_IN_NSECT | | 984 | IDE_TFLAG_IN_TF = IDE_TFLAG_IN_NSECT | |
983 | IDE_TFLAG_IN_LBA, | 985 | IDE_TFLAG_IN_LBA, |
984 | IDE_TFLAG_IN_DEVICE = (1 << 29), | 986 | IDE_TFLAG_IN_DEVICE = (1 << 29), |
985 | IDE_TFLAG_HOB = IDE_TFLAG_OUT_HOB | | 987 | IDE_TFLAG_HOB = IDE_TFLAG_OUT_HOB | |
986 | IDE_TFLAG_IN_HOB, | 988 | IDE_TFLAG_IN_HOB, |
987 | IDE_TFLAG_TF = IDE_TFLAG_OUT_TF | | 989 | IDE_TFLAG_TF = IDE_TFLAG_OUT_TF | |
988 | IDE_TFLAG_IN_TF, | 990 | IDE_TFLAG_IN_TF, |
989 | IDE_TFLAG_DEVICE = IDE_TFLAG_OUT_DEVICE | | 991 | IDE_TFLAG_DEVICE = IDE_TFLAG_OUT_DEVICE | |
990 | IDE_TFLAG_IN_DEVICE, | 992 | IDE_TFLAG_IN_DEVICE, |
991 | /* force 16-bit I/O operations */ | 993 | /* force 16-bit I/O operations */ |
992 | IDE_TFLAG_IO_16BIT = (1 << 30), | 994 | IDE_TFLAG_IO_16BIT = (1 << 30), |
993 | /* ide_task_t was allocated using kmalloc() */ | 995 | /* ide_task_t was allocated using kmalloc() */ |
994 | IDE_TFLAG_DYN = (1 << 31), | 996 | IDE_TFLAG_DYN = (1 << 31), |
995 | }; | 997 | }; |
996 | 998 | ||
997 | struct ide_taskfile { | 999 | struct ide_taskfile { |
998 | u8 hob_data; /* 0: high data byte (for TASKFILE IOCTL) */ | 1000 | u8 hob_data; /* 0: high data byte (for TASKFILE IOCTL) */ |
999 | 1001 | ||
1000 | u8 hob_feature; /* 1-5: additional data to support LBA48 */ | 1002 | u8 hob_feature; /* 1-5: additional data to support LBA48 */ |
1001 | u8 hob_nsect; | 1003 | u8 hob_nsect; |
1002 | u8 hob_lbal; | 1004 | u8 hob_lbal; |
1003 | u8 hob_lbam; | 1005 | u8 hob_lbam; |
1004 | u8 hob_lbah; | 1006 | u8 hob_lbah; |
1005 | 1007 | ||
1006 | u8 data; /* 6: low data byte (for TASKFILE IOCTL) */ | 1008 | u8 data; /* 6: low data byte (for TASKFILE IOCTL) */ |
1007 | 1009 | ||
1008 | union { /* ย 7: */ | 1010 | union { /* ย 7: */ |
1009 | u8 error; /* read: error */ | 1011 | u8 error; /* read: error */ |
1010 | u8 feature; /* write: feature */ | 1012 | u8 feature; /* write: feature */ |
1011 | }; | 1013 | }; |
1012 | 1014 | ||
1013 | u8 nsect; /* 8: number of sectors */ | 1015 | u8 nsect; /* 8: number of sectors */ |
1014 | u8 lbal; /* 9: LBA low */ | 1016 | u8 lbal; /* 9: LBA low */ |
1015 | u8 lbam; /* 10: LBA mid */ | 1017 | u8 lbam; /* 10: LBA mid */ |
1016 | u8 lbah; /* 11: LBA high */ | 1018 | u8 lbah; /* 11: LBA high */ |
1017 | 1019 | ||
1018 | u8 device; /* 12: device select */ | 1020 | u8 device; /* 12: device select */ |
1019 | 1021 | ||
1020 | union { /* 13: */ | 1022 | union { /* 13: */ |
1021 | u8 status; /* ย read: status ย */ | 1023 | u8 status; /* ย read: status ย */ |
1022 | u8 command; /* write: command */ | 1024 | u8 command; /* write: command */ |
1023 | }; | 1025 | }; |
1024 | }; | 1026 | }; |
1025 | 1027 | ||
1026 | typedef struct ide_task_s { | 1028 | typedef struct ide_task_s { |
1027 | union { | 1029 | union { |
1028 | struct ide_taskfile tf; | 1030 | struct ide_taskfile tf; |
1029 | u8 tf_array[14]; | 1031 | u8 tf_array[14]; |
1030 | }; | 1032 | }; |
1031 | u32 tf_flags; | 1033 | u32 tf_flags; |
1032 | int data_phase; | 1034 | int data_phase; |
1033 | struct request *rq; /* copy of request */ | 1035 | struct request *rq; /* copy of request */ |
1034 | void *special; /* valid_t generally */ | 1036 | void *special; /* valid_t generally */ |
1035 | } ide_task_t; | 1037 | } ide_task_t; |
1036 | 1038 | ||
1037 | void ide_tf_dump(const char *, struct ide_taskfile *); | 1039 | void ide_tf_dump(const char *, struct ide_taskfile *); |
1038 | 1040 | ||
1039 | void ide_exec_command(ide_hwif_t *, u8); | 1041 | void ide_exec_command(ide_hwif_t *, u8); |
1040 | u8 ide_read_status(ide_hwif_t *); | 1042 | u8 ide_read_status(ide_hwif_t *); |
1041 | u8 ide_read_altstatus(ide_hwif_t *); | 1043 | u8 ide_read_altstatus(ide_hwif_t *); |
1042 | u8 ide_read_sff_dma_status(ide_hwif_t *); | 1044 | u8 ide_read_sff_dma_status(ide_hwif_t *); |
1043 | 1045 | ||
1044 | void ide_set_irq(ide_hwif_t *, int); | 1046 | void ide_set_irq(ide_hwif_t *, int); |
1045 | 1047 | ||
1046 | void ide_tf_load(ide_drive_t *, ide_task_t *); | 1048 | void ide_tf_load(ide_drive_t *, ide_task_t *); |
1047 | void ide_tf_read(ide_drive_t *, ide_task_t *); | 1049 | void ide_tf_read(ide_drive_t *, ide_task_t *); |
1048 | 1050 | ||
1049 | void ide_input_data(ide_drive_t *, struct request *, void *, unsigned int); | 1051 | void ide_input_data(ide_drive_t *, struct request *, void *, unsigned int); |
1050 | void ide_output_data(ide_drive_t *, struct request *, void *, unsigned int); | 1052 | void ide_output_data(ide_drive_t *, struct request *, void *, unsigned int); |
1051 | 1053 | ||
1052 | extern void SELECT_DRIVE(ide_drive_t *); | 1054 | extern void SELECT_DRIVE(ide_drive_t *); |
1053 | void SELECT_MASK(ide_drive_t *, int); | 1055 | void SELECT_MASK(ide_drive_t *, int); |
1054 | 1056 | ||
1055 | u8 ide_read_error(ide_drive_t *); | 1057 | u8 ide_read_error(ide_drive_t *); |
1056 | void ide_read_bcount_and_ireason(ide_drive_t *, u16 *, u8 *); | 1058 | void ide_read_bcount_and_ireason(ide_drive_t *, u16 *, u8 *); |
1057 | 1059 | ||
1058 | extern int drive_is_ready(ide_drive_t *); | 1060 | extern int drive_is_ready(ide_drive_t *); |
1059 | 1061 | ||
1060 | void ide_pktcmd_tf_load(ide_drive_t *, u32, u16, u8); | 1062 | void ide_pktcmd_tf_load(ide_drive_t *, u32, u16, u8); |
1061 | 1063 | ||
1062 | ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc, | 1064 | ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc, |
1063 | ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry, | 1065 | ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry, |
1064 | void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *), | 1066 | void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *), |
1065 | void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *), | 1067 | void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *), |
1066 | void (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned int, | 1068 | void (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned int, |
1067 | int)); | 1069 | int)); |
1068 | ide_startstop_t ide_transfer_pc(ide_drive_t *, struct ide_atapi_pc *, | 1070 | ide_startstop_t ide_transfer_pc(ide_drive_t *, struct ide_atapi_pc *, |
1069 | ide_handler_t *, unsigned int, ide_expiry_t *); | 1071 | ide_handler_t *, unsigned int, ide_expiry_t *); |
1070 | ide_startstop_t ide_issue_pc(ide_drive_t *, struct ide_atapi_pc *, | 1072 | ide_startstop_t ide_issue_pc(ide_drive_t *, struct ide_atapi_pc *, |
1071 | ide_handler_t *, unsigned int, ide_expiry_t *); | 1073 | ide_handler_t *, unsigned int, ide_expiry_t *); |
1072 | 1074 | ||
1073 | ide_startstop_t do_rw_taskfile(ide_drive_t *, ide_task_t *); | 1075 | ide_startstop_t do_rw_taskfile(ide_drive_t *, ide_task_t *); |
1074 | 1076 | ||
1075 | void task_end_request(ide_drive_t *, struct request *, u8); | 1077 | void task_end_request(ide_drive_t *, struct request *, u8); |
1076 | 1078 | ||
1077 | int ide_raw_taskfile(ide_drive_t *, ide_task_t *, u8 *, u16); | 1079 | int ide_raw_taskfile(ide_drive_t *, ide_task_t *, u8 *, u16); |
1078 | int ide_no_data_taskfile(ide_drive_t *, ide_task_t *); | 1080 | int ide_no_data_taskfile(ide_drive_t *, ide_task_t *); |
1079 | 1081 | ||
1080 | int ide_taskfile_ioctl(ide_drive_t *, unsigned int, unsigned long); | 1082 | int ide_taskfile_ioctl(ide_drive_t *, unsigned int, unsigned long); |
1081 | int ide_cmd_ioctl(ide_drive_t *, unsigned int, unsigned long); | 1083 | int ide_cmd_ioctl(ide_drive_t *, unsigned int, unsigned long); |
1082 | int ide_task_ioctl(ide_drive_t *, unsigned int, unsigned long); | 1084 | int ide_task_ioctl(ide_drive_t *, unsigned int, unsigned long); |
1083 | 1085 | ||
1084 | extern int ide_driveid_update(ide_drive_t *); | 1086 | extern int ide_driveid_update(ide_drive_t *); |
1085 | extern int ide_config_drive_speed(ide_drive_t *, u8); | 1087 | extern int ide_config_drive_speed(ide_drive_t *, u8); |
1086 | extern u8 eighty_ninty_three (ide_drive_t *); | 1088 | extern u8 eighty_ninty_three (ide_drive_t *); |
1087 | extern int taskfile_lib_get_identify(ide_drive_t *drive, u8 *); | 1089 | extern int taskfile_lib_get_identify(ide_drive_t *drive, u8 *); |
1088 | 1090 | ||
1089 | extern int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout); | 1091 | extern int ide_wait_not_busy(ide_hwif_t *hwif, unsigned long timeout); |
1090 | 1092 | ||
1091 | extern void ide_stall_queue(ide_drive_t *drive, unsigned long timeout); | 1093 | extern void ide_stall_queue(ide_drive_t *drive, unsigned long timeout); |
1092 | 1094 | ||
1093 | extern int ide_spin_wait_hwgroup(ide_drive_t *); | 1095 | extern int ide_spin_wait_hwgroup(ide_drive_t *); |
1094 | extern void ide_timer_expiry(unsigned long); | 1096 | extern void ide_timer_expiry(unsigned long); |
1095 | extern irqreturn_t ide_intr(int irq, void *dev_id); | 1097 | extern irqreturn_t ide_intr(int irq, void *dev_id); |
1096 | extern void do_ide_request(struct request_queue *); | 1098 | extern void do_ide_request(struct request_queue *); |
1097 | 1099 | ||
1098 | void ide_init_disk(struct gendisk *, ide_drive_t *); | 1100 | void ide_init_disk(struct gendisk *, ide_drive_t *); |
1099 | 1101 | ||
1100 | #ifdef CONFIG_IDEPCI_PCIBUS_ORDER | 1102 | #ifdef CONFIG_IDEPCI_PCIBUS_ORDER |
1101 | extern int __ide_pci_register_driver(struct pci_driver *driver, struct module *owner, const char *mod_name); | 1103 | extern int __ide_pci_register_driver(struct pci_driver *driver, struct module *owner, const char *mod_name); |
1102 | #define ide_pci_register_driver(d) __ide_pci_register_driver(d, THIS_MODULE, KBUILD_MODNAME) | 1104 | #define ide_pci_register_driver(d) __ide_pci_register_driver(d, THIS_MODULE, KBUILD_MODNAME) |
1103 | #else | 1105 | #else |
1104 | #define ide_pci_register_driver(d) pci_register_driver(d) | 1106 | #define ide_pci_register_driver(d) pci_register_driver(d) |
1105 | #endif | 1107 | #endif |
1106 | 1108 | ||
1107 | void ide_pci_setup_ports(struct pci_dev *, const struct ide_port_info *, int, | 1109 | void ide_pci_setup_ports(struct pci_dev *, const struct ide_port_info *, int, |
1108 | hw_regs_t *, hw_regs_t **); | 1110 | hw_regs_t *, hw_regs_t **); |
1109 | void ide_setup_pci_noise(struct pci_dev *, const struct ide_port_info *); | 1111 | void ide_setup_pci_noise(struct pci_dev *, const struct ide_port_info *); |
1110 | 1112 | ||
1111 | #ifdef CONFIG_BLK_DEV_IDEDMA_PCI | 1113 | #ifdef CONFIG_BLK_DEV_IDEDMA_PCI |
1112 | int ide_pci_set_master(struct pci_dev *, const char *); | 1114 | int ide_pci_set_master(struct pci_dev *, const char *); |
1113 | unsigned long ide_pci_dma_base(ide_hwif_t *, const struct ide_port_info *); | 1115 | unsigned long ide_pci_dma_base(ide_hwif_t *, const struct ide_port_info *); |
1114 | int ide_pci_check_simplex(ide_hwif_t *, const struct ide_port_info *); | 1116 | int ide_pci_check_simplex(ide_hwif_t *, const struct ide_port_info *); |
1115 | int ide_hwif_setup_dma(ide_hwif_t *, const struct ide_port_info *); | 1117 | int ide_hwif_setup_dma(ide_hwif_t *, const struct ide_port_info *); |
1116 | #else | 1118 | #else |
1117 | static inline int ide_hwif_setup_dma(ide_hwif_t *hwif, | 1119 | static inline int ide_hwif_setup_dma(ide_hwif_t *hwif, |
1118 | const struct ide_port_info *d) | 1120 | const struct ide_port_info *d) |
1119 | { | 1121 | { |
1120 | return -EINVAL; | 1122 | return -EINVAL; |
1121 | } | 1123 | } |
1122 | #endif | 1124 | #endif |
1123 | 1125 | ||
1124 | typedef struct ide_pci_enablebit_s { | 1126 | typedef struct ide_pci_enablebit_s { |
1125 | u8 reg; /* byte pci reg holding the enable-bit */ | 1127 | u8 reg; /* byte pci reg holding the enable-bit */ |
1126 | u8 mask; /* mask to isolate the enable-bit */ | 1128 | u8 mask; /* mask to isolate the enable-bit */ |
1127 | u8 val; /* value of masked reg when "enabled" */ | 1129 | u8 val; /* value of masked reg when "enabled" */ |
1128 | } ide_pci_enablebit_t; | 1130 | } ide_pci_enablebit_t; |
1129 | 1131 | ||
1130 | enum { | 1132 | enum { |
1131 | /* Uses ISA control ports not PCI ones. */ | 1133 | /* Uses ISA control ports not PCI ones. */ |
1132 | IDE_HFLAG_ISA_PORTS = (1 << 0), | 1134 | IDE_HFLAG_ISA_PORTS = (1 << 0), |
1133 | /* single port device */ | 1135 | /* single port device */ |
1134 | IDE_HFLAG_SINGLE = (1 << 1), | 1136 | IDE_HFLAG_SINGLE = (1 << 1), |
1135 | /* don't use legacy PIO blacklist */ | 1137 | /* don't use legacy PIO blacklist */ |
1136 | IDE_HFLAG_PIO_NO_BLACKLIST = (1 << 2), | 1138 | IDE_HFLAG_PIO_NO_BLACKLIST = (1 << 2), |
1137 | /* set for the second port of QD65xx */ | 1139 | /* set for the second port of QD65xx */ |
1138 | IDE_HFLAG_QD_2ND_PORT = (1 << 3), | 1140 | IDE_HFLAG_QD_2ND_PORT = (1 << 3), |
1139 | /* use PIO8/9 for prefetch off/on */ | 1141 | /* use PIO8/9 for prefetch off/on */ |
1140 | IDE_HFLAG_ABUSE_PREFETCH = (1 << 4), | 1142 | IDE_HFLAG_ABUSE_PREFETCH = (1 << 4), |
1141 | /* use PIO6/7 for fast-devsel off/on */ | 1143 | /* use PIO6/7 for fast-devsel off/on */ |
1142 | IDE_HFLAG_ABUSE_FAST_DEVSEL = (1 << 5), | 1144 | IDE_HFLAG_ABUSE_FAST_DEVSEL = (1 << 5), |
1143 | /* use 100-102 and 200-202 PIO values to set DMA modes */ | 1145 | /* use 100-102 and 200-202 PIO values to set DMA modes */ |
1144 | IDE_HFLAG_ABUSE_DMA_MODES = (1 << 6), | 1146 | IDE_HFLAG_ABUSE_DMA_MODES = (1 << 6), |
1145 | /* | 1147 | /* |
1146 | * keep DMA setting when programming PIO mode, may be used only | 1148 | * keep DMA setting when programming PIO mode, may be used only |
1147 | * for hosts which have separate PIO and DMA timings (ie. PMAC) | 1149 | * for hosts which have separate PIO and DMA timings (ie. PMAC) |
1148 | */ | 1150 | */ |
1149 | IDE_HFLAG_SET_PIO_MODE_KEEP_DMA = (1 << 7), | 1151 | IDE_HFLAG_SET_PIO_MODE_KEEP_DMA = (1 << 7), |
1150 | /* program host for the transfer mode after programming device */ | 1152 | /* program host for the transfer mode after programming device */ |
1151 | IDE_HFLAG_POST_SET_MODE = (1 << 8), | 1153 | IDE_HFLAG_POST_SET_MODE = (1 << 8), |
1152 | /* don't program host/device for the transfer mode ("smart" hosts) */ | 1154 | /* don't program host/device for the transfer mode ("smart" hosts) */ |
1153 | IDE_HFLAG_NO_SET_MODE = (1 << 9), | 1155 | IDE_HFLAG_NO_SET_MODE = (1 << 9), |
1154 | /* trust BIOS for programming chipset/device for DMA */ | 1156 | /* trust BIOS for programming chipset/device for DMA */ |
1155 | IDE_HFLAG_TRUST_BIOS_FOR_DMA = (1 << 10), | 1157 | IDE_HFLAG_TRUST_BIOS_FOR_DMA = (1 << 10), |
1156 | /* host is CS5510/CS5520 */ | 1158 | /* host is CS5510/CS5520 */ |
1157 | IDE_HFLAG_CS5520 = (1 << 11), | 1159 | IDE_HFLAG_CS5520 = (1 << 11), |
1158 | /* ATAPI DMA is unsupported */ | 1160 | /* ATAPI DMA is unsupported */ |
1159 | IDE_HFLAG_NO_ATAPI_DMA = (1 << 12), | 1161 | IDE_HFLAG_NO_ATAPI_DMA = (1 << 12), |
1160 | /* set if host is a "non-bootable" controller */ | 1162 | /* set if host is a "non-bootable" controller */ |
1161 | IDE_HFLAG_NON_BOOTABLE = (1 << 13), | 1163 | IDE_HFLAG_NON_BOOTABLE = (1 << 13), |
1162 | /* host doesn't support DMA */ | 1164 | /* host doesn't support DMA */ |
1163 | IDE_HFLAG_NO_DMA = (1 << 14), | 1165 | IDE_HFLAG_NO_DMA = (1 << 14), |
1164 | /* check if host is PCI IDE device before allowing DMA */ | 1166 | /* check if host is PCI IDE device before allowing DMA */ |
1165 | IDE_HFLAG_NO_AUTODMA = (1 << 15), | 1167 | IDE_HFLAG_NO_AUTODMA = (1 << 15), |
1166 | /* host uses MMIO */ | 1168 | /* host uses MMIO */ |
1167 | IDE_HFLAG_MMIO = (1 << 16), | 1169 | IDE_HFLAG_MMIO = (1 << 16), |
1168 | /* no LBA48 */ | 1170 | /* no LBA48 */ |
1169 | IDE_HFLAG_NO_LBA48 = (1 << 17), | 1171 | IDE_HFLAG_NO_LBA48 = (1 << 17), |
1170 | /* no LBA48 DMA */ | 1172 | /* no LBA48 DMA */ |
1171 | IDE_HFLAG_NO_LBA48_DMA = (1 << 18), | 1173 | IDE_HFLAG_NO_LBA48_DMA = (1 << 18), |
1172 | /* data FIFO is cleared by an error */ | 1174 | /* data FIFO is cleared by an error */ |
1173 | IDE_HFLAG_ERROR_STOPS_FIFO = (1 << 19), | 1175 | IDE_HFLAG_ERROR_STOPS_FIFO = (1 << 19), |
1174 | /* serialize ports */ | 1176 | /* serialize ports */ |
1175 | IDE_HFLAG_SERIALIZE = (1 << 20), | 1177 | IDE_HFLAG_SERIALIZE = (1 << 20), |
1176 | /* use legacy IRQs */ | 1178 | /* use legacy IRQs */ |
1177 | IDE_HFLAG_LEGACY_IRQS = (1 << 21), | 1179 | IDE_HFLAG_LEGACY_IRQS = (1 << 21), |
1178 | /* force use of legacy IRQs */ | 1180 | /* force use of legacy IRQs */ |
1179 | IDE_HFLAG_FORCE_LEGACY_IRQS = (1 << 22), | 1181 | IDE_HFLAG_FORCE_LEGACY_IRQS = (1 << 22), |
1180 | /* limit LBA48 requests to 256 sectors */ | 1182 | /* limit LBA48 requests to 256 sectors */ |
1181 | IDE_HFLAG_RQSIZE_256 = (1 << 23), | 1183 | IDE_HFLAG_RQSIZE_256 = (1 << 23), |
1182 | /* use 32-bit I/O ops */ | 1184 | /* use 32-bit I/O ops */ |
1183 | IDE_HFLAG_IO_32BIT = (1 << 24), | 1185 | IDE_HFLAG_IO_32BIT = (1 << 24), |
1184 | /* unmask IRQs */ | 1186 | /* unmask IRQs */ |
1185 | IDE_HFLAG_UNMASK_IRQS = (1 << 25), | 1187 | IDE_HFLAG_UNMASK_IRQS = (1 << 25), |
1186 | /* serialize ports if DMA is possible (for sl82c105) */ | 1188 | /* serialize ports if DMA is possible (for sl82c105) */ |
1187 | IDE_HFLAG_SERIALIZE_DMA = (1 << 27), | 1189 | IDE_HFLAG_SERIALIZE_DMA = (1 << 27), |
1188 | /* force host out of "simplex" mode */ | 1190 | /* force host out of "simplex" mode */ |
1189 | IDE_HFLAG_CLEAR_SIMPLEX = (1 << 28), | 1191 | IDE_HFLAG_CLEAR_SIMPLEX = (1 << 28), |
1190 | /* DSC overlap is unsupported */ | 1192 | /* DSC overlap is unsupported */ |
1191 | IDE_HFLAG_NO_DSC = (1 << 29), | 1193 | IDE_HFLAG_NO_DSC = (1 << 29), |
1192 | /* never use 32-bit I/O ops */ | 1194 | /* never use 32-bit I/O ops */ |
1193 | IDE_HFLAG_NO_IO_32BIT = (1 << 30), | 1195 | IDE_HFLAG_NO_IO_32BIT = (1 << 30), |
1194 | /* never unmask IRQs */ | 1196 | /* never unmask IRQs */ |
1195 | IDE_HFLAG_NO_UNMASK_IRQS = (1 << 31), | 1197 | IDE_HFLAG_NO_UNMASK_IRQS = (1 << 31), |
1196 | }; | 1198 | }; |
1197 | 1199 | ||
1198 | #ifdef CONFIG_BLK_DEV_OFFBOARD | 1200 | #ifdef CONFIG_BLK_DEV_OFFBOARD |
1199 | # define IDE_HFLAG_OFF_BOARD 0 | 1201 | # define IDE_HFLAG_OFF_BOARD 0 |
1200 | #else | 1202 | #else |
1201 | # define IDE_HFLAG_OFF_BOARD IDE_HFLAG_NON_BOOTABLE | 1203 | # define IDE_HFLAG_OFF_BOARD IDE_HFLAG_NON_BOOTABLE |
1202 | #endif | 1204 | #endif |
1203 | 1205 | ||
1204 | struct ide_port_info { | 1206 | struct ide_port_info { |
1205 | char *name; | 1207 | char *name; |
1206 | unsigned int (*init_chipset)(struct pci_dev *); | 1208 | unsigned int (*init_chipset)(struct pci_dev *); |
1207 | void (*init_iops)(ide_hwif_t *); | 1209 | void (*init_iops)(ide_hwif_t *); |
1208 | void (*init_hwif)(ide_hwif_t *); | 1210 | void (*init_hwif)(ide_hwif_t *); |
1209 | int (*init_dma)(ide_hwif_t *, | 1211 | int (*init_dma)(ide_hwif_t *, |
1210 | const struct ide_port_info *); | 1212 | const struct ide_port_info *); |
1211 | 1213 | ||
1212 | const struct ide_tp_ops *tp_ops; | 1214 | const struct ide_tp_ops *tp_ops; |
1213 | const struct ide_port_ops *port_ops; | 1215 | const struct ide_port_ops *port_ops; |
1214 | const struct ide_dma_ops *dma_ops; | 1216 | const struct ide_dma_ops *dma_ops; |
1215 | 1217 | ||
1216 | ide_pci_enablebit_t enablebits[2]; | 1218 | ide_pci_enablebit_t enablebits[2]; |
1217 | hwif_chipset_t chipset; | 1219 | hwif_chipset_t chipset; |
1218 | u32 host_flags; | 1220 | u32 host_flags; |
1219 | u8 pio_mask; | 1221 | u8 pio_mask; |
1220 | u8 swdma_mask; | 1222 | u8 swdma_mask; |
1221 | u8 mwdma_mask; | 1223 | u8 mwdma_mask; |
1222 | u8 udma_mask; | 1224 | u8 udma_mask; |
1223 | }; | 1225 | }; |
1224 | 1226 | ||
1225 | int ide_pci_init_one(struct pci_dev *, const struct ide_port_info *, void *); | 1227 | int ide_pci_init_one(struct pci_dev *, const struct ide_port_info *, void *); |
1226 | int ide_pci_init_two(struct pci_dev *, struct pci_dev *, | 1228 | int ide_pci_init_two(struct pci_dev *, struct pci_dev *, |
1227 | const struct ide_port_info *, void *); | 1229 | const struct ide_port_info *, void *); |
1228 | void ide_pci_remove(struct pci_dev *); | 1230 | void ide_pci_remove(struct pci_dev *); |
1229 | 1231 | ||
1230 | void ide_map_sg(ide_drive_t *, struct request *); | 1232 | void ide_map_sg(ide_drive_t *, struct request *); |
1231 | void ide_init_sg_cmd(ide_drive_t *, struct request *); | 1233 | void ide_init_sg_cmd(ide_drive_t *, struct request *); |
1232 | 1234 | ||
1233 | #define BAD_DMA_DRIVE 0 | 1235 | #define BAD_DMA_DRIVE 0 |
1234 | #define GOOD_DMA_DRIVE 1 | 1236 | #define GOOD_DMA_DRIVE 1 |
1235 | 1237 | ||
1236 | struct drive_list_entry { | 1238 | struct drive_list_entry { |
1237 | const char *id_model; | 1239 | const char *id_model; |
1238 | const char *id_firmware; | 1240 | const char *id_firmware; |
1239 | }; | 1241 | }; |
1240 | 1242 | ||
1241 | int ide_in_drive_list(struct hd_driveid *, const struct drive_list_entry *); | 1243 | int ide_in_drive_list(struct hd_driveid *, const struct drive_list_entry *); |
1242 | 1244 | ||
1243 | #ifdef CONFIG_BLK_DEV_IDEDMA | 1245 | #ifdef CONFIG_BLK_DEV_IDEDMA |
1244 | int __ide_dma_bad_drive(ide_drive_t *); | 1246 | int __ide_dma_bad_drive(ide_drive_t *); |
1245 | int ide_id_dma_bug(ide_drive_t *); | 1247 | int ide_id_dma_bug(ide_drive_t *); |
1246 | 1248 | ||
1247 | u8 ide_find_dma_mode(ide_drive_t *, u8); | 1249 | u8 ide_find_dma_mode(ide_drive_t *, u8); |
1248 | 1250 | ||
1249 | static inline u8 ide_max_dma_mode(ide_drive_t *drive) | 1251 | static inline u8 ide_max_dma_mode(ide_drive_t *drive) |
1250 | { | 1252 | { |
1251 | return ide_find_dma_mode(drive, XFER_UDMA_6); | 1253 | return ide_find_dma_mode(drive, XFER_UDMA_6); |
1252 | } | 1254 | } |
1253 | 1255 | ||
1254 | void ide_dma_off_quietly(ide_drive_t *); | 1256 | void ide_dma_off_quietly(ide_drive_t *); |
1255 | void ide_dma_off(ide_drive_t *); | 1257 | void ide_dma_off(ide_drive_t *); |
1256 | void ide_dma_on(ide_drive_t *); | 1258 | void ide_dma_on(ide_drive_t *); |
1257 | int ide_set_dma(ide_drive_t *); | 1259 | int ide_set_dma(ide_drive_t *); |
1258 | void ide_check_dma_crc(ide_drive_t *); | 1260 | void ide_check_dma_crc(ide_drive_t *); |
1259 | ide_startstop_t ide_dma_intr(ide_drive_t *); | 1261 | ide_startstop_t ide_dma_intr(ide_drive_t *); |
1260 | 1262 | ||
1261 | int ide_build_sglist(ide_drive_t *, struct request *); | 1263 | int ide_build_sglist(ide_drive_t *, struct request *); |
1262 | void ide_destroy_dmatable(ide_drive_t *); | 1264 | void ide_destroy_dmatable(ide_drive_t *); |
1263 | 1265 | ||
1264 | #ifdef CONFIG_BLK_DEV_IDEDMA_SFF | 1266 | #ifdef CONFIG_BLK_DEV_IDEDMA_SFF |
1265 | extern int ide_build_dmatable(ide_drive_t *, struct request *); | 1267 | extern int ide_build_dmatable(ide_drive_t *, struct request *); |
1266 | int ide_allocate_dma_engine(ide_hwif_t *); | 1268 | int ide_allocate_dma_engine(ide_hwif_t *); |
1267 | void ide_release_dma_engine(ide_hwif_t *); | 1269 | void ide_release_dma_engine(ide_hwif_t *); |
1268 | 1270 | ||
1269 | void ide_dma_host_set(ide_drive_t *, int); | 1271 | void ide_dma_host_set(ide_drive_t *, int); |
1270 | extern int ide_dma_setup(ide_drive_t *); | 1272 | extern int ide_dma_setup(ide_drive_t *); |
1271 | void ide_dma_exec_cmd(ide_drive_t *, u8); | 1273 | void ide_dma_exec_cmd(ide_drive_t *, u8); |
1272 | extern void ide_dma_start(ide_drive_t *); | 1274 | extern void ide_dma_start(ide_drive_t *); |
1273 | extern int __ide_dma_end(ide_drive_t *); | 1275 | extern int __ide_dma_end(ide_drive_t *); |
1274 | int ide_dma_test_irq(ide_drive_t *); | 1276 | int ide_dma_test_irq(ide_drive_t *); |
1275 | extern void ide_dma_lost_irq(ide_drive_t *); | 1277 | extern void ide_dma_lost_irq(ide_drive_t *); |
1276 | extern void ide_dma_timeout(ide_drive_t *); | 1278 | extern void ide_dma_timeout(ide_drive_t *); |
1277 | extern const struct ide_dma_ops sff_dma_ops; | 1279 | extern const struct ide_dma_ops sff_dma_ops; |
1278 | #endif /* CONFIG_BLK_DEV_IDEDMA_SFF */ | 1280 | #endif /* CONFIG_BLK_DEV_IDEDMA_SFF */ |
1279 | 1281 | ||
1280 | #else | 1282 | #else |
1281 | static inline int ide_id_dma_bug(ide_drive_t *drive) { return 0; } | 1283 | static inline int ide_id_dma_bug(ide_drive_t *drive) { return 0; } |
1282 | static inline u8 ide_find_dma_mode(ide_drive_t *drive, u8 speed) { return 0; } | 1284 | static inline u8 ide_find_dma_mode(ide_drive_t *drive, u8 speed) { return 0; } |
1283 | static inline u8 ide_max_dma_mode(ide_drive_t *drive) { return 0; } | 1285 | static inline u8 ide_max_dma_mode(ide_drive_t *drive) { return 0; } |
1284 | static inline void ide_dma_off_quietly(ide_drive_t *drive) { ; } | 1286 | static inline void ide_dma_off_quietly(ide_drive_t *drive) { ; } |
1285 | static inline void ide_dma_off(ide_drive_t *drive) { ; } | 1287 | static inline void ide_dma_off(ide_drive_t *drive) { ; } |
1286 | static inline void ide_dma_on(ide_drive_t *drive) { ; } | 1288 | static inline void ide_dma_on(ide_drive_t *drive) { ; } |
1287 | static inline void ide_dma_verbose(ide_drive_t *drive) { ; } | 1289 | static inline void ide_dma_verbose(ide_drive_t *drive) { ; } |
1288 | static inline int ide_set_dma(ide_drive_t *drive) { return 1; } | 1290 | static inline int ide_set_dma(ide_drive_t *drive) { return 1; } |
1289 | static inline void ide_check_dma_crc(ide_drive_t *drive) { ; } | 1291 | static inline void ide_check_dma_crc(ide_drive_t *drive) { ; } |
1290 | #endif /* CONFIG_BLK_DEV_IDEDMA */ | 1292 | #endif /* CONFIG_BLK_DEV_IDEDMA */ |
1291 | 1293 | ||
1292 | #ifndef CONFIG_BLK_DEV_IDEDMA_SFF | 1294 | #ifndef CONFIG_BLK_DEV_IDEDMA_SFF |
1293 | static inline void ide_release_dma_engine(ide_hwif_t *hwif) { ; } | 1295 | static inline void ide_release_dma_engine(ide_hwif_t *hwif) { ; } |
1294 | #endif | 1296 | #endif |
1295 | 1297 | ||
1296 | #ifdef CONFIG_BLK_DEV_IDEACPI | 1298 | #ifdef CONFIG_BLK_DEV_IDEACPI |
1297 | extern int ide_acpi_exec_tfs(ide_drive_t *drive); | 1299 | extern int ide_acpi_exec_tfs(ide_drive_t *drive); |
1298 | extern void ide_acpi_get_timing(ide_hwif_t *hwif); | 1300 | extern void ide_acpi_get_timing(ide_hwif_t *hwif); |
1299 | extern void ide_acpi_push_timing(ide_hwif_t *hwif); | 1301 | extern void ide_acpi_push_timing(ide_hwif_t *hwif); |
1300 | extern void ide_acpi_init(ide_hwif_t *hwif); | 1302 | extern void ide_acpi_init(ide_hwif_t *hwif); |
1301 | void ide_acpi_port_init_devices(ide_hwif_t *); | 1303 | void ide_acpi_port_init_devices(ide_hwif_t *); |
1302 | extern void ide_acpi_set_state(ide_hwif_t *hwif, int on); | 1304 | extern void ide_acpi_set_state(ide_hwif_t *hwif, int on); |
1303 | #else | 1305 | #else |
1304 | static inline int ide_acpi_exec_tfs(ide_drive_t *drive) { return 0; } | 1306 | static inline int ide_acpi_exec_tfs(ide_drive_t *drive) { return 0; } |
1305 | static inline void ide_acpi_get_timing(ide_hwif_t *hwif) { ; } | 1307 | static inline void ide_acpi_get_timing(ide_hwif_t *hwif) { ; } |
1306 | static inline void ide_acpi_push_timing(ide_hwif_t *hwif) { ; } | 1308 | static inline void ide_acpi_push_timing(ide_hwif_t *hwif) { ; } |
1307 | static inline void ide_acpi_init(ide_hwif_t *hwif) { ; } | 1309 | static inline void ide_acpi_init(ide_hwif_t *hwif) { ; } |
1308 | static inline void ide_acpi_port_init_devices(ide_hwif_t *hwif) { ; } | 1310 | static inline void ide_acpi_port_init_devices(ide_hwif_t *hwif) { ; } |
1309 | static inline void ide_acpi_set_state(ide_hwif_t *hwif, int on) {} | 1311 | static inline void ide_acpi_set_state(ide_hwif_t *hwif, int on) {} |
1310 | #endif | 1312 | #endif |
1311 | 1313 | ||
1312 | void ide_remove_port_from_hwgroup(ide_hwif_t *); | 1314 | void ide_remove_port_from_hwgroup(ide_hwif_t *); |
1313 | void ide_unregister(ide_hwif_t *); | 1315 | void ide_unregister(ide_hwif_t *); |
1314 | 1316 | ||
1315 | void ide_register_region(struct gendisk *); | 1317 | void ide_register_region(struct gendisk *); |
1316 | void ide_unregister_region(struct gendisk *); | 1318 | void ide_unregister_region(struct gendisk *); |
1317 | 1319 | ||
1318 | void ide_undecoded_slave(ide_drive_t *); | 1320 | void ide_undecoded_slave(ide_drive_t *); |
1319 | 1321 | ||
1320 | void ide_port_apply_params(ide_hwif_t *); | 1322 | void ide_port_apply_params(ide_hwif_t *); |
1321 | 1323 | ||
1322 | struct ide_host *ide_host_alloc_all(const struct ide_port_info *, hw_regs_t **); | 1324 | struct ide_host *ide_host_alloc_all(const struct ide_port_info *, hw_regs_t **); |
1323 | struct ide_host *ide_host_alloc(const struct ide_port_info *, hw_regs_t **); | 1325 | struct ide_host *ide_host_alloc(const struct ide_port_info *, hw_regs_t **); |
1324 | void ide_host_free(struct ide_host *); | 1326 | void ide_host_free(struct ide_host *); |
1325 | int ide_host_register(struct ide_host *, const struct ide_port_info *, | 1327 | int ide_host_register(struct ide_host *, const struct ide_port_info *, |
1326 | hw_regs_t **); | 1328 | hw_regs_t **); |
1327 | int ide_host_add(const struct ide_port_info *, hw_regs_t **, | 1329 | int ide_host_add(const struct ide_port_info *, hw_regs_t **, |
1328 | struct ide_host **); | 1330 | struct ide_host **); |
1329 | void ide_host_remove(struct ide_host *); | 1331 | void ide_host_remove(struct ide_host *); |
1330 | int ide_legacy_device_add(const struct ide_port_info *, unsigned long); | 1332 | int ide_legacy_device_add(const struct ide_port_info *, unsigned long); |
1331 | void ide_port_unregister_devices(ide_hwif_t *); | 1333 | void ide_port_unregister_devices(ide_hwif_t *); |
1332 | void ide_port_scan(ide_hwif_t *); | 1334 | void ide_port_scan(ide_hwif_t *); |
1333 | 1335 | ||
1334 | static inline void *ide_get_hwifdata (ide_hwif_t * hwif) | 1336 | static inline void *ide_get_hwifdata (ide_hwif_t * hwif) |
1335 | { | 1337 | { |
1336 | return hwif->hwif_data; | 1338 | return hwif->hwif_data; |
1337 | } | 1339 | } |
1338 | 1340 | ||
1339 | static inline void ide_set_hwifdata (ide_hwif_t * hwif, void *data) | 1341 | static inline void ide_set_hwifdata (ide_hwif_t * hwif, void *data) |
1340 | { | 1342 | { |
1341 | hwif->hwif_data = data; | 1343 | hwif->hwif_data = data; |
1342 | } | 1344 | } |
1343 | 1345 | ||
1344 | const char *ide_xfer_verbose(u8 mode); | 1346 | const char *ide_xfer_verbose(u8 mode); |
1345 | extern void ide_toggle_bounce(ide_drive_t *drive, int on); | 1347 | extern void ide_toggle_bounce(ide_drive_t *drive, int on); |
1346 | extern int ide_set_xfer_rate(ide_drive_t *drive, u8 rate); | 1348 | extern int ide_set_xfer_rate(ide_drive_t *drive, u8 rate); |
1347 | 1349 | ||
1348 | static inline int ide_dev_has_iordy(struct hd_driveid *id) | 1350 | static inline int ide_dev_has_iordy(struct hd_driveid *id) |
1349 | { | 1351 | { |
1350 | return ((id->field_valid & 2) && (id->capability & 8)) ? 1 : 0; | 1352 | return ((id->field_valid & 2) && (id->capability & 8)) ? 1 : 0; |
1351 | } | 1353 | } |
1352 | 1354 | ||
1353 | static inline int ide_dev_is_sata(struct hd_driveid *id) | 1355 | static inline int ide_dev_is_sata(struct hd_driveid *id) |
1354 | { | 1356 | { |
1355 | /* | 1357 | /* |
1356 | * See if word 93 is 0 AND drive is at least ATA-5 compatible | 1358 | * See if word 93 is 0 AND drive is at least ATA-5 compatible |
1357 | * verifying that word 80 by casting it to a signed type -- | 1359 | * verifying that word 80 by casting it to a signed type -- |
1358 | * this trick allows us to filter out the reserved values of | 1360 | * this trick allows us to filter out the reserved values of |
1359 | * 0x0000 and 0xffff along with the earlier ATA revisions... | 1361 | * 0x0000 and 0xffff along with the earlier ATA revisions... |
1360 | */ | 1362 | */ |
1361 | if (id->hw_config == 0 && (short)id->major_rev_num >= 0x0020) | 1363 | if (id->hw_config == 0 && (short)id->major_rev_num >= 0x0020) |
1362 | return 1; | 1364 | return 1; |
1363 | return 0; | 1365 | return 0; |
1364 | } | 1366 | } |
1365 | 1367 | ||
1366 | u64 ide_get_lba_addr(struct ide_taskfile *, int); | 1368 | u64 ide_get_lba_addr(struct ide_taskfile *, int); |
1367 | u8 ide_dump_status(ide_drive_t *, const char *, u8); | 1369 | u8 ide_dump_status(ide_drive_t *, const char *, u8); |
1368 | 1370 | ||
1369 | struct ide_timing { | 1371 | struct ide_timing { |
1370 | u8 mode; | 1372 | u8 mode; |
1371 | u8 setup; /* t1 */ | 1373 | u8 setup; /* t1 */ |
1372 | u16 act8b; /* t2 for 8-bit io */ | 1374 | u16 act8b; /* t2 for 8-bit io */ |
1373 | u16 rec8b; /* t2i for 8-bit io */ | 1375 | u16 rec8b; /* t2i for 8-bit io */ |
1374 | u16 cyc8b; /* t0 for 8-bit io */ | 1376 | u16 cyc8b; /* t0 for 8-bit io */ |
1375 | u16 active; /* t2 or tD */ | 1377 | u16 active; /* t2 or tD */ |
1376 | u16 recover; /* t2i or tK */ | 1378 | u16 recover; /* t2i or tK */ |
1377 | u16 cycle; /* t0 */ | 1379 | u16 cycle; /* t0 */ |
1378 | u16 udma; /* t2CYCTYP/2 */ | 1380 | u16 udma; /* t2CYCTYP/2 */ |
1379 | }; | 1381 | }; |
1380 | 1382 | ||
1381 | enum { | 1383 | enum { |
1382 | IDE_TIMING_SETUP = (1 << 0), | 1384 | IDE_TIMING_SETUP = (1 << 0), |
1383 | IDE_TIMING_ACT8B = (1 << 1), | 1385 | IDE_TIMING_ACT8B = (1 << 1), |
1384 | IDE_TIMING_REC8B = (1 << 2), | 1386 | IDE_TIMING_REC8B = (1 << 2), |
1385 | IDE_TIMING_CYC8B = (1 << 3), | 1387 | IDE_TIMING_CYC8B = (1 << 3), |
1386 | IDE_TIMING_8BIT = IDE_TIMING_ACT8B | IDE_TIMING_REC8B | | 1388 | IDE_TIMING_8BIT = IDE_TIMING_ACT8B | IDE_TIMING_REC8B | |
1387 | IDE_TIMING_CYC8B, | 1389 | IDE_TIMING_CYC8B, |
1388 | IDE_TIMING_ACTIVE = (1 << 4), | 1390 | IDE_TIMING_ACTIVE = (1 << 4), |
1389 | IDE_TIMING_RECOVER = (1 << 5), | 1391 | IDE_TIMING_RECOVER = (1 << 5), |
1390 | IDE_TIMING_CYCLE = (1 << 6), | 1392 | IDE_TIMING_CYCLE = (1 << 6), |
1391 | IDE_TIMING_UDMA = (1 << 7), | 1393 | IDE_TIMING_UDMA = (1 << 7), |
1392 | IDE_TIMING_ALL = IDE_TIMING_SETUP | IDE_TIMING_8BIT | | 1394 | IDE_TIMING_ALL = IDE_TIMING_SETUP | IDE_TIMING_8BIT | |
1393 | IDE_TIMING_ACTIVE | IDE_TIMING_RECOVER | | 1395 | IDE_TIMING_ACTIVE | IDE_TIMING_RECOVER | |
1394 | IDE_TIMING_CYCLE | IDE_TIMING_UDMA, | 1396 | IDE_TIMING_CYCLE | IDE_TIMING_UDMA, |
1395 | }; | 1397 | }; |
1396 | 1398 | ||
1397 | struct ide_timing *ide_timing_find_mode(u8); | 1399 | struct ide_timing *ide_timing_find_mode(u8); |
1398 | u16 ide_pio_cycle_time(ide_drive_t *, u8); | 1400 | u16 ide_pio_cycle_time(ide_drive_t *, u8); |
1399 | void ide_timing_merge(struct ide_timing *, struct ide_timing *, | 1401 | void ide_timing_merge(struct ide_timing *, struct ide_timing *, |
1400 | struct ide_timing *, unsigned int); | 1402 | struct ide_timing *, unsigned int); |
1401 | int ide_timing_compute(ide_drive_t *, u8, struct ide_timing *, int, int); | 1403 | int ide_timing_compute(ide_drive_t *, u8, struct ide_timing *, int, int); |
1402 | 1404 | ||
1403 | int ide_scan_pio_blacklist(char *); | 1405 | int ide_scan_pio_blacklist(char *); |
1404 | 1406 | ||
1405 | u8 ide_get_best_pio_mode(ide_drive_t *, u8, u8); | 1407 | u8 ide_get_best_pio_mode(ide_drive_t *, u8, u8); |
1406 | 1408 | ||
1407 | int ide_set_pio_mode(ide_drive_t *, u8); | 1409 | int ide_set_pio_mode(ide_drive_t *, u8); |
1408 | int ide_set_dma_mode(ide_drive_t *, u8); | 1410 | int ide_set_dma_mode(ide_drive_t *, u8); |
1409 | 1411 | ||
1410 | void ide_set_pio(ide_drive_t *, u8); | 1412 | void ide_set_pio(ide_drive_t *, u8); |
1411 | 1413 | ||
1412 | static inline void ide_set_max_pio(ide_drive_t *drive) | 1414 | static inline void ide_set_max_pio(ide_drive_t *drive) |
1413 | { | 1415 | { |
1414 | ide_set_pio(drive, 255); | 1416 | ide_set_pio(drive, 255); |
1415 | } | 1417 | } |
1416 | 1418 | ||
1417 | extern spinlock_t ide_lock; | 1419 | extern spinlock_t ide_lock; |
1418 | extern struct mutex ide_cfg_mtx; | 1420 | extern struct mutex ide_cfg_mtx; |
1419 | /* | 1421 | /* |
1420 | * Structure locking: | 1422 | * Structure locking: |
1421 | * | 1423 | * |
1422 | * ide_cfg_mtx and ide_lock together protect changes to | 1424 | * ide_cfg_mtx and ide_lock together protect changes to |
1423 | * ide_hwif_t->{next,hwgroup} | 1425 | * ide_hwif_t->{next,hwgroup} |
1424 | * ide_drive_t->next | 1426 | * ide_drive_t->next |
1425 | * | 1427 | * |
1426 | * ide_hwgroup_t->busy: ide_lock | 1428 | * ide_hwgroup_t->busy: ide_lock |
1427 | * ide_hwgroup_t->hwif: ide_lock | 1429 | * ide_hwgroup_t->hwif: ide_lock |
1428 | * ide_hwif_t->mate: constant, no locking | 1430 | * ide_hwif_t->mate: constant, no locking |
1429 | * ide_drive_t->hwif: constant, no locking | 1431 | * ide_drive_t->hwif: constant, no locking |
1430 | */ | 1432 | */ |
1431 | 1433 | ||
1432 | #define local_irq_set(flags) do { local_save_flags((flags)); local_irq_enable_in_hardirq(); } while (0) | 1434 | #define local_irq_set(flags) do { local_save_flags((flags)); local_irq_enable_in_hardirq(); } while (0) |
1433 | 1435 | ||
1434 | extern struct bus_type ide_bus_type; | 1436 | extern struct bus_type ide_bus_type; |
1435 | extern struct class *ide_port_class; | 1437 | extern struct class *ide_port_class; |
1436 | 1438 | ||
1437 | /* check if CACHE FLUSH (EXT) command is supported (bits defined in ATA-6) */ | 1439 | /* check if CACHE FLUSH (EXT) command is supported (bits defined in ATA-6) */ |
1438 | #define ide_id_has_flush_cache(id) ((id)->cfs_enable_2 & 0x3000) | 1440 | #define ide_id_has_flush_cache(id) ((id)->cfs_enable_2 & 0x3000) |
1439 | 1441 | ||
1440 | /* some Maxtor disks have bit 13 defined incorrectly so check bit 10 too */ | 1442 | /* some Maxtor disks have bit 13 defined incorrectly so check bit 10 too */ |
1441 | #define ide_id_has_flush_cache_ext(id) \ | 1443 | #define ide_id_has_flush_cache_ext(id) \ |
1442 | (((id)->cfs_enable_2 & 0x2400) == 0x2400) | 1444 | (((id)->cfs_enable_2 & 0x2400) == 0x2400) |
1443 | 1445 | ||
1444 | static inline void ide_dump_identify(u8 *id) | 1446 | static inline void ide_dump_identify(u8 *id) |
1445 | { | 1447 | { |
1446 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 2, id, 512, 0); | 1448 | print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 2, id, 512, 0); |
1447 | } | 1449 | } |
1448 | 1450 | ||
1449 | static inline int hwif_to_node(ide_hwif_t *hwif) | 1451 | static inline int hwif_to_node(ide_hwif_t *hwif) |
1450 | { | 1452 | { |
1451 | return hwif->dev ? dev_to_node(hwif->dev) : -1; | 1453 | return hwif->dev ? dev_to_node(hwif->dev) : -1; |
1452 | } | 1454 | } |
1453 | 1455 | ||
1454 | static inline ide_drive_t *ide_get_paired_drive(ide_drive_t *drive) | 1456 | static inline ide_drive_t *ide_get_paired_drive(ide_drive_t *drive) |
1455 | { | 1457 | { |
1456 | ide_hwif_t *hwif = HWIF(drive); | 1458 | ide_hwif_t *hwif = HWIF(drive); |
1457 | 1459 | ||
1458 | return &hwif->drives[(drive->dn ^ 1) & 1]; | 1460 | return &hwif->drives[(drive->dn ^ 1) & 1]; |
1459 | } | 1461 | } |
1460 | #endif /* _IDE_H */ | 1462 | #endif /* _IDE_H */ |
1461 | 1463 |