blob: 61c2ed1ace40421a9b5cf988fddd45338fde15e7 [file] [log] [blame]
Sol Kavy879eb8b2014-04-07 19:11:31 -07001/*
2 **************************************************************************
Stephen Wang3e2dbd12018-03-14 17:28:17 -07003 * Copyright (c) 2014-2018, 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"
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070022#include "nss_dscp_map.h"
Yu Huang8c107082017-07-24 14:58:26 -070023#include "nss_ipv6_stats.h"
Sol Kavy879eb8b2014-04-07 19:11:31 -070024
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070025#define NSS_IPV6_TX_MSG_TIMEOUT 1000 /* 1 sec timeout for IPv6 messages */
Stephen Wang0a2756a2016-08-04 15:52:47 -070026
27/*
28 * Private data structure for ipv6 configure messages
29 */
30struct nss_ipv6_cfg_pvt {
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070031 struct semaphore sem; /* Semaphore structure */
32 struct completion complete; /* Completion structure */
33 int response; /* Response from FW */
34 void *cb; /* Original cb for sync msgs */
35 void *app_data; /* Original app_data for sync msgs */
36} nss_ipv6_pvt;
Stephen Wang0a2756a2016-08-04 15:52:47 -070037
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -070038/*
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070039 * Private data structure for ipv6 connection information.
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -070040 */
41struct nss_ipv6_conn_table_info {
42 uint32_t ce_table_size; /* Size of connection entry table in NSS FW */
43 uint32_t cme_table_size; /* Size of connection match entry table in NSS FW */
44 unsigned long ce_mem; /* Start address for connection entry table */
45 unsigned long cme_mem; /* Start address for connection match entry table */
46} nss_ipv6_ct_info;
Stephen Wang0a2756a2016-08-04 15:52:47 -070047
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -070048int nss_ipv6_conn_cfg = NSS_DEFAULT_NUM_CONN;
Stephen Wangf6a9acb2017-08-23 10:35:39 -070049int nss_ipv6_accel_mode_cfg __read_mostly = 1;
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -070050
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070051static struct nss_dscp_map_entry mapping[NSS_DSCP_MAP_ARRAY_SIZE];
Vijay Dewangan9db18752014-09-15 16:25:01 -070052
Sol Kavy879eb8b2014-04-07 19:11:31 -070053/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -070054 * Callback for conn_sync_many request message.
55 */
56nss_ipv6_msg_callback_t nss_ipv6_conn_sync_many_msg_cb = NULL;
57
58/*
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070059 * nss_ipv6_dscp_map_usage()
60 * Help function shows the usage of the command.
Gareth Williams958aa822015-02-04 19:36:39 +000061 */
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070062static inline void nss_ipv6_dscp_map_usage(void)
Gareth Williams958aa822015-02-04 19:36:39 +000063{
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070064 nss_info_always("\nUsage:\n");
65 nss_info_always("echo <dscp> <action> <prio> > /proc/sys/dev/nss/ipv6cfg/ipv6_dscp_map\n\n");
66 nss_info_always("dscp[0-63] action[0-%u] prio[0-%u]:\n\n",
67 NSS_IPV6_DSCP_MAP_ACTION_MAX - 1,
68 NSS_DSCP_MAP_PRIORITY_MAX - 1);
Gareth Williams958aa822015-02-04 19:36:39 +000069}
Guojun Jin9a1cb282017-07-13 17:32:07 -070070
71/*
Sol Kavy879eb8b2014-04-07 19:11:31 -070072 * nss_ipv6_rx_msg_handler()
73 * Handle NSS -> HLOS messages for IPv6 bridge/route
74 */
75static void nss_ipv6_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
76{
77 struct nss_ipv6_msg *nim = (struct nss_ipv6_msg *)ncm;
78 nss_ipv6_msg_callback_t cb;
79
80 BUG_ON(ncm->interface != NSS_IPV6_RX_INTERFACE);
81
82 /*
83 * Is this a valid request/response packet?
84 */
Murat Sezgin5c8c7362014-09-02 17:58:21 -070085 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -070086 nss_warning("%p: received invalid message %d for IPv6 interface", nss_ctx, nim->cm.type);
87 return;
88 }
89
Suruchi Agarwalef8a8702016-01-08 12:40:08 -080090 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv6_msg)) {
91 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Sol Kavy879eb8b2014-04-07 19:11:31 -070092 return;
93 }
94
95 /*
Suruchi Agarwale3940e72016-07-06 15:56:51 -070096 * Trace messages.
Sol Kavy879eb8b2014-04-07 19:11:31 -070097 */
Suruchi Agarwale3940e72016-07-06 15:56:51 -070098 nss_ipv6_log_rx_msg(nim);
Sol Kavy879eb8b2014-04-07 19:11:31 -070099
100 /*
Stephen Wang0a2756a2016-08-04 15:52:47 -0700101 * Handle deprecated messages. Eventually these messages should be removed.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700102 */
103 switch (nim->cm.type) {
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700104 case NSS_IPV6_RX_NODE_STATS_SYNC_MSG:
105 /*
106 * Update driver statistics on node sync.
107 */
Yu Huang8c107082017-07-24 14:58:26 -0700108 nss_ipv6_stats_node_sync(nss_ctx, &nim->msg.node_stats);
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700109 break;
110
Sol Kavy879eb8b2014-04-07 19:11:31 -0700111 case NSS_IPV6_RX_CONN_STATS_SYNC_MSG:
112 /*
113 * Update driver statistics on connection sync.
114 */
Yu Huang8c107082017-07-24 14:58:26 -0700115 nss_ipv6_stats_conn_sync(nss_ctx, &nim->msg.conn_stats);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700116 break;
Stephen Wang709f9b52015-07-07 14:48:35 -0700117
118 case NSS_IPV6_TX_CONN_STATS_SYNC_MANY_MSG:
119 /*
120 * Update driver statistics on connection sync many.
121 */
Yu Huang8c107082017-07-24 14:58:26 -0700122 nss_ipv6_stats_conn_sync_many(nss_ctx, &nim->msg.conn_stats_many);
Stephen Wangaed46332016-12-12 17:29:03 -0800123 ncm->cb = (nss_ptr_t)nss_ipv6_conn_sync_many_msg_cb;
Stephen Wang709f9b52015-07-07 14:48:35 -0700124 break;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700125 }
Abhishek Rastogi55f39452014-05-08 19:23:29 +0530126
Sol Kavy879eb8b2014-04-07 19:11:31 -0700127 /*
128 * Update the callback and app_data for NOTIFY messages, IPv6 sends all notify messages
129 * to the same callback/app_data.
130 */
131 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800132 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->ipv6_callback;
133 ncm->app_data = (nss_ptr_t)nss_ctx->nss_top->ipv6_ctx;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700134 }
135
136 /*
137 * Do we have a callback?
138 */
139 if (!ncm->cb) {
140 return;
141 }
142
143 /*
144 * Callback
145 */
146 cb = (nss_ipv6_msg_callback_t)ncm->cb;
147 cb((void *)ncm->app_data, nim);
148}
149
150/*
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700151 * nss_ipv6_tx_sync_callback()
152 * Callback to handle the completion of synchronous tx messages.
153 */
154static void nss_ipv6_tx_sync_callback(void *app_data, struct nss_ipv6_msg *nim)
155{
156 nss_ipv6_msg_callback_t callback = (nss_ipv6_msg_callback_t)nss_ipv6_pvt.cb;
157 void *data = nss_ipv6_pvt.app_data;
158
159 nss_ipv6_pvt.cb = NULL;
160 nss_ipv6_pvt.app_data = NULL;
161
162 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
163 nss_warning("ipv6 error response %d\n", nim->cm.response);
164 nss_ipv6_pvt.response = NSS_TX_FAILURE;
165 } else {
166 nss_ipv6_pvt.response = NSS_TX_SUCCESS;
167 }
168
169 if (callback) {
170 callback(data, nim);
171 }
172
173 complete(&nss_ipv6_pvt.complete);
174}
175
176/*
177 * nss_ipv6_dscp_action_get()
178 * Gets the action mapped to dscp.
179 */
180enum nss_ipv6_dscp_map_actions nss_ipv6_dscp_action_get(uint8_t dscp)
181{
Sakthi Vignesh Radhakrishnan1f7a66b2017-10-18 09:33:22 -0700182 if (dscp >= NSS_DSCP_MAP_ARRAY_SIZE) {
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700183 nss_warning("dscp:%u invalid\n", dscp);
184 return NSS_IPV6_DSCP_MAP_ACTION_MAX;
185 }
186
187 return mapping[dscp].action;
188}
189EXPORT_SYMBOL(nss_ipv6_dscp_action_get);
190
191/*
192 * nss_ipv6_max_conn_count()
193 * Return the maximum number of IPv6 connections that the NSS acceleration engine supports.
194 */
195int nss_ipv6_max_conn_count(void)
196{
197 return nss_ipv6_conn_cfg;
198}
199EXPORT_SYMBOL(nss_ipv6_max_conn_count);
200
201/*
202 * nss_ipv6_conn_inquiry()
203 * Inquiry if a connection has been established in NSS FW
204 */
205nss_tx_status_t nss_ipv6_conn_inquiry(struct nss_ipv6_5tuple *ipv6_5t_p,
206 nss_ipv6_msg_callback_t cb)
207{
208 nss_tx_status_t nss_tx_status;
209 struct nss_ipv6_msg nim;
210 struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[0];
211
212 /*
213 * Initialize inquiry message structure.
214 * This is async message and the result will be returned
215 * to the caller by the msg_callback passed in.
216 */
217 memset(&nim, 0, sizeof(nim));
218 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE,
219 NSS_IPV6_TX_CONN_CFG_INQUIRY_MSG,
220 sizeof(struct nss_ipv6_inquiry_msg),
221 cb, NULL);
222 nim.msg.inquiry.rr.tuple = *ipv6_5t_p;
223 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
224 if (nss_tx_status != NSS_TX_SUCCESS) {
225 nss_warning("%p: Send inquiry message failed\n", ipv6_5t_p);
226 }
227
228 return nss_tx_status;
229}
230EXPORT_SYMBOL(nss_ipv6_conn_inquiry);
231
232/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700233 * nss_ipv6_tx_with_size()
234 * Transmit an ipv6 message to the FW with a specified size.
Sol Kavy879eb8b2014-04-07 19:11:31 -0700235 */
Stephen Wang709f9b52015-07-07 14:48:35 -0700236nss_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 -0700237{
Sol Kavy879eb8b2014-04-07 19:11:31 -0700238 struct nss_cmn_msg *ncm = &nim->cm;
Sol Kavy879eb8b2014-04-07 19:11:31 -0700239
240 /*
241 * Sanity check the message
242 */
243 if (ncm->interface != NSS_IPV6_RX_INTERFACE) {
244 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
245 return NSS_TX_FAILURE;
246 }
247
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700248 if (ncm->type >= NSS_IPV6_MAX_MSG_TYPES) {
Sol Kavy879eb8b2014-04-07 19:11:31 -0700249 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
250 return NSS_TX_FAILURE;
251 }
252
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700253 /*
254 * Trace messages.
255 */
256 nss_ipv6_log_tx_msg(nim);
257
Stephen Wang3e2dbd12018-03-14 17:28:17 -0700258 return nss_core_send_cmd(nss_ctx, nim, sizeof(*nim), size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700259}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700260EXPORT_SYMBOL(nss_ipv6_tx_with_size);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700261
262/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700263 * nss_ipv6_tx()
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700264 * Transmit an ipv6 message to the FW.
Stephen Wang709f9b52015-07-07 14:48:35 -0700265 */
266nss_tx_status_t nss_ipv6_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim)
267{
268 return nss_ipv6_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE);
269}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700270EXPORT_SYMBOL(nss_ipv6_tx);
Stephen Wang709f9b52015-07-07 14:48:35 -0700271
272/*
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700273 * nss_ipv6_tx_sync()
274 * Transmit a synchronous ipv6 message to the FW.
275 */
276nss_tx_status_t nss_ipv6_tx_sync(struct nss_ctx_instance *nss_ctx, struct nss_ipv6_msg *nim)
277{
278 nss_tx_status_t status;
279 int ret = 0;
280
281 down(&nss_ipv6_pvt.sem);
282 nss_ipv6_pvt.cb = (void *)nim->cm.cb;
283 nss_ipv6_pvt.app_data = (void *)nim->cm.app_data;
284
285 nim->cm.cb = (nss_ptr_t)nss_ipv6_tx_sync_callback;
286 nim->cm.app_data = (nss_ptr_t)NULL;
287
288 status = nss_ipv6_tx(nss_ctx, nim);
289 if (status != NSS_TX_SUCCESS) {
290 nss_warning("%p: nss ipv6 msg tx failed\n", nss_ctx);
291 up(&nss_ipv6_pvt.sem);
292 return status;
293 }
294
295 ret = wait_for_completion_timeout(&nss_ipv6_pvt.complete, msecs_to_jiffies(NSS_IPV6_TX_MSG_TIMEOUT));
296 if (!ret) {
297 nss_warning("%p: IPv6 tx sync failed due to timeout\n", nss_ctx);
298 nss_ipv6_pvt.response = NSS_TX_FAILURE;
299 }
300
301 status = nss_ipv6_pvt.response;
302 up(&nss_ipv6_pvt.sem);
303 return status;
304}
305EXPORT_SYMBOL(nss_ipv6_tx_sync);
306
307/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700308 **********************************
309 Register/Unregister/Miscellaneous APIs
310 **********************************
311 */
312
313/*
314 * nss_ipv6_notify_register()
315 * Register to received IPv6 events.
316 *
317 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
318 */
319struct nss_ctx_instance *nss_ipv6_notify_register(nss_ipv6_msg_callback_t cb, void *app_data)
320{
321 /*
322 * TODO: We need to have a new array in support of the new API
323 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
324 */
325 nss_top_main.ipv6_callback = cb;
326 nss_top_main.ipv6_ctx = app_data;
327 return &nss_top_main.nss[nss_top_main.ipv6_handler_id];
328}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700329EXPORT_SYMBOL(nss_ipv6_notify_register);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700330
331/*
332 * nss_ipv6_notify_unregister()
333 * Unregister to received IPv6 events.
334 *
335 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv6 on any core?
336 */
337void nss_ipv6_notify_unregister(void)
338{
339 nss_top_main.ipv6_callback = NULL;
340}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700341EXPORT_SYMBOL(nss_ipv6_notify_unregister);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700342
343/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700344 * nss_ipv6_conn_sync_many_notify_register()
345 * Register to receive IPv6 conn_sync_many message response.
346 */
347void nss_ipv6_conn_sync_many_notify_register(nss_ipv6_msg_callback_t cb)
348{
349 nss_ipv6_conn_sync_many_msg_cb = cb;
350}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700351EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_register);
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700352
353/*
354 * nss_ipv6_conn_sync_many_notify_unregister()
355 * Unregister to receive IPv6 conn_sync_many message response.
356 */
357void nss_ipv6_conn_sync_many_notify_unregister(void)
358{
359 nss_ipv6_conn_sync_many_msg_cb = NULL;
360}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700361EXPORT_SYMBOL(nss_ipv6_conn_sync_many_notify_unregister);
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700362
363/*
Sol Kavy879eb8b2014-04-07 19:11:31 -0700364 * nss_ipv6_get_mgr()
365 *
366 * TODO: This only suppports a single ipv6, do we ever want to support more?
367 */
368struct nss_ctx_instance *nss_ipv6_get_mgr(void)
369{
370 return (void *)&nss_top_main.nss[nss_top_main.ipv6_handler_id];
371}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700372EXPORT_SYMBOL(nss_ipv6_get_mgr);
Sol Kavy879eb8b2014-04-07 19:11:31 -0700373
374/*
375 * nss_ipv6_register_handler()
376 * Register our handler to receive messages for this interface
377 */
378void nss_ipv6_register_handler()
379{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700380 struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr();
381
382 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 -0700383 nss_warning("IPv6 handler failed to register");
384 }
Yu Huang8c107082017-07-24 14:58:26 -0700385
386 nss_ipv6_stats_dentry_create();
Sol Kavy879eb8b2014-04-07 19:11:31 -0700387}
388
Vijay Dewangan9db18752014-09-15 16:25:01 -0700389/*
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700390 * nss_ipv6_conn_cfg_process_callback()
391 * Call back function for the ipv6 connection configuration process.
392 */
393static void nss_ipv6_conn_cfg_process_callback(void *app_data, struct nss_ipv6_msg *nim)
394{
395 struct nss_ipv6_rule_conn_cfg_msg *nirccm = &nim->msg.rule_conn_cfg;
396 struct nss_ctx_instance *nss_ctx __maybe_unused = nss_ipv6_get_mgr();
397
398 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
399 nss_warning("%p: IPv6 connection configuration failed with error: %d\n", nss_ctx, nim->cm.error);
Stephen Wang01433692017-10-30 14:45:11 -0700400 nss_core_update_max_ipv6_conn(NSS_FW_DEFAULT_NUM_CONN);
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700401 nss_ipv6_free_conn_tables();
402 return;
403 }
404
405 nss_ipv6_conn_cfg = ntohl(nirccm->num_conn);
406
407 nss_warning("%p: IPv6 connection configuration success: %d\n", nss_ctx, nim->cm.error);
408}
409
410/*
Tushar Mathura3c18932015-08-24 20:27:21 +0530411 * nss_ipv6_conn_cfg_process()
412 * Process request to configure number of ipv6 connections
413 */
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700414static int nss_ipv6_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn)
Tushar Mathura3c18932015-08-24 20:27:21 +0530415{
416 struct nss_ipv6_msg nim;
417 struct nss_ipv6_rule_conn_cfg_msg *nirccm;
418 nss_tx_status_t nss_tx_status;
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700419
420 if ((!nss_ipv6_ct_info.ce_table_size) || (!nss_ipv6_ct_info.cme_table_size)) {
421 nss_warning("%p: connection entry or connection match entry table size not available\n",
422 nss_ctx);
423 return -EINVAL;
424 }
425
426 nss_info("%p: IPv6 supported connections: %d\n", nss_ctx, conn);
427
428 nss_ipv6_ct_info.ce_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
429 get_order(nss_ipv6_ct_info.ce_table_size));
430 if (!nss_ipv6_ct_info.ce_mem) {
431 nss_warning("%p: Memory allocation failed for IPv6 Connections: %d\n",
432 nss_ctx,
433 conn);
434 goto fail;
435 }
436 nss_warning("%p: CE Memory allocated for IPv6 Connections: %d\n",
437 nss_ctx,
438 conn);
439
440 nss_ipv6_ct_info.cme_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
441 get_order(nss_ipv6_ct_info.cme_table_size));
442 if (!nss_ipv6_ct_info.cme_mem) {
443 nss_warning("%p: Memory allocation failed for IPv6 Connections: %d\n",
444 nss_ctx,
445 conn);
446 goto fail;
447 }
448 nss_warning("%p: CME Memory allocated for IPv6 Connections: %d\n",
449 nss_ctx,
450 conn);
451
452 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
453 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_CFG_RULE_MSG,
454 sizeof(struct nss_ipv6_rule_conn_cfg_msg), nss_ipv6_conn_cfg_process_callback, NULL);
455
456 nirccm = &nim.msg.rule_conn_cfg;
457 nirccm->num_conn = htonl(conn);
Suruchi Agarwal8c9e7162017-08-17 15:58:40 -0700458 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);
459 if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->ce_mem))) {
460 nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv6_ct_info.ce_mem);
461 goto fail;
462 }
463
464 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);
465 if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->cme_mem))) {
466 nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv6_ct_info.cme_mem);
467 goto fail;
468 }
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700469
470 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
471 if (nss_tx_status != NSS_TX_SUCCESS) {
472 nss_warning("%p: nss_tx error setting IPv6 Connections: %d\n",
473 nss_ctx,
474 conn);
475 goto fail;
476 }
477
478 return 0;
479
480fail:
481 nss_ipv6_free_conn_tables();
482 return -EINVAL;
483}
484
485/*
486 * nss_ipv6_update_conn_count_callback()
487 * Call back function for the ipv6 get connection info message.
488 */
489static void nss_ipv6_update_conn_count_callback(void *app_data, struct nss_ipv6_msg *nim)
490{
491 struct nss_ipv6_rule_conn_get_table_size_msg *nircgts = &nim->msg.size;
492 struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr();
493
494 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
495 nss_warning("%p: IPv6 fetch connection info failed with error: %d\n", nss_ctx, nim->cm.error);
Stephen Wang01433692017-10-30 14:45:11 -0700496 nss_core_update_max_ipv6_conn(NSS_FW_DEFAULT_NUM_CONN);
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700497 return;
498 }
499
500 nss_info("IPv6 get connection info success\n");
501
502 nss_ipv6_ct_info.ce_table_size = ntohl(nircgts->ce_table_size);
503 nss_ipv6_ct_info.cme_table_size = ntohl(nircgts->cme_table_size);
504
505 if (nss_ipv6_conn_cfg_process(nss_ctx, ntohl(nircgts->num_conn)) != 0) {
506 nss_warning("%p: IPv6 connection entry or connection match entry table size\
507 not available\n", nss_ctx);
508 }
509
510 return;
511}
512
513/*
514 * nss_ipv6_update_conn_count()
515 * Sets the maximum number of IPv6 connections.
516 *
517 * It first gets the connection tables size information from NSS FW
518 * and then configures the connections in NSS FW.
519 */
520int nss_ipv6_update_conn_count(int ipv6_num_conn)
521{
522 struct nss_ctx_instance *nss_ctx = nss_ipv6_get_mgr();
523 struct nss_ipv6_msg nim;
524 struct nss_ipv6_rule_conn_get_table_size_msg *nircgts;
525 nss_tx_status_t nss_tx_status;
Tushar Mathura3c18932015-08-24 20:27:21 +0530526 uint32_t sum_of_conn;
527
528 /*
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700529 * By default, NSS FW is configured with default number of connections.
530 */
Stephen Wang01433692017-10-30 14:45:11 -0700531 if (ipv6_num_conn == NSS_FW_DEFAULT_NUM_CONN) {
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700532 nss_info("%p: Default number of connections (%d) already configured\n", nss_ctx, ipv6_num_conn);
533 return 0;
534 }
535
536 /*
Tushar Mathura3c18932015-08-24 20:27:21 +0530537 * Specifications for input
538 * 1) The input should be power of 2.
539 * 2) Input for ipv4 and ipv6 sum togther should not exceed 8k
540 * 3) Min. value should be at leat 256 connections. This is the
541 * minimum connections we will support for each of them.
542 */
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700543 sum_of_conn = nss_ipv4_conn_cfg + ipv6_num_conn;
544 if ((ipv6_num_conn & NSS_NUM_CONN_QUANTA_MASK) ||
Tushar Mathura3c18932015-08-24 20:27:21 +0530545 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700546 (ipv6_num_conn < NSS_MIN_NUM_CONN)) {
Tushar Mathura3c18932015-08-24 20:27:21 +0530547 nss_warning("%p: input supported connections (%d) does not adhere\
548 specifications\n1) not power of 2,\n2) is less than \
549 min val: %d, OR\n IPv4/6 total exceeds %d\n",
550 nss_ctx,
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700551 ipv6_num_conn,
Tushar Mathura3c18932015-08-24 20:27:21 +0530552 NSS_MIN_NUM_CONN,
553 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
554 return -EINVAL;
555 }
556
Tushar Mathura3c18932015-08-24 20:27:21 +0530557 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700558 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_CONN_TABLE_SIZE_MSG,
559 sizeof(struct nss_ipv6_rule_conn_get_table_size_msg), nss_ipv6_update_conn_count_callback, NULL);
Tushar Mathura3c18932015-08-24 20:27:21 +0530560
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700561 nircgts = &nim.msg.size;
562 nircgts->num_conn = htonl(ipv6_num_conn);
Tushar Mathura3c18932015-08-24 20:27:21 +0530563 nss_tx_status = nss_ipv6_tx(nss_ctx, &nim);
Tushar Mathura3c18932015-08-24 20:27:21 +0530564 if (nss_tx_status != NSS_TX_SUCCESS) {
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700565 nss_warning("%p: Send acceleration mode message failed\n", nss_ctx);
566 return -EINVAL;
Tushar Mathura3c18932015-08-24 20:27:21 +0530567 }
568
569 return 0;
570}
571
572/*
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700573 * nss_ipv6_free_conn_tables()
574 * Frees memory allocated for connection tables
Vijay Dewangan9db18752014-09-15 16:25:01 -0700575 */
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700576void nss_ipv6_free_conn_tables(void)
Vijay Dewangan9db18752014-09-15 16:25:01 -0700577{
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700578 if (nss_ipv6_ct_info.ce_mem) {
579 free_pages(nss_ipv6_ct_info.ce_mem, get_order(nss_ipv6_ct_info.ce_table_size));
Vijay Dewangan9db18752014-09-15 16:25:01 -0700580 }
581
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700582 if (nss_ipv6_ct_info.cme_mem) {
583 free_pages(nss_ipv6_ct_info.cme_mem, get_order(nss_ipv6_ct_info.cme_table_size));
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700584 }
Vijay Dewangan9db18752014-09-15 16:25:01 -0700585
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700586 memset(&nss_ipv6_ct_info, 0, sizeof(struct nss_ipv6_conn_table_info));
587 return;
Tushar Mathura3c18932015-08-24 20:27:21 +0530588}
589
Stephen Wang0a2756a2016-08-04 15:52:47 -0700590/*
Stephen Wang0a2756a2016-08-04 15:52:47 -0700591 * nss_ipv6_accel_mode_cfg_handler()
592 * Configure acceleration mode for IPv6
593 */
594static int nss_ipv6_accel_mode_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
595{
596 struct nss_top_instance *nss_top = &nss_top_main;
597 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
598 struct nss_ipv6_msg nim;
599 struct nss_ipv6_accel_mode_cfg_msg *nipcm;
600 nss_tx_status_t nss_tx_status;
601 int ret = NSS_FAILURE;
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700602 int current_value;
Stephen Wang0a2756a2016-08-04 15:52:47 -0700603
604 /*
605 * Take snap shot of current value
606 */
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700607 current_value = nss_ipv6_accel_mode_cfg;
Stephen Wang0a2756a2016-08-04 15:52:47 -0700608
609 /*
610 * Write the variable with user input
611 */
612 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
613 if (ret || (!write)) {
Stephen Wang0a2756a2016-08-04 15:52:47 -0700614 return ret;
615 }
616
617 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
618 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_ACCEL_MODE_CFG_MSG,
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700619 sizeof(struct nss_ipv6_accel_mode_cfg_msg), NULL, NULL);
Stephen Wang0a2756a2016-08-04 15:52:47 -0700620
621 nipcm = &nim.msg.accel_mode_cfg;
622 nipcm->mode = htonl(nss_ipv6_accel_mode_cfg);
Stephen Wang0a2756a2016-08-04 15:52:47 -0700623
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700624 nss_tx_status = nss_ipv6_tx_sync(nss_ctx, &nim);
Stephen Wang0a2756a2016-08-04 15:52:47 -0700625 if (nss_tx_status != NSS_TX_SUCCESS) {
626 nss_warning("%p: Send acceleration mode message failed\n", nss_ctx);
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700627 nss_ipv6_accel_mode_cfg = current_value;
628 return -EIO;
629 }
630
631 return 0;
632}
633
634/*
635 * nss_ipv6_dscp_map_cfg_handler()
636 * Sysctl handler for dscp/pri mappings.
637 */
638static int nss_ipv6_dscp_map_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
639{
640 struct nss_top_instance *nss_top = &nss_top_main;
641 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
642 struct nss_dscp_map_parse out;
643 struct nss_ipv6_msg nim;
644 struct nss_ipv6_dscp2pri_cfg_msg *nipd2p;
645 nss_tx_status_t status;
646 int ret;
647
648 if (!write) {
649 return nss_dscp_map_print(ctl, buffer, lenp, ppos, mapping);
650 }
651
652 ret = nss_dscp_map_parse(ctl, buffer, lenp, ppos, &out);
653 if (ret) {
654 nss_warning("failed to parse dscp mapping:%d\n", ret);
655 return ret;
656 }
657
658 if (out.action >= NSS_IPV6_DSCP_MAP_ACTION_MAX) {
659 nss_warning("invalid action value: %d\n", out.action);
660 nss_ipv6_dscp_map_usage();
661 return -EINVAL;
662 }
663
664 memset(&nim, 0, sizeof(struct nss_ipv6_msg));
665 nss_ipv6_msg_init(&nim, NSS_IPV6_RX_INTERFACE, NSS_IPV6_TX_DSCP2PRI_CFG_MSG,
666 sizeof(struct nss_ipv6_dscp2pri_cfg_msg), NULL, NULL);
667
668 nipd2p = &nim.msg.dscp2pri_cfg;
669 nipd2p->dscp = out.dscp;
670 nipd2p->priority = out.priority;
671
672 status = nss_ipv6_tx_sync(nss_ctx, &nim);
673 if (status != NSS_TX_SUCCESS) {
674 nss_warning("%p: ipv6 dscp2pri config message failed\n", nss_ctx);
675 return -EFAULT;
Stephen Wang0a2756a2016-08-04 15:52:47 -0700676 }
677
678 /*
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700679 * NSS firmware acknowleged the configuration, so update the mapping
680 * table on HOST side as well.
Stephen Wang0a2756a2016-08-04 15:52:47 -0700681 */
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700682 mapping[out.dscp].action = out.action;
683 mapping[out.dscp].priority = out.priority;
Stephen Wang0a2756a2016-08-04 15:52:47 -0700684
Stephen Wang0a2756a2016-08-04 15:52:47 -0700685 return 0;
Stephen Wang0a2756a2016-08-04 15:52:47 -0700686}
687
Stephen Wang52e6d342016-03-29 15:02:33 -0700688static struct ctl_table nss_ipv6_table[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700689 {
Stephen Wang0a2756a2016-08-04 15:52:47 -0700690 .procname = "ipv6_accel_mode",
691 .data = &nss_ipv6_accel_mode_cfg,
692 .maxlen = sizeof(int),
693 .mode = 0644,
694 .proc_handler = &nss_ipv6_accel_mode_cfg_handler,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700695 },
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700696 {
697 .procname = "ipv6_dscp_map",
698 .data = &mapping[NSS_DSCP_MAP_ARRAY_SIZE],
699 .maxlen = sizeof(struct nss_dscp_map_entry),
700 .mode = 0644,
701 .proc_handler = &nss_ipv6_dscp_map_cfg_handler,
702 },
Vijay Dewangan9db18752014-09-15 16:25:01 -0700703 { }
704};
705
Stephen Wang52e6d342016-03-29 15:02:33 -0700706static struct ctl_table nss_ipv6_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700707 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700708 .procname = "ipv6cfg",
709 .mode = 0555,
710 .child = nss_ipv6_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700711 },
712 { }
713};
714
Stephen Wang52e6d342016-03-29 15:02:33 -0700715static struct ctl_table nss_ipv6_root_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700716 {
717 .procname = "nss",
718 .mode = 0555,
719 .child = nss_ipv6_dir,
720 },
721 { }
722};
723
Stephen Wang52e6d342016-03-29 15:02:33 -0700724static struct ctl_table nss_ipv6_root[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700725 {
726 .procname = "dev",
727 .mode = 0555,
728 .child = nss_ipv6_root_dir,
729 },
730 { }
731};
732
733static struct ctl_table_header *nss_ipv6_header;
734
735/*
736 * nss_ipv6_register_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530737 * Register sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700738 */
739void nss_ipv6_register_sysctl(void)
740{
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700741 sema_init(&nss_ipv6_pvt.sem, 1);
742 init_completion(&nss_ipv6_pvt.complete);
Stephen Wang49b474b2016-03-25 10:40:30 -0700743
Vijay Dewangan9db18752014-09-15 16:25:01 -0700744 /*
745 * Register sysctl table.
746 */
747 nss_ipv6_header = register_sysctl_table(nss_ipv6_root);
748}
749
750/*
751 * nss_ipv6_unregister_sysctl()
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530752 * Unregister sysctl specific to ipv6
Vijay Dewangan9db18752014-09-15 16:25:01 -0700753 */
754void nss_ipv6_unregister_sysctl(void)
755{
756 /*
757 * Unregister sysctl table.
758 */
759 if (nss_ipv6_header) {
760 unregister_sysctl_table(nss_ipv6_header);
761 }
762}
763
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700764/*
765 * nss_ipv6_msg_init()
Stephen Wang0a2756a2016-08-04 15:52:47 -0700766 * Initialize IPv6 message.
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700767 */
768void 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 -0800769 nss_ipv6_msg_callback_t cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700770{
771 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
772}
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700773EXPORT_SYMBOL(nss_ipv6_msg_init);