]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - drivers/ide/ide-disk.c
ide-disk: move IDE_DFLAG_DOORLOCKING flag handling to idedisk_set_doorlock()
[linux-2.6-omap-h63xx.git] / drivers / ide / ide-disk.c
index 3853bde8eedc3c291b8b676529563afccdcc2f0d..289a533afbd699be220689c3b70b9e2ce9c30891 100644 (file)
@@ -49,8 +49,6 @@
 
 static DEFINE_MUTEX(idedisk_ref_mutex);
 
-#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref)
-
 static void ide_disk_release(struct kref *);
 
 static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
@@ -58,7 +56,7 @@ static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
        struct ide_disk_obj *idkp = NULL;
 
        mutex_lock(&idedisk_ref_mutex);
-       idkp = ide_disk_g(disk);
+       idkp = ide_drv_g(disk, ide_disk_obj);
        if (idkp) {
                if (ide_device_get(idkp->drive))
                        idkp = NULL;
@@ -403,6 +401,26 @@ static void init_idedisk_capacity(ide_drive_t *drive)
                if (ata_id_hpa_enabled(id))
                        idedisk_check_hpa(drive);
        }
+
+       /* limit drive capacity to 137GB if LBA48 cannot be used */
+       if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
+           drive->capacity64 > 1ULL << 28) {
+               printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
+                      "%llu sectors (%llu MB)\n",
+                      drive->name, (unsigned long long)drive->capacity64,
+                      sectors_to_MB(drive->capacity64));
+               drive->capacity64 = 1ULL << 28;
+       }
+
+       if ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
+           (drive->dev_flags & IDE_DFLAG_LBA48)) {
+               if (drive->capacity64 > 1ULL << 28) {
+                       printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
+                                        " will be used for accessing sectors "
+                                        "> %u\n", drive->name, 1 << 28);
+               } else
+                       drive->dev_flags &= ~IDE_DFLAG_LBA48;
+       }
 }
 
 sector_t ide_disk_capacity(ide_drive_t *drive)
@@ -654,26 +672,6 @@ static void idedisk_setup(ide_drive_t *drive)
        /* calculate drive capacity, and select LBA if possible */
        init_idedisk_capacity(drive);
 
-       /* limit drive capacity to 137GB if LBA48 cannot be used */
-       if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
-           drive->capacity64 > 1ULL << 28) {
-               printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
-                      "%llu sectors (%llu MB)\n",
-                      drive->name, (unsigned long long)drive->capacity64,
-                      sectors_to_MB(drive->capacity64));
-               drive->capacity64 = 1ULL << 28;
-       }
-
-       if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
-           (drive->dev_flags & IDE_DFLAG_LBA48)) {
-               if (drive->capacity64 > 1ULL << 28) {
-                       printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
-                                        " will be used for accessing sectors "
-                                        "> %u\n", drive->name, 1 << 28);
-               } else
-                       drive->dev_flags &= ~IDE_DFLAG_LBA48;
-       }
-
        /*
         * if possible, give fdisk access to more of the drive,
         * by correcting bios_cyls:
@@ -746,7 +744,7 @@ static void ide_disk_remove(ide_drive_t *drive)
 
 static void ide_disk_release(struct kref *kref)
 {
-       struct ide_disk_obj *idkp = to_ide_disk(kref);
+       struct ide_disk_obj *idkp = to_ide_drv(kref, ide_disk_obj);
        ide_drive_t *drive = idkp->drive;
        struct gendisk *g = idkp->disk;
 
@@ -819,12 +817,21 @@ static ide_driver_t idedisk_driver = {
 static int idedisk_set_doorlock(ide_drive_t *drive, int on)
 {
        ide_task_t task;
+       int ret;
+
+       if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
+               return 0;
 
        memset(&task, 0, sizeof(task));
        task.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK;
        task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
 
-       return ide_no_data_taskfile(drive, &task);
+       ret = ide_no_data_taskfile(drive, &task);
+
+       if (ret)
+               drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
+
+       return ret;
 }
 
 static int idedisk_open(struct inode *inode, struct file *filp)
@@ -842,15 +849,13 @@ static int idedisk_open(struct inode *inode, struct file *filp)
        idkp->openers++;
 
        if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
-               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->dev_flags & IDE_DFLAG_DOORLOCKING) &&
-                   idedisk_set_doorlock(drive, 1))
-                       drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
+               idedisk_set_doorlock(drive, 1);
+               check_disk_change(inode->i_bdev);
        }
        return 0;
 }
@@ -858,17 +863,14 @@ static int idedisk_open(struct inode *inode, struct file *filp)
 static int idedisk_release(struct inode *inode, struct file *filp)
 {
        struct gendisk *disk = inode->i_bdev->bd_disk;
-       struct ide_disk_obj *idkp = ide_disk_g(disk);
+       struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
        ide_drive_t *drive = idkp->drive;
 
        if (idkp->openers == 1)
                ide_cacheflush_p(drive);
 
-       if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
-               if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
-                   idedisk_set_doorlock(drive, 0))
-                       drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
-       }
+       if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1)
+               idedisk_set_doorlock(drive, 0);
 
        idkp->openers--;
 
@@ -879,7 +881,7 @@ static int idedisk_release(struct inode *inode, struct file *filp)
 
 static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 {
-       struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
+       struct ide_disk_obj *idkp = ide_drv_g(bdev->bd_disk, ide_disk_obj);
        ide_drive_t *drive = idkp->drive;
 
        geo->heads = drive->bios_head;
@@ -890,7 +892,7 @@ static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 
 static int idedisk_media_changed(struct gendisk *disk)
 {
-       struct ide_disk_obj *idkp = ide_disk_g(disk);
+       struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
        ide_drive_t *drive = idkp->drive;
 
        /* do not scan partitions twice if this is a removable device */
@@ -905,7 +907,7 @@ static int idedisk_media_changed(struct gendisk *disk)
 
 static int idedisk_revalidate_disk(struct gendisk *disk)
 {
-       struct ide_disk_obj *idkp = ide_disk_g(disk);
+       struct ide_disk_obj *idkp = ide_drv_g(disk, ide_disk_obj);
        set_capacity(disk, ide_disk_capacity(idkp->drive));
        return 0;
 }