qla_attr.c 21 KB

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