qla_attr.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2005 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/vmalloc.h>
  9. /* SYSFS attributes --------------------------------------------------------- */
  10. static ssize_t
  11. qla2x00_sysfs_read_fw_dump(struct kobject *kobj, 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 (ha->fw_dump_reading == 0)
  17. return 0;
  18. if (off > ha->fw_dump_buffer_len)
  19. return 0;
  20. if (off + count > ha->fw_dump_buffer_len)
  21. count = ha->fw_dump_buffer_len - off;
  22. memcpy(buf, &ha->fw_dump_buffer[off], count);
  23. return (count);
  24. }
  25. static ssize_t
  26. qla2x00_sysfs_write_fw_dump(struct kobject *kobj, 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. int reading;
  32. uint32_t dump_size;
  33. if (off != 0)
  34. return (0);
  35. reading = simple_strtol(buf, NULL, 10);
  36. switch (reading) {
  37. case 0:
  38. if (ha->fw_dump_reading == 1) {
  39. qla_printk(KERN_INFO, ha,
  40. "Firmware dump cleared on (%ld).\n",
  41. ha->host_no);
  42. vfree(ha->fw_dump_buffer);
  43. if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
  44. free_pages((unsigned long)ha->fw_dump,
  45. ha->fw_dump_order);
  46. ha->fw_dump_reading = 0;
  47. ha->fw_dump_buffer = NULL;
  48. ha->fw_dump = NULL;
  49. ha->fw_dumped = 0;
  50. }
  51. break;
  52. case 1:
  53. if ((ha->fw_dump || ha->fw_dumped) && !ha->fw_dump_reading) {
  54. ha->fw_dump_reading = 1;
  55. if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
  56. dump_size = FW_DUMP_SIZE_24XX;
  57. else {
  58. dump_size = FW_DUMP_SIZE_1M;
  59. if (ha->fw_memory_size < 0x20000)
  60. dump_size = FW_DUMP_SIZE_128K;
  61. else if (ha->fw_memory_size < 0x80000)
  62. dump_size = FW_DUMP_SIZE_512K;
  63. }
  64. ha->fw_dump_buffer = (char *)vmalloc(dump_size);
  65. if (ha->fw_dump_buffer == NULL) {
  66. qla_printk(KERN_WARNING, ha,
  67. "Unable to allocate memory for firmware "
  68. "dump buffer (%d).\n", dump_size);
  69. ha->fw_dump_reading = 0;
  70. return (count);
  71. }
  72. qla_printk(KERN_INFO, ha,
  73. "Firmware dump ready for read on (%ld).\n",
  74. ha->host_no);
  75. memset(ha->fw_dump_buffer, 0, dump_size);
  76. ha->isp_ops.ascii_fw_dump(ha);
  77. ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
  78. }
  79. break;
  80. }
  81. return (count);
  82. }
  83. static struct bin_attribute sysfs_fw_dump_attr = {
  84. .attr = {
  85. .name = "fw_dump",
  86. .mode = S_IRUSR | S_IWUSR,
  87. .owner = THIS_MODULE,
  88. },
  89. .size = 0,
  90. .read = qla2x00_sysfs_read_fw_dump,
  91. .write = qla2x00_sysfs_write_fw_dump,
  92. };
  93. static ssize_t
  94. qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off,
  95. size_t count)
  96. {
  97. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  98. struct device, kobj)));
  99. unsigned long flags;
  100. if (!capable(CAP_SYS_ADMIN) || off != 0)
  101. return 0;
  102. /* Read NVRAM. */
  103. spin_lock_irqsave(&ha->hardware_lock, flags);
  104. ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
  105. ha->nvram_size);
  106. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  107. return ha->nvram_size;
  108. }
  109. static ssize_t
  110. qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
  111. size_t count)
  112. {
  113. struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
  114. struct device, kobj)));
  115. unsigned long flags;
  116. uint16_t cnt;
  117. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
  118. return 0;
  119. /* Checksum NVRAM. */
  120. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  121. uint32_t *iter;
  122. uint32_t chksum;
  123. iter = (uint32_t *)buf;
  124. chksum = 0;
  125. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  126. chksum += le32_to_cpu(*iter++);
  127. chksum = ~chksum + 1;
  128. *iter = cpu_to_le32(chksum);
  129. } else {
  130. uint8_t *iter;
  131. uint8_t chksum;
  132. iter = (uint8_t *)buf;
  133. chksum = 0;
  134. for (cnt = 0; cnt < count - 1; cnt++)
  135. chksum += *iter++;
  136. chksum = ~chksum + 1;
  137. *iter = chksum;
  138. }
  139. /* Write NVRAM. */
  140. spin_lock_irqsave(&ha->hardware_lock, flags);
  141. ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
  142. spin_unlock_irqrestore(&ha->hardware_lock, flags);
  143. return (count);
  144. }
  145. static struct bin_attribute sysfs_nvram_attr = {
  146. .attr = {
  147. .name = "nvram",
  148. .mode = S_IRUSR | S_IWUSR,
  149. .owner = THIS_MODULE,
  150. },
  151. .size = 512,
  152. .read = qla2x00_sysfs_read_nvram,
  153. .write = qla2x00_sysfs_write_nvram,
  154. };
  155. void
  156. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
  157. {
  158. struct Scsi_Host *host = ha->host;
  159. sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
  160. sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
  161. }
  162. void
  163. qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
  164. {
  165. struct Scsi_Host *host = ha->host;
  166. sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
  167. sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
  168. if (ha->beacon_blink_led == 1)
  169. ha->isp_ops.beacon_off(ha);
  170. }
  171. /* Scsi_Host attributes. */
  172. static ssize_t
  173. qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
  174. {
  175. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  176. }
  177. static ssize_t
  178. qla2x00_fw_version_show(struct class_device *cdev, char *buf)
  179. {
  180. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  181. char fw_str[30];
  182. return snprintf(buf, PAGE_SIZE, "%s\n",
  183. ha->isp_ops.fw_version_str(ha, fw_str));
  184. }
  185. static ssize_t
  186. qla2x00_serial_num_show(struct class_device *cdev, char *buf)
  187. {
  188. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  189. uint32_t sn;
  190. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  191. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  192. sn % 100000);
  193. }
  194. static ssize_t
  195. qla2x00_isp_name_show(struct class_device *cdev, char *buf)
  196. {
  197. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  198. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  199. }
  200. static ssize_t
  201. qla2x00_isp_id_show(struct class_device *cdev, char *buf)
  202. {
  203. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  204. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  205. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  206. ha->product_id[3]);
  207. }
  208. static ssize_t
  209. qla2x00_model_name_show(struct class_device *cdev, char *buf)
  210. {
  211. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  212. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  213. }
  214. static ssize_t
  215. qla2x00_model_desc_show(struct class_device *cdev, char *buf)
  216. {
  217. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  218. return snprintf(buf, PAGE_SIZE, "%s\n",
  219. ha->model_desc ? ha->model_desc: "");
  220. }
  221. static ssize_t
  222. qla2x00_pci_info_show(struct class_device *cdev, char *buf)
  223. {
  224. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  225. char pci_info[30];
  226. return snprintf(buf, PAGE_SIZE, "%s\n",
  227. ha->isp_ops.pci_info_str(ha, pci_info));
  228. }
  229. static ssize_t
  230. qla2x00_state_show(struct class_device *cdev, char *buf)
  231. {
  232. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  233. int len = 0;
  234. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  235. atomic_read(&ha->loop_state) == LOOP_DEAD)
  236. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  237. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  238. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  239. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  240. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  241. else {
  242. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  243. switch (ha->current_topology) {
  244. case ISP_CFG_NL:
  245. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  246. break;
  247. case ISP_CFG_FL:
  248. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  249. break;
  250. case ISP_CFG_N:
  251. len += snprintf(buf + len, PAGE_SIZE-len,
  252. "N_Port to N_Port\n");
  253. break;
  254. case ISP_CFG_F:
  255. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  256. break;
  257. default:
  258. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  259. break;
  260. }
  261. }
  262. return len;
  263. }
  264. static ssize_t
  265. qla2x00_zio_show(struct class_device *cdev, char *buf)
  266. {
  267. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  268. int len = 0;
  269. switch (ha->zio_mode) {
  270. case QLA_ZIO_MODE_5:
  271. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 5\n");
  272. break;
  273. case QLA_ZIO_MODE_6:
  274. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  275. break;
  276. case QLA_ZIO_DISABLED:
  277. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  278. break;
  279. }
  280. return len;
  281. }
  282. static ssize_t
  283. qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
  284. {
  285. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  286. int val = 0;
  287. uint16_t zio_mode;
  288. if (sscanf(buf, "%d", &val) != 1)
  289. return -EINVAL;
  290. switch (val) {
  291. case 1:
  292. zio_mode = QLA_ZIO_MODE_5;
  293. break;
  294. case 2:
  295. zio_mode = QLA_ZIO_MODE_6;
  296. break;
  297. default:
  298. zio_mode = QLA_ZIO_DISABLED;
  299. break;
  300. }
  301. /* Update per-hba values and queue a reset. */
  302. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  303. ha->zio_mode = zio_mode;
  304. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  305. }
  306. return strlen(buf);
  307. }
  308. static ssize_t
  309. qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
  310. {
  311. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  312. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  313. }
  314. static ssize_t
  315. qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
  316. size_t count)
  317. {
  318. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  319. int val = 0;
  320. uint16_t zio_timer;
  321. if (sscanf(buf, "%d", &val) != 1)
  322. return -EINVAL;
  323. if (val > 25500 || val < 100)
  324. return -ERANGE;
  325. zio_timer = (uint16_t)(val / 100);
  326. ha->zio_timer = zio_timer;
  327. return strlen(buf);
  328. }
  329. static ssize_t
  330. qla2x00_beacon_show(struct class_device *cdev, char *buf)
  331. {
  332. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  333. int len = 0;
  334. if (ha->beacon_blink_led)
  335. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  336. else
  337. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  338. return len;
  339. }
  340. static ssize_t
  341. qla2x00_beacon_store(struct class_device *cdev, const char *buf,
  342. size_t count)
  343. {
  344. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  345. int val = 0;
  346. int rval;
  347. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  348. return -EPERM;
  349. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  350. qla_printk(KERN_WARNING, ha,
  351. "Abort ISP active -- ignoring beacon request.\n");
  352. return -EBUSY;
  353. }
  354. if (sscanf(buf, "%d", &val) != 1)
  355. return -EINVAL;
  356. if (val)
  357. rval = ha->isp_ops.beacon_on(ha);
  358. else
  359. rval = ha->isp_ops.beacon_off(ha);
  360. if (rval != QLA_SUCCESS)
  361. count = 0;
  362. return count;
  363. }
  364. static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
  365. NULL);
  366. static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  367. static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  368. static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  369. static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  370. static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  371. static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  372. static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  373. static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
  374. static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
  375. qla2x00_zio_store);
  376. static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  377. qla2x00_zio_timer_store);
  378. static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  379. qla2x00_beacon_store);
  380. struct class_device_attribute *qla2x00_host_attrs[] = {
  381. &class_device_attr_driver_version,
  382. &class_device_attr_fw_version,
  383. &class_device_attr_serial_num,
  384. &class_device_attr_isp_name,
  385. &class_device_attr_isp_id,
  386. &class_device_attr_model_name,
  387. &class_device_attr_model_desc,
  388. &class_device_attr_pci_info,
  389. &class_device_attr_state,
  390. &class_device_attr_zio,
  391. &class_device_attr_zio_timer,
  392. &class_device_attr_beacon,
  393. NULL,
  394. };
  395. /* Host attributes. */
  396. static void
  397. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  398. {
  399. scsi_qla_host_t *ha = to_qla_host(shost);
  400. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  401. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  402. }
  403. static void
  404. qla2x00_get_host_speed(struct Scsi_Host *shost)
  405. {
  406. scsi_qla_host_t *ha = to_qla_host(shost);
  407. uint32_t speed = 0;
  408. switch (ha->link_data_rate) {
  409. case LDR_1GB:
  410. speed = 1;
  411. break;
  412. case LDR_2GB:
  413. speed = 2;
  414. break;
  415. case LDR_4GB:
  416. speed = 4;
  417. break;
  418. }
  419. fc_host_speed(shost) = speed;
  420. }
  421. static void
  422. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  423. {
  424. scsi_qla_host_t *ha = to_qla_host(shost);
  425. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  426. switch (ha->current_topology) {
  427. case ISP_CFG_NL:
  428. port_type = FC_PORTTYPE_LPORT;
  429. break;
  430. case ISP_CFG_FL:
  431. port_type = FC_PORTTYPE_NLPORT;
  432. break;
  433. case ISP_CFG_N:
  434. port_type = FC_PORTTYPE_PTP;
  435. break;
  436. case ISP_CFG_F:
  437. port_type = FC_PORTTYPE_NPORT;
  438. break;
  439. }
  440. fc_host_port_type(shost) = port_type;
  441. }
  442. static void
  443. qla2x00_get_starget_node_name(struct scsi_target *starget)
  444. {
  445. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  446. scsi_qla_host_t *ha = to_qla_host(host);
  447. fc_port_t *fcport;
  448. u64 node_name = 0;
  449. list_for_each_entry(fcport, &ha->fcports, list) {
  450. if (starget->id == fcport->os_target_id) {
  451. node_name = wwn_to_u64(fcport->node_name);
  452. break;
  453. }
  454. }
  455. fc_starget_node_name(starget) = node_name;
  456. }
  457. static void
  458. qla2x00_get_starget_port_name(struct scsi_target *starget)
  459. {
  460. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  461. scsi_qla_host_t *ha = to_qla_host(host);
  462. fc_port_t *fcport;
  463. u64 port_name = 0;
  464. list_for_each_entry(fcport, &ha->fcports, list) {
  465. if (starget->id == fcport->os_target_id) {
  466. port_name = wwn_to_u64(fcport->port_name);
  467. break;
  468. }
  469. }
  470. fc_starget_port_name(starget) = port_name;
  471. }
  472. static void
  473. qla2x00_get_starget_port_id(struct scsi_target *starget)
  474. {
  475. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  476. scsi_qla_host_t *ha = to_qla_host(host);
  477. fc_port_t *fcport;
  478. uint32_t port_id = ~0U;
  479. list_for_each_entry(fcport, &ha->fcports, list) {
  480. if (starget->id == fcport->os_target_id) {
  481. port_id = fcport->d_id.b.domain << 16 |
  482. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  483. break;
  484. }
  485. }
  486. fc_starget_port_id(starget) = port_id;
  487. }
  488. static void
  489. qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
  490. {
  491. struct Scsi_Host *host = rport_to_shost(rport);
  492. scsi_qla_host_t *ha = to_qla_host(host);
  493. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  494. }
  495. static void
  496. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  497. {
  498. struct Scsi_Host *host = rport_to_shost(rport);
  499. scsi_qla_host_t *ha = to_qla_host(host);
  500. if (timeout)
  501. ha->port_down_retry_count = timeout;
  502. else
  503. ha->port_down_retry_count = 1;
  504. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  505. }
  506. static int
  507. qla2x00_issue_lip(struct Scsi_Host *shost)
  508. {
  509. scsi_qla_host_t *ha = to_qla_host(shost);
  510. set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
  511. return 0;
  512. }
  513. static struct fc_host_statistics *
  514. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  515. {
  516. scsi_qla_host_t *ha = to_qla_host(shost);
  517. int rval;
  518. uint16_t mb_stat[1];
  519. link_stat_t stat_buf;
  520. struct fc_host_statistics *pfc_host_stat;
  521. pfc_host_stat = &ha->fc_host_stat;
  522. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  523. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  524. rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
  525. sizeof(stat_buf) / 4, mb_stat);
  526. } else {
  527. rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
  528. mb_stat);
  529. }
  530. if (rval != 0) {
  531. qla_printk(KERN_WARNING, ha,
  532. "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
  533. return pfc_host_stat;
  534. }
  535. pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
  536. pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
  537. pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
  538. pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
  539. pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
  540. pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
  541. return pfc_host_stat;
  542. }
  543. struct fc_function_template qla2xxx_transport_functions = {
  544. .show_host_node_name = 1,
  545. .show_host_port_name = 1,
  546. .show_host_supported_classes = 1,
  547. .get_host_port_id = qla2x00_get_host_port_id,
  548. .show_host_port_id = 1,
  549. .get_host_speed = qla2x00_get_host_speed,
  550. .show_host_speed = 1,
  551. .get_host_port_type = qla2x00_get_host_port_type,
  552. .show_host_port_type = 1,
  553. .dd_fcrport_size = sizeof(struct fc_port *),
  554. .show_rport_supported_classes = 1,
  555. .get_starget_node_name = qla2x00_get_starget_node_name,
  556. .show_starget_node_name = 1,
  557. .get_starget_port_name = qla2x00_get_starget_port_name,
  558. .show_starget_port_name = 1,
  559. .get_starget_port_id = qla2x00_get_starget_port_id,
  560. .show_starget_port_id = 1,
  561. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  562. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  563. .show_rport_dev_loss_tmo = 1,
  564. .issue_fc_host_lip = qla2x00_issue_lip,
  565. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  566. };
  567. void
  568. qla2x00_init_host_attr(scsi_qla_host_t *ha)
  569. {
  570. fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
  571. fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
  572. fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
  573. }