blob: c7c3135285c2e7a1d59fe06a680d6461287dffdf [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 <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;
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080035#if (NSS_PPP_SUPPORT == 1)
Sol Kavy57d24b42014-04-05 13:45:36 -070036 struct net_device *pppoe_dev = NULL;
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080037#endif
Sol Kavy57d24b42014-04-05 13:45:36 -070038
Thomas Wu68250352014-04-02 18:59:40 -070039 /*
40 * Update statistics maintained by NSS driver
41 */
42 spin_lock_bh(&nss_top->stats_lock);
Thomas Wu68250352014-04-02 18:59:40 -070043 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_PKTS] += nirs->flow_rx_packet_count + nirs->return_rx_packet_count;
44 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_BYTES] += nirs->flow_rx_byte_count + nirs->return_rx_byte_count;
45 nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count;
46 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 -070047 spin_unlock_bh(&nss_top->stats_lock);
Sol Kavy57d24b42014-04-05 13:45:36 -070048
49 /*
50 * Update the PPPoE interface stats, if there is any PPPoE session on the interfaces.
51 */
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080052#if (NSS_PPP_SUPPORT == 1)
Sol Kavy57d24b42014-04-05 13:45:36 -070053 if (nirs->flow_pppoe_session_id) {
54 pppoe_dev = ppp_session_to_netdev(nirs->flow_pppoe_session_id, (uint8_t *)nirs->flow_pppoe_remote_mac);
55 if (pppoe_dev) {
56 ppp_update_stats(pppoe_dev, nirs->flow_rx_packet_count, nirs->flow_rx_byte_count,
57 nirs->flow_tx_packet_count, nirs->flow_tx_byte_count);
58 dev_put(pppoe_dev);
59 }
60 }
61
62 if (nirs->return_pppoe_session_id) {
63 pppoe_dev = ppp_session_to_netdev(nirs->return_pppoe_session_id, (uint8_t *)nirs->return_pppoe_remote_mac);
64 if (pppoe_dev) {
65 ppp_update_stats(pppoe_dev, nirs->return_rx_packet_count, nirs->return_rx_byte_count,
66 nirs->return_tx_packet_count, nirs->return_tx_byte_count);
67 dev_put(pppoe_dev);
68 }
69 }
Sundarajan Srinivasan4691ba62014-11-07 11:24:07 -080070#endif
Thomas Wu68250352014-04-02 18:59:40 -070071}
Thomas Wu68250352014-04-02 18:59:40 -070072
73/*
Murat Sezgin0c0561d2014-04-09 18:55:58 -070074 * nss_ipv4_driver_node_sync_update)
75 * Update driver specific information from the messsage.
76 */
77static void nss_ipv4_driver_node_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_node_sync *nins)
78{
79 struct nss_top_instance *nss_top = nss_ctx->nss_top;
80 uint32_t i;
81
82 /*
83 * Update statistics maintained by NSS driver
84 */
85 spin_lock_bh(&nss_top->stats_lock);
86 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_PKTS] += nins->node_stats.rx_packets;
87 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_BYTES] += nins->node_stats.rx_bytes;
88 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_RX_DROPPED] += nins->node_stats.rx_dropped;
89 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_PKTS] += nins->node_stats.tx_packets;
90 nss_top->stats_node[NSS_IPV4_RX_INTERFACE][NSS_STATS_NODE_TX_BYTES] += nins->node_stats.tx_bytes;
91
Murat Sezgin0c0561d2014-04-09 18:55:58 -070092 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_REQUESTS] += nins->ipv4_connection_create_requests;
93 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_COLLISIONS] += nins->ipv4_connection_create_collisions;
94 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_CREATE_INVALID_INTERFACE] += nins->ipv4_connection_create_invalid_interface;
95 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_REQUESTS] += nins->ipv4_connection_destroy_requests;
96 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_DESTROY_MISSES] += nins->ipv4_connection_destroy_misses;
97 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_HITS] += nins->ipv4_connection_hash_hits;
98 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_HASH_REORDERS] += nins->ipv4_connection_hash_reorders;
99 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_FLUSHES] += nins->ipv4_connection_flushes;
100 nss_top->stats_ipv4[NSS_STATS_IPV4_CONNECTION_EVICTIONS] += nins->ipv4_connection_evictions;
Selin Dag60ea2b22014-11-05 09:36:22 -0800101 nss_top->stats_ipv4[NSS_STATS_IPV4_FRAGMENTATIONS] += nins->ipv4_fragmentations;
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700102
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
Thomas Wu68250352014-04-02 18:59:40 -0700138 switch (nim->cm.type) {
Murat Sezgin0c0561d2014-04-09 18:55:58 -0700139 case NSS_IPV4_RX_NODE_STATS_SYNC_MSG:
140 /*
141 * Update driver statistics on node sync.
142 */
143 nss_ipv4_driver_node_sync_update(nss_ctx, &nim->msg.node_stats);
144 break;
145
Thomas Wu68250352014-04-02 18:59:40 -0700146 case NSS_IPV4_RX_CONN_STATS_SYNC_MSG:
Sol Kavy57d24b42014-04-05 13:45:36 -0700147 /*
148 * Update driver statistics on connection sync.
149 */
150 nss_ipv4_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
Sakthi Vignesh Radhakrishnan515f8c22014-06-21 15:04:19 -0700151 break;
Thomas Wu68250352014-04-02 18:59:40 -0700152 }
153
154 /*
Sol Kavy57d24b42014-04-05 13:45:36 -0700155 * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
156 * to the same callback/app_data.
Thomas Wu68250352014-04-02 18:59:40 -0700157 */
Sol Kavy57d24b42014-04-05 13:45:36 -0700158 if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
159 ncm->cb = (uint32_t)nss_ctx->nss_top->ipv4_callback;
160 ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv4_ctx;
161 }
Sol Kavy2783c072014-04-05 12:53:13 -0700162
Thomas Wu68250352014-04-02 18:59:40 -0700163 /*
164 * Do we have a callback?
165 */
166 if (!ncm->cb) {
167 return;
168 }
169
170 /*
171 * Callback
172 */
Sol Kavy57d24b42014-04-05 13:45:36 -0700173 cb = (nss_ipv4_msg_callback_t)ncm->cb;
Thomas Wu68250352014-04-02 18:59:40 -0700174 cb((void *)ncm->app_data, nim);
Thomas Wu68250352014-04-02 18:59:40 -0700175}
176
177/*
178 * nss_ipv4_tx()
179 * Transmit an ipv4 message to the FW.
180 */
181nss_tx_status_t nss_ipv4_tx(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_msg *nim)
182{
183 struct nss_ipv4_msg *nim2;
184 struct nss_cmn_msg *ncm = &nim->cm;
185 struct sk_buff *nbuf;
186 int32_t status;
187
188 NSS_VERIFY_CTX_MAGIC(nss_ctx);
189 if (unlikely(nss_ctx->state != NSS_CORE_STATE_INITIALIZED)) {
190 nss_warning("%p: ipv4 msg dropped as core not ready", nss_ctx);
191 return NSS_TX_FAILURE_NOT_READY;
192 }
193
194 /*
195 * Sanity check the message
196 */
197 if (ncm->interface != NSS_IPV4_RX_INTERFACE) {
198 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
199 return NSS_TX_FAILURE;
200 }
201
Murat Sezgin5c8c7362014-09-02 17:58:21 -0700202 if (ncm->type >= NSS_IPV4_MAX_MSG_TYPES) {
Thomas Wu68250352014-04-02 18:59:40 -0700203 nss_warning("%p: message type out of range: %d", nss_ctx, ncm->type);
204 return NSS_TX_FAILURE;
205 }
206
207 if (ncm->len > sizeof(struct nss_ipv4_msg)) {
208 nss_warning("%p: tx request for another interface: %d", nss_ctx, ncm->interface);
209 return NSS_TX_FAILURE;
210 }
211
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530212 nbuf = dev_alloc_skb(NSS_NBUF_PAYLOAD_SIZE);
Thomas Wu68250352014-04-02 18:59:40 -0700213 if (unlikely(!nbuf)) {
214 spin_lock_bh(&nss_ctx->nss_top->stats_lock);
215 nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_NBUF_ALLOC_FAILS]++;
216 spin_unlock_bh(&nss_ctx->nss_top->stats_lock);
217 nss_warning("%p: msg dropped as command allocation failed", nss_ctx);
218 return NSS_TX_FAILURE;
219 }
220
221 /*
222 * Copy the message to our skb.
223 */
224 nim2 = (struct nss_ipv4_msg *)skb_put(nbuf, sizeof(struct nss_ipv4_msg));
225 memcpy(nim2, nim, sizeof(struct nss_ipv4_msg));
226
227 status = nss_core_send_buffer(nss_ctx, 0, nbuf, NSS_IF_CMD_QUEUE, H2N_BUFFER_CTRL, 0);
228 if (status != NSS_CORE_STATUS_SUCCESS) {
Pamidipati, Vijayb6e38842014-09-16 10:26:05 +0530229 dev_kfree_skb_any(nbuf);
Sol Kavycd1bd5c2014-04-04 11:09:44 -0700230 nss_warning("%p: unable to enqueue IPv4 msg\n", nss_ctx);
Thomas Wu68250352014-04-02 18:59:40 -0700231 return NSS_TX_FAILURE;
232 }
233
234 nss_hal_send_interrupt(nss_ctx->nmap, nss_ctx->h2n_desc_rings[NSS_IF_CMD_QUEUE].desc_ring.int_bit,
235 NSS_REGS_H2N_INTR_STATUS_DATA_COMMAND_QUEUE);
236
237 NSS_PKT_STATS_INCREMENT(nss_ctx, &nss_ctx->nss_top->stats_drv[NSS_STATS_DRV_TX_CMD_REQ]);
238 return NSS_TX_SUCCESS;
239}
240
241/*
242 **********************************
243 Register/Unregister/Miscellaneous APIs
244 **********************************
245 */
246
247/*
248 * nss_ipv4_notify_register()
249 * Register to received IPv4 events.
250 *
251 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
252 */
253struct nss_ctx_instance *nss_ipv4_notify_register(nss_ipv4_msg_callback_t cb, void *app_data)
254{
255 /*
256 * TODO: We need to have a new array in support of the new API
257 * TODO: If we use a per-context array, we would move the array into nss_ctx based.
258 */
259 nss_top_main.ipv4_callback = cb;
Abhishek Rastogie11f47b2014-04-04 18:43:32 +0530260 nss_top_main.ipv4_ctx = app_data;
Thomas Wu68250352014-04-02 18:59:40 -0700261 return &nss_top_main.nss[nss_top_main.ipv4_handler_id];
262}
263
264/*
265 * nss_ipv4_notify_unregister()
266 * Unregister to received IPv4 events.
267 *
268 * NOTE: Do we want to pass an nss_ctx here so that we can register for ipv4 on any core?
269 */
270void nss_ipv4_notify_unregister(void)
271{
272 nss_top_main.ipv4_callback = NULL;
273}
274
275/*
276 * nss_ipv4_get_mgr()
277 *
278 * TODO: This only suppports a single ipv4, do we ever want to support more?
279 */
280struct nss_ctx_instance *nss_ipv4_get_mgr(void)
281{
282 return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id];
283}
284
285/*
286 * nss_ipv4_register_handler()
287 * Register our handler to receive messages for this interface
288 */
Sol Kavy2783c072014-04-05 12:53:13 -0700289void nss_ipv4_register_handler(void)
Thomas Wu68250352014-04-02 18:59:40 -0700290{
Sol Kavy2783c072014-04-05 12:53:13 -0700291 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 -0700292 nss_warning("IPv4 handler failed to register");
293 }
294}
295
Vijay Dewangan9db18752014-09-15 16:25:01 -0700296/*
297 * nss_ipv4_conn_cfg_callback()
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700298 * call back function for the ipv4 connection configuration handler
Vijay Dewangan9db18752014-09-15 16:25:01 -0700299 */
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700300static void nss_ipv4_conn_cfg_callback(void *app_data, struct nss_ipv4_msg *nim)
Vijay Dewangan9db18752014-09-15 16:25:01 -0700301{
302
303 if (nim->cm.response != NSS_CMN_RESPONSE_ACK) {
304 nss_warning("IPv4 connection configuration failed with error: %d\n", nim->cm.error);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700305 /*
306 * Error, hence we are not updating the nss_ipv4_conn_cfg
307 * Restore the current_value to its previous state
308 */
Vijay Dewangan488e5372014-12-29 21:40:11 -0800309 i4cfgp.response = NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700310 complete(&i4cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700311 return;
312 }
313
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700314 /*
315 * Sucess at NSS FW, hence updating nss_ipv4_conn_cfg, with the valid value
316 * saved at the sysctl handler.
317 */
Vijay Dewangan9db18752014-09-15 16:25:01 -0700318 nss_info("IPv4 connection configuration success: %d\n", nim->cm.error);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800319 i4cfgp.response = NSS_SUCCESS;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700320 complete(&i4cfgp.complete);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700321}
322
323/*
324 * nss_ipv4_conn_cfg_handler()
325 * Sets the number of connections for IPv4
326 */
327static int nss_ipv4_conn_cfg_handler(ctl_table *ctl, int write, void __user *buffer, size_t *lenp, loff_t *ppos)
328{
329 struct nss_top_instance *nss_top = &nss_top_main;
330 struct nss_ctx_instance *nss_ctx = &nss_top->nss[0];
331 struct nss_ipv4_msg nim;
332 struct nss_ipv4_rule_conn_cfg_msg *nirccm;
333 nss_tx_status_t nss_tx_status;
Vijay Dewangan488e5372014-12-29 21:40:11 -0800334 int ret = NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700335 uint32_t sum_of_conn;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700336
337 /*
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700338 * Acquiring semaphore
339 */
340 down(&i4cfgp.sem);
341
342 /*
343 * Take snap shot of current value
344 */
345 i4cfgp.current_value = nss_ipv4_conn_cfg;
346
347 /*
348 * Write the variable with user input
349 */
350 ret = proc_dointvec(ctl, write, buffer, lenp, ppos);
351 if (ret || (!write)) {
352 up(&i4cfgp.sem);
353 return ret;
354 }
355
356 /*
357 * The input should be multiple of 1024.
358 * Input for ipv4 and ipv6 sum together should not exceed 8k
359 * Min. value should be at least 256 connections. This is the
Vijay Dewangan9db18752014-09-15 16:25:01 -0700360 * minimum connections we will support for each of them.
361 */
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700362 sum_of_conn = nss_ipv4_conn_cfg + nss_ipv6_conn_cfg;
363 if ((nss_ipv4_conn_cfg & NSS_NUM_CONN_QUANTA_MASK) ||
364 (sum_of_conn > NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6) ||
365 (nss_ipv4_conn_cfg < NSS_MIN_NUM_CONN)) {
Vijay Dewangan9db18752014-09-15 16:25:01 -0700366 nss_warning("%p: input supported connections (%d) does not adhere\
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700367 specifications\n1) not multiple of 1024,\n2) is less than \
Vijay Dewangan9db18752014-09-15 16:25:01 -0700368 min val: %d, OR\n IPv4/6 total exceeds %d\n",
369 nss_ctx,
370 nss_ipv4_conn_cfg,
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700371 NSS_MIN_NUM_CONN,
372 NSS_MAX_TOTAL_NUM_CONN_IPV4_IPV6);
373
374 /*
375 * Restore the current_value to its previous state
376 */
377 nss_ipv4_conn_cfg = i4cfgp.current_value;
378 up(&i4cfgp.sem);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800379 return NSS_FAILURE;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700380 }
381
Vijay Dewangan9db18752014-09-15 16:25:01 -0700382 nss_info("%p: IPv4 supported connections: %d\n", nss_ctx, nss_ipv4_conn_cfg);
383
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700384 nss_ipv4_msg_init(&nim, NSS_IPV4_RX_INTERFACE, NSS_IPV4_TX_CONN_CFG_RULE_MSG,
385 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 -0700386
387 nirccm = &nim.msg.rule_conn_cfg;
388 nirccm->num_conn = htonl(nss_ipv4_conn_cfg);
389 nss_tx_status = nss_ipv4_tx(nss_ctx, &nim);
390
391 if (nss_tx_status != NSS_TX_SUCCESS) {
392 nss_warning("%p: nss_tx error setting IPv4 Connections: %d\n",
393 nss_ctx,
394 nss_ipv4_conn_cfg);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700395
396 /*
397 * Restore the current_value to its previous state
398 */
399 nss_ipv4_conn_cfg = i4cfgp.current_value;
400 up(&i4cfgp.sem);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800401 return NSS_FAILURE;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700402 }
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700403
404 /*
405 * Blocking call, wait till we get ACK for this msg.
406 */
407 ret = wait_for_completion_timeout(&i4cfgp.complete, msecs_to_jiffies(NSS_CONN_CFG_TIMEOUT));
408 if (ret == 0) {
409 nss_warning("%p: Waiting for ack timed out\n", nss_ctx);
410
411 /*
412 * Restore the current_value to its previous state
413 */
414 nss_ipv4_conn_cfg = i4cfgp.current_value;
415 up(&i4cfgp.sem);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800416 return NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700417 }
418
419 /*
420 * ACK/NACK received from NSS FW
421 * If ACK: Callback function will update nss_ipv4_conn_cfg with
422 * i4cfgp.num_conn_valid, which holds the user input
423 */
Vijay Dewangan488e5372014-12-29 21:40:11 -0800424 if (NSS_FAILURE == i4cfgp.response) {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700425
426 /*
427 * Restore the current_value to its previous state
428 */
429 nss_ipv4_conn_cfg = i4cfgp.current_value;
430 up(&i4cfgp.sem);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800431 return NSS_FAILURE;
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700432 }
433
434 up(&i4cfgp.sem);
Vijay Dewangan488e5372014-12-29 21:40:11 -0800435 return NSS_SUCCESS;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700436}
437
438static ctl_table nss_ipv4_table[] = {
439 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700440 .procname = "ipv4_conn",
441 .data = &nss_ipv4_conn_cfg,
442 .maxlen = sizeof(int),
443 .mode = 0644,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700444 .proc_handler = &nss_ipv4_conn_cfg_handler,
445 },
446 { }
447};
448
449static ctl_table nss_ipv4_dir[] = {
450 {
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700451 .procname = "ipv4cfg",
452 .mode = 0555,
453 .child = nss_ipv4_table,
Vijay Dewangan9db18752014-09-15 16:25:01 -0700454 },
455 { }
456};
457
458
459static ctl_table nss_ipv4_root_dir[] = {
460 {
461 .procname = "nss",
462 .mode = 0555,
463 .child = nss_ipv4_dir,
464 },
465 { }
466};
467
468static ctl_table nss_ipv4_root[] = {
469 {
470 .procname = "dev",
471 .mode = 0555,
472 .child = nss_ipv4_root_dir,
473 },
474 { }
475};
476
477static struct ctl_table_header *nss_ipv4_header;
478
479/*
480 * nss_ipv4_register_sysctl()
481 * Register sysctl specific to ipv4
482 */
483void nss_ipv4_register_sysctl(void)
484{
485 /*
486 * Register sysctl table.
487 */
488 nss_ipv4_header = register_sysctl_table(nss_ipv4_root);
Vijay Dewangan4861f4e2014-10-14 16:56:35 -0700489 sema_init(&i4cfgp.sem, 1);
490 init_completion(&i4cfgp.complete);
491 i4cfgp.current_value = nss_ipv4_conn_cfg;
Vijay Dewangan9db18752014-09-15 16:25:01 -0700492}
493
494/*
495 * nss_ipv4_unregister_sysctl()
496 * Unregister sysctl specific to ipv4
497 */
498void nss_ipv4_unregister_sysctl(void)
499{
500 /*
501 * Unregister sysctl table.
502 */
503 if (nss_ipv4_header) {
504 unregister_sysctl_table(nss_ipv4_header);
505 }
506}
507
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700508/*
509 * nss_ipv4_msg_init()
510 * Initialize IPv4 message.
511 */
512void nss_ipv4_msg_init(struct nss_ipv4_msg *nim, uint16_t if_num, uint32_t type, uint32_t len,
513 nss_ipv4_msg_callback_t *cb, void *app_data)
514{
515 nss_cmn_msg_init(&nim->cm, if_num, type, len, (void *)cb, app_data);
516}
517
Thomas Wu68250352014-04-02 18:59:40 -0700518EXPORT_SYMBOL(nss_ipv4_tx);
519EXPORT_SYMBOL(nss_ipv4_notify_register);
520EXPORT_SYMBOL(nss_ipv4_notify_unregister);
521EXPORT_SYMBOL(nss_ipv4_get_mgr);
Vijay Dewangan9db18752014-09-15 16:25:01 -0700522EXPORT_SYMBOL(nss_ipv4_register_sysctl);
523EXPORT_SYMBOL(nss_ipv4_unregister_sysctl);
Sundarajan Srinivasan02e6c2b2014-10-06 11:51:12 -0700524EXPORT_SYMBOL(nss_ipv4_msg_init);