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/vmalloc.h>
11 /* SYSFS attributes --------------------------------------------------------- */
14 qla2x00_sysfs_read_fw_dump(struct kobject *kobj,
15 struct bin_attribute *bin_attr,
16 char *buf, loff_t off, size_t count)
18 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
19 struct device, kobj)));
20 char *rbuf = (char *)ha->fw_dump;
22 if (ha->fw_dump_reading == 0)
24 if (off > ha->fw_dump_len)
26 if (off + count > ha->fw_dump_len)
27 count = ha->fw_dump_len - off;
29 memcpy(buf, &rbuf[off], count);
35 qla2x00_sysfs_write_fw_dump(struct kobject *kobj,
36 struct bin_attribute *bin_attr,
37 char *buf, loff_t off, size_t count)
39 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
40 struct device, kobj)));
46 reading = simple_strtol(buf, NULL, 10);
49 if (!ha->fw_dump_reading)
52 qla_printk(KERN_INFO, ha,
53 "Firmware dump cleared on (%ld).\n", ha->host_no);
55 ha->fw_dump_reading = 0;
59 if (ha->fw_dumped && !ha->fw_dump_reading) {
60 ha->fw_dump_reading = 1;
62 qla_printk(KERN_INFO, ha,
63 "Raw firmware dump ready for read on (%ld).\n",
68 qla2x00_alloc_fw_dump(ha);
74 static struct bin_attribute sysfs_fw_dump_attr = {
77 .mode = S_IRUSR | S_IWUSR,
80 .read = qla2x00_sysfs_read_fw_dump,
81 .write = qla2x00_sysfs_write_fw_dump,
85 qla2x00_sysfs_read_nvram(struct kobject *kobj,
86 struct bin_attribute *bin_attr,
87 char *buf, loff_t off, size_t count)
89 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
90 struct device, kobj)));
93 if (!capable(CAP_SYS_ADMIN) || off != 0)
97 spin_lock_irqsave(&ha->hardware_lock, flags);
98 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
100 spin_unlock_irqrestore(&ha->hardware_lock, flags);
102 return ha->nvram_size;
106 qla2x00_sysfs_write_nvram(struct kobject *kobj,
107 struct bin_attribute *bin_attr,
108 char *buf, loff_t off, size_t count)
110 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
111 struct device, kobj)));
115 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
118 /* Checksum NVRAM. */
119 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
123 iter = (uint32_t *)buf;
125 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
126 chksum += le32_to_cpu(*iter++);
127 chksum = ~chksum + 1;
128 *iter = cpu_to_le32(chksum);
133 iter = (uint8_t *)buf;
135 for (cnt = 0; cnt < count - 1; cnt++)
137 chksum = ~chksum + 1;
142 spin_lock_irqsave(&ha->hardware_lock, flags);
143 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
144 spin_unlock_irqrestore(&ha->hardware_lock, flags);
146 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
151 static struct bin_attribute sysfs_nvram_attr = {
154 .mode = S_IRUSR | S_IWUSR,
157 .read = qla2x00_sysfs_read_nvram,
158 .write = qla2x00_sysfs_write_nvram,
162 qla2x00_sysfs_read_optrom(struct kobject *kobj,
163 struct bin_attribute *bin_attr,
164 char *buf, loff_t off, size_t count)
166 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
167 struct device, kobj)));
169 if (ha->optrom_state != QLA_SREADING)
171 if (off > ha->optrom_size)
173 if (off + count > ha->optrom_size)
174 count = ha->optrom_size - off;
176 memcpy(buf, &ha->optrom_buffer[off], count);
182 qla2x00_sysfs_write_optrom(struct kobject *kobj,
183 struct bin_attribute *bin_attr,
184 char *buf, loff_t off, size_t count)
186 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
187 struct device, kobj)));
189 if (ha->optrom_state != QLA_SWRITING)
191 if (off > ha->optrom_size)
193 if (off + count > ha->optrom_size)
194 count = ha->optrom_size - off;
196 memcpy(&ha->optrom_buffer[off], buf, count);
201 static struct bin_attribute sysfs_optrom_attr = {
204 .mode = S_IRUSR | S_IWUSR,
206 .size = OPTROM_SIZE_24XX,
207 .read = qla2x00_sysfs_read_optrom,
208 .write = qla2x00_sysfs_write_optrom,
212 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
213 struct bin_attribute *bin_attr,
214 char *buf, loff_t off, size_t count)
216 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
217 struct device, kobj)));
223 if (sscanf(buf, "%d", &val) != 1)
228 if (ha->optrom_state != QLA_SREADING &&
229 ha->optrom_state != QLA_SWRITING)
232 ha->optrom_state = QLA_SWAITING;
233 vfree(ha->optrom_buffer);
234 ha->optrom_buffer = NULL;
237 if (ha->optrom_state != QLA_SWAITING)
240 ha->optrom_state = QLA_SREADING;
241 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
242 if (ha->optrom_buffer == NULL) {
243 qla_printk(KERN_WARNING, ha,
244 "Unable to allocate memory for optrom retrieval "
245 "(%x).\n", ha->optrom_size);
247 ha->optrom_state = QLA_SWAITING;
251 memset(ha->optrom_buffer, 0, ha->optrom_size);
252 ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0,
256 if (ha->optrom_state != QLA_SWAITING)
259 ha->optrom_state = QLA_SWRITING;
260 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
261 if (ha->optrom_buffer == NULL) {
262 qla_printk(KERN_WARNING, ha,
263 "Unable to allocate memory for optrom update "
264 "(%x).\n", ha->optrom_size);
266 ha->optrom_state = QLA_SWAITING;
269 memset(ha->optrom_buffer, 0, ha->optrom_size);
272 if (ha->optrom_state != QLA_SWRITING)
275 ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0,
282 static struct bin_attribute sysfs_optrom_ctl_attr = {
284 .name = "optrom_ctl",
288 .write = qla2x00_sysfs_write_optrom_ctl,
292 qla2x00_sysfs_read_vpd(struct kobject *kobj,
293 struct bin_attribute *bin_attr,
294 char *buf, loff_t off, size_t count)
296 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
297 struct device, kobj)));
300 if (!capable(CAP_SYS_ADMIN) || off != 0)
304 spin_lock_irqsave(&ha->hardware_lock, flags);
305 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size);
306 spin_unlock_irqrestore(&ha->hardware_lock, flags);
312 qla2x00_sysfs_write_vpd(struct kobject *kobj,
313 struct bin_attribute *bin_attr,
314 char *buf, loff_t off, size_t count)
316 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
317 struct device, kobj)));
320 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
324 spin_lock_irqsave(&ha->hardware_lock, flags);
325 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
326 spin_unlock_irqrestore(&ha->hardware_lock, flags);
331 static struct bin_attribute sysfs_vpd_attr = {
334 .mode = S_IRUSR | S_IWUSR,
337 .read = qla2x00_sysfs_read_vpd,
338 .write = qla2x00_sysfs_write_vpd,
342 qla2x00_sysfs_read_sfp(struct kobject *kobj,
343 struct bin_attribute *bin_attr,
344 char *buf, loff_t off, size_t count)
346 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
347 struct device, kobj)));
348 uint16_t iter, addr, offset;
351 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
355 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
356 iter++, offset += SFP_BLOCK_SIZE) {
358 /* Skip to next device address. */
363 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
365 if (rval != QLA_SUCCESS) {
366 qla_printk(KERN_WARNING, ha,
367 "Unable to read SFP data (%x/%x/%x).\n", rval,
372 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
373 buf += SFP_BLOCK_SIZE;
379 static struct bin_attribute sysfs_sfp_attr = {
382 .mode = S_IRUSR | S_IWUSR,
384 .size = SFP_DEV_SIZE * 2,
385 .read = qla2x00_sysfs_read_sfp,
388 static struct sysfs_entry {
390 struct bin_attribute *attr;
392 } bin_file_entries[] = {
393 { "fw_dump", &sysfs_fw_dump_attr, },
394 { "nvram", &sysfs_nvram_attr, },
395 { "optrom", &sysfs_optrom_attr, },
396 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
397 { "vpd", &sysfs_vpd_attr, 1 },
398 { "sfp", &sysfs_sfp_attr, 1 },
403 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
405 struct Scsi_Host *host = ha->host;
406 struct sysfs_entry *iter;
409 for (iter = bin_file_entries; iter->name; iter++) {
410 if (iter->is4GBp_only && (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)))
413 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
416 qla_printk(KERN_INFO, ha,
417 "Unable to create sysfs %s binary attribute "
418 "(%d).\n", iter->name, ret);
423 qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
425 struct Scsi_Host *host = ha->host;
426 struct sysfs_entry *iter;
428 for (iter = bin_file_entries; iter->name; iter++) {
429 if (iter->is4GBp_only && (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)))
432 sysfs_remove_bin_file(&host->shost_gendev.kobj,
436 if (ha->beacon_blink_led == 1)
437 ha->isp_ops.beacon_off(ha);
440 /* Scsi_Host attributes. */
443 qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
445 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
449 qla2x00_fw_version_show(struct class_device *cdev, char *buf)
451 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
454 return snprintf(buf, PAGE_SIZE, "%s\n",
455 ha->isp_ops.fw_version_str(ha, fw_str));
459 qla2x00_serial_num_show(struct class_device *cdev, char *buf)
461 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
464 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
465 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
470 qla2x00_isp_name_show(struct class_device *cdev, char *buf)
472 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
473 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
477 qla2x00_isp_id_show(struct class_device *cdev, char *buf)
479 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
480 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
481 ha->product_id[0], ha->product_id[1], ha->product_id[2],
486 qla2x00_model_name_show(struct class_device *cdev, char *buf)
488 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
489 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
493 qla2x00_model_desc_show(struct class_device *cdev, char *buf)
495 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
496 return snprintf(buf, PAGE_SIZE, "%s\n",
497 ha->model_desc ? ha->model_desc: "");
501 qla2x00_pci_info_show(struct class_device *cdev, char *buf)
503 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
506 return snprintf(buf, PAGE_SIZE, "%s\n",
507 ha->isp_ops.pci_info_str(ha, pci_info));
511 qla2x00_state_show(struct class_device *cdev, char *buf)
513 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
516 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
517 atomic_read(&ha->loop_state) == LOOP_DEAD)
518 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
519 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
520 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
521 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
522 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
524 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
526 switch (ha->current_topology) {
528 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
531 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
534 len += snprintf(buf + len, PAGE_SIZE-len,
535 "N_Port to N_Port\n");
538 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
541 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
549 qla2x00_zio_show(struct class_device *cdev, char *buf)
551 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
554 switch (ha->zio_mode) {
556 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
558 case QLA_ZIO_DISABLED:
559 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
566 qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
568 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
572 if (!IS_ZIO_SUPPORTED(ha))
575 if (sscanf(buf, "%d", &val) != 1)
579 zio_mode = QLA_ZIO_MODE_6;
581 zio_mode = QLA_ZIO_DISABLED;
583 /* Update per-hba values and queue a reset. */
584 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
585 ha->zio_mode = zio_mode;
586 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
592 qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
594 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
596 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
600 qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
603 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
607 if (sscanf(buf, "%d", &val) != 1)
609 if (val > 25500 || val < 100)
612 zio_timer = (uint16_t)(val / 100);
613 ha->zio_timer = zio_timer;
619 qla2x00_beacon_show(struct class_device *cdev, char *buf)
621 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
624 if (ha->beacon_blink_led)
625 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
627 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
632 qla2x00_beacon_store(struct class_device *cdev, const char *buf,
635 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
639 if (IS_QLA2100(ha) || IS_QLA2200(ha))
642 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
643 qla_printk(KERN_WARNING, ha,
644 "Abort ISP active -- ignoring beacon request.\n");
648 if (sscanf(buf, "%d", &val) != 1)
652 rval = ha->isp_ops.beacon_on(ha);
654 rval = ha->isp_ops.beacon_off(ha);
656 if (rval != QLA_SUCCESS)
663 qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
665 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
667 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
668 ha->bios_revision[0]);
672 qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
674 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
676 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
677 ha->efi_revision[0]);
681 qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
683 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
685 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
686 ha->fcode_revision[0]);
690 qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
692 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
694 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
695 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
699 static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
701 static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
702 static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
703 static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
704 static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
705 static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
706 static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
707 static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
708 static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
709 static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
711 static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
712 qla2x00_zio_timer_store);
713 static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
714 qla2x00_beacon_store);
715 static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
716 qla2x00_optrom_bios_version_show, NULL);
717 static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
718 qla2x00_optrom_efi_version_show, NULL);
719 static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
720 qla2x00_optrom_fcode_version_show, NULL);
721 static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
722 qla2x00_optrom_fw_version_show, NULL);
724 struct class_device_attribute *qla2x00_host_attrs[] = {
725 &class_device_attr_driver_version,
726 &class_device_attr_fw_version,
727 &class_device_attr_serial_num,
728 &class_device_attr_isp_name,
729 &class_device_attr_isp_id,
730 &class_device_attr_model_name,
731 &class_device_attr_model_desc,
732 &class_device_attr_pci_info,
733 &class_device_attr_state,
734 &class_device_attr_zio,
735 &class_device_attr_zio_timer,
736 &class_device_attr_beacon,
737 &class_device_attr_optrom_bios_version,
738 &class_device_attr_optrom_efi_version,
739 &class_device_attr_optrom_fcode_version,
740 &class_device_attr_optrom_fw_version,
744 /* Host attributes. */
747 qla2x00_get_host_port_id(struct Scsi_Host *shost)
749 scsi_qla_host_t *ha = to_qla_host(shost);
751 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
752 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
756 qla2x00_get_host_speed(struct Scsi_Host *shost)
758 scsi_qla_host_t *ha = to_qla_host(shost);
761 switch (ha->link_data_rate) {
772 fc_host_speed(shost) = speed;
776 qla2x00_get_host_port_type(struct Scsi_Host *shost)
778 scsi_qla_host_t *ha = to_qla_host(shost);
779 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
781 switch (ha->current_topology) {
783 port_type = FC_PORTTYPE_LPORT;
786 port_type = FC_PORTTYPE_NLPORT;
789 port_type = FC_PORTTYPE_PTP;
792 port_type = FC_PORTTYPE_NPORT;
795 fc_host_port_type(shost) = port_type;
799 qla2x00_get_starget_node_name(struct scsi_target *starget)
801 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
802 scsi_qla_host_t *ha = to_qla_host(host);
806 list_for_each_entry(fcport, &ha->fcports, list) {
807 if (starget->id == fcport->os_target_id) {
808 node_name = wwn_to_u64(fcport->node_name);
813 fc_starget_node_name(starget) = node_name;
817 qla2x00_get_starget_port_name(struct scsi_target *starget)
819 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
820 scsi_qla_host_t *ha = to_qla_host(host);
824 list_for_each_entry(fcport, &ha->fcports, list) {
825 if (starget->id == fcport->os_target_id) {
826 port_name = wwn_to_u64(fcport->port_name);
831 fc_starget_port_name(starget) = port_name;
835 qla2x00_get_starget_port_id(struct scsi_target *starget)
837 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
838 scsi_qla_host_t *ha = to_qla_host(host);
840 uint32_t port_id = ~0U;
842 list_for_each_entry(fcport, &ha->fcports, list) {
843 if (starget->id == fcport->os_target_id) {
844 port_id = fcport->d_id.b.domain << 16 |
845 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
850 fc_starget_port_id(starget) = port_id;
854 qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
856 struct Scsi_Host *host = rport_to_shost(rport);
857 scsi_qla_host_t *ha = to_qla_host(host);
859 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
863 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
865 struct Scsi_Host *host = rport_to_shost(rport);
866 scsi_qla_host_t *ha = to_qla_host(host);
869 ha->port_down_retry_count = timeout;
871 ha->port_down_retry_count = 1;
873 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
877 qla2x00_issue_lip(struct Scsi_Host *shost)
879 scsi_qla_host_t *ha = to_qla_host(shost);
881 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
885 static struct fc_host_statistics *
886 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
888 scsi_qla_host_t *ha = to_qla_host(shost);
891 link_stat_t stat_buf;
892 struct fc_host_statistics *pfc_host_stat;
894 rval = QLA_FUNCTION_FAILED;
895 pfc_host_stat = &ha->fc_host_stat;
896 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
898 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
899 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
900 sizeof(stat_buf) / 4, mb_stat);
901 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
902 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
903 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
905 /* Must be in a 'READY' state for statistics retrieval. */
906 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
910 if (rval != QLA_SUCCESS)
913 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
914 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
915 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
916 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
917 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
918 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
920 return pfc_host_stat;
924 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
926 scsi_qla_host_t *ha = to_qla_host(shost);
928 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
932 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
934 scsi_qla_host_t *ha = to_qla_host(shost);
936 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
940 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
942 scsi_qla_host_t *ha = to_qla_host(shost);
945 if (ha->device_flags & SWITCH_FOUND)
946 node_name = wwn_to_u64(ha->fabric_node_name);
948 node_name = wwn_to_u64(ha->node_name);
950 fc_host_fabric_name(shost) = node_name;
954 qla2x00_get_host_port_state(struct Scsi_Host *shost)
956 scsi_qla_host_t *ha = to_qla_host(shost);
958 if (!ha->flags.online)
959 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
960 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
961 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
963 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
966 struct fc_function_template qla2xxx_transport_functions = {
968 .show_host_node_name = 1,
969 .show_host_port_name = 1,
970 .show_host_supported_classes = 1,
972 .get_host_port_id = qla2x00_get_host_port_id,
973 .show_host_port_id = 1,
974 .get_host_speed = qla2x00_get_host_speed,
975 .show_host_speed = 1,
976 .get_host_port_type = qla2x00_get_host_port_type,
977 .show_host_port_type = 1,
978 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
979 .show_host_symbolic_name = 1,
980 .set_host_system_hostname = qla2x00_set_host_system_hostname,
981 .show_host_system_hostname = 1,
982 .get_host_fabric_name = qla2x00_get_host_fabric_name,
983 .show_host_fabric_name = 1,
984 .get_host_port_state = qla2x00_get_host_port_state,
985 .show_host_port_state = 1,
987 .dd_fcrport_size = sizeof(struct fc_port *),
988 .show_rport_supported_classes = 1,
990 .get_starget_node_name = qla2x00_get_starget_node_name,
991 .show_starget_node_name = 1,
992 .get_starget_port_name = qla2x00_get_starget_port_name,
993 .show_starget_port_name = 1,
994 .get_starget_port_id = qla2x00_get_starget_port_id,
995 .show_starget_port_id = 1,
997 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
998 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
999 .show_rport_dev_loss_tmo = 1,
1001 .issue_fc_host_lip = qla2x00_issue_lip,
1002 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1006 qla2x00_init_host_attr(scsi_qla_host_t *ha)
1008 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1009 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
1010 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;