blob: 348ac5003a13d3e507a9c281b5218eed467c0e66 [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/*
Gareth Williams958aa822015-02-04 19:36:39 +000027 * nss_ipv6_max_conn_count()
28 * Return the maximum number of IPv6 connections that the NSS acceleration engine supports.
29 */
30int nss_ipv6_max_conn_count(void)
31{
Tushar Mathur55ba1302015-09-08 13:14:48 +053032 return nss_core_max_ipv6_conn_get();
Gareth Williams958aa822015-02-04 19:36:39 +000033}
34EXPORT_SYMBOL(nss_ipv6_max_conn_count);
35
36/*
Sol Kavy879eb8b2014-04-07 19:11:31 -070037 * nss_ipv6_driver_conn_sync_update()
38 * Update driver specific information from the messsage.
39 */
40static void nss_ipv6_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync *nics)
41{
42 struct nss_top_instance *nss_top = nss_ctx->nss_top;
Sol Kavy879eb8b2014-04-07 19:11:31 -070043
44 /*
45 * Update statistics maintained by NSS driver
46 */
47 spin_lock_bh(&nss_top->stats_lock);
48 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_PKTS] += nics->flow_rx_packet_count + nics->return_rx_packet_count;
49 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_BYTES] += nics->flow_rx_byte_count + nics->return_rx_byte_count;
50 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_PKTS] += nics->flow_tx_packet_count + nics->return_tx_packet_count;
51 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 +053052 spin_unlock_bh(&nss_top->stats_lock);
Sol Kavy879eb8b2014-04-07 19:11:31 -070053}
54
55/*
Stephen Wang709f9b52015-07-07 14:48:35 -070056 * nss_ipv6_driver_conn_sync_many_update()
57 * Update driver specific information from the conn_sync_many messsage.
58 */
59static void nss_ipv6_driver_conn_sync_many_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync_many_msg *nicsm)
60{
61 uint32_t i;
62
63 /*
64 * Sanity check for the stats count
65 */
66 if (nicsm->count * sizeof(struct nss_ipv6_conn_sync) >= nicsm->size) {
67 nss_warning("%p: stats sync count %u exceeds the size of this msg %u", nss_ctx, nicsm->count, nicsm->size);
68 return;
69 }
70
71 for (i = 0; i < nicsm->count; i++) {
72 nss_ipv6_driver_conn_sync_update(nss_ctx, &nicsm->conn_sync[i]);
73 }
74}
75
76/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -070077 * nss_ipv6_driver_node_sync_update)
78 * Update driver specific information from the messsage.
79 */
80static void nss_ipv6_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_node_sync *nins)
81{
82 struct nss_top_instance *nss_top = nss_ctx->nss_top;
83 uint32_t i;
84
85 /*
86 * Update statistics maintained by NSS driver
87 */
88 spin_lock_bh(&nss_top->stats_lock);
89 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
90 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
91 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped;
92 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
93 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
94
Murat Sezgin0c0561d2014-04-09 18:55:58 -070095 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_REQUESTS] += nins->ipv6_connection_create_requests;
96 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_COLLISIONS] += nins->ipv6_connection_create_collisions;
97 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_connection_create_invalid_interface;
98 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_connection_destroy_requests;
99 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_MISSES] += nins->ipv6_connection_destroy_misses;
100 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_HITS] += nins->ipv6_connection_hash_hits;
101 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_REORDERS] += nins->ipv6_connection_hash_reorders;
102 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_FLUSHES] += nins->ipv6_connection_flushes;
103 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_EVICTIONS] += nins->ipv6_connection_evictions;
Selin Dag5d68caa2015-05-12 13:23:33 -0700104 nss_top->stats_ipv6[NSS_STATS_IPV6_FRAGMENTATIONS] += nins->ipv6_fragmentations;
105 nss_top->stats_ipv6[NSS_STATS_IPV6_FRAG_FAILS] += nins->ipv6_frag_fails;
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530106 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_REQUESTS] += nins->ipv6_mc_connection_create_requests;
107 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_UPDATE_REQUESTS] += nins->ipv6_mc_connection_update_requests;
108 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_mc_connection_create_invalid_interface;
109 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_mc_connection_destroy_requests;
110 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_MISSES] += nins->ipv6_mc_connection_destroy_misses;
111 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_FLUSHES] += nins->ipv6_mc_connection_flushes;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700112
113 for (i = 0; i < NSS_EXCEPTION_EVENT_IPV6_MAX; i++) {
114 nss_top->stats_if_exception_ipv6[i] += nins->exception_events[i];
115 }
116 spin_unlock_bh(&nss_top->stats_lock);
117}
118
119/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700120 * nss_ipv6_rx_msg_handler()
121 * Handle NSS -> HLOS messages for IPv6 bridge/route
122 */
123static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
124{
125 struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm;
126 nss_ipv6_msg_callback_t cb;
127
128 BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE);
129
130 /*
131 * Is this a valid request/response packet?
132 */
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700133 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700134 nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type);
135 return;
136 }
137
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800138 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
139 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -0700140 return;
141 }
142
143 /*
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700144 * Trace messages.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700145 */
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700146 nss_ipv6_log_rx_msg(nim);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700147
148 /*
149 * Handle deprecated messages. Eventually these messages should be removed.
150 */
151 switch (nim->cm.type) {
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700152 case NSS_IPV6_RX_NODE_STATS_SYNC_MSG:
153 /*
154 * Update driver statistics on node sync.
155 */
156 nss_ipv6_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
157 break;
158
Sol Kavy879eb8b2014-04-07 19:11:31 -0700159 case NSS_IPV6_RX_CONN_STATS_SYNC_MSG:
160 /*
161 * Update driver statistics on connection sync.
162 */
163 nss_ipv6_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700164 break;
Stephen Wang709f9b52015-07-07 14:48:35 -0700165
166 case NSS_IPV6_TX_CONN_STATS_SYNC_MANY_MSG:
167 /*
168 * Update driver statistics on connection sync many.
169 */
170 nss_ipv6_driver_conn_sync_many_update(nss_ctx, &nim->msg.conn_stats_many);
171 break;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700172 }
Abhishek Rastogi55f39452014-05-08 19:23:29 +0530173
Sol Kavy879eb8b2014-04-07 19:11:31 -0700174 /*
175 * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages
176 * to the same callback/app_data.
177 */
178 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
179 ncm->cb = (uint32_t)nss_ctx->nss_top->ipv6_callback;
180 ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv6_ctx;
181 }
182
183 /*
184 * Do we have a callback?
185 */
186 if (!ncm->cb) {
187 return;
188 }
189
190 /*
191 * Callback
192 */
193 cb = (nss_ipv6_msg_callback_t)ncm->cb;
194 cb((void *)ncm->app_data, nim);
195}
196
197/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700198 * nss_ipv6_tx_with_size()
199 * Transmit an ipv6 message to the FW with a specified size.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700200 */
Stephen Wang709f9b52015-07-07 14:48:35 -0700201nss_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 -0700202{
203 struct nss_ipv6_msg *nim2;
204 struct nss_cmn_msg *ncm = &nim->cm;
205 struct sk_buff *nbuf;
206 int32_t status;
207
208 NSS_VERIFY_CTX_MAGIC(nss_ctx);
209 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
210 nss_warning("%p: ipv6 msg dropped as core not ready", nss_ctx);
211 return NSS_TX_FAILURE_NOT_READY;
212 }
213
214 /*
215 * Sanity check the message
216 */
217 if (ncm->interface != NSS_IPV6_RX_INTERFACE) {
218 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
219 return NSS_TX_FAILURE;
220 }
221
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700222 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700223 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
224 return NSS_TX_FAILURE;
225 }
226
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800227 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
228 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -0700229 return NSS_TX_FAILURE;
230 }
231
Stephen Wang709f9b52015-07-07 14:48:35 -0700232 if(size > PAGE_SIZE) {
233 nss_warning("%p: tx request size too large: %u", nss_ctx, size);
234 return NSS_TX_FAILURE;
235 }
236
237 nbuf = dev_alloc_skb(size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700238 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -0800239 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 -0700240 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
241 return NSS_TX_FAILURE;
242 }
243
244 /*
245 * Copy the message to our skb.
246 */
247 nim2 = (struct nss_ipv6_msg *)skb_put(nbuf, sizeof(struct nss_ipv6_msg));
248 memcpy(nim2, nim, sizeof(struct nss_ipv6_msg));
249
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700250 /*
251 * Trace messages.
252 */
253 nss_ipv6_log_tx_msg(nim);
254
Sol Kavy879eb8b2014-04-07 19:11:31 -0700255 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
256 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530257 dev_kfree_skb_any(nbuf);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700258 nss_warning("%p: Unable to enqueue 'Destroy IPv6' rule\n", nss_ctx);
259 return NSS_TX_FAILURE;
260 }
261
262 nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
263 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
264
265 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
266 return NSS_TX_SUCCESS;
267}
268
269/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700270 * nss_ipv6_tx()
271 * Transmit an ipv4 message to the FW.
272 */
273nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim)
274{
275 return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE);
276}
277
278/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700279 **********************************
280 Register/Unregister/Miscellaneous APIs
281 **********************************
282 */
283
284/*
285 * nss_ipv6_notify_register()
286 * Register to received IPv6 events.
287 *
288 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
289 */
290struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data)
291{
292 /*
293 * TODO: We need to have a new array in support of the new API
294 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
295 */
296 nss_top_main.ipv6_callback = cb;
297 nss_top_main.ipv6_ctx = app_data;
298 return &nss_top_main.nss[nss_top_main.ipv6_handler_id];
299}
300
301/*
302 * nss_ipv6_notify_unregister()
303 * Unregister to received IPv6 events.
304 *
305 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
306 */
307void nss_ipv6_notify_unregister(void)
308{
309 nss_top_main.ipv6_callback = NULL;
310}
311
312/*
313 * nss_ipv6_get_mgr()
314 *
315 * TODO: This only suppports a single ipv6, do we ever want to support more?
316 */
317struct nss_ctx_instance *nss_ipv6_get_mgr(void)
318{
319 return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id];
320}
321
322/*
323 * nss_ipv6_register_handler()
324 * Register our handler to receive messages for this interface
325 */
326void nss_ipv6_register_handler()
327{
328 if (nss_core_register_handler(NSS_IPV6_RX_INTERFACE, nss_ipv6_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) {
329 nss_warning("IPv6 handler failed to register");
330 }
331}
332
Vijay Dewangan9db18752014-09-15 16:25:01 -0700333/*
Tushar Mathura3c18932015-08-24 20:27:21 +0530334 * nss_ipv6_conn_cfg_process()
335 * Process request to configure number of ipv6 connections
336 */
337static int nss_ipv6_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn,
338 void (*cfg_cb)(void *app_data, struct nss_ipv6_msg *nim))
339{
340 struct nss_ipv6_msg nim;
341 struct nss_ipv6_rule_conn_cfg_msg *nirccm;
342 nss_tx_status_t nss_tx_status;
343 uint32_t sum_of_conn;
344
345 /*
346 * Specifications for input
347 * 1) The input should be power of 2.
348 * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k
349 * 3) Min. value should be at leat 256 connections. This is the
350 * minimum connections we will support for each of them.
351 */
352 sum_of_conn = nss_ipv4_conn_cfg + conn;
353 if ((conn & NSS_NUM_CONN_QUANTA_MASK) ||
354 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
355 (conn < NSS_MIN_NUM_CONN)) {
356 nss_warning("%p: input supported connections (%d) does not adhere\
357 specifications\n1) not power of 2,\n2) is less than \
358 min val: %d, OR\n IPv4/6 total exceeds %d\n",
359 nss_ctx,
360 conn,
361 NSS_MIN_NUM_CONN,
362 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
363 return -EINVAL;
364 }
365
366 nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn);
367
368 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
369 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG,
370 sizeof(struct nss_ipv6_rule_conn_cfg_msg), cfg_cb, NULL);
371
372 nirccm = &nim.msg.rule_conn_cfg;
373 nirccm->num_conn = htonl(conn);
374 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
375
376 if (nss_tx_status != NSS_TX_SUCCESS) {
377 nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n",
378 nss_ctx,
379 conn);
380 return -EIO;
381 }
382
383 return 0;
384}
385
386/*
Vijay Dewangan9db18752014-09-15 16:25:01 -0700387 * nss_ipv6_conn_cfg_callback()
388 * call back function for the ipv6 connection configuration handler
389 */
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700390static void nss_ipv6_conn_cfg_callback(void *app_data, struct nss_ipv6_msg *nim)
Vijay Dewangan9db18752014-09-15 16:25:01 -0700391{
392 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700393 /*
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530394 * Error, hence we are not updating the nss_ipv6_conn_cfg
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700395 * Restore the current_value to its previous state
396 */
Vijay Dewangan488e5372014-12-29 21:40:11 -0800397 i6cfgp.response = NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700398 complete(&i6cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700399 return;
400 }
401
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700402 /*
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530403 * Sucess at NSS FW, hence updating nss_ipv6_conn_cfg, with the valid value
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700404 * saved at the sysctl handler.
405 */
Vijay Dewangan9db18752014-09-15 16:25:01 -0700406 nss_info("IPv6 connection configuration success: %d\n", nim->cm.error);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800407 i6cfgp.response = NSS_SUCCESS;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700408 complete(&i6cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700409}
410
411
412/*
413 * nss_ipv6_conn_cfg_handler()
414 * Sets the number of connections for IPv6
415 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700416static 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 -0700417{
418 struct nss_top_instance *nss_top = &nss_top_main;
419 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
Vijay Dewangan488e5372014-12-29 21:40:11 -0800420 int ret = NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700421
422 /*
423 * Acquiring semaphore
424 */
425 down(&i6cfgp.sem);
426
427 /*
428 * Take a snapshot of the current value
429 */
430 i6cfgp.current_value = nss_ipv6_conn_cfg;
431
432 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
433 if (ret || (!write)) {
434 up(&i6cfgp.sem);
435 return ret;
436 }
Vijay Dewangan9db18752014-09-15 16:25:01 -0700437
438 /*
Tushar Mathura3c18932015-08-24 20:27:21 +0530439 * Process request to change number of IPv6 connections
Vijay Dewangan9db18752014-09-15 16:25:01 -0700440 */
Tushar Mathura3c18932015-08-24 20:27:21 +0530441 ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_conn_cfg_callback);
442 if (ret != 0) {
Stephen Wang06761022015-03-03 16:38:42 -0800443 goto failure;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700444 }
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700445
446 /*
447 * Blocking call, wait till we get ACK for this msg.
448 */
449 ret = wait_for_completion_timeout(&i6cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
450 if (ret == 0) {
451 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
Stephen Wang06761022015-03-03 16:38:42 -0800452 goto failure;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700453 }
454
455 /*
456 * ACK/NACK received from NSS FW
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530457 * If ACK: Callback function will update nss_ipv6_conn_cfg with
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700458 * i6cfgp.num_conn_valid, which holds the user input
459 */
Vijay Dewangan488e5372014-12-29 21:40:11 -0800460 if (NSS_FAILURE == i6cfgp.response) {
Stephen Wang06761022015-03-03 16:38:42 -0800461 goto failure;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700462 }
463
464 up(&i6cfgp.sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700465 return 0;
Stephen Wang06761022015-03-03 16:38:42 -0800466
467failure:
468 /*
469 * Restore the current_value to its previous state
470 */
471 nss_ipv6_conn_cfg = i6cfgp.current_value;
472 up(&i6cfgp.sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700473 return -EINVAL;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700474}
475
Tushar Mathura3c18932015-08-24 20:27:21 +0530476/*
477 * nss_ipv6_update_conn_count_cb()
478 * call back function for the ipv6 connection count update handler
479 */
480static void nss_ipv6_update_conn_count_cb(void *app_data, struct nss_ipv6_msg *nim)
481{
482 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
483 nss_warning("IPv6 connection count update failed with error: %d\n", nim->cm.error);
484 return;
485 }
486
487 nss_warning("IPv6 connection count update success: %d\n", nim->cm.error);
488}
489
490/*
491 * nss_ipv6_update_conn_count()
492 * Sets the maximum number of connections for IPv6
493 */
494int nss_ipv6_update_conn_count(int ipv6_num_conn)
495{
496 struct nss_top_instance *nss_top = &nss_top_main;
497 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
498 int saved_nss_ipv6_conn_cfg = nss_ipv6_conn_cfg;
499 int ret = 0;
500
501 nss_ipv6_conn_cfg = ipv6_num_conn;
502
503 /*
504 * Process request to change number of IPv6 connections
505 */
506 ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_update_conn_count_cb);
507 if (ret != 0) {
508 goto failure;
509 }
510
511 return 0;
512
513failure:
514 nss_ipv6_conn_cfg = saved_nss_ipv6_conn_cfg;
515 return -EINVAL;
516}
517
Stephen Wang52e6d342016-03-29 15:02:33 -0700518static struct ctl_table nss_ipv6_table[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700519 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700520 .procname = "ipv6_conn",
521 .data = &nss_ipv6_conn_cfg,
522 .maxlen = sizeof(int),
523 .mode = 0644,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700524 .proc_handler = &nss_ipv6_conn_cfg_handler,
525 },
526 { }
527};
528
Stephen Wang52e6d342016-03-29 15:02:33 -0700529static struct ctl_table nss_ipv6_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700530 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700531 .procname = "ipv6cfg",
532 .mode = 0555,
533 .child = nss_ipv6_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700534 },
535 { }
536};
537
Stephen Wang52e6d342016-03-29 15:02:33 -0700538static struct ctl_table nss_ipv6_root_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700539 {
540 .procname = "nss",
541 .mode = 0555,
542 .child = nss_ipv6_dir,
543 },
544 { }
545};
546
Stephen Wang52e6d342016-03-29 15:02:33 -0700547static struct ctl_table nss_ipv6_root[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700548 {
549 .procname = "dev",
550 .mode = 0555,
551 .child = nss_ipv6_root_dir,
552 },
553 { }
554};
555
556static struct ctl_table_header *nss_ipv6_header;
557
558/*
559 * nss_ipv6_register_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530560 * Register sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700561 */
562void nss_ipv6_register_sysctl(void)
563{
Stephen Wang49b474b2016-03-25 10:40:30 -0700564 sema_init(&i6cfgp.sem, 1);
565 init_completion(&i6cfgp.complete);
566 i6cfgp.current_value = nss_ipv6_conn_cfg;
567
Vijay Dewangan9db18752014-09-15 16:25:01 -0700568 /*
569 * Register sysctl table.
570 */
571 nss_ipv6_header = register_sysctl_table(nss_ipv6_root);
572}
573
574/*
575 * nss_ipv6_unregister_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530576 * Unregister sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700577 */
578void nss_ipv6_unregister_sysctl(void)
579{
580 /*
581 * Unregister sysctl table.
582 */
583 if (nss_ipv6_header) {
584 unregister_sysctl_table(nss_ipv6_header);
585 }
586}
587
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700588/*
589 * nss_ipv6_msg_init()
590 * Initialize IPv6 message.
591 */
592void 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 -0800593 nss_ipv6_msg_callback_t cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700594{
595 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
596}
597
Sol Kavy879eb8b2014-04-07 19:11:31 -0700598EXPORT_SYMBOL(nss_ipv6_tx);
Stephen Wang709f9b52015-07-07 14:48:35 -0700599EXPORT_SYMBOL(nss_ipv6_tx_with_size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700600EXPORT_SYMBOL(nss_ipv6_notify_register);
601EXPORT_SYMBOL(nss_ipv6_notify_unregister);
602EXPORT_SYMBOL(nss_ipv6_get_mgr);
603EXPORT_SYMBOL(nss_ipv6_register_handler);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700604EXPORT_SYMBOL(nss_ipv6_register_sysctl);
605EXPORT_SYMBOL(nss_ipv6_unregister_sysctl);
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700606EXPORT_SYMBOL(nss_ipv6_msg_init);
Tushar Mathura3c18932015-08-24 20:27:21 +0530607EXPORT_SYMBOL(nss_ipv6_update_conn_count);