Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/ide.h> |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 3 | #include <linux/seq_file.h> |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 4 | |
| 5 | #include "ide-disk.h" |
| 6 | |
| 7 | static int smart_enable(ide_drive_t *drive) |
| 8 | { |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 9 | struct ide_cmd cmd; |
| 10 | struct ide_taskfile *tf = &cmd.tf; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 11 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 12 | memset(&cmd, 0, sizeof(cmd)); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 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; |
Sergei Shtylyov | 60f8501 | 2009-04-08 14:13:01 +0200 | [diff] [blame] | 17 | cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE; |
| 18 | cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE; |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 19 | |
| 20 | return ide_no_data_taskfile(drive, &cmd); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 21 | } |
| 22 | |
| 23 | static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd) |
| 24 | { |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 25 | struct ide_cmd cmd; |
| 26 | struct ide_taskfile *tf = &cmd.tf; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 27 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 28 | memset(&cmd, 0, sizeof(cmd)); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 29 | tf->feature = sub_cmd; |
| 30 | tf->nsect = 0x01; |
| 31 | tf->lbam = ATA_SMART_LBAM_PASS; |
| 32 | tf->lbah = ATA_SMART_LBAH_PASS; |
| 33 | tf->command = ATA_CMD_SMART; |
Sergei Shtylyov | 60f8501 | 2009-04-08 14:13:01 +0200 | [diff] [blame] | 34 | cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE; |
| 35 | cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE; |
Bartlomiej Zolnierkiewicz | 0dfb991 | 2009-03-27 12:46:39 +0100 | [diff] [blame] | 36 | cmd.protocol = ATA_PROT_PIO; |
Bartlomiej Zolnierkiewicz | 3937585 | 2009-03-27 12:46:32 +0100 | [diff] [blame] | 37 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 38 | return ide_raw_taskfile(drive, &cmd, buf, 1); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 41 | static int idedisk_cache_proc_show(struct seq_file *m, void *v) |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 42 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 43 | ide_drive_t *drive = (ide_drive_t *) m->private; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 44 | |
| 45 | if (drive->dev_flags & IDE_DFLAG_ID_READ) |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 46 | seq_printf(m, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 47 | else |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 48 | seq_printf(m, "(none)\n"); |
| 49 | return 0; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 50 | } |
| 51 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 52 | static int idedisk_cache_proc_open(struct inode *inode, struct file *file) |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 53 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 54 | return single_open(file, idedisk_cache_proc_show, PDE(inode)->data); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 55 | } |
| 56 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 57 | static const struct file_operations idedisk_cache_proc_fops = { |
| 58 | .owner = THIS_MODULE, |
| 59 | .open = idedisk_cache_proc_open, |
| 60 | .read = seq_read, |
| 61 | .llseek = seq_lseek, |
| 62 | .release = single_release, |
| 63 | }; |
| 64 | |
| 65 | static int idedisk_capacity_proc_show(struct seq_file *m, void *v) |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 66 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 67 | ide_drive_t*drive = (ide_drive_t *)m->private; |
| 68 | |
| 69 | seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive)); |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static int idedisk_capacity_proc_open(struct inode *inode, struct file *file) |
| 74 | { |
| 75 | return single_open(file, idedisk_capacity_proc_show, PDE(inode)->data); |
| 76 | } |
| 77 | |
| 78 | static const struct file_operations idedisk_capacity_proc_fops = { |
| 79 | .owner = THIS_MODULE, |
| 80 | .open = idedisk_capacity_proc_open, |
| 81 | .read = seq_read, |
| 82 | .llseek = seq_lseek, |
| 83 | .release = single_release, |
| 84 | }; |
| 85 | |
| 86 | static int __idedisk_proc_show(struct seq_file *m, ide_drive_t *drive, u8 sub_cmd) |
| 87 | { |
| 88 | u8 *buf; |
| 89 | |
| 90 | buf = kmalloc(SECTOR_SIZE, GFP_KERNEL); |
| 91 | if (!buf) |
| 92 | return -ENOMEM; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 93 | |
Bartlomiej Zolnierkiewicz | 3937585 | 2009-03-27 12:46:32 +0100 | [diff] [blame] | 94 | (void)smart_enable(drive); |
| 95 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 96 | if (get_smart_data(drive, buf, sub_cmd) == 0) { |
| 97 | __le16 *val = (__le16 *)buf; |
| 98 | int i; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 99 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 100 | for (i = 0; i < SECTOR_SIZE / 2; i++) { |
| 101 | seq_printf(m, "%04x%c", le16_to_cpu(val[i]), |
| 102 | (i % 8) == 7 ? '\n' : ' '); |
| 103 | } |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 104 | } |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 105 | kfree(buf); |
| 106 | return 0; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 107 | } |
| 108 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 109 | static int idedisk_sv_proc_show(struct seq_file *m, void *v) |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 110 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 111 | return __idedisk_proc_show(m, m->private, ATA_SMART_READ_VALUES); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 112 | } |
| 113 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 114 | static int idedisk_sv_proc_open(struct inode *inode, struct file *file) |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 115 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 116 | return single_open(file, idedisk_sv_proc_show, PDE(inode)->data); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 117 | } |
| 118 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 119 | static const struct file_operations idedisk_sv_proc_fops = { |
| 120 | .owner = THIS_MODULE, |
| 121 | .open = idedisk_sv_proc_open, |
| 122 | .read = seq_read, |
| 123 | .llseek = seq_lseek, |
| 124 | .release = single_release, |
| 125 | }; |
| 126 | |
| 127 | static int idedisk_st_proc_show(struct seq_file *m, void *v) |
| 128 | { |
| 129 | return __idedisk_proc_show(m, m->private, ATA_SMART_READ_THRESHOLDS); |
| 130 | } |
| 131 | |
| 132 | static int idedisk_st_proc_open(struct inode *inode, struct file *file) |
| 133 | { |
| 134 | return single_open(file, idedisk_st_proc_show, PDE(inode)->data); |
| 135 | } |
| 136 | |
| 137 | static const struct file_operations idedisk_st_proc_fops = { |
| 138 | .owner = THIS_MODULE, |
| 139 | .open = idedisk_st_proc_open, |
| 140 | .read = seq_read, |
| 141 | .llseek = seq_lseek, |
| 142 | .release = single_release, |
| 143 | }; |
| 144 | |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 145 | ide_proc_entry_t ide_disk_proc[] = { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 146 | { "cache", S_IFREG|S_IRUGO, &idedisk_cache_proc_fops }, |
| 147 | { "capacity", S_IFREG|S_IRUGO, &idedisk_capacity_proc_fops }, |
| 148 | { "geometry", S_IFREG|S_IRUGO, &ide_geometry_proc_fops }, |
| 149 | { "smart_values", S_IFREG|S_IRUSR, &idedisk_sv_proc_fops }, |
| 150 | { "smart_thresholds", S_IFREG|S_IRUSR, &idedisk_st_proc_fops }, |
| 151 | {} |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 152 | }; |
| 153 | |
| 154 | ide_devset_rw_field(bios_cyl, bios_cyl); |
| 155 | ide_devset_rw_field(bios_head, bios_head); |
| 156 | ide_devset_rw_field(bios_sect, bios_sect); |
| 157 | ide_devset_rw_field(failures, failures); |
| 158 | ide_devset_rw_field(lun, lun); |
| 159 | ide_devset_rw_field(max_failures, max_failures); |
| 160 | |
| 161 | const struct ide_proc_devset ide_disk_settings[] = { |
| 162 | IDE_PROC_DEVSET(acoustic, 0, 254), |
| 163 | IDE_PROC_DEVSET(address, 0, 2), |
| 164 | IDE_PROC_DEVSET(bios_cyl, 0, 65535), |
| 165 | IDE_PROC_DEVSET(bios_head, 0, 255), |
| 166 | IDE_PROC_DEVSET(bios_sect, 0, 63), |
| 167 | IDE_PROC_DEVSET(failures, 0, 65535), |
| 168 | IDE_PROC_DEVSET(lun, 0, 7), |
| 169 | IDE_PROC_DEVSET(max_failures, 0, 65535), |
| 170 | IDE_PROC_DEVSET(multcount, 0, 16), |
| 171 | IDE_PROC_DEVSET(nowerr, 0, 1), |
| 172 | IDE_PROC_DEVSET(wcache, 0, 1), |
Hannes Eder | 71bfc7a | 2009-03-05 16:10:56 +0100 | [diff] [blame] | 173 | { NULL }, |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 174 | }; |