2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
21 #include <linux/vmalloc.h>
22 #include <scsi/scsi_transport_fc.h>
24 /* SYSFS attributes --------------------------------------------------------- */
27 qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off,
30 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
31 struct device, kobj)));
33 if (ha->fw_dump_reading == 0)
35 if (off > ha->fw_dump_buffer_len)
37 if (off + count > ha->fw_dump_buffer_len)
38 count = ha->fw_dump_buffer_len - off;
40 memcpy(buf, &ha->fw_dump_buffer[off], count);
46 qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off,
49 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
50 struct device, kobj)));
57 reading = simple_strtol(buf, NULL, 10);
60 if (ha->fw_dump_reading == 1) {
61 qla_printk(KERN_INFO, ha,
62 "Firmware dump cleared on (%ld).\n",
65 vfree(ha->fw_dump_buffer);
66 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
67 free_pages((unsigned long)ha->fw_dump,
70 ha->fw_dump_reading = 0;
71 ha->fw_dump_buffer = NULL;
77 if ((ha->fw_dump || ha->fw_dumped) && !ha->fw_dump_reading) {
78 ha->fw_dump_reading = 1;
80 if (IS_QLA24XX(ha) || IS_QLA25XX(ha))
81 dump_size = FW_DUMP_SIZE_24XX;
83 dump_size = FW_DUMP_SIZE_1M;
84 if (ha->fw_memory_size < 0x20000)
85 dump_size = FW_DUMP_SIZE_128K;
86 else if (ha->fw_memory_size < 0x80000)
87 dump_size = FW_DUMP_SIZE_512K;
89 ha->fw_dump_buffer = (char *)vmalloc(dump_size);
90 if (ha->fw_dump_buffer == NULL) {
91 qla_printk(KERN_WARNING, ha,
92 "Unable to allocate memory for firmware "
93 "dump buffer (%d).\n", dump_size);
95 ha->fw_dump_reading = 0;
98 qla_printk(KERN_INFO, ha,
99 "Firmware dump ready for read on (%ld).\n",
101 memset(ha->fw_dump_buffer, 0, dump_size);
102 ha->isp_ops.ascii_fw_dump(ha);
103 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
110 static struct bin_attribute sysfs_fw_dump_attr = {
113 .mode = S_IRUSR | S_IWUSR,
114 .owner = THIS_MODULE,
117 .read = qla2x00_sysfs_read_fw_dump,
118 .write = qla2x00_sysfs_write_fw_dump,
122 qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off,
125 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
126 struct device, kobj)));
129 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
133 spin_lock_irqsave(&ha->hardware_lock, flags);
134 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
136 spin_unlock_irqrestore(&ha->hardware_lock, flags);
142 qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
145 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
146 struct device, kobj)));
150 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
153 /* Checksum NVRAM. */
154 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
158 iter = (uint32_t *)buf;
160 for (cnt = 0; cnt < ((count >> 2) - 1); cnt++)
161 chksum += le32_to_cpu(*iter++);
162 chksum = ~chksum + 1;
163 *iter = cpu_to_le32(chksum);
168 iter = (uint8_t *)buf;
170 for (cnt = 0; cnt < count - 1; cnt++)
172 chksum = ~chksum + 1;
177 spin_lock_irqsave(&ha->hardware_lock, flags);
178 ha->isp_ops.write_nvram(ha, (uint8_t *)buf, ha->nvram_base, count);
179 spin_unlock_irqrestore(&ha->hardware_lock, flags);
184 static struct bin_attribute sysfs_nvram_attr = {
187 .mode = S_IRUSR | S_IWUSR,
188 .owner = THIS_MODULE,
191 .read = qla2x00_sysfs_read_nvram,
192 .write = qla2x00_sysfs_write_nvram,
196 qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
198 struct Scsi_Host *host = ha->host;
200 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
201 sysfs_nvram_attr.size = ha->nvram_size;
202 sysfs_create_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
206 qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
208 struct Scsi_Host *host = ha->host;
210 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_fw_dump_attr);
211 sysfs_remove_bin_file(&host->shost_gendev.kobj, &sysfs_nvram_attr);
214 /* Scsi_Host attributes. */
217 qla2x00_drvr_version_show(struct class_device *cdev, char *buf)
219 return snprintf(buf, PAGE_SIZE, "%s\n", qla2x00_version_str);
223 qla2x00_fw_version_show(struct class_device *cdev, char *buf)
225 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
228 return snprintf(buf, PAGE_SIZE, "%s\n",
229 ha->isp_ops.fw_version_str(ha, fw_str));
233 qla2x00_serial_num_show(struct class_device *cdev, char *buf)
235 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
238 sn = ((ha->serial0 & 0x1f) << 16) | (ha->serial2 << 8) | ha->serial1;
239 return snprintf(buf, PAGE_SIZE, "%c%05d\n", 'A' + sn / 100000,
244 qla2x00_isp_name_show(struct class_device *cdev, char *buf)
246 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
247 return snprintf(buf, PAGE_SIZE, "%s\n", ha->brd_info->isp_name);
251 qla2x00_isp_id_show(struct class_device *cdev, char *buf)
253 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
254 return snprintf(buf, PAGE_SIZE, "%04x %04x %04x %04x\n",
255 ha->product_id[0], ha->product_id[1], ha->product_id[2],
260 qla2x00_model_name_show(struct class_device *cdev, char *buf)
262 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
263 return snprintf(buf, PAGE_SIZE, "%s\n", ha->model_number);
267 qla2x00_model_desc_show(struct class_device *cdev, char *buf)
269 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
270 return snprintf(buf, PAGE_SIZE, "%s\n",
271 ha->model_desc ? ha->model_desc: "");
275 qla2x00_pci_info_show(struct class_device *cdev, char *buf)
277 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
280 return snprintf(buf, PAGE_SIZE, "%s\n",
281 ha->isp_ops.pci_info_str(ha, pci_info));
285 qla2x00_state_show(struct class_device *cdev, char *buf)
287 scsi_qla_host_t *ha = to_qla_host(class_to_shost(cdev));
290 if (atomic_read(&ha->loop_state) == LOOP_DOWN ||
291 atomic_read(&ha->loop_state) == LOOP_DEAD)
292 len = snprintf(buf, PAGE_SIZE, "Link Down\n");
293 else if (atomic_read(&ha->loop_state) != LOOP_READY ||
294 test_bit(ABORT_ISP_ACTIVE, &ha->dpc_flags) ||
295 test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags))
296 len = snprintf(buf, PAGE_SIZE, "Unknown Link State\n");
298 len = snprintf(buf, PAGE_SIZE, "Link Up - ");
300 switch (ha->current_topology) {
302 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
305 len += snprintf(buf + len, PAGE_SIZE-len, "FL_Port\n");
308 len += snprintf(buf + len, PAGE_SIZE-len,
309 "N_Port to N_Port\n");
312 len += snprintf(buf + len, PAGE_SIZE-len, "F_Port\n");
315 len += snprintf(buf + len, PAGE_SIZE-len, "Loop\n");
322 static CLASS_DEVICE_ATTR(driver_version, S_IRUGO, qla2x00_drvr_version_show,
324 static CLASS_DEVICE_ATTR(fw_version, S_IRUGO, qla2x00_fw_version_show, NULL);
325 static CLASS_DEVICE_ATTR(serial_num, S_IRUGO, qla2x00_serial_num_show, NULL);
326 static CLASS_DEVICE_ATTR(isp_name, S_IRUGO, qla2x00_isp_name_show, NULL);
327 static CLASS_DEVICE_ATTR(isp_id, S_IRUGO, qla2x00_isp_id_show, NULL);
328 static CLASS_DEVICE_ATTR(model_name, S_IRUGO, qla2x00_model_name_show, NULL);
329 static CLASS_DEVICE_ATTR(model_desc, S_IRUGO, qla2x00_model_desc_show, NULL);
330 static CLASS_DEVICE_ATTR(pci_info, S_IRUGO, qla2x00_pci_info_show, NULL);
331 static CLASS_DEVICE_ATTR(state, S_IRUGO, qla2x00_state_show, NULL);
333 struct class_device_attribute *qla2x00_host_attrs[] = {
334 &class_device_attr_driver_version,
335 &class_device_attr_fw_version,
336 &class_device_attr_serial_num,
337 &class_device_attr_isp_name,
338 &class_device_attr_isp_id,
339 &class_device_attr_model_name,
340 &class_device_attr_model_desc,
341 &class_device_attr_pci_info,
342 &class_device_attr_state,
346 /* Host attributes. */
349 qla2x00_get_host_port_id(struct Scsi_Host *shost)
351 scsi_qla_host_t *ha = to_qla_host(shost);
353 fc_host_port_id(shost) = ha->d_id.b.domain << 16 |
354 ha->d_id.b.area << 8 | ha->d_id.b.al_pa;
358 qla2x00_get_starget_node_name(struct scsi_target *starget)
360 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
361 scsi_qla_host_t *ha = to_qla_host(host);
365 list_for_each_entry(fcport, &ha->fcports, list) {
366 if (starget->id == fcport->os_target_id) {
367 node_name = wwn_to_u64(fcport->node_name);
372 fc_starget_node_name(starget) = node_name;
376 qla2x00_get_starget_port_name(struct scsi_target *starget)
378 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
379 scsi_qla_host_t *ha = to_qla_host(host);
383 list_for_each_entry(fcport, &ha->fcports, list) {
384 if (starget->id == fcport->os_target_id) {
385 port_name = wwn_to_u64(fcport->port_name);
390 fc_starget_port_name(starget) = port_name;
394 qla2x00_get_starget_port_id(struct scsi_target *starget)
396 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
397 scsi_qla_host_t *ha = to_qla_host(host);
399 uint32_t port_id = ~0U;
401 list_for_each_entry(fcport, &ha->fcports, list) {
402 if (starget->id == fcport->os_target_id) {
403 port_id = fcport->d_id.b.domain << 16 |
404 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
409 fc_starget_port_id(starget) = port_id;
413 qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
415 struct Scsi_Host *host = rport_to_shost(rport);
416 scsi_qla_host_t *ha = to_qla_host(host);
418 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
422 qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
424 struct Scsi_Host *host = rport_to_shost(rport);
425 scsi_qla_host_t *ha = to_qla_host(host);
428 ha->port_down_retry_count = timeout;
430 ha->port_down_retry_count = 1;
432 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
435 struct fc_function_template qla2xxx_transport_functions = {
437 .show_host_node_name = 1,
438 .show_host_port_name = 1,
439 .show_host_supported_classes = 1,
441 .get_host_port_id = qla2x00_get_host_port_id,
442 .show_host_port_id = 1,
444 .dd_fcrport_size = sizeof(struct fc_port *),
445 .show_rport_supported_classes = 1,
447 .get_starget_node_name = qla2x00_get_starget_node_name,
448 .show_starget_node_name = 1,
449 .get_starget_port_name = qla2x00_get_starget_port_name,
450 .show_starget_port_name = 1,
451 .get_starget_port_id = qla2x00_get_starget_port_id,
452 .show_starget_port_id = 1,
454 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
455 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
456 .show_rport_dev_loss_tmo = 1,
461 qla2x00_init_host_attr(scsi_qla_host_t *ha)
463 fc_host_node_name(ha->host) = wwn_to_u64(ha->init_cb->node_name);
464 fc_host_port_name(ha->host) = wwn_to_u64(ha->init_cb->port_name);
465 fc_host_supported_classes(ha->host) = FC_COS_CLASS3;