2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 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 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;
27 if (ha->fw_dump_reading == 0)
30 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
35 qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
36 struct bin_attribute *bin_attr,
37 char *buf, loff_t off, size_t count)
39 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
40 struct device, kobj)));
41 struct qla_hw_data *ha = vha->hw;
45 DEBUG2(qla_printk(KERN_INFO, ha,
46 "Firmware dump not supported for ISP82xx\n"));
53 reading = simple_strtol(buf, NULL, 10);
56 if (!ha->fw_dump_reading)
59 qla_printk(KERN_INFO, ha,
60 "Firmware dump cleared on (%ld).\n", vha->host_no);
62 ha->fw_dump_reading = 0;
66 if (ha->fw_dumped && !ha->fw_dump_reading) {
67 ha->fw_dump_reading = 1;
69 qla_printk(KERN_INFO, ha,
70 "Raw firmware dump ready for read on (%ld).\n",
75 qla2x00_alloc_fw_dump(vha);
78 qla2x00_system_error(vha);
84 static struct bin_attribute sysfs_fw_dump_attr = {
87 .mode = S_IRUSR | S_IWUSR,
90 .read = qla2x00_sysfs_read_fw_dump,
91 .write = qla2x00_sysfs_write_fw_dump,
95 qla2x00_sysfs_read_nvram(struct kobject *kobj,
96 struct bin_attribute *bin_attr,
97 char *buf, loff_t off, size_t count)
99 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
100 struct device, kobj)));
101 struct qla_hw_data *ha = vha->hw;
103 if (!capable(CAP_SYS_ADMIN))
106 if (IS_NOCACHE_VPD_TYPE(ha))
107 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
109 return memory_read_from_buffer(buf, count, &off, ha->nvram,
114 qla2x00_sysfs_write_nvram(struct kobject *kobj,
115 struct bin_attribute *bin_attr,
116 char *buf, loff_t off, size_t count)
118 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
119 struct device, kobj)));
120 struct qla_hw_data *ha = vha->hw;
123 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
124 !ha->isp_ops->write_nvram)
127 /* Checksum NVRAM. */
128 if (IS_FWI2_CAPABLE(ha)) {
132 iter = (uint32_t *)buf;
134 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
135 chksum += le32_to_cpu(*iter++);
136 chksum = ~chksum + 1;
137 *iter = cpu_to_le32(chksum);
142 iter = (uint8_t *)buf;
144 for (cnt = 0; cnt < count - 1; cnt++)
146 chksum = ~chksum + 1;
150 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
151 qla_printk(KERN_WARNING, ha,
152 "HBA not online, failing NVRAM update.\n");
157 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
158 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
161 /* NVRAM settings take effect immediately. */
162 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
163 qla2xxx_wake_dpc(vha);
164 qla2x00_wait_for_chip_reset(vha);
169 static struct bin_attribute sysfs_nvram_attr = {
172 .mode = S_IRUSR | S_IWUSR,
175 .read = qla2x00_sysfs_read_nvram,
176 .write = qla2x00_sysfs_write_nvram,
180 qla2x00_sysfs_read_optrom(struct kobject *kobj,
181 struct bin_attribute *bin_attr,
182 char *buf, loff_t off, size_t count)
184 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
185 struct device, kobj)));
186 struct qla_hw_data *ha = vha->hw;
188 if (ha->optrom_state != QLA_SREADING)
191 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
192 ha->optrom_region_size);
196 qla2x00_sysfs_write_optrom(struct kobject *kobj,
197 struct bin_attribute *bin_attr,
198 char *buf, loff_t off, size_t count)
200 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
201 struct device, kobj)));
202 struct qla_hw_data *ha = vha->hw;
204 if (ha->optrom_state != QLA_SWRITING)
206 if (off > ha->optrom_region_size)
208 if (off + count > ha->optrom_region_size)
209 count = ha->optrom_region_size - off;
211 memcpy(&ha->optrom_buffer[off], buf, count);
216 static struct bin_attribute sysfs_optrom_attr = {
219 .mode = S_IRUSR | S_IWUSR,
222 .read = qla2x00_sysfs_read_optrom,
223 .write = qla2x00_sysfs_write_optrom,
227 qla2x00_sysfs_write_optrom_ctl(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;
236 uint32_t size = ha->optrom_size;
242 if (unlikely(pci_channel_offline(ha->pdev)))
245 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
247 if (start > ha->optrom_size)
252 if (ha->optrom_state != QLA_SREADING &&
253 ha->optrom_state != QLA_SWRITING)
256 ha->optrom_state = QLA_SWAITING;
258 DEBUG2(qla_printk(KERN_INFO, ha,
259 "Freeing flash region allocation -- 0x%x bytes.\n",
260 ha->optrom_region_size));
262 vfree(ha->optrom_buffer);
263 ha->optrom_buffer = NULL;
266 if (ha->optrom_state != QLA_SWAITING)
269 ha->optrom_region_start = start;
270 ha->optrom_region_size = start + size > ha->optrom_size ?
271 ha->optrom_size - start : size;
273 ha->optrom_state = QLA_SREADING;
274 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
275 if (ha->optrom_buffer == NULL) {
276 qla_printk(KERN_WARNING, ha,
277 "Unable to allocate memory for optrom retrieval "
278 "(%x).\n", ha->optrom_region_size);
280 ha->optrom_state = QLA_SWAITING;
284 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
285 qla_printk(KERN_WARNING, ha,
286 "HBA not online, failing NVRAM update.\n");
290 DEBUG2(qla_printk(KERN_INFO, ha,
291 "Reading flash region -- 0x%x/0x%x.\n",
292 ha->optrom_region_start, ha->optrom_region_size));
294 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
295 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
296 ha->optrom_region_start, ha->optrom_region_size);
299 if (ha->optrom_state != QLA_SWAITING)
303 * We need to be more restrictive on which FLASH regions are
304 * allowed to be updated via user-space. Regions accessible
305 * via this method include:
307 * ISP21xx/ISP22xx/ISP23xx type boards:
309 * 0x000000 -> 0x020000 -- Boot code.
311 * ISP2322/ISP24xx type boards:
313 * 0x000000 -> 0x07ffff -- Boot code.
314 * 0x080000 -> 0x0fffff -- Firmware.
316 * ISP25xx type boards:
318 * 0x000000 -> 0x07ffff -- Boot code.
319 * 0x080000 -> 0x0fffff -- Firmware.
320 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
323 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
325 else if (start == (ha->flt_region_boot * 4) ||
326 start == (ha->flt_region_fw * 4))
328 else if (IS_QLA25XX(ha) || IS_QLA8XXX_TYPE(ha))
331 qla_printk(KERN_WARNING, ha,
332 "Invalid start region 0x%x/0x%x.\n", start, size);
336 ha->optrom_region_start = start;
337 ha->optrom_region_size = start + size > ha->optrom_size ?
338 ha->optrom_size - start : size;
340 ha->optrom_state = QLA_SWRITING;
341 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
342 if (ha->optrom_buffer == NULL) {
343 qla_printk(KERN_WARNING, ha,
344 "Unable to allocate memory for optrom update "
345 "(%x).\n", ha->optrom_region_size);
347 ha->optrom_state = QLA_SWAITING;
351 DEBUG2(qla_printk(KERN_INFO, ha,
352 "Staging flash region write -- 0x%x/0x%x.\n",
353 ha->optrom_region_start, ha->optrom_region_size));
355 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
358 if (ha->optrom_state != QLA_SWRITING)
361 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
362 qla_printk(KERN_WARNING, ha,
363 "HBA not online, failing flash update.\n");
367 DEBUG2(qla_printk(KERN_INFO, ha,
368 "Writing flash region -- 0x%x/0x%x.\n",
369 ha->optrom_region_start, ha->optrom_region_size));
371 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
372 ha->optrom_region_start, ha->optrom_region_size);
380 static struct bin_attribute sysfs_optrom_ctl_attr = {
382 .name = "optrom_ctl",
386 .write = qla2x00_sysfs_write_optrom_ctl,
390 qla2x00_sysfs_read_vpd(struct kobject *kobj,
391 struct bin_attribute *bin_attr,
392 char *buf, loff_t off, size_t count)
394 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
395 struct device, kobj)));
396 struct qla_hw_data *ha = vha->hw;
398 if (unlikely(pci_channel_offline(ha->pdev)))
401 if (!capable(CAP_SYS_ADMIN))
404 if (IS_NOCACHE_VPD_TYPE(ha))
405 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
407 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
411 qla2x00_sysfs_write_vpd(struct kobject *kobj,
412 struct bin_attribute *bin_attr,
413 char *buf, loff_t off, size_t count)
415 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
416 struct device, kobj)));
417 struct qla_hw_data *ha = vha->hw;
420 if (unlikely(pci_channel_offline(ha->pdev)))
423 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
424 !ha->isp_ops->write_nvram)
427 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
428 qla_printk(KERN_WARNING, ha,
429 "HBA not online, failing VPD update.\n");
434 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
435 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
437 /* Update flash version information for 4Gb & above. */
438 if (!IS_FWI2_CAPABLE(ha))
441 tmp_data = vmalloc(256);
443 qla_printk(KERN_WARNING, ha,
444 "Unable to allocate memory for VPD information update.\n");
447 ha->isp_ops->get_flash_version(vha, tmp_data);
453 static struct bin_attribute sysfs_vpd_attr = {
456 .mode = S_IRUSR | S_IWUSR,
459 .read = qla2x00_sysfs_read_vpd,
460 .write = qla2x00_sysfs_write_vpd,
464 qla2x00_sysfs_read_sfp(struct kobject *kobj,
465 struct bin_attribute *bin_attr,
466 char *buf, loff_t off, size_t count)
468 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
469 struct device, kobj)));
470 struct qla_hw_data *ha = vha->hw;
471 uint16_t iter, addr, offset;
474 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
480 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
483 qla_printk(KERN_WARNING, ha,
484 "Unable to allocate memory for SFP read-data.\n");
489 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
491 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
492 iter++, offset += SFP_BLOCK_SIZE) {
494 /* Skip to next device address. */
499 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
501 if (rval != QLA_SUCCESS) {
502 qla_printk(KERN_WARNING, ha,
503 "Unable to read SFP data (%x/%x/%x).\n", rval,
508 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
509 buf += SFP_BLOCK_SIZE;
515 static struct bin_attribute sysfs_sfp_attr = {
518 .mode = S_IRUSR | S_IWUSR,
520 .size = SFP_DEV_SIZE * 2,
521 .read = qla2x00_sysfs_read_sfp,
525 qla2x00_sysfs_write_reset(struct kobject *kobj,
526 struct bin_attribute *bin_attr,
527 char *buf, loff_t off, size_t count)
529 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
530 struct device, kobj)));
531 struct qla_hw_data *ha = vha->hw;
532 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
538 type = simple_strtol(buf, NULL, 10);
541 qla_printk(KERN_INFO, ha,
542 "Issuing ISP reset on (%ld).\n", vha->host_no);
544 scsi_block_requests(vha->host);
545 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
546 qla2xxx_wake_dpc(vha);
547 qla2x00_wait_for_chip_reset(vha);
548 scsi_unblock_requests(vha->host);
554 qla_printk(KERN_INFO, ha,
555 "Issuing MPI reset on (%ld).\n", vha->host_no);
557 /* Make sure FC side is not in reset */
558 qla2x00_wait_for_hba_online(vha);
560 /* Issue MPI reset */
561 scsi_block_requests(vha->host);
562 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
563 qla_printk(KERN_WARNING, ha,
564 "MPI reset failed on (%ld).\n", vha->host_no);
565 scsi_unblock_requests(vha->host);
568 if (!IS_QLA82XX(ha) || vha != base_vha) {
569 qla_printk(KERN_INFO, ha,
570 "FCoE ctx reset not supported for host%ld.\n",
575 qla_printk(KERN_INFO, ha,
576 "Issuing FCoE CTX reset on host%ld.\n", vha->host_no);
577 set_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags);
578 qla2xxx_wake_dpc(vha);
579 qla2x00_wait_for_fcoe_ctx_reset(vha);
585 static struct bin_attribute sysfs_reset_attr = {
591 .write = qla2x00_sysfs_write_reset,
595 qla2x00_sysfs_write_edc(struct kobject *kobj,
596 struct bin_attribute *bin_attr,
597 char *buf, loff_t off, size_t count)
599 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
600 struct device, kobj)));
601 struct qla_hw_data *ha = vha->hw;
602 uint16_t dev, adr, opt, len;
605 ha->edc_data_len = 0;
607 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
611 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
614 DEBUG2(qla_printk(KERN_INFO, ha,
615 "Unable to allocate memory for EDC write.\n"));
620 dev = le16_to_cpup((void *)&buf[0]);
621 adr = le16_to_cpup((void *)&buf[2]);
622 opt = le16_to_cpup((void *)&buf[4]);
623 len = le16_to_cpup((void *)&buf[6]);
626 if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
629 memcpy(ha->edc_data, &buf[8], len);
631 rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
632 ha->edc_data, len, opt);
633 if (rval != QLA_SUCCESS) {
634 DEBUG2(qla_printk(KERN_INFO, ha,
635 "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
636 rval, dev, adr, opt, len, *buf));
643 static struct bin_attribute sysfs_edc_attr = {
649 .write = qla2x00_sysfs_write_edc,
653 qla2x00_sysfs_write_edc_status(struct kobject *kobj,
654 struct bin_attribute *bin_attr,
655 char *buf, loff_t off, size_t count)
657 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
658 struct device, kobj)));
659 struct qla_hw_data *ha = vha->hw;
660 uint16_t dev, adr, opt, len;
663 ha->edc_data_len = 0;
665 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
669 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
672 DEBUG2(qla_printk(KERN_INFO, ha,
673 "Unable to allocate memory for EDC status.\n"));
678 dev = le16_to_cpup((void *)&buf[0]);
679 adr = le16_to_cpup((void *)&buf[2]);
680 opt = le16_to_cpup((void *)&buf[4]);
681 len = le16_to_cpup((void *)&buf[6]);
684 if (len == 0 || len > DMA_POOL_SIZE)
687 memset(ha->edc_data, 0, len);
688 rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
689 ha->edc_data, len, opt);
690 if (rval != QLA_SUCCESS) {
691 DEBUG2(qla_printk(KERN_INFO, ha,
692 "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
693 rval, dev, adr, opt, len));
697 ha->edc_data_len = len;
703 qla2x00_sysfs_read_edc_status(struct kobject *kobj,
704 struct bin_attribute *bin_attr,
705 char *buf, loff_t off, size_t count)
707 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
708 struct device, kobj)));
709 struct qla_hw_data *ha = vha->hw;
711 if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
714 if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
717 memcpy(buf, ha->edc_data, ha->edc_data_len);
719 return ha->edc_data_len;
722 static struct bin_attribute sysfs_edc_status_attr = {
724 .name = "edc_status",
725 .mode = S_IRUSR | S_IWUSR,
728 .write = qla2x00_sysfs_write_edc_status,
729 .read = qla2x00_sysfs_read_edc_status,
733 qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
734 struct bin_attribute *bin_attr,
735 char *buf, loff_t off, size_t count)
737 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
738 struct device, kobj)));
739 struct qla_hw_data *ha = vha->hw;
741 uint16_t actual_size;
743 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
749 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
750 &ha->xgmac_data_dma, GFP_KERNEL);
751 if (!ha->xgmac_data) {
752 qla_printk(KERN_WARNING, ha,
753 "Unable to allocate memory for XGMAC read-data.\n");
759 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
761 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
762 XGMAC_DATA_SIZE, &actual_size);
763 if (rval != QLA_SUCCESS) {
764 qla_printk(KERN_WARNING, ha,
765 "Unable to read XGMAC data (%x).\n", rval);
769 count = actual_size > count ? count: actual_size;
770 memcpy(buf, ha->xgmac_data, count);
775 static struct bin_attribute sysfs_xgmac_stats_attr = {
777 .name = "xgmac_stats",
781 .read = qla2x00_sysfs_read_xgmac_stats,
785 qla2x00_sysfs_read_dcbx_tlv(struct kobject *kobj,
786 struct bin_attribute *bin_attr,
787 char *buf, loff_t off, size_t count)
789 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
790 struct device, kobj)));
791 struct qla_hw_data *ha = vha->hw;
793 uint16_t actual_size;
795 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
801 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
802 &ha->dcbx_tlv_dma, GFP_KERNEL);
804 qla_printk(KERN_WARNING, ha,
805 "Unable to allocate memory for DCBX TLV read-data.\n");
811 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
813 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
815 if (rval != QLA_SUCCESS) {
816 qla_printk(KERN_WARNING, ha,
817 "Unable to read DCBX TLV data (%x).\n", rval);
821 memcpy(buf, ha->dcbx_tlv, count);
826 static struct bin_attribute sysfs_dcbx_tlv_attr = {
832 .read = qla2x00_sysfs_read_dcbx_tlv,
835 static struct sysfs_entry {
837 struct bin_attribute *attr;
839 } bin_file_entries[] = {
840 { "fw_dump", &sysfs_fw_dump_attr, },
841 { "nvram", &sysfs_nvram_attr, },
842 { "optrom", &sysfs_optrom_attr, },
843 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
844 { "vpd", &sysfs_vpd_attr, 1 },
845 { "sfp", &sysfs_sfp_attr, 1 },
846 { "reset", &sysfs_reset_attr, },
847 { "edc", &sysfs_edc_attr, 2 },
848 { "edc_status", &sysfs_edc_status_attr, 2 },
849 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
850 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
855 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
857 struct Scsi_Host *host = vha->host;
858 struct sysfs_entry *iter;
861 for (iter = bin_file_entries; iter->name; iter++) {
862 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
864 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
866 if (iter->is4GBp_only == 3 && !(IS_QLA8XXX_TYPE(vha->hw)))
869 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
872 qla_printk(KERN_INFO, vha->hw,
873 "Unable to create sysfs %s binary attribute "
874 "(%d).\n", iter->name, ret);
879 qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
881 struct Scsi_Host *host = vha->host;
882 struct sysfs_entry *iter;
883 struct qla_hw_data *ha = vha->hw;
885 for (iter = bin_file_entries; iter->name; iter++) {
886 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
888 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
890 if (iter->is4GBp_only == 3 && !!(IS_QLA8XXX_TYPE(vha->hw)))
893 sysfs_remove_bin_file(&host->shost_gendev.kobj,
897 if (ha->beacon_blink_led == 1)
898 ha->isp_ops->beacon_off(vha);
901 /* Scsi_Host attributes. */
904 qla2x00_drvr_version_show(struct device *dev,
905 struct device_attribute *attr, char *buf)
907 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
911 qla2x00_fw_version_show(struct device *dev,
912 struct device_attribute *attr, char *buf)
914 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
915 struct qla_hw_data *ha = vha->hw;
918 return snprintf(buf, PAGE_SIZE, "%s\n",
919 ha->isp_ops->fw_version_str(vha, fw_str));
923 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
926 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
927 struct qla_hw_data *ha = vha->hw;
930 if (IS_FWI2_CAPABLE(ha)) {
931 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
932 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
935 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
936 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
941 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
944 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
945 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
949 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
952 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
953 struct qla_hw_data *ha = vha->hw;
954 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
955 ha->product_id[0], ha->product_id[1], ha->product_id[2],
960 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
963 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
964 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
968 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
971 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
972 return snprintf(buf, PAGE_SIZE, "%s\n",
973 vha->hw->model_desc ? vha->hw->model_desc : "");
977 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
980 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
983 return snprintf(buf, PAGE_SIZE, "%s\n",
984 vha->hw->isp_ops->pci_info_str(vha, pci_info));
988 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
991 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
992 struct qla_hw_data *ha = vha->hw;
995 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
996 atomic_read(&vha->loop_state) == LOOP_DEAD ||
997 vha->device_flags & DFLG_NO_CABLE)
998 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
999 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
1000 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1001 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
1002 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1004 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
1006 switch (ha->current_topology) {
1008 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1011 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1014 len += snprintf(buf + len, PAGE_SIZE-len,
1015 "N_Port to N_Port\n");
1018 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1021 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1029 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1032 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1035 switch (vha->hw->zio_mode) {
1036 case QLA_ZIO_MODE_6:
1037 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1039 case QLA_ZIO_DISABLED:
1040 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1047 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1048 const char *buf, size_t count)
1050 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1051 struct qla_hw_data *ha = vha->hw;
1055 if (!IS_ZIO_SUPPORTED(ha))
1058 if (sscanf(buf, "%d", &val) != 1)
1062 zio_mode = QLA_ZIO_MODE_6;
1064 zio_mode = QLA_ZIO_DISABLED;
1066 /* Update per-hba values and queue a reset. */
1067 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1068 ha->zio_mode = zio_mode;
1069 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1075 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1078 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1080 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
1084 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1085 const char *buf, size_t count)
1087 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1091 if (sscanf(buf, "%d", &val) != 1)
1093 if (val > 25500 || val < 100)
1096 zio_timer = (uint16_t)(val / 100);
1097 vha->hw->zio_timer = zio_timer;
1103 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1106 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1109 if (vha->hw->beacon_blink_led)
1110 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1112 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1117 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1118 const char *buf, size_t count)
1120 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1121 struct qla_hw_data *ha = vha->hw;
1125 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1128 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
1129 qla_printk(KERN_WARNING, ha,
1130 "Abort ISP active -- ignoring beacon request.\n");
1134 if (sscanf(buf, "%d", &val) != 1)
1138 rval = ha->isp_ops->beacon_on(vha);
1140 rval = ha->isp_ops->beacon_off(vha);
1142 if (rval != QLA_SUCCESS)
1149 qla2x00_optrom_bios_version_show(struct device *dev,
1150 struct device_attribute *attr, char *buf)
1152 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1153 struct qla_hw_data *ha = vha->hw;
1154 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1155 ha->bios_revision[0]);
1159 qla2x00_optrom_efi_version_show(struct device *dev,
1160 struct device_attribute *attr, char *buf)
1162 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1163 struct qla_hw_data *ha = vha->hw;
1164 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1165 ha->efi_revision[0]);
1169 qla2x00_optrom_fcode_version_show(struct device *dev,
1170 struct device_attribute *attr, char *buf)
1172 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1173 struct qla_hw_data *ha = vha->hw;
1174 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1175 ha->fcode_revision[0]);
1179 qla2x00_optrom_fw_version_show(struct device *dev,
1180 struct device_attribute *attr, char *buf)
1182 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1183 struct qla_hw_data *ha = vha->hw;
1184 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1185 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1186 ha->fw_revision[3]);
1190 qla2x00_total_isp_aborts_show(struct device *dev,
1191 struct device_attribute *attr, char *buf)
1193 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1194 struct qla_hw_data *ha = vha->hw;
1195 return snprintf(buf, PAGE_SIZE, "%d\n",
1196 ha->qla_stats.total_isp_aborts);
1200 qla24xx_84xx_fw_version_show(struct device *dev,
1201 struct device_attribute *attr, char *buf)
1203 int rval = QLA_SUCCESS;
1204 uint16_t status[2] = {0, 0};
1205 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1206 struct qla_hw_data *ha = vha->hw;
1208 if (!IS_QLA84XX(ha))
1209 return snprintf(buf, PAGE_SIZE, "\n");
1211 if (ha->cs84xx && ha->cs84xx->op_fw_version == 0)
1212 rval = qla84xx_verify_chip(vha, status);
1214 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1215 return snprintf(buf, PAGE_SIZE, "%u\n",
1216 (uint32_t)ha->cs84xx->op_fw_version);
1218 return snprintf(buf, PAGE_SIZE, "\n");
1222 qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1225 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1226 struct qla_hw_data *ha = vha->hw;
1228 if (!IS_QLA81XX(ha))
1229 return snprintf(buf, PAGE_SIZE, "\n");
1231 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
1232 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
1233 ha->mpi_capabilities);
1237 qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1240 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1241 struct qla_hw_data *ha = vha->hw;
1243 if (!IS_QLA81XX(ha))
1244 return snprintf(buf, PAGE_SIZE, "\n");
1246 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1247 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
1251 qla2x00_flash_block_size_show(struct device *dev,
1252 struct device_attribute *attr, char *buf)
1254 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1255 struct qla_hw_data *ha = vha->hw;
1257 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1261 qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1264 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1266 if (!IS_QLA8XXX_TYPE(vha->hw))
1267 return snprintf(buf, PAGE_SIZE, "\n");
1269 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1273 qla2x00_vn_port_mac_address_show(struct device *dev,
1274 struct device_attribute *attr, char *buf)
1276 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1278 if (!IS_QLA8XXX_TYPE(vha->hw))
1279 return snprintf(buf, PAGE_SIZE, "\n");
1281 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1282 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1283 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1284 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1288 qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1291 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1293 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1297 qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1300 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1301 int rval = QLA_FUNCTION_FAILED;
1304 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
1305 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
1306 DEBUG2_3_11(printk("%s(%ld): isp reset in progress.\n",
1307 __func__, vha->host_no));
1308 else if (!vha->hw->flags.eeh_busy)
1309 rval = qla2x00_get_firmware_state(vha, state);
1310 if (rval != QLA_SUCCESS)
1311 memset(state, -1, sizeof(state));
1313 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1314 state[1], state[2], state[3], state[4]);
1317 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1318 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1319 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1320 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1321 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1322 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1323 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1324 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
1325 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
1326 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1327 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1328 qla2x00_zio_timer_store);
1329 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1330 qla2x00_beacon_store);
1331 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1332 qla2x00_optrom_bios_version_show, NULL);
1333 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1334 qla2x00_optrom_efi_version_show, NULL);
1335 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1336 qla2x00_optrom_fcode_version_show, NULL);
1337 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1339 static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1341 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1343 static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
1344 static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
1345 static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1347 static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1348 static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1349 qla2x00_vn_port_mac_address_show, NULL);
1350 static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
1351 static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
1353 struct device_attribute *qla2x00_host_attrs[] = {
1354 &dev_attr_driver_version,
1355 &dev_attr_fw_version,
1356 &dev_attr_serial_num,
1359 &dev_attr_model_name,
1360 &dev_attr_model_desc,
1362 &dev_attr_link_state,
1364 &dev_attr_zio_timer,
1366 &dev_attr_optrom_bios_version,
1367 &dev_attr_optrom_efi_version,
1368 &dev_attr_optrom_fcode_version,
1369 &dev_attr_optrom_fw_version,
1370 &dev_attr_84xx_fw_version,
1371 &dev_attr_total_isp_aborts,
1372 &dev_attr_mpi_version,
1373 &dev_attr_phy_version,
1374 &dev_attr_flash_block_size,
1376 &dev_attr_vn_port_mac_address,
1377 &dev_attr_fabric_param,
1382 /* Host attributes. */
1385 qla2x00_get_host_port_id(struct Scsi_Host *shost)
1387 scsi_qla_host_t *vha = shost_priv(shost);
1389 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1390 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
1394 qla2x00_get_host_speed(struct Scsi_Host *shost)
1396 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1397 (shost_priv(shost)))->hw;
1398 u32 speed = FC_PORTSPEED_UNKNOWN;
1400 switch (ha->link_data_rate) {
1401 case PORT_SPEED_1GB:
1402 speed = FC_PORTSPEED_1GBIT;
1404 case PORT_SPEED_2GB:
1405 speed = FC_PORTSPEED_2GBIT;
1407 case PORT_SPEED_4GB:
1408 speed = FC_PORTSPEED_4GBIT;
1410 case PORT_SPEED_8GB:
1411 speed = FC_PORTSPEED_8GBIT;
1413 case PORT_SPEED_10GB:
1414 speed = FC_PORTSPEED_10GBIT;
1417 fc_host_speed(shost) = speed;
1421 qla2x00_get_host_port_type(struct Scsi_Host *shost)
1423 scsi_qla_host_t *vha = shost_priv(shost);
1424 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1427 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1430 switch (vha->hw->current_topology) {
1432 port_type = FC_PORTTYPE_LPORT;
1435 port_type = FC_PORTTYPE_NLPORT;
1438 port_type = FC_PORTTYPE_PTP;
1441 port_type = FC_PORTTYPE_NPORT;
1444 fc_host_port_type(shost) = port_type;
1448 qla2x00_get_starget_node_name(struct scsi_target *starget)
1450 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1451 scsi_qla_host_t *vha = shost_priv(host);
1455 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1456 if (fcport->rport &&
1457 starget->id == fcport->rport->scsi_target_id) {
1458 node_name = wwn_to_u64(fcport->node_name);
1463 fc_starget_node_name(starget) = node_name;
1467 qla2x00_get_starget_port_name(struct scsi_target *starget)
1469 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1470 scsi_qla_host_t *vha = shost_priv(host);
1474 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1475 if (fcport->rport &&
1476 starget->id == fcport->rport->scsi_target_id) {
1477 port_name = wwn_to_u64(fcport->port_name);
1482 fc_starget_port_name(starget) = port_name;
1486 qla2x00_get_starget_port_id(struct scsi_target *starget)
1488 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1489 scsi_qla_host_t *vha = shost_priv(host);
1491 uint32_t port_id = ~0U;
1493 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1494 if (fcport->rport &&
1495 starget->id == fcport->rport->scsi_target_id) {
1496 port_id = fcport->d_id.b.domain << 16 |
1497 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1502 fc_starget_port_id(starget) = port_id;
1506 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1509 rport->dev_loss_tmo = timeout;
1511 rport->dev_loss_tmo = 1;
1515 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1517 struct Scsi_Host *host = rport_to_shost(rport);
1518 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1523 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1526 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1527 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1532 * Transport has effectively 'deleted' the rport, clear
1533 * all local references.
1535 spin_lock_irq(host->host_lock);
1536 fcport->rport = NULL;
1537 *((fc_port_t **)rport->dd_data) = NULL;
1538 spin_unlock_irq(host->host_lock);
1542 qla2x00_terminate_rport_io(struct fc_rport *rport)
1544 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1549 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1552 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1553 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1557 * At this point all fcport's software-states are cleared. Perform any
1558 * final cleanup of firmware resources (PCBs and XCBs).
1560 if (fcport->loop_id != FC_NO_LOOP_ID &&
1561 !test_bit(UNLOADING, &fcport->vha->dpc_flags))
1562 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1563 fcport->loop_id, fcport->d_id.b.domain,
1564 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1568 qla2x00_issue_lip(struct Scsi_Host *shost)
1570 scsi_qla_host_t *vha = shost_priv(shost);
1572 qla2x00_loop_reset(vha);
1576 static struct fc_host_statistics *
1577 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1579 scsi_qla_host_t *vha = shost_priv(shost);
1580 struct qla_hw_data *ha = vha->hw;
1581 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1583 struct link_statistics *stats;
1584 dma_addr_t stats_dma;
1585 struct fc_host_statistics *pfc_host_stat;
1587 pfc_host_stat = &ha->fc_host_stat;
1588 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1590 if (test_bit(UNLOADING, &vha->dpc_flags))
1593 if (unlikely(pci_channel_offline(ha->pdev)))
1596 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1597 if (stats == NULL) {
1598 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1599 __func__, base_vha->host_no));
1602 memset(stats, 0, DMA_POOL_SIZE);
1604 rval = QLA_FUNCTION_FAILED;
1605 if (IS_FWI2_CAPABLE(ha)) {
1606 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1607 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1608 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1609 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1611 /* Must be in a 'READY' state for statistics retrieval. */
1612 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1616 if (rval != QLA_SUCCESS)
1619 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1620 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1621 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1622 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1623 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1624 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1625 if (IS_FWI2_CAPABLE(ha)) {
1626 pfc_host_stat->lip_count = stats->lip_cnt;
1627 pfc_host_stat->tx_frames = stats->tx_frames;
1628 pfc_host_stat->rx_frames = stats->rx_frames;
1629 pfc_host_stat->dumped_frames = stats->dumped_frames;
1630 pfc_host_stat->nos_count = stats->nos_rcvd;
1632 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1633 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
1636 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
1638 return pfc_host_stat;
1642 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1644 scsi_qla_host_t *vha = shost_priv(shost);
1646 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
1650 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1652 scsi_qla_host_t *vha = shost_priv(shost);
1654 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
1658 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1660 scsi_qla_host_t *vha = shost_priv(shost);
1663 if (vha->device_flags & SWITCH_FOUND)
1664 node_name = wwn_to_u64(vha->fabric_node_name);
1666 node_name = wwn_to_u64(vha->node_name);
1668 fc_host_fabric_name(shost) = node_name;
1672 qla2x00_get_host_port_state(struct Scsi_Host *shost)
1674 scsi_qla_host_t *vha = shost_priv(shost);
1675 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
1677 if (!base_vha->flags.online)
1678 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1679 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
1680 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1682 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1686 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1690 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1691 scsi_qla_host_t *vha = NULL;
1692 struct qla_hw_data *ha = base_vha->hw;
1693 uint16_t options = 0;
1695 struct req_que *req = ha->req_q_map[0];
1697 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1699 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1700 "status %x\n", ret));
1704 vha = qla24xx_create_vhost(fc_vport);
1706 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1708 return FC_VPORT_FAILED;
1711 atomic_set(&vha->vp_state, VP_OFFLINE);
1712 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1714 atomic_set(&vha->vp_state, VP_FAILED);
1716 /* ready to create vport */
1717 qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
1720 /* initialized vport states */
1721 atomic_set(&vha->loop_state, LOOP_DOWN);
1722 vha->vp_err_state= VP_ERR_PORTDWN;
1723 vha->vp_prev_err_state= VP_ERR_UNKWN;
1724 /* Check if physical ha port is Up */
1725 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1726 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
1727 /* Don't retry or attempt login of this virtual port */
1728 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1729 base_vha->host_no));
1730 atomic_set(&vha->loop_state, LOOP_DEAD);
1732 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1735 if (IS_QLA25XX(ha) && ql2xenabledif) {
1736 if (ha->fw_attributes & BIT_4) {
1737 vha->flags.difdix_supported = 1;
1738 DEBUG18(qla_printk(KERN_INFO, ha,
1739 "Registering for DIF/DIX type 1 and 3"
1741 scsi_host_set_prot(vha->host,
1742 SHOST_DIF_TYPE1_PROTECTION
1743 | SHOST_DIF_TYPE3_PROTECTION
1744 | SHOST_DIX_TYPE1_PROTECTION
1745 | SHOST_DIX_TYPE3_PROTECTION);
1746 scsi_host_set_guard(vha->host, SHOST_DIX_GUARD_CRC);
1748 vha->flags.difdix_supported = 0;
1751 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1753 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1754 vha->host_no, vha->vp_idx));
1755 goto vport_create_failed_2;
1758 /* initialize attributes */
1759 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1760 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1761 fc_host_supported_classes(vha->host) =
1762 fc_host_supported_classes(base_vha->host);
1763 fc_host_supported_speeds(vha->host) =
1764 fc_host_supported_speeds(base_vha->host);
1766 qla24xx_vport_disable(fc_vport, disable);
1768 if (ha->flags.cpu_affinity_enabled) {
1769 req = ha->req_q_map[1];
1771 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
1773 /* Create a request queue in QoS mode for the vport */
1774 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1775 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1776 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
1778 qos = ha->npiv_info[cnt].q_qos;
1783 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1786 qla_printk(KERN_WARNING, ha,
1787 "Can't create request queue for vp_idx:%d\n",
1790 DEBUG2(qla_printk(KERN_INFO, ha,
1791 "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
1792 ret, qos, vha->vp_idx));
1793 req = ha->req_q_map[ret];
1801 vport_create_failed_2:
1802 qla24xx_disable_vp(vha);
1803 qla24xx_deallocate_vp_id(vha);
1804 scsi_host_put(vha->host);
1805 return FC_VPORT_FAILED;
1809 qla24xx_vport_delete(struct fc_vport *fc_vport)
1811 scsi_qla_host_t *vha = fc_vport->dd_data;
1812 fc_port_t *fcport, *tfcport;
1813 struct qla_hw_data *ha = vha->hw;
1814 uint16_t id = vha->vp_idx;
1816 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
1817 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
1820 qla24xx_disable_vp(vha);
1822 fc_remove_host(vha->host);
1824 scsi_remove_host(vha->host);
1826 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
1827 list_del(&fcport->list);
1832 qla24xx_deallocate_vp_id(vha);
1834 mutex_lock(&ha->vport_lock);
1835 ha->cur_vport_count--;
1836 clear_bit(vha->vp_idx, ha->vp_idx_map);
1837 mutex_unlock(&ha->vport_lock);
1839 if (vha->timer_active) {
1840 qla2x00_vp_stop_timer(vha);
1841 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1843 vha->host_no, vha->vp_idx, vha));
1846 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
1847 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
1848 qla_printk(KERN_WARNING, ha,
1849 "Queue delete failed.\n");
1852 scsi_host_put(vha->host);
1853 qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
1858 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1860 scsi_qla_host_t *vha = fc_vport->dd_data;
1863 qla24xx_disable_vp(vha);
1865 qla24xx_enable_vp(vha);
1870 struct fc_function_template qla2xxx_transport_functions = {
1872 .show_host_node_name = 1,
1873 .show_host_port_name = 1,
1874 .show_host_supported_classes = 1,
1875 .show_host_supported_speeds = 1,
1877 .get_host_port_id = qla2x00_get_host_port_id,
1878 .show_host_port_id = 1,
1879 .get_host_speed = qla2x00_get_host_speed,
1880 .show_host_speed = 1,
1881 .get_host_port_type = qla2x00_get_host_port_type,
1882 .show_host_port_type = 1,
1883 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1884 .show_host_symbolic_name = 1,
1885 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1886 .show_host_system_hostname = 1,
1887 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1888 .show_host_fabric_name = 1,
1889 .get_host_port_state = qla2x00_get_host_port_state,
1890 .show_host_port_state = 1,
1892 .dd_fcrport_size = sizeof(struct fc_port *),
1893 .show_rport_supported_classes = 1,
1895 .get_starget_node_name = qla2x00_get_starget_node_name,
1896 .show_starget_node_name = 1,
1897 .get_starget_port_name = qla2x00_get_starget_port_name,
1898 .show_starget_port_name = 1,
1899 .get_starget_port_id = qla2x00_get_starget_port_id,
1900 .show_starget_port_id = 1,
1902 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1903 .show_rport_dev_loss_tmo = 1,
1905 .issue_fc_host_lip = qla2x00_issue_lip,
1906 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1907 .terminate_rport_io = qla2x00_terminate_rport_io,
1908 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1910 .vport_create = qla24xx_vport_create,
1911 .vport_disable = qla24xx_vport_disable,
1912 .vport_delete = qla24xx_vport_delete,
1913 .bsg_request = qla24xx_bsg_request,
1914 .bsg_timeout = qla24xx_bsg_timeout,
1917 struct fc_function_template qla2xxx_transport_vport_functions = {
1919 .show_host_node_name = 1,
1920 .show_host_port_name = 1,
1921 .show_host_supported_classes = 1,
1923 .get_host_port_id = qla2x00_get_host_port_id,
1924 .show_host_port_id = 1,
1925 .get_host_speed = qla2x00_get_host_speed,
1926 .show_host_speed = 1,
1927 .get_host_port_type = qla2x00_get_host_port_type,
1928 .show_host_port_type = 1,
1929 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1930 .show_host_symbolic_name = 1,
1931 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1932 .show_host_system_hostname = 1,
1933 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1934 .show_host_fabric_name = 1,
1935 .get_host_port_state = qla2x00_get_host_port_state,
1936 .show_host_port_state = 1,
1938 .dd_fcrport_size = sizeof(struct fc_port *),
1939 .show_rport_supported_classes = 1,
1941 .get_starget_node_name = qla2x00_get_starget_node_name,
1942 .show_starget_node_name = 1,
1943 .get_starget_port_name = qla2x00_get_starget_port_name,
1944 .show_starget_port_name = 1,
1945 .get_starget_port_id = qla2x00_get_starget_port_id,
1946 .show_starget_port_id = 1,
1948 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1949 .show_rport_dev_loss_tmo = 1,
1951 .issue_fc_host_lip = qla2x00_issue_lip,
1952 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1953 .terminate_rport_io = qla2x00_terminate_rport_io,
1954 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1955 .bsg_request = qla24xx_bsg_request,
1956 .bsg_timeout = qla24xx_bsg_timeout,
1960 qla2x00_init_host_attr(scsi_qla_host_t *vha)
1962 struct qla_hw_data *ha = vha->hw;
1963 u32 speed = FC_PORTSPEED_UNKNOWN;
1965 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1966 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1967 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
1968 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
1969 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
1971 if (IS_QLA8XXX_TYPE(ha))
1972 speed = FC_PORTSPEED_10GBIT;
1973 else if (IS_QLA25XX(ha))
1974 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1975 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1976 else if (IS_QLA24XX_TYPE(ha))
1977 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1979 else if (IS_QLA23XX(ha))
1980 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1982 speed = FC_PORTSPEED_1GBIT;
1983 fc_host_supported_speeds(vha->host) = speed;