arcmsr_attr.c 13 KB

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