blob: 846bd64ff71969437d1791f6b726c80b2a372108 [file] [log] [blame]
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301/*
2 **************************************************************************
Wayne Tand5058cb2020-01-07 14:39:16 -08003 * Copyright (c) 2013-2020, 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"
Yu Huang8c107082017-07-24 14:58:26 -070023#include "nss_n2h_stats.h"
Wayne Tand5058cb2020-01-07 14:39:16 -080024#include "nss_n2h_strings.h"
25#include "nss_drv_strings.h"
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053026
Aniruddha Paulfc578bd2019-03-18 16:59:22 +053027#define NSS_N2H_MAX_BUF_POOL_SIZE (1024 * 1024 * 20) /* 20MB */
Saurabh Misra71034db2015-06-04 16:18:38 -070028#define NSS_N2H_MIN_EMPTY_POOL_BUF_SZ 32
Aniruddha Paulfc578bd2019-03-18 16:59:22 +053029#define NSS_N2H_MAX_EMPTY_POOL_BUF_SZ 131072
Vijay Dewangan488e5372014-12-29 21:40:11 -080030#define NSS_N2H_DEFAULT_EMPTY_POOL_BUF_SZ 8192
ratheesh kannothab436af2017-07-20 08:51:07 +053031#define NSS_N2H_TX_TIMEOUT 3000 /* 3 Seconds */
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053032
Saurabh Misra71034db2015-06-04 16:18:38 -070033int nss_n2h_empty_pool_buf_cfg[NSS_MAX_CORES] __read_mostly = {-1, -1};
Sachin Shashidhar475012b2017-03-13 16:56:07 -070034int nss_n2h_empty_paged_pool_buf_cfg[NSS_MAX_CORES] __read_mostly = {-1, -1};
Saurabh Misra71034db2015-06-04 16:18:38 -070035int nss_n2h_water_mark[NSS_MAX_CORES][2] __read_mostly = {{-1, -1}, {-1, -1} };
Sachin Shashidhar475012b2017-03-13 16:56:07 -070036int nss_n2h_paged_water_mark[NSS_MAX_CORES][2] __read_mostly = {{-1, -1}, {-1, -1} };
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +053037int nss_n2h_wifi_pool_buf_cfg __read_mostly = -1;
Stephen Wang49b474b2016-03-25 10:40:30 -070038int nss_n2h_core0_mitigation_cfg __read_mostly = 1;
39int nss_n2h_core1_mitigation_cfg __read_mostly = 1;
40int nss_n2h_core0_add_buf_pool_size __read_mostly;
41int nss_n2h_core1_add_buf_pool_size __read_mostly;
Shashank Balashankar4162f572018-08-21 13:32:34 -070042int nss_n2h_queue_limit[NSS_MAX_CORES] __read_mostly = {NSS_DEFAULT_QUEUE_LIMIT, NSS_DEFAULT_QUEUE_LIMIT};
Sakthi Vignesh Radhakrishnanf9823102019-03-05 15:38:36 -080043int nss_n2h_host_bp_config[NSS_MAX_CORES] __read_mostly;
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053044
Vijay Dewangan488e5372014-12-29 21:40:11 -080045struct nss_n2h_registered_data {
46 nss_n2h_msg_callback_t n2h_callback;
47 void *app_data;
48};
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053049
Vijay Dewangan488e5372014-12-29 21:40:11 -080050static struct nss_n2h_cfg_pvt nss_n2h_nepbcfgp[NSS_MAX_CORES];
51static struct nss_n2h_registered_data nss_n2h_rd[NSS_MAX_CORES];
Vijay Dewangan634ce592015-01-07 17:21:09 -080052static struct nss_n2h_cfg_pvt nss_n2h_rcp;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +053053static struct nss_n2h_cfg_pvt nss_n2h_mitigationcp[NSS_CORE_MAX];
54static struct nss_n2h_cfg_pvt nss_n2h_bufcp[NSS_CORE_MAX];
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +053055static struct nss_n2h_cfg_pvt nss_n2h_wp;
ratheesh kannothab436af2017-07-20 08:51:07 +053056static struct nss_n2h_cfg_pvt nss_n2h_q_cfg_pvt;
Shashank Balashankar4162f572018-08-21 13:32:34 -070057static struct nss_n2h_cfg_pvt nss_n2h_q_lim_pvt;
Sakthi Vignesh Radhakrishnanf9823102019-03-05 15:38:36 -080058static struct nss_n2h_cfg_pvt nss_n2h_host_bp_cfg_pvt;
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053059
60/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070061 * nss_n2h_interface_handler()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053062 * Handle NSS -> HLOS messages for N2H node
63 */
Vijay Dewangan634ce592015-01-07 17:21:09 -080064static void nss_n2h_interface_handler(struct nss_ctx_instance *nss_ctx,
65 struct nss_cmn_msg *ncm,
Arunkumar Tba9b4a02016-11-07 11:41:14 +053066 void *app_data)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053067{
68 struct nss_n2h_msg *nnm = (struct nss_n2h_msg *)ncm;
Vijay Dewangan488e5372014-12-29 21:40:11 -080069 nss_n2h_msg_callback_t cb;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053070
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070071 BUG_ON(ncm->interface != NSS_N2H_INTERFACE);
72
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053073 /*
74 * Is this a valid request/response packet?
75 */
76 if (nnm->cm.type >= NSS_METADATA_TYPE_N2H_MAX) {
77 nss_warning("%p: received invalid message %d for Offload stats interface", nss_ctx, nnm->cm.type);
78 return;
79 }
80
81 switch (nnm->cm.type) {
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053082 case NSS_TX_METADATA_TYPE_N2H_RPS_CFG:
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053083 nss_info("NSS N2H rps_en %d \n",nnm->msg.rps_cfg.enable);
Vijay Dewangan488e5372014-12-29 21:40:11 -080084 break;
85
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +053086 case NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG:
87 nss_info("NSS N2H mitigation_dis %d \n",nnm->msg.mitigation_cfg.enable);
88 break;
89
Vijay Dewangan488e5372014-12-29 21:40:11 -080090 case NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG:
91 nss_info("%p: empty pool buf cfg response from FW", nss_ctx);
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053092 break;
93
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +053094 case NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS:
95 nss_info("%p: flush payloads cmd response from FW", nss_ctx);
96 break;
97
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053098 case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC:
Wayne Tand5058cb2020-01-07 14:39:16 -080099 /*
100 * Update driver statistics and send statistics notifications to the registered modules.
101 */
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700102 nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync);
Wayne Tand5058cb2020-01-07 14:39:16 -0800103 nss_n2h_stats_notify(nss_ctx);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530104 break;
105
106 default:
107 if (ncm->response != NSS_CMN_RESPONSE_ACK) {
108 /*
109 * Check response
110 */
111 nss_info("%p: Received response %d for type %d, interface %d",
112 nss_ctx, ncm->response, ncm->type, ncm->interface);
113 }
114 }
Vijay Dewangan488e5372014-12-29 21:40:11 -0800115
116 /*
Stephen Wang49b474b2016-03-25 10:40:30 -0700117 * Update the callback and app_data for NOTIFY messages, n2h sends all notify messages
Vijay Dewangan488e5372014-12-29 21:40:11 -0800118 * to the same callback/app_data.
119 */
Suruchi Agarwale4ad24a2018-06-11 12:03:46 +0530120 if (nnm->cm.response == NSS_CMN_RESPONSE_NOTIFY) {
Vijay Dewangan488e5372014-12-29 21:40:11 -0800121 /*
122 * Place holder for the user to create right call
Suruchi Agarwale4ad24a2018-06-11 12:03:46 +0530123 * back and app data when response is NSS_CMN_RESPONSE_NOTIFY
Vijay Dewangan488e5372014-12-29 21:40:11 -0800124 */
Stephen Wangaed46332016-12-12 17:29:03 -0800125 ncm->cb = (nss_ptr_t)nss_n2h_rd[nss_ctx->id].n2h_callback;
126 ncm->app_data = (nss_ptr_t)nss_n2h_rd[nss_ctx->id].app_data;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800127 }
128
129 /*
130 * Do we have a callback?
131 */
132 if (!ncm->cb) {
133 return;
134 }
135
136 /*
137 * Callback
138 */
139 cb = (nss_n2h_msg_callback_t)ncm->cb;
140 cb((void *)ncm->app_data, nnm);
141}
142
143/*
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530144 * nss_n2h_mitigation_cfg_callback()
145 * call back function for mitigation configuration
146 */
147static void nss_n2h_mitigation_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
148{
Stephen Wangaed46332016-12-12 17:29:03 -0800149 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530150 struct nss_top_instance *nss_top = &nss_top_main;
151 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
152
153 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
154
155 /*
156 * Error, hence we are not updating the nss_n2h_mitigate_en
157 */
158 nss_n2h_mitigationcp[core_num].response = NSS_FAILURE;
159 complete(&nss_n2h_mitigationcp[core_num].complete);
160 nss_warning("core%d: MITIGATION configuration failed : %d\n", core_num, nnm->cm.error);
161 return;
162 }
163
164 nss_info("core%d: MITIGATION configuration succeeded: %d\n", core_num, nnm->cm.error);
165
166 nss_ctx->n2h_mitigate_en = nnm->msg.mitigation_cfg.enable;
167 nss_n2h_mitigationcp[core_num].response = NSS_SUCCESS;
168 complete(&nss_n2h_mitigationcp[core_num].complete);
169}
170
171/*
172 * nss_n2h_buf_cfg_callback()
173 * call back function for pbuf configuration
174 */
175static void nss_n2h_bufs_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
176{
Stephen Wangaed46332016-12-12 17:29:03 -0800177 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +0530178 unsigned int allocated_sz;
179
180 struct nss_top_instance *nss_top = &nss_top_main;
181 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
182
183 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
184 nss_n2h_bufcp[core_num].response = NSS_FAILURE;
185 nss_warning("core%d: buf configuration failed : %d\n", core_num, nnm->cm.error);
186 goto done;
187 }
188
189 nss_info("core%d: buf configuration succeeded: %d\n", core_num, nnm->cm.error);
190
191 allocated_sz = nnm->msg.buf_pool.nss_buf_page_size * nnm->msg.buf_pool.nss_buf_num_pages;
192 nss_ctx->buf_sz_allocated += allocated_sz;
193
194 nss_n2h_bufcp[core_num].response = NSS_SUCCESS;
195
196done:
197 complete(&nss_n2h_bufcp[core_num].complete);
198}
199
200/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700201 * nss_n2h_payload_stats_callback()
202 * It gets called response to payload accounting.
Vijay Dewangan488e5372014-12-29 21:40:11 -0800203 */
Saurabh Misra71034db2015-06-04 16:18:38 -0700204static void nss_n2h_payload_stats_callback(void *app_data,
205 struct nss_n2h_msg *nnm)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800206{
Stephen Wangaed46332016-12-12 17:29:03 -0800207 uint32_t core_num = (uint32_t)(nss_ptr_t)app_data;
Saurabh Misra71034db2015-06-04 16:18:38 -0700208
Vijay Dewangan488e5372014-12-29 21:40:11 -0800209 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
210 struct nss_n2h_empty_pool_buf *nnepbcm;
211 nnepbcm = &nnm->msg.empty_pool_buf_cfg;
212
Saurabh Misra71034db2015-06-04 16:18:38 -0700213 nss_warning("%d: core empty pool buf set failure: %d\n",
214 core_num, nnm->cm.error);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800215 nss_n2h_nepbcfgp[core_num].response = NSS_FAILURE;
216 complete(&nss_n2h_nepbcfgp[core_num].complete);
217 return;
218 }
219
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700220 if (nnm->cm.type == NSS_TX_METADATA_TYPE_GET_WATER_MARK) {
221 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size =
Saurabh Misra71034db2015-06-04 16:18:38 -0700222 ntohl(nnm->msg.payload_info.pool_size);
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700223 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water =
Saurabh Misra71034db2015-06-04 16:18:38 -0700224 ntohl(nnm->msg.payload_info.low_water);
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700225 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water =
Saurabh Misra71034db2015-06-04 16:18:38 -0700226 ntohl(nnm->msg.payload_info.high_water);
227 }
228
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700229 if (nnm->cm.type == NSS_TX_METADATA_TYPE_GET_PAGED_WATER_MARK) {
230 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size =
231 ntohl(nnm->msg.paged_payload_info.pool_size);
232 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water =
233 ntohl(nnm->msg.paged_payload_info.low_water);
234 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water =
235 ntohl(nnm->msg.paged_payload_info.high_water);
236 }
237
Vijay Dewangan488e5372014-12-29 21:40:11 -0800238 nss_n2h_nepbcfgp[core_num].response = NSS_SUCCESS;
239 complete(&nss_n2h_nepbcfgp[core_num].complete);
240}
241
242/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530243 * nss_n2h_set_wifi_payloads_callback()
Cemil Coskun9165c762017-12-04 14:35:24 -0800244 * call back function for response to wifi pool configuration
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530245 *
246 */
247static void nss_n2h_set_wifi_payloads_callback(void *app_data,
248 struct nss_n2h_msg *nnm)
249{
Arunkumar Tba9b4a02016-11-07 11:41:14 +0530250 struct nss_ctx_instance *nss_ctx __maybe_unused = (struct nss_ctx_instance *)app_data;
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530251 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
252
253 nss_n2h_wp.response = NSS_FAILURE;
254 complete(&nss_n2h_wp.complete);
255 nss_warning("%p: wifi pool configuration failed : %d\n", nss_ctx,
256 nnm->cm.error);
257 return;
258 }
259
260 nss_info("%p: wifi payload configuration succeeded: %d\n", nss_ctx,
261 nnm->cm.error);
262 nss_n2h_wp.response = NSS_SUCCESS;
Neelansh Mittalfa08fba2019-12-12 12:25:27 +0530263 nss_n2h_wp.wifi_pool = ntohl(nnm->msg.wp.payloads);
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530264 complete(&nss_n2h_wp.complete);
265}
266
267/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700268 * nss_n2h_get_payload_info()
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700269 * Gets Payload information.
Vijay Dewangan488e5372014-12-29 21:40:11 -0800270 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700271static 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 -0700272{
273 struct nss_top_instance *nss_top = &nss_top_main;
274 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
Saurabh Misra71034db2015-06-04 16:18:38 -0700275 nss_tx_status_t nss_tx_status;
276 int ret = NSS_FAILURE;
277
278 /*
279 * Note that semaphore should be already held.
280 */
281
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700282 nss_tx_status = nss_n2h_tx_msg(nss_ctx, nnm);
Saurabh Misra71034db2015-06-04 16:18:38 -0700283
284 if (nss_tx_status != NSS_TX_SUCCESS) {
Stephen Wangaed46332016-12-12 17:29:03 -0800285 nss_warning("%p: core %d nss_tx error errorn", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700286 return NSS_FAILURE;
287 }
288
289 /*
290 * Blocking call, wait till we get ACK for this msg.
291 */
292 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
293 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
294 if (ret == 0) {
Stephen Wangaed46332016-12-12 17:29:03 -0800295 nss_warning("%p: core %d waiting for ack timed out\n", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700296 return NSS_FAILURE;
297 }
298
299 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
Stephen Wangaed46332016-12-12 17:29:03 -0800300 nss_warning("%p: core %d response returned failure\n", nss_ctx, (int)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700301 return NSS_FAILURE;
302 }
303
304 return NSS_SUCCESS;
305}
306
307/*
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700308 * nss_n2h_get_default_payload_info()
309 * Gets the default payload information.
310 */
311static int nss_n2h_get_default_payload_info(nss_ptr_t core_num)
312{
313 struct nss_n2h_msg nnm;
314
315 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
316 NSS_TX_METADATA_TYPE_GET_WATER_MARK,
317 sizeof(struct nss_n2h_payload_info),
318 nss_n2h_payload_stats_callback,
319 (void *)core_num);
320
321 return nss_n2h_get_payload_info(core_num, &nnm,
322 &nnm.msg.payload_info);
323}
324
325/*
326 * nss_n2h_get_paged_payload_info()
327 * Gets the paged payload information.
328 */
329static int nss_n2h_get_paged_payload_info(nss_ptr_t core_num)
330{
331 struct nss_n2h_msg nnm;
332
333 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
334 NSS_TX_METADATA_TYPE_GET_PAGED_WATER_MARK,
335 sizeof(struct nss_n2h_payload_info),
336 nss_n2h_payload_stats_callback,
337 (void *)core_num);
338
339 return nss_n2h_get_payload_info(core_num, &nnm,
340 &nnm.msg.paged_payload_info);
341}
342
343/*
Amit Guptaca2ea682019-01-24 17:18:46 +0530344 * nss_n2h_set_empty_buf_pool()
Saurabh Misra71034db2015-06-04 16:18:38 -0700345 * Sets empty pool buffer
346 */
Amit Guptaca2ea682019-01-24 17:18:46 +0530347static int nss_n2h_set_empty_buf_pool(struct ctl_table *ctl, int write,
Saurabh Misra71034db2015-06-04 16:18:38 -0700348 void __user *buffer,
349 size_t *lenp, loff_t *ppos,
Stephen Wangaed46332016-12-12 17:29:03 -0800350 nss_ptr_t core_num, int *new_val)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800351{
352 struct nss_top_instance *nss_top = &nss_top_main;
353 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
354 struct nss_n2h_msg nnm;
355 struct nss_n2h_empty_pool_buf *nnepbcm;
356 nss_tx_status_t nss_tx_status;
357 int ret = NSS_FAILURE;
358
359 /*
360 * Acquiring semaphore
361 */
362 down(&nss_n2h_nepbcfgp[core_num].sem);
363
364 /*
365 * Take snap shot of current value
366 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700367 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size = *new_val;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800368
Saurabh Misra71034db2015-06-04 16:18:38 -0700369 if (!write) {
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700370 ret = nss_n2h_get_default_payload_info(core_num);
371 *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size;
Saurabh Misra71034db2015-06-04 16:18:38 -0700372 if (ret == NSS_FAILURE) {
373 up(&nss_n2h_nepbcfgp[core_num].sem);
374 return -EBUSY;
375 }
376
377 up(&nss_n2h_nepbcfgp[core_num].sem);
378
379 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
380 return ret;
381 }
382
Vijay Dewangan488e5372014-12-29 21:40:11 -0800383 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
Saurabh Misra71034db2015-06-04 16:18:38 -0700384 if (ret) {
Vijay Dewangan488e5372014-12-29 21:40:11 -0800385 up(&nss_n2h_nepbcfgp[core_num].sem);
386 return ret;
387 }
388
Vijay Dewangan488e5372014-12-29 21:40:11 -0800389 if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700390 nss_warning("%p: core %d setting %d < min number of buffer",
Stephen Wangaed46332016-12-12 17:29:03 -0800391 nss_ctx, (int)core_num, *new_val);
Stephen Wang06761022015-03-03 16:38:42 -0800392 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800393 }
394
395 nss_info("%p: core %d number of empty pool buffer is : %d\n",
Stephen Wangaed46332016-12-12 17:29:03 -0800396 nss_ctx, (int)core_num, *new_val);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800397
398 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
399 NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG,
400 sizeof(struct nss_n2h_empty_pool_buf),
Saurabh Misra71034db2015-06-04 16:18:38 -0700401 nss_n2h_payload_stats_callback,
Stephen Wangaed46332016-12-12 17:29:03 -0800402 (nss_ptr_t *)core_num);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800403
404 nnepbcm = &nnm.msg.empty_pool_buf_cfg;
405 nnepbcm->pool_size = htonl(*new_val);
406 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
407
408 if (nss_tx_status != NSS_TX_SUCCESS) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700409 nss_warning("%p: core %d nss_tx error empty pool buffer: %d\n",
Stephen Wangaed46332016-12-12 17:29:03 -0800410 nss_ctx, (int)core_num, *new_val);
Stephen Wang06761022015-03-03 16:38:42 -0800411 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800412 }
413
414 /*
415 * Blocking call, wait till we get ACK for this msg.
416 */
Saurabh Misra71034db2015-06-04 16:18:38 -0700417 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
418 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
Vijay Dewangan488e5372014-12-29 21:40:11 -0800419 if (ret == 0) {
Stephen Wangaed46332016-12-12 17:29:03 -0800420 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, (int)core_num);
Stephen Wang06761022015-03-03 16:38:42 -0800421 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800422 }
423
424 /*
425 * ACK/NACK received from NSS FW
426 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
427 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
428 */
429 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
Stephen Wang06761022015-03-03 16:38:42 -0800430 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800431 }
432
433 up(&nss_n2h_nepbcfgp[core_num].sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700434 return 0;
Stephen Wang06761022015-03-03 16:38:42 -0800435
436failure:
437 /*
438 * Restore the current_value to its previous state
439 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700440 *new_val = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.pool_size;
441 up(&nss_n2h_nepbcfgp[core_num].sem);
442 return NSS_FAILURE;
443}
444
445/*
446 * nss_n2h_set_empty_paged_pool_buf()
447 * Sets empty paged pool buffer
448 */
449static int nss_n2h_set_empty_paged_pool_buf(struct ctl_table *ctl, int write,
450 void __user *buffer,
451 size_t *lenp, loff_t *ppos,
452 nss_ptr_t core_num, int *new_val)
453{
454 struct nss_top_instance *nss_top = &nss_top_main;
455 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
456 struct nss_n2h_msg nnm;
457 struct nss_n2h_empty_pool_buf *nneppbcm;
458 nss_tx_status_t nss_tx_status;
459 int ret = NSS_FAILURE;
460
461 /*
462 * Acquiring semaphore
463 */
464 down(&nss_n2h_nepbcfgp[core_num].sem);
465
466 /*
467 * Take snap shot of current value
468 */
469 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size = *new_val;
470
471 if (!write) {
472 ret = nss_n2h_get_paged_payload_info(core_num);
473 *new_val = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size;
474 if (ret == NSS_FAILURE) {
475 up(&nss_n2h_nepbcfgp[core_num].sem);
476 return -EBUSY;
477 }
478
479 up(&nss_n2h_nepbcfgp[core_num].sem);
480
481 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
482 return ret;
483 }
484
485 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
486 if (ret) {
487 up(&nss_n2h_nepbcfgp[core_num].sem);
488 return ret;
489 }
490
491 if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
492 nss_warning("%p: core %d setting %d < min number of buffer",
493 nss_ctx, (int)core_num, *new_val);
494 goto failure;
495 }
496
497 nss_info("%p: core %d number of empty paged pool buffer is : %d\n",
498 nss_ctx, (int)core_num, *new_val);
499
500 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
501 NSS_TX_METADATA_TYPE_N2H_EMPTY_PAGED_POOL_BUF_CFG,
502 sizeof(struct nss_n2h_empty_pool_buf),
503 nss_n2h_payload_stats_callback,
504 (nss_ptr_t *)core_num);
505
506 nneppbcm = &nnm.msg.empty_pool_buf_cfg;
507 nneppbcm->pool_size = htonl(*new_val);
508 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
509
510 if (nss_tx_status != NSS_TX_SUCCESS) {
511 nss_warning("%p: core %d nss_tx error empty paged pool buffer: %d\n",
512 nss_ctx, (int)core_num, *new_val);
513 goto failure;
514 }
515
516 /*
517 * Blocking call, wait till we get ACK for this msg.
518 */
519 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
520 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
521 if (ret == 0) {
522 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, (int)core_num);
523 goto failure;
524 }
525
526 /*
527 * ACK/NACK received from NSS FW
528 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
529 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
530 */
531 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
532 goto failure;
533 }
534
535 up(&nss_n2h_nepbcfgp[core_num].sem);
536 return 0;
537
538failure:
539 /*
540 * Restore the current_value to its previous state
541 */
542 *new_val = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.pool_size;
Saurabh Misra71034db2015-06-04 16:18:38 -0700543 up(&nss_n2h_nepbcfgp[core_num].sem);
544 return NSS_FAILURE;
545}
546
547/*
548 * nss_n2h_set_water_mark()
549 * Sets water mark for N2H SOS
550 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700551static int nss_n2h_set_water_mark(struct ctl_table *ctl, int write,
Saurabh Misra71034db2015-06-04 16:18:38 -0700552 void __user *buffer,
553 size_t *lenp, loff_t *ppos,
Stephen Wangaed46332016-12-12 17:29:03 -0800554 uint32_t core_num, int *low, int *high)
Saurabh Misra71034db2015-06-04 16:18:38 -0700555{
556 struct nss_top_instance *nss_top = &nss_top_main;
557 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
558 struct nss_n2h_msg nnm;
559 struct nss_n2h_water_mark *wm;
560 nss_tx_status_t nss_tx_status;
561 int ret = NSS_FAILURE;
562
563 /*
564 * Acquiring semaphore
565 */
566 down(&nss_n2h_nepbcfgp[core_num].sem);
567
568 /*
569 * Take snap shot of current value
570 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700571 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water = *low;
572 nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water = *high;
Saurabh Misra71034db2015-06-04 16:18:38 -0700573
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700574 if (!write || *low == -1 || *high == -1) {
575 ret = nss_n2h_get_default_payload_info(core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700576 if (ret == NSS_FAILURE) {
577 up(&nss_n2h_nepbcfgp[core_num].sem);
578 return -EBUSY;
579 }
580
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700581 *low = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water;
582 *high = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water;
Saurabh Misra71034db2015-06-04 16:18:38 -0700583 }
584
585 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700586 if (!write || ret) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700587 up(&nss_n2h_nepbcfgp[core_num].sem);
588 return ret;
589 }
590
Saurabh Misra71034db2015-06-04 16:18:38 -0700591 if ((*low < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) ||
592 (*high < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
593 nss_warning("%p: core %d setting %d, %d < min number of buffer",
594 nss_ctx, core_num, *low, *high);
595 goto failure;
596 }
597
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530598 if ((*low > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) ||
599 (*high > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
Saurabh Misra71034db2015-06-04 16:18:38 -0700600 nss_warning("%p: core %d setting %d, %d is > upper limit",
601 nss_ctx, core_num, *low, *high);
602 goto failure;
603 }
604
605 if (*low > *high) {
606 nss_warning("%p: core %d setting low %d is more than high %d",
607 nss_ctx, core_num, *low, *high);
608 goto failure;
609 }
610
611 nss_info("%p: core %d number of low : %d and high : %d\n",
612 nss_ctx, core_num, *low, *high);
613
614 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
615 NSS_TX_METADATA_TYPE_SET_WATER_MARK,
616 sizeof(struct nss_n2h_water_mark),
617 nss_n2h_payload_stats_callback,
Stephen Wangaed46332016-12-12 17:29:03 -0800618 (void *)(nss_ptr_t)core_num);
Saurabh Misra71034db2015-06-04 16:18:38 -0700619
620 wm = &nnm.msg.wm;
621 wm->low_water = htonl(*low);
622 wm->high_water = htonl(*high);
623 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
624
625 if (nss_tx_status != NSS_TX_SUCCESS) {
626 nss_warning("%p: core %d nss_tx error setting : %d, %d\n",
627 nss_ctx, core_num, *low, *high);
628 goto failure;
629 }
630
631 /*
632 * Blocking call, wait till we get ACK for this msg.
633 */
634 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
635 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
636 if (ret == 0) {
637 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx,
638 core_num);
639 goto failure;
640 }
641
642 /*
643 * ACK/NACK received from NSS FW
644 */
645 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response)
646 goto failure;
647
648 up(&nss_n2h_nepbcfgp[core_num].sem);
649 return NSS_SUCCESS;
650
651failure:
652 /*
653 * Restore the current_value to its previous state
654 */
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700655 *low = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.low_water;
656 *high = nss_n2h_nepbcfgp[core_num].empty_buf_pool_info.high_water;
657 up(&nss_n2h_nepbcfgp[core_num].sem);
658 return -EINVAL;
659}
660
661/*
662 * nss_n2h_set_paged_water_mark()
663 * Sets water mark for paged pool N2H SOS
664 */
665static int nss_n2h_set_paged_water_mark(struct ctl_table *ctl, int write,
666 void __user *buffer,
667 size_t *lenp, loff_t *ppos,
668 uint32_t core_num, int *low, int *high)
669{
670 struct nss_top_instance *nss_top = &nss_top_main;
671 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
672 struct nss_n2h_msg nnm;
673 struct nss_n2h_water_mark *pwm;
674 nss_tx_status_t nss_tx_status;
675 int ret = NSS_FAILURE;
676
677 /*
678 * Acquiring semaphore
679 */
680 down(&nss_n2h_nepbcfgp[core_num].sem);
681
682 /*
683 * Take snap shot of current value
684 */
685 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water = *low;
686 nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water = *high;
687
688 if (!write || *low == -1 || *high == -1) {
689 ret = nss_n2h_get_paged_payload_info(core_num);
690 if (ret == NSS_FAILURE) {
691 up(&nss_n2h_nepbcfgp[core_num].sem);
692 return -EBUSY;
693 }
694
695 *low = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water;
696 *high = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water;
697 }
698
699 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
700 if (!write || ret) {
701 up(&nss_n2h_nepbcfgp[core_num].sem);
702 return ret;
703 }
704
705 if ((*low < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) ||
706 (*high < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
707 nss_warning("%p: core %d setting %d, %d < min number of buffer",
708 nss_ctx, core_num, *low, *high);
709 goto failure;
710 }
711
712 if ((*low > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) ||
713 (*high > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
714 nss_warning("%p: core %d setting %d, %d is > upper limit",
715 nss_ctx, core_num, *low, *high);
716 goto failure;
717 }
718
719 if (*low > *high) {
720 nss_warning("%p: core %d setting low %d is more than high %d",
721 nss_ctx, core_num, *low, *high);
722 goto failure;
723 }
724
725 nss_info("%p: core %d number of low : %d and high : %d\n",
726 nss_ctx, core_num, *low, *high);
727
728 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
729 NSS_TX_METADATA_TYPE_SET_PAGED_WATER_MARK,
730 sizeof(struct nss_n2h_water_mark),
731 nss_n2h_payload_stats_callback,
732 (void *)(nss_ptr_t)core_num);
733
734 pwm = &nnm.msg.wm_paged;
735 pwm->low_water = htonl(*low);
736 pwm->high_water = htonl(*high);
737 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
738
739 if (nss_tx_status != NSS_TX_SUCCESS) {
740 nss_warning("%p: core %d nss_tx error setting : %d, %d\n",
741 nss_ctx, core_num, *low, *high);
742 goto failure;
743 }
744
745 /*
746 * Blocking call, wait till we get ACK for this msg.
747 */
748 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete,
749 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
750 if (ret == 0) {
751 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx,
752 core_num);
753 goto failure;
754 }
755
756 /*
757 * ACK/NACK received from NSS FW
758 */
759 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response)
760 goto failure;
761
762 up(&nss_n2h_nepbcfgp[core_num].sem);
763 return NSS_SUCCESS;
764
765failure:
766 /*
767 * Restore the current_value to its previous state
768 */
769 *low = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.low_water;
770 *high = nss_n2h_nepbcfgp[core_num].empty_paged_buf_pool_info.high_water;
Stephen Wang06761022015-03-03 16:38:42 -0800771 up(&nss_n2h_nepbcfgp[core_num].sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700772 return -EINVAL;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800773}
774
775/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530776 * nss_n2h_cfg_wifi_pool()
777 * Sets number of wifi payloads to adjust high water mark for N2H SoS
778 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700779static int nss_n2h_cfg_wifi_pool(struct ctl_table *ctl, int write,
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530780 void __user *buffer,
781 size_t *lenp, loff_t *ppos,
782 int *payloads)
783{
784 struct nss_top_instance *nss_top = &nss_top_main;
785 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
786 struct nss_n2h_msg nnm;
787 struct nss_n2h_wifi_payloads *wp;
788 nss_tx_status_t nss_tx_status;
789 int ret = NSS_FAILURE;
790
791 /*
792 * Acquiring semaphore
793 */
794 down(&nss_n2h_wp.sem);
795
796 if (!write) {
797 *payloads = nss_n2h_wp.wifi_pool;
798
799 up(&nss_n2h_wp.sem);
800 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
801 return ret;
802 }
803
804 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
805 if (ret) {
806 up(&nss_n2h_wp.sem);
807 return ret;
808 }
809
810 /*
811 * If payloads parameter is not set, we do
812 * nothing.
813 */
814 if (*payloads == -1)
815 goto failure;
816
817 if ((*payloads < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
818 nss_warning("%p: wifi setting %d < min number of buffer",
819 nss_ctx, *payloads);
820 goto failure;
821 }
822
823 if ((*payloads > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ)) {
824 nss_warning("%p: wifi setting %d > max number of buffer",
825 nss_ctx, *payloads);
826 goto failure;
827 }
828
829 nss_info("%p: wifi payloads : %d\n",
830 nss_ctx, *payloads);
831
832 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
833 NSS_TX_METADATA_TYPE_N2H_WIFI_POOL_BUF_CFG,
834 sizeof(struct nss_n2h_wifi_payloads),
835 nss_n2h_set_wifi_payloads_callback,
836 (void *)nss_ctx);
837
838 wp = &nnm.msg.wp;
839 wp->payloads = htonl(*payloads);
840 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
841
842 if (nss_tx_status != NSS_TX_SUCCESS) {
843 nss_warning("%p: wifi setting %d nss_tx error",
844 nss_ctx, *payloads);
845 goto failure;
846 }
847
848 /*
849 * Blocking call, wait till we get ACK for this msg.
850 */
851 ret = wait_for_completion_timeout(&nss_n2h_wp.complete,
852 msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
853 if (ret == 0) {
854 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
855 goto failure;
856 }
857
858 /*
859 * ACK/NACK received from NSS FW
860 */
861 if (NSS_FAILURE == nss_n2h_wp.response)
862 goto failure;
863
864 up(&nss_n2h_wp.sem);
865 return NSS_SUCCESS;
866
867failure:
868 up(&nss_n2h_wp.sem);
869 return -EINVAL;
870}
871
872/*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800873 * nss_n2h_empty_pool_buf_core1_handler()
874 * Sets the number of empty buffer for core 1
875 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700876static int nss_n2h_empty_pool_buf_cfg_core1_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700877 int write, void __user *buffer,
878 size_t *lenp, loff_t *ppos)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800879{
Amit Guptaca2ea682019-01-24 17:18:46 +0530880 return nss_n2h_set_empty_buf_pool(ctl, write, buffer, lenp, ppos,
Saurabh Misra71034db2015-06-04 16:18:38 -0700881 NSS_CORE_1, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800882}
883
884/*
885 * nss_n2h_empty_pool_buf_core0_handler()
886 * Sets the number of empty buffer for core 0
887 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700888static int nss_n2h_empty_pool_buf_cfg_core0_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700889 int write, void __user *buffer,
890 size_t *lenp, loff_t *ppos)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800891{
Amit Guptaca2ea682019-01-24 17:18:46 +0530892 return nss_n2h_set_empty_buf_pool(ctl, write, buffer, lenp, ppos,
Saurabh Misra71034db2015-06-04 16:18:38 -0700893 NSS_CORE_0, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]);
894}
895
896/*
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700897 * nss_n2h_empty_paged_pool_buf_cfg_core1_handler()
898 * Sets the number of empty paged buffer for core 1
899 */
900static int nss_n2h_empty_paged_pool_buf_cfg_core1_handler(struct ctl_table *ctl,
901 int write, void __user *buffer,
902 size_t *lenp, loff_t *ppos)
903{
904 return nss_n2h_set_empty_paged_pool_buf(ctl, write, buffer, lenp, ppos,
905 NSS_CORE_1, &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1]);
906}
907
908/*
909 * nss_n2h_empty_paged_pool_buf_cfg_core0_handler()
910 * Sets the number of empty paged buffer for core 0
911 */
912static int nss_n2h_empty_paged_pool_buf_cfg_core0_handler(struct ctl_table *ctl,
913 int write, void __user *buffer,
914 size_t *lenp, loff_t *ppos)
915{
916 return nss_n2h_set_empty_paged_pool_buf(ctl, write, buffer, lenp, ppos,
917 NSS_CORE_0, &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0]);
918}
919
920/*
Saurabh Misra71034db2015-06-04 16:18:38 -0700921 * nss_n2h_water_mark_core1_handler()
922 * Sets water mark for core 1
923 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700924static int nss_n2h_water_mark_core1_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700925 int write, void __user *buffer,
926 size_t *lenp, loff_t *ppos)
927{
928 return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos,
929 NSS_CORE_1, &nss_n2h_water_mark[NSS_CORE_1][0],
930 &nss_n2h_water_mark[NSS_CORE_1][1]);
931}
932
933/*
934 * nss_n2h_water_mark_core0_handler()
935 * Sets water mark for core 0
936 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700937static int nss_n2h_water_mark_core0_handler(struct ctl_table *ctl,
Saurabh Misra71034db2015-06-04 16:18:38 -0700938 int write, void __user *buffer,
939 size_t *lenp, loff_t *ppos)
940{
941 return nss_n2h_set_water_mark(ctl, write, buffer, lenp, ppos,
942 NSS_CORE_0, &nss_n2h_water_mark[NSS_CORE_0][0],
943 &nss_n2h_water_mark[NSS_CORE_0][1]);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800944}
945
Vijay Dewangan634ce592015-01-07 17:21:09 -0800946/*
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700947 * nss_n2h_paged_water_mark_core1_handler()
948 * Sets paged water mark for core 1
949 */
950static int nss_n2h_paged_water_mark_core1_handler(struct ctl_table *ctl,
951 int write, void __user *buffer,
952 size_t *lenp, loff_t *ppos)
953{
954 return nss_n2h_set_paged_water_mark(ctl, write, buffer, lenp, ppos,
955 NSS_CORE_1, &nss_n2h_paged_water_mark[NSS_CORE_1][0],
956 &nss_n2h_paged_water_mark[NSS_CORE_1][1]);
957}
958
Sachin Shashidhar475012b2017-03-13 16:56:07 -0700959/*
960 * nss_n2h_paged_water_mark_core0_handler()
961 * Sets paged water mark for core 0
962 */
963static int nss_n2h_paged_water_mark_core0_handler(struct ctl_table *ctl,
964 int write, void __user *buffer,
965 size_t *lenp, loff_t *ppos)
966{
967 return nss_n2h_set_paged_water_mark(ctl, write, buffer, lenp, ppos,
968 NSS_CORE_0, &nss_n2h_paged_water_mark[NSS_CORE_0][0],
969 &nss_n2h_paged_water_mark[NSS_CORE_0][1]);
970}
971
972/*
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530973 * nss_n2h_wifi_payloads_handler()
974 * Sets number of wifi payloads
975 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700976static int nss_n2h_wifi_payloads_handler(struct ctl_table *ctl,
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +0530977 int write, void __user *buffer,
978 size_t *lenp, loff_t *ppos)
979{
980 return nss_n2h_cfg_wifi_pool(ctl, write, buffer, lenp, ppos,
981 &nss_n2h_wifi_pool_buf_cfg);
982}
983
984/*
ratheesh kannothab436af2017-07-20 08:51:07 +0530985 * nss_n2h_update_queue_config_callback()
986 * Callback to handle the completion of queue config command
ratheesh kannoth024a6e82017-05-18 17:48:10 +0530987 */
ratheesh kannothab436af2017-07-20 08:51:07 +0530988static void nss_n2h_update_queue_config_callback(void *app_data, struct nss_n2h_msg *nim)
ratheesh kannoth024a6e82017-05-18 17:48:10 +0530989{
ratheesh kannothab436af2017-07-20 08:51:07 +0530990 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
991 nss_warning("n2h Error response %d\n", nim->cm.response);
992 nss_n2h_q_cfg_pvt.response = NSS_TX_FAILURE;
993 } else {
994 nss_n2h_q_cfg_pvt.response = NSS_TX_SUCCESS;
995 }
996
997 complete(&nss_n2h_q_cfg_pvt.complete);
998}
999
1000/*
1001 * nss_n2h_update_queue_config_async()
1002 * Asynchronous call to send pnode queue configuration.
1003 */
1004nss_tx_status_t nss_n2h_update_queue_config_async(struct nss_ctx_instance *nss_ctx, bool mq_en, uint16_t *qlimits)
1005{
1006
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301007 struct nss_n2h_msg nnm;
1008 struct nss_n2h_pnode_queue_config *cfg;
1009 nss_tx_status_t status;
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301010 int i;
1011
1012 if (!mq_en) {
1013 return NSS_TX_SUCCESS;
1014 }
1015
ratheesh kannoth93ba95c2017-07-13 15:52:52 +05301016 /*
1017 * MQ mode doesnot make any sense if number of priority queues in NSS
1018 * is 1
1019 */
1020 if (NSS_MAX_NUM_PRI <= 1) {
1021 return NSS_TX_SUCCESS;
1022 }
1023
ratheesh kannothab436af2017-07-20 08:51:07 +05301024 memset(&nnm, 0, sizeof(struct nss_n2h_msg));
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301025
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301026 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1027 NSS_TX_METADATA_TYPE_N2H_SET_PNODE_QUEUE_CFG,
1028 sizeof(struct nss_n2h_pnode_queue_config), NULL, 0);
1029
ratheesh kannothab436af2017-07-20 08:51:07 +05301030 cfg = &nnm.msg.pn_q_cfg;
1031
1032 /*
Cemil Coskun9165c762017-12-04 14:35:24 -08001033 * Update limits
1034 */
ratheesh kannothab436af2017-07-20 08:51:07 +05301035 for (i = 0; i < NSS_MAX_NUM_PRI; i++) {
1036 cfg->qlimits[i] = qlimits[i];
1037 }
1038 cfg->mq_en = true;
1039
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301040 status = nss_n2h_tx_msg(nss_ctx, &nnm);
1041 if (status != NSS_TX_SUCCESS) {
1042 nss_warning("%p: nss_tx error to send pnode queue config\n", nss_ctx);
1043 return status;
1044 }
1045
1046 return NSS_TX_SUCCESS;
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301047}
ratheesh kannothab436af2017-07-20 08:51:07 +05301048EXPORT_SYMBOL(nss_n2h_update_queue_config_async);
1049
1050/*
1051 * nss_n2h_update_queue_config_sync()
1052 * Synchronous call to send pnode queue configuration.
1053 */
1054nss_tx_status_t nss_n2h_update_queue_config_sync(struct nss_ctx_instance *nss_ctx, bool mq_en, uint16_t *qlimits)
1055{
1056
1057 struct nss_n2h_msg nnm;
1058 struct nss_n2h_pnode_queue_config *cfg;
1059 nss_tx_status_t status;
1060 int ret, i;
1061
1062 if (!mq_en) {
1063 return NSS_TX_SUCCESS;
1064 }
1065
ratheesh kannoth93ba95c2017-07-13 15:52:52 +05301066 /*
1067 * MQ mode doesnot make any sense if number of priority queues in NSS
1068 * is 1
1069 */
1070 if (NSS_MAX_NUM_PRI <= 1) {
1071 return NSS_TX_SUCCESS;
1072 }
1073
ratheesh kannothab436af2017-07-20 08:51:07 +05301074 memset(&nnm, 0, sizeof(struct nss_n2h_msg));
1075
1076 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1077 NSS_TX_METADATA_TYPE_N2H_SET_PNODE_QUEUE_CFG,
1078 sizeof(struct nss_n2h_pnode_queue_config), nss_n2h_update_queue_config_callback, 0);
1079
1080 cfg = &nnm.msg.pn_q_cfg;
1081
1082 /*
Cemil Coskun9165c762017-12-04 14:35:24 -08001083 * Update limits
1084 */
ratheesh kannothab436af2017-07-20 08:51:07 +05301085 for (i = 0; i < NSS_MAX_NUM_PRI; i++) {
1086 cfg->qlimits[i] = qlimits[i];
1087 }
1088 cfg->mq_en = true;
1089
1090 down(&nss_n2h_q_cfg_pvt.sem);
1091
1092 status = nss_n2h_tx_msg(nss_ctx, &nnm);
1093
1094 if (status != NSS_TX_SUCCESS) {
1095 nss_warning("%p: n2h_tx_msg failed\n", nss_ctx);
1096 up(&nss_n2h_q_cfg_pvt.sem);
1097 return status;
1098 }
1099 ret = wait_for_completion_timeout(&nss_n2h_q_cfg_pvt.complete, msecs_to_jiffies(NSS_N2H_TX_TIMEOUT));
1100
1101 if (!ret) {
1102 nss_warning("%p: Timeout expired for pnode queue config sync message\n", nss_ctx);
1103 nss_n2h_q_cfg_pvt.response = NSS_TX_FAILURE;
1104 }
1105
1106 status = nss_n2h_q_cfg_pvt.response;
1107 up(&nss_n2h_q_cfg_pvt.sem);
1108 return status;
1109}
1110EXPORT_SYMBOL(nss_n2h_update_queue_config_sync);
ratheesh kannoth024a6e82017-05-18 17:48:10 +05301111
1112/*
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301113 * nss_n2h_mitigation_cfg()
1114 * Send Message to NSS to disable MITIGATION.
1115 */
Stephen Wang49b474b2016-03-25 10:40:30 -07001116static 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 +05301117{
1118 struct nss_n2h_msg nnm;
1119 struct nss_n2h_mitigation *mitigation_cfg;
1120 nss_tx_status_t nss_tx_status;
1121 int ret;
1122
1123 nss_assert(core_num < NSS_CORE_MAX);
1124
1125 down(&nss_n2h_mitigationcp[core_num].sem);
1126 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_MITIGATION_CFG,
1127 sizeof(struct nss_n2h_mitigation),
1128 nss_n2h_mitigation_cfg_callback,
1129 (void *)core_num);
1130
1131 mitigation_cfg = &nnm.msg.mitigation_cfg;
1132 mitigation_cfg->enable = enable_mitigation;
1133
1134 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1135
1136 if (nss_tx_status != NSS_TX_SUCCESS) {
1137 nss_warning("%p: nss_tx error setting mitigation\n", nss_ctx);
1138 goto failure;
1139 }
1140
1141 /*
1142 * Blocking call, wait till we get ACK for this msg.
1143 */
1144 ret = wait_for_completion_timeout(&nss_n2h_mitigationcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
1145 if (ret == 0) {
1146 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
1147 goto failure;
1148 }
1149
1150 /*
1151 * ACK/NACK received from NSS FW
1152 */
1153 if (NSS_FAILURE == nss_n2h_mitigationcp[core_num].response) {
1154 goto failure;
1155 }
1156
1157 up(&nss_n2h_mitigationcp[core_num].sem);
1158 return NSS_SUCCESS;
1159
1160failure:
1161 up(&nss_n2h_mitigationcp[core_num].sem);
1162 return NSS_FAILURE;
1163}
1164
1165static inline void nss_n2h_buf_pool_free(struct nss_n2h_buf_pool *buf_pool)
1166{
1167 int page_count;
1168 for (page_count = 0; page_count < buf_pool->nss_buf_num_pages; page_count++) {
Stephen Wang7df68832017-08-10 16:54:35 -07001169 kfree((void *)buf_pool->nss_buf_pool_vaddr[page_count]);
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301170 }
1171}
1172
1173/*
1174 * nss_n2h_buf_cfg()
1175 * Send Message to NSS to enable pbufs.
1176 */
Stephen Wang49b474b2016-03-25 10:40:30 -07001177static nss_tx_status_t nss_n2h_buf_pool_cfg(struct nss_ctx_instance *nss_ctx,
Tallapragada4b0161b2016-07-07 21:38:34 +05301178 int buf_pool_size, nss_core_id_t core_num)
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301179{
1180 static struct nss_n2h_msg nnm;
1181 struct nss_n2h_buf_pool *buf_pool;
1182 nss_tx_status_t nss_tx_status;
1183 int ret;
1184 int page_count;
1185 int num_pages = ALIGN(buf_pool_size, PAGE_SIZE)/PAGE_SIZE;
1186
1187 nss_assert(core_num < NSS_CORE_MAX);
1188
1189 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_METADATA_TYPE_N2H_ADD_BUF_POOL,
1190 sizeof(struct nss_n2h_buf_pool),
1191 nss_n2h_bufs_cfg_callback,
1192 (void *)core_num);
1193
1194 do {
1195
1196 down(&nss_n2h_bufcp[core_num].sem);
1197
1198 buf_pool = &nnm.msg.buf_pool;
1199 buf_pool->nss_buf_page_size = PAGE_SIZE;
1200
1201 for (page_count = 0; page_count < MAX_PAGES_PER_MSG && num_pages; page_count++, num_pages--) {
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301202 void *kern_addr = kzalloc(PAGE_SIZE, GFP_ATOMIC);
1203 if (!kern_addr) {
1204 BUG_ON(!page_count);
1205 break;
1206 }
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301207
Radha krishna Simha Jiguru60068fb2017-07-28 17:40:52 +05301208 kmemleak_not_leak(kern_addr);
Stephen Wang7df68832017-08-10 16:54:35 -07001209 buf_pool->nss_buf_pool_vaddr[page_count] = (nss_ptr_t)kern_addr;
Stephen Wangefd38512017-01-24 14:01:02 -08001210 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 +05301211 }
1212
1213 buf_pool->nss_buf_num_pages = page_count;
1214 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1215 if (nss_tx_status != NSS_TX_SUCCESS) {
1216
1217 nss_n2h_buf_pool_free(buf_pool);
1218 nss_warning("%p: nss_tx error setting pbuf\n", nss_ctx);
1219 goto failure;
1220 }
1221
1222 /*
Cemil Coskun9165c762017-12-04 14:35:24 -08001223 * Blocking call, wait till we get ACK for this msg.
1224 */
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301225 ret = wait_for_completion_timeout(&nss_n2h_bufcp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
1226 if (ret == 0) {
1227 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
1228 goto failure;
1229 }
1230
1231 /*
1232 * ACK/NACK received from NSS FW
1233 */
1234 if (NSS_FAILURE == nss_n2h_bufcp[core_num].response) {
1235
1236 nss_n2h_buf_pool_free(buf_pool);
1237 goto failure;
1238 }
1239
1240 up(&nss_n2h_bufcp[core_num].sem);
1241 } while(num_pages);
1242
1243 return NSS_SUCCESS;
1244failure:
1245 up(&nss_n2h_bufcp[core_num].sem);
1246 return NSS_FAILURE;
1247}
1248
Stephen Wang49b474b2016-03-25 10:40:30 -07001249
1250/*
1251 * nss_mitigation_handler()
1252 * Enable NSS MITIGATION
1253 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001254static 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 -07001255{
1256 struct nss_top_instance *nss_top = &nss_top_main;
1257 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0];
1258 int ret;
1259
1260 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1261 if (ret) {
1262 return ret;
1263 }
1264
1265 /*
1266 * It's a read operation
1267 */
1268 if (!write) {
1269 return ret;
1270 }
1271
1272 if (!nss_n2h_core0_mitigation_cfg) {
1273 printk(KERN_INFO "Disabling NSS MITIGATION\n");
1274 nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_0);
1275 return 0;
1276 }
1277 printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n");
1278 return -EINVAL;
1279}
1280
1281/*
1282 * nss_mitigation_handler()
1283 * Enable NSS MITIGATION
1284 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001285static 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 -07001286{
1287 struct nss_top_instance *nss_top = &nss_top_main;
1288 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1];
1289 int ret;
1290
1291 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1292 if (ret) {
1293 return ret;
1294 }
1295
1296 /*
1297 * It's a read operation
1298 */
1299 if (!write) {
1300 return ret;
1301 }
1302
1303 if (!nss_n2h_core1_mitigation_cfg) {
1304 printk(KERN_INFO "Disabling NSS MITIGATION\n");
1305 nss_n2h_mitigation_cfg(nss_ctx, 0, NSS_CORE_1);
1306 return 0;
1307 }
1308 printk(KERN_INFO "Invalid input value.Valid value is 0, Runtime re-enabling not supported\n");
1309 return -EINVAL;
1310}
1311
1312/*
1313 * nss_buf_handler()
1314 * Add extra NSS bufs from host memory
1315 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001316static 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 -07001317{
1318 struct nss_top_instance *nss_top = &nss_top_main;
1319 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_0];
1320 int ret;
1321
1322 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1323 if (ret) {
1324 return ret;
1325 }
1326
1327 /*
1328 * It's a read operation
1329 */
1330 if (!write) {
1331 return ret;
1332 }
1333
1334 if (nss_ctx->buf_sz_allocated) {
1335 nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1336 return -EPERM;
1337 }
1338
1339 if ((nss_n2h_core0_add_buf_pool_size >= 1) && (nss_n2h_core0_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) {
1340 printk(KERN_INFO "configuring additional NSS pbufs\n");
1341 ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core0_add_buf_pool_size, NSS_CORE_0);
1342 nss_n2h_core0_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1343 printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated);
1344 return ret;
1345 }
1346
1347 printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE);
1348 return -EINVAL;
1349}
1350
1351/*
1352 * nss_n2h_buf_handler()
1353 * Add extra NSS bufs from host memory
1354 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001355static 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 -07001356{
1357 struct nss_top_instance *nss_top = &nss_top_main;
1358 struct nss_ctx_instance *nss_ctx = &nss_top->nss[NSS_CORE_1];
1359 int ret;
1360
1361 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1362 if (ret) {
1363 return ret;
1364 }
1365
1366 /*
1367 * It's a read operation
1368 */
1369 if (!write) {
1370 return ret;
1371 }
1372
1373 if (nss_ctx->buf_sz_allocated) {
1374 nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1375 return -EPERM;
1376 }
1377
1378 if ((nss_n2h_core1_add_buf_pool_size >= 1) && (nss_n2h_core1_add_buf_pool_size <= NSS_N2H_MAX_BUF_POOL_SIZE)) {
1379 printk(KERN_INFO "configuring additional NSS pbufs\n");
1380 ret = nss_n2h_buf_pool_cfg(nss_ctx, nss_n2h_core1_add_buf_pool_size, NSS_CORE_1);
1381 nss_n2h_core1_add_buf_pool_size = nss_ctx->buf_sz_allocated;
1382 printk(KERN_INFO "additional pbufs of size %d got added to NSS\n", nss_ctx->buf_sz_allocated);
1383 return ret;
1384 }
1385
1386 printk(KERN_INFO "Invalid input value. should be greater than 1 and less than %d\n", NSS_N2H_MAX_BUF_POOL_SIZE);
1387 return -EINVAL;
1388}
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05301389
Shashank Balashankar4162f572018-08-21 13:32:34 -07001390/*
1391 * nss_n2h_queue_limit_callback()
1392 * Callback to handle the completion of queue limit command.
1393 */
1394static void nss_n2h_queue_limit_callback(void *app_data, struct nss_n2h_msg *nim)
1395{
1396 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
1397 nss_warning("n2h error response %d\n", nim->cm.response);
1398 }
1399
1400 nss_n2h_q_lim_pvt.response = nim->cm.response;
1401 complete(&nss_n2h_q_lim_pvt.complete);
1402}
1403
1404/*
1405 * nss_n2h_set_queue_limit_sync()
1406 * Sets the n2h queue size limit synchronously.
1407 */
1408static int nss_n2h_set_queue_limit_sync(struct ctl_table *ctl, int write, void __user *buffer,
1409 size_t *lenp, loff_t *ppos, uint32_t core_id)
1410{
1411 struct nss_top_instance *nss_top = &nss_top_main;
1412 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_id];
1413 struct nss_n2h_msg nim;
1414 struct nss_n2h_queue_limit_config *nnqlc = NULL;
1415 int ret, current_val;
1416 nss_tx_status_t nss_tx_status;
1417
1418 /*
1419 * Take a snap shot of current value
1420 */
1421 current_val = nss_n2h_queue_limit[core_id];
1422
1423 /*
1424 * Write the variable with user input
1425 */
1426 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1427 if (ret || (!write)) {
1428 return ret;
1429 }
1430
1431 /*
1432 * We dont allow shortening of the queue size at run-time
1433 */
1434 if (nss_n2h_queue_limit[core_id] < current_val) {
1435 nss_warning("%p: New queue limit %d less than previous value %d. Cant allow shortening\n",
1436 nss_ctx, nss_n2h_queue_limit[core_id], current_val);
1437 nss_n2h_queue_limit[core_id] = current_val;
1438 return NSS_TX_FAILURE;
1439 }
1440
1441 memset(&nim, 0, sizeof(struct nss_n2h_msg));
1442 nss_n2h_msg_init(&nim, NSS_N2H_INTERFACE,
1443 NSS_TX_METADATA_TYPE_N2H_QUEUE_LIMIT_CFG,
1444 sizeof(struct nss_n2h_queue_limit_config), nss_n2h_queue_limit_callback, NULL);
1445
1446 nnqlc = &nim.msg.ql_cfg;
1447 nnqlc->qlimit = nss_n2h_queue_limit[core_id];
1448
1449 /*
1450 * Send synchronous message to firmware
1451 */
1452 down(&nss_n2h_q_lim_pvt.sem);
1453
1454 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nim);
1455 if (nss_tx_status != NSS_TX_SUCCESS) {
1456 nss_warning("%p: n2h queue limit message send failed\n", nss_ctx);
1457 nss_n2h_queue_limit[core_id] = current_val;
1458 up(&nss_n2h_q_lim_pvt.sem);
1459 return nss_tx_status;
1460 }
1461
1462 ret = wait_for_completion_timeout(&nss_n2h_q_lim_pvt.complete, msecs_to_jiffies(NSS_N2H_TX_TIMEOUT));
1463 if (!ret) {
1464 nss_warning("%p: Timeout expired for queue limit sync message\n", nss_ctx);
1465 nss_n2h_queue_limit[core_id] = current_val;
1466 up(&nss_n2h_q_lim_pvt.sem);
1467 return NSS_TX_FAILURE;
1468 }
1469
1470 /*
1471 * If setting the queue limit failed, reset the value to original value
1472 */
1473 if (nss_n2h_q_lim_pvt.response != NSS_CMN_RESPONSE_ACK) {
1474 nss_n2h_queue_limit[core_id] = current_val;
1475 }
1476
1477 up(&nss_n2h_q_lim_pvt.sem);
1478 return NSS_TX_SUCCESS;
1479}
1480
1481/*
1482 * nss_n2h_queue_limit_core0_handler()
1483 * Sets the n2h queue size limit for core0
1484 */
1485static int nss_n2h_queue_limit_core0_handler(struct ctl_table *ctl,
1486 int write, void __user *buffer,
1487 size_t *lenp, loff_t *ppos)
1488{
1489 return nss_n2h_set_queue_limit_sync(ctl, write, buffer, lenp, ppos,
1490 NSS_CORE_0);
1491}
1492
1493/*
1494 * nss_n2h_queue_limit_core1_handler()
1495 * Sets the n2h queue size limit for core1
1496 */
1497static int nss_n2h_queue_limit_core1_handler(struct ctl_table *ctl,
1498 int write, void __user *buffer,
1499 size_t *lenp, loff_t *ppos)
1500{
1501 return nss_n2h_set_queue_limit_sync(ctl, write, buffer, lenp, ppos,
1502 NSS_CORE_1);
1503}
1504
Sakthi Vignesh Radhakrishnanf9823102019-03-05 15:38:36 -08001505/*
1506 * nss_n2h_host_bp_cfg_callback()
1507 * Callback function for back pressure configuration.
1508 */
1509static void nss_n2h_host_bp_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
1510{
1511 struct nss_ctx_instance *nss_ctx __maybe_unused = (struct nss_ctx_instance *)app_data;
1512 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
1513 nss_n2h_host_bp_cfg_pvt.response = NSS_FAILURE;
1514 complete(&nss_n2h_host_bp_cfg_pvt.complete);
1515 nss_warning("%p: n2h back pressure configuration failed : %d\n", nss_ctx, nnm->cm.error);
1516 return;
1517 }
1518
1519 nss_info("%p: n2h back pressure configuration succeeded: %d\n", nss_ctx, nnm->cm.error);
1520 nss_n2h_host_bp_cfg_pvt.response = NSS_SUCCESS;
1521 complete(&nss_n2h_host_bp_cfg_pvt.complete);
1522}
1523
1524/*
1525 * nss_n2h_host_bp_cfg()
1526 * Send Message to n2h to enable back pressure.
1527 */
1528static nss_tx_status_t nss_n2h_host_bp_cfg_sync(struct nss_ctx_instance *nss_ctx, int enable_bp)
1529{
1530 struct nss_n2h_msg nnm;
1531 nss_tx_status_t nss_tx_status;
1532 int ret;
1533
1534 down(&nss_n2h_host_bp_cfg_pvt.sem);
1535 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_HOST_BACK_PRESSURE_CFG,
1536 sizeof(struct nss_n2h_host_back_pressure),
1537 nss_n2h_host_bp_cfg_callback,
1538 (void *)nss_ctx);
1539
1540 nnm.msg.host_bp_cfg.enable = enable_bp;
1541
1542 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1543 if (nss_tx_status != NSS_TX_SUCCESS) {
1544 nss_warning("%p: nss_tx error setting back pressure\n", nss_ctx);
1545 up(&nss_n2h_host_bp_cfg_pvt.sem);
1546 return NSS_FAILURE;
1547 }
1548
1549 /*
1550 * Blocking call, wait till we get ACK for this msg.
1551 */
1552 ret = wait_for_completion_timeout(&nss_n2h_host_bp_cfg_pvt.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
1553 if (ret == 0) {
1554 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
1555 up(&nss_n2h_host_bp_cfg_pvt.sem);
1556 return NSS_FAILURE;
1557 }
1558
1559 /*
1560 * Response received from NSS FW
1561 */
1562 if (nss_n2h_host_bp_cfg_pvt.response == NSS_FAILURE) {
1563 up(&nss_n2h_host_bp_cfg_pvt.sem);
1564 return NSS_FAILURE;
1565 }
1566
1567 up(&nss_n2h_host_bp_cfg_pvt.sem);
1568 return NSS_SUCCESS;
1569}
1570
1571/*
1572 * nss_n2h_host_bp_cfg_handler()
1573 * Enable n2h back pressure.
1574 */
1575static int nss_n2h_host_bp_cfg_handler(struct ctl_table *ctl, int write,
1576 void __user *buffer, size_t *lenp, loff_t *ppos, uint32_t core_id)
1577{
1578 struct nss_top_instance *nss_top = &nss_top_main;
1579 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_id];
1580 int ret, ret_bp, current_state;
1581 current_state = nss_n2h_host_bp_config[core_id];
1582 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
1583
1584 if (ret != NSS_SUCCESS) {
1585 return ret;
1586 }
1587
1588 if (!write) {
1589 return ret;
1590 }
1591
1592 if ((nss_n2h_host_bp_config[core_id] != 0) && (nss_n2h_host_bp_config[core_id] != 1)) {
1593 nss_info_always("Invalid input value. Valid values are 0 and 1\n");
1594 nss_n2h_host_bp_config[core_id] = current_state;
1595 return ret;
1596 }
1597
1598 nss_info("Configuring n2h back pressure\n");
1599 ret_bp = nss_n2h_host_bp_cfg_sync(nss_ctx, nss_n2h_host_bp_config[core_id]);
1600
1601 if (ret_bp != NSS_SUCCESS) {
1602 nss_warning("%p: n2h back pressure config failed\n", nss_ctx);
1603 nss_n2h_host_bp_config[core_id] = current_state;
1604 }
1605
1606 return ret_bp;
1607}
1608
1609/*
1610 * nss_n2h_host_bp_cfg_core0_handler()
1611 * Enable n2h back pressure in core 0.
1612 */
1613static int nss_n2h_host_bp_cfg_core0_handler(struct ctl_table *ctl, int write,
1614 void __user *buffer, size_t *lenp, loff_t *ppos)
1615{
1616 return nss_n2h_host_bp_cfg_handler(ctl, write, buffer, lenp, ppos, NSS_CORE_0);
1617}
1618
1619/*
1620 * nss_n2h_host_bp_cfg_core1_handler()
1621 * Enable n2h back pressure in core 1.
1622 */
1623static int nss_n2h_host_bp_cfg_core1_handler(struct ctl_table *ctl, int write,
1624 void __user *buffer, size_t *lenp, loff_t *ppos)
1625{
1626 return nss_n2h_host_bp_cfg_handler(ctl, write, buffer, lenp, ppos, NSS_CORE_1);
1627}
1628
Suman Ghosh9f7b3702018-09-21 19:51:40 +05301629static struct ctl_table nss_n2h_table_single_core[] = {
1630 {
1631 .procname = "n2h_empty_pool_buf_core0",
1632 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0],
1633 .maxlen = sizeof(int),
1634 .mode = 0644,
1635 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler,
1636 },
1637 {
1638 .procname = "n2h_empty_paged_pool_buf_core0",
1639 .data = &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0],
1640 .maxlen = sizeof(int),
1641 .mode = 0644,
1642 .proc_handler = &nss_n2h_empty_paged_pool_buf_cfg_core0_handler,
1643 },
1644 {
1645 .procname = "n2h_low_water_core0",
1646 .data = &nss_n2h_water_mark[NSS_CORE_0][0],
1647 .maxlen = sizeof(int),
1648 .mode = 0644,
1649 .proc_handler = &nss_n2h_water_mark_core0_handler,
1650 },
1651 {
1652 .procname = "n2h_high_water_core0",
1653 .data = &nss_n2h_water_mark[NSS_CORE_0][1],
1654 .maxlen = sizeof(int),
1655 .mode = 0644,
1656 .proc_handler = &nss_n2h_water_mark_core0_handler,
1657 },
1658 {
1659 .procname = "n2h_paged_low_water_core0",
1660 .data = &nss_n2h_paged_water_mark[NSS_CORE_0][0],
1661 .maxlen = sizeof(int),
1662 .mode = 0644,
1663 .proc_handler = &nss_n2h_paged_water_mark_core0_handler,
1664 },
1665 {
1666 .procname = "n2h_paged_high_water_core0",
1667 .data = &nss_n2h_paged_water_mark[NSS_CORE_0][1],
1668 .maxlen = sizeof(int),
1669 .mode = 0644,
1670 .proc_handler = &nss_n2h_paged_water_mark_core0_handler,
1671 },
1672 {
1673 .procname = "n2h_wifi_pool_buf",
1674 .data = &nss_n2h_wifi_pool_buf_cfg,
1675 .maxlen = sizeof(int),
1676 .mode = 0644,
1677 .proc_handler = &nss_n2h_wifi_payloads_handler,
1678 },
1679 {
1680 .procname = "mitigation_core0",
1681 .data = &nss_n2h_core0_mitigation_cfg,
1682 .maxlen = sizeof(int),
1683 .mode = 0644,
1684 .proc_handler = &nss_n2h_mitigationcfg_core0_handler,
1685 },
1686 {
1687 .procname = "extra_pbuf_core0",
1688 .data = &nss_n2h_core0_add_buf_pool_size,
1689 .maxlen = sizeof(int),
1690 .mode = 0644,
1691 .proc_handler = &nss_n2h_buf_cfg_core0_handler,
1692 },
1693 {
1694 .procname = "n2h_queue_limit_core0",
1695 .data = &nss_n2h_queue_limit[NSS_CORE_0],
1696 .maxlen = sizeof(int),
1697 .mode = 0644,
1698 .proc_handler = &nss_n2h_queue_limit_core0_handler,
1699 },
Sakthi Vignesh Radhakrishnanf9823102019-03-05 15:38:36 -08001700 {
1701 .procname = "host_bp_enable0",
1702 .data = &nss_n2h_host_bp_config[NSS_CORE_0],
1703 .maxlen = sizeof(int),
1704 .mode = 0644,
1705 .proc_handler = &nss_n2h_host_bp_cfg_core0_handler,
1706 },
Suman Ghosh9f7b3702018-09-21 19:51:40 +05301707
1708 { }
1709};
1710
1711static struct ctl_table nss_n2h_table_multi_core[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001712 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001713 .procname = "n2h_empty_pool_buf_core0",
1714 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0],
1715 .maxlen = sizeof(int),
1716 .mode = 0644,
1717 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler,
Vijay Dewangan488e5372014-12-29 21:40:11 -08001718 },
1719 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001720 .procname = "n2h_empty_pool_buf_core1",
1721 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1],
1722 .maxlen = sizeof(int),
1723 .mode = 0644,
1724 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core1_handler,
1725 },
1726 {
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001727 .procname = "n2h_empty_paged_pool_buf_core0",
1728 .data = &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0],
1729 .maxlen = sizeof(int),
1730 .mode = 0644,
1731 .proc_handler = &nss_n2h_empty_paged_pool_buf_cfg_core0_handler,
1732 },
1733 {
1734 .procname = "n2h_empty_paged_pool_buf_core1",
1735 .data = &nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1],
1736 .maxlen = sizeof(int),
1737 .mode = 0644,
1738 .proc_handler = &nss_n2h_empty_paged_pool_buf_cfg_core1_handler,
1739 },
1740
1741 {
Saurabh Misra71034db2015-06-04 16:18:38 -07001742 .procname = "n2h_low_water_core0",
1743 .data = &nss_n2h_water_mark[NSS_CORE_0][0],
1744 .maxlen = sizeof(int),
1745 .mode = 0644,
1746 .proc_handler = &nss_n2h_water_mark_core0_handler,
1747 },
1748 {
1749 .procname = "n2h_low_water_core1",
1750 .data = &nss_n2h_water_mark[NSS_CORE_1][0],
1751 .maxlen = sizeof(int),
1752 .mode = 0644,
1753 .proc_handler = &nss_n2h_water_mark_core1_handler,
1754 },
1755 {
1756 .procname = "n2h_high_water_core0",
1757 .data = &nss_n2h_water_mark[NSS_CORE_0][1],
1758 .maxlen = sizeof(int),
1759 .mode = 0644,
1760 .proc_handler = &nss_n2h_water_mark_core0_handler,
1761 },
1762 {
1763 .procname = "n2h_high_water_core1",
1764 .data = &nss_n2h_water_mark[NSS_CORE_1][1],
1765 .maxlen = sizeof(int),
1766 .mode = 0644,
1767 .proc_handler = &nss_n2h_water_mark_core1_handler,
Vijay Dewangan488e5372014-12-29 21:40:11 -08001768 },
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301769 {
Sachin Shashidhar475012b2017-03-13 16:56:07 -07001770 .procname = "n2h_paged_low_water_core0",
1771 .data = &nss_n2h_paged_water_mark[NSS_CORE_0][0],
1772 .maxlen = sizeof(int),
1773 .mode = 0644,
1774 .proc_handler = &nss_n2h_paged_water_mark_core0_handler,
1775 },
1776 {
1777 .procname = "n2h_paged_low_water_core1",
1778 .data = &nss_n2h_paged_water_mark[NSS_CORE_1][0],
1779 .maxlen = sizeof(int),
1780 .mode = 0644,
1781 .proc_handler = &nss_n2h_paged_water_mark_core1_handler,
1782 },
1783 {
1784 .procname = "n2h_paged_high_water_core0",
1785 .data = &nss_n2h_paged_water_mark[NSS_CORE_0][1],
1786 .maxlen = sizeof(int),
1787 .mode = 0644,
1788 .proc_handler = &nss_n2h_paged_water_mark_core0_handler,
1789 },
1790 {
1791 .procname = "n2h_paged_high_water_core1",
1792 .data = &nss_n2h_paged_water_mark[NSS_CORE_1][1],
1793 .maxlen = sizeof(int),
1794 .mode = 0644,
1795 .proc_handler = &nss_n2h_paged_water_mark_core1_handler,
1796 },
1797 {
Pamidipati, Vijayee9c2972016-01-10 08:13:19 +05301798 .procname = "n2h_wifi_pool_buf",
1799 .data = &nss_n2h_wifi_pool_buf_cfg,
1800 .maxlen = sizeof(int),
1801 .mode = 0644,
1802 .proc_handler = &nss_n2h_wifi_payloads_handler,
1803 },
Stephen Wang49b474b2016-03-25 10:40:30 -07001804 {
Stephen Wang49b474b2016-03-25 10:40:30 -07001805 .procname = "mitigation_core0",
1806 .data = &nss_n2h_core0_mitigation_cfg,
1807 .maxlen = sizeof(int),
1808 .mode = 0644,
1809 .proc_handler = &nss_n2h_mitigationcfg_core0_handler,
1810 },
1811 {
1812 .procname = "mitigation_core1",
1813 .data = &nss_n2h_core1_mitigation_cfg,
1814 .maxlen = sizeof(int),
1815 .mode = 0644,
1816 .proc_handler = &nss_n2h_mitigationcfg_core1_handler,
1817 },
1818 {
1819 .procname = "extra_pbuf_core0",
1820 .data = &nss_n2h_core0_add_buf_pool_size,
1821 .maxlen = sizeof(int),
1822 .mode = 0644,
1823 .proc_handler = &nss_n2h_buf_cfg_core0_handler,
1824 },
1825 {
1826 .procname = "extra_pbuf_core1",
1827 .data = &nss_n2h_core1_add_buf_pool_size,
1828 .maxlen = sizeof(int),
1829 .mode = 0644,
1830 .proc_handler = &nss_n2h_buf_cfg_core1_handler,
1831 },
Shashank Balashankar4162f572018-08-21 13:32:34 -07001832 {
1833 .procname = "n2h_queue_limit_core0",
1834 .data = &nss_n2h_queue_limit[NSS_CORE_0],
1835 .maxlen = sizeof(int),
1836 .mode = 0644,
1837 .proc_handler = &nss_n2h_queue_limit_core0_handler,
1838 },
1839 {
1840 .procname = "n2h_queue_limit_core1",
1841 .data = &nss_n2h_queue_limit[NSS_CORE_1],
1842 .maxlen = sizeof(int),
1843 .mode = 0644,
1844 .proc_handler = &nss_n2h_queue_limit_core1_handler,
1845 },
Sakthi Vignesh Radhakrishnanf9823102019-03-05 15:38:36 -08001846 {
1847 .procname = "host_bp_enable0",
1848 .data = &nss_n2h_host_bp_config[NSS_CORE_0],
1849 .maxlen = sizeof(int),
1850 .mode = 0644,
1851 .proc_handler = &nss_n2h_host_bp_cfg_core0_handler,
1852 },
1853 {
1854 .procname = "host_bp_enable1",
1855 .data = &nss_n2h_host_bp_config[NSS_CORE_1],
1856 .maxlen = sizeof(int),
1857 .mode = 0644,
1858 .proc_handler = &nss_n2h_host_bp_cfg_core1_handler,
1859 },
Vijay Dewangan488e5372014-12-29 21:40:11 -08001860 { }
1861};
1862
Suman Ghosh9f7b3702018-09-21 19:51:40 +05301863/*
1864 * This table will be overwritten during single-core registration
1865 */
Stephen Wang52e6d342016-03-29 15:02:33 -07001866static struct ctl_table nss_n2h_dir[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001867 {
1868 .procname = "n2hcfg",
1869 .mode = 0555,
Suman Ghosh9f7b3702018-09-21 19:51:40 +05301870 .child = nss_n2h_table_multi_core,
Vijay Dewangan488e5372014-12-29 21:40:11 -08001871 },
1872 { }
1873};
1874
Stephen Wang52e6d342016-03-29 15:02:33 -07001875static struct ctl_table nss_n2h_root_dir[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001876 {
1877 .procname = "nss",
1878 .mode = 0555,
1879 .child = nss_n2h_dir,
1880 },
1881 { }
1882};
1883
Stephen Wang52e6d342016-03-29 15:02:33 -07001884static struct ctl_table nss_n2h_root[] = {
Vijay Dewangan488e5372014-12-29 21:40:11 -08001885 {
1886 .procname = "dev",
1887 .mode = 0555,
1888 .child = nss_n2h_root_dir,
1889 },
1890 { }
1891};
1892
1893static struct ctl_table_header *nss_n2h_header;
1894
1895/*
Amit Guptaca2ea682019-01-24 17:18:46 +05301896 * nss_n2h_cfg_empty_pool_size()
1897 * Config empty buffer pool
1898 */
1899nss_tx_status_t nss_n2h_cfg_empty_pool_size(struct nss_ctx_instance *nss_ctx, uint32_t pool_sz)
1900{
1901 struct nss_n2h_msg nnm;
1902 struct nss_n2h_empty_pool_buf *nnepbcm;
1903 nss_tx_status_t nss_tx_status;
1904
1905 if (pool_sz < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ) {
1906 nss_warning("%p: setting pool size %d < min number of buffer",
1907 nss_ctx, pool_sz);
1908 return NSS_TX_FAILURE;
1909 }
1910
1911 if (pool_sz > NSS_N2H_MAX_EMPTY_POOL_BUF_SZ) {
1912 nss_warning("%p: setting pool size %d > max number of buffer",
1913 nss_ctx, pool_sz);
1914 return NSS_TX_FAILURE;
1915 }
1916
1917 nss_info("%p: update number of empty buffer pool size: %d\n",
1918 nss_ctx, pool_sz);
1919
1920 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1921 NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG,
1922 sizeof(struct nss_n2h_empty_pool_buf), NULL, 0);
1923
1924 nnepbcm = &nnm.msg.empty_pool_buf_cfg;
1925 nnepbcm->pool_size = htonl(pool_sz);
1926 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1927
1928 if (nss_tx_status != NSS_TX_SUCCESS) {
1929 nss_warning("%p: nss_tx error empty buffer pool: %d\n", nss_ctx, pool_sz);
1930 return nss_tx_status;
1931 }
1932
1933 return nss_tx_status;
1934}
1935
1936/*
Amit Gupta738f97e2019-01-11 18:54:55 +05301937 * nss_n2h_paged_buf_pool_init()
1938 * Sends a command down to NSS to initialize paged buffer pool
1939 */
1940nss_tx_status_t nss_n2h_paged_buf_pool_init(struct nss_ctx_instance *nss_ctx)
1941{
1942 struct nss_n2h_msg nnm;
1943 nss_tx_status_t nss_tx_status;
1944
1945 /*
1946 * No additional information needed at this point
1947 */
1948 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1949 NSS_TX_METADATA_TYPE_N2H_PAGED_BUFFER_POOL_INIT,
1950 sizeof(struct nss_n2h_paged_buffer_pool_init),
1951 NULL,
1952 NULL);
1953
1954 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1955 if (nss_tx_status != NSS_TX_SUCCESS) {
1956 nss_warning("%p: failed to send paged buf configuration init command to NSS\n",
1957 nss_ctx);
1958 return NSS_TX_FAILURE;
1959 }
1960
1961 return NSS_TX_SUCCESS;
1962}
1963
1964/*
Stephen Wang49b474b2016-03-25 10:40:30 -07001965 * nss_n2h_flush_payloads()
Cemil Coskun9165c762017-12-04 14:35:24 -08001966 * Sends a command down to NSS for flushing all payloads
Stephen Wang49b474b2016-03-25 10:40:30 -07001967 */
1968nss_tx_status_t nss_n2h_flush_payloads(struct nss_ctx_instance *nss_ctx)
1969{
1970 struct nss_n2h_msg nnm;
1971 struct nss_n2h_flush_payloads *nnflshpl;
1972 nss_tx_status_t nss_tx_status;
1973
1974 nnflshpl = &nnm.msg.flush_payloads;
1975
1976 /*
1977 * TODO: No additional information sent in message
1978 * as of now. Need to initialize message content accordingly
1979 * if needed.
1980 */
1981 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
1982 NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS,
1983 sizeof(struct nss_n2h_flush_payloads),
1984 NULL,
1985 NULL);
1986
1987 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
1988 if (nss_tx_status != NSS_TX_SUCCESS) {
1989 nss_warning("%p: failed to send flush payloads command to NSS\n",
1990 nss_ctx);
1991
1992 return NSS_TX_FAILURE;
1993 }
1994
1995 return NSS_TX_SUCCESS;
1996}
1997
1998/*
Vijay Dewangan488e5372014-12-29 21:40:11 -08001999 * nss_n2h_msg_init()
Stephen Wang49b474b2016-03-25 10:40:30 -07002000 * Initialize n2h message.
Vijay Dewangan488e5372014-12-29 21:40:11 -08002001 */
2002void nss_n2h_msg_init(struct nss_n2h_msg *nim, uint16_t if_num, uint32_t type,
Vijay Dewangan634ce592015-01-07 17:21:09 -08002003 uint32_t len, nss_n2h_msg_callback_t cb, void *app_data)
Vijay Dewangan488e5372014-12-29 21:40:11 -08002004{
2005 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
2006}
2007
Vijay Dewangan488e5372014-12-29 21:40:11 -08002008/*
Vijay Dewangan488e5372014-12-29 21:40:11 -08002009 * nss_n2h_tx_msg()
Cemil Coskun9165c762017-12-04 14:35:24 -08002010 * Send messages to NSS n2h package.
Vijay Dewangan488e5372014-12-29 21:40:11 -08002011 */
2012nss_tx_status_t nss_n2h_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_n2h_msg *nnm)
2013{
Vijay Dewangan488e5372014-12-29 21:40:11 -08002014 struct nss_cmn_msg *ncm = &nnm->cm;
Vijay Dewangan488e5372014-12-29 21:40:11 -08002015
2016 /*
2017 * Sanity check the message
2018 */
2019 if (ncm->interface != NSS_N2H_INTERFACE) {
2020 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
2021 return NSS_TX_FAILURE;
2022 }
2023
2024 if (ncm->type >= NSS_METADATA_TYPE_N2H_MAX) {
2025 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
2026 return NSS_TX_FAILURE;
2027 }
2028
Stephen Wang3e2dbd12018-03-14 17:28:17 -07002029 return nss_core_send_cmd(nss_ctx, nnm, sizeof(*nnm), NSS_NBUF_PAYLOAD_SIZE);
Vijay Dewangan488e5372014-12-29 21:40:11 -08002030}
2031
Vijay Dewangan488e5372014-12-29 21:40:11 -08002032/*
2033 * nss_n2h_notify_register()
2034 * Register to received N2H events.
2035 *
2036 * NOTE: Do we want to pass an nss_ctx here so that we can register for n2h on any core?
2037 */
2038struct nss_ctx_instance *nss_n2h_notify_register(int core, nss_n2h_msg_callback_t cb, void *app_data)
2039{
Suman Ghosh9f7b3702018-09-21 19:51:40 +05302040 if (core >= nss_top_main.num_nss) {
Vijay Dewangan488e5372014-12-29 21:40:11 -08002041 nss_warning("Input core number %d is wrong \n", core);
2042 return NULL;
2043 }
2044 /*
2045 * TODO: We need to have a new array in support of the new API
2046 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
2047 */
2048 nss_n2h_rd[core].n2h_callback = cb;
2049 nss_n2h_rd[core].app_data = app_data;
2050 return &nss_top_main.nss[core];
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05302051}
2052
2053/*
2054 * nss_n2h_register_handler()
2055 */
Thomas Wu91f4bdf2017-06-09 12:03:02 -07002056void nss_n2h_register_handler(struct nss_ctx_instance *nss_ctx)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05302057{
ratheesh kannothab436af2017-07-20 08:51:07 +05302058 sema_init(&nss_n2h_q_cfg_pvt.sem, 1);
2059 init_completion(&nss_n2h_q_cfg_pvt.complete);
2060
Thomas Wu91f4bdf2017-06-09 12:03:02 -07002061 nss_core_register_handler(nss_ctx, NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL);
Yu Huang8c107082017-07-24 14:58:26 -07002062
Cemil Coskun26be6162019-06-28 15:44:48 -07002063 if (nss_ctx->id == NSS_CORE_0) {
2064 nss_n2h_stats_dentry_create();
2065 }
Wayne Tand5058cb2020-01-07 14:39:16 -08002066 nss_n2h_strings_dentry_create();
2067
2068 nss_drv_strings_dentry_create();
Stephen Wang49b474b2016-03-25 10:40:30 -07002069}
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -07002070
Stephen Wang49b474b2016-03-25 10:40:30 -07002071/*
Suman Ghosh9f7b3702018-09-21 19:51:40 +05302072 * nss_n2h_single_core_register_sysctl()
Stephen Wang49b474b2016-03-25 10:40:30 -07002073 */
Suman Ghosh9f7b3702018-09-21 19:51:40 +05302074void nss_n2h_single_core_register_sysctl(void)
2075{
2076 /*
2077 * RPS sema init
2078 */
2079 sema_init(&nss_n2h_rcp.sem, 1);
2080 init_completion(&nss_n2h_rcp.complete);
2081
2082 /*
2083 * MITIGATION sema init for core0
2084 */
2085 sema_init(&nss_n2h_mitigationcp[NSS_CORE_0].sem, 1);
2086 init_completion(&nss_n2h_mitigationcp[NSS_CORE_0].complete);
2087
2088 /*
2089 * PBUF addition sema init for core0
2090 */
2091 sema_init(&nss_n2h_bufcp[NSS_CORE_0].sem, 1);
2092 init_completion(&nss_n2h_bufcp[NSS_CORE_0].complete);
2093
2094 /*
2095 * Core0
2096 */
2097 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1);
2098 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete);
2099 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.pool_size =
2100 nss_n2h_empty_pool_buf_cfg[NSS_CORE_0];
2101 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.low_water =
2102 nss_n2h_water_mark[NSS_CORE_0][0];
2103 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.high_water =
2104 nss_n2h_water_mark[NSS_CORE_0][1];
2105 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.pool_size =
2106 nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0];
2107 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.low_water =
2108 nss_n2h_paged_water_mark[NSS_CORE_0][0];
2109 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.high_water =
2110 nss_n2h_paged_water_mark[NSS_CORE_0][1];
2111
2112 /*
2113 * WiFi pool buf cfg sema init
2114 */
2115 sema_init(&nss_n2h_wp.sem, 1);
2116 init_completion(&nss_n2h_wp.complete);
2117
2118 /*
2119 * N2H queue config sema init
2120 */
2121 sema_init(&nss_n2h_q_lim_pvt.sem, 1);
2122 init_completion(&nss_n2h_q_lim_pvt.complete);
2123
Sakthi Vignesh Radhakrishnanf9823102019-03-05 15:38:36 -08002124 /*
2125 * Back pressure config sema init
2126 */
2127 sema_init(&nss_n2h_host_bp_cfg_pvt.sem, 1);
2128 init_completion(&nss_n2h_host_bp_cfg_pvt.complete);
2129
Suman Ghosh9f7b3702018-09-21 19:51:40 +05302130 nss_n2h_notify_register(NSS_CORE_0, NULL, NULL);
2131
2132 /*
2133 * Register sysctl table.
2134 */
2135 nss_n2h_dir[0].child = nss_n2h_table_single_core;
2136 nss_n2h_header = register_sysctl_table(nss_n2h_root);
2137}
2138
2139/*
2140 * nss_n2h_multi_core_register_sysctl()
2141 */
2142void nss_n2h_multi_core_register_sysctl(void)
Stephen Wang49b474b2016-03-25 10:40:30 -07002143{
Vijay Dewangan634ce592015-01-07 17:21:09 -08002144 /*
2145 * RPS sema init
2146 */
2147 sema_init(&nss_n2h_rcp.sem, 1);
2148 init_completion(&nss_n2h_rcp.complete);
2149
Kalyan Tallapragadab50e8902015-08-06 17:00:54 +05302150 /*
2151 * MITIGATION sema init for core0
2152 */
2153 sema_init(&nss_n2h_mitigationcp[NSS_CORE_0].sem, 1);
2154 init_completion(&nss_n2h_mitigationcp[NSS_CORE_0].complete);
2155
2156 /*
2157 * MITIGATION sema init for core1
2158 */
2159 sema_init(&nss_n2h_mitigationcp[NSS_CORE_1].sem, 1);
2160 init_completion(&nss_n2h_mitigationcp[NSS_CORE_1].complete);
2161
2162 /*
2163 * PBUF addition sema init for core0
2164 */
2165 sema_init(&nss_n2h_bufcp[NSS_CORE_0].sem, 1);
2166 init_completion(&nss_n2h_bufcp[NSS_CORE_0].complete);
2167
2168 /*
2169 * PBUF addition sema init for core1
2170 */
2171 sema_init(&nss_n2h_bufcp[NSS_CORE_1].sem, 1);
2172 init_completion(&nss_n2h_bufcp[NSS_CORE_1].complete);
Vijay Dewangan634ce592015-01-07 17:21:09 -08002173
Stephen Wang49b474b2016-03-25 10:40:30 -07002174 /*
2175 * Core0
2176 */
2177 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1);
2178 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete);
Sachin Shashidhar475012b2017-03-13 16:56:07 -07002179 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.pool_size =
Stephen Wang49b474b2016-03-25 10:40:30 -07002180 nss_n2h_empty_pool_buf_cfg[NSS_CORE_0];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07002181 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.low_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07002182 nss_n2h_water_mark[NSS_CORE_0][0];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07002183 nss_n2h_nepbcfgp[NSS_CORE_0].empty_buf_pool_info.high_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07002184 nss_n2h_water_mark[NSS_CORE_0][1];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07002185 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.pool_size =
2186 nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_0];
2187 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.low_water =
2188 nss_n2h_paged_water_mark[NSS_CORE_0][0];
2189 nss_n2h_nepbcfgp[NSS_CORE_0].empty_paged_buf_pool_info.high_water =
2190 nss_n2h_paged_water_mark[NSS_CORE_0][1];
2191
Stephen Wang49b474b2016-03-25 10:40:30 -07002192 /*
2193 * Core1
2194 */
2195 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_1].sem, 1);
2196 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_1].complete);
Sachin Shashidhar475012b2017-03-13 16:56:07 -07002197 nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.pool_size =
Stephen Wang49b474b2016-03-25 10:40:30 -07002198 nss_n2h_empty_pool_buf_cfg[NSS_CORE_1];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07002199 nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.low_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07002200 nss_n2h_water_mark[NSS_CORE_1][0];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07002201 nss_n2h_nepbcfgp[NSS_CORE_1].empty_buf_pool_info.high_water =
Stephen Wang49b474b2016-03-25 10:40:30 -07002202 nss_n2h_water_mark[NSS_CORE_1][1];
Sachin Shashidhar475012b2017-03-13 16:56:07 -07002203 nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.pool_size =
2204 nss_n2h_empty_paged_pool_buf_cfg[NSS_CORE_1];
2205 nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.low_water =
2206 nss_n2h_paged_water_mark[NSS_CORE_1][0];
2207 nss_n2h_nepbcfgp[NSS_CORE_1].empty_paged_buf_pool_info.high_water =
2208 nss_n2h_paged_water_mark[NSS_CORE_1][1];
2209
Stephen Wang49b474b2016-03-25 10:40:30 -07002210 /*
2211 * WiFi pool buf cfg sema init
2212 */
2213 sema_init(&nss_n2h_wp.sem, 1);
2214 init_completion(&nss_n2h_wp.complete);
2215
Shashank Balashankar4162f572018-08-21 13:32:34 -07002216 /*
2217 * N2H queue config sema init
2218 */
2219 sema_init(&nss_n2h_q_lim_pvt.sem, 1);
2220 init_completion(&nss_n2h_q_lim_pvt.complete);
2221
Sakthi Vignesh Radhakrishnanf9823102019-03-05 15:38:36 -08002222 /*
2223 * Back pressure config sema init
2224 */
2225 sema_init(&nss_n2h_host_bp_cfg_pvt.sem, 1);
2226 init_completion(&nss_n2h_host_bp_cfg_pvt.complete);
2227
Vijay Dewangan488e5372014-12-29 21:40:11 -08002228 nss_n2h_notify_register(NSS_CORE_0, NULL, NULL);
2229 nss_n2h_notify_register(NSS_CORE_1, NULL, NULL);
2230
Stephen Wang49b474b2016-03-25 10:40:30 -07002231 /*
2232 * Register sysctl table.
2233 */
2234 nss_n2h_header = register_sysctl_table(nss_n2h_root);
2235}
2236
2237/*
2238 * nss_n2h_unregister_sysctl()
2239 * Unregister sysctl specific to n2h
2240 */
2241void nss_n2h_unregister_sysctl(void)
2242{
2243 /*
2244 * Unregister sysctl table.
2245 */
2246 if (nss_n2h_header) {
2247 unregister_sysctl_table(nss_n2h_header);
2248 }
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05302249}
Vijay Dewangan488e5372014-12-29 21:40:11 -08002250
2251EXPORT_SYMBOL(nss_n2h_notify_register);