blob: 2825370d99dd129fb1698abd20bd8c1d7860b341 [file] [log] [blame]
Thomas Wu68250352014-04-02 18:59:40 -07001/*
2 **************************************************************************
Vijay Dewangan488e5372014-12-29 21:40:11 -08003 * Copyright (c) 2013-2015, 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"
Thomas Wu68250352014-04-02 18:59:40 -070023
Vijay Dewangan4861f4e2014-10-14 16:56:35 -070024int nss_ipv4_conn_cfg __read_mostly = NSS_DEFAULT_NUM_CONN;
25static struct nss_conn_cfg_pvt i4cfgp;
Vijay Dewangan9db18752014-09-15 16:25:01 -070026
Thomas Wu68250352014-04-02 18:59:40 -070027/*
Sol Kavy57d24b42014-04-05 13:45:36 -070028 * nss_ipv4_driver_conn_sync_update()
Thomas Wu68250352014-04-02 18:59:40 -070029 * Update driver specific information from the messsage.
30 */
Murat Sezgin0c0561d2014-04-09 18:55:58 -070031static 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 -070032{
Sol Kavy57d24b42014-04-05 13:45:36 -070033 struct nss_top_instance *nss_top = nss_ctx->nss_top;
Sol Kavy57d24b42014-04-05 13:45:36 -070034
Thomas Wu68250352014-04-02 18:59:40 -070035 /*
36 * Update statistics maintained by NSS driver
37 */
38 spin_lock_bh(&nss_top->stats_lock);
Thomas Wu68250352014-04-02 18:59:40 -070039 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_PKTS] += nirs->flow_rx_packet_count + nirs->return_rx_packet_count;
40 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_BYTES] += nirs->flow_rx_byte_count + nirs->return_rx_byte_count;
41 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count;
42 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 -070043 spin_unlock_bh(&nss_top->stats_lock);
44}
Thomas Wu68250352014-04-02 18:59:40 -070045
46/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -070047 * nss_ipv4_driver_node_sync_update)
48 * Update driver specific information from the messsage.
49 */
50static void nss_ipv4_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_node_sync *nins)
51{
52 struct nss_top_instance *nss_top = nss_ctx->nss_top;
53 uint32_t i;
54
55 /*
56 * Update statistics maintained by NSS driver
57 */
58 spin_lock_bh(&nss_top->stats_lock);
59 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
60 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
61 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped;
62 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
63 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
64
Murat Sezgin0c0561d2014-04-09 18:55:58 -070065 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_REQUESTS] += nins->ipv4_connection_create_requests;
66 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_COLLISIONS] += nins->ipv4_connection_create_collisions;
67 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv4_connection_create_invalid_interface;
68 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_REQUESTS] += nins->ipv4_connection_destroy_requests;
69 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_MISSES] += nins->ipv4_connection_destroy_misses;
70 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_HITS] += nins->ipv4_connection_hash_hits;
71 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_REORDERS] += nins->ipv4_connection_hash_reorders;
72 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_FLUSHES] += nins->ipv4_connection_flushes;
73 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_EVICTIONS] += nins->ipv4_connection_evictions;
Selin Dag60ea2b22014-11-05 09:36:22 -080074 nss_top->stats_ipv4[NSS_STATS_IPV4_FRAGMENTATIONS] += nins->ipv4_fragmentations;
Murat Sezgin0c0561d2014-04-09 18:55:58 -070075
76 for (i = 0; i < NSS_EXCEPTION_EVENT_IPV4_MAX; i++) {
77 nss_top->stats_if_exception_ipv4[i] += nins->exception_events[i];
78 }
79 spin_unlock_bh(&nss_top->stats_lock);
80}
81
82/*
Sol Kavy2783c072014-04-05 12:53:13 -070083 * nss_ipv4_rx_msg_handler()
Thomas Wu68250352014-04-02 18:59:40 -070084 * Handle NSS -> HLOS messages for IPv4 bridge/route
85 */
Sol Kavy2783c072014-04-05 12:53:13 -070086static 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 -070087{
88 struct nss_ipv4_msg *nim = (struct nss_ipv4_msg *)ncm;
Sol Kavy57d24b42014-04-05 13:45:36 -070089 nss_ipv4_msg_callback_t cb;
Thomas Wu68250352014-04-02 18:59:40 -070090
91 BUG_ON(ncm->interface != NSS_IPV4_RX_INTERFACE);
92
93 /*
94 * Sanity check the message type
95 */
Murat Sezgin5c8c7362014-09-02 17:58:21 -070096 if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) {
Thomas Wu68250352014-04-02 18:59:40 -070097 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
98 return;
99 }
100
101 if (ncm->len > sizeof(struct nss_ipv4_msg)) {
102 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
103 return;
104 }
105
Thomas Wu68250352014-04-02 18:59:40 -0700106 /*
Thomas Wu68250352014-04-02 18:59:40 -0700107 * Log failures
108 */
109 nss_core_log_msg_failures(nss_ctx, ncm);
110
Thomas Wu68250352014-04-02 18:59:40 -0700111 switch (nim->cm.type) {
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700112 case NSS_IPV4_RX_NODE_STATS_SYNC_MSG:
113 /*
114 * Update driver statistics on node sync.
115 */
116 nss_ipv4_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
117 break;
118
Thomas Wu68250352014-04-02 18:59:40 -0700119 case NSS_IPV4_RX_CONN_STATS_SYNC_MSG:
Sol Kavy57d24b42014-04-05 13:45:36 -0700120 /*
121 * Update driver statistics on connection sync.
122 */
123 nss_ipv4_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700124 break;
Thomas Wu68250352014-04-02 18:59:40 -0700125 }
126
127 /*
Sol Kavy57d24b42014-04-05 13:45:36 -0700128 * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
129 * to the same callback/app_data.
Thomas Wu68250352014-04-02 18:59:40 -0700130 */
Sol Kavy57d24b42014-04-05 13:45:36 -0700131 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
132 ncm->cb = (uint32_t)nss_ctx->nss_top->ipv4_callback;
133 ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv4_ctx;
134 }
Sol Kavy2783c072014-04-05 12:53:13 -0700135
Thomas Wu68250352014-04-02 18:59:40 -0700136 /*
137 * Do we have a callback?
138 */
139 if (!ncm->cb) {
140 return;
141 }
142
143 /*
144 * Callback
145 */
Sol Kavy57d24b42014-04-05 13:45:36 -0700146 cb = (nss_ipv4_msg_callback_t)ncm->cb;
Thomas Wu68250352014-04-02 18:59:40 -0700147 cb((void *)ncm->app_data, nim);
Thomas Wu68250352014-04-02 18:59:40 -0700148}
149
150/*
151 * nss_ipv4_tx()
152 * Transmit an ipv4 message to the FW.
153 */
154nss_tx_status_t nss_ipv4_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim)
155{
156 struct nss_ipv4_msg *nim2;
157 struct nss_cmn_msg *ncm = &nim->cm;
158 struct sk_buff *nbuf;
159 int32_t status;
160
161 NSS_VERIFY_CTX_MAGIC(nss_ctx);
162 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
163 nss_warning("%p: ipv4 msg dropped as core not ready", nss_ctx);
164 return NSS_TX_FAILURE_NOT_READY;
165 }
166
167 /*
168 * Sanity check the message
169 */
170 if (ncm->interface != NSS_IPV4_RX_INTERFACE) {
171 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
172 return NSS_TX_FAILURE;
173 }
174
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700175 if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) {
Thomas Wu68250352014-04-02 18:59:40 -0700176 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
177 return NSS_TX_FAILURE;
178 }
179
180 if (ncm->len > sizeof(struct nss_ipv4_msg)) {
181 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
182 return NSS_TX_FAILURE;
183 }
184
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530185 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
Thomas Wu68250352014-04-02 18:59:40 -0700186 if (unlikely(!nbuf)) {
187 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
188 nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
189 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
190 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
191 return NSS_TX_FAILURE;
192 }
193
194 /*
195 * Copy the message to our skb.
196 */
197 nim2 = (struct nss_ipv4_msg *)skb_put(nbuf, sizeof(struct nss_ipv4_msg));
198 memcpy(nim2, nim, sizeof(struct nss_ipv4_msg));
199
200 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
201 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530202 dev_kfree_skb_any(nbuf);
Sol Kavycd1bd5c2014-04-04 11:09:44 -0700203 nss_warning("%p: unable to enqueue IPv4 msg\n", nss_ctx);
Thomas Wu68250352014-04-02 18:59:40 -0700204 return NSS_TX_FAILURE;
205 }
206
207 nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
208 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
209
210 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
211 return NSS_TX_SUCCESS;
212}
213
214/*
215 **********************************
216 Register/Unregister/Miscellaneous APIs
217 **********************************
218 */
219
220/*
221 * nss_ipv4_notify_register()
222 * Register to received IPv4 events.
223 *
224 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
225 */
226struct nss_ctx_instance *nss_ipv4_notify_register(nss_ipv4_msg_callback_t cb, void *app_data)
227{
228 /*
229 * TODO: We need to have a new array in support of the new API
230 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
231 */
232 nss_top_main.ipv4_callback = cb;
Abhishek Rastogie11f47b2014-04-04 18:43:32 +0530233 nss_top_main.ipv4_ctx = app_data;
Thomas Wu68250352014-04-02 18:59:40 -0700234 return &nss_top_main.nss[nss_top_main.ipv4_handler_id];
235}
236
237/*
238 * nss_ipv4_notify_unregister()
239 * Unregister to received IPv4 events.
240 *
241 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
242 */
243void nss_ipv4_notify_unregister(void)
244{
245 nss_top_main.ipv4_callback = NULL;
246}
247
248/*
249 * nss_ipv4_get_mgr()
250 *
251 * TODO: This only suppports a single ipv4, do we ever want to support more?
252 */
253struct nss_ctx_instance *nss_ipv4_get_mgr(void)
254{
255 return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id];
256}
257
258/*
259 * nss_ipv4_register_handler()
260 * Register our handler to receive messages for this interface
261 */
Sol Kavy2783c072014-04-05 12:53:13 -0700262void nss_ipv4_register_handler(void)
Thomas Wu68250352014-04-02 18:59:40 -0700263{
Sol Kavy2783c072014-04-05 12:53:13 -0700264 if (nss_core_register_handler(NSS_IPV4_RX_INTERFACE, nss_ipv4_rx_msg_handler, NULL) != NSS_CORE_STATUS_SUCCESS) {
Thomas Wu68250352014-04-02 18:59:40 -0700265 nss_warning("IPv4 handler failed to register");
266 }
267}
268
Vijay Dewangan9db18752014-09-15 16:25:01 -0700269/*
270 * nss_ipv4_conn_cfg_callback()
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700271 * call back function for the ipv4 connection configuration handler
Vijay Dewangan9db18752014-09-15 16:25:01 -0700272 */
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700273static void nss_ipv4_conn_cfg_callback(void *app_data, struct nss_ipv4_msg *nim)
Vijay Dewangan9db18752014-09-15 16:25:01 -0700274{
275
276 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
277 nss_warning("IPv4 connection configuration failed with error: %d\n", nim->cm.error);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700278 /*
279 * Error, hence we are not updating the nss_ipv4_conn_cfg
280 * Restore the current_value to its previous state
281 */
Vijay Dewangan488e5372014-12-29 21:40:11 -0800282 i4cfgp.response = NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700283 complete(&i4cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700284 return;
285 }
286
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700287 /*
288 * Sucess at NSS FW, hence updating nss_ipv4_conn_cfg, with the valid value
289 * saved at the sysctl handler.
290 */
Vijay Dewangan9db18752014-09-15 16:25:01 -0700291 nss_info("IPv4 connection configuration success: %d\n", nim->cm.error);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800292 i4cfgp.response = NSS_SUCCESS;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700293 complete(&i4cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700294}
295
296/*
297 * nss_ipv4_conn_cfg_handler()
298 * Sets the number of connections for IPv4
299 */
300static int nss_ipv4_conn_cfg_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
301{
302 struct nss_top_instance *nss_top = &nss_top_main;
303 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
304 struct nss_ipv4_msg nim;
305 struct nss_ipv4_rule_conn_cfg_msg *nirccm;
306 nss_tx_status_t nss_tx_status;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800307 int ret = NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700308 uint32_t sum_of_conn;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700309
310 /*
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700311 * Acquiring semaphore
312 */
313 down(&i4cfgp.sem);
314
315 /*
316 * Take snap shot of current value
317 */
318 i4cfgp.current_value = nss_ipv4_conn_cfg;
319
320 /*
321 * Write the variable with user input
322 */
323 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
324 if (ret || (!write)) {
325 up(&i4cfgp.sem);
326 return ret;
327 }
328
329 /*
330 * The input should be multiple of 1024.
331 * Input for ipv4 and ipv6 sum together should not exceed 8k
332 * Min. value should be at least 256 connections. This is the
Vijay Dewangan9db18752014-09-15 16:25:01 -0700333 * minimum connections we will support for each of them.
334 */
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700335 sum_of_conn = nss_ipv4_conn_cfg + nss_ipv6_conn_cfg;
336 if ((nss_ipv4_conn_cfg & NSS_NUM_CONN_QUANTA_MASK) ||
337 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
338 (nss_ipv4_conn_cfg < NSS_MIN_NUM_CONN)) {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700339 nss_warning("%p: input supported connections (%d) does not adhere\
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700340 specifications\n1) not multiple of 1024,\n2) is less than \
Vijay Dewangan9db18752014-09-15 16:25:01 -0700341 min val: %d, OR\n IPv4/6 total exceeds %d\n",
342 nss_ctx,
343 nss_ipv4_conn_cfg,
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700344 NSS_MIN_NUM_CONN,
345 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
346
347 /*
348 * Restore the current_value to its previous state
349 */
350 nss_ipv4_conn_cfg = i4cfgp.current_value;
351 up(&i4cfgp.sem);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800352 return NSS_FAILURE;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700353 }
354
Vijay Dewangan9db18752014-09-15 16:25:01 -0700355 nss_info("%p: IPv4 supported connections: %d\n", nss_ctx, nss_ipv4_conn_cfg);
356
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700357 nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_CONN_CFG_RULE_MSG,
358 sizeof(struct nss_ipv4_rule_conn_cfg_msg), (nss_ipv4_msg_callback_t *)nss_ipv4_conn_cfg_callback, NULL);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700359
360 nirccm = &nim.msg.rule_conn_cfg;
361 nirccm->num_conn = htonl(nss_ipv4_conn_cfg);
362 nss_tx_status = nss_ipv4_tx(nss_ctx, &nim);
363
364 if (nss_tx_status != NSS_TX_SUCCESS) {
365 nss_warning("%p: nss_tx error setting IPv4 Connections: %d\n",
366 nss_ctx,
367 nss_ipv4_conn_cfg);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700368
369 /*
370 * Restore the current_value to its previous state
371 */
372 nss_ipv4_conn_cfg = i4cfgp.current_value;
373 up(&i4cfgp.sem);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800374 return NSS_FAILURE;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700375 }
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700376
377 /*
378 * Blocking call, wait till we get ACK for this msg.
379 */
380 ret = wait_for_completion_timeout(&i4cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
381 if (ret == 0) {
382 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
383
384 /*
385 * Restore the current_value to its previous state
386 */
387 nss_ipv4_conn_cfg = i4cfgp.current_value;
388 up(&i4cfgp.sem);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800389 return NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700390 }
391
392 /*
393 * ACK/NACK received from NSS FW
394 * If ACK: Callback function will update nss_ipv4_conn_cfg with
395 * i4cfgp.num_conn_valid, which holds the user input
396 */
Vijay Dewangan488e5372014-12-29 21:40:11 -0800397 if (NSS_FAILURE == i4cfgp.response) {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700398
399 /*
400 * Restore the current_value to its previous state
401 */
402 nss_ipv4_conn_cfg = i4cfgp.current_value;
403 up(&i4cfgp.sem);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800404 return NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700405 }
406
407 up(&i4cfgp.sem);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800408 return NSS_SUCCESS;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700409}
410
411static ctl_table nss_ipv4_table[] = {
412 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700413 .procname = "ipv4_conn",
414 .data = &nss_ipv4_conn_cfg,
415 .maxlen = sizeof(int),
416 .mode = 0644,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700417 .proc_handler = &nss_ipv4_conn_cfg_handler,
418 },
419 { }
420};
421
422static ctl_table nss_ipv4_dir[] = {
423 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700424 .procname = "ipv4cfg",
425 .mode = 0555,
426 .child = nss_ipv4_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700427 },
428 { }
429};
430
431
432static ctl_table nss_ipv4_root_dir[] = {
433 {
434 .procname = "nss",
435 .mode = 0555,
436 .child = nss_ipv4_dir,
437 },
438 { }
439};
440
441static ctl_table nss_ipv4_root[] = {
442 {
443 .procname = "dev",
444 .mode = 0555,
445 .child = nss_ipv4_root_dir,
446 },
447 { }
448};
449
450static struct ctl_table_header *nss_ipv4_header;
451
452/*
453 * nss_ipv4_register_sysctl()
454 * Register sysctl specific to ipv4
455 */
456void nss_ipv4_register_sysctl(void)
457{
458 /*
459 * Register sysctl table.
460 */
461 nss_ipv4_header = register_sysctl_table(nss_ipv4_root);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700462 sema_init(&i4cfgp.sem, 1);
463 init_completion(&i4cfgp.complete);
464 i4cfgp.current_value = nss_ipv4_conn_cfg;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700465}
466
467/*
468 * nss_ipv4_unregister_sysctl()
469 * Unregister sysctl specific to ipv4
470 */
471void nss_ipv4_unregister_sysctl(void)
472{
473 /*
474 * Unregister sysctl table.
475 */
476 if (nss_ipv4_header) {
477 unregister_sysctl_table(nss_ipv4_header);
478 }
479}
480
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700481/*
482 * nss_ipv4_msg_init()
483 * Initialize IPv4 message.
484 */
485void nss_ipv4_msg_init(struct nss_ipv4_msg *nim, uint16_t if_num, uint32_t type, uint32_t len,
486 nss_ipv4_msg_callback_t *cb, void *app_data)
487{
488 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
489}
490
Thomas Wu68250352014-04-02 18:59:40 -0700491EXPORT_SYMBOL(nss_ipv4_tx);
492EXPORT_SYMBOL(nss_ipv4_notify_register);
493EXPORT_SYMBOL(nss_ipv4_notify_unregister);
494EXPORT_SYMBOL(nss_ipv4_get_mgr);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700495EXPORT_SYMBOL(nss_ipv4_register_sysctl);
496EXPORT_SYMBOL(nss_ipv4_unregister_sysctl);
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700497EXPORT_SYMBOL(nss_ipv4_msg_init);