ide: add ide_tf_read() helper
[pandora-kernel.git] / drivers / ide / ide-lib.c
index 062d3bc..15736d4 100644 (file)
@@ -458,8 +458,7 @@ static void ide_dump_opcode(ide_drive_t *drive)
        spin_unlock(&ide_lock);
        if (!rq)
                return;
-       if (rq->cmd_type == REQ_TYPE_ATA_CMD ||
-           rq->cmd_type == REQ_TYPE_ATA_TASK) {
+       if (rq->cmd_type == REQ_TYPE_ATA_CMD) {
                char *args = rq->buffer;
                if (args) {
                        opcode = args[0];
@@ -468,8 +467,7 @@ static void ide_dump_opcode(ide_drive_t *drive)
        } else if (rq->cmd_type == REQ_TYPE_ATA_TASKFILE) {
                ide_task_t *args = rq->special;
                if (args) {
-                       task_struct_t *tf = (task_struct_t *) args->tfRegister;
-                       opcode = tf->command;
+                       opcode = args->tf.command;
                        found = 1;
                }
        }
@@ -481,6 +479,42 @@ static void ide_dump_opcode(ide_drive_t *drive)
                printk("0x%02x\n", opcode);
 }
 
+static u64 ide_get_lba_addr(struct ide_taskfile *tf, int lba48)
+{
+       u32 high, low;
+
+       if (lba48)
+               high = (tf->hob_lbah << 16) | (tf->hob_lbam << 8) |
+                       tf->hob_lbal;
+       else
+               high = tf->device & 0xf;
+       low  = (tf->lbah << 16) | (tf->lbam << 8) | tf->lbal;
+
+       return ((u64)high << 24) | low;
+}
+
+static void ide_dump_sector(ide_drive_t *drive)
+{
+       ide_task_t task;
+       struct ide_taskfile *tf = &task.tf;
+       int lba48 = (drive->addressing == 1) ? 1 : 0;
+
+       memset(&task, 0, sizeof(task));
+       if (lba48)
+               task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_HOB_LBA |
+                               IDE_TFLAG_LBA48;
+       else
+               task.tf_flags = IDE_TFLAG_IN_LBA | IDE_TFLAG_IN_DEVICE;
+
+       ide_tf_read(drive, &task);
+
+       if (lba48 || (tf->device & ATA_LBA))
+               printk(", LBAsect=%llu", ide_get_lba_addr(tf, lba48));
+       else
+               printk(", CHS=%d/%d/%d", (tf->lbah << 8) + tf->lbam,
+                                        tf->device & 0xf, tf->lbal);
+}
+
 static u8 ide_dump_ata_status(ide_drive_t *drive, const char *msg, u8 stat)
 {
        ide_hwif_t *hwif = HWIF(drive);
@@ -514,33 +548,7 @@ static u8 ide_dump_ata_status(ide_drive_t *drive, const char *msg, u8 stat)
                printk("}");
                if ((err & (BBD_ERR | ABRT_ERR)) == BBD_ERR ||
                    (err & (ECC_ERR|ID_ERR|MARK_ERR))) {
-                       if (drive->addressing == 1) {
-                               __u64 sectors = 0;
-                               u32 low = 0, high = 0;
-                               hwif->OUTB(drive->ctl&~0x80, IDE_CONTROL_REG);
-                               low = ide_read_24(drive);
-                               hwif->OUTB(drive->ctl|0x80, IDE_CONTROL_REG);
-                               high = ide_read_24(drive);
-                               sectors = ((__u64)high << 24) | low;
-                               printk(", LBAsect=%llu, high=%d, low=%d",
-                                      (unsigned long long) sectors,
-                                      high, low);
-                       } else {
-                               u8 cur = hwif->INB(IDE_SELECT_REG);
-                               if (cur & 0x40) {       /* using LBA? */
-                                       printk(", LBAsect=%ld", (unsigned long)
-                                        ((cur&0xf)<<24)
-                                        |(hwif->INB(IDE_HCYL_REG)<<16)
-                                        |(hwif->INB(IDE_LCYL_REG)<<8)
-                                        | hwif->INB(IDE_SECTOR_REG));
-                               } else {
-                                       printk(", CHS=%d/%d/%d",
-                                        (hwif->INB(IDE_HCYL_REG)<<8) +
-                                         hwif->INB(IDE_LCYL_REG),
-                                         cur & 0xf,
-                                         hwif->INB(IDE_SECTOR_REG));
-                               }
-                       }
+                       ide_dump_sector(drive);
                        if (HWGROUP(drive) && HWGROUP(drive)->rq)
                                printk(", sector=%llu",
                                        (unsigned long long)HWGROUP(drive)->rq->sector);
@@ -564,40 +572,36 @@ static u8 ide_dump_ata_status(ide_drive_t *drive, const char *msg, u8 stat)
 static u8 ide_dump_atapi_status(ide_drive_t *drive, const char *msg, u8 stat)
 {
        unsigned long flags;
+       u8 err = 0;
 
-       atapi_status_t status;
-       atapi_error_t error;
-
-       status.all = stat;
-       error.all = 0;
        local_irq_save(flags);
        printk("%s: %s: status=0x%02x { ", drive->name, msg, stat);
-       if (status.b.bsy)
+       if (stat & BUSY_STAT)
                printk("Busy ");
        else {
-               if (status.b.drdy)      printk("DriveReady ");
-               if (status.b.df)        printk("DeviceFault ");
-               if (status.b.dsc)       printk("SeekComplete ");
-               if (status.b.drq)       printk("DataRequest ");
-               if (status.b.corr)      printk("CorrectedError ");
-               if (status.b.idx)       printk("Index ");
-               if (status.b.check)     printk("Error ");
+               if (stat & READY_STAT)  printk("DriveReady ");
+               if (stat & WRERR_STAT)  printk("DeviceFault ");
+               if (stat & SEEK_STAT)   printk("SeekComplete ");
+               if (stat & DRQ_STAT)    printk("DataRequest ");
+               if (stat & ECC_STAT)    printk("CorrectedError ");
+               if (stat & INDEX_STAT)  printk("Index ");
+               if (stat & ERR_STAT)    printk("Error ");
        }
        printk("}\n");
-       if (status.b.check && !status.b.bsy) {
-               error.all = HWIF(drive)->INB(IDE_ERROR_REG);
-               printk("%s: %s: error=0x%02x { ", drive->name, msg, error.all);
-               if (error.b.ili)        printk("IllegalLengthIndication ");
-               if (error.b.eom)        printk("EndOfMedia ");
-               if (error.b.abrt)       printk("AbortedCommand ");
-               if (error.b.mcr)        printk("MediaChangeRequested ");
-               if (error.b.sense_key)  printk("LastFailedSense=0x%02x ",
-                                               error.b.sense_key);
+       if ((stat & (BUSY_STAT|ERR_STAT)) == ERR_STAT) {
+               err = drive->hwif->INB(IDE_ERROR_REG);
+               printk("%s: %s: error=0x%02x { ", drive->name, msg, err);
+               if (err & ILI_ERR)      printk("IllegalLengthIndication ");
+               if (err & EOM_ERR)      printk("EndOfMedia ");
+               if (err & ABRT_ERR)     printk("AbortedCommand ");
+               if (err & MCR_ERR)      printk("MediaChangeRequested ");
+               if (err & LFS_ERR)      printk("LastFailedSense=0x%02x ",
+                                               (err & LFS_ERR) >> 4);
                printk("}\n");
        }
        ide_dump_opcode(drive);
        local_irq_restore(flags);
-       return error.all;
+       return err;
 }
 
 /**