blob: 0badda6e21eeeacd028303d3470690b50c8feef1 [file] [log] [blame]
Shalabh Jainb0037c02013-01-18 12:47:40 -08001/* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
Dixon Petersond6a20a92012-09-27 15:58:50 -07002 *
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
13#ifdef CONFIG_DEBUG_FS
14
15#include <linux/slab.h>
16#include <linux/debugfs.h>
17#include "diagchar.h"
18#include "diagfwd.h"
Shalabh Jain737fca72012-11-14 21:53:43 -080019#include "diagfwd_bridge.h"
Shalabh Jainb0037c02013-01-18 12:47:40 -080020#include "diagfwd_hsic.h"
Ravi Aravamudhan46df7d22013-06-12 11:57:07 -070021#include "diagmem.h"
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -070022#include "diag_dci.h"
Dixon Petersond6a20a92012-09-27 15:58:50 -070023
24#define DEBUG_BUF_SIZE 4096
25static struct dentry *diag_dbgfs_dent;
26static int diag_dbgfs_table_index;
Dixon Petersonf90f3582013-01-26 18:14:17 -080027static int diag_dbgfs_finished;
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -070028static int diag_dbgfs_dci_data_index;
29static int diag_dbgfs_dci_finished;
Dixon Petersond6a20a92012-09-27 15:58:50 -070030
31static ssize_t diag_dbgfs_read_status(struct file *file, char __user *ubuf,
32 size_t count, loff_t *ppos)
33{
34 char *buf;
35 int ret;
36
37 buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL);
38 if (!buf) {
39 pr_err("diag: %s, Error allocating memory\n", __func__);
40 return -ENOMEM;
41 }
42
43 ret = scnprintf(buf, DEBUG_BUF_SIZE,
44 "modem ch: 0x%x\n"
45 "lpass ch: 0x%x\n"
46 "riva ch: 0x%x\n"
47 "dci ch: 0x%x\n"
48 "modem cntl_ch: 0x%x\n"
49 "lpass cntl_ch: 0x%x\n"
50 "riva cntl_ch: 0x%x\n"
Dixon Peterson3ff84ea2012-12-21 20:16:18 -080051 "modem cmd ch: 0x%x\n"
52 "dci cmd ch: 0x%x\n"
Dixon Petersond6a20a92012-09-27 15:58:50 -070053 "CPU Tools id: %d\n"
54 "Apps only: %d\n"
55 "Apps master: %d\n"
56 "Check Polling Response: %d\n"
57 "polling_reg_flag: %d\n"
58 "uses device tree: %d\n"
Dixon Peterson3ff84ea2012-12-21 20:16:18 -080059 "supports separate cmdrsp: %d\n"
60 "Modem separate cmdrsp: %d\n"
61 "LPASS separate cmdrsp: %d\n"
62 "RIVA separate cmdrsp: %d\n"
Dixon Peterson66fb11b2012-12-04 20:30:54 -080063 "Modem in_busy_1: %d\n"
64 "Modem in_busy_2: %d\n"
65 "LPASS in_busy_1: %d\n"
66 "LPASS in_busy_2: %d\n"
67 "RIVA in_busy_1: %d\n"
68 "RIVA in_busy_2: %d\n"
69 "DCI Modem in_busy_1: %d\n"
Dixon Peterson3ff84ea2012-12-21 20:16:18 -080070 "Modem CMD in_busy_1: %d\n"
71 "Modem CMD in_busy_2: %d\n"
72 "DCI CMD Modem in_busy_1: %d\n"
Dixon Peterson15a6ecb2013-06-25 12:36:33 -070073 "Modem supports STM: %d\n"
74 "LPASS supports STM: %d\n"
75 "RIVA supports STM: %d\n"
76 "Modem STM state: %d\n"
77 "LPASS STM state: %d\n"
78 "RIVA STM state: %d\n"
79 "APPS STM state: %d\n"
80 "Modem STM requested state: %d\n"
81 "LPASS STM requested state: %d\n"
82 "RIVA STM requested state: %d\n"
83 "APPS STM requested state: %d\n"
Ravi Aravamudhan6a2da562013-06-17 16:01:34 -070084 "logging_mode: %d\n"
85 "real_time_mode: %d\n",
Dixon Petersoneecbadb2012-12-10 21:59:28 -080086 (unsigned int)driver->smd_data[MODEM_DATA].ch,
87 (unsigned int)driver->smd_data[LPASS_DATA].ch,
88 (unsigned int)driver->smd_data[WCNSS_DATA].ch,
89 (unsigned int)driver->smd_dci[MODEM_DATA].ch,
90 (unsigned int)driver->smd_cntl[MODEM_DATA].ch,
91 (unsigned int)driver->smd_cntl[LPASS_DATA].ch,
92 (unsigned int)driver->smd_cntl[WCNSS_DATA].ch,
Dixon Peterson3ff84ea2012-12-21 20:16:18 -080093 (unsigned int)driver->smd_cmd[MODEM_DATA].ch,
94 (unsigned int)driver->smd_dci_cmd[MODEM_DATA].ch,
Dixon Petersond6a20a92012-09-27 15:58:50 -070095 chk_config_get_id(),
96 chk_apps_only(),
97 chk_apps_master(),
98 chk_polling_response(),
99 driver->polling_reg_flag,
100 driver->use_device_tree,
Dixon Peterson3ff84ea2012-12-21 20:16:18 -0800101 driver->supports_separate_cmdrsp,
102 driver->separate_cmdrsp[MODEM_DATA],
103 driver->separate_cmdrsp[LPASS_DATA],
104 driver->separate_cmdrsp[WCNSS_DATA],
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800105 driver->smd_data[MODEM_DATA].in_busy_1,
106 driver->smd_data[MODEM_DATA].in_busy_2,
107 driver->smd_data[LPASS_DATA].in_busy_1,
108 driver->smd_data[LPASS_DATA].in_busy_2,
109 driver->smd_data[WCNSS_DATA].in_busy_1,
110 driver->smd_data[WCNSS_DATA].in_busy_2,
111 driver->smd_dci[MODEM_DATA].in_busy_1,
Dixon Peterson3ff84ea2012-12-21 20:16:18 -0800112 driver->smd_cmd[MODEM_DATA].in_busy_1,
113 driver->smd_cmd[MODEM_DATA].in_busy_2,
114 driver->smd_dci_cmd[MODEM_DATA].in_busy_1,
Dixon Peterson15a6ecb2013-06-25 12:36:33 -0700115 driver->peripheral_supports_stm[MODEM_DATA],
116 driver->peripheral_supports_stm[LPASS_DATA],
117 driver->peripheral_supports_stm[WCNSS_DATA],
118 driver->stm_state[MODEM_DATA],
119 driver->stm_state[LPASS_DATA],
120 driver->stm_state[WCNSS_DATA],
121 driver->stm_state[APPS_DATA],
122 driver->stm_state_requested[MODEM_DATA],
123 driver->stm_state_requested[LPASS_DATA],
124 driver->stm_state_requested[WCNSS_DATA],
125 driver->stm_state_requested[APPS_DATA],
Ravi Aravamudhan6a2da562013-06-17 16:01:34 -0700126 driver->logging_mode,
127 driver->real_time_mode);
Dixon Petersond6a20a92012-09-27 15:58:50 -0700128
129#ifdef CONFIG_DIAG_OVER_USB
130 ret += scnprintf(buf+ret, DEBUG_BUF_SIZE,
131 "usb_connected: %d\n",
132 driver->usb_connected);
133#endif
134 ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret);
135
136 kfree(buf);
137 return ret;
138}
139
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -0700140static ssize_t diag_dbgfs_read_dcistats(struct file *file,
141 char __user *ubuf, size_t count, loff_t *ppos)
142{
143 char *buf = NULL;
144 int bytes_remaining, bytes_written = 0, bytes_in_buf = 0, i = 0;
145 struct diag_dci_data_info *temp_data = dci_data_smd;
146 int buf_size = (DEBUG_BUF_SIZE < count) ? DEBUG_BUF_SIZE : count;
147
148 if (diag_dbgfs_dci_finished) {
149 diag_dbgfs_dci_finished = 0;
150 return 0;
151 }
152
153 buf = kzalloc(sizeof(char) * buf_size, GFP_KERNEL);
154 if (ZERO_OR_NULL_PTR(buf)) {
155 pr_err("diag: %s, Error allocating memory\n", __func__);
156 return -ENOMEM;
157 }
158
159 bytes_remaining = buf_size;
160
161 if (diag_dbgfs_dci_data_index == 0) {
162 bytes_written =
163 scnprintf(buf, buf_size,
Ravi Aravamudhan6a2da562013-06-17 16:01:34 -0700164 "number of clients: %d\n"
165 "dci proc active: %d\n"
166 "dci real time vote: %d\n",
167 driver->num_dci_client,
168 (driver->proc_active_mask & DIAG_PROC_DCI) ? 1 : 0,
169 (driver->proc_rt_vote_mask & DIAG_PROC_DCI) ? 1 : 0);
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -0700170 bytes_in_buf += bytes_written;
171 bytes_remaining -= bytes_written;
172#ifdef CONFIG_DIAG_OVER_USB
173 bytes_written = scnprintf(buf+bytes_in_buf, bytes_remaining,
174 "usb_connected: %d\n",
175 driver->usb_connected);
176 bytes_in_buf += bytes_written;
177 bytes_remaining -= bytes_written;
178#endif
179 }
180 temp_data += diag_dbgfs_dci_data_index;
181 for (i = diag_dbgfs_dci_data_index; i < DIAG_DCI_DEBUG_CNT; i++) {
182 if (temp_data->iteration != 0) {
183 bytes_written = scnprintf(
184 buf + bytes_in_buf, bytes_remaining,
185 "i %-20ld\t"
186 "s %-20d\t"
187 "t %-20s\n",
188 temp_data->iteration,
189 temp_data->data_size,
190 temp_data->time_stamp);
191 bytes_in_buf += bytes_written;
192 bytes_remaining -= bytes_written;
193 /* Check if there is room for another entry */
194 if (bytes_remaining < bytes_written)
195 break;
196 }
197 temp_data++;
198 }
199
200 diag_dbgfs_dci_data_index = (i >= DIAG_DCI_DEBUG_CNT) ? 0 : i + 1;
201 bytes_written = simple_read_from_buffer(ubuf, count, ppos, buf,
202 bytes_in_buf);
203 kfree(buf);
204 diag_dbgfs_dci_finished = 1;
205 return bytes_written;
206}
207
Dixon Petersond6a20a92012-09-27 15:58:50 -0700208static ssize_t diag_dbgfs_read_workpending(struct file *file,
209 char __user *ubuf, size_t count, loff_t *ppos)
210{
211 char *buf;
212 int ret;
213
214 buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL);
215 if (!buf) {
216 pr_err("diag: %s, Error allocating memory\n", __func__);
217 return -ENOMEM;
218 }
219
220 ret = scnprintf(buf, DEBUG_BUF_SIZE,
221 "Pending status for work_stucts:\n"
222 "diag_drain_work: %d\n"
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800223 "Modem data diag_read_smd_work: %d\n"
224 "LPASS data diag_read_smd_work: %d\n"
225 "RIVA data diag_read_smd_work: %d\n"
226 "Modem cntl diag_read_smd_work: %d\n"
227 "LPASS cntl diag_read_smd_work: %d\n"
228 "RIVA cntl diag_read_smd_work: %d\n"
229 "Modem dci diag_read_smd_work: %d\n"
230 "Modem data diag_notify_update_smd_work: %d\n"
231 "LPASS data diag_notify_update_smd_work: %d\n"
232 "RIVA data diag_notify_update_smd_work: %d\n"
233 "Modem cntl diag_notify_update_smd_work: %d\n"
234 "LPASS cntl diag_notify_update_smd_work: %d\n"
235 "RIVA cntl diag_notify_update_smd_work: %d\n"
236 "Modem dci diag_notify_update_smd_work: %d\n",
Dixon Petersond6a20a92012-09-27 15:58:50 -0700237 work_pending(&(driver->diag_drain_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800238 work_pending(&(driver->smd_data[MODEM_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800239 diag_read_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800240 work_pending(&(driver->smd_data[LPASS_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800241 diag_read_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800242 work_pending(&(driver->smd_data[WCNSS_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800243 diag_read_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800244 work_pending(&(driver->smd_cntl[MODEM_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800245 diag_read_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800246 work_pending(&(driver->smd_cntl[LPASS_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800247 diag_read_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800248 work_pending(&(driver->smd_cntl[WCNSS_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800249 diag_read_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800250 work_pending(&(driver->smd_dci[MODEM_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800251 diag_read_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800252 work_pending(&(driver->smd_data[MODEM_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800253 diag_notify_update_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800254 work_pending(&(driver->smd_data[LPASS_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800255 diag_notify_update_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800256 work_pending(&(driver->smd_data[WCNSS_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800257 diag_notify_update_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800258 work_pending(&(driver->smd_cntl[MODEM_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800259 diag_notify_update_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800260 work_pending(&(driver->smd_cntl[LPASS_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800261 diag_notify_update_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800262 work_pending(&(driver->smd_cntl[WCNSS_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800263 diag_notify_update_smd_work)),
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800264 work_pending(&(driver->smd_dci[MODEM_DATA].
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800265 diag_notify_update_smd_work)));
Dixon Petersond6a20a92012-09-27 15:58:50 -0700266
267#ifdef CONFIG_DIAG_OVER_USB
268 ret += scnprintf(buf+ret, DEBUG_BUF_SIZE,
269 "diag_proc_hdlc_work: %d\n"
270 "diag_read_work: %d\n",
271 work_pending(&(driver->diag_proc_hdlc_work)),
272 work_pending(&(driver->diag_read_work)));
273#endif
274 ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret);
275
276 kfree(buf);
277 return ret;
278}
279
280static ssize_t diag_dbgfs_read_table(struct file *file, char __user *ubuf,
281 size_t count, loff_t *ppos)
282{
283 char *buf;
284 int ret = 0;
285 int i;
286 int bytes_remaining;
287 int bytes_in_buffer = 0;
288 int bytes_written;
289 int buf_size = (DEBUG_BUF_SIZE < count) ? DEBUG_BUF_SIZE : count;
290
291 if (diag_dbgfs_table_index >= diag_max_reg) {
292 /* Done. Reset to prepare for future requests */
293 diag_dbgfs_table_index = 0;
294 return 0;
295 }
296
297 buf = kzalloc(sizeof(char) * buf_size, GFP_KERNEL);
Ashay Jaiswalf7e265a2013-06-05 13:24:38 +0530298 if (ZERO_OR_NULL_PTR(buf)) {
Dixon Petersond6a20a92012-09-27 15:58:50 -0700299 pr_err("diag: %s, Error allocating memory\n", __func__);
300 return -ENOMEM;
301 }
302
303 bytes_remaining = buf_size;
Dixon Petersoneecbadb2012-12-10 21:59:28 -0800304
305 if (diag_dbgfs_table_index == 0) {
306 bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining,
307 "Client ids: Modem: %d, LPASS: %d, "
308 "WCNSS: %d, APPS: %d\n",
309 MODEM_DATA, LPASS_DATA, WCNSS_DATA, APPS_DATA);
310 bytes_in_buffer += bytes_written;
311 }
312
Dixon Petersond6a20a92012-09-27 15:58:50 -0700313 for (i = diag_dbgfs_table_index; i < diag_max_reg; i++) {
314 /* Do not process empty entries in the table */
315 if (driver->table[i].process_id == 0)
316 continue;
317
318 bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining,
319 "i: %3d, cmd_code: %4x, subsys_id: %4x, "
320 "client: %2d, cmd_code_lo: %4x, "
321 "cmd_code_hi: %4x, process_id: %5d\n",
322 i,
323 driver->table[i].cmd_code,
324 driver->table[i].subsys_id,
325 driver->table[i].client_id,
326 driver->table[i].cmd_code_lo,
327 driver->table[i].cmd_code_hi,
328 driver->table[i].process_id);
329
330 bytes_in_buffer += bytes_written;
331
332 /* Check if there is room to add another table entry */
333 bytes_remaining = buf_size - bytes_in_buffer;
334 if (bytes_remaining < bytes_written)
335 break;
336 }
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800337 diag_dbgfs_table_index = i+1;
Dixon Petersond6a20a92012-09-27 15:58:50 -0700338
339 *ppos = 0;
340 ret = simple_read_from_buffer(ubuf, count, ppos, buf, bytes_in_buffer);
341
342 kfree(buf);
343 return ret;
344}
345
Shalabh Jain737fca72012-11-14 21:53:43 -0800346#ifdef CONFIG_DIAGFWD_BRIDGE_CODE
Ravi Aravamudhan46df7d22013-06-12 11:57:07 -0700347static ssize_t diag_dbgfs_read_mempool(struct file *file, char __user *ubuf,
348 size_t count, loff_t *ppos)
349{
350 char *buf = NULL;
351 int ret = 0, i = 0;
352
353 buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL);
354 if (ZERO_OR_NULL_PTR(buf)) {
355 pr_err("diag: %s, Error allocating memory\n", __func__);
356 return -ENOMEM;
357 }
358
359 ret = scnprintf(buf, DEBUG_BUF_SIZE,
360 "POOL_TYPE_COPY: [0x%p : 0x%p] count = %d\n"
361 "POOL_TYPE_HDLC: [0x%p : 0x%p] count = %d\n"
362 "POOL_TYPE_USER: [0x%p : 0x%p] count = %d\n"
363 "POOL_TYPE_WRITE_STRUCT: [0x%p : 0x%p] count = %d\n",
364 driver->diagpool,
365 diag_pools_array[POOL_COPY_IDX],
366 driver->count,
367 driver->diag_hdlc_pool,
368 diag_pools_array[POOL_HDLC_IDX],
369 driver->count_hdlc_pool,
370 driver->diag_user_pool,
371 diag_pools_array[POOL_USER_IDX],
372 driver->count_user_pool,
373 driver->diag_write_struct_pool,
374 diag_pools_array[POOL_WRITE_STRUCT_IDX],
375 driver->count_write_struct_pool);
376
377 for (i = 0; i < MAX_HSIC_CH; i++) {
378 if (!diag_hsic[i].hsic_inited)
379 continue;
380 ret += scnprintf(buf+ret, DEBUG_BUF_SIZE-ret,
381 "POOL_TYPE_HSIC_%d: [0x%p : 0x%p] count = %d\n",
382 i+1,
383 diag_hsic[i].diag_hsic_pool,
384 diag_pools_array[POOL_HSIC_IDX + i],
385 diag_hsic[i].count_hsic_pool);
386 }
387
388 for (i = 0; i < MAX_HSIC_CH; i++) {
389 if (!diag_hsic[i].hsic_inited)
390 continue;
391 ret += scnprintf(buf+ret, DEBUG_BUF_SIZE-ret,
392 "POOL_TYPE_HSIC_%d_WRITE: [0x%p : 0x%p] count = %d\n",
393 i+1,
394 diag_hsic[i].diag_hsic_write_pool,
395 diag_pools_array[POOL_HSIC_WRITE_IDX + i],
396 diag_hsic[i].count_hsic_write_pool);
397 }
398
399 ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret);
400
401 kfree(buf);
402 return ret;
403}
404#else
405static ssize_t diag_dbgfs_read_mempool(struct file *file, char __user *ubuf,
406 size_t count, loff_t *ppos)
407{
408 char *buf = NULL;
409 int ret = 0;
410
411 buf = kzalloc(sizeof(char) * DEBUG_BUF_SIZE, GFP_KERNEL);
412 if (ZERO_OR_NULL_PTR(buf)) {
413 pr_err("diag: %s, Error allocating memory\n", __func__);
414 return -ENOMEM;
415 }
416
417 ret = scnprintf(buf, DEBUG_BUF_SIZE,
418 "POOL_TYPE_COPY: [0x%p : 0x%p] count = %d\n"
419 "POOL_TYPE_HDLC: [0x%p : 0x%p] count = %d\n"
420 "POOL_TYPE_USER: [0x%p : 0x%p] count = %d\n"
421 "POOL_TYPE_WRITE_STRUCT: [0x%p : 0x%p] count = %d\n",
422 driver->diagpool,
423 diag_pools_array[POOL_COPY_IDX],
424 driver->count,
425 driver->diag_hdlc_pool,
426 diag_pools_array[POOL_HDLC_IDX],
427 driver->count_hdlc_pool,
428 driver->diag_user_pool,
429 diag_pools_array[POOL_USER_IDX],
430 driver->count_user_pool,
431 driver->diag_write_struct_pool,
432 diag_pools_array[POOL_WRITE_STRUCT_IDX],
433 driver->count_write_struct_pool);
434
435 ret = simple_read_from_buffer(ubuf, count, ppos, buf, ret);
436
437 kfree(buf);
438 return ret;
439}
440#endif
441
442#ifdef CONFIG_DIAGFWD_BRIDGE_CODE
Shalabh Jain737fca72012-11-14 21:53:43 -0800443static ssize_t diag_dbgfs_read_bridge(struct file *file, char __user *ubuf,
Dixon Petersond6a20a92012-09-27 15:58:50 -0700444 size_t count, loff_t *ppos)
445{
446 char *buf;
447 int ret;
Dixon Petersonf90f3582013-01-26 18:14:17 -0800448 int i;
449 int bytes_remaining;
450 int bytes_in_buffer = 0;
451 int bytes_written;
452 int buf_size = (DEBUG_BUF_SIZE < count) ? DEBUG_BUF_SIZE : count;
453 int bytes_hsic_inited = 45;
454 int bytes_hsic_not_inited = 410;
Dixon Petersond6a20a92012-09-27 15:58:50 -0700455
Dixon Petersonf90f3582013-01-26 18:14:17 -0800456 if (diag_dbgfs_finished) {
457 diag_dbgfs_finished = 0;
458 return 0;
459 }
460
461 buf = kzalloc(sizeof(char) * buf_size, GFP_KERNEL);
Ashay Jaiswalf7e265a2013-06-05 13:24:38 +0530462 if (ZERO_OR_NULL_PTR(buf)) {
Dixon Petersond6a20a92012-09-27 15:58:50 -0700463 pr_err("diag: %s, Error allocating memory\n", __func__);
464 return -ENOMEM;
465 }
466
Dixon Petersonf90f3582013-01-26 18:14:17 -0800467 bytes_remaining = buf_size;
468
469 /* Only one smux for now */
470 bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining,
471 "Values for SMUX instance: 0\n"
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800472 "smux ch: %d\n"
473 "smux enabled %d\n"
474 "smux in busy %d\n"
Dixon Petersonf90f3582013-01-26 18:14:17 -0800475 "smux connected %d\n\n",
Shalabh Jain737fca72012-11-14 21:53:43 -0800476 driver->lcid,
477 driver->diag_smux_enabled,
478 driver->in_busy_smux,
479 driver->smux_connected);
Dixon Petersond6a20a92012-09-27 15:58:50 -0700480
Dixon Petersonf90f3582013-01-26 18:14:17 -0800481 bytes_in_buffer += bytes_written;
482 bytes_remaining = buf_size - bytes_in_buffer;
Dixon Petersond6a20a92012-09-27 15:58:50 -0700483
Dixon Petersonf90f3582013-01-26 18:14:17 -0800484 bytes_written = scnprintf(buf+bytes_in_buffer, bytes_remaining,
485 "HSIC diag_disconnect_work: %d\n",
486 work_pending(&(driver->diag_disconnect_work)));
487
488 bytes_in_buffer += bytes_written;
489 bytes_remaining = buf_size - bytes_in_buffer;
490
491 for (i = 0; i < MAX_HSIC_CH; i++) {
492 if (diag_hsic[i].hsic_inited) {
493 /* Check if there is room to add another HSIC entry */
494 if (bytes_remaining < bytes_hsic_inited)
495 break;
496 bytes_written = scnprintf(buf+bytes_in_buffer,
497 bytes_remaining,
498 "Values for HSIC Instance: %d\n"
499 "hsic ch: %d\n"
500 "hsic_inited: %d\n"
501 "hsic enabled: %d\n"
502 "hsic_opened: %d\n"
503 "hsic_suspend: %d\n"
504 "in_busy_hsic_read_on_device: %d\n"
505 "in_busy_hsic_write: %d\n"
506 "count_hsic_pool: %d\n"
507 "count_hsic_write_pool: %d\n"
508 "diag_hsic_pool: %x\n"
509 "diag_hsic_write_pool: %x\n"
510 "HSIC write_len: %d\n"
511 "num_hsic_buf_tbl_entries: %d\n"
512 "HSIC usb_connected: %d\n"
513 "HSIC diag_read_work: %d\n"
514 "diag_read_hsic_work: %d\n"
515 "diag_usb_read_complete_work: %d\n\n",
516 i,
517 diag_hsic[i].hsic_ch,
518 diag_hsic[i].hsic_inited,
519 diag_hsic[i].hsic_device_enabled,
520 diag_hsic[i].hsic_device_opened,
521 diag_hsic[i].hsic_suspend,
522 diag_hsic[i].in_busy_hsic_read_on_device,
523 diag_hsic[i].in_busy_hsic_write,
524 diag_hsic[i].count_hsic_pool,
525 diag_hsic[i].count_hsic_write_pool,
526 (unsigned int)diag_hsic[i].diag_hsic_pool,
527 (unsigned int)diag_hsic[i].diag_hsic_write_pool,
528 diag_bridge[i].write_len,
529 diag_hsic[i].num_hsic_buf_tbl_entries,
530 diag_bridge[i].usb_connected,
531 work_pending(&(diag_bridge[i].diag_read_work)),
532 work_pending(&(diag_hsic[i].diag_read_hsic_work)),
533 work_pending(&(diag_bridge[i].usb_read_complete_work)));
534 if (bytes_written > bytes_hsic_inited)
535 bytes_hsic_inited = bytes_written;
536 } else {
537 /* Check if there is room to add another HSIC entry */
538 if (bytes_remaining < bytes_hsic_not_inited)
539 break;
540 bytes_written = scnprintf(buf+bytes_in_buffer,
541 bytes_remaining,
542 "HSIC Instance: %d has not been initialized\n\n",
543 i);
544 if (bytes_written > bytes_hsic_not_inited)
545 bytes_hsic_not_inited = bytes_written;
546 }
547
548 bytes_in_buffer += bytes_written;
549
550 bytes_remaining = buf_size - bytes_in_buffer;
551 }
552
553 *ppos = 0;
554 ret = simple_read_from_buffer(ubuf, count, ppos, buf, bytes_in_buffer);
555
556 diag_dbgfs_finished = 1;
Dixon Petersond6a20a92012-09-27 15:58:50 -0700557 kfree(buf);
558 return ret;
559}
560
Shalabh Jain737fca72012-11-14 21:53:43 -0800561const struct file_operations diag_dbgfs_bridge_ops = {
562 .read = diag_dbgfs_read_bridge,
Dixon Petersond6a20a92012-09-27 15:58:50 -0700563};
564#endif
565
566const struct file_operations diag_dbgfs_status_ops = {
567 .read = diag_dbgfs_read_status,
568};
569
570const struct file_operations diag_dbgfs_table_ops = {
571 .read = diag_dbgfs_read_table,
572};
573
574const struct file_operations diag_dbgfs_workpending_ops = {
575 .read = diag_dbgfs_read_workpending,
576};
577
Ravi Aravamudhan46df7d22013-06-12 11:57:07 -0700578const struct file_operations diag_dbgfs_mempool_ops = {
579 .read = diag_dbgfs_read_mempool,
580};
581
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -0700582const struct file_operations diag_dbgfs_dcistats_ops = {
583 .read = diag_dbgfs_read_dcistats,
584};
585
Dixon Petersond6a20a92012-09-27 15:58:50 -0700586void diag_debugfs_init(void)
587{
588 diag_dbgfs_dent = debugfs_create_dir("diag", 0);
589 if (IS_ERR(diag_dbgfs_dent))
590 return;
591
592 debugfs_create_file("status", 0444, diag_dbgfs_dent, 0,
593 &diag_dbgfs_status_ops);
594
595 debugfs_create_file("table", 0444, diag_dbgfs_dent, 0,
596 &diag_dbgfs_table_ops);
597
598 debugfs_create_file("work_pending", 0444, diag_dbgfs_dent, 0,
599 &diag_dbgfs_workpending_ops);
600
Ravi Aravamudhan46df7d22013-06-12 11:57:07 -0700601 debugfs_create_file("mempool", 0444, diag_dbgfs_dent, 0,
602 &diag_dbgfs_mempool_ops);
603
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -0700604 debugfs_create_file("dci_stats", 0444, diag_dbgfs_dent, 0,
605 &diag_dbgfs_dcistats_ops);
606
Shalabh Jain737fca72012-11-14 21:53:43 -0800607#ifdef CONFIG_DIAGFWD_BRIDGE_CODE
608 debugfs_create_file("bridge", 0444, diag_dbgfs_dent, 0,
609 &diag_dbgfs_bridge_ops);
Dixon Petersond6a20a92012-09-27 15:58:50 -0700610#endif
611
612 diag_dbgfs_table_index = 0;
Dixon Petersonf90f3582013-01-26 18:14:17 -0800613 diag_dbgfs_finished = 0;
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -0700614 diag_dbgfs_dci_data_index = 0;
615 diag_dbgfs_dci_finished = 0;
616
617 /* DCI related structures */
618 dci_data_smd = kzalloc(sizeof(struct diag_dci_data_info) *
619 DIAG_DCI_DEBUG_CNT, GFP_KERNEL);
620 if (ZERO_OR_NULL_PTR(dci_data_smd))
621 pr_warn("diag: could not allocate memory for dci debug info\n");
622
623 mutex_init(&dci_stat_mutex);
Dixon Petersond6a20a92012-09-27 15:58:50 -0700624}
625
626void diag_debugfs_cleanup(void)
627{
628 if (diag_dbgfs_dent) {
629 debugfs_remove_recursive(diag_dbgfs_dent);
630 diag_dbgfs_dent = NULL;
631 }
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -0700632
633 kfree(dci_data_smd);
634 mutex_destroy(&dci_stat_mutex);
Dixon Petersond6a20a92012-09-27 15:58:50 -0700635}
636#else
637void diag_debugfs_init(void) { }
638void diag_debugfs_cleanup(void) { }
639#endif