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)));
94 int size = ha->nvram_size;
95 char *nvram_cache = ha->nvram;
97 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
99 if (off + count > size) {
104 /* Read NVRAM data from cache. */
105 memcpy(buf, &nvram_cache[off], count);
111 qla2x00_sysfs_write_nvram(struct kobject *kobj,
112 struct bin_attribute *bin_attr,
113 char *buf, loff_t off, size_t count)
115 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
116 struct device, kobj)));
120 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
123 /* Checksum NVRAM. */
124 if (IS_FWI2_CAPABLE(ha)) {
128 iter = (uint32_t *)buf;
130 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
131 chksum += le32_to_cpu(*iter++);
132 chksum = ~chksum + 1;
133 *iter = cpu_to_le32(chksum);
138 iter = (uint8_t *)buf;
140 for (cnt = 0; cnt < count - 1; cnt++)
142 chksum = ~chksum + 1;
147 spin_lock_irqsave(&ha->hardware_lock, flags);
148 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
149 ha->isp_ops->read_nvram(ha, (uint8_t *)&ha->nvram, ha->nvram_base,
151 spin_unlock_irqrestore(&ha->hardware_lock, flags);
153 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
158 static struct bin_attribute sysfs_nvram_attr = {
161 .mode = S_IRUSR | S_IWUSR,
164 .read = qla2x00_sysfs_read_nvram,
165 .write = qla2x00_sysfs_write_nvram,
169 qla2x00_sysfs_read_optrom(struct kobject *kobj,
170 struct bin_attribute *bin_attr,
171 char *buf, loff_t off, size_t count)
173 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
174 struct device, kobj)));
176 if (ha->optrom_state != QLA_SREADING)
178 if (off > ha->optrom_size)
180 if (off + count > ha->optrom_size)
181 count = ha->optrom_size - off;
183 memcpy(buf, &ha->optrom_buffer[off], count);
189 qla2x00_sysfs_write_optrom(struct kobject *kobj,
190 struct bin_attribute *bin_attr,
191 char *buf, loff_t off, size_t count)
193 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
194 struct device, kobj)));
196 if (ha->optrom_state != QLA_SWRITING)
198 if (off > ha->optrom_size)
200 if (off + count > ha->optrom_size)
201 count = ha->optrom_size - off;
203 memcpy(&ha->optrom_buffer[off], buf, count);
208 static struct bin_attribute sysfs_optrom_attr = {
211 .mode = S_IRUSR | S_IWUSR,
214 .read = qla2x00_sysfs_read_optrom,
215 .write = qla2x00_sysfs_write_optrom,
219 qla2x00_sysfs_write_optrom_ctl(struct kobject *kobj,
220 struct bin_attribute *bin_attr,
221 char *buf, loff_t off, size_t count)
223 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
224 struct device, kobj)));
230 if (sscanf(buf, "%d", &val) != 1)
235 if (ha->optrom_state != QLA_SREADING &&
236 ha->optrom_state != QLA_SWRITING)
239 ha->optrom_state = QLA_SWAITING;
240 vfree(ha->optrom_buffer);
241 ha->optrom_buffer = NULL;
244 if (ha->optrom_state != QLA_SWAITING)
247 ha->optrom_state = QLA_SREADING;
248 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
249 if (ha->optrom_buffer == NULL) {
250 qla_printk(KERN_WARNING, ha,
251 "Unable to allocate memory for optrom retrieval "
252 "(%x).\n", ha->optrom_size);
254 ha->optrom_state = QLA_SWAITING;
258 memset(ha->optrom_buffer, 0, ha->optrom_size);
259 ha->isp_ops->read_optrom(ha, ha->optrom_buffer, 0,
263 if (ha->optrom_state != QLA_SWAITING)
266 ha->optrom_state = QLA_SWRITING;
267 ha->optrom_buffer = (uint8_t *)vmalloc(ha->optrom_size);
268 if (ha->optrom_buffer == NULL) {
269 qla_printk(KERN_WARNING, ha,
270 "Unable to allocate memory for optrom update "
271 "(%x).\n", ha->optrom_size);
273 ha->optrom_state = QLA_SWAITING;
276 memset(ha->optrom_buffer, 0, ha->optrom_size);
279 if (ha->optrom_state != QLA_SWRITING)
282 ha->isp_ops->write_optrom(ha, ha->optrom_buffer, 0,
289 static struct bin_attribute sysfs_optrom_ctl_attr = {
291 .name = "optrom_ctl",
295 .write = qla2x00_sysfs_write_optrom_ctl,
299 qla2x00_sysfs_read_vpd(struct kobject *kobj,
300 struct bin_attribute *bin_attr,
301 char *buf, loff_t off, size_t count)
303 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
304 struct device, kobj)));
305 int size = ha->vpd_size;
306 char *vpd_cache = ha->vpd;
308 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
310 if (off + count > size) {
315 /* Read NVRAM data from cache. */
316 memcpy(buf, &vpd_cache[off], count);
322 qla2x00_sysfs_write_vpd(struct kobject *kobj,
323 struct bin_attribute *bin_attr,
324 char *buf, loff_t off, size_t count)
326 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
327 struct device, kobj)));
330 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
334 spin_lock_irqsave(&ha->hardware_lock, flags);
335 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
336 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
337 spin_unlock_irqrestore(&ha->hardware_lock, flags);
342 static struct bin_attribute sysfs_vpd_attr = {
345 .mode = S_IRUSR | S_IWUSR,
348 .read = qla2x00_sysfs_read_vpd,
349 .write = qla2x00_sysfs_write_vpd,
353 qla2x00_sysfs_read_sfp(struct kobject *kobj,
354 struct bin_attribute *bin_attr,
355 char *buf, loff_t off, size_t count)
357 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
358 struct device, kobj)));
359 uint16_t iter, addr, offset;
362 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
366 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
367 iter++, offset += SFP_BLOCK_SIZE) {
369 /* Skip to next device address. */
374 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
376 if (rval != QLA_SUCCESS) {
377 qla_printk(KERN_WARNING, ha,
378 "Unable to read SFP data (%x/%x/%x).\n", rval,
383 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
384 buf += SFP_BLOCK_SIZE;
390 static struct bin_attribute sysfs_sfp_attr = {
393 .mode = S_IRUSR | S_IWUSR,
395 .size = SFP_DEV_SIZE * 2,
396 .read = qla2x00_sysfs_read_sfp,
399 static struct sysfs_entry {
401 struct bin_attribute *attr;
403 } bin_file_entries[] = {
404 { "fw_dump", &sysfs_fw_dump_attr, },
405 { "nvram", &sysfs_nvram_attr, },
406 { "optrom", &sysfs_optrom_attr, },
407 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
408 { "vpd", &sysfs_vpd_attr, 1 },
409 { "sfp", &sysfs_sfp_attr, 1 },
414 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
416 struct Scsi_Host *host = ha->host;
417 struct sysfs_entry *iter;
420 for (iter = bin_file_entries; iter->name; iter++) {
421 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
424 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
427 qla_printk(KERN_INFO, ha,
428 "Unable to create sysfs %s binary attribute "
429 "(%d).\n", iter->name, ret);
434 qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
436 struct Scsi_Host *host = ha->host;
437 struct sysfs_entry *iter;
439 for (iter = bin_file_entries; iter->name; iter++) {
440 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
443 sysfs_remove_bin_file(&host->shost_gendev.kobj,
447 if (ha->beacon_blink_led == 1)
448 ha->isp_ops->beacon_off(ha);
451 /* Scsi_Host attributes. */
454 qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
456 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
460 qla2x00_fw_version_show(struct class_device *cdev, char *buf)
462 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
465 return snprintf(buf, PAGE_SIZE, "%s\n",
466 ha->isp_ops->fw_version_str(ha, fw_str));
470 qla2x00_serial_num_show(struct class_device *cdev, char *buf)
472 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
475 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
476 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
481 qla2x00_isp_name_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, "ISP%04X\n", ha->pdev->device);
488 qla2x00_isp_id_show(struct class_device *cdev, char *buf)
490 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
491 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
492 ha->product_id[0], ha->product_id[1], ha->product_id[2],
497 qla2x00_model_name_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", ha->model_number);
504 qla2x00_model_desc_show(struct class_device *cdev, char *buf)
506 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
507 return snprintf(buf, PAGE_SIZE, "%s\n",
508 ha->model_desc ? ha->model_desc: "");
512 qla2x00_pci_info_show(struct class_device *cdev, char *buf)
514 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
517 return snprintf(buf, PAGE_SIZE, "%s\n",
518 ha->isp_ops->pci_info_str(ha, pci_info));
522 qla2x00_state_show(struct class_device *cdev, char *buf)
524 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
527 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
528 atomic_read(&ha->loop_state) == LOOP_DEAD)
529 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
530 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
531 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
532 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
533 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
535 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
537 switch (ha->current_topology) {
539 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
542 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
545 len += snprintf(buf + len, PAGE_SIZE-len,
546 "N_Port to N_Port\n");
549 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
552 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
560 qla2x00_zio_show(struct class_device *cdev, char *buf)
562 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
565 switch (ha->zio_mode) {
567 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
569 case QLA_ZIO_DISABLED:
570 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
577 qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
579 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
583 if (!IS_ZIO_SUPPORTED(ha))
586 if (sscanf(buf, "%d", &val) != 1)
590 zio_mode = QLA_ZIO_MODE_6;
592 zio_mode = QLA_ZIO_DISABLED;
594 /* Update per-hba values and queue a reset. */
595 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
596 ha->zio_mode = zio_mode;
597 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
603 qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
605 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
607 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
611 qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
614 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
618 if (sscanf(buf, "%d", &val) != 1)
620 if (val > 25500 || val < 100)
623 zio_timer = (uint16_t)(val / 100);
624 ha->zio_timer = zio_timer;
630 qla2x00_beacon_show(struct class_device *cdev, char *buf)
632 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
635 if (ha->beacon_blink_led)
636 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
638 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
643 qla2x00_beacon_store(struct class_device *cdev, const char *buf,
646 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
650 if (IS_QLA2100(ha) || IS_QLA2200(ha))
653 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
654 qla_printk(KERN_WARNING, ha,
655 "Abort ISP active -- ignoring beacon request.\n");
659 if (sscanf(buf, "%d", &val) != 1)
663 rval = ha->isp_ops->beacon_on(ha);
665 rval = ha->isp_ops->beacon_off(ha);
667 if (rval != QLA_SUCCESS)
674 qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
676 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
678 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
679 ha->bios_revision[0]);
683 qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
685 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
687 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
688 ha->efi_revision[0]);
692 qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
694 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
696 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
697 ha->fcode_revision[0]);
701 qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
703 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
705 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
706 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
710 static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
712 static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
713 static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
714 static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
715 static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
716 static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
717 static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
718 static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
719 static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
720 static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
722 static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
723 qla2x00_zio_timer_store);
724 static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
725 qla2x00_beacon_store);
726 static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
727 qla2x00_optrom_bios_version_show, NULL);
728 static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
729 qla2x00_optrom_efi_version_show, NULL);
730 static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
731 qla2x00_optrom_fcode_version_show, NULL);
732 static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
733 qla2x00_optrom_fw_version_show, NULL);
735 struct class_device_attribute *qla2x00_host_attrs[] = {
736 &class_device_attr_driver_version,
737 &class_device_attr_fw_version,
738 &class_device_attr_serial_num,
739 &class_device_attr_isp_name,
740 &class_device_attr_isp_id,
741 &class_device_attr_model_name,
742 &class_device_attr_model_desc,
743 &class_device_attr_pci_info,
744 &class_device_attr_state,
745 &class_device_attr_zio,
746 &class_device_attr_zio_timer,
747 &class_device_attr_beacon,
748 &class_device_attr_optrom_bios_version,
749 &class_device_attr_optrom_efi_version,
750 &class_device_attr_optrom_fcode_version,
751 &class_device_attr_optrom_fw_version,
755 /* Host attributes. */
758 qla2x00_get_host_port_id(struct Scsi_Host *shost)
760 scsi_qla_host_t *ha = to_qla_host(shost);
762 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
763 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
767 qla2x00_get_host_speed(struct Scsi_Host *shost)
769 scsi_qla_host_t *ha = to_qla_host(shost);
772 switch (ha->link_data_rate) {
783 fc_host_speed(shost) = speed;
787 qla2x00_get_host_port_type(struct Scsi_Host *shost)
789 scsi_qla_host_t *ha = to_qla_host(shost);
790 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
792 switch (ha->current_topology) {
794 port_type = FC_PORTTYPE_LPORT;
797 port_type = FC_PORTTYPE_NLPORT;
800 port_type = FC_PORTTYPE_PTP;
803 port_type = FC_PORTTYPE_NPORT;
806 fc_host_port_type(shost) = port_type;
810 qla2x00_get_starget_node_name(struct scsi_target *starget)
812 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
813 scsi_qla_host_t *ha = to_qla_host(host);
817 list_for_each_entry(fcport, &ha->fcports, list) {
818 if (starget->id == fcport->os_target_id) {
819 node_name = wwn_to_u64(fcport->node_name);
824 fc_starget_node_name(starget) = node_name;
828 qla2x00_get_starget_port_name(struct scsi_target *starget)
830 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
831 scsi_qla_host_t *ha = to_qla_host(host);
835 list_for_each_entry(fcport, &ha->fcports, list) {
836 if (starget->id == fcport->os_target_id) {
837 port_name = wwn_to_u64(fcport->port_name);
842 fc_starget_port_name(starget) = port_name;
846 qla2x00_get_starget_port_id(struct scsi_target *starget)
848 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
849 scsi_qla_host_t *ha = to_qla_host(host);
851 uint32_t port_id = ~0U;
853 list_for_each_entry(fcport, &ha->fcports, list) {
854 if (starget->id == fcport->os_target_id) {
855 port_id = fcport->d_id.b.domain << 16 |
856 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
861 fc_starget_port_id(starget) = port_id;
865 qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
867 struct Scsi_Host *host = rport_to_shost(rport);
868 scsi_qla_host_t *ha = to_qla_host(host);
870 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
874 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
876 struct Scsi_Host *host = rport_to_shost(rport);
877 scsi_qla_host_t *ha = to_qla_host(host);
880 ha->port_down_retry_count = timeout;
882 ha->port_down_retry_count = 1;
884 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
888 qla2x00_issue_lip(struct Scsi_Host *shost)
890 scsi_qla_host_t *ha = to_qla_host(shost);
892 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
896 static struct fc_host_statistics *
897 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
899 scsi_qla_host_t *ha = to_qla_host(shost);
902 link_stat_t stat_buf;
903 struct fc_host_statistics *pfc_host_stat;
905 rval = QLA_FUNCTION_FAILED;
906 pfc_host_stat = &ha->fc_host_stat;
907 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
909 if (IS_FWI2_CAPABLE(ha)) {
910 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
911 sizeof(stat_buf) / 4, mb_stat);
912 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
913 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
914 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
916 /* Must be in a 'READY' state for statistics retrieval. */
917 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
921 if (rval != QLA_SUCCESS)
924 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
925 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
926 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
927 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
928 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
929 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
931 return pfc_host_stat;
935 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
937 scsi_qla_host_t *ha = to_qla_host(shost);
939 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
943 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
945 scsi_qla_host_t *ha = to_qla_host(shost);
947 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
951 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
953 scsi_qla_host_t *ha = to_qla_host(shost);
956 if (ha->device_flags & SWITCH_FOUND)
957 node_name = wwn_to_u64(ha->fabric_node_name);
959 node_name = wwn_to_u64(ha->node_name);
961 fc_host_fabric_name(shost) = node_name;
965 qla2x00_get_host_port_state(struct Scsi_Host *shost)
967 scsi_qla_host_t *ha = to_qla_host(shost);
969 if (!ha->flags.online)
970 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
971 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
972 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
974 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
978 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
981 scsi_qla_host_t *ha = (scsi_qla_host_t *) fc_vport->shost->hostdata;
982 scsi_qla_host_t *vha;
984 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
986 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
987 "status %x\n", ret));
991 vha = qla24xx_create_vhost(fc_vport);
993 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
995 return FC_VPORT_FAILED;
998 atomic_set(&vha->vp_state, VP_OFFLINE);
999 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1001 atomic_set(&vha->vp_state, VP_FAILED);
1003 /* ready to create vport */
1004 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1006 /* initialized vport states */
1007 atomic_set(&vha->loop_state, LOOP_DOWN);
1008 vha->vp_err_state= VP_ERR_PORTDWN;
1009 vha->vp_prev_err_state= VP_ERR_UNKWN;
1010 /* Check if physical ha port is Up */
1011 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1012 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1013 /* Don't retry or attempt login of this virtual port */
1014 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1016 atomic_set(&vha->loop_state, LOOP_DEAD);
1018 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1021 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1022 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1023 vha->host_no, vha->vp_idx));
1024 goto vport_create_failed_2;
1027 /* initialize attributes */
1028 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1029 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1030 fc_host_supported_classes(vha->host) =
1031 fc_host_supported_classes(ha->host);
1032 fc_host_supported_speeds(vha->host) =
1033 fc_host_supported_speeds(ha->host);
1035 qla24xx_vport_disable(fc_vport, disable);
1038 vport_create_failed_2:
1039 qla24xx_disable_vp(vha);
1040 qla24xx_deallocate_vp_id(vha);
1041 kfree(vha->port_name);
1042 kfree(vha->node_name);
1043 scsi_host_put(vha->host);
1044 return FC_VPORT_FAILED;
1048 qla24xx_vport_delete(struct fc_vport *fc_vport)
1050 scsi_qla_host_t *ha = (scsi_qla_host_t *) fc_vport->shost->hostdata;
1051 scsi_qla_host_t *vha = fc_vport->dd_data;
1053 qla24xx_disable_vp(vha);
1054 qla24xx_deallocate_vp_id(vha);
1056 down(&ha->vport_sem);
1057 ha->cur_vport_count--;
1058 clear_bit(vha->vp_idx, (unsigned long *)ha->vp_idx_map);
1061 kfree(vha->node_name);
1062 kfree(vha->port_name);
1064 if (vha->timer_active) {
1065 qla2x00_vp_stop_timer(vha);
1066 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1068 vha->host_no, vha->vp_idx, vha));
1071 fc_remove_host(vha->host);
1073 scsi_remove_host(vha->host);
1075 scsi_host_put(vha->host);
1081 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1083 scsi_qla_host_t *vha = fc_vport->dd_data;
1086 qla24xx_disable_vp(vha);
1088 qla24xx_enable_vp(vha);
1093 struct fc_function_template qla2xxx_transport_functions = {
1095 .show_host_node_name = 1,
1096 .show_host_port_name = 1,
1097 .show_host_supported_classes = 1,
1099 .get_host_port_id = qla2x00_get_host_port_id,
1100 .show_host_port_id = 1,
1101 .get_host_speed = qla2x00_get_host_speed,
1102 .show_host_speed = 1,
1103 .get_host_port_type = qla2x00_get_host_port_type,
1104 .show_host_port_type = 1,
1105 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1106 .show_host_symbolic_name = 1,
1107 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1108 .show_host_system_hostname = 1,
1109 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1110 .show_host_fabric_name = 1,
1111 .get_host_port_state = qla2x00_get_host_port_state,
1112 .show_host_port_state = 1,
1114 .dd_fcrport_size = sizeof(struct fc_port *),
1115 .show_rport_supported_classes = 1,
1117 .get_starget_node_name = qla2x00_get_starget_node_name,
1118 .show_starget_node_name = 1,
1119 .get_starget_port_name = qla2x00_get_starget_port_name,
1120 .show_starget_port_name = 1,
1121 .get_starget_port_id = qla2x00_get_starget_port_id,
1122 .show_starget_port_id = 1,
1124 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1125 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1126 .show_rport_dev_loss_tmo = 1,
1128 .issue_fc_host_lip = qla2x00_issue_lip,
1129 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1131 .vport_create = qla24xx_vport_create,
1132 .vport_disable = qla24xx_vport_disable,
1133 .vport_delete = qla24xx_vport_delete,
1136 struct fc_function_template qla2xxx_transport_vport_functions = {
1138 .show_host_node_name = 1,
1139 .show_host_port_name = 1,
1140 .show_host_supported_classes = 1,
1142 .get_host_port_id = qla2x00_get_host_port_id,
1143 .show_host_port_id = 1,
1144 .get_host_speed = qla2x00_get_host_speed,
1145 .show_host_speed = 1,
1146 .get_host_port_type = qla2x00_get_host_port_type,
1147 .show_host_port_type = 1,
1148 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1149 .show_host_symbolic_name = 1,
1150 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1151 .show_host_system_hostname = 1,
1152 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1153 .show_host_fabric_name = 1,
1154 .get_host_port_state = qla2x00_get_host_port_state,
1155 .show_host_port_state = 1,
1157 .dd_fcrport_size = sizeof(struct fc_port *),
1158 .show_rport_supported_classes = 1,
1160 .get_starget_node_name = qla2x00_get_starget_node_name,
1161 .show_starget_node_name = 1,
1162 .get_starget_port_name = qla2x00_get_starget_port_name,
1163 .show_starget_port_name = 1,
1164 .get_starget_port_id = qla2x00_get_starget_port_id,
1165 .show_starget_port_id = 1,
1167 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1168 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1169 .show_rport_dev_loss_tmo = 1,
1171 .issue_fc_host_lip = qla2x00_issue_lip,
1172 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1176 qla2x00_init_host_attr(scsi_qla_host_t *ha)
1178 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1179 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
1180 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
1181 fc_host_max_npiv_vports(ha->host) = MAX_NUM_VPORT_FABRIC;
1182 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;