aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/ide/ide-disk.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2008-10-11 16:22:33 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2008-10-11 16:22:33 -0400
commit5c3c4d9b5810c9aabd8c05219c62ca088aa83eb0 (patch)
treef1122247e0b6d6269588702738df9c46061e280d /drivers/ide/ide-disk.c
parentead9d23d803ea3a73766c3cb27bf7563ac8d7266 (diff)
parent92f1f8fd8040e7b50a67a850a935509bb01201bb (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: (71 commits) ide: Remove ide_spin_wait_hwgroup() and use special requests instead ide: move IDE{FLOPPY,TAPE}_WAIT_CMD defines to <linux/ide.h> ide: add ide_do_test_unit_ready() helper ide: add ide_do_start_stop() helper ide: add ide_set_media_lock() helper ide-floppy: move floppy ioctls handling to ide-floppy_ioctl.c ide-floppy: ->{srfp,wp} -> IDE_AFLAG_{SRFP,WP} ide: add ide_queue_pc_tail() helper ide: add ide_queue_pc_head() helper ide: add ide_init_pc() helper ide-tape: add ide_tape_set_media_lock() helper ide-floppy: add ide_floppy_set_media_lock() helper ide: add ide_io_buffers() helper ide-scsi: cleanup ide_scsi_io_buffers() ide-floppy: remove MODE_SENSE_* defines ide-{floppy,tape}: remove packet command stack ide-{floppy,tape}: remove request stack ide-generic: handle probing of legacy io-ports v5 ide-floppy: use scatterlists for pio transfers ide-tape: remove idetape_init_rq() ...
Diffstat (limited to 'drivers/ide/ide-disk.c')
-rw-r--r--drivers/ide/ide-disk.c340
1 files changed, 126 insertions, 214 deletions
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c
index 33ea8c048717..01846f244b40 100644
--- a/drivers/ide/ide-disk.c
+++ b/drivers/ide/ide-disk.c
@@ -30,10 +30,8 @@
30#include <linux/delay.h> 30#include <linux/delay.h>
31#include <linux/mutex.h> 31#include <linux/mutex.h>
32#include <linux/leds.h> 32#include <linux/leds.h>
33
34#define _IDE_DISK
35
36#include <linux/ide.h> 33#include <linux/ide.h>
34#include <linux/hdreg.h>
37 35
38#include <asm/byteorder.h> 36#include <asm/byteorder.h>
39#include <asm/irq.h> 37#include <asm/irq.h>
@@ -90,68 +88,19 @@ static void ide_disk_put(struct ide_disk_obj *idkp)
90 mutex_unlock(&idedisk_ref_mutex); 88 mutex_unlock(&idedisk_ref_mutex);
91} 89}
92 90
93/*
94 * lba_capacity_is_ok() performs a sanity check on the claimed "lba_capacity"
95 * value for this drive (from its reported identification information).
96 *
97 * Returns: 1 if lba_capacity looks sensible
98 * 0 otherwise
99 *
100 * It is called only once for each drive.
101 */
102static int lba_capacity_is_ok(struct hd_driveid *id)
103{
104 unsigned long lba_sects, chs_sects, head, tail;
105
106 /* No non-LBA info .. so valid! */
107 if (id->cyls == 0)
108 return 1;
109
110 /*
111 * The ATA spec tells large drives to return
112 * C/H/S = 16383/16/63 independent of their size.
113 * Some drives can be jumpered to use 15 heads instead of 16.
114 * Some drives can be jumpered to use 4092 cyls instead of 16383.
115 */
116 if ((id->cyls == 16383
117 || (id->cyls == 4092 && id->cur_cyls == 16383)) &&
118 id->sectors == 63 &&
119 (id->heads == 15 || id->heads == 16) &&
120 (id->lba_capacity >= 16383*63*id->heads))
121 return 1;
122
123 lba_sects = id->lba_capacity;
124 chs_sects = id->cyls * id->heads * id->sectors;
125
126 /* perform a rough sanity check on lba_sects: within 10% is OK */
127 if ((lba_sects - chs_sects) < chs_sects/10)
128 return 1;
129
130 /* some drives have the word order reversed */
131 head = ((lba_sects >> 16) & 0xffff);
132 tail = (lba_sects & 0xffff);
133 lba_sects = (head | (tail << 16));
134 if ((lba_sects - chs_sects) < chs_sects/10) {
135 id->lba_capacity = lba_sects;
136 return 1; /* lba_capacity is (now) good */
137 }
138
139 return 0; /* lba_capacity value may be bad */
140}
141
142static const u8 ide_rw_cmds[] = { 91static const u8 ide_rw_cmds[] = {
143 WIN_MULTREAD, 92 ATA_CMD_READ_MULTI,
144 WIN_MULTWRITE, 93 ATA_CMD_WRITE_MULTI,
145 WIN_MULTREAD_EXT, 94 ATA_CMD_READ_MULTI_EXT,
146 WIN_MULTWRITE_EXT, 95 ATA_CMD_WRITE_MULTI_EXT,
147 WIN_READ, 96 ATA_CMD_PIO_READ,
148 WIN_WRITE, 97 ATA_CMD_PIO_WRITE,
149 WIN_READ_EXT, 98 ATA_CMD_PIO_READ_EXT,
150 WIN_WRITE_EXT, 99 ATA_CMD_PIO_WRITE_EXT,
151 WIN_READDMA, 100 ATA_CMD_READ,
152 WIN_WRITEDMA, 101 ATA_CMD_WRITE,
153 WIN_READDMA_EXT, 102 ATA_CMD_READ_EXT,
154 WIN_WRITEDMA_EXT, 103 ATA_CMD_WRITE_EXT,
155}; 104};
156 105
157static const u8 ide_data_phases[] = { 106static const u8 ide_data_phases[] = {
@@ -322,9 +271,9 @@ static u64 idedisk_read_native_max_address(ide_drive_t *drive, int lba48)
322 /* Create IDE/ATA command request structure */ 271 /* Create IDE/ATA command request structure */
323 memset(&args, 0, sizeof(ide_task_t)); 272 memset(&args, 0, sizeof(ide_task_t));
324 if (lba48) 273 if (lba48)
325 tf->command = WIN_READ_NATIVE_MAX_EXT; 274 tf->command = ATA_CMD_READ_NATIVE_MAX_EXT;
326 else 275 else
327 tf->command = WIN_READ_NATIVE_MAX; 276 tf->command = ATA_CMD_READ_NATIVE_MAX;
328 tf->device = ATA_LBA; 277 tf->device = ATA_LBA;
329 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 278 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
330 if (lba48) 279 if (lba48)
@@ -359,10 +308,10 @@ static u64 idedisk_set_max_address(ide_drive_t *drive, u64 addr_req, int lba48)
359 tf->hob_lbal = (addr_req >>= 8) & 0xff; 308 tf->hob_lbal = (addr_req >>= 8) & 0xff;
360 tf->hob_lbam = (addr_req >>= 8) & 0xff; 309 tf->hob_lbam = (addr_req >>= 8) & 0xff;
361 tf->hob_lbah = (addr_req >>= 8) & 0xff; 310 tf->hob_lbah = (addr_req >>= 8) & 0xff;
362 tf->command = WIN_SET_MAX_EXT; 311 tf->command = ATA_CMD_SET_MAX_EXT;
363 } else { 312 } else {
364 tf->device = (addr_req >>= 8) & 0x0f; 313 tf->device = (addr_req >>= 8) & 0x0f;
365 tf->command = WIN_SET_MAX; 314 tf->command = ATA_CMD_SET_MAX;
366 } 315 }
367 tf->device |= ATA_LBA; 316 tf->device |= ATA_LBA;
368 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 317 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
@@ -385,25 +334,6 @@ static unsigned long long sectors_to_MB(unsigned long long n)
385} 334}
386 335
387/* 336/*
388 * Bits 10 of command_set_1 and cfs_enable_1 must be equal,
389 * so on non-buggy drives we need test only one.
390 * However, we should also check whether these fields are valid.
391 */
392static inline int idedisk_supports_hpa(const struct hd_driveid *id)
393{
394 return (id->command_set_1 & 0x0400) && (id->cfs_enable_1 & 0x0400);
395}
396
397/*
398 * The same here.
399 */
400static inline int idedisk_supports_lba48(const struct hd_driveid *id)
401{
402 return (id->command_set_2 & 0x0400) && (id->cfs_enable_2 & 0x0400)
403 && id->lba_capacity_2;
404}
405
406/*
407 * Some disks report total number of sectors instead of 337 * Some disks report total number of sectors instead of
408 * maximum sector address. We list them here. 338 * maximum sector address. We list them here.
409 */ 339 */
@@ -417,7 +347,7 @@ static const struct drive_list_entry hpa_list[] = {
417static void idedisk_check_hpa(ide_drive_t *drive) 347static void idedisk_check_hpa(ide_drive_t *drive)
418{ 348{
419 unsigned long long capacity, set_max; 349 unsigned long long capacity, set_max;
420 int lba48 = idedisk_supports_lba48(drive->id); 350 int lba48 = ata_id_lba48_enabled(drive->id);
421 351
422 capacity = drive->capacity64; 352 capacity = drive->capacity64;
423 353
@@ -453,23 +383,23 @@ static void idedisk_check_hpa(ide_drive_t *drive)
453 383
454static void init_idedisk_capacity(ide_drive_t *drive) 384static void init_idedisk_capacity(ide_drive_t *drive)
455{ 385{
456 struct hd_driveid *id = drive->id; 386 u16 *id = drive->id;
457 /* 387 /*
458 * If this drive supports the Host Protected Area feature set, 388 * If this drive supports the Host Protected Area feature set,
459 * then we may need to change our opinion about the drive's capacity. 389 * then we may need to change our opinion about the drive's capacity.
460 */ 390 */
461 int hpa = idedisk_supports_hpa(id); 391 int hpa = ata_id_hpa_enabled(id);
462 392
463 if (idedisk_supports_lba48(id)) { 393 if (ata_id_lba48_enabled(id)) {
464 /* drive speaks 48-bit LBA */ 394 /* drive speaks 48-bit LBA */
465 drive->select.b.lba = 1; 395 drive->select.b.lba = 1;
466 drive->capacity64 = id->lba_capacity_2; 396 drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
467 if (hpa) 397 if (hpa)
468 idedisk_check_hpa(drive); 398 idedisk_check_hpa(drive);
469 } else if ((id->capability & 2) && lba_capacity_is_ok(id)) { 399 } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) {
470 /* drive speaks 28-bit LBA */ 400 /* drive speaks 28-bit LBA */
471 drive->select.b.lba = 1; 401 drive->select.b.lba = 1;
472 drive->capacity64 = id->lba_capacity; 402 drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
473 if (hpa) 403 if (hpa)
474 idedisk_check_hpa(drive); 404 idedisk_check_hpa(drive);
475 } else { 405 } else {
@@ -480,7 +410,7 @@ static void init_idedisk_capacity(ide_drive_t *drive)
480 410
481static sector_t idedisk_capacity(ide_drive_t *drive) 411static sector_t idedisk_capacity(ide_drive_t *drive)
482{ 412{
483 return drive->capacity64 - drive->sect0; 413 return drive->capacity64;
484} 414}
485 415
486#ifdef CONFIG_IDE_PROC_FS 416#ifdef CONFIG_IDE_PROC_FS
@@ -490,10 +420,10 @@ static int smart_enable(ide_drive_t *drive)
490 struct ide_taskfile *tf = &args.tf; 420 struct ide_taskfile *tf = &args.tf;
491 421
492 memset(&args, 0, sizeof(ide_task_t)); 422 memset(&args, 0, sizeof(ide_task_t));
493 tf->feature = SMART_ENABLE; 423 tf->feature = ATA_SMART_ENABLE;
494 tf->lbam = SMART_LCYL_PASS; 424 tf->lbam = ATA_SMART_LBAM_PASS;
495 tf->lbah = SMART_HCYL_PASS; 425 tf->lbah = ATA_SMART_LBAH_PASS;
496 tf->command = WIN_SMART; 426 tf->command = ATA_CMD_SMART;
497 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 427 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
498 return ide_no_data_taskfile(drive, &args); 428 return ide_no_data_taskfile(drive, &args);
499} 429}
@@ -506,9 +436,9 @@ static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
506 memset(&args, 0, sizeof(ide_task_t)); 436 memset(&args, 0, sizeof(ide_task_t));
507 tf->feature = sub_cmd; 437 tf->feature = sub_cmd;
508 tf->nsect = 0x01; 438 tf->nsect = 0x01;
509 tf->lbam = SMART_LCYL_PASS; 439 tf->lbam = ATA_SMART_LBAM_PASS;
510 tf->lbah = SMART_HCYL_PASS; 440 tf->lbah = ATA_SMART_LBAH_PASS;
511 tf->command = WIN_SMART; 441 tf->command = ATA_CMD_SMART;
512 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 442 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
513 args.data_phase = TASKFILE_IN; 443 args.data_phase = TASKFILE_IN;
514 (void) smart_enable(drive); 444 (void) smart_enable(drive);
@@ -523,7 +453,7 @@ static int proc_idedisk_read_cache
523 int len; 453 int len;
524 454
525 if (drive->id_read) 455 if (drive->id_read)
526 len = sprintf(out, "%i\n", drive->id->buf_size / 2); 456 len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
527 else 457 else
528 len = sprintf(out, "(none)\n"); 458 len = sprintf(out, "(none)\n");
529 459
@@ -549,13 +479,14 @@ static int proc_idedisk_read_smart(char *page, char **start, off_t off,
549 479
550 if (get_smart_data(drive, page, sub_cmd) == 0) { 480 if (get_smart_data(drive, page, sub_cmd) == 0) {
551 unsigned short *val = (unsigned short *) page; 481 unsigned short *val = (unsigned short *) page;
552 char *out = ((char *)val) + (SECTOR_WORDS * 4); 482 char *out = (char *)val + SECTOR_SIZE;
483
553 page = out; 484 page = out;
554 do { 485 do {
555 out += sprintf(out, "%04x%c", le16_to_cpu(*val), 486 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
556 (++i & 7) ? ' ' : '\n'); 487 (++i & 7) ? ' ' : '\n');
557 val += 1; 488 val += 1;
558 } while (i < (SECTOR_WORDS * 2)); 489 } while (i < SECTOR_SIZE / 2);
559 len = out - page; 490 len = out - page;
560 } 491 }
561 492
@@ -566,14 +497,14 @@ static int proc_idedisk_read_sv
566 (char *page, char **start, off_t off, int count, int *eof, void *data) 497 (char *page, char **start, off_t off, int count, int *eof, void *data)
567{ 498{
568 return proc_idedisk_read_smart(page, start, off, count, eof, data, 499 return proc_idedisk_read_smart(page, start, off, count, eof, data,
569 SMART_READ_VALUES); 500 ATA_SMART_READ_VALUES);
570} 501}
571 502
572static int proc_idedisk_read_st 503static int proc_idedisk_read_st
573 (char *page, char **start, off_t off, int count, int *eof, void *data) 504 (char *page, char **start, off_t off, int count, int *eof, void *data)
574{ 505{
575 return proc_idedisk_read_smart(page, start, off, count, eof, data, 506 return proc_idedisk_read_smart(page, start, off, count, eof, data,
576 SMART_READ_THRESHOLDS); 507 ATA_SMART_READ_THRESHOLDS);
577} 508}
578 509
579static ide_proc_entry_t idedisk_proc[] = { 510static ide_proc_entry_t idedisk_proc[] = {
@@ -595,11 +526,11 @@ static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
595 BUG_ON(task == NULL); 526 BUG_ON(task == NULL);
596 527
597 memset(task, 0, sizeof(*task)); 528 memset(task, 0, sizeof(*task));
598 if (ide_id_has_flush_cache_ext(drive->id) && 529 if (ata_id_flush_ext_enabled(drive->id) &&
599 (drive->capacity64 >= (1UL << 28))) 530 (drive->capacity64 >= (1UL << 28)))
600 task->tf.command = WIN_FLUSH_CACHE_EXT; 531 task->tf.command = ATA_CMD_FLUSH_EXT;
601 else 532 else
602 task->tf.command = WIN_FLUSH_CACHE; 533 task->tf.command = ATA_CMD_FLUSH;
603 task->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE | 534 task->tf_flags = IDE_TFLAG_OUT_TF | IDE_TFLAG_OUT_DEVICE |
604 IDE_TFLAG_DYN; 535 IDE_TFLAG_DYN;
605 task->data_phase = TASKFILE_NO_DATA; 536 task->data_phase = TASKFILE_NO_DATA;
@@ -609,6 +540,8 @@ static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
609 rq->special = task; 540 rq->special = task;
610} 541}
611 542
543ide_devset_get(multcount, mult_count);
544
612/* 545/*
613 * This is tightly woven into the driver->do_special can not touch. 546 * This is tightly woven into the driver->do_special can not touch.
614 * DON'T do it again until a total personality rewrite is committed. 547 * DON'T do it again until a total personality rewrite is committed.
@@ -618,7 +551,7 @@ static int set_multcount(ide_drive_t *drive, int arg)
618 struct request *rq; 551 struct request *rq;
619 int error; 552 int error;
620 553
621 if (arg < 0 || arg > drive->id->max_multsect) 554 if (arg < 0 || arg > (drive->id[ATA_ID_MAX_MULTSECT] & 0xff))
622 return -EINVAL; 555 return -EINVAL;
623 556
624 if (drive->special.b.set_multmode) 557 if (drive->special.b.set_multmode)
@@ -635,22 +568,21 @@ static int set_multcount(ide_drive_t *drive, int arg)
635 return (drive->mult_count == arg) ? 0 : -EIO; 568 return (drive->mult_count == arg) ? 0 : -EIO;
636} 569}
637 570
571ide_devset_get(nowerr, nowerr);
572
638static int set_nowerr(ide_drive_t *drive, int arg) 573static int set_nowerr(ide_drive_t *drive, int arg)
639{ 574{
640 if (arg < 0 || arg > 1) 575 if (arg < 0 || arg > 1)
641 return -EINVAL; 576 return -EINVAL;
642 577
643 if (ide_spin_wait_hwgroup(drive))
644 return -EBUSY;
645 drive->nowerr = arg; 578 drive->nowerr = arg;
646 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT; 579 drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
647 spin_unlock_irq(&ide_lock);
648 return 0; 580 return 0;
649} 581}
650 582
651static void update_ordered(ide_drive_t *drive) 583static void update_ordered(ide_drive_t *drive)
652{ 584{
653 struct hd_driveid *id = drive->id; 585 u16 *id = drive->id;
654 unsigned ordered = QUEUE_ORDERED_NONE; 586 unsigned ordered = QUEUE_ORDERED_NONE;
655 prepare_flush_fn *prep_fn = NULL; 587 prepare_flush_fn *prep_fn = NULL;
656 588
@@ -666,9 +598,9 @@ static void update_ordered(ide_drive_t *drive)
666 * not available so we don't need to recheck that. 598 * not available so we don't need to recheck that.
667 */ 599 */
668 capacity = idedisk_capacity(drive); 600 capacity = idedisk_capacity(drive);
669 barrier = ide_id_has_flush_cache(id) && !drive->noflush && 601 barrier = ata_id_flush_enabled(id) && !drive->noflush &&
670 (drive->addressing == 0 || capacity <= (1ULL << 28) || 602 (drive->addressing == 0 || capacity <= (1ULL << 28) ||
671 ide_id_has_flush_cache_ext(id)); 603 ata_id_flush_ext_enabled(id));
672 604
673 printk(KERN_INFO "%s: cache flushes %ssupported\n", 605 printk(KERN_INFO "%s: cache flushes %ssupported\n",
674 drive->name, barrier ? "" : "not "); 606 drive->name, barrier ? "" : "not ");
@@ -683,7 +615,9 @@ static void update_ordered(ide_drive_t *drive)
683 blk_queue_ordered(drive->queue, ordered, prep_fn); 615 blk_queue_ordered(drive->queue, ordered, prep_fn);
684} 616}
685 617
686static int write_cache(ide_drive_t *drive, int arg) 618ide_devset_get(wcache, wcache);
619
620static int set_wcache(ide_drive_t *drive, int arg)
687{ 621{
688 ide_task_t args; 622 ide_task_t args;
689 int err = 1; 623 int err = 1;
@@ -691,11 +625,11 @@ static int write_cache(ide_drive_t *drive, int arg)
691 if (arg < 0 || arg > 1) 625 if (arg < 0 || arg > 1)
692 return -EINVAL; 626 return -EINVAL;
693 627
694 if (ide_id_has_flush_cache(drive->id)) { 628 if (ata_id_flush_enabled(drive->id)) {
695 memset(&args, 0, sizeof(ide_task_t)); 629 memset(&args, 0, sizeof(ide_task_t));
696 args.tf.feature = arg ? 630 args.tf.feature = arg ?
697 SETFEATURES_EN_WCACHE : SETFEATURES_DIS_WCACHE; 631 SETFEATURES_WC_ON : SETFEATURES_WC_OFF;
698 args.tf.command = WIN_SETFEATURES; 632 args.tf.command = ATA_CMD_SET_FEATURES;
699 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 633 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
700 err = ide_no_data_taskfile(drive, &args); 634 err = ide_no_data_taskfile(drive, &args);
701 if (err == 0) 635 if (err == 0)
@@ -712,14 +646,16 @@ static int do_idedisk_flushcache(ide_drive_t *drive)
712 ide_task_t args; 646 ide_task_t args;
713 647
714 memset(&args, 0, sizeof(ide_task_t)); 648 memset(&args, 0, sizeof(ide_task_t));
715 if (ide_id_has_flush_cache_ext(drive->id)) 649 if (ata_id_flush_ext_enabled(drive->id))
716 args.tf.command = WIN_FLUSH_CACHE_EXT; 650 args.tf.command = ATA_CMD_FLUSH_EXT;
717 else 651 else
718 args.tf.command = WIN_FLUSH_CACHE; 652 args.tf.command = ATA_CMD_FLUSH;
719 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 653 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
720 return ide_no_data_taskfile(drive, &args); 654 return ide_no_data_taskfile(drive, &args);
721} 655}
722 656
657ide_devset_get(acoustic, acoustic);
658
723static int set_acoustic(ide_drive_t *drive, int arg) 659static int set_acoustic(ide_drive_t *drive, int arg)
724{ 660{
725 ide_task_t args; 661 ide_task_t args;
@@ -728,22 +664,24 @@ static int set_acoustic(ide_drive_t *drive, int arg)
728 return -EINVAL; 664 return -EINVAL;
729 665
730 memset(&args, 0, sizeof(ide_task_t)); 666 memset(&args, 0, sizeof(ide_task_t));
731 args.tf.feature = arg ? SETFEATURES_EN_AAM : SETFEATURES_DIS_AAM; 667 args.tf.feature = arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF;
732 args.tf.nsect = arg; 668 args.tf.nsect = arg;
733 args.tf.command = WIN_SETFEATURES; 669 args.tf.command = ATA_CMD_SET_FEATURES;
734 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 670 args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
735 ide_no_data_taskfile(drive, &args); 671 ide_no_data_taskfile(drive, &args);
736 drive->acoustic = arg; 672 drive->acoustic = arg;
737 return 0; 673 return 0;
738} 674}
739 675
676ide_devset_get(addressing, addressing);
677
740/* 678/*
741 * drive->addressing: 679 * drive->addressing:
742 * 0: 28-bit 680 * 0: 28-bit
743 * 1: 48-bit 681 * 1: 48-bit
744 * 2: 48-bit capable doing 28-bit 682 * 2: 48-bit capable doing 28-bit
745 */ 683 */
746static int set_lba_addressing(ide_drive_t *drive, int arg) 684static int set_addressing(ide_drive_t *drive, int arg)
747{ 685{
748 if (arg < 0 || arg > 2) 686 if (arg < 0 || arg > 2)
749 return -EINVAL; 687 return -EINVAL;
@@ -753,52 +691,54 @@ static int set_lba_addressing(ide_drive_t *drive, int arg)
753 if (drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) 691 if (drive->hwif->host_flags & IDE_HFLAG_NO_LBA48)
754 return 0; 692 return 0;
755 693
756 if (!idedisk_supports_lba48(drive->id)) 694 if (ata_id_lba48_enabled(drive->id) == 0)
757 return -EIO; 695 return -EIO;
696
758 drive->addressing = arg; 697 drive->addressing = arg;
698
759 return 0; 699 return 0;
760} 700}
761 701
702ide_devset_rw(acoustic, acoustic);
703ide_devset_rw(address, addressing);
704ide_devset_rw(multcount, multcount);
705ide_devset_rw(wcache, wcache);
706
707ide_devset_rw_sync(nowerr, nowerr);
708
762#ifdef CONFIG_IDE_PROC_FS 709#ifdef CONFIG_IDE_PROC_FS
763static void idedisk_add_settings(ide_drive_t *drive) 710ide_devset_rw_field(bios_cyl, bios_cyl);
764{ 711ide_devset_rw_field(bios_head, bios_head);
765 struct hd_driveid *id = drive->id; 712ide_devset_rw_field(bios_sect, bios_sect);
766 713ide_devset_rw_field(failures, failures);
767 ide_add_setting(drive, "bios_cyl", SETTING_RW, TYPE_INT, 0, 65535, 1, 1, 714ide_devset_rw_field(lun, lun);
768 &drive->bios_cyl, NULL); 715ide_devset_rw_field(max_failures, max_failures);
769 ide_add_setting(drive, "bios_head", SETTING_RW, TYPE_BYTE, 0, 255, 1, 1, 716
770 &drive->bios_head, NULL); 717static const struct ide_proc_devset idedisk_settings[] = {
771 ide_add_setting(drive, "bios_sect", SETTING_RW, TYPE_BYTE, 0, 63, 1, 1, 718 IDE_PROC_DEVSET(acoustic, 0, 254),
772 &drive->bios_sect, NULL); 719 IDE_PROC_DEVSET(address, 0, 2),
773 ide_add_setting(drive, "address", SETTING_RW, TYPE_BYTE, 0, 2, 1, 1, 720 IDE_PROC_DEVSET(bios_cyl, 0, 65535),
774 &drive->addressing, set_lba_addressing); 721 IDE_PROC_DEVSET(bios_head, 0, 255),
775 ide_add_setting(drive, "multcount", SETTING_RW, TYPE_BYTE, 0, 722 IDE_PROC_DEVSET(bios_sect, 0, 63),
776 id->max_multsect, 1, 1, &drive->mult_count, 723 IDE_PROC_DEVSET(failures, 0, 65535),
777 set_multcount); 724 IDE_PROC_DEVSET(lun, 0, 7),
778 ide_add_setting(drive, "nowerr", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, 725 IDE_PROC_DEVSET(max_failures, 0, 65535),
779 &drive->nowerr, set_nowerr); 726 IDE_PROC_DEVSET(multcount, 0, 16),
780 ide_add_setting(drive, "lun", SETTING_RW, TYPE_INT, 0, 7, 1, 1, 727 IDE_PROC_DEVSET(nowerr, 0, 1),
781 &drive->lun, NULL); 728 IDE_PROC_DEVSET(wcache, 0, 1),
782 ide_add_setting(drive, "wcache", SETTING_RW, TYPE_BYTE, 0, 1, 1, 1, 729 { 0 },
783 &drive->wcache, write_cache); 730};
784 ide_add_setting(drive, "acoustic", SETTING_RW, TYPE_BYTE, 0, 254, 1, 1,
785 &drive->acoustic, set_acoustic);
786 ide_add_setting(drive, "failures", SETTING_RW, TYPE_INT, 0, 65535, 1, 1,
787 &drive->failures, NULL);
788 ide_add_setting(drive, "max_failures", SETTING_RW, TYPE_INT, 0, 65535,
789 1, 1, &drive->max_failures, NULL);
790}
791#else
792static inline void idedisk_add_settings(ide_drive_t *drive) { ; }
793#endif 731#endif
794 732
795static void idedisk_setup(ide_drive_t *drive) 733static void idedisk_setup(ide_drive_t *drive)
796{ 734{
735 struct ide_disk_obj *idkp = drive->driver_data;
797 ide_hwif_t *hwif = drive->hwif; 736 ide_hwif_t *hwif = drive->hwif;
798 struct hd_driveid *id = drive->id; 737 u16 *id = drive->id;
738 char *m = (char *)&id[ATA_ID_PROD];
799 unsigned long long capacity; 739 unsigned long long capacity;
800 740
801 idedisk_add_settings(drive); 741 ide_proc_register_driver(drive, idkp->driver);
802 742
803 if (drive->id_read == 0) 743 if (drive->id_read == 0)
804 return; 744 return;
@@ -807,11 +747,11 @@ static void idedisk_setup(ide_drive_t *drive)
807 /* 747 /*
808 * Removable disks (eg. SYQUEST); ignore 'WD' drives 748 * Removable disks (eg. SYQUEST); ignore 'WD' drives
809 */ 749 */
810 if (id->model[0] != 'W' || id->model[1] != 'D') 750 if (m[0] != 'W' || m[1] != 'D')
811 drive->doorlocking = 1; 751 drive->doorlocking = 1;
812 } 752 }
813 753
814 (void)set_lba_addressing(drive, 1); 754 (void)set_addressing(drive, 1);
815 755
816 if (drive->addressing == 1) { 756 if (drive->addressing == 1) {
817 int max_s = 2048; 757 int max_s = 2048;
@@ -853,8 +793,7 @@ static void idedisk_setup(ide_drive_t *drive)
853 capacity = idedisk_capacity(drive); 793 capacity = idedisk_capacity(drive);
854 794
855 if (!drive->forced_geom) { 795 if (!drive->forced_geom) {
856 796 if (ata_id_lba48_enabled(drive->id)) {
857 if (idedisk_supports_lba48(drive->id)) {
858 /* compatibility */ 797 /* compatibility */
859 drive->bios_sect = 63; 798 drive->bios_sect = 63;
860 drive->bios_head = 255; 799 drive->bios_head = 255;
@@ -880,22 +819,22 @@ static void idedisk_setup(ide_drive_t *drive)
880 drive->name, capacity, sectors_to_MB(capacity)); 819 drive->name, capacity, sectors_to_MB(capacity));
881 820
882 /* Only print cache size when it was specified */ 821 /* Only print cache size when it was specified */
883 if (id->buf_size) 822 if (id[ATA_ID_BUF_SIZE])
884 printk(KERN_CONT " w/%dKiB Cache", id->buf_size / 2); 823 printk(KERN_CONT " w/%dKiB Cache", id[ATA_ID_BUF_SIZE] / 2);
885 824
886 printk(KERN_CONT ", CHS=%d/%d/%d\n", 825 printk(KERN_CONT ", CHS=%d/%d/%d\n",
887 drive->bios_cyl, drive->bios_head, drive->bios_sect); 826 drive->bios_cyl, drive->bios_head, drive->bios_sect);
888 827
889 /* write cache enabled? */ 828 /* write cache enabled? */
890 if ((id->csfo & 1) || (id->cfs_enable_1 & (1 << 5))) 829 if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id))
891 drive->wcache = 1; 830 drive->wcache = 1;
892 831
893 write_cache(drive, 1); 832 set_wcache(drive, 1);
894} 833}
895 834
896static void ide_cacheflush_p(ide_drive_t *drive) 835static void ide_cacheflush_p(ide_drive_t *drive)
897{ 836{
898 if (!drive->wcache || !ide_id_has_flush_cache(drive->id)) 837 if (!drive->wcache || ata_id_flush_enabled(drive->id) == 0)
899 return; 838 return;
900 839
901 if (do_idedisk_flushcache(drive)) 840 if (do_idedisk_flushcache(drive))
@@ -937,7 +876,7 @@ static int ide_disk_probe(ide_drive_t *drive);
937 */ 876 */
938static void ide_disk_resume(ide_drive_t *drive) 877static void ide_disk_resume(ide_drive_t *drive)
939{ 878{
940 if (idedisk_supports_hpa(drive->id)) 879 if (ata_id_hpa_enabled(drive->id))
941 init_idedisk_capacity(drive); 880 init_idedisk_capacity(drive);
942} 881}
943 882
@@ -980,12 +919,12 @@ static ide_driver_t idedisk_driver = {
980 .shutdown = ide_device_shutdown, 919 .shutdown = ide_device_shutdown,
981 .version = IDEDISK_VERSION, 920 .version = IDEDISK_VERSION,
982 .media = ide_disk, 921 .media = ide_disk,
983 .supports_dsc_overlap = 0,
984 .do_request = ide_do_rw_disk, 922 .do_request = ide_do_rw_disk,
985 .end_request = ide_end_request, 923 .end_request = ide_end_request,
986 .error = __ide_error, 924 .error = __ide_error,
987#ifdef CONFIG_IDE_PROC_FS 925#ifdef CONFIG_IDE_PROC_FS
988 .proc = idedisk_proc, 926 .proc = idedisk_proc,
927 .settings = idedisk_settings,
989#endif 928#endif
990}; 929};
991 930
@@ -994,7 +933,7 @@ static int idedisk_set_doorlock(ide_drive_t *drive, int on)
994 ide_task_t task; 933 ide_task_t task;
995 934
996 memset(&task, 0, sizeof(task)); 935 memset(&task, 0, sizeof(task));
997 task.tf.command = on ? WIN_DOORLOCK : WIN_DOORUNLOCK; 936 task.tf.command = on ? ATA_CMD_MEDIA_LOCK : ATA_CMD_MEDIA_UNLOCK;
998 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; 937 task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
999 938
1000 return ide_no_data_taskfile(drive, &task); 939 return ide_no_data_taskfile(drive, &task);
@@ -1059,52 +998,28 @@ static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
1059 return 0; 998 return 0;
1060} 999}
1061 1000
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
1062static int idedisk_ioctl(struct inode *inode, struct file *file, 1010static int idedisk_ioctl(struct inode *inode, struct file *file,
1063 unsigned int cmd, unsigned long arg) 1011 unsigned int cmd, unsigned long arg)
1064{ 1012{
1065 unsigned long flags;
1066 struct block_device *bdev = inode->i_bdev; 1013 struct block_device *bdev = inode->i_bdev;
1067 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk); 1014 struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
1068 ide_drive_t *drive = idkp->drive; 1015 ide_drive_t *drive = idkp->drive;
1069 int err, (*setfunc)(ide_drive_t *, int); 1016 int err;
1070 u8 *val;
1071
1072 switch (cmd) {
1073 case HDIO_GET_ADDRESS: val = &drive->addressing; goto read_val;
1074 case HDIO_GET_MULTCOUNT: val = &drive->mult_count; goto read_val;
1075 case HDIO_GET_NOWERR: val = &drive->nowerr; goto read_val;
1076 case HDIO_GET_WCACHE: val = &drive->wcache; goto read_val;
1077 case HDIO_GET_ACOUSTIC: val = &drive->acoustic; goto read_val;
1078 case HDIO_SET_ADDRESS: setfunc = set_lba_addressing; goto set_val;
1079 case HDIO_SET_MULTCOUNT: setfunc = set_multcount; goto set_val;
1080 case HDIO_SET_NOWERR: setfunc = set_nowerr; goto set_val;
1081 case HDIO_SET_WCACHE: setfunc = write_cache; goto set_val;
1082 case HDIO_SET_ACOUSTIC: setfunc = set_acoustic; goto set_val;
1083 }
1084 1017
1085 return generic_ide_ioctl(drive, file, bdev, cmd, arg); 1018 err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
1019 if (err != -EOPNOTSUPP)
1020 return err;
1086 1021
1087read_val: 1022 return generic_ide_ioctl(drive, file, bdev, cmd, arg);
1088 mutex_lock(&ide_setting_mtx);
1089 spin_lock_irqsave(&ide_lock, flags);
1090 err = *val;
1091 spin_unlock_irqrestore(&ide_lock, flags);
1092 mutex_unlock(&ide_setting_mtx);
1093 return err >= 0 ? put_user(err, (long __user *)arg) : err;
1094
1095set_val:
1096 if (bdev != bdev->bd_contains)
1097 err = -EINVAL;
1098 else {
1099 if (!capable(CAP_SYS_ADMIN))
1100 err = -EACCES;
1101 else {
1102 mutex_lock(&ide_setting_mtx);
1103 err = setfunc(drive, arg);
1104 mutex_unlock(&ide_setting_mtx);
1105 }
1106 }
1107 return err;
1108} 1023}
1109 1024
1110static int idedisk_media_changed(struct gendisk *disk) 1025static int idedisk_media_changed(struct gendisk *disk)
@@ -1148,8 +1063,7 @@ static int ide_disk_probe(ide_drive_t *drive)
1148 /* strstr("foo", "") is non-NULL */ 1063 /* strstr("foo", "") is non-NULL */
1149 if (!strstr("ide-disk", drive->driver_req)) 1064 if (!strstr("ide-disk", drive->driver_req))
1150 goto failed; 1065 goto failed;
1151 if (!drive->present) 1066
1152 goto failed;
1153 if (drive->media != ide_disk) 1067 if (drive->media != ide_disk)
1154 goto failed; 1068 goto failed;
1155 1069
@@ -1163,8 +1077,6 @@ static int ide_disk_probe(ide_drive_t *drive)
1163 1077
1164 ide_init_disk(g, drive); 1078 ide_init_disk(g, drive);
1165 1079
1166 ide_proc_register_driver(drive, &idedisk_driver);
1167
1168 kref_init(&idkp->kref); 1080 kref_init(&idkp->kref);
1169 1081
1170 idkp->drive = drive; 1082 idkp->drive = drive;