2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/kthread.h>
10 #include <linux/vmalloc.h>
12 int qla24xx_vport_disable(struct fc_vport
*, bool);
14 /* SYSFS attributes --------------------------------------------------------- */
17 qla2x00_sysfs_read_fw_dump(struct kobject
*kobj
,
18 struct bin_attribute
*bin_attr
,
19 char *buf
, loff_t off
, size_t count
)
21 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
22 struct device
, kobj
)));
23 char *rbuf
= (char *)ha
->fw_dump
;
25 if (ha
->fw_dump_reading
== 0)
27 if (off
> ha
->fw_dump_len
)
29 if (off
+ count
> ha
->fw_dump_len
)
30 count
= ha
->fw_dump_len
- off
;
32 memcpy(buf
, &rbuf
[off
], count
);
38 qla2x00_sysfs_write_fw_dump(struct kobject
*kobj
,
39 struct bin_attribute
*bin_attr
,
40 char *buf
, loff_t off
, size_t count
)
42 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
43 struct device
, kobj
)));
49 reading
= simple_strtol(buf
, NULL
, 10);
52 if (!ha
->fw_dump_reading
)
55 qla_printk(KERN_INFO
, ha
,
56 "Firmware dump cleared on (%ld).\n", ha
->host_no
);
58 ha
->fw_dump_reading
= 0;
62 if (ha
->fw_dumped
&& !ha
->fw_dump_reading
) {
63 ha
->fw_dump_reading
= 1;
65 qla_printk(KERN_INFO
, ha
,
66 "Raw firmware dump ready for read on (%ld).\n",
71 qla2x00_alloc_fw_dump(ha
);
77 static struct bin_attribute sysfs_fw_dump_attr
= {
80 .mode
= S_IRUSR
| S_IWUSR
,
83 .read
= qla2x00_sysfs_read_fw_dump
,
84 .write
= qla2x00_sysfs_write_fw_dump
,
88 qla2x00_sysfs_read_nvram(struct kobject
*kobj
,
89 struct bin_attribute
*bin_attr
,
90 char *buf
, loff_t off
, size_t count
)
92 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
93 struct device
, kobj
)));
96 if (!capable(CAP_SYS_ADMIN
) || off
!= 0)
100 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
101 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)buf
, ha
->nvram_base
,
103 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
105 return ha
->nvram_size
;
109 qla2x00_sysfs_write_nvram(struct kobject
*kobj
,
110 struct bin_attribute
*bin_attr
,
111 char *buf
, loff_t off
, size_t count
)
113 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
114 struct device
, kobj
)));
118 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->nvram_size
)
121 /* Checksum NVRAM. */
122 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
)) {
126 iter
= (uint32_t *)buf
;
128 for (cnt
= 0; cnt
< ((count
>> 2) - 1); cnt
++)
129 chksum
+= le32_to_cpu(*iter
++);
130 chksum
= ~chksum
+ 1;
131 *iter
= cpu_to_le32(chksum
);
136 iter
= (uint8_t *)buf
;
138 for (cnt
= 0; cnt
< count
- 1; cnt
++)
140 chksum
= ~chksum
+ 1;
145 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
146 ha
->isp_ops
.write_nvram(ha
, (uint8_t *)buf
, ha
->nvram_base
, count
);
147 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
149 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
154 static struct bin_attribute sysfs_nvram_attr
= {
157 .mode
= S_IRUSR
| S_IWUSR
,
160 .read
= qla2x00_sysfs_read_nvram
,
161 .write
= qla2x00_sysfs_write_nvram
,
165 qla2x00_sysfs_read_optrom(struct kobject
*kobj
,
166 struct bin_attribute
*bin_attr
,
167 char *buf
, loff_t off
, size_t count
)
169 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
170 struct device
, kobj
)));
172 if (ha
->optrom_state
!= QLA_SREADING
)
174 if (off
> ha
->optrom_size
)
176 if (off
+ count
> ha
->optrom_size
)
177 count
= ha
->optrom_size
- off
;
179 memcpy(buf
, &ha
->optrom_buffer
[off
], count
);
185 qla2x00_sysfs_write_optrom(struct kobject
*kobj
,
186 struct bin_attribute
*bin_attr
,
187 char *buf
, loff_t off
, size_t count
)
189 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
190 struct device
, kobj
)));
192 if (ha
->optrom_state
!= QLA_SWRITING
)
194 if (off
> ha
->optrom_size
)
196 if (off
+ count
> ha
->optrom_size
)
197 count
= ha
->optrom_size
- off
;
199 memcpy(&ha
->optrom_buffer
[off
], buf
, count
);
204 static struct bin_attribute sysfs_optrom_attr
= {
207 .mode
= S_IRUSR
| S_IWUSR
,
209 .size
= OPTROM_SIZE_24XX
,
210 .read
= qla2x00_sysfs_read_optrom
,
211 .write
= qla2x00_sysfs_write_optrom
,
215 qla2x00_sysfs_write_optrom_ctl(struct kobject
*kobj
,
216 struct bin_attribute
*bin_attr
,
217 char *buf
, loff_t off
, size_t count
)
219 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
220 struct device
, kobj
)));
226 if (sscanf(buf
, "%d", &val
) != 1)
231 if (ha
->optrom_state
!= QLA_SREADING
&&
232 ha
->optrom_state
!= QLA_SWRITING
)
235 ha
->optrom_state
= QLA_SWAITING
;
236 vfree(ha
->optrom_buffer
);
237 ha
->optrom_buffer
= NULL
;
240 if (ha
->optrom_state
!= QLA_SWAITING
)
243 ha
->optrom_state
= QLA_SREADING
;
244 ha
->optrom_buffer
= (uint8_t *)vmalloc(ha
->optrom_size
);
245 if (ha
->optrom_buffer
== NULL
) {
246 qla_printk(KERN_WARNING
, ha
,
247 "Unable to allocate memory for optrom retrieval "
248 "(%x).\n", ha
->optrom_size
);
250 ha
->optrom_state
= QLA_SWAITING
;
254 memset(ha
->optrom_buffer
, 0, ha
->optrom_size
);
255 ha
->isp_ops
.read_optrom(ha
, ha
->optrom_buffer
, 0,
259 if (ha
->optrom_state
!= QLA_SWAITING
)
262 ha
->optrom_state
= QLA_SWRITING
;
263 ha
->optrom_buffer
= (uint8_t *)vmalloc(ha
->optrom_size
);
264 if (ha
->optrom_buffer
== NULL
) {
265 qla_printk(KERN_WARNING
, ha
,
266 "Unable to allocate memory for optrom update "
267 "(%x).\n", ha
->optrom_size
);
269 ha
->optrom_state
= QLA_SWAITING
;
272 memset(ha
->optrom_buffer
, 0, ha
->optrom_size
);
275 if (ha
->optrom_state
!= QLA_SWRITING
)
278 ha
->isp_ops
.write_optrom(ha
, ha
->optrom_buffer
, 0,
285 static struct bin_attribute sysfs_optrom_ctl_attr
= {
287 .name
= "optrom_ctl",
291 .write
= qla2x00_sysfs_write_optrom_ctl
,
295 qla2x00_sysfs_read_vpd(struct kobject
*kobj
,
296 struct bin_attribute
*bin_attr
,
297 char *buf
, loff_t off
, size_t count
)
299 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
300 struct device
, kobj
)));
303 if (!capable(CAP_SYS_ADMIN
) || off
!= 0)
307 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
308 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)buf
, ha
->vpd_base
, ha
->vpd_size
);
309 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
315 qla2x00_sysfs_write_vpd(struct kobject
*kobj
,
316 struct bin_attribute
*bin_attr
,
317 char *buf
, loff_t off
, size_t count
)
319 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
320 struct device
, kobj
)));
323 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->vpd_size
)
327 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
328 ha
->isp_ops
.write_nvram(ha
, (uint8_t *)buf
, ha
->vpd_base
, count
);
329 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
334 static struct bin_attribute sysfs_vpd_attr
= {
337 .mode
= S_IRUSR
| S_IWUSR
,
340 .read
= qla2x00_sysfs_read_vpd
,
341 .write
= qla2x00_sysfs_write_vpd
,
345 qla2x00_sysfs_read_sfp(struct kobject
*kobj
,
346 struct bin_attribute
*bin_attr
,
347 char *buf
, loff_t off
, size_t count
)
349 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
350 struct device
, kobj
)));
351 uint16_t iter
, addr
, offset
;
354 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= SFP_DEV_SIZE
* 2)
358 for (iter
= 0, offset
= 0; iter
< (SFP_DEV_SIZE
* 2) / SFP_BLOCK_SIZE
;
359 iter
++, offset
+= SFP_BLOCK_SIZE
) {
361 /* Skip to next device address. */
366 rval
= qla2x00_read_sfp(ha
, ha
->sfp_data_dma
, addr
, offset
,
368 if (rval
!= QLA_SUCCESS
) {
369 qla_printk(KERN_WARNING
, ha
,
370 "Unable to read SFP data (%x/%x/%x).\n", rval
,
375 memcpy(buf
, ha
->sfp_data
, SFP_BLOCK_SIZE
);
376 buf
+= SFP_BLOCK_SIZE
;
382 static struct bin_attribute sysfs_sfp_attr
= {
385 .mode
= S_IRUSR
| S_IWUSR
,
387 .size
= SFP_DEV_SIZE
* 2,
388 .read
= qla2x00_sysfs_read_sfp
,
391 static struct sysfs_entry
{
393 struct bin_attribute
*attr
;
395 } bin_file_entries
[] = {
396 { "fw_dump", &sysfs_fw_dump_attr
, },
397 { "nvram", &sysfs_nvram_attr
, },
398 { "optrom", &sysfs_optrom_attr
, },
399 { "optrom_ctl", &sysfs_optrom_ctl_attr
, },
400 { "vpd", &sysfs_vpd_attr
, 1 },
401 { "sfp", &sysfs_sfp_attr
, 1 },
406 qla2x00_alloc_sysfs_attr(scsi_qla_host_t
*ha
)
408 struct Scsi_Host
*host
= ha
->host
;
409 struct sysfs_entry
*iter
;
412 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
413 if (iter
->is4GBp_only
&& (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)))
416 ret
= sysfs_create_bin_file(&host
->shost_gendev
.kobj
,
419 qla_printk(KERN_INFO
, ha
,
420 "Unable to create sysfs %s binary attribute "
421 "(%d).\n", iter
->name
, ret
);
426 qla2x00_free_sysfs_attr(scsi_qla_host_t
*ha
)
428 struct Scsi_Host
*host
= ha
->host
;
429 struct sysfs_entry
*iter
;
431 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
432 if (iter
->is4GBp_only
&& (!IS_QLA24XX(ha
) && !IS_QLA54XX(ha
)))
435 sysfs_remove_bin_file(&host
->shost_gendev
.kobj
,
439 if (ha
->beacon_blink_led
== 1)
440 ha
->isp_ops
.beacon_off(ha
);
443 /* Scsi_Host attributes. */
446 qla2x00_drvr_version_show(struct class_device
*cdev
, char *buf
)
448 return snprintf(buf
, PAGE_SIZE
, "%s\n", qla2x00_version_str
);
452 qla2x00_fw_version_show(struct class_device
*cdev
, char *buf
)
454 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
457 return snprintf(buf
, PAGE_SIZE
, "%s\n",
458 ha
->isp_ops
.fw_version_str(ha
, fw_str
));
462 qla2x00_serial_num_show(struct class_device
*cdev
, char *buf
)
464 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
467 sn
= ((ha
->serial0
& 0x1f) << 16) | (ha
->serial2
<< 8) | ha
->serial1
;
468 return snprintf(buf
, PAGE_SIZE
, "%c%05d\n", 'A' + sn
/ 100000,
473 qla2x00_isp_name_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
, "ISP%04X\n", ha
->pdev
->device
);
480 qla2x00_isp_id_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
, "%04x %04x %04x %04x\n",
484 ha
->product_id
[0], ha
->product_id
[1], ha
->product_id
[2],
489 qla2x00_model_name_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", ha
->model_number
);
496 qla2x00_model_desc_show(struct class_device
*cdev
, char *buf
)
498 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
499 return snprintf(buf
, PAGE_SIZE
, "%s\n",
500 ha
->model_desc
? ha
->model_desc
: "");
504 qla2x00_pci_info_show(struct class_device
*cdev
, char *buf
)
506 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
509 return snprintf(buf
, PAGE_SIZE
, "%s\n",
510 ha
->isp_ops
.pci_info_str(ha
, pci_info
));
514 qla2x00_state_show(struct class_device
*cdev
, char *buf
)
516 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
519 if (atomic_read(&ha
->loop_state
) == LOOP_DOWN
||
520 atomic_read(&ha
->loop_state
) == LOOP_DEAD
)
521 len
= snprintf(buf
, PAGE_SIZE
, "Link Down\n");
522 else if (atomic_read(&ha
->loop_state
) != LOOP_READY
||
523 test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) ||
524 test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
))
525 len
= snprintf(buf
, PAGE_SIZE
, "Unknown Link State\n");
527 len
= snprintf(buf
, PAGE_SIZE
, "Link Up - ");
529 switch (ha
->current_topology
) {
531 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
534 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "FL_Port\n");
537 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
538 "N_Port to N_Port\n");
541 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "F_Port\n");
544 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
552 qla2x00_zio_show(struct class_device
*cdev
, char *buf
)
554 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
557 switch (ha
->zio_mode
) {
559 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Mode 6\n");
561 case QLA_ZIO_DISABLED
:
562 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
569 qla2x00_zio_store(struct class_device
*cdev
, const char *buf
, size_t count
)
571 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
575 if (!IS_ZIO_SUPPORTED(ha
))
578 if (sscanf(buf
, "%d", &val
) != 1)
582 zio_mode
= QLA_ZIO_MODE_6
;
584 zio_mode
= QLA_ZIO_DISABLED
;
586 /* Update per-hba values and queue a reset. */
587 if (zio_mode
!= QLA_ZIO_DISABLED
|| ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
588 ha
->zio_mode
= zio_mode
;
589 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
595 qla2x00_zio_timer_show(struct class_device
*cdev
, char *buf
)
597 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
599 return snprintf(buf
, PAGE_SIZE
, "%d us\n", ha
->zio_timer
* 100);
603 qla2x00_zio_timer_store(struct class_device
*cdev
, const char *buf
,
606 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
610 if (sscanf(buf
, "%d", &val
) != 1)
612 if (val
> 25500 || val
< 100)
615 zio_timer
= (uint16_t)(val
/ 100);
616 ha
->zio_timer
= zio_timer
;
622 qla2x00_beacon_show(struct class_device
*cdev
, char *buf
)
624 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
627 if (ha
->beacon_blink_led
)
628 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Enabled\n");
630 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
635 qla2x00_beacon_store(struct class_device
*cdev
, const char *buf
,
638 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
642 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
645 if (test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)) {
646 qla_printk(KERN_WARNING
, ha
,
647 "Abort ISP active -- ignoring beacon request.\n");
651 if (sscanf(buf
, "%d", &val
) != 1)
655 rval
= ha
->isp_ops
.beacon_on(ha
);
657 rval
= ha
->isp_ops
.beacon_off(ha
);
659 if (rval
!= QLA_SUCCESS
)
666 qla2x00_optrom_bios_version_show(struct class_device
*cdev
, char *buf
)
668 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
670 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->bios_revision
[1],
671 ha
->bios_revision
[0]);
675 qla2x00_optrom_efi_version_show(struct class_device
*cdev
, char *buf
)
677 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
679 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->efi_revision
[1],
680 ha
->efi_revision
[0]);
684 qla2x00_optrom_fcode_version_show(struct class_device
*cdev
, char *buf
)
686 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
688 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->fcode_revision
[1],
689 ha
->fcode_revision
[0]);
693 qla2x00_optrom_fw_version_show(struct class_device
*cdev
, char *buf
)
695 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
697 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d %d\n",
698 ha
->fw_revision
[0], ha
->fw_revision
[1], ha
->fw_revision
[2],
702 static CLASS_DEVICE_ATTR(driver_version
, S_IRUGO
, qla2x00_drvr_version_show
,
704 static CLASS_DEVICE_ATTR(fw_version
, S_IRUGO
, qla2x00_fw_version_show
, NULL
);
705 static CLASS_DEVICE_ATTR(serial_num
, S_IRUGO
, qla2x00_serial_num_show
, NULL
);
706 static CLASS_DEVICE_ATTR(isp_name
, S_IRUGO
, qla2x00_isp_name_show
, NULL
);
707 static CLASS_DEVICE_ATTR(isp_id
, S_IRUGO
, qla2x00_isp_id_show
, NULL
);
708 static CLASS_DEVICE_ATTR(model_name
, S_IRUGO
, qla2x00_model_name_show
, NULL
);
709 static CLASS_DEVICE_ATTR(model_desc
, S_IRUGO
, qla2x00_model_desc_show
, NULL
);
710 static CLASS_DEVICE_ATTR(pci_info
, S_IRUGO
, qla2x00_pci_info_show
, NULL
);
711 static CLASS_DEVICE_ATTR(state
, S_IRUGO
, qla2x00_state_show
, NULL
);
712 static CLASS_DEVICE_ATTR(zio
, S_IRUGO
| S_IWUSR
, qla2x00_zio_show
,
714 static CLASS_DEVICE_ATTR(zio_timer
, S_IRUGO
| S_IWUSR
, qla2x00_zio_timer_show
,
715 qla2x00_zio_timer_store
);
716 static CLASS_DEVICE_ATTR(beacon
, S_IRUGO
| S_IWUSR
, qla2x00_beacon_show
,
717 qla2x00_beacon_store
);
718 static CLASS_DEVICE_ATTR(optrom_bios_version
, S_IRUGO
,
719 qla2x00_optrom_bios_version_show
, NULL
);
720 static CLASS_DEVICE_ATTR(optrom_efi_version
, S_IRUGO
,
721 qla2x00_optrom_efi_version_show
, NULL
);
722 static CLASS_DEVICE_ATTR(optrom_fcode_version
, S_IRUGO
,
723 qla2x00_optrom_fcode_version_show
, NULL
);
724 static CLASS_DEVICE_ATTR(optrom_fw_version
, S_IRUGO
,
725 qla2x00_optrom_fw_version_show
, NULL
);
727 struct class_device_attribute
*qla2x00_host_attrs
[] = {
728 &class_device_attr_driver_version
,
729 &class_device_attr_fw_version
,
730 &class_device_attr_serial_num
,
731 &class_device_attr_isp_name
,
732 &class_device_attr_isp_id
,
733 &class_device_attr_model_name
,
734 &class_device_attr_model_desc
,
735 &class_device_attr_pci_info
,
736 &class_device_attr_state
,
737 &class_device_attr_zio
,
738 &class_device_attr_zio_timer
,
739 &class_device_attr_beacon
,
740 &class_device_attr_optrom_bios_version
,
741 &class_device_attr_optrom_efi_version
,
742 &class_device_attr_optrom_fcode_version
,
743 &class_device_attr_optrom_fw_version
,
747 /* Host attributes. */
750 qla2x00_get_host_port_id(struct Scsi_Host
*shost
)
752 scsi_qla_host_t
*ha
= to_qla_host(shost
);
754 fc_host_port_id(shost
) = ha
->d_id
.b
.domain
<< 16 |
755 ha
->d_id
.b
.area
<< 8 | ha
->d_id
.b
.al_pa
;
759 qla2x00_get_host_speed(struct Scsi_Host
*shost
)
761 scsi_qla_host_t
*ha
= to_qla_host(shost
);
764 switch (ha
->link_data_rate
) {
775 fc_host_speed(shost
) = speed
;
779 qla2x00_get_host_port_type(struct Scsi_Host
*shost
)
781 scsi_qla_host_t
*ha
= to_qla_host(shost
);
782 uint32_t port_type
= FC_PORTTYPE_UNKNOWN
;
784 switch (ha
->current_topology
) {
786 port_type
= FC_PORTTYPE_LPORT
;
789 port_type
= FC_PORTTYPE_NLPORT
;
792 port_type
= FC_PORTTYPE_PTP
;
795 port_type
= FC_PORTTYPE_NPORT
;
798 fc_host_port_type(shost
) = port_type
;
802 qla2x00_get_starget_node_name(struct scsi_target
*starget
)
804 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
805 scsi_qla_host_t
*ha
= to_qla_host(host
);
809 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
810 if (starget
->id
== fcport
->os_target_id
) {
811 node_name
= wwn_to_u64(fcport
->node_name
);
816 fc_starget_node_name(starget
) = node_name
;
820 qla2x00_get_starget_port_name(struct scsi_target
*starget
)
822 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
823 scsi_qla_host_t
*ha
= to_qla_host(host
);
827 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
828 if (starget
->id
== fcport
->os_target_id
) {
829 port_name
= wwn_to_u64(fcport
->port_name
);
834 fc_starget_port_name(starget
) = port_name
;
838 qla2x00_get_starget_port_id(struct scsi_target
*starget
)
840 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
841 scsi_qla_host_t
*ha
= to_qla_host(host
);
843 uint32_t port_id
= ~0U;
845 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
846 if (starget
->id
== fcport
->os_target_id
) {
847 port_id
= fcport
->d_id
.b
.domain
<< 16 |
848 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
853 fc_starget_port_id(starget
) = port_id
;
857 qla2x00_get_rport_loss_tmo(struct fc_rport
*rport
)
859 struct Scsi_Host
*host
= rport_to_shost(rport
);
860 scsi_qla_host_t
*ha
= to_qla_host(host
);
862 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
866 qla2x00_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
868 struct Scsi_Host
*host
= rport_to_shost(rport
);
869 scsi_qla_host_t
*ha
= to_qla_host(host
);
872 ha
->port_down_retry_count
= timeout
;
874 ha
->port_down_retry_count
= 1;
876 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
880 qla2x00_issue_lip(struct Scsi_Host
*shost
)
882 scsi_qla_host_t
*ha
= to_qla_host(shost
);
884 set_bit(LOOP_RESET_NEEDED
, &ha
->dpc_flags
);
888 static struct fc_host_statistics
*
889 qla2x00_get_fc_host_stats(struct Scsi_Host
*shost
)
891 scsi_qla_host_t
*ha
= to_qla_host(shost
);
894 link_stat_t stat_buf
;
895 struct fc_host_statistics
*pfc_host_stat
;
897 rval
= QLA_FUNCTION_FAILED
;
898 pfc_host_stat
= &ha
->fc_host_stat
;
899 memset(pfc_host_stat
, -1, sizeof(struct fc_host_statistics
));
901 if (IS_QLA24XX(ha
) || IS_QLA54XX(ha
)) {
902 rval
= qla24xx_get_isp_stats(ha
, (uint32_t *)&stat_buf
,
903 sizeof(stat_buf
) / 4, mb_stat
);
904 } else if (atomic_read(&ha
->loop_state
) == LOOP_READY
&&
905 !test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) &&
906 !test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
) &&
908 /* Must be in a 'READY' state for statistics retrieval. */
909 rval
= qla2x00_get_link_status(ha
, ha
->loop_id
, &stat_buf
,
913 if (rval
!= QLA_SUCCESS
)
916 pfc_host_stat
->link_failure_count
= stat_buf
.link_fail_cnt
;
917 pfc_host_stat
->loss_of_sync_count
= stat_buf
.loss_sync_cnt
;
918 pfc_host_stat
->loss_of_signal_count
= stat_buf
.loss_sig_cnt
;
919 pfc_host_stat
->prim_seq_protocol_err_count
= stat_buf
.prim_seq_err_cnt
;
920 pfc_host_stat
->invalid_tx_word_count
= stat_buf
.inval_xmit_word_cnt
;
921 pfc_host_stat
->invalid_crc_count
= stat_buf
.inval_crc_cnt
;
923 return pfc_host_stat
;
927 qla2x00_get_host_symbolic_name(struct Scsi_Host
*shost
)
929 scsi_qla_host_t
*ha
= to_qla_host(shost
);
931 qla2x00_get_sym_node_name(ha
, fc_host_symbolic_name(shost
));
935 qla2x00_set_host_system_hostname(struct Scsi_Host
*shost
)
937 scsi_qla_host_t
*ha
= to_qla_host(shost
);
939 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
943 qla2x00_get_host_fabric_name(struct Scsi_Host
*shost
)
945 scsi_qla_host_t
*ha
= to_qla_host(shost
);
948 if (ha
->device_flags
& SWITCH_FOUND
)
949 node_name
= wwn_to_u64(ha
->fabric_node_name
);
951 node_name
= wwn_to_u64(ha
->node_name
);
953 fc_host_fabric_name(shost
) = node_name
;
957 qla2x00_get_host_port_state(struct Scsi_Host
*shost
)
959 scsi_qla_host_t
*ha
= to_qla_host(shost
);
961 if (!ha
->flags
.online
)
962 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
963 else if (atomic_read(&ha
->loop_state
) == LOOP_TIMEOUT
)
964 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
966 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
970 qla24xx_vport_create(struct fc_vport
*fc_vport
, bool disable
)
973 scsi_qla_host_t
*ha
= (scsi_qla_host_t
*) fc_vport
->shost
->hostdata
;
974 scsi_qla_host_t
*vha
;
976 ret
= qla24xx_vport_create_req_sanity_check(fc_vport
);
978 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
979 "status %x\n", ret
));
983 vha
= qla24xx_create_vhost(fc_vport
);
985 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
987 return FC_VPORT_FAILED
;
990 atomic_set(&vha
->vp_state
, VP_OFFLINE
);
991 fc_vport_set_state(fc_vport
, FC_VPORT_DISABLED
);
993 atomic_set(&vha
->vp_state
, VP_FAILED
);
995 /* ready to create vport */
996 qla_printk(KERN_INFO
, vha
, "VP entry id %d assigned.\n", vha
->vp_idx
);
998 /* initialized vport states */
999 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1000 vha
->vp_err_state
= VP_ERR_PORTDWN
;
1001 vha
->vp_prev_err_state
= VP_ERR_UNKWN
;
1002 /* Check if physical ha port is Up */
1003 if (atomic_read(&ha
->loop_state
) == LOOP_DOWN
||
1004 atomic_read(&ha
->loop_state
) == LOOP_DEAD
) {
1005 /* Don't retry or attempt login of this virtual port */
1006 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1008 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
1010 fc_vport_set_state(fc_vport
, FC_VPORT_LINKDOWN
);
1013 if (scsi_add_host(vha
->host
, &fc_vport
->dev
)) {
1014 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1015 vha
->host_no
, vha
->vp_idx
));
1016 goto vport_create_failed_2
;
1019 /* initialize attributes */
1020 fc_host_node_name(vha
->host
) = wwn_to_u64(vha
->node_name
);
1021 fc_host_port_name(vha
->host
) = wwn_to_u64(vha
->port_name
);
1022 fc_host_supported_classes(vha
->host
) =
1023 fc_host_supported_classes(ha
->host
);
1024 fc_host_supported_speeds(vha
->host
) =
1025 fc_host_supported_speeds(ha
->host
);
1027 qla24xx_vport_disable(fc_vport
, disable
);
1030 vport_create_failed_2
:
1031 qla24xx_disable_vp(vha
);
1032 qla24xx_deallocate_vp_id(vha
);
1033 kfree(vha
->port_name
);
1034 kfree(vha
->node_name
);
1035 scsi_host_put(vha
->host
);
1036 return FC_VPORT_FAILED
;
1040 qla24xx_vport_delete(struct fc_vport
*fc_vport
)
1042 scsi_qla_host_t
*ha
= (scsi_qla_host_t
*) fc_vport
->shost
->hostdata
;
1043 scsi_qla_host_t
*vha
= fc_vport
->dd_data
;
1045 qla24xx_disable_vp(vha
);
1046 qla24xx_deallocate_vp_id(vha
);
1048 down(&ha
->vport_sem
);
1049 ha
->cur_vport_count
--;
1050 clear_bit(vha
->vp_idx
, (unsigned long *)ha
->vp_idx_map
);
1053 kfree(vha
->node_name
);
1054 kfree(vha
->port_name
);
1056 if (vha
->timer_active
) {
1057 qla2x00_vp_stop_timer(vha
);
1058 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1060 vha
->host_no
, vha
->vp_idx
, vha
));
1063 fc_remove_host(vha
->host
);
1065 scsi_remove_host(vha
->host
);
1067 scsi_host_put(vha
->host
);
1073 qla24xx_vport_disable(struct fc_vport
*fc_vport
, bool disable
)
1075 scsi_qla_host_t
*vha
= fc_vport
->dd_data
;
1078 qla24xx_disable_vp(vha
);
1080 qla24xx_enable_vp(vha
);
1085 struct fc_function_template qla2xxx_transport_functions
= {
1087 .show_host_node_name
= 1,
1088 .show_host_port_name
= 1,
1089 .show_host_supported_classes
= 1,
1091 .get_host_port_id
= qla2x00_get_host_port_id
,
1092 .show_host_port_id
= 1,
1093 .get_host_speed
= qla2x00_get_host_speed
,
1094 .show_host_speed
= 1,
1095 .get_host_port_type
= qla2x00_get_host_port_type
,
1096 .show_host_port_type
= 1,
1097 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
1098 .show_host_symbolic_name
= 1,
1099 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
1100 .show_host_system_hostname
= 1,
1101 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
1102 .show_host_fabric_name
= 1,
1103 .get_host_port_state
= qla2x00_get_host_port_state
,
1104 .show_host_port_state
= 1,
1106 .dd_fcrport_size
= sizeof(struct fc_port
*),
1107 .show_rport_supported_classes
= 1,
1109 .get_starget_node_name
= qla2x00_get_starget_node_name
,
1110 .show_starget_node_name
= 1,
1111 .get_starget_port_name
= qla2x00_get_starget_port_name
,
1112 .show_starget_port_name
= 1,
1113 .get_starget_port_id
= qla2x00_get_starget_port_id
,
1114 .show_starget_port_id
= 1,
1116 .get_rport_dev_loss_tmo
= qla2x00_get_rport_loss_tmo
,
1117 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
1118 .show_rport_dev_loss_tmo
= 1,
1120 .issue_fc_host_lip
= qla2x00_issue_lip
,
1121 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
1123 .vport_create
= qla24xx_vport_create
,
1124 .vport_disable
= qla24xx_vport_disable
,
1125 .vport_delete
= qla24xx_vport_delete
,
1128 struct fc_function_template qla2xxx_transport_vport_functions
= {
1130 .show_host_node_name
= 1,
1131 .show_host_port_name
= 1,
1132 .show_host_supported_classes
= 1,
1134 .get_host_port_id
= qla2x00_get_host_port_id
,
1135 .show_host_port_id
= 1,
1136 .get_host_speed
= qla2x00_get_host_speed
,
1137 .show_host_speed
= 1,
1138 .get_host_port_type
= qla2x00_get_host_port_type
,
1139 .show_host_port_type
= 1,
1140 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
1141 .show_host_symbolic_name
= 1,
1142 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
1143 .show_host_system_hostname
= 1,
1144 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
1145 .show_host_fabric_name
= 1,
1146 .get_host_port_state
= qla2x00_get_host_port_state
,
1147 .show_host_port_state
= 1,
1149 .dd_fcrport_size
= sizeof(struct fc_port
*),
1150 .show_rport_supported_classes
= 1,
1152 .get_starget_node_name
= qla2x00_get_starget_node_name
,
1153 .show_starget_node_name
= 1,
1154 .get_starget_port_name
= qla2x00_get_starget_port_name
,
1155 .show_starget_port_name
= 1,
1156 .get_starget_port_id
= qla2x00_get_starget_port_id
,
1157 .show_starget_port_id
= 1,
1159 .get_rport_dev_loss_tmo
= qla2x00_get_rport_loss_tmo
,
1160 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
1161 .show_rport_dev_loss_tmo
= 1,
1163 .issue_fc_host_lip
= qla2x00_issue_lip
,
1164 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
1168 qla2x00_init_host_attr(scsi_qla_host_t
*ha
)
1170 fc_host_node_name(ha
->host
) = wwn_to_u64(ha
->node_name
);
1171 fc_host_port_name(ha
->host
) = wwn_to_u64(ha
->port_name
);
1172 fc_host_supported_classes(ha
->host
) = FC_COS_CLASS3
;
1173 fc_host_max_npiv_vports(ha
->host
) = MAX_NUM_VPORT_FABRIC
;
1174 fc_host_npiv_vports_inuse(ha
->host
) = ha
->cur_vport_count
;