blob: 6f37608bdfe9f7c436becef1dc2d025e91a042ed [file] [log] [blame]
Shalabh Jainb0037c02013-01-18 12:47:40 -08001/* Copyright (c) 2008-2013, The Linux Foundation. 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>
Dixon Peterson5db2e3c2012-09-06 19:13:14 -070020#include <linux/spinlock.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021#include <linux/workqueue.h>
Shalabh Jain5e9a92b2012-06-07 21:53:49 -070022#include <linux/sched.h>
Dixon Petersonf2d449c2013-02-01 18:02:20 -080023#include <linux/wakelock.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070024#include <mach/msm_smd.h>
25#include <asm/atomic.h>
26#include <asm/mach-types.h>
Dixon Peterson66fb11b2012-12-04 20:30:54 -080027
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028/* Size of the USB buffers used for read and write*/
29#define USB_MAX_OUT_BUF 4096
Shalabh Jain321c8b52012-02-22 12:37:06 -080030#define APPS_BUF_SIZE 2000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031#define IN_BUF_SIZE 16384
32#define MAX_IN_BUF_SIZE 32768
33#define MAX_SYNC_OBJ_NAME_SIZE 32
34/* Size of the buffer used for deframing a packet
35 reveived from the PC tool*/
36#define HDLC_MAX 4096
37#define HDLC_OUT_BUF_SIZE 8192
38#define POOL_TYPE_COPY 1
39#define POOL_TYPE_HDLC 2
40#define POOL_TYPE_WRITE_STRUCT 4
Shalabh Jainb0037c02013-01-18 12:47:40 -080041#define POOL_TYPE_HSIC 5
42#define POOL_TYPE_HSIC_2 6
43#define POOL_TYPE_HSIC_WRITE 11
44#define POOL_TYPE_HSIC_2_WRITE 12
45#define POOL_TYPE_ALL 10
Dixon Petersoneecbadb2012-12-10 21:59:28 -080046#define MODEM_DATA 0
47#define LPASS_DATA 1
48#define WCNSS_DATA 2
Ashay Jaiswal8be3ce82012-09-13 16:01:54 -070049#define APPS_DATA 3
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070050#define SDIO_DATA 4
Dixon Petersoneecbadb2012-12-10 21:59:28 -080051#define HSIC_DATA 5
Shalabh Jainb0037c02013-01-18 12:47:40 -080052#define HSIC_2_DATA 6
53#define SMUX_DATA 10
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070054#define APPS_PROC 1
Shalabh Jain44b79b72012-06-15 13:39:27 -070055#define MSG_MASK_SIZE 10000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070056#define LOG_MASK_SIZE 8000
57#define EVENT_MASK_SIZE 1000
Shalabh Jain69890aa2011-10-10 12:59:16 -070058#define USER_SPACE_DATA 8000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070059#define PKT_SIZE 4096
Shalabh Jainfbf3bdc2012-03-16 21:02:50 -070060#define MAX_EQUIP_ID 15
Shalabh Jain321c8b52012-02-22 12:37:06 -080061#define DIAG_CTRL_MSG_LOG_MASK 9
62#define DIAG_CTRL_MSG_EVENT_MASK 10
63#define DIAG_CTRL_MSG_F3_MASK 11
Shalabh Jain1c99e4c2012-03-26 18:47:59 -070064#define CONTROL_CHAR 0x7E
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070065
Shalabh Jain7b20eab2012-06-19 17:50:58 -070066#define DIAG_CON_APSS (0x0001) /* Bit mask for APSS */
67#define DIAG_CON_MPSS (0x0002) /* Bit mask for MPSS */
68#define DIAG_CON_LPASS (0x0004) /* Bit mask for LPASS */
69#define DIAG_CON_WCNSS (0x0008) /* Bit mask for WCNSS */
70
Dixon Peterson5a26a302012-11-15 17:26:17 -080071/*
72 * The status bit masks when received in a signal handler are to be
73 * used in conjunction with the peripheral list bit mask to determine the
74 * status for a peripheral. For instance, 0x00010002 would denote an open
75 * status on the MPSS
76 */
77#define DIAG_STATUS_OPEN (0x00010000) /* DCI channel open status mask */
78#define DIAG_STATUS_CLOSED (0x00020000) /* DCI channel closed status mask */
79
Dixon Petersonf2d449c2013-02-01 18:02:20 -080080#define MODE_REALTIME 1
81#define MODE_NONREALTIME 0
82
Dixon Peterson66fb11b2012-12-04 20:30:54 -080083#define NUM_SMD_DATA_CHANNELS 3
84#define NUM_SMD_CONTROL_CHANNELS 3
85#define NUM_SMD_DCI_CHANNELS 1
86
87#define SMD_DATA_TYPE 0
88#define SMD_CNTL_TYPE 1
89#define SMD_DCI_TYPE 2
90
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091/* Maximum number of pkt reg supported at initialization*/
Mohit Aggarwal3aa45862013-03-05 18:37:58 +053092extern int diag_max_reg;
93extern int diag_threshold_reg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070094
95#define APPEND_DEBUG(ch) \
96do { \
97 diag_debug_buf[diag_debug_buf_idx] = ch; \
98 (diag_debug_buf_idx < 1023) ? \
99 (diag_debug_buf_idx++) : (diag_debug_buf_idx = 0); \
100} while (0)
101
Ashay Jaiswala372f8c2012-12-12 14:02:38 +0530102/* List of remote processor supported */
103enum remote_procs {
104 MDM = 1,
Dixon Petersonf90f3582013-01-26 18:14:17 -0800105 MDM2 = 2,
106 MDM3 = 3,
107 MDM4 = 4,
108 QSC = 5,
Ashay Jaiswala372f8c2012-12-12 14:02:38 +0530109};
110
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700111struct diag_master_table {
112 uint16_t cmd_code;
113 uint16_t subsys_id;
114 uint32_t client_id;
115 uint16_t cmd_code_lo;
116 uint16_t cmd_code_hi;
117 int process_id;
118};
119
120struct bindpkt_params_per_process {
121 /* Name of the synchronization object associated with this proc */
122 char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE];
123 uint32_t count; /* Number of entries in this bind */
124 struct bindpkt_params *params; /* first bind params */
125};
126
127struct bindpkt_params {
128 uint16_t cmd_code;
129 uint16_t subsys_id;
130 uint16_t cmd_code_lo;
131 uint16_t cmd_code_hi;
132 /* For Central Routing, used to store Processor number */
133 uint16_t proc_id;
134 uint32_t event_id;
135 uint32_t log_code;
136 /* For Central Routing, used to store SMD channel pointer */
137 uint32_t client_id;
138};
139
140struct diag_write_device {
141 void *buf;
142 int length;
143};
144
145struct diag_client_map {
146 char name[20];
147 int pid;
148};
149
Dixon Petersonf2d449c2013-02-01 18:02:20 -0800150struct diag_nrt_wake_lock {
151 int enabled;
152 int ref_count;
153 int copy_count;
154 struct wake_lock read_lock;
155 spinlock_t read_spinlock;
156};
157
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700158/* This structure is defined in USB header file */
159#ifndef CONFIG_DIAG_OVER_USB
160struct diag_request {
161 char *buf;
162 int length;
163 int actual;
164 int status;
165 void *context;
166};
167#endif
168
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800169struct diag_smd_info {
170 int peripheral; /* The peripheral this smd channel communicates with */
171 int type; /* The type of smd channel (data, control, dci) */
172 uint16_t peripheral_mask;
173
174 smd_channel_t *ch;
175 smd_channel_t *ch_save;
176
Dixon Peterson25f042b2013-02-27 13:00:08 -0800177 struct mutex smd_ch_mutex;
178
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800179 int in_busy_1;
180 int in_busy_2;
181
182 unsigned char *buf_in_1;
183 unsigned char *buf_in_2;
184
185 struct diag_request *write_ptr_1;
186 struct diag_request *write_ptr_2;
187
Dixon Petersonf2d449c2013-02-01 18:02:20 -0800188 struct diag_nrt_wake_lock nrt_lock;
189
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800190 struct work_struct diag_read_smd_work;
191 struct work_struct diag_notify_update_smd_work;
192 int notify_context;
193
194 /*
195 * Function ptr for function to call to process the data that
196 * was just read from the smd channel
197 */
198 int (*process_smd_read_data)(struct diag_smd_info *smd_info,
199 void *buf, int num_bytes);
200};
201
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700202struct diagchar_dev {
203
204 /* State for the char driver */
205 unsigned int major;
206 unsigned int minor_start;
207 int num;
208 struct cdev *cdev;
209 char *name;
210 int dropped_count;
211 struct class *diagchar_class;
212 int ref_count;
213 struct mutex diagchar_mutex;
214 wait_queue_head_t wait_q;
Shalabh Jainc70b3b62012-08-31 19:11:20 -0700215 wait_queue_head_t smd_wait_q;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700216 struct diag_client_map *client_map;
217 int *data_ready;
218 int num_clients;
Shalabh Jain3d29fc32012-02-09 17:15:59 -0800219 int polling_reg_flag;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700220 struct diag_write_device *buf_tbl;
Dixon Petersonb4618a42012-02-29 18:56:31 -0800221 int use_device_tree;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700222 /* DCI related variables */
Shalabh Jain16794902012-09-14 10:56:49 -0700223 struct dci_pkt_req_tracking_tbl *req_tracking_tbl;
224 struct diag_dci_client_tbl *dci_client_tbl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700225 int dci_tag;
226 int dci_client_id;
227 struct mutex dci_mutex;
228 int num_dci_client;
229 unsigned char *apps_dci_buf;
230 int dci_state;
Shalabh Jain16794902012-09-14 10:56:49 -0700231 struct workqueue_struct *diag_dci_wq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700232 /* Memory pool parameters */
233 unsigned int itemsize;
234 unsigned int poolsize;
235 unsigned int itemsize_hdlc;
236 unsigned int poolsize_hdlc;
237 unsigned int itemsize_write_struct;
238 unsigned int poolsize_write_struct;
239 unsigned int debug_flag;
240 /* State for the mempool for the char driver */
241 mempool_t *diagpool;
242 mempool_t *diag_hdlc_pool;
243 mempool_t *diag_write_struct_pool;
244 struct mutex diagmem_mutex;
245 int count;
246 int count_hdlc_pool;
247 int count_write_struct_pool;
248 int used;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800249 /* Buffers for masks */
Shalabh Jaina06c6d72012-04-30 13:40:35 -0700250 struct mutex diag_cntl_mutex;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800251 struct diag_ctrl_event_mask *event_mask;
252 struct diag_ctrl_log_mask *log_mask;
253 struct diag_ctrl_msg_mask *msg_mask;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800254 struct diag_ctrl_feature_mask *feature_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700255 /* State for diag forwarding */
Dixon Petersonf2d449c2013-02-01 18:02:20 -0800256 int real_time_mode;
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800257 struct diag_smd_info smd_data[NUM_SMD_DATA_CHANNELS];
258 struct diag_smd_info smd_cntl[NUM_SMD_CONTROL_CHANNELS];
259 struct diag_smd_info smd_dci[NUM_SMD_DCI_CHANNELS];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700260 unsigned char *usb_buf_out;
261 unsigned char *apps_rsp_buf;
Shalabh Jain69890aa2011-10-10 12:59:16 -0700262 unsigned char *user_space_data;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800263 /* buffer for updating mask to peripherals */
264 unsigned char *buf_msg_mask_update;
265 unsigned char *buf_log_mask_update;
266 unsigned char *buf_event_mask_update;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800267 unsigned char *buf_feature_mask_update;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700268 int read_len_legacy;
Dixon Peterson25f042b2013-02-27 13:00:08 -0800269 struct mutex diag_hdlc_mutex;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700270 unsigned char *hdlc_buf;
271 unsigned hdlc_count;
272 unsigned hdlc_escape;
Ravi Aravamudhan72c55282013-03-20 19:29:01 -0700273 int in_busy_pktdata;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700274#ifdef CONFIG_DIAG_OVER_USB
275 int usb_connected;
276 struct usb_diag_ch *legacy_ch;
277 struct work_struct diag_proc_hdlc_work;
278 struct work_struct diag_read_work;
279#endif
280 struct workqueue_struct *diag_wq;
281 struct work_struct diag_drain_work;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800282 struct workqueue_struct *diag_cntl_wq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700283 uint8_t *msg_masks;
284 uint8_t *log_masks;
285 int log_masks_length;
286 uint8_t *event_masks;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800287 uint8_t log_on_demand_support;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700288 struct diag_master_table *table;
289 uint8_t *pkt_buf;
290 int pkt_length;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700291 struct diag_request *usb_read_ptr;
292 struct diag_request *write_ptr_svc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293 int logging_mode;
Shalabh Jainc236f982011-12-15 22:55:20 -0800294 int mask_check;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700295 int logging_process_id;
Dixon Peterson625ee652012-06-21 22:03:49 -0700296 struct task_struct *socket_process;
Shalabh Jain84e30342012-10-16 16:16:08 -0700297 struct task_struct *callback_process;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298#ifdef CONFIG_DIAG_SDIO_PIPE
299 unsigned char *buf_in_sdio;
300 unsigned char *usb_buf_mdm_out;
301 struct sdio_channel *sdio_ch;
302 int read_len_mdm;
303 int in_busy_sdio;
304 struct usb_diag_ch *mdm_ch;
305 struct work_struct diag_read_mdm_work;
306 struct workqueue_struct *diag_sdio_wq;
307 struct work_struct diag_read_sdio_work;
Shalabh Jain5d9ba342011-08-10 13:51:54 -0700308 struct work_struct diag_close_sdio_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700309 struct diag_request *usb_read_mdm_ptr;
310 struct diag_request *write_ptr_mdm;
311#endif
Shalabh Jain737fca72012-11-14 21:53:43 -0800312#ifdef CONFIG_DIAGFWD_BRIDGE_CODE
Dixon Peterson13046ed2013-02-21 17:35:35 -0800313 spinlock_t hsic_ready_spinlock;
Shalabh Jain737fca72012-11-14 21:53:43 -0800314 /* common for all bridges */
315 struct work_struct diag_disconnect_work;
Shalabh Jainf7228dc2012-05-23 17:32:05 -0700316 /* SGLTE variables */
317 int lcid;
318 unsigned char *buf_in_smux;
319 int in_busy_smux;
320 int diag_smux_enabled;
Ashay Jaiswal2d8daae2012-07-17 17:29:33 +0530321 int smux_connected;
Dixon Peterson938f8602012-08-17 20:02:57 -0700322 struct diag_request *write_ptr_mdm;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800323#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700324};
325
Shalabh Jain737fca72012-11-14 21:53:43 -0800326extern struct diag_bridge_dev *diag_bridge;
Shalabh Jainb0037c02013-01-18 12:47:40 -0800327extern struct diag_hsic_dev *diag_hsic;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700328extern struct diagchar_dev *driver;
Ravi Aravamudhanf55dc1d2012-12-27 11:51:42 -0800329
330extern int wrap_enabled;
331extern uint16_t wrap_count;
332
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700333#endif