Manoj Prabhu B | 79c9124 | 2018-03-14 14:53:52 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2008-2018, The Linux Foundation. All rights reserved. |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 2 | * |
| 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 Boyd | 73f8c49 | 2017-09-07 14:57:14 -0700 | [diff] [blame] | 24 | #include <linux/device.h> |
Hardik Arya | d6da1cb | 2017-11-23 20:40:55 +0530 | [diff] [blame] | 25 | #include <soc/qcom/smd.h> |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 26 | #include <linux/atomic.h> |
| 27 | #include "diagfwd_bridge.h" |
| 28 | |
Mohit Aggarwal | b8474a4 | 2017-10-12 14:22:05 +0530 | [diff] [blame] | 29 | #define THRESHOLD_CLIENT_LIMIT 50 |
| 30 | |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 31 | /* 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 Aggarwal | 237dc91 | 2018-03-21 15:14:03 +0530 | [diff] [blame] | 39 | #ifdef CONFIG_USB_CI13XXX_MSM |
| 40 | #define APF_DIAG_PADDING 256 |
| 41 | #else |
Mohit Aggarwal | ae6ddf5 | 2017-10-18 21:25:22 +0530 | [diff] [blame] | 42 | #define APF_DIAG_PADDING 0 |
Mohit Aggarwal | 237dc91 | 2018-03-21 15:14:03 +0530 | [diff] [blame] | 43 | #endif |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 44 | /* |
| 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 B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 68 | #define DIAG_ID_ROOT_STRING "root" |
| 69 | |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 70 | #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 B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 75 | #define DIAG_CON_WDSP (0x0020) /* Bit mask for WDSP */ |
| 76 | #define DIAG_CON_CDSP (0x0040) /* Bit mask for CDSP */ |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 77 | |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 78 | #define DIAG_CON_UPD_WLAN (0x1000) /*Bit mask for WLAN PD*/ |
Manoj Prabhu B | 90e1f50 | 2017-11-02 20:01:45 +0530 | [diff] [blame] | 79 | #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 Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 82 | #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 Gownipalli | 588a31d | 2016-11-02 13:33:43 -0700 | [diff] [blame] | 85 | | DIAG_CON_SENSORS | DIAG_CON_WDSP \ |
| 86 | | DIAG_CON_CDSP) |
Manoj Prabhu B | 90e1f50 | 2017-11-02 20:01:45 +0530 | [diff] [blame] | 87 | #define DIAG_CON_UPD_ALL (DIAG_CON_UPD_WLAN \ |
| 88 | | DIAG_CON_UPD_AUDIO \ |
| 89 | | DIAG_CON_UPD_SENSORS) |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 90 | |
| 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 Gownipalli | 588a31d | 2016-11-02 13:33:43 -0700 | [diff] [blame] | 97 | #define DIAG_STM_CDSP 0x40 |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 98 | |
| 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 Gownipalli | 8d477d3 | 2017-02-08 19:49:06 -0800 | [diff] [blame] | 144 | #define DIAG_GET_DIAG_ID 0x222 |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 145 | #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 B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 184 | #define FEATURE_MASK_LEN 4 |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 185 | |
| 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 Gownipalli | 588a31d | 2016-11-02 13:33:43 -0700 | [diff] [blame] | 224 | #define PERIPHERAL_CDSP 5 |
| 225 | #define NUM_PERIPHERALS 6 |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 226 | #define APPS_DATA (NUM_PERIPHERALS) |
| 227 | |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 228 | #define UPD_WLAN 7 |
Manoj Prabhu B | 90e1f50 | 2017-11-02 20:01:45 +0530 | [diff] [blame] | 229 | #define UPD_AUDIO 8 |
| 230 | #define UPD_SENSORS 9 |
| 231 | #define NUM_UPD 3 |
| 232 | |
| 233 | #define MAX_PERIPHERAL_UPD 2 |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 234 | /* Number of sessions possible in Memory Device Mode. +1 for Apps data */ |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 235 | #define NUM_MD_SESSIONS (NUM_PERIPHERALS \ |
| 236 | + NUM_UPD + 1) |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 237 | |
| 238 | #define MD_PERIPHERAL_MASK(x) (1 << x) |
| 239 | |
Manoj Prabhu B | 90e1f50 | 2017-11-02 20:01:45 +0530 | [diff] [blame] | 240 | #define MD_PERIPHERAL_PD_MASK(x, peripheral, pd_mask) \ |
| 241 | do { \ |
| 242 | fwd_info = &peripheral_info[x][peripheral]; \ |
| 243 | for (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 B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 246 | |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 247 | /* |
| 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 | |
Sreelakshmi Gownipalli | 8d477d3 | 2017-02-08 19:49:06 -0800 | [diff] [blame] | 291 | /* |
| 292 | * List of diag ids |
| 293 | * 0 is reserved for unknown diag id, 1 for apps, diag ids |
| 294 | * for remaining pds are assigned dynamically. |
| 295 | */ |
| 296 | #define DIAG_ID_UNKNOWN 0 |
| 297 | #define DIAG_ID_APPS 1 |
| 298 | |
Sreelakshmi Gownipalli | 75c91e1 | 2018-10-16 16:54:43 -0700 | [diff] [blame] | 299 | #define DIAG_ROUTE_TO_USB 0 |
| 300 | #define DIAG_ROUTE_TO_PCIE 1 |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 301 | /* List of remote processor supported */ |
| 302 | enum remote_procs { |
| 303 | MDM = 1, |
| 304 | MDM2 = 2, |
| 305 | QSC = 5, |
| 306 | }; |
| 307 | |
| 308 | struct diag_pkt_header_t { |
| 309 | uint8_t cmd_code; |
| 310 | uint8_t subsys_id; |
| 311 | uint16_t subsys_cmd_code; |
| 312 | } __packed; |
| 313 | |
| 314 | struct diag_cmd_ext_mobile_rsp_t { |
| 315 | struct diag_pkt_header_t header; |
| 316 | uint8_t version; |
| 317 | uint8_t padding[3]; |
| 318 | uint32_t family; |
| 319 | uint32_t chip_id; |
| 320 | } __packed; |
| 321 | |
Sreelakshmi Gownipalli | 8d477d3 | 2017-02-08 19:49:06 -0800 | [diff] [blame] | 322 | struct diag_cmd_diag_id_query_req_t { |
| 323 | struct diag_pkt_header_t header; |
| 324 | uint8_t version; |
| 325 | } __packed; |
| 326 | |
| 327 | struct diag_id_tbl_t { |
| 328 | struct list_head link; |
| 329 | uint8_t diag_id; |
Manoj Prabhu B | 90e1f50 | 2017-11-02 20:01:45 +0530 | [diff] [blame] | 330 | uint8_t pd_val; |
| 331 | uint8_t peripheral; |
Sreelakshmi Gownipalli | 8d477d3 | 2017-02-08 19:49:06 -0800 | [diff] [blame] | 332 | char *process_name; |
| 333 | } __packed; |
| 334 | struct diag_id_t { |
| 335 | uint8_t diag_id; |
| 336 | uint8_t len; |
| 337 | char *process_name; |
| 338 | } __packed; |
| 339 | |
| 340 | struct diag_cmd_diag_id_query_rsp_t { |
| 341 | struct diag_pkt_header_t header; |
| 342 | uint8_t version; |
| 343 | uint8_t num_entries; |
| 344 | struct diag_id_t entry; |
| 345 | } __packed; |
| 346 | |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 347 | struct diag_cmd_time_sync_query_req_t { |
| 348 | struct diag_pkt_header_t header; |
| 349 | uint8_t version; |
| 350 | }; |
| 351 | |
| 352 | struct diag_cmd_time_sync_query_rsp_t { |
| 353 | struct diag_pkt_header_t header; |
| 354 | uint8_t version; |
| 355 | uint8_t time_api; |
| 356 | }; |
| 357 | |
| 358 | struct diag_cmd_time_sync_switch_req_t { |
| 359 | struct diag_pkt_header_t header; |
| 360 | uint8_t version; |
| 361 | uint8_t time_api; |
| 362 | uint8_t persist_time; |
| 363 | }; |
| 364 | |
| 365 | struct diag_cmd_time_sync_switch_rsp_t { |
| 366 | struct diag_pkt_header_t header; |
| 367 | uint8_t version; |
| 368 | uint8_t time_api; |
| 369 | uint8_t time_api_status; |
| 370 | uint8_t persist_time_status; |
| 371 | }; |
| 372 | |
| 373 | struct diag_cmd_reg_entry_t { |
| 374 | uint16_t cmd_code; |
| 375 | uint16_t subsys_id; |
| 376 | uint16_t cmd_code_lo; |
| 377 | uint16_t cmd_code_hi; |
| 378 | } __packed; |
| 379 | |
| 380 | struct diag_cmd_reg_t { |
| 381 | struct list_head link; |
| 382 | struct diag_cmd_reg_entry_t entry; |
| 383 | uint8_t proc; |
| 384 | int pid; |
| 385 | }; |
| 386 | |
| 387 | /* |
| 388 | * @sync_obj_name: name of the synchronization object associated with this proc |
| 389 | * @count: number of entries in the bind |
| 390 | * @entries: the actual packet registrations |
| 391 | */ |
| 392 | struct diag_cmd_reg_tbl_t { |
| 393 | char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE]; |
| 394 | uint32_t count; |
| 395 | struct diag_cmd_reg_entry_t *entries; |
| 396 | }; |
| 397 | |
| 398 | struct diag_client_map { |
| 399 | char name[20]; |
| 400 | int pid; |
| 401 | }; |
| 402 | |
| 403 | struct real_time_vote_t { |
| 404 | int client_id; |
| 405 | uint16_t proc; |
| 406 | uint8_t real_time_vote; |
| 407 | } __packed; |
| 408 | |
| 409 | struct real_time_query_t { |
| 410 | int real_time; |
| 411 | int proc; |
| 412 | } __packed; |
| 413 | |
| 414 | struct diag_buffering_mode_t { |
| 415 | uint8_t peripheral; |
| 416 | uint8_t mode; |
| 417 | uint8_t high_wm_val; |
| 418 | uint8_t low_wm_val; |
| 419 | } __packed; |
| 420 | |
| 421 | struct diag_callback_reg_t { |
| 422 | int proc; |
| 423 | } __packed; |
| 424 | |
| 425 | struct diag_ws_ref_t { |
| 426 | int ref_count; |
| 427 | int copy_count; |
| 428 | spinlock_t lock; |
| 429 | }; |
| 430 | |
| 431 | /* This structure is defined in USB header file */ |
| 432 | #ifndef CONFIG_DIAG_OVER_USB |
| 433 | struct diag_request { |
| 434 | char *buf; |
| 435 | int length; |
| 436 | int actual; |
| 437 | int status; |
| 438 | void *context; |
| 439 | }; |
| 440 | #endif |
| 441 | |
| 442 | struct diag_pkt_stats_t { |
| 443 | uint32_t alloc_count; |
| 444 | uint32_t drop_count; |
| 445 | }; |
| 446 | |
| 447 | struct diag_cmd_stats_rsp_t { |
| 448 | struct diag_pkt_header_t header; |
| 449 | uint32_t payload; |
| 450 | }; |
| 451 | |
| 452 | struct diag_cmd_hdlc_disable_rsp_t { |
| 453 | struct diag_pkt_header_t header; |
| 454 | uint8_t framing_version; |
| 455 | uint8_t result; |
| 456 | }; |
| 457 | |
| 458 | struct diag_pkt_frame_t { |
| 459 | uint8_t start; |
| 460 | uint8_t version; |
| 461 | uint16_t length; |
| 462 | }; |
| 463 | |
| 464 | struct diag_partial_pkt_t { |
| 465 | uint32_t total_len; |
| 466 | uint32_t read_len; |
| 467 | uint32_t remaining; |
| 468 | uint32_t capacity; |
| 469 | uint8_t processing; |
| 470 | unsigned char *data; |
| 471 | } __packed; |
| 472 | |
| 473 | struct diag_logging_mode_param_t { |
| 474 | uint32_t req_mode; |
| 475 | uint32_t peripheral_mask; |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 476 | uint32_t pd_mask; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 477 | uint8_t mode_param; |
Manoj Prabhu B | 90e1f50 | 2017-11-02 20:01:45 +0530 | [diff] [blame] | 478 | uint8_t diag_id; |
| 479 | uint8_t pd_val; |
| 480 | uint8_t reserved; |
| 481 | int peripheral; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 482 | } __packed; |
| 483 | |
| 484 | struct diag_md_session_t { |
| 485 | int pid; |
| 486 | int peripheral_mask; |
| 487 | uint8_t hdlc_disabled; |
Manoj Prabhu B | 29f7f2d | 2018-08-16 14:52:04 +0530 | [diff] [blame] | 488 | uint8_t msg_mask_tbl_count; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 489 | struct timer_list hdlc_reset_timer; |
| 490 | struct diag_mask_info *msg_mask; |
| 491 | struct diag_mask_info *log_mask; |
| 492 | struct diag_mask_info *event_mask; |
| 493 | struct task_struct *task; |
| 494 | }; |
| 495 | |
| 496 | /* |
| 497 | * High level structure for storing Diag masks. |
| 498 | * |
| 499 | * @ptr: Pointer to the buffer that stores the masks |
| 500 | * @mask_len: Length of the buffer pointed by ptr |
| 501 | * @update_buf: Buffer for performing mask updates to peripherals |
| 502 | * @update_buf_len: Length of the buffer pointed by buf |
| 503 | * @status: status of the mask - all enable, disabled, valid |
| 504 | * @lock: To protect access to the mask variables |
| 505 | */ |
| 506 | struct diag_mask_info { |
| 507 | uint8_t *ptr; |
| 508 | int mask_len; |
| 509 | uint8_t *update_buf; |
| 510 | int update_buf_len; |
| 511 | uint8_t status; |
| 512 | struct mutex lock; |
| 513 | }; |
| 514 | |
| 515 | struct diag_md_proc_info { |
| 516 | int pid; |
| 517 | struct task_struct *socket_process; |
| 518 | struct task_struct *callback_process; |
| 519 | struct task_struct *mdlog_process; |
| 520 | }; |
| 521 | |
| 522 | struct diag_feature_t { |
| 523 | uint8_t feature_mask[FEATURE_MASK_LEN]; |
| 524 | uint8_t rcvd_feature_mask; |
| 525 | uint8_t log_on_demand; |
| 526 | uint8_t separate_cmd_rsp; |
| 527 | uint8_t encode_hdlc; |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 528 | uint8_t untag_header; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 529 | uint8_t peripheral_buffering; |
Manoj Prabhu B | cba38ed | 2017-11-08 20:24:46 +0530 | [diff] [blame] | 530 | uint8_t pd_buffering; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 531 | uint8_t mask_centralization; |
| 532 | uint8_t stm_support; |
| 533 | uint8_t sockets_enabled; |
| 534 | uint8_t sent_feature_mask; |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 535 | uint8_t diag_id_support; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 536 | }; |
| 537 | |
| 538 | struct diagchar_dev { |
| 539 | |
| 540 | /* State for the char driver */ |
| 541 | unsigned int major; |
| 542 | unsigned int minor_start; |
| 543 | int num; |
| 544 | struct cdev *cdev; |
| 545 | char *name; |
| 546 | struct class *diagchar_class; |
| 547 | struct device *diag_dev; |
| 548 | int ref_count; |
Manoj Prabhu B | 2a42827 | 2016-12-22 15:22:03 +0530 | [diff] [blame] | 549 | struct mutex diag_notifier_mutex; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 550 | struct mutex diagchar_mutex; |
| 551 | struct mutex diag_file_mutex; |
| 552 | wait_queue_head_t wait_q; |
| 553 | struct diag_client_map *client_map; |
| 554 | int *data_ready; |
Mohit Aggarwal | b8474a4 | 2017-10-12 14:22:05 +0530 | [diff] [blame] | 555 | atomic_t data_ready_notif[THRESHOLD_CLIENT_LIMIT]; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 556 | int num_clients; |
| 557 | int polling_reg_flag; |
| 558 | int use_device_tree; |
| 559 | int supports_separate_cmdrsp; |
| 560 | int supports_apps_hdlc_encoding; |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 561 | int supports_apps_header_untagging; |
Manoj Prabhu B | cba38ed | 2017-11-08 20:24:46 +0530 | [diff] [blame] | 562 | int supports_pd_buffering; |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 563 | int peripheral_untag[NUM_PERIPHERALS]; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 564 | int supports_sockets; |
| 565 | /* The state requested in the STM command */ |
| 566 | int stm_state_requested[NUM_STM_PROCESSORS]; |
| 567 | /* The current STM state */ |
| 568 | int stm_state[NUM_STM_PROCESSORS]; |
| 569 | uint16_t stm_peripheral; |
| 570 | struct work_struct stm_update_work; |
| 571 | uint16_t mask_update; |
| 572 | struct work_struct mask_update_work; |
| 573 | uint16_t close_transport; |
| 574 | struct work_struct close_transport_work; |
| 575 | struct workqueue_struct *cntl_wq; |
| 576 | struct mutex cntl_lock; |
| 577 | /* Whether or not the peripheral supports STM */ |
| 578 | /* Delayed response Variables */ |
| 579 | uint16_t delayed_rsp_id; |
| 580 | struct mutex delayed_rsp_mutex; |
| 581 | /* DCI related variables */ |
| 582 | struct list_head dci_req_list; |
| 583 | struct list_head dci_client_list; |
| 584 | int dci_tag; |
| 585 | int dci_client_id; |
| 586 | struct mutex dci_mutex; |
| 587 | int num_dci_client; |
| 588 | unsigned char *apps_dci_buf; |
| 589 | int dci_state; |
| 590 | struct workqueue_struct *diag_dci_wq; |
| 591 | struct list_head cmd_reg_list; |
Sreelakshmi Gownipalli | 8d477d3 | 2017-02-08 19:49:06 -0800 | [diff] [blame] | 592 | struct list_head diag_id_list; |
| 593 | struct mutex diag_id_mutex; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 594 | struct mutex cmd_reg_mutex; |
| 595 | uint32_t cmd_reg_count; |
Manoj Prabhu B | 9832546 | 2017-01-10 20:19:28 +0530 | [diff] [blame] | 596 | struct mutex diagfwd_channel_mutex[NUM_PERIPHERALS]; |
Sreelakshmi Gownipalli | 75c91e1 | 2018-10-16 16:54:43 -0700 | [diff] [blame] | 597 | int transport_set; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 598 | /* Sizes that reflect memory pool sizes */ |
| 599 | unsigned int poolsize; |
| 600 | unsigned int poolsize_hdlc; |
| 601 | unsigned int poolsize_dci; |
| 602 | unsigned int poolsize_user; |
| 603 | /* Buffers for masks */ |
| 604 | struct mutex diag_cntl_mutex; |
| 605 | /* Members for Sending response */ |
| 606 | unsigned char *encoded_rsp_buf; |
| 607 | int encoded_rsp_len; |
| 608 | uint8_t rsp_buf_busy; |
| 609 | spinlock_t rsp_buf_busy_lock; |
| 610 | int rsp_buf_ctxt; |
| 611 | struct diagfwd_info *diagfwd_data[NUM_PERIPHERALS]; |
| 612 | struct diagfwd_info *diagfwd_cntl[NUM_PERIPHERALS]; |
| 613 | struct diagfwd_info *diagfwd_dci[NUM_PERIPHERALS]; |
| 614 | struct diagfwd_info *diagfwd_cmd[NUM_PERIPHERALS]; |
| 615 | struct diagfwd_info *diagfwd_dci_cmd[NUM_PERIPHERALS]; |
| 616 | struct diag_feature_t feature[NUM_PERIPHERALS]; |
Manoj Prabhu B | cba38ed | 2017-11-08 20:24:46 +0530 | [diff] [blame] | 617 | struct diag_buffering_mode_t buffering_mode[NUM_MD_SESSIONS]; |
| 618 | uint8_t buffering_flag[NUM_MD_SESSIONS]; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 619 | struct mutex mode_lock; |
| 620 | unsigned char *user_space_data_buf; |
| 621 | uint8_t user_space_data_busy; |
| 622 | struct diag_pkt_stats_t msg_stats; |
| 623 | struct diag_pkt_stats_t log_stats; |
| 624 | struct diag_pkt_stats_t event_stats; |
| 625 | /* buffer for updating mask to peripherals */ |
| 626 | unsigned char *buf_feature_mask_update; |
| 627 | uint8_t hdlc_disabled; |
Manoj Prabhu B | 79c9124 | 2018-03-14 14:53:52 +0530 | [diff] [blame] | 628 | uint8_t p_hdlc_disabled[NUM_MD_SESSIONS]; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 629 | struct mutex hdlc_disable_mutex; |
Hardik Arya | 62dce9f | 2017-06-15 10:39:34 +0530 | [diff] [blame] | 630 | struct mutex hdlc_recovery_mutex; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 631 | struct timer_list hdlc_reset_timer; |
| 632 | struct mutex diag_hdlc_mutex; |
| 633 | unsigned char *hdlc_buf; |
| 634 | uint32_t hdlc_buf_len; |
| 635 | unsigned char *apps_rsp_buf; |
| 636 | struct diag_partial_pkt_t incoming_pkt; |
| 637 | int in_busy_pktdata; |
| 638 | /* Variables for non real time mode */ |
| 639 | int real_time_mode[DIAG_NUM_PROC]; |
| 640 | int real_time_update_busy; |
| 641 | uint16_t proc_active_mask; |
| 642 | uint16_t proc_rt_vote_mask[DIAG_NUM_PROC]; |
| 643 | struct mutex real_time_mutex; |
| 644 | struct work_struct diag_real_time_work; |
| 645 | struct workqueue_struct *diag_real_time_wq; |
| 646 | #ifdef CONFIG_DIAG_OVER_USB |
| 647 | int usb_connected; |
| 648 | #endif |
Sreelakshmi Gownipalli | 75c91e1 | 2018-10-16 16:54:43 -0700 | [diff] [blame] | 649 | int pcie_connected; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 650 | struct workqueue_struct *diag_wq; |
| 651 | struct work_struct diag_drain_work; |
| 652 | struct work_struct update_user_clients; |
| 653 | struct work_struct update_md_clients; |
Manoj Prabhu B | 79c9124 | 2018-03-14 14:53:52 +0530 | [diff] [blame] | 654 | struct work_struct diag_hdlc_reset_work; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 655 | struct workqueue_struct *diag_cntl_wq; |
| 656 | uint8_t log_on_demand_support; |
| 657 | uint8_t *apps_req_buf; |
| 658 | uint32_t apps_req_buf_len; |
| 659 | uint8_t *dci_pkt_buf; /* For Apps DCI packets */ |
| 660 | uint32_t dci_pkt_length; |
| 661 | int in_busy_dcipktdata; |
| 662 | int logging_mode; |
| 663 | int logging_mask; |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 664 | int pd_logging_mode[NUM_UPD]; |
| 665 | int pd_session_clear[NUM_UPD]; |
| 666 | int num_pd_session; |
| 667 | int diag_id_sent[NUM_PERIPHERALS]; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 668 | int mask_check; |
| 669 | uint32_t md_session_mask; |
| 670 | uint8_t md_session_mode; |
| 671 | struct diag_md_session_t *md_session_map[NUM_MD_SESSIONS]; |
| 672 | struct mutex md_session_lock; |
| 673 | /* Power related variables */ |
| 674 | struct diag_ws_ref_t dci_ws; |
| 675 | struct diag_ws_ref_t md_ws; |
| 676 | /* Pointers to Diag Masks */ |
| 677 | struct diag_mask_info *msg_mask; |
| 678 | struct diag_mask_info *log_mask; |
| 679 | struct diag_mask_info *event_mask; |
| 680 | struct diag_mask_info *build_time_mask; |
Manoj Prabhu B | 5e42986 | 2018-02-28 15:21:42 +0530 | [diff] [blame] | 681 | uint8_t set_mask_cmd; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 682 | uint8_t msg_mask_tbl_count; |
Gopikrishna Mogasati | 9a44d8d | 2017-05-05 16:04:35 +0530 | [diff] [blame] | 683 | uint8_t bt_msg_mask_tbl_count; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 684 | uint16_t event_mask_size; |
| 685 | uint16_t last_event_id; |
Gopikrishna Mogasati | 9a44d8d | 2017-05-05 16:04:35 +0530 | [diff] [blame] | 686 | struct mutex msg_mask_lock; |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 687 | /* Variables for Mask Centralization */ |
| 688 | uint16_t num_event_id[NUM_PERIPHERALS]; |
| 689 | uint32_t num_equip_id[NUM_PERIPHERALS]; |
| 690 | uint32_t max_ssid_count[NUM_PERIPHERALS]; |
| 691 | #ifdef CONFIG_DIAGFWD_BRIDGE_CODE |
| 692 | /* For sending command requests in callback mode */ |
| 693 | unsigned char *hdlc_encode_buf; |
| 694 | int hdlc_encode_buf_len; |
| 695 | #endif |
| 696 | int time_sync_enabled; |
| 697 | uint8_t uses_time_api; |
| 698 | }; |
| 699 | |
| 700 | extern struct diagchar_dev *driver; |
| 701 | |
| 702 | extern int wrap_enabled; |
| 703 | extern uint16_t wrap_count; |
| 704 | |
| 705 | void diag_get_timestamp(char *time_str); |
| 706 | void check_drain_timer(void); |
| 707 | int diag_get_remote(int remote_info); |
| 708 | |
| 709 | void diag_ws_init(void); |
| 710 | void diag_ws_on_notify(void); |
| 711 | void diag_ws_on_read(int type, int pkt_len); |
| 712 | void diag_ws_on_copy(int type); |
| 713 | void diag_ws_on_copy_fail(int type); |
| 714 | void diag_ws_on_copy_complete(int type); |
| 715 | void diag_ws_reset(int type); |
| 716 | void diag_ws_release(void); |
| 717 | void chk_logging_wakeup(void); |
| 718 | int diag_cmd_add_reg(struct diag_cmd_reg_entry_t *new_entry, uint8_t proc, |
| 719 | int pid); |
| 720 | struct diag_cmd_reg_entry_t *diag_cmd_search( |
| 721 | struct diag_cmd_reg_entry_t *entry, |
| 722 | int proc); |
| 723 | void diag_cmd_remove_reg(struct diag_cmd_reg_entry_t *entry, uint8_t proc); |
| 724 | void diag_cmd_remove_reg_by_pid(int pid); |
| 725 | void diag_cmd_remove_reg_by_proc(int proc); |
| 726 | int diag_cmd_chk_polling(struct diag_cmd_reg_entry_t *entry); |
Manoj Prabhu B | 95427a2 | 2016-11-04 11:58:11 +0530 | [diff] [blame] | 727 | int diag_mask_param(void); |
Hardik Arya | dbb1c2a | 2017-11-10 16:29:16 +0530 | [diff] [blame] | 728 | void diag_clear_masks(int pid); |
Manoj Prabhu B | 571cf42 | 2017-08-08 19:01:41 +0530 | [diff] [blame] | 729 | uint8_t diag_mask_to_pd_value(uint32_t peripheral_mask); |
Manoj Prabhu B | 90e1f50 | 2017-11-02 20:01:45 +0530 | [diff] [blame] | 730 | int diag_query_pd(char *process_name); |
| 731 | int diag_search_peripheral_by_pd(uint8_t pd_val); |
| 732 | uint8_t diag_search_diagid_by_pd(uint8_t pd_val, |
| 733 | uint8_t *diag_id, int *peripheral); |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 734 | void diag_record_stats(int type, int flag); |
| 735 | |
| 736 | struct diag_md_session_t *diag_md_session_get_pid(int pid); |
| 737 | struct diag_md_session_t *diag_md_session_get_peripheral(uint8_t peripheral); |
Manoj Prabhu B | 79c9124 | 2018-03-14 14:53:52 +0530 | [diff] [blame] | 738 | int diag_md_session_match_pid_peripheral(int pid, uint8_t peripheral); |
Sreelakshmi Gownipalli | cb8893d | 2016-10-19 16:02:34 -0700 | [diff] [blame] | 739 | |
| 740 | #endif |