blob: 4300fe32ee649480f5172ce7c0de30dbbe9609cc [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);
Stephen Wang06761022015-03-03 16:38:42 -0800283 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800284 }
285
286 nss_info("%p: core %d number of empty pool buffer is : %d\n",
287 nss_ctx, core_num, *new_val);
288
289 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
290 NSS_TX_METADATA_TYPE_N2H_EMPTY_POOL_BUF_CFG,
291 sizeof(struct nss_n2h_empty_pool_buf),
Vijay Dewangan634ce592015-01-07 17:21:09 -0800292 nss_n2h_empty_pool_buf_cfg_callback,
Vijay Dewangan488e5372014-12-29 21:40:11 -0800293 (void *)core_num);
294
295 nnepbcm = &nnm.msg.empty_pool_buf_cfg;
296 nnepbcm->pool_size = htonl(*new_val);
297 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
298
299 if (nss_tx_status != NSS_TX_SUCCESS) {
300 nss_warning("%p: core %d nss_tx error setting empty pool buffer: %d\n",
301 nss_ctx, core_num, *new_val);
Stephen Wang06761022015-03-03 16:38:42 -0800302 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800303 }
304
305 /*
306 * Blocking call, wait till we get ACK for this msg.
307 */
308 ret = wait_for_completion_timeout(&nss_n2h_nepbcfgp[core_num].complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
309 if (ret == 0) {
310 nss_warning("%p: core %d Waiting for ack timed out\n", nss_ctx, core_num);
Stephen Wang06761022015-03-03 16:38:42 -0800311 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800312 }
313
314 /*
315 * ACK/NACK received from NSS FW
316 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
317 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
318 */
319 if (NSS_FAILURE == nss_n2h_nepbcfgp[core_num].response) {
Stephen Wang06761022015-03-03 16:38:42 -0800320 goto failure;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800321 }
322
323 up(&nss_n2h_nepbcfgp[core_num].sem);
324 return NSS_SUCCESS;
Stephen Wang06761022015-03-03 16:38:42 -0800325
326failure:
327 /*
328 * Restore the current_value to its previous state
329 */
330 *new_val = nss_n2h_nepbcfgp[core_num].current_value;
331 up(&nss_n2h_nepbcfgp[core_num].sem);
332 return NSS_FAILURE;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800333}
334
335/*
Radha krishna Simha Jiguru7f424d52015-02-10 19:41:01 +0530336 * nss_n2h_flush_payloads()
337 * Sends a command down to NSS for flushing all payloads
338 */
339nss_tx_status_t nss_n2h_flush_payloads(struct nss_ctx_instance *nss_ctx)
340{
341 struct nss_n2h_msg nnm;
342 struct nss_n2h_flush_payloads *nnflshpl;
343 nss_tx_status_t nss_tx_status;
344
345 nnflshpl = &nnm.msg.flush_payloads;
346
347 /*
348 * TODO: No additional information sent in message
349 * as of now. Need to initialize message content accordingly
350 * if needed.
351 */
352 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE,
353 NSS_TX_METADATA_TYPE_N2H_FLUSH_PAYLOADS,
354 sizeof(struct nss_n2h_flush_payloads),
355 NULL,
356 NULL);
357
358 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
359 if (nss_tx_status != NSS_TX_SUCCESS) {
360 nss_warning("%p: failed to send flush payloads command to NSS\n",
361 nss_ctx);
362
363 return NSS_TX_FAILURE;
364 }
365
366 return NSS_TX_SUCCESS;
367}
368
369/*
Vijay Dewangan488e5372014-12-29 21:40:11 -0800370 * nss_n2h_empty_pool_buf_core1_handler()
371 * Sets the number of empty buffer for core 1
372 */
373static int nss_n2h_empty_pool_buf_cfg_core1_handler(ctl_table *ctl,
374 int write, void __user *buffer,
375 size_t *lenp, loff_t *ppos)
376{
377 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
378 NSS_CORE_1, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1]);
379}
380
381/*
382 * nss_n2h_empty_pool_buf_core0_handler()
383 * Sets the number of empty buffer for core 0
384 */
385static int nss_n2h_empty_pool_buf_cfg_core0_handler(ctl_table *ctl,
386 int write, void __user *buffer,
387 size_t *lenp, loff_t *ppos)
388{
389 return nss_n2h_set_empty_pool_buf(ctl, write, buffer, lenp, ppos,
390 NSS_CORE_0, &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0]);
391}
392
Vijay Dewangan634ce592015-01-07 17:21:09 -0800393/*
394 * nss_n2h_rps_cfg()
395 * Send Message to NSS to enable RPS.
396 */
397nss_tx_status_t nss_n2h_rps_cfg(struct nss_ctx_instance *nss_ctx, int enable_rps)
398{
399 struct nss_n2h_msg nnm;
400 struct nss_n2h_rps *rps_cfg;
401 nss_tx_status_t nss_tx_status;
402 int ret;
403
404 down(&nss_n2h_rcp.sem);
405 nss_n2h_msg_init(&nnm, NSS_N2H_INTERFACE, NSS_TX_METADATA_TYPE_N2H_RPS_CFG,
406 sizeof(struct nss_n2h_rps),
407 nss_n2h_rps_cfg_callback,
408 (void *)nss_ctx);
409
410 rps_cfg = &nnm.msg.rps_cfg;
411 rps_cfg->enable = enable_rps;
412
413 nss_tx_status = nss_n2h_tx_msg(nss_ctx, &nnm);
414
415 if (nss_tx_status != NSS_TX_SUCCESS) {
416 nss_warning("%p: nss_tx error setting rps\n", nss_ctx);
417
418 up(&nss_n2h_rcp.sem);
419 return NSS_FAILURE;
420 }
421
422 /*
423 * Blocking call, wait till we get ACK for this msg.
424 */
425 ret = wait_for_completion_timeout(&nss_n2h_rcp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
426 if (ret == 0) {
427 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
428 up(&nss_n2h_rcp.sem);
429 return NSS_FAILURE;
430 }
431
432 /*
433 * ACK/NACK received from NSS FW
434 * If ACK: Callback function will update nss_n2h_empty_pool_buf with
435 * nss_n2h_nepbcfgp.num_conn_valid, which holds the user input
436 */
437 if (NSS_FAILURE == nss_n2h_rcp.response) {
438 up(&nss_n2h_rcp.sem);
439 return NSS_FAILURE;
440 }
441
442 up(&nss_n2h_rcp.sem);
443 return NSS_SUCCESS;
444}
445
Vijay Dewangan488e5372014-12-29 21:40:11 -0800446static ctl_table nss_n2h_table[] = {
447 {
448 .procname = "n2h_empty_pool_buf_core0",
449 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_0],
450 .maxlen = sizeof(int),
451 .mode = 0644,
452 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core0_handler,
453 },
454 {
455 .procname = "n2h_empty_pool_buf_core1",
456 .data = &nss_n2h_empty_pool_buf_cfg[NSS_CORE_1],
457 .maxlen = sizeof(int),
458 .mode = 0644,
459 .proc_handler = &nss_n2h_empty_pool_buf_cfg_core1_handler,
460 },
461
462 { }
463};
464
465static ctl_table nss_n2h_dir[] = {
466 {
467 .procname = "n2hcfg",
468 .mode = 0555,
469 .child = nss_n2h_table,
470 },
471 { }
472};
473
474
475static ctl_table nss_n2h_root_dir[] = {
476 {
477 .procname = "nss",
478 .mode = 0555,
479 .child = nss_n2h_dir,
480 },
481 { }
482};
483
484static ctl_table nss_n2h_root[] = {
485 {
486 .procname = "dev",
487 .mode = 0555,
488 .child = nss_n2h_root_dir,
489 },
490 { }
491};
492
493static struct ctl_table_header *nss_n2h_header;
494
495/*
496 * nss_n2h_msg_init()
497 * Initialize IPv4 message.
498 */
499void nss_n2h_msg_init(struct nss_n2h_msg *nim, uint16_t if_num, uint32_t type,
Vijay Dewangan634ce592015-01-07 17:21:09 -0800500 uint32_t len, nss_n2h_msg_callback_t cb, void *app_data)
Vijay Dewangan488e5372014-12-29 21:40:11 -0800501{
502 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
503}
504
Vijay Dewangan488e5372014-12-29 21:40:11 -0800505/*
506 * nss_n2h_register_sysctl()
507 * Register sysctl specific to n2h
508 */
509void nss_n2h_empty_pool_buf_register_sysctl(void)
510{
511 /*
512 * Register sysctl table.
513 */
514 nss_n2h_header = register_sysctl_table(nss_n2h_root);
515
516 /*
517 * Core0
518 */
519 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_0].sem, 1);
520 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_0].complete);
521 nss_n2h_nepbcfgp[NSS_CORE_0].current_value = nss_n2h_empty_pool_buf_cfg[NSS_CORE_0];
522
523 /*
524 * Core1
525 */
526 sema_init(&nss_n2h_nepbcfgp[NSS_CORE_1].sem, 1);
527 init_completion(&nss_n2h_nepbcfgp[NSS_CORE_1].complete);
528 nss_n2h_nepbcfgp[NSS_CORE_1].current_value = nss_n2h_empty_pool_buf_cfg[NSS_CORE_1];
529}
530
531/*
532 * nss_n2h_unregister_sysctl()
533 * Unregister sysctl specific to n2h
534 */
535void nss_n2h_empty_pool_buf_unregister_sysctl(void)
536{
537 /*
538 * Unregister sysctl table.
539 */
540 if (nss_n2h_header) {
541 unregister_sysctl_table(nss_n2h_header);
542 }
543}
544
545/*
546 * nss_n2h_tx_msg()
547 * Send messages to NSS n2h pacakge
548 */
549nss_tx_status_t nss_n2h_tx_msg(struct nss_ctx_instance *nss_ctx, struct nss_n2h_msg *nnm)
550{
551 struct nss_n2h_msg *nnm2;
552 struct nss_cmn_msg *ncm = &nnm->cm;
553 struct sk_buff *nbuf;
554 nss_tx_status_t status;
555
556 NSS_VERIFY_CTX_MAGIC(nss_ctx);
557 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
558 return NSS_TX_FAILURE_NOT_READY;
559 }
560
561 /*
562 * Sanity check the message
563 */
564 if (ncm->interface != NSS_N2H_INTERFACE) {
565 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
566 return NSS_TX_FAILURE;
567 }
568
569 if (ncm->type >= NSS_METADATA_TYPE_N2H_MAX) {
570 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
571 return NSS_TX_FAILURE;
572 }
573
574 if (ncm->len > sizeof(struct nss_n2h_msg)) {
575 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
576 return NSS_TX_FAILURE;
577 }
578
579
580 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
581 if (unlikely(!nbuf)) {
582 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
583 nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
584 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
585 return NSS_TX_FAILURE;
586 }
587
588 /*
589 * Copy the message to our skb.
590 */
591 nnm2 = (struct nss_n2h_msg *)skb_put(nbuf, sizeof(struct nss_n2h_msg));
592 memcpy(nnm2, nnm, sizeof(struct nss_n2h_msg));
593 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
594 if (status != NSS_CORE_STATUS_SUCCESS) {
595 dev_kfree_skb_any(nbuf);
596 nss_info("%p: unable to enqueue 'nss frequency change' - marked as stopped\n", nss_ctx);
597 return NSS_TX_FAILURE;
598 }
599
600 nss_hal_send_interrupt(nss_ctx->nmap,
601 nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
602 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
603 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
604 return NSS_TX_SUCCESS;
605}
606
Vijay Dewangan488e5372014-12-29 21:40:11 -0800607/*
608 * nss_n2h_notify_register()
609 * Register to received N2H events.
610 *
611 * NOTE: Do we want to pass an nss_ctx here so that we can register for n2h on any core?
612 */
613struct nss_ctx_instance *nss_n2h_notify_register(int core, nss_n2h_msg_callback_t cb, void *app_data)
614{
615 if (core >= NSS_MAX_CORES) {
616 nss_warning("Input core number %d is wrong \n", core);
617 return NULL;
618 }
619 /*
620 * TODO: We need to have a new array in support of the new API
621 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
622 */
623 nss_n2h_rd[core].n2h_callback = cb;
624 nss_n2h_rd[core].app_data = app_data;
625 return &nss_top_main.nss[core];
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530626}
627
628/*
629 * nss_n2h_register_handler()
630 */
631void nss_n2h_register_handler()
632{
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -0700633 nss_core_register_handler(NSS_N2H_INTERFACE, nss_n2h_interface_handler, NULL);
634
Vijay Dewangan634ce592015-01-07 17:21:09 -0800635 /*
636 * RPS sema init
637 */
638 sema_init(&nss_n2h_rcp.sem, 1);
639 init_completion(&nss_n2h_rcp.complete);
640
641
Vijay Dewangan488e5372014-12-29 21:40:11 -0800642 nss_n2h_notify_register(NSS_CORE_0, NULL, NULL);
643 nss_n2h_notify_register(NSS_CORE_1, NULL, NULL);
644
Abhishek Rastogi84d95d02014-03-26 19:31:31 +0530645}
Vijay Dewangan488e5372014-12-29 21:40:11 -0800646
647EXPORT_SYMBOL(nss_n2h_notify_register);
Vijay Dewanganac7efc42015-02-09 16:04:53 -0800648EXPORT_SYMBOL(nss_n2h_empty_pool_buf_register_sysctl);