blob: 44920ea0d877b5a148f2694e0bf88f32a8972289 [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
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -070035/*
36 * Private data structure for ipv4 connection information.
37 */
38struct nss_ipv6_conn_table_info {
39 uint32_t ce_table_size; /* Size of connection entry table in NSS FW */
40 uint32_t cme_table_size; /* Size of connection match entry table in NSS FW */
41 unsigned long ce_mem; /* Start address for connection entry table */
42 unsigned long cme_mem; /* Start address for connection match entry table */
43} nss_ipv6_ct_info;
Stephen Wang0a2756a2016-08-04 15:52:47 -070044
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -070045int nss_ipv6_conn_cfg = NSS_DEFAULT_NUM_CONN;
Stephen Wangf6a9acb2017-08-23 10:35:39 -070046int nss_ipv6_accel_mode_cfg __read_mostly = 1;
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -070047
Stephen Wang0a2756a2016-08-04 15:52:47 -070048static struct nss_ipv6_cfg_pvt i6_accel_mode_cfgp;
Vijay Dewangan9db18752014-09-15 16:25:01 -070049
Sol Kavy879eb8b2014-04-07 19:11:31 -070050/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -070051 * Callback for conn_sync_many request message.
52 */
53nss_ipv6_msg_callback_t nss_ipv6_conn_sync_many_msg_cb = NULL;
54
55/*
Gareth Williams958aa822015-02-04 19:36:39 +000056 * nss_ipv6_max_conn_count()
57 * Return the maximum number of IPv6 connections that the NSS acceleration engine supports.
58 */
59int nss_ipv6_max_conn_count(void)
60{
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -070061 return nss_ipv6_conn_cfg;
Gareth Williams958aa822015-02-04 19:36:39 +000062}
63EXPORT_SYMBOL(nss_ipv6_max_conn_count);
64
65/*
Guojun Jin9a1cb282017-07-13 17:32:07 -070066 * nss_ipv6_conn_inquiry()
67 * Inquiry if a connection has been established in NSS FW
68 */
69nss_tx_status_t nss_ipv6_conn_inquiry(struct nss_ipv6_5tuple *ipv6_5t_p,
70 nss_ipv6_msg_callback_t cb)
71{
72 nss_tx_status_t nss_tx_status;
73 struct nss_ipv6_msg nim;
74 struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[0];
75
76 /*
77 * Initialize inquiry message structure.
78 * This is async message and the result will be returned
79 * to the caller by the msg_callback passed in.
80 */
81 memset(&nim, 0, sizeof(nim));
82 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE,
83 NSS_IPV6_TX_CONN_CFG_INQUIRY_MSG,
84 sizeof(struct nss_ipv6_inquiry_msg),
85 cb, NULL);
86 nim.msg.inquiry.rr.tuple = *ipv6_5t_p;
87 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
88 if (nss_tx_status != NSS_TX_SUCCESS) {
89 nss_warning("%p: Send inquiry message failed\n", ipv6_5t_p);
90 }
91
92 return nss_tx_status;
93}
94EXPORT_SYMBOL(nss_ipv6_conn_inquiry);
95
96/*
Sol Kavy879eb8b2014-04-07 19:11:31 -070097 * nss_ipv6_driver_conn_sync_update()
98 * Update driver specific information from the messsage.
99 */
100static void nss_ipv6_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync *nics)
101{
102 struct nss_top_instance *nss_top = nss_ctx->nss_top;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700103
104 /*
105 * Update statistics maintained by NSS driver
106 */
107 spin_lock_bh(&nss_top->stats_lock);
108 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_PKTS] += nics->flow_rx_packet_count + nics->return_rx_packet_count;
109 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_RX_BYTES] += nics->flow_rx_byte_count + nics->return_rx_byte_count;
110 nss_top->stats_ipv6[NSS_STATS_IPV6_ACCELERATED_TX_PKTS] += nics->flow_tx_packet_count + nics->return_tx_packet_count;
111 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 +0530112 spin_unlock_bh(&nss_top->stats_lock);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700113}
114
115/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700116 * nss_ipv6_driver_conn_sync_many_update()
117 * Update driver specific information from the conn_sync_many messsage.
118 */
119static void nss_ipv6_driver_conn_sync_many_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_conn_sync_many_msg *nicsm)
120{
121 uint32_t i;
122
123 /*
124 * Sanity check for the stats count
125 */
126 if (nicsm->count * sizeof(struct nss_ipv6_conn_sync) >= nicsm->size) {
127 nss_warning("%p: stats sync count %u exceeds the size of this msg %u", nss_ctx, nicsm->count, nicsm->size);
128 return;
129 }
130
131 for (i = 0; i < nicsm->count; i++) {
132 nss_ipv6_driver_conn_sync_update(nss_ctx, &nicsm->conn_sync[i]);
133 }
134}
135
136/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700137 * nss_ipv6_driver_node_sync_update)
138 * Update driver specific information from the messsage.
139 */
140static void nss_ipv6_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_node_sync *nins)
141{
142 struct nss_top_instance *nss_top = nss_ctx->nss_top;
143 uint32_t i;
144
145 /*
146 * Update statistics maintained by NSS driver
147 */
148 spin_lock_bh(&nss_top->stats_lock);
149 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
150 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
151 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped;
152 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
153 nss_top->stats_node[NSS_IPV6_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
154
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700155 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_REQUESTS] += nins->ipv6_connection_create_requests;
156 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_COLLISIONS] += nins->ipv6_connection_create_collisions;
157 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_connection_create_invalid_interface;
158 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_connection_destroy_requests;
159 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_DESTROY_MISSES] += nins->ipv6_connection_destroy_misses;
160 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_HITS] += nins->ipv6_connection_hash_hits;
161 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_HASH_REORDERS] += nins->ipv6_connection_hash_reorders;
162 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_FLUSHES] += nins->ipv6_connection_flushes;
163 nss_top->stats_ipv6[NSS_STATS_IPV6_CONNECTION_EVICTIONS] += nins->ipv6_connection_evictions;
Selin Dag5d68caa2015-05-12 13:23:33 -0700164 nss_top->stats_ipv6[NSS_STATS_IPV6_FRAGMENTATIONS] += nins->ipv6_fragmentations;
165 nss_top->stats_ipv6[NSS_STATS_IPV6_FRAG_FAILS] += nins->ipv6_frag_fails;
Jackson Bockus140d2b22017-08-10 13:56:44 -0700166 nss_top->stats_ipv6[NSS_STATS_IPV6_DROPPED_BY_RULE] += nins->ipv6_dropped_by_rule;
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530167 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_REQUESTS] += nins->ipv6_mc_connection_create_requests;
168 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_UPDATE_REQUESTS] += nins->ipv6_mc_connection_update_requests;
169 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv6_mc_connection_create_invalid_interface;
170 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_REQUESTS] += nins->ipv6_mc_connection_destroy_requests;
171 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_DESTROY_MISSES] += nins->ipv6_mc_connection_destroy_misses;
172 nss_top->stats_ipv6[NSS_STATS_IPV6_MC_CONNECTION_FLUSHES] += nins->ipv6_mc_connection_flushes;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700173
174 for (i = 0; i < NSS_EXCEPTION_EVENT_IPV6_MAX; i++) {
175 nss_top->stats_if_exception_ipv6[i] += nins->exception_events[i];
176 }
177 spin_unlock_bh(&nss_top->stats_lock);
178}
179
180/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700181 * nss_ipv6_rx_msg_handler()
182 * Handle NSS -> HLOS messages for IPv6 bridge/route
183 */
184static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
185{
186 struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm;
187 nss_ipv6_msg_callback_t cb;
188
189 BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE);
190
191 /*
192 * Is this a valid request/response packet?
193 */
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700194 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700195 nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type);
196 return;
197 }
198
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800199 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
200 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -0700201 return;
202 }
203
204 /*
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700205 * Trace messages.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700206 */
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700207 nss_ipv6_log_rx_msg(nim);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700208
209 /*
Stephen Wang0a2756a2016-08-04 15:52:47 -0700210 * Handle deprecated messages. Eventually these messages should be removed.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700211 */
212 switch (nim->cm.type) {
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700213 case NSS_IPV6_RX_NODE_STATS_SYNC_MSG:
214 /*
215 * Update driver statistics on node sync.
216 */
217 nss_ipv6_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
218 break;
219
Sol Kavy879eb8b2014-04-07 19:11:31 -0700220 case NSS_IPV6_RX_CONN_STATS_SYNC_MSG:
221 /*
222 * Update driver statistics on connection sync.
223 */
224 nss_ipv6_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700225 break;
Stephen Wang709f9b52015-07-07 14:48:35 -0700226
227 case NSS_IPV6_TX_CONN_STATS_SYNC_MANY_MSG:
228 /*
229 * Update driver statistics on connection sync many.
230 */
231 nss_ipv6_driver_conn_sync_many_update(nss_ctx, &nim->msg.conn_stats_many);
Stephen Wangaed46332016-12-12 17:29:03 -0800232 ncm->cb = (nss_ptr_t)nss_ipv6_conn_sync_many_msg_cb;
Stephen Wang709f9b52015-07-07 14:48:35 -0700233 break;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700234 }
Abhishek Rastogi55f39452014-05-08 19:23:29 +0530235
Sol Kavy879eb8b2014-04-07 19:11:31 -0700236 /*
237 * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages
238 * to the same callback/app_data.
239 */
240 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800241 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->ipv6_callback;
242 ncm->app_data = (nss_ptr_t)nss_ctx->nss_top->ipv6_ctx;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700243 }
244
245 /*
246 * Do we have a callback?
247 */
248 if (!ncm->cb) {
249 return;
250 }
251
252 /*
253 * Callback
254 */
255 cb = (nss_ipv6_msg_callback_t)ncm->cb;
256 cb((void *)ncm->app_data, nim);
257}
258
259/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700260 * nss_ipv6_tx_with_size()
261 * Transmit an ipv6 message to the FW with a specified size.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700262 */
Stephen Wang709f9b52015-07-07 14:48:35 -0700263nss_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 -0700264{
265 struct nss_ipv6_msg *nim2;
266 struct nss_cmn_msg *ncm = &nim->cm;
267 struct sk_buff *nbuf;
268 int32_t status;
269
270 NSS_VERIFY_CTX_MAGIC(nss_ctx);
271 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
272 nss_warning("%p: ipv6 msg dropped as core not ready", nss_ctx);
273 return NSS_TX_FAILURE_NOT_READY;
274 }
275
276 /*
277 * Sanity check the message
278 */
279 if (ncm->interface != NSS_IPV6_RX_INTERFACE) {
280 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
281 return NSS_TX_FAILURE;
282 }
283
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700284 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700285 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
286 return NSS_TX_FAILURE;
287 }
288
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800289 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
290 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -0700291 return NSS_TX_FAILURE;
292 }
293
Stephen Wang709f9b52015-07-07 14:48:35 -0700294 if(size > PAGE_SIZE) {
295 nss_warning("%p: tx request size too large: %u", nss_ctx, size);
296 return NSS_TX_FAILURE;
297 }
298
299 nbuf = dev_alloc_skb(size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700300 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -0800301 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 -0700302 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
303 return NSS_TX_FAILURE;
304 }
305
306 /*
307 * Copy the message to our skb.
308 */
Suruchi Agarwalea2e5232016-09-14 10:32:08 -0700309 nim2 = (struct nss_ipv6_msg *)skb_put(nbuf, size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700310 memcpy(nim2, nim, sizeof(struct nss_ipv6_msg));
311
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700312 /*
313 * Trace messages.
314 */
315 nss_ipv6_log_tx_msg(nim);
316
Sol Kavy879eb8b2014-04-07 19:11:31 -0700317 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
318 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530319 dev_kfree_skb_any(nbuf);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700320 nss_warning("%p: Unable to enqueue 'Destroy IPv6' rule\n", nss_ctx);
321 return NSS_TX_FAILURE;
322 }
323
Stephen Wang90c67de2016-04-26 15:15:59 -0700324 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700325
326 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
327 return NSS_TX_SUCCESS;
328}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700329EXPORT_SYMBOL(nss_ipv6_tx_with_size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700330
331/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700332 * nss_ipv6_tx()
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700333 * Transmit an ipv6 message to the FW.
Stephen Wang709f9b52015-07-07 14:48:35 -0700334 */
335nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim)
336{
337 return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE);
338}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700339EXPORT_SYMBOL(nss_ipv6_tx);
Stephen Wang709f9b52015-07-07 14:48:35 -0700340
341/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700342 **********************************
343 Register/Unregister/Miscellaneous APIs
344 **********************************
345 */
346
347/*
348 * nss_ipv6_notify_register()
349 * Register to received IPv6 events.
350 *
351 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
352 */
353struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data)
354{
355 /*
356 * TODO: We need to have a new array in support of the new API
357 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
358 */
359 nss_top_main.ipv6_callback = cb;
360 nss_top_main.ipv6_ctx = app_data;
361 return &nss_top_main.nss[nss_top_main.ipv6_handler_id];
362}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700363EXPORT_SYMBOL(nss_ipv6_notify_register);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700364
365/*
366 * nss_ipv6_notify_unregister()
367 * Unregister to received IPv6 events.
368 *
369 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
370 */
371void nss_ipv6_notify_unregister(void)
372{
373 nss_top_main.ipv6_callback = NULL;
374}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700375EXPORT_SYMBOL(nss_ipv6_notify_unregister);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700376
377/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700378 * nss_ipv6_conn_sync_many_notify_register()
379 * Register to receive IPv6 conn_sync_many message response.
380 */
381void nss_ipv6_conn_sync_many_notify_register(nss_ipv6_msg_callback_t cb)
382{
383 nss_ipv6_conn_sync_many_msg_cb = cb;
384}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700385EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_register);
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700386
387/*
388 * nss_ipv6_conn_sync_many_notify_unregister()
389 * Unregister to receive IPv6 conn_sync_many message response.
390 */
391void nss_ipv6_conn_sync_many_notify_unregister(void)
392{
393 nss_ipv6_conn_sync_many_msg_cb = NULL;
394}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700395EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_unregister);
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700396
397/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700398 * nss_ipv6_get_mgr()
399 *
400 * TODO: This only suppports a single ipv6, do we ever want to support more?
401 */
402struct nss_ctx_instance *nss_ipv6_get_mgr(void)
403{
404 return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id];
405}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700406EXPORT_SYMBOL(nss_ipv6_get_mgr);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700407
408/*
409 * nss_ipv6_register_handler()
410 * Register our handler to receive messages for this interface
411 */
412void nss_ipv6_register_handler()
413{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700414 struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr();
415
416 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 -0700417 nss_warning("IPv6 handler failed to register");
418 }
419}
420
Vijay Dewangan9db18752014-09-15 16:25:01 -0700421/*
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700422 * nss_ipv6_conn_cfg_process_callback()
423 * Call back function for the ipv6 connection configuration process.
424 */
425static void nss_ipv6_conn_cfg_process_callback(void *app_data, struct nss_ipv6_msg *nim)
426{
427 struct nss_ipv6_rule_conn_cfg_msg *nirccm = &nim->msg.rule_conn_cfg;
428 struct nss_ctx_instance *nss_ctx __maybe_unused = nss_ipv6_get_mgr();
429
430 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
431 nss_warning("%p: IPv6 connection configuration failed with error: %d\n", nss_ctx, nim->cm.error);
432 nss_core_update_max_ipv6_conn(NSS_DEFAULT_NUM_CONN);
433 nss_ipv6_free_conn_tables();
434 return;
435 }
436
437 nss_ipv6_conn_cfg = ntohl(nirccm->num_conn);
438
439 nss_warning("%p: IPv6 connection configuration success: %d\n", nss_ctx, nim->cm.error);
440}
441
442/*
Tushar Mathura3c18932015-08-24 20:27:21 +0530443 * nss_ipv6_conn_cfg_process()
444 * Process request to configure number of ipv6 connections
445 */
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700446static int nss_ipv6_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn)
Tushar Mathura3c18932015-08-24 20:27:21 +0530447{
448 struct nss_ipv6_msg nim;
449 struct nss_ipv6_rule_conn_cfg_msg *nirccm;
450 nss_tx_status_t nss_tx_status;
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700451
452 if ((!nss_ipv6_ct_info.ce_table_size) || (!nss_ipv6_ct_info.cme_table_size)) {
453 nss_warning("%p: connection entry or connection match entry table size not available\n",
454 nss_ctx);
455 return -EINVAL;
456 }
457
458 nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn);
459
460 nss_ipv6_ct_info.ce_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
461 get_order(nss_ipv6_ct_info.ce_table_size));
462 if (!nss_ipv6_ct_info.ce_mem) {
463 nss_warning("%p: Memory allocation failed for IPv6 Connections: %d\n",
464 nss_ctx,
465 conn);
466 goto fail;
467 }
468 nss_warning("%p: CE Memory allocated for IPv6 Connections: %d\n",
469 nss_ctx,
470 conn);
471
472 nss_ipv6_ct_info.cme_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
473 get_order(nss_ipv6_ct_info.cme_table_size));
474 if (!nss_ipv6_ct_info.cme_mem) {
475 nss_warning("%p: Memory allocation failed for IPv6 Connections: %d\n",
476 nss_ctx,
477 conn);
478 goto fail;
479 }
480 nss_warning("%p: CME Memory allocated for IPv6 Connections: %d\n",
481 nss_ctx,
482 conn);
483
484 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
485 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG,
486 sizeof(struct nss_ipv6_rule_conn_cfg_msg), nss_ipv6_conn_cfg_process_callback, NULL);
487
488 nirccm = &nim.msg.rule_conn_cfg;
489 nirccm->num_conn = htonl(conn);
Suruchi Agarwal8c9e7162017-08-17 15:58:40 -0700490 nirccm->ce_mem = dma_map_single(nss_ctx->dev, (void *)nss_ipv6_ct_info.ce_mem, nss_ipv6_ct_info.ce_table_size, DMA_TO_DEVICE);
491 if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->ce_mem))) {
492 nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv6_ct_info.ce_mem);
493 goto fail;
494 }
495
496 nirccm->cme_mem = dma_map_single(nss_ctx->dev, (void *)nss_ipv6_ct_info.cme_mem, nss_ipv6_ct_info.cme_table_size, DMA_TO_DEVICE);
497 if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->cme_mem))) {
498 nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv6_ct_info.cme_mem);
499 goto fail;
500 }
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700501
502 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
503 if (nss_tx_status != NSS_TX_SUCCESS) {
504 nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n",
505 nss_ctx,
506 conn);
507 goto fail;
508 }
509
510 return 0;
511
512fail:
513 nss_ipv6_free_conn_tables();
514 return -EINVAL;
515}
516
517/*
518 * nss_ipv6_update_conn_count_callback()
519 * Call back function for the ipv6 get connection info message.
520 */
521static void nss_ipv6_update_conn_count_callback(void *app_data, struct nss_ipv6_msg *nim)
522{
523 struct nss_ipv6_rule_conn_get_table_size_msg *nircgts = &nim->msg.size;
524 struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr();
525
526 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
527 nss_warning("%p: IPv6 fetch connection info failed with error: %d\n", nss_ctx, nim->cm.error);
528 nss_core_update_max_ipv6_conn(NSS_DEFAULT_NUM_CONN);
529 return;
530 }
531
532 nss_info("IPv6 get connection info success\n");
533
534 nss_ipv6_ct_info.ce_table_size = ntohl(nircgts->ce_table_size);
535 nss_ipv6_ct_info.cme_table_size = ntohl(nircgts->cme_table_size);
536
537 if (nss_ipv6_conn_cfg_process(nss_ctx, ntohl(nircgts->num_conn)) != 0) {
538 nss_warning("%p: IPv6 connection entry or connection match entry table size\
539 not available\n", nss_ctx);
540 }
541
542 return;
543}
544
545/*
546 * nss_ipv6_update_conn_count()
547 * Sets the maximum number of IPv6 connections.
548 *
549 * It first gets the connection tables size information from NSS FW
550 * and then configures the connections in NSS FW.
551 */
552int nss_ipv6_update_conn_count(int ipv6_num_conn)
553{
554 struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr();
555 struct nss_ipv6_msg nim;
556 struct nss_ipv6_rule_conn_get_table_size_msg *nircgts;
557 nss_tx_status_t nss_tx_status;
Tushar Mathura3c18932015-08-24 20:27:21 +0530558 uint32_t sum_of_conn;
559
560 /*
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700561 * By default, NSS FW is configured with default number of connections.
562 */
563 if (ipv6_num_conn == NSS_DEFAULT_NUM_CONN) {
564 nss_info("%p: Default number of connections (%d) already configured\n", nss_ctx, ipv6_num_conn);
565 return 0;
566 }
567
568 /*
Tushar Mathura3c18932015-08-24 20:27:21 +0530569 * Specifications for input
570 * 1) The input should be power of 2.
571 * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k
572 * 3) Min. value should be at leat 256 connections. This is the
573 * minimum connections we will support for each of them.
574 */
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700575 sum_of_conn = nss_ipv4_conn_cfg + ipv6_num_conn;
576 if ((ipv6_num_conn & NSS_NUM_CONN_QUANTA_MASK) ||
Tushar Mathura3c18932015-08-24 20:27:21 +0530577 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700578 (ipv6_num_conn < NSS_MIN_NUM_CONN)) {
Tushar Mathura3c18932015-08-24 20:27:21 +0530579 nss_warning("%p: input supported connections (%d) does not adhere\
580 specifications\n1) not power of 2,\n2) is less than \
581 min val: %d, OR\n IPv4/6 total exceeds %d\n",
582 nss_ctx,
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700583 ipv6_num_conn,
Tushar Mathura3c18932015-08-24 20:27:21 +0530584 NSS_MIN_NUM_CONN,
585 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
586 return -EINVAL;
587 }
588
Tushar Mathura3c18932015-08-24 20:27:21 +0530589 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700590 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_TABLE_SIZE_MSG,
591 sizeof(struct nss_ipv6_rule_conn_get_table_size_msg), nss_ipv6_update_conn_count_callback, NULL);
Tushar Mathura3c18932015-08-24 20:27:21 +0530592
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700593 nircgts = &nim.msg.size;
594 nircgts->num_conn = htonl(ipv6_num_conn);
Tushar Mathura3c18932015-08-24 20:27:21 +0530595 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
Tushar Mathura3c18932015-08-24 20:27:21 +0530596 if (nss_tx_status != NSS_TX_SUCCESS) {
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700597 nss_warning("%p: Send acceleration mode message failed\n", nss_ctx);
598 return -EINVAL;
Tushar Mathura3c18932015-08-24 20:27:21 +0530599 }
600
601 return 0;
602}
603
604/*
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700605 * nss_ipv6_free_conn_tables()
606 * Frees memory allocated for connection tables
Vijay Dewangan9db18752014-09-15 16:25:01 -0700607 */
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700608void nss_ipv6_free_conn_tables(void)
Vijay Dewangan9db18752014-09-15 16:25:01 -0700609{
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700610 if (nss_ipv6_ct_info.ce_mem) {
611 free_pages(nss_ipv6_ct_info.ce_mem, get_order(nss_ipv6_ct_info.ce_table_size));
Vijay Dewangan9db18752014-09-15 16:25:01 -0700612 }
613
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700614 if (nss_ipv6_ct_info.cme_mem) {
615 free_pages(nss_ipv6_ct_info.cme_mem, get_order(nss_ipv6_ct_info.cme_table_size));
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700616 }
Vijay Dewangan9db18752014-09-15 16:25:01 -0700617
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700618 memset(&nss_ipv6_ct_info, 0, sizeof(struct nss_ipv6_conn_table_info));
619 return;
Tushar Mathura3c18932015-08-24 20:27:21 +0530620}
621
Stephen Wang0a2756a2016-08-04 15:52:47 -0700622/*
623 * nss_ipv6_accel_mode_cfg_callback()
624 * call back function for the ipv6 acceleration mode configurate handler
625 */
626static void nss_ipv6_accel_mode_cfg_callback(void *app_data, struct nss_ipv6_msg *nim)
627{
628 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
629 nss_warning("IPv6 acceleration mode configuration failed with error: %d\n", nim->cm.error);
630 i6_accel_mode_cfgp.response = NSS_FAILURE;
631 complete(&i6_accel_mode_cfgp.complete);
632 return;
633 }
634
635 nss_info("IPv6 acceleration mode configuration success\n");
636 i6_accel_mode_cfgp.response = NSS_SUCCESS;
637 complete(&i6_accel_mode_cfgp.complete);
638}
639
640/*
641 * nss_ipv6_accel_mode_cfg_handler()
642 * Configure acceleration mode for IPv6
643 */
644static int nss_ipv6_accel_mode_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
645{
646 struct nss_top_instance *nss_top = &nss_top_main;
647 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
648 struct nss_ipv6_msg nim;
649 struct nss_ipv6_accel_mode_cfg_msg *nipcm;
650 nss_tx_status_t nss_tx_status;
651 int ret = NSS_FAILURE;
652
653 /*
654 * Acquiring semaphore
655 */
656 down(&i6_accel_mode_cfgp.sem);
657
658 /*
659 * Take snap shot of current value
660 */
661 i6_accel_mode_cfgp.current_value = nss_ipv6_accel_mode_cfg;
662
663 /*
664 * Write the variable with user input
665 */
666 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
667 if (ret || (!write)) {
668 up(&i6_accel_mode_cfgp.sem);
669 return ret;
670 }
671
672 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
673 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_ACCEL_MODE_CFG_MSG,
674 sizeof(struct nss_ipv6_accel_mode_cfg_msg), nss_ipv6_accel_mode_cfg_callback, NULL);
675
676 nipcm = &nim.msg.accel_mode_cfg;
677 nipcm->mode = htonl(nss_ipv6_accel_mode_cfg);
678 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
679
680 if (nss_tx_status != NSS_TX_SUCCESS) {
681 nss_warning("%p: Send acceleration mode message failed\n", nss_ctx);
682 goto fail;
683 }
684
685 /*
686 * Blocking call, wait till we get ACK for this msg.
687 */
688 ret = wait_for_completion_timeout(&i6_accel_mode_cfgp.complete, msecs_to_jiffies(NSS_IPV6_TX_MSG_TIMEOUT));
689 if (ret == 0) {
690 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
691 goto fail;
692 }
693
694 if (NSS_FAILURE == i6_accel_mode_cfgp.response) {
695 nss_warning("%p: accel mode configure failed\n", nss_ctx);
696 goto fail;
697 }
698
699 up(&i6_accel_mode_cfgp.sem);
700 return 0;
701
702fail:
703 nss_ipv6_accel_mode_cfg = i6_accel_mode_cfgp.current_value;
704 up(&i6_accel_mode_cfgp.sem);
705 return -EIO;
706}
707
Stephen Wang52e6d342016-03-29 15:02:33 -0700708static struct ctl_table nss_ipv6_table[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700709 {
Stephen Wang0a2756a2016-08-04 15:52:47 -0700710 .procname = "ipv6_accel_mode",
711 .data = &nss_ipv6_accel_mode_cfg,
712 .maxlen = sizeof(int),
713 .mode = 0644,
714 .proc_handler = &nss_ipv6_accel_mode_cfg_handler,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700715 },
716 { }
717};
718
Stephen Wang52e6d342016-03-29 15:02:33 -0700719static struct ctl_table nss_ipv6_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700720 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700721 .procname = "ipv6cfg",
722 .mode = 0555,
723 .child = nss_ipv6_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700724 },
725 { }
726};
727
Stephen Wang52e6d342016-03-29 15:02:33 -0700728static struct ctl_table nss_ipv6_root_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700729 {
730 .procname = "nss",
731 .mode = 0555,
732 .child = nss_ipv6_dir,
733 },
734 { }
735};
736
Stephen Wang52e6d342016-03-29 15:02:33 -0700737static struct ctl_table nss_ipv6_root[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700738 {
739 .procname = "dev",
740 .mode = 0555,
741 .child = nss_ipv6_root_dir,
742 },
743 { }
744};
745
746static struct ctl_table_header *nss_ipv6_header;
747
748/*
749 * nss_ipv6_register_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530750 * Register sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700751 */
752void nss_ipv6_register_sysctl(void)
753{
Stephen Wang0a2756a2016-08-04 15:52:47 -0700754 sema_init(&i6_accel_mode_cfgp.sem, 1);
755 init_completion(&i6_accel_mode_cfgp.complete);
Stephen Wang49b474b2016-03-25 10:40:30 -0700756
Vijay Dewangan9db18752014-09-15 16:25:01 -0700757 /*
758 * Register sysctl table.
759 */
760 nss_ipv6_header = register_sysctl_table(nss_ipv6_root);
761}
762
763/*
764 * nss_ipv6_unregister_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530765 * Unregister sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700766 */
767void nss_ipv6_unregister_sysctl(void)
768{
769 /*
770 * Unregister sysctl table.
771 */
772 if (nss_ipv6_header) {
773 unregister_sysctl_table(nss_ipv6_header);
774 }
775}
776
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700777/*
778 * nss_ipv6_msg_init()
Stephen Wang0a2756a2016-08-04 15:52:47 -0700779 * Initialize IPv6 message.
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700780 */
781void 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 -0800782 nss_ipv6_msg_callback_t cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700783{
784 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
785}
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700786EXPORT_SYMBOL(nss_ipv6_msg_init);