blob: 9d9df2a70a1a9d3f97825c760be98709e91e2a45 [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
33/* Size of the buffer used for deframing a packet
34 reveived from the PC tool*/
35#define HDLC_MAX 4096
36#define HDLC_OUT_BUF_SIZE 8192
37#define POOL_TYPE_COPY 1
38#define POOL_TYPE_HDLC 2
39#define POOL_TYPE_WRITE_STRUCT 4
Shalabh Jainb0037c02013-01-18 12:47:40 -080040#define POOL_TYPE_HSIC 5
41#define POOL_TYPE_HSIC_2 6
42#define POOL_TYPE_HSIC_WRITE 11
43#define POOL_TYPE_HSIC_2_WRITE 12
44#define POOL_TYPE_ALL 10
Dixon Petersoneecbadb2012-12-10 21:59:28 -080045#define MODEM_DATA 0
46#define LPASS_DATA 1
47#define WCNSS_DATA 2
Ashay Jaiswal8be3ce82012-09-13 16:01:54 -070048#define APPS_DATA 3
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049#define SDIO_DATA 4
Dixon Petersoneecbadb2012-12-10 21:59:28 -080050#define HSIC_DATA 5
Shalabh Jainb0037c02013-01-18 12:47:40 -080051#define HSIC_2_DATA 6
52#define SMUX_DATA 10
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053#define APPS_PROC 1
Shalabh Jain44b79b72012-06-15 13:39:27 -070054#define MSG_MASK_SIZE 10000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070055#define LOG_MASK_SIZE 8000
56#define EVENT_MASK_SIZE 1000
Shalabh Jain69890aa2011-10-10 12:59:16 -070057#define USER_SPACE_DATA 8000
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070058#define PKT_SIZE 4096
Shalabh Jainfbf3bdc2012-03-16 21:02:50 -070059#define MAX_EQUIP_ID 15
Shalabh Jain321c8b52012-02-22 12:37:06 -080060#define DIAG_CTRL_MSG_LOG_MASK 9
61#define DIAG_CTRL_MSG_EVENT_MASK 10
62#define DIAG_CTRL_MSG_F3_MASK 11
Shalabh Jain1c99e4c2012-03-26 18:47:59 -070063#define CONTROL_CHAR 0x7E
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070064
Shalabh Jain7b20eab2012-06-19 17:50:58 -070065#define DIAG_CON_APSS (0x0001) /* Bit mask for APSS */
66#define DIAG_CON_MPSS (0x0002) /* Bit mask for MPSS */
67#define DIAG_CON_LPASS (0x0004) /* Bit mask for LPASS */
68#define DIAG_CON_WCNSS (0x0008) /* Bit mask for WCNSS */
69
Dixon Peterson5a26a302012-11-15 17:26:17 -080070/*
71 * The status bit masks when received in a signal handler are to be
72 * used in conjunction with the peripheral list bit mask to determine the
73 * status for a peripheral. For instance, 0x00010002 would denote an open
74 * status on the MPSS
75 */
76#define DIAG_STATUS_OPEN (0x00010000) /* DCI channel open status mask */
77#define DIAG_STATUS_CLOSED (0x00020000) /* DCI channel closed status mask */
78
Dixon Peterson66fb11b2012-12-04 20:30:54 -080079#define NUM_SMD_DATA_CHANNELS 3
80#define NUM_SMD_CONTROL_CHANNELS 3
81#define NUM_SMD_DCI_CHANNELS 1
82
83#define SMD_DATA_TYPE 0
84#define SMD_CNTL_TYPE 1
85#define SMD_DCI_TYPE 2
86
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070087/* Maximum number of pkt reg supported at initialization*/
Mohit Aggarwal3aa45862013-03-05 18:37:58 +053088extern int diag_max_reg;
89extern int diag_threshold_reg;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070090
91#define APPEND_DEBUG(ch) \
92do { \
93 diag_debug_buf[diag_debug_buf_idx] = ch; \
94 (diag_debug_buf_idx < 1023) ? \
95 (diag_debug_buf_idx++) : (diag_debug_buf_idx = 0); \
96} while (0)
97
Ashay Jaiswala372f8c2012-12-12 14:02:38 +053098/* List of remote processor supported */
99enum remote_procs {
100 MDM = 1,
Dixon Petersonf90f3582013-01-26 18:14:17 -0800101 MDM2 = 2,
102 MDM3 = 3,
103 MDM4 = 4,
104 QSC = 5,
Ashay Jaiswala372f8c2012-12-12 14:02:38 +0530105};
106
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700107struct diag_master_table {
108 uint16_t cmd_code;
109 uint16_t subsys_id;
110 uint32_t client_id;
111 uint16_t cmd_code_lo;
112 uint16_t cmd_code_hi;
113 int process_id;
114};
115
116struct bindpkt_params_per_process {
117 /* Name of the synchronization object associated with this proc */
118 char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE];
119 uint32_t count; /* Number of entries in this bind */
120 struct bindpkt_params *params; /* first bind params */
121};
122
123struct bindpkt_params {
124 uint16_t cmd_code;
125 uint16_t subsys_id;
126 uint16_t cmd_code_lo;
127 uint16_t cmd_code_hi;
128 /* For Central Routing, used to store Processor number */
129 uint16_t proc_id;
130 uint32_t event_id;
131 uint32_t log_code;
132 /* For Central Routing, used to store SMD channel pointer */
133 uint32_t client_id;
134};
135
136struct diag_write_device {
137 void *buf;
138 int length;
139};
140
141struct diag_client_map {
142 char name[20];
143 int pid;
144};
145
146/* This structure is defined in USB header file */
147#ifndef CONFIG_DIAG_OVER_USB
148struct diag_request {
149 char *buf;
150 int length;
151 int actual;
152 int status;
153 void *context;
154};
155#endif
156
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800157struct diag_smd_info {
158 int peripheral; /* The peripheral this smd channel communicates with */
159 int type; /* The type of smd channel (data, control, dci) */
160 uint16_t peripheral_mask;
161
162 smd_channel_t *ch;
163 smd_channel_t *ch_save;
164
Dixon Peterson25f042b2013-02-27 13:00:08 -0800165 struct mutex smd_ch_mutex;
166
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800167 int in_busy_1;
168 int in_busy_2;
169
170 unsigned char *buf_in_1;
171 unsigned char *buf_in_2;
172
173 struct diag_request *write_ptr_1;
174 struct diag_request *write_ptr_2;
175
176 struct work_struct diag_read_smd_work;
177 struct work_struct diag_notify_update_smd_work;
178 int notify_context;
179
180 /*
181 * Function ptr for function to call to process the data that
182 * was just read from the smd channel
183 */
184 int (*process_smd_read_data)(struct diag_smd_info *smd_info,
185 void *buf, int num_bytes);
186};
187
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188struct diagchar_dev {
189
190 /* State for the char driver */
191 unsigned int major;
192 unsigned int minor_start;
193 int num;
194 struct cdev *cdev;
195 char *name;
196 int dropped_count;
197 struct class *diagchar_class;
198 int ref_count;
199 struct mutex diagchar_mutex;
200 wait_queue_head_t wait_q;
Shalabh Jainc70b3b62012-08-31 19:11:20 -0700201 wait_queue_head_t smd_wait_q;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700202 struct diag_client_map *client_map;
203 int *data_ready;
204 int num_clients;
Shalabh Jain3d29fc32012-02-09 17:15:59 -0800205 int polling_reg_flag;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700206 struct diag_write_device *buf_tbl;
Dixon Petersonb4618a42012-02-29 18:56:31 -0800207 int use_device_tree;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700208 /* DCI related variables */
Shalabh Jain16794902012-09-14 10:56:49 -0700209 struct dci_pkt_req_tracking_tbl *req_tracking_tbl;
210 struct diag_dci_client_tbl *dci_client_tbl;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700211 int dci_tag;
212 int dci_client_id;
213 struct mutex dci_mutex;
214 int num_dci_client;
215 unsigned char *apps_dci_buf;
216 int dci_state;
Shalabh Jain16794902012-09-14 10:56:49 -0700217 struct workqueue_struct *diag_dci_wq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700218 /* Memory pool parameters */
219 unsigned int itemsize;
220 unsigned int poolsize;
221 unsigned int itemsize_hdlc;
222 unsigned int poolsize_hdlc;
223 unsigned int itemsize_write_struct;
224 unsigned int poolsize_write_struct;
225 unsigned int debug_flag;
226 /* State for the mempool for the char driver */
227 mempool_t *diagpool;
228 mempool_t *diag_hdlc_pool;
229 mempool_t *diag_write_struct_pool;
230 struct mutex diagmem_mutex;
231 int count;
232 int count_hdlc_pool;
233 int count_write_struct_pool;
234 int used;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800235 /* Buffers for masks */
Shalabh Jaina06c6d72012-04-30 13:40:35 -0700236 struct mutex diag_cntl_mutex;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800237 struct diag_ctrl_event_mask *event_mask;
238 struct diag_ctrl_log_mask *log_mask;
239 struct diag_ctrl_msg_mask *msg_mask;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800240 struct diag_ctrl_feature_mask *feature_mask;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700241 /* State for diag forwarding */
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800242 struct diag_smd_info smd_data[NUM_SMD_DATA_CHANNELS];
243 struct diag_smd_info smd_cntl[NUM_SMD_CONTROL_CHANNELS];
244 struct diag_smd_info smd_dci[NUM_SMD_DCI_CHANNELS];
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700245 unsigned char *usb_buf_out;
246 unsigned char *apps_rsp_buf;
Shalabh Jain69890aa2011-10-10 12:59:16 -0700247 unsigned char *user_space_data;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800248 /* buffer for updating mask to peripherals */
249 unsigned char *buf_msg_mask_update;
250 unsigned char *buf_log_mask_update;
251 unsigned char *buf_event_mask_update;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800252 unsigned char *buf_feature_mask_update;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700253 int read_len_legacy;
Dixon Peterson25f042b2013-02-27 13:00:08 -0800254 struct mutex diag_hdlc_mutex;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700255 unsigned char *hdlc_buf;
256 unsigned hdlc_count;
257 unsigned hdlc_escape;
258#ifdef CONFIG_DIAG_OVER_USB
259 int usb_connected;
260 struct usb_diag_ch *legacy_ch;
261 struct work_struct diag_proc_hdlc_work;
262 struct work_struct diag_read_work;
263#endif
264 struct workqueue_struct *diag_wq;
265 struct work_struct diag_drain_work;
Shalabh Jain321c8b52012-02-22 12:37:06 -0800266 struct workqueue_struct *diag_cntl_wq;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700267 uint8_t *msg_masks;
268 uint8_t *log_masks;
269 int log_masks_length;
270 uint8_t *event_masks;
Ravi Aravamudhand09f8772012-12-20 14:48:30 -0800271 uint8_t log_on_demand_support;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700272 struct diag_master_table *table;
273 uint8_t *pkt_buf;
274 int pkt_length;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700275 struct diag_request *usb_read_ptr;
276 struct diag_request *write_ptr_svc;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700277 int logging_mode;
Shalabh Jainc236f982011-12-15 22:55:20 -0800278 int mask_check;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700279 int logging_process_id;
Dixon Peterson625ee652012-06-21 22:03:49 -0700280 struct task_struct *socket_process;
Shalabh Jain84e30342012-10-16 16:16:08 -0700281 struct task_struct *callback_process;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700282#ifdef CONFIG_DIAG_SDIO_PIPE
283 unsigned char *buf_in_sdio;
284 unsigned char *usb_buf_mdm_out;
285 struct sdio_channel *sdio_ch;
286 int read_len_mdm;
287 int in_busy_sdio;
288 struct usb_diag_ch *mdm_ch;
289 struct work_struct diag_read_mdm_work;
290 struct workqueue_struct *diag_sdio_wq;
291 struct work_struct diag_read_sdio_work;
Shalabh Jain5d9ba342011-08-10 13:51:54 -0700292 struct work_struct diag_close_sdio_work;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700293 struct diag_request *usb_read_mdm_ptr;
294 struct diag_request *write_ptr_mdm;
295#endif
Shalabh Jain737fca72012-11-14 21:53:43 -0800296#ifdef CONFIG_DIAGFWD_BRIDGE_CODE
Dixon Peterson13046ed2013-02-21 17:35:35 -0800297 spinlock_t hsic_ready_spinlock;
Shalabh Jain737fca72012-11-14 21:53:43 -0800298 /* common for all bridges */
299 struct work_struct diag_disconnect_work;
Shalabh Jainf7228dc2012-05-23 17:32:05 -0700300 /* SGLTE variables */
301 int lcid;
302 unsigned char *buf_in_smux;
303 int in_busy_smux;
304 int diag_smux_enabled;
Ashay Jaiswal2d8daae2012-07-17 17:29:33 +0530305 int smux_connected;
Dixon Peterson938f8602012-08-17 20:02:57 -0700306 struct diag_request *write_ptr_mdm;
Dixon Peterson32e70bb2011-12-16 13:26:45 -0800307#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700308};
309
Shalabh Jain737fca72012-11-14 21:53:43 -0800310extern struct diag_bridge_dev *diag_bridge;
Shalabh Jainb0037c02013-01-18 12:47:40 -0800311extern struct diag_hsic_dev *diag_hsic;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700312extern struct diagchar_dev *driver;
Ravi Aravamudhanf55dc1d2012-12-27 11:51:42 -0800313
314extern int wrap_enabled;
315extern uint16_t wrap_count;
316
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700317#endif