blob: 1052de8539111499d2333adfa528176765ae09f0 [file] [log] [blame]
Thomas Wu68250352014-04-02 18:59:40 -07001/*
2 **************************************************************************
Sundarajan Srinivasanf1e57462014-09-17 15:24:01 -07003 * Copyright (c) 2013-2014, 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 <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 -070025int nss_ipv4_conn_cfg __read_mostly = NSS_DEFAULT_NUM_CONN;
26static struct nss_conn_cfg_pvt i4cfgp;
Vijay Dewangan9db18752014-09-15 16:25:01 -070027
Thomas Wu68250352014-04-02 18:59:40 -070028/*
Sol Kavy57d24b42014-04-05 13:45:36 -070029 * nss_ipv4_driver_conn_sync_update()
Thomas Wu68250352014-04-02 18:59:40 -070030 * Update driver specific information from the messsage.
31 */
Murat Sezgin0c0561d2014-04-09 18:55:58 -070032static 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 -070033{
Sol Kavy57d24b42014-04-05 13:45:36 -070034 struct nss_top_instance *nss_top = nss_ctx->nss_top;
35 struct net_device *pppoe_dev = NULL;
36
Thomas Wu68250352014-04-02 18:59:40 -070037 /*
38 * Update statistics maintained by NSS driver
39 */
40 spin_lock_bh(&nss_top->stats_lock);
Thomas Wu68250352014-04-02 18:59:40 -070041 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_PKTS] += nirs->flow_rx_packet_count + nirs->return_rx_packet_count;
42 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_BYTES] += nirs->flow_rx_byte_count + nirs->return_rx_byte_count;
43 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count;
44 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 -070045 spin_unlock_bh(&nss_top->stats_lock);
Sol Kavy57d24b42014-04-05 13:45:36 -070046
47 /*
48 * Update the PPPoE interface stats, if there is any PPPoE session on the interfaces.
49 */
50 if (nirs->flow_pppoe_session_id) {
51 pppoe_dev = ppp_session_to_netdev(nirs->flow_pppoe_session_id, (uint8_t *)nirs->flow_pppoe_remote_mac);
52 if (pppoe_dev) {
53 ppp_update_stats(pppoe_dev, nirs->flow_rx_packet_count, nirs->flow_rx_byte_count,
54 nirs->flow_tx_packet_count, nirs->flow_tx_byte_count);
55 dev_put(pppoe_dev);
56 }
57 }
58
59 if (nirs->return_pppoe_session_id) {
60 pppoe_dev = ppp_session_to_netdev(nirs->return_pppoe_session_id, (uint8_t *)nirs->return_pppoe_remote_mac);
61 if (pppoe_dev) {
62 ppp_update_stats(pppoe_dev, nirs->return_rx_packet_count, nirs->return_rx_byte_count,
63 nirs->return_tx_packet_count, nirs->return_tx_byte_count);
64 dev_put(pppoe_dev);
65 }
66 }
Thomas Wu68250352014-04-02 18:59:40 -070067}
Thomas Wu68250352014-04-02 18:59:40 -070068
69/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -070070 * nss_ipv4_driver_node_sync_update)
71 * Update driver specific information from the messsage.
72 */
73static void nss_ipv4_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_node_sync *nins)
74{
75 struct nss_top_instance *nss_top = nss_ctx->nss_top;
76 uint32_t i;
77
78 /*
79 * Update statistics maintained by NSS driver
80 */
81 spin_lock_bh(&nss_top->stats_lock);
82 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
83 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
84 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped;
85 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
86 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
87
Murat Sezgin0c0561d2014-04-09 18:55:58 -070088 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_REQUESTS] += nins->ipv4_connection_create_requests;
89 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_COLLISIONS] += nins->ipv4_connection_create_collisions;
90 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv4_connection_create_invalid_interface;
91 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_REQUESTS] += nins->ipv4_connection_destroy_requests;
92 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_MISSES] += nins->ipv4_connection_destroy_misses;
93 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_HITS] += nins->ipv4_connection_hash_hits;
94 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_REORDERS] += nins->ipv4_connection_hash_reorders;
95 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_FLUSHES] += nins->ipv4_connection_flushes;
96 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_EVICTIONS] += nins->ipv4_connection_evictions;
Selin Dag60ea2b22014-11-05 09:36:22 -080097 nss_top->stats_ipv4[NSS_STATS_IPV4_FRAGMENTATIONS] += nins->ipv4_fragmentations;
Murat Sezgin0c0561d2014-04-09 18:55:58 -070098
99 for (i = 0; i < NSS_EXCEPTION_EVENT_IPV4_MAX; i++) {
100 nss_top->stats_if_exception_ipv4[i] += nins->exception_events[i];
101 }
102 spin_unlock_bh(&nss_top->stats_lock);
103}
104
105/*
Sol Kavy2783c072014-04-05 12:53:13 -0700106 * nss_ipv4_rx_msg_handler()
Thomas Wu68250352014-04-02 18:59:40 -0700107 * Handle NSS -> HLOS messages for IPv4 bridge/route
108 */
Sol Kavy2783c072014-04-05 12:53:13 -0700109static 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 -0700110{
111 struct nss_ipv4_msg *nim = (struct nss_ipv4_msg *)ncm;
Sol Kavy57d24b42014-04-05 13:45:36 -0700112 nss_ipv4_msg_callback_t cb;
Thomas Wu68250352014-04-02 18:59:40 -0700113
114 BUG_ON(ncm->interface != NSS_IPV4_RX_INTERFACE);
115
116 /*
117 * Sanity check the message type
118 */
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700119 if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) {
Thomas Wu68250352014-04-02 18:59:40 -0700120 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
121 return;
122 }
123
124 if (ncm->len > sizeof(struct nss_ipv4_msg)) {
125 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
126 return;
127 }
128
Thomas Wu68250352014-04-02 18:59:40 -0700129 /*
Thomas Wu68250352014-04-02 18:59:40 -0700130 * Log failures
131 */
132 nss_core_log_msg_failures(nss_ctx, ncm);
133
Thomas Wu68250352014-04-02 18:59:40 -0700134 switch (nim->cm.type) {
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700135 case NSS_IPV4_RX_NODE_STATS_SYNC_MSG:
136 /*
137 * Update driver statistics on node sync.
138 */
139 nss_ipv4_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
140 break;
141
Thomas Wu68250352014-04-02 18:59:40 -0700142 case NSS_IPV4_RX_CONN_STATS_SYNC_MSG:
Sol Kavy57d24b42014-04-05 13:45:36 -0700143 /*
144 * Update driver statistics on connection sync.
145 */
146 nss_ipv4_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700147 break;
Thomas Wu68250352014-04-02 18:59:40 -0700148 }
149
150 /*
Sol Kavy57d24b42014-04-05 13:45:36 -0700151 * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
152 * to the same callback/app_data.
Thomas Wu68250352014-04-02 18:59:40 -0700153 */
Sol Kavy57d24b42014-04-05 13:45:36 -0700154 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
155 ncm->cb = (uint32_t)nss_ctx->nss_top->ipv4_callback;
156 ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv4_ctx;
157 }
Sol Kavy2783c072014-04-05 12:53:13 -0700158
Thomas Wu68250352014-04-02 18:59:40 -0700159 /*
160 * Do we have a callback?
161 */
162 if (!ncm->cb) {
163 return;
164 }
165
166 /*
167 * Callback
168 */
Sol Kavy57d24b42014-04-05 13:45:36 -0700169 cb = (nss_ipv4_msg_callback_t)ncm->cb;
Thomas Wu68250352014-04-02 18:59:40 -0700170 cb((void *)ncm->app_data, nim);
Thomas Wu68250352014-04-02 18:59:40 -0700171}
172
173/*
174 * nss_ipv4_tx()
175 * Transmit an ipv4 message to the FW.
176 */
177nss_tx_status_t nss_ipv4_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim)
178{
179 struct nss_ipv4_msg *nim2;
180 struct nss_cmn_msg *ncm = &nim->cm;
181 struct sk_buff *nbuf;
182 int32_t status;
183
184 NSS_VERIFY_CTX_MAGIC(nss_ctx);
185 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
186 nss_warning("%p: ipv4 msg dropped as core not ready", nss_ctx);
187 return NSS_TX_FAILURE_NOT_READY;
188 }
189
190 /*
191 * Sanity check the message
192 */
193 if (ncm->interface != NSS_IPV4_RX_INTERFACE) {
194 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
195 return NSS_TX_FAILURE;
196 }
197
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700198 if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) {
Thomas Wu68250352014-04-02 18:59:40 -0700199 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
200 return NSS_TX_FAILURE;
201 }
202
203 if (ncm->len > sizeof(struct nss_ipv4_msg)) {
204 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
205 return NSS_TX_FAILURE;
206 }
207
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530208 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
Thomas Wu68250352014-04-02 18:59:40 -0700209 if (unlikely(!nbuf)) {
210 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
211 nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
212 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
213 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
214 return NSS_TX_FAILURE;
215 }
216
217 /*
218 * Copy the message to our skb.
219 */
220 nim2 = (struct nss_ipv4_msg *)skb_put(nbuf, sizeof(struct nss_ipv4_msg));
221 memcpy(nim2, nim, sizeof(struct nss_ipv4_msg));
222
223 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
224 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530225 dev_kfree_skb_any(nbuf);
Sol Kavycd1bd5c2014-04-04 11:09:44 -0700226 nss_warning("%p: unable to enqueue IPv4 msg\n", nss_ctx);
Thomas Wu68250352014-04-02 18:59:40 -0700227 return NSS_TX_FAILURE;
228 }
229
230 nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
231 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
232
233 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
234 return NSS_TX_SUCCESS;
235}
236
237/*
238 **********************************
239 Register/Unregister/Miscellaneous APIs
240 **********************************
241 */
242
243/*
244 * nss_ipv4_notify_register()
245 * Register to received IPv4 events.
246 *
247 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
248 */
249struct nss_ctx_instance *nss_ipv4_notify_register(nss_ipv4_msg_callback_t cb, void *app_data)
250{
251 /*
252 * TODO: We need to have a new array in support of the new API
253 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
254 */
255 nss_top_main.ipv4_callback = cb;
Abhishek Rastogie11f47b2014-04-04 18:43:32 +0530256 nss_top_main.ipv4_ctx = app_data;
Thomas Wu68250352014-04-02 18:59:40 -0700257 return &nss_top_main.nss[nss_top_main.ipv4_handler_id];
258}
259
260/*
261 * nss_ipv4_notify_unregister()
262 * Unregister to received IPv4 events.
263 *
264 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
265 */
266void nss_ipv4_notify_unregister(void)
267{
268 nss_top_main.ipv4_callback = NULL;
269}
270
271/*
272 * nss_ipv4_get_mgr()
273 *
274 * TODO: This only suppports a single ipv4, do we ever want to support more?
275 */
276struct nss_ctx_instance *nss_ipv4_get_mgr(void)
277{
278 return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id];
279}
280
281/*
282 * nss_ipv4_register_handler()
283 * Register our handler to receive messages for this interface
284 */
Sol Kavy2783c072014-04-05 12:53:13 -0700285void nss_ipv4_register_handler(void)
Thomas Wu68250352014-04-02 18:59:40 -0700286{
Sol Kavy2783c072014-04-05 12:53:13 -0700287 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 -0700288 nss_warning("IPv4 handler failed to register");
289 }
290}
291
Vijay Dewangan9db18752014-09-15 16:25:01 -0700292/*
293 * nss_ipv4_conn_cfg_callback()
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700294 * call back function for the ipv4 connection configuration handler
Vijay Dewangan9db18752014-09-15 16:25:01 -0700295 */
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700296static void nss_ipv4_conn_cfg_callback(void *app_data, struct nss_ipv4_msg *nim)
Vijay Dewangan9db18752014-09-15 16:25:01 -0700297{
298
299 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
300 nss_warning("IPv4 connection configuration failed with error: %d\n", nim->cm.error);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700301 /*
302 * Error, hence we are not updating the nss_ipv4_conn_cfg
303 * Restore the current_value to its previous state
304 */
305 i4cfgp.response = FAILURE;
306 complete(&i4cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700307 return;
308 }
309
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700310 /*
311 * Sucess at NSS FW, hence updating nss_ipv4_conn_cfg, with the valid value
312 * saved at the sysctl handler.
313 */
Vijay Dewangan9db18752014-09-15 16:25:01 -0700314 nss_info("IPv4 connection configuration success: %d\n", nim->cm.error);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700315 i4cfgp.response = SUCCESS;
316 complete(&i4cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700317}
318
319/*
320 * nss_ipv4_conn_cfg_handler()
321 * Sets the number of connections for IPv4
322 */
323static int nss_ipv4_conn_cfg_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
324{
325 struct nss_top_instance *nss_top = &nss_top_main;
326 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
327 struct nss_ipv4_msg nim;
328 struct nss_ipv4_rule_conn_cfg_msg *nirccm;
329 nss_tx_status_t nss_tx_status;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700330 int ret = FAILURE;
331 uint32_t sum_of_conn;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700332
333 /*
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700334 * Acquiring semaphore
335 */
336 down(&i4cfgp.sem);
337
338 /*
339 * Take snap shot of current value
340 */
341 i4cfgp.current_value = nss_ipv4_conn_cfg;
342
343 /*
344 * Write the variable with user input
345 */
346 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
347 if (ret || (!write)) {
348 up(&i4cfgp.sem);
349 return ret;
350 }
351
352 /*
353 * The input should be multiple of 1024.
354 * Input for ipv4 and ipv6 sum together should not exceed 8k
355 * Min. value should be at least 256 connections. This is the
Vijay Dewangan9db18752014-09-15 16:25:01 -0700356 * minimum connections we will support for each of them.
357 */
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700358 sum_of_conn = nss_ipv4_conn_cfg + nss_ipv6_conn_cfg;
359 if ((nss_ipv4_conn_cfg & NSS_NUM_CONN_QUANTA_MASK) ||
360 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
361 (nss_ipv4_conn_cfg < NSS_MIN_NUM_CONN)) {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700362 nss_warning("%p: input supported connections (%d) does not adhere\
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700363 specifications\n1) not multiple of 1024,\n2) is less than \
Vijay Dewangan9db18752014-09-15 16:25:01 -0700364 min val: %d, OR\n IPv4/6 total exceeds %d\n",
365 nss_ctx,
366 nss_ipv4_conn_cfg,
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700367 NSS_MIN_NUM_CONN,
368 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
369
370 /*
371 * Restore the current_value to its previous state
372 */
373 nss_ipv4_conn_cfg = i4cfgp.current_value;
374 up(&i4cfgp.sem);
375 return FAILURE;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700376 }
377
Vijay Dewangan9db18752014-09-15 16:25:01 -0700378 nss_info("%p: IPv4 supported connections: %d\n", nss_ctx, nss_ipv4_conn_cfg);
379
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700380 nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_CONN_CFG_RULE_MSG,
381 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 -0700382
383 nirccm = &nim.msg.rule_conn_cfg;
384 nirccm->num_conn = htonl(nss_ipv4_conn_cfg);
385 nss_tx_status = nss_ipv4_tx(nss_ctx, &nim);
386
387 if (nss_tx_status != NSS_TX_SUCCESS) {
388 nss_warning("%p: nss_tx error setting IPv4 Connections: %d\n",
389 nss_ctx,
390 nss_ipv4_conn_cfg);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700391
392 /*
393 * Restore the current_value to its previous state
394 */
395 nss_ipv4_conn_cfg = i4cfgp.current_value;
396 up(&i4cfgp.sem);
397 return FAILURE;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700398 }
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700399
400 /*
401 * Blocking call, wait till we get ACK for this msg.
402 */
403 ret = wait_for_completion_timeout(&i4cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
404 if (ret == 0) {
405 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
406
407 /*
408 * Restore the current_value to its previous state
409 */
410 nss_ipv4_conn_cfg = i4cfgp.current_value;
411 up(&i4cfgp.sem);
412 return FAILURE;
413 }
414
415 /*
416 * ACK/NACK received from NSS FW
417 * If ACK: Callback function will update nss_ipv4_conn_cfg with
418 * i4cfgp.num_conn_valid, which holds the user input
419 */
420 if (FAILURE == i4cfgp.response) {
421
422 /*
423 * Restore the current_value to its previous state
424 */
425 nss_ipv4_conn_cfg = i4cfgp.current_value;
426 up(&i4cfgp.sem);
427 return FAILURE;
428 }
429
430 up(&i4cfgp.sem);
431 return SUCCESS;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700432}
433
434static ctl_table nss_ipv4_table[] = {
435 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700436 .procname = "ipv4_conn",
437 .data = &nss_ipv4_conn_cfg,
438 .maxlen = sizeof(int),
439 .mode = 0644,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700440 .proc_handler = &nss_ipv4_conn_cfg_handler,
441 },
442 { }
443};
444
445static ctl_table nss_ipv4_dir[] = {
446 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700447 .procname = "ipv4cfg",
448 .mode = 0555,
449 .child = nss_ipv4_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700450 },
451 { }
452};
453
454
455static ctl_table nss_ipv4_root_dir[] = {
456 {
457 .procname = "nss",
458 .mode = 0555,
459 .child = nss_ipv4_dir,
460 },
461 { }
462};
463
464static ctl_table nss_ipv4_root[] = {
465 {
466 .procname = "dev",
467 .mode = 0555,
468 .child = nss_ipv4_root_dir,
469 },
470 { }
471};
472
473static struct ctl_table_header *nss_ipv4_header;
474
475/*
476 * nss_ipv4_register_sysctl()
477 * Register sysctl specific to ipv4
478 */
479void nss_ipv4_register_sysctl(void)
480{
481 /*
482 * Register sysctl table.
483 */
484 nss_ipv4_header = register_sysctl_table(nss_ipv4_root);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700485 sema_init(&i4cfgp.sem, 1);
486 init_completion(&i4cfgp.complete);
487 i4cfgp.current_value = nss_ipv4_conn_cfg;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700488}
489
490/*
491 * nss_ipv4_unregister_sysctl()
492 * Unregister sysctl specific to ipv4
493 */
494void nss_ipv4_unregister_sysctl(void)
495{
496 /*
497 * Unregister sysctl table.
498 */
499 if (nss_ipv4_header) {
500 unregister_sysctl_table(nss_ipv4_header);
501 }
502}
503
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700504/*
505 * nss_ipv4_msg_init()
506 * Initialize IPv4 message.
507 */
508void nss_ipv4_msg_init(struct nss_ipv4_msg *nim, uint16_t if_num, uint32_t type, uint32_t len,
509 nss_ipv4_msg_callback_t *cb, void *app_data)
510{
511 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
512}
513
Thomas Wu68250352014-04-02 18:59:40 -0700514EXPORT_SYMBOL(nss_ipv4_tx);
515EXPORT_SYMBOL(nss_ipv4_notify_register);
516EXPORT_SYMBOL(nss_ipv4_notify_unregister);
517EXPORT_SYMBOL(nss_ipv4_get_mgr);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700518EXPORT_SYMBOL(nss_ipv4_register_sysctl);
519EXPORT_SYMBOL(nss_ipv4_unregister_sysctl);
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700520EXPORT_SYMBOL(nss_ipv4_msg_init);