blob: f28a7858c6298ee0cc129aec9ba56651d649787e [file] [log] [blame]
Abhishek Rastogi84d95d02014-03-26 19:31:31 +05301/*
2 **************************************************************************
Vijay Dewangan488e5372014-12-29 21:40:11 -08003 * Copyright (c) 2013-2015, 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
Vijay Dewangan488e5372014-12-29 21:40:11 -080024#define NSS_CORE_0 0
25#define NSS_CORE_1 1
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053026
27/*
Vijay Dewangan488e5372014-12-29 21:40:11 -080028 * This number is chosen becuase currently default IPV4 + IPV6
29 * connection size is 1024 + 1024 = 2048.
30 * FYI: However this doesnt have any impact on n2h/ipv6 connections
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053031 */
Vijay Dewangan488e5372014-12-29 21:40:11 -080032#define NSS_N2H_MIN_EMPTY_POOL_BUF_SZ 2048
33#define NSS_N2H_DEFAULT_EMPTY_POOL_BUF_SZ 8192
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053034
Vijay Dewangan488e5372014-12-29 21:40:11 -080035int nss_n2h_empty_pool_buf_cfg[NSS_MAX_CORES] __read_mostly = {NSS_N2H_DEFAULT_EMPTY_POOL_BUF_SZ, NSS_N2H_DEFAULT_EMPTY_POOL_BUF_SZ};
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053036
Vijay Dewangan488e5372014-12-29 21:40:11 -080037struct nss_n2h_registered_data {
38 nss_n2h_msg_callback_t n2h_callback;
39 void *app_data;
40};
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053041
Vijay Dewangan488e5372014-12-29 21:40:11 -080042static struct nss_n2h_cfg_pvt nss_n2h_nepbcfgp[NSS_MAX_CORES];
43static struct nss_n2h_registered_data nss_n2h_rd[NSS_MAX_CORES];
Vijay Dewangan634ce592015-01-07 17:21:09 -080044static struct nss_n2h_cfg_pvt nss_n2h_rcp;
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +053045
46/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070047 * nss_n2h_stats_sync()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053048 * Handle the syncing of NSS statistics.
49 */
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -070050static void nss_n2h_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_n2h_stats_sync *nnss)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053051{
52 struct nss_top_instance *nss_top = nss_ctx->nss_top;
53
54 spin_lock_bh(&nss_top->stats_lock);
55
56 /*
57 * common node stats
58 */
59 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_PKTS] += nnss->node_stats.rx_packets;
60 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_BYTES] += nnss->node_stats.rx_bytes;
61 nss_ctx->stats_n2h[NSS_STATS_NODE_RX_DROPPED] += nnss->node_stats.rx_dropped;
62 nss_ctx->stats_n2h[NSS_STATS_NODE_TX_PKTS] += nnss->node_stats.tx_packets;
63 nss_ctx->stats_n2h[NSS_STATS_NODE_TX_BYTES] += nnss->node_stats.tx_bytes;
64
65 /*
66 * General N2H stats
67 */
Murat Sezgin0c0561d2014-04-09 18:55:58 -070068 nss_ctx->stats_n2h[NSS_STATS_N2H_QUEUE_DROPPED] += nnss->queue_dropped;
69 nss_ctx->stats_n2h[NSS_STATS_N2H_TOTAL_TICKS] += nnss->total_ticks;
70 nss_ctx->stats_n2h[NSS_STATS_N2H_WORST_CASE_TICKS] += nnss->worst_case_ticks;
71 nss_ctx->stats_n2h[NSS_STATS_N2H_ITERATIONS] += nnss->iterations;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053072
73 /*
Thomas Wu3fd8dd72014-06-11 15:57:05 -070074 * pbuf manager ocm and default pool stats
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053075 */
Thomas Wu3fd8dd72014-06-11 15:57:05 -070076 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_ALLOC_FAILS] += nnss->pbuf_ocm_stats.pbuf_alloc_fails;
77 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_FREE_COUNT] = nnss->pbuf_ocm_stats.pbuf_free_count;
78 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_OCM_TOTAL_COUNT] = nnss->pbuf_ocm_stats.pbuf_total_count;
79
80 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_ALLOC_FAILS] += nnss->pbuf_default_stats.pbuf_alloc_fails;
81 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_FREE_COUNT] = nnss->pbuf_default_stats.pbuf_free_count;
82 nss_ctx->stats_n2h[NSS_STATS_N2H_PBUF_DEFAULT_TOTAL_COUNT] = nnss->pbuf_default_stats.pbuf_total_count;
83
84 /*
85 * payload mgr stats
86 */
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053087 nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_ALLOC_FAILS] += nnss->payload_alloc_fails;
Thomas Wu53679842015-01-22 13:37:35 -080088 nss_ctx->stats_n2h[NSS_STATS_N2H_PAYLOAD_FREE_COUNT] = nnss->payload_free_count;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +053089
Sakthi Vignesh Radhakrishnan2a8ee962014-11-22 13:35:38 -080090 /*
91 * Host <=> NSS control traffic stats
92 */
93 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_PACKETS] += nnss->h2n_ctrl_pkts;
94 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_CONTROL_BYTES] += nnss->h2n_ctrl_bytes;
95 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_PACKETS] += nnss->n2h_ctrl_pkts;
96 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_CONTROL_BYTES] += nnss->n2h_ctrl_bytes;
97
98 /*
99 * Host <=> NSS control data traffic stats
100 */
101 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_PACKETS] += nnss->h2n_data_pkts;
102 nss_ctx->stats_n2h[NSS_STATS_N2H_H2N_DATA_BYTES] += nnss->h2n_data_bytes;
103 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_PACKETS] += nnss->n2h_data_pkts;
104 nss_ctx->stats_n2h[NSS_STATS_N2H_N2H_DATA_BYTES] += nnss->n2h_data_bytes;
105
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530106 spin_unlock_bh(&nss_top->stats_lock);
107}
108
109/*
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700110 * nss_n2h_interface_handler()
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530111 * Handle NSS -> HLOS messages for N2H node
112 */
Vijay Dewangan634ce592015-01-07 17:21:09 -0800113static void nss_n2h_interface_handler(struct nss_ctx_instance *nss_ctx,
114 struct nss_cmn_msg *ncm,
115 __attribute__((unused))void *app_data)
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530116{
117 struct nss_n2h_msg *nnm = (struct nss_n2h_msg *)ncm;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800118 nss_n2h_msg_callback_t cb;
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530119
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700120 BUG_ON(ncm->interface != NSS_N2H_INTERFACE);
121
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530122 /*
123 * Is this a valid request/response packet?
124 */
125 if (nnm->cm.type >= NSS_METADATA_TYPE_N2H_MAX) {
126 nss_warning("%p: received invalid message %d for Offload stats interface", nss_ctx, nnm->cm.type);
127 return;
128 }
129
130 switch (nnm->cm.type) {
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530131 case NSS_TX_METADATA_TYPE_N2H_RPS_CFG:
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530132 nss_info("NSS N2H rps_en %d \n",nnm->msg.rps_cfg.enable);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800133 break;
134
135 case NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG:
136 nss_info("%p: empty pool buf cfg response from FW", nss_ctx);
Pamidipati, Vijayefcc4692014-05-09 14:47:38 +0530137 break;
138
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +0530139 case NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS:
140 nss_info("%p: flush payloads cmd response from FW", nss_ctx);
141 break;
142
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530143 case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC:
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700144 nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530145 break;
146
147 default:
148 if (ncm->response != NSS_CMN_RESPONSE_ACK) {
149 /*
150 * Check response
151 */
152 nss_info("%p: Received response %d for type %d, interface %d",
153 nss_ctx, ncm->response, ncm->type, ncm->interface);
154 }
155 }
Vijay Dewangan488e5372014-12-29 21:40:11 -0800156
157 /*
158 * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
159 * to the same callback/app_data.
160 */
161 if (nnm->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
162 /*
163 * Place holder for the user to create right call
164 * back and app data when response is NSS_CMM_RESPONSE_NOTIFY
165 */
166 ncm->cb = (uint32_t)nss_n2h_rd[nss_ctx->id].n2h_callback;
167 ncm->app_data = (uint32_t)nss_n2h_rd[nss_ctx->id].app_data;
168 }
169
170 /*
171 * Do we have a callback?
172 */
173 if (!ncm->cb) {
174 return;
175 }
176
177 /*
178 * Callback
179 */
180 cb = (nss_n2h_msg_callback_t)ncm->cb;
181 cb((void *)ncm->app_data, nnm);
182}
183
184/*
Vijay Dewangan634ce592015-01-07 17:21:09 -0800185 * nss_n2h_rps_cfg_callback()
186 * call back function for rps configuration
187 */
188static void nss_n2h_rps_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
189{
190 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)app_data;
191 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
192
193 /*
194 * Error, hence we are not updating the nss_n2h_empty_pool_buf
195 * Restore the current_value to its previous state
196 */
197 nss_n2h_rcp.response = NSS_FAILURE;
198 complete(&nss_n2h_rcp.complete);
199 nss_warning("%p: RPS configuration failed : %d\n", nss_ctx,
200 nnm->cm.error);
201 return;
202 }
203
204 nss_info("%p: RPS configuration succeeded: %d\n", nss_ctx,
205 nnm->cm.error);
206 nss_ctx->n2h_rps_en = nnm->msg.rps_cfg.enable;
207 nss_n2h_rcp.response = NSS_SUCCESS;
208 complete(&nss_n2h_rcp.complete);
209}
210
211/*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800212 * nss_n2h_empty_pool_buf_cfg_core1_callback()
213 * call back function for the n2h connection configuration handler
214 */
215static void nss_n2h_empty_pool_buf_cfg_callback(void *app_data,
216 struct nss_n2h_msg *nnm)
217{
218 int core_num = (int)app_data;
219 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
220 struct nss_n2h_empty_pool_buf *nnepbcm;
221 nnepbcm = &nnm->msg.empty_pool_buf_cfg;
222
223 /*
224 * Error, hence we are not updating the nss_n2h_empty_pool_buf
225 * Restore the current_value to its previous state
226 */
227 nss_warning("Core %d empty pool buf set failure: %d\n", core_num, nnm->cm.error);
228 nss_n2h_nepbcfgp[core_num].response = NSS_FAILURE;
229 complete(&nss_n2h_nepbcfgp[core_num].complete);
230 return;
231 }
232
233 /*
234 * Sucess at NSS FW, hence updating nss_n2h_empty_pool_buf, with the valid value
235 * saved at the sysctl handler.
236 */
237 nss_info("Core %d empty pool buf set success: %d\n", core_num, nnm->cm.error);
238 nss_n2h_nepbcfgp[core_num].response = NSS_SUCCESS;
239 complete(&nss_n2h_nepbcfgp[core_num].complete);
240}
241
242/*
243 * nss_n2h_empty_pool_buf_core1_handler()
244 * Sets the number of connections for IPv4
245 */
246static int nss_n2h_set_empty_pool_buf(ctl_table *ctl, int write, void __user *buffer,
247 size_t *lenp, loff_t *ppos,
248 int core_num, int *new_val)
249{
250 struct nss_top_instance *nss_top = &nss_top_main;
251 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
252 struct nss_n2h_msg nnm;
253 struct nss_n2h_empty_pool_buf *nnepbcm;
254 nss_tx_status_t nss_tx_status;
255 int ret = NSS_FAILURE;
256
257 /*
258 * Acquiring semaphore
259 */
260 down(&nss_n2h_nepbcfgp[core_num].sem);
261
262 /*
263 * Take snap shot of current value
264 */
265 nss_n2h_nepbcfgp[core_num].current_value = *new_val;
266
267 /*
268 * Write the variable with user input
269 */
270 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
271 if (ret || (!write)) {
272 up(&nss_n2h_nepbcfgp[core_num].sem);
273 return ret;
274 }
275
276 /*
277 * Input for n2h should be atleast 2048 to support defalt connections
278 * of 1024 (IPV4) + 1024 (IPV6) connections.
279 */
280 if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
281 nss_warning("%p: core %d setting %d is less than minimum number of buffer",
282 nss_ctx, core_num, *new_val);
283
284 /*
285 * Restore the current_value to its previous state
286 */
287 *new_val = nss_n2h_nepbcfgp[core_num].current_value;
288 up(&nss_n2h_nepbcfgp[core_num].sem);
289 return NSS_FAILURE;
290 }
291
292 nss_info("%p: core %d number of empty pool buffer is : %d\n",
293 nss_ctx, core_num, *new_val);
294
295 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
296 NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG,
297 sizeof(struct nss_n2h_empty_pool_buf),
Vijay Dewangan634ce592015-01-07 17:21:09 -0800298 nss_n2h_empty_pool_buf_cfg_callback,
Vijay Dewangan488e5372014-12-29 21:40:11 -0800299 (void *)core_num);
300
301 nnepbcm = &nnm.msg.empty_pool_buf_cfg;
302 nnepbcm->pool_size = htonl(*new_val);
303 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
304
305 if (nss_tx_status != NSS_TX_SUCCESS) {
306 nss_warning("%p: core %d nss_tx error setting empty pool buffer: %d\n",
307 nss_ctx, core_num, *new_val);
308
309 /*
310 * Restore the current_value to its previous state
311 */
312 *new_val = nss_n2h_nepbcfgp[core_num].current_value;
313 up(&nss_n2h_nepbcfgp[core_num].sem);
314 return NSS_FAILURE;
315 }
316
317 /*
318 * Blocking call, wait till we get ACK for this msg.
319 */
320 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
321 if (ret == 0) {
322 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, core_num);
323
324 /*
325 * Restore the current_value to its previous state
326 */
327 *new_val = nss_n2h_nepbcfgp[core_num].current_value;
328 up(&nss_n2h_nepbcfgp[core_num].sem);
329 return NSS_FAILURE;
330 }
331
332 /*
333 * ACK/NACK received from NSS FW
334 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
335 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
336 */
337 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
338
339 /*
340 * Restore the current_value to its previous state
341 */
342 *new_val = nss_n2h_nepbcfgp[core_num].current_value;
343 up(&nss_n2h_nepbcfgp[core_num].sem);
344 return NSS_FAILURE;
345 }
346
347 up(&nss_n2h_nepbcfgp[core_num].sem);
348 return NSS_SUCCESS;
349}
350
351/*
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +0530352 * nss_n2h_flush_payloads()
353 * Sends a command down to NSS for flushing all payloads
354 */
355nss_tx_status_t nss_n2h_flush_payloads(struct nss_ctx_instance *nss_ctx)
356{
357 struct nss_n2h_msg nnm;
358 struct nss_n2h_flush_payloads *nnflshpl;
359 nss_tx_status_t nss_tx_status;
360
361 nnflshpl = &nnm.msg.flush_payloads;
362
363 /*
364 * TODO: No additional information sent in message
365 * as of now. Need to initialize message content accordingly
366 * if needed.
367 */
368 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
369 NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS,
370 sizeof(struct nss_n2h_flush_payloads),
371 NULL,
372 NULL);
373
374 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
375 if (nss_tx_status != NSS_TX_SUCCESS) {
376 nss_warning("%p: failed to send flush payloads command to NSS\n",
377 nss_ctx);
378
379 return NSS_TX_FAILURE;
380 }
381
382 return NSS_TX_SUCCESS;
383}
384
385/*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800386 * nss_n2h_empty_pool_buf_core1_handler()
387 * Sets the number of empty buffer for core 1
388 */
389static int nss_n2h_empty_pool_buf_cfg_core1_handler(ctl_table *ctl,
390 int write, void __user *buffer,
391 size_t *lenp, loff_t *ppos)
392{
393 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
394 NSS_CORE_1, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]);
395}
396
397/*
398 * nss_n2h_empty_pool_buf_core0_handler()
399 * Sets the number of empty buffer for core 0
400 */
401static int nss_n2h_empty_pool_buf_cfg_core0_handler(ctl_table *ctl,
402 int write, void __user *buffer,
403 size_t *lenp, loff_t *ppos)
404{
405 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
406 NSS_CORE_0, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]);
407}
408
Vijay Dewangan634ce592015-01-07 17:21:09 -0800409/*
410 * nss_n2h_rps_cfg()
411 * Send Message to NSS to enable RPS.
412 */
413nss_tx_status_t nss_n2h_rps_cfg(struct nss_ctx_instance *nss_ctx, int enable_rps)
414{
415 struct nss_n2h_msg nnm;
416 struct nss_n2h_rps *rps_cfg;
417 nss_tx_status_t nss_tx_status;
418 int ret;
419
420 down(&nss_n2h_rcp.sem);
421 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_RPS_CFG,
422 sizeof(struct nss_n2h_rps),
423 nss_n2h_rps_cfg_callback,
424 (void *)nss_ctx);
425
426 rps_cfg = &nnm.msg.rps_cfg;
427 rps_cfg->enable = enable_rps;
428
429 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
430
431 if (nss_tx_status != NSS_TX_SUCCESS) {
432 nss_warning("%p: nss_tx error setting rps\n", nss_ctx);
433
434 up(&nss_n2h_rcp.sem);
435 return NSS_FAILURE;
436 }
437
438 /*
439 * Blocking call, wait till we get ACK for this msg.
440 */
441 ret = wait_for_completion_timeout(&nss_n2h_rcp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
442 if (ret == 0) {
443 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
444 up(&nss_n2h_rcp.sem);
445 return NSS_FAILURE;
446 }
447
448 /*
449 * ACK/NACK received from NSS FW
450 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
451 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
452 */
453 if (NSS_FAILURE == nss_n2h_rcp.response) {
454 up(&nss_n2h_rcp.sem);
455 return NSS_FAILURE;
456 }
457
458 up(&nss_n2h_rcp.sem);
459 return NSS_SUCCESS;
460}
461
Vijay Dewangan488e5372014-12-29 21:40:11 -0800462static ctl_table nss_n2h_table[] = {
463 {
464 .procname = "n2h_empty_pool_buf_core0",
465 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0],
466 .maxlen = sizeof(int),
467 .mode = 0644,
468 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler,
469 },
470 {
471 .procname = "n2h_empty_pool_buf_core1",
472 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1],
473 .maxlen = sizeof(int),
474 .mode = 0644,
475 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core1_handler,
476 },
477
478 { }
479};
480
481static ctl_table nss_n2h_dir[] = {
482 {
483 .procname = "n2hcfg",
484 .mode = 0555,
485 .child = nss_n2h_table,
486 },
487 { }
488};
489
490
491static ctl_table nss_n2h_root_dir[] = {
492 {
493 .procname = "nss",
494 .mode = 0555,
495 .child = nss_n2h_dir,
496 },
497 { }
498};
499
500static ctl_table nss_n2h_root[] = {
501 {
502 .procname = "dev",
503 .mode = 0555,
504 .child = nss_n2h_root_dir,
505 },
506 { }
507};
508
509static struct ctl_table_header *nss_n2h_header;
510
511/*
512 * nss_n2h_msg_init()
513 * Initialize IPv4 message.
514 */
515void nss_n2h_msg_init(struct nss_n2h_msg *nim, uint16_t if_num, uint32_t type,
Vijay Dewangan634ce592015-01-07 17:21:09 -0800516 uint32_t len, nss_n2h_msg_callback_t cb, void *app_data)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800517{
518 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
519}
520
Vijay Dewangan488e5372014-12-29 21:40:11 -0800521/*
522 * nss_n2h_register_sysctl()
523 * Register sysctl specific to n2h
524 */
525void nss_n2h_empty_pool_buf_register_sysctl(void)
526{
527 /*
528 * Register sysctl table.
529 */
530 nss_n2h_header = register_sysctl_table(nss_n2h_root);
531
532 /*
533 * Core0
534 */
535 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1);
536 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete);
537 nss_n2h_nepbcfgp[NSS_CORE_0].current_value = nss_n2h_empty_pool_buf_cfg[NSS_CORE_0];
538
539 /*
540 * Core1
541 */
542 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_1].sem, 1);
543 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_1].complete);
544 nss_n2h_nepbcfgp[NSS_CORE_1].current_value = nss_n2h_empty_pool_buf_cfg[NSS_CORE_1];
545}
546
547/*
548 * nss_n2h_unregister_sysctl()
549 * Unregister sysctl specific to n2h
550 */
551void nss_n2h_empty_pool_buf_unregister_sysctl(void)
552{
553 /*
554 * Unregister sysctl table.
555 */
556 if (nss_n2h_header) {
557 unregister_sysctl_table(nss_n2h_header);
558 }
559}
560
561/*
562 * nss_n2h_tx_msg()
563 * Send messages to NSS n2h pacakge
564 */
565nss_tx_status_t nss_n2h_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_n2h_msg *nnm)
566{
567 struct nss_n2h_msg *nnm2;
568 struct nss_cmn_msg *ncm = &nnm->cm;
569 struct sk_buff *nbuf;
570 nss_tx_status_t status;
571
572 NSS_VERIFY_CTX_MAGIC(nss_ctx);
573 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
574 return NSS_TX_FAILURE_NOT_READY;
575 }
576
577 /*
578 * Sanity check the message
579 */
580 if (ncm->interface != NSS_N2H_INTERFACE) {
581 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
582 return NSS_TX_FAILURE;
583 }
584
585 if (ncm->type >= NSS_METADATA_TYPE_N2H_MAX) {
586 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
587 return NSS_TX_FAILURE;
588 }
589
590 if (ncm->len > sizeof(struct nss_n2h_msg)) {
591 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
592 return NSS_TX_FAILURE;
593 }
594
595
596 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
597 if (unlikely(!nbuf)) {
598 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
599 nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
600 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
601 return NSS_TX_FAILURE;
602 }
603
604 /*
605 * Copy the message to our skb.
606 */
607 nnm2 = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg));
608 memcpy(nnm2, nnm, sizeof(struct nss_n2h_msg));
609 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
610 if (status != NSS_CORE_STATUS_SUCCESS) {
611 dev_kfree_skb_any(nbuf);
612 nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx);
613 return NSS_TX_FAILURE;
614 }
615
616 nss_hal_send_interrupt(nss_ctx->nmap,
617 nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
618 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
619 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
620 return NSS_TX_SUCCESS;
621}
622
Vijay Dewangan488e5372014-12-29 21:40:11 -0800623/*
624 * nss_n2h_notify_register()
625 * Register to received N2H events.
626 *
627 * NOTE: Do we want to pass an nss_ctx here so that we can register for n2h on any core?
628 */
629struct nss_ctx_instance *nss_n2h_notify_register(int core, nss_n2h_msg_callback_t cb, void *app_data)
630{
631 if (core >= NSS_MAX_CORES) {
632 nss_warning("Input core number %d is wrong \n", core);
633 return NULL;
634 }
635 /*
636 * TODO: We need to have a new array in support of the new API
637 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
638 */
639 nss_n2h_rd[core].n2h_callback = cb;
640 nss_n2h_rd[core].app_data = app_data;
641 return &nss_top_main.nss[core];
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530642}
643
644/*
645 * nss_n2h_register_handler()
646 */
647void nss_n2h_register_handler()
648{
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700649 nss_core_register_handler(NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL);
650
Vijay Dewangan634ce592015-01-07 17:21:09 -0800651 /*
652 * RPS sema init
653 */
654 sema_init(&nss_n2h_rcp.sem, 1);
655 init_completion(&nss_n2h_rcp.complete);
656
657
Vijay Dewangan488e5372014-12-29 21:40:11 -0800658 nss_n2h_notify_register(NSS_CORE_0, NULL, NULL);
659 nss_n2h_notify_register(NSS_CORE_1, NULL, NULL);
660
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530661}
Vijay Dewangan488e5372014-12-29 21:40:11 -0800662
663EXPORT_SYMBOL(nss_n2h_notify_register);
Vijay Dewanganac7efc42015-02-09 16:04:53 -0800664EXPORT_SYMBOL(nss_n2h_empty_pool_buf_register_sysctl);