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 ||
30 ha->mpi_fw_dump_reading))
33 mutex_lock(&ha->optrom_mutex);
34 if (IS_P3P_TYPE(ha)) {
35 if (off < ha->md_template_size) {
36 rval = memory_read_from_buffer(buf, count,
37 &off, ha->md_tmplt_hdr, ha->md_template_size);
39 off -= ha->md_template_size;
40 rval = memory_read_from_buffer(buf, count,
41 &off, ha->md_dump, ha->md_dump_size);
43 } else if (ha->mctp_dumped && ha->mctp_dump_reading) {
44 rval = memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
46 } else if (ha->mpi_fw_dumped && ha->mpi_fw_dump_reading) {
47 rval = memory_read_from_buffer(buf, count, &off,
50 } else if (ha->fw_dump_reading) {
51 rval = memory_read_from_buffer(buf, count, &off, ha->fw_dump,
56 mutex_unlock(&ha->optrom_mutex);
61 qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
62 struct bin_attribute *bin_attr,
63 char *buf, loff_t off, size_t count)
65 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
66 struct device, kobj)));
67 struct qla_hw_data *ha = vha->hw;
73 reading = simple_strtol(buf, NULL, 10);
76 if (!ha->fw_dump_reading)
79 ql_log(ql_log_info, vha, 0x705d,
80 "Firmware dump cleared on (%ld).\n", vha->host_no);
82 if (IS_P3P_TYPE(ha)) {
86 ha->fw_dump_reading = 0;
87 ha->fw_dumped = false;
90 if (ha->fw_dumped && !ha->fw_dump_reading) {
91 ha->fw_dump_reading = 1;
93 ql_log(ql_log_info, vha, 0x705e,
94 "Raw firmware dump ready for read on (%ld).\n",
99 qla2x00_alloc_fw_dump(vha);
102 if (IS_QLA82XX(ha)) {
103 qla82xx_idc_lock(ha);
104 qla82xx_set_reset_owner(vha);
105 qla82xx_idc_unlock(ha);
106 } else if (IS_QLA8044(ha)) {
107 qla8044_idc_lock(ha);
108 qla82xx_set_reset_owner(vha);
109 qla8044_idc_unlock(ha);
111 qla2x00_system_error(vha);
115 if (IS_P3P_TYPE(ha)) {
116 if (ha->md_tmplt_hdr)
117 ql_dbg(ql_dbg_user, vha, 0x705b,
118 "MiniDump supported with this firmware.\n");
120 ql_dbg(ql_dbg_user, vha, 0x709d,
121 "MiniDump not supported with this firmware.\n");
126 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
129 if (!ha->mctp_dump_reading)
131 ql_log(ql_log_info, vha, 0x70c1,
132 "MCTP dump cleared on (%ld).\n", vha->host_no);
133 ha->mctp_dump_reading = 0;
137 if (ha->mctp_dumped && !ha->mctp_dump_reading) {
138 ha->mctp_dump_reading = 1;
139 ql_log(ql_log_info, vha, 0x70c2,
140 "Raw mctp dump ready for read on (%ld).\n",
145 if (!ha->mpi_fw_dump_reading)
147 ql_log(ql_log_info, vha, 0x70e7,
148 "MPI firmware dump cleared on (%ld).\n", vha->host_no);
149 ha->mpi_fw_dump_reading = 0;
150 ha->mpi_fw_dumped = 0;
153 if (ha->mpi_fw_dumped && !ha->mpi_fw_dump_reading) {
154 ha->mpi_fw_dump_reading = 1;
155 ql_log(ql_log_info, vha, 0x70e8,
156 "Raw MPI firmware dump ready for read on (%ld).\n",
164 static struct bin_attribute sysfs_fw_dump_attr = {
167 .mode = S_IRUSR | S_IWUSR,
170 .read = qla2x00_sysfs_read_fw_dump,
171 .write = qla2x00_sysfs_write_fw_dump,
175 qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
176 struct bin_attribute *bin_attr,
177 char *buf, loff_t off, size_t count)
179 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
180 struct device, kobj)));
181 struct qla_hw_data *ha = vha->hw;
183 struct active_regions active_regions = { };
185 if (!capable(CAP_SYS_ADMIN))
188 mutex_lock(&ha->optrom_mutex);
189 if (qla2x00_chip_is_down(vha)) {
190 mutex_unlock(&ha->optrom_mutex);
194 if (!IS_NOCACHE_VPD_TYPE(ha)) {
195 mutex_unlock(&ha->optrom_mutex);
199 faddr = ha->flt_region_nvram;
200 if (IS_QLA28XX(ha)) {
201 qla28xx_get_aux_images(vha, &active_regions);
202 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
203 faddr = ha->flt_region_nvram_sec;
205 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
207 mutex_unlock(&ha->optrom_mutex);
210 return memory_read_from_buffer(buf, count, &off, ha->nvram,
215 qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
216 struct bin_attribute *bin_attr,
217 char *buf, loff_t off, size_t count)
219 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
220 struct device, kobj)));
221 struct qla_hw_data *ha = vha->hw;
224 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
225 !ha->isp_ops->write_nvram)
228 /* Checksum NVRAM. */
229 if (IS_FWI2_CAPABLE(ha)) {
230 __le32 *iter = (__force __le32 *)buf;
234 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++, iter++)
235 chksum += le32_to_cpu(*iter);
236 chksum = ~chksum + 1;
237 *iter = cpu_to_le32(chksum);
242 iter = (uint8_t *)buf;
244 for (cnt = 0; cnt < count - 1; cnt++)
246 chksum = ~chksum + 1;
250 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
251 ql_log(ql_log_warn, vha, 0x705f,
252 "HBA not online, failing NVRAM update.\n");
256 mutex_lock(&ha->optrom_mutex);
257 if (qla2x00_chip_is_down(vha)) {
258 mutex_unlock(&ha->optrom_mutex);
263 ha->isp_ops->write_nvram(vha, buf, ha->nvram_base, count);
264 ha->isp_ops->read_nvram(vha, ha->nvram, ha->nvram_base,
266 mutex_unlock(&ha->optrom_mutex);
268 ql_dbg(ql_dbg_user, vha, 0x7060,
269 "Setting ISP_ABORT_NEEDED\n");
270 /* NVRAM settings take effect immediately. */
271 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
272 qla2xxx_wake_dpc(vha);
273 qla2x00_wait_for_chip_reset(vha);
278 static struct bin_attribute sysfs_nvram_attr = {
281 .mode = S_IRUSR | S_IWUSR,
284 .read = qla2x00_sysfs_read_nvram,
285 .write = qla2x00_sysfs_write_nvram,
289 qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
290 struct bin_attribute *bin_attr,
291 char *buf, loff_t off, size_t count)
293 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
294 struct device, kobj)));
295 struct qla_hw_data *ha = vha->hw;
298 mutex_lock(&ha->optrom_mutex);
300 if (ha->optrom_state != QLA_SREADING)
303 rval = memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
304 ha->optrom_region_size);
307 mutex_unlock(&ha->optrom_mutex);
313 qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
314 struct bin_attribute *bin_attr,
315 char *buf, loff_t off, size_t count)
317 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
318 struct device, kobj)));
319 struct qla_hw_data *ha = vha->hw;
321 mutex_lock(&ha->optrom_mutex);
323 if (ha->optrom_state != QLA_SWRITING) {
324 mutex_unlock(&ha->optrom_mutex);
327 if (off > ha->optrom_region_size) {
328 mutex_unlock(&ha->optrom_mutex);
331 if (off + count > ha->optrom_region_size)
332 count = ha->optrom_region_size - off;
334 memcpy(&ha->optrom_buffer[off], buf, count);
335 mutex_unlock(&ha->optrom_mutex);
340 static struct bin_attribute sysfs_optrom_attr = {
343 .mode = S_IRUSR | S_IWUSR,
346 .read = qla2x00_sysfs_read_optrom,
347 .write = qla2x00_sysfs_write_optrom,
351 qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
352 struct bin_attribute *bin_attr,
353 char *buf, loff_t off, size_t count)
355 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
356 struct device, kobj)));
357 struct qla_hw_data *ha = vha->hw;
359 uint32_t size = ha->optrom_size;
361 ssize_t rval = count;
366 if (unlikely(pci_channel_offline(ha->pdev)))
369 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
371 if (start > ha->optrom_size)
373 if (size > ha->optrom_size - start)
374 size = ha->optrom_size - start;
376 mutex_lock(&ha->optrom_mutex);
377 if (qla2x00_chip_is_down(vha)) {
378 mutex_unlock(&ha->optrom_mutex);
383 if (ha->optrom_state != QLA_SREADING &&
384 ha->optrom_state != QLA_SWRITING) {
388 ha->optrom_state = QLA_SWAITING;
390 ql_dbg(ql_dbg_user, vha, 0x7061,
391 "Freeing flash region allocation -- 0x%x bytes.\n",
392 ha->optrom_region_size);
394 vfree(ha->optrom_buffer);
395 ha->optrom_buffer = NULL;
398 if (ha->optrom_state != QLA_SWAITING) {
403 ha->optrom_region_start = start;
404 ha->optrom_region_size = size;
406 ha->optrom_state = QLA_SREADING;
407 ha->optrom_buffer = vzalloc(ha->optrom_region_size);
408 if (ha->optrom_buffer == NULL) {
409 ql_log(ql_log_warn, vha, 0x7062,
410 "Unable to allocate memory for optrom retrieval "
411 "(%x).\n", ha->optrom_region_size);
413 ha->optrom_state = QLA_SWAITING;
418 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
419 ql_log(ql_log_warn, vha, 0x7063,
420 "HBA not online, failing NVRAM update.\n");
425 ql_dbg(ql_dbg_user, vha, 0x7064,
426 "Reading flash region -- 0x%x/0x%x.\n",
427 ha->optrom_region_start, ha->optrom_region_size);
429 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
430 ha->optrom_region_start, ha->optrom_region_size);
433 if (ha->optrom_state != QLA_SWAITING) {
439 * We need to be more restrictive on which FLASH regions are
440 * allowed to be updated via user-space. Regions accessible
441 * via this method include:
443 * ISP21xx/ISP22xx/ISP23xx type boards:
445 * 0x000000 -> 0x020000 -- Boot code.
447 * ISP2322/ISP24xx type boards:
449 * 0x000000 -> 0x07ffff -- Boot code.
450 * 0x080000 -> 0x0fffff -- Firmware.
452 * ISP25xx type boards:
454 * 0x000000 -> 0x07ffff -- Boot code.
455 * 0x080000 -> 0x0fffff -- Firmware.
456 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
458 * > ISP25xx type boards:
460 * None -- should go through BSG.
463 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
465 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
468 ql_log(ql_log_warn, vha, 0x7065,
469 "Invalid start region 0x%x/0x%x.\n", start, size);
474 ha->optrom_region_start = start;
475 ha->optrom_region_size = size;
477 ha->optrom_state = QLA_SWRITING;
478 ha->optrom_buffer = vzalloc(ha->optrom_region_size);
479 if (ha->optrom_buffer == NULL) {
480 ql_log(ql_log_warn, vha, 0x7066,
481 "Unable to allocate memory for optrom update "
482 "(%x)\n", ha->optrom_region_size);
484 ha->optrom_state = QLA_SWAITING;
489 ql_dbg(ql_dbg_user, vha, 0x7067,
490 "Staging flash region write -- 0x%x/0x%x.\n",
491 ha->optrom_region_start, ha->optrom_region_size);
495 if (ha->optrom_state != QLA_SWRITING) {
500 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
501 ql_log(ql_log_warn, vha, 0x7068,
502 "HBA not online, failing flash update.\n");
507 ql_dbg(ql_dbg_user, vha, 0x7069,
508 "Writing flash region -- 0x%x/0x%x.\n",
509 ha->optrom_region_start, ha->optrom_region_size);
511 rval = ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
512 ha->optrom_region_start, ha->optrom_region_size);
521 mutex_unlock(&ha->optrom_mutex);
525 static struct bin_attribute sysfs_optrom_ctl_attr = {
527 .name = "optrom_ctl",
531 .write = qla2x00_sysfs_write_optrom_ctl,
535 qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
536 struct bin_attribute *bin_attr,
537 char *buf, loff_t off, size_t count)
539 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
540 struct device, kobj)));
541 struct qla_hw_data *ha = vha->hw;
543 struct active_regions active_regions = { };
545 if (unlikely(pci_channel_offline(ha->pdev)))
548 if (!capable(CAP_SYS_ADMIN))
551 if (IS_NOCACHE_VPD_TYPE(ha))
554 faddr = ha->flt_region_vpd << 2;
556 if (IS_QLA28XX(ha)) {
557 qla28xx_get_aux_images(vha, &active_regions);
558 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
559 faddr = ha->flt_region_vpd_sec << 2;
561 ql_dbg(ql_dbg_init, vha, 0x7070,
562 "Loading %s nvram image.\n",
563 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
564 "primary" : "secondary");
567 mutex_lock(&ha->optrom_mutex);
568 if (qla2x00_chip_is_down(vha)) {
569 mutex_unlock(&ha->optrom_mutex);
573 ha->isp_ops->read_optrom(vha, ha->vpd, faddr, ha->vpd_size);
574 mutex_unlock(&ha->optrom_mutex);
576 ha->isp_ops->read_optrom(vha, ha->vpd, faddr, ha->vpd_size);
578 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
582 qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
583 struct bin_attribute *bin_attr,
584 char *buf, loff_t off, size_t count)
586 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
587 struct device, kobj)));
588 struct qla_hw_data *ha = vha->hw;
591 if (unlikely(pci_channel_offline(ha->pdev)))
594 if (qla2x00_chip_is_down(vha))
597 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
598 !ha->isp_ops->write_nvram)
601 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
602 ql_log(ql_log_warn, vha, 0x706a,
603 "HBA not online, failing VPD update.\n");
607 mutex_lock(&ha->optrom_mutex);
608 if (qla2x00_chip_is_down(vha)) {
609 mutex_unlock(&ha->optrom_mutex);
614 ha->isp_ops->write_nvram(vha, buf, ha->vpd_base, count);
615 ha->isp_ops->read_nvram(vha, ha->vpd, ha->vpd_base, count);
617 /* Update flash version information for 4Gb & above. */
618 if (!IS_FWI2_CAPABLE(ha)) {
619 mutex_unlock(&ha->optrom_mutex);
623 tmp_data = vmalloc(256);
625 mutex_unlock(&ha->optrom_mutex);
626 ql_log(ql_log_warn, vha, 0x706b,
627 "Unable to allocate memory for VPD information update.\n");
630 ha->isp_ops->get_flash_version(vha, tmp_data);
633 mutex_unlock(&ha->optrom_mutex);
638 static struct bin_attribute sysfs_vpd_attr = {
641 .mode = S_IRUSR | S_IWUSR,
644 .read = qla2x00_sysfs_read_vpd,
645 .write = qla2x00_sysfs_write_vpd,
649 qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
650 struct bin_attribute *bin_attr,
651 char *buf, loff_t off, size_t count)
653 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
654 struct device, kobj)));
657 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < SFP_DEV_SIZE)
660 mutex_lock(&vha->hw->optrom_mutex);
661 if (qla2x00_chip_is_down(vha)) {
662 mutex_unlock(&vha->hw->optrom_mutex);
666 rval = qla2x00_read_sfp_dev(vha, buf, count);
667 mutex_unlock(&vha->hw->optrom_mutex);
675 static struct bin_attribute sysfs_sfp_attr = {
678 .mode = S_IRUSR | S_IWUSR,
680 .size = SFP_DEV_SIZE,
681 .read = qla2x00_sysfs_read_sfp,
685 qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
686 struct bin_attribute *bin_attr,
687 char *buf, loff_t off, size_t count)
689 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
690 struct device, kobj)));
691 struct qla_hw_data *ha = vha->hw;
692 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
694 uint32_t idc_control;
695 uint8_t *tmp_data = NULL;
700 type = simple_strtol(buf, NULL, 10);
703 ql_log(ql_log_info, vha, 0x706e,
704 "Issuing ISP reset.\n");
706 scsi_block_requests(vha->host);
707 if (IS_QLA82XX(ha)) {
708 ha->flags.isp82xx_no_md_cap = 1;
709 qla82xx_idc_lock(ha);
710 qla82xx_set_reset_owner(vha);
711 qla82xx_idc_unlock(ha);
712 } else if (IS_QLA8044(ha)) {
713 qla8044_idc_lock(ha);
714 idc_control = qla8044_rd_reg(ha,
715 QLA8044_IDC_DRV_CTRL);
716 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
717 (idc_control | GRACEFUL_RESET_BIT1));
718 qla82xx_set_reset_owner(vha);
719 qla8044_idc_unlock(ha);
721 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
722 qla2xxx_wake_dpc(vha);
724 qla2x00_wait_for_chip_reset(vha);
725 scsi_unblock_requests(vha->host);
728 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
729 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
732 ql_log(ql_log_info, vha, 0x706f,
733 "Issuing MPI reset.\n");
735 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
736 uint32_t idc_control;
738 qla83xx_idc_lock(vha, 0);
739 __qla83xx_get_idc_control(vha, &idc_control);
740 idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
741 __qla83xx_set_idc_control(vha, idc_control);
742 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
743 QLA8XXX_DEV_NEED_RESET);
744 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
745 qla83xx_idc_unlock(vha, 0);
747 } else if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
748 qla27xx_reset_mpi(vha);
750 /* Make sure FC side is not in reset */
751 WARN_ON_ONCE(qla2x00_wait_for_hba_online(vha) !=
754 /* Issue MPI reset */
755 scsi_block_requests(vha->host);
756 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
757 ql_log(ql_log_warn, vha, 0x7070,
758 "MPI reset failed.\n");
759 scsi_unblock_requests(vha->host);
764 if (!IS_P3P_TYPE(ha) || vha != base_vha) {
765 ql_log(ql_log_info, vha, 0x7071,
766 "FCoE ctx reset not supported.\n");
770 ql_log(ql_log_info, vha, 0x7072,
771 "Issuing FCoE ctx reset.\n");
772 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
773 qla2xxx_wake_dpc(vha);
774 qla2x00_wait_for_fcoe_ctx_reset(vha);
779 ql_log(ql_log_info, vha, 0x70bc,
780 "Disabling Reset by IDC control\n");
781 qla83xx_idc_lock(vha, 0);
782 __qla83xx_get_idc_control(vha, &idc_control);
783 idc_control |= QLA83XX_IDC_RESET_DISABLED;
784 __qla83xx_set_idc_control(vha, idc_control);
785 qla83xx_idc_unlock(vha, 0);
790 ql_log(ql_log_info, vha, 0x70bd,
791 "Enabling 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);
799 ql_dbg(ql_dbg_user, vha, 0x70e0,
800 "Updating cache versions without reset ");
802 tmp_data = vmalloc(256);
804 ql_log(ql_log_warn, vha, 0x70e1,
805 "Unable to allocate memory for VPD information update.\n");
808 ha->isp_ops->get_flash_version(vha, tmp_data);
815 static struct bin_attribute sysfs_reset_attr = {
821 .write = qla2x00_sysfs_write_reset,
825 qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
826 struct bin_attribute *bin_attr,
827 char *buf, loff_t off, size_t count)
829 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
830 struct device, kobj)));
834 if (!capable(CAP_SYS_ADMIN))
837 if (unlikely(pci_channel_offline(vha->hw->pdev)))
840 if (qla2x00_chip_is_down(vha))
843 type = simple_strtol(buf, NULL, 10);
845 did.b.domain = (type & 0x00ff0000) >> 16;
846 did.b.area = (type & 0x0000ff00) >> 8;
847 did.b.al_pa = (type & 0x000000ff);
849 ql_log(ql_log_info, vha, 0xd04d, "portid=%02x%02x%02x done\n",
850 did.b.domain, did.b.area, did.b.al_pa);
852 ql_log(ql_log_info, vha, 0x70e4, "%s: %d\n", __func__, type);
854 qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, did);
858 static struct bin_attribute sysfs_issue_logo_attr = {
860 .name = "issue_logo",
864 .write = qla2x00_issue_logo,
868 qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
869 struct bin_attribute *bin_attr,
870 char *buf, loff_t off, size_t count)
872 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
873 struct device, kobj)));
874 struct qla_hw_data *ha = vha->hw;
876 uint16_t actual_size;
878 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
881 if (unlikely(pci_channel_offline(ha->pdev)))
883 mutex_lock(&vha->hw->optrom_mutex);
884 if (qla2x00_chip_is_down(vha)) {
885 mutex_unlock(&vha->hw->optrom_mutex);
892 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
893 &ha->xgmac_data_dma, GFP_KERNEL);
894 if (!ha->xgmac_data) {
895 mutex_unlock(&vha->hw->optrom_mutex);
896 ql_log(ql_log_warn, vha, 0x7076,
897 "Unable to allocate memory for XGMAC read-data.\n");
903 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
905 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
906 XGMAC_DATA_SIZE, &actual_size);
908 mutex_unlock(&vha->hw->optrom_mutex);
909 if (rval != QLA_SUCCESS) {
910 ql_log(ql_log_warn, vha, 0x7077,
911 "Unable to read XGMAC data (%x).\n", rval);
915 count = actual_size > count ? count : actual_size;
916 memcpy(buf, ha->xgmac_data, count);
921 static struct bin_attribute sysfs_xgmac_stats_attr = {
923 .name = "xgmac_stats",
927 .read = qla2x00_sysfs_read_xgmac_stats,
931 qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
932 struct bin_attribute *bin_attr,
933 char *buf, loff_t off, size_t count)
935 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
936 struct device, kobj)));
937 struct qla_hw_data *ha = vha->hw;
940 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
945 mutex_lock(&vha->hw->optrom_mutex);
946 if (qla2x00_chip_is_down(vha)) {
947 mutex_unlock(&vha->hw->optrom_mutex);
951 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
952 &ha->dcbx_tlv_dma, GFP_KERNEL);
954 mutex_unlock(&vha->hw->optrom_mutex);
955 ql_log(ql_log_warn, vha, 0x7078,
956 "Unable to allocate memory for DCBX TLV read-data.\n");
961 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
963 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
966 mutex_unlock(&vha->hw->optrom_mutex);
968 if (rval != QLA_SUCCESS) {
969 ql_log(ql_log_warn, vha, 0x7079,
970 "Unable to read DCBX TLV (%x).\n", rval);
974 memcpy(buf, ha->dcbx_tlv, count);
979 static struct bin_attribute sysfs_dcbx_tlv_attr = {
985 .read = qla2x00_sysfs_read_dcbx_tlv,
988 static struct sysfs_entry {
990 struct bin_attribute *attr;
992 } bin_file_entries[] = {
993 { "fw_dump", &sysfs_fw_dump_attr, },
994 { "nvram", &sysfs_nvram_attr, },
995 { "optrom", &sysfs_optrom_attr, },
996 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
997 { "vpd", &sysfs_vpd_attr, 1 },
998 { "sfp", &sysfs_sfp_attr, 1 },
999 { "reset", &sysfs_reset_attr, },
1000 { "issue_logo", &sysfs_issue_logo_attr, },
1001 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
1002 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
1007 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
1009 struct Scsi_Host *host = vha->host;
1010 struct sysfs_entry *iter;
1013 for (iter = bin_file_entries; iter->name; iter++) {
1014 if (iter->type && !IS_FWI2_CAPABLE(vha->hw))
1016 if (iter->type == 2 && !IS_QLA25XX(vha->hw))
1018 if (iter->type == 3 && !(IS_CNA_CAPABLE(vha->hw)))
1021 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
1024 ql_log(ql_log_warn, vha, 0x00f3,
1025 "Unable to create sysfs %s binary attribute (%d).\n",
1028 ql_dbg(ql_dbg_init, vha, 0x00f4,
1029 "Successfully created sysfs %s binary attribute.\n",
1035 qla2x00_free_sysfs_attr(scsi_qla_host_t *vha, bool stop_beacon)
1037 struct Scsi_Host *host = vha->host;
1038 struct sysfs_entry *iter;
1039 struct qla_hw_data *ha = vha->hw;
1041 for (iter = bin_file_entries; iter->name; iter++) {
1042 if (iter->type && !IS_FWI2_CAPABLE(ha))
1044 if (iter->type == 2 && !IS_QLA25XX(ha))
1046 if (iter->type == 3 && !(IS_CNA_CAPABLE(ha)))
1048 if (iter->type == 0x27 &&
1049 (!IS_QLA27XX(ha) || !IS_QLA28XX(ha)))
1052 sysfs_remove_bin_file(&host->shost_gendev.kobj,
1056 if (stop_beacon && ha->beacon_blink_led == 1)
1057 ha->isp_ops->beacon_off(vha);
1060 /* Scsi_Host attributes. */
1063 qla2x00_driver_version_show(struct device *dev,
1064 struct device_attribute *attr, char *buf)
1066 return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
1070 qla2x00_fw_version_show(struct device *dev,
1071 struct device_attribute *attr, char *buf)
1073 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1074 struct qla_hw_data *ha = vha->hw;
1077 return scnprintf(buf, PAGE_SIZE, "%s\n",
1078 ha->isp_ops->fw_version_str(vha, fw_str, sizeof(fw_str)));
1082 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
1085 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1086 struct qla_hw_data *ha = vha->hw;
1089 if (IS_QLAFX00(vha->hw)) {
1090 return scnprintf(buf, PAGE_SIZE, "%s\n",
1091 vha->hw->mr.serial_num);
1092 } else if (IS_FWI2_CAPABLE(ha)) {
1093 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE - 1);
1094 return strlen(strcat(buf, "\n"));
1097 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1098 return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
1103 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
1106 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1108 return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
1112 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
1115 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1116 struct qla_hw_data *ha = vha->hw;
1118 if (IS_QLAFX00(vha->hw))
1119 return scnprintf(buf, PAGE_SIZE, "%s\n",
1120 vha->hw->mr.hw_version);
1122 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
1123 ha->product_id[0], ha->product_id[1], ha->product_id[2],
1128 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
1131 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1133 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
1137 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1140 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1142 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
1146 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1149 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1152 return scnprintf(buf, PAGE_SIZE, "%s\n",
1153 vha->hw->isp_ops->pci_info_str(vha, pci_info,
1158 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1161 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1162 struct qla_hw_data *ha = vha->hw;
1165 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
1166 atomic_read(&vha->loop_state) == LOOP_DEAD ||
1167 vha->device_flags & DFLG_NO_CABLE)
1168 len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
1169 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1170 qla2x00_chip_is_down(vha))
1171 len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1173 len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
1175 switch (ha->current_topology) {
1177 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1180 len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1183 len += scnprintf(buf + len, PAGE_SIZE-len,
1184 "N_Port to N_Port\n");
1187 len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1190 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1198 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1201 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1204 switch (vha->hw->zio_mode) {
1205 case QLA_ZIO_MODE_6:
1206 len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1208 case QLA_ZIO_DISABLED:
1209 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1216 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1217 const char *buf, size_t count)
1219 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1220 struct qla_hw_data *ha = vha->hw;
1224 if (!IS_ZIO_SUPPORTED(ha))
1227 if (sscanf(buf, "%d", &val) != 1)
1231 zio_mode = QLA_ZIO_MODE_6;
1233 zio_mode = QLA_ZIO_DISABLED;
1235 /* Update per-hba values and queue a reset. */
1236 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1237 ha->zio_mode = zio_mode;
1238 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1244 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1247 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1249 return scnprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
1253 qla2x00_zio_timer_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));
1260 if (sscanf(buf, "%d", &val) != 1)
1262 if (val > 25500 || val < 100)
1265 zio_timer = (uint16_t)(val / 100);
1266 vha->hw->zio_timer = zio_timer;
1272 qla_zio_threshold_show(struct device *dev, struct device_attribute *attr,
1275 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1277 return scnprintf(buf, PAGE_SIZE, "%d exchanges\n",
1278 vha->hw->last_zio_threshold);
1282 qla_zio_threshold_store(struct device *dev, struct device_attribute *attr,
1283 const char *buf, size_t count)
1285 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1288 if (vha->hw->zio_mode != QLA_ZIO_MODE_6)
1290 if (sscanf(buf, "%d", &val) != 1)
1292 if (val < 0 || val > 256)
1295 atomic_set(&vha->hw->zio_threshold, val);
1300 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1303 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1306 if (vha->hw->beacon_blink_led)
1307 len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1309 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1314 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1315 const char *buf, size_t count)
1317 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1318 struct qla_hw_data *ha = vha->hw;
1322 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1325 if (sscanf(buf, "%d", &val) != 1)
1328 mutex_lock(&vha->hw->optrom_mutex);
1329 if (qla2x00_chip_is_down(vha)) {
1330 mutex_unlock(&vha->hw->optrom_mutex);
1331 ql_log(ql_log_warn, vha, 0x707a,
1332 "Abort ISP active -- ignoring beacon request.\n");
1337 rval = ha->isp_ops->beacon_on(vha);
1339 rval = ha->isp_ops->beacon_off(vha);
1341 if (rval != QLA_SUCCESS)
1344 mutex_unlock(&vha->hw->optrom_mutex);
1350 qla2x00_beacon_config_show(struct device *dev, struct device_attribute *attr,
1353 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1354 struct qla_hw_data *ha = vha->hw;
1355 uint16_t led[3] = { 0 };
1357 if (!IS_QLA2031(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1360 if (ql26xx_led_config(vha, 0, led))
1361 return scnprintf(buf, PAGE_SIZE, "\n");
1363 return scnprintf(buf, PAGE_SIZE, "%#04hx %#04hx %#04hx\n",
1364 led[0], led[1], led[2]);
1368 qla2x00_beacon_config_store(struct device *dev, struct device_attribute *attr,
1369 const char *buf, size_t count)
1371 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1372 struct qla_hw_data *ha = vha->hw;
1373 uint16_t options = BIT_0;
1374 uint16_t led[3] = { 0 };
1378 if (!IS_QLA2031(ha) && !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1381 n = sscanf(buf, "%hx %hx %hx %hx", word+0, word+1, word+2, word+3);
1384 options |= BIT_3|BIT_2|BIT_1;
1394 /* check led index */
1416 if (ql26xx_led_config(vha, options, led))
1423 qla2x00_optrom_bios_version_show(struct device *dev,
1424 struct device_attribute *attr, char *buf)
1426 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1427 struct qla_hw_data *ha = vha->hw;
1429 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1430 ha->bios_revision[0]);
1434 qla2x00_optrom_efi_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->efi_revision[1],
1441 ha->efi_revision[0]);
1445 qla2x00_optrom_fcode_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->fcode_revision[1],
1452 ha->fcode_revision[0]);
1456 qla2x00_optrom_fw_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.%02d %d\n",
1463 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1464 ha->fw_revision[3]);
1468 qla2x00_optrom_gold_fw_version_show(struct device *dev,
1469 struct device_attribute *attr, char *buf)
1471 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1472 struct qla_hw_data *ha = vha->hw;
1474 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1475 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1476 return scnprintf(buf, PAGE_SIZE, "\n");
1478 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1479 ha->gold_fw_version[0], ha->gold_fw_version[1],
1480 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1484 qla2x00_total_isp_aborts_show(struct device *dev,
1485 struct device_attribute *attr, char *buf)
1487 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1489 return scnprintf(buf, PAGE_SIZE, "%d\n",
1490 vha->qla_stats.total_isp_aborts);
1494 qla24xx_84xx_fw_version_show(struct device *dev,
1495 struct device_attribute *attr, char *buf)
1497 int rval = QLA_SUCCESS;
1498 uint16_t status[2] = { 0 };
1499 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1500 struct qla_hw_data *ha = vha->hw;
1502 if (!IS_QLA84XX(ha))
1503 return scnprintf(buf, PAGE_SIZE, "\n");
1505 if (!ha->cs84xx->op_fw_version) {
1506 rval = qla84xx_verify_chip(vha, status);
1508 if (!rval && !status[0])
1509 return scnprintf(buf, PAGE_SIZE, "%u\n",
1510 (uint32_t)ha->cs84xx->op_fw_version);
1513 return scnprintf(buf, PAGE_SIZE, "\n");
1517 qla2x00_serdes_version_show(struct device *dev, struct device_attribute *attr,
1520 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1521 struct qla_hw_data *ha = vha->hw;
1523 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1524 return scnprintf(buf, PAGE_SIZE, "\n");
1526 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1527 ha->serdes_version[0], ha->serdes_version[1],
1528 ha->serdes_version[2]);
1532 qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1535 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1536 struct qla_hw_data *ha = vha->hw;
1538 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
1539 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1540 return scnprintf(buf, PAGE_SIZE, "\n");
1542 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
1543 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
1544 ha->mpi_capabilities);
1548 qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1551 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1552 struct qla_hw_data *ha = vha->hw;
1554 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
1555 return scnprintf(buf, PAGE_SIZE, "\n");
1557 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1558 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
1562 qla2x00_flash_block_size_show(struct device *dev,
1563 struct device_attribute *attr, char *buf)
1565 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1566 struct qla_hw_data *ha = vha->hw;
1568 return scnprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1572 qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1575 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1577 if (!IS_CNA_CAPABLE(vha->hw))
1578 return scnprintf(buf, PAGE_SIZE, "\n");
1580 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1584 qla2x00_vn_port_mac_address_show(struct device *dev,
1585 struct device_attribute *attr, char *buf)
1587 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1589 if (!IS_CNA_CAPABLE(vha->hw))
1590 return scnprintf(buf, PAGE_SIZE, "\n");
1592 return scnprintf(buf, PAGE_SIZE, "%pMR\n", vha->fcoe_vn_port_mac);
1596 qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1599 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1601 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1605 qla2x00_thermal_temp_show(struct device *dev,
1606 struct device_attribute *attr, char *buf)
1608 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1612 mutex_lock(&vha->hw->optrom_mutex);
1613 if (qla2x00_chip_is_down(vha)) {
1614 mutex_unlock(&vha->hw->optrom_mutex);
1615 ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
1619 if (vha->hw->flags.eeh_busy) {
1620 mutex_unlock(&vha->hw->optrom_mutex);
1621 ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
1625 rc = qla2x00_get_thermal_temp(vha, &temp);
1626 mutex_unlock(&vha->hw->optrom_mutex);
1627 if (rc == QLA_SUCCESS)
1628 return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
1631 return scnprintf(buf, PAGE_SIZE, "\n");
1635 qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1638 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1639 int rval = QLA_FUNCTION_FAILED;
1643 if (IS_QLAFX00(vha->hw)) {
1644 pstate = qlafx00_fw_state_show(dev, attr, buf);
1645 return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
1648 mutex_lock(&vha->hw->optrom_mutex);
1649 if (qla2x00_chip_is_down(vha)) {
1650 mutex_unlock(&vha->hw->optrom_mutex);
1651 ql_log(ql_log_warn, vha, 0x707c,
1652 "ISP reset active.\n");
1654 } else if (vha->hw->flags.eeh_busy) {
1655 mutex_unlock(&vha->hw->optrom_mutex);
1659 rval = qla2x00_get_firmware_state(vha, state);
1660 mutex_unlock(&vha->hw->optrom_mutex);
1662 if (rval != QLA_SUCCESS) {
1663 memset(state, -1, sizeof(state));
1664 rval = qla2x00_get_firmware_state(vha, state);
1667 return scnprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1668 state[0], state[1], state[2], state[3], state[4], state[5]);
1672 qla2x00_diag_requests_show(struct device *dev,
1673 struct device_attribute *attr, char *buf)
1675 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1677 if (!IS_BIDI_CAPABLE(vha->hw))
1678 return scnprintf(buf, PAGE_SIZE, "\n");
1680 return scnprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
1684 qla2x00_diag_megabytes_show(struct device *dev,
1685 struct device_attribute *attr, char *buf)
1687 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1689 if (!IS_BIDI_CAPABLE(vha->hw))
1690 return scnprintf(buf, PAGE_SIZE, "\n");
1692 return scnprintf(buf, PAGE_SIZE, "%llu\n",
1693 vha->bidi_stats.transfer_bytes >> 20);
1697 qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
1700 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1701 struct qla_hw_data *ha = vha->hw;
1706 else if (IS_P3P_TYPE(ha))
1707 size = ha->md_template_size + ha->md_dump_size;
1709 size = ha->fw_dump_len;
1711 return scnprintf(buf, PAGE_SIZE, "%d\n", size);
1715 qla2x00_allow_cna_fw_dump_show(struct device *dev,
1716 struct device_attribute *attr, char *buf)
1718 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1720 if (!IS_P3P_TYPE(vha->hw))
1721 return scnprintf(buf, PAGE_SIZE, "\n");
1723 return scnprintf(buf, PAGE_SIZE, "%s\n",
1724 vha->hw->allow_cna_fw_dump ? "true" : "false");
1728 qla2x00_allow_cna_fw_dump_store(struct device *dev,
1729 struct device_attribute *attr, const char *buf, size_t count)
1731 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1734 if (!IS_P3P_TYPE(vha->hw))
1737 if (sscanf(buf, "%d", &val) != 1)
1740 vha->hw->allow_cna_fw_dump = val != 0;
1746 qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
1749 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1750 struct qla_hw_data *ha = vha->hw;
1752 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1753 return scnprintf(buf, PAGE_SIZE, "\n");
1755 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1756 ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
1760 qla2x00_min_supported_speed_show(struct device *dev,
1761 struct device_attribute *attr, char *buf)
1763 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1764 struct qla_hw_data *ha = vha->hw;
1766 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1767 return scnprintf(buf, PAGE_SIZE, "\n");
1769 return scnprintf(buf, PAGE_SIZE, "%s\n",
1770 ha->min_supported_speed == 6 ? "64Gps" :
1771 ha->min_supported_speed == 5 ? "32Gps" :
1772 ha->min_supported_speed == 4 ? "16Gps" :
1773 ha->min_supported_speed == 3 ? "8Gps" :
1774 ha->min_supported_speed == 2 ? "4Gps" :
1775 ha->min_supported_speed != 0 ? "unknown" : "");
1779 qla2x00_max_supported_speed_show(struct device *dev,
1780 struct device_attribute *attr, char *buf)
1782 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1783 struct qla_hw_data *ha = vha->hw;
1785 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1786 return scnprintf(buf, PAGE_SIZE, "\n");
1788 return scnprintf(buf, PAGE_SIZE, "%s\n",
1789 ha->max_supported_speed == 2 ? "64Gps" :
1790 ha->max_supported_speed == 1 ? "32Gps" :
1791 ha->max_supported_speed == 0 ? "16Gps" : "unknown");
1795 qla2x00_port_speed_store(struct device *dev, struct device_attribute *attr,
1796 const char *buf, size_t count)
1798 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1801 int mode = QLA_SET_DATA_RATE_LR;
1802 struct qla_hw_data *ha = vha->hw;
1804 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) {
1805 ql_log(ql_log_warn, vha, 0x70d8,
1806 "Speed setting not supported \n");
1810 rval = kstrtol(buf, 10, &type);
1814 if (type == 40 || type == 80 || type == 160 ||
1816 ql_dbg(ql_dbg_user, vha, 0x70d9,
1817 "Setting will be affected after a loss of sync\n");
1819 mode = QLA_SET_DATA_RATE_NOLR;
1822 oldspeed = ha->set_data_rate;
1826 ha->set_data_rate = PORT_SPEED_AUTO;
1829 ha->set_data_rate = PORT_SPEED_4GB;
1832 ha->set_data_rate = PORT_SPEED_8GB;
1835 ha->set_data_rate = PORT_SPEED_16GB;
1838 ha->set_data_rate = PORT_SPEED_32GB;
1841 ql_log(ql_log_warn, vha, 0x1199,
1842 "Unrecognized speed setting:%lx. Setting Autoneg\n",
1844 ha->set_data_rate = PORT_SPEED_AUTO;
1847 if (qla2x00_chip_is_down(vha) || (oldspeed == ha->set_data_rate))
1850 ql_log(ql_log_info, vha, 0x70da,
1851 "Setting speed to %lx Gbps \n", type);
1853 rval = qla2x00_set_data_rate(vha, mode);
1854 if (rval != QLA_SUCCESS)
1861 qla2x00_port_speed_show(struct device *dev, struct device_attribute *attr,
1864 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1865 struct qla_hw_data *ha = vha->hw;
1867 char *spd[7] = {"0", "0", "0", "4", "8", "16", "32"};
1869 rval = qla2x00_get_data_rate(vha);
1870 if (rval != QLA_SUCCESS) {
1871 ql_log(ql_log_warn, vha, 0x70db,
1872 "Unable to get port speed rval:%zd\n", rval);
1876 return scnprintf(buf, PAGE_SIZE, "%s\n", spd[ha->link_data_rate]);
1882 qlini_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1884 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1887 len += scnprintf(buf + len, PAGE_SIZE-len,
1888 "Supported options: enabled | disabled | dual | exclusive\n");
1891 len += scnprintf(buf + len, PAGE_SIZE-len, "Current selection: ");
1893 switch (vha->qlini_mode) {
1894 case QLA2XXX_INI_MODE_EXCLUSIVE:
1895 len += scnprintf(buf + len, PAGE_SIZE-len,
1896 QLA2XXX_INI_MODE_STR_EXCLUSIVE);
1898 case QLA2XXX_INI_MODE_DISABLED:
1899 len += scnprintf(buf + len, PAGE_SIZE-len,
1900 QLA2XXX_INI_MODE_STR_DISABLED);
1902 case QLA2XXX_INI_MODE_ENABLED:
1903 len += scnprintf(buf + len, PAGE_SIZE-len,
1904 QLA2XXX_INI_MODE_STR_ENABLED);
1906 case QLA2XXX_INI_MODE_DUAL:
1907 len += scnprintf(buf + len, PAGE_SIZE-len,
1908 QLA2XXX_INI_MODE_STR_DUAL);
1911 len += scnprintf(buf + len, PAGE_SIZE-len, "\n");
1916 static char *mode_to_str[] = {
1923 #define NEED_EXCH_OFFLOAD(_exchg) ((_exchg) > FW_DEF_EXCHANGES_CNT)
1924 static void qla_set_ini_mode(scsi_qla_host_t *vha, int op)
1929 MODE_CHANGE_NO_ACTION,
1930 TARGET_STILL_ACTIVE,
1932 int action = NO_ACTION;
1934 u8 eo_toggle = 0; /* exchange offload flipped */
1936 switch (vha->qlini_mode) {
1937 case QLA2XXX_INI_MODE_DISABLED:
1939 case QLA2XXX_INI_MODE_DISABLED:
1940 if (qla_tgt_mode_enabled(vha)) {
1941 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1942 vha->hw->flags.exchoffld_enabled)
1944 if (((vha->ql2xexchoffld !=
1945 vha->u_ql2xexchoffld) &&
1946 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1949 * The number of exchange to be offload
1950 * was tweaked or offload option was
1953 action = MODE_CHANGE_ACCEPT;
1955 action = MODE_CHANGE_NO_ACTION;
1958 action = MODE_CHANGE_NO_ACTION;
1961 case QLA2XXX_INI_MODE_EXCLUSIVE:
1962 if (qla_tgt_mode_enabled(vha)) {
1963 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1964 vha->hw->flags.exchoffld_enabled)
1966 if (((vha->ql2xexchoffld !=
1967 vha->u_ql2xexchoffld) &&
1968 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1971 * The number of exchange to be offload
1972 * was tweaked or offload option was
1975 action = MODE_CHANGE_ACCEPT;
1977 action = MODE_CHANGE_NO_ACTION;
1980 action = MODE_CHANGE_ACCEPT;
1983 case QLA2XXX_INI_MODE_DUAL:
1984 action = MODE_CHANGE_ACCEPT;
1985 /* active_mode is target only, reset it to dual */
1986 if (qla_tgt_mode_enabled(vha)) {
1988 action = MODE_CHANGE_ACCEPT;
1990 action = MODE_CHANGE_NO_ACTION;
1994 case QLA2XXX_INI_MODE_ENABLED:
1995 if (qla_tgt_mode_enabled(vha))
1996 action = TARGET_STILL_ACTIVE;
1998 action = MODE_CHANGE_ACCEPT;
2005 case QLA2XXX_INI_MODE_EXCLUSIVE:
2007 case QLA2XXX_INI_MODE_EXCLUSIVE:
2008 if (qla_tgt_mode_enabled(vha)) {
2009 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2010 vha->hw->flags.exchoffld_enabled)
2012 if (((vha->ql2xexchoffld !=
2013 vha->u_ql2xexchoffld) &&
2014 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2017 * The number of exchange to be offload
2018 * was tweaked or offload option was
2021 action = MODE_CHANGE_ACCEPT;
2029 case QLA2XXX_INI_MODE_DISABLED:
2030 if (qla_tgt_mode_enabled(vha)) {
2031 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
2032 vha->hw->flags.exchoffld_enabled)
2034 if (((vha->ql2xexchoffld !=
2035 vha->u_ql2xexchoffld) &&
2036 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
2038 action = MODE_CHANGE_ACCEPT;
2040 action = MODE_CHANGE_NO_ACTION;
2042 action = MODE_CHANGE_NO_ACTION;
2045 case QLA2XXX_INI_MODE_DUAL: /* exclusive -> dual */
2046 if (qla_tgt_mode_enabled(vha)) {
2047 action = MODE_CHANGE_ACCEPT;
2050 action = MODE_CHANGE_ACCEPT;
2053 case QLA2XXX_INI_MODE_ENABLED:
2054 if (qla_tgt_mode_enabled(vha))
2055 action = TARGET_STILL_ACTIVE;
2057 if (vha->hw->flags.fw_started)
2058 action = MODE_CHANGE_NO_ACTION;
2060 action = MODE_CHANGE_ACCEPT;
2066 case QLA2XXX_INI_MODE_ENABLED:
2068 case QLA2XXX_INI_MODE_ENABLED:
2069 if (NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg) !=
2070 vha->hw->flags.exchoffld_enabled)
2072 if (((vha->ql2xiniexchg != vha->u_ql2xiniexchg) &&
2073 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg)) ||
2075 action = MODE_CHANGE_ACCEPT;
2079 case QLA2XXX_INI_MODE_DUAL:
2080 case QLA2XXX_INI_MODE_DISABLED:
2081 action = MODE_CHANGE_ACCEPT;
2084 action = MODE_CHANGE_NO_ACTION;
2089 case QLA2XXX_INI_MODE_DUAL:
2091 case QLA2XXX_INI_MODE_DUAL:
2092 if (qla_tgt_mode_enabled(vha) ||
2093 qla_dual_mode_enabled(vha)) {
2094 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2095 vha->u_ql2xiniexchg) !=
2096 vha->hw->flags.exchoffld_enabled)
2099 if ((((vha->ql2xexchoffld +
2100 vha->ql2xiniexchg) !=
2101 (vha->u_ql2xiniexchg +
2102 vha->u_ql2xexchoffld)) &&
2103 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2104 vha->u_ql2xexchoffld)) || eo_toggle)
2105 action = MODE_CHANGE_ACCEPT;
2109 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2110 vha->u_ql2xiniexchg) !=
2111 vha->hw->flags.exchoffld_enabled)
2114 if ((((vha->ql2xexchoffld + vha->ql2xiniexchg)
2115 != (vha->u_ql2xiniexchg +
2116 vha->u_ql2xexchoffld)) &&
2117 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2118 vha->u_ql2xexchoffld)) || eo_toggle)
2119 action = MODE_CHANGE_NO_ACTION;
2125 case QLA2XXX_INI_MODE_DISABLED:
2126 if (qla_tgt_mode_enabled(vha) ||
2127 qla_dual_mode_enabled(vha)) {
2128 /* turning off initiator mode */
2130 action = MODE_CHANGE_ACCEPT;
2132 action = MODE_CHANGE_NO_ACTION;
2136 case QLA2XXX_INI_MODE_EXCLUSIVE:
2137 if (qla_tgt_mode_enabled(vha) ||
2138 qla_dual_mode_enabled(vha)) {
2140 action = MODE_CHANGE_ACCEPT;
2142 action = MODE_CHANGE_ACCEPT;
2146 case QLA2XXX_INI_MODE_ENABLED:
2147 if (qla_tgt_mode_enabled(vha) ||
2148 qla_dual_mode_enabled(vha)) {
2149 action = TARGET_STILL_ACTIVE;
2151 action = MODE_CHANGE_ACCEPT;
2158 case MODE_CHANGE_ACCEPT:
2159 ql_log(ql_log_warn, vha, 0xffff,
2160 "Mode change accepted. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2161 mode_to_str[vha->qlini_mode], mode_to_str[op],
2162 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2163 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2165 vha->qlini_mode = op;
2166 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2167 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2170 vha->flags.online = 1;
2171 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2174 case MODE_CHANGE_NO_ACTION:
2175 ql_log(ql_log_warn, vha, 0xffff,
2176 "Mode is set. No action taken. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2177 mode_to_str[vha->qlini_mode], mode_to_str[op],
2178 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2179 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2180 vha->qlini_mode = op;
2181 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2182 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2185 case TARGET_STILL_ACTIVE:
2186 ql_log(ql_log_warn, vha, 0xffff,
2187 "Target Mode is active. Unable to change Mode.\n");
2192 ql_log(ql_log_warn, vha, 0xffff,
2193 "Mode unchange. No action taken. %d|%d pct %d|%d.\n",
2194 vha->qlini_mode, op,
2195 vha->ql2xexchoffld, vha->u_ql2xexchoffld);
2201 qlini_mode_store(struct device *dev, struct device_attribute *attr,
2202 const char *buf, size_t count)
2204 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2210 if (strncasecmp(QLA2XXX_INI_MODE_STR_EXCLUSIVE, buf,
2211 strlen(QLA2XXX_INI_MODE_STR_EXCLUSIVE)) == 0)
2212 ini = QLA2XXX_INI_MODE_EXCLUSIVE;
2213 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DISABLED, buf,
2214 strlen(QLA2XXX_INI_MODE_STR_DISABLED)) == 0)
2215 ini = QLA2XXX_INI_MODE_DISABLED;
2216 else if (strncasecmp(QLA2XXX_INI_MODE_STR_ENABLED, buf,
2217 strlen(QLA2XXX_INI_MODE_STR_ENABLED)) == 0)
2218 ini = QLA2XXX_INI_MODE_ENABLED;
2219 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DUAL, buf,
2220 strlen(QLA2XXX_INI_MODE_STR_DUAL)) == 0)
2221 ini = QLA2XXX_INI_MODE_DUAL;
2225 qla_set_ini_mode(vha, ini);
2230 ql2xexchoffld_show(struct device *dev, struct device_attribute *attr,
2233 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2236 len += scnprintf(buf + len, PAGE_SIZE-len,
2237 "target exchange: new %d : current: %d\n\n",
2238 vha->u_ql2xexchoffld, vha->ql2xexchoffld);
2240 len += scnprintf(buf + len, PAGE_SIZE-len,
2241 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2248 ql2xexchoffld_store(struct device *dev, struct device_attribute *attr,
2249 const char *buf, size_t count)
2251 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2254 if (sscanf(buf, "%d", &val) != 1)
2257 if (val > FW_MAX_EXCHANGES_CNT)
2258 val = FW_MAX_EXCHANGES_CNT;
2262 vha->u_ql2xexchoffld = val;
2267 ql2xiniexchg_show(struct device *dev, struct device_attribute *attr,
2270 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2273 len += scnprintf(buf + len, PAGE_SIZE-len,
2274 "target exchange: new %d : current: %d\n\n",
2275 vha->u_ql2xiniexchg, vha->ql2xiniexchg);
2277 len += scnprintf(buf + len, PAGE_SIZE-len,
2278 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2285 ql2xiniexchg_store(struct device *dev, struct device_attribute *attr,
2286 const char *buf, size_t count)
2288 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2291 if (sscanf(buf, "%d", &val) != 1)
2294 if (val > FW_MAX_EXCHANGES_CNT)
2295 val = FW_MAX_EXCHANGES_CNT;
2299 vha->u_ql2xiniexchg = val;
2304 qla2x00_dif_bundle_statistics_show(struct device *dev,
2305 struct device_attribute *attr, char *buf)
2307 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2308 struct qla_hw_data *ha = vha->hw;
2310 return scnprintf(buf, PAGE_SIZE,
2311 "cross=%llu read=%llu write=%llu kalloc=%llu dma_alloc=%llu unusable=%u\n",
2312 ha->dif_bundle_crossed_pages, ha->dif_bundle_reads,
2313 ha->dif_bundle_writes, ha->dif_bundle_kallocs,
2314 ha->dif_bundle_dma_allocs, ha->pool.unusable.count);
2318 qla2x00_fw_attr_show(struct device *dev,
2319 struct device_attribute *attr, char *buf)
2321 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2322 struct qla_hw_data *ha = vha->hw;
2324 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2325 return scnprintf(buf, PAGE_SIZE, "\n");
2327 return scnprintf(buf, PAGE_SIZE, "%llx\n",
2328 (uint64_t)ha->fw_attributes_ext[1] << 48 |
2329 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2330 (uint64_t)ha->fw_attributes_h << 16 |
2331 (uint64_t)ha->fw_attributes);
2335 qla2x00_port_no_show(struct device *dev, struct device_attribute *attr,
2338 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2340 return scnprintf(buf, PAGE_SIZE, "%u\n", vha->hw->port_no);
2344 qla2x00_dport_diagnostics_show(struct device *dev,
2345 struct device_attribute *attr, char *buf)
2347 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2349 if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
2350 !IS_QLA28XX(vha->hw))
2351 return scnprintf(buf, PAGE_SIZE, "\n");
2353 if (!*vha->dport_data)
2354 return scnprintf(buf, PAGE_SIZE, "\n");
2356 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
2357 vha->dport_data[0], vha->dport_data[1],
2358 vha->dport_data[2], vha->dport_data[3]);
2360 static DEVICE_ATTR(dport_diagnostics, 0444,
2361 qla2x00_dport_diagnostics_show, NULL);
2363 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_driver_version_show, NULL);
2364 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
2365 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
2366 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
2367 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
2368 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
2369 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
2370 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
2371 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
2372 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
2373 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
2374 qla2x00_zio_timer_store);
2375 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
2376 qla2x00_beacon_store);
2377 static DEVICE_ATTR(beacon_config, 0644, qla2x00_beacon_config_show,
2378 qla2x00_beacon_config_store);
2379 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
2380 qla2x00_optrom_bios_version_show, NULL);
2381 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
2382 qla2x00_optrom_efi_version_show, NULL);
2383 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
2384 qla2x00_optrom_fcode_version_show, NULL);
2385 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
2387 static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
2388 qla2x00_optrom_gold_fw_version_show, NULL);
2389 static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
2391 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
2393 static DEVICE_ATTR(serdes_version, 0444, qla2x00_serdes_version_show, NULL);
2394 static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
2395 static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
2396 static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
2398 static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
2399 static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
2400 qla2x00_vn_port_mac_address_show, NULL);
2401 static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
2402 static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
2403 static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
2404 static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
2405 static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
2406 static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
2407 static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
2408 qla2x00_allow_cna_fw_dump_show,
2409 qla2x00_allow_cna_fw_dump_store);
2410 static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
2411 static DEVICE_ATTR(min_supported_speed, 0444,
2412 qla2x00_min_supported_speed_show, NULL);
2413 static DEVICE_ATTR(max_supported_speed, 0444,
2414 qla2x00_max_supported_speed_show, NULL);
2415 static DEVICE_ATTR(zio_threshold, 0644,
2416 qla_zio_threshold_show,
2417 qla_zio_threshold_store);
2418 static DEVICE_ATTR_RW(qlini_mode);
2419 static DEVICE_ATTR_RW(ql2xexchoffld);
2420 static DEVICE_ATTR_RW(ql2xiniexchg);
2421 static DEVICE_ATTR(dif_bundle_statistics, 0444,
2422 qla2x00_dif_bundle_statistics_show, NULL);
2423 static DEVICE_ATTR(port_speed, 0644, qla2x00_port_speed_show,
2424 qla2x00_port_speed_store);
2425 static DEVICE_ATTR(port_no, 0444, qla2x00_port_no_show, NULL);
2426 static DEVICE_ATTR(fw_attr, 0444, qla2x00_fw_attr_show, NULL);
2429 struct device_attribute *qla2x00_host_attrs[] = {
2430 &dev_attr_driver_version,
2431 &dev_attr_fw_version,
2432 &dev_attr_serial_num,
2435 &dev_attr_model_name,
2436 &dev_attr_model_desc,
2438 &dev_attr_link_state,
2440 &dev_attr_zio_timer,
2442 &dev_attr_beacon_config,
2443 &dev_attr_optrom_bios_version,
2444 &dev_attr_optrom_efi_version,
2445 &dev_attr_optrom_fcode_version,
2446 &dev_attr_optrom_fw_version,
2447 &dev_attr_84xx_fw_version,
2448 &dev_attr_total_isp_aborts,
2449 &dev_attr_serdes_version,
2450 &dev_attr_mpi_version,
2451 &dev_attr_phy_version,
2452 &dev_attr_flash_block_size,
2454 &dev_attr_vn_port_mac_address,
2455 &dev_attr_fabric_param,
2457 &dev_attr_optrom_gold_fw_version,
2458 &dev_attr_thermal_temp,
2459 &dev_attr_diag_requests,
2460 &dev_attr_diag_megabytes,
2461 &dev_attr_fw_dump_size,
2462 &dev_attr_allow_cna_fw_dump,
2463 &dev_attr_pep_version,
2464 &dev_attr_min_supported_speed,
2465 &dev_attr_max_supported_speed,
2466 &dev_attr_zio_threshold,
2467 &dev_attr_dif_bundle_statistics,
2468 &dev_attr_port_speed,
2471 &dev_attr_dport_diagnostics,
2472 NULL, /* reserve for qlini_mode */
2473 NULL, /* reserve for ql2xiniexchg */
2474 NULL, /* reserve for ql2xexchoffld */
2478 void qla_insert_tgt_attrs(void)
2480 struct device_attribute **attr;
2482 /* advance to empty slot */
2483 for (attr = &qla2x00_host_attrs[0]; *attr; ++attr)
2486 *attr = &dev_attr_qlini_mode;
2488 *attr = &dev_attr_ql2xiniexchg;
2490 *attr = &dev_attr_ql2xexchoffld;
2493 /* Host attributes. */
2496 qla2x00_get_host_port_id(struct Scsi_Host *shost)
2498 scsi_qla_host_t *vha = shost_priv(shost);
2500 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
2501 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
2505 qla2x00_get_host_speed(struct Scsi_Host *shost)
2507 scsi_qla_host_t *vha = shost_priv(shost);
2510 if (IS_QLAFX00(vha->hw)) {
2511 qlafx00_get_host_speed(shost);
2515 switch (vha->hw->link_data_rate) {
2516 case PORT_SPEED_1GB:
2517 speed = FC_PORTSPEED_1GBIT;
2519 case PORT_SPEED_2GB:
2520 speed = FC_PORTSPEED_2GBIT;
2522 case PORT_SPEED_4GB:
2523 speed = FC_PORTSPEED_4GBIT;
2525 case PORT_SPEED_8GB:
2526 speed = FC_PORTSPEED_8GBIT;
2528 case PORT_SPEED_10GB:
2529 speed = FC_PORTSPEED_10GBIT;
2531 case PORT_SPEED_16GB:
2532 speed = FC_PORTSPEED_16GBIT;
2534 case PORT_SPEED_32GB:
2535 speed = FC_PORTSPEED_32GBIT;
2537 case PORT_SPEED_64GB:
2538 speed = FC_PORTSPEED_64GBIT;
2541 speed = FC_PORTSPEED_UNKNOWN;
2545 fc_host_speed(shost) = speed;
2549 qla2x00_get_host_port_type(struct Scsi_Host *shost)
2551 scsi_qla_host_t *vha = shost_priv(shost);
2555 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2558 switch (vha->hw->current_topology) {
2560 port_type = FC_PORTTYPE_LPORT;
2563 port_type = FC_PORTTYPE_NLPORT;
2566 port_type = FC_PORTTYPE_PTP;
2569 port_type = FC_PORTTYPE_NPORT;
2572 port_type = FC_PORTTYPE_UNKNOWN;
2576 fc_host_port_type(shost) = port_type;
2580 qla2x00_get_starget_node_name(struct scsi_target *starget)
2582 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2583 scsi_qla_host_t *vha = shost_priv(host);
2587 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2588 if (fcport->rport &&
2589 starget->id == fcport->rport->scsi_target_id) {
2590 node_name = wwn_to_u64(fcport->node_name);
2595 fc_starget_node_name(starget) = node_name;
2599 qla2x00_get_starget_port_name(struct scsi_target *starget)
2601 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2602 scsi_qla_host_t *vha = shost_priv(host);
2606 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2607 if (fcport->rport &&
2608 starget->id == fcport->rport->scsi_target_id) {
2609 port_name = wwn_to_u64(fcport->port_name);
2614 fc_starget_port_name(starget) = port_name;
2618 qla2x00_get_starget_port_id(struct scsi_target *starget)
2620 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2621 scsi_qla_host_t *vha = shost_priv(host);
2623 uint32_t port_id = ~0U;
2625 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2626 if (fcport->rport &&
2627 starget->id == fcport->rport->scsi_target_id) {
2628 port_id = fcport->d_id.b.domain << 16 |
2629 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2634 fc_starget_port_id(starget) = port_id;
2638 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2640 rport->dev_loss_tmo = timeout ? timeout : 1;
2644 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
2646 struct Scsi_Host *host = rport_to_shost(rport);
2647 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2648 unsigned long flags;
2653 /* Now that the rport has been deleted, set the fcport state to
2655 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
2658 * Transport has effectively 'deleted' the rport, clear
2659 * all local references.
2661 spin_lock_irqsave(host->host_lock, flags);
2662 fcport->rport = fcport->drport = NULL;
2663 *((fc_port_t **)rport->dd_data) = NULL;
2664 spin_unlock_irqrestore(host->host_lock, flags);
2666 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2669 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2670 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2676 qla2x00_terminate_rport_io(struct fc_rport *rport)
2678 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2683 if (test_bit(UNLOADING, &fcport->vha->dpc_flags))
2686 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2689 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2690 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2694 * At this point all fcport's software-states are cleared. Perform any
2695 * final cleanup of firmware resources (PCBs and XCBs).
2697 if (fcport->loop_id != FC_NO_LOOP_ID) {
2698 if (IS_FWI2_CAPABLE(fcport->vha->hw))
2699 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
2700 fcport->loop_id, fcport->d_id.b.domain,
2701 fcport->d_id.b.area, fcport->d_id.b.al_pa);
2703 qla2x00_port_logout(fcport->vha, fcport);
2708 qla2x00_issue_lip(struct Scsi_Host *shost)
2710 scsi_qla_host_t *vha = shost_priv(shost);
2712 if (IS_QLAFX00(vha->hw))
2715 qla2x00_loop_reset(vha);
2719 static struct fc_host_statistics *
2720 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
2722 scsi_qla_host_t *vha = shost_priv(shost);
2723 struct qla_hw_data *ha = vha->hw;
2724 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2726 struct link_statistics *stats;
2727 dma_addr_t stats_dma;
2728 struct fc_host_statistics *p = &vha->fc_host_stat;
2730 memset(p, -1, sizeof(*p));
2732 if (IS_QLAFX00(vha->hw))
2735 if (test_bit(UNLOADING, &vha->dpc_flags))
2738 if (unlikely(pci_channel_offline(ha->pdev)))
2741 if (qla2x00_chip_is_down(vha))
2744 stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2747 ql_log(ql_log_warn, vha, 0x707d,
2748 "Failed to allocate memory for stats.\n");
2752 rval = QLA_FUNCTION_FAILED;
2753 if (IS_FWI2_CAPABLE(ha)) {
2754 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, 0);
2755 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
2757 /* Must be in a 'READY' state for statistics retrieval. */
2758 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
2762 if (rval != QLA_SUCCESS)
2765 p->link_failure_count = le32_to_cpu(stats->link_fail_cnt);
2766 p->loss_of_sync_count = le32_to_cpu(stats->loss_sync_cnt);
2767 p->loss_of_signal_count = le32_to_cpu(stats->loss_sig_cnt);
2768 p->prim_seq_protocol_err_count = le32_to_cpu(stats->prim_seq_err_cnt);
2769 p->invalid_tx_word_count = le32_to_cpu(stats->inval_xmit_word_cnt);
2770 p->invalid_crc_count = le32_to_cpu(stats->inval_crc_cnt);
2771 if (IS_FWI2_CAPABLE(ha)) {
2772 p->lip_count = le32_to_cpu(stats->lip_cnt);
2773 p->tx_frames = le32_to_cpu(stats->tx_frames);
2774 p->rx_frames = le32_to_cpu(stats->rx_frames);
2775 p->dumped_frames = le32_to_cpu(stats->discarded_frames);
2776 p->nos_count = le32_to_cpu(stats->nos_rcvd);
2778 le32_to_cpu(stats->dropped_frames) +
2779 le32_to_cpu(stats->discarded_frames);
2780 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
2781 p->rx_words = le64_to_cpu(stats->fpm_recv_word_cnt);
2782 p->tx_words = le64_to_cpu(stats->fpm_xmit_word_cnt);
2784 p->rx_words = vha->qla_stats.input_bytes;
2785 p->tx_words = vha->qla_stats.output_bytes;
2788 p->fcp_control_requests = vha->qla_stats.control_requests;
2789 p->fcp_input_requests = vha->qla_stats.input_requests;
2790 p->fcp_output_requests = vha->qla_stats.output_requests;
2791 p->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
2792 p->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
2793 p->seconds_since_last_reset =
2794 get_jiffies_64() - vha->qla_stats.jiffies_at_last_reset;
2795 do_div(p->seconds_since_last_reset, HZ);
2798 dma_free_coherent(&ha->pdev->dev, sizeof(struct link_statistics),
2805 qla2x00_reset_host_stats(struct Scsi_Host *shost)
2807 scsi_qla_host_t *vha = shost_priv(shost);
2808 struct qla_hw_data *ha = vha->hw;
2809 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2810 struct link_statistics *stats;
2811 dma_addr_t stats_dma;
2813 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2814 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2816 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2818 if (IS_FWI2_CAPABLE(ha)) {
2819 stats = dma_alloc_coherent(&ha->pdev->dev,
2820 sizeof(*stats), &stats_dma, GFP_KERNEL);
2822 ql_log(ql_log_warn, vha, 0x70d7,
2823 "Failed to allocate memory for stats.\n");
2827 /* reset firmware statistics */
2828 qla24xx_get_isp_stats(base_vha, stats, stats_dma, BIT_0);
2830 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2836 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
2838 scsi_qla_host_t *vha = shost_priv(shost);
2840 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost),
2841 sizeof(fc_host_symbolic_name(shost)));
2845 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
2847 scsi_qla_host_t *vha = shost_priv(shost);
2849 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
2853 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
2855 scsi_qla_host_t *vha = shost_priv(shost);
2856 static const uint8_t node_name[WWN_SIZE] = {
2857 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
2859 u64 fabric_name = wwn_to_u64(node_name);
2861 if (vha->device_flags & SWITCH_FOUND)
2862 fabric_name = wwn_to_u64(vha->fabric_node_name);
2864 fc_host_fabric_name(shost) = fabric_name;
2868 qla2x00_get_host_port_state(struct Scsi_Host *shost)
2870 scsi_qla_host_t *vha = shost_priv(shost);
2871 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
2873 if (!base_vha->flags.online) {
2874 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2878 switch (atomic_read(&base_vha->loop_state)) {
2880 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2883 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
2884 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2886 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2889 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2892 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2895 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2901 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
2905 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
2906 scsi_qla_host_t *vha = NULL;
2907 struct qla_hw_data *ha = base_vha->hw;
2909 struct req_que *req = ha->req_q_map[0];
2910 struct qla_qpair *qpair;
2912 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
2914 ql_log(ql_log_warn, vha, 0x707e,
2915 "Vport sanity check failed, status %x\n", ret);
2919 vha = qla24xx_create_vhost(fc_vport);
2921 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
2922 return FC_VPORT_FAILED;
2925 atomic_set(&vha->vp_state, VP_OFFLINE);
2926 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
2928 atomic_set(&vha->vp_state, VP_FAILED);
2930 /* ready to create vport */
2931 ql_log(ql_log_info, vha, 0x7080,
2932 "VP entry id %d assigned.\n", vha->vp_idx);
2934 /* initialized vport states */
2935 atomic_set(&vha->loop_state, LOOP_DOWN);
2936 vha->vp_err_state = VP_ERR_PORTDWN;
2937 vha->vp_prev_err_state = VP_ERR_UNKWN;
2938 /* Check if physical ha port is Up */
2939 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
2940 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
2941 /* Don't retry or attempt login of this virtual port */
2942 ql_dbg(ql_dbg_user, vha, 0x7081,
2943 "Vport loop state is not UP.\n");
2944 atomic_set(&vha->loop_state, LOOP_DEAD);
2946 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
2949 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
2950 if (ha->fw_attributes & BIT_4) {
2951 int prot = 0, guard;
2953 vha->flags.difdix_supported = 1;
2954 ql_dbg(ql_dbg_user, vha, 0x7082,
2955 "Registered for DIF/DIX type 1 and 3 protection.\n");
2956 if (ql2xenabledif == 1)
2957 prot = SHOST_DIX_TYPE0_PROTECTION;
2958 scsi_host_set_prot(vha->host,
2959 prot | SHOST_DIF_TYPE1_PROTECTION
2960 | SHOST_DIF_TYPE2_PROTECTION
2961 | SHOST_DIF_TYPE3_PROTECTION
2962 | SHOST_DIX_TYPE1_PROTECTION
2963 | SHOST_DIX_TYPE2_PROTECTION
2964 | SHOST_DIX_TYPE3_PROTECTION);
2966 guard = SHOST_DIX_GUARD_CRC;
2968 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2969 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2970 guard |= SHOST_DIX_GUARD_IP;
2972 scsi_host_set_guard(vha->host, guard);
2974 vha->flags.difdix_supported = 0;
2977 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
2979 ql_dbg(ql_dbg_user, vha, 0x7083,
2980 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
2981 goto vport_create_failed_2;
2984 /* initialize attributes */
2985 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
2986 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2987 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
2988 fc_host_supported_classes(vha->host) =
2989 fc_host_supported_classes(base_vha->host);
2990 fc_host_supported_speeds(vha->host) =
2991 fc_host_supported_speeds(base_vha->host);
2993 qlt_vport_create(vha, ha);
2994 qla24xx_vport_disable(fc_vport, disable);
2996 if (!ql2xmqsupport || !ha->npiv_info)
2999 /* Create a request queue in QoS mode for the vport */
3000 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
3001 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
3002 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
3004 qos = ha->npiv_info[cnt].q_qos;
3010 qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx, true);
3012 ql_log(ql_log_warn, vha, 0x7084,
3013 "Can't create qpair for VP[%d]\n",
3016 ql_dbg(ql_dbg_multiq, vha, 0xc001,
3017 "Queue pair: %d Qos: %d) created for VP[%d]\n",
3018 qpair->id, qos, vha->vp_idx);
3019 ql_dbg(ql_dbg_user, vha, 0x7085,
3020 "Queue Pair: %d Qos: %d) created for VP[%d]\n",
3021 qpair->id, qos, vha->vp_idx);
3031 vport_create_failed_2:
3032 qla24xx_disable_vp(vha);
3033 qla24xx_deallocate_vp_id(vha);
3034 scsi_host_put(vha->host);
3035 return FC_VPORT_FAILED;
3039 qla24xx_vport_delete(struct fc_vport *fc_vport)
3041 scsi_qla_host_t *vha = fc_vport->dd_data;
3042 struct qla_hw_data *ha = vha->hw;
3043 uint16_t id = vha->vp_idx;
3045 set_bit(VPORT_DELETE, &vha->dpc_flags);
3047 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
3048 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
3052 qla24xx_disable_vp(vha);
3053 qla2x00_wait_for_sess_deletion(vha);
3055 qla_nvme_delete(vha);
3056 vha->flags.delete_progress = 1;
3058 qlt_remove_target(ha, vha);
3060 fc_remove_host(vha->host);
3062 scsi_remove_host(vha->host);
3064 /* Allow timer to run to drain queued items, when removing vp */
3065 qla24xx_deallocate_vp_id(vha);
3067 if (vha->timer_active) {
3068 qla2x00_vp_stop_timer(vha);
3069 ql_dbg(ql_dbg_user, vha, 0x7086,
3070 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
3073 qla2x00_free_fcports(vha);
3075 mutex_lock(&ha->vport_lock);
3076 ha->cur_vport_count--;
3077 clear_bit(vha->vp_idx, ha->vp_idx_map);
3078 mutex_unlock(&ha->vport_lock);
3080 dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l,
3087 if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {
3088 if (qla2xxx_delete_qpair(vha, vha->qpair) != QLA_SUCCESS)
3089 ql_log(ql_log_warn, vha, 0x7087,
3090 "Queue Pair delete failed.\n");
3093 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
3094 scsi_host_put(vha->host);
3099 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
3101 scsi_qla_host_t *vha = fc_vport->dd_data;
3104 qla24xx_disable_vp(vha);
3106 qla24xx_enable_vp(vha);
3111 struct fc_function_template qla2xxx_transport_functions = {
3113 .show_host_node_name = 1,
3114 .show_host_port_name = 1,
3115 .show_host_supported_classes = 1,
3116 .show_host_supported_speeds = 1,
3118 .get_host_port_id = qla2x00_get_host_port_id,
3119 .show_host_port_id = 1,
3120 .get_host_speed = qla2x00_get_host_speed,
3121 .show_host_speed = 1,
3122 .get_host_port_type = qla2x00_get_host_port_type,
3123 .show_host_port_type = 1,
3124 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3125 .show_host_symbolic_name = 1,
3126 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3127 .show_host_system_hostname = 1,
3128 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3129 .show_host_fabric_name = 1,
3130 .get_host_port_state = qla2x00_get_host_port_state,
3131 .show_host_port_state = 1,
3133 .dd_fcrport_size = sizeof(struct fc_port *),
3134 .show_rport_supported_classes = 1,
3136 .get_starget_node_name = qla2x00_get_starget_node_name,
3137 .show_starget_node_name = 1,
3138 .get_starget_port_name = qla2x00_get_starget_port_name,
3139 .show_starget_port_name = 1,
3140 .get_starget_port_id = qla2x00_get_starget_port_id,
3141 .show_starget_port_id = 1,
3143 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3144 .show_rport_dev_loss_tmo = 1,
3146 .issue_fc_host_lip = qla2x00_issue_lip,
3147 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3148 .terminate_rport_io = qla2x00_terminate_rport_io,
3149 .get_fc_host_stats = qla2x00_get_fc_host_stats,
3150 .reset_fc_host_stats = qla2x00_reset_host_stats,
3152 .vport_create = qla24xx_vport_create,
3153 .vport_disable = qla24xx_vport_disable,
3154 .vport_delete = qla24xx_vport_delete,
3155 .bsg_request = qla24xx_bsg_request,
3156 .bsg_timeout = qla24xx_bsg_timeout,
3159 struct fc_function_template qla2xxx_transport_vport_functions = {
3161 .show_host_node_name = 1,
3162 .show_host_port_name = 1,
3163 .show_host_supported_classes = 1,
3165 .get_host_port_id = qla2x00_get_host_port_id,
3166 .show_host_port_id = 1,
3167 .get_host_speed = qla2x00_get_host_speed,
3168 .show_host_speed = 1,
3169 .get_host_port_type = qla2x00_get_host_port_type,
3170 .show_host_port_type = 1,
3171 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3172 .show_host_symbolic_name = 1,
3173 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3174 .show_host_system_hostname = 1,
3175 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3176 .show_host_fabric_name = 1,
3177 .get_host_port_state = qla2x00_get_host_port_state,
3178 .show_host_port_state = 1,
3180 .dd_fcrport_size = sizeof(struct fc_port *),
3181 .show_rport_supported_classes = 1,
3183 .get_starget_node_name = qla2x00_get_starget_node_name,
3184 .show_starget_node_name = 1,
3185 .get_starget_port_name = qla2x00_get_starget_port_name,
3186 .show_starget_port_name = 1,
3187 .get_starget_port_id = qla2x00_get_starget_port_id,
3188 .show_starget_port_id = 1,
3190 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3191 .show_rport_dev_loss_tmo = 1,
3193 .issue_fc_host_lip = qla2x00_issue_lip,
3194 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3195 .terminate_rport_io = qla2x00_terminate_rport_io,
3196 .get_fc_host_stats = qla2x00_get_fc_host_stats,
3197 .reset_fc_host_stats = qla2x00_reset_host_stats,
3199 .bsg_request = qla24xx_bsg_request,
3200 .bsg_timeout = qla24xx_bsg_timeout,
3204 qla2x00_init_host_attr(scsi_qla_host_t *vha)
3206 struct qla_hw_data *ha = vha->hw;
3207 u32 speeds = FC_PORTSPEED_UNKNOWN;
3209 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
3210 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3211 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
3212 fc_host_supported_classes(vha->host) = ha->base_qpair->enable_class_2 ?
3213 (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
3214 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
3215 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
3217 if (IS_CNA_CAPABLE(ha))
3218 speeds = FC_PORTSPEED_10GBIT;
3219 else if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
3220 if (ha->max_supported_speed == 2) {
3221 if (ha->min_supported_speed <= 6)
3222 speeds |= FC_PORTSPEED_64GBIT;
3224 if (ha->max_supported_speed == 2 ||
3225 ha->max_supported_speed == 1) {
3226 if (ha->min_supported_speed <= 5)
3227 speeds |= FC_PORTSPEED_32GBIT;
3229 if (ha->max_supported_speed == 2 ||
3230 ha->max_supported_speed == 1 ||
3231 ha->max_supported_speed == 0) {
3232 if (ha->min_supported_speed <= 4)
3233 speeds |= FC_PORTSPEED_16GBIT;
3235 if (ha->max_supported_speed == 1 ||
3236 ha->max_supported_speed == 0) {
3237 if (ha->min_supported_speed <= 3)
3238 speeds |= FC_PORTSPEED_8GBIT;
3240 if (ha->max_supported_speed == 0) {
3241 if (ha->min_supported_speed <= 2)
3242 speeds |= FC_PORTSPEED_4GBIT;
3244 } else if (IS_QLA2031(ha))
3245 speeds = FC_PORTSPEED_16GBIT|FC_PORTSPEED_8GBIT|
3247 else if (IS_QLA25XX(ha) || IS_QLAFX00(ha))
3248 speeds = FC_PORTSPEED_8GBIT|FC_PORTSPEED_4GBIT|
3249 FC_PORTSPEED_2GBIT|FC_PORTSPEED_1GBIT;
3250 else if (IS_QLA24XX_TYPE(ha))
3251 speeds = FC_PORTSPEED_4GBIT|FC_PORTSPEED_2GBIT|
3253 else if (IS_QLA23XX(ha))
3254 speeds = FC_PORTSPEED_2GBIT|FC_PORTSPEED_1GBIT;
3256 speeds = FC_PORTSPEED_1GBIT;
3258 fc_host_supported_speeds(vha->host) = speeds;