aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-disk.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-10-20 16:12:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-20 16:12:39 -0400
commit72558dde738b06cc01e16b3247a9659ca739e22d (patch)
tree9b9ff02668fd9f948efe24bef56a23fb78f7e4d0 /drivers/ide/ide-disk.c
parentb91385236c00031c64b42b44db8068ad38a5ea11 (diff)
parent769b49ce68386b21e45bb6e573b63c02020b17a1 (diff)
Merge git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6
* git://git.kernel.org/pub/scm/linux/kernel/git/bart/ide-2.6: (36 commits) ide: re-add TRM290 fix lost during ide_build_dmatable() cleanup scc_pata: kill unused variables sgiioc4: kill duplicate ioremap() sgiioc4: kill useless address checks delkin_cb: add PM support ide: remove broken hpt34x driver ide-floppy: remove idefloppy_floppy_t typedef sgiioc4: remove maskproc() method hpt366: cleanup maskproc() method ide: mask interrupt in ide_config_drive_speed() hpt366: fix compile warning ide: remove unused macros from <asm-parisc/ide.h> ide: remove M68K_IDE_SWAPW define from <asm-m68k/ide.h> ide: remove dead <asm-arm/arch-sa1100/ide.h> ide: fix support for IDE PCI controllers using MMIO on frv ide-cd: remove stale comment ide-cd: small drive type print fix ide-cd: debug log enhancements ide: add generic ATA/ATAPI disk driver ide: allow device drivers to specify per-device type /proc settings ...
Diffstat (limited to 'drivers/ide/ide-disk.c')
-rw-r--r--drivers/ide/ide-disk.c382
1 files changed, 62 insertions, 320 deletions
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 3853bde8eedc..223750c1b5a6 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -14,9 +14,6 @@
14 * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c. 14 * This is the IDE/ATA disk driver, as evolved from hd.c and ide.c.
15 */ 15 */
16 16
17#define IDEDISK_VERSION "1.18"
18
19#include <linux/module.h>
20#include <linux/types.h> 17#include <linux/types.h>
21#include <linux/string.h> 18#include <linux/string.h>
22#include <linux/kernel.h> 19#include <linux/kernel.h>
@@ -39,46 +36,8 @@
39#include <asm/io.h> 36#include <asm/io.h>
40#include <asm/div64.h> 37#include <asm/div64.h>
41 38
42#if !defined(CONFIG_DEBUG_BLOCK_EXT_DEVT)
43#define IDE_DISK_MINORS (1 << PARTN_BITS)
44#else
45#define IDE_DISK_MINORS 0
46#endif
47
48#include "ide-disk.h" 39#include "ide-disk.h"
49 40
50static DEFINE_MUTEX(idedisk_ref_mutex);
51
52#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref)
53
54static void ide_disk_release(struct kref *);
55
56static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
57{
58 struct ide_disk_obj *idkp = NULL;
59
60 mutex_lock(&idedisk_ref_mutex);
61 idkp = ide_disk_g(disk);
62 if (idkp) {
63 if (ide_device_get(idkp->drive))
64 idkp = NULL;
65 else
66 kref_get(&idkp->kref);
67 }
68 mutex_unlock(&idedisk_ref_mutex);
69 return idkp;
70}
71
72static void ide_disk_put(struct ide_disk_obj *idkp)
73{
74 ide_drive_t *drive = idkp->drive;
75
76 mutex_lock(&idedisk_ref_mutex);
77 kref_put(&idkp->kref, ide_disk_release);
78 ide_device_put(drive);
79 mutex_unlock(&idedisk_ref_mutex);
80}
81
82static const u8 ide_rw_cmds[] = { 41static const u8 ide_rw_cmds[] = {
83 ATA_CMD_READ_MULTI, 42 ATA_CMD_READ_MULTI,
84 ATA_CMD_WRITE_MULTI, 43 ATA_CMD_WRITE_MULTI,
@@ -374,7 +333,7 @@ static void idedisk_check_hpa(ide_drive_t *drive)
374 } 333 }
375} 334}
376 335
377static void init_idedisk_capacity(ide_drive_t *drive) 336static int ide_disk_get_capacity(ide_drive_t *drive)
378{ 337{
379 u16 *id = drive->id; 338 u16 *id = drive->id;
380 int lba; 339 int lba;
@@ -403,11 +362,28 @@ static void init_idedisk_capacity(ide_drive_t *drive)
403 if (ata_id_hpa_enabled(id)) 362 if (ata_id_hpa_enabled(id))
404 idedisk_check_hpa(drive); 363 idedisk_check_hpa(drive);
405 } 364 }
406}
407 365
408sector_t ide_disk_capacity(ide_drive_t *drive) 366 /* limit drive capacity to 137GB if LBA48 cannot be used */
409{ 367 if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
410 return drive->capacity64; 368 drive->capacity64 > 1ULL << 28) {
369 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
370 "%llu sectors (%llu MB)\n",
371 drive->name, (unsigned long long)drive->capacity64,
372 sectors_to_MB(drive->capacity64));
373 drive->capacity64 = 1ULL << 28;
374 }
375
376 if ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
377 (drive->dev_flags & IDE_DFLAG_LBA48)) {
378 if (drive->capacity64 > 1ULL << 28) {
379 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
380 " will be used for accessing sectors "
381 "> %u\n", drive->name, 1 << 28);
382 } else
383 drive->dev_flags &= ~IDE_DFLAG_LBA48;
384 }
385
386 return 0;
411} 387}
412 388
413static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) 389static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
@@ -508,7 +484,7 @@ static void update_ordered(ide_drive_t *drive)
508 * time we have trimmed the drive capacity if LBA48 is 484 * time we have trimmed the drive capacity if LBA48 is
509 * not available so we don't need to recheck that. 485 * not available so we don't need to recheck that.
510 */ 486 */
511 capacity = ide_disk_capacity(drive); 487 capacity = ide_gd_capacity(drive);
512 barrier = ata_id_flush_enabled(id) && 488 barrier = ata_id_flush_enabled(id) &&
513 (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 && 489 (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 &&
514 ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 || 490 ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 ||
@@ -616,7 +592,12 @@ ide_ext_devset_rw(wcache, wcache);
616 592
617ide_ext_devset_rw_sync(nowerr, nowerr); 593ide_ext_devset_rw_sync(nowerr, nowerr);
618 594
619static void idedisk_setup(ide_drive_t *drive) 595static int ide_disk_check(ide_drive_t *drive, const char *s)
596{
597 return 1;
598}
599
600static void ide_disk_setup(ide_drive_t *drive)
620{ 601{
621 struct ide_disk_obj *idkp = drive->driver_data; 602 struct ide_disk_obj *idkp = drive->driver_data;
622 ide_hwif_t *hwif = drive->hwif; 603 ide_hwif_t *hwif = drive->hwif;
@@ -652,33 +633,13 @@ static void idedisk_setup(ide_drive_t *drive)
652 drive->queue->max_sectors / 2); 633 drive->queue->max_sectors / 2);
653 634
654 /* calculate drive capacity, and select LBA if possible */ 635 /* calculate drive capacity, and select LBA if possible */
655 init_idedisk_capacity(drive); 636 ide_disk_get_capacity(drive);
656
657 /* limit drive capacity to 137GB if LBA48 cannot be used */
658 if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
659 drive->capacity64 > 1ULL << 28) {
660 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
661 "%llu sectors (%llu MB)\n",
662 drive->name, (unsigned long long)drive->capacity64,
663 sectors_to_MB(drive->capacity64));
664 drive->capacity64 = 1ULL << 28;
665 }
666
667 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
668 (drive->dev_flags & IDE_DFLAG_LBA48)) {
669 if (drive->capacity64 > 1ULL << 28) {
670 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
671 " will be used for accessing sectors "
672 "> %u\n", drive->name, 1 << 28);
673 } else
674 drive->dev_flags &= ~IDE_DFLAG_LBA48;
675 }
676 637
677 /* 638 /*
678 * if possible, give fdisk access to more of the drive, 639 * if possible, give fdisk access to more of the drive,
679 * by correcting bios_cyls: 640 * by correcting bios_cyls:
680 */ 641 */
681 capacity = ide_disk_capacity(drive); 642 capacity = ide_gd_capacity(drive);
682 643
683 if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) { 644 if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) {
684 if (ata_id_lba48_enabled(drive->id)) { 645 if (ata_id_lba48_enabled(drive->id)) {
@@ -718,9 +679,17 @@ static void idedisk_setup(ide_drive_t *drive)
718 drive->dev_flags |= IDE_DFLAG_WCACHE; 679 drive->dev_flags |= IDE_DFLAG_WCACHE;
719 680
720 set_wcache(drive, 1); 681 set_wcache(drive, 1);
682
683 if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
684 (drive->head == 0 || drive->head > 16)) {
685 printk(KERN_ERR "%s: invalid geometry: %d physical heads?\n",
686 drive->name, drive->head);
687 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
688 } else
689 drive->dev_flags |= IDE_DFLAG_ATTACH;
721} 690}
722 691
723static void ide_cacheflush_p(ide_drive_t *drive) 692static void ide_disk_flush(ide_drive_t *drive)
724{ 693{
725 if (ata_id_flush_enabled(drive->id) == 0 || 694 if (ata_id_flush_enabled(drive->id) == 0 ||
726 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) 695 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
@@ -730,267 +699,40 @@ static void ide_cacheflush_p(ide_drive_t *drive)
730 printk(KERN_INFO "%s: wcache flush failed!\n", drive->name); 699 printk(KERN_INFO "%s: wcache flush failed!\n", drive->name);
731} 700}
732 701
733static void ide_disk_remove(ide_drive_t *drive) 702static int ide_disk_init_media(ide_drive_t *drive, struct gendisk *disk)
734{
735 struct ide_disk_obj *idkp = drive->driver_data;
736 struct gendisk *g = idkp->disk;
737
738 ide_proc_unregister_driver(drive, idkp->driver);
739
740 del_gendisk(g);
741
742 ide_cacheflush_p(drive);
743
744 ide_disk_put(idkp);
745}
746
747static void ide_disk_release(struct kref *kref)
748{
749 struct ide_disk_obj *idkp = to_ide_disk(kref);
750 ide_drive_t *drive = idkp->drive;
751 struct gendisk *g = idkp->disk;
752
753 drive->driver_data = NULL;
754 g->private_data = NULL;
755 put_disk(g);
756 kfree(idkp);
757}
758
759static int ide_disk_probe(ide_drive_t *drive);
760
761/*
762 * On HPA drives the capacity needs to be
763 * reinitilized on resume otherwise the disk
764 * can not be used and a hard reset is required
765 */
766static void ide_disk_resume(ide_drive_t *drive)
767{ 703{
768 if (ata_id_hpa_enabled(drive->id)) 704 return 0;
769 init_idedisk_capacity(drive);
770}
771
772static void ide_device_shutdown(ide_drive_t *drive)
773{
774#ifdef CONFIG_ALPHA
775 /* On Alpha, halt(8) doesn't actually turn the machine off,
776 it puts you into the sort of firmware monitor. Typically,
777 it's used to boot another kernel image, so it's not much
778 different from reboot(8). Therefore, we don't need to
779 spin down the disk in this case, especially since Alpha
780 firmware doesn't handle disks in standby mode properly.
781 On the other hand, it's reasonably safe to turn the power
782 off when the shutdown process reaches the firmware prompt,
783 as the firmware initialization takes rather long time -
784 at least 10 seconds, which should be sufficient for
785 the disk to expire its write cache. */
786 if (system_state != SYSTEM_POWER_OFF) {
787#else
788 if (system_state == SYSTEM_RESTART) {
789#endif
790 ide_cacheflush_p(drive);
791 return;
792 }
793
794 printk(KERN_INFO "Shutdown: %s\n", drive->name);
795
796 drive->gendev.bus->suspend(&drive->gendev, PMSG_SUSPEND);
797} 705}
798 706
799static ide_driver_t idedisk_driver = { 707static int ide_disk_set_doorlock(ide_drive_t *drive, struct gendisk *disk,
800 .gen_driver = { 708 int on)
801 .owner = THIS_MODULE,
802 .name = "ide-disk",
803 .bus = &ide_bus_type,
804 },
805 .probe = ide_disk_probe,
806 .remove = ide_disk_remove,
807 .resume = ide_disk_resume,
808 .shutdown = ide_device_shutdown,
809 .version = IDEDISK_VERSION,
810 .do_request = ide_do_rw_disk,
811 .end_request = ide_end_request,
812 .error = __ide_error,
813#ifdef CONFIG_IDE_PROC_FS
814 .proc = ide_disk_proc,
815 .settings = ide_disk_settings,
816#endif
817};
818
819static int idedisk_set_doorlock(ide_drive_t *drive, int on)
820{ 709{
821 ide_task_t task; 710 ide_task_t task;
711 int ret;
712
713 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) == 0)
714 return 0;
822 715
823 memset(&task, 0, sizeof(task)); 716 memset(&task, 0, sizeof(task));
824 task.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK; 717 task.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK;
825 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 718 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
826 719
827 return ide_no_data_taskfile(drive, &task); 720 ret = ide_no_data_taskfile(drive, &task);
828}
829
830static int idedisk_open(struct inode *inode, struct file *filp)
831{
832 struct gendisk *disk = inode->i_bdev->bd_disk;
833 struct ide_disk_obj *idkp;
834 ide_drive_t *drive;
835
836 idkp = ide_disk_get(disk);
837 if (idkp == NULL)
838 return -ENXIO;
839
840 drive = idkp->drive;
841
842 idkp->openers++;
843
844 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
845 check_disk_change(inode->i_bdev);
846 /*
847 * Ignore the return code from door_lock,
848 * since the open() has already succeeded,
849 * and the door_lock is irrelevant at this point.
850 */
851 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
852 idedisk_set_doorlock(drive, 1))
853 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
854 }
855 return 0;
856}
857
858static int idedisk_release(struct inode *inode, struct file *filp)
859{
860 struct gendisk *disk = inode->i_bdev->bd_disk;
861 struct ide_disk_obj *idkp = ide_disk_g(disk);
862 ide_drive_t *drive = idkp->drive;
863
864 if (idkp->openers == 1)
865 ide_cacheflush_p(drive);
866
867 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
868 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
869 idedisk_set_doorlock(drive, 0))
870 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
871 }
872 721
873 idkp->openers--; 722 if (ret)
723 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
874 724
875 ide_disk_put(idkp); 725 return ret;
876
877 return 0;
878}
879
880static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
881{
882 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
883 ide_drive_t *drive = idkp->drive;
884
885 geo->heads = drive->bios_head;
886 geo->sectors = drive->bios_sect;
887 geo->cylinders = (u16)drive->bios_cyl; /* truncate */
888 return 0;
889} 726}
890 727
891static int idedisk_media_changed(struct gendisk *disk) 728const struct ide_disk_ops ide_ata_disk_ops = {
892{ 729 .check = ide_disk_check,
893 struct ide_disk_obj *idkp = ide_disk_g(disk); 730 .get_capacity = ide_disk_get_capacity,
894 ide_drive_t *drive = idkp->drive; 731 .setup = ide_disk_setup,
895 732 .flush = ide_disk_flush,
896 /* do not scan partitions twice if this is a removable device */ 733 .init_media = ide_disk_init_media,
897 if (drive->dev_flags & IDE_DFLAG_ATTACH) { 734 .set_doorlock = ide_disk_set_doorlock,
898 drive->dev_flags &= ~IDE_DFLAG_ATTACH; 735 .do_request = ide_do_rw_disk,
899 return 0; 736 .end_request = ide_end_request,
900 } 737 .ioctl = ide_disk_ioctl,
901
902 /* if removable, always assume it was changed */
903 return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE);
904}
905
906static int idedisk_revalidate_disk(struct gendisk *disk)
907{
908 struct ide_disk_obj *idkp = ide_disk_g(disk);
909 set_capacity(disk, ide_disk_capacity(idkp->drive));
910 return 0;
911}
912
913static struct block_device_operations idedisk_ops = {
914 .owner = THIS_MODULE,
915 .open = idedisk_open,
916 .release = idedisk_release,
917 .ioctl = ide_disk_ioctl,
918 .getgeo = idedisk_getgeo,
919 .media_changed = idedisk_media_changed,
920 .revalidate_disk = idedisk_revalidate_disk
921}; 738};
922
923MODULE_DESCRIPTION("ATA DISK Driver");
924
925static int ide_disk_probe(ide_drive_t *drive)
926{
927 struct ide_disk_obj *idkp;
928 struct gendisk *g;
929
930 /* strstr("foo", "") is non-NULL */
931 if (!strstr("ide-disk", drive->driver_req))
932 goto failed;
933
934 if (drive->media != ide_disk)
935 goto failed;
936
937 idkp = kzalloc(sizeof(*idkp), GFP_KERNEL);
938 if (!idkp)
939 goto failed;
940
941 g = alloc_disk_node(IDE_DISK_MINORS, hwif_to_node(drive->hwif));
942 if (!g)
943 goto out_free_idkp;
944
945 ide_init_disk(g, drive);
946
947 kref_init(&idkp->kref);
948
949 idkp->drive = drive;
950 idkp->driver = &idedisk_driver;
951 idkp->disk = g;
952
953 g->private_data = &idkp->driver;
954
955 drive->driver_data = idkp;
956
957 idedisk_setup(drive);
958 if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
959 (drive->head == 0 || drive->head > 16)) {
960 printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n",
961 drive->name, drive->head);
962 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
963 } else
964 drive->dev_flags |= IDE_DFLAG_ATTACH;
965
966 g->minors = IDE_DISK_MINORS;
967 g->driverfs_dev = &drive->gendev;
968 g->flags |= GENHD_FL_EXT_DEVT;
969 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
970 g->flags = GENHD_FL_REMOVABLE;
971 set_capacity(g, ide_disk_capacity(drive));
972 g->fops = &idedisk_ops;
973 add_disk(g);
974 return 0;
975
976out_free_idkp:
977 kfree(idkp);
978failed:
979 return -ENODEV;
980}
981
982static void __exit idedisk_exit(void)
983{
984 driver_unregister(&idedisk_driver.gen_driver);
985}
986
987static int __init idedisk_init(void)
988{
989 return driver_register(&idedisk_driver.gen_driver);
990}
991
992MODULE_ALIAS("ide:*m-disk*");
993MODULE_ALIAS("ide-disk");
994module_init(idedisk_init);
995module_exit(idedisk_exit);
996MODULE_LICENSE("GPL");