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