gsi_dbg.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2015-2021, The Linux Foundation. All rights reserved.
  4. */
  5. #include <linux/completion.h>
  6. #include <linux/debugfs.h>
  7. #include <linux/dma-mapping.h>
  8. #include <linux/random.h>
  9. #include <linux/uaccess.h>
  10. #include <linux/msm_gsi.h>
  11. #include "gsi.h"
  12. #include "gsihal.h"
  13. #define GSI_MAX_MSG_LEN 4096
  14. #define TERR(fmt, args...) \
  15. pr_err("%s:%d " fmt, __func__, __LINE__, ## args)
  16. #define TDBG(fmt, args...) \
  17. pr_debug("%s:%d " fmt, __func__, __LINE__, ## args)
  18. #define PRT_STAT(fmt, args...) \
  19. pr_err(fmt, ## args)
  20. static struct dentry *dent;
  21. static char dbg_buff[GSI_MAX_MSG_LEN];
  22. static void *gsi_ipc_logbuf_low;
  23. static void gsi_wq_print_dp_stats(struct work_struct *work);
  24. static DECLARE_DELAYED_WORK(gsi_print_dp_stats_work, gsi_wq_print_dp_stats);
  25. static void gsi_wq_update_dp_stats(struct work_struct *work);
  26. static DECLARE_DELAYED_WORK(gsi_update_dp_stats_work, gsi_wq_update_dp_stats);
  27. static ssize_t gsi_dump_evt(struct file *file,
  28. const char __user *buf, size_t count, loff_t *ppos)
  29. {
  30. u32 arg1;
  31. u32 arg2;
  32. unsigned long missing;
  33. char *sptr, *token;
  34. uint32_t val;
  35. struct gsi_evt_ctx *ctx;
  36. uint16_t i;
  37. if (count >= sizeof(dbg_buff))
  38. return -EINVAL;
  39. missing = copy_from_user(dbg_buff, buf, count);
  40. if (missing)
  41. return -EFAULT;
  42. dbg_buff[count] = '\0';
  43. sptr = dbg_buff;
  44. token = strsep(&sptr, " ");
  45. if (!token)
  46. return -EINVAL;
  47. if (kstrtou32(token, 0, &arg1))
  48. return -EINVAL;
  49. token = strsep(&sptr, " ");
  50. if (!token)
  51. return -EINVAL;
  52. if (kstrtou32(token, 0, &arg2))
  53. return -EINVAL;
  54. TDBG("arg1=%u arg2=%u\n", arg1, arg2);
  55. if (arg1 >= gsi_ctx->max_ev) {
  56. TERR("invalid evt ring id %u\n", arg1);
  57. return -EINVAL;
  58. }
  59. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_0,
  60. gsi_ctx->per.ee, arg1);
  61. TERR("EV%2d CTX0 0x%x\n", arg1, val);
  62. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_1,
  63. gsi_ctx->per.ee, arg1);
  64. TERR("EV%2d CTX1 0x%x\n", arg1, val);
  65. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_2,
  66. gsi_ctx->per.ee, arg1);
  67. TERR("EV%2d CTX2 0x%x\n", arg1, val);
  68. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_3,
  69. gsi_ctx->per.ee, arg1);
  70. TERR("EV%2d CTX3 0x%x\n", arg1, val);
  71. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_4,
  72. gsi_ctx->per.ee, arg1);
  73. TERR("EV%2d CTX4 0x%x\n", arg1, val);
  74. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_5,
  75. gsi_ctx->per.ee, arg1);
  76. TERR("EV%2d CTX5 0x%x\n", arg1, val);
  77. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_6,
  78. gsi_ctx->per.ee, arg1);
  79. TERR("EV%2d CTX6 0x%x\n", arg1, val);
  80. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_7,
  81. gsi_ctx->per.ee, arg1);
  82. TERR("EV%2d CTX7 0x%x\n", arg1, val);
  83. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_8,
  84. gsi_ctx->per.ee, arg1);
  85. TERR("EV%2d CTX8 0x%x\n", arg1, val);
  86. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_9,
  87. gsi_ctx->per.ee, arg1);
  88. TERR("EV%2d CTX9 0x%x\n", arg1, val);
  89. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_10,
  90. gsi_ctx->per.ee, arg1);
  91. TERR("EV%2d CTX10 0x%x\n", arg1, val);
  92. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_11,
  93. gsi_ctx->per.ee, arg1);
  94. TERR("EV%2d CTX11 0x%x\n", arg1, val);
  95. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_12,
  96. gsi_ctx->per.ee, arg1);
  97. TERR("EV%2d CTX12 0x%x\n", arg1, val);
  98. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_CNTXT_13,
  99. gsi_ctx->per.ee, arg1);
  100. TERR("EV%2d CTX13 0x%x\n", arg1, val);
  101. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_SCRATCH_0,
  102. gsi_ctx->per.ee, arg1);
  103. TERR("EV%2d SCR0 0x%x\n", arg1, val);
  104. val = gsihal_read_reg_nk(GSI_EE_n_EV_CH_k_SCRATCH_1,
  105. gsi_ctx->per.ee, arg1);
  106. TERR("EV%2d SCR1 0x%x\n", arg1, val);
  107. if (arg2) {
  108. ctx = &gsi_ctx->evtr[arg1];
  109. if (ctx->props.ring_base_vaddr) {
  110. for (i = 0; i < ctx->props.ring_len / 16; i++)
  111. TERR("EV%2d (0x%08llx) %08x %08x %08x %08x\n",
  112. arg1, ctx->props.ring_base_addr + i * 16,
  113. *(u32 *)((u8 *)ctx->props.ring_base_vaddr +
  114. i * 16 + 0),
  115. *(u32 *)((u8 *)ctx->props.ring_base_vaddr +
  116. i * 16 + 4),
  117. *(u32 *)((u8 *)ctx->props.ring_base_vaddr +
  118. i * 16 + 8),
  119. *(u32 *)((u8 *)ctx->props.ring_base_vaddr +
  120. i * 16 + 12));
  121. } else {
  122. TERR("No VA supplied for event ring id %u\n", arg1);
  123. }
  124. }
  125. return count;
  126. }
  127. static ssize_t gsi_dump_ch(struct file *file,
  128. const char __user *buf, size_t count, loff_t *ppos)
  129. {
  130. u32 arg1;
  131. u32 arg2;
  132. unsigned long missing;
  133. char *sptr, *token;
  134. struct gsi_chan_ctx *ctx;
  135. uint16_t i;
  136. if (count >= sizeof(dbg_buff))
  137. return -EINVAL;
  138. missing = copy_from_user(dbg_buff, buf, count);
  139. if (missing)
  140. return -EFAULT;
  141. dbg_buff[count] = '\0';
  142. sptr = dbg_buff;
  143. token = strsep(&sptr, " ");
  144. if (!token)
  145. return -EINVAL;
  146. if (kstrtou32(token, 0, &arg1))
  147. return -EINVAL;
  148. token = strsep(&sptr, " ");
  149. if (!token)
  150. return -EINVAL;
  151. if (kstrtou32(token, 0, &arg2))
  152. return -EINVAL;
  153. TDBG("arg1=%u arg2=%u\n", arg1, arg2);
  154. if (arg1 >= gsi_ctx->max_ch) {
  155. TERR("invalid chan id %u\n", arg1);
  156. return -EINVAL;
  157. }
  158. gsi_dump_ch_info(arg1);
  159. if (arg2) {
  160. ctx = &gsi_ctx->chan[arg1];
  161. if (ctx->props.ring_base_vaddr) {
  162. for (i = 0; i < ctx->props.ring_len / 16; i++)
  163. TERR("CH%2d (0x%08llx) %08x %08x %08x %08x\n",
  164. arg1, ctx->props.ring_base_addr + i * 16,
  165. *(u32 *)((u8 *)ctx->props.ring_base_vaddr +
  166. i * 16 + 0),
  167. *(u32 *)((u8 *)ctx->props.ring_base_vaddr +
  168. i * 16 + 4),
  169. *(u32 *)((u8 *)ctx->props.ring_base_vaddr +
  170. i * 16 + 8),
  171. *(u32 *)((u8 *)ctx->props.ring_base_vaddr +
  172. i * 16 + 12));
  173. } else {
  174. TERR("No VA supplied for chan id %u\n", arg1);
  175. }
  176. }
  177. return count;
  178. }
  179. static void gsi_dump_ch_stats(struct gsi_chan_ctx *ctx)
  180. {
  181. if (!ctx->allocated)
  182. return;
  183. PRT_STAT("CH%2d:\n", ctx->props.ch_id);
  184. PRT_STAT("queued=%lu compl=%lu\n",
  185. ctx->stats.queued,
  186. ctx->stats.completed);
  187. PRT_STAT("cb->poll=%lu poll->cb=%lu poll_pend_irq=%lu\n",
  188. ctx->stats.callback_to_poll,
  189. ctx->stats.poll_to_callback,
  190. ctx->stats.poll_pending_irq);
  191. PRT_STAT("invalid_tre_error=%lu\n",
  192. ctx->stats.invalid_tre_error);
  193. PRT_STAT("poll_ok=%lu poll_empty=%lu\n",
  194. ctx->stats.poll_ok, ctx->stats.poll_empty);
  195. if (ctx->evtr)
  196. PRT_STAT("compl_evt=%lu\n",
  197. ctx->evtr->stats.completed);
  198. PRT_STAT("userdata_in_use=%lu\n", ctx->stats.userdata_in_use);
  199. PRT_STAT("ch_below_lo=%lu\n", ctx->stats.dp.ch_below_lo);
  200. PRT_STAT("ch_below_hi=%lu\n", ctx->stats.dp.ch_below_hi);
  201. PRT_STAT("ch_above_hi=%lu\n", ctx->stats.dp.ch_above_hi);
  202. PRT_STAT("time_empty=%lums\n", ctx->stats.dp.empty_time);
  203. PRT_STAT("\n");
  204. }
  205. static ssize_t gsi_dump_stats(struct file *file,
  206. const char __user *buf, size_t count, loff_t *ppos)
  207. {
  208. int ch_id;
  209. int min, max, ret;
  210. ret = kstrtos32_from_user(buf, count, 0, &ch_id);
  211. if (ret)
  212. return ret;
  213. if (ch_id == -1) {
  214. min = 0;
  215. max = gsi_ctx->max_ch;
  216. } else if (ch_id < 0 || ch_id >= gsi_ctx->max_ch ||
  217. !gsi_ctx->chan[ch_id].allocated) {
  218. goto error;
  219. } else {
  220. min = ch_id;
  221. max = ch_id + 1;
  222. }
  223. for (ch_id = min; ch_id < max; ch_id++)
  224. gsi_dump_ch_stats(&gsi_ctx->chan[ch_id]);
  225. return count;
  226. error:
  227. TERR("Usage: echo ch_id > stats. Use -1 for all\n");
  228. return -EINVAL;
  229. }
  230. static int gsi_dbg_create_stats_wq(void)
  231. {
  232. gsi_ctx->dp_stat_wq =
  233. create_singlethread_workqueue("gsi_stat");
  234. if (!gsi_ctx->dp_stat_wq) {
  235. TERR("failed create workqueue\n");
  236. return -ENOMEM;
  237. }
  238. return 0;
  239. }
  240. static void gsi_dbg_destroy_stats_wq(void)
  241. {
  242. cancel_delayed_work_sync(&gsi_update_dp_stats_work);
  243. cancel_delayed_work_sync(&gsi_print_dp_stats_work);
  244. flush_workqueue(gsi_ctx->dp_stat_wq);
  245. destroy_workqueue(gsi_ctx->dp_stat_wq);
  246. gsi_ctx->dp_stat_wq = NULL;
  247. }
  248. static ssize_t gsi_enable_dp_stats(struct file *file,
  249. const char __user *buf, size_t count, loff_t *ppos)
  250. {
  251. int ch_id;
  252. bool enable;
  253. int ret;
  254. if (count >= sizeof(dbg_buff))
  255. goto error;
  256. if (copy_from_user(dbg_buff, buf, count))
  257. goto error;
  258. dbg_buff[count] = '\0';
  259. if (dbg_buff[0] != '+' && dbg_buff[0] != '-')
  260. goto error;
  261. enable = (dbg_buff[0] == '+');
  262. if (kstrtos32(dbg_buff + 1, 0, &ch_id))
  263. goto error;
  264. if (ch_id < 0 || ch_id >= gsi_ctx->max_ch ||
  265. !gsi_ctx->chan[ch_id].allocated) {
  266. goto error;
  267. }
  268. if (gsi_ctx->chan[ch_id].enable_dp_stats == enable) {
  269. TERR("ch_%d: already enabled/disabled\n", ch_id);
  270. return -EINVAL;
  271. }
  272. gsi_ctx->chan[ch_id].enable_dp_stats = enable;
  273. if (enable)
  274. gsi_ctx->num_ch_dp_stats++;
  275. else
  276. gsi_ctx->num_ch_dp_stats--;
  277. if (enable) {
  278. if (gsi_ctx->num_ch_dp_stats == 1) {
  279. ret = gsi_dbg_create_stats_wq();
  280. if (ret)
  281. return ret;
  282. }
  283. cancel_delayed_work_sync(&gsi_update_dp_stats_work);
  284. queue_delayed_work(gsi_ctx->dp_stat_wq,
  285. &gsi_update_dp_stats_work, msecs_to_jiffies(10));
  286. } else if (!enable && gsi_ctx->num_ch_dp_stats == 0) {
  287. gsi_dbg_destroy_stats_wq();
  288. }
  289. return count;
  290. error:
  291. TERR("Usage: echo [+-]ch_id > enable_dp_stats\n");
  292. return -EINVAL;
  293. }
  294. static ssize_t gsi_set_max_elem_dp_stats(struct file *file,
  295. const char __user *buf, size_t count, loff_t *ppos)
  296. {
  297. u32 ch_id;
  298. u32 max_elem;
  299. unsigned long missing;
  300. char *sptr, *token;
  301. if (count >= sizeof(dbg_buff))
  302. goto error;
  303. missing = copy_from_user(dbg_buff, buf, count);
  304. if (missing)
  305. goto error;
  306. dbg_buff[count] = '\0';
  307. sptr = dbg_buff;
  308. token = strsep(&sptr, " ");
  309. if (!token) {
  310. TERR("\n");
  311. goto error;
  312. }
  313. if (kstrtou32(token, 0, &ch_id)) {
  314. TERR("\n");
  315. goto error;
  316. }
  317. token = strsep(&sptr, " ");
  318. if (!token) {
  319. /* get */
  320. if (kstrtou32(dbg_buff, 0, &ch_id))
  321. goto error;
  322. if (ch_id >= gsi_ctx->max_ch)
  323. goto error;
  324. PRT_STAT("ch %d: max_re_expected=%d\n", ch_id,
  325. gsi_ctx->chan[ch_id].props.max_re_expected);
  326. return count;
  327. }
  328. if (kstrtou32(token, 0, &max_elem)) {
  329. TERR("\n");
  330. goto error;
  331. }
  332. TDBG("ch_id=%u max_elem=%u\n", ch_id, max_elem);
  333. if (ch_id >= gsi_ctx->max_ch) {
  334. TERR("invalid chan id %u\n", ch_id);
  335. goto error;
  336. }
  337. gsi_ctx->chan[ch_id].props.max_re_expected = max_elem;
  338. return count;
  339. error:
  340. TERR("Usage: (set) echo <ch_id> <max_elem> > max_elem_dp_stats\n");
  341. TERR("Usage: (get) echo <ch_id> > max_elem_dp_stats\n");
  342. return -EINVAL;
  343. }
  344. static void gsi_wq_print_dp_stats(struct work_struct *work)
  345. {
  346. int ch_id;
  347. for (ch_id = 0; ch_id < gsi_ctx->max_ch; ch_id++) {
  348. if (gsi_ctx->chan[ch_id].print_dp_stats)
  349. gsi_dump_ch_stats(&gsi_ctx->chan[ch_id]);
  350. }
  351. queue_delayed_work(gsi_ctx->dp_stat_wq, &gsi_print_dp_stats_work,
  352. msecs_to_jiffies(1000));
  353. }
  354. static void gsi_dbg_update_ch_dp_stats(struct gsi_chan_ctx *ctx)
  355. {
  356. uint16_t start_hw;
  357. uint16_t end_hw;
  358. uint64_t rp_hw;
  359. uint64_t wp_hw;
  360. int ee = gsi_ctx->per.ee;
  361. uint16_t used_hw;
  362. rp_hw = gsihal_read_reg_nk(GSI_EE_n_GSI_CH_k_CNTXT_4,
  363. ee, ctx->props.ch_id);
  364. rp_hw |= ((uint64_t)gsihal_read_reg_nk(GSI_EE_n_GSI_CH_k_CNTXT_5,
  365. ee, ctx->props.ch_id)) << 32;
  366. wp_hw = gsihal_read_reg_nk(GSI_EE_n_GSI_CH_k_CNTXT_6,
  367. ee, ctx->props.ch_id);
  368. wp_hw |= ((uint64_t)gsihal_read_reg_nk(GSI_EE_n_GSI_CH_k_CNTXT_7,
  369. ee, ctx->props.ch_id)) << 32;
  370. start_hw = gsi_find_idx_from_addr(&ctx->ring, rp_hw);
  371. end_hw = gsi_find_idx_from_addr(&ctx->ring, wp_hw);
  372. if (end_hw >= start_hw)
  373. used_hw = end_hw - start_hw;
  374. else
  375. used_hw = ctx->ring.max_num_elem + 1 - (start_hw - end_hw);
  376. TDBG("ch %d used %d\n", ctx->props.ch_id, used_hw);
  377. gsi_update_ch_dp_stats(ctx, used_hw);
  378. }
  379. static void gsi_wq_update_dp_stats(struct work_struct *work)
  380. {
  381. int ch_id;
  382. for (ch_id = 0; ch_id < gsi_ctx->max_ch; ch_id++) {
  383. if (gsi_ctx->chan[ch_id].allocated &&
  384. gsi_ctx->chan[ch_id].enable_dp_stats)
  385. gsi_dbg_update_ch_dp_stats(&gsi_ctx->chan[ch_id]);
  386. }
  387. queue_delayed_work(gsi_ctx->dp_stat_wq, &gsi_update_dp_stats_work,
  388. msecs_to_jiffies(10));
  389. }
  390. static ssize_t gsi_rst_stats(struct file *file,
  391. const char __user *buf, size_t count, loff_t *ppos)
  392. {
  393. int ch_id;
  394. int min, max, ret;
  395. ret = kstrtos32_from_user(buf, count, 0, &ch_id);
  396. if (ret)
  397. return ret;
  398. if (ch_id == -1) {
  399. min = 0;
  400. max = gsi_ctx->max_ch;
  401. } else if (ch_id < 0 || ch_id >= gsi_ctx->max_ch ||
  402. !gsi_ctx->chan[ch_id].allocated) {
  403. goto error;
  404. } else {
  405. min = ch_id;
  406. max = ch_id + 1;
  407. }
  408. for (ch_id = min; ch_id < max; ch_id++)
  409. memset(&gsi_ctx->chan[ch_id].stats, 0,
  410. sizeof(gsi_ctx->chan[ch_id].stats));
  411. return count;
  412. error:
  413. TERR("Usage: echo ch_id > rst_stats. Use -1 for all\n");
  414. return -EINVAL;
  415. }
  416. static ssize_t gsi_print_dp_stats(struct file *file,
  417. const char __user *buf, size_t count, loff_t *ppos)
  418. {
  419. int ch_id;
  420. bool enable;
  421. int ret;
  422. if (count >= sizeof(dbg_buff))
  423. goto error;
  424. if (copy_from_user(dbg_buff, buf, count))
  425. goto error;
  426. dbg_buff[count] = '\0';
  427. if (dbg_buff[0] != '+' && dbg_buff[0] != '-')
  428. goto error;
  429. enable = (dbg_buff[0] == '+');
  430. if (kstrtos32(dbg_buff + 1, 0, &ch_id))
  431. goto error;
  432. if (ch_id < 0 || ch_id >= gsi_ctx->max_ch ||
  433. !gsi_ctx->chan[ch_id].allocated) {
  434. goto error;
  435. }
  436. if (gsi_ctx->chan[ch_id].print_dp_stats == enable) {
  437. TERR("ch_%d: already enabled/disabled\n", ch_id);
  438. return -EINVAL;
  439. }
  440. gsi_ctx->chan[ch_id].print_dp_stats = enable;
  441. if (enable)
  442. gsi_ctx->num_ch_dp_stats++;
  443. else
  444. gsi_ctx->num_ch_dp_stats--;
  445. if (enable) {
  446. if (gsi_ctx->num_ch_dp_stats == 1) {
  447. ret = gsi_dbg_create_stats_wq();
  448. if (ret)
  449. return ret;
  450. }
  451. cancel_delayed_work_sync(&gsi_print_dp_stats_work);
  452. queue_delayed_work(gsi_ctx->dp_stat_wq,
  453. &gsi_print_dp_stats_work, msecs_to_jiffies(10));
  454. } else if (!enable && gsi_ctx->num_ch_dp_stats == 0) {
  455. gsi_dbg_destroy_stats_wq();
  456. }
  457. return count;
  458. error:
  459. TERR("Usage: echo [+-]ch_id > print_dp_stats\n");
  460. return -EINVAL;
  461. }
  462. static ssize_t gsi_enable_ipc_low(struct file *file,
  463. const char __user *ubuf, size_t count, loff_t *ppos)
  464. {
  465. s8 option = 0;
  466. int ret;
  467. ret = kstrtos8_from_user(ubuf, count, 0, &option);
  468. if (ret)
  469. return ret;
  470. mutex_lock(&gsi_ctx->mlock);
  471. if (option) {
  472. if (!gsi_ipc_logbuf_low) {
  473. gsi_ipc_logbuf_low =
  474. ipc_log_context_create(GSI_IPC_LOG_PAGES,
  475. "gsi_low", 0);
  476. if (gsi_ipc_logbuf_low == NULL)
  477. TERR("failed to get ipc_logbuf_low\n");
  478. }
  479. gsi_ctx->ipc_logbuf_low = gsi_ipc_logbuf_low;
  480. } else {
  481. gsi_ctx->ipc_logbuf_low = NULL;
  482. }
  483. mutex_unlock(&gsi_ctx->mlock);
  484. return count;
  485. }
  486. static ssize_t gsi_read_gsi_hw_profiling_stats(struct file *file,
  487. char __user *buf, size_t count, loff_t *ppos)
  488. {
  489. struct gsi_hw_profiling_data stats;
  490. int nbytes, cnt = 0;
  491. u64 totalCycles = 0, util = 0;
  492. if (gsi_ctx->per.ver < GSI_VER_2_9) {
  493. nbytes = scnprintf(dbg_buff, GSI_MAX_MSG_LEN,
  494. "This feature only support on GSI2.9+\n");
  495. cnt += nbytes;
  496. goto done;
  497. }
  498. if (!gsi_get_hw_profiling_stats(&stats)) {
  499. totalCycles = stats.mcs_busy_cnt + stats.mcs_idle_cnt +
  500. stats.bp_and_pending_cnt;
  501. if (totalCycles != 0)
  502. util = div_u64(
  503. 100 * (stats.mcs_busy_cnt + stats.bp_and_pending_cnt),
  504. totalCycles);
  505. else
  506. util = 0;
  507. nbytes = scnprintf(dbg_buff, GSI_MAX_MSG_LEN,
  508. "bp_count=0x%llx\n"
  509. "bp_and_pending_count=0x%llx\n"
  510. "mcs_busy=0x%llx\n"
  511. "mcs_idle=0x%llx\n"
  512. "total_cycle_count=0x%llx\n"
  513. "utilization_percentage=%llu%%\n",
  514. stats.bp_cnt,
  515. stats.bp_and_pending_cnt,
  516. stats.mcs_busy_cnt,
  517. stats.mcs_idle_cnt,
  518. totalCycles,
  519. util);
  520. cnt += nbytes;
  521. } else {
  522. nbytes = scnprintf(dbg_buff, GSI_MAX_MSG_LEN,
  523. "Fail to read GSI HW Profiling stats\n");
  524. cnt += nbytes;
  525. }
  526. done:
  527. return simple_read_from_buffer(buf, count, ppos, dbg_buff, cnt);
  528. }
  529. static ssize_t gsi_read_gsi_fw_version(struct file *file,
  530. char __user *buf, size_t count, loff_t *ppos)
  531. {
  532. struct gsi_fw_version ver;
  533. int nbytes, cnt = 0;
  534. if (gsi_ctx->per.ver < GSI_VER_2_9) {
  535. nbytes = scnprintf(dbg_buff, GSI_MAX_MSG_LEN,
  536. "This feature only support on GSI2.9+\n");
  537. cnt += nbytes;
  538. goto done;
  539. }
  540. if (!gsi_get_fw_version(&ver)) {
  541. nbytes = scnprintf(dbg_buff, GSI_MAX_MSG_LEN,
  542. "hw=%d\nflavor=%d\nfw=%d\n",
  543. ver.hw,
  544. ver.flavor,
  545. ver.fw);
  546. cnt += nbytes;
  547. } else {
  548. nbytes = scnprintf(dbg_buff, GSI_MAX_MSG_LEN,
  549. "Fail to read GSI FW version\n");
  550. cnt += nbytes;
  551. }
  552. done:
  553. return simple_read_from_buffer(buf, count, ppos, dbg_buff, cnt);
  554. }
  555. static const struct file_operations gsi_ev_dump_ops = {
  556. .write = gsi_dump_evt,
  557. };
  558. static const struct file_operations gsi_ch_dump_ops = {
  559. .write = gsi_dump_ch,
  560. };
  561. static const struct file_operations gsi_stats_ops = {
  562. .write = gsi_dump_stats,
  563. };
  564. static const struct file_operations gsi_enable_dp_stats_ops = {
  565. .write = gsi_enable_dp_stats,
  566. };
  567. static const struct file_operations gsi_max_elem_dp_stats_ops = {
  568. .write = gsi_set_max_elem_dp_stats,
  569. };
  570. static const struct file_operations gsi_rst_stats_ops = {
  571. .write = gsi_rst_stats,
  572. };
  573. static const struct file_operations gsi_print_dp_stats_ops = {
  574. .write = gsi_print_dp_stats,
  575. };
  576. static const struct file_operations gsi_ipc_low_ops = {
  577. .write = gsi_enable_ipc_low,
  578. };
  579. static const struct file_operations gsi_hw_profiling_ops = {
  580. .read = gsi_read_gsi_hw_profiling_stats,
  581. };
  582. static const struct file_operations gsi_ver_ops = {
  583. .read = gsi_read_gsi_fw_version,
  584. };
  585. void gsi_debugfs_init(void)
  586. {
  587. static struct dentry *dfile;
  588. const mode_t write_only_mode = 0220;
  589. const mode_t read_only_mode = 0440;
  590. dent = debugfs_create_dir("gsi", 0);
  591. if (IS_ERR(dent)) {
  592. TERR("fail to create dir\n");
  593. return;
  594. }
  595. dfile = debugfs_create_file("ev_dump", write_only_mode,
  596. dent, 0, &gsi_ev_dump_ops);
  597. if (!dfile || IS_ERR(dfile)) {
  598. TERR("fail to create ev_dump file\n");
  599. goto fail;
  600. }
  601. dfile = debugfs_create_file("ch_dump", write_only_mode,
  602. dent, 0, &gsi_ch_dump_ops);
  603. if (!dfile || IS_ERR(dfile)) {
  604. TERR("fail to create ch_dump file\n");
  605. goto fail;
  606. }
  607. dfile = debugfs_create_file("stats", write_only_mode, dent,
  608. 0, &gsi_stats_ops);
  609. if (!dfile || IS_ERR(dfile)) {
  610. TERR("fail to create stats file\n");
  611. goto fail;
  612. }
  613. dfile = debugfs_create_file("enable_dp_stats", write_only_mode, dent,
  614. 0, &gsi_enable_dp_stats_ops);
  615. if (!dfile || IS_ERR(dfile)) {
  616. TERR("fail to create stats file\n");
  617. goto fail;
  618. }
  619. dfile = debugfs_create_file("max_elem_dp_stats", write_only_mode,
  620. dent, 0, &gsi_max_elem_dp_stats_ops);
  621. if (!dfile || IS_ERR(dfile)) {
  622. TERR("fail to create stats file\n");
  623. goto fail;
  624. }
  625. dfile = debugfs_create_file("rst_stats", write_only_mode,
  626. dent, 0, &gsi_rst_stats_ops);
  627. if (!dfile || IS_ERR(dfile)) {
  628. TERR("fail to create stats file\n");
  629. goto fail;
  630. }
  631. dfile = debugfs_create_file("print_dp_stats",
  632. write_only_mode, dent, 0, &gsi_print_dp_stats_ops);
  633. if (!dfile || IS_ERR(dfile)) {
  634. TERR("fail to create stats file\n");
  635. goto fail;
  636. }
  637. dfile = debugfs_create_file("ipc_low", write_only_mode,
  638. dent, 0, &gsi_ipc_low_ops);
  639. if (!dfile || IS_ERR(dfile)) {
  640. TERR("could not create ipc_low\n");
  641. goto fail;
  642. }
  643. dfile = debugfs_create_file("gsi_hw_profiling_stats", read_only_mode,
  644. dent, 0, &gsi_hw_profiling_ops);
  645. if (!dfile || IS_ERR(dfile)) {
  646. TERR("could not create gsi_hw_profiling_stats\n");
  647. goto fail;
  648. }
  649. dfile = debugfs_create_file("gsi_fw_version", read_only_mode, dent, 0,
  650. &gsi_ver_ops);
  651. if (!dfile || IS_ERR(dfile)) {
  652. TERR("could not create gsi_fw_version\n");
  653. goto fail;
  654. }
  655. return;
  656. fail:
  657. debugfs_remove_recursive(dent);
  658. }