2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
8 #include "qla_target.h"
10 #include <linux/kthread.h>
11 #include <linux/vmalloc.h>
12 #include <linux/slab.h>
13 #include <linux/delay.h>
15 static int qla24xx_vport_disable(struct fc_vport *, bool);
17 /* SYSFS attributes --------------------------------------------------------- */
20 qla2x00_sysfs_read_fw_dump(struct file *filp, struct kobject *kobj,
21 struct bin_attribute *bin_attr,
22 char *buf, loff_t off, size_t count)
24 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
25 struct device, kobj)));
26 struct qla_hw_data *ha = vha->hw;
29 if (!(ha->fw_dump_reading || ha->mctp_dump_reading))
32 if (IS_P3P_TYPE(ha)) {
33 if (off < ha->md_template_size) {
34 rval = memory_read_from_buffer(buf, count,
35 &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 return memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
45 else if (ha->fw_dump_reading)
46 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
53 qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
54 struct bin_attribute *bin_attr,
55 char *buf, loff_t off, size_t count)
57 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
58 struct device, kobj)));
59 struct qla_hw_data *ha = vha->hw;
65 reading = simple_strtol(buf, NULL, 10);
68 if (!ha->fw_dump_reading)
71 ql_log(ql_log_info, vha, 0x705d,
72 "Firmware dump cleared on (%ld).\n", vha->host_no);
74 if (IS_P3P_TYPE(ha)) {
78 ha->fw_dump_reading = 0;
82 if (ha->fw_dumped && !ha->fw_dump_reading) {
83 ha->fw_dump_reading = 1;
85 ql_log(ql_log_info, vha, 0x705e,
86 "Raw firmware dump ready for read on (%ld).\n",
91 qla2x00_alloc_fw_dump(vha);
96 qla82xx_set_reset_owner(vha);
97 qla82xx_idc_unlock(ha);
98 } else if (IS_QLA8044(ha)) {
100 qla82xx_set_reset_owner(vha);
101 qla8044_idc_unlock(ha);
103 qla2x00_system_error(vha);
106 if (IS_P3P_TYPE(ha)) {
107 if (ha->md_tmplt_hdr)
108 ql_dbg(ql_dbg_user, vha, 0x705b,
109 "MiniDump supported with this firmware.\n");
111 ql_dbg(ql_dbg_user, vha, 0x709d,
112 "MiniDump not supported with this firmware.\n");
117 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
120 if (!ha->mctp_dump_reading)
122 ql_log(ql_log_info, vha, 0x70c1,
123 "MCTP dump cleared on (%ld).\n", vha->host_no);
124 ha->mctp_dump_reading = 0;
128 if (ha->mctp_dumped && !ha->mctp_dump_reading) {
129 ha->mctp_dump_reading = 1;
130 ql_log(ql_log_info, vha, 0x70c2,
131 "Raw mctp dump ready for read on (%ld).\n",
139 static struct bin_attribute sysfs_fw_dump_attr = {
142 .mode = S_IRUSR | S_IWUSR,
145 .read = qla2x00_sysfs_read_fw_dump,
146 .write = qla2x00_sysfs_write_fw_dump,
150 qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
151 struct bin_attribute *bin_attr,
152 char *buf, loff_t off, size_t count)
154 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
155 struct device, kobj)));
156 struct qla_hw_data *ha = vha->hw;
158 if (!capable(CAP_SYS_ADMIN))
161 mutex_lock(&ha->optrom_mutex);
162 if (qla2x00_chip_is_down(vha)) {
163 mutex_unlock(&ha->optrom_mutex);
167 if (IS_NOCACHE_VPD_TYPE(ha))
168 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
170 mutex_unlock(&ha->optrom_mutex);
172 return memory_read_from_buffer(buf, count, &off, ha->nvram,
177 qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
178 struct bin_attribute *bin_attr,
179 char *buf, loff_t off, size_t count)
181 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
182 struct device, kobj)));
183 struct qla_hw_data *ha = vha->hw;
186 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
187 !ha->isp_ops->write_nvram)
190 /* Checksum NVRAM. */
191 if (IS_FWI2_CAPABLE(ha)) {
195 iter = (uint32_t *)buf;
197 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++, iter++)
198 chksum += le32_to_cpu(*iter);
199 chksum = ~chksum + 1;
200 *iter = cpu_to_le32(chksum);
205 iter = (uint8_t *)buf;
207 for (cnt = 0; cnt < count - 1; cnt++)
209 chksum = ~chksum + 1;
213 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
214 ql_log(ql_log_warn, vha, 0x705f,
215 "HBA not online, failing NVRAM update.\n");
219 mutex_lock(&ha->optrom_mutex);
220 if (qla2x00_chip_is_down(vha)) {
221 mutex_unlock(&ha->optrom_mutex);
226 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
227 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
229 mutex_unlock(&ha->optrom_mutex);
231 ql_dbg(ql_dbg_user, vha, 0x7060,
232 "Setting ISP_ABORT_NEEDED\n");
233 /* NVRAM settings take effect immediately. */
234 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
235 qla2xxx_wake_dpc(vha);
236 qla2x00_wait_for_chip_reset(vha);
241 static struct bin_attribute sysfs_nvram_attr = {
244 .mode = S_IRUSR | S_IWUSR,
247 .read = qla2x00_sysfs_read_nvram,
248 .write = qla2x00_sysfs_write_nvram,
252 qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
253 struct bin_attribute *bin_attr,
254 char *buf, loff_t off, size_t count)
256 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
257 struct device, kobj)));
258 struct qla_hw_data *ha = vha->hw;
261 mutex_lock(&ha->optrom_mutex);
263 if (ha->optrom_state != QLA_SREADING)
266 rval = memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
267 ha->optrom_region_size);
270 mutex_unlock(&ha->optrom_mutex);
276 qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
277 struct bin_attribute *bin_attr,
278 char *buf, loff_t off, size_t count)
280 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
281 struct device, kobj)));
282 struct qla_hw_data *ha = vha->hw;
284 mutex_lock(&ha->optrom_mutex);
286 if (ha->optrom_state != QLA_SWRITING) {
287 mutex_unlock(&ha->optrom_mutex);
290 if (off > ha->optrom_region_size) {
291 mutex_unlock(&ha->optrom_mutex);
294 if (off + count > ha->optrom_region_size)
295 count = ha->optrom_region_size - off;
297 memcpy(&ha->optrom_buffer[off], buf, count);
298 mutex_unlock(&ha->optrom_mutex);
303 static struct bin_attribute sysfs_optrom_attr = {
306 .mode = S_IRUSR | S_IWUSR,
309 .read = qla2x00_sysfs_read_optrom,
310 .write = qla2x00_sysfs_write_optrom,
314 qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
315 struct bin_attribute *bin_attr,
316 char *buf, loff_t off, size_t count)
318 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
319 struct device, kobj)));
320 struct qla_hw_data *ha = vha->hw;
322 uint32_t size = ha->optrom_size;
324 ssize_t rval = count;
329 if (unlikely(pci_channel_offline(ha->pdev)))
332 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
334 if (start > ha->optrom_size)
336 if (size > ha->optrom_size - start)
337 size = ha->optrom_size - start;
339 mutex_lock(&ha->optrom_mutex);
340 if (qla2x00_chip_is_down(vha)) {
341 mutex_unlock(&ha->optrom_mutex);
346 if (ha->optrom_state != QLA_SREADING &&
347 ha->optrom_state != QLA_SWRITING) {
351 ha->optrom_state = QLA_SWAITING;
353 ql_dbg(ql_dbg_user, vha, 0x7061,
354 "Freeing flash region allocation -- 0x%x bytes.\n",
355 ha->optrom_region_size);
357 vfree(ha->optrom_buffer);
358 ha->optrom_buffer = NULL;
361 if (ha->optrom_state != QLA_SWAITING) {
366 ha->optrom_region_start = start;
367 ha->optrom_region_size = start + size;
369 ha->optrom_state = QLA_SREADING;
370 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
371 if (ha->optrom_buffer == NULL) {
372 ql_log(ql_log_warn, vha, 0x7062,
373 "Unable to allocate memory for optrom retrieval "
374 "(%x).\n", ha->optrom_region_size);
376 ha->optrom_state = QLA_SWAITING;
381 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
382 ql_log(ql_log_warn, vha, 0x7063,
383 "HBA not online, failing NVRAM update.\n");
388 ql_dbg(ql_dbg_user, vha, 0x7064,
389 "Reading flash region -- 0x%x/0x%x.\n",
390 ha->optrom_region_start, ha->optrom_region_size);
392 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
393 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
394 ha->optrom_region_start, ha->optrom_region_size);
397 if (ha->optrom_state != QLA_SWAITING) {
403 * We need to be more restrictive on which FLASH regions are
404 * allowed to be updated via user-space. Regions accessible
405 * via this method include:
407 * ISP21xx/ISP22xx/ISP23xx type boards:
409 * 0x000000 -> 0x020000 -- Boot code.
411 * ISP2322/ISP24xx type boards:
413 * 0x000000 -> 0x07ffff -- Boot code.
414 * 0x080000 -> 0x0fffff -- Firmware.
416 * ISP25xx type boards:
418 * 0x000000 -> 0x07ffff -- Boot code.
419 * 0x080000 -> 0x0fffff -- Firmware.
420 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
423 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
425 else if (start == (ha->flt_region_boot * 4) ||
426 start == (ha->flt_region_fw * 4))
428 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)
429 || IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)
433 ql_log(ql_log_warn, vha, 0x7065,
434 "Invalid start region 0x%x/0x%x.\n", start, size);
439 ha->optrom_region_start = start;
440 ha->optrom_region_size = start + size;
442 ha->optrom_state = QLA_SWRITING;
443 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
444 if (ha->optrom_buffer == NULL) {
445 ql_log(ql_log_warn, vha, 0x7066,
446 "Unable to allocate memory for optrom update "
447 "(%x)\n", ha->optrom_region_size);
449 ha->optrom_state = QLA_SWAITING;
454 ql_dbg(ql_dbg_user, vha, 0x7067,
455 "Staging flash region write -- 0x%x/0x%x.\n",
456 ha->optrom_region_start, ha->optrom_region_size);
458 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
461 if (ha->optrom_state != QLA_SWRITING) {
466 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
467 ql_log(ql_log_warn, vha, 0x7068,
468 "HBA not online, failing flash update.\n");
473 ql_dbg(ql_dbg_user, vha, 0x7069,
474 "Writing flash region -- 0x%x/0x%x.\n",
475 ha->optrom_region_start, ha->optrom_region_size);
477 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
478 ha->optrom_region_start, ha->optrom_region_size);
485 mutex_unlock(&ha->optrom_mutex);
489 static struct bin_attribute sysfs_optrom_ctl_attr = {
491 .name = "optrom_ctl",
495 .write = qla2x00_sysfs_write_optrom_ctl,
499 qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
500 struct bin_attribute *bin_attr,
501 char *buf, loff_t off, size_t count)
503 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
504 struct device, kobj)));
505 struct qla_hw_data *ha = vha->hw;
508 if (unlikely(pci_channel_offline(ha->pdev)))
511 if (!capable(CAP_SYS_ADMIN))
514 if (IS_NOCACHE_VPD_TYPE(ha)) {
515 faddr = ha->flt_region_vpd << 2;
517 if (IS_QLA27XX(ha) &&
518 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
519 faddr = ha->flt_region_vpd_sec << 2;
521 mutex_lock(&ha->optrom_mutex);
522 if (qla2x00_chip_is_down(vha)) {
523 mutex_unlock(&ha->optrom_mutex);
526 ha->isp_ops->read_optrom(vha, ha->vpd, faddr,
528 mutex_unlock(&ha->optrom_mutex);
530 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
534 qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
535 struct bin_attribute *bin_attr,
536 char *buf, loff_t off, size_t count)
538 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
539 struct device, kobj)));
540 struct qla_hw_data *ha = vha->hw;
543 if (unlikely(pci_channel_offline(ha->pdev)))
546 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
547 !ha->isp_ops->write_nvram)
550 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
551 ql_log(ql_log_warn, vha, 0x706a,
552 "HBA not online, failing VPD update.\n");
556 mutex_lock(&ha->optrom_mutex);
557 if (qla2x00_chip_is_down(vha)) {
558 mutex_unlock(&ha->optrom_mutex);
563 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
564 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
566 /* Update flash version information for 4Gb & above. */
567 if (!IS_FWI2_CAPABLE(ha)) {
568 mutex_unlock(&ha->optrom_mutex);
572 tmp_data = vmalloc(256);
574 mutex_unlock(&ha->optrom_mutex);
575 ql_log(ql_log_warn, vha, 0x706b,
576 "Unable to allocate memory for VPD information update.\n");
579 ha->isp_ops->get_flash_version(vha, tmp_data);
582 mutex_unlock(&ha->optrom_mutex);
587 static struct bin_attribute sysfs_vpd_attr = {
590 .mode = S_IRUSR | S_IWUSR,
593 .read = qla2x00_sysfs_read_vpd,
594 .write = qla2x00_sysfs_write_vpd,
598 qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
599 struct bin_attribute *bin_attr,
600 char *buf, loff_t off, size_t count)
602 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
603 struct device, kobj)));
606 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < SFP_DEV_SIZE)
609 mutex_lock(&vha->hw->optrom_mutex);
610 if (qla2x00_chip_is_down(vha)) {
611 mutex_unlock(&vha->hw->optrom_mutex);
615 rval = qla2x00_read_sfp_dev(vha, buf, count);
616 mutex_unlock(&vha->hw->optrom_mutex);
624 static struct bin_attribute sysfs_sfp_attr = {
627 .mode = S_IRUSR | S_IWUSR,
629 .size = SFP_DEV_SIZE,
630 .read = qla2x00_sysfs_read_sfp,
634 qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
635 struct bin_attribute *bin_attr,
636 char *buf, loff_t off, size_t count)
638 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
639 struct device, kobj)));
640 struct qla_hw_data *ha = vha->hw;
641 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
643 uint32_t idc_control;
644 uint8_t *tmp_data = NULL;
648 type = simple_strtol(buf, NULL, 10);
651 ql_log(ql_log_info, vha, 0x706e,
652 "Issuing ISP reset.\n");
654 scsi_block_requests(vha->host);
655 if (IS_QLA82XX(ha)) {
656 ha->flags.isp82xx_no_md_cap = 1;
657 qla82xx_idc_lock(ha);
658 qla82xx_set_reset_owner(vha);
659 qla82xx_idc_unlock(ha);
660 } else if (IS_QLA8044(ha)) {
661 qla8044_idc_lock(ha);
662 idc_control = qla8044_rd_reg(ha,
663 QLA8044_IDC_DRV_CTRL);
664 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
665 (idc_control | GRACEFUL_RESET_BIT1));
666 qla82xx_set_reset_owner(vha);
667 qla8044_idc_unlock(ha);
669 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
670 qla2xxx_wake_dpc(vha);
672 qla2x00_wait_for_chip_reset(vha);
673 scsi_unblock_requests(vha->host);
676 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
679 ql_log(ql_log_info, vha, 0x706f,
680 "Issuing MPI reset.\n");
682 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
683 uint32_t idc_control;
685 qla83xx_idc_lock(vha, 0);
686 __qla83xx_get_idc_control(vha, &idc_control);
687 idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
688 __qla83xx_set_idc_control(vha, idc_control);
689 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
690 QLA8XXX_DEV_NEED_RESET);
691 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
692 qla83xx_idc_unlock(vha, 0);
695 /* Make sure FC side is not in reset */
696 qla2x00_wait_for_hba_online(vha);
698 /* Issue MPI reset */
699 scsi_block_requests(vha->host);
700 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
701 ql_log(ql_log_warn, vha, 0x7070,
702 "MPI reset failed.\n");
703 scsi_unblock_requests(vha->host);
707 if (!IS_P3P_TYPE(ha) || vha != base_vha) {
708 ql_log(ql_log_info, vha, 0x7071,
709 "FCoE ctx reset not supported.\n");
713 ql_log(ql_log_info, vha, 0x7072,
714 "Issuing FCoE ctx reset.\n");
715 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
716 qla2xxx_wake_dpc(vha);
717 qla2x00_wait_for_fcoe_ctx_reset(vha);
722 ql_log(ql_log_info, vha, 0x70bc,
723 "Disabling Reset by IDC control\n");
724 qla83xx_idc_lock(vha, 0);
725 __qla83xx_get_idc_control(vha, &idc_control);
726 idc_control |= QLA83XX_IDC_RESET_DISABLED;
727 __qla83xx_set_idc_control(vha, idc_control);
728 qla83xx_idc_unlock(vha, 0);
733 ql_log(ql_log_info, vha, 0x70bd,
734 "Enabling Reset by IDC control\n");
735 qla83xx_idc_lock(vha, 0);
736 __qla83xx_get_idc_control(vha, &idc_control);
737 idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
738 __qla83xx_set_idc_control(vha, idc_control);
739 qla83xx_idc_unlock(vha, 0);
742 ql_dbg(ql_dbg_user, vha, 0x70e0,
743 "Updating cache versions without reset ");
745 tmp_data = vmalloc(256);
747 ql_log(ql_log_warn, vha, 0x70e1,
748 "Unable to allocate memory for VPD information update.\n");
751 ha->isp_ops->get_flash_version(vha, tmp_data);
758 static struct bin_attribute sysfs_reset_attr = {
764 .write = qla2x00_sysfs_write_reset,
768 qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
769 struct bin_attribute *bin_attr,
770 char *buf, loff_t off, size_t count)
772 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
773 struct device, kobj)));
777 if (!capable(CAP_SYS_ADMIN))
780 if (unlikely(pci_channel_offline(vha->hw->pdev)))
783 if (qla2x00_chip_is_down(vha))
786 type = simple_strtol(buf, NULL, 10);
788 did.b.domain = (type & 0x00ff0000) >> 16;
789 did.b.area = (type & 0x0000ff00) >> 8;
790 did.b.al_pa = (type & 0x000000ff);
792 ql_log(ql_log_info, vha, 0xd04d, "portid=%02x%02x%02x done\n",
793 did.b.domain, did.b.area, did.b.al_pa);
795 ql_log(ql_log_info, vha, 0x70e4, "%s: %d\n", __func__, type);
797 qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, did);
801 static struct bin_attribute sysfs_issue_logo_attr = {
803 .name = "issue_logo",
807 .write = qla2x00_issue_logo,
811 qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
812 struct bin_attribute *bin_attr,
813 char *buf, loff_t off, size_t count)
815 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
816 struct device, kobj)));
817 struct qla_hw_data *ha = vha->hw;
819 uint16_t actual_size;
821 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
824 if (unlikely(pci_channel_offline(ha->pdev)))
826 mutex_lock(&vha->hw->optrom_mutex);
827 if (qla2x00_chip_is_down(vha)) {
828 mutex_unlock(&vha->hw->optrom_mutex);
835 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
836 &ha->xgmac_data_dma, GFP_KERNEL);
837 if (!ha->xgmac_data) {
838 mutex_unlock(&vha->hw->optrom_mutex);
839 ql_log(ql_log_warn, vha, 0x7076,
840 "Unable to allocate memory for XGMAC read-data.\n");
846 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
848 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
849 XGMAC_DATA_SIZE, &actual_size);
851 mutex_unlock(&vha->hw->optrom_mutex);
852 if (rval != QLA_SUCCESS) {
853 ql_log(ql_log_warn, vha, 0x7077,
854 "Unable to read XGMAC data (%x).\n", rval);
858 count = actual_size > count ? count: actual_size;
859 memcpy(buf, ha->xgmac_data, count);
864 static struct bin_attribute sysfs_xgmac_stats_attr = {
866 .name = "xgmac_stats",
870 .read = qla2x00_sysfs_read_xgmac_stats,
874 qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
875 struct bin_attribute *bin_attr,
876 char *buf, loff_t off, size_t count)
878 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
879 struct device, kobj)));
880 struct qla_hw_data *ha = vha->hw;
883 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
888 mutex_lock(&vha->hw->optrom_mutex);
889 if (qla2x00_chip_is_down(vha)) {
890 mutex_unlock(&vha->hw->optrom_mutex);
894 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
895 &ha->dcbx_tlv_dma, GFP_KERNEL);
897 mutex_unlock(&vha->hw->optrom_mutex);
898 ql_log(ql_log_warn, vha, 0x7078,
899 "Unable to allocate memory for DCBX TLV read-data.\n");
904 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
906 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
909 mutex_unlock(&vha->hw->optrom_mutex);
911 if (rval != QLA_SUCCESS) {
912 ql_log(ql_log_warn, vha, 0x7079,
913 "Unable to read DCBX TLV (%x).\n", rval);
917 memcpy(buf, ha->dcbx_tlv, count);
922 static struct bin_attribute sysfs_dcbx_tlv_attr = {
928 .read = qla2x00_sysfs_read_dcbx_tlv,
931 static struct sysfs_entry {
933 struct bin_attribute *attr;
935 } bin_file_entries[] = {
936 { "fw_dump", &sysfs_fw_dump_attr, },
937 { "nvram", &sysfs_nvram_attr, },
938 { "optrom", &sysfs_optrom_attr, },
939 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
940 { "vpd", &sysfs_vpd_attr, 1 },
941 { "sfp", &sysfs_sfp_attr, 1 },
942 { "reset", &sysfs_reset_attr, },
943 { "issue_logo", &sysfs_issue_logo_attr, },
944 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
945 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
950 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
952 struct Scsi_Host *host = vha->host;
953 struct sysfs_entry *iter;
956 for (iter = bin_file_entries; iter->name; iter++) {
957 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
959 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
961 if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
964 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
967 ql_log(ql_log_warn, vha, 0x00f3,
968 "Unable to create sysfs %s binary attribute (%d).\n",
971 ql_dbg(ql_dbg_init, vha, 0x00f4,
972 "Successfully created sysfs %s binary attribute.\n",
978 qla2x00_free_sysfs_attr(scsi_qla_host_t *vha, bool stop_beacon)
980 struct Scsi_Host *host = vha->host;
981 struct sysfs_entry *iter;
982 struct qla_hw_data *ha = vha->hw;
984 for (iter = bin_file_entries; iter->name; iter++) {
985 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
987 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
989 if (iter->is4GBp_only == 3 && !(IS_CNA_CAPABLE(vha->hw)))
991 if (iter->is4GBp_only == 0x27 && !IS_QLA27XX(vha->hw))
994 sysfs_remove_bin_file(&host->shost_gendev.kobj,
998 if (stop_beacon && ha->beacon_blink_led == 1)
999 ha->isp_ops->beacon_off(vha);
1002 /* Scsi_Host attributes. */
1005 qla2x00_drvr_version_show(struct device *dev,
1006 struct device_attribute *attr, char *buf)
1008 return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
1012 qla2x00_fw_version_show(struct device *dev,
1013 struct device_attribute *attr, char *buf)
1015 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1016 struct qla_hw_data *ha = vha->hw;
1019 return scnprintf(buf, PAGE_SIZE, "%s\n",
1020 ha->isp_ops->fw_version_str(vha, fw_str, sizeof(fw_str)));
1024 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
1027 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1028 struct qla_hw_data *ha = vha->hw;
1031 if (IS_QLAFX00(vha->hw)) {
1032 return scnprintf(buf, PAGE_SIZE, "%s\n",
1033 vha->hw->mr.serial_num);
1034 } else if (IS_FWI2_CAPABLE(ha)) {
1035 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE - 1);
1036 return strlen(strcat(buf, "\n"));
1039 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1040 return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
1045 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
1048 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1049 return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
1053 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
1056 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1057 struct qla_hw_data *ha = vha->hw;
1059 if (IS_QLAFX00(vha->hw))
1060 return scnprintf(buf, PAGE_SIZE, "%s\n",
1061 vha->hw->mr.hw_version);
1063 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
1064 ha->product_id[0], ha->product_id[1], ha->product_id[2],
1069 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
1072 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1074 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
1078 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1081 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1082 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
1086 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1089 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1092 return scnprintf(buf, PAGE_SIZE, "%s\n",
1093 vha->hw->isp_ops->pci_info_str(vha, pci_info));
1097 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1100 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1101 struct qla_hw_data *ha = vha->hw;
1104 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
1105 atomic_read(&vha->loop_state) == LOOP_DEAD ||
1106 vha->device_flags & DFLG_NO_CABLE)
1107 len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
1108 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1109 qla2x00_chip_is_down(vha))
1110 len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1112 len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
1114 switch (ha->current_topology) {
1116 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1119 len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1122 len += scnprintf(buf + len, PAGE_SIZE-len,
1123 "N_Port to N_Port\n");
1126 len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1129 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1137 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1140 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1143 switch (vha->hw->zio_mode) {
1144 case QLA_ZIO_MODE_6:
1145 len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1147 case QLA_ZIO_DISABLED:
1148 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1155 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1156 const char *buf, size_t count)
1158 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1159 struct qla_hw_data *ha = vha->hw;
1163 if (!IS_ZIO_SUPPORTED(ha))
1166 if (sscanf(buf, "%d", &val) != 1)
1170 zio_mode = QLA_ZIO_MODE_6;
1172 zio_mode = QLA_ZIO_DISABLED;
1174 /* Update per-hba values and queue a reset. */
1175 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1176 ha->zio_mode = zio_mode;
1177 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1183 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1186 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1188 return scnprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
1192 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1193 const char *buf, size_t count)
1195 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1199 if (sscanf(buf, "%d", &val) != 1)
1201 if (val > 25500 || val < 100)
1204 zio_timer = (uint16_t)(val / 100);
1205 vha->hw->zio_timer = zio_timer;
1211 qla_zio_threshold_show(struct device *dev, struct device_attribute *attr,
1214 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1216 return scnprintf(buf, PAGE_SIZE, "%d exchanges\n",
1217 vha->hw->last_zio_threshold);
1221 qla_zio_threshold_store(struct device *dev, struct device_attribute *attr,
1222 const char *buf, size_t count)
1224 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1227 if (vha->hw->zio_mode != QLA_ZIO_MODE_6)
1229 if (sscanf(buf, "%d", &val) != 1)
1231 if (val < 0 || val > 256)
1234 atomic_set(&vha->hw->zio_threshold, val);
1239 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1242 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1245 if (vha->hw->beacon_blink_led)
1246 len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1248 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1253 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1254 const char *buf, size_t count)
1256 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1257 struct qla_hw_data *ha = vha->hw;
1261 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1264 if (sscanf(buf, "%d", &val) != 1)
1267 mutex_lock(&vha->hw->optrom_mutex);
1268 if (qla2x00_chip_is_down(vha)) {
1269 mutex_unlock(&vha->hw->optrom_mutex);
1270 ql_log(ql_log_warn, vha, 0x707a,
1271 "Abort ISP active -- ignoring beacon request.\n");
1276 rval = ha->isp_ops->beacon_on(vha);
1278 rval = ha->isp_ops->beacon_off(vha);
1280 if (rval != QLA_SUCCESS)
1283 mutex_unlock(&vha->hw->optrom_mutex);
1289 qla2x00_optrom_bios_version_show(struct device *dev,
1290 struct device_attribute *attr, char *buf)
1292 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1293 struct qla_hw_data *ha = vha->hw;
1294 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1295 ha->bios_revision[0]);
1299 qla2x00_optrom_efi_version_show(struct device *dev,
1300 struct device_attribute *attr, char *buf)
1302 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1303 struct qla_hw_data *ha = vha->hw;
1304 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1305 ha->efi_revision[0]);
1309 qla2x00_optrom_fcode_version_show(struct device *dev,
1310 struct device_attribute *attr, char *buf)
1312 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1313 struct qla_hw_data *ha = vha->hw;
1314 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1315 ha->fcode_revision[0]);
1319 qla2x00_optrom_fw_version_show(struct device *dev,
1320 struct device_attribute *attr, char *buf)
1322 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1323 struct qla_hw_data *ha = vha->hw;
1324 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1325 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1326 ha->fw_revision[3]);
1330 qla2x00_optrom_gold_fw_version_show(struct device *dev,
1331 struct device_attribute *attr, char *buf)
1333 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1334 struct qla_hw_data *ha = vha->hw;
1336 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) && !IS_QLA27XX(ha))
1337 return scnprintf(buf, PAGE_SIZE, "\n");
1339 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1340 ha->gold_fw_version[0], ha->gold_fw_version[1],
1341 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1345 qla2x00_total_isp_aborts_show(struct device *dev,
1346 struct device_attribute *attr, char *buf)
1348 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1349 return scnprintf(buf, PAGE_SIZE, "%d\n",
1350 vha->qla_stats.total_isp_aborts);
1354 qla24xx_84xx_fw_version_show(struct device *dev,
1355 struct device_attribute *attr, char *buf)
1357 int rval = QLA_SUCCESS;
1358 uint16_t status[2] = {0, 0};
1359 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1360 struct qla_hw_data *ha = vha->hw;
1362 if (!IS_QLA84XX(ha))
1363 return scnprintf(buf, PAGE_SIZE, "\n");
1365 if (ha->cs84xx->op_fw_version == 0)
1366 rval = qla84xx_verify_chip(vha, status);
1368 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1369 return scnprintf(buf, PAGE_SIZE, "%u\n",
1370 (uint32_t)ha->cs84xx->op_fw_version);
1372 return scnprintf(buf, PAGE_SIZE, "\n");
1376 qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1379 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1380 struct qla_hw_data *ha = vha->hw;
1382 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
1384 return scnprintf(buf, PAGE_SIZE, "\n");
1386 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
1387 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
1388 ha->mpi_capabilities);
1392 qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1395 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1396 struct qla_hw_data *ha = vha->hw;
1398 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
1399 return scnprintf(buf, PAGE_SIZE, "\n");
1401 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1402 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
1406 qla2x00_flash_block_size_show(struct device *dev,
1407 struct device_attribute *attr, char *buf)
1409 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1410 struct qla_hw_data *ha = vha->hw;
1412 return scnprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1416 qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1419 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1421 if (!IS_CNA_CAPABLE(vha->hw))
1422 return scnprintf(buf, PAGE_SIZE, "\n");
1424 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1428 qla2x00_vn_port_mac_address_show(struct device *dev,
1429 struct device_attribute *attr, char *buf)
1431 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1433 if (!IS_CNA_CAPABLE(vha->hw))
1434 return scnprintf(buf, PAGE_SIZE, "\n");
1436 return scnprintf(buf, PAGE_SIZE, "%pMR\n", vha->fcoe_vn_port_mac);
1440 qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1443 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1445 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1449 qla2x00_thermal_temp_show(struct device *dev,
1450 struct device_attribute *attr, char *buf)
1452 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1456 mutex_lock(&vha->hw->optrom_mutex);
1457 if (qla2x00_chip_is_down(vha)) {
1458 mutex_unlock(&vha->hw->optrom_mutex);
1459 ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
1463 if (vha->hw->flags.eeh_busy) {
1464 mutex_unlock(&vha->hw->optrom_mutex);
1465 ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
1469 rc = qla2x00_get_thermal_temp(vha, &temp);
1470 mutex_unlock(&vha->hw->optrom_mutex);
1471 if (rc == QLA_SUCCESS)
1472 return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
1475 return scnprintf(buf, PAGE_SIZE, "\n");
1479 qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1482 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1483 int rval = QLA_FUNCTION_FAILED;
1487 if (IS_QLAFX00(vha->hw)) {
1488 pstate = qlafx00_fw_state_show(dev, attr, buf);
1489 return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
1492 mutex_lock(&vha->hw->optrom_mutex);
1493 if (qla2x00_chip_is_down(vha)) {
1494 mutex_unlock(&vha->hw->optrom_mutex);
1495 ql_log(ql_log_warn, vha, 0x707c,
1496 "ISP reset active.\n");
1498 } else if (vha->hw->flags.eeh_busy) {
1499 mutex_unlock(&vha->hw->optrom_mutex);
1503 rval = qla2x00_get_firmware_state(vha, state);
1504 mutex_unlock(&vha->hw->optrom_mutex);
1506 if (rval != QLA_SUCCESS) {
1507 memset(state, -1, sizeof(state));
1508 rval = qla2x00_get_firmware_state(vha, state);
1511 return scnprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1512 state[0], state[1], state[2], state[3], state[4], state[5]);
1516 qla2x00_diag_requests_show(struct device *dev,
1517 struct device_attribute *attr, char *buf)
1519 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1521 if (!IS_BIDI_CAPABLE(vha->hw))
1522 return scnprintf(buf, PAGE_SIZE, "\n");
1524 return scnprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
1528 qla2x00_diag_megabytes_show(struct device *dev,
1529 struct device_attribute *attr, char *buf)
1531 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1533 if (!IS_BIDI_CAPABLE(vha->hw))
1534 return scnprintf(buf, PAGE_SIZE, "\n");
1536 return scnprintf(buf, PAGE_SIZE, "%llu\n",
1537 vha->bidi_stats.transfer_bytes >> 20);
1541 qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
1544 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1545 struct qla_hw_data *ha = vha->hw;
1550 else if (IS_P3P_TYPE(ha))
1551 size = ha->md_template_size + ha->md_dump_size;
1553 size = ha->fw_dump_len;
1555 return scnprintf(buf, PAGE_SIZE, "%d\n", size);
1559 qla2x00_allow_cna_fw_dump_show(struct device *dev,
1560 struct device_attribute *attr, char *buf)
1562 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1564 if (!IS_P3P_TYPE(vha->hw))
1565 return scnprintf(buf, PAGE_SIZE, "\n");
1567 return scnprintf(buf, PAGE_SIZE, "%s\n",
1568 vha->hw->allow_cna_fw_dump ? "true" : "false");
1572 qla2x00_allow_cna_fw_dump_store(struct device *dev,
1573 struct device_attribute *attr, const char *buf, size_t count)
1575 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1578 if (!IS_P3P_TYPE(vha->hw))
1581 if (sscanf(buf, "%d", &val) != 1)
1584 vha->hw->allow_cna_fw_dump = val != 0;
1590 qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
1593 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1594 struct qla_hw_data *ha = vha->hw;
1596 if (!IS_QLA27XX(ha))
1597 return scnprintf(buf, PAGE_SIZE, "\n");
1599 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1600 ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
1604 qla2x00_min_link_speed_show(struct device *dev, struct device_attribute *attr,
1607 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1608 struct qla_hw_data *ha = vha->hw;
1610 if (!IS_QLA27XX(ha))
1611 return scnprintf(buf, PAGE_SIZE, "\n");
1613 return scnprintf(buf, PAGE_SIZE, "%s\n",
1614 ha->min_link_speed == 5 ? "32Gps" :
1615 ha->min_link_speed == 4 ? "16Gps" :
1616 ha->min_link_speed == 3 ? "8Gps" :
1617 ha->min_link_speed == 2 ? "4Gps" :
1618 ha->min_link_speed != 0 ? "unknown" : "");
1622 qla2x00_max_speed_sup_show(struct device *dev, struct device_attribute *attr,
1625 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1626 struct qla_hw_data *ha = vha->hw;
1628 if (!IS_QLA27XX(ha))
1629 return scnprintf(buf, PAGE_SIZE, "\n");
1631 return scnprintf(buf, PAGE_SIZE, "%s\n",
1632 ha->max_speed_sup ? "32Gps" : "16Gps");
1638 qlini_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1640 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1643 len += scnprintf(buf + len, PAGE_SIZE-len,
1644 "Supported options: enabled | disabled | dual | exclusive\n");
1647 len += scnprintf(buf + len, PAGE_SIZE-len, "Current selection: ");
1649 switch (vha->qlini_mode) {
1650 case QLA2XXX_INI_MODE_EXCLUSIVE:
1651 len += scnprintf(buf + len, PAGE_SIZE-len,
1652 QLA2XXX_INI_MODE_STR_EXCLUSIVE);
1654 case QLA2XXX_INI_MODE_DISABLED:
1655 len += scnprintf(buf + len, PAGE_SIZE-len,
1656 QLA2XXX_INI_MODE_STR_DISABLED);
1658 case QLA2XXX_INI_MODE_ENABLED:
1659 len += scnprintf(buf + len, PAGE_SIZE-len,
1660 QLA2XXX_INI_MODE_STR_ENABLED);
1662 case QLA2XXX_INI_MODE_DUAL:
1663 len += scnprintf(buf + len, PAGE_SIZE-len,
1664 QLA2XXX_INI_MODE_STR_DUAL);
1667 len += scnprintf(buf + len, PAGE_SIZE-len, "\n");
1672 static char *mode_to_str[] = {
1679 #define NEED_EXCH_OFFLOAD(_exchg) ((_exchg) > FW_DEF_EXCHANGES_CNT)
1680 static int qla_set_ini_mode(scsi_qla_host_t *vha, int op)
1686 MODE_CHANGE_NO_ACTION,
1687 TARGET_STILL_ACTIVE,
1689 int action = NO_ACTION;
1691 u8 eo_toggle = 0; /* exchange offload flipped */
1693 switch (vha->qlini_mode) {
1694 case QLA2XXX_INI_MODE_DISABLED:
1696 case QLA2XXX_INI_MODE_DISABLED:
1697 if (qla_tgt_mode_enabled(vha)) {
1698 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1699 vha->hw->flags.exchoffld_enabled)
1701 if (((vha->ql2xexchoffld !=
1702 vha->u_ql2xexchoffld) &&
1703 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1706 * The number of exchange to be offload
1707 * was tweaked or offload option was
1710 action = MODE_CHANGE_ACCEPT;
1712 action = MODE_CHANGE_NO_ACTION;
1715 action = MODE_CHANGE_NO_ACTION;
1718 case QLA2XXX_INI_MODE_EXCLUSIVE:
1719 if (qla_tgt_mode_enabled(vha)) {
1720 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1721 vha->hw->flags.exchoffld_enabled)
1723 if (((vha->ql2xexchoffld !=
1724 vha->u_ql2xexchoffld) &&
1725 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1728 * The number of exchange to be offload
1729 * was tweaked or offload option was
1732 action = MODE_CHANGE_ACCEPT;
1734 action = MODE_CHANGE_NO_ACTION;
1737 action = MODE_CHANGE_ACCEPT;
1740 case QLA2XXX_INI_MODE_DUAL:
1741 action = MODE_CHANGE_ACCEPT;
1742 /* active_mode is target only, reset it to dual */
1743 if (qla_tgt_mode_enabled(vha)) {
1745 action = MODE_CHANGE_ACCEPT;
1747 action = MODE_CHANGE_NO_ACTION;
1751 case QLA2XXX_INI_MODE_ENABLED:
1752 if (qla_tgt_mode_enabled(vha))
1753 action = TARGET_STILL_ACTIVE;
1755 action = MODE_CHANGE_ACCEPT;
1762 case QLA2XXX_INI_MODE_EXCLUSIVE:
1764 case QLA2XXX_INI_MODE_EXCLUSIVE:
1765 if (qla_tgt_mode_enabled(vha)) {
1766 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1767 vha->hw->flags.exchoffld_enabled)
1769 if (((vha->ql2xexchoffld !=
1770 vha->u_ql2xexchoffld) &&
1771 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1774 * The number of exchange to be offload
1775 * was tweaked or offload option was
1778 action = MODE_CHANGE_ACCEPT;
1786 case QLA2XXX_INI_MODE_DISABLED:
1787 if (qla_tgt_mode_enabled(vha)) {
1788 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1789 vha->hw->flags.exchoffld_enabled)
1791 if (((vha->ql2xexchoffld !=
1792 vha->u_ql2xexchoffld) &&
1793 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1795 action = MODE_CHANGE_ACCEPT;
1797 action = MODE_CHANGE_NO_ACTION;
1799 action = MODE_CHANGE_NO_ACTION;
1802 case QLA2XXX_INI_MODE_DUAL: /* exclusive -> dual */
1803 if (qla_tgt_mode_enabled(vha)) {
1804 action = MODE_CHANGE_ACCEPT;
1807 action = MODE_CHANGE_ACCEPT;
1810 case QLA2XXX_INI_MODE_ENABLED:
1811 if (qla_tgt_mode_enabled(vha))
1812 action = TARGET_STILL_ACTIVE;
1814 if (vha->hw->flags.fw_started)
1815 action = MODE_CHANGE_NO_ACTION;
1817 action = MODE_CHANGE_ACCEPT;
1823 case QLA2XXX_INI_MODE_ENABLED:
1825 case QLA2XXX_INI_MODE_ENABLED:
1826 if (NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg) !=
1827 vha->hw->flags.exchoffld_enabled)
1829 if (((vha->ql2xiniexchg != vha->u_ql2xiniexchg) &&
1830 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg)) ||
1832 action = MODE_CHANGE_ACCEPT;
1836 case QLA2XXX_INI_MODE_DUAL:
1837 case QLA2XXX_INI_MODE_DISABLED:
1838 action = MODE_CHANGE_ACCEPT;
1841 action = MODE_CHANGE_NO_ACTION;
1846 case QLA2XXX_INI_MODE_DUAL:
1848 case QLA2XXX_INI_MODE_DUAL:
1849 if (qla_tgt_mode_enabled(vha) ||
1850 qla_dual_mode_enabled(vha)) {
1851 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
1852 vha->u_ql2xiniexchg) !=
1853 vha->hw->flags.exchoffld_enabled)
1856 if ((((vha->ql2xexchoffld +
1857 vha->ql2xiniexchg) !=
1858 (vha->u_ql2xiniexchg +
1859 vha->u_ql2xexchoffld)) &&
1860 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
1861 vha->u_ql2xexchoffld)) || eo_toggle)
1862 action = MODE_CHANGE_ACCEPT;
1866 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
1867 vha->u_ql2xiniexchg) !=
1868 vha->hw->flags.exchoffld_enabled)
1871 if ((((vha->ql2xexchoffld + vha->ql2xiniexchg)
1872 != (vha->u_ql2xiniexchg +
1873 vha->u_ql2xexchoffld)) &&
1874 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
1875 vha->u_ql2xexchoffld)) || eo_toggle)
1876 action = MODE_CHANGE_NO_ACTION;
1882 case QLA2XXX_INI_MODE_DISABLED:
1883 if (qla_tgt_mode_enabled(vha) ||
1884 qla_dual_mode_enabled(vha)) {
1885 /* turning off initiator mode */
1887 action = MODE_CHANGE_ACCEPT;
1889 action = MODE_CHANGE_NO_ACTION;
1893 case QLA2XXX_INI_MODE_EXCLUSIVE:
1894 if (qla_tgt_mode_enabled(vha) ||
1895 qla_dual_mode_enabled(vha)) {
1897 action = MODE_CHANGE_ACCEPT;
1899 action = MODE_CHANGE_ACCEPT;
1903 case QLA2XXX_INI_MODE_ENABLED:
1904 if (qla_tgt_mode_enabled(vha) ||
1905 qla_dual_mode_enabled(vha)) {
1906 action = TARGET_STILL_ACTIVE;
1908 action = MODE_CHANGE_ACCEPT;
1915 case MODE_CHANGE_ACCEPT:
1916 ql_log(ql_log_warn, vha, 0xffff,
1917 "Mode change accepted. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
1918 mode_to_str[vha->qlini_mode], mode_to_str[op],
1919 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
1920 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
1922 vha->qlini_mode = op;
1923 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
1924 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
1927 vha->flags.online = 1;
1928 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1931 case MODE_CHANGE_NO_ACTION:
1932 ql_log(ql_log_warn, vha, 0xffff,
1933 "Mode is set. No action taken. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
1934 mode_to_str[vha->qlini_mode], mode_to_str[op],
1935 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
1936 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
1937 vha->qlini_mode = op;
1938 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
1939 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
1942 case TARGET_STILL_ACTIVE:
1943 ql_log(ql_log_warn, vha, 0xffff,
1944 "Target Mode is active. Unable to change Mode.\n");
1949 ql_log(ql_log_warn, vha, 0xffff,
1950 "Mode unchange. No action taken. %d|%d pct %d|%d.\n",
1951 vha->qlini_mode, op,
1952 vha->ql2xexchoffld, vha->u_ql2xexchoffld);
1960 qlini_mode_store(struct device *dev, struct device_attribute *attr,
1961 const char *buf, size_t count)
1963 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1969 if (strncasecmp(QLA2XXX_INI_MODE_STR_EXCLUSIVE, buf,
1970 strlen(QLA2XXX_INI_MODE_STR_EXCLUSIVE)) == 0)
1971 ini = QLA2XXX_INI_MODE_EXCLUSIVE;
1972 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DISABLED, buf,
1973 strlen(QLA2XXX_INI_MODE_STR_DISABLED)) == 0)
1974 ini = QLA2XXX_INI_MODE_DISABLED;
1975 else if (strncasecmp(QLA2XXX_INI_MODE_STR_ENABLED, buf,
1976 strlen(QLA2XXX_INI_MODE_STR_ENABLED)) == 0)
1977 ini = QLA2XXX_INI_MODE_ENABLED;
1978 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DUAL, buf,
1979 strlen(QLA2XXX_INI_MODE_STR_DUAL)) == 0)
1980 ini = QLA2XXX_INI_MODE_DUAL;
1984 qla_set_ini_mode(vha, ini);
1989 ql2xexchoffld_show(struct device *dev, struct device_attribute *attr,
1992 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1995 len += scnprintf(buf + len, PAGE_SIZE-len,
1996 "target exchange: new %d : current: %d\n\n",
1997 vha->u_ql2xexchoffld, vha->ql2xexchoffld);
1999 len += scnprintf(buf + len, PAGE_SIZE-len,
2000 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2007 ql2xexchoffld_store(struct device *dev, struct device_attribute *attr,
2008 const char *buf, size_t count)
2010 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2013 if (sscanf(buf, "%d", &val) != 1)
2016 if (val > FW_MAX_EXCHANGES_CNT)
2017 val = FW_MAX_EXCHANGES_CNT;
2021 vha->u_ql2xexchoffld = val;
2026 ql2xiniexchg_show(struct device *dev, struct device_attribute *attr,
2029 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2032 len += scnprintf(buf + len, PAGE_SIZE-len,
2033 "target exchange: new %d : current: %d\n\n",
2034 vha->u_ql2xiniexchg, vha->ql2xiniexchg);
2036 len += scnprintf(buf + len, PAGE_SIZE-len,
2037 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2044 ql2xiniexchg_store(struct device *dev, struct device_attribute *attr,
2045 const char *buf, size_t count)
2047 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2050 if (sscanf(buf, "%d", &val) != 1)
2053 if (val > FW_MAX_EXCHANGES_CNT)
2054 val = FW_MAX_EXCHANGES_CNT;
2058 vha->u_ql2xiniexchg = val;
2062 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
2063 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
2064 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
2065 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
2066 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
2067 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
2068 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
2069 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
2070 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
2071 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
2072 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
2073 qla2x00_zio_timer_store);
2074 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
2075 qla2x00_beacon_store);
2076 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
2077 qla2x00_optrom_bios_version_show, NULL);
2078 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
2079 qla2x00_optrom_efi_version_show, NULL);
2080 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
2081 qla2x00_optrom_fcode_version_show, NULL);
2082 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
2084 static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
2085 qla2x00_optrom_gold_fw_version_show, NULL);
2086 static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
2088 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
2090 static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
2091 static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
2092 static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
2094 static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
2095 static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
2096 qla2x00_vn_port_mac_address_show, NULL);
2097 static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
2098 static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
2099 static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
2100 static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
2101 static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
2102 static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
2103 static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
2104 qla2x00_allow_cna_fw_dump_show,
2105 qla2x00_allow_cna_fw_dump_store);
2106 static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
2107 static DEVICE_ATTR(min_link_speed, S_IRUGO, qla2x00_min_link_speed_show, NULL);
2108 static DEVICE_ATTR(max_speed_sup, S_IRUGO, qla2x00_max_speed_sup_show, NULL);
2109 static DEVICE_ATTR(zio_threshold, 0644,
2110 qla_zio_threshold_show,
2111 qla_zio_threshold_store);
2112 static DEVICE_ATTR_RW(qlini_mode);
2113 static DEVICE_ATTR_RW(ql2xexchoffld);
2114 static DEVICE_ATTR_RW(ql2xiniexchg);
2117 struct device_attribute *qla2x00_host_attrs[] = {
2118 &dev_attr_driver_version,
2119 &dev_attr_fw_version,
2120 &dev_attr_serial_num,
2123 &dev_attr_model_name,
2124 &dev_attr_model_desc,
2126 &dev_attr_link_state,
2128 &dev_attr_zio_timer,
2130 &dev_attr_optrom_bios_version,
2131 &dev_attr_optrom_efi_version,
2132 &dev_attr_optrom_fcode_version,
2133 &dev_attr_optrom_fw_version,
2134 &dev_attr_84xx_fw_version,
2135 &dev_attr_total_isp_aborts,
2136 &dev_attr_mpi_version,
2137 &dev_attr_phy_version,
2138 &dev_attr_flash_block_size,
2140 &dev_attr_vn_port_mac_address,
2141 &dev_attr_fabric_param,
2143 &dev_attr_optrom_gold_fw_version,
2144 &dev_attr_thermal_temp,
2145 &dev_attr_diag_requests,
2146 &dev_attr_diag_megabytes,
2147 &dev_attr_fw_dump_size,
2148 &dev_attr_allow_cna_fw_dump,
2149 &dev_attr_pep_version,
2150 &dev_attr_min_link_speed,
2151 &dev_attr_max_speed_sup,
2152 &dev_attr_zio_threshold,
2153 NULL, /* reserve for qlini_mode */
2154 NULL, /* reserve for ql2xiniexchg */
2155 NULL, /* reserve for ql2xexchoffld */
2159 void qla_insert_tgt_attrs(void)
2161 struct device_attribute **attr;
2163 /* advance to empty slot */
2164 for (attr = &qla2x00_host_attrs[0]; *attr; ++attr)
2167 *attr = &dev_attr_qlini_mode;
2169 *attr = &dev_attr_ql2xiniexchg;
2171 *attr = &dev_attr_ql2xexchoffld;
2174 /* Host attributes. */
2177 qla2x00_get_host_port_id(struct Scsi_Host *shost)
2179 scsi_qla_host_t *vha = shost_priv(shost);
2181 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
2182 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
2186 qla2x00_get_host_speed(struct Scsi_Host *shost)
2188 struct qla_hw_data *ha = ((struct scsi_qla_host *)
2189 (shost_priv(shost)))->hw;
2190 u32 speed = FC_PORTSPEED_UNKNOWN;
2192 if (IS_QLAFX00(ha)) {
2193 qlafx00_get_host_speed(shost);
2197 switch (ha->link_data_rate) {
2198 case PORT_SPEED_1GB:
2199 speed = FC_PORTSPEED_1GBIT;
2201 case PORT_SPEED_2GB:
2202 speed = FC_PORTSPEED_2GBIT;
2204 case PORT_SPEED_4GB:
2205 speed = FC_PORTSPEED_4GBIT;
2207 case PORT_SPEED_8GB:
2208 speed = FC_PORTSPEED_8GBIT;
2210 case PORT_SPEED_10GB:
2211 speed = FC_PORTSPEED_10GBIT;
2213 case PORT_SPEED_16GB:
2214 speed = FC_PORTSPEED_16GBIT;
2216 case PORT_SPEED_32GB:
2217 speed = FC_PORTSPEED_32GBIT;
2220 fc_host_speed(shost) = speed;
2224 qla2x00_get_host_port_type(struct Scsi_Host *shost)
2226 scsi_qla_host_t *vha = shost_priv(shost);
2227 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
2230 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2233 switch (vha->hw->current_topology) {
2235 port_type = FC_PORTTYPE_LPORT;
2238 port_type = FC_PORTTYPE_NLPORT;
2241 port_type = FC_PORTTYPE_PTP;
2244 port_type = FC_PORTTYPE_NPORT;
2247 fc_host_port_type(shost) = port_type;
2251 qla2x00_get_starget_node_name(struct scsi_target *starget)
2253 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2254 scsi_qla_host_t *vha = shost_priv(host);
2258 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2259 if (fcport->rport &&
2260 starget->id == fcport->rport->scsi_target_id) {
2261 node_name = wwn_to_u64(fcport->node_name);
2266 fc_starget_node_name(starget) = node_name;
2270 qla2x00_get_starget_port_name(struct scsi_target *starget)
2272 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2273 scsi_qla_host_t *vha = shost_priv(host);
2277 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2278 if (fcport->rport &&
2279 starget->id == fcport->rport->scsi_target_id) {
2280 port_name = wwn_to_u64(fcport->port_name);
2285 fc_starget_port_name(starget) = port_name;
2289 qla2x00_get_starget_port_id(struct scsi_target *starget)
2291 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2292 scsi_qla_host_t *vha = shost_priv(host);
2294 uint32_t port_id = ~0U;
2296 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2297 if (fcport->rport &&
2298 starget->id == fcport->rport->scsi_target_id) {
2299 port_id = fcport->d_id.b.domain << 16 |
2300 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2305 fc_starget_port_id(starget) = port_id;
2309 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2312 rport->dev_loss_tmo = timeout;
2314 rport->dev_loss_tmo = 1;
2318 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
2320 struct Scsi_Host *host = rport_to_shost(rport);
2321 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2322 unsigned long flags;
2327 /* Now that the rport has been deleted, set the fcport state to
2329 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
2332 * Transport has effectively 'deleted' the rport, clear
2333 * all local references.
2335 spin_lock_irqsave(host->host_lock, flags);
2336 fcport->rport = fcport->drport = NULL;
2337 *((fc_port_t **)rport->dd_data) = NULL;
2338 spin_unlock_irqrestore(host->host_lock, flags);
2340 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2343 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2344 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2350 qla2x00_terminate_rport_io(struct fc_rport *rport)
2352 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2357 if (test_bit(UNLOADING, &fcport->vha->dpc_flags))
2360 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2363 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2364 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2368 * At this point all fcport's software-states are cleared. Perform any
2369 * final cleanup of firmware resources (PCBs and XCBs).
2371 if (fcport->loop_id != FC_NO_LOOP_ID) {
2372 if (IS_FWI2_CAPABLE(fcport->vha->hw))
2373 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
2374 fcport->loop_id, fcport->d_id.b.domain,
2375 fcport->d_id.b.area, fcport->d_id.b.al_pa);
2377 qla2x00_port_logout(fcport->vha, fcport);
2382 qla2x00_issue_lip(struct Scsi_Host *shost)
2384 scsi_qla_host_t *vha = shost_priv(shost);
2386 if (IS_QLAFX00(vha->hw))
2389 qla2x00_loop_reset(vha);
2393 static struct fc_host_statistics *
2394 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
2396 scsi_qla_host_t *vha = shost_priv(shost);
2397 struct qla_hw_data *ha = vha->hw;
2398 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2400 struct link_statistics *stats;
2401 dma_addr_t stats_dma;
2402 struct fc_host_statistics *p = &vha->fc_host_stat;
2404 memset(p, -1, sizeof(*p));
2406 if (IS_QLAFX00(vha->hw))
2409 if (test_bit(UNLOADING, &vha->dpc_flags))
2412 if (unlikely(pci_channel_offline(ha->pdev)))
2415 if (qla2x00_chip_is_down(vha))
2418 stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2421 ql_log(ql_log_warn, vha, 0x707d,
2422 "Failed to allocate memory for stats.\n");
2426 rval = QLA_FUNCTION_FAILED;
2427 if (IS_FWI2_CAPABLE(ha)) {
2428 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, 0);
2429 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
2431 /* Must be in a 'READY' state for statistics retrieval. */
2432 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
2436 if (rval != QLA_SUCCESS)
2439 p->link_failure_count = stats->link_fail_cnt;
2440 p->loss_of_sync_count = stats->loss_sync_cnt;
2441 p->loss_of_signal_count = stats->loss_sig_cnt;
2442 p->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
2443 p->invalid_tx_word_count = stats->inval_xmit_word_cnt;
2444 p->invalid_crc_count = stats->inval_crc_cnt;
2445 if (IS_FWI2_CAPABLE(ha)) {
2446 p->lip_count = stats->lip_cnt;
2447 p->tx_frames = stats->tx_frames;
2448 p->rx_frames = stats->rx_frames;
2449 p->dumped_frames = stats->discarded_frames;
2450 p->nos_count = stats->nos_rcvd;
2452 stats->dropped_frames + stats->discarded_frames;
2453 p->rx_words = vha->qla_stats.input_bytes;
2454 p->tx_words = vha->qla_stats.output_bytes;
2456 p->fcp_control_requests = vha->qla_stats.control_requests;
2457 p->fcp_input_requests = vha->qla_stats.input_requests;
2458 p->fcp_output_requests = vha->qla_stats.output_requests;
2459 p->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
2460 p->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
2461 p->seconds_since_last_reset =
2462 get_jiffies_64() - vha->qla_stats.jiffies_at_last_reset;
2463 do_div(p->seconds_since_last_reset, HZ);
2466 dma_free_coherent(&ha->pdev->dev, sizeof(struct link_statistics),
2473 qla2x00_reset_host_stats(struct Scsi_Host *shost)
2475 scsi_qla_host_t *vha = shost_priv(shost);
2476 struct qla_hw_data *ha = vha->hw;
2477 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2478 struct link_statistics *stats;
2479 dma_addr_t stats_dma;
2481 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2482 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2484 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2486 if (IS_FWI2_CAPABLE(ha)) {
2487 stats = dma_alloc_coherent(&ha->pdev->dev,
2488 sizeof(*stats), &stats_dma, GFP_KERNEL);
2490 ql_log(ql_log_warn, vha, 0x70d7,
2491 "Failed to allocate memory for stats.\n");
2495 /* reset firmware statistics */
2496 qla24xx_get_isp_stats(base_vha, stats, stats_dma, BIT_0);
2498 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2504 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
2506 scsi_qla_host_t *vha = shost_priv(shost);
2508 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost),
2509 sizeof(fc_host_symbolic_name(shost)));
2513 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
2515 scsi_qla_host_t *vha = shost_priv(shost);
2517 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
2521 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
2523 scsi_qla_host_t *vha = shost_priv(shost);
2524 uint8_t node_name[WWN_SIZE] = { 0xFF, 0xFF, 0xFF, 0xFF, \
2525 0xFF, 0xFF, 0xFF, 0xFF};
2526 u64 fabric_name = wwn_to_u64(node_name);
2528 if (vha->device_flags & SWITCH_FOUND)
2529 fabric_name = wwn_to_u64(vha->fabric_node_name);
2531 fc_host_fabric_name(shost) = fabric_name;
2535 qla2x00_get_host_port_state(struct Scsi_Host *shost)
2537 scsi_qla_host_t *vha = shost_priv(shost);
2538 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
2540 if (!base_vha->flags.online) {
2541 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2545 switch (atomic_read(&base_vha->loop_state)) {
2547 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2550 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
2551 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2553 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2556 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2559 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2562 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2568 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
2572 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
2573 scsi_qla_host_t *vha = NULL;
2574 struct qla_hw_data *ha = base_vha->hw;
2576 struct req_que *req = ha->req_q_map[0];
2577 struct qla_qpair *qpair;
2579 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
2581 ql_log(ql_log_warn, vha, 0x707e,
2582 "Vport sanity check failed, status %x\n", ret);
2586 vha = qla24xx_create_vhost(fc_vport);
2588 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
2589 return FC_VPORT_FAILED;
2592 atomic_set(&vha->vp_state, VP_OFFLINE);
2593 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
2595 atomic_set(&vha->vp_state, VP_FAILED);
2597 /* ready to create vport */
2598 ql_log(ql_log_info, vha, 0x7080,
2599 "VP entry id %d assigned.\n", vha->vp_idx);
2601 /* initialized vport states */
2602 atomic_set(&vha->loop_state, LOOP_DOWN);
2603 vha->vp_err_state= VP_ERR_PORTDWN;
2604 vha->vp_prev_err_state= VP_ERR_UNKWN;
2605 /* Check if physical ha port is Up */
2606 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
2607 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
2608 /* Don't retry or attempt login of this virtual port */
2609 ql_dbg(ql_dbg_user, vha, 0x7081,
2610 "Vport loop state is not UP.\n");
2611 atomic_set(&vha->loop_state, LOOP_DEAD);
2613 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
2616 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
2617 if (ha->fw_attributes & BIT_4) {
2618 int prot = 0, guard;
2619 vha->flags.difdix_supported = 1;
2620 ql_dbg(ql_dbg_user, vha, 0x7082,
2621 "Registered for DIF/DIX type 1 and 3 protection.\n");
2622 if (ql2xenabledif == 1)
2623 prot = SHOST_DIX_TYPE0_PROTECTION;
2624 scsi_host_set_prot(vha->host,
2625 prot | SHOST_DIF_TYPE1_PROTECTION
2626 | SHOST_DIF_TYPE2_PROTECTION
2627 | SHOST_DIF_TYPE3_PROTECTION
2628 | SHOST_DIX_TYPE1_PROTECTION
2629 | SHOST_DIX_TYPE2_PROTECTION
2630 | SHOST_DIX_TYPE3_PROTECTION);
2632 guard = SHOST_DIX_GUARD_CRC;
2634 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2635 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2636 guard |= SHOST_DIX_GUARD_IP;
2638 scsi_host_set_guard(vha->host, guard);
2640 vha->flags.difdix_supported = 0;
2643 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
2645 ql_dbg(ql_dbg_user, vha, 0x7083,
2646 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
2647 goto vport_create_failed_2;
2650 /* initialize attributes */
2651 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
2652 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2653 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
2654 fc_host_supported_classes(vha->host) =
2655 fc_host_supported_classes(base_vha->host);
2656 fc_host_supported_speeds(vha->host) =
2657 fc_host_supported_speeds(base_vha->host);
2659 qlt_vport_create(vha, ha);
2660 qla24xx_vport_disable(fc_vport, disable);
2662 if (!ql2xmqsupport || !ha->npiv_info)
2665 /* Create a request queue in QoS mode for the vport */
2666 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
2667 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
2668 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
2670 qos = ha->npiv_info[cnt].q_qos;
2676 qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx, true);
2678 ql_log(ql_log_warn, vha, 0x7084,
2679 "Can't create qpair for VP[%d]\n",
2682 ql_dbg(ql_dbg_multiq, vha, 0xc001,
2683 "Queue pair: %d Qos: %d) created for VP[%d]\n",
2684 qpair->id, qos, vha->vp_idx);
2685 ql_dbg(ql_dbg_user, vha, 0x7085,
2686 "Queue Pair: %d Qos: %d) created for VP[%d]\n",
2687 qpair->id, qos, vha->vp_idx);
2697 vport_create_failed_2:
2698 qla24xx_disable_vp(vha);
2699 qla24xx_deallocate_vp_id(vha);
2700 scsi_host_put(vha->host);
2701 return FC_VPORT_FAILED;
2705 qla24xx_vport_delete(struct fc_vport *fc_vport)
2707 scsi_qla_host_t *vha = fc_vport->dd_data;
2708 struct qla_hw_data *ha = vha->hw;
2709 uint16_t id = vha->vp_idx;
2711 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
2712 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
2715 qla_nvme_delete(vha);
2717 qla24xx_disable_vp(vha);
2718 qla2x00_wait_for_sess_deletion(vha);
2720 vha->flags.delete_progress = 1;
2722 qlt_remove_target(ha, vha);
2724 fc_remove_host(vha->host);
2726 scsi_remove_host(vha->host);
2728 /* Allow timer to run to drain queued items, when removing vp */
2729 qla24xx_deallocate_vp_id(vha);
2731 if (vha->timer_active) {
2732 qla2x00_vp_stop_timer(vha);
2733 ql_dbg(ql_dbg_user, vha, 0x7086,
2734 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
2737 qla2x00_free_fcports(vha);
2739 mutex_lock(&ha->vport_lock);
2740 ha->cur_vport_count--;
2741 clear_bit(vha->vp_idx, ha->vp_idx_map);
2742 mutex_unlock(&ha->vport_lock);
2744 dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l,
2749 if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {
2750 if (qla2xxx_delete_qpair(vha, vha->qpair) != QLA_SUCCESS)
2751 ql_log(ql_log_warn, vha, 0x7087,
2752 "Queue Pair delete failed.\n");
2755 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
2756 scsi_host_put(vha->host);
2761 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
2763 scsi_qla_host_t *vha = fc_vport->dd_data;
2766 qla24xx_disable_vp(vha);
2768 qla24xx_enable_vp(vha);
2773 struct fc_function_template qla2xxx_transport_functions = {
2775 .show_host_node_name = 1,
2776 .show_host_port_name = 1,
2777 .show_host_supported_classes = 1,
2778 .show_host_supported_speeds = 1,
2780 .get_host_port_id = qla2x00_get_host_port_id,
2781 .show_host_port_id = 1,
2782 .get_host_speed = qla2x00_get_host_speed,
2783 .show_host_speed = 1,
2784 .get_host_port_type = qla2x00_get_host_port_type,
2785 .show_host_port_type = 1,
2786 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
2787 .show_host_symbolic_name = 1,
2788 .set_host_system_hostname = qla2x00_set_host_system_hostname,
2789 .show_host_system_hostname = 1,
2790 .get_host_fabric_name = qla2x00_get_host_fabric_name,
2791 .show_host_fabric_name = 1,
2792 .get_host_port_state = qla2x00_get_host_port_state,
2793 .show_host_port_state = 1,
2795 .dd_fcrport_size = sizeof(struct fc_port *),
2796 .show_rport_supported_classes = 1,
2798 .get_starget_node_name = qla2x00_get_starget_node_name,
2799 .show_starget_node_name = 1,
2800 .get_starget_port_name = qla2x00_get_starget_port_name,
2801 .show_starget_port_name = 1,
2802 .get_starget_port_id = qla2x00_get_starget_port_id,
2803 .show_starget_port_id = 1,
2805 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
2806 .show_rport_dev_loss_tmo = 1,
2808 .issue_fc_host_lip = qla2x00_issue_lip,
2809 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
2810 .terminate_rport_io = qla2x00_terminate_rport_io,
2811 .get_fc_host_stats = qla2x00_get_fc_host_stats,
2812 .reset_fc_host_stats = qla2x00_reset_host_stats,
2814 .vport_create = qla24xx_vport_create,
2815 .vport_disable = qla24xx_vport_disable,
2816 .vport_delete = qla24xx_vport_delete,
2817 .bsg_request = qla24xx_bsg_request,
2818 .bsg_timeout = qla24xx_bsg_timeout,
2821 struct fc_function_template qla2xxx_transport_vport_functions = {
2823 .show_host_node_name = 1,
2824 .show_host_port_name = 1,
2825 .show_host_supported_classes = 1,
2827 .get_host_port_id = qla2x00_get_host_port_id,
2828 .show_host_port_id = 1,
2829 .get_host_speed = qla2x00_get_host_speed,
2830 .show_host_speed = 1,
2831 .get_host_port_type = qla2x00_get_host_port_type,
2832 .show_host_port_type = 1,
2833 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
2834 .show_host_symbolic_name = 1,
2835 .set_host_system_hostname = qla2x00_set_host_system_hostname,
2836 .show_host_system_hostname = 1,
2837 .get_host_fabric_name = qla2x00_get_host_fabric_name,
2838 .show_host_fabric_name = 1,
2839 .get_host_port_state = qla2x00_get_host_port_state,
2840 .show_host_port_state = 1,
2842 .dd_fcrport_size = sizeof(struct fc_port *),
2843 .show_rport_supported_classes = 1,
2845 .get_starget_node_name = qla2x00_get_starget_node_name,
2846 .show_starget_node_name = 1,
2847 .get_starget_port_name = qla2x00_get_starget_port_name,
2848 .show_starget_port_name = 1,
2849 .get_starget_port_id = qla2x00_get_starget_port_id,
2850 .show_starget_port_id = 1,
2852 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
2853 .show_rport_dev_loss_tmo = 1,
2855 .issue_fc_host_lip = qla2x00_issue_lip,
2856 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
2857 .terminate_rport_io = qla2x00_terminate_rport_io,
2858 .get_fc_host_stats = qla2x00_get_fc_host_stats,
2859 .reset_fc_host_stats = qla2x00_reset_host_stats,
2861 .bsg_request = qla24xx_bsg_request,
2862 .bsg_timeout = qla24xx_bsg_timeout,
2866 qla2x00_init_host_attr(scsi_qla_host_t *vha)
2868 struct qla_hw_data *ha = vha->hw;
2869 u32 speed = FC_PORTSPEED_UNKNOWN;
2871 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
2872 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2873 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
2874 fc_host_supported_classes(vha->host) = ha->base_qpair->enable_class_2 ?
2875 (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
2876 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
2877 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
2879 if (IS_CNA_CAPABLE(ha))
2880 speed = FC_PORTSPEED_10GBIT;
2881 else if (IS_QLA2031(ha))
2882 speed = FC_PORTSPEED_16GBIT | FC_PORTSPEED_8GBIT |
2884 else if (IS_QLA25XX(ha))
2885 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
2886 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2887 else if (IS_QLA24XX_TYPE(ha))
2888 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
2890 else if (IS_QLA23XX(ha))
2891 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2892 else if (IS_QLAFX00(ha))
2893 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
2894 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2895 else if (IS_QLA27XX(ha))
2896 speed = FC_PORTSPEED_32GBIT | FC_PORTSPEED_16GBIT |
2899 speed = FC_PORTSPEED_1GBIT;
2900 fc_host_supported_speeds(vha->host) = speed;