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 free_pages((unsigned long)ha
->fw_dump
,
69 ha
->fw_dump_reading
= 0;
70 ha
->fw_dump_buffer
= NULL
;
75 if (ha
->fw_dump
!= NULL
&& !ha
->fw_dump_reading
) {
76 ha
->fw_dump_reading
= 1;
78 dump_size
= FW_DUMP_SIZE_1M
;
79 if (ha
->fw_memory_size
< 0x20000)
80 dump_size
= FW_DUMP_SIZE_128K
;
81 else if (ha
->fw_memory_size
< 0x80000)
82 dump_size
= FW_DUMP_SIZE_512K
;
83 ha
->fw_dump_buffer
= (char *)vmalloc(dump_size
);
84 if (ha
->fw_dump_buffer
== NULL
) {
85 qla_printk(KERN_WARNING
, ha
,
86 "Unable to allocate memory for firmware "
87 "dump buffer (%d).\n", dump_size
);
89 ha
->fw_dump_reading
= 0;
92 qla_printk(KERN_INFO
, ha
,
93 "Firmware dump ready for read on (%ld).\n",
95 memset(ha
->fw_dump_buffer
, 0, dump_size
);
96 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
97 qla2100_ascii_fw_dump(ha
);
99 qla2300_ascii_fw_dump(ha
);
100 ha
->fw_dump_buffer_len
= strlen(ha
->fw_dump_buffer
);
107 static struct bin_attribute sysfs_fw_dump_attr
= {
110 .mode
= S_IRUSR
| S_IWUSR
,
111 .owner
= THIS_MODULE
,
114 .read
= qla2x00_sysfs_read_fw_dump
,
115 .write
= qla2x00_sysfs_write_fw_dump
,
119 qla2x00_sysfs_read_nvram(struct kobject
*kobj
, char *buf
, loff_t off
,
122 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
123 struct device
, kobj
)));
128 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= sizeof(nvram_t
))
132 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
133 qla2x00_lock_nvram_access(ha
);
134 witer
= (uint16_t *)buf
;
135 for (cnt
= 0; cnt
< count
/ 2; cnt
++) {
136 *witer
= cpu_to_le16(qla2x00_get_nvram_word(ha
,
137 cnt
+ha
->nvram_base
));
140 qla2x00_unlock_nvram_access(ha
);
141 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
147 qla2x00_sysfs_write_nvram(struct kobject
*kobj
, char *buf
, loff_t off
,
150 struct scsi_qla_host
*ha
= to_qla_host(dev_to_shost(container_of(kobj
,
151 struct device
, kobj
)));
158 if (!capable(CAP_SYS_ADMIN
) || off
!= 0 || count
!= sizeof(nvram_t
))
161 /* Checksum NVRAM. */
162 iter
= (uint8_t *)buf
;
164 for (cnt
= 0; cnt
< count
- 1; cnt
++)
166 chksum
= ~chksum
+ 1;
170 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
171 qla2x00_lock_nvram_access(ha
);
172 qla2x00_release_nvram_protection(ha
);
173 witer
= (uint16_t *)buf
;
174 for (cnt
= 0; cnt
< count
/ 2; cnt
++) {
175 qla2x00_write_nvram_word(ha
, cnt
+ha
->nvram_base
,
176 cpu_to_le16(*witer
));
179 qla2x00_unlock_nvram_access(ha
);
180 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
185 static struct bin_attribute sysfs_nvram_attr
= {
188 .mode
= S_IRUSR
| S_IWUSR
,
189 .owner
= THIS_MODULE
,
191 .size
= sizeof(nvram_t
),
192 .read
= qla2x00_sysfs_read_nvram
,
193 .write
= qla2x00_sysfs_write_nvram
,
197 qla2x00_alloc_sysfs_attr(scsi_qla_host_t
*ha
)
199 struct Scsi_Host
*host
= ha
->host
;
201 sysfs_create_bin_file(&host
->shost_gendev
.kobj
, &sysfs_fw_dump_attr
);
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 /* Host attributes. */
217 qla2x00_get_host_port_id(struct Scsi_Host
*shost
)
219 scsi_qla_host_t
*ha
= to_qla_host(shost
);
221 fc_host_port_id(shost
) = ha
->d_id
.b
.domain
<< 16 |
222 ha
->d_id
.b
.area
<< 8 | ha
->d_id
.b
.al_pa
;
226 qla2x00_get_starget_node_name(struct scsi_target
*starget
)
228 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
229 scsi_qla_host_t
*ha
= to_qla_host(host
);
231 uint64_t node_name
= 0;
233 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
234 if (starget
->id
== fcport
->os_target_id
) {
235 node_name
= *(uint64_t *)fcport
->node_name
;
240 fc_starget_node_name(starget
) = be64_to_cpu(node_name
);
244 qla2x00_get_starget_port_name(struct scsi_target
*starget
)
246 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
247 scsi_qla_host_t
*ha
= to_qla_host(host
);
249 uint64_t port_name
= 0;
251 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
252 if (starget
->id
== fcport
->os_target_id
) {
253 port_name
= *(uint64_t *)fcport
->port_name
;
258 fc_starget_port_name(starget
) = be64_to_cpu(port_name
);
262 qla2x00_get_starget_port_id(struct scsi_target
*starget
)
264 struct Scsi_Host
*host
= dev_to_shost(starget
->dev
.parent
);
265 scsi_qla_host_t
*ha
= to_qla_host(host
);
267 uint32_t port_id
= ~0U;
269 list_for_each_entry(fcport
, &ha
->fcports
, list
) {
270 if (starget
->id
== fcport
->os_target_id
) {
271 port_id
= fcport
->d_id
.b
.domain
<< 16 |
272 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
277 fc_starget_port_id(starget
) = port_id
;
281 qla2x00_get_rport_loss_tmo(struct fc_rport
*rport
)
283 struct Scsi_Host
*host
= rport_to_shost(rport
);
284 scsi_qla_host_t
*ha
= to_qla_host(host
);
286 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
290 qla2x00_set_rport_loss_tmo(struct fc_rport
*rport
, uint32_t timeout
)
292 struct Scsi_Host
*host
= rport_to_shost(rport
);
293 scsi_qla_host_t
*ha
= to_qla_host(host
);
296 ha
->port_down_retry_count
= timeout
;
298 ha
->port_down_retry_count
= 1;
300 rport
->dev_loss_tmo
= ha
->port_down_retry_count
+ 5;
303 struct fc_function_template qla2xxx_transport_functions
= {
305 .show_host_node_name
= 1,
306 .show_host_port_name
= 1,
307 .get_host_port_id
= qla2x00_get_host_port_id
,
308 .show_host_port_id
= 1,
310 .dd_fcrport_size
= sizeof(struct fc_port
*),
312 .get_starget_node_name
= qla2x00_get_starget_node_name
,
313 .show_starget_node_name
= 1,
314 .get_starget_port_name
= qla2x00_get_starget_port_name
,
315 .show_starget_port_name
= 1,
316 .get_starget_port_id
= qla2x00_get_starget_port_id
,
317 .show_starget_port_id
= 1,
319 .get_rport_dev_loss_tmo
= qla2x00_get_rport_loss_tmo
,
320 .set_rport_dev_loss_tmo
= qla2x00_set_rport_loss_tmo
,
321 .show_rport_dev_loss_tmo
= 1,
326 qla2x00_init_host_attr(scsi_qla_host_t
*ha
)
328 fc_host_node_name(ha
->host
) =
329 be64_to_cpu(*(uint64_t *)ha
->init_cb
->node_name
);
330 fc_host_port_name(ha
->host
) =
331 be64_to_cpu(*(uint64_t *)ha
->init_cb
->port_name
);