2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/kthread.h>
10 #include <linux/vmalloc.h>
12 int qla24xx_vport_disable(struct fc_vport *, bool);
14 /* SYSFS attributes --------------------------------------------------------- */
17 qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
18 struct bin_attribute *bin_attr,
19 char *buf, loff_t off, size_t count)
21 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
22 struct device, kobj)));
23 char *rbuf = (char *)ha->fw_dump;
25 if (ha->fw_dump_reading == 0)
27 if (off > ha->fw_dump_len)
29 if (off + count > ha->fw_dump_len)
30 count = ha->fw_dump_len - off;
32 memcpy(buf, &rbuf[off], count);
38 qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
39 struct bin_attribute *bin_attr,
40 char *buf, loff_t off, size_t count)
42 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
43 struct device, kobj)));
49 reading = simple_strtol(buf, NULL, 10);
52 if (!ha->fw_dump_reading)
55 qla_printk(KERN_INFO, ha,
56 "Firmware dump cleared on (%ld).\n", ha->host_no);
58 ha->fw_dump_reading = 0;
62 if (ha->fw_dumped && !ha->fw_dump_reading) {
63 ha->fw_dump_reading = 1;
65 qla_printk(KERN_INFO, ha,
66 "Raw firmware dump ready for read on (%ld).\n",
71 qla2x00_alloc_fw_dump(ha);
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 *ha = shost_priv(dev_to_shost(container_of(kobj,
93 struct device, kobj)));
94 int size = ha->nvram_size;
95 char *nvram_cache = ha->nvram;
97 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
99 if (off + count > size) {
104 /* Read NVRAM data from cache. */
105 memcpy(buf, &nvram_cache[off], count);
111 qla2x00_sysfs_write_nvram(struct kobject *kobj,
112 struct bin_attribute *bin_attr,
113 char *buf, loff_t off, size_t count)
115 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
116 struct device, kobj)));
119 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
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;
146 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
147 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base,
150 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
155 static struct bin_attribute sysfs_nvram_attr = {
158 .mode = S_IRUSR | S_IWUSR,
161 .read = qla2x00_sysfs_read_nvram,
162 .write = qla2x00_sysfs_write_nvram,
166 qla2x00_sysfs_read_optrom(struct kobject *kobj,
167 struct bin_attribute *bin_attr,
168 char *buf, loff_t off, size_t count)
170 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
171 struct device, kobj)));
173 if (ha->optrom_state != QLA_SREADING)
175 if (off > ha->optrom_region_size)
177 if (off + count > ha->optrom_region_size)
178 count = ha->optrom_region_size - off;
180 memcpy(buf, &ha->optrom_buffer[off], count);
186 qla2x00_sysfs_write_optrom(struct kobject *kobj,
187 struct bin_attribute *bin_attr,
188 char *buf, loff_t off, size_t count)
190 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
191 struct device, kobj)));
193 if (ha->optrom_state != QLA_SWRITING)
195 if (off > ha->optrom_region_size)
197 if (off + count > ha->optrom_region_size)
198 count = ha->optrom_region_size - off;
200 memcpy(&ha->optrom_buffer[off], buf, count);
205 static struct bin_attribute sysfs_optrom_attr = {
208 .mode = S_IRUSR | S_IWUSR,
211 .read = qla2x00_sysfs_read_optrom,
212 .write = qla2x00_sysfs_write_optrom,
216 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
217 struct bin_attribute *bin_attr,
218 char *buf, loff_t off, size_t count)
220 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
221 struct device, kobj)));
223 uint32_t size = ha->optrom_size;
229 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
231 if (start > ha->optrom_size)
236 if (ha->optrom_state != QLA_SREADING &&
237 ha->optrom_state != QLA_SWRITING)
240 ha->optrom_state = QLA_SWAITING;
242 DEBUG2(qla_printk(KERN_INFO, ha,
243 "Freeing flash region allocation -- 0x%x bytes.\n",
244 ha->optrom_region_size));
246 vfree(ha->optrom_buffer);
247 ha->optrom_buffer = NULL;
250 if (ha->optrom_state != QLA_SWAITING)
254 qla_printk(KERN_WARNING, ha,
255 "Invalid start region 0x%x/0x%x.\n", start, size);
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(ha, 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 == (FA_BOOT_CODE_ADDR*4) ||
310 start == (FA_RISC_CODE_ADDR*4))
312 else if (IS_QLA25XX(ha) && start == (FA_VPD_NVRAM_ADDR*4))
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 DEBUG2(qla_printk(KERN_INFO, ha,
346 "Writing flash region -- 0x%x/0x%x.\n",
347 ha->optrom_region_start, ha->optrom_region_size));
349 ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
350 ha->optrom_region_start, ha->optrom_region_size);
358 static struct bin_attribute sysfs_optrom_ctl_attr = {
360 .name = "optrom_ctl",
364 .write = qla2x00_sysfs_write_optrom_ctl,
368 qla2x00_sysfs_read_vpd(struct kobject *kobj,
369 struct bin_attribute *bin_attr,
370 char *buf, loff_t off, size_t count)
372 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
373 struct device, kobj)));
374 int size = ha->vpd_size;
375 char *vpd_cache = ha->vpd;
377 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
379 if (off + count > size) {
384 /* Read NVRAM data from cache. */
385 memcpy(buf, &vpd_cache[off], count);
391 qla2x00_sysfs_write_vpd(struct kobject *kobj,
392 struct bin_attribute *bin_attr,
393 char *buf, loff_t off, size_t count)
395 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
396 struct device, kobj)));
398 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
402 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
403 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
408 static struct bin_attribute sysfs_vpd_attr = {
411 .mode = S_IRUSR | S_IWUSR,
414 .read = qla2x00_sysfs_read_vpd,
415 .write = qla2x00_sysfs_write_vpd,
419 qla2x00_sysfs_read_sfp(struct kobject *kobj,
420 struct bin_attribute *bin_attr,
421 char *buf, loff_t off, size_t count)
423 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
424 struct device, kobj)));
425 uint16_t iter, addr, offset;
428 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
432 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
433 iter++, offset += SFP_BLOCK_SIZE) {
435 /* Skip to next device address. */
440 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
442 if (rval != QLA_SUCCESS) {
443 qla_printk(KERN_WARNING, ha,
444 "Unable to read SFP data (%x/%x/%x).\n", rval,
449 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
450 buf += SFP_BLOCK_SIZE;
456 static struct bin_attribute sysfs_sfp_attr = {
459 .mode = S_IRUSR | S_IWUSR,
461 .size = SFP_DEV_SIZE * 2,
462 .read = qla2x00_sysfs_read_sfp,
465 static struct sysfs_entry {
467 struct bin_attribute *attr;
469 } bin_file_entries[] = {
470 { "fw_dump", &sysfs_fw_dump_attr, },
471 { "nvram", &sysfs_nvram_attr, },
472 { "optrom", &sysfs_optrom_attr, },
473 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
474 { "vpd", &sysfs_vpd_attr, 1 },
475 { "sfp", &sysfs_sfp_attr, 1 },
480 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
482 struct Scsi_Host *host = ha->host;
483 struct sysfs_entry *iter;
486 for (iter = bin_file_entries; iter->name; iter++) {
487 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
490 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
493 qla_printk(KERN_INFO, ha,
494 "Unable to create sysfs %s binary attribute "
495 "(%d).\n", iter->name, ret);
500 qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
502 struct Scsi_Host *host = ha->host;
503 struct sysfs_entry *iter;
505 for (iter = bin_file_entries; iter->name; iter++) {
506 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
509 sysfs_remove_bin_file(&host->shost_gendev.kobj,
513 if (ha->beacon_blink_led == 1)
514 ha->isp_ops->beacon_off(ha);
517 /* Scsi_Host attributes. */
520 qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
522 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
526 qla2x00_fw_version_show(struct class_device *cdev, char *buf)
528 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
531 return snprintf(buf, PAGE_SIZE, "%s\n",
532 ha->isp_ops->fw_version_str(ha, fw_str));
536 qla2x00_serial_num_show(struct class_device *cdev, char *buf)
538 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
541 if (IS_FWI2_CAPABLE(ha))
542 return snprintf(buf, PAGE_SIZE, "\n");
544 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
545 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
550 qla2x00_isp_name_show(struct class_device *cdev, char *buf)
552 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
553 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
557 qla2x00_isp_id_show(struct class_device *cdev, char *buf)
559 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
560 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
561 ha->product_id[0], ha->product_id[1], ha->product_id[2],
566 qla2x00_model_name_show(struct class_device *cdev, char *buf)
568 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
569 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
573 qla2x00_model_desc_show(struct class_device *cdev, char *buf)
575 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
576 return snprintf(buf, PAGE_SIZE, "%s\n",
577 ha->model_desc ? ha->model_desc: "");
581 qla2x00_pci_info_show(struct class_device *cdev, char *buf)
583 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
586 return snprintf(buf, PAGE_SIZE, "%s\n",
587 ha->isp_ops->pci_info_str(ha, pci_info));
591 qla2x00_state_show(struct class_device *cdev, char *buf)
593 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
596 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
597 atomic_read(&ha->loop_state) == LOOP_DEAD)
598 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
599 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
600 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
601 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
602 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
604 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
606 switch (ha->current_topology) {
608 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
611 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
614 len += snprintf(buf + len, PAGE_SIZE-len,
615 "N_Port to N_Port\n");
618 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
621 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
629 qla2x00_zio_show(struct class_device *cdev, char *buf)
631 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
634 switch (ha->zio_mode) {
636 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
638 case QLA_ZIO_DISABLED:
639 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
646 qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
648 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
652 if (!IS_ZIO_SUPPORTED(ha))
655 if (sscanf(buf, "%d", &val) != 1)
659 zio_mode = QLA_ZIO_MODE_6;
661 zio_mode = QLA_ZIO_DISABLED;
663 /* Update per-hba values and queue a reset. */
664 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
665 ha->zio_mode = zio_mode;
666 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
672 qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
674 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
676 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
680 qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
683 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
687 if (sscanf(buf, "%d", &val) != 1)
689 if (val > 25500 || val < 100)
692 zio_timer = (uint16_t)(val / 100);
693 ha->zio_timer = zio_timer;
699 qla2x00_beacon_show(struct class_device *cdev, char *buf)
701 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
704 if (ha->beacon_blink_led)
705 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
707 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
712 qla2x00_beacon_store(struct class_device *cdev, const char *buf,
715 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
719 if (IS_QLA2100(ha) || IS_QLA2200(ha))
722 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
723 qla_printk(KERN_WARNING, ha,
724 "Abort ISP active -- ignoring beacon request.\n");
728 if (sscanf(buf, "%d", &val) != 1)
732 rval = ha->isp_ops->beacon_on(ha);
734 rval = ha->isp_ops->beacon_off(ha);
736 if (rval != QLA_SUCCESS)
743 qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
745 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
747 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
748 ha->bios_revision[0]);
752 qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
754 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
756 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
757 ha->efi_revision[0]);
761 qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
763 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
765 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
766 ha->fcode_revision[0]);
770 qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
772 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
774 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
775 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
779 static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
781 static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
782 static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
783 static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
784 static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
785 static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
786 static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
787 static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
788 static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
789 static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
791 static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
792 qla2x00_zio_timer_store);
793 static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
794 qla2x00_beacon_store);
795 static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
796 qla2x00_optrom_bios_version_show, NULL);
797 static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
798 qla2x00_optrom_efi_version_show, NULL);
799 static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
800 qla2x00_optrom_fcode_version_show, NULL);
801 static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
802 qla2x00_optrom_fw_version_show, NULL);
804 struct class_device_attribute *qla2x00_host_attrs[] = {
805 &class_device_attr_driver_version,
806 &class_device_attr_fw_version,
807 &class_device_attr_serial_num,
808 &class_device_attr_isp_name,
809 &class_device_attr_isp_id,
810 &class_device_attr_model_name,
811 &class_device_attr_model_desc,
812 &class_device_attr_pci_info,
813 &class_device_attr_state,
814 &class_device_attr_zio,
815 &class_device_attr_zio_timer,
816 &class_device_attr_beacon,
817 &class_device_attr_optrom_bios_version,
818 &class_device_attr_optrom_efi_version,
819 &class_device_attr_optrom_fcode_version,
820 &class_device_attr_optrom_fw_version,
824 /* Host attributes. */
827 qla2x00_get_host_port_id(struct Scsi_Host *shost)
829 scsi_qla_host_t *ha = shost_priv(shost);
831 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
832 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
836 qla2x00_get_host_speed(struct Scsi_Host *shost)
838 scsi_qla_host_t *ha = shost_priv(shost);
841 switch (ha->link_data_rate) {
852 fc_host_speed(shost) = speed;
856 qla2x00_get_host_port_type(struct Scsi_Host *shost)
858 scsi_qla_host_t *ha = shost_priv(shost);
859 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
861 switch (ha->current_topology) {
863 port_type = FC_PORTTYPE_LPORT;
866 port_type = FC_PORTTYPE_NLPORT;
869 port_type = FC_PORTTYPE_PTP;
872 port_type = FC_PORTTYPE_NPORT;
875 fc_host_port_type(shost) = port_type;
879 qla2x00_get_starget_node_name(struct scsi_target *starget)
881 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
882 scsi_qla_host_t *ha = shost_priv(host);
886 list_for_each_entry(fcport, &ha->fcports, list) {
887 if (starget->id == fcport->os_target_id) {
888 node_name = wwn_to_u64(fcport->node_name);
893 fc_starget_node_name(starget) = node_name;
897 qla2x00_get_starget_port_name(struct scsi_target *starget)
899 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
900 scsi_qla_host_t *ha = shost_priv(host);
904 list_for_each_entry(fcport, &ha->fcports, list) {
905 if (starget->id == fcport->os_target_id) {
906 port_name = wwn_to_u64(fcport->port_name);
911 fc_starget_port_name(starget) = port_name;
915 qla2x00_get_starget_port_id(struct scsi_target *starget)
917 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
918 scsi_qla_host_t *ha = shost_priv(host);
920 uint32_t port_id = ~0U;
922 list_for_each_entry(fcport, &ha->fcports, list) {
923 if (starget->id == fcport->os_target_id) {
924 port_id = fcport->d_id.b.domain << 16 |
925 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
930 fc_starget_port_id(starget) = port_id;
934 qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
936 struct Scsi_Host *host = rport_to_shost(rport);
937 scsi_qla_host_t *ha = shost_priv(host);
939 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
943 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
945 struct Scsi_Host *host = rport_to_shost(rport);
946 scsi_qla_host_t *ha = shost_priv(host);
949 ha->port_down_retry_count = timeout;
951 ha->port_down_retry_count = 1;
953 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
957 qla2x00_issue_lip(struct Scsi_Host *shost)
959 scsi_qla_host_t *ha = shost_priv(shost);
961 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
965 static struct fc_host_statistics *
966 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
968 scsi_qla_host_t *ha = shost_priv(shost);
971 link_stat_t stat_buf;
972 struct fc_host_statistics *pfc_host_stat;
974 rval = QLA_FUNCTION_FAILED;
975 pfc_host_stat = &ha->fc_host_stat;
976 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
978 if (IS_FWI2_CAPABLE(ha)) {
979 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
980 sizeof(stat_buf) / 4, mb_stat);
981 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
982 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
983 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
985 /* Must be in a 'READY' state for statistics retrieval. */
986 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
990 if (rval != QLA_SUCCESS)
993 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
994 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
995 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
996 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
997 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
998 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
1000 return pfc_host_stat;
1004 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1006 scsi_qla_host_t *ha = shost_priv(shost);
1008 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
1012 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1014 scsi_qla_host_t *ha = shost_priv(shost);
1016 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
1020 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1022 scsi_qla_host_t *ha = shost_priv(shost);
1025 if (ha->device_flags & SWITCH_FOUND)
1026 node_name = wwn_to_u64(ha->fabric_node_name);
1028 node_name = wwn_to_u64(ha->node_name);
1030 fc_host_fabric_name(shost) = node_name;
1034 qla2x00_get_host_port_state(struct Scsi_Host *shost)
1036 scsi_qla_host_t *ha = shost_priv(shost);
1038 if (!ha->flags.online)
1039 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1040 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
1041 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1043 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1047 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1050 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
1051 scsi_qla_host_t *vha;
1053 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1055 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1056 "status %x\n", ret));
1060 vha = qla24xx_create_vhost(fc_vport);
1062 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1064 return FC_VPORT_FAILED;
1067 atomic_set(&vha->vp_state, VP_OFFLINE);
1068 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1070 atomic_set(&vha->vp_state, VP_FAILED);
1072 /* ready to create vport */
1073 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1075 /* initialized vport states */
1076 atomic_set(&vha->loop_state, LOOP_DOWN);
1077 vha->vp_err_state= VP_ERR_PORTDWN;
1078 vha->vp_prev_err_state= VP_ERR_UNKWN;
1079 /* Check if physical ha port is Up */
1080 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1081 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1082 /* Don't retry or attempt login of this virtual port */
1083 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1085 atomic_set(&vha->loop_state, LOOP_DEAD);
1087 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1090 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1091 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1092 vha->host_no, vha->vp_idx));
1093 goto vport_create_failed_2;
1096 /* initialize attributes */
1097 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1098 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1099 fc_host_supported_classes(vha->host) =
1100 fc_host_supported_classes(ha->host);
1101 fc_host_supported_speeds(vha->host) =
1102 fc_host_supported_speeds(ha->host);
1104 qla24xx_vport_disable(fc_vport, disable);
1107 vport_create_failed_2:
1108 qla24xx_disable_vp(vha);
1109 qla24xx_deallocate_vp_id(vha);
1110 kfree(vha->port_name);
1111 kfree(vha->node_name);
1112 scsi_host_put(vha->host);
1113 return FC_VPORT_FAILED;
1117 qla24xx_vport_delete(struct fc_vport *fc_vport)
1119 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
1120 scsi_qla_host_t *vha = fc_vport->dd_data;
1122 qla24xx_disable_vp(vha);
1123 qla24xx_deallocate_vp_id(vha);
1125 down(&ha->vport_sem);
1126 ha->cur_vport_count--;
1127 clear_bit(vha->vp_idx, ha->vp_idx_map);
1130 kfree(vha->node_name);
1131 kfree(vha->port_name);
1133 if (vha->timer_active) {
1134 qla2x00_vp_stop_timer(vha);
1135 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1137 vha->host_no, vha->vp_idx, vha));
1140 fc_remove_host(vha->host);
1142 scsi_remove_host(vha->host);
1144 scsi_host_put(vha->host);
1150 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1152 scsi_qla_host_t *vha = fc_vport->dd_data;
1155 qla24xx_disable_vp(vha);
1157 qla24xx_enable_vp(vha);
1162 struct fc_function_template qla2xxx_transport_functions = {
1164 .show_host_node_name = 1,
1165 .show_host_port_name = 1,
1166 .show_host_supported_classes = 1,
1168 .get_host_port_id = qla2x00_get_host_port_id,
1169 .show_host_port_id = 1,
1170 .get_host_speed = qla2x00_get_host_speed,
1171 .show_host_speed = 1,
1172 .get_host_port_type = qla2x00_get_host_port_type,
1173 .show_host_port_type = 1,
1174 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1175 .show_host_symbolic_name = 1,
1176 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1177 .show_host_system_hostname = 1,
1178 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1179 .show_host_fabric_name = 1,
1180 .get_host_port_state = qla2x00_get_host_port_state,
1181 .show_host_port_state = 1,
1183 .dd_fcrport_size = sizeof(struct fc_port *),
1184 .show_rport_supported_classes = 1,
1186 .get_starget_node_name = qla2x00_get_starget_node_name,
1187 .show_starget_node_name = 1,
1188 .get_starget_port_name = qla2x00_get_starget_port_name,
1189 .show_starget_port_name = 1,
1190 .get_starget_port_id = qla2x00_get_starget_port_id,
1191 .show_starget_port_id = 1,
1193 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1194 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1195 .show_rport_dev_loss_tmo = 1,
1197 .issue_fc_host_lip = qla2x00_issue_lip,
1198 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1200 .vport_create = qla24xx_vport_create,
1201 .vport_disable = qla24xx_vport_disable,
1202 .vport_delete = qla24xx_vport_delete,
1205 struct fc_function_template qla2xxx_transport_vport_functions = {
1207 .show_host_node_name = 1,
1208 .show_host_port_name = 1,
1209 .show_host_supported_classes = 1,
1211 .get_host_port_id = qla2x00_get_host_port_id,
1212 .show_host_port_id = 1,
1213 .get_host_speed = qla2x00_get_host_speed,
1214 .show_host_speed = 1,
1215 .get_host_port_type = qla2x00_get_host_port_type,
1216 .show_host_port_type = 1,
1217 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1218 .show_host_symbolic_name = 1,
1219 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1220 .show_host_system_hostname = 1,
1221 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1222 .show_host_fabric_name = 1,
1223 .get_host_port_state = qla2x00_get_host_port_state,
1224 .show_host_port_state = 1,
1226 .dd_fcrport_size = sizeof(struct fc_port *),
1227 .show_rport_supported_classes = 1,
1229 .get_starget_node_name = qla2x00_get_starget_node_name,
1230 .show_starget_node_name = 1,
1231 .get_starget_port_name = qla2x00_get_starget_port_name,
1232 .show_starget_port_name = 1,
1233 .get_starget_port_id = qla2x00_get_starget_port_id,
1234 .show_starget_port_id = 1,
1236 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1237 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1238 .show_rport_dev_loss_tmo = 1,
1240 .issue_fc_host_lip = qla2x00_issue_lip,
1241 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1245 qla2x00_init_host_attr(scsi_qla_host_t *ha)
1247 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1248 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
1249 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
1250 fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
1251 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;