Fix ipv4 old APIs so they co-exist with new APIs for the callback.

Change-Id: Id77423cdc6bd97eb2d158d3f369e7961d147da9a
Signed-off-by: Sol Kavy <skavy@codeaurora.org>
diff --git a/nss_ipv4.c b/nss_ipv4.c
index 7b8a09a..6c81bca 100755
--- a/nss_ipv4.c
+++ b/nss_ipv4.c
@@ -26,12 +26,16 @@
 extern void nss_rx_ipv4_sync(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync *nirs);
 
 /*
- * nss_ipv4_driver_update()
+ * nss_ipv4_driver_conn_sync_update()
  *	Update driver specific information from the messsage.
+ *
+ * TODO: export for now but once we remove old APIs, this can be made statis.
  */
-#if 0
-static void nss_ipv4_driver_conn_update(struct nss_ipv4_msg *nim)
+void nss_ipv4_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync *nirs)
 {
+	struct nss_top_instance *nss_top = nss_ctx->nss_top;
+	struct net_device *pppoe_dev = NULL;
+
 	/*
 	 * Update statistics maintained by NSS driver
 	 */
@@ -41,8 +45,28 @@
 	nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count;
 	nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_BYTES] += nirs->flow_tx_byte_count + nirs->return_tx_byte_count;
 	spin_unlock_bh(&nss_top->stats_lock);
+
+	/*
+	 * Update the PPPoE interface stats, if there is any PPPoE session on the interfaces.
+	 */
+	if (nirs->flow_pppoe_session_id) {
+		pppoe_dev = ppp_session_to_netdev(nirs->flow_pppoe_session_id, (uint8_t *)nirs->flow_pppoe_remote_mac);
+		if (pppoe_dev) {
+			ppp_update_stats(pppoe_dev, nirs->flow_rx_packet_count, nirs->flow_rx_byte_count,
+					nirs->flow_tx_packet_count, nirs->flow_tx_byte_count);
+			dev_put(pppoe_dev);
+		}
+	}
+
+	if (nirs->return_pppoe_session_id) {
+		pppoe_dev = ppp_session_to_netdev(nirs->return_pppoe_session_id, (uint8_t *)nirs->return_pppoe_remote_mac);
+		if (pppoe_dev) {
+			ppp_update_stats(pppoe_dev, nirs->return_rx_packet_count, nirs->return_rx_byte_count,
+					nirs->return_tx_packet_count, nirs->return_tx_byte_count);
+			dev_put(pppoe_dev);
+		}
+	}
 }
-#endif
 
 /*
  * nss_ipv4_rx_msg_handler()
@@ -51,10 +75,7 @@
 static void nss_ipv4_rx_msg_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
 {
 	struct nss_ipv4_msg *nim = (struct nss_ipv4_msg *)ncm;
-/*
- * TODO: Turn back on for new APIs
- */
-//	nss_ipv4_rx_msg_callback_t cb;
+	nss_ipv4_msg_callback_t cb;
 
 	BUG_ON(ncm->interface != NSS_IPV4_RX_INTERFACE);
 
@@ -72,15 +93,6 @@
 	}
 
 	/*
-	 * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
-	 * to the same callback/app_data.
-	 */
-	if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
-		ncm->cb = (uint32_t)nss_ctx->nss_top->ipv4_callback;
-		ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv4_ctx;
-	}
-
-	/*
 	 * Log failures
 	 */
 	nss_core_log_msg_failures(nss_ctx, ncm);
@@ -94,15 +106,22 @@
 		break;
 
 	case NSS_IPV4_RX_CONN_STATS_SYNC_MSG:
+		/*
+		 * Update driver statistics on connection sync.
+		 */
+		nss_ipv4_driver_conn_sync_update(nss_ctx, &nim->msg.conn_stats);
 		return nss_rx_ipv4_sync(nss_ctx, &nim->msg.conn_stats);
 		break;
 	}
 
-#if 0
 	/*
-	 * Local driver updates for ipv4.
+	 * Update the callback and app_data for NOTIFY messages, IPv4 sends all notify messages
+	 * to the same callback/app_data.
 	 */
-	nss_ipv4_driver_update(nim);
+	if (nim->cm.response == NSS_CMM_RESPONSE_NOTIFY) {
+		ncm->cb = (uint32_t)nss_ctx->nss_top->ipv4_callback;
+		ncm->app_data = (uint32_t)nss_ctx->nss_top->ipv4_ctx;
+	}
 
 	/*
 	 * Do we have a callback?
@@ -114,9 +133,8 @@
 	/*
 	 * Callback
 	 */
-	cb = (nss_ipv4_rx_msg_callback_t)ncm->cb;
+	cb = (nss_ipv4_msg_callback_t)ncm->cb;
 	cb((void *)ncm->app_data, nim);
