card_debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. /**
  2. * IBM Accelerator Family 'GenWQE'
  3. *
  4. * (C) Copyright IBM Corp. 2013
  5. *
  6. * Author: Frank Haverkamp <haver@linux.vnet.ibm.com>
  7. * Author: Joerg-Stephan Vogt <jsvogt@de.ibm.com>
  8. * Author: Michael Jung <mijung@gmx.net>
  9. * Author: Michael Ruettger <michael@ibmra.de>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License (version 2 only)
  13. * as published by the Free Software Foundation.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. */
  20. /*
  21. * Debugfs interfaces for the GenWQE card. Help to debug potential
  22. * problems. Dump internal chip state for debugging and failure
  23. * determination.
  24. */
  25. #include <linux/module.h>
  26. #include <linux/kernel.h>
  27. #include <linux/debugfs.h>
  28. #include <linux/seq_file.h>
  29. #include <linux/uaccess.h>
  30. #include "card_base.h"
  31. #include "card_ddcb.h"
  32. #define GENWQE_DEBUGFS_RO(_name, _showfn) \
  33. static int genwqe_debugfs_##_name##_open(struct inode *inode, \
  34. struct file *file) \
  35. { \
  36. return single_open(file, _showfn, inode->i_private); \
  37. } \
  38. static const struct file_operations genwqe_##_name##_fops = { \
  39. .open = genwqe_debugfs_##_name##_open, \
  40. .read = seq_read, \
  41. .llseek = seq_lseek, \
  42. .release = single_release, \
  43. }
  44. static void dbg_uidn_show(struct seq_file *s, struct genwqe_reg *regs,
  45. int entries)
  46. {
  47. unsigned int i;
  48. u32 v_hi, v_lo;
  49. for (i = 0; i < entries; i++) {
  50. v_hi = (regs[i].val >> 32) & 0xffffffff;
  51. v_lo = (regs[i].val) & 0xffffffff;
  52. seq_printf(s, " 0x%08x 0x%08x 0x%08x 0x%08x EXT_ERR_REC\n",
  53. regs[i].addr, regs[i].idx, v_hi, v_lo);
  54. }
  55. }
  56. static int curr_dbg_uidn_show(struct seq_file *s, void *unused, int uid)
  57. {
  58. struct genwqe_dev *cd = s->private;
  59. int entries;
  60. struct genwqe_reg *regs;
  61. entries = genwqe_ffdc_buff_size(cd, uid);
  62. if (entries < 0)
  63. return -EINVAL;
  64. if (entries == 0)
  65. return 0;
  66. regs = kcalloc(entries, sizeof(*regs), GFP_KERNEL);
  67. if (regs == NULL)
  68. return -ENOMEM;
  69. genwqe_stop_traps(cd); /* halt the traps while dumping data */
  70. genwqe_ffdc_buff_read(cd, uid, regs, entries);
  71. genwqe_start_traps(cd);
  72. dbg_uidn_show(s, regs, entries);
  73. kfree(regs);
  74. return 0;
  75. }
  76. static int genwqe_curr_dbg_uid0_show(struct seq_file *s, void *unused)
  77. {
  78. return curr_dbg_uidn_show(s, unused, 0);
  79. }
  80. GENWQE_DEBUGFS_RO(curr_dbg_uid0, genwqe_curr_dbg_uid0_show);
  81. static int genwqe_curr_dbg_uid1_show(struct seq_file *s, void *unused)
  82. {
  83. return curr_dbg_uidn_show(s, unused, 1);
  84. }
  85. GENWQE_DEBUGFS_RO(curr_dbg_uid1, genwqe_curr_dbg_uid1_show);
  86. static int genwqe_curr_dbg_uid2_show(struct seq_file *s, void *unused)
  87. {
  88. return curr_dbg_uidn_show(s, unused, 2);
  89. }
  90. GENWQE_DEBUGFS_RO(curr_dbg_uid2, genwqe_curr_dbg_uid2_show);
  91. static int prev_dbg_uidn_show(struct seq_file *s, void *unused, int uid)
  92. {
  93. struct genwqe_dev *cd = s->private;
  94. dbg_uidn_show(s, cd->ffdc[uid].regs, cd->ffdc[uid].entries);
  95. return 0;
  96. }
  97. static int genwqe_prev_dbg_uid0_show(struct seq_file *s, void *unused)
  98. {
  99. return prev_dbg_uidn_show(s, unused, 0);
  100. }
  101. GENWQE_DEBUGFS_RO(prev_dbg_uid0, genwqe_prev_dbg_uid0_show);
  102. static int genwqe_prev_dbg_uid1_show(struct seq_file *s, void *unused)
  103. {
  104. return prev_dbg_uidn_show(s, unused, 1);
  105. }
  106. GENWQE_DEBUGFS_RO(prev_dbg_uid1, genwqe_prev_dbg_uid1_show);
  107. static int genwqe_prev_dbg_uid2_show(struct seq_file *s, void *unused)
  108. {
  109. return prev_dbg_uidn_show(s, unused, 2);
  110. }
  111. GENWQE_DEBUGFS_RO(prev_dbg_uid2, genwqe_prev_dbg_uid2_show);
  112. static int genwqe_curr_regs_show(struct seq_file *s, void *unused)
  113. {
  114. struct genwqe_dev *cd = s->private;
  115. unsigned int i;
  116. struct genwqe_reg *regs;
  117. regs = kcalloc(GENWQE_FFDC_REGS, sizeof(*regs), GFP_KERNEL);
  118. if (regs == NULL)
  119. return -ENOMEM;
  120. genwqe_stop_traps(cd);
  121. genwqe_read_ffdc_regs(cd, regs, GENWQE_FFDC_REGS, 1);
  122. genwqe_start_traps(cd);
  123. for (i = 0; i < GENWQE_FFDC_REGS; i++) {
  124. if (regs[i].addr == 0xffffffff)
  125. break; /* invalid entries */
  126. if (regs[i].val == 0x0ull)
  127. continue; /* do not print 0x0 FIRs */
  128. seq_printf(s, " 0x%08x 0x%016llx\n",
  129. regs[i].addr, regs[i].val);
  130. }
  131. return 0;
  132. }
  133. GENWQE_DEBUGFS_RO(curr_regs, genwqe_curr_regs_show);
  134. static int genwqe_prev_regs_show(struct seq_file *s, void *unused)
  135. {
  136. struct genwqe_dev *cd = s->private;
  137. unsigned int i;
  138. struct genwqe_reg *regs = cd->ffdc[GENWQE_DBG_REGS].regs;
  139. if (regs == NULL)
  140. return -EINVAL;
  141. for (i = 0; i < GENWQE_FFDC_REGS; i++) {
  142. if (regs[i].addr == 0xffffffff)
  143. break; /* invalid entries */
  144. if (regs[i].val == 0x0ull)
  145. continue; /* do not print 0x0 FIRs */
  146. seq_printf(s, " 0x%08x 0x%016llx\n",
  147. regs[i].addr, regs[i].val);
  148. }
  149. return 0;
  150. }
  151. GENWQE_DEBUGFS_RO(prev_regs, genwqe_prev_regs_show);
  152. static int genwqe_jtimer_show(struct seq_file *s, void *unused)
  153. {
  154. struct genwqe_dev *cd = s->private;
  155. unsigned int vf_num;
  156. u64 jtimer;
  157. jtimer = genwqe_read_vreg(cd, IO_SLC_VF_APPJOB_TIMEOUT, 0);
  158. seq_printf(s, " PF 0x%016llx %d msec\n", jtimer,
  159. GENWQE_PF_JOBTIMEOUT_MSEC);
  160. for (vf_num = 0; vf_num < cd->num_vfs; vf_num++) {
  161. jtimer = genwqe_read_vreg(cd, IO_SLC_VF_APPJOB_TIMEOUT,
  162. vf_num + 1);
  163. seq_printf(s, " VF%-2d 0x%016llx %d msec\n", vf_num, jtimer,
  164. cd->vf_jobtimeout_msec[vf_num]);
  165. }
  166. return 0;
  167. }
  168. GENWQE_DEBUGFS_RO(jtimer, genwqe_jtimer_show);
  169. static int genwqe_queue_working_time_show(struct seq_file *s, void *unused)
  170. {
  171. struct genwqe_dev *cd = s->private;
  172. unsigned int vf_num;
  173. u64 t;
  174. t = genwqe_read_vreg(cd, IO_SLC_VF_QUEUE_WTIME, 0);
  175. seq_printf(s, " PF 0x%016llx\n", t);
  176. for (vf_num = 0; vf_num < cd->num_vfs; vf_num++) {
  177. t = genwqe_read_vreg(cd, IO_SLC_VF_QUEUE_WTIME, vf_num + 1);
  178. seq_printf(s, " VF%-2d 0x%016llx\n", vf_num, t);
  179. }
  180. return 0;
  181. }
  182. GENWQE_DEBUGFS_RO(queue_working_time, genwqe_queue_working_time_show);
  183. static int genwqe_ddcb_info_show(struct seq_file *s, void *unused)
  184. {
  185. struct genwqe_dev *cd = s->private;
  186. unsigned int i;
  187. struct ddcb_queue *queue;
  188. struct ddcb *pddcb;
  189. queue = &cd->queue;
  190. seq_puts(s, "DDCB QUEUE:\n");
  191. seq_printf(s, " ddcb_max: %d\n"
  192. " ddcb_daddr: %016llx - %016llx\n"
  193. " ddcb_vaddr: %016llx\n"
  194. " ddcbs_in_flight: %u\n"
  195. " ddcbs_max_in_flight: %u\n"
  196. " ddcbs_completed: %u\n"
  197. " return_on_busy: %u\n"
  198. " wait_on_busy: %u\n"
  199. " irqs_processed: %u\n",
  200. queue->ddcb_max, (long long)queue->ddcb_daddr,
  201. (long long)queue->ddcb_daddr +
  202. (queue->ddcb_max * DDCB_LENGTH),
  203. (long long)queue->ddcb_vaddr, queue->ddcbs_in_flight,
  204. queue->ddcbs_max_in_flight, queue->ddcbs_completed,
  205. queue->return_on_busy, queue->wait_on_busy,
  206. cd->irqs_processed);
  207. /* Hardware State */
  208. seq_printf(s, " 0x%08x 0x%016llx IO_QUEUE_CONFIG\n"
  209. " 0x%08x 0x%016llx IO_QUEUE_STATUS\n"
  210. " 0x%08x 0x%016llx IO_QUEUE_SEGMENT\n"
  211. " 0x%08x 0x%016llx IO_QUEUE_INITSQN\n"
  212. " 0x%08x 0x%016llx IO_QUEUE_WRAP\n"
  213. " 0x%08x 0x%016llx IO_QUEUE_OFFSET\n"
  214. " 0x%08x 0x%016llx IO_QUEUE_WTIME\n"
  215. " 0x%08x 0x%016llx IO_QUEUE_ERRCNTS\n"
  216. " 0x%08x 0x%016llx IO_QUEUE_LRW\n",
  217. queue->IO_QUEUE_CONFIG,
  218. __genwqe_readq(cd, queue->IO_QUEUE_CONFIG),
  219. queue->IO_QUEUE_STATUS,
  220. __genwqe_readq(cd, queue->IO_QUEUE_STATUS),
  221. queue->IO_QUEUE_SEGMENT,
  222. __genwqe_readq(cd, queue->IO_QUEUE_SEGMENT),
  223. queue->IO_QUEUE_INITSQN,
  224. __genwqe_readq(cd, queue->IO_QUEUE_INITSQN),
  225. queue->IO_QUEUE_WRAP,
  226. __genwqe_readq(cd, queue->IO_QUEUE_WRAP),
  227. queue->IO_QUEUE_OFFSET,
  228. __genwqe_readq(cd, queue->IO_QUEUE_OFFSET),
  229. queue->IO_QUEUE_WTIME,
  230. __genwqe_readq(cd, queue->IO_QUEUE_WTIME),
  231. queue->IO_QUEUE_ERRCNTS,
  232. __genwqe_readq(cd, queue->IO_QUEUE_ERRCNTS),
  233. queue->IO_QUEUE_LRW,
  234. __genwqe_readq(cd, queue->IO_QUEUE_LRW));
  235. seq_printf(s, "DDCB list (ddcb_act=%d/ddcb_next=%d):\n",
  236. queue->ddcb_act, queue->ddcb_next);
  237. pddcb = queue->ddcb_vaddr;
  238. for (i = 0; i < queue->ddcb_max; i++) {
  239. seq_printf(s, " %-3d: RETC=%03x SEQ=%04x HSI/SHI=%02x/%02x ",
  240. i, be16_to_cpu(pddcb->retc_16),
  241. be16_to_cpu(pddcb->seqnum_16),
  242. pddcb->hsi, pddcb->shi);
  243. seq_printf(s, "PRIV=%06llx CMD=%02x\n",
  244. be64_to_cpu(pddcb->priv_64), pddcb->cmd);
  245. pddcb++;
  246. }
  247. return 0;
  248. }
  249. GENWQE_DEBUGFS_RO(ddcb_info, genwqe_ddcb_info_show);
  250. static int genwqe_info_show(struct seq_file *s, void *unused)
  251. {
  252. struct genwqe_dev *cd = s->private;
  253. u64 app_id, slu_id, bitstream = -1;
  254. struct pci_dev *pci_dev = cd->pci_dev;
  255. slu_id = __genwqe_readq(cd, IO_SLU_UNITCFG);
  256. app_id = __genwqe_readq(cd, IO_APP_UNITCFG);
  257. if (genwqe_is_privileged(cd))
  258. bitstream = __genwqe_readq(cd, IO_SLU_BITSTREAM);
  259. seq_printf(s, "%s driver version: %s\n"
  260. " Device Name/Type: %s %s CardIdx: %d\n"
  261. " SLU/APP Config : 0x%016llx/0x%016llx\n"
  262. " Build Date : %u/%x/%u\n"
  263. " Base Clock : %u MHz\n"
  264. " Arch/SVN Release: %u/%llx\n"
  265. " Bitstream : %llx\n",
  266. GENWQE_DEVNAME, DRV_VERSION, dev_name(&pci_dev->dev),
  267. genwqe_is_privileged(cd) ?
  268. "Physical" : "Virtual or no SR-IOV",
  269. cd->card_idx, slu_id, app_id,
  270. (u16)((slu_id >> 12) & 0x0fLLU), /* month */
  271. (u16)((slu_id >> 4) & 0xffLLU), /* day */
  272. (u16)((slu_id >> 16) & 0x0fLLU) + 2010, /* year */
  273. genwqe_base_clock_frequency(cd),
  274. (u16)((slu_id >> 32) & 0xffLLU), slu_id >> 40,
  275. bitstream);
  276. return 0;
  277. }
  278. GENWQE_DEBUGFS_RO(info, genwqe_info_show);
  279. int genwqe_init_debugfs(struct genwqe_dev *cd)
  280. {
  281. struct dentry *root;
  282. struct dentry *file;
  283. int ret;
  284. char card_name[64];
  285. char name[64];
  286. unsigned int i;
  287. sprintf(card_name, "%s%d_card", GENWQE_DEVNAME, cd->card_idx);
  288. root = debugfs_create_dir(card_name, cd->debugfs_genwqe);
  289. if (!root) {
  290. ret = -ENOMEM;
  291. goto err0;
  292. }
  293. /* non privileged interfaces are done here */
  294. file = debugfs_create_file("ddcb_info", S_IRUGO, root, cd,
  295. &genwqe_ddcb_info_fops);
  296. if (!file) {
  297. ret = -ENOMEM;
  298. goto err1;
  299. }
  300. file = debugfs_create_file("info", S_IRUGO, root, cd,
  301. &genwqe_info_fops);
  302. if (!file) {
  303. ret = -ENOMEM;
  304. goto err1;
  305. }
  306. file = debugfs_create_x64("err_inject", 0666, root, &cd->err_inject);
  307. if (!file) {
  308. ret = -ENOMEM;
  309. goto err1;
  310. }
  311. file = debugfs_create_u32("ddcb_software_timeout", 0666, root,
  312. &cd->ddcb_software_timeout);
  313. if (!file) {
  314. ret = -ENOMEM;
  315. goto err1;
  316. }
  317. file = debugfs_create_u32("kill_timeout", 0666, root,
  318. &cd->kill_timeout);
  319. if (!file) {
  320. ret = -ENOMEM;
  321. goto err1;
  322. }
  323. /* privileged interfaces follow here */
  324. if (!genwqe_is_privileged(cd)) {
  325. cd->debugfs_root = root;
  326. return 0;
  327. }
  328. file = debugfs_create_file("curr_regs", S_IRUGO, root, cd,
  329. &genwqe_curr_regs_fops);
  330. if (!file) {
  331. ret = -ENOMEM;
  332. goto err1;
  333. }
  334. file = debugfs_create_file("curr_dbg_uid0", S_IRUGO, root, cd,
  335. &genwqe_curr_dbg_uid0_fops);
  336. if (!file) {
  337. ret = -ENOMEM;
  338. goto err1;
  339. }
  340. file = debugfs_create_file("curr_dbg_uid1", S_IRUGO, root, cd,
  341. &genwqe_curr_dbg_uid1_fops);
  342. if (!file) {
  343. ret = -ENOMEM;
  344. goto err1;
  345. }
  346. file = debugfs_create_file("curr_dbg_uid2", S_IRUGO, root, cd,
  347. &genwqe_curr_dbg_uid2_fops);
  348. if (!file) {
  349. ret = -ENOMEM;
  350. goto err1;
  351. }
  352. file = debugfs_create_file("prev_regs", S_IRUGO, root, cd,
  353. &genwqe_prev_regs_fops);
  354. if (!file) {
  355. ret = -ENOMEM;
  356. goto err1;
  357. }
  358. file = debugfs_create_file("prev_dbg_uid0", S_IRUGO, root, cd,
  359. &genwqe_prev_dbg_uid0_fops);
  360. if (!file) {
  361. ret = -ENOMEM;
  362. goto err1;
  363. }
  364. file = debugfs_create_file("prev_dbg_uid1", S_IRUGO, root, cd,
  365. &genwqe_prev_dbg_uid1_fops);
  366. if (!file) {
  367. ret = -ENOMEM;
  368. goto err1;
  369. }
  370. file = debugfs_create_file("prev_dbg_uid2", S_IRUGO, root, cd,
  371. &genwqe_prev_dbg_uid2_fops);
  372. if (!file) {
  373. ret = -ENOMEM;
  374. goto err1;
  375. }
  376. for (i = 0; i < GENWQE_MAX_VFS; i++) {
  377. sprintf(name, "vf%u_jobtimeout_msec", i);
  378. file = debugfs_create_u32(name, 0666, root,
  379. &cd->vf_jobtimeout_msec[i]);
  380. if (!file) {
  381. ret = -ENOMEM;
  382. goto err1;
  383. }
  384. }
  385. file = debugfs_create_file("jobtimer", S_IRUGO, root, cd,
  386. &genwqe_jtimer_fops);
  387. if (!file) {
  388. ret = -ENOMEM;
  389. goto err1;
  390. }
  391. file = debugfs_create_file("queue_working_time", S_IRUGO, root, cd,
  392. &genwqe_queue_working_time_fops);
  393. if (!file) {
  394. ret = -ENOMEM;
  395. goto err1;
  396. }
  397. file = debugfs_create_u32("skip_recovery", 0666, root,
  398. &cd->skip_recovery);
  399. if (!file) {
  400. ret = -ENOMEM;
  401. goto err1;
  402. }
  403. file = debugfs_create_u32("use_platform_recovery", 0666, root,
  404. &cd->use_platform_recovery);
  405. if (!file) {
  406. ret = -ENOMEM;
  407. goto err1;
  408. }
  409. cd->debugfs_root = root;
  410. return 0;
  411. err1:
  412. debugfs_remove_recursive(root);
  413. err0:
  414. return ret;
  415. }
  416. void genqwe_exit_debugfs(struct genwqe_dev *cd)
  417. {
  418. debugfs_remove_recursive(cd->debugfs_root);
  419. }