Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 2 | #include <linux/kernel.h> |
| 3 | #include <linux/ide.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 4 | #include <linux/slab.h> |
Paul Gortmaker | 38789fd | 2011-07-17 15:33:58 -0400 | [diff] [blame] | 5 | #include <linux/export.h> |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 6 | #include <linux/seq_file.h> |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 7 | |
| 8 | #include "ide-disk.h" |
| 9 | |
| 10 | static int smart_enable(ide_drive_t *drive) |
| 11 | { |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 12 | struct ide_cmd cmd; |
| 13 | struct ide_taskfile *tf = &cmd.tf; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 14 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 15 | memset(&cmd, 0, sizeof(cmd)); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 16 | 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 Shtylyov | 60f8501 | 2009-04-08 14:13:01 +0200 | [diff] [blame] | 20 | cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE; |
| 21 | cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE; |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 22 | |
| 23 | return ide_no_data_taskfile(drive, &cmd); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 24 | } |
| 25 | |
| 26 | static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd) |
| 27 | { |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 28 | struct ide_cmd cmd; |
| 29 | struct ide_taskfile *tf = &cmd.tf; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 30 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 31 | memset(&cmd, 0, sizeof(cmd)); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 32 | 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 Shtylyov | 60f8501 | 2009-04-08 14:13:01 +0200 | [diff] [blame] | 37 | cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE; |
| 38 | cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE; |
Bartlomiej Zolnierkiewicz | 0dfb991 | 2009-03-27 12:46:39 +0100 | [diff] [blame] | 39 | cmd.protocol = ATA_PROT_PIO; |
Bartlomiej Zolnierkiewicz | 3937585 | 2009-03-27 12:46:32 +0100 | [diff] [blame] | 40 | |
Bartlomiej Zolnierkiewicz | 22aa4b3 | 2009-03-27 12:46:37 +0100 | [diff] [blame] | 41 | return ide_raw_taskfile(drive, &cmd, buf, 1); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 42 | } |
| 43 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 44 | static int idedisk_cache_proc_show(struct seq_file *m, void *v) |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 45 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 46 | ide_drive_t *drive = (ide_drive_t *) m->private; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 47 | |
| 48 | if (drive->dev_flags & IDE_DFLAG_ID_READ) |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 49 | seq_printf(m, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 50 | else |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 51 | seq_printf(m, "(none)\n"); |
| 52 | return 0; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 53 | } |
| 54 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 55 | static int idedisk_capacity_proc_show(struct seq_file *m, void *v) |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 56 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 57 | ide_drive_t*drive = (ide_drive_t *)m->private; |
| 58 | |
| 59 | seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive)); |
| 60 | return 0; |
| 61 | } |
| 62 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 63 | static int __idedisk_proc_show(struct seq_file *m, ide_drive_t *drive, u8 sub_cmd) |
| 64 | { |
| 65 | u8 *buf; |
| 66 | |
| 67 | buf = kmalloc(SECTOR_SIZE, GFP_KERNEL); |
| 68 | if (!buf) |
| 69 | return -ENOMEM; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 70 | |
Bartlomiej Zolnierkiewicz | 3937585 | 2009-03-27 12:46:32 +0100 | [diff] [blame] | 71 | (void)smart_enable(drive); |
| 72 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 73 | if (get_smart_data(drive, buf, sub_cmd) == 0) { |
| 74 | __le16 *val = (__le16 *)buf; |
| 75 | int i; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 76 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 77 | for (i = 0; i < SECTOR_SIZE / 2; i++) { |
| 78 | seq_printf(m, "%04x%c", le16_to_cpu(val[i]), |
| 79 | (i % 8) == 7 ? '\n' : ' '); |
| 80 | } |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 81 | } |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 82 | kfree(buf); |
| 83 | return 0; |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 84 | } |
| 85 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 86 | static int idedisk_sv_proc_show(struct seq_file *m, void *v) |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 87 | { |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 88 | return __idedisk_proc_show(m, m->private, ATA_SMART_READ_VALUES); |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 89 | } |
| 90 | |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 91 | static int idedisk_st_proc_show(struct seq_file *m, void *v) |
| 92 | { |
| 93 | return __idedisk_proc_show(m, m->private, ATA_SMART_READ_THRESHOLDS); |
| 94 | } |
| 95 | |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 96 | ide_proc_entry_t ide_disk_proc[] = { |
Christoph Hellwig | ec7d9c9 | 2018-04-13 21:25:54 +0200 | [diff] [blame] | 97 | { "cache", S_IFREG|S_IRUGO, idedisk_cache_proc_show }, |
| 98 | { "capacity", S_IFREG|S_IRUGO, idedisk_capacity_proc_show }, |
| 99 | { "geometry", S_IFREG|S_IRUGO, ide_geometry_proc_show }, |
| 100 | { "smart_values", S_IFREG|S_IRUSR, idedisk_sv_proc_show }, |
| 101 | { "smart_thresholds", S_IFREG|S_IRUSR, idedisk_st_proc_show }, |
Alexey Dobriyan | 6d703a8 | 2009-09-01 17:52:57 -0700 | [diff] [blame] | 102 | {} |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 103 | }; |
| 104 | |
| 105 | ide_devset_rw_field(bios_cyl, bios_cyl); |
| 106 | ide_devset_rw_field(bios_head, bios_head); |
| 107 | ide_devset_rw_field(bios_sect, bios_sect); |
| 108 | ide_devset_rw_field(failures, failures); |
| 109 | ide_devset_rw_field(lun, lun); |
| 110 | ide_devset_rw_field(max_failures, max_failures); |
| 111 | |
| 112 | const struct ide_proc_devset ide_disk_settings[] = { |
| 113 | IDE_PROC_DEVSET(acoustic, 0, 254), |
| 114 | IDE_PROC_DEVSET(address, 0, 2), |
| 115 | IDE_PROC_DEVSET(bios_cyl, 0, 65535), |
| 116 | IDE_PROC_DEVSET(bios_head, 0, 255), |
| 117 | IDE_PROC_DEVSET(bios_sect, 0, 63), |
| 118 | IDE_PROC_DEVSET(failures, 0, 65535), |
| 119 | IDE_PROC_DEVSET(lun, 0, 7), |
| 120 | IDE_PROC_DEVSET(max_failures, 0, 65535), |
| 121 | IDE_PROC_DEVSET(multcount, 0, 16), |
| 122 | IDE_PROC_DEVSET(nowerr, 0, 1), |
| 123 | IDE_PROC_DEVSET(wcache, 0, 1), |
Hannes Eder | 71bfc7a | 2009-03-05 16:10:56 +0100 | [diff] [blame] | 124 | { NULL }, |
Bartlomiej Zolnierkiewicz | 06b8951 | 2008-10-13 21:39:45 +0200 | [diff] [blame] | 125 | }; |