Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 3 | * Copyright (c) 2013, 2015-2018 The Linux Foundation. All rights reserved. |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 4 | * Permission to use, copy, modify, and/or distribute this software for |
| 5 | * any purpose with or without fee is hereby granted, provided that the |
| 6 | * above copyright notice and this permission notice appear in all copies. |
| 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 10 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 12 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT |
| 13 | * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 14 | ************************************************************************** |
| 15 | */ |
| 16 | |
| 17 | /* |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 18 | * nss_freq.c |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 19 | * NSS frequency change APIs |
| 20 | */ |
| 21 | |
| 22 | #include "nss_tx_rx_common.h" |
Sachin Shashidhar | 6dd9cfc | 2018-07-31 14:44:37 -0700 | [diff] [blame] | 23 | #include "nss_freq_log.h" |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 24 | |
| 25 | #define NSS_ACK_STARTED 0 |
| 26 | #define NSS_ACK_FINISHED 1 |
| 27 | |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 28 | extern struct nss_frequency_statistics nss_freq_stat; |
| 29 | extern struct nss_runtime_sampling nss_runtime_samples; |
| 30 | extern struct workqueue_struct *nss_wq; |
| 31 | extern nss_work_t *nss_work; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 32 | |
| 33 | /* |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 34 | * nss_freq_msg_init() |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 35 | * Initialize the freq message |
Sundarajan Srinivasan | 02e6c2b | 2014-10-06 11:51:12 -0700 | [diff] [blame] | 36 | */ |
| 37 | static void nss_freq_msg_init(struct nss_corefreq_msg *ncm, uint16_t if_num, uint32_t type, uint32_t len, |
| 38 | void *cb, void *app_data) |
| 39 | { |
| 40 | nss_cmn_msg_init(&ncm->cm, if_num, type, len, cb, app_data); |
| 41 | } |
| 42 | |
| 43 | /* |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 44 | * nss_freq_handle_ack() |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 45 | * Handle the nss ack of frequency change. |
| 46 | */ |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 47 | static void nss_freq_handle_ack(struct nss_ctx_instance *nss_ctx, struct nss_freq_msg *nfa) |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 48 | { |
Thomas Wu | 168ca26 | 2014-03-21 16:20:27 -0700 | [diff] [blame] | 49 | if (nfa->ack == NSS_ACK_STARTED) { |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 50 | /* |
| 51 | * NSS finished start noficiation - HW change clocks and send end notification |
| 52 | */ |
Thomas Wu | 168ca26 | 2014-03-21 16:20:27 -0700 | [diff] [blame] | 53 | nss_info("%p: NSS ACK Received: %d - Change HW CLK/Send Finish to NSS\n", nss_ctx, nfa->ack); |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 54 | |
| 55 | return; |
| 56 | } |
| 57 | |
Thomas Wu | 168ca26 | 2014-03-21 16:20:27 -0700 | [diff] [blame] | 58 | if (nfa->ack == NSS_ACK_FINISHED) { |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 59 | /* |
| 60 | * NSS finished end notification - Done |
| 61 | */ |
Thomas Wu | 168ca26 | 2014-03-21 16:20:27 -0700 | [diff] [blame] | 62 | nss_info("%p: NSS ACK Received: %d - End Notification ACK - Running: %dmhz\n", nss_ctx, nfa->ack, nfa->freq_current); |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 63 | nss_runtime_samples.freq_scale_ready = 1; |
| 64 | return; |
| 65 | } |
| 66 | |
| 67 | nss_info("%p: NSS had an error - Running: %dmhz\n", nss_ctx, nfa->freq_current); |
| 68 | } |
| 69 | |
| 70 | /* |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 71 | * nss_freq_queue_work() |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 72 | * Queue Work to the NSS Workqueue based on Current index. |
| 73 | */ |
Tanmay V Jagdale | f6b2bce | 2017-03-03 14:31:07 +0530 | [diff] [blame] | 74 | static bool nss_freq_queue_work(void) |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 75 | { |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 76 | nss_freq_scales_t index = nss_runtime_samples.freq_scale_index; |
| 77 | |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 78 | BUG_ON(!nss_wq); |
| 79 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 80 | nss_info("frequency:%d index:%d sample count:%x\n", nss_runtime_samples.freq_scale[index].frequency, |
| 81 | index, nss_runtime_samples.average); |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 82 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 83 | /* |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 84 | * schedule freq change with autoscale ON |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 85 | */ |
Tanmay V Jagdale | f6b2bce | 2017-03-03 14:31:07 +0530 | [diff] [blame] | 86 | return nss_freq_sched_change(index, true); |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /* |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 90 | * nss_freq_handle_core_stats() |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 91 | * Handle the core stats |
| 92 | */ |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 93 | static void nss_freq_handle_core_stats(struct nss_ctx_instance *nss_ctx, struct nss_core_stats *core_stats) |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 94 | { |
| 95 | uint32_t b_index; |
| 96 | uint32_t minimum; |
| 97 | uint32_t maximum; |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 98 | uint32_t sample = core_stats->inst_cnt_total; |
| 99 | uint32_t index = nss_runtime_samples.freq_scale_index; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 100 | |
| 101 | /* |
| 102 | * We do not accept any statistics if auto scaling is off, |
| 103 | * we start with a fresh sample set when scaling is |
| 104 | * eventually turned on. |
| 105 | */ |
| 106 | if (!nss_cmd_buf.auto_scale && nss_runtime_samples.initialized) { |
| 107 | return; |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * Delete Current Index Value, Add New Value, Recalculate new Sum, Shift Index |
| 112 | */ |
| 113 | b_index = nss_runtime_samples.buffer_index; |
| 114 | |
| 115 | nss_runtime_samples.sum = nss_runtime_samples.sum - nss_runtime_samples.buffer[b_index]; |
| 116 | nss_runtime_samples.buffer[b_index] = sample; |
| 117 | nss_runtime_samples.sum = nss_runtime_samples.sum + nss_runtime_samples.buffer[b_index]; |
| 118 | nss_runtime_samples.buffer_index = (b_index + 1) & NSS_SAMPLE_BUFFER_MASK; |
| 119 | |
| 120 | if (nss_runtime_samples.sample_count < NSS_SAMPLE_BUFFER_SIZE) { |
| 121 | nss_runtime_samples.sample_count++; |
| 122 | |
| 123 | /* |
| 124 | * Samples Are All Ready, Start Auto Scale |
| 125 | */ |
| 126 | if (nss_runtime_samples.sample_count == NSS_SAMPLE_BUFFER_SIZE ) { |
| 127 | nss_cmd_buf.auto_scale = 1; |
| 128 | nss_runtime_samples.freq_scale_ready = 1; |
| 129 | nss_runtime_samples.initialized = 1; |
| 130 | } |
| 131 | |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | nss_runtime_samples.average = nss_runtime_samples.sum / nss_runtime_samples.sample_count; |
| 136 | |
| 137 | /* |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 138 | * Print out statistics every 10 samples |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 139 | */ |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 140 | if (nss_runtime_samples.message_rate_limit++ >= NSS_MESSAGE_RATE_LIMIT) { |
Sakthi Vignesh Radhakrishnan | aa37810 | 2014-04-07 13:52:28 -0700 | [diff] [blame] | 141 | nss_trace("%p: Running AVG:%x Sample:%x Divider:%d\n", nss_ctx, nss_runtime_samples.average, core_stats->inst_cnt_total, nss_runtime_samples.sample_count); |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 142 | nss_trace("%p: Current Frequency Index:%d\n", nss_ctx, index); |
Sakthi Vignesh Radhakrishnan | aa37810 | 2014-04-07 13:52:28 -0700 | [diff] [blame] | 143 | nss_trace("%p: Auto Scale:%d Auto Scale Ready:%d\n", nss_ctx, nss_runtime_samples.freq_scale_ready, nss_cmd_buf.auto_scale); |
| 144 | nss_trace("%p: Current Rate:%x\n", nss_ctx, nss_runtime_samples.average); |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 145 | |
| 146 | nss_runtime_samples.message_rate_limit = 0; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 147 | } |
| 148 | |
| 149 | /* |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 150 | * Don't scale if we are not ready or auto scale is disabled. |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 151 | */ |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 152 | if ((nss_runtime_samples.freq_scale_ready != 1) || (nss_cmd_buf.auto_scale != 1)) { |
| 153 | return; |
| 154 | } |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 155 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 156 | /* |
| 157 | * Scale Algorithmn |
| 158 | * Algorithmn will limit how fast it will transition each scale, by the number of samples seen. |
| 159 | * If any sample is out of scale during the idle count, the rate_limit will reset to 0. |
| 160 | * Scales are limited to the max number of cpu scales we support. |
| 161 | */ |
| 162 | if (nss_runtime_samples.freq_scale_rate_limit_up++ >= NSS_FREQUENCY_SCALE_RATE_LIMIT_UP) { |
| 163 | maximum = nss_runtime_samples.freq_scale[index].maximum; |
Thomas Wu | 1fa2609 | 2016-03-30 14:10:03 -0700 | [diff] [blame] | 164 | if ((nss_runtime_samples.average > maximum) && (index < (NSS_FREQ_MAX_SCALE - 1))) { |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 165 | nss_runtime_samples.freq_scale_index++; |
| 166 | nss_runtime_samples.freq_scale_ready = 0; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 167 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 168 | /* |
| 169 | * If fail to increase frequency, decrease index |
| 170 | */ |
Thomas Wu | 4640e56 | 2015-06-10 10:23:04 -0700 | [diff] [blame] | 171 | nss_trace("frequency increase to %d inst:%x > maximum:%x\n", nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency, sample, maximum); |
Tanmay V Jagdale | f6b2bce | 2017-03-03 14:31:07 +0530 | [diff] [blame] | 172 | if (!nss_freq_queue_work()) { |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 173 | nss_runtime_samples.freq_scale_index--; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 174 | } |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 175 | } |
Thomas Wu | 4640e56 | 2015-06-10 10:23:04 -0700 | [diff] [blame] | 176 | |
| 177 | /* |
| 178 | * Reset the down scale counter based on running average, so can idle properlly |
| 179 | */ |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 180 | if (nss_runtime_samples.average > maximum) { |
Thomas Wu | 4640e56 | 2015-06-10 10:23:04 -0700 | [diff] [blame] | 181 | nss_trace("down scale timeout reset running average:%x\n", nss_runtime_samples.average); |
| 182 | nss_runtime_samples.freq_scale_rate_limit_down = 0; |
| 183 | } |
| 184 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 185 | nss_runtime_samples.freq_scale_rate_limit_up = 0; |
| 186 | return; |
| 187 | } |
| 188 | |
| 189 | if (nss_runtime_samples.freq_scale_rate_limit_down++ >= NSS_FREQUENCY_SCALE_RATE_LIMIT_DOWN) { |
| 190 | minimum = nss_runtime_samples.freq_scale[index].minimum; |
| 191 | if ((nss_runtime_samples.average < minimum) && (index > 0)) { |
| 192 | nss_runtime_samples.freq_scale_index--; |
| 193 | nss_runtime_samples.freq_scale_ready = 0; |
| 194 | |
| 195 | /* |
| 196 | * If fail to decrease frequency, increase index |
| 197 | */ |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 198 | nss_trace("frequency decrease to %d inst:%x < minumum:%x\n", nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency, nss_runtime_samples.average, minimum); |
Tanmay V Jagdale | f6b2bce | 2017-03-03 14:31:07 +0530 | [diff] [blame] | 199 | if (!nss_freq_queue_work()) { |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 200 | nss_runtime_samples.freq_scale_index++; |
| 201 | } |
| 202 | } |
| 203 | nss_runtime_samples.freq_scale_rate_limit_down = 0; |
| 204 | return; |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 205 | } |
| 206 | } |
| 207 | |
| 208 | /* |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 209 | * nss_freq_interface_handler() |
Thomas Wu | c07d870 | 2014-03-19 15:46:19 -0700 | [diff] [blame] | 210 | * Handle NSS -> HLOS messages for Frequency Changes and Statistics |
| 211 | */ |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 212 | static void nss_freq_interface_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data) { |
Thomas Wu | c07d870 | 2014-03-19 15:46:19 -0700 | [diff] [blame] | 213 | |
| 214 | struct nss_corefreq_msg *ncfm = (struct nss_corefreq_msg *)ncm; |
| 215 | |
Sachin Shashidhar | 6dd9cfc | 2018-07-31 14:44:37 -0700 | [diff] [blame] | 216 | /* |
| 217 | * Trace Messages |
| 218 | */ |
| 219 | nss_freq_log_rx_msg(ncfm); |
| 220 | |
Thomas Wu | 168ca26 | 2014-03-21 16:20:27 -0700 | [diff] [blame] | 221 | switch (ncfm->cm.type) { |
Thomas Wu | c07d870 | 2014-03-19 15:46:19 -0700 | [diff] [blame] | 222 | case COREFREQ_METADATA_TYPE_TX_FREQ_ACK: |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 223 | nss_freq_handle_ack(nss_ctx, &ncfm->msg.nfc); |
Thomas Wu | c07d870 | 2014-03-19 15:46:19 -0700 | [diff] [blame] | 224 | break; |
| 225 | case COREFREQ_METADATA_TYPE_TX_CORE_STATS: |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 226 | nss_freq_handle_core_stats(nss_ctx, &ncfm->msg.ncs); |
Thomas Wu | c07d870 | 2014-03-19 15:46:19 -0700 | [diff] [blame] | 227 | break; |
| 228 | |
| 229 | default: |
| 230 | if (ncm->response != NSS_CMN_RESPONSE_ACK) { |
| 231 | /* |
| 232 | * Check response |
| 233 | */ |
Thomas Wu | 6825035 | 2014-04-02 18:59:40 -0700 | [diff] [blame] | 234 | nss_info("%p: Received response %d for type %d, interface %d", nss_ctx, ncm->response, ncm->type, ncm->interface); |
Thomas Wu | c07d870 | 2014-03-19 15:46:19 -0700 | [diff] [blame] | 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | /* |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 240 | * nss_freq_change() |
| 241 | * NSS frequency change API. |
| 242 | */ |
| 243 | nss_tx_status_t nss_freq_change(struct nss_ctx_instance *nss_ctx, uint32_t eng, uint32_t stats_enable, uint32_t start_or_end) |
| 244 | { |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 245 | struct nss_corefreq_msg ncm; |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 246 | struct nss_freq_msg *nfc; |
| 247 | |
| 248 | nss_info("%p: frequency changing to: %d\n", nss_ctx, eng); |
| 249 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 250 | nss_freq_msg_init(&ncm, NSS_COREFREQ_INTERFACE, NSS_TX_METADATA_TYPE_NSS_FREQ_CHANGE, |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 251 | sizeof(struct nss_freq_msg), NULL, NULL); |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 252 | nfc = &ncm.msg.nfc; |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 253 | nfc->frequency = eng; |
| 254 | nfc->start_or_end = start_or_end; |
| 255 | nfc->stats_enable = stats_enable; |
| 256 | |
Stephen Wang | 3e2dbd1 | 2018-03-14 17:28:17 -0700 | [diff] [blame] | 257 | return nss_core_send_cmd(nss_ctx, &ncm, sizeof(ncm), NSS_NBUF_PAYLOAD_SIZE); |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | /* |
| 261 | * nss_freq_sched_change() |
| 262 | * schedule a frequency work |
| 263 | */ |
Tanmay V Jagdale | f6b2bce | 2017-03-03 14:31:07 +0530 | [diff] [blame] | 264 | bool nss_freq_sched_change(nss_freq_scales_t index, bool auto_scale) |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 265 | { |
| 266 | if (index >= NSS_FREQ_MAX_SCALE) { |
| 267 | nss_info("NSS freq scale beyond limit\n"); |
Tanmay V Jagdale | f6b2bce | 2017-03-03 14:31:07 +0530 | [diff] [blame] | 268 | return false; |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC); |
| 272 | if (!nss_work) { |
| 273 | nss_info("NSS Freq WQ kmalloc fail"); |
Tanmay V Jagdale | f6b2bce | 2017-03-03 14:31:07 +0530 | [diff] [blame] | 274 | return false; |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 275 | } |
| 276 | |
Thomas Wu | d6af377 | 2017-09-01 13:42:28 -0700 | [diff] [blame] | 277 | INIT_WORK((struct work_struct *)nss_work, nss_hal_wq_function); |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 278 | |
| 279 | nss_work->frequency = nss_runtime_samples.freq_scale[index].frequency; |
| 280 | |
| 281 | nss_work->stats_enable = auto_scale; |
| 282 | nss_cmd_buf.current_freq = nss_work->frequency; |
| 283 | queue_work(nss_wq, (struct work_struct *)nss_work); |
Tanmay V Jagdale | f6b2bce | 2017-03-03 14:31:07 +0530 | [diff] [blame] | 284 | |
| 285 | return true; |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | /* |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 289 | * nss_freq_get_context() |
| 290 | * get NSS context instance for frequency |
| 291 | */ |
| 292 | struct nss_ctx_instance *nss_freq_get_context(void) |
| 293 | { |
| 294 | return (struct nss_ctx_instance *)&nss_top_main.nss[nss_top_main.frequency_handler_id]; |
| 295 | } |
| 296 | EXPORT_SYMBOL(nss_freq_get_context); |
| 297 | |
| 298 | /* |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 299 | * nss_freq_register_handler() |
Thomas Wu | c07d870 | 2014-03-19 15:46:19 -0700 | [diff] [blame] | 300 | */ |
Sundarajan Srinivasan | dedd8e4 | 2014-10-06 11:59:34 -0700 | [diff] [blame] | 301 | void nss_freq_register_handler(void) |
Thomas Wu | c07d870 | 2014-03-19 15:46:19 -0700 | [diff] [blame] | 302 | { |
Thomas Wu | 91f4bdf | 2017-06-09 12:03:02 -0700 | [diff] [blame] | 303 | struct nss_ctx_instance *nss_ctx = nss_freq_get_context(); |
| 304 | |
| 305 | nss_core_register_handler(nss_ctx, NSS_COREFREQ_INTERFACE, nss_freq_interface_handler, NULL); |
Thomas Wu | c07d870 | 2014-03-19 15:46:19 -0700 | [diff] [blame] | 306 | } |