Sreelakshmi Gownipalli | e7c171e | 2013-12-26 17:19:31 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 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 DIAG_DCI_H |
| 13 | #define DIAG_DCI_H |
Shalabh Jain | 1679490 | 2012-09-14 10:56:49 -0700 | [diff] [blame] | 14 | |
| 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 Aravamudhan | c8a192a | 2013-02-22 10:23:15 -0800 | [diff] [blame] | 25 | #define MAX_EVENT_SIZE 512 |
Mohit Aggarwal | 65b69cf | 2013-02-15 11:33:04 -0800 | [diff] [blame] | 26 | #define DCI_CLIENT_INDEX_INVALID -1 |
Dixon Peterson | f90d546 | 2013-10-07 15:03:01 -0700 | [diff] [blame] | 27 | #define DCI_PKT_REQ_MIN_LEN 5 |
Ravi Aravamudhan | b77c694 | 2013-06-04 10:10:11 -0700 | [diff] [blame] | 28 | #define DCI_LOG_CON_MIN_LEN 14 |
| 29 | #define DCI_EVENT_CON_MIN_LEN 16 |
Mohit Aggarwal | 65b69cf | 2013-02-15 11:33:04 -0800 | [diff] [blame] | 30 | |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 31 | #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 Aravamudhan | 3dc6635 | 2013-06-14 10:46:19 -0700 | [diff] [blame] | 38 | #ifdef CONFIG_DEBUG_FS |
| 39 | #define DIAG_DCI_DEBUG_CNT 100 |
| 40 | #define DIAG_DCI_DEBUG_LEN 100 |
| 41 | #endif |
Shalabh Jain | 1679490 | 2012-09-14 10:56:49 -0700 | [diff] [blame] | 42 | |
| 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 Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 51 | |
Ravi Aravamudhan | c94a473 | 2013-12-10 10:26:10 -0800 | [diff] [blame] | 52 | #define MIN_DELAYED_RSP_LEN 12 |
| 53 | |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 54 | extern unsigned int dci_max_reg; |
| 55 | extern unsigned int dci_max_clients; |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 56 | extern unsigned char dci_cumulative_log_mask[DCI_LOG_MASK_SIZE]; |
| 57 | extern unsigned char dci_cumulative_event_mask[DCI_EVENT_MASK_SIZE]; |
Mohit Aggarwal | 3aa4586 | 2013-03-05 18:37:58 +0530 | [diff] [blame] | 58 | extern struct mutex dci_health_mutex; |
Shalabh Jain | 1679490 | 2012-09-14 10:56:49 -0700 | [diff] [blame] | 59 | |
Ravi Aravamudhan | c94a473 | 2013-12-10 10:26:10 -0800 | [diff] [blame] | 60 | struct dci_pkt_req_entry_t { |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 61 | int pid; |
| 62 | int uid; |
| 63 | int tag; |
Ravi Aravamudhan | c94a473 | 2013-12-10 10:26:10 -0800 | [diff] [blame] | 64 | struct list_head track; |
| 65 | } __packed; |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 66 | |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 67 | struct diag_dci_reg_tbl_t { |
Katish Paran | fc787eb | 2014-01-31 12:00:37 +0530 | [diff] [blame] | 68 | uint32_t client_id; |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 69 | uint16_t notification_list; |
Shalabh Jain | 5e9a92b | 2012-06-07 21:53:49 -0700 | [diff] [blame] | 70 | int signal_type; |
Shalabh Jain | a1c69a4 | 2012-10-23 12:51:30 -0700 | [diff] [blame] | 71 | }; |
| 72 | |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 73 | struct diag_dci_health_t { |
Shalabh Jain | a1c69a4 | 2012-10-23 12:51:30 -0700 | [diff] [blame] | 74 | int dropped_logs; |
| 75 | int dropped_events; |
| 76 | int received_logs; |
| 77 | int received_events; |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 78 | }; |
| 79 | |
| 80 | struct 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 | |
| 92 | struct 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 | |
| 101 | struct 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 | |
| 114 | struct diag_dci_health_stats { |
| 115 | struct diag_dci_health_t stats; |
Shalabh Jain | a1c69a4 | 2012-10-23 12:51:30 -0700 | [diff] [blame] | 116 | int reset_status; |
Shalabh Jain | 5e9a92b | 2012-06-07 21:53:49 -0700 | [diff] [blame] | 117 | }; |
| 118 | |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 119 | struct diag_dci_health_stats_proc { |
| 120 | struct diag_dci_health_stats *health; |
| 121 | int proc; |
| 122 | }; |
| 123 | |
Mohit Aggarwal | 3aa4586 | 2013-03-05 18:37:58 +0530 | [diff] [blame] | 124 | /* This is used for querying DCI Log |
| 125 | or Event Mask */ |
| 126 | struct diag_log_event_stats { |
| 127 | uint16_t code; |
| 128 | int is_set; |
| 129 | }; |
| 130 | |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 131 | struct 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 Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 139 | enum { |
| 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 Aravamudhan | 3dc6635 | 2013-06-14 10:46:19 -0700 | [diff] [blame] | 149 | #ifdef CONFIG_DEBUG_FS |
| 150 | /* To collect debug information during each smd read */ |
| 151 | struct diag_dci_data_info { |
| 152 | unsigned long iteration; |
| 153 | int data_size; |
| 154 | char time_stamp[DIAG_TS_SIZE]; |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 155 | uint8_t peripheral; |
Ravi Aravamudhan | 67db95c | 2013-07-18 10:00:50 -0700 | [diff] [blame] | 156 | uint8_t ch_type; |
Ravi Aravamudhan | 3dc6635 | 2013-06-14 10:46:19 -0700 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | extern struct diag_dci_data_info *dci_data_smd; |
| 160 | extern struct mutex dci_stat_mutex; |
| 161 | #endif |
| 162 | |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 163 | int diag_dci_init(void); |
| 164 | void diag_dci_exit(void); |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 165 | int diag_dci_register_client(struct diag_dci_reg_tbl_t *reg_entry); |
| 166 | int diag_dci_deinit_client(void); |
Dixon Peterson | 5a26a30 | 2012-11-15 17:26:17 -0800 | [diff] [blame] | 167 | void diag_update_smd_dci_work_fn(struct work_struct *); |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 168 | void diag_dci_notify_client(int peripheral_mask, int data); |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 169 | void diag_dci_wakeup_clients(void); |
| 170 | void diag_process_apps_dci_read_data(int data_type, void *buf, int recd_bytes); |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 171 | int diag_process_smd_dci_read_data(struct diag_smd_info *smd_info, void *buf, |
| 172 | int recd_bytes); |
Shalabh Jain | 1679490 | 2012-09-14 10:56:49 -0700 | [diff] [blame] | 173 | int diag_process_dci_transaction(unsigned char *buf, int len); |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 174 | void extract_dci_pkt_rsp(unsigned char *buf, int len, int data_source, |
| 175 | struct diag_smd_info *smd_info); |
| 176 | struct diag_dci_client_tbl *diag_dci_get_client_entry(void); |
Shalabh Jain | 1679490 | 2012-09-14 10:56:49 -0700 | [diff] [blame] | 177 | /* DCI Log streaming functions */ |
| 178 | void create_dci_log_mask_tbl(unsigned char *tbl_buf); |
Ravi Aravamudhan | f70200e | 2013-02-13 10:05:36 -0800 | [diff] [blame] | 179 | void update_dci_cumulative_log_mask(int offset, unsigned int byte_index, |
Ravi Aravamudhan | df2947a | 2012-11-16 18:10:05 -0800 | [diff] [blame] | 180 | uint8_t byte_mask); |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 181 | void diag_dci_invalidate_cumulative_log_mask(void); |
| 182 | int diag_send_dci_log_mask(void); |
| 183 | void extract_dci_log(unsigned char *buf, int len, int data_source); |
Mohit Aggarwal | 3aa4586 | 2013-03-05 18:37:58 +0530 | [diff] [blame] | 184 | int diag_dci_clear_log_mask(void); |
| 185 | int diag_dci_query_log_mask(uint16_t log_code); |
Shalabh Jain | 1679490 | 2012-09-14 10:56:49 -0700 | [diff] [blame] | 186 | /* DCI event streaming functions */ |
Ravi Aravamudhan | df2947a | 2012-11-16 18:10:05 -0800 | [diff] [blame] | 187 | void update_dci_cumulative_event_mask(int offset, uint8_t byte_mask); |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 188 | void diag_dci_invalidate_cumulative_event_mask(void); |
| 189 | int diag_send_dci_event_mask(void); |
| 190 | void extract_dci_events(unsigned char *buf, int len, int data_source); |
Shalabh Jain | 1679490 | 2012-09-14 10:56:49 -0700 | [diff] [blame] | 191 | void create_dci_event_mask_tbl(unsigned char *tbl_buf); |
Mohit Aggarwal | 3aa4586 | 2013-03-05 18:37:58 +0530 | [diff] [blame] | 192 | int diag_dci_clear_event_mask(void); |
| 193 | int diag_dci_query_event_mask(uint16_t event_id); |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 194 | void diag_dci_smd_record_info(int read_bytes, uint8_t ch_type, |
| 195 | uint8_t peripheral); |
Ravi Aravamudhan | 6a2da56 | 2013-06-17 16:01:34 -0700 | [diff] [blame] | 196 | uint8_t diag_dci_get_cumulative_real_time(void); |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 197 | int diag_dci_set_real_time(uint8_t real_time); |
| 198 | int diag_dci_copy_health_stats(struct diag_dci_health_stats *stats, int proc); |
Ravi Aravamudhan | 37903fe | 2013-06-03 12:35:05 -0700 | [diff] [blame] | 199 | /* Functions related to DCI wakeup sources */ |
Katish Paran | 244514d | 2013-08-01 18:39:31 -0700 | [diff] [blame^] | 200 | void diag_dci_try_activate_wakeup_source(void); |
| 201 | void diag_dci_try_deactivate_wakeup_source(void); |
| 202 | int diag_dci_write_proc(int peripheral, int pkt_type, char *buf, int len); |
Shalabh Jain | 1c99e4c | 2012-03-26 18:47:59 -0700 | [diff] [blame] | 203 | #endif |