i2c: tegra: remove support for I2C_M_REV_DIR_ADDR
[linux-2.6.git] / drivers / ide / ide-atapi.c
index afe5a43..6f218e0 100644 (file)
@@ -7,9 +7,13 @@
 #include <linux/delay.h>
 #include <linux/ide.h>
 #include <linux/scatterlist.h>
+#include <linux/gfp.h>
 
 #include <scsi/scsi.h>
 
+#define DRV_NAME "ide-atapi"
+#define PFX DRV_NAME ": "
+
 #ifdef DEBUG
 #define debug_log(fmt, args...) \
        printk(KERN_INFO "ide: " fmt, ## args)
@@ -74,8 +78,6 @@ EXPORT_SYMBOL_GPL(ide_check_atapi_device);
 void ide_init_pc(struct ide_atapi_pc *pc)
 {
        memset(pc, 0, sizeof(*pc));
-       pc->buf = pc->pc_buf;
-       pc->buf_size = IDE_PC_BUFFER_SIZE;
 }
 EXPORT_SYMBOL_GPL(ide_init_pc);
 
@@ -84,7 +86,7 @@ EXPORT_SYMBOL_GPL(ide_init_pc);
  * and wait for it to be serviced.
  */
 int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
-                     struct ide_atapi_pc *pc)
+                     struct ide_atapi_pc *pc, void *buf, unsigned int bufflen)
 {
        struct request *rq;
        int error;
@@ -93,8 +95,8 @@ int ide_queue_pc_tail(ide_drive_t *drive, struct gendisk *disk,
        rq->cmd_type = REQ_TYPE_SPECIAL;
        rq->special = (char *)pc;
 
-       if (pc->req_xfer) {
-               error = blk_rq_map_kern(drive->queue, rq, pc->buf, pc->req_xfer,
+       if (buf && bufflen) {
+               error = blk_rq_map_kern(drive->queue, rq, buf, bufflen,
                                        GFP_NOIO);
                if (error)
                        goto put_req;
@@ -117,7 +119,7 @@ int ide_do_test_unit_ready(ide_drive_t *drive, struct gendisk *disk)
        ide_init_pc(&pc);
        pc.c[0] = TEST_UNIT_READY;
 
-       return ide_queue_pc_tail(drive, disk, &pc);
+       return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
 }
 EXPORT_SYMBOL_GPL(ide_do_test_unit_ready);
 
@@ -132,7 +134,7 @@ int ide_do_start_stop(ide_drive_t *drive, struct gendisk *disk, int start)
        if (drive->media == ide_tape)
                pc.flags |= PC_FLAG_WAIT_FOR_DSC;
 
-       return ide_queue_pc_tail(drive, disk, &pc);
+       return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
 }
 EXPORT_SYMBOL_GPL(ide_do_start_stop);
 
@@ -147,7 +149,7 @@ int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
        pc.c[0] = ALLOW_MEDIUM_REMOVAL;
        pc.c[4] = on;
 
-       return ide_queue_pc_tail(drive, disk, &pc);
+       return ide_queue_pc_tail(drive, disk, &pc, NULL, 0);
 }
 EXPORT_SYMBOL_GPL(ide_set_media_lock);
 
@@ -172,8 +174,6 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq)
        unsigned int cmd_len, sense_len;
        int err;
 
-       debug_log("%s: enter\n", __func__);
-
        switch (drive->media) {
        case ide_floppy:
                cmd_len = 255;
@@ -190,7 +190,7 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq)
 
        BUG_ON(sense_len > sizeof(*sense));
 
-       if (blk_sense_request(rq) || drive->sense_rq_armed)
+       if (rq->cmd_type == REQ_TYPE_SENSE || drive->sense_rq_armed)
                return;
 
        memset(sense, 0, sizeof(*sense));
@@ -201,8 +201,8 @@ void ide_prep_sense(ide_drive_t *drive, struct request *rq)
                              GFP_NOIO);
        if (unlikely(err)) {
                if (printk_ratelimit())
-                       printk(KERN_WARNING "%s: failed to map sense buffer\n",
-                              drive->name);
+                       printk(KERN_WARNING PFX "%s: failed to map sense "
+                                           "buffer\n", drive->name);
                return;
        }
 
