2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2008 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
9 #include <linux/kthread.h>
10 #include <linux/vmalloc.h>
12 static 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
)));
24 if (ha
->fw_dump_reading
== 0)
27 return memory_read_from_buffer(buf
, count
, &off
, ha
->fw_dump
,
32 qla2x00_sysfs_write_fw_dump(struct kobject
*kobj
,
33 struct bin_attribute
*bin_attr
,
34 char *buf
, loff_t off
, size_t count
)
36 struct scsi_qla_host
*ha
= shost_priv(dev_to_shost(container_of(kobj
,
37 struct device
, kobj
)));
43 reading
= simple_strtol(buf
, NULL
, 10);
46 if (!ha
->fw_dump_reading
)
49 qla_printk(KERN_INFO
, ha
,
50 "Firmware dump cleared on (%ld).\n", ha
->host_no
);
52 ha
->fw_dump_reading
= 0;
56 if (ha
->fw_dumped
&& !ha
->fw_dump_reading
) {
57 ha
->fw_dump_reading
= 1;
59 qla_printk(KERN_INFO
, ha
,
60 "Raw firmware dump ready for read on (%ld).\n",
65 qla2x00_alloc_fw_dump(ha
);
68 qla2x00_system_error(ha
);
74 static struct bin_attribute sysfs_fw_dump_attr
= {
77 .mode
= S_IRUSR
| S_IWUSR
,
80 .read
= qla2x00_sysfs_read_fw_dump
,
81 .write
= qla2x00_sysfs_write_fw_dump
,
85 qla2x00_sysfs_read_nvram(struct kobject
*kobj
,
86 struct bin_attribute
*bin_attr
,
87 char *buf
, loff_t off
, size_t count
)
89 struct scsi_qla_host
*ha
= shost_priv(dev_to_shost(container_of(kobj
,
90 struct device
, kobj
)));
92 if (!capable(CAP_SYS_ADMIN
))
95 /* Read NVRAM data from cache. */
96 return memory_read_from_buffer(buf
, count
, &off
, ha
->nvram
,
101 qla2x00_sysfs_write_nvram(struct kobject
*kobj
,
102 struct bin_attribute
*bin_attr
,
103 char *buf
, loff_t off
, size_t count
)
105 struct scsi_qla_host
*ha
= shost_priv(dev_to_shost(container_of(kobj
,
106 struct device
, kobj
)));
109 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->nvram_size
)
112 /* Checksum NVRAM. */
113 if (IS_FWI2_CAPABLE(ha
)) {
117 iter
= (uint32_t *)buf
;
119 for (cnt
= 0; cnt
< ((count
>> 2) - 1); cnt
++)
120 chksum
+= le32_to_cpu(*iter
++);
121 chksum
= ~chksum
+ 1;
122 *iter
= cpu_to_le32(chksum
);
127 iter
= (uint8_t *)buf
;
129 for (cnt
= 0; cnt
< count
- 1; cnt
++)
131 chksum
= ~chksum
+ 1;
136 ha
->isp_ops
->write_nvram(ha
, (uint8_t *)buf
, ha
->nvram_base
, count
);
137 ha
->isp_ops
->read_nvram(ha
, (uint8_t *)ha
->nvram
, ha
->nvram_base
,
140 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
145 static struct bin_attribute sysfs_nvram_attr
= {
148 .mode
= S_IRUSR
| S_IWUSR
,
151 .read
= qla2x00_sysfs_read_nvram
,
152 .write
= qla2x00_sysfs_write_nvram
,
156 qla2x00_sysfs_read_optrom(struct kobject
*kobj
,
157 struct bin_attribute
*bin_attr
,
158 char *buf
, loff_t off
, size_t count
)
160 struct scsi_qla_host
*ha
= shost_priv(dev_to_shost(container_of(kobj
,
161 struct device
, kobj
)));
163 if (ha
->optrom_state
!= QLA_SREADING
)
166 return memory_read_from_buffer(buf
, count
, &off
, ha
->optrom_buffer
,
167 ha
->optrom_region_size
);
171 qla2x00_sysfs_write_optrom(struct kobject
*kobj
,
172 struct bin_attribute
*bin_attr
,
173 char *buf
, loff_t off
, size_t count
)
175 struct scsi_qla_host
*ha
= shost_priv(dev_to_shost(container_of(kobj
,
176 struct device
, kobj
)));
178 if (ha
->optrom_state
!= QLA_SWRITING
)
180 if (off
> ha
->optrom_region_size
)
182 if (off
+ count
> ha
->optrom_region_size
)
183 count
= ha
->optrom_region_size
- off
;
185 memcpy(&ha
->optrom_buffer
[off
], buf
, count
);
190 static struct bin_attribute sysfs_optrom_attr
= {
193 .mode
= S_IRUSR
| S_IWUSR
,
196 .read
= qla2x00_sysfs_read_optrom
,
197 .write
= qla2x00_sysfs_write_optrom
,
201 qla2x00_sysfs_write_optrom_ctl(struct kobject
*kobj
,
202 struct bin_attribute
*bin_attr
,
203 char *buf
, loff_t off
, size_t count
)
205 struct scsi_qla_host
*ha
= shost_priv(dev_to_shost(container_of(kobj
,
206 struct device
, kobj
)));
208 uint32_t size
= ha
->optrom_size
;
214 if (sscanf(buf
, "%d:%x:%x", &val
, &start
, &size
) < 1)
216 if (start
> ha
->optrom_size
)
221 if (ha
->optrom_state
!= QLA_SREADING
&&
222 ha
->optrom_state
!= QLA_SWRITING
)
225 ha
->optrom_state
= QLA_SWAITING
;
227 DEBUG2(qla_printk(KERN_INFO
, ha
,
228 "Freeing flash region allocation -- 0x%x bytes.\n",
229 ha
->optrom_region_size
));
231 vfree(ha
->optrom_buffer
);
232 ha
->optrom_buffer
= NULL
;
235 if (ha
->optrom_state
!= QLA_SWAITING
)
239 qla_printk(KERN_WARNING
, ha
,
240 "Invalid start region 0x%x/0x%x.\n", start
, size
);
244 ha
->optrom_region_start
= start
;
245 ha
->optrom_region_size
= start
+ size
> ha
->optrom_size
?
246 ha
->optrom_size
- start
: size
;
248 ha
->optrom_state
= QLA_SREADING
;
249 ha
->optrom_buffer
= vmalloc(ha
->optrom_region_size
);
250 if (ha
->optrom_buffer
== NULL
) {
251 qla_printk(KERN_WARNING
, ha
,
252 "Unable to allocate memory for optrom retrieval "
253 "(%x).\n", ha
->optrom_region_size
);
255 ha
->optrom_state
= QLA_SWAITING
;
259 DEBUG2(qla_printk(KERN_INFO
, ha
,
260 "Reading flash region -- 0x%x/0x%x.\n",
261 ha
->optrom_region_start
, ha
->optrom_region_size
));
263 memset(ha
->optrom_buffer
, 0, ha
->optrom_region_size
);
264 ha
->isp_ops
->read_optrom(ha
, ha
->optrom_buffer
,
265 ha
->optrom_region_start
, ha
->optrom_region_size
);
268 if (ha
->optrom_state
!= QLA_SWAITING
)
272 * We need to be more restrictive on which FLASH regions are
273 * allowed to be updated via user-space. Regions accessible
274 * via this method include:
276 * ISP21xx/ISP22xx/ISP23xx type boards:
278 * 0x000000 -> 0x020000 -- Boot code.
280 * ISP2322/ISP24xx type boards:
282 * 0x000000 -> 0x07ffff -- Boot code.
283 * 0x080000 -> 0x0fffff -- Firmware.
285 * ISP25xx type boards:
287 * 0x000000 -> 0x07ffff -- Boot code.
288 * 0x080000 -> 0x0fffff -- Firmware.
289 * 0x120000 -> 0x12ffff -- VPD and HBA parameters.
292 if (ha
->optrom_size
== OPTROM_SIZE_2300
&& start
== 0)
294 else if (start
== (FA_BOOT_CODE_ADDR
*4) ||
295 start
== (FA_RISC_CODE_ADDR
*4))
297 else if (IS_QLA25XX(ha
) && start
== (FA_VPD_NVRAM_ADDR
*4))
300 qla_printk(KERN_WARNING
, ha
,
301 "Invalid start region 0x%x/0x%x.\n", start
, size
);
305 ha
->optrom_region_start
= start
;
306 ha
->optrom_region_size
= start
+ size
> ha
->optrom_size
?
307 ha
->optrom_size
- start
: size
;
309 ha
->optrom_state
= QLA_SWRITING
;
310 ha
->optrom_buffer
= vmalloc(ha
->optrom_region_size
);
311 if (ha
->optrom_buffer
== NULL
) {
312 qla_printk(KERN_WARNING
, ha
,
313 "Unable to allocate memory for optrom update "
314 "(%x).\n", ha
->optrom_region_size
);
316 ha
->optrom_state
= QLA_SWAITING
;
320 DEBUG2(qla_printk(KERN_INFO
, ha
,
321 "Staging flash region write -- 0x%x/0x%x.\n",
322 ha
->optrom_region_start
, ha
->optrom_region_size
));
324 memset(ha
->optrom_buffer
, 0, ha
->optrom_region_size
);
327 if (ha
->optrom_state
!= QLA_SWRITING
)
330 DEBUG2(qla_printk(KERN_INFO
, ha
,
331 "Writing flash region -- 0x%x/0x%x.\n",
332 ha
->optrom_region_start
, ha
->optrom_region_size
));
334 ha
->isp_ops
->write_optrom(ha
, ha
->optrom_buffer
,
335 ha
->optrom_region_start
, ha
->optrom_region_size
);
343 static struct bin_attribute sysfs_optrom_ctl_attr
= {
345 .name
= "optrom_ctl",
349 .write
= qla2x00_sysfs_write_optrom_ctl
,
353 qla2x00_sysfs_read_vpd(struct kobject
*kobj
,
354 struct bin_attribute
*bin_attr
,
355 char *buf
, loff_t off
, size_t count
)
357 struct scsi_qla_host
*ha
= shost_priv(dev_to_shost(container_of(kobj
,
358 struct device
, kobj
)));
360 if (!capable(CAP_SYS_ADMIN
))
363 /* Read NVRAM data from cache. */
364 return memory_read_from_buffer(buf
, count
, &off
, ha
->vpd
, ha
->vpd_size
);
368 qla2x00_sysfs_write_vpd(struct kobject
*kobj
,
369 struct bin_attribute
*bin_attr
,
370 char *buf
, loff_t off
, size_t count
)
372 struct scsi_qla_host
*ha
= shost_priv(dev_to_shost(container_of(kobj
,
373 struct device
, kobj
)));
375 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->vpd_size
)
379 ha
->isp_ops
->write_nvram(ha
, (uint8_t *)buf
, ha
->vpd_base
, count
);
380 ha
->isp_ops
->read_nvram(ha
, (uint8_t *)ha
->vpd
, ha
->vpd_base
, count
);
385 static struct bin_attribute sysfs_vpd_attr
= {
388 .mode
= S_IRUSR
| S_IWUSR
,
391 .read
= qla2x00_sysfs_read_vpd
,
392 .write
= qla2x00_sysfs_write_vpd
,
396 qla2x00_sysfs_read_sfp(struct kobject
*kobj
,
397 struct bin_attribute
*bin_attr
,
398 char *buf
, loff_t off
, size_t count
)
400 struct scsi_qla_host
*ha
= shost_priv(dev_to_shost(container_of(kobj
,
401 struct device
, kobj
)));
402 uint16_t iter
, addr
, offset
;
405 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= SFP_DEV_SIZE
* 2)
411 ha
->sfp_data
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
,
414 qla_printk(KERN_WARNING
, ha
,
415 "Unable to allocate memory for SFP read-data.\n");
420 memset(ha
->sfp_data
, 0, SFP_BLOCK_SIZE
);
422 for (iter
= 0, offset
= 0; iter
< (SFP_DEV_SIZE
* 2) / SFP_BLOCK_SIZE
;
423 iter
++, offset
+= SFP_BLOCK_SIZE
) {
425 /* Skip to next device address. */
430 rval
= qla2x00_read_sfp(ha
, ha
->sfp_data_dma
, addr
, offset
,
432 if (rval
!= QLA_SUCCESS
) {
433 qla_printk(KERN_WARNING
, ha
,
434 "Unable to read SFP data (%x/%x/%x).\n", rval
,
439 memcpy(buf
, ha
->sfp_data
, SFP_BLOCK_SIZE
);
440 buf
+= SFP_BLOCK_SIZE
;
446 static struct bin_attribute sysfs_sfp_attr
= {
449 .mode
= S_IRUSR
| S_IWUSR
,
451 .size
= SFP_DEV_SIZE
* 2,
452 .read
= qla2x00_sysfs_read_sfp
,
455 static struct sysfs_entry
{
457 struct bin_attribute
*attr
;
459 } bin_file_entries
[] = {
460 { "fw_dump", &sysfs_fw_dump_attr
, },
461 { "nvram", &sysfs_nvram_attr
, },
462 { "optrom", &sysfs_optrom_attr
, },
463 { "optrom_ctl", &sysfs_optrom_ctl_attr
, },
464 { "vpd", &sysfs_vpd_attr
, 1 },
465 { "sfp", &sysfs_sfp_attr
, 1 },
470 qla2x00_alloc_sysfs_attr(scsi_qla_host_t
*ha
)
472 struct Scsi_Host
*host
= ha
->host
;
473 struct sysfs_entry
*iter
;
476 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
477 if (iter
->is4GBp_only
&& !IS_FWI2_CAPABLE(ha
))
480 ret
= sysfs_create_bin_file(&host
->shost_gendev
.kobj
,
483 qla_printk(KERN_INFO
, ha
,
484 "Unable to create sysfs %s binary attribute "
485 "(%d).\n", iter
->name
, ret
);
490 qla2x00_free_sysfs_attr(scsi_qla_host_t
*ha
)
492 struct Scsi_Host
*host
= ha
->host
;
493 struct sysfs_entry
*iter
;
495 for (iter
= bin_file_entries
; iter
->name
; iter
++) {
496 if (iter
->is4GBp_only
&& !IS_FWI2_CAPABLE(ha
))
499 sysfs_remove_bin_file(&host
->shost_gendev
.kobj
,
503 if (ha
->beacon_blink_led
== 1)
504 ha
->isp_ops
->beacon_off(ha
);
507 /* Scsi_Host attributes. */
510 qla2x00_drvr_version_show(struct device
*dev
,
511 struct device_attribute
*attr
, char *buf
)
513 return snprintf(buf
, PAGE_SIZE
, "%s\n", qla2x00_version_str
);
517 qla2x00_fw_version_show(struct device
*dev
,
518 struct device_attribute
*attr
, char *buf
)
520 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
523 return snprintf(buf
, PAGE_SIZE
, "%s\n",
524 ha
->isp_ops
->fw_version_str(ha
, fw_str
));
528 qla2x00_serial_num_show(struct device
*dev
, struct device_attribute
*attr
,
531 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
534 if (IS_FWI2_CAPABLE(ha
)) {
535 qla2xxx_get_vpd_field(ha
, "SN", buf
, PAGE_SIZE
);
536 return snprintf(buf
, PAGE_SIZE
, "%s\n", buf
);
539 sn
= ((ha
->serial0
& 0x1f) << 16) | (ha
->serial2
<< 8) | ha
->serial1
;
540 return snprintf(buf
, PAGE_SIZE
, "%c%05d\n", 'A' + sn
/ 100000,
545 qla2x00_isp_name_show(struct device
*dev
, struct device_attribute
*attr
,
548 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
549 return snprintf(buf
, PAGE_SIZE
, "ISP%04X\n", ha
->pdev
->device
);
553 qla2x00_isp_id_show(struct device
*dev
, struct device_attribute
*attr
,
556 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
557 return snprintf(buf
, PAGE_SIZE
, "%04x %04x %04x %04x\n",
558 ha
->product_id
[0], ha
->product_id
[1], ha
->product_id
[2],
563 qla2x00_model_name_show(struct device
*dev
, struct device_attribute
*attr
,
566 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
567 return snprintf(buf
, PAGE_SIZE
, "%s\n", ha
->model_number
);
571 qla2x00_model_desc_show(struct device
*dev
, struct device_attribute
*attr
,
574 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
575 return snprintf(buf
, PAGE_SIZE
, "%s\n",
576 ha
->model_desc
? ha
->model_desc
: "");
580 qla2x00_pci_info_show(struct device
*dev
, struct device_attribute
*attr
,
583 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
586 return snprintf(buf
, PAGE_SIZE
, "%s\n",
587 ha
->isp_ops
->pci_info_str(ha
, pci_info
));
591 qla2x00_link_state_show(struct device
*dev
, struct device_attribute
*attr
,
594 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
597 if (atomic_read(&ha
->loop_state
) == LOOP_DOWN
||
598 atomic_read(&ha
->loop_state
) == LOOP_DEAD
)
599 len
= snprintf(buf
, PAGE_SIZE
, "Link Down\n");
600 else if (atomic_read(&ha
->loop_state
) != LOOP_READY
||
601 test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) ||
602 test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
))
603 len
= snprintf(buf
, PAGE_SIZE
, "Unknown Link State\n");
605 len
= snprintf(buf
, PAGE_SIZE
, "Link Up - ");
607 switch (ha
->current_topology
) {
609 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
612 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "FL_Port\n");
615 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
616 "N_Port to N_Port\n");
619 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "F_Port\n");
622 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
630 qla2x00_zio_show(struct device
*dev
, struct device_attribute
*attr
,
633 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
636 switch (ha
->zio_mode
) {
638 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Mode 6\n");
640 case QLA_ZIO_DISABLED
:
641 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
648 qla2x00_zio_store(struct device
*dev
, struct device_attribute
*attr
,
649 const char *buf
, size_t count
)
651 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
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 device
*dev
, struct device_attribute
*attr
,
678 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
680 return snprintf(buf
, PAGE_SIZE
, "%d us\n", ha
->zio_timer
* 100);
684 qla2x00_zio_timer_store(struct device
*dev
, struct device_attribute
*attr
,
685 const char *buf
, size_t count
)
687 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
691 if (sscanf(buf
, "%d", &val
) != 1)
693 if (val
> 25500 || val
< 100)
696 zio_timer
= (uint16_t)(val
/ 100);
697 ha
->zio_timer
= zio_timer
;
703 qla2x00_beacon_show(struct device
*dev
, struct device_attribute
*attr
,
706 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
709 if (ha
->beacon_blink_led
)
710 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Enabled\n");
712 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
717 qla2x00_beacon_store(struct device
*dev
, struct device_attribute
*attr
,
718 const char *buf
, size_t count
)
720 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
724 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
727 if (test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
)) {
728 qla_printk(KERN_WARNING
, ha
,
729 "Abort ISP active -- ignoring beacon request.\n");
733 if (sscanf(buf
, "%d", &val
) != 1)
737 rval
= ha
->isp_ops
->beacon_on(ha
);
739 rval
= ha
->isp_ops
->beacon_off(ha
);
741 if (rval
!= QLA_SUCCESS
)
748 qla2x00_optrom_bios_version_show(struct device
*dev
,
749 struct device_attribute
*attr
, char *buf
)
751 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
753 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->bios_revision
[1],
754 ha
->bios_revision
[0]);
758 qla2x00_optrom_efi_version_show(struct device
*dev
,
759 struct device_attribute
*attr
, char *buf
)
761 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
763 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->efi_revision
[1],
764 ha
->efi_revision
[0]);
768 qla2x00_optrom_fcode_version_show(struct device
*dev
,
769 struct device_attribute
*attr
, char *buf
)
771 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
773 return snprintf(buf
, PAGE_SIZE
, "%d.%02d\n", ha
->fcode_revision
[1],
774 ha
->fcode_revision
[0]);
778 qla2x00_optrom_fw_version_show(struct device
*dev
,
779 struct device_attribute
*attr
, char *buf
)
781 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
783 return snprintf(buf
, PAGE_SIZE
, "%d.%02d.%02d %d\n",
784 ha
->fw_revision
[0], ha
->fw_revision
[1], ha
->fw_revision
[2],
789 qla2x00_total_isp_aborts_show(struct device
*dev
,
790 struct device_attribute
*attr
, char *buf
)
792 scsi_qla_host_t
*ha
= shost_priv(class_to_shost(dev
));
794 return snprintf(buf
, PAGE_SIZE
, "%d\n",
795 ha
->qla_stats
.total_isp_aborts
);
798 static DEVICE_ATTR(driver_version
, S_IRUGO
, qla2x00_drvr_version_show
, NULL
);
799 static DEVICE_ATTR(fw_version
, S_IRUGO
, qla2x00_fw_version_show
, NULL
);
800 static DEVICE_ATTR(serial_num
, S_IRUGO
, qla2x00_serial_num_show
, NULL
);
801 static DEVICE_ATTR(isp_name
, S_IRUGO
, qla2x00_isp_name_show
, NULL
);
802 static DEVICE_ATTR(isp_id
, S_IRUGO
, qla2x00_isp_id_show
, NULL
);
803 static DEVICE_ATTR(model_name
, S_IRUGO
, qla2x00_model_name_show
, NULL
);
804 static DEVICE_ATTR(model_desc
, S_IRUGO
, qla2x00_model_desc_show
, NULL
);
805 static DEVICE_ATTR(pci_info
, S_IRUGO
, qla2x00_pci_info_show
, NULL
);
806 static DEVICE_ATTR(link_state
, S_IRUGO
, qla2x00_link_state_show
, NULL
);
807 static DEVICE_ATTR(zio
, S_IRUGO
| S_IWUSR
, qla2x00_zio_show
, qla2x00_zio_store
);
808 static DEVICE_ATTR(zio_timer
, S_IRUGO
| S_IWUSR
, qla2x00_zio_timer_show
,
809 qla2x00_zio_timer_store
);
810 static DEVICE_ATTR(beacon
, S_IRUGO
| S_IWUSR
, qla2x00_beacon_show
,
811 qla2x00_beacon_store
);
812 static DEVICE_ATTR(optrom_bios_version
, S_IRUGO
,
813 qla2x00_optrom_bios_version_show
, NULL
);
814 static DEVICE_ATTR(optrom_efi_version
, S_IRUGO
,
815 qla2x00_optrom_efi_version_show
, NULL
);
816 static DEVICE_ATTR(optrom_fcode_version
, S_IRUGO
,
817 qla2x00_optrom_fcode_version_show
, NULL
);
818 static DEVICE_ATTR(optrom_fw_version
, S_IRUGO
, qla2x00_optrom_fw_version_show
,
820 static DEVICE_ATTR(total_isp_aborts
, S_IRUGO
, qla2x00_total_isp_aborts_show
,
823 struct device_attribute
*qla2x00_host_attrs
[] = {
824 &dev_attr_driver_version
,
825 &dev_attr_fw_version
,
826 &dev_attr_serial_num
,
829 &dev_attr_model_name
,
830 &dev_attr_model_desc
,
832 &dev_attr_link_state
,
836 &dev_attr_optrom_bios_version
,
837 &dev_attr_optrom_efi_version
,
838 &dev_attr_optrom_fcode_version
,
839 &dev_attr_optrom_fw_version
,
840 &dev_attr_total_isp_aborts
,
844 /* Host attributes. */
847 qla2x00_get_host_port_id(struct Scsi_Host
*shost
)
849 scsi_qla_host_t
*ha
= shost_priv(shost
);
851 fc_host_port_id(shost
) = ha
->d_id
.b
.domain
<< 16 |
852 ha
->d_id
.b
.area
<< 8 | ha
->d_id
.b
.al_pa
;
856 qla2x00_get_host_speed(struct Scsi_Host
*shost
)
858 scsi_qla_host_t
*ha
= to_qla_parent(shost_priv(shost
));
859 u32 speed
= FC_PORTSPEED_UNKNOWN
;
861 switch (ha
->link_data_rate
) {
863 speed
= FC_PORTSPEED_1GBIT
;
866 speed
= FC_PORTSPEED_2GBIT
;
869 speed
= FC_PORTSPEED_4GBIT
;
872 speed
= FC_PORTSPEED_8GBIT
;
875 fc_host_speed(shost
) = speed
;
879 qla2x00_get_host_port_type(struct Scsi_Host
*shost
)
881 scsi_qla_host_t
*ha
= shost_priv(shost
);
882 uint32_t port_type
= FC_PORTTYPE_UNKNOWN
;
885 fc_host_port_type(shost
) = FC_PORTTYPE_NPIV
;
888 switch (ha
->current_topology
) {
890 port_type
= FC_PORTTYPE_LPORT
;
893 port_type
= FC_PORTTYPE_NLPORT
;
896 port_type
= FC_PORTTYPE_PTP
;
899 port_type
= FC_PORTTYPE_NPORT
;
902 fc_host_port_type(shost
) = port_type
;
906 qla2x00_get_starget_node_name(struct scsi_target
*starget
)
908 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
909 scsi_qla_host_t
*ha
= shost_priv(host
);
913 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
915 starget
->id
== fcport
->rport
->scsi_target_id
) {
916 node_name
= wwn_to_u64(fcport
->node_name
);
921 fc_starget_node_name(starget
) = node_name
;
925 qla2x00_get_starget_port_name(struct scsi_target
*starget
)
927 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
928 scsi_qla_host_t
*ha
= shost_priv(host
);
932 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
934 starget
->id
== fcport
->rport
->scsi_target_id
) {
935 port_name
= wwn_to_u64(fcport
->port_name
);
940 fc_starget_port_name(starget
) = port_name
;
944 qla2x00_get_starget_port_id(struct scsi_target
*starget
)
946 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
947 scsi_qla_host_t
*ha
= shost_priv(host
);
949 uint32_t port_id
= ~0U;
951 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
953 starget
->id
== fcport
->rport
->scsi_target_id
) {
954 port_id
= fcport
->d_id
.b
.domain
<< 16 |
955 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
960 fc_starget_port_id(starget
) = port_id
;
964 qla2x00_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
967 rport
->dev_loss_tmo
= timeout
;
969 rport
->dev_loss_tmo
= 1;
973 qla2x00_dev_loss_tmo_callbk(struct fc_rport
*rport
)
975 struct Scsi_Host
*host
= rport_to_shost(rport
);
976 fc_port_t
*fcport
= *(fc_port_t
**)rport
->dd_data
;
978 qla2x00_abort_fcport_cmds(fcport
);
981 * Transport has effectively 'deleted' the rport, clear
982 * all local references.
984 spin_lock_irq(host
->host_lock
);
985 fcport
->rport
= NULL
;
986 *((fc_port_t
**)rport
->dd_data
) = NULL
;
987 spin_unlock_irq(host
->host_lock
);
991 qla2x00_terminate_rport_io(struct fc_rport
*rport
)
993 fc_port_t
*fcport
= *(fc_port_t
**)rport
->dd_data
;
995 qla2x00_abort_fcport_cmds(fcport
);
996 scsi_target_unblock(&rport
->dev
);
1000 qla2x00_issue_lip(struct Scsi_Host
*shost
)
1002 scsi_qla_host_t
*ha
= shost_priv(shost
);
1004 qla2x00_loop_reset(ha
);
1008 static struct fc_host_statistics
*
1009 qla2x00_get_fc_host_stats(struct Scsi_Host
*shost
)
1011 scsi_qla_host_t
*ha
= to_qla_parent(shost_priv(shost
));
1013 struct link_statistics
*stats
;
1014 dma_addr_t stats_dma
;
1015 struct fc_host_statistics
*pfc_host_stat
;
1017 pfc_host_stat
= &ha
->fc_host_stat
;
1018 memset(pfc_host_stat
, -1, sizeof(struct fc_host_statistics
));
1020 stats
= dma_pool_alloc(ha
->s_dma_pool
, GFP_KERNEL
, &stats_dma
);
1021 if (stats
== NULL
) {
1022 DEBUG2_3_11(printk("%s(%ld): Failed to allocate memory.\n",
1023 __func__
, ha
->host_no
));
1026 memset(stats
, 0, DMA_POOL_SIZE
);
1028 rval
= QLA_FUNCTION_FAILED
;
1029 if (IS_FWI2_CAPABLE(ha
)) {
1030 rval
= qla24xx_get_isp_stats(ha
, stats
, stats_dma
);
1031 } else if (atomic_read(&ha
->loop_state
) == LOOP_READY
&&
1032 !test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) &&
1033 !test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
) &&
1035 /* Must be in a 'READY' state for statistics retrieval. */
1036 rval
= qla2x00_get_link_status(ha
, ha
->loop_id
, stats
,
1040 if (rval
!= QLA_SUCCESS
)
1043 pfc_host_stat
->link_failure_count
= stats
->link_fail_cnt
;
1044 pfc_host_stat
->loss_of_sync_count
= stats
->loss_sync_cnt
;
1045 pfc_host_stat
->loss_of_signal_count
= stats
->loss_sig_cnt
;
1046 pfc_host_stat
->prim_seq_protocol_err_count
= stats
->prim_seq_err_cnt
;
1047 pfc_host_stat
->invalid_tx_word_count
= stats
->inval_xmit_word_cnt
;
1048 pfc_host_stat
->invalid_crc_count
= stats
->inval_crc_cnt
;
1049 if (IS_FWI2_CAPABLE(ha
)) {
1050 pfc_host_stat
->lip_count
= stats
->lip_cnt
;
1051 pfc_host_stat
->tx_frames
= stats
->tx_frames
;
1052 pfc_host_stat
->rx_frames
= stats
->rx_frames
;
1053 pfc_host_stat
->dumped_frames
= stats
->dumped_frames
;
1054 pfc_host_stat
->nos_count
= stats
->nos_rcvd
;
1058 dma_pool_free(ha
->s_dma_pool
, stats
, stats_dma
);
1060 return pfc_host_stat
;
1064 qla2x00_get_host_symbolic_name(struct Scsi_Host
*shost
)
1066 scsi_qla_host_t
*ha
= shost_priv(shost
);
1068 qla2x00_get_sym_node_name(ha
, fc_host_symbolic_name(shost
));
1072 qla2x00_set_host_system_hostname(struct Scsi_Host
*shost
)
1074 scsi_qla_host_t
*ha
= shost_priv(shost
);
1076 set_bit(REGISTER_FDMI_NEEDED
, &ha
->dpc_flags
);
1080 qla2x00_get_host_fabric_name(struct Scsi_Host
*shost
)
1082 scsi_qla_host_t
*ha
= shost_priv(shost
);
1085 if (ha
->device_flags
& SWITCH_FOUND
)
1086 node_name
= wwn_to_u64(ha
->fabric_node_name
);
1088 node_name
= wwn_to_u64(ha
->node_name
);
1090 fc_host_fabric_name(shost
) = node_name
;
1094 qla2x00_get_host_port_state(struct Scsi_Host
*shost
)
1096 scsi_qla_host_t
*ha
= to_qla_parent(shost_priv(shost
));
1098 if (!ha
->flags
.online
)
1099 fc_host_port_state(shost
) = FC_PORTSTATE_OFFLINE
;
1100 else if (atomic_read(&ha
->loop_state
) == LOOP_TIMEOUT
)
1101 fc_host_port_state(shost
) = FC_PORTSTATE_UNKNOWN
;
1103 fc_host_port_state(shost
) = FC_PORTSTATE_ONLINE
;
1107 qla24xx_vport_create(struct fc_vport
*fc_vport
, bool disable
)
1110 scsi_qla_host_t
*ha
= shost_priv(fc_vport
->shost
);
1111 scsi_qla_host_t
*vha
;
1113 ret
= qla24xx_vport_create_req_sanity_check(fc_vport
);
1115 DEBUG15(printk("qla24xx_vport_create_req_sanity_check failed, "
1116 "status %x\n", ret
));
1120 vha
= qla24xx_create_vhost(fc_vport
);
1122 DEBUG15(printk ("qla24xx_create_vhost failed, vha = %p\n",
1124 return FC_VPORT_FAILED
;
1127 atomic_set(&vha
->vp_state
, VP_OFFLINE
);
1128 fc_vport_set_state(fc_vport
, FC_VPORT_DISABLED
);
1130 atomic_set(&vha
->vp_state
, VP_FAILED
);
1132 /* ready to create vport */
1133 qla_printk(KERN_INFO
, vha
, "VP entry id %d assigned.\n", vha
->vp_idx
);
1135 /* initialized vport states */
1136 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1137 vha
->vp_err_state
= VP_ERR_PORTDWN
;
1138 vha
->vp_prev_err_state
= VP_ERR_UNKWN
;
1139 /* Check if physical ha port is Up */
1140 if (atomic_read(&ha
->loop_state
) == LOOP_DOWN
||
1141 atomic_read(&ha
->loop_state
) == LOOP_DEAD
) {
1142 /* Don't retry or attempt login of this virtual port */
1143 DEBUG15(printk ("scsi(%ld): pport loop_state is not UP.\n",
1145 atomic_set(&vha
->loop_state
, LOOP_DEAD
);
1147 fc_vport_set_state(fc_vport
, FC_VPORT_LINKDOWN
);
1150 if (scsi_add_host(vha
->host
, &fc_vport
->dev
)) {
1151 DEBUG15(printk("scsi(%ld): scsi_add_host failure for VP[%d].\n",
1152 vha
->host_no
, vha
->vp_idx
));
1153 goto vport_create_failed_2
;
1156 /* initialize attributes */
1157 fc_host_node_name(vha
->host
) = wwn_to_u64(vha
->node_name
);
1158 fc_host_port_name(vha
->host
) = wwn_to_u64(vha
->port_name
);
1159 fc_host_supported_classes(vha
->host
) =
1160 fc_host_supported_classes(ha
->host
);
1161 fc_host_supported_speeds(vha
->host
) =
1162 fc_host_supported_speeds(ha
->host
);
1164 qla24xx_vport_disable(fc_vport
, disable
);
1167 vport_create_failed_2
:
1168 qla24xx_disable_vp(vha
);
1169 qla24xx_deallocate_vp_id(vha
);
1170 kfree(vha
->port_name
);
1171 kfree(vha
->node_name
);
1172 scsi_host_put(vha
->host
);
1173 return FC_VPORT_FAILED
;
1177 qla24xx_vport_delete(struct fc_vport
*fc_vport
)
1179 scsi_qla_host_t
*vha
= fc_vport
->dd_data
;
1181 qla24xx_disable_vp(vha
);
1182 qla24xx_deallocate_vp_id(vha
);
1184 kfree(vha
->node_name
);
1185 kfree(vha
->port_name
);
1187 if (vha
->timer_active
) {
1188 qla2x00_vp_stop_timer(vha
);
1189 DEBUG15(printk ("scsi(%ld): timer for the vport[%d] = %p "
1191 vha
->host_no
, vha
->vp_idx
, vha
));
1194 fc_remove_host(vha
->host
);
1196 scsi_remove_host(vha
->host
);
1198 scsi_host_put(vha
->host
);
1204 qla24xx_vport_disable(struct fc_vport
*fc_vport
, bool disable
)
1206 scsi_qla_host_t
*vha
= fc_vport
->dd_data
;
1209 qla24xx_disable_vp(vha
);
1211 qla24xx_enable_vp(vha
);
1216 struct fc_function_template qla2xxx_transport_functions
= {
1218 .show_host_node_name
= 1,
1219 .show_host_port_name
= 1,
1220 .show_host_supported_classes
= 1,
1221 .show_host_supported_speeds
= 1,
1223 .get_host_port_id
= qla2x00_get_host_port_id
,
1224 .show_host_port_id
= 1,
1225 .get_host_speed
= qla2x00_get_host_speed
,
1226 .show_host_speed
= 1,
1227 .get_host_port_type
= qla2x00_get_host_port_type
,
1228 .show_host_port_type
= 1,
1229 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
1230 .show_host_symbolic_name
= 1,
1231 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
1232 .show_host_system_hostname
= 1,
1233 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
1234 .show_host_fabric_name
= 1,
1235 .get_host_port_state
= qla2x00_get_host_port_state
,
1236 .show_host_port_state
= 1,
1238 .dd_fcrport_size
= sizeof(struct fc_port
*),
1239 .show_rport_supported_classes
= 1,
1241 .get_starget_node_name
= qla2x00_get_starget_node_name
,
1242 .show_starget_node_name
= 1,
1243 .get_starget_port_name
= qla2x00_get_starget_port_name
,
1244 .show_starget_port_name
= 1,
1245 .get_starget_port_id
= qla2x00_get_starget_port_id
,
1246 .show_starget_port_id
= 1,
1248 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
1249 .show_rport_dev_loss_tmo
= 1,
1251 .issue_fc_host_lip
= qla2x00_issue_lip
,
1252 .dev_loss_tmo_callbk
= qla2x00_dev_loss_tmo_callbk
,
1253 .terminate_rport_io
= qla2x00_terminate_rport_io
,
1254 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
1256 .vport_create
= qla24xx_vport_create
,
1257 .vport_disable
= qla24xx_vport_disable
,
1258 .vport_delete
= qla24xx_vport_delete
,
1261 struct fc_function_template qla2xxx_transport_vport_functions
= {
1263 .show_host_node_name
= 1,
1264 .show_host_port_name
= 1,
1265 .show_host_supported_classes
= 1,
1267 .get_host_port_id
= qla2x00_get_host_port_id
,
1268 .show_host_port_id
= 1,
1269 .get_host_speed
= qla2x00_get_host_speed
,
1270 .show_host_speed
= 1,
1271 .get_host_port_type
= qla2x00_get_host_port_type
,
1272 .show_host_port_type
= 1,
1273 .get_host_symbolic_name
= qla2x00_get_host_symbolic_name
,
1274 .show_host_symbolic_name
= 1,
1275 .set_host_system_hostname
= qla2x00_set_host_system_hostname
,
1276 .show_host_system_hostname
= 1,
1277 .get_host_fabric_name
= qla2x00_get_host_fabric_name
,
1278 .show_host_fabric_name
= 1,
1279 .get_host_port_state
= qla2x00_get_host_port_state
,
1280 .show_host_port_state
= 1,
1282 .dd_fcrport_size
= sizeof(struct fc_port
*),
1283 .show_rport_supported_classes
= 1,
1285 .get_starget_node_name
= qla2x00_get_starget_node_name
,
1286 .show_starget_node_name
= 1,
1287 .get_starget_port_name
= qla2x00_get_starget_port_name
,
1288 .show_starget_port_name
= 1,
1289 .get_starget_port_id
= qla2x00_get_starget_port_id
,
1290 .show_starget_port_id
= 1,
1292 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
1293 .show_rport_dev_loss_tmo
= 1,
1295 .issue_fc_host_lip
= qla2x00_issue_lip
,
1296 .dev_loss_tmo_callbk
= qla2x00_dev_loss_tmo_callbk
,
1297 .terminate_rport_io
= qla2x00_terminate_rport_io
,
1298 .get_fc_host_stats
= qla2x00_get_fc_host_stats
,
1302 qla2x00_init_host_attr(scsi_qla_host_t
*ha
)
1304 u32 speed
= FC_PORTSPEED_UNKNOWN
;
1306 fc_host_node_name(ha
->host
) = wwn_to_u64(ha
->node_name
);
1307 fc_host_port_name(ha
->host
) = wwn_to_u64(ha
->port_name
);
1308 fc_host_supported_classes(ha
->host
) = FC_COS_CLASS3
;
1309 fc_host_max_npiv_vports(ha
->host
) = ha
->max_npiv_vports
;;
1310 fc_host_npiv_vports_inuse(ha
->host
) = ha
->cur_vport_count
;
1313 speed
= FC_PORTSPEED_8GBIT
| FC_PORTSPEED_4GBIT
|
1314 FC_PORTSPEED_2GBIT
| FC_PORTSPEED_1GBIT
;
1315 else if (IS_QLA24XX_TYPE(ha
))
1316 speed
= FC_PORTSPEED_4GBIT
| FC_PORTSPEED_2GBIT
|
1318 else if (IS_QLA23XX(ha
))
1319 speed
= FC_PORTSPEED_2GBIT
| FC_PORTSPEED_1GBIT
;
1321 speed
= FC_PORTSPEED_1GBIT
;
1322 fc_host_supported_speeds(ha
->host
) = speed
;