diff options
author | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-10-13 15:39:45 -0400 |
---|---|---|
committer | Bartlomiej Zolnierkiewicz <bzolnier@gmail.com> | 2008-10-13 15:39:45 -0400 |
commit | 06b89518fa69fb7243dc98c31f9a9cfa61bfe788 (patch) | |
tree | c343692a440f551da2a09d22cf644df9e093b426 /drivers | |
parent | f87904898e91923a91b925078ac933f05076c7fd (diff) |
ide-disk: move /proc handling to ide-disk_proc.c (take 3)
While at it:
- idedisk_capacity() -> ide_disk_capacity()
- idedisk_proc[] -> ide_disk_proc[]
- idedisk_settings[] -> ide_disk_settings[]
v2/3:
Build fix for CONFIG_IDE_PROC_FS=n from Elias Oltmanns.
Signed-off-by: Bartlomiej Zolnierkiewicz <bzolnier@gmail.com>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/ide/Makefile | 1 | ||||
-rw-r--r-- | drivers/ide/ide-disk.c | 142 | ||||
-rw-r--r-- | drivers/ide/ide-disk.h | 7 | ||||
-rw-r--r-- | drivers/ide/ide-disk_proc.c | 129 |
4 files changed, 144 insertions, 135 deletions
diff --git a/drivers/ide/Makefile b/drivers/ide/Makefile index 57b252b8e792..e6e7811812d2 100644 --- a/drivers/ide/Makefile +++ b/drivers/ide/Makefile | |||
@@ -41,6 +41,7 @@ ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o | |||
41 | ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o | 41 | ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o |
42 | 42 | ||
43 | ifeq ($(CONFIG_IDE_PROC_FS), y) | 43 | ifeq ($(CONFIG_IDE_PROC_FS), y) |
44 | ide-disk_mod-y += ide-disk_proc.o | ||
44 | ide-floppy_mod-y += ide-floppy_proc.o | 45 | ide-floppy_mod-y += ide-floppy_proc.o |
45 | endif | 46 | endif |
46 | 47 | ||
diff --git a/drivers/ide/ide-disk.c b/drivers/ide/ide-disk.c index 995d448109eb..3853bde8eedc 100644 --- a/drivers/ide/ide-disk.c +++ b/drivers/ide/ide-disk.c | |||
@@ -405,115 +405,11 @@ static void init_idedisk_capacity(ide_drive_t *drive) | |||
405 | } | 405 | } |
406 | } | 406 | } |
407 | 407 | ||
408 | static sector_t idedisk_capacity(ide_drive_t *drive) | 408 | sector_t ide_disk_capacity(ide_drive_t *drive) |
409 | { | 409 | { |
410 | return drive->capacity64; | 410 | return drive->capacity64; |
411 | } | 411 | } |
412 | 412 | ||
413 | #ifdef CONFIG_IDE_PROC_FS | ||
414 | static int smart_enable(ide_drive_t *drive) | ||
415 | { | ||
416 | ide_task_t args; | ||
417 | struct ide_taskfile *tf = &args.tf; | ||
418 | |||
419 | memset(&args, 0, sizeof(ide_task_t)); | ||
420 | tf->feature = ATA_SMART_ENABLE; | ||
421 | tf->lbam = ATA_SMART_LBAM_PASS; | ||
422 | tf->lbah = ATA_SMART_LBAH_PASS; | ||
423 | tf->command = ATA_CMD_SMART; | ||
424 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; | ||
425 | return ide_no_data_taskfile(drive, &args); | ||
426 | } | ||
427 | |||
428 | static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd) | ||
429 | { | ||
430 | ide_task_t args; | ||
431 | struct ide_taskfile *tf = &args.tf; | ||
432 | |||
433 | memset(&args, 0, sizeof(ide_task_t)); | ||
434 | tf->feature = sub_cmd; | ||
435 | tf->nsect = 0x01; | ||
436 | tf->lbam = ATA_SMART_LBAM_PASS; | ||
437 | tf->lbah = ATA_SMART_LBAH_PASS; | ||
438 | tf->command = ATA_CMD_SMART; | ||
439 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; | ||
440 | args.data_phase = TASKFILE_IN; | ||
441 | (void) smart_enable(drive); | ||
442 | return ide_raw_taskfile(drive, &args, buf, 1); | ||
443 | } | ||
444 | |||
445 | static int proc_idedisk_read_cache | ||
446 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
447 | { | ||
448 | ide_drive_t *drive = (ide_drive_t *) data; | ||
449 | char *out = page; | ||
450 | int len; | ||
451 | |||
452 | if (drive->dev_flags & IDE_DFLAG_ID_READ) | ||
453 | len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); | ||
454 | else | ||
455 | len = sprintf(out, "(none)\n"); | ||
456 | |||
457 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | ||
458 | } | ||
459 | |||
460 | static int proc_idedisk_read_capacity | ||
461 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
462 | { | ||
463 | ide_drive_t*drive = (ide_drive_t *)data; | ||
464 | int len; | ||
465 | |||
466 | len = sprintf(page, "%llu\n", (long long)idedisk_capacity(drive)); | ||
467 | |||
468 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | ||
469 | } | ||
470 | |||
471 | static int proc_idedisk_read_smart(char *page, char **start, off_t off, | ||
472 | int count, int *eof, void *data, u8 sub_cmd) | ||
473 | { | ||
474 | ide_drive_t *drive = (ide_drive_t *)data; | ||
475 | int len = 0, i = 0; | ||
476 | |||
477 | if (get_smart_data(drive, page, sub_cmd) == 0) { | ||
478 | unsigned short *val = (unsigned short *) page; | ||
479 | char *out = (char *)val + SECTOR_SIZE; | ||
480 | |||
481 | page = out; | ||
482 | do { | ||
483 | out += sprintf(out, "%04x%c", le16_to_cpu(*val), | ||
484 | (++i & 7) ? ' ' : '\n'); | ||
485 | val += 1; | ||
486 | } while (i < SECTOR_SIZE / 2); | ||
487 | len = out - page; | ||
488 | } | ||
489 | |||
490 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | ||
491 | } | ||
492 | |||
493 | static int proc_idedisk_read_sv | ||
494 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
495 | { | ||
496 | return proc_idedisk_read_smart(page, start, off, count, eof, data, | ||
497 | ATA_SMART_READ_VALUES); | ||
498 | } | ||
499 | |||
500 | static int proc_idedisk_read_st | ||
501 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
502 | { | ||
503 | return proc_idedisk_read_smart(page, start, off, count, eof, data, | ||
504 | ATA_SMART_READ_THRESHOLDS); | ||
505 | } | ||
506 | |||
507 | static ide_proc_entry_t idedisk_proc[] = { | ||
508 | { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL }, | ||
509 | { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL }, | ||
510 | { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, | ||
511 | { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL }, | ||
512 | { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL }, | ||
513 | { NULL, 0, NULL, NULL } | ||
514 | }; | ||
515 | #endif /* CONFIG_IDE_PROC_FS */ | ||
516 | |||
517 | static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) | 413 | static void idedisk_prepare_flush(struct request_queue *q, struct request *rq) |
518 | { | 414 | { |
519 | ide_drive_t *drive = q->queuedata; | 415 | ide_drive_t *drive = q->queuedata; |
@@ -612,7 +508,7 @@ static void update_ordered(ide_drive_t *drive) | |||
612 | * time we have trimmed the drive capacity if LBA48 is | 508 | * time we have trimmed the drive capacity if LBA48 is |
613 | * not available so we don't need to recheck that. | 509 | * not available so we don't need to recheck that. |
614 | */ | 510 | */ |
615 | capacity = idedisk_capacity(drive); | 511 | capacity = ide_disk_capacity(drive); |
616 | barrier = ata_id_flush_enabled(id) && | 512 | barrier = ata_id_flush_enabled(id) && |
617 | (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 && | 513 | (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 && |
618 | ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 || | 514 | ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 || |
@@ -720,30 +616,6 @@ ide_ext_devset_rw(wcache, wcache); | |||
720 | 616 | ||
721 | ide_ext_devset_rw_sync(nowerr, nowerr); | 617 | ide_ext_devset_rw_sync(nowerr, nowerr); |
722 | 618 | ||
723 | #ifdef CONFIG_IDE_PROC_FS | ||
724 | ide_devset_rw_field(bios_cyl, bios_cyl); | ||
725 | ide_devset_rw_field(bios_head, bios_head); | ||
726 | ide_devset_rw_field(bios_sect, bios_sect); | ||
727 | ide_devset_rw_field(failures, failures); | ||
728 | ide_devset_rw_field(lun, lun); | ||
729 | ide_devset_rw_field(max_failures, max_failures); | ||
730 | |||
731 | static const struct ide_proc_devset idedisk_settings[] = { | ||
732 | IDE_PROC_DEVSET(acoustic, 0, 254), | ||
733 | IDE_PROC_DEVSET(address, 0, 2), | ||
734 | IDE_PROC_DEVSET(bios_cyl, 0, 65535), | ||
735 | IDE_PROC_DEVSET(bios_head, 0, 255), | ||
736 | IDE_PROC_DEVSET(bios_sect, 0, 63), | ||
737 | IDE_PROC_DEVSET(failures, 0, 65535), | ||
738 | IDE_PROC_DEVSET(lun, 0, 7), | ||
739 | IDE_PROC_DEVSET(max_failures, 0, 65535), | ||
740 | IDE_PROC_DEVSET(multcount, 0, 16), | ||
741 | IDE_PROC_DEVSET(nowerr, 0, 1), | ||
742 | IDE_PROC_DEVSET(wcache, 0, 1), | ||
743 | { 0 }, | ||
744 | }; | ||
745 | #endif | ||
746 | |||
747 | static void idedisk_setup(ide_drive_t *drive) | 619 | static void idedisk_setup(ide_drive_t *drive) |
748 | { | 620 | { |
749 | struct ide_disk_obj *idkp = drive->driver_data; | 621 | struct ide_disk_obj *idkp = drive->driver_data; |
@@ -806,7 +678,7 @@ static void idedisk_setup(ide_drive_t *drive) | |||
806 | * if possible, give fdisk access to more of the drive, | 678 | * if possible, give fdisk access to more of the drive, |
807 | * by correcting bios_cyls: | 679 | * by correcting bios_cyls: |
808 | */ | 680 | */ |
809 | capacity = idedisk_capacity(drive); | 681 | capacity = ide_disk_capacity(drive); |
810 | 682 | ||
811 | if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) { | 683 | if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) { |
812 | if (ata_id_lba48_enabled(drive->id)) { | 684 | if (ata_id_lba48_enabled(drive->id)) { |
@@ -939,8 +811,8 @@ static ide_driver_t idedisk_driver = { | |||
939 | .end_request = ide_end_request, | 811 | .end_request = ide_end_request, |
940 | .error = __ide_error, | 812 | .error = __ide_error, |
941 | #ifdef CONFIG_IDE_PROC_FS | 813 | #ifdef CONFIG_IDE_PROC_FS |
942 | .proc = idedisk_proc, | 814 | .proc = ide_disk_proc, |
943 | .settings = idedisk_settings, | 815 | .settings = ide_disk_settings, |
944 | #endif | 816 | #endif |
945 | }; | 817 | }; |
946 | 818 | ||
@@ -1034,7 +906,7 @@ static int idedisk_media_changed(struct gendisk *disk) | |||
1034 | static int idedisk_revalidate_disk(struct gendisk *disk) | 906 | static int idedisk_revalidate_disk(struct gendisk *disk) |
1035 | { | 907 | { |
1036 | struct ide_disk_obj *idkp = ide_disk_g(disk); | 908 | struct ide_disk_obj *idkp = ide_disk_g(disk); |
1037 | set_capacity(disk, idedisk_capacity(idkp->drive)); | 909 | set_capacity(disk, ide_disk_capacity(idkp->drive)); |
1038 | return 0; | 910 | return 0; |
1039 | } | 911 | } |
1040 | 912 | ||
@@ -1096,7 +968,7 @@ static int ide_disk_probe(ide_drive_t *drive) | |||
1096 | g->flags |= GENHD_FL_EXT_DEVT; | 968 | g->flags |= GENHD_FL_EXT_DEVT; |
1097 | if (drive->dev_flags & IDE_DFLAG_REMOVABLE) | 969 | if (drive->dev_flags & IDE_DFLAG_REMOVABLE) |
1098 | g->flags = GENHD_FL_REMOVABLE; | 970 | g->flags = GENHD_FL_REMOVABLE; |
1099 | set_capacity(g, idedisk_capacity(drive)); | 971 | set_capacity(g, ide_disk_capacity(drive)); |
1100 | g->fops = &idedisk_ops; | 972 | g->fops = &idedisk_ops; |
1101 | add_disk(g); | 973 | add_disk(g); |
1102 | return 0; | 974 | return 0; |
diff --git a/drivers/ide/ide-disk.h b/drivers/ide/ide-disk.h index 7f007854adac..a82fa4355665 100644 --- a/drivers/ide/ide-disk.h +++ b/drivers/ide/ide-disk.h | |||
@@ -13,6 +13,7 @@ struct ide_disk_obj { | |||
13 | container_of((disk)->private_data, struct ide_disk_obj, driver) | 13 | container_of((disk)->private_data, struct ide_disk_obj, driver) |
14 | 14 | ||
15 | /* ide-disk.c */ | 15 | /* ide-disk.c */ |
16 | sector_t ide_disk_capacity(ide_drive_t *); | ||
16 | ide_decl_devset(address); | 17 | ide_decl_devset(address); |
17 | ide_decl_devset(multcount); | 18 | ide_decl_devset(multcount); |
18 | ide_decl_devset(nowerr); | 19 | ide_decl_devset(nowerr); |
@@ -22,4 +23,10 @@ ide_decl_devset(acoustic); | |||
22 | /* ide-disk_ioctl.c */ | 23 | /* ide-disk_ioctl.c */ |
23 | int ide_disk_ioctl(struct inode *, struct file *, unsigned int, unsigned long); | 24 | int ide_disk_ioctl(struct inode *, struct file *, unsigned int, unsigned long); |
24 | 25 | ||
26 | #ifdef CONFIG_IDE_PROC_FS | ||
27 | /* ide-disk_proc.c */ | ||
28 | extern ide_proc_entry_t ide_disk_proc[]; | ||
29 | extern const struct ide_proc_devset ide_disk_settings[]; | ||
30 | #endif | ||
31 | |||
25 | #endif /* __IDE_DISK_H */ | 32 | #endif /* __IDE_DISK_H */ |
diff --git a/drivers/ide/ide-disk_proc.c b/drivers/ide/ide-disk_proc.c new file mode 100644 index 000000000000..4724976afe71 --- /dev/null +++ b/drivers/ide/ide-disk_proc.c | |||
@@ -0,0 +1,129 @@ | |||
1 | #include <linux/kernel.h> | ||
2 | #include <linux/ide.h> | ||
3 | #include <linux/hdreg.h> | ||
4 | |||
5 | #include "ide-disk.h" | ||
6 | |||
7 | static int smart_enable(ide_drive_t *drive) | ||
8 | { | ||
9 | ide_task_t args; | ||
10 | struct ide_taskfile *tf = &args.tf; | ||
11 | |||
12 | memset(&args, 0, sizeof(ide_task_t)); | ||
13 | tf->feature = ATA_SMART_ENABLE; | ||
14 | tf->lbam = ATA_SMART_LBAM_PASS; | ||
15 | tf->lbah = ATA_SMART_LBAH_PASS; | ||
16 | tf->command = ATA_CMD_SMART; | ||
17 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; | ||
18 | return ide_no_data_taskfile(drive, &args); | ||
19 | } | ||
20 | |||
21 | static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd) | ||
22 | { | ||
23 | ide_task_t args; | ||
24 | struct ide_taskfile *tf = &args.tf; | ||
25 | |||
26 | memset(&args, 0, sizeof(ide_task_t)); | ||
27 | tf->feature = sub_cmd; | ||
28 | tf->nsect = 0x01; | ||
29 | tf->lbam = ATA_SMART_LBAM_PASS; | ||
30 | tf->lbah = ATA_SMART_LBAH_PASS; | ||
31 | tf->command = ATA_CMD_SMART; | ||
32 | args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE; | ||
33 | args.data_phase = TASKFILE_IN; | ||
34 | (void) smart_enable(drive); | ||
35 | return ide_raw_taskfile(drive, &args, buf, 1); | ||
36 | } | ||
37 | |||
38 | static int proc_idedisk_read_cache | ||
39 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
40 | { | ||
41 | ide_drive_t *drive = (ide_drive_t *) data; | ||
42 | char *out = page; | ||
43 | int len; | ||
44 | |||
45 | if (drive->dev_flags & IDE_DFLAG_ID_READ) | ||
46 | len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); | ||
47 | else | ||
48 | len = sprintf(out, "(none)\n"); | ||
49 | |||
50 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | ||
51 | } | ||
52 | |||
53 | static int proc_idedisk_read_capacity | ||
54 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
55 | { | ||
56 | ide_drive_t*drive = (ide_drive_t *)data; | ||
57 | int len; | ||
58 | |||
59 | len = sprintf(page, "%llu\n", (long long)ide_disk_capacity(drive)); | ||
60 | |||
61 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | ||
62 | } | ||
63 | |||
64 | static int proc_idedisk_read_smart(char *page, char **start, off_t off, | ||
65 | int count, int *eof, void *data, u8 sub_cmd) | ||
66 | { | ||
67 | ide_drive_t *drive = (ide_drive_t *)data; | ||
68 | int len = 0, i = 0; | ||
69 | |||
70 | if (get_smart_data(drive, page, sub_cmd) == 0) { | ||
71 | unsigned short *val = (unsigned short *) page; | ||
72 | char *out = (char *)val + SECTOR_SIZE; | ||
73 | |||
74 | page = out; | ||
75 | do { | ||
76 | out += sprintf(out, "%04x%c", le16_to_cpu(*val), | ||
77 | (++i & 7) ? ' ' : '\n'); | ||
78 | val += 1; | ||
79 | } while (i < SECTOR_SIZE / 2); | ||
80 | len = out - page; | ||
81 | } | ||
82 | |||
83 | PROC_IDE_READ_RETURN(page, start, off, count, eof, len); | ||
84 | } | ||
85 | |||
86 | static int proc_idedisk_read_sv | ||
87 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
88 | { | ||
89 | return proc_idedisk_read_smart(page, start, off, count, eof, data, | ||
90 | ATA_SMART_READ_VALUES); | ||
91 | } | ||
92 | |||
93 | static int proc_idedisk_read_st | ||
94 | (char *page, char **start, off_t off, int count, int *eof, void *data) | ||
95 | { | ||
96 | return proc_idedisk_read_smart(page, start, off, count, eof, data, | ||
97 | ATA_SMART_READ_THRESHOLDS); | ||
98 | } | ||
99 | |||
100 | ide_proc_entry_t ide_disk_proc[] = { | ||
101 | { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL }, | ||
102 | { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL }, | ||
103 | { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL }, | ||
104 | { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL }, | ||
105 | { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL }, | ||
106 | { NULL, 0, NULL, NULL } | ||
107 | }; | ||
108 | |||
109 | ide_devset_rw_field(bios_cyl, bios_cyl); | ||
110 | ide_devset_rw_field(bios_head, bios_head); | ||
111 | ide_devset_rw_field(bios_sect, bios_sect); | ||
112 | ide_devset_rw_field(failures, failures); | ||
113 | ide_devset_rw_field(lun, lun); | ||
114 | ide_devset_rw_field(max_failures, max_failures); | ||
115 | |||
116 | const struct ide_proc_devset ide_disk_settings[] = { | ||
117 | IDE_PROC_DEVSET(acoustic, 0, 254), | ||
118 | IDE_PROC_DEVSET(address, 0, 2), | ||
119 | IDE_PROC_DEVSET(bios_cyl, 0, 65535), | ||
120 | IDE_PROC_DEVSET(bios_head, 0, 255), | ||
121 | IDE_PROC_DEVSET(bios_sect, 0, 63), | ||
122 | IDE_PROC_DEVSET(failures, 0, 65535), | ||
123 | IDE_PROC_DEVSET(lun, 0, 7), | ||
124 | IDE_PROC_DEVSET(max_failures, 0, 65535), | ||
125 | IDE_PROC_DEVSET(multcount, 0, 16), | ||
126 | IDE_PROC_DEVSET(nowerr, 0, 1), | ||
127 | IDE_PROC_DEVSET(wcache, 0, 1), | ||
128 | { 0 }, | ||
129 | }; | ||