blob: d7699d8e0bd9f529675acb5e07c03b3d8555c1f3 [file] [log] [blame]
Thomas Wu68250352014-04-02 18:59:40 -07001/*
2 **************************************************************************
3 * Copyright (c) 2013, The Linux Foundation. All rights reserved.
4 * 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 <linux/ppp_channel.h>
23#include "nss_tx_rx_common.h"
Thomas Wu68250352014-04-02 18:59:40 -070024
Vijay Dewangan4861f4e2014-10-14 16:56:35 -070025
Thomas Wu68250352014-04-02 18:59:40 -070026extern void nss_rx_metadata_ipv4_rule_establish(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_rule_establish *nire);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -070027extern void nss_rx_metadata_ipv4_create_response(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim);
Thomas Wu68250352014-04-02 18:59:40 -070028extern void nss_rx_ipv4_sync(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync *nirs);
29
Vijay Dewangan4861f4e2014-10-14 16:56:35 -070030int nss_ipv4_conn_cfg __read_mostly = NSS_DEFAULT_NUM_CONN;
31static struct nss_conn_cfg_pvt i4cfgp;
Vijay Dewangan9db18752014-09-15 16:25:01 -070032
Thomas Wu68250352014-04-02 18:59:40 -070033/*
Sol Kavy57d24b42014-04-05 13:45:36 -070034 * nss_ipv4_driver_conn_sync_update()
Thomas Wu68250352014-04-02 18:59:40 -070035 * Update driver specific information from the messsage.
36 */
Murat Sezgin0c0561d2014-04-09 18:55:58 -070037static 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 -070038{
Sol Kavy57d24b42014-04-05 13:45:36 -070039 struct nss_top_instance *nss_top = nss_ctx->nss_top;
40 struct net_device *pppoe_dev = NULL;
41
Thomas Wu68250352014-04-02 18:59:40 -070042 /*
43 * Update statistics maintained by NSS driver
44 */
45 spin_lock_bh(&nss_top->stats_lock);
Thomas Wu68250352014-04-02 18:59:40 -070046 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_PKTS] += nirs->flow_rx_packet_count + nirs->return_rx_packet_count;
47 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_BYTES] += nirs->flow_rx_byte_count + nirs->return_rx_byte_count;
48 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count;
49 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 -070050 spin_unlock_bh(&nss_top->stats_lock);
Sol Kavy57d24b42014-04-05 13:45:36 -070051
52 /*
53 * Update the PPPoE interface stats, if there is any PPPoE session on the interfaces.
54 */
55 if (nirs->flow_pppoe_session_id) {
56 pppoe_dev = ppp_session_to_netdev(nirs->flow_pppoe_session_id, (uint8_t *)nirs->flow_pppoe_remote_mac);
57 if (pppoe_dev) {
58 ppp_update_stats(pppoe_dev, nirs->flow_rx_packet_count, nirs->flow_rx_byte_count,
59 nirs->flow_tx_packet_count, nirs->flow_tx_byte_count);
60 dev_put(pppoe_dev);
61 }
62 }
63
64 if (nirs->return_pppoe_session_id) {
65 pppoe_dev = ppp_session_to_netdev(nirs->return_pppoe_session_id, (uint8_t *)nirs->return_pppoe_remote_mac);
66 if (pppoe_dev) {
67 ppp_update_stats(pppoe_dev, nirs->return_rx_packet_count, nirs->return_rx_byte_count,
68 nirs->return_tx_packet_count, nirs->return_tx_byte_count);
69 dev_put(pppoe_dev);
70 }
71 }
Thomas Wu68250352014-04-02 18:59:40 -070072}
Thomas Wu68250352014-04-02 18:59:40 -070073
74/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -070075 * nss_ipv4_driver_node_sync_update)
76 * Update driver specific information from the messsage.
77 */
78static void nss_ipv4_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_node_sync *nins)
79{
80 struct nss_top_instance *nss_top = nss_ctx->nss_top;
81 uint32_t i;
82
83 /*
84 * Update statistics maintained by NSS driver
85 */
86 spin_lock_bh(&nss_top->stats_lock);
87 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
88 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
89 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped;
90 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
91 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
92
Murat Sezgin0c0561d2014-04-09 18:55:58 -070093 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_REQUESTS] += nins->ipv4_connection_create_requests;
94 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_COLLISIONS] += nins->ipv4_connection_create_collisions;
95 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv4_connection_create_invalid_interface;
96 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_REQUESTS] += nins->ipv4_connection_destroy_requests;
97 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_MISSES] += nins->ipv4_connection_destroy_misses;
98 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_HITS] += nins->ipv4_connection_hash_hits;
99 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_REORDERS] += nins->ipv4_connection_hash_reorders;
100 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_FLUSHES] += nins->ipv4_connection_flushes;
101 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_EVICTIONS] += nins->ipv4_connection_evictions;
102
103 for (i = 0; i < NSS_EXCEPTION_EVENT_IPV4_MAX; i++) {
104 nss_top->stats_if_exception_ipv4[i] += nins->exception_events[i];
105 }
106 spin_unlock_bh(&nss_top->stats_lock);
107}
108
109/*
Sol Kavy2783c072014-04-05 12:53:13 -0700110 * nss_ipv4_rx_msg_handler()
Thomas Wu68250352014-04-02 18:59:40 -0700111 * Handle NSS -> HLOS messages for IPv4 bridge/route
112 */
Sol Kavy2783c072014-04-05 12:53:13 -0700113static 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 -0700114{
115 struct nss_ipv4_msg *nim = (struct nss_ipv4_msg *)ncm;
Sol Kavy57d24b42014-04-05 13:45:36 -0700116 nss_ipv4_msg_callback_t cb;
Thomas Wu68250352014-04-02 18:59:40 -0700117
118 BUG_ON(ncm->interface != NSS_IPV4_RX_INTERFACE);
119
120 /*
121 * Sanity check the message type
122 */
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700123 if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) {
Thomas Wu68250352014-04-02 18:59:40 -0700124 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
125 return;
126 }
127
128 if (ncm->len > sizeof(struct nss_ipv4_msg)) {
129 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
130 return;
131 }
132
Thomas Wu68250352014-04-02 18:59:40 -0700133 /*
Thomas Wu68250352014-04-02 18:59:40 -0700134 * Log failures
135 */
136 nss_core_log_msg_failures(nss_ctx, ncm);
137
138 /*
139 * Handle deprecated messages. Eventually these messages should be removed.
140 */
141 switch (nim->cm.type) {
142 case NSS_IPV4_RX_ESTABLISH_RULE_MSG:
143 return nss_rx_metadata_ipv4_rule_establish(nss_ctx, &nim->msg.rule_establish);
144 break;
145
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700146 case NSS_IPV4_RX_NODE_STATS_SYNC_MSG:
147 /*
148 * Update driver statistics on node sync.
149 */
150 nss_ipv4_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
151 break;
152
Thomas Wu68250352014-04-02 18:59:40 -0700153 case NSS_IPV4_RX_CONN_STATS_SYNC_MSG:
Sol Kavy57d24b42014-04-05 13:45:36 -0700154 /*
155 * Update driver statistics on connection sync.
156 */
157 nss_ipv4_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
Sol Kavy4013e282014-04-06 15:57:00 -0700158 nss_rx_ipv4_sync(nss_ctx, &nim->msg.conn_stats);
Thomas Wu68250352014-04-02 18:59:40 -0700159 break;
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700160
161 case NSS_IPV4_TX_CREATE_RULE_MSG:
162 nss_rx_metadata_ipv4_create_response(nss_ctx, nim);
163 break;
Thomas Wu68250352014-04-02 18:59:40 -0700164 }
165
166 /*
Sol Kavy57d24b42014-04-05 13:45:36 -0700167 * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
168 * to the same callback/app_data.
Thomas Wu68250352014-04-02 18:59:40 -0700169 */
Sol Kavy57d24b42014-04-05 13:45:36 -0700170 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
171 ncm->cb = (uint32_t)nss_ctx->nss_top->ipv4_callback;
172 ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv4_ctx;
173 }
Sol Kavy2783c072014-04-05 12:53:13 -0700174
Thomas Wu68250352014-04-02 18:59:40 -0700175 /*
176 * Do we have a callback?
177 */
178 if (!ncm->cb) {
179 return;
180 }
181
182 /*
183 * Callback
184 */
Sol Kavy57d24b42014-04-05 13:45:36 -0700185 cb = (nss_ipv4_msg_callback_t)ncm->cb;
Thomas Wu68250352014-04-02 18:59:40 -0700186 cb((void *)ncm->app_data, nim);
Thomas Wu68250352014-04-02 18:59:40 -0700187}
188
189/*
190 * nss_ipv4_tx()
191 * Transmit an ipv4 message to the FW.
192 */
193nss_tx_status_t nss_ipv4_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim)
194{
195 struct nss_ipv4_msg *nim2;
196 struct nss_cmn_msg *ncm = &nim->cm;
197 struct sk_buff *nbuf;
198 int32_t status;
199
200 NSS_VERIFY_CTX_MAGIC(nss_ctx);
201 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
202 nss_warning("%p: ipv4 msg dropped as core not ready", nss_ctx);
203 return NSS_TX_FAILURE_NOT_READY;
204 }
205
206 /*
207 * Sanity check the message
208 */
209 if (ncm->interface != NSS_IPV4_RX_INTERFACE) {
210 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
211 return NSS_TX_FAILURE;
212 }
213
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700214 if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) {
Thomas Wu68250352014-04-02 18:59:40 -0700215 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
216 return NSS_TX_FAILURE;
217 }
218
219 if (ncm->len > sizeof(struct nss_ipv4_msg)) {
220 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
221 return NSS_TX_FAILURE;
222 }
223
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530224 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
Thomas Wu68250352014-04-02 18:59:40 -0700225 if (unlikely(!nbuf)) {
226 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
227 nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
228 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
229 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
230 return NSS_TX_FAILURE;
231 }
232
233 /*
234 * Copy the message to our skb.
235 */
236 nim2 = (struct nss_ipv4_msg *)skb_put(nbuf, sizeof(struct nss_ipv4_msg));
237 memcpy(nim2, nim, sizeof(struct nss_ipv4_msg));
238
239 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
240 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530241 dev_kfree_skb_any(nbuf);
Sol Kavycd1bd5c2014-04-04 11:09:44 -0700242 nss_warning("%p: unable to enqueue IPv4 msg\n", nss_ctx);
Thomas Wu68250352014-04-02 18:59:40 -0700243 return NSS_TX_FAILURE;
244 }
245
246 nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
247 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
248
249 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
250 return NSS_TX_SUCCESS;
251}
252
253/*
254 **********************************
255 Register/Unregister/Miscellaneous APIs
256 **********************************
257 */
258
259/*
260 * nss_ipv4_notify_register()
261 * Register to received IPv4 events.
262 *
263 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
264 */
265struct nss_ctx_instance *nss_ipv4_notify_register(nss_ipv4_msg_callback_t cb, void *app_data)
266{
267 /*
268 * TODO: We need to have a new array in support of the new API
269 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
270 */
271 nss_top_main.ipv4_callback = cb;
Abhishek Rastogie11f47b2014-04-04 18:43:32 +0530272 nss_top_main.ipv4_ctx = app_data;
Thomas Wu68250352014-04-02 18:59:40 -0700273 return &nss_top_main.nss[nss_top_main.ipv4_handler_id];
274}
275
276/*
277 * nss_ipv4_notify_unregister()
278 * Unregister to received IPv4 events.
279 *
280 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
281 */
282void nss_ipv4_notify_unregister(void)
283{
284 nss_top_main.ipv4_callback = NULL;
285}
286
287/*
288 * nss_ipv4_get_mgr()
289 *
290 * TODO: This only suppports a single ipv4, do we ever want to support more?
291 */
292struct nss_ctx_instance *nss_ipv4_get_mgr(void)
293{
294 return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id];
295}
296
297/*
298 * nss_ipv4_register_handler()
299 * Register our handler to receive messages for this interface
300 */
Sol Kavy2783c072014-04-05 12:53:13 -0700301void nss_ipv4_register_handler(void)
Thomas Wu68250352014-04-02 18:59:40 -0700302{
Sol Kavy2783c072014-04-05 12:53:13 -0700303 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 -0700304 nss_warning("IPv4 handler failed to register");
305 }
306}
307
Vijay Dewangan9db18752014-09-15 16:25:01 -0700308/*
309 * nss_ipv4_conn_cfg_callback()
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700310 * call back function for the ipv4 connection configuration handler
Vijay Dewangan9db18752014-09-15 16:25:01 -0700311 */
312static void nss_ipv4_conn_cfg_callback(void *app_data, struct nss_if_msg *nim)
313{
314
315 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
316 nss_warning("IPv4 connection configuration failed with error: %d\n", nim->cm.error);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700317 /*
318 * Error, hence we are not updating the nss_ipv4_conn_cfg
319 * Restore the current_value to its previous state
320 */
321 i4cfgp.response = FAILURE;
322 complete(&i4cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700323 return;
324 }
325
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700326 /*
327 * Sucess at NSS FW, hence updating nss_ipv4_conn_cfg, with the valid value
328 * saved at the sysctl handler.
329 */
Vijay Dewangan9db18752014-09-15 16:25:01 -0700330 nss_info("IPv4 connection configuration success: %d\n", nim->cm.error);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700331 i4cfgp.response = SUCCESS;
332 complete(&i4cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700333}
334
335/*
336 * nss_ipv4_conn_cfg_handler()
337 * Sets the number of connections for IPv4
338 */
339static int nss_ipv4_conn_cfg_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
340{
341 struct nss_top_instance *nss_top = &nss_top_main;
342 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
343 struct nss_ipv4_msg nim;
344 struct nss_ipv4_rule_conn_cfg_msg *nirccm;
345 nss_tx_status_t nss_tx_status;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700346 int ret = FAILURE;
347 uint32_t sum_of_conn;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700348
349 /*
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700350 * Acquiring semaphore
351 */
352 down(&i4cfgp.sem);
353
354 /*
355 * Take snap shot of current value
356 */
357 i4cfgp.current_value = nss_ipv4_conn_cfg;
358
359 /*
360 * Write the variable with user input
361 */
362 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
363 if (ret || (!write)) {
364 up(&i4cfgp.sem);
365 return ret;
366 }
367
368 /*
369 * The input should be multiple of 1024.
370 * Input for ipv4 and ipv6 sum together should not exceed 8k
371 * Min. value should be at least 256 connections. This is the
Vijay Dewangan9db18752014-09-15 16:25:01 -0700372 * minimum connections we will support for each of them.
373 */
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700374 sum_of_conn = nss_ipv4_conn_cfg + nss_ipv6_conn_cfg;
375 if ((nss_ipv4_conn_cfg & NSS_NUM_CONN_QUANTA_MASK) ||
376 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
377 (nss_ipv4_conn_cfg < NSS_MIN_NUM_CONN)) {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700378 nss_warning("%p: input supported connections (%d) does not adhere\
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700379 specifications\n1) not multiple of 1024,\n2) is less than \
Vijay Dewangan9db18752014-09-15 16:25:01 -0700380 min val: %d, OR\n IPv4/6 total exceeds %d\n",
381 nss_ctx,
382 nss_ipv4_conn_cfg,
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700383 NSS_MIN_NUM_CONN,
384 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
385
386 /*
387 * Restore the current_value to its previous state
388 */
389 nss_ipv4_conn_cfg = i4cfgp.current_value;
390 up(&i4cfgp.sem);
391 return FAILURE;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700392 }
393
Vijay Dewangan9db18752014-09-15 16:25:01 -0700394 nss_info("%p: IPv4 supported connections: %d\n", nss_ctx, nss_ipv4_conn_cfg);
395
396 nss_cmn_msg_init(&nim.cm, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_CONN_CFG_RULE_MSG,
397 sizeof(struct nss_ipv4_rule_conn_cfg_msg), nss_ipv4_conn_cfg_callback, NULL);
398
399 nirccm = &nim.msg.rule_conn_cfg;
400 nirccm->num_conn = htonl(nss_ipv4_conn_cfg);
401 nss_tx_status = nss_ipv4_tx(nss_ctx, &nim);
402
403 if (nss_tx_status != NSS_TX_SUCCESS) {
404 nss_warning("%p: nss_tx error setting IPv4 Connections: %d\n",
405 nss_ctx,
406 nss_ipv4_conn_cfg);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700407
408 /*
409 * Restore the current_value to its previous state
410 */
411 nss_ipv4_conn_cfg = i4cfgp.current_value;
412 up(&i4cfgp.sem);
413 return FAILURE;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700414 }
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700415
416 /*
417 * Blocking call, wait till we get ACK for this msg.
418 */
419 ret = wait_for_completion_timeout(&i4cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
420 if (ret == 0) {
421 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
422
423 /*
424 * Restore the current_value to its previous state
425 */
426 nss_ipv4_conn_cfg = i4cfgp.current_value;
427 up(&i4cfgp.sem);
428 return FAILURE;
429 }
430
431 /*
432 * ACK/NACK received from NSS FW
433 * If ACK: Callback function will update nss_ipv4_conn_cfg with
434 * i4cfgp.num_conn_valid, which holds the user input
435 */
436 if (FAILURE == i4cfgp.response) {
437
438 /*
439 * Restore the current_value to its previous state
440 */
441 nss_ipv4_conn_cfg = i4cfgp.current_value;
442 up(&i4cfgp.sem);
443 return FAILURE;
444 }
445
446 up(&i4cfgp.sem);
447 return SUCCESS;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700448}
449
450static ctl_table nss_ipv4_table[] = {
451 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700452 .procname = "ipv4_conn",
453 .data = &nss_ipv4_conn_cfg,
454 .maxlen = sizeof(int),
455 .mode = 0644,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700456 .proc_handler = &nss_ipv4_conn_cfg_handler,
457 },
458 { }
459};
460
461static ctl_table nss_ipv4_dir[] = {
462 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700463 .procname = "ipv4cfg",
464 .mode = 0555,
465 .child = nss_ipv4_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700466 },
467 { }
468};
469
470
471static ctl_table nss_ipv4_root_dir[] = {
472 {
473 .procname = "nss",
474 .mode = 0555,
475 .child = nss_ipv4_dir,
476 },
477 { }
478};
479
480static ctl_table nss_ipv4_root[] = {
481 {
482 .procname = "dev",
483 .mode = 0555,
484 .child = nss_ipv4_root_dir,
485 },
486 { }
487};
488
489static struct ctl_table_header *nss_ipv4_header;
490
491/*
492 * nss_ipv4_register_sysctl()
493 * Register sysctl specific to ipv4
494 */
495void nss_ipv4_register_sysctl(void)
496{
497 /*
498 * Register sysctl table.
499 */
500 nss_ipv4_header = register_sysctl_table(nss_ipv4_root);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700501 sema_init(&i4cfgp.sem, 1);
502 init_completion(&i4cfgp.complete);
503 i4cfgp.current_value = nss_ipv4_conn_cfg;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700504}
505
506/*
507 * nss_ipv4_unregister_sysctl()
508 * Unregister sysctl specific to ipv4
509 */
510void nss_ipv4_unregister_sysctl(void)
511{
512 /*
513 * Unregister sysctl table.
514 */
515 if (nss_ipv4_header) {
516 unregister_sysctl_table(nss_ipv4_header);
517 }
518}
519
Thomas Wu68250352014-04-02 18:59:40 -0700520EXPORT_SYMBOL(nss_ipv4_tx);
521EXPORT_SYMBOL(nss_ipv4_notify_register);
522EXPORT_SYMBOL(nss_ipv4_notify_unregister);
523EXPORT_SYMBOL(nss_ipv4_get_mgr);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700524EXPORT_SYMBOL(nss_ipv4_register_sysctl);
525EXPORT_SYMBOL(nss_ipv4_unregister_sysctl);