blob: acdae33de52188f6ee16c3cbb55ef12db6e7c101 [file] [log] [blame]
Erich Chen1c57e862006-07-12 08:59:32 -07001/*
2*******************************************************************************
3** O.S : Linux
4** FILE NAME : arcmsr_attr.c
NickCheng97b99122011-01-06 17:32:41 +08005** BY : Nick Cheng
Erich Chen1c57e862006-07-12 08:59:32 -07006** 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
Nick Cheng1a4f5502007-09-13 17:26:40 +080011** E-mail: support@areca.com.tw
Erich Chen1c57e862006-07-12 08:59:32 -070012**
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>
Nick Cheng1a4f5502007-09-13 17:26:40 +080052#include <linux/pci.h>
Erich Chen1c57e862006-07-12 08:59:32 -070053
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
Tony Jonesee959b02008-02-22 00:13:36 +010060struct device_attribute *arcmsr_host_attrs[];
Erich Chen1c57e862006-07-12 08:59:32 -070061
Chris Wright2c3c8be2010-05-12 18:28:57 -070062static ssize_t arcmsr_sysfs_iop_message_read(struct file *filp,
63 struct kobject *kobj,
James Bottomley685b9e02007-09-15 11:41:53 -050064 struct bin_attribute *bin,
65 char *buf, loff_t off,
66 size_t count)
Erich Chen1c57e862006-07-12 08:59:32 -070067{
Tony Jonesee959b02008-02-22 00:13:36 +010068 struct device *dev = container_of(kobj,struct device,kobj);
69 struct Scsi_Host *host = class_to_shost(dev);
Erich Chen1c57e862006-07-12 08:59:32 -070070 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -070071 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) {
Al Viro80da1ad2007-10-29 05:08:28 +000089 struct QBUFFER __iomem *prbuffer;
90 uint8_t __iomem *iop_data;
Erich Chen1c57e862006-07-12 08:59:32 -070091 int32_t iop_len;
92
93 acb->acb_flags &= ~ACB_F_IOPDATA_OVERFLOW;
Nick Cheng1a4f5502007-09-13 17:26:40 +080094 prbuffer = arcmsr_get_iop_rqbuffer(acb);
Al Viro80da1ad2007-10-29 05:08:28 +000095 iop_data = prbuffer->data;
Erich Chen1c57e862006-07-12 08:59:32 -070096 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 }
Nick Cheng1a4f5502007-09-13 17:26:40 +0800104 arcmsr_iop_message_read(acb);
Erich Chen1c57e862006-07-12 08:59:32 -0700105 }
106 return (allxfer_len);
107}
108
Chris Wright2c3c8be2010-05-12 18:28:57 -0700109static ssize_t arcmsr_sysfs_iop_message_write(struct file *filp,
110 struct kobject *kobj,
James Bottomley685b9e02007-09-15 11:41:53 -0500111 struct bin_attribute *bin,
112 char *buf, loff_t off,
113 size_t count)
Erich Chen1c57e862006-07-12 08:59:32 -0700114{
Tony Jonesee959b02008-02-22 00:13:36 +0100115 struct device *dev = container_of(kobj,struct device,kobj);
116 struct Scsi_Host *host = class_to_shost(dev);
Erich Chen1c57e862006-07-12 08:59:32 -0700117 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) {
Nick Cheng1a4f5502007-09-13 17:26:40 +0800131 arcmsr_post_ioctldata2iop(acb);
Erich Chen1c57e862006-07-12 08:59:32 -0700132 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;
Nick Cheng1a4f5502007-09-13 17:26:40 +0800149 arcmsr_post_ioctldata2iop(acb);
Erich Chen1c57e862006-07-12 08:59:32 -0700150 }
151 return count;
152 } else {
153 return 0; /*need retry*/
154 }
155 }
156}
157
Chris Wright2c3c8be2010-05-12 18:28:57 -0700158static ssize_t arcmsr_sysfs_iop_message_clear(struct file *filp,
159 struct kobject *kobj,
James Bottomley685b9e02007-09-15 11:41:53 -0500160 struct bin_attribute *bin,
161 char *buf, loff_t off,
162 size_t count)
Erich Chen1c57e862006-07-12 08:59:32 -0700163{
Tony Jonesee959b02008-02-22 00:13:36 +0100164 struct device *dev = container_of(kobj,struct device,kobj);
165 struct Scsi_Host *host = class_to_shost(dev);
Erich Chen1c57e862006-07-12 08:59:32 -0700166 struct AdapterControlBlock *acb = (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -0700167 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;
Nick Cheng1a4f5502007-09-13 17:26:40 +0800174 arcmsr_iop_message_read(acb);
Erich Chen1c57e862006-07-12 08:59:32 -0700175 }
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 ,
Erich Chen1c57e862006-07-12 08:59:32 -0700195 },
196 .size = 1032,
197 .read = arcmsr_sysfs_iop_message_read,
198};
199
200static struct bin_attribute arcmsr_sysfs_message_write_attr = {
201 .attr = {
202 .name = "mu_write",
203 .mode = S_IWUSR,
Erich Chen1c57e862006-07-12 08:59:32 -0700204 },
205 .size = 1032,
206 .write = arcmsr_sysfs_iop_message_write,
207};
208
209static struct bin_attribute arcmsr_sysfs_message_clear_attr = {
210 .attr = {
211 .name = "mu_clear",
212 .mode = S_IWUSR,
Erich Chen1c57e862006-07-12 08:59:32 -0700213 },
214 .size = 1,
215 .write = arcmsr_sysfs_iop_message_clear,
216};
217
218int arcmsr_alloc_sysfs_attr(struct AdapterControlBlock *acb)
219{
220 struct Scsi_Host *host = acb->host;
221 int error;
222
Tony Jonesee959b02008-02-22 00:13:36 +0100223 error = sysfs_create_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_read_attr);
Erich Chen1c57e862006-07-12 08:59:32 -0700224 if (error) {
225 printk(KERN_ERR "arcmsr: alloc sysfs mu_read failed\n");
226 goto error_bin_file_message_read;
227 }
Tony Jonesee959b02008-02-22 00:13:36 +0100228 error = sysfs_create_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_write_attr);
Erich Chen1c57e862006-07-12 08:59:32 -0700229 if (error) {
230 printk(KERN_ERR "arcmsr: alloc sysfs mu_write failed\n");
231 goto error_bin_file_message_write;
232 }
Tony Jonesee959b02008-02-22 00:13:36 +0100233 error = sysfs_create_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_clear_attr);
Erich Chen1c57e862006-07-12 08:59:32 -0700234 if (error) {
235 printk(KERN_ERR "arcmsr: alloc sysfs mu_clear failed\n");
236 goto error_bin_file_message_clear;
237 }
238 return 0;
239error_bin_file_message_clear:
Tony Jonesee959b02008-02-22 00:13:36 +0100240 sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_write_attr);
Erich Chen1c57e862006-07-12 08:59:32 -0700241error_bin_file_message_write:
Tony Jonesee959b02008-02-22 00:13:36 +0100242 sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_read_attr);
Erich Chen1c57e862006-07-12 08:59:32 -0700243error_bin_file_message_read:
244 return error;
245}
246
Tony Jonesee959b02008-02-22 00:13:36 +0100247void arcmsr_free_sysfs_attr(struct AdapterControlBlock *acb)
248{
Erich Chen1c57e862006-07-12 08:59:32 -0700249 struct Scsi_Host *host = acb->host;
Erich Chen1c57e862006-07-12 08:59:32 -0700250
Tony Jonesee959b02008-02-22 00:13:36 +0100251 sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_clear_attr);
252 sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_write_attr);
253 sysfs_remove_bin_file(&host->shost_dev.kobj, &arcmsr_sysfs_message_read_attr);
Erich Chen1c57e862006-07-12 08:59:32 -0700254}
255
256
257static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100258arcmsr_attr_host_driver_version(struct device *dev,
259 struct device_attribute *attr, char *buf)
260{
Erich Chen1c57e862006-07-12 08:59:32 -0700261 return snprintf(buf, PAGE_SIZE,
James Bottomleyd67a70a2006-07-28 17:36:46 -0500262 "%s\n",
Erich Chen1c57e862006-07-12 08:59:32 -0700263 ARCMSR_DRIVER_VERSION);
264}
265
266static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100267arcmsr_attr_host_driver_posted_cmd(struct device *dev,
268 struct device_attribute *attr, char *buf)
269{
270 struct Scsi_Host *host = class_to_shost(dev);
271 struct AdapterControlBlock *acb =
272 (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -0700273 return snprintf(buf, PAGE_SIZE,
James Bottomleyd67a70a2006-07-28 17:36:46 -0500274 "%4d\n",
Erich Chen1c57e862006-07-12 08:59:32 -0700275 atomic_read(&acb->ccboutstandingcount));
276}
277
278static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100279arcmsr_attr_host_driver_reset(struct device *dev,
280 struct device_attribute *attr, char *buf)
281{
282 struct Scsi_Host *host = class_to_shost(dev);
283 struct AdapterControlBlock *acb =
284 (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -0700285 return snprintf(buf, PAGE_SIZE,
James Bottomleyd67a70a2006-07-28 17:36:46 -0500286 "%4d\n",
Erich Chen1c57e862006-07-12 08:59:32 -0700287 acb->num_resets);
288}
289
290static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100291arcmsr_attr_host_driver_abort(struct device *dev,
292 struct device_attribute *attr, char *buf)
293{
294 struct Scsi_Host *host = class_to_shost(dev);
295 struct AdapterControlBlock *acb =
296 (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -0700297 return snprintf(buf, PAGE_SIZE,
James Bottomleyd67a70a2006-07-28 17:36:46 -0500298 "%4d\n",
Erich Chen1c57e862006-07-12 08:59:32 -0700299 acb->num_aborts);
300}
301
302static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100303arcmsr_attr_host_fw_model(struct device *dev, struct device_attribute *attr,
304 char *buf)
305{
306 struct Scsi_Host *host = class_to_shost(dev);
307 struct AdapterControlBlock *acb =
308 (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -0700309 return snprintf(buf, PAGE_SIZE,
James Bottomleyd67a70a2006-07-28 17:36:46 -0500310 "%s\n",
Erich Chen1c57e862006-07-12 08:59:32 -0700311 acb->firm_model);
312}
313
314static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100315arcmsr_attr_host_fw_version(struct device *dev,
316 struct device_attribute *attr, char *buf)
317{
318 struct Scsi_Host *host = class_to_shost(dev);
319 struct AdapterControlBlock *acb =
320 (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -0700321
322 return snprintf(buf, PAGE_SIZE,
James Bottomleyd67a70a2006-07-28 17:36:46 -0500323 "%s\n",
Erich Chen1c57e862006-07-12 08:59:32 -0700324 acb->firm_version);
325}
326
327static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100328arcmsr_attr_host_fw_request_len(struct device *dev,
329 struct device_attribute *attr, char *buf)
330{
331 struct Scsi_Host *host = class_to_shost(dev);
332 struct AdapterControlBlock *acb =
333 (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -0700334
335 return snprintf(buf, PAGE_SIZE,
James Bottomleyd67a70a2006-07-28 17:36:46 -0500336 "%4d\n",
Erich Chen1c57e862006-07-12 08:59:32 -0700337 acb->firm_request_len);
338}
339
340static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100341arcmsr_attr_host_fw_numbers_queue(struct device *dev,
342 struct device_attribute *attr, char *buf)
343{
344 struct Scsi_Host *host = class_to_shost(dev);
345 struct AdapterControlBlock *acb =
346 (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -0700347
348 return snprintf(buf, PAGE_SIZE,
James Bottomleyd67a70a2006-07-28 17:36:46 -0500349 "%4d\n",
Erich Chen1c57e862006-07-12 08:59:32 -0700350 acb->firm_numbers_queue);
351}
352
353static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100354arcmsr_attr_host_fw_sdram_size(struct device *dev,
355 struct device_attribute *attr, char *buf)
356{
357 struct Scsi_Host *host = class_to_shost(dev);
358 struct AdapterControlBlock *acb =
359 (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -0700360
361 return snprintf(buf, PAGE_SIZE,
James Bottomleyd67a70a2006-07-28 17:36:46 -0500362 "%4d\n",
Erich Chen1c57e862006-07-12 08:59:32 -0700363 acb->firm_sdram_size);
364}
365
366static ssize_t
Tony Jonesee959b02008-02-22 00:13:36 +0100367arcmsr_attr_host_fw_hd_channels(struct device *dev,
368 struct device_attribute *attr, char *buf)
369{
370 struct Scsi_Host *host = class_to_shost(dev);
371 struct AdapterControlBlock *acb =
372 (struct AdapterControlBlock *) host->hostdata;
Erich Chen1c57e862006-07-12 08:59:32 -0700373
374 return snprintf(buf, PAGE_SIZE,
James Bottomleyd67a70a2006-07-28 17:36:46 -0500375 "%4d\n",
Erich Chen1c57e862006-07-12 08:59:32 -0700376 acb->firm_hd_channels);
377}
378
Tony Jonesee959b02008-02-22 00:13:36 +0100379static DEVICE_ATTR(host_driver_version, S_IRUGO, arcmsr_attr_host_driver_version, NULL);
380static DEVICE_ATTR(host_driver_posted_cmd, S_IRUGO, arcmsr_attr_host_driver_posted_cmd, NULL);
381static DEVICE_ATTR(host_driver_reset, S_IRUGO, arcmsr_attr_host_driver_reset, NULL);
382static DEVICE_ATTR(host_driver_abort, S_IRUGO, arcmsr_attr_host_driver_abort, NULL);
383static DEVICE_ATTR(host_fw_model, S_IRUGO, arcmsr_attr_host_fw_model, NULL);
384static DEVICE_ATTR(host_fw_version, S_IRUGO, arcmsr_attr_host_fw_version, NULL);
385static DEVICE_ATTR(host_fw_request_len, S_IRUGO, arcmsr_attr_host_fw_request_len, NULL);
386static DEVICE_ATTR(host_fw_numbers_queue, S_IRUGO, arcmsr_attr_host_fw_numbers_queue, NULL);
387static DEVICE_ATTR(host_fw_sdram_size, S_IRUGO, arcmsr_attr_host_fw_sdram_size, NULL);
388static DEVICE_ATTR(host_fw_hd_channels, S_IRUGO, arcmsr_attr_host_fw_hd_channels, NULL);
Erich Chen1c57e862006-07-12 08:59:32 -0700389
Tony Jonesee959b02008-02-22 00:13:36 +0100390struct device_attribute *arcmsr_host_attrs[] = {
391 &dev_attr_host_driver_version,
392 &dev_attr_host_driver_posted_cmd,
393 &dev_attr_host_driver_reset,
394 &dev_attr_host_driver_abort,
395 &dev_attr_host_fw_model,
396 &dev_attr_host_fw_version,
397 &dev_attr_host_fw_request_len,
398 &dev_attr_host_fw_numbers_queue,
399 &dev_attr_host_fw_sdram_size,
400 &dev_attr_host_fw_hd_channels,
Erich Chen1c57e862006-07-12 08:59:32 -0700401 NULL,
402};