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>
12 #include <linux/version.h>
14 #include "qla2x_tgt.h"
15 #include <linux/ctype.h>
17 static int qla24xx_vport_disable(struct fc_vport *, bool);
19 /* SYSFS attributes --------------------------------------------------------- */
22 qla2x00_show_class2_enabled(struct device *dev,
23 struct device_attribute *attr, char *buffer)
25 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
26 ulong max_size = PAGE_SIZE;
29 size = scnprintf(buffer, max_size, "%d\n", ha->enable_class_2);
35 qla2x00_store_class2_enabled(struct device *dev,
36 struct device_attribute *attr, const char *buffer, size_t size)
38 struct scsi_qla_host *ha = shost_priv(class_to_shost(dev));
46 spin_lock_irqsave(&ha->hardware_lock, flags);
50 if (ha->enable_class_2) {
51 ha->enable_class_2 = 0;
56 if (!ha->enable_class_2) {
57 if (ha->fw_attributes & __constant_cpu_to_le32(BIT_0)) {
58 qla_printk(KERN_INFO, ha, "Enabling class 2 "
60 ha->enable_class_2 = 1;
63 qla_printk(KERN_INFO, ha, "Firmware doesn't "
64 "support class 2 operations.\n");
71 #if defined(QL_DEBUG_LEVEL_9) || defined(QL_DEBUG_LEVEL_11)
72 qla_printk(KERN_ERR "%s: Requested action not understood: %s\n",
79 spin_unlock_irqrestore(&ha->hardware_lock, flags);
82 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
88 spin_unlock_irqrestore(&ha->hardware_lock, flags);
92 static DEVICE_ATTR(class2_enabled,
94 qla2x00_show_class2_enabled,
95 qla2x00_store_class2_enabled);
97 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
99 #define CONFIG_SCST_PROC
101 #ifdef CONFIG_SCST_PROC
104 qla2x00_show_tgt_enabled(struct device *dev,
105 struct device_attribute *attr, char *buffer)
107 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
110 size = scnprintf(buffer, PAGE_SIZE, "%d\n", qla_tgt_mode_enabled(ha));
116 qla2x00_store_tgt_enabled(struct device *dev,
117 struct device_attribute *attr, const char *buffer, size_t size)
119 struct scsi_qla_host *ha = shost_priv(class_to_shost(dev));
122 if ((buffer == NULL) || (size == 0))
125 if (qla_target.tgt_host_action == NULL) {
126 qla_printk(KERN_INFO, ha, "%s: not acting for lack of target "
127 "driver\n", __func__);
134 res = qla_target.tgt_host_action(ha, DISABLE_TARGET_MODE);
137 res = qla_target.tgt_host_action(ha, ENABLE_TARGET_MODE);
140 qla_printk(KERN_ERR, ha, "%s: Requested action not "
141 "understood: %s\n", __func__, buffer);
149 if ((size > 1) && (buffer[1] == 'r'))
150 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
156 static DEVICE_ATTR(target_mode_enabled,
158 qla2x00_show_tgt_enabled,
159 qla2x00_store_tgt_enabled);
162 qla2x00_show_expl_conf_enabled(struct device *dev,
163 struct device_attribute *attr, char *buffer)
165 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
166 ulong max_size = PAGE_SIZE;
169 size = scnprintf(buffer, max_size, "%d\n", ha->enable_explicit_conf);
175 qla2x00_store_expl_conf_enabled(struct device *dev,
176 struct device_attribute *attr, const char *buffer, size_t size)
178 struct scsi_qla_host *ha = shost_priv(class_to_shost(dev));
184 spin_lock_irqsave(&ha->hardware_lock, flags);
188 ha->enable_explicit_conf = 0;
189 qla_printk(KERN_INFO, ha, "qla2xxx(%ld): explicit conformation "
190 "disabled\n", ha->instance);
193 ha->enable_explicit_conf = 1;
194 qla_printk(KERN_INFO, ha, "qla2xxx(%ld): explicit conformation "
195 "enabled\n", ha->instance);
198 #if defined(QL_DEBUG_LEVEL_9) || defined(QL_DEBUG_LEVEL_11)
199 qla_printk(KERN_ERR, ha, "%s: Requested action not understood: "
200 "%s\n", __func__, buffer);
205 spin_unlock_irqrestore(&ha->hardware_lock, flags);
210 static DEVICE_ATTR(explicit_conform_enabled,
212 qla2x00_show_expl_conf_enabled,
213 qla2x00_store_expl_conf_enabled);
215 #endif /* CONFIG_SCST_PROC */
218 qla2x00_show_resource_counts(struct device *dev,
219 struct device_attribute *attr, char *buffer)
221 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
222 ulong max_size = PAGE_SIZE;
227 mc.mb[0] = MBC_GET_RESOURCE_COUNTS;
229 mc.in_mb = MBX_0|MBX_1|MBX_2;
233 rval = qla2x00_mailbox_command(ha, &mc);
235 if (rval != QLA_SUCCESS) {
236 size = scnprintf(buffer, max_size,
237 "Mailbox Command failed %d, mb %#x",
240 size = scnprintf(buffer, max_size,
241 "immed_notify\t%d\ncommand\t\t%d\n",
248 static DEVICE_ATTR(resource_counts,
250 qla2x00_show_resource_counts,
254 uint8_t port_name[WWN_SIZE];
259 uint8_t port_name[WWN_SIZE];
265 qla2x00_show_port_database(struct device *dev,
266 struct device_attribute *attr, char *buffer)
268 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
269 ulong max_size = PAGE_SIZE;
276 ulong dma_size = 0x100 * sizeof(port24_data_t);
278 pmap = dma_alloc_coherent(&ha->pdev->dev, dma_size,
279 &pmap_dma, GFP_KERNEL);
281 size = scnprintf(buffer, max_size, "DMA Alloc failed of %ld",
286 mc.mb[0] = MBC_PORT_NODE_NAME_LIST;
287 mc.mb[1] = BIT_1 | BIT_3;
288 mc.mb[2] = MSW(pmap_dma);
289 mc.mb[3] = LSW(pmap_dma);
290 mc.mb[6] = MSW(MSD(pmap_dma));
291 mc.mb[7] = LSW(MSD(pmap_dma));
293 mc.out_mb = MBX_0|MBX_1|MBX_2|MBX_3|MBX_6|MBX_7|MBX_8;
294 mc.in_mb = MBX_0|MBX_1;
296 mc.flags = MBX_DMA_IN;
298 rval = qla2x00_mailbox_command(ha, &mc);
300 if (rval != QLA_SUCCESS) {
301 size = scnprintf(buffer, max_size,
302 "Mailbox Command failed %d, mb0 %#x mb1 %#x\n",
303 rval, mc.mb[0], mc.mb[1]);
307 size += scnprintf(buffer+size, max_size-size,
308 "Port Name List (%#04x) returned %d bytes\nL_ID WWPN\n",
309 MBC_PORT_NODE_NAME_LIST, le16_to_cpu(mc.mb[1]));
311 if (IS_FWI2_CAPABLE(ha)) {
312 port24_data_t *pmap24 = pmap;
314 entries = le16_to_cpu(mc.mb[1])/sizeof(*pmap24);
316 for (i = 0; (i < entries) && (size < max_size); ++i) {
317 size += scnprintf(buffer+size, max_size-size,
318 "%04x %02x%02x%02x%02x%02x%02x%02x%02x\n",
319 le16_to_cpu(pmap24[i].loop_id),
320 pmap24[i].port_name[7],
321 pmap24[i].port_name[6],
322 pmap24[i].port_name[5],
323 pmap24[i].port_name[4],
324 pmap24[i].port_name[3],
325 pmap24[i].port_name[2],
326 pmap24[i].port_name[1],
327 pmap24[i].port_name[0]);
330 port_data_t *pmap2x = pmap;
332 entries = le16_to_cpu(mc.mb[1])/sizeof(*pmap2x);
334 for (i = 0; (i < entries) && (size < max_size); ++i) {
335 size += scnprintf(buffer+size, max_size-size,
336 "%04x %02x%02x%02x%02x%02x%02x%02x%02x\n",
337 le16_to_cpu(pmap2x[i].loop_id),
338 pmap2x[i].port_name[7],
339 pmap2x[i].port_name[6],
340 pmap2x[i].port_name[5],
341 pmap2x[i].port_name[4],
342 pmap2x[i].port_name[3],
343 pmap2x[i].port_name[2],
344 pmap2x[i].port_name[1],
345 pmap2x[i].port_name[0]);
350 dma_free_coherent(&ha->pdev->dev, dma_size, pmap, pmap_dma);
352 if (size < max_size) {
353 dma_addr_t gid_list_dma;
354 struct gid_list_info *gid_list;
356 struct gid_list_info *gid;
358 gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
359 &gid_list_dma, GFP_KERNEL);
360 if (gid_list == NULL) {
361 size += scnprintf(buffer+size, max_size-size,
362 "Unable to allocate gid_list");
363 goto out_id_list_failed;
366 /* Get list of logged in devices. */
367 rval = qla2x00_get_id_list(ha, gid_list, gid_list_dma,
369 if (rval != QLA_SUCCESS) {
370 size += scnprintf(buffer+size, max_size-size,
371 "qla2x00_get_id_list failed: %d",
373 goto out_free_id_list;
376 size += scnprintf(buffer+size, max_size-size,
377 "\nGet ID List (0x007C) returned %d entries\n"
381 id_iter = (char *)gid_list;
382 for (i = 0; (i < entries) && (size < max_size); ++i) {
383 gid = (struct gid_list_info *)id_iter;
384 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
385 size += scnprintf(buffer+size, max_size-size,
386 "%02x %02x%02x%02x\n",
393 size += scnprintf(buffer+size, max_size-size,
394 "%04x %02x%02x%02x %02x\n",
395 le16_to_cpu(gid->loop_id),
402 id_iter += ha->gid_list_info_size;
405 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, gid_list,
410 if (size < max_size) {
413 char port_type[] = "URSBIT";
415 size += scnprintf(buffer+size, max_size-size,
416 "\nfc_ports database\n");
418 list_for_each_entry_rcu(fcport, &ha->fcports, list) {
419 if (size >= max_size)
421 switch (atomic_read(&fcport->state)) {
422 case FCS_UNCONFIGURED : state = "Unconfigured"; break;
423 case FCS_DEVICE_DEAD : state = "Dead"; break;
424 case FCS_DEVICE_LOST : state = "Lost"; break;
425 case FCS_ONLINE : state = "Online"; break;
426 case FCS_NOT_SUPPORTED : state = "Not Supported"; break;
427 case FCS_FAILOVER : state = "Failover"; break;
428 case FCS_FAILOVER_FAILED : state = "Failover Failed"; break;
429 default: state = "Unknown"; break;
432 size += scnprintf(buffer+size, max_size-size,
434 "%02x%02x%02x%02x%02x%02x%02x%02x "
437 fcport->d_id.b.domain,
439 fcport->d_id.b.al_pa,
440 fcport->port_name[0], fcport->port_name[1],
441 fcport->port_name[2], fcport->port_name[3],
442 fcport->port_name[4], fcport->port_name[5],
443 fcport->port_name[6], fcport->port_name[7],
444 port_type[fcport->port_type], state);
451 extern int qla2x00_configure_loop(scsi_qla_host_t *);
452 extern int qla2x00_configure_local_loop(scsi_qla_host_t *);
453 extern int qla2x00_configure_fabric(scsi_qla_host_t *);
456 qla2x00_update_portdb(struct device *dev,
457 struct device_attribute *attr, const char *buffer, size_t size)
459 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
461 if ((buffer == NULL) || (size == 0))
466 qla_printk(KERN_INFO, ha, "Reconfiguring loop on %ld\n",
468 qla2x00_configure_loop(ha);
473 qla_printk(KERN_INFO, ha, "Reconfiguring local loop on %ld\n",
475 qla2x00_configure_local_loop(ha);
480 qla_printk(KERN_INFO, ha, "Reconfiguring fabric on %ld\n",
482 qla2x00_configure_fabric(ha);
485 qla_printk(KERN_INFO, ha, "Resyncing loop on %ld\n",
487 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
496 static DEVICE_ATTR(port_database,
498 qla2x00_show_port_database,
499 qla2x00_update_portdb);
501 #endif /* CONFIG_SCSI_QLA2XXX_TARGET */
504 qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
505 struct bin_attribute *bin_attr,
506 char *buf, loff_t off, size_t count)
508 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
509 struct device, kobj)));
510 char *rbuf = (char *)ha->fw_dump;
512 if (ha->fw_dump_reading == 0)
514 if (off > ha->fw_dump_len)
516 if (off + count > ha->fw_dump_len)
517 count = ha->fw_dump_len - off;
519 memcpy(buf, &rbuf[off], count);
525 qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
526 struct bin_attribute *bin_attr,
527 char *buf, loff_t off, size_t count)
529 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
530 struct device, kobj)));
536 reading = simple_strtol(buf, NULL, 10);
539 if (!ha->fw_dump_reading)
542 qla_printk(KERN_INFO, ha,
543 "Firmware dump cleared on (%ld).\n", ha->host_no);
545 ha->fw_dump_reading = 0;
549 if (ha->fw_dumped && !ha->fw_dump_reading) {
550 ha->fw_dump_reading = 1;
552 qla_printk(KERN_INFO, ha,
553 "Raw firmware dump ready for read on (%ld).\n",
558 qla2x00_alloc_fw_dump(ha);
561 qla2x00_system_error(ha);
567 static struct bin_attribute sysfs_fw_dump_attr = {
570 .mode = S_IRUSR | S_IWUSR,
573 .read = qla2x00_sysfs_read_fw_dump,
574 .write = qla2x00_sysfs_write_fw_dump,
578 qla2x00_sysfs_read_nvram(struct kobject *kobj,
579 struct bin_attribute *bin_attr,
580 char *buf, loff_t off, size_t count)
582 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
583 struct device, kobj)));
584 int size = ha->nvram_size;
585 char *nvram_cache = ha->nvram;
587 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
589 if (off + count > size) {
594 /* Read NVRAM data from cache. */
595 memcpy(buf, &nvram_cache[off], count);
601 qla2x00_sysfs_write_nvram(struct kobject *kobj,
602 struct bin_attribute *bin_attr,
603 char *buf, loff_t off, size_t count)
605 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
606 struct device, kobj)));
609 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
612 /* Checksum NVRAM. */
613 if (IS_FWI2_CAPABLE(ha)) {
617 iter = (uint32_t *)buf;
619 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
620 chksum += le32_to_cpu(*iter++);
621 chksum = ~chksum + 1;
622 *iter = cpu_to_le32(chksum);
627 iter = (uint8_t *)buf;
629 for (cnt = 0; cnt < count - 1; cnt++)
631 chksum = ~chksum + 1;
636 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
637 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base,
640 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
645 static struct bin_attribute sysfs_nvram_attr = {
648 .mode = S_IRUSR | S_IWUSR,
651 .read = qla2x00_sysfs_read_nvram,
652 .write = qla2x00_sysfs_write_nvram,
656 qla2x00_sysfs_read_optrom(struct kobject *kobj,
657 struct bin_attribute *bin_attr,
658 char *buf, loff_t off, size_t count)
660 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
661 struct device, kobj)));
663 if (ha->optrom_state != QLA_SREADING)
665 if (off > ha->optrom_region_size)
667 if (off + count > ha->optrom_region_size)
668 count = ha->optrom_region_size - off;
670 memcpy(buf, &ha->optrom_buffer[off], count);
676 qla2x00_sysfs_write_optrom(struct kobject *kobj,
677 struct bin_attribute *bin_attr,
678 char *buf, loff_t off, size_t count)
680 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
681 struct device, kobj)));
683 if (ha->optrom_state != QLA_SWRITING)
685 if (off > ha->optrom_region_size)
687 if (off + count > ha->optrom_region_size)
688 count = ha->optrom_region_size - off;
690 memcpy(&ha->optrom_buffer[off], buf, count);
695 static struct bin_attribute sysfs_optrom_attr = {
698 .mode = S_IRUSR | S_IWUSR,
701 .read = qla2x00_sysfs_read_optrom,
702 .write = qla2x00_sysfs_write_optrom,
706 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
707 struct bin_attribute *bin_attr,
708 char *buf, loff_t off, size_t count)
710 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
711 struct device, kobj)));
713 uint32_t size = ha->optrom_size;
719 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
721 if (start > ha->optrom_size)
726 if (ha->optrom_state != QLA_SREADING &&
727 ha->optrom_state != QLA_SWRITING)
730 ha->optrom_state = QLA_SWAITING;
732 DEBUG2(qla_printk(KERN_INFO, ha,
733 "Freeing flash region allocation -- 0x%x bytes.\n",
734 ha->optrom_region_size));
736 vfree(ha->optrom_buffer);
737 ha->optrom_buffer = NULL;
740 if (ha->optrom_state != QLA_SWAITING)
744 qla_printk(KERN_WARNING, ha,
745 "Invalid start region 0x%x/0x%x.\n", start, size);
749 ha->optrom_region_start = start;
750 ha->optrom_region_size = start + size > ha->optrom_size ?
751 ha->optrom_size - start : size;
753 ha->optrom_state = QLA_SREADING;
754 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
755 if (ha->optrom_buffer == NULL) {
756 qla_printk(KERN_WARNING, ha,
757 "Unable to allocate memory for optrom retrieval "
758 "(%x).\n", ha->optrom_region_size);
760 ha->optrom_state = QLA_SWAITING;
764 DEBUG2(qla_printk(KERN_INFO, ha,
765 "Reading flash region -- 0x%x/0x%x.\n",
766 ha->optrom_region_start, ha->optrom_region_size));
768 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
769 ha->isp_ops->read_optrom(ha, ha->optrom_buffer,
770 ha->optrom_region_start, ha->optrom_region_size);
773 if (ha->optrom_state != QLA_SWAITING)
777 * We need to be more restrictive on which FLASH regions are
778 * allowed to be updated via user-space. Regions accessible
779 * via this method include:
781 * ISP21xx/ISP22xx/ISP23xx type boards:
783 * 0x000000 -> 0x020000 -- Boot code.
785 * ISP2322/ISP24xx type boards:
787 * 0x000000 -> 0x07ffff -- Boot code.
788 * 0x080000 -> 0x0fffff -- Firmware.
790 * ISP25xx type boards:
792 * 0x000000 -> 0x07ffff -- Boot code.
793 * 0x080000 -> 0x0fffff -- Firmware.
794 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
797 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
799 else if (start == (FA_BOOT_CODE_ADDR*4) ||
800 start == (FA_RISC_CODE_ADDR*4))
802 else if (IS_QLA25XX(ha) && start == (FA_VPD_NVRAM_ADDR*4))
805 qla_printk(KERN_WARNING, ha,
806 "Invalid start region 0x%x/0x%x.\n", start, size);
810 ha->optrom_region_start = start;
811 ha->optrom_region_size = start + size > ha->optrom_size ?
812 ha->optrom_size - start : size;
814 ha->optrom_state = QLA_SWRITING;
815 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
816 if (ha->optrom_buffer == NULL) {
817 qla_printk(KERN_WARNING, ha,
818 "Unable to allocate memory for optrom update "
819 "(%x).\n", ha->optrom_region_size);
821 ha->optrom_state = QLA_SWAITING;
825 DEBUG2(qla_printk(KERN_INFO, ha,
826 "Staging flash region write -- 0x%x/0x%x.\n",
827 ha->optrom_region_start, ha->optrom_region_size));
829 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
832 if (ha->optrom_state != QLA_SWRITING)
835 DEBUG2(qla_printk(KERN_INFO, ha,
836 "Writing flash region -- 0x%x/0x%x.\n",
837 ha->optrom_region_start, ha->optrom_region_size));
839 ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
840 ha->optrom_region_start, ha->optrom_region_size);
848 static struct bin_attribute sysfs_optrom_ctl_attr = {
850 .name = "optrom_ctl",
854 .write = qla2x00_sysfs_write_optrom_ctl,
858 qla2x00_sysfs_read_vpd(struct kobject *kobj,
859 struct bin_attribute *bin_attr,
860 char *buf, loff_t off, size_t count)
862 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
863 struct device, kobj)));
864 int size = ha->vpd_size;
865 char *vpd_cache = ha->vpd;
867 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
869 if (off + count > size) {
874 /* Read NVRAM data from cache. */
875 memcpy(buf, &vpd_cache[off], count);
881 qla2x00_sysfs_write_vpd(struct kobject *kobj,
882 struct bin_attribute *bin_attr,
883 char *buf, loff_t off, size_t count)
885 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
886 struct device, kobj)));
888 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
892 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
893 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
898 static struct bin_attribute sysfs_vpd_attr = {
901 .mode = S_IRUSR | S_IWUSR,
904 .read = qla2x00_sysfs_read_vpd,
905 .write = qla2x00_sysfs_write_vpd,
909 qla2x00_sysfs_read_sfp(struct kobject *kobj,
910 struct bin_attribute *bin_attr,
911 char *buf, loff_t off, size_t count)
913 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
914 struct device, kobj)));
915 uint16_t iter, addr, offset;
918 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
924 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
927 qla_printk(KERN_WARNING, ha,
928 "Unable to allocate memory for SFP read-data.\n");
933 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
935 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
936 iter++, offset += SFP_BLOCK_SIZE) {
938 /* Skip to next device address. */
943 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
945 if (rval != QLA_SUCCESS) {
946 qla_printk(KERN_WARNING, ha,
947 "Unable to read SFP data (%x/%x/%x).\n", rval,
952 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
953 buf += SFP_BLOCK_SIZE;
959 static struct bin_attribute sysfs_sfp_attr = {
962 .mode = S_IRUSR | S_IWUSR,
964 .size = SFP_DEV_SIZE * 2,
965 .read = qla2x00_sysfs_read_sfp,
968 static struct sysfs_entry {
970 struct bin_attribute *attr;
972 } bin_file_entries[] = {
973 { "fw_dump", &sysfs_fw_dump_attr, },
974 { "nvram", &sysfs_nvram_attr, },
975 { "optrom", &sysfs_optrom_attr, },
976 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
977 { "vpd", &sysfs_vpd_attr, 1 },
978 { "sfp", &sysfs_sfp_attr, 1 },
983 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
985 struct Scsi_Host *host = ha->host;
986 struct sysfs_entry *iter;
989 for (iter = bin_file_entries; iter->name; iter++) {
990 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
993 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
996 qla_printk(KERN_INFO, ha,
997 "Unable to create sysfs %s binary attribute "
998 "(%d).\n", iter->name, ret);
1003 qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
1005 struct Scsi_Host *host = ha->host;
1006 struct sysfs_entry *iter;
1008 for (iter = bin_file_entries; iter->name; iter++) {
1009 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
1012 sysfs_remove_bin_file(&host->shost_gendev.kobj,
1016 if (ha->beacon_blink_led == 1)
1017 ha->isp_ops->beacon_off(ha);
1020 /* Scsi_Host attributes. */
1023 qla2x00_drvr_version_show(struct device *dev,
1024 struct device_attribute *attr, char *buf)
1026 return scnprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
1030 qla2x00_fw_version_show(struct device *dev,
1031 struct device_attribute *attr, char *buf)
1033 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1036 return scnprintf(buf, PAGE_SIZE, "%s\n",
1037 ha->isp_ops->fw_version_str(ha, fw_str));
1041 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
1044 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1047 if (IS_FWI2_CAPABLE(ha))
1048 return scnprintf(buf, PAGE_SIZE, "\n");
1050 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
1051 return scnprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
1056 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
1059 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1060 return scnprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
1064 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
1067 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1068 return scnprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
1069 ha->product_id[0], ha->product_id[1], ha->product_id[2],
1074 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
1077 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1078 return scnprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
1082 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
1085 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1086 return scnprintf(buf, PAGE_SIZE, "%s\n",
1087 ha->model_desc ? ha->model_desc: "");
1091 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
1094 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1097 return scnprintf(buf, PAGE_SIZE, "%s\n",
1098 ha->isp_ops->pci_info_str(ha, pci_info));
1102 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
1105 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1108 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1109 atomic_read(&ha->loop_state) == LOOP_DEAD)
1110 len = scnprintf(buf, PAGE_SIZE, "Link Down\n");
1111 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
1112 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
1113 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
1114 len = scnprintf(buf, PAGE_SIZE, "Unknown Link State\n");
1116 len = scnprintf(buf, PAGE_SIZE, "Link Up - ");
1118 switch (ha->current_topology) {
1120 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1123 len += scnprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
1126 len += scnprintf(buf + len, PAGE_SIZE-len,
1127 "N_Port to N_Port\n");
1130 len += scnprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
1133 len += scnprintf(buf + len, PAGE_SIZE-len, "Loop\n");
1141 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
1144 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1147 switch (ha->zio_mode) {
1148 case QLA_ZIO_MODE_6:
1149 len += scnprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
1151 case QLA_ZIO_DISABLED:
1152 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1159 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
1160 const char *buf, size_t count)
1162 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1166 if (!IS_ZIO_SUPPORTED(ha))
1169 if (sscanf(buf, "%d", &val) != 1)
1173 zio_mode = QLA_ZIO_MODE_6;
1175 zio_mode = QLA_ZIO_DISABLED;
1177 /* Update per-hba values and queue a reset. */
1178 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
1179 ha->zio_mode = zio_mode;
1180 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1186 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
1189 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1191 return scnprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
1195 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
1196 const char *buf, size_t count)
1198 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1202 if (sscanf(buf, "%d", &val) != 1)
1204 if (val > 25500 || val < 100)
1207 zio_timer = (uint16_t)(val / 100);
1208 ha->zio_timer = zio_timer;
1214 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
1217 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1220 if (ha->beacon_blink_led)
1221 len += scnprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
1223 len += scnprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
1228 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
1229 const char *buf, size_t count)
1231 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1235 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1238 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
1239 qla_printk(KERN_WARNING, ha,
1240 "Abort ISP active -- ignoring beacon request.\n");
1244 if (sscanf(buf, "%d", &val) != 1)
1248 rval = ha->isp_ops->beacon_on(ha);
1250 rval = ha->isp_ops->beacon_off(ha);
1252 if (rval != QLA_SUCCESS)
1259 qla2x00_optrom_bios_version_show(struct device *dev,
1260 struct device_attribute *attr, char *buf)
1262 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1264 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
1265 ha->bios_revision[0]);
1269 qla2x00_optrom_efi_version_show(struct device *dev,
1270 struct device_attribute *attr, char *buf)
1272 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1274 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
1275 ha->efi_revision[0]);
1279 qla2x00_optrom_fcode_version_show(struct device *dev,
1280 struct device_attribute *attr, char *buf)
1282 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1284 return scnprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
1285 ha->fcode_revision[0]);
1289 qla2x00_optrom_fw_version_show(struct device *dev,
1290 struct device_attribute *attr, char *buf)
1292 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
1294 return scnprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
1295 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
1296 ha->fw_revision[3]);
1299 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
1300 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
1301 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
1302 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
1303 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
1304 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
1305 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
1306 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
1307 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
1308 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
1309 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
1310 qla2x00_zio_timer_store);
1311 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
1312 qla2x00_beacon_store);
1313 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
1314 qla2x00_optrom_bios_version_show, NULL);
1315 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
1316 qla2x00_optrom_efi_version_show, NULL);
1317 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
1318 qla2x00_optrom_fcode_version_show, NULL);
1319 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
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_class2_enabled,
1340 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
1341 #ifdef CONFIG_SCST_PROC
1342 &dev_attr_target_mode_enabled,
1343 &dev_attr_explicit_conform_enabled,
1345 &dev_attr_resource_counts,
1346 &dev_attr_port_database,
1351 /* Host attributes. */
1354 qla2x00_get_host_port_id(struct Scsi_Host *shost)
1356 scsi_qla_host_t *ha = shost_priv(shost);
1358 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
1359 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
1363 qla2x00_get_host_speed(struct Scsi_Host *shost)
1365 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
1366 u32 speed = FC_PORTSPEED_UNKNOWN;
1368 switch (ha->link_data_rate) {
1369 case PORT_SPEED_1GB:
1370 speed = FC_PORTSPEED_1GBIT;
1372 case PORT_SPEED_2GB:
1373 speed = FC_PORTSPEED_2GBIT;
1375 case PORT_SPEED_4GB:
1376 speed = FC_PORTSPEED_4GBIT;
1378 case PORT_SPEED_8GB:
1379 speed = FC_PORTSPEED_8GBIT;
1382 fc_host_speed(shost) = speed;
1386 qla2x00_get_host_port_type(struct Scsi_Host *shost)
1388 scsi_qla_host_t *ha = shost_priv(shost);
1389 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
1392 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
1395 switch (ha->current_topology) {
1397 port_type = FC_PORTTYPE_LPORT;
1400 port_type = FC_PORTTYPE_NLPORT;
1403 port_type = FC_PORTTYPE_PTP;
1406 port_type = FC_PORTTYPE_NPORT;
1409 fc_host_port_type(shost) = port_type;
1413 qla2x00_get_starget_node_name(struct scsi_target *starget)
1415 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1416 scsi_qla_host_t *ha = shost_priv(host);
1420 list_for_each_entry_rcu(fcport, &ha->fcports, list) {
1421 if (fcport->rport &&
1422 starget->id == fcport->rport->scsi_target_id) {
1423 node_name = wwn_to_u64(fcport->node_name);
1428 fc_starget_node_name(starget) = node_name;
1432 qla2x00_get_starget_port_name(struct scsi_target *starget)
1434 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1435 scsi_qla_host_t *ha = shost_priv(host);
1439 list_for_each_entry_rcu(fcport, &ha->fcports, list) {
1440 if (fcport->rport &&
1441 starget->id == fcport->rport->scsi_target_id) {
1442 port_name = wwn_to_u64(fcport->port_name);
1447 fc_starget_port_name(starget) = port_name;
1451 qla2x00_get_starget_port_id(struct scsi_target *starget)
1453 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
1454 scsi_qla_host_t *ha = shost_priv(host);
1456 uint32_t port_id = ~0U;
1458 list_for_each_entry_rcu(fcport, &ha->fcports, list) {
1459 if (fcport->rport &&
1460 starget->id == fcport->rport->scsi_target_id) {
1461 port_id = fcport->d_id.b.domain << 16 |
1462 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
1467 fc_starget_port_id(starget) = port_id;
1471 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
1474 rport->dev_loss_tmo = timeout;
1476 rport->dev_loss_tmo = 1;
1480 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
1482 struct Scsi_Host *host = rport_to_shost(rport);
1483 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1485 qla2x00_abort_fcport_cmds(fcport);
1488 * Transport has effectively 'deleted' the rport, clear
1489 * all local references.
1491 spin_lock_irq(host->host_lock);
1492 fcport->rport = NULL;
1493 *((fc_port_t **)rport->dd_data) = NULL;
1494 spin_unlock_irq(host->host_lock);
1498 qla2x00_terminate_rport_io(struct fc_rport *rport)
1500 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
1502 qla2x00_abort_fcport_cmds(fcport);
1503 scsi_target_unblock(&rport->dev);
1507 qla2x00_issue_lip(struct Scsi_Host *shost)
1509 scsi_qla_host_t *ha = shost_priv(shost);
1511 qla2x00_loop_reset(ha);
1515 static struct fc_host_statistics *
1516 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1518 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
1520 struct link_statistics *stats;
1521 dma_addr_t stats_dma;
1522 struct fc_host_statistics *pfc_host_stat;
1524 pfc_host_stat = &ha->fc_host_stat;
1525 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1527 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1528 if (stats == NULL) {
1529 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1530 __func__, ha->host_no));
1533 memset(stats, 0, DMA_POOL_SIZE);
1535 rval = QLA_FUNCTION_FAILED;
1536 if (IS_FWI2_CAPABLE(ha)) {
1537 rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
1538 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
1539 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
1540 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
1542 /* Must be in a 'READY' state for statistics retrieval. */
1543 rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
1547 if (rval != QLA_SUCCESS)
1550 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1551 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1552 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1553 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1554 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1555 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1556 if (IS_FWI2_CAPABLE(ha)) {
1557 pfc_host_stat->tx_frames = stats->tx_frames;
1558 pfc_host_stat->rx_frames = stats->rx_frames;
1559 pfc_host_stat->dumped_frames = stats->dumped_frames;
1560 pfc_host_stat->nos_count = stats->nos_rcvd;
1564 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
1566 return pfc_host_stat;
1570 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1572 scsi_qla_host_t *ha = shost_priv(shost);
1574 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
1578 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1580 scsi_qla_host_t *ha = shost_priv(shost);
1582 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
1586 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1588 scsi_qla_host_t *ha = shost_priv(shost);
1591 if (ha->device_flags & SWITCH_FOUND)
1592 node_name = wwn_to_u64(ha->fabric_node_name);
1594 node_name = wwn_to_u64(ha->node_name);
1596 fc_host_fabric_name(shost) = node_name;
1600 qla2x00_get_host_port_state(struct Scsi_Host *shost)
1602 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
1604 if (!ha->flags.online)
1605 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1606 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
1607 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1609 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1613 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1616 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
1617 scsi_qla_host_t *vha;
1619 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1621 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1622 "status %x\n", ret));
1626 vha = qla24xx_create_vhost(fc_vport);
1628 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1630 return FC_VPORT_FAILED;
1633 atomic_set(&vha->vp_state, VP_OFFLINE);
1634 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1636 atomic_set(&vha->vp_state, VP_FAILED);
1638 /* ready to create vport */
1639 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1641 /* initialized vport states */
1642 atomic_set(&vha->loop_state, LOOP_DOWN);
1643 vha->vp_err_state= VP_ERR_PORTDWN;
1644 vha->vp_prev_err_state= VP_ERR_UNKWN;
1645 /* Check if physical ha port is Up */
1646 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1647 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1648 /* Don't retry or attempt login of this virtual port */
1649 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1651 atomic_set(&vha->loop_state, LOOP_DEAD);
1653 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1656 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1657 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1658 vha->host_no, vha->vp_idx));
1659 goto vport_create_failed_2;
1662 /* initialize attributes */
1663 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1664 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1665 fc_host_supported_classes(vha->host) =
1666 fc_host_supported_classes(ha->host);
1667 fc_host_supported_speeds(vha->host) =
1668 fc_host_supported_speeds(ha->host);
1670 qla24xx_vport_disable(fc_vport, disable);
1673 vport_create_failed_2:
1674 qla24xx_disable_vp(vha);
1675 qla24xx_deallocate_vp_id(vha);
1676 kfree(vha->port_name);
1677 kfree(vha->node_name);
1678 scsi_host_put(vha->host);
1679 return FC_VPORT_FAILED;
1683 qla24xx_vport_delete(struct fc_vport *fc_vport)
1685 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
1686 scsi_qla_host_t *vha = fc_vport->dd_data;
1688 qla24xx_disable_vp(vha);
1689 qla24xx_deallocate_vp_id(vha);
1691 mutex_lock(&ha->vport_lock);
1692 ha->cur_vport_count--;
1693 clear_bit(vha->vp_idx, ha->vp_idx_map);
1694 mutex_unlock(&ha->vport_lock);
1696 kfree(vha->node_name);
1697 kfree(vha->port_name);
1699 if (vha->timer_active) {
1700 qla2x00_vp_stop_timer(vha);
1701 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1703 vha->host_no, vha->vp_idx, vha));
1706 fc_remove_host(vha->host);
1708 scsi_remove_host(vha->host);
1710 scsi_host_put(vha->host);
1716 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1718 scsi_qla_host_t *vha = fc_vport->dd_data;
1721 qla24xx_disable_vp(vha);
1723 qla24xx_enable_vp(vha);
1728 struct fc_function_template qla2xxx_transport_functions = {
1730 .show_host_node_name = 1,
1731 .show_host_port_name = 1,
1732 .show_host_supported_classes = 1,
1733 .show_host_supported_speeds = 1,
1735 .get_host_port_id = qla2x00_get_host_port_id,
1736 .show_host_port_id = 1,
1737 .get_host_speed = qla2x00_get_host_speed,
1738 .show_host_speed = 1,
1739 .get_host_port_type = qla2x00_get_host_port_type,
1740 .show_host_port_type = 1,
1741 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1742 .show_host_symbolic_name = 1,
1743 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1744 .show_host_system_hostname = 1,
1745 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1746 .show_host_fabric_name = 1,
1747 .get_host_port_state = qla2x00_get_host_port_state,
1748 .show_host_port_state = 1,
1750 .dd_fcrport_size = sizeof(struct fc_port *),
1751 .show_rport_supported_classes = 1,
1753 .get_starget_node_name = qla2x00_get_starget_node_name,
1754 .show_starget_node_name = 1,
1755 .get_starget_port_name = qla2x00_get_starget_port_name,
1756 .show_starget_port_name = 1,
1757 .get_starget_port_id = qla2x00_get_starget_port_id,
1758 .show_starget_port_id = 1,
1760 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1761 .show_rport_dev_loss_tmo = 1,
1763 .issue_fc_host_lip = qla2x00_issue_lip,
1764 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1765 .terminate_rport_io = qla2x00_terminate_rport_io,
1766 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1768 .vport_create = qla24xx_vport_create,
1769 .vport_disable = qla24xx_vport_disable,
1770 .vport_delete = qla24xx_vport_delete,
1773 struct fc_function_template qla2xxx_transport_vport_functions = {
1775 .show_host_node_name = 1,
1776 .show_host_port_name = 1,
1777 .show_host_supported_classes = 1,
1779 .get_host_port_id = qla2x00_get_host_port_id,
1780 .show_host_port_id = 1,
1781 .get_host_speed = qla2x00_get_host_speed,
1782 .show_host_speed = 1,
1783 .get_host_port_type = qla2x00_get_host_port_type,
1784 .show_host_port_type = 1,
1785 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1786 .show_host_symbolic_name = 1,
1787 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1788 .show_host_system_hostname = 1,
1789 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1790 .show_host_fabric_name = 1,
1791 .get_host_port_state = qla2x00_get_host_port_state,
1792 .show_host_port_state = 1,
1794 .dd_fcrport_size = sizeof(struct fc_port *),
1795 .show_rport_supported_classes = 1,
1797 .get_starget_node_name = qla2x00_get_starget_node_name,
1798 .show_starget_node_name = 1,
1799 .get_starget_port_name = qla2x00_get_starget_port_name,
1800 .show_starget_port_name = 1,
1801 .get_starget_port_id = qla2x00_get_starget_port_id,
1802 .show_starget_port_id = 1,
1804 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1805 .show_rport_dev_loss_tmo = 1,
1807 .issue_fc_host_lip = qla2x00_issue_lip,
1808 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1809 .terminate_rport_io = qla2x00_terminate_rport_io,
1810 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1814 qla2x00_init_host_attr(scsi_qla_host_t *ha)
1816 u32 speed = FC_PORTSPEED_UNKNOWN;
1818 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1819 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
1820 fc_host_supported_classes(ha->host) = ha->enable_class_2 ?
1821 (FC_COS_CLASS2|FC_COS_CLASS3) : FC_COS_CLASS3;
1822 fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
1823 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
1826 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1827 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1828 else if (IS_QLA24XX_TYPE(ha))
1829 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1831 else if (IS_QLA23XX(ha))
1832 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1834 speed = FC_PORTSPEED_1GBIT;
1835 fc_host_supported_speeds(ha->host) = speed;