blob: 0d1fae6cba6d571f3754bdffe6d209b57b150c73 [file] [log] [blame]
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +02001#include <linux/kernel.h>
2#include <linux/ide.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09003#include <linux/slab.h>
Paul Gortmaker38789fd2011-07-17 15:33:58 -04004#include <linux/export.h>
Alexey Dobriyan6d703a82009-09-01 17:52:57 -07005#include <linux/seq_file.h>
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +02006
7#include "ide-disk.h"
8
9static int smart_enable(ide_drive_t *drive)
10{
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010011 struct ide_cmd cmd;
12 struct ide_taskfile *tf = &cmd.tf;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020013
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010014 memset(&cmd, 0, sizeof(cmd));
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020015 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 Shtylyov60f85012009-04-08 14:13:01 +020019 cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
20 cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010021
22 return ide_no_data_taskfile(drive, &cmd);
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020023}
24
25static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
26{
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010027 struct ide_cmd cmd;
28 struct ide_taskfile *tf = &cmd.tf;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020029
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010030 memset(&cmd, 0, sizeof(cmd));
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020031 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 Shtylyov60f85012009-04-08 14:13:01 +020036 cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
37 cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
Bartlomiej Zolnierkiewicz0dfb9912009-03-27 12:46:39 +010038 cmd.protocol = ATA_PROT_PIO;
Bartlomiej Zolnierkiewicz39375852009-03-27 12:46:32 +010039
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010040 return ide_raw_taskfile(drive, &cmd, buf, 1);
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020041}
42
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070043static int idedisk_cache_proc_show(struct seq_file *m, void *v)
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020044{
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070045 ide_drive_t *drive = (ide_drive_t *) m->private;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020046
47 if (drive->dev_flags & IDE_DFLAG_ID_READ)
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070048 seq_printf(m, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020049 else
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070050 seq_printf(m, "(none)\n");
51 return 0;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020052}
53
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070054static int idedisk_cache_proc_open(struct inode *inode, struct file *file)
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020055{
Al Virod9dda782013-03-31 18:16:14 -040056 return single_open(file, idedisk_cache_proc_show, PDE_DATA(inode));
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020057}
58
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070059static 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
67static int idedisk_capacity_proc_show(struct seq_file *m, void *v)
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020068{
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070069 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
75static int idedisk_capacity_proc_open(struct inode *inode, struct file *file)
76{
Al Virod9dda782013-03-31 18:16:14 -040077 return single_open(file, idedisk_capacity_proc_show, PDE_DATA(inode));
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070078}
79
80static 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
88static 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 Zolnierkiewicz06b89512008-10-13 21:39:45 +020095
Bartlomiej Zolnierkiewicz39375852009-03-27 12:46:32 +010096 (void)smart_enable(drive);
97
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070098 if (get_smart_data(drive, buf, sub_cmd) == 0) {
99 __le16 *val = (__le16 *)buf;
100 int i;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200101
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700102 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 Zolnierkiewicz06b89512008-10-13 21:39:45 +0200106 }
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700107 kfree(buf);
108 return 0;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200109}
110
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700111static int idedisk_sv_proc_show(struct seq_file *m, void *v)
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200112{
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700113 return __idedisk_proc_show(m, m->private, ATA_SMART_READ_VALUES);
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200114}
115
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700116static int idedisk_sv_proc_open(struct inode *inode, struct file *file)
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200117{
Al Virod9dda782013-03-31 18:16:14 -0400118 return single_open(file, idedisk_sv_proc_show, PDE_DATA(inode));
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200119}
120
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700121static 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
129static 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
134static int idedisk_st_proc_open(struct inode *inode, struct file *file)
135{
Al Virod9dda782013-03-31 18:16:14 -0400136 return single_open(file, idedisk_st_proc_show, PDE_DATA(inode));
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700137}
138
139static 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 Zolnierkiewicz06b89512008-10-13 21:39:45 +0200147ide_proc_entry_t ide_disk_proc[] = {
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700148 { "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 Zolnierkiewicz06b89512008-10-13 21:39:45 +0200154};
155
156ide_devset_rw_field(bios_cyl, bios_cyl);
157ide_devset_rw_field(bios_head, bios_head);
158ide_devset_rw_field(bios_sect, bios_sect);
159ide_devset_rw_field(failures, failures);
160ide_devset_rw_field(lun, lun);
161ide_devset_rw_field(max_failures, max_failures);
162
163const 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 Eder71bfc7a2009-03-05 16:10:56 +0100175 { NULL },
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200176};