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
);
107 qla2x00_system_error(vha
);
111 if (IS_P3P_TYPE(ha
)) {
112 if (ha
->md_tmplt_hdr
)
113 ql_dbg(ql_dbg_user
, vha
, 0x705b,
114 "MiniDump supported with this firmware.\n");
116 ql_dbg(ql_dbg_user
, vha
, 0x709d,
117 "MiniDump not supported with this firmware.\n");
122 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
125 if (!ha
->mctp_dump_reading
)
127 ql_log(ql_log_info
, vha
, 0x70c1,
128 "MCTP dump cleared on (%ld).\n", vha
->host_no
);
129 ha
->mctp_dump_reading
= 0;
133 if (ha
->mctp_dumped
&& !ha
->mctp_dump_reading
) {
134 ha
->mctp_dump_reading
= 1;
135 ql_log(ql_log_info
, vha
, 0x70c2,
136 "Raw mctp dump ready for read on (%ld).\n",
144 static struct bin_attribute sysfs_fw_dump_attr
= {
147 .mode
= S_IRUSR
| S_IWUSR
,
150 .read
= qla2x00_sysfs_read_fw_dump
,
151 .write
= qla2x00_sysfs_write_fw_dump
,
155 qla2x00_sysfs_read_nvram(struct file
*filp
, struct kobject
*kobj
,
156 struct bin_attribute
*bin_attr
,
157 char *buf
, loff_t off
, size_t count
)
159 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
160 struct device
, kobj
)));
161 struct qla_hw_data
*ha
= vha
->hw
;
163 struct active_regions active_regions
= { };
165 if (!capable(CAP_SYS_ADMIN
))
168 mutex_lock(&ha
->optrom_mutex
);
169 if (qla2x00_chip_is_down(vha
)) {
170 mutex_unlock(&ha
->optrom_mutex
);
174 if (!IS_NOCACHE_VPD_TYPE(ha
)) {
175 mutex_unlock(&ha
->optrom_mutex
);
179 faddr
= ha
->flt_region_nvram
;
180 if (IS_QLA28XX(ha
)) {
181 qla28xx_get_aux_images(vha
, &active_regions
);
182 if (active_regions
.aux
.vpd_nvram
== QLA27XX_SECONDARY_IMAGE
)
183 faddr
= ha
->flt_region_nvram_sec
;
185 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, faddr
<< 2, ha
->nvram_size
);
187 mutex_unlock(&ha
->optrom_mutex
);
190 return memory_read_from_buffer(buf
, count
, &off
, ha
->nvram
,
195 qla2x00_sysfs_write_nvram(struct file
*filp
, struct kobject
*kobj
,
196 struct bin_attribute
*bin_attr
,
197 char *buf
, loff_t off
, size_t count
)
199 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
200 struct device
, kobj
)));
201 struct qla_hw_data
*ha
= vha
->hw
;
204 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->nvram_size
||
205 !ha
->isp_ops
->write_nvram
)
208 /* Checksum NVRAM. */
209 if (IS_FWI2_CAPABLE(ha
)) {
213 iter
= (uint32_t *)buf
;
215 for (cnt
= 0; cnt
< ((count
>> 2) - 1); cnt
++, iter
++)
216 chksum
+= le32_to_cpu(*iter
);
217 chksum
= ~chksum
+ 1;
218 *iter
= cpu_to_le32(chksum
);
223 iter
= (uint8_t *)buf
;
225 for (cnt
= 0; cnt
< count
- 1; cnt
++)
227 chksum
= ~chksum
+ 1;
231 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
232 ql_log(ql_log_warn
, vha
, 0x705f,
233 "HBA not online, failing NVRAM update.\n");
237 mutex_lock(&ha
->optrom_mutex
);
238 if (qla2x00_chip_is_down(vha
)) {
239 mutex_unlock(&ha
->optrom_mutex
);
244 ha
->isp_ops
->write_nvram(vha
, buf
, ha
->nvram_base
, count
);
245 ha
->isp_ops
->read_nvram(vha
, ha
->nvram
, ha
->nvram_base
,
247 mutex_unlock(&ha
->optrom_mutex
);
249 ql_dbg(ql_dbg_user
, vha
, 0x7060,
250 "Setting ISP_ABORT_NEEDED\n");
251 /* NVRAM settings take effect immediately. */
252 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
253 qla2xxx_wake_dpc(vha
);
254 qla2x00_wait_for_chip_reset(vha
);
259 static struct bin_attribute sysfs_nvram_attr
= {
262 .mode
= S_IRUSR
| S_IWUSR
,
265 .read
= qla2x00_sysfs_read_nvram
,
266 .write
= qla2x00_sysfs_write_nvram
,
270 qla2x00_sysfs_read_optrom(struct file
*filp
, struct kobject
*kobj
,
271 struct bin_attribute
*bin_attr
,
272 char *buf
, loff_t off
, size_t count
)
274 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
275 struct device
, kobj
)));
276 struct qla_hw_data
*ha
= vha
->hw
;
279 mutex_lock(&ha
->optrom_mutex
);
281 if (ha
->optrom_state
!= QLA_SREADING
)
284 rval
= memory_read_from_buffer(buf
, count
, &off
, ha
->optrom_buffer
,
285 ha
->optrom_region_size
);
288 mutex_unlock(&ha
->optrom_mutex
);
294 qla2x00_sysfs_write_optrom(struct file
*filp
, struct kobject
*kobj
,
295 struct bin_attribute
*bin_attr
,
296 char *buf
, loff_t off
, size_t count
)
298 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
299 struct device
, kobj
)));
300 struct qla_hw_data
*ha
= vha
->hw
;
302 mutex_lock(&ha
->optrom_mutex
);
304 if (ha
->optrom_state
!= QLA_SWRITING
) {
305 mutex_unlock(&ha
->optrom_mutex
);
308 if (off
> ha
->optrom_region_size
) {
309 mutex_unlock(&ha
->optrom_mutex
);
312 if (off
+ count
> ha
->optrom_region_size
)
313 count
= ha
->optrom_region_size
- off
;
315 memcpy(&ha
->optrom_buffer
[off
], buf
, count
);
316 mutex_unlock(&ha
->optrom_mutex
);
321 static struct bin_attribute sysfs_optrom_attr
= {
324 .mode
= S_IRUSR
| S_IWUSR
,
327 .read
= qla2x00_sysfs_read_optrom
,
328 .write
= qla2x00_sysfs_write_optrom
,
332 qla2x00_sysfs_write_optrom_ctl(struct file
*filp
, struct kobject
*kobj
,
333 struct bin_attribute
*bin_attr
,
334 char *buf
, loff_t off
, size_t count
)
336 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
337 struct device
, kobj
)));
338 struct qla_hw_data
*ha
= vha
->hw
;
340 uint32_t size
= ha
->optrom_size
;
342 ssize_t rval
= count
;
347 if (unlikely(pci_channel_offline(ha
->pdev
)))
350 if (sscanf(buf
, "%d:%x:%x", &val
, &start
, &size
) < 1)
352 if (start
> ha
->optrom_size
)
354 if (size
> ha
->optrom_size
- start
)
355 size
= ha
->optrom_size
- start
;
357 mutex_lock(&ha
->optrom_mutex
);
358 if (qla2x00_chip_is_down(vha
)) {
359 mutex_unlock(&ha
->optrom_mutex
);
364 if (ha
->optrom_state
!= QLA_SREADING
&&
365 ha
->optrom_state
!= QLA_SWRITING
) {
369 ha
->optrom_state
= QLA_SWAITING
;
371 ql_dbg(ql_dbg_user
, vha
, 0x7061,
372 "Freeing flash region allocation -- 0x%x bytes.\n",
373 ha
->optrom_region_size
);
375 vfree(ha
->optrom_buffer
);
376 ha
->optrom_buffer
= NULL
;
379 if (ha
->optrom_state
!= QLA_SWAITING
) {
384 ha
->optrom_region_start
= start
;
385 ha
->optrom_region_size
= size
;
387 ha
->optrom_state
= QLA_SREADING
;
388 ha
->optrom_buffer
= vzalloc(ha
->optrom_region_size
);
389 if (ha
->optrom_buffer
== NULL
) {
390 ql_log(ql_log_warn
, vha
, 0x7062,
391 "Unable to allocate memory for optrom retrieval "
392 "(%x).\n", ha
->optrom_region_size
);
394 ha
->optrom_state
= QLA_SWAITING
;
399 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
400 ql_log(ql_log_warn
, vha
, 0x7063,
401 "HBA not online, failing NVRAM update.\n");
406 ql_dbg(ql_dbg_user
, vha
, 0x7064,
407 "Reading flash region -- 0x%x/0x%x.\n",
408 ha
->optrom_region_start
, ha
->optrom_region_size
);
410 ha
->isp_ops
->read_optrom(vha
, ha
->optrom_buffer
,
411 ha
->optrom_region_start
, ha
->optrom_region_size
);
414 if (ha
->optrom_state
!= QLA_SWAITING
) {
420 * We need to be more restrictive on which FLASH regions are
421 * allowed to be updated via user-space. Regions accessible
422 * via this method include:
424 * ISP21xx/ISP22xx/ISP23xx type boards:
426 * 0x000000 -> 0x020000 -- Boot code.
428 * ISP2322/ISP24xx type boards:
430 * 0x000000 -> 0x07ffff -- Boot code.
431 * 0x080000 -> 0x0fffff -- Firmware.
433 * ISP25xx type boards:
435 * 0x000000 -> 0x07ffff -- Boot code.
436 * 0x080000 -> 0x0fffff -- Firmware.
437 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
439 * > ISP25xx type boards:
441 * None -- should go through BSG.
444 if (ha
->optrom_size
== OPTROM_SIZE_2300
&& start
== 0)
446 else if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
449 ql_log(ql_log_warn
, vha
, 0x7065,
450 "Invalid start region 0x%x/0x%x.\n", start
, size
);
455 ha
->optrom_region_start
= start
;
456 ha
->optrom_region_size
= size
;
458 ha
->optrom_state
= QLA_SWRITING
;
459 ha
->optrom_buffer
= vzalloc(ha
->optrom_region_size
);
460 if (ha
->optrom_buffer
== NULL
) {
461 ql_log(ql_log_warn
, vha
, 0x7066,
462 "Unable to allocate memory for optrom update "
463 "(%x)\n", ha
->optrom_region_size
);
465 ha
->optrom_state
= QLA_SWAITING
;
470 ql_dbg(ql_dbg_user
, vha
, 0x7067,
471 "Staging flash region write -- 0x%x/0x%x.\n",
472 ha
->optrom_region_start
, ha
->optrom_region_size
);
476 if (ha
->optrom_state
!= QLA_SWRITING
) {
481 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
482 ql_log(ql_log_warn
, vha
, 0x7068,
483 "HBA not online, failing flash update.\n");
488 ql_dbg(ql_dbg_user
, vha
, 0x7069,
489 "Writing flash region -- 0x%x/0x%x.\n",
490 ha
->optrom_region_start
, ha
->optrom_region_size
);
492 rval
= ha
->isp_ops
->write_optrom(vha
, ha
->optrom_buffer
,
493 ha
->optrom_region_start
, ha
->optrom_region_size
);
502 mutex_unlock(&ha
->optrom_mutex
);
506 static struct bin_attribute sysfs_optrom_ctl_attr
= {
508 .name
= "optrom_ctl",
512 .write
= qla2x00_sysfs_write_optrom_ctl
,
516 qla2x00_sysfs_read_vpd(struct file
*filp
, struct kobject
*kobj
,
517 struct bin_attribute
*bin_attr
,
518 char *buf
, loff_t off
, size_t count
)
520 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
521 struct device
, kobj
)));
522 struct qla_hw_data
*ha
= vha
->hw
;
524 struct active_regions active_regions
= { };
526 if (unlikely(pci_channel_offline(ha
->pdev
)))
529 if (!capable(CAP_SYS_ADMIN
))
532 if (IS_NOCACHE_VPD_TYPE(ha
))
535 faddr
= ha
->flt_region_vpd
<< 2;
537 if (IS_QLA28XX(ha
)) {
538 qla28xx_get_aux_images(vha
, &active_regions
);
539 if (active_regions
.aux
.vpd_nvram
== QLA27XX_SECONDARY_IMAGE
)
540 faddr
= ha
->flt_region_vpd_sec
<< 2;
542 ql_dbg(ql_dbg_init
, vha
, 0x7070,
543 "Loading %s nvram image.\n",
544 active_regions
.aux
.vpd_nvram
== QLA27XX_PRIMARY_IMAGE
?
545 "primary" : "secondary");
548 mutex_lock(&ha
->optrom_mutex
);
549 if (qla2x00_chip_is_down(vha
)) {
550 mutex_unlock(&ha
->optrom_mutex
);
554 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, faddr
, ha
->vpd_size
);
555 mutex_unlock(&ha
->optrom_mutex
);
557 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, faddr
, ha
->vpd_size
);
559 return memory_read_from_buffer(buf
, count
, &off
, ha
->vpd
, ha
->vpd_size
);
563 qla2x00_sysfs_write_vpd(struct file
*filp
, struct kobject
*kobj
,
564 struct bin_attribute
*bin_attr
,
565 char *buf
, loff_t off
, size_t count
)
567 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
568 struct device
, kobj
)));
569 struct qla_hw_data
*ha
= vha
->hw
;
572 if (unlikely(pci_channel_offline(ha
->pdev
)))
575 if (qla2x00_chip_is_down(vha
))
578 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->vpd_size
||
579 !ha
->isp_ops
->write_nvram
)
582 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
583 ql_log(ql_log_warn
, vha
, 0x706a,
584 "HBA not online, failing VPD update.\n");
588 mutex_lock(&ha
->optrom_mutex
);
589 if (qla2x00_chip_is_down(vha
)) {
590 mutex_unlock(&ha
->optrom_mutex
);
595 ha
->isp_ops
->write_nvram(vha
, buf
, ha
->vpd_base
, count
);
596 ha
->isp_ops
->read_nvram(vha
, ha
->vpd
, ha
->vpd_base
, count
);
598 /* Update flash version information for 4Gb & above. */
599 if (!IS_FWI2_CAPABLE(ha
)) {
600 mutex_unlock(&ha
->optrom_mutex
);
604 tmp_data
= vmalloc(256);
606 mutex_unlock(&ha
->optrom_mutex
);
607 ql_log(ql_log_warn
, vha
, 0x706b,
608 "Unable to allocate memory for VPD information update.\n");
611 ha
->isp_ops
->get_flash_version(vha
, tmp_data
);
614 mutex_unlock(&ha
->optrom_mutex
);
619 static struct bin_attribute sysfs_vpd_attr
= {
622 .mode
= S_IRUSR
| S_IWUSR
,
625 .read
= qla2x00_sysfs_read_vpd
,
626 .write
= qla2x00_sysfs_write_vpd
,
630 qla2x00_sysfs_read_sfp(struct file
*filp
, struct kobject
*kobj
,
631 struct bin_attribute
*bin_attr
,
632 char *buf
, loff_t off
, size_t count
)
634 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
635 struct device
, kobj
)));
638 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
< SFP_DEV_SIZE
)
641 mutex_lock(&vha
->hw
->optrom_mutex
);
642 if (qla2x00_chip_is_down(vha
)) {
643 mutex_unlock(&vha
->hw
->optrom_mutex
);
647 rval
= qla2x00_read_sfp_dev(vha
, buf
, count
);
648 mutex_unlock(&vha
->hw
->optrom_mutex
);
656 static struct bin_attribute sysfs_sfp_attr
= {
659 .mode
= S_IRUSR
| S_IWUSR
,
661 .size
= SFP_DEV_SIZE
,
662 .read
= qla2x00_sysfs_read_sfp
,
666 qla2x00_sysfs_write_reset(struct file
*filp
, struct kobject
*kobj
,
667 struct bin_attribute
*bin_attr
,
668 char *buf
, loff_t off
, size_t count
)
670 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
671 struct device
, kobj
)));
672 struct qla_hw_data
*ha
= vha
->hw
;
673 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
675 uint32_t idc_control
;
676 uint8_t *tmp_data
= NULL
;
681 type
= simple_strtol(buf
, NULL
, 10);
684 ql_log(ql_log_info
, vha
, 0x706e,
685 "Issuing ISP reset.\n");
687 scsi_block_requests(vha
->host
);
688 if (IS_QLA82XX(ha
)) {
689 ha
->flags
.isp82xx_no_md_cap
= 1;
690 qla82xx_idc_lock(ha
);
691 qla82xx_set_reset_owner(vha
);
692 qla82xx_idc_unlock(ha
);
693 } else if (IS_QLA8044(ha
)) {
694 qla8044_idc_lock(ha
);
695 idc_control
= qla8044_rd_reg(ha
,
696 QLA8044_IDC_DRV_CTRL
);
697 qla8044_wr_reg(ha
, QLA8044_IDC_DRV_CTRL
,
698 (idc_control
| GRACEFUL_RESET_BIT1
));
699 qla82xx_set_reset_owner(vha
);
700 qla8044_idc_unlock(ha
);
702 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
703 qla2xxx_wake_dpc(vha
);
705 qla2x00_wait_for_chip_reset(vha
);
706 scsi_unblock_requests(vha
->host
);
709 if (!IS_QLA81XX(ha
) && !IS_QLA83XX(ha
))
712 ql_log(ql_log_info
, vha
, 0x706f,
713 "Issuing MPI reset.\n");
715 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
)) {
716 uint32_t idc_control
;
718 qla83xx_idc_lock(vha
, 0);
719 __qla83xx_get_idc_control(vha
, &idc_control
);
720 idc_control
|= QLA83XX_IDC_GRACEFUL_RESET
;
721 __qla83xx_set_idc_control(vha
, idc_control
);
722 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
723 QLA8XXX_DEV_NEED_RESET
);
724 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
725 qla83xx_idc_unlock(vha
, 0);
728 /* Make sure FC side is not in reset */
729 WARN_ON_ONCE(qla2x00_wait_for_hba_online(vha
) !=
732 /* Issue MPI reset */
733 scsi_block_requests(vha
->host
);
734 if (qla81xx_restart_mpi_firmware(vha
) != QLA_SUCCESS
)
735 ql_log(ql_log_warn
, vha
, 0x7070,
736 "MPI reset failed.\n");
737 scsi_unblock_requests(vha
->host
);
741 if (!IS_P3P_TYPE(ha
) || vha
!= base_vha
) {
742 ql_log(ql_log_info
, vha
, 0x7071,
743 "FCoE ctx reset not supported.\n");
747 ql_log(ql_log_info
, vha
, 0x7072,
748 "Issuing FCoE ctx reset.\n");
749 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
750 qla2xxx_wake_dpc(vha
);
751 qla2x00_wait_for_fcoe_ctx_reset(vha
);
756 ql_log(ql_log_info
, vha
, 0x70bc,
757 "Disabling Reset by IDC control\n");
758 qla83xx_idc_lock(vha
, 0);
759 __qla83xx_get_idc_control(vha
, &idc_control
);
760 idc_control
|= QLA83XX_IDC_RESET_DISABLED
;
761 __qla83xx_set_idc_control(vha
, idc_control
);
762 qla83xx_idc_unlock(vha
, 0);
767 ql_log(ql_log_info
, vha
, 0x70bd,
768 "Enabling Reset by IDC control\n");
769 qla83xx_idc_lock(vha
, 0);
770 __qla83xx_get_idc_control(vha
, &idc_control
);
771 idc_control
&= ~QLA83XX_IDC_RESET_DISABLED
;
772 __qla83xx_set_idc_control(vha
, idc_control
);
773 qla83xx_idc_unlock(vha
, 0);
776 ql_dbg(ql_dbg_user
, vha
, 0x70e0,
777 "Updating cache versions without reset ");
779 tmp_data
= vmalloc(256);
781 ql_log(ql_log_warn
, vha
, 0x70e1,
782 "Unable to allocate memory for VPD information update.\n");
785 ha
->isp_ops
->get_flash_version(vha
, tmp_data
);
792 static struct bin_attribute sysfs_reset_attr
= {
798 .write
= qla2x00_sysfs_write_reset
,
802 qla2x00_issue_logo(struct file
*filp
, struct kobject
*kobj
,
803 struct bin_attribute
*bin_attr
,
804 char *buf
, loff_t off
, size_t count
)
806 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
807 struct device
, kobj
)));
811 if (!capable(CAP_SYS_ADMIN
))
814 if (unlikely(pci_channel_offline(vha
->hw
->pdev
)))
817 if (qla2x00_chip_is_down(vha
))
820 type
= simple_strtol(buf
, NULL
, 10);
822 did
.b
.domain
= (type
& 0x00ff0000) >> 16;
823 did
.b
.area
= (type
& 0x0000ff00) >> 8;
824 did
.b
.al_pa
= (type
& 0x000000ff);
826 ql_log(ql_log_info
, vha
, 0xd04d, "portid=%02x%02x%02x done\n",
827 did
.b
.domain
, did
.b
.area
, did
.b
.al_pa
);
829 ql_log(ql_log_info
, vha
, 0x70e4, "%s: %d\n", __func__
, type
);
831 qla24xx_els_dcmd_iocb(vha
, ELS_DCMD_LOGO
, did
);
835 static struct bin_attribute sysfs_issue_logo_attr
= {
837 .name
= "issue_logo",
841 .write
= qla2x00_issue_logo
,
845 qla2x00_sysfs_read_xgmac_stats(struct file
*filp
, struct kobject
*kobj
,
846 struct bin_attribute
*bin_attr
,
847 char *buf
, loff_t off
, size_t count
)
849 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
850 struct device
, kobj
)));
851 struct qla_hw_data
*ha
= vha
->hw
;
853 uint16_t actual_size
;
855 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
> XGMAC_DATA_SIZE
)
858 if (unlikely(pci_channel_offline(ha
->pdev
)))
860 mutex_lock(&vha
->hw
->optrom_mutex
);
861 if (qla2x00_chip_is_down(vha
)) {
862 mutex_unlock(&vha
->hw
->optrom_mutex
);
869 ha
->xgmac_data
= dma_alloc_coherent(&ha
->pdev
->dev
, XGMAC_DATA_SIZE
,
870 &ha
->xgmac_data_dma
, GFP_KERNEL
);
871 if (!ha
->xgmac_data
) {
872 mutex_unlock(&vha
->hw
->optrom_mutex
);
873 ql_log(ql_log_warn
, vha
, 0x7076,
874 "Unable to allocate memory for XGMAC read-data.\n");
880 memset(ha
->xgmac_data
, 0, XGMAC_DATA_SIZE
);
882 rval
= qla2x00_get_xgmac_stats(vha
, ha
->xgmac_data_dma
,
883 XGMAC_DATA_SIZE
, &actual_size
);
885 mutex_unlock(&vha
->hw
->optrom_mutex
);
886 if (rval
!= QLA_SUCCESS
) {
887 ql_log(ql_log_warn
, vha
, 0x7077,
888 "Unable to read XGMAC data (%x).\n", rval
);
892 count
= actual_size
> count
? count
: actual_size
;
893 memcpy(buf
, ha
->xgmac_data
, count
);
898 static struct bin_attribute sysfs_xgmac_stats_attr
= {
900 .name
= "xgmac_stats",
904 .read
= qla2x00_sysfs_read_xgmac_stats
,
908 qla2x00_sysfs_read_dcbx_tlv(struct file
*filp
, struct kobject
*kobj
,
909 struct bin_attribute
*bin_attr
,
910 char *buf
, loff_t off
, size_t count
)
912 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
913 struct device
, kobj
)));
914 struct qla_hw_data
*ha
= vha
->hw
;
917 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
> DCBX_TLV_DATA_SIZE
)
922 mutex_lock(&vha
->hw
->optrom_mutex
);
923 if (qla2x00_chip_is_down(vha
)) {
924 mutex_unlock(&vha
->hw
->optrom_mutex
);
928 ha
->dcbx_tlv
= dma_alloc_coherent(&ha
->pdev
->dev
, DCBX_TLV_DATA_SIZE
,
929 &ha
->dcbx_tlv_dma
, GFP_KERNEL
);
931 mutex_unlock(&vha
->hw
->optrom_mutex
);
932 ql_log(ql_log_warn
, vha
, 0x7078,
933 "Unable to allocate memory for DCBX TLV read-data.\n");
938 memset(ha
->dcbx_tlv
, 0, DCBX_TLV_DATA_SIZE
);
940 rval
= qla2x00_get_dcbx_params(vha
, ha
->dcbx_tlv_dma
,
943 mutex_unlock(&vha
->hw
->optrom_mutex
);
945 if (rval
!= QLA_SUCCESS
) {
946 ql_log(ql_log_warn
, vha
, 0x7079,
947 "Unable to read DCBX TLV (%x).\n", rval
);
951 memcpy(buf
, ha
->dcbx_tlv
, count
);
956 static struct bin_attribute sysfs_dcbx_tlv_attr
= {
962 .read
= qla2x00_sysfs_read_dcbx_tlv
,
965 static struct sysfs_entry
{
967 struct bin_attribute
*attr
;
969 } bin_file_entries
[] = {
970 { "fw_dump", &sysfs_fw_dump_attr
, },
971 { "nvram", &sysfs_nvram_attr
, },
972 { "optrom", &sysfs_optrom_attr
, },
973 { "optrom_ctl", &sysfs_optrom_ctl_attr
, },
974 { "vpd", &sysfs_vpd_attr
, 1 },
975 { "sfp", &sysfs_sfp_attr
, 1 },
976 { "reset", &sysfs_reset_attr
, },
977 { "issue_logo", &sysfs_issue_logo_attr
, },
978 { "xgmac_stats", &sysfs_xgmac_stats_attr
, 3 },
979 { "dcbx_tlv", &sysfs_dcbx_tlv_attr
, 3 },
984 qla2x00_alloc_sysfs_attr(scsi_qla_host_t
*vha
)
986 struct Scsi_Host
*host
= vha
->host
;
987 struct sysfs_entry
*iter
;
990 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
991 if (iter
->type
&& !IS_FWI2_CAPABLE(vha
->hw
))
993 if (iter
->type
== 2 && !IS_QLA25XX(vha
->hw
))
995 if (iter
->type
== 3 && !(IS_CNA_CAPABLE(vha
->hw
)))
998 ret
= sysfs_create_bin_file(&host
->shost_gendev
.kobj
,
1001 ql_log(ql_log_warn
, vha
, 0x00f3,
1002 "Unable to create sysfs %s binary attribute (%d).\n",
1005 ql_dbg(ql_dbg_init
, vha
, 0x00f4,
1006 "Successfully created sysfs %s binary attribute.\n",
1012 qla2x00_free_sysfs_attr(scsi_qla_host_t
*vha
, bool stop_beacon
)
1014 struct Scsi_Host
*host
= vha
->host
;
1015 struct sysfs_entry
*iter
;
1016 struct qla_hw_data
*ha
= vha
->hw
;
1018 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
1019 if (iter
->type
&& !IS_FWI2_CAPABLE(ha
))
1021 if (iter
->type
== 2 && !IS_QLA25XX(ha
))
1023 if (iter
->type
== 3 && !(IS_CNA_CAPABLE(ha
)))
1025 if (iter
->type
== 0x27 &&
1026 (!IS_QLA27XX(ha
) || !IS_QLA28XX(ha
)))
1029 sysfs_remove_bin_file(&host
->shost_gendev
.kobj
,
1033 if (stop_beacon
&& ha
->beacon_blink_led
== 1)
1034 ha
->isp_ops
->beacon_off(vha
);
1037 /* Scsi_Host attributes. */
1040 qla2x00_driver_version_show(struct device
*dev
,
1041 struct device_attribute
*attr
, char *buf
)
1043 return scnprintf(buf
, PAGE_SIZE
, "%s\n", qla2x00_version_str
);
1047 qla2x00_fw_version_show(struct device
*dev
,
1048 struct device_attribute
*attr
, char *buf
)
1050 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1051 struct qla_hw_data
*ha
= vha
->hw
;
1054 return scnprintf(buf
, PAGE_SIZE
, "%s\n",
1055 ha
->isp_ops
->fw_version_str(vha
, fw_str
, sizeof(fw_str
)));
1059 qla2x00_serial_num_show(struct device
*dev
, struct device_attribute
*attr
,
1062 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1063 struct qla_hw_data
*ha
= vha
->hw
;
1066 if (IS_QLAFX00(vha
->hw
)) {
1067 return scnprintf(buf
, PAGE_SIZE
, "%s\n",
1068 vha
->hw
->mr
.serial_num
);
1069 } else if (IS_FWI2_CAPABLE(ha
)) {
1070 qla2xxx_get_vpd_field(vha
, "SN", buf
, PAGE_SIZE
- 1);
1071 return strlen(strcat(buf
, "\n"));
1074 sn
= ((ha
->serial0
& 0x1f) << 16) | (ha
->serial2
<< 8) | ha
->serial1
;
1075 return scnprintf(buf
, PAGE_SIZE
, "%c%05d\n", 'A' + sn
/ 100000,
1080 qla2x00_isp_name_show(struct device
*dev
, struct device_attribute
*attr
,
1083 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1085 return scnprintf(buf
, PAGE_SIZE
, "ISP%04X\n", vha
->hw
->pdev
->device
);
1089 qla2x00_isp_id_show(struct device
*dev
, struct device_attribute
*attr
,
1092 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1093 struct qla_hw_data
*ha
= vha
->hw
;
1095 if (IS_QLAFX00(vha
->hw
))
1096 return scnprintf(buf
, PAGE_SIZE
, "%s\n",
1097 vha
->hw
->mr
.hw_version
);
1099 return scnprintf(buf
, PAGE_SIZE
, "%04x %04x %04x %04x\n",
1100 ha
->product_id
[0], ha
->product_id
[1], ha
->product_id
[2],
1105 qla2x00_model_name_show(struct device
*dev
, struct device_attribute
*attr
,
1108 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1110 return scnprintf(buf
, PAGE_SIZE
, "%s\n", vha
->hw
->model_number
);
1114 qla2x00_model_desc_show(struct device
*dev
, struct device_attribute
*attr
,
1117 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1119 return scnprintf(buf
, PAGE_SIZE
, "%s\n", vha
->hw
->model_desc
);
1123 qla2x00_pci_info_show(struct device
*dev
, struct device_attribute
*attr
,
1126 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1129 return scnprintf(buf
, PAGE_SIZE
, "%s\n",
1130 vha
->hw
->isp_ops
->pci_info_str(vha
, pci_info
,
1135 qla2x00_link_state_show(struct device
*dev
, struct device_attribute
*attr
,
1138 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1139 struct qla_hw_data
*ha
= vha
->hw
;
1142 if (atomic_read(&vha
->loop_state
) == LOOP_DOWN
||
1143 atomic_read(&vha
->loop_state
) == LOOP_DEAD
||
1144 vha
->device_flags
& DFLG_NO_CABLE
)
1145 len
= scnprintf(buf
, PAGE_SIZE
, "Link Down\n");
1146 else if (atomic_read(&vha
->loop_state
) != LOOP_READY
||
1147 qla2x00_chip_is_down(vha
))
1148 len
= scnprintf(buf
, PAGE_SIZE
, "Unknown Link State\n");
1150 len
= scnprintf(buf
, PAGE_SIZE
, "Link Up - ");
1152 switch (ha
->current_topology
) {
1154 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
1157 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "FL_Port\n");
1160 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
1161 "N_Port to N_Port\n");
1164 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "F_Port\n");
1167 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
1175 qla2x00_zio_show(struct device
*dev
, struct device_attribute
*attr
,
1178 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1181 switch (vha
->hw
->zio_mode
) {
1182 case QLA_ZIO_MODE_6
:
1183 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "Mode 6\n");
1185 case QLA_ZIO_DISABLED
:
1186 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
1193 qla2x00_zio_store(struct device
*dev
, struct device_attribute
*attr
,
1194 const char *buf
, size_t count
)
1196 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1197 struct qla_hw_data
*ha
= vha
->hw
;
1201 if (!IS_ZIO_SUPPORTED(ha
))
1204 if (sscanf(buf
, "%d", &val
) != 1)
1208 zio_mode
= QLA_ZIO_MODE_6
;
1210 zio_mode
= QLA_ZIO_DISABLED
;
1212 /* Update per-hba values and queue a reset. */
1213 if (zio_mode
!= QLA_ZIO_DISABLED
|| ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
1214 ha
->zio_mode
= zio_mode
;
1215 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1221 qla2x00_zio_timer_show(struct device
*dev
, struct device_attribute
*attr
,
1224 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1226 return scnprintf(buf
, PAGE_SIZE
, "%d us\n", vha
->hw
->zio_timer
* 100);
1230 qla2x00_zio_timer_store(struct device
*dev
, struct device_attribute
*attr
,
1231 const char *buf
, size_t count
)
1233 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1237 if (sscanf(buf
, "%d", &val
) != 1)
1239 if (val
> 25500 || val
< 100)
1242 zio_timer
= (uint16_t)(val
/ 100);
1243 vha
->hw
->zio_timer
= zio_timer
;
1249 qla_zio_threshold_show(struct device
*dev
, struct device_attribute
*attr
,
1252 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1254 return scnprintf(buf
, PAGE_SIZE
, "%d exchanges\n",
1255 vha
->hw
->last_zio_threshold
);
1259 qla_zio_threshold_store(struct device
*dev
, struct device_attribute
*attr
,
1260 const char *buf
, size_t count
)
1262 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1265 if (vha
->hw
->zio_mode
!= QLA_ZIO_MODE_6
)
1267 if (sscanf(buf
, "%d", &val
) != 1)
1269 if (val
< 0 || val
> 256)
1272 atomic_set(&vha
->hw
->zio_threshold
, val
);
1277 qla2x00_beacon_show(struct device
*dev
, struct device_attribute
*attr
,
1280 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1283 if (vha
->hw
->beacon_blink_led
)
1284 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "Enabled\n");
1286 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
1291 qla2x00_beacon_store(struct device
*dev
, struct device_attribute
*attr
,
1292 const char *buf
, size_t count
)
1294 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1295 struct qla_hw_data
*ha
= vha
->hw
;
1299 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1302 if (sscanf(buf
, "%d", &val
) != 1)
1305 mutex_lock(&vha
->hw
->optrom_mutex
);
1306 if (qla2x00_chip_is_down(vha
)) {
1307 mutex_unlock(&vha
->hw
->optrom_mutex
);
1308 ql_log(ql_log_warn
, vha
, 0x707a,
1309 "Abort ISP active -- ignoring beacon request.\n");
1314 rval
= ha
->isp_ops
->beacon_on(vha
);
1316 rval
= ha
->isp_ops
->beacon_off(vha
);
1318 if (rval
!= QLA_SUCCESS
)
1321 mutex_unlock(&vha
->hw
->optrom_mutex
);
1327 qla2x00_beacon_config_show(struct device
*dev
, struct device_attribute
*attr
,
1330 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1331 struct qla_hw_data
*ha
= vha
->hw
;
1332 uint16_t led
[3] = { 0 };
1334 if (!IS_QLA2031(ha
) && !IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
1337 if (ql26xx_led_config(vha
, 0, led
))
1338 return scnprintf(buf
, PAGE_SIZE
, "\n");
1340 return scnprintf(buf
, PAGE_SIZE
, "%#04hx %#04hx %#04hx\n",
1341 led
[0], led
[1], led
[2]);
1345 qla2x00_beacon_config_store(struct device
*dev
, struct device_attribute
*attr
,
1346 const char *buf
, size_t count
)
1348 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1349 struct qla_hw_data
*ha
= vha
->hw
;
1350 uint16_t options
= BIT_0
;
1351 uint16_t led
[3] = { 0 };
1355 if (!IS_QLA2031(ha
) && !IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
1358 n
= sscanf(buf
, "%hx %hx %hx %hx", word
+0, word
+1, word
+2, word
+3);
1361 options
|= BIT_3
|BIT_2
|BIT_1
;
1371 /* check led index */
1393 if (ql26xx_led_config(vha
, options
, led
))
1400 qla2x00_optrom_bios_version_show(struct device
*dev
,
1401 struct device_attribute
*attr
, char *buf
)
1403 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1404 struct qla_hw_data
*ha
= vha
->hw
;
1406 return scnprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->bios_revision
[1],
1407 ha
->bios_revision
[0]);
1411 qla2x00_optrom_efi_version_show(struct device
*dev
,
1412 struct device_attribute
*attr
, char *buf
)
1414 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1415 struct qla_hw_data
*ha
= vha
->hw
;
1417 return scnprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->efi_revision
[1],
1418 ha
->efi_revision
[0]);
1422 qla2x00_optrom_fcode_version_show(struct device
*dev
,
1423 struct device_attribute
*attr
, char *buf
)
1425 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1426 struct qla_hw_data
*ha
= vha
->hw
;
1428 return scnprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->fcode_revision
[1],
1429 ha
->fcode_revision
[0]);
1433 qla2x00_optrom_fw_version_show(struct device
*dev
,
1434 struct device_attribute
*attr
, char *buf
)
1436 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1437 struct qla_hw_data
*ha
= vha
->hw
;
1439 return scnprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d %d\n",
1440 ha
->fw_revision
[0], ha
->fw_revision
[1], ha
->fw_revision
[2],
1441 ha
->fw_revision
[3]);
1445 qla2x00_optrom_gold_fw_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 if (!IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
1452 !IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
1453 return scnprintf(buf
, PAGE_SIZE
, "\n");
1455 return scnprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d (%d)\n",
1456 ha
->gold_fw_version
[0], ha
->gold_fw_version
[1],
1457 ha
->gold_fw_version
[2], ha
->gold_fw_version
[3]);
1461 qla2x00_total_isp_aborts_show(struct device
*dev
,
1462 struct device_attribute
*attr
, char *buf
)
1464 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1466 return scnprintf(buf
, PAGE_SIZE
, "%d\n",
1467 vha
->qla_stats
.total_isp_aborts
);
1471 qla24xx_84xx_fw_version_show(struct device
*dev
,
1472 struct device_attribute
*attr
, char *buf
)
1474 int rval
= QLA_SUCCESS
;
1475 uint16_t status
[2] = { 0 };
1476 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1477 struct qla_hw_data
*ha
= vha
->hw
;
1479 if (!IS_QLA84XX(ha
))
1480 return scnprintf(buf
, PAGE_SIZE
, "\n");
1482 if (!ha
->cs84xx
->op_fw_version
) {
1483 rval
= qla84xx_verify_chip(vha
, status
);
1485 if (!rval
&& !status
[0])
1486 return scnprintf(buf
, PAGE_SIZE
, "%u\n",
1487 (uint32_t)ha
->cs84xx
->op_fw_version
);
1490 return scnprintf(buf
, PAGE_SIZE
, "\n");
1494 qla2x00_serdes_version_show(struct device
*dev
, struct device_attribute
*attr
,
1497 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1498 struct qla_hw_data
*ha
= vha
->hw
;
1500 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
1501 return scnprintf(buf
, PAGE_SIZE
, "\n");
1503 return scnprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d\n",
1504 ha
->serdes_version
[0], ha
->serdes_version
[1],
1505 ha
->serdes_version
[2]);
1509 qla2x00_mpi_version_show(struct device
*dev
, struct device_attribute
*attr
,
1512 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1513 struct qla_hw_data
*ha
= vha
->hw
;
1515 if (!IS_QLA81XX(ha
) && !IS_QLA8031(ha
) && !IS_QLA8044(ha
) &&
1516 !IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
1517 return scnprintf(buf
, PAGE_SIZE
, "\n");
1519 return scnprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d (%x)\n",
1520 ha
->mpi_version
[0], ha
->mpi_version
[1], ha
->mpi_version
[2],
1521 ha
->mpi_capabilities
);
1525 qla2x00_phy_version_show(struct device
*dev
, struct device_attribute
*attr
,
1528 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1529 struct qla_hw_data
*ha
= vha
->hw
;
1531 if (!IS_QLA81XX(ha
) && !IS_QLA8031(ha
))
1532 return scnprintf(buf
, PAGE_SIZE
, "\n");
1534 return scnprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d\n",
1535 ha
->phy_version
[0], ha
->phy_version
[1], ha
->phy_version
[2]);
1539 qla2x00_flash_block_size_show(struct device
*dev
,
1540 struct device_attribute
*attr
, char *buf
)
1542 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1543 struct qla_hw_data
*ha
= vha
->hw
;
1545 return scnprintf(buf
, PAGE_SIZE
, "0x%x\n", ha
->fdt_block_size
);
1549 qla2x00_vlan_id_show(struct device
*dev
, struct device_attribute
*attr
,
1552 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1554 if (!IS_CNA_CAPABLE(vha
->hw
))
1555 return scnprintf(buf
, PAGE_SIZE
, "\n");
1557 return scnprintf(buf
, PAGE_SIZE
, "%d\n", vha
->fcoe_vlan_id
);
1561 qla2x00_vn_port_mac_address_show(struct device
*dev
,
1562 struct device_attribute
*attr
, char *buf
)
1564 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1566 if (!IS_CNA_CAPABLE(vha
->hw
))
1567 return scnprintf(buf
, PAGE_SIZE
, "\n");
1569 return scnprintf(buf
, PAGE_SIZE
, "%pMR\n", vha
->fcoe_vn_port_mac
);
1573 qla2x00_fabric_param_show(struct device
*dev
, struct device_attribute
*attr
,
1576 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1578 return scnprintf(buf
, PAGE_SIZE
, "%d\n", vha
->hw
->switch_cap
);
1582 qla2x00_thermal_temp_show(struct device
*dev
,
1583 struct device_attribute
*attr
, char *buf
)
1585 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1589 mutex_lock(&vha
->hw
->optrom_mutex
);
1590 if (qla2x00_chip_is_down(vha
)) {
1591 mutex_unlock(&vha
->hw
->optrom_mutex
);
1592 ql_log(ql_log_warn
, vha
, 0x70dc, "ISP reset active.\n");
1596 if (vha
->hw
->flags
.eeh_busy
) {
1597 mutex_unlock(&vha
->hw
->optrom_mutex
);
1598 ql_log(ql_log_warn
, vha
, 0x70dd, "PCI EEH busy.\n");
1602 rc
= qla2x00_get_thermal_temp(vha
, &temp
);
1603 mutex_unlock(&vha
->hw
->optrom_mutex
);
1604 if (rc
== QLA_SUCCESS
)
1605 return scnprintf(buf
, PAGE_SIZE
, "%d\n", temp
);
1608 return scnprintf(buf
, PAGE_SIZE
, "\n");
1612 qla2x00_fw_state_show(struct device
*dev
, struct device_attribute
*attr
,
1615 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1616 int rval
= QLA_FUNCTION_FAILED
;
1620 if (IS_QLAFX00(vha
->hw
)) {
1621 pstate
= qlafx00_fw_state_show(dev
, attr
, buf
);
1622 return scnprintf(buf
, PAGE_SIZE
, "0x%x\n", pstate
);
1625 mutex_lock(&vha
->hw
->optrom_mutex
);
1626 if (qla2x00_chip_is_down(vha
)) {
1627 mutex_unlock(&vha
->hw
->optrom_mutex
);
1628 ql_log(ql_log_warn
, vha
, 0x707c,
1629 "ISP reset active.\n");
1631 } else if (vha
->hw
->flags
.eeh_busy
) {
1632 mutex_unlock(&vha
->hw
->optrom_mutex
);
1636 rval
= qla2x00_get_firmware_state(vha
, state
);
1637 mutex_unlock(&vha
->hw
->optrom_mutex
);
1639 if (rval
!= QLA_SUCCESS
) {
1640 memset(state
, -1, sizeof(state
));
1641 rval
= qla2x00_get_firmware_state(vha
, state
);
1644 return scnprintf(buf
, PAGE_SIZE
, "0x%x 0x%x 0x%x 0x%x 0x%x 0x%x\n",
1645 state
[0], state
[1], state
[2], state
[3], state
[4], state
[5]);
1649 qla2x00_diag_requests_show(struct device
*dev
,
1650 struct device_attribute
*attr
, char *buf
)
1652 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1654 if (!IS_BIDI_CAPABLE(vha
->hw
))
1655 return scnprintf(buf
, PAGE_SIZE
, "\n");
1657 return scnprintf(buf
, PAGE_SIZE
, "%llu\n", vha
->bidi_stats
.io_count
);
1661 qla2x00_diag_megabytes_show(struct device
*dev
,
1662 struct device_attribute
*attr
, char *buf
)
1664 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1666 if (!IS_BIDI_CAPABLE(vha
->hw
))
1667 return scnprintf(buf
, PAGE_SIZE
, "\n");
1669 return scnprintf(buf
, PAGE_SIZE
, "%llu\n",
1670 vha
->bidi_stats
.transfer_bytes
>> 20);
1674 qla2x00_fw_dump_size_show(struct device
*dev
, struct device_attribute
*attr
,
1677 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1678 struct qla_hw_data
*ha
= vha
->hw
;
1683 else if (IS_P3P_TYPE(ha
))
1684 size
= ha
->md_template_size
+ ha
->md_dump_size
;
1686 size
= ha
->fw_dump_len
;
1688 return scnprintf(buf
, PAGE_SIZE
, "%d\n", size
);
1692 qla2x00_allow_cna_fw_dump_show(struct device
*dev
,
1693 struct device_attribute
*attr
, char *buf
)
1695 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1697 if (!IS_P3P_TYPE(vha
->hw
))
1698 return scnprintf(buf
, PAGE_SIZE
, "\n");
1700 return scnprintf(buf
, PAGE_SIZE
, "%s\n",
1701 vha
->hw
->allow_cna_fw_dump
? "true" : "false");
1705 qla2x00_allow_cna_fw_dump_store(struct device
*dev
,
1706 struct device_attribute
*attr
, const char *buf
, size_t count
)
1708 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1711 if (!IS_P3P_TYPE(vha
->hw
))
1714 if (sscanf(buf
, "%d", &val
) != 1)
1717 vha
->hw
->allow_cna_fw_dump
= val
!= 0;
1723 qla2x00_pep_version_show(struct device
*dev
, struct device_attribute
*attr
,
1726 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1727 struct qla_hw_data
*ha
= vha
->hw
;
1729 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
1730 return scnprintf(buf
, PAGE_SIZE
, "\n");
1732 return scnprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d\n",
1733 ha
->pep_version
[0], ha
->pep_version
[1], ha
->pep_version
[2]);
1737 qla2x00_min_supported_speed_show(struct device
*dev
,
1738 struct device_attribute
*attr
, char *buf
)
1740 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1741 struct qla_hw_data
*ha
= vha
->hw
;
1743 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
1744 return scnprintf(buf
, PAGE_SIZE
, "\n");
1746 return scnprintf(buf
, PAGE_SIZE
, "%s\n",
1747 ha
->min_supported_speed
== 6 ? "64Gps" :
1748 ha
->min_supported_speed
== 5 ? "32Gps" :
1749 ha
->min_supported_speed
== 4 ? "16Gps" :
1750 ha
->min_supported_speed
== 3 ? "8Gps" :
1751 ha
->min_supported_speed
== 2 ? "4Gps" :
1752 ha
->min_supported_speed
!= 0 ? "unknown" : "");
1756 qla2x00_max_supported_speed_show(struct device
*dev
,
1757 struct device_attribute
*attr
, char *buf
)
1759 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1760 struct qla_hw_data
*ha
= vha
->hw
;
1762 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
1763 return scnprintf(buf
, PAGE_SIZE
, "\n");
1765 return scnprintf(buf
, PAGE_SIZE
, "%s\n",
1766 ha
->max_supported_speed
== 2 ? "64Gps" :
1767 ha
->max_supported_speed
== 1 ? "32Gps" :
1768 ha
->max_supported_speed
== 0 ? "16Gps" : "unknown");
1772 qla2x00_port_speed_store(struct device
*dev
, struct device_attribute
*attr
,
1773 const char *buf
, size_t count
)
1775 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(dev
));
1778 int mode
= QLA_SET_DATA_RATE_LR
;
1779 struct qla_hw_data
*ha
= vha
->hw
;
1781 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
)) {
1782 ql_log(ql_log_warn
, vha
, 0x70d8,
1783 "Speed setting not supported \n");
1787 rval
= kstrtol(buf
, 10, &type
);
1791 if (type
== 40 || type
== 80 || type
== 160 ||
1793 ql_dbg(ql_dbg_user
, vha
, 0x70d9,
1794 "Setting will be affected after a loss of sync\n");
1796 mode
= QLA_SET_DATA_RATE_NOLR
;
1799 oldspeed
= ha
->set_data_rate
;
1803 ha
->set_data_rate
= PORT_SPEED_AUTO
;
1806 ha
->set_data_rate
= PORT_SPEED_4GB
;
1809 ha
->set_data_rate
= PORT_SPEED_8GB
;
1812 ha
->set_data_rate
= PORT_SPEED_16GB
;
1815 ha
->set_data_rate
= PORT_SPEED_32GB
;
1818 ql_log(ql_log_warn
, vha
, 0x1199,
1819 "Unrecognized speed setting:%lx. Setting Autoneg\n",
1821 ha
->set_data_rate
= PORT_SPEED_AUTO
;
1824 if (qla2x00_chip_is_down(vha
) || (oldspeed
== ha
->set_data_rate
))
1827 ql_log(ql_log_info
, vha
, 0x70da,
1828 "Setting speed to %lx Gbps \n", type
);
1830 rval
= qla2x00_set_data_rate(vha
, mode
);
1831 if (rval
!= QLA_SUCCESS
)
1838 qla2x00_port_speed_show(struct device
*dev
, struct device_attribute
*attr
,
1841 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(dev
));
1842 struct qla_hw_data
*ha
= vha
->hw
;
1844 char *spd
[7] = {"0", "0", "0", "4", "8", "16", "32"};
1846 rval
= qla2x00_get_data_rate(vha
);
1847 if (rval
!= QLA_SUCCESS
) {
1848 ql_log(ql_log_warn
, vha
, 0x70db,
1849 "Unable to get port speed rval:%zd\n", rval
);
1853 ql_log(ql_log_info
, vha
, 0x70d6,
1854 "port speed:%d\n", ha
->link_data_rate
);
1856 return scnprintf(buf
, PAGE_SIZE
, "%s\n", spd
[ha
->link_data_rate
]);
1862 qlini_mode_show(struct device
*dev
, struct device_attribute
*attr
, char *buf
)
1864 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1867 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
1868 "Supported options: enabled | disabled | dual | exclusive\n");
1871 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "Current selection: ");
1873 switch (vha
->qlini_mode
) {
1874 case QLA2XXX_INI_MODE_EXCLUSIVE
:
1875 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
1876 QLA2XXX_INI_MODE_STR_EXCLUSIVE
);
1878 case QLA2XXX_INI_MODE_DISABLED
:
1879 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
1880 QLA2XXX_INI_MODE_STR_DISABLED
);
1882 case QLA2XXX_INI_MODE_ENABLED
:
1883 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
1884 QLA2XXX_INI_MODE_STR_ENABLED
);
1886 case QLA2XXX_INI_MODE_DUAL
:
1887 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
1888 QLA2XXX_INI_MODE_STR_DUAL
);
1891 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
, "\n");
1896 static char *mode_to_str
[] = {
1903 #define NEED_EXCH_OFFLOAD(_exchg) ((_exchg) > FW_DEF_EXCHANGES_CNT)
1904 static int qla_set_ini_mode(scsi_qla_host_t
*vha
, int op
)
1910 MODE_CHANGE_NO_ACTION
,
1911 TARGET_STILL_ACTIVE
,
1913 int action
= NO_ACTION
;
1915 u8 eo_toggle
= 0; /* exchange offload flipped */
1917 switch (vha
->qlini_mode
) {
1918 case QLA2XXX_INI_MODE_DISABLED
:
1920 case QLA2XXX_INI_MODE_DISABLED
:
1921 if (qla_tgt_mode_enabled(vha
)) {
1922 if (NEED_EXCH_OFFLOAD(vha
->u_ql2xexchoffld
) !=
1923 vha
->hw
->flags
.exchoffld_enabled
)
1925 if (((vha
->ql2xexchoffld
!=
1926 vha
->u_ql2xexchoffld
) &&
1927 NEED_EXCH_OFFLOAD(vha
->u_ql2xexchoffld
)) ||
1930 * The number of exchange to be offload
1931 * was tweaked or offload option was
1934 action
= MODE_CHANGE_ACCEPT
;
1936 action
= MODE_CHANGE_NO_ACTION
;
1939 action
= MODE_CHANGE_NO_ACTION
;
1942 case QLA2XXX_INI_MODE_EXCLUSIVE
:
1943 if (qla_tgt_mode_enabled(vha
)) {
1944 if (NEED_EXCH_OFFLOAD(vha
->u_ql2xexchoffld
) !=
1945 vha
->hw
->flags
.exchoffld_enabled
)
1947 if (((vha
->ql2xexchoffld
!=
1948 vha
->u_ql2xexchoffld
) &&
1949 NEED_EXCH_OFFLOAD(vha
->u_ql2xexchoffld
)) ||
1952 * The number of exchange to be offload
1953 * was tweaked or offload option was
1956 action
= MODE_CHANGE_ACCEPT
;
1958 action
= MODE_CHANGE_NO_ACTION
;
1961 action
= MODE_CHANGE_ACCEPT
;
1964 case QLA2XXX_INI_MODE_DUAL
:
1965 action
= MODE_CHANGE_ACCEPT
;
1966 /* active_mode is target only, reset it to dual */
1967 if (qla_tgt_mode_enabled(vha
)) {
1969 action
= MODE_CHANGE_ACCEPT
;
1971 action
= MODE_CHANGE_NO_ACTION
;
1975 case QLA2XXX_INI_MODE_ENABLED
:
1976 if (qla_tgt_mode_enabled(vha
))
1977 action
= TARGET_STILL_ACTIVE
;
1979 action
= MODE_CHANGE_ACCEPT
;
1986 case QLA2XXX_INI_MODE_EXCLUSIVE
:
1988 case QLA2XXX_INI_MODE_EXCLUSIVE
:
1989 if (qla_tgt_mode_enabled(vha
)) {
1990 if (NEED_EXCH_OFFLOAD(vha
->u_ql2xexchoffld
) !=
1991 vha
->hw
->flags
.exchoffld_enabled
)
1993 if (((vha
->ql2xexchoffld
!=
1994 vha
->u_ql2xexchoffld
) &&
1995 NEED_EXCH_OFFLOAD(vha
->u_ql2xexchoffld
)) ||
1998 * The number of exchange to be offload
1999 * was tweaked or offload option was
2002 action
= MODE_CHANGE_ACCEPT
;
2010 case QLA2XXX_INI_MODE_DISABLED
:
2011 if (qla_tgt_mode_enabled(vha
)) {
2012 if (NEED_EXCH_OFFLOAD(vha
->u_ql2xexchoffld
) !=
2013 vha
->hw
->flags
.exchoffld_enabled
)
2015 if (((vha
->ql2xexchoffld
!=
2016 vha
->u_ql2xexchoffld
) &&
2017 NEED_EXCH_OFFLOAD(vha
->u_ql2xexchoffld
)) ||
2019 action
= MODE_CHANGE_ACCEPT
;
2021 action
= MODE_CHANGE_NO_ACTION
;
2023 action
= MODE_CHANGE_NO_ACTION
;
2026 case QLA2XXX_INI_MODE_DUAL
: /* exclusive -> dual */
2027 if (qla_tgt_mode_enabled(vha
)) {
2028 action
= MODE_CHANGE_ACCEPT
;
2031 action
= MODE_CHANGE_ACCEPT
;
2034 case QLA2XXX_INI_MODE_ENABLED
:
2035 if (qla_tgt_mode_enabled(vha
))
2036 action
= TARGET_STILL_ACTIVE
;
2038 if (vha
->hw
->flags
.fw_started
)
2039 action
= MODE_CHANGE_NO_ACTION
;
2041 action
= MODE_CHANGE_ACCEPT
;
2047 case QLA2XXX_INI_MODE_ENABLED
:
2049 case QLA2XXX_INI_MODE_ENABLED
:
2050 if (NEED_EXCH_OFFLOAD(vha
->u_ql2xiniexchg
) !=
2051 vha
->hw
->flags
.exchoffld_enabled
)
2053 if (((vha
->ql2xiniexchg
!= vha
->u_ql2xiniexchg
) &&
2054 NEED_EXCH_OFFLOAD(vha
->u_ql2xiniexchg
)) ||
2056 action
= MODE_CHANGE_ACCEPT
;
2060 case QLA2XXX_INI_MODE_DUAL
:
2061 case QLA2XXX_INI_MODE_DISABLED
:
2062 action
= MODE_CHANGE_ACCEPT
;
2065 action
= MODE_CHANGE_NO_ACTION
;
2070 case QLA2XXX_INI_MODE_DUAL
:
2072 case QLA2XXX_INI_MODE_DUAL
:
2073 if (qla_tgt_mode_enabled(vha
) ||
2074 qla_dual_mode_enabled(vha
)) {
2075 if (NEED_EXCH_OFFLOAD(vha
->u_ql2xexchoffld
+
2076 vha
->u_ql2xiniexchg
) !=
2077 vha
->hw
->flags
.exchoffld_enabled
)
2080 if ((((vha
->ql2xexchoffld
+
2081 vha
->ql2xiniexchg
) !=
2082 (vha
->u_ql2xiniexchg
+
2083 vha
->u_ql2xexchoffld
)) &&
2084 NEED_EXCH_OFFLOAD(vha
->u_ql2xiniexchg
+
2085 vha
->u_ql2xexchoffld
)) || eo_toggle
)
2086 action
= MODE_CHANGE_ACCEPT
;
2090 if (NEED_EXCH_OFFLOAD(vha
->u_ql2xexchoffld
+
2091 vha
->u_ql2xiniexchg
) !=
2092 vha
->hw
->flags
.exchoffld_enabled
)
2095 if ((((vha
->ql2xexchoffld
+ vha
->ql2xiniexchg
)
2096 != (vha
->u_ql2xiniexchg
+
2097 vha
->u_ql2xexchoffld
)) &&
2098 NEED_EXCH_OFFLOAD(vha
->u_ql2xiniexchg
+
2099 vha
->u_ql2xexchoffld
)) || eo_toggle
)
2100 action
= MODE_CHANGE_NO_ACTION
;
2106 case QLA2XXX_INI_MODE_DISABLED
:
2107 if (qla_tgt_mode_enabled(vha
) ||
2108 qla_dual_mode_enabled(vha
)) {
2109 /* turning off initiator mode */
2111 action
= MODE_CHANGE_ACCEPT
;
2113 action
= MODE_CHANGE_NO_ACTION
;
2117 case QLA2XXX_INI_MODE_EXCLUSIVE
:
2118 if (qla_tgt_mode_enabled(vha
) ||
2119 qla_dual_mode_enabled(vha
)) {
2121 action
= MODE_CHANGE_ACCEPT
;
2123 action
= MODE_CHANGE_ACCEPT
;
2127 case QLA2XXX_INI_MODE_ENABLED
:
2128 if (qla_tgt_mode_enabled(vha
) ||
2129 qla_dual_mode_enabled(vha
)) {
2130 action
= TARGET_STILL_ACTIVE
;
2132 action
= MODE_CHANGE_ACCEPT
;
2139 case MODE_CHANGE_ACCEPT
:
2140 ql_log(ql_log_warn
, vha
, 0xffff,
2141 "Mode change accepted. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2142 mode_to_str
[vha
->qlini_mode
], mode_to_str
[op
],
2143 vha
->ql2xexchoffld
, vha
->u_ql2xexchoffld
,
2144 vha
->ql2xiniexchg
, vha
->u_ql2xiniexchg
);
2146 vha
->qlini_mode
= op
;
2147 vha
->ql2xexchoffld
= vha
->u_ql2xexchoffld
;
2148 vha
->ql2xiniexchg
= vha
->u_ql2xiniexchg
;
2151 vha
->flags
.online
= 1;
2152 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2155 case MODE_CHANGE_NO_ACTION
:
2156 ql_log(ql_log_warn
, vha
, 0xffff,
2157 "Mode is set. No action taken. From %s to %s, Tgt exchg %d|%d. ini exchg %d|%d\n",
2158 mode_to_str
[vha
->qlini_mode
], mode_to_str
[op
],
2159 vha
->ql2xexchoffld
, vha
->u_ql2xexchoffld
,
2160 vha
->ql2xiniexchg
, vha
->u_ql2xiniexchg
);
2161 vha
->qlini_mode
= op
;
2162 vha
->ql2xexchoffld
= vha
->u_ql2xexchoffld
;
2163 vha
->ql2xiniexchg
= vha
->u_ql2xiniexchg
;
2166 case TARGET_STILL_ACTIVE
:
2167 ql_log(ql_log_warn
, vha
, 0xffff,
2168 "Target Mode is active. Unable to change Mode.\n");
2173 ql_log(ql_log_warn
, vha
, 0xffff,
2174 "Mode unchange. No action taken. %d|%d pct %d|%d.\n",
2175 vha
->qlini_mode
, op
,
2176 vha
->ql2xexchoffld
, vha
->u_ql2xexchoffld
);
2184 qlini_mode_store(struct device
*dev
, struct device_attribute
*attr
,
2185 const char *buf
, size_t count
)
2187 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
2193 if (strncasecmp(QLA2XXX_INI_MODE_STR_EXCLUSIVE
, buf
,
2194 strlen(QLA2XXX_INI_MODE_STR_EXCLUSIVE
)) == 0)
2195 ini
= QLA2XXX_INI_MODE_EXCLUSIVE
;
2196 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DISABLED
, buf
,
2197 strlen(QLA2XXX_INI_MODE_STR_DISABLED
)) == 0)
2198 ini
= QLA2XXX_INI_MODE_DISABLED
;
2199 else if (strncasecmp(QLA2XXX_INI_MODE_STR_ENABLED
, buf
,
2200 strlen(QLA2XXX_INI_MODE_STR_ENABLED
)) == 0)
2201 ini
= QLA2XXX_INI_MODE_ENABLED
;
2202 else if (strncasecmp(QLA2XXX_INI_MODE_STR_DUAL
, buf
,
2203 strlen(QLA2XXX_INI_MODE_STR_DUAL
)) == 0)
2204 ini
= QLA2XXX_INI_MODE_DUAL
;
2208 qla_set_ini_mode(vha
, ini
);
2213 ql2xexchoffld_show(struct device
*dev
, struct device_attribute
*attr
,
2216 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
2219 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
2220 "target exchange: new %d : current: %d\n\n",
2221 vha
->u_ql2xexchoffld
, vha
->ql2xexchoffld
);
2223 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
2224 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2231 ql2xexchoffld_store(struct device
*dev
, struct device_attribute
*attr
,
2232 const char *buf
, size_t count
)
2234 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
2237 if (sscanf(buf
, "%d", &val
) != 1)
2240 if (val
> FW_MAX_EXCHANGES_CNT
)
2241 val
= FW_MAX_EXCHANGES_CNT
;
2245 vha
->u_ql2xexchoffld
= val
;
2250 ql2xiniexchg_show(struct device
*dev
, struct device_attribute
*attr
,
2253 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
2256 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
2257 "target exchange: new %d : current: %d\n\n",
2258 vha
->u_ql2xiniexchg
, vha
->ql2xiniexchg
);
2260 len
+= scnprintf(buf
+ len
, PAGE_SIZE
-len
,
2261 "Please (re)set operating mode via \"/sys/class/scsi_host/host%ld/qlini_mode\" to load new setting.\n",
2268 ql2xiniexchg_store(struct device
*dev
, struct device_attribute
*attr
,
2269 const char *buf
, size_t count
)
2271 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
2274 if (sscanf(buf
, "%d", &val
) != 1)
2277 if (val
> FW_MAX_EXCHANGES_CNT
)
2278 val
= FW_MAX_EXCHANGES_CNT
;
2282 vha
->u_ql2xiniexchg
= val
;
2287 qla2x00_dif_bundle_statistics_show(struct device
*dev
,
2288 struct device_attribute
*attr
, char *buf
)
2290 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
2291 struct qla_hw_data
*ha
= vha
->hw
;
2293 return scnprintf(buf
, PAGE_SIZE
,
2294 "cross=%llu read=%llu write=%llu kalloc=%llu dma_alloc=%llu unusable=%u\n",
2295 ha
->dif_bundle_crossed_pages
, ha
->dif_bundle_reads
,
2296 ha
->dif_bundle_writes
, ha
->dif_bundle_kallocs
,
2297 ha
->dif_bundle_dma_allocs
, ha
->pool
.unusable
.count
);
2301 qla2x00_fw_attr_show(struct device
*dev
,
2302 struct device_attribute
*attr
, char *buf
)
2304 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
2305 struct qla_hw_data
*ha
= vha
->hw
;
2307 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
2308 return scnprintf(buf
, PAGE_SIZE
, "\n");
2310 return scnprintf(buf
, PAGE_SIZE
, "%llx\n",
2311 (uint64_t)ha
->fw_attributes_ext
[1] << 48 |
2312 (uint64_t)ha
->fw_attributes_ext
[0] << 32 |
2313 (uint64_t)ha
->fw_attributes_h
<< 16 |
2314 (uint64_t)ha
->fw_attributes
);
2318 qla2x00_port_no_show(struct device
*dev
, struct device_attribute
*attr
,
2321 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
2323 return scnprintf(buf
, PAGE_SIZE
, "%u\n", vha
->hw
->port_no
);
2327 qla2x00_dport_diagnostics_show(struct device
*dev
,
2328 struct device_attribute
*attr
, char *buf
)
2330 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
2332 if (!IS_QLA83XX(vha
->hw
) && !IS_QLA27XX(vha
->hw
) &&
2333 !IS_QLA28XX(vha
->hw
))
2334 return scnprintf(buf
, PAGE_SIZE
, "\n");
2336 if (!*vha
->dport_data
)
2337 return scnprintf(buf
, PAGE_SIZE
, "\n");
2339 return scnprintf(buf
, PAGE_SIZE
, "%04x %04x %04x %04x\n",
2340 vha
->dport_data
[0], vha
->dport_data
[1],
2341 vha
->dport_data
[2], vha
->dport_data
[3]);
2343 static DEVICE_ATTR(dport_diagnostics
, 0444,
2344 qla2x00_dport_diagnostics_show
, NULL
);
2346 static DEVICE_ATTR(driver_version
, S_IRUGO
, qla2x00_driver_version_show
, NULL
);
2347 static DEVICE_ATTR(fw_version
, S_IRUGO
, qla2x00_fw_version_show
, NULL
);
2348 static DEVICE_ATTR(serial_num
, S_IRUGO
, qla2x00_serial_num_show
, NULL
);
2349 static DEVICE_ATTR(isp_name
, S_IRUGO
, qla2x00_isp_name_show
, NULL
);
2350 static DEVICE_ATTR(isp_id
, S_IRUGO
, qla2x00_isp_id_show
, NULL
);
2351 static DEVICE_ATTR(model_name
, S_IRUGO
, qla2x00_model_name_show
, NULL
);
2352 static DEVICE_ATTR(model_desc
, S_IRUGO
, qla2x00_model_desc_show
, NULL
);
2353 static DEVICE_ATTR(pci_info
, S_IRUGO
, qla2x00_pci_info_show
, NULL
);
2354 static DEVICE_ATTR(link_state
, S_IRUGO
, qla2x00_link_state_show
, NULL
);
2355 static DEVICE_ATTR(zio
, S_IRUGO
| S_IWUSR
, qla2x00_zio_show
, qla2x00_zio_store
);
2356 static DEVICE_ATTR(zio_timer
, S_IRUGO
| S_IWUSR
, qla2x00_zio_timer_show
,
2357 qla2x00_zio_timer_store
);
2358 static DEVICE_ATTR(beacon
, S_IRUGO
| S_IWUSR
, qla2x00_beacon_show
,
2359 qla2x00_beacon_store
);
2360 static DEVICE_ATTR(beacon_config
, 0644, qla2x00_beacon_config_show
,
2361 qla2x00_beacon_config_store
);
2362 static DEVICE_ATTR(optrom_bios_version
, S_IRUGO
,
2363 qla2x00_optrom_bios_version_show
, NULL
);
2364 static DEVICE_ATTR(optrom_efi_version
, S_IRUGO
,
2365 qla2x00_optrom_efi_version_show
, NULL
);
2366 static DEVICE_ATTR(optrom_fcode_version
, S_IRUGO
,
2367 qla2x00_optrom_fcode_version_show
, NULL
);
2368 static DEVICE_ATTR(optrom_fw_version
, S_IRUGO
, qla2x00_optrom_fw_version_show
,
2370 static DEVICE_ATTR(optrom_gold_fw_version
, S_IRUGO
,
2371 qla2x00_optrom_gold_fw_version_show
, NULL
);
2372 static DEVICE_ATTR(84xx_fw_version
, S_IRUGO
, qla24xx_84xx_fw_version_show
,
2374 static DEVICE_ATTR(total_isp_aborts
, S_IRUGO
, qla2x00_total_isp_aborts_show
,
2376 static DEVICE_ATTR(serdes_version
, 0444, qla2x00_serdes_version_show
, NULL
);
2377 static DEVICE_ATTR(mpi_version
, S_IRUGO
, qla2x00_mpi_version_show
, NULL
);
2378 static DEVICE_ATTR(phy_version
, S_IRUGO
, qla2x00_phy_version_show
, NULL
);
2379 static DEVICE_ATTR(flash_block_size
, S_IRUGO
, qla2x00_flash_block_size_show
,
2381 static DEVICE_ATTR(vlan_id
, S_IRUGO
, qla2x00_vlan_id_show
, NULL
);
2382 static DEVICE_ATTR(vn_port_mac_address
, S_IRUGO
,
2383 qla2x00_vn_port_mac_address_show
, NULL
);
2384 static DEVICE_ATTR(fabric_param
, S_IRUGO
, qla2x00_fabric_param_show
, NULL
);
2385 static DEVICE_ATTR(fw_state
, S_IRUGO
, qla2x00_fw_state_show
, NULL
);
2386 static DEVICE_ATTR(thermal_temp
, S_IRUGO
, qla2x00_thermal_temp_show
, NULL
);
2387 static DEVICE_ATTR(diag_requests
, S_IRUGO
, qla2x00_diag_requests_show
, NULL
);
2388 static DEVICE_ATTR(diag_megabytes
, S_IRUGO
, qla2x00_diag_megabytes_show
, NULL
);
2389 static DEVICE_ATTR(fw_dump_size
, S_IRUGO
, qla2x00_fw_dump_size_show
, NULL
);
2390 static DEVICE_ATTR(allow_cna_fw_dump
, S_IRUGO
| S_IWUSR
,
2391 qla2x00_allow_cna_fw_dump_show
,
2392 qla2x00_allow_cna_fw_dump_store
);
2393 static DEVICE_ATTR(pep_version
, S_IRUGO
, qla2x00_pep_version_show
, NULL
);
2394 static DEVICE_ATTR(min_supported_speed
, 0444,
2395 qla2x00_min_supported_speed_show
, NULL
);
2396 static DEVICE_ATTR(max_supported_speed
, 0444,
2397 qla2x00_max_supported_speed_show
, NULL
);
2398 static DEVICE_ATTR(zio_threshold
, 0644,
2399 qla_zio_threshold_show
,
2400 qla_zio_threshold_store
);
2401 static DEVICE_ATTR_RW(qlini_mode
);
2402 static DEVICE_ATTR_RW(ql2xexchoffld
);
2403 static DEVICE_ATTR_RW(ql2xiniexchg
);
2404 static DEVICE_ATTR(dif_bundle_statistics
, 0444,
2405 qla2x00_dif_bundle_statistics_show
, NULL
);
2406 static DEVICE_ATTR(port_speed
, 0644, qla2x00_port_speed_show
,
2407 qla2x00_port_speed_store
);
2408 static DEVICE_ATTR(port_no
, 0444, qla2x00_port_no_show
, NULL
);
2409 static DEVICE_ATTR(fw_attr
, 0444, qla2x00_fw_attr_show
, NULL
);
2412 struct device_attribute
*qla2x00_host_attrs
[] = {
2413 &dev_attr_driver_version
,
2414 &dev_attr_fw_version
,
2415 &dev_attr_serial_num
,
2418 &dev_attr_model_name
,
2419 &dev_attr_model_desc
,
2421 &dev_attr_link_state
,
2423 &dev_attr_zio_timer
,
2425 &dev_attr_beacon_config
,
2426 &dev_attr_optrom_bios_version
,
2427 &dev_attr_optrom_efi_version
,
2428 &dev_attr_optrom_fcode_version
,
2429 &dev_attr_optrom_fw_version
,
2430 &dev_attr_84xx_fw_version
,
2431 &dev_attr_total_isp_aborts
,
2432 &dev_attr_serdes_version
,
2433 &dev_attr_mpi_version
,
2434 &dev_attr_phy_version
,
2435 &dev_attr_flash_block_size
,
2437 &dev_attr_vn_port_mac_address
,
2438 &dev_attr_fabric_param
,
2440 &dev_attr_optrom_gold_fw_version
,
2441 &dev_attr_thermal_temp
,
2442 &dev_attr_diag_requests
,
2443 &dev_attr_diag_megabytes
,
2444 &dev_attr_fw_dump_size
,
2445 &dev_attr_allow_cna_fw_dump
,
2446 &dev_attr_pep_version
,
2447 &dev_attr_min_supported_speed
,
2448 &dev_attr_max_supported_speed
,
2449 &dev_attr_zio_threshold
,
2450 &dev_attr_dif_bundle_statistics
,
2451 &dev_attr_port_speed
,
2454 &dev_attr_dport_diagnostics
,
2455 NULL
, /* reserve for qlini_mode */
2456 NULL
, /* reserve for ql2xiniexchg */
2457 NULL
, /* reserve for ql2xexchoffld */
2461 void qla_insert_tgt_attrs(void)
2463 struct device_attribute
**attr
;
2465 /* advance to empty slot */
2466 for (attr
= &qla2x00_host_attrs
[0]; *attr
; ++attr
)
2469 *attr
= &dev_attr_qlini_mode
;
2471 *attr
= &dev_attr_ql2xiniexchg
;
2473 *attr
= &dev_attr_ql2xexchoffld
;
2476 /* Host attributes. */
2479 qla2x00_get_host_port_id(struct Scsi_Host
*shost
)
2481 scsi_qla_host_t
*vha
= shost_priv(shost
);
2483 fc_host_port_id(shost
) = vha
->d_id
.b
.domain
<< 16 |
2484 vha
->d_id
.b
.area
<< 8 | vha
->d_id
.b
.al_pa
;
2488 qla2x00_get_host_speed(struct Scsi_Host
*shost
)
2490 scsi_qla_host_t
*vha
= shost_priv(shost
);
2493 if (IS_QLAFX00(vha
->hw
)) {
2494 qlafx00_get_host_speed(shost
);
2498 switch (vha
->hw
->link_data_rate
) {
2499 case PORT_SPEED_1GB
:
2500 speed
= FC_PORTSPEED_1GBIT
;
2502 case PORT_SPEED_2GB
:
2503 speed
= FC_PORTSPEED_2GBIT
;
2505 case PORT_SPEED_4GB
:
2506 speed
= FC_PORTSPEED_4GBIT
;
2508 case PORT_SPEED_8GB
:
2509 speed
= FC_PORTSPEED_8GBIT
;
2511 case PORT_SPEED_10GB
:
2512 speed
= FC_PORTSPEED_10GBIT
;
2514 case PORT_SPEED_16GB
:
2515 speed
= FC_PORTSPEED_16GBIT
;
2517 case PORT_SPEED_32GB
:
2518 speed
= FC_PORTSPEED_32GBIT
;
2520 case PORT_SPEED_64GB
:
2521 speed
= FC_PORTSPEED_64GBIT
;
2524 speed
= FC_PORTSPEED_UNKNOWN
;
2528 fc_host_speed(shost
) = speed
;
2532 qla2x00_get_host_port_type(struct Scsi_Host
*shost
)
2534 scsi_qla_host_t
*vha
= shost_priv(shost
);
2538 fc_host_port_type(shost
) = FC_PORTTYPE_NPIV
;
2541 switch (vha
->hw
->current_topology
) {
2543 port_type
= FC_PORTTYPE_LPORT
;
2546 port_type
= FC_PORTTYPE_NLPORT
;
2549 port_type
= FC_PORTTYPE_PTP
;
2552 port_type
= FC_PORTTYPE_NPORT
;
2555 port_type
= FC_PORTTYPE_UNKNOWN
;
2559 fc_host_port_type(shost
) = port_type
;
2563 qla2x00_get_starget_node_name(struct scsi_target
*starget
)
2565 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
2566 scsi_qla_host_t
*vha
= shost_priv(host
);
2570 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2571 if (fcport
->rport
&&
2572 starget
->id
== fcport
->rport
->scsi_target_id
) {
2573 node_name
= wwn_to_u64(fcport
->node_name
);
2578 fc_starget_node_name(starget
) = node_name
;
2582 qla2x00_get_starget_port_name(struct scsi_target
*starget
)
2584 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
2585 scsi_qla_host_t
*vha
= shost_priv(host
);
2589 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2590 if (fcport
->rport
&&
2591 starget
->id
== fcport
->rport
->scsi_target_id
) {
2592 port_name
= wwn_to_u64(fcport
->port_name
);
2597 fc_starget_port_name(starget
) = port_name
;
2601 qla2x00_get_starget_port_id(struct scsi_target
*starget
)
2603 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
2604 scsi_qla_host_t
*vha
= shost_priv(host
);
2606 uint32_t port_id
= ~0U;
2608 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2609 if (fcport
->rport
&&
2610 starget
->id
== fcport
->rport
->scsi_target_id
) {
2611 port_id
= fcport
->d_id
.b
.domain
<< 16 |
2612 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2617 fc_starget_port_id(starget
) = port_id
;
2621 qla2x00_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
2623 rport
->dev_loss_tmo
= timeout
? timeout
: 1;
2627 qla2x00_dev_loss_tmo_callbk(struct fc_rport
*rport
)
2629 struct Scsi_Host
*host
= rport_to_shost(rport
);
2630 fc_port_t
*fcport
= *(fc_port_t
**)rport
->dd_data
;
2631 unsigned long flags
;
2636 /* Now that the rport has been deleted, set the fcport state to
2638 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_DEAD
);
2641 * Transport has effectively 'deleted' the rport, clear
2642 * all local references.
2644 spin_lock_irqsave(host
->host_lock
, flags
);
2645 fcport
->rport
= fcport
->drport
= NULL
;
2646 *((fc_port_t
**)rport
->dd_data
) = NULL
;
2647 spin_unlock_irqrestore(host
->host_lock
, flags
);
2649 if (test_bit(ABORT_ISP_ACTIVE
, &fcport
->vha
->dpc_flags
))
2652 if (unlikely(pci_channel_offline(fcport
->vha
->hw
->pdev
))) {
2653 qla2x00_abort_all_cmds(fcport
->vha
, DID_NO_CONNECT
<< 16);
2659 qla2x00_terminate_rport_io(struct fc_rport
*rport
)
2661 fc_port_t
*fcport
= *(fc_port_t
**)rport
->dd_data
;
2666 if (test_bit(UNLOADING
, &fcport
->vha
->dpc_flags
))
2669 if (test_bit(ABORT_ISP_ACTIVE
, &fcport
->vha
->dpc_flags
))
2672 if (unlikely(pci_channel_offline(fcport
->vha
->hw
->pdev
))) {
2673 qla2x00_abort_all_cmds(fcport
->vha
, DID_NO_CONNECT
<< 16);
2677 * At this point all fcport's software-states are cleared. Perform any
2678 * final cleanup of firmware resources (PCBs and XCBs).
2680 if (fcport
->loop_id
!= FC_NO_LOOP_ID
) {
2681 if (IS_FWI2_CAPABLE(fcport
->vha
->hw
))
2682 fcport
->vha
->hw
->isp_ops
->fabric_logout(fcport
->vha
,
2683 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
2684 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
2686 qla2x00_port_logout(fcport
->vha
, fcport
);
2691 qla2x00_issue_lip(struct Scsi_Host
*shost
)
2693 scsi_qla_host_t
*vha
= shost_priv(shost
);
2695 if (IS_QLAFX00(vha
->hw
))
2698 qla2x00_loop_reset(vha
);
2702 static struct fc_host_statistics
*
2703 qla2x00_get_fc_host_stats(struct Scsi_Host
*shost
)
2705 scsi_qla_host_t
*vha
= shost_priv(shost
);
2706 struct qla_hw_data
*ha
= vha
->hw
;
2707 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2709 struct link_statistics
*stats
;
2710 dma_addr_t stats_dma
;
2711 struct fc_host_statistics
*p
= &vha
->fc_host_stat
;
2713 memset(p
, -1, sizeof(*p
));
2715 if (IS_QLAFX00(vha
->hw
))
2718 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
2721 if (unlikely(pci_channel_offline(ha
->pdev
)))
2724 if (qla2x00_chip_is_down(vha
))
2727 stats
= dma_alloc_coherent(&ha
->pdev
->dev
, sizeof(*stats
), &stats_dma
,
2730 ql_log(ql_log_warn
, vha
, 0x707d,
2731 "Failed to allocate memory for stats.\n");
2735 rval
= QLA_FUNCTION_FAILED
;
2736 if (IS_FWI2_CAPABLE(ha
)) {
2737 rval
= qla24xx_get_isp_stats(base_vha
, stats
, stats_dma
, 0);
2738 } else if (atomic_read(&base_vha
->loop_state
) == LOOP_READY
&&
2740 /* Must be in a 'READY' state for statistics retrieval. */
2741 rval
= qla2x00_get_link_status(base_vha
, base_vha
->loop_id
,
2745 if (rval
!= QLA_SUCCESS
)
2748 p
->link_failure_count
= le32_to_cpu(stats
->link_fail_cnt
);
2749 p
->loss_of_sync_count
= le32_to_cpu(stats
->loss_sync_cnt
);
2750 p
->loss_of_signal_count
= le32_to_cpu(stats
->loss_sig_cnt
);
2751 p
->prim_seq_protocol_err_count
= le32_to_cpu(stats
->prim_seq_err_cnt
);
2752 p
->invalid_tx_word_count
= le32_to_cpu(stats
->inval_xmit_word_cnt
);
2753 p
->invalid_crc_count
= le32_to_cpu(stats
->inval_crc_cnt
);
2754 if (IS_FWI2_CAPABLE(ha
)) {
2755 p
->lip_count
= le32_to_cpu(stats
->lip_cnt
);
2756 p
->tx_frames
= le32_to_cpu(stats
->tx_frames
);
2757 p
->rx_frames
= le32_to_cpu(stats
->rx_frames
);
2758 p
->dumped_frames
= le32_to_cpu(stats
->discarded_frames
);
2759 p
->nos_count
= le32_to_cpu(stats
->nos_rcvd
);
2761 le32_to_cpu(stats
->dropped_frames
) +
2762 le32_to_cpu(stats
->discarded_frames
);
2763 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
)) {
2764 p
->rx_words
= le64_to_cpu(stats
->fpm_recv_word_cnt
);
2765 p
->tx_words
= le64_to_cpu(stats
->fpm_xmit_word_cnt
);
2767 p
->rx_words
= vha
->qla_stats
.input_bytes
;
2768 p
->tx_words
= vha
->qla_stats
.output_bytes
;
2771 p
->fcp_control_requests
= vha
->qla_stats
.control_requests
;
2772 p
->fcp_input_requests
= vha
->qla_stats
.input_requests
;
2773 p
->fcp_output_requests
= vha
->qla_stats
.output_requests
;
2774 p
->fcp_input_megabytes
= vha
->qla_stats
.input_bytes
>> 20;
2775 p
->fcp_output_megabytes
= vha
->qla_stats
.output_bytes
>> 20;
2776 p
->seconds_since_last_reset
=
2777 get_jiffies_64() - vha
->qla_stats
.jiffies_at_last_reset
;
2778 do_div(p
->seconds_since_last_reset
, HZ
);
2781 dma_free_coherent(&ha
->pdev
->dev
, sizeof(struct link_statistics
),
2788 qla2x00_reset_host_stats(struct Scsi_Host
*shost
)
2790 scsi_qla_host_t
*vha
= shost_priv(shost
);
2791 struct qla_hw_data
*ha
= vha
->hw
;
2792 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2793 struct link_statistics
*stats
;
2794 dma_addr_t stats_dma
;
2796 memset(&vha
->qla_stats
, 0, sizeof(vha
->qla_stats
));
2797 memset(&vha
->fc_host_stat
, 0, sizeof(vha
->fc_host_stat
));
2799 vha
->qla_stats
.jiffies_at_last_reset
= get_jiffies_64();
2801 if (IS_FWI2_CAPABLE(ha
)) {
2802 stats
= dma_alloc_coherent(&ha
->pdev
->dev
,
2803 sizeof(*stats
), &stats_dma
, GFP_KERNEL
);
2805 ql_log(ql_log_warn
, vha
, 0x70d7,
2806 "Failed to allocate memory for stats.\n");
2810 /* reset firmware statistics */
2811 qla24xx_get_isp_stats(base_vha
, stats
, stats_dma
, BIT_0
);
2813 dma_free_coherent(&ha
->pdev
->dev
, sizeof(*stats
),
2819 qla2x00_get_host_symbolic_name(struct Scsi_Host
*shost
)
2821 scsi_qla_host_t
*vha
= shost_priv(shost
);
2823 qla2x00_get_sym_node_name(vha
, fc_host_symbolic_name(shost
),
2824 sizeof(fc_host_symbolic_name(shost
)));
2828 qla2x00_set_host_system_hostname(struct Scsi_Host
*shost
)
2830 scsi_qla_host_t
*vha
= shost_priv(shost
);
2832 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
2836 qla2x00_get_host_fabric_name(struct Scsi_Host
*shost
)
2838 scsi_qla_host_t
*vha
= shost_priv(shost
);
2839 static const uint8_t node_name
[WWN_SIZE
] = {
2840 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
2842 u64 fabric_name
= wwn_to_u64(node_name
);
2844 if (vha
->device_flags
& SWITCH_FOUND
)
2845 fabric_name
= wwn_to_u64(vha
->fabric_node_name
);
2847 fc_host_fabric_name(shost
) = fabric_name
;
2851 qla2x00_get_host_port_state(struct Scsi_Host
*shost
)
2853 scsi_qla_host_t
*vha
= shost_priv(shost
);
2854 struct scsi_qla_host
*base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
2856 if (!base_vha
->flags
.online
) {
2857 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
2861 switch (atomic_read(&base_vha
->loop_state
)) {
2863 fc_host_port_state(shost
) = FC_PORTSTATE_DIAGNOSTICS
;
2866 if (test_bit(LOOP_RESYNC_NEEDED
, &base_vha
->dpc_flags
))
2867 fc_host_port_state(shost
) = FC_PORTSTATE_DIAGNOSTICS
;
2869 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
2872 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
2875 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
2878 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
2884 qla24xx_vport_create(struct fc_vport
*fc_vport
, bool disable
)
2888 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
2889 scsi_qla_host_t
*vha
= NULL
;
2890 struct qla_hw_data
*ha
= base_vha
->hw
;
2892 struct req_que
*req
= ha
->req_q_map
[0];
2893 struct qla_qpair
*qpair
;
2895 ret
= qla24xx_vport_create_req_sanity_check(fc_vport
);
2897 ql_log(ql_log_warn
, vha
, 0x707e,
2898 "Vport sanity check failed, status %x\n", ret
);
2902 vha
= qla24xx_create_vhost(fc_vport
);
2904 ql_log(ql_log_warn
, vha
, 0x707f, "Vport create host failed.\n");
2905 return FC_VPORT_FAILED
;
2908 atomic_set(&vha
->vp_state
, VP_OFFLINE
);
2909 fc_vport_set_state(fc_vport
, FC_VPORT_DISABLED
);
2911 atomic_set(&vha
->vp_state
, VP_FAILED
);
2913 /* ready to create vport */
2914 ql_log(ql_log_info
, vha
, 0x7080,
2915 "VP entry id %d assigned.\n", vha
->vp_idx
);
2917 /* initialized vport states */
2918 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
2919 vha
->vp_err_state
= VP_ERR_PORTDWN
;
2920 vha
->vp_prev_err_state
= VP_ERR_UNKWN
;
2921 /* Check if physical ha port is Up */
2922 if (atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
||
2923 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
2924 /* Don't retry or attempt login of this virtual port */
2925 ql_dbg(ql_dbg_user
, vha
, 0x7081,
2926 "Vport loop state is not UP.\n");
2927 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
2929 fc_vport_set_state(fc_vport
, FC_VPORT_LINKDOWN
);
2932 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
2933 if (ha
->fw_attributes
& BIT_4
) {
2934 int prot
= 0, guard
;
2936 vha
->flags
.difdix_supported
= 1;
2937 ql_dbg(ql_dbg_user
, vha
, 0x7082,
2938 "Registered for DIF/DIX type 1 and 3 protection.\n");
2939 if (ql2xenabledif
== 1)
2940 prot
= SHOST_DIX_TYPE0_PROTECTION
;
2941 scsi_host_set_prot(vha
->host
,
2942 prot
| SHOST_DIF_TYPE1_PROTECTION
2943 | SHOST_DIF_TYPE2_PROTECTION
2944 | SHOST_DIF_TYPE3_PROTECTION
2945 | SHOST_DIX_TYPE1_PROTECTION
2946 | SHOST_DIX_TYPE2_PROTECTION
2947 | SHOST_DIX_TYPE3_PROTECTION
);
2949 guard
= SHOST_DIX_GUARD_CRC
;
2951 if (IS_PI_IPGUARD_CAPABLE(ha
) &&
2952 (ql2xenabledif
> 1 || IS_PI_DIFB_DIX0_CAPABLE(ha
)))
2953 guard
|= SHOST_DIX_GUARD_IP
;
2955 scsi_host_set_guard(vha
->host
, guard
);
2957 vha
->flags
.difdix_supported
= 0;
2960 if (scsi_add_host_with_dma(vha
->host
, &fc_vport
->dev
,
2962 ql_dbg(ql_dbg_user
, vha
, 0x7083,
2963 "scsi_add_host failure for VP[%d].\n", vha
->vp_idx
);
2964 goto vport_create_failed_2
;
2967 /* initialize attributes */
2968 fc_host_dev_loss_tmo(vha
->host
) = ha
->port_down_retry_count
;
2969 fc_host_node_name(vha
->host
) = wwn_to_u64(vha
->node_name
);
2970 fc_host_port_name(vha
->host
) = wwn_to_u64(vha
->port_name
);
2971 fc_host_supported_classes(vha
->host
) =
2972 fc_host_supported_classes(base_vha
->host
);
2973 fc_host_supported_speeds(vha
->host
) =
2974 fc_host_supported_speeds(base_vha
->host
);
2976 qlt_vport_create(vha
, ha
);
2977 qla24xx_vport_disable(fc_vport
, disable
);
2979 if (!ql2xmqsupport
|| !ha
->npiv_info
)
2982 /* Create a request queue in QoS mode for the vport */
2983 for (cnt
= 0; cnt
< ha
->nvram_npiv_size
; cnt
++) {
2984 if (memcmp(ha
->npiv_info
[cnt
].port_name
, vha
->port_name
, 8) == 0
2985 && memcmp(ha
->npiv_info
[cnt
].node_name
, vha
->node_name
,
2987 qos
= ha
->npiv_info
[cnt
].q_qos
;
2993 qpair
= qla2xxx_create_qpair(vha
, qos
, vha
->vp_idx
, true);
2995 ql_log(ql_log_warn
, vha
, 0x7084,
2996 "Can't create qpair for VP[%d]\n",
2999 ql_dbg(ql_dbg_multiq
, vha
, 0xc001,
3000 "Queue pair: %d Qos: %d) created for VP[%d]\n",
3001 qpair
->id
, qos
, vha
->vp_idx
);
3002 ql_dbg(ql_dbg_user
, vha
, 0x7085,
3003 "Queue Pair: %d Qos: %d) created for VP[%d]\n",
3004 qpair
->id
, qos
, vha
->vp_idx
);
3014 vport_create_failed_2
:
3015 qla24xx_disable_vp(vha
);
3016 qla24xx_deallocate_vp_id(vha
);
3017 scsi_host_put(vha
->host
);
3018 return FC_VPORT_FAILED
;
3022 qla24xx_vport_delete(struct fc_vport
*fc_vport
)
3024 scsi_qla_host_t
*vha
= fc_vport
->dd_data
;
3025 struct qla_hw_data
*ha
= vha
->hw
;
3026 uint16_t id
= vha
->vp_idx
;
3028 set_bit(VPORT_DELETE
, &vha
->dpc_flags
);
3030 while (test_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
) ||
3031 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
))
3034 qla_nvme_delete(vha
);
3036 qla24xx_disable_vp(vha
);
3037 qla2x00_wait_for_sess_deletion(vha
);
3039 vha
->flags
.delete_progress
= 1;
3041 qlt_remove_target(ha
, vha
);
3043 fc_remove_host(vha
->host
);
3045 scsi_remove_host(vha
->host
);
3047 /* Allow timer to run to drain queued items, when removing vp */
3048 qla24xx_deallocate_vp_id(vha
);
3050 if (vha
->timer_active
) {
3051 qla2x00_vp_stop_timer(vha
);
3052 ql_dbg(ql_dbg_user
, vha
, 0x7086,
3053 "Timer for the VP[%d] has stopped\n", vha
->vp_idx
);
3056 qla2x00_free_fcports(vha
);
3058 mutex_lock(&ha
->vport_lock
);
3059 ha
->cur_vport_count
--;
3060 clear_bit(vha
->vp_idx
, ha
->vp_idx_map
);
3061 mutex_unlock(&ha
->vport_lock
);
3063 dma_free_coherent(&ha
->pdev
->dev
, vha
->gnl
.size
, vha
->gnl
.l
,
3070 if (vha
->qpair
&& vha
->qpair
->vp_idx
== vha
->vp_idx
) {
3071 if (qla2xxx_delete_qpair(vha
, vha
->qpair
) != QLA_SUCCESS
)
3072 ql_log(ql_log_warn
, vha
, 0x7087,
3073 "Queue Pair delete failed.\n");
3076 ql_log(ql_log_info
, vha
, 0x7088, "VP[%d] deleted.\n", id
);
3077 scsi_host_put(vha
->host
);
3082 qla24xx_vport_disable(struct fc_vport
*fc_vport
, bool disable
)
3084 scsi_qla_host_t
*vha
= fc_vport
->dd_data
;
3087 qla24xx_disable_vp(vha
);
3089 qla24xx_enable_vp(vha
);
3094 struct fc_function_template qla2xxx_transport_functions
= {
3096 .show_host_node_name
= 1,
3097 .show_host_port_name
= 1,
3098 .show_host_supported_classes
= 1,
3099 .show_host_supported_speeds
= 1,
3101 .get_host_port_id
= qla2x00_get_host_port_id
,
3102 .show_host_port_id
= 1,
3103 .get_host_speed
= qla2x00_get_host_speed
,
3104 .show_host_speed
= 1,
3105 .get_host_port_type
= qla2x00_get_host_port_type
,
3106 .show_host_port_type
= 1,
3107 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
3108 .show_host_symbolic_name
= 1,
3109 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
3110 .show_host_system_hostname
= 1,
3111 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
3112 .show_host_fabric_name
= 1,
3113 .get_host_port_state
= qla2x00_get_host_port_state
,
3114 .show_host_port_state
= 1,
3116 .dd_fcrport_size
= sizeof(struct fc_port
*),
3117 .show_rport_supported_classes
= 1,
3119 .get_starget_node_name
= qla2x00_get_starget_node_name
,
3120 .show_starget_node_name
= 1,
3121 .get_starget_port_name
= qla2x00_get_starget_port_name
,
3122 .show_starget_port_name
= 1,
3123 .get_starget_port_id
= qla2x00_get_starget_port_id
,
3124 .show_starget_port_id
= 1,
3126 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
3127 .show_rport_dev_loss_tmo
= 1,
3129 .issue_fc_host_lip
= qla2x00_issue_lip
,
3130 .dev_loss_tmo_callbk
= qla2x00_dev_loss_tmo_callbk
,
3131 .terminate_rport_io
= qla2x00_terminate_rport_io
,
3132 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
3133 .reset_fc_host_stats
= qla2x00_reset_host_stats
,
3135 .vport_create
= qla24xx_vport_create
,
3136 .vport_disable
= qla24xx_vport_disable
,
3137 .vport_delete
= qla24xx_vport_delete
,
3138 .bsg_request
= qla24xx_bsg_request
,
3139 .bsg_timeout
= qla24xx_bsg_timeout
,
3142 struct fc_function_template qla2xxx_transport_vport_functions
= {
3144 .show_host_node_name
= 1,
3145 .show_host_port_name
= 1,
3146 .show_host_supported_classes
= 1,
3148 .get_host_port_id
= qla2x00_get_host_port_id
,
3149 .show_host_port_id
= 1,
3150 .get_host_speed
= qla2x00_get_host_speed
,
3151 .show_host_speed
= 1,
3152 .get_host_port_type
= qla2x00_get_host_port_type
,
3153 .show_host_port_type
= 1,
3154 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
3155 .show_host_symbolic_name
= 1,
3156 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
3157 .show_host_system_hostname
= 1,
3158 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
3159 .show_host_fabric_name
= 1,
3160 .get_host_port_state
= qla2x00_get_host_port_state
,
3161 .show_host_port_state
= 1,
3163 .dd_fcrport_size
= sizeof(struct fc_port
*),
3164 .show_rport_supported_classes
= 1,
3166 .get_starget_node_name
= qla2x00_get_starget_node_name
,
3167 .show_starget_node_name
= 1,
3168 .get_starget_port_name
= qla2x00_get_starget_port_name
,
3169 .show_starget_port_name
= 1,
3170 .get_starget_port_id
= qla2x00_get_starget_port_id
,
3171 .show_starget_port_id
= 1,
3173 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
3174 .show_rport_dev_loss_tmo
= 1,
3176 .issue_fc_host_lip
= qla2x00_issue_lip
,
3177 .dev_loss_tmo_callbk
= qla2x00_dev_loss_tmo_callbk
,
3178 .terminate_rport_io
= qla2x00_terminate_rport_io
,
3179 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
3180 .reset_fc_host_stats
= qla2x00_reset_host_stats
,
3182 .bsg_request
= qla24xx_bsg_request
,
3183 .bsg_timeout
= qla24xx_bsg_timeout
,
3187 qla2x00_init_host_attr(scsi_qla_host_t
*vha
)
3189 struct qla_hw_data
*ha
= vha
->hw
;
3190 u32 speeds
= FC_PORTSPEED_UNKNOWN
;
3192 fc_host_dev_loss_tmo(vha
->host
) = ha
->port_down_retry_count
;
3193 fc_host_node_name(vha
->host
) = wwn_to_u64(vha
->node_name
);
3194 fc_host_port_name(vha
->host
) = wwn_to_u64(vha
->port_name
);
3195 fc_host_supported_classes(vha
->host
) = ha
->base_qpair
->enable_class_2
?
3196 (FC_COS_CLASS2
|FC_COS_CLASS3
) : FC_COS_CLASS3
;
3197 fc_host_max_npiv_vports(vha
->host
) = ha
->max_npiv_vports
;
3198 fc_host_npiv_vports_inuse(vha
->host
) = ha
->cur_vport_count
;
3200 if (IS_CNA_CAPABLE(ha
))
3201 speeds
= FC_PORTSPEED_10GBIT
;
3202 else if (IS_QLA28XX(ha
) || IS_QLA27XX(ha
)) {
3203 if (ha
->max_supported_speed
== 2) {
3204 if (ha
->min_supported_speed
<= 6)
3205 speeds
|= FC_PORTSPEED_64GBIT
;
3207 if (ha
->max_supported_speed
== 2 ||
3208 ha
->max_supported_speed
== 1) {
3209 if (ha
->min_supported_speed
<= 5)
3210 speeds
|= FC_PORTSPEED_32GBIT
;
3212 if (ha
->max_supported_speed
== 2 ||
3213 ha
->max_supported_speed
== 1 ||
3214 ha
->max_supported_speed
== 0) {
3215 if (ha
->min_supported_speed
<= 4)
3216 speeds
|= FC_PORTSPEED_16GBIT
;
3218 if (ha
->max_supported_speed
== 1 ||
3219 ha
->max_supported_speed
== 0) {
3220 if (ha
->min_supported_speed
<= 3)
3221 speeds
|= FC_PORTSPEED_8GBIT
;
3223 if (ha
->max_supported_speed
== 0) {
3224 if (ha
->min_supported_speed
<= 2)
3225 speeds
|= FC_PORTSPEED_4GBIT
;
3227 } else if (IS_QLA2031(ha
))
3228 speeds
= FC_PORTSPEED_16GBIT
|FC_PORTSPEED_8GBIT
|
3230 else if (IS_QLA25XX(ha
) || IS_QLAFX00(ha
))
3231 speeds
= FC_PORTSPEED_8GBIT
|FC_PORTSPEED_4GBIT
|
3232 FC_PORTSPEED_2GBIT
|FC_PORTSPEED_1GBIT
;
3233 else if (IS_QLA24XX_TYPE(ha
))
3234 speeds
= FC_PORTSPEED_4GBIT
|FC_PORTSPEED_2GBIT
|
3236 else if (IS_QLA23XX(ha
))
3237 speeds
= FC_PORTSPEED_2GBIT
|FC_PORTSPEED_1GBIT
;
3239 speeds
= FC_PORTSPEED_1GBIT
;
3241 fc_host_supported_speeds(vha
->host
) = speeds
;