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