Dixon Peterson | 32e70bb | 2011-12-16 13:26:45 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2008-2012, Code Aurora Forum. 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> |
| 20 | #include <linux/workqueue.h> |
Shalabh Jain | 5e9a92b | 2012-06-07 21:53:49 -0700 | [diff] [blame] | 21 | #include <linux/sched.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | #include <mach/msm_smd.h> |
| 23 | #include <asm/atomic.h> |
| 24 | #include <asm/mach-types.h> |
| 25 | /* Size of the USB buffers used for read and write*/ |
| 26 | #define USB_MAX_OUT_BUF 4096 |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 27 | #define APPS_BUF_SIZE 2000 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 28 | #define IN_BUF_SIZE 16384 |
| 29 | #define MAX_IN_BUF_SIZE 32768 |
| 30 | #define MAX_SYNC_OBJ_NAME_SIZE 32 |
| 31 | /* Size of the buffer used for deframing a packet |
| 32 | reveived from the PC tool*/ |
| 33 | #define HDLC_MAX 4096 |
| 34 | #define HDLC_OUT_BUF_SIZE 8192 |
| 35 | #define POOL_TYPE_COPY 1 |
| 36 | #define POOL_TYPE_HDLC 2 |
| 37 | #define POOL_TYPE_WRITE_STRUCT 4 |
| 38 | #define POOL_TYPE_ALL 7 |
| 39 | #define MODEM_DATA 1 |
| 40 | #define QDSP_DATA 2 |
| 41 | #define APPS_DATA 3 |
| 42 | #define SDIO_DATA 4 |
| 43 | #define WCNSS_DATA 5 |
Dixon Peterson | 32e70bb | 2011-12-16 13:26:45 -0800 | [diff] [blame] | 44 | #define HSIC_DATA 6 |
Shalabh Jain | f7228dc | 2012-05-23 17:32:05 -0700 | [diff] [blame] | 45 | #define SMUX_DATA 7 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 46 | #define MODEM_PROC 0 |
| 47 | #define APPS_PROC 1 |
| 48 | #define QDSP_PROC 2 |
| 49 | #define WCNSS_PROC 3 |
Shalabh Jain | 6a2ca7c | 2012-04-10 14:35:15 -0700 | [diff] [blame] | 50 | #define MSG_MASK_SIZE 9500 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 51 | #define LOG_MASK_SIZE 8000 |
| 52 | #define EVENT_MASK_SIZE 1000 |
Shalabh Jain | 69890aa | 2011-10-10 12:59:16 -0700 | [diff] [blame] | 53 | #define USER_SPACE_DATA 8000 |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 54 | #define PKT_SIZE 4096 |
Shalabh Jain | fbf3bdc | 2012-03-16 21:02:50 -0700 | [diff] [blame] | 55 | #define MAX_EQUIP_ID 15 |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 56 | #define DIAG_CTRL_MSG_LOG_MASK 9 |
| 57 | #define DIAG_CTRL_MSG_EVENT_MASK 10 |
| 58 | #define DIAG_CTRL_MSG_F3_MASK 11 |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 59 | #define CONTROL_CHAR 0x7E |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 60 | |
| 61 | /* Maximum number of pkt reg supported at initialization*/ |
Shalabh Jain | fe02b0c | 2012-02-21 14:48:03 -0800 | [diff] [blame] | 62 | extern unsigned int diag_max_reg; |
| 63 | extern unsigned int diag_threshold_reg; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 64 | |
| 65 | #define APPEND_DEBUG(ch) \ |
| 66 | do { \ |
| 67 | diag_debug_buf[diag_debug_buf_idx] = ch; \ |
| 68 | (diag_debug_buf_idx < 1023) ? \ |
| 69 | (diag_debug_buf_idx++) : (diag_debug_buf_idx = 0); \ |
| 70 | } while (0) |
| 71 | |
| 72 | struct diag_master_table { |
| 73 | uint16_t cmd_code; |
| 74 | uint16_t subsys_id; |
| 75 | uint32_t client_id; |
| 76 | uint16_t cmd_code_lo; |
| 77 | uint16_t cmd_code_hi; |
| 78 | int process_id; |
| 79 | }; |
| 80 | |
| 81 | struct bindpkt_params_per_process { |
| 82 | /* Name of the synchronization object associated with this proc */ |
| 83 | char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE]; |
| 84 | uint32_t count; /* Number of entries in this bind */ |
| 85 | struct bindpkt_params *params; /* first bind params */ |
| 86 | }; |
| 87 | |
| 88 | struct bindpkt_params { |
| 89 | uint16_t cmd_code; |
| 90 | uint16_t subsys_id; |
| 91 | uint16_t cmd_code_lo; |
| 92 | uint16_t cmd_code_hi; |
| 93 | /* For Central Routing, used to store Processor number */ |
| 94 | uint16_t proc_id; |
| 95 | uint32_t event_id; |
| 96 | uint32_t log_code; |
| 97 | /* For Central Routing, used to store SMD channel pointer */ |
| 98 | uint32_t client_id; |
| 99 | }; |
| 100 | |
| 101 | struct diag_write_device { |
| 102 | void *buf; |
| 103 | int length; |
| 104 | }; |
| 105 | |
| 106 | struct diag_client_map { |
| 107 | char name[20]; |
| 108 | int pid; |
| 109 | }; |
| 110 | |
| 111 | /* This structure is defined in USB header file */ |
| 112 | #ifndef CONFIG_DIAG_OVER_USB |
| 113 | struct diag_request { |
| 114 | char *buf; |
| 115 | int length; |
| 116 | int actual; |
| 117 | int status; |
| 118 | void *context; |
| 119 | }; |
| 120 | #endif |
| 121 | |
| 122 | struct diagchar_dev { |
| 123 | |
| 124 | /* State for the char driver */ |
| 125 | unsigned int major; |
| 126 | unsigned int minor_start; |
| 127 | int num; |
| 128 | struct cdev *cdev; |
| 129 | char *name; |
| 130 | int dropped_count; |
| 131 | struct class *diagchar_class; |
| 132 | int ref_count; |
| 133 | struct mutex diagchar_mutex; |
| 134 | wait_queue_head_t wait_q; |
| 135 | struct diag_client_map *client_map; |
| 136 | int *data_ready; |
| 137 | int num_clients; |
Shalabh Jain | 3d29fc3 | 2012-02-09 17:15:59 -0800 | [diff] [blame] | 138 | int polling_reg_flag; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 139 | struct diag_write_device *buf_tbl; |
Dixon Peterson | b4618a4 | 2012-02-29 18:56:31 -0800 | [diff] [blame] | 140 | int use_device_tree; |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 141 | /* DCI related variables */ |
| 142 | struct diag_dci_tbl *dci_tbl; |
Shalabh Jain | 5e9a92b | 2012-06-07 21:53:49 -0700 | [diff] [blame] | 143 | struct dci_notification_tbl *dci_notify_tbl; |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 144 | int dci_tag; |
| 145 | int dci_client_id; |
| 146 | struct mutex dci_mutex; |
| 147 | int num_dci_client; |
| 148 | unsigned char *apps_dci_buf; |
| 149 | int dci_state; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 150 | /* Memory pool parameters */ |
| 151 | unsigned int itemsize; |
| 152 | unsigned int poolsize; |
| 153 | unsigned int itemsize_hdlc; |
| 154 | unsigned int poolsize_hdlc; |
| 155 | unsigned int itemsize_write_struct; |
| 156 | unsigned int poolsize_write_struct; |
| 157 | unsigned int debug_flag; |
| 158 | /* State for the mempool for the char driver */ |
| 159 | mempool_t *diagpool; |
| 160 | mempool_t *diag_hdlc_pool; |
| 161 | mempool_t *diag_write_struct_pool; |
| 162 | struct mutex diagmem_mutex; |
| 163 | int count; |
| 164 | int count_hdlc_pool; |
| 165 | int count_write_struct_pool; |
| 166 | int used; |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 167 | /* Buffers for masks */ |
Shalabh Jain | a06c6d7 | 2012-04-30 13:40:35 -0700 | [diff] [blame] | 168 | struct mutex diag_cntl_mutex; |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 169 | struct diag_ctrl_event_mask *event_mask; |
| 170 | struct diag_ctrl_log_mask *log_mask; |
| 171 | struct diag_ctrl_msg_mask *msg_mask; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 172 | /* State for diag forwarding */ |
| 173 | unsigned char *buf_in_1; |
| 174 | unsigned char *buf_in_2; |
| 175 | unsigned char *buf_in_cntl; |
| 176 | unsigned char *buf_in_qdsp_1; |
| 177 | unsigned char *buf_in_qdsp_2; |
| 178 | unsigned char *buf_in_qdsp_cntl; |
Ashay Jaiswal | 2962012 | 2012-03-21 12:02:36 +0530 | [diff] [blame] | 179 | unsigned char *buf_in_wcnss_1; |
| 180 | unsigned char *buf_in_wcnss_2; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 181 | unsigned char *buf_in_wcnss_cntl; |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 182 | unsigned char *buf_in_dci; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 183 | unsigned char *usb_buf_out; |
| 184 | unsigned char *apps_rsp_buf; |
Shalabh Jain | 69890aa | 2011-10-10 12:59:16 -0700 | [diff] [blame] | 185 | unsigned char *user_space_data; |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 186 | /* buffer for updating mask to peripherals */ |
| 187 | unsigned char *buf_msg_mask_update; |
| 188 | unsigned char *buf_log_mask_update; |
| 189 | unsigned char *buf_event_mask_update; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 190 | smd_channel_t *ch; |
| 191 | smd_channel_t *ch_cntl; |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 192 | smd_channel_t *ch_dci; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 193 | smd_channel_t *chqdsp; |
| 194 | smd_channel_t *chqdsp_cntl; |
| 195 | smd_channel_t *ch_wcnss; |
| 196 | smd_channel_t *ch_wcnss_cntl; |
| 197 | int in_busy_1; |
| 198 | int in_busy_2; |
| 199 | int in_busy_qdsp_1; |
| 200 | int in_busy_qdsp_2; |
Ashay Jaiswal | 2962012 | 2012-03-21 12:02:36 +0530 | [diff] [blame] | 201 | int in_busy_wcnss_1; |
| 202 | int in_busy_wcnss_2; |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 203 | int in_busy_dci; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 204 | int read_len_legacy; |
| 205 | unsigned char *hdlc_buf; |
| 206 | unsigned hdlc_count; |
| 207 | unsigned hdlc_escape; |
| 208 | #ifdef CONFIG_DIAG_OVER_USB |
| 209 | int usb_connected; |
| 210 | struct usb_diag_ch *legacy_ch; |
| 211 | struct work_struct diag_proc_hdlc_work; |
| 212 | struct work_struct diag_read_work; |
| 213 | #endif |
| 214 | struct workqueue_struct *diag_wq; |
| 215 | struct work_struct diag_drain_work; |
| 216 | struct work_struct diag_read_smd_work; |
| 217 | struct work_struct diag_read_smd_cntl_work; |
| 218 | struct work_struct diag_read_smd_qdsp_work; |
| 219 | struct work_struct diag_read_smd_qdsp_cntl_work; |
| 220 | struct work_struct diag_read_smd_wcnss_work; |
| 221 | struct work_struct diag_read_smd_wcnss_cntl_work; |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 222 | struct workqueue_struct *diag_cntl_wq; |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 223 | struct work_struct diag_modem_mask_update_work; |
| 224 | struct work_struct diag_qdsp_mask_update_work; |
| 225 | struct work_struct diag_wcnss_mask_update_work; |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 226 | struct work_struct diag_read_smd_dci_work; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 227 | uint8_t *msg_masks; |
| 228 | uint8_t *log_masks; |
| 229 | int log_masks_length; |
| 230 | uint8_t *event_masks; |
| 231 | struct diag_master_table *table; |
| 232 | uint8_t *pkt_buf; |
| 233 | int pkt_length; |
| 234 | struct diag_request *write_ptr_1; |
| 235 | struct diag_request *write_ptr_2; |
| 236 | struct diag_request *usb_read_ptr; |
| 237 | struct diag_request *write_ptr_svc; |
| 238 | struct diag_request *write_ptr_qdsp_1; |
| 239 | struct diag_request *write_ptr_qdsp_2; |
Ashay Jaiswal | 2962012 | 2012-03-21 12:02:36 +0530 | [diff] [blame] | 240 | struct diag_request *write_ptr_wcnss_1; |
| 241 | struct diag_request *write_ptr_wcnss_2; |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 242 | struct diag_write_device *write_ptr_dci; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 243 | int logging_mode; |
Shalabh Jain | c236f98 | 2011-12-15 22:55:20 -0800 | [diff] [blame] | 244 | int mask_check; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 245 | int logging_process_id; |
| 246 | #ifdef CONFIG_DIAG_SDIO_PIPE |
| 247 | unsigned char *buf_in_sdio; |
| 248 | unsigned char *usb_buf_mdm_out; |
| 249 | struct sdio_channel *sdio_ch; |
| 250 | int read_len_mdm; |
| 251 | int in_busy_sdio; |
| 252 | struct usb_diag_ch *mdm_ch; |
| 253 | struct work_struct diag_read_mdm_work; |
| 254 | struct workqueue_struct *diag_sdio_wq; |
| 255 | struct work_struct diag_read_sdio_work; |
Shalabh Jain | 5d9ba34 | 2011-08-10 13:51:54 -0700 | [diff] [blame] | 256 | struct work_struct diag_close_sdio_work; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 257 | struct diag_request *usb_read_mdm_ptr; |
| 258 | struct diag_request *write_ptr_mdm; |
| 259 | #endif |
Shalabh Jain | f7228dc | 2012-05-23 17:32:05 -0700 | [diff] [blame] | 260 | #ifdef CONFIG_DIAG_BRIDGE_CODE |
| 261 | /* SGLTE variables */ |
| 262 | int lcid; |
| 263 | unsigned char *buf_in_smux; |
| 264 | int in_busy_smux; |
| 265 | int diag_smux_enabled; |
| 266 | /* HSIC variables */ |
Dixon Peterson | 32e70bb | 2011-12-16 13:26:45 -0800 | [diff] [blame] | 267 | unsigned char *buf_in_hsic; |
Dixon Peterson | 32e70bb | 2011-12-16 13:26:45 -0800 | [diff] [blame] | 268 | int hsic_ch; |
| 269 | int hsic_device_enabled; |
| 270 | int hsic_device_opened; |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 271 | int hsic_suspend; |
Dixon Peterson | f79b66f | 2012-04-26 13:21:26 -0700 | [diff] [blame] | 272 | int in_busy_hsic_read_on_device; |
| 273 | int in_busy_hsic_write_on_device; |
Dixon Peterson | 32e70bb | 2011-12-16 13:26:45 -0800 | [diff] [blame] | 274 | int in_busy_hsic_write; |
| 275 | int in_busy_hsic_read; |
Dixon Peterson | 32e70bb | 2011-12-16 13:26:45 -0800 | [diff] [blame] | 276 | struct work_struct diag_read_hsic_work; |
Shalabh Jain | f7228dc | 2012-05-23 17:32:05 -0700 | [diff] [blame] | 277 | /* USB MDM channel variables */ |
| 278 | int usb_mdm_connected; |
| 279 | int read_len_mdm; |
| 280 | unsigned char *usb_buf_mdm_out; |
| 281 | struct usb_diag_ch *mdm_ch; |
| 282 | struct workqueue_struct *diag_bridge_wq; |
| 283 | struct work_struct diag_read_mdm_work; |
Jack Pham | b60775a | 2012-02-14 17:57:41 -0800 | [diff] [blame] | 284 | struct work_struct diag_disconnect_work; |
| 285 | struct work_struct diag_usb_read_complete_work; |
Dixon Peterson | 32e70bb | 2011-12-16 13:26:45 -0800 | [diff] [blame] | 286 | struct diag_request *usb_read_mdm_ptr; |
| 287 | struct diag_request *write_ptr_mdm; |
| 288 | #endif |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 289 | }; |
| 290 | |
| 291 | extern struct diagchar_dev *driver; |
| 292 | #endif |