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 *ha = shost_priv(dev_to_shost(container_of(kobj,
23 struct device, kobj)));
25 if (ha->fw_dump_reading == 0)
28 return memory_read_from_buffer(buf, count, &off, ha->fw_dump,
33 qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
34 struct bin_attribute *bin_attr,
35 char *buf, loff_t off, size_t count)
37 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
38 struct device, kobj)));
44 reading = simple_strtol(buf, NULL, 10);
47 if (!ha->fw_dump_reading)
50 qla_printk(KERN_INFO, ha,
51 "Firmware dump cleared on (%ld).\n", ha->host_no);
53 ha->fw_dump_reading = 0;
57 if (ha->fw_dumped && !ha->fw_dump_reading) {
58 ha->fw_dump_reading = 1;
60 qla_printk(KERN_INFO, ha,
61 "Raw firmware dump ready for read on (%ld).\n",
66 qla2x00_alloc_fw_dump(ha);
69 qla2x00_system_error(ha);
75 static struct bin_attribute sysfs_fw_dump_attr = {
78 .mode = S_IRUSR | S_IWUSR,
81 .read = qla2x00_sysfs_read_fw_dump,
82 .write = qla2x00_sysfs_write_fw_dump,
86 qla2x00_sysfs_read_nvram(struct kobject *kobj,
87 struct bin_attribute *bin_attr,
88 char *buf, loff_t off, size_t count)
90 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
91 struct device, kobj)));
93 if (!capable(CAP_SYS_ADMIN))
96 /* Read NVRAM data from cache. */
97 return memory_read_from_buffer(buf, count, &off, ha->nvram,
102 qla2x00_sysfs_write_nvram(struct kobject *kobj,
103 struct bin_attribute *bin_attr,
104 char *buf, loff_t off, size_t count)
106 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
107 struct device, kobj)));
110 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
113 /* Checksum NVRAM. */
114 if (IS_FWI2_CAPABLE(ha)) {
118 iter = (uint32_t *)buf;
120 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
121 chksum += le32_to_cpu(*iter++);
122 chksum = ~chksum + 1;
123 *iter = cpu_to_le32(chksum);
128 iter = (uint8_t *)buf;
130 for (cnt = 0; cnt < count - 1; cnt++)
132 chksum = ~chksum + 1;
137 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
138 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->nvram, ha->nvram_base,
141 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
146 static struct bin_attribute sysfs_nvram_attr = {
149 .mode = S_IRUSR | S_IWUSR,
152 .read = qla2x00_sysfs_read_nvram,
153 .write = qla2x00_sysfs_write_nvram,
157 qla2x00_sysfs_read_optrom(struct kobject *kobj,
158 struct bin_attribute *bin_attr,
159 char *buf, loff_t off, size_t count)
161 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
162 struct device, kobj)));
164 if (ha->optrom_state != QLA_SREADING)
167 return memory_read_from_buffer(buf, count, &off, ha->optrom_buffer,
168 ha->optrom_region_size);
172 qla2x00_sysfs_write_optrom(struct kobject *kobj,
173 struct bin_attribute *bin_attr,
174 char *buf, loff_t off, size_t count)
176 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
177 struct device, kobj)));
179 if (ha->optrom_state != QLA_SWRITING)
181 if (off > ha->optrom_region_size)
183 if (off + count > ha->optrom_region_size)
184 count = ha->optrom_region_size - off;
186 memcpy(&ha->optrom_buffer[off], buf, count);
191 static struct bin_attribute sysfs_optrom_attr = {
194 .mode = S_IRUSR | S_IWUSR,
197 .read = qla2x00_sysfs_read_optrom,
198 .write = qla2x00_sysfs_write_optrom,
202 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
203 struct bin_attribute *bin_attr,
204 char *buf, loff_t off, size_t count)
206 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
207 struct device, kobj)));
209 uint32_t size = ha->optrom_size;
215 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
217 if (start > ha->optrom_size)
222 if (ha->optrom_state != QLA_SREADING &&
223 ha->optrom_state != QLA_SWRITING)
226 ha->optrom_state = QLA_SWAITING;
228 DEBUG2(qla_printk(KERN_INFO, ha,
229 "Freeing flash region allocation -- 0x%x bytes.\n",
230 ha->optrom_region_size));
232 vfree(ha->optrom_buffer);
233 ha->optrom_buffer = NULL;
236 if (ha->optrom_state != QLA_SWAITING)
240 qla_printk(KERN_WARNING, ha,
241 "Invalid start region 0x%x/0x%x.\n", start, size);
245 ha->optrom_region_start = start;
246 ha->optrom_region_size = start + size > ha->optrom_size ?
247 ha->optrom_size - start : size;
249 ha->optrom_state = QLA_SREADING;
250 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
251 if (ha->optrom_buffer == NULL) {
252 qla_printk(KERN_WARNING, ha,
253 "Unable to allocate memory for optrom retrieval "
254 "(%x).\n", ha->optrom_region_size);
256 ha->optrom_state = QLA_SWAITING;
260 DEBUG2(qla_printk(KERN_INFO, ha,
261 "Reading flash region -- 0x%x/0x%x.\n",
262 ha->optrom_region_start, ha->optrom_region_size));
264 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
265 ha->isp_ops->read_optrom(ha, ha->optrom_buffer,
266 ha->optrom_region_start, ha->optrom_region_size);
269 if (ha->optrom_state != QLA_SWAITING)
273 * We need to be more restrictive on which FLASH regions are
274 * allowed to be updated via user-space. Regions accessible
275 * via this method include:
277 * ISP21xx/ISP22xx/ISP23xx type boards:
279 * 0x000000 -> 0x020000 -- Boot code.
281 * ISP2322/ISP24xx type boards:
283 * 0x000000 -> 0x07ffff -- Boot code.
284 * 0x080000 -> 0x0fffff -- Firmware.
286 * ISP25xx type boards:
288 * 0x000000 -> 0x07ffff -- Boot code.
289 * 0x080000 -> 0x0fffff -- Firmware.
290 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
293 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
295 else if (start == (ha->flt_region_boot * 4) ||
296 start == (ha->flt_region_fw * 4))
298 else if (IS_QLA25XX(ha) &&
299 start == (ha->flt_region_vpd_nvram * 4))
302 qla_printk(KERN_WARNING, ha,
303 "Invalid start region 0x%x/0x%x.\n", start, size);
307 ha->optrom_region_start = start;
308 ha->optrom_region_size = start + size > ha->optrom_size ?
309 ha->optrom_size - start : size;
311 ha->optrom_state = QLA_SWRITING;
312 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
313 if (ha->optrom_buffer == NULL) {
314 qla_printk(KERN_WARNING, ha,
315 "Unable to allocate memory for optrom update "
316 "(%x).\n", ha->optrom_region_size);
318 ha->optrom_state = QLA_SWAITING;
322 DEBUG2(qla_printk(KERN_INFO, ha,
323 "Staging flash region write -- 0x%x/0x%x.\n",
324 ha->optrom_region_start, ha->optrom_region_size));
326 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
329 if (ha->optrom_state != QLA_SWRITING)
332 DEBUG2(qla_printk(KERN_INFO, ha,
333 "Writing flash region -- 0x%x/0x%x.\n",
334 ha->optrom_region_start, ha->optrom_region_size));
336 ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
337 ha->optrom_region_start, ha->optrom_region_size);
345 static struct bin_attribute sysfs_optrom_ctl_attr = {
347 .name = "optrom_ctl",
351 .write = qla2x00_sysfs_write_optrom_ctl,
355 qla2x00_sysfs_read_vpd(struct kobject *kobj,
356 struct bin_attribute *bin_attr,
357 char *buf, loff_t off, size_t count)
359 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
360 struct device, kobj)));
362 if (!capable(CAP_SYS_ADMIN))
365 /* Read NVRAM data from cache. */
366 return memory_read_from_buffer(buf, count, &off, ha->vpd, ha->vpd_size);
370 qla2x00_sysfs_write_vpd(struct kobject *kobj,
371 struct bin_attribute *bin_attr,
372 char *buf, loff_t off, size_t count)
374 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
375 struct device, kobj)));
377 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
381 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
382 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
387 static struct bin_attribute sysfs_vpd_attr = {
390 .mode = S_IRUSR | S_IWUSR,
393 .read = qla2x00_sysfs_read_vpd,
394 .write = qla2x00_sysfs_write_vpd,
398 qla2x00_sysfs_read_sfp(struct kobject *kobj,
399 struct bin_attribute *bin_attr,
400 char *buf, loff_t off, size_t count)
402 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
403 struct device, kobj)));
404 uint16_t iter, addr, offset;
407 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
413 ha->sfp_data = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
416 qla_printk(KERN_WARNING, ha,
417 "Unable to allocate memory for SFP read-data.\n");
422 memset(ha->sfp_data, 0, SFP_BLOCK_SIZE);
424 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
425 iter++, offset += SFP_BLOCK_SIZE) {
427 /* Skip to next device address. */
432 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
434 if (rval != QLA_SUCCESS) {
435 qla_printk(KERN_WARNING, ha,
436 "Unable to read SFP data (%x/%x/%x).\n", rval,
441 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
442 buf += SFP_BLOCK_SIZE;
448 static struct bin_attribute sysfs_sfp_attr = {
451 .mode = S_IRUSR | S_IWUSR,
453 .size = SFP_DEV_SIZE * 2,
454 .read = qla2x00_sysfs_read_sfp,
457 static struct sysfs_entry {
459 struct bin_attribute *attr;
461 } bin_file_entries[] = {
462 { "fw_dump", &sysfs_fw_dump_attr, },
463 { "nvram", &sysfs_nvram_attr, },
464 { "optrom", &sysfs_optrom_attr, },
465 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
466 { "vpd", &sysfs_vpd_attr, 1 },
467 { "sfp", &sysfs_sfp_attr, 1 },
472 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
474 struct Scsi_Host *host = ha->host;
475 struct sysfs_entry *iter;
478 for (iter = bin_file_entries; iter->name; iter++) {
479 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
482 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
485 qla_printk(KERN_INFO, ha,
486 "Unable to create sysfs %s binary attribute "
487 "(%d).\n", iter->name, ret);
492 qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
494 struct Scsi_Host *host = ha->host;
495 struct sysfs_entry *iter;
497 for (iter = bin_file_entries; iter->name; iter++) {
498 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
501 sysfs_remove_bin_file(&host->shost_gendev.kobj,
505 if (ha->beacon_blink_led == 1)
506 ha->isp_ops->beacon_off(ha);
509 /* Scsi_Host attributes. */
512 qla2x00_drvr_version_show(struct device *dev,
513 struct device_attribute *attr, char *buf)
515 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
519 qla2x00_fw_version_show(struct device *dev,
520 struct device_attribute *attr, char *buf)
522 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
525 return snprintf(buf, PAGE_SIZE, "%s\n",
526 ha->isp_ops->fw_version_str(ha, fw_str));
530 qla2x00_serial_num_show(struct device *dev, struct device_attribute *attr,
533 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
536 if (IS_FWI2_CAPABLE(ha)) {
537 qla2xxx_get_vpd_field(ha, "SN", buf, PAGE_SIZE);
538 return snprintf(buf, PAGE_SIZE, "%s\n", buf);
541 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
542 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
547 qla2x00_isp_name_show(struct device *dev, struct device_attribute *attr,
550 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
551 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
555 qla2x00_isp_id_show(struct device *dev, struct device_attribute *attr,
558 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
559 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
560 ha->product_id[0], ha->product_id[1], ha->product_id[2],
565 qla2x00_model_name_show(struct device *dev, struct device_attribute *attr,
568 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
569 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
573 qla2x00_model_desc_show(struct device *dev, struct device_attribute *attr,
576 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
577 return snprintf(buf, PAGE_SIZE, "%s\n",
578 ha->model_desc ? ha->model_desc: "");
582 qla2x00_pci_info_show(struct device *dev, struct device_attribute *attr,
585 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
588 return snprintf(buf, PAGE_SIZE, "%s\n",
589 ha->isp_ops->pci_info_str(ha, pci_info));
593 qla2x00_link_state_show(struct device *dev, struct device_attribute *attr,
596 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
599 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
600 atomic_read(&ha->loop_state) == LOOP_DEAD)
601 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
602 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
603 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
604 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
605 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
607 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
609 switch (ha->current_topology) {
611 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
614 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
617 len += snprintf(buf + len, PAGE_SIZE-len,
618 "N_Port to N_Port\n");
621 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
624 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
632 qla2x00_zio_show(struct device *dev, struct device_attribute *attr,
635 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
638 switch (ha->zio_mode) {
640 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
642 case QLA_ZIO_DISABLED:
643 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
650 qla2x00_zio_store(struct device *dev, struct device_attribute *attr,
651 const char *buf, size_t count)
653 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
657 if (!IS_ZIO_SUPPORTED(ha))
660 if (sscanf(buf, "%d", &val) != 1)
664 zio_mode = QLA_ZIO_MODE_6;
666 zio_mode = QLA_ZIO_DISABLED;
668 /* Update per-hba values and queue a reset. */
669 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
670 ha->zio_mode = zio_mode;
671 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
677 qla2x00_zio_timer_show(struct device *dev, struct device_attribute *attr,
680 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
682 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
686 qla2x00_zio_timer_store(struct device *dev, struct device_attribute *attr,
687 const char *buf, size_t count)
689 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
693 if (sscanf(buf, "%d", &val) != 1)
695 if (val > 25500 || val < 100)
698 zio_timer = (uint16_t)(val / 100);
699 ha->zio_timer = zio_timer;
705 qla2x00_beacon_show(struct device *dev, struct device_attribute *attr,
708 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
711 if (ha->beacon_blink_led)
712 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
714 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
719 qla2x00_beacon_store(struct device *dev, struct device_attribute *attr,
720 const char *buf, size_t count)
722 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
726 if (IS_QLA2100(ha) || IS_QLA2200(ha))
729 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
730 qla_printk(KERN_WARNING, ha,
731 "Abort ISP active -- ignoring beacon request.\n");
735 if (sscanf(buf, "%d", &val) != 1)
739 rval = ha->isp_ops->beacon_on(ha);
741 rval = ha->isp_ops->beacon_off(ha);
743 if (rval != QLA_SUCCESS)
750 qla2x00_optrom_bios_version_show(struct device *dev,
751 struct device_attribute *attr, char *buf)
753 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
755 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
756 ha->bios_revision[0]);
760 qla2x00_optrom_efi_version_show(struct device *dev,
761 struct device_attribute *attr, char *buf)
763 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
765 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
766 ha->efi_revision[0]);
770 qla2x00_optrom_fcode_version_show(struct device *dev,
771 struct device_attribute *attr, char *buf)
773 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
775 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
776 ha->fcode_revision[0]);
780 qla2x00_optrom_fw_version_show(struct device *dev,
781 struct device_attribute *attr, char *buf)
783 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
785 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
786 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
791 qla2x00_total_isp_aborts_show(struct device *dev,
792 struct device_attribute *attr, char *buf)
794 scsi_qla_host_t *ha = shost_priv(class_to_shost(dev));
796 return snprintf(buf, PAGE_SIZE, "%d\n",
797 ha->qla_stats.total_isp_aborts);
800 static DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show, NULL);
801 static DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
802 static DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
803 static DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
804 static DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
805 static DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
806 static DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
807 static DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
808 static DEVICE_ATTR(link_state, S_IRUGO, qla2x00_link_state_show, NULL);
809 static DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show, qla2x00_zio_store);
810 static DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
811 qla2x00_zio_timer_store);
812 static DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
813 qla2x00_beacon_store);
814 static DEVICE_ATTR(optrom_bios_version, S_IRUGO,
815 qla2x00_optrom_bios_version_show, NULL);
816 static DEVICE_ATTR(optrom_efi_version, S_IRUGO,
817 qla2x00_optrom_efi_version_show, NULL);
818 static DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
819 qla2x00_optrom_fcode_version_show, NULL);
820 static DEVICE_ATTR(optrom_fw_version, S_IRUGO, qla2x00_optrom_fw_version_show,
822 static DEVICE_ATTR(total_isp_aborts, S_IRUGO, qla2x00_total_isp_aborts_show,
825 struct device_attribute *qla2x00_host_attrs[] = {
826 &dev_attr_driver_version,
827 &dev_attr_fw_version,
828 &dev_attr_serial_num,
831 &dev_attr_model_name,
832 &dev_attr_model_desc,
834 &dev_attr_link_state,
838 &dev_attr_optrom_bios_version,
839 &dev_attr_optrom_efi_version,
840 &dev_attr_optrom_fcode_version,
841 &dev_attr_optrom_fw_version,
842 &dev_attr_total_isp_aborts,
846 /* Host attributes. */
849 qla2x00_get_host_port_id(struct Scsi_Host *shost)
851 scsi_qla_host_t *ha = shost_priv(shost);
853 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
854 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
858 qla2x00_get_host_speed(struct Scsi_Host *shost)
860 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
861 u32 speed = FC_PORTSPEED_UNKNOWN;
863 switch (ha->link_data_rate) {
865 speed = FC_PORTSPEED_1GBIT;
868 speed = FC_PORTSPEED_2GBIT;
871 speed = FC_PORTSPEED_4GBIT;
874 speed = FC_PORTSPEED_8GBIT;
877 fc_host_speed(shost) = speed;
881 qla2x00_get_host_port_type(struct Scsi_Host *shost)
883 scsi_qla_host_t *ha = shost_priv(shost);
884 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
887 fc_host_port_type(shost) = FC_PORTTYPE_NPIV;
890 switch (ha->current_topology) {
892 port_type = FC_PORTTYPE_LPORT;
895 port_type = FC_PORTTYPE_NLPORT;
898 port_type = FC_PORTTYPE_PTP;
901 port_type = FC_PORTTYPE_NPORT;
904 fc_host_port_type(shost) = port_type;
908 qla2x00_get_starget_node_name(struct scsi_target *starget)
910 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
911 scsi_qla_host_t *ha = shost_priv(host);
915 list_for_each_entry(fcport, &ha->fcports, list) {
917 starget->id == fcport->rport->scsi_target_id) {
918 node_name = wwn_to_u64(fcport->node_name);
923 fc_starget_node_name(starget) = node_name;
927 qla2x00_get_starget_port_name(struct scsi_target *starget)
929 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
930 scsi_qla_host_t *ha = shost_priv(host);
934 list_for_each_entry(fcport, &ha->fcports, list) {
936 starget->id == fcport->rport->scsi_target_id) {
937 port_name = wwn_to_u64(fcport->port_name);
942 fc_starget_port_name(starget) = port_name;
946 qla2x00_get_starget_port_id(struct scsi_target *starget)
948 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
949 scsi_qla_host_t *ha = shost_priv(host);
951 uint32_t port_id = ~0U;
953 list_for_each_entry(fcport, &ha->fcports, list) {
955 starget->id == fcport->rport->scsi_target_id) {
956 port_id = fcport->d_id.b.domain << 16 |
957 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
962 fc_starget_port_id(starget) = port_id;
966 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
969 rport->dev_loss_tmo = timeout;
971 rport->dev_loss_tmo = 1;
975 qla2x00_dev_loss_tmo_callbk(struct fc_rport *rport)
977 struct Scsi_Host *host = rport_to_shost(rport);
978 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
980 qla2x00_abort_fcport_cmds(fcport);
983 * Transport has effectively 'deleted' the rport, clear
984 * all local references.
986 spin_lock_irq(host->host_lock);
987 fcport->rport = NULL;
988 *((fc_port_t **)rport->dd_data) = NULL;
989 spin_unlock_irq(host->host_lock);
993 qla2x00_terminate_rport_io(struct fc_rport *rport)
995 fc_port_t *fcport = *(fc_port_t **)rport->dd_data;
998 * At this point all fcport's software-states are cleared. Perform any
999 * final cleanup of firmware resources (PCBs and XCBs).
1001 if (fcport->loop_id != FC_NO_LOOP_ID) {
1002 fcport->ha->isp_ops->fabric_logout(fcport->ha, fcport->loop_id,
1003 fcport->d_id.b.domain, fcport->d_id.b.area,
1004 fcport->d_id.b.al_pa);
1005 fcport->loop_id = FC_NO_LOOP_ID;
1008 qla2x00_abort_fcport_cmds(fcport);
1012 qla2x00_issue_lip(struct Scsi_Host *shost)
1014 scsi_qla_host_t *ha = shost_priv(shost);
1016 qla2x00_loop_reset(ha);
1020 static struct fc_host_statistics *
1021 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
1023 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
1025 struct link_statistics *stats;
1026 dma_addr_t stats_dma;
1027 struct fc_host_statistics *pfc_host_stat;
1029 pfc_host_stat = &ha->fc_host_stat;
1030 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
1032 stats = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &stats_dma);
1033 if (stats == NULL) {
1034 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1035 __func__, ha->host_no));
1038 memset(stats, 0, DMA_POOL_SIZE);
1040 rval = QLA_FUNCTION_FAILED;
1041 if (IS_FWI2_CAPABLE(ha)) {
1042 rval = qla24xx_get_isp_stats(ha, stats, stats_dma);
1043 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
1044 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
1045 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
1047 /* Must be in a 'READY' state for statistics retrieval. */
1048 rval = qla2x00_get_link_status(ha, ha->loop_id, stats,
1052 if (rval != QLA_SUCCESS)
1055 pfc_host_stat->link_failure_count = stats->link_fail_cnt;
1056 pfc_host_stat->loss_of_sync_count = stats->loss_sync_cnt;
1057 pfc_host_stat->loss_of_signal_count = stats->loss_sig_cnt;
1058 pfc_host_stat->prim_seq_protocol_err_count = stats->prim_seq_err_cnt;
1059 pfc_host_stat->invalid_tx_word_count = stats->inval_xmit_word_cnt;
1060 pfc_host_stat->invalid_crc_count = stats->inval_crc_cnt;
1061 if (IS_FWI2_CAPABLE(ha)) {
1062 pfc_host_stat->lip_count = stats->lip_cnt;
1063 pfc_host_stat->tx_frames = stats->tx_frames;
1064 pfc_host_stat->rx_frames = stats->rx_frames;
1065 pfc_host_stat->dumped_frames = stats->dumped_frames;
1066 pfc_host_stat->nos_count = stats->nos_rcvd;
1068 pfc_host_stat->fcp_input_megabytes = ha->qla_stats.input_bytes >> 20;
1069 pfc_host_stat->fcp_output_megabytes = ha->qla_stats.output_bytes >> 20;
1072 dma_pool_free(ha->s_dma_pool, stats, stats_dma);
1074 return pfc_host_stat;
1078 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1080 scsi_qla_host_t *ha = shost_priv(shost);
1082 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
1086 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1088 scsi_qla_host_t *ha = shost_priv(shost);
1090 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
1094 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1096 scsi_qla_host_t *ha = shost_priv(shost);
1099 if (ha->device_flags & SWITCH_FOUND)
1100 node_name = wwn_to_u64(ha->fabric_node_name);
1102 node_name = wwn_to_u64(ha->node_name);
1104 fc_host_fabric_name(shost) = node_name;
1108 qla2x00_get_host_port_state(struct Scsi_Host *shost)
1110 scsi_qla_host_t *ha = to_qla_parent(shost_priv(shost));
1112 if (!ha->flags.online)
1113 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1114 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
1115 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1117 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1121 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1124 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
1125 scsi_qla_host_t *vha;
1127 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1129 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1130 "status %x\n", ret));
1134 vha = qla24xx_create_vhost(fc_vport);
1136 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1138 return FC_VPORT_FAILED;
1141 atomic_set(&vha->vp_state, VP_OFFLINE);
1142 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1144 atomic_set(&vha->vp_state, VP_FAILED);
1146 /* ready to create vport */
1147 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1149 /* initialized vport states */
1150 atomic_set(&vha->loop_state, LOOP_DOWN);
1151 vha->vp_err_state= VP_ERR_PORTDWN;
1152 vha->vp_prev_err_state= VP_ERR_UNKWN;
1153 /* Check if physical ha port is Up */
1154 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1155 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1156 /* Don't retry or attempt login of this virtual port */
1157 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1159 atomic_set(&vha->loop_state, LOOP_DEAD);
1161 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1164 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1165 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1166 vha->host_no, vha->vp_idx));
1167 goto vport_create_failed_2;
1170 /* initialize attributes */
1171 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1172 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1173 fc_host_supported_classes(vha->host) =
1174 fc_host_supported_classes(ha->host);
1175 fc_host_supported_speeds(vha->host) =
1176 fc_host_supported_speeds(ha->host);
1178 qla24xx_vport_disable(fc_vport, disable);
1181 vport_create_failed_2:
1182 qla24xx_disable_vp(vha);
1183 qla24xx_deallocate_vp_id(vha);
1184 kfree(vha->port_name);
1185 kfree(vha->node_name);
1186 scsi_host_put(vha->host);
1187 return FC_VPORT_FAILED;
1191 qla24xx_vport_delete(struct fc_vport *fc_vport)
1193 scsi_qla_host_t *vha = fc_vport->dd_data;
1194 scsi_qla_host_t *pha = to_qla_parent(vha);
1196 while (test_bit(LOOP_RESYNC_ACTIVE, &vha->dpc_flags) ||
1197 test_bit(FCPORT_UPDATE_NEEDED, &pha->dpc_flags))
1200 qla24xx_disable_vp(vha);
1201 qla24xx_deallocate_vp_id(vha);
1203 kfree(vha->node_name);
1204 kfree(vha->port_name);
1206 if (vha->timer_active) {
1207 qla2x00_vp_stop_timer(vha);
1208 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1210 vha->host_no, vha->vp_idx, vha));
1213 fc_remove_host(vha->host);
1215 scsi_remove_host(vha->host);
1217 scsi_host_put(vha->host);
1223 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1225 scsi_qla_host_t *vha = fc_vport->dd_data;
1228 qla24xx_disable_vp(vha);
1230 qla24xx_enable_vp(vha);
1235 struct fc_function_template qla2xxx_transport_functions = {
1237 .show_host_node_name = 1,
1238 .show_host_port_name = 1,
1239 .show_host_supported_classes = 1,
1240 .show_host_supported_speeds = 1,
1242 .get_host_port_id = qla2x00_get_host_port_id,
1243 .show_host_port_id = 1,
1244 .get_host_speed = qla2x00_get_host_speed,
1245 .show_host_speed = 1,
1246 .get_host_port_type = qla2x00_get_host_port_type,
1247 .show_host_port_type = 1,
1248 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1249 .show_host_symbolic_name = 1,
1250 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1251 .show_host_system_hostname = 1,
1252 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1253 .show_host_fabric_name = 1,
1254 .get_host_port_state = qla2x00_get_host_port_state,
1255 .show_host_port_state = 1,
1257 .dd_fcrport_size = sizeof(struct fc_port *),
1258 .show_rport_supported_classes = 1,
1260 .get_starget_node_name = qla2x00_get_starget_node_name,
1261 .show_starget_node_name = 1,
1262 .get_starget_port_name = qla2x00_get_starget_port_name,
1263 .show_starget_port_name = 1,
1264 .get_starget_port_id = qla2x00_get_starget_port_id,
1265 .show_starget_port_id = 1,
1267 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1268 .show_rport_dev_loss_tmo = 1,
1270 .issue_fc_host_lip = qla2x00_issue_lip,
1271 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1272 .terminate_rport_io = qla2x00_terminate_rport_io,
1273 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1275 .vport_create = qla24xx_vport_create,
1276 .vport_disable = qla24xx_vport_disable,
1277 .vport_delete = qla24xx_vport_delete,
1280 struct fc_function_template qla2xxx_transport_vport_functions = {
1282 .show_host_node_name = 1,
1283 .show_host_port_name = 1,
1284 .show_host_supported_classes = 1,
1286 .get_host_port_id = qla2x00_get_host_port_id,
1287 .show_host_port_id = 1,
1288 .get_host_speed = qla2x00_get_host_speed,
1289 .show_host_speed = 1,
1290 .get_host_port_type = qla2x00_get_host_port_type,
1291 .show_host_port_type = 1,
1292 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1293 .show_host_symbolic_name = 1,
1294 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1295 .show_host_system_hostname = 1,
1296 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1297 .show_host_fabric_name = 1,
1298 .get_host_port_state = qla2x00_get_host_port_state,
1299 .show_host_port_state = 1,
1301 .dd_fcrport_size = sizeof(struct fc_port *),
1302 .show_rport_supported_classes = 1,
1304 .get_starget_node_name = qla2x00_get_starget_node_name,
1305 .show_starget_node_name = 1,
1306 .get_starget_port_name = qla2x00_get_starget_port_name,
1307 .show_starget_port_name = 1,
1308 .get_starget_port_id = qla2x00_get_starget_port_id,
1309 .show_starget_port_id = 1,
1311 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1312 .show_rport_dev_loss_tmo = 1,
1314 .issue_fc_host_lip = qla2x00_issue_lip,
1315 .dev_loss_tmo_callbk = qla2x00_dev_loss_tmo_callbk,
1316 .terminate_rport_io = qla2x00_terminate_rport_io,
1317 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1321 qla2x00_init_host_attr(scsi_qla_host_t *ha)
1323 u32 speed = FC_PORTSPEED_UNKNOWN;
1325 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1326 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
1327 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
1328 fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
1329 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;
1332 speed = FC_PORTSPEED_8GBIT | FC_PORTSPEED_4GBIT |
1333 FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1334 else if (IS_QLA24XX_TYPE(ha))
1335 speed = FC_PORTSPEED_4GBIT | FC_PORTSPEED_2GBIT |
1337 else if (IS_QLA23XX(ha))
1338 speed = FC_PORTSPEED_2GBIT | FC_PORTSPEED_1GBIT;
1340 speed = FC_PORTSPEED_1GBIT;
1341 fc_host_supported_speeds(ha->host) = speed;