]> err.no Git - linux-2.6/blobdiff - drivers/ide/ide-disk.c
iget: stop QNX4 from using iget() and read_inode()
[linux-2.6] / drivers / ide / ide-disk.c
index 97abc91db7d09aed2014a2b33a9902addd47f629..3c69822507e2a59216e8d2690362c961a940579b 100644 (file)
@@ -1,10 +1,9 @@
 /*
- *  linux/drivers/ide/ide-disk.c       Version 1.18    Mar 05, 2003
- *
- *  Copyright (C) 1994-1998  Linus Torvalds & authors (see below)
- *  Copyright (C) 1998-2002  Linux ATA Development
- *                             Andre Hedrick <andre@linux-ide.org>
- *  Copyright (C) 2003      Red Hat <alan@redhat.com>
+ *  Copyright (C) 1994-1998       Linus Torvalds & authors (see below)
+ *  Copyright (C) 1998-2002       Linux ATA Development
+ *                                   Andre Hedrick <andre@linux-ide.org>
+ *  Copyright (C) 2003            Red Hat <alan@redhat.com>
+ *  Copyright (C) 2003-2005, 2007  Bartlomiej Zolnierkiewicz
  */
 
 /*
@@ -185,6 +184,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
        u8 lba48                = (drive->addressing == 1) ? 1 : 0;
        ide_task_t              task;
        struct ide_taskfile     *tf = &task.tf;
+       ide_startstop_t         rc;
 
        if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && lba48 && dma) {
                if (block + rq->nr_sectors > 1ULL << 28)
@@ -200,7 +200,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
 
        memset(&task, 0, sizeof(task));
        task.tf_flags = IDE_TFLAG_NO_SELECT_MASK;  /* FIXME? */
-       task.tf_flags |= (IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE);
+       task.tf_flags |= (IDE_TFLAG_TF | IDE_TFLAG_DEVICE);
 
        if (drive->select.b.lba) {
                if (lba48) {
@@ -218,13 +218,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
                        tf->lbal   = (u8) block;
                        tf->lbam   = (u8)(block >>  8);
                        tf->lbah   = (u8)(block >> 16);
-#ifdef DEBUG
-                       printk("%s: 0x%02x%02x 0x%02x%02x%02x%02x%02x%02x\n",
-                               drive->name, tf->hob_nsect, tf->nsect,
-                               tf->hob_lbah, tf->hob_lbam, tf->hob_lbal,
-                               tf->lbah, tf->lbam, tf->lbal);
-#endif
-                       task.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_OUT_HOB);
+
+                       task.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB);
                } else {
                        tf->nsect  = nsectors & 0xff;
                        tf->lbal   = block;
@@ -252,32 +247,22 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
                task.tf_flags |= IDE_TFLAG_WRITE;
 
        ide_tf_set_cmd(drive, &task, dma);
+       if (!dma)
+               hwif->data_phase = task.data_phase;
+       task.rq = rq;
 
-       ide_tf_load(drive, &task);
+       rc = do_rw_taskfile(drive, &task);
 
-       if (dma) {
-               if (!hwif->dma_setup(drive)) {
-                       hwif->dma_exec_cmd(drive, tf->command);
-                       hwif->dma_start(drive);
-                       return ide_started;
-               }
+       if (rc == ide_stopped && dma) {
                /* fallback to PIO */
+               task.tf_flags |= IDE_TFLAG_DMA_PIO_FALLBACK;
                ide_tf_set_cmd(drive, &task, 0);
+               hwif->data_phase = task.data_phase;
                ide_init_sg_cmd(drive, rq);
+               rc = do_rw_taskfile(drive, &task);
        }
 
-       hwif->data_phase = task.data_phase;
-
-       if (rq_data_dir(rq) == READ) {
-               ide_execute_command(drive, tf->command, &task_in_intr,
-                                   WAIT_WORSTCASE, NULL);
-               return ide_started;
-       } else {
-               hwif->OUTBSYNC(drive, tf->command, IDE_COMMAND_REG);
-               ndelay(400);    /* FIXME */
-
-               return pre_task_out_intr(drive, rq);
-       }
+       return rc;
 }
 
 /*
@@ -328,25 +313,16 @@ static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48)
        else
                tf->command = WIN_READ_NATIVE_MAX;
        tf->device  = ATA_LBA;
-       args.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
+       args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
        if (lba48)
-               args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_OUT_HOB);
+               args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB);
        /* submit command request */
        ide_no_data_taskfile(drive, &args);
 
        /* if OK, compute maximum address value */
-       if ((tf->status & 0x01) == 0) {
-               u32 high, low;
+       if ((tf->status & 0x01) == 0)
+               addr = ide_get_lba_addr(tf, lba48) + 1;
 
-               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;
-               addr = ((__u64)high << 24) | low;
-               addr++; /* since the return value is (maxlba - 1), we add 1 */
-       }
        return addr;
 }
 
@@ -376,24 +352,15 @@ static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48)
                tf->command  = WIN_SET_MAX;
        }
        tf->device |= ATA_LBA;
-       args.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
+       args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
        if (lba48)
-               args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_OUT_HOB);
+               args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_HOB);
        /* submit command request */
        ide_no_data_taskfile(drive, &args);
        /* if OK, compute maximum address value */
-       if ((tf->status & 0x01) == 0) {
-               u32 high, low;
+       if ((tf->status & 0x01) == 0)
+               addr_set = ide_get_lba_addr(tf, lba48) + 1;
 
-               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;
-               addr_set = ((__u64)high << 24) | low;
-               addr_set++;
-       }
        return addr_set;
 }
 
