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 if (vha->hw->flags.port_isolated) {
714 ql_log(ql_log_info, vha, 0x706e,
715 "Port is isolated, returning.\n");
719 scsi_block_requests(vha->host);
720 if (IS_QLA82XX(ha)) {
721 ha->flags.isp82xx_no_md_cap = 1;
722 qla82xx_idc_lock(ha);
723 qla82xx_set_reset_owner(vha);
724 qla82xx_idc_unlock(ha);
725 } else if (IS_QLA8044(ha)) {
726 qla8044_idc_lock(ha);
727 idc_control = qla8044_rd_reg(ha,
728 QLA8044_IDC_DRV_CTRL);
729 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
730 (idc_control | GRACEFUL_RESET_BIT1));
731 qla82xx_set_reset_owner(vha);
732 qla8044_idc_unlock(ha);
734 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
735 qla2xxx_wake_dpc(vha);
737 qla2x00_wait_for_chip_reset(vha);
738 scsi_unblock_requests(vha->host);
741 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
742 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
745 ql_log(ql_log_info, vha, 0x706f,
746 "Issuing MPI reset.\n");
748 if (IS_QLA83XX(ha)) {
749 uint32_t idc_control;
751 qla83xx_idc_lock(vha, 0);
752 __qla83xx_get_idc_control(vha, &idc_control);
753 idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
754 __qla83xx_set_idc_control(vha, idc_control);
755 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
756 QLA8XXX_DEV_NEED_RESET);
757 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
758 qla83xx_idc_unlock(vha, 0);
761 /* Make sure FC side is not in reset */
762 WARN_ON_ONCE(qla2x00_wait_for_hba_online(vha) !=
765 /* Issue MPI reset */
766 scsi_block_requests(vha->host);
767 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
768 ql_log(ql_log_warn, vha, 0x7070,
769 "MPI reset failed.\n");
770 scsi_unblock_requests(vha->host);
775 if (!IS_P3P_TYPE(ha) || vha != base_vha) {
776 ql_log(ql_log_info, vha, 0x7071,
777 "FCoE ctx reset not supported.\n");
781 ql_log(ql_log_info, vha, 0x7072,
782 "Issuing FCoE ctx reset.\n");
783 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
784 qla2xxx_wake_dpc(vha);
785 qla2x00_wait_for_fcoe_ctx_reset(vha);
790 ql_log(ql_log_info, vha, 0x70bc,
791 "Disabling Reset by IDC control\n");
792 qla83xx_idc_lock(vha, 0);
793 __qla83xx_get_idc_control(vha, &idc_control);
794 idc_control |= QLA83XX_IDC_RESET_DISABLED;
795 __qla83xx_set_idc_control(vha, idc_control);
796 qla83xx_idc_unlock(vha, 0);
801 ql_log(ql_log_info, vha, 0x70bd,
802 "Enabling Reset by IDC control\n");
803 qla83xx_idc_lock(vha, 0);
804 __qla83xx_get_idc_control(vha, &idc_control);
805 idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
806 __qla83xx_set_idc_control(vha, idc_control);
807 qla83xx_idc_unlock(vha, 0);
810 ql_dbg(ql_dbg_user, vha, 0x70e0,
811 "Updating cache versions without reset ");
813 tmp_data = vmalloc(256);
815 ql_log(ql_log_warn, vha, 0x70e1,
816 "Unable to allocate memory for VPD information update.\n");
819 ha->isp_ops->get_flash_version(vha, tmp_data);
826 static struct bin_attribute sysfs_reset_attr = {
832 .write = qla2x00_sysfs_write_reset,
836 qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
837 struct bin_attribute *bin_attr,
838 char *buf, loff_t off, size_t count)
840 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
841 struct device, kobj)));
845 if (!capable(CAP_SYS_ADMIN))
848 if (unlikely(pci_channel_offline(vha->hw->pdev)))
851 if (qla2x00_chip_is_down(vha))
854 type = simple_strtol(buf, NULL, 10);
856 did.b.domain = (type & 0x00ff0000) >> 16;
857 did.b.area = (type & 0x0000ff00) >> 8;
858 did.b.al_pa = (type & 0x000000ff);
860 ql_log(ql_log_info, vha, 0xd04d, "portid=%02x%02x%02x done\n",
861 did.b.domain, did.b.area, did.b.al_pa);
863 ql_log(ql_log_info, vha, 0x70e4, "%s: %d\n", __func__, type);
865 qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, did);
869 static struct bin_attribute sysfs_issue_logo_attr = {
871 .name = "issue_logo",
875 .write = qla2x00_issue_logo,
879 qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
880 struct bin_attribute *bin_attr,
881 char *buf, loff_t off, size_t count)
883 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
884 struct device, kobj)));
885 struct qla_hw_data *ha = vha->hw;
887 uint16_t actual_size;
889 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
892 if (unlikely(pci_channel_offline(ha->pdev)))
894 mutex_lock(&vha->hw->optrom_mutex);
895 if (qla2x00_chip_is_down(vha)) {
896 mutex_unlock(&vha->hw->optrom_mutex);
903 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
904 &ha->xgmac_data_dma, GFP_KERNEL);
905 if (!ha->xgmac_data) {
906 mutex_unlock(&vha->hw->optrom_mutex);
907 ql_log(ql_log_warn, vha, 0x7076,
908 "Unable to allocate memory for XGMAC read-data.\n");
914 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
916 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
917 XGMAC_DATA_SIZE, &actual_size);
919 mutex_unlock(&vha->hw->optrom_mutex);
920 if (rval != QLA_SUCCESS) {
921 ql_log(ql_log_warn, vha, 0x7077,
922 "Unable to read XGMAC data (%x).\n", rval);
926 count = actual_size > count ? count : actual_size;
927 memcpy(buf, ha->xgmac_data, count);
932 static struct bin_attribute sysfs_xgmac_stats_attr = {
934 .name = "xgmac_stats",
938 .read = qla2x00_sysfs_read_xgmac_stats,
942 qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
943 struct bin_attribute *bin_attr,
944 char *buf, loff_t off, size_t count)
946 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
947 struct device, kobj)));
948 struct qla_hw_data *ha = vha->hw;
951 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
956 mutex_lock(&vha->hw->optrom_mutex);
957 if (qla2x00_chip_is_down(vha)) {
958 mutex_unlock(&vha->hw->optrom_mutex);
962 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
963 &ha->dcbx_tlv_dma, GFP_KERNEL);
965 mutex_unlock(&vha->hw->optrom_mutex);
966 ql_log(ql_log_warn, vha, 0x7078,
967 "Unable to allocate memory for DCBX TLV read-data.\n");
972 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
974 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
977 mutex_unlock(&vha->hw->optrom_mutex);
979 if (rval != QLA_SUCCESS) {
980 ql_log(ql_log_warn, vha, 0x7079,
981 "Unable to read DCBX TLV (%x).\n", rval);
985 memcpy(buf, ha->dcbx_tlv, count);
990 static struct bin_attribute sysfs_dcbx_tlv_attr = {
996 .read = qla2x00_sysfs_read_dcbx_tlv,
999 static struct sysfs_entry {
1001 struct bin_attribute *attr;
1003 } bin_file_entries[] = {
1004 { "fw_dump", &sysfs_fw_dump_attr, },
1005 { "nvram", &sysfs_nvram_attr, },
1006 { "optrom", &sysfs_optrom_attr, },
1007 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
1008 { "vpd", &sysfs_vpd_attr, 1 },
1009 { "sfp", &sysfs_sfp_attr, 1 },
1010 { "reset", &sysfs_reset_attr, },
1011 { "issue_logo", &sysfs_issue_logo_attr, },
1012 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
1013 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
1018 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
1020 struct Scsi_Host *host = vha->host;
1021 struct sysfs_entry *iter;
1024 for (iter = bin_file_entries; iter->name; iter++) {
1025 if (iter->type && !IS_FWI2_CAPABLE(vha->hw))
1027 if (iter->type == 2 && !IS_QLA25XX(vha->hw))
1029 if (iter->type == 3 && !(IS_CNA_CAPABLE(vha->hw)))
1032 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
1035 ql_log(ql_log_warn, vha, 0x00f3,
1036 "Unable to create sysfs %s binary attribute (%d).\n",
1039 ql_dbg(ql_dbg_init, vha, 0x00f4,
1040 "Successfully created sysfs %s binary attribute.\n",
1046 qla2x00_free_sysfs_attr(scsi_qla_host_t *vha, bool stop_beacon)
1048 struct Scsi_Host *host = vha->host;
1049 struct sysfs_entry *iter;
1050 struct qla_hw_data *ha = vha->hw;
1052 for (iter = bin_file_entries; iter->name; iter++) {
1053 if (iter->type && !IS_FWI2_CAPABLE(ha))
1055 if (iter->type == 2 && !IS_QLA25XX(ha))
1057 if (iter->type == 3 && !(IS_CNA_CAPABLE(ha)))
1060 sysfs_remove_bin_file(&host->shost_gendev.kobj,
1064 if (stop_beacon && ha->beacon_blink_led == 1)
1065 ha->isp_ops->beacon_off(vha);
1068 /* Scsi_Host attributes. */
1071 qla2x00_driver_version_show(struct device *dev,
1072 struct device_attribute *attr, char *buf)
1074 return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
1078 qla2x00_fw_version_show(struct device *dev,
1079 struct device_attribute *attr, char *buf)
1081 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1082 struct qla_hw_data *ha = vha->hw;
1085 return scnprintf(buf, PAGE_SIZE, "%s\n",
1086 ha->isp_ops->fw_version_str(vha, fw_str, sizeof(fw_str)));
1090 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
1093 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1094 struct qla_hw_data *ha = vha->hw;
1097 if (IS_QLAFX00(vha->hw)) {
1098 return scnprintf(buf, PAGE_SIZE, "%s\n",
1099 vha->hw->mr.serial_num);
1100 } else if (IS_FWI2_CAPABLE(ha)) {
1101 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE - 1);
1102 return strlen(strcat(buf, "\n"));
1105 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1106 return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
1111 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
1114 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1116 return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
1120 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
1123 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1124 struct qla_hw_data *ha = vha->hw;
1126 if (IS_QLAFX00(vha->hw))
1127 return scnprintf(buf, PAGE_SIZE, "%s\n",
1128 vha->hw->mr.hw_version);
1130 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
1131 ha->product_id[0], ha->product_id[1], ha->product_id[2],
1136 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
1139 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1141 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
1145 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1148 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1150 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
1154 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1157 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1160 return scnprintf(buf, PAGE_SIZE, "%s\n",
1161 vha->hw->isp_ops->pci_info_str(vha, pci_info,
1166 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1169 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1170 struct qla_hw_data *ha = vha->hw;
1173 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
1174 atomic_read(&vha->loop_state) == LOOP_DEAD ||
1175 vha->device_flags & DFLG_NO_CABLE)
1176 len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
1177 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1178 qla2x00_chip_is_down(vha))
1179 len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1181 len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
1183 switch (ha->current_topology) {
1185 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1188 len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1191 len += scnprintf(buf + len, PAGE_SIZE-len,
1192 "N_Port to N_Port\n");
1195 len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1198 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1206 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1209 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1212 switch (vha->hw->zio_mode) {
1213 case QLA_ZIO_MODE_6:
1214 len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1216 case QLA_ZIO_DISABLED:
1217 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1224 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1225 const char *buf, size_t count)
1227 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1228 struct qla_hw_data *ha = vha->hw;
1232 if (!IS_ZIO_SUPPORTED(ha))
1235 if (sscanf(buf, "%d", &val) != 1)
1239 zio_mode = QLA_ZIO_MODE_6;
1241 zio_mode = QLA_ZIO_DISABLED;
1243 /* Update per-hba values and queue a reset. */
1244 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1245 ha->zio_mode = zio_mode;
1246 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1252 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1255 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1257 return scnprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
1261 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1262 const char *buf, size_t count)
1264 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1268 if (sscanf(buf, "%d", &val) != 1)
1270 if (val > 25500 || val < 100)
1273 zio_timer = (uint16_t)(val / 100);
1274 vha->hw->zio_timer = zio_timer;
1280 qla_zio_threshold_show(struct device *dev, struct device_attribute *attr,
1283 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1285 return scnprintf(buf, PAGE_SIZE, "%d exchanges\n",
1286 vha->hw->last_zio_threshold);
1290 qla_zio_threshold_store(struct device *dev, struct device_attribute *attr,
1291 const char *buf, size_t count)
1293 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1296 if (vha->hw->zio_mode != QLA_ZIO_MODE_6)
1298 if (sscanf(buf, "%d", &val) != 1)
1300 if (val < 0 || val > 256)
1303 atomic_set(&vha->hw->zio_threshold, val);
1308 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1311 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1314 if (vha->hw->beacon_blink_led)
1315 len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1317 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1322 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1323 const char *buf, size_t count)
1325 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1326 struct qla_hw_data *ha = vha->hw;
1330 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1333 if (sscanf(buf, "%d", &val) != 1)
1336 mutex_lock(&vha->hw->optrom_mutex);
1337 if (qla2x00_chip_is_down(vha)) {
1338 mutex_unlock(&vha->hw->optrom_mutex);
1339 ql_log(ql_log_warn, vha, 0x707a,
1340 "Abort ISP active -- ignoring beacon request.\n");
1345 rval = ha->isp_ops->beacon_on(vha);
1347 rval = ha->isp_ops->beacon_off(vha);
1349 if (rval != QLA_SUCCESS)
1352 mutex_unlock(&vha->hw->optrom_mutex);
1358 qla2x00_beacon_config_show(struct device *dev, struct device_attribute *attr,
1361 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1362 struct qla_hw_data *ha = vha->hw;
1363 uint16_t led[3] = { 0 };
1365 if (!IS_QLA2031(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1368 if (ql26xx_led_config(vha, 0, led))
1369 return scnprintf(buf, PAGE_SIZE, "\n");
1371 return scnprintf(buf, PAGE_SIZE, "%#04hx %#04hx %#04hx\n",
1372 led[0], led[1], led[2]);
1376 qla2x00_beacon_config_store(struct device *dev, struct device_attribute *attr,
1377 const char *buf, size_t count)
1379 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1380 struct qla_hw_data *ha = vha->hw;
1381 uint16_t options = BIT_0;
1382 uint16_t led[3] = { 0 };
1386 if (!IS_QLA2031(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1389 n = sscanf(buf, "%hx %hx %hx %hx", word+0, word+1, word+2, word+3);
1392 options |= BIT_3|BIT_2|BIT_1;
1402 /* check led index */
1424 if (ql26xx_led_config(vha, options, led))
1431 qla2x00_optrom_bios_version_show(struct device *dev,
1432 struct device_attribute *attr, char *buf)
1434 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1435 struct qla_hw_data *ha = vha->hw;
1437 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1438 ha->bios_revision[0]);
1442 qla2x00_optrom_efi_version_show(struct device *dev,
1443 struct device_attribute *attr, char *buf)
1445 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1446 struct qla_hw_data *ha = vha->hw;
1448 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1449 ha->efi_revision[0]);
1453 qla2x00_optrom_fcode_version_show(struct device *dev,
1454 struct device_attribute *attr, char *buf)
1456 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1457 struct qla_hw_data *ha = vha->hw;
1459 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1460 ha->fcode_revision[0]);
1464 qla2x00_optrom_fw_version_show(struct device *dev,
1465 struct device_attribute *attr, char *buf)
1467 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1468 struct qla_hw_data *ha = vha->hw;
1470 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1471 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1472 ha->fw_revision[3]);
1476 qla2x00_optrom_gold_fw_version_show(struct device *dev,
1477 struct device_attribute *attr, char *buf)
1479 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1480 struct qla_hw_data *ha = vha->hw;
1482 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1483 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1484 return scnprintf(buf, PAGE_SIZE, "\n");
1486 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1487 ha->gold_fw_version[0], ha->gold_fw_version[1],
1488 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1492 qla2x00_total_isp_aborts_show(struct device *dev,
1493 struct device_attribute *attr, char *buf)
1495 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1497 return scnprintf(buf, PAGE_SIZE, "%d\n",
1498 vha->qla_stats.total_isp_aborts);
1502 qla24xx_84xx_fw_version_show(struct device *dev,
1503 struct device_attribute *attr, char *buf)
1505 int rval = QLA_SUCCESS;
1506 uint16_t status[2] = { 0 };
1507 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1508 struct qla_hw_data *ha = vha->hw;
1510 if (!IS_QLA84XX(ha))
1511 return scnprintf(buf, PAGE_SIZE, "\n");
1513 if (!ha->cs84xx->op_fw_version) {
1514 rval = qla84xx_verify_chip(vha, status);
1516 if (!rval && !status[0])
1517 return scnprintf(buf, PAGE_SIZE, "%u\n",
1518 (uint32_t)ha->cs84xx->op_fw_version);
1521 return scnprintf(buf, PAGE_SIZE, "\n");
1525 qla2x00_serdes_version_show(struct device *dev, struct device_attribute *attr,
1528 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1529 struct qla_hw_data *ha = vha->hw;
1531 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1532 return scnprintf(buf, PAGE_SIZE, "\n");
1534 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1535 ha->serdes_version[0], ha->serdes_version[1],
1536 ha->serdes_version[2]);
1540 qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1543 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1544 struct qla_hw_data *ha = vha->hw;
1546 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
1547 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1548 return scnprintf(buf, PAGE_SIZE, "\n");
1550 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
1551 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
1552 ha->mpi_capabilities);
1556 qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1559 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1560 struct qla_hw_data *ha = vha->hw;
1562 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
1563 return scnprintf(buf, PAGE_SIZE, "\n");
1565 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1566 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
1570 qla2x00_flash_block_size_show(struct device *dev,
1571 struct device_attribute *attr, char *buf)
1573 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1574 struct qla_hw_data *ha = vha->hw;
1576 return scnprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1580 qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1583 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1585 if (!IS_CNA_CAPABLE(vha->hw))
1586 return scnprintf(buf, PAGE_SIZE, "\n");
1588 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1592 qla2x00_vn_port_mac_address_show(struct device *dev,
1593 struct device_attribute *attr, char *buf)
1595 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1597 if (!IS_CNA_CAPABLE(vha->hw))
1598 return scnprintf(buf, PAGE_SIZE, "\n");
1600 return scnprintf(buf, PAGE_SIZE, "%pMR\n", vha->fcoe_vn_port_mac);
1604 qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1607 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1609 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1613 qla2x00_thermal_temp_show(struct device *dev,
1614 struct device_attribute *attr, char *buf)
1616 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1620 mutex_lock(&vha->hw->optrom_mutex);
1621 if (qla2x00_chip_is_down(vha)) {
1622 mutex_unlock(&vha->hw->optrom_mutex);
1623 ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
1627 if (vha->hw->flags.eeh_busy) {
1628 mutex_unlock(&vha->hw->optrom_mutex);
1629 ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
1633 rc = qla2x00_get_thermal_temp(vha, &temp);
1634 mutex_unlock(&vha->hw->optrom_mutex);
1635 if (rc == QLA_SUCCESS)
1636 return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
1639 return scnprintf(buf, PAGE_SIZE, "\n");
1643 qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1646 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1647 int rval = QLA_FUNCTION_FAILED;
1651 if (IS_QLAFX00(vha->hw)) {
1652 pstate = qlafx00_fw_state_show(dev, attr, buf);
1653 return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
1656 mutex_lock(&vha->hw->optrom_mutex);
1657 if (qla2x00_chip_is_down(vha)) {
1658 mutex_unlock(&vha->hw->optrom_mutex);
1659 ql_log(ql_log_warn, vha, 0x707c,
1660 "ISP reset active.\n");
1662 } else if (vha->hw->flags.eeh_busy) {
1663 mutex_unlock(&vha->hw->optrom_mutex);
1667 rval = qla2x00_get_firmware_state(vha, state);
1668 mutex_unlock(&vha->hw->optrom_mutex);
1670 if (rval != QLA_SUCCESS) {
1671 memset(state, -1, sizeof(state));
1672 rval = qla2x00_get_firmware_state(vha, state);
1675 return scnprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1676 state[0], state[1], state[2], state[3], state[4], state[5]);
1680 qla2x00_diag_requests_show(struct device *dev,
1681 struct device_attribute *attr, char *buf)
1683 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1685 if (!IS_BIDI_CAPABLE(vha->hw))
1686 return scnprintf(buf, PAGE_SIZE, "\n");
1688 return scnprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
1692 qla2x00_diag_megabytes_show(struct device *dev,
1693 struct device_attribute *attr, char *buf)
1695 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1697 if (!IS_BIDI_CAPABLE(vha->hw))
1698 return scnprintf(buf, PAGE_SIZE, "\n");
1700 return scnprintf(buf, PAGE_SIZE, "%llu\n",
1701 vha->bidi_stats.transfer_bytes >> 20);
1705 qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
1708 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1709 struct qla_hw_data *ha = vha->hw;
1714 else if (IS_P3P_TYPE(ha))
1715 size = ha->md_template_size + ha->md_dump_size;
1717 size = ha->fw_dump_len;
1719 return scnprintf(buf, PAGE_SIZE, "%d\n", size);
1723 qla2x00_allow_cna_fw_dump_show(struct device *dev,
1724 struct device_attribute *attr, char *buf)
1726 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1728 if (!IS_P3P_TYPE(vha->hw))
1729 return scnprintf(buf, PAGE_SIZE, "\n");
1731 return scnprintf(buf, PAGE_SIZE, "%s\n",
1732 vha->hw->allow_cna_fw_dump ? "true" : "false");
1736 qla2x00_allow_cna_fw_dump_store(struct device *dev,
1737 struct device_attribute *attr, const char *buf, size_t count)
1739 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1742 if (!IS_P3P_TYPE(vha->hw))
1745 if (sscanf(buf, "%d", &val) != 1)
1748 vha->hw->allow_cna_fw_dump = val != 0;
1754 qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
1757 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1758 struct qla_hw_data *ha = vha->hw;
1760 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1761 return scnprintf(buf, PAGE_SIZE, "\n");
1763 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1764 ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
1768 qla2x00_min_supported_speed_show(struct device *dev,
1769 struct device_attribute *attr, char *buf)
1771 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1772 struct qla_hw_data *ha = vha->hw;
1774 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1775 return scnprintf(buf, PAGE_SIZE, "\n");
1777 return scnprintf(buf, PAGE_SIZE, "%s\n",
1778 ha->min_supported_speed == 6 ? "64Gps" :
1779 ha->min_supported_speed == 5 ? "32Gps" :
1780 ha->min_supported_speed == 4 ? "16Gps" :
1781 ha->min_supported_speed == 3 ? "8Gps" :
1782 ha->min_supported_speed == 2 ? "4Gps" :
1783 ha->min_supported_speed != 0 ? "unknown" : "");
1787 qla2x00_max_supported_speed_show(struct device *dev,
1788 struct device_attribute *attr, char *buf)
1790 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1791 struct qla_hw_data *ha = vha->hw;
1793 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1794 return scnprintf(buf, PAGE_SIZE, "\n");
1796 return scnprintf(buf, PAGE_SIZE, "%s\n",
1797 ha->max_supported_speed == 2 ? "64Gps" :
1798 ha->max_supported_speed == 1 ? "32Gps" :
1799 ha->max_supported_speed == 0 ? "16Gps" : "unknown");
1803 qla2x00_port_speed_store(struct device *dev, struct device_attribute *attr,
1804 const char *buf, size_t count)
1806 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1809 int mode = QLA_SET_DATA_RATE_LR;
1810 struct qla_hw_data *ha = vha->hw;
1812 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) {
1813 ql_log(ql_log_warn, vha, 0x70d8,
1814 "Speed setting not supported \n");
1818 rval = kstrtol(buf, 10, &type);
1822 if (type == 40 || type == 80 || type == 160 ||
1824 ql_dbg(ql_dbg_user, vha, 0x70d9,
1825 "Setting will be affected after a loss of sync\n");
1827 mode = QLA_SET_DATA_RATE_NOLR;
1830 oldspeed = ha->set_data_rate;
1834 ha->set_data_rate = PORT_SPEED_AUTO;
1837 ha->set_data_rate = PORT_SPEED_4GB;
1840 ha->set_data_rate = PORT_SPEED_8GB;
1843 ha->set_data_rate = PORT_SPEED_16GB;
1846 ha->set_data_rate = PORT_SPEED_32GB;
1849 ql_log(ql_log_warn, vha, 0x1199,
1850 "Unrecognized speed setting:%lx. Setting Autoneg\n",
1852 ha->set_data_rate = PORT_SPEED_AUTO;
1855 if (qla2x00_chip_is_down(vha) || (oldspeed == ha->set_data_rate))
1858 ql_log(ql_log_info, vha, 0x70da,
1859 "Setting speed to %lx Gbps \n", type);
1861 rval = qla2x00_set_data_rate(vha, mode);
1862 if (rval != QLA_SUCCESS)
1868 static const struct {
1871 } port_speed_str[] = {
1872 { PORT_SPEED_4GB, "4" },
1873 { PORT_SPEED_8GB, "8" },
1874 { PORT_SPEED_16GB, "16" },
1875 { PORT_SPEED_32GB, "32" },
1876 { PORT_SPEED_64GB, "64" },
1877 { PORT_SPEED_10GB, "10" },
1881 qla2x00_port_speed_show(struct device *dev, struct device_attribute *attr,
1884 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1885 struct qla_hw_data *ha = vha->hw;
1888 char *speed = "Unknown";
1890 rval = qla2x00_get_data_rate(vha);
1891 if (rval != QLA_SUCCESS) {
1892 ql_log(ql_log_warn, vha, 0x70db,
1893 "Unable to get port speed rval:%zd\n", rval);
1897 for (i = 0; i < ARRAY_SIZE(port_speed_str); i++) {
1898 if (port_speed_str[i].rate != ha->link_data_rate)
1900 speed = port_speed_str[i].str;
1904 return scnprintf(buf, PAGE_SIZE, "%s\n", speed);
1908 qla2x00_mpi_pause_store(struct device *dev,
1909 struct device_attribute *attr, const char *buf, size_t count)
1911 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1914 if (sscanf(buf, "%d", &rval) != 1)
1917 ql_log(ql_log_warn, vha, 0x7089, "Pausing MPI...\n");
1919 rval = qla83xx_wr_reg(vha, 0x002012d4, 0x30000001);
1921 if (rval != QLA_SUCCESS) {
1922 ql_log(ql_log_warn, vha, 0x708a, "Unable to pause MPI.\n");
1929 static DEVICE_ATTR(mpi_pause, S_IWUSR, NULL, qla2x00_mpi_pause_store);
1934 qlini_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1936 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1939 len += scnprintf(buf + len, PAGE_SIZE-len,
1940 "Supported options: enabled | disabled | dual | exclusive\n");
1943 len += scnprintf(buf + len, PAGE_SIZE-len, "Current selection: ");
1945 switch (vha->qlini_mode) {
1946 case QLA2XXX_INI_MODE_EXCLUSIVE:
1947 len += scnprintf(buf + len, PAGE_SIZE-len,
1948 QLA2XXX_INI_MODE_STR_EXCLUSIVE);
1950 case QLA2XXX_INI_MODE_DISABLED:
1951 len += scnprintf(buf + len, PAGE_SIZE-len,
1952 QLA2XXX_INI_MODE_STR_DISABLED);
1954 case QLA2XXX_INI_MODE_ENABLED:
1955 len += scnprintf(buf + len, PAGE_SIZE-len,
1956 QLA2XXX_INI_MODE_STR_ENABLED);
1958 case QLA2XXX_INI_MODE_DUAL:
1959 len += scnprintf(buf + len, PAGE_SIZE-len,
1960 QLA2XXX_INI_MODE_STR_DUAL);
1963 len += scnprintf(buf + len, PAGE_SIZE-len, "\n");
1968 static char *mode_to_str[] = {
1975 #define NEED_EXCH_OFFLOAD(_exchg) ((_exchg) > FW_DEF_EXCHANGES_CNT)
1976 static void qla_set_ini_mode(scsi_qla_host_t *vha, int op)
1981 MODE_CHANGE_NO_ACTION,
1982 TARGET_STILL_ACTIVE,
1984 int action = NO_ACTION;
1986 u8 eo_toggle = 0; /* exchange offload flipped */
1988 switch (vha->qlini_mode) {
1989 case QLA2XXX_INI_MODE_DISABLED:
1991 case QLA2XXX_INI_MODE_DISABLED:
1992 if (qla_tgt_mode_enabled(vha)) {
1993 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1994 vha->hw->flags.exchoffld_enabled)
1996 if (((vha->ql2xexchoffld !=
1997 vha->u_ql2xexchoffld) &&
1998 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2001 * The number of exchange to be offload
2002 * was tweaked or offload option was
2005 action = MODE_CHANGE_ACCEPT;
2007 action = MODE_CHANGE_NO_ACTION;
2010 action = MODE_CHANGE_NO_ACTION;
2013 case QLA2XXX_INI_MODE_EXCLUSIVE:
2014 if (qla_tgt_mode_enabled(vha)) {
2015 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2016 vha->hw->flags.exchoffld_enabled)
2018 if (((vha->ql2xexchoffld !=
2019 vha->u_ql2xexchoffld) &&
2020 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2023 * The number of exchange to be offload
2024 * was tweaked or offload option was
2027 action = MODE_CHANGE_ACCEPT;
2029 action = MODE_CHANGE_NO_ACTION;
2032 action = MODE_CHANGE_ACCEPT;
2035 case QLA2XXX_INI_MODE_DUAL:
2036 action = MODE_CHANGE_ACCEPT;
2037 /* active_mode is target only, reset it to dual */
2038 if (qla_tgt_mode_enabled(vha)) {
2040 action = MODE_CHANGE_ACCEPT;
2042 action = MODE_CHANGE_NO_ACTION;
2046 case QLA2XXX_INI_MODE_ENABLED:
2047 if (qla_tgt_mode_enabled(vha))
2048 action = TARGET_STILL_ACTIVE;
2050 action = MODE_CHANGE_ACCEPT;
2057 case QLA2XXX_INI_MODE_EXCLUSIVE:
2059 case QLA2XXX_INI_MODE_EXCLUSIVE:
2060 if (qla_tgt_mode_enabled(vha)) {
2061 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2062 vha->hw->flags.exchoffld_enabled)
2064 if (((vha->ql2xexchoffld !=
2065 vha->u_ql2xexchoffld) &&
2066 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2069 * The number of exchange to be offload
2070 * was tweaked or offload option was
2073 action = MODE_CHANGE_ACCEPT;
2081 case QLA2XXX_INI_MODE_DISABLED:
2082 if (qla_tgt_mode_enabled(vha)) {
2083 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2084 vha->hw->flags.exchoffld_enabled)
2086 if (((vha->ql2xexchoffld !=
2087 vha->u_ql2xexchoffld) &&
2088 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2090 action = MODE_CHANGE_ACCEPT;
2092 action = MODE_CHANGE_NO_ACTION;
2094 action = MODE_CHANGE_NO_ACTION;
2097 case QLA2XXX_INI_MODE_DUAL: /* exclusive -> dual */
2098 if (qla_tgt_mode_enabled(vha)) {
2099 action = MODE_CHANGE_ACCEPT;
2102 action = MODE_CHANGE_ACCEPT;
2105 case QLA2XXX_INI_MODE_ENABLED:
2106 if (qla_tgt_mode_enabled(vha))
2107 action = TARGET_STILL_ACTIVE;
2109 if (vha->hw->flags.fw_started)
2110 action = MODE_CHANGE_NO_ACTION;
2112 action = MODE_CHANGE_ACCEPT;
2118 case QLA2XXX_INI_MODE_ENABLED:
2120 case QLA2XXX_INI_MODE_ENABLED:
2121 if (NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg) !=
2122 vha->hw->flags.exchoffld_enabled)
2124 if (((vha->ql2xiniexchg != vha->u_ql2xiniexchg) &&
2125 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg)) ||
2127 action = MODE_CHANGE_ACCEPT;
2131 case QLA2XXX_INI_MODE_DUAL:
2132 case QLA2XXX_INI_MODE_DISABLED:
2133 action = MODE_CHANGE_ACCEPT;
2136 action = MODE_CHANGE_NO_ACTION;
2141 case QLA2XXX_INI_MODE_DUAL:
2143 case QLA2XXX_INI_MODE_DUAL:
2144 if (qla_tgt_mode_enabled(vha) ||
2145 qla_dual_mode_enabled(vha)) {
2146 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2147 vha->u_ql2xiniexchg) !=
2148 vha->hw->flags.exchoffld_enabled)
2151 if ((((vha->ql2xexchoffld +
2152 vha->ql2xiniexchg) !=
2153 (vha->u_ql2xiniexchg +
2154 vha->u_ql2xexchoffld)) &&
2155 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2156 vha->u_ql2xexchoffld)) || eo_toggle)
2157 action = MODE_CHANGE_ACCEPT;
2161 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2162 vha->u_ql2xiniexchg) !=
2163 vha->hw->flags.exchoffld_enabled)
2166 if ((((vha->ql2xexchoffld + vha->ql2xiniexchg)
2167 != (vha->u_ql2xiniexchg +
2168 vha->u_ql2xexchoffld)) &&
2169 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2170 vha->u_ql2xexchoffld)) || eo_toggle)
2171 action = MODE_CHANGE_NO_ACTION;
2177 case QLA2XXX_INI_MODE_DISABLED:
2178 if (qla_tgt_mode_enabled(vha) ||
2179 qla_dual_mode_enabled(vha)) {
2180 /* turning off initiator mode */
2182 action = MODE_CHANGE_ACCEPT;
2184 action = MODE_CHANGE_NO_ACTION;
2188 case QLA2XXX_INI_MODE_EXCLUSIVE:
2189 if (qla_tgt_mode_enabled(vha) ||
2190 qla_dual_mode_enabled(vha)) {
2192 action = MODE_CHANGE_ACCEPT;
2194 action = MODE_CHANGE_ACCEPT;
2198 case QLA2XXX_INI_MODE_ENABLED:
2199 if (qla_tgt_mode_enabled(vha) ||
2200 qla_dual_mode_enabled(vha)) {
2201 action = TARGET_STILL_ACTIVE;
2203 action = MODE_CHANGE_ACCEPT;
2210 case MODE_CHANGE_ACCEPT:
2211 ql_log(ql_log_warn, vha, 0xffff,
2212 "Mode change accepted. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2213 mode_to_str[vha->qlini_mode], mode_to_str[op],
2214 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2215 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2217 vha->qlini_mode = op;
2218 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2219 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2222 vha->flags.online = 1;
2223 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2226 case MODE_CHANGE_NO_ACTION:
2227 ql_log(ql_log_warn, vha, 0xffff,
2228 "Mode is set. No action taken. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2229 mode_to_str[vha->qlini_mode], mode_to_str[op],
2230 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2231 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2232 vha->qlini_mode = op;
2233 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2234 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2237 case TARGET_STILL_ACTIVE:
2238 ql_log(ql_log_warn, vha, 0xffff,
2239 "Target Mode is active. Unable to change Mode.\n");
2244 ql_log(ql_log_warn, vha, 0xffff,
2245 "Mode unchange. No action taken. %d|%d pct %d|%d.\n",
2246 vha->qlini_mode, op,
2247 vha->ql2xexchoffld, vha->u_ql2xexchoffld);
2253 qlini_mode_store(struct device *dev, struct device_attribute *attr,
2254 const char *buf, size_t count)
2256 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2262 if (strncasecmp(QLA2XXX_INI_MODE_STR_EXCLUSIVE, buf,
2263 strlen(QLA2XXX_INI_MODE_STR_EXCLUSIVE)) == 0)
2264 ini = QLA2XXX_INI_MODE_EXCLUSIVE;
2265 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DISABLED, buf,
2266 strlen(QLA2XXX_INI_MODE_STR_DISABLED)) == 0)
2267 ini = QLA2XXX_INI_MODE_DISABLED;
2268 else if (strncasecmp(QLA2XXX_INI_MODE_STR_ENABLED, buf,
2269 strlen(QLA2XXX_INI_MODE_STR_ENABLED)) == 0)
2270 ini = QLA2XXX_INI_MODE_ENABLED;
2271 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DUAL, buf,
2272 strlen(QLA2XXX_INI_MODE_STR_DUAL)) == 0)
2273 ini = QLA2XXX_INI_MODE_DUAL;
2277 qla_set_ini_mode(vha, ini);
2282 ql2xexchoffld_show(struct device *dev, struct device_attribute *attr,
2285 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2288 len += scnprintf(buf + len, PAGE_SIZE-len,
2289 "target exchange: new %d : current: %d\n\n",
2290 vha->u_ql2xexchoffld, vha->ql2xexchoffld);
2292 len += scnprintf(buf + len, PAGE_SIZE-len,
2293 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2300 ql2xexchoffld_store(struct device *dev, struct device_attribute *attr,
2301 const char *buf, size_t count)
2303 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2306 if (sscanf(buf, "%d", &val) != 1)
2309 if (val > FW_MAX_EXCHANGES_CNT)
2310 val = FW_MAX_EXCHANGES_CNT;
2314 vha->u_ql2xexchoffld = val;
2319 ql2xiniexchg_show(struct device *dev, struct device_attribute *attr,
2322 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2325 len += scnprintf(buf + len, PAGE_SIZE-len,
2326 "target exchange: new %d : current: %d\n\n",
2327 vha->u_ql2xiniexchg, vha->ql2xiniexchg);
2329 len += scnprintf(buf + len, PAGE_SIZE-len,
2330 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2337 ql2xiniexchg_store(struct device *dev, struct device_attribute *attr,
2338 const char *buf, size_t count)
2340 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2343 if (sscanf(buf, "%d", &val) != 1)
2346 if (val > FW_MAX_EXCHANGES_CNT)
2347 val = FW_MAX_EXCHANGES_CNT;
2351 vha->u_ql2xiniexchg = val;
2356 qla2x00_dif_bundle_statistics_show(struct device *dev,
2357 struct device_attribute *attr, char *buf)
2359 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2360 struct qla_hw_data *ha = vha->hw;
2362 return scnprintf(buf, PAGE_SIZE,
2363 "cross=%llu read=%llu write=%llu kalloc=%llu dma_alloc=%llu unusable=%u\n",
2364 ha->dif_bundle_crossed_pages, ha->dif_bundle_reads,
2365 ha->dif_bundle_writes, ha->dif_bundle_kallocs,
2366 ha->dif_bundle_dma_allocs, ha->pool.unusable.count);
2370 qla2x00_fw_attr_show(struct device *dev,
2371 struct device_attribute *attr, char *buf)
2373 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2374 struct qla_hw_data *ha = vha->hw;
2376 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2377 return scnprintf(buf, PAGE_SIZE, "\n");
2379 return scnprintf(buf, PAGE_SIZE, "%llx\n",
2380 (uint64_t)ha->fw_attributes_ext[1] << 48 |
2381 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2382 (uint64_t)ha->fw_attributes_h << 16 |
2383 (uint64_t)ha->fw_attributes);
2387 qla2x00_port_no_show(struct device *dev, struct device_attribute *attr,
2390 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2392 return scnprintf(buf, PAGE_SIZE, "%u\n", vha->hw->port_no);
2396 qla2x00_dport_diagnostics_show(struct device *dev,
2397 struct device_attribute *attr, char *buf)
2399 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2401 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
2402 !IS_QLA28XX(vha->hw))
2403 return scnprintf(buf, PAGE_SIZE, "\n");
2405 if (!*vha->dport_data)
2406 return scnprintf(buf, PAGE_SIZE, "\n");
2408 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
2409 vha->dport_data[0], vha->dport_data[1],
2410 vha->dport_data[2], vha->dport_data[3]);
2412 static DEVICE_ATTR(dport_diagnostics, 0444,
2413 qla2x00_dport_diagnostics_show, NULL);
2415 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_driver_version_show, NULL);
2416 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
2417 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
2418 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
2419 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
2420 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
2421 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
2422 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
2423 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
2424 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
2425 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
2426 qla2x00_zio_timer_store);
2427 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
2428 qla2x00_beacon_store);
2429 static DEVICE_ATTR(beacon_config, 0644, qla2x00_beacon_config_show,
2430 qla2x00_beacon_config_store);
2431 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
2432 qla2x00_optrom_bios_version_show, NULL);
2433 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
2434 qla2x00_optrom_efi_version_show, NULL);
2435 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
2436 qla2x00_optrom_fcode_version_show, NULL);
2437 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
2439 static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
2440 qla2x00_optrom_gold_fw_version_show, NULL);
2441 static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
2443 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
2445 static DEVICE_ATTR(serdes_version, 0444, qla2x00_serdes_version_show, NULL);
2446 static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
2447 static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
2448 static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
2450 static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
2451 static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
2452 qla2x00_vn_port_mac_address_show, NULL);
2453 static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
2454 static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
2455 static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
2456 static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
2457 static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
2458 static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
2459 static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
2460 qla2x00_allow_cna_fw_dump_show,
2461 qla2x00_allow_cna_fw_dump_store);
2462 static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
2463 static DEVICE_ATTR(min_supported_speed, 0444,
2464 qla2x00_min_supported_speed_show, NULL);
2465 static DEVICE_ATTR(max_supported_speed, 0444,
2466 qla2x00_max_supported_speed_show, NULL);
2467 static DEVICE_ATTR(zio_threshold, 0644,
2468 qla_zio_threshold_show,
2469 qla_zio_threshold_store);
2470 static DEVICE_ATTR_RW(qlini_mode);
2471 static DEVICE_ATTR_RW(ql2xexchoffld);
2472 static DEVICE_ATTR_RW(ql2xiniexchg);
2473 static DEVICE_ATTR(dif_bundle_statistics, 0444,
2474 qla2x00_dif_bundle_statistics_show, NULL);
2475 static DEVICE_ATTR(port_speed, 0644, qla2x00_port_speed_show,
2476 qla2x00_port_speed_store);
2477 static DEVICE_ATTR(port_no, 0444, qla2x00_port_no_show, NULL);
2478 static DEVICE_ATTR(fw_attr, 0444, qla2x00_fw_attr_show, NULL);
2479 static DEVICE_ATTR_RO(edif_doorbell);
2482 struct device_attribute *qla2x00_host_attrs[] = {
2483 &dev_attr_driver_version,
2484 &dev_attr_fw_version,
2485 &dev_attr_serial_num,
2488 &dev_attr_model_name,
2489 &dev_attr_model_desc,
2491 &dev_attr_link_state,
2493 &dev_attr_zio_timer,
2495 &dev_attr_beacon_config,
2496 &dev_attr_optrom_bios_version,
2497 &dev_attr_optrom_efi_version,
2498 &dev_attr_optrom_fcode_version,
2499 &dev_attr_optrom_fw_version,
2500 &dev_attr_84xx_fw_version,
2501 &dev_attr_total_isp_aborts,
2502 &dev_attr_serdes_version,
2503 &dev_attr_mpi_version,
2504 &dev_attr_phy_version,
2505 &dev_attr_flash_block_size,
2507 &dev_attr_vn_port_mac_address,
2508 &dev_attr_fabric_param,
2510 &dev_attr_optrom_gold_fw_version,
2511 &dev_attr_thermal_temp,
2512 &dev_attr_diag_requests,
2513 &dev_attr_diag_megabytes,
2514 &dev_attr_fw_dump_size,
2515 &dev_attr_allow_cna_fw_dump,
2516 &dev_attr_pep_version,
2517 &dev_attr_min_supported_speed,
2518 &dev_attr_max_supported_speed,
2519 &dev_attr_zio_threshold,
2520 &dev_attr_dif_bundle_statistics,
2521 &dev_attr_port_speed,
2524 &dev_attr_dport_diagnostics,
2525 &dev_attr_edif_doorbell,
2526 &dev_attr_mpi_pause,
2527 NULL, /* reserve for qlini_mode */
2528 NULL, /* reserve for ql2xiniexchg */
2529 NULL, /* reserve for ql2xexchoffld */
2533 void qla_insert_tgt_attrs(void)
2535 struct device_attribute **attr;
2537 /* advance to empty slot */
2538 for (attr = &qla2x00_host_attrs[0]; *attr; ++attr)
2541 *attr = &dev_attr_qlini_mode;
2543 *attr = &dev_attr_ql2xiniexchg;
2545 *attr = &dev_attr_ql2xexchoffld;
2548 /* Host attributes. */
2551 qla2x00_get_host_port_id(struct Scsi_Host *shost)
2553 scsi_qla_host_t *vha = shost_priv(shost);
2555 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
2556 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
2560 qla2x00_get_host_speed(struct Scsi_Host *shost)
2562 scsi_qla_host_t *vha = shost_priv(shost);
2565 if (IS_QLAFX00(vha->hw)) {
2566 qlafx00_get_host_speed(shost);
2570 switch (vha->hw->link_data_rate) {
2571 case PORT_SPEED_1GB:
2572 speed = FC_PORTSPEED_1GBIT;
2574 case PORT_SPEED_2GB:
2575 speed = FC_PORTSPEED_2GBIT;
2577 case PORT_SPEED_4GB:
2578 speed = FC_PORTSPEED_4GBIT;
2580 case PORT_SPEED_8GB:
2581 speed = FC_PORTSPEED_8GBIT;
2583 case PORT_SPEED_10GB:
2584 speed = FC_PORTSPEED_10GBIT;
2586 case PORT_SPEED_16GB:
2587 speed = FC_PORTSPEED_16GBIT;
2589 case PORT_SPEED_32GB:
2590 speed = FC_PORTSPEED_32GBIT;
2592 case PORT_SPEED_64GB:
2593 speed = FC_PORTSPEED_64GBIT;
2596 speed = FC_PORTSPEED_UNKNOWN;
2600 fc_host_speed(shost) = speed;
2604 qla2x00_get_host_port_type(struct Scsi_Host *shost)
2606 scsi_qla_host_t *vha = shost_priv(shost);
2610 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2613 switch (vha->hw->current_topology) {
2615 port_type = FC_PORTTYPE_LPORT;
2618 port_type = FC_PORTTYPE_NLPORT;
2621 port_type = FC_PORTTYPE_PTP;
2624 port_type = FC_PORTTYPE_NPORT;
2627 port_type = FC_PORTTYPE_UNKNOWN;
2631 fc_host_port_type(shost) = port_type;
2635 qla2x00_get_starget_node_name(struct scsi_target *starget)
2637 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2638 scsi_qla_host_t *vha = shost_priv(host);
2642 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2643 if (fcport->rport &&
2644 starget->id == fcport->rport->scsi_target_id) {
2645 node_name = wwn_to_u64(fcport->node_name);
2650 fc_starget_node_name(starget) = node_name;
2654 qla2x00_get_starget_port_name(struct scsi_target *starget)
2656 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2657 scsi_qla_host_t *vha = shost_priv(host);
2661 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2662 if (fcport->rport &&
2663 starget->id == fcport->rport->scsi_target_id) {
2664 port_name = wwn_to_u64(fcport->port_name);
2669 fc_starget_port_name(starget) = port_name;
2673 qla2x00_get_starget_port_id(struct scsi_target *starget)
2675 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2676 scsi_qla_host_t *vha = shost_priv(host);
2678 uint32_t port_id = ~0U;
2680 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2681 if (fcport->rport &&
2682 starget->id == fcport->rport->scsi_target_id) {
2683 port_id = fcport->d_id.b.domain << 16 |
2684 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2689 fc_starget_port_id(starget) = port_id;
2693 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2695 rport->dev_loss_tmo = timeout ? timeout : 1;
2699 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
2701 struct Scsi_Host *host = rport_to_shost(rport);
2702 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2703 unsigned long flags;
2708 /* Now that the rport has been deleted, set the fcport state to
2710 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
2713 * Transport has effectively 'deleted' the rport, clear
2714 * all local references.
2716 spin_lock_irqsave(host->host_lock, flags);
2717 fcport->rport = fcport->drport = NULL;
2718 *((fc_port_t **)rport->dd_data) = NULL;
2719 spin_unlock_irqrestore(host->host_lock, flags);
2721 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2724 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2725 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2731 qla2x00_terminate_rport_io(struct fc_rport *rport)
2733 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2738 if (test_bit(UNLOADING, &fcport->vha->dpc_flags))
2741 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2744 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2745 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2749 * At this point all fcport's software-states are cleared. Perform any
2750 * final cleanup of firmware resources (PCBs and XCBs).
2752 if (fcport->loop_id != FC_NO_LOOP_ID) {
2753 if (IS_FWI2_CAPABLE(fcport->vha->hw)) {
2754 if (fcport->loop_id != FC_NO_LOOP_ID)
2755 fcport->logout_on_delete = 1;
2757 if (!EDIF_NEGOTIATION_PENDING(fcport)) {
2758 ql_dbg(ql_dbg_disc, fcport->vha, 0x911e,
2759 "%s %d schedule session deletion\n", __func__,
2761 qlt_schedule_sess_for_deletion(fcport);
2764 qla2x00_port_logout(fcport->vha, fcport);
2770 qla2x00_issue_lip(struct Scsi_Host *shost)
2772 scsi_qla_host_t *vha = shost_priv(shost);
2774 if (IS_QLAFX00(vha->hw))
2777 if (vha->hw->flags.port_isolated)
2780 qla2x00_loop_reset(vha);
2784 static struct fc_host_statistics *
2785 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
2787 scsi_qla_host_t *vha = shost_priv(shost);
2788 struct qla_hw_data *ha = vha->hw;
2789 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2791 struct link_statistics *stats;
2792 dma_addr_t stats_dma;
2793 struct fc_host_statistics *p = &vha->fc_host_stat;
2794 struct qla_qpair *qpair;
2796 u64 ib = 0, ob = 0, ir = 0, or = 0;
2798 memset(p, -1, sizeof(*p));
2800 if (IS_QLAFX00(vha->hw))
2803 if (test_bit(UNLOADING, &vha->dpc_flags))
2806 if (unlikely(pci_channel_offline(ha->pdev)))
2809 if (qla2x00_chip_is_down(vha))
2812 stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2815 ql_log(ql_log_warn, vha, 0x707d,
2816 "Failed to allocate memory for stats.\n");
2820 rval = QLA_FUNCTION_FAILED;
2821 if (IS_FWI2_CAPABLE(ha)) {
2822 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, 0);
2823 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
2825 /* Must be in a 'READY' state for statistics retrieval. */
2826 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
2830 if (rval != QLA_SUCCESS)
2834 for (i = 0; i < vha->hw->max_qpairs; i++) {
2835 qpair = vha->hw->queue_pair_map[i];
2838 ir += qpair->counters.input_requests;
2839 or += qpair->counters.output_requests;
2840 ib += qpair->counters.input_bytes;
2841 ob += qpair->counters.output_bytes;
2843 ir += ha->base_qpair->counters.input_requests;
2844 or += ha->base_qpair->counters.output_requests;
2845 ib += ha->base_qpair->counters.input_bytes;
2846 ob += ha->base_qpair->counters.output_bytes;
2848 ir += vha->qla_stats.input_requests;
2849 or += vha->qla_stats.output_requests;
2850 ib += vha->qla_stats.input_bytes;
2851 ob += vha->qla_stats.output_bytes;
2854 p->link_failure_count = le32_to_cpu(stats->link_fail_cnt);
2855 p->loss_of_sync_count = le32_to_cpu(stats->loss_sync_cnt);
2856 p->loss_of_signal_count = le32_to_cpu(stats->loss_sig_cnt);
2857 p->prim_seq_protocol_err_count = le32_to_cpu(stats->prim_seq_err_cnt);
2858 p->invalid_tx_word_count = le32_to_cpu(stats->inval_xmit_word_cnt);
2859 p->invalid_crc_count = le32_to_cpu(stats->inval_crc_cnt);
2860 if (IS_FWI2_CAPABLE(ha)) {
2861 p->lip_count = le32_to_cpu(stats->lip_cnt);
2862 p->tx_frames = le32_to_cpu(stats->tx_frames);
2863 p->rx_frames = le32_to_cpu(stats->rx_frames);
2864 p->dumped_frames = le32_to_cpu(stats->discarded_frames);
2865 p->nos_count = le32_to_cpu(stats->nos_rcvd);
2867 le32_to_cpu(stats->dropped_frames) +
2868 le32_to_cpu(stats->discarded_frames);
2869 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
2870 p->rx_words = le64_to_cpu(stats->fpm_recv_word_cnt);
2871 p->tx_words = le64_to_cpu(stats->fpm_xmit_word_cnt);
2873 p->rx_words = ib >> 2;
2874 p->tx_words = ob >> 2;
2878 p->fcp_control_requests = vha->qla_stats.control_requests;
2879 p->fcp_input_requests = ir;
2880 p->fcp_output_requests = or;
2881 p->fcp_input_megabytes = ib >> 20;
2882 p->fcp_output_megabytes = ob >> 20;
2883 p->seconds_since_last_reset =
2884 get_jiffies_64() - vha->qla_stats.jiffies_at_last_reset;
2885 do_div(p->seconds_since_last_reset, HZ);
2888 dma_free_coherent(&ha->pdev->dev, sizeof(struct link_statistics),
2895 qla2x00_reset_host_stats(struct Scsi_Host *shost)
2897 scsi_qla_host_t *vha = shost_priv(shost);
2898 struct qla_hw_data *ha = vha->hw;
2899 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2900 struct link_statistics *stats;
2901 dma_addr_t stats_dma;
2903 struct qla_qpair *qpair;
2905 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2906 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2907 for (i = 0; i < vha->hw->max_qpairs; i++) {
2908 qpair = vha->hw->queue_pair_map[i];
2911 memset(&qpair->counters, 0, sizeof(qpair->counters));
2913 memset(&ha->base_qpair->counters, 0, sizeof(qpair->counters));
2915 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2917 if (IS_FWI2_CAPABLE(ha)) {
2920 stats = dma_alloc_coherent(&ha->pdev->dev,
2921 sizeof(*stats), &stats_dma, GFP_KERNEL);
2923 ql_log(ql_log_warn, vha, 0x70d7,
2924 "Failed to allocate memory for stats.\n");
2928 /* reset firmware statistics */
2929 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, BIT_0);
2930 if (rval != QLA_SUCCESS)
2931 ql_log(ql_log_warn, vha, 0x70de,
2932 "Resetting ISP statistics failed: rval = %d\n",
2935 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2941 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
2943 scsi_qla_host_t *vha = shost_priv(shost);
2945 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost),
2946 sizeof(fc_host_symbolic_name(shost)));
2950 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
2952 scsi_qla_host_t *vha = shost_priv(shost);
2954 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
2958 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
2960 scsi_qla_host_t *vha = shost_priv(shost);
2961 static const uint8_t node_name[WWN_SIZE] = {
2962 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
2964 u64 fabric_name = wwn_to_u64(node_name);
2966 if (vha->device_flags & SWITCH_FOUND)
2967 fabric_name = wwn_to_u64(vha->fabric_node_name);
2969 fc_host_fabric_name(shost) = fabric_name;
2973 qla2x00_get_host_port_state(struct Scsi_Host *shost)
2975 scsi_qla_host_t *vha = shost_priv(shost);
2976 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
2978 if (!base_vha->flags.online) {
2979 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2983 switch (atomic_read(&base_vha->loop_state)) {
2985 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2988 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
2989 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2991 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2994 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2997 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3000 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3006 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
3010 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
3011 scsi_qla_host_t *vha = NULL;
3012 struct qla_hw_data *ha = base_vha->hw;
3014 struct req_que *req = ha->req_q_map[0];
3015 struct qla_qpair *qpair;
3017 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
3019 ql_log(ql_log_warn, vha, 0x707e,
3020 "Vport sanity check failed, status %x\n", ret);
3024 vha = qla24xx_create_vhost(fc_vport);
3026 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
3027 return FC_VPORT_FAILED;
3030 atomic_set(&vha->vp_state, VP_OFFLINE);
3031 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
3033 atomic_set(&vha->vp_state, VP_FAILED);
3035 /* ready to create vport */
3036 ql_log(ql_log_info, vha, 0x7080,
3037 "VP entry id %d assigned.\n", vha->vp_idx);
3039 /* initialized vport states */
3040 atomic_set(&vha->loop_state, LOOP_DOWN);
3041 vha->vp_err_state = VP_ERR_PORTDWN;
3042 vha->vp_prev_err_state = VP_ERR_UNKWN;
3043 /* Check if physical ha port is Up */
3044 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
3045 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
3046 /* Don't retry or attempt login of this virtual port */
3047 ql_dbg(ql_dbg_user, vha, 0x7081,
3048 "Vport loop state is not UP.\n");
3049 atomic_set(&vha->loop_state, LOOP_DEAD);
3051 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
3054 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3055 if (ha->fw_attributes & BIT_4) {
3056 int prot = 0, guard;
3058 vha->flags.difdix_supported = 1;
3059 ql_dbg(ql_dbg_user, vha, 0x7082,
3060 "Registered for DIF/DIX type 1 and 3 protection.\n");
3061 if (ql2xenabledif == 1)
3062 prot = SHOST_DIX_TYPE0_PROTECTION;
3063 scsi_host_set_prot(vha->host,
3064 prot | SHOST_DIF_TYPE1_PROTECTION
3065 | SHOST_DIF_TYPE2_PROTECTION
3066 | SHOST_DIF_TYPE3_PROTECTION
3067 | SHOST_DIX_TYPE1_PROTECTION
3068 | SHOST_DIX_TYPE2_PROTECTION
3069 | SHOST_DIX_TYPE3_PROTECTION);
3071 guard = SHOST_DIX_GUARD_CRC;
3073 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3074 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3075 guard |= SHOST_DIX_GUARD_IP;
3077 scsi_host_set_guard(vha->host, guard);
3079 vha->flags.difdix_supported = 0;
3082 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
3084 ql_dbg(ql_dbg_user, vha, 0x7083,
3085 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
3086 goto vport_create_failed_2;
3089 /* initialize attributes */
3090 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
3091 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3092 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
3093 fc_host_supported_classes(vha->host) =
3094 fc_host_supported_classes(base_vha->host);
3095 fc_host_supported_speeds(vha->host) =
3096 fc_host_supported_speeds(base_vha->host);
3098 qlt_vport_create(vha, ha);
3099 qla24xx_vport_disable(fc_vport, disable);
3101 if (!ql2xmqsupport || !ha->npiv_info)
3104 /* Create a request queue in QoS mode for the vport */
3105 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
3106 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
3107 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
3109 qos = ha->npiv_info[cnt].q_qos;
3115 qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx, true);
3117 ql_log(ql_log_warn, vha, 0x7084,
3118 "Can't create qpair for VP[%d]\n",
3121 ql_dbg(ql_dbg_multiq, vha, 0xc001,
3122 "Queue pair: %d Qos: %d) created for VP[%d]\n",
3123 qpair->id, qos, vha->vp_idx);
3124 ql_dbg(ql_dbg_user, vha, 0x7085,
3125 "Queue Pair: %d Qos: %d) created for VP[%d]\n",
3126 qpair->id, qos, vha->vp_idx);
3136 vport_create_failed_2:
3137 qla24xx_disable_vp(vha);
3138 qla24xx_deallocate_vp_id(vha);
3139 scsi_host_put(vha->host);
3140 return FC_VPORT_FAILED;
3144 qla24xx_vport_delete(struct fc_vport *fc_vport)
3146 scsi_qla_host_t *vha = fc_vport->dd_data;
3147 struct qla_hw_data *ha = vha->hw;
3148 uint16_t id = vha->vp_idx;
3150 set_bit(VPORT_DELETE, &vha->dpc_flags);
3152 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
3153 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
3157 qla24xx_disable_vp(vha);
3158 qla2x00_wait_for_sess_deletion(vha);
3160 qla_nvme_delete(vha);
3161 qla_enode_stop(vha);
3164 vha->flags.delete_progress = 1;
3166 qlt_remove_target(ha, vha);
3168 fc_remove_host(vha->host);
3170 scsi_remove_host(vha->host);
3172 /* Allow timer to run to drain queued items, when removing vp */
3173 qla24xx_deallocate_vp_id(vha);
3175 if (vha->timer_active) {
3176 qla2x00_vp_stop_timer(vha);
3177 ql_dbg(ql_dbg_user, vha, 0x7086,
3178 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
3181 qla2x00_free_fcports(vha);
3183 mutex_lock(&ha->vport_lock);
3184 ha->cur_vport_count--;
3185 clear_bit(vha->vp_idx, ha->vp_idx_map);
3186 mutex_unlock(&ha->vport_lock);
3188 dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l,
3195 if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {
3196 if (qla2xxx_delete_qpair(vha, vha->qpair) != QLA_SUCCESS)
3197 ql_log(ql_log_warn, vha, 0x7087,
3198 "Queue Pair delete failed.\n");
3201 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
3202 scsi_host_put(vha->host);
3207 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
3209 scsi_qla_host_t *vha = fc_vport->dd_data;
3212 qla24xx_disable_vp(vha);
3214 qla24xx_enable_vp(vha);
3219 struct fc_function_template qla2xxx_transport_functions = {
3221 .show_host_node_name = 1,
3222 .show_host_port_name = 1,
3223 .show_host_supported_classes = 1,
3224 .show_host_supported_speeds = 1,
3226 .get_host_port_id = qla2x00_get_host_port_id,
3227 .show_host_port_id = 1,
3228 .get_host_speed = qla2x00_get_host_speed,
3229 .show_host_speed = 1,
3230 .get_host_port_type = qla2x00_get_host_port_type,
3231 .show_host_port_type = 1,
3232 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3233 .show_host_symbolic_name = 1,
3234 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3235 .show_host_system_hostname = 1,
3236 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3237 .show_host_fabric_name = 1,
3238 .get_host_port_state = qla2x00_get_host_port_state,
3239 .show_host_port_state = 1,
3241 .dd_fcrport_size = sizeof(struct fc_port *),
3242 .show_rport_supported_classes = 1,
3244 .get_starget_node_name = qla2x00_get_starget_node_name,
3245 .show_starget_node_name = 1,
3246 .get_starget_port_name = qla2x00_get_starget_port_name,
3247 .show_starget_port_name = 1,
3248 .get_starget_port_id = qla2x00_get_starget_port_id,
3249 .show_starget_port_id = 1,
3251 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3252 .show_rport_dev_loss_tmo = 1,
3254 .issue_fc_host_lip = qla2x00_issue_lip,
3255 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3256 .terminate_rport_io = qla2x00_terminate_rport_io,
3257 .get_fc_host_stats = qla2x00_get_fc_host_stats,
3258 .reset_fc_host_stats = qla2x00_reset_host_stats,
3260 .vport_create = qla24xx_vport_create,
3261 .vport_disable = qla24xx_vport_disable,
3262 .vport_delete = qla24xx_vport_delete,
3263 .bsg_request = qla24xx_bsg_request,
3264 .bsg_timeout = qla24xx_bsg_timeout,
3267 struct fc_function_template qla2xxx_transport_vport_functions = {
3269 .show_host_node_name = 1,
3270 .show_host_port_name = 1,
3271 .show_host_supported_classes = 1,
3273 .get_host_port_id = qla2x00_get_host_port_id,
3274 .show_host_port_id = 1,
3275 .get_host_speed = qla2x00_get_host_speed,
3276 .show_host_speed = 1,
3277 .get_host_port_type = qla2x00_get_host_port_type,
3278 .show_host_port_type = 1,
3279 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3280 .show_host_symbolic_name = 1,
3281 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3282 .show_host_system_hostname = 1,
3283 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3284 .show_host_fabric_name = 1,
3285 .get_host_port_state = qla2x00_get_host_port_state,
3286 .show_host_port_state = 1,
3288 .dd_fcrport_size = sizeof(struct fc_port *),
3289 .show_rport_supported_classes = 1,
3291 .get_starget_node_name = qla2x00_get_starget_node_name,
3292 .show_starget_node_name = 1,
3293 .get_starget_port_name = qla2x00_get_starget_port_name,
3294 .show_starget_port_name = 1,
3295 .get_starget_port_id = qla2x00_get_starget_port_id,
3296 .show_starget_port_id = 1,
3298 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3299 .show_rport_dev_loss_tmo = 1,
3301 .issue_fc_host_lip = qla2x00_issue_lip,
3302 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3303 .terminate_rport_io = qla2x00_terminate_rport_io,
3304 .get_fc_host_stats = qla2x00_get_fc_host_stats,
3305 .reset_fc_host_stats = qla2x00_reset_host_stats,
3307 .bsg_request = qla24xx_bsg_request,
3308 .bsg_timeout = qla24xx_bsg_timeout,
3312 qla2x00_init_host_attr(scsi_qla_host_t *vha)
3314 struct qla_hw_data *ha = vha->hw;
3315 u32 speeds = FC_PORTSPEED_UNKNOWN;
3317 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
3318 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3319 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
3320 fc_host_supported_classes(vha->host) = ha->base_qpair->enable_class_2 ?
3321 (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
3322 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
3323 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
3325 speeds = qla25xx_fdmi_port_speed_capability(ha);
3327 fc_host_supported_speeds(vha->host) = speeds;