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