blob: 64af645a82e9e9c8d3630a22e6bafc7d28e6b344 [file] [log] [blame]
Sol Kavy879eb8b2014-04-07 19:11:31 -07001/*
2 **************************************************************************
Stephen Wangaed46332016-12-12 17:29:03 -08003 * Copyright (c) 2014-2017, The Linux Foundation. All rights reserved.
Sol Kavy879eb8b2014-04-07 19:11:31 -07004 * 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/*
18 * nss_ipv6.c
19 * NSS IPv6 APIs
20 */
Sol Kavy879eb8b2014-04-07 19:11:31 -070021#include "nss_tx_rx_common.h"
Sol Kavy879eb8b2014-04-07 19:11:31 -070022
Stephen Wang0a2756a2016-08-04 15:52:47 -070023#define NSS_IPV6_TX_MSG_TIMEOUT 1000 /* 1 sec timeout for IPv4 messages */
24
25/*
26 * Private data structure for ipv6 configure messages
27 */
28struct nss_ipv6_cfg_pvt {
29 struct semaphore sem; /* Semaphore structure */
30 struct completion complete; /* completion structure */
31 int current_value; /* valid entry */
32 int response; /* Response from FW */
33};
34
Vijay Dewangan4861f4e2014-10-14 16:56:35 -070035int nss_ipv6_conn_cfg __read_mostly = NSS_DEFAULT_NUM_CONN;
Stephen Wang0a2756a2016-08-04 15:52:47 -070036int nss_ipv6_accel_mode_cfg __read_mostly = 1;
37
38static struct nss_ipv6_cfg_pvt i6_conn_cfgp;
39static struct nss_ipv6_cfg_pvt i6_accel_mode_cfgp;
Vijay Dewangan9db18752014-09-15 16:25:01 -070040
Sol Kavy879eb8b2014-04-07 19:11:31 -070041/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -070042 * Callback for conn_sync_many request message.
43 */
44nss_ipv6_msg_callback_t nss_ipv6_conn_sync_many_msg_cb = NULL;
45
46/*
Gareth Williams958aa822015-02-04 19:36:39 +000047 * nss_ipv6_max_conn_count()
48 * Return the maximum number of IPv6 connections that the NSS acceleration engine supports.
49 */
50int nss_ipv6_max_conn_count(void)
51{
Tushar Mathur55ba1302015-09-08 13:14:48 +053052 return nss_core_max_ipv6_conn_get();
Gareth Williams958aa822015-02-04 19:36:39 +000053}
54EXPORT_SYMBOL(nss_ipv6_max_conn_count);
55
56/*
Sol Kavy879eb8b2014-04-07 19:11:31 -070057 * nss_ipv6_driver_conn_sync_update()
58 * Update driver specific information from the messsage.
59 */
60static void nss_ipv6_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync *nics)
61{
62 struct nss_top_instance *nss_top = nss_ctx->nss_top;
Sol Kavy879eb8b2014-04-07 19:11:31 -070063
64 /*
65 * Update statistics maintained by NSS driver
66 */
67 spin_lock_bh(&nss_top->stats_lock);
68 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_PKTS] += nics->flow_rx_packet_count + nics->return_rx_packet_count;
69 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_BYTES] += nics->flow_rx_byte_count + nics->return_rx_byte_count;
70 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_PKTS] += nics->flow_tx_packet_count + nics->return_tx_packet_count;
71 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_BYTES] += nics->flow_tx_byte_count + nics->return_tx_byte_count;
Abhishek Rastogi55f39452014-05-08 19:23:29 +053072 spin_unlock_bh(&nss_top->stats_lock);
Sol Kavy879eb8b2014-04-07 19:11:31 -070073}
74
75/*
Stephen Wang709f9b52015-07-07 14:48:35 -070076 * nss_ipv6_driver_conn_sync_many_update()
77 * Update driver specific information from the conn_sync_many messsage.
78 */
79static void nss_ipv6_driver_conn_sync_many_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync_many_msg *nicsm)
80{
81 uint32_t i;
82
83 /*
84 * Sanity check for the stats count
85 */
86 if (nicsm->count * sizeof(struct nss_ipv6_conn_sync) >= nicsm->size) {
87 nss_warning("%p: stats sync count %u exceeds the size of this msg %u", nss_ctx, nicsm->count, nicsm->size);
88 return;
89 }
90
91 for (i = 0; i < nicsm->count; i++) {
92 nss_ipv6_driver_conn_sync_update(nss_ctx, &nicsm->conn_sync[i]);
93 }
94}
95
96/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -070097 * nss_ipv6_driver_node_sync_update)
98 * Update driver specific information from the messsage.
99 */
100static void nss_ipv6_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_node_sync *nins)
101{
102 struct nss_top_instance *nss_top = nss_ctx->nss_top;
103 uint32_t i;
104
105 /*
106 * Update statistics maintained by NSS driver
107 */
108 spin_lock_bh(&nss_top->stats_lock);
109 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
110 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
111 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped;
112 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
113 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
114
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700115 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_REQUESTS] += nins->ipv6_connection_create_requests;
116 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_COLLISIONS] += nins->ipv6_connection_create_collisions;
117 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_connection_create_invalid_interface;
118 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_connection_destroy_requests;
119 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_MISSES] += nins->ipv6_connection_destroy_misses;
120 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_HITS] += nins->ipv6_connection_hash_hits;
121 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_REORDERS] += nins->ipv6_connection_hash_reorders;
122 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_FLUSHES] += nins->ipv6_connection_flushes;
123 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_EVICTIONS] += nins->ipv6_connection_evictions;
Selin Dag5d68caa2015-05-12 13:23:33 -0700124 nss_top->stats_ipv6[NSS_STATS_IPV6_FRAGMENTATIONS] += nins->ipv6_fragmentations;
125 nss_top->stats_ipv6[NSS_STATS_IPV6_FRAG_FAILS] += nins->ipv6_frag_fails;
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530126 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_REQUESTS] += nins->ipv6_mc_connection_create_requests;
127 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_UPDATE_REQUESTS] += nins->ipv6_mc_connection_update_requests;
128 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_mc_connection_create_invalid_interface;
129 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_mc_connection_destroy_requests;
130 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_MISSES] += nins->ipv6_mc_connection_destroy_misses;
131 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_FLUSHES] += nins->ipv6_mc_connection_flushes;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700132
133 for (i = 0; i < NSS_EXCEPTION_EVENT_IPV6_MAX; i++) {
134 nss_top->stats_if_exception_ipv6[i] += nins->exception_events[i];
135 }
136 spin_unlock_bh(&nss_top->stats_lock);
137}
138
139/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700140 * nss_ipv6_rx_msg_handler()
141 * Handle NSS -> HLOS messages for IPv6 bridge/route
142 */
143static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
144{
145 struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm;
146 nss_ipv6_msg_callback_t cb;
147
148 BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE);
149
150 /*
151 * Is this a valid request/response packet?
152 */
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700153 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700154 nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type);
155 return;
156 }
157
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800158 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
159 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -0700160 return;
161 }
162
163 /*
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700164 * Trace messages.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700165 */
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700166 nss_ipv6_log_rx_msg(nim);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700167
168 /*
Stephen Wang0a2756a2016-08-04 15:52:47 -0700169 * Handle deprecated messages. Eventually these messages should be removed.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700170 */
171 switch (nim->cm.type) {
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700172 case NSS_IPV6_RX_NODE_STATS_SYNC_MSG:
173 /*
174 * Update driver statistics on node sync.
175 */
176 nss_ipv6_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
177 break;
178
Sol Kavy879eb8b2014-04-07 19:11:31 -0700179 case NSS_IPV6_RX_CONN_STATS_SYNC_MSG:
180 /*
181 * Update driver statistics on connection sync.
182 */
183 nss_ipv6_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700184 break;
Stephen Wang709f9b52015-07-07 14:48:35 -0700185
186 case NSS_IPV6_TX_CONN_STATS_SYNC_MANY_MSG:
187 /*
188 * Update driver statistics on connection sync many.
189 */
190 nss_ipv6_driver_conn_sync_many_update(nss_ctx, &nim->msg.conn_stats_many);
Stephen Wangaed46332016-12-12 17:29:03 -0800191 ncm->cb = (nss_ptr_t)nss_ipv6_conn_sync_many_msg_cb;
Stephen Wang709f9b52015-07-07 14:48:35 -0700192 break;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700193 }
Abhishek Rastogi55f39452014-05-08 19:23:29 +0530194
Sol Kavy879eb8b2014-04-07 19:11:31 -0700195 /*
196 * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages
197 * to the same callback/app_data.
198 */
199 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800200 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->ipv6_callback;
201 ncm->app_data = (nss_ptr_t)nss_ctx->nss_top->ipv6_ctx;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700202 }
203
204 /*
205 * Do we have a callback?
206 */
207 if (!ncm->cb) {
208 return;
209 }
210
211 /*
212 * Callback
213 */
214 cb = (nss_ipv6_msg_callback_t)ncm->cb;
215 cb((void *)ncm->app_data, nim);
216}
217
218/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700219 * nss_ipv6_tx_with_size()
220 * Transmit an ipv6 message to the FW with a specified size.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700221 */
Stephen Wang709f9b52015-07-07 14:48:35 -0700222nss_tx_status_t nss_ipv6_tx_with_size(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim, uint32_t size)
Sol Kavy879eb8b2014-04-07 19:11:31 -0700223{
224 struct nss_ipv6_msg *nim2;
225 struct nss_cmn_msg *ncm = &nim->cm;
226 struct sk_buff *nbuf;
227 int32_t status;
228
229 NSS_VERIFY_CTX_MAGIC(nss_ctx);
230 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
231 nss_warning("%p: ipv6 msg dropped as core not ready", nss_ctx);
232 return NSS_TX_FAILURE_NOT_READY;
233 }
234
235 /*
236 * Sanity check the message
237 */
238 if (ncm->interface != NSS_IPV6_RX_INTERFACE) {
239 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
240 return NSS_TX_FAILURE;
241 }
242
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700243 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700244 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
245 return NSS_TX_FAILURE;
246 }
247
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800248 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
249 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -0700250 return NSS_TX_FAILURE;
251 }
252
Stephen Wang709f9b52015-07-07 14:48:35 -0700253 if(size > PAGE_SIZE) {
254 nss_warning("%p: tx request size too large: %u", nss_ctx, size);
255 return NSS_TX_FAILURE;
256 }
257
258 nbuf = dev_alloc_skb(size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700259 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -0800260 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700261 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
262 return NSS_TX_FAILURE;
263 }
264
265 /*
266 * Copy the message to our skb.
267 */
Suruchi Agarwalea2e5232016-09-14 10:32:08 -0700268 nim2 = (struct nss_ipv6_msg *)skb_put(nbuf, size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700269 memcpy(nim2, nim, sizeof(struct nss_ipv6_msg));
270
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700271 /*
272 * Trace messages.
273 */
274 nss_ipv6_log_tx_msg(nim);
275
Sol Kavy879eb8b2014-04-07 19:11:31 -0700276 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
277 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530278 dev_kfree_skb_any(nbuf);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700279 nss_warning("%p: Unable to enqueue 'Destroy IPv6' rule\n", nss_ctx);
280 return NSS_TX_FAILURE;
281 }
282
Stephen Wang90c67de2016-04-26 15:15:59 -0700283 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700284
285 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
286 return NSS_TX_SUCCESS;
287}
288
289/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700290 * nss_ipv6_tx()
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700291 * Transmit an ipv6 message to the FW.
Stephen Wang709f9b52015-07-07 14:48:35 -0700292 */
293nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim)
294{
295 return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE);
296}
297
298/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700299 **********************************
300 Register/Unregister/Miscellaneous APIs
301 **********************************
302 */
303
304/*
305 * nss_ipv6_notify_register()
306 * Register to received IPv6 events.
307 *
308 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
309 */
310struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data)
311{
312 /*
313 * TODO: We need to have a new array in support of the new API
314 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
315 */
316 nss_top_main.ipv6_callback = cb;
317 nss_top_main.ipv6_ctx = app_data;
318 return &nss_top_main.nss[nss_top_main.ipv6_handler_id];
319}
320
321/*
322 * nss_ipv6_notify_unregister()
323 * Unregister to received IPv6 events.
324 *
325 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
326 */
327void nss_ipv6_notify_unregister(void)
328{
329 nss_top_main.ipv6_callback = NULL;
330}
331
332/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700333 * nss_ipv6_conn_sync_many_notify_register()
334 * Register to receive IPv6 conn_sync_many message response.
335 */
336void nss_ipv6_conn_sync_many_notify_register(nss_ipv6_msg_callback_t cb)
337{
338 nss_ipv6_conn_sync_many_msg_cb = cb;
339}
340
341/*
342 * nss_ipv6_conn_sync_many_notify_unregister()
343 * Unregister to receive IPv6 conn_sync_many message response.
344 */
345void nss_ipv6_conn_sync_many_notify_unregister(void)
346{
347 nss_ipv6_conn_sync_many_msg_cb = NULL;
348}
349
350/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700351 * nss_ipv6_get_mgr()
352 *
353 * TODO: This only suppports a single ipv6, do we ever want to support more?
354 */
355struct nss_ctx_instance *nss_ipv6_get_mgr(void)
356{
357 return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id];
358}
359
360/*
361 * nss_ipv6_register_handler()
362 * Register our handler to receive messages for this interface
363 */
364void nss_ipv6_register_handler()
365{
366 if (nss_core_register_handler(NSS_IPV6_RX_INTERFACE, nss_ipv6_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) {
367 nss_warning("IPv6 handler failed to register");
368 }
369}
370
Vijay Dewangan9db18752014-09-15 16:25:01 -0700371/*
Tushar Mathura3c18932015-08-24 20:27:21 +0530372 * nss_ipv6_conn_cfg_process()
373 * Process request to configure number of ipv6 connections
374 */
375static int nss_ipv6_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn,
376 void (*cfg_cb)(void *app_data, struct nss_ipv6_msg *nim))
377{
378 struct nss_ipv6_msg nim;
379 struct nss_ipv6_rule_conn_cfg_msg *nirccm;
380 nss_tx_status_t nss_tx_status;
381 uint32_t sum_of_conn;
382
383 /*
384 * Specifications for input
385 * 1) The input should be power of 2.
386 * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k
387 * 3) Min. value should be at leat 256 connections. This is the
388 * minimum connections we will support for each of them.
389 */
390 sum_of_conn = nss_ipv4_conn_cfg + conn;
391 if ((conn & NSS_NUM_CONN_QUANTA_MASK) ||
392 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
393 (conn < NSS_MIN_NUM_CONN)) {
394 nss_warning("%p: input supported connections (%d) does not adhere\
395 specifications\n1) not power of 2,\n2) is less than \
396 min val: %d, OR\n IPv4/6 total exceeds %d\n",
397 nss_ctx,
398 conn,
399 NSS_MIN_NUM_CONN,
400 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
401 return -EINVAL;
402 }
403
404 nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn);
405
406 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
407 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG,
408 sizeof(struct nss_ipv6_rule_conn_cfg_msg), cfg_cb, NULL);
409
410 nirccm = &nim.msg.rule_conn_cfg;
411 nirccm->num_conn = htonl(conn);
412 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
413
414 if (nss_tx_status != NSS_TX_SUCCESS) {
415 nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n",
416 nss_ctx,
417 conn);
418 return -EIO;
419 }
420
421 return 0;
422}
423
424/*
Vijay Dewangan9db18752014-09-15 16:25:01 -0700425 * nss_ipv6_conn_cfg_callback()
426 * call back function for the ipv6 connection configuration handler
427 */
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700428static void nss_ipv6_conn_cfg_callback(void *app_data, struct nss_ipv6_msg *nim)
Vijay Dewangan9db18752014-09-15 16:25:01 -0700429{
430 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700431 /*
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530432 * Error, hence we are not updating the nss_ipv6_conn_cfg
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700433 * Restore the current_value to its previous state
434 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700435 i6_conn_cfgp.response = NSS_FAILURE;
436 complete(&i6_conn_cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700437 return;
438 }
439
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700440 /*
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530441 * Sucess at NSS FW, hence updating nss_ipv6_conn_cfg, with the valid value
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700442 * saved at the sysctl handler.
443 */
Vijay Dewangan9db18752014-09-15 16:25:01 -0700444 nss_info("IPv6 connection configuration success: %d\n", nim->cm.error);
Stephen Wang0a2756a2016-08-04 15:52:47 -0700445 i6_conn_cfgp.response = NSS_SUCCESS;
446 complete(&i6_conn_cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700447}
448
449
450/*
451 * nss_ipv6_conn_cfg_handler()
452 * Sets the number of connections for IPv6
453 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700454static int nss_ipv6_conn_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
Vijay Dewangan9db18752014-09-15 16:25:01 -0700455{
456 struct nss_top_instance *nss_top = &nss_top_main;
457 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
Vijay Dewangan488e5372014-12-29 21:40:11 -0800458 int ret = NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700459
460 /*
461 * Acquiring semaphore
462 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700463 down(&i6_conn_cfgp.sem);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700464
465 /*
466 * Take a snapshot of the current value
467 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700468 i6_conn_cfgp.current_value = nss_ipv6_conn_cfg;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700469
470 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
471 if (ret || (!write)) {
Stephen Wang0a2756a2016-08-04 15:52:47 -0700472 up(&i6_conn_cfgp.sem);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700473 return ret;
474 }
Vijay Dewangan9db18752014-09-15 16:25:01 -0700475
476 /*
Tushar Mathura3c18932015-08-24 20:27:21 +0530477 * Process request to change number of IPv6 connections
Vijay Dewangan9db18752014-09-15 16:25:01 -0700478 */
Tushar Mathura3c18932015-08-24 20:27:21 +0530479 ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_conn_cfg_callback);
480 if (ret != 0) {
Stephen Wang06761022015-03-03 16:38:42 -0800481 goto failure;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700482 }
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700483
484 /*
485 * Blocking call, wait till we get ACK for this msg.
486 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700487 ret = wait_for_completion_timeout(&i6_conn_cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700488 if (ret == 0) {
489 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
Stephen Wang06761022015-03-03 16:38:42 -0800490 goto failure;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700491 }
492
493 /*
494 * ACK/NACK received from NSS FW
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530495 * If ACK: Callback function will update nss_ipv6_conn_cfg with
Stephen Wang0a2756a2016-08-04 15:52:47 -0700496 * i6_conn_cfgp.num_conn_valid, which holds the user input
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700497 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700498 if (NSS_FAILURE == i6_conn_cfgp.response) {
Stephen Wang06761022015-03-03 16:38:42 -0800499 goto failure;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700500 }
501
Stephen Wang0a2756a2016-08-04 15:52:47 -0700502 up(&i6_conn_cfgp.sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700503 return 0;
Stephen Wang06761022015-03-03 16:38:42 -0800504
505failure:
506 /*
507 * Restore the current_value to its previous state
508 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700509 nss_ipv6_conn_cfg = i6_conn_cfgp.current_value;
510 up(&i6_conn_cfgp.sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700511 return -EINVAL;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700512}
513
Tushar Mathura3c18932015-08-24 20:27:21 +0530514/*
515 * nss_ipv6_update_conn_count_cb()
516 * call back function for the ipv6 connection count update handler
517 */
518static void nss_ipv6_update_conn_count_cb(void *app_data, struct nss_ipv6_msg *nim)
519{
520 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
521 nss_warning("IPv6 connection count update failed with error: %d\n", nim->cm.error);
522 return;
523 }
524
525 nss_warning("IPv6 connection count update success: %d\n", nim->cm.error);
526}
527
528/*
529 * nss_ipv6_update_conn_count()
530 * Sets the maximum number of connections for IPv6
531 */
532int nss_ipv6_update_conn_count(int ipv6_num_conn)
533{
534 struct nss_top_instance *nss_top = &nss_top_main;
535 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
536 int saved_nss_ipv6_conn_cfg = nss_ipv6_conn_cfg;
537 int ret = 0;
538
539 nss_ipv6_conn_cfg = ipv6_num_conn;
540
541 /*
542 * Process request to change number of IPv6 connections
543 */
544 ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_update_conn_count_cb);
545 if (ret != 0) {
546 goto failure;
547 }
548
549 return 0;
550
551failure:
552 nss_ipv6_conn_cfg = saved_nss_ipv6_conn_cfg;
553 return -EINVAL;
554}
555
Stephen Wang0a2756a2016-08-04 15:52:47 -0700556/*
557 * nss_ipv6_accel_mode_cfg_callback()
558 * call back function for the ipv6 acceleration mode configurate handler
559 */
560static void nss_ipv6_accel_mode_cfg_callback(void *app_data, struct nss_ipv6_msg *nim)
561{
562 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
563 nss_warning("IPv6 acceleration mode configuration failed with error: %d\n", nim->cm.error);
564 i6_accel_mode_cfgp.response = NSS_FAILURE;
565 complete(&i6_accel_mode_cfgp.complete);
566 return;
567 }
568
569 nss_info("IPv6 acceleration mode configuration success\n");
570 i6_accel_mode_cfgp.response = NSS_SUCCESS;
571 complete(&i6_accel_mode_cfgp.complete);
572}
573
574/*
575 * nss_ipv6_accel_mode_cfg_handler()
576 * Configure acceleration mode for IPv6
577 */
578static int nss_ipv6_accel_mode_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
579{
580 struct nss_top_instance *nss_top = &nss_top_main;
581 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
582 struct nss_ipv6_msg nim;
583 struct nss_ipv6_accel_mode_cfg_msg *nipcm;
584 nss_tx_status_t nss_tx_status;
585 int ret = NSS_FAILURE;
586
587 /*
588 * Acquiring semaphore
589 */
590 down(&i6_accel_mode_cfgp.sem);
591
592 /*
593 * Take snap shot of current value
594 */
595 i6_accel_mode_cfgp.current_value = nss_ipv6_accel_mode_cfg;
596
597 /*
598 * Write the variable with user input
599 */
600 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
601 if (ret || (!write)) {
602 up(&i6_accel_mode_cfgp.sem);
603 return ret;
604 }
605
606 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
607 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_ACCEL_MODE_CFG_MSG,
608 sizeof(struct nss_ipv6_accel_mode_cfg_msg), nss_ipv6_accel_mode_cfg_callback, NULL);
609
610 nipcm = &nim.msg.accel_mode_cfg;
611 nipcm->mode = htonl(nss_ipv6_accel_mode_cfg);
612 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
613
614 if (nss_tx_status != NSS_TX_SUCCESS) {
615 nss_warning("%p: Send acceleration mode message failed\n", nss_ctx);
616 goto fail;
617 }
618
619 /*
620 * Blocking call, wait till we get ACK for this msg.
621 */
622 ret = wait_for_completion_timeout(&i6_accel_mode_cfgp.complete, msecs_to_jiffies(NSS_IPV6_TX_MSG_TIMEOUT));
623 if (ret == 0) {
624 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
625 goto fail;
626 }
627
628 if (NSS_FAILURE == i6_accel_mode_cfgp.response) {
629 nss_warning("%p: accel mode configure failed\n", nss_ctx);
630 goto fail;
631 }
632
633 up(&i6_accel_mode_cfgp.sem);
634 return 0;
635
636fail:
637 nss_ipv6_accel_mode_cfg = i6_accel_mode_cfgp.current_value;
638 up(&i6_accel_mode_cfgp.sem);
639 return -EIO;
640}
641
Stephen Wang52e6d342016-03-29 15:02:33 -0700642static struct ctl_table nss_ipv6_table[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700643 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700644 .procname = "ipv6_conn",
645 .data = &nss_ipv6_conn_cfg,
646 .maxlen = sizeof(int),
647 .mode = 0644,
Stephen Wang0a2756a2016-08-04 15:52:47 -0700648 .proc_handler = &nss_ipv6_conn_cfg_handler,
649 },
650 {
651 .procname = "ipv6_accel_mode",
652 .data = &nss_ipv6_accel_mode_cfg,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &nss_ipv6_accel_mode_cfg_handler,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700656 },
657 { }
658};
659
Stephen Wang52e6d342016-03-29 15:02:33 -0700660static struct ctl_table nss_ipv6_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700661 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700662 .procname = "ipv6cfg",
663 .mode = 0555,
664 .child = nss_ipv6_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700665 },
666 { }
667};
668
Stephen Wang52e6d342016-03-29 15:02:33 -0700669static struct ctl_table nss_ipv6_root_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700670 {
671 .procname = "nss",
672 .mode = 0555,
673 .child = nss_ipv6_dir,
674 },
675 { }
676};
677
Stephen Wang52e6d342016-03-29 15:02:33 -0700678static struct ctl_table nss_ipv6_root[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700679 {
680 .procname = "dev",
681 .mode = 0555,
682 .child = nss_ipv6_root_dir,
683 },
684 { }
685};
686
687static struct ctl_table_header *nss_ipv6_header;
688
689/*
690 * nss_ipv6_register_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530691 * Register sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700692 */
693void nss_ipv6_register_sysctl(void)
694{
Stephen Wang0a2756a2016-08-04 15:52:47 -0700695 sema_init(&i6_conn_cfgp.sem, 1);
696 init_completion(&i6_conn_cfgp.complete);
697
698 sema_init(&i6_accel_mode_cfgp.sem, 1);
699 init_completion(&i6_accel_mode_cfgp.complete);
Stephen Wang49b474b2016-03-25 10:40:30 -0700700
Vijay Dewangan9db18752014-09-15 16:25:01 -0700701 /*
702 * Register sysctl table.
703 */
704 nss_ipv6_header = register_sysctl_table(nss_ipv6_root);
705}
706
707/*
708 * nss_ipv6_unregister_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530709 * Unregister sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700710 */
711void nss_ipv6_unregister_sysctl(void)
712{
713 /*
714 * Unregister sysctl table.
715 */
716 if (nss_ipv6_header) {
717 unregister_sysctl_table(nss_ipv6_header);
718 }
719}
720
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700721/*
722 * nss_ipv6_msg_init()
Stephen Wang0a2756a2016-08-04 15:52:47 -0700723 * Initialize IPv6 message.
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700724 */
725void nss_ipv6_msg_init(struct nss_ipv6_msg *nim, uint16_t if_num, uint32_t type, uint32_t len,
Sundarajan Srinivasan30a53d42015-01-30 10:52:08 -0800726 nss_ipv6_msg_callback_t cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700727{
728 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
729}
730
Sol Kavy879eb8b2014-04-07 19:11:31 -0700731EXPORT_SYMBOL(nss_ipv6_tx);
Stephen Wang709f9b52015-07-07 14:48:35 -0700732EXPORT_SYMBOL(nss_ipv6_tx_with_size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700733EXPORT_SYMBOL(nss_ipv6_notify_register);
734EXPORT_SYMBOL(nss_ipv6_notify_unregister);
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700735EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_register);
736EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_unregister);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700737EXPORT_SYMBOL(nss_ipv6_get_mgr);
738EXPORT_SYMBOL(nss_ipv6_register_handler);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700739EXPORT_SYMBOL(nss_ipv6_register_sysctl);
740EXPORT_SYMBOL(nss_ipv6_unregister_sysctl);
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700741EXPORT_SYMBOL(nss_ipv6_msg_init);
Tushar Mathura3c18932015-08-24 20:27:21 +0530742EXPORT_SYMBOL(nss_ipv6_update_conn_count);