diag_debugfs.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740
  1. /* Copyright (c) 2011-2017, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifdef CONFIG_DEBUG_FS
  13. #include <linux/slab.h>
  14. #include <linux/debugfs.h>
  15. #include "diagchar.h"
  16. #include "diagfwd.h"
  17. #include "diagfwd_bridge.h"
  18. #include "diagfwd_hsic.h"
  19. #include "diagmem.h"
  20. #include "diag_dci.h"
  21. #define DEBUG_BUF_SIZE 4096
  22. static struct dentry *diag_dbgfs_dent;
  23. static int diag_dbgfs_table_index;
  24. static int diag_dbgfs_finished;
  25. static int diag_dbgfs_dci_data_index;
  26. static int diag_dbgfs_dci_finished;
  27. static struct mutex diag_dci_dbgfs_mutex;
  28. static ssize_t diag_dbgfs_read_status(struct file *file, char __user *ubuf,
  29. size_t count, loff_t *ppos)
  30. {
  31. char *buf;
  32. int ret;
  33. unsigned int buf_size;
  34. buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL);
  35. if (!buf) {
  36. pr_err("diag: %s, Error allocating memory\n", __func__);
  37. return -ENOMEM;
  38. }
  39. buf_size = ksize(buf);
  40. ret = scnprintf(buf, buf_size,
  41. "modem ch: 0x%x\n"
  42. "lpass ch: 0x%x\n"
  43. "riva ch: 0x%x\n"
  44. "dci ch: 0x%x\n"
  45. "modem cntl_ch: 0x%x\n"
  46. "lpass cntl_ch: 0x%x\n"
  47. "riva cntl_ch: 0x%x\n"
  48. "modem cmd ch: 0x%x\n"
  49. "dci cmd ch: 0x%x\n"
  50. "CPU Tools id: %d\n"
  51. "Apps only: %d\n"
  52. "Apps master: %d\n"
  53. "Check Polling Response: %d\n"
  54. "polling_reg_flag: %d\n"
  55. "uses device tree: %d\n"
  56. "supports separate cmdrsp: %d\n"
  57. "Modem separate cmdrsp: %d\n"
  58. "LPASS separate cmdrsp: %d\n"
  59. "RIVA separate cmdrsp: %d\n"
  60. "Modem in_busy_1: %d\n"
  61. "Modem in_busy_2: %d\n"
  62. "LPASS in_busy_1: %d\n"
  63. "LPASS in_busy_2: %d\n"
  64. "RIVA in_busy_1: %d\n"
  65. "RIVA in_busy_2: %d\n"
  66. "DCI Modem in_busy_1: %d\n"
  67. "Modem CMD in_busy_1: %d\n"
  68. "Modem CMD in_busy_2: %d\n"
  69. "DCI CMD Modem in_busy_1: %d\n"
  70. "Modem supports STM: %d\n"
  71. "LPASS supports STM: %d\n"
  72. "RIVA supports STM: %d\n"
  73. "Modem STM state: %d\n"
  74. "LPASS STM state: %d\n"
  75. "RIVA STM state: %d\n"
  76. "APPS STM state: %d\n"
  77. "Modem STM requested state: %d\n"
  78. "LPASS STM requested state: %d\n"
  79. "RIVA STM requested state: %d\n"
  80. "APPS STM requested state: %d\n"
  81. "supports apps hdlc encoding: %d\n"
  82. "Modem hdlc encoding: %d\n"
  83. "Lpass hdlc encoding: %d\n"
  84. "RIVA hdlc encoding: %d\n"
  85. "Modem CMD hdlc encoding: %d\n"
  86. "Modem DATA in_buf_1_size: %d\n"
  87. "Modem DATA in_buf_2_size: %d\n"
  88. "ADSP DATA in_buf_1_size: %d\n"
  89. "ADSP DATA in_buf_2_size: %d\n"
  90. "RIVA DATA in_buf_1_size: %d\n"
  91. "RIVA DATA in_buf_2_size: %d\n"
  92. "Modem DATA in_buf_1_raw_size: %d\n"
  93. "Modem DATA in_buf_2_raw_size: %d\n"
  94. "ADSP DATA in_buf_1_raw_size: %d\n"
  95. "ADSP DATA in_buf_2_raw_size: %d\n"
  96. "RIVA DATA in_buf_1_raw_size: %d\n"
  97. "RIVA DATA in_buf_2_raw_size: %d\n"
  98. "Modem CMD in_buf_1_size: %d\n"
  99. "Modem CMD in_buf_1_raw_size: %d\n"
  100. "Modem CNTL in_buf_1_size: %d\n"
  101. "ADSP CNTL in_buf_1_size: %d\n"
  102. "RIVA CNTL in_buf_1_size: %d\n"
  103. "Modem DCI in_buf_1_size: %d\n"
  104. "Modem DCI CMD in_buf_1_size: %d\n"
  105. "Received Feature mask from Modem: %d\n"
  106. "Received Feature mask from LPASS: %d\n"
  107. "Received Feature mask from WCNSS: %d\n"
  108. "logging_mode: %d\n"
  109. "real_time_mode: %d\n",
  110. (unsigned int)driver->smd_data[MODEM_DATA].ch,
  111. (unsigned int)driver->smd_data[LPASS_DATA].ch,
  112. (unsigned int)driver->smd_data[WCNSS_DATA].ch,
  113. (unsigned int)driver->smd_dci[MODEM_DATA].ch,
  114. (unsigned int)driver->smd_cntl[MODEM_DATA].ch,
  115. (unsigned int)driver->smd_cntl[LPASS_DATA].ch,
  116. (unsigned int)driver->smd_cntl[WCNSS_DATA].ch,
  117. (unsigned int)driver->smd_cmd[MODEM_DATA].ch,
  118. (unsigned int)driver->smd_dci_cmd[MODEM_DATA].ch,
  119. chk_config_get_id(),
  120. chk_apps_only(),
  121. chk_apps_master(),
  122. chk_polling_response(),
  123. driver->polling_reg_flag,
  124. driver->use_device_tree,
  125. driver->supports_separate_cmdrsp,
  126. driver->separate_cmdrsp[MODEM_DATA],
  127. driver->separate_cmdrsp[LPASS_DATA],
  128. driver->separate_cmdrsp[WCNSS_DATA],
  129. driver->smd_data[MODEM_DATA].in_busy_1,
  130. driver->smd_data[MODEM_DATA].in_busy_2,
  131. driver->smd_data[LPASS_DATA].in_busy_1,
  132. driver->smd_data[LPASS_DATA].in_busy_2,
  133. driver->smd_data[WCNSS_DATA].in_busy_1,
  134. driver->smd_data[WCNSS_DATA].in_busy_2,
  135. driver->smd_dci[MODEM_DATA].in_busy_1,
  136. driver->smd_cmd[MODEM_DATA].in_busy_1,
  137. driver->smd_cmd[MODEM_DATA].in_busy_2,
  138. driver->smd_dci_cmd[MODEM_DATA].in_busy_1,
  139. driver->peripheral_supports_stm[MODEM_DATA],
  140. driver->peripheral_supports_stm[LPASS_DATA],
  141. driver->peripheral_supports_stm[WCNSS_DATA],
  142. driver->stm_state[MODEM_DATA],
  143. driver->stm_state[LPASS_DATA],
  144. driver->stm_state[WCNSS_DATA],
  145. driver->stm_state[APPS_DATA],
  146. driver->stm_state_requested[MODEM_DATA],
  147. driver->stm_state_requested[LPASS_DATA],
  148. driver->stm_state_requested[WCNSS_DATA],
  149. driver->stm_state_requested[APPS_DATA],
  150. driver->supports_apps_hdlc_encoding,
  151. driver->smd_data[MODEM_DATA].encode_hdlc,
  152. driver->smd_data[LPASS_DATA].encode_hdlc,
  153. driver->smd_data[WCNSS_DATA].encode_hdlc,
  154. driver->smd_cmd[MODEM_DATA].encode_hdlc,
  155. (unsigned int)driver->smd_data[MODEM_DATA].buf_in_1_size,
  156. (unsigned int)driver->smd_data[MODEM_DATA].buf_in_2_size,
  157. (unsigned int)driver->smd_data[LPASS_DATA].buf_in_1_size,
  158. (unsigned int)driver->smd_data[LPASS_DATA].buf_in_2_size,
  159. (unsigned int)driver->smd_data[WCNSS_DATA].buf_in_1_size,
  160. (unsigned int)driver->smd_data[WCNSS_DATA].buf_in_2_size,
  161. (unsigned int)driver->smd_data[MODEM_DATA].buf_in_1_raw_size,
  162. (unsigned int)driver->smd_data[MODEM_DATA].buf_in_2_raw_size,
  163. (unsigned int)driver->smd_data[LPASS_DATA].buf_in_1_raw_size,
  164. (unsigned int)driver->smd_data[LPASS_DATA].buf_in_2_raw_size,
  165. (unsigned int)driver->smd_data[WCNSS_DATA].buf_in_1_raw_size,
  166. (unsigned int)driver->smd_data[WCNSS_DATA].buf_in_2_raw_size,
  167. (unsigned int)driver->smd_cmd[MODEM_DATA].buf_in_1_size,
  168. (unsigned int)driver->smd_cmd[MODEM_DATA].buf_in_1_raw_size,
  169. (unsigned int)driver->smd_cntl[MODEM_DATA].buf_in_1_size,
  170. (unsigned int)driver->smd_cntl[LPASS_DATA].buf_in_1_size,
  171. (unsigned int)driver->smd_cntl[WCNSS_DATA].buf_in_1_size,
  172. (unsigned int)driver->smd_dci[MODEM_DATA].buf_in_1_size,
  173. (unsigned int)driver->smd_dci_cmd[MODEM_DATA].buf_in_1_size,
  174. driver->rcvd_feature_mask[MODEM_DATA],
  175. driver->rcvd_feature_mask[LPASS_DATA],
  176. driver->rcvd_feature_mask[WCNSS_DATA],
  177. driver->logging_mode,
  178. driver->real_time_mode);
  179. #ifdef CONFIG_DIAG_OVER_USB
  180. ret += scnprintf(buf+ret, buf_size-ret,
  181. "usb_connected: %d\n",
  182. driver->usb_connected);
  183. #endif
  184. ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret);
  185. kfree(buf);
  186. return ret;
  187. }
  188. static ssize_t diag_dbgfs_read_dcistats(struct file *file,
  189. char __user *ubuf, size_t count, loff_t *ppos)
  190. {
  191. char *buf = NULL;
  192. unsigned int bytes_remaining, bytes_written = 0;
  193. unsigned int bytes_in_buf = 0, i = 0;
  194. struct diag_dci_data_info *temp_data = dci_data_smd;
  195. unsigned int buf_size;
  196. buf_size = (DEBUG_BUF_SIZE < count) ? DEBUG_BUF_SIZE : count;
  197. if (diag_dbgfs_dci_finished) {
  198. diag_dbgfs_dci_finished = 0;
  199. return 0;
  200. }
  201. buf = kzalloc(sizeof(char) * buf_size, GFP_KERNEL);
  202. if (ZERO_OR_NULL_PTR(buf)) {
  203. pr_err("diag: %s, Error allocating memory\n", __func__);
  204. return -ENOMEM;
  205. }
  206. buf_size = ksize(buf);
  207. bytes_remaining = buf_size;
  208. mutex_lock(&diag_dci_dbgfs_mutex);
  209. if (diag_dbgfs_dci_data_index == 0) {
  210. bytes_written =
  211. scnprintf(buf, buf_size,
  212. "number of clients: %d\n"
  213. "dci proc active: %d\n"
  214. "dci real time vote: %d\n",
  215. driver->num_dci_client,
  216. (driver->proc_active_mask & DIAG_PROC_DCI) ? 1 : 0,
  217. (driver->proc_rt_vote_mask & DIAG_PROC_DCI) ? 1 : 0);
  218. bytes_in_buf += bytes_written;
  219. bytes_remaining -= bytes_written;
  220. #ifdef CONFIG_DIAG_OVER_USB
  221. bytes_written = scnprintf(buf+bytes_in_buf, bytes_remaining,
  222. "usb_connected: %d\n",
  223. driver->usb_connected);
  224. bytes_in_buf += bytes_written;
  225. bytes_remaining -= bytes_written;
  226. #endif
  227. bytes_written = scnprintf(buf+bytes_in_buf,
  228. bytes_remaining,
  229. "dci power: active, relax: %lu, %lu\n",
  230. driver->diag_dev->power.wakeup->
  231. active_count,
  232. driver->diag_dev->
  233. power.wakeup->relax_count);
  234. bytes_in_buf += bytes_written;
  235. bytes_remaining -= bytes_written;
  236. }
  237. temp_data += diag_dbgfs_dci_data_index;
  238. for (i = diag_dbgfs_dci_data_index; i < DIAG_DCI_DEBUG_CNT; i++) {
  239. if (temp_data->iteration != 0) {
  240. bytes_written = scnprintf(
  241. buf + bytes_in_buf, bytes_remaining,
  242. "i %-5ld\t"
  243. "s %-5d\t"
  244. "p %-5d\t"
  245. "c %-5d\t"
  246. "t %-15s\n",
  247. temp_data->iteration,
  248. temp_data->data_size,
  249. temp_data->peripheral,
  250. temp_data->ch_type,
  251. temp_data->time_stamp);
  252. bytes_in_buf += bytes_written;
  253. bytes_remaining -= bytes_written;
  254. /* Check if there is room for another entry */
  255. if (bytes_remaining < bytes_written)
  256. break;
  257. }
  258. temp_data++;
  259. }
  260. diag_dbgfs_dci_data_index = (i >= DIAG_DCI_DEBUG_CNT) ? 0 : i + 1;
  261. mutex_unlock(&diag_dci_dbgfs_mutex);
  262. bytes_written = simple_read_from_buffer(ubuf, count, ppos, buf,
  263. bytes_in_buf);
  264. kfree(buf);
  265. diag_dbgfs_dci_finished = 1;
  266. return bytes_written;
  267. }
  268. static ssize_t diag_dbgfs_read_workpending(struct file *file,
  269. char __user *ubuf, size_t count, loff_t *ppos)
  270. {
  271. char *buf;
  272. int ret;
  273. unsigned int buf_size;
  274. buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL);
  275. if (!buf) {
  276. pr_err("diag: %s, Error allocating memory\n", __func__);
  277. return -ENOMEM;
  278. }
  279. buf_size = ksize(buf);
  280. ret = scnprintf(buf, buf_size,
  281. "Pending status for work_stucts:\n"
  282. "diag_drain_work: %d\n"
  283. "Modem data diag_read_smd_work: %d\n"
  284. "LPASS data diag_read_smd_work: %d\n"
  285. "RIVA data diag_read_smd_work: %d\n"
  286. "Modem cntl diag_read_smd_work: %d\n"
  287. "LPASS cntl diag_read_smd_work: %d\n"
  288. "RIVA cntl diag_read_smd_work: %d\n"
  289. "Modem dci diag_read_smd_work: %d\n"
  290. "Modem data diag_notify_update_smd_work: %d\n"
  291. "LPASS data diag_notify_update_smd_work: %d\n"
  292. "RIVA data diag_notify_update_smd_work: %d\n"
  293. "Modem cntl diag_notify_update_smd_work: %d\n"
  294. "LPASS cntl diag_notify_update_smd_work: %d\n"
  295. "RIVA cntl diag_notify_update_smd_work: %d\n"
  296. "Modem dci diag_notify_update_smd_work: %d\n",
  297. work_pending(&(driver->diag_drain_work)),
  298. work_pending(&(driver->smd_data[MODEM_DATA].
  299. diag_read_smd_work)),
  300. work_pending(&(driver->smd_data[LPASS_DATA].
  301. diag_read_smd_work)),
  302. work_pending(&(driver->smd_data[WCNSS_DATA].
  303. diag_read_smd_work)),
  304. work_pending(&(driver->smd_cntl[MODEM_DATA].
  305. diag_read_smd_work)),
  306. work_pending(&(driver->smd_cntl[LPASS_DATA].
  307. diag_read_smd_work)),
  308. work_pending(&(driver->smd_cntl[WCNSS_DATA].
  309. diag_read_smd_work)),
  310. work_pending(&(driver->smd_dci[MODEM_DATA].
  311. diag_read_smd_work)),
  312. work_pending(&(driver->smd_data[MODEM_DATA].
  313. diag_notify_update_smd_work)),
  314. work_pending(&(driver->smd_data[LPASS_DATA].
  315. diag_notify_update_smd_work)),
  316. work_pending(&(driver->smd_data[WCNSS_DATA].
  317. diag_notify_update_smd_work)),
  318. work_pending(&(driver->smd_cntl[MODEM_DATA].
  319. diag_notify_update_smd_work)),
  320. work_pending(&(driver->smd_cntl[LPASS_DATA].
  321. diag_notify_update_smd_work)),
  322. work_pending(&(driver->smd_cntl[WCNSS_DATA].
  323. diag_notify_update_smd_work)),
  324. work_pending(&(driver->smd_dci[MODEM_DATA].
  325. diag_notify_update_smd_work)));
  326. #ifdef CONFIG_DIAG_OVER_USB
  327. ret += scnprintf(buf+ret, buf_size-ret,
  328. "diag_proc_hdlc_work: %d\n"
  329. "diag_read_work: %d\n",
  330. work_pending(&(driver->diag_proc_hdlc_work)),
  331. work_pending(&(driver->diag_read_work)));
  332. #endif
  333. ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret);
  334. kfree(buf);
  335. return ret;
  336. }
  337. static ssize_t diag_dbgfs_read_table(struct file *file, char __user *ubuf,
  338. size_t count, loff_t *ppos)
  339. {
  340. char *buf;
  341. int ret = 0;
  342. int i;
  343. unsigned int bytes_remaining;
  344. unsigned int bytes_in_buffer = 0;
  345. unsigned int bytes_written;
  346. unsigned int buf_size;
  347. buf_size = (DEBUG_BUF_SIZE < count) ? DEBUG_BUF_SIZE : count;
  348. mutex_lock(&driver->cmd_reg_mutex);
  349. if (diag_dbgfs_table_index >= diag_max_reg) {
  350. /* Done. Reset to prepare for future requests */
  351. diag_dbgfs_table_index = 0;
  352. mutex_unlock(&driver->cmd_reg_mutex);
  353. return 0;
  354. }
  355. buf = kzalloc(sizeof(char) * buf_size, GFP_KERNEL);
  356. if (ZERO_OR_NULL_PTR(buf)) {
  357. pr_err("diag: %s, Error allocating memory\n", __func__);
  358. mutex_unlock(&driver->cmd_reg_mutex);
  359. return -ENOMEM;
  360. }
  361. buf_size = ksize(buf);
  362. bytes_remaining = buf_size;
  363. if (diag_dbgfs_table_index == 0) {
  364. bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining,
  365. "Client ids: Modem: %d, LPASS: %d, "
  366. "WCNSS: %d, APPS: %d\n",
  367. MODEM_DATA, LPASS_DATA, WCNSS_DATA, APPS_DATA);
  368. bytes_in_buffer += bytes_written;
  369. bytes_remaining -= bytes_written;
  370. }
  371. for (i = diag_dbgfs_table_index; i < diag_max_reg; i++) {
  372. /* Do not process empty entries in the table */
  373. if (driver->table[i].process_id == 0)
  374. continue;
  375. bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining,
  376. "i: %3d, cmd_code: %4x, subsys_id: %4x, "
  377. "client: %2d, cmd_code_lo: %4x, "
  378. "cmd_code_hi: %4x, process_id: %5d %s\n",
  379. i,
  380. driver->table[i].cmd_code,
  381. driver->table[i].subsys_id,
  382. driver->table[i].client_id,
  383. driver->table[i].cmd_code_lo,
  384. driver->table[i].cmd_code_hi,
  385. driver->table[i].process_id,
  386. (diag_find_polling_reg(i) ? "<- Polling cmd reg" : ""));
  387. bytes_in_buffer += bytes_written;
  388. /* Check if there is room to add another table entry */
  389. bytes_remaining = buf_size - bytes_in_buffer;
  390. if (bytes_remaining < bytes_written)
  391. break;
  392. }
  393. diag_dbgfs_table_index = i+1;
  394. mutex_unlock(&driver->cmd_reg_mutex);
  395. *ppos = 0;
  396. ret = simple_read_from_buffer(ubuf, count, ppos, buf, bytes_in_buffer);
  397. kfree(buf);
  398. return ret;
  399. }
  400. #ifdef CONFIG_DIAGFWD_BRIDGE_CODE
  401. static ssize_t diag_dbgfs_read_mempool(struct file *file, char __user *ubuf,
  402. size_t count, loff_t *ppos)
  403. {
  404. char *buf = NULL;
  405. int ret = 0, i = 0;
  406. unsigned int buf_size;
  407. buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL);
  408. if (ZERO_OR_NULL_PTR(buf)) {
  409. pr_err("diag: %s, Error allocating memory\n", __func__);
  410. return -ENOMEM;
  411. }
  412. buf_size = ksize(buf);
  413. ret = scnprintf(buf, buf_size,
  414. "POOL_TYPE_COPY: [0x%p : 0x%p] count = %d\n"
  415. "POOL_TYPE_HDLC: [0x%p : 0x%p] count = %d\n"
  416. "POOL_TYPE_USER: [0x%p : 0x%p] count = %d\n"
  417. "POOL_TYPE_WRITE_STRUCT: [0x%p : 0x%p] count = %d\n"
  418. "POOL_TYPE_DCI: [0x%p : 0x%p] count = %d\n",
  419. driver->diagpool,
  420. diag_pools_array[POOL_COPY_IDX],
  421. driver->count,
  422. driver->diag_hdlc_pool,
  423. diag_pools_array[POOL_HDLC_IDX],
  424. driver->count_hdlc_pool,
  425. driver->diag_user_pool,
  426. diag_pools_array[POOL_USER_IDX],
  427. driver->count_user_pool,
  428. driver->diag_write_struct_pool,
  429. diag_pools_array[POOL_WRITE_STRUCT_IDX],
  430. driver->count_write_struct_pool,
  431. driver->diag_dci_pool,
  432. diag_pools_array[POOL_DCI_IDX],
  433. driver->count_dci_pool);
  434. for (i = 0; i < MAX_HSIC_CH; i++) {
  435. if (!diag_hsic[i].hsic_inited)
  436. continue;
  437. ret += scnprintf(buf+ret, buf_size-ret,
  438. "POOL_TYPE_HSIC_%d: [0x%p : 0x%p] count = %d\n",
  439. i+1,
  440. diag_hsic[i].diag_hsic_pool,
  441. diag_pools_array[POOL_HSIC_IDX + i],
  442. diag_hsic[i].count_hsic_pool);
  443. }
  444. for (i = 0; i < MAX_HSIC_CH; i++) {
  445. if (!diag_hsic[i].hsic_inited)
  446. continue;
  447. ret += scnprintf(buf+ret, buf_size-ret,
  448. "POOL_TYPE_HSIC_%d_WRITE: [0x%p : 0x%p] count = %d\n",
  449. i+1,
  450. diag_hsic[i].diag_hsic_write_pool,
  451. diag_pools_array[POOL_HSIC_WRITE_IDX + i],
  452. diag_hsic[i].count_hsic_write_pool);
  453. }
  454. ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret);
  455. kfree(buf);
  456. return ret;
  457. }
  458. #else
  459. static ssize_t diag_dbgfs_read_mempool(struct file *file, char __user *ubuf,
  460. size_t count, loff_t *ppos)
  461. {
  462. char *buf = NULL;
  463. int ret = 0;
  464. unsigned int buf_size;
  465. buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL);
  466. if (ZERO_OR_NULL_PTR(buf)) {
  467. pr_err("diag: %s, Error allocating memory\n", __func__);
  468. return -ENOMEM;
  469. }
  470. buf_size = ksize(buf);
  471. ret = scnprintf(buf, buf_size,
  472. "POOL_TYPE_COPY: [0x%p : 0x%p] count = %d\n"
  473. "POOL_TYPE_HDLC: [0x%p : 0x%p] count = %d\n"
  474. "POOL_TYPE_USER: [0x%p : 0x%p] count = %d\n"
  475. "POOL_TYPE_WRITE_STRUCT: [0x%p : 0x%p] count = %d\n"
  476. "POOL_TYPE_DCI: [0x%p : 0x%p] count = %d\n",
  477. driver->diagpool,
  478. diag_pools_array[POOL_COPY_IDX],
  479. driver->count,
  480. driver->diag_hdlc_pool,
  481. diag_pools_array[POOL_HDLC_IDX],
  482. driver->count_hdlc_pool,
  483. driver->diag_user_pool,
  484. diag_pools_array[POOL_USER_IDX],
  485. driver->count_user_pool,
  486. driver->diag_write_struct_pool,
  487. diag_pools_array[POOL_WRITE_STRUCT_IDX],
  488. driver->count_write_struct_pool,
  489. driver->diag_dci_pool,
  490. diag_pools_array[POOL_DCI_IDX],
  491. driver->count_dci_pool);
  492. ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret);
  493. kfree(buf);
  494. return ret;
  495. }
  496. #endif
  497. #ifdef CONFIG_DIAGFWD_BRIDGE_CODE
  498. static ssize_t diag_dbgfs_read_bridge(struct file *file, char __user *ubuf,
  499. size_t count, loff_t *ppos)
  500. {
  501. char *buf;
  502. int ret;
  503. int i;
  504. unsigned int bytes_remaining;
  505. unsigned int bytes_in_buffer = 0;
  506. unsigned int bytes_written;
  507. unsigned int buf_size;
  508. int bytes_hsic_inited = 45;
  509. int bytes_hsic_not_inited = 410;
  510. buf_size = (DEBUG_BUF_SIZE < count) ? DEBUG_BUF_SIZE : count;
  511. if (diag_dbgfs_finished) {
  512. diag_dbgfs_finished = 0;
  513. return 0;
  514. }
  515. buf = kzalloc(sizeof(char) * buf_size, GFP_KERNEL);
  516. if (ZERO_OR_NULL_PTR(buf)) {
  517. pr_err("diag: %s, Error allocating memory\n", __func__);
  518. return -ENOMEM;
  519. }
  520. buf_size = ksize(buf);
  521. bytes_remaining = buf_size;
  522. /* Only one smux for now */
  523. bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining,
  524. "Values for SMUX instance: 0\n"
  525. "smux ch: %d\n"
  526. "smux enabled %d\n"
  527. "smux in busy %d\n"
  528. "smux connected %d\n\n",
  529. driver->lcid,
  530. driver->diag_smux_enabled,
  531. driver->in_busy_smux,
  532. driver->smux_connected);
  533. bytes_in_buffer += bytes_written;
  534. bytes_remaining = buf_size - bytes_in_buffer;
  535. bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining,
  536. "HSIC diag_disconnect_work: %d\n",
  537. work_pending(&(driver->diag_disconnect_work)));
  538. bytes_in_buffer += bytes_written;
  539. bytes_remaining = buf_size - bytes_in_buffer;
  540. for (i = 0; i < MAX_HSIC_CH; i++) {
  541. if (diag_hsic[i].hsic_inited) {
  542. /* Check if there is room to add another HSIC entry */
  543. if (bytes_remaining < bytes_hsic_inited)
  544. break;
  545. bytes_written = scnprintf(buf+bytes_in_buffer,
  546. bytes_remaining,
  547. "Values for HSIC Instance: %d\n"
  548. "hsic ch: %d\n"
  549. "hsic_inited: %d\n"
  550. "hsic enabled: %d\n"
  551. "hsic_opened: %d\n"
  552. "hsic_suspend: %d\n"
  553. "in_busy_hsic_read_on_device: %d\n"
  554. "in_busy_hsic_write: %d\n"
  555. "count_hsic_pool: %d\n"
  556. "count_hsic_write_pool: %d\n"
  557. "diag_hsic_pool: %p\n"
  558. "diag_hsic_write_pool: %p\n"
  559. "HSIC write_len: %d\n"
  560. "num_hsic_buf_tbl_entries: %d\n"
  561. "HSIC usb_connected: %d\n"
  562. "HSIC diag_read_work: %d\n"
  563. "diag_read_hsic_work: %d\n"
  564. "diag_usb_read_complete_work: %d\n\n",
  565. i,
  566. diag_hsic[i].hsic_ch,
  567. diag_hsic[i].hsic_inited,
  568. diag_hsic[i].hsic_device_enabled,
  569. diag_hsic[i].hsic_device_opened,
  570. diag_hsic[i].hsic_suspend,
  571. diag_hsic[i].in_busy_hsic_read_on_device,
  572. diag_hsic[i].in_busy_hsic_write,
  573. diag_hsic[i].count_hsic_pool,
  574. diag_hsic[i].count_hsic_write_pool,
  575. diag_hsic[i].diag_hsic_pool,
  576. diag_hsic[i].diag_hsic_write_pool,
  577. diag_bridge[i].write_len,
  578. diag_hsic[i].num_hsic_buf_tbl_entries,
  579. diag_bridge[i].usb_connected,
  580. work_pending(&(diag_bridge[i].diag_read_work)),
  581. work_pending(&(diag_hsic[i].diag_read_hsic_work)),
  582. work_pending(&(diag_bridge[i].usb_read_complete_work)));
  583. if (bytes_written > bytes_hsic_inited)
  584. bytes_hsic_inited = bytes_written;
  585. } else {
  586. /* Check if there is room to add another HSIC entry */
  587. if (bytes_remaining < bytes_hsic_not_inited)
  588. break;
  589. bytes_written = scnprintf(buf+bytes_in_buffer,
  590. bytes_remaining,
  591. "HSIC Instance: %d has not been initialized\n\n",
  592. i);
  593. if (bytes_written > bytes_hsic_not_inited)
  594. bytes_hsic_not_inited = bytes_written;
  595. }
  596. bytes_in_buffer += bytes_written;
  597. bytes_remaining = buf_size - bytes_in_buffer;
  598. }
  599. *ppos = 0;
  600. ret = simple_read_from_buffer(ubuf, count, ppos, buf, bytes_in_buffer);
  601. diag_dbgfs_finished = 1;
  602. kfree(buf);
  603. return ret;
  604. }
  605. const struct file_operations diag_dbgfs_bridge_ops = {
  606. .read = diag_dbgfs_read_bridge,
  607. };
  608. #endif
  609. const struct file_operations diag_dbgfs_status_ops = {
  610. .read = diag_dbgfs_read_status,
  611. };
  612. const struct file_operations diag_dbgfs_table_ops = {
  613. .read = diag_dbgfs_read_table,
  614. };
  615. const struct file_operations diag_dbgfs_workpending_ops = {
  616. .read = diag_dbgfs_read_workpending,
  617. };
  618. const struct file_operations diag_dbgfs_mempool_ops = {
  619. .read = diag_dbgfs_read_mempool,
  620. };
  621. const struct file_operations diag_dbgfs_dcistats_ops = {
  622. .read = diag_dbgfs_read_dcistats,
  623. };
  624. void diag_debugfs_init(void)
  625. {
  626. diag_dbgfs_dent = debugfs_create_dir("diag", 0);
  627. if (IS_ERR(diag_dbgfs_dent))
  628. return;
  629. debugfs_create_file("status", 0444, diag_dbgfs_dent, 0,
  630. &diag_dbgfs_status_ops);
  631. debugfs_create_file("table", 0444, diag_dbgfs_dent, 0,
  632. &diag_dbgfs_table_ops);
  633. debugfs_create_file("work_pending", 0444, diag_dbgfs_dent, 0,
  634. &diag_dbgfs_workpending_ops);
  635. debugfs_create_file("mempool", 0444, diag_dbgfs_dent, 0,
  636. &diag_dbgfs_mempool_ops);
  637. debugfs_create_file("dci_stats", 0444, diag_dbgfs_dent, 0,
  638. &diag_dbgfs_dcistats_ops);
  639. #ifdef CONFIG_DIAGFWD_BRIDGE_CODE
  640. debugfs_create_file("bridge", 0444, diag_dbgfs_dent, 0,
  641. &diag_dbgfs_bridge_ops);
  642. #endif
  643. diag_dbgfs_table_index = 0;
  644. diag_dbgfs_finished = 0;
  645. diag_dbgfs_dci_data_index = 0;
  646. diag_dbgfs_dci_finished = 0;
  647. /* DCI related structures */
  648. dci_data_smd = kzalloc(sizeof(struct diag_dci_data_info) *
  649. DIAG_DCI_DEBUG_CNT, GFP_KERNEL);
  650. if (ZERO_OR_NULL_PTR(dci_data_smd))
  651. pr_warn("diag: could not allocate memory for dci debug info\n");
  652. mutex_init(&dci_stat_mutex);
  653. mutex_init(&diag_dci_dbgfs_mutex);
  654. }
  655. void diag_debugfs_cleanup(void)
  656. {
  657. if (diag_dbgfs_dent) {
  658. debugfs_remove_recursive(diag_dbgfs_dent);
  659. diag_dbgfs_dent = NULL;
  660. }
  661. kfree(dci_data_smd);
  662. mutex_destroy(&dci_stat_mutex);
  663. mutex_destroy(&diag_dci_dbgfs_mutex);
  664. }
  665. #else
  666. void diag_debugfs_init(void) { }
  667. void diag_debugfs_cleanup(void) { }
  668. #endif