debugfs.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  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. }