blob: 870990d71d0935d74cf1a2206b8689db0898e390 [file] [log] [blame]
Radhakrishna Jiguru1c9b2252013-08-27 23:57:48 +05301/*
2 **************************************************************************
Stephen Wanga428d0b2017-01-12 21:30:01 -08003 * Copyright (c) 2013-2017, 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;
Radha krishna Simha Jiguru28a0a252015-08-04 16:34:09 +053062int nss_skip_nw_process = 0x0;
63module_param(nss_skip_nw_process, int, S_IRUGO);
Abhishek Rastogibc74e432013-04-02 10:28:22 +053064
65/*
Pamidipati, Vijay5d27d812013-11-22 16:48:11 +053066 * PM client handle
67 */
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080068#if (NSS_PM_SUPPORT == 1)
Pamidipati, Vijay5d27d812013-11-22 16:48:11 +053069static void *pm_client;
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080070#endif
Pamidipati, Vijay5d27d812013-11-22 16:48:11 +053071
72/*
wthomas626147f2013-09-18 13:12:40 -070073 * Handler to send NSS messages
74 */
Thomas Wufb6a6842013-10-23 13:14:27 -070075struct clk *nss_core0_clk;
Thomas Wu63bcff62017-03-20 11:44:41 -070076struct clk *nss_core1_clk;
wthomas626147f2013-09-18 13:12:40 -070077
78/*
Thomas Wucd6b35a2015-07-14 10:17:48 -070079 * Handle fabric requests - only on new kernel
80 */
81#if (NSS_DT_SUPPORT == 1)
82struct clk *nss_fab0_clk;
83struct clk *nss_fab1_clk;
84#endif
85
86/*
Abhishek Rastogibc74e432013-04-02 10:28:22 +053087 * Top level nss context structure
88 */
89struct nss_top_instance nss_top_main;
wthomas442c7972013-08-05 14:28:17 -070090struct nss_cmd_buffer nss_cmd_buf;
wthomas626147f2013-09-18 13:12:40 -070091struct nss_runtime_sampling nss_runtime_samples;
92struct workqueue_struct *nss_wq;
93
94/*
95 * Work Queue to handle messages to Kernel
96 */
97nss_work_t *nss_work;
Abhishek Rastogibc74e432013-04-02 10:28:22 +053098
Arunkumar T79990cb2015-06-05 10:53:16 +053099extern struct of_device_id nss_dt_ids[];
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530100
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530101/*
102 * nss_probe()
Cemil Coskun9165c762017-12-04 14:35:24 -0800103 * HLOS device probe callback
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530104 */
Ram Chandra Jangir6577f382016-05-31 12:16:28 +0530105static inline int nss_probe(struct platform_device *nss_dev)
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530106{
Arunkumar T79990cb2015-06-05 10:53:16 +0530107 return nss_hal_probe(nss_dev);
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530108}
109
110/*
111 * nss_remove()
Cemil Coskun9165c762017-12-04 14:35:24 -0800112 * HLOS device remove callback
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530113 */
Ram Chandra Jangir6577f382016-05-31 12:16:28 +0530114static inline int nss_remove(struct platform_device *nss_dev)
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530115{
Arunkumar T79990cb2015-06-05 10:53:16 +0530116 return nss_hal_remove(nss_dev);
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530117}
118
Stephen Wang90c67de2016-04-26 15:15:59 -0700119#if (NSS_DT_SUPPORT == 1)
120/*
121 * Platform Device ID for NSS core.
122 */
123struct of_device_id nss_dt_ids[] = {
124 { .compatible = "qcom,nss" },
125 { .compatible = "qcom,nss0" },
126 { .compatible = "qcom,nss1" },
127 {},
128};
129MODULE_DEVICE_TABLE(of, nss_dt_ids);
130#endif
131
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530132/*
133 * nss_driver
134 * Platform driver structure for NSS
135 */
136struct platform_driver nss_driver = {
137 .probe = nss_probe,
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800138 .remove = nss_remove,
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530139 .driver = {
140 .name = "qca-nss",
141 .owner = THIS_MODULE,
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800142#if (NSS_DT_SUPPORT == 1)
143 .of_match_table = of_match_ptr(nss_dt_ids),
144#endif
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530145 },
146};
147
Arunkumar T28b2d742015-06-16 22:15:58 +0530148#if (NSS_FREQ_SCALE_SUPPORT == 1)
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530149/*
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530150 * nss_reset_frequency_stats_samples()
151 * Reset all frequency sampling state when auto scaling is turned off.
152 */
Thomas Wud6af3772017-09-01 13:42:28 -0700153static void nss_reset_frequency_stats_samples(void)
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530154{
155 nss_runtime_samples.buffer_index = 0;
156 nss_runtime_samples.sum = 0;
157 nss_runtime_samples.average = 0;
158 nss_runtime_samples.sample_count = 0;
159 nss_runtime_samples.message_rate_limit = 0;
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530160 nss_runtime_samples.freq_scale_rate_limit_down = 0;
161}
162
163/*
wthomas442c7972013-08-05 14:28:17 -0700164 * nss_current_freq_handler()
165 * Handle Userspace Frequency Change Requests
166 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700167static 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 -0700168{
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800169 int ret, i;
wthomas626147f2013-09-18 13:12:40 -0700170
171 BUG_ON(!nss_wq);
wthomas442c7972013-08-05 14:28:17 -0700172
173 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
174
Thomas Wuc151f2e2015-09-08 10:59:44 -0700175 if (!*lenp || (*ppos && !write)) {
wthomas626147f2013-09-18 13:12:40 -0700176 printk("Frequency Set to %d\n", nss_cmd_buf.current_freq);
Thomas Wuc151f2e2015-09-08 10:59:44 -0700177 *lenp = 0;
wthomasd39fa822013-08-22 16:44:23 -0700178 return ret;
wthomas442c7972013-08-05 14:28:17 -0700179 }
wthomasd39fa822013-08-22 16:44:23 -0700180
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800181 /*
182 * Check if frequency exists in frequency Table
183 */
184 i = 0;
Thomas Wu7132bd32015-05-07 15:03:06 -0700185 while (i < NSS_FREQ_MAX_SCALE) {
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800186 if (nss_runtime_samples.freq_scale[i].frequency == nss_cmd_buf.current_freq) {
187 break;
188 }
189 i++;
190 }
Thomas Wu7132bd32015-05-07 15:03:06 -0700191 if (i == NSS_FREQ_MAX_SCALE) {
Thomas Wufb6a6842013-10-23 13:14:27 -0700192 printk("Frequency not found. Please check Frequency Table\n");
Thomas Wub7683af2016-07-07 14:19:09 -0700193 nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency;
wthomas626147f2013-09-18 13:12:40 -0700194 return ret;
wthomasd39fa822013-08-22 16:44:23 -0700195 }
196
Thomas Wub7683af2016-07-07 14:19:09 -0700197 /*
198 * Turn off Auto Scale
199 */
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800200 nss_cmd_buf.auto_scale = 0;
201 nss_runtime_samples.freq_scale_ready = 0;
Thomas Wub7683af2016-07-07 14:19:09 -0700202 nss_runtime_samples.freq_scale_index = i;
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800203
Thomas Wu7409bce2014-05-21 10:56:07 -0700204 nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC);
wthomas626147f2013-09-18 13:12:40 -0700205 if (!nss_work) {
206 nss_info("NSS Freq WQ kmalloc fail");
207 return ret;
208 }
Thomas Wud6af3772017-09-01 13:42:28 -0700209 INIT_WORK((struct work_struct *)nss_work, nss_hal_wq_function);
wthomas626147f2013-09-18 13:12:40 -0700210 nss_work->frequency = nss_cmd_buf.current_freq;
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530211 nss_work->stats_enable = 0;
212
Thomas Wub7683af2016-07-07 14:19:09 -0700213 /*
214 * Ensure we start with a fresh set of samples later
215 */
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530216 nss_reset_frequency_stats_samples();
217
wthomas626147f2013-09-18 13:12:40 -0700218 queue_work(nss_wq, (struct work_struct *)nss_work);
219
wthomas442c7972013-08-05 14:28:17 -0700220 return ret;
221}
222
223/*
224 * nss_auto_scale_handler()
225 * Enables or Disable Auto Scaling
226 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700227static 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 -0700228{
229 int ret;
230
231 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
232
Thomas Wuc151f2e2015-09-08 10:59:44 -0700233 if (!*lenp || (*ppos && !write)) {
wthomas626147f2013-09-18 13:12:40 -0700234 return ret;
235 }
236
Thomas Wufb6a6842013-10-23 13:14:27 -0700237 if (nss_cmd_buf.auto_scale != 1) {
wthomas626147f2013-09-18 13:12:40 -0700238 /*
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530239 * Is auto scaling currently enabled? If so, send the command to
240 * disable stats reporting to NSS
wthomas626147f2013-09-18 13:12:40 -0700241 */
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530242 if (nss_runtime_samples.freq_scale_ready != 0) {
243 nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency;
Thomas Wu7409bce2014-05-21 10:56:07 -0700244 nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC);
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530245 if (!nss_work) {
246 nss_info("NSS Freq WQ kmalloc fail");
247 return ret;
248 }
Thomas Wud6af3772017-09-01 13:42:28 -0700249 INIT_WORK((struct work_struct *)nss_work, nss_hal_wq_function);
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530250 nss_work->frequency = nss_cmd_buf.current_freq;
251 nss_work->stats_enable = 0;
252 queue_work(nss_wq, (struct work_struct *)nss_work);
253 nss_runtime_samples.freq_scale_ready = 0;
254
255 /*
256 * The current samples would be stale later when scaling is
257 * enabled again, hence reset them
258 */
259 nss_reset_frequency_stats_samples();
260 }
Thomas Wufb6a6842013-10-23 13:14:27 -0700261 return ret;
wthomas626147f2013-09-18 13:12:40 -0700262 }
wthomas442c7972013-08-05 14:28:17 -0700263
Thomas Wufb6a6842013-10-23 13:14:27 -0700264 /*
265 * Auto Scaling is already being done
266 */
267 if (nss_runtime_samples.freq_scale_ready == 1) {
268 return ret;
269 }
270
271 /*
272 * Setup default values - Middle of Freq Scale Band
273 */
274 nss_runtime_samples.freq_scale_index = 1;
275 nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency;
276
Thomas Wu7409bce2014-05-21 10:56:07 -0700277 nss_work = (nss_work_t *)kmalloc(sizeof(nss_work_t), GFP_ATOMIC);
Thomas Wufb6a6842013-10-23 13:14:27 -0700278 if (!nss_work) {
279 nss_info("NSS Freq WQ kmalloc fail");
280 return ret;
281 }
Thomas Wud6af3772017-09-01 13:42:28 -0700282 INIT_WORK((struct work_struct *)nss_work, nss_hal_wq_function);
Thomas Wufb6a6842013-10-23 13:14:27 -0700283 nss_work->frequency = nss_cmd_buf.current_freq;
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530284 nss_work->stats_enable = 1;
Thomas Wufb6a6842013-10-23 13:14:27 -0700285 queue_work(nss_wq, (struct work_struct *)nss_work);
286
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800287 nss_cmd_buf.auto_scale = 0;
Thomas Wufb6a6842013-10-23 13:14:27 -0700288 nss_runtime_samples.freq_scale_ready = 1;
289
wthomas442c7972013-08-05 14:28:17 -0700290 return ret;
291}
292
293/*
294 * nss_get_freq_table_handler()
295 * Display Support Freq and Ex how to Change.
296 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700297static 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 -0700298{
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800299 int ret, i;
wthomas442c7972013-08-05 14:28:17 -0700300
301 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
302
Thomas Wuc151f2e2015-09-08 10:59:44 -0700303 if (write) {
304 return ret;
305 }
306
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800307 printk("Frequency Supported - ");
Thomas Wuc151f2e2015-09-08 10:59:44 -0700308
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800309 i = 0;
Thomas Wu7132bd32015-05-07 15:03:06 -0700310 while (i < NSS_FREQ_MAX_SCALE) {
Thomas Wu6a48ac92017-11-03 10:48:04 -0700311 printk("%d Hz ", nss_runtime_samples.freq_scale[i].frequency);
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800312 i++;
Thomas Wu0a0a9c92013-11-21 15:28:19 -0800313 }
Thomas Wu0e2fc4f2015-03-04 15:39:14 -0800314 printk("\n");
wthomas442c7972013-08-05 14:28:17 -0700315
Thomas Wuc151f2e2015-09-08 10:59:44 -0700316 *lenp = 0;
wthomas442c7972013-08-05 14:28:17 -0700317 return ret;
318}
319
320/*
Thomas Wu05495be2013-12-19 14:24:24 -0800321 * nss_get_average_inst_handler()
322 * Display AVG Inst Per Ms.
323 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700324static 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 -0800325{
326 int ret;
327
328 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
329
Thomas Wuc151f2e2015-09-08 10:59:44 -0700330 if (write) {
331 return ret;
Thomas Wu05495be2013-12-19 14:24:24 -0800332 }
333
Thomas Wuc151f2e2015-09-08 10:59:44 -0700334 printk("Current Inst Per Ms %x\n", nss_runtime_samples.average);
335
336 *lenp = 0;
Thomas Wu05495be2013-12-19 14:24:24 -0800337 return ret;
338}
Arunkumar T28b2d742015-06-16 22:15:58 +0530339#endif
Thomas Wu05495be2013-12-19 14:24:24 -0800340
Sundarajan Srinivasan758e8f42014-12-08 14:56:24 -0800341#if (NSS_FW_DBG_SUPPORT == 1)
Thomas Wu05495be2013-12-19 14:24:24 -0800342/*
Abhishek Rastogi1626a902013-11-21 17:09:49 +0530343 * nss_debug_handler()
344 * Enable NSS debug output
345 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700346static 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 +0530347{
348 int ret;
349
350 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
351 if (!ret) {
352 if ((write) && (nss_ctl_debug != 0)) {
353 printk("Enabling NSS SPI Debug\n");
354 nss_hal_debug_enable();
355 }
356 }
357
358 return ret;
359}
Sundarajan Srinivasan758e8f42014-12-08 14:56:24 -0800360#endif
Abhishek Rastogi1626a902013-11-21 17:09:49 +0530361
362/*
Thomas Wu52075f42014-02-06 16:32:42 -0800363 * nss_coredump_handler()
364 * Send Signal To Coredump NSS Cores
365 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700366static 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 -0800367{
Guojun Jin32a3c6d2015-05-06 12:27:52 -0700368 struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[NSS_CORE_0];
Thomas Wu52075f42014-02-06 16:32:42 -0800369 int ret;
370
371 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
372 if (!ret) {
Guojun Jin244ecab2017-03-16 16:04:25 -0700373 /*
374 * if nss_cmd_buf.coredump is not 0 or 1, panic will be disabled
375 * when NSS FW crashes, so OEM/ODM have a chance to use mdump
376 * to dump crash dump (coredump) and send dump to us for analysis.
377 */
378 if ((write) && (nss_ctl_debug != 0) && nss_cmd_buf.coredump == 1) {
Thomas Wu52075f42014-02-06 16:32:42 -0800379 printk("Coredumping to DDR\n");
Stephen Wang90c67de2016-04-26 15:15:59 -0700380 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_TRIGGER_COREDUMP);
Thomas Wu52075f42014-02-06 16:32:42 -0800381 }
382 }
383
384 return ret;
385}
386
387/*
Sundarajan Srinivasanf9c4a232014-11-18 13:25:40 -0800388 * nss_jumbo_mru_handler()
389 * Sysctl to modify nss_jumbo_mru
390 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700391static 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 -0800392{
393 int ret;
394
395 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
396 if (ret) {
397 return ret;
398 }
399
400 if (write) {
401 nss_core_set_jumbo_mru(nss_jumbo_mru);
402 nss_info("jumbo_mru set to %d\n", nss_jumbo_mru);
403 }
404
405 return ret;
406}
407
408/* nss_paged_mode_handler()
409 * Sysctl to modify nss_paged_mode.
410 */
411
Stephen Wang52e6d342016-03-29 15:02:33 -0700412static 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 -0800413{
414 int ret;
415
416 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
417 if (ret) {
418 return ret;
419 }
420
421 if (write) {
422 nss_core_set_paged_mode(nss_paged_mode);
423 nss_info("paged_mode set to %d\n", nss_paged_mode);
424 }
425
426 return ret;
427}
428
Arunkumar T28b2d742015-06-16 22:15:58 +0530429#if (NSS_FREQ_SCALE_SUPPORT == 1)
Sundarajan Srinivasanf9c4a232014-11-18 13:25:40 -0800430/*
wthomas442c7972013-08-05 14:28:17 -0700431 * sysctl-tuning infrastructure.
432 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700433static struct ctl_table nss_freq_table[] = {
wthomas442c7972013-08-05 14:28:17 -0700434 {
435 .procname = "current_freq",
436 .data = &nss_cmd_buf.current_freq,
437 .maxlen = sizeof(int),
438 .mode = 0644,
439 .proc_handler = &nss_current_freq_handler,
440 },
441 {
442 .procname = "freq_table",
443 .data = &nss_cmd_buf.max_freq,
444 .maxlen = sizeof(int),
445 .mode = 0644,
446 .proc_handler = &nss_get_freq_table_handler,
447 },
448 {
449 .procname = "auto_scale",
450 .data = &nss_cmd_buf.auto_scale,
451 .maxlen = sizeof(int),
452 .mode = 0644,
453 .proc_handler = &nss_auto_scale_handler,
454 },
Thomas Wu05495be2013-12-19 14:24:24 -0800455 {
456 .procname = "inst_per_sec",
457 .data = &nss_cmd_buf.average_inst,
458 .maxlen = sizeof(int),
459 .mode = 0644,
460 .proc_handler = &nss_get_average_inst_handler,
461 },
wthomas442c7972013-08-05 14:28:17 -0700462 { }
463};
Arunkumar T28b2d742015-06-16 22:15:58 +0530464#endif
wthomas442c7972013-08-05 14:28:17 -0700465
Stephen Wang52e6d342016-03-29 15:02:33 -0700466static struct ctl_table nss_general_table[] = {
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +0530467 {
468 .procname = "redirect",
469 .data = &nss_ctl_redirect,
470 .maxlen = sizeof(int),
471 .mode = 0644,
Cemil Coskun9165c762017-12-04 14:35:24 -0800472 .proc_handler = proc_dointvec,
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +0530473 },
Sundarajan Srinivasan758e8f42014-12-08 14:56:24 -0800474#if (NSS_FW_DBG_SUPPORT == 1)
Abhishek Rastogi1626a902013-11-21 17:09:49 +0530475 {
476 .procname = "debug",
477 .data = &nss_ctl_debug,
478 .maxlen = sizeof(int),
479 .mode = 0644,
Cemil Coskun9165c762017-12-04 14:35:24 -0800480 .proc_handler = &nss_debug_handler,
Abhishek Rastogi1626a902013-11-21 17:09:49 +0530481 },
Sundarajan Srinivasan758e8f42014-12-08 14:56:24 -0800482#endif
Thomas Wu52075f42014-02-06 16:32:42 -0800483 {
484 .procname = "coredump",
485 .data = &nss_cmd_buf.coredump,
486 .maxlen = sizeof(int),
487 .mode = 0644,
Cemil Coskun9165c762017-12-04 14:35:24 -0800488 .proc_handler = &nss_coredump_handler,
Thomas Wu52075f42014-02-06 16:32:42 -0800489 },
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530490 {
Saurabh Misra96998db2014-07-10 12:15:48 -0700491 .procname = "logbuf",
492 .data = &nss_ctl_logbuf,
493 .maxlen = sizeof(int),
494 .mode = 0644,
Cemil Coskun9165c762017-12-04 14:35:24 -0800495 .proc_handler = &nss_logbuffer_handler,
Saurabh Misra96998db2014-07-10 12:15:48 -0700496 },
Sundarajan Srinivasanf9c4a232014-11-18 13:25:40 -0800497 {
498 .procname = "jumbo_mru",
499 .data = &nss_jumbo_mru,
500 .maxlen = sizeof(int),
501 .mode = 0644,
502 .proc_handler = &nss_jumbo_mru_handler,
503 },
504 {
505 .procname = "paged_mode",
506 .data = &nss_paged_mode,
507 .maxlen = sizeof(int),
508 .mode = 0644,
509 .proc_handler = &nss_paged_mode_handler,
510 },
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +0530511 { }
512};
513
Stephen Wang52e6d342016-03-29 15:02:33 -0700514static struct ctl_table nss_clock_dir[] = {
Arunkumar T28b2d742015-06-16 22:15:58 +0530515#if (NSS_FREQ_SCALE_SUPPORT == 1)
wthomas442c7972013-08-05 14:28:17 -0700516 {
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +0530517 .procname = "clock",
518 .mode = 0555,
519 .child = nss_freq_table,
520 },
Arunkumar T28b2d742015-06-16 22:15:58 +0530521#endif
Abhishek Rastogi5cd2e4c2013-11-13 18:09:08 +0530522 {
523 .procname = "general",
524 .mode = 0555,
525 .child = nss_general_table,
wthomas442c7972013-08-05 14:28:17 -0700526 },
527 { }
528};
529
Stephen Wang52e6d342016-03-29 15:02:33 -0700530static struct ctl_table nss_root_dir[] = {
wthomas442c7972013-08-05 14:28:17 -0700531 {
532 .procname = "nss",
533 .mode = 0555,
534 .child = nss_clock_dir,
535 },
536 { }
537};
538
Stephen Wang52e6d342016-03-29 15:02:33 -0700539static struct ctl_table nss_root[] = {
wthomas442c7972013-08-05 14:28:17 -0700540 {
541 .procname = "dev",
542 .mode = 0555,
543 .child = nss_root_dir,
544 },
545 { }
546};
547
548static struct ctl_table_header *nss_dev_header;
549
550/*
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530551 * nss_init()
552 * Registers nss driver
553 */
554static int __init nss_init(void)
555{
Radha krishna Simha Jiguru3295b8b2017-03-12 10:54:15 +0530556#if (NSS_DT_SUPPORT == 1)
557 struct device_node *cmn = NULL;
558#endif
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530559 nss_info("Init NSS driver");
560
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800561#if (NSS_DT_SUPPORT == 1)
562 /*
Radha krishna Simha Jiguru3295b8b2017-03-12 10:54:15 +0530563 * Get reference to NSS common device node
564 */
565 cmn = of_find_node_by_name(NULL, "nss-common");
566 if (!cmn) {
567 nss_info_always("qca-nss-drv.ko is loaded for symbol link\n");
568 return 0;
569 }
570 of_node_put(cmn);
571
572 /*
Stephen Wang90c67de2016-04-26 15:15:59 -0700573 * Pick up HAL by target information
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800574 */
Stephen Wang90c67de2016-04-26 15:15:59 -0700575#if defined(NSS_HAL_IPQ806X_SUPPORT)
576 if (of_machine_is_compatible("qcom,ipq8064") || of_machine_is_compatible("qcom,ipq8062")) {
577 nss_top_main.hal_ops = &nss_hal_ipq806x_ops;
Stephen Wang5901def2016-05-09 16:21:03 -0700578 nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops;
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800579 }
Stephen Wang90c67de2016-04-26 15:15:59 -0700580#endif
Stephen Wangbe348022016-05-02 17:11:34 -0700581#if defined(NSS_HAL_IPQ807x_SUPPORT)
582 if (of_machine_is_compatible("qcom,ipq807x")) {
583 nss_top_main.hal_ops = &nss_hal_ipq807x_ops;
Stephen Wangdf8323b2016-05-09 22:51:22 -0700584 nss_top_main.data_plane_ops = &nss_data_plane_edma_ops;
Stephen Wangbe348022016-05-02 17:11:34 -0700585 }
586#endif
Stephen Wang90c67de2016-04-26 15:15:59 -0700587#if defined(NSS_HAL_FSM9010_SUPPORT)
588 if (of_machine_is_compatible("qcom,fsm9010")) {
589 nss_top_main.hal_ops = &nss_hal_fsm9010_ops;
Stephen Wang5901def2016-05-09 16:21:03 -0700590 nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops;
Stephen Wang90c67de2016-04-26 15:15:59 -0700591 }
592#endif
593 if (!nss_top_main.hal_ops) {
594 nss_info_always("No supported HAL compiled on this platform\n");
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800595 return -EFAULT;
596 }
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800597#else
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530598 /*
Stephen Wang90c67de2016-04-26 15:15:59 -0700599 * For banana, only ipq806x is supported
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530600 */
Stephen Wang90c67de2016-04-26 15:15:59 -0700601 nss_top_main.hal_ops = &nss_hal_ipq806x_ops;
Stephen Wang5901def2016-05-09 16:21:03 -0700602 nss_top_main.data_plane_ops = &nss_data_plane_gmac_ops;
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530603
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800604#endif /* NSS_DT_SUPPORT */
Stephen Wang90c67de2016-04-26 15:15:59 -0700605 nss_top_main.nss_hal_common_init_done = false;
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800606
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530607 /*
Stephen Wangb42ddc52015-12-17 18:10:35 -0800608 * Initialize data_plane workqueue
609 */
610 if (nss_data_plane_init_delay_work()) {
611 nss_warning("Error initializing nss_data_plane_workqueue\n");
612 return -EFAULT;
613 }
614
615 /*
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530616 * Enable spin locks
617 */
618 spin_lock_init(&(nss_top_main.lock));
619 spin_lock_init(&(nss_top_main.stats_lock));
c_athandfde2e912017-01-10 15:40:12 +0530620 mutex_init(&(nss_top_main.wq_lock));
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530621
622 /*
Abhishek Rastogi38cffff2013-06-02 11:25:47 +0530623 * Enable NSS statistics
624 */
625 nss_stats_init();
626
627 /*
wthomas442c7972013-08-05 14:28:17 -0700628 * Register sysctl table.
629 */
630 nss_dev_header = register_sysctl_table(nss_root);
631
632 /*
Vijay Dewangan9db18752014-09-15 16:25:01 -0700633 * Registering sysctl for ipv4/6 specific config.
634 */
635 nss_ipv4_register_sysctl();
636 nss_ipv6_register_sysctl();
637
Vijay Dewanganac7efc42015-02-09 16:04:53 -0800638 /*
Stephen Wang49b474b2016-03-25 10:40:30 -0700639 * Registering sysctl for n2h specific config.
Vijay Dewanganac7efc42015-02-09 16:04:53 -0800640 */
Stephen Wang49b474b2016-03-25 10:40:30 -0700641 nss_n2h_register_sysctl();
Vijay Dewanganac7efc42015-02-09 16:04:53 -0800642
Vijay Dewangan9db18752014-09-15 16:25:01 -0700643 /*
Cemil Coskun9165c762017-12-04 14:35:24 -0800644 * Registering sysctl for rps specific config.
645 */
646 nss_rps_register_sysctl();
647
648 /*
Jackson Bockusc2a4e682017-06-23 11:59:29 -0700649 * Register sysctl for project config
650 */
651 nss_project_register_sysctl();
652
653 /*
wthomas626147f2013-09-18 13:12:40 -0700654 * Setup Runtime Sample values
655 */
wthomas626147f2013-09-18 13:12:40 -0700656 nss_runtime_samples.freq_scale_index = 1;
657 nss_runtime_samples.freq_scale_ready = 0;
Thomas Wu9681f7e2013-11-06 13:12:57 -0800658 nss_runtime_samples.freq_scale_rate_limit_down = 0;
wthomas626147f2013-09-18 13:12:40 -0700659 nss_runtime_samples.buffer_index = 0;
660 nss_runtime_samples.sum = 0;
661 nss_runtime_samples.sample_count = 0;
662 nss_runtime_samples.average = 0;
663 nss_runtime_samples.message_rate_limit = 0;
Kiran Kumar C.S.K69fd5992014-01-06 20:58:14 +0530664 nss_runtime_samples.initialized = 0;
wthomas626147f2013-09-18 13:12:40 -0700665
Thomas Wu05495be2013-12-19 14:24:24 -0800666 nss_cmd_buf.current_freq = nss_runtime_samples.freq_scale[nss_runtime_samples.freq_scale_index].frequency;
667
wthomas626147f2013-09-18 13:12:40 -0700668 /*
669 * Initial Workqueue
670 */
671 nss_wq = create_workqueue("nss_freq_queue");
672
Thomas Wu0d112192015-04-13 11:37:22 -0700673#if (NSS_PM_SUPPORT == 1)
wthomas626147f2013-09-18 13:12:40 -0700674 /*
Pamidipati, Vijay7f413b52013-09-24 19:07:12 +0530675 * Initialize NSS Bus PM module
676 */
677 nss_pm_init();
678
679 /*
Pamidipati, Vijay5d27d812013-11-22 16:48:11 +0530680 * Register with Bus driver
681 */
682 pm_client = nss_pm_client_register(NSS_PM_CLIENT_NETAP);
683 if (!pm_client) {
684 nss_warning("Error registering with PM driver");
685 }
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -0800686#endif
Pamidipati, Vijay5d27d812013-11-22 16:48:11 +0530687
688 /*
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +0530689 * Initialize mtu size needed as start
690 */
Stephen Wanga428d0b2017-01-12 21:30:01 -0800691 nss_top_main.prev_mtu_sz = ETH_DATA_LEN;
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +0530692
693 /*
Guojun Jin1cb79522015-06-22 22:34:22 -0700694 * register panic handler and timeout control
695 */
696 nss_coredump_notify_register();
697 nss_coredump_init_delay_work();
698
699 /*
Stephen Wang1f6ad492016-01-27 23:42:06 -0800700 * Init capwap
701 */
702 nss_capwap_init();
703
704 /*
Amit Gupta316729b2016-08-12 12:21:15 +0530705 * INIT ppe on supported platform
706 */
707 if (of_machine_is_compatible("qcom,ipq807x")) {
708 nss_ppe_init();
709 }
710
711 /*
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530712 * Register platform_driver
713 */
714 return platform_driver_register(&nss_driver);
715}
716
717/*
718 * nss_cleanup()
719 * Unregisters nss driver
720 */
721static void __exit nss_cleanup(void)
722{
723 nss_info("Exit NSS driver");
wthomas442c7972013-08-05 14:28:17 -0700724
725 if (nss_dev_header)
726 unregister_sysctl_table(nss_dev_header);
727
Vijay Dewangan9db18752014-09-15 16:25:01 -0700728 /*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800729 * Unregister n2h specific sysctl
730 */
Stephen Wang49b474b2016-03-25 10:40:30 -0700731 nss_n2h_unregister_sysctl();
Vijay Dewangan488e5372014-12-29 21:40:11 -0800732
733 /*
Cemil Coskun9165c762017-12-04 14:35:24 -0800734 * Unregister rps specific sysctl
735 */
736 nss_rps_unregister_sysctl();
737
738 /*
Vijay Dewangan9db18752014-09-15 16:25:01 -0700739 * Unregister ipv4/6 specific sysctl
740 */
741 nss_ipv4_unregister_sysctl();
742 nss_ipv6_unregister_sysctl();
743
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700744 /*
745 * Free Memory allocated for connection tables
746 */
747 nss_ipv4_free_conn_tables();
748 nss_ipv6_free_conn_tables();
749
Jackson Bockusc2a4e682017-06-23 11:59:29 -0700750 nss_project_unregister_sysctl();
Stephen Wangb42ddc52015-12-17 18:10:35 -0800751 nss_data_plane_destroy_delay_work();
752
Amit Gupta316729b2016-08-12 12:21:15 +0530753 /*
754 * cleanup ppe on supported platform
755 */
756 if (of_machine_is_compatible("qcom,ipq807x")) {
757 nss_ppe_free();
758 }
759
Abhishek Rastogibc74e432013-04-02 10:28:22 +0530760 platform_driver_unregister(&nss_driver);
761}
762
763module_init(nss_init);
764module_exit(nss_cleanup);
765
766MODULE_DESCRIPTION("QCA NSS Driver");
767MODULE_AUTHOR("Qualcomm Atheros Inc");
768MODULE_LICENSE("Dual BSD/GPL");