debugfs.c 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536
  1. /*
  2. * Copyright(c) 2015-2017 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. static struct dentry *hfi1_dbg_root;
  63. /* wrappers to enforce srcu in seq file */
  64. static ssize_t hfi1_seq_read(
  65. struct file *file,
  66. char __user *buf,
  67. size_t size,
  68. loff_t *ppos)
  69. {
  70. struct dentry *d = file->f_path.dentry;
  71. int srcu_idx;
  72. ssize_t r;
  73. r = debugfs_use_file_start(d, &srcu_idx);
  74. if (likely(!r))
  75. r = seq_read(file, buf, size, ppos);
  76. debugfs_use_file_finish(srcu_idx);
  77. return r;
  78. }
  79. static loff_t hfi1_seq_lseek(
  80. struct file *file,
  81. loff_t offset,
  82. int whence)
  83. {
  84. struct dentry *d = file->f_path.dentry;
  85. int srcu_idx;
  86. loff_t r;
  87. r = debugfs_use_file_start(d, &srcu_idx);
  88. if (likely(!r))
  89. r = seq_lseek(file, offset, whence);
  90. debugfs_use_file_finish(srcu_idx);
  91. return r;
  92. }
  93. #define private2dd(file) (file_inode(file)->i_private)
  94. #define private2ppd(file) (file_inode(file)->i_private)
  95. #define DEBUGFS_SEQ_FILE_OPS(name) \
  96. static const struct seq_operations _##name##_seq_ops = { \
  97. .start = _##name##_seq_start, \
  98. .next = _##name##_seq_next, \
  99. .stop = _##name##_seq_stop, \
  100. .show = _##name##_seq_show \
  101. }
  102. #define DEBUGFS_SEQ_FILE_OPEN(name) \
  103. static int _##name##_open(struct inode *inode, struct file *s) \
  104. { \
  105. struct seq_file *seq; \
  106. int ret; \
  107. ret = seq_open(s, &_##name##_seq_ops); \
  108. if (ret) \
  109. return ret; \
  110. seq = s->private_data; \
  111. seq->private = inode->i_private; \
  112. return 0; \
  113. }
  114. #define DEBUGFS_FILE_OPS(name) \
  115. static const struct file_operations _##name##_file_ops = { \
  116. .owner = THIS_MODULE, \
  117. .open = _##name##_open, \
  118. .read = hfi1_seq_read, \
  119. .llseek = hfi1_seq_lseek, \
  120. .release = seq_release \
  121. }
  122. #define DEBUGFS_FILE_CREATE(name, parent, data, ops, mode) \
  123. do { \
  124. struct dentry *ent; \
  125. ent = debugfs_create_file(name, mode, parent, \
  126. data, ops); \
  127. if (!ent) \
  128. pr_warn("create of %s failed\n", name); \
  129. } while (0)
  130. #define DEBUGFS_SEQ_FILE_CREATE(name, parent, data) \
  131. DEBUGFS_FILE_CREATE(#name, parent, data, &_##name##_file_ops, S_IRUGO)
  132. static void *_opcode_stats_seq_start(struct seq_file *s, loff_t *pos)
  133. {
  134. struct hfi1_opcode_stats_perctx *opstats;
  135. if (*pos >= ARRAY_SIZE(opstats->stats))
  136. return NULL;
  137. return pos;
  138. }
  139. static void *_opcode_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
  140. {
  141. struct hfi1_opcode_stats_perctx *opstats;
  142. ++*pos;
  143. if (*pos >= ARRAY_SIZE(opstats->stats))
  144. return NULL;
  145. return pos;
  146. }
  147. static void _opcode_stats_seq_stop(struct seq_file *s, void *v)
  148. {
  149. }
  150. static int _opcode_stats_seq_show(struct seq_file *s, void *v)
  151. {
  152. loff_t *spos = v;
  153. loff_t i = *spos, 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. struct hfi1_ctxtdata *rcd;
  158. for (j = 0; j < dd->first_dyn_alloc_ctxt; j++) {
  159. rcd = hfi1_rcd_get_by_index(dd, j);
  160. if (rcd) {
  161. n_packets += rcd->opstats->stats[i].n_packets;
  162. n_bytes += rcd->opstats->stats[i].n_bytes;
  163. }
  164. hfi1_rcd_put(rcd);
  165. }
  166. if (!n_packets && !n_bytes)
  167. return SEQ_SKIP;
  168. seq_printf(s, "%02llx %llu/%llu\n", i,
  169. (unsigned long long)n_packets,
  170. (unsigned long long)n_bytes);
  171. return 0;
  172. }
  173. DEBUGFS_SEQ_FILE_OPS(opcode_stats);
  174. DEBUGFS_SEQ_FILE_OPEN(opcode_stats)
  175. DEBUGFS_FILE_OPS(opcode_stats);
  176. static void *_ctx_stats_seq_start(struct seq_file *s, loff_t *pos)
  177. {
  178. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  179. struct hfi1_devdata *dd = dd_from_dev(ibd);
  180. if (!*pos)
  181. return SEQ_START_TOKEN;
  182. if (*pos >= dd->first_dyn_alloc_ctxt)
  183. return NULL;
  184. return pos;
  185. }
  186. static void *_ctx_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
  187. {
  188. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  189. struct hfi1_devdata *dd = dd_from_dev(ibd);
  190. if (v == SEQ_START_TOKEN)
  191. return pos;
  192. ++*pos;
  193. if (*pos >= dd->first_dyn_alloc_ctxt)
  194. return NULL;
  195. return pos;
  196. }
  197. static void _ctx_stats_seq_stop(struct seq_file *s, void *v)
  198. {
  199. /* nothing allocated */
  200. }
  201. static int _ctx_stats_seq_show(struct seq_file *s, void *v)
  202. {
  203. loff_t *spos;
  204. loff_t i, j;
  205. u64 n_packets = 0;
  206. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  207. struct hfi1_devdata *dd = dd_from_dev(ibd);
  208. struct hfi1_ctxtdata *rcd;
  209. if (v == SEQ_START_TOKEN) {
  210. seq_puts(s, "Ctx:npkts\n");
  211. return 0;
  212. }
  213. spos = v;
  214. i = *spos;
  215. rcd = hfi1_rcd_get_by_index(dd, i);
  216. if (!rcd)
  217. return SEQ_SKIP;
  218. for (j = 0; j < ARRAY_SIZE(rcd->opstats->stats); j++)
  219. n_packets += rcd->opstats->stats[j].n_packets;
  220. hfi1_rcd_put(rcd);
  221. if (!n_packets)
  222. return SEQ_SKIP;
  223. seq_printf(s, " %llu:%llu\n", i, n_packets);
  224. return 0;
  225. }
  226. DEBUGFS_SEQ_FILE_OPS(ctx_stats);
  227. DEBUGFS_SEQ_FILE_OPEN(ctx_stats)
  228. DEBUGFS_FILE_OPS(ctx_stats);
  229. static void *_qp_stats_seq_start(struct seq_file *s, loff_t *pos)
  230. __acquires(RCU)
  231. {
  232. struct rvt_qp_iter *iter;
  233. loff_t n = *pos;
  234. iter = rvt_qp_iter_init(s->private, 0, NULL);
  235. /* stop calls rcu_read_unlock */
  236. rcu_read_lock();
  237. if (!iter)
  238. return NULL;
  239. do {
  240. if (rvt_qp_iter_next(iter)) {
  241. kfree(iter);
  242. return NULL;
  243. }
  244. } while (n--);
  245. return iter;
  246. }
  247. static void *_qp_stats_seq_next(struct seq_file *s, void *iter_ptr,
  248. loff_t *pos)
  249. __must_hold(RCU)
  250. {
  251. struct rvt_qp_iter *iter = iter_ptr;
  252. (*pos)++;
  253. if (rvt_qp_iter_next(iter)) {
  254. kfree(iter);
  255. return NULL;
  256. }
  257. return iter;
  258. }
  259. static void _qp_stats_seq_stop(struct seq_file *s, void *iter_ptr)
  260. __releases(RCU)
  261. {
  262. rcu_read_unlock();
  263. }
  264. static int _qp_stats_seq_show(struct seq_file *s, void *iter_ptr)
  265. {
  266. struct rvt_qp_iter *iter = iter_ptr;
  267. if (!iter)
  268. return 0;
  269. qp_iter_print(s, iter);
  270. return 0;
  271. }
  272. DEBUGFS_SEQ_FILE_OPS(qp_stats);
  273. DEBUGFS_SEQ_FILE_OPEN(qp_stats)
  274. DEBUGFS_FILE_OPS(qp_stats);
  275. static void *_sdes_seq_start(struct seq_file *s, loff_t *pos)
  276. {
  277. struct hfi1_ibdev *ibd;
  278. struct hfi1_devdata *dd;
  279. ibd = (struct hfi1_ibdev *)s->private;
  280. dd = dd_from_dev(ibd);
  281. if (!dd->per_sdma || *pos >= dd->num_sdma)
  282. return NULL;
  283. return pos;
  284. }
  285. static void *_sdes_seq_next(struct seq_file *s, void *v, loff_t *pos)
  286. {
  287. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  288. struct hfi1_devdata *dd = dd_from_dev(ibd);
  289. ++*pos;
  290. if (!dd->per_sdma || *pos >= dd->num_sdma)
  291. return NULL;
  292. return pos;
  293. }
  294. static void _sdes_seq_stop(struct seq_file *s, void *v)
  295. {
  296. }
  297. static int _sdes_seq_show(struct seq_file *s, void *v)
  298. {
  299. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  300. struct hfi1_devdata *dd = dd_from_dev(ibd);
  301. loff_t *spos = v;
  302. loff_t i = *spos;
  303. sdma_seqfile_dump_sde(s, &dd->per_sdma[i]);
  304. return 0;
  305. }
  306. DEBUGFS_SEQ_FILE_OPS(sdes);
  307. DEBUGFS_SEQ_FILE_OPEN(sdes)
  308. DEBUGFS_FILE_OPS(sdes);
  309. static void *_rcds_seq_start(struct seq_file *s, loff_t *pos)
  310. {
  311. struct hfi1_ibdev *ibd;
  312. struct hfi1_devdata *dd;
  313. ibd = (struct hfi1_ibdev *)s->private;
  314. dd = dd_from_dev(ibd);
  315. if (!dd->rcd || *pos >= dd->n_krcv_queues)
  316. return NULL;
  317. return pos;
  318. }
  319. static void *_rcds_seq_next(struct seq_file *s, void *v, loff_t *pos)
  320. {
  321. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  322. struct hfi1_devdata *dd = dd_from_dev(ibd);
  323. ++*pos;
  324. if (!dd->rcd || *pos >= dd->n_krcv_queues)
  325. return NULL;
  326. return pos;
  327. }
  328. static void _rcds_seq_stop(struct seq_file *s, void *v)
  329. {
  330. }
  331. static int _rcds_seq_show(struct seq_file *s, void *v)
  332. {
  333. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  334. struct hfi1_devdata *dd = dd_from_dev(ibd);
  335. struct hfi1_ctxtdata *rcd;
  336. loff_t *spos = v;
  337. loff_t i = *spos;
  338. rcd = hfi1_rcd_get_by_index(dd, i);
  339. if (rcd)
  340. seqfile_dump_rcd(s, rcd);
  341. hfi1_rcd_put(rcd);
  342. return 0;
  343. }
  344. DEBUGFS_SEQ_FILE_OPS(rcds);
  345. DEBUGFS_SEQ_FILE_OPEN(rcds)
  346. DEBUGFS_FILE_OPS(rcds);
  347. /* read the per-device counters */
  348. static ssize_t dev_counters_read(struct file *file, char __user *buf,
  349. size_t count, loff_t *ppos)
  350. {
  351. u64 *counters;
  352. size_t avail;
  353. struct hfi1_devdata *dd;
  354. ssize_t rval;
  355. dd = private2dd(file);
  356. avail = hfi1_read_cntrs(dd, NULL, &counters);
  357. rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
  358. return rval;
  359. }
  360. /* read the per-device counters */
  361. static ssize_t dev_names_read(struct file *file, char __user *buf,
  362. size_t count, loff_t *ppos)
  363. {
  364. char *names;
  365. size_t avail;
  366. struct hfi1_devdata *dd;
  367. ssize_t rval;
  368. dd = private2dd(file);
  369. avail = hfi1_read_cntrs(dd, &names, NULL);
  370. rval = simple_read_from_buffer(buf, count, ppos, names, avail);
  371. return rval;
  372. }
  373. struct counter_info {
  374. char *name;
  375. const struct file_operations ops;
  376. };
  377. /*
  378. * Could use file_inode(file)->i_ino to figure out which file,
  379. * instead of separate routine for each, but for now, this works...
  380. */
  381. /* read the per-port names (same for each port) */
  382. static ssize_t portnames_read(struct file *file, char __user *buf,
  383. size_t count, loff_t *ppos)
  384. {
  385. char *names;
  386. size_t avail;
  387. struct hfi1_devdata *dd;
  388. ssize_t rval;
  389. dd = private2dd(file);
  390. avail = hfi1_read_portcntrs(dd->pport, &names, NULL);
  391. rval = simple_read_from_buffer(buf, count, ppos, names, avail);
  392. return rval;
  393. }
  394. /* read the per-port counters */
  395. static ssize_t portcntrs_debugfs_read(struct file *file, char __user *buf,
  396. size_t count, loff_t *ppos)
  397. {
  398. u64 *counters;
  399. size_t avail;
  400. struct hfi1_pportdata *ppd;
  401. ssize_t rval;
  402. ppd = private2ppd(file);
  403. avail = hfi1_read_portcntrs(ppd, NULL, &counters);
  404. rval = simple_read_from_buffer(buf, count, ppos, counters, avail);
  405. return rval;
  406. }
  407. static void check_dyn_flag(u64 scratch0, char *p, int size, int *used,
  408. int this_hfi, int hfi, u32 flag, const char *what)
  409. {
  410. u32 mask;
  411. mask = flag << (hfi ? CR_DYN_SHIFT : 0);
  412. if (scratch0 & mask) {
  413. *used += scnprintf(p + *used, size - *used,
  414. " 0x%08x - HFI%d %s in use, %s device\n",
  415. mask, hfi, what,
  416. this_hfi == hfi ? "this" : "other");
  417. }
  418. }
  419. static ssize_t asic_flags_read(struct file *file, char __user *buf,
  420. size_t count, loff_t *ppos)
  421. {
  422. struct hfi1_pportdata *ppd;
  423. struct hfi1_devdata *dd;
  424. u64 scratch0;
  425. char *tmp;
  426. int ret = 0;
  427. int size;
  428. int used;
  429. int i;
  430. ppd = private2ppd(file);
  431. dd = ppd->dd;
  432. size = PAGE_SIZE;
  433. used = 0;
  434. tmp = kmalloc(size, GFP_KERNEL);
  435. if (!tmp)
  436. return -ENOMEM;
  437. scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
  438. used += scnprintf(tmp + used, size - used,
  439. "Resource flags: 0x%016llx\n", scratch0);
  440. /* check permanent flag */
  441. if (scratch0 & CR_THERM_INIT) {
  442. used += scnprintf(tmp + used, size - used,
  443. " 0x%08x - thermal monitoring initialized\n",
  444. (u32)CR_THERM_INIT);
  445. }
  446. /* check each dynamic flag on each HFI */
  447. for (i = 0; i < 2; i++) {
  448. check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
  449. CR_SBUS, "SBus");
  450. check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
  451. CR_EPROM, "EPROM");
  452. check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
  453. CR_I2C1, "i2c chain 1");
  454. check_dyn_flag(scratch0, tmp, size, &used, dd->hfi1_id, i,
  455. CR_I2C2, "i2c chain 2");
  456. }
  457. used += scnprintf(tmp + used, size - used, "Write bits to clear\n");
  458. ret = simple_read_from_buffer(buf, count, ppos, tmp, used);
  459. kfree(tmp);
  460. return ret;
  461. }
  462. static ssize_t asic_flags_write(struct file *file, const char __user *buf,
  463. size_t count, loff_t *ppos)
  464. {
  465. struct hfi1_pportdata *ppd;
  466. struct hfi1_devdata *dd;
  467. char *buff;
  468. int ret;
  469. unsigned long long value;
  470. u64 scratch0;
  471. u64 clear;
  472. ppd = private2ppd(file);
  473. dd = ppd->dd;
  474. /* zero terminate and read the expected integer */
  475. buff = memdup_user_nul(buf, count);
  476. if (IS_ERR(buff))
  477. return PTR_ERR(buff);
  478. ret = kstrtoull(buff, 0, &value);
  479. if (ret)
  480. goto do_free;
  481. clear = value;
  482. /* obtain exclusive access */
  483. mutex_lock(&dd->asic_data->asic_resource_mutex);
  484. acquire_hw_mutex(dd);
  485. scratch0 = read_csr(dd, ASIC_CFG_SCRATCH);
  486. scratch0 &= ~clear;
  487. write_csr(dd, ASIC_CFG_SCRATCH, scratch0);
  488. /* force write to be visible to other HFI on another OS */
  489. (void)read_csr(dd, ASIC_CFG_SCRATCH);
  490. release_hw_mutex(dd);
  491. mutex_unlock(&dd->asic_data->asic_resource_mutex);
  492. /* return the number of bytes written */
  493. ret = count;
  494. do_free:
  495. kfree(buff);
  496. return ret;
  497. }
  498. /* read the dc8051 memory */
  499. static ssize_t dc8051_memory_read(struct file *file, char __user *buf,
  500. size_t count, loff_t *ppos)
  501. {
  502. struct hfi1_pportdata *ppd = private2ppd(file);
  503. ssize_t rval;
  504. void *tmp;
  505. loff_t start, end;
  506. /* the checks below expect the position to be positive */
  507. if (*ppos < 0)
  508. return -EINVAL;
  509. tmp = kzalloc(DC8051_DATA_MEM_SIZE, GFP_KERNEL);
  510. if (!tmp)
  511. return -ENOMEM;
  512. /*
  513. * Fill in the requested portion of the temporary buffer from the
  514. * 8051 memory. The 8051 memory read is done in terms of 8 bytes.
  515. * Adjust start and end to fit. Skip reading anything if out of
  516. * range.
  517. */
  518. start = *ppos & ~0x7; /* round down */
  519. if (start < DC8051_DATA_MEM_SIZE) {
  520. end = (*ppos + count + 7) & ~0x7; /* round up */
  521. if (end > DC8051_DATA_MEM_SIZE)
  522. end = DC8051_DATA_MEM_SIZE;
  523. rval = read_8051_data(ppd->dd, start, end - start,
  524. (u64 *)(tmp + start));
  525. if (rval)
  526. goto done;
  527. }
  528. rval = simple_read_from_buffer(buf, count, ppos, tmp,
  529. DC8051_DATA_MEM_SIZE);
  530. done:
  531. kfree(tmp);
  532. return rval;
  533. }
  534. static ssize_t debugfs_lcb_read(struct file *file, char __user *buf,
  535. size_t count, loff_t *ppos)
  536. {
  537. struct hfi1_pportdata *ppd = private2ppd(file);
  538. struct hfi1_devdata *dd = ppd->dd;
  539. unsigned long total, csr_off;
  540. u64 data;
  541. if (*ppos < 0)
  542. return -EINVAL;
  543. /* only read 8 byte quantities */
  544. if ((count % 8) != 0)
  545. return -EINVAL;
  546. /* offset must be 8-byte aligned */
  547. if ((*ppos % 8) != 0)
  548. return -EINVAL;
  549. /* do nothing if out of range or zero count */
  550. if (*ppos >= (LCB_END - LCB_START) || !count)
  551. return 0;
  552. /* reduce count if needed */
  553. if (*ppos + count > LCB_END - LCB_START)
  554. count = (LCB_END - LCB_START) - *ppos;
  555. csr_off = LCB_START + *ppos;
  556. for (total = 0; total < count; total += 8, csr_off += 8) {
  557. if (read_lcb_csr(dd, csr_off, (u64 *)&data))
  558. break; /* failed */
  559. if (put_user(data, (unsigned long __user *)(buf + total)))
  560. break;
  561. }
  562. *ppos += total;
  563. return total;
  564. }
  565. static ssize_t debugfs_lcb_write(struct file *file, const char __user *buf,
  566. size_t count, loff_t *ppos)
  567. {
  568. struct hfi1_pportdata *ppd = private2ppd(file);
  569. struct hfi1_devdata *dd = ppd->dd;
  570. unsigned long total, csr_off, data;
  571. if (*ppos < 0)
  572. return -EINVAL;
  573. /* only write 8 byte quantities */
  574. if ((count % 8) != 0)
  575. return -EINVAL;
  576. /* offset must be 8-byte aligned */
  577. if ((*ppos % 8) != 0)
  578. return -EINVAL;
  579. /* do nothing if out of range or zero count */
  580. if (*ppos >= (LCB_END - LCB_START) || !count)
  581. return 0;
  582. /* reduce count if needed */
  583. if (*ppos + count > LCB_END - LCB_START)
  584. count = (LCB_END - LCB_START) - *ppos;
  585. csr_off = LCB_START + *ppos;
  586. for (total = 0; total < count; total += 8, csr_off += 8) {
  587. if (get_user(data, (unsigned long __user *)(buf + total)))
  588. break;
  589. if (write_lcb_csr(dd, csr_off, data))
  590. break; /* failed */
  591. }
  592. *ppos += total;
  593. return total;
  594. }
  595. /*
  596. * read the per-port QSFP data for ppd
  597. */
  598. static ssize_t qsfp_debugfs_dump(struct file *file, char __user *buf,
  599. size_t count, loff_t *ppos)
  600. {
  601. struct hfi1_pportdata *ppd;
  602. char *tmp;
  603. int ret;
  604. ppd = private2ppd(file);
  605. tmp = kmalloc(PAGE_SIZE, GFP_KERNEL);
  606. if (!tmp)
  607. return -ENOMEM;
  608. ret = qsfp_dump(ppd, tmp, PAGE_SIZE);
  609. if (ret > 0)
  610. ret = simple_read_from_buffer(buf, count, ppos, tmp, ret);
  611. kfree(tmp);
  612. return ret;
  613. }
  614. /* Do an i2c write operation on the chain for the given HFI. */
  615. static ssize_t __i2c_debugfs_write(struct file *file, const char __user *buf,
  616. size_t count, loff_t *ppos, u32 target)
  617. {
  618. struct hfi1_pportdata *ppd;
  619. char *buff;
  620. int ret;
  621. int i2c_addr;
  622. int offset;
  623. int total_written;
  624. ppd = private2ppd(file);
  625. /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
  626. i2c_addr = (*ppos >> 16) & 0xffff;
  627. offset = *ppos & 0xffff;
  628. /* explicitly reject invalid address 0 to catch cp and cat */
  629. if (i2c_addr == 0)
  630. return -EINVAL;
  631. buff = memdup_user(buf, count);
  632. if (IS_ERR(buff))
  633. return PTR_ERR(buff);
  634. total_written = i2c_write(ppd, target, i2c_addr, offset, buff, count);
  635. if (total_written < 0) {
  636. ret = total_written;
  637. goto _free;
  638. }
  639. *ppos += total_written;
  640. ret = total_written;
  641. _free:
  642. kfree(buff);
  643. return ret;
  644. }
  645. /* Do an i2c write operation on chain for HFI 0. */
  646. static ssize_t i2c1_debugfs_write(struct file *file, const char __user *buf,
  647. size_t count, loff_t *ppos)
  648. {
  649. return __i2c_debugfs_write(file, buf, count, ppos, 0);
  650. }
  651. /* Do an i2c write operation on chain for HFI 1. */
  652. static ssize_t i2c2_debugfs_write(struct file *file, const char __user *buf,
  653. size_t count, loff_t *ppos)
  654. {
  655. return __i2c_debugfs_write(file, buf, count, ppos, 1);
  656. }
  657. /* Do an i2c read operation on the chain for the given HFI. */
  658. static ssize_t __i2c_debugfs_read(struct file *file, char __user *buf,
  659. size_t count, loff_t *ppos, u32 target)
  660. {
  661. struct hfi1_pportdata *ppd;
  662. char *buff;
  663. int ret;
  664. int i2c_addr;
  665. int offset;
  666. int total_read;
  667. ppd = private2ppd(file);
  668. /* byte offset format: [offsetSize][i2cAddr][offsetHigh][offsetLow] */
  669. i2c_addr = (*ppos >> 16) & 0xffff;
  670. offset = *ppos & 0xffff;
  671. /* explicitly reject invalid address 0 to catch cp and cat */
  672. if (i2c_addr == 0)
  673. return -EINVAL;
  674. buff = kmalloc(count, GFP_KERNEL);
  675. if (!buff)
  676. return -ENOMEM;
  677. total_read = i2c_read(ppd, target, i2c_addr, offset, buff, count);
  678. if (total_read < 0) {
  679. ret = total_read;
  680. goto _free;
  681. }
  682. *ppos += total_read;
  683. ret = copy_to_user(buf, buff, total_read);
  684. if (ret > 0) {
  685. ret = -EFAULT;
  686. goto _free;
  687. }
  688. ret = total_read;
  689. _free:
  690. kfree(buff);
  691. return ret;
  692. }
  693. /* Do an i2c read operation on chain for HFI 0. */
  694. static ssize_t i2c1_debugfs_read(struct file *file, char __user *buf,
  695. size_t count, loff_t *ppos)
  696. {
  697. return __i2c_debugfs_read(file, buf, count, ppos, 0);
  698. }
  699. /* Do an i2c read operation on chain for HFI 1. */
  700. static ssize_t i2c2_debugfs_read(struct file *file, char __user *buf,
  701. size_t count, loff_t *ppos)
  702. {
  703. return __i2c_debugfs_read(file, buf, count, ppos, 1);
  704. }
  705. /* Do a QSFP write operation on the i2c chain for the given HFI. */
  706. static ssize_t __qsfp_debugfs_write(struct file *file, const char __user *buf,
  707. size_t count, loff_t *ppos, u32 target)
  708. {
  709. struct hfi1_pportdata *ppd;
  710. char *buff;
  711. int ret;
  712. int total_written;
  713. if (*ppos + count > QSFP_PAGESIZE * 4) /* base page + page00-page03 */
  714. return -EINVAL;
  715. ppd = private2ppd(file);
  716. buff = memdup_user(buf, count);
  717. if (IS_ERR(buff))
  718. return PTR_ERR(buff);
  719. total_written = qsfp_write(ppd, target, *ppos, buff, count);
  720. if (total_written < 0) {
  721. ret = total_written;
  722. goto _free;
  723. }
  724. *ppos += total_written;
  725. ret = total_written;
  726. _free:
  727. kfree(buff);
  728. return ret;
  729. }
  730. /* Do a QSFP write operation on i2c chain for HFI 0. */
  731. static ssize_t qsfp1_debugfs_write(struct file *file, const char __user *buf,
  732. size_t count, loff_t *ppos)
  733. {
  734. return __qsfp_debugfs_write(file, buf, count, ppos, 0);
  735. }
  736. /* Do a QSFP write operation on i2c chain for HFI 1. */
  737. static ssize_t qsfp2_debugfs_write(struct file *file, const char __user *buf,
  738. size_t count, loff_t *ppos)
  739. {
  740. return __qsfp_debugfs_write(file, buf, count, ppos, 1);
  741. }
  742. /* Do a QSFP read operation on the i2c chain for the given HFI. */
  743. static ssize_t __qsfp_debugfs_read(struct file *file, char __user *buf,
  744. size_t count, loff_t *ppos, u32 target)
  745. {
  746. struct hfi1_pportdata *ppd;
  747. char *buff;
  748. int ret;
  749. int total_read;
  750. if (*ppos + count > QSFP_PAGESIZE * 4) { /* base page + page00-page03 */
  751. ret = -EINVAL;
  752. goto _return;
  753. }
  754. ppd = private2ppd(file);
  755. buff = kmalloc(count, GFP_KERNEL);
  756. if (!buff) {
  757. ret = -ENOMEM;
  758. goto _return;
  759. }
  760. total_read = qsfp_read(ppd, target, *ppos, buff, count);
  761. if (total_read < 0) {
  762. ret = total_read;
  763. goto _free;
  764. }
  765. *ppos += total_read;
  766. ret = copy_to_user(buf, buff, total_read);
  767. if (ret > 0) {
  768. ret = -EFAULT;
  769. goto _free;
  770. }
  771. ret = total_read;
  772. _free:
  773. kfree(buff);
  774. _return:
  775. return ret;
  776. }
  777. /* Do a QSFP read operation on i2c chain for HFI 0. */
  778. static ssize_t qsfp1_debugfs_read(struct file *file, char __user *buf,
  779. size_t count, loff_t *ppos)
  780. {
  781. return __qsfp_debugfs_read(file, buf, count, ppos, 0);
  782. }
  783. /* Do a QSFP read operation on i2c chain for HFI 1. */
  784. static ssize_t qsfp2_debugfs_read(struct file *file, char __user *buf,
  785. size_t count, loff_t *ppos)
  786. {
  787. return __qsfp_debugfs_read(file, buf, count, ppos, 1);
  788. }
  789. static int __i2c_debugfs_open(struct inode *in, struct file *fp, u32 target)
  790. {
  791. struct hfi1_pportdata *ppd;
  792. int ret;
  793. if (!try_module_get(THIS_MODULE))
  794. return -ENODEV;
  795. ppd = private2ppd(fp);
  796. ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
  797. if (ret) /* failed - release the module */
  798. module_put(THIS_MODULE);
  799. return ret;
  800. }
  801. static int i2c1_debugfs_open(struct inode *in, struct file *fp)
  802. {
  803. return __i2c_debugfs_open(in, fp, 0);
  804. }
  805. static int i2c2_debugfs_open(struct inode *in, struct file *fp)
  806. {
  807. return __i2c_debugfs_open(in, fp, 1);
  808. }
  809. static int __i2c_debugfs_release(struct inode *in, struct file *fp, u32 target)
  810. {
  811. struct hfi1_pportdata *ppd;
  812. ppd = private2ppd(fp);
  813. release_chip_resource(ppd->dd, i2c_target(target));
  814. module_put(THIS_MODULE);
  815. return 0;
  816. }
  817. static int i2c1_debugfs_release(struct inode *in, struct file *fp)
  818. {
  819. return __i2c_debugfs_release(in, fp, 0);
  820. }
  821. static int i2c2_debugfs_release(struct inode *in, struct file *fp)
  822. {
  823. return __i2c_debugfs_release(in, fp, 1);
  824. }
  825. static int __qsfp_debugfs_open(struct inode *in, struct file *fp, u32 target)
  826. {
  827. struct hfi1_pportdata *ppd;
  828. int ret;
  829. if (!try_module_get(THIS_MODULE))
  830. return -ENODEV;
  831. ppd = private2ppd(fp);
  832. ret = acquire_chip_resource(ppd->dd, i2c_target(target), 0);
  833. if (ret) /* failed - release the module */
  834. module_put(THIS_MODULE);
  835. return ret;
  836. }
  837. static int qsfp1_debugfs_open(struct inode *in, struct file *fp)
  838. {
  839. return __qsfp_debugfs_open(in, fp, 0);
  840. }
  841. static int qsfp2_debugfs_open(struct inode *in, struct file *fp)
  842. {
  843. return __qsfp_debugfs_open(in, fp, 1);
  844. }
  845. static int __qsfp_debugfs_release(struct inode *in, struct file *fp, u32 target)
  846. {
  847. struct hfi1_pportdata *ppd;
  848. ppd = private2ppd(fp);
  849. release_chip_resource(ppd->dd, i2c_target(target));
  850. module_put(THIS_MODULE);
  851. return 0;
  852. }
  853. static int qsfp1_debugfs_release(struct inode *in, struct file *fp)
  854. {
  855. return __qsfp_debugfs_release(in, fp, 0);
  856. }
  857. static int qsfp2_debugfs_release(struct inode *in, struct file *fp)
  858. {
  859. return __qsfp_debugfs_release(in, fp, 1);
  860. }
  861. #define DEBUGFS_OPS(nm, readroutine, writeroutine) \
  862. { \
  863. .name = nm, \
  864. .ops = { \
  865. .read = readroutine, \
  866. .write = writeroutine, \
  867. .llseek = generic_file_llseek, \
  868. }, \
  869. }
  870. #define DEBUGFS_XOPS(nm, readf, writef, openf, releasef) \
  871. { \
  872. .name = nm, \
  873. .ops = { \
  874. .read = readf, \
  875. .write = writef, \
  876. .llseek = generic_file_llseek, \
  877. .open = openf, \
  878. .release = releasef \
  879. }, \
  880. }
  881. static const struct counter_info cntr_ops[] = {
  882. DEBUGFS_OPS("counter_names", dev_names_read, NULL),
  883. DEBUGFS_OPS("counters", dev_counters_read, NULL),
  884. DEBUGFS_OPS("portcounter_names", portnames_read, NULL),
  885. };
  886. static const struct counter_info port_cntr_ops[] = {
  887. DEBUGFS_OPS("port%dcounters", portcntrs_debugfs_read, NULL),
  888. DEBUGFS_XOPS("i2c1", i2c1_debugfs_read, i2c1_debugfs_write,
  889. i2c1_debugfs_open, i2c1_debugfs_release),
  890. DEBUGFS_XOPS("i2c2", i2c2_debugfs_read, i2c2_debugfs_write,
  891. i2c2_debugfs_open, i2c2_debugfs_release),
  892. DEBUGFS_OPS("qsfp_dump%d", qsfp_debugfs_dump, NULL),
  893. DEBUGFS_XOPS("qsfp1", qsfp1_debugfs_read, qsfp1_debugfs_write,
  894. qsfp1_debugfs_open, qsfp1_debugfs_release),
  895. DEBUGFS_XOPS("qsfp2", qsfp2_debugfs_read, qsfp2_debugfs_write,
  896. qsfp2_debugfs_open, qsfp2_debugfs_release),
  897. DEBUGFS_OPS("asic_flags", asic_flags_read, asic_flags_write),
  898. DEBUGFS_OPS("dc8051_memory", dc8051_memory_read, NULL),
  899. DEBUGFS_OPS("lcb", debugfs_lcb_read, debugfs_lcb_write),
  900. };
  901. static void *_sdma_cpu_list_seq_start(struct seq_file *s, loff_t *pos)
  902. {
  903. if (*pos >= num_online_cpus())
  904. return NULL;
  905. return pos;
  906. }
  907. static void *_sdma_cpu_list_seq_next(struct seq_file *s, void *v, loff_t *pos)
  908. {
  909. ++*pos;
  910. if (*pos >= num_online_cpus())
  911. return NULL;
  912. return pos;
  913. }
  914. static void _sdma_cpu_list_seq_stop(struct seq_file *s, void *v)
  915. {
  916. /* nothing allocated */
  917. }
  918. static int _sdma_cpu_list_seq_show(struct seq_file *s, void *v)
  919. {
  920. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  921. struct hfi1_devdata *dd = dd_from_dev(ibd);
  922. loff_t *spos = v;
  923. loff_t i = *spos;
  924. sdma_seqfile_dump_cpu_list(s, dd, (unsigned long)i);
  925. return 0;
  926. }
  927. DEBUGFS_SEQ_FILE_OPS(sdma_cpu_list);
  928. DEBUGFS_SEQ_FILE_OPEN(sdma_cpu_list)
  929. DEBUGFS_FILE_OPS(sdma_cpu_list);
  930. #ifdef CONFIG_FAULT_INJECTION
  931. static void *_fault_stats_seq_start(struct seq_file *s, loff_t *pos)
  932. {
  933. struct hfi1_opcode_stats_perctx *opstats;
  934. if (*pos >= ARRAY_SIZE(opstats->stats))
  935. return NULL;
  936. return pos;
  937. }
  938. static void *_fault_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
  939. {
  940. struct hfi1_opcode_stats_perctx *opstats;
  941. ++*pos;
  942. if (*pos >= ARRAY_SIZE(opstats->stats))
  943. return NULL;
  944. return pos;
  945. }
  946. static void _fault_stats_seq_stop(struct seq_file *s, void *v)
  947. {
  948. }
  949. static int _fault_stats_seq_show(struct seq_file *s, void *v)
  950. {
  951. loff_t *spos = v;
  952. loff_t i = *spos, j;
  953. u64 n_packets = 0, n_bytes = 0;
  954. struct hfi1_ibdev *ibd = (struct hfi1_ibdev *)s->private;
  955. struct hfi1_devdata *dd = dd_from_dev(ibd);
  956. struct hfi1_ctxtdata *rcd;
  957. for (j = 0; j < dd->first_dyn_alloc_ctxt; j++) {
  958. rcd = hfi1_rcd_get_by_index(dd, j);
  959. if (rcd) {
  960. n_packets += rcd->opstats->stats[i].n_packets;
  961. n_bytes += rcd->opstats->stats[i].n_bytes;
  962. }
  963. hfi1_rcd_put(rcd);
  964. }
  965. if (!n_packets && !n_bytes)
  966. return SEQ_SKIP;
  967. if (!ibd->fault_opcode->n_rxfaults[i] &&
  968. !ibd->fault_opcode->n_txfaults[i])
  969. return SEQ_SKIP;
  970. seq_printf(s, "%02llx %llu/%llu (faults rx:%llu faults: tx:%llu)\n", i,
  971. (unsigned long long)n_packets,
  972. (unsigned long long)n_bytes,
  973. (unsigned long long)ibd->fault_opcode->n_rxfaults[i],
  974. (unsigned long long)ibd->fault_opcode->n_txfaults[i]);
  975. return 0;
  976. }
  977. DEBUGFS_SEQ_FILE_OPS(fault_stats);
  978. DEBUGFS_SEQ_FILE_OPEN(fault_stats);
  979. DEBUGFS_FILE_OPS(fault_stats);
  980. static void fault_exit_opcode_debugfs(struct hfi1_ibdev *ibd)
  981. {
  982. debugfs_remove_recursive(ibd->fault_opcode->dir);
  983. kfree(ibd->fault_opcode);
  984. ibd->fault_opcode = NULL;
  985. }
  986. static int fault_init_opcode_debugfs(struct hfi1_ibdev *ibd)
  987. {
  988. struct dentry *parent = ibd->hfi1_ibdev_dbg;
  989. ibd->fault_opcode = kzalloc(sizeof(*ibd->fault_opcode), GFP_KERNEL);
  990. if (!ibd->fault_opcode)
  991. return -ENOMEM;
  992. ibd->fault_opcode->attr.interval = 1;
  993. ibd->fault_opcode->attr.require_end = ULONG_MAX;
  994. ibd->fault_opcode->attr.stacktrace_depth = 32;
  995. ibd->fault_opcode->attr.dname = NULL;
  996. ibd->fault_opcode->attr.verbose = 0;
  997. ibd->fault_opcode->fault_by_opcode = false;
  998. ibd->fault_opcode->opcode = 0;
  999. ibd->fault_opcode->mask = 0xff;
  1000. ibd->fault_opcode->dir =
  1001. fault_create_debugfs_attr("fault_opcode",
  1002. parent,
  1003. &ibd->fault_opcode->attr);
  1004. if (IS_ERR(ibd->fault_opcode->dir)) {
  1005. kfree(ibd->fault_opcode);
  1006. return -ENOENT;
  1007. }
  1008. DEBUGFS_SEQ_FILE_CREATE(fault_stats, ibd->fault_opcode->dir, ibd);
  1009. if (!debugfs_create_bool("fault_by_opcode", 0600,
  1010. ibd->fault_opcode->dir,
  1011. &ibd->fault_opcode->fault_by_opcode))
  1012. goto fail;
  1013. if (!debugfs_create_x8("opcode", 0600, ibd->fault_opcode->dir,
  1014. &ibd->fault_opcode->opcode))
  1015. goto fail;
  1016. if (!debugfs_create_x8("mask", 0600, ibd->fault_opcode->dir,
  1017. &ibd->fault_opcode->mask))
  1018. goto fail;
  1019. return 0;
  1020. fail:
  1021. fault_exit_opcode_debugfs(ibd);
  1022. return -ENOMEM;
  1023. }
  1024. static void fault_exit_packet_debugfs(struct hfi1_ibdev *ibd)
  1025. {
  1026. debugfs_remove_recursive(ibd->fault_packet->dir);
  1027. kfree(ibd->fault_packet);
  1028. ibd->fault_packet = NULL;
  1029. }
  1030. static int fault_init_packet_debugfs(struct hfi1_ibdev *ibd)
  1031. {
  1032. struct dentry *parent = ibd->hfi1_ibdev_dbg;
  1033. ibd->fault_packet = kzalloc(sizeof(*ibd->fault_packet), GFP_KERNEL);
  1034. if (!ibd->fault_packet)
  1035. return -ENOMEM;
  1036. ibd->fault_packet->attr.interval = 1;
  1037. ibd->fault_packet->attr.require_end = ULONG_MAX;
  1038. ibd->fault_packet->attr.stacktrace_depth = 32;
  1039. ibd->fault_packet->attr.dname = NULL;
  1040. ibd->fault_packet->attr.verbose = 0;
  1041. ibd->fault_packet->fault_by_packet = false;
  1042. ibd->fault_packet->dir =
  1043. fault_create_debugfs_attr("fault_packet",
  1044. parent,
  1045. &ibd->fault_opcode->attr);
  1046. if (IS_ERR(ibd->fault_packet->dir)) {
  1047. kfree(ibd->fault_packet);
  1048. return -ENOENT;
  1049. }
  1050. if (!debugfs_create_bool("fault_by_packet", 0600,
  1051. ibd->fault_packet->dir,
  1052. &ibd->fault_packet->fault_by_packet))
  1053. goto fail;
  1054. if (!debugfs_create_u64("fault_stats", 0400,
  1055. ibd->fault_packet->dir,
  1056. &ibd->fault_packet->n_faults))
  1057. goto fail;
  1058. return 0;
  1059. fail:
  1060. fault_exit_packet_debugfs(ibd);
  1061. return -ENOMEM;
  1062. }
  1063. static void fault_exit_debugfs(struct hfi1_ibdev *ibd)
  1064. {
  1065. fault_exit_opcode_debugfs(ibd);
  1066. fault_exit_packet_debugfs(ibd);
  1067. }
  1068. static int fault_init_debugfs(struct hfi1_ibdev *ibd)
  1069. {
  1070. int ret = 0;
  1071. ret = fault_init_opcode_debugfs(ibd);
  1072. if (ret)
  1073. return ret;
  1074. ret = fault_init_packet_debugfs(ibd);
  1075. if (ret)
  1076. fault_exit_opcode_debugfs(ibd);
  1077. return ret;
  1078. }
  1079. bool hfi1_dbg_fault_suppress_err(struct hfi1_ibdev *ibd)
  1080. {
  1081. return ibd->fault_suppress_err;
  1082. }
  1083. bool hfi1_dbg_fault_opcode(struct rvt_qp *qp, u32 opcode, bool rx)
  1084. {
  1085. bool ret = false;
  1086. struct hfi1_ibdev *ibd = to_idev(qp->ibqp.device);
  1087. if (!ibd->fault_opcode || !ibd->fault_opcode->fault_by_opcode)
  1088. return false;
  1089. if (ibd->fault_opcode->opcode != (opcode & ibd->fault_opcode->mask))
  1090. return false;
  1091. ret = should_fail(&ibd->fault_opcode->attr, 1);
  1092. if (ret) {
  1093. trace_hfi1_fault_opcode(qp, opcode);
  1094. if (rx)
  1095. ibd->fault_opcode->n_rxfaults[opcode]++;
  1096. else
  1097. ibd->fault_opcode->n_txfaults[opcode]++;
  1098. }
  1099. return ret;
  1100. }
  1101. bool hfi1_dbg_fault_packet(struct hfi1_packet *packet)
  1102. {
  1103. struct rvt_dev_info *rdi = &packet->rcd->ppd->dd->verbs_dev.rdi;
  1104. struct hfi1_ibdev *ibd = dev_from_rdi(rdi);
  1105. bool ret = false;
  1106. if (!ibd->fault_packet || !ibd->fault_packet->fault_by_packet)
  1107. return false;
  1108. ret = should_fail(&ibd->fault_packet->attr, 1);
  1109. if (ret) {
  1110. ++ibd->fault_packet->n_faults;
  1111. trace_hfi1_fault_packet(packet);
  1112. }
  1113. return ret;
  1114. }
  1115. #endif
  1116. void hfi1_dbg_ibdev_init(struct hfi1_ibdev *ibd)
  1117. {
  1118. char name[sizeof("port0counters") + 1];
  1119. char link[10];
  1120. struct hfi1_devdata *dd = dd_from_dev(ibd);
  1121. struct hfi1_pportdata *ppd;
  1122. int unit = dd->unit;
  1123. int i, j;
  1124. if (!hfi1_dbg_root)
  1125. return;
  1126. snprintf(name, sizeof(name), "%s_%d", class_name(), unit);
  1127. snprintf(link, sizeof(link), "%d", unit);
  1128. ibd->hfi1_ibdev_dbg = debugfs_create_dir(name, hfi1_dbg_root);
  1129. if (!ibd->hfi1_ibdev_dbg) {
  1130. pr_warn("create of %s failed\n", name);
  1131. return;
  1132. }
  1133. ibd->hfi1_ibdev_link =
  1134. debugfs_create_symlink(link, hfi1_dbg_root, name);
  1135. if (!ibd->hfi1_ibdev_link) {
  1136. pr_warn("create of %s symlink failed\n", name);
  1137. return;
  1138. }
  1139. DEBUGFS_SEQ_FILE_CREATE(opcode_stats, ibd->hfi1_ibdev_dbg, ibd);
  1140. DEBUGFS_SEQ_FILE_CREATE(ctx_stats, ibd->hfi1_ibdev_dbg, ibd);
  1141. DEBUGFS_SEQ_FILE_CREATE(qp_stats, ibd->hfi1_ibdev_dbg, ibd);
  1142. DEBUGFS_SEQ_FILE_CREATE(sdes, ibd->hfi1_ibdev_dbg, ibd);
  1143. DEBUGFS_SEQ_FILE_CREATE(rcds, ibd->hfi1_ibdev_dbg, ibd);
  1144. DEBUGFS_SEQ_FILE_CREATE(sdma_cpu_list, ibd->hfi1_ibdev_dbg, ibd);
  1145. /* dev counter files */
  1146. for (i = 0; i < ARRAY_SIZE(cntr_ops); i++)
  1147. DEBUGFS_FILE_CREATE(cntr_ops[i].name,
  1148. ibd->hfi1_ibdev_dbg,
  1149. dd,
  1150. &cntr_ops[i].ops, S_IRUGO);
  1151. /* per port files */
  1152. for (ppd = dd->pport, j = 0; j < dd->num_pports; j++, ppd++)
  1153. for (i = 0; i < ARRAY_SIZE(port_cntr_ops); i++) {
  1154. snprintf(name,
  1155. sizeof(name),
  1156. port_cntr_ops[i].name,
  1157. j + 1);
  1158. DEBUGFS_FILE_CREATE(name,
  1159. ibd->hfi1_ibdev_dbg,
  1160. ppd,
  1161. &port_cntr_ops[i].ops,
  1162. !port_cntr_ops[i].ops.write ?
  1163. S_IRUGO : S_IRUGO | S_IWUSR);
  1164. }
  1165. #ifdef CONFIG_FAULT_INJECTION
  1166. debugfs_create_bool("fault_suppress_err", 0600,
  1167. ibd->hfi1_ibdev_dbg,
  1168. &ibd->fault_suppress_err);
  1169. fault_init_debugfs(ibd);
  1170. #endif
  1171. }
  1172. void hfi1_dbg_ibdev_exit(struct hfi1_ibdev *ibd)
  1173. {
  1174. if (!hfi1_dbg_root)
  1175. goto out;
  1176. #ifdef CONFIG_FAULT_INJECTION
  1177. fault_exit_debugfs(ibd);
  1178. #endif
  1179. debugfs_remove(ibd->hfi1_ibdev_link);
  1180. debugfs_remove_recursive(ibd->hfi1_ibdev_dbg);
  1181. out:
  1182. ibd->hfi1_ibdev_dbg = NULL;
  1183. }
  1184. /*
  1185. * driver stats field names, one line per stat, single string. Used by
  1186. * programs like hfistats to print the stats in a way which works for
  1187. * different versions of drivers, without changing program source.
  1188. * if hfi1_ib_stats changes, this needs to change. Names need to be
  1189. * 12 chars or less (w/o newline), for proper display by hfistats utility.
  1190. */
  1191. static const char * const hfi1_statnames[] = {
  1192. /* must be element 0*/
  1193. "KernIntr",
  1194. "ErrorIntr",
  1195. "Tx_Errs",
  1196. "Rcv_Errs",
  1197. "H/W_Errs",
  1198. "NoPIOBufs",
  1199. "CtxtsOpen",
  1200. "RcvLen_Errs",
  1201. "EgrBufFull",
  1202. "EgrHdrFull"
  1203. };
  1204. static void *_driver_stats_names_seq_start(struct seq_file *s, loff_t *pos)
  1205. {
  1206. if (*pos >= ARRAY_SIZE(hfi1_statnames))
  1207. return NULL;
  1208. return pos;
  1209. }
  1210. static void *_driver_stats_names_seq_next(
  1211. struct seq_file *s,
  1212. void *v,
  1213. loff_t *pos)
  1214. {
  1215. ++*pos;
  1216. if (*pos >= ARRAY_SIZE(hfi1_statnames))
  1217. return NULL;
  1218. return pos;
  1219. }
  1220. static void _driver_stats_names_seq_stop(struct seq_file *s, void *v)
  1221. {
  1222. }
  1223. static int _driver_stats_names_seq_show(struct seq_file *s, void *v)
  1224. {
  1225. loff_t *spos = v;
  1226. seq_printf(s, "%s\n", hfi1_statnames[*spos]);
  1227. return 0;
  1228. }
  1229. DEBUGFS_SEQ_FILE_OPS(driver_stats_names);
  1230. DEBUGFS_SEQ_FILE_OPEN(driver_stats_names)
  1231. DEBUGFS_FILE_OPS(driver_stats_names);
  1232. static void *_driver_stats_seq_start(struct seq_file *s, loff_t *pos)
  1233. {
  1234. if (*pos >= ARRAY_SIZE(hfi1_statnames))
  1235. return NULL;
  1236. return pos;
  1237. }
  1238. static void *_driver_stats_seq_next(struct seq_file *s, void *v, loff_t *pos)
  1239. {
  1240. ++*pos;
  1241. if (*pos >= ARRAY_SIZE(hfi1_statnames))
  1242. return NULL;
  1243. return pos;
  1244. }
  1245. static void _driver_stats_seq_stop(struct seq_file *s, void *v)
  1246. {
  1247. }
  1248. static u64 hfi1_sps_ints(void)
  1249. {
  1250. unsigned long flags;
  1251. struct hfi1_devdata *dd;
  1252. u64 sps_ints = 0;
  1253. spin_lock_irqsave(&hfi1_devs_lock, flags);
  1254. list_for_each_entry(dd, &hfi1_dev_list, list) {
  1255. sps_ints += get_all_cpu_total(dd->int_counter);
  1256. }
  1257. spin_unlock_irqrestore(&hfi1_devs_lock, flags);
  1258. return sps_ints;
  1259. }
  1260. static int _driver_stats_seq_show(struct seq_file *s, void *v)
  1261. {
  1262. loff_t *spos = v;
  1263. char *buffer;
  1264. u64 *stats = (u64 *)&hfi1_stats;
  1265. size_t sz = seq_get_buf(s, &buffer);
  1266. if (sz < sizeof(u64))
  1267. return SEQ_SKIP;
  1268. /* special case for interrupts */
  1269. if (*spos == 0)
  1270. *(u64 *)buffer = hfi1_sps_ints();
  1271. else
  1272. *(u64 *)buffer = stats[*spos];
  1273. seq_commit(s, sizeof(u64));
  1274. return 0;
  1275. }
  1276. DEBUGFS_SEQ_FILE_OPS(driver_stats);
  1277. DEBUGFS_SEQ_FILE_OPEN(driver_stats)
  1278. DEBUGFS_FILE_OPS(driver_stats);
  1279. void hfi1_dbg_init(void)
  1280. {
  1281. hfi1_dbg_root = debugfs_create_dir(DRIVER_NAME, NULL);
  1282. if (!hfi1_dbg_root)
  1283. pr_warn("init of debugfs failed\n");
  1284. DEBUGFS_SEQ_FILE_CREATE(driver_stats_names, hfi1_dbg_root, NULL);
  1285. DEBUGFS_SEQ_FILE_CREATE(driver_stats, hfi1_dbg_root, NULL);
  1286. }
  1287. void hfi1_dbg_exit(void)
  1288. {
  1289. debugfs_remove_recursive(hfi1_dbg_root);
  1290. hfi1_dbg_root = NULL;
  1291. }