blob: fc4ee15ac016898364c9c5cf60aaf08284bbb569 [file] [log] [blame]
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301/*
2 **************************************************************************
Stephen Wangefd38512017-01-24 14:01:02 -08003 * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
Abhishek Rastogi84d95d02014-03-26 19:31:31 +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 */
16
17/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070018 * nss_n2h.c
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053019 * NSS N2H node APIs
20 */
21
22#include "nss_tx_rx_common.h"
23
Stephen Wang49b474b2016-03-25 10:40:30 -070024#define NSS_N2H_MAX_BUF_POOL_SIZE (1024 * 1024 * 8) /* 8MB */
Saurabh Misra71034db2015-06-04 16:18:38 -070025#define NSS_N2H_MIN_EMPTY_POOL_BUF_SZ 32
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +053026#define NSS_N2H_MAX_EMPTY_POOL_BUF_SZ 65536
Vijay Dewangan488e5372014-12-29 21:40:11 -080027#define NSS_N2H_DEFAULT_EMPTY_POOL_BUF_SZ 8192
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053028
Saurabh Misra71034db2015-06-04 16:18:38 -070029int nss_n2h_empty_pool_buf_cfg[NSS_MAX_CORES] __read_mostly = {-1, -1};
30int nss_n2h_water_mark[NSS_MAX_CORES][2] __read_mostly = {{-1, -1}, {-1, -1} };
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +053031int nss_n2h_wifi_pool_buf_cfg __read_mostly = -1;
Stephen Wang49b474b2016-03-25 10:40:30 -070032int nss_n2h_rps_config __read_mostly;
33int nss_n2h_core0_mitigation_cfg __read_mostly = 1;
34int nss_n2h_core1_mitigation_cfg __read_mostly = 1;
35int nss_n2h_core0_add_buf_pool_size __read_mostly;
36int nss_n2h_core1_add_buf_pool_size __read_mostly;
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053037
Vijay Dewangan488e5372014-12-29 21:40:11 -080038struct nss_n2h_registered_data {
39 nss_n2h_msg_callback_t n2h_callback;
40 void *app_data;
41};
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053042
Vijay Dewangan488e5372014-12-29 21:40:11 -080043static struct nss_n2h_cfg_pvt nss_n2h_nepbcfgp[NSS_MAX_CORES];
44static struct nss_n2h_registered_data nss_n2h_rd[NSS_MAX_CORES];
Vijay Dewangan634ce592015-01-07 17:21:09 -080045static struct nss_n2h_cfg_pvt nss_n2h_rcp;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +053046static struct nss_n2h_cfg_pvt nss_n2h_mitigationcp[NSS_CORE_MAX];
47static struct nss_n2h_cfg_pvt nss_n2h_bufcp[NSS_CORE_MAX];
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +053048static struct nss_n2h_cfg_pvt nss_n2h_wp;
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053049
50/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070051 * nss_n2h_stats_sync()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053052 * Handle the syncing of NSS statistics.
53 */
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070054static void nss_n2h_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_n2h_stats_sync *nnss)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053055{
56 struct nss_top_instance *nss_top = nss_ctx->nss_top;
57
58 spin_lock_bh(&nss_top->stats_lock);
59
60 /*
61 * common node stats
62 */
63 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_PKTS] += nnss->node_stats.rx_packets;
64 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_BYTES] += nnss->node_stats.rx_bytes;
65 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_DROPPED] += nnss->node_stats.rx_dropped;
66 nss_ctx->stats_n2h[NSS_STATS_NODE_TX_PKTS] += nnss->node_stats.tx_packets;
67 nss_ctx->stats_n2h[NSS_STATS_NODE_TX_BYTES] += nnss->node_stats.tx_bytes;
68
69 /*
70 * General N2H stats
71 */
Murat Sezgin0c0561d2014-04-09 18:55:58 -070072 nss_ctx->stats_n2h[NSS_STATS_N2H_QUEUE_DROPPED] += nnss->queue_dropped;
73 nss_ctx->stats_n2h[NSS_STATS_N2H_TOTAL_TICKS] += nnss->total_ticks;
74 nss_ctx->stats_n2h[NSS_STATS_N2H_WORST_CASE_TICKS] += nnss->worst_case_ticks;
75 nss_ctx->stats_n2h[NSS_STATS_N2H_ITERATIONS] += nnss->iterations;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053076
77 /*
Thomas Wu3fd8dd72014-06-11 15:57:05 -070078 * pbuf manager ocm and default pool stats
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053079 */
Thomas Wu3fd8dd72014-06-11 15:57:05 -070080 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_ALLOC_FAILS] += nnss->pbuf_ocm_stats.pbuf_alloc_fails;
81 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_FREE_COUNT] = nnss->pbuf_ocm_stats.pbuf_free_count;
82 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_TOTAL_COUNT] = nnss->pbuf_ocm_stats.pbuf_total_count;
83
84 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_ALLOC_FAILS] += nnss->pbuf_default_stats.pbuf_alloc_fails;
85 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_FREE_COUNT] = nnss->pbuf_default_stats.pbuf_free_count;
86 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_TOTAL_COUNT] = nnss->pbuf_default_stats.pbuf_total_count;
87
88 /*
89 * payload mgr stats
90 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053091 nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_ALLOC_FAILS] += nnss->payload_alloc_fails;
Thomas Wu53679842015-01-22 13:37:35 -080092 nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_FREE_COUNT] = nnss->payload_free_count;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053093
Sakthi Vignesh Radhakrishnan2a8ee962014-11-22 13:35:38 -080094 /*
95 * Host <=> NSS control traffic stats
96 */
97 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_PACKETS] += nnss->h2n_ctrl_pkts;
98 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_BYTES] += nnss->h2n_ctrl_bytes;
99 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_PACKETS] += nnss->n2h_ctrl_pkts;
100 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_BYTES] += nnss->n2h_ctrl_bytes;
101
102 /*
103 * Host <=> NSS control data traffic stats
104 */
105 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_PACKETS] += nnss->h2n_data_pkts;
106 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_BYTES] += nnss->h2n_data_bytes;
107 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_PACKETS] += nnss->n2h_data_pkts;
108 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_BYTES] += nnss->n2h_data_bytes;
109
Saurabh Misra71034db2015-06-04 16:18:38 -0700110 /*
111 * Payloads related stats
112 */
113 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_TOT_PAYLOADS] = nnss->tot_payloads;
114
Guojun Jin85dfa7b2015-09-02 15:13:56 -0700115 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_INTERFACE_INVALID] += nnss->data_interface_invalid;
116
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530117 spin_unlock_bh(&nss_top->stats_lock);
118}
119
120/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700121 * nss_n2h_interface_handler()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530122 * Handle NSS -> HLOS messages for N2H node
123 */
Vijay Dewangan634ce592015-01-07 17:21:09 -0800124static void nss_n2h_interface_handler(struct nss_ctx_instance *nss_ctx,
125 struct nss_cmn_msg *ncm,
Arunkumar Tba9b4a02016-11-07 11:41:14 +0530126 void *app_data)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530127{
128 struct nss_n2h_msg *nnm = (struct nss_n2h_msg *)ncm;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800129 nss_n2h_msg_callback_t cb;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530130
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700131 BUG_ON(ncm->interface != NSS_N2H_INTERFACE);
132
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530133 /*
134 * Is this a valid request/response packet?
135 */
136 if (nnm->cm.type >= NSS_METADATA_TYPE_N2H_MAX) {
137 nss_warning("%p: received invalid message %d for Offload stats interface", nss_ctx, nnm->cm.type);
138 return;
139 }
140
141 switch (nnm->cm.type) {
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530142 case NSS_TX_METADATA_TYPE_N2H_RPS_CFG:
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530143 nss_info("NSS N2H rps_en %d \n",nnm->msg.rps_cfg.enable);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800144 break;
145
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530146 case NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG:
147 nss_info("NSS N2H mitigation_dis %d \n",nnm->msg.mitigation_cfg.enable);
148 break;
149
Vijay Dewangan488e5372014-12-29 21:40:11 -0800150 case NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG:
151 nss_info("%p: empty pool buf cfg response from FW", nss_ctx);
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530152 break;
153
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +0530154 case NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS:
155 nss_info("%p: flush payloads cmd response from FW", nss_ctx);
156 break;
157
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530158 case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC:
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700159 nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530160 break;
161
162 default:
163 if (ncm->response != NSS_CMN_RESPONSE_ACK) {
164 /*
165 * Check response
166 */
167 nss_info("%p: Received response %d for type %d, interface %d",
168 nss_ctx, ncm->response, ncm->type, ncm->interface);
169 }
170 }
Vijay Dewangan488e5372014-12-29 21:40:11 -0800171
172 /*
Stephen Wang49b474b2016-03-25 10:40:30 -0700173 * Update the callback and app_data for NOTIFY messages, n2h sends all notify messages
Vijay Dewangan488e5372014-12-29 21:40:11 -0800174 * to the same callback/app_data.
175 */
176 if (nnm->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
177 /*
178 * Place holder for the user to create right call
179 * back and app data when response is NSS_CMM_RESPONSE_NOTIFY
180 */
Stephen Wangaed46332016-12-12 17:29:03 -0800181 ncm->cb = (nss_ptr_t)nss_n2h_rd[nss_ctx->id].n2h_callback;
182 ncm->app_data = (nss_ptr_t)nss_n2h_rd[nss_ctx->id].app_data;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800183 }
184
185 /*
186 * Do we have a callback?
187 */
188 if (!ncm->cb) {
189 return;
190 }
191
192 /*
193 * Callback
194 */
195 cb = (nss_n2h_msg_callback_t)ncm->cb;
196 cb((void *)ncm->app_data, nnm);
197}
198
199/*
Vijay Dewangan634ce592015-01-07 17:21:09 -0800200 * nss_n2h_rps_cfg_callback()
201 * call back function for rps configuration
202 */
203static void nss_n2h_rps_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
204{
205 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)app_data;
206 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
207
208 /*
209 * Error, hence we are not updating the nss_n2h_empty_pool_buf
210 * Restore the current_value to its previous state
211 */
212 nss_n2h_rcp.response = NSS_FAILURE;
213 complete(&nss_n2h_rcp.complete);
214 nss_warning("%p: RPS configuration failed : %d\n", nss_ctx,
215 nnm->cm.error);
216 return;
217 }
218
219 nss_info("%p: RPS configuration succeeded: %d\n", nss_ctx,
220 nnm->cm.error);
221 nss_ctx->n2h_rps_en = nnm->msg.rps_cfg.enable;
222 nss_n2h_rcp.response = NSS_SUCCESS;
223 complete(&nss_n2h_rcp.complete);
224}
225
226/*
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530227 * nss_n2h_mitigation_cfg_callback()
228 * call back function for mitigation configuration
229 */
230static void nss_n2h_mitigation_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
231{
Stephen Wangaed46332016-12-12 17:29:03 -0800232 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530233 struct nss_top_instance *nss_top = &nss_top_main;
234 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
235
236 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
237
238 /*
239 * Error, hence we are not updating the nss_n2h_mitigate_en
240 */
241 nss_n2h_mitigationcp[core_num].response = NSS_FAILURE;
242 complete(&nss_n2h_mitigationcp[core_num].complete);
243 nss_warning("core%d: MITIGATION configuration failed : %d\n", core_num, nnm->cm.error);
244 return;
245 }
246
247 nss_info("core%d: MITIGATION configuration succeeded: %d\n", core_num, nnm->cm.error);
248
249 nss_ctx->n2h_mitigate_en = nnm->msg.mitigation_cfg.enable;
250 nss_n2h_mitigationcp[core_num].response = NSS_SUCCESS;
251 complete(&nss_n2h_mitigationcp[core_num].complete);
252}
253
254/*
255 * nss_n2h_buf_cfg_callback()
256 * call back function for pbuf configuration
257 */
258static void nss_n2h_bufs_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
259{
Stephen Wangaed46332016-12-12 17:29:03 -0800260 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530261 unsigned int allocated_sz;
262
263 struct nss_top_instance *nss_top = &nss_top_main;
264 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
265
266 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
267 nss_n2h_bufcp[core_num].response = NSS_FAILURE;
268 nss_warning("core%d: buf configuration failed : %d\n", core_num, nnm->cm.error);
269 goto done;
270 }
271
272 nss_info("core%d: buf configuration succeeded: %d\n", core_num, nnm->cm.error);
273
274 allocated_sz = nnm->msg.buf_pool.nss_buf_page_size * nnm->msg.buf_pool.nss_buf_num_pages;
275 nss_ctx->buf_sz_allocated += allocated_sz;
276
277 nss_n2h_bufcp[core_num].response = NSS_SUCCESS;
278
279done:
280 complete(&nss_n2h_bufcp[core_num].complete);
281}
282
283/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700284 * nss_n2h_payload_stats_callback()
285 * It gets called response to payload accounting.
Vijay Dewangan488e5372014-12-29 21:40:11 -0800286 */
Saurabh Misra71034db2015-06-04 16:18:38 -0700287static void nss_n2h_payload_stats_callback(void *app_data,
288 struct nss_n2h_msg *nnm)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800289{
Stephen Wangaed46332016-12-12 17:29:03 -0800290 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Saurabh Misra71034db2015-06-04 16:18:38 -0700291
Vijay Dewangan488e5372014-12-29 21:40:11 -0800292 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
293 struct nss_n2h_empty_pool_buf *nnepbcm;
294 nnepbcm = &nnm->msg.empty_pool_buf_cfg;
295
Saurabh Misra71034db2015-06-04 16:18:38 -0700296 nss_warning("%d: core empty pool buf set failure: %d\n",
297 core_num, nnm->cm.error);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800298 nss_n2h_nepbcfgp[core_num].response = NSS_FAILURE;
299 complete(&nss_n2h_nepbcfgp[core_num].complete);
300 return;
301 }
302
Saurabh Misra71034db2015-06-04 16:18:38 -0700303 if (nnm->cm.type == NSS_TX_METADATA_TYPE_GET_PAYLOAD_INFO) {
304 nss_n2h_nepbcfgp[core_num].empty_buf_pool =
305 ntohl(nnm->msg.payload_info.pool_size);
306 nss_n2h_nepbcfgp[core_num].low_water =
307 ntohl(nnm->msg.payload_info.low_water);
308 nss_n2h_nepbcfgp[core_num].high_water =
309 ntohl(nnm->msg.payload_info.high_water);
310 }
311
Vijay Dewangan488e5372014-12-29 21:40:11 -0800312 nss_n2h_nepbcfgp[core_num].response = NSS_SUCCESS;
313 complete(&nss_n2h_nepbcfgp[core_num].complete);
314}
315
316/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530317 * nss_n2h_set_wifi_payloads_callback()
318 * call back function for response to wifi pool configuration
319 *
320 */
321static void nss_n2h_set_wifi_payloads_callback(void *app_data,
322 struct nss_n2h_msg *nnm)
323{
Arunkumar Tba9b4a02016-11-07 11:41:14 +0530324 struct nss_ctx_instance *nss_ctx __maybe_unused = (struct nss_ctx_instance *)app_data;
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530325 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
326
327 nss_n2h_wp.response = NSS_FAILURE;
328 complete(&nss_n2h_wp.complete);
329 nss_warning("%p: wifi pool configuration failed : %d\n", nss_ctx,
330 nnm->cm.error);
331 return;
332 }
333
334 nss_info("%p: wifi payload configuration succeeded: %d\n", nss_ctx,
335 nnm->cm.error);
336 nss_n2h_wp.response = NSS_SUCCESS;
337 complete(&nss_n2h_wp.complete);
338}
339
340/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700341 * nss_n2h_get_payload_info()
342 * Gets Payload information
Vijay Dewangan488e5372014-12-29 21:40:11 -0800343 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700344static int nss_n2h_get_payload_info(struct ctl_table *ctl, int write,
Saurabh Misra71034db2015-06-04 16:18:38 -0700345 void __user *buffer, size_t *lenp, loff_t *ppos,
Stephen Wangaed46332016-12-12 17:29:03 -0800346 nss_ptr_t core_num)
Saurabh Misra71034db2015-06-04 16:18:38 -0700347{
348 struct nss_top_instance *nss_top = &nss_top_main;
349 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
350 struct nss_n2h_msg nnm;
351 struct nss_n2h_payload_info *nnepbcm;
352 nss_tx_status_t nss_tx_status;
353 int ret = NSS_FAILURE;
354
355 /*
356 * Note that semaphore should be already held.
357 */
358
359 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
360 NSS_TX_METADATA_TYPE_GET_PAYLOAD_INFO,
361 sizeof(struct nss_n2h_payload_info),
362 nss_n2h_payload_stats_callback,
363 (void *)core_num);
364
365 nnepbcm = &nnm.msg.payload_info;
366 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
367
368 if (nss_tx_status != NSS_TX_SUCCESS) {
Stephen Wangaed46332016-12-12 17:29:03 -0800369 nss_warning("%p: core %d nss_tx error errorn", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700370 return NSS_FAILURE;
371 }
372
373 /*
374 * Blocking call, wait till we get ACK for this msg.
375 */
376 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
377 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
378 if (ret == 0) {
Stephen Wangaed46332016-12-12 17:29:03 -0800379 nss_warning("%p: core %d waiting for ack timed out\n", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700380 return NSS_FAILURE;
381 }
382
383 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
Stephen Wangaed46332016-12-12 17:29:03 -0800384 nss_warning("%p: core %d response returned failure\n", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700385 return NSS_FAILURE;
386 }
387
388 return NSS_SUCCESS;
389}
390
391/*
392 * nss_n2h_set_empty_pool_buf()
393 * Sets empty pool buffer
394 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700395static int nss_n2h_set_empty_pool_buf(struct ctl_table *ctl, int write,
Saurabh Misra71034db2015-06-04 16:18:38 -0700396 void __user *buffer,
397 size_t *lenp, loff_t *ppos,
Stephen Wangaed46332016-12-12 17:29:03 -0800398 nss_ptr_t core_num, int *new_val)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800399{
400 struct nss_top_instance *nss_top = &nss_top_main;
401 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
402 struct nss_n2h_msg nnm;
403 struct nss_n2h_empty_pool_buf *nnepbcm;
404 nss_tx_status_t nss_tx_status;
405 int ret = NSS_FAILURE;
406
407 /*
408 * Acquiring semaphore
409 */
410 down(&nss_n2h_nepbcfgp[core_num].sem);
411
412 /*
413 * Take snap shot of current value
414 */
Saurabh Misra71034db2015-06-04 16:18:38 -0700415 nss_n2h_nepbcfgp[core_num].empty_buf_pool = *new_val;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800416
Saurabh Misra71034db2015-06-04 16:18:38 -0700417 if (!write) {
418 ret = nss_n2h_get_payload_info(ctl, write, buffer, lenp, ppos,
419 core_num);
420 *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool;
421 if (ret == NSS_FAILURE) {
422 up(&nss_n2h_nepbcfgp[core_num].sem);
423 return -EBUSY;
424 }
425
426 up(&nss_n2h_nepbcfgp[core_num].sem);
427
428 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
429 return ret;
430 }
431
Vijay Dewangan488e5372014-12-29 21:40:11 -0800432 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
Saurabh Misra71034db2015-06-04 16:18:38 -0700433 if (ret) {
Vijay Dewangan488e5372014-12-29 21:40:11 -0800434 up(&nss_n2h_nepbcfgp[core_num].sem);
435 return ret;
436 }
437
Vijay Dewangan488e5372014-12-29 21:40:11 -0800438 if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700439 nss_warning("%p: core %d setting %d < min number of buffer",
Stephen Wangaed46332016-12-12 17:29:03 -0800440 nss_ctx, (int)core_num, *new_val);
Stephen Wang06761022015-03-03 16:38:42 -0800441 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800442 }
443
444 nss_info("%p: core %d number of empty pool buffer is : %d\n",
Stephen Wangaed46332016-12-12 17:29:03 -0800445 nss_ctx, (int)core_num, *new_val);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800446
447 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
448 NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG,
449 sizeof(struct nss_n2h_empty_pool_buf),
Saurabh Misra71034db2015-06-04 16:18:38 -0700450 nss_n2h_payload_stats_callback,
Stephen Wangaed46332016-12-12 17:29:03 -0800451 (nss_ptr_t *)core_num);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800452
453 nnepbcm = &nnm.msg.empty_pool_buf_cfg;
454 nnepbcm->pool_size = htonl(*new_val);
455 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
456
457 if (nss_tx_status != NSS_TX_SUCCESS) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700458 nss_warning("%p: core %d nss_tx error empty pool buffer: %d\n",
Stephen Wangaed46332016-12-12 17:29:03 -0800459 nss_ctx, (int)core_num, *new_val);
Stephen Wang06761022015-03-03 16:38:42 -0800460 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800461 }
462
463 /*
464 * Blocking call, wait till we get ACK for this msg.
465 */
Saurabh Misra71034db2015-06-04 16:18:38 -0700466 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
467 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
Vijay Dewangan488e5372014-12-29 21:40:11 -0800468 if (ret == 0) {
Stephen Wangaed46332016-12-12 17:29:03 -0800469 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, (int)core_num);
Stephen Wang06761022015-03-03 16:38:42 -0800470 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800471 }
472
473 /*
474 * ACK/NACK received from NSS FW
475 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
476 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
477 */
478 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
Stephen Wang06761022015-03-03 16:38:42 -0800479 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800480 }
481
482 up(&nss_n2h_nepbcfgp[core_num].sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700483 return 0;
Stephen Wang06761022015-03-03 16:38:42 -0800484
485failure:
486 /*
487 * Restore the current_value to its previous state
488 */
Saurabh Misra71034db2015-06-04 16:18:38 -0700489 *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool;
490 up(&nss_n2h_nepbcfgp[core_num].sem);
491 return NSS_FAILURE;
492}
493
494/*
495 * nss_n2h_set_water_mark()
496 * Sets water mark for N2H SOS
497 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700498static int nss_n2h_set_water_mark(struct ctl_table *ctl, int write,
Saurabh Misra71034db2015-06-04 16:18:38 -0700499 void __user *buffer,
500 size_t *lenp, loff_t *ppos,
Stephen Wangaed46332016-12-12 17:29:03 -0800501 uint32_t core_num, int *low, int *high)
Saurabh Misra71034db2015-06-04 16:18:38 -0700502{
503 struct nss_top_instance *nss_top = &nss_top_main;
504 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
505 struct nss_n2h_msg nnm;
506 struct nss_n2h_water_mark *wm;
507 nss_tx_status_t nss_tx_status;
508 int ret = NSS_FAILURE;
509
510 /*
511 * Acquiring semaphore
512 */
513 down(&nss_n2h_nepbcfgp[core_num].sem);
514
515 /*
516 * Take snap shot of current value
517 */
518 nss_n2h_nepbcfgp[core_num].low_water = *low;
519 nss_n2h_nepbcfgp[core_num].high_water = *high;
520
521 if (!write) {
522 ret = nss_n2h_get_payload_info(ctl, write, buffer, lenp, ppos,
523 core_num);
524 *low = nss_n2h_nepbcfgp[core_num].low_water;
525 *high = nss_n2h_nepbcfgp[core_num].high_water;
526
527 if (ret == NSS_FAILURE) {
528 up(&nss_n2h_nepbcfgp[core_num].sem);
529 return -EBUSY;
530 }
531
532 up(&nss_n2h_nepbcfgp[core_num].sem);
533 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
534 return ret;
535 }
536
537 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
538 if (ret) {
539 up(&nss_n2h_nepbcfgp[core_num].sem);
540 return ret;
541 }
542
543 /*
544 * If either low or high water mark is not set then we do
545 * nothing.
546 */
547 if (*low == -1 || *high == -1)
548 goto failure;
549
550 if ((*low < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) ||
551 (*high < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
552 nss_warning("%p: core %d setting %d, %d < min number of buffer",
553 nss_ctx, core_num, *low, *high);
554 goto failure;
555 }
556
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530557 if ((*low > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) ||
558 (*high > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700559 nss_warning("%p: core %d setting %d, %d is > upper limit",
560 nss_ctx, core_num, *low, *high);
561 goto failure;
562 }
563
564 if (*low > *high) {
565 nss_warning("%p: core %d setting low %d is more than high %d",
566 nss_ctx, core_num, *low, *high);
567 goto failure;
568 }
569
570 nss_info("%p: core %d number of low : %d and high : %d\n",
571 nss_ctx, core_num, *low, *high);
572
573 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
574 NSS_TX_METADATA_TYPE_SET_WATER_MARK,
575 sizeof(struct nss_n2h_water_mark),
576 nss_n2h_payload_stats_callback,
Stephen Wangaed46332016-12-12 17:29:03 -0800577 (void *)(nss_ptr_t)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700578
579 wm = &nnm.msg.wm;
580 wm->low_water = htonl(*low);
581 wm->high_water = htonl(*high);
582 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
583
584 if (nss_tx_status != NSS_TX_SUCCESS) {
585 nss_warning("%p: core %d nss_tx error setting : %d, %d\n",
586 nss_ctx, core_num, *low, *high);
587 goto failure;
588 }
589
590 /*
591 * Blocking call, wait till we get ACK for this msg.
592 */
593 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
594 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
595 if (ret == 0) {
596 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx,
597 core_num);
598 goto failure;
599 }
600
601 /*
602 * ACK/NACK received from NSS FW
603 */
604 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response)
605 goto failure;
606
607 up(&nss_n2h_nepbcfgp[core_num].sem);
608 return NSS_SUCCESS;
609
610failure:
611 /*
612 * Restore the current_value to its previous state
613 */
614 *low = nss_n2h_nepbcfgp[core_num].low_water;
615 *high = nss_n2h_nepbcfgp[core_num].high_water;
Stephen Wang06761022015-03-03 16:38:42 -0800616 up(&nss_n2h_nepbcfgp[core_num].sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700617 return -EINVAL;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800618}
619
620/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530621 * nss_n2h_cfg_wifi_pool()
622 * Sets number of wifi payloads to adjust high water mark for N2H SoS
623 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700624static int nss_n2h_cfg_wifi_pool(struct ctl_table *ctl, int write,
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530625 void __user *buffer,
626 size_t *lenp, loff_t *ppos,
627 int *payloads)
628{
629 struct nss_top_instance *nss_top = &nss_top_main;
630 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
631 struct nss_n2h_msg nnm;
632 struct nss_n2h_wifi_payloads *wp;
633 nss_tx_status_t nss_tx_status;
634 int ret = NSS_FAILURE;
635
636 /*
637 * Acquiring semaphore
638 */
639 down(&nss_n2h_wp.sem);
640
641 if (!write) {
642 *payloads = nss_n2h_wp.wifi_pool;
643
644 up(&nss_n2h_wp.sem);
645 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
646 return ret;
647 }
648
649 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
650 if (ret) {
651 up(&nss_n2h_wp.sem);
652 return ret;
653 }
654
655 /*
656 * If payloads parameter is not set, we do
657 * nothing.
658 */
659 if (*payloads == -1)
660 goto failure;
661
662 if ((*payloads < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
663 nss_warning("%p: wifi setting %d < min number of buffer",
664 nss_ctx, *payloads);
665 goto failure;
666 }
667
668 if ((*payloads > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
669 nss_warning("%p: wifi setting %d > max number of buffer",
670 nss_ctx, *payloads);
671 goto failure;
672 }
673
674 nss_info("%p: wifi payloads : %d\n",
675 nss_ctx, *payloads);
676
677 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
678 NSS_TX_METADATA_TYPE_N2H_WIFI_POOL_BUF_CFG,
679 sizeof(struct nss_n2h_wifi_payloads),
680 nss_n2h_set_wifi_payloads_callback,
681 (void *)nss_ctx);
682
683 wp = &nnm.msg.wp;
684 wp->payloads = htonl(*payloads);
685 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
686
687 if (nss_tx_status != NSS_TX_SUCCESS) {
688 nss_warning("%p: wifi setting %d nss_tx error",
689 nss_ctx, *payloads);
690 goto failure;
691 }
692
693 /*
694 * Blocking call, wait till we get ACK for this msg.
695 */
696 ret = wait_for_completion_timeout(&nss_n2h_wp.complete,
697 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
698 if (ret == 0) {
699 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
700 goto failure;
701 }
702
703 /*
704 * ACK/NACK received from NSS FW
705 */
706 if (NSS_FAILURE == nss_n2h_wp.response)
707 goto failure;
708
709 up(&nss_n2h_wp.sem);
710 return NSS_SUCCESS;
711
712failure:
713 up(&nss_n2h_wp.sem);
714 return -EINVAL;
715}
716
717/*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800718 * nss_n2h_empty_pool_buf_core1_handler()
719 * Sets the number of empty buffer for core 1
720 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700721static int nss_n2h_empty_pool_buf_cfg_core1_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700722 int write, void __user *buffer,
723 size_t *lenp, loff_t *ppos)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800724{
725 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
Saurabh Misra71034db2015-06-04 16:18:38 -0700726 NSS_CORE_1, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800727}
728
729/*
730 * nss_n2h_empty_pool_buf_core0_handler()
731 * Sets the number of empty buffer for core 0
732 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700733static int nss_n2h_empty_pool_buf_cfg_core0_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700734 int write, void __user *buffer,
735 size_t *lenp, loff_t *ppos)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800736{
737 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
Saurabh Misra71034db2015-06-04 16:18:38 -0700738 NSS_CORE_0, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]);
739}
740
741/*
742 * nss_n2h_water_mark_core1_handler()
743 * Sets water mark for core 1
744 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700745static int nss_n2h_water_mark_core1_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700746 int write, void __user *buffer,
747 size_t *lenp, loff_t *ppos)
748{
749 return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos,
750 NSS_CORE_1, &nss_n2h_water_mark[NSS_CORE_1][0],
751 &nss_n2h_water_mark[NSS_CORE_1][1]);
752}
753
754/*
755 * nss_n2h_water_mark_core0_handler()
756 * Sets water mark for core 0
757 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700758static int nss_n2h_water_mark_core0_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700759 int write, void __user *buffer,
760 size_t *lenp, loff_t *ppos)
761{
762 return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos,
763 NSS_CORE_0, &nss_n2h_water_mark[NSS_CORE_0][0],
764 &nss_n2h_water_mark[NSS_CORE_0][1]);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800765}
766
Vijay Dewangan634ce592015-01-07 17:21:09 -0800767/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530768 * nss_n2h_wifi_payloads_handler()
769 * Sets number of wifi payloads
770 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700771static int nss_n2h_wifi_payloads_handler(struct ctl_table *ctl,
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530772 int write, void __user *buffer,
773 size_t *lenp, loff_t *ppos)
774{
775 return nss_n2h_cfg_wifi_pool(ctl, write, buffer, lenp, ppos,
776 &nss_n2h_wifi_pool_buf_cfg);
777}
778
779/*
Vijay Dewangan634ce592015-01-07 17:21:09 -0800780 * nss_n2h_rps_cfg()
781 * Send Message to NSS to enable RPS.
782 */
Stephen Wang49b474b2016-03-25 10:40:30 -0700783static nss_tx_status_t nss_n2h_rps_cfg(struct nss_ctx_instance *nss_ctx, int enable_rps)
Vijay Dewangan634ce592015-01-07 17:21:09 -0800784{
785 struct nss_n2h_msg nnm;
786 struct nss_n2h_rps *rps_cfg;
787 nss_tx_status_t nss_tx_status;
788 int ret;
789
790 down(&nss_n2h_rcp.sem);
791 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_RPS_CFG,
792 sizeof(struct nss_n2h_rps),
793 nss_n2h_rps_cfg_callback,
794 (void *)nss_ctx);
795
796 rps_cfg = &nnm.msg.rps_cfg;
797 rps_cfg->enable = enable_rps;
798
799 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
800
801 if (nss_tx_status != NSS_TX_SUCCESS) {
802 nss_warning("%p: nss_tx error setting rps\n", nss_ctx);
803
804 up(&nss_n2h_rcp.sem);
805 return NSS_FAILURE;
806 }
807
808 /*
809 * Blocking call, wait till we get ACK for this msg.
810 */
811 ret = wait_for_completion_timeout(&nss_n2h_rcp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
812 if (ret == 0) {
813 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
814 up(&nss_n2h_rcp.sem);
815 return NSS_FAILURE;
816 }
817
818 /*
819 * ACK/NACK received from NSS FW
820 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
821 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
822 */
823 if (NSS_FAILURE == nss_n2h_rcp.response) {
824 up(&nss_n2h_rcp.sem);
825 return NSS_FAILURE;
826 }
827
828 up(&nss_n2h_rcp.sem);
829 return NSS_SUCCESS;
830}
831
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530832/*
833 * nss_n2h_mitigation_cfg()
834 * Send Message to NSS to disable MITIGATION.
835 */
Stephen Wang49b474b2016-03-25 10:40:30 -0700836static nss_tx_status_t nss_n2h_mitigation_cfg(struct nss_ctx_instance *nss_ctx, int enable_mitigation, nss_core_id_t core_num)
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530837{
838 struct nss_n2h_msg nnm;
839 struct nss_n2h_mitigation *mitigation_cfg;
840 nss_tx_status_t nss_tx_status;
841 int ret;
842
843 nss_assert(core_num < NSS_CORE_MAX);
844
845 down(&nss_n2h_mitigationcp[core_num].sem);
846 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG,
847 sizeof(struct nss_n2h_mitigation),
848 nss_n2h_mitigation_cfg_callback,
849 (void *)core_num);
850
851 mitigation_cfg = &nnm.msg.mitigation_cfg;
852 mitigation_cfg->enable = enable_mitigation;
853
854 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
855
856 if (nss_tx_status != NSS_TX_SUCCESS) {
857 nss_warning("%p: nss_tx error setting mitigation\n", nss_ctx);
858 goto failure;
859 }
860
861 /*
862 * Blocking call, wait till we get ACK for this msg.
863 */
864 ret = wait_for_completion_timeout(&nss_n2h_mitigationcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
865 if (ret == 0) {
866 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
867 goto failure;
868 }
869
870 /*
871 * ACK/NACK received from NSS FW
872 */
873 if (NSS_FAILURE == nss_n2h_mitigationcp[core_num].response) {
874 goto failure;
875 }
876
877 up(&nss_n2h_mitigationcp[core_num].sem);
878 return NSS_SUCCESS;
879
880failure:
881 up(&nss_n2h_mitigationcp[core_num].sem);
882 return NSS_FAILURE;
883}
884
885static inline void nss_n2h_buf_pool_free(struct nss_n2h_buf_pool *buf_pool)
886{
887 int page_count;
888 for (page_count = 0; page_count < buf_pool->nss_buf_num_pages; page_count++) {
889 kfree(buf_pool->nss_buf_pool_vaddr[page_count]);
890 }
891}
892
893/*
894 * nss_n2h_buf_cfg()
895 * Send Message to NSS to enable pbufs.
896 */
Stephen Wang49b474b2016-03-25 10:40:30 -0700897static nss_tx_status_t nss_n2h_buf_pool_cfg(struct nss_ctx_instance *nss_ctx,
Tallapragada4b0161b2016-07-07 21:38:34 +0530898 int buf_pool_size, nss_core_id_t core_num)
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530899{
900 static struct nss_n2h_msg nnm;
901 struct nss_n2h_buf_pool *buf_pool;
902 nss_tx_status_t nss_tx_status;
903 int ret;
904 int page_count;
905 int num_pages = ALIGN(buf_pool_size, PAGE_SIZE)/PAGE_SIZE;
906
907 nss_assert(core_num < NSS_CORE_MAX);
908
909 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_METADATA_TYPE_N2H_ADD_BUF_POOL,
910 sizeof(struct nss_n2h_buf_pool),
911 nss_n2h_bufs_cfg_callback,
912 (void *)core_num);
913
914 do {
915
916 down(&nss_n2h_bufcp[core_num].sem);
917
918 buf_pool = &nnm.msg.buf_pool;
919 buf_pool->nss_buf_page_size = PAGE_SIZE;
920
921 for (page_count = 0; page_count < MAX_PAGES_PER_MSG && num_pages; page_count++, num_pages--) {
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530922 void *kern_addr = kzalloc(PAGE_SIZE, GFP_ATOMIC);
923 if (!kern_addr) {
924 BUG_ON(!page_count);
925 break;
926 }
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530927
928 buf_pool->nss_buf_pool_vaddr[page_count] = kern_addr;
Stephen Wangefd38512017-01-24 14:01:02 -0800929 buf_pool->nss_buf_pool_addr[page_count] = dma_map_single(nss_ctx->dev, kern_addr, PAGE_SIZE, DMA_TO_DEVICE);
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530930 }
931
932 buf_pool->nss_buf_num_pages = page_count;
933 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
934 if (nss_tx_status != NSS_TX_SUCCESS) {
935
936 nss_n2h_buf_pool_free(buf_pool);
937 nss_warning("%p: nss_tx error setting pbuf\n", nss_ctx);
938 goto failure;
939 }
940
941 /*
942 * Blocking call, wait till we get ACK for this msg.
943 */
944 ret = wait_for_completion_timeout(&nss_n2h_bufcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
945 if (ret == 0) {
946 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
947 goto failure;
948 }
949
950 /*
951 * ACK/NACK received from NSS FW
952 */
953 if (NSS_FAILURE == nss_n2h_bufcp[core_num].response) {
954
955 nss_n2h_buf_pool_free(buf_pool);
956 goto failure;
957 }
958
959 up(&nss_n2h_bufcp[core_num].sem);
960 } while(num_pages);
961
962 return NSS_SUCCESS;
963failure:
964 up(&nss_n2h_bufcp[core_num].sem);
965 return NSS_FAILURE;
966}
967
Stephen Wang49b474b2016-03-25 10:40:30 -0700968/*
969 * nss_rps_handler()
970 * Enable NSS RPS
971 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700972static int nss_n2h_rpscfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Stephen Wang49b474b2016-03-25 10:40:30 -0700973{
974 struct nss_top_instance *nss_top = &nss_top_main;
975 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
976 int ret;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530977
Stephen Wang49b474b2016-03-25 10:40:30 -0700978 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
979 if (!ret) {
980 if ((write) && (nss_n2h_rps_config == 1)) {
981 printk(KERN_INFO "Enabling NSS RPS\n");
982
983 return nss_n2h_rps_cfg(nss_ctx, 1);
984 }
985
986 if ((write) && (nss_n2h_rps_config == 0)) {
987 printk(KERN_INFO "Runtime disabling of NSS RPS not supported\n");
988 return ret;
989 }
990
991 if (write) {
992 printk(KERN_INFO "Invalid input value.Valid values are 0 and 1\n");
993 }
994
995 }
996
997 return ret;
998}
999
1000/*
1001 * nss_mitigation_handler()
1002 * Enable NSS MITIGATION
1003 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001004static int nss_n2h_mitigationcfg_core0_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Stephen Wang49b474b2016-03-25 10:40:30 -07001005{
1006 struct nss_top_instance *nss_top = &nss_top_main;
1007 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0];
1008 int ret;
1009
1010 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1011 if (ret) {
1012 return ret;
1013 }
1014
1015 /*
1016 * It's a read operation
1017 */
1018 if (!write) {
1019 return ret;
1020 }
1021
1022 if (!nss_n2h_core0_mitigation_cfg) {
1023 printk(KERN_INFO "Disabling NSS MITIGATION\n");
1024 nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_0);
1025 return 0;
1026 }
1027 printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n");
1028 return -EINVAL;
1029}
1030
1031/*
1032 * nss_mitigation_handler()
1033 * Enable NSS MITIGATION
1034 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001035static int nss_n2h_mitigationcfg_core1_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Stephen Wang49b474b2016-03-25 10:40:30 -07001036{
1037 struct nss_top_instance *nss_top = &nss_top_main;
1038 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1];
1039 int ret;
1040
1041 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1042 if (ret) {
1043 return ret;
1044 }
1045
1046 /*
1047 * It's a read operation
1048 */
1049 if (!write) {
1050 return ret;
1051 }
1052
1053 if (!nss_n2h_core1_mitigation_cfg) {
1054 printk(KERN_INFO "Disabling NSS MITIGATION\n");
1055 nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_1);
1056 return 0;
1057 }
1058 printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n");
1059 return -EINVAL;
1060}
1061
1062/*
1063 * nss_buf_handler()
1064 * Add extra NSS bufs from host memory
1065 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001066static int nss_n2h_buf_cfg_core0_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Stephen Wang49b474b2016-03-25 10:40:30 -07001067{
1068 struct nss_top_instance *nss_top = &nss_top_main;
1069 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0];
1070 int ret;
1071
1072 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1073 if (ret) {
1074 return ret;
1075 }
1076
1077 /*
1078 * It's a read operation
1079 */
1080 if (!write) {
1081 return ret;
1082 }
1083
1084 if (nss_ctx->buf_sz_allocated) {
1085 nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1086 return -EPERM;
1087 }
1088
1089 if ((nss_n2h_core0_add_buf_pool_size >= 1) && (nss_n2h_core0_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) {
1090 printk(KERN_INFO "configuring additional NSS pbufs\n");
1091 ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core0_add_buf_pool_size, NSS_CORE_0);
1092 nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1093 printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated);
1094 return ret;
1095 }
1096
1097 printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE);
1098 return -EINVAL;
1099}
1100
1101/*
1102 * nss_n2h_buf_handler()
1103 * Add extra NSS bufs from host memory
1104 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001105static int nss_n2h_buf_cfg_core1_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Stephen Wang49b474b2016-03-25 10:40:30 -07001106{
1107 struct nss_top_instance *nss_top = &nss_top_main;
1108 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1];
1109 int ret;
1110
1111 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1112 if (ret) {
1113 return ret;
1114 }
1115
1116 /*
1117 * It's a read operation
1118 */
1119 if (!write) {
1120 return ret;
1121 }
1122
1123 if (nss_ctx->buf_sz_allocated) {
1124 nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1125 return -EPERM;
1126 }
1127
1128 if ((nss_n2h_core1_add_buf_pool_size >= 1) && (nss_n2h_core1_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) {
1129 printk(KERN_INFO "configuring additional NSS pbufs\n");
1130 ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core1_add_buf_pool_size, NSS_CORE_1);
1131 nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1132 printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated);
1133 return ret;
1134 }
1135
1136 printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE);
1137 return -EINVAL;
1138}
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301139
Stephen Wang52e6d342016-03-29 15:02:33 -07001140static struct ctl_table nss_n2h_table[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001141 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001142 .procname = "n2h_empty_pool_buf_core0",
1143 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0],
1144 .maxlen = sizeof(int),
1145 .mode = 0644,
1146 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler,
Vijay Dewangan488e5372014-12-29 21:40:11 -08001147 },
1148 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001149 .procname = "n2h_empty_pool_buf_core1",
1150 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1],
1151 .maxlen = sizeof(int),
1152 .mode = 0644,
1153 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core1_handler,
1154 },
1155 {
1156 .procname = "n2h_low_water_core0",
1157 .data = &nss_n2h_water_mark[NSS_CORE_0][0],
1158 .maxlen = sizeof(int),
1159 .mode = 0644,
1160 .proc_handler = &nss_n2h_water_mark_core0_handler,
1161 },
1162 {
1163 .procname = "n2h_low_water_core1",
1164 .data = &nss_n2h_water_mark[NSS_CORE_1][0],
1165 .maxlen = sizeof(int),
1166 .mode = 0644,
1167 .proc_handler = &nss_n2h_water_mark_core1_handler,
1168 },
1169 {
1170 .procname = "n2h_high_water_core0",
1171 .data = &nss_n2h_water_mark[NSS_CORE_0][1],
1172 .maxlen = sizeof(int),
1173 .mode = 0644,
1174 .proc_handler = &nss_n2h_water_mark_core0_handler,
1175 },
1176 {
1177 .procname = "n2h_high_water_core1",
1178 .data = &nss_n2h_water_mark[NSS_CORE_1][1],
1179 .maxlen = sizeof(int),
1180 .mode = 0644,
1181 .proc_handler = &nss_n2h_water_mark_core1_handler,
Vijay Dewangan488e5372014-12-29 21:40:11 -08001182 },
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301183 {
1184 .procname = "n2h_wifi_pool_buf",
1185 .data = &nss_n2h_wifi_pool_buf_cfg,
1186 .maxlen = sizeof(int),
1187 .mode = 0644,
1188 .proc_handler = &nss_n2h_wifi_payloads_handler,
1189 },
Stephen Wang49b474b2016-03-25 10:40:30 -07001190 {
1191 .procname = "rps",
1192 .data = &nss_n2h_rps_config,
1193 .maxlen = sizeof(int),
1194 .mode = 0644,
1195 .proc_handler = &nss_n2h_rpscfg_handler,
1196 },
1197 {
1198 .procname = "mitigation_core0",
1199 .data = &nss_n2h_core0_mitigation_cfg,
1200 .maxlen = sizeof(int),
1201 .mode = 0644,
1202 .proc_handler = &nss_n2h_mitigationcfg_core0_handler,
1203 },
1204 {
1205 .procname = "mitigation_core1",
1206 .data = &nss_n2h_core1_mitigation_cfg,
1207 .maxlen = sizeof(int),
1208 .mode = 0644,
1209 .proc_handler = &nss_n2h_mitigationcfg_core1_handler,
1210 },
1211 {
1212 .procname = "extra_pbuf_core0",
1213 .data = &nss_n2h_core0_add_buf_pool_size,
1214 .maxlen = sizeof(int),
1215 .mode = 0644,
1216 .proc_handler = &nss_n2h_buf_cfg_core0_handler,
1217 },
1218 {
1219 .procname = "extra_pbuf_core1",
1220 .data = &nss_n2h_core1_add_buf_pool_size,
1221 .maxlen = sizeof(int),
1222 .mode = 0644,
1223 .proc_handler = &nss_n2h_buf_cfg_core1_handler,
1224 },
Vijay Dewangan488e5372014-12-29 21:40:11 -08001225
1226 { }
1227};
1228
Stephen Wang52e6d342016-03-29 15:02:33 -07001229static struct ctl_table nss_n2h_dir[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001230 {
1231 .procname = "n2hcfg",
1232 .mode = 0555,
1233 .child = nss_n2h_table,
1234 },
1235 { }
1236};
1237
1238
Stephen Wang52e6d342016-03-29 15:02:33 -07001239static struct ctl_table nss_n2h_root_dir[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001240 {
1241 .procname = "nss",
1242 .mode = 0555,
1243 .child = nss_n2h_dir,
1244 },
1245 { }
1246};
1247
Stephen Wang52e6d342016-03-29 15:02:33 -07001248static struct ctl_table nss_n2h_root[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001249 {
1250 .procname = "dev",
1251 .mode = 0555,
1252 .child = nss_n2h_root_dir,
1253 },
1254 { }
1255};
1256
1257static struct ctl_table_header *nss_n2h_header;
1258
1259/*
Stephen Wang49b474b2016-03-25 10:40:30 -07001260 * nss_n2h_flush_payloads()
1261 * Sends a command down to NSS for flushing all payloads
1262 */
1263nss_tx_status_t nss_n2h_flush_payloads(struct nss_ctx_instance *nss_ctx)
1264{
1265 struct nss_n2h_msg nnm;
1266 struct nss_n2h_flush_payloads *nnflshpl;
1267 nss_tx_status_t nss_tx_status;
1268
1269 nnflshpl = &nnm.msg.flush_payloads;
1270
1271 /*
1272 * TODO: No additional information sent in message
1273 * as of now. Need to initialize message content accordingly
1274 * if needed.
1275 */
1276 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1277 NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS,
1278 sizeof(struct nss_n2h_flush_payloads),
1279 NULL,
1280 NULL);
1281
1282 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1283 if (nss_tx_status != NSS_TX_SUCCESS) {
1284 nss_warning("%p: failed to send flush payloads command to NSS\n",
1285 nss_ctx);
1286
1287 return NSS_TX_FAILURE;
1288 }
1289
1290 return NSS_TX_SUCCESS;
1291}
1292
1293/*
Vijay Dewangan488e5372014-12-29 21:40:11 -08001294 * nss_n2h_msg_init()
Stephen Wang49b474b2016-03-25 10:40:30 -07001295 * Initialize n2h message.
Vijay Dewangan488e5372014-12-29 21:40:11 -08001296 */
1297void nss_n2h_msg_init(struct nss_n2h_msg *nim, uint16_t if_num, uint32_t type,
Vijay Dewangan634ce592015-01-07 17:21:09 -08001298 uint32_t len, nss_n2h_msg_callback_t cb, void *app_data)
Vijay Dewangan488e5372014-12-29 21:40:11 -08001299{
1300 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
1301}
1302
Vijay Dewangan488e5372014-12-29 21:40:11 -08001303/*
Vijay Dewangan488e5372014-12-29 21:40:11 -08001304 * nss_n2h_tx_msg()
1305 * Send messages to NSS n2h pacakge
1306 */
1307nss_tx_status_t nss_n2h_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_n2h_msg *nnm)
1308{
1309 struct nss_n2h_msg *nnm2;
1310 struct nss_cmn_msg *ncm = &nnm->cm;
1311 struct sk_buff *nbuf;
1312 nss_tx_status_t status;
1313
1314 NSS_VERIFY_CTX_MAGIC(nss_ctx);
1315 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
1316 return NSS_TX_FAILURE_NOT_READY;
1317 }
1318
1319 /*
1320 * Sanity check the message
1321 */
1322 if (ncm->interface != NSS_N2H_INTERFACE) {
1323 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
1324 return NSS_TX_FAILURE;
1325 }
1326
1327 if (ncm->type >= NSS_METADATA_TYPE_N2H_MAX) {
1328 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
1329 return NSS_TX_FAILURE;
1330 }
1331
Suruchi Agarwalef8a8702016-01-08 12:40:08 -08001332 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_n2h_msg)) {
1333 nss_warning("%p: tx request for another interface: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Vijay Dewangan488e5372014-12-29 21:40:11 -08001334 return NSS_TX_FAILURE;
1335 }
1336
1337
1338 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
1339 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -08001340 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]);
Vijay Dewangan488e5372014-12-29 21:40:11 -08001341 return NSS_TX_FAILURE;
1342 }
1343
1344 /*
1345 * Copy the message to our skb.
1346 */
1347 nnm2 = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg));
1348 memcpy(nnm2, nnm, sizeof(struct nss_n2h_msg));
1349 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
1350 if (status != NSS_CORE_STATUS_SUCCESS) {
1351 dev_kfree_skb_any(nbuf);
1352 nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx);
1353 return NSS_TX_FAILURE;
1354 }
1355
Stephen Wang90c67de2016-04-26 15:15:59 -07001356 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Vijay Dewangan488e5372014-12-29 21:40:11 -08001357 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
1358 return NSS_TX_SUCCESS;
1359}
1360
Vijay Dewangan488e5372014-12-29 21:40:11 -08001361/*
1362 * nss_n2h_notify_register()
1363 * Register to received N2H events.
1364 *
1365 * NOTE: Do we want to pass an nss_ctx here so that we can register for n2h on any core?
1366 */
1367struct nss_ctx_instance *nss_n2h_notify_register(int core, nss_n2h_msg_callback_t cb, void *app_data)
1368{
1369 if (core >= NSS_MAX_CORES) {
1370 nss_warning("Input core number %d is wrong \n", core);
1371 return NULL;
1372 }
1373 /*
1374 * TODO: We need to have a new array in support of the new API
1375 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
1376 */
1377 nss_n2h_rd[core].n2h_callback = cb;
1378 nss_n2h_rd[core].app_data = app_data;
1379 return &nss_top_main.nss[core];
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301380}
1381
1382/*
1383 * nss_n2h_register_handler()
1384 */
1385void nss_n2h_register_handler()
1386{
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -07001387 nss_core_register_handler(NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL);
Stephen Wang49b474b2016-03-25 10:40:30 -07001388}
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -07001389
Stephen Wang49b474b2016-03-25 10:40:30 -07001390/*
1391 * nss_n2h_register_sysctl()
1392 */
1393void nss_n2h_register_sysctl(void)
1394{
Vijay Dewangan634ce592015-01-07 17:21:09 -08001395 /*
1396 * RPS sema init
1397 */
1398 sema_init(&nss_n2h_rcp.sem, 1);
1399 init_completion(&nss_n2h_rcp.complete);
1400
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301401 /*
1402 * MITIGATION sema init for core0
1403 */
1404 sema_init(&nss_n2h_mitigationcp[NSS_CORE_0].sem, 1);
1405 init_completion(&nss_n2h_mitigationcp[NSS_CORE_0].complete);
1406
1407 /*
1408 * MITIGATION sema init for core1
1409 */
1410 sema_init(&nss_n2h_mitigationcp[NSS_CORE_1].sem, 1);
1411 init_completion(&nss_n2h_mitigationcp[NSS_CORE_1].complete);
1412
1413 /*
1414 * PBUF addition sema init for core0
1415 */
1416 sema_init(&nss_n2h_bufcp[NSS_CORE_0].sem, 1);
1417 init_completion(&nss_n2h_bufcp[NSS_CORE_0].complete);
1418
1419 /*
1420 * PBUF addition sema init for core1
1421 */
1422 sema_init(&nss_n2h_bufcp[NSS_CORE_1].sem, 1);
1423 init_completion(&nss_n2h_bufcp[NSS_CORE_1].complete);
Vijay Dewangan634ce592015-01-07 17:21:09 -08001424
Stephen Wang49b474b2016-03-25 10:40:30 -07001425 /*
1426 * Core0
1427 */
1428 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1);
1429 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete);
1430 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool =
1431 nss_n2h_empty_pool_buf_cfg[NSS_CORE_0];
1432 nss_n2h_nepbcfgp[NSS_CORE_0].low_water =
1433 nss_n2h_water_mark[NSS_CORE_0][0];
1434 nss_n2h_nepbcfgp[NSS_CORE_0].high_water =
1435 nss_n2h_water_mark[NSS_CORE_0][1];
1436
1437 /*
1438 * Core1
1439 */
1440 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_1].sem, 1);
1441 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_1].complete);
1442 nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool =
1443 nss_n2h_empty_pool_buf_cfg[NSS_CORE_1];
1444 nss_n2h_nepbcfgp[NSS_CORE_1].low_water =
1445 nss_n2h_water_mark[NSS_CORE_1][0];
1446 nss_n2h_nepbcfgp[NSS_CORE_1].high_water =
1447 nss_n2h_water_mark[NSS_CORE_1][1];
1448
1449 /*
1450 * WiFi pool buf cfg sema init
1451 */
1452 sema_init(&nss_n2h_wp.sem, 1);
1453 init_completion(&nss_n2h_wp.complete);
1454
Vijay Dewangan488e5372014-12-29 21:40:11 -08001455 nss_n2h_notify_register(NSS_CORE_0, NULL, NULL);
1456 nss_n2h_notify_register(NSS_CORE_1, NULL, NULL);
1457
Stephen Wang49b474b2016-03-25 10:40:30 -07001458 /*
1459 * Register sysctl table.
1460 */
1461 nss_n2h_header = register_sysctl_table(nss_n2h_root);
1462}
1463
1464/*
1465 * nss_n2h_unregister_sysctl()
1466 * Unregister sysctl specific to n2h
1467 */
1468void nss_n2h_unregister_sysctl(void)
1469{
1470 /*
1471 * Unregister sysctl table.
1472 */
1473 if (nss_n2h_header) {
1474 unregister_sysctl_table(nss_n2h_header);
1475 }
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301476}
Vijay Dewangan488e5372014-12-29 21:40:11 -08001477
1478EXPORT_SYMBOL(nss_n2h_notify_register);