Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 1 | /* |
| 2 | * ATAPI support. |
| 3 | */ |
| 4 | |
| 5 | #include <linux/kernel.h> |
Borislav Petkov | 4cad085 | 2009-01-02 16:12:53 +0100 | [diff] [blame] | 6 | #include <linux/cdrom.h> |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 7 | #include <linux/delay.h> |
| 8 | #include <linux/ide.h> |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 9 | #include <scsi/scsi.h> |
| 10 | |
| 11 | #ifdef DEBUG |
| 12 | #define debug_log(fmt, args...) \ |
| 13 | printk(KERN_INFO "ide: " fmt, ## args) |
| 14 | #else |
| 15 | #define debug_log(fmt, args...) do {} while (0) |
| 16 | #endif |
| 17 | |
Borislav Petkov | 8c66285 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 18 | #define ATAPI_MIN_CDB_BYTES 12 |
| 19 | |
Borislav Petkov | 991cb26 | 2009-01-02 16:12:52 +0100 | [diff] [blame] | 20 | static inline int dev_is_idecd(ide_drive_t *drive) |
| 21 | { |
Borislav Petkov | 5317464 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 22 | return drive->media == ide_cdrom || drive->media == ide_optical; |
Borislav Petkov | 991cb26 | 2009-01-02 16:12:52 +0100 | [diff] [blame] | 23 | } |
| 24 | |
Bartlomiej Zolnierkiewicz | 51509ee | 2008-10-10 22:39:34 +0200 | [diff] [blame] | 25 | /* |
| 26 | * Check whether we can support a device, |
| 27 | * based on the ATAPI IDENTIFY command results. |
| 28 | */ |
| 29 | int ide_check_atapi_device(ide_drive_t *drive, const char *s) |
| 30 | { |
| 31 | u16 *id = drive->id; |
| 32 | u8 gcw[2], protocol, device_type, removable, drq_type, packet_size; |
| 33 | |
| 34 | *((u16 *)&gcw) = id[ATA_ID_CONFIG]; |
| 35 | |
| 36 | protocol = (gcw[1] & 0xC0) >> 6; |
| 37 | device_type = gcw[1] & 0x1F; |
| 38 | removable = (gcw[0] & 0x80) >> 7; |
| 39 | drq_type = (gcw[0] & 0x60) >> 5; |
| 40 | packet_size = gcw[0] & 0x03; |
| 41 | |
| 42 | #ifdef CONFIG_PPC |
| 43 | /* kludge for Apple PowerBook internal zip */ |
| 44 | if (drive->media == ide_floppy && device_type == 5 && |
| 45 | !strstr((char *)&id[ATA_ID_PROD], "CD-ROM") && |
| 46 | strstr((char *)&id[ATA_ID_PROD], "ZIP")) |
| 47 | device_type = 0; |
| 48 | #endif |
| 49 | |
| 50 | if (protocol != 2) |
| 51 | printk(KERN_ERR "%s: %s: protocol (0x%02x) is not ATAPI\n", |
| 52 | s, drive->name, protocol); |
| 53 | else if ((drive->media == ide_floppy && device_type != 0) || |
| 54 | (drive->media == ide_tape && device_type != 1)) |
| 55 | printk(KERN_ERR "%s: %s: invalid device type (0x%02x)\n", |
| 56 | s, drive->name, device_type); |
| 57 | else if (removable == 0) |
| 58 | printk(KERN_ERR "%s: %s: the removable flag is not set\n", |
| 59 | s, drive->name); |
| 60 | else if (drive->media == ide_floppy && drq_type == 3) |
| 61 | printk(KERN_ERR "%s: %s: sorry, DRQ type (0x%02x) not " |
| 62 | "supported\n", s, drive->name, drq_type); |
| 63 | else if (packet_size != 0) |
| 64 | printk(KERN_ERR "%s: %s: packet size (0x%02x) is not 12 " |
| 65 | "bytes\n", s, drive->name, packet_size); |
| 66 | else |
| 67 | return 1; |
| 68 | return 0; |
| 69 | } |
| 70 | EXPORT_SYMBOL_GPL(ide_check_atapi_device); |
| 71 | |
Bartlomiej Zolnierkiewicz | acaa0f5 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 72 | /* PIO data transfer routine using the scatter gather table. */ |
| 73 | int ide_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc, |
| 74 | unsigned int bcount, int write) |
| 75 | { |
| 76 | ide_hwif_t *hwif = drive->hwif; |
| 77 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; |
| 78 | xfer_func_t *xf = write ? tp_ops->output_data : tp_ops->input_data; |
| 79 | struct scatterlist *sg = pc->sg; |
| 80 | char *buf; |
| 81 | int count, done = 0; |
| 82 | |
| 83 | while (bcount) { |
| 84 | count = min(sg->length - pc->b_count, bcount); |
| 85 | |
| 86 | if (PageHighMem(sg_page(sg))) { |
| 87 | unsigned long flags; |
| 88 | |
| 89 | local_irq_save(flags); |
| 90 | buf = kmap_atomic(sg_page(sg), KM_IRQ0) + sg->offset; |
| 91 | xf(drive, NULL, buf + pc->b_count, count); |
| 92 | kunmap_atomic(buf - sg->offset, KM_IRQ0); |
| 93 | local_irq_restore(flags); |
| 94 | } else { |
| 95 | buf = sg_virt(sg); |
| 96 | xf(drive, NULL, buf + pc->b_count, count); |
| 97 | } |
| 98 | |
| 99 | bcount -= count; |
| 100 | pc->b_count += count; |
| 101 | done += count; |
| 102 | |
| 103 | if (pc->b_count == sg->length) { |
| 104 | if (!--pc->sg_cnt) |
| 105 | break; |
| 106 | pc->sg = sg = sg_next(sg); |
| 107 | pc->b_count = 0; |
| 108 | } |
| 109 | } |
| 110 | |
| 111 | if (bcount) { |
| 112 | printk(KERN_ERR "%s: %d leftover bytes, %s\n", drive->name, |
| 113 | bcount, write ? "padding with zeros" |
| 114 | : "discarding data"); |
| 115 | ide_pad_transfer(drive, write, bcount); |
| 116 | } |
| 117 | |
| 118 | return done; |
| 119 | } |
| 120 | EXPORT_SYMBOL_GPL(ide_io_buffers); |
| 121 | |
Bartlomiej Zolnierkiewicz | 7bf7420 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 122 | void ide_init_pc(struct ide_atapi_pc *pc) |
| 123 | { |
| 124 | memset(pc, 0, sizeof(*pc)); |
| 125 | pc->buf = pc->pc_buf; |
| 126 | pc->buf_size = IDE_PC_BUFFER_SIZE; |
| 127 | } |
| 128 | EXPORT_SYMBOL_GPL(ide_init_pc); |
| 129 | |
Bartlomiej Zolnierkiewicz | 7645c15 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 130 | /* |
| 131 | * Generate a new packet command request in front of the request queue, before |
| 132 | * the current request, so that it will be processed immediately, on the next |
| 133 | * pass through the driver. |
| 134 | */ |
Bartlomiej Zolnierkiewicz | 6b0da28 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 135 | static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk, |
| 136 | struct ide_atapi_pc *pc, struct request *rq) |
Bartlomiej Zolnierkiewicz | 7645c15 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 137 | { |
| 138 | blk_rq_init(NULL, rq); |
| 139 | rq->cmd_type = REQ_TYPE_SPECIAL; |
| 140 | rq->cmd_flags |= REQ_PREEMPT; |
| 141 | rq->buffer = (char *)pc; |
| 142 | rq->rq_disk = disk; |
Borislav Petkov | 3eb76c1 | 2009-03-13 21:16:12 +0100 | [diff] [blame] | 143 | |
| 144 | if (pc->req_xfer) { |
| 145 | rq->data = pc->buf; |
| 146 | rq->data_len = pc->req_xfer; |
| 147 | } |
| 148 | |
Bartlomiej Zolnierkiewicz | 7645c15 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 149 | memcpy(rq->cmd, pc->c, 12); |
| 150 | if (drive->media == ide_tape) |
| 151 | rq->cmd[13] = REQ_IDETAPE_PC1; |
| 152 | ide_do_drive_cmd(drive, rq); |
| 153 | } |
Bartlomiej Zolnierkiewicz | 7645c15 | 2008-10-10 22:39:37 +0200 | [diff] [blame] | 154 | |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 155 | /* |
| 156 | * Add a special packet command request to the tail of the request queue, |
| 157 | * and wait for it to be serviced. |
| 158 | */ |
| 159 | int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk, |
| 160 | struct ide_atapi_pc *pc) |
| 161 | { |
| 162 | struct request *rq; |
| 163 | int error; |
| 164 | |
| 165 | rq = blk_get_request(drive->queue, READ, __GFP_WAIT); |
| 166 | rq->cmd_type = REQ_TYPE_SPECIAL; |
| 167 | rq->buffer = (char *)pc; |
Borislav Petkov | 3eb76c1 | 2009-03-13 21:16:12 +0100 | [diff] [blame] | 168 | |
| 169 | if (pc->req_xfer) { |
| 170 | rq->data = pc->buf; |
| 171 | rq->data_len = pc->req_xfer; |
| 172 | } |
| 173 | |
Bartlomiej Zolnierkiewicz | 2ac07d9 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 174 | memcpy(rq->cmd, pc->c, 12); |
| 175 | if (drive->media == ide_tape) |
| 176 | rq->cmd[13] = REQ_IDETAPE_PC1; |
| 177 | error = blk_execute_rq(drive->queue, disk, rq, 0); |
| 178 | blk_put_request(rq); |
| 179 | |
| 180 | return error; |
| 181 | } |
| 182 | EXPORT_SYMBOL_GPL(ide_queue_pc_tail); |
| 183 | |
Bartlomiej Zolnierkiewicz | de699ad | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 184 | int ide_do_test_unit_ready(ide_drive_t *drive, struct gendisk *disk) |
| 185 | { |
| 186 | struct ide_atapi_pc pc; |
| 187 | |
| 188 | ide_init_pc(&pc); |
| 189 | pc.c[0] = TEST_UNIT_READY; |
| 190 | |
| 191 | return ide_queue_pc_tail(drive, disk, &pc); |
| 192 | } |
| 193 | EXPORT_SYMBOL_GPL(ide_do_test_unit_ready); |
| 194 | |
Bartlomiej Zolnierkiewicz | 0c8a6c7 | 2008-10-10 22:39:39 +0200 | [diff] [blame] | 195 | int ide_do_start_stop(ide_drive_t *drive, struct gendisk *disk, int start) |
| 196 | { |
| 197 | struct ide_atapi_pc pc; |
| 198 | |
| 199 | ide_init_pc(&pc); |
| 200 | pc.c[0] = START_STOP; |
| 201 | pc.c[4] = start; |
| 202 | |
| 203 | if (drive->media == ide_tape) |
| 204 | pc.flags |= PC_FLAG_WAIT_FOR_DSC; |
| 205 | |
| 206 | return ide_queue_pc_tail(drive, disk, &pc); |
| 207 | } |
| 208 | EXPORT_SYMBOL_GPL(ide_do_start_stop); |
| 209 | |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 210 | int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on) |
| 211 | { |
| 212 | struct ide_atapi_pc pc; |
| 213 | |
Bartlomiej Zolnierkiewicz | 42619d3 | 2008-10-17 18:09:11 +0200 | [diff] [blame] | 214 | if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0) |
Bartlomiej Zolnierkiewicz | 0578042 | 2008-10-10 22:39:38 +0200 | [diff] [blame] | 215 | return 0; |
| 216 | |
| 217 | ide_init_pc(&pc); |
| 218 | pc.c[0] = ALLOW_MEDIUM_REMOVAL; |
| 219 | pc.c[4] = on; |
| 220 | |
| 221 | return ide_queue_pc_tail(drive, disk, &pc); |
| 222 | } |
| 223 | EXPORT_SYMBOL_GPL(ide_set_media_lock); |
| 224 | |
Bartlomiej Zolnierkiewicz | 6b0da28 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 225 | void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc) |
| 226 | { |
| 227 | ide_init_pc(pc); |
| 228 | pc->c[0] = REQUEST_SENSE; |
| 229 | if (drive->media == ide_floppy) { |
| 230 | pc->c[4] = 255; |
| 231 | pc->req_xfer = 18; |
| 232 | } else { |
| 233 | pc->c[4] = 20; |
| 234 | pc->req_xfer = 20; |
| 235 | } |
| 236 | } |
| 237 | EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd); |
| 238 | |
| 239 | /* |
| 240 | * Called when an error was detected during the last packet command. |
| 241 | * We queue a request sense packet command in the head of the request list. |
| 242 | */ |
| 243 | void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk) |
| 244 | { |
| 245 | struct request *rq = &drive->request_sense_rq; |
| 246 | struct ide_atapi_pc *pc = &drive->request_sense_pc; |
| 247 | |
| 248 | (void)ide_read_error(drive); |
| 249 | ide_create_request_sense_cmd(drive, pc); |
| 250 | if (drive->media == ide_tape) |
| 251 | set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags); |
| 252 | ide_queue_pc_head(drive, disk, pc, rq); |
| 253 | } |
| 254 | EXPORT_SYMBOL_GPL(ide_retry_pc); |
| 255 | |
Borislav Petkov | 4cad085 | 2009-01-02 16:12:53 +0100 | [diff] [blame] | 256 | int ide_cd_expiry(ide_drive_t *drive) |
| 257 | { |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 258 | struct request *rq = drive->hwif->rq; |
Borislav Petkov | 4cad085 | 2009-01-02 16:12:53 +0100 | [diff] [blame] | 259 | unsigned long wait = 0; |
| 260 | |
| 261 | debug_log("%s: rq->cmd[0]: 0x%x\n", __func__, rq->cmd[0]); |
| 262 | |
| 263 | /* |
| 264 | * Some commands are *slow* and normally take a long time to complete. |
| 265 | * Usually we can use the ATAPI "disconnect" to bypass this, but not all |
| 266 | * commands/drives support that. Let ide_timer_expiry keep polling us |
| 267 | * for these. |
| 268 | */ |
| 269 | switch (rq->cmd[0]) { |
| 270 | case GPCMD_BLANK: |
| 271 | case GPCMD_FORMAT_UNIT: |
| 272 | case GPCMD_RESERVE_RZONE_TRACK: |
| 273 | case GPCMD_CLOSE_TRACK: |
| 274 | case GPCMD_FLUSH_CACHE: |
| 275 | wait = ATAPI_WAIT_PC; |
| 276 | break; |
| 277 | default: |
| 278 | if (!(rq->cmd_flags & REQ_QUIET)) |
| 279 | printk(KERN_INFO "cmd 0x%x timed out\n", |
| 280 | rq->cmd[0]); |
| 281 | wait = 0; |
| 282 | break; |
| 283 | } |
| 284 | return wait; |
| 285 | } |
| 286 | EXPORT_SYMBOL_GPL(ide_cd_expiry); |
| 287 | |
Borislav Petkov | 392de1d | 2009-01-02 16:12:52 +0100 | [diff] [blame] | 288 | int ide_cd_get_xferlen(struct request *rq) |
| 289 | { |
| 290 | if (blk_fs_request(rq)) |
| 291 | return 32768; |
| 292 | else if (blk_sense_request(rq) || blk_pc_request(rq) || |
| 293 | rq->cmd_type == REQ_TYPE_ATA_PC) |
| 294 | return rq->data_len; |
| 295 | else |
| 296 | return 0; |
| 297 | } |
| 298 | EXPORT_SYMBOL_GPL(ide_cd_get_xferlen); |
| 299 | |
Bartlomiej Zolnierkiewicz | aa5d2de7 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 300 | /* |
| 301 | * This is the usual interrupt handler which will be called during a packet |
| 302 | * command. We will transfer some of the data (as requested by the drive) |
| 303 | * and will re-point interrupt handler to us. |
| 304 | */ |
| 305 | static ide_startstop_t ide_pc_intr(ide_drive_t *drive) |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 306 | { |
Bartlomiej Zolnierkiewicz | 2b9efba | 2008-10-13 21:39:31 +0200 | [diff] [blame] | 307 | struct ide_atapi_pc *pc = drive->pc; |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 308 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 309 | struct request *rq = hwif->rq; |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 310 | const struct ide_tp_ops *tp_ops = hwif->tp_ops; |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 311 | xfer_func_t *xferfunc; |
Bartlomiej Zolnierkiewicz | 844b946 | 2008-10-13 21:39:31 +0200 | [diff] [blame] | 312 | unsigned int timeout, temp; |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 313 | u16 bcount; |
Borislav Petkov | 5d655a0 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 314 | u8 stat, ireason, dsc = 0; |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 315 | |
| 316 | debug_log("Enter %s - interrupt handler\n", __func__); |
| 317 | |
Borislav Petkov | 5d655a0 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 318 | timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD |
| 319 | : WAIT_TAPE_CMD; |
Bartlomiej Zolnierkiewicz | 844b946 | 2008-10-13 21:39:31 +0200 | [diff] [blame] | 320 | |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 321 | if (pc->flags & PC_FLAG_TIMEDOUT) { |
Bartlomiej Zolnierkiewicz | b14c721 | 2008-10-13 21:39:30 +0200 | [diff] [blame] | 322 | drive->pc_callback(drive, 0); |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 323 | return ide_stopped; |
| 324 | } |
| 325 | |
| 326 | /* Clear the interrupt */ |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 327 | stat = tp_ops->read_status(hwif); |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 328 | |
| 329 | if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { |
| 330 | if (hwif->dma_ops->dma_end(drive) || |
Borislav Petkov | 5d655a0 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 331 | (drive->media == ide_tape && (stat & ATA_ERR))) { |
| 332 | if (drive->media == ide_floppy) |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 333 | printk(KERN_ERR "%s: DMA %s error\n", |
| 334 | drive->name, rq_data_dir(pc->rq) |
| 335 | ? "write" : "read"); |
| 336 | pc->flags |= PC_FLAG_DMA_ERROR; |
| 337 | } else { |
| 338 | pc->xferred = pc->req_xfer; |
Bartlomiej Zolnierkiewicz | 85e3903 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 339 | if (drive->pc_update_buffers) |
| 340 | drive->pc_update_buffers(drive, pc); |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 341 | } |
| 342 | debug_log("%s: DMA finished\n", drive->name); |
| 343 | } |
| 344 | |
| 345 | /* No more interrupts */ |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 346 | if ((stat & ATA_DRQ) == 0) { |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 347 | debug_log("Packet command completed, %d bytes transferred\n", |
| 348 | pc->xferred); |
| 349 | |
| 350 | pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; |
| 351 | |
| 352 | local_irq_enable_in_hardirq(); |
| 353 | |
Borislav Petkov | 5d655a0 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 354 | if (drive->media == ide_tape && |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 355 | (stat & ATA_ERR) && rq->cmd[0] == REQUEST_SENSE) |
| 356 | stat &= ~ATA_ERR; |
Borislav Petkov | 8fccf89 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 357 | |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 358 | if ((stat & ATA_ERR) || (pc->flags & PC_FLAG_DMA_ERROR)) { |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 359 | /* Error detected */ |
| 360 | debug_log("%s: I/O error\n", drive->name); |
| 361 | |
Borislav Petkov | 5d655a0 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 362 | if (drive->media != ide_tape) |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 363 | pc->rq->errors++; |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 364 | |
Borislav Petkov | 8fccf89 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 365 | if (rq->cmd[0] == REQUEST_SENSE) { |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 366 | printk(KERN_ERR "%s: I/O error in request sense" |
| 367 | " command\n", drive->name); |
| 368 | return ide_do_reset(drive); |
| 369 | } |
| 370 | |
Borislav Petkov | 8fccf89 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 371 | debug_log("[cmd %x]: check condition\n", rq->cmd[0]); |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 372 | |
| 373 | /* Retry operation */ |
Bartlomiej Zolnierkiewicz | 6b0da28 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 374 | ide_retry_pc(drive, rq->rq_disk); |
Borislav Petkov | 8fccf89 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 375 | |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 376 | /* queued, but not started */ |
| 377 | return ide_stopped; |
| 378 | } |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 379 | pc->error = 0; |
Bartlomiej Zolnierkiewicz | b14c721 | 2008-10-13 21:39:30 +0200 | [diff] [blame] | 380 | |
| 381 | if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0) |
| 382 | dsc = 1; |
Borislav Petkov | 8fccf89 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 383 | |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 384 | /* Command finished - Call the callback function */ |
Bartlomiej Zolnierkiewicz | b14c721 | 2008-10-13 21:39:30 +0200 | [diff] [blame] | 385 | drive->pc_callback(drive, dsc); |
Borislav Petkov | 8fccf89 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 386 | |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 387 | return ide_stopped; |
| 388 | } |
| 389 | |
| 390 | if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) { |
| 391 | pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS; |
| 392 | printk(KERN_ERR "%s: The device wants to issue more interrupts " |
| 393 | "in DMA mode\n", drive->name); |
| 394 | ide_dma_off(drive); |
| 395 | return ide_do_reset(drive); |
| 396 | } |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 397 | |
Bartlomiej Zolnierkiewicz | 1823649 | 2008-07-23 19:55:54 +0200 | [diff] [blame] | 398 | /* Get the number of bytes to transfer on this interrupt. */ |
| 399 | ide_read_bcount_and_ireason(drive, &bcount, &ireason); |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 400 | |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 401 | if (ireason & ATAPI_COD) { |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 402 | printk(KERN_ERR "%s: CoD != 0 in %s\n", drive->name, __func__); |
| 403 | return ide_do_reset(drive); |
| 404 | } |
Borislav Petkov | 8fccf89 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 405 | |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 406 | if (((ireason & ATAPI_IO) == ATAPI_IO) == |
| 407 | !!(pc->flags & PC_FLAG_WRITING)) { |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 408 | /* Hopefully, we will never get here */ |
| 409 | printk(KERN_ERR "%s: We wanted to %s, but the device wants us " |
| 410 | "to %s!\n", drive->name, |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 411 | (ireason & ATAPI_IO) ? "Write" : "Read", |
| 412 | (ireason & ATAPI_IO) ? "Read" : "Write"); |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 413 | return ide_do_reset(drive); |
| 414 | } |
Borislav Petkov | 8fccf89 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 415 | |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 416 | if (!(pc->flags & PC_FLAG_WRITING)) { |
| 417 | /* Reading - Check that we have enough space */ |
| 418 | temp = pc->xferred + bcount; |
| 419 | if (temp > pc->req_xfer) { |
| 420 | if (temp > pc->buf_size) { |
| 421 | printk(KERN_ERR "%s: The device wants to send " |
| 422 | "us more data than expected - " |
| 423 | "discarding data\n", |
| 424 | drive->name); |
Borislav Petkov | 5d655a0 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 425 | |
| 426 | ide_pad_transfer(drive, 0, bcount); |
Bartlomiej Zolnierkiewicz | 844b946 | 2008-10-13 21:39:31 +0200 | [diff] [blame] | 427 | goto next_irq; |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 428 | } |
| 429 | debug_log("The device wants to send us more data than " |
| 430 | "expected - allowing transfer\n"); |
| 431 | } |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 432 | xferfunc = tp_ops->input_data; |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 433 | } else |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 434 | xferfunc = tp_ops->output_data; |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 435 | |
Borislav Petkov | 5d655a0 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 436 | if ((drive->media == ide_floppy && !pc->buf) || |
| 437 | (drive->media == ide_tape && pc->bh)) { |
Bartlomiej Zolnierkiewicz | 85e3903 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 438 | int done = drive->pc_io_buffers(drive, pc, bcount, |
Bartlomiej Zolnierkiewicz | acaa0f5 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 439 | !!(pc->flags & PC_FLAG_WRITING)); |
| 440 | |
| 441 | /* FIXME: don't do partial completions */ |
Borislav Petkov | 5d655a0 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 442 | if (drive->media == ide_floppy) |
Bartlomiej Zolnierkiewicz | acaa0f5 | 2008-10-10 22:39:36 +0200 | [diff] [blame] | 443 | ide_end_request(drive, 1, done >> 9); |
| 444 | } else |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 445 | xferfunc(drive, NULL, pc->cur_pos, bcount); |
| 446 | |
| 447 | /* Update the current position */ |
| 448 | pc->xferred += bcount; |
| 449 | pc->cur_pos += bcount; |
| 450 | |
| 451 | debug_log("[cmd %x] transferred %d bytes on that intr.\n", |
Borislav Petkov | 8fccf89 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 452 | rq->cmd[0], bcount); |
Bartlomiej Zolnierkiewicz | 844b946 | 2008-10-13 21:39:31 +0200 | [diff] [blame] | 453 | next_irq: |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 454 | /* And set the interrupt handler again */ |
Borislav Petkov | 5d655a0 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 455 | ide_set_handler(drive, ide_pc_intr, timeout, NULL); |
Bartlomiej Zolnierkiewicz | 646c0cb | 2008-07-15 21:22:03 +0200 | [diff] [blame] | 456 | return ide_started; |
| 457 | } |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 458 | |
Bartlomiej Zolnierkiewicz | 88a7210 | 2008-07-23 19:55:54 +0200 | [diff] [blame] | 459 | static u8 ide_read_ireason(ide_drive_t *drive) |
| 460 | { |
| 461 | ide_task_t task; |
| 462 | |
| 463 | memset(&task, 0, sizeof(task)); |
| 464 | task.tf_flags = IDE_TFLAG_IN_NSECT; |
| 465 | |
Bartlomiej Zolnierkiewicz | 374e042 | 2008-07-23 19:55:56 +0200 | [diff] [blame] | 466 | drive->hwif->tp_ops->tf_read(drive, &task); |
Bartlomiej Zolnierkiewicz | 88a7210 | 2008-07-23 19:55:54 +0200 | [diff] [blame] | 467 | |
| 468 | return task.tf.nsect & 3; |
| 469 | } |
| 470 | |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 471 | static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason) |
| 472 | { |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 473 | int retries = 100; |
| 474 | |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 475 | while (retries-- && ((ireason & ATAPI_COD) == 0 || |
| 476 | (ireason & ATAPI_IO))) { |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 477 | printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing " |
| 478 | "a packet command, retrying\n", drive->name); |
| 479 | udelay(100); |
Bartlomiej Zolnierkiewicz | 88a7210 | 2008-07-23 19:55:54 +0200 | [diff] [blame] | 480 | ireason = ide_read_ireason(drive); |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 481 | if (retries == 0) { |
| 482 | printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing " |
| 483 | "a packet command, ignoring\n", |
| 484 | drive->name); |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 485 | ireason |= ATAPI_COD; |
| 486 | ireason &= ~ATAPI_IO; |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 487 | } |
| 488 | } |
| 489 | |
| 490 | return ireason; |
| 491 | } |
| 492 | |
Bartlomiej Zolnierkiewicz | baf08f0 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 493 | static int ide_delayed_transfer_pc(ide_drive_t *drive) |
| 494 | { |
| 495 | /* Send the actual packet */ |
| 496 | drive->hwif->tp_ops->output_data(drive, NULL, drive->pc->c, 12); |
| 497 | |
| 498 | /* Timeout for the packet command */ |
| 499 | return WAIT_FLOPPY_CMD; |
| 500 | } |
| 501 | |
| 502 | static ide_startstop_t ide_transfer_pc(ide_drive_t *drive) |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 503 | { |
Borislav Petkov | b16aabc | 2009-01-02 16:12:56 +0100 | [diff] [blame] | 504 | struct ide_atapi_pc *uninitialized_var(pc); |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 505 | ide_hwif_t *hwif = drive->hwif; |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 506 | struct request *rq = hwif->rq; |
Bartlomiej Zolnierkiewicz | baf08f0 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 507 | ide_expiry_t *expiry; |
| 508 | unsigned int timeout; |
Borislav Petkov | 8c66285 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 509 | int cmd_len; |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 510 | ide_startstop_t startstop; |
| 511 | u8 ireason; |
| 512 | |
Bartlomiej Zolnierkiewicz | 3a7d248 | 2008-10-10 22:39:21 +0200 | [diff] [blame] | 513 | if (ide_wait_stat(&startstop, drive, ATA_DRQ, ATA_BUSY, WAIT_READY)) { |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 514 | printk(KERN_ERR "%s: Strange, packet command initiated yet " |
| 515 | "DRQ isn't asserted\n", drive->name); |
| 516 | return startstop; |
| 517 | } |
| 518 | |
Borislav Petkov | 5f25843 | 2009-01-02 16:12:53 +0100 | [diff] [blame] | 519 | if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { |
| 520 | if (drive->dma) |
| 521 | drive->waiting_for_dma = 1; |
| 522 | } |
| 523 | |
Borislav Petkov | 8c66285 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 524 | if (dev_is_idecd(drive)) { |
| 525 | /* ATAPI commands get padded out to 12 bytes minimum */ |
| 526 | cmd_len = COMMAND_SIZE(rq->cmd[0]); |
| 527 | if (cmd_len < ATAPI_MIN_CDB_BYTES) |
| 528 | cmd_len = ATAPI_MIN_CDB_BYTES; |
Borislav Petkov | def860d | 2009-01-02 16:12:55 +0100 | [diff] [blame] | 529 | |
| 530 | timeout = rq->timeout; |
| 531 | expiry = ide_cd_expiry; |
| 532 | } else { |
Borislav Petkov | b16aabc | 2009-01-02 16:12:56 +0100 | [diff] [blame] | 533 | pc = drive->pc; |
| 534 | |
Borislav Petkov | 8c66285 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 535 | cmd_len = ATAPI_MIN_CDB_BYTES; |
| 536 | |
Borislav Petkov | def860d | 2009-01-02 16:12:55 +0100 | [diff] [blame] | 537 | /* |
| 538 | * If necessary schedule the packet transfer to occur 'timeout' |
| 539 | * miliseconds later in ide_delayed_transfer_pc() after the |
| 540 | * device says it's ready for a packet. |
| 541 | */ |
| 542 | if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) { |
| 543 | timeout = drive->pc_delay; |
| 544 | expiry = &ide_delayed_transfer_pc; |
| 545 | } else { |
| 546 | timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD |
| 547 | : WAIT_TAPE_CMD; |
| 548 | expiry = NULL; |
| 549 | } |
Borislav Petkov | 06cc277 | 2009-01-02 16:12:56 +0100 | [diff] [blame] | 550 | |
| 551 | ireason = ide_read_ireason(drive); |
| 552 | if (drive->media == ide_tape) |
| 553 | ireason = ide_wait_ireason(drive, ireason); |
| 554 | |
| 555 | if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) { |
| 556 | printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing " |
| 557 | "a packet command\n", drive->name); |
| 558 | |
| 559 | return ide_do_reset(drive); |
| 560 | } |
Bartlomiej Zolnierkiewicz | baf08f0 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 561 | } |
| 562 | |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 563 | /* Set the interrupt routine */ |
Borislav Petkov | d6251d4 | 2009-01-06 17:20:58 +0100 | [diff] [blame] | 564 | ide_set_handler(drive, |
| 565 | (dev_is_idecd(drive) ? drive->irq_handler |
| 566 | : ide_pc_intr), |
| 567 | timeout, expiry); |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 568 | |
| 569 | /* Begin DMA, if necessary */ |
Borislav Petkov | b16aabc | 2009-01-02 16:12:56 +0100 | [diff] [blame] | 570 | if (dev_is_idecd(drive)) { |
| 571 | if (drive->dma) |
| 572 | hwif->dma_ops->dma_start(drive); |
| 573 | } else { |
| 574 | if (pc->flags & PC_FLAG_DMA_OK) { |
| 575 | pc->flags |= PC_FLAG_DMA_IN_PROGRESS; |
| 576 | hwif->dma_ops->dma_start(drive); |
| 577 | } |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | /* Send the actual packet */ |
Borislav Petkov | ea68d27 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 581 | if ((drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) == 0) |
Borislav Petkov | 8c66285 | 2009-01-02 16:12:54 +0100 | [diff] [blame] | 582 | hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len); |
Bartlomiej Zolnierkiewicz | 594c16d | 2008-07-15 21:21:58 +0200 | [diff] [blame] | 583 | |
| 584 | return ide_started; |
| 585 | } |
Bartlomiej Zolnierkiewicz | 6bf1641 | 2008-07-15 21:22:00 +0200 | [diff] [blame] | 586 | |
Borislav Petkov | 28ad91d | 2009-01-02 16:12:56 +0100 | [diff] [blame] | 587 | ide_startstop_t ide_issue_pc(ide_drive_t *drive) |
Bartlomiej Zolnierkiewicz | 6bf1641 | 2008-07-15 21:22:00 +0200 | [diff] [blame] | 588 | { |
Borislav Petkov | d77612a | 2009-01-02 16:12:55 +0100 | [diff] [blame] | 589 | struct ide_atapi_pc *pc; |
Bartlomiej Zolnierkiewicz | 6bf1641 | 2008-07-15 21:22:00 +0200 | [diff] [blame] | 590 | ide_hwif_t *hwif = drive->hwif; |
Borislav Petkov | 4cad085 | 2009-01-02 16:12:53 +0100 | [diff] [blame] | 591 | ide_expiry_t *expiry = NULL; |
Borislav Petkov | 28ad91d | 2009-01-02 16:12:56 +0100 | [diff] [blame] | 592 | unsigned int timeout; |
Borislav Petkov | f9476b9 | 2008-10-13 21:39:50 +0200 | [diff] [blame] | 593 | u32 tf_flags; |
Borislav Petkov | 392de1d | 2009-01-02 16:12:52 +0100 | [diff] [blame] | 594 | u16 bcount; |
Bartlomiej Zolnierkiewicz | 6bf1641 | 2008-07-15 21:22:00 +0200 | [diff] [blame] | 595 | |
Borislav Petkov | ed48554 | 2009-01-02 16:12:52 +0100 | [diff] [blame] | 596 | if (dev_is_idecd(drive)) { |
| 597 | tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL; |
Bartlomiej Zolnierkiewicz | b65fac3 | 2009-01-06 17:20:50 +0100 | [diff] [blame] | 598 | bcount = ide_cd_get_xferlen(hwif->rq); |
Borislav Petkov | 4cad085 | 2009-01-02 16:12:53 +0100 | [diff] [blame] | 599 | expiry = ide_cd_expiry; |
Borislav Petkov | 28ad91d | 2009-01-02 16:12:56 +0100 | [diff] [blame] | 600 | timeout = ATAPI_WAIT_PC; |
Borislav Petkov | d77612a | 2009-01-02 16:12:55 +0100 | [diff] [blame] | 601 | |
| 602 | if (drive->dma) |
| 603 | drive->dma = !hwif->dma_ops->dma_setup(drive); |
Borislav Petkov | ed48554 | 2009-01-02 16:12:52 +0100 | [diff] [blame] | 604 | } else { |
Borislav Petkov | d77612a | 2009-01-02 16:12:55 +0100 | [diff] [blame] | 605 | pc = drive->pc; |
| 606 | |
| 607 | /* We haven't transferred any data yet */ |
| 608 | pc->xferred = 0; |
| 609 | pc->cur_pos = pc->buf; |
| 610 | |
Borislav Petkov | ed48554 | 2009-01-02 16:12:52 +0100 | [diff] [blame] | 611 | tf_flags = IDE_TFLAG_OUT_DEVICE; |
| 612 | bcount = ((drive->media == ide_tape) ? |
| 613 | pc->req_xfer : |
| 614 | min(pc->req_xfer, 63 * 1024)); |
Borislav Petkov | d77612a | 2009-01-02 16:12:55 +0100 | [diff] [blame] | 615 | |
| 616 | if (pc->flags & PC_FLAG_DMA_ERROR) { |
| 617 | pc->flags &= ~PC_FLAG_DMA_ERROR; |
| 618 | ide_dma_off(drive); |
| 619 | } |
| 620 | |
| 621 | if ((pc->flags & PC_FLAG_DMA_OK) && |
| 622 | (drive->dev_flags & IDE_DFLAG_USING_DMA)) |
| 623 | drive->dma = !hwif->dma_ops->dma_setup(drive); |
| 624 | |
| 625 | if (!drive->dma) |
| 626 | pc->flags &= ~PC_FLAG_DMA_OK; |
Borislav Petkov | 28ad91d | 2009-01-02 16:12:56 +0100 | [diff] [blame] | 627 | |
| 628 | timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD |
| 629 | : WAIT_TAPE_CMD; |
Borislav Petkov | ed48554 | 2009-01-02 16:12:52 +0100 | [diff] [blame] | 630 | } |
Bartlomiej Zolnierkiewicz | 6bf1641 | 2008-07-15 21:22:00 +0200 | [diff] [blame] | 631 | |
Borislav Petkov | f9476b9 | 2008-10-13 21:39:50 +0200 | [diff] [blame] | 632 | ide_pktcmd_tf_load(drive, tf_flags, bcount, drive->dma); |
Bartlomiej Zolnierkiewicz | 6bf1641 | 2008-07-15 21:22:00 +0200 | [diff] [blame] | 633 | |
| 634 | /* Issue the packet command */ |
Borislav Petkov | ac77ef8 | 2008-07-23 19:56:01 +0200 | [diff] [blame] | 635 | if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) { |
Borislav Petkov | 5f25843 | 2009-01-02 16:12:53 +0100 | [diff] [blame] | 636 | if (drive->dma) |
| 637 | drive->waiting_for_dma = 0; |
Bartlomiej Zolnierkiewicz | baf08f0 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 638 | ide_execute_command(drive, ATA_CMD_PACKET, ide_transfer_pc, |
Borislav Petkov | 4cad085 | 2009-01-02 16:12:53 +0100 | [diff] [blame] | 639 | timeout, expiry); |
Bartlomiej Zolnierkiewicz | 6bf1641 | 2008-07-15 21:22:00 +0200 | [diff] [blame] | 640 | return ide_started; |
| 641 | } else { |
| 642 | ide_execute_pkt_cmd(drive); |
Bartlomiej Zolnierkiewicz | baf08f0 | 2008-10-13 21:39:32 +0200 | [diff] [blame] | 643 | return ide_transfer_pc(drive); |
Bartlomiej Zolnierkiewicz | 6bf1641 | 2008-07-15 21:22:00 +0200 | [diff] [blame] | 644 | } |
| 645 | } |
| 646 | EXPORT_SYMBOL_GPL(ide_issue_pc); |