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