Pavan Kumar Chilamkurthi | bd69943 | 2018-01-24 12:53:01 -0800 | [diff] [blame] | 1 | /* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [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/module.h> |
| 14 | #include <linux/of_platform.h> |
| 15 | #include <linux/slab.h> |
| 16 | #include <linux/mutex.h> |
| 17 | #include "cam_req_mgr_interface.h" |
| 18 | #include "cam_req_mgr_util.h" |
| 19 | #include "cam_req_mgr_core.h" |
| 20 | #include "cam_req_mgr_workq.h" |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 21 | #include "cam_req_mgr_debug.h" |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 22 | #include "cam_trace.h" |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 23 | #include "cam_debug_util.h" |
Soundrapandian Jeyaprakash | 8d16e27 | 2017-10-12 11:05:37 -0700 | [diff] [blame] | 24 | #include "cam_req_mgr_dev.h" |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 25 | |
| 26 | static struct cam_req_mgr_core_device *g_crm_core_dev; |
| 27 | |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 28 | void cam_req_mgr_handle_core_shutdown(void) |
| 29 | { |
| 30 | struct cam_req_mgr_core_session *session; |
| 31 | struct cam_req_mgr_core_session *tsession; |
| 32 | struct cam_req_mgr_session_info ses_info; |
| 33 | |
| 34 | if (!list_empty(&g_crm_core_dev->session_head)) { |
| 35 | list_for_each_entry_safe(session, tsession, |
| 36 | &g_crm_core_dev->session_head, entry) { |
| 37 | ses_info.session_hdl = |
| 38 | session->session_hdl; |
| 39 | cam_req_mgr_destroy_session(&ses_info); |
| 40 | } |
| 41 | } |
| 42 | } |
| 43 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 44 | static int __cam_req_mgr_setup_payload(struct cam_req_mgr_core_workq *workq) |
| 45 | { |
| 46 | int32_t i = 0; |
| 47 | int rc = 0; |
| 48 | struct crm_task_payload *task_data = NULL; |
| 49 | |
| 50 | task_data = kcalloc( |
| 51 | workq->task.num_task, sizeof(*task_data), |
| 52 | GFP_KERNEL); |
| 53 | if (!task_data) { |
| 54 | rc = -ENOMEM; |
| 55 | } else { |
| 56 | for (i = 0; i < workq->task.num_task; i++) |
| 57 | workq->task.pool[i].payload = &task_data[i]; |
| 58 | } |
| 59 | |
| 60 | return rc; |
| 61 | } |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 62 | |
| 63 | /** |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 64 | * __cam_req_mgr_reset_req_tbl() |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 65 | * |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 66 | * @brief : Initialize req table data |
| 67 | * @in_q : request queue pointer |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 68 | * |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 69 | * @return: 0 for success, negative for failure |
| 70 | * |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 71 | */ |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 72 | static int __cam_req_mgr_print_req_tbl(struct cam_req_mgr_req_data *req) |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 73 | { |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 74 | int rc = 0; |
| 75 | int32_t i = 0; |
| 76 | struct cam_req_mgr_req_queue *in_q = req->in_q; |
| 77 | struct cam_req_mgr_req_tbl *req_tbl = req->l_tbl; |
| 78 | |
| 79 | if (!in_q || !req_tbl) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 80 | CAM_WARN(CAM_CRM, "NULL pointer %pK %pK", in_q, req_tbl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 81 | return -EINVAL; |
| 82 | } |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 83 | CAM_DBG(CAM_CRM, "in_q %pK %pK %d", in_q, req_tbl, req_tbl->num_slots); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 84 | mutex_lock(&req->lock); |
| 85 | for (i = 0; i < in_q->num_slots; i++) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 86 | CAM_DBG(CAM_CRM, "IN_Q %d: idx %d, red_id %lld", i, |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 87 | in_q->slot[i].idx, CRM_GET_REQ_ID(in_q, i)); |
| 88 | } |
| 89 | |
| 90 | while (req_tbl != NULL) { |
| 91 | for (i = 0; i < req_tbl->num_slots; i++) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 92 | CAM_DBG(CAM_CRM, "idx= %d, map= %x, state= %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 93 | req_tbl->slot[i].idx, |
| 94 | req_tbl->slot[i].req_ready_map, |
| 95 | req_tbl->slot[i].state); |
| 96 | } |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 97 | CAM_DBG(CAM_CRM, |
| 98 | "TBL:id= %d, pd=%d cnt=%d mask=%x skip=%d num_slt= %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 99 | req_tbl->id, req_tbl->pd, req_tbl->dev_count, |
| 100 | req_tbl->dev_mask, req_tbl->skip_traverse, |
| 101 | req_tbl->num_slots); |
| 102 | req_tbl = req_tbl->next; |
| 103 | } |
| 104 | mutex_unlock(&req->lock); |
| 105 | |
| 106 | return rc; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * __cam_req_mgr_find_pd_tbl() |
| 111 | * |
| 112 | * @brief : Find pipeline delay based table pointer which matches delay |
| 113 | * @tbl : Pointer to list of request table |
| 114 | * @delay : Pipeline delay value to be searched for comparison |
| 115 | * |
| 116 | * @return : pointer to request table for matching pipeline delay table. |
| 117 | * |
| 118 | */ |
| 119 | static struct cam_req_mgr_req_tbl *__cam_req_mgr_find_pd_tbl( |
| 120 | struct cam_req_mgr_req_tbl *tbl, int32_t delay) |
| 121 | { |
| 122 | if (!tbl) |
| 123 | return NULL; |
| 124 | |
| 125 | do { |
| 126 | if (delay != tbl->pd) |
| 127 | tbl = tbl->next; |
| 128 | else |
| 129 | return tbl; |
| 130 | } while (tbl != NULL); |
| 131 | |
| 132 | return NULL; |
| 133 | } |
| 134 | |
| 135 | /** |
| 136 | * __cam_req_mgr_inc_idx() |
| 137 | * |
| 138 | * @brief : Increment val passed by step size and rollover after max_val |
| 139 | * @val : value to be incremented |
| 140 | * @step : amount/step by which val is incremented |
| 141 | * @max_val : max val after which idx will roll over |
| 142 | * |
| 143 | */ |
| 144 | static void __cam_req_mgr_inc_idx(int32_t *val, int32_t step, int32_t max_val) |
| 145 | { |
| 146 | *val = (*val + step) % max_val; |
| 147 | } |
| 148 | |
| 149 | /** |
| 150 | * __cam_req_mgr_dec_idx() |
| 151 | * |
| 152 | * @brief : Decrement val passed by step size and rollover after max_val |
| 153 | * @val : value to be decremented |
| 154 | * @step : amount/step by which val is decremented |
| 155 | * @max_val : after zero value will roll over to max val |
| 156 | * |
| 157 | */ |
| 158 | static void __cam_req_mgr_dec_idx(int32_t *val, int32_t step, int32_t max_val) |
| 159 | { |
| 160 | *val = *val - step; |
| 161 | if (*val < 0) |
| 162 | *val = max_val + (*val); |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * __cam_req_mgr_traverse() |
| 167 | * |
| 168 | * @brief : Traverse through pd tables, it will internally cover all linked |
| 169 | * pd tables. Each pd table visited will check if idx passed to its |
| 170 | * in ready state. If ready means all devices linked to the pd table |
| 171 | * have this request id packet ready. Then it calls subsequent pd |
| 172 | * tbl with new idx. New idx value takes into account the delta |
| 173 | * between current pd table and next one. |
| 174 | * @traverse_data: contains all the info to traverse through pd tables |
| 175 | * |
| 176 | * @return: 0 for success, negative for failure |
| 177 | * |
| 178 | */ |
| 179 | static int __cam_req_mgr_traverse(struct cam_req_mgr_traverse *traverse_data) |
| 180 | { |
| 181 | int rc = 0; |
| 182 | int32_t next_idx = traverse_data->idx; |
| 183 | int32_t curr_idx = traverse_data->idx; |
| 184 | struct cam_req_mgr_req_tbl *tbl; |
| 185 | struct cam_req_mgr_apply *apply_data; |
| 186 | |
| 187 | if (!traverse_data->tbl || !traverse_data->apply_data) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 188 | CAM_ERR(CAM_CRM, "NULL pointer %pK %pK", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 189 | traverse_data->tbl, traverse_data->apply_data); |
| 190 | traverse_data->result = 0; |
| 191 | return -EINVAL; |
| 192 | } |
| 193 | |
| 194 | tbl = traverse_data->tbl; |
| 195 | apply_data = traverse_data->apply_data; |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 196 | CAM_DBG(CAM_CRM, |
| 197 | "Enter pd %d idx %d state %d skip %d status %d skip_idx %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 198 | tbl->pd, curr_idx, tbl->slot[curr_idx].state, |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 199 | tbl->skip_traverse, traverse_data->in_q->slot[curr_idx].status, |
| 200 | traverse_data->in_q->slot[curr_idx].skip_idx); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 201 | |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 202 | if ((tbl->inject_delay > 0) && |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 203 | (traverse_data->self_link == true)) { |
Sagar Gore | a4d7dfd | 2017-09-13 19:56:24 -0700 | [diff] [blame] | 204 | CAM_DBG(CAM_CRM, "Injecting Delay of one frame"); |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 205 | apply_data[tbl->pd].req_id = -1; |
Sagar Gore | a4d7dfd | 2017-09-13 19:56:24 -0700 | [diff] [blame] | 206 | tbl->inject_delay--; |
| 207 | /* This pd table is not ready to proceed with asked idx */ |
| 208 | SET_FAILURE_BIT(traverse_data->result, tbl->pd); |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 209 | return -EAGAIN; |
Sagar Gore | a4d7dfd | 2017-09-13 19:56:24 -0700 | [diff] [blame] | 210 | } |
| 211 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 212 | /* Check if req is ready or in skip mode or pd tbl is in skip mode */ |
| 213 | if (tbl->slot[curr_idx].state == CRM_REQ_STATE_READY || |
| 214 | traverse_data->in_q->slot[curr_idx].skip_idx == 1 || |
| 215 | tbl->skip_traverse > 0) { |
| 216 | if (tbl->next) { |
| 217 | __cam_req_mgr_dec_idx(&next_idx, tbl->pd_delta, |
| 218 | tbl->num_slots); |
| 219 | traverse_data->idx = next_idx; |
| 220 | traverse_data->tbl = tbl->next; |
| 221 | rc = __cam_req_mgr_traverse(traverse_data); |
| 222 | } |
| 223 | if (rc >= 0) { |
| 224 | SET_SUCCESS_BIT(traverse_data->result, tbl->pd); |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 225 | |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 226 | if (traverse_data->validate_only == false) { |
| 227 | apply_data[tbl->pd].pd = tbl->pd; |
| 228 | apply_data[tbl->pd].req_id = |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 229 | CRM_GET_REQ_ID( |
| 230 | traverse_data->in_q, curr_idx); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 231 | apply_data[tbl->pd].idx = curr_idx; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 232 | |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 233 | CAM_DBG(CAM_CRM, "req_id: %d with pd of %d", |
| 234 | apply_data[tbl->pd].req_id, |
| 235 | apply_data[tbl->pd].pd); |
| 236 | /* |
| 237 | * If traverse is successful decrement |
| 238 | * traverse skip |
| 239 | */ |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 240 | if (tbl->skip_traverse > 0) { |
| 241 | apply_data[tbl->pd].req_id = -1; |
| 242 | tbl->skip_traverse--; |
| 243 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 244 | } |
| 245 | } else { |
| 246 | /* linked pd table is not ready for this traverse yet */ |
| 247 | return rc; |
| 248 | } |
| 249 | } else { |
| 250 | /* This pd table is not ready to proceed with asked idx */ |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 251 | SET_FAILURE_BIT(traverse_data->result, tbl->pd); |
| 252 | return -EAGAIN; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 253 | } |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * __cam_req_mgr_in_q_skip_idx() |
| 259 | * |
| 260 | * @brief : Decrement val passed by step size and rollover after max_val |
| 261 | * @in_q : input queue pointer |
| 262 | * @idx : Sets skip_idx bit of the particular slot to true so when traverse |
| 263 | * happens for this idx, no req will be submitted for devices |
| 264 | * handling this idx. |
| 265 | * |
| 266 | */ |
| 267 | static void __cam_req_mgr_in_q_skip_idx(struct cam_req_mgr_req_queue *in_q, |
| 268 | int32_t idx) |
| 269 | { |
| 270 | in_q->slot[idx].req_id = -1; |
| 271 | in_q->slot[idx].skip_idx = 1; |
| 272 | in_q->slot[idx].status = CRM_SLOT_STATUS_REQ_ADDED; |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 273 | CAM_DBG(CAM_CRM, "SET IDX SKIP on slot= %d", idx); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /** |
| 277 | * __cam_req_mgr_tbl_set_id() |
| 278 | * |
| 279 | * @brief : Set unique id to table |
| 280 | * @tbl : pipeline based table which requires new id |
| 281 | * @req : pointer to request data wihch contains num_tables counter |
| 282 | * |
| 283 | */ |
| 284 | static void __cam_req_mgr_tbl_set_id(struct cam_req_mgr_req_tbl *tbl, |
| 285 | struct cam_req_mgr_req_data *req) |
| 286 | { |
| 287 | if (!tbl) |
| 288 | return; |
| 289 | do { |
| 290 | tbl->id = req->num_tbl++; |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 291 | CAM_DBG(CAM_CRM, "%d: pd %d skip_traverse %d delta %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 292 | tbl->id, tbl->pd, tbl->skip_traverse, |
| 293 | tbl->pd_delta); |
| 294 | tbl = tbl->next; |
| 295 | } while (tbl != NULL); |
| 296 | } |
| 297 | |
| 298 | /** |
| 299 | * __cam_req_mgr_tbl_set_all_skip_cnt() |
| 300 | * |
| 301 | * @brief : Each pd table sets skip value based on delta between itself and |
| 302 | * max pd value. During initial streamon or bubble case this is |
| 303 | * used. That way each pd table skips required num of traverse and |
| 304 | * align themselve with req mgr connected devs. |
| 305 | * @l_tbl : iterates through list of pd tables and sets skip traverse |
| 306 | * |
| 307 | */ |
| 308 | static void __cam_req_mgr_tbl_set_all_skip_cnt( |
| 309 | struct cam_req_mgr_req_tbl **l_tbl) |
| 310 | { |
| 311 | struct cam_req_mgr_req_tbl *tbl = *l_tbl; |
| 312 | int32_t max_pd; |
| 313 | |
| 314 | if (!tbl) |
| 315 | return; |
| 316 | |
| 317 | max_pd = tbl->pd; |
| 318 | do { |
| 319 | tbl->skip_traverse = max_pd - tbl->pd; |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 320 | CAM_DBG(CAM_CRM, "%d: pd %d skip_traverse %d delta %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 321 | tbl->id, tbl->pd, tbl->skip_traverse, |
| 322 | tbl->pd_delta); |
| 323 | tbl = tbl->next; |
| 324 | } while (tbl != NULL); |
| 325 | } |
| 326 | |
| 327 | /** |
| 328 | * __cam_req_mgr_reset_req_slot() |
| 329 | * |
| 330 | * @brief : reset specified idx/slot in input queue as well as all pd tables |
| 331 | * @link : link pointer |
| 332 | * @idx : slot index which will be reset |
| 333 | * |
| 334 | */ |
| 335 | static void __cam_req_mgr_reset_req_slot(struct cam_req_mgr_core_link *link, |
| 336 | int32_t idx) |
| 337 | { |
| 338 | struct cam_req_mgr_slot *slot; |
| 339 | struct cam_req_mgr_req_tbl *tbl = link->req.l_tbl; |
| 340 | struct cam_req_mgr_req_queue *in_q = link->req.in_q; |
| 341 | |
| 342 | slot = &in_q->slot[idx]; |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 343 | CAM_DBG(CAM_CRM, "RESET: idx: %d: slot->status %d", idx, slot->status); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 344 | |
| 345 | /* Check if CSL has already pushed new request*/ |
| 346 | if (slot->status == CRM_SLOT_STATUS_REQ_ADDED) |
| 347 | return; |
| 348 | |
| 349 | /* Reset input queue slot */ |
| 350 | slot->req_id = -1; |
| 351 | slot->skip_idx = 0; |
| 352 | slot->recover = 0; |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 353 | slot->sync_mode = CAM_REQ_MGR_SYNC_MODE_NO_SYNC; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 354 | slot->status = CRM_SLOT_STATUS_NO_REQ; |
| 355 | |
| 356 | /* Reset all pd table slot */ |
| 357 | while (tbl != NULL) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 358 | CAM_DBG(CAM_CRM, "pd: %d: idx %d state %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 359 | tbl->pd, idx, tbl->slot[idx].state); |
| 360 | tbl->slot[idx].req_ready_map = 0; |
| 361 | tbl->slot[idx].state = CRM_REQ_STATE_EMPTY; |
| 362 | tbl = tbl->next; |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * __cam_req_mgr_check_next_req_slot() |
| 368 | * |
| 369 | * @brief : While streaming if input queue does not contain any pending |
| 370 | * request, req mgr still needs to submit pending request ids to |
| 371 | * devices with lower pipeline delay value. |
| 372 | * @in_q : Pointer to input queue where req mgr wil peep into |
| 373 | * |
| 374 | */ |
| 375 | static void __cam_req_mgr_check_next_req_slot( |
| 376 | struct cam_req_mgr_req_queue *in_q) |
| 377 | { |
| 378 | int32_t idx = in_q->rd_idx; |
| 379 | struct cam_req_mgr_slot *slot; |
| 380 | |
| 381 | __cam_req_mgr_inc_idx(&idx, 1, in_q->num_slots); |
| 382 | slot = &in_q->slot[idx]; |
| 383 | |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 384 | CAM_DBG(CAM_CRM, "idx: %d: slot->status %d", idx, slot->status); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 385 | |
| 386 | /* Check if there is new req from CSL, if not complete req */ |
| 387 | if (slot->status == CRM_SLOT_STATUS_NO_REQ) { |
| 388 | __cam_req_mgr_in_q_skip_idx(in_q, idx); |
| 389 | if (in_q->wr_idx != idx) |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 390 | CAM_WARN(CAM_CRM, |
| 391 | "CHECK here wr %d, rd %d", in_q->wr_idx, idx); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 392 | __cam_req_mgr_inc_idx(&in_q->wr_idx, 1, in_q->num_slots); |
| 393 | } |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * __cam_req_mgr_send_req() |
| 398 | * |
| 399 | * @brief : send request id to be applied to each device connected on link |
| 400 | * @link : pointer to link whose input queue and req tbl are |
| 401 | * traversed through |
| 402 | * @in_q : pointer to input request queue |
| 403 | * |
| 404 | * @return : 0 for success, negative for failure |
| 405 | * |
| 406 | */ |
| 407 | static int __cam_req_mgr_send_req(struct cam_req_mgr_core_link *link, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 408 | struct cam_req_mgr_req_queue *in_q, uint32_t trigger) |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 409 | { |
| 410 | int rc = 0, pd, i, idx; |
| 411 | struct cam_req_mgr_connected_device *dev = NULL; |
| 412 | struct cam_req_mgr_apply_request apply_req; |
| 413 | struct cam_req_mgr_link_evt_data evt_data; |
| 414 | |
| 415 | apply_req.link_hdl = link->link_hdl; |
| 416 | apply_req.report_if_bubble = 0; |
| 417 | |
| 418 | for (i = 0; i < link->num_devs; i++) { |
| 419 | dev = &link->l_dev[i]; |
| 420 | if (dev) { |
| 421 | pd = dev->dev_info.p_delay; |
| 422 | if (pd >= CAM_PIPELINE_DELAY_MAX) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 423 | CAM_WARN(CAM_CRM, "pd %d greater than max", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 424 | pd); |
| 425 | continue; |
| 426 | } |
| 427 | if (link->req.apply_data[pd].skip_idx || |
| 428 | link->req.apply_data[pd].req_id < 0) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 429 | CAM_DBG(CAM_CRM, "skip %d req_id %lld", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 430 | link->req.apply_data[pd].skip_idx, |
| 431 | link->req.apply_data[pd].req_id); |
| 432 | continue; |
| 433 | } |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 434 | if (!(dev->dev_info.trigger & trigger)) |
| 435 | continue; |
| 436 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 437 | apply_req.dev_hdl = dev->dev_hdl; |
| 438 | apply_req.request_id = |
| 439 | link->req.apply_data[pd].req_id; |
| 440 | idx = link->req.apply_data[pd].idx; |
| 441 | apply_req.report_if_bubble = |
| 442 | in_q->slot[idx].recover; |
Gregory Bergschneider | 6067993 | 2017-07-19 15:27:16 -0600 | [diff] [blame] | 443 | |
| 444 | trace_cam_req_mgr_apply_request(link, &apply_req, dev); |
| 445 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 446 | apply_req.trigger_point = trigger; |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 447 | CAM_DBG(CAM_CRM, "SEND: link_hdl: %x pd %d req_id %lld", |
| 448 | link->link_hdl, pd, apply_req.request_id); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 449 | if (dev->ops && dev->ops->apply_req) { |
| 450 | rc = dev->ops->apply_req(&apply_req); |
| 451 | if (rc < 0) |
| 452 | break; |
| 453 | } |
| 454 | } |
| 455 | } |
| 456 | if (rc < 0) { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 457 | CAM_ERR_RATE_LIMIT(CAM_CRM, "APPLY FAILED pd %d req_id %lld", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 458 | dev->dev_info.p_delay, apply_req.request_id); |
| 459 | /* Apply req failed notify already applied devs */ |
| 460 | for (; i >= 0; i--) { |
| 461 | dev = &link->l_dev[i]; |
| 462 | evt_data.evt_type = CAM_REQ_MGR_LINK_EVT_ERR; |
| 463 | evt_data.link_hdl = link->link_hdl; |
| 464 | evt_data.req_id = apply_req.request_id; |
| 465 | evt_data.u.error = CRM_KMD_ERR_BUBBLE; |
| 466 | if (dev->ops && dev->ops->process_evt) |
| 467 | dev->ops->process_evt(&evt_data); |
| 468 | } |
| 469 | } |
| 470 | return rc; |
| 471 | } |
| 472 | |
| 473 | /** |
| 474 | * __cam_req_mgr_check_link_is_ready() |
| 475 | * |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 476 | * @brief : traverse through all request tables and see if all devices are |
| 477 | * ready to apply request settings. |
| 478 | * @link : pointer to link whose input queue and req tbl are |
| 479 | * traversed through |
| 480 | * @idx : index within input request queue |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 481 | * @validate_only : Whether to validate only and/or update settings |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 482 | * @self_link : To indicate whether the validation is for the given link or |
| 483 | * other sync link |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 484 | * |
| 485 | * @return : 0 for success, negative for failure |
| 486 | * |
| 487 | */ |
| 488 | static int __cam_req_mgr_check_link_is_ready(struct cam_req_mgr_core_link *link, |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 489 | int32_t idx, bool validate_only, bool self_link) |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 490 | { |
| 491 | int rc; |
| 492 | struct cam_req_mgr_traverse traverse_data; |
| 493 | struct cam_req_mgr_req_queue *in_q; |
| 494 | struct cam_req_mgr_apply *apply_data; |
| 495 | |
| 496 | in_q = link->req.in_q; |
| 497 | |
| 498 | apply_data = link->req.apply_data; |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 499 | |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 500 | if (validate_only == false) { |
| 501 | memset(apply_data, 0, |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 502 | sizeof(struct cam_req_mgr_apply) * CAM_PIPELINE_DELAY_MAX); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 503 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 504 | |
| 505 | traverse_data.apply_data = apply_data; |
| 506 | traverse_data.idx = idx; |
| 507 | traverse_data.tbl = link->req.l_tbl; |
| 508 | traverse_data.in_q = in_q; |
| 509 | traverse_data.result = 0; |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 510 | traverse_data.validate_only = validate_only; |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 511 | traverse_data.self_link = self_link; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 512 | /* |
| 513 | * Traverse through all pd tables, if result is success, |
| 514 | * apply the settings |
| 515 | */ |
| 516 | |
| 517 | rc = __cam_req_mgr_traverse(&traverse_data); |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 518 | CAM_DBG(CAM_CRM, |
| 519 | "SOF: idx %d self_link %d validate %d result %x pd_mask %x rc %d", |
| 520 | idx, traverse_data.self_link, traverse_data.validate_only, |
| 521 | traverse_data.result, link->pd_mask, rc); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 522 | |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 523 | if (!rc && traverse_data.result == link->pd_mask) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 524 | CAM_DBG(CAM_CRM, |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 525 | "APPLY: link_hdl= %x idx= %d, req_id= %lld :%lld :%lld", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 526 | link->link_hdl, idx, |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 527 | apply_data[2].req_id, |
| 528 | apply_data[1].req_id, |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 529 | apply_data[0].req_id); |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 530 | } else |
| 531 | rc = -EAGAIN; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 532 | |
| 533 | return rc; |
| 534 | } |
| 535 | |
| 536 | /** |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 537 | * __cam_req_mgr_find_slot_for_req() |
| 538 | * |
| 539 | * @brief : Find idx from input queue at which req id is enqueued |
| 540 | * @in_q : input request queue pointer |
| 541 | * @req_id : request id which needs to be searched in input queue |
| 542 | * |
| 543 | * @return : slot index where passed request id is stored, -1 for failure |
| 544 | * |
| 545 | */ |
| 546 | static int32_t __cam_req_mgr_find_slot_for_req( |
| 547 | struct cam_req_mgr_req_queue *in_q, int64_t req_id) |
| 548 | { |
| 549 | int32_t idx, i; |
| 550 | struct cam_req_mgr_slot *slot; |
| 551 | |
| 552 | idx = in_q->rd_idx; |
| 553 | for (i = 0; i < in_q->num_slots; i++) { |
| 554 | slot = &in_q->slot[idx]; |
| 555 | if (slot->req_id == req_id) { |
| 556 | CAM_DBG(CAM_CRM, |
| 557 | "req: %lld found at idx: %d status: %d sync_mode: %d", |
| 558 | req_id, idx, slot->status, slot->sync_mode); |
| 559 | break; |
| 560 | } |
| 561 | __cam_req_mgr_dec_idx(&idx, 1, in_q->num_slots); |
| 562 | } |
| 563 | if (i >= in_q->num_slots) |
| 564 | idx = -1; |
| 565 | |
| 566 | return idx; |
| 567 | } |
| 568 | |
| 569 | /** |
| 570 | * __cam_req_mgr_reset_sof_cnt() |
| 571 | * |
| 572 | * @brief : the sof_count for both the links are reset |
| 573 | * @link : pointer to link whose input queue and req tbl are |
| 574 | * traversed through |
| 575 | * |
| 576 | */ |
| 577 | static void __cam_req_mgr_reset_sof_cnt( |
| 578 | struct cam_req_mgr_core_link *link) |
| 579 | { |
| 580 | link->sof_counter = -1; |
| 581 | link->sync_link->sof_counter = -1; |
| 582 | link->frame_skip_flag = false; |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 583 | |
| 584 | CAM_DBG(CAM_CRM, |
| 585 | "link_hdl %x self_counter %lld other_counter %lld frame_skip_lag %d", |
| 586 | link->link_hdl, link->sof_counter, |
| 587 | link->sync_link->sof_counter, link->frame_skip_flag); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 588 | } |
| 589 | |
| 590 | /** |
| 591 | * __cam_req_mgr_sof_cnt_initialize() |
| 592 | * |
| 593 | * @brief : when the sof count is intially -1 it increments count |
| 594 | * and computes the sync_self_ref for this link |
| 595 | * the count needs to be wrapped back starting from 0 |
| 596 | * @link : pointer to link whose input queue and req tbl are |
| 597 | * traversed through |
| 598 | * |
| 599 | */ |
| 600 | static void __cam_req_mgr_sof_cnt_initialize( |
| 601 | struct cam_req_mgr_core_link *link) |
| 602 | { |
| 603 | link->sof_counter++; |
| 604 | link->sync_self_ref = link->sof_counter - |
| 605 | link->sync_link->sof_counter; |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 606 | |
| 607 | CAM_DBG(CAM_CRM, |
| 608 | "link_hdl %x self_counter %lld other_counter %lld", |
| 609 | link->link_hdl, link->sof_counter, |
| 610 | link->sync_link->sof_counter); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 611 | } |
| 612 | |
| 613 | /** |
| 614 | * __cam_req_mgr_wrap_sof_cnt() |
| 615 | * |
| 616 | * @brief : once the sof count reaches a predefined maximum |
| 617 | * the count needs to be wrapped back starting from 0 |
| 618 | * @link : pointer to link whose input queue and req tbl are |
| 619 | * traversed through |
| 620 | * |
| 621 | */ |
| 622 | static void __cam_req_mgr_wrap_sof_cnt( |
| 623 | struct cam_req_mgr_core_link *link) |
| 624 | { |
| 625 | link->sof_counter = (MAX_SYNC_COUNT - |
| 626 | (link->sync_link->sof_counter)); |
| 627 | link->sync_link->sof_counter = 0; |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 628 | |
| 629 | CAM_DBG(CAM_CRM, |
| 630 | "link_hdl %x self_counter %lld sync_link_hdl %x other_counter %lld", |
| 631 | link->link_hdl, link->sof_counter, |
| 632 | link->sync_link->link_hdl, link->sync_link->sof_counter); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 633 | } |
| 634 | |
| 635 | /** |
| 636 | * __cam_req_mgr_validate_sof_cnt() |
| 637 | * |
| 638 | * @brief : validates sof count difference for a given link |
| 639 | * @link : pointer to link whose input queue and req tbl are |
| 640 | * traversed through |
| 641 | * @sync_link : pointer to the sync link |
| 642 | * @return : 0 for success, negative for failure |
| 643 | * |
| 644 | */ |
| 645 | static int __cam_req_mgr_validate_sof_cnt( |
| 646 | struct cam_req_mgr_core_link *link, |
| 647 | struct cam_req_mgr_core_link *sync_link) |
| 648 | { |
| 649 | int64_t sync_diff = 0; |
| 650 | int rc = 0; |
| 651 | |
| 652 | if (link->sof_counter == MAX_SYNC_COUNT) |
| 653 | __cam_req_mgr_wrap_sof_cnt(link); |
| 654 | |
| 655 | sync_diff = link->sof_counter - sync_link->sof_counter; |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 656 | |
| 657 | CAM_DBG(CAM_CRM, |
| 658 | "link[%x] self_counter=%lld other_counter=%lld diff=%lld sync_self_ref=%lld", |
| 659 | link->link_hdl, link->sof_counter, |
| 660 | sync_link->sof_counter, sync_diff, link->sync_self_ref); |
| 661 | |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 662 | if (sync_diff != link->sync_self_ref) { |
| 663 | link->sync_link->frame_skip_flag = true; |
| 664 | CAM_WARN(CAM_CRM, |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 665 | "Detected anomaly, skip link_hdl %x self_counter=%lld other_counter=%lld sync_self_ref=%lld", |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 666 | link->link_hdl, link->sof_counter, |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 667 | sync_link->sof_counter, link->sync_self_ref); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 668 | rc = -EPERM; |
| 669 | } |
| 670 | |
| 671 | return rc; |
| 672 | } |
| 673 | |
| 674 | |
| 675 | /** |
| 676 | * __cam_req_mgr_process_sync_req() |
| 677 | * |
| 678 | * @brief : processes requests during sync mode |
| 679 | * @link : pointer to link whose input queue and req tbl are |
| 680 | * traversed through |
| 681 | * @slot : pointer to the current slot being processed |
| 682 | * @return : 0 for success, negative for failure |
| 683 | * |
| 684 | */ |
| 685 | static int __cam_req_mgr_process_sync_req( |
| 686 | struct cam_req_mgr_core_link *link, |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 687 | struct cam_req_mgr_slot *slot) |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 688 | { |
| 689 | struct cam_req_mgr_core_link *sync_link = NULL; |
| 690 | int64_t req_id = 0; |
| 691 | int sync_slot_idx = 0, rc = 0; |
| 692 | |
| 693 | if (!link->sync_link) { |
| 694 | CAM_ERR(CAM_CRM, "Sync link null"); |
| 695 | return -EINVAL; |
| 696 | } |
| 697 | |
| 698 | sync_link = link->sync_link; |
| 699 | req_id = slot->req_id; |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 700 | |
| 701 | CAM_DBG(CAM_CRM, |
| 702 | "link_hdl %x req %lld sync_self_ref %lld sof_counter %lld frame_skip_flag %d sync_link_self_ref %lld", |
| 703 | link->link_hdl, req_id, link->sync_self_ref, link->sof_counter, |
| 704 | link->frame_skip_flag, link->sync_link->sync_self_ref); |
| 705 | |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 706 | if (link->sof_counter == -1) { |
| 707 | __cam_req_mgr_sof_cnt_initialize(link); |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 708 | } else if ((link->frame_skip_flag) && |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 709 | (sync_link->sync_self_ref != -1)) { |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 710 | CAM_DBG(CAM_CRM, "Link[%x] Req[%lld] Resetting values ", |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 711 | link->link_hdl, req_id); |
| 712 | __cam_req_mgr_reset_sof_cnt(link); |
| 713 | __cam_req_mgr_sof_cnt_initialize(link); |
| 714 | } else { |
| 715 | link->sof_counter++; |
| 716 | } |
| 717 | |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 718 | rc = __cam_req_mgr_check_link_is_ready(link, slot->idx, true, true); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 719 | if (rc) { |
| 720 | CAM_DBG(CAM_CRM, |
| 721 | "Req: %lld [My link]not available link: %x, rc=%d", |
| 722 | req_id, link->link_hdl, rc); |
| 723 | goto failure; |
| 724 | } |
| 725 | |
| 726 | sync_slot_idx = __cam_req_mgr_find_slot_for_req( |
| 727 | sync_link->req.in_q, req_id); |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 728 | |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 729 | if (sync_slot_idx != -1) { |
| 730 | rc = __cam_req_mgr_check_link_is_ready( |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 731 | sync_link, sync_slot_idx, true, false); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 732 | CAM_DBG(CAM_CRM, "sync_slot_idx=%d, status=%d, rc=%d", |
| 733 | sync_slot_idx, |
| 734 | sync_link->req.in_q->slot[sync_slot_idx].status, |
| 735 | rc); |
| 736 | } else { |
| 737 | CAM_DBG(CAM_CRM, "sync_slot_idx=%d, rc=%d", |
| 738 | sync_slot_idx, rc); |
| 739 | } |
| 740 | |
| 741 | if ((sync_slot_idx != -1) && |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 742 | ((sync_link->req.in_q->slot[sync_slot_idx].status == |
| 743 | CRM_SLOT_STATUS_REQ_APPLIED) || (rc == 0))) { |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 744 | rc = __cam_req_mgr_validate_sof_cnt(link, sync_link); |
| 745 | if (rc) { |
| 746 | CAM_DBG(CAM_CRM, |
| 747 | "Req: %lld validate failed: %x", |
| 748 | req_id, sync_link->link_hdl); |
| 749 | goto failure; |
| 750 | } |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 751 | |
| 752 | CAM_DBG(CAM_CRM, |
| 753 | "Req: %lld ready to apply on link: %x [validation successful]", |
| 754 | req_id, link->link_hdl); |
| 755 | /* |
| 756 | * At this point all validation is successfully done |
| 757 | * and we can proceed to apply the given request. |
| 758 | * Ideally the next call should return success. |
| 759 | */ |
| 760 | rc = __cam_req_mgr_check_link_is_ready(link, |
| 761 | slot->idx, false, true); |
| 762 | |
| 763 | if (rc) { |
| 764 | CAM_WARN(CAM_CRM, "Unexpected return value rc: %d", rc); |
| 765 | } |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 766 | } else { |
| 767 | CAM_DBG(CAM_CRM, |
| 768 | "Req: %lld [Other link] not ready to apply on link: %x", |
| 769 | req_id, sync_link->link_hdl); |
| 770 | rc = -EPERM; |
| 771 | goto failure; |
| 772 | } |
| 773 | |
| 774 | return rc; |
| 775 | |
| 776 | failure: |
| 777 | link->sof_counter--; |
| 778 | return rc; |
| 779 | } |
| 780 | |
| 781 | /** |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 782 | * __cam_req_mgr_process_req() |
| 783 | * |
| 784 | * @brief : processes read index in request queue and traverse through table |
| 785 | * @link : pointer to link whose input queue and req tbl are |
| 786 | * traversed through |
| 787 | * |
| 788 | * @return : 0 for success, negative for failure |
| 789 | * |
| 790 | */ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 791 | static int __cam_req_mgr_process_req(struct cam_req_mgr_core_link *link, |
| 792 | uint32_t trigger) |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 793 | { |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 794 | int rc = 0, idx; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 795 | struct cam_req_mgr_slot *slot = NULL; |
| 796 | struct cam_req_mgr_req_queue *in_q; |
| 797 | struct cam_req_mgr_core_session *session; |
| 798 | |
| 799 | in_q = link->req.in_q; |
| 800 | session = (struct cam_req_mgr_core_session *)link->parent; |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 801 | mutex_lock(&session->lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 802 | /* |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 803 | * Check if new read index, |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 804 | * - if in pending state, traverse again to complete |
| 805 | * transaction of this read index. |
| 806 | * - if in applied_state, somthign wrong. |
| 807 | * - if in no_req state, no new req |
| 808 | */ |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 809 | CAM_DBG(CAM_CRM, "SOF Req[%lld] idx %d req_status %d link_hdl %x", |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 810 | in_q->slot[in_q->rd_idx].req_id, in_q->rd_idx, |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 811 | in_q->slot[in_q->rd_idx].status, link->link_hdl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 812 | |
| 813 | slot = &in_q->slot[in_q->rd_idx]; |
| 814 | if (slot->status == CRM_SLOT_STATUS_NO_REQ) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 815 | CAM_DBG(CAM_CRM, "No Pending req"); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 816 | rc = 0; |
| 817 | goto error; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 818 | } |
| 819 | |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 820 | if ((trigger != CAM_TRIGGER_POINT_SOF) && |
| 821 | (trigger != CAM_TRIGGER_POINT_EOF)) |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 822 | goto error; |
| 823 | |
| 824 | if ((trigger == CAM_TRIGGER_POINT_EOF) && |
| 825 | (!(link->trigger_mask & CAM_TRIGGER_POINT_SOF))) { |
| 826 | CAM_DBG(CAM_CRM, "Applying for last SOF fails"); |
| 827 | rc = -EINVAL; |
| 828 | goto error; |
| 829 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 830 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 831 | if (trigger == CAM_TRIGGER_POINT_SOF) { |
Junzhe Zou | 3f77d83 | 2017-08-25 14:55:23 -0700 | [diff] [blame] | 832 | if (link->trigger_mask) { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 833 | CAM_ERR_RATE_LIMIT(CAM_CRM, |
| 834 | "Applying for last EOF fails"); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 835 | rc = -EINVAL; |
| 836 | goto error; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 837 | } |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 838 | |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 839 | if (slot->sync_mode == CAM_REQ_MGR_SYNC_MODE_SYNC) |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 840 | rc = __cam_req_mgr_process_sync_req(link, slot); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 841 | else |
| 842 | rc = __cam_req_mgr_check_link_is_ready(link, |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 843 | slot->idx, false, true); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 844 | |
| 845 | if (rc < 0) { |
| 846 | /* |
| 847 | * If traverse result is not success, then some devices |
| 848 | * are not ready with packet for the asked request id, |
| 849 | * hence try again in next sof |
| 850 | */ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 851 | slot->status = CRM_SLOT_STATUS_REQ_PENDING; |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 852 | spin_lock_bh(&link->link_state_spin_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 853 | if (link->state == CAM_CRM_LINK_STATE_ERR) { |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 854 | /* |
| 855 | * During error recovery all tables should be |
| 856 | * ready, don't expect to enter here. |
| 857 | * @TODO: gracefully handle if recovery fails. |
| 858 | */ |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 859 | CAM_ERR_RATE_LIMIT(CAM_CRM, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 860 | "FATAL recovery cant finish idx %d status %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 861 | in_q->rd_idx, |
| 862 | in_q->slot[in_q->rd_idx].status); |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 863 | rc = -EPERM; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 864 | } |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 865 | spin_unlock_bh(&link->link_state_spin_lock); |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 866 | goto error; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 867 | } |
| 868 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 869 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 870 | rc = __cam_req_mgr_send_req(link, link->req.in_q, trigger); |
| 871 | if (rc < 0) { |
| 872 | /* Apply req failed retry at next sof */ |
| 873 | slot->status = CRM_SLOT_STATUS_REQ_PENDING; |
| 874 | } else { |
| 875 | link->trigger_mask |= trigger; |
| 876 | |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 877 | CAM_DBG(CAM_CRM, "Applied req[%lld] on link[%x] success", |
| 878 | slot->req_id, link->link_hdl); |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 879 | spin_lock_bh(&link->link_state_spin_lock); |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 880 | if (link->state == CAM_CRM_LINK_STATE_ERR) { |
| 881 | CAM_WARN(CAM_CRM, "Err recovery done idx %d", |
| 882 | in_q->rd_idx); |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 883 | link->state = CAM_CRM_LINK_STATE_READY; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 884 | } |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 885 | spin_unlock_bh(&link->link_state_spin_lock); |
| 886 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 887 | if (link->trigger_mask == link->subscribe_event) { |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 888 | slot->status = CRM_SLOT_STATUS_REQ_APPLIED; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 889 | link->trigger_mask = 0; |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 890 | CAM_DBG(CAM_CRM, "req %d is applied on link %x", |
Venkat Chinta | ddbe513 | 2018-01-30 12:00:29 -0800 | [diff] [blame] | 891 | slot->req_id, |
| 892 | link->link_hdl); |
| 893 | idx = in_q->rd_idx; |
| 894 | __cam_req_mgr_dec_idx( |
| 895 | &idx, link->max_delay + 1, |
| 896 | in_q->num_slots); |
| 897 | __cam_req_mgr_reset_req_slot(link, idx); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 898 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 899 | } |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 900 | |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 901 | mutex_unlock(&session->lock); |
| 902 | return rc; |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 903 | error: |
| 904 | mutex_unlock(&session->lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 905 | return rc; |
| 906 | } |
| 907 | |
| 908 | /** |
| 909 | * __cam_req_mgr_add_tbl_to_link() |
| 910 | * |
| 911 | * @brief : Add table to list under link sorted by pd decremeting order |
| 912 | * @l_tbl : list of pipeline delay tables. |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 913 | * @new_tbl : new tbl which will be appended to above list as per its pd value |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 914 | * |
| 915 | */ |
| 916 | static void __cam_req_mgr_add_tbl_to_link(struct cam_req_mgr_req_tbl **l_tbl, |
| 917 | struct cam_req_mgr_req_tbl *new_tbl) |
| 918 | { |
| 919 | struct cam_req_mgr_req_tbl *tbl; |
| 920 | |
| 921 | if (!(*l_tbl) || (*l_tbl)->pd < new_tbl->pd) { |
| 922 | new_tbl->next = *l_tbl; |
| 923 | if (*l_tbl) { |
| 924 | new_tbl->pd_delta = |
| 925 | new_tbl->pd - (*l_tbl)->pd; |
| 926 | } |
| 927 | *l_tbl = new_tbl; |
| 928 | } else { |
| 929 | tbl = *l_tbl; |
| 930 | |
| 931 | /* Reach existing tbl which has less pd value */ |
| 932 | while (tbl->next != NULL && |
| 933 | new_tbl->pd < tbl->next->pd) { |
| 934 | tbl = tbl->next; |
| 935 | } |
| 936 | if (tbl->next != NULL) { |
| 937 | new_tbl->pd_delta = |
| 938 | new_tbl->pd - tbl->next->pd; |
| 939 | } else { |
| 940 | /* This is last table in linked list*/ |
| 941 | new_tbl->pd_delta = 0; |
| 942 | } |
| 943 | new_tbl->next = tbl->next; |
| 944 | tbl->next = new_tbl; |
| 945 | tbl->pd_delta = tbl->pd - new_tbl->pd; |
| 946 | } |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 947 | CAM_DBG(CAM_CRM, "added pd %d tbl to link delta %d", new_tbl->pd, |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 948 | new_tbl->pd_delta); |
| 949 | } |
| 950 | |
| 951 | /** |
| 952 | * __cam_req_mgr_create_pd_tbl() |
| 953 | * |
| 954 | * @brief : Creates new request table for new delay value |
| 955 | * @delay : New pd table allocated will have this delay value |
| 956 | * |
| 957 | * @return : pointer to newly allocated table, NULL for failure |
| 958 | * |
| 959 | */ |
| 960 | static struct cam_req_mgr_req_tbl *__cam_req_mgr_create_pd_tbl(int32_t delay) |
| 961 | { |
| 962 | struct cam_req_mgr_req_tbl *tbl = |
| 963 | kzalloc(sizeof(struct cam_req_mgr_req_tbl), GFP_KERNEL); |
| 964 | if (tbl != NULL) { |
| 965 | tbl->num_slots = MAX_REQ_SLOTS; |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 966 | CAM_DBG(CAM_CRM, "pd= %d slots= %d", delay, tbl->num_slots); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 967 | } |
| 968 | |
| 969 | return tbl; |
| 970 | } |
| 971 | |
| 972 | /** |
| 973 | * __cam_req_mgr_destroy_all_tbl() |
| 974 | * |
| 975 | * @brief : This func will destroy all pipeline delay based req table structs |
| 976 | * @l_tbl : pointer to first table in list and it has max pd . |
| 977 | * |
| 978 | */ |
| 979 | static void __cam_req_mgr_destroy_all_tbl(struct cam_req_mgr_req_tbl **l_tbl) |
| 980 | { |
| 981 | struct cam_req_mgr_req_tbl *tbl = *l_tbl, *temp; |
| 982 | |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 983 | CAM_DBG(CAM_CRM, "*l_tbl %pK", tbl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 984 | while (tbl != NULL) { |
| 985 | temp = tbl->next; |
| 986 | kfree(tbl); |
| 987 | tbl = temp; |
| 988 | } |
| 989 | *l_tbl = NULL; |
| 990 | } |
| 991 | |
| 992 | /** |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 993 | * __cam_req_mgr_setup_in_q() |
| 994 | * |
| 995 | * @brief : Initialize req table data |
| 996 | * @req : request data pointer |
| 997 | * |
| 998 | * @return: 0 for success, negative for failure |
| 999 | * |
| 1000 | */ |
| 1001 | static int __cam_req_mgr_setup_in_q(struct cam_req_mgr_req_data *req) |
| 1002 | { |
| 1003 | int i; |
| 1004 | struct cam_req_mgr_req_queue *in_q = req->in_q; |
| 1005 | |
| 1006 | if (!in_q) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1007 | CAM_ERR(CAM_CRM, "NULL in_q"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1008 | return -EINVAL; |
| 1009 | } |
| 1010 | |
| 1011 | mutex_lock(&req->lock); |
| 1012 | in_q->num_slots = MAX_REQ_SLOTS; |
| 1013 | |
| 1014 | for (i = 0; i < in_q->num_slots; i++) { |
| 1015 | in_q->slot[i].idx = i; |
| 1016 | in_q->slot[i].req_id = -1; |
| 1017 | in_q->slot[i].skip_idx = 0; |
| 1018 | in_q->slot[i].status = CRM_SLOT_STATUS_NO_REQ; |
| 1019 | } |
| 1020 | |
| 1021 | in_q->wr_idx = 0; |
| 1022 | in_q->rd_idx = 0; |
| 1023 | mutex_unlock(&req->lock); |
| 1024 | |
| 1025 | return 0; |
| 1026 | } |
| 1027 | |
| 1028 | /** |
| 1029 | * __cam_req_mgr_reset_req_tbl() |
| 1030 | * |
| 1031 | * @brief : Initialize req table data |
| 1032 | * @req : request queue pointer |
| 1033 | * |
| 1034 | * @return: 0 for success, negative for failure |
| 1035 | * |
| 1036 | */ |
| 1037 | static int __cam_req_mgr_reset_in_q(struct cam_req_mgr_req_data *req) |
| 1038 | { |
| 1039 | struct cam_req_mgr_req_queue *in_q = req->in_q; |
| 1040 | |
| 1041 | if (!in_q) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1042 | CAM_ERR(CAM_CRM, "NULL in_q"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1043 | return -EINVAL; |
| 1044 | } |
| 1045 | |
| 1046 | mutex_lock(&req->lock); |
| 1047 | memset(in_q->slot, 0, |
| 1048 | sizeof(struct cam_req_mgr_slot) * in_q->num_slots); |
| 1049 | in_q->num_slots = 0; |
| 1050 | |
| 1051 | in_q->wr_idx = 0; |
| 1052 | in_q->rd_idx = 0; |
| 1053 | mutex_unlock(&req->lock); |
| 1054 | |
| 1055 | return 0; |
| 1056 | } |
| 1057 | |
| 1058 | /** |
| 1059 | * __cam_req_mgr_sof_freeze() |
| 1060 | * |
| 1061 | * @brief : Apoptosis - Handles case when connected devices are not responding |
| 1062 | * @data : timer pointer |
| 1063 | * |
| 1064 | */ |
| 1065 | static void __cam_req_mgr_sof_freeze(unsigned long data) |
| 1066 | { |
Harsh Shah | 67fa231 | 2017-10-30 04:03:07 -0700 | [diff] [blame] | 1067 | struct cam_req_mgr_timer *timer = (struct cam_req_mgr_timer *)data; |
| 1068 | struct cam_req_mgr_core_link *link = NULL; |
| 1069 | struct cam_req_mgr_core_session *session = NULL; |
| 1070 | struct cam_req_mgr_message msg; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1071 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1072 | if (!timer) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1073 | CAM_ERR(CAM_CRM, "NULL timer"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1074 | return; |
| 1075 | } |
| 1076 | link = (struct cam_req_mgr_core_link *)timer->parent; |
Harsh Shah | 67fa231 | 2017-10-30 04:03:07 -0700 | [diff] [blame] | 1077 | session = (struct cam_req_mgr_core_session *)link->parent; |
| 1078 | |
| 1079 | CAM_ERR(CAM_CRM, "SOF freeze for session %d link 0x%x", |
| 1080 | session->session_hdl, link->link_hdl); |
| 1081 | |
| 1082 | memset(&msg, 0, sizeof(msg)); |
| 1083 | |
| 1084 | msg.session_hdl = session->session_hdl; |
| 1085 | msg.u.err_msg.error_type = CAM_REQ_MGR_ERROR_TYPE_DEVICE; |
| 1086 | msg.u.err_msg.request_id = 0; |
| 1087 | msg.u.err_msg.link_hdl = link->link_hdl; |
| 1088 | |
| 1089 | |
| 1090 | if (cam_req_mgr_notify_message(&msg, |
| 1091 | V4L_EVENT_CAM_REQ_MGR_ERROR, V4L_EVENT_CAM_REQ_MGR_EVENT)) |
| 1092 | CAM_ERR(CAM_CRM, |
| 1093 | "Error notifying SOF freeze for session %d link 0x%x", |
| 1094 | session->session_hdl, link->link_hdl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
| 1097 | /** |
| 1098 | * __cam_req_mgr_create_subdevs() |
| 1099 | * |
| 1100 | * @brief : Create new crm subdev to link with realtime devices |
| 1101 | * @l_dev : list of subdevs internal to crm |
| 1102 | * @num_dev : num of subdevs to be created for link |
| 1103 | * |
| 1104 | * @return : pointer to allocated list of devices |
| 1105 | */ |
| 1106 | static int __cam_req_mgr_create_subdevs( |
| 1107 | struct cam_req_mgr_connected_device **l_dev, int32_t num_dev) |
| 1108 | { |
| 1109 | int rc = 0; |
| 1110 | *l_dev = (struct cam_req_mgr_connected_device *) |
| 1111 | kzalloc(sizeof(struct cam_req_mgr_connected_device) * num_dev, |
| 1112 | GFP_KERNEL); |
| 1113 | if (!*l_dev) |
| 1114 | rc = -ENOMEM; |
| 1115 | |
| 1116 | return rc; |
| 1117 | } |
| 1118 | |
| 1119 | /** |
| 1120 | * __cam_req_mgr_destroy_subdev() |
| 1121 | * |
| 1122 | * @brief : Cleans up the subdevs allocated by crm for link |
| 1123 | * @l_device : pointer to list of subdevs crm created |
| 1124 | * |
| 1125 | */ |
| 1126 | static void __cam_req_mgr_destroy_subdev( |
| 1127 | struct cam_req_mgr_connected_device *l_device) |
| 1128 | { |
| 1129 | kfree(l_device); |
| 1130 | l_device = NULL; |
| 1131 | } |
| 1132 | |
| 1133 | /** |
| 1134 | * __cam_req_mgr_destroy_link_info() |
| 1135 | * |
| 1136 | * @brief : Cleans up the mem allocated while linking |
| 1137 | * @link : pointer to link, mem associated with this link is freed |
| 1138 | * |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 1139 | * @return : returns if unlink for any device was success or failure |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1140 | */ |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 1141 | static int __cam_req_mgr_destroy_link_info(struct cam_req_mgr_core_link *link) |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1142 | { |
| 1143 | int32_t i = 0; |
| 1144 | struct cam_req_mgr_connected_device *dev; |
| 1145 | struct cam_req_mgr_core_dev_link_setup link_data; |
Harsh Shah | a606d18 | 2017-11-10 00:15:58 -0800 | [diff] [blame] | 1146 | int rc = 0; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1147 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1148 | link_data.link_enable = 0; |
| 1149 | link_data.link_hdl = link->link_hdl; |
| 1150 | link_data.crm_cb = NULL; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1151 | link_data.subscribe_event = 0; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1152 | |
| 1153 | /* Using device ops unlink devices */ |
| 1154 | for (i = 0; i < link->num_devs; i++) { |
| 1155 | dev = &link->l_dev[i]; |
| 1156 | if (dev != NULL) { |
Soundrapandian Jeyaprakash | 7494626 | 2017-08-11 18:23:47 -0700 | [diff] [blame] | 1157 | link_data.dev_hdl = dev->dev_hdl; |
Lynus Vaz | 345e6a0 | 2017-12-04 17:02:12 +0530 | [diff] [blame] | 1158 | if (dev->ops && dev->ops->link_setup) { |
Harsh Shah | a606d18 | 2017-11-10 00:15:58 -0800 | [diff] [blame] | 1159 | rc = dev->ops->link_setup(&link_data); |
| 1160 | if (rc) |
| 1161 | CAM_ERR(CAM_CRM, |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 1162 | "Unlink failed dev_hdl %d", |
| 1163 | dev->dev_hdl); |
Lynus Vaz | 345e6a0 | 2017-12-04 17:02:12 +0530 | [diff] [blame] | 1164 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1165 | dev->dev_hdl = 0; |
| 1166 | dev->parent = NULL; |
| 1167 | dev->ops = NULL; |
| 1168 | } |
| 1169 | } |
| 1170 | __cam_req_mgr_destroy_all_tbl(&link->req.l_tbl); |
| 1171 | __cam_req_mgr_reset_in_q(&link->req); |
| 1172 | link->req.num_tbl = 0; |
| 1173 | mutex_destroy(&link->req.lock); |
| 1174 | |
| 1175 | link->pd_mask = 0; |
| 1176 | link->num_devs = 0; |
| 1177 | link->max_delay = 0; |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 1178 | |
| 1179 | return rc; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1180 | } |
| 1181 | |
| 1182 | /** |
| 1183 | * __cam_req_mgr_reserve_link() |
| 1184 | * |
| 1185 | * @brief: Reserves one link data struct within session |
| 1186 | * @session: session identifier |
| 1187 | * |
| 1188 | * @return: pointer to link reserved |
| 1189 | * |
| 1190 | */ |
| 1191 | static struct cam_req_mgr_core_link *__cam_req_mgr_reserve_link( |
| 1192 | struct cam_req_mgr_core_session *session) |
| 1193 | { |
| 1194 | struct cam_req_mgr_core_link *link; |
| 1195 | struct cam_req_mgr_req_queue *in_q; |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 1196 | int i; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1197 | |
| 1198 | if (!session || !g_crm_core_dev) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1199 | CAM_ERR(CAM_CRM, "NULL session/core_dev ptr"); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1200 | return NULL; |
| 1201 | } |
| 1202 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1203 | if (session->num_links >= MAX_LINKS_PER_SESSION) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1204 | CAM_ERR(CAM_CRM, "Reached max links %d per session limit %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1205 | session->num_links, MAX_LINKS_PER_SESSION); |
| 1206 | return NULL; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1207 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1208 | |
| 1209 | link = (struct cam_req_mgr_core_link *) |
| 1210 | kzalloc(sizeof(struct cam_req_mgr_core_link), GFP_KERNEL); |
| 1211 | if (!link) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1212 | CAM_ERR(CAM_CRM, "failed to create link, no mem"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1213 | return NULL; |
| 1214 | } |
Sagar Gore | d46e67d | 2017-08-31 17:05:46 -0700 | [diff] [blame] | 1215 | in_q = (struct cam_req_mgr_req_queue *) |
| 1216 | kzalloc(sizeof(struct cam_req_mgr_req_queue), GFP_KERNEL); |
| 1217 | if (!in_q) { |
| 1218 | CAM_ERR(CAM_CRM, "failed to create input queue, no mem"); |
| 1219 | kfree(link); |
| 1220 | return NULL; |
| 1221 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1222 | mutex_init(&link->lock); |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1223 | spin_lock_init(&link->link_state_spin_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1224 | |
| 1225 | mutex_lock(&link->lock); |
| 1226 | link->state = CAM_CRM_LINK_STATE_AVAILABLE; |
| 1227 | link->num_devs = 0; |
| 1228 | link->max_delay = 0; |
| 1229 | memset(in_q->slot, 0, |
| 1230 | sizeof(struct cam_req_mgr_slot) * MAX_REQ_SLOTS); |
| 1231 | link->req.in_q = in_q; |
| 1232 | in_q->num_slots = 0; |
| 1233 | link->state = CAM_CRM_LINK_STATE_IDLE; |
| 1234 | link->parent = (void *)session; |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 1235 | link->sync_link = NULL; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1236 | mutex_unlock(&link->lock); |
| 1237 | |
| 1238 | mutex_lock(&session->lock); |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 1239 | /* Loop through and find a free index */ |
| 1240 | for (i = 0; i < MAX_LINKS_PER_SESSION; i++) { |
| 1241 | if (!session->links[i]) { |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 1242 | CAM_DBG(CAM_CRM, |
| 1243 | "Free link index %d found, num_links=%d", |
| 1244 | i, session->num_links); |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 1245 | session->links[i] = link; |
| 1246 | break; |
| 1247 | } |
| 1248 | } |
| 1249 | |
| 1250 | if (i == MAX_LINKS_PER_SESSION) { |
| 1251 | CAM_ERR(CAM_CRM, "Free link index not found"); |
| 1252 | goto error; |
| 1253 | } |
| 1254 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1255 | session->num_links++; |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1256 | CAM_DBG(CAM_CRM, "Active session links (%d)", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1257 | session->num_links); |
| 1258 | mutex_unlock(&session->lock); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1259 | |
| 1260 | return link; |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 1261 | error: |
| 1262 | mutex_unlock(&session->lock); |
| 1263 | kfree(link); |
| 1264 | kfree(in_q); |
| 1265 | return NULL; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1266 | } |
| 1267 | |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 1268 | /* |
| 1269 | * __cam_req_mgr_free_link() |
| 1270 | * |
| 1271 | * @brief: Frees the link and its request queue |
| 1272 | * |
| 1273 | * @link: link identifier |
| 1274 | * |
| 1275 | */ |
| 1276 | static void __cam_req_mgr_free_link(struct cam_req_mgr_core_link *link) |
| 1277 | { |
| 1278 | kfree(link->req.in_q); |
| 1279 | link->req.in_q = NULL; |
| 1280 | kfree(link); |
| 1281 | } |
| 1282 | |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1283 | /** |
Sagar Gore | d46e67d | 2017-08-31 17:05:46 -0700 | [diff] [blame] | 1284 | * __cam_req_mgr_unreserve_link() |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1285 | * |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 1286 | * @brief : Removes the link data struct from the session and frees it |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1287 | * @session: session identifier |
| 1288 | * @link : link identifier |
| 1289 | * |
| 1290 | */ |
| 1291 | static void __cam_req_mgr_unreserve_link( |
| 1292 | struct cam_req_mgr_core_session *session, |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 1293 | struct cam_req_mgr_core_link *link) |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1294 | { |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 1295 | int i; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1296 | |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 1297 | if (!session || !link) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1298 | CAM_ERR(CAM_CRM, "NULL session/link ptr %pK %pK", |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 1299 | session, link); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1300 | return; |
| 1301 | } |
| 1302 | |
| 1303 | mutex_lock(&session->lock); |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 1304 | if (!session->num_links) { |
| 1305 | CAM_WARN(CAM_CRM, "No active link or invalid state: hdl %x", |
| 1306 | link->link_hdl); |
| 1307 | mutex_unlock(&session->lock); |
| 1308 | return; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1309 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1310 | |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 1311 | for (i = 0; i < MAX_LINKS_PER_SESSION; i++) { |
| 1312 | if (session->links[i] == link) |
| 1313 | session->links[i] = NULL; |
| 1314 | } |
| 1315 | |
| 1316 | if ((session->sync_mode != CAM_REQ_MGR_SYNC_MODE_NO_SYNC) && |
| 1317 | (link->sync_link)) { |
| 1318 | /* |
| 1319 | * make sure to unlink sync setup under the assumption |
| 1320 | * of only having 2 links in a given session |
| 1321 | */ |
| 1322 | session->sync_mode = CAM_REQ_MGR_SYNC_MODE_NO_SYNC; |
| 1323 | for (i = 0; i < MAX_LINKS_PER_SESSION; i++) { |
| 1324 | if (session->links[i]) |
| 1325 | session->links[i]->sync_link = NULL; |
| 1326 | } |
| 1327 | } |
| 1328 | |
| 1329 | session->num_links--; |
| 1330 | CAM_DBG(CAM_CRM, "Active session links (%d)", session->num_links); |
| 1331 | mutex_unlock(&session->lock); |
| 1332 | __cam_req_mgr_free_link(link); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1333 | } |
| 1334 | |
| 1335 | /* Workqueue context processing section */ |
| 1336 | |
| 1337 | /** |
| 1338 | * cam_req_mgr_process_send_req() |
| 1339 | * |
| 1340 | * @brief: This runs in workque thread context. Call core funcs to send |
| 1341 | * apply request id to drivers. |
| 1342 | * @priv : link information. |
| 1343 | * @data : contains information about frame_id, link etc. |
| 1344 | * |
| 1345 | * @return: 0 on success. |
| 1346 | */ |
| 1347 | int cam_req_mgr_process_send_req(void *priv, void *data) |
| 1348 | { |
| 1349 | int rc = 0; |
| 1350 | struct cam_req_mgr_core_link *link = NULL; |
| 1351 | struct cam_req_mgr_send_request *send_req = NULL; |
| 1352 | struct cam_req_mgr_req_queue *in_q = NULL; |
| 1353 | |
| 1354 | if (!data || !priv) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1355 | CAM_ERR(CAM_CRM, "input args NULL %pK %pK", data, priv); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1356 | rc = -EINVAL; |
| 1357 | goto end; |
| 1358 | } |
| 1359 | link = (struct cam_req_mgr_core_link *)priv; |
| 1360 | send_req = (struct cam_req_mgr_send_request *)data; |
| 1361 | in_q = send_req->in_q; |
| 1362 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1363 | rc = __cam_req_mgr_send_req(link, in_q, CAM_TRIGGER_POINT_SOF); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1364 | end: |
| 1365 | return rc; |
| 1366 | } |
| 1367 | |
| 1368 | /** |
| 1369 | * cam_req_mgr_process_flush_req() |
| 1370 | * |
| 1371 | * @brief: This runs in workque thread context. Call core funcs to check |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1372 | * which requests need to be removed/cancelled. |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1373 | * @priv : link information. |
| 1374 | * @data : contains information about frame_id, link etc. |
| 1375 | * |
| 1376 | * @return: 0 on success. |
| 1377 | */ |
| 1378 | int cam_req_mgr_process_flush_req(void *priv, void *data) |
| 1379 | { |
| 1380 | int rc = 0, i = 0, idx = -1; |
| 1381 | struct cam_req_mgr_flush_info *flush_info = NULL; |
| 1382 | struct cam_req_mgr_core_link *link = NULL; |
| 1383 | struct cam_req_mgr_req_queue *in_q = NULL; |
| 1384 | struct cam_req_mgr_slot *slot = NULL; |
| 1385 | struct cam_req_mgr_connected_device *device = NULL; |
| 1386 | struct cam_req_mgr_flush_request flush_req; |
| 1387 | struct crm_task_payload *task_data = NULL; |
| 1388 | |
| 1389 | if (!data || !priv) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1390 | CAM_ERR(CAM_CRM, "input args NULL %pK %pK", data, priv); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1391 | rc = -EINVAL; |
| 1392 | goto end; |
| 1393 | } |
| 1394 | link = (struct cam_req_mgr_core_link *)priv; |
| 1395 | task_data = (struct crm_task_payload *)data; |
| 1396 | flush_info = (struct cam_req_mgr_flush_info *)&task_data->u; |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1397 | CAM_DBG(CAM_CRM, "link_hdl %x req_id %lld type %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1398 | flush_info->link_hdl, |
| 1399 | flush_info->req_id, |
| 1400 | flush_info->flush_type); |
| 1401 | |
| 1402 | in_q = link->req.in_q; |
| 1403 | |
Gregory Bergschneider | 6067993 | 2017-07-19 15:27:16 -0600 | [diff] [blame] | 1404 | trace_cam_flush_req(link, flush_info); |
Gregory Bergschneider | 5164f3a | 2017-07-07 10:26:17 -0600 | [diff] [blame] | 1405 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1406 | mutex_lock(&link->req.lock); |
| 1407 | if (flush_info->flush_type == CAM_REQ_MGR_FLUSH_TYPE_ALL) { |
| 1408 | for (i = 0; i < in_q->num_slots; i++) { |
| 1409 | slot = &in_q->slot[i]; |
| 1410 | slot->req_id = -1; |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 1411 | slot->sync_mode = CAM_REQ_MGR_SYNC_MODE_NO_SYNC; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1412 | slot->skip_idx = 1; |
| 1413 | slot->status = CRM_SLOT_STATUS_NO_REQ; |
| 1414 | } |
| 1415 | in_q->wr_idx = 0; |
| 1416 | in_q->rd_idx = 0; |
| 1417 | } else if (flush_info->flush_type == |
| 1418 | CAM_REQ_MGR_FLUSH_TYPE_CANCEL_REQ) { |
| 1419 | idx = __cam_req_mgr_find_slot_for_req(in_q, flush_info->req_id); |
| 1420 | if (idx < 0) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1421 | CAM_ERR(CAM_CRM, "req_id %lld not found in input queue", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1422 | flush_info->req_id); |
| 1423 | } else { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1424 | CAM_DBG(CAM_CRM, "req_id %lld found at idx %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1425 | flush_info->req_id, idx); |
| 1426 | slot = &in_q->slot[idx]; |
| 1427 | if (slot->status == CRM_SLOT_STATUS_REQ_PENDING || |
| 1428 | slot->status == CRM_SLOT_STATUS_REQ_APPLIED) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1429 | CAM_WARN(CAM_CRM, |
| 1430 | "req_id %lld can not be cancelled", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1431 | flush_info->req_id); |
| 1432 | mutex_unlock(&link->req.lock); |
| 1433 | return -EINVAL; |
| 1434 | } |
| 1435 | __cam_req_mgr_in_q_skip_idx(in_q, idx); |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | for (i = 0; i < link->num_devs; i++) { |
| 1440 | device = &link->l_dev[i]; |
| 1441 | flush_req.link_hdl = flush_info->link_hdl; |
| 1442 | flush_req.dev_hdl = device->dev_hdl; |
| 1443 | flush_req.req_id = flush_info->req_id; |
| 1444 | flush_req.type = flush_info->flush_type; |
| 1445 | /* @TODO: error return handling from drivers */ |
| 1446 | if (device->ops && device->ops->flush_req) |
| 1447 | rc = device->ops->flush_req(&flush_req); |
| 1448 | } |
Alok Pandey | a6bde9e | 2018-02-02 10:14:19 +0530 | [diff] [blame] | 1449 | complete(&link->workq_comp); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1450 | mutex_unlock(&link->req.lock); |
| 1451 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1452 | end: |
| 1453 | return rc; |
| 1454 | } |
| 1455 | |
| 1456 | /** |
| 1457 | * cam_req_mgr_process_sched_req() |
| 1458 | * |
| 1459 | * @brief: This runs in workque thread context. Call core funcs to check |
| 1460 | * which peding requests can be processed. |
| 1461 | * @priv : link information. |
| 1462 | * @data : contains information about frame_id, link etc. |
| 1463 | * |
| 1464 | * @return: 0 on success. |
| 1465 | */ |
| 1466 | int cam_req_mgr_process_sched_req(void *priv, void *data) |
| 1467 | { |
| 1468 | int rc = 0; |
| 1469 | struct cam_req_mgr_sched_request *sched_req = NULL; |
| 1470 | struct cam_req_mgr_core_link *link = NULL; |
| 1471 | struct cam_req_mgr_req_queue *in_q = NULL; |
| 1472 | struct cam_req_mgr_slot *slot = NULL; |
| 1473 | struct crm_task_payload *task_data = NULL; |
| 1474 | |
| 1475 | if (!data || !priv) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1476 | CAM_ERR(CAM_CRM, "input args NULL %pK %pK", data, priv); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1477 | rc = -EINVAL; |
| 1478 | goto end; |
| 1479 | } |
| 1480 | link = (struct cam_req_mgr_core_link *)priv; |
| 1481 | task_data = (struct crm_task_payload *)data; |
| 1482 | sched_req = (struct cam_req_mgr_sched_request *)&task_data->u; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1483 | in_q = link->req.in_q; |
| 1484 | |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 1485 | CAM_DBG(CAM_CRM, "link_hdl %x req_id %lld at slot %d sync_mode %d", |
| 1486 | sched_req->link_hdl, sched_req->req_id, |
| 1487 | in_q->wr_idx, sched_req->sync_mode); |
| 1488 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1489 | mutex_lock(&link->req.lock); |
| 1490 | slot = &in_q->slot[in_q->wr_idx]; |
| 1491 | |
| 1492 | if (slot->status != CRM_SLOT_STATUS_NO_REQ && |
Sagar Gore | b56c81e | 2017-05-08 17:15:47 -0700 | [diff] [blame] | 1493 | slot->status != CRM_SLOT_STATUS_REQ_APPLIED) |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1494 | CAM_WARN(CAM_CRM, "in_q overwrite %d", slot->status); |
Sagar Gore | b56c81e | 2017-05-08 17:15:47 -0700 | [diff] [blame] | 1495 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1496 | slot->status = CRM_SLOT_STATUS_REQ_ADDED; |
| 1497 | slot->req_id = sched_req->req_id; |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 1498 | slot->sync_mode = sched_req->sync_mode; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1499 | slot->skip_idx = 0; |
| 1500 | slot->recover = sched_req->bubble_enable; |
| 1501 | __cam_req_mgr_inc_idx(&in_q->wr_idx, 1, in_q->num_slots); |
| 1502 | mutex_unlock(&link->req.lock); |
| 1503 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1504 | end: |
| 1505 | return rc; |
| 1506 | } |
| 1507 | |
| 1508 | /** |
| 1509 | * cam_req_mgr_process_add_req() |
| 1510 | * |
| 1511 | * @brief: This runs in workque thread context. Call core funcs to check |
| 1512 | * which peding requests can be processed. |
| 1513 | * @priv : link information. |
| 1514 | * @data : contains information about frame_id, link etc. |
| 1515 | * |
| 1516 | * @return: 0 on success. |
| 1517 | */ |
| 1518 | int cam_req_mgr_process_add_req(void *priv, void *data) |
| 1519 | { |
| 1520 | int rc = 0, i = 0, idx; |
| 1521 | struct cam_req_mgr_add_request *add_req = NULL; |
| 1522 | struct cam_req_mgr_core_link *link = NULL; |
| 1523 | struct cam_req_mgr_connected_device *device = NULL; |
| 1524 | struct cam_req_mgr_req_tbl *tbl = NULL; |
| 1525 | struct cam_req_mgr_tbl_slot *slot = NULL; |
| 1526 | struct crm_task_payload *task_data = NULL; |
| 1527 | |
| 1528 | if (!data || !priv) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1529 | CAM_ERR(CAM_CRM, "input args NULL %pK %pK", data, priv); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1530 | rc = -EINVAL; |
| 1531 | goto end; |
| 1532 | } |
| 1533 | |
| 1534 | link = (struct cam_req_mgr_core_link *)priv; |
| 1535 | task_data = (struct crm_task_payload *)data; |
| 1536 | add_req = (struct cam_req_mgr_add_request *)&task_data->u; |
| 1537 | |
| 1538 | for (i = 0; i < link->num_devs; i++) { |
| 1539 | device = &link->l_dev[i]; |
| 1540 | if (device->dev_hdl == add_req->dev_hdl) { |
| 1541 | tbl = device->pd_tbl; |
| 1542 | break; |
| 1543 | } |
| 1544 | } |
| 1545 | if (!tbl) { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 1546 | CAM_ERR_RATE_LIMIT(CAM_CRM, "dev_hdl not found %x, %x %x", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1547 | add_req->dev_hdl, |
| 1548 | link->l_dev[0].dev_hdl, |
| 1549 | link->l_dev[1].dev_hdl); |
| 1550 | rc = -EINVAL; |
| 1551 | goto end; |
| 1552 | } |
| 1553 | /* |
| 1554 | * Go through request table and add |
| 1555 | * request id to proper table |
| 1556 | * 1. find req slot in in_q matching req_id.sent by dev |
| 1557 | * 2. goto table of this device based on p_delay |
| 1558 | * 3. mark req_ready_map with this dev_bit. |
| 1559 | */ |
| 1560 | |
| 1561 | mutex_lock(&link->req.lock); |
| 1562 | idx = __cam_req_mgr_find_slot_for_req(link->req.in_q, add_req->req_id); |
| 1563 | if (idx < 0) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1564 | CAM_ERR(CAM_CRM, "req %lld not found in in_q", add_req->req_id); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1565 | rc = -EBADSLT; |
| 1566 | mutex_unlock(&link->req.lock); |
| 1567 | goto end; |
| 1568 | } |
Sagar Gore | a4d7dfd | 2017-09-13 19:56:24 -0700 | [diff] [blame] | 1569 | |
| 1570 | if (add_req->skip_before_applying > tbl->inject_delay) |
| 1571 | tbl->inject_delay = add_req->skip_before_applying; |
| 1572 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1573 | slot = &tbl->slot[idx]; |
| 1574 | if (slot->state != CRM_REQ_STATE_PENDING && |
| 1575 | slot->state != CRM_REQ_STATE_EMPTY) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1576 | CAM_WARN(CAM_CRM, "Unexpected state %d for slot %d map %x", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1577 | slot->state, idx, slot->req_ready_map); |
| 1578 | } |
| 1579 | |
| 1580 | slot->state = CRM_REQ_STATE_PENDING; |
| 1581 | slot->req_ready_map |= (1 << device->dev_bit); |
| 1582 | |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1583 | CAM_DBG(CAM_CRM, "idx %d dev_hdl %x req_id %lld pd %d ready_map %x", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1584 | idx, add_req->dev_hdl, add_req->req_id, tbl->pd, |
| 1585 | slot->req_ready_map); |
| 1586 | |
Gregory Bergschneider | 6067993 | 2017-07-19 15:27:16 -0600 | [diff] [blame] | 1587 | trace_cam_req_mgr_add_req(link, idx, add_req, tbl, device); |
| 1588 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1589 | if (slot->req_ready_map == tbl->dev_mask) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1590 | CAM_DBG(CAM_CRM, "idx %d req_id %lld pd %d SLOT READY", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1591 | idx, add_req->req_id, tbl->pd); |
| 1592 | slot->state = CRM_REQ_STATE_READY; |
| 1593 | } |
| 1594 | mutex_unlock(&link->req.lock); |
| 1595 | |
| 1596 | end: |
| 1597 | return rc; |
| 1598 | } |
| 1599 | |
| 1600 | /** |
| 1601 | * cam_req_mgr_process_error() |
| 1602 | * |
| 1603 | * @brief: This runs in workque thread context. bubble /err recovery. |
| 1604 | * @priv : link information. |
| 1605 | * @data : contains information about frame_id, link etc. |
| 1606 | * |
| 1607 | * @return: 0 on success. |
| 1608 | */ |
| 1609 | int cam_req_mgr_process_error(void *priv, void *data) |
| 1610 | { |
| 1611 | int rc = 0, idx = -1, i; |
| 1612 | struct cam_req_mgr_error_notify *err_info = NULL; |
| 1613 | struct cam_req_mgr_core_link *link = NULL; |
| 1614 | struct cam_req_mgr_req_queue *in_q = NULL; |
| 1615 | struct cam_req_mgr_slot *slot = NULL; |
| 1616 | struct cam_req_mgr_connected_device *device = NULL; |
| 1617 | struct cam_req_mgr_link_evt_data evt_data; |
| 1618 | struct crm_task_payload *task_data = NULL; |
| 1619 | |
| 1620 | if (!data || !priv) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1621 | CAM_ERR(CAM_CRM, "input args NULL %pK %pK", data, priv); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1622 | rc = -EINVAL; |
| 1623 | goto end; |
| 1624 | } |
| 1625 | link = (struct cam_req_mgr_core_link *)priv; |
| 1626 | task_data = (struct crm_task_payload *)data; |
| 1627 | err_info = (struct cam_req_mgr_error_notify *)&task_data->u; |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1628 | CAM_DBG(CAM_CRM, "link_hdl %x req_id %lld error %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1629 | err_info->link_hdl, |
| 1630 | err_info->req_id, |
| 1631 | err_info->error); |
| 1632 | |
| 1633 | in_q = link->req.in_q; |
| 1634 | |
| 1635 | mutex_lock(&link->req.lock); |
| 1636 | if (err_info->error == CRM_KMD_ERR_BUBBLE) { |
| 1637 | idx = __cam_req_mgr_find_slot_for_req(in_q, err_info->req_id); |
| 1638 | if (idx < 0) { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 1639 | CAM_ERR_RATE_LIMIT(CAM_CRM, |
| 1640 | "req_id %lld not found in input queue", |
| 1641 | err_info->req_id); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1642 | } else { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1643 | CAM_DBG(CAM_CRM, "req_id %lld found at idx %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1644 | err_info->req_id, idx); |
| 1645 | slot = &in_q->slot[idx]; |
| 1646 | if (!slot->recover) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1647 | CAM_WARN(CAM_CRM, |
| 1648 | "err recovery disabled req_id %lld", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1649 | err_info->req_id); |
| 1650 | mutex_unlock(&link->req.lock); |
| 1651 | return 0; |
| 1652 | } else if (slot->status != CRM_SLOT_STATUS_REQ_PENDING |
| 1653 | && slot->status != CRM_SLOT_STATUS_REQ_APPLIED) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1654 | CAM_WARN(CAM_CRM, |
| 1655 | "req_id %lld can not be recovered %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1656 | err_info->req_id, slot->status); |
| 1657 | mutex_unlock(&link->req.lock); |
| 1658 | return -EINVAL; |
| 1659 | } |
| 1660 | /* Notify all devices in the link about error */ |
| 1661 | for (i = 0; i < link->num_devs; i++) { |
| 1662 | device = &link->l_dev[i]; |
| 1663 | if (device != NULL) { |
| 1664 | evt_data.dev_hdl = device->dev_hdl; |
| 1665 | evt_data.evt_type = |
| 1666 | CAM_REQ_MGR_LINK_EVT_ERR; |
| 1667 | evt_data.link_hdl = link->link_hdl; |
| 1668 | evt_data.req_id = err_info->req_id; |
| 1669 | evt_data.u.error = err_info->error; |
| 1670 | if (device->ops && |
| 1671 | device->ops->process_evt) |
| 1672 | rc = device->ops-> |
| 1673 | process_evt(&evt_data); |
| 1674 | } |
| 1675 | } |
| 1676 | /* Bring processing pointer to bubbled req id */ |
| 1677 | __cam_req_mgr_tbl_set_all_skip_cnt(&link->req.l_tbl); |
| 1678 | in_q->rd_idx = idx; |
| 1679 | in_q->slot[idx].status = CRM_SLOT_STATUS_REQ_ADDED; |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1680 | spin_lock_bh(&link->link_state_spin_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1681 | link->state = CAM_CRM_LINK_STATE_ERR; |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1682 | spin_unlock_bh(&link->link_state_spin_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1683 | } |
| 1684 | } |
| 1685 | mutex_unlock(&link->req.lock); |
| 1686 | |
| 1687 | end: |
| 1688 | return rc; |
| 1689 | } |
| 1690 | |
| 1691 | /** |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1692 | * cam_req_mgr_process_trigger() |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1693 | * |
| 1694 | * @brief: This runs in workque thread context. Call core funcs to check |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1695 | * which peding requests can be processed. |
| 1696 | * @priv : link information. |
| 1697 | * @data : contains information about frame_id, link etc. |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1698 | * |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1699 | * @return: 0 on success. |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1700 | */ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1701 | static int cam_req_mgr_process_trigger(void *priv, void *data) |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1702 | { |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1703 | int rc = 0; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1704 | struct cam_req_mgr_trigger_notify *trigger_data = NULL; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1705 | struct cam_req_mgr_core_link *link = NULL; |
| 1706 | struct cam_req_mgr_req_queue *in_q = NULL; |
| 1707 | struct crm_task_payload *task_data = NULL; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1708 | |
| 1709 | if (!data || !priv) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1710 | CAM_ERR(CAM_CRM, "input args NULL %pK %pK", data, priv); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1711 | rc = -EINVAL; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1712 | goto end; |
| 1713 | } |
| 1714 | link = (struct cam_req_mgr_core_link *)priv; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1715 | task_data = (struct crm_task_payload *)data; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1716 | trigger_data = (struct cam_req_mgr_trigger_notify *)&task_data->u; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1717 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1718 | CAM_DBG(CAM_CRM, "link_hdl %x frame_id %lld, trigger %x\n", |
| 1719 | trigger_data->link_hdl, |
| 1720 | trigger_data->frame_id, |
| 1721 | trigger_data->trigger); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1722 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1723 | in_q = link->req.in_q; |
| 1724 | |
| 1725 | mutex_lock(&link->req.lock); |
| 1726 | /* |
| 1727 | * Check if current read index is in applied state, if yes make it free |
| 1728 | * and increment read index to next slot. |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1729 | */ |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1730 | CAM_DBG(CAM_CRM, "link_hdl %x curent idx %d req_status %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1731 | link->link_hdl, in_q->rd_idx, in_q->slot[in_q->rd_idx].status); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1732 | |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1733 | spin_lock_bh(&link->link_state_spin_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1734 | if (link->state == CAM_CRM_LINK_STATE_ERR) |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1735 | CAM_WARN(CAM_CRM, "Error recovery idx %d status %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1736 | in_q->rd_idx, |
| 1737 | in_q->slot[in_q->rd_idx].status); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1738 | |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1739 | spin_unlock_bh(&link->link_state_spin_lock); |
| 1740 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1741 | if (in_q->slot[in_q->rd_idx].status == CRM_SLOT_STATUS_REQ_APPLIED) { |
| 1742 | /* |
| 1743 | * Do NOT reset req q slot data here, it can not be done |
| 1744 | * here because we need to preserve the data to handle bubble. |
Junzhe Zou | 2b34222 | 2017-08-28 18:15:54 -0700 | [diff] [blame] | 1745 | * |
| 1746 | * Check if any new req is pending in slot, if not finish the |
| 1747 | * lower pipeline delay device with available req ids. |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1748 | */ |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 1749 | CAM_DBG(CAM_CRM, "link[%x] Req[%lld] invalidating slot", |
| 1750 | link->link_hdl, in_q->slot[in_q->rd_idx].req_id); |
Junzhe Zou | 2b34222 | 2017-08-28 18:15:54 -0700 | [diff] [blame] | 1751 | __cam_req_mgr_check_next_req_slot(in_q); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1752 | __cam_req_mgr_inc_idx(&in_q->rd_idx, 1, in_q->num_slots); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1753 | } |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1754 | rc = __cam_req_mgr_process_req(link, trigger_data->trigger); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1755 | mutex_unlock(&link->req.lock); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1756 | |
| 1757 | end: |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1758 | return rc; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1759 | } |
| 1760 | |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1761 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1762 | /* Linked devices' Callback section */ |
| 1763 | |
| 1764 | /** |
| 1765 | * cam_req_mgr_cb_add_req() |
| 1766 | * |
| 1767 | * @brief : Drivers call this function to notify new packet is available. |
| 1768 | * @add_req : Information about new request available at a device. |
| 1769 | * |
| 1770 | * @return : 0 on success, negative in case of failure |
| 1771 | * |
| 1772 | */ |
| 1773 | static int cam_req_mgr_cb_add_req(struct cam_req_mgr_add_request *add_req) |
| 1774 | { |
| 1775 | int rc = 0, idx; |
| 1776 | struct crm_workq_task *task = NULL; |
| 1777 | struct cam_req_mgr_core_link *link = NULL; |
| 1778 | struct cam_req_mgr_add_request *dev_req; |
| 1779 | struct crm_task_payload *task_data; |
| 1780 | |
| 1781 | if (!add_req) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1782 | CAM_ERR(CAM_CRM, "sof_data is NULL"); |
Suresh Vankadara | 10a8e49 | 2017-11-09 01:11:31 +0530 | [diff] [blame] | 1783 | return -EINVAL; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1784 | } |
| 1785 | |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1786 | CAM_DBG(CAM_CRM, "E: dev %x dev req %lld", |
| 1787 | add_req->dev_hdl, add_req->req_id); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1788 | link = (struct cam_req_mgr_core_link *) |
| 1789 | cam_get_device_priv(add_req->link_hdl); |
| 1790 | |
| 1791 | if (!link) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1792 | CAM_DBG(CAM_CRM, "link ptr NULL %x", add_req->link_hdl); |
Suresh Vankadara | 10a8e49 | 2017-11-09 01:11:31 +0530 | [diff] [blame] | 1793 | return -EINVAL; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1794 | } |
| 1795 | |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1796 | mutex_lock(&link->lock); |
| 1797 | spin_lock_bh(&link->link_state_spin_lock); |
| 1798 | if (link->state != CAM_CRM_LINK_STATE_READY) { |
| 1799 | CAM_WARN(CAM_CRM, "invalid link state:%d", link->state); |
| 1800 | rc = -EPERM; |
| 1801 | spin_unlock_bh(&link->link_state_spin_lock); |
| 1802 | goto end; |
| 1803 | } |
| 1804 | spin_unlock_bh(&link->link_state_spin_lock); |
| 1805 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1806 | /* Validate if req id is present in input queue */ |
| 1807 | idx = __cam_req_mgr_find_slot_for_req(link->req.in_q, add_req->req_id); |
| 1808 | if (idx < 0) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1809 | CAM_ERR(CAM_CRM, "req %lld not found in in_q", add_req->req_id); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1810 | rc = -ENOENT; |
| 1811 | goto end; |
| 1812 | } |
| 1813 | |
| 1814 | task = cam_req_mgr_workq_get_task(link->workq); |
| 1815 | if (!task) { |
Harsh Shah | cb0072c | 2017-09-26 19:22:10 -0700 | [diff] [blame] | 1816 | CAM_ERR_RATE_LIMIT(CAM_CRM, "no empty task dev %x req %lld", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1817 | add_req->dev_hdl, add_req->req_id); |
| 1818 | rc = -EBUSY; |
| 1819 | goto end; |
| 1820 | } |
| 1821 | |
| 1822 | task_data = (struct crm_task_payload *)task->payload; |
| 1823 | task_data->type = CRM_WORKQ_TASK_DEV_ADD_REQ; |
| 1824 | dev_req = (struct cam_req_mgr_add_request *)&task_data->u; |
| 1825 | dev_req->req_id = add_req->req_id; |
| 1826 | dev_req->link_hdl = add_req->link_hdl; |
| 1827 | dev_req->dev_hdl = add_req->dev_hdl; |
Sagar Gore | a4d7dfd | 2017-09-13 19:56:24 -0700 | [diff] [blame] | 1828 | dev_req->skip_before_applying = add_req->skip_before_applying; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1829 | task->process_cb = &cam_req_mgr_process_add_req; |
| 1830 | rc = cam_req_mgr_workq_enqueue_task(task, link, CRM_TASK_PRIORITY_0); |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1831 | CAM_DBG(CAM_CRM, "X: dev %x dev req %lld", |
| 1832 | add_req->dev_hdl, add_req->req_id); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1833 | |
| 1834 | end: |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1835 | mutex_unlock(&link->lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1836 | return rc; |
| 1837 | } |
| 1838 | |
| 1839 | /** |
| 1840 | * cam_req_mgr_cb_notify_err() |
| 1841 | * |
| 1842 | * @brief : Error received from device, sends bubble recovery |
| 1843 | * @err_info : contains information about error occurred like bubble/overflow |
| 1844 | * |
| 1845 | * @return : 0 on success, negative in case of failure |
| 1846 | * |
| 1847 | */ |
| 1848 | static int cam_req_mgr_cb_notify_err( |
| 1849 | struct cam_req_mgr_error_notify *err_info) |
| 1850 | { |
| 1851 | int rc = 0; |
| 1852 | struct crm_workq_task *task = NULL; |
| 1853 | struct cam_req_mgr_core_link *link = NULL; |
| 1854 | struct cam_req_mgr_error_notify *notify_err; |
| 1855 | struct crm_task_payload *task_data; |
| 1856 | |
| 1857 | if (!err_info) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1858 | CAM_ERR(CAM_CRM, "err_info is NULL"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1859 | rc = -EINVAL; |
| 1860 | goto end; |
| 1861 | } |
| 1862 | |
| 1863 | link = (struct cam_req_mgr_core_link *) |
| 1864 | cam_get_device_priv(err_info->link_hdl); |
| 1865 | if (!link) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1866 | CAM_DBG(CAM_CRM, "link ptr NULL %x", err_info->link_hdl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1867 | rc = -EINVAL; |
| 1868 | goto end; |
| 1869 | } |
| 1870 | |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1871 | spin_lock_bh(&link->link_state_spin_lock); |
| 1872 | if (link->state != CAM_CRM_LINK_STATE_READY) { |
| 1873 | CAM_WARN(CAM_CRM, "invalid link state:%d", link->state); |
| 1874 | spin_unlock_bh(&link->link_state_spin_lock); |
| 1875 | rc = -EPERM; |
| 1876 | goto end; |
| 1877 | } |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 1878 | crm_timer_reset(link->watchdog); |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1879 | spin_unlock_bh(&link->link_state_spin_lock); |
| 1880 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1881 | task = cam_req_mgr_workq_get_task(link->workq); |
| 1882 | if (!task) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1883 | CAM_ERR(CAM_CRM, "no empty task req_id %lld", err_info->req_id); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1884 | rc = -EBUSY; |
| 1885 | goto end; |
| 1886 | } |
| 1887 | |
| 1888 | task_data = (struct crm_task_payload *)task->payload; |
| 1889 | task_data->type = CRM_WORKQ_TASK_NOTIFY_ERR; |
| 1890 | notify_err = (struct cam_req_mgr_error_notify *)&task_data->u; |
| 1891 | notify_err->req_id = err_info->req_id; |
| 1892 | notify_err->link_hdl = err_info->link_hdl; |
| 1893 | notify_err->dev_hdl = err_info->dev_hdl; |
| 1894 | notify_err->error = err_info->error; |
| 1895 | task->process_cb = &cam_req_mgr_process_error; |
| 1896 | rc = cam_req_mgr_workq_enqueue_task(task, link, CRM_TASK_PRIORITY_0); |
| 1897 | |
| 1898 | end: |
| 1899 | return rc; |
| 1900 | } |
| 1901 | |
| 1902 | /** |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1903 | * cam_req_mgr_cb_notify_trigger() |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1904 | * |
| 1905 | * @brief : SOF received from device, sends trigger through workqueue |
| 1906 | * @sof_data: contains information about frame_id, link etc. |
| 1907 | * |
| 1908 | * @return : 0 on success |
| 1909 | * |
| 1910 | */ |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1911 | static int cam_req_mgr_cb_notify_trigger( |
| 1912 | struct cam_req_mgr_trigger_notify *trigger_data) |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1913 | { |
| 1914 | int rc = 0; |
| 1915 | struct crm_workq_task *task = NULL; |
| 1916 | struct cam_req_mgr_core_link *link = NULL; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1917 | struct cam_req_mgr_trigger_notify *notify_trigger; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1918 | struct crm_task_payload *task_data; |
| 1919 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1920 | if (!trigger_data) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1921 | CAM_ERR(CAM_CRM, "sof_data is NULL"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1922 | rc = -EINVAL; |
| 1923 | goto end; |
| 1924 | } |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1925 | |
| 1926 | link = (struct cam_req_mgr_core_link *) |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1927 | cam_get_device_priv(trigger_data->link_hdl); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1928 | if (!link) { |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1929 | CAM_DBG(CAM_CRM, "link ptr NULL %x", trigger_data->link_hdl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1930 | rc = -EINVAL; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1931 | goto end; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1932 | } |
| 1933 | |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1934 | spin_lock_bh(&link->link_state_spin_lock); |
| 1935 | if (link->state != CAM_CRM_LINK_STATE_READY) { |
| 1936 | CAM_WARN(CAM_CRM, "invalid link state:%d", link->state); |
| 1937 | spin_unlock_bh(&link->link_state_spin_lock); |
| 1938 | rc = -EPERM; |
| 1939 | goto end; |
| 1940 | } |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 1941 | crm_timer_reset(link->watchdog); |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 1942 | spin_unlock_bh(&link->link_state_spin_lock); |
| 1943 | |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1944 | task = cam_req_mgr_workq_get_task(link->workq); |
| 1945 | if (!task) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1946 | CAM_ERR(CAM_CRM, "no empty task frame %lld", |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1947 | trigger_data->frame_id); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1948 | rc = -EBUSY; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1949 | goto end; |
| 1950 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1951 | task_data = (struct crm_task_payload *)task->payload; |
| 1952 | task_data->type = CRM_WORKQ_TASK_NOTIFY_SOF; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1953 | notify_trigger = (struct cam_req_mgr_trigger_notify *)&task_data->u; |
| 1954 | notify_trigger->frame_id = trigger_data->frame_id; |
| 1955 | notify_trigger->link_hdl = trigger_data->link_hdl; |
| 1956 | notify_trigger->dev_hdl = trigger_data->dev_hdl; |
| 1957 | notify_trigger->trigger = trigger_data->trigger; |
| 1958 | task->process_cb = &cam_req_mgr_process_trigger; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1959 | rc = cam_req_mgr_workq_enqueue_task(task, link, CRM_TASK_PRIORITY_0); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1960 | |
| 1961 | end: |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1962 | return rc; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1963 | } |
| 1964 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1965 | static struct cam_req_mgr_crm_cb cam_req_mgr_ops = { |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1966 | .notify_trigger = cam_req_mgr_cb_notify_trigger, |
| 1967 | .notify_err = cam_req_mgr_cb_notify_err, |
| 1968 | .add_req = cam_req_mgr_cb_add_req, |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1969 | }; |
| 1970 | |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1971 | /** |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1972 | * __cam_req_mgr_setup_link_info() |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1973 | * |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1974 | * @brief : Sets up input queue, create pd based tables, communicate with |
| 1975 | * devs connected on this link and setup communication. |
| 1976 | * @link : pointer to link to setup |
| 1977 | * @link_info : link_info coming from CSL to prepare link |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1978 | * |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1979 | * @return : 0 on success, negative in case of failure |
| 1980 | * |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1981 | */ |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1982 | static int __cam_req_mgr_setup_link_info(struct cam_req_mgr_core_link *link, |
| 1983 | struct cam_req_mgr_link_info *link_info) |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1984 | { |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1985 | int rc = 0, i = 0; |
| 1986 | struct cam_req_mgr_core_dev_link_setup link_data; |
| 1987 | struct cam_req_mgr_connected_device *dev; |
| 1988 | struct cam_req_mgr_req_tbl *pd_tbl; |
| 1989 | enum cam_pipeline_delay max_delay; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 1990 | uint32_t subscribe_event = 0; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1991 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1992 | if (link_info->num_devices > CAM_REQ_MGR_MAX_HANDLES) |
| 1993 | return -EPERM; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 1994 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1995 | mutex_init(&link->req.lock); |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 1996 | CAM_DBG(CAM_CRM, "LOCK_DBG in_q lock %pK", &link->req.lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 1997 | link->req.num_tbl = 0; |
| 1998 | |
| 1999 | rc = __cam_req_mgr_setup_in_q(&link->req); |
| 2000 | if (rc < 0) |
| 2001 | return rc; |
| 2002 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2003 | max_delay = CAM_PIPELINE_DELAY_0; |
| 2004 | for (i = 0; i < link_info->num_devices; i++) { |
| 2005 | dev = &link->l_dev[i]; |
| 2006 | /* Using dev hdl, get ops ptr to communicate with device */ |
| 2007 | dev->ops = (struct cam_req_mgr_kmd_ops *) |
| 2008 | cam_get_device_ops(link_info->dev_hdls[i]); |
| 2009 | if (!dev->ops || |
| 2010 | !dev->ops->get_dev_info || |
| 2011 | !dev->ops->link_setup) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2012 | CAM_ERR(CAM_CRM, "FATAL: device ops NULL"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2013 | rc = -ENXIO; |
| 2014 | goto error; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2015 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2016 | dev->dev_hdl = link_info->dev_hdls[i]; |
| 2017 | dev->parent = (void *)link; |
| 2018 | dev->dev_info.dev_hdl = dev->dev_hdl; |
| 2019 | rc = dev->ops->get_dev_info(&dev->dev_info); |
Gregory Bergschneider | 6067993 | 2017-07-19 15:27:16 -0600 | [diff] [blame] | 2020 | |
| 2021 | trace_cam_req_mgr_connect_device(link, &dev->dev_info); |
| 2022 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 2023 | CAM_DBG(CAM_CRM, |
| 2024 | "%x: connected: %s, id %d, delay %d, trigger %x", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2025 | link_info->session_hdl, dev->dev_info.name, |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 2026 | dev->dev_info.dev_id, dev->dev_info.p_delay, |
| 2027 | dev->dev_info.trigger); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2028 | if (rc < 0 || |
| 2029 | dev->dev_info.p_delay >= |
| 2030 | CAM_PIPELINE_DELAY_MAX || |
| 2031 | dev->dev_info.p_delay < |
| 2032 | CAM_PIPELINE_DELAY_0) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2033 | CAM_ERR(CAM_CRM, "get device info failed"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2034 | goto error; |
| 2035 | } else { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2036 | CAM_DBG(CAM_CRM, "%x: connected: %s, delay %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2037 | link_info->session_hdl, |
| 2038 | dev->dev_info.name, |
| 2039 | dev->dev_info.p_delay); |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 2040 | if (dev->dev_info.p_delay > max_delay) |
| 2041 | max_delay = dev->dev_info.p_delay; |
| 2042 | |
| 2043 | subscribe_event |= (uint32_t)dev->dev_info.trigger; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2044 | } |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2045 | } |
| 2046 | |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 2047 | link->subscribe_event = subscribe_event; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2048 | link_data.link_enable = 1; |
| 2049 | link_data.link_hdl = link->link_hdl; |
| 2050 | link_data.crm_cb = &cam_req_mgr_ops; |
| 2051 | link_data.max_delay = max_delay; |
Junzhe Zou | 2df8450 | 2017-05-26 13:20:23 -0700 | [diff] [blame] | 2052 | link_data.subscribe_event = subscribe_event; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2053 | |
| 2054 | for (i = 0; i < link_info->num_devices; i++) { |
| 2055 | dev = &link->l_dev[i]; |
| 2056 | |
| 2057 | link_data.dev_hdl = dev->dev_hdl; |
| 2058 | /* |
| 2059 | * For unique pipeline delay table create request |
| 2060 | * tracking table |
| 2061 | */ |
| 2062 | if (link->pd_mask & (1 << dev->dev_info.p_delay)) { |
| 2063 | pd_tbl = __cam_req_mgr_find_pd_tbl(link->req.l_tbl, |
| 2064 | dev->dev_info.p_delay); |
| 2065 | if (!pd_tbl) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2066 | CAM_ERR(CAM_CRM, "pd %d tbl not found", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2067 | dev->dev_info.p_delay); |
| 2068 | rc = -ENXIO; |
| 2069 | goto error; |
| 2070 | } |
| 2071 | } else { |
| 2072 | pd_tbl = __cam_req_mgr_create_pd_tbl( |
| 2073 | dev->dev_info.p_delay); |
| 2074 | if (pd_tbl == NULL) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2075 | CAM_ERR(CAM_CRM, "create new pd tbl failed"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2076 | rc = -ENXIO; |
| 2077 | goto error; |
| 2078 | } |
| 2079 | pd_tbl->pd = dev->dev_info.p_delay; |
| 2080 | link->pd_mask |= (1 << pd_tbl->pd); |
| 2081 | /* |
| 2082 | * Add table to list and also sort list |
| 2083 | * from max pd to lowest |
| 2084 | */ |
| 2085 | __cam_req_mgr_add_tbl_to_link(&link->req.l_tbl, pd_tbl); |
| 2086 | } |
| 2087 | dev->dev_bit = pd_tbl->dev_count++; |
| 2088 | dev->pd_tbl = pd_tbl; |
| 2089 | pd_tbl->dev_mask |= (1 << dev->dev_bit); |
| 2090 | |
| 2091 | /* Communicate with dev to establish the link */ |
| 2092 | dev->ops->link_setup(&link_data); |
| 2093 | |
| 2094 | if (link->max_delay < dev->dev_info.p_delay) |
| 2095 | link->max_delay = dev->dev_info.p_delay; |
| 2096 | } |
| 2097 | link->num_devs = link_info->num_devices; |
| 2098 | |
| 2099 | /* Assign id for pd tables */ |
| 2100 | __cam_req_mgr_tbl_set_id(link->req.l_tbl, &link->req); |
| 2101 | |
| 2102 | /* At start, expect max pd devices, all are in skip state */ |
| 2103 | __cam_req_mgr_tbl_set_all_skip_cnt(&link->req.l_tbl); |
| 2104 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2105 | return 0; |
| 2106 | |
| 2107 | error: |
| 2108 | __cam_req_mgr_destroy_link_info(link); |
| 2109 | return rc; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2110 | } |
| 2111 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2112 | /* IOCTLs handling section */ |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2113 | int cam_req_mgr_create_session( |
| 2114 | struct cam_req_mgr_session_info *ses_info) |
| 2115 | { |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2116 | int rc = 0; |
| 2117 | int32_t session_hdl; |
| 2118 | struct cam_req_mgr_core_session *cam_session = NULL; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2119 | |
| 2120 | if (!ses_info) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2121 | CAM_DBG(CAM_CRM, "NULL session info pointer"); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2122 | return -EINVAL; |
| 2123 | } |
| 2124 | mutex_lock(&g_crm_core_dev->crm_lock); |
| 2125 | cam_session = (struct cam_req_mgr_core_session *) |
| 2126 | kzalloc(sizeof(*cam_session), GFP_KERNEL); |
| 2127 | if (!cam_session) { |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2128 | rc = -ENOMEM; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2129 | goto end; |
| 2130 | } |
| 2131 | |
| 2132 | session_hdl = cam_create_session_hdl((void *)cam_session); |
| 2133 | if (session_hdl < 0) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2134 | CAM_ERR(CAM_CRM, "unable to create session_hdl = %x", |
| 2135 | session_hdl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2136 | rc = session_hdl; |
| 2137 | kfree(cam_session); |
| 2138 | goto end; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2139 | } |
| 2140 | ses_info->session_hdl = session_hdl; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2141 | |
| 2142 | mutex_init(&cam_session->lock); |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2143 | CAM_DBG(CAM_CRM, "LOCK_DBG session lock %pK", &cam_session->lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2144 | |
| 2145 | mutex_lock(&cam_session->lock); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2146 | cam_session->session_hdl = session_hdl; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2147 | cam_session->num_links = 0; |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2148 | cam_session->sync_mode = CAM_REQ_MGR_SYNC_MODE_NO_SYNC; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2149 | list_add(&cam_session->entry, &g_crm_core_dev->session_head); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2150 | mutex_unlock(&cam_session->lock); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2151 | end: |
| 2152 | mutex_unlock(&g_crm_core_dev->crm_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2153 | return rc; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2154 | } |
| 2155 | |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2156 | /** |
| 2157 | * __cam_req_mgr_unlink() |
| 2158 | * |
| 2159 | * @brief : Unlink devices on a link structure from the session |
| 2160 | * @link : Pointer to the link structure |
| 2161 | * |
| 2162 | * @return: 0 for success, negative for failure |
| 2163 | * |
| 2164 | */ |
| 2165 | static int __cam_req_mgr_unlink(struct cam_req_mgr_core_link *link) |
| 2166 | { |
| 2167 | int rc; |
| 2168 | |
| 2169 | mutex_lock(&link->lock); |
| 2170 | spin_lock_bh(&link->link_state_spin_lock); |
| 2171 | link->state = CAM_CRM_LINK_STATE_IDLE; |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 2172 | |
| 2173 | /* Destroy timer of link */ |
| 2174 | crm_timer_exit(&link->watchdog); |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2175 | spin_unlock_bh(&link->link_state_spin_lock); |
| 2176 | __cam_req_mgr_print_req_tbl(&link->req); |
| 2177 | |
| 2178 | /* Destroy workq payload data */ |
| 2179 | kfree(link->workq->task.pool[0].payload); |
| 2180 | link->workq->task.pool[0].payload = NULL; |
| 2181 | |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 2182 | /* Destroy workq of link */ |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2183 | cam_req_mgr_workq_destroy(&link->workq); |
| 2184 | |
| 2185 | /* Cleanup request tables and unlink devices */ |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 2186 | rc = __cam_req_mgr_destroy_link_info(link); |
Vishalsingh Hajeri | 87c3131b | 2018-02-09 17:36:35 -0800 | [diff] [blame] | 2187 | if (rc) |
| 2188 | CAM_ERR(CAM_CORE, |
| 2189 | "Unlink for all devices was not successful"); |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2190 | |
| 2191 | /* Free memory holding data of linked devs */ |
| 2192 | __cam_req_mgr_destroy_subdev(link->l_dev); |
| 2193 | |
| 2194 | /* Destroy the link handle */ |
| 2195 | rc = cam_destroy_device_hdl(link->link_hdl); |
| 2196 | if (rc < 0) { |
| 2197 | CAM_ERR(CAM_CRM, "error while destroying dev handle %d %x", |
| 2198 | rc, link->link_hdl); |
| 2199 | } |
| 2200 | |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2201 | mutex_unlock(&link->lock); |
| 2202 | return rc; |
| 2203 | } |
| 2204 | |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2205 | int cam_req_mgr_destroy_session( |
| 2206 | struct cam_req_mgr_session_info *ses_info) |
| 2207 | { |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2208 | int rc; |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2209 | int i; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2210 | struct cam_req_mgr_core_session *cam_session = NULL; |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2211 | struct cam_req_mgr_core_link *link; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2212 | |
| 2213 | if (!ses_info) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2214 | CAM_DBG(CAM_CRM, "NULL session info pointer"); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2215 | return -EINVAL; |
| 2216 | } |
| 2217 | |
| 2218 | mutex_lock(&g_crm_core_dev->crm_lock); |
| 2219 | cam_session = (struct cam_req_mgr_core_session *) |
| 2220 | cam_get_device_priv(ses_info->session_hdl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2221 | if (!cam_session) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2222 | CAM_ERR(CAM_CRM, "failed to get session priv"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2223 | rc = -ENOENT; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2224 | goto end; |
| 2225 | |
| 2226 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2227 | mutex_lock(&cam_session->lock); |
| 2228 | if (cam_session->num_links) { |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2229 | CAM_DBG(CAM_CRM, "destroy session %x num_active_links %d", |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2230 | ses_info->session_hdl, |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2231 | cam_session->num_links); |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2232 | |
| 2233 | for (i = 0; i < MAX_LINKS_PER_SESSION; i++) { |
| 2234 | link = cam_session->links[i]; |
| 2235 | |
| 2236 | if (!link) |
| 2237 | continue; |
| 2238 | |
| 2239 | /* Ignore return value since session is going away */ |
| 2240 | __cam_req_mgr_unlink(link); |
| 2241 | __cam_req_mgr_free_link(link); |
| 2242 | } |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2243 | } |
| 2244 | list_del(&cam_session->entry); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2245 | mutex_unlock(&cam_session->lock); |
| 2246 | mutex_destroy(&cam_session->lock); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2247 | kfree(cam_session); |
| 2248 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2249 | rc = cam_destroy_session_hdl(ses_info->session_hdl); |
| 2250 | if (rc < 0) |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2251 | CAM_ERR(CAM_CRM, "unable to destroy session_hdl = %x rc %d", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2252 | ses_info->session_hdl, rc); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2253 | |
| 2254 | end: |
| 2255 | mutex_unlock(&g_crm_core_dev->crm_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2256 | return rc; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | int cam_req_mgr_link(struct cam_req_mgr_link_info *link_info) |
| 2260 | { |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2261 | int rc = 0; |
| 2262 | char buf[128]; |
| 2263 | struct cam_create_dev_hdl root_dev; |
| 2264 | struct cam_req_mgr_core_session *cam_session; |
| 2265 | struct cam_req_mgr_core_link *link; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2266 | |
| 2267 | if (!link_info) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2268 | CAM_DBG(CAM_CRM, "NULL pointer"); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2269 | return -EINVAL; |
| 2270 | } |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2271 | if (link_info->num_devices > CAM_REQ_MGR_MAX_HANDLES) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2272 | CAM_ERR(CAM_CRM, "Invalid num devices %d", |
| 2273 | link_info->num_devices); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2274 | return -EINVAL; |
| 2275 | } |
| 2276 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2277 | /* session hdl's priv data is cam session struct */ |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2278 | cam_session = (struct cam_req_mgr_core_session *) |
| 2279 | cam_get_device_priv(link_info->session_hdl); |
| 2280 | if (!cam_session) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2281 | CAM_DBG(CAM_CRM, "NULL pointer"); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2282 | return -EINVAL; |
| 2283 | } |
| 2284 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2285 | mutex_lock(&g_crm_core_dev->crm_lock); |
| 2286 | |
| 2287 | /* Allocate link struct and map it with session's request queue */ |
| 2288 | link = __cam_req_mgr_reserve_link(cam_session); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2289 | if (!link) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2290 | CAM_ERR(CAM_CRM, "failed to reserve new link"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2291 | mutex_unlock(&g_crm_core_dev->crm_lock); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2292 | return -EINVAL; |
| 2293 | } |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2294 | CAM_DBG(CAM_CRM, "link reserved %pK %x", link, link->link_hdl); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2295 | |
| 2296 | memset(&root_dev, 0, sizeof(struct cam_create_dev_hdl)); |
| 2297 | root_dev.session_hdl = link_info->session_hdl; |
| 2298 | root_dev.priv = (void *)link; |
| 2299 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2300 | mutex_lock(&link->lock); |
| 2301 | /* Create unique dev handle for link */ |
| 2302 | link->link_hdl = cam_create_device_hdl(&root_dev); |
| 2303 | if (link->link_hdl < 0) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2304 | CAM_ERR(CAM_CRM, |
| 2305 | "Insufficient memory to create new device handle"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2306 | rc = link->link_hdl; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2307 | goto link_hdl_fail; |
| 2308 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2309 | link_info->link_hdl = link->link_hdl; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2310 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2311 | /* Allocate memory to hold data of all linked devs */ |
| 2312 | rc = __cam_req_mgr_create_subdevs(&link->l_dev, |
| 2313 | link_info->num_devices); |
| 2314 | if (rc < 0) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2315 | CAM_ERR(CAM_CRM, |
| 2316 | "Insufficient memory to create new crm subdevs"); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2317 | goto create_subdev_failed; |
| 2318 | } |
| 2319 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2320 | /* Using device ops query connected devs, prepare request tables */ |
| 2321 | rc = __cam_req_mgr_setup_link_info(link, link_info); |
| 2322 | if (rc < 0) |
| 2323 | goto setup_failed; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2324 | |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 2325 | spin_lock_bh(&link->link_state_spin_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2326 | link->state = CAM_CRM_LINK_STATE_READY; |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 2327 | spin_unlock_bh(&link->link_state_spin_lock); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2328 | |
| 2329 | /* Create worker for current link */ |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2330 | snprintf(buf, sizeof(buf), "%x-%x", |
| 2331 | link_info->session_hdl, link->link_hdl); |
Sagar Gore | 9f40471 | 2017-05-22 16:57:25 -0700 | [diff] [blame] | 2332 | rc = cam_req_mgr_workq_create(buf, CRM_WORKQ_NUM_TASKS, |
| 2333 | &link->workq, CRM_WORKQ_USAGE_NON_IRQ); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2334 | if (rc < 0) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2335 | CAM_ERR(CAM_CRM, "FATAL: unable to create worker"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2336 | __cam_req_mgr_destroy_link_info(link); |
| 2337 | goto setup_failed; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2338 | } |
| 2339 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2340 | /* Assign payload to workqueue tasks */ |
| 2341 | rc = __cam_req_mgr_setup_payload(link->workq); |
| 2342 | if (rc < 0) { |
| 2343 | __cam_req_mgr_destroy_link_info(link); |
| 2344 | cam_req_mgr_workq_destroy(&link->workq); |
| 2345 | goto setup_failed; |
| 2346 | } |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2347 | |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 2348 | mutex_unlock(&link->lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2349 | mutex_unlock(&g_crm_core_dev->crm_lock); |
| 2350 | return rc; |
| 2351 | setup_failed: |
| 2352 | __cam_req_mgr_destroy_subdev(link->l_dev); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2353 | create_subdev_failed: |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2354 | cam_destroy_device_hdl(link->link_hdl); |
| 2355 | link_info->link_hdl = 0; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2356 | link_hdl_fail: |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 2357 | mutex_unlock(&link->lock); |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2358 | __cam_req_mgr_unreserve_link(cam_session, link); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2359 | mutex_unlock(&g_crm_core_dev->crm_lock); |
| 2360 | return rc; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2361 | } |
| 2362 | |
| 2363 | int cam_req_mgr_unlink(struct cam_req_mgr_unlink_info *unlink_info) |
| 2364 | { |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2365 | int rc = 0; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2366 | struct cam_req_mgr_core_session *cam_session; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2367 | struct cam_req_mgr_core_link *link; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2368 | |
| 2369 | if (!unlink_info) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2370 | CAM_ERR(CAM_CRM, "NULL pointer"); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2371 | return -EINVAL; |
| 2372 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2373 | |
| 2374 | mutex_lock(&g_crm_core_dev->crm_lock); |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2375 | CAM_DBG(CAM_CRM, "link_hdl %x", unlink_info->link_hdl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2376 | |
| 2377 | /* session hdl's priv data is cam session struct */ |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2378 | cam_session = (struct cam_req_mgr_core_session *) |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2379 | cam_get_device_priv(unlink_info->session_hdl); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2380 | if (!cam_session) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2381 | CAM_ERR(CAM_CRM, "NULL pointer"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2382 | mutex_unlock(&g_crm_core_dev->crm_lock); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2383 | return -EINVAL; |
| 2384 | } |
| 2385 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2386 | /* link hdl's priv data is core_link struct */ |
| 2387 | link = cam_get_device_priv(unlink_info->link_hdl); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2388 | if (!link) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2389 | CAM_ERR(CAM_CRM, "NULL pointer"); |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2390 | rc = -EINVAL; |
| 2391 | goto done; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2392 | } |
Ravikishore Pampana | 6c2e1c1 | 2017-10-16 18:46:15 +0530 | [diff] [blame] | 2393 | |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2394 | rc = __cam_req_mgr_unlink(link); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2395 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2396 | /* Free curent link and put back into session's free pool of links */ |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2397 | if (!rc) |
| 2398 | __cam_req_mgr_unreserve_link(cam_session, link); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2399 | |
Sunil Khatri | bc029f7 | 2017-11-28 18:54:24 +0530 | [diff] [blame] | 2400 | done: |
| 2401 | mutex_unlock(&g_crm_core_dev->crm_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2402 | return rc; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2403 | } |
| 2404 | |
| 2405 | int cam_req_mgr_schedule_request( |
| 2406 | struct cam_req_mgr_sched_request *sched_req) |
| 2407 | { |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2408 | int rc = 0; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2409 | struct cam_req_mgr_core_link *link = NULL; |
| 2410 | struct cam_req_mgr_core_session *session = NULL; |
| 2411 | struct cam_req_mgr_sched_request *sched; |
Sagar Gore | b56c81e | 2017-05-08 17:15:47 -0700 | [diff] [blame] | 2412 | struct crm_task_payload task_data; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2413 | |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2414 | if (!sched_req) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2415 | CAM_ERR(CAM_CRM, "csl_req is NULL"); |
Vishalsingh Hajeri | 41ac167 | 2017-12-01 14:36:00 -0800 | [diff] [blame] | 2416 | return -EINVAL; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2417 | } |
| 2418 | |
Vishalsingh Hajeri | 41ac167 | 2017-12-01 14:36:00 -0800 | [diff] [blame] | 2419 | mutex_lock(&g_crm_core_dev->crm_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2420 | link = (struct cam_req_mgr_core_link *) |
| 2421 | cam_get_device_priv(sched_req->link_hdl); |
| 2422 | if (!link) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2423 | CAM_DBG(CAM_CRM, "link ptr NULL %x", sched_req->link_hdl); |
Vishalsingh Hajeri | 41ac167 | 2017-12-01 14:36:00 -0800 | [diff] [blame] | 2424 | rc = -EINVAL; |
| 2425 | goto end; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2426 | } |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2427 | |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2428 | session = (struct cam_req_mgr_core_session *)link->parent; |
| 2429 | if (!session) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2430 | CAM_WARN(CAM_CRM, "session ptr NULL %x", sched_req->link_hdl); |
Vishalsingh Hajeri | 41ac167 | 2017-12-01 14:36:00 -0800 | [diff] [blame] | 2431 | rc = -EINVAL; |
| 2432 | goto end; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2433 | } |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2434 | |
| 2435 | CAM_DBG(CAM_CRM, "link %x req %lld, sync_mode %d", |
| 2436 | sched_req->link_hdl, sched_req->req_id, sched_req->sync_mode); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2437 | |
Sagar Gore | b56c81e | 2017-05-08 17:15:47 -0700 | [diff] [blame] | 2438 | task_data.type = CRM_WORKQ_TASK_SCHED_REQ; |
| 2439 | sched = (struct cam_req_mgr_sched_request *)&task_data.u; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2440 | sched->req_id = sched_req->req_id; |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2441 | sched->sync_mode = sched_req->sync_mode; |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2442 | sched->link_hdl = sched_req->link_hdl; |
| 2443 | if (session->force_err_recovery == AUTO_RECOVERY) { |
| 2444 | sched->bubble_enable = sched_req->bubble_enable; |
| 2445 | } else { |
| 2446 | sched->bubble_enable = |
| 2447 | (session->force_err_recovery == FORCE_ENABLE_RECOVERY) ? 1 : 0; |
| 2448 | } |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2449 | |
Sagar Gore | b56c81e | 2017-05-08 17:15:47 -0700 | [diff] [blame] | 2450 | rc = cam_req_mgr_process_sched_req(link, &task_data); |
| 2451 | |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2452 | CAM_DBG(CAM_CRM, "DONE dev %x req %lld sync_mode %d", |
| 2453 | sched_req->link_hdl, sched_req->req_id, sched_req->sync_mode); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2454 | end: |
Vishalsingh Hajeri | 41ac167 | 2017-12-01 14:36:00 -0800 | [diff] [blame] | 2455 | mutex_unlock(&g_crm_core_dev->crm_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2456 | return rc; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2457 | } |
| 2458 | |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2459 | int cam_req_mgr_sync_config( |
| 2460 | struct cam_req_mgr_sync_mode *sync_info) |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2461 | { |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2462 | int rc = 0; |
| 2463 | struct cam_req_mgr_core_session *cam_session; |
| 2464 | struct cam_req_mgr_core_link *link1 = NULL; |
| 2465 | struct cam_req_mgr_core_link *link2 = NULL; |
| 2466 | |
| 2467 | if (!sync_info) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2468 | CAM_ERR(CAM_CRM, "NULL pointer"); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2469 | return -EINVAL; |
| 2470 | } |
| 2471 | |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2472 | if ((sync_info->num_links < 0) || |
| 2473 | (sync_info->num_links > MAX_LINKS_PER_SESSION)) { |
| 2474 | CAM_ERR(CAM_CRM, "Invalid num links %d", sync_info->num_links); |
| 2475 | return -EINVAL; |
| 2476 | } |
| 2477 | |
Pavan Kumar Chilamkurthi | bd69943 | 2018-01-24 12:53:01 -0800 | [diff] [blame] | 2478 | if ((!sync_info->link_hdls[0]) || (!sync_info->link_hdls[1])) { |
| 2479 | CAM_WARN(CAM_CRM, "Invalid link handles 0x%x 0x%x", |
| 2480 | sync_info->link_hdls[0], sync_info->link_hdls[1]); |
| 2481 | return -EINVAL; |
| 2482 | } |
| 2483 | |
Vishalsingh Hajeri | 41ac167 | 2017-12-01 14:36:00 -0800 | [diff] [blame] | 2484 | mutex_lock(&g_crm_core_dev->crm_lock); |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2485 | /* session hdl's priv data is cam session struct */ |
| 2486 | cam_session = (struct cam_req_mgr_core_session *) |
| 2487 | cam_get_device_priv(sync_info->session_hdl); |
| 2488 | if (!cam_session) { |
| 2489 | CAM_ERR(CAM_CRM, "NULL pointer"); |
Vishalsingh Hajeri | 41ac167 | 2017-12-01 14:36:00 -0800 | [diff] [blame] | 2490 | mutex_unlock(&g_crm_core_dev->crm_lock); |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2491 | return -EINVAL; |
| 2492 | } |
| 2493 | |
| 2494 | mutex_lock(&cam_session->lock); |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 2495 | |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 2496 | CAM_DBG(CAM_CRM, "link handles %x %x", |
| 2497 | sync_info->link_hdls[0], sync_info->link_hdls[1]); |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2498 | |
| 2499 | /* only two links existing per session in dual cam use case*/ |
| 2500 | link1 = cam_get_device_priv(sync_info->link_hdls[0]); |
| 2501 | if (!link1) { |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 2502 | CAM_ERR(CAM_CRM, "link1 NULL pointer"); |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2503 | rc = -EINVAL; |
| 2504 | goto done; |
| 2505 | } |
| 2506 | |
| 2507 | link2 = cam_get_device_priv(sync_info->link_hdls[1]); |
| 2508 | if (!link2) { |
Karthik Anantha Ram | fa64333 | 2017-11-06 13:49:31 -0800 | [diff] [blame] | 2509 | CAM_ERR(CAM_CRM, "link2 NULL pointer"); |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2510 | rc = -EINVAL; |
| 2511 | goto done; |
| 2512 | } |
| 2513 | |
| 2514 | link1->sof_counter = -1; |
| 2515 | link1->sync_self_ref = -1; |
| 2516 | link1->frame_skip_flag = false; |
| 2517 | link1->sync_link = link2; |
| 2518 | |
| 2519 | link2->sof_counter = -1; |
| 2520 | link2->sync_self_ref = -1; |
| 2521 | link2->frame_skip_flag = false; |
| 2522 | link2->sync_link = link1; |
| 2523 | |
| 2524 | cam_session->sync_mode = sync_info->sync_mode; |
| 2525 | |
| 2526 | done: |
| 2527 | mutex_unlock(&cam_session->lock); |
Vishalsingh Hajeri | 41ac167 | 2017-12-01 14:36:00 -0800 | [diff] [blame] | 2528 | mutex_unlock(&g_crm_core_dev->crm_lock); |
Pavan Kumar Chilamkurthi | 1fd0344 | 2017-11-07 17:07:21 -0800 | [diff] [blame] | 2529 | return rc; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | int cam_req_mgr_flush_requests( |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2533 | struct cam_req_mgr_flush_info *flush_info) |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2534 | { |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2535 | int rc = 0; |
| 2536 | struct crm_workq_task *task = NULL; |
| 2537 | struct cam_req_mgr_core_link *link = NULL; |
| 2538 | struct cam_req_mgr_flush_info *flush; |
| 2539 | struct crm_task_payload *task_data; |
| 2540 | struct cam_req_mgr_core_session *session = NULL; |
| 2541 | |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2542 | if (!flush_info) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2543 | CAM_ERR(CAM_CRM, "flush req is NULL"); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2544 | rc = -EFAULT; |
| 2545 | goto end; |
| 2546 | } |
| 2547 | if (flush_info->flush_type >= CAM_REQ_MGR_FLUSH_TYPE_MAX) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2548 | CAM_ERR(CAM_CRM, "incorrect flush type %x", |
| 2549 | flush_info->flush_type); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2550 | rc = -EINVAL; |
| 2551 | goto end; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2552 | } |
| 2553 | |
Vishalsingh Hajeri | 41ac167 | 2017-12-01 14:36:00 -0800 | [diff] [blame] | 2554 | mutex_lock(&g_crm_core_dev->crm_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2555 | /* session hdl's priv data is cam session struct */ |
| 2556 | session = (struct cam_req_mgr_core_session *) |
| 2557 | cam_get_device_priv(flush_info->session_hdl); |
| 2558 | if (!session) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2559 | CAM_ERR(CAM_CRM, "Invalid session %x", flush_info->session_hdl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2560 | rc = -EINVAL; |
| 2561 | goto end; |
| 2562 | } |
| 2563 | if (session->num_links <= 0) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2564 | CAM_WARN(CAM_CRM, "No active links in session %x", |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2565 | flush_info->session_hdl); |
| 2566 | goto end; |
| 2567 | } |
| 2568 | |
| 2569 | link = (struct cam_req_mgr_core_link *) |
| 2570 | cam_get_device_priv(flush_info->link_hdl); |
| 2571 | if (!link) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2572 | CAM_DBG(CAM_CRM, "link ptr NULL %x", flush_info->link_hdl); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2573 | rc = -EINVAL; |
| 2574 | goto end; |
| 2575 | } |
| 2576 | |
| 2577 | task = cam_req_mgr_workq_get_task(link->workq); |
| 2578 | if (!task) { |
| 2579 | rc = -ENOMEM; |
| 2580 | goto end; |
| 2581 | } |
| 2582 | |
| 2583 | task_data = (struct crm_task_payload *)task->payload; |
| 2584 | task_data->type = CRM_WORKQ_TASK_FLUSH_REQ; |
| 2585 | flush = (struct cam_req_mgr_flush_info *)&task_data->u; |
| 2586 | flush->req_id = flush_info->req_id; |
| 2587 | flush->link_hdl = flush_info->link_hdl; |
| 2588 | flush->flush_type = flush_info->flush_type; |
| 2589 | task->process_cb = &cam_req_mgr_process_flush_req; |
Junzhe Zou | 158da72 | 2017-10-25 19:14:32 -0700 | [diff] [blame] | 2590 | init_completion(&link->workq_comp); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2591 | rc = cam_req_mgr_workq_enqueue_task(task, link, CRM_TASK_PRIORITY_0); |
| 2592 | |
| 2593 | /* Blocking call */ |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2594 | rc = wait_for_completion_timeout( |
| 2595 | &link->workq_comp, |
| 2596 | msecs_to_jiffies(CAM_REQ_MGR_SCHED_REQ_TIMEOUT)); |
| 2597 | end: |
Vishalsingh Hajeri | 41ac167 | 2017-12-01 14:36:00 -0800 | [diff] [blame] | 2598 | mutex_unlock(&g_crm_core_dev->crm_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2599 | return rc; |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2600 | } |
| 2601 | |
Jing Zhou | 0f64533 | 2017-11-17 12:16:40 -0800 | [diff] [blame] | 2602 | int cam_req_mgr_link_control(struct cam_req_mgr_link_control *control) |
| 2603 | { |
| 2604 | int rc = 0; |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2605 | int i, j; |
Jing Zhou | 0f64533 | 2017-11-17 12:16:40 -0800 | [diff] [blame] | 2606 | struct cam_req_mgr_core_link *link = NULL; |
| 2607 | |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2608 | struct cam_req_mgr_connected_device *dev = NULL; |
| 2609 | struct cam_req_mgr_link_evt_data evt_data; |
| 2610 | |
Jing Zhou | 0f64533 | 2017-11-17 12:16:40 -0800 | [diff] [blame] | 2611 | if (!control) { |
| 2612 | CAM_ERR(CAM_CRM, "Control command is NULL"); |
| 2613 | rc = -EINVAL; |
| 2614 | goto end; |
| 2615 | } |
| 2616 | |
| 2617 | mutex_lock(&g_crm_core_dev->crm_lock); |
| 2618 | for (i = 0; i < control->num_links; i++) { |
| 2619 | link = (struct cam_req_mgr_core_link *) |
| 2620 | cam_get_device_priv(control->link_hdls[i]); |
| 2621 | if (!link) { |
| 2622 | CAM_ERR(CAM_CRM, "Link(%d) is NULL on session 0x%x", |
| 2623 | i, control->session_hdl); |
| 2624 | rc = -EINVAL; |
| 2625 | break; |
| 2626 | } |
| 2627 | |
| 2628 | mutex_lock(&link->lock); |
| 2629 | if (control->ops == CAM_REQ_MGR_LINK_ACTIVATE) { |
| 2630 | /* Start SOF watchdog timer */ |
| 2631 | rc = crm_timer_init(&link->watchdog, |
| 2632 | CAM_REQ_MGR_WATCHDOG_TIMEOUT, link, |
| 2633 | &__cam_req_mgr_sof_freeze); |
| 2634 | if (rc < 0) { |
| 2635 | CAM_ERR(CAM_CRM, |
| 2636 | "SOF timer start fails: link=0x%x", |
| 2637 | link->link_hdl); |
| 2638 | rc = -EFAULT; |
| 2639 | } |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2640 | /* notify nodes */ |
| 2641 | for (j = 0; j < link->num_devs; j++) { |
| 2642 | dev = &link->l_dev[j]; |
| 2643 | evt_data.evt_type = CAM_REQ_MGR_LINK_EVT_RESUME; |
| 2644 | evt_data.link_hdl = link->link_hdl; |
| 2645 | evt_data.dev_hdl = dev->dev_hdl; |
| 2646 | evt_data.req_id = 0; |
| 2647 | if (dev->ops && dev->ops->process_evt) |
| 2648 | dev->ops->process_evt(&evt_data); |
| 2649 | } |
Jing Zhou | 0f64533 | 2017-11-17 12:16:40 -0800 | [diff] [blame] | 2650 | } else if (control->ops == CAM_REQ_MGR_LINK_DEACTIVATE) { |
| 2651 | /* Destroy SOF watchdog timer */ |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 2652 | spin_lock_bh(&link->link_state_spin_lock); |
Jing Zhou | 0f64533 | 2017-11-17 12:16:40 -0800 | [diff] [blame] | 2653 | crm_timer_exit(&link->watchdog); |
Venkat Chinta | 686c9e5 | 2018-01-20 14:33:25 -0800 | [diff] [blame] | 2654 | spin_unlock_bh(&link->link_state_spin_lock); |
Jing Zhou | 30504bd | 2017-11-21 11:36:07 -0800 | [diff] [blame] | 2655 | /* notify nodes */ |
| 2656 | for (j = 0; j < link->num_devs; j++) { |
| 2657 | dev = &link->l_dev[j]; |
| 2658 | evt_data.evt_type = CAM_REQ_MGR_LINK_EVT_PAUSE; |
| 2659 | evt_data.link_hdl = link->link_hdl; |
| 2660 | evt_data.dev_hdl = dev->dev_hdl; |
| 2661 | evt_data.req_id = 0; |
| 2662 | if (dev->ops && dev->ops->process_evt) |
| 2663 | dev->ops->process_evt(&evt_data); |
| 2664 | } |
Jing Zhou | 0f64533 | 2017-11-17 12:16:40 -0800 | [diff] [blame] | 2665 | } else { |
| 2666 | CAM_ERR(CAM_CRM, "Invalid link control command"); |
| 2667 | rc = -EINVAL; |
| 2668 | } |
| 2669 | mutex_unlock(&link->lock); |
| 2670 | } |
| 2671 | mutex_unlock(&g_crm_core_dev->crm_lock); |
| 2672 | end: |
| 2673 | return rc; |
| 2674 | } |
| 2675 | |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2676 | |
| 2677 | int cam_req_mgr_core_device_init(void) |
| 2678 | { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2679 | CAM_DBG(CAM_CRM, "Enter g_crm_core_dev %pK", g_crm_core_dev); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2680 | |
| 2681 | if (g_crm_core_dev) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2682 | CAM_WARN(CAM_CRM, "core device is already initialized"); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2683 | return 0; |
| 2684 | } |
| 2685 | g_crm_core_dev = (struct cam_req_mgr_core_device *) |
| 2686 | kzalloc(sizeof(*g_crm_core_dev), GFP_KERNEL); |
| 2687 | if (!g_crm_core_dev) |
| 2688 | return -ENOMEM; |
| 2689 | |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2690 | CAM_DBG(CAM_CRM, "g_crm_core_dev %pK", g_crm_core_dev); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2691 | INIT_LIST_HEAD(&g_crm_core_dev->session_head); |
| 2692 | mutex_init(&g_crm_core_dev->crm_lock); |
Sagar Gore | d79f95e | 2017-03-14 18:32:17 -0700 | [diff] [blame] | 2693 | cam_req_mgr_debug_register(g_crm_core_dev); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2694 | |
| 2695 | return 0; |
| 2696 | } |
| 2697 | |
| 2698 | int cam_req_mgr_core_device_deinit(void) |
| 2699 | { |
| 2700 | if (!g_crm_core_dev) { |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2701 | CAM_ERR(CAM_CRM, "NULL pointer"); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2702 | return -EINVAL; |
| 2703 | } |
| 2704 | |
Jigarkumar Zala | 36ad717 | 2017-07-18 19:52:14 -0700 | [diff] [blame] | 2705 | CAM_DBG(CAM_CRM, "g_crm_core_dev %pK", g_crm_core_dev); |
Sagar Gore | 8d91a62 | 2017-02-23 14:57:18 -0800 | [diff] [blame] | 2706 | mutex_destroy(&g_crm_core_dev->crm_lock); |
| 2707 | kfree(g_crm_core_dev); |
| 2708 | g_crm_core_dev = NULL; |
| 2709 | |
| 2710 | return 0; |
| 2711 | } |