qla_attr.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679
  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 || count != ha->nvram_size)
  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 (count);
  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 = 0,
  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_nvram_attr.size = ha->nvram_size;
  161. sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
  162. }
  163. void
  164. qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
  165. {
  166. struct Scsi_Host *host = ha->host;
  167. sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
  168. sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
  169. if (ha->beacon_blink_led == 1)
  170. ha->isp_ops.beacon_off(ha);
  171. }
  172. /* Scsi_Host attributes. */
  173. static ssize_t
  174. qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
  175. {
  176. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  177. }
  178. static ssize_t
  179. qla2x00_fw_version_show(struct class_device *cdev, char *buf)
  180. {
  181. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  182. char fw_str[30];
  183. return snprintf(buf, PAGE_SIZE, "%s\n",
  184. ha->isp_ops.fw_version_str(ha, fw_str));
  185. }
  186. static ssize_t
  187. qla2x00_serial_num_show(struct class_device *cdev, char *buf)
  188. {
  189. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  190. uint32_t sn;
  191. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  192. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  193. sn % 100000);
  194. }
  195. static ssize_t
  196. qla2x00_isp_name_show(struct class_device *cdev, char *buf)
  197. {
  198. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  199. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  200. }
  201. static ssize_t
  202. qla2x00_isp_id_show(struct class_device *cdev, char *buf)
  203. {
  204. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  205. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  206. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  207. ha->product_id[3]);
  208. }
  209. static ssize_t
  210. qla2x00_model_name_show(struct class_device *cdev, char *buf)
  211. {
  212. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  213. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  214. }
  215. static ssize_t
  216. qla2x00_model_desc_show(struct class_device *cdev, char *buf)
  217. {
  218. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  219. return snprintf(buf, PAGE_SIZE, "%s\n",
  220. ha->model_desc ? ha->model_desc: "");
  221. }
  222. static ssize_t
  223. qla2x00_pci_info_show(struct class_device *cdev, char *buf)
  224. {
  225. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  226. char pci_info[30];
  227. return snprintf(buf, PAGE_SIZE, "%s\n",
  228. ha->isp_ops.pci_info_str(ha, pci_info));
  229. }
  230. static ssize_t
  231. qla2x00_state_show(struct class_device *cdev, char *buf)
  232. {
  233. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  234. int len = 0;
  235. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  236. atomic_read(&ha->loop_state) == LOOP_DEAD)
  237. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  238. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  239. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  240. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  241. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  242. else {
  243. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  244. switch (ha->current_topology) {
  245. case ISP_CFG_NL:
  246. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  247. break;
  248. case ISP_CFG_FL:
  249. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  250. break;
  251. case ISP_CFG_N:
  252. len += snprintf(buf + len, PAGE_SIZE-len,
  253. "N_Port to N_Port\n");
  254. break;
  255. case ISP_CFG_F:
  256. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  257. break;
  258. default:
  259. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  260. break;
  261. }
  262. }
  263. return len;
  264. }
  265. static ssize_t
  266. qla2x00_zio_show(struct class_device *cdev, char *buf)
  267. {
  268. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  269. int len = 0;
  270. switch (ha->zio_mode) {
  271. case QLA_ZIO_MODE_5:
  272. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 5\n");
  273. break;
  274. case QLA_ZIO_MODE_6:
  275. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  276. break;
  277. case QLA_ZIO_DISABLED:
  278. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  279. break;
  280. }
  281. return len;
  282. }
  283. static ssize_t
  284. qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
  285. {
  286. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  287. int val = 0;
  288. uint16_t zio_mode;
  289. if (sscanf(buf, "%d", &val) != 1)
  290. return -EINVAL;
  291. switch (val) {
  292. case 1:
  293. zio_mode = QLA_ZIO_MODE_5;
  294. break;
  295. case 2:
  296. zio_mode = QLA_ZIO_MODE_6;
  297. break;
  298. default:
  299. zio_mode = QLA_ZIO_DISABLED;
  300. break;
  301. }
  302. /* Update per-hba values and queue a reset. */
  303. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  304. ha->zio_mode = zio_mode;
  305. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  306. }
  307. return strlen(buf);
  308. }
  309. static ssize_t
  310. qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
  311. {
  312. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  313. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  314. }
  315. static ssize_t
  316. qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
  317. size_t count)
  318. {
  319. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  320. int val = 0;
  321. uint16_t zio_timer;
  322. if (sscanf(buf, "%d", &val) != 1)
  323. return -EINVAL;
  324. if (val > 25500 || val < 100)
  325. return -ERANGE;
  326. zio_timer = (uint16_t)(val / 100);
  327. ha->zio_timer = zio_timer;
  328. return strlen(buf);
  329. }
  330. static ssize_t
  331. qla2x00_beacon_show(struct class_device *cdev, char *buf)
  332. {
  333. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  334. int len = 0;
  335. if (ha->beacon_blink_led)
  336. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  337. else
  338. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  339. return len;
  340. }
  341. static ssize_t
  342. qla2x00_beacon_store(struct class_device *cdev, const char *buf,
  343. size_t count)
  344. {
  345. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  346. int val = 0;
  347. int rval;
  348. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  349. return -EPERM;
  350. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  351. qla_printk(KERN_WARNING, ha,
  352. "Abort ISP active -- ignoring beacon request.\n");
  353. return -EBUSY;
  354. }
  355. if (sscanf(buf, "%d", &val) != 1)
  356. return -EINVAL;
  357. if (val)
  358. rval = ha->isp_ops.beacon_on(ha);
  359. else
  360. rval = ha->isp_ops.beacon_off(ha);
  361. if (rval != QLA_SUCCESS)
  362. count = 0;
  363. return count;
  364. }
  365. static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
  366. NULL);
  367. static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  368. static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  369. static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  370. static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  371. static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  372. static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  373. static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  374. static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
  375. static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
  376. qla2x00_zio_store);
  377. static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  378. qla2x00_zio_timer_store);
  379. static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  380. qla2x00_beacon_store);
  381. struct class_device_attribute *qla2x00_host_attrs[] = {
  382. &class_device_attr_driver_version,
  383. &class_device_attr_fw_version,
  384. &class_device_attr_serial_num,
  385. &class_device_attr_isp_name,
  386. &class_device_attr_isp_id,
  387. &class_device_attr_model_name,
  388. &class_device_attr_model_desc,
  389. &class_device_attr_pci_info,
  390. &class_device_attr_state,
  391. &class_device_attr_zio,
  392. &class_device_attr_zio_timer,
  393. &class_device_attr_beacon,
  394. NULL,
  395. };
  396. /* Host attributes. */
  397. static void
  398. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  399. {
  400. scsi_qla_host_t *ha = to_qla_host(shost);
  401. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  402. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  403. }
  404. static void
  405. qla2x00_get_host_speed(struct Scsi_Host *shost)
  406. {
  407. scsi_qla_host_t *ha = to_qla_host(shost);
  408. uint32_t speed = 0;
  409. switch (ha->link_data_rate) {
  410. case LDR_1GB:
  411. speed = 1;
  412. break;
  413. case LDR_2GB:
  414. speed = 2;
  415. break;
  416. case LDR_4GB:
  417. speed = 4;
  418. break;
  419. }
  420. fc_host_speed(shost) = speed;
  421. }
  422. static void
  423. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  424. {
  425. scsi_qla_host_t *ha = to_qla_host(shost);
  426. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  427. switch (ha->current_topology) {
  428. case ISP_CFG_NL:
  429. port_type = FC_PORTTYPE_LPORT;
  430. break;
  431. case ISP_CFG_FL:
  432. port_type = FC_PORTTYPE_NLPORT;
  433. break;
  434. case ISP_CFG_N:
  435. port_type = FC_PORTTYPE_PTP;
  436. break;
  437. case ISP_CFG_F:
  438. port_type = FC_PORTTYPE_NPORT;
  439. break;
  440. }
  441. fc_host_port_type(shost) = port_type;
  442. }
  443. static void
  444. qla2x00_get_starget_node_name(struct scsi_target *starget)
  445. {
  446. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  447. scsi_qla_host_t *ha = to_qla_host(host);
  448. fc_port_t *fcport;
  449. u64 node_name = 0;
  450. list_for_each_entry(fcport, &ha->fcports, list) {
  451. if (starget->id == fcport->os_target_id) {
  452. node_name = wwn_to_u64(fcport->node_name);
  453. break;
  454. }
  455. }
  456. fc_starget_node_name(starget) = node_name;
  457. }
  458. static void
  459. qla2x00_get_starget_port_name(struct scsi_target *starget)
  460. {
  461. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  462. scsi_qla_host_t *ha = to_qla_host(host);
  463. fc_port_t *fcport;
  464. u64 port_name = 0;
  465. list_for_each_entry(fcport, &ha->fcports, list) {
  466. if (starget->id == fcport->os_target_id) {
  467. port_name = wwn_to_u64(fcport->port_name);
  468. break;
  469. }
  470. }
  471. fc_starget_port_name(starget) = port_name;
  472. }
  473. static void
  474. qla2x00_get_starget_port_id(struct scsi_target *starget)
  475. {
  476. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  477. scsi_qla_host_t *ha = to_qla_host(host);
  478. fc_port_t *fcport;
  479. uint32_t port_id = ~0U;
  480. list_for_each_entry(fcport, &ha->fcports, list) {
  481. if (starget->id == fcport->os_target_id) {
  482. port_id = fcport->d_id.b.domain << 16 |
  483. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  484. break;
  485. }
  486. }
  487. fc_starget_port_id(starget) = port_id;
  488. }
  489. static void
  490. qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
  491. {
  492. struct Scsi_Host *host = rport_to_shost(rport);
  493. scsi_qla_host_t *ha = to_qla_host(host);
  494. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  495. }
  496. static void
  497. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  498. {
  499. struct Scsi_Host *host = rport_to_shost(rport);
  500. scsi_qla_host_t *ha = to_qla_host(host);
  501. if (timeout)
  502. ha->port_down_retry_count = timeout;
  503. else
  504. ha->port_down_retry_count = 1;
  505. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  506. }
  507. static int
  508. qla2x00_issue_lip(struct Scsi_Host *shost)
  509. {
  510. scsi_qla_host_t *ha = to_qla_host(shost);
  511. set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
  512. return 0;
  513. }
  514. static struct fc_host_statistics *
  515. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  516. {
  517. scsi_qla_host_t *ha = to_qla_host(shost);
  518. int rval;
  519. uint16_t mb_stat[1];
  520. link_stat_t stat_buf;
  521. struct fc_host_statistics *pfc_host_stat;
  522. pfc_host_stat = &ha->fc_host_stat;
  523. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  524. if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
  525. rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
  526. sizeof(stat_buf) / 4, mb_stat);
  527. } else {
  528. rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
  529. mb_stat);
  530. }
  531. if (rval != 0) {
  532. qla_printk(KERN_WARNING, ha,
  533. "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
  534. return pfc_host_stat;
  535. }
  536. pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
  537. pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
  538. pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
  539. pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
  540. pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
  541. pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
  542. return pfc_host_stat;
  543. }
  544. struct fc_function_template qla2xxx_transport_functions = {
  545. .show_host_node_name = 1,
  546. .show_host_port_name = 1,
  547. .show_host_supported_classes = 1,
  548. .get_host_port_id = qla2x00_get_host_port_id,
  549. .show_host_port_id = 1,
  550. .get_host_speed = qla2x00_get_host_speed,
  551. .show_host_speed = 1,
  552. .get_host_port_type = qla2x00_get_host_port_type,
  553. .show_host_port_type = 1,
  554. .dd_fcrport_size = sizeof(struct fc_port *),
  555. .show_rport_supported_classes = 1,
  556. .get_starget_node_name = qla2x00_get_starget_node_name,
  557. .show_starget_node_name = 1,
  558. .get_starget_port_name = qla2x00_get_starget_port_name,
  559. .show_starget_port_name = 1,
  560. .get_starget_port_id = qla2x00_get_starget_port_id,
  561. .show_starget_port_id = 1,
  562. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  563. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  564. .show_rport_dev_loss_tmo = 1,
  565. .issue_fc_host_lip = qla2x00_issue_lip,
  566. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  567. };
  568. void
  569. qla2x00_init_host_attr(scsi_qla_host_t *ha)
  570. {
  571. fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
  572. fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
  573. fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
  574. }