blob: 3f9248f21f48e057c788bb62f6e1b8c38db58bec [file] [log] [blame]
Radhakrishna Jiguru1c9b2252013-08-27 23:57:48 +05301/*
2 **************************************************************************
Yu Huang6b2f0be2017-10-18 16:11:49 -07003 * Copyright (c) 2013-2018, The Linux Foundation. All rights reserved.
Radhakrishna Jiguru1c9b2252013-08-27 23:57:48 +05304 * 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 Rastogibc74e432013-04-02 10:28:22 +053016
17/*
18 * nss_init.c
19 * NSS init APIs
20 *
21 */
Abhishek Rastogibc74e432013-04-02 10:28:22 +053022#include "nss_core.h"
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080023#if (NSS_PM_SUPPORT == 1)
Pamidipati, Vijay7f413b52013-09-24 19:07:12 +053024#include "nss_pm.h"
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080025#endif
Abhishek Rastogi9da47472014-03-18 19:46:15 +053026#include "nss_tx_rx_common.h"
Stephen Wang38e89bc2014-11-06 11:34:45 -080027#include "nss_data_plane.h"
Stephen Wang1f6ad492016-01-27 23:42:06 -080028#include "nss_capwap.h"
Pamidipati, Vijay7f413b52013-09-24 19:07:12 +053029
Abhishek Rastogibc74e432013-04-02 10:28:22 +053030#include <nss_hal.h>
31
32#include <linux/module.h>
33#include <linux/platform_device.h>
wthomas442c7972013-08-05 14:28:17 -070034#include <linux/proc_fs.h>
35#include <linux/device.h>
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080036
37#if (NSS_DT_SUPPORT == 1)
Stephen Wang463f1cf2016-03-29 15:25:51 -070038#if (NSS_FABRIC_SCALING_SUPPORT == 1)
Stephen Wang8ffd17f2016-03-07 14:03:40 -080039#include <linux/fab_scaling.h>
Stephen Wang1017ad12016-03-14 10:18:06 -070040#endif
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080041#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 Rastogibc74e432013-04-02 10:28:22 +053047#include <mach/msm_nss.h>
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080048#endif
Abhishek Rastogibc74e432013-04-02 10:28:22 +053049
wthomas442c7972013-08-05 14:28:17 -070050#include <linux/sysctl.h>
51#include <linux/regulator/consumer.h>
Thomas Wufb6a6842013-10-23 13:14:27 -070052#include <linux/clk.h>
wthomas442c7972013-08-05 14:28:17 -070053
Abhishek Rastogibc74e432013-04-02 10:28:22 +053054/*
55 * Global declarations
56 */
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +053057int nss_ctl_redirect __read_mostly = 0;
Sakthi Vignesh Radhakrishnanaf39aad2014-03-31 11:31:03 -070058int nss_ctl_debug __read_mostly = 0;
Saurabh Misra96998db2014-07-10 12:15:48 -070059int nss_ctl_logbuf __read_mostly = 0;
Sundarajan Srinivasanf9c4a232014-11-18 13:25:40 -080060int nss_jumbo_mru __read_mostly = 0;
61int nss_paged_mode __read_mostly = 0;
Casey Chen56c13632018-09-10 17:05:03 -070062#if (NSS_SKB_REUSE_SUPPORT == 1)
63int nss_max_reuse __read_mostly = PAGE_SIZE;
64#endif
Radha krishna Simha Jiguru28a0a252015-08-04 16:34:09 +053065int nss_skip_nw_process = 0x0;
66module_param(nss_skip_nw_process, int, S_IRUGO);
Abhishek Rastogibc74e432013-04-02 10:28:22 +053067
68/*
Pamidipati, Vijay5d27d812013-11-22 16:48:11 +053069 * PM client handle
70 */
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080071#if (NSS_PM_SUPPORT == 1)
Pamidipati, Vijay5d27d812013-11-22 16:48:11 +053072static void *pm_client;
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080073#endif
Pamidipati, Vijay5d27d812013-11-22 16:48:11 +053074
75/*
wthomas626147f2013-09-18 13:12:40 -070076 * Handler to send NSS messages
77 */
Thomas Wufb6a6842013-10-23 13:14:27 -070078struct clk *nss_core0_clk;
Thomas Wu63bcff62017-03-20 11:44:41 -070079struct clk *nss_core1_clk;
wthomas626147f2013-09-18 13:12:40 -070080
81/*
Thomas Wucd6b35a2015-07-14 10:17:48 -070082 * Handle fabric requests - only on new kernel
83 */
84#if (NSS_DT_SUPPORT == 1)
85struct clk *nss_fab0_clk;
86struct clk *nss_fab1_clk;
87#endif
88
89/*
Abhishek Rastogibc74e432013-04-02 10:28:22 +053090 * Top level nss context structure
91 */
92struct nss_top_instance nss_top_main;
wthomas442c7972013-08-05 14:28:17 -070093struct nss_cmd_buffer nss_cmd_buf;
wthomas626147f2013-09-18 13:12:40 -070094struct nss_runtime_sampling nss_runtime_samples;
95struct workqueue_struct *nss_wq;
96
97/*
98 * Work Queue to handle messages to Kernel
99 */
100nss_work_t *nss_work;
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530101
Arunkumar T79990cb2015-06-05 10:53:16 +0530102extern struct of_device_id nss_dt_ids[];
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530103
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530104/*
105 * nss_probe()
Cemil Coskun9165c762017-12-04 14:35:24 -0800106 * HLOS device probe callback
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530107 */
Ram Chandra Jangir6577f382016-05-31 12:16:28 +0530108static inline int nss_probe(struct platform_device *nss_dev)
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530109{
Arunkumar T79990cb2015-06-05 10:53:16 +0530110 return nss_hal_probe(nss_dev);
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530111}
112
113/*
114 * nss_remove()
Cemil Coskun9165c762017-12-04 14:35:24 -0800115 * HLOS device remove callback
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530116 */
Ram Chandra Jangir6577f382016-05-31 12:16:28 +0530117static inline int nss_remove(struct platform_device *nss_dev)
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530118{
Arunkumar T79990cb2015-06-05 10:53:16 +0530119 return nss_hal_remove(nss_dev);
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530120}
121
Stephen Wang90c67de2016-04-26 15:15:59 -0700122#if (NSS_DT_SUPPORT == 1)
123/*
124 * Platform Device ID for NSS core.
125 */
126struct of_device_id nss_dt_ids[] = {
127 { .compatible = "qcom,nss" },
128 { .compatible = "qcom,nss0" },
129 { .compatible = "qcom,nss1" },
130 {},
131};
132MODULE_DEVICE_TABLE(of, nss_dt_ids);
133#endif
134
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530135/*
136 * nss_driver
137 * Platform driver structure for NSS
138 */
139struct platform_driver nss_driver = {
140 .probe = nss_probe,
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800141 .remove = nss_remove,
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530142 .driver = {
143 .name = "qca-nss",
144 .owner = THIS_MODULE,
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800145#if (NSS_DT_SUPPORT == 1)
146 .of_match_table = of_match_ptr(nss_dt_ids),
147#endif
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530148 },
149};
150
Arunkumar T28b2d742015-06-16 22:15:58 +0530151#if (NSS_FREQ_SCALE_SUPPORT == 1)
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530152/*
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530153 * nss_reset_frequency_stats_samples()
154 * Reset all frequency sampling state when auto scaling is turned off.
155 */
Thomas Wud6af3772017-09-01 13:42:28 -0700156static void nss_reset_frequency_stats_samples(void)
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530157{
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.K69fd5992014-01-06 20:58:14 +0530163 nss_runtime_samples.freq_scale_rate_limit_down = 0;
164}
165
166/*
wthomas442c7972013-08-05 14:28:17 -0700167 * nss_current_freq_handler()
168 * Handle Userspace Frequency Change Requests
169 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700170static int nss_current_freq_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
wthomas442c7972013-08-05 14:28:17 -0700171{
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800172 int ret, i;
wthomas626147f2013-09-18 13:12:40 -0700173
174 BUG_ON(!nss_wq);
wthomas442c7972013-08-05 14:28:17 -0700175
176 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
177
Thomas Wuc151f2e2015-09-08 10:59:44 -0700178 if (!*lenp || (*ppos && !write)) {
wthomas626147f2013-09-18 13:12:40 -0700179 printk("Frequency Set to %d\n", nss_cmd_buf.current_freq);
Thomas Wuc151f2e2015-09-08 10:59:44 -0700180 *lenp = 0;
wthomasd39fa822013-08-22 16:44:23 -0700181 return ret;
wthomas442c7972013-08-05 14:28:17 -0700182 }
wthomasd39fa822013-08-22 16:44:23 -0700183
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800184 /*
185 * Check if frequency exists in frequency Table
186 */
187 i = 0;
Thomas Wu7132bd32015-05-07 15:03:06 -0700188 while (i < NSS_FREQ_MAX_SCALE) {
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800189 if (nss_runtime_samples.freq_scale[i].frequency == nss_cmd_buf.current_freq) {
190 break;
191 }
192 i++;
193 }
Thomas Wu7132bd32015-05-07 15:03:06 -0700194 if (i == NSS_FREQ_MAX_SCALE) {
Thomas Wufb6a6842013-10-23 13:14:27 -0700195 printk("Frequency not found. Please check Frequency Table\n");
Thomas Wub7683af2016-07-07 14:19:09 -0700196 nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency;
wthomas626147f2013-09-18 13:12:40 -0700197 return ret;
wthomasd39fa822013-08-22 16:44:23 -0700198 }
199
Thomas Wub7683af2016-07-07 14:19:09 -0700200 /*
201 * Turn off Auto Scale
202 */
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800203 nss_cmd_buf.auto_scale = 0;
204 nss_runtime_samples.freq_scale_ready = 0;
Thomas Wub7683af2016-07-07 14:19:09 -0700205 nss_runtime_samples.freq_scale_index = i;
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800206
Thomas Wu7409bce2014-05-21 10:56:07 -0700207 nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC);
wthomas626147f2013-09-18 13:12:40 -0700208 if (!nss_work) {
209 nss_info("NSS Freq WQ kmalloc fail");
210 return ret;
211 }
Thomas Wud6af3772017-09-01 13:42:28 -0700212 INIT_WORK((struct work_struct *)nss_work, nss_hal_wq_function);
wthomas626147f2013-09-18 13:12:40 -0700213 nss_work->frequency = nss_cmd_buf.current_freq;
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530214 nss_work->stats_enable = 0;
215
Thomas Wub7683af2016-07-07 14:19:09 -0700216 /*
217 * Ensure we start with a fresh set of samples later
218 */
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530219 nss_reset_frequency_stats_samples();
220
wthomas626147f2013-09-18 13:12:40 -0700221 queue_work(nss_wq, (struct work_struct *)nss_work);
222
wthomas442c7972013-08-05 14:28:17 -0700223 return ret;
224}
225
226/*
227 * nss_auto_scale_handler()
228 * Enables or Disable Auto Scaling
229 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700230static int nss_auto_scale_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
wthomas442c7972013-08-05 14:28:17 -0700231{
232 int ret;
233
234 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
235
Thomas Wuc151f2e2015-09-08 10:59:44 -0700236 if (!*lenp || (*ppos && !write)) {
wthomas626147f2013-09-18 13:12:40 -0700237 return ret;
238 }
239
Thomas Wufb6a6842013-10-23 13:14:27 -0700240 if (nss_cmd_buf.auto_scale != 1) {
wthomas626147f2013-09-18 13:12:40 -0700241 /*
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530242 * Is auto scaling currently enabled? If so, send the command to
243 * disable stats reporting to NSS
wthomas626147f2013-09-18 13:12:40 -0700244 */
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530245 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 Wu7409bce2014-05-21 10:56:07 -0700247 nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC);
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530248 if (!nss_work) {
249 nss_info("NSS Freq WQ kmalloc fail");
250 return ret;
251 }
Thomas Wud6af3772017-09-01 13:42:28 -0700252 INIT_WORK((struct work_struct *)nss_work, nss_hal_wq_function);
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530253 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 Wufb6a6842013-10-23 13:14:27 -0700264 return ret;
wthomas626147f2013-09-18 13:12:40 -0700265 }
wthomas442c7972013-08-05 14:28:17 -0700266
Thomas Wufb6a6842013-10-23 13:14:27 -0700267 /*
268 * Auto Scaling is already being done
269 */
270 if (nss_runtime_samples.freq_scale_ready == 1) {
271 return ret;
272 }
273
274 /*
275 * Setup default values - Middle of Freq Scale Band
276 */
277 nss_runtime_samples.freq_scale_index = 1;
278 nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency;
279
Thomas Wu7409bce2014-05-21 10:56:07 -0700280 nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC);
Thomas Wufb6a6842013-10-23 13:14:27 -0700281 if (!nss_work) {
282 nss_info("NSS Freq WQ kmalloc fail");
283 return ret;
284 }
Thomas Wud6af3772017-09-01 13:42:28 -0700285 INIT_WORK((struct work_struct *)nss_work, nss_hal_wq_function);
Thomas Wufb6a6842013-10-23 13:14:27 -0700286 nss_work->frequency = nss_cmd_buf.current_freq;
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530287 nss_work->stats_enable = 1;
Thomas Wufb6a6842013-10-23 13:14:27 -0700288 queue_work(nss_wq, (struct work_struct *)nss_work);
289
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800290 nss_cmd_buf.auto_scale = 0;
Thomas Wufb6a6842013-10-23 13:14:27 -0700291 nss_runtime_samples.freq_scale_ready = 1;
292
wthomas442c7972013-08-05 14:28:17 -0700293 return ret;
294}
295
296/*
297 * nss_get_freq_table_handler()
298 * Display Support Freq and Ex how to Change.
299 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700300static int nss_get_freq_table_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
wthomas442c7972013-08-05 14:28:17 -0700301{
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800302 int ret, i;
wthomas442c7972013-08-05 14:28:17 -0700303
304 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
305
Thomas Wuc151f2e2015-09-08 10:59:44 -0700306 if (write) {
307 return ret;
308 }
309
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800310 printk("Frequency Supported - ");
Thomas Wuc151f2e2015-09-08 10:59:44 -0700311
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800312 i = 0;
Thomas Wu7132bd32015-05-07 15:03:06 -0700313 while (i < NSS_FREQ_MAX_SCALE) {
Thomas Wu6a48ac92017-11-03 10:48:04 -0700314 printk("%d Hz ", nss_runtime_samples.freq_scale[i].frequency);
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800315 i++;
Thomas Wu0a0a9c92013-11-21 15:28:19 -0800316 }
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800317 printk("\n");
wthomas442c7972013-08-05 14:28:17 -0700318
Thomas Wuc151f2e2015-09-08 10:59:44 -0700319 *lenp = 0;
wthomas442c7972013-08-05 14:28:17 -0700320 return ret;
321}
322
323/*
Thomas Wu05495be2013-12-19 14:24:24 -0800324 * nss_get_average_inst_handler()
325 * Display AVG Inst Per Ms.
326 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700327static int nss_get_average_inst_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Thomas Wu05495be2013-12-19 14:24:24 -0800328{
329 int ret;
330
331 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
332
Thomas Wuc151f2e2015-09-08 10:59:44 -0700333 if (write) {
334 return ret;
Thomas Wu05495be2013-12-19 14:24:24 -0800335 }
336
Thomas Wuc151f2e2015-09-08 10:59:44 -0700337 printk("Current Inst Per Ms %x\n", nss_runtime_samples.average);
338
339 *lenp = 0;
Thomas Wu05495be2013-12-19 14:24:24 -0800340 return ret;
341}
Arunkumar T28b2d742015-06-16 22:15:58 +0530342#endif
Thomas Wu05495be2013-12-19 14:24:24 -0800343
Sundarajan Srinivasan758e8f42014-12-08 14:56:24 -0800344#if (NSS_FW_DBG_SUPPORT == 1)
Thomas Wu05495be2013-12-19 14:24:24 -0800345/*
Abhishek Rastogi1626a902013-11-21 17:09:49 +0530346 * nss_debug_handler()
347 * Enable NSS debug output
348 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700349static int nss_debug_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Abhishek Rastogi1626a902013-11-21 17:09:49 +0530350{
351 int ret;
352
353 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
354 if (!ret) {
355 if ((write) && (nss_ctl_debug != 0)) {
356 printk("Enabling NSS SPI Debug\n");
357 nss_hal_debug_enable();
358 }
359 }
360
361 return ret;
362}
Sundarajan Srinivasan758e8f42014-12-08 14:56:24 -0800363#endif
Abhishek Rastogi1626a902013-11-21 17:09:49 +0530364
365/*
Thomas Wu52075f42014-02-06 16:32:42 -0800366 * nss_coredump_handler()
367 * Send Signal To Coredump NSS Cores
368 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700369static int nss_coredump_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Thomas Wu52075f42014-02-06 16:32:42 -0800370{
Guojun Jin32a3c6d2015-05-06 12:27:52 -0700371 struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[NSS_CORE_0];
Thomas Wu52075f42014-02-06 16:32:42 -0800372 int ret;
373
374 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
375 if (!ret) {
Guojun Jin244ecab2017-03-16 16:04:25 -0700376 /*
377 * if nss_cmd_buf.coredump is not 0 or 1, panic will be disabled
378 * when NSS FW crashes, so OEM/ODM have a chance to use mdump
379 * to dump crash dump (coredump) and send dump to us for analysis.
380 */
381 if ((write) && (nss_ctl_debug != 0) && nss_cmd_buf.coredump == 1) {
Thomas Wu52075f42014-02-06 16:32:42 -0800382 printk("Coredumping to DDR\n");
Stephen Wang90c67de2016-04-26 15:15:59 -0700383 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_TRIGGER_COREDUMP);
Thomas Wu52075f42014-02-06 16:32:42 -0800384 }
385 }
386
387 return ret;
388}
389
390/*
Sundarajan Srinivasanf9c4a232014-11-18 13:25:40 -0800391 * nss_jumbo_mru_handler()
392 * Sysctl to modify nss_jumbo_mru
393 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700394static int nss_jumbo_mru_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Sundarajan Srinivasanf9c4a232014-11-18 13:25:40 -0800395{
396 int ret;
397
398 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
399 if (ret) {
400 return ret;
401 }
402
403 if (write) {
404 nss_core_set_jumbo_mru(nss_jumbo_mru);
405 nss_info("jumbo_mru set to %d\n", nss_jumbo_mru);
406 }
407
408 return ret;
409}
410
411/* nss_paged_mode_handler()
412 * Sysctl to modify nss_paged_mode.
413 */
414
Stephen Wang52e6d342016-03-29 15:02:33 -0700415static int nss_paged_mode_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Sundarajan Srinivasanf9c4a232014-11-18 13:25:40 -0800416{
417 int ret;
418
419 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
420 if (ret) {
421 return ret;
422 }
423
424 if (write) {
425 nss_core_set_paged_mode(nss_paged_mode);
426 nss_info("paged_mode set to %d\n", nss_paged_mode);
427 }
428
429 return ret;
430}
431
Casey Chen56c13632018-09-10 17:05:03 -0700432#if (NSS_SKB_REUSE_SUPPORT == 1)
433/*
434 * nss_get_min_reuse_handler()
435 * Sysctl to get min reuse sizes
436 */
437static int nss_get_min_reuse_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
438{
439 int ret;
440 struct nss_ctx_instance *nss_ctx = NULL;
441 uint32_t core_id;
442
443 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
444 if (ret) {
445 return ret;
446 }
447
448 printk("Min SKB reuse sizes - ");
449
450 for (core_id = 0; core_id < NSS_CORE_MAX; core_id++) {
451 nss_ctx = (struct nss_ctx_instance *)&nss_top_main.nss[core_id];
452 printk("core %d: %d ", core_id, nss_core_get_min_reuse(nss_ctx));
453 }
454
455 printk("\n");
456 *lenp = 0;
457 return ret;
458}
459
460/*
461 * nss_max_reuse_handler()
462 * Sysctl to modify nss_max_reuse
463 */
464static int nss_max_reuse_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
465{
466 int ret;
467
468 nss_max_reuse = nss_core_get_max_reuse();
469 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
470 if (ret) {
471 return ret;
472 }
473
474 if (write) {
475 nss_core_set_max_reuse(nss_max_reuse);
476 nss_info("max_reuse set to %d\n", nss_max_reuse);
477 }
478
479 return ret;
480}
481
482/*
483 * sysctl-tuning for NSS driver SKB reuse
484 */
485static struct ctl_table nss_skb_reuse_table[] = {
486 {
487 .procname = "min_sizes",
488 .data = NULL,
489 .maxlen = sizeof(int),
490 .mode = 0644,
491 .proc_handler = &nss_get_min_reuse_handler,
492 },
493 {
494 .procname = "max_size",
495 .data = &nss_max_reuse,
496 .maxlen = sizeof(int),
497 .mode = 0644,
498 .proc_handler = &nss_max_reuse_handler,
499 },
500 { }
501};
502#endif
503
Arunkumar T28b2d742015-06-16 22:15:58 +0530504#if (NSS_FREQ_SCALE_SUPPORT == 1)
Sundarajan Srinivasanf9c4a232014-11-18 13:25:40 -0800505/*
wthomas442c7972013-08-05 14:28:17 -0700506 * sysctl-tuning infrastructure.
507 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700508static struct ctl_table nss_freq_table[] = {
wthomas442c7972013-08-05 14:28:17 -0700509 {
510 .procname = "current_freq",
511 .data = &nss_cmd_buf.current_freq,
512 .maxlen = sizeof(int),
513 .mode = 0644,
514 .proc_handler = &nss_current_freq_handler,
515 },
516 {
517 .procname = "freq_table",
518 .data = &nss_cmd_buf.max_freq,
519 .maxlen = sizeof(int),
520 .mode = 0644,
521 .proc_handler = &nss_get_freq_table_handler,
522 },
523 {
524 .procname = "auto_scale",
525 .data = &nss_cmd_buf.auto_scale,
526 .maxlen = sizeof(int),
527 .mode = 0644,
528 .proc_handler = &nss_auto_scale_handler,
529 },
Thomas Wu05495be2013-12-19 14:24:24 -0800530 {
531 .procname = "inst_per_sec",
532 .data = &nss_cmd_buf.average_inst,
533 .maxlen = sizeof(int),
534 .mode = 0644,
535 .proc_handler = &nss_get_average_inst_handler,
536 },
wthomas442c7972013-08-05 14:28:17 -0700537 { }
538};
Arunkumar T28b2d742015-06-16 22:15:58 +0530539#endif
wthomas442c7972013-08-05 14:28:17 -0700540
Stephen Wang52e6d342016-03-29 15:02:33 -0700541static struct ctl_table nss_general_table[] = {
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +0530542 {
543 .procname = "redirect",
544 .data = &nss_ctl_redirect,
545 .maxlen = sizeof(int),
546 .mode = 0644,
Cemil Coskun9165c762017-12-04 14:35:24 -0800547 .proc_handler = proc_dointvec,
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +0530548 },
Sundarajan Srinivasan758e8f42014-12-08 14:56:24 -0800549#if (NSS_FW_DBG_SUPPORT == 1)
Abhishek Rastogi1626a902013-11-21 17:09:49 +0530550 {
551 .procname = "debug",
552 .data = &nss_ctl_debug,
553 .maxlen = sizeof(int),
554 .mode = 0644,
Cemil Coskun9165c762017-12-04 14:35:24 -0800555 .proc_handler = &nss_debug_handler,
Abhishek Rastogi1626a902013-11-21 17:09:49 +0530556 },
Sundarajan Srinivasan758e8f42014-12-08 14:56:24 -0800557#endif
Thomas Wu52075f42014-02-06 16:32:42 -0800558 {
559 .procname = "coredump",
560 .data = &nss_cmd_buf.coredump,
561 .maxlen = sizeof(int),
562 .mode = 0644,
Cemil Coskun9165c762017-12-04 14:35:24 -0800563 .proc_handler = &nss_coredump_handler,
Thomas Wu52075f42014-02-06 16:32:42 -0800564 },
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530565 {
Saurabh Misra96998db2014-07-10 12:15:48 -0700566 .procname = "logbuf",
567 .data = &nss_ctl_logbuf,
568 .maxlen = sizeof(int),
569 .mode = 0644,
Cemil Coskun9165c762017-12-04 14:35:24 -0800570 .proc_handler = &nss_logbuffer_handler,
Saurabh Misra96998db2014-07-10 12:15:48 -0700571 },
Sundarajan Srinivasanf9c4a232014-11-18 13:25:40 -0800572 {
573 .procname = "jumbo_mru",
574 .data = &nss_jumbo_mru,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = &nss_jumbo_mru_handler,
578 },
579 {
580 .procname = "paged_mode",
581 .data = &nss_paged_mode,
582 .maxlen = sizeof(int),
583 .mode = 0644,
584 .proc_handler = &nss_paged_mode_handler,
585 },
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +0530586 { }
587};
588
Casey Chen56c13632018-09-10 17:05:03 -0700589static struct ctl_table nss_init_dir[] = {
Arunkumar T28b2d742015-06-16 22:15:58 +0530590#if (NSS_FREQ_SCALE_SUPPORT == 1)
wthomas442c7972013-08-05 14:28:17 -0700591 {
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +0530592 .procname = "clock",
593 .mode = 0555,
594 .child = nss_freq_table,
595 },
Arunkumar T28b2d742015-06-16 22:15:58 +0530596#endif
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +0530597 {
598 .procname = "general",
599 .mode = 0555,
600 .child = nss_general_table,
wthomas442c7972013-08-05 14:28:17 -0700601 },
Casey Chen56c13632018-09-10 17:05:03 -0700602#if (NSS_SKB_REUSE_SUPPORT == 1)
603 {
604 .procname = "skb_reuse",
605 .mode = 0555,
606 .child = nss_skb_reuse_table,
607 },
608#endif
wthomas442c7972013-08-05 14:28:17 -0700609 { }
610};
611
Stephen Wang52e6d342016-03-29 15:02:33 -0700612static struct ctl_table nss_root_dir[] = {
wthomas442c7972013-08-05 14:28:17 -0700613 {
614 .procname = "nss",
615 .mode = 0555,
Casey Chen56c13632018-09-10 17:05:03 -0700616 .child = nss_init_dir,
wthomas442c7972013-08-05 14:28:17 -0700617 },
618 { }
619};
620
Stephen Wang52e6d342016-03-29 15:02:33 -0700621static struct ctl_table nss_root[] = {
wthomas442c7972013-08-05 14:28:17 -0700622 {
623 .procname = "dev",
624 .mode = 0555,
625 .child = nss_root_dir,
626 },
627 { }
628};
629
630static struct ctl_table_header *nss_dev_header;
631
632/*
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530633 * nss_init()
634 * Registers nss driver
635 */
636static int __init nss_init(void)
637{
Radha krishna Simha Jiguru3295b8b2017-03-12 10:54:15 +0530638#if (NSS_DT_SUPPORT == 1)
639 struct device_node *cmn = NULL;
640#endif
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530641 nss_info("Init NSS driver");
642
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800643#if (NSS_DT_SUPPORT == 1)
644 /*
Radha krishna Simha Jiguru3295b8b2017-03-12 10:54:15 +0530645 * Get reference to NSS common device node
646 */
647 cmn = of_find_node_by_name(NULL, "nss-common");
648 if (!cmn) {
649 nss_info_always("qca-nss-drv.ko is loaded for symbol link\n");
650 return 0;
651 }
652 of_node_put(cmn);
653
654 /*
Stephen Wang90c67de2016-04-26 15:15:59 -0700655 * Pick up HAL by target information
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800656 */
Stephen Wang90c67de2016-04-26 15:15:59 -0700657#if defined(NSS_HAL_IPQ806X_SUPPORT)
658 if (of_machine_is_compatible("qcom,ipq8064") || of_machine_is_compatible("qcom,ipq8062")) {
659 nss_top_main.hal_ops = &nss_hal_ipq806x_ops;
Stephen Wang5901def2016-05-09 16:21:03 -0700660 nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops;
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800661 }
Stephen Wang90c67de2016-04-26 15:15:59 -0700662#endif
Stephen Wangbe348022016-05-02 17:11:34 -0700663#if defined(NSS_HAL_IPQ807x_SUPPORT)
664 if (of_machine_is_compatible("qcom,ipq807x")) {
665 nss_top_main.hal_ops = &nss_hal_ipq807x_ops;
Stephen Wangdf8323b2016-05-09 22:51:22 -0700666 nss_top_main.data_plane_ops = &nss_data_plane_edma_ops;
Stephen Wangbe348022016-05-02 17:11:34 -0700667 }
668#endif
Suman Ghosh3f940232018-08-17 20:43:03 +0530669#if defined(NSS_HAL_IPQ60XX_SUPPORT)
670 if (of_machine_is_compatible("qcom,ipq6018")) {
671 nss_top_main.hal_ops = &nss_hal_ipq60xx_ops;
672 nss_top_main.data_plane_ops = &nss_data_plane_edma_ops;
673 }
674#endif
Stephen Wang90c67de2016-04-26 15:15:59 -0700675#if defined(NSS_HAL_FSM9010_SUPPORT)
676 if (of_machine_is_compatible("qcom,fsm9010")) {
677 nss_top_main.hal_ops = &nss_hal_fsm9010_ops;
Stephen Wang5901def2016-05-09 16:21:03 -0700678 nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops;
Stephen Wang90c67de2016-04-26 15:15:59 -0700679 }
680#endif
681 if (!nss_top_main.hal_ops) {
682 nss_info_always("No supported HAL compiled on this platform\n");
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800683 return -EFAULT;
684 }
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800685#else
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530686 /*
Stephen Wang90c67de2016-04-26 15:15:59 -0700687 * For banana, only ipq806x is supported
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530688 */
Stephen Wang90c67de2016-04-26 15:15:59 -0700689 nss_top_main.hal_ops = &nss_hal_ipq806x_ops;
Stephen Wang5901def2016-05-09 16:21:03 -0700690 nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops;
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530691
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800692#endif /* NSS_DT_SUPPORT */
Stephen Wang90c67de2016-04-26 15:15:59 -0700693 nss_top_main.nss_hal_common_init_done = false;
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800694
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530695 /*
Stephen Wangb42ddc52015-12-17 18:10:35 -0800696 * Initialize data_plane workqueue
697 */
698 if (nss_data_plane_init_delay_work()) {
699 nss_warning("Error initializing nss_data_plane_workqueue\n");
700 return -EFAULT;
701 }
702
703 /*
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530704 * Enable spin locks
705 */
706 spin_lock_init(&(nss_top_main.lock));
707 spin_lock_init(&(nss_top_main.stats_lock));
c_athandfde2e912017-01-10 15:40:12 +0530708 mutex_init(&(nss_top_main.wq_lock));
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530709
710 /*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530711 * Enable NSS statistics
712 */
713 nss_stats_init();
714
715 /*
wthomas442c7972013-08-05 14:28:17 -0700716 * Register sysctl table.
717 */
718 nss_dev_header = register_sysctl_table(nss_root);
719
720 /*
Vijay Dewangan9db18752014-09-15 16:25:01 -0700721 * Registering sysctl for ipv4/6 specific config.
722 */
723 nss_ipv4_register_sysctl();
724 nss_ipv6_register_sysctl();
725
Vijay Dewanganac7efc42015-02-09 16:04:53 -0800726 /*
Stephen Wang49b474b2016-03-25 10:40:30 -0700727 * Registering sysctl for n2h specific config.
Vijay Dewanganac7efc42015-02-09 16:04:53 -0800728 */
Stephen Wang49b474b2016-03-25 10:40:30 -0700729 nss_n2h_register_sysctl();
Vijay Dewanganac7efc42015-02-09 16:04:53 -0800730
Vijay Dewangan9db18752014-09-15 16:25:01 -0700731 /*
Cemil Coskun9165c762017-12-04 14:35:24 -0800732 * Registering sysctl for rps specific config.
733 */
734 nss_rps_register_sysctl();
735
736 /*
Cemil Coskun497f7ec2018-07-12 14:08:53 -0700737 * Registering sysctl for c2c_tx specific config.
738 */
739 nss_c2c_tx_register_sysctl();
740
741 /*
Jackson Bockusc2a4e682017-06-23 11:59:29 -0700742 * Register sysctl for project config
743 */
744 nss_project_register_sysctl();
745
746 /*
wthomas626147f2013-09-18 13:12:40 -0700747 * Setup Runtime Sample values
748 */
wthomas626147f2013-09-18 13:12:40 -0700749 nss_runtime_samples.freq_scale_index = 1;
750 nss_runtime_samples.freq_scale_ready = 0;
Thomas Wu9681f7e2013-11-06 13:12:57 -0800751 nss_runtime_samples.freq_scale_rate_limit_down = 0;
wthomas626147f2013-09-18 13:12:40 -0700752 nss_runtime_samples.buffer_index = 0;
753 nss_runtime_samples.sum = 0;
754 nss_runtime_samples.sample_count = 0;
755 nss_runtime_samples.average = 0;
756 nss_runtime_samples.message_rate_limit = 0;
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530757 nss_runtime_samples.initialized = 0;
wthomas626147f2013-09-18 13:12:40 -0700758
Thomas Wu05495be2013-12-19 14:24:24 -0800759 nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency;
760
wthomas626147f2013-09-18 13:12:40 -0700761 /*
762 * Initial Workqueue
763 */
764 nss_wq = create_workqueue("nss_freq_queue");
765
Thomas Wu0d112192015-04-13 11:37:22 -0700766#if (NSS_PM_SUPPORT == 1)
wthomas626147f2013-09-18 13:12:40 -0700767 /*
Pamidipati, Vijay7f413b52013-09-24 19:07:12 +0530768 * Initialize NSS Bus PM module
769 */
770 nss_pm_init();
771
772 /*
Pamidipati, Vijay5d27d812013-11-22 16:48:11 +0530773 * Register with Bus driver
774 */
775 pm_client = nss_pm_client_register(NSS_PM_CLIENT_NETAP);
776 if (!pm_client) {
777 nss_warning("Error registering with PM driver");
778 }
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800779#endif
Pamidipati, Vijay5d27d812013-11-22 16:48:11 +0530780
781 /*
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +0530782 * Initialize mtu size needed as start
783 */
Stephen Wanga428d0b2017-01-12 21:30:01 -0800784 nss_top_main.prev_mtu_sz = ETH_DATA_LEN;
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +0530785
786 /*
Guojun Jin1cb79522015-06-22 22:34:22 -0700787 * register panic handler and timeout control
788 */
789 nss_coredump_notify_register();
790 nss_coredump_init_delay_work();
791
792 /*
Stephen Wang1f6ad492016-01-27 23:42:06 -0800793 * Init capwap
794 */
795 nss_capwap_init();
796
797 /*
Yu Huang6b2f0be2017-10-18 16:11:49 -0700798 * Init QRFS
799 */
800 nss_qrfs_init();
801
802 /*
Cemil Coskun1c9c3922018-01-23 16:21:49 -0800803 * Init c2c_tx
804 */
805 nss_c2c_tx_init();
806
807 /*
Amit Gupta316729b2016-08-12 12:21:15 +0530808 * INIT ppe on supported platform
809 */
Suman Ghosh3f940232018-08-17 20:43:03 +0530810 if (of_machine_is_compatible("qcom,ipq807x") || of_machine_is_compatible("qcom,ipq6018")) {
Amit Gupta316729b2016-08-12 12:21:15 +0530811 nss_ppe_init();
812 }
813
814 /*
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530815 * Register platform_driver
816 */
817 return platform_driver_register(&nss_driver);
818}
819
820/*
821 * nss_cleanup()
822 * Unregisters nss driver
823 */
824static void __exit nss_cleanup(void)
825{
826 nss_info("Exit NSS driver");
wthomas442c7972013-08-05 14:28:17 -0700827
828 if (nss_dev_header)
829 unregister_sysctl_table(nss_dev_header);
830
Vijay Dewangan9db18752014-09-15 16:25:01 -0700831 /*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800832 * Unregister n2h specific sysctl
833 */
Stephen Wang49b474b2016-03-25 10:40:30 -0700834 nss_n2h_unregister_sysctl();
Vijay Dewangan488e5372014-12-29 21:40:11 -0800835
836 /*
Cemil Coskun9165c762017-12-04 14:35:24 -0800837 * Unregister rps specific sysctl
838 */
839 nss_rps_unregister_sysctl();
840
841 /*
Cemil Coskun497f7ec2018-07-12 14:08:53 -0700842 * Unregister c2c_tx specific sysctl
843 */
844 nss_c2c_tx_unregister_sysctl();
845
846 /*
Vijay Dewangan9db18752014-09-15 16:25:01 -0700847 * Unregister ipv4/6 specific sysctl
848 */
849 nss_ipv4_unregister_sysctl();
850 nss_ipv6_unregister_sysctl();
851
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700852 /*
853 * Free Memory allocated for connection tables
854 */
855 nss_ipv4_free_conn_tables();
856 nss_ipv6_free_conn_tables();
857
Jackson Bockusc2a4e682017-06-23 11:59:29 -0700858 nss_project_unregister_sysctl();
Stephen Wangb42ddc52015-12-17 18:10:35 -0800859 nss_data_plane_destroy_delay_work();
860
Amit Gupta316729b2016-08-12 12:21:15 +0530861 /*
862 * cleanup ppe on supported platform
863 */
Suman Ghosh3f940232018-08-17 20:43:03 +0530864 if (of_machine_is_compatible("qcom,ipq807x") || of_machine_is_compatible("qcom,ipq6018")) {
Amit Gupta316729b2016-08-12 12:21:15 +0530865 nss_ppe_free();
866 }
867
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530868 platform_driver_unregister(&nss_driver);
869}
870
871module_init(nss_init);
872module_exit(nss_cleanup);
873
874MODULE_DESCRIPTION("QCA NSS Driver");
875MODULE_AUTHOR("Qualcomm Atheros Inc");
876MODULE_LICENSE("Dual BSD/GPL");