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 = shost_priv(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 = shost_priv(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 = shost_priv(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 = shost_priv(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 = shost_priv(dev_to_shost(container_of(kobj,
174 struct device, kobj)));
176 if (ha->optrom_state != QLA_SREADING)
178 if (off > ha->optrom_region_size)
180 if (off + count > ha->optrom_region_size)
181 count = ha->optrom_region_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 = shost_priv(dev_to_shost(container_of(kobj,
194 struct device, kobj)));
196 if (ha->optrom_state != QLA_SWRITING)
198 if (off > ha->optrom_region_size)
200 if (off + count > ha->optrom_region_size)
201 count = ha->optrom_region_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 = shost_priv(dev_to_shost(container_of(kobj,
224 struct device, kobj)));
226 uint32_t size = ha->optrom_size;
232 if (sscanf(buf, "%d:%x:%x", &val, &start, &size) < 1)
234 if (start > ha->optrom_size)
239 if (ha->optrom_state != QLA_SREADING &&
240 ha->optrom_state != QLA_SWRITING)
243 ha->optrom_state = QLA_SWAITING;
245 DEBUG2(qla_printk(KERN_INFO, ha,
246 "Freeing flash region allocation -- 0x%x bytes.\n",
247 ha->optrom_region_size));
249 vfree(ha->optrom_buffer);
250 ha->optrom_buffer = NULL;
253 if (ha->optrom_state != QLA_SWAITING)
257 qla_printk(KERN_WARNING, ha,
258 "Invalid start region 0x%x/0x%x.\n", start, size);
262 ha->optrom_region_start = start;
263 ha->optrom_region_size = start + size > ha->optrom_size ?
264 ha->optrom_size - start : size;
266 ha->optrom_state = QLA_SREADING;
267 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
268 if (ha->optrom_buffer == NULL) {
269 qla_printk(KERN_WARNING, ha,
270 "Unable to allocate memory for optrom retrieval "
271 "(%x).\n", ha->optrom_region_size);
273 ha->optrom_state = QLA_SWAITING;
277 DEBUG2(qla_printk(KERN_INFO, ha,
278 "Reading flash region -- 0x%x/0x%x.\n",
279 ha->optrom_region_start, ha->optrom_region_size));
281 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
282 ha->isp_ops->read_optrom(ha, ha->optrom_buffer,
283 ha->optrom_region_start, ha->optrom_region_size);
286 if (ha->optrom_state != QLA_SWAITING)
290 * We need to be more restrictive on which FLASH regions are
291 * allowed to be updated via user-space. Regions accessible
292 * via this method include:
294 * ISP21xx/ISP22xx/ISP23xx type boards:
296 * 0x000000 -> 0x020000 -- Boot code.
298 * ISP2322/ISP24xx type boards:
300 * 0x000000 -> 0x07ffff -- Boot code.
301 * 0x080000 -> 0x0fffff -- Firmware.
303 * ISP25xx type boards:
305 * 0x000000 -> 0x07ffff -- Boot code.
306 * 0x080000 -> 0x0fffff -- Firmware.
307 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
310 if (ha->optrom_size == OPTROM_SIZE_2300 && start == 0)
312 else if (start == (FA_BOOT_CODE_ADDR*4) ||
313 start == (FA_RISC_CODE_ADDR*4))
315 else if (IS_QLA25XX(ha) && start == (FA_VPD_NVRAM_ADDR*4))
318 qla_printk(KERN_WARNING, ha,
319 "Invalid start region 0x%x/0x%x.\n", start, size);
323 ha->optrom_region_start = start;
324 ha->optrom_region_size = start + size > ha->optrom_size ?
325 ha->optrom_size - start : size;
327 ha->optrom_state = QLA_SWRITING;
328 ha->optrom_buffer = vmalloc(ha->optrom_region_size);
329 if (ha->optrom_buffer == NULL) {
330 qla_printk(KERN_WARNING, ha,
331 "Unable to allocate memory for optrom update "
332 "(%x).\n", ha->optrom_region_size);
334 ha->optrom_state = QLA_SWAITING;
338 DEBUG2(qla_printk(KERN_INFO, ha,
339 "Staging flash region write -- 0x%x/0x%x.\n",
340 ha->optrom_region_start, ha->optrom_region_size));
342 memset(ha->optrom_buffer, 0, ha->optrom_region_size);
345 if (ha->optrom_state != QLA_SWRITING)
348 DEBUG2(qla_printk(KERN_INFO, ha,
349 "Writing flash region -- 0x%x/0x%x.\n",
350 ha->optrom_region_start, ha->optrom_region_size));
352 ha->isp_ops->write_optrom(ha, ha->optrom_buffer,
353 ha->optrom_region_start, ha->optrom_region_size);
361 static struct bin_attribute sysfs_optrom_ctl_attr = {
363 .name = "optrom_ctl",
367 .write = qla2x00_sysfs_write_optrom_ctl,
371 qla2x00_sysfs_read_vpd(struct kobject *kobj,
372 struct bin_attribute *bin_attr,
373 char *buf, loff_t off, size_t count)
375 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
376 struct device, kobj)));
377 int size = ha->vpd_size;
378 char *vpd_cache = ha->vpd;
380 if (!capable(CAP_SYS_ADMIN) || off > size || count == 0)
382 if (off + count > size) {
387 /* Read NVRAM data from cache. */
388 memcpy(buf, &vpd_cache[off], count);
394 qla2x00_sysfs_write_vpd(struct kobject *kobj,
395 struct bin_attribute *bin_attr,
396 char *buf, loff_t off, size_t count)
398 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
399 struct device, kobj)));
402 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->vpd_size)
406 spin_lock_irqsave(&ha->hardware_lock, flags);
407 ha->isp_ops->write_nvram(ha, (uint8_t *)buf, ha->vpd_base, count);
408 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd, ha->vpd_base, count);
409 spin_unlock_irqrestore(&ha->hardware_lock, flags);
414 static struct bin_attribute sysfs_vpd_attr = {
417 .mode = S_IRUSR | S_IWUSR,
420 .read = qla2x00_sysfs_read_vpd,
421 .write = qla2x00_sysfs_write_vpd,
425 qla2x00_sysfs_read_sfp(struct kobject *kobj,
426 struct bin_attribute *bin_attr,
427 char *buf, loff_t off, size_t count)
429 struct scsi_qla_host *ha = shost_priv(dev_to_shost(container_of(kobj,
430 struct device, kobj)));
431 uint16_t iter, addr, offset;
434 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != SFP_DEV_SIZE * 2)
438 for (iter = 0, offset = 0; iter < (SFP_DEV_SIZE * 2) / SFP_BLOCK_SIZE;
439 iter++, offset += SFP_BLOCK_SIZE) {
441 /* Skip to next device address. */
446 rval = qla2x00_read_sfp(ha, ha->sfp_data_dma, addr, offset,
448 if (rval != QLA_SUCCESS) {
449 qla_printk(KERN_WARNING, ha,
450 "Unable to read SFP data (%x/%x/%x).\n", rval,
455 memcpy(buf, ha->sfp_data, SFP_BLOCK_SIZE);
456 buf += SFP_BLOCK_SIZE;
462 static struct bin_attribute sysfs_sfp_attr = {
465 .mode = S_IRUSR | S_IWUSR,
467 .size = SFP_DEV_SIZE * 2,
468 .read = qla2x00_sysfs_read_sfp,
471 static struct sysfs_entry {
473 struct bin_attribute *attr;
475 } bin_file_entries[] = {
476 { "fw_dump", &sysfs_fw_dump_attr, },
477 { "nvram", &sysfs_nvram_attr, },
478 { "optrom", &sysfs_optrom_attr, },
479 { "optrom_ctl", &sysfs_optrom_ctl_attr, },
480 { "vpd", &sysfs_vpd_attr, 1 },
481 { "sfp", &sysfs_sfp_attr, 1 },
486 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
488 struct Scsi_Host *host = ha->host;
489 struct sysfs_entry *iter;
492 for (iter = bin_file_entries; iter->name; iter++) {
493 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
496 ret = sysfs_create_bin_file(&host->shost_gendev.kobj,
499 qla_printk(KERN_INFO, ha,
500 "Unable to create sysfs %s binary attribute "
501 "(%d).\n", iter->name, ret);
506 qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
508 struct Scsi_Host *host = ha->host;
509 struct sysfs_entry *iter;
511 for (iter = bin_file_entries; iter->name; iter++) {
512 if (iter->is4GBp_only && !IS_FWI2_CAPABLE(ha))
515 sysfs_remove_bin_file(&host->shost_gendev.kobj,
519 if (ha->beacon_blink_led == 1)
520 ha->isp_ops->beacon_off(ha);
523 /* Scsi_Host attributes. */
526 qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
528 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
532 qla2x00_fw_version_show(struct class_device *cdev, char *buf)
534 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
537 return snprintf(buf, PAGE_SIZE, "%s\n",
538 ha->isp_ops->fw_version_str(ha, fw_str));
542 qla2x00_serial_num_show(struct class_device *cdev, char *buf)
544 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
547 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
548 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
553 qla2x00_isp_name_show(struct class_device *cdev, char *buf)
555 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
556 return snprintf(buf, PAGE_SIZE, "ISP%04X\n", ha->pdev->device);
560 qla2x00_isp_id_show(struct class_device *cdev, char *buf)
562 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
563 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
564 ha->product_id[0], ha->product_id[1], ha->product_id[2],
569 qla2x00_model_name_show(struct class_device *cdev, char *buf)
571 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
572 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
576 qla2x00_model_desc_show(struct class_device *cdev, char *buf)
578 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
579 return snprintf(buf, PAGE_SIZE, "%s\n",
580 ha->model_desc ? ha->model_desc: "");
584 qla2x00_pci_info_show(struct class_device *cdev, char *buf)
586 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
589 return snprintf(buf, PAGE_SIZE, "%s\n",
590 ha->isp_ops->pci_info_str(ha, pci_info));
594 qla2x00_state_show(struct class_device *cdev, char *buf)
596 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
599 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
600 atomic_read(&ha->loop_state) == LOOP_DEAD)
601 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
602 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
603 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
604 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
605 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
607 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
609 switch (ha->current_topology) {
611 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
614 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
617 len += snprintf(buf + len, PAGE_SIZE-len,
618 "N_Port to N_Port\n");
621 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
624 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
632 qla2x00_zio_show(struct class_device *cdev, char *buf)
634 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
637 switch (ha->zio_mode) {
639 len += snprintf(buf + len, PAGE_SIZE-len, "Mode 6\n");
641 case QLA_ZIO_DISABLED:
642 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
649 qla2x00_zio_store(struct class_device *cdev, const char *buf, size_t count)
651 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
655 if (!IS_ZIO_SUPPORTED(ha))
658 if (sscanf(buf, "%d", &val) != 1)
662 zio_mode = QLA_ZIO_MODE_6;
664 zio_mode = QLA_ZIO_DISABLED;
666 /* Update per-hba values and queue a reset. */
667 if (zio_mode != QLA_ZIO_DISABLED || ha->zio_mode != QLA_ZIO_DISABLED) {
668 ha->zio_mode = zio_mode;
669 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
675 qla2x00_zio_timer_show(struct class_device *cdev, char *buf)
677 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
679 return snprintf(buf, PAGE_SIZE, "%d us\n", ha->zio_timer * 100);
683 qla2x00_zio_timer_store(struct class_device *cdev, const char *buf,
686 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
690 if (sscanf(buf, "%d", &val) != 1)
692 if (val > 25500 || val < 100)
695 zio_timer = (uint16_t)(val / 100);
696 ha->zio_timer = zio_timer;
702 qla2x00_beacon_show(struct class_device *cdev, char *buf)
704 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
707 if (ha->beacon_blink_led)
708 len += snprintf(buf + len, PAGE_SIZE-len, "Enabled\n");
710 len += snprintf(buf + len, PAGE_SIZE-len, "Disabled\n");
715 qla2x00_beacon_store(struct class_device *cdev, const char *buf,
718 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
722 if (IS_QLA2100(ha) || IS_QLA2200(ha))
725 if (test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags)) {
726 qla_printk(KERN_WARNING, ha,
727 "Abort ISP active -- ignoring beacon request.\n");
731 if (sscanf(buf, "%d", &val) != 1)
735 rval = ha->isp_ops->beacon_on(ha);
737 rval = ha->isp_ops->beacon_off(ha);
739 if (rval != QLA_SUCCESS)
746 qla2x00_optrom_bios_version_show(struct class_device *cdev, char *buf)
748 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
750 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->bios_revision[1],
751 ha->bios_revision[0]);
755 qla2x00_optrom_efi_version_show(struct class_device *cdev, char *buf)
757 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
759 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->efi_revision[1],
760 ha->efi_revision[0]);
764 qla2x00_optrom_fcode_version_show(struct class_device *cdev, char *buf)
766 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
768 return snprintf(buf, PAGE_SIZE, "%d.%02d\n", ha->fcode_revision[1],
769 ha->fcode_revision[0]);
773 qla2x00_optrom_fw_version_show(struct class_device *cdev, char *buf)
775 scsi_qla_host_t *ha = shost_priv(class_to_shost(cdev));
777 return snprintf(buf, PAGE_SIZE, "%d.%02d.%02d %d\n",
778 ha->fw_revision[0], ha->fw_revision[1], ha->fw_revision[2],
782 static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
784 static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
785 static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
786 static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
787 static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
788 static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
789 static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
790 static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
791 static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
792 static CLASS_DEVICE_ATTR(zio, S_IRUGO | S_IWUSR, qla2x00_zio_show,
794 static CLASS_DEVICE_ATTR(zio_timer, S_IRUGO | S_IWUSR, qla2x00_zio_timer_show,
795 qla2x00_zio_timer_store);
796 static CLASS_DEVICE_ATTR(beacon, S_IRUGO | S_IWUSR, qla2x00_beacon_show,
797 qla2x00_beacon_store);
798 static CLASS_DEVICE_ATTR(optrom_bios_version, S_IRUGO,
799 qla2x00_optrom_bios_version_show, NULL);
800 static CLASS_DEVICE_ATTR(optrom_efi_version, S_IRUGO,
801 qla2x00_optrom_efi_version_show, NULL);
802 static CLASS_DEVICE_ATTR(optrom_fcode_version, S_IRUGO,
803 qla2x00_optrom_fcode_version_show, NULL);
804 static CLASS_DEVICE_ATTR(optrom_fw_version, S_IRUGO,
805 qla2x00_optrom_fw_version_show, NULL);
807 struct class_device_attribute *qla2x00_host_attrs[] = {
808 &class_device_attr_driver_version,
809 &class_device_attr_fw_version,
810 &class_device_attr_serial_num,
811 &class_device_attr_isp_name,
812 &class_device_attr_isp_id,
813 &class_device_attr_model_name,
814 &class_device_attr_model_desc,
815 &class_device_attr_pci_info,
816 &class_device_attr_state,
817 &class_device_attr_zio,
818 &class_device_attr_zio_timer,
819 &class_device_attr_beacon,
820 &class_device_attr_optrom_bios_version,
821 &class_device_attr_optrom_efi_version,
822 &class_device_attr_optrom_fcode_version,
823 &class_device_attr_optrom_fw_version,
827 /* Host attributes. */
830 qla2x00_get_host_port_id(struct Scsi_Host *shost)
832 scsi_qla_host_t *ha = shost_priv(shost);
834 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
835 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
839 qla2x00_get_host_speed(struct Scsi_Host *shost)
841 scsi_qla_host_t *ha = shost_priv(shost);
844 switch (ha->link_data_rate) {
855 fc_host_speed(shost) = speed;
859 qla2x00_get_host_port_type(struct Scsi_Host *shost)
861 scsi_qla_host_t *ha = shost_priv(shost);
862 uint32_t port_type = FC_PORTTYPE_UNKNOWN;
864 switch (ha->current_topology) {
866 port_type = FC_PORTTYPE_LPORT;
869 port_type = FC_PORTTYPE_NLPORT;
872 port_type = FC_PORTTYPE_PTP;
875 port_type = FC_PORTTYPE_NPORT;
878 fc_host_port_type(shost) = port_type;
882 qla2x00_get_starget_node_name(struct scsi_target *starget)
884 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
885 scsi_qla_host_t *ha = shost_priv(host);
889 list_for_each_entry(fcport, &ha->fcports, list) {
890 if (starget->id == fcport->os_target_id) {
891 node_name = wwn_to_u64(fcport->node_name);
896 fc_starget_node_name(starget) = node_name;
900 qla2x00_get_starget_port_name(struct scsi_target *starget)
902 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
903 scsi_qla_host_t *ha = shost_priv(host);
907 list_for_each_entry(fcport, &ha->fcports, list) {
908 if (starget->id == fcport->os_target_id) {
909 port_name = wwn_to_u64(fcport->port_name);
914 fc_starget_port_name(starget) = port_name;
918 qla2x00_get_starget_port_id(struct scsi_target *starget)
920 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
921 scsi_qla_host_t *ha = shost_priv(host);
923 uint32_t port_id = ~0U;
925 list_for_each_entry(fcport, &ha->fcports, list) {
926 if (starget->id == fcport->os_target_id) {
927 port_id = fcport->d_id.b.domain << 16 |
928 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
933 fc_starget_port_id(starget) = port_id;
937 qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
939 struct Scsi_Host *host = rport_to_shost(rport);
940 scsi_qla_host_t *ha = shost_priv(host);
942 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
946 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
948 struct Scsi_Host *host = rport_to_shost(rport);
949 scsi_qla_host_t *ha = shost_priv(host);
952 ha->port_down_retry_count = timeout;
954 ha->port_down_retry_count = 1;
956 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
960 qla2x00_issue_lip(struct Scsi_Host *shost)
962 scsi_qla_host_t *ha = shost_priv(shost);
964 set_bit(LOOP_RESET_NEEDED, &ha->dpc_flags);
968 static struct fc_host_statistics *
969 qla2x00_get_fc_host_stats(struct Scsi_Host *shost)
971 scsi_qla_host_t *ha = shost_priv(shost);
974 link_stat_t stat_buf;
975 struct fc_host_statistics *pfc_host_stat;
977 rval = QLA_FUNCTION_FAILED;
978 pfc_host_stat = &ha->fc_host_stat;
979 memset(pfc_host_stat, -1, sizeof(struct fc_host_statistics));
981 if (IS_FWI2_CAPABLE(ha)) {
982 rval = qla24xx_get_isp_stats(ha, (uint32_t *)&stat_buf,
983 sizeof(stat_buf) / 4, mb_stat);
984 } else if (atomic_read(&ha->loop_state) == LOOP_READY &&
985 !test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) &&
986 !test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags) &&
988 /* Must be in a 'READY' state for statistics retrieval. */
989 rval = qla2x00_get_link_status(ha, ha->loop_id, &stat_buf,
993 if (rval != QLA_SUCCESS)
996 pfc_host_stat->link_failure_count = stat_buf.link_fail_cnt;
997 pfc_host_stat->loss_of_sync_count = stat_buf.loss_sync_cnt;
998 pfc_host_stat->loss_of_signal_count = stat_buf.loss_sig_cnt;
999 pfc_host_stat->prim_seq_protocol_err_count = stat_buf.prim_seq_err_cnt;
1000 pfc_host_stat->invalid_tx_word_count = stat_buf.inval_xmit_word_cnt;
1001 pfc_host_stat->invalid_crc_count = stat_buf.inval_crc_cnt;
1003 return pfc_host_stat;
1007 qla2x00_get_host_symbolic_name(struct Scsi_Host *shost)
1009 scsi_qla_host_t *ha = shost_priv(shost);
1011 qla2x00_get_sym_node_name(ha, fc_host_symbolic_name(shost));
1015 qla2x00_set_host_system_hostname(struct Scsi_Host *shost)
1017 scsi_qla_host_t *ha = shost_priv(shost);
1019 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
1023 qla2x00_get_host_fabric_name(struct Scsi_Host *shost)
1025 scsi_qla_host_t *ha = shost_priv(shost);
1028 if (ha->device_flags & SWITCH_FOUND)
1029 node_name = wwn_to_u64(ha->fabric_node_name);
1031 node_name = wwn_to_u64(ha->node_name);
1033 fc_host_fabric_name(shost) = node_name;
1037 qla2x00_get_host_port_state(struct Scsi_Host *shost)
1039 scsi_qla_host_t *ha = shost_priv(shost);
1041 if (!ha->flags.online)
1042 fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE;
1043 else if (atomic_read(&ha->loop_state) == LOOP_TIMEOUT)
1044 fc_host_port_state(shost) = FC_PORTSTATE_UNKNOWN;
1046 fc_host_port_state(shost) = FC_PORTSTATE_ONLINE;
1050 qla24xx_vport_create(struct fc_vport *fc_vport, bool disable)
1053 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
1054 scsi_qla_host_t *vha;
1056 ret = qla24xx_vport_create_req_sanity_check(fc_vport);
1058 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1059 "status %x\n", ret));
1063 vha = qla24xx_create_vhost(fc_vport);
1065 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1067 return FC_VPORT_FAILED;
1070 atomic_set(&vha->vp_state, VP_OFFLINE);
1071 fc_vport_set_state(fc_vport, FC_VPORT_DISABLED);
1073 atomic_set(&vha->vp_state, VP_FAILED);
1075 /* ready to create vport */
1076 qla_printk(KERN_INFO, vha, "VP entry id %d assigned.\n", vha->vp_idx);
1078 /* initialized vport states */
1079 atomic_set(&vha->loop_state, LOOP_DOWN);
1080 vha->vp_err_state= VP_ERR_PORTDWN;
1081 vha->vp_prev_err_state= VP_ERR_UNKWN;
1082 /* Check if physical ha port is Up */
1083 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
1084 atomic_read(&ha->loop_state) == LOOP_DEAD) {
1085 /* Don't retry or attempt login of this virtual port */
1086 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1088 atomic_set(&vha->loop_state, LOOP_DEAD);
1090 fc_vport_set_state(fc_vport, FC_VPORT_LINKDOWN);
1093 if (scsi_add_host(vha->host, &fc_vport->dev)) {
1094 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1095 vha->host_no, vha->vp_idx));
1096 goto vport_create_failed_2;
1099 /* initialize attributes */
1100 fc_host_node_name(vha->host) = wwn_to_u64(vha->node_name);
1101 fc_host_port_name(vha->host) = wwn_to_u64(vha->port_name);
1102 fc_host_supported_classes(vha->host) =
1103 fc_host_supported_classes(ha->host);
1104 fc_host_supported_speeds(vha->host) =
1105 fc_host_supported_speeds(ha->host);
1107 qla24xx_vport_disable(fc_vport, disable);
1110 vport_create_failed_2:
1111 qla24xx_disable_vp(vha);
1112 qla24xx_deallocate_vp_id(vha);
1113 kfree(vha->port_name);
1114 kfree(vha->node_name);
1115 scsi_host_put(vha->host);
1116 return FC_VPORT_FAILED;
1120 qla24xx_vport_delete(struct fc_vport *fc_vport)
1122 scsi_qla_host_t *ha = shost_priv(fc_vport->shost);
1123 scsi_qla_host_t *vha = fc_vport->dd_data;
1125 qla24xx_disable_vp(vha);
1126 qla24xx_deallocate_vp_id(vha);
1128 down(&ha->vport_sem);
1129 ha->cur_vport_count--;
1130 clear_bit(vha->vp_idx, (unsigned long *)ha->vp_idx_map);
1133 kfree(vha->node_name);
1134 kfree(vha->port_name);
1136 if (vha->timer_active) {
1137 qla2x00_vp_stop_timer(vha);
1138 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1140 vha->host_no, vha->vp_idx, vha));
1143 fc_remove_host(vha->host);
1145 scsi_remove_host(vha->host);
1147 scsi_host_put(vha->host);
1153 qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
1155 scsi_qla_host_t *vha = fc_vport->dd_data;
1158 qla24xx_disable_vp(vha);
1160 qla24xx_enable_vp(vha);
1165 struct fc_function_template qla2xxx_transport_functions = {
1167 .show_host_node_name = 1,
1168 .show_host_port_name = 1,
1169 .show_host_supported_classes = 1,
1171 .get_host_port_id = qla2x00_get_host_port_id,
1172 .show_host_port_id = 1,
1173 .get_host_speed = qla2x00_get_host_speed,
1174 .show_host_speed = 1,
1175 .get_host_port_type = qla2x00_get_host_port_type,
1176 .show_host_port_type = 1,
1177 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1178 .show_host_symbolic_name = 1,
1179 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1180 .show_host_system_hostname = 1,
1181 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1182 .show_host_fabric_name = 1,
1183 .get_host_port_state = qla2x00_get_host_port_state,
1184 .show_host_port_state = 1,
1186 .dd_fcrport_size = sizeof(struct fc_port *),
1187 .show_rport_supported_classes = 1,
1189 .get_starget_node_name = qla2x00_get_starget_node_name,
1190 .show_starget_node_name = 1,
1191 .get_starget_port_name = qla2x00_get_starget_port_name,
1192 .show_starget_port_name = 1,
1193 .get_starget_port_id = qla2x00_get_starget_port_id,
1194 .show_starget_port_id = 1,
1196 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1197 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1198 .show_rport_dev_loss_tmo = 1,
1200 .issue_fc_host_lip = qla2x00_issue_lip,
1201 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1203 .vport_create = qla24xx_vport_create,
1204 .vport_disable = qla24xx_vport_disable,
1205 .vport_delete = qla24xx_vport_delete,
1208 struct fc_function_template qla2xxx_transport_vport_functions = {
1210 .show_host_node_name = 1,
1211 .show_host_port_name = 1,
1212 .show_host_supported_classes = 1,
1214 .get_host_port_id = qla2x00_get_host_port_id,
1215 .show_host_port_id = 1,
1216 .get_host_speed = qla2x00_get_host_speed,
1217 .show_host_speed = 1,
1218 .get_host_port_type = qla2x00_get_host_port_type,
1219 .show_host_port_type = 1,
1220 .get_host_symbolic_name = qla2x00_get_host_symbolic_name,
1221 .show_host_symbolic_name = 1,
1222 .set_host_system_hostname = qla2x00_set_host_system_hostname,
1223 .show_host_system_hostname = 1,
1224 .get_host_fabric_name = qla2x00_get_host_fabric_name,
1225 .show_host_fabric_name = 1,
1226 .get_host_port_state = qla2x00_get_host_port_state,
1227 .show_host_port_state = 1,
1229 .dd_fcrport_size = sizeof(struct fc_port *),
1230 .show_rport_supported_classes = 1,
1232 .get_starget_node_name = qla2x00_get_starget_node_name,
1233 .show_starget_node_name = 1,
1234 .get_starget_port_name = qla2x00_get_starget_port_name,
1235 .show_starget_port_name = 1,
1236 .get_starget_port_id = qla2x00_get_starget_port_id,
1237 .show_starget_port_id = 1,
1239 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
1240 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
1241 .show_rport_dev_loss_tmo = 1,
1243 .issue_fc_host_lip = qla2x00_issue_lip,
1244 .get_fc_host_stats = qla2x00_get_fc_host_stats,
1248 qla2x00_init_host_attr(scsi_qla_host_t *ha)
1250 fc_host_node_name(ha->host) = wwn_to_u64(ha->node_name);
1251 fc_host_port_name(ha->host) = wwn_to_u64(ha->port_name);
1252 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;
1253 fc_host_max_npiv_vports(ha->host) = ha->max_npiv_vports;;
1254 fc_host_npiv_vports_inuse(ha->host) = ha->cur_vport_count;