[qca-nss-ecm] Renamed and moved the conntrack notifier into nss directory.

* This conntrack notifier is specific to the NSS front end. Each
  acceleration engine front end should implement its own conntrack
  notifier.

Change-Id: Iffacb2ba52f86e73404a549adff1f4c0558e5c82
Signed-off-by: Murat Sezgin <msezgin@codeaurora.org>
diff --git a/Makefile b/Makefile
index 78253bc..b7ab8a7 100755
--- a/Makefile
+++ b/Makefile
@@ -25,11 +25,12 @@
 	 ecm_tracker.o \
 	 frontends/ecm_front_end_ipv4.o \
 	 frontends/ecm_front_end_ipv6.o \
+	 frontends/ecm_front_end_common.o \
 	 frontends/nss/ecm_nss_ipv4.o \
 	 frontends/nss/ecm_nss_ported_ipv4.o \
 	 ecm_db.o \
 	 ecm_classifier_default.o \
-	 ecm_conntrack_notifier.o \
+	 frontends/nss/ecm_nss_conntrack_notifier.o \
 	 ecm_interface.o \
 	 ecm_init.o
 
@@ -195,6 +196,7 @@
 ccflags-y += -DECM_INIT_DEBUG_LEVEL=3
 ccflags-y += -DECM_FRONT_END_IPV4_DEBUG_LEVEL=1
 ccflags-y += -DECM_FRONT_END_IPV6_DEBUG_LEVEL=1
+ccflags-y += -DECM_FRONT_END_COMMON_DEBUG_LEVEL=1
 ccflags-y += -DECM_NSS_IPV4_DEBUG_LEVEL=1
 ccflags-y += -DECM_NSS_PORTED_IPV4_DEBUG_LEVEL=1
 ccflags-y += -DECM_NSS_NON_PORTED_IPV4_DEBUG_LEVEL=1
diff --git a/ecm_init.c b/ecm_init.c
index 373a3bc..5d7a927 100644
--- a/ecm_init.c
+++ b/ecm_init.c
@@ -43,6 +43,7 @@
 #ifdef ECM_IPV6_ENABLE
 #include "ecm_front_end_ipv6.h"
 #endif
+#include "ecm_front_end_common.h"
 
 struct dentry *ecm_dentry;	/* Dentry object for top level ecm debugfs directory */
 
@@ -72,10 +73,6 @@
 extern void ecm_bond_notifier_exit(void);
 #endif
 
-extern int ecm_conntrack_notifier_init(struct dentry *dentry);
-extern void ecm_conntrack_notifier_stop(int);
-extern void ecm_conntrack_notifier_exit(void);
-
 #ifdef ECM_CLASSIFIER_DSCP_ENABLE
 extern int ecm_classifier_dscp_init(struct dentry *dentry);
 extern void ecm_classifier_dscp_exit(void);
@@ -177,7 +174,7 @@
 	}
 #endif
 
-	ret = ecm_conntrack_notifier_init(ecm_dentry);
+	ret = ecm_front_end_conntrack_notifier_init(ecm_dentry);
 	if (0 != ret) {
 		goto err_ct;
 	}
@@ -194,7 +191,7 @@
 
 #ifdef ECM_STATE_OUTPUT_ENABLE
 err_state:
-	ecm_conntrack_notifier_exit();
+	ecm_front_end_conntrack_notifier_exit();
 #endif
 err_ct:
 #ifdef ECM_IPV6_ENABLE
@@ -255,7 +252,7 @@
 
 	/* call stop on anything that requires a prepare-to-exit signal */
 	DEBUG_INFO("stop conntrack notifier\n");
-	ecm_conntrack_notifier_stop(1);
+	ecm_front_end_conntrack_notifier_stop(1);
 	DEBUG_INFO("stop front_end_ipv4\n");
 	ecm_front_end_ipv4_stop(1);
 #ifdef ECM_IPV6_ENABLE
@@ -275,7 +272,7 @@
 	ecm_state_exit();
 #endif
 	DEBUG_INFO("exit conntrack notifier\n");
-	ecm_conntrack_notifier_exit();
+	ecm_front_end_conntrack_notifier_exit();
 	DEBUG_INFO("exit front_end_ipv4\n");
 	ecm_front_end_ipv4_exit();
 #ifdef ECM_IPV6_ENABLE
