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
,
79 .read
= qla2x00_sysfs_read_fw_dump
,
80 .write
= qla2x00_sysfs_write_fw_dump
,
84 qla2x00_sysfs_read_nvram(struct kobject
*kobj
, char *buf
, loff_t off
,
87 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
88 struct device
, kobj
)));
91 if (!capable(CAP_SYS_ADMIN
) || off
!= 0)
95 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
96 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)buf
, ha
->nvram_base
,
98 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
100 return ha
->nvram_size
;
104 qla2x00_sysfs_write_nvram(struct kobject
*kobj
, char *buf
, loff_t off
,
107 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
108 struct device
, kobj
)));
112 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->nvram_size
)
115 /* Checksum NVRAM. */
116 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
)) {
120 iter
= (uint32_t *)buf
;
122 for (cnt
= 0; cnt
< ((count
>> 2) - 1); cnt
++)
123 chksum
+= le32_to_cpu(*iter
++);
124 chksum
= ~chksum
+ 1;
125 *iter
= cpu_to_le32(chksum
);
130 iter
= (uint8_t *)buf
;
132 for (cnt
= 0; cnt
< count
- 1; cnt
++)
134 chksum
= ~chksum
+ 1;
139 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
140 ha
->isp_ops
.write_nvram(ha
, (uint8_t *)buf
, ha
->nvram_base
, count
);
141 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
143 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
148 static struct bin_attribute sysfs_nvram_attr
= {
151 .mode
= S_IRUSR
| S_IWUSR
,
152 .owner
= THIS_MODULE
,
155 .read
= qla2x00_sysfs_read_nvram
,
156 .write
= qla2x00_sysfs_write_nvram
,
160 qla2x00_sysfs_read_optrom(struct kobject
*kobj
, char *buf
, loff_t off
,
163 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
164 struct device
, kobj
)));
166 if (ha
->optrom_state
!= QLA_SREADING
)
168 if (off
> ha
->optrom_size
)
170 if (off
+ count
> ha
->optrom_size
)
171 count
= ha
->optrom_size
- off
;
173 memcpy(buf
, &ha
->optrom_buffer
[off
], count
);
179 qla2x00_sysfs_write_optrom(struct kobject
*kobj
, char *buf
, loff_t off
,
182 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
183 struct device
, kobj
)));
185 if (ha
->optrom_state
!= QLA_SWRITING
)
187 if (off
> ha
->optrom_size
)
189 if (off
+ count
> ha
->optrom_size
)
190 count
= ha
->optrom_size
- off
;
192 memcpy(&ha
->optrom_buffer
[off
], buf
, count
);
197 static struct bin_attribute sysfs_optrom_attr
= {
200 .mode
= S_IRUSR
| S_IWUSR
,
201 .owner
= THIS_MODULE
,
203 .size
= OPTROM_SIZE_24XX
,
204 .read
= qla2x00_sysfs_read_optrom
,
205 .write
= qla2x00_sysfs_write_optrom
,
209 qla2x00_sysfs_write_optrom_ctl(struct kobject
*kobj
, char *buf
, loff_t off
,
212 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
213 struct device
, kobj
)));
219 if (sscanf(buf
, "%d", &val
) != 1)
224 if (ha
->optrom_state
!= QLA_SREADING
&&
225 ha
->optrom_state
!= QLA_SWRITING
)
228 ha
->optrom_state
= QLA_SWAITING
;
229 vfree(ha
->optrom_buffer
);
230 ha
->optrom_buffer
= NULL
;
233 if (ha
->optrom_state
!= QLA_SWAITING
)
236 ha
->optrom_state
= QLA_SREADING
;
237 ha
->optrom_buffer
= (uint8_t *)vmalloc(ha
->optrom_size
);
238 if (ha
->optrom_buffer
== NULL
) {
239 qla_printk(KERN_WARNING
, ha
,
240 "Unable to allocate memory for optrom retrieval "
241 "(%x).\n", ha
->optrom_size
);
243 ha
->optrom_state
= QLA_SWAITING
;
247 memset(ha
->optrom_buffer
, 0, ha
->optrom_size
);
248 ha
->isp_ops
.read_optrom(ha
, ha
->optrom_buffer
, 0,
252 if (ha
->optrom_state
!= QLA_SWAITING
)
255 ha
->optrom_state
= QLA_SWRITING
;
256 ha
->optrom_buffer
= (uint8_t *)vmalloc(ha
->optrom_size
);
257 if (ha
->optrom_buffer
== NULL
) {
258 qla_printk(KERN_WARNING
, ha
,
259 "Unable to allocate memory for optrom update "
260 "(%x).\n", ha
->optrom_size
);
262 ha
->optrom_state
= QLA_SWAITING
;
265 memset(ha
->optrom_buffer
, 0, ha
->optrom_size
);
268 if (ha
->optrom_state
!= QLA_SWRITING
)
271 ha
->isp_ops
.write_optrom(ha
, ha
->optrom_buffer
, 0,
278 static struct bin_attribute sysfs_optrom_ctl_attr
= {
280 .name
= "optrom_ctl",
282 .owner
= THIS_MODULE
,
285 .write
= qla2x00_sysfs_write_optrom_ctl
,
289 qla2x00_sysfs_read_vpd(struct kobject
*kobj
, char *buf
, loff_t off
,
292 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
293 struct device
, kobj
)));
296 if (!capable(CAP_SYS_ADMIN
) || off
!= 0)
300 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
301 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)buf
, ha
->vpd_base
, ha
->vpd_size
);
302 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
308 qla2x00_sysfs_write_vpd(struct kobject
*kobj
, char *buf
, loff_t off
,
311 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
312 struct device
, kobj
)));
315 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->vpd_size
)
319 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
320 ha
->isp_ops
.write_nvram(ha
, (uint8_t *)buf
, ha
->vpd_base
, count
);
321 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
326 static struct bin_attribute sysfs_vpd_attr
= {
329 .mode
= S_IRUSR
| S_IWUSR
,
330 .owner
= THIS_MODULE
,
333 .read
= qla2x00_sysfs_read_vpd
,
334 .write
= qla2x00_sysfs_write_vpd
,
338 qla2x00_sysfs_read_sfp(struct kobject
*kobj
, char *buf
, loff_t off
,
341 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
342 struct device
, kobj
)));
343 uint16_t iter
, addr
, offset
;
346 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= SFP_DEV_SIZE
* 2)
350 for (iter
= 0, offset
= 0; iter
< (SFP_DEV_SIZE
* 2) / SFP_BLOCK_SIZE
;
351 iter
++, offset
+= SFP_BLOCK_SIZE
) {
353 /* Skip to next device address. */
358 rval
= qla2x00_read_sfp(ha
, ha
->sfp_data_dma
, addr
, offset
,
360 if (rval
!= QLA_SUCCESS
) {
361 qla_printk(KERN_WARNING
, ha
,
362 "Unable to read SFP data (%x/%x/%x).\n", rval
,
367 memcpy(buf
, ha
->sfp_data
, SFP_BLOCK_SIZE
);
368 buf
+= SFP_BLOCK_SIZE
;
374 static struct bin_attribute sysfs_sfp_attr
= {
377 .mode
= S_IRUSR
| S_IWUSR
,
378 .owner
= THIS_MODULE
,
380 .size
= SFP_DEV_SIZE
* 2,
381 .read
= qla2x00_sysfs_read_sfp
,
384 static struct sysfs_entry
{
386 struct bin_attribute
*attr
;
388 } bin_file_entries
[] = {
389 { "fw_dump", &sysfs_fw_dump_attr
, },
390 { "nvram", &sysfs_nvram_attr
, },
391 { "optrom", &sysfs_optrom_attr
, },
392 { "optrom_ctl", &sysfs_optrom_ctl_attr
, },
393 { "vpd", &sysfs_vpd_attr
, 1 },
394 { "sfp", &sysfs_sfp_attr
, 1 },
399 qla2x00_alloc_sysfs_attr(scsi_qla_host_t
*ha
)
401 struct Scsi_Host
*host
= ha
->host
;
402 struct sysfs_entry
*iter
;
405 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
406 if (iter
->is4GBp_only
&& (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)))
409 ret
= sysfs_create_bin_file(&host
->shost_gendev
.kobj
,
412 qla_printk(KERN_INFO
, ha
,
413 "Unable to create sysfs %s binary attribute "
414 "(%d).\n", iter
->name
, ret
);
419 qla2x00_free_sysfs_attr(scsi_qla_host_t
*ha
)
421 struct Scsi_Host
*host
= ha
->host
;
422 struct sysfs_entry
*iter
;
424 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
425 if (iter
->is4GBp_only
&& (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)))
428 sysfs_remove_bin_file(&host
->shost_gendev
.kobj
,
432 if (ha
->beacon_blink_led
== 1)
433 ha
->isp_ops
.beacon_off(ha
);
436 /* Scsi_Host attributes. */
439 qla2x00_drvr_version_show(struct class_device
*cdev
, char *buf
)
441 return snprintf(buf
, PAGE_SIZE
, "%s\n", qla2x00_version_str
);
445 qla2x00_fw_version_show(struct class_device
*cdev
, char *buf
)
447 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
450 return snprintf(buf
, PAGE_SIZE
, "%s\n",
451 ha
->isp_ops
.fw_version_str(ha
, fw_str
));
455 qla2x00_serial_num_show(struct class_device
*cdev
, char *buf
)
457 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
460 sn
= ((ha
->serial0
& 0x1f) << 16) | (ha
->serial2
<< 8) | ha
->serial1
;
461 return snprintf(buf
, PAGE_SIZE
, "%c%05d\n", 'A' + sn
/ 100000,
466 qla2x00_isp_name_show(struct class_device
*cdev
, char *buf
)
468 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
469 return snprintf(buf
, PAGE_SIZE
, "ISP%04X\n", ha
->pdev
->device
);
473 qla2x00_isp_id_show(struct class_device
*cdev
, char *buf
)
475 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
476 return snprintf(buf
, PAGE_SIZE
, "%04x %04x %04x %04x\n",
477 ha
->product_id
[0], ha
->product_id
[1], ha
->product_id
[2],
482 qla2x00_model_name_show(struct class_device
*cdev
, char *buf
)
484 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
485 return snprintf(buf
, PAGE_SIZE
, "%s\n", ha
->model_number
);
489 qla2x00_model_desc_show(struct class_device
*cdev
, char *buf
)
491 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
492 return snprintf(buf
, PAGE_SIZE
, "%s\n",
493 ha
->model_desc
? ha
->model_desc
: "");
497 qla2x00_pci_info_show(struct class_device
*cdev
, char *buf
)
499 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
502 return snprintf(buf
, PAGE_SIZE
, "%s\n",
503 ha
->isp_ops
.pci_info_str(ha
, pci_info
));
507 qla2x00_state_show(struct class_device
*cdev
, char *buf
)
509 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
512 if (atomic_read(&ha
->loop_state
) == LOOP_DOWN
||
513 atomic_read(&ha
->loop_state
) == LOOP_DEAD
)
514 len
= snprintf(buf
, PAGE_SIZE
, "Link Down\n");
515 else if (atomic_read(&ha
->loop_state
) != LOOP_READY
||
516 test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) ||
517 test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
))
518 len
= snprintf(buf
, PAGE_SIZE
, "Unknown Link State\n");
520 len
= snprintf(buf
, PAGE_SIZE
, "Link Up - ");
522 switch (ha
->current_topology
) {
524 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
527 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "FL_Port\n");
530 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
531 "N_Port to N_Port\n");
534 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "F_Port\n");
537 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
545 qla2x00_zio_show(struct class_device
*cdev
, char *buf
)
547 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
550 switch (ha
->zio_mode
) {
552 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Mode 6\n");
554 case QLA_ZIO_DISABLED
:
555 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
562 qla2x00_zio_store(struct class_device
*cdev
, const char *buf
, size_t count
)
564 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
568 if (!IS_ZIO_SUPPORTED(ha
))
571 if (sscanf(buf
, "%d", &val
) != 1)
575 zio_mode
= QLA_ZIO_MODE_6
;
577 zio_mode
= QLA_ZIO_DISABLED
;
579 /* Update per-hba values and queue a reset. */
580 if (zio_mode
!= QLA_ZIO_DISABLED
|| ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
581 ha
->zio_mode
= zio_mode
;
582 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
588 qla2x00_zio_timer_show(struct class_device
*cdev
, char *buf
)
590 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
592 return snprintf(buf
, PAGE_SIZE
, "%d us\n", ha
->zio_timer
* 100);
596 qla2x00_zio_timer_store(struct class_device
*cdev
, const char *buf
,
599 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
603 if (sscanf(buf
, "%d", &val
) != 1)
605 if (val
> 25500 || val
< 100)
608 zio_timer
= (uint16_t)(val
/ 100);
609 ha
->zio_timer
= zio_timer
;
615 qla2x00_beacon_show(struct class_device
*cdev
, char *buf
)
617 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
620 if (ha
->beacon_blink_led
)
621 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Enabled\n");
623 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
628 qla2x00_beacon_store(struct class_device
*cdev
, const char *buf
,
631 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
635 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
638 if (test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)) {
639 qla_printk(KERN_WARNING
, ha
,
640 "Abort ISP active -- ignoring beacon request.\n");
644 if (sscanf(buf
, "%d", &val
) != 1)
648 rval
= ha
->isp_ops
.beacon_on(ha
);
650 rval
= ha
->isp_ops
.beacon_off(ha
);
652 if (rval
!= QLA_SUCCESS
)
659 qla2x00_optrom_bios_version_show(struct class_device
*cdev
, char *buf
)
661 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
663 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->bios_revision
[1],
664 ha
->bios_revision
[0]);
668 qla2x00_optrom_efi_version_show(struct class_device
*cdev
, char *buf
)
670 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
672 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->efi_revision
[1],
673 ha
->efi_revision
[0]);
677 qla2x00_optrom_fcode_version_show(struct class_device
*cdev
, char *buf
)
679 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
681 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->fcode_revision
[1],
682 ha
->fcode_revision
[0]);
686 qla2x00_optrom_fw_version_show(struct class_device
*cdev
, char *buf
)
688 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
690 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d %d\n",
691 ha
->fw_revision
[0], ha
->fw_revision
[1], ha
->fw_revision
[2],
695 static CLASS_DEVICE_ATTR(driver_version
, S_IRUGO
, qla2x00_drvr_version_show
,
697 static CLASS_DEVICE_ATTR(fw_version
, S_IRUGO
, qla2x00_fw_version_show
, NULL
);
698 static CLASS_DEVICE_ATTR(serial_num
, S_IRUGO
, qla2x00_serial_num_show
, NULL
);
699 static CLASS_DEVICE_ATTR(isp_name
, S_IRUGO
, qla2x00_isp_name_show
, NULL
);
700 static CLASS_DEVICE_ATTR(isp_id
, S_IRUGO
, qla2x00_isp_id_show
, NULL
);
701 static CLASS_DEVICE_ATTR(model_name
, S_IRUGO
, qla2x00_model_name_show
, NULL
);
702 static CLASS_DEVICE_ATTR(model_desc
, S_IRUGO
, qla2x00_model_desc_show
, NULL
);
703 static CLASS_DEVICE_ATTR(pci_info
, S_IRUGO
, qla2x00_pci_info_show
, NULL
);
704 static CLASS_DEVICE_ATTR(state
, S_IRUGO
, qla2x00_state_show
, NULL
);
705 static CLASS_DEVICE_ATTR(zio
, S_IRUGO
| S_IWUSR
, qla2x00_zio_show
,
707 static CLASS_DEVICE_ATTR(zio_timer
, S_IRUGO
| S_IWUSR
, qla2x00_zio_timer_show
,
708 qla2x00_zio_timer_store
);
709 static CLASS_DEVICE_ATTR(beacon
, S_IRUGO
| S_IWUSR
, qla2x00_beacon_show
,
710 qla2x00_beacon_store
);
711 static CLASS_DEVICE_ATTR(optrom_bios_version
, S_IRUGO
,
712 qla2x00_optrom_bios_version_show
, NULL
);
713 static CLASS_DEVICE_ATTR(optrom_efi_version
, S_IRUGO
,
714 qla2x00_optrom_efi_version_show
, NULL
);
715 static CLASS_DEVICE_ATTR(optrom_fcode_version
, S_IRUGO
,
716 qla2x00_optrom_fcode_version_show
, NULL
);
717 static CLASS_DEVICE_ATTR(optrom_fw_version
, S_IRUGO
,
718 qla2x00_optrom_fw_version_show
, NULL
);
720 struct class_device_attribute
*qla2x00_host_attrs
[] = {
721 &class_device_attr_driver_version
,
722 &class_device_attr_fw_version
,
723 &class_device_attr_serial_num
,
724 &class_device_attr_isp_name
,
725 &class_device_attr_isp_id
,
726 &class_device_attr_model_name
,
727 &class_device_attr_model_desc
,
728 &class_device_attr_pci_info
,
729 &class_device_attr_state
,
730 &class_device_attr_zio
,
731 &class_device_attr_zio_timer
,
732 &class_device_attr_beacon
,
733 &class_device_attr_optrom_bios_version
,
734 &class_device_attr_optrom_efi_version
,
735 &class_device_attr_optrom_fcode_version
,
736 &class_device_attr_optrom_fw_version
,
740 /* Host attributes. */
743 qla2x00_get_host_port_id(struct Scsi_Host
*shost
)
745 scsi_qla_host_t
*ha
= to_qla_host(shost
);
747 fc_host_port_id(shost
) = ha
->d_id
.b
.domain
<< 16 |
748 ha
->d_id
.b
.area
<< 8 | ha
->d_id
.b
.al_pa
;
752 qla2x00_get_host_speed(struct Scsi_Host
*shost
)
754 scsi_qla_host_t
*ha
= to_qla_host(shost
);
757 switch (ha
->link_data_rate
) {
768 fc_host_speed(shost
) = speed
;
772 qla2x00_get_host_port_type(struct Scsi_Host
*shost
)
774 scsi_qla_host_t
*ha
= to_qla_host(shost
);
775 uint32_t port_type
= FC_PORTTYPE_UNKNOWN
;
777 switch (ha
->current_topology
) {
779 port_type
= FC_PORTTYPE_LPORT
;
782 port_type
= FC_PORTTYPE_NLPORT
;
785 port_type
= FC_PORTTYPE_PTP
;
788 port_type
= FC_PORTTYPE_NPORT
;
791 fc_host_port_type(shost
) = port_type
;
795 qla2x00_get_starget_node_name(struct scsi_target
*starget
)
797 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
798 scsi_qla_host_t
*ha
= to_qla_host(host
);
802 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
803 if (starget
->id
== fcport
->os_target_id
) {
804 node_name
= wwn_to_u64(fcport
->node_name
);
809 fc_starget_node_name(starget
) = node_name
;
813 qla2x00_get_starget_port_name(struct scsi_target
*starget
)
815 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
816 scsi_qla_host_t
*ha
= to_qla_host(host
);
820 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
821 if (starget
->id
== fcport
->os_target_id
) {
822 port_name
= wwn_to_u64(fcport
->port_name
);
827 fc_starget_port_name(starget
) = port_name
;
831 qla2x00_get_starget_port_id(struct scsi_target
*starget
)
833 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
834 scsi_qla_host_t
*ha
= to_qla_host(host
);
836 uint32_t port_id
= ~0U;
838 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
839 if (starget
->id
== fcport
->os_target_id
) {
840 port_id
= fcport
->d_id
.b
.domain
<< 16 |
841 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
846 fc_starget_port_id(starget
) = port_id
;
850 qla2x00_get_rport_loss_tmo(struct fc_rport
*rport
)
852 struct Scsi_Host
*host
= rport_to_shost(rport
);
853 scsi_qla_host_t
*ha
= to_qla_host(host
);
855 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
859 qla2x00_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
861 struct Scsi_Host
*host
= rport_to_shost(rport
);
862 scsi_qla_host_t
*ha
= to_qla_host(host
);
865 ha
->port_down_retry_count
= timeout
;
867 ha
->port_down_retry_count
= 1;
869 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
873 qla2x00_issue_lip(struct Scsi_Host
*shost
)
875 scsi_qla_host_t
*ha
= to_qla_host(shost
);
877 set_bit(LOOP_RESET_NEEDED
, &ha
->dpc_flags
);
881 static struct fc_host_statistics
*
882 qla2x00_get_fc_host_stats(struct Scsi_Host
*shost
)
884 scsi_qla_host_t
*ha
= to_qla_host(shost
);
887 link_stat_t stat_buf
;
888 struct fc_host_statistics
*pfc_host_stat
;
890 rval
= QLA_FUNCTION_FAILED
;
891 pfc_host_stat
= &ha
->fc_host_stat
;
892 memset(pfc_host_stat
, -1, sizeof(struct fc_host_statistics
));
894 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
)) {
895 rval
= qla24xx_get_isp_stats(ha
, (uint32_t *)&stat_buf
,
896 sizeof(stat_buf
) / 4, mb_stat
);
897 } else if (atomic_read(&ha
->loop_state
) == LOOP_READY
&&
898 !test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) &&
899 !test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
) &&
901 /* Must be in a 'READY' state for statistics retrieval. */
902 rval
= qla2x00_get_link_status(ha
, ha
->loop_id
, &stat_buf
,
906 if (rval
!= QLA_SUCCESS
)
909 pfc_host_stat
->link_failure_count
= stat_buf
.link_fail_cnt
;
910 pfc_host_stat
->loss_of_sync_count
= stat_buf
.loss_sync_cnt
;
911 pfc_host_stat
->loss_of_signal_count
= stat_buf
.loss_sig_cnt
;
912 pfc_host_stat
->prim_seq_protocol_err_count
= stat_buf
.prim_seq_err_cnt
;
913 pfc_host_stat
->invalid_tx_word_count
= stat_buf
.inval_xmit_word_cnt
;
914 pfc_host_stat
->invalid_crc_count
= stat_buf
.inval_crc_cnt
;
916 return pfc_host_stat
;
920 qla2x00_get_host_symbolic_name(struct Scsi_Host
*shost
)
922 scsi_qla_host_t
*ha
= to_qla_host(shost
);
924 qla2x00_get_sym_node_name(ha
, fc_host_symbolic_name(shost
));
928 qla2x00_set_host_system_hostname(struct Scsi_Host
*shost
)
930 scsi_qla_host_t
*ha
= to_qla_host(shost
);
932 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
936 qla2x00_get_host_fabric_name(struct Scsi_Host
*shost
)
938 scsi_qla_host_t
*ha
= to_qla_host(shost
);
941 if (ha
->device_flags
& SWITCH_FOUND
)
942 node_name
= wwn_to_u64(ha
->fabric_node_name
);
944 node_name
= wwn_to_u64(ha
->node_name
);
946 fc_host_fabric_name(shost
) = node_name
;
950 qla2x00_get_host_port_state(struct Scsi_Host
*shost
)
952 scsi_qla_host_t
*ha
= to_qla_host(shost
);
954 if (!ha
->flags
.online
)
955 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
956 else if (atomic_read(&ha
->loop_state
) == LOOP_TIMEOUT
)
957 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
959 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
962 struct fc_function_template qla2xxx_transport_functions
= {
964 .show_host_node_name
= 1,
965 .show_host_port_name
= 1,
966 .show_host_supported_classes
= 1,
968 .get_host_port_id
= qla2x00_get_host_port_id
,
969 .show_host_port_id
= 1,
970 .get_host_speed
= qla2x00_get_host_speed
,
971 .show_host_speed
= 1,
972 .get_host_port_type
= qla2x00_get_host_port_type
,
973 .show_host_port_type
= 1,
974 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
975 .show_host_symbolic_name
= 1,
976 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
977 .show_host_system_hostname
= 1,
978 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
979 .show_host_fabric_name
= 1,
980 .get_host_port_state
= qla2x00_get_host_port_state
,
981 .show_host_port_state
= 1,
983 .dd_fcrport_size
= sizeof(struct fc_port
*),
984 .show_rport_supported_classes
= 1,
986 .get_starget_node_name
= qla2x00_get_starget_node_name
,
987 .show_starget_node_name
= 1,
988 .get_starget_port_name
= qla2x00_get_starget_port_name
,
989 .show_starget_port_name
= 1,
990 .get_starget_port_id
= qla2x00_get_starget_port_id
,
991 .show_starget_port_id
= 1,
993 .get_rport_dev_loss_tmo
= qla2x00_get_rport_loss_tmo
,
994 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
995 .show_rport_dev_loss_tmo
= 1,
997 .issue_fc_host_lip
= qla2x00_issue_lip
,
998 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
1002 qla2x00_init_host_attr(scsi_qla_host_t
*ha
)
1004 fc_host_node_name(ha
->host
) = wwn_to_u64(ha
->node_name
);
1005 fc_host_port_name(ha
->host
) = wwn_to_u64(ha
->port_name
);
1006 fc_host_supported_classes(ha
->host
) = FC_COS_CLASS3
;