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/delay.h>
13 static int qla24xx_vport_disable(struct fc_vport *, bool);
14 static int qla84xx_reset(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
15 int qla84xx_reset_chip(scsi_qla_host_t *, uint16_t, uint16_t *);
16 static int qla84xx_mgmt_cmd(scsi_qla_host_t *, struct msg_echo_lb *, struct fc_bsg_job *);
17 /* SYSFS attributes --------------------------------------------------------- */
20 qla2x00_sysfs_read_fw_dump(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;
28 if (ha->fw_dump_reading == 0)
31 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
36 qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
37 struct bin_attribute *bin_attr,
38 char *buf, loff_t off, size_t count)
40 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
41 struct device, kobj)));
42 struct qla_hw_data *ha = vha->hw;
48 reading = simple_strtol(buf, NULL, 10);
51 if (!ha->fw_dump_reading)
54 qla_printk(KERN_INFO, ha,
55 "Firmware dump cleared on (%ld).\n", vha->host_no);
57 ha->fw_dump_reading = 0;
61 if (ha->fw_dumped && !ha->fw_dump_reading) {
62 ha->fw_dump_reading = 1;
64 qla_printk(KERN_INFO, ha,
65 "Raw firmware dump ready for read on (%ld).\n",
70 qla2x00_alloc_fw_dump(vha);
73 qla2x00_system_error(vha);
79 static struct bin_attribute sysfs_fw_dump_attr = {
82 .mode = S_IRUSR | S_IWUSR,
85 .read = qla2x00_sysfs_read_fw_dump,
86 .write = qla2x00_sysfs_write_fw_dump,
90 qla2x00_sysfs_read_nvram(struct kobject *kobj,
91 struct bin_attribute *bin_attr,
92 char *buf, loff_t off, size_t count)
94 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
95 struct device, kobj)));
96 struct qla_hw_data *ha = vha->hw;
98 if (!capable(CAP_SYS_ADMIN))
101 if (IS_NOCACHE_VPD_TYPE(ha))
102 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
104 return memory_read_from_buffer(buf, count, &off, ha->nvram,
109 qla2x00_sysfs_write_nvram(struct kobject *kobj,
110 struct bin_attribute *bin_attr,
111 char *buf, loff_t off, size_t count)
113 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
114 struct device, kobj)));
115 struct qla_hw_data *ha = vha->hw;
118 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
119 !ha->isp_ops->write_nvram)
122 /* Checksum NVRAM. */
123 if (IS_FWI2_CAPABLE(ha)) {
127 iter = (uint32_t *)buf;
129 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
130 chksum += le32_to_cpu(*iter++);
131 chksum = ~chksum + 1;
132 *iter = cpu_to_le32(chksum);
137 iter = (uint8_t *)buf;
139 for (cnt = 0; cnt < count - 1; cnt++)
141 chksum = ~chksum + 1;
145 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
146 qla_printk(KERN_WARNING, ha,
147 "HBA not online, failing NVRAM update.\n");
152 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
153 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
156 /* NVRAM settings take effect immediately. */
157 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
158 qla2xxx_wake_dpc(vha);
159 qla2x00_wait_for_chip_reset(vha);
164 static struct bin_attribute sysfs_nvram_attr = {
167 .mode = S_IRUSR | S_IWUSR,
170 .read = qla2x00_sysfs_read_nvram,
171 .write = qla2x00_sysfs_write_nvram,
175 qla2x00_sysfs_read_optrom(struct kobject *kobj,
176 struct bin_attribute *bin_attr,
177 char *buf, loff_t off, size_t count)
179 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
180 struct device, kobj)));
181 struct qla_hw_data *ha = vha->hw;
183 if (ha->optrom_state != QLA_SREADING)
186 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
187 ha->optrom_region_size);
191 qla2x00_sysfs_write_optrom(struct kobject *kobj,
192 struct bin_attribute *bin_attr,
193 char *buf, loff_t off, size_t count)
195 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
196 struct device, kobj)));
197 struct qla_hw_data *ha = vha->hw;
199 if (ha->optrom_state != QLA_SWRITING)
201 if (off > ha->optrom_region_size)
203 if (off + count > ha->optrom_region_size)
204 count = ha->optrom_region_size - off;
206 memcpy(&ha->optrom_buffer[off], buf, count);
211 static struct bin_attribute sysfs_optrom_attr = {
214 .mode = S_IRUSR | S_IWUSR,
217 .read = qla2x00_sysfs_read_optrom,
218 .write = qla2x00_sysfs_write_optrom,
222 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
223 struct bin_attribute *bin_attr,
224 char *buf, loff_t off, size_t count)
226 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
227 struct device, kobj)));
228 struct qla_hw_data *ha = vha->hw;
231 uint32_t size = ha->optrom_size;
237 if (unlikely(pci_channel_offline(ha->pdev)))
240 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
242 if (start > ha->optrom_size)
247 if (ha->optrom_state != QLA_SREADING &&
248 ha->optrom_state != QLA_SWRITING)
251 ha->optrom_state = QLA_SWAITING;
253 DEBUG2(qla_printk(KERN_INFO, ha,
254 "Freeing flash region allocation -- 0x%x bytes.\n",
255 ha->optrom_region_size));
257 vfree(ha->optrom_buffer);
258 ha->optrom_buffer = NULL;
261 if (ha->optrom_state != QLA_SWAITING)
264 ha->optrom_region_start = start;
265 ha->optrom_region_size = start + size > ha->optrom_size ?
266 ha->optrom_size - start : size;
268 ha->optrom_state = QLA_SREADING;
269 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
270 if (ha->optrom_buffer == NULL) {
271 qla_printk(KERN_WARNING, ha,
272 "Unable to allocate memory for optrom retrieval "
273 "(%x).\n", ha->optrom_region_size);
275 ha->optrom_state = QLA_SWAITING;
279 DEBUG2(qla_printk(KERN_INFO, ha,
280 "Reading flash region -- 0x%x/0x%x.\n",
281 ha->optrom_region_start, ha->optrom_region_size));
283 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
284 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
285 ha->optrom_region_start, ha->optrom_region_size);
288 if (ha->optrom_state != QLA_SWAITING)
292 * We need to be more restrictive on which FLASH regions are
293 * allowed to be updated via user-space. Regions accessible
294 * via this method include:
296 * ISP21xx/ISP22xx/ISP23xx type boards:
298 * 0x000000 -> 0x020000 -- Boot code.
300 * ISP2322/ISP24xx type boards:
302 * 0x000000 -> 0x07ffff -- Boot code.
303 * 0x080000 -> 0x0fffff -- Firmware.
305 * ISP25xx type boards:
307 * 0x000000 -> 0x07ffff -- Boot code.
308 * 0x080000 -> 0x0fffff -- Firmware.
309 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
312 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
314 else if (start == (ha->flt_region_boot * 4) ||
315 start == (ha->flt_region_fw * 4))
317 else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
320 qla_printk(KERN_WARNING, ha,
321 "Invalid start region 0x%x/0x%x.\n", start, size);
325 ha->optrom_region_start = start;
326 ha->optrom_region_size = start + size > ha->optrom_size ?
327 ha->optrom_size - start : size;
329 ha->optrom_state = QLA_SWRITING;
330 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
331 if (ha->optrom_buffer == NULL) {
332 qla_printk(KERN_WARNING, ha,
333 "Unable to allocate memory for optrom update "
334 "(%x).\n", ha->optrom_region_size);
336 ha->optrom_state = QLA_SWAITING;
340 DEBUG2(qla_printk(KERN_INFO, ha,
341 "Staging flash region write -- 0x%x/0x%x.\n",
342 ha->optrom_region_start, ha->optrom_region_size));
344 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
347 if (ha->optrom_state != QLA_SWRITING)
350 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
351 qla_printk(KERN_WARNING, ha,
352 "HBA not online, failing flash update.\n");
356 DEBUG2(qla_printk(KERN_INFO, ha,
357 "Writing flash region -- 0x%x/0x%x.\n",
358 ha->optrom_region_start, ha->optrom_region_size));
360 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
361 ha->optrom_region_start, ha->optrom_region_size);
369 static struct bin_attribute sysfs_optrom_ctl_attr = {
371 .name = "optrom_ctl",
375 .write = qla2x00_sysfs_write_optrom_ctl,
379 qla2x00_sysfs_read_vpd(struct kobject *kobj,
380 struct bin_attribute *bin_attr,
381 char *buf, loff_t off, size_t count)
383 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
384 struct device, kobj)));
385 struct qla_hw_data *ha = vha->hw;
387 if (unlikely(pci_channel_offline(ha->pdev)))
390 if (!capable(CAP_SYS_ADMIN))
393 if (IS_NOCACHE_VPD_TYPE(ha))
394 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
396 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
400 qla2x00_sysfs_write_vpd(struct kobject *kobj,
401 struct bin_attribute *bin_attr,
402 char *buf, loff_t off, size_t count)
404 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
405 struct device, kobj)));
406 struct qla_hw_data *ha = vha->hw;
409 if (unlikely(pci_channel_offline(ha->pdev)))
412 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
413 !ha->isp_ops->write_nvram)
416 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
417 qla_printk(KERN_WARNING, ha,
418 "HBA not online, failing VPD update.\n");
423 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
424 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
426 /* Update flash version information for 4Gb & above. */
427 if (!IS_FWI2_CAPABLE(ha))
430 tmp_data = vmalloc(256);
432 qla_printk(KERN_WARNING, ha,
433 "Unable to allocate memory for VPD information update.\n");
436 ha->isp_ops->get_flash_version(vha, tmp_data);
442 static struct bin_attribute sysfs_vpd_attr = {
445 .mode = S_IRUSR | S_IWUSR,
448 .read = qla2x00_sysfs_read_vpd,
449 .write = qla2x00_sysfs_write_vpd,
453 qla2x00_sysfs_read_sfp(struct kobject *kobj,
454 struct bin_attribute *bin_attr,
455 char *buf, loff_t off, size_t count)
457 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
458 struct device, kobj)));
459 struct qla_hw_data *ha = vha->hw;
460 uint16_t iter, addr, offset;
463 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
469 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
472 qla_printk(KERN_WARNING, ha,
473 "Unable to allocate memory for SFP read-data.\n");
478 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
480 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
481 iter++, offset += SFP_BLOCK_SIZE) {
483 /* Skip to next device address. */
488 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
490 if (rval != QLA_SUCCESS) {
491 qla_printk(KERN_WARNING, ha,
492 "Unable to read SFP data (%x/%x/%x).\n", rval,
497 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
498 buf += SFP_BLOCK_SIZE;
504 static struct bin_attribute sysfs_sfp_attr = {
507 .mode = S_IRUSR | S_IWUSR,
509 .size = SFP_DEV_SIZE * 2,
510 .read = qla2x00_sysfs_read_sfp,
514 qla2x00_sysfs_write_reset(struct kobject *kobj,
515 struct bin_attribute *bin_attr,
516 char *buf, loff_t off, size_t count)
518 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
519 struct device, kobj)));
520 struct qla_hw_data *ha = vha->hw;
526 type = simple_strtol(buf, NULL, 10);
529 qla_printk(KERN_INFO, ha,
530 "Issuing ISP reset on (%ld).\n", vha->host_no);
532 scsi_block_requests(vha->host);
533 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
534 qla2xxx_wake_dpc(vha);
535 qla2x00_wait_for_chip_reset(vha);
536 scsi_unblock_requests(vha->host);
542 qla_printk(KERN_INFO, ha,
543 "Issuing MPI reset on (%ld).\n", vha->host_no);
545 /* Make sure FC side is not in reset */
546 qla2x00_wait_for_hba_online(vha);
548 /* Issue MPI reset */
549 scsi_block_requests(vha->host);
550 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
551 qla_printk(KERN_WARNING, ha,
552 "MPI reset failed on (%ld).\n", vha->host_no);
553 scsi_unblock_requests(vha->host);
559 static struct bin_attribute sysfs_reset_attr = {
565 .write = qla2x00_sysfs_write_reset,
569 qla2x00_sysfs_write_edc(struct kobject *kobj,
570 struct bin_attribute *bin_attr,
571 char *buf, loff_t off, size_t count)
573 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
574 struct device, kobj)));
575 struct qla_hw_data *ha = vha->hw;
576 uint16_t dev, adr, opt, len;
579 ha->edc_data_len = 0;
581 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
585 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
588 DEBUG2(qla_printk(KERN_INFO, ha,
589 "Unable to allocate memory for EDC write.\n"));
594 dev = le16_to_cpup((void *)&buf[0]);
595 adr = le16_to_cpup((void *)&buf[2]);
596 opt = le16_to_cpup((void *)&buf[4]);
597 len = le16_to_cpup((void *)&buf[6]);
600 if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
603 memcpy(ha->edc_data, &buf[8], len);
605 rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
606 ha->edc_data, len, opt);
607 if (rval != QLA_SUCCESS) {
608 DEBUG2(qla_printk(KERN_INFO, ha,
609 "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
610 rval, dev, adr, opt, len, *buf));
617 static struct bin_attribute sysfs_edc_attr = {
623 .write = qla2x00_sysfs_write_edc,
627 qla2x00_sysfs_write_edc_status(struct kobject *kobj,
628 struct bin_attribute *bin_attr,
629 char *buf, loff_t off, size_t count)
631 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
632 struct device, kobj)));
633 struct qla_hw_data *ha = vha->hw;
634 uint16_t dev, adr, opt, len;
637 ha->edc_data_len = 0;
639 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
643 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
646 DEBUG2(qla_printk(KERN_INFO, ha,
647 "Unable to allocate memory for EDC status.\n"));
652 dev = le16_to_cpup((void *)&buf[0]);
653 adr = le16_to_cpup((void *)&buf[2]);
654 opt = le16_to_cpup((void *)&buf[4]);
655 len = le16_to_cpup((void *)&buf[6]);
658 if (len == 0 || len > DMA_POOL_SIZE)
661 memset(ha->edc_data, 0, len);
662 rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
663 ha->edc_data, len, opt);
664 if (rval != QLA_SUCCESS) {
665 DEBUG2(qla_printk(KERN_INFO, ha,
666 "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
667 rval, dev, adr, opt, len));
671 ha->edc_data_len = len;
677 qla2x00_sysfs_read_edc_status(struct kobject *kobj,
678 struct bin_attribute *bin_attr,
679 char *buf, loff_t off, size_t count)
681 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
682 struct device, kobj)));
683 struct qla_hw_data *ha = vha->hw;
685 if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
688 if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
691 memcpy(buf, ha->edc_data, ha->edc_data_len);
693 return ha->edc_data_len;
696 static struct bin_attribute sysfs_edc_status_attr = {
698 .name = "edc_status",
699 .mode = S_IRUSR | S_IWUSR,
702 .write = qla2x00_sysfs_write_edc_status,
703 .read = qla2x00_sysfs_read_edc_status,
707 qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
708 struct bin_attribute *bin_attr,
709 char *buf, loff_t off, size_t count)
711 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
712 struct device, kobj)));
713 struct qla_hw_data *ha = vha->hw;
715 uint16_t actual_size;
717 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
723 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
724 &ha->xgmac_data_dma, GFP_KERNEL);
725 if (!ha->xgmac_data) {
726 qla_printk(KERN_WARNING, ha,
727 "Unable to allocate memory for XGMAC read-data.\n");
733 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
735 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
736 XGMAC_DATA_SIZE, &actual_size);
737 if (rval != QLA_SUCCESS) {
738 qla_printk(KERN_WARNING, ha,
739 "Unable to read XGMAC data (%x).\n", rval);
743 count = actual_size > count ? count: actual_size;
744 memcpy(buf, ha->xgmac_data, count);
749 static struct bin_attribute sysfs_xgmac_stats_attr = {
751 .name = "xgmac_stats",
755 .read = qla2x00_sysfs_read_xgmac_stats,
759 qla2x00_sysfs_read_dcbx_tlv(struct kobject *kobj,
760 struct bin_attribute *bin_attr,
761 char *buf, loff_t off, size_t count)
763 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
764 struct device, kobj)));
765 struct qla_hw_data *ha = vha->hw;
767 uint16_t actual_size;
769 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > DCBX_TLV_DATA_SIZE)
775 ha->dcbx_tlv = dma_alloc_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
776 &ha->dcbx_tlv_dma, GFP_KERNEL);
778 qla_printk(KERN_WARNING, ha,
779 "Unable to allocate memory for DCBX TLV read-data.\n");
785 memset(ha->dcbx_tlv, 0, DCBX_TLV_DATA_SIZE);
787 rval = qla2x00_get_dcbx_params(vha, ha->dcbx_tlv_dma,
789 if (rval != QLA_SUCCESS) {
790 qla_printk(KERN_WARNING, ha,
791 "Unable to read DCBX TLV data (%x).\n", rval);
795 memcpy(buf, ha->dcbx_tlv, count);
800 static struct bin_attribute sysfs_dcbx_tlv_attr = {
806 .read = qla2x00_sysfs_read_dcbx_tlv,
809 static struct sysfs_entry {
811 struct bin_attribute *attr;
813 } bin_file_entries[] = {
814 { "fw_dump", &sysfs_fw_dump_attr, },
815 { "nvram", &sysfs_nvram_attr, },
816 { "optrom", &sysfs_optrom_attr, },
817 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
818 { "vpd", &sysfs_vpd_attr, 1 },
819 { "sfp", &sysfs_sfp_attr, 1 },
820 { "reset", &sysfs_reset_attr, },
821 { "edc", &sysfs_edc_attr, 2 },
822 { "edc_status", &sysfs_edc_status_attr, 2 },
823 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
824 { "dcbx_tlv", &sysfs_dcbx_tlv_attr, 3 },
829 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
831 struct Scsi_Host *host = vha->host;
832 struct sysfs_entry *iter;
835 for (iter = bin_file_entries; iter->name; iter++) {
836 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
838 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
840 if (iter->is4GBp_only == 3 && !IS_QLA81XX(vha->hw))
843 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
846 qla_printk(KERN_INFO, vha->hw,
847 "Unable to create sysfs %s binary attribute "
848 "(%d).\n", iter->name, ret);
853 qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
855 struct Scsi_Host *host = vha->host;
856 struct sysfs_entry *iter;
857 struct qla_hw_data *ha = vha->hw;
859 for (iter = bin_file_entries; iter->name; iter++) {
860 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
862 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
864 if (iter->is4GBp_only == 3 && !IS_QLA81XX(ha))
867 sysfs_remove_bin_file(&host->shost_gendev.kobj,
871 if (ha->beacon_blink_led == 1)
872 ha->isp_ops->beacon_off(vha);
875 /* Scsi_Host attributes. */
878 qla2x00_drvr_version_show(struct device *dev,
879 struct device_attribute *attr, char *buf)
881 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
885 qla2x00_fw_version_show(struct device *dev,
886 struct device_attribute *attr, char *buf)
888 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
889 struct qla_hw_data *ha = vha->hw;
892 return snprintf(buf, PAGE_SIZE, "%s\n",
893 ha->isp_ops->fw_version_str(vha, fw_str));
897 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
900 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
901 struct qla_hw_data *ha = vha->hw;
904 if (IS_FWI2_CAPABLE(ha)) {
905 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
906 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
909 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
910 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
915 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
918 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
919 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
923 qla2x00_isp_id_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;
928 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
929 ha->product_id[0], ha->product_id[1], ha->product_id[2],
934 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
937 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
938 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
942 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
945 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
946 return snprintf(buf, PAGE_SIZE, "%s\n",
947 vha->hw->model_desc ? vha->hw->model_desc : "");
951 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
954 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
957 return snprintf(buf, PAGE_SIZE, "%s\n",
958 vha->hw->isp_ops->pci_info_str(vha, pci_info));
962 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
965 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
966 struct qla_hw_data *ha = vha->hw;
969 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
970 atomic_read(&vha->loop_state) == LOOP_DEAD)
971 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
972 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
973 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
974 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
975 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
977 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
979 switch (ha->current_topology) {
981 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
984 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
987 len += snprintf(buf + len, PAGE_SIZE-len,
988 "N_Port to N_Port\n");
991 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
994 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1002 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1005 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1008 switch (vha->hw->zio_mode) {
1009 case QLA_ZIO_MODE_6:
1010 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1012 case QLA_ZIO_DISABLED:
1013 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1020 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1021 const char *buf, size_t count)
1023 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1024 struct qla_hw_data *ha = vha->hw;
1028 if (!IS_ZIO_SUPPORTED(ha))
1031 if (sscanf(buf, "%d", &val) != 1)
1035 zio_mode = QLA_ZIO_MODE_6;
1037 zio_mode = QLA_ZIO_DISABLED;
1039 /* Update per-hba values and queue a reset. */
1040 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1041 ha->zio_mode = zio_mode;
1042 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1048 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1051 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1053 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
1057 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1058 const char *buf, size_t count)
1060 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1064 if (sscanf(buf, "%d", &val) != 1)
1066 if (val > 25500 || val < 100)
1069 zio_timer = (uint16_t)(val / 100);
1070 vha->hw->zio_timer = zio_timer;
1076 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1079 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1082 if (vha->hw->beacon_blink_led)
1083 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1085 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1090 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1091 const char *buf, size_t count)
1093 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1094 struct qla_hw_data *ha = vha->hw;
1098 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1101 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
1102 qla_printk(KERN_WARNING, ha,
1103 "Abort ISP active -- ignoring beacon request.\n");
1107 if (sscanf(buf, "%d", &val) != 1)
1111 rval = ha->isp_ops->beacon_on(vha);
1113 rval = ha->isp_ops->beacon_off(vha);
1115 if (rval != QLA_SUCCESS)
1122 qla2x00_optrom_bios_version_show(struct device *dev,
1123 struct device_attribute *attr, char *buf)
1125 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1126 struct qla_hw_data *ha = vha->hw;
1127 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1128 ha->bios_revision[0]);
1132 qla2x00_optrom_efi_version_show(struct device *dev,
1133 struct device_attribute *attr, char *buf)
1135 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1136 struct qla_hw_data *ha = vha->hw;
1137 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1138 ha->efi_revision[0]);
1142 qla2x00_optrom_fcode_version_show(struct device *dev,
1143 struct device_attribute *attr, char *buf)
1145 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1146 struct qla_hw_data *ha = vha->hw;
1147 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1148 ha->fcode_revision[0]);
1152 qla2x00_optrom_fw_version_show(struct device *dev,
1153 struct device_attribute *attr, char *buf)
1155 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1156 struct qla_hw_data *ha = vha->hw;
1157 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1158 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1159 ha->fw_revision[3]);
1163 qla2x00_total_isp_aborts_show(struct device *dev,
1164 struct device_attribute *attr, char *buf)
1166 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1167 struct qla_hw_data *ha = vha->hw;
1168 return snprintf(buf, PAGE_SIZE, "%d\n",
1169 ha->qla_stats.total_isp_aborts);
1173 qla24xx_84xx_fw_version_show(struct device *dev,
1174 struct device_attribute *attr, char *buf)
1176 int rval = QLA_SUCCESS;
1177 uint16_t status[2] = {0, 0};
1178 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1179 struct qla_hw_data *ha = vha->hw;
1181 if (IS_QLA84XX(ha) && ha->cs84xx) {
1182 if (ha->cs84xx->op_fw_version == 0) {
1183 rval = qla84xx_verify_chip(vha, status);
1186 if ((rval == QLA_SUCCESS) && (status[0] == 0))
1187 return snprintf(buf, PAGE_SIZE, "%u\n",
1188 (uint32_t)ha->cs84xx->op_fw_version);
1191 return snprintf(buf, PAGE_SIZE, "\n");
1195 qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1198 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1199 struct qla_hw_data *ha = vha->hw;
1201 if (!IS_QLA81XX(ha))
1202 return snprintf(buf, PAGE_SIZE, "\n");
1204 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
1205 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
1206 ha->mpi_capabilities);
1210 qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1213 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1214 struct qla_hw_data *ha = vha->hw;
1216 if (!IS_QLA81XX(ha))
1217 return snprintf(buf, PAGE_SIZE, "\n");
1219 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1220 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
1224 qla2x00_flash_block_size_show(struct device *dev,
1225 struct device_attribute *attr, char *buf)
1227 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1228 struct qla_hw_data *ha = vha->hw;
1230 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1234 qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1237 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1239 if (!IS_QLA81XX(vha->hw))
1240 return snprintf(buf, PAGE_SIZE, "\n");
1242 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1246 qla2x00_vn_port_mac_address_show(struct device *dev,
1247 struct device_attribute *attr, char *buf)
1249 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1251 if (!IS_QLA81XX(vha->hw))
1252 return snprintf(buf, PAGE_SIZE, "\n");
1254 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1255 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1256 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1257 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1261 qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1264 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1266 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1270 qla2x00_fw_state_show(struct device *dev, struct device_attribute *attr,
1273 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1274 int rval = QLA_FUNCTION_FAILED;
1277 if (!vha->hw->flags.eeh_busy)
1278 rval = qla2x00_get_firmware_state(vha, state);
1279 if (rval != QLA_SUCCESS)
1280 memset(state, -1, sizeof(state));
1282 return snprintf(buf, PAGE_SIZE, "0x%x 0x%x 0x%x 0x%x 0x%x\n", state[0],
1283 state[1], state[2], state[3], state[4]);
1286 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1287 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1288 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1289 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1290 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1291 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1292 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1293 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
1294 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
1295 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1296 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1297 qla2x00_zio_timer_store);
1298 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1299 qla2x00_beacon_store);
1300 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1301 qla2x00_optrom_bios_version_show, NULL);
1302 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1303 qla2x00_optrom_efi_version_show, NULL);
1304 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1305 qla2x00_optrom_fcode_version_show, NULL);
1306 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1308 static DEVICE_ATTR(84xx_fw_version, S_IRUGO, qla24xx_84xx_fw_version_show,
1310 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1312 static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
1313 static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
1314 static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1316 static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1317 static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1318 qla2x00_vn_port_mac_address_show, NULL);
1319 static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
1320 static DEVICE_ATTR(fw_state, S_IRUGO, qla2x00_fw_state_show, NULL);
1322 struct device_attribute *qla2x00_host_attrs[] = {
1323 &dev_attr_driver_version,
1324 &dev_attr_fw_version,
1325 &dev_attr_serial_num,
1328 &dev_attr_model_name,
1329 &dev_attr_model_desc,
1331 &dev_attr_link_state,
1333 &dev_attr_zio_timer,
1335 &dev_attr_optrom_bios_version,
1336 &dev_attr_optrom_efi_version,
1337 &dev_attr_optrom_fcode_version,
1338 &dev_attr_optrom_fw_version,
1339 &dev_attr_84xx_fw_version,
1340 &dev_attr_total_isp_aborts,
1341 &dev_attr_mpi_version,
1342 &dev_attr_phy_version,
1343 &dev_attr_flash_block_size,
1345 &dev_attr_vn_port_mac_address,
1346 &dev_attr_fabric_param,
1351 /* Host attributes. */
1354 qla2x00_get_host_port_id(struct Scsi_Host *shost)
1356 scsi_qla_host_t *vha = shost_priv(shost);
1358 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1359 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
1363 qla2x00_get_host_speed(struct Scsi_Host *shost)
1365 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1366 (shost_priv(shost)))->hw;
1367 u32 speed = FC_PORTSPEED_UNKNOWN;
1369 switch (ha->link_data_rate) {
1370 case PORT_SPEED_1GB:
1371 speed = FC_PORTSPEED_1GBIT;
1373 case PORT_SPEED_2GB:
1374 speed = FC_PORTSPEED_2GBIT;
1376 case PORT_SPEED_4GB:
1377 speed = FC_PORTSPEED_4GBIT;
1379 case PORT_SPEED_8GB:
1380 speed = FC_PORTSPEED_8GBIT;
1382 case PORT_SPEED_10GB:
1383 speed = FC_PORTSPEED_10GBIT;
1386 fc_host_speed(shost) = speed;
1390 qla2x00_get_host_port_type(struct Scsi_Host *shost)
1392 scsi_qla_host_t *vha = shost_priv(shost);
1393 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1396 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1399 switch (vha->hw->current_topology) {
1401 port_type = FC_PORTTYPE_LPORT;
1404 port_type = FC_PORTTYPE_NLPORT;
1407 port_type = FC_PORTTYPE_PTP;
1410 port_type = FC_PORTTYPE_NPORT;
1413 fc_host_port_type(shost) = port_type;
1417 qla2x00_get_starget_node_name(struct scsi_target *starget)
1419 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1420 scsi_qla_host_t *vha = shost_priv(host);
1424 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1425 if (fcport->rport &&
1426 starget->id == fcport->rport->scsi_target_id) {
1427 node_name = wwn_to_u64(fcport->node_name);
1432 fc_starget_node_name(starget) = node_name;
1436 qla2x00_get_starget_port_name(struct scsi_target *starget)
1438 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1439 scsi_qla_host_t *vha = shost_priv(host);
1443 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1444 if (fcport->rport &&
1445 starget->id == fcport->rport->scsi_target_id) {
1446 port_name = wwn_to_u64(fcport->port_name);
1451 fc_starget_port_name(starget) = port_name;
1455 qla2x00_get_starget_port_id(struct scsi_target *starget)
1457 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1458 scsi_qla_host_t *vha = shost_priv(host);
1460 uint32_t port_id = ~0U;
1462 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1463 if (fcport->rport &&
1464 starget->id == fcport->rport->scsi_target_id) {
1465 port_id = fcport->d_id.b.domain << 16 |
1466 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1471 fc_starget_port_id(starget) = port_id;
1475 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1478 rport->dev_loss_tmo = timeout;
1480 rport->dev_loss_tmo = 1;
1484 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1486 struct Scsi_Host *host = rport_to_shost(rport);
1487 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1492 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1495 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1496 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1501 * Transport has effectively 'deleted' the rport, clear
1502 * all local references.
1504 spin_lock_irq(host->host_lock);
1505 fcport->rport = NULL;
1506 *((fc_port_t **)rport->dd_data) = NULL;
1507 spin_unlock_irq(host->host_lock);
1511 qla2x00_terminate_rport_io(struct fc_rport *rport)
1513 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1518 if (test_bit(ABORT_ISP_ACTIVE, &fcport->vha->dpc_flags))
1521 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1522 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1526 * At this point all fcport's software-states are cleared. Perform any
1527 * final cleanup of firmware resources (PCBs and XCBs).
1529 if (fcport->loop_id != FC_NO_LOOP_ID &&
1530 !test_bit(UNLOADING, &fcport->vha->dpc_flags))
1531 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1532 fcport->loop_id, fcport->d_id.b.domain,
1533 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1535 qla2x00_abort_fcport_cmds(fcport);
1539 qla2x00_issue_lip(struct Scsi_Host *shost)
1541 scsi_qla_host_t *vha = shost_priv(shost);
1543 qla2x00_loop_reset(vha);
1547 static struct fc_host_statistics *
1548 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1550 scsi_qla_host_t *vha = shost_priv(shost);
1551 struct qla_hw_data *ha = vha->hw;
1552 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1554 struct link_statistics *stats;
1555 dma_addr_t stats_dma;
1556 struct fc_host_statistics *pfc_host_stat;
1558 pfc_host_stat = &ha->fc_host_stat;
1559 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1561 if (test_bit(UNLOADING, &vha->dpc_flags))
1564 if (unlikely(pci_channel_offline(ha->pdev)))
1567 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1568 if (stats == NULL) {
1569 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1570 __func__, base_vha->host_no));
1573 memset(stats, 0, DMA_POOL_SIZE);
1575 rval = QLA_FUNCTION_FAILED;
1576 if (IS_FWI2_CAPABLE(ha)) {
1577 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1578 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1579 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1580 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1582 /* Must be in a 'READY' state for statistics retrieval. */
1583 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1587 if (rval != QLA_SUCCESS)
1590 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1591 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1592 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1593 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1594 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1595 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1596 if (IS_FWI2_CAPABLE(ha)) {
1597 pfc_host_stat->lip_count = stats->lip_cnt;
1598 pfc_host_stat->tx_frames = stats->tx_frames;
1599 pfc_host_stat->rx_frames = stats->rx_frames;
1600 pfc_host_stat->dumped_frames = stats->dumped_frames;
1601 pfc_host_stat->nos_count = stats->nos_rcvd;
1603 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1604 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
1607 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
1609 return pfc_host_stat;
1613 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1615 scsi_qla_host_t *vha = shost_priv(shost);
1617 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
1621 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1623 scsi_qla_host_t *vha = shost_priv(shost);
1625 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
1629 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1631 scsi_qla_host_t *vha = shost_priv(shost);
1634 if (vha->device_flags & SWITCH_FOUND)
1635 node_name = wwn_to_u64(vha->fabric_node_name);
1637 node_name = wwn_to_u64(vha->node_name);
1639 fc_host_fabric_name(shost) = node_name;
1643 qla2x00_get_host_port_state(struct Scsi_Host *shost)
1645 scsi_qla_host_t *vha = shost_priv(shost);
1646 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
1648 if (!base_vha->flags.online)
1649 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1650 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
1651 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1653 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
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 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1671 "status %x\n", ret));
1675 vha = qla24xx_create_vhost(fc_vport);
1677 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1679 return FC_VPORT_FAILED;
1682 atomic_set(&vha->vp_state, VP_OFFLINE);
1683 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1685 atomic_set(&vha->vp_state, VP_FAILED);
1687 /* ready to create vport */
1688 qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
1691 /* initialized vport states */
1692 atomic_set(&vha->loop_state, LOOP_DOWN);
1693 vha->vp_err_state= VP_ERR_PORTDWN;
1694 vha->vp_prev_err_state= VP_ERR_UNKWN;
1695 /* Check if physical ha port is Up */
1696 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1697 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
1698 /* Don't retry or attempt login of this virtual port */
1699 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1700 base_vha->host_no));
1701 atomic_set(&vha->loop_state, LOOP_DEAD);
1703 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1706 if (scsi_add_host_with_dma(vha->host, &fc_vport->dev,
1708 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1709 vha->host_no, vha->vp_idx));
1710 goto vport_create_failed_2;
1713 /* initialize attributes */
1714 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1715 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1716 fc_host_supported_classes(vha->host) =
1717 fc_host_supported_classes(base_vha->host);
1718 fc_host_supported_speeds(vha->host) =
1719 fc_host_supported_speeds(base_vha->host);
1721 qla24xx_vport_disable(fc_vport, disable);
1723 if (ha->flags.cpu_affinity_enabled) {
1724 req = ha->req_q_map[1];
1726 } else if (ql2xmaxqueues == 1 || !ha->npiv_info)
1728 /* Create a request queue in QoS mode for the vport */
1729 for (cnt = 0; cnt < ha->nvram_npiv_size; cnt++) {
1730 if (memcmp(ha->npiv_info[cnt].port_name, vha->port_name, 8) == 0
1731 && memcmp(ha->npiv_info[cnt].node_name, vha->node_name,
1733 qos = ha->npiv_info[cnt].q_qos;
1738 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1741 qla_printk(KERN_WARNING, ha,
1742 "Can't create request queue for vp_idx:%d\n",
1745 DEBUG2(qla_printk(KERN_INFO, ha,
1746 "Request Que:%d (QoS: %d) created for vp_idx:%d\n",
1747 ret, qos, vha->vp_idx));
1748 req = ha->req_q_map[ret];
1756 vport_create_failed_2:
1757 qla24xx_disable_vp(vha);
1758 qla24xx_deallocate_vp_id(vha);
1759 scsi_host_put(vha->host);
1760 return FC_VPORT_FAILED;
1764 qla24xx_vport_delete(struct fc_vport *fc_vport)
1766 scsi_qla_host_t *vha = fc_vport->dd_data;
1767 fc_port_t *fcport, *tfcport;
1768 struct qla_hw_data *ha = vha->hw;
1769 uint16_t id = vha->vp_idx;
1771 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
1772 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
1775 qla24xx_disable_vp(vha);
1777 fc_remove_host(vha->host);
1779 scsi_remove_host(vha->host);
1781 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
1782 list_del(&fcport->list);
1787 qla24xx_deallocate_vp_id(vha);
1789 mutex_lock(&ha->vport_lock);
1790 ha->cur_vport_count--;
1791 clear_bit(vha->vp_idx, ha->vp_idx_map);
1792 mutex_unlock(&ha->vport_lock);
1794 if (vha->timer_active) {
1795 qla2x00_vp_stop_timer(vha);
1796 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1798 vha->host_no, vha->vp_idx, vha));
1801 if (vha->req->id && !ha->flags.cpu_affinity_enabled) {
1802 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
1803 qla_printk(KERN_WARNING, ha,
1804 "Queue delete failed.\n");
1807 scsi_host_put(vha->host);
1808 qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
1813 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1815 scsi_qla_host_t *vha = fc_vport->dd_data;
1818 qla24xx_disable_vp(vha);
1820 qla24xx_enable_vp(vha);
1825 /* BSG support for ELS/CT pass through */
1827 qla2x00_get_ctx_bsg_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size)
1830 struct qla_hw_data *ha = vha->hw;
1831 struct srb_bsg_ctx *ctx;
1833 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
1836 ctx = kzalloc(size, GFP_KERNEL);
1838 mempool_free(sp, ha->srb_mempool);
1842 memset(sp, 0, sizeof(*sp));
1843 sp->fcport = fcport;
1850 qla2x00_process_els(struct fc_bsg_job *bsg_job)
1852 struct fc_rport *rport;
1854 struct Scsi_Host *host;
1855 scsi_qla_host_t *vha;
1856 struct qla_hw_data *ha;
1859 int req_sg_cnt, rsp_sg_cnt;
1860 int rval = (DRIVER_ERROR << 16);
1861 uint16_t nextlid = 0;
1862 struct srb_bsg *els;
1864 /* Multiple SG's are not supported for ELS requests */
1865 if (bsg_job->request_payload.sg_cnt > 1 ||
1866 bsg_job->reply_payload.sg_cnt > 1) {
1867 DEBUG2(printk(KERN_INFO
1868 "multiple SG's are not supported for ELS requests"
1869 " [request_sg_cnt: %x reply_sg_cnt: %x]\n",
1870 bsg_job->request_payload.sg_cnt,
1871 bsg_job->reply_payload.sg_cnt));
1876 /* ELS request for rport */
1877 if (bsg_job->request->msgcode == FC_BSG_RPT_ELS) {
1878 rport = bsg_job->rport;
1879 fcport = *(fc_port_t **) rport->dd_data;
1880 host = rport_to_shost(rport);
1881 vha = shost_priv(host);
1883 type = "FC_BSG_RPT_ELS";
1885 /* make sure the rport is logged in,
1886 * if not perform fabric login
1888 if (qla2x00_fabric_login(vha, fcport, &nextlid)) {
1889 DEBUG2(qla_printk(KERN_WARNING, ha,
1890 "failed to login port %06X for ELS passthru\n",
1896 host = bsg_job->shost;
1897 vha = shost_priv(host);
1899 type = "FC_BSG_HST_ELS_NOLOGIN";
1901 /* Allocate a dummy fcport structure, since functions
1902 * preparing the IOCB and mailbox command retrieves port
1903 * specific information from fcport structure. For Host based
1904 * ELS commands there will be no fcport structure allocated
1906 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1912 /* Initialize all required fields of fcport */
1914 fcport->vp_idx = vha->vp_idx;
1915 fcport->d_id.b.al_pa =
1916 bsg_job->request->rqst_data.h_els.port_id[0];
1917 fcport->d_id.b.area =
1918 bsg_job->request->rqst_data.h_els.port_id[1];
1919 fcport->d_id.b.domain =
1920 bsg_job->request->rqst_data.h_els.port_id[2];
1922 (fcport->d_id.b.al_pa == 0xFD) ?
1923 NPH_FABRIC_CONTROLLER : NPH_F_PORT;
1926 if (!vha->flags.online) {
1927 DEBUG2(qla_printk(KERN_WARNING, ha,
1928 "host not online\n"));
1934 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1935 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1938 goto done_free_fcport;
1940 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1941 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1944 goto done_free_fcport;
1947 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
1948 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
1950 DEBUG2(printk(KERN_INFO
1951 "dma mapping resulted in different sg counts \
1952 [request_sg_cnt: %x dma_request_sg_cnt: %x\
1953 reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
1954 bsg_job->request_payload.sg_cnt, req_sg_cnt,
1955 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
1960 /* Alloc SRB structure */
1961 sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
1969 (bsg_job->request->msgcode == FC_BSG_RPT_ELS ?
1970 SRB_ELS_CMD_RPT : SRB_ELS_CMD_HST);
1971 els->bsg_job = bsg_job;
1973 DEBUG2(qla_printk(KERN_INFO, ha,
1974 "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
1975 "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
1976 bsg_job->request->rqst_data.h_els.command_code,
1977 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
1978 fcport->d_id.b.al_pa));
1980 rval = qla2x00_start_sp(sp);
1981 if (rval != QLA_SUCCESS) {
1983 mempool_free(sp, ha->srb_mempool);
1990 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
1991 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
1992 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
1993 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
1994 goto done_free_fcport;
1997 if (bsg_job->request->msgcode == FC_BSG_HST_ELS_NOLOGIN)
2004 qla2x00_process_ct(struct fc_bsg_job *bsg_job)
2007 struct Scsi_Host *host = bsg_job->shost;
2008 scsi_qla_host_t *vha = shost_priv(host);
2009 struct qla_hw_data *ha = vha->hw;
2010 int rval = (DRIVER_ERROR << 16);
2011 int req_sg_cnt, rsp_sg_cnt;
2013 struct fc_port *fcport;
2014 char *type = "FC_BSG_HST_CT";
2017 /* pass through is supported only for ISP 4Gb or higher */
2018 if (!IS_FWI2_CAPABLE(ha)) {
2019 DEBUG2(qla_printk(KERN_INFO, ha,
2020 "scsi(%ld):Firmware is not capable to support FC "
2021 "CT pass thru\n", vha->host_no));
2027 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
2028 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2034 rsp_sg_cnt = dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
2035 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2041 if ((req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
2042 (rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
2044 DEBUG2(qla_printk(KERN_WARNING, ha,
2045 "dma mapping resulted in different sg counts \
2046 [request_sg_cnt: %x dma_request_sg_cnt: %x\
2047 reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
2048 bsg_job->request_payload.sg_cnt, req_sg_cnt,
2049 bsg_job->reply_payload.sg_cnt, rsp_sg_cnt));
2054 if (!vha->flags.online) {
2055 DEBUG2(qla_printk(KERN_WARNING, ha,
2056 "host not online\n"));
2062 (bsg_job->request->rqst_data.h_ct.preamble_word1 & 0xFF000000)
2066 loop_id = cpu_to_le16(NPH_SNS);
2069 loop_id = vha->mgmt_svr_loop_id;
2072 DEBUG2(qla_printk(KERN_INFO, ha,
2073 "Unknown loop id: %x\n", loop_id));
2078 /* Allocate a dummy fcport structure, since functions preparing the
2079 * IOCB and mailbox command retrieves port specific information
2080 * from fcport structure. For Host based ELS commands there will be
2081 * no fcport structure allocated
2083 fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
2090 /* Initialize all required fields of fcport */
2092 fcport->vp_idx = vha->vp_idx;
2093 fcport->d_id.b.al_pa = bsg_job->request->rqst_data.h_ct.port_id[0];
2094 fcport->d_id.b.area = bsg_job->request->rqst_data.h_ct.port_id[1];
2095 fcport->d_id.b.domain = bsg_job->request->rqst_data.h_ct.port_id[2];
2096 fcport->loop_id = loop_id;
2098 /* Alloc SRB structure */
2099 sp = qla2x00_get_ctx_bsg_sp(vha, fcport, sizeof(struct srb_bsg));
2102 goto done_free_fcport;
2106 ct->ctx.type = SRB_CT_CMD;
2107 ct->bsg_job = bsg_job;
2109 DEBUG2(qla_printk(KERN_INFO, ha,
2110 "scsi(%ld:%x): bsg rqst type: %s els type: %x - loop-id=%x "
2111 "portid=%02x%02x%02x.\n", vha->host_no, sp->handle, type,
2112 (bsg_job->request->rqst_data.h_ct.preamble_word2 >> 16),
2113 fcport->loop_id, fcport->d_id.b.domain, fcport->d_id.b.area,
2114 fcport->d_id.b.al_pa));
2116 rval = qla2x00_start_sp(sp);
2117 if (rval != QLA_SUCCESS) {
2119 mempool_free(sp, ha->srb_mempool);
2121 goto done_free_fcport;
2128 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
2129 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2130 dma_unmap_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
2131 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2137 qla2x00_process_vendor_specific(struct fc_bsg_job *bsg_job)
2139 struct Scsi_Host *host = bsg_job->shost;
2140 scsi_qla_host_t *vha = shost_priv(host);
2141 struct qla_hw_data *ha = vha->hw;
2143 uint8_t command_sent;
2144 uint32_t vendor_cmd;
2146 struct msg_echo_lb elreq;
2147 uint16_t response[MAILBOX_REGISTER_COUNT];
2148 uint8_t* fw_sts_ptr;
2150 dma_addr_t req_data_dma;
2151 uint32_t req_data_len;
2153 dma_addr_t rsp_data_dma;
2154 uint32_t rsp_data_len;
2156 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
2157 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
2158 test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
2163 if (!vha->flags.online) {
2164 DEBUG2(qla_printk(KERN_WARNING, ha,
2165 "host not online\n"));
2171 dma_map_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
2172 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2173 if (!elreq.req_sg_cnt) {
2178 dma_map_sg(&ha->pdev->dev, bsg_job->reply_payload.sg_list,
2179 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2180 if (!elreq.rsp_sg_cnt) {
2185 if ((elreq.req_sg_cnt != bsg_job->request_payload.sg_cnt) ||
2186 (elreq.rsp_sg_cnt != bsg_job->reply_payload.sg_cnt))
2188 DEBUG2(printk(KERN_INFO
2189 "dma mapping resulted in different sg counts \
2190 [request_sg_cnt: %x dma_request_sg_cnt: %x\
2191 reply_sg_cnt: %x dma_reply_sg_cnt: %x]\n",
2192 bsg_job->request_payload.sg_cnt, elreq.req_sg_cnt,
2193 bsg_job->reply_payload.sg_cnt, elreq.rsp_sg_cnt));
2197 req_data_len = rsp_data_len = bsg_job->request_payload.payload_len;
2198 req_data = dma_alloc_coherent(&ha->pdev->dev, req_data_len,
2199 &req_data_dma, GFP_KERNEL);
2201 rsp_data = dma_alloc_coherent(&ha->pdev->dev, rsp_data_len,
2202 &rsp_data_dma, GFP_KERNEL);
2204 /* Copy the request buffer in req_data now */
2205 sg_copy_to_buffer(bsg_job->request_payload.sg_list,
2206 bsg_job->request_payload.sg_cnt, req_data,
2209 elreq.send_dma = req_data_dma;
2210 elreq.rcv_dma = rsp_data_dma;
2211 elreq.transfer_size = req_data_len;
2213 /* Vendor cmd : loopback or ECHO diagnostic
2215 * Loopback : Either internal or external loopback
2216 * ECHO: ECHO ELS or Vendor specific FC4 link data
2218 vendor_cmd = bsg_job->request->rqst_data.h_vendor.vendor_cmd[0];
2220 *(((uint32_t *)bsg_job->request->rqst_data.h_vendor.vendor_cmd)
2223 switch (bsg_job->request->rqst_data.h_vendor.vendor_cmd[0]) {
2224 case QL_VND_LOOPBACK:
2225 if (ha->current_topology != ISP_CFG_F) {
2226 type = "FC_BSG_HST_VENDOR_LOOPBACK";
2228 DEBUG2(qla_printk(KERN_INFO, ha,
2229 "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
2230 vha->host_no, type, vendor_cmd, elreq.options));
2232 command_sent = INT_DEF_LB_LOOPBACK_CMD;
2233 rval = qla2x00_loopback_test(vha, &elreq, response);
2234 if (IS_QLA81XX(ha)) {
2235 if (response[0] == MBS_COMMAND_ERROR && response[1] == MBS_LB_RESET) {
2236 DEBUG2(printk(KERN_ERR "%s(%ld): ABORTing "
2237 "ISP\n", __func__, vha->host_no));
2238 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2239 qla2xxx_wake_dpc(vha);
2243 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
2244 DEBUG2(qla_printk(KERN_INFO, ha,
2245 "scsi(%ld) bsg rqst type: %s vendor rqst type: %x options: %x.\n",
2246 vha->host_no, type, vendor_cmd, elreq.options));
2248 command_sent = INT_DEF_LB_ECHO_CMD;
2249 rval = qla2x00_echo_test(vha, &elreq, response);
2253 if (!IS_QLA84XX(vha->hw)) {
2256 "%s(%ld): 8xxx exiting.\n",
2257 __func__, vha->host_no));
2260 rval = qla84xx_reset(vha, &elreq, bsg_job);
2262 case QLA84_MGMT_CMD:
2263 if (!IS_QLA84XX(vha->hw)) {
2266 "%s(%ld): 8xxx exiting.\n",
2267 __func__, vha->host_no));
2270 rval = qla84xx_mgmt_cmd(vha, &elreq, bsg_job);
2276 if (rval != QLA_SUCCESS) {
2277 DEBUG2(qla_printk(KERN_WARNING, ha,
2278 "scsi(%ld) Vendor request %s failed\n", vha->host_no, type));
2280 bsg_job->reply->result = (DID_ERROR << 16);
2281 bsg_job->reply->reply_payload_rcv_len = 0;
2282 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
2283 memcpy( fw_sts_ptr, response, sizeof(response));
2284 fw_sts_ptr += sizeof(response);
2285 *fw_sts_ptr = command_sent;
2287 DEBUG2(qla_printk(KERN_WARNING, ha,
2288 "scsi(%ld) Vendor request %s completed\n", vha->host_no, type));
2289 rval = bsg_job->reply->result = 0;
2290 bsg_job->reply_len = sizeof(struct fc_bsg_reply) + sizeof(response) + sizeof(uint8_t);
2291 bsg_job->reply->reply_payload_rcv_len = bsg_job->reply_payload.payload_len;
2292 fw_sts_ptr = ((uint8_t*)bsg_job->req->sense) + sizeof(struct fc_bsg_reply);
2293 memcpy(fw_sts_ptr, response, sizeof(response));
2294 fw_sts_ptr += sizeof(response);
2295 *fw_sts_ptr = command_sent;
2296 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2297 bsg_job->reply_payload.sg_cnt, rsp_data,
2300 bsg_job->job_done(bsg_job);
2305 dma_free_coherent(&ha->pdev->dev, req_data_len,
2306 req_data, req_data_dma);
2307 dma_unmap_sg(&ha->pdev->dev,
2308 bsg_job->request_payload.sg_list,
2309 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
2310 dma_unmap_sg(&ha->pdev->dev,
2311 bsg_job->reply_payload.sg_list,
2312 bsg_job->reply_payload.sg_cnt, DMA_FROM_DEVICE);
2319 qla24xx_bsg_request(struct fc_bsg_job *bsg_job)
2323 switch (bsg_job->request->msgcode) {
2324 case FC_BSG_RPT_ELS:
2325 case FC_BSG_HST_ELS_NOLOGIN:
2326 ret = qla2x00_process_els(bsg_job);
2329 ret = qla2x00_process_ct(bsg_job);
2331 case FC_BSG_HST_VENDOR:
2332 ret = qla2x00_process_vendor_specific(bsg_job);
2334 case FC_BSG_HST_ADD_RPORT:
2335 case FC_BSG_HST_DEL_RPORT:
2338 DEBUG2(printk("qla2xxx: unsupported BSG request\n"));
2345 qla24xx_bsg_timeout(struct fc_bsg_job *bsg_job)
2347 scsi_qla_host_t *vha = shost_priv(bsg_job->shost);
2348 struct qla_hw_data *ha = vha->hw;
2351 unsigned long flags;
2352 struct req_que *req;
2353 struct srb_bsg *sp_bsg;
2355 /* find the bsg job from the active list of commands */
2356 spin_lock_irqsave(&ha->hardware_lock, flags);
2357 for (que = 0; que < ha->max_req_queues; que++) {
2358 req = ha->req_q_map[que];
2362 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++ ) {
2363 sp = req->outstanding_cmds[cnt];
2366 sp_bsg = (struct srb_bsg*)sp->ctx;
2368 if (((sp_bsg->ctx.type == SRB_CT_CMD) ||
2369 (sp_bsg->ctx.type == SRB_ELS_CMD_RPT)
2370 || ( sp_bsg->ctx.type == SRB_ELS_CMD_HST)) &&
2371 (sp_bsg->bsg_job == bsg_job)) {
2372 if (ha->isp_ops->abort_command(sp)) {
2373 DEBUG2(qla_printk(KERN_INFO, ha,
2374 "scsi(%ld): mbx abort_command failed\n", vha->host_no));
2375 bsg_job->req->errors = bsg_job->reply->result = -EIO;
2377 DEBUG2(qla_printk(KERN_INFO, ha,
2378 "scsi(%ld): mbx abort_command success\n", vha->host_no));
2379 bsg_job->req->errors = bsg_job->reply->result = 0;
2386 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2387 DEBUG2(qla_printk(KERN_INFO, ha,
2388 "scsi(%ld) SRB not found to abort\n", vha->host_no));
2389 bsg_job->req->errors = bsg_job->reply->result = -ENXIO;
2393 if (bsg_job->request->msgcode == FC_BSG_HST_CT)
2396 mempool_free(sp, ha->srb_mempool);
2400 struct fc_function_template qla2xxx_transport_functions = {
2402 .show_host_node_name = 1,
2403 .show_host_port_name = 1,
2404 .show_host_supported_classes = 1,
2405 .show_host_supported_speeds = 1,
2407 .get_host_port_id = qla2x00_get_host_port_id,
2408 .show_host_port_id = 1,
2409 .get_host_speed = qla2x00_get_host_speed,
2410 .show_host_speed = 1,
2411 .get_host_port_type = qla2x00_get_host_port_type,
2412 .show_host_port_type = 1,
2413 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
2414 .show_host_symbolic_name = 1,
2415 .set_host_system_hostname = qla2x00_set_host_system_hostname,
2416 .show_host_system_hostname = 1,
2417 .get_host_fabric_name = qla2x00_get_host_fabric_name,
2418 .show_host_fabric_name = 1,
2419 .get_host_port_state = qla2x00_get_host_port_state,
2420 .show_host_port_state = 1,
2422 .dd_fcrport_size = sizeof(struct fc_port *),
2423 .show_rport_supported_classes = 1,
2425 .get_starget_node_name = qla2x00_get_starget_node_name,
2426 .show_starget_node_name = 1,
2427 .get_starget_port_name = qla2x00_get_starget_port_name,
2428 .show_starget_port_name = 1,
2429 .get_starget_port_id = qla2x00_get_starget_port_id,
2430 .show_starget_port_id = 1,
2432 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
2433 .show_rport_dev_loss_tmo = 1,
2435 .issue_fc_host_lip = qla2x00_issue_lip,
2436 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
2437 .terminate_rport_io = qla2x00_terminate_rport_io,
2438 .get_fc_host_stats = qla2x00_get_fc_host_stats,
2440 .vport_create = qla24xx_vport_create,
2441 .vport_disable = qla24xx_vport_disable,
2442 .vport_delete = qla24xx_vport_delete,
2443 .bsg_request = qla24xx_bsg_request,
2444 .bsg_timeout = qla24xx_bsg_timeout,
2447 struct fc_function_template qla2xxx_transport_vport_functions = {
2449 .show_host_node_name = 1,
2450 .show_host_port_name = 1,
2451 .show_host_supported_classes = 1,
2453 .get_host_port_id = qla2x00_get_host_port_id,
2454 .show_host_port_id = 1,
2455 .get_host_speed = qla2x00_get_host_speed,
2456 .show_host_speed = 1,
2457 .get_host_port_type = qla2x00_get_host_port_type,
2458 .show_host_port_type = 1,
2459 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
2460 .show_host_symbolic_name = 1,
2461 .set_host_system_hostname = qla2x00_set_host_system_hostname,
2462 .show_host_system_hostname = 1,
2463 .get_host_fabric_name = qla2x00_get_host_fabric_name,
2464 .show_host_fabric_name = 1,
2465 .get_host_port_state = qla2x00_get_host_port_state,
2466 .show_host_port_state = 1,
2468 .dd_fcrport_size = sizeof(struct fc_port *),
2469 .show_rport_supported_classes = 1,
2471 .get_starget_node_name = qla2x00_get_starget_node_name,
2472 .show_starget_node_name = 1,
2473 .get_starget_port_name = qla2x00_get_starget_port_name,
2474 .show_starget_port_name = 1,
2475 .get_starget_port_id = qla2x00_get_starget_port_id,
2476 .show_starget_port_id = 1,
2478 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
2479 .show_rport_dev_loss_tmo = 1,
2481 .issue_fc_host_lip = qla2x00_issue_lip,
2482 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
2483 .terminate_rport_io = qla2x00_terminate_rport_io,
2484 .get_fc_host_stats = qla2x00_get_fc_host_stats,
2485 .bsg_request = qla24xx_bsg_request,
2486 .bsg_timeout = qla24xx_bsg_timeout,
2490 qla2x00_init_host_attr(scsi_qla_host_t *vha)
2492 struct qla_hw_data *ha = vha->hw;
2493 u32 speed = FC_PORTSPEED_UNKNOWN;
2495 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
2496 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
2497 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
2498 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
2499 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
2502 speed = FC_PORTSPEED_10GBIT;
2503 else if (IS_QLA25XX(ha))
2504 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
2505 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2506 else if (IS_QLA24XX_TYPE(ha))
2507 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
2509 else if (IS_QLA23XX(ha))
2510 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
2512 speed = FC_PORTSPEED_1GBIT;
2513 fc_host_supported_speeds(vha->host) = speed;
2516 qla84xx_reset(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
2520 uint16_t cmd_status;
2522 DEBUG16(printk("%s(%ld): entered.\n", __func__, ha->host_no));
2524 cmd = (*((bsg_job->request->rqst_data.h_vendor.vendor_cmd) + 2))
2525 == A84_RESET_FLAG_ENABLE_DIAG_FW ?
2526 A84_ISSUE_RESET_DIAG_FW : A84_ISSUE_RESET_OP_FW;
2527 ret = qla84xx_reset_chip(ha, cmd == A84_ISSUE_RESET_DIAG_FW,
2533 qla84xx_mgmt_cmd(scsi_qla_host_t *ha, struct msg_echo_lb *mreq, struct fc_bsg_job *bsg_job)
2535 struct access_chip_84xx *mn;
2536 dma_addr_t mn_dma, mgmt_dma;
2537 void *mgmt_b = NULL;
2539 int rsp_hdr_len, len = 0;
2540 struct qla84_msg_mgmt *ql84_mgmt;
2542 ql84_mgmt = (struct qla84_msg_mgmt *) vmalloc(sizeof(struct qla84_msg_mgmt));
2544 *((uint16_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 2));
2545 ql84_mgmt->mgmtp.u.mem.start_addr =
2546 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 3));
2548 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 4));
2549 ql84_mgmt->mgmtp.u.config.id =
2550 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 5));
2551 ql84_mgmt->mgmtp.u.config.param0 =
2552 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 6));
2553 ql84_mgmt->mgmtp.u.config.param1 =
2554 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 7));
2555 ql84_mgmt->mgmtp.u.info.type =
2556 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 8));
2557 ql84_mgmt->mgmtp.u.info.context =
2558 *((uint32_t *)(bsg_job->request->rqst_data.h_vendor.vendor_cmd + 9));
2560 rsp_hdr_len = bsg_job->request_payload.payload_len;
2562 mn = dma_pool_alloc(ha->hw->s_dma_pool, GFP_KERNEL, &mn_dma);
2564 DEBUG2(printk(KERN_ERR "%s: dma alloc for fw buffer "
2565 "failed%lu\n", __func__, ha->host_no));
2569 memset(mn, 0, sizeof (struct access_chip_84xx));
2571 mn->entry_type = ACCESS_CHIP_IOCB_TYPE;
2572 mn->entry_count = 1;
2574 switch (ql84_mgmt->cmd) {
2575 case QLA84_MGMT_READ_MEM:
2576 mn->options = cpu_to_le16(ACO_DUMP_MEMORY);
2577 mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
2579 case QLA84_MGMT_WRITE_MEM:
2580 mn->options = cpu_to_le16(ACO_LOAD_MEMORY);
2581 mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.mem.start_addr);
2583 case QLA84_MGMT_CHNG_CONFIG:
2584 mn->options = cpu_to_le16(ACO_CHANGE_CONFIG_PARAM);
2585 mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.id);
2586 mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param0);
2587 mn->parameter3 = cpu_to_le32(ql84_mgmt->mgmtp.u.config.param1);
2589 case QLA84_MGMT_GET_INFO:
2590 mn->options = cpu_to_le16(ACO_REQUEST_INFO);
2591 mn->parameter1 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.type);
2592 mn->parameter2 = cpu_to_le32(ql84_mgmt->mgmtp.u.info.context);
2599 if ((len == ql84_mgmt->len) &&
2600 ql84_mgmt->cmd != QLA84_MGMT_CHNG_CONFIG) {
2601 mgmt_b = dma_alloc_coherent(&ha->hw->pdev->dev, len,
2602 &mgmt_dma, GFP_KERNEL);
2603 if (mgmt_b == NULL) {
2604 DEBUG2(printk(KERN_ERR "%s: dma alloc mgmt_b "
2605 "failed%lu\n", __func__, ha->host_no));
2609 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->len);
2610 mn->dseg_count = cpu_to_le16(1);
2611 mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
2612 mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
2613 mn->dseg_length = cpu_to_le32(len);
2615 if (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM) {
2616 memcpy(mgmt_b, ql84_mgmt->payload, len);
2620 ret = qla2x00_issue_iocb(ha, mn, mn_dma, 0);
2621 if ((ret != QLA_SUCCESS) || (ql84_mgmt->cmd == QLA84_MGMT_WRITE_MEM)
2622 || (ql84_mgmt->cmd == QLA84_MGMT_CHNG_CONFIG)) {
2623 if (ret != QLA_SUCCESS)
2624 DEBUG2(printk(KERN_ERR "%s(%lu): failed\n",
2625 __func__, ha->host_no));
2626 } else if ((ql84_mgmt->cmd == QLA84_MGMT_READ_MEM) ||
2627 (ql84_mgmt->cmd == QLA84_MGMT_GET_INFO)) {
2631 dma_free_coherent(&ha->hw->pdev->dev, len, mgmt_b, mgmt_dma);
2634 dma_pool_free(ha->hw->s_dma_pool, mn, mn_dma);