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