aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/scsi/qla2xxx/qla_attr.c
diff options
context:
space:
mode:
author <andrew.vasquez@qlogic.com>2005-04-17 16:04:54 -0400
committerJames Bottomley <jejb@titanic>2005-04-18 14:47:19 -0400
commit8482e118afa0cb4321ab3d30b1100d27d63130c0 (patch)
tree971714d297194e1c20e1b80b1d2e031d4517f5ad /drivers/scsi/qla2xxx/qla_attr.c
parentf4f051ebb40e74ad0ba02d2cb3a6c16b0393472b (diff)
[PATCH] qla2xxx: add remote port codes...
Add initial support for FC remote port infrastructure. o Use fc_remote_port...() registration and block/unlock functions. o Consolidate 'attribute' (fc-remote/sysfs) helpers into new qla_attr.c file. Signed-off-by: Andrew Vasquez <andrew.vasquez@qlogic.com> Signed-off-by: James Bottomley <James.Bottomley@SteelEye.com>
Diffstat (limited to 'drivers/scsi/qla2xxx/qla_attr.c')
-rw-r--r--drivers/scsi/qla2xxx/qla_attr.c323
1 files changed, 323 insertions, 0 deletions
diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
new file mode 100644
index 000000000000..0105b609ff3a
--- /dev/null
+++ b/drivers/scsi/qla2xxx/qla_attr.c
@@ -0,0 +1,323 @@
1/*
2 * QLOGIC LINUX SOFTWARE
3 *
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2005 QLogic Corporation
6 * (www.qlogic.com)
7 *
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.
12 *
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.
17 *
18 */
19#include "qla_def.h"
20
21#include <linux/version.h>
22#include <scsi/scsi_transport_fc.h>
23
24/* SYSFS attributes --------------------------------------------------------- */
25
26static ssize_t
27qla2x00_sysfs_read_fw_dump(struct kobject *kobj, char *buf, loff_t off,
28 size_t count)
29{
30 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
31 struct device, kobj)));
32
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;
39
40 memcpy(buf, &ha->fw_dump_buffer[off], count);
41
42 return (count);
43}
44
45static ssize_t
46qla2x00_sysfs_write_fw_dump(struct kobject *kobj, char *buf, loff_t off,
47 size_t count)
48{
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;
53
54 if (off != 0)
55 return (0);
56
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);
64
65 vfree(ha->fw_dump_buffer);
66 free_pages((unsigned long)ha->fw_dump,
67 ha->fw_dump_order);
68
69 ha->fw_dump_reading = 0;
70 ha->fw_dump_buffer = NULL;
71 ha->fw_dump = NULL;
72 }
73 break;
74 case 1:
75 if (ha->fw_dump != NULL && !ha->fw_dump_reading) {
76 ha->fw_dump_reading = 1;
77
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);
88
89 ha->fw_dump_reading = 0;
90 return (count);
91 }
92 qla_printk(KERN_INFO, ha,
93 "Firmware dump ready for read on (%ld).\n",
94 ha->host_no);
95 memset(ha->fw_dump_buffer, 0, dump_size);
96 if (IS_QLA2100(ha) || IS_QLA2200(ha))
97 qla2100_ascii_fw_dump(ha);
98 else
99 qla2300_ascii_fw_dump(ha);
100 ha->fw_dump_buffer_len = strlen(ha->fw_dump_buffer);
101 }
102 break;
103 }
104 return (count);
105}
106
107static struct bin_attribute sysfs_fw_dump_attr = {
108 .attr = {
109 .name = "fw_dump",
110 .mode = S_IRUSR | S_IWUSR,
111 .owner = THIS_MODULE,
112 },
113 .size = 0,
114 .read = qla2x00_sysfs_read_fw_dump,
115 .write = qla2x00_sysfs_write_fw_dump,
116};
117
118static ssize_t
119qla2x00_sysfs_read_nvram(struct kobject *kobj, char *buf, loff_t off,
120 size_t count)
121{
122 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
123 struct device, kobj)));
124 uint16_t *witer;
125 unsigned long flags;
126 uint16_t cnt;
127
128 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
129 return 0;
130
131 /* Read NVRAM. */
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));
138 witer++;
139 }
140 qla2x00_unlock_nvram_access(ha);
141 spin_unlock_irqrestore(&ha->hardware_lock, flags);
142
143 return (count);
144}
145
146static ssize_t
147qla2x00_sysfs_write_nvram(struct kobject *kobj, char *buf, loff_t off,
148 size_t count)
149{
150 struct scsi_qla_host *ha = to_qla_host(dev_to_shost(container_of(kobj,
151 struct device, kobj)));
152 uint8_t *iter;
153 uint16_t *witer;
154 unsigned long flags;
155 uint16_t cnt;
156 uint8_t chksum;
157
158 if (!capable(CAP_SYS_ADMIN) || off != 0 || count != sizeof(nvram_t))
159 return 0;
160
161 /* Checksum NVRAM. */
162 iter = (uint8_t *)buf;
163 chksum = 0;
164 for (cnt = 0; cnt < count - 1; cnt++)
165 chksum += *iter++;
166 chksum = ~chksum + 1;
167 *iter = chksum;
168
169 /* Write NVRAM. */
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));
177 witer++;
178 }
179 qla2x00_unlock_nvram_access(ha);
180 spin_unlock_irqrestore(&ha->hardware_lock, flags);
181
182 return (count);
183}
184
185static struct bin_attribute sysfs_nvram_attr = {
186 .attr = {
187 .name = "nvram",
188 .mode = S_IRUSR | S_IWUSR,
189 .owner = THIS_MODULE,
190 },
191 .size = sizeof(nvram_t),
192 .read = qla2x00_sysfs_read_nvram,
193 .write = qla2x00_sysfs_write_nvram,
194};
195
196void
197qla2x00_alloc_sysfs_attr(scsi_qla_host_t *ha)
198{
199 struct Scsi_Host *host = ha->host;
200
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);
203}
204
205void
206qla2x00_free_sysfs_attr(scsi_qla_host_t *ha)
207{
208 struct Scsi_Host *host = ha->host;
209
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);
212}
213
214/* Host attributes. */
215
216static void
217qla2x00_get_host_port_id(struct Scsi_Host *shost)
218{
219 scsi_qla_host_t *ha = to_qla_host(shost);
220
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;
223}
224
225static void
226qla2x00_get_starget_node_name(struct scsi_target *starget)
227{
228 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
229 scsi_qla_host_t *ha = to_qla_host(host);
230 os_tgt_t *tq = (os_tgt_t *) TGT_Q(ha, starget->id);
231 uint64_t node_name = 0;
232
233 if (tq->fcport)
234 node_name = be64_to_cpu(*(uint64_t *)tq->fcport->node_name);
235 fc_starget_node_name(starget) = node_name;
236}
237
238static void
239qla2x00_get_starget_port_name(struct scsi_target *starget)
240{
241 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
242 scsi_qla_host_t *ha = to_qla_host(host);
243 os_tgt_t *tq = (os_tgt_t *) TGT_Q(ha, starget->id);
244 uint64_t port_name = 0;
245
246 if (tq->fcport)
247 port_name = be64_to_cpu(*(uint64_t *)tq->fcport->port_name);
248 fc_starget_port_name(starget) = port_name;
249}
250
251static void
252qla2x00_get_starget_port_id(struct scsi_target *starget)
253{
254 struct Scsi_Host *host = dev_to_shost(starget->dev.parent);
255 scsi_qla_host_t *ha = to_qla_host(host);
256 os_tgt_t *tq = (os_tgt_t *) TGT_Q(ha, starget->id);
257 uint32_t port_id = 0;
258
259 if (tq->fcport)
260 port_id = tq->fcport->d_id.b.domain << 16 |
261 tq->fcport->d_id.b.area << 8 | tq->fcport->d_id.b.al_pa;
262 fc_starget_port_id(starget) = port_id;
263}
264
265static void
266qla2x00_get_rport_loss_tmo(struct fc_rport *rport)
267{
268 os_tgt_t *tq = rport->dd_data;
269 scsi_qla_host_t *ha = tq->ha;
270
271 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
272}
273
274static void
275qla2x00_set_rport_loss_tmo(struct fc_rport *rport, uint32_t timeout)
276{
277 os_tgt_t *tq = rport->dd_data;
278 scsi_qla_host_t *ha = tq->ha;
279
280 if (timeout)
281 ha->port_down_retry_count = timeout;
282 else
283 ha->port_down_retry_count = 1;
284
285 rport->dev_loss_tmo = ha->port_down_retry_count + 5;
286}
287
288static struct fc_function_template qla2xxx_transport_functions = {
289
290 .show_host_node_name = 1,
291 .show_host_port_name = 1,
292 .get_host_port_id = qla2x00_get_host_port_id,
293 .show_host_port_id = 1,
294
295 .dd_fcrport_size = sizeof(os_tgt_t *),
296
297 .get_starget_node_name = qla2x00_get_starget_node_name,
298 .show_starget_node_name = 1,
299 .get_starget_port_name = qla2x00_get_starget_port_name,
300 .show_starget_port_name = 1,
301 .get_starget_port_id = qla2x00_get_starget_port_id,
302 .show_starget_port_id = 1,
303
304 .get_rport_dev_loss_tmo = qla2x00_get_rport_loss_tmo,
305 .set_rport_dev_loss_tmo = qla2x00_set_rport_loss_tmo,
306 .show_rport_dev_loss_tmo = 1,
307
308};
309
310struct scsi_transport_template *
311qla2x00_alloc_transport_tmpl(void)
312{
313 return (fc_attach_transport(&qla2xxx_transport_functions));
314}
315
316void
317qla2x00_init_host_attr(scsi_qla_host_t *ha)
318{
319 fc_host_node_name(ha->host) =
320 be64_to_cpu(*(uint64_t *)ha->init_cb->node_name);
321 fc_host_port_name(ha->host) =
322 be64_to_cpu(*(uint64_t *)ha->init_cb->port_name);
323}