blob: ccd1a710c239d3930021a0e2b32e1fe1f7fb73ec [file] [log] [blame]
Sreelakshmi Gownipallie7c171e2013-12-26 17:19:31 -08001/* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved.
Shalabh Jain1c99e4c2012-03-26 18:47:59 -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#ifndef DIAG_DCI_H
13#define DIAG_DCI_H
Shalabh Jain16794902012-09-14 10:56:49 -070014
15#define MAX_DCI_CLIENTS 10
16#define DCI_PKT_RSP_CODE 0x93
17#define DCI_DELAYED_RSP_CODE 0x94
18#define LOG_CMD_CODE 0x10
19#define EVENT_CMD_CODE 0x60
20#define DCI_PKT_RSP_TYPE 0
21#define DCI_LOG_TYPE -1
22#define DCI_EVENT_TYPE -2
23#define SET_LOG_MASK 1
24#define DISABLE_LOG_MASK 0
Ravi Aravamudhanc8a192a2013-02-22 10:23:15 -080025#define MAX_EVENT_SIZE 512
Mohit Aggarwal65b69cf2013-02-15 11:33:04 -080026#define DCI_CLIENT_INDEX_INVALID -1
Dixon Petersonf90d5462013-10-07 15:03:01 -070027#define DCI_PKT_REQ_MIN_LEN 5
Ravi Aravamudhanb77c6942013-06-04 10:10:11 -070028#define DCI_LOG_CON_MIN_LEN 14
29#define DCI_EVENT_CON_MIN_LEN 16
Mohit Aggarwal65b69cf2013-02-15 11:33:04 -080030
Katish Paran244514d2013-08-01 18:39:31 -070031#define DIAG_DATA_TYPE 1
32#define DIAG_CNTL_TYPE 2
33
34#define DCI_BUF_PRIMARY 1
35#define DCI_BUF_SECONDARY 2
36#define DCI_BUF_CMD 3
37
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -070038#ifdef CONFIG_DEBUG_FS
39#define DIAG_DCI_DEBUG_CNT 100
40#define DIAG_DCI_DEBUG_LEN 100
41#endif
Shalabh Jain16794902012-09-14 10:56:49 -070042
43/* 16 log code categories, each has:
44 * 1 bytes equip id + 1 dirty byte + 512 byte max log mask
45 */
46#define DCI_LOG_MASK_SIZE (16*514)
47#define DCI_EVENT_MASK_SIZE 512
48#define DCI_MASK_STREAM 2
49#define DCI_MAX_LOG_CODES 16
50#define DCI_MAX_ITEMS_PER_LOG_CODE 512
Shalabh Jain1c99e4c2012-03-26 18:47:59 -070051
Ravi Aravamudhanc94a4732013-12-10 10:26:10 -080052#define MIN_DELAYED_RSP_LEN 12
53
Shalabh Jain1c99e4c2012-03-26 18:47:59 -070054extern unsigned int dci_max_reg;
55extern unsigned int dci_max_clients;
Katish Paran244514d2013-08-01 18:39:31 -070056extern unsigned char dci_cumulative_log_mask[DCI_LOG_MASK_SIZE];
57extern unsigned char dci_cumulative_event_mask[DCI_EVENT_MASK_SIZE];
Mohit Aggarwal3aa45862013-03-05 18:37:58 +053058extern struct mutex dci_health_mutex;
Shalabh Jain16794902012-09-14 10:56:49 -070059
Ravi Aravamudhanc94a4732013-12-10 10:26:10 -080060struct dci_pkt_req_entry_t {
Shalabh Jain1c99e4c2012-03-26 18:47:59 -070061 int pid;
62 int uid;
63 int tag;
Ravi Aravamudhanc94a4732013-12-10 10:26:10 -080064 struct list_head track;
65} __packed;
Shalabh Jain1c99e4c2012-03-26 18:47:59 -070066
Katish Paran244514d2013-08-01 18:39:31 -070067struct diag_dci_reg_tbl_t {
Katish Paranfc787eb2014-01-31 12:00:37 +053068 uint32_t client_id;
Katish Paran244514d2013-08-01 18:39:31 -070069 uint16_t notification_list;
Shalabh Jain5e9a92b2012-06-07 21:53:49 -070070 int signal_type;
Shalabh Jaina1c69a42012-10-23 12:51:30 -070071};
72
Katish Paran244514d2013-08-01 18:39:31 -070073struct diag_dci_health_t {
Shalabh Jaina1c69a42012-10-23 12:51:30 -070074 int dropped_logs;
75 int dropped_events;
76 int received_logs;
77 int received_events;
Katish Paran244514d2013-08-01 18:39:31 -070078};
79
80struct diag_dci_buffer_t {
81 unsigned char *data;
82 unsigned int data_len;
83 struct mutex data_mutex;
84 uint8_t in_busy;
85 uint8_t buf_type;
86 int data_source;
87 int capacity;
88 uint8_t in_list;
89 struct list_head buf_track;
90};
91
92struct diag_dci_buf_peripheral_t {
93 struct diag_dci_buffer_t *buf_curr;
94 struct diag_dci_buffer_t *buf_primary;
95 struct diag_dci_buffer_t *buf_cmd;
96 struct diag_dci_health_t health;
97 struct mutex health_mutex;
98 struct mutex buf_mutex;
99};
100
101struct diag_dci_client_tbl {
102 struct diag_dci_reg_tbl_t client_info;
103 struct task_struct *client;
104 unsigned char *dci_log_mask;
105 unsigned char *dci_event_mask;
106 uint8_t real_time;
107 struct list_head track;
108 struct diag_dci_buf_peripheral_t buffers[NUM_DCI_PROC];
109 uint8_t in_service;
110 struct list_head list_write_buf;
111 struct mutex write_buf_mutex;
112};
113
114struct diag_dci_health_stats {
115 struct diag_dci_health_t stats;
Shalabh Jaina1c69a42012-10-23 12:51:30 -0700116 int reset_status;
Shalabh Jain5e9a92b2012-06-07 21:53:49 -0700117};
118
Katish Paran244514d2013-08-01 18:39:31 -0700119struct diag_dci_health_stats_proc {
120 struct diag_dci_health_stats *health;
121 int proc;
122};
123
Mohit Aggarwal3aa45862013-03-05 18:37:58 +0530124/* This is used for querying DCI Log
125 or Event Mask */
126struct diag_log_event_stats {
127 uint16_t code;
128 int is_set;
129};
130
Katish Paran244514d2013-08-01 18:39:31 -0700131struct diag_dci_pkt_header_t {
132 uint8_t start;
133 uint8_t version;
134 uint16_t len;
135 uint8_t pkt_code;
136 int tag;
137} __packed;
138
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700139enum {
140 DIAG_DCI_NO_ERROR = 1001, /* No error */
141 DIAG_DCI_NO_REG, /* Could not register */
142 DIAG_DCI_NO_MEM, /* Failed memory allocation */
143 DIAG_DCI_NOT_SUPPORTED, /* This particular client is not supported */
144 DIAG_DCI_HUGE_PACKET, /* Request/Response Packet too huge */
145 DIAG_DCI_SEND_DATA_FAIL,/* writing to kernel or peripheral fails */
146 DIAG_DCI_TABLE_ERR /* Error dealing with registration tables */
147};
148
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -0700149#ifdef CONFIG_DEBUG_FS
150/* To collect debug information during each smd read */
151struct diag_dci_data_info {
152 unsigned long iteration;
153 int data_size;
154 char time_stamp[DIAG_TS_SIZE];
Katish Paran244514d2013-08-01 18:39:31 -0700155 uint8_t peripheral;
Ravi Aravamudhan67db95c2013-07-18 10:00:50 -0700156 uint8_t ch_type;
Ravi Aravamudhan3dc66352013-06-14 10:46:19 -0700157};
158
159extern struct diag_dci_data_info *dci_data_smd;
160extern struct mutex dci_stat_mutex;
161#endif
162
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700163int diag_dci_init(void);
164void diag_dci_exit(void);
Katish Paran244514d2013-08-01 18:39:31 -0700165int diag_dci_register_client(struct diag_dci_reg_tbl_t *reg_entry);
166int diag_dci_deinit_client(void);
Dixon Peterson5a26a302012-11-15 17:26:17 -0800167void diag_update_smd_dci_work_fn(struct work_struct *);
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800168void diag_dci_notify_client(int peripheral_mask, int data);
Katish Paran244514d2013-08-01 18:39:31 -0700169void diag_dci_wakeup_clients(void);
170void diag_process_apps_dci_read_data(int data_type, void *buf, int recd_bytes);
Dixon Peterson66fb11b2012-12-04 20:30:54 -0800171int diag_process_smd_dci_read_data(struct diag_smd_info *smd_info, void *buf,
172 int recd_bytes);
Shalabh Jain16794902012-09-14 10:56:49 -0700173int diag_process_dci_transaction(unsigned char *buf, int len);
Katish Paran244514d2013-08-01 18:39:31 -0700174void extract_dci_pkt_rsp(unsigned char *buf, int len, int data_source,
175 struct diag_smd_info *smd_info);
176struct diag_dci_client_tbl *diag_dci_get_client_entry(void);
Shalabh Jain16794902012-09-14 10:56:49 -0700177/* DCI Log streaming functions */
178void create_dci_log_mask_tbl(unsigned char *tbl_buf);
Ravi Aravamudhanf70200e2013-02-13 10:05:36 -0800179void update_dci_cumulative_log_mask(int offset, unsigned int byte_index,
Ravi Aravamudhandf2947a2012-11-16 18:10:05 -0800180 uint8_t byte_mask);
Katish Paran244514d2013-08-01 18:39:31 -0700181void diag_dci_invalidate_cumulative_log_mask(void);
182int diag_send_dci_log_mask(void);
183void extract_dci_log(unsigned char *buf, int len, int data_source);
Mohit Aggarwal3aa45862013-03-05 18:37:58 +0530184int diag_dci_clear_log_mask(void);
185int diag_dci_query_log_mask(uint16_t log_code);
Shalabh Jain16794902012-09-14 10:56:49 -0700186/* DCI event streaming functions */
Ravi Aravamudhandf2947a2012-11-16 18:10:05 -0800187void update_dci_cumulative_event_mask(int offset, uint8_t byte_mask);
Katish Paran244514d2013-08-01 18:39:31 -0700188void diag_dci_invalidate_cumulative_event_mask(void);
189int diag_send_dci_event_mask(void);
190void extract_dci_events(unsigned char *buf, int len, int data_source);
Shalabh Jain16794902012-09-14 10:56:49 -0700191void create_dci_event_mask_tbl(unsigned char *tbl_buf);
Mohit Aggarwal3aa45862013-03-05 18:37:58 +0530192int diag_dci_clear_event_mask(void);
193int diag_dci_query_event_mask(uint16_t event_id);
Katish Paran244514d2013-08-01 18:39:31 -0700194void diag_dci_smd_record_info(int read_bytes, uint8_t ch_type,
195 uint8_t peripheral);
Ravi Aravamudhan6a2da562013-06-17 16:01:34 -0700196uint8_t diag_dci_get_cumulative_real_time(void);
Katish Paran244514d2013-08-01 18:39:31 -0700197int diag_dci_set_real_time(uint8_t real_time);
198int diag_dci_copy_health_stats(struct diag_dci_health_stats *stats, int proc);
Ravi Aravamudhan37903fe2013-06-03 12:35:05 -0700199/* Functions related to DCI wakeup sources */
Katish Paran244514d2013-08-01 18:39:31 -0700200void diag_dci_try_activate_wakeup_source(void);
201void diag_dci_try_deactivate_wakeup_source(void);
202int diag_dci_write_proc(int peripheral, int pkt_type, char *buf, int len);
Shalabh Jain1c99e4c2012-03-26 18:47:59 -0700203#endif