qla_attr.c 20 KB

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