debugfs.c 31 KB

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