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>
10 #include <scsi/scsi_transport_fc.h>
12 /* SYSFS attributes --------------------------------------------------------- */
15 qla2x00_sysfs_read_fw_dump(struct kobject
*kobj
, char *buf
, loff_t off
,
18 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
19 struct device
, kobj
)));
21 if (ha
->fw_dump_reading
== 0)
23 if (off
> ha
->fw_dump_buffer_len
)
25 if (off
+ count
> ha
->fw_dump_buffer_len
)
26 count
= ha
->fw_dump_buffer_len
- off
;
28 memcpy(buf
, &ha
->fw_dump_buffer
[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
)));
45 reading
= simple_strtol(buf
, NULL
, 10);
48 if (ha
->fw_dump_reading
== 1) {
49 qla_printk(KERN_INFO
, ha
,
50 "Firmware dump cleared on (%ld).\n",
53 vfree(ha
->fw_dump_buffer
);
54 if (!IS_QLA24XX(ha
) && !IS_QLA25XX(ha
))
55 free_pages((unsigned long)ha
->fw_dump
,
58 ha
->fw_dump_reading
= 0;
59 ha
->fw_dump_buffer
= NULL
;
65 if ((ha
->fw_dump
|| ha
->fw_dumped
) && !ha
->fw_dump_reading
) {
66 ha
->fw_dump_reading
= 1;
68 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
))
69 dump_size
= FW_DUMP_SIZE_24XX
;
71 dump_size
= FW_DUMP_SIZE_1M
;
72 if (ha
->fw_memory_size
< 0x20000)
73 dump_size
= FW_DUMP_SIZE_128K
;
74 else if (ha
->fw_memory_size
< 0x80000)
75 dump_size
= FW_DUMP_SIZE_512K
;
77 ha
->fw_dump_buffer
= (char *)vmalloc(dump_size
);
78 if (ha
->fw_dump_buffer
== NULL
) {
79 qla_printk(KERN_WARNING
, ha
,
80 "Unable to allocate memory for firmware "
81 "dump buffer (%d).\n", dump_size
);
83 ha
->fw_dump_reading
= 0;
86 qla_printk(KERN_INFO
, ha
,
87 "Firmware dump ready for read on (%ld).\n",
89 memset(ha
->fw_dump_buffer
, 0, dump_size
);
90 ha
->isp_ops
.ascii_fw_dump(ha
);
91 ha
->fw_dump_buffer_len
= strlen(ha
->fw_dump_buffer
);
98 static struct bin_attribute sysfs_fw_dump_attr
= {
101 .mode
= S_IRUSR
| S_IWUSR
,
102 .owner
= THIS_MODULE
,
105 .read
= qla2x00_sysfs_read_fw_dump
,
106 .write
= qla2x00_sysfs_write_fw_dump
,
110 qla2x00_sysfs_read_nvram(struct kobject
*kobj
, char *buf
, loff_t off
,
113 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
114 struct device
, kobj
)));
117 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->nvram_size
)
121 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
122 ha
->isp_ops
.read_nvram(ha
, (uint8_t *)buf
, ha
->nvram_base
,
124 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
130 qla2x00_sysfs_write_nvram(struct kobject
*kobj
, char *buf
, loff_t off
,
133 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
134 struct device
, kobj
)));
138 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= ha
->nvram_size
)
141 /* Checksum NVRAM. */
142 if (IS_QLA24XX(ha
) || IS_QLA25XX(ha
)) {
146 iter
= (uint32_t *)buf
;
148 for (cnt
= 0; cnt
< ((count
>> 2) - 1); cnt
++)
149 chksum
+= le32_to_cpu(*iter
++);
150 chksum
= ~chksum
+ 1;
151 *iter
= cpu_to_le32(chksum
);
156 iter
= (uint8_t *)buf
;
158 for (cnt
= 0; cnt
< count
- 1; cnt
++)
160 chksum
= ~chksum
+ 1;
165 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
166 ha
->isp_ops
.write_nvram(ha
, (uint8_t *)buf
, ha
->nvram_base
, count
);
167 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
172 static struct bin_attribute sysfs_nvram_attr
= {
175 .mode
= S_IRUSR
| S_IWUSR
,
176 .owner
= THIS_MODULE
,
179 .read
= qla2x00_sysfs_read_nvram
,
180 .write
= qla2x00_sysfs_write_nvram
,
184 qla2x00_alloc_sysfs_attr(scsi_qla_host_t
*ha
)
186 struct Scsi_Host
*host
= ha
->host
;
188 sysfs_create_bin_file(&host
->shost_gendev
.kobj
, &sysfs_fw_dump_attr
);
189 sysfs_nvram_attr
.size
= ha
->nvram_size
;
190 sysfs_create_bin_file(&host
->shost_gendev
.kobj
, &sysfs_nvram_attr
);
194 qla2x00_free_sysfs_attr(scsi_qla_host_t
*ha
)
196 struct Scsi_Host
*host
= ha
->host
;
198 sysfs_remove_bin_file(&host
->shost_gendev
.kobj
, &sysfs_fw_dump_attr
);
199 sysfs_remove_bin_file(&host
->shost_gendev
.kobj
, &sysfs_nvram_attr
);
202 /* Scsi_Host attributes. */
205 qla2x00_drvr_version_show(struct class_device
*cdev
, char *buf
)
207 return snprintf(buf
, PAGE_SIZE
, "%s\n", qla2x00_version_str
);
211 qla2x00_fw_version_show(struct class_device
*cdev
, char *buf
)
213 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
216 return snprintf(buf
, PAGE_SIZE
, "%s\n",
217 ha
->isp_ops
.fw_version_str(ha
, fw_str
));
221 qla2x00_serial_num_show(struct class_device
*cdev
, char *buf
)
223 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
226 sn
= ((ha
->serial0
& 0x1f) << 16) | (ha
->serial2
<< 8) | ha
->serial1
;
227 return snprintf(buf
, PAGE_SIZE
, "%c%05d\n", 'A' + sn
/ 100000,
232 qla2x00_isp_name_show(struct class_device
*cdev
, char *buf
)
234 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
235 return snprintf(buf
, PAGE_SIZE
, "%s\n", ha
->brd_info
->isp_name
);
239 qla2x00_isp_id_show(struct class_device
*cdev
, char *buf
)
241 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
242 return snprintf(buf
, PAGE_SIZE
, "%04x %04x %04x %04x\n",
243 ha
->product_id
[0], ha
->product_id
[1], ha
->product_id
[2],
248 qla2x00_model_name_show(struct class_device
*cdev
, char *buf
)
250 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
251 return snprintf(buf
, PAGE_SIZE
, "%s\n", ha
->model_number
);
255 qla2x00_model_desc_show(struct class_device
*cdev
, char *buf
)
257 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
258 return snprintf(buf
, PAGE_SIZE
, "%s\n",
259 ha
->model_desc
? ha
->model_desc
: "");
263 qla2x00_pci_info_show(struct class_device
*cdev
, char *buf
)
265 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
268 return snprintf(buf
, PAGE_SIZE
, "%s\n",
269 ha
->isp_ops
.pci_info_str(ha
, pci_info
));
273 qla2x00_state_show(struct class_device
*cdev
, char *buf
)
275 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
278 if (atomic_read(&ha
->loop_state
) == LOOP_DOWN
||
279 atomic_read(&ha
->loop_state
) == LOOP_DEAD
)
280 len
= snprintf(buf
, PAGE_SIZE
, "Link Down\n");
281 else if (atomic_read(&ha
->loop_state
) != LOOP_READY
||
282 test_bit(ABORT_ISP_ACTIVE
, &ha
->dpc_flags
) ||
283 test_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
))
284 len
= snprintf(buf
, PAGE_SIZE
, "Unknown Link State\n");
286 len
= snprintf(buf
, PAGE_SIZE
, "Link Up - ");
288 switch (ha
->current_topology
) {
290 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
293 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "FL_Port\n");
296 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
,
297 "N_Port to N_Port\n");
300 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "F_Port\n");
303 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Loop\n");
311 qla2x00_zio_show(struct class_device
*cdev
, char *buf
)
313 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
316 switch (ha
->zio_mode
) {
318 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Mode 5\n");
321 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Mode 6\n");
323 case QLA_ZIO_DISABLED
:
324 len
+= snprintf(buf
+ len
, PAGE_SIZE
-len
, "Disabled\n");
331 qla2x00_zio_store(struct class_device
*cdev
, const char *buf
, size_t count
)
333 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
337 if (sscanf(buf
, "%d", &val
) != 1)
342 zio_mode
= QLA_ZIO_MODE_5
;
345 zio_mode
= QLA_ZIO_MODE_6
;
348 zio_mode
= QLA_ZIO_DISABLED
;
352 /* Update per-hba values and queue a reset. */
353 if (zio_mode
!= QLA_ZIO_DISABLED
|| ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
354 ha
->zio_mode
= zio_mode
;
355 set_bit(ISP_ABORT_NEEDED
, &ha
->dpc_flags
);
361 qla2x00_zio_timer_show(struct class_device
*cdev
, char *buf
)
363 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
365 return snprintf(buf
, PAGE_SIZE
, "%d us\n", ha
->zio_timer
* 100);
369 qla2x00_zio_timer_store(struct class_device
*cdev
, const char *buf
,
372 scsi_qla_host_t
*ha
= to_qla_host(class_to_shost(cdev
));
376 if (sscanf(buf
, "%d", &val
) != 1)
378 if (val
> 25500 || val
< 100)
381 zio_timer
= (uint16_t)(val
/ 100);
382 ha
->zio_timer
= zio_timer
;
387 static CLASS_DEVICE_ATTR(driver_version
, S_IRUGO
, qla2x00_drvr_version_show
,
389 static CLASS_DEVICE_ATTR(fw_version
, S_IRUGO
, qla2x00_fw_version_show
, NULL
);
390 static CLASS_DEVICE_ATTR(serial_num
, S_IRUGO
, qla2x00_serial_num_show
, NULL
);
391 static CLASS_DEVICE_ATTR(isp_name
, S_IRUGO
, qla2x00_isp_name_show
, NULL
);
392 static CLASS_DEVICE_ATTR(isp_id
, S_IRUGO
, qla2x00_isp_id_show
, NULL
);
393 static CLASS_DEVICE_ATTR(model_name
, S_IRUGO
, qla2x00_model_name_show
, NULL
);
394 static CLASS_DEVICE_ATTR(model_desc
, S_IRUGO
, qla2x00_model_desc_show
, NULL
);
395 static CLASS_DEVICE_ATTR(pci_info
, S_IRUGO
, qla2x00_pci_info_show
, NULL
);
396 static CLASS_DEVICE_ATTR(state
, S_IRUGO
, qla2x00_state_show
, NULL
);
397 static CLASS_DEVICE_ATTR(zio
, S_IRUGO
| S_IWUSR
, qla2x00_zio_show
,
399 static CLASS_DEVICE_ATTR(zio_timer
, S_IRUGO
| S_IWUSR
, qla2x00_zio_timer_show
,
400 qla2x00_zio_timer_store
);
402 struct class_device_attribute
*qla2x00_host_attrs
[] = {
403 &class_device_attr_driver_version
,
404 &class_device_attr_fw_version
,
405 &class_device_attr_serial_num
,
406 &class_device_attr_isp_name
,
407 &class_device_attr_isp_id
,
408 &class_device_attr_model_name
,
409 &class_device_attr_model_desc
,
410 &class_device_attr_pci_info
,
411 &class_device_attr_state
,
412 &class_device_attr_zio
,
413 &class_device_attr_zio_timer
,
417 /* Host attributes. */
420 qla2x00_get_host_port_id(struct Scsi_Host
*shost
)
422 scsi_qla_host_t
*ha
= to_qla_host(shost
);
424 fc_host_port_id(shost
) = ha
->d_id
.b
.domain
<< 16 |
425 ha
->d_id
.b
.area
<< 8 | ha
->d_id
.b
.al_pa
;
429 qla2x00_get_starget_node_name(struct scsi_target
*starget
)
431 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
432 scsi_qla_host_t
*ha
= to_qla_host(host
);
436 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
437 if (starget
->id
== fcport
->os_target_id
) {
438 node_name
= wwn_to_u64(fcport
->node_name
);
443 fc_starget_node_name(starget
) = node_name
;
447 qla2x00_get_starget_port_name(struct scsi_target
*starget
)
449 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
450 scsi_qla_host_t
*ha
= to_qla_host(host
);
454 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
455 if (starget
->id
== fcport
->os_target_id
) {
456 port_name
= wwn_to_u64(fcport
->port_name
);
461 fc_starget_port_name(starget
) = port_name
;
465 qla2x00_get_starget_port_id(struct scsi_target
*starget
)
467 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
468 scsi_qla_host_t
*ha
= to_qla_host(host
);
470 uint32_t port_id
= ~0U;
472 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
473 if (starget
->id
== fcport
->os_target_id
) {
474 port_id
= fcport
->d_id
.b
.domain
<< 16 |
475 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
480 fc_starget_port_id(starget
) = port_id
;
484 qla2x00_get_rport_loss_tmo(struct fc_rport
*rport
)
486 struct Scsi_Host
*host
= rport_to_shost(rport
);
487 scsi_qla_host_t
*ha
= to_qla_host(host
);
489 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
493 qla2x00_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
495 struct Scsi_Host
*host
= rport_to_shost(rport
);
496 scsi_qla_host_t
*ha
= to_qla_host(host
);
499 ha
->port_down_retry_count
= timeout
;
501 ha
->port_down_retry_count
= 1;
503 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
507 qla2x00_issue_lip(struct Scsi_Host
*shost
)
509 scsi_qla_host_t
*ha
= to_qla_host(shost
);
511 set_bit(LOOP_RESET_NEEDED
, &ha
->dpc_flags
);
515 struct fc_function_template qla2xxx_transport_functions
= {
517 .show_host_node_name
= 1,
518 .show_host_port_name
= 1,
519 .show_host_supported_classes
= 1,
521 .get_host_port_id
= qla2x00_get_host_port_id
,
522 .show_host_port_id
= 1,
524 .dd_fcrport_size
= sizeof(struct fc_port
*),
525 .show_rport_supported_classes
= 1,
527 .get_starget_node_name
= qla2x00_get_starget_node_name
,
528 .show_starget_node_name
= 1,
529 .get_starget_port_name
= qla2x00_get_starget_port_name
,
530 .show_starget_port_name
= 1,
531 .get_starget_port_id
= qla2x00_get_starget_port_id
,
532 .show_starget_port_id
= 1,
534 .get_rport_dev_loss_tmo
= qla2x00_get_rport_loss_tmo
,
535 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
536 .show_rport_dev_loss_tmo
= 1,
538 .issue_fc_host_lip
= qla2x00_issue_lip
,
542 qla2x00_init_host_attr(scsi_qla_host_t
*ha
)
544 fc_host_node_name(ha
->host
) = wwn_to_u64(ha
->init_cb
->node_name
);
545 fc_host_port_name(ha
->host
) = wwn_to_u64(ha
->init_cb
->port_name
);
546 fc_host_supported_classes(ha
->host
) = FC_COS_CLASS3
;