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