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