blob: 921fbe89aa95f0ef56a0e90ed54faff7af4aa33b [file] [log] [blame]
Manoj Prabhu B9299d342020-05-06 09:49:47 +05301/* Copyright (c) 2008-2020, 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
Manoj Prabhu B8b771912018-10-26 11:59:47 +0530485struct diag_query_pid_t {
486 uint32_t peripheral_mask;
487 uint32_t pd_mask;
488 int pid;
489};
490
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700491struct diag_md_session_t {
492 int pid;
493 int peripheral_mask;
494 uint8_t hdlc_disabled;
Manoj Prabhu B29f7f2d2018-08-16 14:52:04 +0530495 uint8_t msg_mask_tbl_count;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700496 struct timer_list hdlc_reset_timer;
497 struct diag_mask_info *msg_mask;
498 struct diag_mask_info *log_mask;
499 struct diag_mask_info *event_mask;
500 struct task_struct *task;
501};
502
503/*
504 * High level structure for storing Diag masks.
505 *
506 * @ptr: Pointer to the buffer that stores the masks
507 * @mask_len: Length of the buffer pointed by ptr
508 * @update_buf: Buffer for performing mask updates to peripherals
509 * @update_buf_len: Length of the buffer pointed by buf
510 * @status: status of the mask - all enable, disabled, valid
511 * @lock: To protect access to the mask variables
512 */
513struct diag_mask_info {
514 uint8_t *ptr;
515 int mask_len;
516 uint8_t *update_buf;
517 int update_buf_len;
518 uint8_t status;
519 struct mutex lock;
520};
521
522struct diag_md_proc_info {
523 int pid;
524 struct task_struct *socket_process;
525 struct task_struct *callback_process;
526 struct task_struct *mdlog_process;
527};
528
529struct diag_feature_t {
530 uint8_t feature_mask[FEATURE_MASK_LEN];
531 uint8_t rcvd_feature_mask;
532 uint8_t log_on_demand;
533 uint8_t separate_cmd_rsp;
534 uint8_t encode_hdlc;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530535 uint8_t untag_header;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700536 uint8_t peripheral_buffering;
Manoj Prabhu Bcba38ed2017-11-08 20:24:46 +0530537 uint8_t pd_buffering;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700538 uint8_t mask_centralization;
539 uint8_t stm_support;
540 uint8_t sockets_enabled;
541 uint8_t sent_feature_mask;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530542 uint8_t diag_id_support;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700543};
544
545struct diagchar_dev {
546
547 /* State for the char driver */
548 unsigned int major;
549 unsigned int minor_start;
550 int num;
551 struct cdev *cdev;
552 char *name;
553 struct class *diagchar_class;
554 struct device *diag_dev;
555 int ref_count;
Manoj Prabhu B2a428272016-12-22 15:22:03 +0530556 struct mutex diag_notifier_mutex;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700557 struct mutex diagchar_mutex;
558 struct mutex diag_file_mutex;
559 wait_queue_head_t wait_q;
560 struct diag_client_map *client_map;
561 int *data_ready;
Mohit Aggarwalb8474a42017-10-12 14:22:05 +0530562 atomic_t data_ready_notif[THRESHOLD_CLIENT_LIMIT];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700563 int num_clients;
564 int polling_reg_flag;
565 int use_device_tree;
566 int supports_separate_cmdrsp;
567 int supports_apps_hdlc_encoding;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530568 int supports_apps_header_untagging;
Manoj Prabhu Bcba38ed2017-11-08 20:24:46 +0530569 int supports_pd_buffering;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530570 int peripheral_untag[NUM_PERIPHERALS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700571 int supports_sockets;
572 /* The state requested in the STM command */
573 int stm_state_requested[NUM_STM_PROCESSORS];
574 /* The current STM state */
575 int stm_state[NUM_STM_PROCESSORS];
576 uint16_t stm_peripheral;
577 struct work_struct stm_update_work;
578 uint16_t mask_update;
579 struct work_struct mask_update_work;
580 uint16_t close_transport;
581 struct work_struct close_transport_work;
582 struct workqueue_struct *cntl_wq;
583 struct mutex cntl_lock;
584 /* Whether or not the peripheral supports STM */
585 /* Delayed response Variables */
586 uint16_t delayed_rsp_id;
587 struct mutex delayed_rsp_mutex;
588 /* DCI related variables */
589 struct list_head dci_req_list;
590 struct list_head dci_client_list;
591 int dci_tag;
Hardik Aryab04c14a2019-01-08 11:48:54 +0530592 int dci_client_id[MAX_DCI_CLIENTS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700593 struct mutex dci_mutex;
594 int num_dci_client;
595 unsigned char *apps_dci_buf;
596 int dci_state;
597 struct workqueue_struct *diag_dci_wq;
598 struct list_head cmd_reg_list;
Sreelakshmi Gownipalli8d477d32017-02-08 19:49:06 -0800599 struct list_head diag_id_list;
600 struct mutex diag_id_mutex;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700601 struct mutex cmd_reg_mutex;
Manoj Prabhu B9299d342020-05-06 09:49:47 +0530602 spinlock_t dci_mempool_lock;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700603 uint32_t cmd_reg_count;
Manoj Prabhu B98325462017-01-10 20:19:28 +0530604 struct mutex diagfwd_channel_mutex[NUM_PERIPHERALS];
Sreelakshmi Gownipalli75c91e12018-10-16 16:54:43 -0700605 int transport_set;
Manoj Prabhu B10ced022019-01-11 11:00:43 +0530606 int pcie_transport_def;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700607 /* Sizes that reflect memory pool sizes */
608 unsigned int poolsize;
609 unsigned int poolsize_hdlc;
610 unsigned int poolsize_dci;
611 unsigned int poolsize_user;
Hardik Arya9cb4c102019-01-18 12:21:16 +0530612 spinlock_t diagmem_lock;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700613 /* Buffers for masks */
614 struct mutex diag_cntl_mutex;
615 /* Members for Sending response */
616 unsigned char *encoded_rsp_buf;
617 int encoded_rsp_len;
618 uint8_t rsp_buf_busy;
619 spinlock_t rsp_buf_busy_lock;
620 int rsp_buf_ctxt;
621 struct diagfwd_info *diagfwd_data[NUM_PERIPHERALS];
622 struct diagfwd_info *diagfwd_cntl[NUM_PERIPHERALS];
623 struct diagfwd_info *diagfwd_dci[NUM_PERIPHERALS];
624 struct diagfwd_info *diagfwd_cmd[NUM_PERIPHERALS];
625 struct diagfwd_info *diagfwd_dci_cmd[NUM_PERIPHERALS];
626 struct diag_feature_t feature[NUM_PERIPHERALS];
Manoj Prabhu Bcba38ed2017-11-08 20:24:46 +0530627 struct diag_buffering_mode_t buffering_mode[NUM_MD_SESSIONS];
628 uint8_t buffering_flag[NUM_MD_SESSIONS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700629 struct mutex mode_lock;
630 unsigned char *user_space_data_buf;
631 uint8_t user_space_data_busy;
632 struct diag_pkt_stats_t msg_stats;
633 struct diag_pkt_stats_t log_stats;
634 struct diag_pkt_stats_t event_stats;
635 /* buffer for updating mask to peripherals */
636 unsigned char *buf_feature_mask_update;
637 uint8_t hdlc_disabled;
Manoj Prabhu B79c91242018-03-14 14:53:52 +0530638 uint8_t p_hdlc_disabled[NUM_MD_SESSIONS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700639 struct mutex hdlc_disable_mutex;
Hardik Arya62dce9f2017-06-15 10:39:34 +0530640 struct mutex hdlc_recovery_mutex;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700641 struct timer_list hdlc_reset_timer;
642 struct mutex diag_hdlc_mutex;
643 unsigned char *hdlc_buf;
644 uint32_t hdlc_buf_len;
645 unsigned char *apps_rsp_buf;
646 struct diag_partial_pkt_t incoming_pkt;
647 int in_busy_pktdata;
648 /* Variables for non real time mode */
649 int real_time_mode[DIAG_NUM_PROC];
650 int real_time_update_busy;
651 uint16_t proc_active_mask;
652 uint16_t proc_rt_vote_mask[DIAG_NUM_PROC];
653 struct mutex real_time_mutex;
654 struct work_struct diag_real_time_work;
655 struct workqueue_struct *diag_real_time_wq;
656#ifdef CONFIG_DIAG_OVER_USB
657 int usb_connected;
658#endif
Sreelakshmi Gownipalli75c91e12018-10-16 16:54:43 -0700659 int pcie_connected;
Manoj Prabhu B85656972019-06-14 10:53:40 +0530660 int pcie_switch_pid;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700661 struct workqueue_struct *diag_wq;
662 struct work_struct diag_drain_work;
663 struct work_struct update_user_clients;
664 struct work_struct update_md_clients;
Manoj Prabhu B79c91242018-03-14 14:53:52 +0530665 struct work_struct diag_hdlc_reset_work;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700666 struct workqueue_struct *diag_cntl_wq;
667 uint8_t log_on_demand_support;
668 uint8_t *apps_req_buf;
669 uint32_t apps_req_buf_len;
670 uint8_t *dci_pkt_buf; /* For Apps DCI packets */
671 uint32_t dci_pkt_length;
672 int in_busy_dcipktdata;
673 int logging_mode;
674 int logging_mask;
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530675 int pd_logging_mode[NUM_UPD];
676 int pd_session_clear[NUM_UPD];
677 int num_pd_session;
678 int diag_id_sent[NUM_PERIPHERALS];
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700679 int mask_check;
680 uint32_t md_session_mask;
681 uint8_t md_session_mode;
682 struct diag_md_session_t *md_session_map[NUM_MD_SESSIONS];
683 struct mutex md_session_lock;
684 /* Power related variables */
685 struct diag_ws_ref_t dci_ws;
686 struct diag_ws_ref_t md_ws;
687 /* Pointers to Diag Masks */
688 struct diag_mask_info *msg_mask;
689 struct diag_mask_info *log_mask;
690 struct diag_mask_info *event_mask;
691 struct diag_mask_info *build_time_mask;
Manoj Prabhu B5e429862018-02-28 15:21:42 +0530692 uint8_t set_mask_cmd;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700693 uint8_t msg_mask_tbl_count;
Gopikrishna Mogasati9a44d8d2017-05-05 16:04:35 +0530694 uint8_t bt_msg_mask_tbl_count;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700695 uint16_t event_mask_size;
696 uint16_t last_event_id;
Gopikrishna Mogasati9a44d8d2017-05-05 16:04:35 +0530697 struct mutex msg_mask_lock;
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700698 /* Variables for Mask Centralization */
699 uint16_t num_event_id[NUM_PERIPHERALS];
700 uint32_t num_equip_id[NUM_PERIPHERALS];
701 uint32_t max_ssid_count[NUM_PERIPHERALS];
702#ifdef CONFIG_DIAGFWD_BRIDGE_CODE
703 /* For sending command requests in callback mode */
704 unsigned char *hdlc_encode_buf;
705 int hdlc_encode_buf_len;
706#endif
707 int time_sync_enabled;
708 uint8_t uses_time_api;
709};
710
711extern struct diagchar_dev *driver;
712
713extern int wrap_enabled;
714extern uint16_t wrap_count;
715
716void diag_get_timestamp(char *time_str);
717void check_drain_timer(void);
718int diag_get_remote(int remote_info);
719
720void diag_ws_init(void);
721void diag_ws_on_notify(void);
722void diag_ws_on_read(int type, int pkt_len);
723void diag_ws_on_copy(int type);
724void diag_ws_on_copy_fail(int type);
725void diag_ws_on_copy_complete(int type);
726void diag_ws_reset(int type);
727void diag_ws_release(void);
728void chk_logging_wakeup(void);
729int diag_cmd_add_reg(struct diag_cmd_reg_entry_t *new_entry, uint8_t proc,
730 int pid);
731struct diag_cmd_reg_entry_t *diag_cmd_search(
732 struct diag_cmd_reg_entry_t *entry,
733 int proc);
734void diag_cmd_remove_reg(struct diag_cmd_reg_entry_t *entry, uint8_t proc);
735void diag_cmd_remove_reg_by_pid(int pid);
736void diag_cmd_remove_reg_by_proc(int proc);
737int diag_cmd_chk_polling(struct diag_cmd_reg_entry_t *entry);
Manoj Prabhu B95427a22016-11-04 11:58:11 +0530738int diag_mask_param(void);
Hardik Aryadbb1c2a2017-11-10 16:29:16 +0530739void diag_clear_masks(int pid);
Manoj Prabhu B571cf422017-08-08 19:01:41 +0530740uint8_t diag_mask_to_pd_value(uint32_t peripheral_mask);
Manoj Prabhu B90e1f502017-11-02 20:01:45 +0530741int diag_query_pd(char *process_name);
742int diag_search_peripheral_by_pd(uint8_t pd_val);
743uint8_t diag_search_diagid_by_pd(uint8_t pd_val,
744 uint8_t *diag_id, int *peripheral);
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700745void diag_record_stats(int type, int flag);
746
747struct diag_md_session_t *diag_md_session_get_pid(int pid);
748struct diag_md_session_t *diag_md_session_get_peripheral(uint8_t peripheral);
Manoj Prabhu B79c91242018-03-14 14:53:52 +0530749int diag_md_session_match_pid_peripheral(int pid, uint8_t peripheral);
Sreelakshmi Gownipallicb8893d2016-10-19 16:02:34 -0700750
751#endif