ql4_attr.c 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351
  1. /*
  2. * QLogic iSCSI HBA Driver
  3. * Copyright (c) 2003-2013 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) || is_qla8042(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->fw_info.fw_major, ha->fw_info.fw_minor,
  142. ha->fw_info.fw_patch, ha->fw_info.fw_build);
  143. else
  144. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d.%02d\n",
  145. ha->fw_info.fw_major, ha->fw_info.fw_minor,
  146. ha->fw_info.fw_patch, ha->fw_info.fw_build);
  147. }
  148. static ssize_t
  149. qla4xxx_serial_num_show(struct device *dev, struct device_attribute *attr,
  150. char *buf)
  151. {
  152. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  153. return snprintf(buf, PAGE_SIZE, "%s\n", ha->serial_number);
  154. }
  155. static ssize_t
  156. qla4xxx_iscsi_version_show(struct device *dev, struct device_attribute *attr,
  157. char *buf)
  158. {
  159. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  160. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fw_info.iscsi_major,
  161. ha->fw_info.iscsi_minor);
  162. }
  163. static ssize_t
  164. qla4xxx_optrom_version_show(struct device *dev, struct device_attribute *attr,
  165. char *buf)
  166. {
  167. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  168. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d.%02d\n",
  169. ha->fw_info.bootload_major, ha->fw_info.bootload_minor,
  170. ha->fw_info.bootload_patch, ha->fw_info.bootload_build);
  171. }
  172. static ssize_t
  173. qla4xxx_board_id_show(struct device *dev, struct device_attribute *attr,
  174. char *buf)
  175. {
  176. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  177. return snprintf(buf, PAGE_SIZE, "0x%08X\n", ha->board_id);
  178. }
  179. static ssize_t
  180. qla4xxx_fw_state_show(struct device *dev, struct device_attribute *attr,
  181. char *buf)
  182. {
  183. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  184. qla4xxx_get_firmware_state(ha);
  185. return snprintf(buf, PAGE_SIZE, "0x%08X%8X\n", ha->firmware_state,
  186. ha->addl_fw_state);
  187. }
  188. static ssize_t
  189. qla4xxx_phy_port_cnt_show(struct device *dev, struct device_attribute *attr,
  190. char *buf)
  191. {
  192. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  193. if (is_qla40XX(ha))
  194. return -ENOSYS;
  195. return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_cnt);
  196. }
  197. static ssize_t
  198. qla4xxx_phy_port_num_show(struct device *dev, struct device_attribute *attr,
  199. char *buf)
  200. {
  201. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  202. if (is_qla40XX(ha))
  203. return -ENOSYS;
  204. return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->phy_port_num);
  205. }
  206. static ssize_t
  207. qla4xxx_iscsi_func_cnt_show(struct device *dev, struct device_attribute *attr,
  208. char *buf)
  209. {
  210. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  211. if (is_qla40XX(ha))
  212. return -ENOSYS;
  213. return snprintf(buf, PAGE_SIZE, "0x%04X\n", ha->iscsi_pci_func_cnt);
  214. }
  215. static ssize_t
  216. qla4xxx_hba_model_show(struct device *dev, struct device_attribute *attr,
  217. char *buf)
  218. {
  219. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  220. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_name);
  221. }
  222. static ssize_t
  223. qla4xxx_fw_timestamp_show(struct device *dev, struct device_attribute *attr,
  224. char *buf)
  225. {
  226. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  227. return snprintf(buf, PAGE_SIZE, "%s %s\n", ha->fw_info.fw_build_date,
  228. ha->fw_info.fw_build_time);
  229. }
  230. static ssize_t
  231. qla4xxx_fw_build_user_show(struct device *dev, struct device_attribute *attr,
  232. char *buf)
  233. {
  234. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  235. return snprintf(buf, PAGE_SIZE, "%s\n", ha->fw_info.fw_build_user);
  236. }
  237. static ssize_t
  238. qla4xxx_fw_ext_timestamp_show(struct device *dev, struct device_attribute *attr,
  239. char *buf)
  240. {
  241. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  242. return snprintf(buf, PAGE_SIZE, "%s\n", ha->fw_info.extended_timestamp);
  243. }
  244. static ssize_t
  245. qla4xxx_fw_load_src_show(struct device *dev, struct device_attribute *attr,
  246. char *buf)
  247. {
  248. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  249. char *load_src = NULL;
  250. switch (ha->fw_info.fw_load_source) {
  251. case 1:
  252. load_src = "Flash Primary";
  253. break;
  254. case 2:
  255. load_src = "Flash Secondary";
  256. break;
  257. case 3:
  258. load_src = "Host Download";
  259. break;
  260. }
  261. return snprintf(buf, PAGE_SIZE, "%s\n", load_src);
  262. }
  263. static ssize_t
  264. qla4xxx_fw_uptime_show(struct device *dev, struct device_attribute *attr,
  265. char *buf)
  266. {
  267. struct scsi_qla_host *ha = to_qla_host(class_to_shost(dev));
  268. qla4xxx_about_firmware(ha);
  269. return snprintf(buf, PAGE_SIZE, "%u.%u secs\n", ha->fw_uptime_secs,
  270. ha->fw_uptime_msecs);
  271. }
  272. static DEVICE_ATTR(fw_version, S_IRUGO, qla4xxx_fw_version_show, NULL);
  273. static DEVICE_ATTR(serial_num, S_IRUGO, qla4xxx_serial_num_show, NULL);
  274. static DEVICE_ATTR(iscsi_version, S_IRUGO, qla4xxx_iscsi_version_show, NULL);
  275. static DEVICE_ATTR(optrom_version, S_IRUGO, qla4xxx_optrom_version_show, NULL);
  276. static DEVICE_ATTR(board_id, S_IRUGO, qla4xxx_board_id_show, NULL);
  277. static DEVICE_ATTR(fw_state, S_IRUGO, qla4xxx_fw_state_show, NULL);
  278. static DEVICE_ATTR(phy_port_cnt, S_IRUGO, qla4xxx_phy_port_cnt_show, NULL);
  279. static DEVICE_ATTR(phy_port_num, S_IRUGO, qla4xxx_phy_port_num_show, NULL);
  280. static DEVICE_ATTR(iscsi_func_cnt, S_IRUGO, qla4xxx_iscsi_func_cnt_show, NULL);
  281. static DEVICE_ATTR(hba_model, S_IRUGO, qla4xxx_hba_model_show, NULL);
  282. static DEVICE_ATTR(fw_timestamp, S_IRUGO, qla4xxx_fw_timestamp_show, NULL);
  283. static DEVICE_ATTR(fw_build_user, S_IRUGO, qla4xxx_fw_build_user_show, NULL);
  284. static DEVICE_ATTR(fw_ext_timestamp, S_IRUGO, qla4xxx_fw_ext_timestamp_show,
  285. NULL);
  286. static DEVICE_ATTR(fw_load_src, S_IRUGO, qla4xxx_fw_load_src_show, NULL);
  287. static DEVICE_ATTR(fw_uptime, S_IRUGO, qla4xxx_fw_uptime_show, NULL);
  288. struct device_attribute *qla4xxx_host_attrs[] = {
  289. &dev_attr_fw_version,
  290. &dev_attr_serial_num,
  291. &dev_attr_iscsi_version,
  292. &dev_attr_optrom_version,
  293. &dev_attr_board_id,
  294. &dev_attr_fw_state,
  295. &dev_attr_phy_port_cnt,
  296. &dev_attr_phy_port_num,
  297. &dev_attr_iscsi_func_cnt,
  298. &dev_attr_hba_model,
  299. &dev_attr_fw_timestamp,
  300. &dev_attr_fw_build_user,
  301. &dev_attr_fw_ext_timestamp,
  302. &dev_attr_fw_load_src,
  303. &dev_attr_fw_uptime,
  304. NULL,
  305. };