blob: 6acf338062ccec05476688434b629d19bf186bba [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;
61
62 spin_lock_bh(&nss_top->stats_lock);
63
64 /*
65 * common node stats
66 */
67 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_PKTS] += nnss->node_stats.rx_packets;
68 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_BYTES] += nnss->node_stats.rx_bytes;
69 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_DROPPED] += nnss->node_stats.rx_dropped;
70 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
73 /*
74 * General N2H stats
75 */
Murat Sezgin0c0561d2014-04-09 18:55:58 -070076 nss_ctx->stats_n2h[NSS_STATS_N2H_QUEUE_DROPPED] += nnss->queue_dropped;
77 nss_ctx->stats_n2h[NSS_STATS_N2H_TOTAL_TICKS] += nnss->total_ticks;
78 nss_ctx->stats_n2h[NSS_STATS_N2H_WORST_CASE_TICKS] += nnss->worst_case_ticks;
79 nss_ctx->stats_n2h[NSS_STATS_N2H_ITERATIONS] += nnss->iterations;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053080
81 /*
Thomas Wu3fd8dd72014-06-11 15:57:05 -070082 * pbuf manager ocm and default pool stats
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053083 */
Thomas Wu3fd8dd72014-06-11 15:57:05 -070084 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_ALLOC_FAILS] += nnss->pbuf_ocm_stats.pbuf_alloc_fails;
85 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_FREE_COUNT] = nnss->pbuf_ocm_stats.pbuf_free_count;
86 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_TOTAL_COUNT] = nnss->pbuf_ocm_stats.pbuf_total_count;
87
88 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_ALLOC_FAILS] += nnss->pbuf_default_stats.pbuf_alloc_fails;
89 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_FREE_COUNT] = nnss->pbuf_default_stats.pbuf_free_count;
90 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_TOTAL_COUNT] = nnss->pbuf_default_stats.pbuf_total_count;
91
92 /*
93 * payload mgr stats
94 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053095 nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_ALLOC_FAILS] += nnss->payload_alloc_fails;
Thomas Wu53679842015-01-22 13:37:35 -080096 nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_FREE_COUNT] = nnss->payload_free_count;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053097
Sakthi Vignesh Radhakrishnan2a8ee962014-11-22 13:35:38 -080098 /*
99 * Host <=> NSS control traffic stats
100 */
101 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_PACKETS] += nnss->h2n_ctrl_pkts;
102 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_BYTES] += nnss->h2n_ctrl_bytes;
103 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_PACKETS] += nnss->n2h_ctrl_pkts;
104 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_BYTES] += nnss->n2h_ctrl_bytes;
105
106 /*
107 * Host <=> NSS control data traffic stats
108 */
109 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_PACKETS] += nnss->h2n_data_pkts;
110 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_BYTES] += nnss->h2n_data_bytes;
111 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_PACKETS] += nnss->n2h_data_pkts;
112 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_BYTES] += nnss->n2h_data_bytes;
113
Saurabh Misra71034db2015-06-04 16:18:38 -0700114 /*
115 * Payloads related stats
116 */
117 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_TOT_PAYLOADS] = nnss->tot_payloads;
118
Guojun Jin85dfa7b2015-09-02 15:13:56 -0700119 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_INTERFACE_INVALID] += nnss->data_interface_invalid;
120
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530121 spin_unlock_bh(&nss_top->stats_lock);
122}
123
124/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700125 * nss_n2h_interface_handler()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530126 * Handle NSS -> HLOS messages for N2H node
127 */
Vijay Dewangan634ce592015-01-07 17:21:09 -0800128static void nss_n2h_interface_handler(struct nss_ctx_instance *nss_ctx,
129 struct nss_cmn_msg *ncm,
Arunkumar Tba9b4a02016-11-07 11:41:14 +0530130 void *app_data)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530131{
132 struct nss_n2h_msg *nnm = (struct nss_n2h_msg *)ncm;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800133 nss_n2h_msg_callback_t cb;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530134
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700135 BUG_ON(ncm->interface != NSS_N2H_INTERFACE);
136
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530137 /*
138 * Is this a valid request/response packet?
139 */
140 if (nnm->cm.type >= NSS_METADATA_TYPE_N2H_MAX) {
141 nss_warning("%p: received invalid message %d for Offload stats interface", nss_ctx, nnm->cm.type);
142 return;
143 }
144
145 switch (nnm->cm.type) {
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530146 case NSS_TX_METADATA_TYPE_N2H_RPS_CFG:
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530147 nss_info("NSS N2H rps_en %d \n",nnm->msg.rps_cfg.enable);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800148 break;
149
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530150 case NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG:
151 nss_info("NSS N2H mitigation_dis %d \n",nnm->msg.mitigation_cfg.enable);
152 break;
153
Vijay Dewangan488e5372014-12-29 21:40:11 -0800154 case NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG:
155 nss_info("%p: empty pool buf cfg response from FW", nss_ctx);
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530156 break;
157
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +0530158 case NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS:
159 nss_info("%p: flush payloads cmd response from FW", nss_ctx);
160 break;
161
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530162 case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC:
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700163 nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530164 break;
165
166 default:
167 if (ncm->response != NSS_CMN_RESPONSE_ACK) {
168 /*
169 * Check response
170 */
171 nss_info("%p: Received response %d for type %d, interface %d",
172 nss_ctx, ncm->response, ncm->type, ncm->interface);
173 }
174 }
Vijay Dewangan488e5372014-12-29 21:40:11 -0800175
176 /*
Stephen Wang49b474b2016-03-25 10:40:30 -0700177 * Update the callback and app_data for NOTIFY messages, n2h sends all notify messages
Vijay Dewangan488e5372014-12-29 21:40:11 -0800178 * to the same callback/app_data.
179 */
180 if (nnm->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
181 /*
182 * Place holder for the user to create right call
183 * back and app data when response is NSS_CMM_RESPONSE_NOTIFY
184 */
Stephen Wangaed46332016-12-12 17:29:03 -0800185 ncm->cb = (nss_ptr_t)nss_n2h_rd[nss_ctx->id].n2h_callback;
186 ncm->app_data = (nss_ptr_t)nss_n2h_rd[nss_ctx->id].app_data;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800187 }
188
189 /*
190 * Do we have a callback?
191 */
192 if (!ncm->cb) {
193 return;
194 }
195
196 /*
197 * Callback
198 */
199 cb = (nss_n2h_msg_callback_t)ncm->cb;
200 cb((void *)ncm->app_data, nnm);
201}
202
203/*
Vijay Dewangan634ce592015-01-07 17:21:09 -0800204 * nss_n2h_rps_cfg_callback()
205 * call back function for rps configuration
206 */
207static void nss_n2h_rps_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
208{
209 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)app_data;
210 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
211
212 /*
213 * Error, hence we are not updating the nss_n2h_empty_pool_buf
214 * Restore the current_value to its previous state
215 */
216 nss_n2h_rcp.response = NSS_FAILURE;
217 complete(&nss_n2h_rcp.complete);
218 nss_warning("%p: RPS configuration failed : %d\n", nss_ctx,
219 nnm->cm.error);
220 return;
221 }
222
223 nss_info("%p: RPS configuration succeeded: %d\n", nss_ctx,
224 nnm->cm.error);
225 nss_ctx->n2h_rps_en = nnm->msg.rps_cfg.enable;
226 nss_n2h_rcp.response = NSS_SUCCESS;
227 complete(&nss_n2h_rcp.complete);
228}
229
230/*
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530231 * nss_n2h_mitigation_cfg_callback()
232 * call back function for mitigation configuration
233 */
234static void nss_n2h_mitigation_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
235{
Stephen Wangaed46332016-12-12 17:29:03 -0800236 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530237 struct nss_top_instance *nss_top = &nss_top_main;
238 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
239
240 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
241
242 /*
243 * Error, hence we are not updating the nss_n2h_mitigate_en
244 */
245 nss_n2h_mitigationcp[core_num].response = NSS_FAILURE;
246 complete(&nss_n2h_mitigationcp[core_num].complete);
247 nss_warning("core%d: MITIGATION configuration failed : %d\n", core_num, nnm->cm.error);
248 return;
249 }
250
251 nss_info("core%d: MITIGATION configuration succeeded: %d\n", core_num, nnm->cm.error);
252
253 nss_ctx->n2h_mitigate_en = nnm->msg.mitigation_cfg.enable;
254 nss_n2h_mitigationcp[core_num].response = NSS_SUCCESS;
255 complete(&nss_n2h_mitigationcp[core_num].complete);
256}
257
258/*
259 * nss_n2h_buf_cfg_callback()
260 * call back function for pbuf configuration
261 */
262static void nss_n2h_bufs_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
263{
Stephen Wangaed46332016-12-12 17:29:03 -0800264 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530265 unsigned int allocated_sz;
266
267 struct nss_top_instance *nss_top = &nss_top_main;
268 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
269
270 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
271 nss_n2h_bufcp[core_num].response = NSS_FAILURE;
272 nss_warning("core%d: buf configuration failed : %d\n", core_num, nnm->cm.error);
273 goto done;
274 }
275
276 nss_info("core%d: buf configuration succeeded: %d\n", core_num, nnm->cm.error);
277
278 allocated_sz = nnm->msg.buf_pool.nss_buf_page_size * nnm->msg.buf_pool.nss_buf_num_pages;
279 nss_ctx->buf_sz_allocated += allocated_sz;
280
281 nss_n2h_bufcp[core_num].response = NSS_SUCCESS;
282
283done:
284 complete(&nss_n2h_bufcp[core_num].complete);
285}
286
287/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700288 * nss_n2h_payload_stats_callback()
289 * It gets called response to payload accounting.
Vijay Dewangan488e5372014-12-29 21:40:11 -0800290 */
Saurabh Misra71034db2015-06-04 16:18:38 -0700291static void nss_n2h_payload_stats_callback(void *app_data,
292 struct nss_n2h_msg *nnm)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800293{
Stephen Wangaed46332016-12-12 17:29:03 -0800294 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Saurabh Misra71034db2015-06-04 16:18:38 -0700295
Vijay Dewangan488e5372014-12-29 21:40:11 -0800296 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
297 struct nss_n2h_empty_pool_buf *nnepbcm;
298 nnepbcm = &nnm->msg.empty_pool_buf_cfg;
299
Saurabh Misra71034db2015-06-04 16:18:38 -0700300 nss_warning("%d: core empty pool buf set failure: %d\n",
301 core_num, nnm->cm.error);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800302 nss_n2h_nepbcfgp[core_num].response = NSS_FAILURE;
303 complete(&nss_n2h_nepbcfgp[core_num].complete);
304 return;
305 }
306
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700307 if (nnm->cm.type == NSS_TX_METADATA_TYPE_GET_WATER_MARK) {
308 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size =
Saurabh Misra71034db2015-06-04 16:18:38 -0700309 ntohl(nnm->msg.payload_info.pool_size);
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700310 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water =
Saurabh Misra71034db2015-06-04 16:18:38 -0700311 ntohl(nnm->msg.payload_info.low_water);
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700312 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water =
Saurabh Misra71034db2015-06-04 16:18:38 -0700313 ntohl(nnm->msg.payload_info.high_water);
314 }
315
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700316 if (nnm->cm.type == NSS_TX_METADATA_TYPE_GET_PAGED_WATER_MARK) {
317 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size =
318 ntohl(nnm->msg.paged_payload_info.pool_size);
319 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water =
320 ntohl(nnm->msg.paged_payload_info.low_water);
321 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water =
322 ntohl(nnm->msg.paged_payload_info.high_water);
323 }
324
Vijay Dewangan488e5372014-12-29 21:40:11 -0800325 nss_n2h_nepbcfgp[core_num].response = NSS_SUCCESS;
326 complete(&nss_n2h_nepbcfgp[core_num].complete);
327}
328
329/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530330 * nss_n2h_set_wifi_payloads_callback()
331 * call back function for response to wifi pool configuration
332 *
333 */
334static void nss_n2h_set_wifi_payloads_callback(void *app_data,
335 struct nss_n2h_msg *nnm)
336{
Arunkumar Tba9b4a02016-11-07 11:41:14 +0530337 struct nss_ctx_instance *nss_ctx __maybe_unused = (struct nss_ctx_instance *)app_data;
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530338 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
339
340 nss_n2h_wp.response = NSS_FAILURE;
341 complete(&nss_n2h_wp.complete);
342 nss_warning("%p: wifi pool configuration failed : %d\n", nss_ctx,
343 nnm->cm.error);
344 return;
345 }
346
347 nss_info("%p: wifi payload configuration succeeded: %d\n", nss_ctx,
348 nnm->cm.error);
349 nss_n2h_wp.response = NSS_SUCCESS;
350 complete(&nss_n2h_wp.complete);
351}
352
353/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700354 * nss_n2h_get_payload_info()
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700355 * Gets Payload information.
Vijay Dewangan488e5372014-12-29 21:40:11 -0800356 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700357static 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 -0700358{
359 struct nss_top_instance *nss_top = &nss_top_main;
360 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
Saurabh Misra71034db2015-06-04 16:18:38 -0700361 nss_tx_status_t nss_tx_status;
362 int ret = NSS_FAILURE;
363
364 /*
365 * Note that semaphore should be already held.
366 */
367
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700368 nss_tx_status = nss_n2h_tx_msg(nss_ctx, nnm);
Saurabh Misra71034db2015-06-04 16:18:38 -0700369
370 if (nss_tx_status != NSS_TX_SUCCESS) {
Stephen Wangaed46332016-12-12 17:29:03 -0800371 nss_warning("%p: core %d nss_tx error errorn", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700372 return NSS_FAILURE;
373 }
374
375 /*
376 * Blocking call, wait till we get ACK for this msg.
377 */
378 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
379 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
380 if (ret == 0) {
Stephen Wangaed46332016-12-12 17:29:03 -0800381 nss_warning("%p: core %d waiting for ack timed out\n", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700382 return NSS_FAILURE;
383 }
384
385 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
Stephen Wangaed46332016-12-12 17:29:03 -0800386 nss_warning("%p: core %d response returned failure\n", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700387 return NSS_FAILURE;
388 }
389
390 return NSS_SUCCESS;
391}
392
393/*
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700394 * nss_n2h_get_default_payload_info()
395 * Gets the default payload information.
396 */
397static int nss_n2h_get_default_payload_info(nss_ptr_t core_num)
398{
399 struct nss_n2h_msg nnm;
400
401 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
402 NSS_TX_METADATA_TYPE_GET_WATER_MARK,
403 sizeof(struct nss_n2h_payload_info),
404 nss_n2h_payload_stats_callback,
405 (void *)core_num);
406
407 return nss_n2h_get_payload_info(core_num, &nnm,
408 &nnm.msg.payload_info);
409}
410
411/*
412 * nss_n2h_get_paged_payload_info()
413 * Gets the paged payload information.
414 */
415static int nss_n2h_get_paged_payload_info(nss_ptr_t core_num)
416{
417 struct nss_n2h_msg nnm;
418
419 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
420 NSS_TX_METADATA_TYPE_GET_PAGED_WATER_MARK,
421 sizeof(struct nss_n2h_payload_info),
422 nss_n2h_payload_stats_callback,
423 (void *)core_num);
424
425 return nss_n2h_get_payload_info(core_num, &nnm,
426 &nnm.msg.paged_payload_info);
427}
428
429/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700430 * nss_n2h_set_empty_pool_buf()
431 * Sets empty pool buffer
432 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700433static int nss_n2h_set_empty_pool_buf(struct ctl_table *ctl, int write,
Saurabh Misra71034db2015-06-04 16:18:38 -0700434 void __user *buffer,
435 size_t *lenp, loff_t *ppos,
Stephen Wangaed46332016-12-12 17:29:03 -0800436 nss_ptr_t core_num, int *new_val)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800437{
438 struct nss_top_instance *nss_top = &nss_top_main;
439 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
440 struct nss_n2h_msg nnm;
441 struct nss_n2h_empty_pool_buf *nnepbcm;
442 nss_tx_status_t nss_tx_status;
443 int ret = NSS_FAILURE;
444
445 /*
446 * Acquiring semaphore
447 */
448 down(&nss_n2h_nepbcfgp[core_num].sem);
449
450 /*
451 * Take snap shot of current value
452 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700453 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size = *new_val;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800454
Saurabh Misra71034db2015-06-04 16:18:38 -0700455 if (!write) {
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700456 ret = nss_n2h_get_default_payload_info(core_num);
457 *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size;
Saurabh Misra71034db2015-06-04 16:18:38 -0700458 if (ret == NSS_FAILURE) {
459 up(&nss_n2h_nepbcfgp[core_num].sem);
460 return -EBUSY;
461 }
462
463 up(&nss_n2h_nepbcfgp[core_num].sem);
464
465 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
466 return ret;
467 }
468
Vijay Dewangan488e5372014-12-29 21:40:11 -0800469 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
Saurabh Misra71034db2015-06-04 16:18:38 -0700470 if (ret) {
Vijay Dewangan488e5372014-12-29 21:40:11 -0800471 up(&nss_n2h_nepbcfgp[core_num].sem);
472 return ret;
473 }
474
Vijay Dewangan488e5372014-12-29 21:40:11 -0800475 if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700476 nss_warning("%p: core %d setting %d < min number of buffer",
Stephen Wangaed46332016-12-12 17:29:03 -0800477 nss_ctx, (int)core_num, *new_val);
Stephen Wang06761022015-03-03 16:38:42 -0800478 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800479 }
480
481 nss_info("%p: core %d number of empty pool buffer is : %d\n",
Stephen Wangaed46332016-12-12 17:29:03 -0800482 nss_ctx, (int)core_num, *new_val);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800483
484 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
485 NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG,
486 sizeof(struct nss_n2h_empty_pool_buf),
Saurabh Misra71034db2015-06-04 16:18:38 -0700487 nss_n2h_payload_stats_callback,
Stephen Wangaed46332016-12-12 17:29:03 -0800488 (nss_ptr_t *)core_num);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800489
490 nnepbcm = &nnm.msg.empty_pool_buf_cfg;
491 nnepbcm->pool_size = htonl(*new_val);
492 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
493
494 if (nss_tx_status != NSS_TX_SUCCESS) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700495 nss_warning("%p: core %d nss_tx error empty pool buffer: %d\n",
Stephen Wangaed46332016-12-12 17:29:03 -0800496 nss_ctx, (int)core_num, *new_val);
Stephen Wang06761022015-03-03 16:38:42 -0800497 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800498 }
499
500 /*
501 * Blocking call, wait till we get ACK for this msg.
502 */
Saurabh Misra71034db2015-06-04 16:18:38 -0700503 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
504 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
Vijay Dewangan488e5372014-12-29 21:40:11 -0800505 if (ret == 0) {
Stephen Wangaed46332016-12-12 17:29:03 -0800506 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, (int)core_num);
Stephen Wang06761022015-03-03 16:38:42 -0800507 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800508 }
509
510 /*
511 * ACK/NACK received from NSS FW
512 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
513 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
514 */
515 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
Stephen Wang06761022015-03-03 16:38:42 -0800516 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800517 }
518
519 up(&nss_n2h_nepbcfgp[core_num].sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700520 return 0;
Stephen Wang06761022015-03-03 16:38:42 -0800521
522failure:
523 /*
524 * Restore the current_value to its previous state
525 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700526 *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size;
527 up(&nss_n2h_nepbcfgp[core_num].sem);
528 return NSS_FAILURE;
529}
530
531/*
532 * nss_n2h_set_empty_paged_pool_buf()
533 * Sets empty paged pool buffer
534 */
535static int nss_n2h_set_empty_paged_pool_buf(struct ctl_table *ctl, int write,
536 void __user *buffer,
537 size_t *lenp, loff_t *ppos,
538 nss_ptr_t core_num, int *new_val)
539{
540 struct nss_top_instance *nss_top = &nss_top_main;
541 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
542 struct nss_n2h_msg nnm;
543 struct nss_n2h_empty_pool_buf *nneppbcm;
544 nss_tx_status_t nss_tx_status;
545 int ret = NSS_FAILURE;
546
547 /*
548 * Acquiring semaphore
549 */
550 down(&nss_n2h_nepbcfgp[core_num].sem);
551
552 /*
553 * Take snap shot of current value
554 */
555 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size = *new_val;
556
557 if (!write) {
558 ret = nss_n2h_get_paged_payload_info(core_num);
559 *new_val = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size;
560 if (ret == NSS_FAILURE) {
561 up(&nss_n2h_nepbcfgp[core_num].sem);
562 return -EBUSY;
563 }
564
565 up(&nss_n2h_nepbcfgp[core_num].sem);
566
567 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
568 return ret;
569 }
570
571 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
572 if (ret) {
573 up(&nss_n2h_nepbcfgp[core_num].sem);
574 return ret;
575 }
576
577 if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
578 nss_warning("%p: core %d setting %d < min number of buffer",
579 nss_ctx, (int)core_num, *new_val);
580 goto failure;
581 }
582
583 nss_info("%p: core %d number of empty paged pool buffer is : %d\n",
584 nss_ctx, (int)core_num, *new_val);
585
586 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
587 NSS_TX_METADATA_TYPE_N2H_EMPTY_PAGED_POOL_BUF_CFG,
588 sizeof(struct nss_n2h_empty_pool_buf),
589 nss_n2h_payload_stats_callback,
590 (nss_ptr_t *)core_num);
591
592 nneppbcm = &nnm.msg.empty_pool_buf_cfg;
593 nneppbcm->pool_size = htonl(*new_val);
594 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
595
596 if (nss_tx_status != NSS_TX_SUCCESS) {
597 nss_warning("%p: core %d nss_tx error empty paged pool buffer: %d\n",
598 nss_ctx, (int)core_num, *new_val);
599 goto failure;
600 }
601
602 /*
603 * Blocking call, wait till we get ACK for this msg.
604 */
605 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
606 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
607 if (ret == 0) {
608 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, (int)core_num);
609 goto failure;
610 }
611
612 /*
613 * ACK/NACK received from NSS FW
614 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
615 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
616 */
617 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
618 goto failure;
619 }
620
621 up(&nss_n2h_nepbcfgp[core_num].sem);
622 return 0;
623
624failure:
625 /*
626 * Restore the current_value to its previous state
627 */
628 *new_val = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size;
Saurabh Misra71034db2015-06-04 16:18:38 -0700629 up(&nss_n2h_nepbcfgp[core_num].sem);
630 return NSS_FAILURE;
631}
632
633/*
634 * nss_n2h_set_water_mark()
635 * Sets water mark for N2H SOS
636 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700637static int nss_n2h_set_water_mark(struct ctl_table *ctl, int write,
Saurabh Misra71034db2015-06-04 16:18:38 -0700638 void __user *buffer,
639 size_t *lenp, loff_t *ppos,
Stephen Wangaed46332016-12-12 17:29:03 -0800640 uint32_t core_num, int *low, int *high)
Saurabh Misra71034db2015-06-04 16:18:38 -0700641{
642 struct nss_top_instance *nss_top = &nss_top_main;
643 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
644 struct nss_n2h_msg nnm;
645 struct nss_n2h_water_mark *wm;
646 nss_tx_status_t nss_tx_status;
647 int ret = NSS_FAILURE;
648
649 /*
650 * Acquiring semaphore
651 */
652 down(&nss_n2h_nepbcfgp[core_num].sem);
653
654 /*
655 * Take snap shot of current value
656 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700657 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water = *low;
658 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water = *high;
Saurabh Misra71034db2015-06-04 16:18:38 -0700659
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700660 if (!write || *low == -1 || *high == -1) {
661 ret = nss_n2h_get_default_payload_info(core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700662 if (ret == NSS_FAILURE) {
663 up(&nss_n2h_nepbcfgp[core_num].sem);
664 return -EBUSY;
665 }
666
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700667 *low = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water;
668 *high = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water;
Saurabh Misra71034db2015-06-04 16:18:38 -0700669 }
670
671 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700672 if (!write || ret) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700673 up(&nss_n2h_nepbcfgp[core_num].sem);
674 return ret;
675 }
676
Saurabh Misra71034db2015-06-04 16:18:38 -0700677 if ((*low < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) ||
678 (*high < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
679 nss_warning("%p: core %d setting %d, %d < min number of buffer",
680 nss_ctx, core_num, *low, *high);
681 goto failure;
682 }
683
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530684 if ((*low > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) ||
685 (*high > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700686 nss_warning("%p: core %d setting %d, %d is > upper limit",
687 nss_ctx, core_num, *low, *high);
688 goto failure;
689 }
690
691 if (*low > *high) {
692 nss_warning("%p: core %d setting low %d is more than high %d",
693 nss_ctx, core_num, *low, *high);
694 goto failure;
695 }
696
697 nss_info("%p: core %d number of low : %d and high : %d\n",
698 nss_ctx, core_num, *low, *high);
699
700 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
701 NSS_TX_METADATA_TYPE_SET_WATER_MARK,
702 sizeof(struct nss_n2h_water_mark),
703 nss_n2h_payload_stats_callback,
Stephen Wangaed46332016-12-12 17:29:03 -0800704 (void *)(nss_ptr_t)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700705
706 wm = &nnm.msg.wm;
707 wm->low_water = htonl(*low);
708 wm->high_water = htonl(*high);
709 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
710
711 if (nss_tx_status != NSS_TX_SUCCESS) {
712 nss_warning("%p: core %d nss_tx error setting : %d, %d\n",
713 nss_ctx, core_num, *low, *high);
714 goto failure;
715 }
716
717 /*
718 * Blocking call, wait till we get ACK for this msg.
719 */
720 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
721 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
722 if (ret == 0) {
723 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx,
724 core_num);
725 goto failure;
726 }
727
728 /*
729 * ACK/NACK received from NSS FW
730 */
731 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response)
732 goto failure;
733
734 up(&nss_n2h_nepbcfgp[core_num].sem);
735 return NSS_SUCCESS;
736
737failure:
738 /*
739 * Restore the current_value to its previous state
740 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700741 *low = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water;
742 *high = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water;
743 up(&nss_n2h_nepbcfgp[core_num].sem);
744 return -EINVAL;
745}
746
747/*
748 * nss_n2h_set_paged_water_mark()
749 * Sets water mark for paged pool N2H SOS
750 */
751static int nss_n2h_set_paged_water_mark(struct ctl_table *ctl, int write,
752 void __user *buffer,
753 size_t *lenp, loff_t *ppos,
754 uint32_t core_num, int *low, int *high)
755{
756 struct nss_top_instance *nss_top = &nss_top_main;
757 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
758 struct nss_n2h_msg nnm;
759 struct nss_n2h_water_mark *pwm;
760 nss_tx_status_t nss_tx_status;
761 int ret = NSS_FAILURE;
762
763 /*
764 * Acquiring semaphore
765 */
766 down(&nss_n2h_nepbcfgp[core_num].sem);
767
768 /*
769 * Take snap shot of current value
770 */
771 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water = *low;
772 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water = *high;
773
774 if (!write || *low == -1 || *high == -1) {
775 ret = nss_n2h_get_paged_payload_info(core_num);
776 if (ret == NSS_FAILURE) {
777 up(&nss_n2h_nepbcfgp[core_num].sem);
778 return -EBUSY;
779 }
780
781 *low = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water;
782 *high = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water;
783 }
784
785 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
786 if (!write || ret) {
787 up(&nss_n2h_nepbcfgp[core_num].sem);
788 return ret;
789 }
790
791 if ((*low < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) ||
792 (*high < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
793 nss_warning("%p: core %d setting %d, %d < min number of buffer",
794 nss_ctx, core_num, *low, *high);
795 goto failure;
796 }
797
798 if ((*low > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) ||
799 (*high > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
800 nss_warning("%p: core %d setting %d, %d is > upper limit",
801 nss_ctx, core_num, *low, *high);
802 goto failure;
803 }
804
805 if (*low > *high) {
806 nss_warning("%p: core %d setting low %d is more than high %d",
807 nss_ctx, core_num, *low, *high);
808 goto failure;
809 }
810
811 nss_info("%p: core %d number of low : %d and high : %d\n",
812 nss_ctx, core_num, *low, *high);
813
814 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
815 NSS_TX_METADATA_TYPE_SET_PAGED_WATER_MARK,
816 sizeof(struct nss_n2h_water_mark),
817 nss_n2h_payload_stats_callback,
818 (void *)(nss_ptr_t)core_num);
819
820 pwm = &nnm.msg.wm_paged;
821 pwm->low_water = htonl(*low);
822 pwm->high_water = htonl(*high);
823 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
824
825 if (nss_tx_status != NSS_TX_SUCCESS) {
826 nss_warning("%p: core %d nss_tx error setting : %d, %d\n",
827 nss_ctx, core_num, *low, *high);
828 goto failure;
829 }
830
831 /*
832 * Blocking call, wait till we get ACK for this msg.
833 */
834 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
835 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
836 if (ret == 0) {
837 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx,
838 core_num);
839 goto failure;
840 }
841
842 /*
843 * ACK/NACK received from NSS FW
844 */
845 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response)
846 goto failure;
847
848 up(&nss_n2h_nepbcfgp[core_num].sem);
849 return NSS_SUCCESS;
850
851failure:
852 /*
853 * Restore the current_value to its previous state
854 */
855 *low = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water;
856 *high = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water;
Stephen Wang06761022015-03-03 16:38:42 -0800857 up(&nss_n2h_nepbcfgp[core_num].sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700858 return -EINVAL;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800859}
860
861/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530862 * nss_n2h_cfg_wifi_pool()
863 * Sets number of wifi payloads to adjust high water mark for N2H SoS
864 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700865static int nss_n2h_cfg_wifi_pool(struct ctl_table *ctl, int write,
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530866 void __user *buffer,
867 size_t *lenp, loff_t *ppos,
868 int *payloads)
869{
870 struct nss_top_instance *nss_top = &nss_top_main;
871 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
872 struct nss_n2h_msg nnm;
873 struct nss_n2h_wifi_payloads *wp;
874 nss_tx_status_t nss_tx_status;
875 int ret = NSS_FAILURE;
876
877 /*
878 * Acquiring semaphore
879 */
880 down(&nss_n2h_wp.sem);
881
882 if (!write) {
883 *payloads = nss_n2h_wp.wifi_pool;
884
885 up(&nss_n2h_wp.sem);
886 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
887 return ret;
888 }
889
890 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
891 if (ret) {
892 up(&nss_n2h_wp.sem);
893 return ret;
894 }
895
896 /*
897 * If payloads parameter is not set, we do
898 * nothing.
899 */
900 if (*payloads == -1)
901 goto failure;
902
903 if ((*payloads < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
904 nss_warning("%p: wifi setting %d < min number of buffer",
905 nss_ctx, *payloads);
906 goto failure;
907 }
908
909 if ((*payloads > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
910 nss_warning("%p: wifi setting %d > max number of buffer",
911 nss_ctx, *payloads);
912 goto failure;
913 }
914
915 nss_info("%p: wifi payloads : %d\n",
916 nss_ctx, *payloads);
917
918 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
919 NSS_TX_METADATA_TYPE_N2H_WIFI_POOL_BUF_CFG,
920 sizeof(struct nss_n2h_wifi_payloads),
921 nss_n2h_set_wifi_payloads_callback,
922 (void *)nss_ctx);
923
924 wp = &nnm.msg.wp;
925 wp->payloads = htonl(*payloads);
926 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
927
928 if (nss_tx_status != NSS_TX_SUCCESS) {
929 nss_warning("%p: wifi setting %d nss_tx error",
930 nss_ctx, *payloads);
931 goto failure;
932 }
933
934 /*
935 * Blocking call, wait till we get ACK for this msg.
936 */
937 ret = wait_for_completion_timeout(&nss_n2h_wp.complete,
938 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
939 if (ret == 0) {
940 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
941 goto failure;
942 }
943
944 /*
945 * ACK/NACK received from NSS FW
946 */
947 if (NSS_FAILURE == nss_n2h_wp.response)
948 goto failure;
949
950 up(&nss_n2h_wp.sem);
951 return NSS_SUCCESS;
952
953failure:
954 up(&nss_n2h_wp.sem);
955 return -EINVAL;
956}
957
958/*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800959 * nss_n2h_empty_pool_buf_core1_handler()
960 * Sets the number of empty buffer for core 1
961 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700962static int nss_n2h_empty_pool_buf_cfg_core1_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700963 int write, void __user *buffer,
964 size_t *lenp, loff_t *ppos)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800965{
966 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
Saurabh Misra71034db2015-06-04 16:18:38 -0700967 NSS_CORE_1, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800968}
969
970/*
971 * nss_n2h_empty_pool_buf_core0_handler()
972 * Sets the number of empty buffer for core 0
973 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700974static int nss_n2h_empty_pool_buf_cfg_core0_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700975 int write, void __user *buffer,
976 size_t *lenp, loff_t *ppos)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800977{
978 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
Saurabh Misra71034db2015-06-04 16:18:38 -0700979 NSS_CORE_0, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]);
980}
981
982/*
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700983 * nss_n2h_empty_paged_pool_buf_cfg_core1_handler()
984 * Sets the number of empty paged buffer for core 1
985 */
986static int nss_n2h_empty_paged_pool_buf_cfg_core1_handler(struct ctl_table *ctl,
987 int write, void __user *buffer,
988 size_t *lenp, loff_t *ppos)
989{
990 return nss_n2h_set_empty_paged_pool_buf(ctl, write, buffer, lenp, ppos,
991 NSS_CORE_1, &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1]);
992}
993
994/*
995 * nss_n2h_empty_paged_pool_buf_cfg_core0_handler()
996 * Sets the number of empty paged buffer for core 0
997 */
998static int nss_n2h_empty_paged_pool_buf_cfg_core0_handler(struct ctl_table *ctl,
999 int write, void __user *buffer,
1000 size_t *lenp, loff_t *ppos)
1001{
1002 return nss_n2h_set_empty_paged_pool_buf(ctl, write, buffer, lenp, ppos,
1003 NSS_CORE_0, &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0]);
1004}
1005
1006/*
Saurabh Misra71034db2015-06-04 16:18:38 -07001007 * nss_n2h_water_mark_core1_handler()
1008 * Sets water mark for core 1
1009 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001010static int nss_n2h_water_mark_core1_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -07001011 int write, void __user *buffer,
1012 size_t *lenp, loff_t *ppos)
1013{
1014 return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos,
1015 NSS_CORE_1, &nss_n2h_water_mark[NSS_CORE_1][0],
1016 &nss_n2h_water_mark[NSS_CORE_1][1]);
1017}
1018
1019/*
1020 * nss_n2h_water_mark_core0_handler()
1021 * Sets water mark for core 0
1022 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001023static int nss_n2h_water_mark_core0_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -07001024 int write, void __user *buffer,
1025 size_t *lenp, loff_t *ppos)
1026{
1027 return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos,
1028 NSS_CORE_0, &nss_n2h_water_mark[NSS_CORE_0][0],
1029 &nss_n2h_water_mark[NSS_CORE_0][1]);
Vijay Dewangan488e5372014-12-29 21:40:11 -08001030}
1031
Vijay Dewangan634ce592015-01-07 17:21:09 -08001032/*
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001033 * nss_n2h_paged_water_mark_core1_handler()
1034 * Sets paged water mark for core 1
1035 */
1036static int nss_n2h_paged_water_mark_core1_handler(struct ctl_table *ctl,
1037 int write, void __user *buffer,
1038 size_t *lenp, loff_t *ppos)
1039{
1040 return nss_n2h_set_paged_water_mark(ctl, write, buffer, lenp, ppos,
1041 NSS_CORE_1, &nss_n2h_paged_water_mark[NSS_CORE_1][0],
1042 &nss_n2h_paged_water_mark[NSS_CORE_1][1]);
1043}
1044
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001045/*
1046 * nss_n2h_paged_water_mark_core0_handler()
1047 * Sets paged water mark for core 0
1048 */
1049static int nss_n2h_paged_water_mark_core0_handler(struct ctl_table *ctl,
1050 int write, void __user *buffer,
1051 size_t *lenp, loff_t *ppos)
1052{
1053 return nss_n2h_set_paged_water_mark(ctl, write, buffer, lenp, ppos,
1054 NSS_CORE_0, &nss_n2h_paged_water_mark[NSS_CORE_0][0],
1055 &nss_n2h_paged_water_mark[NSS_CORE_0][1]);
1056}
1057
1058/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301059 * nss_n2h_wifi_payloads_handler()
1060 * Sets number of wifi payloads
1061 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001062static int nss_n2h_wifi_payloads_handler(struct ctl_table *ctl,
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301063 int write, void __user *buffer,
1064 size_t *lenp, loff_t *ppos)
1065{
1066 return nss_n2h_cfg_wifi_pool(ctl, write, buffer, lenp, ppos,
1067 &nss_n2h_wifi_pool_buf_cfg);
1068}
1069
1070/*
ratheesh kannothab436af2017-07-20 08:51:07 +05301071 * nss_n2h_update_queue_config_callback()
1072 * Callback to handle the completion of queue config command
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301073 */
ratheesh kannothab436af2017-07-20 08:51:07 +05301074static void nss_n2h_update_queue_config_callback(void *app_data, struct nss_n2h_msg *nim)
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301075{
ratheesh kannothab436af2017-07-20 08:51:07 +05301076 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
1077 nss_warning("n2h Error response %d\n", nim->cm.response);
1078 nss_n2h_q_cfg_pvt.response = NSS_TX_FAILURE;
1079 } else {
1080 nss_n2h_q_cfg_pvt.response = NSS_TX_SUCCESS;
1081 }
1082
1083 complete(&nss_n2h_q_cfg_pvt.complete);
1084}
1085
1086/*
1087 * nss_n2h_update_queue_config_async()
1088 * Asynchronous call to send pnode queue configuration.
1089 */
1090nss_tx_status_t nss_n2h_update_queue_config_async(struct nss_ctx_instance *nss_ctx, bool mq_en, uint16_t *qlimits)
1091{
1092
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301093 struct nss_n2h_msg nnm;
1094 struct nss_n2h_pnode_queue_config *cfg;
1095 nss_tx_status_t status;
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301096 int i;
1097
1098 if (!mq_en) {
1099 return NSS_TX_SUCCESS;
1100 }
1101
ratheesh kannothab436af2017-07-20 08:51:07 +05301102 memset(&nnm, 0, sizeof(struct nss_n2h_msg));
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301103
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301104 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1105 NSS_TX_METADATA_TYPE_N2H_SET_PNODE_QUEUE_CFG,
1106 sizeof(struct nss_n2h_pnode_queue_config), NULL, 0);
1107
ratheesh kannothab436af2017-07-20 08:51:07 +05301108 cfg = &nnm.msg.pn_q_cfg;
1109
1110 /*
1111 * Update limits
1112 */
1113 for (i = 0; i < NSS_MAX_NUM_PRI; i++) {
1114 cfg->qlimits[i] = qlimits[i];
1115 }
1116 cfg->mq_en = true;
1117
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301118 status = nss_n2h_tx_msg(nss_ctx, &nnm);
1119 if (status != NSS_TX_SUCCESS) {
1120 nss_warning("%p: nss_tx error to send pnode queue config\n", nss_ctx);
1121 return status;
1122 }
1123
1124 return NSS_TX_SUCCESS;
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301125}
ratheesh kannothab436af2017-07-20 08:51:07 +05301126EXPORT_SYMBOL(nss_n2h_update_queue_config_async);
1127
1128/*
1129 * nss_n2h_update_queue_config_sync()
1130 * Synchronous call to send pnode queue configuration.
1131 */
1132nss_tx_status_t nss_n2h_update_queue_config_sync(struct nss_ctx_instance *nss_ctx, bool mq_en, uint16_t *qlimits)
1133{
1134
1135 struct nss_n2h_msg nnm;
1136 struct nss_n2h_pnode_queue_config *cfg;
1137 nss_tx_status_t status;
1138 int ret, i;
1139
1140 if (!mq_en) {
1141 return NSS_TX_SUCCESS;
1142 }
1143
1144 memset(&nnm, 0, sizeof(struct nss_n2h_msg));
1145
1146 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1147 NSS_TX_METADATA_TYPE_N2H_SET_PNODE_QUEUE_CFG,
1148 sizeof(struct nss_n2h_pnode_queue_config), nss_n2h_update_queue_config_callback, 0);
1149
1150 cfg = &nnm.msg.pn_q_cfg;
1151
1152 /*
1153 * Update limits
1154 */
1155 for (i = 0; i < NSS_MAX_NUM_PRI; i++) {
1156 cfg->qlimits[i] = qlimits[i];
1157 }
1158 cfg->mq_en = true;
1159
1160 down(&nss_n2h_q_cfg_pvt.sem);
1161
1162 status = nss_n2h_tx_msg(nss_ctx, &nnm);
1163
1164 if (status != NSS_TX_SUCCESS) {
1165 nss_warning("%p: n2h_tx_msg failed\n", nss_ctx);
1166 up(&nss_n2h_q_cfg_pvt.sem);
1167 return status;
1168 }
1169 ret = wait_for_completion_timeout(&nss_n2h_q_cfg_pvt.complete, msecs_to_jiffies(NSS_N2H_TX_TIMEOUT));
1170
1171 if (!ret) {
1172 nss_warning("%p: Timeout expired for pnode queue config sync message\n", nss_ctx);
1173 nss_n2h_q_cfg_pvt.response = NSS_TX_FAILURE;
1174 }
1175
1176 status = nss_n2h_q_cfg_pvt.response;
1177 up(&nss_n2h_q_cfg_pvt.sem);
1178 return status;
1179}
1180EXPORT_SYMBOL(nss_n2h_update_queue_config_sync);
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301181
1182/*
Vijay Dewangan634ce592015-01-07 17:21:09 -08001183 * nss_n2h_rps_cfg()
1184 * Send Message to NSS to enable RPS.
1185 */
Stephen Wang49b474b2016-03-25 10:40:30 -07001186static nss_tx_status_t nss_n2h_rps_cfg(struct nss_ctx_instance *nss_ctx, int enable_rps)
Vijay Dewangan634ce592015-01-07 17:21:09 -08001187{
1188 struct nss_n2h_msg nnm;
1189 struct nss_n2h_rps *rps_cfg;
1190 nss_tx_status_t nss_tx_status;
1191 int ret;
1192
1193 down(&nss_n2h_rcp.sem);
1194 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_RPS_CFG,
1195 sizeof(struct nss_n2h_rps),
1196 nss_n2h_rps_cfg_callback,
1197 (void *)nss_ctx);
1198
1199 rps_cfg = &nnm.msg.rps_cfg;
1200 rps_cfg->enable = enable_rps;
1201
1202 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1203
1204 if (nss_tx_status != NSS_TX_SUCCESS) {
1205 nss_warning("%p: nss_tx error setting rps\n", nss_ctx);
1206
1207 up(&nss_n2h_rcp.sem);
1208 return NSS_FAILURE;
1209 }
1210
1211 /*
1212 * Blocking call, wait till we get ACK for this msg.
1213 */
1214 ret = wait_for_completion_timeout(&nss_n2h_rcp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
1215 if (ret == 0) {
1216 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
1217 up(&nss_n2h_rcp.sem);
1218 return NSS_FAILURE;
1219 }
1220
1221 /*
1222 * ACK/NACK received from NSS FW
1223 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
1224 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
1225 */
1226 if (NSS_FAILURE == nss_n2h_rcp.response) {
1227 up(&nss_n2h_rcp.sem);
1228 return NSS_FAILURE;
1229 }
1230
1231 up(&nss_n2h_rcp.sem);
1232 return NSS_SUCCESS;
1233}
1234
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301235/*
1236 * nss_n2h_mitigation_cfg()
1237 * Send Message to NSS to disable MITIGATION.
1238 */
Stephen Wang49b474b2016-03-25 10:40:30 -07001239static 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 +05301240{
1241 struct nss_n2h_msg nnm;
1242 struct nss_n2h_mitigation *mitigation_cfg;
1243 nss_tx_status_t nss_tx_status;
1244 int ret;
1245
1246 nss_assert(core_num < NSS_CORE_MAX);
1247
1248 down(&nss_n2h_mitigationcp[core_num].sem);
1249 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG,
1250 sizeof(struct nss_n2h_mitigation),
1251 nss_n2h_mitigation_cfg_callback,
1252 (void *)core_num);
1253
1254 mitigation_cfg = &nnm.msg.mitigation_cfg;
1255 mitigation_cfg->enable = enable_mitigation;
1256
1257 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1258
1259 if (nss_tx_status != NSS_TX_SUCCESS) {
1260 nss_warning("%p: nss_tx error setting mitigation\n", nss_ctx);
1261 goto failure;
1262 }
1263
1264 /*
1265 * Blocking call, wait till we get ACK for this msg.
1266 */
1267 ret = wait_for_completion_timeout(&nss_n2h_mitigationcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
1268 if (ret == 0) {
1269 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
1270 goto failure;
1271 }
1272
1273 /*
1274 * ACK/NACK received from NSS FW
1275 */
1276 if (NSS_FAILURE == nss_n2h_mitigationcp[core_num].response) {
1277 goto failure;
1278 }
1279
1280 up(&nss_n2h_mitigationcp[core_num].sem);
1281 return NSS_SUCCESS;
1282
1283failure:
1284 up(&nss_n2h_mitigationcp[core_num].sem);
1285 return NSS_FAILURE;
1286}
1287
1288static inline void nss_n2h_buf_pool_free(struct nss_n2h_buf_pool *buf_pool)
1289{
1290 int page_count;
1291 for (page_count = 0; page_count < buf_pool->nss_buf_num_pages; page_count++) {
Stephen Wang7df68832017-08-10 16:54:35 -07001292 kfree((void *)buf_pool->nss_buf_pool_vaddr[page_count]);
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301293 }
1294}
1295
1296/*
1297 * nss_n2h_buf_cfg()
1298 * Send Message to NSS to enable pbufs.
1299 */
Stephen Wang49b474b2016-03-25 10:40:30 -07001300static nss_tx_status_t nss_n2h_buf_pool_cfg(struct nss_ctx_instance *nss_ctx,
Tallapragada4b0161b2016-07-07 21:38:34 +05301301 int buf_pool_size, nss_core_id_t core_num)
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301302{
1303 static struct nss_n2h_msg nnm;
1304 struct nss_n2h_buf_pool *buf_pool;
1305 nss_tx_status_t nss_tx_status;
1306 int ret;
1307 int page_count;
1308 int num_pages = ALIGN(buf_pool_size, PAGE_SIZE)/PAGE_SIZE;
1309
1310 nss_assert(core_num < NSS_CORE_MAX);
1311
1312 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_METADATA_TYPE_N2H_ADD_BUF_POOL,
1313 sizeof(struct nss_n2h_buf_pool),
1314 nss_n2h_bufs_cfg_callback,
1315 (void *)core_num);
1316
1317 do {
1318
1319 down(&nss_n2h_bufcp[core_num].sem);
1320
1321 buf_pool = &nnm.msg.buf_pool;
1322 buf_pool->nss_buf_page_size = PAGE_SIZE;
1323
1324 for (page_count = 0; page_count < MAX_PAGES_PER_MSG && num_pages; page_count++, num_pages--) {
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301325 void *kern_addr = kzalloc(PAGE_SIZE, GFP_ATOMIC);
1326 if (!kern_addr) {
1327 BUG_ON(!page_count);
1328 break;
1329 }
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301330
Radha krishna Simha Jiguru60068fb2017-07-28 17:40:52 +05301331 kmemleak_not_leak(kern_addr);
Stephen Wang7df68832017-08-10 16:54:35 -07001332 buf_pool->nss_buf_pool_vaddr[page_count] = (nss_ptr_t)kern_addr;
Stephen Wangefd38512017-01-24 14:01:02 -08001333 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 +05301334 }
1335
1336 buf_pool->nss_buf_num_pages = page_count;
1337 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1338 if (nss_tx_status != NSS_TX_SUCCESS) {
1339
1340 nss_n2h_buf_pool_free(buf_pool);
1341 nss_warning("%p: nss_tx error setting pbuf\n", nss_ctx);
1342 goto failure;
1343 }
1344
1345 /*
1346 * Blocking call, wait till we get ACK for this msg.
1347 */
1348 ret = wait_for_completion_timeout(&nss_n2h_bufcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
1349 if (ret == 0) {
1350 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
1351 goto failure;
1352 }
1353
1354 /*
1355 * ACK/NACK received from NSS FW
1356 */
1357 if (NSS_FAILURE == nss_n2h_bufcp[core_num].response) {
1358
1359 nss_n2h_buf_pool_free(buf_pool);
1360 goto failure;
1361 }
1362
1363 up(&nss_n2h_bufcp[core_num].sem);
1364 } while(num_pages);
1365
1366 return NSS_SUCCESS;
1367failure:
1368 up(&nss_n2h_bufcp[core_num].sem);
1369 return NSS_FAILURE;
1370}
1371
Stephen Wang49b474b2016-03-25 10:40:30 -07001372/*
1373 * nss_rps_handler()
1374 * Enable NSS RPS
1375 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001376static 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 -07001377{
1378 struct nss_top_instance *nss_top = &nss_top_main;
1379 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
1380 int ret;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301381
Stephen Wang49b474b2016-03-25 10:40:30 -07001382 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1383 if (!ret) {
1384 if ((write) && (nss_n2h_rps_config == 1)) {
1385 printk(KERN_INFO "Enabling NSS RPS\n");
1386
1387 return nss_n2h_rps_cfg(nss_ctx, 1);
1388 }
1389
1390 if ((write) && (nss_n2h_rps_config == 0)) {
1391 printk(KERN_INFO "Runtime disabling of NSS RPS not supported\n");
1392 return ret;
1393 }
1394
1395 if (write) {
1396 printk(KERN_INFO "Invalid input value.Valid values are 0 and 1\n");
1397 }
1398
1399 }
1400
1401 return ret;
1402}
1403
1404/*
1405 * nss_mitigation_handler()
1406 * Enable NSS MITIGATION
1407 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001408static 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 -07001409{
1410 struct nss_top_instance *nss_top = &nss_top_main;
1411 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0];
1412 int ret;
1413
1414 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1415 if (ret) {
1416 return ret;
1417 }
1418
1419 /*
1420 * It's a read operation
1421 */
1422 if (!write) {
1423 return ret;
1424 }
1425
1426 if (!nss_n2h_core0_mitigation_cfg) {
1427 printk(KERN_INFO "Disabling NSS MITIGATION\n");
1428 nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_0);
1429 return 0;
1430 }
1431 printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n");
1432 return -EINVAL;
1433}
1434
1435/*
1436 * nss_mitigation_handler()
1437 * Enable NSS MITIGATION
1438 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001439static 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 -07001440{
1441 struct nss_top_instance *nss_top = &nss_top_main;
1442 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1];
1443 int ret;
1444
1445 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1446 if (ret) {
1447 return ret;
1448 }
1449
1450 /*
1451 * It's a read operation
1452 */
1453 if (!write) {
1454 return ret;
1455 }
1456
1457 if (!nss_n2h_core1_mitigation_cfg) {
1458 printk(KERN_INFO "Disabling NSS MITIGATION\n");
1459 nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_1);
1460 return 0;
1461 }
1462 printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n");
1463 return -EINVAL;
1464}
1465
1466/*
1467 * nss_buf_handler()
1468 * Add extra NSS bufs from host memory
1469 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001470static 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 -07001471{
1472 struct nss_top_instance *nss_top = &nss_top_main;
1473 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0];
1474 int ret;
1475
1476 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1477 if (ret) {
1478 return ret;
1479 }
1480
1481 /*
1482 * It's a read operation
1483 */
1484 if (!write) {
1485 return ret;
1486 }
1487
1488 if (nss_ctx->buf_sz_allocated) {
1489 nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1490 return -EPERM;
1491 }
1492
1493 if ((nss_n2h_core0_add_buf_pool_size >= 1) && (nss_n2h_core0_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) {
1494 printk(KERN_INFO "configuring additional NSS pbufs\n");
1495 ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core0_add_buf_pool_size, NSS_CORE_0);
1496 nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1497 printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated);
1498 return ret;
1499 }
1500
1501 printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE);
1502 return -EINVAL;
1503}
1504
1505/*
1506 * nss_n2h_buf_handler()
1507 * Add extra NSS bufs from host memory
1508 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001509static 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 -07001510{
1511 struct nss_top_instance *nss_top = &nss_top_main;
1512 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1];
1513 int ret;
1514
1515 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1516 if (ret) {
1517 return ret;
1518 }
1519
1520 /*
1521 * It's a read operation
1522 */
1523 if (!write) {
1524 return ret;
1525 }
1526
1527 if (nss_ctx->buf_sz_allocated) {
1528 nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1529 return -EPERM;
1530 }
1531
1532 if ((nss_n2h_core1_add_buf_pool_size >= 1) && (nss_n2h_core1_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) {
1533 printk(KERN_INFO "configuring additional NSS pbufs\n");
1534 ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core1_add_buf_pool_size, NSS_CORE_1);
1535 nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1536 printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated);
1537 return ret;
1538 }
1539
1540 printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE);
1541 return -EINVAL;
1542}
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301543
Stephen Wang52e6d342016-03-29 15:02:33 -07001544static struct ctl_table nss_n2h_table[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001545 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001546 .procname = "n2h_empty_pool_buf_core0",
1547 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0],
1548 .maxlen = sizeof(int),
1549 .mode = 0644,
1550 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler,
Vijay Dewangan488e5372014-12-29 21:40:11 -08001551 },
1552 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001553 .procname = "n2h_empty_pool_buf_core1",
1554 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1],
1555 .maxlen = sizeof(int),
1556 .mode = 0644,
1557 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core1_handler,
1558 },
1559 {
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001560 .procname = "n2h_empty_paged_pool_buf_core0",
1561 .data = &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0],
1562 .maxlen = sizeof(int),
1563 .mode = 0644,
1564 .proc_handler = &nss_n2h_empty_paged_pool_buf_cfg_core0_handler,
1565 },
1566 {
1567 .procname = "n2h_empty_paged_pool_buf_core1",
1568 .data = &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1],
1569 .maxlen = sizeof(int),
1570 .mode = 0644,
1571 .proc_handler = &nss_n2h_empty_paged_pool_buf_cfg_core1_handler,
1572 },
1573
1574 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001575 .procname = "n2h_low_water_core0",
1576 .data = &nss_n2h_water_mark[NSS_CORE_0][0],
1577 .maxlen = sizeof(int),
1578 .mode = 0644,
1579 .proc_handler = &nss_n2h_water_mark_core0_handler,
1580 },
1581 {
1582 .procname = "n2h_low_water_core1",
1583 .data = &nss_n2h_water_mark[NSS_CORE_1][0],
1584 .maxlen = sizeof(int),
1585 .mode = 0644,
1586 .proc_handler = &nss_n2h_water_mark_core1_handler,
1587 },
1588 {
1589 .procname = "n2h_high_water_core0",
1590 .data = &nss_n2h_water_mark[NSS_CORE_0][1],
1591 .maxlen = sizeof(int),
1592 .mode = 0644,
1593 .proc_handler = &nss_n2h_water_mark_core0_handler,
1594 },
1595 {
1596 .procname = "n2h_high_water_core1",
1597 .data = &nss_n2h_water_mark[NSS_CORE_1][1],
1598 .maxlen = sizeof(int),
1599 .mode = 0644,
1600 .proc_handler = &nss_n2h_water_mark_core1_handler,
Vijay Dewangan488e5372014-12-29 21:40:11 -08001601 },
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301602 {
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001603 .procname = "n2h_paged_low_water_core0",
1604 .data = &nss_n2h_paged_water_mark[NSS_CORE_0][0],
1605 .maxlen = sizeof(int),
1606 .mode = 0644,
1607 .proc_handler = &nss_n2h_paged_water_mark_core0_handler,
1608 },
1609 {
1610 .procname = "n2h_paged_low_water_core1",
1611 .data = &nss_n2h_paged_water_mark[NSS_CORE_1][0],
1612 .maxlen = sizeof(int),
1613 .mode = 0644,
1614 .proc_handler = &nss_n2h_paged_water_mark_core1_handler,
1615 },
1616 {
1617 .procname = "n2h_paged_high_water_core0",
1618 .data = &nss_n2h_paged_water_mark[NSS_CORE_0][1],
1619 .maxlen = sizeof(int),
1620 .mode = 0644,
1621 .proc_handler = &nss_n2h_paged_water_mark_core0_handler,
1622 },
1623 {
1624 .procname = "n2h_paged_high_water_core1",
1625 .data = &nss_n2h_paged_water_mark[NSS_CORE_1][1],
1626 .maxlen = sizeof(int),
1627 .mode = 0644,
1628 .proc_handler = &nss_n2h_paged_water_mark_core1_handler,
1629 },
1630 {
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301631 .procname = "n2h_wifi_pool_buf",
1632 .data = &nss_n2h_wifi_pool_buf_cfg,
1633 .maxlen = sizeof(int),
1634 .mode = 0644,
1635 .proc_handler = &nss_n2h_wifi_payloads_handler,
1636 },
Stephen Wang49b474b2016-03-25 10:40:30 -07001637 {
1638 .procname = "rps",
1639 .data = &nss_n2h_rps_config,
1640 .maxlen = sizeof(int),
1641 .mode = 0644,
1642 .proc_handler = &nss_n2h_rpscfg_handler,
1643 },
1644 {
1645 .procname = "mitigation_core0",
1646 .data = &nss_n2h_core0_mitigation_cfg,
1647 .maxlen = sizeof(int),
1648 .mode = 0644,
1649 .proc_handler = &nss_n2h_mitigationcfg_core0_handler,
1650 },
1651 {
1652 .procname = "mitigation_core1",
1653 .data = &nss_n2h_core1_mitigation_cfg,
1654 .maxlen = sizeof(int),
1655 .mode = 0644,
1656 .proc_handler = &nss_n2h_mitigationcfg_core1_handler,
1657 },
1658 {
1659 .procname = "extra_pbuf_core0",
1660 .data = &nss_n2h_core0_add_buf_pool_size,
1661 .maxlen = sizeof(int),
1662 .mode = 0644,
1663 .proc_handler = &nss_n2h_buf_cfg_core0_handler,
1664 },
1665 {
1666 .procname = "extra_pbuf_core1",
1667 .data = &nss_n2h_core1_add_buf_pool_size,
1668 .maxlen = sizeof(int),
1669 .mode = 0644,
1670 .proc_handler = &nss_n2h_buf_cfg_core1_handler,
1671 },
Vijay Dewangan488e5372014-12-29 21:40:11 -08001672
1673 { }
1674};
1675
Stephen Wang52e6d342016-03-29 15:02:33 -07001676static struct ctl_table nss_n2h_dir[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001677 {
1678 .procname = "n2hcfg",
1679 .mode = 0555,
1680 .child = nss_n2h_table,
1681 },
1682 { }
1683};
1684
Stephen Wang52e6d342016-03-29 15:02:33 -07001685static struct ctl_table nss_n2h_root_dir[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001686 {
1687 .procname = "nss",
1688 .mode = 0555,
1689 .child = nss_n2h_dir,
1690 },
1691 { }
1692};
1693
Stephen Wang52e6d342016-03-29 15:02:33 -07001694static struct ctl_table nss_n2h_root[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001695 {
1696 .procname = "dev",
1697 .mode = 0555,
1698 .child = nss_n2h_root_dir,
1699 },
1700 { }
1701};
1702
1703static struct ctl_table_header *nss_n2h_header;
1704
1705/*
Stephen Wang49b474b2016-03-25 10:40:30 -07001706 * nss_n2h_flush_payloads()
1707 * Sends a command down to NSS for flushing all payloads
1708 */
1709nss_tx_status_t nss_n2h_flush_payloads(struct nss_ctx_instance *nss_ctx)
1710{
1711 struct nss_n2h_msg nnm;
1712 struct nss_n2h_flush_payloads *nnflshpl;
1713 nss_tx_status_t nss_tx_status;
1714
1715 nnflshpl = &nnm.msg.flush_payloads;
1716
1717 /*
1718 * TODO: No additional information sent in message
1719 * as of now. Need to initialize message content accordingly
1720 * if needed.
1721 */
1722 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1723 NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS,
1724 sizeof(struct nss_n2h_flush_payloads),
1725 NULL,
1726 NULL);
1727
1728 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1729 if (nss_tx_status != NSS_TX_SUCCESS) {
1730 nss_warning("%p: failed to send flush payloads command to NSS\n",
1731 nss_ctx);
1732
1733 return NSS_TX_FAILURE;
1734 }
1735
1736 return NSS_TX_SUCCESS;
1737}
1738
1739/*
Vijay Dewangan488e5372014-12-29 21:40:11 -08001740 * nss_n2h_msg_init()
Stephen Wang49b474b2016-03-25 10:40:30 -07001741 * Initialize n2h message.
Vijay Dewangan488e5372014-12-29 21:40:11 -08001742 */
1743void nss_n2h_msg_init(struct nss_n2h_msg *nim, uint16_t if_num, uint32_t type,
Vijay Dewangan634ce592015-01-07 17:21:09 -08001744 uint32_t len, nss_n2h_msg_callback_t cb, void *app_data)
Vijay Dewangan488e5372014-12-29 21:40:11 -08001745{
1746 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
1747}
1748
Vijay Dewangan488e5372014-12-29 21:40:11 -08001749/*
Vijay Dewangan488e5372014-12-29 21:40:11 -08001750 * nss_n2h_tx_msg()
1751 * Send messages to NSS n2h pacakge
1752 */
1753nss_tx_status_t nss_n2h_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_n2h_msg *nnm)
1754{
1755 struct nss_n2h_msg *nnm2;
1756 struct nss_cmn_msg *ncm = &nnm->cm;
1757 struct sk_buff *nbuf;
1758 nss_tx_status_t status;
1759
1760 NSS_VERIFY_CTX_MAGIC(nss_ctx);
1761 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
1762 return NSS_TX_FAILURE_NOT_READY;
1763 }
1764
1765 /*
1766 * Sanity check the message
1767 */
1768 if (ncm->interface != NSS_N2H_INTERFACE) {
1769 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
1770 return NSS_TX_FAILURE;
1771 }
1772
1773 if (ncm->type >= NSS_METADATA_TYPE_N2H_MAX) {
1774 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
1775 return NSS_TX_FAILURE;
1776 }
1777
Suruchi Agarwalef8a8702016-01-08 12:40:08 -08001778 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_n2h_msg)) {
1779 nss_warning("%p: tx request for another interface: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Vijay Dewangan488e5372014-12-29 21:40:11 -08001780 return NSS_TX_FAILURE;
1781 }
1782
Vijay Dewangan488e5372014-12-29 21:40:11 -08001783 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
1784 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -08001785 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 -08001786 return NSS_TX_FAILURE;
1787 }
1788
1789 /*
1790 * Copy the message to our skb.
1791 */
1792 nnm2 = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg));
1793 memcpy(nnm2, nnm, sizeof(struct nss_n2h_msg));
1794 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
1795 if (status != NSS_CORE_STATUS_SUCCESS) {
1796 dev_kfree_skb_any(nbuf);
1797 nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx);
1798 return NSS_TX_FAILURE;
1799 }
1800
Stephen Wang90c67de2016-04-26 15:15:59 -07001801 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Vijay Dewangan488e5372014-12-29 21:40:11 -08001802 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
1803 return NSS_TX_SUCCESS;
1804}
1805
Vijay Dewangan488e5372014-12-29 21:40:11 -08001806/*
1807 * nss_n2h_notify_register()
1808 * Register to received N2H events.
1809 *
1810 * NOTE: Do we want to pass an nss_ctx here so that we can register for n2h on any core?
1811 */
1812struct nss_ctx_instance *nss_n2h_notify_register(int core, nss_n2h_msg_callback_t cb, void *app_data)
1813{
1814 if (core >= NSS_MAX_CORES) {
1815 nss_warning("Input core number %d is wrong \n", core);
1816 return NULL;
1817 }
1818 /*
1819 * TODO: We need to have a new array in support of the new API
1820 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
1821 */
1822 nss_n2h_rd[core].n2h_callback = cb;
1823 nss_n2h_rd[core].app_data = app_data;
1824 return &nss_top_main.nss[core];
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301825}
1826
1827/*
1828 * nss_n2h_register_handler()
1829 */
Thomas Wu91f4bdf2017-06-09 12:03:02 -07001830void nss_n2h_register_handler(struct nss_ctx_instance *nss_ctx)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301831{
ratheesh kannothab436af2017-07-20 08:51:07 +05301832 sema_init(&nss_n2h_q_cfg_pvt.sem, 1);
1833 init_completion(&nss_n2h_q_cfg_pvt.complete);
1834
Thomas Wu91f4bdf2017-06-09 12:03:02 -07001835 nss_core_register_handler(nss_ctx, NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL);
Stephen Wang49b474b2016-03-25 10:40:30 -07001836}
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -07001837
Stephen Wang49b474b2016-03-25 10:40:30 -07001838/*
1839 * nss_n2h_register_sysctl()
1840 */
1841void nss_n2h_register_sysctl(void)
1842{
Vijay Dewangan634ce592015-01-07 17:21:09 -08001843 /*
1844 * RPS sema init
1845 */
1846 sema_init(&nss_n2h_rcp.sem, 1);
1847 init_completion(&nss_n2h_rcp.complete);
1848
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301849 /*
1850 * MITIGATION sema init for core0
1851 */
1852 sema_init(&nss_n2h_mitigationcp[NSS_CORE_0].sem, 1);
1853 init_completion(&nss_n2h_mitigationcp[NSS_CORE_0].complete);
1854
1855 /*
1856 * MITIGATION sema init for core1
1857 */
1858 sema_init(&nss_n2h_mitigationcp[NSS_CORE_1].sem, 1);
1859 init_completion(&nss_n2h_mitigationcp[NSS_CORE_1].complete);
1860
1861 /*
1862 * PBUF addition sema init for core0
1863 */
1864 sema_init(&nss_n2h_bufcp[NSS_CORE_0].sem, 1);
1865 init_completion(&nss_n2h_bufcp[NSS_CORE_0].complete);
1866
1867 /*
1868 * PBUF addition sema init for core1
1869 */
1870 sema_init(&nss_n2h_bufcp[NSS_CORE_1].sem, 1);
1871 init_completion(&nss_n2h_bufcp[NSS_CORE_1].complete);
Vijay Dewangan634ce592015-01-07 17:21:09 -08001872
Stephen Wang49b474b2016-03-25 10:40:30 -07001873 /*
1874 * Core0
1875 */
1876 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1);
1877 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete);
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001878 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.pool_size =
Stephen Wang49b474b2016-03-25 10:40:30 -07001879 nss_n2h_empty_pool_buf_cfg[NSS_CORE_0];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001880 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.low_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07001881 nss_n2h_water_mark[NSS_CORE_0][0];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001882 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.high_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07001883 nss_n2h_water_mark[NSS_CORE_0][1];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001884 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.pool_size =
1885 nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0];
1886 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.low_water =
1887 nss_n2h_paged_water_mark[NSS_CORE_0][0];
1888 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.high_water =
1889 nss_n2h_paged_water_mark[NSS_CORE_0][1];
1890
Stephen Wang49b474b2016-03-25 10:40:30 -07001891 /*
1892 * Core1
1893 */
1894 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_1].sem, 1);
1895 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_1].complete);
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001896 nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.pool_size =
Stephen Wang49b474b2016-03-25 10:40:30 -07001897 nss_n2h_empty_pool_buf_cfg[NSS_CORE_1];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001898 nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.low_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07001899 nss_n2h_water_mark[NSS_CORE_1][0];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001900 nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.high_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07001901 nss_n2h_water_mark[NSS_CORE_1][1];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001902 nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.pool_size =
1903 nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1];
1904 nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.low_water =
1905 nss_n2h_paged_water_mark[NSS_CORE_1][0];
1906 nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.high_water =
1907 nss_n2h_paged_water_mark[NSS_CORE_1][1];
1908
Stephen Wang49b474b2016-03-25 10:40:30 -07001909 /*
1910 * WiFi pool buf cfg sema init
1911 */
1912 sema_init(&nss_n2h_wp.sem, 1);
1913 init_completion(&nss_n2h_wp.complete);
1914
Vijay Dewangan488e5372014-12-29 21:40:11 -08001915 nss_n2h_notify_register(NSS_CORE_0, NULL, NULL);
1916 nss_n2h_notify_register(NSS_CORE_1, NULL, NULL);
1917
Stephen Wang49b474b2016-03-25 10:40:30 -07001918 /*
1919 * Register sysctl table.
1920 */
1921 nss_n2h_header = register_sysctl_table(nss_n2h_root);
1922}
1923
1924/*
1925 * nss_n2h_unregister_sysctl()
1926 * Unregister sysctl specific to n2h
1927 */
1928void nss_n2h_unregister_sysctl(void)
1929{
1930 /*
1931 * Unregister sysctl table.
1932 */
1933 if (nss_n2h_header) {
1934 unregister_sysctl_table(nss_n2h_header);
1935 }
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301936}
Vijay Dewangan488e5372014-12-29 21:40:11 -08001937
1938EXPORT_SYMBOL(nss_n2h_notify_register);