blob: c5a6590810e119517aa164c6b5bc424180fb4a04 [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/*
Guojun Jin9a1cb282017-07-13 17:32:07 -070057 * nss_ipv6_conn_inquiry()
58 * Inquiry if a connection has been established in NSS FW
59 */
60nss_tx_status_t nss_ipv6_conn_inquiry(struct nss_ipv6_5tuple *ipv6_5t_p,
61 nss_ipv6_msg_callback_t cb)
62{
63 nss_tx_status_t nss_tx_status;
64 struct nss_ipv6_msg nim;
65 struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[0];
66
67 /*
68 * Initialize inquiry message structure.
69 * This is async message and the result will be returned
70 * to the caller by the msg_callback passed in.
71 */
72 memset(&nim, 0, sizeof(nim));
73 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE,
74 NSS_IPV6_TX_CONN_CFG_INQUIRY_MSG,
75 sizeof(struct nss_ipv6_inquiry_msg),
76 cb, NULL);
77 nim.msg.inquiry.rr.tuple = *ipv6_5t_p;
78 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
79 if (nss_tx_status != NSS_TX_SUCCESS) {
80 nss_warning("%p: Send inquiry message failed\n", ipv6_5t_p);
81 }
82
83 return nss_tx_status;
84}
85EXPORT_SYMBOL(nss_ipv6_conn_inquiry);
86
87/*
Sol Kavy879eb8b2014-04-07 19:11:31 -070088 * nss_ipv6_driver_conn_sync_update()
89 * Update driver specific information from the messsage.
90 */
91static void nss_ipv6_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync *nics)
92{
93 struct nss_top_instance *nss_top = nss_ctx->nss_top;
Sol Kavy879eb8b2014-04-07 19:11:31 -070094
95 /*
96 * Update statistics maintained by NSS driver
97 */
98 spin_lock_bh(&nss_top->stats_lock);
99 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_PKTS] += nics->flow_rx_packet_count + nics->return_rx_packet_count;
100 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_BYTES] += nics->flow_rx_byte_count + nics->return_rx_byte_count;
101 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_PKTS] += nics->flow_tx_packet_count + nics->return_tx_packet_count;
102 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 +0530103 spin_unlock_bh(&nss_top->stats_lock);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700104}
105
106/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700107 * nss_ipv6_driver_conn_sync_many_update()
108 * Update driver specific information from the conn_sync_many messsage.
109 */
110static void nss_ipv6_driver_conn_sync_many_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync_many_msg *nicsm)
111{
112 uint32_t i;
113
114 /*
115 * Sanity check for the stats count
116 */
117 if (nicsm->count * sizeof(struct nss_ipv6_conn_sync) >= nicsm->size) {
118 nss_warning("%p: stats sync count %u exceeds the size of this msg %u", nss_ctx, nicsm->count, nicsm->size);
119 return;
120 }
121
122 for (i = 0; i < nicsm->count; i++) {
123 nss_ipv6_driver_conn_sync_update(nss_ctx, &nicsm->conn_sync[i]);
124 }
125}
126
127/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700128 * nss_ipv6_driver_node_sync_update)
129 * Update driver specific information from the messsage.
130 */
131static void nss_ipv6_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_node_sync *nins)
132{
133 struct nss_top_instance *nss_top = nss_ctx->nss_top;
134 uint32_t i;
135
136 /*
137 * Update statistics maintained by NSS driver
138 */
139 spin_lock_bh(&nss_top->stats_lock);
140 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
141 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
142 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped;
143 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
144 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
145
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700146 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_REQUESTS] += nins->ipv6_connection_create_requests;
147 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_COLLISIONS] += nins->ipv6_connection_create_collisions;
148 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_connection_create_invalid_interface;
149 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_connection_destroy_requests;
150 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_MISSES] += nins->ipv6_connection_destroy_misses;
151 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_HITS] += nins->ipv6_connection_hash_hits;
152 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_REORDERS] += nins->ipv6_connection_hash_reorders;
153 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_FLUSHES] += nins->ipv6_connection_flushes;
154 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_EVICTIONS] += nins->ipv6_connection_evictions;
Selin Dag5d68caa2015-05-12 13:23:33 -0700155 nss_top->stats_ipv6[NSS_STATS_IPV6_FRAGMENTATIONS] += nins->ipv6_fragmentations;
156 nss_top->stats_ipv6[NSS_STATS_IPV6_FRAG_FAILS] += nins->ipv6_frag_fails;
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530157 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_REQUESTS] += nins->ipv6_mc_connection_create_requests;
158 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_UPDATE_REQUESTS] += nins->ipv6_mc_connection_update_requests;
159 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_mc_connection_create_invalid_interface;
160 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_mc_connection_destroy_requests;
161 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_MISSES] += nins->ipv6_mc_connection_destroy_misses;
162 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_FLUSHES] += nins->ipv6_mc_connection_flushes;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700163
164 for (i = 0; i < NSS_EXCEPTION_EVENT_IPV6_MAX; i++) {
165 nss_top->stats_if_exception_ipv6[i] += nins->exception_events[i];
166 }
167 spin_unlock_bh(&nss_top->stats_lock);
168}
169
170/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700171 * nss_ipv6_rx_msg_handler()
172 * Handle NSS -> HLOS messages for IPv6 bridge/route
173 */
174static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
175{
176 struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm;
177 nss_ipv6_msg_callback_t cb;
178
179 BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE);
180
181 /*
182 * Is this a valid request/response packet?
183 */
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700184 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700185 nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type);
186 return;
187 }
188
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800189 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
190 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -0700191 return;
192 }
193
194 /*
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700195 * Trace messages.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700196 */
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700197 nss_ipv6_log_rx_msg(nim);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700198
199 /*
Stephen Wang0a2756a2016-08-04 15:52:47 -0700200 * Handle deprecated messages. Eventually these messages should be removed.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700201 */
202 switch (nim->cm.type) {
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700203 case NSS_IPV6_RX_NODE_STATS_SYNC_MSG:
204 /*
205 * Update driver statistics on node sync.
206 */
207 nss_ipv6_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
208 break;
209
Sol Kavy879eb8b2014-04-07 19:11:31 -0700210 case NSS_IPV6_RX_CONN_STATS_SYNC_MSG:
211 /*
212 * Update driver statistics on connection sync.
213 */
214 nss_ipv6_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700215 break;
Stephen Wang709f9b52015-07-07 14:48:35 -0700216
217 case NSS_IPV6_TX_CONN_STATS_SYNC_MANY_MSG:
218 /*
219 * Update driver statistics on connection sync many.
220 */
221 nss_ipv6_driver_conn_sync_many_update(nss_ctx, &nim->msg.conn_stats_many);
Stephen Wangaed46332016-12-12 17:29:03 -0800222 ncm->cb = (nss_ptr_t)nss_ipv6_conn_sync_many_msg_cb;
Stephen Wang709f9b52015-07-07 14:48:35 -0700223 break;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700224 }
Abhishek Rastogi55f39452014-05-08 19:23:29 +0530225
Sol Kavy879eb8b2014-04-07 19:11:31 -0700226 /*
227 * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages
228 * to the same callback/app_data.
229 */
230 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800231 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->ipv6_callback;
232 ncm->app_data = (nss_ptr_t)nss_ctx->nss_top->ipv6_ctx;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700233 }
234
235 /*
236 * Do we have a callback?
237 */
238 if (!ncm->cb) {
239 return;
240 }
241
242 /*
243 * Callback
244 */
245 cb = (nss_ipv6_msg_callback_t)ncm->cb;
246 cb((void *)ncm->app_data, nim);
247}
248
249/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700250 * nss_ipv6_tx_with_size()
251 * Transmit an ipv6 message to the FW with a specified size.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700252 */
Stephen Wang709f9b52015-07-07 14:48:35 -0700253nss_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 -0700254{
255 struct nss_ipv6_msg *nim2;
256 struct nss_cmn_msg *ncm = &nim->cm;
257 struct sk_buff *nbuf;
258 int32_t status;
259
260 NSS_VERIFY_CTX_MAGIC(nss_ctx);
261 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
262 nss_warning("%p: ipv6 msg dropped as core not ready", nss_ctx);
263 return NSS_TX_FAILURE_NOT_READY;
264 }
265
266 /*
267 * Sanity check the message
268 */
269 if (ncm->interface != NSS_IPV6_RX_INTERFACE) {
270 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
271 return NSS_TX_FAILURE;
272 }
273
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700274 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700275 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
276 return NSS_TX_FAILURE;
277 }
278
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800279 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
280 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -0700281 return NSS_TX_FAILURE;
282 }
283
Stephen Wang709f9b52015-07-07 14:48:35 -0700284 if(size > PAGE_SIZE) {
285 nss_warning("%p: tx request size too large: %u", nss_ctx, size);
286 return NSS_TX_FAILURE;
287 }
288
289 nbuf = dev_alloc_skb(size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700290 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -0800291 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 -0700292 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
293 return NSS_TX_FAILURE;
294 }
295
296 /*
297 * Copy the message to our skb.
298 */
Suruchi Agarwalea2e5232016-09-14 10:32:08 -0700299 nim2 = (struct nss_ipv6_msg *)skb_put(nbuf, size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700300 memcpy(nim2, nim, sizeof(struct nss_ipv6_msg));
301
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700302 /*
303 * Trace messages.
304 */
305 nss_ipv6_log_tx_msg(nim);
306
Sol Kavy879eb8b2014-04-07 19:11:31 -0700307 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
308 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530309 dev_kfree_skb_any(nbuf);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700310 nss_warning("%p: Unable to enqueue 'Destroy IPv6' rule\n", nss_ctx);
311 return NSS_TX_FAILURE;
312 }
313
Stephen Wang90c67de2016-04-26 15:15:59 -0700314 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700315
316 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
317 return NSS_TX_SUCCESS;
318}
319
320/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700321 * nss_ipv6_tx()
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700322 * Transmit an ipv6 message to the FW.
Stephen Wang709f9b52015-07-07 14:48:35 -0700323 */
324nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim)
325{
326 return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE);
327}
328
329/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700330 **********************************
331 Register/Unregister/Miscellaneous APIs
332 **********************************
333 */
334
335/*
336 * nss_ipv6_notify_register()
337 * Register to received IPv6 events.
338 *
339 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
340 */
341struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data)
342{
343 /*
344 * TODO: We need to have a new array in support of the new API
345 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
346 */
347 nss_top_main.ipv6_callback = cb;
348 nss_top_main.ipv6_ctx = app_data;
349 return &nss_top_main.nss[nss_top_main.ipv6_handler_id];
350}
351
352/*
353 * nss_ipv6_notify_unregister()
354 * Unregister to received IPv6 events.
355 *
356 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
357 */
358void nss_ipv6_notify_unregister(void)
359{
360 nss_top_main.ipv6_callback = NULL;
361}
362
363/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700364 * nss_ipv6_conn_sync_many_notify_register()
365 * Register to receive IPv6 conn_sync_many message response.
366 */
367void nss_ipv6_conn_sync_many_notify_register(nss_ipv6_msg_callback_t cb)
368{
369 nss_ipv6_conn_sync_many_msg_cb = cb;
370}
371
372/*
373 * nss_ipv6_conn_sync_many_notify_unregister()
374 * Unregister to receive IPv6 conn_sync_many message response.
375 */
376void nss_ipv6_conn_sync_many_notify_unregister(void)
377{
378 nss_ipv6_conn_sync_many_msg_cb = NULL;
379}
380
381/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700382 * nss_ipv6_get_mgr()
383 *
384 * TODO: This only suppports a single ipv6, do we ever want to support more?
385 */
386struct nss_ctx_instance *nss_ipv6_get_mgr(void)
387{
388 return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id];
389}
390
391/*
392 * nss_ipv6_register_handler()
393 * Register our handler to receive messages for this interface
394 */
395void nss_ipv6_register_handler()
396{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700397 struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr();
398
399 if (nss_core_register_handler(nss_ctx, NSS_IPV6_RX_INTERFACE, nss_ipv6_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700400 nss_warning("IPv6 handler failed to register");
401 }
402}
403
Vijay Dewangan9db18752014-09-15 16:25:01 -0700404/*
Tushar Mathura3c18932015-08-24 20:27:21 +0530405 * nss_ipv6_conn_cfg_process()
406 * Process request to configure number of ipv6 connections
407 */
408static int nss_ipv6_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn,
409 void (*cfg_cb)(void *app_data, struct nss_ipv6_msg *nim))
410{
411 struct nss_ipv6_msg nim;
412 struct nss_ipv6_rule_conn_cfg_msg *nirccm;
413 nss_tx_status_t nss_tx_status;
414 uint32_t sum_of_conn;
415
416 /*
417 * Specifications for input
418 * 1) The input should be power of 2.
419 * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k
420 * 3) Min. value should be at leat 256 connections. This is the
421 * minimum connections we will support for each of them.
422 */
423 sum_of_conn = nss_ipv4_conn_cfg + conn;
424 if ((conn & NSS_NUM_CONN_QUANTA_MASK) ||
425 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
426 (conn < NSS_MIN_NUM_CONN)) {
427 nss_warning("%p: input supported connections (%d) does not adhere\
428 specifications\n1) not power of 2,\n2) is less than \
429 min val: %d, OR\n IPv4/6 total exceeds %d\n",
430 nss_ctx,
431 conn,
432 NSS_MIN_NUM_CONN,
433 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
434 return -EINVAL;
435 }
436
437 nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn);
438
439 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
440 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG,
441 sizeof(struct nss_ipv6_rule_conn_cfg_msg), cfg_cb, NULL);
442
443 nirccm = &nim.msg.rule_conn_cfg;
444 nirccm->num_conn = htonl(conn);
445 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
446
447 if (nss_tx_status != NSS_TX_SUCCESS) {
448 nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n",
449 nss_ctx,
450 conn);
451 return -EIO;
452 }
453
454 return 0;
455}
456
457/*
Vijay Dewangan9db18752014-09-15 16:25:01 -0700458 * nss_ipv6_conn_cfg_callback()
459 * call back function for the ipv6 connection configuration handler
460 */
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700461static void nss_ipv6_conn_cfg_callback(void *app_data, struct nss_ipv6_msg *nim)
Vijay Dewangan9db18752014-09-15 16:25:01 -0700462{
463 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700464 /*
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530465 * Error, hence we are not updating the nss_ipv6_conn_cfg
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700466 * Restore the current_value to its previous state
467 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700468 i6_conn_cfgp.response = NSS_FAILURE;
469 complete(&i6_conn_cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700470 return;
471 }
472
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700473 /*
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530474 * Sucess at NSS FW, hence updating nss_ipv6_conn_cfg, with the valid value
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700475 * saved at the sysctl handler.
476 */
Vijay Dewangan9db18752014-09-15 16:25:01 -0700477 nss_info("IPv6 connection configuration success: %d\n", nim->cm.error);
Stephen Wang0a2756a2016-08-04 15:52:47 -0700478 i6_conn_cfgp.response = NSS_SUCCESS;
479 complete(&i6_conn_cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700480}
481
482
483/*
484 * nss_ipv6_conn_cfg_handler()
485 * Sets the number of connections for IPv6
486 */
Stephen Wang52e6d342016-03-29 15:02:33 -0700487static 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 -0700488{
489 struct nss_top_instance *nss_top = &nss_top_main;
490 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
Vijay Dewangan488e5372014-12-29 21:40:11 -0800491 int ret = NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700492
493 /*
494 * Acquiring semaphore
495 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700496 down(&i6_conn_cfgp.sem);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700497
498 /*
499 * Take a snapshot of the current value
500 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700501 i6_conn_cfgp.current_value = nss_ipv6_conn_cfg;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700502
503 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
504 if (ret || (!write)) {
Stephen Wang0a2756a2016-08-04 15:52:47 -0700505 up(&i6_conn_cfgp.sem);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700506 return ret;
507 }
Vijay Dewangan9db18752014-09-15 16:25:01 -0700508
509 /*
Tushar Mathura3c18932015-08-24 20:27:21 +0530510 * Process request to change number of IPv6 connections
Vijay Dewangan9db18752014-09-15 16:25:01 -0700511 */
Tushar Mathura3c18932015-08-24 20:27:21 +0530512 ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_conn_cfg_callback);
513 if (ret != 0) {
Stephen Wang06761022015-03-03 16:38:42 -0800514 goto failure;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700515 }
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700516
517 /*
518 * Blocking call, wait till we get ACK for this msg.
519 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700520 ret = wait_for_completion_timeout(&i6_conn_cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700521 if (ret == 0) {
522 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
Stephen Wang06761022015-03-03 16:38:42 -0800523 goto failure;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700524 }
525
526 /*
527 * ACK/NACK received from NSS FW
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530528 * If ACK: Callback function will update nss_ipv6_conn_cfg with
Stephen Wang0a2756a2016-08-04 15:52:47 -0700529 * i6_conn_cfgp.num_conn_valid, which holds the user input
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700530 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700531 if (NSS_FAILURE == i6_conn_cfgp.response) {
Stephen Wang06761022015-03-03 16:38:42 -0800532 goto failure;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700533 }
534
Stephen Wang0a2756a2016-08-04 15:52:47 -0700535 up(&i6_conn_cfgp.sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700536 return 0;
Stephen Wang06761022015-03-03 16:38:42 -0800537
538failure:
539 /*
540 * Restore the current_value to its previous state
541 */
Stephen Wang0a2756a2016-08-04 15:52:47 -0700542 nss_ipv6_conn_cfg = i6_conn_cfgp.current_value;
543 up(&i6_conn_cfgp.sem);
Thomas Wu651b3902015-05-12 11:21:09 -0700544 return -EINVAL;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700545}
546
Tushar Mathura3c18932015-08-24 20:27:21 +0530547/*
548 * nss_ipv6_update_conn_count_cb()
549 * call back function for the ipv6 connection count update handler
550 */
551static void nss_ipv6_update_conn_count_cb(void *app_data, struct nss_ipv6_msg *nim)
552{
553 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
554 nss_warning("IPv6 connection count update failed with error: %d\n", nim->cm.error);
555 return;
556 }
557
558 nss_warning("IPv6 connection count update success: %d\n", nim->cm.error);
559}
560
561/*
562 * nss_ipv6_update_conn_count()
563 * Sets the maximum number of connections for IPv6
564 */
565int nss_ipv6_update_conn_count(int ipv6_num_conn)
566{
567 struct nss_top_instance *nss_top = &nss_top_main;
568 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
569 int saved_nss_ipv6_conn_cfg = nss_ipv6_conn_cfg;
570 int ret = 0;
571
572 nss_ipv6_conn_cfg = ipv6_num_conn;
573
574 /*
575 * Process request to change number of IPv6 connections
576 */
577 ret = nss_ipv6_conn_cfg_process(nss_ctx, nss_ipv6_conn_cfg, nss_ipv6_update_conn_count_cb);
578 if (ret != 0) {
579 goto failure;
580 }
581
582 return 0;
583
584failure:
585 nss_ipv6_conn_cfg = saved_nss_ipv6_conn_cfg;
586 return -EINVAL;
587}
588
Stephen Wang0a2756a2016-08-04 15:52:47 -0700589/*
590 * nss_ipv6_accel_mode_cfg_callback()
591 * call back function for the ipv6 acceleration mode configurate handler
592 */
593static void nss_ipv6_accel_mode_cfg_callback(void *app_data, struct nss_ipv6_msg *nim)
594{
595 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
596 nss_warning("IPv6 acceleration mode configuration failed with error: %d\n", nim->cm.error);
597 i6_accel_mode_cfgp.response = NSS_FAILURE;
598 complete(&i6_accel_mode_cfgp.complete);
599 return;
600 }
601
602 nss_info("IPv6 acceleration mode configuration success\n");
603 i6_accel_mode_cfgp.response = NSS_SUCCESS;
604 complete(&i6_accel_mode_cfgp.complete);
605}
606
607/*
608 * nss_ipv6_accel_mode_cfg_handler()
609 * Configure acceleration mode for IPv6
610 */
611static int nss_ipv6_accel_mode_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
612{
613 struct nss_top_instance *nss_top = &nss_top_main;
614 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
615 struct nss_ipv6_msg nim;
616 struct nss_ipv6_accel_mode_cfg_msg *nipcm;
617 nss_tx_status_t nss_tx_status;
618 int ret = NSS_FAILURE;
619
620 /*
621 * Acquiring semaphore
622 */
623 down(&i6_accel_mode_cfgp.sem);
624
625 /*
626 * Take snap shot of current value
627 */
628 i6_accel_mode_cfgp.current_value = nss_ipv6_accel_mode_cfg;
629
630 /*
631 * Write the variable with user input
632 */
633 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
634 if (ret || (!write)) {
635 up(&i6_accel_mode_cfgp.sem);
636 return ret;
637 }
638
639 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
640 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_ACCEL_MODE_CFG_MSG,
641 sizeof(struct nss_ipv6_accel_mode_cfg_msg), nss_ipv6_accel_mode_cfg_callback, NULL);
642
643 nipcm = &nim.msg.accel_mode_cfg;
644 nipcm->mode = htonl(nss_ipv6_accel_mode_cfg);
645 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
646
647 if (nss_tx_status != NSS_TX_SUCCESS) {
648 nss_warning("%p: Send acceleration mode message failed\n", nss_ctx);
649 goto fail;
650 }
651
652 /*
653 * Blocking call, wait till we get ACK for this msg.
654 */
655 ret = wait_for_completion_timeout(&i6_accel_mode_cfgp.complete, msecs_to_jiffies(NSS_IPV6_TX_MSG_TIMEOUT));
656 if (ret == 0) {
657 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
658 goto fail;
659 }
660
661 if (NSS_FAILURE == i6_accel_mode_cfgp.response) {
662 nss_warning("%p: accel mode configure failed\n", nss_ctx);
663 goto fail;
664 }
665
666 up(&i6_accel_mode_cfgp.sem);
667 return 0;
668
669fail:
670 nss_ipv6_accel_mode_cfg = i6_accel_mode_cfgp.current_value;
671 up(&i6_accel_mode_cfgp.sem);
672 return -EIO;
673}
674
Stephen Wang52e6d342016-03-29 15:02:33 -0700675static struct ctl_table nss_ipv6_table[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700676 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700677 .procname = "ipv6_conn",
678 .data = &nss_ipv6_conn_cfg,
679 .maxlen = sizeof(int),
680 .mode = 0644,
Stephen Wang0a2756a2016-08-04 15:52:47 -0700681 .proc_handler = &nss_ipv6_conn_cfg_handler,
682 },
683 {
684 .procname = "ipv6_accel_mode",
685 .data = &nss_ipv6_accel_mode_cfg,
686 .maxlen = sizeof(int),
687 .mode = 0644,
688 .proc_handler = &nss_ipv6_accel_mode_cfg_handler,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700689 },
690 { }
691};
692
Stephen Wang52e6d342016-03-29 15:02:33 -0700693static struct ctl_table nss_ipv6_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700694 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700695 .procname = "ipv6cfg",
696 .mode = 0555,
697 .child = nss_ipv6_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700698 },
699 { }
700};
701
Stephen Wang52e6d342016-03-29 15:02:33 -0700702static struct ctl_table nss_ipv6_root_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700703 {
704 .procname = "nss",
705 .mode = 0555,
706 .child = nss_ipv6_dir,
707 },
708 { }
709};
710
Stephen Wang52e6d342016-03-29 15:02:33 -0700711static struct ctl_table nss_ipv6_root[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700712 {
713 .procname = "dev",
714 .mode = 0555,
715 .child = nss_ipv6_root_dir,
716 },
717 { }
718};
719
720static struct ctl_table_header *nss_ipv6_header;
721
722/*
723 * nss_ipv6_register_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530724 * Register sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700725 */
726void nss_ipv6_register_sysctl(void)
727{
Stephen Wang0a2756a2016-08-04 15:52:47 -0700728 sema_init(&i6_conn_cfgp.sem, 1);
729 init_completion(&i6_conn_cfgp.complete);
730
731 sema_init(&i6_accel_mode_cfgp.sem, 1);
732 init_completion(&i6_accel_mode_cfgp.complete);
Stephen Wang49b474b2016-03-25 10:40:30 -0700733
Vijay Dewangan9db18752014-09-15 16:25:01 -0700734 /*
735 * Register sysctl table.
736 */
737 nss_ipv6_header = register_sysctl_table(nss_ipv6_root);
738}
739
740/*
741 * nss_ipv6_unregister_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530742 * Unregister sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700743 */
744void nss_ipv6_unregister_sysctl(void)
745{
746 /*
747 * Unregister sysctl table.
748 */
749 if (nss_ipv6_header) {
750 unregister_sysctl_table(nss_ipv6_header);
751 }
752}
753
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700754/*
755 * nss_ipv6_msg_init()
Stephen Wang0a2756a2016-08-04 15:52:47 -0700756 * Initialize IPv6 message.
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700757 */
758void 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 -0800759 nss_ipv6_msg_callback_t cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700760{
761 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
762}
763
Sol Kavy879eb8b2014-04-07 19:11:31 -0700764EXPORT_SYMBOL(nss_ipv6_tx);
Stephen Wang709f9b52015-07-07 14:48:35 -0700765EXPORT_SYMBOL(nss_ipv6_tx_with_size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700766EXPORT_SYMBOL(nss_ipv6_notify_register);
767EXPORT_SYMBOL(nss_ipv6_notify_unregister);
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700768EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_register);
769EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_unregister);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700770EXPORT_SYMBOL(nss_ipv6_get_mgr);
771EXPORT_SYMBOL(nss_ipv6_register_handler);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700772EXPORT_SYMBOL(nss_ipv6_register_sysctl);
773EXPORT_SYMBOL(nss_ipv6_unregister_sysctl);
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700774EXPORT_SYMBOL(nss_ipv6_msg_init);
Tushar Mathura3c18932015-08-24 20:27:21 +0530775EXPORT_SYMBOL(nss_ipv6_update_conn_count);