Duy Truong | 790f06d | 2013-02-13 16:38:12 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, The Linux Foundation. All rights reserved. |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -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 | |
| 13 | #include <linux/slab.h> |
| 14 | #include <linux/diagchar.h> |
| 15 | #include <linux/platform_device.h> |
Dixon Peterson | cc0bea77 | 2012-04-11 20:45:37 -0700 | [diff] [blame] | 16 | #include <linux/kmemleak.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 17 | #include "diagchar.h" |
| 18 | #include "diagfwd.h" |
| 19 | #include "diagfwd_cntl.h" |
Shalabh Jain | 7b20eab | 2012-06-19 17:50:58 -0700 | [diff] [blame] | 20 | /* tracks which peripheral is undergoing SSR */ |
| 21 | static uint16_t reg_dirty; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 22 | #define HDR_SIZ 8 |
| 23 | |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 24 | void diag_clean_reg_fn(struct work_struct *work) |
Shalabh Jain | 7b20eab | 2012-06-19 17:50:58 -0700 | [diff] [blame] | 25 | { |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 26 | struct diag_smd_info *smd_info = container_of(work, |
| 27 | struct diag_smd_info, |
| 28 | diag_notify_update_smd_work); |
| 29 | if (!smd_info) |
Shalabh Jain | 4e1bd31 | 2012-02-16 19:33:05 -0800 | [diff] [blame] | 30 | return; |
| 31 | |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 32 | pr_debug("diag: clean registration for peripheral: %d\n", |
| 33 | smd_info->peripheral); |
| 34 | |
| 35 | reg_dirty |= smd_info->peripheral_mask; |
| 36 | diag_clear_reg(smd_info->peripheral); |
| 37 | reg_dirty ^= smd_info->peripheral_mask; |
| 38 | |
| 39 | smd_info->notify_context = 0; |
Shalabh Jain | 4e1bd31 | 2012-02-16 19:33:05 -0800 | [diff] [blame] | 40 | } |
| 41 | |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 42 | /* Process the data read from the smd control channel */ |
| 43 | int diag_process_smd_cntl_read_data(struct diag_smd_info *smd_info, void *buf, |
| 44 | int total_recd) |
Shalabh Jain | 4e1bd31 | 2012-02-16 19:33:05 -0800 | [diff] [blame] | 45 | { |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 46 | int data_len = 0, type = -1, count_bytes = 0, j, flag = 0; |
Ravi Aravamudhan | d09f877 | 2012-12-20 14:48:30 -0800 | [diff] [blame] | 47 | int feature_mask_len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 48 | struct bindpkt_params_per_process *pkt_params = |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 49 | kzalloc(sizeof(struct bindpkt_params_per_process), GFP_KERNEL); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 50 | struct diag_ctrl_msg *msg; |
| 51 | struct cmd_code_range *range; |
| 52 | struct bindpkt_params *temp; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 53 | |
Shalabh Jain | 4e1bd31 | 2012-02-16 19:33:05 -0800 | [diff] [blame] | 54 | if (pkt_params == NULL) { |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 55 | pr_alert("diag: In %s, Memory allocation failure\n", |
| 56 | __func__); |
| 57 | return 0; |
Shalabh Jain | 4e1bd31 | 2012-02-16 19:33:05 -0800 | [diff] [blame] | 58 | } |
| 59 | |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 60 | if (!smd_info) { |
| 61 | pr_err("diag: In %s, No smd info. Not able to read.\n", |
| 62 | __func__); |
Shalabh Jain | f89c546 | 2011-08-23 18:46:03 -0700 | [diff] [blame] | 63 | kfree(pkt_params); |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 64 | return 0; |
Shalabh Jain | f89c546 | 2011-08-23 18:46:03 -0700 | [diff] [blame] | 65 | } |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 66 | |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 67 | while (count_bytes + HDR_SIZ <= total_recd) { |
| 68 | type = *(uint32_t *)(buf); |
| 69 | data_len = *(uint32_t *)(buf + 4); |
| 70 | if (type < DIAG_CTRL_MSG_REG || |
| 71 | type > DIAG_CTRL_MSG_F3_MASK_V2) { |
| 72 | pr_alert("diag: In %s, Invalid Msg type %d proc %d", |
| 73 | __func__, type, smd_info->peripheral); |
| 74 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 75 | } |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 76 | if (data_len < 0 || data_len > total_recd) { |
| 77 | pr_alert("diag: In %s, Invalid data len %d, total_recd: %d, proc %d", |
| 78 | __func__, data_len, total_recd, |
| 79 | smd_info->peripheral); |
| 80 | break; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 81 | } |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 82 | count_bytes = count_bytes+HDR_SIZ+data_len; |
| 83 | if (type == DIAG_CTRL_MSG_REG && total_recd >= count_bytes) { |
| 84 | msg = buf+HDR_SIZ; |
| 85 | range = buf+HDR_SIZ+ |
| 86 | sizeof(struct diag_ctrl_msg); |
| 87 | pkt_params->count = msg->count_entries; |
| 88 | temp = kzalloc(pkt_params->count * sizeof(struct |
| 89 | bindpkt_params), GFP_KERNEL); |
| 90 | if (temp == NULL) { |
| 91 | pr_alert("diag: In %s, Memory alloc fail\n", |
| 92 | __func__); |
| 93 | kfree(pkt_params); |
| 94 | return flag; |
| 95 | } |
| 96 | for (j = 0; j < pkt_params->count; j++) { |
| 97 | temp->cmd_code = msg->cmd_code; |
| 98 | temp->subsys_id = msg->subsysid; |
| 99 | temp->client_id = smd_info->peripheral; |
Dixon Peterson | eecbadb | 2012-12-10 21:59:28 -0800 | [diff] [blame] | 100 | temp->proc_id = NON_APPS_PROC; |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 101 | temp->cmd_code_lo = range->cmd_code_lo; |
| 102 | temp->cmd_code_hi = range->cmd_code_hi; |
| 103 | range++; |
| 104 | temp++; |
| 105 | } |
| 106 | temp -= pkt_params->count; |
| 107 | pkt_params->params = temp; |
| 108 | flag = 1; |
| 109 | /* peripheral undergoing SSR should not |
| 110 | * record new registration |
| 111 | */ |
| 112 | if (!(reg_dirty & smd_info->peripheral_mask)) |
| 113 | diagchar_ioctl(NULL, DIAG_IOCTL_COMMAND_REG, |
| 114 | (unsigned long)pkt_params); |
| 115 | else |
| 116 | pr_err("diag: drop reg proc %d\n", |
| 117 | smd_info->peripheral); |
| 118 | kfree(temp); |
Ravi Aravamudhan | d09f877 | 2012-12-20 14:48:30 -0800 | [diff] [blame] | 119 | } else if ((type == DIAG_CTRL_MSG_FEATURE) && |
| 120 | (smd_info->peripheral == MODEM_DATA)) { |
| 121 | feature_mask_len = *(int *)(buf + 8); |
| 122 | driver->log_on_demand_support = (*(uint8_t *) |
| 123 | (buf + 12)) & 0x04; |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 124 | } else if (type != DIAG_CTRL_MSG_REG) { |
| 125 | flag = 1; |
| 126 | } |
| 127 | buf = buf + HDR_SIZ + data_len; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 128 | } |
| 129 | kfree(pkt_params); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 130 | |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 131 | return flag; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 134 | static int diag_smd_cntl_probe(struct platform_device *pdev) |
| 135 | { |
| 136 | int r = 0; |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 137 | int index = -1; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 138 | |
Shalabh Jain | 10f5f43 | 2012-01-11 11:45:44 +0530 | [diff] [blame] | 139 | /* open control ports only on 8960 & newer targets */ |
Shalabh Jain | fb8e3c1 | 2011-10-19 17:29:42 -0700 | [diff] [blame] | 140 | if (chk_apps_only()) { |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 141 | if (pdev->id == SMD_APPS_MODEM) { |
Dixon Peterson | eecbadb | 2012-12-10 21:59:28 -0800 | [diff] [blame] | 142 | index = MODEM_DATA; |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 143 | r = smd_open("DIAG_CNTL", |
| 144 | &driver->smd_cntl[index].ch, |
| 145 | &driver->smd_cntl[index], |
| 146 | diag_smd_notify); |
| 147 | driver->smd_cntl[index].ch_save = |
| 148 | driver->smd_cntl[index].ch; |
| 149 | } else if (pdev->id == SMD_APPS_QDSP) { |
Dixon Peterson | eecbadb | 2012-12-10 21:59:28 -0800 | [diff] [blame] | 150 | index = LPASS_DATA; |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 151 | r = smd_named_open_on_edge("DIAG_CNTL", |
| 152 | SMD_APPS_QDSP, |
| 153 | &driver->smd_cntl[index].ch, |
| 154 | &driver->smd_cntl[index], |
| 155 | diag_smd_notify); |
| 156 | driver->smd_cntl[index].ch_save = |
| 157 | driver->smd_cntl[index].ch; |
| 158 | } else if (pdev->id == SMD_APPS_WCNSS) { |
Dixon Peterson | eecbadb | 2012-12-10 21:59:28 -0800 | [diff] [blame] | 159 | index = WCNSS_DATA; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 160 | r = smd_named_open_on_edge("APPS_RIVA_CTRL", |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 161 | SMD_APPS_WCNSS, |
| 162 | &driver->smd_cntl[index].ch, |
| 163 | &driver->smd_cntl[index], |
| 164 | diag_smd_notify); |
| 165 | driver->smd_cntl[index].ch_save = |
| 166 | driver->smd_cntl[index].ch; |
| 167 | } |
| 168 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 169 | pr_debug("diag: open CNTL port, ID = %d,r = %d\n", pdev->id, r); |
| 170 | } |
| 171 | return 0; |
| 172 | } |
| 173 | |
| 174 | static int diagfwd_cntl_runtime_suspend(struct device *dev) |
| 175 | { |
| 176 | dev_dbg(dev, "pm_runtime: suspending...\n"); |
| 177 | return 0; |
| 178 | } |
| 179 | |
| 180 | static int diagfwd_cntl_runtime_resume(struct device *dev) |
| 181 | { |
| 182 | dev_dbg(dev, "pm_runtime: resuming...\n"); |
| 183 | return 0; |
| 184 | } |
| 185 | |
| 186 | static const struct dev_pm_ops diagfwd_cntl_dev_pm_ops = { |
| 187 | .runtime_suspend = diagfwd_cntl_runtime_suspend, |
| 188 | .runtime_resume = diagfwd_cntl_runtime_resume, |
| 189 | }; |
| 190 | |
| 191 | static struct platform_driver msm_smd_ch1_cntl_driver = { |
| 192 | |
| 193 | .probe = diag_smd_cntl_probe, |
| 194 | .driver = { |
| 195 | .name = "DIAG_CNTL", |
| 196 | .owner = THIS_MODULE, |
| 197 | .pm = &diagfwd_cntl_dev_pm_ops, |
| 198 | }, |
| 199 | }; |
| 200 | |
| 201 | static struct platform_driver diag_smd_lite_cntl_driver = { |
| 202 | |
| 203 | .probe = diag_smd_cntl_probe, |
| 204 | .driver = { |
| 205 | .name = "APPS_RIVA_CTRL", |
| 206 | .owner = THIS_MODULE, |
| 207 | .pm = &diagfwd_cntl_dev_pm_ops, |
| 208 | }, |
| 209 | }; |
| 210 | |
| 211 | void diagfwd_cntl_init(void) |
| 212 | { |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 213 | int success; |
| 214 | int i; |
| 215 | |
Shalabh Jain | 7b20eab | 2012-06-19 17:50:58 -0700 | [diff] [blame] | 216 | reg_dirty = 0; |
Shalabh Jain | 3d29fc3 | 2012-02-09 17:15:59 -0800 | [diff] [blame] | 217 | driver->polling_reg_flag = 0; |
Ravi Aravamudhan | d09f877 | 2012-12-20 14:48:30 -0800 | [diff] [blame] | 218 | driver->log_on_demand_support = 1; |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 219 | driver->diag_cntl_wq = create_singlethread_workqueue("diag_cntl_wq"); |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 220 | |
Dixon Peterson | eecbadb | 2012-12-10 21:59:28 -0800 | [diff] [blame] | 221 | success = diag_smd_constructor(&driver->smd_cntl[MODEM_DATA], |
| 222 | MODEM_DATA, SMD_CNTL_TYPE); |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 223 | if (!success) |
| 224 | goto err; |
| 225 | |
Dixon Peterson | eecbadb | 2012-12-10 21:59:28 -0800 | [diff] [blame] | 226 | success = diag_smd_constructor(&driver->smd_cntl[LPASS_DATA], |
| 227 | LPASS_DATA, SMD_CNTL_TYPE); |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 228 | if (!success) |
| 229 | goto err; |
| 230 | |
Dixon Peterson | eecbadb | 2012-12-10 21:59:28 -0800 | [diff] [blame] | 231 | success = diag_smd_constructor(&driver->smd_cntl[WCNSS_DATA], |
| 232 | WCNSS_DATA, SMD_CNTL_TYPE); |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 233 | if (!success) |
| 234 | goto err; |
| 235 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 236 | platform_driver_register(&msm_smd_ch1_cntl_driver); |
| 237 | platform_driver_register(&diag_smd_lite_cntl_driver); |
| 238 | |
| 239 | return; |
| 240 | err: |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 241 | pr_err("diag: Could not initialize diag buffers"); |
| 242 | |
| 243 | for (i = 0; i < NUM_SMD_CONTROL_CHANNELS; i++) |
| 244 | diag_smd_destructor(&driver->smd_cntl[i]); |
| 245 | |
| 246 | if (driver->diag_cntl_wq) |
| 247 | destroy_workqueue(driver->diag_cntl_wq); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | void diagfwd_cntl_exit(void) |
| 251 | { |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 252 | int i; |
| 253 | |
| 254 | for (i = 0; i < NUM_SMD_CONTROL_CHANNELS; i++) |
| 255 | diag_smd_destructor(&driver->smd_cntl[i]); |
| 256 | |
Shalabh Jain | 321c8b5 | 2012-02-22 12:37:06 -0800 | [diff] [blame] | 257 | destroy_workqueue(driver->diag_cntl_wq); |
Dixon Peterson | 66fb11b | 2012-12-04 20:30:54 -0800 | [diff] [blame] | 258 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 259 | platform_driver_unregister(&msm_smd_ch1_cntl_driver); |
| 260 | platform_driver_unregister(&diag_smd_lite_cntl_driver); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 261 | } |