Radhakrishna Jiguru | 1c9b225 | 2013-08-27 23:57:48 +0530 | [diff] [blame] | 1 | /* |
| 2 | ************************************************************************** |
Radha krishna Simha Jiguru | 68d0cbc | 2019-02-15 00:19:21 +0530 | [diff] [blame] | 3 | * Copyright (c) 2013-2019, 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 | /* |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 268 | * Setup default values - Middle of Freq Scale Band |
| 269 | */ |
| 270 | nss_runtime_samples.freq_scale_index = 1; |
Thomas Wu | bfe3ffc | 2019-07-19 16:09:52 -0700 | [diff] [blame] | 271 | nss_runtime_samples.sample_count = 0; |
| 272 | nss_runtime_samples.initialized = 0; |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 273 | nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency; |
| 274 | |
Thomas Wu | 7409bce | 2014-05-21 10:56:07 -0700 | [diff] [blame] | 275 | nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC); |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 276 | if (!nss_work) { |
| 277 | nss_info("NSS Freq WQ kmalloc fail"); |
| 278 | return ret; |
| 279 | } |
Thomas Wu | d6af377 | 2017-09-01 13:42:28 -0700 | [diff] [blame] | 280 | INIT_WORK((struct work_struct *)nss_work, nss_hal_wq_function); |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 281 | nss_work->frequency = nss_cmd_buf.current_freq; |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 282 | nss_work->stats_enable = 1; |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 283 | queue_work(nss_wq, (struct work_struct *)nss_work); |
| 284 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 285 | nss_cmd_buf.auto_scale = 0; |
Thomas Wu | fb6a684 | 2013-10-23 13:14:27 -0700 | [diff] [blame] | 286 | nss_runtime_samples.freq_scale_ready = 1; |
| 287 | |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 288 | return ret; |
| 289 | } |
| 290 | |
| 291 | /* |
| 292 | * nss_get_freq_table_handler() |
| 293 | * Display Support Freq and Ex how to Change. |
| 294 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 295 | 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] | 296 | { |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 297 | int ret, i; |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 298 | |
| 299 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 300 | |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 301 | if (write) { |
| 302 | return ret; |
| 303 | } |
| 304 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 305 | printk("Frequency Supported - "); |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 306 | |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 307 | i = 0; |
Thomas Wu | 7132bd3 | 2015-05-07 15:03:06 -0700 | [diff] [blame] | 308 | while (i < NSS_FREQ_MAX_SCALE) { |
Thomas Wu | 6a48ac9 | 2017-11-03 10:48:04 -0700 | [diff] [blame] | 309 | printk("%d Hz ", nss_runtime_samples.freq_scale[i].frequency); |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 310 | i++; |
Thomas Wu | 0a0a9c9 | 2013-11-21 15:28:19 -0800 | [diff] [blame] | 311 | } |
Thomas Wu | 0e2fc4f | 2015-03-04 15:39:14 -0800 | [diff] [blame] | 312 | printk("\n"); |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 313 | |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 314 | *lenp = 0; |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 315 | return ret; |
| 316 | } |
| 317 | |
| 318 | /* |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 319 | * nss_get_average_inst_handler() |
| 320 | * Display AVG Inst Per Ms. |
| 321 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 322 | 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] | 323 | { |
| 324 | int ret; |
| 325 | |
| 326 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 327 | |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 328 | if (write) { |
| 329 | return ret; |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 330 | } |
| 331 | |
Thomas Wu | c151f2e | 2015-09-08 10:59:44 -0700 | [diff] [blame] | 332 | printk("Current Inst Per Ms %x\n", nss_runtime_samples.average); |
| 333 | |
| 334 | *lenp = 0; |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 335 | return ret; |
| 336 | } |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 337 | #endif |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 338 | |
Sundarajan Srinivasan | 758e8f4 | 2014-12-08 14:56:24 -0800 | [diff] [blame] | 339 | #if (NSS_FW_DBG_SUPPORT == 1) |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 340 | /* |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 341 | * nss_debug_handler() |
| 342 | * Enable NSS debug output |
| 343 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 344 | 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] | 345 | { |
| 346 | int ret; |
| 347 | |
| 348 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 349 | if (!ret) { |
| 350 | if ((write) && (nss_ctl_debug != 0)) { |
| 351 | printk("Enabling NSS SPI Debug\n"); |
| 352 | nss_hal_debug_enable(); |
| 353 | } |
| 354 | } |
| 355 | |
| 356 | return ret; |
| 357 | } |
Sundarajan Srinivasan | 758e8f4 | 2014-12-08 14:56:24 -0800 | [diff] [blame] | 358 | #endif |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 359 | |
| 360 | /* |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 361 | * nss_coredump_handler() |
| 362 | * Send Signal To Coredump NSS Cores |
| 363 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 364 | 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] | 365 | { |
Guojun Jin | 32a3c6d | 2015-05-06 12:27:52 -0700 | [diff] [blame] | 366 | 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] | 367 | int ret; |
| 368 | |
| 369 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 370 | if (!ret) { |
Guojun Jin | 244ecab | 2017-03-16 16:04:25 -0700 | [diff] [blame] | 371 | /* |
| 372 | * if nss_cmd_buf.coredump is not 0 or 1, panic will be disabled |
| 373 | * when NSS FW crashes, so OEM/ODM have a chance to use mdump |
| 374 | * to dump crash dump (coredump) and send dump to us for analysis. |
| 375 | */ |
| 376 | if ((write) && (nss_ctl_debug != 0) && nss_cmd_buf.coredump == 1) { |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 377 | printk("Coredumping to DDR\n"); |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 378 | nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_TRIGGER_COREDUMP); |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
| 382 | return ret; |
| 383 | } |
| 384 | |
| 385 | /* |
Sundarajan Srinivasan | f9c4a23 | 2014-11-18 13:25:40 -0800 | [diff] [blame] | 386 | * nss_jumbo_mru_handler() |
| 387 | * Sysctl to modify nss_jumbo_mru |
| 388 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 389 | 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] | 390 | { |
| 391 | int ret; |
| 392 | |
| 393 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 394 | if (ret) { |
| 395 | return ret; |
| 396 | } |
| 397 | |
| 398 | if (write) { |
| 399 | nss_core_set_jumbo_mru(nss_jumbo_mru); |
| 400 | nss_info("jumbo_mru set to %d\n", nss_jumbo_mru); |
| 401 | } |
| 402 | |
| 403 | return ret; |
| 404 | } |
| 405 | |
| 406 | /* nss_paged_mode_handler() |
| 407 | * Sysctl to modify nss_paged_mode. |
| 408 | */ |
| 409 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 410 | 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] | 411 | { |
| 412 | int ret; |
| 413 | |
| 414 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 415 | if (ret) { |
| 416 | return ret; |
| 417 | } |
| 418 | |
| 419 | if (write) { |
| 420 | nss_core_set_paged_mode(nss_paged_mode); |
| 421 | nss_info("paged_mode set to %d\n", nss_paged_mode); |
| 422 | } |
| 423 | |
| 424 | return ret; |
| 425 | } |
| 426 | |
Casey Chen | 56c1363 | 2018-09-10 17:05:03 -0700 | [diff] [blame] | 427 | #if (NSS_SKB_REUSE_SUPPORT == 1) |
| 428 | /* |
| 429 | * nss_get_min_reuse_handler() |
| 430 | * Sysctl to get min reuse sizes |
| 431 | */ |
| 432 | static int nss_get_min_reuse_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 433 | { |
| 434 | int ret; |
| 435 | struct nss_ctx_instance *nss_ctx = NULL; |
| 436 | uint32_t core_id; |
| 437 | |
| 438 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 439 | if (ret) { |
| 440 | return ret; |
| 441 | } |
| 442 | |
| 443 | printk("Min SKB reuse sizes - "); |
| 444 | |
| 445 | for (core_id = 0; core_id < NSS_CORE_MAX; core_id++) { |
| 446 | nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[core_id]; |
| 447 | printk("core %d: %d ", core_id, nss_core_get_min_reuse(nss_ctx)); |
| 448 | } |
| 449 | |
| 450 | printk("\n"); |
| 451 | *lenp = 0; |
| 452 | return ret; |
| 453 | } |
| 454 | |
| 455 | /* |
| 456 | * nss_max_reuse_handler() |
| 457 | * Sysctl to modify nss_max_reuse |
| 458 | */ |
| 459 | static int nss_max_reuse_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos) |
| 460 | { |
| 461 | int ret; |
| 462 | |
| 463 | nss_max_reuse = nss_core_get_max_reuse(); |
| 464 | ret = proc_dointvec(ctl, write, buffer, lenp, ppos); |
| 465 | if (ret) { |
| 466 | return ret; |
| 467 | } |
| 468 | |
| 469 | if (write) { |
| 470 | nss_core_set_max_reuse(nss_max_reuse); |
| 471 | nss_info("max_reuse set to %d\n", nss_max_reuse); |
| 472 | } |
| 473 | |
| 474 | return ret; |
| 475 | } |
| 476 | |
| 477 | /* |
| 478 | * sysctl-tuning for NSS driver SKB reuse |
| 479 | */ |
| 480 | static struct ctl_table nss_skb_reuse_table[] = { |
| 481 | { |
| 482 | .procname = "min_sizes", |
| 483 | .data = NULL, |
| 484 | .maxlen = sizeof(int), |
| 485 | .mode = 0644, |
| 486 | .proc_handler = &nss_get_min_reuse_handler, |
| 487 | }, |
| 488 | { |
| 489 | .procname = "max_size", |
| 490 | .data = &nss_max_reuse, |
| 491 | .maxlen = sizeof(int), |
| 492 | .mode = 0644, |
| 493 | .proc_handler = &nss_max_reuse_handler, |
| 494 | }, |
| 495 | { } |
| 496 | }; |
| 497 | #endif |
| 498 | |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 499 | #if (NSS_FREQ_SCALE_SUPPORT == 1) |
Sundarajan Srinivasan | f9c4a23 | 2014-11-18 13:25:40 -0800 | [diff] [blame] | 500 | /* |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 501 | * sysctl-tuning infrastructure. |
| 502 | */ |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 503 | static struct ctl_table nss_freq_table[] = { |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 504 | { |
| 505 | .procname = "current_freq", |
| 506 | .data = &nss_cmd_buf.current_freq, |
| 507 | .maxlen = sizeof(int), |
| 508 | .mode = 0644, |
| 509 | .proc_handler = &nss_current_freq_handler, |
| 510 | }, |
| 511 | { |
| 512 | .procname = "freq_table", |
| 513 | .data = &nss_cmd_buf.max_freq, |
| 514 | .maxlen = sizeof(int), |
| 515 | .mode = 0644, |
| 516 | .proc_handler = &nss_get_freq_table_handler, |
| 517 | }, |
| 518 | { |
| 519 | .procname = "auto_scale", |
| 520 | .data = &nss_cmd_buf.auto_scale, |
| 521 | .maxlen = sizeof(int), |
| 522 | .mode = 0644, |
| 523 | .proc_handler = &nss_auto_scale_handler, |
| 524 | }, |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 525 | { |
| 526 | .procname = "inst_per_sec", |
| 527 | .data = &nss_cmd_buf.average_inst, |
| 528 | .maxlen = sizeof(int), |
| 529 | .mode = 0644, |
| 530 | .proc_handler = &nss_get_average_inst_handler, |
| 531 | }, |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 532 | { } |
| 533 | }; |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 534 | #endif |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 535 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 536 | static struct ctl_table nss_general_table[] = { |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 537 | { |
| 538 | .procname = "redirect", |
| 539 | .data = &nss_ctl_redirect, |
| 540 | .maxlen = sizeof(int), |
| 541 | .mode = 0644, |
Cemil Coskun | 9165c76 | 2017-12-04 14:35:24 -0800 | [diff] [blame] | 542 | .proc_handler = proc_dointvec, |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 543 | }, |
Sundarajan Srinivasan | 758e8f4 | 2014-12-08 14:56:24 -0800 | [diff] [blame] | 544 | #if (NSS_FW_DBG_SUPPORT == 1) |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 545 | { |
| 546 | .procname = "debug", |
| 547 | .data = &nss_ctl_debug, |
| 548 | .maxlen = sizeof(int), |
| 549 | .mode = 0644, |
Cemil Coskun | 9165c76 | 2017-12-04 14:35:24 -0800 | [diff] [blame] | 550 | .proc_handler = &nss_debug_handler, |
Abhishek Rastogi | 1626a90 | 2013-11-21 17:09:49 +0530 | [diff] [blame] | 551 | }, |
Sundarajan Srinivasan | 758e8f4 | 2014-12-08 14:56:24 -0800 | [diff] [blame] | 552 | #endif |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 553 | { |
| 554 | .procname = "coredump", |
| 555 | .data = &nss_cmd_buf.coredump, |
| 556 | .maxlen = sizeof(int), |
| 557 | .mode = 0644, |
Cemil Coskun | 9165c76 | 2017-12-04 14:35:24 -0800 | [diff] [blame] | 558 | .proc_handler = &nss_coredump_handler, |
Thomas Wu | 52075f4 | 2014-02-06 16:32:42 -0800 | [diff] [blame] | 559 | }, |
Pamidipati, Vijay | efcc469 | 2014-05-09 14:47:38 +0530 | [diff] [blame] | 560 | { |
Saurabh Misra | 96998db | 2014-07-10 12:15:48 -0700 | [diff] [blame] | 561 | .procname = "logbuf", |
| 562 | .data = &nss_ctl_logbuf, |
| 563 | .maxlen = sizeof(int), |
| 564 | .mode = 0644, |
Cemil Coskun | 9165c76 | 2017-12-04 14:35:24 -0800 | [diff] [blame] | 565 | .proc_handler = &nss_logbuffer_handler, |
Saurabh Misra | 96998db | 2014-07-10 12:15:48 -0700 | [diff] [blame] | 566 | }, |
Sundarajan Srinivasan | f9c4a23 | 2014-11-18 13:25:40 -0800 | [diff] [blame] | 567 | { |
| 568 | .procname = "jumbo_mru", |
| 569 | .data = &nss_jumbo_mru, |
| 570 | .maxlen = sizeof(int), |
| 571 | .mode = 0644, |
| 572 | .proc_handler = &nss_jumbo_mru_handler, |
| 573 | }, |
| 574 | { |
| 575 | .procname = "paged_mode", |
| 576 | .data = &nss_paged_mode, |
| 577 | .maxlen = sizeof(int), |
| 578 | .mode = 0644, |
| 579 | .proc_handler = &nss_paged_mode_handler, |
| 580 | }, |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 581 | { } |
| 582 | }; |
| 583 | |
Casey Chen | 56c1363 | 2018-09-10 17:05:03 -0700 | [diff] [blame] | 584 | static struct ctl_table nss_init_dir[] = { |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 585 | #if (NSS_FREQ_SCALE_SUPPORT == 1) |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 586 | { |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 587 | .procname = "clock", |
| 588 | .mode = 0555, |
| 589 | .child = nss_freq_table, |
| 590 | }, |
Arunkumar T | 28b2d74 | 2015-06-16 22:15:58 +0530 | [diff] [blame] | 591 | #endif |
Abhishek Rastogi | 5cd2e4c | 2013-11-13 18:09:08 +0530 | [diff] [blame] | 592 | { |
| 593 | .procname = "general", |
| 594 | .mode = 0555, |
| 595 | .child = nss_general_table, |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 596 | }, |
Casey Chen | 56c1363 | 2018-09-10 17:05:03 -0700 | [diff] [blame] | 597 | #if (NSS_SKB_REUSE_SUPPORT == 1) |
| 598 | { |
| 599 | .procname = "skb_reuse", |
| 600 | .mode = 0555, |
| 601 | .child = nss_skb_reuse_table, |
| 602 | }, |
| 603 | #endif |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 604 | { } |
| 605 | }; |
| 606 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 607 | static struct ctl_table nss_root_dir[] = { |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 608 | { |
| 609 | .procname = "nss", |
| 610 | .mode = 0555, |
Casey Chen | 56c1363 | 2018-09-10 17:05:03 -0700 | [diff] [blame] | 611 | .child = nss_init_dir, |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 612 | }, |
| 613 | { } |
| 614 | }; |
| 615 | |
Stephen Wang | 52e6d34 | 2016-03-29 15:02:33 -0700 | [diff] [blame] | 616 | static struct ctl_table nss_root[] = { |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 617 | { |
| 618 | .procname = "dev", |
| 619 | .mode = 0555, |
| 620 | .child = nss_root_dir, |
| 621 | }, |
| 622 | { } |
| 623 | }; |
| 624 | |
| 625 | static struct ctl_table_header *nss_dev_header; |
| 626 | |
| 627 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 628 | * nss_init() |
| 629 | * Registers nss driver |
| 630 | */ |
| 631 | static int __init nss_init(void) |
| 632 | { |
Radha krishna Simha Jiguru | 3295b8b | 2017-03-12 10:54:15 +0530 | [diff] [blame] | 633 | #if (NSS_DT_SUPPORT == 1) |
| 634 | struct device_node *cmn = NULL; |
| 635 | #endif |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 636 | nss_info("Init NSS driver"); |
| 637 | |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 638 | #if (NSS_DT_SUPPORT == 1) |
| 639 | /* |
Radha krishna Simha Jiguru | 3295b8b | 2017-03-12 10:54:15 +0530 | [diff] [blame] | 640 | * Get reference to NSS common device node |
| 641 | */ |
| 642 | cmn = of_find_node_by_name(NULL, "nss-common"); |
| 643 | if (!cmn) { |
| 644 | nss_info_always("qca-nss-drv.ko is loaded for symbol link\n"); |
| 645 | return 0; |
| 646 | } |
| 647 | of_node_put(cmn); |
| 648 | |
| 649 | /* |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 650 | * Pick up HAL by target information |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 651 | */ |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 652 | #if defined(NSS_HAL_IPQ806X_SUPPORT) |
| 653 | if (of_machine_is_compatible("qcom,ipq8064") || of_machine_is_compatible("qcom,ipq8062")) { |
| 654 | nss_top_main.hal_ops = &nss_hal_ipq806x_ops; |
Stephen Wang | 5901def | 2016-05-09 16:21:03 -0700 | [diff] [blame] | 655 | nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops; |
Suman Ghosh | 9f7b370 | 2018-09-21 19:51:40 +0530 | [diff] [blame] | 656 | nss_top_main.num_nss = 2; |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 657 | } |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 658 | #endif |
Stephen Wang | be34802 | 2016-05-02 17:11:34 -0700 | [diff] [blame] | 659 | #if defined(NSS_HAL_IPQ807x_SUPPORT) |
| 660 | if (of_machine_is_compatible("qcom,ipq807x")) { |
| 661 | nss_top_main.hal_ops = &nss_hal_ipq807x_ops; |
Stephen Wang | df8323b | 2016-05-09 22:51:22 -0700 | [diff] [blame] | 662 | nss_top_main.data_plane_ops = &nss_data_plane_edma_ops; |
Radha krishna Simha Jiguru | 68d0cbc | 2019-02-15 00:19:21 +0530 | [diff] [blame] | 663 | #if defined(NSS_MEM_PROFILE_LOW) |
| 664 | nss_top_main.num_nss = 1; |
| 665 | #else |
Suman Ghosh | 9f7b370 | 2018-09-21 19:51:40 +0530 | [diff] [blame] | 666 | nss_top_main.num_nss = 2; |
Radha krishna Simha Jiguru | 68d0cbc | 2019-02-15 00:19:21 +0530 | [diff] [blame] | 667 | #endif |
Stephen Wang | be34802 | 2016-05-02 17:11:34 -0700 | [diff] [blame] | 668 | } |
| 669 | #endif |
Suman Ghosh | 3f94023 | 2018-08-17 20:43:03 +0530 | [diff] [blame] | 670 | #if defined(NSS_HAL_IPQ60XX_SUPPORT) |
| 671 | if (of_machine_is_compatible("qcom,ipq6018")) { |
| 672 | nss_top_main.hal_ops = &nss_hal_ipq60xx_ops; |
| 673 | nss_top_main.data_plane_ops = &nss_data_plane_edma_ops; |
Suman Ghosh | 9f7b370 | 2018-09-21 19:51:40 +0530 | [diff] [blame] | 674 | nss_top_main.num_nss = 1; |
Suman Ghosh | 3f94023 | 2018-08-17 20:43:03 +0530 | [diff] [blame] | 675 | } |
| 676 | #endif |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 677 | #if defined(NSS_HAL_FSM9010_SUPPORT) |
| 678 | if (of_machine_is_compatible("qcom,fsm9010")) { |
| 679 | nss_top_main.hal_ops = &nss_hal_fsm9010_ops; |
Stephen Wang | 5901def | 2016-05-09 16:21:03 -0700 | [diff] [blame] | 680 | nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops; |
Suman Ghosh | 9f7b370 | 2018-09-21 19:51:40 +0530 | [diff] [blame] | 681 | nss_top_main.num_nss = 1; |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 682 | } |
| 683 | #endif |
| 684 | if (!nss_top_main.hal_ops) { |
| 685 | nss_info_always("No supported HAL compiled on this platform\n"); |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 686 | return -EFAULT; |
| 687 | } |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 688 | #else |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 689 | /* |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 690 | * For banana, only ipq806x is supported |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 691 | */ |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 692 | nss_top_main.hal_ops = &nss_hal_ipq806x_ops; |
Stephen Wang | 5901def | 2016-05-09 16:21:03 -0700 | [diff] [blame] | 693 | nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops; |
Suman Ghosh | 9f7b370 | 2018-09-21 19:51:40 +0530 | [diff] [blame] | 694 | nss_top_main.num_nss = 2; |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 695 | |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 696 | #endif /* NSS_DT_SUPPORT */ |
Stephen Wang | 90c67de | 2016-04-26 15:15:59 -0700 | [diff] [blame] | 697 | nss_top_main.nss_hal_common_init_done = false; |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 698 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 699 | /* |
Stephen Wang | b42ddc5 | 2015-12-17 18:10:35 -0800 | [diff] [blame] | 700 | * Initialize data_plane workqueue |
| 701 | */ |
| 702 | if (nss_data_plane_init_delay_work()) { |
| 703 | nss_warning("Error initializing nss_data_plane_workqueue\n"); |
| 704 | return -EFAULT; |
| 705 | } |
| 706 | |
| 707 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 708 | * Enable spin locks |
| 709 | */ |
| 710 | spin_lock_init(&(nss_top_main.lock)); |
| 711 | spin_lock_init(&(nss_top_main.stats_lock)); |
c_athand | fde2e91 | 2017-01-10 15:40:12 +0530 | [diff] [blame] | 712 | mutex_init(&(nss_top_main.wq_lock)); |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 713 | |
| 714 | /* |
Abhishek Rastogi | 38cffff | 2013-06-02 11:25:47 +0530 | [diff] [blame] | 715 | * Enable NSS statistics |
| 716 | */ |
| 717 | nss_stats_init(); |
| 718 | |
| 719 | /* |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 720 | * Register sysctl table. |
| 721 | */ |
| 722 | nss_dev_header = register_sysctl_table(nss_root); |
| 723 | |
| 724 | /* |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 725 | * Registering sysctl for ipv4/6 specific config. |
| 726 | */ |
| 727 | nss_ipv4_register_sysctl(); |
| 728 | nss_ipv6_register_sysctl(); |
| 729 | |
Vijay Dewangan | ac7efc4 | 2015-02-09 16:04:53 -0800 | [diff] [blame] | 730 | /* |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 731 | * Registering sysctl for n2h specific config. |
Vijay Dewangan | ac7efc4 | 2015-02-09 16:04:53 -0800 | [diff] [blame] | 732 | */ |
Suman Ghosh | 9f7b370 | 2018-09-21 19:51:40 +0530 | [diff] [blame] | 733 | if (nss_top_main.num_nss == 1) { |
| 734 | nss_n2h_single_core_register_sysctl(); |
| 735 | } else { |
| 736 | nss_n2h_multi_core_register_sysctl(); |
| 737 | } |
Vijay Dewangan | ac7efc4 | 2015-02-09 16:04:53 -0800 | [diff] [blame] | 738 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 739 | /* |
Cemil Coskun | 9165c76 | 2017-12-04 14:35:24 -0800 | [diff] [blame] | 740 | * Registering sysctl for rps specific config. |
| 741 | */ |
| 742 | nss_rps_register_sysctl(); |
| 743 | |
| 744 | /* |
Cemil Coskun | 497f7ec | 2018-07-12 14:08:53 -0700 | [diff] [blame] | 745 | * Registering sysctl for c2c_tx specific config. |
| 746 | */ |
| 747 | nss_c2c_tx_register_sysctl(); |
| 748 | |
| 749 | /* |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 750 | * Register sysctl for project config |
| 751 | */ |
| 752 | nss_project_register_sysctl(); |
| 753 | |
| 754 | /* |
Amit Gupta | 1fe4d91 | 2019-03-19 15:57:10 +0530 | [diff] [blame] | 755 | * Registering sysctl for pppoe specific config. |
| 756 | */ |
| 757 | nss_pppoe_register_sysctl(); |
| 758 | |
| 759 | /* |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 760 | * Setup Runtime Sample values |
| 761 | */ |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 762 | nss_runtime_samples.freq_scale_index = 1; |
| 763 | nss_runtime_samples.freq_scale_ready = 0; |
Thomas Wu | 9681f7e | 2013-11-06 13:12:57 -0800 | [diff] [blame] | 764 | nss_runtime_samples.freq_scale_rate_limit_down = 0; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 765 | nss_runtime_samples.buffer_index = 0; |
| 766 | nss_runtime_samples.sum = 0; |
| 767 | nss_runtime_samples.sample_count = 0; |
| 768 | nss_runtime_samples.average = 0; |
| 769 | nss_runtime_samples.message_rate_limit = 0; |
Kiran Kumar C.S.K | 69fd599 | 2014-01-06 20:58:14 +0530 | [diff] [blame] | 770 | nss_runtime_samples.initialized = 0; |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 771 | |
Thomas Wu | 05495be | 2013-12-19 14:24:24 -0800 | [diff] [blame] | 772 | nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency; |
| 773 | |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 774 | /* |
| 775 | * Initial Workqueue |
| 776 | */ |
| 777 | nss_wq = create_workqueue("nss_freq_queue"); |
| 778 | |
Thomas Wu | 0d11219 | 2015-04-13 11:37:22 -0700 | [diff] [blame] | 779 | #if (NSS_PM_SUPPORT == 1) |
wthomas | 626147f | 2013-09-18 13:12:40 -0700 | [diff] [blame] | 780 | /* |
Pamidipati, Vijay | 7f413b5 | 2013-09-24 19:07:12 +0530 | [diff] [blame] | 781 | * Initialize NSS Bus PM module |
| 782 | */ |
| 783 | nss_pm_init(); |
| 784 | |
| 785 | /* |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 786 | * Register with Bus driver |
| 787 | */ |
| 788 | pm_client = nss_pm_client_register(NSS_PM_CLIENT_NETAP); |
| 789 | if (!pm_client) { |
| 790 | nss_warning("Error registering with PM driver"); |
| 791 | } |
Sundarajan Srinivasan | 4691ba6 | 2014-11-07 11:24:07 -0800 | [diff] [blame] | 792 | #endif |
Pamidipati, Vijay | 5d27d81 | 2013-11-22 16:48:11 +0530 | [diff] [blame] | 793 | |
| 794 | /* |
Radha krishna Simha Jiguru | 7f424d5 | 2015-02-10 19:41:01 +0530 | [diff] [blame] | 795 | * Initialize mtu size needed as start |
| 796 | */ |
Stephen Wang | a428d0b | 2017-01-12 21:30:01 -0800 | [diff] [blame] | 797 | nss_top_main.prev_mtu_sz = ETH_DATA_LEN; |
Radha krishna Simha Jiguru | 7f424d5 | 2015-02-10 19:41:01 +0530 | [diff] [blame] | 798 | |
| 799 | /* |
Guojun Jin | 1cb7952 | 2015-06-22 22:34:22 -0700 | [diff] [blame] | 800 | * register panic handler and timeout control |
| 801 | */ |
| 802 | nss_coredump_notify_register(); |
| 803 | nss_coredump_init_delay_work(); |
| 804 | |
| 805 | /* |
Stephen Wang | 1f6ad49 | 2016-01-27 23:42:06 -0800 | [diff] [blame] | 806 | * Init capwap |
| 807 | */ |
| 808 | nss_capwap_init(); |
| 809 | |
| 810 | /* |
Yu Huang | 6b2f0be | 2017-10-18 16:11:49 -0700 | [diff] [blame] | 811 | * Init QRFS |
| 812 | */ |
| 813 | nss_qrfs_init(); |
| 814 | |
| 815 | /* |
Cemil Coskun | 1c9c392 | 2018-01-23 16:21:49 -0800 | [diff] [blame] | 816 | * Init c2c_tx |
| 817 | */ |
| 818 | nss_c2c_tx_init(); |
| 819 | |
| 820 | /* |
Cemil Coskun | cdcd1dd | 2019-01-28 13:35:31 -0800 | [diff] [blame] | 821 | * Init pvxlan |
| 822 | */ |
| 823 | nss_pvxlan_init(); |
| 824 | |
| 825 | /* |
Suman Ghosh | 85f353a | 2019-06-03 14:47:32 +0530 | [diff] [blame^] | 826 | * Init clmap |
| 827 | */ |
| 828 | nss_clmap_init(); |
| 829 | |
| 830 | /* |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 831 | * INIT ppe on supported platform |
| 832 | */ |
Suman Ghosh | 3f94023 | 2018-08-17 20:43:03 +0530 | [diff] [blame] | 833 | 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] | 834 | nss_ppe_init(); |
| 835 | } |
| 836 | |
| 837 | /* |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 838 | * Register platform_driver |
| 839 | */ |
| 840 | return platform_driver_register(&nss_driver); |
| 841 | } |
| 842 | |
| 843 | /* |
| 844 | * nss_cleanup() |
| 845 | * Unregisters nss driver |
| 846 | */ |
| 847 | static void __exit nss_cleanup(void) |
| 848 | { |
| 849 | nss_info("Exit NSS driver"); |
wthomas | 442c797 | 2013-08-05 14:28:17 -0700 | [diff] [blame] | 850 | |
| 851 | if (nss_dev_header) |
| 852 | unregister_sysctl_table(nss_dev_header); |
| 853 | |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 854 | /* |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 855 | * Unregister n2h specific sysctl |
| 856 | */ |
Stephen Wang | 49b474b | 2016-03-25 10:40:30 -0700 | [diff] [blame] | 857 | nss_n2h_unregister_sysctl(); |
Vijay Dewangan | 488e537 | 2014-12-29 21:40:11 -0800 | [diff] [blame] | 858 | |
| 859 | /* |
Cemil Coskun | 9165c76 | 2017-12-04 14:35:24 -0800 | [diff] [blame] | 860 | * Unregister rps specific sysctl |
| 861 | */ |
| 862 | nss_rps_unregister_sysctl(); |
| 863 | |
| 864 | /* |
Cemil Coskun | 497f7ec | 2018-07-12 14:08:53 -0700 | [diff] [blame] | 865 | * Unregister c2c_tx specific sysctl |
| 866 | */ |
| 867 | nss_c2c_tx_unregister_sysctl(); |
| 868 | |
| 869 | /* |
Amit Gupta | 1fe4d91 | 2019-03-19 15:57:10 +0530 | [diff] [blame] | 870 | * Unregister pppoe specific sysctl |
| 871 | */ |
| 872 | nss_pppoe_unregister_sysctl(); |
| 873 | |
| 874 | /* |
Vijay Dewangan | 9db1875 | 2014-09-15 16:25:01 -0700 | [diff] [blame] | 875 | * Unregister ipv4/6 specific sysctl |
| 876 | */ |
| 877 | nss_ipv4_unregister_sysctl(); |
| 878 | nss_ipv6_unregister_sysctl(); |
| 879 | |
Suruchi Agarwal | cdcb5b4 | 2017-07-06 11:08:22 -0700 | [diff] [blame] | 880 | /* |
| 881 | * Free Memory allocated for connection tables |
| 882 | */ |
| 883 | nss_ipv4_free_conn_tables(); |
| 884 | nss_ipv6_free_conn_tables(); |
| 885 | |
Jackson Bockus | c2a4e68 | 2017-06-23 11:59:29 -0700 | [diff] [blame] | 886 | nss_project_unregister_sysctl(); |
Stephen Wang | b42ddc5 | 2015-12-17 18:10:35 -0800 | [diff] [blame] | 887 | nss_data_plane_destroy_delay_work(); |
| 888 | |
Amit Gupta | 316729b | 2016-08-12 12:21:15 +0530 | [diff] [blame] | 889 | /* |
| 890 | * cleanup ppe on supported platform |
| 891 | */ |
Suman Ghosh | 3f94023 | 2018-08-17 20:43:03 +0530 | [diff] [blame] | 892 | 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] | 893 | nss_ppe_free(); |
| 894 | } |
| 895 | |
Abhishek Rastogi | bc74e43 | 2013-04-02 10:28:22 +0530 | [diff] [blame] | 896 | platform_driver_unregister(&nss_driver); |
| 897 | } |
| 898 | |
| 899 | module_init(nss_init); |
| 900 | module_exit(nss_cleanup); |
| 901 | |
| 902 | MODULE_DESCRIPTION("QCA NSS Driver"); |
| 903 | MODULE_AUTHOR("Qualcomm Atheros Inc"); |
| 904 | MODULE_LICENSE("Dual BSD/GPL"); |