]> bbs.cooldavid.org Git - net-next-2.6.git/blame - drivers/scsi/arcmsr/arcmsr_attr.c
Merge branch 'fix' of git://git.kernel.org/pub/scm/linux/kernel/git/ycmiao/pxa-linux-2.6
[net-next-2.6.git] / drivers / scsi / arcmsr / arcmsr_attr.c
CommitLineData
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
1a4f550a 11** E-mail: support@areca.com.tw
1c57e86d
EC
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>
1a4f550a 52#include <linux/pci.h>
1c57e86d
EC
53
54#include <scsi/scsi_cmnd.h>
55#include <scsi/scsi_device.h>
56#include <scsi/scsi_host.h>
57#include <scsi/scsi_transport.h>
58#include "arcmsr.h"
59
ee959b00 60struct device_attribute *arcmsr_host_attrs[];
1c57e86d 61
2c3c8bea
CW
62static ssize_t arcmsr_sysfs_iop_message_read(struct file *filp,
63 struct kobject *kobj,
685b9e02
JB
64 struct bin_attribute *bin,
65 char *buf, loff_t off,
66 size_t count)
1c57e86d 67{
ee959b00
TJ
68 struct device *dev = container_of(kobj,struct device,kobj);
69 struct Scsi_Host *host = class_to_shost(dev);
1c57e86d 70 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
1c57e86d
EC
71 uint8_t *pQbuffer,*ptmpQbuffer;
72 int32_t allxfer_len = 0;
73
74 if (!capable(CAP_SYS_ADMIN))
75 return -EACCES;
76
77 /* do message unit read. */
78 ptmpQbuffer = (uint8_t *)buf;
79 while ((acb->rqbuf_firstindex != acb->rqbuf_lastindex)
80 && (allxfer_len < 1031)) {
81 pQbuffer = &acb->rqbuffer[acb->rqbuf_firstindex];
82 memcpy(ptmpQbuffer, pQbuffer, 1);
83 acb->rqbuf_firstindex++;
84 acb->rqbuf_firstindex %= ARCMSR_MAX_QBUFFER;
85 ptmpQbuffer++;
86 allxfer_len++;
87 }
88 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
80da1adb
AV
89 struct QBUFFER __iomem *prbuffer;
90 uint8_t __iomem *iop_data;
1c57e86d
EC
91 int32_t iop_len;
92
93 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
1a4f550a 94 prbuffer = arcmsr_get_iop_rqbuffer(acb);
80da1adb 95 iop_data = prbuffer->data;
1c57e86d
EC
96 iop_len = readl(&prbuffer->data_len);
97 while (iop_len > 0) {
98 acb->rqbuffer[acb->rqbuf_lastindex] = readb(iop_data);
99 acb->rqbuf_lastindex++;
100 acb->rqbuf_lastindex %= ARCMSR_MAX_QBUFFER;
101 iop_data++;
102 iop_len--;
103 }
1a4f550a 104 arcmsr_iop_message_read(acb);
1c57e86d
EC
105 }
106 return (allxfer_len);
107}
108
2c3c8bea
CW
109static ssize_t arcmsr_sysfs_iop_message_write(struct file *filp,
110 struct kobject *kobj,
685b9e02
JB
111 struct bin_attribute *bin,
112 char *buf, loff_t off,
113 size_t count)
1c57e86d 114{
ee959b00
TJ
115 struct device *dev = container_of(kobj,struct device,kobj);
116 struct Scsi_Host *host = class_to_shost(dev);
1c57e86d
EC
117 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
118 int32_t my_empty_len, user_len, wqbuf_firstindex, wqbuf_lastindex;
119 uint8_t *pQbuffer, *ptmpuserbuffer;
120
121 if (!capable(CAP_SYS_ADMIN))
122 return -EACCES;
123 if (count > 1032)
124 return -EINVAL;
125 /* do message unit write. */
126 ptmpuserbuffer = (uint8_t *)buf;
127 user_len = (int32_t)count;
128 wqbuf_lastindex = acb->wqbuf_lastindex;
129 wqbuf_firstindex = acb->wqbuf_firstindex;
130 if (wqbuf_lastindex != wqbuf_firstindex) {
1a4f550a 131 arcmsr_post_ioctldata2iop(acb);
1c57e86d
EC
132 return 0; /*need retry*/
133 } else {
134 my_empty_len = (wqbuf_firstindex-wqbuf_lastindex - 1)
135 &(ARCMSR_MAX_QBUFFER - 1);
136 if (my_empty_len >= user_len) {
137 while (user_len > 0) {
138 pQbuffer =
139 &acb->wqbuffer[acb->wqbuf_lastindex];
140 memcpy(pQbuffer, ptmpuserbuffer, 1);
141 acb->wqbuf_lastindex++;
142 acb->wqbuf_lastindex %= ARCMSR_MAX_QBUFFER;
143 ptmpuserbuffer++;
144 user_len--;
145 }
146 if (acb->acb_flags & ACB_F_MESSAGE_WQBUFFER_CLEARED) {
147 acb->acb_flags &=
148 ~ACB_F_MESSAGE_WQBUFFER_CLEARED;
1a4f550a 149 arcmsr_post_ioctldata2iop(acb);
1c57e86d
EC
150 }
151 return count;
152 } else {
153 return 0; /*need retry*/
154 }
155 }
156}
157
2c3c8bea
CW
158static ssize_t arcmsr_sysfs_iop_message_clear(struct file *filp,
159 struct kobject *kobj,
685b9e02
JB
160 struct bin_attribute *bin,
161 char *buf, loff_t off,
162 size_t count)
1c57e86d 163{
ee959b00
TJ
164 struct device *dev = container_of(kobj,struct device,kobj);
165 struct Scsi_Host *host = class_to_shost(dev);
1c57e86d 166 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
1c57e86d
EC
167 uint8_t *pQbuffer;
168
169 if (!capable(CAP_SYS_ADMIN))
170 return -EACCES;
171
172 if (acb->acb_flags & ACB_F_IOPDATA_OVERFLOW) {
173 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
1a4f550a 174 arcmsr_iop_message_read(acb);
1c57e86d
EC
175 }
176 acb->acb_flags |=
177 (ACB_F_MESSAGE_WQBUFFER_CLEARED
178 | ACB_F_MESSAGE_RQBUFFER_CLEARED
179 | ACB_F_MESSAGE_WQBUFFER_READED);
180 acb->rqbuf_firstindex = 0;
181 acb->rqbuf_lastindex = 0;
182 acb->wqbuf_firstindex = 0;
183 acb->wqbuf_lastindex = 0;
184 pQbuffer = acb->rqbuffer;
185 memset(pQbuffer, 0, sizeof (struct QBUFFER));
186 pQbuffer = acb->wqbuffer;
187 memset(pQbuffer, 0, sizeof (struct QBUFFER));
188 return 1;
189}
190
191static struct bin_attribute arcmsr_sysfs_message_read_attr = {
192 .attr = {
193 .name = "mu_read",
194 .mode = S_IRUSR ,
36b83ded 195 .owner = THIS_MODULE,
1c57e86d
EC
196 },
197 .size = 1032,
198 .read = arcmsr_sysfs_iop_message_read,
199};
200
201static struct bin_attribute arcmsr_sysfs_message_write_attr = {
202 .attr = {
203 .name = "mu_write",
204 .mode = S_IWUSR,
36b83ded 205 .owner = THIS_MODULE,
1c57e86d
EC
206 },
207 .size = 1032,
208 .write = arcmsr_sysfs_iop_message_write,
209};
210
211static struct bin_attribute arcmsr_sysfs_message_clear_attr = {
212 .attr = {
213 .name = "mu_clear",
214 .mode = S_IWUSR,
36b83ded 215 .owner = THIS_MODULE,
1c57e86d
EC
216 },
217 .size = 1,
218 .write = arcmsr_sysfs_iop_message_clear,
219};
220
221int arcmsr_alloc_sysfs_attr(struct AdapterControlBlock *acb)
222{
223 struct Scsi_Host *host = acb->host;
224 int error;
225
ee959b00 226 error = sysfs_create_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_read_attr);
1c57e86d
EC
227 if (error) {
228 printk(KERN_ERR "arcmsr: alloc sysfs mu_read failed\n");
229 goto error_bin_file_message_read;
230 }
ee959b00 231 error = sysfs_create_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_write_attr);
1c57e86d
EC
232 if (error) {
233 printk(KERN_ERR "arcmsr: alloc sysfs mu_write failed\n");
234 goto error_bin_file_message_write;
235 }
ee959b00 236 error = sysfs_create_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_clear_attr);
1c57e86d
EC
237 if (error) {
238 printk(KERN_ERR "arcmsr: alloc sysfs mu_clear failed\n");
239 goto error_bin_file_message_clear;
240 }
241 return 0;
242error_bin_file_message_clear:
ee959b00 243 sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_write_attr);
1c57e86d 244error_bin_file_message_write:
ee959b00 245 sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_read_attr);
1c57e86d
EC
246error_bin_file_message_read:
247 return error;
248}
249
ee959b00
TJ
250void arcmsr_free_sysfs_attr(struct AdapterControlBlock *acb)
251{
1c57e86d 252 struct Scsi_Host *host = acb->host;
1c57e86d 253
ee959b00
TJ
254 sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_clear_attr);
255 sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_write_attr);
256 sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_read_attr);
1c57e86d
EC
257}
258
259
260static ssize_t
ee959b00
TJ
261arcmsr_attr_host_driver_version(struct device *dev,
262 struct device_attribute *attr, char *buf)
263{
1c57e86d 264 return snprintf(buf, PAGE_SIZE,
d67a70ac 265 "%s\n",
1c57e86d
EC
266 ARCMSR_DRIVER_VERSION);
267}
268
269static ssize_t
ee959b00
TJ
270arcmsr_attr_host_driver_posted_cmd(struct device *dev,
271 struct device_attribute *attr, char *buf)
272{
273 struct Scsi_Host *host = class_to_shost(dev);
274 struct AdapterControlBlock *acb =
275 (struct AdapterControlBlock *) host->hostdata;
1c57e86d 276 return snprintf(buf, PAGE_SIZE,
d67a70ac 277 "%4d\n",
1c57e86d
EC
278 atomic_read(&acb->ccboutstandingcount));
279}
280
281static ssize_t
ee959b00
TJ
282arcmsr_attr_host_driver_reset(struct device *dev,
283 struct device_attribute *attr, char *buf)
284{
285 struct Scsi_Host *host = class_to_shost(dev);
286 struct AdapterControlBlock *acb =
287 (struct AdapterControlBlock *) host->hostdata;
1c57e86d 288 return snprintf(buf, PAGE_SIZE,
d67a70ac 289 "%4d\n",
1c57e86d
EC
290 acb->num_resets);
291}
292
293static ssize_t
ee959b00
TJ
294arcmsr_attr_host_driver_abort(struct device *dev,
295 struct device_attribute *attr, char *buf)
296{
297 struct Scsi_Host *host = class_to_shost(dev);
298 struct AdapterControlBlock *acb =
299 (struct AdapterControlBlock *) host->hostdata;
1c57e86d 300 return snprintf(buf, PAGE_SIZE,
d67a70ac 301 "%4d\n",
1c57e86d
EC
302 acb->num_aborts);
303}
304
305static ssize_t
ee959b00
TJ
306arcmsr_attr_host_fw_model(struct device *dev, struct device_attribute *attr,
307 char *buf)
308{
309 struct Scsi_Host *host = class_to_shost(dev);
310 struct AdapterControlBlock *acb =
311 (struct AdapterControlBlock *) host->hostdata;
1c57e86d 312 return snprintf(buf, PAGE_SIZE,
d67a70ac 313 "%s\n",
1c57e86d
EC
314 acb->firm_model);
315}
316
317static ssize_t
ee959b00
TJ
318arcmsr_attr_host_fw_version(struct device *dev,
319 struct device_attribute *attr, char *buf)
320{
321 struct Scsi_Host *host = class_to_shost(dev);
322 struct AdapterControlBlock *acb =
323 (struct AdapterControlBlock *) host->hostdata;
1c57e86d
EC
324
325 return snprintf(buf, PAGE_SIZE,
d67a70ac 326 "%s\n",
1c57e86d
EC
327 acb->firm_version);
328}
329
330static ssize_t
ee959b00
TJ
331arcmsr_attr_host_fw_request_len(struct device *dev,
332 struct device_attribute *attr, char *buf)
333{
334 struct Scsi_Host *host = class_to_shost(dev);
335 struct AdapterControlBlock *acb =
336 (struct AdapterControlBlock *) host->hostdata;
1c57e86d
EC
337
338 return snprintf(buf, PAGE_SIZE,
d67a70ac 339 "%4d\n",
1c57e86d
EC
340 acb->firm_request_len);
341}
342
343static ssize_t
ee959b00
TJ
344arcmsr_attr_host_fw_numbers_queue(struct device *dev,
345 struct device_attribute *attr, char *buf)
346{
347 struct Scsi_Host *host = class_to_shost(dev);
348 struct AdapterControlBlock *acb =
349 (struct AdapterControlBlock *) host->hostdata;
1c57e86d
EC
350
351 return snprintf(buf, PAGE_SIZE,
d67a70ac 352 "%4d\n",
1c57e86d
EC
353 acb->firm_numbers_queue);
354}
355
356static ssize_t
ee959b00
TJ
357arcmsr_attr_host_fw_sdram_size(struct device *dev,
358 struct device_attribute *attr, char *buf)
359{
360 struct Scsi_Host *host = class_to_shost(dev);
361 struct AdapterControlBlock *acb =
362 (struct AdapterControlBlock *) host->hostdata;
1c57e86d
EC
363
364 return snprintf(buf, PAGE_SIZE,
d67a70ac 365 "%4d\n",
1c57e86d
EC
366 acb->firm_sdram_size);
367}
368
369static ssize_t
ee959b00
TJ
370arcmsr_attr_host_fw_hd_channels(struct device *dev,
371 struct device_attribute *attr, char *buf)
372{
373 struct Scsi_Host *host = class_to_shost(dev);
374 struct AdapterControlBlock *acb =
375 (struct AdapterControlBlock *) host->hostdata;
1c57e86d
EC
376
377 return snprintf(buf, PAGE_SIZE,
d67a70ac 378 "%4d\n",
1c57e86d
EC
379 acb->firm_hd_channels);
380}
381
ee959b00
TJ
382static DEVICE_ATTR(host_driver_version, S_IRUGO, arcmsr_attr_host_driver_version, NULL);
383static DEVICE_ATTR(host_driver_posted_cmd, S_IRUGO, arcmsr_attr_host_driver_posted_cmd, NULL);
384static DEVICE_ATTR(host_driver_reset, S_IRUGO, arcmsr_attr_host_driver_reset, NULL);
385static DEVICE_ATTR(host_driver_abort, S_IRUGO, arcmsr_attr_host_driver_abort, NULL);
386static DEVICE_ATTR(host_fw_model, S_IRUGO, arcmsr_attr_host_fw_model, NULL);
387static DEVICE_ATTR(host_fw_version, S_IRUGO, arcmsr_attr_host_fw_version, NULL);
388static DEVICE_ATTR(host_fw_request_len, S_IRUGO, arcmsr_attr_host_fw_request_len, NULL);
389static DEVICE_ATTR(host_fw_numbers_queue, S_IRUGO, arcmsr_attr_host_fw_numbers_queue, NULL);
390static DEVICE_ATTR(host_fw_sdram_size, S_IRUGO, arcmsr_attr_host_fw_sdram_size, NULL);
391static DEVICE_ATTR(host_fw_hd_channels, S_IRUGO, arcmsr_attr_host_fw_hd_channels, NULL);
392
393struct device_attribute *arcmsr_host_attrs[] = {
394 &dev_attr_host_driver_version,
395 &dev_attr_host_driver_posted_cmd,
396 &dev_attr_host_driver_reset,
397 &dev_attr_host_driver_abort,
398 &dev_attr_host_fw_model,
399 &dev_attr_host_fw_version,
400 &dev_attr_host_fw_request_len,
401 &dev_attr_host_fw_numbers_queue,
402 &dev_attr_host_fw_sdram_size,
403 &dev_attr_host_fw_hd_channels,
1c57e86d
EC
404 NULL,
405};