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 = to_qla_host(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 = to_qla_host(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 = to_qla_host(dev_to_shost(container_of(kobj,
93 struct device, kobj)));
96 if (!capable(CAP_SYS_ADMIN) || off != 0)
100 spin_lock_irqsave(&ha->hardware_lock, flags);
101 ha->isp_ops->read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
103 spin_unlock_irqrestore(&ha->hardware_lock, flags);
105 return ha->nvram_size;
109 qla2x00_sysfs_write_nvram(struct kobject *kobj,
110 struct bin_attribute *bin_attr,
111 char *buf, loff_t off, size_t count)
113 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
114 struct device, kobj)));
118 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
121 /* Checksum NVRAM. */
122 if (IS_FWI2_CAPABLE(ha)) {
126 iter = (uint32_t *)buf;
128 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
129 chksum += le32_to_cpu(*iter++);
130 chksum = ~chksum + 1;
131 *iter = cpu_to_le32(chksum);
136 iter = (uint8_t *)buf;
138 for (cnt = 0; cnt < count - 1; cnt++)
140 chksum = ~chksum + 1;
145 spin_lock_irqsave(&ha->hardware_lock, flags);
146 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
149 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
154 static struct bin_attribute sysfs_nvram_attr = {
157 .mode = S_IRUSR | S_IWUSR,
160 .read = qla2x00_sysfs_read_nvram,
161 .write = qla2x00_sysfs_write_nvram,
165 qla2x00_sysfs_read_optrom(struct kobject *kobj,
166 struct bin_attribute *bin_attr,
167 char *buf, loff_t off, size_t count)
169 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
170 struct device, kobj)));
172 if (ha->optrom_state != QLA_SREADING)
174 if (off > ha->optrom_size)
176 if (off + count > ha->optrom_size)
177 count = ha->optrom_size - off;
179 memcpy(buf, &ha->optrom_buffer[off], count);
185 qla2x00_sysfs_write_optrom(struct kobject *kobj,
186 struct bin_attribute *bin_attr,
187 char *buf, loff_t off, size_t count)
189 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
190 struct device, kobj)));
192 if (ha->optrom_state != QLA_SWRITING)
194 if (off > ha->optrom_size)
196 if (off + count > ha->optrom_size)
197 count = ha->optrom_size - off;
199 memcpy(&ha->optrom_buffer[off], buf, count);
204 static struct bin_attribute sysfs_optrom_attr = {
207 .mode = S_IRUSR | S_IWUSR,
210 .read = qla2x00_sysfs_read_optrom,
211 .write = qla2x00_sysfs_write_optrom,
215 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
216 struct bin_attribute *bin_attr,
217 char *buf, loff_t off, size_t count)
219 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
220 struct device, kobj)));
226 if (sscanf(buf, "%d", &val) != 1)
231 if (ha->optrom_state != QLA_SREADING &&
232 ha->optrom_state != QLA_SWRITING)
235 ha->optrom_state = QLA_SWAITING;
236 vfree(ha->optrom_buffer);
237 ha->optrom_buffer = NULL;
240 if (ha->optrom_state != QLA_SWAITING)
243 ha->optrom_state = QLA_SREADING;
244 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
245 if (ha->optrom_buffer == NULL) {
246 qla_printk(KERN_WARNING, ha,
247 "Unable to allocate memory for optrom retrieval "
248 "(%x).\n", ha->optrom_size);
250 ha->optrom_state = QLA_SWAITING;
254 memset(ha->optrom_buffer, 0, ha->optrom_size);
255 ha->isp_ops->read_optrom(ha, ha->optrom_buffer, 0,
259 if (ha->optrom_state != QLA_SWAITING)
262 ha->optrom_state = QLA_SWRITING;
263 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
264 if (ha->optrom_buffer == NULL) {
265 qla_printk(KERN_WARNING, ha,
266 "Unable to allocate memory for optrom update "
267 "(%x).\n", ha->optrom_size);
269 ha->optrom_state = QLA_SWAITING;
272 memset(ha->optrom_buffer, 0, ha->optrom_size);
275 if (ha->optrom_state != QLA_SWRITING)
278 ha->isp_ops->write_optrom(ha, ha->optrom_buffer, 0,
285 static struct bin_attribute sysfs_optrom_ctl_attr = {
287 .name = "optrom_ctl",
291 .write = qla2x00_sysfs_write_optrom_ctl,
295 qla2x00_sysfs_read_vpd(struct kobject *kobj,
296 struct bin_attribute *bin_attr,
297 char *buf, loff_t off, size_t count)
299 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
300 struct device, kobj)));
303 if (!capable(CAP_SYS_ADMIN) || off != 0)
307 spin_lock_irqsave(&ha->hardware_lock, flags);
308 ha->isp_ops->read_nvram(ha, (uint8_t *)buf, ha->vpd_base,
310 spin_unlock_irqrestore(&ha->hardware_lock, flags);
316 qla2x00_sysfs_write_vpd(struct kobject *kobj,
317 struct bin_attribute *bin_attr,
318 char *buf, loff_t off, size_t count)
320 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
321 struct device, kobj)));
324 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
328 spin_lock_irqsave(&ha->hardware_lock, flags);
329 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
330 spin_unlock_irqrestore(&ha->hardware_lock, flags);
335 static struct bin_attribute sysfs_vpd_attr = {
338 .mode = S_IRUSR | S_IWUSR,
341 .read = qla2x00_sysfs_read_vpd,
342 .write = qla2x00_sysfs_write_vpd,
346 qla2x00_sysfs_read_sfp(struct kobject *kobj,
347 struct bin_attribute *bin_attr,
348 char *buf, loff_t off, size_t count)
350 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
351 struct device, kobj)));
352 uint16_t iter, addr, offset;
355 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
359 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
360 iter++, offset += SFP_BLOCK_SIZE) {
362 /* Skip to next device address. */
367 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
369 if (rval != QLA_SUCCESS) {
370 qla_printk(KERN_WARNING, ha,
371 "Unable to read SFP data (%x/%x/%x).\n", rval,
376 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
377 buf += SFP_BLOCK_SIZE;
383 static struct bin_attribute sysfs_sfp_attr = {
386 .mode = S_IRUSR | S_IWUSR,
388 .size = SFP_DEV_SIZE * 2,
389 .read = qla2x00_sysfs_read_sfp,
392 static struct sysfs_entry {
394 struct bin_attribute *attr;
396 } bin_file_entries[] = {
397 { "fw_dump", &sysfs_fw_dump_attr, },
398 { "nvram", &sysfs_nvram_attr, },
399 { "optrom", &sysfs_optrom_attr, },
400 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
401 { "vpd", &sysfs_vpd_attr, 1 },
402 { "sfp", &sysfs_sfp_attr, 1 },
407 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
409 struct Scsi_Host *host = ha->host;
410 struct sysfs_entry *iter;
413 for (iter = bin_file_entries; iter->name; iter++) {
414 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
417 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
420 qla_printk(KERN_INFO, ha,
421 "Unable to create sysfs %s binary attribute "
422 "(%d).\n", iter->name, ret);
427 qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
429 struct Scsi_Host *host = ha->host;
430 struct sysfs_entry *iter;
432 for (iter = bin_file_entries; iter->name; iter++) {
433 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
436 sysfs_remove_bin_file(&host->shost_gendev.kobj,
440 if (ha->beacon_blink_led == 1)
441 ha->isp_ops->beacon_off(ha);
444 /* Scsi_Host attributes. */
447 qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
449 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
453 qla2x00_fw_version_show(struct class_device *cdev, char *buf)
455 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
458 return snprintf(buf, PAGE_SIZE, "%s\n",
459 ha->isp_ops->fw_version_str(ha, fw_str));
463 qla2x00_serial_num_show(struct class_device *cdev, char *buf)
465 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
468 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
469 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
474 qla2x00_isp_name_show(struct class_device *cdev, char *buf)
476 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
477 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
481 qla2x00_isp_id_show(struct class_device *cdev, char *buf)
483 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
484 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
485 ha->product_id[0], ha->product_id[1], ha->product_id[2],
490 qla2x00_model_name_show(struct class_device *cdev, char *buf)
492 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
493 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
497 qla2x00_model_desc_show(struct class_device *cdev, char *buf)
499 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
500 return snprintf(buf, PAGE_SIZE, "%s\n",
501 ha->model_desc ? ha->model_desc: "");
505 qla2x00_pci_info_show(struct class_device *cdev, char *buf)
507 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
510 return snprintf(buf, PAGE_SIZE, "%s\n",
511 ha->isp_ops->pci_info_str(ha, pci_info));
515 qla2x00_state_show(struct class_device *cdev, char *buf)
517 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
520 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
521 atomic_read(&ha->loop_state) == LOOP_DEAD)
522 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
523 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
524 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
525 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
526 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
528 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
530 switch (ha->current_topology) {
532 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
535 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
538 len += snprintf(buf + len, PAGE_SIZE-len,
539 "N_Port to N_Port\n");
542 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
545 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
553 qla2x00_zio_show(struct class_device *cdev, char *buf)
555 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
558 switch (ha->zio_mode) {
560 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
562 case QLA_ZIO_DISABLED:
563 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
570 qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
572 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
576 if (!IS_ZIO_SUPPORTED(ha))
579 if (sscanf(buf, "%d", &val) != 1)
583 zio_mode = QLA_ZIO_MODE_6;
585 zio_mode = QLA_ZIO_DISABLED;
587 /* Update per-hba values and queue a reset. */
588 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
589 ha->zio_mode = zio_mode;
590 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
596 qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
598 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
600 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
604 qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
607 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
611 if (sscanf(buf, "%d", &val) != 1)
613 if (val > 25500 || val < 100)
616 zio_timer = (uint16_t)(val / 100);
617 ha->zio_timer = zio_timer;
623 qla2x00_beacon_show(struct class_device *cdev, char *buf)
625 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
628 if (ha->beacon_blink_led)
629 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
631 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
636 qla2x00_beacon_store(struct class_device *cdev, const char *buf,
639 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
643 if (IS_QLA2100(ha) || IS_QLA2200(ha))
646 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
647 qla_printk(KERN_WARNING, ha,
648 "Abort ISP active -- ignoring beacon request.\n");
652 if (sscanf(buf, "%d", &val) != 1)
656 rval = ha->isp_ops->beacon_on(ha);
658 rval = ha->isp_ops->beacon_off(ha);
660 if (rval != QLA_SUCCESS)
667 qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
669 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
671 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
672 ha->bios_revision[0]);
676 qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
678 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
680 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
681 ha->efi_revision[0]);
685 qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
687 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
689 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
690 ha->fcode_revision[0]);
694 qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
696 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
698 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
699 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
703 static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
705 static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
706 static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
707 static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
708 static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
709 static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
710 static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
711 static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
712 static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
713 static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
715 static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
716 qla2x00_zio_timer_store);
717 static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
718 qla2x00_beacon_store);
719 static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
720 qla2x00_optrom_bios_version_show, NULL);
721 static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
722 qla2x00_optrom_efi_version_show, NULL);
723 static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
724 qla2x00_optrom_fcode_version_show, NULL);
725 static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
726 qla2x00_optrom_fw_version_show, NULL);
728 struct class_device_attribute *qla2x00_host_attrs[] = {
729 &class_device_attr_driver_version,
730 &class_device_attr_fw_version,
731 &class_device_attr_serial_num,
732 &class_device_attr_isp_name,
733 &class_device_attr_isp_id,
734 &class_device_attr_model_name,
735 &class_device_attr_model_desc,
736 &class_device_attr_pci_info,
737 &class_device_attr_state,
738 &class_device_attr_zio,
739 &class_device_attr_zio_timer,
740 &class_device_attr_beacon,
741 &class_device_attr_optrom_bios_version,
742 &class_device_attr_optrom_efi_version,
743 &class_device_attr_optrom_fcode_version,
744 &class_device_attr_optrom_fw_version,
748 /* Host attributes. */
751 qla2x00_get_host_port_id(struct Scsi_Host *shost)
753 scsi_qla_host_t *ha = to_qla_host(shost);
755 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
756 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
760 qla2x00_get_host_speed(struct Scsi_Host *shost)
762 scsi_qla_host_t *ha = to_qla_host(shost);
765 switch (ha->link_data_rate) {
776 fc_host_speed(shost) = speed;
780 qla2x00_get_host_port_type(struct Scsi_Host *shost)
782 scsi_qla_host_t *ha = to_qla_host(shost);
783 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
785 switch (ha->current_topology) {
787 port_type = FC_PORTTYPE_LPORT;
790 port_type = FC_PORTTYPE_NLPORT;
793 port_type = FC_PORTTYPE_PTP;
796 port_type = FC_PORTTYPE_NPORT;
799 fc_host_port_type(shost) = port_type;
803 qla2x00_get_starget_node_name(struct scsi_target *starget)
805 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
806 scsi_qla_host_t *ha = to_qla_host(host);
810 list_for_each_entry(fcport, &ha->fcports, list) {
811 if (starget->id == fcport->os_target_id) {
812 node_name = wwn_to_u64(fcport->node_name);
817 fc_starget_node_name(starget) = node_name;
821 qla2x00_get_starget_port_name(struct scsi_target *starget)
823 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
824 scsi_qla_host_t *ha = to_qla_host(host);
828 list_for_each_entry(fcport, &ha->fcports, list) {
829 if (starget->id == fcport->os_target_id) {
830 port_name = wwn_to_u64(fcport->port_name);
835 fc_starget_port_name(starget) = port_name;
839 qla2x00_get_starget_port_id(struct scsi_target *starget)
841 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
842 scsi_qla_host_t *ha = to_qla_host(host);
844 uint32_t port_id = ~0U;
846 list_for_each_entry(fcport, &ha->fcports, list) {
847 if (starget->id == fcport->os_target_id) {
848 port_id = fcport->d_id.b.domain << 16 |
849 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
854 fc_starget_port_id(starget) = port_id;
858 qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
860 struct Scsi_Host *host = rport_to_shost(rport);
861 scsi_qla_host_t *ha = to_qla_host(host);
863 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
867 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
869 struct Scsi_Host *host = rport_to_shost(rport);
870 scsi_qla_host_t *ha = to_qla_host(host);
873 ha->port_down_retry_count = timeout;
875 ha->port_down_retry_count = 1;
877 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
881 qla2x00_issue_lip(struct Scsi_Host *shost)
883 scsi_qla_host_t *ha = to_qla_host(shost);
885 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
889 static struct fc_host_statistics *
890 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
892 scsi_qla_host_t *ha = to_qla_host(shost);
895 link_stat_t stat_buf;
896 struct fc_host_statistics *pfc_host_stat;
898 rval = QLA_FUNCTION_FAILED;
899 pfc_host_stat = &ha->fc_host_stat;
900 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
902 if (IS_FWI2_CAPABLE(ha)) {
903 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
904 sizeof(stat_buf) / 4, mb_stat);
905 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
906 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
907 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
909 /* Must be in a 'READY' state for statistics retrieval. */
910 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
914 if (rval != QLA_SUCCESS)
917 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
918 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
919 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
920 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
921 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
922 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
924 return pfc_host_stat;
928 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
930 scsi_qla_host_t *ha = to_qla_host(shost);
932 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
936 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
938 scsi_qla_host_t *ha = to_qla_host(shost);
940 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
944 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
946 scsi_qla_host_t *ha = to_qla_host(shost);
949 if (ha->device_flags & SWITCH_FOUND)
950 node_name = wwn_to_u64(ha->fabric_node_name);
952 node_name = wwn_to_u64(ha->node_name);
954 fc_host_fabric_name(shost) = node_name;
958 qla2x00_get_host_port_state(struct Scsi_Host *shost)
960 scsi_qla_host_t *ha = to_qla_host(shost);
962 if (!ha->flags.online)
963 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
964 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
965 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
967 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
971 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
974 scsi_qla_host_t *ha = (scsi_qla_host_t *) fc_vport->shost->hostdata;
975 scsi_qla_host_t *vha;
977 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
979 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
980 "status %x\n", ret));
984 vha = qla24xx_create_vhost(fc_vport);
986 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
988 return FC_VPORT_FAILED;
991 atomic_set(&vha->vp_state, VP_OFFLINE);
992 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
994 atomic_set(&vha->vp_state, VP_FAILED);
996 /* ready to create vport */
997 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
999 /* initialized vport states */
1000 atomic_set(&vha->loop_state, LOOP_DOWN);
1001 vha->vp_err_state= VP_ERR_PORTDWN;
1002 vha->vp_prev_err_state= VP_ERR_UNKWN;
1003 /* Check if physical ha port is Up */
1004 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1005 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1006 /* Don't retry or attempt login of this virtual port */
1007 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1009 atomic_set(&vha->loop_state, LOOP_DEAD);
1011 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1014 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1015 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1016 vha->host_no, vha->vp_idx));
1017 goto vport_create_failed_2;
1020 /* initialize attributes */
1021 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1022 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1023 fc_host_supported_classes(vha->host) =
1024 fc_host_supported_classes(ha->host);
1025 fc_host_supported_speeds(vha->host) =
1026 fc_host_supported_speeds(ha->host);
1028 qla24xx_vport_disable(fc_vport, disable);
1031 vport_create_failed_2:
1032 qla24xx_disable_vp(vha);
1033 qla24xx_deallocate_vp_id(vha);
1034 kfree(vha->port_name);
1035 kfree(vha->node_name);
1036 scsi_host_put(vha->host);
1037 return FC_VPORT_FAILED;
1041 qla24xx_vport_delete(struct fc_vport *fc_vport)
1043 scsi_qla_host_t *ha = (scsi_qla_host_t *) fc_vport->shost->hostdata;
1044 scsi_qla_host_t *vha = fc_vport->dd_data;
1046 qla24xx_disable_vp(vha);
1047 qla24xx_deallocate_vp_id(vha);
1049 down(&ha->vport_sem);
1050 ha->cur_vport_count--;
1051 clear_bit(vha->vp_idx, (unsigned long *)ha->vp_idx_map);
1054 kfree(vha->node_name);
1055 kfree(vha->port_name);
1057 if (vha->timer_active) {
1058 qla2x00_vp_stop_timer(vha);
1059 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1061 vha->host_no, vha->vp_idx, vha));
1064 fc_remove_host(vha->host);
1066 scsi_remove_host(vha->host);
1068 scsi_host_put(vha->host);
1074 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1076 scsi_qla_host_t *vha = fc_vport->dd_data;
1079 qla24xx_disable_vp(vha);
1081 qla24xx_enable_vp(vha);
1086 struct fc_function_template qla2xxx_transport_functions = {
1088 .show_host_node_name = 1,
1089 .show_host_port_name = 1,
1090 .show_host_supported_classes = 1,
1092 .get_host_port_id = qla2x00_get_host_port_id,
1093 .show_host_port_id = 1,
1094 .get_host_speed = qla2x00_get_host_speed,
1095 .show_host_speed = 1,
1096 .get_host_port_type = qla2x00_get_host_port_type,
1097 .show_host_port_type = 1,
1098 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1099 .show_host_symbolic_name = 1,
1100 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1101 .show_host_system_hostname = 1,
1102 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1103 .show_host_fabric_name = 1,
1104 .get_host_port_state = qla2x00_get_host_port_state,
1105 .show_host_port_state = 1,
1107 .dd_fcrport_size = sizeof(struct fc_port *),
1108 .show_rport_supported_classes = 1,
1110 .get_starget_node_name = qla2x00_get_starget_node_name,
1111 .show_starget_node_name = 1,
1112 .get_starget_port_name = qla2x00_get_starget_port_name,
1113 .show_starget_port_name = 1,
1114 .get_starget_port_id = qla2x00_get_starget_port_id,
1115 .show_starget_port_id = 1,
1117 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1118 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1119 .show_rport_dev_loss_tmo = 1,
1121 .issue_fc_host_lip = qla2x00_issue_lip,
1122 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1124 .vport_create = qla24xx_vport_create,
1125 .vport_disable = qla24xx_vport_disable,
1126 .vport_delete = qla24xx_vport_delete,
1129 struct fc_function_template qla2xxx_transport_vport_functions = {
1131 .show_host_node_name = 1,
1132 .show_host_port_name = 1,
1133 .show_host_supported_classes = 1,
1135 .get_host_port_id = qla2x00_get_host_port_id,
1136 .show_host_port_id = 1,
1137 .get_host_speed = qla2x00_get_host_speed,
1138 .show_host_speed = 1,
1139 .get_host_port_type = qla2x00_get_host_port_type,
1140 .show_host_port_type = 1,
1141 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1142 .show_host_symbolic_name = 1,
1143 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1144 .show_host_system_hostname = 1,
1145 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1146 .show_host_fabric_name = 1,
1147 .get_host_port_state = qla2x00_get_host_port_state,
1148 .show_host_port_state = 1,
1150 .dd_fcrport_size = sizeof(struct fc_port *),
1151 .show_rport_supported_classes = 1,
1153 .get_starget_node_name = qla2x00_get_starget_node_name,
1154 .show_starget_node_name = 1,
1155 .get_starget_port_name = qla2x00_get_starget_port_name,
1156 .show_starget_port_name = 1,
1157 .get_starget_port_id = qla2x00_get_starget_port_id,
1158 .show_starget_port_id = 1,
1160 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1161 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1162 .show_rport_dev_loss_tmo = 1,
1164 .issue_fc_host_lip = qla2x00_issue_lip,
1165 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1169 qla2x00_init_host_attr(scsi_qla_host_t *ha)
1171 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1172 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
1173 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
1174 fc_host_max_npiv_vports(ha->host) = MAX_NUM_VPORT_FABRIC;
1175 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;