blob: 6c2f4a881736bc8bcf9e5e296edee2124e2f0994 [file] [log] [blame]
Sol Kavy879eb8b2014-04-07 19:11:31 -07001/*
2 **************************************************************************
Suruchi Agarwalef8a8702016-01-08 12:40:08 -08003 * Copyright (c) 2014-2016, 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
Vijay Dewangan4861f4e2014-10-14 16:56:35 -070023int nss_ipv6_conn_cfg __read_mostly = NSS_DEFAULT_NUM_CONN;
24static struct nss_conn_cfg_pvt i6cfgp;
Vijay Dewangan9db18752014-09-15 16:25:01 -070025
Sol Kavy879eb8b2014-04-07 19:11:31 -070026/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -070027 * Callback for conn_sync_many request message.
28 */
29nss_ipv6_msg_callback_t nss_ipv6_conn_sync_many_msg_cb = NULL;
30
31/*
Gareth Williams958aa822015-02-04 19:36:39 +000032 * nss_ipv6_max_conn_count()
33 * Return the maximum number of IPv6 connections that the NSS acceleration engine supports.
34 */
35int nss_ipv6_max_conn_count(void)
36{
Tushar Mathur55ba1302015-09-08 13:14:48 +053037 return nss_core_max_ipv6_conn_get();
Gareth Williams958aa822015-02-04 19:36:39 +000038}
39EXPORT_SYMBOL(nss_ipv6_max_conn_count);
40
41/*
Sol Kavy879eb8b2014-04-07 19:11:31 -070042 * nss_ipv6_driver_conn_sync_update()
43 * Update driver specific information from the messsage.
44 */
45static void nss_ipv6_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync *nics)
46{
47 struct nss_top_instance *nss_top = nss_ctx->nss_top;
Sol Kavy879eb8b2014-04-07 19:11:31 -070048
49 /*
50 * Update statistics maintained by NSS driver
51 */
52 spin_lock_bh(&nss_top->stats_lock);
53 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_PKTS] += nics->flow_rx_packet_count + nics->return_rx_packet_count;
54 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_BYTES] += nics->flow_rx_byte_count + nics->return_rx_byte_count;
55 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_PKTS] += nics->flow_tx_packet_count + nics->return_tx_packet_count;
56 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 +053057 spin_unlock_bh(&nss_top->stats_lock);
Sol Kavy879eb8b2014-04-07 19:11:31 -070058}
59
60/*
Stephen Wang709f9b52015-07-07 14:48:35 -070061 * nss_ipv6_driver_conn_sync_many_update()
62 * Update driver specific information from the conn_sync_many messsage.
63 */
64static void nss_ipv6_driver_conn_sync_many_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync_many_msg *nicsm)
65{
66 uint32_t i;
67
68 /*
69 * Sanity check for the stats count
70 */
71 if (nicsm->count * sizeof(struct nss_ipv6_conn_sync) >= nicsm->size) {
72 nss_warning("%p: stats sync count %u exceeds the size of this msg %u", nss_ctx, nicsm->count, nicsm->size);
73 return;
74 }
75
76 for (i = 0; i < nicsm->count; i++) {
77 nss_ipv6_driver_conn_sync_update(nss_ctx, &nicsm->conn_sync[i]);
78 }
79}
80
81/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -070082 * nss_ipv6_driver_node_sync_update)
83 * Update driver specific information from the messsage.
84 */
85static void nss_ipv6_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_node_sync *nins)
86{
87 struct nss_top_instance *nss_top = nss_ctx->nss_top;
88 uint32_t i;
89
90 /*
91 * Update statistics maintained by NSS driver
92 */
93 spin_lock_bh(&nss_top->stats_lock);
94 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
95 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
96 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped;
97 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
98 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
99
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700100 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_REQUESTS] += nins->ipv6_connection_create_requests;
101 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_COLLISIONS] += nins->ipv6_connection_create_collisions;
102 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_connection_create_invalid_interface;
103 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_connection_destroy_requests;
104 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_MISSES] += nins->ipv6_connection_destroy_misses;
105 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_HITS] += nins->ipv6_connection_hash_hits;
106 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_REORDERS] += nins->ipv6_connection_hash_reorders;
107 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_FLUSHES] += nins->ipv6_connection_flushes;
108 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_EVICTIONS] += nins->ipv6_connection_evictions;
Selin Dag5d68caa2015-05-12 13:23:33 -0700109 nss_top->stats_ipv6[NSS_STATS_IPV6_FRAGMENTATIONS] += nins->ipv6_fragmentations;
110 nss_top->stats_ipv6[NSS_STATS_IPV6_FRAG_FAILS] += nins->ipv6_frag_fails;
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530111 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_REQUESTS] += nins->ipv6_mc_connection_create_requests;
112 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_UPDATE_REQUESTS] += nins->ipv6_mc_connection_update_requests;
113 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_mc_connection_create_invalid_interface;
114 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_mc_connection_destroy_requests;
115 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_MISSES] += nins->ipv6_mc_connection_destroy_misses;
116 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_FLUSHES] += nins->ipv6_mc_connection_flushes;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700117
118 for (i = 0; i < NSS_EXCEPTION_EVENT_IPV6_MAX; i++) {
119 nss_top->stats_if_exception_ipv6[i] += nins->exception_events[i];
120 }
121 spin_unlock_bh(&nss_top->stats_lock);
122}
123
124/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700125 * nss_ipv6_rx_msg_handler()
126 * Handle NSS -> HLOS messages for IPv6 bridge/route
127 */
128static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
129{
130 struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm;
131 nss_ipv6_msg_callback_t cb;
132
133 BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE);
134
135 /*
136 * Is this a valid request/response packet?
137 */
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700138 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700139 nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type);
140 return;
141 }
142
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800143 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
144 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -0700145 return;
146 }
147
148 /*
149 * Log failures
150 */
151 nss_core_log_msg_failures(nss_ctx, ncm);
152
153 /*
154 * Handle deprecated messages. Eventually these messages should be removed.
155 */
156 switch (nim->cm.type) {
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700157 case NSS_IPV6_RX_NODE_STATS_SYNC_MSG:
158 /*
159 * Update driver statistics on node sync.
160 */
161 nss_ipv6_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
162 break;
163
Sol Kavy879eb8b2014-04-07 19:11:31 -0700164 case NSS_IPV6_RX_CONN_STATS_SYNC_MSG:
165 /*
166 * Update driver statistics on connection sync.
167 */
168 nss_ipv6_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700169 break;
Stephen Wang709f9b52015-07-07 14:48:35 -0700170
171 case NSS_IPV6_TX_CONN_STATS_SYNC_MANY_MSG:
172 /*
173 * Update driver statistics on connection sync many.
174 */
175 nss_ipv6_driver_conn_sync_many_update(nss_ctx, &nim->msg.conn_stats_many);
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700176 ncm->cb = (uint32_t)nss_ipv6_conn_sync_many_msg_cb;
Stephen Wang709f9b52015-07-07 14:48:35 -0700177 break;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700178 }
Abhishek Rastogi55f39452014-05-08 19:23:29 +0530179
Sol Kavy879eb8b2014-04-07 19:11:31 -0700180 /*
181 * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages
182 * to the same callback/app_data.
183 */
184 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
185 ncm->cb = (uint32_t)nss_ctx->nss_top->ipv6_callback;
186 ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv6_ctx;
187 }
188
189 /*
190 * Do we have a callback?
191 */
192 if (!ncm->cb) {
193 return;
194 }
195
196 /*
197 * Callback
198 */
199 cb = (nss_ipv6_msg_callback_t)ncm->cb;
200 cb((void *)ncm->app_data, nim);
201}
202
203/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700204 * nss_ipv6_tx_with_size()
205 * Transmit an ipv6 message to the FW with a specified size.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700206 */
Stephen Wang709f9b52015-07-07 14:48:35 -0700207nss_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 -0700208{
209 struct nss_ipv6_msg *nim2;
210 struct nss_cmn_msg *ncm = &nim->cm;
211 struct sk_buff *nbuf;
212 int32_t status;
213
214 NSS_VERIFY_CTX_MAGIC(nss_ctx);
215 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
216 nss_warning("%p: ipv6 msg dropped as core not ready", nss_ctx);
217 return NSS_TX_FAILURE_NOT_READY;
218 }
219
220 /*
221 * Sanity check the message
222 */
223 if (ncm->interface != NSS_IPV6_RX_INTERFACE) {
224 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
225 return NSS_TX_FAILURE;
226 }
227
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700228 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700229 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
230 return NSS_TX_FAILURE;
231 }
232
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800233 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
234 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -0700235 return NSS_TX_FAILURE;
236 }
237
Stephen Wang709f9b52015-07-07 14:48:35 -0700238 if(size > PAGE_SIZE) {
239 nss_warning("%p: tx request size too large: %u", nss_ctx, size);
240 return NSS_TX_FAILURE;
241 }
242
243 nbuf = dev_alloc_skb(size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700244 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -0800245 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 -0700246 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
247 return NSS_TX_FAILURE;
248 }
249
250 /*
251 * Copy the message to our skb.
252 */
253 nim2 = (struct nss_ipv6_msg *)skb_put(nbuf, sizeof(struct nss_ipv6_msg));
254 memcpy(nim2, nim, sizeof(struct nss_ipv6_msg));
255
256 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
257 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530258 dev_kfree_skb_any(nbuf);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700259 nss_warning("%p: Unable to enqueue 'Destroy IPv6' rule\n", nss_ctx);
260 return NSS_TX_FAILURE;
261 }
262
263 nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
264 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
265
266 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
267 return NSS_TX_SUCCESS;
268}
269
270/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700271 * nss_ipv6_tx()
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700272 * Transmit an ipv6 message to the FW.
Stephen Wang709f9b52015-07-07 14:48:35 -0700273 */
274nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim)
275{
276 return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE);
277}
278
279/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700280 **********************************
281 Register/Unregister/Miscellaneous APIs
282 **********************************
283 */
284
285/*
286 * nss_ipv6_notify_register()
287 * Register to received IPv6 events.
288 *
289 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
290 */
291struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data)
292{
293 /*
294 * TODO: We need to have a new array in support of the new API
295 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
296 */
297 nss_top_main.ipv6_callback = cb;
298 nss_top_main.ipv6_ctx = app_data;
299 return &nss_top_main.nss[nss_top_main.ipv6_handler_id];
300}
301
302/*
303 * nss_ipv6_notify_unregister()
304 * Unregister to received IPv6 events.
305 *
306 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
307 */
308void nss_ipv6_notify_unregister(void)
309{
310 nss_top_main.ipv6_callback = NULL;
311}
312
313/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700314 * nss_ipv6_conn_sync_many_notify_register()
315 * Register to receive IPv6 conn_sync_many message response.
316 */
317void nss_ipv6_conn_sync_many_notify_register(nss_ipv6_msg_callback_t cb)
318{
319 nss_ipv6_conn_sync_many_msg_cb = cb;
320}
321
322/*
323 * nss_ipv6_conn_sync_many_notify_unregister()
324 * Unregister to receive IPv6 conn_sync_many message response.
325 */
326void nss_ipv6_conn_sync_many_notify_unregister(void)
327{
328 nss_ipv6_conn_sync_many_msg_cb = NULL;
329}
330
331/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700332 * nss_ipv6_get_mgr()
333 *
334 * TODO: This only suppports a single ipv6, do we ever want to support more?
335 */
336struct nss_ctx_instance *nss_ipv6_get_mgr(void)
337{
338 return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id];
339}
340
341/*
342 * nss_ipv6_register_handler()
343 * Register our handler to receive messages for this interface
344 */
345void nss_ipv6_register_handler()
346{
347 if (nss_core_register_handler(NSS_IPV6_RX_INTERFACE, nss_ipv6_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) {
348 nss_warning("IPv6 handler failed to register");
349 }
350}
351
Vijay Dewangan9db18752014-09-15 16:25:01 -0700352/*
Tushar Mathura3c18932015-08-24 20:27:21 +0530353 * nss_ipv6_conn_cfg_process()
354 * Process request to configure number of ipv6 connections
355 */
356static int nss_ipv6_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn,
357 void (*cfg_cb)(void *app_data, struct nss_ipv6_msg *nim))
358{
359 struct nss_ipv6_msg nim;
360 struct nss_ipv6_rule_conn_cfg_msg *nirccm;
361 nss_tx_status_t nss_tx_status;
362 uint32_t sum_of_conn;
363
364 /*
365 * Specifications for input
366 * 1) The input should be power of 2.
367 * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k
368 * 3) Min. value should be at leat 256 connections. This is the
369 * minimum connections we will support for each of them.
370 */
371 sum_of_conn = nss_ipv4_conn_cfg + conn;
372 if ((conn & NSS_NUM_CONN_QUANTA_MASK) ||
373 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
374 (conn < NSS_MIN_NUM_CONN)) {
375 nss_warning("%p: input supported connections (%d) does not adhere\
376 specifications\n1) not power of 2,\n2) is less than \
377 min val: %d, OR\n IPv4/6 total exceeds %d\n",
378 nss_ctx,
379 conn,
380 NSS_MIN_NUM_CONN,
381 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
382 return -EINVAL;
383 }
384
385 nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn);
386
387 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
388 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG,
389 sizeof(struct nss_ipv6_rule_conn_cfg_msg), cfg_cb, NULL);
390
391 nirccm = &nim.msg.rule_conn_cfg;
392 nirccm->num_conn = htonl(conn);
393 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
394
395 if (nss_tx_status != NSS_TX_SUCCESS) {
396 nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n",
397 nss_ctx,
398 conn);
399 return -EIO;
400 }
401
402 return 0;
403}
404
405/*
Vijay Dewangan9db18752014-09-15 16:25:01 -0700406 * nss_ipv6_conn_cfg_callback()
407 * call back function for the ipv6 connection configuration handler
408 */
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700409static void nss_ipv6_conn_cfg_callback(void *app_data, struct nss_ipv6_msg *nim)
Vijay Dewangan9db18752014-09-15 16:25:01 -0700410{
411 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700412 /*
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530413 * Error, hence we are not updating the nss_ipv6_conn_cfg
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700414 * Restore the current_value to its previous state
415 */
Vijay Dewangan488e5372014-12-29 21:40:11 -0800416 i6cfgp.response = NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700417 complete(&i6cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700418 return;
419 }
420
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700421 /*
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530422 * Sucess at NSS FW, hence updating nss_ipv6_conn_cfg, with the valid value
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700423 * saved at the sysctl handler.
424 */
Vijay Dewangan9db18752014-09-15 16:25:01 -0700425 nss_info("IPv6 connection configuration success: %d\n", nim->cm.error);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800426 i6cfgp.response = NSS_SUCCESS;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700427 complete(&i6cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700428}
429
430
431/*
432 * nss_ipv6_conn_cfg_handler()
433 * Sets the number of connections for IPv6
434 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700435static 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 -0700436{
437 struct nss_top_instance *nss_top = &nss_top_main;
438 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
Vijay Dewangan488e5372014-12-29 21:40:11 -0800439 int ret = NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700440
441 /*
442 * Acquiring semaphore
443 */
444 down(&i6cfgp.sem);
445
446 /*
447 * Take a snapshot of the current value
448 */
449 i6cfgp.current_value = nss_ipv6_conn_cfg;
450
451 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
452 if (ret || (!write)) {
453 up(&i6cfgp.sem);
454 return ret;
455 }
Vijay Dewangan9db18752014-09-15 16:25:01 -0700456
457 /*
Tushar Mathura3c18932015-08-24 20:27:21 +0530458 * Process request to change number of IPv6 connections
Vijay Dewangan9db18752014-09-15 16:25:01 -0700459 */
Tushar Mathura3c18932015-08-24 20:27:21 +0530460 ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_conn_cfg_callback);
461 if (ret != 0) {
Stephen Wang06761022015-03-03 16:38:42 -0800462 goto failure;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700463 }
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700464
465 /*
466 * Blocking call, wait till we get ACK for this msg.
467 */
468 ret = wait_for_completion_timeout(&i6cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
469 if (ret == 0) {
470 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
Stephen Wang06761022015-03-03 16:38:42 -0800471 goto failure;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700472 }
473
474 /*
475 * ACK/NACK received from NSS FW
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530476 * If ACK: Callback function will update nss_ipv6_conn_cfg with
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700477 * i6cfgp.num_conn_valid, which holds the user input
478 */
Vijay Dewangan488e5372014-12-29 21:40:11 -0800479 if (NSS_FAILURE == i6cfgp.response) {
Stephen Wang06761022015-03-03 16:38:42 -0800480 goto failure;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700481 }
482
483 up(&i6cfgp.sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700484 return 0;
Stephen Wang06761022015-03-03 16:38:42 -0800485
486failure:
487 /*
488 * Restore the current_value to its previous state
489 */
490 nss_ipv6_conn_cfg = i6cfgp.current_value;
491 up(&i6cfgp.sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700492 return -EINVAL;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700493}
494
Tushar Mathura3c18932015-08-24 20:27:21 +0530495/*
496 * nss_ipv6_update_conn_count_cb()
497 * call back function for the ipv6 connection count update handler
498 */
499static void nss_ipv6_update_conn_count_cb(void *app_data, struct nss_ipv6_msg *nim)
500{
501 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
502 nss_warning("IPv6 connection count update failed with error: %d\n", nim->cm.error);
503 return;
504 }
505
506 nss_warning("IPv6 connection count update success: %d\n", nim->cm.error);
507}
508
509/*
510 * nss_ipv6_update_conn_count()
511 * Sets the maximum number of connections for IPv6
512 */
513int nss_ipv6_update_conn_count(int ipv6_num_conn)
514{
515 struct nss_top_instance *nss_top = &nss_top_main;
516 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
517 int saved_nss_ipv6_conn_cfg = nss_ipv6_conn_cfg;
518 int ret = 0;
519
520 nss_ipv6_conn_cfg = ipv6_num_conn;
521
522 /*
523 * Process request to change number of IPv6 connections
524 */
525 ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_update_conn_count_cb);
526 if (ret != 0) {
527 goto failure;
528 }
529
530 return 0;
531
532failure:
533 nss_ipv6_conn_cfg = saved_nss_ipv6_conn_cfg;
534 return -EINVAL;
535}
536
Stephen Wang52e6d342016-03-29 15:02:33 -0700537static struct ctl_table nss_ipv6_table[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700538 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700539 .procname = "ipv6_conn",
540 .data = &nss_ipv6_conn_cfg,
541 .maxlen = sizeof(int),
542 .mode = 0644,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700543 .proc_handler = &nss_ipv6_conn_cfg_handler,
544 },
545 { }
546};
547
Stephen Wang52e6d342016-03-29 15:02:33 -0700548static struct ctl_table nss_ipv6_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700549 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700550 .procname = "ipv6cfg",
551 .mode = 0555,
552 .child = nss_ipv6_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700553 },
554 { }
555};
556
Stephen Wang52e6d342016-03-29 15:02:33 -0700557static struct ctl_table nss_ipv6_root_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700558 {
559 .procname = "nss",
560 .mode = 0555,
561 .child = nss_ipv6_dir,
562 },
563 { }
564};
565
Stephen Wang52e6d342016-03-29 15:02:33 -0700566static struct ctl_table nss_ipv6_root[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700567 {
568 .procname = "dev",
569 .mode = 0555,
570 .child = nss_ipv6_root_dir,
571 },
572 { }
573};
574
575static struct ctl_table_header *nss_ipv6_header;
576
577/*
578 * nss_ipv6_register_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530579 * Register sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700580 */
581void nss_ipv6_register_sysctl(void)
582{
Stephen Wang49b474b2016-03-25 10:40:30 -0700583 sema_init(&i6cfgp.sem, 1);
584 init_completion(&i6cfgp.complete);
585 i6cfgp.current_value = nss_ipv6_conn_cfg;
586
Vijay Dewangan9db18752014-09-15 16:25:01 -0700587 /*
588 * Register sysctl table.
589 */
590 nss_ipv6_header = register_sysctl_table(nss_ipv6_root);
591}
592
593/*
594 * nss_ipv6_unregister_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530595 * Unregister sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700596 */
597void nss_ipv6_unregister_sysctl(void)
598{
599 /*
600 * Unregister sysctl table.
601 */
602 if (nss_ipv6_header) {
603 unregister_sysctl_table(nss_ipv6_header);
604 }
605}
606
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700607/*
608 * nss_ipv6_msg_init()
609 * Initialize IPv6 message.
610 */
611void 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 -0800612 nss_ipv6_msg_callback_t cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700613{
614 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
615}
616
Sol Kavy879eb8b2014-04-07 19:11:31 -0700617EXPORT_SYMBOL(nss_ipv6_tx);
Stephen Wang709f9b52015-07-07 14:48:35 -0700618EXPORT_SYMBOL(nss_ipv6_tx_with_size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700619EXPORT_SYMBOL(nss_ipv6_notify_register);
620EXPORT_SYMBOL(nss_ipv6_notify_unregister);
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700621EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_register);
622EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_unregister);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700623EXPORT_SYMBOL(nss_ipv6_get_mgr);
624EXPORT_SYMBOL(nss_ipv6_register_handler);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700625EXPORT_SYMBOL(nss_ipv6_register_sysctl);
626EXPORT_SYMBOL(nss_ipv6_unregister_sysctl);
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700627EXPORT_SYMBOL(nss_ipv6_msg_init);
Tushar Mathura3c18932015-08-24 20:27:21 +0530628EXPORT_SYMBOL(nss_ipv6_update_conn_count);