ide-disk_proc.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/kernel.h>
  3. #include <linux/ide.h>
  4. #include <linux/slab.h>
  5. #include <linux/export.h>
  6. #include <linux/seq_file.h>
  7. #include "ide-disk.h"
  8. static int smart_enable(ide_drive_t *drive)
  9. {
  10. struct ide_cmd cmd;
  11. struct ide_taskfile *tf = &cmd.tf;
  12. memset(&cmd, 0, sizeof(cmd));
  13. tf->feature = ATA_SMART_ENABLE;
  14. tf->lbam = ATA_SMART_LBAM_PASS;
  15. tf->lbah = ATA_SMART_LBAH_PASS;
  16. tf->command = ATA_CMD_SMART;
  17. cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
  18. cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
  19. return ide_no_data_taskfile(drive, &cmd);
  20. }
  21. static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
  22. {
  23. struct ide_cmd cmd;
  24. struct ide_taskfile *tf = &cmd.tf;
  25. memset(&cmd, 0, sizeof(cmd));
  26. tf->feature = sub_cmd;
  27. tf->nsect = 0x01;
  28. tf->lbam = ATA_SMART_LBAM_PASS;
  29. tf->lbah = ATA_SMART_LBAH_PASS;
  30. tf->command = ATA_CMD_SMART;
  31. cmd.valid.out.tf = IDE_VALID_OUT_TF | IDE_VALID_DEVICE;
  32. cmd.valid.in.tf = IDE_VALID_IN_TF | IDE_VALID_DEVICE;
  33. cmd.protocol = ATA_PROT_PIO;
  34. return ide_raw_taskfile(drive, &cmd, buf, 1);
  35. }
  36. static int idedisk_cache_proc_show(struct seq_file *m, void *v)
  37. {
  38. ide_drive_t *drive = (ide_drive_t *) m->private;
  39. if (drive->dev_flags & IDE_DFLAG_ID_READ)
  40. seq_printf(m, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
  41. else
  42. seq_printf(m, "(none)\n");
  43. return 0;
  44. }
  45. static int idedisk_cache_proc_open(struct inode *inode, struct file *file)
  46. {
  47. return single_open(file, idedisk_cache_proc_show, PDE_DATA(inode));
  48. }
  49. static const struct file_operations idedisk_cache_proc_fops = {
  50. .owner = THIS_MODULE,
  51. .open = idedisk_cache_proc_open,
  52. .read = seq_read,
  53. .llseek = seq_lseek,
  54. .release = single_release,
  55. };
  56. static int idedisk_capacity_proc_show(struct seq_file *m, void *v)
  57. {
  58. ide_drive_t*drive = (ide_drive_t *)m->private;
  59. seq_printf(m, "%llu\n", (long long)ide_gd_capacity(drive));
  60. return 0;
  61. }
  62. static int idedisk_capacity_proc_open(struct inode *inode, struct file *file)
  63. {
  64. return single_open(file, idedisk_capacity_proc_show, PDE_DATA(inode));
  65. }
  66. static const struct file_operations idedisk_capacity_proc_fops = {
  67. .owner = THIS_MODULE,
  68. .open = idedisk_capacity_proc_open,
  69. .read = seq_read,
  70. .llseek = seq_lseek,
  71. .release = single_release,
  72. };
  73. static int __idedisk_proc_show(struct seq_file *m, ide_drive_t *drive, u8 sub_cmd)
  74. {
  75. u8 *buf;
  76. buf = kmalloc(SECTOR_SIZE, GFP_KERNEL);
  77. if (!buf)
  78. return -ENOMEM;
  79. (void)smart_enable(drive);
  80. if (get_smart_data(drive, buf, sub_cmd) == 0) {
  81. __le16 *val = (__le16 *)buf;
  82. int i;
  83. for (i = 0; i < SECTOR_SIZE / 2; i++) {
  84. seq_printf(m, "%04x%c", le16_to_cpu(val[i]),
  85. (i % 8) == 7 ? '\n' : ' ');
  86. }
  87. }
  88. kfree(buf);
  89. return 0;
  90. }
  91. static int idedisk_sv_proc_show(struct seq_file *m, void *v)
  92. {
  93. return __idedisk_proc_show(m, m->private, ATA_SMART_READ_VALUES);
  94. }
  95. static int idedisk_sv_proc_open(struct inode *inode, struct file *file)
  96. {
  97. return single_open(file, idedisk_sv_proc_show, PDE_DATA(inode));
  98. }
  99. static const struct file_operations idedisk_sv_proc_fops = {
  100. .owner = THIS_MODULE,
  101. .open = idedisk_sv_proc_open,
  102. .read = seq_read,
  103. .llseek = seq_lseek,
  104. .release = single_release,
  105. };
  106. static int idedisk_st_proc_show(struct seq_file *m, void *v)
  107. {
  108. return __idedisk_proc_show(m, m->private, ATA_SMART_READ_THRESHOLDS);
  109. }
  110. static int idedisk_st_proc_open(struct inode *inode, struct file *file)
  111. {
  112. return single_open(file, idedisk_st_proc_show, PDE_DATA(inode));
  113. }
  114. static const struct file_operations idedisk_st_proc_fops = {
  115. .owner = THIS_MODULE,
  116. .open = idedisk_st_proc_open,
  117. .read = seq_read,
  118. .llseek = seq_lseek,
  119. .release = single_release,
  120. };
  121. ide_proc_entry_t ide_disk_proc[] = {
  122. { "cache", S_IFREG|S_IRUGO, &idedisk_cache_proc_fops },
  123. { "capacity", S_IFREG|S_IRUGO, &idedisk_capacity_proc_fops },
  124. { "geometry", S_IFREG|S_IRUGO, &ide_geometry_proc_fops },
  125. { "smart_values", S_IFREG|S_IRUSR, &idedisk_sv_proc_fops },
  126. { "smart_thresholds", S_IFREG|S_IRUSR, &idedisk_st_proc_fops },
  127. {}
  128. };
  129. ide_devset_rw_field(bios_cyl, bios_cyl);
  130. ide_devset_rw_field(bios_head, bios_head);
  131. ide_devset_rw_field(bios_sect, bios_sect);
  132. ide_devset_rw_field(failures, failures);
  133. ide_devset_rw_field(lun, lun);
  134. ide_devset_rw_field(max_failures, max_failures);
  135. const struct ide_proc_devset ide_disk_settings[] = {
  136. IDE_PROC_DEVSET(acoustic, 0, 254),
  137. IDE_PROC_DEVSET(address, 0, 2),
  138. IDE_PROC_DEVSET(bios_cyl, 0, 65535),
  139. IDE_PROC_DEVSET(bios_head, 0, 255),
  140. IDE_PROC_DEVSET(bios_sect, 0, 63),
  141. IDE_PROC_DEVSET(failures, 0, 65535),
  142. IDE_PROC_DEVSET(lun, 0, 7),
  143. IDE_PROC_DEVSET(max_failures, 0, 65535),
  144. IDE_PROC_DEVSET(multcount, 0, 16),
  145. IDE_PROC_DEVSET(nowerr, 0, 1),
  146. IDE_PROC_DEVSET(wcache, 0, 1),
  147. { NULL },
  148. };