qla_attr.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  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. void
  264. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
  265. {
  266. struct Scsi_Host *host = ha->host;
  267. sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
  268. sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
  269. sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
  270. sysfs_create_bin_file(&host->shost_gendev.kobj,
  271. &sysfs_optrom_ctl_attr);
  272. }
  273. void
  274. qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
  275. {
  276. struct Scsi_Host *host = ha->host;
  277. sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
  278. sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
  279. sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_optrom_attr);
  280. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  281. &sysfs_optrom_ctl_attr);
  282. if (ha->beacon_blink_led == 1)
  283. ha->isp_ops.beacon_off(ha);
  284. }
  285. /* Scsi_Host attributes. */
  286. static ssize_t
  287. qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
  288. {
  289. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  290. }
  291. static ssize_t
  292. qla2x00_fw_version_show(struct class_device *cdev, char *buf)
  293. {
  294. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  295. char fw_str[30];
  296. return snprintf(buf, PAGE_SIZE, "%s\n",
  297. ha->isp_ops.fw_version_str(ha, fw_str));
  298. }
  299. static ssize_t
  300. qla2x00_serial_num_show(struct class_device *cdev, char *buf)
  301. {
  302. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  303. uint32_t sn;
  304. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  305. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  306. sn % 100000);
  307. }
  308. static ssize_t
  309. qla2x00_isp_name_show(struct class_device *cdev, char *buf)
  310. {
  311. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  312. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
  313. }
  314. static ssize_t
  315. qla2x00_isp_id_show(struct class_device *cdev, char *buf)
  316. {
  317. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  318. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  319. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  320. ha->product_id[3]);
  321. }
  322. static ssize_t
  323. qla2x00_model_name_show(struct class_device *cdev, char *buf)
  324. {
  325. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  326. return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
  327. }
  328. static ssize_t
  329. qla2x00_model_desc_show(struct class_device *cdev, char *buf)
  330. {
  331. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  332. return snprintf(buf, PAGE_SIZE, "%s\n",
  333. ha->model_desc ? ha->model_desc: "");
  334. }
  335. static ssize_t
  336. qla2x00_pci_info_show(struct class_device *cdev, char *buf)
  337. {
  338. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  339. char pci_info[30];
  340. return snprintf(buf, PAGE_SIZE, "%s\n",
  341. ha->isp_ops.pci_info_str(ha, pci_info));
  342. }
  343. static ssize_t
  344. qla2x00_state_show(struct class_device *cdev, char *buf)
  345. {
  346. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  347. int len = 0;
  348. if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
  349. atomic_read(&ha->loop_state) == LOOP_DEAD)
  350. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  351. else if (atomic_read(&ha->loop_state) != LOOP_READY ||
  352. test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
  353. test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
  354. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  355. else {
  356. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  357. switch (ha->current_topology) {
  358. case ISP_CFG_NL:
  359. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  360. break;
  361. case ISP_CFG_FL:
  362. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  363. break;
  364. case ISP_CFG_N:
  365. len += snprintf(buf + len, PAGE_SIZE-len,
  366. "N_Port to N_Port\n");
  367. break;
  368. case ISP_CFG_F:
  369. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  370. break;
  371. default:
  372. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  373. break;
  374. }
  375. }
  376. return len;
  377. }
  378. static ssize_t
  379. qla2x00_zio_show(struct class_device *cdev, char *buf)
  380. {
  381. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  382. int len = 0;
  383. switch (ha->zio_mode) {
  384. case QLA_ZIO_MODE_5:
  385. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 5\n");
  386. break;
  387. case QLA_ZIO_MODE_6:
  388. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  389. break;
  390. case QLA_ZIO_DISABLED:
  391. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  392. break;
  393. }
  394. return len;
  395. }
  396. static ssize_t
  397. qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
  398. {
  399. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  400. int val = 0;
  401. uint16_t zio_mode;
  402. if (sscanf(buf, "%d", &val) != 1)
  403. return -EINVAL;
  404. switch (val) {
  405. case 1:
  406. zio_mode = QLA_ZIO_MODE_5;
  407. break;
  408. case 2:
  409. zio_mode = QLA_ZIO_MODE_6;
  410. break;
  411. default:
  412. zio_mode = QLA_ZIO_DISABLED;
  413. break;
  414. }
  415. /* Update per-hba values and queue a reset. */
  416. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  417. ha->zio_mode = zio_mode;
  418. set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
  419. }
  420. return strlen(buf);
  421. }
  422. static ssize_t
  423. qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
  424. {
  425. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  426. return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
  427. }
  428. static ssize_t
  429. qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
  430. size_t count)
  431. {
  432. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  433. int val = 0;
  434. uint16_t zio_timer;
  435. if (sscanf(buf, "%d", &val) != 1)
  436. return -EINVAL;
  437. if (val > 25500 || val < 100)
  438. return -ERANGE;
  439. zio_timer = (uint16_t)(val / 100);
  440. ha->zio_timer = zio_timer;
  441. return strlen(buf);
  442. }
  443. static ssize_t
  444. qla2x00_beacon_show(struct class_device *cdev, char *buf)
  445. {
  446. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  447. int len = 0;
  448. if (ha->beacon_blink_led)
  449. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  450. else
  451. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  452. return len;
  453. }
  454. static ssize_t
  455. qla2x00_beacon_store(struct class_device *cdev, const char *buf,
  456. size_t count)
  457. {
  458. scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
  459. int val = 0;
  460. int rval;
  461. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  462. return -EPERM;
  463. if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
  464. qla_printk(KERN_WARNING, ha,
  465. "Abort ISP active -- ignoring beacon request.\n");
  466. return -EBUSY;
  467. }
  468. if (sscanf(buf, "%d", &val) != 1)
  469. return -EINVAL;
  470. if (val)
  471. rval = ha->isp_ops.beacon_on(ha);
  472. else
  473. rval = ha->isp_ops.beacon_off(ha);
  474. if (rval != QLA_SUCCESS)
  475. count = 0;
  476. return count;
  477. }
  478. static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
  479. NULL);
  480. static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  481. static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  482. static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  483. static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  484. static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  485. static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  486. static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  487. static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
  488. static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
  489. qla2x00_zio_store);
  490. static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  491. qla2x00_zio_timer_store);
  492. static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  493. qla2x00_beacon_store);
  494. struct class_device_attribute *qla2x00_host_attrs[] = {
  495. &class_device_attr_driver_version,
  496. &class_device_attr_fw_version,
  497. &class_device_attr_serial_num,
  498. &class_device_attr_isp_name,
  499. &class_device_attr_isp_id,
  500. &class_device_attr_model_name,
  501. &class_device_attr_model_desc,
  502. &class_device_attr_pci_info,
  503. &class_device_attr_state,
  504. &class_device_attr_zio,
  505. &class_device_attr_zio_timer,
  506. &class_device_attr_beacon,
  507. NULL,
  508. };
  509. /* Host attributes. */
  510. static void
  511. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  512. {
  513. scsi_qla_host_t *ha = to_qla_host(shost);
  514. fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
  515. ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
  516. }
  517. static void
  518. qla2x00_get_host_speed(struct Scsi_Host *shost)
  519. {
  520. scsi_qla_host_t *ha = to_qla_host(shost);
  521. uint32_t speed = 0;
  522. switch (ha->link_data_rate) {
  523. case LDR_1GB:
  524. speed = 1;
  525. break;
  526. case LDR_2GB:
  527. speed = 2;
  528. break;
  529. case LDR_4GB:
  530. speed = 4;
  531. break;
  532. }
  533. fc_host_speed(shost) = speed;
  534. }
  535. static void
  536. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  537. {
  538. scsi_qla_host_t *ha = to_qla_host(shost);
  539. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  540. switch (ha->current_topology) {
  541. case ISP_CFG_NL:
  542. port_type = FC_PORTTYPE_LPORT;
  543. break;
  544. case ISP_CFG_FL:
  545. port_type = FC_PORTTYPE_NLPORT;
  546. break;
  547. case ISP_CFG_N:
  548. port_type = FC_PORTTYPE_PTP;
  549. break;
  550. case ISP_CFG_F:
  551. port_type = FC_PORTTYPE_NPORT;
  552. break;
  553. }
  554. fc_host_port_type(shost) = port_type;
  555. }
  556. static void
  557. qla2x00_get_starget_node_name(struct scsi_target *starget)
  558. {
  559. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  560. scsi_qla_host_t *ha = to_qla_host(host);
  561. fc_port_t *fcport;
  562. u64 node_name = 0;
  563. list_for_each_entry(fcport, &ha->fcports, list) {
  564. if (starget->id == fcport->os_target_id) {
  565. node_name = wwn_to_u64(fcport->node_name);
  566. break;
  567. }
  568. }
  569. fc_starget_node_name(starget) = node_name;
  570. }
  571. static void
  572. qla2x00_get_starget_port_name(struct scsi_target *starget)
  573. {
  574. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  575. scsi_qla_host_t *ha = to_qla_host(host);
  576. fc_port_t *fcport;
  577. u64 port_name = 0;
  578. list_for_each_entry(fcport, &ha->fcports, list) {
  579. if (starget->id == fcport->os_target_id) {
  580. port_name = wwn_to_u64(fcport->port_name);
  581. break;
  582. }
  583. }
  584. fc_starget_port_name(starget) = port_name;
  585. }
  586. static void
  587. qla2x00_get_starget_port_id(struct scsi_target *starget)
  588. {
  589. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  590. scsi_qla_host_t *ha = to_qla_host(host);
  591. fc_port_t *fcport;
  592. uint32_t port_id = ~0U;
  593. list_for_each_entry(fcport, &ha->fcports, list) {
  594. if (starget->id == fcport->os_target_id) {
  595. port_id = fcport->d_id.b.domain << 16 |
  596. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  597. break;
  598. }
  599. }
  600. fc_starget_port_id(starget) = port_id;
  601. }
  602. static void
  603. qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
  604. {
  605. struct Scsi_Host *host = rport_to_shost(rport);
  606. scsi_qla_host_t *ha = to_qla_host(host);
  607. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  608. }
  609. static void
  610. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  611. {
  612. struct Scsi_Host *host = rport_to_shost(rport);
  613. scsi_qla_host_t *ha = to_qla_host(host);
  614. if (timeout)
  615. ha->port_down_retry_count = timeout;
  616. else
  617. ha->port_down_retry_count = 1;
  618. rport->dev_loss_tmo = ha->port_down_retry_count + 5;
  619. }
  620. static int
  621. qla2x00_issue_lip(struct Scsi_Host *shost)
  622. {
  623. scsi_qla_host_t *ha = to_qla_host(shost);
  624. set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
  625. return 0;
  626. }
  627. static struct fc_host_statistics *
  628. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  629. {
  630. scsi_qla_host_t *ha = to_qla_host(shost);
  631. int rval;
  632. uint16_t mb_stat[1];
  633. link_stat_t stat_buf;
  634. struct fc_host_statistics *pfc_host_stat;
  635. pfc_host_stat = &ha->fc_host_stat;
  636. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  637. if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
  638. rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
  639. sizeof(stat_buf) / 4, mb_stat);
  640. } else {
  641. rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
  642. mb_stat);
  643. }
  644. if (rval != 0) {
  645. qla_printk(KERN_WARNING, ha,
  646. "Unable to retrieve host statistics (%d).\n", mb_stat[0]);
  647. return pfc_host_stat;
  648. }
  649. pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
  650. pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
  651. pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
  652. pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
  653. pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
  654. pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
  655. return pfc_host_stat;
  656. }
  657. struct fc_function_template qla2xxx_transport_functions = {
  658. .show_host_node_name = 1,
  659. .show_host_port_name = 1,
  660. .show_host_supported_classes = 1,
  661. .get_host_port_id = qla2x00_get_host_port_id,
  662. .show_host_port_id = 1,
  663. .get_host_speed = qla2x00_get_host_speed,
  664. .show_host_speed = 1,
  665. .get_host_port_type = qla2x00_get_host_port_type,
  666. .show_host_port_type = 1,
  667. .dd_fcrport_size = sizeof(struct fc_port *),
  668. .show_rport_supported_classes = 1,
  669. .get_starget_node_name = qla2x00_get_starget_node_name,
  670. .show_starget_node_name = 1,
  671. .get_starget_port_name = qla2x00_get_starget_port_name,
  672. .show_starget_port_name = 1,
  673. .get_starget_port_id = qla2x00_get_starget_port_id,
  674. .show_starget_port_id = 1,
  675. .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
  676. .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
  677. .show_rport_dev_loss_tmo = 1,
  678. .issue_fc_host_lip = qla2x00_issue_lip,
  679. .get_fc_host_stats = qla2x00_get_fc_host_stats,
  680. };
  681. void
  682. qla2x00_init_host_attr(scsi_qla_host_t *ha)
  683. {
  684. fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
  685. fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
  686. fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
  687. }