Merge branch 'for-2.6.31' of git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 20 Jun 2009 17:11:11 +0000 (10:11 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 20 Jun 2009 17:11:11 +0000 (10:11 -0700)
* 'for-2.6.31' of git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6: (34 commits)
  ide-cd: prevent null pointer deref via cdrom_newpc_intr
  ide: BUG() on unknown requests
  ide: filter out invalid DMA xfer mode changes in HDIO_DRIVE_CMD ioctl handler
  ide: do not access ide_drive_t 'drive_data' field directly
  sl82c105: implement test_irq() method
  siimage: implement test_irq() method
  pdc202xx_old: implement test_irq() method (take 2)
  cmd64x: implement test_irq() method
  cmd640: implement test_irq() method
  ide: move ack_intr() method into 'struct ide_port_ops' (take 2)
  ide: move IRQ clearing from ack_intr() method to clear_irq() method (take 2)
  siimage: use ide_dma_test_irq() (take 2)
  cmd64x: implement clear_irq() method (take 2)
  ide: call clear_irq() method in ide_timer_expiry()
  sgiioc4: coding style cleanup
  ide: don't enable IORDY at a probe time
  ide: IORDY handling fixes
  ata: add ata_id_pio_need_iordy() helper (v2)
  ide-tape: fix build issue
  ide: unify interrupt reason checking
  ...

1  2 
drivers/ide/ide-atapi.c
drivers/ide/ide-probe.c

diff --combined drivers/ide/ide-atapi.c
@@@ -10,6 -10,9 +10,9 @@@
  
  #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 -77,6 +77,6 @@@ EXPORT_SYMBOL_GPL(ide_check_atapi_devic
  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 -85,7 +85,7 @@@
   * 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 -94,8 +94,8 @@@
        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 -118,7 +118,7 @@@ int ide_do_test_unit_ready(ide_drive_t 
        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 -133,7 +133,7 @@@ int ide_do_start_stop(ide_drive_t *driv
        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 -148,7 +148,7 @@@ int ide_set_media_lock(ide_drive_t *dri
        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 -173,6 +173,6 @@@ void ide_prep_sense(ide_drive_t *drive
        unsigned int cmd_len, sense_len;
        int err;
  
-       debug_log("%s: enter\n", __func__);
        switch (drive->media) {
        case ide_floppy:
                cmd_len = 255;
                              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 -222,7 +222,7 @@@ int ide_queue_sense_rq(ide_drive_t *dri
  {
        /* 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;
        }
@@@ -255,8 -254,6 +254,6 @@@ 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 = blk_rq_bytes(sense_rq);
  
        if (drive->media == ide_tape)
                drive->atapi_flags |= IDE_AFLAG_IGNORE_DSC;
@@@ -298,7 -295,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;
@@@ -331,6 -328,55 +328,55 @@@ void ide_read_bcount_and_ireason(ide_dr
  }
  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)
@@@ -365,12 -411,12 +411,12 @@@ static ide_startstop_t ide_pc_intr(ide_
  
                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);
        }
  
                int uptodate, error;
  
                debug_log("Packet command completed, %d bytes transferred\n",
-                         pc->xferred);
+                         blk_rq_bytes(rq));
  
                pc->flags &= ~PC_FLAG_DMA_IN_PROGRESS;
  
                                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);
                        }
  
  
        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);
        }
        /* 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__);
+       if (ide_check_ireason(drive, rq, bcount, ireason, write))
                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");
-               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);
@@@ -515,13 -550,13 +550,13 @@@ static u8 ide_wait_ireason(ide_drive_t 
  
        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;
@@@ -552,7 -587,7 +587,7 @@@ static ide_startstop_t ide_transfer_pc(
        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;
        }
  
                /*
                 * 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) {
                        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);
                }
@@@ -633,7 -668,7 +668,7 @@@ ide_startstop_t ide_issue_pc(ide_drive_
        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);
        } 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;
diff --combined drivers/ide/ide-probe.c
@@@ -535,7 -535,7 +535,7 @@@ static int ide_register_port(ide_hwif_
  
        /* register with global device tree */
        dev_set_name(&hwif->gendev, hwif->name);
 -      hwif->gendev.driver_data = hwif;
 +      dev_set_drvdata(&hwif->gendev, hwif);
        if (hwif->gendev.parent == NULL)
                hwif->gendev.parent = hwif->dev;
        hwif->gendev.release = hwif_release_dev;
@@@ -987,9 -987,9 +987,9 @@@ static void hwif_register_devices(ide_h
                int ret;
  
                dev_set_name(dev, "%u.%u", hwif->index, i);
 +              dev_set_drvdata(dev, drive);
                dev->parent = &hwif->gendev;
                dev->bus = &ide_bus_type;
 -              dev->driver_data = drive;
                dev->release = drive_release_dev;
  
                ret = device_register(dev);
@@@ -1170,7 -1170,6 +1170,6 @@@ static void ide_init_port_hw(ide_hwif_
        hwif->irq = hw->irq;
        hwif->dev = hw->dev;
        hwif->gendev.parent = hw->parent ? hw->parent : hw->dev;
-       hwif->ack_intr = hw->ack_intr;
        hwif->config_data = hw->config;
  }
  
@@@ -1378,6 -1377,9 +1377,9 @@@ int ide_host_register(struct ide_host *
  
                ide_init_port(hwif, i & 1, d);
                ide_port_cable_detect(hwif);
+               hwif->port_flags |= IDE_PFLAG_PROBING;
                ide_port_init_devices(hwif);
        }
  
                if (ide_probe_port(hwif) == 0)
                        hwif->present = 1;
  
+               hwif->port_flags &= ~IDE_PFLAG_PROBING;
                if ((hwif->host_flags & IDE_HFLAG_4DRIVES) == 0 ||
                    hwif->mate == NULL || hwif->mate->present == 0) {
                        if (ide_register_port(hwif)) {
@@@ -1569,11 -1573,20 +1573,20 @@@ EXPORT_SYMBOL_GPL(ide_host_remove)
  
  void ide_port_scan(ide_hwif_t *hwif)
  {
+       int rc;
        ide_port_apply_params(hwif);
        ide_port_cable_detect(hwif);
+       hwif->port_flags |= IDE_PFLAG_PROBING;
        ide_port_init_devices(hwif);
  
-       if (ide_probe_port(hwif) < 0)
+       rc = ide_probe_port(hwif);
+       hwif->port_flags &= ~IDE_PFLAG_PROBING;
+       if (rc < 0)
                return;
  
        hwif->present = 1;