diagchar.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484
  1. /* Copyright (c) 2008-2015, The Linux Foundation. All rights reserved.
  2. *
  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. #ifndef DIAGCHAR_H
  13. #define DIAGCHAR_H
  14. #include <linux/init.h>
  15. #include <linux/module.h>
  16. #include <linux/mempool.h>
  17. #include <linux/mutex.h>
  18. #include <linux/list.h>
  19. #include <linux/spinlock.h>
  20. #include <linux/workqueue.h>
  21. #include <linux/sched.h>
  22. #include <linux/wakelock.h>
  23. #include <mach/msm_smd.h>
  24. #include <asm/atomic.h>
  25. /* Size of the USB buffers used for read and write*/
  26. #define USB_MAX_OUT_BUF 4096
  27. #define APPS_BUF_SIZE 4096
  28. #define IN_BUF_SIZE 16384
  29. #define MAX_IN_BUF_SIZE 32768
  30. #define MAX_SYNC_OBJ_NAME_SIZE 32
  31. /* Size of the buffer used for deframing a packet
  32. reveived from the PC tool*/
  33. #define HDLC_MAX 4096
  34. #define HDLC_OUT_BUF_SIZE 8192
  35. #define POOL_TYPE_COPY 1
  36. #define POOL_TYPE_HDLC 2
  37. #define POOL_TYPE_USER 3
  38. #define POOL_TYPE_WRITE_STRUCT 4
  39. #define POOL_TYPE_HSIC 5
  40. #define POOL_TYPE_HSIC_2 6
  41. #define POOL_TYPE_HSIC_WRITE 11
  42. #define POOL_TYPE_HSIC_2_WRITE 12
  43. #define POOL_TYPE_ALL 10
  44. #define POOL_TYPE_DCI 20
  45. #define POOL_COPY_IDX 0
  46. #define POOL_HDLC_IDX 1
  47. #define POOL_USER_IDX 2
  48. #define POOL_WRITE_STRUCT_IDX 3
  49. #define POOL_DCI_IDX 4
  50. #define POOL_BRIDGE_BASE POOL_DCI_IDX
  51. #define POOL_HSIC_IDX (POOL_BRIDGE_BASE + 1)
  52. #define POOL_HSIC_2_IDX (POOL_BRIDGE_BASE + 2)
  53. #define POOL_HSIC_3_IDX (POOL_BRIDGE_BASE + 3)
  54. #define POOL_HSIC_4_IDX (POOL_BRIDGE_BASE + 4)
  55. #define POOL_HSIC_WRITE_IDX (POOL_BRIDGE_BASE + 5)
  56. #define POOL_HSIC_2_WRITE_IDX (POOL_BRIDGE_BASE + 6)
  57. #define POOL_HSIC_3_WRITE_IDX (POOL_BRIDGE_BASE + 7)
  58. #define POOL_HSIC_4_WRITE_IDX (POOL_BRIDGE_BASE + 8)
  59. #ifdef CONFIG_DIAGFWD_BRIDGE_CODE
  60. #define NUM_MEMORY_POOLS 13
  61. #else
  62. #define NUM_MEMORY_POOLS 5
  63. #endif
  64. #define MAX_SSID_PER_RANGE 200
  65. #define ALL_PROC -1
  66. #define MODEM_DATA 0
  67. #define LPASS_DATA 1
  68. #define WCNSS_DATA 2
  69. #define APPS_DATA 3
  70. #define SDIO_DATA 4
  71. #define HSIC_DATA 5
  72. #define HSIC_2_DATA 6
  73. #define SMUX_DATA 10
  74. #define APPS_PROC 1
  75. /*
  76. * Each row contains First (uint32_t), Last (uint32_t), Actual
  77. * last (uint32_t) values along with the range of SSIDs
  78. * (MAX_SSID_PER_RANGE*uint32_t).
  79. * And there are MSG_MASK_TBL_CNT rows.
  80. */
  81. #define MSG_MASK_SIZE ((MAX_SSID_PER_RANGE+3) * 4 * MSG_MASK_TBL_CNT)
  82. #define MAX_EQUIP_ID 16
  83. #define MAX_ITEMS_PER_EQUIP_ID 512
  84. #define LOG_MASK_ITEM_SIZE (5 + MAX_ITEMS_PER_EQUIP_ID)
  85. #define LOG_MASK_SIZE (MAX_EQUIP_ID * LOG_MASK_ITEM_SIZE)
  86. #define EVENT_MASK_SIZE 1000
  87. #define USER_SPACE_DATA 8192
  88. #define PKT_SIZE 4096
  89. #define DIAG_CTRL_MSG_LOG_MASK 9
  90. #define DIAG_CTRL_MSG_EVENT_MASK 10
  91. #define DIAG_CTRL_MSG_F3_MASK 11
  92. #define CONTROL_CHAR 0x7E
  93. #define DIAG_CON_APSS (0x0001) /* Bit mask for APSS */
  94. #define DIAG_CON_MPSS (0x0002) /* Bit mask for MPSS */
  95. #define DIAG_CON_LPASS (0x0004) /* Bit mask for LPASS */
  96. #define DIAG_CON_WCNSS (0x0008) /* Bit mask for WCNSS */
  97. #define NUM_STM_PROCESSORS 4
  98. #define DIAG_STM_MODEM 0x01
  99. #define DIAG_STM_LPASS 0x02
  100. #define DIAG_STM_WCNSS 0x04
  101. #define DIAG_STM_APPS 0x08
  102. #define BAD_PARAM_RESPONSE_MESSAGE 20
  103. #define DIAG_CMD_VERSION 0
  104. #define DIAG_CMD_DOWNLOAD 0x3A
  105. #define DIAG_CMD_DIAG_SUBSYS 0x4B
  106. #define DIAG_CMD_LOG_ON_DMND 0x78
  107. #define DIAG_CMD_EXT_BUILD 0x7c
  108. #define DIAG_SS_DIAG 0x12
  109. #define DIAG_SS_PARAMS 0x32
  110. #define DIAG_DIAG_MAX_PKT_SZ 0x55
  111. #define DIAG_DIAG_STM 0x20E
  112. #define DIAG_DIAG_POLL 0x03
  113. #define DIAG_DEL_RSP_WRAP 0x04
  114. #define DIAG_DEL_RSP_WRAP_CNT 0x05
  115. #define MODE_CMD 41
  116. #define RESET_ID 2
  117. /*
  118. * The status bit masks when received in a signal handler are to be
  119. * used in conjunction with the peripheral list bit mask to determine the
  120. * status for a peripheral. For instance, 0x00010002 would denote an open
  121. * status on the MPSS
  122. */
  123. #define DIAG_STATUS_OPEN (0x00010000) /* DCI channel open status mask */
  124. #define DIAG_STATUS_CLOSED (0x00020000) /* DCI channel closed status mask */
  125. #define MODE_REALTIME 1
  126. #define MODE_NONREALTIME 0
  127. #define NUM_SMD_DATA_CHANNELS 3
  128. #define NUM_SMD_CONTROL_CHANNELS NUM_SMD_DATA_CHANNELS
  129. #define NUM_SMD_DCI_CHANNELS 1
  130. #define NUM_SMD_CMD_CHANNELS 1
  131. #define NUM_SMD_DCI_CMD_CHANNELS 1
  132. /*
  133. * Indicates number of peripherals that can support DCI and Apps
  134. * processor. This doesn't mean that a peripheral has the
  135. * feature.
  136. */
  137. #define NUM_DCI_PROC (NUM_SMD_DATA_CHANNELS + 1)
  138. #define SMD_DATA_TYPE 0
  139. #define SMD_CNTL_TYPE 1
  140. #define SMD_DCI_TYPE 2
  141. #define SMD_CMD_TYPE 3
  142. #define SMD_DCI_CMD_TYPE 4
  143. #define DIAG_PROC_DCI 1
  144. #define DIAG_PROC_MEMORY_DEVICE 2
  145. /* Flags to vote the DCI or Memory device process up or down
  146. when it becomes active or inactive */
  147. #define VOTE_DOWN 0
  148. #define VOTE_UP 1
  149. #define DIAG_TS_SIZE 50
  150. /* Maximum number of pkt reg supported at initialization*/
  151. extern int diag_max_reg;
  152. extern int diag_threshold_reg;
  153. #define APPEND_DEBUG(ch) \
  154. do { \
  155. diag_debug_buf[diag_debug_buf_idx] = ch; \
  156. (diag_debug_buf_idx < 1023) ? \
  157. (diag_debug_buf_idx++) : (diag_debug_buf_idx = 0); \
  158. } while (0)
  159. /* List of remote processor supported */
  160. enum remote_procs {
  161. MDM = 1,
  162. MDM2 = 2,
  163. MDM3 = 3,
  164. MDM4 = 4,
  165. QSC = 5,
  166. };
  167. struct diag_pkt_header_t {
  168. uint8_t cmd_code;
  169. uint8_t subsys_id;
  170. uint16_t subsys_cmd_code;
  171. } __packed;
  172. struct diag_master_table {
  173. uint16_t cmd_code;
  174. uint16_t subsys_id;
  175. uint32_t client_id;
  176. uint16_t cmd_code_lo;
  177. uint16_t cmd_code_hi;
  178. int process_id;
  179. };
  180. struct bindpkt_params_per_process {
  181. /* Name of the synchronization object associated with this proc */
  182. char sync_obj_name[MAX_SYNC_OBJ_NAME_SIZE];
  183. uint32_t count; /* Number of entries in this bind */
  184. struct bindpkt_params *params; /* first bind params */
  185. };
  186. struct bindpkt_params {
  187. uint16_t cmd_code;
  188. uint16_t subsys_id;
  189. uint16_t cmd_code_lo;
  190. uint16_t cmd_code_hi;
  191. /* For Central Routing, used to store Processor number */
  192. uint16_t proc_id;
  193. uint32_t event_id;
  194. uint32_t log_code;
  195. /* For Central Routing, used to store SMD channel pointer */
  196. uint32_t client_id;
  197. };
  198. struct diag_write_device {
  199. void *buf;
  200. int length;
  201. };
  202. struct diag_client_map {
  203. char name[20];
  204. int pid;
  205. };
  206. struct real_time_vote_t {
  207. uint16_t proc;
  208. uint8_t real_time_vote;
  209. };
  210. /* This structure is defined in USB header file */
  211. #ifndef CONFIG_DIAG_OVER_USB
  212. struct diag_request {
  213. char *buf;
  214. int length;
  215. int actual;
  216. int status;
  217. void *context;
  218. };
  219. #endif
  220. struct diag_smd_info {
  221. int peripheral; /* The peripheral this smd channel communicates with */
  222. int type; /* The type of smd channel (data, control, dci) */
  223. uint16_t peripheral_mask;
  224. int encode_hdlc; /* Whether data is raw and needs to be hdlc encoded */
  225. smd_channel_t *ch;
  226. smd_channel_t *ch_save;
  227. struct mutex smd_ch_mutex;
  228. int in_busy_1;
  229. int in_busy_2;
  230. spinlock_t in_busy_lock;
  231. unsigned char *buf_in_1;
  232. unsigned char *buf_in_2;
  233. unsigned char *buf_in_1_raw;
  234. unsigned char *buf_in_2_raw;
  235. unsigned int buf_in_1_size;
  236. unsigned int buf_in_2_size;
  237. unsigned int buf_in_1_raw_size;
  238. unsigned int buf_in_2_raw_size;
  239. struct diag_request *write_ptr_1;
  240. struct diag_request *write_ptr_2;
  241. struct workqueue_struct *wq;
  242. struct work_struct diag_read_smd_work;
  243. struct work_struct diag_notify_update_smd_work;
  244. int notify_context;
  245. struct work_struct diag_general_smd_work;
  246. int general_context;
  247. /*
  248. * Function ptr for function to call to process the data that
  249. * was just read from the smd channel
  250. */
  251. int (*process_smd_read_data)(struct diag_smd_info *smd_info,
  252. void *buf, int num_bytes);
  253. };
  254. struct diagchar_dev {
  255. /* State for the char driver */
  256. unsigned int major;
  257. unsigned int minor_start;
  258. int num;
  259. struct cdev *cdev;
  260. char *name;
  261. int dropped_count;
  262. struct class *diagchar_class;
  263. struct device *diag_dev;
  264. int ref_count;
  265. struct mutex diagchar_mutex;
  266. struct mutex diag_file_mutex;
  267. wait_queue_head_t wait_q;
  268. wait_queue_head_t smd_wait_q;
  269. struct diag_client_map *client_map;
  270. int *data_ready;
  271. int num_clients;
  272. int polling_reg_flag;
  273. struct diag_write_device *buf_tbl;
  274. unsigned int buf_tbl_size;
  275. int use_device_tree;
  276. int supports_separate_cmdrsp;
  277. int supports_apps_hdlc_encoding;
  278. /* The state requested in the STM command */
  279. int stm_state_requested[NUM_STM_PROCESSORS];
  280. /* The current STM state */
  281. int stm_state[NUM_STM_PROCESSORS];
  282. /* Whether or not the peripheral supports STM */
  283. int peripheral_supports_stm[NUM_SMD_CONTROL_CHANNELS];
  284. /* DCI related variables */
  285. struct list_head dci_req_list;
  286. struct list_head dci_client_list;
  287. int dci_tag;
  288. int dci_client_id;
  289. struct mutex dci_mutex;
  290. int num_dci_client;
  291. unsigned char *apps_dci_buf;
  292. int dci_state;
  293. struct workqueue_struct *diag_dci_wq;
  294. struct mutex cmd_reg_mutex;
  295. /* Memory pool parameters */
  296. unsigned int itemsize;
  297. unsigned int poolsize;
  298. unsigned int itemsize_hdlc;
  299. unsigned int poolsize_hdlc;
  300. unsigned int itemsize_user;
  301. unsigned int poolsize_user;
  302. unsigned int itemsize_write_struct;
  303. unsigned int poolsize_write_struct;
  304. unsigned int itemsize_dci;
  305. unsigned int poolsize_dci;
  306. unsigned int debug_flag;
  307. /* State for the mempool for the char driver */
  308. mempool_t *diagpool;
  309. mempool_t *diag_hdlc_pool;
  310. mempool_t *diag_user_pool;
  311. mempool_t *diag_write_struct_pool;
  312. mempool_t *diag_dci_pool;
  313. spinlock_t diag_mem_lock;
  314. int count;
  315. int count_hdlc_pool;
  316. int count_user_pool;
  317. int count_write_struct_pool;
  318. int count_dci_pool;
  319. int used;
  320. /* Buffers for masks */
  321. struct mutex diag_cntl_mutex;
  322. struct diag_ctrl_event_mask *event_mask;
  323. struct diag_ctrl_log_mask *log_mask;
  324. struct diag_ctrl_msg_mask *msg_mask;
  325. struct diag_ctrl_feature_mask *feature_mask;
  326. struct mutex log_mask_mutex;
  327. /* State for diag forwarding */
  328. struct diag_smd_info smd_data[NUM_SMD_DATA_CHANNELS];
  329. struct diag_smd_info smd_cntl[NUM_SMD_CONTROL_CHANNELS];
  330. struct diag_smd_info smd_dci[NUM_SMD_DCI_CHANNELS];
  331. struct diag_smd_info smd_cmd[NUM_SMD_CMD_CHANNELS];
  332. struct diag_smd_info smd_dci_cmd[NUM_SMD_DCI_CMD_CHANNELS];
  333. int rcvd_feature_mask[NUM_SMD_CONTROL_CHANNELS];
  334. int separate_cmdrsp[NUM_SMD_CONTROL_CHANNELS];
  335. unsigned char *usb_buf_out;
  336. unsigned char *apps_rsp_buf;
  337. unsigned char *user_space_data_buf;
  338. /* buffer for updating mask to peripherals */
  339. unsigned char *buf_msg_mask_update;
  340. unsigned char *buf_log_mask_update;
  341. unsigned char *buf_event_mask_update;
  342. unsigned char *buf_feature_mask_update;
  343. int read_len_legacy;
  344. struct mutex diag_hdlc_mutex;
  345. unsigned char *hdlc_buf;
  346. unsigned hdlc_count;
  347. unsigned hdlc_escape;
  348. int in_busy_pktdata;
  349. /* Variables for non real time mode */
  350. int real_time_mode;
  351. int real_time_update_busy;
  352. uint16_t proc_active_mask;
  353. uint16_t proc_rt_vote_mask;
  354. struct mutex real_time_mutex;
  355. struct work_struct diag_real_time_work;
  356. struct workqueue_struct *diag_real_time_wq;
  357. #ifdef CONFIG_DIAG_OVER_USB
  358. int usb_connected;
  359. struct usb_diag_ch *legacy_ch;
  360. struct work_struct diag_proc_hdlc_work;
  361. struct work_struct diag_read_work;
  362. struct work_struct diag_usb_connect_work;
  363. struct work_struct diag_usb_disconnect_work;
  364. #endif
  365. struct workqueue_struct *diag_wq;
  366. struct workqueue_struct *diag_usb_wq;
  367. struct work_struct diag_drain_work;
  368. struct workqueue_struct *diag_cntl_wq;
  369. uint8_t *msg_masks;
  370. uint8_t msg_status;
  371. uint8_t *log_masks;
  372. uint8_t log_status;
  373. uint8_t *event_masks;
  374. uint8_t event_status;
  375. uint8_t log_on_demand_support;
  376. struct diag_master_table *table;
  377. uint8_t *pkt_buf;
  378. int pkt_length;
  379. uint8_t *dci_pkt_buf; /* For Apps DCI packets */
  380. uint32_t dci_pkt_length;
  381. int in_busy_dcipktdata;
  382. struct diag_request *usb_read_ptr;
  383. struct diag_request *write_ptr_svc;
  384. int logging_mode;
  385. int mask_check;
  386. int logging_process_id;
  387. struct task_struct *socket_process;
  388. struct task_struct *callback_process;
  389. /* pid for diag_mdlog(CP silent log app) */
  390. struct pid *silent_log_pid;
  391. #ifdef CONFIG_DIAG_SDIO_PIPE
  392. unsigned char *buf_in_sdio;
  393. unsigned char *usb_buf_mdm_out;
  394. struct sdio_channel *sdio_ch;
  395. int read_len_mdm;
  396. int in_busy_sdio;
  397. struct usb_diag_ch *mdm_ch;
  398. struct work_struct diag_read_mdm_work;
  399. struct workqueue_struct *diag_sdio_wq;
  400. struct work_struct diag_read_sdio_work;
  401. struct work_struct diag_close_sdio_work;
  402. struct diag_request *usb_read_mdm_ptr;
  403. struct diag_request *write_ptr_mdm;
  404. #endif
  405. #ifdef CONFIG_DIAGFWD_BRIDGE_CODE
  406. /* common for all bridges */
  407. struct work_struct diag_connect_work;
  408. struct work_struct diag_disconnect_work;
  409. /* SGLTE variables */
  410. int lcid;
  411. unsigned char *buf_in_smux;
  412. int in_busy_smux;
  413. int diag_smux_enabled;
  414. int smux_connected;
  415. struct diag_request *write_ptr_mdm;
  416. #endif
  417. /* Wakeup source related variables */
  418. spinlock_t ws_lock;
  419. int ws_ref_count;
  420. int copy_count;
  421. };
  422. extern struct diag_bridge_dev *diag_bridge;
  423. extern struct diag_hsic_dev *diag_hsic;
  424. extern struct diagchar_dev *driver;
  425. extern int wrap_enabled;
  426. extern uint16_t wrap_count;
  427. void diag_get_timestamp(char *time_str);
  428. int diag_find_polling_reg(int i);
  429. void check_drain_timer(void);
  430. #endif