[IPX]: Fix build error in ipx_recvmsg()
[linux-2.6/verdex.git] / drivers / scsi / qla2xxx / qla_attr.c
blob659a5d63467dc335a570f62e20f4d874bbbabe23
1 /*
2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 QLogic Corporation
6 * (www.qlogic.com)
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
11 * later version.
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.
19 #include "qla_def.h"
21 #include <linux/vmalloc.h>
22 #include <scsi/scsi_transport_fc.h>
24 /* SYSFS attributes --------------------------------------------------------- */
26 static ssize_t
27 qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off,
28 size_t count)
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)
34 return 0;
35 if (off > ha->fw_dump_buffer_len)
36 return 0;
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);
42 return (count);
45 static ssize_t
46 qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off,
47 size_t count)
49 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
50 struct device, kobj)));
51 int reading;
52 uint32_t dump_size;
54 if (off != 0)
55 return (0);
57 reading = simple_strtol(buf, NULL, 10);
58 switch (reading) {
59 case 0:
60 if (ha->fw_dump_reading == 1) {
61 qla_printk(KERN_INFO, ha,
62 "Firmware dump cleared on (%ld).\n",
63 ha->host_no);
65 vfree(ha->fw_dump_buffer);
66 if (!IS_QLA24XX(ha) && !IS_QLA25XX(ha))
67 free_pages((unsigned long)ha->fw_dump,
68 ha->fw_dump_order);
70 ha->fw_dump_reading = 0;
71 ha->fw_dump_buffer = NULL;
72 ha->fw_dump = NULL;
73 ha->fw_dumped = 0;
75 break;
76 case 1:
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;
82 else {
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;
96 return (count);
98 qla_printk(KERN_INFO, ha,
99 "Firmware dump ready for read on (%ld).\n",
100 ha->host_no);
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);
105 break;
107 return (count);
110 static struct bin_attribute sysfs_fw_dump_attr = {
111 .attr = {
112 .name = "fw_dump",
113 .mode = S_IRUSR | S_IWUSR,
114 .owner = THIS_MODULE,
116 .size = 0,
117 .read = qla2x00_sysfs_read_fw_dump,
118 .write = qla2x00_sysfs_write_fw_dump,
121 static ssize_t
122 qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off,
123 size_t count)
125 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
126 struct device, kobj)));
127 unsigned long flags;
129 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
130 return 0;
132 /* Read NVRAM. */
133 spin_lock_irqsave(&ha->hardware_lock, flags);
134 ha->isp_ops.read_nvram(ha, (uint8_t *)buf, ha->nvram_base,
135 ha->nvram_size);
136 spin_unlock_irqrestore(&ha->hardware_lock, flags);
138 return (count);
141 static ssize_t
142 qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
143 size_t count)
145 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
146 struct device, kobj)));
147 unsigned long flags;
148 uint16_t cnt;
150 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != ha->nvram_size)
151 return 0;
153 /* Checksum NVRAM. */
154 if (IS_QLA24XX(ha) || IS_QLA25XX(ha)) {
155 uint32_t *iter;
156 uint32_t chksum;
158 iter = (uint32_t *)buf;
159 chksum = 0;
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);
164 } else {
165 uint8_t *iter;
166 uint8_t chksum;
168 iter = (uint8_t *)buf;
169 chksum = 0;
170 for (cnt = 0; cnt < count - 1; cnt++)
171 chksum += *iter++;
172 chksum = ~chksum + 1;
173 *iter = chksum;
176 /* Write NVRAM. */
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);
181 return (count);
184 static struct bin_attribute sysfs_nvram_attr = {
185 .attr = {
186 .name = "nvram",
187 .mode = S_IRUSR | S_IWUSR,
188 .owner = THIS_MODULE,
190 .size = 0,
191 .read = qla2x00_sysfs_read_nvram,
192 .write = qla2x00_sysfs_write_nvram,
195 void
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);
205 void
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. */
216 static void
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;
225 static void
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);
230 fc_port_t *fcport;
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;
236 break;
240 fc_starget_node_name(starget) = be64_to_cpu(node_name);
243 static void
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);
248 fc_port_t *fcport;
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;
254 break;
258 fc_starget_port_name(starget) = be64_to_cpu(port_name);
261 static void
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);
266 fc_port_t *fcport;
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;
273 break;
277 fc_starget_port_id(starget) = port_id;
280 static void
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;
289 static void
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);
295 if (timeout)
296 ha->port_down_retry_count = timeout;
297 else
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,
325 void
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);