ide-disk_proc.c 4.6 KB

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