blob: 82a36ced4e968c4fe4e554128320853f15e83628 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +02002#include <linux/kernel.h>
3#include <linux/ide.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +09004#include <linux/slab.h>
Paul Gortmaker38789fd2011-07-17 15:33:58 -04005#include <linux/export.h>
Alexey Dobriyan6d703a82009-09-01 17:52:57 -07006#include <linux/seq_file.h>
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +02007
8#include "ide-disk.h"
9
10static int smart_enable(ide_drive_t *drive)
11{
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010012 struct ide_cmd cmd;
13 struct ide_taskfile *tf = &cmd.tf;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020014
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010015 memset(&cmd, 0, sizeof(cmd));
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020016 tf->feature = ATA_SMART_ENABLE;
17 tf->lbam = ATA_SMART_LBAM_PASS;
18 tf->lbah = ATA_SMART_LBAH_PASS;
19 tf->command = ATA_CMD_SMART;
Sergei Shtylyov60f85012009-04-08 14:13:01 +020020 cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
21 cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010022
23 return ide_no_data_taskfile(drive, &cmd);
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020024}
25
26static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
27{
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010028 struct ide_cmd cmd;
29 struct ide_taskfile *tf = &cmd.tf;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020030
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010031 memset(&cmd, 0, sizeof(cmd));
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020032 tf->feature = sub_cmd;
33 tf->nsect = 0x01;
34 tf->lbam = ATA_SMART_LBAM_PASS;
35 tf->lbah = ATA_SMART_LBAH_PASS;
36 tf->command = ATA_CMD_SMART;
Sergei Shtylyov60f85012009-04-08 14:13:01 +020037 cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
38 cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
Bartlomiej Zolnierkiewicz0dfb9912009-03-27 12:46:39 +010039 cmd.protocol = ATA_PROT_PIO;
Bartlomiej Zolnierkiewicz39375852009-03-27 12:46:32 +010040
Bartlomiej Zolnierkiewicz22aa4b32009-03-27 12:46:37 +010041 return ide_raw_taskfile(drive, &cmd, buf, 1);
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020042}
43
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070044static int idedisk_cache_proc_show(struct seq_file *m, void *v)
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020045{
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070046 ide_drive_t *drive = (ide_drive_t *) m->private;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020047
48 if (drive->dev_flags & IDE_DFLAG_ID_READ)
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070049 seq_printf(m, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020050 else
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070051 seq_printf(m, "(none)\n");
52 return 0;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020053}
54
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070055static int idedisk_cache_proc_open(struct inode *inode, struct file *file)
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020056{
Al Virod9dda782013-03-31 18:16:14 -040057 return single_open(file, idedisk_cache_proc_show, PDE_DATA(inode));
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020058}
59
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070060static const struct file_operations idedisk_cache_proc_fops = {
61 .owner = THIS_MODULE,
62 .open = idedisk_cache_proc_open,
63 .read = seq_read,
64 .llseek = seq_lseek,
65 .release = single_release,
66};
67
68static int idedisk_capacity_proc_show(struct seq_file *m, void *v)
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020069{
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070070 ide_drive_t*drive = (ide_drive_t *)m->private;
71
72 seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive));
73 return 0;
74}
75
76static int idedisk_capacity_proc_open(struct inode *inode, struct file *file)
77{
Al Virod9dda782013-03-31 18:16:14 -040078 return single_open(file, idedisk_capacity_proc_show, PDE_DATA(inode));
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070079}
80
81static const struct file_operations idedisk_capacity_proc_fops = {
82 .owner = THIS_MODULE,
83 .open = idedisk_capacity_proc_open,
84 .read = seq_read,
85 .llseek = seq_lseek,
86 .release = single_release,
87};
88
89static int __idedisk_proc_show(struct seq_file *m, ide_drive_t *drive, u8 sub_cmd)
90{
91 u8 *buf;
92
93 buf = kmalloc(SECTOR_SIZE, GFP_KERNEL);
94 if (!buf)
95 return -ENOMEM;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +020096
Bartlomiej Zolnierkiewicz39375852009-03-27 12:46:32 +010097 (void)smart_enable(drive);
98
Alexey Dobriyan6d703a82009-09-01 17:52:57 -070099 if (get_smart_data(drive, buf, sub_cmd) == 0) {
100 __le16 *val = (__le16 *)buf;
101 int i;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200102
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700103 for (i = 0; i < SECTOR_SIZE / 2; i++) {
104 seq_printf(m, "%04x%c", le16_to_cpu(val[i]),
105 (i % 8) == 7 ? '\n' : ' ');
106 }
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200107 }
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700108 kfree(buf);
109 return 0;
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200110}
111
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700112static int idedisk_sv_proc_show(struct seq_file *m, void *v)
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200113{
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700114 return __idedisk_proc_show(m, m->private, ATA_SMART_READ_VALUES);
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200115}
116
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700117static int idedisk_sv_proc_open(struct inode *inode, struct file *file)
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200118{
Al Virod9dda782013-03-31 18:16:14 -0400119 return single_open(file, idedisk_sv_proc_show, PDE_DATA(inode));
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200120}
121
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700122static const struct file_operations idedisk_sv_proc_fops = {
123 .owner = THIS_MODULE,
124 .open = idedisk_sv_proc_open,
125 .read = seq_read,
126 .llseek = seq_lseek,
127 .release = single_release,
128};
129
130static int idedisk_st_proc_show(struct seq_file *m, void *v)
131{
132 return __idedisk_proc_show(m, m->private, ATA_SMART_READ_THRESHOLDS);
133}
134
135static int idedisk_st_proc_open(struct inode *inode, struct file *file)
136{
Al Virod9dda782013-03-31 18:16:14 -0400137 return single_open(file, idedisk_st_proc_show, PDE_DATA(inode));
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700138}
139
140static const struct file_operations idedisk_st_proc_fops = {
141 .owner = THIS_MODULE,
142 .open = idedisk_st_proc_open,
143 .read = seq_read,
144 .llseek = seq_lseek,
145 .release = single_release,
146};
147
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200148ide_proc_entry_t ide_disk_proc[] = {
Alexey Dobriyan6d703a82009-09-01 17:52:57 -0700149 { "cache", S_IFREG|S_IRUGO, &idedisk_cache_proc_fops },
150 { "capacity", S_IFREG|S_IRUGO, &idedisk_capacity_proc_fops },
151 { "geometry", S_IFREG|S_IRUGO, &ide_geometry_proc_fops },
152 { "smart_values", S_IFREG|S_IRUSR, &idedisk_sv_proc_fops },
153 { "smart_thresholds", S_IFREG|S_IRUSR, &idedisk_st_proc_fops },
154 {}
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200155};
156
157ide_devset_rw_field(bios_cyl, bios_cyl);
158ide_devset_rw_field(bios_head, bios_head);
159ide_devset_rw_field(bios_sect, bios_sect);
160ide_devset_rw_field(failures, failures);
161ide_devset_rw_field(lun, lun);
162ide_devset_rw_field(max_failures, max_failures);
163
164const struct ide_proc_devset ide_disk_settings[] = {
165 IDE_PROC_DEVSET(acoustic, 0, 254),
166 IDE_PROC_DEVSET(address, 0, 2),
167 IDE_PROC_DEVSET(bios_cyl, 0, 65535),
168 IDE_PROC_DEVSET(bios_head, 0, 255),
169 IDE_PROC_DEVSET(bios_sect, 0, 63),
170 IDE_PROC_DEVSET(failures, 0, 65535),
171 IDE_PROC_DEVSET(lun, 0, 7),
172 IDE_PROC_DEVSET(max_failures, 0, 65535),
173 IDE_PROC_DEVSET(multcount, 0, 16),
174 IDE_PROC_DEVSET(nowerr, 0, 1),
175 IDE_PROC_DEVSET(wcache, 0, 1),
Hannes Eder71bfc7a2009-03-05 16:10:56 +0100176 { NULL },
Bartlomiej Zolnierkiewicz06b89512008-10-13 21:39:45 +0200177};