Commit | Line | Data |
---|---|---|
1c57e86d EC |
1 | /* |
2 | ******************************************************************************* | |
3 | ** O.S : Linux | |
4 | ** FILE NAME : arcmsr_attr.c | |
5 | ** BY : Erich Chen | |
6 | ** Description: attributes exported to sysfs and device host | |
7 | ******************************************************************************* | |
8 | ** Copyright (C) 2002 - 2005, Areca Technology Corporation All rights reserved | |
9 | ** | |
10 | ** Web site: www.areca.com.tw | |
11 | ** E-mail: erich@areca.com.tw | |
12 | ** | |
13 | ** This program is free software; you can redistribute it and/or modify | |
14 | ** it under the terms of the GNU General Public License version 2 as | |
15 | ** published by the Free Software Foundation. | |
16 | ** This program is distributed in the hope that it will be useful, | |
17 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 | ** GNU General Public License for more details. | |
20 | ******************************************************************************* | |
21 | ** Redistribution and use in source and binary forms, with or without | |
22 | ** modification, are permitted provided that the following conditions | |
23 | ** are met: | |
24 | ** 1. Redistributions of source code must retain the above copyright | |
25 | ** notice, this list of conditions and the following disclaimer. | |
26 | ** 2. Redistributions in binary form must reproduce the above copyright | |
27 | ** notice, this list of conditions and the following disclaimer in the | |
28 | ** documentation and/or other materials provided with the distribution. | |
29 | ** 3. The name of the author may not be used to endorse or promote products | |
30 | ** derived from this software without specific prior written permission. | |
31 | ** | |
32 | ** THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR | |
33 | ** IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
34 | ** OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
35 | ** IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | |
36 | ** INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES(INCLUDING,BUT | |
37 | ** NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
38 | ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION)HOWEVER CAUSED AND ON ANY | |
39 | ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
40 | ** (INCLUDING NEGLIGENCE OR OTHERWISE)ARISING IN ANY WAY OUT OF THE USE OF | |
41 | ** THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
42 | ******************************************************************************* | |
43 | ** For history of changes, see Documentation/scsi/ChangeLog.arcmsr | |
44 | ** Firmware Specification, see Documentation/scsi/arcmsr_spec.txt | |
45 | ******************************************************************************* | |
46 | */ | |
47 | #include <linux/module.h> | |
48 | #include <linux/kernel.h> | |
49 | #include <linux/init.h> | |
50 | #include <linux/errno.h> | |
51 | #include <linux/delay.h> | |
1c57e86d EC |
52 | |
53 | #include <scsi/scsi_cmnd.h> | |
54 | #include <scsi/scsi_device.h> | |
55 | #include <scsi/scsi_host.h> | |
56 | #include <scsi/scsi_transport.h> | |
57 | #include "arcmsr.h" | |
58 | ||
59 | struct class_device_attribute *arcmsr_host_attrs[]; | |
60 | ||
61 | static ssize_t | |
91a69029 ZR |
62 | arcmsr_sysfs_iop_message_read(struct kobject *kobj, |
63 | struct bin_attribute *bin_attr, | |
64 | char *buf, loff_t off, size_t count) | |
1c57e86d EC |
65 | { |
66 | struct class_device *cdev = container_of(kobj,struct class_device,kobj); | |
67 | struct Scsi_Host *host = class_to_shost(cdev); | |
68 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
69 | struct MessageUnit __iomem *reg = acb->pmu; | |
70 | uint8_t *pQbuffer,*ptmpQbuffer; | |
71 | int32_t allxfer_len = 0; | |
72 | ||
73 | if (!capable(CAP_SYS_ADMIN)) | |
74 | return -EACCES; | |
75 | ||
76 | /* do message unit read. */ | |
77 | ptmpQbuffer = (uint8_t *)buf; | |
78 | while ((acb->rqbuf_firstindex != acb->rqbuf_lastindex) | |
79 | && (allxfer_len < 1031)) { | |
80 | pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; | |
81 | memcpy(ptmpQbuffer, pQbuffer, 1); | |
82 | acb->rqbuf_firstindex++; | |
83 | acb->rqbuf_firstindex %= ARCMSR_MAX_QBUFFER; | |
84 | ptmpQbuffer++; | |
85 | allxfer_len++; | |
86 | } | |
87 | if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { | |
88 | struct QBUFFER __iomem * prbuffer = (struct QBUFFER __iomem *) | |
89 | ®->message_rbuffer; | |
90 | uint8_t __iomem * iop_data = (uint8_t __iomem *)prbuffer->data; | |
91 | int32_t iop_len; | |
92 | ||
93 | acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; | |
94 | iop_len = readl(&prbuffer->data_len); | |
95 | while (iop_len > 0) { | |
96 | acb->rqbuffer[acb->rqbuf_lastindex] = readb(iop_data); | |
97 | acb->rqbuf_lastindex++; | |
98 | acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER; | |
99 | iop_data++; | |
100 | iop_len--; | |
101 | } | |
102 | writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, | |
103 | ®->inbound_doorbell); | |
104 | } | |
105 | return (allxfer_len); | |
106 | } | |
107 | ||
108 | static ssize_t | |
91a69029 ZR |
109 | arcmsr_sysfs_iop_message_write(struct kobject *kobj, |
110 | struct bin_attribute *bin_attr, | |
111 | char *buf, loff_t off, size_t count) | |
1c57e86d EC |
112 | { |
113 | struct class_device *cdev = container_of(kobj,struct class_device,kobj); | |
114 | struct Scsi_Host *host = class_to_shost(cdev); | |
115 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
116 | int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; | |
117 | uint8_t *pQbuffer, *ptmpuserbuffer; | |
118 | ||
119 | if (!capable(CAP_SYS_ADMIN)) | |
120 | return -EACCES; | |
121 | if (count > 1032) | |
122 | return -EINVAL; | |
123 | /* do message unit write. */ | |
124 | ptmpuserbuffer = (uint8_t *)buf; | |
125 | user_len = (int32_t)count; | |
126 | wqbuf_lastindex = acb->wqbuf_lastindex; | |
127 | wqbuf_firstindex = acb->wqbuf_firstindex; | |
128 | if (wqbuf_lastindex != wqbuf_firstindex) { | |
129 | arcmsr_post_Qbuffer(acb); | |
130 | return 0; /*need retry*/ | |
131 | } else { | |
132 | my_empty_len = (wqbuf_firstindex-wqbuf_lastindex - 1) | |
133 | &(ARCMSR_MAX_QBUFFER - 1); | |
134 | if (my_empty_len >= user_len) { | |
135 | while (user_len > 0) { | |
136 | pQbuffer = | |
137 | &acb->wqbuffer[acb->wqbuf_lastindex]; | |
138 | memcpy(pQbuffer, ptmpuserbuffer, 1); | |
139 | acb->wqbuf_lastindex++; | |
140 | acb->wqbuf_lastindex %= ARCMSR_MAX_QBUFFER; | |
141 | ptmpuserbuffer++; | |
142 | user_len--; | |
143 | } | |
144 | if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) { | |
145 | acb->acb_flags &= | |
146 | ~ACB_F_MESSAGE_WQBUFFER_CLEARED; | |
147 | arcmsr_post_Qbuffer(acb); | |
148 | } | |
149 | return count; | |
150 | } else { | |
151 | return 0; /*need retry*/ | |
152 | } | |
153 | } | |
154 | } | |
155 | ||
156 | static ssize_t | |
91a69029 ZR |
157 | arcmsr_sysfs_iop_message_clear(struct kobject *kobj, |
158 | struct bin_attribute *bin_attr, | |
159 | char *buf, loff_t off, size_t count) | |
1c57e86d EC |
160 | { |
161 | struct class_device *cdev = container_of(kobj,struct class_device,kobj); | |
162 | struct Scsi_Host *host = class_to_shost(cdev); | |
163 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
164 | struct MessageUnit __iomem *reg = acb->pmu; | |
165 | uint8_t *pQbuffer; | |
166 | ||
167 | if (!capable(CAP_SYS_ADMIN)) | |
168 | return -EACCES; | |
169 | ||
170 | if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { | |
171 | acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; | |
172 | writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK | |
173 | , ®->inbound_doorbell); | |
174 | } | |
175 | acb->acb_flags |= | |
176 | (ACB_F_MESSAGE_WQBUFFER_CLEARED | |
177 | | ACB_F_MESSAGE_RQBUFFER_CLEARED | |
178 | | ACB_F_MESSAGE_WQBUFFER_READED); | |
179 | acb->rqbuf_firstindex = 0; | |
180 | acb->rqbuf_lastindex = 0; | |
181 | acb->wqbuf_firstindex = 0; | |
182 | acb->wqbuf_lastindex = 0; | |
183 | pQbuffer = acb->rqbuffer; | |
184 | memset(pQbuffer, 0, sizeof (struct QBUFFER)); | |
185 | pQbuffer = acb->wqbuffer; | |
186 | memset(pQbuffer, 0, sizeof (struct QBUFFER)); | |
187 | return 1; | |
188 | } | |
189 | ||
190 | static struct bin_attribute arcmsr_sysfs_message_read_attr = { | |
191 | .attr = { | |
192 | .name = "mu_read", | |
193 | .mode = S_IRUSR , | |
1c57e86d EC |
194 | }, |
195 | .size = 1032, | |
196 | .read = arcmsr_sysfs_iop_message_read, | |
197 | }; | |
198 | ||
199 | static struct bin_attribute arcmsr_sysfs_message_write_attr = { | |
200 | .attr = { | |
201 | .name = "mu_write", | |
202 | .mode = S_IWUSR, | |
1c57e86d EC |
203 | }, |
204 | .size = 1032, | |
205 | .write = arcmsr_sysfs_iop_message_write, | |
206 | }; | |
207 | ||
208 | static struct bin_attribute arcmsr_sysfs_message_clear_attr = { | |
209 | .attr = { | |
210 | .name = "mu_clear", | |
211 | .mode = S_IWUSR, | |
1c57e86d EC |
212 | }, |
213 | .size = 1, | |
214 | .write = arcmsr_sysfs_iop_message_clear, | |
215 | }; | |
216 | ||
217 | int arcmsr_alloc_sysfs_attr(struct AdapterControlBlock *acb) | |
218 | { | |
219 | struct Scsi_Host *host = acb->host; | |
220 | int error; | |
221 | ||
222 | error = sysfs_create_bin_file(&host->shost_classdev.kobj, | |
223 | &arcmsr_sysfs_message_read_attr); | |
224 | if (error) { | |
225 | printk(KERN_ERR "arcmsr: alloc sysfs mu_read failed\n"); | |
226 | goto error_bin_file_message_read; | |
227 | } | |
228 | error = sysfs_create_bin_file(&host->shost_classdev.kobj, | |
229 | &arcmsr_sysfs_message_write_attr); | |
230 | if (error) { | |
231 | printk(KERN_ERR "arcmsr: alloc sysfs mu_write failed\n"); | |
232 | goto error_bin_file_message_write; | |
233 | } | |
234 | error = sysfs_create_bin_file(&host->shost_classdev.kobj, | |
235 | &arcmsr_sysfs_message_clear_attr); | |
236 | if (error) { | |
237 | printk(KERN_ERR "arcmsr: alloc sysfs mu_clear failed\n"); | |
238 | goto error_bin_file_message_clear; | |
239 | } | |
240 | return 0; | |
241 | error_bin_file_message_clear: | |
43d6b68d | 242 | sysfs_remove_bin_file(&host->shost_classdev.kobj, |
1c57e86d | 243 | &arcmsr_sysfs_message_write_attr); |
1c57e86d | 244 | error_bin_file_message_write: |
43d6b68d | 245 | sysfs_remove_bin_file(&host->shost_classdev.kobj, |
1c57e86d | 246 | &arcmsr_sysfs_message_read_attr); |
1c57e86d EC |
247 | error_bin_file_message_read: |
248 | return error; | |
249 | } | |
250 | ||
251 | void | |
252 | arcmsr_free_sysfs_attr(struct AdapterControlBlock *acb) { | |
253 | struct Scsi_Host *host = acb->host; | |
1c57e86d | 254 | |
43d6b68d | 255 | sysfs_remove_bin_file(&host->shost_classdev.kobj, |
1c57e86d | 256 | &arcmsr_sysfs_message_clear_attr); |
43d6b68d | 257 | sysfs_remove_bin_file(&host->shost_classdev.kobj, |
1c57e86d | 258 | &arcmsr_sysfs_message_write_attr); |
43d6b68d | 259 | sysfs_remove_bin_file(&host->shost_classdev.kobj, |
1c57e86d | 260 | &arcmsr_sysfs_message_read_attr); |
1c57e86d EC |
261 | } |
262 | ||
263 | ||
264 | static ssize_t | |
265 | arcmsr_attr_host_driver_version(struct class_device *cdev, char *buf) { | |
266 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 267 | "%s\n", |
1c57e86d EC |
268 | ARCMSR_DRIVER_VERSION); |
269 | } | |
270 | ||
271 | static ssize_t | |
272 | arcmsr_attr_host_driver_posted_cmd(struct class_device *cdev, char *buf) { | |
273 | struct Scsi_Host *host = class_to_shost(cdev); | |
274 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
275 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 276 | "%4d\n", |
1c57e86d EC |
277 | atomic_read(&acb->ccboutstandingcount)); |
278 | } | |
279 | ||
280 | static ssize_t | |
281 | arcmsr_attr_host_driver_reset(struct class_device *cdev, char *buf) { | |
282 | struct Scsi_Host *host = class_to_shost(cdev); | |
283 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
284 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 285 | "%4d\n", |
1c57e86d EC |
286 | acb->num_resets); |
287 | } | |
288 | ||
289 | static ssize_t | |
290 | arcmsr_attr_host_driver_abort(struct class_device *cdev, char *buf) { | |
291 | struct Scsi_Host *host = class_to_shost(cdev); | |
292 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
293 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 294 | "%4d\n", |
1c57e86d EC |
295 | acb->num_aborts); |
296 | } | |
297 | ||
298 | static ssize_t | |
299 | arcmsr_attr_host_fw_model(struct class_device *cdev, char *buf) { | |
300 | struct Scsi_Host *host = class_to_shost(cdev); | |
301 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
302 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 303 | "%s\n", |
1c57e86d EC |
304 | acb->firm_model); |
305 | } | |
306 | ||
307 | static ssize_t | |
308 | arcmsr_attr_host_fw_version(struct class_device *cdev, char *buf) { | |
309 | struct Scsi_Host *host = class_to_shost(cdev); | |
310 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
311 | ||
312 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 313 | "%s\n", |
1c57e86d EC |
314 | acb->firm_version); |
315 | } | |
316 | ||
317 | static ssize_t | |
318 | arcmsr_attr_host_fw_request_len(struct class_device *cdev, char *buf) { | |
319 | struct Scsi_Host *host = class_to_shost(cdev); | |
320 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
321 | ||
322 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 323 | "%4d\n", |
1c57e86d EC |
324 | acb->firm_request_len); |
325 | } | |
326 | ||
327 | static ssize_t | |
328 | arcmsr_attr_host_fw_numbers_queue(struct class_device *cdev, char *buf) { | |
329 | struct Scsi_Host *host = class_to_shost(cdev); | |
330 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
331 | ||
332 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 333 | "%4d\n", |
1c57e86d EC |
334 | acb->firm_numbers_queue); |
335 | } | |
336 | ||
337 | static ssize_t | |
338 | arcmsr_attr_host_fw_sdram_size(struct class_device *cdev, char *buf) { | |
339 | struct Scsi_Host *host = class_to_shost(cdev); | |
340 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
341 | ||
342 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 343 | "%4d\n", |
1c57e86d EC |
344 | acb->firm_sdram_size); |
345 | } | |
346 | ||
347 | static ssize_t | |
348 | arcmsr_attr_host_fw_hd_channels(struct class_device *cdev, char *buf) { | |
349 | struct Scsi_Host *host = class_to_shost(cdev); | |
350 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
351 | ||
352 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 353 | "%4d\n", |
1c57e86d EC |
354 | acb->firm_hd_channels); |
355 | } | |
356 | ||
357 | static CLASS_DEVICE_ATTR(host_driver_version, S_IRUGO, arcmsr_attr_host_driver_version, NULL); | |
358 | static CLASS_DEVICE_ATTR(host_driver_posted_cmd, S_IRUGO, arcmsr_attr_host_driver_posted_cmd, NULL); | |
359 | static CLASS_DEVICE_ATTR(host_driver_reset, S_IRUGO, arcmsr_attr_host_driver_reset, NULL); | |
360 | static CLASS_DEVICE_ATTR(host_driver_abort, S_IRUGO, arcmsr_attr_host_driver_abort, NULL); | |
361 | static CLASS_DEVICE_ATTR(host_fw_model, S_IRUGO, arcmsr_attr_host_fw_model, NULL); | |
362 | static CLASS_DEVICE_ATTR(host_fw_version, S_IRUGO, arcmsr_attr_host_fw_version, NULL); | |
363 | static CLASS_DEVICE_ATTR(host_fw_request_len, S_IRUGO, arcmsr_attr_host_fw_request_len, NULL); | |
364 | static CLASS_DEVICE_ATTR(host_fw_numbers_queue, S_IRUGO, arcmsr_attr_host_fw_numbers_queue, NULL); | |
365 | static CLASS_DEVICE_ATTR(host_fw_sdram_size, S_IRUGO, arcmsr_attr_host_fw_sdram_size, NULL); | |
366 | static CLASS_DEVICE_ATTR(host_fw_hd_channels, S_IRUGO, arcmsr_attr_host_fw_hd_channels, NULL); | |
367 | ||
368 | struct class_device_attribute *arcmsr_host_attrs[] = { | |
369 | &class_device_attr_host_driver_version, | |
370 | &class_device_attr_host_driver_posted_cmd, | |
371 | &class_device_attr_host_driver_reset, | |
372 | &class_device_attr_host_driver_abort, | |
373 | &class_device_attr_host_fw_model, | |
374 | &class_device_attr_host_fw_version, | |
375 | &class_device_attr_host_fw_request_len, | |
376 | &class_device_attr_host_fw_numbers_queue, | |
377 | &class_device_attr_host_fw_sdram_size, | |
378 | &class_device_attr_host_fw_hd_channels, | |
379 | NULL, | |
380 | }; |