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 | |
62 | arcmsr_sysfs_iop_message_read(struct kobject *kobj, char *buf, loff_t off, | |
63 | size_t count) | |
64 | { | |
65 | struct class_device *cdev = container_of(kobj,struct class_device,kobj); | |
66 | struct Scsi_Host *host = class_to_shost(cdev); | |
67 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
68 | struct MessageUnit __iomem *reg = acb->pmu; | |
69 | uint8_t *pQbuffer,*ptmpQbuffer; | |
70 | int32_t allxfer_len = 0; | |
71 | ||
72 | if (!capable(CAP_SYS_ADMIN)) | |
73 | return -EACCES; | |
74 | ||
75 | /* do message unit read. */ | |
76 | ptmpQbuffer = (uint8_t *)buf; | |
77 | while ((acb->rqbuf_firstindex != acb->rqbuf_lastindex) | |
78 | && (allxfer_len < 1031)) { | |
79 | pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex]; | |
80 | memcpy(ptmpQbuffer, pQbuffer, 1); | |
81 | acb->rqbuf_firstindex++; | |
82 | acb->rqbuf_firstindex %= ARCMSR_MAX_QBUFFER; | |
83 | ptmpQbuffer++; | |
84 | allxfer_len++; | |
85 | } | |
86 | if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { | |
87 | struct QBUFFER __iomem * prbuffer = (struct QBUFFER __iomem *) | |
88 | ®->message_rbuffer; | |
89 | uint8_t __iomem * iop_data = (uint8_t __iomem *)prbuffer->data; | |
90 | int32_t iop_len; | |
91 | ||
92 | acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; | |
93 | iop_len = readl(&prbuffer->data_len); | |
94 | while (iop_len > 0) { | |
95 | acb->rqbuffer[acb->rqbuf_lastindex] = readb(iop_data); | |
96 | acb->rqbuf_lastindex++; | |
97 | acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER; | |
98 | iop_data++; | |
99 | iop_len--; | |
100 | } | |
101 | writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK, | |
102 | ®->inbound_doorbell); | |
103 | } | |
104 | return (allxfer_len); | |
105 | } | |
106 | ||
107 | static ssize_t | |
108 | arcmsr_sysfs_iop_message_write(struct kobject *kobj, char *buf, loff_t off, | |
109 | size_t count) | |
110 | { | |
111 | struct class_device *cdev = container_of(kobj,struct class_device,kobj); | |
112 | struct Scsi_Host *host = class_to_shost(cdev); | |
113 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
114 | int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex; | |
115 | uint8_t *pQbuffer, *ptmpuserbuffer; | |
116 | ||
117 | if (!capable(CAP_SYS_ADMIN)) | |
118 | return -EACCES; | |
119 | if (count > 1032) | |
120 | return -EINVAL; | |
121 | /* do message unit write. */ | |
122 | ptmpuserbuffer = (uint8_t *)buf; | |
123 | user_len = (int32_t)count; | |
124 | wqbuf_lastindex = acb->wqbuf_lastindex; | |
125 | wqbuf_firstindex = acb->wqbuf_firstindex; | |
126 | if (wqbuf_lastindex != wqbuf_firstindex) { | |
127 | arcmsr_post_Qbuffer(acb); | |
128 | return 0; /*need retry*/ | |
129 | } else { | |
130 | my_empty_len = (wqbuf_firstindex-wqbuf_lastindex - 1) | |
131 | &(ARCMSR_MAX_QBUFFER - 1); | |
132 | if (my_empty_len >= user_len) { | |
133 | while (user_len > 0) { | |
134 | pQbuffer = | |
135 | &acb->wqbuffer[acb->wqbuf_lastindex]; | |
136 | memcpy(pQbuffer, ptmpuserbuffer, 1); | |
137 | acb->wqbuf_lastindex++; | |
138 | acb->wqbuf_lastindex %= ARCMSR_MAX_QBUFFER; | |
139 | ptmpuserbuffer++; | |
140 | user_len--; | |
141 | } | |
142 | if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) { | |
143 | acb->acb_flags &= | |
144 | ~ACB_F_MESSAGE_WQBUFFER_CLEARED; | |
145 | arcmsr_post_Qbuffer(acb); | |
146 | } | |
147 | return count; | |
148 | } else { | |
149 | return 0; /*need retry*/ | |
150 | } | |
151 | } | |
152 | } | |
153 | ||
154 | static ssize_t | |
155 | arcmsr_sysfs_iop_message_clear(struct kobject *kobj, char *buf, loff_t off, | |
156 | size_t count) | |
157 | { | |
158 | struct class_device *cdev = container_of(kobj,struct class_device,kobj); | |
159 | struct Scsi_Host *host = class_to_shost(cdev); | |
160 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
161 | struct MessageUnit __iomem *reg = acb->pmu; | |
162 | uint8_t *pQbuffer; | |
163 | ||
164 | if (!capable(CAP_SYS_ADMIN)) | |
165 | return -EACCES; | |
166 | ||
167 | if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) { | |
168 | acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW; | |
169 | writel(ARCMSR_INBOUND_DRIVER_DATA_READ_OK | |
170 | , ®->inbound_doorbell); | |
171 | } | |
172 | acb->acb_flags |= | |
173 | (ACB_F_MESSAGE_WQBUFFER_CLEARED | |
174 | | ACB_F_MESSAGE_RQBUFFER_CLEARED | |
175 | | ACB_F_MESSAGE_WQBUFFER_READED); | |
176 | acb->rqbuf_firstindex = 0; | |
177 | acb->rqbuf_lastindex = 0; | |
178 | acb->wqbuf_firstindex = 0; | |
179 | acb->wqbuf_lastindex = 0; | |
180 | pQbuffer = acb->rqbuffer; | |
181 | memset(pQbuffer, 0, sizeof (struct QBUFFER)); | |
182 | pQbuffer = acb->wqbuffer; | |
183 | memset(pQbuffer, 0, sizeof (struct QBUFFER)); | |
184 | return 1; | |
185 | } | |
186 | ||
187 | static struct bin_attribute arcmsr_sysfs_message_read_attr = { | |
188 | .attr = { | |
189 | .name = "mu_read", | |
190 | .mode = S_IRUSR , | |
1c57e86d EC |
191 | }, |
192 | .size = 1032, | |
193 | .read = arcmsr_sysfs_iop_message_read, | |
194 | }; | |
195 | ||
196 | static struct bin_attribute arcmsr_sysfs_message_write_attr = { | |
197 | .attr = { | |
198 | .name = "mu_write", | |
199 | .mode = S_IWUSR, | |
1c57e86d EC |
200 | }, |
201 | .size = 1032, | |
202 | .write = arcmsr_sysfs_iop_message_write, | |
203 | }; | |
204 | ||
205 | static struct bin_attribute arcmsr_sysfs_message_clear_attr = { | |
206 | .attr = { | |
207 | .name = "mu_clear", | |
208 | .mode = S_IWUSR, | |
1c57e86d EC |
209 | }, |
210 | .size = 1, | |
211 | .write = arcmsr_sysfs_iop_message_clear, | |
212 | }; | |
213 | ||
214 | int arcmsr_alloc_sysfs_attr(struct AdapterControlBlock *acb) | |
215 | { | |
216 | struct Scsi_Host *host = acb->host; | |
217 | int error; | |
218 | ||
219 | error = sysfs_create_bin_file(&host->shost_classdev.kobj, | |
220 | &arcmsr_sysfs_message_read_attr); | |
221 | if (error) { | |
222 | printk(KERN_ERR "arcmsr: alloc sysfs mu_read failed\n"); | |
223 | goto error_bin_file_message_read; | |
224 | } | |
225 | error = sysfs_create_bin_file(&host->shost_classdev.kobj, | |
226 | &arcmsr_sysfs_message_write_attr); | |
227 | if (error) { | |
228 | printk(KERN_ERR "arcmsr: alloc sysfs mu_write failed\n"); | |
229 | goto error_bin_file_message_write; | |
230 | } | |
231 | error = sysfs_create_bin_file(&host->shost_classdev.kobj, | |
232 | &arcmsr_sysfs_message_clear_attr); | |
233 | if (error) { | |
234 | printk(KERN_ERR "arcmsr: alloc sysfs mu_clear failed\n"); | |
235 | goto error_bin_file_message_clear; | |
236 | } | |
237 | return 0; | |
238 | error_bin_file_message_clear: | |
43d6b68d | 239 | sysfs_remove_bin_file(&host->shost_classdev.kobj, |
1c57e86d | 240 | &arcmsr_sysfs_message_write_attr); |
1c57e86d | 241 | error_bin_file_message_write: |
43d6b68d | 242 | sysfs_remove_bin_file(&host->shost_classdev.kobj, |
1c57e86d | 243 | &arcmsr_sysfs_message_read_attr); |
1c57e86d EC |
244 | error_bin_file_message_read: |
245 | return error; | |
246 | } | |
247 | ||
248 | void | |
249 | arcmsr_free_sysfs_attr(struct AdapterControlBlock *acb) { | |
250 | struct Scsi_Host *host = acb->host; | |
1c57e86d | 251 | |
43d6b68d | 252 | sysfs_remove_bin_file(&host->shost_classdev.kobj, |
1c57e86d | 253 | &arcmsr_sysfs_message_clear_attr); |
43d6b68d | 254 | sysfs_remove_bin_file(&host->shost_classdev.kobj, |
1c57e86d | 255 | &arcmsr_sysfs_message_write_attr); |
43d6b68d | 256 | sysfs_remove_bin_file(&host->shost_classdev.kobj, |
1c57e86d | 257 | &arcmsr_sysfs_message_read_attr); |
1c57e86d EC |
258 | } |
259 | ||
260 | ||
261 | static ssize_t | |
262 | arcmsr_attr_host_driver_version(struct class_device *cdev, char *buf) { | |
263 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 264 | "%s\n", |
1c57e86d EC |
265 | ARCMSR_DRIVER_VERSION); |
266 | } | |
267 | ||
268 | static ssize_t | |
269 | arcmsr_attr_host_driver_posted_cmd(struct class_device *cdev, char *buf) { | |
270 | struct Scsi_Host *host = class_to_shost(cdev); | |
271 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
272 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 273 | "%4d\n", |
1c57e86d EC |
274 | atomic_read(&acb->ccboutstandingcount)); |
275 | } | |
276 | ||
277 | static ssize_t | |
278 | arcmsr_attr_host_driver_reset(struct class_device *cdev, char *buf) { | |
279 | struct Scsi_Host *host = class_to_shost(cdev); | |
280 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
281 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 282 | "%4d\n", |
1c57e86d EC |
283 | acb->num_resets); |
284 | } | |
285 | ||
286 | static ssize_t | |
287 | arcmsr_attr_host_driver_abort(struct class_device *cdev, char *buf) { | |
288 | struct Scsi_Host *host = class_to_shost(cdev); | |
289 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
290 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 291 | "%4d\n", |
1c57e86d EC |
292 | acb->num_aborts); |
293 | } | |
294 | ||
295 | static ssize_t | |
296 | arcmsr_attr_host_fw_model(struct class_device *cdev, char *buf) { | |
297 | struct Scsi_Host *host = class_to_shost(cdev); | |
298 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
299 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 300 | "%s\n", |
1c57e86d EC |
301 | acb->firm_model); |
302 | } | |
303 | ||
304 | static ssize_t | |
305 | arcmsr_attr_host_fw_version(struct class_device *cdev, char *buf) { | |
306 | struct Scsi_Host *host = class_to_shost(cdev); | |
307 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
308 | ||
309 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 310 | "%s\n", |
1c57e86d EC |
311 | acb->firm_version); |
312 | } | |
313 | ||
314 | static ssize_t | |
315 | arcmsr_attr_host_fw_request_len(struct class_device *cdev, char *buf) { | |
316 | struct Scsi_Host *host = class_to_shost(cdev); | |
317 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
318 | ||
319 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 320 | "%4d\n", |
1c57e86d EC |
321 | acb->firm_request_len); |
322 | } | |
323 | ||
324 | static ssize_t | |
325 | arcmsr_attr_host_fw_numbers_queue(struct class_device *cdev, char *buf) { | |
326 | struct Scsi_Host *host = class_to_shost(cdev); | |
327 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
328 | ||
329 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 330 | "%4d\n", |
1c57e86d EC |
331 | acb->firm_numbers_queue); |
332 | } | |
333 | ||
334 | static ssize_t | |
335 | arcmsr_attr_host_fw_sdram_size(struct class_device *cdev, char *buf) { | |
336 | struct Scsi_Host *host = class_to_shost(cdev); | |
337 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
338 | ||
339 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 340 | "%4d\n", |
1c57e86d EC |
341 | acb->firm_sdram_size); |
342 | } | |
343 | ||
344 | static ssize_t | |
345 | arcmsr_attr_host_fw_hd_channels(struct class_device *cdev, char *buf) { | |
346 | struct Scsi_Host *host = class_to_shost(cdev); | |
347 | struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata; | |
348 | ||
349 | return snprintf(buf, PAGE_SIZE, | |
d67a70ac | 350 | "%4d\n", |
1c57e86d EC |
351 | acb->firm_hd_channels); |
352 | } | |
353 | ||
354 | static CLASS_DEVICE_ATTR(host_driver_version, S_IRUGO, arcmsr_attr_host_driver_version, NULL); | |
355 | static CLASS_DEVICE_ATTR(host_driver_posted_cmd, S_IRUGO, arcmsr_attr_host_driver_posted_cmd, NULL); | |
356 | static CLASS_DEVICE_ATTR(host_driver_reset, S_IRUGO, arcmsr_attr_host_driver_reset, NULL); | |
357 | static CLASS_DEVICE_ATTR(host_driver_abort, S_IRUGO, arcmsr_attr_host_driver_abort, NULL); | |
358 | static CLASS_DEVICE_ATTR(host_fw_model, S_IRUGO, arcmsr_attr_host_fw_model, NULL); | |
359 | static CLASS_DEVICE_ATTR(host_fw_version, S_IRUGO, arcmsr_attr_host_fw_version, NULL); | |
360 | static CLASS_DEVICE_ATTR(host_fw_request_len, S_IRUGO, arcmsr_attr_host_fw_request_len, NULL); | |
361 | static CLASS_DEVICE_ATTR(host_fw_numbers_queue, S_IRUGO, arcmsr_attr_host_fw_numbers_queue, NULL); | |
362 | static CLASS_DEVICE_ATTR(host_fw_sdram_size, S_IRUGO, arcmsr_attr_host_fw_sdram_size, NULL); | |
363 | static CLASS_DEVICE_ATTR(host_fw_hd_channels, S_IRUGO, arcmsr_attr_host_fw_hd_channels, NULL); | |
364 | ||
365 | struct class_device_attribute *arcmsr_host_attrs[] = { | |
366 | &class_device_attr_host_driver_version, | |
367 | &class_device_attr_host_driver_posted_cmd, | |
368 | &class_device_attr_host_driver_reset, | |
369 | &class_device_attr_host_driver_abort, | |
370 | &class_device_attr_host_fw_model, | |
371 | &class_device_attr_host_fw_version, | |
372 | &class_device_attr_host_fw_request_len, | |
373 | &class_device_attr_host_fw_numbers_queue, | |
374 | &class_device_attr_host_fw_sdram_size, | |
375 | &class_device_attr_host_fw_hd_channels, | |
376 | NULL, | |
377 | }; |