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, char *buf, loff_t off,
17 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
18 struct device, kobj)));
19 char *rbuf = (char *)ha->fw_dump;
21 if (ha->fw_dump_reading == 0)
23 if (off > ha->fw_dump_len)
25 if (off + count > ha->fw_dump_len)
26 count = ha->fw_dump_len - off;
28 memcpy(buf, &rbuf[off], count);
34 qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off,
37 struct scsi_qla_host *ha = to_qla_host(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);
72 static struct bin_attribute sysfs_fw_dump_attr = {
75 .mode = S_IRUSR | S_IWUSR,
78 .read = qla2x00_sysfs_read_fw_dump,
79 .write = qla2x00_sysfs_write_fw_dump,
83 qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off,
86 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
87 struct device, kobj)));
90 if (!capable(CAP_SYS_ADMIN) || off != 0)
94 spin_lock_irqsave(&ha->hardware_lock, flags);
95 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
97 spin_unlock_irqrestore(&ha->hardware_lock, flags);
99 return ha->nvram_size;
103 qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
106 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
107 struct device, kobj)));
111 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
114 /* Checksum NVRAM. */
115 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
119 iter = (uint32_t *)buf;
121 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
122 chksum += le32_to_cpu(*iter++);
123 chksum = ~chksum + 1;
124 *iter = cpu_to_le32(chksum);
129 iter = (uint8_t *)buf;
131 for (cnt = 0; cnt < count - 1; cnt++)
133 chksum = ~chksum + 1;
138 spin_lock_irqsave(&ha->hardware_lock, flags);
139 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
140 spin_unlock_irqrestore(&ha->hardware_lock, flags);
142 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
147 static struct bin_attribute sysfs_nvram_attr = {
150 .mode = S_IRUSR | S_IWUSR,
153 .read = qla2x00_sysfs_read_nvram,
154 .write = qla2x00_sysfs_write_nvram,
158 qla2x00_sysfs_read_optrom(struct kobject *kobj, char *buf, loff_t off,
161 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
162 struct device, kobj)));
164 if (ha->optrom_state != QLA_SREADING)
166 if (off > ha->optrom_size)
168 if (off + count > ha->optrom_size)
169 count = ha->optrom_size - off;
171 memcpy(buf, &ha->optrom_buffer[off], count);
177 qla2x00_sysfs_write_optrom(struct kobject *kobj, char *buf, loff_t off,
180 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
181 struct device, kobj)));
183 if (ha->optrom_state != QLA_SWRITING)
185 if (off > ha->optrom_size)
187 if (off + count > ha->optrom_size)
188 count = ha->optrom_size - off;
190 memcpy(&ha->optrom_buffer[off], buf, count);
195 static struct bin_attribute sysfs_optrom_attr = {
198 .mode = S_IRUSR | S_IWUSR,
200 .size = OPTROM_SIZE_24XX,
201 .read = qla2x00_sysfs_read_optrom,
202 .write = qla2x00_sysfs_write_optrom,
206 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj, char *buf, loff_t off,
209 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
210 struct device, kobj)));
216 if (sscanf(buf, "%d", &val) != 1)
221 if (ha->optrom_state != QLA_SREADING &&
222 ha->optrom_state != QLA_SWRITING)
225 ha->optrom_state = QLA_SWAITING;
226 vfree(ha->optrom_buffer);
227 ha->optrom_buffer = NULL;
230 if (ha->optrom_state != QLA_SWAITING)
233 ha->optrom_state = QLA_SREADING;
234 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
235 if (ha->optrom_buffer == NULL) {
236 qla_printk(KERN_WARNING, ha,
237 "Unable to allocate memory for optrom retrieval "
238 "(%x).\n", ha->optrom_size);
240 ha->optrom_state = QLA_SWAITING;
244 memset(ha->optrom_buffer, 0, ha->optrom_size);
245 ha->isp_ops.read_optrom(ha, ha->optrom_buffer, 0,
249 if (ha->optrom_state != QLA_SWAITING)
252 ha->optrom_state = QLA_SWRITING;
253 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
254 if (ha->optrom_buffer == NULL) {
255 qla_printk(KERN_WARNING, ha,
256 "Unable to allocate memory for optrom update "
257 "(%x).\n", ha->optrom_size);
259 ha->optrom_state = QLA_SWAITING;
262 memset(ha->optrom_buffer, 0, ha->optrom_size);
265 if (ha->optrom_state != QLA_SWRITING)
268 ha->isp_ops.write_optrom(ha, ha->optrom_buffer, 0,
275 static struct bin_attribute sysfs_optrom_ctl_attr = {
277 .name = "optrom_ctl",
281 .write = qla2x00_sysfs_write_optrom_ctl,
285 qla2x00_sysfs_read_vpd(struct kobject *kobj, char *buf, loff_t off,
288 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
289 struct device, kobj)));
292 if (!capable(CAP_SYS_ADMIN) || off != 0)
296 spin_lock_irqsave(&ha->hardware_lock, flags);
297 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->vpd_base, ha->vpd_size);
298 spin_unlock_irqrestore(&ha->hardware_lock, flags);
304 qla2x00_sysfs_write_vpd(struct kobject *kobj, char *buf, loff_t off,
307 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
308 struct device, kobj)));
311 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
315 spin_lock_irqsave(&ha->hardware_lock, flags);
316 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
317 spin_unlock_irqrestore(&ha->hardware_lock, flags);
322 static struct bin_attribute sysfs_vpd_attr = {
325 .mode = S_IRUSR | S_IWUSR,
328 .read = qla2x00_sysfs_read_vpd,
329 .write = qla2x00_sysfs_write_vpd,
333 qla2x00_sysfs_read_sfp(struct kobject *kobj, char *buf, loff_t off,
336 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
337 struct device, kobj)));
338 uint16_t iter, addr, offset;
341 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
345 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
346 iter++, offset += SFP_BLOCK_SIZE) {
348 /* Skip to next device address. */
353 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
355 if (rval != QLA_SUCCESS) {
356 qla_printk(KERN_WARNING, ha,
357 "Unable to read SFP data (%x/%x/%x).\n", rval,
362 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
363 buf += SFP_BLOCK_SIZE;
369 static struct bin_attribute sysfs_sfp_attr = {
372 .mode = S_IRUSR | S_IWUSR,
374 .size = SFP_DEV_SIZE * 2,
375 .read = qla2x00_sysfs_read_sfp,
378 static struct sysfs_entry {
380 struct bin_attribute *attr;
382 } bin_file_entries[] = {
383 { "fw_dump", &sysfs_fw_dump_attr, },
384 { "nvram", &sysfs_nvram_attr, },
385 { "optrom", &sysfs_optrom_attr, },
386 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
387 { "vpd", &sysfs_vpd_attr, 1 },
388 { "sfp", &sysfs_sfp_attr, 1 },
393 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
395 struct Scsi_Host *host = ha->host;
396 struct sysfs_entry *iter;
399 for (iter = bin_file_entries; iter->name; iter++) {
400 if (iter->is4GBp_only && (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)))
403 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
406 qla_printk(KERN_INFO, ha,
407 "Unable to create sysfs %s binary attribute "
408 "(%d).\n", iter->name, ret);
413 qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
415 struct Scsi_Host *host = ha->host;
416 struct sysfs_entry *iter;
418 for (iter = bin_file_entries; iter->name; iter++) {
419 if (iter->is4GBp_only && (!IS_QLA24XX(ha) && !IS_QLA54XX(ha)))
422 sysfs_remove_bin_file(&host->shost_gendev.kobj,
426 if (ha->beacon_blink_led == 1)
427 ha->isp_ops.beacon_off(ha);
430 /* Scsi_Host attributes. */
433 qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
435 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
439 qla2x00_fw_version_show(struct class_device *cdev, char *buf)
441 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
444 return snprintf(buf, PAGE_SIZE, "%s\n",
445 ha->isp_ops.fw_version_str(ha, fw_str));
449 qla2x00_serial_num_show(struct class_device *cdev, char *buf)
451 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
454 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
455 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
460 qla2x00_isp_name_show(struct class_device *cdev, char *buf)
462 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
463 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
467 qla2x00_isp_id_show(struct class_device *cdev, char *buf)
469 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
470 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
471 ha->product_id[0], ha->product_id[1], ha->product_id[2],
476 qla2x00_model_name_show(struct class_device *cdev, char *buf)
478 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
479 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
483 qla2x00_model_desc_show(struct class_device *cdev, char *buf)
485 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
486 return snprintf(buf, PAGE_SIZE, "%s\n",
487 ha->model_desc ? ha->model_desc: "");
491 qla2x00_pci_info_show(struct class_device *cdev, char *buf)
493 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
496 return snprintf(buf, PAGE_SIZE, "%s\n",
497 ha->isp_ops.pci_info_str(ha, pci_info));
501 qla2x00_state_show(struct class_device *cdev, char *buf)
503 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
506 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
507 atomic_read(&ha->loop_state) == LOOP_DEAD)
508 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
509 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
510 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
511 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
512 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
514 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
516 switch (ha->current_topology) {
518 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
521 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
524 len += snprintf(buf + len, PAGE_SIZE-len,
525 "N_Port to N_Port\n");
528 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
531 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
539 qla2x00_zio_show(struct class_device *cdev, char *buf)
541 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
544 switch (ha->zio_mode) {
546 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
548 case QLA_ZIO_DISABLED:
549 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
556 qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
558 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
562 if (!IS_ZIO_SUPPORTED(ha))
565 if (sscanf(buf, "%d", &val) != 1)
569 zio_mode = QLA_ZIO_MODE_6;
571 zio_mode = QLA_ZIO_DISABLED;
573 /* Update per-hba values and queue a reset. */
574 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
575 ha->zio_mode = zio_mode;
576 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
582 qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
584 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
586 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
590 qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
593 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
597 if (sscanf(buf, "%d", &val) != 1)
599 if (val > 25500 || val < 100)
602 zio_timer = (uint16_t)(val / 100);
603 ha->zio_timer = zio_timer;
609 qla2x00_beacon_show(struct class_device *cdev, char *buf)
611 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
614 if (ha->beacon_blink_led)
615 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
617 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
622 qla2x00_beacon_store(struct class_device *cdev, const char *buf,
625 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
629 if (IS_QLA2100(ha) || IS_QLA2200(ha))
632 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
633 qla_printk(KERN_WARNING, ha,
634 "Abort ISP active -- ignoring beacon request.\n");
638 if (sscanf(buf, "%d", &val) != 1)
642 rval = ha->isp_ops.beacon_on(ha);
644 rval = ha->isp_ops.beacon_off(ha);
646 if (rval != QLA_SUCCESS)
653 qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
655 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
657 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
658 ha->bios_revision[0]);
662 qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
664 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
666 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
667 ha->efi_revision[0]);
671 qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
673 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
675 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
676 ha->fcode_revision[0]);
680 qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
682 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
684 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
685 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
689 static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
691 static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
692 static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
693 static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
694 static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
695 static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
696 static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
697 static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
698 static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
699 static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
701 static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
702 qla2x00_zio_timer_store);
703 static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
704 qla2x00_beacon_store);
705 static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
706 qla2x00_optrom_bios_version_show, NULL);
707 static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
708 qla2x00_optrom_efi_version_show, NULL);
709 static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
710 qla2x00_optrom_fcode_version_show, NULL);
711 static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
712 qla2x00_optrom_fw_version_show, NULL);
714 struct class_device_attribute *qla2x00_host_attrs[] = {
715 &class_device_attr_driver_version,
716 &class_device_attr_fw_version,
717 &class_device_attr_serial_num,
718 &class_device_attr_isp_name,
719 &class_device_attr_isp_id,
720 &class_device_attr_model_name,
721 &class_device_attr_model_desc,
722 &class_device_attr_pci_info,
723 &class_device_attr_state,
724 &class_device_attr_zio,
725 &class_device_attr_zio_timer,
726 &class_device_attr_beacon,
727 &class_device_attr_optrom_bios_version,
728 &class_device_attr_optrom_efi_version,
729 &class_device_attr_optrom_fcode_version,
730 &class_device_attr_optrom_fw_version,
734 /* Host attributes. */
737 qla2x00_get_host_port_id(struct Scsi_Host *shost)
739 scsi_qla_host_t *ha = to_qla_host(shost);
741 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
742 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
746 qla2x00_get_host_speed(struct Scsi_Host *shost)
748 scsi_qla_host_t *ha = to_qla_host(shost);
751 switch (ha->link_data_rate) {
762 fc_host_speed(shost) = speed;
766 qla2x00_get_host_port_type(struct Scsi_Host *shost)
768 scsi_qla_host_t *ha = to_qla_host(shost);
769 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
771 switch (ha->current_topology) {
773 port_type = FC_PORTTYPE_LPORT;
776 port_type = FC_PORTTYPE_NLPORT;
779 port_type = FC_PORTTYPE_PTP;
782 port_type = FC_PORTTYPE_NPORT;
785 fc_host_port_type(shost) = port_type;
789 qla2x00_get_starget_node_name(struct scsi_target *starget)
791 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
792 scsi_qla_host_t *ha = to_qla_host(host);
796 list_for_each_entry(fcport, &ha->fcports, list) {
797 if (starget->id == fcport->os_target_id) {
798 node_name = wwn_to_u64(fcport->node_name);
803 fc_starget_node_name(starget) = node_name;
807 qla2x00_get_starget_port_name(struct scsi_target *starget)
809 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
810 scsi_qla_host_t *ha = to_qla_host(host);
814 list_for_each_entry(fcport, &ha->fcports, list) {
815 if (starget->id == fcport->os_target_id) {
816 port_name = wwn_to_u64(fcport->port_name);
821 fc_starget_port_name(starget) = port_name;
825 qla2x00_get_starget_port_id(struct scsi_target *starget)
827 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
828 scsi_qla_host_t *ha = to_qla_host(host);
830 uint32_t port_id = ~0U;
832 list_for_each_entry(fcport, &ha->fcports, list) {
833 if (starget->id == fcport->os_target_id) {
834 port_id = fcport->d_id.b.domain << 16 |
835 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
840 fc_starget_port_id(starget) = port_id;
844 qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
846 struct Scsi_Host *host = rport_to_shost(rport);
847 scsi_qla_host_t *ha = to_qla_host(host);
849 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
853 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
855 struct Scsi_Host *host = rport_to_shost(rport);
856 scsi_qla_host_t *ha = to_qla_host(host);
859 ha->port_down_retry_count = timeout;
861 ha->port_down_retry_count = 1;
863 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
867 qla2x00_issue_lip(struct Scsi_Host *shost)
869 scsi_qla_host_t *ha = to_qla_host(shost);
871 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
875 static struct fc_host_statistics *
876 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
878 scsi_qla_host_t *ha = to_qla_host(shost);
881 link_stat_t stat_buf;
882 struct fc_host_statistics *pfc_host_stat;
884 rval = QLA_FUNCTION_FAILED;
885 pfc_host_stat = &ha->fc_host_stat;
886 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
888 if (IS_QLA24XX(ha) || IS_QLA54XX(ha)) {
889 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
890 sizeof(stat_buf) / 4, mb_stat);
891 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
892 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
893 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
895 /* Must be in a 'READY' state for statistics retrieval. */
896 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
900 if (rval != QLA_SUCCESS)
903 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
904 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
905 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
906 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
907 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
908 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
910 return pfc_host_stat;
914 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
916 scsi_qla_host_t *ha = to_qla_host(shost);
918 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
922 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
924 scsi_qla_host_t *ha = to_qla_host(shost);
926 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
930 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
932 scsi_qla_host_t *ha = to_qla_host(shost);
935 if (ha->device_flags & SWITCH_FOUND)
936 node_name = wwn_to_u64(ha->fabric_node_name);
938 node_name = wwn_to_u64(ha->node_name);
940 fc_host_fabric_name(shost) = node_name;
944 qla2x00_get_host_port_state(struct Scsi_Host *shost)
946 scsi_qla_host_t *ha = to_qla_host(shost);
948 if (!ha->flags.online)
949 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
950 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
951 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
953 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
956 struct fc_function_template qla2xxx_transport_functions = {
958 .show_host_node_name = 1,
959 .show_host_port_name = 1,
960 .show_host_supported_classes = 1,
962 .get_host_port_id = qla2x00_get_host_port_id,
963 .show_host_port_id = 1,
964 .get_host_speed = qla2x00_get_host_speed,
965 .show_host_speed = 1,
966 .get_host_port_type = qla2x00_get_host_port_type,
967 .show_host_port_type = 1,
968 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
969 .show_host_symbolic_name = 1,
970 .set_host_system_hostname = qla2x00_set_host_system_hostname,
971 .show_host_system_hostname = 1,
972 .get_host_fabric_name = qla2x00_get_host_fabric_name,
973 .show_host_fabric_name = 1,
974 .get_host_port_state = qla2x00_get_host_port_state,
975 .show_host_port_state = 1,
977 .dd_fcrport_size = sizeof(struct fc_port *),
978 .show_rport_supported_classes = 1,
980 .get_starget_node_name = qla2x00_get_starget_node_name,
981 .show_starget_node_name = 1,
982 .get_starget_port_name = qla2x00_get_starget_port_name,
983 .show_starget_port_name = 1,
984 .get_starget_port_id = qla2x00_get_starget_port_id,
985 .show_starget_port_id = 1,
987 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
988 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
989 .show_rport_dev_loss_tmo = 1,
991 .issue_fc_host_lip = qla2x00_issue_lip,
992 .get_fc_host_stats = qla2x00_get_fc_host_stats,
996 qla2x00_init_host_attr(scsi_qla_host_t *ha)
998 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
999 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
1000 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;