blob: 4153b7bff9e429c78627ae21b3259eb2e0c85a5d [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
48#define MSG_MASK_SIZE 8000
49#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
53#define MAX_EQUIP_ID 12
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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057
58/* Maximum number of pkt reg supported at initialization*/
Shalabh Jainfe02b0c2012-02-21 14:48:03 -080059extern unsigned int diag_max_reg;
60extern unsigned int diag_threshold_reg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070061
62#define APPEND_DEBUG(ch) \
63do { \
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
69struct 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
78struct 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
85struct 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
98struct diag_write_device {
99 void *buf;
100 int length;
101};
102
103struct 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
110struct diag_request {
111 char *buf;
112 int length;
113 int actual;
114 int status;
115 void *context;
116};
117#endif
118
119struct 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 Jain3d29fc32012-02-09 17:15:59 -0800135 int polling_reg_flag;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700136 struct diag_write_device *buf_tbl;
137
138 /* Memory pool parameters */
139 unsigned int itemsize;
140 unsigned int poolsize;
141 unsigned int itemsize_hdlc;
142 unsigned int poolsize_hdlc;
143 unsigned int itemsize_write_struct;
144 unsigned int poolsize_write_struct;
145 unsigned int debug_flag;
146 /* State for the mempool for the char driver */
147 mempool_t *diagpool;
148 mempool_t *diag_hdlc_pool;
149 mempool_t *diag_write_struct_pool;
150 struct mutex diagmem_mutex;
151 int count;
152 int count_hdlc_pool;
153 int count_write_struct_pool;
154 int used;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800155 /* Buffers for masks */
156 struct diag_ctrl_event_mask *event_mask;
157 struct diag_ctrl_log_mask *log_mask;
158 struct diag_ctrl_msg_mask *msg_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159 /* State for diag forwarding */
160 unsigned char *buf_in_1;
161 unsigned char *buf_in_2;
162 unsigned char *buf_in_cntl;
163 unsigned char *buf_in_qdsp_1;
164 unsigned char *buf_in_qdsp_2;
165 unsigned char *buf_in_qdsp_cntl;
166 unsigned char *buf_in_wcnss;
167 unsigned char *buf_in_wcnss_cntl;
168 unsigned char *usb_buf_out;
169 unsigned char *apps_rsp_buf;
Shalabh Jain69890aa2011-10-10 12:59:16 -0700170 unsigned char *user_space_data;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800171 /* buffer for updating mask to peripherals */
172 unsigned char *buf_msg_mask_update;
173 unsigned char *buf_log_mask_update;
174 unsigned char *buf_event_mask_update;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700175 smd_channel_t *ch;
176 smd_channel_t *ch_cntl;
177 smd_channel_t *chqdsp;
178 smd_channel_t *chqdsp_cntl;
179 smd_channel_t *ch_wcnss;
180 smd_channel_t *ch_wcnss_cntl;
181 int in_busy_1;
182 int in_busy_2;
183 int in_busy_qdsp_1;
184 int in_busy_qdsp_2;
185 int in_busy_wcnss;
186 int read_len_legacy;
187 unsigned char *hdlc_buf;
188 unsigned hdlc_count;
189 unsigned hdlc_escape;
190#ifdef CONFIG_DIAG_OVER_USB
191 int usb_connected;
192 struct usb_diag_ch *legacy_ch;
193 struct work_struct diag_proc_hdlc_work;
194 struct work_struct diag_read_work;
195#endif
196 struct workqueue_struct *diag_wq;
197 struct work_struct diag_drain_work;
198 struct work_struct diag_read_smd_work;
199 struct work_struct diag_read_smd_cntl_work;
200 struct work_struct diag_read_smd_qdsp_work;
201 struct work_struct diag_read_smd_qdsp_cntl_work;
202 struct work_struct diag_read_smd_wcnss_work;
203 struct work_struct diag_read_smd_wcnss_cntl_work;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800204 struct workqueue_struct *diag_cntl_wq;
205 struct work_struct diag_msg_mask_update_work;
206 struct work_struct diag_log_mask_update_work;
207 struct work_struct diag_event_mask_update_work;
208 struct work_struct diag_modem_mask_update_work;
209 struct work_struct diag_qdsp_mask_update_work;
210 struct work_struct diag_wcnss_mask_update_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700211 uint8_t *msg_masks;
212 uint8_t *log_masks;
213 int log_masks_length;
214 uint8_t *event_masks;
215 struct diag_master_table *table;
216 uint8_t *pkt_buf;
217 int pkt_length;
218 struct diag_request *write_ptr_1;
219 struct diag_request *write_ptr_2;
220 struct diag_request *usb_read_ptr;
221 struct diag_request *write_ptr_svc;
222 struct diag_request *write_ptr_qdsp_1;
223 struct diag_request *write_ptr_qdsp_2;
224 struct diag_request *write_ptr_wcnss;
225 int logging_mode;
Shalabh Jainc236f982011-12-15 22:55:20 -0800226 int mask_check;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700227 int logging_process_id;
228#ifdef CONFIG_DIAG_SDIO_PIPE
229 unsigned char *buf_in_sdio;
230 unsigned char *usb_buf_mdm_out;
231 struct sdio_channel *sdio_ch;
232 int read_len_mdm;
233 int in_busy_sdio;
234 struct usb_diag_ch *mdm_ch;
235 struct work_struct diag_read_mdm_work;
236 struct workqueue_struct *diag_sdio_wq;
237 struct work_struct diag_read_sdio_work;
Shalabh Jain5d9ba342011-08-10 13:51:54 -0700238 struct work_struct diag_close_sdio_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700239 struct diag_request *usb_read_mdm_ptr;
240 struct diag_request *write_ptr_mdm;
241#endif
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800242#ifdef CONFIG_DIAG_HSIC_PIPE
243 unsigned char *buf_in_hsic;
244 unsigned char *usb_buf_mdm_out;
245 int hsic_initialized;
246 int hsic_ch;
247 int hsic_device_enabled;
248 int hsic_device_opened;
Jack Phamb60775a2012-02-14 17:57:41 -0800249 int hsic_suspend;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800250 int read_len_mdm;
251 int in_busy_hsic_read_on_mdm;
252 int in_busy_hsic_write_on_mdm;
253 int in_busy_hsic_write;
254 int in_busy_hsic_read;
255 int usb_mdm_connected;
256 struct usb_diag_ch *mdm_ch;
257 struct workqueue_struct *diag_hsic_wq;
258 struct work_struct diag_read_mdm_work;
259 struct work_struct diag_read_hsic_work;
Jack Phamb60775a2012-02-14 17:57:41 -0800260 struct work_struct diag_disconnect_work;
261 struct work_struct diag_usb_read_complete_work;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800262 struct diag_request *usb_read_mdm_ptr;
263 struct diag_request *write_ptr_mdm;
264#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700265};
266
267extern struct diagchar_dev *driver;
268#endif