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