diff --git a/frontends/ecm_front_end_common.c b/frontends/ecm_front_end_common.c
new file mode 100644
index 0000000..7ded197
--- /dev/null
+++ b/frontends/ecm_front_end_common.c
@@ -0,0 +1,113 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2015 The Linux Foundation.  All rights reserved.
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************
+ */
+
+#include <linux/version.h>
+#include <linux/module.h>
+#include <linux/of.h>
+#include <linux/debugfs.h>
+#include <linux/inet.h>
+#include <linux/etherdevice.h>
+#include <net/netfilter/nf_conntrack.h>
+#include <net/ip.h>
+#include <net/ipv6.h>
+
+/*
+ * Debug output levels
+ * 0 = OFF
+ * 1 = ASSERTS / ERRORS
+ * 2 = 1 + WARN
+ * 3 = 2 + INFO
+ * 4 = 3 + TRACE
+ */
+#define DEBUG_LEVEL ECM_FRONT_END_COMMON_DEBUG_LEVEL
+
+#include <nss_api_if.h>
+
+#include "ecm_types.h"
+#include "ecm_db_types.h"
+#include "ecm_state.h"
+#include "ecm_tracker.h"
+#include "ecm_classifier.h"
+#include "ecm_front_end_types.h"
+#include "ecm_tracker_datagram.h"
+#include "ecm_tracker_udp.h"
+#include "ecm_tracker_tcp.h"
+#include "ecm_db.h"
+#include "ecm_nss_conntrack_notifier.h"
+
+/*
+ * ecm_front_end_conntrack_notifier_stop()
+ */
+void ecm_front_end_conntrack_notifier_stop(int num)
+{
+	/*
+	 * If the device tree is used, check which accel engine's conntrack notifier
+	 * will be stopped.
+	 * For ipq8064 platforms, we will stop NSS version.
+	 */
+#ifdef CONFIG_OF
+	/*
+	 * Check the other platforms and use the correct APIs for those platforms.
+	 */
+	if (!of_machine_is_compatible("qcom,ipq8064")) {
+		return;
+	}
+#endif
+	ecm_nss_conntrack_notifier_stop(num);
+}
+
+/*
+ * ecm_front_end_conntrack_notifier_init()
+ */
+int ecm_front_end_conntrack_notifier_init(struct dentry *dentry)
+{
+	/*
+	 * If the device tree is used, check which accel engine's conntrack notifier
+	 * can be used.
+	 * For ipq8064 platform, we will use NSS.
+	 */
+#ifdef CONFIG_OF
+	/*
+	 * Check the other platforms and use the correct APIs for those platforms.
+	 */
+	if (!of_machine_is_compatible("qcom,ipq8064")) {
+		return -1;
+	}
+#endif
+	return ecm_nss_conntrack_notifier_init(dentry);
+}
+
+/*
+ * ecm_front_end_conntrack_notifier_exit()
+ */
+void ecm_front_end_conntrack_notifier_exit(void)
+{
+	/*
+	 * If the device tree is used, check which accel engine's conntack notifier
+	 * will be exited.
+	 * For ipq8064 platforms, we will exit NSS.
+	 */
+#ifdef CONFIG_OF
+	/*
+	 * Check the other platforms and use the correct APIs for those platforms.
+	 */
+	if (!of_machine_is_compatible("qcom,ipq8064")) {
+		return;
+	}
+#endif
+	ecm_nss_conntrack_notifier_exit();
+}
+
diff --git a/frontends/include/ecm_front_end_common.h b/frontends/include/ecm_front_end_common.h
index 8ce3cef..ec9356b 100644
--- a/frontends/include/ecm_front_end_common.h
+++ b/frontends/include/ecm_front_end_common.h
@@ -14,8 +14,8 @@
  **************************************************************************
  */
 
-#ifndef _ECM_FRONT_END_COMMON_
-#define _ECM_FRONT_END_COMMON_
+#include <linux/if_pppox.h>
+#include "ecm_nss_conntrack_notifier.h"
 
 /*
  * ecm_front_end_l2_encap_header_len()
@@ -35,7 +35,7 @@
  * ecm_front_end_pull_l2_encap_header()
  *      Pull encapsulating L2 header
  */
