Blame view

drivers/ide/ide-disk_proc.c 4.61 KB
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
1
2
  #include <linux/kernel.h>
  #include <linux/ide.h>
5a0e3ad6a   Tejun Heo   include cleanup: ...
3
  #include <linux/slab.h>
38789fda2   Paul Gortmaker   ide/ata: Add expo...
4
  #include <linux/export.h>
6d703a81a   Alexey Dobriyan   ide: convert to -...
5
  #include <linux/seq_file.h>
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
6
7
8
9
10
  
  #include "ide-disk.h"
  
  static int smart_enable(ide_drive_t *drive)
  {
22aa4b32a   Bartlomiej Zolnierkiewicz   ide: remove ide_t...
11
12
  	struct ide_cmd cmd;
  	struct ide_taskfile *tf = &cmd.tf;
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
13

22aa4b32a   Bartlomiej Zolnierkiewicz   ide: remove ide_t...
14
  	memset(&cmd, 0, sizeof(cmd));
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
15
16
17
18
  	tf->feature = ATA_SMART_ENABLE;
  	tf->lbam    = ATA_SMART_LBAM_PASS;
  	tf->lbah    = ATA_SMART_LBAH_PASS;
  	tf->command = ATA_CMD_SMART;
60f85019c   Sergei Shtylyov   ide: replace IDE_...
19
20
  	cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
  	cmd.valid.in.tf  = IDE_VALID_IN_TF  | IDE_VALID_DEVICE;
22aa4b32a   Bartlomiej Zolnierkiewicz   ide: remove ide_t...
21
22
  
  	return ide_no_data_taskfile(drive, &cmd);
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
23
24
25
26
  }
  
  static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
  {
22aa4b32a   Bartlomiej Zolnierkiewicz   ide: remove ide_t...
27
28
  	struct ide_cmd cmd;
  	struct ide_taskfile *tf = &cmd.tf;
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
29

22aa4b32a   Bartlomiej Zolnierkiewicz   ide: remove ide_t...
30
  	memset(&cmd, 0, sizeof(cmd));
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
31
32
33
34
35
  	tf->feature = sub_cmd;
  	tf->nsect   = 0x01;
  	tf->lbam    = ATA_SMART_LBAM_PASS;
  	tf->lbah    = ATA_SMART_LBAH_PASS;
  	tf->command = ATA_CMD_SMART;
60f85019c   Sergei Shtylyov   ide: replace IDE_...
36
37
  	cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
  	cmd.valid.in.tf  = IDE_VALID_IN_TF  | IDE_VALID_DEVICE;
0dfb991c6   Bartlomiej Zolnierkiewicz   ide: use ata_tf_p...
38
  	cmd.protocol = ATA_PROT_PIO;
39375853d   Bartlomiej Zolnierkiewicz   ide: move smart_e...
39

22aa4b32a   Bartlomiej Zolnierkiewicz   ide: remove ide_t...
40
  	return ide_raw_taskfile(drive, &cmd, buf, 1);
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
41
  }
