blob: df28dab1ad283f43312275a63e406908e8eea75b [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>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023#include <mach/msm_smd.h>
24#include <asm/atomic.h>
25#include <asm/mach-types.h>
Dixon Peterson66fb11b2012-12-04 20:30:54 -080026
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070027/* Size of the USB buffers used for read and write*/
28#define USB_MAX_OUT_BUF 4096
Shalabh Jain321c8b52012-02-22 12:37:06 -080029#define APPS_BUF_SIZE 2000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070030#define IN_BUF_SIZE 16384
31#define MAX_IN_BUF_SIZE 32768
32#define MAX_SYNC_OBJ_NAME_SIZE 32
Ravi Aravamudhan77ad4832012-11-15 16:04:04 -080033#define UINT32_MAX UINT_MAX
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070034/* 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 Peterson66fb11b2012-12-04 20:30:54 -080080#define NUM_SMD_DATA_CHANNELS 3
81#define NUM_SMD_CONTROL_CHANNELS 3
82#define NUM_SMD_DCI_CHANNELS 1
83
84#define SMD_DATA_TYPE 0
85#define SMD_CNTL_TYPE 1
86#define SMD_DCI_TYPE 2
87
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070088/* Maximum number of pkt reg supported at initialization*/
Shalabh Jainfe02b0c2012-02-21 14:48:03 -080089extern unsigned int diag_max_reg;
90extern unsigned int diag_threshold_reg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070091
92#define APPEND_DEBUG(ch) \
93do { \
94 diag_debug_buf[diag_debug_buf_idx] = ch; \
95 (diag_debug_buf_idx < 1023) ? \
96 (diag_debug_buf_idx++) : (diag_debug_buf_idx = 0); \
97} while (0)
98
Ashay Jaiswala372f8c2012-12-12 14:02:38 +053099/* List of remote processor supported */
100enum remote_procs {
101 MDM = 1,
Dixon Petersonf90f3582013-01-26 18:14:17 -0800102 MDM2 = 2,
103 MDM3 = 3,
104 MDM4 = 4,
105 QSC = 5,
Ashay Jaiswala372f8c2012-12-12 14:02:38 +0530106};
107
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108struct diag_master_table {
109 uint16_t cmd_code;
110 uint16_t subsys_id;
111 uint32_t client_id;
112 uint16_t cmd_code_lo;
113 uint16_t cmd_code_hi;
114 int process_id;
115};
116
117struct bindpkt_params_per_process {
118 /* Name of the synchronization object associated with this proc */
119 char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE];
120 uint32_t count; /* Number of entries in this bind */
121 struct bindpkt_params *params; /* first bind params */
122};
123
124struct bindpkt_params {
125 uint16_t cmd_code;
126 uint16_t subsys_id;
127 uint16_t cmd_code_lo;
128 uint16_t cmd_code_hi;
129 /* For Central Routing, used to store Processor number */
130 uint16_t proc_id;
131 uint32_t event_id;
132 uint32_t log_code;
133 /* For Central Routing, used to store SMD channel pointer */
134 uint32_t client_id;
135};
136
137struct diag_write_device {
138 void *buf;
139 int length;
140};
141
142struct diag_client_map {
143 char name[20];
144 int pid;
145};
146
147/* This structure is defined in USB header file */
148#ifndef CONFIG_DIAG_OVER_USB
149struct diag_request {
150 char *buf;
151 int length;
152 int actual;
153 int status;
154 void *context;
155};
156#endif
157
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800158struct diag_smd_info {
159 int peripheral; /* The peripheral this smd channel communicates with */
160 int type; /* The type of smd channel (data, control, dci) */
161 uint16_t peripheral_mask;
162
163 smd_channel_t *ch;
164 smd_channel_t *ch_save;
165
166 int in_busy_1;
167 int in_busy_2;
168
169 unsigned char *buf_in_1;
170 unsigned char *buf_in_2;
171
172 struct diag_request *write_ptr_1;
173 struct diag_request *write_ptr_2;
174
175 struct work_struct diag_read_smd_work;
176 struct work_struct diag_notify_update_smd_work;
177 int notify_context;
178
179 /*
180 * Function ptr for function to call to process the data that
181 * was just read from the smd channel
182 */
183 int (*process_smd_read_data)(struct diag_smd_info *smd_info,
184 void *buf, int num_bytes);
185};
186
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700187struct diagchar_dev {
188
189 /* State for the char driver */
190 unsigned int major;
191 unsigned int minor_start;
192 int num;
193 struct cdev *cdev;
194 char *name;
195 int dropped_count;
196 struct class *diagchar_class;
197 int ref_count;
198 struct mutex diagchar_mutex;
199 wait_queue_head_t wait_q;
Shalabh Jainc70b3b62012-08-31 19:11:20 -0700200 wait_queue_head_t smd_wait_q;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700201 struct diag_client_map *client_map;
202 int *data_ready;
203 int num_clients;
Shalabh Jain3d29fc32012-02-09 17:15:59 -0800204 int polling_reg_flag;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205 struct diag_write_device *buf_tbl;
Dixon Petersonb4618a42012-02-29 18:56:31 -0800206 int use_device_tree;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700207 /* DCI related variables */
Shalabh Jain16794902012-09-14 10:56:49 -0700208 struct dci_pkt_req_tracking_tbl *req_tracking_tbl;
209 struct diag_dci_client_tbl *dci_client_tbl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700210 int dci_tag;
211 int dci_client_id;
212 struct mutex dci_mutex;
213 int num_dci_client;
214 unsigned char *apps_dci_buf;
215 int dci_state;
Shalabh Jain16794902012-09-14 10:56:49 -0700216 struct workqueue_struct *diag_dci_wq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700217 /* Memory pool parameters */
218 unsigned int itemsize;
219 unsigned int poolsize;
220 unsigned int itemsize_hdlc;
221 unsigned int poolsize_hdlc;
222 unsigned int itemsize_write_struct;
223 unsigned int poolsize_write_struct;
224 unsigned int debug_flag;
225 /* State for the mempool for the char driver */
226 mempool_t *diagpool;
227 mempool_t *diag_hdlc_pool;
228 mempool_t *diag_write_struct_pool;
229 struct mutex diagmem_mutex;
230 int count;
231 int count_hdlc_pool;
232 int count_write_struct_pool;
233 int used;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800234 /* Buffers for masks */
Shalabh Jaina06c6d72012-04-30 13:40:35 -0700235 struct mutex diag_cntl_mutex;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800236 struct diag_ctrl_event_mask *event_mask;
237 struct diag_ctrl_log_mask *log_mask;
238 struct diag_ctrl_msg_mask *msg_mask;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800239 struct diag_ctrl_feature_mask *feature_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700240 /* State for diag forwarding */
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800241 struct diag_smd_info smd_data[NUM_SMD_DATA_CHANNELS];
242 struct diag_smd_info smd_cntl[NUM_SMD_CONTROL_CHANNELS];
243 struct diag_smd_info smd_dci[NUM_SMD_DCI_CHANNELS];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700244 unsigned char *usb_buf_out;
245 unsigned char *apps_rsp_buf;
Shalabh Jain69890aa2011-10-10 12:59:16 -0700246 unsigned char *user_space_data;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800247 /* buffer for updating mask to peripherals */
248 unsigned char *buf_msg_mask_update;
249 unsigned char *buf_log_mask_update;
250 unsigned char *buf_event_mask_update;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800251 unsigned char *buf_feature_mask_update;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700252 int read_len_legacy;
253 unsigned char *hdlc_buf;
254 unsigned hdlc_count;
255 unsigned hdlc_escape;
256#ifdef CONFIG_DIAG_OVER_USB
257 int usb_connected;
258 struct usb_diag_ch *legacy_ch;
259 struct work_struct diag_proc_hdlc_work;
260 struct work_struct diag_read_work;
261#endif
262 struct workqueue_struct *diag_wq;
263 struct work_struct diag_drain_work;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800264 struct workqueue_struct *diag_cntl_wq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700265 uint8_t *msg_masks;
266 uint8_t *log_masks;
267 int log_masks_length;
268 uint8_t *event_masks;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800269 uint8_t log_on_demand_support;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700270 struct diag_master_table *table;
271 uint8_t *pkt_buf;
272 int pkt_length;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700273 struct diag_request *usb_read_ptr;
274 struct diag_request *write_ptr_svc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700275 int logging_mode;
Shalabh Jainc236f982011-12-15 22:55:20 -0800276 int mask_check;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700277 int logging_process_id;
Dixon Peterson625ee652012-06-21 22:03:49 -0700278 struct task_struct *socket_process;
Shalabh Jain84e30342012-10-16 16:16:08 -0700279 struct task_struct *callback_process;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700280#ifdef CONFIG_DIAG_SDIO_PIPE
281 unsigned char *buf_in_sdio;
282 unsigned char *usb_buf_mdm_out;
283 struct sdio_channel *sdio_ch;
284 int read_len_mdm;
285 int in_busy_sdio;
286 struct usb_diag_ch *mdm_ch;
287 struct work_struct diag_read_mdm_work;
288 struct workqueue_struct *diag_sdio_wq;
289 struct work_struct diag_read_sdio_work;
Shalabh Jain5d9ba342011-08-10 13:51:54 -0700290 struct work_struct diag_close_sdio_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700291 struct diag_request *usb_read_mdm_ptr;
292 struct diag_request *write_ptr_mdm;
293#endif
Shalabh Jain737fca72012-11-14 21:53:43 -0800294#ifdef CONFIG_DIAGFWD_BRIDGE_CODE
295 /* common for all bridges */
296 struct work_struct diag_disconnect_work;
Shalabh Jainf7228dc2012-05-23 17:32:05 -0700297 /* SGLTE variables */
298 int lcid;
299 unsigned char *buf_in_smux;
300 int in_busy_smux;
301 int diag_smux_enabled;
Ashay Jaiswal2d8daae2012-07-17 17:29:33 +0530302 int smux_connected;
Dixon Peterson938f8602012-08-17 20:02:57 -0700303 struct diag_request *write_ptr_mdm;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800304#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700305};
306
Shalabh Jain737fca72012-11-14 21:53:43 -0800307extern struct diag_bridge_dev *diag_bridge;
Shalabh Jainb0037c02013-01-18 12:47:40 -0800308extern struct diag_hsic_dev *diag_hsic;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700309extern struct diagchar_dev *driver;
Ravi Aravamudhanf55dc1d2012-12-27 11:51:42 -0800310
311extern int wrap_enabled;
312extern uint16_t wrap_count;
313
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700314#endif