1 #include <linux/kernel.h>
6 static int smart_enable(ide_drive_t *drive)
9 struct ide_taskfile *tf = &cmd.tf;
11 memset(&cmd, 0, sizeof(cmd));
12 tf->feature = ATA_SMART_ENABLE;
13 tf->lbam = ATA_SMART_LBAM_PASS;
14 tf->lbah = ATA_SMART_LBAH_PASS;
15 tf->command = ATA_CMD_SMART;
16 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
18 return ide_no_data_taskfile(drive, &cmd);
21 static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
24 struct ide_taskfile *tf = &cmd.tf;
26 memset(&cmd, 0, sizeof(cmd));
27 tf->feature = sub_cmd;
29 tf->lbam = ATA_SMART_LBAM_PASS;
30 tf->lbah = ATA_SMART_LBAH_PASS;
31 tf->command = ATA_CMD_SMART;
32 cmd.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
33 cmd.protocol = ATA_PROT_PIO;
35 return ide_raw_taskfile(drive, &cmd, buf, 1);
38 static int proc_idedisk_read_cache
39 (char *page, char **start, off_t off, int count, int *eof, void *data)
41 ide_drive_t *drive = (ide_drive_t *) data;
45 if (drive->dev_flags & IDE_DFLAG_ID_READ)
46 len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
48 len = sprintf(out, "(none)\n");
50 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
53 static int proc_idedisk_read_capacity
54 (char *page, char **start, off_t off, int count, int *eof, void *data)
56 ide_drive_t*drive = (ide_drive_t *)data;
59 len = sprintf(page, "%llu\n", (long long)ide_gd_capacity(drive));
61 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
64 static int proc_idedisk_read_smart(char *page, char **start, off_t off,
65 int count, int *eof, void *data, u8 sub_cmd)
67 ide_drive_t *drive = (ide_drive_t *)data;
70 (void)smart_enable(drive);
72 if (get_smart_data(drive, page, sub_cmd) == 0) {
73 unsigned short *val = (unsigned short *) page;
74 char *out = (char *)val + SECTOR_SIZE;
78 out += sprintf(out, "%04x%c", le16_to_cpu(*val),
79 (++i & 7) ? ' ' : '\n');
81 } while (i < SECTOR_SIZE / 2);
85 PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
88 static int proc_idedisk_read_sv
89 (char *page, char **start, off_t off, int count, int *eof, void *data)
91 return proc_idedisk_read_smart(page, start, off, count, eof, data,
92 ATA_SMART_READ_VALUES);
95 static int proc_idedisk_read_st
96 (char *page, char **start, off_t off, int count, int *eof, void *data)
98 return proc_idedisk_read_smart(page, start, off, count, eof, data,
99 ATA_SMART_READ_THRESHOLDS);
102 ide_proc_entry_t ide_disk_proc[] = {
103 { "cache", S_IFREG|S_IRUGO, proc_idedisk_read_cache, NULL },
104 { "capacity", S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
105 { "geometry", S_IFREG|S_IRUGO, proc_ide_read_geometry, NULL },
106 { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv, NULL },
107 { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st, NULL },
108 { NULL, 0, NULL, NULL }
111 ide_devset_rw_field(bios_cyl, bios_cyl);
112 ide_devset_rw_field(bios_head, bios_head);
113 ide_devset_rw_field(bios_sect, bios_sect);
114 ide_devset_rw_field(failures, failures);
115 ide_devset_rw_field(lun, lun);
116 ide_devset_rw_field(max_failures, max_failures);
118 const struct ide_proc_devset ide_disk_settings[] = {
119 IDE_PROC_DEVSET(acoustic, 0, 254),
120 IDE_PROC_DEVSET(address, 0, 2),
121 IDE_PROC_DEVSET(bios_cyl, 0, 65535),
122 IDE_PROC_DEVSET(bios_head, 0, 255),
123 IDE_PROC_DEVSET(bios_sect, 0, 63),
124 IDE_PROC_DEVSET(failures, 0, 65535),
125 IDE_PROC_DEVSET(lun, 0, 7),
126 IDE_PROC_DEVSET(max_failures, 0, 65535),
127 IDE_PROC_DEVSET(multcount, 0, 16),
128 IDE_PROC_DEVSET(nowerr, 0, 1),
129 IDE_PROC_DEVSET(wcache, 0, 1),