-static void ecm_front_end_pull_l2_encap_header(struct sk_buff *skb, uint32_t len)
+static inline void ecm_front_end_pull_l2_encap_header(struct sk_buff *skb, uint32_t len)
 {
 	skb->data += len;
 	skb->network_header += len;
@@ -45,10 +45,12 @@
  * ecm_front_end_push_l2_encap_header()
  *      Push encapsulating L2 header
  */
-static void ecm_front_end_push_l2_encap_header(struct sk_buff *skb, uint32_t len)
+static inline void ecm_front_end_push_l2_encap_header(struct sk_buff *skb, uint32_t len)
 {
 	skb->data -= len;
 	skb->network_header -= len;
 }
 
-#endif
+extern void ecm_front_end_conntrack_notifier_stop(int num);
+extern int ecm_front_end_conntrack_notifier_init(struct dentry *dentry);
+extern void ecm_front_end_conntrack_notifier_exit(void);
diff --git a/ecm_conntrack_notifier.c b/frontends/nss/ecm_nss_conntrack_notifier.c
similarity index 67%
rename from ecm_conntrack_notifier.c
rename to frontends/nss/ecm_nss_conntrack_notifier.c
index 6014a0e..fcca942 100644
--- a/ecm_conntrack_notifier.c
+++ b/frontends/nss/ecm_nss_conntrack_notifier.c
@@ -15,7 +15,7 @@
  */
 
 /*
- * ecm_conntrack_notifier.c
+ * ecm_nss_conntrack_notifier.c
  * 	Conntrack notifier functionality.
  */
 
@@ -79,35 +79,35 @@
 #include "ecm_tracker_tcp.h"
 #include "ecm_tracker_datagram.h"
 #include "ecm_db.h"
-#include "ecm_front_end_ipv4.h"
+#include "ecm_nss_ipv4.h"
 #ifdef ECM_IPV6_ENABLE
-#include "ecm_front_end_ipv6.h"
+#include "ecm_nss_ipv6.h"
 #endif
 
 /*
  * Locking of the classifier - concurrency control
  */
-static DEFINE_SPINLOCK(ecm_conntrack_notifier_lock);				/* Protect against SMP access between netfilter, events and private threaded function. */
+static DEFINE_SPINLOCK(ecm_nss_conntrack_notifier_lock);				/* Protect against SMP access between netfilter, events and private threaded function. */
 
 /*
  * Debugfs dentry object.
  */
-static struct dentry *ecm_conntrack_notifier_dentry;
+static struct dentry *ecm_nss_conntrack_notifier_dentry;
 
 /*
  * General operational control
  */
-static int ecm_conntrack_notifier_stopped = 0;				/* When non-zero further traffic will not be processed */
+static int ecm_nss_conntrack_notifier_stopped = 0;				/* When non-zero further traffic will not be processed */
 
 #ifdef CONFIG_NF_CONNTRACK_EVENTS
 /*
- * ecm_conntrack_event()
+ * ecm_nss_conntrack_event()
  *	Callback event invoked when conntrack connection state changes, currently we handle destroy events to quickly release state
  */
 #ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
-static int ecm_conntrack_event(struct notifier_block *this, unsigned long events, void *ptr)
+static int ecm_nss_conntrack_event(struct notifier_block *this, unsigned long events, void *ptr)
 #else
-static int ecm_conntrack_event(unsigned int events, struct nf_ct_event *item)
+static int ecm_nss_conntrack_event(unsigned int events, struct nf_ct_event *item)
 #endif
 {
 #ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
@@ -118,13 +118,13 @@
 	/*
 	 * If operations have stopped then do not process event
 	 */
-	spin_lock_bh(&ecm_conntrack_notifier_lock);
-	if (unlikely(ecm_conntrack_notifier_stopped)) {
+	spin_lock_bh(&ecm_nss_conntrack_notifier_lock);
+	if (unlikely(ecm_nss_conntrack_notifier_stopped)) {
 		DEBUG_WARN("Ignoring event - stopped\n");
-		spin_unlock_bh(&ecm_conntrack_notifier_lock);
+		spin_unlock_bh(&ecm_nss_conntrack_notifier_lock);
 		return NOTIFY_DONE;
 	}
-	spin_unlock_bh(&ecm_conntrack_notifier_lock);
+	spin_unlock_bh(&ecm_nss_conntrack_notifier_lock);
 
 	if (!ct) {
 		DEBUG_WARN("Error: no ct\n");
@@ -155,50 +155,50 @@
 
 #ifdef CONFIG_NF_CONNTRACK_CHAIN_EVENTS
 /*
- * struct notifier_block ecm_conntrack_notifier
+ * struct notifier_block ecm_nss_conntrack_notifier
  *	Netfilter conntrack event system to monitor connection tracking changes
  */
-static struct notifier_block ecm_conntrack_notifier = {
-	.notifier_call	= ecm_conntrack_event,
+static struct notifier_block ecm_nss_conntrack_notifier = {
+	.notifier_call	= ecm_nss_conntrack_event,
 };
 #else
 /*
- * struct nf_ct_event_notifier ecm_conntrack_notifier
+ * struct nf_ct_event_notifier ecm_nss_conntrack_notifier
  *	Netfilter conntrack event system to monitor connection tracking changes
  */
-static struct nf_ct_event_notifier ecm_conntrack_notifier = {
-	.fcn	= ecm_conntrack_event,
+static struct nf_ct_event_notifier ecm_nss_conntrack_notifier = {
+	.fcn	= ecm_nss_conntrack_event,
 };
 #endif
 #endif
 
 /*
- * ecm_conntrack_notifier_stop()
+ * ecm_nss_conntrack_notifier_stop()
  */
-void ecm_conntrack_notifier_stop(int num)
+void ecm_nss_conntrack_notifier_stop(int num)
 {
-	ecm_conntrack_notifier_stopped = num;
+	ecm_nss_conntrack_notifier_stopped = num;
 }
-EXPORT_SYMBOL(ecm_conntrack_notifier_stop);
+EXPORT_SYMBOL(ecm_nss_conntrack_notifier_stop);
 
 /*
- * ecm_conntrack_notifier_init()
+ * ecm_nss_conntrack_notifier_init()
  */
-int ecm_conntrack_notifier_init(struct dentry *dentry)
+int ecm_nss_conntrack_notifier_init(struct dentry *dentry)
 {
 	int result;
 	DEBUG_INFO("ECM Conntrack Notifier init\n");
 
-	ecm_conntrack_notifier_dentry = debugfs_create_dir("ecm_conntrack_notifier", dentry);
-	if (!ecm_conntrack_notifier_dentry) {
+	ecm_nss_conntrack_notifier_dentry = debugfs_create_dir("ecm_nss_conntrack_notifier", dentry);
+	if (!ecm_nss_conntrack_notifier_dentry) {
 		DEBUG_ERROR("Failed to create ecm conntrack notifier directory in debugfs\n");
 		return -1;
 	}
 
-	if (!debugfs_create_u32("stop", S_IRUGO | S_IWUSR, ecm_conntrack_notifier_dentry,
-					(u32 *)&ecm_conntrack_notifier_stopped)) {
+	if (!debugfs_create_u32("stop", S_IRUGO | S_IWUSR, ecm_nss_conntrack_notifier_dentry,
+					(u32 *)&ecm_nss_conntrack_notifier_stopped)) {
 		DEBUG_ERROR("Failed to create ecm conntrack notifier stopped file in debugfs\n");
-		debugfs_remove_recursive(ecm_conntrack_notifier_dentry);
+		debugfs_remove_recursive(ecm_nss_conntrack_notifier_dentry);
 		return -1;
 	}
 
@@ -206,32 +206,32 @@
 	/*
 	 * Eventing subsystem is available so we register a notifier hook to get fast notifications of expired connections
 	 */
-	result = nf_conntrack_register_notifier(&init_net, &ecm_conntrack_notifier);
+	result = nf_conntrack_register_notifier(&init_net, &ecm_nss_conntrack_notifier);
 	if (result < 0) {
 		DEBUG_ERROR("Can't register nf notifier hook.\n");
-		debugfs_remove_recursive(ecm_conntrack_notifier_dentry);
+		debugfs_remove_recursive(ecm_nss_conntrack_notifier_dentry);
 		return result;
 	}
 #endif
 
 	return 0;
 }
-EXPORT_SYMBOL(ecm_conntrack_notifier_init);
+EXPORT_SYMBOL(ecm_nss_conntrack_notifier_init);
 
 /*
- * ecm_conntrack_notifier_exit()
+ * ecm_nss_conntrack_notifier_exit()
  */
-void ecm_conntrack_notifier_exit(void)
+void ecm_nss_conntrack_notifier_exit(void)
 {
 	DEBUG_INFO("ECM Conntrack Notifier exit\n");
 #ifdef CONFIG_NF_CONNTRACK_EVENTS
-	nf_conntrack_unregister_notifier(&init_net, &ecm_conntrack_notifier);
+	nf_conntrack_unregister_notifier(&init_net, &ecm_nss_conntrack_notifier);
 #endif
 	/*
 	 * Remove the debugfs files recursively.
 	 */
-	if (ecm_conntrack_notifier_dentry) {
-		debugfs_remove_recursive(ecm_conntrack_notifier_dentry);
+	if (ecm_nss_conntrack_notifier_dentry) {
+		debugfs_remove_recursive(ecm_nss_conntrack_notifier_dentry);
 	}
 }
-EXPORT_SYMBOL(ecm_conntrack_notifier_exit);
+EXPORT_SYMBOL(ecm_nss_conntrack_notifier_exit);
diff --git a/frontends/nss/ecm_nss_conntrack_notifier.h b/frontends/nss/ecm_nss_conntrack_notifier.h
new file mode 100644
index 0000000..da1fe83
--- /dev/null
+++ b/frontends/nss/ecm_nss_conntrack_notifier.h
@@ -0,0 +1,19 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2014-2015, The Linux Foundation. All rights reserved.
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all copies.
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+ * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ **************************************************************************
+ */
+
+extern void ecm_nss_conntrack_notifier_stop(int num);
+extern int ecm_nss_conntrack_notifier_init(struct dentry *dentry);
+extern void ecm_nss_conntrack_notifier_exit(void);