blob: 6a7b931321d70c104d51f3ad3a662f9c0d347d40 [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>
Shalabh Jain5e9a92b2012-06-07 21:53:49 -070021#include <linux/sched.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070022#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 Jain321c8b52012-02-22 12:37:06 -080027#define APPS_BUF_SIZE 2000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028#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 Peterson32e70bb2011-12-16 13:26:45 -080044#define HSIC_DATA 6
Shalabh Jainf7228dc2012-05-23 17:32:05 -070045#define SMUX_DATA 7
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070046#define MODEM_PROC 0
47#define APPS_PROC 1
48#define QDSP_PROC 2
49#define WCNSS_PROC 3
Shalabh Jain6a2ca7c2012-04-10 14:35:15 -070050#define MSG_MASK_SIZE 9500
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051#define LOG_MASK_SIZE 8000
52#define EVENT_MASK_SIZE 1000
Shalabh Jain69890aa2011-10-10 12:59:16 -070053#define USER_SPACE_DATA 8000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070054#define PKT_SIZE 4096
Shalabh Jainfbf3bdc2012-03-16 21:02:50 -070055#define MAX_EQUIP_ID 15
Shalabh Jain321c8b52012-02-22 12:37:06 -080056#define DIAG_CTRL_MSG_LOG_MASK 9
57#define DIAG_CTRL_MSG_EVENT_MASK 10
58#define DIAG_CTRL_MSG_F3_MASK 11
Shalabh Jain1c99e4c2012-03-26 18:47:59 -070059#define CONTROL_CHAR 0x7E
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060
61/* Maximum number of pkt reg supported at initialization*/
Shalabh Jainfe02b0c2012-02-21 14:48:03 -080062extern unsigned int diag_max_reg;
63extern unsigned int diag_threshold_reg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064
65#define APPEND_DEBUG(ch) \
66do { \
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
72struct 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
81struct 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
88struct 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
101struct diag_write_device {
102 void *buf;
103 int length;
104};
105
106struct 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
113struct diag_request {
114 char *buf;
115 int length;
116 int actual;
117 int status;
118 void *context;
119};
120#endif
121
122struct 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 Jain3d29fc32012-02-09 17:15:59 -0800138 int polling_reg_flag;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700139 struct diag_write_device *buf_tbl;
Dixon Petersonb4618a42012-02-29 18:56:31 -0800140 int use_device_tree;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700141 /* DCI related variables */
142 struct diag_dci_tbl *dci_tbl;
Shalabh Jain5e9a92b2012-06-07 21:53:49 -0700143 struct dci_notification_tbl *dci_notify_tbl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700144 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 Huntsman3f2bc4d2011-08-16 17:27:22 -0700150 /* 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 Jain321c8b52012-02-22 12:37:06 -0800167 /* Buffers for masks */
Shalabh Jaina06c6d72012-04-30 13:40:35 -0700168 struct mutex diag_cntl_mutex;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800169 struct diag_ctrl_event_mask *event_mask;
170 struct diag_ctrl_log_mask *log_mask;
171 struct diag_ctrl_msg_mask *msg_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700172 /* 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 Jaiswal29620122012-03-21 12:02:36 +0530179 unsigned char *buf_in_wcnss_1;
180 unsigned char *buf_in_wcnss_2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181 unsigned char *buf_in_wcnss_cntl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700182 unsigned char *buf_in_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700183 unsigned char *usb_buf_out;
184 unsigned char *apps_rsp_buf;
Shalabh Jain69890aa2011-10-10 12:59:16 -0700185 unsigned char *user_space_data;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800186 /* 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 Huntsman3f2bc4d2011-08-16 17:27:22 -0700190 smd_channel_t *ch;
191 smd_channel_t *ch_cntl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700192 smd_channel_t *ch_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700193 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 Jaiswal29620122012-03-21 12:02:36 +0530201 int in_busy_wcnss_1;
202 int in_busy_wcnss_2;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700203 int in_busy_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700204 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 Jain321c8b52012-02-22 12:37:06 -0800222 struct workqueue_struct *diag_cntl_wq;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800223 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 Jain1c99e4c2012-03-26 18:47:59 -0700226 struct work_struct diag_read_smd_dci_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227 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 Jaiswal29620122012-03-21 12:02:36 +0530240 struct diag_request *write_ptr_wcnss_1;
241 struct diag_request *write_ptr_wcnss_2;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700242 struct diag_write_device *write_ptr_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700243 int logging_mode;
Shalabh Jainc236f982011-12-15 22:55:20 -0800244 int mask_check;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700245 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 Jain5d9ba342011-08-10 13:51:54 -0700256 struct work_struct diag_close_sdio_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700257 struct diag_request *usb_read_mdm_ptr;
258 struct diag_request *write_ptr_mdm;
259#endif
Shalabh Jainf7228dc2012-05-23 17:32:05 -0700260#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 Peterson32e70bb2011-12-16 13:26:45 -0800267 unsigned char *buf_in_hsic;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800268 int hsic_ch;
269 int hsic_device_enabled;
270 int hsic_device_opened;
Jack Phamb60775a2012-02-14 17:57:41 -0800271 int hsic_suspend;
Dixon Petersonf79b66f2012-04-26 13:21:26 -0700272 int in_busy_hsic_read_on_device;
273 int in_busy_hsic_write_on_device;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800274 int in_busy_hsic_write;
275 int in_busy_hsic_read;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800276 struct work_struct diag_read_hsic_work;
Shalabh Jainf7228dc2012-05-23 17:32:05 -0700277 /* 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 Phamb60775a2012-02-14 17:57:41 -0800284 struct work_struct diag_disconnect_work;
285 struct work_struct diag_usb_read_complete_work;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800286 struct diag_request *usb_read_mdm_ptr;
287 struct diag_request *write_ptr_mdm;
288#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700289};
290
291extern struct diagchar_dev *driver;
292#endif