aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-disk.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/ide/ide-disk.c')
-rw-r--r--drivers/ide/ide-disk.c357
1 files changed, 113 insertions, 244 deletions
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 01846f244b40..3853bde8eedc 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -45,21 +45,12 @@
45#define IDE_DISK_MINORS 0 45#define IDE_DISK_MINORS 0
46#endif 46#endif
47 47
48struct ide_disk_obj { 48#include "ide-disk.h"
49 ide_drive_t *drive;
50 ide_driver_t *driver;
51 struct gendisk *disk;
52 struct kref kref;
53 unsigned int openers; /* protected by BKL for now */
54};
55 49
56static DEFINE_MUTEX(idedisk_ref_mutex); 50static DEFINE_MUTEX(idedisk_ref_mutex);
57 51
58#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref) 52#define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref)
59 53
60#define ide_disk_g(disk) \
61 container_of((disk)->private_data, struct ide_disk_obj, driver)
62
63static void ide_disk_release(struct kref *); 54static void ide_disk_release(struct kref *);
64 55
65static struct ide_disk_obj *ide_disk_get(struct gendisk *disk) 56static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
@@ -140,9 +131,9 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
140 sector_t block) 131 sector_t block)
141{ 132{
142 ide_hwif_t *hwif = HWIF(drive); 133 ide_hwif_t *hwif = HWIF(drive);
143 unsigned int dma = drive->using_dma;
144 u16 nsectors = (u16)rq->nr_sectors; 134 u16 nsectors = (u16)rq->nr_sectors;
145 u8 lba48 = (drive->addressing == 1) ? 1 : 0; 135 u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
136 u8 dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
146 ide_task_t task; 137 ide_task_t task;
147 struct ide_taskfile *tf = &task.tf; 138 struct ide_taskfile *tf = &task.tf;
148 ide_startstop_t rc; 139 ide_startstop_t rc;
@@ -162,7 +153,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
162 memset(&task, 0, sizeof(task)); 153 memset(&task, 0, sizeof(task));
163 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 154 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
164 155
165 if (drive->select.b.lba) { 156 if (drive->dev_flags & IDE_DFLAG_LBA) {
166 if (lba48) { 157 if (lba48) {
167 pr_debug("%s: LBA=0x%012llx\n", drive->name, 158 pr_debug("%s: LBA=0x%012llx\n", drive->name,
168 (unsigned long long)block); 159 (unsigned long long)block);
@@ -187,6 +178,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
187 tf->lbah = block >>= 8; 178 tf->lbah = block >>= 8;
188 tf->device = (block >> 8) & 0xf; 179 tf->device = (block >> 8) & 0xf;
189 } 180 }
181
182 tf->device |= ATA_LBA;
190 } else { 183 } else {
191 unsigned int sect, head, cyl, track; 184 unsigned int sect, head, cyl, track;
192 185
@@ -237,7 +230,7 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
237{ 230{
238 ide_hwif_t *hwif = HWIF(drive); 231 ide_hwif_t *hwif = HWIF(drive);
239 232
240 BUG_ON(drive->blocked); 233 BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
241 234
242 if (!blk_fs_request(rq)) { 235 if (!blk_fs_request(rq)) {
243 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command"); 236 blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command");
@@ -384,139 +377,39 @@ static void idedisk_check_hpa(ide_drive_t *drive)
384static void init_idedisk_capacity(ide_drive_t *drive) 377static void init_idedisk_capacity(ide_drive_t *drive)
385{ 378{
386 u16 *id = drive->id; 379 u16 *id = drive->id;
387 /* 380 int lba;
388 * If this drive supports the Host Protected Area feature set,
389 * then we may need to change our opinion about the drive's capacity.
390 */
391 int hpa = ata_id_hpa_enabled(id);
392 381
393 if (ata_id_lba48_enabled(id)) { 382 if (ata_id_lba48_enabled(id)) {
394 /* drive speaks 48-bit LBA */ 383 /* drive speaks 48-bit LBA */
395 drive->select.b.lba = 1; 384 lba = 1;
396 drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2); 385 drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
397 if (hpa)
398 idedisk_check_hpa(drive);
399 } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) { 386 } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) {
400 /* drive speaks 28-bit LBA */ 387 /* drive speaks 28-bit LBA */
401 drive->select.b.lba = 1; 388 lba = 1;
402 drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY); 389 drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
403 if (hpa)
404 idedisk_check_hpa(drive);
405 } else { 390 } else {
406 /* drive speaks boring old 28-bit CHS */ 391 /* drive speaks boring old 28-bit CHS */
392 lba = 0;
407 drive->capacity64 = drive->cyl * drive->head * drive->sect; 393 drive->capacity64 = drive->cyl * drive->head * drive->sect;
408 } 394 }
409}
410 395
411static sector_t idedisk_capacity(ide_drive_t *drive) 396 if (lba) {
412{ 397 drive->dev_flags |= IDE_DFLAG_LBA;
413 return drive->capacity64;
414}
415 398
416#ifdef CONFIG_IDE_PROC_FS 399 /*
417static int smart_enable(ide_drive_t *drive) 400 * If this device supports the Host Protected Area feature set,
418{ 401 * then we may need to change our opinion about its capacity.
419 ide_task_t args; 402 */
420 struct ide_taskfile *tf = &args.tf; 403 if (ata_id_hpa_enabled(id))
421 404 idedisk_check_hpa(drive);
422 memset(&args, 0, sizeof(ide_task_t));
423 tf->feature = ATA_SMART_ENABLE;
424 tf->lbam = ATA_SMART_LBAM_PASS;
425 tf->lbah = ATA_SMART_LBAH_PASS;
426 tf->command = ATA_CMD_SMART;
427 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
428 return ide_no_data_taskfile(drive, &args);
429}
430
431static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
432{
433 ide_task_t args;
434 struct ide_taskfile *tf = &args.tf;
435
436 memset(&args, 0, sizeof(ide_task_t));
437 tf->feature = sub_cmd;
438 tf->nsect = 0x01;
439 tf->lbam = ATA_SMART_LBAM_PASS;
440 tf->lbah = ATA_SMART_LBAH_PASS;
441 tf->command = ATA_CMD_SMART;
442 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
443 args.data_phase = TASKFILE_IN;
444 (void) smart_enable(drive);
445 return ide_raw_taskfile(drive, &args, buf, 1);
446}
447
448static int proc_idedisk_read_cache
449 (char *page, char **start, off_t off, int count, int *eof, void *data)
450{
451 ide_drive_t *drive = (ide_drive_t *) data;
452 char *out = page;
453 int len;
454
455 if (drive->id_read)
456 len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
457 else
458 len = sprintf(out, "(none)\n");
459
460 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
461}
462
463static int proc_idedisk_read_capacity
464 (char *page, char **start, off_t off, int count, int *eof, void *data)
465{
466 ide_drive_t*drive = (ide_drive_t *)data;
467 int len;
468
469 len = sprintf(page, "%llu\n", (long long)idedisk_capacity(drive));
470
471 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
472}
473
474static int proc_idedisk_read_smart(char *page, char **start, off_t off,
475 int count, int *eof, void *data, u8 sub_cmd)
476{
477 ide_drive_t *drive = (ide_drive_t *)data;
478 int len = 0, i = 0;
479
480 if (get_smart_data(drive, page, sub_cmd) == 0) {
481 unsigned short *val = (unsigned short *) page;
482 char *out = (char *)val + SECTOR_SIZE;
483
484 page = out;
485 do {
486 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
487 (++i & 7) ? ' ' : '\n');
488 val += 1;
489 } while (i < SECTOR_SIZE / 2);
490 len = out - page;
491 } 405 }
492
493 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
494} 406}
495 407
496static int proc_idedisk_read_sv 408sector_t ide_disk_capacity(ide_drive_t *drive)
497 (char *page, char **start, off_t off, int count, int *eof, void *data)
498{ 409{
499 return proc_idedisk_read_smart(page, start, off, count, eof, data, 410 return drive->capacity64;
500 ATA_SMART_READ_VALUES);
501}
502
503static int proc_idedisk_read_st
504 (char *page, char **start, off_t off, int count, int *eof, void *data)
505{
506 return proc_idedisk_read_smart(page, start, off, count, eof, data,
507 ATA_SMART_READ_THRESHOLDS);
508} 411}
509 412
510static ide_proc_entry_t idedisk_proc[] = {
511 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL },
512 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
513 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
514 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL },
515 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL },
516 { NULL, 0, NULL, NULL }
517};
518#endif /* CONFIG_IDE_PROC_FS */
519
520static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) 413static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
521{ 414{
522 ide_drive_t *drive = q->queuedata; 415 ide_drive_t *drive = q->queuedata;
@@ -568,25 +461,43 @@ static int set_multcount(ide_drive_t *drive, int arg)
568 return (drive->mult_count == arg) ? 0 : -EIO; 461 return (drive->mult_count == arg) ? 0 : -EIO;
569} 462}
570 463
571ide_devset_get(nowerr, nowerr); 464ide_devset_get_flag(nowerr, IDE_DFLAG_NOWERR);
572 465
573static int set_nowerr(ide_drive_t *drive, int arg) 466static int set_nowerr(ide_drive_t *drive, int arg)
574{ 467{
575 if (arg < 0 || arg > 1) 468 if (arg < 0 || arg > 1)
576 return -EINVAL; 469 return -EINVAL;
577 470
578 drive->nowerr = arg; 471 if (arg)
472 drive->dev_flags |= IDE_DFLAG_NOWERR;
473 else
474 drive->dev_flags &= ~IDE_DFLAG_NOWERR;
475
579 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT; 476 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
477
580 return 0; 478 return 0;
581} 479}
582 480
481static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect)
482{
483 ide_task_t task;
484
485 memset(&task, 0, sizeof(task));
486 task.tf.feature = feature;
487 task.tf.nsect = nsect;
488 task.tf.command = ATA_CMD_SET_FEATURES;
489 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
490
491 return ide_no_data_taskfile(drive, &task);
492}
493
583static void update_ordered(ide_drive_t *drive) 494static void update_ordered(ide_drive_t *drive)
584{ 495{
585 u16 *id = drive->id; 496 u16 *id = drive->id;
586 unsigned ordered = QUEUE_ORDERED_NONE; 497 unsigned ordered = QUEUE_ORDERED_NONE;
587 prepare_flush_fn *prep_fn = NULL; 498 prepare_flush_fn *prep_fn = NULL;
588 499
589 if (drive->wcache) { 500 if (drive->dev_flags & IDE_DFLAG_WCACHE) {
590 unsigned long long capacity; 501 unsigned long long capacity;
591 int barrier; 502 int barrier;
592 /* 503 /*
@@ -597,9 +508,11 @@ static void update_ordered(ide_drive_t *drive)
597 * time we have trimmed the drive capacity if LBA48 is 508 * time we have trimmed the drive capacity if LBA48 is
598 * not available so we don't need to recheck that. 509 * not available so we don't need to recheck that.
599 */ 510 */
600 capacity = idedisk_capacity(drive); 511 capacity = ide_disk_capacity(drive);
601 barrier = ata_id_flush_enabled(id) && !drive->noflush && 512 barrier = ata_id_flush_enabled(id) &&
602 (drive->addressing == 0 || capacity <= (1ULL << 28) || 513 (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 &&
514 ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 ||
515 capacity <= (1ULL << 28) ||
603 ata_id_flush_ext_enabled(id)); 516 ata_id_flush_ext_enabled(id));
604 517
605 printk(KERN_INFO "%s: cache flushes %ssupported\n", 518 printk(KERN_INFO "%s: cache flushes %ssupported\n",
@@ -615,25 +528,24 @@ static void update_ordered(ide_drive_t *drive)
615 blk_queue_ordered(drive->queue, ordered, prep_fn); 528 blk_queue_ordered(drive->queue, ordered, prep_fn);
616} 529}
617 530
618ide_devset_get(wcache, wcache); 531ide_devset_get_flag(wcache, IDE_DFLAG_WCACHE);
619 532
620static int set_wcache(ide_drive_t *drive, int arg) 533static int set_wcache(ide_drive_t *drive, int arg)
621{ 534{
622 ide_task_t args;
623 int err = 1; 535 int err = 1;
624 536
625 if (arg < 0 || arg > 1) 537 if (arg < 0 || arg > 1)
626 return -EINVAL; 538 return -EINVAL;
627 539
628 if (ata_id_flush_enabled(drive->id)) { 540 if (ata_id_flush_enabled(drive->id)) {
629 memset(&args, 0, sizeof(ide_task_t)); 541 err = ide_do_setfeature(drive,
630 args.tf.feature = arg ? 542 arg ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF, 0);
631 SETFEATURES_WC_ON : SETFEATURES_WC_OFF; 543 if (err == 0) {
632 args.tf.command = ATA_CMD_SET_FEATURES; 544 if (arg)
633 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 545 drive->dev_flags |= IDE_DFLAG_WCACHE;
634 err = ide_no_data_taskfile(drive, &args); 546 else
635 if (err == 0) 547 drive->dev_flags &= ~IDE_DFLAG_WCACHE;
636 drive->wcache = arg; 548 }
637 } 549 }
638 550
639 update_ordered(drive); 551 update_ordered(drive);
@@ -658,22 +570,18 @@ ide_devset_get(acoustic, acoustic);
658 570
659static int set_acoustic(ide_drive_t *drive, int arg) 571static int set_acoustic(ide_drive_t *drive, int arg)
660{ 572{
661 ide_task_t args;
662
663 if (arg < 0 || arg > 254) 573 if (arg < 0 || arg > 254)
664 return -EINVAL; 574 return -EINVAL;
665 575
666 memset(&args, 0, sizeof(ide_task_t)); 576 ide_do_setfeature(drive,
667 args.tf.feature = arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF; 577 arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF, arg);
668 args.tf.nsect = arg; 578
669 args.tf.command = ATA_CMD_SET_FEATURES;
670 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
671 ide_no_data_taskfile(drive, &args);
672 drive->acoustic = arg; 579 drive->acoustic = arg;
580
673 return 0; 581 return 0;
674} 582}
675 583
676ide_devset_get(addressing, addressing); 584ide_devset_get_flag(addressing, IDE_DFLAG_LBA48);
677 585
678/* 586/*
679 * drive->addressing: 587 * drive->addressing:
@@ -686,49 +594,27 @@ static int set_addressing(ide_drive_t *drive, int arg)
686 if (arg < 0 || arg > 2) 594 if (arg < 0 || arg > 2)
687 return -EINVAL; 595 return -EINVAL;
688 596
689 drive->addressing = 0; 597 if (arg && ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
690 598 ata_id_lba48_enabled(drive->id) == 0))
691 if (drive->hwif->host_flags & IDE_HFLAG_NO_LBA48)
692 return 0;
693
694 if (ata_id_lba48_enabled(drive->id) == 0)
695 return -EIO; 599 return -EIO;
696 600
697 drive->addressing = arg; 601 if (arg == 2)
602 arg = 0;
603
604 if (arg)
605 drive->dev_flags |= IDE_DFLAG_LBA48;
606 else
607 drive->dev_flags &= ~IDE_DFLAG_LBA48;
698 608
699 return 0; 609 return 0;
700} 610}
701 611
702ide_devset_rw(acoustic, acoustic); 612ide_ext_devset_rw(acoustic, acoustic);
703ide_devset_rw(address, addressing); 613ide_ext_devset_rw(address, addressing);
704ide_devset_rw(multcount, multcount); 614ide_ext_devset_rw(multcount, multcount);
705ide_devset_rw(wcache, wcache); 615ide_ext_devset_rw(wcache, wcache);
706
707ide_devset_rw_sync(nowerr, nowerr);
708 616
709#ifdef CONFIG_IDE_PROC_FS 617ide_ext_devset_rw_sync(nowerr, nowerr);
710ide_devset_rw_field(bios_cyl, bios_cyl);
711ide_devset_rw_field(bios_head, bios_head);
712ide_devset_rw_field(bios_sect, bios_sect);
713ide_devset_rw_field(failures, failures);
714ide_devset_rw_field(lun, lun);
715ide_devset_rw_field(max_failures, max_failures);
716
717static const struct ide_proc_devset idedisk_settings[] = {
718 IDE_PROC_DEVSET(acoustic, 0, 254),
719 IDE_PROC_DEVSET(address, 0, 2),
720 IDE_PROC_DEVSET(bios_cyl, 0, 65535),
721 IDE_PROC_DEVSET(bios_head, 0, 255),
722 IDE_PROC_DEVSET(bios_sect, 0, 63),
723 IDE_PROC_DEVSET(failures, 0, 65535),
724 IDE_PROC_DEVSET(lun, 0, 7),
725 IDE_PROC_DEVSET(max_failures, 0, 65535),
726 IDE_PROC_DEVSET(multcount, 0, 16),
727 IDE_PROC_DEVSET(nowerr, 0, 1),
728 IDE_PROC_DEVSET(wcache, 0, 1),
729 { 0 },
730};
731#endif
732 618
733static void idedisk_setup(ide_drive_t *drive) 619static void idedisk_setup(ide_drive_t *drive)
734{ 620{
@@ -740,20 +626,20 @@ static void idedisk_setup(ide_drive_t *drive)
740 626
741 ide_proc_register_driver(drive, idkp->driver); 627 ide_proc_register_driver(drive, idkp->driver);
742 628
743 if (drive->id_read == 0) 629 if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0)
744 return; 630 return;
745 631
746 if (drive->removable) { 632 if (drive->dev_flags & IDE_DFLAG_REMOVABLE) {
747 /* 633 /*
748 * Removable disks (eg. SYQUEST); ignore 'WD' drives 634 * Removable disks (eg. SYQUEST); ignore 'WD' drives
749 */ 635 */
750 if (m[0] != 'W' || m[1] != 'D') 636 if (m[0] != 'W' || m[1] != 'D')
751 drive->doorlocking = 1; 637 drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
752 } 638 }
753 639
754 (void)set_addressing(drive, 1); 640 (void)set_addressing(drive, 1);
755 641
756 if (drive->addressing == 1) { 642 if (drive->dev_flags & IDE_DFLAG_LBA48) {
757 int max_s = 2048; 643 int max_s = 2048;
758 644
759 if (max_s > hwif->rqsize) 645 if (max_s > hwif->rqsize)
@@ -769,7 +655,8 @@ static void idedisk_setup(ide_drive_t *drive)
769 init_idedisk_capacity(drive); 655 init_idedisk_capacity(drive);
770 656
771 /* limit drive capacity to 137GB if LBA48 cannot be used */ 657 /* limit drive capacity to 137GB if LBA48 cannot be used */
772 if (drive->addressing == 0 && drive->capacity64 > 1ULL << 28) { 658 if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
659 drive->capacity64 > 1ULL << 28) {
773 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity " 660 printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
774 "%llu sectors (%llu MB)\n", 661 "%llu sectors (%llu MB)\n",
775 drive->name, (unsigned long long)drive->capacity64, 662 drive->name, (unsigned long long)drive->capacity64,
@@ -777,22 +664,23 @@ static void idedisk_setup(ide_drive_t *drive)
777 drive->capacity64 = 1ULL << 28; 664 drive->capacity64 = 1ULL << 28;
778 } 665 }
779 666
780 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && drive->addressing) { 667 if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
668 (drive->dev_flags & IDE_DFLAG_LBA48)) {
781 if (drive->capacity64 > 1ULL << 28) { 669 if (drive->capacity64 > 1ULL << 28) {
782 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode" 670 printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
783 " will be used for accessing sectors " 671 " will be used for accessing sectors "
784 "> %u\n", drive->name, 1 << 28); 672 "> %u\n", drive->name, 1 << 28);
785 } else 673 } else
786 drive->addressing = 0; 674 drive->dev_flags &= ~IDE_DFLAG_LBA48;
787 } 675 }
788 676
789 /* 677 /*
790 * if possible, give fdisk access to more of the drive, 678 * if possible, give fdisk access to more of the drive,
791 * by correcting bios_cyls: 679 * by correcting bios_cyls:
792 */ 680 */
793 capacity = idedisk_capacity(drive); 681 capacity = ide_disk_capacity(drive);
794 682
795 if (!drive->forced_geom) { 683 if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) {
796 if (ata_id_lba48_enabled(drive->id)) { 684 if (ata_id_lba48_enabled(drive->id)) {
797 /* compatibility */ 685 /* compatibility */
798 drive->bios_sect = 63; 686 drive->bios_sect = 63;
@@ -827,14 +715,15 @@ static void idedisk_setup(ide_drive_t *drive)
827 715
828 /* write cache enabled? */ 716 /* write cache enabled? */
829 if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id)) 717 if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id))
830 drive->wcache = 1; 718 drive->dev_flags |= IDE_DFLAG_WCACHE;
831 719
832 set_wcache(drive, 1); 720 set_wcache(drive, 1);
833} 721}
834 722
835static void ide_cacheflush_p(ide_drive_t *drive) 723static void ide_cacheflush_p(ide_drive_t *drive)
836{ 724{
837 if (!drive->wcache || ata_id_flush_enabled(drive->id) == 0) 725 if (ata_id_flush_enabled(drive->id) == 0 ||
726 (drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
838 return; 727 return;
839 728
840 if (do_idedisk_flushcache(drive)) 729 if (do_idedisk_flushcache(drive))
@@ -918,13 +807,12 @@ static ide_driver_t idedisk_driver = {
918 .resume = ide_disk_resume, 807 .resume = ide_disk_resume,
919 .shutdown = ide_device_shutdown, 808 .shutdown = ide_device_shutdown,
920 .version = IDEDISK_VERSION, 809 .version = IDEDISK_VERSION,
921 .media = ide_disk,
922 .do_request = ide_do_rw_disk, 810 .do_request = ide_do_rw_disk,
923 .end_request = ide_end_request, 811 .end_request = ide_end_request,
924 .error = __ide_error, 812 .error = __ide_error,
925#ifdef CONFIG_IDE_PROC_FS 813#ifdef CONFIG_IDE_PROC_FS
926 .proc = idedisk_proc, 814 .proc = ide_disk_proc,
927 .settings = idedisk_settings, 815 .settings = ide_disk_settings,
928#endif 816#endif
929}; 817};
930 818
@@ -953,15 +841,16 @@ static int idedisk_open(struct inode *inode, struct file *filp)
953 841
954 idkp->openers++; 842 idkp->openers++;
955 843
956 if (drive->removable && idkp->openers == 1) { 844 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
957 check_disk_change(inode->i_bdev); 845 check_disk_change(inode->i_bdev);
958 /* 846 /*
959 * Ignore the return code from door_lock, 847 * Ignore the return code from door_lock,
960 * since the open() has already succeeded, 848 * since the open() has already succeeded,
961 * and the door_lock is irrelevant at this point. 849 * and the door_lock is irrelevant at this point.
962 */ 850 */
963 if (drive->doorlocking && idedisk_set_doorlock(drive, 1)) 851 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
964 drive->doorlocking = 0; 852 idedisk_set_doorlock(drive, 1))
853 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
965 } 854 }
966 return 0; 855 return 0;
967} 856}
@@ -975,9 +864,10 @@ static int idedisk_release(struct inode *inode, struct file *filp)
975 if (idkp->openers == 1) 864 if (idkp->openers == 1)
976 ide_cacheflush_p(drive); 865 ide_cacheflush_p(drive);
977 866
978 if (drive->removable && idkp->openers == 1) { 867 if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
979 if (drive->doorlocking && idedisk_set_doorlock(drive, 0)) 868 if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
980 drive->doorlocking = 0; 869 idedisk_set_doorlock(drive, 0))
870 drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
981 } 871 }
982 872
983 idkp->openers--; 873 idkp->openers--;
@@ -998,48 +888,25 @@ static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
998 return 0; 888 return 0;
999} 889}
1000 890
1001static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
1002{ HDIO_GET_ADDRESS, HDIO_SET_ADDRESS, &ide_devset_address },
1003{ HDIO_GET_MULTCOUNT, HDIO_SET_MULTCOUNT, &ide_devset_multcount },
1004{ HDIO_GET_NOWERR, HDIO_SET_NOWERR, &ide_devset_nowerr },
1005{ HDIO_GET_WCACHE, HDIO_SET_WCACHE, &ide_devset_wcache },
1006{ HDIO_GET_ACOUSTIC, HDIO_SET_ACOUSTIC, &ide_devset_acoustic },
1007{ 0 }
1008};
1009
1010static int idedisk_ioctl(struct inode *inode, struct file *file,
1011 unsigned int cmd, unsigned long arg)
1012{
1013 struct block_device *bdev = inode->i_bdev;
1014 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
1015 ide_drive_t *drive = idkp->drive;
1016 int err;
1017
1018 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
1019 if (err != -EOPNOTSUPP)
1020 return err;
1021
1022 return generic_ide_ioctl(drive, file, bdev, cmd, arg);
1023}
1024
1025static int idedisk_media_changed(struct gendisk *disk) 891static int idedisk_media_changed(struct gendisk *disk)
1026{ 892{
1027 struct ide_disk_obj *idkp = ide_disk_g(disk); 893 struct ide_disk_obj *idkp = ide_disk_g(disk);
1028 ide_drive_t *drive = idkp->drive; 894 ide_drive_t *drive = idkp->drive;
1029 895
1030 /* do not scan partitions twice if this is a removable device */ 896 /* do not scan partitions twice if this is a removable device */
1031 if (drive->attach) { 897 if (drive->dev_flags & IDE_DFLAG_ATTACH) {
1032 drive->attach = 0; 898 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
1033 return 0; 899 return 0;
1034 } 900 }
901
1035 /* if removable, always assume it was changed */ 902 /* if removable, always assume it was changed */
1036 return drive->removable; 903 return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE);
1037} 904}
1038 905
1039static int idedisk_revalidate_disk(struct gendisk *disk) 906static int idedisk_revalidate_disk(struct gendisk *disk)
1040{ 907{
1041 struct ide_disk_obj *idkp = ide_disk_g(disk); 908 struct ide_disk_obj *idkp = ide_disk_g(disk);
1042 set_capacity(disk, idedisk_capacity(idkp->drive)); 909 set_capacity(disk, ide_disk_capacity(idkp->drive));
1043 return 0; 910 return 0;
1044} 911}
1045 912
@@ -1047,7 +914,7 @@ static struct block_device_operations idedisk_ops = {
1047 .owner = THIS_MODULE, 914 .owner = THIS_MODULE,
1048 .open = idedisk_open, 915 .open = idedisk_open,
1049 .release = idedisk_release, 916 .release = idedisk_release,
1050 .ioctl = idedisk_ioctl, 917 .ioctl = ide_disk_ioctl,
1051 .getgeo = idedisk_getgeo, 918 .getgeo = idedisk_getgeo,
1052 .media_changed = idedisk_media_changed, 919 .media_changed = idedisk_media_changed,
1053 .revalidate_disk = idedisk_revalidate_disk 920 .revalidate_disk = idedisk_revalidate_disk
@@ -1088,19 +955,20 @@ static int ide_disk_probe(ide_drive_t *drive)
1088 drive->driver_data = idkp; 955 drive->driver_data = idkp;
1089 956
1090 idedisk_setup(drive); 957 idedisk_setup(drive);
1091 if ((!drive->head || drive->head > 16) && !drive->select.b.lba) { 958 if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
959 (drive->head == 0 || drive->head > 16)) {
1092 printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n", 960 printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n",
1093 drive->name, drive->head); 961 drive->name, drive->head);
1094 drive->attach = 0; 962 drive->dev_flags &= ~IDE_DFLAG_ATTACH;
1095 } else 963 } else
1096 drive->attach = 1; 964 drive->dev_flags |= IDE_DFLAG_ATTACH;
1097 965
1098 g->minors = IDE_DISK_MINORS; 966 g->minors = IDE_DISK_MINORS;
1099 g->driverfs_dev = &drive->gendev; 967 g->driverfs_dev = &drive->gendev;
1100 g->flags |= GENHD_FL_EXT_DEVT; 968 g->flags |= GENHD_FL_EXT_DEVT;
1101 if (drive->removable) 969 if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
1102 g->flags |= GENHD_FL_REMOVABLE; 970 g->flags = GENHD_FL_REMOVABLE;
1103 set_capacity(g, idedisk_capacity(drive)); 971 set_capacity(g, ide_disk_capacity(drive));
1104 g->fops = &idedisk_ops; 972 g->fops = &idedisk_ops;
1105 add_disk(g); 973 add_disk(g);
1106 return 0; 974 return 0;
@@ -1122,6 +990,7 @@ static int __init idedisk_init(void)
1122} 990}
1123 991
1124MODULE_ALIAS("ide:*m-disk*"); 992MODULE_ALIAS("ide:*m-disk*");
993MODULE_ALIAS("ide-disk");
1125module_init(idedisk_init); 994module_init(idedisk_init);
1126module_exit(idedisk_exit); 995module_exit(idedisk_exit);
1127MODULE_LICENSE("GPL"); 996MODULE_LICENSE("GPL");