PageRenderTime 1638ms CodeModel.GetById 42ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/scsi/qla2xxx/qla_attr.c

https://github.com/Mengqi/linux-2.6
C | 1875 lines | 1543 code | 277 blank | 55 comment | 281 complexity | 68adf35b8c259a7340c062f6465d3549 MD5 | raw file
  1. /*
  2. * QLogic Fibre Channel HBA Driver
  3. * Copyright (c) 2003-2011 QLogic Corporation
  4. *
  5. * See LICENSE.qla2xxx for copyright and licensing details.
  6. */
  7. #include "qla_def.h"
  8. #include <linux/kthread.h>
  9. #include <linux/vmalloc.h>
  10. #include <linux/slab.h>
  11. #include <linux/delay.h>
  12. static int qla24xx_vport_disable(struct fc_vport *, bool);
  13. /* SYSFS attributes --------------------------------------------------------- */
  14. static ssize_t
  15. qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
  16. struct bin_attribute *bin_attr,
  17. char *buf, loff_t off, size_t count)
  18. {
  19. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  20. struct device, kobj)));
  21. struct qla_hw_data *ha = vha->hw;
  22. if (ha->fw_dump_reading == 0)
  23. return 0;
  24. return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
  25. ha->fw_dump_len);
  26. }
  27. static ssize_t
  28. qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
  29. struct bin_attribute *bin_attr,
  30. char *buf, loff_t off, size_t count)
  31. {
  32. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  33. struct device, kobj)));
  34. struct qla_hw_data *ha = vha->hw;
  35. int reading;
  36. if (IS_QLA82XX(ha)) {
  37. ql_dbg(ql_dbg_user, vha, 0x705b,
  38. "Firmware dump not supported for ISP82xx\n");
  39. return count;
  40. }
  41. if (off != 0)
  42. return (0);
  43. reading = simple_strtol(buf, NULL, 10);
  44. switch (reading) {
  45. case 0:
  46. if (!ha->fw_dump_reading)
  47. break;
  48. ql_log(ql_log_info, vha, 0x705d,
  49. "Firmware dump cleared on (%ld).\n", vha->host_no);
  50. ha->fw_dump_reading = 0;
  51. ha->fw_dumped = 0;
  52. break;
  53. case 1:
  54. if (ha->fw_dumped && !ha->fw_dump_reading) {
  55. ha->fw_dump_reading = 1;
  56. ql_log(ql_log_info, vha, 0x705e,
  57. "Raw firmware dump ready for read on (%ld).\n",
  58. vha->host_no);
  59. }
  60. break;
  61. case 2:
  62. qla2x00_alloc_fw_dump(vha);
  63. break;
  64. case 3:
  65. qla2x00_system_error(vha);
  66. break;
  67. }
  68. return (count);
  69. }
  70. static struct bin_attribute sysfs_fw_dump_attr = {
  71. .attr = {
  72. .name = "fw_dump",
  73. .mode = S_IRUSR | S_IWUSR,
  74. },
  75. .size = 0,
  76. .read = qla2x00_sysfs_read_fw_dump,
  77. .write = qla2x00_sysfs_write_fw_dump,
  78. };
  79. static ssize_t
  80. qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
  81. struct bin_attribute *bin_attr,
  82. char *buf, loff_t off, size_t count)
  83. {
  84. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  85. struct device, kobj)));
  86. struct qla_hw_data *ha = vha->hw;
  87. if (!capable(CAP_SYS_ADMIN))
  88. return 0;
  89. if (IS_NOCACHE_VPD_TYPE(ha))
  90. ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
  91. ha->nvram_size);
  92. return memory_read_from_buffer(buf, count, &off, ha->nvram,
  93. ha->nvram_size);
  94. }
  95. static ssize_t
  96. qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
  97. struct bin_attribute *bin_attr,
  98. char *buf, loff_t off, size_t count)
  99. {
  100. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  101. struct device, kobj)));
  102. struct qla_hw_data *ha = vha->hw;
  103. uint16_t cnt;
  104. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
  105. !ha->isp_ops->write_nvram)
  106. return 0;
  107. /* Checksum NVRAM. */
  108. if (IS_FWI2_CAPABLE(ha)) {
  109. uint32_t *iter;
  110. uint32_t chksum;
  111. iter = (uint32_t *)buf;
  112. chksum = 0;
  113. for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
  114. chksum += le32_to_cpu(*iter++);
  115. chksum = ~chksum + 1;
  116. *iter = cpu_to_le32(chksum);
  117. } else {
  118. uint8_t *iter;
  119. uint8_t chksum;
  120. iter = (uint8_t *)buf;
  121. chksum = 0;
  122. for (cnt = 0; cnt < count - 1; cnt++)
  123. chksum += *iter++;
  124. chksum = ~chksum + 1;
  125. *iter = chksum;
  126. }
  127. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  128. ql_log(ql_log_warn, vha, 0x705f,
  129. "HBA not online, failing NVRAM update.\n");
  130. return -EAGAIN;
  131. }
  132. /* Write NVRAM. */
  133. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
  134. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
  135. count);
  136. ql_dbg(ql_dbg_user, vha, 0x7060,
  137. "Setting ISP_ABORT_NEEDED\n");
  138. /* NVRAM settings take effect immediately. */
  139. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  140. qla2xxx_wake_dpc(vha);
  141. qla2x00_wait_for_chip_reset(vha);
  142. return (count);
  143. }
  144. static struct bin_attribute sysfs_nvram_attr = {
  145. .attr = {
  146. .name = "nvram",
  147. .mode = S_IRUSR | S_IWUSR,
  148. },
  149. .size = 512,
  150. .read = qla2x00_sysfs_read_nvram,
  151. .write = qla2x00_sysfs_write_nvram,
  152. };
  153. static ssize_t
  154. qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
  155. struct bin_attribute *bin_attr,
  156. char *buf, loff_t off, size_t count)
  157. {
  158. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  159. struct device, kobj)));
  160. struct qla_hw_data *ha = vha->hw;
  161. if (ha->optrom_state != QLA_SREADING)
  162. return 0;
  163. return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
  164. ha->optrom_region_size);
  165. }
  166. static ssize_t
  167. qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
  168. struct bin_attribute *bin_attr,
  169. char *buf, loff_t off, size_t count)
  170. {
  171. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  172. struct device, kobj)));
  173. struct qla_hw_data *ha = vha->hw;
  174. if (ha->optrom_state != QLA_SWRITING)
  175. return -EINVAL;
  176. if (off > ha->optrom_region_size)
  177. return -ERANGE;
  178. if (off + count > ha->optrom_region_size)
  179. count = ha->optrom_region_size - off;
  180. memcpy(&ha->optrom_buffer[off], buf, count);
  181. return count;
  182. }
  183. static struct bin_attribute sysfs_optrom_attr = {
  184. .attr = {
  185. .name = "optrom",
  186. .mode = S_IRUSR | S_IWUSR,
  187. },
  188. .size = 0,
  189. .read = qla2x00_sysfs_read_optrom,
  190. .write = qla2x00_sysfs_write_optrom,
  191. };
  192. static ssize_t
  193. qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
  194. struct bin_attribute *bin_attr,
  195. char *buf, loff_t off, size_t count)
  196. {
  197. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  198. struct device, kobj)));
  199. struct qla_hw_data *ha = vha->hw;
  200. uint32_t start = 0;
  201. uint32_t size = ha->optrom_size;
  202. int val, valid;
  203. if (off)
  204. return 0;
  205. if (unlikely(pci_channel_offline(ha->pdev)))
  206. return 0;
  207. if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
  208. return -EINVAL;
  209. if (start > ha->optrom_size)
  210. return -EINVAL;
  211. switch (val) {
  212. case 0:
  213. if (ha->optrom_state != QLA_SREADING &&
  214. ha->optrom_state != QLA_SWRITING)
  215. break;
  216. ha->optrom_state = QLA_SWAITING;
  217. ql_dbg(ql_dbg_user, vha, 0x7061,
  218. "Freeing flash region allocation -- 0x%x bytes.\n",
  219. ha->optrom_region_size);
  220. vfree(ha->optrom_buffer);
  221. ha->optrom_buffer = NULL;
  222. break;
  223. case 1:
  224. if (ha->optrom_state != QLA_SWAITING)
  225. break;
  226. ha->optrom_region_start = start;
  227. ha->optrom_region_size = start + size > ha->optrom_size ?
  228. ha->optrom_size - start : size;
  229. ha->optrom_state = QLA_SREADING;
  230. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  231. if (ha->optrom_buffer == NULL) {
  232. ql_log(ql_log_warn, vha, 0x7062,
  233. "Unable to allocate memory for optrom retrieval "
  234. "(%x).\n", ha->optrom_region_size);
  235. ha->optrom_state = QLA_SWAITING;
  236. return count;
  237. }
  238. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  239. ql_log(ql_log_warn, vha, 0x7063,
  240. "HBA not online, failing NVRAM update.\n");
  241. return -EAGAIN;
  242. }
  243. ql_dbg(ql_dbg_user, vha, 0x7064,
  244. "Reading flash region -- 0x%x/0x%x.\n",
  245. ha->optrom_region_start, ha->optrom_region_size);
  246. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  247. ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
  248. ha->optrom_region_start, ha->optrom_region_size);
  249. break;
  250. case 2:
  251. if (ha->optrom_state != QLA_SWAITING)
  252. break;
  253. /*
  254. * We need to be more restrictive on which FLASH regions are
  255. * allowed to be updated via user-space. Regions accessible
  256. * via this method include:
  257. *
  258. * ISP21xx/ISP22xx/ISP23xx type boards:
  259. *
  260. * 0x000000 -> 0x020000 -- Boot code.
  261. *
  262. * ISP2322/ISP24xx type boards:
  263. *
  264. * 0x000000 -> 0x07ffff -- Boot code.
  265. * 0x080000 -> 0x0fffff -- Firmware.
  266. *
  267. * ISP25xx type boards:
  268. *
  269. * 0x000000 -> 0x07ffff -- Boot code.
  270. * 0x080000 -> 0x0fffff -- Firmware.
  271. * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
  272. */
  273. valid = 0;
  274. if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
  275. valid = 1;
  276. else if (start == (ha->flt_region_boot * 4) ||
  277. start == (ha->flt_region_fw * 4))
  278. valid = 1;
  279. else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
  280. valid = 1;
  281. if (!valid) {
  282. ql_log(ql_log_warn, vha, 0x7065,
  283. "Invalid start region 0x%x/0x%x.\n", start, size);
  284. return -EINVAL;
  285. }
  286. ha->optrom_region_start = start;
  287. ha->optrom_region_size = start + size > ha->optrom_size ?
  288. ha->optrom_size - start : size;
  289. ha->optrom_state = QLA_SWRITING;
  290. ha->optrom_buffer = vmalloc(ha->optrom_region_size);
  291. if (ha->optrom_buffer == NULL) {
  292. ql_log(ql_log_warn, vha, 0x7066,
  293. "Unable to allocate memory for optrom update "
  294. "(%x)\n", ha->optrom_region_size);
  295. ha->optrom_state = QLA_SWAITING;
  296. return count;
  297. }
  298. ql_dbg(ql_dbg_user, vha, 0x7067,
  299. "Staging flash region write -- 0x%x/0x%x.\n",
  300. ha->optrom_region_start, ha->optrom_region_size);
  301. memset(ha->optrom_buffer, 0, ha->optrom_region_size);
  302. break;
  303. case 3:
  304. if (ha->optrom_state != QLA_SWRITING)
  305. break;
  306. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  307. ql_log(ql_log_warn, vha, 0x7068,
  308. "HBA not online, failing flash update.\n");
  309. return -EAGAIN;
  310. }
  311. ql_dbg(ql_dbg_user, vha, 0x7069,
  312. "Writing flash region -- 0x%x/0x%x.\n",
  313. ha->optrom_region_start, ha->optrom_region_size);
  314. ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
  315. ha->optrom_region_start, ha->optrom_region_size);
  316. break;
  317. default:
  318. count = -EINVAL;
  319. }
  320. return count;
  321. }
  322. static struct bin_attribute sysfs_optrom_ctl_attr = {
  323. .attr = {
  324. .name = "optrom_ctl",
  325. .mode = S_IWUSR,
  326. },
  327. .size = 0,
  328. .write = qla2x00_sysfs_write_optrom_ctl,
  329. };
  330. static ssize_t
  331. qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
  332. struct bin_attribute *bin_attr,
  333. char *buf, loff_t off, size_t count)
  334. {
  335. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  336. struct device, kobj)));
  337. struct qla_hw_data *ha = vha->hw;
  338. if (unlikely(pci_channel_offline(ha->pdev)))
  339. return 0;
  340. if (!capable(CAP_SYS_ADMIN))
  341. return 0;
  342. if (IS_NOCACHE_VPD_TYPE(ha))
  343. ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
  344. ha->vpd_size);
  345. return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
  346. }
  347. static ssize_t
  348. qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
  349. struct bin_attribute *bin_attr,
  350. char *buf, loff_t off, size_t count)
  351. {
  352. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  353. struct device, kobj)));
  354. struct qla_hw_data *ha = vha->hw;
  355. uint8_t *tmp_data;
  356. if (unlikely(pci_channel_offline(ha->pdev)))
  357. return 0;
  358. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
  359. !ha->isp_ops->write_nvram)
  360. return 0;
  361. if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
  362. ql_log(ql_log_warn, vha, 0x706a,
  363. "HBA not online, failing VPD update.\n");
  364. return -EAGAIN;
  365. }
  366. /* Write NVRAM. */
  367. ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
  368. ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
  369. /* Update flash version information for 4Gb & above. */
  370. if (!IS_FWI2_CAPABLE(ha))
  371. goto done;
  372. tmp_data = vmalloc(256);
  373. if (!tmp_data) {
  374. ql_log(ql_log_warn, vha, 0x706b,
  375. "Unable to allocate memory for VPD information update.\n");
  376. goto done;
  377. }
  378. ha->isp_ops->get_flash_version(vha, tmp_data);
  379. vfree(tmp_data);
  380. done:
  381. return count;
  382. }
  383. static struct bin_attribute sysfs_vpd_attr = {
  384. .attr = {
  385. .name = "vpd",
  386. .mode = S_IRUSR | S_IWUSR,
  387. },
  388. .size = 0,
  389. .read = qla2x00_sysfs_read_vpd,
  390. .write = qla2x00_sysfs_write_vpd,
  391. };
  392. static ssize_t
  393. qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
  394. struct bin_attribute *bin_attr,
  395. char *buf, loff_t off, size_t count)
  396. {
  397. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  398. struct device, kobj)));
  399. struct qla_hw_data *ha = vha->hw;
  400. uint16_t iter, addr, offset;
  401. int rval;
  402. if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
  403. return 0;
  404. if (ha->sfp_data)
  405. goto do_read;
  406. ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  407. &ha->sfp_data_dma);
  408. if (!ha->sfp_data) {
  409. ql_log(ql_log_warn, vha, 0x706c,
  410. "Unable to allocate memory for SFP read-data.\n");
  411. return 0;
  412. }
  413. do_read:
  414. memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
  415. addr = 0xa0;
  416. for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
  417. iter++, offset += SFP_BLOCK_SIZE) {
  418. if (iter == 4) {
  419. /* Skip to next device address. */
  420. addr = 0xa2;
  421. offset = 0;
  422. }
  423. rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, ha->sfp_data,
  424. addr, offset, SFP_BLOCK_SIZE, 0);
  425. if (rval != QLA_SUCCESS) {
  426. ql_log(ql_log_warn, vha, 0x706d,
  427. "Unable to read SFP data (%x/%x/%x).\n", rval,
  428. addr, offset);
  429. count = 0;
  430. break;
  431. }
  432. memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
  433. buf += SFP_BLOCK_SIZE;
  434. }
  435. return count;
  436. }
  437. static struct bin_attribute sysfs_sfp_attr = {
  438. .attr = {
  439. .name = "sfp",
  440. .mode = S_IRUSR | S_IWUSR,
  441. },
  442. .size = SFP_DEV_SIZE * 2,
  443. .read = qla2x00_sysfs_read_sfp,
  444. };
  445. static ssize_t
  446. qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
  447. struct bin_attribute *bin_attr,
  448. char *buf, loff_t off, size_t count)
  449. {
  450. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  451. struct device, kobj)));
  452. struct qla_hw_data *ha = vha->hw;
  453. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  454. int type;
  455. if (off != 0)
  456. return 0;
  457. type = simple_strtol(buf, NULL, 10);
  458. switch (type) {
  459. case 0x2025c:
  460. ql_log(ql_log_info, vha, 0x706e,
  461. "Issuing ISP reset.\n");
  462. scsi_block_requests(vha->host);
  463. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  464. qla2xxx_wake_dpc(vha);
  465. qla2x00_wait_for_chip_reset(vha);
  466. scsi_unblock_requests(vha->host);
  467. break;
  468. case 0x2025d:
  469. if (!IS_QLA81XX(ha))
  470. break;
  471. ql_log(ql_log_info, vha, 0x706f,
  472. "Issuing MPI reset.\n");
  473. /* Make sure FC side is not in reset */
  474. qla2x00_wait_for_hba_online(vha);
  475. /* Issue MPI reset */
  476. scsi_block_requests(vha->host);
  477. if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
  478. ql_log(ql_log_warn, vha, 0x7070,
  479. "MPI reset failed.\n");
  480. scsi_unblock_requests(vha->host);
  481. break;
  482. case 0x2025e:
  483. if (!IS_QLA82XX(ha) || vha != base_vha) {
  484. ql_log(ql_log_info, vha, 0x7071,
  485. "FCoE ctx reset no supported.\n");
  486. return count;
  487. }
  488. ql_log(ql_log_info, vha, 0x7072,
  489. "Issuing FCoE ctx reset.\n");
  490. set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
  491. qla2xxx_wake_dpc(vha);
  492. qla2x00_wait_for_fcoe_ctx_reset(vha);
  493. break;
  494. }
  495. return count;
  496. }
  497. static struct bin_attribute sysfs_reset_attr = {
  498. .attr = {
  499. .name = "reset",
  500. .mode = S_IWUSR,
  501. },
  502. .size = 0,
  503. .write = qla2x00_sysfs_write_reset,
  504. };
  505. static ssize_t
  506. qla2x00_sysfs_write_edc(struct file *filp, struct kobject *kobj,
  507. struct bin_attribute *bin_attr,
  508. char *buf, loff_t off, size_t count)
  509. {
  510. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  511. struct device, kobj)));
  512. struct qla_hw_data *ha = vha->hw;
  513. uint16_t dev, adr, opt, len;
  514. int rval;
  515. ha->edc_data_len = 0;
  516. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  517. return 0;
  518. if (!ha->edc_data) {
  519. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  520. &ha->edc_data_dma);
  521. if (!ha->edc_data) {
  522. ql_log(ql_log_warn, vha, 0x7073,
  523. "Unable to allocate memory for EDC write.\n");
  524. return 0;
  525. }
  526. }
  527. dev = le16_to_cpup((void *)&buf[0]);
  528. adr = le16_to_cpup((void *)&buf[2]);
  529. opt = le16_to_cpup((void *)&buf[4]);
  530. len = le16_to_cpup((void *)&buf[6]);
  531. if (!(opt & BIT_0))
  532. if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
  533. return -EINVAL;
  534. memcpy(ha->edc_data, &buf[8], len);
  535. rval = qla2x00_write_sfp(vha, ha->edc_data_dma, ha->edc_data,
  536. dev, adr, len, opt);
  537. if (rval != QLA_SUCCESS) {
  538. ql_log(ql_log_warn, vha, 0x7074,
  539. "Unable to write EDC (%x) %02x:%04x:%02x:%02x\n",
  540. rval, dev, adr, opt, len, buf[8]);
  541. return 0;
  542. }
  543. return count;
  544. }
  545. static struct bin_attribute sysfs_edc_attr = {
  546. .attr = {
  547. .name = "edc",
  548. .mode = S_IWUSR,
  549. },
  550. .size = 0,
  551. .write = qla2x00_sysfs_write_edc,
  552. };
  553. static ssize_t
  554. qla2x00_sysfs_write_edc_status(struct file *filp, struct kobject *kobj,
  555. struct bin_attribute *bin_attr,
  556. char *buf, loff_t off, size_t count)
  557. {
  558. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  559. struct device, kobj)));
  560. struct qla_hw_data *ha = vha->hw;
  561. uint16_t dev, adr, opt, len;
  562. int rval;
  563. ha->edc_data_len = 0;
  564. if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
  565. return 0;
  566. if (!ha->edc_data) {
  567. ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
  568. &ha->edc_data_dma);
  569. if (!ha->edc_data) {
  570. ql_log(ql_log_warn, vha, 0x708c,
  571. "Unable to allocate memory for EDC status.\n");
  572. return 0;
  573. }
  574. }
  575. dev = le16_to_cpup((void *)&buf[0]);
  576. adr = le16_to_cpup((void *)&buf[2]);
  577. opt = le16_to_cpup((void *)&buf[4]);
  578. len = le16_to_cpup((void *)&buf[6]);
  579. if (!(opt & BIT_0))
  580. if (len == 0 || len > DMA_POOL_SIZE)
  581. return -EINVAL;
  582. memset(ha->edc_data, 0, len);
  583. rval = qla2x00_read_sfp(vha, ha->edc_data_dma, ha->edc_data,
  584. dev, adr, len, opt);
  585. if (rval != QLA_SUCCESS) {
  586. ql_log(ql_log_info, vha, 0x7075,
  587. "Unable to write EDC status (%x) %02x:%04x:%02x.\n",
  588. rval, dev, adr, opt, len);
  589. return 0;
  590. }
  591. ha->edc_data_len = len;
  592. return count;
  593. }
  594. static ssize_t
  595. qla2x00_sysfs_read_edc_status(struct file *filp, struct kobject *kobj,
  596. struct bin_attribute *bin_attr,
  597. char *buf, loff_t off, size_t count)
  598. {
  599. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  600. struct device, kobj)));
  601. struct qla_hw_data *ha = vha->hw;
  602. if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
  603. return 0;
  604. if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
  605. return -EINVAL;
  606. memcpy(buf, ha->edc_data, ha->edc_data_len);
  607. return ha->edc_data_len;
  608. }
  609. static struct bin_attribute sysfs_edc_status_attr = {
  610. .attr = {
  611. .name = "edc_status",
  612. .mode = S_IRUSR | S_IWUSR,
  613. },
  614. .size = 0,
  615. .write = qla2x00_sysfs_write_edc_status,
  616. .read = qla2x00_sysfs_read_edc_status,
  617. };
  618. static ssize_t
  619. qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
  620. struct bin_attribute *bin_attr,
  621. char *buf, loff_t off, size_t count)
  622. {
  623. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  624. struct device, kobj)));
  625. struct qla_hw_data *ha = vha->hw;
  626. int rval;
  627. uint16_t actual_size;
  628. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
  629. return 0;
  630. if (ha->xgmac_data)
  631. goto do_read;
  632. ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
  633. &ha->xgmac_data_dma, GFP_KERNEL);
  634. if (!ha->xgmac_data) {
  635. ql_log(ql_log_warn, vha, 0x7076,
  636. "Unable to allocate memory for XGMAC read-data.\n");
  637. return 0;
  638. }
  639. do_read:
  640. actual_size = 0;
  641. memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
  642. rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
  643. XGMAC_DATA_SIZE, &actual_size);
  644. if (rval != QLA_SUCCESS) {
  645. ql_log(ql_log_warn, vha, 0x7077,
  646. "Unable to read XGMAC data (%x).\n", rval);
  647. count = 0;
  648. }
  649. count = actual_size > count ? count: actual_size;
  650. memcpy(buf, ha->xgmac_data, count);
  651. return count;
  652. }
  653. static struct bin_attribute sysfs_xgmac_stats_attr = {
  654. .attr = {
  655. .name = "xgmac_stats",
  656. .mode = S_IRUSR,
  657. },
  658. .size = 0,
  659. .read = qla2x00_sysfs_read_xgmac_stats,
  660. };
  661. static ssize_t
  662. qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
  663. struct bin_attribute *bin_attr,
  664. char *buf, loff_t off, size_t count)
  665. {
  666. struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
  667. struct device, kobj)));
  668. struct qla_hw_data *ha = vha->hw;
  669. int rval;
  670. uint16_t actual_size;
  671. if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
  672. return 0;
  673. if (ha->dcbx_tlv)
  674. goto do_read;
  675. ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
  676. &ha->dcbx_tlv_dma, GFP_KERNEL);
  677. if (!ha->dcbx_tlv) {
  678. ql_log(ql_log_warn, vha, 0x7078,
  679. "Unable to allocate memory for DCBX TLV read-data.\n");
  680. return 0;
  681. }
  682. do_read:
  683. actual_size = 0;
  684. memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
  685. rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
  686. DCBX_TLV_DATA_SIZE);
  687. if (rval != QLA_SUCCESS) {
  688. ql_log(ql_log_warn, vha, 0x7079,
  689. "Unable to read DCBX TLV (%x).\n", rval);
  690. count = 0;
  691. }
  692. memcpy(buf, ha->dcbx_tlv, count);
  693. return count;
  694. }
  695. static struct bin_attribute sysfs_dcbx_tlv_attr = {
  696. .attr = {
  697. .name = "dcbx_tlv",
  698. .mode = S_IRUSR,
  699. },
  700. .size = 0,
  701. .read = qla2x00_sysfs_read_dcbx_tlv,
  702. };
  703. static struct sysfs_entry {
  704. char *name;
  705. struct bin_attribute *attr;
  706. int is4GBp_only;
  707. } bin_file_entries[] = {
  708. { "fw_dump", &sysfs_fw_dump_attr, },
  709. { "nvram", &sysfs_nvram_attr, },
  710. { "optrom", &sysfs_optrom_attr, },
  711. { "optrom_ctl", &sysfs_optrom_ctl_attr, },
  712. { "vpd", &sysfs_vpd_attr, 1 },
  713. { "sfp", &sysfs_sfp_attr, 1 },
  714. { "reset", &sysfs_reset_attr, },
  715. { "edc", &sysfs_edc_attr, 2 },
  716. { "edc_status", &sysfs_edc_status_attr, 2 },
  717. { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
  718. { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
  719. { NULL },
  720. };
  721. void
  722. qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
  723. {
  724. struct Scsi_Host *host = vha->host;
  725. struct sysfs_entry *iter;
  726. int ret;
  727. for (iter = bin_file_entries; iter->name; iter++) {
  728. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
  729. continue;
  730. if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
  731. continue;
  732. if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw)))
  733. continue;
  734. ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
  735. iter->attr);
  736. if (ret)
  737. ql_log(ql_log_warn, vha, 0x00f3,
  738. "Unable to create sysfs %s binary attribute (%d).\n",
  739. iter->name, ret);
  740. else
  741. ql_dbg(ql_dbg_init, vha, 0x00f4,
  742. "Successfully created sysfs %s binary attribure.\n",
  743. iter->name);
  744. }
  745. }
  746. void
  747. qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
  748. {
  749. struct Scsi_Host *host = vha->host;
  750. struct sysfs_entry *iter;
  751. struct qla_hw_data *ha = vha->hw;
  752. for (iter = bin_file_entries; iter->name; iter++) {
  753. if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
  754. continue;
  755. if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
  756. continue;
  757. if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw)))
  758. continue;
  759. sysfs_remove_bin_file(&host->shost_gendev.kobj,
  760. iter->attr);
  761. }
  762. if (ha->beacon_blink_led == 1)
  763. ha->isp_ops->beacon_off(vha);
  764. }
  765. /* Scsi_Host attributes. */
  766. static ssize_t
  767. qla2x00_drvr_version_show(struct device *dev,
  768. struct device_attribute *attr, char *buf)
  769. {
  770. return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
  771. }
  772. static ssize_t
  773. qla2x00_fw_version_show(struct device *dev,
  774. struct device_attribute *attr, char *buf)
  775. {
  776. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  777. struct qla_hw_data *ha = vha->hw;
  778. char fw_str[128];
  779. return snprintf(buf, PAGE_SIZE, "%s\n",
  780. ha->isp_ops->fw_version_str(vha, fw_str));
  781. }
  782. static ssize_t
  783. qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
  784. char *buf)
  785. {
  786. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  787. struct qla_hw_data *ha = vha->hw;
  788. uint32_t sn;
  789. if (IS_FWI2_CAPABLE(ha)) {
  790. qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
  791. return snprintf(buf, PAGE_SIZE, "%s\n", buf);
  792. }
  793. sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
  794. return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
  795. sn % 100000);
  796. }
  797. static ssize_t
  798. qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
  799. char *buf)
  800. {
  801. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  802. return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
  803. }
  804. static ssize_t
  805. qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
  806. char *buf)
  807. {
  808. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  809. struct qla_hw_data *ha = vha->hw;
  810. return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
  811. ha->product_id[0], ha->product_id[1], ha->product_id[2],
  812. ha->product_id[3]);
  813. }
  814. static ssize_t
  815. qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
  816. char *buf)
  817. {
  818. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  819. return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
  820. }
  821. static ssize_t
  822. qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
  823. char *buf)
  824. {
  825. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  826. return snprintf(buf, PAGE_SIZE, "%s\n",
  827. vha->hw->model_desc ? vha->hw->model_desc : "");
  828. }
  829. static ssize_t
  830. qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
  831. char *buf)
  832. {
  833. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  834. char pci_info[30];
  835. return snprintf(buf, PAGE_SIZE, "%s\n",
  836. vha->hw->isp_ops->pci_info_str(vha, pci_info));
  837. }
  838. static ssize_t
  839. qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
  840. char *buf)
  841. {
  842. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  843. struct qla_hw_data *ha = vha->hw;
  844. int len = 0;
  845. if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
  846. atomic_read(&vha->loop_state) == LOOP_DEAD ||
  847. vha->device_flags & DFLG_NO_CABLE)
  848. len = snprintf(buf, PAGE_SIZE, "Link Down\n");
  849. else if (atomic_read(&vha->loop_state) != LOOP_READY ||
  850. test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  851. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  852. len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
  853. else {
  854. len = snprintf(buf, PAGE_SIZE, "Link Up - ");
  855. switch (ha->current_topology) {
  856. case ISP_CFG_NL:
  857. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  858. break;
  859. case ISP_CFG_FL:
  860. len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
  861. break;
  862. case ISP_CFG_N:
  863. len += snprintf(buf + len, PAGE_SIZE-len,
  864. "N_Port to N_Port\n");
  865. break;
  866. case ISP_CFG_F:
  867. len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
  868. break;
  869. default:
  870. len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
  871. break;
  872. }
  873. }
  874. return len;
  875. }
  876. static ssize_t
  877. qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
  878. char *buf)
  879. {
  880. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  881. int len = 0;
  882. switch (vha->hw->zio_mode) {
  883. case QLA_ZIO_MODE_6:
  884. len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
  885. break;
  886. case QLA_ZIO_DISABLED:
  887. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  888. break;
  889. }
  890. return len;
  891. }
  892. static ssize_t
  893. qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
  894. const char *buf, size_t count)
  895. {
  896. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  897. struct qla_hw_data *ha = vha->hw;
  898. int val = 0;
  899. uint16_t zio_mode;
  900. if (!IS_ZIO_SUPPORTED(ha))
  901. return -ENOTSUPP;
  902. if (sscanf(buf, "%d", &val) != 1)
  903. return -EINVAL;
  904. if (val)
  905. zio_mode = QLA_ZIO_MODE_6;
  906. else
  907. zio_mode = QLA_ZIO_DISABLED;
  908. /* Update per-hba values and queue a reset. */
  909. if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
  910. ha->zio_mode = zio_mode;
  911. set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
  912. }
  913. return strlen(buf);
  914. }
  915. static ssize_t
  916. qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
  917. char *buf)
  918. {
  919. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  920. return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
  921. }
  922. static ssize_t
  923. qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
  924. const char *buf, size_t count)
  925. {
  926. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  927. int val = 0;
  928. uint16_t zio_timer;
  929. if (sscanf(buf, "%d", &val) != 1)
  930. return -EINVAL;
  931. if (val > 25500 || val < 100)
  932. return -ERANGE;
  933. zio_timer = (uint16_t)(val / 100);
  934. vha->hw->zio_timer = zio_timer;
  935. return strlen(buf);
  936. }
  937. static ssize_t
  938. qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
  939. char *buf)
  940. {
  941. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  942. int len = 0;
  943. if (vha->hw->beacon_blink_led)
  944. len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
  945. else
  946. len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
  947. return len;
  948. }
  949. static ssize_t
  950. qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
  951. const char *buf, size_t count)
  952. {
  953. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  954. struct qla_hw_data *ha = vha->hw;
  955. int val = 0;
  956. int rval;
  957. if (IS_QLA2100(ha) || IS_QLA2200(ha))
  958. return -EPERM;
  959. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
  960. ql_log(ql_log_warn, vha, 0x707a,
  961. "Abort ISP active -- ignoring beacon request.\n");
  962. return -EBUSY;
  963. }
  964. if (sscanf(buf, "%d", &val) != 1)
  965. return -EINVAL;
  966. if (val)
  967. rval = ha->isp_ops->beacon_on(vha);
  968. else
  969. rval = ha->isp_ops->beacon_off(vha);
  970. if (rval != QLA_SUCCESS)
  971. count = 0;
  972. return count;
  973. }
  974. static ssize_t
  975. qla2x00_optrom_bios_version_show(struct device *dev,
  976. struct device_attribute *attr, char *buf)
  977. {
  978. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  979. struct qla_hw_data *ha = vha->hw;
  980. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
  981. ha->bios_revision[0]);
  982. }
  983. static ssize_t
  984. qla2x00_optrom_efi_version_show(struct device *dev,
  985. struct device_attribute *attr, char *buf)
  986. {
  987. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  988. struct qla_hw_data *ha = vha->hw;
  989. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
  990. ha->efi_revision[0]);
  991. }
  992. static ssize_t
  993. qla2x00_optrom_fcode_version_show(struct device *dev,
  994. struct device_attribute *attr, char *buf)
  995. {
  996. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  997. struct qla_hw_data *ha = vha->hw;
  998. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
  999. ha->fcode_revision[0]);
  1000. }
  1001. static ssize_t
  1002. qla2x00_optrom_fw_version_show(struct device *dev,
  1003. struct device_attribute *attr, char *buf)
  1004. {
  1005. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1006. struct qla_hw_data *ha = vha->hw;
  1007. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
  1008. ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
  1009. ha->fw_revision[3]);
  1010. }
  1011. static ssize_t
  1012. qla2x00_optrom_gold_fw_version_show(struct device *dev,
  1013. struct device_attribute *attr, char *buf)
  1014. {
  1015. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1016. struct qla_hw_data *ha = vha->hw;
  1017. if (!IS_QLA81XX(ha))
  1018. return snprintf(buf, PAGE_SIZE, "\n");
  1019. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
  1020. ha->gold_fw_version[0], ha->gold_fw_version[1],
  1021. ha->gold_fw_version[2], ha->gold_fw_version[3]);
  1022. }
  1023. static ssize_t
  1024. qla2x00_total_isp_aborts_show(struct device *dev,
  1025. struct device_attribute *attr, char *buf)
  1026. {
  1027. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1028. struct qla_hw_data *ha = vha->hw;
  1029. return snprintf(buf, PAGE_SIZE, "%d\n",
  1030. ha->qla_stats.total_isp_aborts);
  1031. }
  1032. static ssize_t
  1033. qla24xx_84xx_fw_version_show(struct device *dev,
  1034. struct device_attribute *attr, char *buf)
  1035. {
  1036. int rval = QLA_SUCCESS;
  1037. uint16_t status[2] = {0, 0};
  1038. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1039. struct qla_hw_data *ha = vha->hw;
  1040. if (!IS_QLA84XX(ha))
  1041. return snprintf(buf, PAGE_SIZE, "\n");
  1042. if (ha->cs84xx->op_fw_version == 0)
  1043. rval = qla84xx_verify_chip(vha, status);
  1044. if ((rval == QLA_SUCCESS) && (status[0] == 0))
  1045. return snprintf(buf, PAGE_SIZE, "%u\n",
  1046. (uint32_t)ha->cs84xx->op_fw_version);
  1047. return snprintf(buf, PAGE_SIZE, "\n");
  1048. }
  1049. static ssize_t
  1050. qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
  1051. char *buf)
  1052. {
  1053. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1054. struct qla_hw_data *ha = vha->hw;
  1055. if (!IS_QLA81XX(ha))
  1056. return snprintf(buf, PAGE_SIZE, "\n");
  1057. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
  1058. ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
  1059. ha->mpi_capabilities);
  1060. }
  1061. static ssize_t
  1062. qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
  1063. char *buf)
  1064. {
  1065. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1066. struct qla_hw_data *ha = vha->hw;
  1067. if (!IS_QLA81XX(ha))
  1068. return snprintf(buf, PAGE_SIZE, "\n");
  1069. return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
  1070. ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
  1071. }
  1072. static ssize_t
  1073. qla2x00_flash_block_size_show(struct device *dev,
  1074. struct device_attribute *attr, char *buf)
  1075. {
  1076. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1077. struct qla_hw_data *ha = vha->hw;
  1078. return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
  1079. }
  1080. static ssize_t
  1081. qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
  1082. char *buf)
  1083. {
  1084. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1085. if (!IS_QLA8XXX_TYPE(vha->hw))
  1086. return snprintf(buf, PAGE_SIZE, "\n");
  1087. return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
  1088. }
  1089. static ssize_t
  1090. qla2x00_vn_port_mac_address_show(struct device *dev,
  1091. struct device_attribute *attr, char *buf)
  1092. {
  1093. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1094. if (!IS_QLA8XXX_TYPE(vha->hw))
  1095. return snprintf(buf, PAGE_SIZE, "\n");
  1096. return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
  1097. vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
  1098. vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
  1099. vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
  1100. }
  1101. static ssize_t
  1102. qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
  1103. char *buf)
  1104. {
  1105. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1106. return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
  1107. }
  1108. static ssize_t
  1109. qla2x00_thermal_temp_show(struct device *dev,
  1110. struct device_attribute *attr, char *buf)
  1111. {
  1112. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1113. int rval = QLA_FUNCTION_FAILED;
  1114. uint16_t temp, frac;
  1115. if (!vha->hw->flags.thermal_supported)
  1116. return snprintf(buf, PAGE_SIZE, "\n");
  1117. temp = frac = 0;
  1118. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1119. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  1120. ql_log(ql_log_warn, vha, 0x707b,
  1121. "ISP reset active.\n");
  1122. else if (!vha->hw->flags.eeh_busy)
  1123. rval = qla2x00_get_thermal_temp(vha, &temp, &frac);
  1124. if (rval != QLA_SUCCESS)
  1125. temp = frac = 0;
  1126. return snprintf(buf, PAGE_SIZE, "%d.%02d\n", temp, frac);
  1127. }
  1128. static ssize_t
  1129. qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
  1130. char *buf)
  1131. {
  1132. scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
  1133. int rval = QLA_FUNCTION_FAILED;
  1134. uint16_t state[5];
  1135. if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
  1136. test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
  1137. ql_log(ql_log_warn, vha, 0x707c,
  1138. "ISP reset active.\n");
  1139. else if (!vha->hw->flags.eeh_busy)
  1140. rval = qla2x00_get_firmware_state(vha, state);
  1141. if (rval != QLA_SUCCESS)
  1142. memset(state, -1, sizeof(state));
  1143. return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
  1144. state[1], state[2], state[3], state[4]);
  1145. }
  1146. static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
  1147. static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
  1148. static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
  1149. static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
  1150. static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
  1151. static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
  1152. static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
  1153. static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
  1154. static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
  1155. static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
  1156. static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
  1157. qla2x00_zio_timer_store);
  1158. static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
  1159. qla2x00_beacon_store);
  1160. static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
  1161. qla2x00_optrom_bios_version_show, NULL);
  1162. static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
  1163. qla2x00_optrom_efi_version_show, NULL);
  1164. static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
  1165. qla2x00_optrom_fcode_version_show, NULL);
  1166. static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
  1167. NULL);
  1168. static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
  1169. qla2x00_optrom_gold_fw_version_show, NULL);
  1170. static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
  1171. NULL);
  1172. static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
  1173. NULL);
  1174. static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
  1175. static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
  1176. static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
  1177. NULL);
  1178. static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
  1179. static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
  1180. qla2x00_vn_port_mac_address_show, NULL);
  1181. static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
  1182. static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
  1183. static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
  1184. struct device_attribute *qla2x00_host_attrs[] = {
  1185. &dev_attr_driver_version,
  1186. &dev_attr_fw_version,
  1187. &dev_attr_serial_num,
  1188. &dev_attr_isp_name,
  1189. &dev_attr_isp_id,
  1190. &dev_attr_model_name,
  1191. &dev_attr_model_desc,
  1192. &dev_attr_pci_info,
  1193. &dev_attr_link_state,
  1194. &dev_attr_zio,
  1195. &dev_attr_zio_timer,
  1196. &dev_attr_beacon,
  1197. &dev_attr_optrom_bios_version,
  1198. &dev_attr_optrom_efi_version,
  1199. &dev_attr_optrom_fcode_version,
  1200. &dev_attr_optrom_fw_version,
  1201. &dev_attr_84xx_fw_version,
  1202. &dev_attr_total_isp_aborts,
  1203. &dev_attr_mpi_version,
  1204. &dev_attr_phy_version,
  1205. &dev_attr_flash_block_size,
  1206. &dev_attr_vlan_id,
  1207. &dev_attr_vn_port_mac_address,
  1208. &dev_attr_fabric_param,
  1209. &dev_attr_fw_state,
  1210. &dev_attr_optrom_gold_fw_version,
  1211. &dev_attr_thermal_temp,
  1212. NULL,
  1213. };
  1214. /* Host attributes. */
  1215. static void
  1216. qla2x00_get_host_port_id(struct Scsi_Host *shost)
  1217. {
  1218. scsi_qla_host_t *vha = shost_priv(shost);
  1219. fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
  1220. vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
  1221. }
  1222. static void
  1223. qla2x00_get_host_speed(struct Scsi_Host *shost)
  1224. {
  1225. struct qla_hw_data *ha = ((struct scsi_qla_host *)
  1226. (shost_priv(shost)))->hw;
  1227. u32 speed = FC_PORTSPEED_UNKNOWN;
  1228. switch (ha->link_data_rate) {
  1229. case PORT_SPEED_1GB:
  1230. speed = FC_PORTSPEED_1GBIT;
  1231. break;
  1232. case PORT_SPEED_2GB:
  1233. speed = FC_PORTSPEED_2GBIT;
  1234. break;
  1235. case PORT_SPEED_4GB:
  1236. speed = FC_PORTSPEED_4GBIT;
  1237. break;
  1238. case PORT_SPEED_8GB:
  1239. speed = FC_PORTSPEED_8GBIT;
  1240. break;
  1241. case PORT_SPEED_10GB:
  1242. speed = FC_PORTSPEED_10GBIT;
  1243. break;
  1244. }
  1245. fc_host_speed(shost) = speed;
  1246. }
  1247. static void
  1248. qla2x00_get_host_port_type(struct Scsi_Host *shost)
  1249. {
  1250. scsi_qla_host_t *vha = shost_priv(shost);
  1251. uint32_t port_type = FC_PORTTYPE_UNKNOWN;
  1252. if (vha->vp_idx) {
  1253. fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
  1254. return;
  1255. }
  1256. switch (vha->hw->current_topology) {
  1257. case ISP_CFG_NL:
  1258. port_type = FC_PORTTYPE_LPORT;
  1259. break;
  1260. case ISP_CFG_FL:
  1261. port_type = FC_PORTTYPE_NLPORT;
  1262. break;
  1263. case ISP_CFG_N:
  1264. port_type = FC_PORTTYPE_PTP;
  1265. break;
  1266. case ISP_CFG_F:
  1267. port_type = FC_PORTTYPE_NPORT;
  1268. break;
  1269. }
  1270. fc_host_port_type(shost) = port_type;
  1271. }
  1272. static void
  1273. qla2x00_get_starget_node_name(struct scsi_target *starget)
  1274. {
  1275. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1276. scsi_qla_host_t *vha = shost_priv(host);
  1277. fc_port_t *fcport;
  1278. u64 node_name = 0;
  1279. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1280. if (fcport->rport &&
  1281. starget->id == fcport->rport->scsi_target_id) {
  1282. node_name = wwn_to_u64(fcport->node_name);
  1283. break;
  1284. }
  1285. }
  1286. fc_starget_node_name(starget) = node_name;
  1287. }
  1288. static void
  1289. qla2x00_get_starget_port_name(struct scsi_target *starget)
  1290. {
  1291. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1292. scsi_qla_host_t *vha = shost_priv(host);
  1293. fc_port_t *fcport;
  1294. u64 port_name = 0;
  1295. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1296. if (fcport->rport &&
  1297. starget->id == fcport->rport->scsi_target_id) {
  1298. port_name = wwn_to_u64(fcport->port_name);
  1299. break;
  1300. }
  1301. }
  1302. fc_starget_port_name(starget) = port_name;
  1303. }
  1304. static void
  1305. qla2x00_get_starget_port_id(struct scsi_target *starget)
  1306. {
  1307. struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
  1308. scsi_qla_host_t *vha = shost_priv(host);
  1309. fc_port_t *fcport;
  1310. uint32_t port_id = ~0U;
  1311. list_for_each_entry(fcport, &vha->vp_fcports, list) {
  1312. if (fcport->rport &&
  1313. starget->id == fcport->rport->scsi_target_id) {
  1314. port_id = fcport->d_id.b.domain << 16 |
  1315. fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
  1316. break;
  1317. }
  1318. }
  1319. fc_starget_port_id(starget) = port_id;
  1320. }
  1321. static void
  1322. qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
  1323. {
  1324. if (timeout)
  1325. rport->dev_loss_tmo = timeout;
  1326. else
  1327. rport->dev_loss_tmo = 1;
  1328. }
  1329. static void
  1330. qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
  1331. {
  1332. struct Scsi_Host *host = rport_to_shost(rport);
  1333. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1334. unsigned long flags;
  1335. if (!fcport)
  1336. return;
  1337. /* Now that the rport has been deleted, set the fcport state to
  1338. FCS_DEVICE_DEAD */
  1339. qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
  1340. /*
  1341. * Transport has effectively 'deleted' the rport, clear
  1342. * all local references.
  1343. */
  1344. spin_lock_irqsave(host->host_lock, flags);
  1345. fcport->rport = fcport->drport = NULL;
  1346. *((fc_port_t **)rport->dd_data) = NULL;
  1347. spin_unlock_irqrestore(host->host_lock, flags);
  1348. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1349. return;
  1350. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1351. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1352. return;
  1353. }
  1354. }
  1355. static void
  1356. qla2x00_terminate_rport_io(struct fc_rport *rport)
  1357. {
  1358. fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
  1359. if (!fcport)
  1360. return;
  1361. if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
  1362. return;
  1363. if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
  1364. qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
  1365. return;
  1366. }
  1367. /*
  1368. * At this point all fcport's software-states are cleared. Perform any
  1369. * final cleanup of firmware resources (PCBs and XCBs).
  1370. */
  1371. if (fcport->loop_id != FC_NO_LOOP_ID &&
  1372. !test_bit(UNLOADING, &fcport->vha->dpc_flags))
  1373. fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
  1374. fcport->loop_id, fcport->d_id.b.domain,
  1375. fcport->d_id.b.area, fcport->d_id.b.al_pa);
  1376. }
  1377. static int
  1378. qla2x00_issue_lip(struct Scsi_Host *shost)
  1379. {
  1380. scsi_qla_host_t *vha = shost_priv(shost);
  1381. qla2x00_loop_reset(vha);
  1382. return 0;
  1383. }
  1384. static struct fc_host_statistics *
  1385. qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
  1386. {
  1387. scsi_qla_host_t *vha = shost_priv(shost);
  1388. struct qla_hw_data *ha = vha->hw;
  1389. struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
  1390. int rval;
  1391. struct link_statistics *stats;
  1392. dma_addr_t stats_dma;
  1393. struct fc_host_statistics *pfc_host_stat;
  1394. pfc_host_stat = &ha->fc_host_stat;
  1395. memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
  1396. if (test_bit(UNLOADING, &vha->dpc_flags))
  1397. goto done;
  1398. if (unlikely(pci_channel_offline(ha->pdev)))
  1399. goto done;
  1400. stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
  1401. if (stats == NULL) {
  1402. ql_log(ql_log_warn, vha, 0x707d,
  1403. "Failed to allocate memory for stats.\n");
  1404. goto done;
  1405. }
  1406. memset(stats, 0, DMA_POOL_SIZE);
  1407. rval = QLA_FUNCTION_FAILED;
  1408. if (IS_FWI2_CAPABLE(ha)) {
  1409. rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
  1410. } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
  1411. !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
  1412. !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
  1413. !ha->dpc_active) {
  1414. /* Must be in a 'READY' state for statistics retrieval. */
  1415. rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
  1416. stats, stats_dma);
  1417. }
  1418. if (rval != QLA_SUCCESS)
  1419. goto done_free;
  1420. pfc_host_stat->link_failure_count = stats->link_fail_cnt;
  1421. pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
  1422. pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
  1423. pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
  1424. pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
  1425. pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
  1426. if (IS_FWI2_CAPABLE(ha)) {
  1427. pfc_host_stat->lip_count = stats->lip_cnt;
  1428. pfc_host_stat->tx_frames = stats->tx_frames;
  1429. pfc_host_stat->rx_frames = stats->rx_frames;
  1430. pfc_host_stat->dumped_frames = stats->dumped_frames;
  1431. pfc_host_stat->nos_count = stats->nos_rcvd;
  1432. }
  1433. pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
  1434. pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
  1435. done_free:
  1436. dma_pool_free(ha->s_dma_pool, stats, stats_dma);
  1437. done:
  1438. return pfc_host_stat;
  1439. }
  1440. static void
  1441. qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
  1442. {
  1443. scsi_qla_host_t *vha = shost_priv(shost);
  1444. qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
  1445. }
  1446. static void
  1447. qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
  1448. {
  1449. scsi_qla_host_t *vha = shost_priv(shost);
  1450. set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
  1451. }
  1452. static void
  1453. qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
  1454. {
  1455. scsi_qla_host_t *vha = shost_priv(shost);
  1456. uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
  1457. 0xFF, 0xFF, 0xFF, 0xFF};
  1458. u64 fabric_name = wwn_to_u64(node_name);
  1459. if (vha->device_flags & SWITCH_FOUND)
  1460. fabric_name = wwn_to_u64(vha->fabric_node_name);
  1461. fc_host_fabric_name(shost) = fabric_name;
  1462. }
  1463. static void
  1464. qla2x00_get_host_port_state(struct Scsi_Host *shost)
  1465. {
  1466. scsi_qla_host_t *vha = shost_priv(shost);
  1467. struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
  1468. if (!base_vha->flags.online)
  1469. fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
  1470. else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
  1471. fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
  1472. else
  1473. fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
  1474. }
  1475. static int
  1476. qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
  1477. {
  1478. int ret = 0;
  1479. uint8_t qos = 0;
  1480. scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
  1481. scsi_qla_host_t *vha = NULL;
  1482. struct qla_hw_data *ha = base_vha->hw;
  1483. uint16_t options = 0;
  1484. int cnt;
  1485. struct req_que *req = ha->req_q_map[0];
  1486. ret = qla24xx_vport_create_req_sanity_check(fc_vport);
  1487. if (ret) {
  1488. ql_log(ql_log_warn, vha, 0x707e,
  1489. "Vport sanity check failed, status %x\n", ret);
  1490. return (ret);
  1491. }
  1492. vha = qla24xx_create_vhost(fc_vport);
  1493. if (vha == NULL) {
  1494. ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
  1495. return FC_VPORT_FAILED;
  1496. }
  1497. if (disable) {
  1498. atomic_set(&vha->vp_state, VP_OFFLINE);
  1499. fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
  1500. } else
  1501. atomic_set(&vha->vp_state, VP_FAILED);
  1502. /* ready to create vport */
  1503. ql_log(ql_log_info, vha, 0x7080,
  1504. "VP entry id %d assigned.\n", vha->vp_idx);
  1505. /* initialized vport states */
  1506. atomic_set(&vha->loop_state, LOOP_DOWN);
  1507. vha->vp_err_state= VP_ERR_PORTDWN;
  1508. vha->vp_prev_err_state= VP_ERR_UNKWN;
  1509. /* Check if physical ha port is Up */
  1510. if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
  1511. atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
  1512. /* Don't retry or attempt login of this virtual port */
  1513. ql_dbg(ql_dbg_user, vha, 0x7081,
  1514. "Vport loop state is not UP.\n");
  1515. atomic_set(&vha->loop_state, LOOP_DEAD);
  1516. if (!disable)
  1517. fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
  1518. }
  1519. if ((IS_QLA25XX(ha) || IS_QLA81XX(ha)) && ql2xenabledif) {
  1520. if (ha->fw_attributes & BIT_4) {
  1521. vha->flags.difdix_supported = 1;
  1522. ql_dbg(ql_dbg_user, vha, 0x7082,
  1523. "Registered for DIF/DIX type 1 and 3 protection.\n");
  1524. scsi_host_set_prot(vha->host,
  1525. SHOST_DIF_TYPE1_PROTECTION
  1526. | SHOST_DIF_TYPE2_PROTECTION
  1527. | SHOST_DIF_TYPE3_PROTECTION
  1528. | SHOST_DIX_TYPE1_PROTECTION
  1529. | SHOST_DIX_TYPE2_PROTECTION
  1530. | SHOST_DIX_TYPE3_PROTECTION);
  1531. scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
  1532. } else
  1533. vha->flags.difdix_supported = 0;
  1534. }
  1535. if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
  1536. &ha->pdev->dev)) {
  1537. ql_dbg(ql_dbg_user, vha, 0x7083,
  1538. "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
  1539. goto vport_create_failed_2;
  1540. }
  1541. /* initialize attributes */
  1542. fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
  1543. fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
  1544. fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
  1545. fc_host_supported_classes(vha->host) =
  1546. fc_host_supported_classes(base_vha->host);
  1547. fc_host_supported_speeds(vha->host) =
  1548. fc_host_supported_speeds(base_vha->host);
  1549. qla24xx_vport_disable(fc_vport, disable);
  1550. if (ha->flags.cpu_affinity_enabled) {
  1551. req = ha->req_q_map[1];
  1552. ql_dbg(ql_dbg_multiq, vha, 0xc000,
  1553. "Request queue %p attached with "
  1554. "VP[%d], cpu affinity =%d\n",
  1555. req, vha->vp_idx, ha->flags.cpu_affinity_enabled);
  1556. goto vport_queue;
  1557. } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
  1558. goto vport_queue;
  1559. /* Create a request queue in QoS mode for the vport */
  1560. for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
  1561. if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
  1562. && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
  1563. 8) == 0) {
  1564. qos = ha->npiv_info[cnt].q_qos;
  1565. break;
  1566. }
  1567. }
  1568. if (qos) {
  1569. ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
  1570. qos);
  1571. if (!ret)
  1572. ql_log(ql_log_warn, vha, 0x7084,
  1573. "Can't create request queue for VP[%d]\n",
  1574. vha->vp_idx);
  1575. else {
  1576. ql_dbg(ql_dbg_multiq, vha, 0xc001,
  1577. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1578. ret, qos, vha->vp_idx);
  1579. ql_dbg(ql_dbg_user, vha, 0x7085,
  1580. "Request Que:%d Q0s: %d) created for VP[%d]\n",
  1581. ret, qos, vha->vp_idx);
  1582. req = ha->req_q_map[ret];
  1583. }
  1584. }
  1585. vport_queue:
  1586. vha->req = req;
  1587. return 0;
  1588. vport_create_failed_2:
  1589. qla24xx_disable_vp(vha);
  1590. qla24xx_deallocate_vp_id(vha);
  1591. scsi_host_put(vha->host);
  1592. return FC_VPORT_FAILED;
  1593. }
  1594. static int
  1595. qla24xx_vport_delete(struct fc_vport *fc_vport)
  1596. {
  1597. scsi_qla_host_t *vha = fc_vport->dd_data;
  1598. struct