blob: 49d687d99a714f22515cc9caee1170fa1b31be88 [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 */
Shalabh Jaina06c6d72012-04-30 13:40:35 -0700165 struct mutex diag_cntl_mutex;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800166 struct diag_ctrl_event_mask *event_mask;
167 struct diag_ctrl_log_mask *log_mask;
168 struct diag_ctrl_msg_mask *msg_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700169 /* State for diag forwarding */
170 unsigned char *buf_in_1;
171 unsigned char *buf_in_2;
172 unsigned char *buf_in_cntl;
173 unsigned char *buf_in_qdsp_1;
174 unsigned char *buf_in_qdsp_2;
175 unsigned char *buf_in_qdsp_cntl;
Ashay Jaiswal29620122012-03-21 12:02:36 +0530176 unsigned char *buf_in_wcnss_1;
177 unsigned char *buf_in_wcnss_2;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178 unsigned char *buf_in_wcnss_cntl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700179 unsigned char *buf_in_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180 unsigned char *usb_buf_out;
181 unsigned char *apps_rsp_buf;
Shalabh Jain69890aa2011-10-10 12:59:16 -0700182 unsigned char *user_space_data;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800183 /* buffer for updating mask to peripherals */
184 unsigned char *buf_msg_mask_update;
185 unsigned char *buf_log_mask_update;
186 unsigned char *buf_event_mask_update;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187 smd_channel_t *ch;
188 smd_channel_t *ch_cntl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700189 smd_channel_t *ch_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700190 smd_channel_t *chqdsp;
191 smd_channel_t *chqdsp_cntl;
192 smd_channel_t *ch_wcnss;
193 smd_channel_t *ch_wcnss_cntl;
194 int in_busy_1;
195 int in_busy_2;
196 int in_busy_qdsp_1;
197 int in_busy_qdsp_2;
Ashay Jaiswal29620122012-03-21 12:02:36 +0530198 int in_busy_wcnss_1;
199 int in_busy_wcnss_2;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700200 int in_busy_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700201 int read_len_legacy;
202 unsigned char *hdlc_buf;
203 unsigned hdlc_count;
204 unsigned hdlc_escape;
205#ifdef CONFIG_DIAG_OVER_USB
206 int usb_connected;
207 struct usb_diag_ch *legacy_ch;
208 struct work_struct diag_proc_hdlc_work;
209 struct work_struct diag_read_work;
210#endif
211 struct workqueue_struct *diag_wq;
212 struct work_struct diag_drain_work;
213 struct work_struct diag_read_smd_work;
214 struct work_struct diag_read_smd_cntl_work;
215 struct work_struct diag_read_smd_qdsp_work;
216 struct work_struct diag_read_smd_qdsp_cntl_work;
217 struct work_struct diag_read_smd_wcnss_work;
218 struct work_struct diag_read_smd_wcnss_cntl_work;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800219 struct workqueue_struct *diag_cntl_wq;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800220 struct work_struct diag_modem_mask_update_work;
221 struct work_struct diag_qdsp_mask_update_work;
222 struct work_struct diag_wcnss_mask_update_work;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700223 struct work_struct diag_read_smd_dci_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700224 uint8_t *msg_masks;
225 uint8_t *log_masks;
226 int log_masks_length;
227 uint8_t *event_masks;
228 struct diag_master_table *table;
229 uint8_t *pkt_buf;
230 int pkt_length;
231 struct diag_request *write_ptr_1;
232 struct diag_request *write_ptr_2;
233 struct diag_request *usb_read_ptr;
234 struct diag_request *write_ptr_svc;
235 struct diag_request *write_ptr_qdsp_1;
236 struct diag_request *write_ptr_qdsp_2;
Ashay Jaiswal29620122012-03-21 12:02:36 +0530237 struct diag_request *write_ptr_wcnss_1;
238 struct diag_request *write_ptr_wcnss_2;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700239 struct diag_write_device *write_ptr_dci;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700240 int logging_mode;
Shalabh Jainc236f982011-12-15 22:55:20 -0800241 int mask_check;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700242 int logging_process_id;
243#ifdef CONFIG_DIAG_SDIO_PIPE
244 unsigned char *buf_in_sdio;
245 unsigned char *usb_buf_mdm_out;
246 struct sdio_channel *sdio_ch;
247 int read_len_mdm;
248 int in_busy_sdio;
249 struct usb_diag_ch *mdm_ch;
250 struct work_struct diag_read_mdm_work;
251 struct workqueue_struct *diag_sdio_wq;
252 struct work_struct diag_read_sdio_work;
Shalabh Jain5d9ba342011-08-10 13:51:54 -0700253 struct work_struct diag_close_sdio_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700254 struct diag_request *usb_read_mdm_ptr;
255 struct diag_request *write_ptr_mdm;
256#endif
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800257#ifdef CONFIG_DIAG_HSIC_PIPE
258 unsigned char *buf_in_hsic;
259 unsigned char *usb_buf_mdm_out;
260 int hsic_initialized;
261 int hsic_ch;
262 int hsic_device_enabled;
263 int hsic_device_opened;
Jack Phamb60775a2012-02-14 17:57:41 -0800264 int hsic_suspend;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800265 int read_len_mdm;
Dixon Petersonf79b66f2012-04-26 13:21:26 -0700266 int in_busy_hsic_read_on_device;
267 int in_busy_hsic_write_on_device;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800268 int in_busy_hsic_write;
269 int in_busy_hsic_read;
270 int usb_mdm_connected;
271 struct usb_diag_ch *mdm_ch;
272 struct workqueue_struct *diag_hsic_wq;
273 struct work_struct diag_read_mdm_work;
274 struct work_struct diag_read_hsic_work;
Jack Phamb60775a2012-02-14 17:57:41 -0800275 struct work_struct diag_disconnect_work;
276 struct work_struct diag_usb_read_complete_work;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800277 struct diag_request *usb_read_mdm_ptr;
278 struct diag_request *write_ptr_mdm;
279#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700280};
281
282extern struct diagchar_dev *driver;
283#endif