27 #include <linux/module.h>
28 #include <linux/types.h>
29 #include <linux/string.h>
30 #include <linux/kernel.h>
35 #include <linux/errno.h>
38 #include <linux/slab.h>
40 #include <linux/pci.h>
44 #include <linux/reboot.h>
45 #include <linux/cdrom.h>
47 #include <linux/device.h>
50 #include <linux/bitops.h>
52 #include <asm/byteorder.h>
54 #include <asm/uaccess.h>
58 unsigned int nr_bytes)
89 cmd->
tf.data = data[0];
90 cmd->
hob.data = data[1];
97 if (tf->
lbal != 0xc4) {
105 if (rq && rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
106 struct ide_cmd *orig_cmd = rq->special;
111 memcpy(orig_cmd, cmd,
sizeof(*cmd));
125 if (blk_noretry_request(rq) && error <= 0)
126 nr_bytes = blk_rq_sectors(rq) << 9;
138 u8 drv_req = (rq->cmd_type == REQ_TYPE_SPECIAL) && rq->rq_disk;
148 else if (rq->cmd_type != REQ_TYPE_FS && rq->errors == 0)
204 ide_tf_set_specify_cmd(drive, &
cmd.tf);
207 ide_tf_set_restore_cmd(drive, &
cmd.tf);
210 ide_tf_set_setmult_cmd(drive, &
cmd.tf);
272 printk(
"%s: DRIVE_CMD (null)\n", drive->
name);
313 printk(
"%s: start_request: current=0x%08lx\n",
314 drive->
hwif->name, (
unsigned long) rq);
323 if (blk_pm_request(rq))
326 drive->
hwif->tp_ops->dev_select(drive);
343 if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE)
344 return execute_drive_cmd(drive, rq);
345 else if (blk_pm_request(rq)) {
346 struct request_pm_state *
pm = rq->special;
348 printk(
"%s: start_power_step(step: %d)\n",
349 drive->
name, pm->pm_step);
356 }
else if (!rq->rq_disk && rq->cmd_type == REQ_TYPE_SPECIAL)
365 return ide_special_rq(drive, rq);
367 drv = *(
struct ide_driver **)rq->rq_disk->private_data;
369 return drv->
do_request(drive, rq, blk_rq_pos(rq));
371 return do_special(drive);
395 static inline int ide_lock_port(
ide_hwif_t *hwif)
405 static inline void ide_unlock_port(
ide_hwif_t *hwif)
424 static inline void ide_unlock_host(
struct ide_host *host)
449 __ide_requeue_and_plug(q, rq);
450 spin_unlock_irqrestore(q->queue_lock, flags);
463 unsigned long queue_run_ms = 3;
465 spin_unlock_irq(q->queue_lock);
470 if (ide_lock_host(host, hwif))
473 spin_lock_irq(&hwif->
lock);
475 if (!ide_lock_port(hwif)) {
480 prev_port = hwif->
host->cur_port;
486 ide_unlock_port(hwif);
501 prev_port->
tp_ops->write_devctl(prev_port,
505 hwif->
host->cur_port = hwif;
510 spin_unlock_irq(&hwif->
lock);
511 spin_lock_irq(q->queue_lock);
519 spin_unlock_irq(q->queue_lock);
520 spin_lock_irq(&hwif->
lock);
523 ide_unlock_port(hwif);
541 blk_pm_request(rq) == 0 &&
544 ide_unlock_port(hwif);
550 spin_unlock_irq(&hwif->
lock);
551 startstop = start_request(drive, rq);
552 spin_lock_irq(&hwif->
lock);
562 spin_unlock_irq(&hwif->
lock);
564 ide_unlock_host(host);
565 spin_lock_irq(q->queue_lock);
569 spin_unlock_irq(&hwif->
lock);
570 ide_unlock_host(host);
572 spin_lock_irq(q->queue_lock);
573 __ide_requeue_and_plug(q, rq);
582 return hwif->
dma_ops->dma_test_irq(drive);
586 stat = hwif->
tp_ops->read_altstatus(hwif);
589 stat = hwif->
tp_ops->read_status(hwif);
641 wait = expiry(drive);
647 spin_unlock_irqrestore(&hwif->
lock, flags);
658 spin_unlock(&hwif->
lock);
664 startstop = handler(drive);
665 }
else if (drive_is_ready(drive)) {
667 hwif->
dma_ops->dma_lost_irq(drive);
673 startstop = handler(drive);
678 startstop =
ide_error(drive,
"irq timeout",
679 hwif->
tp_ops->read_status(hwif));
681 spin_lock_irq(&hwif->
lock);
684 rq_in_flight = hwif->
rq;
686 ide_unlock_port(hwif);
690 spin_unlock_irqrestore(&hwif->
lock, flags);
693 ide_unlock_host(hwif->
host);
727 static void unexpected_intr(
int irq,
ide_hwif_t *hwif)
729 u8 stat = hwif->
tp_ops->read_status(hwif);
733 static unsigned long last_msgtime,
count;
739 "status=0x%02x, count=%ld\n",
740 hwif->
name, stat, count);
790 hwif->
port_ops->test_irq(hwif) == 0)
813 unexpected_intr(irq, hwif);
826 if (!drive_is_ready(drive))
840 spin_unlock(&hwif->
lock);
849 startstop = handler(drive);
851 spin_lock_irq(&hwif->
lock);
861 rq_in_flight = hwif->
rq;
863 ide_unlock_port(hwif);
868 spin_unlock_irqrestore(&hwif->
lock, flags);
871 ide_unlock_host(hwif->
host);