adf_transport_debug.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294
  1. /*
  2. This file is provided under a dual BSD/GPLv2 license. When using or
  3. redistributing this file, you may do so under either license.
  4. GPL LICENSE SUMMARY
  5. Copyright(c) 2014 Intel Corporation.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of version 2 of the GNU General Public License as
  8. published by the Free Software Foundation.
  9. This program is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. Contact Information:
  14. qat-linux@intel.com
  15. BSD LICENSE
  16. Copyright(c) 2014 Intel Corporation.
  17. Redistribution and use in source and binary forms, with or without
  18. modification, are permitted provided that the following conditions
  19. are met:
  20. * Redistributions of source code must retain the above copyright
  21. notice, this list of conditions and the following disclaimer.
  22. * Redistributions in binary form must reproduce the above copyright
  23. notice, this list of conditions and the following disclaimer in
  24. the documentation and/or other materials provided with the
  25. distribution.
  26. * Neither the name of Intel Corporation nor the names of its
  27. contributors may be used to endorse or promote products derived
  28. from this software without specific prior written permission.
  29. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  30. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  31. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  32. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  33. OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  34. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  36. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  37. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  38. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  39. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. */
  41. #include <linux/mutex.h>
  42. #include <linux/slab.h>
  43. #include <linux/seq_file.h>
  44. #include "adf_accel_devices.h"
  45. #include "adf_transport_internal.h"
  46. #include "adf_transport_access_macros.h"
  47. static DEFINE_MUTEX(ring_read_lock);
  48. static DEFINE_MUTEX(bank_read_lock);
  49. static void *adf_ring_start(struct seq_file *sfile, loff_t *pos)
  50. {
  51. struct adf_etr_ring_data *ring = sfile->private;
  52. mutex_lock(&ring_read_lock);
  53. if (*pos == 0)
  54. return SEQ_START_TOKEN;
  55. if (*pos >= (ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) /
  56. ADF_MSG_SIZE_TO_BYTES(ring->msg_size)))
  57. return NULL;
  58. return ring->base_addr +
  59. (ADF_MSG_SIZE_TO_BYTES(ring->msg_size) * (*pos)++);
  60. }
  61. static void *adf_ring_next(struct seq_file *sfile, void *v, loff_t *pos)
  62. {
  63. struct adf_etr_ring_data *ring = sfile->private;
  64. if (*pos >= (ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size) /
  65. ADF_MSG_SIZE_TO_BYTES(ring->msg_size)))
  66. return NULL;
  67. return ring->base_addr +
  68. (ADF_MSG_SIZE_TO_BYTES(ring->msg_size) * (*pos)++);
  69. }
  70. static int adf_ring_show(struct seq_file *sfile, void *v)
  71. {
  72. struct adf_etr_ring_data *ring = sfile->private;
  73. struct adf_etr_bank_data *bank = ring->bank;
  74. void __iomem *csr = ring->bank->csr_addr;
  75. if (v == SEQ_START_TOKEN) {
  76. int head, tail, empty;
  77. head = READ_CSR_RING_HEAD(csr, bank->bank_number,
  78. ring->ring_number);
  79. tail = READ_CSR_RING_TAIL(csr, bank->bank_number,
  80. ring->ring_number);
  81. empty = READ_CSR_E_STAT(csr, bank->bank_number);
  82. seq_puts(sfile, "------- Ring configuration -------\n");
  83. seq_printf(sfile, "ring name: %s\n",
  84. ring->ring_debug->ring_name);
  85. seq_printf(sfile, "ring num %d, bank num %d\n",
  86. ring->ring_number, ring->bank->bank_number);
  87. seq_printf(sfile, "head %x, tail %x, empty: %d\n",
  88. head, tail, (empty & 1 << ring->ring_number)
  89. >> ring->ring_number);
  90. seq_printf(sfile, "ring size %d, msg size %d\n",
  91. ADF_SIZE_TO_RING_SIZE_IN_BYTES(ring->ring_size),
  92. ADF_MSG_SIZE_TO_BYTES(ring->msg_size));
  93. seq_puts(sfile, "----------- Ring data ------------\n");
  94. return 0;
  95. }
  96. seq_hex_dump(sfile, "", DUMP_PREFIX_ADDRESS, 32, 4,
  97. v, ADF_MSG_SIZE_TO_BYTES(ring->msg_size), false);
  98. return 0;
  99. }
  100. static void adf_ring_stop(struct seq_file *sfile, void *v)
  101. {
  102. mutex_unlock(&ring_read_lock);
  103. }
  104. static const struct seq_operations adf_ring_sops = {
  105. .start = adf_ring_start,
  106. .next = adf_ring_next,
  107. .stop = adf_ring_stop,
  108. .show = adf_ring_show
  109. };
  110. static int adf_ring_open(struct inode *inode, struct file *file)
  111. {
  112. int ret = seq_open(file, &adf_ring_sops);
  113. if (!ret) {
  114. struct seq_file *seq_f = file->private_data;
  115. seq_f->private = inode->i_private;
  116. }
  117. return ret;
  118. }
  119. static const struct file_operations adf_ring_debug_fops = {
  120. .open = adf_ring_open,
  121. .read = seq_read,
  122. .llseek = seq_lseek,
  123. .release = seq_release
  124. };
  125. int adf_ring_debugfs_add(struct adf_etr_ring_data *ring, const char *name)
  126. {
  127. struct adf_etr_ring_debug_entry *ring_debug;
  128. char entry_name[8];
  129. ring_debug = kzalloc(sizeof(*ring_debug), GFP_KERNEL);
  130. if (!ring_debug)
  131. return -ENOMEM;
  132. strlcpy(ring_debug->ring_name, name, sizeof(ring_debug->ring_name));
  133. snprintf(entry_name, sizeof(entry_name), "ring_%02d",
  134. ring->ring_number);
  135. ring_debug->debug = debugfs_create_file(entry_name, S_IRUSR,
  136. ring->bank->bank_debug_dir,
  137. ring, &adf_ring_debug_fops);
  138. if (!ring_debug->debug) {
  139. pr_err("QAT: Failed to create ring debug entry.\n");
  140. kfree(ring_debug);
  141. return -EFAULT;
  142. }
  143. ring->ring_debug = ring_debug;
  144. return 0;
  145. }
  146. void adf_ring_debugfs_rm(struct adf_etr_ring_data *ring)
  147. {
  148. if (ring->ring_debug) {
  149. debugfs_remove(ring->ring_debug->debug);
  150. kfree(ring->ring_debug);
  151. ring->ring_debug = NULL;
  152. }
  153. }
  154. static void *adf_bank_start(struct seq_file *sfile, loff_t *pos)
  155. {
  156. mutex_lock(&bank_read_lock);
  157. if (*pos == 0)
  158. return SEQ_START_TOKEN;
  159. if (*pos >= ADF_ETR_MAX_RINGS_PER_BANK)
  160. return NULL;
  161. return pos;
  162. }
  163. static void *adf_bank_next(struct seq_file *sfile, void *v, loff_t *pos)
  164. {
  165. if (++(*pos) >= ADF_ETR_MAX_RINGS_PER_BANK)
  166. return NULL;
  167. return pos;
  168. }
  169. static int adf_bank_show(struct seq_file *sfile, void *v)
  170. {
  171. struct adf_etr_bank_data *bank = sfile->private;
  172. if (v == SEQ_START_TOKEN) {
  173. seq_printf(sfile, "------- Bank %d configuration -------\n",
  174. bank->bank_number);
  175. } else {
  176. int ring_id = *((int *)v) - 1;
  177. struct adf_etr_ring_data *ring = &bank->rings[ring_id];
  178. void __iomem *csr = bank->csr_addr;
  179. int head, tail, empty;
  180. if (!(bank->ring_mask & 1 << ring_id))
  181. return 0;
  182. head = READ_CSR_RING_HEAD(csr, bank->bank_number,
  183. ring->ring_number);
  184. tail = READ_CSR_RING_TAIL(csr, bank->bank_number,
  185. ring->ring_number);
  186. empty = READ_CSR_E_STAT(csr, bank->bank_number);
  187. seq_printf(sfile,
  188. "ring num %02d, head %04x, tail %04x, empty: %d\n",
  189. ring->ring_number, head, tail,
  190. (empty & 1 << ring->ring_number) >>
  191. ring->ring_number);
  192. }
  193. return 0;
  194. }
  195. static void adf_bank_stop(struct seq_file *sfile, void *v)
  196. {
  197. mutex_unlock(&bank_read_lock);
  198. }
  199. static const struct seq_operations adf_bank_sops = {
  200. .start = adf_bank_start,
  201. .next = adf_bank_next,
  202. .stop = adf_bank_stop,
  203. .show = adf_bank_show
  204. };
  205. static int adf_bank_open(struct inode *inode, struct file *file)
  206. {
  207. int ret = seq_open(file, &adf_bank_sops);
  208. if (!ret) {
  209. struct seq_file *seq_f = file->private_data;
  210. seq_f->private = inode->i_private;
  211. }
  212. return ret;
  213. }
  214. static const struct file_operations adf_bank_debug_fops = {
  215. .open = adf_bank_open,
  216. .read = seq_read,
  217. .llseek = seq_lseek,
  218. .release = seq_release
  219. };
  220. int adf_bank_debugfs_add(struct adf_etr_bank_data *bank)
  221. {
  222. struct adf_accel_dev *accel_dev = bank->accel_dev;
  223. struct dentry *parent = accel_dev->transport->debug;
  224. char name[8];
  225. snprintf(name, sizeof(name), "bank_%02d", bank->bank_number);
  226. bank->bank_debug_dir = debugfs_create_dir(name, parent);
  227. if (!bank->bank_debug_dir) {
  228. pr_err("QAT: Failed to create bank debug dir.\n");
  229. return -EFAULT;
  230. }
  231. bank->bank_debug_cfg = debugfs_create_file("config", S_IRUSR,
  232. bank->bank_debug_dir, bank,
  233. &adf_bank_debug_fops);
  234. if (!bank->bank_debug_cfg) {
  235. pr_err("QAT: Failed to create bank debug entry.\n");
  236. debugfs_remove(bank->bank_debug_dir);
  237. return -EFAULT;
  238. }
  239. return 0;
  240. }
  241. void adf_bank_debugfs_rm(struct adf_etr_bank_data *bank)
  242. {
  243. debugfs_remove(bank->bank_debug_cfg);
  244. debugfs_remove(bank->bank_debug_dir);
  245. }