2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 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
== 0)
33 if (off
< ha
->md_template_size
) {
34 rval
= memory_read_from_buffer(buf
, count
,
35 &off
, ha
->md_tmplt_hdr
, ha
->md_template_size
);
38 off
-= ha
->md_template_size
;
39 rval
= memory_read_from_buffer(buf
, count
,
40 &off
, ha
->md_dump
, ha
->md_dump_size
);
43 return memory_read_from_buffer(buf
, count
, &off
, ha
->fw_dump
,
48 qla2x00_sysfs_write_fw_dump(struct file
*filp
, struct kobject
*kobj
,
49 struct bin_attribute
*bin_attr
,
50 char *buf
, loff_t off
, size_t count
)
52 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
53 struct device
, kobj
)));
54 struct qla_hw_data
*ha
= vha
->hw
;
60 reading
= simple_strtol(buf
, NULL
, 10);
63 if (!ha
->fw_dump_reading
)
66 ql_log(ql_log_info
, vha
, 0x705d,
67 "Firmware dump cleared on (%ld).\n", vha
->host_no
);
69 if (IS_QLA82XX(vha
->hw
)) {
73 ha
->fw_dump_reading
= 0;
77 if (ha
->fw_dumped
&& !ha
->fw_dump_reading
) {
78 ha
->fw_dump_reading
= 1;
80 ql_log(ql_log_info
, vha
, 0x705e,
81 "Raw firmware dump ready for read on (%ld).\n",
86 qla2x00_alloc_fw_dump(vha
);
91 qla82xx_set_reset_owner(vha
);
92 qla82xx_idc_unlock(ha
);
94 qla2x00_system_error(vha
);
99 ql_dbg(ql_dbg_user
, vha
, 0x705b,
100 "MiniDump supported with this firmware.\n");
102 ql_dbg(ql_dbg_user
, vha
, 0x709d,
103 "MiniDump not supported with this firmware.\n");
108 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
114 static struct bin_attribute sysfs_fw_dump_attr
= {
117 .mode
= S_IRUSR
| S_IWUSR
,
120 .read
= qla2x00_sysfs_read_fw_dump
,
121 .write
= qla2x00_sysfs_write_fw_dump
,
125 qla2x00_sysfs_read_nvram(struct file
*filp
, struct kobject
*kobj
,
126 struct bin_attribute
*bin_attr
,
127 char *buf
, loff_t off
, size_t count
)
129 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
130 struct device
, kobj
)));
131 struct qla_hw_data
*ha
= vha
->hw
;
133 if (!capable(CAP_SYS_ADMIN
))
136 if (IS_NOCACHE_VPD_TYPE(ha
))
137 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
139 return memory_read_from_buffer(buf
, count
, &off
, ha
->nvram
,
144 qla2x00_sysfs_write_nvram(struct file
*filp
, struct kobject
*kobj
,
145 struct bin_attribute
*bin_attr
,
146 char *buf
, loff_t off
, size_t count
)
148 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
149 struct device
, kobj
)));
150 struct qla_hw_data
*ha
= vha
->hw
;
153 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->nvram_size
||
154 !ha
->isp_ops
->write_nvram
)
157 /* Checksum NVRAM. */
158 if (IS_FWI2_CAPABLE(ha
)) {
162 iter
= (uint32_t *)buf
;
164 for (cnt
= 0; cnt
< ((count
>> 2) - 1); cnt
++)
165 chksum
+= le32_to_cpu(*iter
++);
166 chksum
= ~chksum
+ 1;
167 *iter
= cpu_to_le32(chksum
);
172 iter
= (uint8_t *)buf
;
174 for (cnt
= 0; cnt
< count
- 1; cnt
++)
176 chksum
= ~chksum
+ 1;
180 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
181 ql_log(ql_log_warn
, vha
, 0x705f,
182 "HBA not online, failing NVRAM update.\n");
187 ha
->isp_ops
->write_nvram(vha
, (uint8_t *)buf
, ha
->nvram_base
, count
);
188 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->nvram
, ha
->nvram_base
,
191 ql_dbg(ql_dbg_user
, vha
, 0x7060,
192 "Setting ISP_ABORT_NEEDED\n");
193 /* NVRAM settings take effect immediately. */
194 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
195 qla2xxx_wake_dpc(vha
);
196 qla2x00_wait_for_chip_reset(vha
);
201 static struct bin_attribute sysfs_nvram_attr
= {
204 .mode
= S_IRUSR
| S_IWUSR
,
207 .read
= qla2x00_sysfs_read_nvram
,
208 .write
= qla2x00_sysfs_write_nvram
,
212 qla2x00_sysfs_read_optrom(struct file
*filp
, struct kobject
*kobj
,
213 struct bin_attribute
*bin_attr
,
214 char *buf
, loff_t off
, size_t count
)
216 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
217 struct device
, kobj
)));
218 struct qla_hw_data
*ha
= vha
->hw
;
220 if (ha
->optrom_state
!= QLA_SREADING
)
223 return memory_read_from_buffer(buf
, count
, &off
, ha
->optrom_buffer
,
224 ha
->optrom_region_size
);
228 qla2x00_sysfs_write_optrom(struct file
*filp
, struct kobject
*kobj
,
229 struct bin_attribute
*bin_attr
,
230 char *buf
, loff_t off
, size_t count
)
232 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
233 struct device
, kobj
)));
234 struct qla_hw_data
*ha
= vha
->hw
;
236 if (ha
->optrom_state
!= QLA_SWRITING
)
238 if (off
> ha
->optrom_region_size
)
240 if (off
+ count
> ha
->optrom_region_size
)
241 count
= ha
->optrom_region_size
- off
;
243 memcpy(&ha
->optrom_buffer
[off
], buf
, count
);
248 static struct bin_attribute sysfs_optrom_attr
= {
251 .mode
= S_IRUSR
| S_IWUSR
,
254 .read
= qla2x00_sysfs_read_optrom
,
255 .write
= qla2x00_sysfs_write_optrom
,
259 qla2x00_sysfs_write_optrom_ctl(struct file
*filp
, struct kobject
*kobj
,
260 struct bin_attribute
*bin_attr
,
261 char *buf
, loff_t off
, size_t count
)
263 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
264 struct device
, kobj
)));
265 struct qla_hw_data
*ha
= vha
->hw
;
268 uint32_t size
= ha
->optrom_size
;
274 if (unlikely(pci_channel_offline(ha
->pdev
)))
277 if (sscanf(buf
, "%d:%x:%x", &val
, &start
, &size
) < 1)
279 if (start
> ha
->optrom_size
)
284 if (ha
->optrom_state
!= QLA_SREADING
&&
285 ha
->optrom_state
!= QLA_SWRITING
)
288 ha
->optrom_state
= QLA_SWAITING
;
290 ql_dbg(ql_dbg_user
, vha
, 0x7061,
291 "Freeing flash region allocation -- 0x%x bytes.\n",
292 ha
->optrom_region_size
);
294 vfree(ha
->optrom_buffer
);
295 ha
->optrom_buffer
= NULL
;
298 if (ha
->optrom_state
!= QLA_SWAITING
)
301 ha
->optrom_region_start
= start
;
302 ha
->optrom_region_size
= start
+ size
> ha
->optrom_size
?
303 ha
->optrom_size
- start
: size
;
305 ha
->optrom_state
= QLA_SREADING
;
306 ha
->optrom_buffer
= vmalloc(ha
->optrom_region_size
);
307 if (ha
->optrom_buffer
== NULL
) {
308 ql_log(ql_log_warn
, vha
, 0x7062,
309 "Unable to allocate memory for optrom retrieval "
310 "(%x).\n", ha
->optrom_region_size
);
312 ha
->optrom_state
= QLA_SWAITING
;
316 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
317 ql_log(ql_log_warn
, vha
, 0x7063,
318 "HBA not online, failing NVRAM update.\n");
322 ql_dbg(ql_dbg_user
, vha
, 0x7064,
323 "Reading flash region -- 0x%x/0x%x.\n",
324 ha
->optrom_region_start
, ha
->optrom_region_size
);
326 memset(ha
->optrom_buffer
, 0, ha
->optrom_region_size
);
327 ha
->isp_ops
->read_optrom(vha
, ha
->optrom_buffer
,
328 ha
->optrom_region_start
, ha
->optrom_region_size
);
331 if (ha
->optrom_state
!= QLA_SWAITING
)
335 * We need to be more restrictive on which FLASH regions are
336 * allowed to be updated via user-space. Regions accessible
337 * via this method include:
339 * ISP21xx/ISP22xx/ISP23xx type boards:
341 * 0x000000 -> 0x020000 -- Boot code.
343 * ISP2322/ISP24xx type boards:
345 * 0x000000 -> 0x07ffff -- Boot code.
346 * 0x080000 -> 0x0fffff -- Firmware.
348 * ISP25xx type boards:
350 * 0x000000 -> 0x07ffff -- Boot code.
351 * 0x080000 -> 0x0fffff -- Firmware.
352 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
355 if (ha
->optrom_size
== OPTROM_SIZE_2300
&& start
== 0)
357 else if (start
== (ha
->flt_region_boot
* 4) ||
358 start
== (ha
->flt_region_fw
* 4))
360 else if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
)
361 || IS_CNA_CAPABLE(ha
) || IS_QLA2031(ha
))
364 ql_log(ql_log_warn
, vha
, 0x7065,
365 "Invalid start region 0x%x/0x%x.\n", start
, size
);
369 ha
->optrom_region_start
= start
;
370 ha
->optrom_region_size
= start
+ size
> ha
->optrom_size
?
371 ha
->optrom_size
- start
: size
;
373 ha
->optrom_state
= QLA_SWRITING
;
374 ha
->optrom_buffer
= vmalloc(ha
->optrom_region_size
);
375 if (ha
->optrom_buffer
== NULL
) {
376 ql_log(ql_log_warn
, vha
, 0x7066,
377 "Unable to allocate memory for optrom update "
378 "(%x)\n", ha
->optrom_region_size
);
380 ha
->optrom_state
= QLA_SWAITING
;
384 ql_dbg(ql_dbg_user
, vha
, 0x7067,
385 "Staging flash region write -- 0x%x/0x%x.\n",
386 ha
->optrom_region_start
, ha
->optrom_region_size
);
388 memset(ha
->optrom_buffer
, 0, ha
->optrom_region_size
);
391 if (ha
->optrom_state
!= QLA_SWRITING
)
394 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
395 ql_log(ql_log_warn
, vha
, 0x7068,
396 "HBA not online, failing flash update.\n");
400 ql_dbg(ql_dbg_user
, vha
, 0x7069,
401 "Writing flash region -- 0x%x/0x%x.\n",
402 ha
->optrom_region_start
, ha
->optrom_region_size
);
404 ha
->isp_ops
->write_optrom(vha
, ha
->optrom_buffer
,
405 ha
->optrom_region_start
, ha
->optrom_region_size
);
413 static struct bin_attribute sysfs_optrom_ctl_attr
= {
415 .name
= "optrom_ctl",
419 .write
= qla2x00_sysfs_write_optrom_ctl
,
423 qla2x00_sysfs_read_vpd(struct file
*filp
, struct kobject
*kobj
,
424 struct bin_attribute
*bin_attr
,
425 char *buf
, loff_t off
, size_t count
)
427 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
428 struct device
, kobj
)));
429 struct qla_hw_data
*ha
= vha
->hw
;
431 if (unlikely(pci_channel_offline(ha
->pdev
)))
434 if (!capable(CAP_SYS_ADMIN
))
437 if (IS_NOCACHE_VPD_TYPE(ha
))
438 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
440 return memory_read_from_buffer(buf
, count
, &off
, ha
->vpd
, ha
->vpd_size
);
444 qla2x00_sysfs_write_vpd(struct file
*filp
, struct kobject
*kobj
,
445 struct bin_attribute
*bin_attr
,
446 char *buf
, loff_t off
, size_t count
)
448 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
449 struct device
, kobj
)));
450 struct qla_hw_data
*ha
= vha
->hw
;
453 if (unlikely(pci_channel_offline(ha
->pdev
)))
456 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->vpd_size
||
457 !ha
->isp_ops
->write_nvram
)
460 if (qla2x00_wait_for_hba_online(vha
) != QLA_SUCCESS
) {
461 ql_log(ql_log_warn
, vha
, 0x706a,
462 "HBA not online, failing VPD update.\n");
467 ha
->isp_ops
->write_nvram(vha
, (uint8_t *)buf
, ha
->vpd_base
, count
);
468 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
, ha
->vpd_base
, count
);
470 /* Update flash version information for 4Gb & above. */
471 if (!IS_FWI2_CAPABLE(ha
))
474 tmp_data
= vmalloc(256);
476 ql_log(ql_log_warn
, vha
, 0x706b,
477 "Unable to allocate memory for VPD information update.\n");
480 ha
->isp_ops
->get_flash_version(vha
, tmp_data
);
486 static struct bin_attribute sysfs_vpd_attr
= {
489 .mode
= S_IRUSR
| S_IWUSR
,
492 .read
= qla2x00_sysfs_read_vpd
,
493 .write
= qla2x00_sysfs_write_vpd
,
497 qla2x00_sysfs_read_sfp(struct file
*filp
, struct kobject
*kobj
,
498 struct bin_attribute
*bin_attr
,
499 char *buf
, loff_t off
, size_t count
)
501 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
502 struct device
, kobj
)));
503 struct qla_hw_data
*ha
= vha
->hw
;
504 uint16_t iter
, addr
, offset
;
507 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= SFP_DEV_SIZE
* 2)
513 ha
->sfp_data
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
516 ql_log(ql_log_warn
, vha
, 0x706c,
517 "Unable to allocate memory for SFP read-data.\n");
522 memset(ha
->sfp_data
, 0, SFP_BLOCK_SIZE
);
524 for (iter
= 0, offset
= 0; iter
< (SFP_DEV_SIZE
* 2) / SFP_BLOCK_SIZE
;
525 iter
++, offset
+= SFP_BLOCK_SIZE
) {
527 /* Skip to next device address. */
532 rval
= qla2x00_read_sfp(vha
, ha
->sfp_data_dma
, ha
->sfp_data
,
533 addr
, offset
, SFP_BLOCK_SIZE
, 0);
534 if (rval
!= QLA_SUCCESS
) {
535 ql_log(ql_log_warn
, vha
, 0x706d,
536 "Unable to read SFP data (%x/%x/%x).\n", rval
,
541 memcpy(buf
, ha
->sfp_data
, SFP_BLOCK_SIZE
);
542 buf
+= SFP_BLOCK_SIZE
;
548 static struct bin_attribute sysfs_sfp_attr
= {
551 .mode
= S_IRUSR
| S_IWUSR
,
553 .size
= SFP_DEV_SIZE
* 2,
554 .read
= qla2x00_sysfs_read_sfp
,
558 qla2x00_sysfs_write_reset(struct file
*filp
, struct kobject
*kobj
,
559 struct bin_attribute
*bin_attr
,
560 char *buf
, loff_t off
, size_t count
)
562 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
563 struct device
, kobj
)));
564 struct qla_hw_data
*ha
= vha
->hw
;
565 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
571 type
= simple_strtol(buf
, NULL
, 10);
574 ql_log(ql_log_info
, vha
, 0x706e,
575 "Issuing ISP reset.\n");
577 scsi_block_requests(vha
->host
);
578 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
579 if (IS_QLA82XX(ha
)) {
580 ha
->flags
.isp82xx_no_md_cap
= 1;
581 qla82xx_idc_lock(ha
);
582 qla82xx_set_reset_owner(vha
);
583 qla82xx_idc_unlock(ha
);
585 qla2xxx_wake_dpc(vha
);
586 qla2x00_wait_for_chip_reset(vha
);
587 scsi_unblock_requests(vha
->host
);
590 if (!IS_QLA81XX(ha
) || !IS_QLA8031(ha
))
593 ql_log(ql_log_info
, vha
, 0x706f,
594 "Issuing MPI reset.\n");
596 /* Make sure FC side is not in reset */
597 qla2x00_wait_for_hba_online(vha
);
599 /* Issue MPI reset */
600 scsi_block_requests(vha
->host
);
601 if (qla81xx_restart_mpi_firmware(vha
) != QLA_SUCCESS
)
602 ql_log(ql_log_warn
, vha
, 0x7070,
603 "MPI reset failed.\n");
604 scsi_unblock_requests(vha
->host
);
607 if (!IS_QLA82XX(ha
) || vha
!= base_vha
) {
608 ql_log(ql_log_info
, vha
, 0x7071,
609 "FCoE ctx reset no supported.\n");
613 ql_log(ql_log_info
, vha
, 0x7072,
614 "Issuing FCoE ctx reset.\n");
615 set_bit(FCOE_CTX_RESET_NEEDED
, &vha
->dpc_flags
);
616 qla2xxx_wake_dpc(vha
);
617 qla2x00_wait_for_fcoe_ctx_reset(vha
);
623 static struct bin_attribute sysfs_reset_attr
= {
629 .write
= qla2x00_sysfs_write_reset
,
633 qla2x00_sysfs_read_xgmac_stats(struct file
*filp
, struct kobject
*kobj
,
634 struct bin_attribute
*bin_attr
,
635 char *buf
, loff_t off
, size_t count
)
637 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
638 struct device
, kobj
)));
639 struct qla_hw_data
*ha
= vha
->hw
;
641 uint16_t actual_size
;
643 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
> XGMAC_DATA_SIZE
)
649 ha
->xgmac_data
= dma_alloc_coherent(&ha
->pdev
->dev
, XGMAC_DATA_SIZE
,
650 &ha
->xgmac_data_dma
, GFP_KERNEL
);
651 if (!ha
->xgmac_data
) {
652 ql_log(ql_log_warn
, vha
, 0x7076,
653 "Unable to allocate memory for XGMAC read-data.\n");
659 memset(ha
->xgmac_data
, 0, XGMAC_DATA_SIZE
);
661 rval
= qla2x00_get_xgmac_stats(vha
, ha
->xgmac_data_dma
,
662 XGMAC_DATA_SIZE
, &actual_size
);
663 if (rval
!= QLA_SUCCESS
) {
664 ql_log(ql_log_warn
, vha
, 0x7077,
665 "Unable to read XGMAC data (%x).\n", rval
);
669 count
= actual_size
> count
? count
: actual_size
;
670 memcpy(buf
, ha
->xgmac_data
, count
);
675 static struct bin_attribute sysfs_xgmac_stats_attr
= {
677 .name
= "xgmac_stats",
681 .read
= qla2x00_sysfs_read_xgmac_stats
,
685 qla2x00_sysfs_read_dcbx_tlv(struct file
*filp
, struct kobject
*kobj
,
686 struct bin_attribute
*bin_attr
,
687 char *buf
, loff_t off
, size_t count
)
689 struct scsi_qla_host
*vha
= shost_priv(dev_to_shost(container_of(kobj
,
690 struct device
, kobj
)));
691 struct qla_hw_data
*ha
= vha
->hw
;
693 uint16_t actual_size
;
695 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
> DCBX_TLV_DATA_SIZE
)
701 ha
->dcbx_tlv
= dma_alloc_coherent(&ha
->pdev
->dev
, DCBX_TLV_DATA_SIZE
,
702 &ha
->dcbx_tlv_dma
, GFP_KERNEL
);
704 ql_log(ql_log_warn
, vha
, 0x7078,
705 "Unable to allocate memory for DCBX TLV read-data.\n");
711 memset(ha
->dcbx_tlv
, 0, DCBX_TLV_DATA_SIZE
);
713 rval
= qla2x00_get_dcbx_params(vha
, ha
->dcbx_tlv_dma
,
715 if (rval
!= QLA_SUCCESS
) {
716 ql_log(ql_log_warn
, vha
, 0x7079,
717 "Unable to read DCBX TLV (%x).\n", rval
);
721 memcpy(buf
, ha
->dcbx_tlv
, count
);
726 static struct bin_attribute sysfs_dcbx_tlv_attr
= {
732 .read
= qla2x00_sysfs_read_dcbx_tlv
,
735 static struct sysfs_entry
{
737 struct bin_attribute
*attr
;
739 } bin_file_entries
[] = {
740 { "fw_dump", &sysfs_fw_dump_attr
, },
741 { "nvram", &sysfs_nvram_attr
, },
742 { "optrom", &sysfs_optrom_attr
, },
743 { "optrom_ctl", &sysfs_optrom_ctl_attr
, },
744 { "vpd", &sysfs_vpd_attr
, 1 },
745 { "sfp", &sysfs_sfp_attr
, 1 },
746 { "reset", &sysfs_reset_attr
, },
747 { "xgmac_stats", &sysfs_xgmac_stats_attr
, 3 },
748 { "dcbx_tlv", &sysfs_dcbx_tlv_attr
, 3 },
753 qla2x00_alloc_sysfs_attr(scsi_qla_host_t
*vha
)
755 struct Scsi_Host
*host
= vha
->host
;
756 struct sysfs_entry
*iter
;
759 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
760 if (iter
->is4GBp_only
&& !IS_FWI2_CAPABLE(vha
->hw
))
762 if (iter
->is4GBp_only
== 2 && !IS_QLA25XX(vha
->hw
))
764 if (iter
->is4GBp_only
== 3 && !(IS_CNA_CAPABLE(vha
->hw
)))
767 ret
= sysfs_create_bin_file(&host
->shost_gendev
.kobj
,
770 ql_log(ql_log_warn
, vha
, 0x00f3,
771 "Unable to create sysfs %s binary attribute (%d).\n",
774 ql_dbg(ql_dbg_init
, vha
, 0x00f4,
775 "Successfully created sysfs %s binary attribure.\n",
781 qla2x00_free_sysfs_attr(scsi_qla_host_t
*vha
)
783 struct Scsi_Host
*host
= vha
->host
;
784 struct sysfs_entry
*iter
;
785 struct qla_hw_data
*ha
= vha
->hw
;
787 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
788 if (iter
->is4GBp_only
&& !IS_FWI2_CAPABLE(ha
))
790 if (iter
->is4GBp_only
== 2 && !IS_QLA25XX(ha
))
792 if (iter
->is4GBp_only
== 3 && !(IS_CNA_CAPABLE(vha
->hw
)))
795 sysfs_remove_bin_file(&host
->shost_gendev
.kobj
,
799 if (ha
->beacon_blink_led
== 1)
800 ha
->isp_ops
->beacon_off(vha
);
803 /* Scsi_Host attributes. */
806 qla2x00_drvr_version_show(struct device
*dev
,
807 struct device_attribute
*attr
, char *buf
)
809 return snprintf(buf
, PAGE_SIZE
, "%s\n", qla2x00_version_str
);
813 qla2x00_fw_version_show(struct device
*dev
,
814 struct device_attribute
*attr
, char *buf
)
816 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
817 struct qla_hw_data
*ha
= vha
->hw
;
820 return snprintf(buf
, PAGE_SIZE
, "%s\n",
821 ha
->isp_ops
->fw_version_str(vha
, fw_str
));
825 qla2x00_serial_num_show(struct device
*dev
, struct device_attribute
*attr
,
828 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
829 struct qla_hw_data
*ha
= vha
->hw
;
832 if (IS_FWI2_CAPABLE(ha
)) {
833 qla2xxx_get_vpd_field(vha
, "SN", buf
, PAGE_SIZE
);
834 return snprintf(buf
, PAGE_SIZE
, "%s\n", buf
);
837 sn
= ((ha
->serial0
& 0x1f) << 16) | (ha
->serial2
<< 8) | ha
->serial1
;
838 return snprintf(buf
, PAGE_SIZE
, "%c%05d\n", 'A' + sn
/ 100000,
843 qla2x00_isp_name_show(struct device
*dev
, struct device_attribute
*attr
,
846 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
847 return snprintf(buf
, PAGE_SIZE
, "ISP%04X\n", vha
->hw
->pdev
->device
);
851 qla2x00_isp_id_show(struct device
*dev
, struct device_attribute
*attr
,
854 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
855 struct qla_hw_data
*ha
= vha
->hw
;
856 return snprintf(buf
, PAGE_SIZE
, "%04x %04x %04x %04x\n",
857 ha
->product_id
[0], ha
->product_id
[1], ha
->product_id
[2],
862 qla2x00_model_name_show(struct device
*dev
, struct device_attribute
*attr
,
865 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
866 return snprintf(buf
, PAGE_SIZE
, "%s\n", vha
->hw
->model_number
);
870 qla2x00_model_desc_show(struct device
*dev
, struct device_attribute
*attr
,
873 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
874 return snprintf(buf
, PAGE_SIZE
, "%s\n",
875 vha
->hw
->model_desc
? vha
->hw
->model_desc
: "");
879 qla2x00_pci_info_show(struct device
*dev
, struct device_attribute
*attr
,
882 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
885 return snprintf(buf
, PAGE_SIZE
, "%s\n",
886 vha
->hw
->isp_ops
->pci_info_str(vha
, pci_info
));
890 qla2x00_link_state_show(struct device
*dev
, struct device_attribute
*attr
,
893 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
894 struct qla_hw_data
*ha
= vha
->hw
;
897 if (atomic_read(&vha
->loop_state
) == LOOP_DOWN
||
898 atomic_read(&vha
->loop_state
) == LOOP_DEAD
||
899 vha
->device_flags
& DFLG_NO_CABLE
)
900 len
= snprintf(buf
, PAGE_SIZE
, "Link Down\n");
901 else if (atomic_read(&vha
->loop_state
) != LOOP_READY
||
902 qla2x00_reset_active(vha
))
903 len
= snprintf(buf
, PAGE_SIZE
, "Unknown Link State\n");
905 len
= snprintf(buf
, PAGE_SIZE
, "Link Up - ");
907 switch (ha
->current_topology
) {
909 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
912 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "FL_Port\n");
915 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
916 "N_Port to N_Port\n");
919 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "F_Port\n");
922 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
930 qla2x00_zio_show(struct device
*dev
, struct device_attribute
*attr
,
933 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
936 switch (vha
->hw
->zio_mode
) {
938 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Mode 6\n");
940 case QLA_ZIO_DISABLED
:
941 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
948 qla2x00_zio_store(struct device
*dev
, struct device_attribute
*attr
,
949 const char *buf
, size_t count
)
951 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
952 struct qla_hw_data
*ha
= vha
->hw
;
956 if (!IS_ZIO_SUPPORTED(ha
))
959 if (sscanf(buf
, "%d", &val
) != 1)
963 zio_mode
= QLA_ZIO_MODE_6
;
965 zio_mode
= QLA_ZIO_DISABLED
;
967 /* Update per-hba values and queue a reset. */
968 if (zio_mode
!= QLA_ZIO_DISABLED
|| ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
969 ha
->zio_mode
= zio_mode
;
970 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
976 qla2x00_zio_timer_show(struct device
*dev
, struct device_attribute
*attr
,
979 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
981 return snprintf(buf
, PAGE_SIZE
, "%d us\n", vha
->hw
->zio_timer
* 100);
985 qla2x00_zio_timer_store(struct device
*dev
, struct device_attribute
*attr
,
986 const char *buf
, size_t count
)
988 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
992 if (sscanf(buf
, "%d", &val
) != 1)
994 if (val
> 25500 || val
< 100)
997 zio_timer
= (uint16_t)(val
/ 100);
998 vha
->hw
->zio_timer
= zio_timer
;
1004 qla2x00_beacon_show(struct device
*dev
, struct device_attribute
*attr
,
1007 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1010 if (vha
->hw
->beacon_blink_led
)
1011 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Enabled\n");
1013 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
1018 qla2x00_beacon_store(struct device
*dev
, struct device_attribute
*attr
,
1019 const char *buf
, size_t count
)
1021 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1022 struct qla_hw_data
*ha
= vha
->hw
;
1026 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1029 if (test_bit(ABORT_ISP_ACTIVE
, &vha
->dpc_flags
)) {
1030 ql_log(ql_log_warn
, vha
, 0x707a,
1031 "Abort ISP active -- ignoring beacon request.\n");
1035 if (sscanf(buf
, "%d", &val
) != 1)
1039 rval
= ha
->isp_ops
->beacon_on(vha
);
1041 rval
= ha
->isp_ops
->beacon_off(vha
);
1043 if (rval
!= QLA_SUCCESS
)
1050 qla2x00_optrom_bios_version_show(struct device
*dev
,
1051 struct device_attribute
*attr
, char *buf
)
1053 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1054 struct qla_hw_data
*ha
= vha
->hw
;
1055 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->bios_revision
[1],
1056 ha
->bios_revision
[0]);
1060 qla2x00_optrom_efi_version_show(struct device
*dev
,
1061 struct device_attribute
*attr
, char *buf
)
1063 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1064 struct qla_hw_data
*ha
= vha
->hw
;
1065 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->efi_revision
[1],
1066 ha
->efi_revision
[0]);
1070 qla2x00_optrom_fcode_version_show(struct device
*dev
,
1071 struct device_attribute
*attr
, char *buf
)
1073 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1074 struct qla_hw_data
*ha
= vha
->hw
;
1075 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->fcode_revision
[1],
1076 ha
->fcode_revision
[0]);
1080 qla2x00_optrom_fw_version_show(struct device
*dev
,
1081 struct device_attribute
*attr
, char *buf
)
1083 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1084 struct qla_hw_data
*ha
= vha
->hw
;
1085 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d %d\n",
1086 ha
->fw_revision
[0], ha
->fw_revision
[1], ha
->fw_revision
[2],
1087 ha
->fw_revision
[3]);
1091 qla2x00_optrom_gold_fw_version_show(struct device
*dev
,
1092 struct device_attribute
*attr
, char *buf
)
1094 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1095 struct qla_hw_data
*ha
= vha
->hw
;
1097 if (!IS_QLA81XX(ha
) && !IS_QLA83XX(ha
))
1098 return snprintf(buf
, PAGE_SIZE
, "\n");
1100 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d (%d)\n",
1101 ha
->gold_fw_version
[0], ha
->gold_fw_version
[1],
1102 ha
->gold_fw_version
[2], ha
->gold_fw_version
[3]);
1106 qla2x00_total_isp_aborts_show(struct device
*dev
,
1107 struct device_attribute
*attr
, char *buf
)
1109 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1110 return snprintf(buf
, PAGE_SIZE
, "%d\n",
1111 vha
->qla_stats
.total_isp_aborts
);
1115 qla24xx_84xx_fw_version_show(struct device
*dev
,
1116 struct device_attribute
*attr
, char *buf
)
1118 int rval
= QLA_SUCCESS
;
1119 uint16_t status
[2] = {0, 0};
1120 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1121 struct qla_hw_data
*ha
= vha
->hw
;
1123 if (!IS_QLA84XX(ha
))
1124 return snprintf(buf
, PAGE_SIZE
, "\n");
1126 if (ha
->cs84xx
->op_fw_version
== 0)
1127 rval
= qla84xx_verify_chip(vha
, status
);
1129 if ((rval
== QLA_SUCCESS
) && (status
[0] == 0))
1130 return snprintf(buf
, PAGE_SIZE
, "%u\n",
1131 (uint32_t)ha
->cs84xx
->op_fw_version
);
1133 return snprintf(buf
, PAGE_SIZE
, "\n");
1137 qla2x00_mpi_version_show(struct device
*dev
, struct device_attribute
*attr
,
1140 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1141 struct qla_hw_data
*ha
= vha
->hw
;
1143 if (!IS_QLA81XX(ha
) && !IS_QLA8031(ha
))
1144 return snprintf(buf
, PAGE_SIZE
, "\n");
1146 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d (%x)\n",
1147 ha
->mpi_version
[0], ha
->mpi_version
[1], ha
->mpi_version
[2],
1148 ha
->mpi_capabilities
);
1152 qla2x00_phy_version_show(struct device
*dev
, struct device_attribute
*attr
,
1155 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1156 struct qla_hw_data
*ha
= vha
->hw
;
1158 if (!IS_QLA81XX(ha
) && !IS_QLA8031(ha
))
1159 return snprintf(buf
, PAGE_SIZE
, "\n");
1161 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d\n",
1162 ha
->phy_version
[0], ha
->phy_version
[1], ha
->phy_version
[2]);
1166 qla2x00_flash_block_size_show(struct device
*dev
,
1167 struct device_attribute
*attr
, char *buf
)
1169 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1170 struct qla_hw_data
*ha
= vha
->hw
;
1172 return snprintf(buf
, PAGE_SIZE
, "0x%x\n", ha
->fdt_block_size
);
1176 qla2x00_vlan_id_show(struct device
*dev
, struct device_attribute
*attr
,
1179 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1181 if (!IS_CNA_CAPABLE(vha
->hw
))
1182 return snprintf(buf
, PAGE_SIZE
, "\n");
1184 return snprintf(buf
, PAGE_SIZE
, "%d\n", vha
->fcoe_vlan_id
);
1188 qla2x00_vn_port_mac_address_show(struct device
*dev
,
1189 struct device_attribute
*attr
, char *buf
)
1191 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1193 if (!IS_CNA_CAPABLE(vha
->hw
))
1194 return snprintf(buf
, PAGE_SIZE
, "\n");
1196 return snprintf(buf
, PAGE_SIZE
, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1197 vha
->fcoe_vn_port_mac
[5], vha
->fcoe_vn_port_mac
[4],
1198 vha
->fcoe_vn_port_mac
[3], vha
->fcoe_vn_port_mac
[2],
1199 vha
->fcoe_vn_port_mac
[1], vha
->fcoe_vn_port_mac
[0]);
1203 qla2x00_fabric_param_show(struct device
*dev
, struct device_attribute
*attr
,
1206 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1208 return snprintf(buf
, PAGE_SIZE
, "%d\n", vha
->hw
->switch_cap
);
1212 qla2x00_thermal_temp_show(struct device
*dev
,
1213 struct device_attribute
*attr
, char *buf
)
1215 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1216 int rval
= QLA_FUNCTION_FAILED
;
1217 uint16_t temp
, frac
;
1219 if (!vha
->hw
->flags
.thermal_supported
)
1220 return snprintf(buf
, PAGE_SIZE
, "\n");
1223 if (qla2x00_reset_active(vha
))
1224 ql_log(ql_log_warn
, vha
, 0x707b,
1225 "ISP reset active.\n");
1226 else if (!vha
->hw
->flags
.eeh_busy
)
1227 rval
= qla2x00_get_thermal_temp(vha
, &temp
, &frac
);
1228 if (rval
!= QLA_SUCCESS
)
1229 return snprintf(buf
, PAGE_SIZE
, "\n");
1231 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", temp
, frac
);
1235 qla2x00_fw_state_show(struct device
*dev
, struct device_attribute
*attr
,
1238 scsi_qla_host_t
*vha
= shost_priv(class_to_shost(dev
));
1239 int rval
= QLA_FUNCTION_FAILED
;
1242 if (qla2x00_reset_active(vha
))
1243 ql_log(ql_log_warn
, vha
, 0x707c,
1244 "ISP reset active.\n");
1245 else if (!vha
->hw
->flags
.eeh_busy
)
1246 rval
= qla2x00_get_firmware_state(vha
, state
);
1247 if (rval
!= QLA_SUCCESS
)
1248 memset(state
, -1, sizeof(state
));
1250 return snprintf(buf
, PAGE_SIZE
, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state
[0],
1251 state
[1], state
[2], state
[3], state
[4]);
1254 static DEVICE_ATTR(driver_version
, S_IRUGO
, qla2x00_drvr_version_show
, NULL
);
1255 static DEVICE_ATTR(fw_version
, S_IRUGO
, qla2x00_fw_version_show
, NULL
);
1256 static DEVICE_ATTR(serial_num
, S_IRUGO
, qla2x00_serial_num_show
, NULL
);
1257 static DEVICE_ATTR(isp_name
, S_IRUGO
, qla2x00_isp_name_show
, NULL
);
1258 static DEVICE_ATTR(isp_id
, S_IRUGO
, qla2x00_isp_id_show
, NULL
);
1259 static DEVICE_ATTR(model_name
, S_IRUGO
, qla2x00_model_name_show
, NULL
);
1260 static DEVICE_ATTR(model_desc
, S_IRUGO
, qla2x00_model_desc_show
, NULL
);
1261 static DEVICE_ATTR(pci_info
, S_IRUGO
, qla2x00_pci_info_show
, NULL
);
1262 static DEVICE_ATTR(link_state
, S_IRUGO
, qla2x00_link_state_show
, NULL
);
1263 static DEVICE_ATTR(zio
, S_IRUGO
| S_IWUSR
, qla2x00_zio_show
, qla2x00_zio_store
);
1264 static DEVICE_ATTR(zio_timer
, S_IRUGO
| S_IWUSR
, qla2x00_zio_timer_show
,
1265 qla2x00_zio_timer_store
);
1266 static DEVICE_ATTR(beacon
, S_IRUGO
| S_IWUSR
, qla2x00_beacon_show
,
1267 qla2x00_beacon_store
);
1268 static DEVICE_ATTR(optrom_bios_version
, S_IRUGO
,
1269 qla2x00_optrom_bios_version_show
, NULL
);
1270 static DEVICE_ATTR(optrom_efi_version
, S_IRUGO
,
1271 qla2x00_optrom_efi_version_show
, NULL
);
1272 static DEVICE_ATTR(optrom_fcode_version
, S_IRUGO
,
1273 qla2x00_optrom_fcode_version_show
, NULL
);
1274 static DEVICE_ATTR(optrom_fw_version
, S_IRUGO
, qla2x00_optrom_fw_version_show
,
1276 static DEVICE_ATTR(optrom_gold_fw_version
, S_IRUGO
,
1277 qla2x00_optrom_gold_fw_version_show
, NULL
);
1278 static DEVICE_ATTR(84xx_fw_version
, S_IRUGO
, qla24xx_84xx_fw_version_show
,
1280 static DEVICE_ATTR(total_isp_aborts
, S_IRUGO
, qla2x00_total_isp_aborts_show
,
1282 static DEVICE_ATTR(mpi_version
, S_IRUGO
, qla2x00_mpi_version_show
, NULL
);
1283 static DEVICE_ATTR(phy_version
, S_IRUGO
, qla2x00_phy_version_show
, NULL
);
1284 static DEVICE_ATTR(flash_block_size
, S_IRUGO
, qla2x00_flash_block_size_show
,
1286 static DEVICE_ATTR(vlan_id
, S_IRUGO
, qla2x00_vlan_id_show
, NULL
);
1287 static DEVICE_ATTR(vn_port_mac_address
, S_IRUGO
,
1288 qla2x00_vn_port_mac_address_show
, NULL
);
1289 static DEVICE_ATTR(fabric_param
, S_IRUGO
, qla2x00_fabric_param_show
, NULL
);
1290 static DEVICE_ATTR(fw_state
, S_IRUGO
, qla2x00_fw_state_show
, NULL
);
1291 static DEVICE_ATTR(thermal_temp
, S_IRUGO
, qla2x00_thermal_temp_show
, NULL
);
1293 struct device_attribute
*qla2x00_host_attrs
[] = {
1294 &dev_attr_driver_version
,
1295 &dev_attr_fw_version
,
1296 &dev_attr_serial_num
,
1299 &dev_attr_model_name
,
1300 &dev_attr_model_desc
,
1302 &dev_attr_link_state
,
1304 &dev_attr_zio_timer
,
1306 &dev_attr_optrom_bios_version
,
1307 &dev_attr_optrom_efi_version
,
1308 &dev_attr_optrom_fcode_version
,
1309 &dev_attr_optrom_fw_version
,
1310 &dev_attr_84xx_fw_version
,
1311 &dev_attr_total_isp_aborts
,
1312 &dev_attr_mpi_version
,
1313 &dev_attr_phy_version
,
1314 &dev_attr_flash_block_size
,
1316 &dev_attr_vn_port_mac_address
,
1317 &dev_attr_fabric_param
,
1319 &dev_attr_optrom_gold_fw_version
,
1320 &dev_attr_thermal_temp
,
1324 /* Host attributes. */
1327 qla2x00_get_host_port_id(struct Scsi_Host
*shost
)
1329 scsi_qla_host_t
*vha
= shost_priv(shost
);
1331 fc_host_port_id(shost
) = vha
->d_id
.b
.domain
<< 16 |
1332 vha
->d_id
.b
.area
<< 8 | vha
->d_id
.b
.al_pa
;
1336 qla2x00_get_host_speed(struct Scsi_Host
*shost
)
1338 struct qla_hw_data
*ha
= ((struct scsi_qla_host
*)
1339 (shost_priv(shost
)))->hw
;
1340 u32 speed
= FC_PORTSPEED_UNKNOWN
;
1342 switch (ha
->link_data_rate
) {
1343 case PORT_SPEED_1GB
:
1344 speed
= FC_PORTSPEED_1GBIT
;
1346 case PORT_SPEED_2GB
:
1347 speed
= FC_PORTSPEED_2GBIT
;
1349 case PORT_SPEED_4GB
:
1350 speed
= FC_PORTSPEED_4GBIT
;
1352 case PORT_SPEED_8GB
:
1353 speed
= FC_PORTSPEED_8GBIT
;
1355 case PORT_SPEED_10GB
:
1356 speed
= FC_PORTSPEED_10GBIT
;
1358 case PORT_SPEED_16GB
:
1359 speed
= FC_PORTSPEED_16GBIT
;
1362 fc_host_speed(shost
) = speed
;
1366 qla2x00_get_host_port_type(struct Scsi_Host
*shost
)
1368 scsi_qla_host_t
*vha
= shost_priv(shost
);
1369 uint32_t port_type
= FC_PORTTYPE_UNKNOWN
;
1372 fc_host_port_type(shost
) = FC_PORTTYPE_NPIV
;
1375 switch (vha
->hw
->current_topology
) {
1377 port_type
= FC_PORTTYPE_LPORT
;
1380 port_type
= FC_PORTTYPE_NLPORT
;
1383 port_type
= FC_PORTTYPE_PTP
;
1386 port_type
= FC_PORTTYPE_NPORT
;
1389 fc_host_port_type(shost
) = port_type
;
1393 qla2x00_get_starget_node_name(struct scsi_target
*starget
)
1395 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
1396 scsi_qla_host_t
*vha
= shost_priv(host
);
1400 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1401 if (fcport
->rport
&&
1402 starget
->id
== fcport
->rport
->scsi_target_id
) {
1403 node_name
= wwn_to_u64(fcport
->node_name
);
1408 fc_starget_node_name(starget
) = node_name
;
1412 qla2x00_get_starget_port_name(struct scsi_target
*starget
)
1414 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
1415 scsi_qla_host_t
*vha
= shost_priv(host
);
1419 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1420 if (fcport
->rport
&&
1421 starget
->id
== fcport
->rport
->scsi_target_id
) {
1422 port_name
= wwn_to_u64(fcport
->port_name
);
1427 fc_starget_port_name(starget
) = port_name
;
1431 qla2x00_get_starget_port_id(struct scsi_target
*starget
)
1433 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
1434 scsi_qla_host_t
*vha
= shost_priv(host
);
1436 uint32_t port_id
= ~0U;
1438 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
1439 if (fcport
->rport
&&
1440 starget
->id
== fcport
->rport
->scsi_target_id
) {
1441 port_id
= fcport
->d_id
.b
.domain
<< 16 |
1442 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
1447 fc_starget_port_id(starget
) = port_id
;
1451 qla2x00_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
1454 rport
->dev_loss_tmo
= timeout
;
1456 rport
->dev_loss_tmo
= 1;
1460 qla2x00_dev_loss_tmo_callbk(struct fc_rport
*rport
)
1462 struct Scsi_Host
*host
= rport_to_shost(rport
);
1463 fc_port_t
*fcport
= *(fc_port_t
**)rport
->dd_data
;
1464 unsigned long flags
;
1469 /* Now that the rport has been deleted, set the fcport state to
1471 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_DEAD
);
1474 * Transport has effectively 'deleted' the rport, clear
1475 * all local references.
1477 spin_lock_irqsave(host
->host_lock
, flags
);
1478 fcport
->rport
= fcport
->drport
= NULL
;
1479 *((fc_port_t
**)rport
->dd_data
) = NULL
;
1480 spin_unlock_irqrestore(host
->host_lock
, flags
);
1482 if (test_bit(ABORT_ISP_ACTIVE
, &fcport
->vha
->dpc_flags
))
1485 if (unlikely(pci_channel_offline(fcport
->vha
->hw
->pdev
))) {
1486 qla2x00_abort_all_cmds(fcport
->vha
, DID_NO_CONNECT
<< 16);
1492 qla2x00_terminate_rport_io(struct fc_rport
*rport
)
1494 fc_port_t
*fcport
= *(fc_port_t
**)rport
->dd_data
;
1499 if (test_bit(ABORT_ISP_ACTIVE
, &fcport
->vha
->dpc_flags
))
1502 if (unlikely(pci_channel_offline(fcport
->vha
->hw
->pdev
))) {
1503 qla2x00_abort_all_cmds(fcport
->vha
, DID_NO_CONNECT
<< 16);
1507 * At this point all fcport's software-states are cleared. Perform any
1508 * final cleanup of firmware resources (PCBs and XCBs).
1510 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
1511 !test_bit(UNLOADING
, &fcport
->vha
->dpc_flags
)) {
1512 if (IS_FWI2_CAPABLE(fcport
->vha
->hw
))
1513 fcport
->vha
->hw
->isp_ops
->fabric_logout(fcport
->vha
,
1514 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
1515 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
1517 qla2x00_port_logout(fcport
->vha
, fcport
);
1522 qla2x00_issue_lip(struct Scsi_Host
*shost
)
1524 scsi_qla_host_t
*vha
= shost_priv(shost
);
1526 qla2x00_loop_reset(vha
);
1530 static struct fc_host_statistics
*
1531 qla2x00_get_fc_host_stats(struct Scsi_Host
*shost
)
1533 scsi_qla_host_t
*vha
= shost_priv(shost
);
1534 struct qla_hw_data
*ha
= vha
->hw
;
1535 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
1537 struct link_statistics
*stats
;
1538 dma_addr_t stats_dma
;
1539 struct fc_host_statistics
*pfc_host_stat
;
1541 pfc_host_stat
= &vha
->fc_host_stat
;
1542 memset(pfc_host_stat
, -1, sizeof(struct fc_host_statistics
));
1544 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1547 if (unlikely(pci_channel_offline(ha
->pdev
)))
1550 stats
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
, &stats_dma
);
1551 if (stats
== NULL
) {
1552 ql_log(ql_log_warn
, vha
, 0x707d,
1553 "Failed to allocate memory for stats.\n");
1556 memset(stats
, 0, DMA_POOL_SIZE
);
1558 rval
= QLA_FUNCTION_FAILED
;
1559 if (IS_FWI2_CAPABLE(ha
)) {
1560 rval
= qla24xx_get_isp_stats(base_vha
, stats
, stats_dma
);
1561 } else if (atomic_read(&base_vha
->loop_state
) == LOOP_READY
&&
1562 !qla2x00_reset_active(vha
) && !ha
->dpc_active
) {
1563 /* Must be in a 'READY' state for statistics retrieval. */
1564 rval
= qla2x00_get_link_status(base_vha
, base_vha
->loop_id
,
1568 if (rval
!= QLA_SUCCESS
)
1571 pfc_host_stat
->link_failure_count
= stats
->link_fail_cnt
;
1572 pfc_host_stat
->loss_of_sync_count
= stats
->loss_sync_cnt
;
1573 pfc_host_stat
->loss_of_signal_count
= stats
->loss_sig_cnt
;
1574 pfc_host_stat
->prim_seq_protocol_err_count
= stats
->prim_seq_err_cnt
;
1575 pfc_host_stat
->invalid_tx_word_count
= stats
->inval_xmit_word_cnt
;
1576 pfc_host_stat
->invalid_crc_count
= stats
->inval_crc_cnt
;
1577 if (IS_FWI2_CAPABLE(ha
)) {
1578 pfc_host_stat
->lip_count
= stats
->lip_cnt
;
1579 pfc_host_stat
->tx_frames
= stats
->tx_frames
;
1580 pfc_host_stat
->rx_frames
= stats
->rx_frames
;
1581 pfc_host_stat
->dumped_frames
= stats
->dumped_frames
;
1582 pfc_host_stat
->nos_count
= stats
->nos_rcvd
;
1584 pfc_host_stat
->fcp_input_megabytes
= vha
->qla_stats
.input_bytes
>> 20;
1585 pfc_host_stat
->fcp_output_megabytes
= vha
->qla_stats
.output_bytes
>> 20;
1588 dma_pool_free(ha
->s_dma_pool
, stats
, stats_dma
);
1590 return pfc_host_stat
;
1594 qla2x00_get_host_symbolic_name(struct Scsi_Host
*shost
)
1596 scsi_qla_host_t
*vha
= shost_priv(shost
);
1598 qla2x00_get_sym_node_name(vha
, fc_host_symbolic_name(shost
));
1602 qla2x00_set_host_system_hostname(struct Scsi_Host
*shost
)
1604 scsi_qla_host_t
*vha
= shost_priv(shost
);
1606 set_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
);
1610 qla2x00_get_host_fabric_name(struct Scsi_Host
*shost
)
1612 scsi_qla_host_t
*vha
= shost_priv(shost
);
1613 uint8_t node_name
[WWN_SIZE
] = { 0xFF, 0xFF, 0xFF, 0xFF, \
1614 0xFF, 0xFF, 0xFF, 0xFF};
1615 u64 fabric_name
= wwn_to_u64(node_name
);
1617 if (vha
->device_flags
& SWITCH_FOUND
)
1618 fabric_name
= wwn_to_u64(vha
->fabric_node_name
);
1620 fc_host_fabric_name(shost
) = fabric_name
;
1624 qla2x00_get_host_port_state(struct Scsi_Host
*shost
)
1626 scsi_qla_host_t
*vha
= shost_priv(shost
);
1627 struct scsi_qla_host
*base_vha
= pci_get_drvdata(vha
->hw
->pdev
);
1629 if (!base_vha
->flags
.online
) {
1630 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
1634 switch (atomic_read(&base_vha
->loop_state
)) {
1636 fc_host_port_state(shost
) = FC_PORTSTATE_DIAGNOSTICS
;
1639 if (test_bit(LOOP_RESYNC_NEEDED
, &base_vha
->dpc_flags
))
1640 fc_host_port_state(shost
) = FC_PORTSTATE_DIAGNOSTICS
;
1642 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
1645 fc_host_port_state(shost
) = FC_PORTSTATE_LINKDOWN
;
1648 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
1651 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
1657 qla24xx_vport_create(struct fc_vport
*fc_vport
, bool disable
)
1661 scsi_qla_host_t
*base_vha
= shost_priv(fc_vport
->shost
);
1662 scsi_qla_host_t
*vha
= NULL
;
1663 struct qla_hw_data
*ha
= base_vha
->hw
;
1664 uint16_t options
= 0;
1666 struct req_que
*req
= ha
->req_q_map
[0];
1668 ret
= qla24xx_vport_create_req_sanity_check(fc_vport
);
1670 ql_log(ql_log_warn
, vha
, 0x707e,
1671 "Vport sanity check failed, status %x\n", ret
);
1675 vha
= qla24xx_create_vhost(fc_vport
);
1677 ql_log(ql_log_warn
, vha
, 0x707f, "Vport create host failed.\n");
1678 return FC_VPORT_FAILED
;
1681 atomic_set(&vha
->vp_state
, VP_OFFLINE
);
1682 fc_vport_set_state(fc_vport
, FC_VPORT_DISABLED
);
1684 atomic_set(&vha
->vp_state
, VP_FAILED
);
1686 /* ready to create vport */
1687 ql_log(ql_log_info
, vha
, 0x7080,
1688 "VP entry id %d assigned.\n", vha
->vp_idx
);
1690 /* initialized vport states */
1691 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1692 vha
->vp_err_state
= VP_ERR_PORTDWN
;
1693 vha
->vp_prev_err_state
= VP_ERR_UNKWN
;
1694 /* Check if physical ha port is Up */
1695 if (atomic_read(&base_vha
->loop_state
) == LOOP_DOWN
||
1696 atomic_read(&base_vha
->loop_state
) == LOOP_DEAD
) {
1697 /* Don't retry or attempt login of this virtual port */
1698 ql_dbg(ql_dbg_user
, vha
, 0x7081,
1699 "Vport loop state is not UP.\n");
1700 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
1702 fc_vport_set_state(fc_vport
, FC_VPORT_LINKDOWN
);
1705 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
1706 if (ha
->fw_attributes
& BIT_4
) {
1708 vha
->flags
.difdix_supported
= 1;
1709 ql_dbg(ql_dbg_user
, vha
, 0x7082,
1710 "Registered for DIF/DIX type 1 and 3 protection.\n");
1711 if (ql2xenabledif
== 1)
1712 prot
= SHOST_DIX_TYPE0_PROTECTION
;
1713 scsi_host_set_prot(vha
->host
,
1714 prot
| SHOST_DIF_TYPE1_PROTECTION
1715 | SHOST_DIF_TYPE2_PROTECTION
1716 | SHOST_DIF_TYPE3_PROTECTION
1717 | SHOST_DIX_TYPE1_PROTECTION
1718 | SHOST_DIX_TYPE2_PROTECTION
1719 | SHOST_DIX_TYPE3_PROTECTION
);
1720 scsi_host_set_guard(vha
->host
, SHOST_DIX_GUARD_CRC
);
1722 vha
->flags
.difdix_supported
= 0;
1725 if (scsi_add_host_with_dma(vha
->host
, &fc_vport
->dev
,
1727 ql_dbg(ql_dbg_user
, vha
, 0x7083,
1728 "scsi_add_host failure for VP[%d].\n", vha
->vp_idx
);
1729 goto vport_create_failed_2
;
1732 /* initialize attributes */
1733 fc_host_dev_loss_tmo(vha
->host
) = ha
->port_down_retry_count
;
1734 fc_host_node_name(vha
->host
) = wwn_to_u64(vha
->node_name
);
1735 fc_host_port_name(vha
->host
) = wwn_to_u64(vha
->port_name
);
1736 fc_host_supported_classes(vha
->host
) =
1737 fc_host_supported_classes(base_vha
->host
);
1738 fc_host_supported_speeds(vha
->host
) =
1739 fc_host_supported_speeds(base_vha
->host
);
1741 qlt_vport_create(vha
, ha
);
1742 qla24xx_vport_disable(fc_vport
, disable
);
1744 if (ha
->flags
.cpu_affinity_enabled
) {
1745 req
= ha
->req_q_map
[1];
1746 ql_dbg(ql_dbg_multiq
, vha
, 0xc000,
1747 "Request queue %p attached with "
1748 "VP[%d], cpu affinity =%d\n",
1749 req
, vha
->vp_idx
, ha
->flags
.cpu_affinity_enabled
);
1751 } else if (ql2xmaxqueues
== 1 || !ha
->npiv_info
)
1753 /* Create a request queue in QoS mode for the vport */
1754 for (cnt
= 0; cnt
< ha
->nvram_npiv_size
; cnt
++) {
1755 if (memcmp(ha
->npiv_info
[cnt
].port_name
, vha
->port_name
, 8) == 0
1756 && memcmp(ha
->npiv_info
[cnt
].node_name
, vha
->node_name
,
1758 qos
= ha
->npiv_info
[cnt
].q_qos
;
1764 ret
= qla25xx_create_req_que(ha
, options
, vha
->vp_idx
, 0, 0,
1767 ql_log(ql_log_warn
, vha
, 0x7084,
1768 "Can't create request queue for VP[%d]\n",
1771 ql_dbg(ql_dbg_multiq
, vha
, 0xc001,
1772 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1773 ret
, qos
, vha
->vp_idx
);
1774 ql_dbg(ql_dbg_user
, vha
, 0x7085,
1775 "Request Que:%d Q0s: %d) created for VP[%d]\n",
1776 ret
, qos
, vha
->vp_idx
);
1777 req
= ha
->req_q_map
[ret
];
1785 vport_create_failed_2
:
1786 qla24xx_disable_vp(vha
);
1787 qla24xx_deallocate_vp_id(vha
);
1788 scsi_host_put(vha
->host
);
1789 return FC_VPORT_FAILED
;
1793 qla24xx_vport_delete(struct fc_vport
*fc_vport
)
1795 scsi_qla_host_t
*vha
= fc_vport
->dd_data
;
1796 struct qla_hw_data
*ha
= vha
->hw
;
1797 uint16_t id
= vha
->vp_idx
;
1799 while (test_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
) ||
1800 test_bit(FCPORT_UPDATE_NEEDED
, &vha
->dpc_flags
))
1803 qla24xx_disable_vp(vha
);
1805 vha
->flags
.delete_progress
= 1;
1807 fc_remove_host(vha
->host
);
1809 scsi_remove_host(vha
->host
);
1811 /* Allow timer to run to drain queued items, when removing vp */
1812 qla24xx_deallocate_vp_id(vha
);
1814 if (vha
->timer_active
) {
1815 qla2x00_vp_stop_timer(vha
);
1816 ql_dbg(ql_dbg_user
, vha
, 0x7086,
1817 "Timer for the VP[%d] has stopped\n", vha
->vp_idx
);
1820 /* No pending activities shall be there on the vha now */
1821 if (ql2xextended_error_logging
& ql_dbg_user
)
1822 msleep(random32()%10); /* Just to see if something falls on
1823 * the net we have placed below */
1825 BUG_ON(atomic_read(&vha
->vref_count
));
1827 qla2x00_free_fcports(vha
);
1829 mutex_lock(&ha
->vport_lock
);
1830 ha
->cur_vport_count
--;
1831 clear_bit(vha
->vp_idx
, ha
->vp_idx_map
);
1832 mutex_unlock(&ha
->vport_lock
);
1834 if (vha
->req
->id
&& !ha
->flags
.cpu_affinity_enabled
) {
1835 if (qla25xx_delete_req_que(vha
, vha
->req
) != QLA_SUCCESS
)
1836 ql_log(ql_log_warn
, vha
, 0x7087,
1837 "Queue delete failed.\n");
1840 ql_log(ql_log_info
, vha
, 0x7088, "VP[%d] deleted.\n", id
);
1841 scsi_host_put(vha
->host
);
1846 qla24xx_vport_disable(struct fc_vport
*fc_vport
, bool disable
)
1848 scsi_qla_host_t
*vha
= fc_vport
->dd_data
;
1851 qla24xx_disable_vp(vha
);
1853 qla24xx_enable_vp(vha
);
1858 struct fc_function_template qla2xxx_transport_functions
= {
1860 .show_host_node_name
= 1,
1861 .show_host_port_name
= 1,
1862 .show_host_supported_classes
= 1,
1863 .show_host_supported_speeds
= 1,
1865 .get_host_port_id
= qla2x00_get_host_port_id
,
1866 .show_host_port_id
= 1,
1867 .get_host_speed
= qla2x00_get_host_speed
,
1868 .show_host_speed
= 1,
1869 .get_host_port_type
= qla2x00_get_host_port_type
,
1870 .show_host_port_type
= 1,
1871 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
1872 .show_host_symbolic_name
= 1,
1873 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
1874 .show_host_system_hostname
= 1,
1875 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
1876 .show_host_fabric_name
= 1,
1877 .get_host_port_state
= qla2x00_get_host_port_state
,
1878 .show_host_port_state
= 1,
1880 .dd_fcrport_size
= sizeof(struct fc_port
*),
1881 .show_rport_supported_classes
= 1,
1883 .get_starget_node_name
= qla2x00_get_starget_node_name
,
1884 .show_starget_node_name
= 1,
1885 .get_starget_port_name
= qla2x00_get_starget_port_name
,
1886 .show_starget_port_name
= 1,
1887 .get_starget_port_id
= qla2x00_get_starget_port_id
,
1888 .show_starget_port_id
= 1,
1890 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
1891 .show_rport_dev_loss_tmo
= 1,
1893 .issue_fc_host_lip
= qla2x00_issue_lip
,
1894 .dev_loss_tmo_callbk
= qla2x00_dev_loss_tmo_callbk
,
1895 .terminate_rport_io
= qla2x00_terminate_rport_io
,
1896 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
1898 .vport_create
= qla24xx_vport_create
,
1899 .vport_disable
= qla24xx_vport_disable
,
1900 .vport_delete
= qla24xx_vport_delete
,
1901 .bsg_request
= qla24xx_bsg_request
,
1902 .bsg_timeout
= qla24xx_bsg_timeout
,
1905 struct fc_function_template qla2xxx_transport_vport_functions
= {
1907 .show_host_node_name
= 1,
1908 .show_host_port_name
= 1,
1909 .show_host_supported_classes
= 1,
1911 .get_host_port_id
= qla2x00_get_host_port_id
,
1912 .show_host_port_id
= 1,
1913 .get_host_speed
= qla2x00_get_host_speed
,
1914 .show_host_speed
= 1,
1915 .get_host_port_type
= qla2x00_get_host_port_type
,
1916 .show_host_port_type
= 1,
1917 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
1918 .show_host_symbolic_name
= 1,
1919 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
1920 .show_host_system_hostname
= 1,
1921 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
1922 .show_host_fabric_name
= 1,
1923 .get_host_port_state
= qla2x00_get_host_port_state
,
1924 .show_host_port_state
= 1,
1926 .dd_fcrport_size
= sizeof(struct fc_port
*),
1927 .show_rport_supported_classes
= 1,
1929 .get_starget_node_name
= qla2x00_get_starget_node_name
,
1930 .show_starget_node_name
= 1,
1931 .get_starget_port_name
= qla2x00_get_starget_port_name
,
1932 .show_starget_port_name
= 1,
1933 .get_starget_port_id
= qla2x00_get_starget_port_id
,
1934 .show_starget_port_id
= 1,
1936 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
1937 .show_rport_dev_loss_tmo
= 1,
1939 .issue_fc_host_lip
= qla2x00_issue_lip
,
1940 .dev_loss_tmo_callbk
= qla2x00_dev_loss_tmo_callbk
,
1941 .terminate_rport_io
= qla2x00_terminate_rport_io
,
1942 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
1943 .bsg_request
= qla24xx_bsg_request
,
1944 .bsg_timeout
= qla24xx_bsg_timeout
,
1948 qla2x00_init_host_attr(scsi_qla_host_t
*vha
)
1950 struct qla_hw_data
*ha
= vha
->hw
;
1951 u32 speed
= FC_PORTSPEED_UNKNOWN
;
1953 fc_host_dev_loss_tmo(vha
->host
) = ha
->port_down_retry_count
;
1954 fc_host_node_name(vha
->host
) = wwn_to_u64(vha
->node_name
);
1955 fc_host_port_name(vha
->host
) = wwn_to_u64(vha
->port_name
);
1956 fc_host_supported_classes(vha
->host
) = ha
->tgt
.enable_class_2
?
1957 (FC_COS_CLASS2
|FC_COS_CLASS3
) : FC_COS_CLASS3
;
1958 fc_host_max_npiv_vports(vha
->host
) = ha
->max_npiv_vports
;
1959 fc_host_npiv_vports_inuse(vha
->host
) = ha
->cur_vport_count
;
1961 if (IS_CNA_CAPABLE(ha
))
1962 speed
= FC_PORTSPEED_10GBIT
;
1963 else if (IS_QLA2031(ha
))
1964 speed
= FC_PORTSPEED_16GBIT
| FC_PORTSPEED_8GBIT
|
1966 else if (IS_QLA25XX(ha
))
1967 speed
= FC_PORTSPEED_8GBIT
| FC_PORTSPEED_4GBIT
|
1968 FC_PORTSPEED_2GBIT
| FC_PORTSPEED_1GBIT
;
1969 else if (IS_QLA24XX_TYPE(ha
))
1970 speed
= FC_PORTSPEED_4GBIT
| FC_PORTSPEED_2GBIT
|
1972 else if (IS_QLA23XX(ha
))
1973 speed
= FC_PORTSPEED_2GBIT
| FC_PORTSPEED_1GBIT
;
1975 speed
= FC_PORTSPEED_1GBIT
;
1976 fc_host_supported_speeds(vha
->host
) = speed
;