2 *******************************************************************************
4 ** FILE NAME : arcmsr_attr.c
6 ** Description: attributes exported to sysfs and device host
7 *******************************************************************************
8 ** Copyright (C) 2002 - 2005, Areca Technology Corporation All rights reserved
10 ** Web site: www.areca.com.tw
11 ** E-mail: support@areca.com.tw
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
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.
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 *******************************************************************************
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>
52 #include <linux/pci.h>
54 #include <scsi/scsi_cmnd.h>
55 #include <scsi/scsi_device.h>
56 #include <scsi/scsi_host.h>
57 #include <scsi/scsi_transport.h>
60 struct class_device_attribute
*arcmsr_host_attrs
[];
62 static ssize_t
arcmsr_sysfs_iop_message_read(struct kobject
*kobj
,
63 struct bin_attribute
*bin
,
64 char *buf
, loff_t off
,
67 struct class_device
*cdev
= container_of(kobj
,struct class_device
,kobj
);
68 struct Scsi_Host
*host
= class_to_shost(cdev
);
69 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
70 uint8_t *pQbuffer
,*ptmpQbuffer
;
71 int32_t allxfer_len
= 0;
73 if (!capable(CAP_SYS_ADMIN
))
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
;
87 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
88 struct QBUFFER __iomem
*prbuffer
;
89 uint8_t __iomem
*iop_data
;
92 acb
->acb_flags
&= ~ACB_F_IOPDATA_OVERFLOW
;
93 prbuffer
= arcmsr_get_iop_rqbuffer(acb
);
94 iop_data
= prbuffer
->data
;
95 iop_len
= readl(&prbuffer
->data_len
);
97 acb
->rqbuffer
[acb
->rqbuf_lastindex
] = readb(iop_data
);
98 acb
->rqbuf_lastindex
++;
99 acb
->rqbuf_lastindex
%= ARCMSR_MAX_QBUFFER
;
103 arcmsr_iop_message_read(acb
);
105 return (allxfer_len
);
108 static ssize_t
arcmsr_sysfs_iop_message_write(struct kobject
*kobj
,
109 struct bin_attribute
*bin
,
110 char *buf
, loff_t off
,
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
;
119 if (!capable(CAP_SYS_ADMIN
))
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_ioctldata2iop(acb
);
130 return 0; /*need retry*/
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) {
137 &acb
->wqbuffer
[acb
->wqbuf_lastindex
];
138 memcpy(pQbuffer
, ptmpuserbuffer
, 1);
139 acb
->wqbuf_lastindex
++;
140 acb
->wqbuf_lastindex
%= ARCMSR_MAX_QBUFFER
;
144 if (acb
->acb_flags
& ACB_F_MESSAGE_WQBUFFER_CLEARED
) {
146 ~ACB_F_MESSAGE_WQBUFFER_CLEARED
;
147 arcmsr_post_ioctldata2iop(acb
);
151 return 0; /*need retry*/
156 static ssize_t
arcmsr_sysfs_iop_message_clear(struct kobject
*kobj
,
157 struct bin_attribute
*bin
,
158 char *buf
, loff_t off
,
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
;
166 if (!capable(CAP_SYS_ADMIN
))
169 if (acb
->acb_flags
& ACB_F_IOPDATA_OVERFLOW
) {
170 acb
->acb_flags
&= ~ACB_F_IOPDATA_OVERFLOW
;
171 arcmsr_iop_message_read(acb
);
174 (ACB_F_MESSAGE_WQBUFFER_CLEARED
175 | ACB_F_MESSAGE_RQBUFFER_CLEARED
176 | ACB_F_MESSAGE_WQBUFFER_READED
);
177 acb
->rqbuf_firstindex
= 0;
178 acb
->rqbuf_lastindex
= 0;
179 acb
->wqbuf_firstindex
= 0;
180 acb
->wqbuf_lastindex
= 0;
181 pQbuffer
= acb
->rqbuffer
;
182 memset(pQbuffer
, 0, sizeof (struct QBUFFER
));
183 pQbuffer
= acb
->wqbuffer
;
184 memset(pQbuffer
, 0, sizeof (struct QBUFFER
));
188 static struct bin_attribute arcmsr_sysfs_message_read_attr
= {
192 .owner
= THIS_MODULE
,
195 .read
= arcmsr_sysfs_iop_message_read
,
198 static struct bin_attribute arcmsr_sysfs_message_write_attr
= {
202 .owner
= THIS_MODULE
,
205 .write
= arcmsr_sysfs_iop_message_write
,
208 static struct bin_attribute arcmsr_sysfs_message_clear_attr
= {
212 .owner
= THIS_MODULE
,
215 .write
= arcmsr_sysfs_iop_message_clear
,
218 int arcmsr_alloc_sysfs_attr(struct AdapterControlBlock
*acb
)
220 struct Scsi_Host
*host
= acb
->host
;
223 error
= sysfs_create_bin_file(&host
->shost_classdev
.kobj
, &arcmsr_sysfs_message_read_attr
);
225 printk(KERN_ERR
"arcmsr: alloc sysfs mu_read failed\n");
226 goto error_bin_file_message_read
;
228 error
= sysfs_create_bin_file(&host
->shost_classdev
.kobj
, &arcmsr_sysfs_message_write_attr
);
230 printk(KERN_ERR
"arcmsr: alloc sysfs mu_write failed\n");
231 goto error_bin_file_message_write
;
233 error
= sysfs_create_bin_file(&host
->shost_classdev
.kobj
, &arcmsr_sysfs_message_clear_attr
);
235 printk(KERN_ERR
"arcmsr: alloc sysfs mu_clear failed\n");
236 goto error_bin_file_message_clear
;
239 error_bin_file_message_clear
:
240 sysfs_remove_bin_file(&host
->shost_classdev
.kobj
, &arcmsr_sysfs_message_write_attr
);
241 error_bin_file_message_write
:
242 sysfs_remove_bin_file(&host
->shost_classdev
.kobj
, &arcmsr_sysfs_message_read_attr
);
243 error_bin_file_message_read
:
248 arcmsr_free_sysfs_attr(struct AdapterControlBlock
*acb
) {
249 struct Scsi_Host
*host
= acb
->host
;
251 sysfs_remove_bin_file(&host
->shost_classdev
.kobj
, &arcmsr_sysfs_message_clear_attr
);
252 sysfs_remove_bin_file(&host
->shost_classdev
.kobj
, &arcmsr_sysfs_message_write_attr
);
253 sysfs_remove_bin_file(&host
->shost_classdev
.kobj
, &arcmsr_sysfs_message_read_attr
);
258 arcmsr_attr_host_driver_version(struct class_device
*cdev
, char *buf
) {
259 return snprintf(buf
, PAGE_SIZE
,
261 ARCMSR_DRIVER_VERSION
);
265 arcmsr_attr_host_driver_posted_cmd(struct class_device
*cdev
, char *buf
) {
266 struct Scsi_Host
*host
= class_to_shost(cdev
);
267 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
268 return snprintf(buf
, PAGE_SIZE
,
270 atomic_read(&acb
->ccboutstandingcount
));
274 arcmsr_attr_host_driver_reset(struct class_device
*cdev
, char *buf
) {
275 struct Scsi_Host
*host
= class_to_shost(cdev
);
276 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
277 return snprintf(buf
, PAGE_SIZE
,
283 arcmsr_attr_host_driver_abort(struct class_device
*cdev
, char *buf
) {
284 struct Scsi_Host
*host
= class_to_shost(cdev
);
285 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
286 return snprintf(buf
, PAGE_SIZE
,
292 arcmsr_attr_host_fw_model(struct class_device
*cdev
, char *buf
) {
293 struct Scsi_Host
*host
= class_to_shost(cdev
);
294 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
295 return snprintf(buf
, PAGE_SIZE
,
301 arcmsr_attr_host_fw_version(struct class_device
*cdev
, char *buf
) {
302 struct Scsi_Host
*host
= class_to_shost(cdev
);
303 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
305 return snprintf(buf
, PAGE_SIZE
,
311 arcmsr_attr_host_fw_request_len(struct class_device
*cdev
, char *buf
) {
312 struct Scsi_Host
*host
= class_to_shost(cdev
);
313 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
315 return snprintf(buf
, PAGE_SIZE
,
317 acb
->firm_request_len
);
321 arcmsr_attr_host_fw_numbers_queue(struct class_device
*cdev
, char *buf
) {
322 struct Scsi_Host
*host
= class_to_shost(cdev
);
323 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
325 return snprintf(buf
, PAGE_SIZE
,
327 acb
->firm_numbers_queue
);
331 arcmsr_attr_host_fw_sdram_size(struct class_device
*cdev
, char *buf
) {
332 struct Scsi_Host
*host
= class_to_shost(cdev
);
333 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
335 return snprintf(buf
, PAGE_SIZE
,
337 acb
->firm_sdram_size
);
341 arcmsr_attr_host_fw_hd_channels(struct class_device
*cdev
, char *buf
) {
342 struct Scsi_Host
*host
= class_to_shost(cdev
);
343 struct AdapterControlBlock
*acb
= (struct AdapterControlBlock
*) host
->hostdata
;
345 return snprintf(buf
, PAGE_SIZE
,
347 acb
->firm_hd_channels
);
350 static CLASS_DEVICE_ATTR(host_driver_version
, S_IRUGO
, arcmsr_attr_host_driver_version
, NULL
);
351 static CLASS_DEVICE_ATTR(host_driver_posted_cmd
, S_IRUGO
, arcmsr_attr_host_driver_posted_cmd
, NULL
);
352 static CLASS_DEVICE_ATTR(host_driver_reset
, S_IRUGO
, arcmsr_attr_host_driver_reset
, NULL
);
353 static CLASS_DEVICE_ATTR(host_driver_abort
, S_IRUGO
, arcmsr_attr_host_driver_abort
, NULL
);
354 static CLASS_DEVICE_ATTR(host_fw_model
, S_IRUGO
, arcmsr_attr_host_fw_model
, NULL
);
355 static CLASS_DEVICE_ATTR(host_fw_version
, S_IRUGO
, arcmsr_attr_host_fw_version
, NULL
);
356 static CLASS_DEVICE_ATTR(host_fw_request_len
, S_IRUGO
, arcmsr_attr_host_fw_request_len
, NULL
);
357 static CLASS_DEVICE_ATTR(host_fw_numbers_queue
, S_IRUGO
, arcmsr_attr_host_fw_numbers_queue
, NULL
);
358 static CLASS_DEVICE_ATTR(host_fw_sdram_size
, S_IRUGO
, arcmsr_attr_host_fw_sdram_size
, NULL
);
359 static CLASS_DEVICE_ATTR(host_fw_hd_channels
, S_IRUGO
, arcmsr_attr_host_fw_hd_channels
, NULL
);
361 struct class_device_attribute
*arcmsr_host_attrs
[] = {
362 &class_device_attr_host_driver_version
,
363 &class_device_attr_host_driver_posted_cmd
,
364 &class_device_attr_host_driver_reset
,
365 &class_device_attr_host_driver_abort
,
366 &class_device_attr_host_fw_model
,
367 &class_device_attr_host_fw_version
,
368 &class_device_attr_host_fw_request_len
,
369 &class_device_attr_host_fw_numbers_queue
,
370 &class_device_attr_host_fw_sdram_size
,
371 &class_device_attr_host_fw_hd_channels
,