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 mutex_lock(&ha->optrom_mutex);
33 if (IS_P3P_TYPE(ha)) {
34 if (off < ha->md_template_size) {
35 rval = memory_read_from_buffer(buf, count,
36 &off, ha->md_tmplt_hdr, ha->md_template_size);
38 off -= ha->md_template_size;
39 rval = memory_read_from_buffer(buf, count,
40 &off, ha->md_dump, ha->md_dump_size);
42 } else if (ha->mctp_dumped && ha->mctp_dump_reading) {
43 rval = memory_read_from_buffer(buf, count, &off, ha->mctp_dump,
45 } else if (ha->fw_dump_reading) {
46 rval = memory_read_from_buffer(buf, count, &off, ha->fw_dump,
51 mutex_unlock(&ha->optrom_mutex);
56 qla2x00_sysfs_write_fw_dump(struct file *filp, struct kobject *kobj,
57 struct bin_attribute *bin_attr,
58 char *buf, loff_t off, size_t count)
60 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
61 struct device, kobj)));
62 struct qla_hw_data *ha = vha->hw;
68 reading = simple_strtol(buf, NULL, 10);
71 if (!ha->fw_dump_reading)
74 ql_log(ql_log_info, vha, 0x705d,
75 "Firmware dump cleared on (%ld).\n", vha->host_no);
77 if (IS_P3P_TYPE(ha)) {
81 ha->fw_dump_reading = 0;
85 if (ha->fw_dumped && !ha->fw_dump_reading) {
86 ha->fw_dump_reading = 1;
88 ql_log(ql_log_info, vha, 0x705e,
89 "Raw firmware dump ready for read on (%ld).\n",
94 qla2x00_alloc_fw_dump(vha);
99 qla82xx_set_reset_owner(vha);
100 qla82xx_idc_unlock(ha);
101 } else if (IS_QLA8044(ha)) {
102 qla8044_idc_lock(ha);
103 qla82xx_set_reset_owner(vha);
104 qla8044_idc_unlock(ha);
106 qla2x00_system_error(vha);
109 if (IS_P3P_TYPE(ha)) {
110 if (ha->md_tmplt_hdr)
111 ql_dbg(ql_dbg_user, vha, 0x705b,
112 "MiniDump supported with this firmware.\n");
114 ql_dbg(ql_dbg_user, vha, 0x709d,
115 "MiniDump not supported with this firmware.\n");
120 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
123 if (!ha->mctp_dump_reading)
125 ql_log(ql_log_info, vha, 0x70c1,
126 "MCTP dump cleared on (%ld).\n", vha->host_no);
127 ha->mctp_dump_reading = 0;
131 if (ha->mctp_dumped && !ha->mctp_dump_reading) {
132 ha->mctp_dump_reading = 1;
133 ql_log(ql_log_info, vha, 0x70c2,
134 "Raw mctp dump ready for read on (%ld).\n",
142 static struct bin_attribute sysfs_fw_dump_attr = {
145 .mode = S_IRUSR | S_IWUSR,
148 .read = qla2x00_sysfs_read_fw_dump,
149 .write = qla2x00_sysfs_write_fw_dump,
153 qla2x00_sysfs_read_nvram(struct file *filp, struct kobject *kobj,
154 struct bin_attribute *bin_attr,
155 char *buf, loff_t off, size_t count)
157 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
158 struct device, kobj)));
159 struct qla_hw_data *ha = vha->hw;
161 struct active_regions active_regions = { };
163 if (!capable(CAP_SYS_ADMIN))
166 mutex_lock(&ha->optrom_mutex);
167 if (qla2x00_chip_is_down(vha)) {
168 mutex_unlock(&ha->optrom_mutex);
172 if (!IS_NOCACHE_VPD_TYPE(ha)) {
173 mutex_unlock(&ha->optrom_mutex);
177 faddr = ha->flt_region_nvram;
178 if (IS_QLA28XX(ha)) {
179 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
180 faddr = ha->flt_region_nvram_sec;
182 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
184 mutex_unlock(&ha->optrom_mutex);
187 return memory_read_from_buffer(buf, count, &off, ha->nvram,
192 qla2x00_sysfs_write_nvram(struct file *filp, struct kobject *kobj,
193 struct bin_attribute *bin_attr,
194 char *buf, loff_t off, size_t count)
196 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
197 struct device, kobj)));
198 struct qla_hw_data *ha = vha->hw;
201 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
202 !ha->isp_ops->write_nvram)
205 /* Checksum NVRAM. */
206 if (IS_FWI2_CAPABLE(ha)) {
210 iter = (uint32_t *)buf;
212 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++, iter++)
213 chksum += le32_to_cpu(*iter);
214 chksum = ~chksum + 1;
215 *iter = cpu_to_le32(chksum);
220 iter = (uint8_t *)buf;
222 for (cnt = 0; cnt < count - 1; cnt++)
224 chksum = ~chksum + 1;
228 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
229 ql_log(ql_log_warn, vha, 0x705f,
230 "HBA not online, failing NVRAM update.\n");
234 mutex_lock(&ha->optrom_mutex);
235 if (qla2x00_chip_is_down(vha)) {
236 mutex_unlock(&ha->optrom_mutex);
241 ha->isp_ops->write_nvram(vha, buf, ha->nvram_base, count);
242 ha->isp_ops->read_nvram(vha, ha->nvram, ha->nvram_base,
244 mutex_unlock(&ha->optrom_mutex);
246 ql_dbg(ql_dbg_user, vha, 0x7060,
247 "Setting ISP_ABORT_NEEDED\n");
248 /* NVRAM settings take effect immediately. */
249 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
250 qla2xxx_wake_dpc(vha);
251 qla2x00_wait_for_chip_reset(vha);
256 static struct bin_attribute sysfs_nvram_attr = {
259 .mode = S_IRUSR | S_IWUSR,
262 .read = qla2x00_sysfs_read_nvram,
263 .write = qla2x00_sysfs_write_nvram,
267 qla2x00_sysfs_read_optrom(struct file *filp, struct kobject *kobj,
268 struct bin_attribute *bin_attr,
269 char *buf, loff_t off, size_t count)
271 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
272 struct device, kobj)));
273 struct qla_hw_data *ha = vha->hw;
276 mutex_lock(&ha->optrom_mutex);
278 if (ha->optrom_state != QLA_SREADING)
281 rval = memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
282 ha->optrom_region_size);
285 mutex_unlock(&ha->optrom_mutex);
291 qla2x00_sysfs_write_optrom(struct file *filp, struct kobject *kobj,
292 struct bin_attribute *bin_attr,
293 char *buf, loff_t off, size_t count)
295 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
296 struct device, kobj)));
297 struct qla_hw_data *ha = vha->hw;
299 mutex_lock(&ha->optrom_mutex);
301 if (ha->optrom_state != QLA_SWRITING) {
302 mutex_unlock(&ha->optrom_mutex);
305 if (off > ha->optrom_region_size) {
306 mutex_unlock(&ha->optrom_mutex);
309 if (off + count > ha->optrom_region_size)
310 count = ha->optrom_region_size - off;
312 memcpy(&ha->optrom_buffer[off], buf, count);
313 mutex_unlock(&ha->optrom_mutex);
318 static struct bin_attribute sysfs_optrom_attr = {
321 .mode = S_IRUSR | S_IWUSR,
324 .read = qla2x00_sysfs_read_optrom,
325 .write = qla2x00_sysfs_write_optrom,
329 qla2x00_sysfs_write_optrom_ctl(struct file *filp, struct kobject *kobj,
330 struct bin_attribute *bin_attr,
331 char *buf, loff_t off, size_t count)
333 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
334 struct device, kobj)));
335 struct qla_hw_data *ha = vha->hw;
337 uint32_t size = ha->optrom_size;
339 ssize_t rval = count;
344 if (unlikely(pci_channel_offline(ha->pdev)))
347 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
349 if (start > ha->optrom_size)
351 if (size > ha->optrom_size - start)
352 size = ha->optrom_size - start;
354 mutex_lock(&ha->optrom_mutex);
355 if (qla2x00_chip_is_down(vha)) {
356 mutex_unlock(&ha->optrom_mutex);
361 if (ha->optrom_state != QLA_SREADING &&
362 ha->optrom_state != QLA_SWRITING) {
366 ha->optrom_state = QLA_SWAITING;
368 ql_dbg(ql_dbg_user, vha, 0x7061,
369 "Freeing flash region allocation -- 0x%x bytes.\n",
370 ha->optrom_region_size);
372 vfree(ha->optrom_buffer);
373 ha->optrom_buffer = NULL;
376 if (ha->optrom_state != QLA_SWAITING) {
381 ha->optrom_region_start = start;
382 ha->optrom_region_size = size;
384 ha->optrom_state = QLA_SREADING;
385 ha->optrom_buffer = vzalloc(ha->optrom_region_size);
386 if (ha->optrom_buffer == NULL) {
387 ql_log(ql_log_warn, vha, 0x7062,
388 "Unable to allocate memory for optrom retrieval "
389 "(%x).\n", ha->optrom_region_size);
391 ha->optrom_state = QLA_SWAITING;
396 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
397 ql_log(ql_log_warn, vha, 0x7063,
398 "HBA not online, failing NVRAM update.\n");
403 ql_dbg(ql_dbg_user, vha, 0x7064,
404 "Reading flash region -- 0x%x/0x%x.\n",
405 ha->optrom_region_start, ha->optrom_region_size);
407 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
408 ha->optrom_region_start, ha->optrom_region_size);
411 if (ha->optrom_state != QLA_SWAITING) {
417 * We need to be more restrictive on which FLASH regions are
418 * allowed to be updated via user-space. Regions accessible
419 * via this method include:
421 * ISP21xx/ISP22xx/ISP23xx type boards:
423 * 0x000000 -> 0x020000 -- Boot code.
425 * ISP2322/ISP24xx type boards:
427 * 0x000000 -> 0x07ffff -- Boot code.
428 * 0x080000 -> 0x0fffff -- Firmware.
430 * ISP25xx type boards:
432 * 0x000000 -> 0x07ffff -- Boot code.
433 * 0x080000 -> 0x0fffff -- Firmware.
434 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
436 * > ISP25xx type boards:
438 * None -- should go through BSG.
441 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
443 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
446 ql_log(ql_log_warn, vha, 0x7065,
447 "Invalid start region 0x%x/0x%x.\n", start, size);
452 ha->optrom_region_start = start;
453 ha->optrom_region_size = size;
455 ha->optrom_state = QLA_SWRITING;
456 ha->optrom_buffer = vzalloc(ha->optrom_region_size);
457 if (ha->optrom_buffer == NULL) {
458 ql_log(ql_log_warn, vha, 0x7066,
459 "Unable to allocate memory for optrom update "
460 "(%x)\n", ha->optrom_region_size);
462 ha->optrom_state = QLA_SWAITING;
467 ql_dbg(ql_dbg_user, vha, 0x7067,
468 "Staging flash region write -- 0x%x/0x%x.\n",
469 ha->optrom_region_start, ha->optrom_region_size);
473 if (ha->optrom_state != QLA_SWRITING) {
478 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
479 ql_log(ql_log_warn, vha, 0x7068,
480 "HBA not online, failing flash update.\n");
485 ql_dbg(ql_dbg_user, vha, 0x7069,
486 "Writing flash region -- 0x%x/0x%x.\n",
487 ha->optrom_region_start, ha->optrom_region_size);
489 rval = ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
490 ha->optrom_region_start, ha->optrom_region_size);
499 mutex_unlock(&ha->optrom_mutex);
503 static struct bin_attribute sysfs_optrom_ctl_attr = {
505 .name = "optrom_ctl",
509 .write = qla2x00_sysfs_write_optrom_ctl,
513 qla2x00_sysfs_read_vpd(struct file *filp, struct kobject *kobj,
514 struct bin_attribute *bin_attr,
515 char *buf, loff_t off, size_t count)
517 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
518 struct device, kobj)));
519 struct qla_hw_data *ha = vha->hw;
521 struct active_regions active_regions = { };
523 if (unlikely(pci_channel_offline(ha->pdev)))
526 if (!capable(CAP_SYS_ADMIN))
529 if (IS_NOCACHE_VPD_TYPE(ha))
532 faddr = ha->flt_region_vpd << 2;
534 if (IS_QLA28XX(ha)) {
535 qla28xx_get_aux_images(vha, &active_regions);
536 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
537 faddr = ha->flt_region_vpd_sec << 2;
539 ql_dbg(ql_dbg_init, vha, 0x7070,
540 "Loading %s nvram image.\n",
541 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
542 "primary" : "secondary");
545 mutex_lock(&ha->optrom_mutex);
546 if (qla2x00_chip_is_down(vha)) {
547 mutex_unlock(&ha->optrom_mutex);
551 ha->isp_ops->read_optrom(vha, ha->vpd, faddr, ha->vpd_size);
552 mutex_unlock(&ha->optrom_mutex);
554 ha->isp_ops->read_optrom(vha, ha->vpd, faddr, ha->vpd_size);
556 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
560 qla2x00_sysfs_write_vpd(struct file *filp, struct kobject *kobj,
561 struct bin_attribute *bin_attr,
562 char *buf, loff_t off, size_t count)
564 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
565 struct device, kobj)));
566 struct qla_hw_data *ha = vha->hw;
569 if (unlikely(pci_channel_offline(ha->pdev)))
572 if (qla2x00_chip_is_down(vha))
575 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
576 !ha->isp_ops->write_nvram)
579 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
580 ql_log(ql_log_warn, vha, 0x706a,
581 "HBA not online, failing VPD update.\n");
585 mutex_lock(&ha->optrom_mutex);
586 if (qla2x00_chip_is_down(vha)) {
587 mutex_unlock(&ha->optrom_mutex);
592 ha->isp_ops->write_nvram(vha, buf, ha->vpd_base, count);
593 ha->isp_ops->read_nvram(vha, ha->vpd, ha->vpd_base, count);
595 /* Update flash version information for 4Gb & above. */
596 if (!IS_FWI2_CAPABLE(ha)) {
597 mutex_unlock(&ha->optrom_mutex);
601 tmp_data = vmalloc(256);
603 mutex_unlock(&ha->optrom_mutex);
604 ql_log(ql_log_warn, vha, 0x706b,
605 "Unable to allocate memory for VPD information update.\n");
608 ha->isp_ops->get_flash_version(vha, tmp_data);
611 mutex_unlock(&ha->optrom_mutex);
616 static struct bin_attribute sysfs_vpd_attr = {
619 .mode = S_IRUSR | S_IWUSR,
622 .read = qla2x00_sysfs_read_vpd,
623 .write = qla2x00_sysfs_write_vpd,
627 qla2x00_sysfs_read_sfp(struct file *filp, struct kobject *kobj,
628 struct bin_attribute *bin_attr,
629 char *buf, loff_t off, size_t count)
631 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
632 struct device, kobj)));
635 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < SFP_DEV_SIZE)
638 mutex_lock(&vha->hw->optrom_mutex);
639 if (qla2x00_chip_is_down(vha)) {
640 mutex_unlock(&vha->hw->optrom_mutex);
644 rval = qla2x00_read_sfp_dev(vha, buf, count);
645 mutex_unlock(&vha->hw->optrom_mutex);
653 static struct bin_attribute sysfs_sfp_attr = {
656 .mode = S_IRUSR | S_IWUSR,
658 .size = SFP_DEV_SIZE,
659 .read = qla2x00_sysfs_read_sfp,
663 qla2x00_sysfs_write_reset(struct file *filp, struct kobject *kobj,
664 struct bin_attribute *bin_attr,
665 char *buf, loff_t off, size_t count)
667 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
668 struct device, kobj)));
669 struct qla_hw_data *ha = vha->hw;
670 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
672 uint32_t idc_control;
673 uint8_t *tmp_data = NULL;
678 type = simple_strtol(buf, NULL, 10);
681 ql_log(ql_log_info, vha, 0x706e,
682 "Issuing ISP reset.\n");
684 scsi_block_requests(vha->host);
685 if (IS_QLA82XX(ha)) {
686 ha->flags.isp82xx_no_md_cap = 1;
687 qla82xx_idc_lock(ha);
688 qla82xx_set_reset_owner(vha);
689 qla82xx_idc_unlock(ha);
690 } else if (IS_QLA8044(ha)) {
691 qla8044_idc_lock(ha);
692 idc_control = qla8044_rd_reg(ha,
693 QLA8044_IDC_DRV_CTRL);
694 qla8044_wr_reg(ha, QLA8044_IDC_DRV_CTRL,
695 (idc_control | GRACEFUL_RESET_BIT1));
696 qla82xx_set_reset_owner(vha);
697 qla8044_idc_unlock(ha);
699 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
700 qla2xxx_wake_dpc(vha);
702 qla2x00_wait_for_chip_reset(vha);
703 scsi_unblock_requests(vha->host);
706 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha))
709 ql_log(ql_log_info, vha, 0x706f,
710 "Issuing MPI reset.\n");
712 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
713 uint32_t idc_control;
715 qla83xx_idc_lock(vha, 0);
716 __qla83xx_get_idc_control(vha, &idc_control);
717 idc_control |= QLA83XX_IDC_GRACEFUL_RESET;
718 __qla83xx_set_idc_control(vha, idc_control);
719 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
720 QLA8XXX_DEV_NEED_RESET);
721 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
722 qla83xx_idc_unlock(vha, 0);
725 /* Make sure FC side is not in reset */
726 WARN_ON_ONCE(qla2x00_wait_for_hba_online(vha) !=
729 /* Issue MPI reset */
730 scsi_block_requests(vha->host);
731 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
732 ql_log(ql_log_warn, vha, 0x7070,
733 "MPI reset failed.\n");
734 scsi_unblock_requests(vha->host);
738 if (!IS_P3P_TYPE(ha) || vha != base_vha) {
739 ql_log(ql_log_info, vha, 0x7071,
740 "FCoE ctx reset not supported.\n");
744 ql_log(ql_log_info, vha, 0x7072,
745 "Issuing FCoE ctx reset.\n");
746 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
747 qla2xxx_wake_dpc(vha);
748 qla2x00_wait_for_fcoe_ctx_reset(vha);
753 ql_log(ql_log_info, vha, 0x70bc,
754 "Disabling Reset by IDC control\n");
755 qla83xx_idc_lock(vha, 0);
756 __qla83xx_get_idc_control(vha, &idc_control);
757 idc_control |= QLA83XX_IDC_RESET_DISABLED;
758 __qla83xx_set_idc_control(vha, idc_control);
759 qla83xx_idc_unlock(vha, 0);
764 ql_log(ql_log_info, vha, 0x70bd,
765 "Enabling Reset by IDC control\n");
766 qla83xx_idc_lock(vha, 0);
767 __qla83xx_get_idc_control(vha, &idc_control);
768 idc_control &= ~QLA83XX_IDC_RESET_DISABLED;
769 __qla83xx_set_idc_control(vha, idc_control);
770 qla83xx_idc_unlock(vha, 0);
773 ql_dbg(ql_dbg_user, vha, 0x70e0,
774 "Updating cache versions without reset ");
776 tmp_data = vmalloc(256);
778 ql_log(ql_log_warn, vha, 0x70e1,
779 "Unable to allocate memory for VPD information update.\n");
782 ha->isp_ops->get_flash_version(vha, tmp_data);
789 static struct bin_attribute sysfs_reset_attr = {
795 .write = qla2x00_sysfs_write_reset,
799 qla2x00_issue_logo(struct file *filp, struct kobject *kobj,
800 struct bin_attribute *bin_attr,
801 char *buf, loff_t off, size_t count)
803 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
804 struct device, kobj)));
808 if (!capable(CAP_SYS_ADMIN))
811 if (unlikely(pci_channel_offline(vha->hw->pdev)))
814 if (qla2x00_chip_is_down(vha))
817 type = simple_strtol(buf, NULL, 10);
819 did.b.domain = (type & 0x00ff0000) >> 16;
820 did.b.area = (type & 0x0000ff00) >> 8;
821 did.b.al_pa = (type & 0x000000ff);
823 ql_log(ql_log_info, vha, 0xd04d, "portid=%02x%02x%02x done\n",
824 did.b.domain, did.b.area, did.b.al_pa);
826 ql_log(ql_log_info, vha, 0x70e4, "%s: %d\n", __func__, type);
828 qla24xx_els_dcmd_iocb(vha, ELS_DCMD_LOGO, did);
832 static struct bin_attribute sysfs_issue_logo_attr = {
834 .name = "issue_logo",
838 .write = qla2x00_issue_logo,
842 qla2x00_sysfs_read_xgmac_stats(struct file *filp, struct kobject *kobj,
843 struct bin_attribute *bin_attr,
844 char *buf, loff_t off, size_t count)
846 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
847 struct device, kobj)));
848 struct qla_hw_data *ha = vha->hw;
850 uint16_t actual_size;
852 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
855 if (unlikely(pci_channel_offline(ha->pdev)))
857 mutex_lock(&vha->hw->optrom_mutex);
858 if (qla2x00_chip_is_down(vha)) {
859 mutex_unlock(&vha->hw->optrom_mutex);
866 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
867 &ha->xgmac_data_dma, GFP_KERNEL);
868 if (!ha->xgmac_data) {
869 mutex_unlock(&vha->hw->optrom_mutex);
870 ql_log(ql_log_warn, vha, 0x7076,
871 "Unable to allocate memory for XGMAC read-data.\n");
877 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
879 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
880 XGMAC_DATA_SIZE, &actual_size);
882 mutex_unlock(&vha->hw->optrom_mutex);
883 if (rval != QLA_SUCCESS) {
884 ql_log(ql_log_warn, vha, 0x7077,
885 "Unable to read XGMAC data (%x).\n", rval);
889 count = actual_size > count ? count : actual_size;
890 memcpy(buf, ha->xgmac_data, count);
895 static struct bin_attribute sysfs_xgmac_stats_attr = {
897 .name = "xgmac_stats",
901 .read = qla2x00_sysfs_read_xgmac_stats,
905 qla2x00_sysfs_read_dcbx_tlv(struct file *filp, struct kobject *kobj,
906 struct bin_attribute *bin_attr,
907 char *buf, loff_t off, size_t count)
909 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
910 struct device, kobj)));
911 struct qla_hw_data *ha = vha->hw;
914 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
919 mutex_lock(&vha->hw->optrom_mutex);
920 if (qla2x00_chip_is_down(vha)) {
921 mutex_unlock(&vha->hw->optrom_mutex);
925 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
926 &ha->dcbx_tlv_dma, GFP_KERNEL);
928 mutex_unlock(&vha->hw->optrom_mutex);
929 ql_log(ql_log_warn, vha, 0x7078,
930 "Unable to allocate memory for DCBX TLV read-data.\n");
935 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
937 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
940 mutex_unlock(&vha->hw->optrom_mutex);
942 if (rval != QLA_SUCCESS) {
943 ql_log(ql_log_warn, vha, 0x7079,
944 "Unable to read DCBX TLV (%x).\n", rval);
948 memcpy(buf, ha->dcbx_tlv, count);
953 static struct bin_attribute sysfs_dcbx_tlv_attr = {
959 .read = qla2x00_sysfs_read_dcbx_tlv,
962 static struct sysfs_entry {
964 struct bin_attribute *attr;
966 } bin_file_entries[] = {
967 { "fw_dump", &sysfs_fw_dump_attr, },
968 { "nvram", &sysfs_nvram_attr, },
969 { "optrom", &sysfs_optrom_attr, },
970 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
971 { "vpd", &sysfs_vpd_attr, 1 },
972 { "sfp", &sysfs_sfp_attr, 1 },
973 { "reset", &sysfs_reset_attr, },
974 { "issue_logo", &sysfs_issue_logo_attr, },
975 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
976 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
981 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
983 struct Scsi_Host *host = vha->host;
984 struct sysfs_entry *iter;
987 for (iter = bin_file_entries; iter->name; iter++) {
988 if (iter->type && !IS_FWI2_CAPABLE(vha->hw))
990 if (iter->type == 2 && !IS_QLA25XX(vha->hw))
992 if (iter->type == 3 && !(IS_CNA_CAPABLE(vha->hw)))
995 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
998 ql_log(ql_log_warn, vha, 0x00f3,
999 "Unable to create sysfs %s binary attribute (%d).\n",
1002 ql_dbg(ql_dbg_init, vha, 0x00f4,
1003 "Successfully created sysfs %s binary attribute.\n",
1009 qla2x00_free_sysfs_attr(scsi_qla_host_t *vha, bool stop_beacon)
1011 struct Scsi_Host *host = vha->host;
1012 struct sysfs_entry *iter;
1013 struct qla_hw_data *ha = vha->hw;
1015 for (iter = bin_file_entries; iter->name; iter++) {
1016 if (iter->type && !IS_FWI2_CAPABLE(ha))
1018 if (iter->type == 2 && !IS_QLA25XX(ha))
1020 if (iter->type == 3 && !(IS_CNA_CAPABLE(ha)))
1022 if (iter->type == 0x27 &&
1023 (!IS_QLA27XX(ha) || !IS_QLA28XX(ha)))
1026 sysfs_remove_bin_file(&host->shost_gendev.kobj,
1030 if (stop_beacon && ha->beacon_blink_led == 1)
1031 ha->isp_ops->beacon_off(vha);
1034 /* Scsi_Host attributes. */
1037 qla2x00_driver_version_show(struct device *dev,
1038 struct device_attribute *attr, char *buf)
1040 return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
1044 qla2x00_fw_version_show(struct device *dev,
1045 struct device_attribute *attr, char *buf)
1047 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1048 struct qla_hw_data *ha = vha->hw;
1051 return scnprintf(buf, PAGE_SIZE, "%s\n",
1052 ha->isp_ops->fw_version_str(vha, fw_str, sizeof(fw_str)));
1056 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
1059 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1060 struct qla_hw_data *ha = vha->hw;
1063 if (IS_QLAFX00(vha->hw)) {
1064 return scnprintf(buf, PAGE_SIZE, "%s\n",
1065 vha->hw->mr.serial_num);
1066 } else if (IS_FWI2_CAPABLE(ha)) {
1067 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE - 1);
1068 return strlen(strcat(buf, "\n"));
1071 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1072 return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
1077 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
1080 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1082 return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
1086 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
1089 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1090 struct qla_hw_data *ha = vha->hw;
1092 if (IS_QLAFX00(vha->hw))
1093 return scnprintf(buf, PAGE_SIZE, "%s\n",
1094 vha->hw->mr.hw_version);
1096 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
1097 ha->product_id[0], ha->product_id[1], ha->product_id[2],
1102 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
1105 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1107 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
1111 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1114 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1116 return scnprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_desc);
1120 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1123 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1126 return scnprintf(buf, PAGE_SIZE, "%s\n",
1127 vha->hw->isp_ops->pci_info_str(vha, pci_info,
1132 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1135 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1136 struct qla_hw_data *ha = vha->hw;
1139 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
1140 atomic_read(&vha->loop_state) == LOOP_DEAD ||
1141 vha->device_flags & DFLG_NO_CABLE)
1142 len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
1143 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1144 qla2x00_chip_is_down(vha))
1145 len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1147 len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
1149 switch (ha->current_topology) {
1151 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1154 len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1157 len += scnprintf(buf + len, PAGE_SIZE-len,
1158 "N_Port to N_Port\n");
1161 len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1164 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1172 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1175 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1178 switch (vha->hw->zio_mode) {
1179 case QLA_ZIO_MODE_6:
1180 len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1182 case QLA_ZIO_DISABLED:
1183 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1190 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1191 const char *buf, size_t count)
1193 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1194 struct qla_hw_data *ha = vha->hw;
1198 if (!IS_ZIO_SUPPORTED(ha))
1201 if (sscanf(buf, "%d", &val) != 1)
1205 zio_mode = QLA_ZIO_MODE_6;
1207 zio_mode = QLA_ZIO_DISABLED;
1209 /* Update per-hba values and queue a reset. */
1210 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1211 ha->zio_mode = zio_mode;
1212 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1218 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1221 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1223 return scnprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
1227 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1228 const char *buf, size_t count)
1230 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1234 if (sscanf(buf, "%d", &val) != 1)
1236 if (val > 25500 || val < 100)
1239 zio_timer = (uint16_t)(val / 100);
1240 vha->hw->zio_timer = zio_timer;
1246 qla_zio_threshold_show(struct device *dev, struct device_attribute *attr,
1249 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1251 return scnprintf(buf, PAGE_SIZE, "%d exchanges\n",
1252 vha->hw->last_zio_threshold);
1256 qla_zio_threshold_store(struct device *dev, struct device_attribute *attr,
1257 const char *buf, size_t count)
1259 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1262 if (vha->hw->zio_mode != QLA_ZIO_MODE_6)
1264 if (sscanf(buf, "%d", &val) != 1)
1266 if (val < 0 || val > 256)
1269 atomic_set(&vha->hw->zio_threshold, val);
1274 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1277 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1280 if (vha->hw->beacon_blink_led)
1281 len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1283 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1288 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1289 const char *buf, size_t count)
1291 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1292 struct qla_hw_data *ha = vha->hw;
1296 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1299 if (sscanf(buf, "%d", &val) != 1)
1302 mutex_lock(&vha->hw->optrom_mutex);
1303 if (qla2x00_chip_is_down(vha)) {
1304 mutex_unlock(&vha->hw->optrom_mutex);
1305 ql_log(ql_log_warn, vha, 0x707a,
1306 "Abort ISP active -- ignoring beacon request.\n");
1311 rval = ha->isp_ops->beacon_on(vha);
1313 rval = ha->isp_ops->beacon_off(vha);
1315 if (rval != QLA_SUCCESS)
1318 mutex_unlock(&vha->hw->optrom_mutex);
1324 qla2x00_optrom_bios_version_show(struct device *dev,
1325 struct device_attribute *attr, char *buf)
1327 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1328 struct qla_hw_data *ha = vha->hw;
1330 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1331 ha->bios_revision[0]);
1335 qla2x00_optrom_efi_version_show(struct device *dev,
1336 struct device_attribute *attr, char *buf)
1338 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1339 struct qla_hw_data *ha = vha->hw;
1341 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1342 ha->efi_revision[0]);
1346 qla2x00_optrom_fcode_version_show(struct device *dev,
1347 struct device_attribute *attr, char *buf)
1349 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1350 struct qla_hw_data *ha = vha->hw;
1352 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1353 ha->fcode_revision[0]);
1357 qla2x00_optrom_fw_version_show(struct device *dev,
1358 struct device_attribute *attr, char *buf)
1360 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1361 struct qla_hw_data *ha = vha->hw;
1363 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1364 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1365 ha->fw_revision[3]);
1369 qla2x00_optrom_gold_fw_version_show(struct device *dev,
1370 struct device_attribute *attr, char *buf)
1372 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1373 struct qla_hw_data *ha = vha->hw;
1375 if (!IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
1376 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1377 return scnprintf(buf, PAGE_SIZE, "\n");
1379 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%d)\n",
1380 ha->gold_fw_version[0], ha->gold_fw_version[1],
1381 ha->gold_fw_version[2], ha->gold_fw_version[3]);
1385 qla2x00_total_isp_aborts_show(struct device *dev,
1386 struct device_attribute *attr, char *buf)
1388 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1390 return scnprintf(buf, PAGE_SIZE, "%d\n",
1391 vha->qla_stats.total_isp_aborts);
1395 qla24xx_84xx_fw_version_show(struct device *dev,
1396 struct device_attribute *attr, char *buf)
1398 int rval = QLA_SUCCESS;
1399 uint16_t status[2] = { 0 };
1400 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1401 struct qla_hw_data *ha = vha->hw;
1403 if (!IS_QLA84XX(ha))
1404 return scnprintf(buf, PAGE_SIZE, "\n");
1406 if (!ha->cs84xx->op_fw_version) {
1407 rval = qla84xx_verify_chip(vha, status);
1409 if (!rval && !status[0])
1410 return scnprintf(buf, PAGE_SIZE, "%u\n",
1411 (uint32_t)ha->cs84xx->op_fw_version);
1414 return scnprintf(buf, PAGE_SIZE, "\n");
1418 qla2x00_serdes_version_show(struct device *dev, struct device_attribute *attr,
1421 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1422 struct qla_hw_data *ha = vha->hw;
1424 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1425 return scnprintf(buf, PAGE_SIZE, "\n");
1427 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1428 ha->serdes_version[0], ha->serdes_version[1],
1429 ha->serdes_version[2]);
1433 qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1436 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1437 struct qla_hw_data *ha = vha->hw;
1439 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha) && !IS_QLA8044(ha) &&
1440 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1441 return scnprintf(buf, PAGE_SIZE, "\n");
1443 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
1444 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
1445 ha->mpi_capabilities);
1449 qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1452 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1453 struct qla_hw_data *ha = vha->hw;
1455 if (!IS_QLA81XX(ha) && !IS_QLA8031(ha))
1456 return scnprintf(buf, PAGE_SIZE, "\n");
1458 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1459 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
1463 qla2x00_flash_block_size_show(struct device *dev,
1464 struct device_attribute *attr, char *buf)
1466 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1467 struct qla_hw_data *ha = vha->hw;
1469 return scnprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1473 qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1476 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1478 if (!IS_CNA_CAPABLE(vha->hw))
1479 return scnprintf(buf, PAGE_SIZE, "\n");
1481 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1485 qla2x00_vn_port_mac_address_show(struct device *dev,
1486 struct device_attribute *attr, char *buf)
1488 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1490 if (!IS_CNA_CAPABLE(vha->hw))
1491 return scnprintf(buf, PAGE_SIZE, "\n");
1493 return scnprintf(buf, PAGE_SIZE, "%pMR\n", vha->fcoe_vn_port_mac);
1497 qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1500 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1502 return scnprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1506 qla2x00_thermal_temp_show(struct device *dev,
1507 struct device_attribute *attr, char *buf)
1509 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1513 mutex_lock(&vha->hw->optrom_mutex);
1514 if (qla2x00_chip_is_down(vha)) {
1515 mutex_unlock(&vha->hw->optrom_mutex);
1516 ql_log(ql_log_warn, vha, 0x70dc, "ISP reset active.\n");
1520 if (vha->hw->flags.eeh_busy) {
1521 mutex_unlock(&vha->hw->optrom_mutex);
1522 ql_log(ql_log_warn, vha, 0x70dd, "PCI EEH busy.\n");
1526 rc = qla2x00_get_thermal_temp(vha, &temp);
1527 mutex_unlock(&vha->hw->optrom_mutex);
1528 if (rc == QLA_SUCCESS)
1529 return scnprintf(buf, PAGE_SIZE, "%d\n", temp);
1532 return scnprintf(buf, PAGE_SIZE, "\n");
1536 qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1539 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1540 int rval = QLA_FUNCTION_FAILED;
1544 if (IS_QLAFX00(vha->hw)) {
1545 pstate = qlafx00_fw_state_show(dev, attr, buf);
1546 return scnprintf(buf, PAGE_SIZE, "0x%x\n", pstate);
1549 mutex_lock(&vha->hw->optrom_mutex);
1550 if (qla2x00_chip_is_down(vha)) {
1551 mutex_unlock(&vha->hw->optrom_mutex);
1552 ql_log(ql_log_warn, vha, 0x707c,
1553 "ISP reset active.\n");
1555 } else if (vha->hw->flags.eeh_busy) {
1556 mutex_unlock(&vha->hw->optrom_mutex);
1560 rval = qla2x00_get_firmware_state(vha, state);
1561 mutex_unlock(&vha->hw->optrom_mutex);
1563 if (rval != QLA_SUCCESS) {
1564 memset(state, -1, sizeof(state));
1565 rval = qla2x00_get_firmware_state(vha, state);
1568 return scnprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1569 state[0], state[1], state[2], state[3], state[4], state[5]);
1573 qla2x00_diag_requests_show(struct device *dev,
1574 struct device_attribute *attr, char *buf)
1576 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1578 if (!IS_BIDI_CAPABLE(vha->hw))
1579 return scnprintf(buf, PAGE_SIZE, "\n");
1581 return scnprintf(buf, PAGE_SIZE, "%llu\n", vha->bidi_stats.io_count);
1585 qla2x00_diag_megabytes_show(struct device *dev,
1586 struct device_attribute *attr, char *buf)
1588 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1590 if (!IS_BIDI_CAPABLE(vha->hw))
1591 return scnprintf(buf, PAGE_SIZE, "\n");
1593 return scnprintf(buf, PAGE_SIZE, "%llu\n",
1594 vha->bidi_stats.transfer_bytes >> 20);
1598 qla2x00_fw_dump_size_show(struct device *dev, struct device_attribute *attr,
1601 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1602 struct qla_hw_data *ha = vha->hw;
1607 else if (IS_P3P_TYPE(ha))
1608 size = ha->md_template_size + ha->md_dump_size;
1610 size = ha->fw_dump_len;
1612 return scnprintf(buf, PAGE_SIZE, "%d\n", size);
1616 qla2x00_allow_cna_fw_dump_show(struct device *dev,
1617 struct device_attribute *attr, char *buf)
1619 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1621 if (!IS_P3P_TYPE(vha->hw))
1622 return scnprintf(buf, PAGE_SIZE, "\n");
1624 return scnprintf(buf, PAGE_SIZE, "%s\n",
1625 vha->hw->allow_cna_fw_dump ? "true" : "false");
1629 qla2x00_allow_cna_fw_dump_store(struct device *dev,
1630 struct device_attribute *attr, const char *buf, size_t count)
1632 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1635 if (!IS_P3P_TYPE(vha->hw))
1638 if (sscanf(buf, "%d", &val) != 1)
1641 vha->hw->allow_cna_fw_dump = val != 0;
1647 qla2x00_pep_version_show(struct device *dev, struct device_attribute *attr,
1650 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1651 struct qla_hw_data *ha = vha->hw;
1653 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1654 return scnprintf(buf, PAGE_SIZE, "\n");
1656 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1657 ha->pep_version[0], ha->pep_version[1], ha->pep_version[2]);
1661 qla2x00_min_supported_speed_show(struct device *dev,
1662 struct device_attribute *attr, char *buf)
1664 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1665 struct qla_hw_data *ha = vha->hw;
1667 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1668 return scnprintf(buf, PAGE_SIZE, "\n");
1670 return scnprintf(buf, PAGE_SIZE, "%s\n",
1671 ha->min_supported_speed == 6 ? "64Gps" :
1672 ha->min_supported_speed == 5 ? "32Gps" :
1673 ha->min_supported_speed == 4 ? "16Gps" :
1674 ha->min_supported_speed == 3 ? "8Gps" :
1675 ha->min_supported_speed == 2 ? "4Gps" :
1676 ha->min_supported_speed != 0 ? "unknown" : "");
1680 qla2x00_max_supported_speed_show(struct device *dev,
1681 struct device_attribute *attr, char *buf)
1683 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1684 struct qla_hw_data *ha = vha->hw;
1686 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
1687 return scnprintf(buf, PAGE_SIZE, "\n");
1689 return scnprintf(buf, PAGE_SIZE, "%s\n",
1690 ha->max_supported_speed == 2 ? "64Gps" :
1691 ha->max_supported_speed == 1 ? "32Gps" :
1692 ha->max_supported_speed == 0 ? "16Gps" : "unknown");
1696 qla2x00_port_speed_store(struct device *dev, struct device_attribute *attr,
1697 const char *buf, size_t count)
1699 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1702 int mode = QLA_SET_DATA_RATE_LR;
1703 struct qla_hw_data *ha = vha->hw;
1705 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha)) {
1706 ql_log(ql_log_warn, vha, 0x70d8,
1707 "Speed setting not supported \n");
1711 rval = kstrtol(buf, 10, &type);
1715 if (type == 40 || type == 80 || type == 160 ||
1717 ql_dbg(ql_dbg_user, vha, 0x70d9,
1718 "Setting will be affected after a loss of sync\n");
1720 mode = QLA_SET_DATA_RATE_NOLR;
1723 oldspeed = ha->set_data_rate;
1727 ha->set_data_rate = PORT_SPEED_AUTO;
1730 ha->set_data_rate = PORT_SPEED_4GB;
1733 ha->set_data_rate = PORT_SPEED_8GB;
1736 ha->set_data_rate = PORT_SPEED_16GB;
1739 ha->set_data_rate = PORT_SPEED_32GB;
1742 ql_log(ql_log_warn, vha, 0x1199,
1743 "Unrecognized speed setting:%lx. Setting Autoneg\n",
1745 ha->set_data_rate = PORT_SPEED_AUTO;
1748 if (qla2x00_chip_is_down(vha) || (oldspeed == ha->set_data_rate))
1751 ql_log(ql_log_info, vha, 0x70da,
1752 "Setting speed to %lx Gbps \n", type);
1754 rval = qla2x00_set_data_rate(vha, mode);
1755 if (rval != QLA_SUCCESS)
1762 qla2x00_port_speed_show(struct device *dev, struct device_attribute *attr,
1765 struct scsi_qla_host *vha = shost_priv(dev_to_shost(dev));
1766 struct qla_hw_data *ha = vha->hw;
1768 char *spd[7] = {"0", "0", "0", "4", "8", "16", "32"};
1770 rval = qla2x00_get_data_rate(vha);
1771 if (rval != QLA_SUCCESS) {
1772 ql_log(ql_log_warn, vha, 0x70db,
1773 "Unable to get port speed rval:%zd\n", rval);
1777 ql_log(ql_log_info, vha, 0x70d6,
1778 "port speed:%d\n", ha->link_data_rate);
1780 return scnprintf(buf, PAGE_SIZE, "%s\n", spd[ha->link_data_rate]);
1786 qlini_mode_show(struct device *dev, struct device_attribute *attr, char *buf)
1788 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1791 len += scnprintf(buf + len, PAGE_SIZE-len,
1792 "Supported options: enabled | disabled | dual | exclusive\n");
1795 len += scnprintf(buf + len, PAGE_SIZE-len, "Current selection: ");
1797 switch (vha->qlini_mode) {
1798 case QLA2XXX_INI_MODE_EXCLUSIVE:
1799 len += scnprintf(buf + len, PAGE_SIZE-len,
1800 QLA2XXX_INI_MODE_STR_EXCLUSIVE);
1802 case QLA2XXX_INI_MODE_DISABLED:
1803 len += scnprintf(buf + len, PAGE_SIZE-len,
1804 QLA2XXX_INI_MODE_STR_DISABLED);
1806 case QLA2XXX_INI_MODE_ENABLED:
1807 len += scnprintf(buf + len, PAGE_SIZE-len,
1808 QLA2XXX_INI_MODE_STR_ENABLED);
1810 case QLA2XXX_INI_MODE_DUAL:
1811 len += scnprintf(buf + len, PAGE_SIZE-len,
1812 QLA2XXX_INI_MODE_STR_DUAL);
1815 len += scnprintf(buf + len, PAGE_SIZE-len, "\n");
1820 static char *mode_to_str[] = {
1827 #define NEED_EXCH_OFFLOAD(_exchg) ((_exchg) > FW_DEF_EXCHANGES_CNT)
1828 static int qla_set_ini_mode(scsi_qla_host_t *vha, int op)
1834 MODE_CHANGE_NO_ACTION,
1835 TARGET_STILL_ACTIVE,
1837 int action = NO_ACTION;
1839 u8 eo_toggle = 0; /* exchange offload flipped */
1841 switch (vha->qlini_mode) {
1842 case QLA2XXX_INI_MODE_DISABLED:
1844 case QLA2XXX_INI_MODE_DISABLED:
1845 if (qla_tgt_mode_enabled(vha)) {
1846 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1847 vha->hw->flags.exchoffld_enabled)
1849 if (((vha->ql2xexchoffld !=
1850 vha->u_ql2xexchoffld) &&
1851 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1854 * The number of exchange to be offload
1855 * was tweaked or offload option was
1858 action = MODE_CHANGE_ACCEPT;
1860 action = MODE_CHANGE_NO_ACTION;
1863 action = MODE_CHANGE_NO_ACTION;
1866 case QLA2XXX_INI_MODE_EXCLUSIVE:
1867 if (qla_tgt_mode_enabled(vha)) {
1868 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1869 vha->hw->flags.exchoffld_enabled)
1871 if (((vha->ql2xexchoffld !=
1872 vha->u_ql2xexchoffld) &&
1873 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1876 * The number of exchange to be offload
1877 * was tweaked or offload option was
1880 action = MODE_CHANGE_ACCEPT;
1882 action = MODE_CHANGE_NO_ACTION;
1885 action = MODE_CHANGE_ACCEPT;
1888 case QLA2XXX_INI_MODE_DUAL:
1889 action = MODE_CHANGE_ACCEPT;
1890 /* active_mode is target only, reset it to dual */
1891 if (qla_tgt_mode_enabled(vha)) {
1893 action = MODE_CHANGE_ACCEPT;
1895 action = MODE_CHANGE_NO_ACTION;
1899 case QLA2XXX_INI_MODE_ENABLED:
1900 if (qla_tgt_mode_enabled(vha))
1901 action = TARGET_STILL_ACTIVE;
1903 action = MODE_CHANGE_ACCEPT;
1910 case QLA2XXX_INI_MODE_EXCLUSIVE:
1912 case QLA2XXX_INI_MODE_EXCLUSIVE:
1913 if (qla_tgt_mode_enabled(vha)) {
1914 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1915 vha->hw->flags.exchoffld_enabled)
1917 if (((vha->ql2xexchoffld !=
1918 vha->u_ql2xexchoffld) &&
1919 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1922 * The number of exchange to be offload
1923 * was tweaked or offload option was
1926 action = MODE_CHANGE_ACCEPT;
1934 case QLA2XXX_INI_MODE_DISABLED:
1935 if (qla_tgt_mode_enabled(vha)) {
1936 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld) !=
1937 vha->hw->flags.exchoffld_enabled)
1939 if (((vha->ql2xexchoffld !=
1940 vha->u_ql2xexchoffld) &&
1941 NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld)) ||
1943 action = MODE_CHANGE_ACCEPT;
1945 action = MODE_CHANGE_NO_ACTION;
1947 action = MODE_CHANGE_NO_ACTION;
1950 case QLA2XXX_INI_MODE_DUAL: /* exclusive -> dual */
1951 if (qla_tgt_mode_enabled(vha)) {
1952 action = MODE_CHANGE_ACCEPT;
1955 action = MODE_CHANGE_ACCEPT;
1958 case QLA2XXX_INI_MODE_ENABLED:
1959 if (qla_tgt_mode_enabled(vha))
1960 action = TARGET_STILL_ACTIVE;
1962 if (vha->hw->flags.fw_started)
1963 action = MODE_CHANGE_NO_ACTION;
1965 action = MODE_CHANGE_ACCEPT;
1971 case QLA2XXX_INI_MODE_ENABLED:
1973 case QLA2XXX_INI_MODE_ENABLED:
1974 if (NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg) !=
1975 vha->hw->flags.exchoffld_enabled)
1977 if (((vha->ql2xiniexchg != vha->u_ql2xiniexchg) &&
1978 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg)) ||
1980 action = MODE_CHANGE_ACCEPT;
1984 case QLA2XXX_INI_MODE_DUAL:
1985 case QLA2XXX_INI_MODE_DISABLED:
1986 action = MODE_CHANGE_ACCEPT;
1989 action = MODE_CHANGE_NO_ACTION;
1994 case QLA2XXX_INI_MODE_DUAL:
1996 case QLA2XXX_INI_MODE_DUAL:
1997 if (qla_tgt_mode_enabled(vha) ||
1998 qla_dual_mode_enabled(vha)) {
1999 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2000 vha->u_ql2xiniexchg) !=
2001 vha->hw->flags.exchoffld_enabled)
2004 if ((((vha->ql2xexchoffld +
2005 vha->ql2xiniexchg) !=
2006 (vha->u_ql2xiniexchg +
2007 vha->u_ql2xexchoffld)) &&
2008 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2009 vha->u_ql2xexchoffld)) || eo_toggle)
2010 action = MODE_CHANGE_ACCEPT;
2014 if (NEED_EXCH_OFFLOAD(vha->u_ql2xexchoffld +
2015 vha->u_ql2xiniexchg) !=
2016 vha->hw->flags.exchoffld_enabled)
2019 if ((((vha->ql2xexchoffld + vha->ql2xiniexchg)
2020 != (vha->u_ql2xiniexchg +
2021 vha->u_ql2xexchoffld)) &&
2022 NEED_EXCH_OFFLOAD(vha->u_ql2xiniexchg +
2023 vha->u_ql2xexchoffld)) || eo_toggle)
2024 action = MODE_CHANGE_NO_ACTION;
2030 case QLA2XXX_INI_MODE_DISABLED:
2031 if (qla_tgt_mode_enabled(vha) ||
2032 qla_dual_mode_enabled(vha)) {
2033 /* turning off initiator mode */
2035 action = MODE_CHANGE_ACCEPT;
2037 action = MODE_CHANGE_NO_ACTION;
2041 case QLA2XXX_INI_MODE_EXCLUSIVE:
2042 if (qla_tgt_mode_enabled(vha) ||
2043 qla_dual_mode_enabled(vha)) {
2045 action = MODE_CHANGE_ACCEPT;
2047 action = MODE_CHANGE_ACCEPT;
2051 case QLA2XXX_INI_MODE_ENABLED:
2052 if (qla_tgt_mode_enabled(vha) ||
2053 qla_dual_mode_enabled(vha)) {
2054 action = TARGET_STILL_ACTIVE;
2056 action = MODE_CHANGE_ACCEPT;
2063 case MODE_CHANGE_ACCEPT:
2064 ql_log(ql_log_warn, vha, 0xffff,
2065 "Mode change accepted. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2066 mode_to_str[vha->qlini_mode], mode_to_str[op],
2067 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2068 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2070 vha->qlini_mode = op;
2071 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2072 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2075 vha->flags.online = 1;
2076 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2079 case MODE_CHANGE_NO_ACTION:
2080 ql_log(ql_log_warn, vha, 0xffff,
2081 "Mode is set. No action taken. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2082 mode_to_str[vha->qlini_mode], mode_to_str[op],
2083 vha->ql2xexchoffld, vha->u_ql2xexchoffld,
2084 vha->ql2xiniexchg, vha->u_ql2xiniexchg);
2085 vha->qlini_mode = op;
2086 vha->ql2xexchoffld = vha->u_ql2xexchoffld;
2087 vha->ql2xiniexchg = vha->u_ql2xiniexchg;
2090 case TARGET_STILL_ACTIVE:
2091 ql_log(ql_log_warn, vha, 0xffff,
2092 "Target Mode is active. Unable to change Mode.\n");
2097 ql_log(ql_log_warn, vha, 0xffff,
2098 "Mode unchange. No action taken. %d|%d pct %d|%d.\n",
2099 vha->qlini_mode, op,
2100 vha->ql2xexchoffld, vha->u_ql2xexchoffld);
2108 qlini_mode_store(struct device *dev, struct device_attribute *attr,
2109 const char *buf, size_t count)
2111 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2117 if (strncasecmp(QLA2XXX_INI_MODE_STR_EXCLUSIVE, buf,
2118 strlen(QLA2XXX_INI_MODE_STR_EXCLUSIVE)) == 0)
2119 ini = QLA2XXX_INI_MODE_EXCLUSIVE;
2120 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DISABLED, buf,
2121 strlen(QLA2XXX_INI_MODE_STR_DISABLED)) == 0)
2122 ini = QLA2XXX_INI_MODE_DISABLED;
2123 else if (strncasecmp(QLA2XXX_INI_MODE_STR_ENABLED, buf,
2124 strlen(QLA2XXX_INI_MODE_STR_ENABLED)) == 0)
2125 ini = QLA2XXX_INI_MODE_ENABLED;
2126 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DUAL, buf,
2127 strlen(QLA2XXX_INI_MODE_STR_DUAL)) == 0)
2128 ini = QLA2XXX_INI_MODE_DUAL;
2132 qla_set_ini_mode(vha, ini);
2137 ql2xexchoffld_show(struct device *dev, struct device_attribute *attr,
2140 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2143 len += scnprintf(buf + len, PAGE_SIZE-len,
2144 "target exchange: new %d : current: %d\n\n",
2145 vha->u_ql2xexchoffld, vha->ql2xexchoffld);
2147 len += scnprintf(buf + len, PAGE_SIZE-len,
2148 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2155 ql2xexchoffld_store(struct device *dev, struct device_attribute *attr,
2156 const char *buf, size_t count)
2158 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2161 if (sscanf(buf, "%d", &val) != 1)
2164 if (val > FW_MAX_EXCHANGES_CNT)
2165 val = FW_MAX_EXCHANGES_CNT;
2169 vha->u_ql2xexchoffld = val;
2174 ql2xiniexchg_show(struct device *dev, struct device_attribute *attr,
2177 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2180 len += scnprintf(buf + len, PAGE_SIZE-len,
2181 "target exchange: new %d : current: %d\n\n",
2182 vha->u_ql2xiniexchg, vha->ql2xiniexchg);
2184 len += scnprintf(buf + len, PAGE_SIZE-len,
2185 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2192 ql2xiniexchg_store(struct device *dev, struct device_attribute *attr,
2193 const char *buf, size_t count)
2195 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2198 if (sscanf(buf, "%d", &val) != 1)
2201 if (val > FW_MAX_EXCHANGES_CNT)
2202 val = FW_MAX_EXCHANGES_CNT;
2206 vha->u_ql2xiniexchg = val;
2211 qla2x00_dif_bundle_statistics_show(struct device *dev,
2212 struct device_attribute *attr, char *buf)
2214 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2215 struct qla_hw_data *ha = vha->hw;
2217 return scnprintf(buf, PAGE_SIZE,
2218 "cross=%llu read=%llu write=%llu kalloc=%llu dma_alloc=%llu unusable=%u\n",
2219 ha->dif_bundle_crossed_pages, ha->dif_bundle_reads,
2220 ha->dif_bundle_writes, ha->dif_bundle_kallocs,
2221 ha->dif_bundle_dma_allocs, ha->pool.unusable.count);
2225 qla2x00_fw_attr_show(struct device *dev,
2226 struct device_attribute *attr, char *buf)
2228 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2229 struct qla_hw_data *ha = vha->hw;
2231 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
2232 return scnprintf(buf, PAGE_SIZE, "\n");
2234 return scnprintf(buf, PAGE_SIZE, "%llx\n",
2235 (uint64_t)ha->fw_attributes_ext[1] << 48 |
2236 (uint64_t)ha->fw_attributes_ext[0] << 32 |
2237 (uint64_t)ha->fw_attributes_h << 16 |
2238 (uint64_t)ha->fw_attributes);
2242 qla2x00_port_no_show(struct device *dev, struct device_attribute *attr,
2245 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
2247 return scnprintf(buf, PAGE_SIZE, "%u\n", vha->hw->port_no);
2250 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_driver_version_show, NULL);
2251 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
2252 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
2253 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
2254 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
2255 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
2256 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
2257 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
2258 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
2259 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
2260 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
2261 qla2x00_zio_timer_store);
2262 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
2263 qla2x00_beacon_store);
2264 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
2265 qla2x00_optrom_bios_version_show, NULL);
2266 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
2267 qla2x00_optrom_efi_version_show, NULL);
2268 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
2269 qla2x00_optrom_fcode_version_show, NULL);
2270 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
2272 static DEVICE_ATTR(optrom_gold_fw_version, S_IRUGO,
2273 qla2x00_optrom_gold_fw_version_show, NULL);
2274 static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
2276 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
2278 static DEVICE_ATTR(serdes_version, 0444, qla2x00_serdes_version_show, NULL);
2279 static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
2280 static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
2281 static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
2283 static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
2284 static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
2285 qla2x00_vn_port_mac_address_show, NULL);
2286 static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
2287 static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
2288 static DEVICE_ATTR(thermal_temp, S_IRUGO, qla2x00_thermal_temp_show, NULL);
2289 static DEVICE_ATTR(diag_requests, S_IRUGO, qla2x00_diag_requests_show, NULL);
2290 static DEVICE_ATTR(diag_megabytes, S_IRUGO, qla2x00_diag_megabytes_show, NULL);
2291 static DEVICE_ATTR(fw_dump_size, S_IRUGO, qla2x00_fw_dump_size_show, NULL);
2292 static DEVICE_ATTR(allow_cna_fw_dump, S_IRUGO | S_IWUSR,
2293 qla2x00_allow_cna_fw_dump_show,
2294 qla2x00_allow_cna_fw_dump_store);
2295 static DEVICE_ATTR(pep_version, S_IRUGO, qla2x00_pep_version_show, NULL);
2296 static DEVICE_ATTR(min_supported_speed, 0444,
2297 qla2x00_min_supported_speed_show, NULL);
2298 static DEVICE_ATTR(max_supported_speed, 0444,
2299 qla2x00_max_supported_speed_show, NULL);
2300 static DEVICE_ATTR(zio_threshold, 0644,
2301 qla_zio_threshold_show,
2302 qla_zio_threshold_store);
2303 static DEVICE_ATTR_RW(qlini_mode);
2304 static DEVICE_ATTR_RW(ql2xexchoffld);
2305 static DEVICE_ATTR_RW(ql2xiniexchg);
2306 static DEVICE_ATTR(dif_bundle_statistics, 0444,
2307 qla2x00_dif_bundle_statistics_show, NULL);
2308 static DEVICE_ATTR(port_speed, 0644, qla2x00_port_speed_show,
2309 qla2x00_port_speed_store);
2310 static DEVICE_ATTR(port_no, 0444, qla2x00_port_no_show, NULL);
2311 static DEVICE_ATTR(fw_attr, 0444, qla2x00_fw_attr_show, NULL);
2314 struct device_attribute *qla2x00_host_attrs[] = {
2315 &dev_attr_driver_version,
2316 &dev_attr_fw_version,
2317 &dev_attr_serial_num,
2320 &dev_attr_model_name,
2321 &dev_attr_model_desc,
2323 &dev_attr_link_state,
2325 &dev_attr_zio_timer,
2327 &dev_attr_optrom_bios_version,
2328 &dev_attr_optrom_efi_version,
2329 &dev_attr_optrom_fcode_version,
2330 &dev_attr_optrom_fw_version,
2331 &dev_attr_84xx_fw_version,
2332 &dev_attr_total_isp_aborts,
2333 &dev_attr_serdes_version,
2334 &dev_attr_mpi_version,
2335 &dev_attr_phy_version,
2336 &dev_attr_flash_block_size,
2338 &dev_attr_vn_port_mac_address,
2339 &dev_attr_fabric_param,
2341 &dev_attr_optrom_gold_fw_version,
2342 &dev_attr_thermal_temp,
2343 &dev_attr_diag_requests,
2344 &dev_attr_diag_megabytes,
2345 &dev_attr_fw_dump_size,
2346 &dev_attr_allow_cna_fw_dump,
2347 &dev_attr_pep_version,
2348 &dev_attr_min_supported_speed,
2349 &dev_attr_max_supported_speed,
2350 &dev_attr_zio_threshold,
2351 &dev_attr_dif_bundle_statistics,
2352 &dev_attr_port_speed,
2355 NULL, /* reserve for qlini_mode */
2356 NULL, /* reserve for ql2xiniexchg */
2357 NULL, /* reserve for ql2xexchoffld */
2361 void qla_insert_tgt_attrs(void)
2363 struct device_attribute **attr;
2365 /* advance to empty slot */
2366 for (attr = &qla2x00_host_attrs[0]; *attr; ++attr)
2369 *attr = &dev_attr_qlini_mode;
2371 *attr = &dev_attr_ql2xiniexchg;
2373 *attr = &dev_attr_ql2xexchoffld;
2376 /* Host attributes. */
2379 qla2x00_get_host_port_id(struct Scsi_Host *shost)
2381 scsi_qla_host_t *vha = shost_priv(shost);
2383 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
2384 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
2388 qla2x00_get_host_speed(struct Scsi_Host *shost)
2390 scsi_qla_host_t *vha = shost_priv(shost);
2393 if (IS_QLAFX00(vha->hw)) {
2394 qlafx00_get_host_speed(shost);
2398 switch (vha->hw->link_data_rate) {
2399 case PORT_SPEED_1GB:
2400 speed = FC_PORTSPEED_1GBIT;
2402 case PORT_SPEED_2GB:
2403 speed = FC_PORTSPEED_2GBIT;
2405 case PORT_SPEED_4GB:
2406 speed = FC_PORTSPEED_4GBIT;
2408 case PORT_SPEED_8GB:
2409 speed = FC_PORTSPEED_8GBIT;
2411 case PORT_SPEED_10GB:
2412 speed = FC_PORTSPEED_10GBIT;
2414 case PORT_SPEED_16GB:
2415 speed = FC_PORTSPEED_16GBIT;
2417 case PORT_SPEED_32GB:
2418 speed = FC_PORTSPEED_32GBIT;
2420 case PORT_SPEED_64GB:
2421 speed = FC_PORTSPEED_64GBIT;
2424 speed = FC_PORTSPEED_UNKNOWN;
2428 fc_host_speed(shost) = speed;
2432 qla2x00_get_host_port_type(struct Scsi_Host *shost)
2434 scsi_qla_host_t *vha = shost_priv(shost);
2438 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
2441 switch (vha->hw->current_topology) {
2443 port_type = FC_PORTTYPE_LPORT;
2446 port_type = FC_PORTTYPE_NLPORT;
2449 port_type = FC_PORTTYPE_PTP;
2452 port_type = FC_PORTTYPE_NPORT;
2455 port_type = FC_PORTTYPE_UNKNOWN;
2459 fc_host_port_type(shost) = port_type;
2463 qla2x00_get_starget_node_name(struct scsi_target *starget)
2465 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2466 scsi_qla_host_t *vha = shost_priv(host);
2470 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2471 if (fcport->rport &&
2472 starget->id == fcport->rport->scsi_target_id) {
2473 node_name = wwn_to_u64(fcport->node_name);
2478 fc_starget_node_name(starget) = node_name;
2482 qla2x00_get_starget_port_name(struct scsi_target *starget)
2484 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2485 scsi_qla_host_t *vha = shost_priv(host);
2489 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2490 if (fcport->rport &&
2491 starget->id == fcport->rport->scsi_target_id) {
2492 port_name = wwn_to_u64(fcport->port_name);
2497 fc_starget_port_name(starget) = port_name;
2501 qla2x00_get_starget_port_id(struct scsi_target *starget)
2503 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
2504 scsi_qla_host_t *vha = shost_priv(host);
2506 uint32_t port_id = ~0U;
2508 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2509 if (fcport->rport &&
2510 starget->id == fcport->rport->scsi_target_id) {
2511 port_id = fcport->d_id.b.domain << 16 |
2512 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2517 fc_starget_port_id(starget) = port_id;
2521 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
2523 rport->dev_loss_tmo = timeout ? timeout : 1;
2527 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
2529 struct Scsi_Host *host = rport_to_shost(rport);
2530 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2531 unsigned long flags;
2536 /* Now that the rport has been deleted, set the fcport state to
2538 qla2x00_set_fcport_state(fcport, FCS_DEVICE_DEAD);
2541 * Transport has effectively 'deleted' the rport, clear
2542 * all local references.
2544 spin_lock_irqsave(host->host_lock, flags);
2545 fcport->rport = fcport->drport = NULL;
2546 *((fc_port_t **)rport->dd_data) = NULL;
2547 spin_unlock_irqrestore(host->host_lock, flags);
2549 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2552 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2553 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2559 qla2x00_terminate_rport_io(struct fc_rport *rport)
2561 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
2566 if (test_bit(UNLOADING, &fcport->vha->dpc_flags))
2569 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
2572 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
2573 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
2577 * At this point all fcport's software-states are cleared. Perform any
2578 * final cleanup of firmware resources (PCBs and XCBs).
2580 if (fcport->loop_id != FC_NO_LOOP_ID) {
2581 if (IS_FWI2_CAPABLE(fcport->vha->hw))
2582 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
2583 fcport->loop_id, fcport->d_id.b.domain,
2584 fcport->d_id.b.area, fcport->d_id.b.al_pa);
2586 qla2x00_port_logout(fcport->vha, fcport);
2591 qla2x00_issue_lip(struct Scsi_Host *shost)
2593 scsi_qla_host_t *vha = shost_priv(shost);
2595 if (IS_QLAFX00(vha->hw))
2598 qla2x00_loop_reset(vha);
2602 static struct fc_host_statistics *
2603 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
2605 scsi_qla_host_t *vha = shost_priv(shost);
2606 struct qla_hw_data *ha = vha->hw;
2607 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2609 struct link_statistics *stats;
2610 dma_addr_t stats_dma;
2611 struct fc_host_statistics *p = &vha->fc_host_stat;
2613 memset(p, -1, sizeof(*p));
2615 if (IS_QLAFX00(vha->hw))
2618 if (test_bit(UNLOADING, &vha->dpc_flags))
2621 if (unlikely(pci_channel_offline(ha->pdev)))
2624 if (qla2x00_chip_is_down(vha))
2627 stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2630 ql_log(ql_log_warn, vha, 0x707d,
2631 "Failed to allocate memory for stats.\n");
2635 rval = QLA_FUNCTION_FAILED;
2636 if (IS_FWI2_CAPABLE(ha)) {
2637 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, 0);
2638 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
2640 /* Must be in a 'READY' state for statistics retrieval. */
2641 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
2645 if (rval != QLA_SUCCESS)
2648 p->link_failure_count = stats->link_fail_cnt;
2649 p->loss_of_sync_count = stats->loss_sync_cnt;
2650 p->loss_of_signal_count = stats->loss_sig_cnt;
2651 p->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
2652 p->invalid_tx_word_count = stats->inval_xmit_word_cnt;
2653 p->invalid_crc_count = stats->inval_crc_cnt;
2654 if (IS_FWI2_CAPABLE(ha)) {
2655 p->lip_count = stats->lip_cnt;
2656 p->tx_frames = stats->tx_frames;
2657 p->rx_frames = stats->rx_frames;
2658 p->dumped_frames = stats->discarded_frames;
2659 p->nos_count = stats->nos_rcvd;
2661 stats->dropped_frames + stats->discarded_frames;
2662 p->rx_words = vha->qla_stats.input_bytes;
2663 p->tx_words = vha->qla_stats.output_bytes;
2665 p->fcp_control_requests = vha->qla_stats.control_requests;
2666 p->fcp_input_requests = vha->qla_stats.input_requests;
2667 p->fcp_output_requests = vha->qla_stats.output_requests;
2668 p->fcp_input_megabytes = vha->qla_stats.input_bytes >> 20;
2669 p->fcp_output_megabytes = vha->qla_stats.output_bytes >> 20;
2670 p->seconds_since_last_reset =
2671 get_jiffies_64() - vha->qla_stats.jiffies_at_last_reset;
2672 do_div(p->seconds_since_last_reset, HZ);
2675 dma_free_coherent(&ha->pdev->dev, sizeof(struct link_statistics),
2682 qla2x00_reset_host_stats(struct Scsi_Host *shost)
2684 scsi_qla_host_t *vha = shost_priv(shost);
2685 struct qla_hw_data *ha = vha->hw;
2686 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
2687 struct link_statistics *stats;
2688 dma_addr_t stats_dma;
2690 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2691 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2693 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2695 if (IS_FWI2_CAPABLE(ha)) {
2696 stats = dma_alloc_coherent(&ha->pdev->dev,
2697 sizeof(*stats), &stats_dma, GFP_KERNEL);
2699 ql_log(ql_log_warn, vha, 0x70d7,
2700 "Failed to allocate memory for stats.\n");
2704 /* reset firmware statistics */
2705 qla24xx_get_isp_stats(base_vha, stats, stats_dma, BIT_0);
2707 dma_free_coherent(&ha->pdev->dev, sizeof(*stats),
2713 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
2715 scsi_qla_host_t *vha = shost_priv(shost);
2717 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost),
2718 sizeof(fc_host_symbolic_name(shost)));
2722 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
2724 scsi_qla_host_t *vha = shost_priv(shost);
2726 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
2730 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
2732 scsi_qla_host_t *vha = shost_priv(shost);
2733 static const uint8_t node_name[WWN_SIZE] = {
2734 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
2736 u64 fabric_name = wwn_to_u64(node_name);
2738 if (vha->device_flags & SWITCH_FOUND)
2739 fabric_name = wwn_to_u64(vha->fabric_node_name);
2741 fc_host_fabric_name(shost) = fabric_name;
2745 qla2x00_get_host_port_state(struct Scsi_Host *shost)
2747 scsi_qla_host_t *vha = shost_priv(shost);
2748 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
2750 if (!base_vha->flags.online) {
2751 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
2755 switch (atomic_read(&base_vha->loop_state)) {
2757 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2760 if (test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags))
2761 fc_host_port_state(shost) = FC_PORTSTATE_DIAGNOSTICS;
2763 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2766 fc_host_port_state(shost) = FC_PORTSTATE_LINKDOWN;
2769 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
2772 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
2778 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
2782 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
2783 scsi_qla_host_t *vha = NULL;
2784 struct qla_hw_data *ha = base_vha->hw;
2786 struct req_que *req = ha->req_q_map[0];
2787 struct qla_qpair *qpair;
2789 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
2791 ql_log(ql_log_warn, vha, 0x707e,
2792 "Vport sanity check failed, status %x\n", ret);
2796 vha = qla24xx_create_vhost(fc_vport);
2798 ql_log(ql_log_warn, vha, 0x707f, "Vport create host failed.\n");
2799 return FC_VPORT_FAILED;
2802 atomic_set(&vha->vp_state, VP_OFFLINE);
2803 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
2805 atomic_set(&vha->vp_state, VP_FAILED);
2807 /* ready to create vport */
2808 ql_log(ql_log_info, vha, 0x7080,
2809 "VP entry id %d assigned.\n", vha->vp_idx);
2811 /* initialized vport states */
2812 atomic_set(&vha->loop_state, LOOP_DOWN);
2813 vha->vp_err_state = VP_ERR_PORTDWN;
2814 vha->vp_prev_err_state = VP_ERR_UNKWN;
2815 /* Check if physical ha port is Up */
2816 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
2817 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
2818 /* Don't retry or attempt login of this virtual port */
2819 ql_dbg(ql_dbg_user, vha, 0x7081,
2820 "Vport loop state is not UP.\n");
2821 atomic_set(&vha->loop_state, LOOP_DEAD);
2823 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
2826 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
2827 if (ha->fw_attributes & BIT_4) {
2828 int prot = 0, guard;
2830 vha->flags.difdix_supported = 1;
2831 ql_dbg(ql_dbg_user, vha, 0x7082,
2832 "Registered for DIF/DIX type 1 and 3 protection.\n");
2833 if (ql2xenabledif == 1)
2834 prot = SHOST_DIX_TYPE0_PROTECTION;
2835 scsi_host_set_prot(vha->host,
2836 prot | SHOST_DIF_TYPE1_PROTECTION
2837 | SHOST_DIF_TYPE2_PROTECTION
2838 | SHOST_DIF_TYPE3_PROTECTION
2839 | SHOST_DIX_TYPE1_PROTECTION
2840 | SHOST_DIX_TYPE2_PROTECTION
2841 | SHOST_DIX_TYPE3_PROTECTION);
2843 guard = SHOST_DIX_GUARD_CRC;
2845 if (IS_PI_IPGUARD_CAPABLE(ha) &&
2846 (ql2xenabledif > 1 || IS_PI_DIFB_DIX0_CAPABLE(ha)))
2847 guard |= SHOST_DIX_GUARD_IP;
2849 scsi_host_set_guard(vha->host, guard);
2851 vha->flags.difdix_supported = 0;
2854 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
2856 ql_dbg(ql_dbg_user, vha, 0x7083,
2857 "scsi_add_host failure for VP[%d].\n", vha->vp_idx);
2858 goto vport_create_failed_2;
2861 /* initialize attributes */
2862 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
2863 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2864 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
2865 fc_host_supported_classes(vha->host) =
2866 fc_host_supported_classes(base_vha->host);
2867 fc_host_supported_speeds(vha->host) =
2868 fc_host_supported_speeds(base_vha->host);
2870 qlt_vport_create(vha, ha);
2871 qla24xx_vport_disable(fc_vport, disable);
2873 if (!ql2xmqsupport || !ha->npiv_info)
2876 /* Create a request queue in QoS mode for the vport */
2877 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
2878 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
2879 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
2881 qos = ha->npiv_info[cnt].q_qos;
2887 qpair = qla2xxx_create_qpair(vha, qos, vha->vp_idx, true);
2889 ql_log(ql_log_warn, vha, 0x7084,
2890 "Can't create qpair for VP[%d]\n",
2893 ql_dbg(ql_dbg_multiq, vha, 0xc001,
2894 "Queue pair: %d Qos: %d) created for VP[%d]\n",
2895 qpair->id, qos, vha->vp_idx);
2896 ql_dbg(ql_dbg_user, vha, 0x7085,
2897 "Queue Pair: %d Qos: %d) created for VP[%d]\n",
2898 qpair->id, qos, vha->vp_idx);
2908 vport_create_failed_2:
2909 qla24xx_disable_vp(vha);
2910 qla24xx_deallocate_vp_id(vha);
2911 scsi_host_put(vha->host);
2912 return FC_VPORT_FAILED;
2916 qla24xx_vport_delete(struct fc_vport *fc_vport)
2918 scsi_qla_host_t *vha = fc_vport->dd_data;
2919 struct qla_hw_data *ha = vha->hw;
2920 uint16_t id = vha->vp_idx;
2922 set_bit(VPORT_DELETE, &vha->dpc_flags);
2924 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
2925 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
2928 qla_nvme_delete(vha);
2930 qla24xx_disable_vp(vha);
2931 qla2x00_wait_for_sess_deletion(vha);
2933 vha->flags.delete_progress = 1;
2935 qlt_remove_target(ha, vha);
2937 fc_remove_host(vha->host);
2939 scsi_remove_host(vha->host);
2941 /* Allow timer to run to drain queued items, when removing vp */
2942 qla24xx_deallocate_vp_id(vha);
2944 if (vha->timer_active) {
2945 qla2x00_vp_stop_timer(vha);
2946 ql_dbg(ql_dbg_user, vha, 0x7086,
2947 "Timer for the VP[%d] has stopped\n", vha->vp_idx);
2950 qla2x00_free_fcports(vha);
2952 mutex_lock(&ha->vport_lock);
2953 ha->cur_vport_count--;
2954 clear_bit(vha->vp_idx, ha->vp_idx_map);
2955 mutex_unlock(&ha->vport_lock);
2957 dma_free_coherent(&ha->pdev->dev, vha->gnl.size, vha->gnl.l,
2964 if (vha->qpair && vha->qpair->vp_idx == vha->vp_idx) {
2965 if (qla2xxx_delete_qpair(vha, vha->qpair) != QLA_SUCCESS)
2966 ql_log(ql_log_warn, vha, 0x7087,
2967 "Queue Pair delete failed.\n");
2970 ql_log(ql_log_info, vha, 0x7088, "VP[%d] deleted.\n", id);
2971 scsi_host_put(vha->host);
2976 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
2978 scsi_qla_host_t *vha = fc_vport->dd_data;
2981 qla24xx_disable_vp(vha);
2983 qla24xx_enable_vp(vha);
2988 struct fc_function_template qla2xxx_transport_functions = {
2990 .show_host_node_name = 1,
2991 .show_host_port_name = 1,
2992 .show_host_supported_classes = 1,
2993 .show_host_supported_speeds = 1,
2995 .get_host_port_id = qla2x00_get_host_port_id,
2996 .show_host_port_id = 1,
2997 .get_host_speed = qla2x00_get_host_speed,
2998 .show_host_speed = 1,
2999 .get_host_port_type = qla2x00_get_host_port_type,
3000 .show_host_port_type = 1,
3001 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3002 .show_host_symbolic_name = 1,
3003 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3004 .show_host_system_hostname = 1,
3005 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3006 .show_host_fabric_name = 1,
3007 .get_host_port_state = qla2x00_get_host_port_state,
3008 .show_host_port_state = 1,
3010 .dd_fcrport_size = sizeof(struct fc_port *),
3011 .show_rport_supported_classes = 1,
3013 .get_starget_node_name = qla2x00_get_starget_node_name,
3014 .show_starget_node_name = 1,
3015 .get_starget_port_name = qla2x00_get_starget_port_name,
3016 .show_starget_port_name = 1,
3017 .get_starget_port_id = qla2x00_get_starget_port_id,
3018 .show_starget_port_id = 1,
3020 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3021 .show_rport_dev_loss_tmo = 1,
3023 .issue_fc_host_lip = qla2x00_issue_lip,
3024 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3025 .terminate_rport_io = qla2x00_terminate_rport_io,
3026 .get_fc_host_stats = qla2x00_get_fc_host_stats,
3027 .reset_fc_host_stats = qla2x00_reset_host_stats,
3029 .vport_create = qla24xx_vport_create,
3030 .vport_disable = qla24xx_vport_disable,
3031 .vport_delete = qla24xx_vport_delete,
3032 .bsg_request = qla24xx_bsg_request,
3033 .bsg_timeout = qla24xx_bsg_timeout,
3036 struct fc_function_template qla2xxx_transport_vport_functions = {
3038 .show_host_node_name = 1,
3039 .show_host_port_name = 1,
3040 .show_host_supported_classes = 1,
3042 .get_host_port_id = qla2x00_get_host_port_id,
3043 .show_host_port_id = 1,
3044 .get_host_speed = qla2x00_get_host_speed,
3045 .show_host_speed = 1,
3046 .get_host_port_type = qla2x00_get_host_port_type,
3047 .show_host_port_type = 1,
3048 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
3049 .show_host_symbolic_name = 1,
3050 .set_host_system_hostname = qla2x00_set_host_system_hostname,
3051 .show_host_system_hostname = 1,
3052 .get_host_fabric_name = qla2x00_get_host_fabric_name,
3053 .show_host_fabric_name = 1,
3054 .get_host_port_state = qla2x00_get_host_port_state,
3055 .show_host_port_state = 1,
3057 .dd_fcrport_size = sizeof(struct fc_port *),
3058 .show_rport_supported_classes = 1,
3060 .get_starget_node_name = qla2x00_get_starget_node_name,
3061 .show_starget_node_name = 1,
3062 .get_starget_port_name = qla2x00_get_starget_port_name,
3063 .show_starget_port_name = 1,
3064 .get_starget_port_id = qla2x00_get_starget_port_id,
3065 .show_starget_port_id = 1,
3067 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
3068 .show_rport_dev_loss_tmo = 1,
3070 .issue_fc_host_lip = qla2x00_issue_lip,
3071 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
3072 .terminate_rport_io = qla2x00_terminate_rport_io,
3073 .get_fc_host_stats = qla2x00_get_fc_host_stats,
3074 .reset_fc_host_stats = qla2x00_reset_host_stats,
3076 .bsg_request = qla24xx_bsg_request,
3077 .bsg_timeout = qla24xx_bsg_timeout,
3081 qla2x00_init_host_attr(scsi_qla_host_t *vha)
3083 struct qla_hw_data *ha = vha->hw;
3084 u32 speeds = FC_PORTSPEED_UNKNOWN;
3086 fc_host_dev_loss_tmo(vha->host) = ha->port_down_retry_count;
3087 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
3088 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
3089 fc_host_supported_classes(vha->host) = ha->base_qpair->enable_class_2 ?
3090 (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
3091 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
3092 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
3094 if (IS_CNA_CAPABLE(ha))
3095 speeds = FC_PORTSPEED_10GBIT;
3096 else if (IS_QLA28XX(ha) || IS_QLA27XX(ha)) {
3097 if (ha->max_supported_speed == 2) {
3098 if (ha->min_supported_speed <= 6)
3099 speeds |= FC_PORTSPEED_64GBIT;
3101 if (ha->max_supported_speed == 2 ||
3102 ha->max_supported_speed == 1) {
3103 if (ha->min_supported_speed <= 5)
3104 speeds |= FC_PORTSPEED_32GBIT;
3106 if (ha->max_supported_speed == 2 ||
3107 ha->max_supported_speed == 1 ||
3108 ha->max_supported_speed == 0) {
3109 if (ha->min_supported_speed <= 4)
3110 speeds |= FC_PORTSPEED_16GBIT;
3112 if (ha->max_supported_speed == 1 ||
3113 ha->max_supported_speed == 0) {
3114 if (ha->min_supported_speed <= 3)
3115 speeds |= FC_PORTSPEED_8GBIT;
3117 if (ha->max_supported_speed == 0) {
3118 if (ha->min_supported_speed <= 2)
3119 speeds |= FC_PORTSPEED_4GBIT;
3121 } else if (IS_QLA2031(ha))
3122 speeds = FC_PORTSPEED_16GBIT|FC_PORTSPEED_8GBIT|
3124 else if (IS_QLA25XX(ha) || IS_QLAFX00(ha))
3125 speeds = FC_PORTSPEED_8GBIT|FC_PORTSPEED_4GBIT|
3126 FC_PORTSPEED_2GBIT|FC_PORTSPEED_1GBIT;
3127 else if (IS_QLA24XX_TYPE(ha))
3128 speeds = FC_PORTSPEED_4GBIT|FC_PORTSPEED_2GBIT|
3130 else if (IS_QLA23XX(ha))
3131 speeds = FC_PORTSPEED_2GBIT|FC_PORTSPEED_1GBIT;
3133 speeds = FC_PORTSPEED_1GBIT;
3135 fc_host_supported_speeds(vha->host) = speeds;