blob: e048367620d0f4f101be96f61b484fcb0531875a [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
26#define IN_BUF_SIZE 16384
27#define MAX_IN_BUF_SIZE 32768
28#define MAX_SYNC_OBJ_NAME_SIZE 32
29/* Size of the buffer used for deframing a packet
30 reveived from the PC tool*/
31#define HDLC_MAX 4096
32#define HDLC_OUT_BUF_SIZE 8192
33#define POOL_TYPE_COPY 1
34#define POOL_TYPE_HDLC 2
35#define POOL_TYPE_WRITE_STRUCT 4
36#define POOL_TYPE_ALL 7
37#define MODEM_DATA 1
38#define QDSP_DATA 2
39#define APPS_DATA 3
40#define SDIO_DATA 4
41#define WCNSS_DATA 5
Dixon Peterson32e70bb2011-12-16 13:26:45 -080042#define HSIC_DATA 6
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070043#define MODEM_PROC 0
44#define APPS_PROC 1
45#define QDSP_PROC 2
46#define WCNSS_PROC 3
47#define MSG_MASK_SIZE 8000
48#define LOG_MASK_SIZE 8000
49#define EVENT_MASK_SIZE 1000
Shalabh Jain69890aa2011-10-10 12:59:16 -070050#define USER_SPACE_DATA 8000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051#define PKT_SIZE 4096
52#define MAX_EQUIP_ID 12
Shalabh Jain4ad89862011-10-19 18:55:47 -070053#define DIAG_CTRL_MSG_LOG_MASK 9
54#define DIAG_CTRL_MSG_EVENT_MASK 10
55#define DIAG_CTRL_MSG_F3_MASK 11
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070056
57/* Maximum number of pkt reg supported at initialization*/
58extern unsigned int diag_max_registration;
59extern unsigned int diag_threshold_registration;
60
61#define APPEND_DEBUG(ch) \
62do { \
63 diag_debug_buf[diag_debug_buf_idx] = ch; \
64 (diag_debug_buf_idx < 1023) ? \
65 (diag_debug_buf_idx++) : (diag_debug_buf_idx = 0); \
66} while (0)
67
68struct diag_master_table {
69 uint16_t cmd_code;
70 uint16_t subsys_id;
71 uint32_t client_id;
72 uint16_t cmd_code_lo;
73 uint16_t cmd_code_hi;
74 int process_id;
75};
76
77struct bindpkt_params_per_process {
78 /* Name of the synchronization object associated with this proc */
79 char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE];
80 uint32_t count; /* Number of entries in this bind */
81 struct bindpkt_params *params; /* first bind params */
82};
83
84struct bindpkt_params {
85 uint16_t cmd_code;
86 uint16_t subsys_id;
87 uint16_t cmd_code_lo;
88 uint16_t cmd_code_hi;
89 /* For Central Routing, used to store Processor number */
90 uint16_t proc_id;
91 uint32_t event_id;
92 uint32_t log_code;
93 /* For Central Routing, used to store SMD channel pointer */
94 uint32_t client_id;
95};
96
97struct diag_write_device {
98 void *buf;
99 int length;
100};
101
102struct diag_client_map {
103 char name[20];
104 int pid;
105};
106
107/* This structure is defined in USB header file */
108#ifndef CONFIG_DIAG_OVER_USB
109struct diag_request {
110 char *buf;
111 int length;
112 int actual;
113 int status;
114 void *context;
115};
116#endif
117
118struct diagchar_dev {
119
120 /* State for the char driver */
121 unsigned int major;
122 unsigned int minor_start;
123 int num;
124 struct cdev *cdev;
125 char *name;
126 int dropped_count;
127 struct class *diagchar_class;
128 int ref_count;
129 struct mutex diagchar_mutex;
130 wait_queue_head_t wait_q;
131 struct diag_client_map *client_map;
132 int *data_ready;
133 int num_clients;
134 struct diag_write_device *buf_tbl;
135
136 /* Memory pool parameters */
137 unsigned int itemsize;
138 unsigned int poolsize;
139 unsigned int itemsize_hdlc;
140 unsigned int poolsize_hdlc;
141 unsigned int itemsize_write_struct;
142 unsigned int poolsize_write_struct;
143 unsigned int debug_flag;
144 /* State for the mempool for the char driver */
145 mempool_t *diagpool;
146 mempool_t *diag_hdlc_pool;
147 mempool_t *diag_write_struct_pool;
148 struct mutex diagmem_mutex;
149 int count;
150 int count_hdlc_pool;
151 int count_write_struct_pool;
152 int used;
Shalabh Jain4ad89862011-10-19 18:55:47 -0700153 /* Buffers for masks */
154 struct diag_ctrl_event_mask *event_mask;
155 struct diag_ctrl_log_mask *log_mask;
156 struct diag_ctrl_msg_mask *msg_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700157 /* State for diag forwarding */
158 unsigned char *buf_in_1;
159 unsigned char *buf_in_2;
160 unsigned char *buf_in_cntl;
161 unsigned char *buf_in_qdsp_1;
162 unsigned char *buf_in_qdsp_2;
163 unsigned char *buf_in_qdsp_cntl;
164 unsigned char *buf_in_wcnss;
165 unsigned char *buf_in_wcnss_cntl;
166 unsigned char *usb_buf_out;
167 unsigned char *apps_rsp_buf;
Shalabh Jain69890aa2011-10-10 12:59:16 -0700168 unsigned char *user_space_data;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700169 smd_channel_t *ch;
170 smd_channel_t *ch_cntl;
171 smd_channel_t *chqdsp;
172 smd_channel_t *chqdsp_cntl;
173 smd_channel_t *ch_wcnss;
174 smd_channel_t *ch_wcnss_cntl;
175 int in_busy_1;
176 int in_busy_2;
177 int in_busy_qdsp_1;
178 int in_busy_qdsp_2;
179 int in_busy_wcnss;
180 int read_len_legacy;
181 unsigned char *hdlc_buf;
182 unsigned hdlc_count;
183 unsigned hdlc_escape;
184#ifdef CONFIG_DIAG_OVER_USB
185 int usb_connected;
186 struct usb_diag_ch *legacy_ch;
187 struct work_struct diag_proc_hdlc_work;
188 struct work_struct diag_read_work;
189#endif
190 struct workqueue_struct *diag_wq;
191 struct work_struct diag_drain_work;
192 struct work_struct diag_read_smd_work;
193 struct work_struct diag_read_smd_cntl_work;
194 struct work_struct diag_read_smd_qdsp_work;
195 struct work_struct diag_read_smd_qdsp_cntl_work;
196 struct work_struct diag_read_smd_wcnss_work;
197 struct work_struct diag_read_smd_wcnss_cntl_work;
198 uint8_t *msg_masks;
199 uint8_t *log_masks;
200 int log_masks_length;
201 uint8_t *event_masks;
202 struct diag_master_table *table;
203 uint8_t *pkt_buf;
204 int pkt_length;
205 struct diag_request *write_ptr_1;
206 struct diag_request *write_ptr_2;
207 struct diag_request *usb_read_ptr;
208 struct diag_request *write_ptr_svc;
209 struct diag_request *write_ptr_qdsp_1;
210 struct diag_request *write_ptr_qdsp_2;
211 struct diag_request *write_ptr_wcnss;
212 int logging_mode;
Shalabh Jainc236f982011-12-15 22:55:20 -0800213 int mask_check;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700214 int logging_process_id;
215#ifdef CONFIG_DIAG_SDIO_PIPE
216 unsigned char *buf_in_sdio;
217 unsigned char *usb_buf_mdm_out;
218 struct sdio_channel *sdio_ch;
219 int read_len_mdm;
220 int in_busy_sdio;
221 struct usb_diag_ch *mdm_ch;
222 struct work_struct diag_read_mdm_work;
223 struct workqueue_struct *diag_sdio_wq;
224 struct work_struct diag_read_sdio_work;
Shalabh Jain5d9ba342011-08-10 13:51:54 -0700225 struct work_struct diag_close_sdio_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700226 struct diag_request *usb_read_mdm_ptr;
227 struct diag_request *write_ptr_mdm;
228#endif
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800229#ifdef CONFIG_DIAG_HSIC_PIPE
230 unsigned char *buf_in_hsic;
231 unsigned char *usb_buf_mdm_out;
232 int hsic_initialized;
233 int hsic_ch;
234 int hsic_device_enabled;
235 int hsic_device_opened;
236 int read_len_mdm;
237 int in_busy_hsic_read_on_mdm;
238 int in_busy_hsic_write_on_mdm;
239 int in_busy_hsic_write;
240 int in_busy_hsic_read;
241 int usb_mdm_connected;
242 struct usb_diag_ch *mdm_ch;
243 struct workqueue_struct *diag_hsic_wq;
244 struct work_struct diag_read_mdm_work;
245 struct work_struct diag_read_hsic_work;
246 struct diag_request *usb_read_mdm_ptr;
247 struct diag_request *write_ptr_mdm;
248#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700249};
250
251extern struct diagchar_dev *driver;
252#endif