card_debugfs.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508
  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. u16 val16, type;
  254. u64 app_id, slu_id, bitstream = -1;
  255. struct pci_dev *pci_dev = cd->pci_dev;
  256. slu_id = __genwqe_readq(cd, IO_SLU_UNITCFG);
  257. app_id = __genwqe_readq(cd, IO_APP_UNITCFG);
  258. if (genwqe_is_privileged(cd))
  259. bitstream = __genwqe_readq(cd, IO_SLU_BITSTREAM);
  260. val16 = (u16)(slu_id & 0x0fLLU);
  261. type = (u16)((slu_id >> 20) & 0xffLLU);
  262. seq_printf(s, "%s driver version: %s\n"
  263. " Device Name/Type: %s %s CardIdx: %d\n"
  264. " SLU/APP Config : 0x%016llx/0x%016llx\n"
  265. " Build Date : %u/%x/%u\n"
  266. " Base Clock : %u MHz\n"
  267. " Arch/SVN Release: %u/%llx\n"
  268. " Bitstream : %llx\n",
  269. GENWQE_DEVNAME, DRV_VERSION, dev_name(&pci_dev->dev),
  270. genwqe_is_privileged(cd) ?
  271. "Physical" : "Virtual or no SR-IOV",
  272. cd->card_idx, slu_id, app_id,
  273. (u16)((slu_id >> 12) & 0x0fLLU), /* month */
  274. (u16)((slu_id >> 4) & 0xffLLU), /* day */
  275. (u16)((slu_id >> 16) & 0x0fLLU) + 2010, /* year */
  276. genwqe_base_clock_frequency(cd),
  277. (u16)((slu_id >> 32) & 0xffLLU), slu_id >> 40,
  278. bitstream);
  279. return 0;
  280. }
  281. GENWQE_DEBUGFS_RO(info, genwqe_info_show);
  282. int genwqe_init_debugfs(struct genwqe_dev *cd)
  283. {
  284. struct dentry *root;
  285. struct dentry *file;
  286. int ret;
  287. char card_name[64];
  288. char name[64];
  289. unsigned int i;
  290. sprintf(card_name, "%s%d_card", GENWQE_DEVNAME, cd->card_idx);
  291. root = debugfs_create_dir(card_name, cd->debugfs_genwqe);
  292. if (!root) {
  293. ret = -ENOMEM;
  294. goto err0;
  295. }
  296. /* non privileged interfaces are done here */
  297. file = debugfs_create_file("ddcb_info", S_IRUGO, root, cd,
  298. &genwqe_ddcb_info_fops);
  299. if (!file) {
  300. ret = -ENOMEM;
  301. goto err1;
  302. }
  303. file = debugfs_create_file("info", S_IRUGO, root, cd,
  304. &genwqe_info_fops);
  305. if (!file) {
  306. ret = -ENOMEM;
  307. goto err1;
  308. }
  309. file = debugfs_create_x64("err_inject", 0666, root, &cd->err_inject);
  310. if (!file) {
  311. ret = -ENOMEM;
  312. goto err1;
  313. }
  314. file = debugfs_create_u32("ddcb_software_timeout", 0666, root,
  315. &cd->ddcb_software_timeout);
  316. if (!file) {
  317. ret = -ENOMEM;
  318. goto err1;
  319. }
  320. file = debugfs_create_u32("kill_timeout", 0666, root,
  321. &cd->kill_timeout);
  322. if (!file) {
  323. ret = -ENOMEM;
  324. goto err1;
  325. }
  326. /* privileged interfaces follow here */
  327. if (!genwqe_is_privileged(cd)) {
  328. cd->debugfs_root = root;
  329. return 0;
  330. }
  331. file = debugfs_create_file("curr_regs", S_IRUGO, root, cd,
  332. &genwqe_curr_regs_fops);
  333. if (!file) {
  334. ret = -ENOMEM;
  335. goto err1;
  336. }
  337. file = debugfs_create_file("curr_dbg_uid0", S_IRUGO, root, cd,
  338. &genwqe_curr_dbg_uid0_fops);
  339. if (!file) {
  340. ret = -ENOMEM;
  341. goto err1;
  342. }
  343. file = debugfs_create_file("curr_dbg_uid1", S_IRUGO, root, cd,
  344. &genwqe_curr_dbg_uid1_fops);
  345. if (!file) {
  346. ret = -ENOMEM;
  347. goto err1;
  348. }
  349. file = debugfs_create_file("curr_dbg_uid2", S_IRUGO, root, cd,
  350. &genwqe_curr_dbg_uid2_fops);
  351. if (!file) {
  352. ret = -ENOMEM;
  353. goto err1;
  354. }
  355. file = debugfs_create_file("prev_regs", S_IRUGO, root, cd,
  356. &genwqe_prev_regs_fops);
  357. if (!file) {
  358. ret = -ENOMEM;
  359. goto err1;
  360. }
  361. file = debugfs_create_file("prev_dbg_uid0", S_IRUGO, root, cd,
  362. &genwqe_prev_dbg_uid0_fops);
  363. if (!file) {
  364. ret = -ENOMEM;
  365. goto err1;
  366. }
  367. file = debugfs_create_file("prev_dbg_uid1", S_IRUGO, root, cd,
  368. &genwqe_prev_dbg_uid1_fops);
  369. if (!file) {
  370. ret = -ENOMEM;
  371. goto err1;
  372. }
  373. file = debugfs_create_file("prev_dbg_uid2", S_IRUGO, root, cd,
  374. &genwqe_prev_dbg_uid2_fops);
  375. if (!file) {
  376. ret = -ENOMEM;
  377. goto err1;
  378. }
  379. for (i = 0; i < GENWQE_MAX_VFS; i++) {
  380. sprintf(name, "vf%u_jobtimeout_msec", i);
  381. file = debugfs_create_u32(name, 0666, root,
  382. &cd->vf_jobtimeout_msec[i]);
  383. if (!file) {
  384. ret = -ENOMEM;
  385. goto err1;
  386. }
  387. }
  388. file = debugfs_create_file("jobtimer", S_IRUGO, root, cd,
  389. &genwqe_jtimer_fops);
  390. if (!file) {
  391. ret = -ENOMEM;
  392. goto err1;
  393. }
  394. file = debugfs_create_file("queue_working_time", S_IRUGO, root, cd,
  395. &genwqe_queue_working_time_fops);
  396. if (!file) {
  397. ret = -ENOMEM;
  398. goto err1;
  399. }
  400. file = debugfs_create_u32("skip_recovery", 0666, root,
  401. &cd->skip_recovery);
  402. if (!file) {
  403. ret = -ENOMEM;
  404. goto err1;
  405. }
  406. file = debugfs_create_u32("use_platform_recovery", 0666, root,
  407. &cd->use_platform_recovery);
  408. if (!file) {
  409. ret = -ENOMEM;
  410. goto err1;
  411. }
  412. cd->debugfs_root = root;
  413. return 0;
  414. err1:
  415. debugfs_remove_recursive(root);
  416. err0:
  417. return ret;
  418. }
  419. void genqwe_exit_debugfs(struct genwqe_dev *cd)
  420. {
  421. debugfs_remove_recursive(cd->debugfs_root);
  422. }