blob: 3d6d303768ce3b638b99be3f4a8151f3e6a6c87b [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
ratheesh kannothab436af2017-07-20 08:51:07 +053028#define NSS_N2H_TX_TIMEOUT 3000 /* 3 Seconds */
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053029
Saurabh Misra71034db2015-06-04 16:18:38 -070030int nss_n2h_empty_pool_buf_cfg[NSS_MAX_CORES] __read_mostly = {-1, -1};
Sachin Shashidhar475012b2017-03-13 16:56:07 -070031int nss_n2h_empty_paged_pool_buf_cfg[NSS_MAX_CORES] __read_mostly = {-1, -1};
Saurabh Misra71034db2015-06-04 16:18:38 -070032int nss_n2h_water_mark[NSS_MAX_CORES][2] __read_mostly = {{-1, -1}, {-1, -1} };
Sachin Shashidhar475012b2017-03-13 16:56:07 -070033int nss_n2h_paged_water_mark[NSS_MAX_CORES][2] __read_mostly = {{-1, -1}, {-1, -1} };
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +053034int nss_n2h_wifi_pool_buf_cfg __read_mostly = -1;
Stephen Wang49b474b2016-03-25 10:40:30 -070035int nss_n2h_rps_config __read_mostly;
36int nss_n2h_core0_mitigation_cfg __read_mostly = 1;
37int nss_n2h_core1_mitigation_cfg __read_mostly = 1;
38int nss_n2h_core0_add_buf_pool_size __read_mostly;
39int nss_n2h_core1_add_buf_pool_size __read_mostly;
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053040
Vijay Dewangan488e5372014-12-29 21:40:11 -080041struct nss_n2h_registered_data {
42 nss_n2h_msg_callback_t n2h_callback;
43 void *app_data;
44};
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053045
Vijay Dewangan488e5372014-12-29 21:40:11 -080046static struct nss_n2h_cfg_pvt nss_n2h_nepbcfgp[NSS_MAX_CORES];
47static struct nss_n2h_registered_data nss_n2h_rd[NSS_MAX_CORES];
Vijay Dewangan634ce592015-01-07 17:21:09 -080048static struct nss_n2h_cfg_pvt nss_n2h_rcp;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +053049static struct nss_n2h_cfg_pvt nss_n2h_mitigationcp[NSS_CORE_MAX];
50static struct nss_n2h_cfg_pvt nss_n2h_bufcp[NSS_CORE_MAX];
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +053051static struct nss_n2h_cfg_pvt nss_n2h_wp;
ratheesh kannothab436af2017-07-20 08:51:07 +053052static struct nss_n2h_cfg_pvt nss_n2h_q_cfg_pvt;
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053053
54/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070055 * nss_n2h_stats_sync()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053056 * Handle the syncing of NSS statistics.
57 */
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070058static void nss_n2h_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_n2h_stats_sync *nnss)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053059{
60 struct nss_top_instance *nss_top = nss_ctx->nss_top;
ratheesh kannoth93ba95c2017-07-13 15:52:52 +053061 int j;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053062
63 spin_lock_bh(&nss_top->stats_lock);
64
65 /*
66 * common node stats
67 */
68 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_PKTS] += nnss->node_stats.rx_packets;
69 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_BYTES] += nnss->node_stats.rx_bytes;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053070 nss_ctx->stats_n2h[NSS_STATS_NODE_TX_PKTS] += nnss->node_stats.tx_packets;
71 nss_ctx->stats_n2h[NSS_STATS_NODE_TX_BYTES] += nnss->node_stats.tx_bytes;
72
ratheesh kannoth93ba95c2017-07-13 15:52:52 +053073 for (j = 0; j < NSS_MAX_NUM_PRI; j++) {
74 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_QUEUE_0_DROPPED + j] += nnss->node_stats.rx_dropped[j];
75 }
76
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053077 /*
78 * General N2H stats
79 */
Murat Sezgin0c0561d2014-04-09 18:55:58 -070080 nss_ctx->stats_n2h[NSS_STATS_N2H_QUEUE_DROPPED] += nnss->queue_dropped;
81 nss_ctx->stats_n2h[NSS_STATS_N2H_TOTAL_TICKS] += nnss->total_ticks;
82 nss_ctx->stats_n2h[NSS_STATS_N2H_WORST_CASE_TICKS] += nnss->worst_case_ticks;
83 nss_ctx->stats_n2h[NSS_STATS_N2H_ITERATIONS] += nnss->iterations;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053084
85 /*
Thomas Wu3fd8dd72014-06-11 15:57:05 -070086 * pbuf manager ocm and default pool stats
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053087 */
Thomas Wu3fd8dd72014-06-11 15:57:05 -070088 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_ALLOC_FAILS] += nnss->pbuf_ocm_stats.pbuf_alloc_fails;
89 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_FREE_COUNT] = nnss->pbuf_ocm_stats.pbuf_free_count;
90 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_TOTAL_COUNT] = nnss->pbuf_ocm_stats.pbuf_total_count;
91
92 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_ALLOC_FAILS] += nnss->pbuf_default_stats.pbuf_alloc_fails;
93 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_FREE_COUNT] = nnss->pbuf_default_stats.pbuf_free_count;
94 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_TOTAL_COUNT] = nnss->pbuf_default_stats.pbuf_total_count;
95
96 /*
97 * payload mgr stats
98 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053099 nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_ALLOC_FAILS] += nnss->payload_alloc_fails;
Thomas Wu53679842015-01-22 13:37:35 -0800100 nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_FREE_COUNT] = nnss->payload_free_count;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530101
Sakthi Vignesh Radhakrishnan2a8ee962014-11-22 13:35:38 -0800102 /*
103 * Host <=> NSS control traffic stats
104 */
105 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_PACKETS] += nnss->h2n_ctrl_pkts;
106 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_BYTES] += nnss->h2n_ctrl_bytes;
107 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_PACKETS] += nnss->n2h_ctrl_pkts;
108 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_BYTES] += nnss->n2h_ctrl_bytes;
109
110 /*
111 * Host <=> NSS control data traffic stats
112 */
113 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_PACKETS] += nnss->h2n_data_pkts;
114 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_BYTES] += nnss->h2n_data_bytes;
115 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_PACKETS] += nnss->n2h_data_pkts;
116 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_BYTES] += nnss->n2h_data_bytes;
117
Saurabh Misra71034db2015-06-04 16:18:38 -0700118 /*
119 * Payloads related stats
120 */
121 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_TOT_PAYLOADS] = nnss->tot_payloads;
122
Guojun Jin85dfa7b2015-09-02 15:13:56 -0700123 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_INTERFACE_INVALID] += nnss->data_interface_invalid;
124
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530125 spin_unlock_bh(&nss_top->stats_lock);
126}
127
128/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700129 * nss_n2h_interface_handler()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530130 * Handle NSS -> HLOS messages for N2H node
131 */
Vijay Dewangan634ce592015-01-07 17:21:09 -0800132static void nss_n2h_interface_handler(struct nss_ctx_instance *nss_ctx,
133 struct nss_cmn_msg *ncm,
Arunkumar Tba9b4a02016-11-07 11:41:14 +0530134 void *app_data)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530135{
136 struct nss_n2h_msg *nnm = (struct nss_n2h_msg *)ncm;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800137 nss_n2h_msg_callback_t cb;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530138
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700139 BUG_ON(ncm->interface != NSS_N2H_INTERFACE);
140
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530141 /*
142 * Is this a valid request/response packet?
143 */
144 if (nnm->cm.type >= NSS_METADATA_TYPE_N2H_MAX) {
145 nss_warning("%p: received invalid message %d for Offload stats interface", nss_ctx, nnm->cm.type);
146 return;
147 }
148
149 switch (nnm->cm.type) {
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530150 case NSS_TX_METADATA_TYPE_N2H_RPS_CFG:
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530151 nss_info("NSS N2H rps_en %d \n",nnm->msg.rps_cfg.enable);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800152 break;
153
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530154 case NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG:
155 nss_info("NSS N2H mitigation_dis %d \n",nnm->msg.mitigation_cfg.enable);
156 break;
157
Vijay Dewangan488e5372014-12-29 21:40:11 -0800158 case NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG:
159 nss_info("%p: empty pool buf cfg response from FW", nss_ctx);
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530160 break;
161
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +0530162 case NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS:
163 nss_info("%p: flush payloads cmd response from FW", nss_ctx);
164 break;
165
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530166 case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC:
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700167 nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530168 break;
169
170 default:
171 if (ncm->response != NSS_CMN_RESPONSE_ACK) {
172 /*
173 * Check response
174 */
175 nss_info("%p: Received response %d for type %d, interface %d",
176 nss_ctx, ncm->response, ncm->type, ncm->interface);
177 }
178 }
Vijay Dewangan488e5372014-12-29 21:40:11 -0800179
180 /*
Stephen Wang49b474b2016-03-25 10:40:30 -0700181 * Update the callback and app_data for NOTIFY messages, n2h sends all notify messages
Vijay Dewangan488e5372014-12-29 21:40:11 -0800182 * to the same callback/app_data.
183 */
184 if (nnm->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
185 /*
186 * Place holder for the user to create right call
187 * back and app data when response is NSS_CMM_RESPONSE_NOTIFY
188 */
Stephen Wangaed46332016-12-12 17:29:03 -0800189 ncm->cb = (nss_ptr_t)nss_n2h_rd[nss_ctx->id].n2h_callback;
190 ncm->app_data = (nss_ptr_t)nss_n2h_rd[nss_ctx->id].app_data;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800191 }
192
193 /*
194 * Do we have a callback?
195 */
196 if (!ncm->cb) {
197 return;
198 }
199
200 /*
201 * Callback
202 */
203 cb = (nss_n2h_msg_callback_t)ncm->cb;
204 cb((void *)ncm->app_data, nnm);
205}
206
207/*
Vijay Dewangan634ce592015-01-07 17:21:09 -0800208 * nss_n2h_rps_cfg_callback()
209 * call back function for rps configuration
210 */
211static void nss_n2h_rps_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
212{
213 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)app_data;
214 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
215
216 /*
217 * Error, hence we are not updating the nss_n2h_empty_pool_buf
218 * Restore the current_value to its previous state
219 */
220 nss_n2h_rcp.response = NSS_FAILURE;
221 complete(&nss_n2h_rcp.complete);
222 nss_warning("%p: RPS configuration failed : %d\n", nss_ctx,
223 nnm->cm.error);
224 return;
225 }
226
227 nss_info("%p: RPS configuration succeeded: %d\n", nss_ctx,
228 nnm->cm.error);
229 nss_ctx->n2h_rps_en = nnm->msg.rps_cfg.enable;
230 nss_n2h_rcp.response = NSS_SUCCESS;
231 complete(&nss_n2h_rcp.complete);
232}
233
234/*
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530235 * nss_n2h_mitigation_cfg_callback()
236 * call back function for mitigation configuration
237 */
238static void nss_n2h_mitigation_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
239{
Stephen Wangaed46332016-12-12 17:29:03 -0800240 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530241 struct nss_top_instance *nss_top = &nss_top_main;
242 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
243
244 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
245
246 /*
247 * Error, hence we are not updating the nss_n2h_mitigate_en
248 */
249 nss_n2h_mitigationcp[core_num].response = NSS_FAILURE;
250 complete(&nss_n2h_mitigationcp[core_num].complete);
251 nss_warning("core%d: MITIGATION configuration failed : %d\n", core_num, nnm->cm.error);
252 return;
253 }
254
255 nss_info("core%d: MITIGATION configuration succeeded: %d\n", core_num, nnm->cm.error);
256
257 nss_ctx->n2h_mitigate_en = nnm->msg.mitigation_cfg.enable;
258 nss_n2h_mitigationcp[core_num].response = NSS_SUCCESS;
259 complete(&nss_n2h_mitigationcp[core_num].complete);
260}
261
262/*
263 * nss_n2h_buf_cfg_callback()
264 * call back function for pbuf configuration
265 */
266static void nss_n2h_bufs_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
267{
Stephen Wangaed46332016-12-12 17:29:03 -0800268 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530269 unsigned int allocated_sz;
270
271 struct nss_top_instance *nss_top = &nss_top_main;
272 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
273
274 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
275 nss_n2h_bufcp[core_num].response = NSS_FAILURE;
276 nss_warning("core%d: buf configuration failed : %d\n", core_num, nnm->cm.error);
277 goto done;
278 }
279
280 nss_info("core%d: buf configuration succeeded: %d\n", core_num, nnm->cm.error);
281
282 allocated_sz = nnm->msg.buf_pool.nss_buf_page_size * nnm->msg.buf_pool.nss_buf_num_pages;
283 nss_ctx->buf_sz_allocated += allocated_sz;
284
285 nss_n2h_bufcp[core_num].response = NSS_SUCCESS;
286
287done:
288 complete(&nss_n2h_bufcp[core_num].complete);
289}
290
291/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700292 * nss_n2h_payload_stats_callback()
293 * It gets called response to payload accounting.
Vijay Dewangan488e5372014-12-29 21:40:11 -0800294 */
Saurabh Misra71034db2015-06-04 16:18:38 -0700295static void nss_n2h_payload_stats_callback(void *app_data,
296 struct nss_n2h_msg *nnm)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800297{
Stephen Wangaed46332016-12-12 17:29:03 -0800298 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Saurabh Misra71034db2015-06-04 16:18:38 -0700299
Vijay Dewangan488e5372014-12-29 21:40:11 -0800300 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
301 struct nss_n2h_empty_pool_buf *nnepbcm;
302 nnepbcm = &nnm->msg.empty_pool_buf_cfg;
303
Saurabh Misra71034db2015-06-04 16:18:38 -0700304 nss_warning("%d: core empty pool buf set failure: %d\n",
305 core_num, nnm->cm.error);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800306 nss_n2h_nepbcfgp[core_num].response = NSS_FAILURE;
307 complete(&nss_n2h_nepbcfgp[core_num].complete);
308 return;
309 }
310
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700311 if (nnm->cm.type == NSS_TX_METADATA_TYPE_GET_WATER_MARK) {
312 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size =
Saurabh Misra71034db2015-06-04 16:18:38 -0700313 ntohl(nnm->msg.payload_info.pool_size);
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700314 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water =
Saurabh Misra71034db2015-06-04 16:18:38 -0700315 ntohl(nnm->msg.payload_info.low_water);
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700316 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water =
Saurabh Misra71034db2015-06-04 16:18:38 -0700317 ntohl(nnm->msg.payload_info.high_water);
318 }
319
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700320 if (nnm->cm.type == NSS_TX_METADATA_TYPE_GET_PAGED_WATER_MARK) {
321 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size =
322 ntohl(nnm->msg.paged_payload_info.pool_size);
323 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water =
324 ntohl(nnm->msg.paged_payload_info.low_water);
325 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water =
326 ntohl(nnm->msg.paged_payload_info.high_water);
327 }
328
Vijay Dewangan488e5372014-12-29 21:40:11 -0800329 nss_n2h_nepbcfgp[core_num].response = NSS_SUCCESS;
330 complete(&nss_n2h_nepbcfgp[core_num].complete);
331}
332
333/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530334 * nss_n2h_set_wifi_payloads_callback()
335 * call back function for response to wifi pool configuration
336 *
337 */
338static void nss_n2h_set_wifi_payloads_callback(void *app_data,
339 struct nss_n2h_msg *nnm)
340{
Arunkumar Tba9b4a02016-11-07 11:41:14 +0530341 struct nss_ctx_instance *nss_ctx __maybe_unused = (struct nss_ctx_instance *)app_data;
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530342 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
343
344 nss_n2h_wp.response = NSS_FAILURE;
345 complete(&nss_n2h_wp.complete);
346 nss_warning("%p: wifi pool configuration failed : %d\n", nss_ctx,
347 nnm->cm.error);
348 return;
349 }
350
351 nss_info("%p: wifi payload configuration succeeded: %d\n", nss_ctx,
352 nnm->cm.error);
353 nss_n2h_wp.response = NSS_SUCCESS;
354 complete(&nss_n2h_wp.complete);
355}
356
357/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700358 * nss_n2h_get_payload_info()
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700359 * Gets Payload information.
Vijay Dewangan488e5372014-12-29 21:40:11 -0800360 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700361static int nss_n2h_get_payload_info(nss_ptr_t core_num, struct nss_n2h_msg *nnm, struct nss_n2h_payload_info *nnepbcm)
Saurabh Misra71034db2015-06-04 16:18:38 -0700362{
363 struct nss_top_instance *nss_top = &nss_top_main;
364 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
Saurabh Misra71034db2015-06-04 16:18:38 -0700365 nss_tx_status_t nss_tx_status;
366 int ret = NSS_FAILURE;
367
368 /*
369 * Note that semaphore should be already held.
370 */
371
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700372 nss_tx_status = nss_n2h_tx_msg(nss_ctx, nnm);
Saurabh Misra71034db2015-06-04 16:18:38 -0700373
374 if (nss_tx_status != NSS_TX_SUCCESS) {
Stephen Wangaed46332016-12-12 17:29:03 -0800375 nss_warning("%p: core %d nss_tx error errorn", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700376 return NSS_FAILURE;
377 }
378
379 /*
380 * Blocking call, wait till we get ACK for this msg.
381 */
382 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
383 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
384 if (ret == 0) {
Stephen Wangaed46332016-12-12 17:29:03 -0800385 nss_warning("%p: core %d waiting for ack timed out\n", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700386 return NSS_FAILURE;
387 }
388
389 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
Stephen Wangaed46332016-12-12 17:29:03 -0800390 nss_warning("%p: core %d response returned failure\n", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700391 return NSS_FAILURE;
392 }
393
394 return NSS_SUCCESS;
395}
396
397/*
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700398 * nss_n2h_get_default_payload_info()
399 * Gets the default payload information.
400 */
401static int nss_n2h_get_default_payload_info(nss_ptr_t core_num)
402{
403 struct nss_n2h_msg nnm;
404
405 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
406 NSS_TX_METADATA_TYPE_GET_WATER_MARK,
407 sizeof(struct nss_n2h_payload_info),
408 nss_n2h_payload_stats_callback,
409 (void *)core_num);
410
411 return nss_n2h_get_payload_info(core_num, &nnm,
412 &nnm.msg.payload_info);
413}
414
415/*
416 * nss_n2h_get_paged_payload_info()
417 * Gets the paged payload information.
418 */
419static int nss_n2h_get_paged_payload_info(nss_ptr_t core_num)
420{
421 struct nss_n2h_msg nnm;
422
423 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
424 NSS_TX_METADATA_TYPE_GET_PAGED_WATER_MARK,
425 sizeof(struct nss_n2h_payload_info),
426 nss_n2h_payload_stats_callback,
427 (void *)core_num);
428
429 return nss_n2h_get_payload_info(core_num, &nnm,
430 &nnm.msg.paged_payload_info);
431}
432
433/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700434 * nss_n2h_set_empty_pool_buf()
435 * Sets empty pool buffer
436 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700437static int nss_n2h_set_empty_pool_buf(struct ctl_table *ctl, int write,
Saurabh Misra71034db2015-06-04 16:18:38 -0700438 void __user *buffer,
439 size_t *lenp, loff_t *ppos,
Stephen Wangaed46332016-12-12 17:29:03 -0800440 nss_ptr_t core_num, int *new_val)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800441{
442 struct nss_top_instance *nss_top = &nss_top_main;
443 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
444 struct nss_n2h_msg nnm;
445 struct nss_n2h_empty_pool_buf *nnepbcm;
446 nss_tx_status_t nss_tx_status;
447 int ret = NSS_FAILURE;
448
449 /*
450 * Acquiring semaphore
451 */
452 down(&nss_n2h_nepbcfgp[core_num].sem);
453
454 /*
455 * Take snap shot of current value
456 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700457 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size = *new_val;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800458
Saurabh Misra71034db2015-06-04 16:18:38 -0700459 if (!write) {
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700460 ret = nss_n2h_get_default_payload_info(core_num);
461 *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size;
Saurabh Misra71034db2015-06-04 16:18:38 -0700462 if (ret == NSS_FAILURE) {
463 up(&nss_n2h_nepbcfgp[core_num].sem);
464 return -EBUSY;
465 }
466
467 up(&nss_n2h_nepbcfgp[core_num].sem);
468
469 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
470 return ret;
471 }
472
Vijay Dewangan488e5372014-12-29 21:40:11 -0800473 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
Saurabh Misra71034db2015-06-04 16:18:38 -0700474 if (ret) {
Vijay Dewangan488e5372014-12-29 21:40:11 -0800475 up(&nss_n2h_nepbcfgp[core_num].sem);
476 return ret;
477 }
478
Vijay Dewangan488e5372014-12-29 21:40:11 -0800479 if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700480 nss_warning("%p: core %d setting %d < min number of buffer",
Stephen Wangaed46332016-12-12 17:29:03 -0800481 nss_ctx, (int)core_num, *new_val);
Stephen Wang06761022015-03-03 16:38:42 -0800482 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800483 }
484
485 nss_info("%p: core %d number of empty pool buffer is : %d\n",
Stephen Wangaed46332016-12-12 17:29:03 -0800486 nss_ctx, (int)core_num, *new_val);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800487
488 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
489 NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG,
490 sizeof(struct nss_n2h_empty_pool_buf),
Saurabh Misra71034db2015-06-04 16:18:38 -0700491 nss_n2h_payload_stats_callback,
Stephen Wangaed46332016-12-12 17:29:03 -0800492 (nss_ptr_t *)core_num);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800493
494 nnepbcm = &nnm.msg.empty_pool_buf_cfg;
495 nnepbcm->pool_size = htonl(*new_val);
496 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
497
498 if (nss_tx_status != NSS_TX_SUCCESS) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700499 nss_warning("%p: core %d nss_tx error empty pool buffer: %d\n",
Stephen Wangaed46332016-12-12 17:29:03 -0800500 nss_ctx, (int)core_num, *new_val);
Stephen Wang06761022015-03-03 16:38:42 -0800501 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800502 }
503
504 /*
505 * Blocking call, wait till we get ACK for this msg.
506 */
Saurabh Misra71034db2015-06-04 16:18:38 -0700507 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
508 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
Vijay Dewangan488e5372014-12-29 21:40:11 -0800509 if (ret == 0) {
Stephen Wangaed46332016-12-12 17:29:03 -0800510 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, (int)core_num);
Stephen Wang06761022015-03-03 16:38:42 -0800511 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800512 }
513
514 /*
515 * ACK/NACK received from NSS FW
516 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
517 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
518 */
519 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
Stephen Wang06761022015-03-03 16:38:42 -0800520 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800521 }
522
523 up(&nss_n2h_nepbcfgp[core_num].sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700524 return 0;
Stephen Wang06761022015-03-03 16:38:42 -0800525
526failure:
527 /*
528 * Restore the current_value to its previous state
529 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700530 *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size;
531 up(&nss_n2h_nepbcfgp[core_num].sem);
532 return NSS_FAILURE;
533}
534
535/*
536 * nss_n2h_set_empty_paged_pool_buf()
537 * Sets empty paged pool buffer
538 */
539static int nss_n2h_set_empty_paged_pool_buf(struct ctl_table *ctl, int write,
540 void __user *buffer,
541 size_t *lenp, loff_t *ppos,
542 nss_ptr_t core_num, int *new_val)
543{
544 struct nss_top_instance *nss_top = &nss_top_main;
545 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
546 struct nss_n2h_msg nnm;
547 struct nss_n2h_empty_pool_buf *nneppbcm;
548 nss_tx_status_t nss_tx_status;
549 int ret = NSS_FAILURE;
550
551 /*
552 * Acquiring semaphore
553 */
554 down(&nss_n2h_nepbcfgp[core_num].sem);
555
556 /*
557 * Take snap shot of current value
558 */
559 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size = *new_val;
560
561 if (!write) {
562 ret = nss_n2h_get_paged_payload_info(core_num);
563 *new_val = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size;
564 if (ret == NSS_FAILURE) {
565 up(&nss_n2h_nepbcfgp[core_num].sem);
566 return -EBUSY;
567 }
568
569 up(&nss_n2h_nepbcfgp[core_num].sem);
570
571 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
572 return ret;
573 }
574
575 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
576 if (ret) {
577 up(&nss_n2h_nepbcfgp[core_num].sem);
578 return ret;
579 }
580
581 if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
582 nss_warning("%p: core %d setting %d < min number of buffer",
583 nss_ctx, (int)core_num, *new_val);
584 goto failure;
585 }
586
587 nss_info("%p: core %d number of empty paged pool buffer is : %d\n",
588 nss_ctx, (int)core_num, *new_val);
589
590 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
591 NSS_TX_METADATA_TYPE_N2H_EMPTY_PAGED_POOL_BUF_CFG,
592 sizeof(struct nss_n2h_empty_pool_buf),
593 nss_n2h_payload_stats_callback,
594 (nss_ptr_t *)core_num);
595
596 nneppbcm = &nnm.msg.empty_pool_buf_cfg;
597 nneppbcm->pool_size = htonl(*new_val);
598 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
599
600 if (nss_tx_status != NSS_TX_SUCCESS) {
601 nss_warning("%p: core %d nss_tx error empty paged pool buffer: %d\n",
602 nss_ctx, (int)core_num, *new_val);
603 goto failure;
604 }
605
606 /*
607 * Blocking call, wait till we get ACK for this msg.
608 */
609 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
610 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
611 if (ret == 0) {
612 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, (int)core_num);
613 goto failure;
614 }
615
616 /*
617 * ACK/NACK received from NSS FW
618 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
619 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
620 */
621 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
622 goto failure;
623 }
624
625 up(&nss_n2h_nepbcfgp[core_num].sem);
626 return 0;
627
628failure:
629 /*
630 * Restore the current_value to its previous state
631 */
632 *new_val = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size;
Saurabh Misra71034db2015-06-04 16:18:38 -0700633 up(&nss_n2h_nepbcfgp[core_num].sem);
634 return NSS_FAILURE;
635}
636
637/*
638 * nss_n2h_set_water_mark()
639 * Sets water mark for N2H SOS
640 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700641static int nss_n2h_set_water_mark(struct ctl_table *ctl, int write,
Saurabh Misra71034db2015-06-04 16:18:38 -0700642 void __user *buffer,
643 size_t *lenp, loff_t *ppos,
Stephen Wangaed46332016-12-12 17:29:03 -0800644 uint32_t core_num, int *low, int *high)
Saurabh Misra71034db2015-06-04 16:18:38 -0700645{
646 struct nss_top_instance *nss_top = &nss_top_main;
647 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
648 struct nss_n2h_msg nnm;
649 struct nss_n2h_water_mark *wm;
650 nss_tx_status_t nss_tx_status;
651 int ret = NSS_FAILURE;
652
653 /*
654 * Acquiring semaphore
655 */
656 down(&nss_n2h_nepbcfgp[core_num].sem);
657
658 /*
659 * Take snap shot of current value
660 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700661 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water = *low;
662 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water = *high;
Saurabh Misra71034db2015-06-04 16:18:38 -0700663
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700664 if (!write || *low == -1 || *high == -1) {
665 ret = nss_n2h_get_default_payload_info(core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700666 if (ret == NSS_FAILURE) {
667 up(&nss_n2h_nepbcfgp[core_num].sem);
668 return -EBUSY;
669 }
670
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700671 *low = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water;
672 *high = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water;
Saurabh Misra71034db2015-06-04 16:18:38 -0700673 }
674
675 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700676 if (!write || ret) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700677 up(&nss_n2h_nepbcfgp[core_num].sem);
678 return ret;
679 }
680
Saurabh Misra71034db2015-06-04 16:18:38 -0700681 if ((*low < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) ||
682 (*high < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
683 nss_warning("%p: core %d setting %d, %d < min number of buffer",
684 nss_ctx, core_num, *low, *high);
685 goto failure;
686 }
687
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530688 if ((*low > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) ||
689 (*high > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700690 nss_warning("%p: core %d setting %d, %d is > upper limit",
691 nss_ctx, core_num, *low, *high);
692 goto failure;
693 }
694
695 if (*low > *high) {
696 nss_warning("%p: core %d setting low %d is more than high %d",
697 nss_ctx, core_num, *low, *high);
698 goto failure;
699 }
700
701 nss_info("%p: core %d number of low : %d and high : %d\n",
702 nss_ctx, core_num, *low, *high);
703
704 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
705 NSS_TX_METADATA_TYPE_SET_WATER_MARK,
706 sizeof(struct nss_n2h_water_mark),
707 nss_n2h_payload_stats_callback,
Stephen Wangaed46332016-12-12 17:29:03 -0800708 (void *)(nss_ptr_t)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700709
710 wm = &nnm.msg.wm;
711 wm->low_water = htonl(*low);
712 wm->high_water = htonl(*high);
713 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
714
715 if (nss_tx_status != NSS_TX_SUCCESS) {
716 nss_warning("%p: core %d nss_tx error setting : %d, %d\n",
717 nss_ctx, core_num, *low, *high);
718 goto failure;
719 }
720
721 /*
722 * Blocking call, wait till we get ACK for this msg.
723 */
724 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
725 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
726 if (ret == 0) {
727 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx,
728 core_num);
729 goto failure;
730 }
731
732 /*
733 * ACK/NACK received from NSS FW
734 */
735 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response)
736 goto failure;
737
738 up(&nss_n2h_nepbcfgp[core_num].sem);
739 return NSS_SUCCESS;
740
741failure:
742 /*
743 * Restore the current_value to its previous state
744 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700745 *low = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water;
746 *high = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water;
747 up(&nss_n2h_nepbcfgp[core_num].sem);
748 return -EINVAL;
749}
750
751/*
752 * nss_n2h_set_paged_water_mark()
753 * Sets water mark for paged pool N2H SOS
754 */
755static int nss_n2h_set_paged_water_mark(struct ctl_table *ctl, int write,
756 void __user *buffer,
757 size_t *lenp, loff_t *ppos,
758 uint32_t core_num, int *low, int *high)
759{
760 struct nss_top_instance *nss_top = &nss_top_main;
761 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
762 struct nss_n2h_msg nnm;
763 struct nss_n2h_water_mark *pwm;
764 nss_tx_status_t nss_tx_status;
765 int ret = NSS_FAILURE;
766
767 /*
768 * Acquiring semaphore
769 */
770 down(&nss_n2h_nepbcfgp[core_num].sem);
771
772 /*
773 * Take snap shot of current value
774 */
775 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water = *low;
776 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water = *high;
777
778 if (!write || *low == -1 || *high == -1) {
779 ret = nss_n2h_get_paged_payload_info(core_num);
780 if (ret == NSS_FAILURE) {
781 up(&nss_n2h_nepbcfgp[core_num].sem);
782 return -EBUSY;
783 }
784
785 *low = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water;
786 *high = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water;
787 }
788
789 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
790 if (!write || ret) {
791 up(&nss_n2h_nepbcfgp[core_num].sem);
792 return ret;
793 }
794
795 if ((*low < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) ||
796 (*high < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
797 nss_warning("%p: core %d setting %d, %d < min number of buffer",
798 nss_ctx, core_num, *low, *high);
799 goto failure;
800 }
801
802 if ((*low > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) ||
803 (*high > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
804 nss_warning("%p: core %d setting %d, %d is > upper limit",
805 nss_ctx, core_num, *low, *high);
806 goto failure;
807 }
808
809 if (*low > *high) {
810 nss_warning("%p: core %d setting low %d is more than high %d",
811 nss_ctx, core_num, *low, *high);
812 goto failure;
813 }
814
815 nss_info("%p: core %d number of low : %d and high : %d\n",
816 nss_ctx, core_num, *low, *high);
817
818 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
819 NSS_TX_METADATA_TYPE_SET_PAGED_WATER_MARK,
820 sizeof(struct nss_n2h_water_mark),
821 nss_n2h_payload_stats_callback,
822 (void *)(nss_ptr_t)core_num);
823
824 pwm = &nnm.msg.wm_paged;
825 pwm->low_water = htonl(*low);
826 pwm->high_water = htonl(*high);
827 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
828
829 if (nss_tx_status != NSS_TX_SUCCESS) {
830 nss_warning("%p: core %d nss_tx error setting : %d, %d\n",
831 nss_ctx, core_num, *low, *high);
832 goto failure;
833 }
834
835 /*
836 * Blocking call, wait till we get ACK for this msg.
837 */
838 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
839 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
840 if (ret == 0) {
841 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx,
842 core_num);
843 goto failure;
844 }
845
846 /*
847 * ACK/NACK received from NSS FW
848 */
849 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response)
850 goto failure;
851
852 up(&nss_n2h_nepbcfgp[core_num].sem);
853 return NSS_SUCCESS;
854
855failure:
856 /*
857 * Restore the current_value to its previous state
858 */
859 *low = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water;
860 *high = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water;
Stephen Wang06761022015-03-03 16:38:42 -0800861 up(&nss_n2h_nepbcfgp[core_num].sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700862 return -EINVAL;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800863}
864
865/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530866 * nss_n2h_cfg_wifi_pool()
867 * Sets number of wifi payloads to adjust high water mark for N2H SoS
868 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700869static int nss_n2h_cfg_wifi_pool(struct ctl_table *ctl, int write,
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530870 void __user *buffer,
871 size_t *lenp, loff_t *ppos,
872 int *payloads)
873{
874 struct nss_top_instance *nss_top = &nss_top_main;
875 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
876 struct nss_n2h_msg nnm;
877 struct nss_n2h_wifi_payloads *wp;
878 nss_tx_status_t nss_tx_status;
879 int ret = NSS_FAILURE;
880
881 /*
882 * Acquiring semaphore
883 */
884 down(&nss_n2h_wp.sem);
885
886 if (!write) {
887 *payloads = nss_n2h_wp.wifi_pool;
888
889 up(&nss_n2h_wp.sem);
890 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
891 return ret;
892 }
893
894 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
895 if (ret) {
896 up(&nss_n2h_wp.sem);
897 return ret;
898 }
899
900 /*
901 * If payloads parameter is not set, we do
902 * nothing.
903 */
904 if (*payloads == -1)
905 goto failure;
906
907 if ((*payloads < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
908 nss_warning("%p: wifi setting %d < min number of buffer",
909 nss_ctx, *payloads);
910 goto failure;
911 }
912
913 if ((*payloads > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
914 nss_warning("%p: wifi setting %d > max number of buffer",
915 nss_ctx, *payloads);
916 goto failure;
917 }
918
919 nss_info("%p: wifi payloads : %d\n",
920 nss_ctx, *payloads);
921
922 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
923 NSS_TX_METADATA_TYPE_N2H_WIFI_POOL_BUF_CFG,
924 sizeof(struct nss_n2h_wifi_payloads),
925 nss_n2h_set_wifi_payloads_callback,
926 (void *)nss_ctx);
927
928 wp = &nnm.msg.wp;
929 wp->payloads = htonl(*payloads);
930 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
931
932 if (nss_tx_status != NSS_TX_SUCCESS) {
933 nss_warning("%p: wifi setting %d nss_tx error",
934 nss_ctx, *payloads);
935 goto failure;
936 }
937
938 /*
939 * Blocking call, wait till we get ACK for this msg.
940 */
941 ret = wait_for_completion_timeout(&nss_n2h_wp.complete,
942 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
943 if (ret == 0) {
944 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
945 goto failure;
946 }
947
948 /*
949 * ACK/NACK received from NSS FW
950 */
951 if (NSS_FAILURE == nss_n2h_wp.response)
952 goto failure;
953
954 up(&nss_n2h_wp.sem);
955 return NSS_SUCCESS;
956
957failure:
958 up(&nss_n2h_wp.sem);
959 return -EINVAL;
960}
961
962/*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800963 * nss_n2h_empty_pool_buf_core1_handler()
964 * Sets the number of empty buffer for core 1
965 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700966static int nss_n2h_empty_pool_buf_cfg_core1_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700967 int write, void __user *buffer,
968 size_t *lenp, loff_t *ppos)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800969{
970 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
Saurabh Misra71034db2015-06-04 16:18:38 -0700971 NSS_CORE_1, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800972}
973
974/*
975 * nss_n2h_empty_pool_buf_core0_handler()
976 * Sets the number of empty buffer for core 0
977 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700978static int nss_n2h_empty_pool_buf_cfg_core0_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700979 int write, void __user *buffer,
980 size_t *lenp, loff_t *ppos)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800981{
982 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
Saurabh Misra71034db2015-06-04 16:18:38 -0700983 NSS_CORE_0, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]);
984}
985
986/*
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700987 * nss_n2h_empty_paged_pool_buf_cfg_core1_handler()
988 * Sets the number of empty paged buffer for core 1
989 */
990static int nss_n2h_empty_paged_pool_buf_cfg_core1_handler(struct ctl_table *ctl,
991 int write, void __user *buffer,
992 size_t *lenp, loff_t *ppos)
993{
994 return nss_n2h_set_empty_paged_pool_buf(ctl, write, buffer, lenp, ppos,
995 NSS_CORE_1, &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1]);
996}
997
998/*
999 * nss_n2h_empty_paged_pool_buf_cfg_core0_handler()
1000 * Sets the number of empty paged buffer for core 0
1001 */
1002static int nss_n2h_empty_paged_pool_buf_cfg_core0_handler(struct ctl_table *ctl,
1003 int write, void __user *buffer,
1004 size_t *lenp, loff_t *ppos)
1005{
1006 return nss_n2h_set_empty_paged_pool_buf(ctl, write, buffer, lenp, ppos,
1007 NSS_CORE_0, &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0]);
1008}
1009
1010/*
Saurabh Misra71034db2015-06-04 16:18:38 -07001011 * nss_n2h_water_mark_core1_handler()
1012 * Sets water mark for core 1
1013 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001014static int nss_n2h_water_mark_core1_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -07001015 int write, void __user *buffer,
1016 size_t *lenp, loff_t *ppos)
1017{
1018 return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos,
1019 NSS_CORE_1, &nss_n2h_water_mark[NSS_CORE_1][0],
1020 &nss_n2h_water_mark[NSS_CORE_1][1]);
1021}
1022
1023/*
1024 * nss_n2h_water_mark_core0_handler()
1025 * Sets water mark for core 0
1026 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001027static int nss_n2h_water_mark_core0_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -07001028 int write, void __user *buffer,
1029 size_t *lenp, loff_t *ppos)
1030{
1031 return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos,
1032 NSS_CORE_0, &nss_n2h_water_mark[NSS_CORE_0][0],
1033 &nss_n2h_water_mark[NSS_CORE_0][1]);
Vijay Dewangan488e5372014-12-29 21:40:11 -08001034}
1035
Vijay Dewangan634ce592015-01-07 17:21:09 -08001036/*
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001037 * nss_n2h_paged_water_mark_core1_handler()
1038 * Sets paged water mark for core 1
1039 */
1040static int nss_n2h_paged_water_mark_core1_handler(struct ctl_table *ctl,
1041 int write, void __user *buffer,
1042 size_t *lenp, loff_t *ppos)
1043{
1044 return nss_n2h_set_paged_water_mark(ctl, write, buffer, lenp, ppos,
1045 NSS_CORE_1, &nss_n2h_paged_water_mark[NSS_CORE_1][0],
1046 &nss_n2h_paged_water_mark[NSS_CORE_1][1]);
1047}
1048
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001049/*
1050 * nss_n2h_paged_water_mark_core0_handler()
1051 * Sets paged water mark for core 0
1052 */
1053static int nss_n2h_paged_water_mark_core0_handler(struct ctl_table *ctl,
1054 int write, void __user *buffer,
1055 size_t *lenp, loff_t *ppos)
1056{
1057 return nss_n2h_set_paged_water_mark(ctl, write, buffer, lenp, ppos,
1058 NSS_CORE_0, &nss_n2h_paged_water_mark[NSS_CORE_0][0],
1059 &nss_n2h_paged_water_mark[NSS_CORE_0][1]);
1060}
1061
1062/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301063 * nss_n2h_wifi_payloads_handler()
1064 * Sets number of wifi payloads
1065 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001066static int nss_n2h_wifi_payloads_handler(struct ctl_table *ctl,
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301067 int write, void __user *buffer,
1068 size_t *lenp, loff_t *ppos)
1069{
1070 return nss_n2h_cfg_wifi_pool(ctl, write, buffer, lenp, ppos,
1071 &nss_n2h_wifi_pool_buf_cfg);
1072}
1073
1074/*
ratheesh kannothab436af2017-07-20 08:51:07 +05301075 * nss_n2h_update_queue_config_callback()
1076 * Callback to handle the completion of queue config command
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301077 */
ratheesh kannothab436af2017-07-20 08:51:07 +05301078static void nss_n2h_update_queue_config_callback(void *app_data, struct nss_n2h_msg *nim)
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301079{
ratheesh kannothab436af2017-07-20 08:51:07 +05301080 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
1081 nss_warning("n2h Error response %d\n", nim->cm.response);
1082 nss_n2h_q_cfg_pvt.response = NSS_TX_FAILURE;
1083 } else {
1084 nss_n2h_q_cfg_pvt.response = NSS_TX_SUCCESS;
1085 }
1086
1087 complete(&nss_n2h_q_cfg_pvt.complete);
1088}
1089
1090/*
1091 * nss_n2h_update_queue_config_async()
1092 * Asynchronous call to send pnode queue configuration.
1093 */
1094nss_tx_status_t nss_n2h_update_queue_config_async(struct nss_ctx_instance *nss_ctx, bool mq_en, uint16_t *qlimits)
1095{
1096
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301097 struct nss_n2h_msg nnm;
1098 struct nss_n2h_pnode_queue_config *cfg;
1099 nss_tx_status_t status;
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301100 int i;
1101
1102 if (!mq_en) {
1103 return NSS_TX_SUCCESS;
1104 }
1105
ratheesh kannoth93ba95c2017-07-13 15:52:52 +05301106 /*
1107 * MQ mode doesnot make any sense if number of priority queues in NSS
1108 * is 1
1109 */
1110 if (NSS_MAX_NUM_PRI <= 1) {
1111 return NSS_TX_SUCCESS;
1112 }
1113
ratheesh kannothab436af2017-07-20 08:51:07 +05301114 memset(&nnm, 0, sizeof(struct nss_n2h_msg));
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301115
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301116 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1117 NSS_TX_METADATA_TYPE_N2H_SET_PNODE_QUEUE_CFG,
1118 sizeof(struct nss_n2h_pnode_queue_config), NULL, 0);
1119
ratheesh kannothab436af2017-07-20 08:51:07 +05301120 cfg = &nnm.msg.pn_q_cfg;
1121
1122 /*
1123 * Update limits
1124 */
1125 for (i = 0; i < NSS_MAX_NUM_PRI; i++) {
1126 cfg->qlimits[i] = qlimits[i];
1127 }
1128 cfg->mq_en = true;
1129
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301130 status = nss_n2h_tx_msg(nss_ctx, &nnm);
1131 if (status != NSS_TX_SUCCESS) {
1132 nss_warning("%p: nss_tx error to send pnode queue config\n", nss_ctx);
1133 return status;
1134 }
1135
1136 return NSS_TX_SUCCESS;
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301137}
ratheesh kannothab436af2017-07-20 08:51:07 +05301138EXPORT_SYMBOL(nss_n2h_update_queue_config_async);
1139
1140/*
1141 * nss_n2h_update_queue_config_sync()
1142 * Synchronous call to send pnode queue configuration.
1143 */
1144nss_tx_status_t nss_n2h_update_queue_config_sync(struct nss_ctx_instance *nss_ctx, bool mq_en, uint16_t *qlimits)
1145{
1146
1147 struct nss_n2h_msg nnm;
1148 struct nss_n2h_pnode_queue_config *cfg;
1149 nss_tx_status_t status;
1150 int ret, i;
1151
1152 if (!mq_en) {
1153 return NSS_TX_SUCCESS;
1154 }
1155
ratheesh kannoth93ba95c2017-07-13 15:52:52 +05301156 /*
1157 * MQ mode doesnot make any sense if number of priority queues in NSS
1158 * is 1
1159 */
1160 if (NSS_MAX_NUM_PRI <= 1) {
1161 return NSS_TX_SUCCESS;
1162 }
1163
ratheesh kannothab436af2017-07-20 08:51:07 +05301164 memset(&nnm, 0, sizeof(struct nss_n2h_msg));
1165
1166 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1167 NSS_TX_METADATA_TYPE_N2H_SET_PNODE_QUEUE_CFG,
1168 sizeof(struct nss_n2h_pnode_queue_config), nss_n2h_update_queue_config_callback, 0);
1169
1170 cfg = &nnm.msg.pn_q_cfg;
1171
1172 /*
1173 * Update limits
1174 */
1175 for (i = 0; i < NSS_MAX_NUM_PRI; i++) {
1176 cfg->qlimits[i] = qlimits[i];
1177 }
1178 cfg->mq_en = true;
1179
1180 down(&nss_n2h_q_cfg_pvt.sem);
1181
1182 status = nss_n2h_tx_msg(nss_ctx, &nnm);
1183
1184 if (status != NSS_TX_SUCCESS) {
1185 nss_warning("%p: n2h_tx_msg failed\n", nss_ctx);
1186 up(&nss_n2h_q_cfg_pvt.sem);
1187 return status;
1188 }
1189 ret = wait_for_completion_timeout(&nss_n2h_q_cfg_pvt.complete, msecs_to_jiffies(NSS_N2H_TX_TIMEOUT));
1190
1191 if (!ret) {
1192 nss_warning("%p: Timeout expired for pnode queue config sync message\n", nss_ctx);
1193 nss_n2h_q_cfg_pvt.response = NSS_TX_FAILURE;
1194 }
1195
1196 status = nss_n2h_q_cfg_pvt.response;
1197 up(&nss_n2h_q_cfg_pvt.sem);
1198 return status;
1199}
1200EXPORT_SYMBOL(nss_n2h_update_queue_config_sync);
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301201
1202/*
Vijay Dewangan634ce592015-01-07 17:21:09 -08001203 * nss_n2h_rps_cfg()
1204 * Send Message to NSS to enable RPS.
1205 */
Stephen Wang49b474b2016-03-25 10:40:30 -07001206static nss_tx_status_t nss_n2h_rps_cfg(struct nss_ctx_instance *nss_ctx, int enable_rps)
Vijay Dewangan634ce592015-01-07 17:21:09 -08001207{
1208 struct nss_n2h_msg nnm;
1209 struct nss_n2h_rps *rps_cfg;
1210 nss_tx_status_t nss_tx_status;
1211 int ret;
1212
1213 down(&nss_n2h_rcp.sem);
1214 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_RPS_CFG,
1215 sizeof(struct nss_n2h_rps),
1216 nss_n2h_rps_cfg_callback,
1217 (void *)nss_ctx);
1218
1219 rps_cfg = &nnm.msg.rps_cfg;
1220 rps_cfg->enable = enable_rps;
1221
1222 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1223
1224 if (nss_tx_status != NSS_TX_SUCCESS) {
1225 nss_warning("%p: nss_tx error setting rps\n", nss_ctx);
1226
1227 up(&nss_n2h_rcp.sem);
1228 return NSS_FAILURE;
1229 }
1230
1231 /*
1232 * Blocking call, wait till we get ACK for this msg.
1233 */
1234 ret = wait_for_completion_timeout(&nss_n2h_rcp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
1235 if (ret == 0) {
1236 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
1237 up(&nss_n2h_rcp.sem);
1238 return NSS_FAILURE;
1239 }
1240
1241 /*
1242 * ACK/NACK received from NSS FW
1243 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
1244 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
1245 */
1246 if (NSS_FAILURE == nss_n2h_rcp.response) {
1247 up(&nss_n2h_rcp.sem);
1248 return NSS_FAILURE;
1249 }
1250
1251 up(&nss_n2h_rcp.sem);
1252 return NSS_SUCCESS;
1253}
1254
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301255/*
1256 * nss_n2h_mitigation_cfg()
1257 * Send Message to NSS to disable MITIGATION.
1258 */
Stephen Wang49b474b2016-03-25 10:40:30 -07001259static 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 +05301260{
1261 struct nss_n2h_msg nnm;
1262 struct nss_n2h_mitigation *mitigation_cfg;
1263 nss_tx_status_t nss_tx_status;
1264 int ret;
1265
1266 nss_assert(core_num < NSS_CORE_MAX);
1267
1268 down(&nss_n2h_mitigationcp[core_num].sem);
1269 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG,
1270 sizeof(struct nss_n2h_mitigation),
1271 nss_n2h_mitigation_cfg_callback,
1272 (void *)core_num);
1273
1274 mitigation_cfg = &nnm.msg.mitigation_cfg;
1275 mitigation_cfg->enable = enable_mitigation;
1276
1277 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1278
1279 if (nss_tx_status != NSS_TX_SUCCESS) {
1280 nss_warning("%p: nss_tx error setting mitigation\n", nss_ctx);
1281 goto failure;
1282 }
1283
1284 /*
1285 * Blocking call, wait till we get ACK for this msg.
1286 */
1287 ret = wait_for_completion_timeout(&nss_n2h_mitigationcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
1288 if (ret == 0) {
1289 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
1290 goto failure;
1291 }
1292
1293 /*
1294 * ACK/NACK received from NSS FW
1295 */
1296 if (NSS_FAILURE == nss_n2h_mitigationcp[core_num].response) {
1297 goto failure;
1298 }
1299
1300 up(&nss_n2h_mitigationcp[core_num].sem);
1301 return NSS_SUCCESS;
1302
1303failure:
1304 up(&nss_n2h_mitigationcp[core_num].sem);
1305 return NSS_FAILURE;
1306}
1307
1308static inline void nss_n2h_buf_pool_free(struct nss_n2h_buf_pool *buf_pool)
1309{
1310 int page_count;
1311 for (page_count = 0; page_count < buf_pool->nss_buf_num_pages; page_count++) {
Stephen Wang7df68832017-08-10 16:54:35 -07001312 kfree((void *)buf_pool->nss_buf_pool_vaddr[page_count]);
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301313 }
1314}
1315
1316/*
1317 * nss_n2h_buf_cfg()
1318 * Send Message to NSS to enable pbufs.
1319 */
Stephen Wang49b474b2016-03-25 10:40:30 -07001320static nss_tx_status_t nss_n2h_buf_pool_cfg(struct nss_ctx_instance *nss_ctx,
Tallapragada4b0161b2016-07-07 21:38:34 +05301321 int buf_pool_size, nss_core_id_t core_num)
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301322{
1323 static struct nss_n2h_msg nnm;
1324 struct nss_n2h_buf_pool *buf_pool;
1325 nss_tx_status_t nss_tx_status;
1326 int ret;
1327 int page_count;
1328 int num_pages = ALIGN(buf_pool_size, PAGE_SIZE)/PAGE_SIZE;
1329
1330 nss_assert(core_num < NSS_CORE_MAX);
1331
1332 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_METADATA_TYPE_N2H_ADD_BUF_POOL,
1333 sizeof(struct nss_n2h_buf_pool),
1334 nss_n2h_bufs_cfg_callback,
1335 (void *)core_num);
1336
1337 do {
1338
1339 down(&nss_n2h_bufcp[core_num].sem);
1340
1341 buf_pool = &nnm.msg.buf_pool;
1342 buf_pool->nss_buf_page_size = PAGE_SIZE;
1343
1344 for (page_count = 0; page_count < MAX_PAGES_PER_MSG && num_pages; page_count++, num_pages--) {
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301345 void *kern_addr = kzalloc(PAGE_SIZE, GFP_ATOMIC);
1346 if (!kern_addr) {
1347 BUG_ON(!page_count);
1348 break;
1349 }
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301350
Radha krishna Simha Jiguru60068fb2017-07-28 17:40:52 +05301351 kmemleak_not_leak(kern_addr);
Stephen Wang7df68832017-08-10 16:54:35 -07001352 buf_pool->nss_buf_pool_vaddr[page_count] = (nss_ptr_t)kern_addr;
Stephen Wangefd38512017-01-24 14:01:02 -08001353 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 +05301354 }
1355
1356 buf_pool->nss_buf_num_pages = page_count;
1357 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1358 if (nss_tx_status != NSS_TX_SUCCESS) {
1359
1360 nss_n2h_buf_pool_free(buf_pool);
1361 nss_warning("%p: nss_tx error setting pbuf\n", nss_ctx);
1362 goto failure;
1363 }
1364
1365 /*
1366 * Blocking call, wait till we get ACK for this msg.
1367 */
1368 ret = wait_for_completion_timeout(&nss_n2h_bufcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
1369 if (ret == 0) {
1370 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
1371 goto failure;
1372 }
1373
1374 /*
1375 * ACK/NACK received from NSS FW
1376 */
1377 if (NSS_FAILURE == nss_n2h_bufcp[core_num].response) {
1378
1379 nss_n2h_buf_pool_free(buf_pool);
1380 goto failure;
1381 }
1382
1383 up(&nss_n2h_bufcp[core_num].sem);
1384 } while(num_pages);
1385
1386 return NSS_SUCCESS;
1387failure:
1388 up(&nss_n2h_bufcp[core_num].sem);
1389 return NSS_FAILURE;
1390}
1391
Stephen Wang49b474b2016-03-25 10:40:30 -07001392/*
1393 * nss_rps_handler()
1394 * Enable NSS RPS
1395 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001396static 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 -07001397{
1398 struct nss_top_instance *nss_top = &nss_top_main;
1399 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
1400 int ret;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301401
Stephen Wang49b474b2016-03-25 10:40:30 -07001402 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1403 if (!ret) {
1404 if ((write) && (nss_n2h_rps_config == 1)) {
1405 printk(KERN_INFO "Enabling NSS RPS\n");
1406
1407 return nss_n2h_rps_cfg(nss_ctx, 1);
1408 }
1409
1410 if ((write) && (nss_n2h_rps_config == 0)) {
1411 printk(KERN_INFO "Runtime disabling of NSS RPS not supported\n");
1412 return ret;
1413 }
1414
1415 if (write) {
1416 printk(KERN_INFO "Invalid input value.Valid values are 0 and 1\n");
1417 }
1418
1419 }
1420
1421 return ret;
1422}
1423
1424/*
1425 * nss_mitigation_handler()
1426 * Enable NSS MITIGATION
1427 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001428static 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 -07001429{
1430 struct nss_top_instance *nss_top = &nss_top_main;
1431 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0];
1432 int ret;
1433
1434 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1435 if (ret) {
1436 return ret;
1437 }
1438
1439 /*
1440 * It's a read operation
1441 */
1442 if (!write) {
1443 return ret;
1444 }
1445
1446 if (!nss_n2h_core0_mitigation_cfg) {
1447 printk(KERN_INFO "Disabling NSS MITIGATION\n");
1448 nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_0);
1449 return 0;
1450 }
1451 printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n");
1452 return -EINVAL;
1453}
1454
1455/*
1456 * nss_mitigation_handler()
1457 * Enable NSS MITIGATION
1458 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001459static 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 -07001460{
1461 struct nss_top_instance *nss_top = &nss_top_main;
1462 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1];
1463 int ret;
1464
1465 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1466 if (ret) {
1467 return ret;
1468 }
1469
1470 /*
1471 * It's a read operation
1472 */
1473 if (!write) {
1474 return ret;
1475 }
1476
1477 if (!nss_n2h_core1_mitigation_cfg) {
1478 printk(KERN_INFO "Disabling NSS MITIGATION\n");
1479 nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_1);
1480 return 0;
1481 }
1482 printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n");
1483 return -EINVAL;
1484}
1485
1486/*
1487 * nss_buf_handler()
1488 * Add extra NSS bufs from host memory
1489 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001490static 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 -07001491{
1492 struct nss_top_instance *nss_top = &nss_top_main;
1493 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0];
1494 int ret;
1495
1496 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1497 if (ret) {
1498 return ret;
1499 }
1500
1501 /*
1502 * It's a read operation
1503 */
1504 if (!write) {
1505 return ret;
1506 }
1507
1508 if (nss_ctx->buf_sz_allocated) {
1509 nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1510 return -EPERM;
1511 }
1512
1513 if ((nss_n2h_core0_add_buf_pool_size >= 1) && (nss_n2h_core0_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) {
1514 printk(KERN_INFO "configuring additional NSS pbufs\n");
1515 ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core0_add_buf_pool_size, NSS_CORE_0);
1516 nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1517 printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated);
1518 return ret;
1519 }
1520
1521 printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE);
1522 return -EINVAL;
1523}
1524
1525/*
1526 * nss_n2h_buf_handler()
1527 * Add extra NSS bufs from host memory
1528 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001529static 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 -07001530{
1531 struct nss_top_instance *nss_top = &nss_top_main;
1532 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1];
1533 int ret;
1534
1535 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1536 if (ret) {
1537 return ret;
1538 }
1539
1540 /*
1541 * It's a read operation
1542 */
1543 if (!write) {
1544 return ret;
1545 }
1546
1547 if (nss_ctx->buf_sz_allocated) {
1548 nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1549 return -EPERM;
1550 }
1551
1552 if ((nss_n2h_core1_add_buf_pool_size >= 1) && (nss_n2h_core1_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) {
1553 printk(KERN_INFO "configuring additional NSS pbufs\n");
1554 ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core1_add_buf_pool_size, NSS_CORE_1);
1555 nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1556 printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated);
1557 return ret;
1558 }
1559
1560 printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE);
1561 return -EINVAL;
1562}
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301563
Stephen Wang52e6d342016-03-29 15:02:33 -07001564static struct ctl_table nss_n2h_table[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001565 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001566 .procname = "n2h_empty_pool_buf_core0",
1567 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0],
1568 .maxlen = sizeof(int),
1569 .mode = 0644,
1570 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler,
Vijay Dewangan488e5372014-12-29 21:40:11 -08001571 },
1572 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001573 .procname = "n2h_empty_pool_buf_core1",
1574 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1],
1575 .maxlen = sizeof(int),
1576 .mode = 0644,
1577 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core1_handler,
1578 },
1579 {
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001580 .procname = "n2h_empty_paged_pool_buf_core0",
1581 .data = &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0],
1582 .maxlen = sizeof(int),
1583 .mode = 0644,
1584 .proc_handler = &nss_n2h_empty_paged_pool_buf_cfg_core0_handler,
1585 },
1586 {
1587 .procname = "n2h_empty_paged_pool_buf_core1",
1588 .data = &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1],
1589 .maxlen = sizeof(int),
1590 .mode = 0644,
1591 .proc_handler = &nss_n2h_empty_paged_pool_buf_cfg_core1_handler,
1592 },
1593
1594 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001595 .procname = "n2h_low_water_core0",
1596 .data = &nss_n2h_water_mark[NSS_CORE_0][0],
1597 .maxlen = sizeof(int),
1598 .mode = 0644,
1599 .proc_handler = &nss_n2h_water_mark_core0_handler,
1600 },
1601 {
1602 .procname = "n2h_low_water_core1",
1603 .data = &nss_n2h_water_mark[NSS_CORE_1][0],
1604 .maxlen = sizeof(int),
1605 .mode = 0644,
1606 .proc_handler = &nss_n2h_water_mark_core1_handler,
1607 },
1608 {
1609 .procname = "n2h_high_water_core0",
1610 .data = &nss_n2h_water_mark[NSS_CORE_0][1],
1611 .maxlen = sizeof(int),
1612 .mode = 0644,
1613 .proc_handler = &nss_n2h_water_mark_core0_handler,
1614 },
1615 {
1616 .procname = "n2h_high_water_core1",
1617 .data = &nss_n2h_water_mark[NSS_CORE_1][1],
1618 .maxlen = sizeof(int),
1619 .mode = 0644,
1620 .proc_handler = &nss_n2h_water_mark_core1_handler,
Vijay Dewangan488e5372014-12-29 21:40:11 -08001621 },
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301622 {
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001623 .procname = "n2h_paged_low_water_core0",
1624 .data = &nss_n2h_paged_water_mark[NSS_CORE_0][0],
1625 .maxlen = sizeof(int),
1626 .mode = 0644,
1627 .proc_handler = &nss_n2h_paged_water_mark_core0_handler,
1628 },
1629 {
1630 .procname = "n2h_paged_low_water_core1",
1631 .data = &nss_n2h_paged_water_mark[NSS_CORE_1][0],
1632 .maxlen = sizeof(int),
1633 .mode = 0644,
1634 .proc_handler = &nss_n2h_paged_water_mark_core1_handler,
1635 },
1636 {
1637 .procname = "n2h_paged_high_water_core0",
1638 .data = &nss_n2h_paged_water_mark[NSS_CORE_0][1],
1639 .maxlen = sizeof(int),
1640 .mode = 0644,
1641 .proc_handler = &nss_n2h_paged_water_mark_core0_handler,
1642 },
1643 {
1644 .procname = "n2h_paged_high_water_core1",
1645 .data = &nss_n2h_paged_water_mark[NSS_CORE_1][1],
1646 .maxlen = sizeof(int),
1647 .mode = 0644,
1648 .proc_handler = &nss_n2h_paged_water_mark_core1_handler,
1649 },
1650 {
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301651 .procname = "n2h_wifi_pool_buf",
1652 .data = &nss_n2h_wifi_pool_buf_cfg,
1653 .maxlen = sizeof(int),
1654 .mode = 0644,
1655 .proc_handler = &nss_n2h_wifi_payloads_handler,
1656 },
Stephen Wang49b474b2016-03-25 10:40:30 -07001657 {
1658 .procname = "rps",
1659 .data = &nss_n2h_rps_config,
1660 .maxlen = sizeof(int),
1661 .mode = 0644,
1662 .proc_handler = &nss_n2h_rpscfg_handler,
1663 },
1664 {
1665 .procname = "mitigation_core0",
1666 .data = &nss_n2h_core0_mitigation_cfg,
1667 .maxlen = sizeof(int),
1668 .mode = 0644,
1669 .proc_handler = &nss_n2h_mitigationcfg_core0_handler,
1670 },
1671 {
1672 .procname = "mitigation_core1",
1673 .data = &nss_n2h_core1_mitigation_cfg,
1674 .maxlen = sizeof(int),
1675 .mode = 0644,
1676 .proc_handler = &nss_n2h_mitigationcfg_core1_handler,
1677 },
1678 {
1679 .procname = "extra_pbuf_core0",
1680 .data = &nss_n2h_core0_add_buf_pool_size,
1681 .maxlen = sizeof(int),
1682 .mode = 0644,
1683 .proc_handler = &nss_n2h_buf_cfg_core0_handler,
1684 },
1685 {
1686 .procname = "extra_pbuf_core1",
1687 .data = &nss_n2h_core1_add_buf_pool_size,
1688 .maxlen = sizeof(int),
1689 .mode = 0644,
1690 .proc_handler = &nss_n2h_buf_cfg_core1_handler,
1691 },
Vijay Dewangan488e5372014-12-29 21:40:11 -08001692
1693 { }
1694};
1695
Stephen Wang52e6d342016-03-29 15:02:33 -07001696static struct ctl_table nss_n2h_dir[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001697 {
1698 .procname = "n2hcfg",
1699 .mode = 0555,
1700 .child = nss_n2h_table,
1701 },
1702 { }
1703};
1704
Stephen Wang52e6d342016-03-29 15:02:33 -07001705static struct ctl_table nss_n2h_root_dir[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001706 {
1707 .procname = "nss",
1708 .mode = 0555,
1709 .child = nss_n2h_dir,
1710 },
1711 { }
1712};
1713
Stephen Wang52e6d342016-03-29 15:02:33 -07001714static struct ctl_table nss_n2h_root[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001715 {
1716 .procname = "dev",
1717 .mode = 0555,
1718 .child = nss_n2h_root_dir,
1719 },
1720 { }
1721};
1722
1723static struct ctl_table_header *nss_n2h_header;
1724
1725/*
Stephen Wang49b474b2016-03-25 10:40:30 -07001726 * nss_n2h_flush_payloads()
1727 * Sends a command down to NSS for flushing all payloads
1728 */
1729nss_tx_status_t nss_n2h_flush_payloads(struct nss_ctx_instance *nss_ctx)
1730{
1731 struct nss_n2h_msg nnm;
1732 struct nss_n2h_flush_payloads *nnflshpl;
1733 nss_tx_status_t nss_tx_status;
1734
1735 nnflshpl = &nnm.msg.flush_payloads;
1736
1737 /*
1738 * TODO: No additional information sent in message
1739 * as of now. Need to initialize message content accordingly
1740 * if needed.
1741 */
1742 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1743 NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS,
1744 sizeof(struct nss_n2h_flush_payloads),
1745 NULL,
1746 NULL);
1747
1748 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1749 if (nss_tx_status != NSS_TX_SUCCESS) {
1750 nss_warning("%p: failed to send flush payloads command to NSS\n",
1751 nss_ctx);
1752
1753 return NSS_TX_FAILURE;
1754 }
1755
1756 return NSS_TX_SUCCESS;
1757}
1758
1759/*
Vijay Dewangan488e5372014-12-29 21:40:11 -08001760 * nss_n2h_msg_init()
Stephen Wang49b474b2016-03-25 10:40:30 -07001761 * Initialize n2h message.
Vijay Dewangan488e5372014-12-29 21:40:11 -08001762 */
1763void nss_n2h_msg_init(struct nss_n2h_msg *nim, uint16_t if_num, uint32_t type,
Vijay Dewangan634ce592015-01-07 17:21:09 -08001764 uint32_t len, nss_n2h_msg_callback_t cb, void *app_data)
Vijay Dewangan488e5372014-12-29 21:40:11 -08001765{
1766 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
1767}
1768
Vijay Dewangan488e5372014-12-29 21:40:11 -08001769/*
Vijay Dewangan488e5372014-12-29 21:40:11 -08001770 * nss_n2h_tx_msg()
1771 * Send messages to NSS n2h pacakge
1772 */
1773nss_tx_status_t nss_n2h_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_n2h_msg *nnm)
1774{
1775 struct nss_n2h_msg *nnm2;
1776 struct nss_cmn_msg *ncm = &nnm->cm;
1777 struct sk_buff *nbuf;
1778 nss_tx_status_t status;
1779
1780 NSS_VERIFY_CTX_MAGIC(nss_ctx);
1781 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
1782 return NSS_TX_FAILURE_NOT_READY;
1783 }
1784
1785 /*
1786 * Sanity check the message
1787 */
1788 if (ncm->interface != NSS_N2H_INTERFACE) {
1789 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
1790 return NSS_TX_FAILURE;
1791 }
1792
1793 if (ncm->type >= NSS_METADATA_TYPE_N2H_MAX) {
1794 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
1795 return NSS_TX_FAILURE;
1796 }
1797
Suruchi Agarwalef8a8702016-01-08 12:40:08 -08001798 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_n2h_msg)) {
1799 nss_warning("%p: tx request for another interface: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Vijay Dewangan488e5372014-12-29 21:40:11 -08001800 return NSS_TX_FAILURE;
1801 }
1802
Vijay Dewangan488e5372014-12-29 21:40:11 -08001803 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
1804 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -08001805 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 -08001806 return NSS_TX_FAILURE;
1807 }
1808
1809 /*
1810 * Copy the message to our skb.
1811 */
1812 nnm2 = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg));
1813 memcpy(nnm2, nnm, sizeof(struct nss_n2h_msg));
1814 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
1815 if (status != NSS_CORE_STATUS_SUCCESS) {
1816 dev_kfree_skb_any(nbuf);
1817 nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx);
1818 return NSS_TX_FAILURE;
1819 }
1820
Stephen Wang90c67de2016-04-26 15:15:59 -07001821 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Vijay Dewangan488e5372014-12-29 21:40:11 -08001822 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
1823 return NSS_TX_SUCCESS;
1824}
1825
Vijay Dewangan488e5372014-12-29 21:40:11 -08001826/*
1827 * nss_n2h_notify_register()
1828 * Register to received N2H events.
1829 *
1830 * NOTE: Do we want to pass an nss_ctx here so that we can register for n2h on any core?
1831 */
1832struct nss_ctx_instance *nss_n2h_notify_register(int core, nss_n2h_msg_callback_t cb, void *app_data)
1833{
1834 if (core >= NSS_MAX_CORES) {
1835 nss_warning("Input core number %d is wrong \n", core);
1836 return NULL;
1837 }
1838 /*
1839 * TODO: We need to have a new array in support of the new API
1840 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
1841 */
1842 nss_n2h_rd[core].n2h_callback = cb;
1843 nss_n2h_rd[core].app_data = app_data;
1844 return &nss_top_main.nss[core];
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301845}
1846
1847/*
1848 * nss_n2h_register_handler()
1849 */
Thomas Wu91f4bdf2017-06-09 12:03:02 -07001850void nss_n2h_register_handler(struct nss_ctx_instance *nss_ctx)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301851{
ratheesh kannothab436af2017-07-20 08:51:07 +05301852 sema_init(&nss_n2h_q_cfg_pvt.sem, 1);
1853 init_completion(&nss_n2h_q_cfg_pvt.complete);
1854
Thomas Wu91f4bdf2017-06-09 12:03:02 -07001855 nss_core_register_handler(nss_ctx, NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL);
Stephen Wang49b474b2016-03-25 10:40:30 -07001856}
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -07001857
Stephen Wang49b474b2016-03-25 10:40:30 -07001858/*
1859 * nss_n2h_register_sysctl()
1860 */
1861void nss_n2h_register_sysctl(void)
1862{
Vijay Dewangan634ce592015-01-07 17:21:09 -08001863 /*
1864 * RPS sema init
1865 */
1866 sema_init(&nss_n2h_rcp.sem, 1);
1867 init_completion(&nss_n2h_rcp.complete);
1868
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301869 /*
1870 * MITIGATION sema init for core0
1871 */
1872 sema_init(&nss_n2h_mitigationcp[NSS_CORE_0].sem, 1);
1873 init_completion(&nss_n2h_mitigationcp[NSS_CORE_0].complete);
1874
1875 /*
1876 * MITIGATION sema init for core1
1877 */
1878 sema_init(&nss_n2h_mitigationcp[NSS_CORE_1].sem, 1);
1879 init_completion(&nss_n2h_mitigationcp[NSS_CORE_1].complete);
1880
1881 /*
1882 * PBUF addition sema init for core0
1883 */
1884 sema_init(&nss_n2h_bufcp[NSS_CORE_0].sem, 1);
1885 init_completion(&nss_n2h_bufcp[NSS_CORE_0].complete);
1886
1887 /*
1888 * PBUF addition sema init for core1
1889 */
1890 sema_init(&nss_n2h_bufcp[NSS_CORE_1].sem, 1);
1891 init_completion(&nss_n2h_bufcp[NSS_CORE_1].complete);
Vijay Dewangan634ce592015-01-07 17:21:09 -08001892
Stephen Wang49b474b2016-03-25 10:40:30 -07001893 /*
1894 * Core0
1895 */
1896 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1);
1897 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete);
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001898 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.pool_size =
Stephen Wang49b474b2016-03-25 10:40:30 -07001899 nss_n2h_empty_pool_buf_cfg[NSS_CORE_0];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001900 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.low_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07001901 nss_n2h_water_mark[NSS_CORE_0][0];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001902 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.high_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07001903 nss_n2h_water_mark[NSS_CORE_0][1];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001904 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.pool_size =
1905 nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0];
1906 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.low_water =
1907 nss_n2h_paged_water_mark[NSS_CORE_0][0];
1908 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.high_water =
1909 nss_n2h_paged_water_mark[NSS_CORE_0][1];
1910
Stephen Wang49b474b2016-03-25 10:40:30 -07001911 /*
1912 * Core1
1913 */
1914 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_1].sem, 1);
1915 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_1].complete);
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001916 nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.pool_size =
Stephen Wang49b474b2016-03-25 10:40:30 -07001917 nss_n2h_empty_pool_buf_cfg[NSS_CORE_1];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001918 nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.low_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07001919 nss_n2h_water_mark[NSS_CORE_1][0];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001920 nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.high_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07001921 nss_n2h_water_mark[NSS_CORE_1][1];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001922 nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.pool_size =
1923 nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1];
1924 nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.low_water =
1925 nss_n2h_paged_water_mark[NSS_CORE_1][0];
1926 nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.high_water =
1927 nss_n2h_paged_water_mark[NSS_CORE_1][1];
1928
Stephen Wang49b474b2016-03-25 10:40:30 -07001929 /*
1930 * WiFi pool buf cfg sema init
1931 */
1932 sema_init(&nss_n2h_wp.sem, 1);
1933 init_completion(&nss_n2h_wp.complete);
1934
Vijay Dewangan488e5372014-12-29 21:40:11 -08001935 nss_n2h_notify_register(NSS_CORE_0, NULL, NULL);
1936 nss_n2h_notify_register(NSS_CORE_1, NULL, NULL);
1937
Stephen Wang49b474b2016-03-25 10:40:30 -07001938 /*
1939 * Register sysctl table.
1940 */
1941 nss_n2h_header = register_sysctl_table(nss_n2h_root);
1942}
1943
1944/*
1945 * nss_n2h_unregister_sysctl()
1946 * Unregister sysctl specific to n2h
1947 */
1948void nss_n2h_unregister_sysctl(void)
1949{
1950 /*
1951 * Unregister sysctl table.
1952 */
1953 if (nss_n2h_header) {
1954 unregister_sysctl_table(nss_n2h_header);
1955 }
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301956}
Vijay Dewangan488e5372014-12-29 21:40:11 -08001957
1958EXPORT_SYMBOL(nss_n2h_notify_register);