debugfs.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363
  1. // SPDX-License-Identifier: GPL-2.0 or BSD-3-Clause
  2. /*
  3. * Copyright(c) 2015-2018 Intel Corporation.
  4. */
  5. #include <linux/debugfs.h>
  6. #include <linux/seq_file.h>
  7. #include <linux/kernel.h>
  8. #include <linux/export.h>
  9. #include <linux/string.h>
  10. #include <linux/types.h>
  11. #include <linux/ratelimit.h>
  12. #include <linux/fault-inject.h>
  13. #include "hfi.h"
  14. #include "trace.h"
  15. #include "debugfs.h"
  16. #include "device.h"
  17. #include "qp.h"
  18. #include "sdma.h"
  19. #include "fault.h"
  20. static struct dentry *hfi1_dbg_root;
  21. /* wrappers to enforce srcu in seq file */
  22. ssize_t hfi1_seq_read(struct file *file, char __user *buf, size_t size,
  23. loff_t *ppos)
  24. {
  25. struct dentry *d = file->f_path.dentry;
  26. ssize_t r;
  27. r = debugfs_file_get(d);
  28. if (unlikely(r))
  29. return r;
  30. r = seq_read(file, buf, size, ppos);
  31. debugfs_file_put(d);
  32. return r;
  33. }
  34. loff_t hfi1_seq_lseek(struct file *file, loff_t offset, int whence)
  35. {
  36. struct dentry *d = file->f_path.dentry;
  37. loff_t r;
  38. r = debugfs_file_get(d);
  39. if (unlikely(r))
  40. return r;
  41. r = seq_lseek(file, offset, whence);
  42. debugfs_file_put(d);
  43. return r;
  44. }
  45. #define private2dd(file) (file_inode(file)->i_private)
  46. #define private2ppd(file) (file_inode(file)->i_private)
  47. static void *_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
  48. {
  49. struct hfi1_opcode_stats_perctx *opstats;
  50. if (*pos >= ARRAY_SIZE(opstats->stats))
  51. return NULL;
  52. return pos;
  53. }
  54. static void *_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
  55. {
  56. struct hfi1_opcode_stats_perctx *opstats;
  57. ++*pos;
  58. if (*pos >= ARRAY_SIZE(opstats->stats))
  59. return NULL;
  60. return pos;
  61. }
  62. static void _opcode_stats_seq_stop(struct seq_file *s, void *v)
  63. {
  64. }
  65. static int opcode_stats_show(struct seq_file *s, u8 i, u64 packets, u64 bytes)
  66. {
  67. if (!packets && !bytes)
  68. return SEQ_SKIP;
  69. seq_printf(s, "%02x %llu/%llu\n", i,
  70. (unsigned long long)packets,
  71. (unsigned long long)bytes);
  72. return 0;
  73. }
  74. static int _opcode_stats_seq_show(struct seq_file *s, void *v)
  75. {
  76. loff_t *spos = v;
  77. loff_t i = *spos, j;
  78. u64 n_packets = 0, n_bytes = 0;
  79. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  80. struct hfi1_devdata *dd = dd_from_dev(ibd);
  81. struct hfi1_ctxtdata *rcd;
  82. for (j = 0; j < dd->first_dyn_alloc_ctxt; j++) {
  83. rcd = hfi1_rcd_get_by_index(dd, j);
  84. if (rcd) {
  85. n_packets += rcd->opstats->stats[i].n_packets;
  86. n_bytes += rcd->opstats->stats[i].n_bytes;
  87. }
  88. hfi1_rcd_put(rcd);
  89. }
  90. return opcode_stats_show(s, i, n_packets, n_bytes);
  91. }
  92. DEBUGFS_SEQ_FILE_OPS(opcode_stats);
  93. DEBUGFS_SEQ_FILE_OPEN(opcode_stats)
  94. DEBUGFS_FILE_OPS(opcode_stats);
  95. static void *_tx_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
  96. {
  97. return _opcode_stats_seq_start(s, pos);
  98. }
  99. static void *_tx_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
  100. {
  101. return _opcode_stats_seq_next(s, v, pos);
  102. }
  103. static void _tx_opcode_stats_seq_stop(struct seq_file *s, void *v)
  104. {
  105. }
  106. static int _tx_opcode_stats_seq_show(struct seq_file *s, void *v)
  107. {
  108. loff_t *spos = v;
  109. loff_t i = *spos;
  110. int j;
  111. u64 n_packets = 0, n_bytes = 0;
  112. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  113. struct hfi1_devdata *dd = dd_from_dev(ibd);
  114. for_each_possible_cpu(j) {
  115. struct hfi1_opcode_stats_perctx *s =
  116. per_cpu_ptr(dd->tx_opstats, j);
  117. n_packets += s->stats[i].n_packets;
  118. n_bytes += s->stats[i].n_bytes;
  119. }
  120. return opcode_stats_show(s, i, n_packets, n_bytes);
  121. }
  122. DEBUGFS_SEQ_FILE_OPS(tx_opcode_stats);
  123. DEBUGFS_SEQ_FILE_OPEN(tx_opcode_stats)
  124. DEBUGFS_FILE_OPS(tx_opcode_stats);
  125. static void *_ctx_stats_seq_start(struct seq_file *s, loff_t *pos)
  126. {
  127. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  128. struct hfi1_devdata *dd = dd_from_dev(ibd);
  129. if (!*pos)
  130. return SEQ_START_TOKEN;
  131. if (*pos >= dd->first_dyn_alloc_ctxt)
  132. return NULL;
  133. return pos;
  134. }
  135. static void *_ctx_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
  136. {
  137. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  138. struct hfi1_devdata *dd = dd_from_dev(ibd);
  139. if (v == SEQ_START_TOKEN)
  140. return pos;
  141. ++*pos;
  142. if (*pos >= dd->first_dyn_alloc_ctxt)
  143. return NULL;
  144. return pos;
  145. }
  146. static void _ctx_stats_seq_stop(struct seq_file *s, void *v)
  147. {
  148. /* nothing allocated */
  149. }
  150. static int _ctx_stats_seq_show(struct seq_file *s, void *v)
  151. {
  152. loff_t *spos;
  153. loff_t i, j;
  154. u64 n_packets = 0;
  155. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  156. struct hfi1_devdata *dd = dd_from_dev(ibd);
  157. struct hfi1_ctxtdata *rcd;
  158. if (v == SEQ_START_TOKEN) {
  159. seq_puts(s, "Ctx:npkts\n");
  160. return 0;
  161. }
  162. spos = v;
  163. i = *spos;
  164. rcd = hfi1_rcd_get_by_index_safe(dd, i);
  165. if (!rcd)
  166. return SEQ_SKIP;
  167. for (j = 0; j < ARRAY_SIZE(rcd->opstats->stats); j++)
  168. n_packets += rcd->opstats->stats[j].n_packets;
  169. hfi1_rcd_put(rcd);
  170. if (!n_packets)
  171. return SEQ_SKIP;
  172. seq_printf(s, " %llu:%llu\n", i, n_packets);
  173. return 0;
  174. }
  175. DEBUGFS_SEQ_FILE_OPS(ctx_stats);
  176. DEBUGFS_SEQ_FILE_OPEN(ctx_stats)
  177. DEBUGFS_FILE_OPS(ctx_stats);
  178. static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
  179. __acquires(RCU)
  180. {
  181. struct rvt_qp_iter *iter;
  182. loff_t n = *pos;
  183. iter = rvt_qp_iter_init(s->private, 0, NULL);
  184. /* stop calls rcu_read_unlock */
  185. rcu_read_lock();
  186. if (!iter)
  187. return NULL;
  188. do {
  189. if (rvt_qp_iter_next(iter)) {
  190. kfree(iter);
  191. return NULL;
  192. }
  193. } while (n--);
  194. return iter;
  195. }
  196. static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
  197. loff_t *pos)
  198. __must_hold(RCU)
  199. {
  200. struct rvt_qp_iter *iter = iter_ptr;
  201. (*pos)++;
  202. if (rvt_qp_iter_next(iter)) {
  203. kfree(iter);
  204. return NULL;
  205. }
  206. return iter;
  207. }
  208. static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr)
  209. __releases(RCU)
  210. {
  211. rcu_read_unlock();
  212. }
  213. static int _qp_stats_seq_show(struct seq_file *s, void *iter_ptr)
  214. {
  215. struct rvt_qp_iter *iter = iter_ptr;
  216. if (!iter)
  217. return 0;
  218. qp_iter_print(s, iter);
  219. return 0;
  220. }
  221. DEBUGFS_SEQ_FILE_OPS(qp_stats);
  222. DEBUGFS_SEQ_FILE_OPEN(qp_stats)
  223. DEBUGFS_FILE_OPS(qp_stats);
  224. static void *_sdes_seq_start(struct seq_file *s, loff_t *pos)
  225. {
  226. struct hfi1_ibdev *ibd;
  227. struct hfi1_devdata *dd;
  228. ibd = (struct hfi1_ibdev *)s->private;
  229. dd = dd_from_dev(ibd);
  230. if (!dd->per_sdma || *pos >= dd->num_sdma)
  231. return NULL;
  232. return pos;
  233. }
  234. static void *_sdes_seq_next(struct seq_file *s, void *v, loff_t *pos)
  235. {
  236. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  237. struct hfi1_devdata *dd = dd_from_dev(ibd);
  238. ++*pos;
  239. if (!dd->per_sdma || *pos >= dd->num_sdma)
  240. return NULL;
  241. return pos;
  242. }
  243. static void _sdes_seq_stop(struct seq_file *s, void *v)
  244. {
  245. }
  246. static int _sdes_seq_show(struct seq_file *s, void *v)
  247. {
  248. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  249. struct hfi1_devdata *dd = dd_from_dev(ibd);
  250. loff_t *spos = v;
  251. loff_t i = *spos;
  252. sdma_seqfile_dump_sde(s, &dd->per_sdma[i]);
  253. return 0;
  254. }
  255. DEBUGFS_SEQ_FILE_OPS(sdes);
  256. DEBUGFS_SEQ_FILE_OPEN(sdes)
  257. DEBUGFS_FILE_OPS(sdes);
  258. static void *_rcds_seq_start(struct seq_file *s, loff_t *pos)
  259. {
  260. struct hfi1_ibdev *ibd;
  261. struct hfi1_devdata *dd;
  262. ibd = (struct hfi1_ibdev *)s->private;
  263. dd = dd_from_dev(ibd);
  264. if (!dd->rcd || *pos >= dd->n_krcv_queues)
  265. return NULL;
  266. return pos;
  267. }
  268. static void *_rcds_seq_next(struct seq_file *s, void *v, loff_t *pos)
  269. {
  270. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  271. struct hfi1_devdata *dd = dd_from_dev(ibd);
  272. ++*pos;
  273. if (!dd->rcd || *pos >= dd->num_rcv_contexts)
  274. return NULL;
  275. return pos;
  276. }
  277. static void _rcds_seq_stop(struct seq_file *s, void *v)
  278. {
  279. }
  280. static int _rcds_seq_show(struct seq_file *s, void *v)
  281. {
  282. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  283. struct hfi1_devdata *dd = dd_from_dev(ibd);
  284. struct hfi1_ctxtdata *rcd;
  285. loff_t *spos = v;
  286. loff_t i = *spos;
  287. rcd = hfi1_rcd_get_by_index_safe(dd, i);
  288. if (rcd)
  289. seqfile_dump_rcd(s, rcd);
  290. hfi1_rcd_put(rcd);
  291. return 0;
  292. }
  293. DEBUGFS_SEQ_FILE_OPS(rcds);
  294. DEBUGFS_SEQ_FILE_OPEN(rcds)
  295. DEBUGFS_FILE_OPS(rcds);
  296. static void *_pios_seq_start(struct seq_file *s, loff_t *pos)
  297. {
  298. struct hfi1_ibdev *ibd;
  299. struct hfi1_devdata *dd;
  300. ibd = (struct hfi1_ibdev *)s->private;
  301. dd = dd_from_dev(ibd);
  302. if (!dd->send_contexts || *pos >= dd->num_send_contexts)
  303. return NULL;
  304. return pos;
  305. }
  306. static void *_pios_seq_next(struct seq_file *s, void *v, loff_t *pos)
  307. {
  308. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  309. struct hfi1_devdata *dd = dd_from_dev(ibd);
  310. ++*pos;
  311. if (!dd->send_contexts || *pos >= dd->num_send_contexts)
  312. return NULL;
  313. return pos;
  314. }
  315. static void _pios_seq_stop(struct seq_file *s, void *v)
  316. {
  317. }
  318. static int _pios_seq_show(struct seq_file *s, void *v)
  319. {
  320. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  321. struct hfi1_devdata *dd = dd_from_dev(ibd);
  322. struct send_context_info *sci;
  323. loff_t *spos = v;
  324. loff_t i = *spos;
  325. unsigned long flags;
  326. spin_lock_irqsave(&dd->sc_lock, flags);
  327. sci = &dd->send_contexts[i];
  328. if (sci && sci->type != SC_USER && sci->allocated && sci->sc)
  329. seqfile_dump_sci(s, i, sci);
  330. spin_unlock_irqrestore(&dd->sc_lock, flags);
  331. return 0;
  332. }
  333. DEBUGFS_SEQ_FILE_OPS(pios);
  334. DEBUGFS_SEQ_FILE_OPEN(pios)
  335. DEBUGFS_FILE_OPS(pios);
  336. /* read the per-device counters */
  337. static ssize_t dev_counters_read(struct file *file, char __user *buf,
  338. size_t count, loff_t *ppos)
  339. {
  340. u64 *counters;
  341. size_t avail;
  342. struct hfi1_devdata *dd;
  343. ssize_t rval;
  344. dd = private2dd(file);
  345. avail = hfi1_read_cntrs(dd, NULL, &counters);
  346. rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
  347. return rval;
  348. }
  349. /* read the per-device counters */
  350. static ssize_t dev_names_read(struct file *file, char __user *buf,
  351. size_t count, loff_t *ppos)
  352. {
  353. char *names;
  354. size_t avail;
  355. struct hfi1_devdata *dd;
  356. ssize_t rval;
  357. dd = private2dd(file);
  358. avail = hfi1_read_cntrs(dd, &names, NULL);
  359. rval = simple_read_from_buffer(buf, count, ppos, names, avail);
  360. return rval;
  361. }
  362. struct counter_info {
  363. char *name;
  364. const struct file_operations ops;
  365. };
  366. /*
  367. * Could use file_inode(file)->i_ino to figure out which file,
  368. * instead of separate routine for each, but for now, this works...
  369. */
  370. /* read the per-port names (same for each port) */
  371. static ssize_t portnames_read(struct file *file, char __user *buf,
  372. size_t count, loff_t *ppos)
  373. {
  374. char *names;
  375. size_t avail;
  376. struct hfi1_devdata *dd;
  377. ssize_t rval;
  378. dd = private2dd(file);
  379. avail = hfi1_read_portcntrs(dd->pport, &names, NULL);
  380. rval = simple_read_from_buffer(buf, count, ppos, names, avail);
  381. return rval;
  382. }
  383. /* read the per-port counters */
  384. static ssize_t portcntrs_debugfs_read(struct file *file, char __user *buf,
  385. size_t count, loff_t *ppos)
  386. {
  387. u64 *counters;
  388. size_t avail;
  389. struct hfi1_pportdata *ppd;
  390. ssize_t rval;
  391. ppd = private2ppd(file);
  392. avail = hfi1_read_portcntrs(ppd, NULL, &counters);
  393. rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
  394. return rval;
  395. }
  396. static void check_dyn_flag(u64 scratch0, char *p, int size, int *used,
  397. int this_hfi, int hfi, u32 flag, const char *what)
  398. {
  399. u32 mask;
  400. mask = flag << (hfi ? CR_DYN_SHIFT : 0);
  401. if (scratch0 & mask) {
  402. *used += scnprintf(p + *used, size - *used,
  403. " 0x%08x - HFI%d %s in use, %s device\n",
  404. mask, hfi, what,
  405. this_hfi == hfi ? "this" : "other");
  406. }
  407. }
  408. static ssize_t asic_flags_read(struct file *file, char __user *buf,
  409. size_t count, loff_t *ppos)
  410. {
  411. struct hfi1_pportdata *ppd;
  412. struct hfi1_devdata *dd;
  413. u64 scratch0;
  414. char *tmp;
  415. int ret = 0;
  416. int size;
  417. int used;
  418. int i;
  419. ppd = private2ppd(file);
  420. dd = ppd->dd;
  421. size = PAGE_SIZE;
  422. used = 0;
  423. tmp = kmalloc(size, GFP_KERNEL);
  424. if (!tmp)
  425. return -ENOMEM;
  426. scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
  427. used += scnprintf(tmp + used, size - used,
  428. "Resource flags: 0x%016llx\n", scratch0);
  429. /* check permanent flag */
  430. if (scratch0 & CR_THERM_INIT) {
  431. used += scnprintf(tmp + used, size - used,
  432. " 0x%08x - thermal monitoring initialized\n",
  433. (u32)CR_THERM_INIT);
  434. }
  435. /* check each dynamic flag on each HFI */
  436. for (i = 0; i < 2; i++) {
  437. check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
  438. CR_SBUS, "SBus");
  439. check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
  440. CR_EPROM, "EPROM");
  441. check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
  442. CR_I2C1, "i2c chain 1");
  443. check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
  444. CR_I2C2, "i2c chain 2");
  445. }
  446. used += scnprintf(tmp + used, size - used, "Write bits to clear\n");
  447. ret = simple_read_from_buffer(buf, count, ppos, tmp, used);
  448. kfree(tmp);
  449. return ret;
  450. }
  451. static ssize_t asic_flags_write(struct file *file, const char __user *buf,
  452. size_t count, loff_t *ppos)
  453. {
  454. struct hfi1_pportdata *ppd;
  455. struct hfi1_devdata *dd;
  456. char *buff;
  457. int ret;
  458. unsigned long long value;
  459. u64 scratch0;
  460. u64 clear;
  461. ppd = private2ppd(file);
  462. dd = ppd->dd;
  463. /* zero terminate and read the expected integer */
  464. buff = memdup_user_nul(buf, count);
  465. if (IS_ERR(buff))
  466. return PTR_ERR(buff);
  467. ret = kstrtoull(buff, 0, &value);
  468. if (ret)
  469. goto do_free;
  470. clear = value;
  471. /* obtain exclusive access */
  472. mutex_lock(&dd->asic_data->asic_resource_mutex);
  473. acquire_hw_mutex(dd);
  474. scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
  475. scratch0 &= ~clear;
  476. write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
  477. /* force write to be visible to other HFI on another OS */
  478. (void)read_csr(dd, ASIC_CFG_SCRATCH);
  479. release_hw_mutex(dd);
  480. mutex_unlock(&dd->asic_data->asic_resource_mutex);
  481. /* return the number of bytes written */
  482. ret = count;
  483. do_free:
  484. kfree(buff);
  485. return ret;
  486. }
  487. /* read the dc8051 memory */
  488. static ssize_t dc8051_memory_read(struct file *file, char __user *buf,
  489. size_t count, loff_t *ppos)
  490. {
  491. struct hfi1_pportdata *ppd = private2ppd(file);
  492. ssize_t rval;
  493. void *tmp;
  494. loff_t start, end;
  495. /* the checks below expect the position to be positive */
  496. if (*ppos < 0)
  497. return -EINVAL;
  498. tmp = kzalloc(DC8051_DATA_MEM_SIZE, GFP_KERNEL);
  499. if (!tmp)
  500. return -ENOMEM;
  501. /*
  502. * Fill in the requested portion of the temporary buffer from the
  503. * 8051 memory. The 8051 memory read is done in terms of 8 bytes.
  504. * Adjust start and end to fit. Skip reading anything if out of
  505. * range.
  506. */
  507. start = *ppos & ~0x7; /* round down */
  508. if (start < DC8051_DATA_MEM_SIZE) {
  509. end = (*ppos + count + 7) & ~0x7; /* round up */
  510. if (end > DC8051_DATA_MEM_SIZE)
  511. end = DC8051_DATA_MEM_SIZE;
  512. rval = read_8051_data(ppd->dd, start, end - start,
  513. (u64 *)(tmp + start));
  514. if (rval)
  515. goto done;
  516. }
  517. rval = simple_read_from_buffer(buf, count, ppos, tmp,
  518. DC8051_DATA_MEM_SIZE);
  519. done:
  520. kfree(tmp);
  521. return rval;
  522. }
  523. static ssize_t debugfs_lcb_read(struct file *file, char __user *buf,
  524. size_t count, loff_t *ppos)
  525. {
  526. struct hfi1_pportdata *ppd = private2ppd(file);
  527. struct hfi1_devdata *dd = ppd->dd;
  528. unsigned long total, csr_off;
  529. u64 data;
  530. if (*ppos < 0)
  531. return -EINVAL;
  532. /* only read 8 byte quantities */
  533. if ((count % 8) != 0)
  534. return -EINVAL;
  535. /* offset must be 8-byte aligned */
  536. if ((*ppos % 8) != 0)
  537. return -EINVAL;
  538. /* do nothing if out of range or zero count */
  539. if (*ppos >= (LCB_END - LCB_START) || !count)
  540. return 0;
  541. /* reduce count if needed */
  542. if (*ppos + count > LCB_END - LCB_START)
  543. count = (LCB_END - LCB_START) - *ppos;
  544. csr_off = LCB_START + *ppos;
  545. for (total = 0; total < count; total += 8, csr_off += 8) {
  546. if (read_lcb_csr(dd, csr_off, (u64 *)&data))
  547. break; /* failed */
  548. if (put_user(data, (unsigned long __user *)(buf + total)))
  549. break;
  550. }
  551. *ppos += total;
  552. return total;
  553. }
  554. static ssize_t debugfs_lcb_write(struct file *file, const char __user *buf,
  555. size_t count, loff_t *ppos)
  556. {
  557. struct hfi1_pportdata *ppd = private2ppd(file);
  558. struct hfi1_devdata *dd = ppd->dd;
  559. unsigned long total, csr_off, data;
  560. if (*ppos < 0)
  561. return -EINVAL;
  562. /* only write 8 byte quantities */
  563. if ((count % 8) != 0)
  564. return -EINVAL;
  565. /* offset must be 8-byte aligned */
  566. if ((*ppos % 8) != 0)
  567. return -EINVAL;
  568. /* do nothing if out of range or zero count */
  569. if (*ppos >= (LCB_END - LCB_START) || !count)
  570. return 0;
  571. /* reduce count if needed */
  572. if (*ppos + count > LCB_END - LCB_START)
  573. count = (LCB_END - LCB_START) - *ppos;
  574. csr_off = LCB_START + *ppos;
  575. for (total = 0; total < count; total += 8, csr_off += 8) {
  576. if (get_user(data, (unsigned long __user *)(buf + total)))
  577. break;
  578. if (write_lcb_csr(dd, csr_off, data))
  579. break; /* failed */
  580. }
  581. *ppos += total;
  582. return total;
  583. }
  584. /*
  585. * read the per-port QSFP data for ppd
  586. */
  587. static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf,
  588. size_t count, loff_t *ppos)
  589. {
  590. struct hfi1_pportdata *ppd;
  591. char *tmp;
  592. int ret;
  593. ppd = private2ppd(file);
  594. tmp = kmalloc(PAGE_SIZE, GFP_KERNEL);
  595. if (!tmp)
  596. return -ENOMEM;
  597. ret = qsfp_dump(ppd, tmp, PAGE_SIZE);
  598. if (ret > 0)
  599. ret = simple_read_from_buffer(buf, count, ppos, tmp, ret);
  600. kfree(tmp);
  601. return ret;
  602. }
  603. /* Do an i2c write operation on the chain for the given HFI. */
  604. static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
  605. size_t count, loff_t *ppos, u32 target)
  606. {
  607. struct hfi1_pportdata *ppd;
  608. char *buff;
  609. int ret;
  610. int i2c_addr;
  611. int offset;
  612. int total_written;
  613. ppd = private2ppd(file);
  614. /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
  615. i2c_addr = (*ppos >> 16) & 0xffff;
  616. offset = *ppos & 0xffff;
  617. /* explicitly reject invalid address 0 to catch cp and cat */
  618. if (i2c_addr == 0)
  619. return -EINVAL;
  620. buff = memdup_user(buf, count);
  621. if (IS_ERR(buff))
  622. return PTR_ERR(buff);
  623. total_written = i2c_write(ppd, target, i2c_addr, offset, buff, count);
  624. if (total_written < 0) {
  625. ret = total_written;
  626. goto _free;
  627. }
  628. *ppos += total_written;
  629. ret = total_written;
  630. _free:
  631. kfree(buff);
  632. return ret;
  633. }
  634. /* Do an i2c write operation on chain for HFI 0. */
  635. static ssize_t i2c1_debugfs_write(struct file *file, const char __user *buf,
  636. size_t count, loff_t *ppos)
  637. {
  638. return __i2c_debugfs_write(file, buf, count, ppos, 0);
  639. }
  640. /* Do an i2c write operation on chain for HFI 1. */
  641. static ssize_t i2c2_debugfs_write(struct file *file, const char __user *buf,
  642. size_t count, loff_t *ppos)
  643. {
  644. return __i2c_debugfs_write(file, buf, count, ppos, 1);
  645. }
  646. /* Do an i2c read operation on the chain for the given HFI. */
  647. static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
  648. size_t count, loff_t *ppos, u32 target)
  649. {
  650. struct hfi1_pportdata *ppd;
  651. char *buff;
  652. int ret;
  653. int i2c_addr;
  654. int offset;
  655. int total_read;
  656. ppd = private2ppd(file);
  657. /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
  658. i2c_addr = (*ppos >> 16) & 0xffff;
  659. offset = *ppos & 0xffff;
  660. /* explicitly reject invalid address 0 to catch cp and cat */
  661. if (i2c_addr == 0)
  662. return -EINVAL;
  663. buff = kmalloc(count, GFP_KERNEL);
  664. if (!buff)
  665. return -ENOMEM;
  666. total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count);
  667. if (total_read < 0) {
  668. ret = total_read;
  669. goto _free;
  670. }
  671. *ppos += total_read;
  672. ret = copy_to_user(buf, buff, total_read);
  673. if (ret > 0) {
  674. ret = -EFAULT;
  675. goto _free;
  676. }
  677. ret = total_read;
  678. _free:
  679. kfree(buff);
  680. return ret;
  681. }
  682. /* Do an i2c read operation on chain for HFI 0. */
  683. static ssize_t i2c1_debugfs_read(struct file *file, char __user *buf,
  684. size_t count, loff_t *ppos)
  685. {
  686. return __i2c_debugfs_read(file, buf, count, ppos, 0);
  687. }
  688. /* Do an i2c read operation on chain for HFI 1. */
  689. static ssize_t i2c2_debugfs_read(struct file *file, char __user *buf,
  690. size_t count, loff_t *ppos)
  691. {
  692. return __i2c_debugfs_read(file, buf, count, ppos, 1);
  693. }
  694. /* Do a QSFP write operation on the i2c chain for the given HFI. */
  695. static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
  696. size_t count, loff_t *ppos, u32 target)
  697. {
  698. struct hfi1_pportdata *ppd;
  699. char *buff;
  700. int ret;
  701. int total_written;
  702. if (*ppos + count > QSFP_PAGESIZE * 4) /* base page + page00-page03 */
  703. return -EINVAL;
  704. ppd = private2ppd(file);
  705. buff = memdup_user(buf, count);
  706. if (IS_ERR(buff))
  707. return PTR_ERR(buff);
  708. total_written = qsfp_write(ppd, target, *ppos, buff, count);
  709. if (total_written < 0) {
  710. ret = total_written;
  711. goto _free;
  712. }
  713. *ppos += total_written;
  714. ret = total_written;
  715. _free:
  716. kfree(buff);
  717. return ret;
  718. }
  719. /* Do a QSFP write operation on i2c chain for HFI 0. */
  720. static ssize_t qsfp1_debugfs_write(struct file *file, const char __user *buf,
  721. size_t count, loff_t *ppos)
  722. {
  723. return __qsfp_debugfs_write(file, buf, count, ppos, 0);
  724. }
  725. /* Do a QSFP write operation on i2c chain for HFI 1. */
  726. static ssize_t qsfp2_debugfs_write(struct file *file, const char __user *buf,
  727. size_t count, loff_t *ppos)
  728. {
  729. return __qsfp_debugfs_write(file, buf, count, ppos, 1);
  730. }
  731. /* Do a QSFP read operation on the i2c chain for the given HFI. */
  732. static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
  733. size_t count, loff_t *ppos, u32 target)
  734. {
  735. struct hfi1_pportdata *ppd;
  736. char *buff;
  737. int ret;
  738. int total_read;
  739. if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */
  740. ret = -EINVAL;
  741. goto _return;
  742. }
  743. ppd = private2ppd(file);
  744. buff = kmalloc(count, GFP_KERNEL);
  745. if (!buff) {
  746. ret = -ENOMEM;
  747. goto _return;
  748. }
  749. total_read = qsfp_read(ppd, target, *ppos, buff, count);
  750. if (total_read < 0) {
  751. ret = total_read;
  752. goto _free;
  753. }
  754. *ppos += total_read;
  755. ret = copy_to_user(buf, buff, total_read);
  756. if (ret > 0) {
  757. ret = -EFAULT;
  758. goto _free;
  759. }
  760. ret = total_read;
  761. _free:
  762. kfree(buff);
  763. _return:
  764. return ret;
  765. }
  766. /* Do a QSFP read operation on i2c chain for HFI 0. */
  767. static ssize_t qsfp1_debugfs_read(struct file *file, char __user *buf,
  768. size_t count, loff_t *ppos)
  769. {
  770. return __qsfp_debugfs_read(file, buf, count, ppos, 0);
  771. }
  772. /* Do a QSFP read operation on i2c chain for HFI 1. */
  773. static ssize_t qsfp2_debugfs_read(struct file *file, char __user *buf,
  774. size_t count, loff_t *ppos)
  775. {
  776. return __qsfp_debugfs_read(file, buf, count, ppos, 1);
  777. }
  778. static int __i2c_debugfs_open(struct inode *in, struct file *fp, u32 target)
  779. {
  780. struct hfi1_pportdata *ppd;
  781. ppd = private2ppd(fp);
  782. return acquire_chip_resource(ppd->dd, i2c_target(target), 0);
  783. }
  784. static int i2c1_debugfs_open(struct inode *in, struct file *fp)
  785. {
  786. return __i2c_debugfs_open(in, fp, 0);
  787. }
  788. static int i2c2_debugfs_open(struct inode *in, struct file *fp)
  789. {
  790. return __i2c_debugfs_open(in, fp, 1);
  791. }
  792. static int __i2c_debugfs_release(struct inode *in, struct file *fp, u32 target)
  793. {
  794. struct hfi1_pportdata *ppd;
  795. ppd = private2ppd(fp);
  796. release_chip_resource(ppd->dd, i2c_target(target));
  797. return 0;
  798. }
  799. static int i2c1_debugfs_release(struct inode *in, struct file *fp)
  800. {
  801. return __i2c_debugfs_release(in, fp, 0);
  802. }
  803. static int i2c2_debugfs_release(struct inode *in, struct file *fp)
  804. {
  805. return __i2c_debugfs_release(in, fp, 1);
  806. }
  807. static int __qsfp_debugfs_open(struct inode *in, struct file *fp, u32 target)
  808. {
  809. struct hfi1_pportdata *ppd;
  810. ppd = private2ppd(fp);
  811. return acquire_chip_resource(ppd->dd, i2c_target(target), 0);
  812. }
  813. static int qsfp1_debugfs_open(struct inode *in, struct file *fp)
  814. {
  815. return __qsfp_debugfs_open(in, fp, 0);
  816. }
  817. static int qsfp2_debugfs_open(struct inode *in, struct file *fp)
  818. {
  819. return __qsfp_debugfs_open(in, fp, 1);
  820. }
  821. static int __qsfp_debugfs_release(struct inode *in, struct file *fp, u32 target)
  822. {
  823. struct hfi1_pportdata *ppd;
  824. ppd = private2ppd(fp);
  825. release_chip_resource(ppd->dd, i2c_target(target));
  826. return 0;
  827. }
  828. static int qsfp1_debugfs_release(struct inode *in, struct file *fp)
  829. {
  830. return __qsfp_debugfs_release(in, fp, 0);
  831. }
  832. static int qsfp2_debugfs_release(struct inode *in, struct file *fp)
  833. {
  834. return __qsfp_debugfs_release(in, fp, 1);
  835. }
  836. #define EXPROM_WRITE_ENABLE BIT_ULL(14)
  837. static bool exprom_wp_disabled;
  838. static int exprom_wp_set(struct hfi1_devdata *dd, bool disable)
  839. {
  840. u64 gpio_val = 0;
  841. if (disable) {
  842. gpio_val = EXPROM_WRITE_ENABLE;
  843. exprom_wp_disabled = true;
  844. dd_dev_info(dd, "Disable Expansion ROM Write Protection\n");
  845. } else {
  846. exprom_wp_disabled = false;
  847. dd_dev_info(dd, "Enable Expansion ROM Write Protection\n");
  848. }
  849. write_csr(dd, ASIC_GPIO_OUT, gpio_val);
  850. write_csr(dd, ASIC_GPIO_OE, gpio_val);
  851. return 0;
  852. }
  853. static ssize_t exprom_wp_debugfs_read(struct file *file, char __user *buf,
  854. size_t count, loff_t *ppos)
  855. {
  856. return 0;
  857. }
  858. static ssize_t exprom_wp_debugfs_write(struct file *file,
  859. const char __user *buf, size_t count,
  860. loff_t *ppos)
  861. {
  862. struct hfi1_pportdata *ppd = private2ppd(file);
  863. char cdata;
  864. if (count != 1)
  865. return -EINVAL;
  866. if (get_user(cdata, buf))
  867. return -EFAULT;
  868. if (cdata == '0')
  869. exprom_wp_set(ppd->dd, false);
  870. else if (cdata == '1')
  871. exprom_wp_set(ppd->dd, true);
  872. else
  873. return -EINVAL;
  874. return 1;
  875. }
  876. static unsigned long exprom_in_use;
  877. static int exprom_wp_debugfs_open(struct inode *in, struct file *fp)
  878. {
  879. if (test_and_set_bit(0, &exprom_in_use))
  880. return -EBUSY;
  881. return 0;
  882. }
  883. static int exprom_wp_debugfs_release(struct inode *in, struct file *fp)
  884. {
  885. struct hfi1_pportdata *ppd = private2ppd(fp);
  886. if (exprom_wp_disabled)
  887. exprom_wp_set(ppd->dd, false);
  888. clear_bit(0, &exprom_in_use);
  889. return 0;
  890. }
  891. #define DEBUGFS_OPS(nm, readroutine, writeroutine) \
  892. { \
  893. .name = nm, \
  894. .ops = { \
  895. .owner = THIS_MODULE, \
  896. .read = readroutine, \
  897. .write = writeroutine, \
  898. .llseek = generic_file_llseek, \
  899. }, \
  900. }
  901. #define DEBUGFS_XOPS(nm, readf, writef, openf, releasef) \
  902. { \
  903. .name = nm, \
  904. .ops = { \
  905. .owner = THIS_MODULE, \
  906. .read = readf, \
  907. .write = writef, \
  908. .llseek = generic_file_llseek, \
  909. .open = openf, \
  910. .release = releasef \
  911. }, \
  912. }
  913. static const struct counter_info cntr_ops[] = {
  914. DEBUGFS_OPS("counter_names", dev_names_read, NULL),
  915. DEBUGFS_OPS("counters", dev_counters_read, NULL),
  916. DEBUGFS_OPS("portcounter_names", portnames_read, NULL),
  917. };
  918. static const struct counter_info port_cntr_ops[] = {
  919. DEBUGFS_OPS("port%dcounters", portcntrs_debugfs_read, NULL),
  920. DEBUGFS_XOPS("i2c1", i2c1_debugfs_read, i2c1_debugfs_write,
  921. i2c1_debugfs_open, i2c1_debugfs_release),
  922. DEBUGFS_XOPS("i2c2", i2c2_debugfs_read, i2c2_debugfs_write,
  923. i2c2_debugfs_open, i2c2_debugfs_release),
  924. DEBUGFS_OPS("qsfp_dump%d", qsfp_debugfs_dump, NULL),
  925. DEBUGFS_XOPS("qsfp1", qsfp1_debugfs_read, qsfp1_debugfs_write,
  926. qsfp1_debugfs_open, qsfp1_debugfs_release),
  927. DEBUGFS_XOPS("qsfp2", qsfp2_debugfs_read, qsfp2_debugfs_write,
  928. qsfp2_debugfs_open, qsfp2_debugfs_release),
  929. DEBUGFS_XOPS("exprom_wp", exprom_wp_debugfs_read,
  930. exprom_wp_debugfs_write, exprom_wp_debugfs_open,
  931. exprom_wp_debugfs_release),
  932. DEBUGFS_OPS("asic_flags", asic_flags_read, asic_flags_write),
  933. DEBUGFS_OPS("dc8051_memory", dc8051_memory_read, NULL),
  934. DEBUGFS_OPS("lcb", debugfs_lcb_read, debugfs_lcb_write),
  935. };
  936. static void *_sdma_cpu_list_seq_start(struct seq_file *s, loff_t *pos)
  937. {
  938. if (*pos >= num_online_cpus())
  939. return NULL;
  940. return pos;
  941. }
  942. static void *_sdma_cpu_list_seq_next(struct seq_file *s, void *v, loff_t *pos)
  943. {
  944. ++*pos;
  945. if (*pos >= num_online_cpus())
  946. return NULL;
  947. return pos;
  948. }
  949. static void _sdma_cpu_list_seq_stop(struct seq_file *s, void *v)
  950. {
  951. /* nothing allocated */
  952. }
  953. static int _sdma_cpu_list_seq_show(struct seq_file *s, void *v)
  954. {
  955. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  956. struct hfi1_devdata *dd = dd_from_dev(ibd);
  957. loff_t *spos = v;
  958. loff_t i = *spos;
  959. sdma_seqfile_dump_cpu_list(s, dd, (unsigned long)i);
  960. return 0;
  961. }
  962. DEBUGFS_SEQ_FILE_OPS(sdma_cpu_list);
  963. DEBUGFS_SEQ_FILE_OPEN(sdma_cpu_list)
  964. DEBUGFS_FILE_OPS(sdma_cpu_list);
  965. void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
  966. {
  967. char name[sizeof("port0counters") + 1];
  968. char link[10];
  969. struct hfi1_devdata *dd = dd_from_dev(ibd);
  970. struct hfi1_pportdata *ppd;
  971. struct dentry *root;
  972. int unit = dd->unit;
  973. int i, j;
  974. if (!hfi1_dbg_root)
  975. return;
  976. snprintf(name, sizeof(name), "%s_%d", class_name(), unit);
  977. snprintf(link, sizeof(link), "%d", unit);
  978. root = debugfs_create_dir(name, hfi1_dbg_root);
  979. ibd->hfi1_ibdev_dbg = root;
  980. ibd->hfi1_ibdev_link =
  981. debugfs_create_symlink(link, hfi1_dbg_root, name);
  982. debugfs_create_file("opcode_stats", 0444, root, ibd,
  983. &_opcode_stats_file_ops);
  984. debugfs_create_file("tx_opcode_stats", 0444, root, ibd,
  985. &_tx_opcode_stats_file_ops);
  986. debugfs_create_file("ctx_stats", 0444, root, ibd, &_ctx_stats_file_ops);
  987. debugfs_create_file("qp_stats", 0444, root, ibd, &_qp_stats_file_ops);
  988. debugfs_create_file("sdes", 0444, root, ibd, &_sdes_file_ops);
  989. debugfs_create_file("rcds", 0444, root, ibd, &_rcds_file_ops);
  990. debugfs_create_file("pios", 0444, root, ibd, &_pios_file_ops);
  991. debugfs_create_file("sdma_cpu_list", 0444, root, ibd,
  992. &_sdma_cpu_list_file_ops);
  993. /* dev counter files */
  994. for (i = 0; i < ARRAY_SIZE(cntr_ops); i++)
  995. debugfs_create_file(cntr_ops[i].name, 0444, root, dd,
  996. &cntr_ops[i].ops);
  997. /* per port files */
  998. for (ppd = dd->pport, j = 0; j < dd->num_pports; j++, ppd++)
  999. for (i = 0; i < ARRAY_SIZE(port_cntr_ops); i++) {
  1000. snprintf(name,
  1001. sizeof(name),
  1002. port_cntr_ops[i].name,
  1003. j + 1);
  1004. debugfs_create_file(name,
  1005. !port_cntr_ops[i].ops.write ?
  1006. S_IRUGO :
  1007. S_IRUGO | S_IWUSR,
  1008. root, ppd, &port_cntr_ops[i].ops);
  1009. }
  1010. hfi1_fault_init_debugfs(ibd);
  1011. }
  1012. void hfi1_dbg_ibdev_exit(struct hfi1_ibdev *ibd)
  1013. {
  1014. if (!hfi1_dbg_root)
  1015. goto out;
  1016. hfi1_fault_exit_debugfs(ibd);
  1017. debugfs_remove(ibd->hfi1_ibdev_link);
  1018. debugfs_remove_recursive(ibd->hfi1_ibdev_dbg);
  1019. out:
  1020. ibd->hfi1_ibdev_dbg = NULL;
  1021. }
  1022. /*
  1023. * driver stats field names, one line per stat, single string. Used by
  1024. * programs like hfistats to print the stats in a way which works for
  1025. * different versions of drivers, without changing program source.
  1026. * if hfi1_ib_stats changes, this needs to change. Names need to be
  1027. * 12 chars or less (w/o newline), for proper display by hfistats utility.
  1028. */
  1029. static const char * const hfi1_statnames[] = {
  1030. /* must be element 0*/
  1031. "KernIntr",
  1032. "ErrorIntr",
  1033. "Tx_Errs",
  1034. "Rcv_Errs",
  1035. "H/W_Errs",
  1036. "NoPIOBufs",
  1037. "CtxtsOpen",
  1038. "RcvLen_Errs",
  1039. "EgrBufFull",
  1040. "EgrHdrFull"
  1041. };
  1042. static void *_driver_stats_names_seq_start(struct seq_file *s, loff_t *pos)
  1043. {
  1044. if (*pos >= ARRAY_SIZE(hfi1_statnames))
  1045. return NULL;
  1046. return pos;
  1047. }
  1048. static void *_driver_stats_names_seq_next(
  1049. struct seq_file *s,
  1050. void *v,
  1051. loff_t *pos)
  1052. {
  1053. ++*pos;
  1054. if (*pos >= ARRAY_SIZE(hfi1_statnames))
  1055. return NULL;
  1056. return pos;
  1057. }
  1058. static void _driver_stats_names_seq_stop(struct seq_file *s, void *v)
  1059. {
  1060. }
  1061. static int _driver_stats_names_seq_show(struct seq_file *s, void *v)
  1062. {
  1063. loff_t *spos = v;
  1064. seq_printf(s, "%s\n", hfi1_statnames[*spos]);
  1065. return 0;
  1066. }
  1067. DEBUGFS_SEQ_FILE_OPS(driver_stats_names);
  1068. DEBUGFS_SEQ_FILE_OPEN(driver_stats_names)
  1069. DEBUGFS_FILE_OPS(driver_stats_names);
  1070. static void *_driver_stats_seq_start(struct seq_file *s, loff_t *pos)
  1071. {
  1072. if (*pos >= ARRAY_SIZE(hfi1_statnames))
  1073. return NULL;
  1074. return pos;
  1075. }
  1076. static void *_driver_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
  1077. {
  1078. ++*pos;
  1079. if (*pos >= ARRAY_SIZE(hfi1_statnames))
  1080. return NULL;
  1081. return pos;
  1082. }
  1083. static void _driver_stats_seq_stop(struct seq_file *s, void *v)
  1084. {
  1085. }
  1086. static void hfi1_sps_show_ints(struct seq_file *s)
  1087. {
  1088. unsigned long index, flags;
  1089. struct hfi1_devdata *dd;
  1090. u64 sps_ints = 0;
  1091. xa_lock_irqsave(&hfi1_dev_table, flags);
  1092. xa_for_each(&hfi1_dev_table, index, dd) {
  1093. sps_ints += get_all_cpu_total(dd->int_counter);
  1094. }
  1095. xa_unlock_irqrestore(&hfi1_dev_table, flags);
  1096. seq_write(s, &sps_ints, sizeof(u64));
  1097. }
  1098. static int _driver_stats_seq_show(struct seq_file *s, void *v)
  1099. {
  1100. loff_t *spos = v;
  1101. u64 *stats = (u64 *)&hfi1_stats;
  1102. /* special case for interrupts */
  1103. if (*spos == 0)
  1104. hfi1_sps_show_ints(s);
  1105. else
  1106. seq_write(s, stats + *spos, sizeof(u64));
  1107. return 0;
  1108. }
  1109. DEBUGFS_SEQ_FILE_OPS(driver_stats);
  1110. DEBUGFS_SEQ_FILE_OPEN(driver_stats)
  1111. DEBUGFS_FILE_OPS(driver_stats);
  1112. void hfi1_dbg_init(void)
  1113. {
  1114. hfi1_dbg_root = debugfs_create_dir(DRIVER_NAME, NULL);
  1115. debugfs_create_file("driver_stats_names", 0444, hfi1_dbg_root, NULL,
  1116. &_driver_stats_names_file_ops);
  1117. debugfs_create_file("driver_stats", 0444, hfi1_dbg_root, NULL,
  1118. &_driver_stats_file_ops);
  1119. }
  1120. void hfi1_dbg_exit(void)
  1121. {
  1122. debugfs_remove_recursive(hfi1_dbg_root);
  1123. hfi1_dbg_root = NULL;
  1124. }