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);
15 /* SYSFS attributes --------------------------------------------------------- */
18 qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
19 struct bin_attribute *bin_attr,
20 char *buf, loff_t off, size_t count)
22 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
23 struct device, kobj)));
24 struct qla_hw_data *ha = vha->hw;
26 if (ha->fw_dump_reading == 0)
29 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
34 qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
35 struct bin_attribute *bin_attr,
36 char *buf, loff_t off, size_t count)
38 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
39 struct device, kobj)));
40 struct qla_hw_data *ha = vha->hw;
46 reading = simple_strtol(buf, NULL, 10);
49 if (!ha->fw_dump_reading)
52 qla_printk(KERN_INFO, ha,
53 "Firmware dump cleared on (%ld).\n", vha->host_no);
55 ha->fw_dump_reading = 0;
59 if (ha->fw_dumped && !ha->fw_dump_reading) {
60 ha->fw_dump_reading = 1;
62 qla_printk(KERN_INFO, ha,
63 "Raw firmware dump ready for read on (%ld).\n",
68 qla2x00_alloc_fw_dump(vha);
71 qla2x00_system_error(vha);
77 static struct bin_attribute sysfs_fw_dump_attr = {
80 .mode = S_IRUSR | S_IWUSR,
83 .read = qla2x00_sysfs_read_fw_dump,
84 .write = qla2x00_sysfs_write_fw_dump,
88 qla2x00_sysfs_read_nvram(struct kobject *kobj,
89 struct bin_attribute *bin_attr,
90 char *buf, loff_t off, size_t count)
92 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
93 struct device, kobj)));
94 struct qla_hw_data *ha = vha->hw;
96 if (!capable(CAP_SYS_ADMIN))
99 if (IS_NOCACHE_VPD_TYPE(ha))
100 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
102 return memory_read_from_buffer(buf, count, &off, ha->nvram,
107 qla2x00_sysfs_write_nvram(struct kobject *kobj,
108 struct bin_attribute *bin_attr,
109 char *buf, loff_t off, size_t count)
111 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
112 struct device, kobj)));
113 struct qla_hw_data *ha = vha->hw;
116 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size ||
117 !ha->isp_ops->write_nvram)
120 /* Checksum NVRAM. */
121 if (IS_FWI2_CAPABLE(ha)) {
125 iter = (uint32_t *)buf;
127 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
128 chksum += le32_to_cpu(*iter++);
129 chksum = ~chksum + 1;
130 *iter = cpu_to_le32(chksum);
135 iter = (uint8_t *)buf;
137 for (cnt = 0; cnt < count - 1; cnt++)
139 chksum = ~chksum + 1;
143 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
144 qla_printk(KERN_WARNING, ha,
145 "HBA not online, failing NVRAM update.\n");
150 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->nvram_base, count);
151 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->nvram, ha->nvram_base,
154 /* NVRAM settings take effect immediately. */
155 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
156 qla2xxx_wake_dpc(vha);
157 qla2x00_wait_for_chip_reset(vha);
162 static struct bin_attribute sysfs_nvram_attr = {
165 .mode = S_IRUSR | S_IWUSR,
168 .read = qla2x00_sysfs_read_nvram,
169 .write = qla2x00_sysfs_write_nvram,
173 qla2x00_sysfs_read_optrom(struct kobject *kobj,
174 struct bin_attribute *bin_attr,
175 char *buf, loff_t off, size_t count)
177 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
178 struct device, kobj)));
179 struct qla_hw_data *ha = vha->hw;
181 if (ha->optrom_state != QLA_SREADING)
184 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
185 ha->optrom_region_size);
189 qla2x00_sysfs_write_optrom(struct kobject *kobj,
190 struct bin_attribute *bin_attr,
191 char *buf, loff_t off, size_t count)
193 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
194 struct device, kobj)));
195 struct qla_hw_data *ha = vha->hw;
197 if (ha->optrom_state != QLA_SWRITING)
199 if (off > ha->optrom_region_size)
201 if (off + count > ha->optrom_region_size)
202 count = ha->optrom_region_size - off;
204 memcpy(&ha->optrom_buffer[off], buf, count);
209 static struct bin_attribute sysfs_optrom_attr = {
212 .mode = S_IRUSR | S_IWUSR,
215 .read = qla2x00_sysfs_read_optrom,
216 .write = qla2x00_sysfs_write_optrom,
220 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
221 struct bin_attribute *bin_attr,
222 char *buf, loff_t off, size_t count)
224 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
225 struct device, kobj)));
226 struct qla_hw_data *ha = vha->hw;
229 uint32_t size = ha->optrom_size;
235 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
237 if (start > ha->optrom_size)
242 if (ha->optrom_state != QLA_SREADING &&
243 ha->optrom_state != QLA_SWRITING)
246 ha->optrom_state = QLA_SWAITING;
248 DEBUG2(qla_printk(KERN_INFO, ha,
249 "Freeing flash region allocation -- 0x%x bytes.\n",
250 ha->optrom_region_size));
252 vfree(ha->optrom_buffer);
253 ha->optrom_buffer = NULL;
256 if (ha->optrom_state != QLA_SWAITING)
259 ha->optrom_region_start = start;
260 ha->optrom_region_size = start + size > ha->optrom_size ?
261 ha->optrom_size - start : size;
263 ha->optrom_state = QLA_SREADING;
264 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
265 if (ha->optrom_buffer == NULL) {
266 qla_printk(KERN_WARNING, ha,
267 "Unable to allocate memory for optrom retrieval "
268 "(%x).\n", ha->optrom_region_size);
270 ha->optrom_state = QLA_SWAITING;
274 DEBUG2(qla_printk(KERN_INFO, ha,
275 "Reading flash region -- 0x%x/0x%x.\n",
276 ha->optrom_region_start, ha->optrom_region_size));
278 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
279 ha->isp_ops->read_optrom(vha, ha->optrom_buffer,
280 ha->optrom_region_start, ha->optrom_region_size);
283 if (ha->optrom_state != QLA_SWAITING)
287 * We need to be more restrictive on which FLASH regions are
288 * allowed to be updated via user-space. Regions accessible
289 * via this method include:
291 * ISP21xx/ISP22xx/ISP23xx type boards:
293 * 0x000000 -> 0x020000 -- Boot code.
295 * ISP2322/ISP24xx type boards:
297 * 0x000000 -> 0x07ffff -- Boot code.
298 * 0x080000 -> 0x0fffff -- Firmware.
300 * ISP25xx type boards:
302 * 0x000000 -> 0x07ffff -- Boot code.
303 * 0x080000 -> 0x0fffff -- Firmware.
304 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
307 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
309 else if (start == (ha->flt_region_boot * 4) ||
310 start == (ha->flt_region_fw * 4))
312 else if (IS_QLA25XX(ha) || IS_QLA81XX(ha))
315 qla_printk(KERN_WARNING, ha,
316 "Invalid start region 0x%x/0x%x.\n", start, size);
320 ha->optrom_region_start = start;
321 ha->optrom_region_size = start + size > ha->optrom_size ?
322 ha->optrom_size - start : size;
324 ha->optrom_state = QLA_SWRITING;
325 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
326 if (ha->optrom_buffer == NULL) {
327 qla_printk(KERN_WARNING, ha,
328 "Unable to allocate memory for optrom update "
329 "(%x).\n", ha->optrom_region_size);
331 ha->optrom_state = QLA_SWAITING;
335 DEBUG2(qla_printk(KERN_INFO, ha,
336 "Staging flash region write -- 0x%x/0x%x.\n",
337 ha->optrom_region_start, ha->optrom_region_size));
339 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
342 if (ha->optrom_state != QLA_SWRITING)
345 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
346 qla_printk(KERN_WARNING, ha,
347 "HBA not online, failing flash update.\n");
351 DEBUG2(qla_printk(KERN_INFO, ha,
352 "Writing flash region -- 0x%x/0x%x.\n",
353 ha->optrom_region_start, ha->optrom_region_size));
355 ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
356 ha->optrom_region_start, ha->optrom_region_size);
364 static struct bin_attribute sysfs_optrom_ctl_attr = {
366 .name = "optrom_ctl",
370 .write = qla2x00_sysfs_write_optrom_ctl,
374 qla2x00_sysfs_read_vpd(struct kobject *kobj,
375 struct bin_attribute *bin_attr,
376 char *buf, loff_t off, size_t count)
378 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
379 struct device, kobj)));
380 struct qla_hw_data *ha = vha->hw;
382 if (!capable(CAP_SYS_ADMIN))
385 if (IS_NOCACHE_VPD_TYPE(ha))
386 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
388 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
392 qla2x00_sysfs_write_vpd(struct kobject *kobj,
393 struct bin_attribute *bin_attr,
394 char *buf, loff_t off, size_t count)
396 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
397 struct device, kobj)));
398 struct qla_hw_data *ha = vha->hw;
401 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size ||
402 !ha->isp_ops->write_nvram)
405 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
406 qla_printk(KERN_WARNING, ha,
407 "HBA not online, failing VPD update.\n");
412 ha->isp_ops->write_nvram(vha, (uint8_t *)buf, ha->vpd_base, count);
413 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, ha->vpd_base, count);
415 /* Update flash version information for 4Gb & above. */
416 if (!IS_FWI2_CAPABLE(ha))
419 tmp_data = vmalloc(256);
421 qla_printk(KERN_WARNING, ha,
422 "Unable to allocate memory for VPD information update.\n");
425 ha->isp_ops->get_flash_version(vha, tmp_data);
431 static struct bin_attribute sysfs_vpd_attr = {
434 .mode = S_IRUSR | S_IWUSR,
437 .read = qla2x00_sysfs_read_vpd,
438 .write = qla2x00_sysfs_write_vpd,
442 qla2x00_sysfs_read_sfp(struct kobject *kobj,
443 struct bin_attribute *bin_attr,
444 char *buf, loff_t off, size_t count)
446 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
447 struct device, kobj)));
448 struct qla_hw_data *ha = vha->hw;
449 uint16_t iter, addr, offset;
452 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
458 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
461 qla_printk(KERN_WARNING, ha,
462 "Unable to allocate memory for SFP read-data.\n");
467 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
469 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
470 iter++, offset += SFP_BLOCK_SIZE) {
472 /* Skip to next device address. */
477 rval = qla2x00_read_sfp(vha, ha->sfp_data_dma, addr, offset,
479 if (rval != QLA_SUCCESS) {
480 qla_printk(KERN_WARNING, ha,
481 "Unable to read SFP data (%x/%x/%x).\n", rval,
486 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
487 buf += SFP_BLOCK_SIZE;
493 static struct bin_attribute sysfs_sfp_attr = {
496 .mode = S_IRUSR | S_IWUSR,
498 .size = SFP_DEV_SIZE * 2,
499 .read = qla2x00_sysfs_read_sfp,
503 qla2x00_sysfs_write_reset(struct kobject *kobj,
504 struct bin_attribute *bin_attr,
505 char *buf, loff_t off, size_t count)
507 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
508 struct device, kobj)));
509 struct qla_hw_data *ha = vha->hw;
515 type = simple_strtol(buf, NULL, 10);
518 qla_printk(KERN_INFO, ha,
519 "Issuing ISP reset on (%ld).\n", vha->host_no);
521 scsi_block_requests(vha->host);
522 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
523 qla2xxx_wake_dpc(vha);
524 qla2x00_wait_for_chip_reset(vha);
525 scsi_unblock_requests(vha->host);
531 qla_printk(KERN_INFO, ha,
532 "Issuing MPI reset on (%ld).\n", vha->host_no);
534 /* Make sure FC side is not in reset */
535 qla2x00_wait_for_hba_online(vha);
537 /* Issue MPI reset */
538 scsi_block_requests(vha->host);
539 if (qla81xx_restart_mpi_firmware(vha) != QLA_SUCCESS)
540 qla_printk(KERN_WARNING, ha,
541 "MPI reset failed on (%ld).\n", vha->host_no);
542 scsi_unblock_requests(vha->host);
548 static struct bin_attribute sysfs_reset_attr = {
554 .write = qla2x00_sysfs_write_reset,
558 qla2x00_sysfs_write_edc(struct kobject *kobj,
559 struct bin_attribute *bin_attr,
560 char *buf, loff_t off, size_t count)
562 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
563 struct device, kobj)));
564 struct qla_hw_data *ha = vha->hw;
565 uint16_t dev, adr, opt, len;
568 ha->edc_data_len = 0;
570 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
574 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
577 DEBUG2(qla_printk(KERN_INFO, ha,
578 "Unable to allocate memory for EDC write.\n"));
583 dev = le16_to_cpup((void *)&buf[0]);
584 adr = le16_to_cpup((void *)&buf[2]);
585 opt = le16_to_cpup((void *)&buf[4]);
586 len = le16_to_cpup((void *)&buf[6]);
589 if (len == 0 || len > DMA_POOL_SIZE || len > count - 8)
592 memcpy(ha->edc_data, &buf[8], len);
594 rval = qla2x00_write_edc(vha, dev, adr, ha->edc_data_dma,
595 ha->edc_data, len, opt);
596 if (rval != QLA_SUCCESS) {
597 DEBUG2(qla_printk(KERN_INFO, ha,
598 "Unable to write EDC (%x) %02x:%02x:%04x:%02x:%02x.\n",
599 rval, dev, adr, opt, len, *buf));
606 static struct bin_attribute sysfs_edc_attr = {
612 .write = qla2x00_sysfs_write_edc,
616 qla2x00_sysfs_write_edc_status(struct kobject *kobj,
617 struct bin_attribute *bin_attr,
618 char *buf, loff_t off, size_t count)
620 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
621 struct device, kobj)));
622 struct qla_hw_data *ha = vha->hw;
623 uint16_t dev, adr, opt, len;
626 ha->edc_data_len = 0;
628 if (!capable(CAP_SYS_ADMIN) || off != 0 || count < 8)
632 ha->edc_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
635 DEBUG2(qla_printk(KERN_INFO, ha,
636 "Unable to allocate memory for EDC status.\n"));
641 dev = le16_to_cpup((void *)&buf[0]);
642 adr = le16_to_cpup((void *)&buf[2]);
643 opt = le16_to_cpup((void *)&buf[4]);
644 len = le16_to_cpup((void *)&buf[6]);
647 if (len == 0 || len > DMA_POOL_SIZE)
650 memset(ha->edc_data, 0, len);
651 rval = qla2x00_read_edc(vha, dev, adr, ha->edc_data_dma,
652 ha->edc_data, len, opt);
653 if (rval != QLA_SUCCESS) {
654 DEBUG2(qla_printk(KERN_INFO, ha,
655 "Unable to write EDC status (%x) %02x:%02x:%04x:%02x.\n",
656 rval, dev, adr, opt, len));
660 ha->edc_data_len = len;
666 qla2x00_sysfs_read_edc_status(struct kobject *kobj,
667 struct bin_attribute *bin_attr,
668 char *buf, loff_t off, size_t count)
670 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
671 struct device, kobj)));
672 struct qla_hw_data *ha = vha->hw;
674 if (!capable(CAP_SYS_ADMIN) || off != 0 || count == 0)
677 if (!ha->edc_data || ha->edc_data_len == 0 || ha->edc_data_len > count)
680 memcpy(buf, ha->edc_data, ha->edc_data_len);
682 return ha->edc_data_len;
685 static struct bin_attribute sysfs_edc_status_attr = {
687 .name = "edc_status",
688 .mode = S_IRUSR | S_IWUSR,
691 .write = qla2x00_sysfs_write_edc_status,
692 .read = qla2x00_sysfs_read_edc_status,
696 qla2x00_sysfs_read_xgmac_stats(struct kobject *kobj,
697 struct bin_attribute *bin_attr,
698 char *buf, loff_t off, size_t count)
700 struct scsi_qla_host *vha = shost_priv(dev_to_shost(container_of(kobj,
701 struct device, kobj)));
702 struct qla_hw_data *ha = vha->hw;
704 uint16_t actual_size;
706 if (!capable(CAP_SYS_ADMIN) || off != 0 || count > XGMAC_DATA_SIZE)
712 ha->xgmac_data = dma_alloc_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
713 &ha->xgmac_data_dma, GFP_KERNEL);
714 if (!ha->xgmac_data) {
715 qla_printk(KERN_WARNING, ha,
716 "Unable to allocate memory for XGMAC read-data.\n");
722 memset(ha->xgmac_data, 0, XGMAC_DATA_SIZE);
724 rval = qla2x00_get_xgmac_stats(vha, ha->xgmac_data_dma,
725 XGMAC_DATA_SIZE, &actual_size);
726 if (rval != QLA_SUCCESS) {
727 qla_printk(KERN_WARNING, ha,
728 "Unable to read XGMAC data (%x).\n", rval);
732 count = actual_size > count ? count: actual_size;
733 memcpy(buf, ha->xgmac_data, count);
738 static struct bin_attribute sysfs_xgmac_stats_attr = {
740 .name = "xgmac_stats",
744 .read = qla2x00_sysfs_read_xgmac_stats,
747 static struct sysfs_entry {
749 struct bin_attribute *attr;
751 } bin_file_entries[] = {
752 { "fw_dump", &sysfs_fw_dump_attr, },
753 { "nvram", &sysfs_nvram_attr, },
754 { "optrom", &sysfs_optrom_attr, },
755 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
756 { "vpd", &sysfs_vpd_attr, 1 },
757 { "sfp", &sysfs_sfp_attr, 1 },
758 { "reset", &sysfs_reset_attr, },
759 { "edc", &sysfs_edc_attr, 2 },
760 { "edc_status", &sysfs_edc_status_attr, 2 },
761 { "xgmac_stats", &sysfs_xgmac_stats_attr, 3 },
766 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *vha)
768 struct Scsi_Host *host = vha->host;
769 struct sysfs_entry *iter;
772 for (iter = bin_file_entries; iter->name; iter++) {
773 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(vha->hw))
775 if (iter->is4GBp_only == 2 && !IS_QLA25XX(vha->hw))
777 if (iter->is4GBp_only == 3 && !IS_QLA81XX(vha->hw))
780 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
783 qla_printk(KERN_INFO, vha->hw,
784 "Unable to create sysfs %s binary attribute "
785 "(%d).\n", iter->name, ret);
790 qla2x00_free_sysfs_attr(scsi_qla_host_t *vha)
792 struct Scsi_Host *host = vha->host;
793 struct sysfs_entry *iter;
794 struct qla_hw_data *ha = vha->hw;
796 for (iter = bin_file_entries; iter->name; iter++) {
797 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
799 if (iter->is4GBp_only == 2 && !IS_QLA25XX(ha))
801 if (iter->is4GBp_only == 3 && !IS_QLA81XX(ha))
804 sysfs_remove_bin_file(&host->shost_gendev.kobj,
808 if (ha->beacon_blink_led == 1)
809 ha->isp_ops->beacon_off(vha);
812 /* Scsi_Host attributes. */
815 qla2x00_drvr_version_show(struct device *dev,
816 struct device_attribute *attr, char *buf)
818 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
822 qla2x00_fw_version_show(struct device *dev,
823 struct device_attribute *attr, char *buf)
825 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
826 struct qla_hw_data *ha = vha->hw;
829 return snprintf(buf, PAGE_SIZE, "%s\n",
830 ha->isp_ops->fw_version_str(vha, fw_str));
834 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
837 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
838 struct qla_hw_data *ha = vha->hw;
841 if (IS_FWI2_CAPABLE(ha)) {
842 qla2xxx_get_vpd_field(vha, "SN", buf, PAGE_SIZE);
843 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
846 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
847 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
852 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
855 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
856 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", vha->hw->pdev->device);
860 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
863 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
864 struct qla_hw_data *ha = vha->hw;
865 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
866 ha->product_id[0], ha->product_id[1], ha->product_id[2],
871 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
874 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
875 return snprintf(buf, PAGE_SIZE, "%s\n", vha->hw->model_number);
879 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
882 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
883 return snprintf(buf, PAGE_SIZE, "%s\n",
884 vha->hw->model_desc ? vha->hw->model_desc : "");
888 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
891 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
894 return snprintf(buf, PAGE_SIZE, "%s\n",
895 vha->hw->isp_ops->pci_info_str(vha, pci_info));
899 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
902 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
903 struct qla_hw_data *ha = vha->hw;
906 if (atomic_read(&vha->loop_state) == LOOP_DOWN ||
907 atomic_read(&vha->loop_state) == LOOP_DEAD)
908 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
909 else if (atomic_read(&vha->loop_state) != LOOP_READY ||
910 test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags) ||
911 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
912 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
914 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
916 switch (ha->current_topology) {
918 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
921 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
924 len += snprintf(buf + len, PAGE_SIZE-len,
925 "N_Port to N_Port\n");
928 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
931 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
939 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
942 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
945 switch (vha->hw->zio_mode) {
947 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
949 case QLA_ZIO_DISABLED:
950 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
957 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
958 const char *buf, size_t count)
960 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
961 struct qla_hw_data *ha = vha->hw;
965 if (!IS_ZIO_SUPPORTED(ha))
968 if (sscanf(buf, "%d", &val) != 1)
972 zio_mode = QLA_ZIO_MODE_6;
974 zio_mode = QLA_ZIO_DISABLED;
976 /* Update per-hba values and queue a reset. */
977 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
978 ha->zio_mode = zio_mode;
979 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
985 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
988 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
990 return snprintf(buf, PAGE_SIZE, "%d us\n", vha->hw->zio_timer * 100);
994 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
995 const char *buf, size_t count)
997 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1001 if (sscanf(buf, "%d", &val) != 1)
1003 if (val > 25500 || val < 100)
1006 zio_timer = (uint16_t)(val / 100);
1007 vha->hw->zio_timer = zio_timer;
1013 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1016 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1019 if (vha->hw->beacon_blink_led)
1020 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1022 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1027 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1028 const char *buf, size_t count)
1030 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1031 struct qla_hw_data *ha = vha->hw;
1035 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1038 if (test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) {
1039 qla_printk(KERN_WARNING, ha,
1040 "Abort ISP active -- ignoring beacon request.\n");
1044 if (sscanf(buf, "%d", &val) != 1)
1048 rval = ha->isp_ops->beacon_on(vha);
1050 rval = ha->isp_ops->beacon_off(vha);
1052 if (rval != QLA_SUCCESS)
1059 qla2x00_optrom_bios_version_show(struct device *dev,
1060 struct device_attribute *attr, char *buf)
1062 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1063 struct qla_hw_data *ha = vha->hw;
1064 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1065 ha->bios_revision[0]);
1069 qla2x00_optrom_efi_version_show(struct device *dev,
1070 struct device_attribute *attr, char *buf)
1072 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1073 struct qla_hw_data *ha = vha->hw;
1074 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1075 ha->efi_revision[0]);
1079 qla2x00_optrom_fcode_version_show(struct device *dev,
1080 struct device_attribute *attr, char *buf)
1082 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1083 struct qla_hw_data *ha = vha->hw;
1084 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1085 ha->fcode_revision[0]);
1089 qla2x00_optrom_fw_version_show(struct device *dev,
1090 struct device_attribute *attr, char *buf)
1092 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1093 struct qla_hw_data *ha = vha->hw;
1094 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1095 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1096 ha->fw_revision[3]);
1100 qla2x00_total_isp_aborts_show(struct device *dev,
1101 struct device_attribute *attr, char *buf)
1103 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1104 struct qla_hw_data *ha = vha->hw;
1105 return snprintf(buf, PAGE_SIZE, "%d\n",
1106 ha->qla_stats.total_isp_aborts);
1110 qla2x00_mpi_version_show(struct device *dev, struct device_attribute *attr,
1113 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1114 struct qla_hw_data *ha = vha->hw;
1116 if (!IS_QLA81XX(ha))
1117 return snprintf(buf, PAGE_SIZE, "\n");
1119 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d (%x)\n",
1120 ha->mpi_version[0], ha->mpi_version[1], ha->mpi_version[2],
1121 ha->mpi_capabilities);
1125 qla2x00_phy_version_show(struct device *dev, struct device_attribute *attr,
1128 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1129 struct qla_hw_data *ha = vha->hw;
1131 if (!IS_QLA81XX(ha))
1132 return snprintf(buf, PAGE_SIZE, "\n");
1134 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d\n",
1135 ha->phy_version[0], ha->phy_version[1], ha->phy_version[2]);
1139 qla2x00_flash_block_size_show(struct device *dev,
1140 struct device_attribute *attr, char *buf)
1142 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1143 struct qla_hw_data *ha = vha->hw;
1145 return snprintf(buf, PAGE_SIZE, "0x%x\n", ha->fdt_block_size);
1149 qla2x00_vlan_id_show(struct device *dev, struct device_attribute *attr,
1152 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1154 if (!IS_QLA81XX(vha->hw))
1155 return snprintf(buf, PAGE_SIZE, "\n");
1157 return snprintf(buf, PAGE_SIZE, "%d\n", vha->fcoe_vlan_id);
1161 qla2x00_vn_port_mac_address_show(struct device *dev,
1162 struct device_attribute *attr, char *buf)
1164 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1166 if (!IS_QLA81XX(vha->hw))
1167 return snprintf(buf, PAGE_SIZE, "\n");
1169 return snprintf(buf, PAGE_SIZE, "%02x:%02x:%02x:%02x:%02x:%02x\n",
1170 vha->fcoe_vn_port_mac[5], vha->fcoe_vn_port_mac[4],
1171 vha->fcoe_vn_port_mac[3], vha->fcoe_vn_port_mac[2],
1172 vha->fcoe_vn_port_mac[1], vha->fcoe_vn_port_mac[0]);
1176 qla2x00_fabric_param_show(struct device *dev, struct device_attribute *attr,
1179 scsi_qla_host_t *vha = shost_priv(class_to_shost(dev));
1181 return snprintf(buf, PAGE_SIZE, "%d\n", vha->hw->switch_cap);
1184 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1185 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1186 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1187 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1188 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1189 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1190 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1191 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
1192 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
1193 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1194 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1195 qla2x00_zio_timer_store);
1196 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1197 qla2x00_beacon_store);
1198 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1199 qla2x00_optrom_bios_version_show, NULL);
1200 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1201 qla2x00_optrom_efi_version_show, NULL);
1202 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1203 qla2x00_optrom_fcode_version_show, NULL);
1204 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
1206 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
1208 static DEVICE_ATTR(mpi_version, S_IRUGO, qla2x00_mpi_version_show, NULL);
1209 static DEVICE_ATTR(phy_version, S_IRUGO, qla2x00_phy_version_show, NULL);
1210 static DEVICE_ATTR(flash_block_size, S_IRUGO, qla2x00_flash_block_size_show,
1212 static DEVICE_ATTR(vlan_id, S_IRUGO, qla2x00_vlan_id_show, NULL);
1213 static DEVICE_ATTR(vn_port_mac_address, S_IRUGO,
1214 qla2x00_vn_port_mac_address_show, NULL);
1215 static DEVICE_ATTR(fabric_param, S_IRUGO, qla2x00_fabric_param_show, NULL);
1217 struct device_attribute *qla2x00_host_attrs[] = {
1218 &dev_attr_driver_version,
1219 &dev_attr_fw_version,
1220 &dev_attr_serial_num,
1223 &dev_attr_model_name,
1224 &dev_attr_model_desc,
1226 &dev_attr_link_state,
1228 &dev_attr_zio_timer,
1230 &dev_attr_optrom_bios_version,
1231 &dev_attr_optrom_efi_version,
1232 &dev_attr_optrom_fcode_version,
1233 &dev_attr_optrom_fw_version,
1234 &dev_attr_total_isp_aborts,
1235 &dev_attr_mpi_version,
1236 &dev_attr_phy_version,
1237 &dev_attr_flash_block_size,
1239 &dev_attr_vn_port_mac_address,
1240 &dev_attr_fabric_param,
1244 /* Host attributes. */
1247 qla2x00_get_host_port_id(struct Scsi_Host *shost)
1249 scsi_qla_host_t *vha = shost_priv(shost);
1251 fc_host_port_id(shost) = vha->d_id.b.domain << 16 |
1252 vha->d_id.b.area << 8 | vha->d_id.b.al_pa;
1256 qla2x00_get_host_speed(struct Scsi_Host *shost)
1258 struct qla_hw_data *ha = ((struct scsi_qla_host *)
1259 (shost_priv(shost)))->hw;
1260 u32 speed = FC_PORTSPEED_UNKNOWN;
1262 switch (ha->link_data_rate) {
1263 case PORT_SPEED_1GB:
1264 speed = FC_PORTSPEED_1GBIT;
1266 case PORT_SPEED_2GB:
1267 speed = FC_PORTSPEED_2GBIT;
1269 case PORT_SPEED_4GB:
1270 speed = FC_PORTSPEED_4GBIT;
1272 case PORT_SPEED_8GB:
1273 speed = FC_PORTSPEED_8GBIT;
1275 case PORT_SPEED_10GB:
1276 speed = FC_PORTSPEED_10GBIT;
1279 fc_host_speed(shost) = speed;
1283 qla2x00_get_host_port_type(struct Scsi_Host *shost)
1285 scsi_qla_host_t *vha = shost_priv(shost);
1286 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1289 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1292 switch (vha->hw->current_topology) {
1294 port_type = FC_PORTTYPE_LPORT;
1297 port_type = FC_PORTTYPE_NLPORT;
1300 port_type = FC_PORTTYPE_PTP;
1303 port_type = FC_PORTTYPE_NPORT;
1306 fc_host_port_type(shost) = port_type;
1310 qla2x00_get_starget_node_name(struct scsi_target *starget)
1312 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1313 scsi_qla_host_t *vha = shost_priv(host);
1317 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1318 if (fcport->rport &&
1319 starget->id == fcport->rport->scsi_target_id) {
1320 node_name = wwn_to_u64(fcport->node_name);
1325 fc_starget_node_name(starget) = node_name;
1329 qla2x00_get_starget_port_name(struct scsi_target *starget)
1331 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1332 scsi_qla_host_t *vha = shost_priv(host);
1336 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1337 if (fcport->rport &&
1338 starget->id == fcport->rport->scsi_target_id) {
1339 port_name = wwn_to_u64(fcport->port_name);
1344 fc_starget_port_name(starget) = port_name;
1348 qla2x00_get_starget_port_id(struct scsi_target *starget)
1350 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1351 scsi_qla_host_t *vha = shost_priv(host);
1353 uint32_t port_id = ~0U;
1355 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1356 if (fcport->rport &&
1357 starget->id == fcport->rport->scsi_target_id) {
1358 port_id = fcport->d_id.b.domain << 16 |
1359 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1364 fc_starget_port_id(starget) = port_id;
1368 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1371 rport->dev_loss_tmo = timeout;
1373 rport->dev_loss_tmo = 1;
1377 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1379 struct Scsi_Host *host = rport_to_shost(rport);
1380 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1385 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev)))
1386 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1388 qla2x00_abort_fcport_cmds(fcport);
1391 * Transport has effectively 'deleted' the rport, clear
1392 * all local references.
1394 spin_lock_irq(host->host_lock);
1395 fcport->rport = NULL;
1396 *((fc_port_t **)rport->dd_data) = NULL;
1397 spin_unlock_irq(host->host_lock);
1401 qla2x00_terminate_rport_io(struct fc_rport *rport)
1403 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1408 if (unlikely(pci_channel_offline(fcport->vha->hw->pdev))) {
1409 qla2x00_abort_all_cmds(fcport->vha, DID_NO_CONNECT << 16);
1413 * At this point all fcport's software-states are cleared. Perform any
1414 * final cleanup of firmware resources (PCBs and XCBs).
1416 if (fcport->loop_id != FC_NO_LOOP_ID)
1417 fcport->vha->hw->isp_ops->fabric_logout(fcport->vha,
1418 fcport->loop_id, fcport->d_id.b.domain,
1419 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1421 qla2x00_abort_fcport_cmds(fcport);
1425 qla2x00_issue_lip(struct Scsi_Host *shost)
1427 scsi_qla_host_t *vha = shost_priv(shost);
1429 qla2x00_loop_reset(vha);
1433 static struct fc_host_statistics *
1434 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1436 scsi_qla_host_t *vha = shost_priv(shost);
1437 struct qla_hw_data *ha = vha->hw;
1438 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1440 struct link_statistics *stats;
1441 dma_addr_t stats_dma;
1442 struct fc_host_statistics *pfc_host_stat;
1444 pfc_host_stat = &ha->fc_host_stat;
1445 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1447 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1448 if (stats == NULL) {
1449 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1450 __func__, base_vha->host_no));
1453 memset(stats, 0, DMA_POOL_SIZE);
1455 rval = QLA_FUNCTION_FAILED;
1456 if (IS_FWI2_CAPABLE(ha)) {
1457 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma);
1458 } else if (atomic_read(&base_vha->loop_state) == LOOP_READY &&
1459 !test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) &&
1460 !test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
1462 /* Must be in a 'READY' state for statistics retrieval. */
1463 rval = qla2x00_get_link_status(base_vha, base_vha->loop_id,
1467 if (rval != QLA_SUCCESS)
1470 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1471 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1472 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1473 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1474 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1475 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1476 if (IS_FWI2_CAPABLE(ha)) {
1477 pfc_host_stat->lip_count = stats->lip_cnt;
1478 pfc_host_stat->tx_frames = stats->tx_frames;
1479 pfc_host_stat->rx_frames = stats->rx_frames;
1480 pfc_host_stat->dumped_frames = stats->dumped_frames;
1481 pfc_host_stat->nos_count = stats->nos_rcvd;
1483 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1484 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
1487 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
1489 return pfc_host_stat;
1493 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1495 scsi_qla_host_t *vha = shost_priv(shost);
1497 qla2x00_get_sym_node_name(vha, fc_host_symbolic_name(shost));
1501 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1503 scsi_qla_host_t *vha = shost_priv(shost);
1505 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
1509 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1511 scsi_qla_host_t *vha = shost_priv(shost);
1514 if (vha->device_flags & SWITCH_FOUND)
1515 node_name = wwn_to_u64(vha->fabric_node_name);
1517 node_name = wwn_to_u64(vha->node_name);
1519 fc_host_fabric_name(shost) = node_name;
1523 qla2x00_get_host_port_state(struct Scsi_Host *shost)
1525 scsi_qla_host_t *vha = shost_priv(shost);
1526 struct scsi_qla_host *base_vha = pci_get_drvdata(vha->hw->pdev);
1528 if (!base_vha->flags.online)
1529 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1530 else if (atomic_read(&base_vha->loop_state) == LOOP_TIMEOUT)
1531 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1533 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1537 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1541 scsi_qla_host_t *base_vha = shost_priv(fc_vport->shost);
1542 scsi_qla_host_t *vha = NULL;
1543 struct qla_hw_data *ha = base_vha->hw;
1544 uint16_t options = 0;
1547 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1549 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1550 "status %x\n", ret));
1554 vha = qla24xx_create_vhost(fc_vport);
1556 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1558 return FC_VPORT_FAILED;
1561 atomic_set(&vha->vp_state, VP_OFFLINE);
1562 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1564 atomic_set(&vha->vp_state, VP_FAILED);
1566 /* ready to create vport */
1567 qla_printk(KERN_INFO, vha->hw, "VP entry id %d assigned.\n",
1570 /* initialized vport states */
1571 atomic_set(&vha->loop_state, LOOP_DOWN);
1572 vha->vp_err_state= VP_ERR_PORTDWN;
1573 vha->vp_prev_err_state= VP_ERR_UNKWN;
1574 /* Check if physical ha port is Up */
1575 if (atomic_read(&base_vha->loop_state) == LOOP_DOWN ||
1576 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
1577 /* Don't retry or attempt login of this virtual port */
1578 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1579 base_vha->host_no));
1580 atomic_set(&vha->loop_state, LOOP_DEAD);
1582 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1585 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1586 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1587 vha->host_no, vha->vp_idx));
1588 goto vport_create_failed_2;
1591 /* initialize attributes */
1592 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1593 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1594 fc_host_supported_classes(vha->host) =
1595 fc_host_supported_classes(base_vha->host);
1596 fc_host_supported_speeds(vha->host) =
1597 fc_host_supported_speeds(base_vha->host);
1599 qla24xx_vport_disable(fc_vport, disable);
1602 if (ha->cur_vport_count <= ha->flex_port_count || ql2xmultique_tag
1603 || ha->max_req_queues == 1 || !ha->npiv_info)
1605 /* Create a request queue in QoS mode for the vport */
1606 for (cnt = ha->flex_port_count; cnt < ha->nvram_npiv_size; cnt++) {
1607 if (ha->npiv_info[cnt].port_name == vha->port_name &&
1608 ha->npiv_info[cnt].node_name == vha->node_name) {
1609 qos = ha->npiv_info[cnt].q_qos;
1614 ret = qla25xx_create_req_que(ha, options, vha->vp_idx, 0, 0,
1617 qla_printk(KERN_WARNING, ha,
1618 "Can't create request queue for vp_idx:%d\n",
1621 DEBUG2(qla_printk(KERN_INFO, ha,
1622 "Request Que:%d created for vp_idx:%d\n",
1627 vha->req = ha->req_q_map[ret];
1630 vport_create_failed_2:
1631 qla24xx_disable_vp(vha);
1632 qla24xx_deallocate_vp_id(vha);
1633 scsi_host_put(vha->host);
1634 return FC_VPORT_FAILED;
1638 qla24xx_vport_delete(struct fc_vport *fc_vport)
1640 scsi_qla_host_t *vha = fc_vport->dd_data;
1641 fc_port_t *fcport, *tfcport;
1642 struct qla_hw_data *ha = vha->hw;
1643 uint16_t id = vha->vp_idx;
1645 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
1646 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags))
1649 qla24xx_disable_vp(vha);
1651 fc_remove_host(vha->host);
1653 scsi_remove_host(vha->host);
1655 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
1656 list_del(&fcport->list);
1661 qla24xx_deallocate_vp_id(vha);
1663 if (vha->timer_active) {
1664 qla2x00_vp_stop_timer(vha);
1665 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1667 vha->host_no, vha->vp_idx, vha));
1670 if (vha->req->id && !ql2xmultique_tag) {
1671 if (qla25xx_delete_req_que(vha, vha->req) != QLA_SUCCESS)
1672 qla_printk(KERN_WARNING, ha,
1673 "Queue delete failed.\n");
1676 scsi_host_put(vha->host);
1677 qla_printk(KERN_INFO, ha, "vport %d deleted\n", id);
1682 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1684 scsi_qla_host_t *vha = fc_vport->dd_data;
1687 qla24xx_disable_vp(vha);
1689 qla24xx_enable_vp(vha);
1694 struct fc_function_template qla2xxx_transport_functions = {
1696 .show_host_node_name = 1,
1697 .show_host_port_name = 1,
1698 .show_host_supported_classes = 1,
1699 .show_host_supported_speeds = 1,
1701 .get_host_port_id = qla2x00_get_host_port_id,
1702 .show_host_port_id = 1,
1703 .get_host_speed = qla2x00_get_host_speed,
1704 .show_host_speed = 1,
1705 .get_host_port_type = qla2x00_get_host_port_type,
1706 .show_host_port_type = 1,
1707 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1708 .show_host_symbolic_name = 1,
1709 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1710 .show_host_system_hostname = 1,
1711 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1712 .show_host_fabric_name = 1,
1713 .get_host_port_state = qla2x00_get_host_port_state,
1714 .show_host_port_state = 1,
1716 .dd_fcrport_size = sizeof(struct fc_port *),
1717 .show_rport_supported_classes = 1,
1719 .get_starget_node_name = qla2x00_get_starget_node_name,
1720 .show_starget_node_name = 1,
1721 .get_starget_port_name = qla2x00_get_starget_port_name,
1722 .show_starget_port_name = 1,
1723 .get_starget_port_id = qla2x00_get_starget_port_id,
1724 .show_starget_port_id = 1,
1726 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1727 .show_rport_dev_loss_tmo = 1,
1729 .issue_fc_host_lip = qla2x00_issue_lip,
1730 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1731 .terminate_rport_io = qla2x00_terminate_rport_io,
1732 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1734 .vport_create = qla24xx_vport_create,
1735 .vport_disable = qla24xx_vport_disable,
1736 .vport_delete = qla24xx_vport_delete,
1739 struct fc_function_template qla2xxx_transport_vport_functions = {
1741 .show_host_node_name = 1,
1742 .show_host_port_name = 1,
1743 .show_host_supported_classes = 1,
1745 .get_host_port_id = qla2x00_get_host_port_id,
1746 .show_host_port_id = 1,
1747 .get_host_speed = qla2x00_get_host_speed,
1748 .show_host_speed = 1,
1749 .get_host_port_type = qla2x00_get_host_port_type,
1750 .show_host_port_type = 1,
1751 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1752 .show_host_symbolic_name = 1,
1753 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1754 .show_host_system_hostname = 1,
1755 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1756 .show_host_fabric_name = 1,
1757 .get_host_port_state = qla2x00_get_host_port_state,
1758 .show_host_port_state = 1,
1760 .dd_fcrport_size = sizeof(struct fc_port *),
1761 .show_rport_supported_classes = 1,
1763 .get_starget_node_name = qla2x00_get_starget_node_name,
1764 .show_starget_node_name = 1,
1765 .get_starget_port_name = qla2x00_get_starget_port_name,
1766 .show_starget_port_name = 1,
1767 .get_starget_port_id = qla2x00_get_starget_port_id,
1768 .show_starget_port_id = 1,
1770 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1771 .show_rport_dev_loss_tmo = 1,
1773 .issue_fc_host_lip = qla2x00_issue_lip,
1774 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1775 .terminate_rport_io = qla2x00_terminate_rport_io,
1776 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1780 qla2x00_init_host_attr(scsi_qla_host_t *vha)
1782 struct qla_hw_data *ha = vha->hw;
1783 u32 speed = FC_PORTSPEED_UNKNOWN;
1785 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1786 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1787 fc_host_supported_classes(vha->host) = FC_COS_CLASS3;
1788 fc_host_max_npiv_vports(vha->host) = ha->max_npiv_vports;
1789 fc_host_npiv_vports_inuse(vha->host) = ha->cur_vport_count;
1792 speed = FC_PORTSPEED_10GBIT;
1793 else if (IS_QLA25XX(ha))
1794 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1795 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1796 else if (IS_QLA24XX_TYPE(ha))
1797 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1799 else if (IS_QLA23XX(ha))
1800 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1802 speed = FC_PORTSPEED_1GBIT;
1803 fc_host_supported_speeds(vha->host) = speed;