-#endif
 }
 
 /*
diff --git a/nss_tx_rx_ipv4.c b/nss_tx_rx_ipv4.c
index a8fd7d4..0f777d1 100755
--- a/nss_tx_rx_ipv4.c
+++ b/nss_tx_rx_ipv4.c
@@ -25,14 +25,22 @@
 #include "nss_ipv4.h"
 
 /*
+ * Depreceated callback maintained locally.
+ */
+nss_ipv4_callback_t nss_tx_rx_ipv4_event_callback = NULL;
+
+/*
+ * TOOD: When we remove this backward compat layer, clean up nss_ipv4.c
+ */
+extern void nss_ipv4_driver_conn_sync_update(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync *nirs);
+
+/*
  * nss_rx_ipv4_sync()
- *	Deprecated - Handle the syncing of an IPv4 node.
+ *	Handle the syncing of an IPv4 node.
  */
 void nss_rx_ipv4_sync(struct nss_ctx_instance *nss_ctx, struct nss_ipv4_conn_sync *nirs)
 {
-	struct nss_top_instance *nss_top = nss_ctx->nss_top;
 	struct nss_ipv4_cb_params nicp;
-	struct net_device *pppoe_dev = NULL;
 
 	nicp.reason = NSS_IPV4_CB_REASON_SYNC;
 	nicp.params.sync.index = nirs->index;
@@ -100,49 +108,17 @@
 	/*
 	 * Call IPv4 manager callback function
 	 */
-	if (nss_ctx->nss_top->ipv4_callback) {
-		nss_ipv4_callback_t cb = (nss_ipv4_callback_t)nss_ctx->nss_top->ipv4_callback;
-		cb(&nicp);
-	} else {
+	if (!nss_tx_rx_ipv4_event_callback) {
 		nss_info("%p: IPV4 sync message received before connection manager has registered", nss_ctx);
+	} else {
+		nss_ipv4_callback_t cb = nss_tx_rx_ipv4_event_callback;
+		cb(&nicp);
 	}
 
 	/*
-	 * Update statistics maintained by NSS driver
+	 * Update local driver statistics
 	 */
-	spin_lock_bh(&nss_top->stats_lock);
-
-	nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_PKTS] += nirs->flow_rx_packet_count + nirs->return_rx_packet_count;
-	nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_RX_BYTES] += nirs->flow_rx_byte_count + nirs->return_rx_byte_count;
-	nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_PKTS] += nirs->flow_tx_packet_count + nirs->return_tx_packet_count;
-	nss_top->stats_ipv4[NSS_STATS_IPV4_ACCELERATED_TX_BYTES] += nirs->flow_tx_byte_count + nirs->return_tx_byte_count;
-
-	/*
-	 * Update the PPPoE interface stats, if there is any PPPoE session on the interfaces.
-	 */
-	if (nirs->flow_pppoe_session_id) {
-		pppoe_dev = ppp_session_to_netdev(nirs->flow_pppoe_session_id, (uint8_t *)nirs->flow_pppoe_remote_mac);
-		if (pppoe_dev) {
-			ppp_update_stats(pppoe_dev, nirs->flow_rx_packet_count, nirs->flow_rx_byte_count,
-					nirs->flow_tx_packet_count, nirs->flow_tx_byte_count);
-			dev_put(pppoe_dev);
-		}
-	}
-
-	if (nirs->return_pppoe_session_id) {
-		pppoe_dev = ppp_session_to_netdev(nirs->return_pppoe_session_id, (uint8_t *)nirs->return_pppoe_remote_mac);
-		if (pppoe_dev) {
-			ppp_update_stats(pppoe_dev, nirs->return_rx_packet_count, nirs->return_rx_byte_count,
-					nirs->return_tx_packet_count, nirs->return_tx_byte_count);
-			dev_put(pppoe_dev);
-		}
-	}
-
-	/*
-	 * TODO: Update per dev accelerated statistics
-	 */
-
-	spin_unlock_bh(&nss_top->stats_lock);
+	nss_ipv4_driver_conn_sync_update(nss_ctx, nirs);
 }
 
 /*
@@ -161,11 +137,11 @@
 	/*
 	 * Call IPv4 manager callback function
 	 */
-	if (!nss_ctx->nss_top->ipv4_callback) {
+	if (!nss_tx_rx_ipv4_event_callback) {
 		nss_info("%p: IPV4 establish message received before connection manager has registered", nss_ctx);
 		return;
 	}
-	cb = (nss_ipv4_callback_t)nss_ctx->nss_top->ipv4_callback;
+	cb = nss_tx_rx_ipv4_event_callback;
 	cb(&nicp);
 	nss_info("%p: Establish message - Index: %d\n", nss_ctx, nire->index);
 }
@@ -430,7 +406,8 @@
  */
 void *nss_register_ipv4_mgr(nss_ipv4_callback_t event_callback)
 {
-	return (void *)nss_ipv4_notify_register((nss_ipv4_msg_callback_t)event_callback, NULL);
+	nss_tx_rx_ipv4_event_callback = event_callback;
+	return (void *)&nss_top_main.nss[nss_top_main.ipv4_handler_id];
 }
 
 /*
@@ -438,7 +415,7 @@
  */
 void nss_unregister_ipv4_mgr(void)
 {
-	nss_ipv4_notify_unregister();
+	nss_tx_rx_ipv4_event_callback = NULL;
 }
 
 /*