debugfs.c 35 KB

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