qla_attr.c 21 KB

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