ide-disk_proc.c 4.6 KB

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