blob: 656223bbcb10f3fa21e4ed3e7158c3a9a7a9bb56 [file] [log] [blame]
Dixon Peterson32e70bb2011-12-16 13:26:45 -08001/* Copyright (c) 2008-2012, Code Aurora Forum. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -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/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 Jain321c8b52012-02-22 12:37:06 -080026#define APPS_BUF_SIZE 2000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027#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 Peterson32e70bb2011-12-16 13:26:45 -080043#define HSIC_DATA 6
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070044#define MODEM_PROC 0
45#define APPS_PROC 1
46#define QDSP_PROC 2
47#define WCNSS_PROC 3
Shalabh Jain6a2ca7c2012-04-10 14:35:15 -070048#define MSG_MASK_SIZE 9500
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049#define LOG_MASK_SIZE 8000
50#define EVENT_MASK_SIZE 1000
Shalabh Jain69890aa2011-10-10 12:59:16 -070051#define USER_SPACE_DATA 8000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070052#define PKT_SIZE 4096
Shalabh Jainfbf3bdc2012-03-16 21:02:50 -070053#define MAX_EQUIP_ID 15
Shalabh Jain321c8b52012-02-22 12:37:06 -080054#define DIAG_CTRL_MSG_LOG_MASK 9
55#define DIAG_CTRL_MSG_EVENT_MASK 10
56#define DIAG_CTRL_MSG_F3_MASK 11
Shalabh Jain1c99e4c2012-03-26 18:47:59 -070057#define CONTROL_CHAR 0x7E
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070058
59/* Maximum number of pkt reg supported at initialization*/
Shalabh Jainfe02b0c2012-02-21 14:48:03 -080060extern unsigned int diag_max_reg;
61extern unsigned int diag_threshold_reg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070062
63#define APPEND_DEBUG(ch) \
64do { \
65 diag_debug_buf[diag_debug_buf_idx] = ch; \
66 (diag_debug_buf_idx < 1023) ? \
67 (diag_debug_buf_idx++) : (diag_debug_buf_idx = 0); \
68} while (0)
69
70struct diag_master_table {
71 uint16_t cmd_code;
72 uint16_t subsys_id;
73 uint32_t client_id;
74 uint16_t cmd_code_lo;
75 uint16_t cmd_code_hi;
76 int process_id;
77};
78
79struct bindpkt_params_per_process {
80 /* Name of the synchronization object associated with this proc */
81 char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE];
82 uint32_t count; /* Number of entries in this bind */
83 struct bindpkt_params *params; /* first bind params */
84};
85
86struct bindpkt_params {
87 uint16_t cmd_code;
88 uint16_t subsys_id;
89 uint16_t cmd_code_lo;
90 uint16_t cmd_code_hi;
91 /* For Central Routing, used to store Processor number */
92 uint16_t proc_id;
93 uint32_t event_id;
94 uint32_t log_code;
95 /* For Central Routing, used to store SMD channel pointer */
96 uint32_t client_id;
97};
98
99struct diag_write_device {
100 void *buf;
101 int length;
102};
103
104struct diag_client_map {
105 char name[20];
106 int pid;
107};
108
109/* This structure is defined in USB header file */
110#ifndef CONFIG_DIAG_OVER_USB
111struct diag_request {
112 char *buf;
113 int length;
114 int actual;
115 int status;
116 void *context;
117};
118#endif
119
120struct diagchar_dev {
121
122 /* State for the char driver */
123 unsigned int major;
124 unsigned int minor_start;
125 int num;
126 struct cdev *cdev;
127 char *name;
128 int dropped_count;
129 struct class *diagchar_class;
130 int ref_count;
131 struct mutex diagchar_mutex;
132 wait_queue_head_t wait_q;
133 struct diag_client_map *client_map;
134 int *data_ready;
135 int num_clients;
Shalabh Jain3d29fc32012-02-09 17:15:59 -0800136 int polling_reg_flag;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700137 struct diag_write_device *buf_tbl;
Dixon Petersonb4618a42012-02-29 18:56:31 -0800138 int use_device_tree;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700139 /* DCI related variables */
140 struct diag_dci_tbl *dci_tbl;
141 int dci_tag;
142 int dci_client_id;
143 struct mutex dci_mutex;
144 int num_dci_client;
145 unsigned char *apps_dci_buf;
146 int dci_state;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147 /* Memory pool parameters */
148 unsigned int itemsize;
149 unsigned int poolsize;
150 unsigned int itemsize_hdlc;
151 unsigned int poolsize_hdlc;
152 unsigned int itemsize_write_struct;
153 unsigned int poolsize_write_struct;
154 unsigned int debug_flag;
155 /* State for the mempool for the char driver */
156 mempool_t *diagpool;
157 mempool_t *diag_hdlc_pool;
158 mempool_t *diag_write_struct_pool;
159 struct mutex diagmem_mutex;
160 int count;
161 int count_hdlc_pool;
162 int count_write_struct_pool;
163 int used;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800164 /* Buffers for masks */
165 struct diag_ctrl_event_mask *event_mask;
166 struct diag_ctrl_log_mask *log_mask;
167 struct diag_ctrl_msg_mask *msg_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700168 /* State for diag forwarding */
169 unsigned char *buf_in_1;
170 unsigned char *buf_in_2;
171 unsigned char *buf_in_cntl;
172 unsigned char *buf_in_qdsp_1;
173 unsigned char *buf_in_qdsp_2;
174 unsigned char *buf_in_qdsp_cntl;
Ashay Jaiswal29620122012-03-21 12:02:36 +0530175 unsigned char *buf_in_wcnss_1;
176 unsigned char *buf_in_wcnss_2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700177 unsigned char *buf_in_wcnss_cntl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700178 unsigned char *buf_in_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700179 unsigned char *usb_buf_out;
180 unsigned char *apps_rsp_buf;
Shalabh Jain69890aa2011-10-10 12:59:16 -0700181 unsigned char *user_space_data;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800182 /* buffer for updating mask to peripherals */
183 unsigned char *buf_msg_mask_update;
184 unsigned char *buf_log_mask_update;
185 unsigned char *buf_event_mask_update;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700186 smd_channel_t *ch;
187 smd_channel_t *ch_cntl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700188 smd_channel_t *ch_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189 smd_channel_t *chqdsp;
190 smd_channel_t *chqdsp_cntl;
191 smd_channel_t *ch_wcnss;
192 smd_channel_t *ch_wcnss_cntl;
193 int in_busy_1;
194 int in_busy_2;
195 int in_busy_qdsp_1;
196 int in_busy_qdsp_2;
Ashay Jaiswal29620122012-03-21 12:02:36 +0530197 int in_busy_wcnss_1;
198 int in_busy_wcnss_2;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700199 int in_busy_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700200 int read_len_legacy;
201 unsigned char *hdlc_buf;
202 unsigned hdlc_count;
203 unsigned hdlc_escape;
204#ifdef CONFIG_DIAG_OVER_USB
205 int usb_connected;
206 struct usb_diag_ch *legacy_ch;
207 struct work_struct diag_proc_hdlc_work;
208 struct work_struct diag_read_work;
209#endif
210 struct workqueue_struct *diag_wq;
211 struct work_struct diag_drain_work;
212 struct work_struct diag_read_smd_work;
213 struct work_struct diag_read_smd_cntl_work;
214 struct work_struct diag_read_smd_qdsp_work;
215 struct work_struct diag_read_smd_qdsp_cntl_work;
216 struct work_struct diag_read_smd_wcnss_work;
217 struct work_struct diag_read_smd_wcnss_cntl_work;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800218 struct workqueue_struct *diag_cntl_wq;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800219 struct work_struct diag_modem_mask_update_work;
220 struct work_struct diag_qdsp_mask_update_work;
221 struct work_struct diag_wcnss_mask_update_work;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700222 struct work_struct diag_read_smd_dci_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700223 uint8_t *msg_masks;
224 uint8_t *log_masks;
225 int log_masks_length;
226 uint8_t *event_masks;
227 struct diag_master_table *table;
228 uint8_t *pkt_buf;
229 int pkt_length;
230 struct diag_request *write_ptr_1;
231 struct diag_request *write_ptr_2;
232 struct diag_request *usb_read_ptr;
233 struct diag_request *write_ptr_svc;
234 struct diag_request *write_ptr_qdsp_1;
235 struct diag_request *write_ptr_qdsp_2;
Ashay Jaiswal29620122012-03-21 12:02:36 +0530236 struct diag_request *write_ptr_wcnss_1;
237 struct diag_request *write_ptr_wcnss_2;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700238 struct diag_write_device *write_ptr_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239 int logging_mode;
Shalabh Jainc236f982011-12-15 22:55:20 -0800240 int mask_check;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700241 int logging_process_id;
242#ifdef CONFIG_DIAG_SDIO_PIPE
243 unsigned char *buf_in_sdio;
244 unsigned char *usb_buf_mdm_out;
245 struct sdio_channel *sdio_ch;
246 int read_len_mdm;
247 int in_busy_sdio;
248 struct usb_diag_ch *mdm_ch;
249 struct work_struct diag_read_mdm_work;
250 struct workqueue_struct *diag_sdio_wq;
251 struct work_struct diag_read_sdio_work;
Shalabh Jain5d9ba342011-08-10 13:51:54 -0700252 struct work_struct diag_close_sdio_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700253 struct diag_request *usb_read_mdm_ptr;
254 struct diag_request *write_ptr_mdm;
255#endif
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800256#ifdef CONFIG_DIAG_HSIC_PIPE
257 unsigned char *buf_in_hsic;
258 unsigned char *usb_buf_mdm_out;
259 int hsic_initialized;
260 int hsic_ch;
261 int hsic_device_enabled;
262 int hsic_device_opened;
Jack Phamb60775a2012-02-14 17:57:41 -0800263 int hsic_suspend;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800264 int read_len_mdm;
Dixon Petersonf79b66f2012-04-26 13:21:26 -0700265 int in_busy_hsic_read_on_device;
266 int in_busy_hsic_write_on_device;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800267 int in_busy_hsic_write;
268 int in_busy_hsic_read;
269 int usb_mdm_connected;
270 struct usb_diag_ch *mdm_ch;
271 struct workqueue_struct *diag_hsic_wq;
272 struct work_struct diag_read_mdm_work;
273 struct work_struct diag_read_hsic_work;
Jack Phamb60775a2012-02-14 17:57:41 -0800274 struct work_struct diag_disconnect_work;
275 struct work_struct diag_usb_read_complete_work;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800276 struct diag_request *usb_read_mdm_ptr;
277 struct diag_request *write_ptr_mdm;
278#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700279};
280
281extern struct diagchar_dev *driver;
282#endif