5 #include <linux/kernel.h>
6 #include <linux/cdrom.h>
8 #include <linux/export.h>
13 #include <scsi/scsi.h>
15 #define DRV_NAME "ide-atapi"
16 #define PFX DRV_NAME ": "
19 #define debug_log(fmt, args...) \
20 printk(KERN_INFO "ide: " fmt, ## args)
22 #define debug_log(fmt, args...) do {} while (0)
25 #define ATAPI_MIN_CDB_BYTES 12
43 protocol = (gcw[1] & 0xC0) >> 6;
44 device_type = gcw[1] & 0x1F;
45 removable = (gcw[0] & 0x80) >> 7;
46 drq_type = (gcw[0] & 0x60) >> 5;
47 packet_size = gcw[0] & 0x03;
59 s, drive->
name, protocol);
63 s, drive->
name, device_type);
64 else if (removable == 0)
69 "supported\n", s, drive->
name, drq_type);
70 else if (packet_size != 0)
72 "bytes\n", s, drive->
name, packet_size);
81 memset(pc, 0,
sizeof(*pc));
96 rq->cmd_type = REQ_TYPE_SPECIAL;
97 rq->special = (
char *)pc;
178 switch (drive->
media) {
192 BUG_ON(sense_len >
sizeof(*sense));
197 memset(sense, 0,
sizeof(*sense));
204 if (printk_ratelimit())
206 "buffer\n", drive->
name);
210 sense_rq->rq_disk = rq->rq_disk;
213 sense_rq->cmd_type = REQ_TYPE_SENSE;
257 memcpy(pc->
c, sense_rq->cmd, 12);
279 unsigned long wait = 0;
281 debug_log(
"%s: rq->cmd[0]: 0x%x\n", __func__, rq->cmd[0]);
289 switch (rq->cmd[0]) {
310 switch (rq->cmd_type) {
314 case REQ_TYPE_BLOCK_PC:
315 case REQ_TYPE_ATA_PC:
316 return blk_rq_bytes(rq);
331 *ireason = tf.
nsect & 3;
348 debug_log(
"ireason: 0x%x, rw: 0x%x\n", ireason, rw);
350 if (ireason == (!rw << 1))
352 else if (ireason == (rw << 1)) {
354 drive->
name, __func__);
356 if (dev_is_idecd(drive))
358 }
else if (!rw && ireason ==
ATAPI_COD) {
359 if (dev_is_idecd(drive)) {
374 drive->
name, __func__, ireason);
377 if (dev_is_idecd(drive) && rq->cmd_type == REQ_TYPE_ATA_PC)
398 u8 stat, ireason, dsc = 0;
401 debug_log(
"Enter %s - interrupt handler\n", __func__);
413 rc = hwif->
dma_ops->dma_end(drive);
419 drive->
name, rq_data_dir(pc->
rq)
431 debug_log(
"Packet command completed, %d bytes transferred\n",
451 "sense command\n", drive->
name);
455 debug_log(
"[cmd %x]: check condition\n", rq->cmd[0]);
472 done = blk_rq_bytes(rq);
480 if (rq->cmd_type == REQ_TYPE_SPECIAL) {
485 if (rq->cmd_type != REQ_TYPE_FS && uptodate <= 0) {
490 error = uptodate ? 0 : -
EIO;
500 "interrupts in DMA mode\n", drive->
name);
511 done =
min_t(
unsigned int, bcount, cmd->
nleft);
515 rq->resid_len -=
done;
522 debug_log(
"[cmd %x] transferred %d bytes, padded %d bytes, resid: %u\n",
523 rq->cmd[0], done, bcount, rq->resid_len);
530 static void ide_init_packet_cmd(
struct ide_cmd *cmd,
u8 valid_tf,
537 cmd->
tf.feature =
dma;
538 cmd->
tf.lbam = bcount & 0xff;
539 cmd->
tf.lbah = (bcount >> 8) & 0xff;
555 while (retries-- && ((ireason &
ATAPI_COD) == 0 ||
558 "a packet command, retrying\n", drive->
name);
560 ireason = ide_read_ireason(drive);
563 " a packet command, ignoring\n",
566 ireason &= ~ATAPI_IO;
573 static int ide_delayed_transfer_pc(
ide_drive_t *drive)
576 drive->
hwif->tp_ops->output_data(drive,
NULL, drive->
pc->c, 12);
588 unsigned int timeout;
595 "DRQ isn't asserted\n", drive->
name);
604 if (dev_is_idecd(drive)) {
610 timeout = rq->timeout;
624 expiry = &ide_delayed_transfer_pc;
631 ireason = ide_read_ireason(drive);
633 ireason = ide_wait_ireason(drive, ireason);
635 if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
637 "issuing a packet command\n", drive->
name);
653 hwif->
tp_ops->output_data(drive,
NULL, rq->cmd, cmd_len);
656 if (dev_is_idecd(drive)) {
658 hwif->
dma_ops->dma_start(drive);
662 hwif->
dma_ops->dma_start(drive);
675 unsigned int timeout,
bytes;
680 if (dev_is_idecd(drive)) {
692 bytes = blk_rq_bytes(rq);
694 :
min_t(
unsigned int,
715 ide_init_packet_cmd(cmd, valid_tf, bcount, drive->
dma);
727 return drq_int ?
ide_started : ide_transfer_pc(drive);