blob: 264443d9c953544b4b4130ebadcc0edb613bc3d9 [file] [log] [blame]
Manoj Prabhu B10ced022019-01-11 11:00:43 +05301/* Copyright (c) 2008-2019, 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 Aggarwal237dc912018-03-21 15:14:03 +053039#ifdef CONFIG_USB_CI13XXX_MSM
40#define APF_DIAG_PADDING 256
41#else
Mohit Aggarwalae6ddf52017-10-18 21:25:22 +053042#define APF_DIAG_PADDING 0
Mohit Aggarwal237dc912018-03-21 15:14:03 +053043#endif
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070044/*
45 * In the worst case, the HDLC buffer can be atmost twice the size of the
46 * original packet. Add 3 bytes for 16 bit CRC (2 bytes) and a delimiter
47 * (1 byte)
48 */
49#define DIAG_MAX_HDLC_BUF_SIZE ((DIAG_MAX_REQ_SIZE * 2) + 3)
50
51/* The header of callback data type has remote processor token (of type int) */
52#define CALLBACK_HDR_SIZE (sizeof(int))
53#define CALLBACK_BUF_SIZE (DIAG_MAX_REQ_SIZE + CALLBACK_HDR_SIZE)
54
55#define MAX_SSID_PER_RANGE 200
56
57#define ALL_PROC -1
58
59#define REMOTE_DATA 4
60
61#define USER_SPACE_DATA 16384
62
63#define DIAG_CTRL_MSG_LOG_MASK 9
64#define DIAG_CTRL_MSG_EVENT_MASK 10
65#define DIAG_CTRL_MSG_F3_MASK 11
66#define CONTROL_CHAR 0x7E
67
Manoj Prabhu B571cf422017-08-08 19:01:41 +053068#define DIAG_ID_ROOT_STRING "root"
69
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070070#define DIAG_CON_APSS (0x0001) /* Bit mask for APSS */
71#define DIAG_CON_MPSS (0x0002) /* Bit mask for MPSS */
72#define DIAG_CON_LPASS (0x0004) /* Bit mask for LPASS */
73#define DIAG_CON_WCNSS (0x0008) /* Bit mask for WCNSS */
74#define DIAG_CON_SENSORS (0x0010) /* Bit mask for Sensors */
Manoj Prabhu B571cf422017-08-08 19:01:41 +053075#define DIAG_CON_WDSP (0x0020) /* Bit mask for WDSP */
76#define DIAG_CON_CDSP (0x0040) /* Bit mask for CDSP */
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070077
Manoj Prabhu B571cf422017-08-08 19:01:41 +053078#define DIAG_CON_UPD_WLAN (0x1000) /*Bit mask for WLAN PD*/
Manoj Prabhu B90e1f502017-11-02 20:01:45 +053079#define DIAG_CON_UPD_AUDIO (0x2000) /*Bit mask for AUDIO PD*/
80#define DIAG_CON_UPD_SENSORS (0x4000) /*Bit mask for SENSORS PD*/
81
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070082#define DIAG_CON_NONE (0x0000) /* Bit mask for No SS*/
83#define DIAG_CON_ALL (DIAG_CON_APSS | DIAG_CON_MPSS \
84 | DIAG_CON_LPASS | DIAG_CON_WCNSS \
Sreelakshmi Gownipalli588a31d2016-11-02 13:33:43 -070085 | DIAG_CON_SENSORS | DIAG_CON_WDSP \
86 | DIAG_CON_CDSP)
Manoj Prabhu B90e1f502017-11-02 20:01:45 +053087#define DIAG_CON_UPD_ALL (DIAG_CON_UPD_WLAN \
88 | DIAG_CON_UPD_AUDIO \
89 | DIAG_CON_UPD_SENSORS)
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070090
91#define DIAG_STM_MODEM 0x01
92#define DIAG_STM_LPASS 0x02
93#define DIAG_STM_WCNSS 0x04
94#define DIAG_STM_APPS 0x08
95#define DIAG_STM_SENSORS 0x10
96#define DIAG_STM_WDSP 0x20
Sreelakshmi Gownipalli588a31d2016-11-02 13:33:43 -070097#define DIAG_STM_CDSP 0x40
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -070098
99#define INVALID_PID -1
100#define DIAG_CMD_FOUND 1
101#define DIAG_CMD_NOT_FOUND 0
102#define DIAG_CMD_POLLING 1
103#define DIAG_CMD_NOT_POLLING 0
104#define DIAG_CMD_ADD 1
105#define DIAG_CMD_REMOVE 0
106
107#define DIAG_CMD_VERSION 0
108#define DIAG_CMD_ERROR 0x13
109#define DIAG_CMD_DOWNLOAD 0x3A
110#define DIAG_CMD_DIAG_SUBSYS 0x4B
111#define DIAG_CMD_LOG_CONFIG 0x73
112#define DIAG_CMD_LOG_ON_DMND 0x78
113#define DIAG_CMD_EXT_BUILD 0x7c
114#define DIAG_CMD_MSG_CONFIG 0x7D
115#define DIAG_CMD_GET_EVENT_MASK 0x81
116#define DIAG_CMD_SET_EVENT_MASK 0x82
117#define DIAG_CMD_EVENT_TOGGLE 0x60
118#define DIAG_CMD_NO_SUBSYS 0xFF
119#define DIAG_CMD_STATUS 0x0C
120#define DIAG_SS_WCDMA 0x04
121#define DIAG_CMD_QUERY_CALL 0x0E
122#define DIAG_SS_GSM 0x08
123#define DIAG_CMD_QUERY_TMC 0x02
124#define DIAG_SS_TDSCDMA 0x57
125#define DIAG_CMD_TDSCDMA_STATUS 0x0E
126#define DIAG_CMD_DIAG_SUBSYS_DELAY 0x80
127
128#define DIAG_SS_DIAG 0x12
129#define DIAG_SS_PARAMS 0x32
130#define DIAG_SS_FILE_READ_MODEM 0x0816
131#define DIAG_SS_FILE_READ_ADSP 0x0E10
132#define DIAG_SS_FILE_READ_WCNSS 0x141F
133#define DIAG_SS_FILE_READ_SLPI 0x01A18
134#define DIAG_SS_FILE_READ_APPS 0x020F
135
136#define DIAG_DIAG_MAX_PKT_SZ 0x55
137#define DIAG_DIAG_STM 0x214
138#define DIAG_DIAG_POLL 0x03
139#define DIAG_DEL_RSP_WRAP 0x04
140#define DIAG_DEL_RSP_WRAP_CNT 0x05
141#define DIAG_EXT_MOBILE_ID 0x06
142#define DIAG_GET_TIME_API 0x21B
143#define DIAG_SET_TIME_API 0x21C
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800144#define DIAG_GET_DIAG_ID 0x222
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700145#define DIAG_SWITCH_COMMAND 0x081B
146#define DIAG_BUFFERING_MODE 0x080C
147
148#define DIAG_CMD_OP_LOG_DISABLE 0
149#define DIAG_CMD_OP_GET_LOG_RANGE 1
150#define DIAG_CMD_OP_SET_LOG_MASK 3
151#define DIAG_CMD_OP_GET_LOG_MASK 4
152
153#define DIAG_CMD_OP_GET_SSID_RANGE 1
154#define DIAG_CMD_OP_GET_BUILD_MASK 2
155#define DIAG_CMD_OP_GET_MSG_MASK 3
156#define DIAG_CMD_OP_SET_MSG_MASK 4
157#define DIAG_CMD_OP_SET_ALL_MSG_MASK 5
158
159#define DIAG_CMD_OP_GET_MSG_ALLOC 0x33
160#define DIAG_CMD_OP_GET_MSG_DROP 0x30
161#define DIAG_CMD_OP_RESET_MSG_STATS 0x2F
162#define DIAG_CMD_OP_GET_LOG_ALLOC 0x31
163#define DIAG_CMD_OP_GET_LOG_DROP 0x2C
164#define DIAG_CMD_OP_RESET_LOG_STATS 0x2B
165#define DIAG_CMD_OP_GET_EVENT_ALLOC 0x32
166#define DIAG_CMD_OP_GET_EVENT_DROP 0x2E
167#define DIAG_CMD_OP_RESET_EVENT_STATS 0x2D
168
169#define DIAG_CMD_OP_HDLC_DISABLE 0x218
170
171#define BAD_PARAM_RESPONSE_MESSAGE 20
172
173#define PERSIST_TIME_SUCCESS 0
174#define PERSIST_TIME_FAILURE 1
175#define PERSIST_TIME_NOT_SUPPORTED 2
176
177#define MODE_CMD 41
178#define RESET_ID 2
179
180#define PKT_DROP 0
181#define PKT_ALLOC 1
182#define PKT_RESET 2
183
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530184#define FEATURE_MASK_LEN 4
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700185
186#define DIAG_MD_NONE 0
187#define DIAG_MD_PERIPHERAL 1
188
189/*
190 * The status bit masks when received in a signal handler are to be
191 * used in conjunction with the peripheral list bit mask to determine the
192 * status for a peripheral. For instance, 0x00010002 would denote an open
193 * status on the MPSS
194 */
195#define DIAG_STATUS_OPEN (0x00010000) /* DCI channel open status mask */
196#define DIAG_STATUS_CLOSED (0x00020000) /* DCI channel closed status mask */
197
198#define MODE_NONREALTIME 0
199#define MODE_REALTIME 1
200#define MODE_UNKNOWN 2
201
202#define DIAG_BUFFERING_MODE_STREAMING 0
203#define DIAG_BUFFERING_MODE_THRESHOLD 1
204#define DIAG_BUFFERING_MODE_CIRCULAR 2
205
206#define DIAG_MIN_WM_VAL 0
207#define DIAG_MAX_WM_VAL 100
208
209#define DEFAULT_LOW_WM_VAL 15
210#define DEFAULT_HIGH_WM_VAL 85
211
212#define TYPE_DATA 0
213#define TYPE_CNTL 1
214#define TYPE_DCI 2
215#define TYPE_CMD 3
216#define TYPE_DCI_CMD 4
217#define NUM_TYPES 5
218
219#define PERIPHERAL_MODEM 0
220#define PERIPHERAL_LPASS 1
221#define PERIPHERAL_WCNSS 2
222#define PERIPHERAL_SENSORS 3
223#define PERIPHERAL_WDSP 4
Sreelakshmi Gownipalli588a31d2016-11-02 13:33:43 -0700224#define PERIPHERAL_CDSP 5
225#define NUM_PERIPHERALS 6
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700226#define APPS_DATA (NUM_PERIPHERALS)
227
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530228#define UPD_WLAN 7
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530229#define UPD_AUDIO 8
230#define UPD_SENSORS 9
231#define NUM_UPD 3
232
233#define MAX_PERIPHERAL_UPD 2
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700234/* Number of sessions possible in Memory Device Mode. +1 for Apps data */
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530235#define NUM_MD_SESSIONS (NUM_PERIPHERALS \
236 + NUM_UPD + 1)
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700237
238#define MD_PERIPHERAL_MASK(x) (1 << x)
239
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530240#define MD_PERIPHERAL_PD_MASK(x, peripheral, pd_mask) \
241do { \
242fwd_info = &peripheral_info[x][peripheral]; \
243for (i = 0; i <= fwd_info->num_pd - 2; i++) \
244 pd_mask |= (1 << fwd_info->upd_diag_id[i].pd);\
245} while (0)
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530246
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700247/*
248 * Number of stm processors includes all the peripherals and
249 * apps.Added 1 below to indicate apps
250 */
251#define NUM_STM_PROCESSORS (NUM_PERIPHERALS + 1)
252/*
253 * Indicates number of peripherals that can support DCI and Apps
254 * processor. This doesn't mean that a peripheral has the
255 * feature.
256 */
257#define NUM_DCI_PERIPHERALS (NUM_PERIPHERALS + 1)
258
259#define DIAG_PROC_DCI 1
260#define DIAG_PROC_MEMORY_DEVICE 2
261
262/* Flags to vote the DCI or Memory device process up or down
263 * when it becomes active or inactive.
264 */
265#define VOTE_DOWN 0
266#define VOTE_UP 1
267
268#define DIAG_TS_SIZE 50
269
270#define DIAG_MDM_BUF_SIZE 2048
271/* The Maximum request size is 2k + DCI header + footer (6 bytes) */
272#define DIAG_MDM_DCI_BUF_SIZE (2048 + 6)
273
274#define DIAG_LOCAL_PROC 0
275
276#ifndef CONFIG_DIAGFWD_BRIDGE_CODE
277/* Local Processor only */
278#define DIAG_NUM_PROC 1
279#else
280/* Local Processor + Remote Devices */
281#define DIAG_NUM_PROC (1 + NUM_REMOTE_DEV)
282#endif
283
284#define DIAG_WS_DCI 0
285#define DIAG_WS_MUX 1
286
287#define DIAG_DATA_TYPE 1
288#define DIAG_CNTL_TYPE 2
289#define DIAG_DCI_TYPE 3
290
Hardik Aryab04c14a2019-01-08 11:48:54 +0530291#define MAX_DCI_CLIENTS 10
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800292/*
293 * List of diag ids
294 * 0 is reserved for unknown diag id, 1 for apps, diag ids
295 * for remaining pds are assigned dynamically.
296 */
297#define DIAG_ID_UNKNOWN 0
298#define DIAG_ID_APPS 1
299
Sreelakshmi Gownipalli75c91e12018-10-16 16:54:43 -0700300#define DIAG_ROUTE_TO_USB 0
301#define DIAG_ROUTE_TO_PCIE 1
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700302/* List of remote processor supported */
303enum remote_procs {
304 MDM = 1,
305 MDM2 = 2,
306 QSC = 5,
307};
308
309struct diag_pkt_header_t {
310 uint8_t cmd_code;
311 uint8_t subsys_id;
312 uint16_t subsys_cmd_code;
313} __packed;
314
315struct diag_cmd_ext_mobile_rsp_t {
316 struct diag_pkt_header_t header;
317 uint8_t version;
318 uint8_t padding[3];
319 uint32_t family;
320 uint32_t chip_id;
321} __packed;
322
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800323struct diag_cmd_diag_id_query_req_t {
324 struct diag_pkt_header_t header;
325 uint8_t version;
326} __packed;
327
328struct diag_id_tbl_t {
329 struct list_head link;
330 uint8_t diag_id;
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530331 uint8_t pd_val;
332 uint8_t peripheral;
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800333 char *process_name;
334} __packed;
335struct diag_id_t {
336 uint8_t diag_id;
337 uint8_t len;
338 char *process_name;
339} __packed;
340
341struct diag_cmd_diag_id_query_rsp_t {
342 struct diag_pkt_header_t header;
343 uint8_t version;
344 uint8_t num_entries;
345 struct diag_id_t entry;
346} __packed;
347
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700348struct diag_cmd_time_sync_query_req_t {
349 struct diag_pkt_header_t header;
350 uint8_t version;
351};
352
353struct diag_cmd_time_sync_query_rsp_t {
354 struct diag_pkt_header_t header;
355 uint8_t version;
356 uint8_t time_api;
357};
358
359struct diag_cmd_time_sync_switch_req_t {
360 struct diag_pkt_header_t header;
361 uint8_t version;
362 uint8_t time_api;
363 uint8_t persist_time;
364};
365
366struct diag_cmd_time_sync_switch_rsp_t {
367 struct diag_pkt_header_t header;
368 uint8_t version;
369 uint8_t time_api;
370 uint8_t time_api_status;
371 uint8_t persist_time_status;
372};
373
374struct diag_cmd_reg_entry_t {
375 uint16_t cmd_code;
376 uint16_t subsys_id;
377 uint16_t cmd_code_lo;
378 uint16_t cmd_code_hi;
379} __packed;
380
381struct diag_cmd_reg_t {
382 struct list_head link;
383 struct diag_cmd_reg_entry_t entry;
384 uint8_t proc;
385 int pid;
386};
387
388/*
389 * @sync_obj_name: name of the synchronization object associated with this proc
390 * @count: number of entries in the bind
391 * @entries: the actual packet registrations
392 */
393struct diag_cmd_reg_tbl_t {
394 char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE];
395 uint32_t count;
396 struct diag_cmd_reg_entry_t *entries;
397};
398
399struct diag_client_map {
400 char name[20];
401 int pid;
402};
403
404struct real_time_vote_t {
405 int client_id;
406 uint16_t proc;
407 uint8_t real_time_vote;
408} __packed;
409
410struct real_time_query_t {
411 int real_time;
412 int proc;
413} __packed;
414
415struct diag_buffering_mode_t {
416 uint8_t peripheral;
417 uint8_t mode;
418 uint8_t high_wm_val;
419 uint8_t low_wm_val;
420} __packed;
421
422struct diag_callback_reg_t {
423 int proc;
424} __packed;
425
426struct diag_ws_ref_t {
427 int ref_count;
428 int copy_count;
429 spinlock_t lock;
430};
431
432/* This structure is defined in USB header file */
433#ifndef CONFIG_DIAG_OVER_USB
434struct diag_request {
435 char *buf;
436 int length;
437 int actual;
438 int status;
439 void *context;
440};
441#endif
442
443struct diag_pkt_stats_t {
444 uint32_t alloc_count;
445 uint32_t drop_count;
446};
447
448struct diag_cmd_stats_rsp_t {
449 struct diag_pkt_header_t header;
450 uint32_t payload;
451};
452
453struct diag_cmd_hdlc_disable_rsp_t {
454 struct diag_pkt_header_t header;
455 uint8_t framing_version;
456 uint8_t result;
457};
458
459struct diag_pkt_frame_t {
460 uint8_t start;
461 uint8_t version;
462 uint16_t length;
463};
464
465struct diag_partial_pkt_t {
466 uint32_t total_len;
467 uint32_t read_len;
468 uint32_t remaining;
469 uint32_t capacity;
470 uint8_t processing;
471 unsigned char *data;
472} __packed;
473
474struct diag_logging_mode_param_t {
475 uint32_t req_mode;
476 uint32_t peripheral_mask;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530477 uint32_t pd_mask;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700478 uint8_t mode_param;
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530479 uint8_t diag_id;
480 uint8_t pd_val;
481 uint8_t reserved;
482 int peripheral;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700483} __packed;
484
485struct diag_md_session_t {
486 int pid;
487 int peripheral_mask;
488 uint8_t hdlc_disabled;
Manoj Prabhu B29f7f2d2018-08-16 14:52:04 +0530489 uint8_t msg_mask_tbl_count;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700490 struct timer_list hdlc_reset_timer;
491 struct diag_mask_info *msg_mask;
492 struct diag_mask_info *log_mask;
493 struct diag_mask_info *event_mask;
494 struct task_struct *task;
495};
496
497/*
498 * High level structure for storing Diag masks.
499 *
500 * @ptr: Pointer to the buffer that stores the masks
501 * @mask_len: Length of the buffer pointed by ptr
502 * @update_buf: Buffer for performing mask updates to peripherals
503 * @update_buf_len: Length of the buffer pointed by buf
504 * @status: status of the mask - all enable, disabled, valid
505 * @lock: To protect access to the mask variables
506 */
507struct diag_mask_info {
508 uint8_t *ptr;
509 int mask_len;
510 uint8_t *update_buf;
511 int update_buf_len;
512 uint8_t status;
513 struct mutex lock;
514};
515
516struct diag_md_proc_info {
517 int pid;
518 struct task_struct *socket_process;
519 struct task_struct *callback_process;
520 struct task_struct *mdlog_process;
521};
522
523struct diag_feature_t {
524 uint8_t feature_mask[FEATURE_MASK_LEN];
525 uint8_t rcvd_feature_mask;
526 uint8_t log_on_demand;
527 uint8_t separate_cmd_rsp;
528 uint8_t encode_hdlc;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530529 uint8_t untag_header;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700530 uint8_t peripheral_buffering;
Manoj Prabhu Bcba38ed2017-11-08 20:24:46 +0530531 uint8_t pd_buffering;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700532 uint8_t mask_centralization;
533 uint8_t stm_support;
534 uint8_t sockets_enabled;
535 uint8_t sent_feature_mask;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530536 uint8_t diag_id_support;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700537};
538
539struct diagchar_dev {
540
541 /* State for the char driver */
542 unsigned int major;
543 unsigned int minor_start;
544 int num;
545 struct cdev *cdev;
546 char *name;
547 struct class *diagchar_class;
548 struct device *diag_dev;
549 int ref_count;
Manoj Prabhu B2a428272016-12-22 15:22:03 +0530550 struct mutex diag_notifier_mutex;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700551 struct mutex diagchar_mutex;
552 struct mutex diag_file_mutex;
553 wait_queue_head_t wait_q;
554 struct diag_client_map *client_map;
555 int *data_ready;
Mohit Aggarwalb8474a42017-10-12 14:22:05 +0530556 atomic_t data_ready_notif[THRESHOLD_CLIENT_LIMIT];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700557 int num_clients;
558 int polling_reg_flag;
559 int use_device_tree;
560 int supports_separate_cmdrsp;
561 int supports_apps_hdlc_encoding;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530562 int supports_apps_header_untagging;
Manoj Prabhu Bcba38ed2017-11-08 20:24:46 +0530563 int supports_pd_buffering;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530564 int peripheral_untag[NUM_PERIPHERALS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700565 int supports_sockets;
566 /* The state requested in the STM command */
567 int stm_state_requested[NUM_STM_PROCESSORS];
568 /* The current STM state */
569 int stm_state[NUM_STM_PROCESSORS];
570 uint16_t stm_peripheral;
571 struct work_struct stm_update_work;
572 uint16_t mask_update;
573 struct work_struct mask_update_work;
574 uint16_t close_transport;
575 struct work_struct close_transport_work;
576 struct workqueue_struct *cntl_wq;
577 struct mutex cntl_lock;
578 /* Whether or not the peripheral supports STM */
579 /* Delayed response Variables */
580 uint16_t delayed_rsp_id;
581 struct mutex delayed_rsp_mutex;
582 /* DCI related variables */
583 struct list_head dci_req_list;
584 struct list_head dci_client_list;
585 int dci_tag;
Hardik Aryab04c14a2019-01-08 11:48:54 +0530586 int dci_client_id[MAX_DCI_CLIENTS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700587 struct mutex dci_mutex;
588 int num_dci_client;
589 unsigned char *apps_dci_buf;
590 int dci_state;
591 struct workqueue_struct *diag_dci_wq;
592 struct list_head cmd_reg_list;
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800593 struct list_head diag_id_list;
594 struct mutex diag_id_mutex;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700595 struct mutex cmd_reg_mutex;
596 uint32_t cmd_reg_count;
Manoj Prabhu B98325462017-01-10 20:19:28 +0530597 struct mutex diagfwd_channel_mutex[NUM_PERIPHERALS];
Sreelakshmi Gownipalli75c91e12018-10-16 16:54:43 -0700598 int transport_set;
Manoj Prabhu B10ced022019-01-11 11:00:43 +0530599 int pcie_transport_def;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700600 /* Sizes that reflect memory pool sizes */
601 unsigned int poolsize;
602 unsigned int poolsize_hdlc;
603 unsigned int poolsize_dci;
604 unsigned int poolsize_user;
Hardik Arya9cb4c102019-01-18 12:21:16 +0530605 spinlock_t diagmem_lock;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700606 /* Buffers for masks */
607 struct mutex diag_cntl_mutex;
608 /* Members for Sending response */
609 unsigned char *encoded_rsp_buf;
610 int encoded_rsp_len;
611 uint8_t rsp_buf_busy;
612 spinlock_t rsp_buf_busy_lock;
613 int rsp_buf_ctxt;
614 struct diagfwd_info *diagfwd_data[NUM_PERIPHERALS];
615 struct diagfwd_info *diagfwd_cntl[NUM_PERIPHERALS];
616 struct diagfwd_info *diagfwd_dci[NUM_PERIPHERALS];
617 struct diagfwd_info *diagfwd_cmd[NUM_PERIPHERALS];
618 struct diagfwd_info *diagfwd_dci_cmd[NUM_PERIPHERALS];
619 struct diag_feature_t feature[NUM_PERIPHERALS];
Manoj Prabhu Bcba38ed2017-11-08 20:24:46 +0530620 struct diag_buffering_mode_t buffering_mode[NUM_MD_SESSIONS];
621 uint8_t buffering_flag[NUM_MD_SESSIONS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700622 struct mutex mode_lock;
623 unsigned char *user_space_data_buf;
624 uint8_t user_space_data_busy;
625 struct diag_pkt_stats_t msg_stats;
626 struct diag_pkt_stats_t log_stats;
627 struct diag_pkt_stats_t event_stats;
628 /* buffer for updating mask to peripherals */
629 unsigned char *buf_feature_mask_update;
630 uint8_t hdlc_disabled;
Manoj Prabhu B79c91242018-03-14 14:53:52 +0530631 uint8_t p_hdlc_disabled[NUM_MD_SESSIONS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700632 struct mutex hdlc_disable_mutex;
Hardik Arya62dce9f2017-06-15 10:39:34 +0530633 struct mutex hdlc_recovery_mutex;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700634 struct timer_list hdlc_reset_timer;
635 struct mutex diag_hdlc_mutex;
636 unsigned char *hdlc_buf;
637 uint32_t hdlc_buf_len;
638 unsigned char *apps_rsp_buf;
639 struct diag_partial_pkt_t incoming_pkt;
640 int in_busy_pktdata;
641 /* Variables for non real time mode */
642 int real_time_mode[DIAG_NUM_PROC];
643 int real_time_update_busy;
644 uint16_t proc_active_mask;
645 uint16_t proc_rt_vote_mask[DIAG_NUM_PROC];
646 struct mutex real_time_mutex;
647 struct work_struct diag_real_time_work;
648 struct workqueue_struct *diag_real_time_wq;
649#ifdef CONFIG_DIAG_OVER_USB
650 int usb_connected;
651#endif
Sreelakshmi Gownipalli75c91e12018-10-16 16:54:43 -0700652 int pcie_connected;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700653 struct workqueue_struct *diag_wq;
654 struct work_struct diag_drain_work;
655 struct work_struct update_user_clients;
656 struct work_struct update_md_clients;
Manoj Prabhu B79c91242018-03-14 14:53:52 +0530657 struct work_struct diag_hdlc_reset_work;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700658 struct workqueue_struct *diag_cntl_wq;
659 uint8_t log_on_demand_support;
660 uint8_t *apps_req_buf;
661 uint32_t apps_req_buf_len;
662 uint8_t *dci_pkt_buf; /* For Apps DCI packets */
663 uint32_t dci_pkt_length;
664 int in_busy_dcipktdata;
665 int logging_mode;
666 int logging_mask;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530667 int pd_logging_mode[NUM_UPD];
668 int pd_session_clear[NUM_UPD];
669 int num_pd_session;
670 int diag_id_sent[NUM_PERIPHERALS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700671 int mask_check;
672 uint32_t md_session_mask;
673 uint8_t md_session_mode;
674 struct diag_md_session_t *md_session_map[NUM_MD_SESSIONS];
675 struct mutex md_session_lock;
676 /* Power related variables */
677 struct diag_ws_ref_t dci_ws;
678 struct diag_ws_ref_t md_ws;
679 /* Pointers to Diag Masks */
680 struct diag_mask_info *msg_mask;
681 struct diag_mask_info *log_mask;
682 struct diag_mask_info *event_mask;
683 struct diag_mask_info *build_time_mask;
Manoj Prabhu B5e429862018-02-28 15:21:42 +0530684 uint8_t set_mask_cmd;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700685 uint8_t msg_mask_tbl_count;
Gopikrishna Mogasati9a44d8d2017-05-05 16:04:35 +0530686 uint8_t bt_msg_mask_tbl_count;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700687 uint16_t event_mask_size;
688 uint16_t last_event_id;
Gopikrishna Mogasati9a44d8d2017-05-05 16:04:35 +0530689 struct mutex msg_mask_lock;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700690 /* Variables for Mask Centralization */
691 uint16_t num_event_id[NUM_PERIPHERALS];
692 uint32_t num_equip_id[NUM_PERIPHERALS];
693 uint32_t max_ssid_count[NUM_PERIPHERALS];
694#ifdef CONFIG_DIAGFWD_BRIDGE_CODE
695 /* For sending command requests in callback mode */
696 unsigned char *hdlc_encode_buf;
697 int hdlc_encode_buf_len;
698#endif
699 int time_sync_enabled;
700 uint8_t uses_time_api;
701};
702
703extern struct diagchar_dev *driver;
704
705extern int wrap_enabled;
706extern uint16_t wrap_count;
707
708void diag_get_timestamp(char *time_str);
709void check_drain_timer(void);
710int diag_get_remote(int remote_info);
711
712void diag_ws_init(void);
713void diag_ws_on_notify(void);
714void diag_ws_on_read(int type, int pkt_len);
715void diag_ws_on_copy(int type);
716void diag_ws_on_copy_fail(int type);
717void diag_ws_on_copy_complete(int type);
718void diag_ws_reset(int type);
719void diag_ws_release(void);
720void chk_logging_wakeup(void);
721int diag_cmd_add_reg(struct diag_cmd_reg_entry_t *new_entry, uint8_t proc,
722 int pid);
723struct diag_cmd_reg_entry_t *diag_cmd_search(
724 struct diag_cmd_reg_entry_t *entry,
725 int proc);
726void diag_cmd_remove_reg(struct diag_cmd_reg_entry_t *entry, uint8_t proc);
727void diag_cmd_remove_reg_by_pid(int pid);
728void diag_cmd_remove_reg_by_proc(int proc);
729int diag_cmd_chk_polling(struct diag_cmd_reg_entry_t *entry);
Manoj Prabhu B95427a22016-11-04 11:58:11 +0530730int diag_mask_param(void);
Hardik Aryadbb1c2a2017-11-10 16:29:16 +0530731void diag_clear_masks(int pid);
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530732uint8_t diag_mask_to_pd_value(uint32_t peripheral_mask);
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530733int diag_query_pd(char *process_name);
734int diag_search_peripheral_by_pd(uint8_t pd_val);
735uint8_t diag_search_diagid_by_pd(uint8_t pd_val,
736 uint8_t *diag_id, int *peripheral);
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700737void diag_record_stats(int type, int flag);
738
739struct diag_md_session_t *diag_md_session_get_pid(int pid);
740struct diag_md_session_t *diag_md_session_get_peripheral(uint8_t peripheral);
Manoj Prabhu B79c91242018-03-14 14:53:52 +0530741int diag_md_session_match_pid_peripheral(int pid, uint8_t peripheral);
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700742
743#endif