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) || IS_QLA27XX(ha) || IS_QLA28XX(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)))
1059 if (iter->type == 0x27 &&
1060 (!IS_QLA27XX(ha) || !IS_QLA28XX(ha)))
1063 sysfs_remove_bin_file(&host->shost_gendev.kobj,
1067 if (stop_beacon && ha->beacon_blink_led == 1)
1068 ha->isp_ops->beacon_off(vha);
1071 /* Scsi_Host attributes. */
1074 qla2x00_driver_version_show(struct device *dev,
1075 struct device_attribute *attr, char *buf)
1077 return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
1081 qla2x00_fw_version_show(struct device *dev,
1082 struct device_attribute *attr, char *buf)
1084 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1085 struct qla_hw_data *ha = vha->hw;
1088 return scnprintf(buf, PAGE_SIZE, "%s\n",
1089 ha->isp_ops->fw_version_str(vha, fw_str, sizeof(fw_str)));
1093 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
1096 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1097 struct qla_hw_data *ha = vha->hw;
1100 if (IS_QLAFX00(vha->hw)) {
1101 return scnprintf(buf, PAGE_SIZE, "%s\n",
1102 vha->hw->mr.serial_num);
1103 } else if (IS_FWI2_CAPABLE(ha)) {
1104 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE - 1);
1105 return strlen(strcat(buf, "\n"));
1108 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1109 return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
1114 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
1117 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1119 return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
1123 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
1126 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1127 struct qla_hw_data *ha = vha->hw;
1129 if (IS_QLAFX00(vha->hw))
1130 return scnprintf(buf, PAGE_SIZE, "%s\n",
1131 vha->hw->mr.hw_version);
1133 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
1134 ha->product_id[0], ha->product_id[1], ha->product_id[2],
1139 qla2x00_model_name_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_number);
1148 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1151 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1153 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
1157 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1160 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1163 return scnprintf(buf, PAGE_SIZE, "%s\n",
1164 vha->hw->isp_ops->pci_info_str(vha, pci_info,
1169 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1172 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1173 struct qla_hw_data *ha = vha->hw;
1176 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
1177 atomic_read(&vha->loop_state) == LOOP_DEAD ||
1178 vha->device_flags & DFLG_NO_CABLE)
1179 len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
1180 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1181 qla2x00_chip_is_down(vha))
1182 len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1184 len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
1186 switch (ha->current_topology) {
1188 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1191 len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1194 len += scnprintf(buf + len, PAGE_SIZE-len,
1195 "N_Port to N_Port\n");
1198 len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1201 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1209 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1212 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1215 switch (vha->hw->zio_mode) {
1216 case QLA_ZIO_MODE_6:
1217 len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1219 case QLA_ZIO_DISABLED:
1220 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1227 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1228 const char *buf, size_t count)
1230 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1231 struct qla_hw_data *ha = vha->hw;
1235 if (!IS_ZIO_SUPPORTED(ha))
1238 if (sscanf(buf, "%d", &val) != 1)
1242 zio_mode = QLA_ZIO_MODE_6;
1244 zio_mode = QLA_ZIO_DISABLED;
1246 /* Update per-hba values and queue a reset. */
1247 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1248 ha->zio_mode = zio_mode;
1249 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1255 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1258 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1260 return scnprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
1264 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1265 const char *buf, size_t count)
1267 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1271 if (sscanf(buf, "%d", &val) != 1)
1273 if (val > 25500 || val < 100)
1276 zio_timer = (uint16_t)(val / 100);
1277 vha->hw->zio_timer = zio_timer;
1283 qla_zio_threshold_show(struct device *dev, struct device_attribute *attr,
1286 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1288 return scnprintf(buf, PAGE_SIZE, "%d exchanges\n",
1289 vha->hw->last_zio_threshold);
1293 qla_zio_threshold_store(struct device *dev, struct device_attribute *attr,
1294 const char *buf, size_t count)
1296 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1299 if (vha->hw->zio_mode != QLA_ZIO_MODE_6)
1301 if (sscanf(buf, "%d", &val) != 1)
1303 if (val < 0 || val > 256)
1306 atomic_set(&vha->hw->zio_threshold, val);
1311 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1314 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1317 if (vha->hw->beacon_blink_led)
1318 len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1320 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1325 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1326 const char *buf, size_t count)
1328 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1329 struct qla_hw_data *ha = vha->hw;
1333 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1336 if (sscanf(buf, "%d", &val) != 1)
1339 mutex_lock(&vha->hw->optrom_mutex);
1340 if (qla2x00_chip_is_down(vha)) {
1341 mutex_unlock(&vha->hw->optrom_mutex);
1342 ql_log(ql_log_warn, vha, 0x707a,
1343 "Abort ISP active -- ignoring beacon request.\n");
1348 rval = ha->isp_ops->beacon_on(vha);
1350 rval = ha->isp_ops->beacon_off(vha);
1352 if (rval != QLA_SUCCESS)
1355 mutex_unlock(&vha->hw->optrom_mutex);
1361 qla2x00_beacon_config_show(struct device *dev, struct device_attribute *attr,
1364 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1365 struct qla_hw_data *ha = vha->hw;
1366 uint16_t led[3] = { 0 };
1368 if (!IS_QLA2031(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1371 if (ql26xx_led_config(vha, 0, led))
1372 return scnprintf(buf, PAGE_SIZE, "\n");
1374 return scnprintf(buf, PAGE_SIZE, "%#04hx %#04hx %#04hx\n",
1375 led[0], led[1], led[2]);
1379 qla2x00_beacon_config_store(struct device *dev, struct device_attribute *attr,
1380 const char *buf, size_t count)
1382 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1383 struct qla_hw_data *ha = vha->hw;
1384 uint16_t options = BIT_0;
1385 uint16_t led[3] = { 0 };
1389 if (!IS_QLA2031(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1392 n = sscanf(buf, "%hx %hx %hx %hx", word+0, word+1, word+2, word+3);
1395 options |= BIT_3|BIT_2|BIT_1;
1405 /* check led index */
1427 if (ql26xx_led_config(vha, options, led))
1434 qla2x00_optrom_bios_version_show(struct device *dev,
1435 struct device_attribute *attr, char *buf)
1437 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1438 struct qla_hw_data *ha = vha->hw;
1440 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1441 ha->bios_revision[0]);
1445 qla2x00_optrom_efi_version_show(struct device *dev,
1446 struct device_attribute *attr, char *buf)
1448 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1449 struct qla_hw_data *ha = vha->hw;
1451 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1452 ha->efi_revision[0]);
1456 qla2x00_optrom_fcode_version_show(struct device *dev,
1457 struct device_attribute *attr, char *buf)
1459 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1460 struct qla_hw_data *ha = vha->hw;
1462 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1463 ha->fcode_revision[0]);
1467 qla2x00_optrom_fw_version_show(struct device *dev,
1468 struct device_attribute *attr, char *buf)
1470 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1471 struct qla_hw_data *ha = vha->hw;
1473 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1474 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1475 ha->fw_revision[3]);
1479 qla2x00_optrom_gold_fw_version_show(struct device *dev,
1480 struct device_attribute *attr, char *buf)
1482 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1483 struct qla_hw_data *ha = vha->hw;
1485 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1486 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1487 return scnprintf(buf, PAGE_SIZE, "\n");
1489 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1490 ha->gold_fw_version[0], ha->gold_fw_version[1],
1491 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1495 qla2x00_total_isp_aborts_show(struct device *dev,
1496 struct device_attribute *attr, char *buf)
1498 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1500 return scnprintf(buf, PAGE_SIZE, "%d\n",
1501 vha->qla_stats.total_isp_aborts);
1505 qla24xx_84xx_fw_version_show(struct device *dev,
1506 struct device_attribute *attr, char *buf)
1508 int rval = QLA_SUCCESS;
1509 uint16_t status[2] = { 0 };
1510 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1511 struct qla_hw_data *ha = vha->hw;
1513 if (!IS_QLA84XX(ha))
1514 return scnprintf(buf, PAGE_SIZE, "\n");
1516 if (!ha->cs84xx->op_fw_version) {
1517 rval = qla84xx_verify_chip(vha, status);
1519 if (!rval && !status[0])
1520 return scnprintf(buf, PAGE_SIZE, "%u\n",
1521 (uint32_t)ha->cs84xx->op_fw_version);
1524 return scnprintf(buf, PAGE_SIZE, "\n");
1528 qla2x00_serdes_version_show(struct device *dev, struct device_attribute *attr,
1531 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1532 struct qla_hw_data *ha = vha->hw;
1534 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1535 return scnprintf(buf, PAGE_SIZE, "\n");
1537 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1538 ha->serdes_version[0], ha->serdes_version[1],
1539 ha->serdes_version[2]);
1543 qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1546 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1547 struct qla_hw_data *ha = vha->hw;
1549 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
1550 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1551 return scnprintf(buf, PAGE_SIZE, "\n");
1553 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
1554 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
1555 ha->mpi_capabilities);
1559 qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1562 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1563 struct qla_hw_data *ha = vha->hw;
1565 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
1566 return scnprintf(buf, PAGE_SIZE, "\n");
1568 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1569 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
1573 qla2x00_flash_block_size_show(struct device *dev,
1574 struct device_attribute *attr, char *buf)
1576 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1577 struct qla_hw_data *ha = vha->hw;
1579 return scnprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1583 qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1586 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1588 if (!IS_CNA_CAPABLE(vha->hw))
1589 return scnprintf(buf, PAGE_SIZE, "\n");
1591 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1595 qla2x00_vn_port_mac_address_show(struct device *dev,
1596 struct device_attribute *attr, char *buf)
1598 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1600 if (!IS_CNA_CAPABLE(vha->hw))
1601 return scnprintf(buf, PAGE_SIZE, "\n");
1603 return scnprintf(buf, PAGE_SIZE, "%pMR\n", vha->fcoe_vn_port_mac);
1607 qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1610 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1612 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1616 qla2x00_thermal_temp_show(struct device *dev,
1617 struct device_attribute *attr, char *buf)
1619 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1623 mutex_lock(&vha->hw->optrom_mutex);
1624 if (qla2x00_chip_is_down(vha)) {
1625 mutex_unlock(&vha->hw->optrom_mutex);
1626 ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
1630 if (vha->hw->flags.eeh_busy) {
1631 mutex_unlock(&vha->hw->optrom_mutex);
1632 ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
1636 rc = qla2x00_get_thermal_temp(vha, &temp);
1637 mutex_unlock(&vha->hw->optrom_mutex);
1638 if (rc == QLA_SUCCESS)
1639 return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
1642 return scnprintf(buf, PAGE_SIZE, "\n");
1646 qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1649 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1650 int rval = QLA_FUNCTION_FAILED;
1654 if (IS_QLAFX00(vha->hw)) {
1655 pstate = qlafx00_fw_state_show(dev, attr, buf);
1656 return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
1659 mutex_lock(&vha->hw->optrom_mutex);
1660 if (qla2x00_chip_is_down(vha)) {
1661 mutex_unlock(&vha->hw->optrom_mutex);
1662 ql_log(ql_log_warn, vha, 0x707c,
1663 "ISP reset active.\n");
1665 } else if (vha->hw->flags.eeh_busy) {
1666 mutex_unlock(&vha->hw->optrom_mutex);
1670 rval = qla2x00_get_firmware_state(vha, state);
1671 mutex_unlock(&vha->hw->optrom_mutex);
1673 if (rval != QLA_SUCCESS) {
1674 memset(state, -1, sizeof(state));
1675 rval = qla2x00_get_firmware_state(vha, state);
1678 return scnprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1679 state[0], state[1], state[2], state[3], state[4], state[5]);
1683 qla2x00_diag_requests_show(struct device *dev,
1684 struct device_attribute *attr, char *buf)
1686 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1688 if (!IS_BIDI_CAPABLE(vha->hw))
1689 return scnprintf(buf, PAGE_SIZE, "\n");
1691 return scnprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
1695 qla2x00_diag_megabytes_show(struct device *dev,
1696 struct device_attribute *attr, char *buf)
1698 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1700 if (!IS_BIDI_CAPABLE(vha->hw))
1701 return scnprintf(buf, PAGE_SIZE, "\n");
1703 return scnprintf(buf, PAGE_SIZE, "%llu\n",
1704 vha->bidi_stats.transfer_bytes >> 20);
1708 qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
1711 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1712 struct qla_hw_data *ha = vha->hw;
1717 else if (IS_P3P_TYPE(ha))
1718 size = ha->md_template_size + ha->md_dump_size;
1720 size = ha->fw_dump_len;
1722 return scnprintf(buf, PAGE_SIZE, "%d\n", size);
1726 qla2x00_allow_cna_fw_dump_show(struct device *dev,
1727 struct device_attribute *attr, char *buf)
1729 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1731 if (!IS_P3P_TYPE(vha->hw))
1732 return scnprintf(buf, PAGE_SIZE, "\n");
1734 return scnprintf(buf, PAGE_SIZE, "%s\n",
1735 vha->hw->allow_cna_fw_dump ? "true" : "false");
1739 qla2x00_allow_cna_fw_dump_store(struct device *dev,
1740 struct device_attribute *attr, const char *buf, size_t count)
1742 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1745 if (!IS_P3P_TYPE(vha->hw))
1748 if (sscanf(buf, "%d", &val) != 1)
1751 vha->hw->allow_cna_fw_dump = val != 0;
1757 qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
1760 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1761 struct qla_hw_data *ha = vha->hw;
1763 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1764 return scnprintf(buf, PAGE_SIZE, "\n");
1766 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1767 ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
1771 qla2x00_min_supported_speed_show(struct device *dev,
1772 struct device_attribute *attr, char *buf)
1774 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1775 struct qla_hw_data *ha = vha->hw;
1777 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1778 return scnprintf(buf, PAGE_SIZE, "\n");
1780 return scnprintf(buf, PAGE_SIZE, "%s\n",
1781 ha->min_supported_speed == 6 ? "64Gps" :
1782 ha->min_supported_speed == 5 ? "32Gps" :
1783 ha->min_supported_speed == 4 ? "16Gps" :
1784 ha->min_supported_speed == 3 ? "8Gps" :
1785 ha->min_supported_speed == 2 ? "4Gps" :
1786 ha->min_supported_speed != 0 ? "unknown" : "");
1790 qla2x00_max_supported_speed_show(struct device *dev,
1791 struct device_attribute *attr, char *buf)
1793 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1794 struct qla_hw_data *ha = vha->hw;
1796 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1797 return scnprintf(buf, PAGE_SIZE, "\n");
1799 return scnprintf(buf, PAGE_SIZE, "%s\n",
1800 ha->max_supported_speed == 2 ? "64Gps" :
1801 ha->max_supported_speed == 1 ? "32Gps" :
1802 ha->max_supported_speed == 0 ? "16Gps" : "unknown");
1806 qla2x00_port_speed_store(struct device *dev, struct device_attribute *attr,
1807 const char *buf, size_t count)
1809 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1812 int mode = QLA_SET_DATA_RATE_LR;
1813 struct qla_hw_data *ha = vha->hw;
1815 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) {
1816 ql_log(ql_log_warn, vha, 0x70d8,
1817 "Speed setting not supported \n");
1821 rval = kstrtol(buf, 10, &type);
1825 if (type == 40 || type == 80 || type == 160 ||
1827 ql_dbg(ql_dbg_user, vha, 0x70d9,
1828 "Setting will be affected after a loss of sync\n");
1830 mode = QLA_SET_DATA_RATE_NOLR;
1833 oldspeed = ha->set_data_rate;
1837 ha->set_data_rate = PORT_SPEED_AUTO;
1840 ha->set_data_rate = PORT_SPEED_4GB;
1843 ha->set_data_rate = PORT_SPEED_8GB;
1846 ha->set_data_rate = PORT_SPEED_16GB;
1849 ha->set_data_rate = PORT_SPEED_32GB;
1852 ql_log(ql_log_warn, vha, 0x1199,
1853 "Unrecognized speed setting:%lx. Setting Autoneg\n",
1855 ha->set_data_rate = PORT_SPEED_AUTO;
1858 if (qla2x00_chip_is_down(vha) || (oldspeed == ha->set_data_rate))
1861 ql_log(ql_log_info, vha, 0x70da,
1862 "Setting speed to %lx Gbps \n", type);
1864 rval = qla2x00_set_data_rate(vha, mode);
1865 if (rval != QLA_SUCCESS)
1871 static const struct {
1874 } port_speed_str[] = {
1875 { PORT_SPEED_4GB, "4" },
1876 { PORT_SPEED_8GB, "8" },
1877 { PORT_SPEED_16GB, "16" },
1878 { PORT_SPEED_32GB, "32" },
1879 { PORT_SPEED_64GB, "64" },
1880 { PORT_SPEED_10GB, "10" },
1884 qla2x00_port_speed_show(struct device *dev, struct device_attribute *attr,
1887 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1888 struct qla_hw_data *ha = vha->hw;
1891 char *speed = "Unknown";
1893 rval = qla2x00_get_data_rate(vha);
1894 if (rval != QLA_SUCCESS) {
1895 ql_log(ql_log_warn, vha, 0x70db,
1896 "Unable to get port speed rval:%zd\n", rval);
1900 for (i = 0; i < ARRAY_SIZE(port_speed_str); i++) {
1901 if (port_speed_str[i].rate != ha->link_data_rate)
1903 speed = port_speed_str[i].str;
1907 return scnprintf(buf, PAGE_SIZE, "%s\n", speed);
1911 qla2x00_mpi_pause_store(struct device *dev,
1912 struct device_attribute *attr, const char *buf, size_t count)
1914 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1917 if (sscanf(buf, "%d", &rval) != 1)
1920 ql_log(ql_log_warn, vha, 0x7089, "Pausing MPI...\n");
1922 rval = qla83xx_wr_reg(vha, 0x002012d4, 0x30000001);
1924 if (rval != QLA_SUCCESS) {
1925 ql_log(ql_log_warn, vha, 0x708a, "Unable to pause MPI.\n");
1932 static DEVICE_ATTR(mpi_pause, S_IWUSR, NULL, qla2x00_mpi_pause_store);
1937 qlini_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1939 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1942 len += scnprintf(buf + len, PAGE_SIZE-len,
1943 "Supported options: enabled | disabled | dual | exclusive\n");
1946 len += scnprintf(buf + len, PAGE_SIZE-len, "Current selection: ");
1948 switch (vha->qlini_mode) {
1949 case QLA2XXX_INI_MODE_EXCLUSIVE:
1950 len += scnprintf(buf + len, PAGE_SIZE-len,
1951 QLA2XXX_INI_MODE_STR_EXCLUSIVE);
1953 case QLA2XXX_INI_MODE_DISABLED:
1954 len += scnprintf(buf + len, PAGE_SIZE-len,
1955 QLA2XXX_INI_MODE_STR_DISABLED);
1957 case QLA2XXX_INI_MODE_ENABLED:
1958 len += scnprintf(buf + len, PAGE_SIZE-len,
1959 QLA2XXX_INI_MODE_STR_ENABLED);
1961 case QLA2XXX_INI_MODE_DUAL:
1962 len += scnprintf(buf + len, PAGE_SIZE-len,
1963 QLA2XXX_INI_MODE_STR_DUAL);
1966 len += scnprintf(buf + len, PAGE_SIZE-len, "\n");
1971 static char *mode_to_str[] = {
1978 #define NEED_EXCH_OFFLOAD(_exchg) ((_exchg) > FW_DEF_EXCHANGES_CNT)
1979 static void qla_set_ini_mode(scsi_qla_host_t *vha, int op)
1984 MODE_CHANGE_NO_ACTION,
1985 TARGET_STILL_ACTIVE,
1987 int action = NO_ACTION;
1989 u8 eo_toggle = 0; /* exchange offload flipped */
1991 switch (vha->qlini_mode) {
1992 case QLA2XXX_INI_MODE_DISABLED:
1994 case QLA2XXX_INI_MODE_DISABLED:
1995 if (qla_tgt_mode_enabled(vha)) {
1996 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1997 vha->hw->flags.exchoffld_enabled)
1999 if (((vha->ql2xexchoffld !=
2000 vha->u_ql2xexchoffld) &&
2001 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2004 * The number of exchange to be offload
2005 * was tweaked or offload option was
2008 action = MODE_CHANGE_ACCEPT;
2010 action = MODE_CHANGE_NO_ACTION;
2013 action = MODE_CHANGE_NO_ACTION;
2016 case QLA2XXX_INI_MODE_EXCLUSIVE:
2017 if (qla_tgt_mode_enabled(vha)) {
2018 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2019 vha->hw->flags.exchoffld_enabled)
2021 if (((vha->ql2xexchoffld !=
2022 vha->u_ql2xexchoffld) &&
2023 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2026 * The number of exchange to be offload
2027 * was tweaked or offload option was
2030 action = MODE_CHANGE_ACCEPT;
2032 action = MODE_CHANGE_NO_ACTION;
2035 action = MODE_CHANGE_ACCEPT;
2038 case QLA2XXX_INI_MODE_DUAL:
2039 action = MODE_CHANGE_ACCEPT;
2040 /* active_mode is target only, reset it to dual */
2041 if (qla_tgt_mode_enabled(vha)) {
2043 action = MODE_CHANGE_ACCEPT;
2045 action = MODE_CHANGE_NO_ACTION;
2049 case QLA2XXX_INI_MODE_ENABLED:
2050 if (qla_tgt_mode_enabled(vha))
2051 action = TARGET_STILL_ACTIVE;
2053 action = MODE_CHANGE_ACCEPT;
2060 case QLA2XXX_INI_MODE_EXCLUSIVE:
2062 case QLA2XXX_INI_MODE_EXCLUSIVE:
2063 if (qla_tgt_mode_enabled(vha)) {
2064 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2065 vha->hw->flags.exchoffld_enabled)
2067 if (((vha->ql2xexchoffld !=
2068 vha->u_ql2xexchoffld) &&
2069 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2072 * The number of exchange to be offload
2073 * was tweaked or offload option was
2076 action = MODE_CHANGE_ACCEPT;
2084 case QLA2XXX_INI_MODE_DISABLED:
2085 if (qla_tgt_mode_enabled(vha)) {
2086 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2087 vha->hw->flags.exchoffld_enabled)
2089 if (((vha->ql2xexchoffld !=
2090 vha->u_ql2xexchoffld) &&
2091 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2093 action = MODE_CHANGE_ACCEPT;
2095 action = MODE_CHANGE_NO_ACTION;
2097 action = MODE_CHANGE_NO_ACTION;
2100 case QLA2XXX_INI_MODE_DUAL: /* exclusive -> dual */
2101 if (qla_tgt_mode_enabled(vha)) {
2102 action = MODE_CHANGE_ACCEPT;
2105 action = MODE_CHANGE_ACCEPT;
2108 case QLA2XXX_INI_MODE_ENABLED:
2109 if (qla_tgt_mode_enabled(vha))
2110 action = TARGET_STILL_ACTIVE;
2112 if (vha->hw->flags.fw_started)
2113 action = MODE_CHANGE_NO_ACTION;
2115 action = MODE_CHANGE_ACCEPT;
2121 case QLA2XXX_INI_MODE_ENABLED:
2123 case QLA2XXX_INI_MODE_ENABLED:
2124 if (NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg) !=
2125 vha->hw->flags.exchoffld_enabled)
2127 if (((vha->ql2xiniexchg != vha->u_ql2xiniexchg) &&
2128 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg)) ||
2130 action = MODE_CHANGE_ACCEPT;
2134 case QLA2XXX_INI_MODE_DUAL:
2135 case QLA2XXX_INI_MODE_DISABLED:
2136 action = MODE_CHANGE_ACCEPT;
2139 action = MODE_CHANGE_NO_ACTION;
2144 case QLA2XXX_INI_MODE_DUAL:
2146 case QLA2XXX_INI_MODE_DUAL:
2147 if (qla_tgt_mode_enabled(vha) ||
2148 qla_dual_mode_enabled(vha)) {
2149 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2150 vha->u_ql2xiniexchg) !=
2151 vha->hw->flags.exchoffld_enabled)
2154 if ((((vha->ql2xexchoffld +
2155 vha->ql2xiniexchg) !=
2156 (vha->u_ql2xiniexchg +
2157 vha->u_ql2xexchoffld)) &&
2158 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2159 vha->u_ql2xexchoffld)) || eo_toggle)
2160 action = MODE_CHANGE_ACCEPT;
2164 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2165 vha->u_ql2xiniexchg) !=
2166 vha->hw->flags.exchoffld_enabled)
2169 if ((((vha->ql2xexchoffld + vha->ql2xiniexchg)
2170 != (vha->u_ql2xiniexchg +
2171 vha->u_ql2xexchoffld)) &&
2172 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2173 vha->u_ql2xexchoffld)) || eo_toggle)
2174 action = MODE_CHANGE_NO_ACTION;
2180 case QLA2XXX_INI_MODE_DISABLED:
2181 if (qla_tgt_mode_enabled(vha) ||
2182 qla_dual_mode_enabled(vha)) {
2183 /* turning off initiator mode */
2185 action = MODE_CHANGE_ACCEPT;
2187 action = MODE_CHANGE_NO_ACTION;
2191 case QLA2XXX_INI_MODE_EXCLUSIVE:
2192 if (qla_tgt_mode_enabled(vha) ||
2193 qla_dual_mode_enabled(vha)) {
2195 action = MODE_CHANGE_ACCEPT;
2197 action = MODE_CHANGE_ACCEPT;
2201 case QLA2XXX_INI_MODE_ENABLED:
2202 if (qla_tgt_mode_enabled(vha) ||
2203 qla_dual_mode_enabled(vha)) {
2204 action = TARGET_STILL_ACTIVE;
2206 action = MODE_CHANGE_ACCEPT;
2213 case MODE_CHANGE_ACCEPT:
2214 ql_log(ql_log_warn, vha, 0xffff,
2215 "Mode change accepted. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2216 mode_to_str[vha->qlini_mode], mode_to_str[op],
2217 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2218 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2220 vha->qlini_mode = op;
2221 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2222 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2225 vha->flags.online = 1;
2226 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2229 case MODE_CHANGE_NO_ACTION:
2230 ql_log(ql_log_warn, vha, 0xffff,
2231 "Mode is set. No action taken. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2232 mode_to_str[vha->qlini_mode], mode_to_str[op],
2233 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2234 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2235 vha->qlini_mode = op;
2236 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2237 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2240 case TARGET_STILL_ACTIVE:
2241 ql_log(ql_log_warn, vha, 0xffff,
2242 "Target Mode is active. Unable to change Mode.\n");
2247 ql_log(ql_log_warn, vha, 0xffff,
2248 "Mode unchange. No action taken. %d|%d pct %d|%d.\n",
2249 vha->qlini_mode, op,
2250 vha->ql2xexchoffld, vha->u_ql2xexchoffld);
2256 qlini_mode_store(struct device *dev, struct device_attribute *attr,
2257 const char *buf, size_t count)
2259 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2265 if (strncasecmp(QLA2XXX_INI_MODE_STR_EXCLUSIVE, buf,
2266 strlen(QLA2XXX_INI_MODE_STR_EXCLUSIVE)) == 0)
2267 ini = QLA2XXX_INI_MODE_EXCLUSIVE;
2268 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DISABLED, buf,
2269 strlen(QLA2XXX_INI_MODE_STR_DISABLED)) == 0)
2270 ini = QLA2XXX_INI_MODE_DISABLED;
2271 else if (strncasecmp(QLA2XXX_INI_MODE_STR_ENABLED, buf,
2272 strlen(QLA2XXX_INI_MODE_STR_ENABLED)) == 0)
2273 ini = QLA2XXX_INI_MODE_ENABLED;
2274 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DUAL, buf,
2275 strlen(QLA2XXX_INI_MODE_STR_DUAL)) == 0)
2276 ini = QLA2XXX_INI_MODE_DUAL;
2280 qla_set_ini_mode(vha, ini);
2285 ql2xexchoffld_show(struct device *dev, struct device_attribute *attr,
2288 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2291 len += scnprintf(buf + len, PAGE_SIZE-len,
2292 "target exchange: new %d : current: %d\n\n",
2293 vha->u_ql2xexchoffld, vha->ql2xexchoffld);
2295 len += scnprintf(buf + len, PAGE_SIZE-len,
2296 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2303 ql2xexchoffld_store(struct device *dev, struct device_attribute *attr,
2304 const char *buf, size_t count)
2306 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2309 if (sscanf(buf, "%d", &val) != 1)
2312 if (val > FW_MAX_EXCHANGES_CNT)
2313 val = FW_MAX_EXCHANGES_CNT;
2317 vha->u_ql2xexchoffld = val;
2322 ql2xiniexchg_show(struct device *dev, struct device_attribute *attr,
2325 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2328 len += scnprintf(buf + len, PAGE_SIZE-len,
2329 "target exchange: new %d : current: %d\n\n",
2330 vha->u_ql2xiniexchg, vha->ql2xiniexchg);
2332 len += scnprintf(buf + len, PAGE_SIZE-len,
2333 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2340 ql2xiniexchg_store(struct device *dev, struct device_attribute *attr,
2341 const char *buf, size_t count)
2343 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2346 if (sscanf(buf, "%d", &val) != 1)
2349 if (val > FW_MAX_EXCHANGES_CNT)
2350 val = FW_MAX_EXCHANGES_CNT;
2354 vha->u_ql2xiniexchg = val;
2359 qla2x00_dif_bundle_statistics_show(struct device *dev,
2360 struct device_attribute *attr, char *buf)
2362 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2363 struct qla_hw_data *ha = vha->hw;
2365 return scnprintf(buf, PAGE_SIZE,
2366 "cross=%llu read=%llu write=%llu kalloc=%llu dma_alloc=%llu unusable=%u\n",
2367 ha->dif_bundle_crossed_pages, ha->dif_bundle_reads,
2368 ha->dif_bundle_writes, ha->dif_bundle_kallocs,
2369 ha->dif_bundle_dma_allocs, ha->pool.unusable.count);
2373 qla2x00_fw_attr_show(struct device *dev,
2374 struct device_attribute *attr, char *buf)
2376 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2377 struct qla_hw_data *ha = vha->hw;
2379 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2380 return scnprintf(buf, PAGE_SIZE, "\n");
2382 return scnprintf(buf, PAGE_SIZE, "%llx\n",
2383 (uint64_t)ha->fw_attributes_ext[1] << 48 |
2384 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2385 (uint64_t)ha->fw_attributes_h << 16 |
2386 (uint64_t)ha->fw_attributes);
2390 qla2x00_port_no_show(struct device *dev, struct device_attribute *attr,
2393 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2395 return scnprintf(buf, PAGE_SIZE, "%u\n", vha->hw->port_no);
2399 qla2x00_dport_diagnostics_show(struct device *dev,
2400 struct device_attribute *attr, char *buf)
2402 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2404 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
2405 !IS_QLA28XX(vha->hw))
2406 return scnprintf(buf, PAGE_SIZE, "\n");
2408 if (!*vha->dport_data)
2409 return scnprintf(buf, PAGE_SIZE, "\n");
2411 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
2412 vha->dport_data[0], vha->dport_data[1],
2413 vha->dport_data[2], vha->dport_data[3]);
2415 static DEVICE_ATTR(dport_diagnostics, 0444,
2416 qla2x00_dport_diagnostics_show, NULL);
2418 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_driver_version_show, NULL);
2419 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
2420 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
2421 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
2422 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
2423 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
2424 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
2425 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
2426 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
2427 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
2428 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
2429 qla2x00_zio_timer_store);
2430 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
2431 qla2x00_beacon_store);
2432 static DEVICE_ATTR(beacon_config, 0644, qla2x00_beacon_config_show,
2433 qla2x00_beacon_config_store);
2434 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
2435 qla2x00_optrom_bios_version_show, NULL);
2436 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
2437 qla2x00_optrom_efi_version_show, NULL);
2438 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
2439 qla2x00_optrom_fcode_version_show, NULL);
2440 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
2442 static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
2443 qla2x00_optrom_gold_fw_version_show, NULL);
2444 static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
2446 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
2448 static DEVICE_ATTR(serdes_version, 0444, qla2x00_serdes_version_show, NULL);
2449 static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
2450 static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
2451 static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
2453 static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
2454 static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
2455 qla2x00_vn_port_mac_address_show, NULL);
2456 static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
2457 static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
2458 static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
2459 static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
2460 static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
2461 static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
2462 static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
2463 qla2x00_allow_cna_fw_dump_show,
2464 qla2x00_allow_cna_fw_dump_store);
2465 static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
2466 static DEVICE_ATTR(min_supported_speed, 0444,
2467 qla2x00_min_supported_speed_show, NULL);
2468 static DEVICE_ATTR(max_supported_speed, 0444,
2469 qla2x00_max_supported_speed_show, NULL);
2470 static DEVICE_ATTR(zio_threshold, 0644,
2471 qla_zio_threshold_show,
2472 qla_zio_threshold_store);
2473 static DEVICE_ATTR_RW(qlini_mode);
2474 static DEVICE_ATTR_RW(ql2xexchoffld);
2475 static DEVICE_ATTR_RW(ql2xiniexchg);
2476 static DEVICE_ATTR(dif_bundle_statistics, 0444,
2477 qla2x00_dif_bundle_statistics_show, NULL);
2478 static DEVICE_ATTR(port_speed, 0644, qla2x00_port_speed_show,
2479 qla2x00_port_speed_store);
2480 static DEVICE_ATTR(port_no, 0444, qla2x00_port_no_show, NULL);
2481 static DEVICE_ATTR(fw_attr, 0444, qla2x00_fw_attr_show, NULL);
2482 static DEVICE_ATTR_RO(edif_doorbell);
2484 static struct attribute *qla2x00_host_attrs[] = {
2485 &dev_attr_driver_version.attr,
2486 &dev_attr_fw_version.attr,
2487 &dev_attr_serial_num.attr,
2488 &dev_attr_isp_name.attr,
2489 &dev_attr_isp_id.attr,
2490 &dev_attr_model_name.attr,
2491 &dev_attr_model_desc.attr,
2492 &dev_attr_pci_info.attr,
2493 &dev_attr_link_state.attr,
2495 &dev_attr_zio_timer.attr,
2496 &dev_attr_beacon.attr,
2497 &dev_attr_beacon_config.attr,
2498 &dev_attr_optrom_bios_version.attr,
2499 &dev_attr_optrom_efi_version.attr,
2500 &dev_attr_optrom_fcode_version.attr,
2501 &dev_attr_optrom_fw_version.attr,
2502 &dev_attr_84xx_fw_version.attr,
2503 &dev_attr_total_isp_aborts.attr,
2504 &dev_attr_serdes_version.attr,
2505 &dev_attr_mpi_version.attr,
2506 &dev_attr_phy_version.attr,
2507 &dev_attr_flash_block_size.attr,
2508 &dev_attr_vlan_id.attr,
2509 &dev_attr_vn_port_mac_address.attr,
2510 &dev_attr_fabric_param.attr,
2511 &dev_attr_fw_state.attr,
2512 &dev_attr_optrom_gold_fw_version.attr,
2513 &dev_attr_thermal_temp.attr,
2514 &dev_attr_diag_requests.attr,
2515 &dev_attr_diag_megabytes.attr,
2516 &dev_attr_fw_dump_size.attr,
2517 &dev_attr_allow_cna_fw_dump.attr,
2518 &dev_attr_pep_version.attr,
2519 &dev_attr_min_supported_speed.attr,
2520 &dev_attr_max_supported_speed.attr,
2521 &dev_attr_zio_threshold.attr,
2522 &dev_attr_dif_bundle_statistics.attr,
2523 &dev_attr_port_speed.attr,
2524 &dev_attr_port_no.attr,
2525 &dev_attr_fw_attr.attr,
2526 &dev_attr_dport_diagnostics.attr,
2527 &dev_attr_edif_doorbell.attr,
2528 &dev_attr_mpi_pause.attr,
2529 &dev_attr_qlini_mode.attr,
2530 &dev_attr_ql2xiniexchg.attr,
2531 &dev_attr_ql2xexchoffld.attr,
2535 static umode_t qla_host_attr_is_visible(struct kobject *kobj,
2536 struct attribute *attr, int i)
2538 if (ql2x_ini_mode != QLA2XXX_INI_MODE_DUAL &&
2539 (attr == &dev_attr_qlini_mode.attr ||
2540 attr == &dev_attr_ql2xiniexchg.attr ||
2541 attr == &dev_attr_ql2xexchoffld.attr))
2546 static const struct attribute_group qla2x00_host_attr_group = {
2547 .is_visible = qla_host_attr_is_visible,
2548 .attrs = qla2x00_host_attrs
2551 const struct attribute_group *qla2x00_host_groups[] = {
2552 &qla2x00_host_attr_group,
2556 /* Host attributes. */
2559 qla2x00_get_host_port_id(struct Scsi_Host *shost)
2561 scsi_qla_host_t *vha = shost_priv(shost);
2563 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
2564 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
2568 qla2x00_get_host_speed(struct Scsi_Host *shost)
2570 scsi_qla_host_t *vha = shost_priv(shost);
2573 if (IS_QLAFX00(vha->hw)) {
2574 qlafx00_get_host_speed(shost);
2578 switch (vha->hw->link_data_rate) {
2579 case PORT_SPEED_1GB:
2580 speed = FC_PORTSPEED_1GBIT;
2582 case PORT_SPEED_2GB:
2583 speed = FC_PORTSPEED_2GBIT;
2585 case PORT_SPEED_4GB:
2586 speed = FC_PORTSPEED_4GBIT;
2588 case PORT_SPEED_8GB:
2589 speed = FC_PORTSPEED_8GBIT;
2591 case PORT_SPEED_10GB:
2592 speed = FC_PORTSPEED_10GBIT;
2594 case PORT_SPEED_16GB:
2595 speed = FC_PORTSPEED_16GBIT;
2597 case PORT_SPEED_32GB:
2598 speed = FC_PORTSPEED_32GBIT;
2600 case PORT_SPEED_64GB:
2601 speed = FC_PORTSPEED_64GBIT;
2604 speed = FC_PORTSPEED_UNKNOWN;
2608 fc_host_speed(shost) = speed;
2612 qla2x00_get_host_port_type(struct Scsi_Host *shost)
2614 scsi_qla_host_t *vha = shost_priv(shost);
2618 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2621 switch (vha->hw->current_topology) {
2623 port_type = FC_PORTTYPE_LPORT;
2626 port_type = FC_PORTTYPE_NLPORT;
2629 port_type = FC_PORTTYPE_PTP;
2632 port_type = FC_PORTTYPE_NPORT;
2635 port_type = FC_PORTTYPE_UNKNOWN;
2639 fc_host_port_type(shost) = port_type;
2643 qla2x00_get_starget_node_name(struct scsi_target *starget)
2645 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2646 scsi_qla_host_t *vha = shost_priv(host);
2650 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2651 if (fcport->rport &&
2652 starget->id == fcport->rport->scsi_target_id) {
2653 node_name = wwn_to_u64(fcport->node_name);
2658 fc_starget_node_name(starget) = node_name;
2662 qla2x00_get_starget_port_name(struct scsi_target *starget)
2664 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2665 scsi_qla_host_t *vha = shost_priv(host);
2669 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2670 if (fcport->rport &&
2671 starget->id == fcport->rport->scsi_target_id) {
2672 port_name = wwn_to_u64(fcport->port_name);
2677 fc_starget_port_name(starget) = port_name;
2681 qla2x00_get_starget_port_id(struct scsi_target *starget)
2683 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2684 scsi_qla_host_t *vha = shost_priv(host);
2686 uint32_t port_id = ~0U;
2688 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2689 if (fcport->rport &&
2690 starget->id == fcport->rport->scsi_target_id) {
2691 port_id = fcport->d_id.b.domain << 16 |
2692 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2697 fc_starget_port_id(starget) = port_id;
2701 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2703 rport->dev_loss_tmo = timeout ? timeout : 1;
2707 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
2709 struct Scsi_Host *host = rport_to_shost(rport);
2710 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2711 unsigned long flags;
2716 /* Now that the rport has been deleted, set the fcport state to
2718 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
2721 * Transport has effectively 'deleted' the rport, clear
2722 * all local references.
2724 spin_lock_irqsave(host->host_lock, flags);
2725 fcport->rport = fcport->drport = NULL;
2726 *((fc_port_t **)rport->dd_data) = NULL;
2727 spin_unlock_irqrestore(host->host_lock, flags);
2729 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2732 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2733 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2739 qla2x00_terminate_rport_io(struct fc_rport *rport)
2741 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2746 if (test_bit(UNLOADING, &fcport->vha->dpc_flags))
2749 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2752 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2753 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2757 * At this point all fcport's software-states are cleared. Perform any
2758 * final cleanup of firmware resources (PCBs and XCBs).
2760 if (fcport->loop_id != FC_NO_LOOP_ID) {
2761 if (IS_FWI2_CAPABLE(fcport->vha->hw)) {
2762 if (fcport->loop_id != FC_NO_LOOP_ID)
2763 fcport->logout_on_delete = 1;
2765 if (!EDIF_NEGOTIATION_PENDING(fcport)) {
2766 ql_dbg(ql_dbg_disc, fcport->vha, 0x911e,
2767 "%s %d schedule session deletion\n", __func__,
2769 qlt_schedule_sess_for_deletion(fcport);
2772 qla2x00_port_logout(fcport->vha, fcport);
2778 qla2x00_issue_lip(struct Scsi_Host *shost)
2780 scsi_qla_host_t *vha = shost_priv(shost);
2782 if (IS_QLAFX00(vha->hw))
2785 if (vha->hw->flags.port_isolated)
2788 qla2x00_loop_reset(vha);
2792 static struct fc_host_statistics *
2793 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
2795 scsi_qla_host_t *vha = shost_priv(shost);
2796 struct qla_hw_data *ha = vha->hw;
2797 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2799 struct link_statistics *stats;
2800 dma_addr_t stats_dma;
2801 struct fc_host_statistics *p = &vha->fc_host_stat;
2802 struct qla_qpair *qpair;
2804 u64 ib = 0, ob = 0, ir = 0, or = 0;
2806 memset(p, -1, sizeof(*p));
2808 if (IS_QLAFX00(vha->hw))
2811 if (test_bit(UNLOADING, &vha->dpc_flags))
2814 if (unlikely(pci_channel_offline(ha->pdev)))
2817 if (qla2x00_chip_is_down(vha))
2820 stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2823 ql_log(ql_log_warn, vha, 0x707d,
2824 "Failed to allocate memory for stats.\n");
2828 rval = QLA_FUNCTION_FAILED;
2829 if (IS_FWI2_CAPABLE(ha)) {
2830 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, 0);
2831 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
2833 /* Must be in a 'READY' state for statistics retrieval. */
2834 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
2838 if (rval != QLA_SUCCESS)
2842 for (i = 0; i < vha->hw->max_qpairs; i++) {
2843 qpair = vha->hw->queue_pair_map[i];
2846 ir += qpair->counters.input_requests;
2847 or += qpair->counters.output_requests;
2848 ib += qpair->counters.input_bytes;
2849 ob += qpair->counters.output_bytes;
2851 ir += ha->base_qpair->counters.input_requests;
2852 or += ha->base_qpair->counters.output_requests;
2853 ib += ha->base_qpair->counters.input_bytes;
2854 ob += ha->base_qpair->counters.output_bytes;
2856 ir += vha->qla_stats.input_requests;
2857 or += vha->qla_stats.output_requests;
2858 ib += vha->qla_stats.input_bytes;
2859 ob += vha->qla_stats.output_bytes;
2862 p->link_failure_count = le32_to_cpu(stats->link_fail_cnt);
2863 p->loss_of_sync_count = le32_to_cpu(stats->loss_sync_cnt);
2864 p->loss_of_signal_count = le32_to_cpu(stats->loss_sig_cnt);
2865 p->prim_seq_protocol_err_count = le32_to_cpu(stats->prim_seq_err_cnt);
2866 p->invalid_tx_word_count = le32_to_cpu(stats->inval_xmit_word_cnt);
2867 p->invalid_crc_count = le32_to_cpu(stats->inval_crc_cnt);
2868 if (IS_FWI2_CAPABLE(ha)) {
2869 p->lip_count = le32_to_cpu(stats->lip_cnt);
2870 p->tx_frames = le32_to_cpu(stats->tx_frames);
2871 p->rx_frames = le32_to_cpu(stats->rx_frames);
2872 p->dumped_frames = le32_to_cpu(stats->discarded_frames);
2873 p->nos_count = le32_to_cpu(stats->nos_rcvd);
2875 le32_to_cpu(stats->dropped_frames) +
2876 le32_to_cpu(stats->discarded_frames);
2877 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
2878 p->rx_words = le64_to_cpu(stats->fpm_recv_word_cnt);
2879 p->tx_words = le64_to_cpu(stats->fpm_xmit_word_cnt);
2881 p->rx_words = ib >> 2;
2882 p->tx_words = ob >> 2;
2886 p->fcp_control_requests = vha->qla_stats.control_requests;
2887 p->fcp_input_requests = ir;
2888 p->fcp_output_requests = or;
2889 p->fcp_input_megabytes = ib >> 20;
2890 p->fcp_output_megabytes = ob >> 20;
2891 p->seconds_since_last_reset =
2892 get_jiffies_64() - vha->qla_stats.jiffies_at_last_reset;
2893 do_div(p->seconds_since_last_reset, HZ);
2896 dma_free_coherent(&ha->pdev->dev, sizeof(struct link_statistics),
2903 qla2x00_reset_host_stats(struct Scsi_Host *shost)
2905 scsi_qla_host_t *vha = shost_priv(shost);
2906 struct qla_hw_data *ha = vha->hw;
2907 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2908 struct link_statistics *stats;
2909 dma_addr_t stats_dma;
2911 struct qla_qpair *qpair;
2913 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2914 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2915 for (i = 0; i < vha->hw->max_qpairs; i++) {
2916 qpair = vha->hw->queue_pair_map[i];
2919 memset(&qpair->counters, 0, sizeof(qpair->counters));
2921 memset(&ha->base_qpair->counters, 0, sizeof(qpair->counters));
2923 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2925 if (IS_FWI2_CAPABLE(ha)) {
2928 stats = dma_alloc_coherent(&ha->pdev->dev,
2929 sizeof(*stats), &stats_dma, GFP_KERNEL);
2931 ql_log(ql_log_warn, vha, 0x70d7,
2932 "Failed to allocate memory for stats.\n");
2936 /* reset firmware statistics */
2937 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, BIT_0);
2938 if (rval != QLA_SUCCESS)
2939 ql_log(ql_log_warn, vha, 0x70de,
2940 "Resetting ISP statistics failed: rval = %d\n",
2943 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2949 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
2951 scsi_qla_host_t *vha = shost_priv(shost);
2953 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost),
2954 sizeof(fc_host_symbolic_name(shost)));
2958 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
2960 scsi_qla_host_t *vha = shost_priv(shost);
2962 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
2966 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
2968 scsi_qla_host_t *vha = shost_priv(shost);
2969 static const uint8_t node_name[WWN_SIZE] = {
2970 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
2972 u64 fabric_name = wwn_to_u64(node_name);
2974 if (vha->device_flags & SWITCH_FOUND)
2975 fabric_name = wwn_to_u64(vha->fabric_node_name);
2977 fc_host_fabric_name(shost) = fabric_name;
2981 qla2x00_get_host_port_state(struct Scsi_Host *shost)
2983 scsi_qla_host_t *vha = shost_priv(shost);
2984 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
2986 if (!base_vha->flags.online) {
2987 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2991 switch (atomic_read(&base_vha->loop_state)) {
2993 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2996 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
2997 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2999 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3002 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
3005 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
3008 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
3014 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
3018 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
3019 scsi_qla_host_t *vha = NULL;
3020 struct qla_hw_data *ha = base_vha->hw;
3022 struct req_que *req = ha->req_q_map[0];
3023 struct qla_qpair *qpair;
3025 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
3027 ql_log(ql_log_warn, vha, 0x707e,
3028 "Vport sanity check failed, status %x\n", ret);
3032 vha = qla24xx_create_vhost(fc_vport);
3034 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
3035 return FC_VPORT_FAILED;
3038 atomic_set(&vha->vp_state, VP_OFFLINE);
3039 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
3041 atomic_set(&vha->vp_state, VP_FAILED);
3043 /* ready to create vport */
3044 ql_log(ql_log_info, vha, 0x7080,
3045 "VP entry id %d assigned.\n", vha->vp_idx);
3047 /* initialized vport states */
3048 atomic_set(&vha->loop_state, LOOP_DOWN);
3049 vha->vp_err_state = VP_ERR_PORTDWN;
3050 vha->vp_prev_err_state = VP_ERR_UNKWN;
3051 /* Check if physical ha port is Up */
3052 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
3053 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
3054 /* Don't retry or attempt login of this virtual port */
3055 ql_dbg(ql_dbg_user, vha, 0x7081,
3056 "Vport loop state is not UP.\n");
3057 atomic_set(&vha->loop_state, LOOP_DEAD);
3059 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
3062 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
3063 if (ha->fw_attributes & BIT_4) {
3064 int prot = 0, guard;
3066 vha->flags.difdix_supported = 1;
3067 ql_dbg(ql_dbg_user, vha, 0x7082,
3068 "Registered for DIF/DIX type 1 and 3 protection.\n");
3069 if (ql2xenabledif == 1)
3070 prot = SHOST_DIX_TYPE0_PROTECTION;
3071 scsi_host_set_prot(vha->host,
3072 prot | SHOST_DIF_TYPE1_PROTECTION
3073 | SHOST_DIF_TYPE2_PROTECTION
3074 | SHOST_DIF_TYPE3_PROTECTION
3075 | SHOST_DIX_TYPE1_PROTECTION
3076 | SHOST_DIX_TYPE2_PROTECTION
3077 | SHOST_DIX_TYPE3_PROTECTION);
3079 guard = SHOST_DIX_GUARD_CRC;
3081 if (IS_PI_IPGUARD_CAPABLE(ha) &&
3082 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
3083 guard |= SHOST_DIX_GUARD_IP;
3085 scsi_host_set_guard(vha->host, guard);
3087 vha->flags.difdix_supported = 0;
3090 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
3092 ql_dbg(ql_dbg_user, vha, 0x7083,
3093 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
3094 goto vport_create_failed_2;
3097 /* initialize attributes */
3098 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
3099 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3100 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
3101 fc_host_supported_classes(vha->host) =
3102 fc_host_supported_classes(base_vha->host);
3103 fc_host_supported_speeds(vha->host) =
3104 fc_host_supported_speeds(base_vha->host);
3106 qlt_vport_create(vha, ha);
3107 qla24xx_vport_disable(fc_vport, disable);
3109 if (!ql2xmqsupport || !ha->npiv_info)
3112 /* Create a request queue in QoS mode for the vport */
3113 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
3114 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
3115 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
3117 qos = ha->npiv_info[cnt].q_qos;
3123 qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx, true);
3125 ql_log(ql_log_warn, vha, 0x7084,
3126 "Can't create qpair for VP[%d]\n",
3129 ql_dbg(ql_dbg_multiq, vha, 0xc001,
3130 "Queue pair: %d Qos: %d) created for VP[%d]\n",
3131 qpair->id, qos, vha->vp_idx);
3132 ql_dbg(ql_dbg_user, vha, 0x7085,
3133 "Queue Pair: %d Qos: %d) created for VP[%d]\n",
3134 qpair->id, qos, vha->vp_idx);
3144 vport_create_failed_2:
3145 qla24xx_disable_vp(vha);
3146 qla24xx_deallocate_vp_id(vha);
3147 scsi_host_put(vha->host);
3148 return FC_VPORT_FAILED;
3152 qla24xx_vport_delete(struct fc_vport *fc_vport)
3154 scsi_qla_host_t *vha = fc_vport->dd_data;
3155 struct qla_hw_data *ha = vha->hw;
3156 uint16_t id = vha->vp_idx;
3158 set_bit(VPORT_DELETE, &vha->dpc_flags);
3160 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
3161 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
3165 qla24xx_disable_vp(vha);
3166 qla2x00_wait_for_sess_deletion(vha);
3168 qla_nvme_delete(vha);
3169 qla_enode_stop(vha);
3172 vha->flags.delete_progress = 1;
3174 qlt_remove_target(ha, vha);
3176 fc_remove_host(vha->host);
3178 scsi_remove_host(vha->host);
3180 /* Allow timer to run to drain queued items, when removing vp */
3181 qla24xx_deallocate_vp_id(vha);
3183 if (vha->timer_active) {
3184 qla2x00_vp_stop_timer(vha);
3185 ql_dbg(ql_dbg_user, vha, 0x7086,
3186 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
3189 qla2x00_free_fcports(vha);
3191 mutex_lock(&ha->vport_lock);
3192 ha->cur_vport_count--;
3193 clear_bit(vha->vp_idx, ha->vp_idx_map);
3194 mutex_unlock(&ha->vport_lock);
3196 dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l,
3203 if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {
3204 if (qla2xxx_delete_qpair(vha, vha->qpair) != QLA_SUCCESS)
3205 ql_log(ql_log_warn, vha, 0x7087,
3206 "Queue Pair delete failed.\n");
3209 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
3210 scsi_host_put(vha->host);
3215 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
3217 scsi_qla_host_t *vha = fc_vport->dd_data;
3220 qla24xx_disable_vp(vha);
3222 qla24xx_enable_vp(vha);
3227 struct fc_function_template qla2xxx_transport_functions = {
3229 .show_host_node_name = 1,
3230 .show_host_port_name = 1,
3231 .show_host_supported_classes = 1,
3232 .show_host_supported_speeds = 1,
3234 .get_host_port_id = qla2x00_get_host_port_id,
3235 .show_host_port_id = 1,
3236 .get_host_speed = qla2x00_get_host_speed,
3237 .show_host_speed = 1,
3238 .get_host_port_type = qla2x00_get_host_port_type,
3239 .show_host_port_type = 1,
3240 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3241 .show_host_symbolic_name = 1,
3242 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3243 .show_host_system_hostname = 1,
3244 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3245 .show_host_fabric_name = 1,
3246 .get_host_port_state = qla2x00_get_host_port_state,
3247 .show_host_port_state = 1,
3249 .dd_fcrport_size = sizeof(struct fc_port *),
3250 .show_rport_supported_classes = 1,
3252 .get_starget_node_name = qla2x00_get_starget_node_name,
3253 .show_starget_node_name = 1,
3254 .get_starget_port_name = qla2x00_get_starget_port_name,
3255 .show_starget_port_name = 1,
3256 .get_starget_port_id = qla2x00_get_starget_port_id,
3257 .show_starget_port_id = 1,
3259 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3260 .show_rport_dev_loss_tmo = 1,
3262 .issue_fc_host_lip = qla2x00_issue_lip,
3263 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3264 .terminate_rport_io = qla2x00_terminate_rport_io,
3265 .get_fc_host_stats = qla2x00_get_fc_host_stats,
3266 .reset_fc_host_stats = qla2x00_reset_host_stats,
3268 .vport_create = qla24xx_vport_create,
3269 .vport_disable = qla24xx_vport_disable,
3270 .vport_delete = qla24xx_vport_delete,
3271 .bsg_request = qla24xx_bsg_request,
3272 .bsg_timeout = qla24xx_bsg_timeout,
3275 struct fc_function_template qla2xxx_transport_vport_functions = {
3277 .show_host_node_name = 1,
3278 .show_host_port_name = 1,
3279 .show_host_supported_classes = 1,
3281 .get_host_port_id = qla2x00_get_host_port_id,
3282 .show_host_port_id = 1,
3283 .get_host_speed = qla2x00_get_host_speed,
3284 .show_host_speed = 1,
3285 .get_host_port_type = qla2x00_get_host_port_type,
3286 .show_host_port_type = 1,
3287 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3288 .show_host_symbolic_name = 1,
3289 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3290 .show_host_system_hostname = 1,
3291 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3292 .show_host_fabric_name = 1,
3293 .get_host_port_state = qla2x00_get_host_port_state,
3294 .show_host_port_state = 1,
3296 .dd_fcrport_size = sizeof(struct fc_port *),
3297 .show_rport_supported_classes = 1,
3299 .get_starget_node_name = qla2x00_get_starget_node_name,
3300 .show_starget_node_name = 1,
3301 .get_starget_port_name = qla2x00_get_starget_port_name,
3302 .show_starget_port_name = 1,
3303 .get_starget_port_id = qla2x00_get_starget_port_id,
3304 .show_starget_port_id = 1,
3306 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3307 .show_rport_dev_loss_tmo = 1,
3309 .issue_fc_host_lip = qla2x00_issue_lip,
3310 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3311 .terminate_rport_io = qla2x00_terminate_rport_io,
3312 .get_fc_host_stats = qla2x00_get_fc_host_stats,
3313 .reset_fc_host_stats = qla2x00_reset_host_stats,
3315 .bsg_request = qla24xx_bsg_request,
3316 .bsg_timeout = qla24xx_bsg_timeout,
3320 qla2x00_init_host_attr(scsi_qla_host_t *vha)
3322 struct qla_hw_data *ha = vha->hw;
3323 u32 speeds = FC_PORTSPEED_UNKNOWN;
3325 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
3326 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3327 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
3328 fc_host_supported_classes(vha->host) = ha->base_qpair->enable_class_2 ?
3329 (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
3330 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
3331 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
3333 speeds = qla25xx_fdmi_port_speed_capability(ha);
3335 fc_host_supported_speeds(vha->host) = speeds;