@@ -223,7 +223,7 @@ int ide_queue_sense_rq(ide_drive_t *drive, void *special)
 {
        /* deferred failure from ide_prep_sense() */
        if (!drive->sense_rq_armed) {
-               printk(KERN_WARNING "%s: failed queue sense request\n",
+               printk(KERN_WARNING PFX "%s: error queuing a sense request\n",
                       drive->name);
                return -ENOMEM;
        }
@@ -233,8 +233,7 @@ int ide_queue_sense_rq(ide_drive_t *drive, void *special)
 
        drive->hwif->rq = NULL;
 
-       elv_add_request(drive->queue, &drive->sense_rq,
-                       ELEVATOR_INSERT_FRONT, 0);
+       elv_add_request(drive->queue, &drive->sense_rq, ELEVATOR_INSERT_FRONT);
        return 0;
 }
 EXPORT_SYMBOL_GPL(ide_queue_sense_rq);
@@ -246,6 +245,7 @@ EXPORT_SYMBOL_GPL(ide_queue_sense_rq);
  */
 void ide_retry_pc(ide_drive_t *drive)
 {
+       struct request *failed_rq = drive->hwif->rq;
        struct request *sense_rq = &drive->sense_rq;
        struct ide_atapi_pc *pc = &drive->request_sense_pc;
 
@@ -254,14 +254,21 @@ void ide_retry_pc(ide_drive_t *drive)
        /* init pc from sense_rq */
        ide_init_pc(pc);
        memcpy(pc->c, sense_rq->cmd, 12);
-       pc->buf = bio_data(sense_rq->bio);      /* pointer to mapped address */
-       pc->req_xfer = sense_rq->data_len;
 
        if (drive->media == ide_tape)
-               set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
+               drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC;
 
-       if (ide_queue_sense_rq(drive, pc))
-               ide_complete_rq(drive, -EIO, blk_rq_bytes(drive->hwif->rq));
+       /*
+        * Push back the failed request and put request sense on top
+        * of it.  The failed command will be retried after sense data
+        * is acquired.
+        */
+       drive->hwif->rq = NULL;
+       ide_requeue_and_plug(drive, failed_rq);
+       if (ide_queue_sense_rq(drive, pc)) {
+               blk_start_request(failed_rq);
+               ide_complete_rq(drive, -EIO, blk_rq_bytes(failed_rq));
+       }
 }
 EXPORT_SYMBOL_GPL(ide_retry_pc);
 
@@ -288,7 +295,7 @@ int ide_cd_expiry(ide_drive_t *drive)
                break;
        default:
                if (!(rq->cmd_flags & REQ_QUIET))
-                       printk(KERN_INFO "cmd 0x%x timed out\n",
+                       printk(KERN_INFO PFX "cmd 0x%x timed out\n",
                                         rq->cmd[0]);
                wait = 0;
                break;
@@ -299,13 +306,16 @@ EXPORT_SYMBOL_GPL(ide_cd_expiry);
 
 int ide_cd_get_xferlen(struct request *rq)
 {
-       if (blk_fs_request(rq))
+       switch (rq->cmd_type) {
+       case REQ_TYPE_FS:
                return 32768;
-       else if (blk_sense_request(rq) || blk_pc_request(rq) ||
-                        rq->cmd_type == REQ_TYPE_ATA_PC)
-               return rq->data_len;
-       else
+       case REQ_TYPE_SENSE:
+       case REQ_TYPE_BLOCK_PC:
+       case REQ_TYPE_ATA_PC:
+               return blk_rq_bytes(rq);
+       default:
                return 0;
+       }
 }
 EXPORT_SYMBOL_GPL(ide_cd_get_xferlen);
 
@@ -322,6 +332,55 @@ void ide_read_bcount_and_ireason(ide_drive_t *drive, u16 *bcount, u8 *ireason)
 EXPORT_SYMBOL_GPL(ide_read_bcount_and_ireason);
 
 /*
+ * Check the contents of the interrupt reason register and attempt to recover if
+ * there are problems.
+ *
+ * Returns:
+ * - 0 if everything's ok
+ * - 1 if the request has to be terminated.
+ */
+int ide_check_ireason(ide_drive_t *drive, struct request *rq, int len,
+                     int ireason, int rw)
+{
+       ide_hwif_t *hwif = drive->hwif;
+
+       debug_log("ireason: 0x%x, rw: 0x%x\n", ireason, rw);
+
+       if (ireason == (!rw << 1))
+               return 0;
+       else if (ireason == (rw << 1)) {
+               printk(KERN_ERR PFX "%s: %s: wrong transfer direction!\n",
+                               drive->name, __func__);
+
+               if (dev_is_idecd(drive))
+                       ide_pad_transfer(drive, rw, len);
+       } else if (!rw && ireason == ATAPI_COD) {
+               if (dev_is_idecd(drive)) {
+                       /*
+                        * Some drives (ASUS) seem to tell us that status info
+                        * is available.  Just get it and ignore.
+                        */
+                       (void)hwif->tp_ops->read_status(hwif);
+                       return 0;
+               }
+       } else {
+               if (ireason & ATAPI_COD)
+                       printk(KERN_ERR PFX "%s: CoD != 0 in %s\n", drive->name,
+                                       __func__);
+
+               /* drive wants a command packet, or invalid ireason... */
+               printk(KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n",
+                               drive->name, __func__, ireason);
+       }
+
+       if (dev_is_idecd(drive) && rq->cmd_type == REQ_TYPE_ATA_PC)
+               rq->cmd_flags |= REQ_FAILED;
+
+       return 1;
+}
+EXPORT_SYMBOL_GPL(ide_check_ireason);
+
+/*
  * This is the usual interrupt handler which will be called during a packet
  * command.  We will transfer some of the data (as requested by the drive)
  * and will re-point interrupt handler to us.
@@ -355,22 +414,21 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
 
                if (rc || (drive->media == ide_tape && (stat & ATA_ERR))) {
                        if (drive->media == ide_floppy)
-                               printk(KERN_ERR "%s: DMA %s error\n",
+                               printk(KERN_ERR PFX "%s: DMA %s error\n",
                                        drive->name, rq_data_dir(pc->rq)
                                                     ? "write" : "read");
                        pc->flags |= PC_FLAG_DMA_ERROR;
                } else
-                       pc->xferred = pc->req_xfer;
+                       rq->resid_len = 0;
                debug_log("%s: DMA finished\n", drive->name);
        }
 
        /* No more interrupts */
        if ((stat & ATA_DRQ) == 0) {
                int uptodate, error;
-               unsigned int done;
 
                debug_log("Packet command completed, %d bytes transferred\n",
-                         pc->xferred);
+                         blk_rq_bytes(rq));
 
                pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
 
@@ -388,8 +446,8 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
                                pc->rq->errors++;
 
                        if (rq->cmd[0] == REQUEST_SENSE) {
-                               printk(KERN_ERR "%s: I/O error in request sense"
-                                               " command\n", drive->name);
+                               printk(KERN_ERR PFX "%s: I/O error in request "
+                                               "sense command\n", drive->name);
                                return ide_do_reset(drive);
                        }
 
@@ -418,12 +476,12 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
                if (uptodate == 0)
                        drive->failed_pc = NULL;
 
-               if (blk_special_request(rq)) {
+               if (rq->cmd_type == REQ_TYPE_SPECIAL) {
                        rq->errors = 0;
                        error = 0;
                } else {
 
-                       if (blk_fs_request(rq) == 0 && uptodate <= 0) {
+                       if (rq->cmd_type != REQ_TYPE_FS && uptodate <= 0) {
                                if (rq->errors == 0)
                                        rq->errors = -EIO;
                        }
@@ -431,14 +489,14 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
                        error = uptodate ? 0 : -EIO;
                }
 
-               ide_complete_rq(drive, error, done);
+               ide_complete_rq(drive, error, blk_rq_bytes(rq));
                return ide_stopped;
        }
 
        if (pc->flags & PC_FLAG_DMA_IN_PROGRESS) {
                pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
-               printk(KERN_ERR "%s: The device wants to issue more interrupts "
-                               "in DMA mode\n", drive->name);
+               printk(KERN_ERR PFX "%s: The device wants to issue more "
+                               "interrupts in DMA mode\n", drive->name);
                ide_dma_off(drive);
                return ide_do_reset(drive);
        }
@@ -446,33 +504,22 @@ static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
        /* Get the number of bytes to transfer on this interrupt. */
        ide_read_bcount_and_ireason(drive, &bcount, &ireason);
 
-       if (ireason & ATAPI_COD) {
-               printk(KERN_ERR "%s: CoD != 0 in %s\n", drive->name, __func__);
-               return ide_do_reset(drive);
-       }
-
-       if (((ireason & ATAPI_IO) == ATAPI_IO) == write) {
-               /* Hopefully, we will never get here */
-               printk(KERN_ERR "%s: We wanted to %s, but the device wants us "
-                               "to %s!\n", drive->name,
-                               (ireason & ATAPI_IO) ? "Write" : "Read",
-                               (ireason & ATAPI_IO) ? "Read" : "Write");
+       if (ide_check_ireason(drive, rq, bcount, ireason, write))
                return ide_do_reset(drive);
-       }
 
        done = min_t(unsigned int, bcount, cmd->nleft);
        ide_pio_bytes(drive, cmd, write, done);
 
        /* Update transferred byte count */
-       pc->xferred += done;
+       rq->resid_len -= done;
 
        bcount -= done;
 
        if (bcount)
                ide_pad_transfer(drive, write, bcount);
 
-       debug_log("[cmd %x] transferred %d bytes, padded %d bytes\n",
-                 rq->cmd[0], done, bcount);
+       debug_log("[cmd %x] transferred %d bytes, padded %d bytes, resid: %u\n",
+                 rq->cmd[0], done, bcount, rq->resid_len);
 
        /* And set the interrupt handler again */
        ide_set_handler(drive, ide_pc_intr, timeout);
@@ -506,13 +553,13 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
 
        while (retries-- && ((ireason & ATAPI_COD) == 0 ||
                (ireason & ATAPI_IO))) {
-               printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
+               printk(KERN_ERR PFX "%s: (IO,CoD != (0,1) while issuing "
                                "a packet command, retrying\n", drive->name);
                udelay(100);
                ireason = ide_read_ireason(drive);
                if (retries == 0) {
-                       printk(KERN_ERR "%s: (IO,CoD != (0,1) while issuing "
-                                       "a packet command, ignoring\n",
+                       printk(KERN_ERR PFX "%s: (IO,CoD != (0,1) while issuing"
+                                       " a packet command, ignoring\n",
                                        drive->name);
                        ireason |= ATAPI_COD;
                        ireason &= ~ATAPI_IO;
@@ -543,7 +590,7 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
        u8 ireason;
 
        if (ide_wait_stat(&startstop, drive, ATA_DRQ, ATA_BUSY, WAIT_READY)) {
-               printk(KERN_ERR "%s: Strange, packet command initiated yet "
+               printk(KERN_ERR PFX "%s: Strange, packet command initiated yet "
                                "DRQ isn't asserted\n", drive->name);
                return startstop;
        }
@@ -568,7 +615,7 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
 
                /*
                 * If necessary schedule the packet transfer to occur 'timeout'
-                * miliseconds later in ide_delayed_transfer_pc() after the
+                * milliseconds later in ide_delayed_transfer_pc() after the
                 * device says it's ready for a packet.
                 */
                if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
@@ -585,8 +632,8 @@ static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
                        ireason = ide_wait_ireason(drive, ireason);
 
                if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
-                       printk(KERN_ERR "%s: (IO,CoD) != (0,1) while issuing "
-                                       "a packet command\n", drive->name);
+                       printk(KERN_ERR PFX "%s: (IO,CoD) != (0,1) while "
+                               "issuing a packet command\n", drive->name);
 
                        return ide_do_reset(drive);
                }
@@ -624,7 +671,7 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
        ide_hwif_t *hwif = drive->hwif;
        ide_expiry_t *expiry = NULL;
        struct request *rq = hwif->rq;
-       unsigned int timeout;
+       unsigned int timeout, bytes;
        u16 bcount;
        u8 valid_tf;
        u8 drq_int = !!(drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT);
@@ -640,13 +687,14 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_cmd *cmd)
        } else {
                pc = drive->pc;
 
-               /* We haven't transferred any data yet */
-               pc->xferred = 0;
-
                valid_tf = IDE_VALID_DEVICE;
-               bcount = ((drive->media == ide_tape) ?
-                               pc->req_xfer :
-                               min(pc->req_xfer, 63 * 1024));
+               bytes = blk_rq_bytes(rq);
+               bcount = ((drive->media == ide_tape) ? bytes
+                                                    : min_t(unsigned int,
+                                                            bytes, 63 * 1024));
+
+               /* We haven't transferred any data yet */
+               rq->resid_len = bcount;
 
                if (pc->flags & PC_FLAG_DMA_ERROR) {
                        pc->flags &= ~PC_FLAG_DMA_ERROR;