Radhakrishna Jiguru | 1c9b225 | 2013-08-27 23:57:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Stephen Wang | a428d0b | 2017-01-12 21:30:01 -0800 | [diff] [blame] | 3 | * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved. |
Radhakrishna Jiguru | 1c9b225 | 2013-08-27 23:57:48 +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 | */ |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 16 | |
| 17 | /* |
| 18 | * nss_init.c |
| 19 | * NSS init APIs |
| 20 | * |
| 21 | */ |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 22 | #include "nss_core.h" |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 23 | #if (NSS_PM_SUPPORT == 1) |
Pamidipati, Vijay | 7f413b5 | 2013-09-24 19:07:12 +0530 | [diff] [blame] | 24 | #include "nss_pm.h" |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 25 | #endif |
Abhishek Rastogi | 9da4747 | 2014-03-18 19:46:15 +0530 | [diff] [blame] | 26 | #include "nss_tx_rx_common.h" |
Stephen Wang | 38e89bc | 2014-11-06 11:34:45 -0800 | [diff] [blame] | 27 | #include "nss_data_plane.h" |
Stephen Wang | 1f6ad49 | 2016-01-27 23:42:06 -0800 | [diff] [blame] | 28 | #include "nss_capwap.h" |
Pamidipati, Vijay | 7f413b5 | 2013-09-24 19:07:12 +0530 | [diff] [blame] | 29 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 30 | #include <nss_hal.h> |
| 31 | |
| 32 | #include <linux/module.h> |
| 33 | #include <linux/platform_device.h> |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 34 | #include <linux/proc_fs.h> |
| 35 | #include <linux/device.h> |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 36 | |
| 37 | #if (NSS_DT_SUPPORT == 1) |
Stephen Wang | 463f1cf | 2016-03-29 15:25:51 -0700 | [diff] [blame] | 38 | #if (NSS_FABRIC_SCALING_SUPPORT == 1) |
Stephen Wang | 8ffd17f | 2016-03-07 14:03:40 -0800 | [diff] [blame] | 39 | #include <linux/fab_scaling.h> |
Stephen Wang | 1017ad1 | 2016-03-14 10:18:06 -0700 | [diff] [blame] | 40 | #endif |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 41 | #include <linux/of.h> |
| 42 | #include <linux/of_net.h> |
| 43 | #include <linux/of_irq.h> |
| 44 | #include <linux/of_address.h> |
| 45 | #include <linux/reset.h> |
| 46 | #else |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 47 | #include <mach/msm_nss.h> |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 48 | #endif |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 49 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 50 | #include <linux/sysctl.h> |
| 51 | #include <linux/regulator/consumer.h> |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 52 | #include <linux/clk.h> |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 53 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 54 | /* |
| 55 | * Global declarations |
| 56 | */ |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 57 | int nss_ctl_redirect __read_mostly = 0; |
Sakthi Vignesh Radhakrishnan | af39aad | 2014-03-31 11:31:03 -0700 | [diff] [blame] | 58 | int nss_ctl_debug __read_mostly = 0; |
Saurabh Misra | 96998db | 2014-07-10 12:15:48 -0700 | [diff] [blame] | 59 | int nss_ctl_logbuf __read_mostly = 0; |
Sundarajan Srinivasan | f9c4a23 | 2014-11-18 13:25:40 -0800 | [diff] [blame] | 60 | int nss_jumbo_mru __read_mostly = 0; |
| 61 | int nss_paged_mode __read_mostly = 0; |
Radha krishna Simha Jiguru | 28a0a25 | 2015-08-04 16:34:09 +0530 | [diff] [blame] | 62 | int nss_skip_nw_process = 0x0; |
| 63 | module_param(nss_skip_nw_process, int, S_IRUGO); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 64 | |
| 65 | /* |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 66 | * PM client handle |
| 67 | */ |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 68 | #if (NSS_PM_SUPPORT == 1) |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 69 | static void *pm_client; |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 70 | #endif |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 71 | |
| 72 | /* |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 73 | * Handler to send NSS messages |
| 74 | */ |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 75 | struct clk *nss_core0_clk; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 76 | |
| 77 | /* |
Thomas Wu | cd6b35a | 2015-07-14 10:17:48 -0700 | [diff] [blame] | 78 | * Handle fabric requests - only on new kernel |
| 79 | */ |
| 80 | #if (NSS_DT_SUPPORT == 1) |
| 81 | struct clk *nss_fab0_clk; |
| 82 | struct clk *nss_fab1_clk; |
Samarjeet Banerjee | 69731a2 | 2016-07-21 13:04:59 +0530 | [diff] [blame] | 83 | bool nss_crypto_is_scaled = false; |
Thomas Wu | cd6b35a | 2015-07-14 10:17:48 -0700 | [diff] [blame] | 84 | #endif |
| 85 | |
| 86 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 87 | * Top level nss context structure |
| 88 | */ |
| 89 | struct nss_top_instance nss_top_main; |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 90 | struct nss_cmd_buffer nss_cmd_buf; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 91 | struct nss_runtime_sampling nss_runtime_samples; |
| 92 | struct workqueue_struct *nss_wq; |
| 93 | |
| 94 | /* |
| 95 | * Work Queue to handle messages to Kernel |
| 96 | */ |
| 97 | nss_work_t *nss_work; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 98 | |
Arunkumar T | 79990cb | 2015-06-05 10:53:16 +0530 | [diff] [blame] | 99 | extern struct of_device_id nss_dt_ids[]; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 100 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 101 | /* |
| 102 | * nss_probe() |
Arunkumar T | 79990cb | 2015-06-05 10:53:16 +0530 | [diff] [blame] | 103 | * HLOS device probe callback |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 104 | */ |
Ram Chandra Jangir | 6577f38 | 2016-05-31 12:16:28 +0530 | [diff] [blame] | 105 | static inline int nss_probe(struct platform_device *nss_dev) |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 106 | { |
Arunkumar T | 79990cb | 2015-06-05 10:53:16 +0530 | [diff] [blame] | 107 | return nss_hal_probe(nss_dev); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 108 | } |
| 109 | |
| 110 | /* |
| 111 | * nss_remove() |
Arunkumar T | 79990cb | 2015-06-05 10:53:16 +0530 | [diff] [blame] | 112 | * HLOS device remove callback |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 113 | */ |
Ram Chandra Jangir | 6577f38 | 2016-05-31 12:16:28 +0530 | [diff] [blame] | 114 | static inline int nss_remove(struct platform_device *nss_dev) |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 115 | { |
Arunkumar T | 79990cb | 2015-06-05 10:53:16 +0530 | [diff] [blame] | 116 | return nss_hal_remove(nss_dev); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 117 | } |
| 118 | |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 119 | #if (NSS_DT_SUPPORT == 1) |
| 120 | /* |
| 121 | * Platform Device ID for NSS core. |
| 122 | */ |
| 123 | struct of_device_id nss_dt_ids[] = { |
| 124 | { .compatible = "qcom,nss" }, |
| 125 | { .compatible = "qcom,nss0" }, |
| 126 | { .compatible = "qcom,nss1" }, |
| 127 | {}, |
| 128 | }; |
| 129 | MODULE_DEVICE_TABLE(of, nss_dt_ids); |
| 130 | #endif |
| 131 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 132 | /* |
| 133 | * nss_driver |
| 134 | * Platform driver structure for NSS |
| 135 | */ |
| 136 | struct platform_driver nss_driver = { |
| 137 | .probe = nss_probe, |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 138 | .remove = nss_remove, |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 139 | .driver = { |
| 140 | .name = "qca-nss", |
| 141 | .owner = THIS_MODULE, |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 142 | #if (NSS_DT_SUPPORT == 1) |
| 143 | .of_match_table = of_match_ptr(nss_dt_ids), |
| 144 | #endif |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 145 | }, |
| 146 | }; |
| 147 | |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 148 | #if (NSS_FREQ_SCALE_SUPPORT == 1) |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 149 | /* |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 150 | * nss_reset_frequency_stats_samples() |
| 151 | * Reset all frequency sampling state when auto scaling is turned off. |
| 152 | */ |
| 153 | static void nss_reset_frequency_stats_samples (void) |
| 154 | { |
| 155 | nss_runtime_samples.buffer_index = 0; |
| 156 | nss_runtime_samples.sum = 0; |
| 157 | nss_runtime_samples.average = 0; |
| 158 | nss_runtime_samples.sample_count = 0; |
| 159 | nss_runtime_samples.message_rate_limit = 0; |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 160 | nss_runtime_samples.freq_scale_rate_limit_down = 0; |
| 161 | } |
| 162 | |
| 163 | /* |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 164 | *************************************************************************************************** |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 165 | * nss_wq_function() is used to queue up requests to change NSS frequencies. |
| 166 | * The function will take care of NSS notices and also control clock. |
| 167 | * The auto rate algorithmn will queue up requests or the procfs may also queue up these requests. |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 168 | *************************************************************************************************** |
| 169 | */ |
| 170 | |
| 171 | /* |
| 172 | * nss_wq_function() |
| 173 | * Added to Handle BH requests to kernel |
| 174 | */ |
| 175 | void nss_wq_function (struct work_struct *work) |
| 176 | { |
| 177 | nss_work_t *my_work = (nss_work_t *)work; |
Vijay Vigneshan | a94c265 | 2016-06-02 12:39:35 +0530 | [diff] [blame] | 178 | #if (NSS_DT_SUPPORT == 1) |
| 179 | nss_crypto_pm_event_callback_t crypto_pm_cb; |
Samarjeet Banerjee | 69731a2 | 2016-07-21 13:04:59 +0530 | [diff] [blame] | 180 | bool auto_scale; |
| 181 | bool turbo; |
| 182 | |
c_athand | fde2e91 | 2017-01-10 15:40:12 +0530 | [diff] [blame] | 183 | mutex_lock(&nss_top_main.wq_lock); |
Samarjeet Banerjee | 69731a2 | 2016-07-21 13:04:59 +0530 | [diff] [blame] | 184 | /* |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 185 | * If crypto clock is in Turbo, disable scaling for other |
| 186 | * NSS subsystem components and retain them at turbo |
Samarjeet Banerjee | 69731a2 | 2016-07-21 13:04:59 +0530 | [diff] [blame] | 187 | */ |
| 188 | if (nss_crypto_is_scaled) { |
Samarjeet Banerjee | b126e0f | 2016-08-05 20:58:27 +0530 | [diff] [blame] | 189 | nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[NSS_FREQ_HIGH_SCALE].frequency; |
c_athand | fde2e91 | 2017-01-10 15:40:12 +0530 | [diff] [blame] | 190 | mutex_unlock(&nss_top_main.wq_lock); |
Samarjeet Banerjee | 69731a2 | 2016-07-21 13:04:59 +0530 | [diff] [blame] | 191 | return; |
| 192 | } |
Vijay Vigneshan | a94c265 | 2016-06-02 12:39:35 +0530 | [diff] [blame] | 193 | #endif |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 194 | |
Guojun Jin | 32a3c6d | 2015-05-06 12:27:52 -0700 | [diff] [blame] | 195 | nss_freq_change(&nss_top_main.nss[NSS_CORE_0], my_work->frequency, my_work->stats_enable, 0); |
Guojun Jin | 9d78281 | 2015-05-12 14:01:25 -0700 | [diff] [blame] | 196 | if (nss_top_main.nss[NSS_CORE_1].state == NSS_CORE_STATE_INITIALIZED) { |
| 197 | nss_freq_change(&nss_top_main.nss[NSS_CORE_1], my_work->frequency, my_work->stats_enable, 0); |
| 198 | } |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 199 | clk_set_rate(nss_core0_clk, my_work->frequency); |
Guojun Jin | 32a3c6d | 2015-05-06 12:27:52 -0700 | [diff] [blame] | 200 | nss_freq_change(&nss_top_main.nss[NSS_CORE_0], my_work->frequency, my_work->stats_enable, 1); |
Guojun Jin | 9d78281 | 2015-05-12 14:01:25 -0700 | [diff] [blame] | 201 | if (nss_top_main.nss[NSS_CORE_1].state == NSS_CORE_STATE_INITIALIZED) { |
| 202 | nss_freq_change(&nss_top_main.nss[NSS_CORE_1], my_work->frequency, my_work->stats_enable, 1); |
| 203 | } |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 204 | |
Thomas Wu | cd6b35a | 2015-07-14 10:17:48 -0700 | [diff] [blame] | 205 | /* |
| 206 | * If we are running NSS_PM_SUPPORT, we are on banana |
| 207 | * otherwise, we check if we are are on new kernel by checking if the |
| 208 | * fabric lookups are not NULL (success in init())) |
| 209 | */ |
Thomas Wu | 0d11219 | 2015-04-13 11:37:22 -0700 | [diff] [blame] | 210 | #if (NSS_PM_SUPPORT == 1) |
Thomas Wu | cd6b35a | 2015-07-14 10:17:48 -0700 | [diff] [blame] | 211 | if (!pm_client) { |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 212 | goto out; |
| 213 | } |
| 214 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 215 | if (my_work->frequency >= NSS_FREQ_733) { |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 216 | nss_pm_set_perf_level(pm_client, NSS_PM_PERF_LEVEL_TURBO); |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 217 | } else if (my_work->frequency > NSS_FREQ_110) { |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 218 | nss_pm_set_perf_level(pm_client, NSS_PM_PERF_LEVEL_NOMINAL); |
| 219 | } else { |
| 220 | nss_pm_set_perf_level(pm_client, NSS_PM_PERF_LEVEL_IDLE); |
| 221 | } |
Thomas Wu | 0d11219 | 2015-04-13 11:37:22 -0700 | [diff] [blame] | 222 | |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 223 | out: |
Thomas Wu | cd6b35a | 2015-07-14 10:17:48 -0700 | [diff] [blame] | 224 | #else |
| 225 | #if (NSS_DT_SUPPORT == 1) |
Stephen Wang | 463f1cf | 2016-03-29 15:25:51 -0700 | [diff] [blame] | 226 | #if (NSS_FABRIC_SCALING_SUPPORT == 1) |
Stephen Wang | 8ffd17f | 2016-03-07 14:03:40 -0800 | [diff] [blame] | 227 | scale_fabrics(); |
Stephen Wang | 1017ad1 | 2016-03-14 10:18:06 -0700 | [diff] [blame] | 228 | #endif |
Samarjeet Banerjee | 69731a2 | 2016-07-21 13:04:59 +0530 | [diff] [blame] | 229 | if ((nss_fab0_clk != NULL) && (nss_fab1_clk != NULL)) { |
Thomas Wu | cd6b35a | 2015-07-14 10:17:48 -0700 | [diff] [blame] | 230 | if (my_work->frequency >= NSS_FREQ_733) { |
| 231 | clk_set_rate(nss_fab0_clk, NSS_FABRIC0_TURBO); |
| 232 | clk_set_rate(nss_fab1_clk, NSS_FABRIC1_TURBO); |
| 233 | } else if (my_work->frequency > NSS_FREQ_110) { |
| 234 | clk_set_rate(nss_fab0_clk, NSS_FABRIC0_NOMINAL); |
| 235 | clk_set_rate(nss_fab1_clk, NSS_FABRIC1_NOMINAL); |
| 236 | } else { |
| 237 | clk_set_rate(nss_fab0_clk, NSS_FABRIC0_IDLE); |
| 238 | clk_set_rate(nss_fab1_clk, NSS_FABRIC1_IDLE); |
| 239 | } |
Samarjeet Banerjee | cdfc0bd | 2016-05-28 00:22:31 +0530 | [diff] [blame] | 240 | |
| 241 | /* |
| 242 | * notify crypto about the clock change |
| 243 | */ |
| 244 | crypto_pm_cb = nss_top_main.crypto_pm_callback; |
| 245 | if (crypto_pm_cb) { |
| 246 | turbo = (my_work->frequency >= NSS_FREQ_733); |
Samarjeet Banerjee | 69731a2 | 2016-07-21 13:04:59 +0530 | [diff] [blame] | 247 | auto_scale = nss_cmd_buf.auto_scale; |
| 248 | nss_crypto_is_scaled = crypto_pm_cb(nss_top_main.crypto_pm_ctx, turbo, auto_scale); |
Samarjeet Banerjee | cdfc0bd | 2016-05-28 00:22:31 +0530 | [diff] [blame] | 249 | } |
Thomas Wu | cd6b35a | 2015-07-14 10:17:48 -0700 | [diff] [blame] | 250 | } |
| 251 | #endif |
Thomas Wu | 0d11219 | 2015-04-13 11:37:22 -0700 | [diff] [blame] | 252 | #endif |
c_athand | fde2e91 | 2017-01-10 15:40:12 +0530 | [diff] [blame] | 253 | mutex_unlock(&nss_top_main.wq_lock); |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 254 | kfree((void *)work); |
| 255 | } |
| 256 | |
| 257 | /* |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 258 | * nss_current_freq_handler() |
| 259 | * Handle Userspace Frequency Change Requests |
| 260 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 261 | static int nss_current_freq_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 262 | { |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 263 | int ret, i; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 264 | |
| 265 | BUG_ON(!nss_wq); |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 266 | |
| 267 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 268 | |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 269 | if (!*lenp || (*ppos && !write)) { |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 270 | printk("Frequency Set to %d\n", nss_cmd_buf.current_freq); |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 271 | *lenp = 0; |
wthomas | d39fa82 | 2013-08-22 16:44:23 -0700 | [diff] [blame] | 272 | return ret; |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 273 | } |
wthomas | d39fa82 | 2013-08-22 16:44:23 -0700 | [diff] [blame] | 274 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 275 | /* |
| 276 | * Check if frequency exists in frequency Table |
| 277 | */ |
| 278 | i = 0; |
Thomas Wu | 7132bd3 | 2015-05-07 15:03:06 -0700 | [diff] [blame] | 279 | while (i < NSS_FREQ_MAX_SCALE) { |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 280 | if (nss_runtime_samples.freq_scale[i].frequency == nss_cmd_buf.current_freq) { |
| 281 | break; |
| 282 | } |
| 283 | i++; |
| 284 | } |
Thomas Wu | 7132bd3 | 2015-05-07 15:03:06 -0700 | [diff] [blame] | 285 | if (i == NSS_FREQ_MAX_SCALE) { |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 286 | printk("Frequency not found. Please check Frequency Table\n"); |
Thomas Wu | b7683af | 2016-07-07 14:19:09 -0700 | [diff] [blame] | 287 | nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 288 | return ret; |
wthomas | d39fa82 | 2013-08-22 16:44:23 -0700 | [diff] [blame] | 289 | } |
| 290 | |
Thomas Wu | b7683af | 2016-07-07 14:19:09 -0700 | [diff] [blame] | 291 | /* |
| 292 | * Turn off Auto Scale |
| 293 | */ |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 294 | nss_cmd_buf.auto_scale = 0; |
| 295 | nss_runtime_samples.freq_scale_ready = 0; |
Thomas Wu | b7683af | 2016-07-07 14:19:09 -0700 | [diff] [blame] | 296 | nss_runtime_samples.freq_scale_index = i; |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 297 | |
Thomas Wu | 7409bce | 2014-05-21 10:56:07 -0700 | [diff] [blame] | 298 | nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC); |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 299 | if (!nss_work) { |
| 300 | nss_info("NSS Freq WQ kmalloc fail"); |
| 301 | return ret; |
| 302 | } |
| 303 | INIT_WORK((struct work_struct *)nss_work, nss_wq_function); |
| 304 | nss_work->frequency = nss_cmd_buf.current_freq; |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 305 | nss_work->stats_enable = 0; |
| 306 | |
Thomas Wu | b7683af | 2016-07-07 14:19:09 -0700 | [diff] [blame] | 307 | /* |
| 308 | * Ensure we start with a fresh set of samples later |
| 309 | */ |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 310 | nss_reset_frequency_stats_samples(); |
| 311 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 312 | queue_work(nss_wq, (struct work_struct *)nss_work); |
| 313 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 314 | return ret; |
| 315 | } |
| 316 | |
| 317 | /* |
| 318 | * nss_auto_scale_handler() |
| 319 | * Enables or Disable Auto Scaling |
| 320 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 321 | static int nss_auto_scale_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 322 | { |
| 323 | int ret; |
| 324 | |
| 325 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 326 | |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 327 | if (!*lenp || (*ppos && !write)) { |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 328 | return ret; |
| 329 | } |
| 330 | |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 331 | if (nss_cmd_buf.auto_scale != 1) { |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 332 | /* |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 333 | * Is auto scaling currently enabled? If so, send the command to |
| 334 | * disable stats reporting to NSS |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 335 | */ |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 336 | if (nss_runtime_samples.freq_scale_ready != 0) { |
| 337 | nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency; |
Thomas Wu | 7409bce | 2014-05-21 10:56:07 -0700 | [diff] [blame] | 338 | nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC); |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 339 | if (!nss_work) { |
| 340 | nss_info("NSS Freq WQ kmalloc fail"); |
| 341 | return ret; |
| 342 | } |
| 343 | INIT_WORK((struct work_struct *)nss_work, nss_wq_function); |
| 344 | nss_work->frequency = nss_cmd_buf.current_freq; |
| 345 | nss_work->stats_enable = 0; |
| 346 | queue_work(nss_wq, (struct work_struct *)nss_work); |
| 347 | nss_runtime_samples.freq_scale_ready = 0; |
| 348 | |
| 349 | /* |
| 350 | * The current samples would be stale later when scaling is |
| 351 | * enabled again, hence reset them |
| 352 | */ |
| 353 | nss_reset_frequency_stats_samples(); |
| 354 | } |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 355 | return ret; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 356 | } |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 357 | |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 358 | /* |
| 359 | * Auto Scaling is already being done |
| 360 | */ |
| 361 | if (nss_runtime_samples.freq_scale_ready == 1) { |
| 362 | return ret; |
| 363 | } |
| 364 | |
| 365 | /* |
| 366 | * Setup default values - Middle of Freq Scale Band |
| 367 | */ |
| 368 | nss_runtime_samples.freq_scale_index = 1; |
| 369 | nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency; |
| 370 | |
Thomas Wu | 7409bce | 2014-05-21 10:56:07 -0700 | [diff] [blame] | 371 | nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC); |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 372 | if (!nss_work) { |
| 373 | nss_info("NSS Freq WQ kmalloc fail"); |
| 374 | return ret; |
| 375 | } |
| 376 | INIT_WORK((struct work_struct *)nss_work, nss_wq_function); |
| 377 | nss_work->frequency = nss_cmd_buf.current_freq; |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 378 | nss_work->stats_enable = 1; |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 379 | queue_work(nss_wq, (struct work_struct *)nss_work); |
| 380 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 381 | nss_cmd_buf.auto_scale = 0; |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 382 | nss_runtime_samples.freq_scale_ready = 1; |
| 383 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 384 | return ret; |
| 385 | } |
| 386 | |
| 387 | /* |
| 388 | * nss_get_freq_table_handler() |
| 389 | * Display Support Freq and Ex how to Change. |
| 390 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 391 | static int nss_get_freq_table_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 392 | { |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 393 | int ret, i; |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 394 | |
| 395 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 396 | |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 397 | if (write) { |
| 398 | return ret; |
| 399 | } |
| 400 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 401 | printk("Frequency Supported - "); |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 402 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 403 | i = 0; |
Thomas Wu | 7132bd3 | 2015-05-07 15:03:06 -0700 | [diff] [blame] | 404 | while (i < NSS_FREQ_MAX_SCALE) { |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 405 | printk("%dMhz ", nss_runtime_samples.freq_scale[i].frequency/1000000); |
| 406 | i++; |
Thomas Wu | 0a0a9c9 | 2013-11-21 15:28:19 -0800 | [diff] [blame] | 407 | } |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 408 | printk("\n"); |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 409 | |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 410 | *lenp = 0; |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 411 | return ret; |
| 412 | } |
| 413 | |
| 414 | /* |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 415 | * nss_get_average_inst_handler() |
| 416 | * Display AVG Inst Per Ms. |
| 417 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 418 | static int nss_get_average_inst_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 419 | { |
| 420 | int ret; |
| 421 | |
| 422 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 423 | |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 424 | if (write) { |
| 425 | return ret; |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 426 | } |
| 427 | |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 428 | printk("Current Inst Per Ms %x\n", nss_runtime_samples.average); |
| 429 | |
| 430 | *lenp = 0; |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 431 | return ret; |
| 432 | } |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 433 | #endif |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 434 | |
Sundarajan Srinivasan | 758e8f4 | 2014-12-08 14:56:24 -0800 | [diff] [blame] | 435 | #if (NSS_FW_DBG_SUPPORT == 1) |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 436 | /* |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 437 | * nss_debug_handler() |
| 438 | * Enable NSS debug output |
| 439 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 440 | static int nss_debug_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 441 | { |
| 442 | int ret; |
| 443 | |
| 444 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 445 | if (!ret) { |
| 446 | if ((write) && (nss_ctl_debug != 0)) { |
| 447 | printk("Enabling NSS SPI Debug\n"); |
| 448 | nss_hal_debug_enable(); |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | return ret; |
| 453 | } |
Sundarajan Srinivasan | 758e8f4 | 2014-12-08 14:56:24 -0800 | [diff] [blame] | 454 | #endif |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 455 | |
| 456 | /* |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 457 | * nss_coredump_handler() |
| 458 | * Send Signal To Coredump NSS Cores |
| 459 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 460 | static int nss_coredump_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 461 | { |
Guojun Jin | 32a3c6d | 2015-05-06 12:27:52 -0700 | [diff] [blame] | 462 | struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[NSS_CORE_0]; |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 463 | int ret; |
| 464 | |
| 465 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 466 | if (!ret) { |
Guojun Jin | 244ecab | 2017-03-16 16:04:25 -0700 | [diff] [blame] | 467 | /* |
| 468 | * if nss_cmd_buf.coredump is not 0 or 1, panic will be disabled |
| 469 | * when NSS FW crashes, so OEM/ODM have a chance to use mdump |
| 470 | * to dump crash dump (coredump) and send dump to us for analysis. |
| 471 | */ |
| 472 | if ((write) && (nss_ctl_debug != 0) && nss_cmd_buf.coredump == 1) { |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 473 | printk("Coredumping to DDR\n"); |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 474 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_TRIGGER_COREDUMP); |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
| 478 | return ret; |
| 479 | } |
| 480 | |
| 481 | /* |
Sundarajan Srinivasan | f9c4a23 | 2014-11-18 13:25:40 -0800 | [diff] [blame] | 482 | * nss_jumbo_mru_handler() |
| 483 | * Sysctl to modify nss_jumbo_mru |
| 484 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 485 | static int nss_jumbo_mru_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Sundarajan Srinivasan | f9c4a23 | 2014-11-18 13:25:40 -0800 | [diff] [blame] | 486 | { |
| 487 | int ret; |
| 488 | |
| 489 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 490 | if (ret) { |
| 491 | return ret; |
| 492 | } |
| 493 | |
| 494 | if (write) { |
| 495 | nss_core_set_jumbo_mru(nss_jumbo_mru); |
| 496 | nss_info("jumbo_mru set to %d\n", nss_jumbo_mru); |
| 497 | } |
| 498 | |
| 499 | return ret; |
| 500 | } |
| 501 | |
| 502 | /* nss_paged_mode_handler() |
| 503 | * Sysctl to modify nss_paged_mode. |
| 504 | */ |
| 505 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 506 | static int nss_paged_mode_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
Sundarajan Srinivasan | f9c4a23 | 2014-11-18 13:25:40 -0800 | [diff] [blame] | 507 | { |
| 508 | int ret; |
| 509 | |
| 510 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 511 | if (ret) { |
| 512 | return ret; |
| 513 | } |
| 514 | |
| 515 | if (write) { |
| 516 | nss_core_set_paged_mode(nss_paged_mode); |
| 517 | nss_info("paged_mode set to %d\n", nss_paged_mode); |
| 518 | } |
| 519 | |
| 520 | return ret; |
| 521 | } |
| 522 | |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 523 | #if (NSS_FREQ_SCALE_SUPPORT == 1) |
Sundarajan Srinivasan | f9c4a23 | 2014-11-18 13:25:40 -0800 | [diff] [blame] | 524 | /* |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 525 | * sysctl-tuning infrastructure. |
| 526 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 527 | static struct ctl_table nss_freq_table[] = { |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 528 | { |
| 529 | .procname = "current_freq", |
| 530 | .data = &nss_cmd_buf.current_freq, |
| 531 | .maxlen = sizeof(int), |
| 532 | .mode = 0644, |
| 533 | .proc_handler = &nss_current_freq_handler, |
| 534 | }, |
| 535 | { |
| 536 | .procname = "freq_table", |
| 537 | .data = &nss_cmd_buf.max_freq, |
| 538 | .maxlen = sizeof(int), |
| 539 | .mode = 0644, |
| 540 | .proc_handler = &nss_get_freq_table_handler, |
| 541 | }, |
| 542 | { |
| 543 | .procname = "auto_scale", |
| 544 | .data = &nss_cmd_buf.auto_scale, |
| 545 | .maxlen = sizeof(int), |
| 546 | .mode = 0644, |
| 547 | .proc_handler = &nss_auto_scale_handler, |
| 548 | }, |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 549 | { |
| 550 | .procname = "inst_per_sec", |
| 551 | .data = &nss_cmd_buf.average_inst, |
| 552 | .maxlen = sizeof(int), |
| 553 | .mode = 0644, |
| 554 | .proc_handler = &nss_get_average_inst_handler, |
| 555 | }, |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 556 | { } |
| 557 | }; |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 558 | #endif |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 559 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 560 | static struct ctl_table nss_general_table[] = { |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 561 | { |
| 562 | .procname = "redirect", |
| 563 | .data = &nss_ctl_redirect, |
| 564 | .maxlen = sizeof(int), |
| 565 | .mode = 0644, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 566 | .proc_handler = proc_dointvec, |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 567 | }, |
Sundarajan Srinivasan | 758e8f4 | 2014-12-08 14:56:24 -0800 | [diff] [blame] | 568 | #if (NSS_FW_DBG_SUPPORT == 1) |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 569 | { |
| 570 | .procname = "debug", |
| 571 | .data = &nss_ctl_debug, |
| 572 | .maxlen = sizeof(int), |
| 573 | .mode = 0644, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 574 | .proc_handler = &nss_debug_handler, |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 575 | }, |
Sundarajan Srinivasan | 758e8f4 | 2014-12-08 14:56:24 -0800 | [diff] [blame] | 576 | #endif |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 577 | { |
| 578 | .procname = "coredump", |
| 579 | .data = &nss_cmd_buf.coredump, |
| 580 | .maxlen = sizeof(int), |
| 581 | .mode = 0644, |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 582 | .proc_handler = &nss_coredump_handler, |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 583 | }, |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 584 | { |
Saurabh Misra | 96998db | 2014-07-10 12:15:48 -0700 | [diff] [blame] | 585 | .procname = "logbuf", |
| 586 | .data = &nss_ctl_logbuf, |
| 587 | .maxlen = sizeof(int), |
| 588 | .mode = 0644, |
| 589 | .proc_handler = &nss_logbuffer_handler, |
| 590 | }, |
Sundarajan Srinivasan | f9c4a23 | 2014-11-18 13:25:40 -0800 | [diff] [blame] | 591 | { |
| 592 | .procname = "jumbo_mru", |
| 593 | .data = &nss_jumbo_mru, |
| 594 | .maxlen = sizeof(int), |
| 595 | .mode = 0644, |
| 596 | .proc_handler = &nss_jumbo_mru_handler, |
| 597 | }, |
| 598 | { |
| 599 | .procname = "paged_mode", |
| 600 | .data = &nss_paged_mode, |
| 601 | .maxlen = sizeof(int), |
| 602 | .mode = 0644, |
| 603 | .proc_handler = &nss_paged_mode_handler, |
| 604 | }, |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 605 | { } |
| 606 | }; |
| 607 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 608 | static struct ctl_table nss_clock_dir[] = { |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 609 | #if (NSS_FREQ_SCALE_SUPPORT == 1) |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 610 | { |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 611 | .procname = "clock", |
| 612 | .mode = 0555, |
| 613 | .child = nss_freq_table, |
| 614 | }, |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 615 | #endif |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 616 | { |
| 617 | .procname = "general", |
| 618 | .mode = 0555, |
| 619 | .child = nss_general_table, |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 620 | }, |
| 621 | { } |
| 622 | }; |
| 623 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 624 | static struct ctl_table nss_root_dir[] = { |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 625 | { |
| 626 | .procname = "nss", |
| 627 | .mode = 0555, |
| 628 | .child = nss_clock_dir, |
| 629 | }, |
| 630 | { } |
| 631 | }; |
| 632 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 633 | static struct ctl_table nss_root[] = { |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 634 | { |
| 635 | .procname = "dev", |
| 636 | .mode = 0555, |
| 637 | .child = nss_root_dir, |
| 638 | }, |
| 639 | { } |
| 640 | }; |
| 641 | |
| 642 | static struct ctl_table_header *nss_dev_header; |
| 643 | |
| 644 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 645 | * nss_init() |
| 646 | * Registers nss driver |
| 647 | */ |
| 648 | static int __init nss_init(void) |
| 649 | { |
Radha krishna Simha Jiguru | 3295b8b | 2017-03-12 10:54:15 +0530 | [diff] [blame] | 650 | #if (NSS_DT_SUPPORT == 1) |
| 651 | struct device_node *cmn = NULL; |
| 652 | #endif |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 653 | nss_info("Init NSS driver"); |
| 654 | |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 655 | #if (NSS_DT_SUPPORT == 1) |
| 656 | /* |
Radha krishna Simha Jiguru | 3295b8b | 2017-03-12 10:54:15 +0530 | [diff] [blame] | 657 | * Get reference to NSS common device node |
| 658 | */ |
| 659 | cmn = of_find_node_by_name(NULL, "nss-common"); |
| 660 | if (!cmn) { |
| 661 | nss_info_always("qca-nss-drv.ko is loaded for symbol link\n"); |
| 662 | return 0; |
| 663 | } |
| 664 | of_node_put(cmn); |
| 665 | |
| 666 | /* |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 667 | * Pick up HAL by target information |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 668 | */ |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 669 | #if defined(NSS_HAL_IPQ806X_SUPPORT) |
| 670 | if (of_machine_is_compatible("qcom,ipq8064") || of_machine_is_compatible("qcom,ipq8062")) { |
| 671 | nss_top_main.hal_ops = &nss_hal_ipq806x_ops; |
Stephen Wang | 5901def | 2016-05-09 16:21:03 -0700 | [diff] [blame] | 672 | nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops; |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 673 | } |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 674 | #endif |
Stephen Wang | be34802 | 2016-05-02 17:11:34 -0700 | [diff] [blame] | 675 | #if defined(NSS_HAL_IPQ807x_SUPPORT) |
| 676 | if (of_machine_is_compatible("qcom,ipq807x")) { |
| 677 | nss_top_main.hal_ops = &nss_hal_ipq807x_ops; |
Stephen Wang | df8323b | 2016-05-09 22:51:22 -0700 | [diff] [blame] | 678 | nss_top_main.data_plane_ops = &nss_data_plane_edma_ops; |
Stephen Wang | be34802 | 2016-05-02 17:11:34 -0700 | [diff] [blame] | 679 | } |
| 680 | #endif |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 681 | #if defined(NSS_HAL_FSM9010_SUPPORT) |
| 682 | if (of_machine_is_compatible("qcom,fsm9010")) { |
| 683 | nss_top_main.hal_ops = &nss_hal_fsm9010_ops; |
Stephen Wang | 5901def | 2016-05-09 16:21:03 -0700 | [diff] [blame] | 684 | nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops; |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 685 | } |
| 686 | #endif |
| 687 | if (!nss_top_main.hal_ops) { |
| 688 | nss_info_always("No supported HAL compiled on this platform\n"); |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 689 | return -EFAULT; |
| 690 | } |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 691 | #else |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 692 | /* |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 693 | * For banana, only ipq806x is supported |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 694 | */ |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 695 | nss_top_main.hal_ops = &nss_hal_ipq806x_ops; |
Stephen Wang | 5901def | 2016-05-09 16:21:03 -0700 | [diff] [blame] | 696 | nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 697 | |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 698 | #endif /* NSS_DT_SUPPORT */ |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 699 | nss_top_main.nss_hal_common_init_done = false; |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 700 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 701 | /* |
Stephen Wang | b42ddc5 | 2015-12-17 18:10:35 -0800 | [diff] [blame] | 702 | * Initialize data_plane workqueue |
| 703 | */ |
| 704 | if (nss_data_plane_init_delay_work()) { |
| 705 | nss_warning("Error initializing nss_data_plane_workqueue\n"); |
| 706 | return -EFAULT; |
| 707 | } |
| 708 | |
| 709 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 710 | * Enable spin locks |
| 711 | */ |
| 712 | spin_lock_init(&(nss_top_main.lock)); |
| 713 | spin_lock_init(&(nss_top_main.stats_lock)); |
c_athand | fde2e91 | 2017-01-10 15:40:12 +0530 | [diff] [blame] | 714 | mutex_init(&(nss_top_main.wq_lock)); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 715 | |
| 716 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 717 | * Enable NSS statistics |
| 718 | */ |
| 719 | nss_stats_init(); |
| 720 | |
| 721 | /* |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 722 | * Register sysctl table. |
| 723 | */ |
| 724 | nss_dev_header = register_sysctl_table(nss_root); |
| 725 | |
| 726 | /* |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 727 | * Registering sysctl for ipv4/6 specific config. |
| 728 | */ |
| 729 | nss_ipv4_register_sysctl(); |
| 730 | nss_ipv6_register_sysctl(); |
| 731 | |
Vijay Dewangan | ac7efc4 | 2015-02-09 16:04:53 -0800 | [diff] [blame] | 732 | /* |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 733 | * Registering sysctl for n2h specific config. |
Vijay Dewangan | ac7efc4 | 2015-02-09 16:04:53 -0800 | [diff] [blame] | 734 | */ |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 735 | nss_n2h_register_sysctl(); |
Vijay Dewangan | ac7efc4 | 2015-02-09 16:04:53 -0800 | [diff] [blame] | 736 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 737 | /* |
Murat Sezgin | e5079aa | 2017-06-07 18:09:38 -0700 | [diff] [blame^] | 738 | * Registering sysctl for dscp2pri specific config. |
| 739 | */ |
| 740 | nss_dscp2pri_register_sysctl(); |
| 741 | |
| 742 | /* |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 743 | * Setup Runtime Sample values |
| 744 | */ |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 745 | nss_runtime_samples.freq_scale_index = 1; |
| 746 | nss_runtime_samples.freq_scale_ready = 0; |
Thomas Wu | 9681f7e | 2013-11-06 13:12:57 -0800 | [diff] [blame] | 747 | nss_runtime_samples.freq_scale_rate_limit_down = 0; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 748 | nss_runtime_samples.buffer_index = 0; |
| 749 | nss_runtime_samples.sum = 0; |
| 750 | nss_runtime_samples.sample_count = 0; |
| 751 | nss_runtime_samples.average = 0; |
| 752 | nss_runtime_samples.message_rate_limit = 0; |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 753 | nss_runtime_samples.initialized = 0; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 754 | |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 755 | nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency; |
| 756 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 757 | /* |
| 758 | * Initial Workqueue |
| 759 | */ |
| 760 | nss_wq = create_workqueue("nss_freq_queue"); |
| 761 | |
Thomas Wu | 0d11219 | 2015-04-13 11:37:22 -0700 | [diff] [blame] | 762 | #if (NSS_PM_SUPPORT == 1) |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 763 | /* |
Pamidipati, Vijay | 7f413b5 | 2013-09-24 19:07:12 +0530 | [diff] [blame] | 764 | * Initialize NSS Bus PM module |
| 765 | */ |
| 766 | nss_pm_init(); |
| 767 | |
| 768 | /* |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 769 | * Register with Bus driver |
| 770 | */ |
| 771 | pm_client = nss_pm_client_register(NSS_PM_CLIENT_NETAP); |
| 772 | if (!pm_client) { |
| 773 | nss_warning("Error registering with PM driver"); |
| 774 | } |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 775 | #endif |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 776 | |
| 777 | /* |
Radha krishna Simha Jiguru | 7f424d5 | 2015-02-10 19:41:01 +0530 | [diff] [blame] | 778 | * Initialize mtu size needed as start |
| 779 | */ |
Stephen Wang | a428d0b | 2017-01-12 21:30:01 -0800 | [diff] [blame] | 780 | nss_top_main.prev_mtu_sz = ETH_DATA_LEN; |
Radha krishna Simha Jiguru | 7f424d5 | 2015-02-10 19:41:01 +0530 | [diff] [blame] | 781 | |
| 782 | /* |
Guojun Jin | 1cb7952 | 2015-06-22 22:34:22 -0700 | [diff] [blame] | 783 | * register panic handler and timeout control |
| 784 | */ |
| 785 | nss_coredump_notify_register(); |
| 786 | nss_coredump_init_delay_work(); |
| 787 | |
| 788 | /* |
Stephen Wang | 1f6ad49 | 2016-01-27 23:42:06 -0800 | [diff] [blame] | 789 | * Init capwap |
| 790 | */ |
| 791 | nss_capwap_init(); |
| 792 | |
| 793 | /* |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 794 | * INIT ppe on supported platform |
| 795 | */ |
| 796 | if (of_machine_is_compatible("qcom,ipq807x")) { |
| 797 | nss_ppe_init(); |
| 798 | } |
| 799 | |
| 800 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 801 | * Register platform_driver |
| 802 | */ |
| 803 | return platform_driver_register(&nss_driver); |
| 804 | } |
| 805 | |
| 806 | /* |
| 807 | * nss_cleanup() |
| 808 | * Unregisters nss driver |
| 809 | */ |
| 810 | static void __exit nss_cleanup(void) |
| 811 | { |
| 812 | nss_info("Exit NSS driver"); |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 813 | |
| 814 | if (nss_dev_header) |
| 815 | unregister_sysctl_table(nss_dev_header); |
| 816 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 817 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 818 | * Unregister n2h specific sysctl |
| 819 | */ |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 820 | nss_n2h_unregister_sysctl(); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 821 | |
| 822 | /* |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 823 | * Unregister ipv4/6 specific sysctl |
| 824 | */ |
| 825 | nss_ipv4_unregister_sysctl(); |
| 826 | nss_ipv6_unregister_sysctl(); |
| 827 | |
Murat Sezgin | e5079aa | 2017-06-07 18:09:38 -0700 | [diff] [blame^] | 828 | nss_dscp2pri_unregister_sysctl(); |
Stephen Wang | b42ddc5 | 2015-12-17 18:10:35 -0800 | [diff] [blame] | 829 | nss_data_plane_destroy_delay_work(); |
| 830 | |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 831 | /* |
| 832 | * cleanup ppe on supported platform |
| 833 | */ |
| 834 | if (of_machine_is_compatible("qcom,ipq807x")) { |
| 835 | nss_ppe_free(); |
| 836 | } |
| 837 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 838 | platform_driver_unregister(&nss_driver); |
| 839 | } |
| 840 | |
| 841 | module_init(nss_init); |
| 842 | module_exit(nss_cleanup); |
| 843 | |
| 844 | MODULE_DESCRIPTION("QCA NSS Driver"); |
| 845 | MODULE_AUTHOR("Qualcomm Atheros Inc"); |
| 846 | MODULE_LICENSE("Dual BSD/GPL"); |