arcmsr_attr.c 13 KB

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