2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/kthread.h>
10 #include <linux/vmalloc.h>
11 #include <linux/slab.h>
12 #include <linux/delay.h>
14 static int qla24xx_vport_disable(struct fc_vport
*, bool);
16 /* SYSFS attributes --------------------------------------------------------- */
19 qla2x00_sysfs_read_fw_dump(struct file
*filp
, struct kobject
*kobj
,
20 struct bin_attribute
*bin_attr
,
21 char *buf
, loff_t off
, size_t count
)
23 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
24 struct device
, kobj
)));
25 struct qla_hw_data
*ha
= vha
->hw
;
28 if (ha
->fw_dump_reading
== 0)
32 if (off
< ha
->md_template_size
) {
33 rval
= memory_read_from_buffer(buf
, count
,
34 &off
, ha
->md_tmplt_hdr
, ha
->md_template_size
);
37 off
-= ha
->md_template_size
;
38 rval
= memory_read_from_buffer(buf
, count
,
39 &off
, ha
->md_dump
, ha
->md_dump_size
);
42 return memory_read_from_buffer(buf
, count
, &off
, ha
->fw_dump
,
47 qla2x00_sysfs_write_fw_dump(struct file
*filp
, struct kobject
*kobj
,
48 struct bin_attribute
*bin_attr
,
49 char *buf
, loff_t off
, size_t count
)
51 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
52 struct device
, kobj
)));
53 struct qla_hw_data
*ha
= vha
->hw
;
59 reading
= simple_strtol(buf
, NULL
, 10);
62 if (!ha
->fw_dump_reading
)
65 ql_log(ql_log_info
, vha
, 0x705d,
66 "Firmware dump cleared on (%ld).\n", vha
->host_no
);
68 if (IS_QLA82XX(vha
->hw
)) {
72 ha
->fw_dump_reading
= 0;
76 if (ha
->fw_dumped
&& !ha
->fw_dump_reading
) {
77 ha
->fw_dump_reading
= 1;
79 ql_log(ql_log_info
, vha
, 0x705e,
80 "Raw firmware dump ready for read on (%ld).\n",
85 qla2x00_alloc_fw_dump(vha
);
90 qla82xx_set_reset_owner(vha
);
91 qla82xx_idc_unlock(ha
);
93 qla2x00_system_error(vha
);
98 ql_dbg(ql_dbg_user
, vha
, 0x705b,
99 "MiniDump supported with this firmware.\n");
101 ql_dbg(ql_dbg_user
, vha
, 0x709d,
102 "MiniDump not supported with this firmware.\n");
107 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
113 static struct bin_attribute sysfs_fw_dump_attr
= {
116 .mode
= S_IRUSR
| S_IWUSR
,
119 .read
= qla2x00_sysfs_read_fw_dump
,
120 .write
= qla2x00_sysfs_write_fw_dump
,
124 qla2x00_sysfs_read_nvram(struct file
*filp
, struct kobject
*kobj
,
125 struct bin_attribute
*bin_attr
,
126 char *buf
, loff_t off
, size_t count
)
128 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
129 struct device
, kobj
)));
130 struct qla_hw_data
*ha
= vha
->hw
;
132 if (!capable(CAP_SYS_ADMIN
))
135 if (IS_NOCACHE_VPD_TYPE(ha
))
136 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
138 return memory_read_from_buffer(buf
, count
, &off
, ha
->nvram
,
143 qla2x00_sysfs_write_nvram(struct file
*filp
, struct kobject
*kobj
,
144 struct bin_attribute
*bin_attr
,
145 char *buf
, loff_t off
, size_t count
)
147 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
148 struct device
, kobj
)));
149 struct qla_hw_data
*ha
= vha
->hw
;
152 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->nvram_size
||
153 !ha
->isp_ops
->write_nvram
)
156 /* Checksum NVRAM. */
157 if (IS_FWI2_CAPABLE(ha
)) {
161 iter
= (uint32_t *)buf
;
163 for (cnt
= 0; cnt
< ((count
>> 2) - 1); cnt
++)
164 chksum
+= le32_to_cpu(*iter
++);
165 chksum
= ~chksum
+ 1;
166 *iter
= cpu_to_le32(chksum
);
171 iter
= (uint8_t *)buf
;
173 for (cnt
= 0; cnt
< count
- 1; cnt
++)
175 chksum
= ~chksum
+ 1;
179 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
180 ql_log(ql_log_warn
, vha
, 0x705f,
181 "HBA not online, failing NVRAM update.\n");
186 ha
->isp_ops
->write_nvram(vha
, (uint8_t *)buf
, ha
->nvram_base
, count
);
187 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->nvram
, ha
->nvram_base
,
190 ql_dbg(ql_dbg_user
, vha
, 0x7060,
191 "Setting ISP_ABORT_NEEDED\n");
192 /* NVRAM settings take effect immediately. */
193 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
194 qla2xxx_wake_dpc(vha
);
195 qla2x00_wait_for_chip_reset(vha
);
200 static struct bin_attribute sysfs_nvram_attr
= {
203 .mode
= S_IRUSR
| S_IWUSR
,
206 .read
= qla2x00_sysfs_read_nvram
,
207 .write
= qla2x00_sysfs_write_nvram
,
211 qla2x00_sysfs_read_optrom(struct file
*filp
, struct kobject
*kobj
,
212 struct bin_attribute
*bin_attr
,
213 char *buf
, loff_t off
, size_t count
)
215 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
216 struct device
, kobj
)));
217 struct qla_hw_data
*ha
= vha
->hw
;
219 if (ha
->optrom_state
!= QLA_SREADING
)
222 return memory_read_from_buffer(buf
, count
, &off
, ha
->optrom_buffer
,
223 ha
->optrom_region_size
);
227 qla2x00_sysfs_write_optrom(struct file
*filp
, struct kobject
*kobj
,
228 struct bin_attribute
*bin_attr
,
229 char *buf
, loff_t off
, size_t count
)
231 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
232 struct device
, kobj
)));
233 struct qla_hw_data
*ha
= vha
->hw
;
235 if (ha
->optrom_state
!= QLA_SWRITING
)
237 if (off
> ha
->optrom_region_size
)
239 if (off
+ count
> ha
->optrom_region_size
)
240 count
= ha
->optrom_region_size
- off
;
242 memcpy(&ha
->optrom_buffer
[off
], buf
, count
);
247 static struct bin_attribute sysfs_optrom_attr
= {
250 .mode
= S_IRUSR
| S_IWUSR
,
253 .read
= qla2x00_sysfs_read_optrom
,
254 .write
= qla2x00_sysfs_write_optrom
,
258 qla2x00_sysfs_write_optrom_ctl(struct file
*filp
, struct kobject
*kobj
,
259 struct bin_attribute
*bin_attr
,
260 char *buf
, loff_t off
, size_t count
)
262 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
263 struct device
, kobj
)));
264 struct qla_hw_data
*ha
= vha
->hw
;
267 uint32_t size
= ha
->optrom_size
;
273 if (unlikely(pci_channel_offline(ha
->pdev
)))
276 if (sscanf(buf
, "%d:%x:%x", &val
, &start
, &size
) < 1)
278 if (start
> ha
->optrom_size
)
283 if (ha
->optrom_state
!= QLA_SREADING
&&
284 ha
->optrom_state
!= QLA_SWRITING
)
287 ha
->optrom_state
= QLA_SWAITING
;
289 ql_dbg(ql_dbg_user
, vha
, 0x7061,
290 "Freeing flash region allocation -- 0x%x bytes.\n",
291 ha
->optrom_region_size
);
293 vfree(ha
->optrom_buffer
);
294 ha
->optrom_buffer
= NULL
;
297 if (ha
->optrom_state
!= QLA_SWAITING
)
300 ha
->optrom_region_start
= start
;
301 ha
->optrom_region_size
= start
+ size
> ha
->optrom_size
?
302 ha
->optrom_size
- start
: size
;
304 ha
->optrom_state
= QLA_SREADING
;
305 ha
->optrom_buffer
= vmalloc(ha
->optrom_region_size
);
306 if (ha
->optrom_buffer
== NULL
) {
307 ql_log(ql_log_warn
, vha
, 0x7062,
308 "Unable to allocate memory for optrom retrieval "
309 "(%x).\n", ha
->optrom_region_size
);
311 ha
->optrom_state
= QLA_SWAITING
;
315 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
316 ql_log(ql_log_warn
, vha
, 0x7063,
317 "HBA not online, failing NVRAM update.\n");
321 ql_dbg(ql_dbg_user
, vha
, 0x7064,
322 "Reading flash region -- 0x%x/0x%x.\n",
323 ha
->optrom_region_start
, ha
->optrom_region_size
);
325 memset(ha
->optrom_buffer
, 0, ha
->optrom_region_size
);
326 ha
->isp_ops
->read_optrom(vha
, ha
->optrom_buffer
,
327 ha
->optrom_region_start
, ha
->optrom_region_size
);
330 if (ha
->optrom_state
!= QLA_SWAITING
)
334 * We need to be more restrictive on which FLASH regions are
335 * allowed to be updated via user-space. Regions accessible
336 * via this method include:
338 * ISP21xx/ISP22xx/ISP23xx type boards:
340 * 0x000000 -> 0x020000 -- Boot code.
342 * ISP2322/ISP24xx type boards:
344 * 0x000000 -> 0x07ffff -- Boot code.
345 * 0x080000 -> 0x0fffff -- Firmware.
347 * ISP25xx type boards:
349 * 0x000000 -> 0x07ffff -- Boot code.
350 * 0x080000 -> 0x0fffff -- Firmware.
351 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
354 if (ha
->optrom_size
== OPTROM_SIZE_2300
&& start
== 0)
356 else if (start
== (ha
->flt_region_boot
* 4) ||
357 start
== (ha
->flt_region_fw
* 4))
359 else if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
)
360 || IS_CNA_CAPABLE(ha
) || IS_QLA2031(ha
))
363 ql_log(ql_log_warn
, vha
, 0x7065,
364 "Invalid start region 0x%x/0x%x.\n", start
, size
);
368 ha
->optrom_region_start
= start
;
369 ha
->optrom_region_size
= start
+ size
> ha
->optrom_size
?
370 ha
->optrom_size
- start
: size
;
372 ha
->optrom_state
= QLA_SWRITING
;
373 ha
->optrom_buffer
= vmalloc(ha
->optrom_region_size
);
374 if (ha
->optrom_buffer
== NULL
) {
375 ql_log(ql_log_warn
, vha
, 0x7066,
376 "Unable to allocate memory for optrom update "
377 "(%x)\n", ha
->optrom_region_size
);
379 ha
->optrom_state
= QLA_SWAITING
;
383 ql_dbg(ql_dbg_user
, vha
, 0x7067,
384 "Staging flash region write -- 0x%x/0x%x.\n",
385 ha
->optrom_region_start
, ha
->optrom_region_size
);
387 memset(ha
->optrom_buffer
, 0, ha
->optrom_region_size
);
390 if (ha
->optrom_state
!= QLA_SWRITING
)
393 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
394 ql_log(ql_log_warn
, vha
, 0x7068,
395 "HBA not online, failing flash update.\n");
399 ql_dbg(ql_dbg_user
, vha
, 0x7069,
400 "Writing flash region -- 0x%x/0x%x.\n",
401 ha
->optrom_region_start
, ha
->optrom_region_size
);
403 ha
->isp_ops
->write_optrom(vha
, ha
->optrom_buffer
,
404 ha
->optrom_region_start
, ha
->optrom_region_size
);
412 static struct bin_attribute sysfs_optrom_ctl_attr
= {
414 .name
= "optrom_ctl",
418 .write
= qla2x00_sysfs_write_optrom_ctl
,
422 qla2x00_sysfs_read_vpd(struct file
*filp
, struct kobject
*kobj
,
423 struct bin_attribute
*bin_attr
,
424 char *buf
, loff_t off
, size_t count
)
426 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
427 struct device
, kobj
)));
428 struct qla_hw_data
*ha
= vha
->hw
;
430 if (unlikely(pci_channel_offline(ha
->pdev
)))
433 if (!capable(CAP_SYS_ADMIN
))
436 if (IS_NOCACHE_VPD_TYPE(ha
))
437 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
439 return memory_read_from_buffer(buf
, count
, &off
, ha
->vpd
, ha
->vpd_size
);
443 qla2x00_sysfs_write_vpd(struct file
*filp
, struct kobject
*kobj
,
444 struct bin_attribute
*bin_attr
,
445 char *buf
, loff_t off
, size_t count
)
447 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
448 struct device
, kobj
)));
449 struct qla_hw_data
*ha
= vha
->hw
;
452 if (unlikely(pci_channel_offline(ha
->pdev
)))
455 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->vpd_size
||
456 !ha
->isp_ops
->write_nvram
)
459 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
460 ql_log(ql_log_warn
, vha
, 0x706a,
461 "HBA not online, failing VPD update.\n");
466 ha
->isp_ops
->write_nvram(vha
, (uint8_t *)buf
, ha
->vpd_base
, count
);
467 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
, ha
->vpd_base
, count
);
469 /* Update flash version information for 4Gb & above. */
470 if (!IS_FWI2_CAPABLE(ha
))
473 tmp_data
= vmalloc(256);
475 ql_log(ql_log_warn
, vha
, 0x706b,
476 "Unable to allocate memory for VPD information update.\n");
479 ha
->isp_ops
->get_flash_version(vha
, tmp_data
);
485 static struct bin_attribute sysfs_vpd_attr
= {
488 .mode
= S_IRUSR
| S_IWUSR
,
491 .read
= qla2x00_sysfs_read_vpd
,
492 .write
= qla2x00_sysfs_write_vpd
,
496 qla2x00_sysfs_read_sfp(struct file
*filp
, struct kobject
*kobj
,
497 struct bin_attribute
*bin_attr
,
498 char *buf
, loff_t off
, size_t count
)
500 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
501 struct device
, kobj
)));
502 struct qla_hw_data
*ha
= vha
->hw
;
503 uint16_t iter
, addr
, offset
;
506 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= SFP_DEV_SIZE
* 2)
512 ha
->sfp_data
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
515 ql_log(ql_log_warn
, vha
, 0x706c,
516 "Unable to allocate memory for SFP read-data.\n");
521 memset(ha
->sfp_data
, 0, SFP_BLOCK_SIZE
);
523 for (iter
= 0, offset
= 0; iter
< (SFP_DEV_SIZE
* 2) / SFP_BLOCK_SIZE
;
524 iter
++, offset
+= SFP_BLOCK_SIZE
) {
526 /* Skip to next device address. */
531 rval
= qla2x00_read_sfp(vha
, ha
->sfp_data_dma
, ha
->sfp_data
,
532 addr
, offset
, SFP_BLOCK_SIZE
, 0);
533 if (rval
!= QLA_SUCCESS
) {
534 ql_log(ql_log_warn
, vha
, 0x706d,
535 "Unable to read SFP data (%x/%x/%x).\n", rval
,
540 memcpy(buf
, ha
->sfp_data
, SFP_BLOCK_SIZE
);
541 buf
+= SFP_BLOCK_SIZE
;
547 static struct bin_attribute sysfs_sfp_attr
= {
550 .mode
= S_IRUSR
| S_IWUSR
,
552 .size
= SFP_DEV_SIZE
* 2,
553 .read
= qla2x00_sysfs_read_sfp
,
557 qla2x00_sysfs_write_reset(struct file
*filp
, struct kobject
*kobj
,
558 struct bin_attribute
*bin_attr
,
559 char *buf
, loff_t off
, size_t count
)
561 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
562 struct device
, kobj
)));
563 struct qla_hw_data
*ha
= vha
->hw
;
564 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
570 type
= simple_strtol(buf
, NULL
, 10);
573 ql_log(ql_log_info
, vha
, 0x706e,
574 "Issuing ISP reset.\n");
576 scsi_block_requests(vha
->host
);
577 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
578 if (IS_QLA82XX(ha
)) {
579 qla82xx_idc_lock(ha
);
580 qla82xx_set_reset_owner(vha
);
581 qla82xx_idc_unlock(ha
);
583 qla2xxx_wake_dpc(vha
);
584 qla2x00_wait_for_chip_reset(vha
);
585 scsi_unblock_requests(vha
->host
);
591 ql_log(ql_log_info
, vha
, 0x706f,
592 "Issuing MPI reset.\n");
594 /* Make sure FC side is not in reset */
595 qla2x00_wait_for_hba_online(vha
);
597 /* Issue MPI reset */
598 scsi_block_requests(vha
->host
);
599 if (qla81xx_restart_mpi_firmware(vha
) != QLA_SUCCESS
)
600 ql_log(ql_log_warn
, vha
, 0x7070,
601 "MPI reset failed.\n");
602 scsi_unblock_requests(vha
->host
);
605 if (!IS_QLA82XX(ha
) || vha
!= base_vha
) {
606 ql_log(ql_log_info
, vha
, 0x7071,
607 "FCoE ctx reset no supported.\n");
611 ql_log(ql_log_info
, vha
, 0x7072,
612 "Issuing FCoE ctx reset.\n");
613 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
614 qla2xxx_wake_dpc(vha
);
615 qla2x00_wait_for_fcoe_ctx_reset(vha
);
621 static struct bin_attribute sysfs_reset_attr
= {
627 .write
= qla2x00_sysfs_write_reset
,
631 qla2x00_sysfs_read_xgmac_stats(struct file
*filp
, struct kobject
*kobj
,
632 struct bin_attribute
*bin_attr
,
633 char *buf
, loff_t off
, size_t count
)
635 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
636 struct device
, kobj
)));
637 struct qla_hw_data
*ha
= vha
->hw
;
639 uint16_t actual_size
;
641 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
> XGMAC_DATA_SIZE
)
647 ha
->xgmac_data
= dma_alloc_coherent(&ha
->pdev
->dev
, XGMAC_DATA_SIZE
,
648 &ha
->xgmac_data_dma
, GFP_KERNEL
);
649 if (!ha
->xgmac_data
) {
650 ql_log(ql_log_warn
, vha
, 0x7076,
651 "Unable to allocate memory for XGMAC read-data.\n");
657 memset(ha
->xgmac_data
, 0, XGMAC_DATA_SIZE
);
659 rval
= qla2x00_get_xgmac_stats(vha
, ha
->xgmac_data_dma
,
660 XGMAC_DATA_SIZE
, &actual_size
);
661 if (rval
!= QLA_SUCCESS
) {
662 ql_log(ql_log_warn
, vha
, 0x7077,
663 "Unable to read XGMAC data (%x).\n", rval
);
667 count
= actual_size
> count
? count
: actual_size
;
668 memcpy(buf
, ha
->xgmac_data
, count
);
673 static struct bin_attribute sysfs_xgmac_stats_attr
= {
675 .name
= "xgmac_stats",
679 .read
= qla2x00_sysfs_read_xgmac_stats
,
683 qla2x00_sysfs_read_dcbx_tlv(struct file
*filp
, struct kobject
*kobj
,
684 struct bin_attribute
*bin_attr
,
685 char *buf
, loff_t off
, size_t count
)
687 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
688 struct device
, kobj
)));
689 struct qla_hw_data
*ha
= vha
->hw
;
691 uint16_t actual_size
;
693 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
> DCBX_TLV_DATA_SIZE
)
699 ha
->dcbx_tlv
= dma_alloc_coherent(&ha
->pdev
->dev
, DCBX_TLV_DATA_SIZE
,
700 &ha
->dcbx_tlv_dma
, GFP_KERNEL
);
702 ql_log(ql_log_warn
, vha
, 0x7078,
703 "Unable to allocate memory for DCBX TLV read-data.\n");
709 memset(ha
->dcbx_tlv
, 0, DCBX_TLV_DATA_SIZE
);
711 rval
= qla2x00_get_dcbx_params(vha
, ha
->dcbx_tlv_dma
,
713 if (rval
!= QLA_SUCCESS
) {
714 ql_log(ql_log_warn
, vha
, 0x7079,
715 "Unable to read DCBX TLV (%x).\n", rval
);
719 memcpy(buf
, ha
->dcbx_tlv
, count
);
724 static struct bin_attribute sysfs_dcbx_tlv_attr
= {
730 .read
= qla2x00_sysfs_read_dcbx_tlv
,
733 static struct sysfs_entry
{
735 struct bin_attribute
*attr
;
737 } bin_file_entries
[] = {
738 { "fw_dump", &sysfs_fw_dump_attr
, },
739 { "nvram", &sysfs_nvram_attr
, },
740 { "optrom", &sysfs_optrom_attr
, },
741 { "optrom_ctl", &sysfs_optrom_ctl_attr
, },
742 { "vpd", &sysfs_vpd_attr
, 1 },
743 { "sfp", &sysfs_sfp_attr
, 1 },
744 { "reset", &sysfs_reset_attr
, },
745 { "xgmac_stats", &sysfs_xgmac_stats_attr
, 3 },
746 { "dcbx_tlv", &sysfs_dcbx_tlv_attr
, 3 },
751 qla2x00_alloc_sysfs_attr(scsi_qla_host_t
*vha
)
753 struct Scsi_Host
*host
= vha
->host
;
754 struct sysfs_entry
*iter
;
757 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
758 if (iter
->is4GBp_only
&& !IS_FWI2_CAPABLE(vha
->hw
))
760 if (iter
->is4GBp_only
== 2 && !IS_QLA25XX(vha
->hw
))
762 if (iter
->is4GBp_only
== 3 && !(IS_CNA_CAPABLE(vha
->hw
)))
765 ret
= sysfs_create_bin_file(&host
->shost_gendev
.kobj
,
768 ql_log(ql_log_warn
, vha
, 0x00f3,
769 "Unable to create sysfs %s binary attribute (%d).\n",
772 ql_dbg(ql_dbg_init
, vha
, 0x00f4,
773 "Successfully created sysfs %s binary attribure.\n",
779 qla2x00_free_sysfs_attr(scsi_qla_host_t
*vha
)
781 struct Scsi_Host
*host
= vha
->host
;
782 struct sysfs_entry
*iter
;
783 struct qla_hw_data
*ha
= vha
->hw
;
785 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
786 if (iter
->is4GBp_only
&& !IS_FWI2_CAPABLE(ha
))
788 if (iter
->is4GBp_only
== 2 && !IS_QLA25XX(ha
))
790 if (iter
->is4GBp_only
== 3 && !(IS_CNA_CAPABLE(vha
->hw
)))
793 sysfs_remove_bin_file(&host
->shost_gendev
.kobj
,
797 if (ha
->beacon_blink_led
== 1)
798 ha
->isp_ops
->beacon_off(vha
);
801 /* Scsi_Host attributes. */
804 qla2x00_drvr_version_show(struct device
*dev
,
805 struct device_attribute
*attr
, char *buf
)
807 return snprintf(buf
, PAGE_SIZE
, "%s\n", qla2x00_version_str
);
811 qla2x00_fw_version_show(struct device
*dev
,
812 struct device_attribute
*attr
, char *buf
)
814 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
815 struct qla_hw_data
*ha
= vha
->hw
;
818 return snprintf(buf
, PAGE_SIZE
, "%s\n",
819 ha
->isp_ops
->fw_version_str(vha
, fw_str
));
823 qla2x00_serial_num_show(struct device
*dev
, struct device_attribute
*attr
,
826 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
827 struct qla_hw_data
*ha
= vha
->hw
;
830 if (IS_FWI2_CAPABLE(ha
)) {
831 qla2xxx_get_vpd_field(vha
, "SN", buf
, PAGE_SIZE
);
832 return snprintf(buf
, PAGE_SIZE
, "%s\n", buf
);
835 sn
= ((ha
->serial0
& 0x1f) << 16) | (ha
->serial2
<< 8) | ha
->serial1
;
836 return snprintf(buf
, PAGE_SIZE
, "%c%05d\n", 'A' + sn
/ 100000,
841 qla2x00_isp_name_show(struct device
*dev
, struct device_attribute
*attr
,
844 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
845 return snprintf(buf
, PAGE_SIZE
, "ISP%04X\n", vha
->hw
->pdev
->device
);
849 qla2x00_isp_id_show(struct device
*dev
, struct device_attribute
*attr
,
852 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
853 struct qla_hw_data
*ha
= vha
->hw
;
854 return snprintf(buf
, PAGE_SIZE
, "%04x %04x %04x %04x\n",
855 ha
->product_id
[0], ha
->product_id
[1], ha
->product_id
[2],
860 qla2x00_model_name_show(struct device
*dev
, struct device_attribute
*attr
,
863 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
864 return snprintf(buf
, PAGE_SIZE
, "%s\n", vha
->hw
->model_number
);
868 qla2x00_model_desc_show(struct device
*dev
, struct device_attribute
*attr
,
871 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
872 return snprintf(buf
, PAGE_SIZE
, "%s\n",
873 vha
->hw
->model_desc
? vha
->hw
->model_desc
: "");
877 qla2x00_pci_info_show(struct device
*dev
, struct device_attribute
*attr
,
880 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
883 return snprintf(buf
, PAGE_SIZE
, "%s\n",
884 vha
->hw
->isp_ops
->pci_info_str(vha
, pci_info
));
888 qla2x00_link_state_show(struct device
*dev
, struct device_attribute
*attr
,
891 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
892 struct qla_hw_data
*ha
= vha
->hw
;
895 if (atomic_read(&vha
->loop_state
) == LOOP_DOWN
||
896 atomic_read(&vha
->loop_state
) == LOOP_DEAD
||
897 vha
->device_flags
& DFLG_NO_CABLE
)
898 len
= snprintf(buf
, PAGE_SIZE
, "Link Down\n");
899 else if (atomic_read(&vha
->loop_state
) != LOOP_READY
||
900 qla2x00_reset_active(vha
))
901 len
= snprintf(buf
, PAGE_SIZE
, "Unknown Link State\n");
903 len
= snprintf(buf
, PAGE_SIZE
, "Link Up - ");
905 switch (ha
->current_topology
) {
907 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
910 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "FL_Port\n");
913 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
914 "N_Port to N_Port\n");
917 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "F_Port\n");
920 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
928 qla2x00_zio_show(struct device
*dev
, struct device_attribute
*attr
,
931 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
934 switch (vha
->hw
->zio_mode
) {
936 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Mode 6\n");
938 case QLA_ZIO_DISABLED
:
939 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
946 qla2x00_zio_store(struct device
*dev
, struct device_attribute
*attr
,
947 const char *buf
, size_t count
)
949 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
950 struct qla_hw_data
*ha
= vha
->hw
;
954 if (!IS_ZIO_SUPPORTED(ha
))
957 if (sscanf(buf
, "%d", &val
) != 1)
961 zio_mode
= QLA_ZIO_MODE_6
;
963 zio_mode
= QLA_ZIO_DISABLED
;
965 /* Update per-hba values and queue a reset. */
966 if (zio_mode
!= QLA_ZIO_DISABLED
|| ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
967 ha
->zio_mode
= zio_mode
;
968 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
974 qla2x00_zio_timer_show(struct device
*dev
, struct device_attribute
*attr
,
977 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
979 return snprintf(buf
, PAGE_SIZE
, "%d us\n", vha
->hw
->zio_timer
* 100);
983 qla2x00_zio_timer_store(struct device
*dev
, struct device_attribute
*attr
,
984 const char *buf
, size_t count
)
986 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
990 if (sscanf(buf
, "%d", &val
) != 1)
992 if (val
> 25500 || val
< 100)
995 zio_timer
= (uint16_t)(val
/ 100);
996 vha
->hw
->zio_timer
= zio_timer
;
1002 qla2x00_beacon_show(struct device
*dev
, struct device_attribute
*attr
,
1005 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1008 if (vha
->hw
->beacon_blink_led
)
1009 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Enabled\n");
1011 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
1016 qla2x00_beacon_store(struct device
*dev
, struct device_attribute
*attr
,
1017 const char *buf
, size_t count
)
1019 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1020 struct qla_hw_data
*ha
= vha
->hw
;
1024 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1027 if (test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)) {
1028 ql_log(ql_log_warn
, vha
, 0x707a,
1029 "Abort ISP active -- ignoring beacon request.\n");
1033 if (sscanf(buf
, "%d", &val
) != 1)
1037 rval
= ha
->isp_ops
->beacon_on(vha
);
1039 rval
= ha
->isp_ops
->beacon_off(vha
);
1041 if (rval
!= QLA_SUCCESS
)
1048 qla2x00_optrom_bios_version_show(struct device
*dev
,
1049 struct device_attribute
*attr
, char *buf
)
1051 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1052 struct qla_hw_data
*ha
= vha
->hw
;
1053 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->bios_revision
[1],
1054 ha
->bios_revision
[0]);
1058 qla2x00_optrom_efi_version_show(struct device
*dev
,
1059 struct device_attribute
*attr
, char *buf
)
1061 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1062 struct qla_hw_data
*ha
= vha
->hw
;
1063 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->efi_revision
[1],
1064 ha
->efi_revision
[0]);
1068 qla2x00_optrom_fcode_version_show(struct device
*dev
,
1069 struct device_attribute
*attr
, char *buf
)
1071 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1072 struct qla_hw_data
*ha
= vha
->hw
;
1073 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->fcode_revision
[1],
1074 ha
->fcode_revision
[0]);
1078 qla2x00_optrom_fw_version_show(struct device
*dev
,
1079 struct device_attribute
*attr
, char *buf
)
1081 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1082 struct qla_hw_data
*ha
= vha
->hw
;
1083 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d %d\n",
1084 ha
->fw_revision
[0], ha
->fw_revision
[1], ha
->fw_revision
[2],
1085 ha
->fw_revision
[3]);
1089 qla2x00_optrom_gold_fw_version_show(struct device
*dev
,
1090 struct device_attribute
*attr
, char *buf
)
1092 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1093 struct qla_hw_data
*ha
= vha
->hw
;
1095 if (!IS_QLA81XX(ha
) && !IS_QLA83XX(ha
))
1096 return snprintf(buf
, PAGE_SIZE
, "\n");
1098 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d (%d)\n",
1099 ha
->gold_fw_version
[0], ha
->gold_fw_version
[1],
1100 ha
->gold_fw_version
[2], ha
->gold_fw_version
[3]);
1104 qla2x00_total_isp_aborts_show(struct device
*dev
,
1105 struct device_attribute
*attr
, char *buf
)
1107 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1108 struct qla_hw_data
*ha
= vha
->hw
;
1109 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1110 ha
->qla_stats
.total_isp_aborts
);
1114 qla24xx_84xx_fw_version_show(struct device
*dev
,
1115 struct device_attribute
*attr
, char *buf
)
1117 int rval
= QLA_SUCCESS
;
1118 uint16_t status
[2] = {0, 0};
1119 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1120 struct qla_hw_data
*ha
= vha
->hw
;
1122 if (!IS_QLA84XX(ha
))
1123 return snprintf(buf
, PAGE_SIZE
, "\n");
1125 if (ha
->cs84xx
->op_fw_version
== 0)
1126 rval
= qla84xx_verify_chip(vha
, status
);
1128 if ((rval
== QLA_SUCCESS
) && (status
[0] == 0))
1129 return snprintf(buf
, PAGE_SIZE
, "%u\n",
1130 (uint32_t)ha
->cs84xx
->op_fw_version
);
1132 return snprintf(buf
, PAGE_SIZE
, "\n");
1136 qla2x00_mpi_version_show(struct device
*dev
, struct device_attribute
*attr
,
1139 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1140 struct qla_hw_data
*ha
= vha
->hw
;
1142 if (!IS_QLA81XX(ha
) && !IS_QLA8031(ha
))
1143 return snprintf(buf
, PAGE_SIZE
, "\n");
1145 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d (%x)\n",
1146 ha
->mpi_version
[0], ha
->mpi_version
[1], ha
->mpi_version
[2],
1147 ha
->mpi_capabilities
);
1151 qla2x00_phy_version_show(struct device
*dev
, struct device_attribute
*attr
,
1154 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1155 struct qla_hw_data
*ha
= vha
->hw
;
1157 if (!IS_QLA81XX(ha
) && !IS_QLA83XX(ha
))
1158 return snprintf(buf
, PAGE_SIZE
, "\n");
1160 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d\n",
1161 ha
->phy_version
[0], ha
->phy_version
[1], ha
->phy_version
[2]);
1165 qla2x00_flash_block_size_show(struct device
*dev
,
1166 struct device_attribute
*attr
, char *buf
)
1168 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1169 struct qla_hw_data
*ha
= vha
->hw
;
1171 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", ha
->fdt_block_size
);
1175 qla2x00_vlan_id_show(struct device
*dev
, struct device_attribute
*attr
,
1178 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1180 if (!IS_CNA_CAPABLE(vha
->hw
))
1181 return snprintf(buf
, PAGE_SIZE
, "\n");
1183 return snprintf(buf
, PAGE_SIZE
, "%d\n", vha
->fcoe_vlan_id
);
1187 qla2x00_vn_port_mac_address_show(struct device
*dev
,
1188 struct device_attribute
*attr
, char *buf
)
1190 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1192 if (!IS_CNA_CAPABLE(vha
->hw
))
1193 return snprintf(buf
, PAGE_SIZE
, "\n");
1195 return snprintf(buf
, PAGE_SIZE
, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1196 vha
->fcoe_vn_port_mac
[5], vha
->fcoe_vn_port_mac
[4],
1197 vha
->fcoe_vn_port_mac
[3], vha
->fcoe_vn_port_mac
[2],
1198 vha
->fcoe_vn_port_mac
[1], vha
->fcoe_vn_port_mac
[0]);
1202 qla2x00_fabric_param_show(struct device
*dev
, struct device_attribute
*attr
,
1205 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1207 return snprintf(buf
, PAGE_SIZE
, "%d\n", vha
->hw
->switch_cap
);
1211 qla2x00_thermal_temp_show(struct device
*dev
,
1212 struct device_attribute
*attr
, char *buf
)
1214 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1215 int rval
= QLA_FUNCTION_FAILED
;
1216 uint16_t temp
, frac
;
1218 if (!vha
->hw
->flags
.thermal_supported
)
1219 return snprintf(buf
, PAGE_SIZE
, "\n");
1222 if (qla2x00_reset_active(vha
))
1223 ql_log(ql_log_warn
, vha
, 0x707b,
1224 "ISP reset active.\n");
1225 else if (!vha
->hw
->flags
.eeh_busy
)
1226 rval
= qla2x00_get_thermal_temp(vha
, &temp
, &frac
);
1227 if (rval
!= QLA_SUCCESS
)
1228 return snprintf(buf
, PAGE_SIZE
, "\n");
1230 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", temp
, frac
);
1234 qla2x00_fw_state_show(struct device
*dev
, struct device_attribute
*attr
,
1237 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1238 int rval
= QLA_FUNCTION_FAILED
;
1241 if (qla2x00_reset_active(vha
))
1242 ql_log(ql_log_warn
, vha
, 0x707c,
1243 "ISP reset active.\n");
1244 else if (!vha
->hw
->flags
.eeh_busy
)
1245 rval
= qla2x00_get_firmware_state(vha
, state
);
1246 if (rval
!= QLA_SUCCESS
)
1247 memset(state
, -1, sizeof(state
));
1249 return snprintf(buf
, PAGE_SIZE
, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state
[0],
1250 state
[1], state
[2], state
[3], state
[4]);
1253 static DEVICE_ATTR(driver_version
, S_IRUGO
, qla2x00_drvr_version_show
, NULL
);
1254 static DEVICE_ATTR(fw_version
, S_IRUGO
, qla2x00_fw_version_show
, NULL
);
1255 static DEVICE_ATTR(serial_num
, S_IRUGO
, qla2x00_serial_num_show
, NULL
);
1256 static DEVICE_ATTR(isp_name
, S_IRUGO
, qla2x00_isp_name_show
, NULL
);
1257 static DEVICE_ATTR(isp_id
, S_IRUGO
, qla2x00_isp_id_show
, NULL
);
1258 static DEVICE_ATTR(model_name
, S_IRUGO
, qla2x00_model_name_show
, NULL
);
1259 static DEVICE_ATTR(model_desc
, S_IRUGO
, qla2x00_model_desc_show
, NULL
);
1260 static DEVICE_ATTR(pci_info
, S_IRUGO
, qla2x00_pci_info_show
, NULL
);
1261 static DEVICE_ATTR(link_state
, S_IRUGO
, qla2x00_link_state_show
, NULL
);
1262 static DEVICE_ATTR(zio
, S_IRUGO
| S_IWUSR
, qla2x00_zio_show
, qla2x00_zio_store
);
1263 static DEVICE_ATTR(zio_timer
, S_IRUGO
| S_IWUSR
, qla2x00_zio_timer_show
,
1264 qla2x00_zio_timer_store
);
1265 static DEVICE_ATTR(beacon
, S_IRUGO
| S_IWUSR
, qla2x00_beacon_show
,
1266 qla2x00_beacon_store
);
1267 static DEVICE_ATTR(optrom_bios_version
, S_IRUGO
,
1268 qla2x00_optrom_bios_version_show
, NULL
);
1269 static DEVICE_ATTR(optrom_efi_version
, S_IRUGO
,
1270 qla2x00_optrom_efi_version_show
, NULL
);
1271 static DEVICE_ATTR(optrom_fcode_version
, S_IRUGO
,
1272 qla2x00_optrom_fcode_version_show
, NULL
);
1273 static DEVICE_ATTR(optrom_fw_version
, S_IRUGO
, qla2x00_optrom_fw_version_show
,
1275 static DEVICE_ATTR(optrom_gold_fw_version
, S_IRUGO
,
1276 qla2x00_optrom_gold_fw_version_show
, NULL
);
1277 static DEVICE_ATTR(84xx_fw_version
, S_IRUGO
, qla24xx_84xx_fw_version_show
,
1279 static DEVICE_ATTR(total_isp_aborts
, S_IRUGO
, qla2x00_total_isp_aborts_show
,
1281 static DEVICE_ATTR(mpi_version
, S_IRUGO
, qla2x00_mpi_version_show
, NULL
);
1282 static DEVICE_ATTR(phy_version
, S_IRUGO
, qla2x00_phy_version_show
, NULL
);
1283 static DEVICE_ATTR(flash_block_size
, S_IRUGO
, qla2x00_flash_block_size_show
,
1285 static DEVICE_ATTR(vlan_id
, S_IRUGO
, qla2x00_vlan_id_show
, NULL
);
1286 static DEVICE_ATTR(vn_port_mac_address
, S_IRUGO
,
1287 qla2x00_vn_port_mac_address_show
, NULL
);
1288 static DEVICE_ATTR(fabric_param
, S_IRUGO
, qla2x00_fabric_param_show
, NULL
);
1289 static DEVICE_ATTR(fw_state
, S_IRUGO
, qla2x00_fw_state_show
, NULL
);
1290 static DEVICE_ATTR(thermal_temp
, S_IRUGO
, qla2x00_thermal_temp_show
, NULL
);
1292 struct device_attribute
*qla2x00_host_attrs
[] = {
1293 &dev_attr_driver_version
,
1294 &dev_attr_fw_version
,
1295 &dev_attr_serial_num
,
1298 &dev_attr_model_name
,
1299 &dev_attr_model_desc
,
1301 &dev_attr_link_state
,
1303 &dev_attr_zio_timer
,
1305 &dev_attr_optrom_bios_version
,
1306 &dev_attr_optrom_efi_version
,
1307 &dev_attr_optrom_fcode_version
,
1308 &dev_attr_optrom_fw_version
,
1309 &dev_attr_84xx_fw_version
,
1310 &dev_attr_total_isp_aborts
,
1311 &dev_attr_mpi_version
,
1312 &dev_attr_phy_version
,
1313 &dev_attr_flash_block_size
,
1315 &dev_attr_vn_port_mac_address
,
1316 &dev_attr_fabric_param
,
1318 &dev_attr_optrom_gold_fw_version
,
1319 &dev_attr_thermal_temp
,
1323 /* Host attributes. */
1326 qla2x00_get_host_port_id(struct Scsi_Host
*shost
)
1328 scsi_qla_host_t
*vha
= shost_priv(shost
);
1330 fc_host_port_id(shost
) = vha
->d_id
.b
.domain
<< 16 |
1331 vha
->d_id
.b
.area
<< 8 | vha
->d_id
.b
.al_pa
;
1335 qla2x00_get_host_speed(struct Scsi_Host
*shost
)
1337 struct qla_hw_data
*ha
= ((struct scsi_qla_host
*)
1338 (shost_priv(shost
)))->hw
;
1339 u32 speed
= FC_PORTSPEED_UNKNOWN
;
1341 switch (ha
->link_data_rate
) {
1342 case PORT_SPEED_1GB
:
1343 speed
= FC_PORTSPEED_1GBIT
;
1345 case PORT_SPEED_2GB
:
1346 speed
= FC_PORTSPEED_2GBIT
;
1348 case PORT_SPEED_4GB
:
1349 speed
= FC_PORTSPEED_4GBIT
;
1351 case PORT_SPEED_8GB
:
1352 speed
= FC_PORTSPEED_8GBIT
;
1354 case PORT_SPEED_10GB
:
1355 speed
= FC_PORTSPEED_10GBIT
;
1357 case PORT_SPEED_16GB
:
1358 speed
= FC_PORTSPEED_16GBIT
;
1361 fc_host_speed(shost
) = speed
;
1365 qla2x00_get_host_port_type(struct Scsi_Host
*shost
)
1367 scsi_qla_host_t
*vha
= shost_priv(shost
);
1368 uint32_t port_type
= FC_PORTTYPE_UNKNOWN
;
1371 fc_host_port_type(shost
) = FC_PORTTYPE_NPIV
;
1374 switch (vha
->hw
->current_topology
) {
1376 port_type
= FC_PORTTYPE_LPORT
;
1379 port_type
= FC_PORTTYPE_NLPORT
;
1382 port_type
= FC_PORTTYPE_PTP
;
1385 port_type
= FC_PORTTYPE_NPORT
;
1388 fc_host_port_type(shost
) = port_type
;
1392 qla2x00_get_starget_node_name(struct scsi_target
*starget
)
1394 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
1395 scsi_qla_host_t
*vha
= shost_priv(host
);
1399 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1400 if (fcport
->rport
&&
1401 starget
->id
== fcport
->rport
->scsi_target_id
) {
1402 node_name
= wwn_to_u64(fcport
->node_name
);
1407 fc_starget_node_name(starget
) = node_name
;
1411 qla2x00_get_starget_port_name(struct scsi_target
*starget
)
1413 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
1414 scsi_qla_host_t
*vha
= shost_priv(host
);
1418 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1419 if (fcport
->rport
&&
1420 starget
->id
== fcport
->rport
->scsi_target_id
) {
1421 port_name
= wwn_to_u64(fcport
->port_name
);
1426 fc_starget_port_name(starget
) = port_name
;
1430 qla2x00_get_starget_port_id(struct scsi_target
*starget
)
1432 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
1433 scsi_qla_host_t
*vha
= shost_priv(host
);
1435 uint32_t port_id
= ~0U;
1437 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1438 if (fcport
->rport
&&
1439 starget
->id
== fcport
->rport
->scsi_target_id
) {
1440 port_id
= fcport
->d_id
.b
.domain
<< 16 |
1441 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
1446 fc_starget_port_id(starget
) = port_id
;
1450 qla2x00_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
1453 rport
->dev_loss_tmo
= timeout
;
1455 rport
->dev_loss_tmo
= 1;
1459 qla2x00_dev_loss_tmo_callbk(struct fc_rport
*rport
)
1461 struct Scsi_Host
*host
= rport_to_shost(rport
);
1462 fc_port_t
*fcport
= *(fc_port_t
**)rport
->dd_data
;
1463 unsigned long flags
;
1468 /* Now that the rport has been deleted, set the fcport state to
1470 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_DEAD
);
1473 * Transport has effectively 'deleted' the rport, clear
1474 * all local references.
1476 spin_lock_irqsave(host
->host_lock
, flags
);
1477 fcport
->rport
= fcport
->drport
= NULL
;
1478 *((fc_port_t
**)rport
->dd_data
) = NULL
;
1479 spin_unlock_irqrestore(host
->host_lock
, flags
);
1481 if (test_bit(ABORT_ISP_ACTIVE
, &fcport
->vha
->dpc_flags
))
1484 if (unlikely(pci_channel_offline(fcport
->vha
->hw
->pdev
))) {
1485 qla2x00_abort_all_cmds(fcport
->vha
, DID_NO_CONNECT
<< 16);
1491 qla2x00_terminate_rport_io(struct fc_rport
*rport
)
1493 fc_port_t
*fcport
= *(fc_port_t
**)rport
->dd_data
;
1498 if (test_bit(ABORT_ISP_ACTIVE
, &fcport
->vha
->dpc_flags
))
1501 if (unlikely(pci_channel_offline(fcport
->vha
->hw
->pdev
))) {
1502 qla2x00_abort_all_cmds(fcport
->vha
, DID_NO_CONNECT
<< 16);
1506 * At this point all fcport's software-states are cleared. Perform any
1507 * final cleanup of firmware resources (PCBs and XCBs).
1509 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
1510 !test_bit(UNLOADING
, &fcport
->vha
->dpc_flags
)) {
1511 if (IS_FWI2_CAPABLE(fcport
->vha
->hw
))
1512 fcport
->vha
->hw
->isp_ops
->fabric_logout(fcport
->vha
,
1513 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
1514 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
1516 qla2x00_port_logout(fcport
->vha
, fcport
);
1521 qla2x00_issue_lip(struct Scsi_Host
*shost
)
1523 scsi_qla_host_t
*vha
= shost_priv(shost
);
1525 qla2x00_loop_reset(vha
);
1529 static struct fc_host_statistics
*
1530 qla2x00_get_fc_host_stats(struct Scsi_Host
*shost
)
1532 scsi_qla_host_t
*vha
= shost_priv(shost
);
1533 struct qla_hw_data
*ha
= vha
->hw
;
1534 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
1536 struct link_statistics
*stats
;
1537 dma_addr_t stats_dma
;
1538 struct fc_host_statistics
*pfc_host_stat
;
1540 pfc_host_stat
= &ha
->fc_host_stat
;
1541 memset(pfc_host_stat
, -1, sizeof(struct fc_host_statistics
));
1543 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1546 if (unlikely(pci_channel_offline(ha
->pdev
)))
1549 stats
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
, &stats_dma
);
1550 if (stats
== NULL
) {
1551 ql_log(ql_log_warn
, vha
, 0x707d,
1552 "Failed to allocate memory for stats.\n");
1555 memset(stats
, 0, DMA_POOL_SIZE
);
1557 rval
= QLA_FUNCTION_FAILED
;
1558 if (IS_FWI2_CAPABLE(ha
)) {
1559 rval
= qla24xx_get_isp_stats(base_vha
, stats
, stats_dma
);
1560 } else if (atomic_read(&base_vha
->loop_state
) == LOOP_READY
&&
1561 !qla2x00_reset_active(vha
) && !ha
->dpc_active
) {
1562 /* Must be in a 'READY' state for statistics retrieval. */
1563 rval
= qla2x00_get_link_status(base_vha
, base_vha
->loop_id
,
1567 if (rval
!= QLA_SUCCESS
)
1570 pfc_host_stat
->link_failure_count
= stats
->link_fail_cnt
;
1571 pfc_host_stat
->loss_of_sync_count
= stats
->loss_sync_cnt
;
1572 pfc_host_stat
->loss_of_signal_count
= stats
->loss_sig_cnt
;
1573 pfc_host_stat
->prim_seq_protocol_err_count
= stats
->prim_seq_err_cnt
;
1574 pfc_host_stat
->invalid_tx_word_count
= stats
->inval_xmit_word_cnt
;
1575 pfc_host_stat
->invalid_crc_count
= stats
->inval_crc_cnt
;
1576 if (IS_FWI2_CAPABLE(ha
)) {
1577 pfc_host_stat
->lip_count
= stats
->lip_cnt
;
1578 pfc_host_stat
->tx_frames
= stats
->tx_frames
;
1579 pfc_host_stat
->rx_frames
= stats
->rx_frames
;
1580 pfc_host_stat
->dumped_frames
= stats
->dumped_frames
;
1581 pfc_host_stat
->nos_count
= stats
->nos_rcvd
;
1583 pfc_host_stat
->fcp_input_megabytes
= ha
->qla_stats
.input_bytes
>> 20;
1584 pfc_host_stat
->fcp_output_megabytes
= ha
->qla_stats
.output_bytes
>> 20;
1587 dma_pool_free(ha
->s_dma_pool
, stats
, stats_dma
);
1589 return pfc_host_stat
;
1593 qla2x00_get_host_symbolic_name(struct Scsi_Host
*shost
)
1595 scsi_qla_host_t
*vha
= shost_priv(shost
);
1597 qla2x00_get_sym_node_name(vha
, fc_host_symbolic_name(shost
));
1601 qla2x00_set_host_system_hostname(struct Scsi_Host
*shost
)
1603 scsi_qla_host_t
*vha
= shost_priv(shost
);
1605 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
1609 qla2x00_get_host_fabric_name(struct Scsi_Host
*shost
)
1611 scsi_qla_host_t
*vha
= shost_priv(shost
);
1612 uint8_t node_name
[WWN_SIZE
] = { 0xFF, 0xFF, 0xFF, 0xFF, \
1613 0xFF, 0xFF, 0xFF, 0xFF};
1614 u64 fabric_name
= wwn_to_u64(node_name
);
1616 if (vha
->device_flags
& SWITCH_FOUND
)
1617 fabric_name
= wwn_to_u64(vha
->fabric_node_name
);
1619 fc_host_fabric_name(shost
) = fabric_name
;
1623 qla2x00_get_host_port_state(struct Scsi_Host
*shost
)
1625 scsi_qla_host_t
*vha
= shost_priv(shost
);
1626 struct scsi_qla_host
*base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
1628 if (!base_vha
->flags
.online
) {
1629 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
1633 switch (atomic_read(&base_vha
->loop_state
)) {
1635 fc_host_port_state(shost
) = FC_PORTSTATE_DIAGNOSTICS
;
1638 if (test_bit(LOOP_RESYNC_NEEDED
, &base_vha
->dpc_flags
))
1639 fc_host_port_state(shost
) = FC_PORTSTATE_DIAGNOSTICS
;
1641 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
1644 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
1647 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
1650 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
1656 qla24xx_vport_create(struct fc_vport
*fc_vport
, bool disable
)
1660 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
1661 scsi_qla_host_t
*vha
= NULL
;
1662 struct qla_hw_data
*ha
= base_vha
->hw
;
1663 uint16_t options
= 0;
1665 struct req_que
*req
= ha
->req_q_map
[0];
1667 ret
= qla24xx_vport_create_req_sanity_check(fc_vport
);
1669 ql_log(ql_log_warn
, vha
, 0x707e,
1670 "Vport sanity check failed, status %x\n", ret
);
1674 vha
= qla24xx_create_vhost(fc_vport
);
1676 ql_log(ql_log_warn
, vha
, 0x707f, "Vport create host failed.\n");
1677 return FC_VPORT_FAILED
;
1680 atomic_set(&vha
->vp_state
, VP_OFFLINE
);
1681 fc_vport_set_state(fc_vport
, FC_VPORT_DISABLED
);
1683 atomic_set(&vha
->vp_state
, VP_FAILED
);
1685 /* ready to create vport */
1686 ql_log(ql_log_info
, vha
, 0x7080,
1687 "VP entry id %d assigned.\n", vha
->vp_idx
);
1689 /* initialized vport states */
1690 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1691 vha
->vp_err_state
= VP_ERR_PORTDWN
;
1692 vha
->vp_prev_err_state
= VP_ERR_UNKWN
;
1693 /* Check if physical ha port is Up */
1694 if (atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
||
1695 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
1696 /* Don't retry or attempt login of this virtual port */
1697 ql_dbg(ql_dbg_user
, vha
, 0x7081,
1698 "Vport loop state is not UP.\n");
1699 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
1701 fc_vport_set_state(fc_vport
, FC_VPORT_LINKDOWN
);
1704 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
1705 if (ha
->fw_attributes
& BIT_4
) {
1707 vha
->flags
.difdix_supported
= 1;
1708 ql_dbg(ql_dbg_user
, vha
, 0x7082,
1709 "Registered for DIF/DIX type 1 and 3 protection.\n");
1710 if (ql2xenabledif
== 1)
1711 prot
= SHOST_DIX_TYPE0_PROTECTION
;
1712 scsi_host_set_prot(vha
->host
,
1713 prot
| SHOST_DIF_TYPE1_PROTECTION
1714 | SHOST_DIF_TYPE2_PROTECTION
1715 | SHOST_DIF_TYPE3_PROTECTION
1716 | SHOST_DIX_TYPE1_PROTECTION
1717 | SHOST_DIX_TYPE2_PROTECTION
1718 | SHOST_DIX_TYPE3_PROTECTION
);
1719 scsi_host_set_guard(vha
->host
, SHOST_DIX_GUARD_CRC
);
1721 vha
->flags
.difdix_supported
= 0;
1724 if (scsi_add_host_with_dma(vha
->host
, &fc_vport
->dev
,
1726 ql_dbg(ql_dbg_user
, vha
, 0x7083,
1727 "scsi_add_host failure for VP[%d].\n", vha
->vp_idx
);
1728 goto vport_create_failed_2
;
1731 /* initialize attributes */
1732 fc_host_dev_loss_tmo(vha
->host
) = ha
->port_down_retry_count
;
1733 fc_host_node_name(vha
->host
) = wwn_to_u64(vha
->node_name
);
1734 fc_host_port_name(vha
->host
) = wwn_to_u64(vha
->port_name
);
1735 fc_host_supported_classes(vha
->host
) =
1736 fc_host_supported_classes(base_vha
->host
);
1737 fc_host_supported_speeds(vha
->host
) =
1738 fc_host_supported_speeds(base_vha
->host
);
1740 qla24xx_vport_disable(fc_vport
, disable
);
1742 if (ha
->flags
.cpu_affinity_enabled
) {
1743 req
= ha
->req_q_map
[1];
1744 ql_dbg(ql_dbg_multiq
, vha
, 0xc000,
1745 "Request queue %p attached with "
1746 "VP[%d], cpu affinity =%d\n",
1747 req
, vha
->vp_idx
, ha
->flags
.cpu_affinity_enabled
);
1749 } else if (ql2xmaxqueues
== 1 || !ha
->npiv_info
)
1751 /* Create a request queue in QoS mode for the vport */
1752 for (cnt
= 0; cnt
< ha
->nvram_npiv_size
; cnt
++) {
1753 if (memcmp(ha
->npiv_info
[cnt
].port_name
, vha
->port_name
, 8) == 0
1754 && memcmp(ha
->npiv_info
[cnt
].node_name
, vha
->node_name
,
1756 qos
= ha
->npiv_info
[cnt
].q_qos
;
1762 ret
= qla25xx_create_req_que(ha
, options
, vha
->vp_idx
, 0, 0,
1765 ql_log(ql_log_warn
, vha
, 0x7084,
1766 "Can't create request queue for VP[%d]\n",
1769 ql_dbg(ql_dbg_multiq
, vha
, 0xc001,
1770 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1771 ret
, qos
, vha
->vp_idx
);
1772 ql_dbg(ql_dbg_user
, vha
, 0x7085,
1773 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1774 ret
, qos
, vha
->vp_idx
);
1775 req
= ha
->req_q_map
[ret
];
1783 vport_create_failed_2
:
1784 qla24xx_disable_vp(vha
);
1785 qla24xx_deallocate_vp_id(vha
);
1786 scsi_host_put(vha
->host
);
1787 return FC_VPORT_FAILED
;
1791 qla24xx_vport_delete(struct fc_vport
*fc_vport
)
1793 scsi_qla_host_t
*vha
= fc_vport
->dd_data
;
1794 struct qla_hw_data
*ha
= vha
->hw
;
1795 uint16_t id
= vha
->vp_idx
;
1797 while (test_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
) ||
1798 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
))
1801 qla24xx_disable_vp(vha
);
1803 vha
->flags
.delete_progress
= 1;
1805 fc_remove_host(vha
->host
);
1807 scsi_remove_host(vha
->host
);
1809 /* Allow timer to run to drain queued items, when removing vp */
1810 qla24xx_deallocate_vp_id(vha
);
1812 if (vha
->timer_active
) {
1813 qla2x00_vp_stop_timer(vha
);
1814 ql_dbg(ql_dbg_user
, vha
, 0x7086,
1815 "Timer for the VP[%d] has stopped\n", vha
->vp_idx
);
1818 /* No pending activities shall be there on the vha now */
1819 if (ql2xextended_error_logging
& ql_dbg_user
)
1820 msleep(random32()%10); /* Just to see if something falls on
1821 * the net we have placed below */
1823 BUG_ON(atomic_read(&vha
->vref_count
));
1825 qla2x00_free_fcports(vha
);
1827 mutex_lock(&ha
->vport_lock
);
1828 ha
->cur_vport_count
--;
1829 clear_bit(vha
->vp_idx
, ha
->vp_idx_map
);
1830 mutex_unlock(&ha
->vport_lock
);
1832 if (vha
->req
->id
&& !ha
->flags
.cpu_affinity_enabled
) {
1833 if (qla25xx_delete_req_que(vha
, vha
->req
) != QLA_SUCCESS
)
1834 ql_log(ql_log_warn
, vha
, 0x7087,
1835 "Queue delete failed.\n");
1838 ql_log(ql_log_info
, vha
, 0x7088, "VP[%d] deleted.\n", id
);
1839 scsi_host_put(vha
->host
);
1844 qla24xx_vport_disable(struct fc_vport
*fc_vport
, bool disable
)
1846 scsi_qla_host_t
*vha
= fc_vport
->dd_data
;
1849 qla24xx_disable_vp(vha
);
1851 qla24xx_enable_vp(vha
);
1856 struct fc_function_template qla2xxx_transport_functions
= {
1858 .show_host_node_name
= 1,
1859 .show_host_port_name
= 1,
1860 .show_host_supported_classes
= 1,
1861 .show_host_supported_speeds
= 1,
1863 .get_host_port_id
= qla2x00_get_host_port_id
,
1864 .show_host_port_id
= 1,
1865 .get_host_speed
= qla2x00_get_host_speed
,
1866 .show_host_speed
= 1,
1867 .get_host_port_type
= qla2x00_get_host_port_type
,
1868 .show_host_port_type
= 1,
1869 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
1870 .show_host_symbolic_name
= 1,
1871 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
1872 .show_host_system_hostname
= 1,
1873 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
1874 .show_host_fabric_name
= 1,
1875 .get_host_port_state
= qla2x00_get_host_port_state
,
1876 .show_host_port_state
= 1,
1878 .dd_fcrport_size
= sizeof(struct fc_port
*),
1879 .show_rport_supported_classes
= 1,
1881 .get_starget_node_name
= qla2x00_get_starget_node_name
,
1882 .show_starget_node_name
= 1,
1883 .get_starget_port_name
= qla2x00_get_starget_port_name
,
1884 .show_starget_port_name
= 1,
1885 .get_starget_port_id
= qla2x00_get_starget_port_id
,
1886 .show_starget_port_id
= 1,
1888 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
1889 .show_rport_dev_loss_tmo
= 1,
1891 .issue_fc_host_lip
= qla2x00_issue_lip
,
1892 .dev_loss_tmo_callbk
= qla2x00_dev_loss_tmo_callbk
,
1893 .terminate_rport_io
= qla2x00_terminate_rport_io
,
1894 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
1896 .vport_create
= qla24xx_vport_create
,
1897 .vport_disable
= qla24xx_vport_disable
,
1898 .vport_delete
= qla24xx_vport_delete
,
1899 .bsg_request
= qla24xx_bsg_request
,
1900 .bsg_timeout
= qla24xx_bsg_timeout
,
1903 struct fc_function_template qla2xxx_transport_vport_functions
= {
1905 .show_host_node_name
= 1,
1906 .show_host_port_name
= 1,
1907 .show_host_supported_classes
= 1,
1909 .get_host_port_id
= qla2x00_get_host_port_id
,
1910 .show_host_port_id
= 1,
1911 .get_host_speed
= qla2x00_get_host_speed
,
1912 .show_host_speed
= 1,
1913 .get_host_port_type
= qla2x00_get_host_port_type
,
1914 .show_host_port_type
= 1,
1915 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
1916 .show_host_symbolic_name
= 1,
1917 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
1918 .show_host_system_hostname
= 1,
1919 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
1920 .show_host_fabric_name
= 1,
1921 .get_host_port_state
= qla2x00_get_host_port_state
,
1922 .show_host_port_state
= 1,
1924 .dd_fcrport_size
= sizeof(struct fc_port
*),
1925 .show_rport_supported_classes
= 1,
1927 .get_starget_node_name
= qla2x00_get_starget_node_name
,
1928 .show_starget_node_name
= 1,
1929 .get_starget_port_name
= qla2x00_get_starget_port_name
,
1930 .show_starget_port_name
= 1,
1931 .get_starget_port_id
= qla2x00_get_starget_port_id
,
1932 .show_starget_port_id
= 1,
1934 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
1935 .show_rport_dev_loss_tmo
= 1,
1937 .issue_fc_host_lip
= qla2x00_issue_lip
,
1938 .dev_loss_tmo_callbk
= qla2x00_dev_loss_tmo_callbk
,
1939 .terminate_rport_io
= qla2x00_terminate_rport_io
,
1940 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
1941 .bsg_request
= qla24xx_bsg_request
,
1942 .bsg_timeout
= qla24xx_bsg_timeout
,
1946 qla2x00_init_host_attr(scsi_qla_host_t
*vha
)
1948 struct qla_hw_data
*ha
= vha
->hw
;
1949 u32 speed
= FC_PORTSPEED_UNKNOWN
;
1951 fc_host_dev_loss_tmo(vha
->host
) = ha
->port_down_retry_count
;
1952 fc_host_node_name(vha
->host
) = wwn_to_u64(vha
->node_name
);
1953 fc_host_port_name(vha
->host
) = wwn_to_u64(vha
->port_name
);
1954 fc_host_supported_classes(vha
->host
) = FC_COS_CLASS3
;
1955 fc_host_max_npiv_vports(vha
->host
) = ha
->max_npiv_vports
;
1956 fc_host_npiv_vports_inuse(vha
->host
) = ha
->cur_vport_count
;
1958 if (IS_CNA_CAPABLE(ha
))
1959 speed
= FC_PORTSPEED_10GBIT
;
1960 else if (IS_QLA25XX(ha
))
1961 speed
= FC_PORTSPEED_8GBIT
| FC_PORTSPEED_4GBIT
|
1962 FC_PORTSPEED_2GBIT
| FC_PORTSPEED_1GBIT
;
1963 else if (IS_QLA24XX_TYPE(ha
))
1964 speed
= FC_PORTSPEED_4GBIT
| FC_PORTSPEED_2GBIT
|
1966 else if (IS_QLA23XX(ha
))
1967 speed
= FC_PORTSPEED_2GBIT
| FC_PORTSPEED_1GBIT
;
1969 speed
= FC_PORTSPEED_1GBIT
;
1970 fc_host_supported_speeds(vha
->host
) = speed
;