blob: 292a0be99ce7341483cd545404a76a7ce9178f65 [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
Dixon Peterson6dba7572013-04-12 18:45:16 -070040#define POOL_TYPE_USER 3
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070041#define POOL_TYPE_WRITE_STRUCT 4
Shalabh Jainb0037c02013-01-18 12:47:40 -080042#define POOL_TYPE_HSIC 5
43#define POOL_TYPE_HSIC_2 6
44#define POOL_TYPE_HSIC_WRITE 11
45#define POOL_TYPE_HSIC_2_WRITE 12
46#define POOL_TYPE_ALL 10
Dixon Petersoneecbadb2012-12-10 21:59:28 -080047#define MODEM_DATA 0
48#define LPASS_DATA 1
49#define WCNSS_DATA 2
Ashay Jaiswal8be3ce82012-09-13 16:01:54 -070050#define APPS_DATA 3
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070051#define SDIO_DATA 4
Dixon Petersoneecbadb2012-12-10 21:59:28 -080052#define HSIC_DATA 5
Shalabh Jainb0037c02013-01-18 12:47:40 -080053#define HSIC_2_DATA 6
54#define SMUX_DATA 10
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055#define APPS_PROC 1
Shalabh Jain44b79b72012-06-15 13:39:27 -070056#define MSG_MASK_SIZE 10000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057#define LOG_MASK_SIZE 8000
58#define EVENT_MASK_SIZE 1000
Dixon Peterson6dba7572013-04-12 18:45:16 -070059#define USER_SPACE_DATA 8192
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070060#define PKT_SIZE 4096
Shalabh Jainfbf3bdc2012-03-16 21:02:50 -070061#define MAX_EQUIP_ID 15
Shalabh Jain321c8b52012-02-22 12:37:06 -080062#define DIAG_CTRL_MSG_LOG_MASK 9
63#define DIAG_CTRL_MSG_EVENT_MASK 10
64#define DIAG_CTRL_MSG_F3_MASK 11
Shalabh Jain1c99e4c2012-03-26 18:47:59 -070065#define CONTROL_CHAR 0x7E
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070066
Shalabh Jain7b20eab2012-06-19 17:50:58 -070067#define DIAG_CON_APSS (0x0001) /* Bit mask for APSS */
68#define DIAG_CON_MPSS (0x0002) /* Bit mask for MPSS */
69#define DIAG_CON_LPASS (0x0004) /* Bit mask for LPASS */
70#define DIAG_CON_WCNSS (0x0008) /* Bit mask for WCNSS */
71
Dixon Peterson5a26a302012-11-15 17:26:17 -080072/*
73 * The status bit masks when received in a signal handler are to be
74 * used in conjunction with the peripheral list bit mask to determine the
75 * status for a peripheral. For instance, 0x00010002 would denote an open
76 * status on the MPSS
77 */
78#define DIAG_STATUS_OPEN (0x00010000) /* DCI channel open status mask */
79#define DIAG_STATUS_CLOSED (0x00020000) /* DCI channel closed status mask */
80
Dixon Petersonf2d449c2013-02-01 18:02:20 -080081#define MODE_REALTIME 1
82#define MODE_NONREALTIME 0
83
Dixon Peterson66fb11b2012-12-04 20:30:54 -080084#define NUM_SMD_DATA_CHANNELS 3
85#define NUM_SMD_CONTROL_CHANNELS 3
86#define NUM_SMD_DCI_CHANNELS 1
87
88#define SMD_DATA_TYPE 0
89#define SMD_CNTL_TYPE 1
90#define SMD_DCI_TYPE 2
91
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070092/* Maximum number of pkt reg supported at initialization*/
Mohit Aggarwal3aa45862013-03-05 18:37:58 +053093extern int diag_max_reg;
94extern int diag_threshold_reg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070095
96#define APPEND_DEBUG(ch) \
97do { \
98 diag_debug_buf[diag_debug_buf_idx] = ch; \
99 (diag_debug_buf_idx < 1023) ? \
100 (diag_debug_buf_idx++) : (diag_debug_buf_idx = 0); \
101} while (0)
102
Ashay Jaiswala372f8c2012-12-12 14:02:38 +0530103/* List of remote processor supported */
104enum remote_procs {
105 MDM = 1,
Dixon Petersonf90f3582013-01-26 18:14:17 -0800106 MDM2 = 2,
107 MDM3 = 3,
108 MDM4 = 4,
109 QSC = 5,
Ashay Jaiswala372f8c2012-12-12 14:02:38 +0530110};
111
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700112struct diag_master_table {
113 uint16_t cmd_code;
114 uint16_t subsys_id;
115 uint32_t client_id;
116 uint16_t cmd_code_lo;
117 uint16_t cmd_code_hi;
118 int process_id;
119};
120
121struct bindpkt_params_per_process {
122 /* Name of the synchronization object associated with this proc */
123 char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE];
124 uint32_t count; /* Number of entries in this bind */
125 struct bindpkt_params *params; /* first bind params */
126};
127
128struct bindpkt_params {
129 uint16_t cmd_code;
130 uint16_t subsys_id;
131 uint16_t cmd_code_lo;
132 uint16_t cmd_code_hi;
133 /* For Central Routing, used to store Processor number */
134 uint16_t proc_id;
135 uint32_t event_id;
136 uint32_t log_code;
137 /* For Central Routing, used to store SMD channel pointer */
138 uint32_t client_id;
139};
140
141struct diag_write_device {
142 void *buf;
143 int length;
144};
145
146struct diag_client_map {
147 char name[20];
148 int pid;
149};
150
Dixon Petersonf2d449c2013-02-01 18:02:20 -0800151struct diag_nrt_wake_lock {
152 int enabled;
153 int ref_count;
154 int copy_count;
155 struct wake_lock read_lock;
156 spinlock_t read_spinlock;
157};
158
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159/* This structure is defined in USB header file */
160#ifndef CONFIG_DIAG_OVER_USB
161struct diag_request {
162 char *buf;
163 int length;
164 int actual;
165 int status;
166 void *context;
167};
168#endif
169
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800170struct diag_smd_info {
171 int peripheral; /* The peripheral this smd channel communicates with */
172 int type; /* The type of smd channel (data, control, dci) */
173 uint16_t peripheral_mask;
174
175 smd_channel_t *ch;
176 smd_channel_t *ch_save;
177
Dixon Peterson25f042b2013-02-27 13:00:08 -0800178 struct mutex smd_ch_mutex;
179
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800180 int in_busy_1;
181 int in_busy_2;
182
183 unsigned char *buf_in_1;
184 unsigned char *buf_in_2;
185
186 struct diag_request *write_ptr_1;
187 struct diag_request *write_ptr_2;
188
Dixon Petersonf2d449c2013-02-01 18:02:20 -0800189 struct diag_nrt_wake_lock nrt_lock;
190
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800191 struct work_struct diag_read_smd_work;
192 struct work_struct diag_notify_update_smd_work;
193 int notify_context;
194
195 /*
196 * Function ptr for function to call to process the data that
197 * was just read from the smd channel
198 */
199 int (*process_smd_read_data)(struct diag_smd_info *smd_info,
200 void *buf, int num_bytes);
201};
202
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700203struct diagchar_dev {
204
205 /* State for the char driver */
206 unsigned int major;
207 unsigned int minor_start;
208 int num;
209 struct cdev *cdev;
210 char *name;
211 int dropped_count;
212 struct class *diagchar_class;
213 int ref_count;
214 struct mutex diagchar_mutex;
215 wait_queue_head_t wait_q;
Shalabh Jainc70b3b62012-08-31 19:11:20 -0700216 wait_queue_head_t smd_wait_q;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700217 struct diag_client_map *client_map;
218 int *data_ready;
219 int num_clients;
Shalabh Jain3d29fc32012-02-09 17:15:59 -0800220 int polling_reg_flag;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700221 struct diag_write_device *buf_tbl;
Dixon Petersona6d98092013-05-16 12:26:26 -0700222 unsigned int buf_tbl_size;
Dixon Petersonb4618a42012-02-29 18:56:31 -0800223 int use_device_tree;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700224 /* DCI related variables */
Shalabh Jain16794902012-09-14 10:56:49 -0700225 struct dci_pkt_req_tracking_tbl *req_tracking_tbl;
226 struct diag_dci_client_tbl *dci_client_tbl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700227 int dci_tag;
228 int dci_client_id;
229 struct mutex dci_mutex;
230 int num_dci_client;
231 unsigned char *apps_dci_buf;
232 int dci_state;
Shalabh Jain16794902012-09-14 10:56:49 -0700233 struct workqueue_struct *diag_dci_wq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700234 /* Memory pool parameters */
235 unsigned int itemsize;
236 unsigned int poolsize;
237 unsigned int itemsize_hdlc;
238 unsigned int poolsize_hdlc;
Dixon Peterson6dba7572013-04-12 18:45:16 -0700239 unsigned int itemsize_user;
240 unsigned int poolsize_user;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700241 unsigned int itemsize_write_struct;
242 unsigned int poolsize_write_struct;
243 unsigned int debug_flag;
244 /* State for the mempool for the char driver */
245 mempool_t *diagpool;
246 mempool_t *diag_hdlc_pool;
Dixon Peterson6dba7572013-04-12 18:45:16 -0700247 mempool_t *diag_user_pool;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700248 mempool_t *diag_write_struct_pool;
249 struct mutex diagmem_mutex;
250 int count;
251 int count_hdlc_pool;
Dixon Peterson6dba7572013-04-12 18:45:16 -0700252 int count_user_pool;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700253 int count_write_struct_pool;
254 int used;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800255 /* Buffers for masks */
Shalabh Jaina06c6d72012-04-30 13:40:35 -0700256 struct mutex diag_cntl_mutex;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800257 struct diag_ctrl_event_mask *event_mask;
258 struct diag_ctrl_log_mask *log_mask;
259 struct diag_ctrl_msg_mask *msg_mask;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800260 struct diag_ctrl_feature_mask *feature_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700261 /* State for diag forwarding */
Dixon Petersonf2d449c2013-02-01 18:02:20 -0800262 int real_time_mode;
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800263 struct diag_smd_info smd_data[NUM_SMD_DATA_CHANNELS];
264 struct diag_smd_info smd_cntl[NUM_SMD_CONTROL_CHANNELS];
265 struct diag_smd_info smd_dci[NUM_SMD_DCI_CHANNELS];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700266 unsigned char *usb_buf_out;
267 unsigned char *apps_rsp_buf;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800268 /* buffer for updating mask to peripherals */
269 unsigned char *buf_msg_mask_update;
270 unsigned char *buf_log_mask_update;
271 unsigned char *buf_event_mask_update;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800272 unsigned char *buf_feature_mask_update;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700273 int read_len_legacy;
Dixon Peterson25f042b2013-02-27 13:00:08 -0800274 struct mutex diag_hdlc_mutex;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700275 unsigned char *hdlc_buf;
276 unsigned hdlc_count;
277 unsigned hdlc_escape;
Ravi Aravamudhan72c55282013-03-20 19:29:01 -0700278 int in_busy_pktdata;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700279#ifdef CONFIG_DIAG_OVER_USB
280 int usb_connected;
281 struct usb_diag_ch *legacy_ch;
282 struct work_struct diag_proc_hdlc_work;
283 struct work_struct diag_read_work;
Mohit Aggarwalb4465772013-04-18 13:08:07 +0530284 struct work_struct diag_usb_connect_work;
285 struct work_struct diag_usb_disconnect_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700286#endif
287 struct workqueue_struct *diag_wq;
288 struct work_struct diag_drain_work;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800289 struct workqueue_struct *diag_cntl_wq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700290 uint8_t *msg_masks;
291 uint8_t *log_masks;
292 int log_masks_length;
293 uint8_t *event_masks;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800294 uint8_t log_on_demand_support;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700295 struct diag_master_table *table;
296 uint8_t *pkt_buf;
297 int pkt_length;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700298 struct diag_request *usb_read_ptr;
299 struct diag_request *write_ptr_svc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700300 int logging_mode;
Shalabh Jainc236f982011-12-15 22:55:20 -0800301 int mask_check;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700302 int logging_process_id;
Dixon Peterson625ee652012-06-21 22:03:49 -0700303 struct task_struct *socket_process;
Shalabh Jain84e30342012-10-16 16:16:08 -0700304 struct task_struct *callback_process;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700305#ifdef CONFIG_DIAG_SDIO_PIPE
306 unsigned char *buf_in_sdio;
307 unsigned char *usb_buf_mdm_out;
308 struct sdio_channel *sdio_ch;
309 int read_len_mdm;
310 int in_busy_sdio;
311 struct usb_diag_ch *mdm_ch;
312 struct work_struct diag_read_mdm_work;
313 struct workqueue_struct *diag_sdio_wq;
314 struct work_struct diag_read_sdio_work;
Shalabh Jain5d9ba342011-08-10 13:51:54 -0700315 struct work_struct diag_close_sdio_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700316 struct diag_request *usb_read_mdm_ptr;
317 struct diag_request *write_ptr_mdm;
318#endif
Shalabh Jain737fca72012-11-14 21:53:43 -0800319#ifdef CONFIG_DIAGFWD_BRIDGE_CODE
Dixon Peterson13046ed2013-02-21 17:35:35 -0800320 spinlock_t hsic_ready_spinlock;
Shalabh Jain737fca72012-11-14 21:53:43 -0800321 /* common for all bridges */
Mohit Aggarwalb4465772013-04-18 13:08:07 +0530322 struct work_struct diag_connect_work;
Shalabh Jain737fca72012-11-14 21:53:43 -0800323 struct work_struct diag_disconnect_work;
Shalabh Jainf7228dc2012-05-23 17:32:05 -0700324 /* SGLTE variables */
325 int lcid;
326 unsigned char *buf_in_smux;
327 int in_busy_smux;
328 int diag_smux_enabled;
Ashay Jaiswal2d8daae2012-07-17 17:29:33 +0530329 int smux_connected;
Dixon Peterson938f8602012-08-17 20:02:57 -0700330 struct diag_request *write_ptr_mdm;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800331#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700332};
333
Shalabh Jain737fca72012-11-14 21:53:43 -0800334extern struct diag_bridge_dev *diag_bridge;
Shalabh Jainb0037c02013-01-18 12:47:40 -0800335extern struct diag_hsic_dev *diag_hsic;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700336extern struct diagchar_dev *driver;
Ravi Aravamudhanf55dc1d2012-12-27 11:51:42 -0800337
338extern int wrap_enabled;
339extern uint16_t wrap_count;
340
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700341#endif