Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2008-2013, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -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> |
Dixon Peterson | 5db2e3c | 2012-09-06 19:13:14 -0700 | [diff] [blame] | 20 | #include <linux/spinlock.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 21 | #include <linux/workqueue.h> |
Shalabh Jain | 5e9a92b | 2012-06-07 21:53:49 -0700 | [diff] [blame] | 22 | #include <linux/sched.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 23 | #include <mach/msm_smd.h> |
| 24 | #include <asm/atomic.h> |
| 25 | #include <asm/mach-types.h> |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 26 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 27 | /* Size of the USB buffers used for read and write*/ |
| 28 | #define USB_MAX_OUT_BUF 4096 |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 29 | #define APPS_BUF_SIZE 2000 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 30 | #define IN_BUF_SIZE 16384 |
| 31 | #define MAX_IN_BUF_SIZE 32768 |
| 32 | #define MAX_SYNC_OBJ_NAME_SIZE 32 |
Ravi Aravamudhan | 77ad483 | 2012-11-15 16:04:04 -0800 | [diff] [blame] | 33 | #define UINT32_MAX UINT_MAX |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 34 | /* Size of the buffer used for deframing a packet |
| 35 | reveived from the PC tool*/ |
| 36 | #define HDLC_MAX 4096 |
| 37 | #define HDLC_OUT_BUF_SIZE 8192 |
| 38 | #define POOL_TYPE_COPY 1 |
| 39 | #define POOL_TYPE_HDLC 2 |
| 40 | #define POOL_TYPE_WRITE_STRUCT 4 |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 41 | #define POOL_TYPE_HSIC 5 |
| 42 | #define POOL_TYPE_HSIC_2 6 |
| 43 | #define POOL_TYPE_HSIC_WRITE 11 |
| 44 | #define POOL_TYPE_HSIC_2_WRITE 12 |
| 45 | #define POOL_TYPE_ALL 10 |
Dixon Peterson | eecbadb | 2012-12-10 21:59:28 -0800 | [diff] [blame] | 46 | #define MODEM_DATA 0 |
| 47 | #define LPASS_DATA 1 |
| 48 | #define WCNSS_DATA 2 |
Ashay Jaiswal | 8be3ce8 | 2012-09-13 16:01:54 -0700 | [diff] [blame] | 49 | #define APPS_DATA 3 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 50 | #define SDIO_DATA 4 |
Dixon Peterson | eecbadb | 2012-12-10 21:59:28 -0800 | [diff] [blame] | 51 | #define HSIC_DATA 5 |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 52 | #define HSIC_2_DATA 6 |
| 53 | #define SMUX_DATA 10 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 54 | #define APPS_PROC 1 |
Shalabh Jain | 44b79b7 | 2012-06-15 13:39:27 -0700 | [diff] [blame] | 55 | #define MSG_MASK_SIZE 10000 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 56 | #define LOG_MASK_SIZE 8000 |
| 57 | #define EVENT_MASK_SIZE 1000 |
Shalabh Jain | 69890aa | 2011-10-10 12:59:16 -0700 | [diff] [blame] | 58 | #define USER_SPACE_DATA 8000 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 59 | #define PKT_SIZE 4096 |
Shalabh Jain | fbf3bdc | 2012-03-16 21:02:50 -0700 | [diff] [blame] | 60 | #define MAX_EQUIP_ID 15 |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 61 | #define DIAG_CTRL_MSG_LOG_MASK 9 |
| 62 | #define DIAG_CTRL_MSG_EVENT_MASK 10 |
| 63 | #define DIAG_CTRL_MSG_F3_MASK 11 |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 64 | #define CONTROL_CHAR 0x7E |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 65 | |
Shalabh Jain | 7b20eab | 2012-06-19 17:50:58 -0700 | [diff] [blame] | 66 | #define DIAG_CON_APSS (0x0001) /* Bit mask for APSS */ |
| 67 | #define DIAG_CON_MPSS (0x0002) /* Bit mask for MPSS */ |
| 68 | #define DIAG_CON_LPASS (0x0004) /* Bit mask for LPASS */ |
| 69 | #define DIAG_CON_WCNSS (0x0008) /* Bit mask for WCNSS */ |
| 70 | |
Dixon Peterson | 5a26a30 | 2012-11-15 17:26:17 -0800 | [diff] [blame] | 71 | /* |
| 72 | * The status bit masks when received in a signal handler are to be |
| 73 | * used in conjunction with the peripheral list bit mask to determine the |
| 74 | * status for a peripheral. For instance, 0x00010002 would denote an open |
| 75 | * status on the MPSS |
| 76 | */ |
| 77 | #define DIAG_STATUS_OPEN (0x00010000) /* DCI channel open status mask */ |
| 78 | #define DIAG_STATUS_CLOSED (0x00020000) /* DCI channel closed status mask */ |
| 79 | |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 80 | #define NUM_SMD_DATA_CHANNELS 3 |
| 81 | #define NUM_SMD_CONTROL_CHANNELS 3 |
| 82 | #define NUM_SMD_DCI_CHANNELS 1 |
| 83 | |
| 84 | #define SMD_DATA_TYPE 0 |
| 85 | #define SMD_CNTL_TYPE 1 |
| 86 | #define SMD_DCI_TYPE 2 |
| 87 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 88 | /* Maximum number of pkt reg supported at initialization*/ |
Shalabh Jain | fe02b0c | 2012-02-21 14:48:03 -0800 | [diff] [blame] | 89 | extern unsigned int diag_max_reg; |
| 90 | extern unsigned int diag_threshold_reg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 91 | |
| 92 | #define APPEND_DEBUG(ch) \ |
| 93 | do { \ |
| 94 | diag_debug_buf[diag_debug_buf_idx] = ch; \ |
| 95 | (diag_debug_buf_idx < 1023) ? \ |
| 96 | (diag_debug_buf_idx++) : (diag_debug_buf_idx = 0); \ |
| 97 | } while (0) |
| 98 | |
Ashay Jaiswal | a372f8c | 2012-12-12 14:02:38 +0530 | [diff] [blame] | 99 | /* List of remote processor supported */ |
| 100 | enum remote_procs { |
| 101 | MDM = 1, |
Dixon Peterson | f90f358 | 2013-01-26 18:14:17 -0800 | [diff] [blame] | 102 | MDM2 = 2, |
| 103 | MDM3 = 3, |
| 104 | MDM4 = 4, |
| 105 | QSC = 5, |
Ashay Jaiswal | a372f8c | 2012-12-12 14:02:38 +0530 | [diff] [blame] | 106 | }; |
| 107 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 108 | struct diag_master_table { |
| 109 | uint16_t cmd_code; |
| 110 | uint16_t subsys_id; |
| 111 | uint32_t client_id; |
| 112 | uint16_t cmd_code_lo; |
| 113 | uint16_t cmd_code_hi; |
| 114 | int process_id; |
| 115 | }; |
| 116 | |
| 117 | struct bindpkt_params_per_process { |
| 118 | /* Name of the synchronization object associated with this proc */ |
| 119 | char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE]; |
| 120 | uint32_t count; /* Number of entries in this bind */ |
| 121 | struct bindpkt_params *params; /* first bind params */ |
| 122 | }; |
| 123 | |
| 124 | struct bindpkt_params { |
| 125 | uint16_t cmd_code; |
| 126 | uint16_t subsys_id; |
| 127 | uint16_t cmd_code_lo; |
| 128 | uint16_t cmd_code_hi; |
| 129 | /* For Central Routing, used to store Processor number */ |
| 130 | uint16_t proc_id; |
| 131 | uint32_t event_id; |
| 132 | uint32_t log_code; |
| 133 | /* For Central Routing, used to store SMD channel pointer */ |
| 134 | uint32_t client_id; |
| 135 | }; |
| 136 | |
| 137 | struct diag_write_device { |
| 138 | void *buf; |
| 139 | int length; |
| 140 | }; |
| 141 | |
| 142 | struct diag_client_map { |
| 143 | char name[20]; |
| 144 | int pid; |
| 145 | }; |
| 146 | |
| 147 | /* This structure is defined in USB header file */ |
| 148 | #ifndef CONFIG_DIAG_OVER_USB |
| 149 | struct diag_request { |
| 150 | char *buf; |
| 151 | int length; |
| 152 | int actual; |
| 153 | int status; |
| 154 | void *context; |
| 155 | }; |
| 156 | #endif |
| 157 | |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 158 | struct diag_smd_info { |
| 159 | int peripheral; /* The peripheral this smd channel communicates with */ |
| 160 | int type; /* The type of smd channel (data, control, dci) */ |
| 161 | uint16_t peripheral_mask; |
| 162 | |
| 163 | smd_channel_t *ch; |
| 164 | smd_channel_t *ch_save; |
| 165 | |
| 166 | int in_busy_1; |
| 167 | int in_busy_2; |
| 168 | |
| 169 | unsigned char *buf_in_1; |
| 170 | unsigned char *buf_in_2; |
| 171 | |
| 172 | struct diag_request *write_ptr_1; |
| 173 | struct diag_request *write_ptr_2; |
| 174 | |
| 175 | struct work_struct diag_read_smd_work; |
| 176 | struct work_struct diag_notify_update_smd_work; |
| 177 | int notify_context; |
| 178 | |
| 179 | /* |
| 180 | * Function ptr for function to call to process the data that |
| 181 | * was just read from the smd channel |
| 182 | */ |
| 183 | int (*process_smd_read_data)(struct diag_smd_info *smd_info, |
| 184 | void *buf, int num_bytes); |
| 185 | }; |
| 186 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 187 | struct diagchar_dev { |
| 188 | |
| 189 | /* State for the char driver */ |
| 190 | unsigned int major; |
| 191 | unsigned int minor_start; |
| 192 | int num; |
| 193 | struct cdev *cdev; |
| 194 | char *name; |
| 195 | int dropped_count; |
| 196 | struct class *diagchar_class; |
| 197 | int ref_count; |
| 198 | struct mutex diagchar_mutex; |
| 199 | wait_queue_head_t wait_q; |
Shalabh Jain | c70b3b6 | 2012-08-31 19:11:20 -0700 | [diff] [blame] | 200 | wait_queue_head_t smd_wait_q; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 201 | struct diag_client_map *client_map; |
| 202 | int *data_ready; |
| 203 | int num_clients; |
Shalabh Jain | 3d29fc3 | 2012-02-09 17:15:59 -0800 | [diff] [blame] | 204 | int polling_reg_flag; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 205 | struct diag_write_device *buf_tbl; |
Dixon Peterson | b4618a4 | 2012-02-29 18:56:31 -0800 | [diff] [blame] | 206 | int use_device_tree; |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 207 | /* DCI related variables */ |
Shalabh Jain | 1679490 | 2012-09-14 10:56:49 -0700 | [diff] [blame] | 208 | struct dci_pkt_req_tracking_tbl *req_tracking_tbl; |
| 209 | struct diag_dci_client_tbl *dci_client_tbl; |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 210 | int dci_tag; |
| 211 | int dci_client_id; |
| 212 | struct mutex dci_mutex; |
| 213 | int num_dci_client; |
| 214 | unsigned char *apps_dci_buf; |
| 215 | int dci_state; |
Shalabh Jain | 1679490 | 2012-09-14 10:56:49 -0700 | [diff] [blame] | 216 | struct workqueue_struct *diag_dci_wq; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 217 | /* Memory pool parameters */ |
| 218 | unsigned int itemsize; |
| 219 | unsigned int poolsize; |
| 220 | unsigned int itemsize_hdlc; |
| 221 | unsigned int poolsize_hdlc; |
| 222 | unsigned int itemsize_write_struct; |
| 223 | unsigned int poolsize_write_struct; |
| 224 | unsigned int debug_flag; |
| 225 | /* State for the mempool for the char driver */ |
| 226 | mempool_t *diagpool; |
| 227 | mempool_t *diag_hdlc_pool; |
| 228 | mempool_t *diag_write_struct_pool; |
| 229 | struct mutex diagmem_mutex; |
| 230 | int count; |
| 231 | int count_hdlc_pool; |
| 232 | int count_write_struct_pool; |
| 233 | int used; |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 234 | /* Buffers for masks */ |
Shalabh Jain | a06c6d7 | 2012-04-30 13:40:35 -0700 | [diff] [blame] | 235 | struct mutex diag_cntl_mutex; |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 236 | struct diag_ctrl_event_mask *event_mask; |
| 237 | struct diag_ctrl_log_mask *log_mask; |
| 238 | struct diag_ctrl_msg_mask *msg_mask; |
Ravi Aravamudhan | d09f877 | 2012-12-20 14:48:30 -0800 | [diff] [blame] | 239 | struct diag_ctrl_feature_mask *feature_mask; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 240 | /* State for diag forwarding */ |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 241 | struct diag_smd_info smd_data[NUM_SMD_DATA_CHANNELS]; |
| 242 | struct diag_smd_info smd_cntl[NUM_SMD_CONTROL_CHANNELS]; |
| 243 | struct diag_smd_info smd_dci[NUM_SMD_DCI_CHANNELS]; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 244 | unsigned char *usb_buf_out; |
| 245 | unsigned char *apps_rsp_buf; |
Shalabh Jain | 69890aa | 2011-10-10 12:59:16 -0700 | [diff] [blame] | 246 | unsigned char *user_space_data; |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 247 | /* buffer for updating mask to peripherals */ |
| 248 | unsigned char *buf_msg_mask_update; |
| 249 | unsigned char *buf_log_mask_update; |
| 250 | unsigned char *buf_event_mask_update; |
Ravi Aravamudhan | d09f877 | 2012-12-20 14:48:30 -0800 | [diff] [blame] | 251 | unsigned char *buf_feature_mask_update; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 252 | int read_len_legacy; |
| 253 | unsigned char *hdlc_buf; |
| 254 | unsigned hdlc_count; |
| 255 | unsigned hdlc_escape; |
| 256 | #ifdef CONFIG_DIAG_OVER_USB |
| 257 | int usb_connected; |
| 258 | struct usb_diag_ch *legacy_ch; |
| 259 | struct work_struct diag_proc_hdlc_work; |
| 260 | struct work_struct diag_read_work; |
| 261 | #endif |
| 262 | struct workqueue_struct *diag_wq; |
| 263 | struct work_struct diag_drain_work; |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 264 | struct workqueue_struct *diag_cntl_wq; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 265 | uint8_t *msg_masks; |
| 266 | uint8_t *log_masks; |
| 267 | int log_masks_length; |
| 268 | uint8_t *event_masks; |
Ravi Aravamudhan | d09f877 | 2012-12-20 14:48:30 -0800 | [diff] [blame] | 269 | uint8_t log_on_demand_support; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 270 | struct diag_master_table *table; |
| 271 | uint8_t *pkt_buf; |
| 272 | int pkt_length; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 273 | struct diag_request *usb_read_ptr; |
| 274 | struct diag_request *write_ptr_svc; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 275 | int logging_mode; |
Shalabh Jain | c236f98 | 2011-12-15 22:55:20 -0800 | [diff] [blame] | 276 | int mask_check; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 277 | int logging_process_id; |
Dixon Peterson | 625ee65 | 2012-06-21 22:03:49 -0700 | [diff] [blame] | 278 | struct task_struct *socket_process; |
Shalabh Jain | 84e3034 | 2012-10-16 16:16:08 -0700 | [diff] [blame] | 279 | struct task_struct *callback_process; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 280 | #ifdef CONFIG_DIAG_SDIO_PIPE |
| 281 | unsigned char *buf_in_sdio; |
| 282 | unsigned char *usb_buf_mdm_out; |
| 283 | struct sdio_channel *sdio_ch; |
| 284 | int read_len_mdm; |
| 285 | int in_busy_sdio; |
| 286 | struct usb_diag_ch *mdm_ch; |
| 287 | struct work_struct diag_read_mdm_work; |
| 288 | struct workqueue_struct *diag_sdio_wq; |
| 289 | struct work_struct diag_read_sdio_work; |
Shalabh Jain | 5d9ba34 | 2011-08-10 13:51:54 -0700 | [diff] [blame] | 290 | struct work_struct diag_close_sdio_work; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 291 | struct diag_request *usb_read_mdm_ptr; |
| 292 | struct diag_request *write_ptr_mdm; |
| 293 | #endif |
Shalabh Jain | 737fca7 | 2012-11-14 21:53:43 -0800 | [diff] [blame] | 294 | #ifdef CONFIG_DIAGFWD_BRIDGE_CODE |
| 295 | /* common for all bridges */ |
| 296 | struct work_struct diag_disconnect_work; |
Shalabh Jain | f7228dc | 2012-05-23 17:32:05 -0700 | [diff] [blame] | 297 | /* SGLTE variables */ |
| 298 | int lcid; |
| 299 | unsigned char *buf_in_smux; |
| 300 | int in_busy_smux; |
| 301 | int diag_smux_enabled; |
Ashay Jaiswal | 2d8daae | 2012-07-17 17:29:33 +0530 | [diff] [blame] | 302 | int smux_connected; |
Dixon Peterson | 938f860 | 2012-08-17 20:02:57 -0700 | [diff] [blame] | 303 | struct diag_request *write_ptr_mdm; |
Dixon Peterson | 32e70bb | 2011-12-16 13:26:45 -0800 | [diff] [blame] | 304 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 305 | }; |
| 306 | |
Shalabh Jain | 737fca7 | 2012-11-14 21:53:43 -0800 | [diff] [blame] | 307 | extern struct diag_bridge_dev *diag_bridge; |
Shalabh Jain | b0037c0 | 2013-01-18 12:47:40 -0800 | [diff] [blame] | 308 | extern struct diag_hsic_dev *diag_hsic; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 309 | extern struct diagchar_dev *driver; |
Ravi Aravamudhan | f55dc1d | 2012-12-27 11:51:42 -0800 | [diff] [blame] | 310 | |
| 311 | extern int wrap_enabled; |
| 312 | extern uint16_t wrap_count; |
| 313 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 314 | #endif |