ql4_attr.c 9.6 KB

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