blob: 7e7b51459f79e661c3c9b34c72e3aff781d0e1d8 [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
Shalabh Jainf7228dc2012-05-23 17:32:05 -070044#define SMUX_DATA 7
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070045#define MODEM_PROC 0
46#define APPS_PROC 1
47#define QDSP_PROC 2
48#define WCNSS_PROC 3
Shalabh Jain6a2ca7c2012-04-10 14:35:15 -070049#define MSG_MASK_SIZE 9500
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050#define LOG_MASK_SIZE 8000
51#define EVENT_MASK_SIZE 1000
Shalabh Jain69890aa2011-10-10 12:59:16 -070052#define USER_SPACE_DATA 8000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053#define PKT_SIZE 4096
Shalabh Jainfbf3bdc2012-03-16 21:02:50 -070054#define MAX_EQUIP_ID 15
Shalabh Jain321c8b52012-02-22 12:37:06 -080055#define DIAG_CTRL_MSG_LOG_MASK 9
56#define DIAG_CTRL_MSG_EVENT_MASK 10
57#define DIAG_CTRL_MSG_F3_MASK 11
Shalabh Jain1c99e4c2012-03-26 18:47:59 -070058#define CONTROL_CHAR 0x7E
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059
60/* Maximum number of pkt reg supported at initialization*/
Shalabh Jainfe02b0c2012-02-21 14:48:03 -080061extern unsigned int diag_max_reg;
62extern unsigned int diag_threshold_reg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070063
64#define APPEND_DEBUG(ch) \
65do { \
66 diag_debug_buf[diag_debug_buf_idx] = ch; \
67 (diag_debug_buf_idx < 1023) ? \
68 (diag_debug_buf_idx++) : (diag_debug_buf_idx = 0); \
69} while (0)
70
71struct diag_master_table {
72 uint16_t cmd_code;
73 uint16_t subsys_id;
74 uint32_t client_id;
75 uint16_t cmd_code_lo;
76 uint16_t cmd_code_hi;
77 int process_id;
78};
79
80struct bindpkt_params_per_process {
81 /* Name of the synchronization object associated with this proc */
82 char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE];
83 uint32_t count; /* Number of entries in this bind */
84 struct bindpkt_params *params; /* first bind params */
85};
86
87struct bindpkt_params {
88 uint16_t cmd_code;
89 uint16_t subsys_id;
90 uint16_t cmd_code_lo;
91 uint16_t cmd_code_hi;
92 /* For Central Routing, used to store Processor number */
93 uint16_t proc_id;
94 uint32_t event_id;
95 uint32_t log_code;
96 /* For Central Routing, used to store SMD channel pointer */
97 uint32_t client_id;
98};
99
100struct diag_write_device {
101 void *buf;
102 int length;
103};
104
105struct diag_client_map {
106 char name[20];
107 int pid;
108};
109
110/* This structure is defined in USB header file */
111#ifndef CONFIG_DIAG_OVER_USB
112struct diag_request {
113 char *buf;
114 int length;
115 int actual;
116 int status;
117 void *context;
118};
119#endif
120
121struct diagchar_dev {
122
123 /* State for the char driver */
124 unsigned int major;
125 unsigned int minor_start;
126 int num;
127 struct cdev *cdev;
128 char *name;
129 int dropped_count;
130 struct class *diagchar_class;
131 int ref_count;
132 struct mutex diagchar_mutex;
133 wait_queue_head_t wait_q;
134 struct diag_client_map *client_map;
135 int *data_ready;
136 int num_clients;
Shalabh Jain3d29fc32012-02-09 17:15:59 -0800137 int polling_reg_flag;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700138 struct diag_write_device *buf_tbl;
Dixon Petersonb4618a42012-02-29 18:56:31 -0800139 int use_device_tree;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700140 /* DCI related variables */
141 struct diag_dci_tbl *dci_tbl;
142 int dci_tag;
143 int dci_client_id;
144 struct mutex dci_mutex;
145 int num_dci_client;
146 unsigned char *apps_dci_buf;
147 int dci_state;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700148 /* Memory pool parameters */
149 unsigned int itemsize;
150 unsigned int poolsize;
151 unsigned int itemsize_hdlc;
152 unsigned int poolsize_hdlc;
153 unsigned int itemsize_write_struct;
154 unsigned int poolsize_write_struct;
155 unsigned int debug_flag;
156 /* State for the mempool for the char driver */
157 mempool_t *diagpool;
158 mempool_t *diag_hdlc_pool;
159 mempool_t *diag_write_struct_pool;
160 struct mutex diagmem_mutex;
161 int count;
162 int count_hdlc_pool;
163 int count_write_struct_pool;
164 int used;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800165 /* Buffers for masks */
Shalabh Jaina06c6d72012-04-30 13:40:35 -0700166 struct mutex diag_cntl_mutex;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800167 struct diag_ctrl_event_mask *event_mask;
168 struct diag_ctrl_log_mask *log_mask;
169 struct diag_ctrl_msg_mask *msg_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700170 /* State for diag forwarding */
171 unsigned char *buf_in_1;
172 unsigned char *buf_in_2;
173 unsigned char *buf_in_cntl;
174 unsigned char *buf_in_qdsp_1;
175 unsigned char *buf_in_qdsp_2;
176 unsigned char *buf_in_qdsp_cntl;
Ashay Jaiswal29620122012-03-21 12:02:36 +0530177 unsigned char *buf_in_wcnss_1;
178 unsigned char *buf_in_wcnss_2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700179 unsigned char *buf_in_wcnss_cntl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700180 unsigned char *buf_in_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181 unsigned char *usb_buf_out;
182 unsigned char *apps_rsp_buf;
Shalabh Jain69890aa2011-10-10 12:59:16 -0700183 unsigned char *user_space_data;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800184 /* buffer for updating mask to peripherals */
185 unsigned char *buf_msg_mask_update;
186 unsigned char *buf_log_mask_update;
187 unsigned char *buf_event_mask_update;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188 smd_channel_t *ch;
189 smd_channel_t *ch_cntl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700190 smd_channel_t *ch_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700191 smd_channel_t *chqdsp;
192 smd_channel_t *chqdsp_cntl;
193 smd_channel_t *ch_wcnss;
194 smd_channel_t *ch_wcnss_cntl;
195 int in_busy_1;
196 int in_busy_2;
197 int in_busy_qdsp_1;
198 int in_busy_qdsp_2;
Ashay Jaiswal29620122012-03-21 12:02:36 +0530199 int in_busy_wcnss_1;
200 int in_busy_wcnss_2;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700201 int in_busy_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700202 int read_len_legacy;
203 unsigned char *hdlc_buf;
204 unsigned hdlc_count;
205 unsigned hdlc_escape;
206#ifdef CONFIG_DIAG_OVER_USB
207 int usb_connected;
208 struct usb_diag_ch *legacy_ch;
209 struct work_struct diag_proc_hdlc_work;
210 struct work_struct diag_read_work;
211#endif
212 struct workqueue_struct *diag_wq;
213 struct work_struct diag_drain_work;
214 struct work_struct diag_read_smd_work;
215 struct work_struct diag_read_smd_cntl_work;
216 struct work_struct diag_read_smd_qdsp_work;
217 struct work_struct diag_read_smd_qdsp_cntl_work;
218 struct work_struct diag_read_smd_wcnss_work;
219 struct work_struct diag_read_smd_wcnss_cntl_work;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800220 struct workqueue_struct *diag_cntl_wq;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800221 struct work_struct diag_modem_mask_update_work;
222 struct work_struct diag_qdsp_mask_update_work;
223 struct work_struct diag_wcnss_mask_update_work;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700224 struct work_struct diag_read_smd_dci_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700225 uint8_t *msg_masks;
226 uint8_t *log_masks;
227 int log_masks_length;
228 uint8_t *event_masks;
229 struct diag_master_table *table;
230 uint8_t *pkt_buf;
231 int pkt_length;
232 struct diag_request *write_ptr_1;
233 struct diag_request *write_ptr_2;
234 struct diag_request *usb_read_ptr;
235 struct diag_request *write_ptr_svc;
236 struct diag_request *write_ptr_qdsp_1;
237 struct diag_request *write_ptr_qdsp_2;
Ashay Jaiswal29620122012-03-21 12:02:36 +0530238 struct diag_request *write_ptr_wcnss_1;
239 struct diag_request *write_ptr_wcnss_2;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700240 struct diag_write_device *write_ptr_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700241 int logging_mode;
Shalabh Jainc236f982011-12-15 22:55:20 -0800242 int mask_check;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700243 int logging_process_id;
244#ifdef CONFIG_DIAG_SDIO_PIPE
245 unsigned char *buf_in_sdio;
246 unsigned char *usb_buf_mdm_out;
247 struct sdio_channel *sdio_ch;
248 int read_len_mdm;
249 int in_busy_sdio;
250 struct usb_diag_ch *mdm_ch;
251 struct work_struct diag_read_mdm_work;
252 struct workqueue_struct *diag_sdio_wq;
253 struct work_struct diag_read_sdio_work;
Shalabh Jain5d9ba342011-08-10 13:51:54 -0700254 struct work_struct diag_close_sdio_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700255 struct diag_request *usb_read_mdm_ptr;
256 struct diag_request *write_ptr_mdm;
257#endif
Shalabh Jainf7228dc2012-05-23 17:32:05 -0700258#ifdef CONFIG_DIAG_BRIDGE_CODE
259 /* SGLTE variables */
260 int lcid;
261 unsigned char *buf_in_smux;
262 int in_busy_smux;
263 int diag_smux_enabled;
264 /* HSIC variables */
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800265 unsigned char *buf_in_hsic;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800266 int hsic_ch;
267 int hsic_device_enabled;
268 int hsic_device_opened;
Jack Phamb60775a2012-02-14 17:57:41 -0800269 int hsic_suspend;
Dixon Petersonf79b66f2012-04-26 13:21:26 -0700270 int in_busy_hsic_read_on_device;
271 int in_busy_hsic_write_on_device;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800272 int in_busy_hsic_write;
273 int in_busy_hsic_read;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800274 struct work_struct diag_read_hsic_work;
Shalabh Jainf7228dc2012-05-23 17:32:05 -0700275 /* USB MDM channel variables */
276 int usb_mdm_connected;
277 int read_len_mdm;
278 unsigned char *usb_buf_mdm_out;
279 struct usb_diag_ch *mdm_ch;
280 struct workqueue_struct *diag_bridge_wq;
281 struct work_struct diag_read_mdm_work;
Jack Phamb60775a2012-02-14 17:57:41 -0800282 struct work_struct diag_disconnect_work;
283 struct work_struct diag_usb_read_complete_work;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800284 struct diag_request *usb_read_mdm_ptr;
285 struct diag_request *write_ptr_mdm;
286#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700287};
288
289extern struct diagchar_dev *driver;
290#endif