@@ -527,7 +494,7 @@ static int smart_enable(ide_drive_t *drive)
        tf->lbam    = SMART_LCYL_PASS;
        tf->lbah    = SMART_HCYL_PASS;
        tf->command = WIN_SMART;
-       args.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
+       args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
        return ide_no_data_taskfile(drive, &args);
 }
 
@@ -542,7 +509,7 @@ static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
        tf->lbam    = SMART_LCYL_PASS;
        tf->lbah    = SMART_HCYL_PASS;
        tf->command = WIN_SMART;
-       args.tf_flags   = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
+       args.tf_flags   = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
        args.data_phase = TASKFILE_IN;
        (void) smart_enable(drive);
        return ide_raw_taskfile(drive, &args, buf, 1);
@@ -652,8 +619,10 @@ static int set_multcount(ide_drive_t *drive, int arg)
 
        if (drive->special.b.set_multmode)
                return -EBUSY;
+
        ide_init_drive_cmd (&rq);
-       rq.cmd_type = REQ_TYPE_ATA_CMD;
+       rq.cmd_type = REQ_TYPE_ATA_TASKFILE;
+
        drive->mult_req = arg;
        drive->special.b.set_multmode = 1;
        (void) ide_do_drive_cmd (drive, &rq, ide_wait);
@@ -721,7 +690,7 @@ static int write_cache(ide_drive_t *drive, int arg)
                args.tf.feature = arg ?
                        SETFEATURES_EN_WCACHE : SETFEATURES_DIS_WCACHE;
                args.tf.command = WIN_SETFEATURES;
-               args.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
+               args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
                err = ide_no_data_taskfile(drive, &args);
                if (err == 0)
                        drive->wcache = arg;
@@ -741,7 +710,7 @@ static int do_idedisk_flushcache (ide_drive_t *drive)
                args.tf.command = WIN_FLUSH_CACHE_EXT;
        else
                args.tf.command = WIN_FLUSH_CACHE;
-       args.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
+       args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
        return ide_no_data_taskfile(drive, &args);
 }
 
@@ -756,7 +725,7 @@ static int set_acoustic (ide_drive_t *drive, int arg)
        args.tf.feature = arg ? SETFEATURES_EN_AAM : SETFEATURES_DIS_AAM;
        args.tf.nsect   = arg;
        args.tf.command = WIN_SETFEATURES;
-       args.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
+       args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
        ide_no_data_taskfile(drive, &args);
        drive->acoustic = arg;
        return 0;
@@ -793,7 +762,6 @@ static void idedisk_add_settings(ide_drive_t *drive)
        ide_add_setting(drive,  "bios_head",    SETTING_RW,     TYPE_BYTE,      0,      255,                    1,      1,      &drive->bios_head,      NULL);
        ide_add_setting(drive,  "bios_sect",    SETTING_RW,     TYPE_BYTE,      0,      63,                     1,      1,      &drive->bios_sect,      NULL);
        ide_add_setting(drive,  "address",      SETTING_RW,     TYPE_BYTE,      0,      2,                      1,      1,      &drive->addressing,     set_lba_addressing);
-       ide_add_setting(drive,  "bswap",        SETTING_READ,   TYPE_BYTE,      0,      1,                      1,      1,      &drive->bswap,          NULL);
        ide_add_setting(drive,  "multcount",    SETTING_RW,     TYPE_BYTE,      0,      id->max_multsect,       1,      1,      &drive->mult_count,     set_multcount);
        ide_add_setting(drive,  "nowerr",       SETTING_RW,     TYPE_BYTE,      0,      1,                      1,      1,      &drive->nowerr,         set_nowerr);
        ide_add_setting(drive,  "lun",          SETTING_RW,     TYPE_INT,       0,      7,                      1,      1,      &drive->lun,            NULL);
@@ -1002,6 +970,17 @@ static ide_driver_t idedisk_driver = {
 #endif
 };
 
+static int idedisk_set_doorlock(ide_drive_t *drive, int on)
+{
+       ide_task_t task;
+
+       memset(&task, 0, sizeof(task));
+       task.tf.command = on ? WIN_DOORLOCK : WIN_DOORUNLOCK;
+       task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
+
+       return ide_no_data_taskfile(drive, &task);
+}
+
 static int idedisk_open(struct inode *inode, struct file *filp)
 {
        struct gendisk *disk = inode->i_bdev->bd_disk;
@@ -1016,17 +995,13 @@ static int idedisk_open(struct inode *inode, struct file *filp)
        idkp->openers++;
 
        if (drive->removable && idkp->openers == 1) {
-               ide_task_t args;
-               memset(&args, 0, sizeof(ide_task_t));
-               args.tf.command = WIN_DOORLOCK;
-               args.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
                check_disk_change(inode->i_bdev);
                /*
                 * Ignore the return code from door_lock,
                 * since the open() has already succeeded,
                 * and the door_lock is irrelevant at this point.
                 */
-               if (drive->doorlocking && ide_no_data_taskfile(drive, &args))
+               if (drive->doorlocking && idedisk_set_doorlock(drive, 1))
                        drive->doorlocking = 0;
        }
        return 0;
@@ -1042,11 +1017,7 @@ static int idedisk_release(struct inode *inode, struct file *filp)
                ide_cacheflush_p(drive);
 
        if (drive->removable && idkp->openers == 1) {
-               ide_task_t args;
-               memset(&args, 0, sizeof(ide_task_t));
-               args.tf.command = WIN_DOORUNLOCK;
-               args.tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE;
-               if (drive->doorlocking && ide_no_data_taskfile(drive, &args))
+               if (drive->doorlocking && idedisk_set_doorlock(drive, 0))
                        drive->doorlocking = 0;
        }