blob: 667915e9037a07b253a7c74ad6368e4b68423d80 [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
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530139 case NSS_RX_METADATA_TYPE_N2H_STATS_SYNC:
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700140 nss_n2h_stats_sync(nss_ctx, &nnm->msg.stats_sync);
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530141 break;
142
143 default:
144 if (ncm->response != NSS_CMN_RESPONSE_ACK) {
145 /*
146 * Check response
147 */
148 nss_info("%p: Received response %d for type %d, interface %d",
149 nss_ctx, ncm->response, ncm->type, ncm->interface);
150 }
151 }
Vijay Dewangan488e5372014-12-29 21:40:11 -0800152
153 /*
154 * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
155 * to the same callback/app_data.
156 */
157 if (nnm->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
158 /*
159 * Place holder for the user to create right call
160 * back and app data when response is NSS_CMM_RESPONSE_NOTIFY
161 */
162 ncm->cb = (uint32_t)nss_n2h_rd[nss_ctx->id].n2h_callback;
163 ncm->app_data = (uint32_t)nss_n2h_rd[nss_ctx->id].app_data;
164 }
165
166 /*
167 * Do we have a callback?
168 */
169 if (!ncm->cb) {
170 return;
171 }
172
173 /*
174 * Callback
175 */
176 cb = (nss_n2h_msg_callback_t)ncm->cb;
177 cb((void *)ncm->app_data, nnm);
178}
179
180/*
Vijay Dewangan634ce592015-01-07 17:21:09 -0800181 * nss_n2h_rps_cfg_callback()
182 * call back function for rps configuration
183 */
184static void nss_n2h_rps_cfg_callback(void *app_data, struct nss_n2h_msg *nnm)
185{
186 struct nss_ctx_instance *nss_ctx = (struct nss_ctx_instance *)app_data;
187 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
188
189 /*
190 * Error, hence we are not updating the nss_n2h_empty_pool_buf
191 * Restore the current_value to its previous state
192 */
193 nss_n2h_rcp.response = NSS_FAILURE;
194 complete(&nss_n2h_rcp.complete);
195 nss_warning("%p: RPS configuration failed : %d\n", nss_ctx,
196 nnm->cm.error);
197 return;
198 }
199
200 nss_info("%p: RPS configuration succeeded: %d\n", nss_ctx,
201 nnm->cm.error);
202 nss_ctx->n2h_rps_en = nnm->msg.rps_cfg.enable;
203 nss_n2h_rcp.response = NSS_SUCCESS;
204 complete(&nss_n2h_rcp.complete);
205}
206
207/*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800208 * nss_n2h_empty_pool_buf_cfg_core1_callback()
209 * call back function for the n2h connection configuration handler
210 */
211static void nss_n2h_empty_pool_buf_cfg_callback(void *app_data,
212 struct nss_n2h_msg *nnm)
213{
214 int core_num = (int)app_data;
215 if (nnm->cm.response != NSS_CMN_RESPONSE_ACK) {
216 struct nss_n2h_empty_pool_buf *nnepbcm;
217 nnepbcm = &nnm->msg.empty_pool_buf_cfg;
218
219 /*
220 * Error, hence we are not updating the nss_n2h_empty_pool_buf
221 * Restore the current_value to its previous state
222 */
223 nss_warning("Core %d empty pool buf set failure: %d\n", core_num, nnm->cm.error);
224 nss_n2h_nepbcfgp[core_num].response = NSS_FAILURE;
225 complete(&nss_n2h_nepbcfgp[core_num].complete);
226 return;
227 }
228
229 /*
230 * Sucess at NSS FW, hence updating nss_n2h_empty_pool_buf, with the valid value
231 * saved at the sysctl handler.
232 */
233 nss_info("Core %d empty pool buf set success: %d\n", core_num, nnm->cm.error);
234 nss_n2h_nepbcfgp[core_num].response = NSS_SUCCESS;
235 complete(&nss_n2h_nepbcfgp[core_num].complete);
236}
237
238/*
239 * nss_n2h_empty_pool_buf_core1_handler()
240 * Sets the number of connections for IPv4
241 */
242static int nss_n2h_set_empty_pool_buf(ctl_table *ctl, int write, void __user *buffer,
243 size_t *lenp, loff_t *ppos,
244 int core_num, int *new_val)
245{
246 struct nss_top_instance *nss_top = &nss_top_main;
247 struct nss_ctx_instance *nss_ctx = &nss_top->nss[core_num];
248 struct nss_n2h_msg nnm;
249 struct nss_n2h_empty_pool_buf *nnepbcm;
250 nss_tx_status_t nss_tx_status;
251 int ret = NSS_FAILURE;
252
253 /*
254 * Acquiring semaphore
255 */
256 down(&nss_n2h_nepbcfgp[core_num].sem);
257
258 /*
259 * Take snap shot of current value
260 */
261 nss_n2h_nepbcfgp[core_num].current_value = *new_val;
262
263 /*
264 * Write the variable with user input
265 */
266 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
267 if (ret || (!write)) {
268 up(&nss_n2h_nepbcfgp[core_num].sem);
269 return ret;
270 }
271
272 /*
273 * Input for n2h should be atleast 2048 to support defalt connections
274 * of 1024 (IPV4) + 1024 (IPV6) connections.
275 */
276 if ((*new_val < NSS_N2H_MIN_EMPTY_POOL_BUF_SZ)) {
277 nss_warning("%p: core %d setting %d is less than minimum number of buffer",
278 nss_ctx, core_num, *new_val);
279
280 /*
281 * Restore the current_value to its previous state
282 */
283 *new_val = nss_n2h_nepbcfgp[core_num].current_value;
284 up(&nss_n2h_nepbcfgp[core_num].sem);
285 return NSS_FAILURE;
286 }
287
288 nss_info("%p: core %d number of empty pool buffer is : %d\n",
289 nss_ctx, core_num, *new_val);
290
291 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
292 NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG,
293 sizeof(struct nss_n2h_empty_pool_buf),
Vijay Dewangan634ce592015-01-07 17:21:09 -0800294 nss_n2h_empty_pool_buf_cfg_callback,
Vijay Dewangan488e5372014-12-29 21:40:11 -0800295 (void *)core_num);
296
297 nnepbcm = &nnm.msg.empty_pool_buf_cfg;
298 nnepbcm->pool_size = htonl(*new_val);
299 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
300
301 if (nss_tx_status != NSS_TX_SUCCESS) {
302 nss_warning("%p: core %d nss_tx error setting empty pool buffer: %d\n",
303 nss_ctx, core_num, *new_val);
304
305 /*
306 * Restore the current_value to its previous state
307 */
308 *new_val = nss_n2h_nepbcfgp[core_num].current_value;
309 up(&nss_n2h_nepbcfgp[core_num].sem);
310 return NSS_FAILURE;
311 }
312
313 /*
314 * Blocking call, wait till we get ACK for this msg.
315 */
316 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
317 if (ret == 0) {
318 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, core_num);
319
320 /*
321 * Restore the current_value to its previous state
322 */
323 *new_val = nss_n2h_nepbcfgp[core_num].current_value;
324 up(&nss_n2h_nepbcfgp[core_num].sem);
325 return NSS_FAILURE;
326 }
327
328 /*
329 * ACK/NACK received from NSS FW
330 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
331 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
332 */
333 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
334
335 /*
336 * Restore the current_value to its previous state
337 */
338 *new_val = nss_n2h_nepbcfgp[core_num].current_value;
339 up(&nss_n2h_nepbcfgp[core_num].sem);
340 return NSS_FAILURE;
341 }
342
343 up(&nss_n2h_nepbcfgp[core_num].sem);
344 return NSS_SUCCESS;
345}
346
347/*
348 * nss_n2h_empty_pool_buf_core1_handler()
349 * Sets the number of empty buffer for core 1
350 */
351static int nss_n2h_empty_pool_buf_cfg_core1_handler(ctl_table *ctl,
352 int write, void __user *buffer,
353 size_t *lenp, loff_t *ppos)
354{
355 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
356 NSS_CORE_1, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]);
357}
358
359/*
360 * nss_n2h_empty_pool_buf_core0_handler()
361 * Sets the number of empty buffer for core 0
362 */
363static int nss_n2h_empty_pool_buf_cfg_core0_handler(ctl_table *ctl,
364 int write, void __user *buffer,
365 size_t *lenp, loff_t *ppos)
366{
367 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
368 NSS_CORE_0, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]);
369}
370
Vijay Dewangan634ce592015-01-07 17:21:09 -0800371/*
372 * nss_n2h_rps_cfg()
373 * Send Message to NSS to enable RPS.
374 */
375nss_tx_status_t nss_n2h_rps_cfg(struct nss_ctx_instance *nss_ctx, int enable_rps)
376{
377 struct nss_n2h_msg nnm;
378 struct nss_n2h_rps *rps_cfg;
379 nss_tx_status_t nss_tx_status;
380 int ret;
381
382 down(&nss_n2h_rcp.sem);
383 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_RPS_CFG,
384 sizeof(struct nss_n2h_rps),
385 nss_n2h_rps_cfg_callback,
386 (void *)nss_ctx);
387
388 rps_cfg = &nnm.msg.rps_cfg;
389 rps_cfg->enable = enable_rps;
390
391 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
392
393 if (nss_tx_status != NSS_TX_SUCCESS) {
394 nss_warning("%p: nss_tx error setting rps\n", nss_ctx);
395
396 up(&nss_n2h_rcp.sem);
397 return NSS_FAILURE;
398 }
399
400 /*
401 * Blocking call, wait till we get ACK for this msg.
402 */
403 ret = wait_for_completion_timeout(&nss_n2h_rcp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
404 if (ret == 0) {
405 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
406 up(&nss_n2h_rcp.sem);
407 return NSS_FAILURE;
408 }
409
410 /*
411 * ACK/NACK received from NSS FW
412 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
413 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
414 */
415 if (NSS_FAILURE == nss_n2h_rcp.response) {
416 up(&nss_n2h_rcp.sem);
417 return NSS_FAILURE;
418 }
419
420 up(&nss_n2h_rcp.sem);
421 return NSS_SUCCESS;
422}
423
Vijay Dewangan488e5372014-12-29 21:40:11 -0800424static ctl_table nss_n2h_table[] = {
425 {
426 .procname = "n2h_empty_pool_buf_core0",
427 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0],
428 .maxlen = sizeof(int),
429 .mode = 0644,
430 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler,
431 },
432 {
433 .procname = "n2h_empty_pool_buf_core1",
434 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1],
435 .maxlen = sizeof(int),
436 .mode = 0644,
437 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core1_handler,
438 },
439
440 { }
441};
442
443static ctl_table nss_n2h_dir[] = {
444 {
445 .procname = "n2hcfg",
446 .mode = 0555,
447 .child = nss_n2h_table,
448 },
449 { }
450};
451
452
453static ctl_table nss_n2h_root_dir[] = {
454 {
455 .procname = "nss",
456 .mode = 0555,
457 .child = nss_n2h_dir,
458 },
459 { }
460};
461
462static ctl_table nss_n2h_root[] = {
463 {
464 .procname = "dev",
465 .mode = 0555,
466 .child = nss_n2h_root_dir,
467 },
468 { }
469};
470
471static struct ctl_table_header *nss_n2h_header;
472
473/*
474 * nss_n2h_msg_init()
475 * Initialize IPv4 message.
476 */
477void nss_n2h_msg_init(struct nss_n2h_msg *nim, uint16_t if_num, uint32_t type,
Vijay Dewangan634ce592015-01-07 17:21:09 -0800478 uint32_t len, nss_n2h_msg_callback_t cb, void *app_data)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800479{
480 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
481}
482
Vijay Dewangan488e5372014-12-29 21:40:11 -0800483/*
484 * nss_n2h_register_sysctl()
485 * Register sysctl specific to n2h
486 */
487void nss_n2h_empty_pool_buf_register_sysctl(void)
488{
489 /*
490 * Register sysctl table.
491 */
492 nss_n2h_header = register_sysctl_table(nss_n2h_root);
493
494 /*
495 * Core0
496 */
497 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1);
498 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete);
499 nss_n2h_nepbcfgp[NSS_CORE_0].current_value = nss_n2h_empty_pool_buf_cfg[NSS_CORE_0];
500
501 /*
502 * Core1
503 */
504 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_1].sem, 1);
505 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_1].complete);
506 nss_n2h_nepbcfgp[NSS_CORE_1].current_value = nss_n2h_empty_pool_buf_cfg[NSS_CORE_1];
507}
508
509/*
510 * nss_n2h_unregister_sysctl()
511 * Unregister sysctl specific to n2h
512 */
513void nss_n2h_empty_pool_buf_unregister_sysctl(void)
514{
515 /*
516 * Unregister sysctl table.
517 */
518 if (nss_n2h_header) {
519 unregister_sysctl_table(nss_n2h_header);
520 }
521}
522
523/*
524 * nss_n2h_tx_msg()
525 * Send messages to NSS n2h pacakge
526 */
527nss_tx_status_t nss_n2h_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_n2h_msg *nnm)
528{
529 struct nss_n2h_msg *nnm2;
530 struct nss_cmn_msg *ncm = &nnm->cm;
531 struct sk_buff *nbuf;
532 nss_tx_status_t status;
533
534 NSS_VERIFY_CTX_MAGIC(nss_ctx);
535 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
536 return NSS_TX_FAILURE_NOT_READY;
537 }
538
539 /*
540 * Sanity check the message
541 */
542 if (ncm->interface != NSS_N2H_INTERFACE) {
543 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
544 return NSS_TX_FAILURE;
545 }
546
547 if (ncm->type >= NSS_METADATA_TYPE_N2H_MAX) {
548 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
549 return NSS_TX_FAILURE;
550 }
551
552 if (ncm->len > sizeof(struct nss_n2h_msg)) {
553 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
554 return NSS_TX_FAILURE;
555 }
556
557
558 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
559 if (unlikely(!nbuf)) {
560 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
561 nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
562 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
563 return NSS_TX_FAILURE;
564 }
565
566 /*
567 * Copy the message to our skb.
568 */
569 nnm2 = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg));
570 memcpy(nnm2, nnm, sizeof(struct nss_n2h_msg));
571 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
572 if (status != NSS_CORE_STATUS_SUCCESS) {
573 dev_kfree_skb_any(nbuf);
574 nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx);
575 return NSS_TX_FAILURE;
576 }
577
578 nss_hal_send_interrupt(nss_ctx->nmap,
579 nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
580 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
581 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
582 return NSS_TX_SUCCESS;
583}
584
Vijay Dewangan488e5372014-12-29 21:40:11 -0800585/*
586 * nss_n2h_notify_register()
587 * Register to received N2H events.
588 *
589 * NOTE: Do we want to pass an nss_ctx here so that we can register for n2h on any core?
590 */
591struct nss_ctx_instance *nss_n2h_notify_register(int core, nss_n2h_msg_callback_t cb, void *app_data)
592{
593 if (core >= NSS_MAX_CORES) {
594 nss_warning("Input core number %d is wrong \n", core);
595 return NULL;
596 }
597 /*
598 * TODO: We need to have a new array in support of the new API
599 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
600 */
601 nss_n2h_rd[core].n2h_callback = cb;
602 nss_n2h_rd[core].app_data = app_data;
603 return &nss_top_main.nss[core];
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530604}
605
606/*
607 * nss_n2h_register_handler()
608 */
609void nss_n2h_register_handler()
610{
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700611 nss_core_register_handler(NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL);
612
Vijay Dewangan634ce592015-01-07 17:21:09 -0800613 /*
614 * RPS sema init
615 */
616 sema_init(&nss_n2h_rcp.sem, 1);
617 init_completion(&nss_n2h_rcp.complete);
618
619
Vijay Dewangan488e5372014-12-29 21:40:11 -0800620 nss_n2h_notify_register(NSS_CORE_0, NULL, NULL);
621 nss_n2h_notify_register(NSS_CORE_1, NULL, NULL);
622
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700623 /*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800624 * Registering sysctl for n2h empty pool buffer.
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700625 */
Vijay Dewangan488e5372014-12-29 21:40:11 -0800626 nss_n2h_empty_pool_buf_register_sysctl();
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530627}
Vijay Dewangan488e5372014-12-29 21:40:11 -0800628
629EXPORT_SYMBOL(nss_n2h_notify_register);