6d703a81a   Alexey Dobriyan   ide: convert to -...
42
  static int idedisk_cache_proc_show(struct seq_file *m, void *v)
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
43
  {
6d703a81a   Alexey Dobriyan   ide: convert to -...
44
  	ide_drive_t	*drive = (ide_drive_t *) m->private;
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
45
46
  
  	if (drive->dev_flags & IDE_DFLAG_ID_READ)
6d703a81a   Alexey Dobriyan   ide: convert to -...
47
48
  		seq_printf(m, "%i
  ", drive->id[ATA_ID_BUF_SIZE] / 2);
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
49
  	else
6d703a81a   Alexey Dobriyan   ide: convert to -...
50
51
52
53
  		seq_printf(m, "(none)
  ");
  	return 0;
  }
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
54

6d703a81a   Alexey Dobriyan   ide: convert to -...
55
56
57
  static int idedisk_cache_proc_open(struct inode *inode, struct file *file)
  {
  	return single_open(file, idedisk_cache_proc_show, PDE(inode)->data);
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
58
  }
6d703a81a   Alexey Dobriyan   ide: convert to -...
59
60
61
62
63
64
65
66
67
  static const struct file_operations idedisk_cache_proc_fops = {
  	.owner		= THIS_MODULE,
  	.open		= idedisk_cache_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
  
  static int idedisk_capacity_proc_show(struct seq_file *m, void *v)
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
68
  {
6d703a81a   Alexey Dobriyan   ide: convert to -...
69
  	ide_drive_t*drive = (ide_drive_t *)m->private;
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
70

6d703a81a   Alexey Dobriyan   ide: convert to -...
71
72
73
74
  	seq_printf(m, "%llu
  ", (long long)ide_gd_capacity(drive));
  	return 0;
  }
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
75

6d703a81a   Alexey Dobriyan   ide: convert to -...
76
77
78
  static int idedisk_capacity_proc_open(struct inode *inode, struct file *file)
  {
  	return single_open(file, idedisk_capacity_proc_show, PDE(inode)->data);
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
79
  }
6d703a81a   Alexey Dobriyan   ide: convert to -...
80
81
82
83
84
85
86
87
88
  static const struct file_operations idedisk_capacity_proc_fops = {
  	.owner		= THIS_MODULE,
  	.open		= idedisk_capacity_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
  
  static int __idedisk_proc_show(struct seq_file *m, ide_drive_t *drive, u8 sub_cmd)
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
89
  {
6d703a81a   Alexey Dobriyan   ide: convert to -...
90
91
92
93
94
  	u8 *buf;
  
  	buf = kmalloc(SECTOR_SIZE, GFP_KERNEL);
  	if (!buf)
  		return -ENOMEM;
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
95

39375853d   Bartlomiej Zolnierkiewicz   ide: move smart_e...
96
  	(void)smart_enable(drive);
6d703a81a   Alexey Dobriyan   ide: convert to -...
97
98
99
100
101
102
103
104
105
  	if (get_smart_data(drive, buf, sub_cmd) == 0) {
  		__le16 *val = (__le16 *)buf;
  		int i;
  
  		for (i = 0; i < SECTOR_SIZE / 2; i++) {
  			seq_printf(m, "%04x%c", le16_to_cpu(val[i]),
  					(i % 8) == 7 ? '
  ' : ' ');
  		}
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
106
  	}
6d703a81a   Alexey Dobriyan   ide: convert to -...
107
108
109
  	kfree(buf);
  	return 0;
  }
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
110

6d703a81a   Alexey Dobriyan   ide: convert to -...
111
112
113
  static int idedisk_sv_proc_show(struct seq_file *m, void *v)
  {
  	return __idedisk_proc_show(m, m->private, ATA_SMART_READ_VALUES);
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
114
  }
6d703a81a   Alexey Dobriyan   ide: convert to -...
115
  static int idedisk_sv_proc_open(struct inode *inode, struct file *file)
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
116
  {
6d703a81a   Alexey Dobriyan   ide: convert to -...
117
  	return single_open(file, idedisk_sv_proc_show, PDE(inode)->data);
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
118
  }
6d703a81a   Alexey Dobriyan   ide: convert to -...
119
120
121
122
123
124
125
126
127
  static const struct file_operations idedisk_sv_proc_fops = {
  	.owner		= THIS_MODULE,
  	.open		= idedisk_sv_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
  
  static int idedisk_st_proc_show(struct seq_file *m, void *v)
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
128
  {
6d703a81a   Alexey Dobriyan   ide: convert to -...
129
  	return __idedisk_proc_show(m, m->private, ATA_SMART_READ_THRESHOLDS);
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
130
  }
6d703a81a   Alexey Dobriyan   ide: convert to -...
131
132
133
134
135
136
137
138
139
140
141
142
  static int idedisk_st_proc_open(struct inode *inode, struct file *file)
  {
  	return single_open(file, idedisk_st_proc_show, PDE(inode)->data);
  }
  
  static const struct file_operations idedisk_st_proc_fops = {
  	.owner		= THIS_MODULE,
  	.open		= idedisk_st_proc_open,
  	.read		= seq_read,
  	.llseek		= seq_lseek,
  	.release	= single_release,
  };
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
143
  ide_proc_entry_t ide_disk_proc[] = {
6d703a81a   Alexey Dobriyan   ide: convert to -...
144
145
146
147
148
149
  	{ "cache",	  S_IFREG|S_IRUGO, &idedisk_cache_proc_fops	},
  	{ "capacity",	  S_IFREG|S_IRUGO, &idedisk_capacity_proc_fops	},
  	{ "geometry",	  S_IFREG|S_IRUGO, &ide_geometry_proc_fops	},
  	{ "smart_values", S_IFREG|S_IRUSR, &idedisk_sv_proc_fops	},
  	{ "smart_thresholds", S_IFREG|S_IRUSR, &idedisk_st_proc_fops	},
  	{}
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
  };
  
  ide_devset_rw_field(bios_cyl, bios_cyl);
  ide_devset_rw_field(bios_head, bios_head);
  ide_devset_rw_field(bios_sect, bios_sect);
  ide_devset_rw_field(failures, failures);
  ide_devset_rw_field(lun, lun);
  ide_devset_rw_field(max_failures, max_failures);
  
  const struct ide_proc_devset ide_disk_settings[] = {
  	IDE_PROC_DEVSET(acoustic,	0,   254),
  	IDE_PROC_DEVSET(address,	0,     2),
  	IDE_PROC_DEVSET(bios_cyl,	0, 65535),
  	IDE_PROC_DEVSET(bios_head,	0,   255),
  	IDE_PROC_DEVSET(bios_sect,	0,    63),
  	IDE_PROC_DEVSET(failures,	0, 65535),
  	IDE_PROC_DEVSET(lun,		0,     7),
  	IDE_PROC_DEVSET(max_failures,	0, 65535),
  	IDE_PROC_DEVSET(multcount,	0,    16),
  	IDE_PROC_DEVSET(nowerr,		0,     1),
  	IDE_PROC_DEVSET(wcache,		0,     1),
71bfc7a7c   Hannes Eder   ide: NULL noise: ...
171
  	{ NULL },
06b89518f   Bartlomiej Zolnierkiewicz   ide-disk: move /p...
172
  };