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