blob: e6dfe1afbd317cf59447614a52fed657c7cf77a3 [file] [log] [blame]
Thomas Wu68250352014-04-02 18:59:40 -07001/*
2 **************************************************************************
Stephen Wangaed46332016-12-12 17:29:03 -08003 * Copyright (c) 2013-2017, The Linux Foundation. All rights reserved.
Thomas Wu68250352014-04-02 18:59:40 -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/*
Murat Sezgin5c8c7362014-09-02 17:58:21 -070018 * nss_ipv4.c
Thomas Wu68250352014-04-02 18:59:40 -070019 * NSS IPv4 APIs
20 */
Vijay Dewangan9db18752014-09-15 16:25:01 -070021#include <linux/sysctl.h>
Thomas Wu68250352014-04-02 18:59:40 -070022#include "nss_tx_rx_common.h"
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070023#include "nss_dscp_map.h"
Thomas Wu68250352014-04-02 18:59:40 -070024
Stephen Wang0a2756a2016-08-04 15:52:47 -070025#define NSS_IPV4_TX_MSG_TIMEOUT 1000 /* 1 sec timeout for IPv4 messages */
26
27/*
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070028 * Private data structure for ipv4 configuration
Stephen Wang0a2756a2016-08-04 15:52:47 -070029 */
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070030struct nss_ipv4_pvt {
31 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_ipv4_pvt;
Stephen Wang0a2756a2016-08-04 15:52:47 -070037
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -070038/*
39 * Private data structure for ipv4 connection information.
40 */
41struct nss_ipv4_conn_table_info {
42 uint32_t ce_table_size; /* Size of connection table entry in NSS FW */
43 uint32_t cme_table_size; /* Size of connection match table entry 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_ipv4_ct_info;
47
Vijay Dewangan4861f4e2014-10-14 16:56:35 -070048int nss_ipv4_conn_cfg __read_mostly = NSS_DEFAULT_NUM_CONN;
Stephen Wang0a2756a2016-08-04 15:52:47 -070049int nss_ipv4_accel_mode_cfg __read_mostly = 1;
50
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
Thomas Wu68250352014-04-02 18:59:40 -070053/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -070054 * Callback for conn_sync_many request message.
55 */
56nss_ipv4_msg_callback_t nss_ipv4_conn_sync_many_msg_cb = NULL;
57
58/*
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -070059 * nss_ipv4_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_ipv4_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/ipv4cfg/ipv4_dscp_map\n\n");
66 nss_info_always("dscp[0-63] action[0-%u] prio[0-%u]:\n\n",
67 NSS_IPV4_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 Kavy57d24b42014-04-05 13:45:36 -070072 * nss_ipv4_driver_conn_sync_update()
Thomas Wu68250352014-04-02 18:59:40 -070073 * Update driver specific information from the messsage.
74 */
Murat Sezgin0c0561d2014-04-09 18:55:58 -070075static void nss_ipv4_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync *nirs)
Thomas Wu68250352014-04-02 18:59:40 -070076{
Sol Kavy57d24b42014-04-05 13:45:36 -070077 struct nss_top_instance *nss_top = nss_ctx->nss_top;
Sol Kavy57d24b42014-04-05 13:45:36 -070078
Thomas Wu68250352014-04-02 18:59:40 -070079 /*
80 * Update statistics maintained by NSS driver
81 */
82 spin_lock_bh(&nss_top->stats_lock);
Thomas Wu68250352014-04-02 18:59:40 -070083 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_PKTS] += nirs->flow_rx_packet_count + nirs->return_rx_packet_count;
84 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_BYTES] += nirs->flow_rx_byte_count + nirs->return_rx_byte_count;
85 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count;
86 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_BYTES] += nirs->flow_tx_byte_count + nirs->return_tx_byte_count;
Thomas Wu68250352014-04-02 18:59:40 -070087 spin_unlock_bh(&nss_top->stats_lock);
88}
Thomas Wu68250352014-04-02 18:59:40 -070089
90/*
Stephen Wang709f9b52015-07-07 14:48:35 -070091 * nss_ipv4_driver_conn_sync_many_update()
92 * Update driver specific information from the conn_sync_many messsage.
93 */
94static void nss_ipv4_driver_conn_sync_many_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync_many_msg *nicsm)
95{
96 int i;
97
98 /*
99 * Sanity check for the stats count
100 */
101 if (nicsm->count * sizeof(struct nss_ipv4_conn_sync) >= nicsm->size) {
102 nss_warning("%p: stats sync count %u exceeds the size of this msg %u", nss_ctx, nicsm->count, nicsm->size);
103 return;
104 }
105
106 for (i = 0; i < nicsm->count; i++) {
107 nss_ipv4_driver_conn_sync_update(nss_ctx, &nicsm->conn_sync[i]);
108 }
109}
110
111/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700112 * nss_ipv4_driver_node_sync_update)
113 * Update driver specific information from the messsage.
114 */
115static void nss_ipv4_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_node_sync *nins)
116{
117 struct nss_top_instance *nss_top = nss_ctx->nss_top;
ratheesh kannoth93ba95c2017-07-13 15:52:52 +0530118 int i;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700119
120 /*
121 * Update statistics maintained by NSS driver
122 */
123 spin_lock_bh(&nss_top->stats_lock);
124 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
125 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700126 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
127 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
128
ratheesh kannoth93ba95c2017-07-13 15:52:52 +0530129 for (i = 0; i < NSS_MAX_NUM_PRI; i++) {
130 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_QUEUE_0_DROPPED + i] += nins->node_stats.rx_dropped[i];
131 }
132
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700133 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_REQUESTS] += nins->ipv4_connection_create_requests;
134 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_COLLISIONS] += nins->ipv4_connection_create_collisions;
135 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv4_connection_create_invalid_interface;
136 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_REQUESTS] += nins->ipv4_connection_destroy_requests;
137 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_MISSES] += nins->ipv4_connection_destroy_misses;
138 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_HITS] += nins->ipv4_connection_hash_hits;
139 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_REORDERS] += nins->ipv4_connection_hash_reorders;
140 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_FLUSHES] += nins->ipv4_connection_flushes;
141 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_EVICTIONS] += nins->ipv4_connection_evictions;
Selin Dag60ea2b22014-11-05 09:36:22 -0800142 nss_top->stats_ipv4[NSS_STATS_IPV4_FRAGMENTATIONS] += nins->ipv4_fragmentations;
Kiran Kumar C.S.Kfadf92d2015-06-26 12:48:33 +0530143 nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_CREATE_REQUESTS] += nins->ipv4_mc_connection_create_requests;
144 nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_UPDATE_REQUESTS] += nins->ipv4_mc_connection_update_requests;
145 nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv4_mc_connection_create_invalid_interface;
146 nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_DESTROY_REQUESTS] += nins->ipv4_mc_connection_destroy_requests;
147 nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_DESTROY_MISSES] += nins->ipv4_mc_connection_destroy_misses;
148 nss_top->stats_ipv4[NSS_STATS_IPV4_MC_CONNECTION_FLUSHES] += nins->ipv4_mc_connection_flushes;
Jackson Bockus67fc0a82017-08-09 10:30:56 -0700149 nss_top->stats_ipv4[NSS_STATS_IPV4_DROPPED_BY_RULE] += nins->ipv4_dropped_by_rule;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700150
151 for (i = 0; i < NSS_EXCEPTION_EVENT_IPV4_MAX; i++) {
152 nss_top->stats_if_exception_ipv4[i] += nins->exception_events[i];
153 }
154 spin_unlock_bh(&nss_top->stats_lock);
155}
156
157/*
Sol Kavy2783c072014-04-05 12:53:13 -0700158 * nss_ipv4_rx_msg_handler()
Thomas Wu68250352014-04-02 18:59:40 -0700159 * Handle NSS -> HLOS messages for IPv4 bridge/route
160 */
Sol Kavy2783c072014-04-05 12:53:13 -0700161static void nss_ipv4_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
Thomas Wu68250352014-04-02 18:59:40 -0700162{
163 struct nss_ipv4_msg *nim = (struct nss_ipv4_msg *)ncm;
Sol Kavy57d24b42014-04-05 13:45:36 -0700164 nss_ipv4_msg_callback_t cb;
Thomas Wu68250352014-04-02 18:59:40 -0700165
166 BUG_ON(ncm->interface != NSS_IPV4_RX_INTERFACE);
167
168 /*
169 * Sanity check the message type
170 */
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700171 if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) {
Thomas Wu68250352014-04-02 18:59:40 -0700172 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
173 return;
174 }
175
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800176 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv4_msg)) {
177 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Thomas Wu68250352014-04-02 18:59:40 -0700178 return;
179 }
180
Thomas Wu68250352014-04-02 18:59:40 -0700181 /*
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700182 * Trace messages.
Thomas Wu68250352014-04-02 18:59:40 -0700183 */
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700184 nss_ipv4_log_rx_msg(nim);
Thomas Wu68250352014-04-02 18:59:40 -0700185
Thomas Wu68250352014-04-02 18:59:40 -0700186 switch (nim->cm.type) {
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700187 case NSS_IPV4_RX_NODE_STATS_SYNC_MSG:
188 /*
189 * Update driver statistics on node sync.
190 */
191 nss_ipv4_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
192 break;
193
Thomas Wu68250352014-04-02 18:59:40 -0700194 case NSS_IPV4_RX_CONN_STATS_SYNC_MSG:
Sol Kavy57d24b42014-04-05 13:45:36 -0700195 /*
196 * Update driver statistics on connection sync.
197 */
198 nss_ipv4_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700199 break;
Stephen Wang709f9b52015-07-07 14:48:35 -0700200
201 case NSS_IPV4_TX_CONN_STATS_SYNC_MANY_MSG:
202 /*
203 * Update driver statistics on connection sync many.
204 */
205 nss_ipv4_driver_conn_sync_many_update(nss_ctx, &nim->msg.conn_stats_many);
Stephen Wangaed46332016-12-12 17:29:03 -0800206 ncm->cb = (nss_ptr_t)nss_ipv4_conn_sync_many_msg_cb;
Stephen Wang709f9b52015-07-07 14:48:35 -0700207 break;
Thomas Wu68250352014-04-02 18:59:40 -0700208 }
209
210 /*
Sol Kavy57d24b42014-04-05 13:45:36 -0700211 * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
212 * to the same callback/app_data.
Thomas Wu68250352014-04-02 18:59:40 -0700213 */
Sol Kavy57d24b42014-04-05 13:45:36 -0700214 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
Stephen Wangaed46332016-12-12 17:29:03 -0800215 ncm->cb = (nss_ptr_t)nss_ctx->nss_top->ipv4_callback;
216 ncm->app_data = (nss_ptr_t)nss_ctx->nss_top->ipv4_ctx;
Sol Kavy57d24b42014-04-05 13:45:36 -0700217 }
Sol Kavy2783c072014-04-05 12:53:13 -0700218
Thomas Wu68250352014-04-02 18:59:40 -0700219 /*
220 * Do we have a callback?
221 */
222 if (!ncm->cb) {
223 return;
224 }
225
226 /*
227 * Callback
228 */
Sol Kavy57d24b42014-04-05 13:45:36 -0700229 cb = (nss_ipv4_msg_callback_t)ncm->cb;
Thomas Wu68250352014-04-02 18:59:40 -0700230 cb((void *)ncm->app_data, nim);
Thomas Wu68250352014-04-02 18:59:40 -0700231}
232
233/*
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700234 * nss_ipv4_tx_sync_callback()
235 * Callback to handle the completion of synchronous tx messages.
236 */
237static void nss_ipv4_tx_sync_callback(void *app_data, struct nss_ipv4_msg *nim)
238{
239 nss_ipv4_msg_callback_t callback = (nss_ipv4_msg_callback_t)nss_ipv4_pvt.cb;
240 void *data = nss_ipv4_pvt.app_data;
241
242 nss_ipv4_pvt.cb = NULL;
243 nss_ipv4_pvt.app_data = NULL;
244
245 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
246 nss_warning("ipv4 error response %d\n", nim->cm.response);
247 nss_ipv4_pvt.response = NSS_TX_FAILURE;
248 } else {
249 nss_ipv4_pvt.response = NSS_TX_SUCCESS;
250 }
251
252 if (callback) {
253 callback(data, nim);
254 }
255
256 complete(&nss_ipv4_pvt.complete);
257}
258
259/*
260 * nss_ipv4_dscp_action_get()
261 * Gets the action mapped to dscp.
262 */
263enum nss_ipv4_dscp_map_actions nss_ipv4_dscp_action_get(uint8_t dscp)
264{
265 if (dscp > NSS_DSCP_MAP_ARRAY_SIZE) {
266 nss_warning("dscp:%u invalid\n", dscp);
267 return NSS_IPV4_DSCP_MAP_ACTION_MAX;
268 }
269
270 return mapping[dscp].action;
271}
272EXPORT_SYMBOL(nss_ipv4_dscp_action_get);
273
274/*
275 * nss_ipv4_max_conn_count()
276 * Return the maximum number of IPv4 connections that the NSS acceleration engine supports.
277 */
278int nss_ipv4_max_conn_count(void)
279{
280 return nss_ipv4_conn_cfg;
281}
282EXPORT_SYMBOL(nss_ipv4_max_conn_count);
283
284/*
285 * nss_ipv4_conn_inquiry()
286 * Inquiry if a connection has been established in NSS FW
287 */
288nss_tx_status_t nss_ipv4_conn_inquiry(struct nss_ipv4_5tuple *ipv4_5t_p,
289 nss_ipv4_msg_callback_t cb)
290{
291 nss_tx_status_t nss_tx_status;
292 struct nss_ipv4_msg nim;
293 struct nss_ctx_instance *nss_ctx = &nss_top_main.nss[0];
294
295 /*
296 * Initialize inquiry message structure.
297 * This is async message and the result will be returned
298 * to the caller by the msg_callback passed in.
299 */
300 memset(&nim, 0, sizeof(nim));
301 nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE,
302 NSS_IPV4_TX_CONN_CFG_INQUIRY_MSG,
303 sizeof(struct nss_ipv4_inquiry_msg),
304 cb, NULL);
305 nim.msg.inquiry.rr.tuple = *ipv4_5t_p;
306 nss_tx_status = nss_ipv4_tx(nss_ctx, &nim);
307 if (nss_tx_status != NSS_TX_SUCCESS) {
308 nss_warning("%p: Send inquiry message failed\n", ipv4_5t_p);
309 }
310
311 return nss_tx_status;
312}
313EXPORT_SYMBOL(nss_ipv4_conn_inquiry);
314
315/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700316 * nss_ipv4_tx_with_size()
317 * Transmit an ipv4 message to the FW with a specified size.
Thomas Wu68250352014-04-02 18:59:40 -0700318 */
Stephen Wang709f9b52015-07-07 14:48:35 -0700319nss_tx_status_t nss_ipv4_tx_with_size(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim, uint32_t size)
Thomas Wu68250352014-04-02 18:59:40 -0700320{
321 struct nss_ipv4_msg *nim2;
322 struct nss_cmn_msg *ncm = &nim->cm;
323 struct sk_buff *nbuf;
324 int32_t status;
325
326 NSS_VERIFY_CTX_MAGIC(nss_ctx);
327 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
328 nss_warning("%p: ipv4 msg dropped as core not ready", nss_ctx);
329 return NSS_TX_FAILURE_NOT_READY;
330 }
331
332 /*
333 * Sanity check the message
334 */
335 if (ncm->interface != NSS_IPV4_RX_INTERFACE) {
336 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
337 return NSS_TX_FAILURE;
338 }
339
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700340 if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) {
Thomas Wu68250352014-04-02 18:59:40 -0700341 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
342 return NSS_TX_FAILURE;
343 }
344
Suruchi Agarwalef8a8702016-01-08 12:40:08 -0800345 if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ipv4_msg)) {
346 nss_warning("%p: message length is invalid: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
Thomas Wu68250352014-04-02 18:59:40 -0700347 return NSS_TX_FAILURE;
348 }
349
Stephen Wang709f9b52015-07-07 14:48:35 -0700350 if(size > PAGE_SIZE) {
351 nss_warning("%p: tx request size too large: %u", nss_ctx, size);
352 return NSS_TX_FAILURE;
353 }
354
355 nbuf = dev_alloc_skb(size);
Thomas Wu68250352014-04-02 18:59:40 -0700356 if (unlikely(!nbuf)) {
Sundarajan Srinivasan62fee7e2015-01-22 11:13:10 -0800357 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]);
Thomas Wu68250352014-04-02 18:59:40 -0700358 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
359 return NSS_TX_FAILURE;
360 }
361
362 /*
363 * Copy the message to our skb.
364 */
Suruchi Agarwalea2e5232016-09-14 10:32:08 -0700365 nim2 = (struct nss_ipv4_msg *)skb_put(nbuf, size);
Thomas Wu68250352014-04-02 18:59:40 -0700366 memcpy(nim2, nim, sizeof(struct nss_ipv4_msg));
367
Suruchi Agarwale3940e72016-07-06 15:56:51 -0700368 /*
369 * Trace messages.
370 */
371 nss_ipv4_log_tx_msg(nim);
372
Thomas Wu68250352014-04-02 18:59:40 -0700373 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
374 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530375 dev_kfree_skb_any(nbuf);
Sol Kavycd1bd5c2014-04-04 11:09:44 -0700376 nss_warning("%p: unable to enqueue IPv4 msg\n", nss_ctx);
Thomas Wu68250352014-04-02 18:59:40 -0700377 return NSS_TX_FAILURE;
378 }
379
Stephen Wang90c67de2016-04-26 15:15:59 -0700380 nss_hal_send_interrupt(nss_ctx, NSS_H2N_INTR_DATA_COMMAND_QUEUE);
Thomas Wu68250352014-04-02 18:59:40 -0700381
382 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
383 return NSS_TX_SUCCESS;
384}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700385EXPORT_SYMBOL(nss_ipv4_tx_with_size);
Thomas Wu68250352014-04-02 18:59:40 -0700386
387/*
Stephen Wang709f9b52015-07-07 14:48:35 -0700388 * nss_ipv4_tx()
389 * Transmit an ipv4 message to the FW.
390 */
391nss_tx_status_t nss_ipv4_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim)
392{
393 return nss_ipv4_tx_with_size(nss_ctx, nim, NSS_NBUF_PAYLOAD_SIZE);
394}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700395EXPORT_SYMBOL(nss_ipv4_tx);
Stephen Wang709f9b52015-07-07 14:48:35 -0700396
397/*
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700398 * nss_ipv4_tx_sync()
399 * Transmit a synchronous ipv4 message to the FW.
400 */
401nss_tx_status_t nss_ipv4_tx_sync(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim)
402{
403 nss_tx_status_t status;
404 int ret = 0;
405
406 down(&nss_ipv4_pvt.sem);
407 nss_ipv4_pvt.cb = (void *)nim->cm.cb;
408 nss_ipv4_pvt.app_data = (void *)nim->cm.app_data;
409
410 nim->cm.cb = (nss_ptr_t)nss_ipv4_tx_sync_callback;
411 nim->cm.app_data = (nss_ptr_t)NULL;
412
413 status = nss_ipv4_tx(nss_ctx, nim);
414 if (status != NSS_TX_SUCCESS) {
415 nss_warning("%p: nss ipv4 msg tx failed\n", nss_ctx);
416 up(&nss_ipv4_pvt.sem);
417 return status;
418 }
419
420 ret = wait_for_completion_timeout(&nss_ipv4_pvt.complete, msecs_to_jiffies(NSS_IPV4_TX_MSG_TIMEOUT));
421 if (!ret) {
422 nss_warning("%p: IPv4 tx sync failed due to timeout\n", nss_ctx);
423 nss_ipv4_pvt.response = NSS_TX_FAILURE;
424 }
425
426 status = nss_ipv4_pvt.response;
427 up(&nss_ipv4_pvt.sem);
428 return status;
429}
430EXPORT_SYMBOL(nss_ipv4_tx_sync);
431
432/*
Thomas Wu68250352014-04-02 18:59:40 -0700433 **********************************
434 Register/Unregister/Miscellaneous APIs
435 **********************************
436 */
437
438/*
439 * nss_ipv4_notify_register()
440 * Register to received IPv4 events.
441 *
442 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
443 */
444struct nss_ctx_instance *nss_ipv4_notify_register(nss_ipv4_msg_callback_t cb, void *app_data)
445{
446 /*
447 * TODO: We need to have a new array in support of the new API
448 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
449 */
450 nss_top_main.ipv4_callback = cb;
Abhishek Rastogie11f47b2014-04-04 18:43:32 +0530451 nss_top_main.ipv4_ctx = app_data;
Thomas Wu68250352014-04-02 18:59:40 -0700452 return &nss_top_main.nss[nss_top_main.ipv4_handler_id];
453}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700454EXPORT_SYMBOL(nss_ipv4_notify_register);
Thomas Wu68250352014-04-02 18:59:40 -0700455
456/*
457 * nss_ipv4_notify_unregister()
458 * Unregister to received IPv4 events.
459 *
460 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
461 */
462void nss_ipv4_notify_unregister(void)
463{
464 nss_top_main.ipv4_callback = NULL;
465}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700466EXPORT_SYMBOL(nss_ipv4_notify_unregister);
Thomas Wu68250352014-04-02 18:59:40 -0700467
468/*
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700469 * nss_ipv4_conn_sync_many_notify_register()
470 * Register to receive IPv4 conn_sync_many message response.
471 */
472void nss_ipv4_conn_sync_many_notify_register(nss_ipv4_msg_callback_t cb)
473{
474 nss_ipv4_conn_sync_many_msg_cb = cb;
475}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700476EXPORT_SYMBOL(nss_ipv4_conn_sync_many_notify_register);
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700477
478/*
479 * nss_ipv4_conn_sync_many_notify_unregister()
480 * Unregister to receive IPv4 conn_sync_many message response.
481 */
482void nss_ipv4_conn_sync_many_notify_unregister(void)
483{
484 nss_ipv4_conn_sync_many_msg_cb = NULL;
485}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700486EXPORT_SYMBOL(nss_ipv4_conn_sync_many_notify_unregister);
Suruchi Agarwal611ecd02016-08-04 15:54:35 -0700487
488/*
Thomas Wu68250352014-04-02 18:59:40 -0700489 * nss_ipv4_get_mgr()
490 *
491 * TODO: This only suppports a single ipv4, do we ever want to support more?
492 */
493struct nss_ctx_instance *nss_ipv4_get_mgr(void)
494{
495 return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id];
496}
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700497EXPORT_SYMBOL(nss_ipv4_get_mgr);
Thomas Wu68250352014-04-02 18:59:40 -0700498
499/*
500 * nss_ipv4_register_handler()
501 * Register our handler to receive messages for this interface
502 */
Sol Kavy2783c072014-04-05 12:53:13 -0700503void nss_ipv4_register_handler(void)
Thomas Wu68250352014-04-02 18:59:40 -0700504{
Thomas Wu91f4bdf2017-06-09 12:03:02 -0700505 struct nss_ctx_instance *nss_ctx = nss_ipv4_get_mgr();
506
507 if (nss_core_register_handler(nss_ctx, NSS_IPV4_RX_INTERFACE, nss_ipv4_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) {
Thomas Wu68250352014-04-02 18:59:40 -0700508 nss_warning("IPv4 handler failed to register");
509 }
510}
511
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700512/*
513 * nss_ipv4_conn_cfg_process_callback()
514 * Call back function for the ipv4 connection configure process
515 */
516static void nss_ipv4_conn_cfg_process_callback(void *app_data, struct nss_ipv4_msg *nim)
517{
518 struct nss_ipv4_rule_conn_cfg_msg *nirccm = &nim->msg.rule_conn_cfg;
519 struct nss_ctx_instance *nss_ctx __maybe_unused = nss_ipv4_get_mgr();
520
521 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
522 nss_warning("%p: IPv4 connection configuration failed with error: %d\n", nss_ctx, nim->cm.error);
523 nss_core_update_max_ipv4_conn(NSS_DEFAULT_NUM_CONN);
524 nss_ipv4_free_conn_tables();
525 return;
526 }
527
528 nss_ipv4_conn_cfg = ntohl(nirccm->num_conn);
529 nss_warning("%p: IPv4 connection configuration success: %d\n", nss_ctx, nim->cm.error);
530}
531
Vijay Dewangan9db18752014-09-15 16:25:01 -0700532/*
Tushar Mathura3c18932015-08-24 20:27:21 +0530533 * nss_ipv4_conn_cfg_process()
534 * Process request to configure number of ipv4 connections
535 */
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700536static int nss_ipv4_conn_cfg_process(struct nss_ctx_instance *nss_ctx, int conn)
Tushar Mathura3c18932015-08-24 20:27:21 +0530537{
538 struct nss_ipv4_msg nim;
539 struct nss_ipv4_rule_conn_cfg_msg *nirccm;
540 nss_tx_status_t nss_tx_status;
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700541
542 if ((!nss_ipv4_ct_info.ce_table_size) || (!nss_ipv4_ct_info.cme_table_size)) {
543 nss_warning("%p: connection entry or connection match entry table size not available\n",
544 nss_ctx);
545 return -EINVAL;
546 }
547
548 nss_info("%p: IPv4 supported connections: %d\n", nss_ctx, conn);
549
550 nss_ipv4_ct_info.ce_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
551 get_order(nss_ipv4_ct_info.ce_table_size));
552 if (!nss_ipv4_ct_info.ce_mem) {
553 nss_warning("%p: Memory allocation failed for IPv4 Connections: %d\n",
554 nss_ctx,
555 conn);
556 goto fail;
557 }
558
559 nss_ipv4_ct_info.cme_mem = __get_free_pages(GFP_KERNEL | __GFP_NOWARN | __GFP_ZERO,
560 get_order(nss_ipv4_ct_info.cme_table_size));
561 if (!nss_ipv4_ct_info.ce_mem) {
562 nss_warning("%p: Memory allocation failed for IPv4 Connections: %d\n",
563 nss_ctx,
564 conn);
565 goto fail;
566 }
567
568 memset(&nim, 0, sizeof(struct nss_ipv4_msg));
569 nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_CONN_CFG_RULE_MSG,
570 sizeof(struct nss_ipv4_rule_conn_cfg_msg), nss_ipv4_conn_cfg_process_callback, NULL);
571
572 nirccm = &nim.msg.rule_conn_cfg;
573 nirccm->num_conn = htonl(conn);
Suruchi Agarwal8c9e7162017-08-17 15:58:40 -0700574 nirccm->ce_mem = dma_map_single(nss_ctx->dev, (void *)nss_ipv4_ct_info.ce_mem, nss_ipv4_ct_info.ce_table_size, DMA_TO_DEVICE);
575 if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->ce_mem))) {
576 nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv4_ct_info.ce_mem);
577 goto fail;
578 }
579
580 nirccm->cme_mem = dma_map_single(nss_ctx->dev, (void *)nss_ipv4_ct_info.cme_mem, nss_ipv4_ct_info.cme_table_size, DMA_TO_DEVICE);
581 if (unlikely(dma_mapping_error(nss_ctx->dev, nirccm->cme_mem))) {
582 nss_warning("%p: DMA mapping failed for virtual address = %p", nss_ctx, (void *)nss_ipv4_ct_info.cme_mem);
583 goto fail;
584 }
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700585
586 nss_tx_status = nss_ipv4_tx(nss_ctx, &nim);
587 if (nss_tx_status != NSS_TX_SUCCESS) {
588 nss_warning("%p: nss_tx error setting IPv4 Connections: %d\n",
589 nss_ctx,
590 conn);
591 goto fail;
592 }
593
594 return 0;
595
596fail:
597 nss_ipv4_free_conn_tables();
598 return -EINVAL;;
599}
600
601/*
602 * nss_ipv4_update_conn_count_callback()
603 * Callback function for the ipv4 get connection info message.
604 */
605static void nss_ipv4_update_conn_count_callback(void *app_data, struct nss_ipv4_msg *nim)
606{
607 struct nss_ipv4_rule_conn_get_table_size_msg *nircgts = &nim->msg.size;
608 struct nss_ctx_instance *nss_ctx = nss_ipv4_get_mgr();
609
610 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
611 nss_warning("%p: IPv4 fetch connection info failed with error: %d\n", nss_ctx, nim->cm.error);
612 nss_core_update_max_ipv4_conn(NSS_DEFAULT_NUM_CONN);
613 return;
614 }
615
616 nss_info("IPv4 get connection info success\n");
617
618 nss_ipv4_ct_info.ce_table_size = ntohl(nircgts->ce_table_size);
619 nss_ipv4_ct_info.cme_table_size = ntohl(nircgts->cme_table_size);
620
621 if (nss_ipv4_conn_cfg_process(nss_ctx, ntohl(nircgts->num_conn)) != 0) {
622 nss_warning("%p: IPv4 connection entry or connection match entry table size\
623 not available\n", nss_ctx);
624 }
625
626 return;
627}
628
629/*
630 * nss_ipv4_update_conn_count()
631 * Sets the maximum number of IPv4 connections.
632 *
633 * It first gets the connection tables size information from NSS FW
634 * and then configures the connections in NSS FW.
635 */
636int nss_ipv4_update_conn_count(int ipv4_num_conn)
637{
638 struct nss_ctx_instance *nss_ctx = nss_ipv4_get_mgr();
639 struct nss_ipv4_msg nim;
640 struct nss_ipv4_rule_conn_get_table_size_msg *nircgts;
641 nss_tx_status_t nss_tx_status;
Tushar Mathura3c18932015-08-24 20:27:21 +0530642 uint32_t sum_of_conn;
643
644 /*
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700645 * By default, NSS FW is configured with default number of connections.
646 */
647 if (ipv4_num_conn == NSS_DEFAULT_NUM_CONN) {
648 nss_info("%p: Default number of connections (%d) already configured\n", nss_ctx, ipv4_num_conn);
649 return 0;
650 }
651
652 /*
Tushar Mathura3c18932015-08-24 20:27:21 +0530653 * The input should be multiple of 1024.
654 * Input for ipv4 and ipv6 sum together should not exceed 8k
655 * Min. value should be at least 256 connections. This is the
656 * minimum connections we will support for each of them.
657 */
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700658 sum_of_conn = ipv4_num_conn + nss_ipv6_conn_cfg;
659 if ((ipv4_num_conn & NSS_NUM_CONN_QUANTA_MASK) ||
Tushar Mathura3c18932015-08-24 20:27:21 +0530660 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700661 (ipv4_num_conn < NSS_MIN_NUM_CONN)) {
Tushar Mathura3c18932015-08-24 20:27:21 +0530662 nss_warning("%p: input supported connections (%d) does not adhere\
663 specifications\n1) not multiple of 1024,\n2) is less than \
664 min val: %d, OR\n IPv4/6 total exceeds %d\n",
665 nss_ctx,
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700666 ipv4_num_conn,
Tushar Mathura3c18932015-08-24 20:27:21 +0530667 NSS_MIN_NUM_CONN,
668 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
669 return -EINVAL;
670 }
671
Tushar Mathura3c18932015-08-24 20:27:21 +0530672 memset(&nim, 0, sizeof(struct nss_ipv4_msg));
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700673 nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_CONN_TABLE_SIZE_MSG,
674 sizeof(struct nss_ipv4_rule_conn_get_table_size_msg), nss_ipv4_update_conn_count_callback, NULL);
Tushar Mathura3c18932015-08-24 20:27:21 +0530675
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700676 nircgts = &nim.msg.size;
677 nircgts->num_conn = htonl(ipv4_num_conn);
Tushar Mathura3c18932015-08-24 20:27:21 +0530678 nss_tx_status = nss_ipv4_tx(nss_ctx, &nim);
679
680 if (nss_tx_status != NSS_TX_SUCCESS) {
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700681 nss_warning("%p: Send fetch connection info message failed\n", nss_ctx);
682 return -EINVAL;
Tushar Mathura3c18932015-08-24 20:27:21 +0530683 }
684
685 return 0;
686}
687
Stephen Wang0a2756a2016-08-04 15:52:47 -0700688/*
Suruchi Agarwalcdcb5b42017-07-06 11:08:22 -0700689 * nss_ipv4_free_conn_tables()
690 * Frees memory allocated for connection tables
691 */
692void nss_ipv4_free_conn_tables(void)
693{
694 if (nss_ipv4_ct_info.ce_mem) {
695 free_pages(nss_ipv4_ct_info.ce_mem, get_order(nss_ipv4_ct_info.ce_table_size));
696 }
697
698 if (nss_ipv4_ct_info.cme_mem) {
699 free_pages(nss_ipv4_ct_info.cme_mem, get_order(nss_ipv4_ct_info.cme_table_size));
700 }
701
702 memset(&nss_ipv4_ct_info, 0, sizeof(struct nss_ipv4_conn_table_info));
703 return;
704}
705
706/*
Stephen Wang0a2756a2016-08-04 15:52:47 -0700707 * nss_ipv4_accel_mode_cfg_handler()
708 * Configure acceleration mode for IPv4
709 */
710static int nss_ipv4_accel_mode_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
711{
712 struct nss_top_instance *nss_top = &nss_top_main;
713 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
714 struct nss_ipv4_msg nim;
715 struct nss_ipv4_accel_mode_cfg_msg *nipcm;
716 nss_tx_status_t nss_tx_status;
717 int ret = NSS_FAILURE;
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700718 int current_value;
Stephen Wang0a2756a2016-08-04 15:52:47 -0700719
720 /*
721 * Take snap shot of current value
722 */
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700723 current_value = nss_ipv4_accel_mode_cfg;
Stephen Wang0a2756a2016-08-04 15:52:47 -0700724
725 /*
726 * Write the variable with user input
727 */
728 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
729 if (ret || (!write)) {
Stephen Wang0a2756a2016-08-04 15:52:47 -0700730 return ret;
731 }
732
733 memset(&nim, 0, sizeof(struct nss_ipv4_msg));
734 nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_ACCEL_MODE_CFG_MSG,
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700735 sizeof(struct nss_ipv4_accel_mode_cfg_msg), NULL, NULL);
Stephen Wang0a2756a2016-08-04 15:52:47 -0700736
737 nipcm = &nim.msg.accel_mode_cfg;
738 nipcm->mode = htonl(nss_ipv4_accel_mode_cfg);
Stephen Wang0a2756a2016-08-04 15:52:47 -0700739
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700740 nss_tx_status = nss_ipv4_tx_sync(nss_ctx, &nim);
Stephen Wang0a2756a2016-08-04 15:52:47 -0700741 if (nss_tx_status != NSS_TX_SUCCESS) {
742 nss_warning("%p: Send acceleration mode message failed\n", nss_ctx);
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700743 nss_ipv4_accel_mode_cfg = current_value;
744 return -EIO;
745 }
746
747 return 0;
748}
749
750/*
751 * nss_ipv4_dscp_map_cfg_handler()
752 * Sysctl handler for dscp/pri mappings.
753 */
754static int nss_ipv4_dscp_map_cfg_handler(struct ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
755{
756 struct nss_top_instance *nss_top = &nss_top_main;
757 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
758 struct nss_dscp_map_parse out;
759 struct nss_ipv4_msg nim;
760 struct nss_ipv4_dscp2pri_cfg_msg *nipd2p;
761 nss_tx_status_t status;
762 int ret;
763
764 if (!write) {
765 return nss_dscp_map_print(ctl, buffer, lenp, ppos, mapping);
766 }
767
768 ret = nss_dscp_map_parse(ctl, buffer, lenp, ppos, &out);
769 if (ret) {
770 nss_warning("failed to parse dscp mapping:%d\n", ret);
771 nss_ipv4_dscp_map_usage();
772 return ret;
773 }
774
775 if (out.action >= NSS_IPV4_DSCP_MAP_ACTION_MAX) {
776 nss_warning("invalid action value: %d\n", out.action);
777 nss_ipv4_dscp_map_usage();
778 return -EINVAL;
779 }
780
781 memset(&nim, 0, sizeof(struct nss_ipv4_msg));
782 nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_DSCP2PRI_CFG_MSG,
783 sizeof(struct nss_ipv4_dscp2pri_cfg_msg), NULL, NULL);
784
785 nipd2p = &nim.msg.dscp2pri_cfg;
786 nipd2p->dscp = out.dscp;
787 nipd2p->priority = out.priority;
788
789 status = nss_ipv4_tx_sync(nss_ctx, &nim);
790 if (status != NSS_TX_SUCCESS) {
791 nss_warning("%p: ipv4 dscp2pri config message failed\n", nss_ctx);
792 return -EFAULT;
Stephen Wang0a2756a2016-08-04 15:52:47 -0700793 }
794
795 /*
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700796 * NSS firmware acknowleged the configuration, so update the mapping
797 * table on HOST side as well.
Stephen Wang0a2756a2016-08-04 15:52:47 -0700798 */
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700799 mapping[out.dscp].action = out.action;
800 mapping[out.dscp].priority = out.priority;
Stephen Wang0a2756a2016-08-04 15:52:47 -0700801
Stephen Wang0a2756a2016-08-04 15:52:47 -0700802 return 0;
Stephen Wang0a2756a2016-08-04 15:52:47 -0700803}
804
Stephen Wang52e6d342016-03-29 15:02:33 -0700805static struct ctl_table nss_ipv4_table[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700806 {
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700807 .procname = "ipv4_accel_mode",
808 .data = &nss_ipv4_accel_mode_cfg,
809 .maxlen = sizeof(int),
810 .mode = 0644,
811 .proc_handler = &nss_ipv4_accel_mode_cfg_handler,
812 },
813 {
814 .procname = "ipv4_dscp_map",
815 .data = &mapping[NSS_DSCP_MAP_ARRAY_SIZE],
816 .maxlen = sizeof(struct nss_dscp_map_entry),
817 .mode = 0644,
818 .proc_handler = &nss_ipv4_dscp_map_cfg_handler,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700819 },
820 { }
821};
822
Stephen Wang52e6d342016-03-29 15:02:33 -0700823static struct ctl_table nss_ipv4_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700824 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700825 .procname = "ipv4cfg",
826 .mode = 0555,
827 .child = nss_ipv4_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700828 },
829 { }
830};
831
Stephen Wang52e6d342016-03-29 15:02:33 -0700832static struct ctl_table nss_ipv4_root_dir[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700833 {
834 .procname = "nss",
835 .mode = 0555,
836 .child = nss_ipv4_dir,
837 },
838 { }
839};
840
Stephen Wang52e6d342016-03-29 15:02:33 -0700841static struct ctl_table nss_ipv4_root[] = {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700842 {
843 .procname = "dev",
844 .mode = 0555,
845 .child = nss_ipv4_root_dir,
846 },
847 { }
848};
849
850static struct ctl_table_header *nss_ipv4_header;
851
852/*
853 * nss_ipv4_register_sysctl()
854 * Register sysctl specific to ipv4
855 */
856void nss_ipv4_register_sysctl(void)
857{
Sakthi Vignesh Radhakrishnan8d02a2d2017-09-06 14:38:59 -0700858 sema_init(&nss_ipv4_pvt.sem, 1);
859 init_completion(&nss_ipv4_pvt.complete);
Stephen Wang49b474b2016-03-25 10:40:30 -0700860
Vijay Dewangan9db18752014-09-15 16:25:01 -0700861 /*
862 * Register sysctl table.
863 */
864 nss_ipv4_header = register_sysctl_table(nss_ipv4_root);
865}
866
867/*
868 * nss_ipv4_unregister_sysctl()
869 * Unregister sysctl specific to ipv4
870 */
871void nss_ipv4_unregister_sysctl(void)
872{
873 /*
874 * Unregister sysctl table.
875 */
876 if (nss_ipv4_header) {
877 unregister_sysctl_table(nss_ipv4_header);
878 }
879}
880
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700881/*
882 * nss_ipv4_msg_init()
883 * Initialize IPv4 message.
884 */
885void nss_ipv4_msg_init(struct nss_ipv4_msg *nim, uint16_t if_num, uint32_t type, uint32_t len,
Sundarajan Srinivasan30a53d42015-01-30 10:52:08 -0800886 nss_ipv4_msg_callback_t cb, void *app_data)
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700887{
888 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
889}
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700890EXPORT_SYMBOL(nss_ipv4_msg_init);