blob: badd12cdf48b930a02a61d9eec01e5898d31e236 [file] [log] [blame]
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -08001/* Copyright (c) 2008-2017, The Linux Foundation. All rights reserved.
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -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#ifndef DIAGCHAR_H
14#define DIAGCHAR_H
15
16#include <linux/init.h>
17#include <linux/module.h>
18#include <linux/mempool.h>
19#include <linux/mutex.h>
20#include <linux/list.h>
21#include <linux/spinlock.h>
22#include <linux/workqueue.h>
23#include <linux/sched.h>
Stephen Boyd73f8c492017-09-07 14:57:14 -070024#include <linux/device.h>
Hardik Aryad6da1cb2017-11-23 20:40:55 +053025#include <soc/qcom/smd.h>
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070026#include <linux/atomic.h>
27#include "diagfwd_bridge.h"
28
Mohit Aggarwalb8474a42017-10-12 14:22:05 +053029#define THRESHOLD_CLIENT_LIMIT 50
30
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070031/* Size of the USB buffers used for read and write*/
32#define USB_MAX_OUT_BUF 4096
33#define APPS_BUF_SIZE 4096
34#define IN_BUF_SIZE 16384
35#define MAX_SYNC_OBJ_NAME_SIZE 32
36
37#define DIAG_MAX_REQ_SIZE (16 * 1024)
38#define DIAG_MAX_RSP_SIZE (16 * 1024)
Mohit Aggarwalae6ddf52017-10-18 21:25:22 +053039#define APF_DIAG_PADDING 0
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070040/*
41 * In the worst case, the HDLC buffer can be atmost twice the size of the
42 * original packet. Add 3 bytes for 16 bit CRC (2 bytes) and a delimiter
43 * (1 byte)
44 */
45#define DIAG_MAX_HDLC_BUF_SIZE ((DIAG_MAX_REQ_SIZE * 2) + 3)
46
47/* The header of callback data type has remote processor token (of type int) */
48#define CALLBACK_HDR_SIZE (sizeof(int))
49#define CALLBACK_BUF_SIZE (DIAG_MAX_REQ_SIZE + CALLBACK_HDR_SIZE)
50
51#define MAX_SSID_PER_RANGE 200
52
53#define ALL_PROC -1
54
55#define REMOTE_DATA 4
56
57#define USER_SPACE_DATA 16384
58
59#define DIAG_CTRL_MSG_LOG_MASK 9
60#define DIAG_CTRL_MSG_EVENT_MASK 10
61#define DIAG_CTRL_MSG_F3_MASK 11
62#define CONTROL_CHAR 0x7E
63
Manoj Prabhu B571cf422017-08-08 19:01:41 +053064#define DIAG_ID_ROOT_STRING "root"
65
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070066#define DIAG_CON_APSS (0x0001) /* Bit mask for APSS */
67#define DIAG_CON_MPSS (0x0002) /* Bit mask for MPSS */
68#define DIAG_CON_LPASS (0x0004) /* Bit mask for LPASS */
69#define DIAG_CON_WCNSS (0x0008) /* Bit mask for WCNSS */
70#define DIAG_CON_SENSORS (0x0010) /* Bit mask for Sensors */
Manoj Prabhu B571cf422017-08-08 19:01:41 +053071#define DIAG_CON_WDSP (0x0020) /* Bit mask for WDSP */
72#define DIAG_CON_CDSP (0x0040) /* Bit mask for CDSP */
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070073
Manoj Prabhu B571cf422017-08-08 19:01:41 +053074#define DIAG_CON_UPD_WLAN (0x1000) /*Bit mask for WLAN PD*/
Manoj Prabhu B90e1f502017-11-02 20:01:45 +053075#define DIAG_CON_UPD_AUDIO (0x2000) /*Bit mask for AUDIO PD*/
76#define DIAG_CON_UPD_SENSORS (0x4000) /*Bit mask for SENSORS PD*/
77
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070078#define DIAG_CON_NONE (0x0000) /* Bit mask for No SS*/
79#define DIAG_CON_ALL (DIAG_CON_APSS | DIAG_CON_MPSS \
80 | DIAG_CON_LPASS | DIAG_CON_WCNSS \
Sreelakshmi Gownipalli588a31d2016-11-02 13:33:43 -070081 | DIAG_CON_SENSORS | DIAG_CON_WDSP \
82 | DIAG_CON_CDSP)
Manoj Prabhu B90e1f502017-11-02 20:01:45 +053083#define DIAG_CON_UPD_ALL (DIAG_CON_UPD_WLAN \
84 | DIAG_CON_UPD_AUDIO \
85 | DIAG_CON_UPD_SENSORS)
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070086
87#define DIAG_STM_MODEM 0x01
88#define DIAG_STM_LPASS 0x02
89#define DIAG_STM_WCNSS 0x04
90#define DIAG_STM_APPS 0x08
91#define DIAG_STM_SENSORS 0x10
92#define DIAG_STM_WDSP 0x20
Sreelakshmi Gownipalli588a31d2016-11-02 13:33:43 -070093#define DIAG_STM_CDSP 0x40
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070094
95#define INVALID_PID -1
96#define DIAG_CMD_FOUND 1
97#define DIAG_CMD_NOT_FOUND 0
98#define DIAG_CMD_POLLING 1
99#define DIAG_CMD_NOT_POLLING 0
100#define DIAG_CMD_ADD 1
101#define DIAG_CMD_REMOVE 0
102
103#define DIAG_CMD_VERSION 0
104#define DIAG_CMD_ERROR 0x13
105#define DIAG_CMD_DOWNLOAD 0x3A
106#define DIAG_CMD_DIAG_SUBSYS 0x4B
107#define DIAG_CMD_LOG_CONFIG 0x73
108#define DIAG_CMD_LOG_ON_DMND 0x78
109#define DIAG_CMD_EXT_BUILD 0x7c
110#define DIAG_CMD_MSG_CONFIG 0x7D
111#define DIAG_CMD_GET_EVENT_MASK 0x81
112#define DIAG_CMD_SET_EVENT_MASK 0x82
113#define DIAG_CMD_EVENT_TOGGLE 0x60
114#define DIAG_CMD_NO_SUBSYS 0xFF
115#define DIAG_CMD_STATUS 0x0C
116#define DIAG_SS_WCDMA 0x04
117#define DIAG_CMD_QUERY_CALL 0x0E
118#define DIAG_SS_GSM 0x08
119#define DIAG_CMD_QUERY_TMC 0x02
120#define DIAG_SS_TDSCDMA 0x57
121#define DIAG_CMD_TDSCDMA_STATUS 0x0E
122#define DIAG_CMD_DIAG_SUBSYS_DELAY 0x80
123
124#define DIAG_SS_DIAG 0x12
125#define DIAG_SS_PARAMS 0x32
126#define DIAG_SS_FILE_READ_MODEM 0x0816
127#define DIAG_SS_FILE_READ_ADSP 0x0E10
128#define DIAG_SS_FILE_READ_WCNSS 0x141F
129#define DIAG_SS_FILE_READ_SLPI 0x01A18
130#define DIAG_SS_FILE_READ_APPS 0x020F
131
132#define DIAG_DIAG_MAX_PKT_SZ 0x55
133#define DIAG_DIAG_STM 0x214
134#define DIAG_DIAG_POLL 0x03
135#define DIAG_DEL_RSP_WRAP 0x04
136#define DIAG_DEL_RSP_WRAP_CNT 0x05
137#define DIAG_EXT_MOBILE_ID 0x06
138#define DIAG_GET_TIME_API 0x21B
139#define DIAG_SET_TIME_API 0x21C
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800140#define DIAG_GET_DIAG_ID 0x222
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700141#define DIAG_SWITCH_COMMAND 0x081B
142#define DIAG_BUFFERING_MODE 0x080C
143
144#define DIAG_CMD_OP_LOG_DISABLE 0
145#define DIAG_CMD_OP_GET_LOG_RANGE 1
146#define DIAG_CMD_OP_SET_LOG_MASK 3
147#define DIAG_CMD_OP_GET_LOG_MASK 4
148
149#define DIAG_CMD_OP_GET_SSID_RANGE 1
150#define DIAG_CMD_OP_GET_BUILD_MASK 2
151#define DIAG_CMD_OP_GET_MSG_MASK 3
152#define DIAG_CMD_OP_SET_MSG_MASK 4
153#define DIAG_CMD_OP_SET_ALL_MSG_MASK 5
154
155#define DIAG_CMD_OP_GET_MSG_ALLOC 0x33
156#define DIAG_CMD_OP_GET_MSG_DROP 0x30
157#define DIAG_CMD_OP_RESET_MSG_STATS 0x2F
158#define DIAG_CMD_OP_GET_LOG_ALLOC 0x31
159#define DIAG_CMD_OP_GET_LOG_DROP 0x2C
160#define DIAG_CMD_OP_RESET_LOG_STATS 0x2B
161#define DIAG_CMD_OP_GET_EVENT_ALLOC 0x32
162#define DIAG_CMD_OP_GET_EVENT_DROP 0x2E
163#define DIAG_CMD_OP_RESET_EVENT_STATS 0x2D
164
165#define DIAG_CMD_OP_HDLC_DISABLE 0x218
166
167#define BAD_PARAM_RESPONSE_MESSAGE 20
168
169#define PERSIST_TIME_SUCCESS 0
170#define PERSIST_TIME_FAILURE 1
171#define PERSIST_TIME_NOT_SUPPORTED 2
172
173#define MODE_CMD 41
174#define RESET_ID 2
175
176#define PKT_DROP 0
177#define PKT_ALLOC 1
178#define PKT_RESET 2
179
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530180#define FEATURE_MASK_LEN 4
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700181
182#define DIAG_MD_NONE 0
183#define DIAG_MD_PERIPHERAL 1
184
185/*
186 * The status bit masks when received in a signal handler are to be
187 * used in conjunction with the peripheral list bit mask to determine the
188 * status for a peripheral. For instance, 0x00010002 would denote an open
189 * status on the MPSS
190 */
191#define DIAG_STATUS_OPEN (0x00010000) /* DCI channel open status mask */
192#define DIAG_STATUS_CLOSED (0x00020000) /* DCI channel closed status mask */
193
194#define MODE_NONREALTIME 0
195#define MODE_REALTIME 1
196#define MODE_UNKNOWN 2
197
198#define DIAG_BUFFERING_MODE_STREAMING 0
199#define DIAG_BUFFERING_MODE_THRESHOLD 1
200#define DIAG_BUFFERING_MODE_CIRCULAR 2
201
202#define DIAG_MIN_WM_VAL 0
203#define DIAG_MAX_WM_VAL 100
204
205#define DEFAULT_LOW_WM_VAL 15
206#define DEFAULT_HIGH_WM_VAL 85
207
208#define TYPE_DATA 0
209#define TYPE_CNTL 1
210#define TYPE_DCI 2
211#define TYPE_CMD 3
212#define TYPE_DCI_CMD 4
213#define NUM_TYPES 5
214
215#define PERIPHERAL_MODEM 0
216#define PERIPHERAL_LPASS 1
217#define PERIPHERAL_WCNSS 2
218#define PERIPHERAL_SENSORS 3
219#define PERIPHERAL_WDSP 4
Sreelakshmi Gownipalli588a31d2016-11-02 13:33:43 -0700220#define PERIPHERAL_CDSP 5
221#define NUM_PERIPHERALS 6
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700222#define APPS_DATA (NUM_PERIPHERALS)
223
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530224#define UPD_WLAN 7
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530225#define UPD_AUDIO 8
226#define UPD_SENSORS 9
227#define NUM_UPD 3
228
229#define MAX_PERIPHERAL_UPD 2
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700230/* Number of sessions possible in Memory Device Mode. +1 for Apps data */
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530231#define NUM_MD_SESSIONS (NUM_PERIPHERALS \
232 + NUM_UPD + 1)
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700233
234#define MD_PERIPHERAL_MASK(x) (1 << x)
235
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530236#define MD_PERIPHERAL_PD_MASK(x, peripheral, pd_mask) \
237do { \
238fwd_info = &peripheral_info[x][peripheral]; \
239for (i = 0; i <= fwd_info->num_pd - 2; i++) \
240 pd_mask |= (1 << fwd_info->upd_diag_id[i].pd);\
241} while (0)
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530242
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700243/*
244 * Number of stm processors includes all the peripherals and
245 * apps.Added 1 below to indicate apps
246 */
247#define NUM_STM_PROCESSORS (NUM_PERIPHERALS + 1)
248/*
249 * Indicates number of peripherals that can support DCI and Apps
250 * processor. This doesn't mean that a peripheral has the
251 * feature.
252 */
253#define NUM_DCI_PERIPHERALS (NUM_PERIPHERALS + 1)
254
255#define DIAG_PROC_DCI 1
256#define DIAG_PROC_MEMORY_DEVICE 2
257
258/* Flags to vote the DCI or Memory device process up or down
259 * when it becomes active or inactive.
260 */
261#define VOTE_DOWN 0
262#define VOTE_UP 1
263
264#define DIAG_TS_SIZE 50
265
266#define DIAG_MDM_BUF_SIZE 2048
267/* The Maximum request size is 2k + DCI header + footer (6 bytes) */
268#define DIAG_MDM_DCI_BUF_SIZE (2048 + 6)
269
270#define DIAG_LOCAL_PROC 0
271
272#ifndef CONFIG_DIAGFWD_BRIDGE_CODE
273/* Local Processor only */
274#define DIAG_NUM_PROC 1
275#else
276/* Local Processor + Remote Devices */
277#define DIAG_NUM_PROC (1 + NUM_REMOTE_DEV)
278#endif
279
280#define DIAG_WS_DCI 0
281#define DIAG_WS_MUX 1
282
283#define DIAG_DATA_TYPE 1
284#define DIAG_CNTL_TYPE 2
285#define DIAG_DCI_TYPE 3
286
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800287/*
288 * List of diag ids
289 * 0 is reserved for unknown diag id, 1 for apps, diag ids
290 * for remaining pds are assigned dynamically.
291 */
292#define DIAG_ID_UNKNOWN 0
293#define DIAG_ID_APPS 1
294
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700295/* List of remote processor supported */
296enum remote_procs {
297 MDM = 1,
298 MDM2 = 2,
299 QSC = 5,
300};
301
302struct diag_pkt_header_t {
303 uint8_t cmd_code;
304 uint8_t subsys_id;
305 uint16_t subsys_cmd_code;
306} __packed;
307
308struct diag_cmd_ext_mobile_rsp_t {
309 struct diag_pkt_header_t header;
310 uint8_t version;
311 uint8_t padding[3];
312 uint32_t family;
313 uint32_t chip_id;
314} __packed;
315
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800316struct diag_cmd_diag_id_query_req_t {
317 struct diag_pkt_header_t header;
318 uint8_t version;
319} __packed;
320
321struct diag_id_tbl_t {
322 struct list_head link;
323 uint8_t diag_id;
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530324 uint8_t pd_val;
325 uint8_t peripheral;
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800326 char *process_name;
327} __packed;
328struct diag_id_t {
329 uint8_t diag_id;
330 uint8_t len;
331 char *process_name;
332} __packed;
333
334struct diag_cmd_diag_id_query_rsp_t {
335 struct diag_pkt_header_t header;
336 uint8_t version;
337 uint8_t num_entries;
338 struct diag_id_t entry;
339} __packed;
340
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700341struct diag_cmd_time_sync_query_req_t {
342 struct diag_pkt_header_t header;
343 uint8_t version;
344};
345
346struct diag_cmd_time_sync_query_rsp_t {
347 struct diag_pkt_header_t header;
348 uint8_t version;
349 uint8_t time_api;
350};
351
352struct diag_cmd_time_sync_switch_req_t {
353 struct diag_pkt_header_t header;
354 uint8_t version;
355 uint8_t time_api;
356 uint8_t persist_time;
357};
358
359struct diag_cmd_time_sync_switch_rsp_t {
360 struct diag_pkt_header_t header;
361 uint8_t version;
362 uint8_t time_api;
363 uint8_t time_api_status;
364 uint8_t persist_time_status;
365};
366
367struct diag_cmd_reg_entry_t {
368 uint16_t cmd_code;
369 uint16_t subsys_id;
370 uint16_t cmd_code_lo;
371 uint16_t cmd_code_hi;
372} __packed;
373
374struct diag_cmd_reg_t {
375 struct list_head link;
376 struct diag_cmd_reg_entry_t entry;
377 uint8_t proc;
378 int pid;
379};
380
381/*
382 * @sync_obj_name: name of the synchronization object associated with this proc
383 * @count: number of entries in the bind
384 * @entries: the actual packet registrations
385 */
386struct diag_cmd_reg_tbl_t {
387 char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE];
388 uint32_t count;
389 struct diag_cmd_reg_entry_t *entries;
390};
391
392struct diag_client_map {
393 char name[20];
394 int pid;
395};
396
397struct real_time_vote_t {
398 int client_id;
399 uint16_t proc;
400 uint8_t real_time_vote;
401} __packed;
402
403struct real_time_query_t {
404 int real_time;
405 int proc;
406} __packed;
407
408struct diag_buffering_mode_t {
409 uint8_t peripheral;
410 uint8_t mode;
411 uint8_t high_wm_val;
412 uint8_t low_wm_val;
413} __packed;
414
415struct diag_callback_reg_t {
416 int proc;
417} __packed;
418
419struct diag_ws_ref_t {
420 int ref_count;
421 int copy_count;
422 spinlock_t lock;
423};
424
425/* This structure is defined in USB header file */
426#ifndef CONFIG_DIAG_OVER_USB
427struct diag_request {
428 char *buf;
429 int length;
430 int actual;
431 int status;
432 void *context;
433};
434#endif
435
436struct diag_pkt_stats_t {
437 uint32_t alloc_count;
438 uint32_t drop_count;
439};
440
441struct diag_cmd_stats_rsp_t {
442 struct diag_pkt_header_t header;
443 uint32_t payload;
444};
445
446struct diag_cmd_hdlc_disable_rsp_t {
447 struct diag_pkt_header_t header;
448 uint8_t framing_version;
449 uint8_t result;
450};
451
452struct diag_pkt_frame_t {
453 uint8_t start;
454 uint8_t version;
455 uint16_t length;
456};
457
458struct diag_partial_pkt_t {
459 uint32_t total_len;
460 uint32_t read_len;
461 uint32_t remaining;
462 uint32_t capacity;
463 uint8_t processing;
464 unsigned char *data;
465} __packed;
466
467struct diag_logging_mode_param_t {
468 uint32_t req_mode;
469 uint32_t peripheral_mask;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530470 uint32_t pd_mask;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700471 uint8_t mode_param;
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530472 uint8_t diag_id;
473 uint8_t pd_val;
474 uint8_t reserved;
475 int peripheral;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700476} __packed;
477
478struct diag_md_session_t {
479 int pid;
480 int peripheral_mask;
481 uint8_t hdlc_disabled;
482 struct timer_list hdlc_reset_timer;
483 struct diag_mask_info *msg_mask;
484 struct diag_mask_info *log_mask;
485 struct diag_mask_info *event_mask;
486 struct task_struct *task;
487};
488
489/*
490 * High level structure for storing Diag masks.
491 *
492 * @ptr: Pointer to the buffer that stores the masks
493 * @mask_len: Length of the buffer pointed by ptr
494 * @update_buf: Buffer for performing mask updates to peripherals
495 * @update_buf_len: Length of the buffer pointed by buf
496 * @status: status of the mask - all enable, disabled, valid
497 * @lock: To protect access to the mask variables
498 */
499struct diag_mask_info {
500 uint8_t *ptr;
501 int mask_len;
502 uint8_t *update_buf;
503 int update_buf_len;
504 uint8_t status;
505 struct mutex lock;
506};
507
508struct diag_md_proc_info {
509 int pid;
510 struct task_struct *socket_process;
511 struct task_struct *callback_process;
512 struct task_struct *mdlog_process;
513};
514
515struct diag_feature_t {
516 uint8_t feature_mask[FEATURE_MASK_LEN];
517 uint8_t rcvd_feature_mask;
518 uint8_t log_on_demand;
519 uint8_t separate_cmd_rsp;
520 uint8_t encode_hdlc;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530521 uint8_t untag_header;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700522 uint8_t peripheral_buffering;
Manoj Prabhu Bcba38ed2017-11-08 20:24:46 +0530523 uint8_t pd_buffering;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700524 uint8_t mask_centralization;
525 uint8_t stm_support;
526 uint8_t sockets_enabled;
527 uint8_t sent_feature_mask;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530528 uint8_t diag_id_support;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700529};
530
531struct diagchar_dev {
532
533 /* State for the char driver */
534 unsigned int major;
535 unsigned int minor_start;
536 int num;
537 struct cdev *cdev;
538 char *name;
539 struct class *diagchar_class;
540 struct device *diag_dev;
541 int ref_count;
542 int mask_clear;
543 struct mutex diag_maskclear_mutex;
Manoj Prabhu B2a428272016-12-22 15:22:03 +0530544 struct mutex diag_notifier_mutex;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700545 struct mutex diagchar_mutex;
546 struct mutex diag_file_mutex;
547 wait_queue_head_t wait_q;
548 struct diag_client_map *client_map;
549 int *data_ready;
Mohit Aggarwalb8474a42017-10-12 14:22:05 +0530550 atomic_t data_ready_notif[THRESHOLD_CLIENT_LIMIT];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700551 int num_clients;
552 int polling_reg_flag;
553 int use_device_tree;
554 int supports_separate_cmdrsp;
555 int supports_apps_hdlc_encoding;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530556 int supports_apps_header_untagging;
Manoj Prabhu Bcba38ed2017-11-08 20:24:46 +0530557 int supports_pd_buffering;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530558 int peripheral_untag[NUM_PERIPHERALS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700559 int supports_sockets;
560 /* The state requested in the STM command */
561 int stm_state_requested[NUM_STM_PROCESSORS];
562 /* The current STM state */
563 int stm_state[NUM_STM_PROCESSORS];
564 uint16_t stm_peripheral;
565 struct work_struct stm_update_work;
566 uint16_t mask_update;
567 struct work_struct mask_update_work;
568 uint16_t close_transport;
569 struct work_struct close_transport_work;
570 struct workqueue_struct *cntl_wq;
571 struct mutex cntl_lock;
572 /* Whether or not the peripheral supports STM */
573 /* Delayed response Variables */
574 uint16_t delayed_rsp_id;
575 struct mutex delayed_rsp_mutex;
576 /* DCI related variables */
577 struct list_head dci_req_list;
578 struct list_head dci_client_list;
579 int dci_tag;
580 int dci_client_id;
581 struct mutex dci_mutex;
582 int num_dci_client;
583 unsigned char *apps_dci_buf;
584 int dci_state;
585 struct workqueue_struct *diag_dci_wq;
586 struct list_head cmd_reg_list;
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800587 struct list_head diag_id_list;
588 struct mutex diag_id_mutex;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700589 struct mutex cmd_reg_mutex;
590 uint32_t cmd_reg_count;
Manoj Prabhu B98325462017-01-10 20:19:28 +0530591 struct mutex diagfwd_channel_mutex[NUM_PERIPHERALS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700592 /* Sizes that reflect memory pool sizes */
593 unsigned int poolsize;
594 unsigned int poolsize_hdlc;
595 unsigned int poolsize_dci;
596 unsigned int poolsize_user;
597 /* Buffers for masks */
598 struct mutex diag_cntl_mutex;
599 /* Members for Sending response */
600 unsigned char *encoded_rsp_buf;
601 int encoded_rsp_len;
602 uint8_t rsp_buf_busy;
603 spinlock_t rsp_buf_busy_lock;
604 int rsp_buf_ctxt;
605 struct diagfwd_info *diagfwd_data[NUM_PERIPHERALS];
606 struct diagfwd_info *diagfwd_cntl[NUM_PERIPHERALS];
607 struct diagfwd_info *diagfwd_dci[NUM_PERIPHERALS];
608 struct diagfwd_info *diagfwd_cmd[NUM_PERIPHERALS];
609 struct diagfwd_info *diagfwd_dci_cmd[NUM_PERIPHERALS];
610 struct diag_feature_t feature[NUM_PERIPHERALS];
Manoj Prabhu Bcba38ed2017-11-08 20:24:46 +0530611 struct diag_buffering_mode_t buffering_mode[NUM_MD_SESSIONS];
612 uint8_t buffering_flag[NUM_MD_SESSIONS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700613 struct mutex mode_lock;
614 unsigned char *user_space_data_buf;
615 uint8_t user_space_data_busy;
616 struct diag_pkt_stats_t msg_stats;
617 struct diag_pkt_stats_t log_stats;
618 struct diag_pkt_stats_t event_stats;
619 /* buffer for updating mask to peripherals */
620 unsigned char *buf_feature_mask_update;
621 uint8_t hdlc_disabled;
622 struct mutex hdlc_disable_mutex;
Hardik Arya62dce9f2017-06-15 10:39:34 +0530623 struct mutex hdlc_recovery_mutex;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700624 struct timer_list hdlc_reset_timer;
625 struct mutex diag_hdlc_mutex;
626 unsigned char *hdlc_buf;
627 uint32_t hdlc_buf_len;
628 unsigned char *apps_rsp_buf;
629 struct diag_partial_pkt_t incoming_pkt;
630 int in_busy_pktdata;
631 /* Variables for non real time mode */
632 int real_time_mode[DIAG_NUM_PROC];
633 int real_time_update_busy;
634 uint16_t proc_active_mask;
635 uint16_t proc_rt_vote_mask[DIAG_NUM_PROC];
636 struct mutex real_time_mutex;
637 struct work_struct diag_real_time_work;
638 struct workqueue_struct *diag_real_time_wq;
639#ifdef CONFIG_DIAG_OVER_USB
640 int usb_connected;
641#endif
642 struct workqueue_struct *diag_wq;
643 struct work_struct diag_drain_work;
644 struct work_struct update_user_clients;
645 struct work_struct update_md_clients;
646 struct workqueue_struct *diag_cntl_wq;
647 uint8_t log_on_demand_support;
648 uint8_t *apps_req_buf;
649 uint32_t apps_req_buf_len;
650 uint8_t *dci_pkt_buf; /* For Apps DCI packets */
651 uint32_t dci_pkt_length;
652 int in_busy_dcipktdata;
653 int logging_mode;
654 int logging_mask;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530655 int pd_logging_mode[NUM_UPD];
656 int pd_session_clear[NUM_UPD];
657 int num_pd_session;
658 int diag_id_sent[NUM_PERIPHERALS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700659 int mask_check;
660 uint32_t md_session_mask;
661 uint8_t md_session_mode;
662 struct diag_md_session_t *md_session_map[NUM_MD_SESSIONS];
663 struct mutex md_session_lock;
664 /* Power related variables */
665 struct diag_ws_ref_t dci_ws;
666 struct diag_ws_ref_t md_ws;
667 /* Pointers to Diag Masks */
668 struct diag_mask_info *msg_mask;
669 struct diag_mask_info *log_mask;
670 struct diag_mask_info *event_mask;
671 struct diag_mask_info *build_time_mask;
672 uint8_t msg_mask_tbl_count;
Gopikrishna Mogasati9a44d8d2017-05-05 16:04:35 +0530673 uint8_t bt_msg_mask_tbl_count;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700674 uint16_t event_mask_size;
675 uint16_t last_event_id;
Gopikrishna Mogasati9a44d8d2017-05-05 16:04:35 +0530676 struct mutex msg_mask_lock;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700677 /* Variables for Mask Centralization */
678 uint16_t num_event_id[NUM_PERIPHERALS];
679 uint32_t num_equip_id[NUM_PERIPHERALS];
680 uint32_t max_ssid_count[NUM_PERIPHERALS];
681#ifdef CONFIG_DIAGFWD_BRIDGE_CODE
682 /* For sending command requests in callback mode */
683 unsigned char *hdlc_encode_buf;
684 int hdlc_encode_buf_len;
685#endif
686 int time_sync_enabled;
687 uint8_t uses_time_api;
688};
689
690extern struct diagchar_dev *driver;
691
692extern int wrap_enabled;
693extern uint16_t wrap_count;
694
695void diag_get_timestamp(char *time_str);
696void check_drain_timer(void);
697int diag_get_remote(int remote_info);
698
699void diag_ws_init(void);
700void diag_ws_on_notify(void);
701void diag_ws_on_read(int type, int pkt_len);
702void diag_ws_on_copy(int type);
703void diag_ws_on_copy_fail(int type);
704void diag_ws_on_copy_complete(int type);
705void diag_ws_reset(int type);
706void diag_ws_release(void);
707void chk_logging_wakeup(void);
708int diag_cmd_add_reg(struct diag_cmd_reg_entry_t *new_entry, uint8_t proc,
709 int pid);
710struct diag_cmd_reg_entry_t *diag_cmd_search(
711 struct diag_cmd_reg_entry_t *entry,
712 int proc);
713void diag_cmd_remove_reg(struct diag_cmd_reg_entry_t *entry, uint8_t proc);
714void diag_cmd_remove_reg_by_pid(int pid);
715void diag_cmd_remove_reg_by_proc(int proc);
716int diag_cmd_chk_polling(struct diag_cmd_reg_entry_t *entry);
Manoj Prabhu B95427a22016-11-04 11:58:11 +0530717int diag_mask_param(void);
Hardik Aryadbb1c2a2017-11-10 16:29:16 +0530718void diag_clear_masks(int pid);
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530719uint8_t diag_mask_to_pd_value(uint32_t peripheral_mask);
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530720int diag_query_pd(char *process_name);
721int diag_search_peripheral_by_pd(uint8_t pd_val);
722uint8_t diag_search_diagid_by_pd(uint8_t pd_val,
723 uint8_t *diag_id, int *peripheral);
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700724void diag_record_stats(int type, int flag);
725
726struct diag_md_session_t *diag_md_session_get_pid(int pid);
727struct diag_md_session_t *diag_md_session_get_peripheral(uint8_t peripheral);
728
729#endif