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
);
146 static struct bin_attribute sysfs_nvram_attr
= {
149 .mode
= S_IRUSR
| S_IWUSR
,
150 .owner
= THIS_MODULE
,
153 .read
= qla2x00_sysfs_read_nvram
,
154 .write
= qla2x00_sysfs_write_nvram
,
158 qla2x00_sysfs_read_optrom(struct kobject
*kobj
, char *buf
, loff_t off
,
161 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
162 struct device
, kobj
)));
164 if (ha
->optrom_state
!= QLA_SREADING
)
166 if (off
> ha
->optrom_size
)
168 if (off
+ count
> ha
->optrom_size
)
169 count
= ha
->optrom_size
- off
;
171 memcpy(buf
, &ha
->optrom_buffer
[off
], count
);
177 qla2x00_sysfs_write_optrom(struct kobject
*kobj
, char *buf
, loff_t off
,
180 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
181 struct device
, kobj
)));
183 if (ha
->optrom_state
!= QLA_SWRITING
)
185 if (off
> ha
->optrom_size
)
187 if (off
+ count
> ha
->optrom_size
)
188 count
= ha
->optrom_size
- off
;
190 memcpy(&ha
->optrom_buffer
[off
], buf
, count
);
195 static struct bin_attribute sysfs_optrom_attr
= {
198 .mode
= S_IRUSR
| S_IWUSR
,
199 .owner
= THIS_MODULE
,
201 .size
= OPTROM_SIZE_24XX
,
202 .read
= qla2x00_sysfs_read_optrom
,
203 .write
= qla2x00_sysfs_write_optrom
,
207 qla2x00_sysfs_write_optrom_ctl(struct kobject
*kobj
, char *buf
, loff_t off
,
210 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
211 struct device
, kobj
)));
217 if (sscanf(buf
, "%d", &val
) != 1)
222 if (ha
->optrom_state
!= QLA_SREADING
&&
223 ha
->optrom_state
!= QLA_SWRITING
)
226 ha
->optrom_state
= QLA_SWAITING
;
227 vfree(ha
->optrom_buffer
);
228 ha
->optrom_buffer
= NULL
;
231 if (ha
->optrom_state
!= QLA_SWAITING
)
234 ha
->optrom_state
= QLA_SREADING
;
235 ha
->optrom_buffer
= (uint8_t *)vmalloc(ha
->optrom_size
);
236 if (ha
->optrom_buffer
== NULL
) {
237 qla_printk(KERN_WARNING
, ha
,
238 "Unable to allocate memory for optrom retrieval "
239 "(%x).\n", ha
->optrom_size
);
241 ha
->optrom_state
= QLA_SWAITING
;
245 memset(ha
->optrom_buffer
, 0, ha
->optrom_size
);
246 ha
->isp_ops
.read_optrom(ha
, ha
->optrom_buffer
, 0,
250 if (ha
->optrom_state
!= QLA_SWAITING
)
253 ha
->optrom_state
= QLA_SWRITING
;
254 ha
->optrom_buffer
= (uint8_t *)vmalloc(ha
->optrom_size
);
255 if (ha
->optrom_buffer
== NULL
) {
256 qla_printk(KERN_WARNING
, ha
,
257 "Unable to allocate memory for optrom update "
258 "(%x).\n", ha
->optrom_size
);
260 ha
->optrom_state
= QLA_SWAITING
;
263 memset(ha
->optrom_buffer
, 0, ha
->optrom_size
);
266 if (ha
->optrom_state
!= QLA_SWRITING
)
269 ha
->isp_ops
.write_optrom(ha
, ha
->optrom_buffer
, 0,
276 static struct bin_attribute sysfs_optrom_ctl_attr
= {
278 .name
= "optrom_ctl",
280 .owner
= THIS_MODULE
,
283 .write
= qla2x00_sysfs_write_optrom_ctl
,
287 qla2x00_sysfs_read_vpd(struct kobject
*kobj
, char *buf
, loff_t off
,
290 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
291 struct device
, kobj
)));
294 if (!capable(CAP_SYS_ADMIN
) || off
!= 0)
298 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
299 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)buf
, ha
->vpd_base
, ha
->vpd_size
);
300 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
306 qla2x00_sysfs_write_vpd(struct kobject
*kobj
, char *buf
, loff_t off
,
309 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
310 struct device
, kobj
)));
313 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->vpd_size
)
317 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
318 ha
->isp_ops
.write_nvram(ha
, (uint8_t *)buf
, ha
->vpd_base
, count
);
319 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
324 static struct bin_attribute sysfs_vpd_attr
= {
327 .mode
= S_IRUSR
| S_IWUSR
,
328 .owner
= THIS_MODULE
,
331 .read
= qla2x00_sysfs_read_vpd
,
332 .write
= qla2x00_sysfs_write_vpd
,
336 qla2x00_sysfs_read_sfp(struct kobject
*kobj
, char *buf
, loff_t off
,
339 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
340 struct device
, kobj
)));
341 uint16_t iter
, addr
, offset
;
344 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= SFP_DEV_SIZE
* 2)
348 for (iter
= 0, offset
= 0; iter
< (SFP_DEV_SIZE
* 2) / SFP_BLOCK_SIZE
;
349 iter
++, offset
+= SFP_BLOCK_SIZE
) {
351 /* Skip to next device address. */
356 rval
= qla2x00_read_sfp(ha
, ha
->sfp_data_dma
, addr
, offset
,
358 if (rval
!= QLA_SUCCESS
) {
359 qla_printk(KERN_WARNING
, ha
,
360 "Unable to read SFP data (%x/%x/%x).\n", rval
,
365 memcpy(buf
, ha
->sfp_data
, SFP_BLOCK_SIZE
);
366 buf
+= SFP_BLOCK_SIZE
;
372 static struct bin_attribute sysfs_sfp_attr
= {
375 .mode
= S_IRUSR
| S_IWUSR
,
376 .owner
= THIS_MODULE
,
378 .size
= SFP_DEV_SIZE
* 2,
379 .read
= qla2x00_sysfs_read_sfp
,
382 static struct sysfs_entry
{
384 struct bin_attribute
*attr
;
386 } bin_file_entries
[] = {
387 { "fw_dump", &sysfs_fw_dump_attr
, },
388 { "nvram", &sysfs_nvram_attr
, },
389 { "optrom", &sysfs_optrom_attr
, },
390 { "optrom_ctl", &sysfs_optrom_ctl_attr
, },
391 { "vpd", &sysfs_vpd_attr
, 1 },
392 { "sfp", &sysfs_sfp_attr
, 1 },
397 qla2x00_alloc_sysfs_attr(scsi_qla_host_t
*ha
)
399 struct Scsi_Host
*host
= ha
->host
;
400 struct sysfs_entry
*iter
;
403 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
404 if (iter
->is4GBp_only
&& (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)))
407 ret
= sysfs_create_bin_file(&host
->shost_gendev
.kobj
,
410 qla_printk(KERN_INFO
, ha
,
411 "Unable to create sysfs %s binary attribute "
412 "(%d).\n", iter
->name
, ret
);
417 qla2x00_free_sysfs_attr(scsi_qla_host_t
*ha
)
419 struct Scsi_Host
*host
= ha
->host
;
420 struct sysfs_entry
*iter
;
422 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
423 if (iter
->is4GBp_only
&& (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)))
426 sysfs_remove_bin_file(&host
->shost_gendev
.kobj
,
430 if (ha
->beacon_blink_led
== 1)
431 ha
->isp_ops
.beacon_off(ha
);
434 /* Scsi_Host attributes. */
437 qla2x00_drvr_version_show(struct class_device
*cdev
, char *buf
)
439 return snprintf(buf
, PAGE_SIZE
, "%s\n", qla2x00_version_str
);
443 qla2x00_fw_version_show(struct class_device
*cdev
, char *buf
)
445 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
448 return snprintf(buf
, PAGE_SIZE
, "%s\n",
449 ha
->isp_ops
.fw_version_str(ha
, fw_str
));
453 qla2x00_serial_num_show(struct class_device
*cdev
, char *buf
)
455 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
458 sn
= ((ha
->serial0
& 0x1f) << 16) | (ha
->serial2
<< 8) | ha
->serial1
;
459 return snprintf(buf
, PAGE_SIZE
, "%c%05d\n", 'A' + sn
/ 100000,
464 qla2x00_isp_name_show(struct class_device
*cdev
, char *buf
)
466 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
467 return snprintf(buf
, PAGE_SIZE
, "ISP%04X\n", ha
->pdev
->device
);
471 qla2x00_isp_id_show(struct class_device
*cdev
, char *buf
)
473 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
474 return snprintf(buf
, PAGE_SIZE
, "%04x %04x %04x %04x\n",
475 ha
->product_id
[0], ha
->product_id
[1], ha
->product_id
[2],
480 qla2x00_model_name_show(struct class_device
*cdev
, char *buf
)
482 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
483 return snprintf(buf
, PAGE_SIZE
, "%s\n", ha
->model_number
);
487 qla2x00_model_desc_show(struct class_device
*cdev
, char *buf
)
489 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
490 return snprintf(buf
, PAGE_SIZE
, "%s\n",
491 ha
->model_desc
? ha
->model_desc
: "");
495 qla2x00_pci_info_show(struct class_device
*cdev
, char *buf
)
497 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
500 return snprintf(buf
, PAGE_SIZE
, "%s\n",
501 ha
->isp_ops
.pci_info_str(ha
, pci_info
));
505 qla2x00_state_show(struct class_device
*cdev
, char *buf
)
507 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
510 if (atomic_read(&ha
->loop_state
) == LOOP_DOWN
||
511 atomic_read(&ha
->loop_state
) == LOOP_DEAD
)
512 len
= snprintf(buf
, PAGE_SIZE
, "Link Down\n");
513 else if (atomic_read(&ha
->loop_state
) != LOOP_READY
||
514 test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) ||
515 test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
))
516 len
= snprintf(buf
, PAGE_SIZE
, "Unknown Link State\n");
518 len
= snprintf(buf
, PAGE_SIZE
, "Link Up - ");
520 switch (ha
->current_topology
) {
522 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
525 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "FL_Port\n");
528 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
529 "N_Port to N_Port\n");
532 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "F_Port\n");
535 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
543 qla2x00_zio_show(struct class_device
*cdev
, char *buf
)
545 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
548 switch (ha
->zio_mode
) {
550 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Mode 6\n");
552 case QLA_ZIO_DISABLED
:
553 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
560 qla2x00_zio_store(struct class_device
*cdev
, const char *buf
, size_t count
)
562 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
566 if (!IS_ZIO_SUPPORTED(ha
))
569 if (sscanf(buf
, "%d", &val
) != 1)
573 zio_mode
= QLA_ZIO_MODE_6
;
575 zio_mode
= QLA_ZIO_DISABLED
;
577 /* Update per-hba values and queue a reset. */
578 if (zio_mode
!= QLA_ZIO_DISABLED
|| ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
579 ha
->zio_mode
= zio_mode
;
580 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
586 qla2x00_zio_timer_show(struct class_device
*cdev
, char *buf
)
588 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
590 return snprintf(buf
, PAGE_SIZE
, "%d us\n", ha
->zio_timer
* 100);
594 qla2x00_zio_timer_store(struct class_device
*cdev
, const char *buf
,
597 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
601 if (sscanf(buf
, "%d", &val
) != 1)
603 if (val
> 25500 || val
< 100)
606 zio_timer
= (uint16_t)(val
/ 100);
607 ha
->zio_timer
= zio_timer
;
613 qla2x00_beacon_show(struct class_device
*cdev
, char *buf
)
615 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
618 if (ha
->beacon_blink_led
)
619 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Enabled\n");
621 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
626 qla2x00_beacon_store(struct class_device
*cdev
, const char *buf
,
629 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
633 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
636 if (test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)) {
637 qla_printk(KERN_WARNING
, ha
,
638 "Abort ISP active -- ignoring beacon request.\n");
642 if (sscanf(buf
, "%d", &val
) != 1)
646 rval
= ha
->isp_ops
.beacon_on(ha
);
648 rval
= ha
->isp_ops
.beacon_off(ha
);
650 if (rval
!= QLA_SUCCESS
)
656 static CLASS_DEVICE_ATTR(driver_version
, S_IRUGO
, qla2x00_drvr_version_show
,
658 static CLASS_DEVICE_ATTR(fw_version
, S_IRUGO
, qla2x00_fw_version_show
, NULL
);
659 static CLASS_DEVICE_ATTR(serial_num
, S_IRUGO
, qla2x00_serial_num_show
, NULL
);
660 static CLASS_DEVICE_ATTR(isp_name
, S_IRUGO
, qla2x00_isp_name_show
, NULL
);
661 static CLASS_DEVICE_ATTR(isp_id
, S_IRUGO
, qla2x00_isp_id_show
, NULL
);
662 static CLASS_DEVICE_ATTR(model_name
, S_IRUGO
, qla2x00_model_name_show
, NULL
);
663 static CLASS_DEVICE_ATTR(model_desc
, S_IRUGO
, qla2x00_model_desc_show
, NULL
);
664 static CLASS_DEVICE_ATTR(pci_info
, S_IRUGO
, qla2x00_pci_info_show
, NULL
);
665 static CLASS_DEVICE_ATTR(state
, S_IRUGO
, qla2x00_state_show
, NULL
);
666 static CLASS_DEVICE_ATTR(zio
, S_IRUGO
| S_IWUSR
, qla2x00_zio_show
,
668 static CLASS_DEVICE_ATTR(zio_timer
, S_IRUGO
| S_IWUSR
, qla2x00_zio_timer_show
,
669 qla2x00_zio_timer_store
);
670 static CLASS_DEVICE_ATTR(beacon
, S_IRUGO
| S_IWUSR
, qla2x00_beacon_show
,
671 qla2x00_beacon_store
);
673 struct class_device_attribute
*qla2x00_host_attrs
[] = {
674 &class_device_attr_driver_version
,
675 &class_device_attr_fw_version
,
676 &class_device_attr_serial_num
,
677 &class_device_attr_isp_name
,
678 &class_device_attr_isp_id
,
679 &class_device_attr_model_name
,
680 &class_device_attr_model_desc
,
681 &class_device_attr_pci_info
,
682 &class_device_attr_state
,
683 &class_device_attr_zio
,
684 &class_device_attr_zio_timer
,
685 &class_device_attr_beacon
,
689 /* Host attributes. */
692 qla2x00_get_host_port_id(struct Scsi_Host
*shost
)
694 scsi_qla_host_t
*ha
= to_qla_host(shost
);
696 fc_host_port_id(shost
) = ha
->d_id
.b
.domain
<< 16 |
697 ha
->d_id
.b
.area
<< 8 | ha
->d_id
.b
.al_pa
;
701 qla2x00_get_host_speed(struct Scsi_Host
*shost
)
703 scsi_qla_host_t
*ha
= to_qla_host(shost
);
706 switch (ha
->link_data_rate
) {
717 fc_host_speed(shost
) = speed
;
721 qla2x00_get_host_port_type(struct Scsi_Host
*shost
)
723 scsi_qla_host_t
*ha
= to_qla_host(shost
);
724 uint32_t port_type
= FC_PORTTYPE_UNKNOWN
;
726 switch (ha
->current_topology
) {
728 port_type
= FC_PORTTYPE_LPORT
;
731 port_type
= FC_PORTTYPE_NLPORT
;
734 port_type
= FC_PORTTYPE_PTP
;
737 port_type
= FC_PORTTYPE_NPORT
;
740 fc_host_port_type(shost
) = port_type
;
744 qla2x00_get_starget_node_name(struct scsi_target
*starget
)
746 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
747 scsi_qla_host_t
*ha
= to_qla_host(host
);
751 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
752 if (starget
->id
== fcport
->os_target_id
) {
753 node_name
= wwn_to_u64(fcport
->node_name
);
758 fc_starget_node_name(starget
) = node_name
;
762 qla2x00_get_starget_port_name(struct scsi_target
*starget
)
764 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
765 scsi_qla_host_t
*ha
= to_qla_host(host
);
769 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
770 if (starget
->id
== fcport
->os_target_id
) {
771 port_name
= wwn_to_u64(fcport
->port_name
);
776 fc_starget_port_name(starget
) = port_name
;
780 qla2x00_get_starget_port_id(struct scsi_target
*starget
)
782 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
783 scsi_qla_host_t
*ha
= to_qla_host(host
);
785 uint32_t port_id
= ~0U;
787 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
788 if (starget
->id
== fcport
->os_target_id
) {
789 port_id
= fcport
->d_id
.b
.domain
<< 16 |
790 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
795 fc_starget_port_id(starget
) = port_id
;
799 qla2x00_get_rport_loss_tmo(struct fc_rport
*rport
)
801 struct Scsi_Host
*host
= rport_to_shost(rport
);
802 scsi_qla_host_t
*ha
= to_qla_host(host
);
804 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
808 qla2x00_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
810 struct Scsi_Host
*host
= rport_to_shost(rport
);
811 scsi_qla_host_t
*ha
= to_qla_host(host
);
814 ha
->port_down_retry_count
= timeout
;
816 ha
->port_down_retry_count
= 1;
818 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
822 qla2x00_issue_lip(struct Scsi_Host
*shost
)
824 scsi_qla_host_t
*ha
= to_qla_host(shost
);
826 set_bit(LOOP_RESET_NEEDED
, &ha
->dpc_flags
);
830 static struct fc_host_statistics
*
831 qla2x00_get_fc_host_stats(struct Scsi_Host
*shost
)
833 scsi_qla_host_t
*ha
= to_qla_host(shost
);
836 link_stat_t stat_buf
;
837 struct fc_host_statistics
*pfc_host_stat
;
839 pfc_host_stat
= &ha
->fc_host_stat
;
840 memset(pfc_host_stat
, -1, sizeof(struct fc_host_statistics
));
842 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
)) {
843 rval
= qla24xx_get_isp_stats(ha
, (uint32_t *)&stat_buf
,
844 sizeof(stat_buf
) / 4, mb_stat
);
846 rval
= qla2x00_get_link_status(ha
, ha
->loop_id
, &stat_buf
,
850 qla_printk(KERN_WARNING
, ha
,
851 "Unable to retrieve host statistics (%d).\n", mb_stat
[0]);
852 return pfc_host_stat
;
855 pfc_host_stat
->link_failure_count
= stat_buf
.link_fail_cnt
;
856 pfc_host_stat
->loss_of_sync_count
= stat_buf
.loss_sync_cnt
;
857 pfc_host_stat
->loss_of_signal_count
= stat_buf
.loss_sig_cnt
;
858 pfc_host_stat
->prim_seq_protocol_err_count
= stat_buf
.prim_seq_err_cnt
;
859 pfc_host_stat
->invalid_tx_word_count
= stat_buf
.inval_xmit_word_cnt
;
860 pfc_host_stat
->invalid_crc_count
= stat_buf
.inval_crc_cnt
;
862 return pfc_host_stat
;
866 qla2x00_get_host_symbolic_name(struct Scsi_Host
*shost
)
868 scsi_qla_host_t
*ha
= to_qla_host(shost
);
870 qla2x00_get_sym_node_name(ha
, fc_host_symbolic_name(shost
));
874 qla2x00_set_host_system_hostname(struct Scsi_Host
*shost
)
876 scsi_qla_host_t
*ha
= to_qla_host(shost
);
878 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
882 qla2x00_get_host_fabric_name(struct Scsi_Host
*shost
)
884 scsi_qla_host_t
*ha
= to_qla_host(shost
);
887 if (ha
->device_flags
& SWITCH_FOUND
)
888 node_name
= wwn_to_u64(ha
->fabric_node_name
);
890 node_name
= wwn_to_u64(ha
->node_name
);
892 fc_host_fabric_name(shost
) = node_name
;
896 qla2x00_get_host_port_state(struct Scsi_Host
*shost
)
898 scsi_qla_host_t
*ha
= to_qla_host(shost
);
900 if (!ha
->flags
.online
)
901 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
902 else if (atomic_read(&ha
->loop_state
) == LOOP_TIMEOUT
)
903 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
905 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
908 struct fc_function_template qla2xxx_transport_functions
= {
910 .show_host_node_name
= 1,
911 .show_host_port_name
= 1,
912 .show_host_supported_classes
= 1,
914 .get_host_port_id
= qla2x00_get_host_port_id
,
915 .show_host_port_id
= 1,
916 .get_host_speed
= qla2x00_get_host_speed
,
917 .show_host_speed
= 1,
918 .get_host_port_type
= qla2x00_get_host_port_type
,
919 .show_host_port_type
= 1,
920 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
921 .show_host_symbolic_name
= 1,
922 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
923 .show_host_system_hostname
= 1,
924 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
925 .show_host_fabric_name
= 1,
926 .get_host_port_state
= qla2x00_get_host_port_state
,
927 .show_host_port_state
= 1,
929 .dd_fcrport_size
= sizeof(struct fc_port
*),
930 .show_rport_supported_classes
= 1,
932 .get_starget_node_name
= qla2x00_get_starget_node_name
,
933 .show_starget_node_name
= 1,
934 .get_starget_port_name
= qla2x00_get_starget_port_name
,
935 .show_starget_port_name
= 1,
936 .get_starget_port_id
= qla2x00_get_starget_port_id
,
937 .show_starget_port_id
= 1,
939 .get_rport_dev_loss_tmo
= qla2x00_get_rport_loss_tmo
,
940 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
941 .show_rport_dev_loss_tmo
= 1,
943 .issue_fc_host_lip
= qla2x00_issue_lip
,
944 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
948 qla2x00_init_host_attr(scsi_qla_host_t
*ha
)
950 fc_host_node_name(ha
->host
) = wwn_to_u64(ha
->node_name
);
951 fc_host_port_name(ha
->host
) = wwn_to_u64(ha
->port_name
);
952 fc_host_supported_classes(ha
->host
) = FC_COS_CLASS3
;