1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2014 QLogic Corporation
7 #include "qla_target.h"
9 #include <linux/kthread.h>
10 #include <linux/vmalloc.h>
11 #include <linux/slab.h>
12 #include <linux/delay.h>
14 static int qla24xx_vport_disable(struct fc_vport *, bool);
16 /* SYSFS attributes --------------------------------------------------------- */
19 qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
20 struct bin_attribute *bin_attr,
21 char *buf, loff_t off, size_t count)
23 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
24 struct device, kobj)));
25 struct qla_hw_data *ha = vha->hw;
28 if (!(ha->fw_dump_reading || ha->mctp_dump_reading ||
29 ha->mpi_fw_dump_reading))
32 mutex_lock(&ha->optrom_mutex);
33 if (IS_P3P_TYPE(ha)) {
34 if (off < ha->md_template_size) {
35 rval = memory_read_from_buffer(buf, count,
36 &off, ha->md_tmplt_hdr, ha->md_template_size);
38 off -= ha->md_template_size;
39 rval = memory_read_from_buffer(buf, count,
40 &off, ha->md_dump, ha->md_dump_size);
42 } else if (ha->mctp_dumped && ha->mctp_dump_reading) {
43 rval = memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
45 } else if (ha->mpi_fw_dumped && ha->mpi_fw_dump_reading) {
46 rval = memory_read_from_buffer(buf, count, &off,
49 } else if (ha->fw_dump_reading) {
50 rval = memory_read_from_buffer(buf, count, &off, ha->fw_dump,
55 mutex_unlock(&ha->optrom_mutex);
60 qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
61 struct bin_attribute *bin_attr,
62 char *buf, loff_t off, size_t count)
64 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
65 struct device, kobj)));
66 struct qla_hw_data *ha = vha->hw;
72 reading = simple_strtol(buf, NULL, 10);
75 if (!ha->fw_dump_reading)
78 ql_log(ql_log_info, vha, 0x705d,
79 "Firmware dump cleared on (%ld).\n", vha->host_no);
81 if (IS_P3P_TYPE(ha)) {
85 ha->fw_dump_reading = 0;
86 ha->fw_dumped = false;
89 if (ha->fw_dumped && !ha->fw_dump_reading) {
90 ha->fw_dump_reading = 1;
92 ql_log(ql_log_info, vha, 0x705e,
93 "Raw firmware dump ready for read on (%ld).\n",
98 qla2x00_alloc_fw_dump(vha);
101 if (IS_QLA82XX(ha)) {
102 qla82xx_idc_lock(ha);
103 qla82xx_set_reset_owner(vha);
104 qla82xx_idc_unlock(ha);
105 } else if (IS_QLA8044(ha)) {
106 qla8044_idc_lock(ha);
107 qla82xx_set_reset_owner(vha);
108 qla8044_idc_unlock(ha);
110 qla2x00_system_error(vha);
114 if (IS_P3P_TYPE(ha)) {
115 if (ha->md_tmplt_hdr)
116 ql_dbg(ql_dbg_user, vha, 0x705b,
117 "MiniDump supported with this firmware.\n");
119 ql_dbg(ql_dbg_user, vha, 0x709d,
120 "MiniDump not supported with this firmware.\n");
125 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
128 if (!ha->mctp_dump_reading)
130 ql_log(ql_log_info, vha, 0x70c1,
131 "MCTP dump cleared on (%ld).\n", vha->host_no);
132 ha->mctp_dump_reading = 0;
136 if (ha->mctp_dumped && !ha->mctp_dump_reading) {
137 ha->mctp_dump_reading = 1;
138 ql_log(ql_log_info, vha, 0x70c2,
139 "Raw mctp dump ready for read on (%ld).\n",
144 if (!ha->mpi_fw_dump_reading)
146 ql_log(ql_log_info, vha, 0x70e7,
147 "MPI firmware dump cleared on (%ld).\n", vha->host_no);
148 ha->mpi_fw_dump_reading = 0;
149 ha->mpi_fw_dumped = 0;
152 if (ha->mpi_fw_dumped && !ha->mpi_fw_dump_reading) {
153 ha->mpi_fw_dump_reading = 1;
154 ql_log(ql_log_info, vha, 0x70e8,
155 "Raw MPI firmware dump ready for read on (%ld).\n",
160 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
161 ql_log(ql_log_info, vha, 0x70e9,
162 "Issuing MPI firmware dump on host#%ld.\n",
164 ha->isp_ops->mpi_fw_dump(vha, 0);
171 static struct bin_attribute sysfs_fw_dump_attr = {
174 .mode = S_IRUSR | S_IWUSR,
177 .read = qla2x00_sysfs_read_fw_dump,
178 .write = qla2x00_sysfs_write_fw_dump,
182 qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
183 struct bin_attribute *bin_attr,
184 char *buf, loff_t off, size_t count)
186 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
187 struct device, kobj)));
188 struct qla_hw_data *ha = vha->hw;
190 struct active_regions active_regions = { };
192 if (!capable(CAP_SYS_ADMIN))
195 mutex_lock(&ha->optrom_mutex);
196 if (qla2x00_chip_is_down(vha)) {
197 mutex_unlock(&ha->optrom_mutex);
201 if (!IS_NOCACHE_VPD_TYPE(ha)) {
202 mutex_unlock(&ha->optrom_mutex);
206 faddr = ha->flt_region_nvram;
207 if (IS_QLA28XX(ha)) {
208 qla28xx_get_aux_images(vha, &active_regions);
209 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
210 faddr = ha->flt_region_nvram_sec;
212 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
214 mutex_unlock(&ha->optrom_mutex);
217 return memory_read_from_buffer(buf, count, &off, ha->nvram,
222 qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
223 struct bin_attribute *bin_attr,
224 char *buf, loff_t off, size_t count)
226 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
227 struct device, kobj)));
228 struct qla_hw_data *ha = vha->hw;
231 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
232 !ha->isp_ops->write_nvram)
235 /* Checksum NVRAM. */
236 if (IS_FWI2_CAPABLE(ha)) {
237 __le32 *iter = (__force __le32 *)buf;
241 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++, iter++)
242 chksum += le32_to_cpu(*iter);
243 chksum = ~chksum + 1;
244 *iter = cpu_to_le32(chksum);
249 iter = (uint8_t *)buf;
251 for (cnt = 0; cnt < count - 1; cnt++)
253 chksum = ~chksum + 1;
257 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
258 ql_log(ql_log_warn, vha, 0x705f,
259 "HBA not online, failing NVRAM update.\n");
263 mutex_lock(&ha->optrom_mutex);
264 if (qla2x00_chip_is_down(vha)) {
265 mutex_unlock(&ha->optrom_mutex);
270 ha->isp_ops->write_nvram(vha, buf, ha->nvram_base, count);
271 ha->isp_ops->read_nvram(vha, ha->nvram, ha->nvram_base,
273 mutex_unlock(&ha->optrom_mutex);
275 ql_dbg(ql_dbg_user, vha, 0x7060,
276 "Setting ISP_ABORT_NEEDED\n");
277 /* NVRAM settings take effect immediately. */
278 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
279 qla2xxx_wake_dpc(vha);
280 qla2x00_wait_for_chip_reset(vha);
285 static struct bin_attribute sysfs_nvram_attr = {
288 .mode = S_IRUSR | S_IWUSR,
291 .read = qla2x00_sysfs_read_nvram,
292 .write = qla2x00_sysfs_write_nvram,
296 qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
297 struct bin_attribute *bin_attr,
298 char *buf, loff_t off, size_t count)
300 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
301 struct device, kobj)));
302 struct qla_hw_data *ha = vha->hw;
305 mutex_lock(&ha->optrom_mutex);
307 if (ha->optrom_state != QLA_SREADING)
310 rval = memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
311 ha->optrom_region_size);
314 mutex_unlock(&ha->optrom_mutex);
320 qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
321 struct bin_attribute *bin_attr,
322 char *buf, loff_t off, size_t count)
324 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
325 struct device, kobj)));
326 struct qla_hw_data *ha = vha->hw;
328 mutex_lock(&ha->optrom_mutex);
330 if (ha->optrom_state != QLA_SWRITING) {
331 mutex_unlock(&ha->optrom_mutex);
334 if (off > ha->optrom_region_size) {
335 mutex_unlock(&ha->optrom_mutex);
338 if (off + count > ha->optrom_region_size)
339 count = ha->optrom_region_size - off;
341 memcpy(&ha->optrom_buffer[off], buf, count);
342 mutex_unlock(&ha->optrom_mutex);
347 static struct bin_attribute sysfs_optrom_attr = {
350 .mode = S_IRUSR | S_IWUSR,
353 .read = qla2x00_sysfs_read_optrom,
354 .write = qla2x00_sysfs_write_optrom,
358 qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
359 struct bin_attribute *bin_attr,
360 char *buf, loff_t off, size_t count)
362 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
363 struct device, kobj)));
364 struct qla_hw_data *ha = vha->hw;
366 uint32_t size = ha->optrom_size;
368 ssize_t rval = count;
373 if (unlikely(pci_channel_offline(ha->pdev)))
376 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
378 if (start > ha->optrom_size)
380 if (size > ha->optrom_size - start)
381 size = ha->optrom_size - start;
383 mutex_lock(&ha->optrom_mutex);
384 if (qla2x00_chip_is_down(vha)) {
385 mutex_unlock(&ha->optrom_mutex);
390 if (ha->optrom_state != QLA_SREADING &&
391 ha->optrom_state != QLA_SWRITING) {
395 ha->optrom_state = QLA_SWAITING;
397 ql_dbg(ql_dbg_user, vha, 0x7061,
398 "Freeing flash region allocation -- 0x%x bytes.\n",
399 ha->optrom_region_size);
401 vfree(ha->optrom_buffer);
402 ha->optrom_buffer = NULL;
405 if (ha->optrom_state != QLA_SWAITING) {
410 ha->optrom_region_start = start;
411 ha->optrom_region_size = size;
413 ha->optrom_state = QLA_SREADING;
414 ha->optrom_buffer = vzalloc(ha->optrom_region_size);
415 if (ha->optrom_buffer == NULL) {
416 ql_log(ql_log_warn, vha, 0x7062,
417 "Unable to allocate memory for optrom retrieval "
418 "(%x).\n", ha->optrom_region_size);
420 ha->optrom_state = QLA_SWAITING;
425 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
426 ql_log(ql_log_warn, vha, 0x7063,
427 "HBA not online, failing NVRAM update.\n");
432 ql_dbg(ql_dbg_user, vha, 0x7064,
433 "Reading flash region -- 0x%x/0x%x.\n",
434 ha->optrom_region_start, ha->optrom_region_size);
436 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
437 ha->optrom_region_start, ha->optrom_region_size);
440 if (ha->optrom_state != QLA_SWAITING) {
446 * We need to be more restrictive on which FLASH regions are
447 * allowed to be updated via user-space. Regions accessible
448 * via this method include:
450 * ISP21xx/ISP22xx/ISP23xx type boards:
452 * 0x000000 -> 0x020000 -- Boot code.
454 * ISP2322/ISP24xx type boards:
456 * 0x000000 -> 0x07ffff -- Boot code.
457 * 0x080000 -> 0x0fffff -- Firmware.
459 * ISP25xx type boards:
461 * 0x000000 -> 0x07ffff -- Boot code.
462 * 0x080000 -> 0x0fffff -- Firmware.
463 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
465 * > ISP25xx type boards:
467 * None -- should go through BSG.
470 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
472 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
475 ql_log(ql_log_warn, vha, 0x7065,
476 "Invalid start region 0x%x/0x%x.\n", start, size);
481 ha->optrom_region_start = start;
482 ha->optrom_region_size = size;
484 ha->optrom_state = QLA_SWRITING;
485 ha->optrom_buffer = vzalloc(ha->optrom_region_size);
486 if (ha->optrom_buffer == NULL) {
487 ql_log(ql_log_warn, vha, 0x7066,
488 "Unable to allocate memory for optrom update "
489 "(%x)\n", ha->optrom_region_size);
491 ha->optrom_state = QLA_SWAITING;
496 ql_dbg(ql_dbg_user, vha, 0x7067,
497 "Staging flash region write -- 0x%x/0x%x.\n",
498 ha->optrom_region_start, ha->optrom_region_size);
502 if (ha->optrom_state != QLA_SWRITING) {
507 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
508 ql_log(ql_log_warn, vha, 0x7068,
509 "HBA not online, failing flash update.\n");
514 ql_dbg(ql_dbg_user, vha, 0x7069,
515 "Writing flash region -- 0x%x/0x%x.\n",
516 ha->optrom_region_start, ha->optrom_region_size);
518 rval = ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
519 ha->optrom_region_start, ha->optrom_region_size);
528 mutex_unlock(&ha->optrom_mutex);
532 static struct bin_attribute sysfs_optrom_ctl_attr = {
534 .name = "optrom_ctl",
538 .write = qla2x00_sysfs_write_optrom_ctl,
542 qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
543 struct bin_attribute *bin_attr,
544 char *buf, loff_t off, size_t count)
546 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
547 struct device, kobj)));
548 struct qla_hw_data *ha = vha->hw;
550 struct active_regions active_regions = { };
552 if (unlikely(pci_channel_offline(ha->pdev)))
555 if (!capable(CAP_SYS_ADMIN))
558 if (!IS_NOCACHE_VPD_TYPE(ha))
561 faddr = ha->flt_region_vpd << 2;
563 if (IS_QLA28XX(ha)) {
564 qla28xx_get_aux_images(vha, &active_regions);
565 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
566 faddr = ha->flt_region_vpd_sec << 2;
568 ql_dbg(ql_dbg_init, vha, 0x7070,
569 "Loading %s nvram image.\n",
570 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
571 "primary" : "secondary");
574 mutex_lock(&ha->optrom_mutex);
575 if (qla2x00_chip_is_down(vha)) {
576 mutex_unlock(&ha->optrom_mutex);
580 ha->isp_ops->read_optrom(vha, ha->vpd, faddr, ha->vpd_size);
581 mutex_unlock(&ha->optrom_mutex);
583 ha->isp_ops->read_optrom(vha, ha->vpd, faddr, ha->vpd_size);
585 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
589 qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
590 struct bin_attribute *bin_attr,
591 char *buf, loff_t off, size_t count)
593 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
594 struct device, kobj)));
595 struct qla_hw_data *ha = vha->hw;
598 if (unlikely(pci_channel_offline(ha->pdev)))
601 if (qla2x00_chip_is_down(vha))
604 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
605 !ha->isp_ops->write_nvram)
608 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
609 ql_log(ql_log_warn, vha, 0x706a,
610 "HBA not online, failing VPD update.\n");
614 mutex_lock(&ha->optrom_mutex);
615 if (qla2x00_chip_is_down(vha)) {
616 mutex_unlock(&ha->optrom_mutex);
621 ha->isp_ops->write_nvram(vha, buf, ha->vpd_base, count);
622 ha->isp_ops->read_nvram(vha, ha->vpd, ha->vpd_base, count);
624 /* Update flash version information for 4Gb & above. */
625 if (!IS_FWI2_CAPABLE(ha)) {
626 mutex_unlock(&ha->optrom_mutex);
630 tmp_data = vmalloc(256);
632 mutex_unlock(&ha->optrom_mutex);
633 ql_log(ql_log_warn, vha, 0x706b,
634 "Unable to allocate memory for VPD information update.\n");
637 ha->isp_ops->get_flash_version(vha, tmp_data);
640 mutex_unlock(&ha->optrom_mutex);
645 static struct bin_attribute sysfs_vpd_attr = {
648 .mode = S_IRUSR | S_IWUSR,
651 .read = qla2x00_sysfs_read_vpd,
652 .write = qla2x00_sysfs_write_vpd,
656 qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
657 struct bin_attribute *bin_attr,
658 char *buf, loff_t off, size_t count)
660 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
661 struct device, kobj)));
664 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < SFP_DEV_SIZE)
667 mutex_lock(&vha->hw->optrom_mutex);
668 if (qla2x00_chip_is_down(vha)) {
669 mutex_unlock(&vha->hw->optrom_mutex);
673 rval = qla2x00_read_sfp_dev(vha, buf, count);
674 mutex_unlock(&vha->hw->optrom_mutex);
682 static struct bin_attribute sysfs_sfp_attr = {
685 .mode = S_IRUSR | S_IWUSR,
687 .size = SFP_DEV_SIZE,
688 .read = qla2x00_sysfs_read_sfp,
692 qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
693 struct bin_attribute *bin_attr,
694 char *buf, loff_t off, size_t count)
696 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
697 struct device, kobj)));
698 struct qla_hw_data *ha = vha->hw;
699 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
701 uint32_t idc_control;
702 uint8_t *tmp_data = NULL;
707 type = simple_strtol(buf, NULL, 10);
710 ql_log(ql_log_info, vha, 0x706e,
711 "Issuing ISP reset.\n");
713 scsi_block_requests(vha->host);
714 if (IS_QLA82XX(ha)) {
715 ha->flags.isp82xx_no_md_cap = 1;
716 qla82xx_idc_lock(ha);
717 qla82xx_set_reset_owner(vha);
718 qla82xx_idc_unlock(ha);
719 } else if (IS_QLA8044(ha)) {
720 qla8044_idc_lock(ha);
721 idc_control = qla8044_rd_reg(ha,
722 QLA8044_IDC_DRV_CTRL);
723 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
724 (idc_control | GRACEFUL_RESET_BIT1));
725 qla82xx_set_reset_owner(vha);
726 qla8044_idc_unlock(ha);
728 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
729 qla2xxx_wake_dpc(vha);
731 qla2x00_wait_for_chip_reset(vha);
732 scsi_unblock_requests(vha->host);
735 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
736 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
739 ql_log(ql_log_info, vha, 0x706f,
740 "Issuing MPI reset.\n");
742 if (IS_QLA83XX(ha)) {
743 uint32_t idc_control;
745 qla83xx_idc_lock(vha, 0);
746 __qla83xx_get_idc_control(vha, &idc_control);
747 idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
748 __qla83xx_set_idc_control(vha, idc_control);
749 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
750 QLA8XXX_DEV_NEED_RESET);
751 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
752 qla83xx_idc_unlock(vha, 0);
755 /* Make sure FC side is not in reset */
756 WARN_ON_ONCE(qla2x00_wait_for_hba_online(vha) !=
759 /* Issue MPI reset */
760 scsi_block_requests(vha->host);
761 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
762 ql_log(ql_log_warn, vha, 0x7070,
763 "MPI reset failed.\n");
764 scsi_unblock_requests(vha->host);
769 if (!IS_P3P_TYPE(ha) || vha != base_vha) {
770 ql_log(ql_log_info, vha, 0x7071,
771 "FCoE ctx reset not supported.\n");
775 ql_log(ql_log_info, vha, 0x7072,
776 "Issuing FCoE ctx reset.\n");
777 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
778 qla2xxx_wake_dpc(vha);
779 qla2x00_wait_for_fcoe_ctx_reset(vha);
784 ql_log(ql_log_info, vha, 0x70bc,
785 "Disabling Reset by IDC control\n");
786 qla83xx_idc_lock(vha, 0);
787 __qla83xx_get_idc_control(vha, &idc_control);
788 idc_control |= QLA83XX_IDC_RESET_DISABLED;
789 __qla83xx_set_idc_control(vha, idc_control);
790 qla83xx_idc_unlock(vha, 0);
795 ql_log(ql_log_info, vha, 0x70bd,
796 "Enabling Reset by IDC control\n");
797 qla83xx_idc_lock(vha, 0);
798 __qla83xx_get_idc_control(vha, &idc_control);
799 idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
800 __qla83xx_set_idc_control(vha, idc_control);
801 qla83xx_idc_unlock(vha, 0);
804 ql_dbg(ql_dbg_user, vha, 0x70e0,
805 "Updating cache versions without reset ");
807 tmp_data = vmalloc(256);
809 ql_log(ql_log_warn, vha, 0x70e1,
810 "Unable to allocate memory for VPD information update.\n");
813 ha->isp_ops->get_flash_version(vha, tmp_data);
820 static struct bin_attribute sysfs_reset_attr = {
826 .write = qla2x00_sysfs_write_reset,
830 qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
831 struct bin_attribute *bin_attr,
832 char *buf, loff_t off, size_t count)
834 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
835 struct device, kobj)));
839 if (!capable(CAP_SYS_ADMIN))
842 if (unlikely(pci_channel_offline(vha->hw->pdev)))
845 if (qla2x00_chip_is_down(vha))
848 type = simple_strtol(buf, NULL, 10);
850 did.b.domain = (type & 0x00ff0000) >> 16;
851 did.b.area = (type & 0x0000ff00) >> 8;
852 did.b.al_pa = (type & 0x000000ff);
854 ql_log(ql_log_info, vha, 0xd04d, "portid=%02x%02x%02x done\n",
855 did.b.domain, did.b.area, did.b.al_pa);
857 ql_log(ql_log_info, vha, 0x70e4, "%s: %d\n", __func__, type);
859 qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, did);
863 static struct bin_attribute sysfs_issue_logo_attr = {
865 .name = "issue_logo",
869 .write = qla2x00_issue_logo,
873 qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
874 struct bin_attribute *bin_attr,
875 char *buf, loff_t off, size_t count)
877 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
878 struct device, kobj)));
879 struct qla_hw_data *ha = vha->hw;
881 uint16_t actual_size;
883 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
886 if (unlikely(pci_channel_offline(ha->pdev)))
888 mutex_lock(&vha->hw->optrom_mutex);
889 if (qla2x00_chip_is_down(vha)) {
890 mutex_unlock(&vha->hw->optrom_mutex);
897 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
898 &ha->xgmac_data_dma, GFP_KERNEL);
899 if (!ha->xgmac_data) {
900 mutex_unlock(&vha->hw->optrom_mutex);
901 ql_log(ql_log_warn, vha, 0x7076,
902 "Unable to allocate memory for XGMAC read-data.\n");
908 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
910 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
911 XGMAC_DATA_SIZE, &actual_size);
913 mutex_unlock(&vha->hw->optrom_mutex);
914 if (rval != QLA_SUCCESS) {
915 ql_log(ql_log_warn, vha, 0x7077,
916 "Unable to read XGMAC data (%x).\n", rval);
920 count = actual_size > count ? count : actual_size;
921 memcpy(buf, ha->xgmac_data, count);
926 static struct bin_attribute sysfs_xgmac_stats_attr = {
928 .name = "xgmac_stats",
932 .read = qla2x00_sysfs_read_xgmac_stats,
936 qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
937 struct bin_attribute *bin_attr,
938 char *buf, loff_t off, size_t count)
940 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
941 struct device, kobj)));
942 struct qla_hw_data *ha = vha->hw;
945 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
950 mutex_lock(&vha->hw->optrom_mutex);
951 if (qla2x00_chip_is_down(vha)) {
952 mutex_unlock(&vha->hw->optrom_mutex);
956 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
957 &ha->dcbx_tlv_dma, GFP_KERNEL);
959 mutex_unlock(&vha->hw->optrom_mutex);
960 ql_log(ql_log_warn, vha, 0x7078,
961 "Unable to allocate memory for DCBX TLV read-data.\n");
966 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
968 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
971 mutex_unlock(&vha->hw->optrom_mutex);
973 if (rval != QLA_SUCCESS) {
974 ql_log(ql_log_warn, vha, 0x7079,
975 "Unable to read DCBX TLV (%x).\n", rval);
979 memcpy(buf, ha->dcbx_tlv, count);
984 static struct bin_attribute sysfs_dcbx_tlv_attr = {
990 .read = qla2x00_sysfs_read_dcbx_tlv,
993 static struct sysfs_entry {
995 struct bin_attribute *attr;
997 } bin_file_entries[] = {
998 { "fw_dump", &sysfs_fw_dump_attr, },
999 { "nvram", &sysfs_nvram_attr, },
1000 { "optrom", &sysfs_optrom_attr, },
1001 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
1002 { "vpd", &sysfs_vpd_attr, 1 },
1003 { "sfp", &sysfs_sfp_attr, 1 },
1004 { "reset", &sysfs_reset_attr, },
1005 { "issue_logo", &sysfs_issue_logo_attr, },
1006 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
1007 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
1012 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
1014 struct Scsi_Host *host = vha->host;
1015 struct sysfs_entry *iter;
1018 for (iter = bin_file_entries; iter->name; iter++) {
1019 if (iter->type && !IS_FWI2_CAPABLE(vha->hw))
1021 if (iter->type == 2 && !IS_QLA25XX(vha->hw))
1023 if (iter->type == 3 && !(IS_CNA_CAPABLE(vha->hw)))
1026 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
1029 ql_log(ql_log_warn, vha, 0x00f3,
1030 "Unable to create sysfs %s binary attribute (%d).\n",
1033 ql_dbg(ql_dbg_init, vha, 0x00f4,
1034 "Successfully created sysfs %s binary attribute.\n",
1040 qla2x00_free_sysfs_attr(scsi_qla_host_t *vha, bool stop_beacon)
1042 struct Scsi_Host *host = vha->host;
1043 struct sysfs_entry *iter;
1044 struct qla_hw_data *ha = vha->hw;
1046 for (iter = bin_file_entries; iter->name; iter++) {
1047 if (iter->type && !IS_FWI2_CAPABLE(ha))
1049 if (iter->type == 2 && !IS_QLA25XX(ha))
1051 if (iter->type == 3 && !(IS_CNA_CAPABLE(ha)))
1054 sysfs_remove_bin_file(&host->shost_gendev.kobj,
1058 if (stop_beacon && ha->beacon_blink_led == 1)
1059 ha->isp_ops->beacon_off(vha);
1062 /* Scsi_Host attributes. */
1065 qla2x00_driver_version_show(struct device *dev,
1066 struct device_attribute *attr, char *buf)
1068 return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
1072 qla2x00_fw_version_show(struct device *dev,
1073 struct device_attribute *attr, char *buf)
1075 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1076 struct qla_hw_data *ha = vha->hw;
1079 return scnprintf(buf, PAGE_SIZE, "%s\n",
1080 ha->isp_ops->fw_version_str(vha, fw_str, sizeof(fw_str)));
1084 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
1087 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1088 struct qla_hw_data *ha = vha->hw;
1091 if (IS_QLAFX00(vha->hw)) {
1092 return scnprintf(buf, PAGE_SIZE, "%s\n",
1093 vha->hw->mr.serial_num);
1094 } else if (IS_FWI2_CAPABLE(ha)) {
1095 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE - 1);
1096 return strlen(strcat(buf, "\n"));
1099 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1100 return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
1105 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
1108 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1110 return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
1114 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
1117 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1118 struct qla_hw_data *ha = vha->hw;
1120 if (IS_QLAFX00(vha->hw))
1121 return scnprintf(buf, PAGE_SIZE, "%s\n",
1122 vha->hw->mr.hw_version);
1124 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
1125 ha->product_id[0], ha->product_id[1], ha->product_id[2],
1130 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
1133 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1135 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
1139 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1142 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1144 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
1148 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1151 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1154 return scnprintf(buf, PAGE_SIZE, "%s\n",
1155 vha->hw->isp_ops->pci_info_str(vha, pci_info,
1160 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1163 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1164 struct qla_hw_data *ha = vha->hw;
1167 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
1168 atomic_read(&vha->loop_state) == LOOP_DEAD ||
1169 vha->device_flags & DFLG_NO_CABLE)
1170 len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
1171 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1172 qla2x00_chip_is_down(vha))
1173 len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1175 len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
1177 switch (ha->current_topology) {
1179 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1182 len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1185 len += scnprintf(buf + len, PAGE_SIZE-len,
1186 "N_Port to N_Port\n");
1189 len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1192 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1200 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1203 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1206 switch (vha->hw->zio_mode) {
1207 case QLA_ZIO_MODE_6:
1208 len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1210 case QLA_ZIO_DISABLED:
1211 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1218 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1219 const char *buf, size_t count)
1221 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1222 struct qla_hw_data *ha = vha->hw;
1226 if (!IS_ZIO_SUPPORTED(ha))
1229 if (sscanf(buf, "%d", &val) != 1)
1233 zio_mode = QLA_ZIO_MODE_6;
1235 zio_mode = QLA_ZIO_DISABLED;
1237 /* Update per-hba values and queue a reset. */
1238 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1239 ha->zio_mode = zio_mode;
1240 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1246 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1249 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1251 return scnprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
1255 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1256 const char *buf, size_t count)
1258 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1262 if (sscanf(buf, "%d", &val) != 1)
1264 if (val > 25500 || val < 100)
1267 zio_timer = (uint16_t)(val / 100);
1268 vha->hw->zio_timer = zio_timer;
1274 qla_zio_threshold_show(struct device *dev, struct device_attribute *attr,
1277 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1279 return scnprintf(buf, PAGE_SIZE, "%d exchanges\n",
1280 vha->hw->last_zio_threshold);
1284 qla_zio_threshold_store(struct device *dev, struct device_attribute *attr,
1285 const char *buf, size_t count)
1287 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1290 if (vha->hw->zio_mode != QLA_ZIO_MODE_6)
1292 if (sscanf(buf, "%d", &val) != 1)
1294 if (val < 0 || val > 256)
1297 atomic_set(&vha->hw->zio_threshold, val);
1302 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1305 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1308 if (vha->hw->beacon_blink_led)
1309 len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1311 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1316 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1317 const char *buf, size_t count)
1319 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1320 struct qla_hw_data *ha = vha->hw;
1324 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1327 if (sscanf(buf, "%d", &val) != 1)
1330 mutex_lock(&vha->hw->optrom_mutex);
1331 if (qla2x00_chip_is_down(vha)) {
1332 mutex_unlock(&vha->hw->optrom_mutex);
1333 ql_log(ql_log_warn, vha, 0x707a,
1334 "Abort ISP active -- ignoring beacon request.\n");
1339 rval = ha->isp_ops->beacon_on(vha);
1341 rval = ha->isp_ops->beacon_off(vha);
1343 if (rval != QLA_SUCCESS)
1346 mutex_unlock(&vha->hw->optrom_mutex);
1352 qla2x00_beacon_config_show(struct device *dev, struct device_attribute *attr,
1355 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1356 struct qla_hw_data *ha = vha->hw;
1357 uint16_t led[3] = { 0 };
1359 if (!IS_QLA2031(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1362 if (ql26xx_led_config(vha, 0, led))
1363 return scnprintf(buf, PAGE_SIZE, "\n");
1365 return scnprintf(buf, PAGE_SIZE, "%#04hx %#04hx %#04hx\n",
1366 led[0], led[1], led[2]);
1370 qla2x00_beacon_config_store(struct device *dev, struct device_attribute *attr,
1371 const char *buf, size_t count)
1373 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1374 struct qla_hw_data *ha = vha->hw;
1375 uint16_t options = BIT_0;
1376 uint16_t led[3] = { 0 };
1380 if (!IS_QLA2031(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1383 n = sscanf(buf, "%hx %hx %hx %hx", word+0, word+1, word+2, word+3);
1386 options |= BIT_3|BIT_2|BIT_1;
1396 /* check led index */
1418 if (ql26xx_led_config(vha, options, led))
1425 qla2x00_optrom_bios_version_show(struct device *dev,
1426 struct device_attribute *attr, char *buf)
1428 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1429 struct qla_hw_data *ha = vha->hw;
1431 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1432 ha->bios_revision[0]);
1436 qla2x00_optrom_efi_version_show(struct device *dev,
1437 struct device_attribute *attr, char *buf)
1439 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1440 struct qla_hw_data *ha = vha->hw;
1442 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1443 ha->efi_revision[0]);
1447 qla2x00_optrom_fcode_version_show(struct device *dev,
1448 struct device_attribute *attr, char *buf)
1450 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1451 struct qla_hw_data *ha = vha->hw;
1453 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1454 ha->fcode_revision[0]);
1458 qla2x00_optrom_fw_version_show(struct device *dev,
1459 struct device_attribute *attr, char *buf)
1461 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1462 struct qla_hw_data *ha = vha->hw;
1464 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1465 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1466 ha->fw_revision[3]);
1470 qla2x00_optrom_gold_fw_version_show(struct device *dev,
1471 struct device_attribute *attr, char *buf)
1473 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1474 struct qla_hw_data *ha = vha->hw;
1476 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1477 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1478 return scnprintf(buf, PAGE_SIZE, "\n");
1480 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1481 ha->gold_fw_version[0], ha->gold_fw_version[1],
1482 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1486 qla2x00_total_isp_aborts_show(struct device *dev,
1487 struct device_attribute *attr, char *buf)
1489 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1491 return scnprintf(buf, PAGE_SIZE, "%d\n",
1492 vha->qla_stats.total_isp_aborts);
1496 qla24xx_84xx_fw_version_show(struct device *dev,
1497 struct device_attribute *attr, char *buf)
1499 int rval = QLA_SUCCESS;
1500 uint16_t status[2] = { 0 };
1501 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1502 struct qla_hw_data *ha = vha->hw;
1504 if (!IS_QLA84XX(ha))
1505 return scnprintf(buf, PAGE_SIZE, "\n");
1507 if (!ha->cs84xx->op_fw_version) {
1508 rval = qla84xx_verify_chip(vha, status);
1510 if (!rval && !status[0])
1511 return scnprintf(buf, PAGE_SIZE, "%u\n",
1512 (uint32_t)ha->cs84xx->op_fw_version);
1515 return scnprintf(buf, PAGE_SIZE, "\n");
1519 qla2x00_serdes_version_show(struct device *dev, struct device_attribute *attr,
1522 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1523 struct qla_hw_data *ha = vha->hw;
1525 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1526 return scnprintf(buf, PAGE_SIZE, "\n");
1528 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1529 ha->serdes_version[0], ha->serdes_version[1],
1530 ha->serdes_version[2]);
1534 qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1537 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1538 struct qla_hw_data *ha = vha->hw;
1540 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
1541 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1542 return scnprintf(buf, PAGE_SIZE, "\n");
1544 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
1545 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
1546 ha->mpi_capabilities);
1550 qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1553 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1554 struct qla_hw_data *ha = vha->hw;
1556 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
1557 return scnprintf(buf, PAGE_SIZE, "\n");
1559 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1560 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
1564 qla2x00_flash_block_size_show(struct device *dev,
1565 struct device_attribute *attr, char *buf)
1567 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1568 struct qla_hw_data *ha = vha->hw;
1570 return scnprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1574 qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1577 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1579 if (!IS_CNA_CAPABLE(vha->hw))
1580 return scnprintf(buf, PAGE_SIZE, "\n");
1582 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1586 qla2x00_vn_port_mac_address_show(struct device *dev,
1587 struct device_attribute *attr, char *buf)
1589 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1591 if (!IS_CNA_CAPABLE(vha->hw))
1592 return scnprintf(buf, PAGE_SIZE, "\n");
1594 return scnprintf(buf, PAGE_SIZE, "%pMR\n", vha->fcoe_vn_port_mac);
1598 qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1601 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1603 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1607 qla2x00_thermal_temp_show(struct device *dev,
1608 struct device_attribute *attr, char *buf)
1610 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1614 mutex_lock(&vha->hw->optrom_mutex);
1615 if (qla2x00_chip_is_down(vha)) {
1616 mutex_unlock(&vha->hw->optrom_mutex);
1617 ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
1621 if (vha->hw->flags.eeh_busy) {
1622 mutex_unlock(&vha->hw->optrom_mutex);
1623 ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
1627 rc = qla2x00_get_thermal_temp(vha, &temp);
1628 mutex_unlock(&vha->hw->optrom_mutex);
1629 if (rc == QLA_SUCCESS)
1630 return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
1633 return scnprintf(buf, PAGE_SIZE, "\n");
1637 qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1640 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1641 int rval = QLA_FUNCTION_FAILED;
1645 if (IS_QLAFX00(vha->hw)) {
1646 pstate = qlafx00_fw_state_show(dev, attr, buf);
1647 return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
1650 mutex_lock(&vha->hw->optrom_mutex);
1651 if (qla2x00_chip_is_down(vha)) {
1652 mutex_unlock(&vha->hw->optrom_mutex);
1653 ql_log(ql_log_warn, vha, 0x707c,
1654 "ISP reset active.\n");
1656 } else if (vha->hw->flags.eeh_busy) {
1657 mutex_unlock(&vha->hw->optrom_mutex);
1661 rval = qla2x00_get_firmware_state(vha, state);
1662 mutex_unlock(&vha->hw->optrom_mutex);
1664 if (rval != QLA_SUCCESS) {
1665 memset(state, -1, sizeof(state));
1666 rval = qla2x00_get_firmware_state(vha, state);
1669 return scnprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1670 state[0], state[1], state[2], state[3], state[4], state[5]);
1674 qla2x00_diag_requests_show(struct device *dev,
1675 struct device_attribute *attr, char *buf)
1677 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1679 if (!IS_BIDI_CAPABLE(vha->hw))
1680 return scnprintf(buf, PAGE_SIZE, "\n");
1682 return scnprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
1686 qla2x00_diag_megabytes_show(struct device *dev,
1687 struct device_attribute *attr, char *buf)
1689 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1691 if (!IS_BIDI_CAPABLE(vha->hw))
1692 return scnprintf(buf, PAGE_SIZE, "\n");
1694 return scnprintf(buf, PAGE_SIZE, "%llu\n",
1695 vha->bidi_stats.transfer_bytes >> 20);
1699 qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
1702 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1703 struct qla_hw_data *ha = vha->hw;
1708 else if (IS_P3P_TYPE(ha))
1709 size = ha->md_template_size + ha->md_dump_size;
1711 size = ha->fw_dump_len;
1713 return scnprintf(buf, PAGE_SIZE, "%d\n", size);
1717 qla2x00_allow_cna_fw_dump_show(struct device *dev,
1718 struct device_attribute *attr, char *buf)
1720 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1722 if (!IS_P3P_TYPE(vha->hw))
1723 return scnprintf(buf, PAGE_SIZE, "\n");
1725 return scnprintf(buf, PAGE_SIZE, "%s\n",
1726 vha->hw->allow_cna_fw_dump ? "true" : "false");
1730 qla2x00_allow_cna_fw_dump_store(struct device *dev,
1731 struct device_attribute *attr, const char *buf, size_t count)
1733 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1736 if (!IS_P3P_TYPE(vha->hw))
1739 if (sscanf(buf, "%d", &val) != 1)
1742 vha->hw->allow_cna_fw_dump = val != 0;
1748 qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
1751 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1752 struct qla_hw_data *ha = vha->hw;
1754 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1755 return scnprintf(buf, PAGE_SIZE, "\n");
1757 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1758 ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
1762 qla2x00_min_supported_speed_show(struct device *dev,
1763 struct device_attribute *attr, char *buf)
1765 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1766 struct qla_hw_data *ha = vha->hw;
1768 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1769 return scnprintf(buf, PAGE_SIZE, "\n");
1771 return scnprintf(buf, PAGE_SIZE, "%s\n",
1772 ha->min_supported_speed == 6 ? "64Gps" :
1773 ha->min_supported_speed == 5 ? "32Gps" :
1774 ha->min_supported_speed == 4 ? "16Gps" :
1775 ha->min_supported_speed == 3 ? "8Gps" :
1776 ha->min_supported_speed == 2 ? "4Gps" :
1777 ha->min_supported_speed != 0 ? "unknown" : "");
1781 qla2x00_max_supported_speed_show(struct device *dev,
1782 struct device_attribute *attr, char *buf)
1784 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1785 struct qla_hw_data *ha = vha->hw;
1787 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1788 return scnprintf(buf, PAGE_SIZE, "\n");
1790 return scnprintf(buf, PAGE_SIZE, "%s\n",
1791 ha->max_supported_speed == 2 ? "64Gps" :
1792 ha->max_supported_speed == 1 ? "32Gps" :
1793 ha->max_supported_speed == 0 ? "16Gps" : "unknown");
1797 qla2x00_port_speed_store(struct device *dev, struct device_attribute *attr,
1798 const char *buf, size_t count)
1800 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1803 int mode = QLA_SET_DATA_RATE_LR;
1804 struct qla_hw_data *ha = vha->hw;
1806 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) {
1807 ql_log(ql_log_warn, vha, 0x70d8,
1808 "Speed setting not supported \n");
1812 rval = kstrtol(buf, 10, &type);
1816 if (type == 40 || type == 80 || type == 160 ||
1818 ql_dbg(ql_dbg_user, vha, 0x70d9,
1819 "Setting will be affected after a loss of sync\n");
1821 mode = QLA_SET_DATA_RATE_NOLR;
1824 oldspeed = ha->set_data_rate;
1828 ha->set_data_rate = PORT_SPEED_AUTO;
1831 ha->set_data_rate = PORT_SPEED_4GB;
1834 ha->set_data_rate = PORT_SPEED_8GB;
1837 ha->set_data_rate = PORT_SPEED_16GB;
1840 ha->set_data_rate = PORT_SPEED_32GB;
1843 ql_log(ql_log_warn, vha, 0x1199,
1844 "Unrecognized speed setting:%lx. Setting Autoneg\n",
1846 ha->set_data_rate = PORT_SPEED_AUTO;
1849 if (qla2x00_chip_is_down(vha) || (oldspeed == ha->set_data_rate))
1852 ql_log(ql_log_info, vha, 0x70da,
1853 "Setting speed to %lx Gbps \n", type);
1855 rval = qla2x00_set_data_rate(vha, mode);
1856 if (rval != QLA_SUCCESS)
1862 static const struct {
1865 } port_speed_str[] = {
1866 { PORT_SPEED_4GB, "4" },
1867 { PORT_SPEED_8GB, "8" },
1868 { PORT_SPEED_16GB, "16" },
1869 { PORT_SPEED_32GB, "32" },
1870 { PORT_SPEED_64GB, "64" },
1871 { PORT_SPEED_10GB, "10" },
1875 qla2x00_port_speed_show(struct device *dev, struct device_attribute *attr,
1878 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1879 struct qla_hw_data *ha = vha->hw;
1882 char *speed = "Unknown";
1884 rval = qla2x00_get_data_rate(vha);
1885 if (rval != QLA_SUCCESS) {
1886 ql_log(ql_log_warn, vha, 0x70db,
1887 "Unable to get port speed rval:%zd\n", rval);
1891 for (i = 0; i < ARRAY_SIZE(port_speed_str); i++) {
1892 if (port_speed_str[i].rate != ha->link_data_rate)
1894 speed = port_speed_str[i].str;
1898 return scnprintf(buf, PAGE_SIZE, "%s\n", speed);
1904 qlini_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1906 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1909 len += scnprintf(buf + len, PAGE_SIZE-len,
1910 "Supported options: enabled | disabled | dual | exclusive\n");
1913 len += scnprintf(buf + len, PAGE_SIZE-len, "Current selection: ");
1915 switch (vha->qlini_mode) {
1916 case QLA2XXX_INI_MODE_EXCLUSIVE:
1917 len += scnprintf(buf + len, PAGE_SIZE-len,
1918 QLA2XXX_INI_MODE_STR_EXCLUSIVE);
1920 case QLA2XXX_INI_MODE_DISABLED:
1921 len += scnprintf(buf + len, PAGE_SIZE-len,
1922 QLA2XXX_INI_MODE_STR_DISABLED);
1924 case QLA2XXX_INI_MODE_ENABLED:
1925 len += scnprintf(buf + len, PAGE_SIZE-len,
1926 QLA2XXX_INI_MODE_STR_ENABLED);
1928 case QLA2XXX_INI_MODE_DUAL:
1929 len += scnprintf(buf + len, PAGE_SIZE-len,
1930 QLA2XXX_INI_MODE_STR_DUAL);
1933 len += scnprintf(buf + len, PAGE_SIZE-len, "\n");
1938 static char *mode_to_str[] = {
1945 #define NEED_EXCH_OFFLOAD(_exchg) ((_exchg) > FW_DEF_EXCHANGES_CNT)
1946 static void qla_set_ini_mode(scsi_qla_host_t *vha, int op)
1951 MODE_CHANGE_NO_ACTION,
1952 TARGET_STILL_ACTIVE,
1954 int action = NO_ACTION;
1956 u8 eo_toggle = 0; /* exchange offload flipped */
1958 switch (vha->qlini_mode) {
1959 case QLA2XXX_INI_MODE_DISABLED:
1961 case QLA2XXX_INI_MODE_DISABLED:
1962 if (qla_tgt_mode_enabled(vha)) {
1963 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1964 vha->hw->flags.exchoffld_enabled)
1966 if (((vha->ql2xexchoffld !=
1967 vha->u_ql2xexchoffld) &&
1968 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1971 * The number of exchange to be offload
1972 * was tweaked or offload option was
1975 action = MODE_CHANGE_ACCEPT;
1977 action = MODE_CHANGE_NO_ACTION;
1980 action = MODE_CHANGE_NO_ACTION;
1983 case QLA2XXX_INI_MODE_EXCLUSIVE:
1984 if (qla_tgt_mode_enabled(vha)) {
1985 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1986 vha->hw->flags.exchoffld_enabled)
1988 if (((vha->ql2xexchoffld !=
1989 vha->u_ql2xexchoffld) &&
1990 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1993 * The number of exchange to be offload
1994 * was tweaked or offload option was
1997 action = MODE_CHANGE_ACCEPT;
1999 action = MODE_CHANGE_NO_ACTION;
2002 action = MODE_CHANGE_ACCEPT;
2005 case QLA2XXX_INI_MODE_DUAL:
2006 action = MODE_CHANGE_ACCEPT;
2007 /* active_mode is target only, reset it to dual */
2008 if (qla_tgt_mode_enabled(vha)) {
2010 action = MODE_CHANGE_ACCEPT;
2012 action = MODE_CHANGE_NO_ACTION;
2016 case QLA2XXX_INI_MODE_ENABLED:
2017 if (qla_tgt_mode_enabled(vha))
2018 action = TARGET_STILL_ACTIVE;
2020 action = MODE_CHANGE_ACCEPT;
2027 case QLA2XXX_INI_MODE_EXCLUSIVE:
2029 case QLA2XXX_INI_MODE_EXCLUSIVE:
2030 if (qla_tgt_mode_enabled(vha)) {
2031 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2032 vha->hw->flags.exchoffld_enabled)
2034 if (((vha->ql2xexchoffld !=
2035 vha->u_ql2xexchoffld) &&
2036 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2039 * The number of exchange to be offload
2040 * was tweaked or offload option was
2043 action = MODE_CHANGE_ACCEPT;
2051 case QLA2XXX_INI_MODE_DISABLED:
2052 if (qla_tgt_mode_enabled(vha)) {
2053 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2054 vha->hw->flags.exchoffld_enabled)
2056 if (((vha->ql2xexchoffld !=
2057 vha->u_ql2xexchoffld) &&
2058 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2060 action = MODE_CHANGE_ACCEPT;
2062 action = MODE_CHANGE_NO_ACTION;
2064 action = MODE_CHANGE_NO_ACTION;
2067 case QLA2XXX_INI_MODE_DUAL: /* exclusive -> dual */
2068 if (qla_tgt_mode_enabled(vha)) {
2069 action = MODE_CHANGE_ACCEPT;
2072 action = MODE_CHANGE_ACCEPT;
2075 case QLA2XXX_INI_MODE_ENABLED:
2076 if (qla_tgt_mode_enabled(vha))
2077 action = TARGET_STILL_ACTIVE;
2079 if (vha->hw->flags.fw_started)
2080 action = MODE_CHANGE_NO_ACTION;
2082 action = MODE_CHANGE_ACCEPT;
2088 case QLA2XXX_INI_MODE_ENABLED:
2090 case QLA2XXX_INI_MODE_ENABLED:
2091 if (NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg) !=
2092 vha->hw->flags.exchoffld_enabled)
2094 if (((vha->ql2xiniexchg != vha->u_ql2xiniexchg) &&
2095 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg)) ||
2097 action = MODE_CHANGE_ACCEPT;
2101 case QLA2XXX_INI_MODE_DUAL:
2102 case QLA2XXX_INI_MODE_DISABLED:
2103 action = MODE_CHANGE_ACCEPT;
2106 action = MODE_CHANGE_NO_ACTION;
2111 case QLA2XXX_INI_MODE_DUAL:
2113 case QLA2XXX_INI_MODE_DUAL:
2114 if (qla_tgt_mode_enabled(vha) ||
2115 qla_dual_mode_enabled(vha)) {
2116 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2117 vha->u_ql2xiniexchg) !=
2118 vha->hw->flags.exchoffld_enabled)
2121 if ((((vha->ql2xexchoffld +
2122 vha->ql2xiniexchg) !=
2123 (vha->u_ql2xiniexchg +
2124 vha->u_ql2xexchoffld)) &&
2125 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2126 vha->u_ql2xexchoffld)) || eo_toggle)
2127 action = MODE_CHANGE_ACCEPT;
2131 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2132 vha->u_ql2xiniexchg) !=
2133 vha->hw->flags.exchoffld_enabled)
2136 if ((((vha->ql2xexchoffld + vha->ql2xiniexchg)
2137 != (vha->u_ql2xiniexchg +
2138 vha->u_ql2xexchoffld)) &&
2139 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2140 vha->u_ql2xexchoffld)) || eo_toggle)
2141 action = MODE_CHANGE_NO_ACTION;
2147 case QLA2XXX_INI_MODE_DISABLED:
2148 if (qla_tgt_mode_enabled(vha) ||
2149 qla_dual_mode_enabled(vha)) {
2150 /* turning off initiator mode */
2152 action = MODE_CHANGE_ACCEPT;
2154 action = MODE_CHANGE_NO_ACTION;
2158 case QLA2XXX_INI_MODE_EXCLUSIVE:
2159 if (qla_tgt_mode_enabled(vha) ||
2160 qla_dual_mode_enabled(vha)) {
2162 action = MODE_CHANGE_ACCEPT;
2164 action = MODE_CHANGE_ACCEPT;
2168 case QLA2XXX_INI_MODE_ENABLED:
2169 if (qla_tgt_mode_enabled(vha) ||
2170 qla_dual_mode_enabled(vha)) {
2171 action = TARGET_STILL_ACTIVE;
2173 action = MODE_CHANGE_ACCEPT;
2180 case MODE_CHANGE_ACCEPT:
2181 ql_log(ql_log_warn, vha, 0xffff,
2182 "Mode change accepted. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2183 mode_to_str[vha->qlini_mode], mode_to_str[op],
2184 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2185 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2187 vha->qlini_mode = op;
2188 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2189 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2192 vha->flags.online = 1;
2193 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2196 case MODE_CHANGE_NO_ACTION:
2197 ql_log(ql_log_warn, vha, 0xffff,
2198 "Mode is set. No action taken. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2199 mode_to_str[vha->qlini_mode], mode_to_str[op],
2200 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2201 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2202 vha->qlini_mode = op;
2203 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2204 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2207 case TARGET_STILL_ACTIVE:
2208 ql_log(ql_log_warn, vha, 0xffff,
2209 "Target Mode is active. Unable to change Mode.\n");
2214 ql_log(ql_log_warn, vha, 0xffff,
2215 "Mode unchange. No action taken. %d|%d pct %d|%d.\n",
2216 vha->qlini_mode, op,
2217 vha->ql2xexchoffld, vha->u_ql2xexchoffld);
2223 qlini_mode_store(struct device *dev, struct device_attribute *attr,
2224 const char *buf, size_t count)
2226 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2232 if (strncasecmp(QLA2XXX_INI_MODE_STR_EXCLUSIVE, buf,
2233 strlen(QLA2XXX_INI_MODE_STR_EXCLUSIVE)) == 0)
2234 ini = QLA2XXX_INI_MODE_EXCLUSIVE;
2235 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DISABLED, buf,
2236 strlen(QLA2XXX_INI_MODE_STR_DISABLED)) == 0)
2237 ini = QLA2XXX_INI_MODE_DISABLED;
2238 else if (strncasecmp(QLA2XXX_INI_MODE_STR_ENABLED, buf,
2239 strlen(QLA2XXX_INI_MODE_STR_ENABLED)) == 0)
2240 ini = QLA2XXX_INI_MODE_ENABLED;
2241 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DUAL, buf,
2242 strlen(QLA2XXX_INI_MODE_STR_DUAL)) == 0)
2243 ini = QLA2XXX_INI_MODE_DUAL;
2247 qla_set_ini_mode(vha, ini);
2252 ql2xexchoffld_show(struct device *dev, struct device_attribute *attr,
2255 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2258 len += scnprintf(buf + len, PAGE_SIZE-len,
2259 "target exchange: new %d : current: %d\n\n",
2260 vha->u_ql2xexchoffld, vha->ql2xexchoffld);
2262 len += scnprintf(buf + len, PAGE_SIZE-len,
2263 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2270 ql2xexchoffld_store(struct device *dev, struct device_attribute *attr,
2271 const char *buf, size_t count)
2273 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2276 if (sscanf(buf, "%d", &val) != 1)
2279 if (val > FW_MAX_EXCHANGES_CNT)
2280 val = FW_MAX_EXCHANGES_CNT;
2284 vha->u_ql2xexchoffld = val;
2289 ql2xiniexchg_show(struct device *dev, struct device_attribute *attr,
2292 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2295 len += scnprintf(buf + len, PAGE_SIZE-len,
2296 "target exchange: new %d : current: %d\n\n",
2297 vha->u_ql2xiniexchg, vha->ql2xiniexchg);
2299 len += scnprintf(buf + len, PAGE_SIZE-len,
2300 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2307 ql2xiniexchg_store(struct device *dev, struct device_attribute *attr,
2308 const char *buf, size_t count)
2310 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2313 if (sscanf(buf, "%d", &val) != 1)
2316 if (val > FW_MAX_EXCHANGES_CNT)
2317 val = FW_MAX_EXCHANGES_CNT;
2321 vha->u_ql2xiniexchg = val;
2326 qla2x00_dif_bundle_statistics_show(struct device *dev,
2327 struct device_attribute *attr, char *buf)
2329 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2330 struct qla_hw_data *ha = vha->hw;
2332 return scnprintf(buf, PAGE_SIZE,
2333 "cross=%llu read=%llu write=%llu kalloc=%llu dma_alloc=%llu unusable=%u\n",
2334 ha->dif_bundle_crossed_pages, ha->dif_bundle_reads,
2335 ha->dif_bundle_writes, ha->dif_bundle_kallocs,
2336 ha->dif_bundle_dma_allocs, ha->pool.unusable.count);
2340 qla2x00_fw_attr_show(struct device *dev,
2341 struct device_attribute *attr, char *buf)
2343 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2344 struct qla_hw_data *ha = vha->hw;
2346 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2347 return scnprintf(buf, PAGE_SIZE, "\n");
2349 return scnprintf(buf, PAGE_SIZE, "%llx\n",
2350 (uint64_t)ha->fw_attributes_ext[1] << 48 |
2351 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2352 (uint64_t)ha->fw_attributes_h << 16 |
2353 (uint64_t)ha->fw_attributes);
2357 qla2x00_port_no_show(struct device *dev, struct device_attribute *attr,
2360 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2362 return scnprintf(buf, PAGE_SIZE, "%u\n", vha->hw->port_no);
2366 qla2x00_dport_diagnostics_show(struct device *dev,
2367 struct device_attribute *attr, char *buf)
2369 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2371 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
2372 !IS_QLA28XX(vha->hw))
2373 return scnprintf(buf, PAGE_SIZE, "\n");
2375 if (!*vha->dport_data)
2376 return scnprintf(buf, PAGE_SIZE, "\n");
2378 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
2379 vha->dport_data[0], vha->dport_data[1],
2380 vha->dport_data[2], vha->dport_data[3]);
2382 static DEVICE_ATTR(dport_diagnostics, 0444,
2383 qla2x00_dport_diagnostics_show, NULL);
2385 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_driver_version_show, NULL);
2386 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
2387 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
2388 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
2389 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
2390 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
2391 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
2392 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
2393 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
2394 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
2395 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
2396 qla2x00_zio_timer_store);
2397 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
2398 qla2x00_beacon_store);
2399 static DEVICE_ATTR(beacon_config, 0644, qla2x00_beacon_config_show,
2400 qla2x00_beacon_config_store);
2401 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
2402 qla2x00_optrom_bios_version_show, NULL);
2403 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
2404 qla2x00_optrom_efi_version_show, NULL);
2405 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
2406 qla2x00_optrom_fcode_version_show, NULL);
2407 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
2409 static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
2410 qla2x00_optrom_gold_fw_version_show, NULL);
2411 static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
2413 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
2415 static DEVICE_ATTR(serdes_version, 0444, qla2x00_serdes_version_show, NULL);
2416 static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
2417 static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
2418 static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
2420 static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
2421 static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
2422 qla2x00_vn_port_mac_address_show, NULL);
2423 static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
2424 static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
2425 static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
2426 static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
2427 static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
2428 static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
2429 static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
2430 qla2x00_allow_cna_fw_dump_show,
2431 qla2x00_allow_cna_fw_dump_store);
2432 static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
2433 static DEVICE_ATTR(min_supported_speed, 0444,
2434 qla2x00_min_supported_speed_show, NULL);
2435 static DEVICE_ATTR(max_supported_speed, 0444,
2436 qla2x00_max_supported_speed_show, NULL);
2437 static DEVICE_ATTR(zio_threshold, 0644,
2438 qla_zio_threshold_show,
2439 qla_zio_threshold_store);
2440 static DEVICE_ATTR_RW(qlini_mode);
2441 static DEVICE_ATTR_RW(ql2xexchoffld);
2442 static DEVICE_ATTR_RW(ql2xiniexchg);
2443 static DEVICE_ATTR(dif_bundle_statistics, 0444,
2444 qla2x00_dif_bundle_statistics_show, NULL);
2445 static DEVICE_ATTR(port_speed, 0644, qla2x00_port_speed_show,
2446 qla2x00_port_speed_store);
2447 static DEVICE_ATTR(port_no, 0444, qla2x00_port_no_show, NULL);
2448 static DEVICE_ATTR(fw_attr, 0444, qla2x00_fw_attr_show, NULL);
2451 struct device_attribute *qla2x00_host_attrs[] = {
2452 &dev_attr_driver_version,
2453 &dev_attr_fw_version,
2454 &dev_attr_serial_num,
2457 &dev_attr_model_name,
2458 &dev_attr_model_desc,
2460 &dev_attr_link_state,
2462 &dev_attr_zio_timer,
2464 &dev_attr_beacon_config,
2465 &dev_attr_optrom_bios_version,
2466 &dev_attr_optrom_efi_version,
2467 &dev_attr_optrom_fcode_version,
2468 &dev_attr_optrom_fw_version,
2469 &dev_attr_84xx_fw_version,
2470 &dev_attr_total_isp_aborts,
2471 &dev_attr_serdes_version,
2472 &dev_attr_mpi_version,
2473 &dev_attr_phy_version,
2474 &dev_attr_flash_block_size,
2476 &dev_attr_vn_port_mac_address,
2477 &dev_attr_fabric_param,
2479 &dev_attr_optrom_gold_fw_version,
2480 &dev_attr_thermal_temp,
2481 &dev_attr_diag_requests,
2482 &dev_attr_diag_megabytes,
2483 &dev_attr_fw_dump_size,
2484 &dev_attr_allow_cna_fw_dump,
2485 &dev_attr_pep_version,
2486 &dev_attr_min_supported_speed,
2487 &dev_attr_max_supported_speed,
2488 &dev_attr_zio_threshold,
2489 &dev_attr_dif_bundle_statistics,
2490 &dev_attr_port_speed,
2493 &dev_attr_dport_diagnostics,
2494 NULL, /* reserve for qlini_mode */
2495 NULL, /* reserve for ql2xiniexchg */
2496 NULL, /* reserve for ql2xexchoffld */
2500 void qla_insert_tgt_attrs(void)
2502 struct device_attribute **attr;
2504 /* advance to empty slot */
2505 for (attr = &qla2x00_host_attrs[0]; *attr; ++attr)
2508 *attr = &dev_attr_qlini_mode;
2510 *attr = &dev_attr_ql2xiniexchg;
2512 *attr = &dev_attr_ql2xexchoffld;
2515 /* Host attributes. */
2518 qla2x00_get_host_port_id(struct Scsi_Host *shost)
2520 scsi_qla_host_t *vha = shost_priv(shost);
2522 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
2523 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
2527 qla2x00_get_host_speed(struct Scsi_Host *shost)
2529 scsi_qla_host_t *vha = shost_priv(shost);
2532 if (IS_QLAFX00(vha->hw)) {
2533 qlafx00_get_host_speed(shost);
2537 switch (vha->hw->link_data_rate) {
2538 case PORT_SPEED_1GB:
2539 speed = FC_PORTSPEED_1GBIT;
2541 case PORT_SPEED_2GB:
2542 speed = FC_PORTSPEED_2GBIT;
2544 case PORT_SPEED_4GB:
2545 speed = FC_PORTSPEED_4GBIT;
2547 case PORT_SPEED_8GB:
2548 speed = FC_PORTSPEED_8GBIT;
2550 case PORT_SPEED_10GB:
2551 speed = FC_PORTSPEED_10GBIT;
2553 case PORT_SPEED_16GB:
2554 speed = FC_PORTSPEED_16GBIT;
2556 case PORT_SPEED_32GB:
2557 speed = FC_PORTSPEED_32GBIT;
2559 case PORT_SPEED_64GB:
2560 speed = FC_PORTSPEED_64GBIT;
2563 speed = FC_PORTSPEED_UNKNOWN;
2567 fc_host_speed(shost) = speed;
2571 qla2x00_get_host_port_type(struct Scsi_Host *shost)
2573 scsi_qla_host_t *vha = shost_priv(shost);
2577 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2580 switch (vha->hw->current_topology) {
2582 port_type = FC_PORTTYPE_LPORT;
2585 port_type = FC_PORTTYPE_NLPORT;
2588 port_type = FC_PORTTYPE_PTP;
2591 port_type = FC_PORTTYPE_NPORT;
2594 port_type = FC_PORTTYPE_UNKNOWN;
2598 fc_host_port_type(shost) = port_type;
2602 qla2x00_get_starget_node_name(struct scsi_target *starget)
2604 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2605 scsi_qla_host_t *vha = shost_priv(host);
2609 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2610 if (fcport->rport &&
2611 starget->id == fcport->rport->scsi_target_id) {
2612 node_name = wwn_to_u64(fcport->node_name);
2617 fc_starget_node_name(starget) = node_name;
2621 qla2x00_get_starget_port_name(struct scsi_target *starget)
2623 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2624 scsi_qla_host_t *vha = shost_priv(host);
2628 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2629 if (fcport->rport &&
2630 starget->id == fcport->rport->scsi_target_id) {
2631 port_name = wwn_to_u64(fcport->port_name);
2636 fc_starget_port_name(starget) = port_name;
2640 qla2x00_get_starget_port_id(struct scsi_target *starget)
2642 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2643 scsi_qla_host_t *vha = shost_priv(host);
2645 uint32_t port_id = ~0U;
2647 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2648 if (fcport->rport &&
2649 starget->id == fcport->rport->scsi_target_id) {
2650 port_id = fcport->d_id.b.domain << 16 |
2651 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2656 fc_starget_port_id(starget) = port_id;
2660 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2662 rport->dev_loss_tmo = timeout ? timeout : 1;
2666 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
2668 struct Scsi_Host *host = rport_to_shost(rport);
2669 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2670 unsigned long flags;
2675 /* Now that the rport has been deleted, set the fcport state to
2677 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
2680 * Transport has effectively 'deleted' the rport, clear
2681 * all local references.
2683 spin_lock_irqsave(host->host_lock, flags);
2684 fcport->rport = fcport->drport = NULL;
2685 *((fc_port_t **)rport->dd_data) = NULL;
2686 spin_unlock_irqrestore(host->host_lock, flags);
2688 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2691 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2692 /* Will wait for wind down of adapter */
2693 ql_dbg(ql_dbg_aer, fcport->vha, 0x900c,
2694 "%s pci offline detected (id %06x)\n", __func__,
2696 qla_pci_set_eeh_busy(fcport->vha);
2697 qla2x00_eh_wait_for_pending_commands(fcport->vha, fcport->d_id.b24,
2704 qla2x00_terminate_rport_io(struct fc_rport *rport)
2706 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2707 scsi_qla_host_t *vha;
2712 if (test_bit(UNLOADING, &fcport->vha->dpc_flags))
2715 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2719 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2720 /* Will wait for wind down of adapter */
2721 ql_dbg(ql_dbg_aer, fcport->vha, 0x900b,
2722 "%s pci offline detected (id %06x)\n", __func__,
2724 qla_pci_set_eeh_busy(vha);
2725 qla2x00_eh_wait_for_pending_commands(fcport->vha, fcport->d_id.b24,
2730 * At this point all fcport's software-states are cleared. Perform any
2731 * final cleanup of firmware resources (PCBs and XCBs).
2733 if (fcport->loop_id != FC_NO_LOOP_ID) {
2734 if (IS_FWI2_CAPABLE(fcport->vha->hw))
2735 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
2736 fcport->loop_id, fcport->d_id.b.domain,
2737 fcport->d_id.b.area, fcport->d_id.b.al_pa);
2739 qla2x00_port_logout(fcport->vha, fcport);
2742 /* check for any straggling io left behind */
2743 if (qla2x00_eh_wait_for_pending_commands(fcport->vha, fcport->d_id.b24, 0, WAIT_TARGET)) {
2744 ql_log(ql_log_warn, vha, 0x300b,
2745 "IO not return. Resetting. \n");
2746 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2747 qla2xxx_wake_dpc(vha);
2748 qla2x00_wait_for_chip_reset(vha);
2753 qla2x00_issue_lip(struct Scsi_Host *shost)
2755 scsi_qla_host_t *vha = shost_priv(shost);
2757 if (IS_QLAFX00(vha->hw))
2760 qla2x00_loop_reset(vha);
2764 static struct fc_host_statistics *
2765 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
2767 scsi_qla_host_t *vha = shost_priv(shost);
2768 struct qla_hw_data *ha = vha->hw;
2769 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2771 struct link_statistics *stats;
2772 dma_addr_t stats_dma;
2773 struct fc_host_statistics *p = &vha->fc_host_stat;
2774 struct qla_qpair *qpair;
2776 u64 ib = 0, ob = 0, ir = 0, or = 0;
2778 memset(p, -1, sizeof(*p));
2780 if (IS_QLAFX00(vha->hw))
2783 if (test_bit(UNLOADING, &vha->dpc_flags))
2786 if (unlikely(pci_channel_offline(ha->pdev)))
2789 if (qla2x00_chip_is_down(vha))
2792 stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2795 ql_log(ql_log_warn, vha, 0x707d,
2796 "Failed to allocate memory for stats.\n");
2800 rval = QLA_FUNCTION_FAILED;
2801 if (IS_FWI2_CAPABLE(ha)) {
2802 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, 0);
2803 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
2805 /* Must be in a 'READY' state for statistics retrieval. */
2806 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
2810 if (rval != QLA_SUCCESS)
2814 for (i = 0; i < vha->hw->max_qpairs; i++) {
2815 qpair = vha->hw->queue_pair_map[i];
2818 ir += qpair->counters.input_requests;
2819 or += qpair->counters.output_requests;
2820 ib += qpair->counters.input_bytes;
2821 ob += qpair->counters.output_bytes;
2823 ir += ha->base_qpair->counters.input_requests;
2824 or += ha->base_qpair->counters.output_requests;
2825 ib += ha->base_qpair->counters.input_bytes;
2826 ob += ha->base_qpair->counters.output_bytes;
2828 ir += vha->qla_stats.input_requests;
2829 or += vha->qla_stats.output_requests;
2830 ib += vha->qla_stats.input_bytes;
2831 ob += vha->qla_stats.output_bytes;
2834 p->link_failure_count = le32_to_cpu(stats->link_fail_cnt);
2835 p->loss_of_sync_count = le32_to_cpu(stats->loss_sync_cnt);
2836 p->loss_of_signal_count = le32_to_cpu(stats->loss_sig_cnt);
2837 p->prim_seq_protocol_err_count = le32_to_cpu(stats->prim_seq_err_cnt);
2838 p->invalid_tx_word_count = le32_to_cpu(stats->inval_xmit_word_cnt);
2839 p->invalid_crc_count = le32_to_cpu(stats->inval_crc_cnt);
2840 if (IS_FWI2_CAPABLE(ha)) {
2841 p->lip_count = le32_to_cpu(stats->lip_cnt);
2842 p->tx_frames = le32_to_cpu(stats->tx_frames);
2843 p->rx_frames = le32_to_cpu(stats->rx_frames);
2844 p->dumped_frames = le32_to_cpu(stats->discarded_frames);
2845 p->nos_count = le32_to_cpu(stats->nos_rcvd);
2847 le32_to_cpu(stats->dropped_frames) +
2848 le32_to_cpu(stats->discarded_frames);
2849 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
2850 p->rx_words = le64_to_cpu(stats->fpm_recv_word_cnt);
2851 p->tx_words = le64_to_cpu(stats->fpm_xmit_word_cnt);
2853 p->rx_words = ib >> 2;
2854 p->tx_words = ob >> 2;
2858 p->fcp_control_requests = vha->qla_stats.control_requests;
2859 p->fcp_input_requests = ir;
2860 p->fcp_output_requests = or;
2861 p->fcp_input_megabytes = ib >> 20;
2862 p->fcp_output_megabytes = ob >> 20;
2863 p->seconds_since_last_reset =
2864 get_jiffies_64() - vha->qla_stats.jiffies_at_last_reset;
2865 do_div(p->seconds_since_last_reset, HZ);
2868 dma_free_coherent(&ha->pdev->dev, sizeof(struct link_statistics),
2875 qla2x00_reset_host_stats(struct Scsi_Host *shost)
2877 scsi_qla_host_t *vha = shost_priv(shost);
2878 struct qla_hw_data *ha = vha->hw;
2879 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2880 struct link_statistics *stats;
2881 dma_addr_t stats_dma;
2883 struct qla_qpair *qpair;
2885 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2886 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2887 for (i = 0; i < vha->hw->max_qpairs; i++) {
2888 qpair = vha->hw->queue_pair_map[i];
2891 memset(&qpair->counters, 0, sizeof(qpair->counters));
2893 memset(&ha->base_qpair->counters, 0, sizeof(qpair->counters));
2895 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2897 if (IS_FWI2_CAPABLE(ha)) {
2900 stats = dma_alloc_coherent(&ha->pdev->dev,
2901 sizeof(*stats), &stats_dma, GFP_KERNEL);
2903 ql_log(ql_log_warn, vha, 0x70d7,
2904 "Failed to allocate memory for stats.\n");
2908 /* reset firmware statistics */
2909 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, BIT_0);
2910 if (rval != QLA_SUCCESS)
2911 ql_log(ql_log_warn, vha, 0x70de,
2912 "Resetting ISP statistics failed: rval = %d\n",
2915 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2921 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
2923 scsi_qla_host_t *vha = shost_priv(shost);
2925 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost),
2926 sizeof(fc_host_symbolic_name(shost)));
2930 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
2932 scsi_qla_host_t *vha = shost_priv(shost);
2934 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
2938 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
2940 scsi_qla_host_t *vha = shost_priv(shost);
2941 static const uint8_t node_name[WWN_SIZE] = {
2942 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
2944 u64 fabric_name = wwn_to_u64(node_name);
2946 if (vha->device_flags & SWITCH_FOUND)
2947 fabric_name = wwn_to_u64(vha->fabric_node_name);
2949 fc_host_fabric_name(shost) = fabric_name;
2953 qla2x00_get_host_port_state(struct Scsi_Host *shost)
2955 scsi_qla_host_t *vha = shost_priv(shost);
2956 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
2958 if (!base_vha->flags.online) {
2959 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2963 switch (atomic_read(&base_vha->loop_state)) {
2965 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2968 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
2969 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2971 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2974 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2977 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2980 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2986 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
2990 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
2991 scsi_qla_host_t *vha = NULL;
2992 struct qla_hw_data *ha = base_vha->hw;
2994 struct req_que *req = ha->req_q_map[0];
2995 struct qla_qpair *qpair;
2997 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
2999 ql_log(ql_log_warn, vha, 0x707e,
3000 "Vport sanity check failed, status %x\n", ret);
3004 vha = qla24xx_create_vhost(fc_vport);
3006 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
3007 return FC_VPORT_FAILED;
3010 atomic_set(&vha->vp_state, VP_OFFLINE);
3011 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
3013 atomic_set(&vha->vp_state, VP_FAILED);
3015 /* ready to create vport */
3016 ql_log(ql_log_info, vha, 0x7080,
3017 "VP entry id %d assigned.\n", vha->vp_idx);
3019 /* initialized vport states */
3020 atomic_set(&vha->loop_state, LOOP_DOWN);
3021 vha->vp_err_state = VP_ERR_PORTDWN;
3022 vha->vp_prev_err_state = VP_ERR_UNKWN;
3023 /* Check if physical ha port is Up */
3024 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
3025 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
3026 /* Don't retry or attempt login of this virtual port */
3027 ql_dbg(ql_dbg_user, vha, 0x7081,
3028 "Vport loop state is not UP.\n");
3029 atomic_set(&vha->loop_state, LOOP_DEAD);
3031 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
3034 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3035 if (ha->fw_attributes & BIT_4) {
3036 int prot = 0, guard;
3038 vha->flags.difdix_supported = 1;
3039 ql_dbg(ql_dbg_user, vha, 0x7082,
3040 "Registered for DIF/DIX type 1 and 3 protection.\n");
3041 scsi_host_set_prot(vha->host,
3042 prot | SHOST_DIF_TYPE1_PROTECTION
3043 | SHOST_DIF_TYPE2_PROTECTION
3044 | SHOST_DIF_TYPE3_PROTECTION
3045 | SHOST_DIX_TYPE1_PROTECTION
3046 | SHOST_DIX_TYPE2_PROTECTION
3047 | SHOST_DIX_TYPE3_PROTECTION);
3049 guard = SHOST_DIX_GUARD_CRC;
3051 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3052 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3053 guard |= SHOST_DIX_GUARD_IP;
3055 scsi_host_set_guard(vha->host, guard);
3057 vha->flags.difdix_supported = 0;
3060 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
3062 ql_dbg(ql_dbg_user, vha, 0x7083,
3063 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
3064 goto vport_create_failed_2;
3067 /* initialize attributes */
3068 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
3069 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3070 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
3071 fc_host_supported_classes(vha->host) =
3072 fc_host_supported_classes(base_vha->host);
3073 fc_host_supported_speeds(vha->host) =
3074 fc_host_supported_speeds(base_vha->host);
3076 qlt_vport_create(vha, ha);
3077 qla24xx_vport_disable(fc_vport, disable);
3079 if (!ql2xmqsupport || !ha->npiv_info)
3082 /* Create a request queue in QoS mode for the vport */
3083 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
3084 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
3085 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
3087 qos = ha->npiv_info[cnt].q_qos;
3093 qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx, true);
3095 ql_log(ql_log_warn, vha, 0x7084,
3096 "Can't create qpair for VP[%d]\n",
3099 ql_dbg(ql_dbg_multiq, vha, 0xc001,
3100 "Queue pair: %d Qos: %d) created for VP[%d]\n",
3101 qpair->id, qos, vha->vp_idx);
3102 ql_dbg(ql_dbg_user, vha, 0x7085,
3103 "Queue Pair: %d Qos: %d) created for VP[%d]\n",
3104 qpair->id, qos, vha->vp_idx);
3114 vport_create_failed_2:
3115 qla24xx_disable_vp(vha);
3116 qla24xx_deallocate_vp_id(vha);
3117 scsi_host_put(vha->host);
3118 return FC_VPORT_FAILED;
3122 qla24xx_vport_delete(struct fc_vport *fc_vport)
3124 scsi_qla_host_t *vha = fc_vport->dd_data;
3125 struct qla_hw_data *ha = vha->hw;
3126 uint16_t id = vha->vp_idx;
3128 set_bit(VPORT_DELETE, &vha->dpc_flags);
3130 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
3131 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
3135 qla24xx_disable_vp(vha);
3136 qla2x00_wait_for_sess_deletion(vha);
3138 qla_nvme_delete(vha);
3139 vha->flags.delete_progress = 1;
3141 qlt_remove_target(ha, vha);
3143 fc_remove_host(vha->host);
3145 scsi_remove_host(vha->host);
3147 /* Allow timer to run to drain queued items, when removing vp */
3148 qla24xx_deallocate_vp_id(vha);
3150 if (vha->timer_active) {
3151 qla2x00_vp_stop_timer(vha);
3152 ql_dbg(ql_dbg_user, vha, 0x7086,
3153 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
3156 qla2x00_free_fcports(vha);
3158 mutex_lock(&ha->vport_lock);
3159 ha->cur_vport_count--;
3160 clear_bit(vha->vp_idx, ha->vp_idx_map);
3161 mutex_unlock(&ha->vport_lock);
3163 dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l,
3170 if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {
3171 if (qla2xxx_delete_qpair(vha, vha->qpair) != QLA_SUCCESS)
3172 ql_log(ql_log_warn, vha, 0x7087,
3173 "Queue Pair delete failed.\n");
3176 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
3177 scsi_host_put(vha->host);
3182 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
3184 scsi_qla_host_t *vha = fc_vport->dd_data;
3187 qla24xx_disable_vp(vha);
3189 qla24xx_enable_vp(vha);
3194 struct fc_function_template qla2xxx_transport_functions = {
3196 .show_host_node_name = 1,
3197 .show_host_port_name = 1,
3198 .show_host_supported_classes = 1,
3199 .show_host_supported_speeds = 1,
3201 .get_host_port_id = qla2x00_get_host_port_id,
3202 .show_host_port_id = 1,
3203 .get_host_speed = qla2x00_get_host_speed,
3204 .show_host_speed = 1,
3205 .get_host_port_type = qla2x00_get_host_port_type,
3206 .show_host_port_type = 1,
3207 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3208 .show_host_symbolic_name = 1,
3209 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3210 .show_host_system_hostname = 1,
3211 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3212 .show_host_fabric_name = 1,
3213 .get_host_port_state = qla2x00_get_host_port_state,
3214 .show_host_port_state = 1,
3216 .dd_fcrport_size = sizeof(struct fc_port *),
3217 .show_rport_supported_classes = 1,
3219 .get_starget_node_name = qla2x00_get_starget_node_name,
3220 .show_starget_node_name = 1,
3221 .get_starget_port_name = qla2x00_get_starget_port_name,
3222 .show_starget_port_name = 1,
3223 .get_starget_port_id = qla2x00_get_starget_port_id,
3224 .show_starget_port_id = 1,
3226 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3227 .show_rport_dev_loss_tmo = 1,
3229 .issue_fc_host_lip = qla2x00_issue_lip,
3230 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3231 .terminate_rport_io = qla2x00_terminate_rport_io,
3232 .get_fc_host_stats = qla2x00_get_fc_host_stats,
3233 .reset_fc_host_stats = qla2x00_reset_host_stats,
3235 .vport_create = qla24xx_vport_create,
3236 .vport_disable = qla24xx_vport_disable,
3237 .vport_delete = qla24xx_vport_delete,
3238 .bsg_request = qla24xx_bsg_request,
3239 .bsg_timeout = qla24xx_bsg_timeout,
3242 struct fc_function_template qla2xxx_transport_vport_functions = {
3244 .show_host_node_name = 1,
3245 .show_host_port_name = 1,
3246 .show_host_supported_classes = 1,
3248 .get_host_port_id = qla2x00_get_host_port_id,
3249 .show_host_port_id = 1,
3250 .get_host_speed = qla2x00_get_host_speed,
3251 .show_host_speed = 1,
3252 .get_host_port_type = qla2x00_get_host_port_type,
3253 .show_host_port_type = 1,
3254 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3255 .show_host_symbolic_name = 1,
3256 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3257 .show_host_system_hostname = 1,
3258 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3259 .show_host_fabric_name = 1,
3260 .get_host_port_state = qla2x00_get_host_port_state,
3261 .show_host_port_state = 1,
3263 .dd_fcrport_size = sizeof(struct fc_port *),
3264 .show_rport_supported_classes = 1,
3266 .get_starget_node_name = qla2x00_get_starget_node_name,
3267 .show_starget_node_name = 1,
3268 .get_starget_port_name = qla2x00_get_starget_port_name,
3269 .show_starget_port_name = 1,
3270 .get_starget_port_id = qla2x00_get_starget_port_id,
3271 .show_starget_port_id = 1,
3273 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3274 .show_rport_dev_loss_tmo = 1,
3276 .issue_fc_host_lip = qla2x00_issue_lip,
3277 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3278 .terminate_rport_io = qla2x00_terminate_rport_io,
3279 .get_fc_host_stats = qla2x00_get_fc_host_stats,
3280 .reset_fc_host_stats = qla2x00_reset_host_stats,
3282 .bsg_request = qla24xx_bsg_request,
3283 .bsg_timeout = qla24xx_bsg_timeout,
3287 qla2x00_get_host_supported_speeds(scsi_qla_host_t *vha, uint speeds)
3289 uint supported_speeds = FC_PORTSPEED_UNKNOWN;
3291 if (speeds & FDMI_PORT_SPEED_64GB)
3292 supported_speeds |= FC_PORTSPEED_64GBIT;
3293 if (speeds & FDMI_PORT_SPEED_32GB)
3294 supported_speeds |= FC_PORTSPEED_32GBIT;
3295 if (speeds & FDMI_PORT_SPEED_16GB)
3296 supported_speeds |= FC_PORTSPEED_16GBIT;
3297 if (speeds & FDMI_PORT_SPEED_8GB)
3298 supported_speeds |= FC_PORTSPEED_8GBIT;
3299 if (speeds & FDMI_PORT_SPEED_4GB)
3300 supported_speeds |= FC_PORTSPEED_4GBIT;
3301 if (speeds & FDMI_PORT_SPEED_2GB)
3302 supported_speeds |= FC_PORTSPEED_2GBIT;
3303 if (speeds & FDMI_PORT_SPEED_1GB)
3304 supported_speeds |= FC_PORTSPEED_1GBIT;
3306 return supported_speeds;
3310 qla2x00_init_host_attr(scsi_qla_host_t *vha)
3312 struct qla_hw_data *ha = vha->hw;
3313 u32 speeds = 0, fdmi_speed = 0;
3315 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
3316 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3317 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
3318 fc_host_supported_classes(vha->host) = ha->base_qpair->enable_class_2 ?
3319 (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
3320 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
3321 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
3323 fdmi_speed = qla25xx_fdmi_port_speed_capability(ha);
3324 speeds = qla2x00_get_host_supported_speeds(vha, fdmi_speed);
3326 fc_host_supported_speeds(vha->host) = speeds;