ql4_attr.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2011 QLogic Corporation
  4. *
  5. * See LICENSE.qla4xxx for copyright and licensing details.
  6. */
  7. #include "ql4_def.h"
  8. #include "ql4_glbl.h"
  9. #include "ql4_dbg.h"
  10. static ssize_t
  11. qla4_8xxx_sysfs_read_fw_dump(struct file *filep, struct kobject *kobj,
  12. struct bin_attribute *ba, char *buf, loff_t off,
  13. size_t count)
  14. {
  15. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  16. struct device, kobj)));
  17. if (is_qla40XX(ha))
  18. return -EINVAL;
  19. if (!test_bit(AF_82XX_DUMP_READING, &ha->flags))
  20. return 0;
  21. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  22. ha->fw_dump_size);
  23. }
  24. static ssize_t
  25. qla4_8xxx_sysfs_write_fw_dump(struct file *filep, struct kobject *kobj,
  26. struct bin_attribute *ba, char *buf, loff_t off,
  27. size_t count)
  28. {
  29. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  30. struct device, kobj)));
  31. uint32_t dev_state;
  32. long reading;
  33. int ret = 0;
  34. if (is_qla40XX(ha))
  35. return -EINVAL;
  36. if (off != 0)
  37. return ret;
  38. buf[1] = 0;
  39. ret = kstrtol(buf, 10, &reading);
  40. if (ret) {
  41. ql4_printk(KERN_ERR, ha, "%s: Invalid input. Return err %d\n",
  42. __func__, ret);
  43. return ret;
  44. }
  45. switch (reading) {
  46. case 0:
  47. /* clear dump collection flags */
  48. if (test_and_clear_bit(AF_82XX_DUMP_READING, &ha->flags)) {
  49. clear_bit(AF_82XX_FW_DUMPED, &ha->flags);
  50. /* Reload minidump template */
  51. qla4xxx_alloc_fw_dump(ha);
  52. DEBUG2(ql4_printk(KERN_INFO, ha,
  53. "Firmware template reloaded\n"));
  54. }
  55. break;
  56. case 1:
  57. /* Set flag to read dump */
  58. if (test_bit(AF_82XX_FW_DUMPED, &ha->flags) &&
  59. !test_bit(AF_82XX_DUMP_READING, &ha->flags)) {
  60. set_bit(AF_82XX_DUMP_READING, &ha->flags);
  61. DEBUG2(ql4_printk(KERN_INFO, ha,
  62. "Raw firmware dump ready for read on (%ld).\n",
  63. ha->host_no));
  64. }
  65. break;
  66. case 2:
  67. /* Reset HBA and collect FW dump */
  68. ha->isp_ops->idc_lock(ha);
  69. dev_state = qla4_8xxx_rd_direct(ha, QLA8XXX_CRB_DEV_STATE);
  70. if (dev_state == QLA8XXX_DEV_READY) {
  71. ql4_printk(KERN_INFO, ha, "%s: Setting Need reset\n",
  72. __func__);
  73. qla4_8xxx_wr_direct(ha, QLA8XXX_CRB_DEV_STATE,
  74. QLA8XXX_DEV_NEED_RESET);
  75. if (is_qla8022(ha) ||
  76. (is_qla8032(ha) &&
  77. qla4_83xx_can_perform_reset(ha))) {
  78. set_bit(AF_8XXX_RST_OWNER, &ha->flags);
  79. set_bit(AF_FW_RECOVERY, &ha->flags);
  80. ql4_printk(KERN_INFO, ha, "%s: Reset owner is 0x%x\n",
  81. __func__, ha->func_num);
  82. }
  83. } else
  84. ql4_printk(KERN_INFO, ha,
  85. "%s: Reset not performed as device state is 0x%x\n",
  86. __func__, dev_state);
  87. ha->isp_ops->idc_unlock(ha);
  88. break;
  89. default:
  90. /* do nothing */
  91. break;
  92. }
  93. return count;
  94. }
  95. static struct bin_attribute sysfs_fw_dump_attr = {
  96. .attr = {
  97. .name = "fw_dump",
  98. .mode = S_IRUSR | S_IWUSR,
  99. },
  100. .size = 0,
  101. .read = qla4_8xxx_sysfs_read_fw_dump,
  102. .write = qla4_8xxx_sysfs_write_fw_dump,
  103. };
  104. static struct sysfs_entry {
  105. char *name;
  106. struct bin_attribute *attr;
  107. } bin_file_entries[] = {
  108. { "fw_dump", &sysfs_fw_dump_attr },
  109. { NULL },
  110. };
  111. void qla4_8xxx_alloc_sysfs_attr(struct scsi_qla_host *ha)
  112. {
  113. struct Scsi_Host *host = ha->host;
  114. struct sysfs_entry *iter;
  115. int ret;
  116. for (iter = bin_file_entries; iter->name; iter++) {
  117. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  118. iter->attr);
  119. if (ret)
  120. ql4_printk(KERN_ERR, ha,
  121. "Unable to create sysfs %s binary attribute (%d).\n",
  122. iter->name, ret);
  123. }
  124. }
  125. void qla4_8xxx_free_sysfs_attr(struct scsi_qla_host *ha)
  126. {
  127. struct Scsi_Host *host = ha->host;
  128. struct sysfs_entry *iter;
  129. for (iter = bin_file_entries; iter->name; iter++)
  130. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  131. iter->attr);
  132. }
  133. /* Scsi_Host attributes. */
  134. static ssize_t
  135. qla4xxx_fw_version_show(struct device *dev,
  136. struct device_attribute *attr, char *buf)
  137. {
  138. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  139. if (is_qla80XX(ha))
  140. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  141. ha->firmware_version[0],
  142. ha->firmware_version[1],
  143. ha->patch_number, ha->build_number);
  144. else
  145. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d.%02d\n",
  146. ha->firmware_version[0],
  147. ha->firmware_version[1],
  148. ha->patch_number, ha->build_number);
  149. }
  150. static ssize_t
  151. qla4xxx_serial_num_show(struct device *dev, struct device_attribute *attr,
  152. char *buf)
  153. {
  154. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  155. return snprintf(buf, PAGE_SIZE, "%s\n", ha->serial_number);
  156. }
  157. static ssize_t
  158. qla4xxx_iscsi_version_show(struct device *dev, struct device_attribute *attr,
  159. char *buf)
  160. {
  161. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  162. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->iscsi_major,
  163. ha->iscsi_minor);
  164. }
  165. static ssize_t
  166. qla4xxx_optrom_version_show(struct device *dev, struct device_attribute *attr,
  167. char *buf)
  168. {
  169. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  170. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d.%02d\n",
  171. ha->bootload_major, ha->bootload_minor,
  172. ha->bootload_patch, ha->bootload_build);
  173. }
  174. static ssize_t
  175. qla4xxx_board_id_show(struct device *dev, struct device_attribute *attr,
  176. char *buf)
  177. {
  178. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  179. return snprintf(buf, PAGE_SIZE, "0x%08X\n", ha->board_id);
  180. }
  181. static ssize_t
  182. qla4xxx_fw_state_show(struct device *dev, struct device_attribute *attr,
  183. char *buf)
  184. {
  185. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  186. qla4xxx_get_firmware_state(ha);
  187. return snprintf(buf, PAGE_SIZE, "0x%08X%8X\n", ha->firmware_state,
  188. ha->addl_fw_state);
  189. }
  190. static ssize_t
  191. qla4xxx_phy_port_cnt_show(struct device *dev, struct device_attribute *attr,
  192. char *buf)
  193. {
  194. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  195. if (is_qla40XX(ha))
  196. return -ENOSYS;
  197. return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_cnt);
  198. }
  199. static ssize_t
  200. qla4xxx_phy_port_num_show(struct device *dev, struct device_attribute *attr,
  201. char *buf)
  202. {
  203. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  204. if (is_qla40XX(ha))
  205. return -ENOSYS;
  206. return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_num);
  207. }
  208. static ssize_t
  209. qla4xxx_iscsi_func_cnt_show(struct device *dev, struct device_attribute *attr,
  210. char *buf)
  211. {
  212. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  213. if (is_qla40XX(ha))
  214. return -ENOSYS;
  215. return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->iscsi_pci_func_cnt);
  216. }
  217. static ssize_t
  218. qla4xxx_hba_model_show(struct device *dev, struct device_attribute *attr,
  219. char *buf)
  220. {
  221. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  222. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_name);
  223. }
  224. static DEVICE_ATTR(fw_version, S_IRUGO, qla4xxx_fw_version_show, NULL);
  225. static DEVICE_ATTR(serial_num, S_IRUGO, qla4xxx_serial_num_show, NULL);
  226. static DEVICE_ATTR(iscsi_version, S_IRUGO, qla4xxx_iscsi_version_show, NULL);
  227. static DEVICE_ATTR(optrom_version, S_IRUGO, qla4xxx_optrom_version_show, NULL);
  228. static DEVICE_ATTR(board_id, S_IRUGO, qla4xxx_board_id_show, NULL);
  229. static DEVICE_ATTR(fw_state, S_IRUGO, qla4xxx_fw_state_show, NULL);
  230. static DEVICE_ATTR(phy_port_cnt, S_IRUGO, qla4xxx_phy_port_cnt_show, NULL);
  231. static DEVICE_ATTR(phy_port_num, S_IRUGO, qla4xxx_phy_port_num_show, NULL);
  232. static DEVICE_ATTR(iscsi_func_cnt, S_IRUGO, qla4xxx_iscsi_func_cnt_show, NULL);
  233. static DEVICE_ATTR(hba_model, S_IRUGO, qla4xxx_hba_model_show, NULL);
  234. struct device_attribute *qla4xxx_host_attrs[] = {
  235. &dev_attr_fw_version,
  236. &dev_attr_serial_num,
  237. &dev_attr_iscsi_version,
  238. &dev_attr_optrom_version,
  239. &dev_attr_board_id,
  240. &dev_attr_fw_state,
  241. &dev_attr_phy_port_cnt,
  242. &dev_attr_phy_port_num,
  243. &dev_attr_iscsi_func_cnt,
  244. &dev_attr_hba_model,
  245. NULL,
  246. };