arcmsr_attr.c 12 KB

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