[qca-nss-drv] NSS PPE stats

Changes to enable various PPE stats through debugfs.
Currently there are 3 new files implemented under -
/sys/kernel/debug/qca-nss-drv/ppe/ for connection,
l3-debug and packet code related information.

Change-Id: I13e8e030be90402c7b4bd5551144a4ef788e0b64
Signed-off-by: Amit Gupta <amitgupt@codeaurora.org>
diff --git a/Makefile b/Makefile
index 489954c..71c9146 100644
--- a/Makefile
+++ b/Makefile
@@ -39,6 +39,7 @@
 			nss_phys_if.o \
 			nss_profiler.o \
 			nss_portid.o \
+			nss_ppe.o \
 			nss_pppoe.o \
 			nss_pptp.o \
 			nss_shaper.o \
diff --git a/exports/nss_api_if.h b/exports/nss_api_if.h
index 003b3e9..96437d1 100644
--- a/exports/nss_api_if.h
+++ b/exports/nss_api_if.h
@@ -66,6 +66,7 @@
 #include "nss_dtls.h"
 #include "nss_edma.h"
 #include "nss_bridge.h"
+#include "nss_ppe.h"
 
 /*
  * Interface numbers are reserved in the
diff --git a/exports/nss_ppe.h b/exports/nss_ppe.h
new file mode 100644
index 0000000..2605649
--- /dev/null
+++ b/exports/nss_ppe.h
@@ -0,0 +1,116 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2016, 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.
+ **************************************************************************
+ */
+
+/*
+ * nss_ppe.h
+ *	NSS TO HLOS interface definitions.
+ */
+#ifndef _NSS_PPE_H_
+#define _NSS_PPE_H_
+
+/**
+ *  request/response types
+ */
+enum nss_ppe_metadata_types {
+	NSS_PPE_MSG_SYNC_STATS,		/**< session stats sync message */
+	NSS_PPE_MSG_MAX,		/**< Max message type */
+};
+
+/**
+ * Message error types
+ */
+enum nss_ppe_msg_error_type {
+	PPE_MSG_ERROR_OK,			/**< No error */
+	PPE_MSG_ERROR_UNKNOWN_TYPE,		/**< Message is of unknown type */
+};
+
+/**
+ * ppe statistics sync message structure.
+ */
+struct nss_ppe_sync_stats_msg {
+	uint32_t nss_ppe_v4_l3_flows;		/**< No of v4 routed flows */
+	uint32_t nss_ppe_v4_l2_flows;		/**< No of v4 bridge flows */
+	uint32_t nss_ppe_v4_create_req;		/**< No of v4 create requests */
+	uint32_t nss_ppe_v4_create_fail;	/**< No of v4 create failure */
+	uint32_t nss_ppe_v4_destroy_req;	/**< No of v4 delete requests */
+	uint32_t nss_ppe_v4_destroy_fail;	/**< No of v4 delete failure */
+
+	uint32_t nss_ppe_v6_l3_flows;		/**< No of v6 routed flows */
+	uint32_t nss_ppe_v6_l2_flows;		/**< No of v6 bridge flows */
+	uint32_t nss_ppe_v6_create_req;		/**< No of v6 create requests */
+	uint32_t nss_ppe_v6_create_fail;	/**< No of v6 create failure */
+	uint32_t nss_ppe_v6_destroy_req;	/**< No of v6 delete requests */
+	uint32_t nss_ppe_v6_destroy_fail;	/**< No of v6 delete failure */
+
+	uint32_t nss_ppe_fail_nh_full;		/**< Create req fail due to nexthop table full */
+	uint32_t nss_ppe_fail_flow_full;	/**< Create req fail due to flow table full */
+	uint32_t nss_ppe_fail_host_full;	/**< Create req fail due to host table full */
+	uint32_t nss_ppe_fail_pubip_full;	/**< Create req fail due to pub-ip table full */
+	uint32_t nss_ppe_fail_port_setup;	/**< Create req fail due to PPE port not setup */
+	uint32_t nss_ppe_fail_rw_fifo_full;	/**< Create req fail due to rw fifo full */
+	uint32_t nss_ppe_fail_flow_command;	/**< Create req fail due to PPE flow command failure */
+	uint32_t nss_ppe_fail_unknown_proto;	/**< Create req fail due to unknown protocol */
+	uint32_t nss_ppe_fail_ppe_unresponsive;	/**< Create req fail due to PPE not responding */
+
+};
+
+/**
+ * Message structure for Host-NSS information exchange
+ */
+struct nss_ppe_msg {
+	struct nss_cmn_msg cm;
+	union {
+		struct nss_ppe_sync_stats_msg stats;
+	} msg;
+};
+
+/**
+ * @brief register ppe interface with nss.
+ *
+ * @param None
+ *
+ * @return None
+ */
+extern void nss_ppe_register_handler(void);
+
+/**
+ * @brief get ppe connection stats.
+ *
+ * @param memory address to be copied to
+ *
+ * @return None
+ */
+void nss_ppe_stats_conn_get(uint32_t *stats);
+
+/**
+ * @brief get ppe l3 debug stats.
+ *
+ * @param memory address to be copied to
+ *
+ * @return None
+ */
+void nss_ppe_stats_l3_get(uint32_t *stats);
+
+/**
+ * @brief get ppe packet code stats.
+ *
+ * @param memory address to be copied to
+ *
+ * @return None
+ */
+void nss_ppe_stats_code_get(uint32_t *stats);
+
+#endif /* _NSS_PPE_H_ */
diff --git a/nss_core.h b/nss_core.h
index c6de218..19b47d6 100644
--- a/nss_core.h
+++ b/nss_core.h
@@ -622,6 +622,61 @@
 };
 
 /*
+ * PPE stats
+ */
+enum nss_stats_ppe_conn {
+	NSS_STATS_PPE_V4_L3_FLOWS,		/* No of v4 routed flows */
+	NSS_STATS_PPE_V4_L2_FLOWS,		/* No of v4 bridge flows */
+	NSS_STATS_PPE_V4_CREATE_REQ,		/* No of v4 create requests */
+	NSS_STATS_PPE_V4_CREATE_FAIL,		/* No of v4 create failure */
+	NSS_STATS_PPE_V4_DESTROY_REQ,		/* No of v4 delete requests */
+	NSS_STATS_PPE_V4_DESTROY_FAIL,		/* No of v4 delete failure */
+
+	NSS_STATS_PPE_V6_L3_FLOWS,		/* No of v6 routed flows */
+	NSS_STATS_PPE_V6_L2_FLOWS,		/* No of v6 bridge flows */
+	NSS_STATS_PPE_V6_CREATE_REQ,		/* No of v6 create requests */
+	NSS_STATS_PPE_V6_CREATE_FAIL,		/* No of v6 create failure */
+	NSS_STATS_PPE_V6_DESTROY_REQ,		/* No of v6 delete requests */
+	NSS_STATS_PPE_V6_DESTROY_FAIL,		/* No of v6 delete failure */
+
+	NSS_STATS_PPE_FAIL_NH_FULL,		/* Create req fail due to nexthop table full */
+	NSS_STATS_PPE_FAIL_FLOW_FULL,		/* Create req fail due to flow table full */
+	NSS_STATS_PPE_FAIL_HOST_FULL,		/* Create req fail due to host table full */
+	NSS_STATS_PPE_FAIL_PUBIP_FULL,		/* Create req fail due to pub-ip table full */
+	NSS_STATS_PPE_FAIL_PORT_SETUP,		/* Create req fail due to PPE port not setup */
+	NSS_STATS_PPE_FAIL_RW_FIFO_FULL,	/* Create req fail due to rw fifo full */
+	NSS_STATS_PPE_FAIL_FLOW_COMMAND,	/* Create req fail due to PPE flow command failure */
+	NSS_STATS_PPE_FAIL_UNKNOWN_PROTO,	/* Create req fail due to unknown protocol */
+	NSS_STATS_PPE_FAIL_PPE_UNRESPONSIVE,	/* Create req fail due to PPE not responding */
+	NSS_STATS_PPE_CONN_MAX
+};
+
+enum nss_stats_ppe_l3 {
+	NSS_STATS_PPE_L3_DBG_0,		/* PPE L3 debug register 0 */
+	NSS_STATS_PPE_L3_DBG_1,		/* PPE L3 debug register 1 */
+	NSS_STATS_PPE_L3_DBG_2,		/* PPE L3 debug register 2 */
+	NSS_STATS_PPE_L3_DBG_3,		/* PPE L3 debug register 3 */
+	NSS_STATS_PPE_L3_DBG_4,		/* PPE L3 debug register 4 */
+	NSS_STATS_PPE_L3_DBG_PORT,	/* PPE L3 debug register Port */
+	NSS_STATS_PPE_L3_MAX
+};
+
+enum nss_stats_ppe_code {
+	NSS_STATS_PPE_CODE_CPU,		/* PPE CPU code for last packet processed */
+	NSS_STATS_PPE_CODE_DROP,	/* PPE DROP code for last packet processed */
+	NSS_STATS_PPE_CODE_MAX
+};
+
+struct nss_stats_ppe_debug {
+	uint32_t conn_stats[NSS_STATS_PPE_CONN_MAX];
+	uint32_t l3_stats[NSS_STATS_PPE_L3_MAX];
+	uint32_t code_stats[NSS_STATS_PPE_CODE_MAX];
+	int32_t if_index;
+	uint32_t if_num; /* nss interface number */
+	bool valid;
+};
+
+/*
  * MAP-T debug error types
  */
 enum nss_stats_map_t_instance {
@@ -881,6 +936,10 @@
 	struct dentry *gmac_dentry;		/* GMAC ethnode stats dentry */
 	struct dentry *capwap_decap_dentry;	/* CAPWAP decap ethnode stats dentry */
 	struct dentry *capwap_encap_dentry;	/* CAPWAP encap ethnode stats dentry */
+	struct dentry *ppe_dentry;	/* PPE root dentry */
+	struct dentry *ppe_conn_dentry;	/* PPE connection stats dentry */
+	struct dentry *ppe_l3_dentry;	/* PPE L3 debug stats dentry */
+	struct dentry *ppe_code_dentry;	/* PPE code stats dentry */
 	struct dentry *gre_redir_dentry;	/* gre_redir ethnode stats dentry */
 	struct dentry *sjack_dentry;		/* sjack stats dentry */
 	struct dentry *portid_dentry;		/* portid stats dentry */
@@ -909,6 +968,7 @@
 	uint8_t wlan_handler_id;
 	uint8_t tun6rd_handler_id;
 	uint8_t wifi_handler_id;
+	uint8_t ppe_handler_id;
 	uint8_t pptp_handler_id;
 	uint8_t l2tpv2_handler_id;
 	uint8_t dtls_handler_id;
@@ -1189,6 +1249,8 @@
 				/* Does this core handle map-t */
 	enum nss_feature_enabled oam_enabled;
 				/* Does this core handle oam? */
+	enum nss_feature_enabled ppe_enabled;
+				/* Does this core handle ppe ? */
 	enum nss_feature_enabled pppoe_enabled;
 				/* Does this core handle pppoe? */
 	enum nss_feature_enabled pptp_enabled;
@@ -1296,4 +1358,10 @@
 extern void nss_coredump_notify_register(void);
 extern void nss_fw_coredump_notify(struct nss_ctx_instance *nss_own, int intr);
 extern int nss_coredump_init_delay_work(void);
+
+/*
+ * APIs for PPE
+ */
+extern void nss_ppe_init(void);
+extern void nss_ppe_free(void);
 #endif /* __NSS_CORE_H */
diff --git a/nss_hal/nss_hal.c b/nss_hal/nss_hal.c
index db3ddc3..27507a2 100644
--- a/nss_hal/nss_hal.c
+++ b/nss_hal/nss_hal.c
@@ -111,6 +111,7 @@
 	npd->l2tpv2_enabled = of_property_read_bool(np, "qcom,l2tpv2-enabled");
 	npd->map_t_enabled = of_property_read_bool(np, "qcom,map-t-enabled");
 	npd->oam_enabled = of_property_read_bool(np, "qcom,oam-enabled");
+	npd->ppe_enabled = of_property_read_bool(np, "qcom,ppe-enabled");
 	npd->pppoe_enabled = of_property_read_bool(np, "qcom,pppoe-enabled");
 	npd->pptp_enabled = of_property_read_bool(np, "qcom,pptp-enabled");
 	npd->portid_enabled = of_property_read_bool(np, "qcom,portid-enabled");
@@ -418,6 +419,11 @@
 		nss_pptp_register_handler();
 	}
 
+	if (npd->ppe_enabled == NSS_FEATURE_ENABLED) {
+		nss_top->ppe_handler_id = nss_dev->id;
+		nss_ppe_register_handler();
+	}
+
 	if (npd->l2tpv2_enabled == NSS_FEATURE_ENABLED) {
 		nss_top->l2tpv2_handler_id = nss_dev->id;
 		nss_l2tpv2_register_handler();
diff --git a/nss_init.c b/nss_init.c
index 5bcbe2e..27d98d0 100644
--- a/nss_init.c
+++ b/nss_init.c
@@ -752,6 +752,13 @@
 	nss_capwap_init();
 
 	/*
+	 * INIT ppe on supported platform
+	 */
+	if (of_machine_is_compatible("qcom,ipq807x")) {
+		nss_ppe_init();
+	}
+
+	/*
 	 * Register platform_driver
 	 */
 	return platform_driver_register(&nss_driver);
@@ -781,6 +788,13 @@
 
 	nss_data_plane_destroy_delay_work();
 
+	/*
+	 * cleanup ppe on supported platform
+	 */
+	if (of_machine_is_compatible("qcom,ipq807x")) {
+		nss_ppe_free();
+	}
+
 	platform_driver_unregister(&nss_driver);
 }
 
diff --git a/nss_ppe.c b/nss_ppe.c
new file mode 100644
index 0000000..5c694cf
--- /dev/null
+++ b/nss_ppe.c
@@ -0,0 +1,262 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2016, 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 "nss_ppe.h"
+
+/*
+ * nss_ppe_verify_ifnum()
+ *	Verify PPE interface number.
+ */
+static inline bool nss_ppe_verify_ifnum(int if_num)
+{
+	return nss_is_dynamic_interface(if_num) || (if_num == NSS_PPE_INTERFACE);
+}
+
+/*
+ * nss_ppe_stats_sync
+ *	PPE connection sync stats from NSS
+ */
+static void nss_ppe_stats_sync(struct nss_ctx_instance *nss_ctx, struct nss_ppe_sync_stats_msg *stats_msg, uint16_t if_num)
+{
+	spin_lock_bh(&nss_ppe_stats_lock);
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_L3_FLOWS] += stats_msg->nss_ppe_v4_l3_flows;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_L2_FLOWS] += stats_msg->nss_ppe_v4_l2_flows;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_CREATE_REQ] += stats_msg->nss_ppe_v4_create_req;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_CREATE_FAIL] += stats_msg->nss_ppe_v4_create_fail;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_DESTROY_REQ] += stats_msg->nss_ppe_v4_destroy_req;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V4_DESTROY_FAIL] += stats_msg->nss_ppe_v4_destroy_fail;
+
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_L3_FLOWS] += stats_msg->nss_ppe_v6_l3_flows;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_L2_FLOWS] += stats_msg->nss_ppe_v6_l2_flows;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_CREATE_REQ] += stats_msg->nss_ppe_v6_create_req;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_CREATE_FAIL] += stats_msg->nss_ppe_v6_create_fail;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_DESTROY_REQ] += stats_msg->nss_ppe_v6_destroy_req;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_V6_DESTROY_FAIL] += stats_msg->nss_ppe_v6_destroy_fail;
+
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_NH_FULL] += stats_msg->nss_ppe_fail_nh_full;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_FLOW_FULL] += stats_msg->nss_ppe_fail_flow_full;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_HOST_FULL] += stats_msg->nss_ppe_fail_host_full;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_PUBIP_FULL] += stats_msg->nss_ppe_fail_pubip_full;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_PORT_SETUP] += stats_msg->nss_ppe_fail_port_setup;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_RW_FIFO_FULL] += stats_msg->nss_ppe_fail_rw_fifo_full;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_FLOW_COMMAND] += stats_msg->nss_ppe_fail_flow_command;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_UNKNOWN_PROTO] += stats_msg->nss_ppe_fail_unknown_proto;
+	nss_ppe_debug_stats.conn_stats[NSS_STATS_PPE_FAIL_PPE_UNRESPONSIVE] += stats_msg->nss_ppe_fail_ppe_unresponsive;
+	spin_unlock_bh(&nss_ppe_stats_lock);
+}
+
+/*
+ * nss_ppe_stats_conn_get()
+ *	Get ppe connection stats.
+ */
+void nss_ppe_stats_conn_get(uint32_t *stats)
+{
+	if (!stats) {
+		nss_warning("No memory to copy ppe connection stats");
+		return;
+	}
+
+	spin_lock_bh(&nss_ppe_stats_lock);
+
+	if (!nss_ppe_debug_stats.valid) {
+		spin_unlock_bh(&nss_ppe_stats_lock);
+		nss_warning("PPE base address not initialized!\n");
+		return;
+	}
+
+	/*
+	 * Get flow stats
+	 */
+	memcpy(stats, nss_ppe_debug_stats.conn_stats, (sizeof(uint32_t) * NSS_STATS_PPE_CONN_MAX));
+
+	spin_unlock_bh(&nss_ppe_stats_lock);
+}
+
+/*
+ * nss_ppe_stats_l3_get()
+ *	Get ppe L3 debug stats.
+ */
+void nss_ppe_stats_l3_get(uint32_t *stats)
+{
+	if (!stats) {
+		nss_warning("No memory to copy ppe l3 dbg stats\n");
+		return;
+	}
+
+	spin_lock_bh(&nss_ppe_stats_lock);
+
+	if (!nss_ppe_debug_stats.valid) {
+		spin_unlock_bh(&nss_ppe_stats_lock);
+		nss_warning("PPE base address not initialized!\n");
+		return;
+	}
+
+	nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG0_OFFSET);
+	nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_0]);
+
+	nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG1_OFFSET);
+	nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_1]);
+
+	nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG2_OFFSET);
+	nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_2]);
+
+	nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG3_OFFSET);
+	nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_3]);
+
+	nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG4_OFFSET);
+	nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_4]);
+
+	nss_ppe_reg_write(PPE_L3_DBG_WR_OFFSET, PPE_L3_DBG_PORT_OFFSET);
+	nss_ppe_reg_read(PPE_L3_DBG_RD_OFFSET, &stats[NSS_STATS_PPE_L3_DBG_PORT]);
+
+	spin_unlock_bh(&nss_ppe_stats_lock);
+}
+
+/*
+ * nss_ppe_stats_code_get()
+ *	Get ppe CPU and DROP code for last packet processed.
+ */
+void nss_ppe_stats_code_get(uint32_t *stats)
+{
+	uint32_t drop_0, drop_1, cpu_code;
+
+	nss_trace("%s(%d) Start\n", __func__, __LINE__);
+	if (!stats) {
+		nss_warning("No memory to copy ppe code\n");
+		return;
+	}
+
+	if (!nss_ppe_debug_stats.valid) {
+		nss_warning("PPE base address not initialized!\n");
+		return;
+	}
+
+	spin_lock_bh(&nss_ppe_stats_lock);
+	nss_ppe_reg_write(PPE_PKT_CODE_WR_OFFSET, PPE_PKT_CODE_DROP0_OFFSET);
+	nss_ppe_reg_read(PPE_PKT_CODE_RD_OFFSET, &drop_0);
+
+	nss_ppe_reg_write(PPE_PKT_CODE_WR_OFFSET, PPE_PKT_CODE_DROP1_OFFSET);
+	nss_ppe_reg_read(PPE_PKT_CODE_RD_OFFSET, &drop_1);
+
+	stats[NSS_STATS_PPE_CODE_DROP] = PPE_PKT_CODE_DROP_GET(drop_0, drop_1);
+
+	nss_ppe_reg_write(PPE_PKT_CODE_WR_OFFSET, PPE_PKT_CODE_CPU_OFFSET);
+	nss_ppe_reg_read(PPE_PKT_CODE_RD_OFFSET, &cpu_code);
+
+	stats[NSS_STATS_PPE_CODE_CPU] = PPE_PKT_CODE_CPU_GET(cpu_code);
+
+	spin_unlock_bh(&nss_ppe_stats_lock);
+}
+
+/*
+ * nss_ppe_handler()
+ *	Handle NSS -> HLOS messages for ppe tunnel
+ */
+static void nss_ppe_handler(struct nss_ctx_instance *nss_ctx, struct nss_cmn_msg *ncm, __attribute__((unused))void *app_data)
+{
+	struct nss_ppe_msg *msg = (struct nss_ppe_msg *)ncm;
+
+	nss_trace("nss_ctx: %p ppe msg: %p", nss_ctx, msg);
+	BUG_ON(!nss_ppe_verify_ifnum(ncm->interface));
+
+	/*
+	 * Is this a valid request/response packet?
+	 */
+	if (ncm->type >= NSS_PPE_MSG_MAX) {
+		nss_warning("%p: received invalid message %d for PPE interface", nss_ctx, ncm->type);
+		return;
+	}
+
+	if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_ppe_msg)) {
+		nss_warning("%p: Length of message is greater than required: %d", nss_ctx, nss_cmn_get_msg_len(ncm));
+		return;
+	}
+
+	switch (msg->cm.type) {
+	case NSS_PPE_MSG_SYNC_STATS:
+		/*
+		 * session debug stats embeded in session stats msg
+		 */
+		nss_ppe_stats_sync(nss_ctx, &msg->msg.stats, ncm->interface);
+		break;
+	}
+}
+
+/*
+ * nss_ppe_register_handler()
+ *	debugfs stats msg handler received on static ppe interface
+ *
+ *	TODO: Export API so that others can also read PPE stats.
+ */
+void nss_ppe_register_handler(void)
+{
+	nss_core_register_handler(NSS_PPE_INTERFACE, nss_ppe_handler, NULL);
+}
+
+/*
+ * nss_ppe_free()
+ *	Uninitialize PPE base
+ */
+void nss_ppe_free(void)
+{
+	/*
+	 * Check if PPE base is already uninitialized.
+	 */
+	if (!ppe_pvt.ppe_base) {
+		return;
+	}
+
+	/*
+	 * Unmap PPE base address
+	 */
+	iounmap(ppe_pvt.ppe_base);
+	ppe_pvt.ppe_base = NULL;
+
+	spin_lock_bh(&nss_ppe_stats_lock);
+	nss_ppe_debug_stats.valid = false;
+	nss_ppe_debug_stats.if_num = 0;
+	nss_ppe_debug_stats.if_index = 0;
+	spin_unlock_bh(&nss_ppe_stats_lock);
+}
+
+/*
+ * nss_ppe_init()
+ *	Initialize PPE base
+ */
+void nss_ppe_init(void)
+{
+	/*
+	 * Check if PPE base is already initialized.
+	 */
+	if (ppe_pvt.ppe_base) {
+		return;
+	}
+
+	/*
+	 * Get the PPE base address
+	 */
+	ppe_pvt.ppe_base = ioremap_nocache(PPE_BASE_ADDR, PPE_REG_SIZE);
+	if (!ppe_pvt.ppe_base) {
+		nss_warning("DRV can't get PPE base address\n");
+		return;
+	}
+
+	spin_lock_bh(&nss_ppe_stats_lock);
+	nss_ppe_debug_stats.valid = true;
+	nss_ppe_debug_stats.if_num = 0;
+	nss_ppe_debug_stats.if_index = 0;
+	spin_unlock_bh(&nss_ppe_stats_lock);
+}
diff --git a/nss_ppe.h b/nss_ppe.h
new file mode 100644
index 0000000..dd658f0
--- /dev/null
+++ b/nss_ppe.h
@@ -0,0 +1,77 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2016, 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.
+ **************************************************************************
+ */
+
+/*
+ * nss_ppe.h
+ *      NSS PPE header file
+ */
+
+#include <net/sock.h>
+#include "nss_tx_rx_common.h"
+
+#define PPE_BASE_ADDR			0x3a000000
+#define PPE_REG_SIZE			0x1000000
+
+#define PPE_L3_DBG_WR_OFFSET		0x200c04
+#define PPE_L3_DBG_RD_OFFSET		0x200c0c
+#define PPE_L3_DBG0_OFFSET		0x10001
+#define PPE_L3_DBG1_OFFSET		0x10002
+#define PPE_L3_DBG2_OFFSET		0x10003
+#define PPE_L3_DBG3_OFFSET		0x10004
+#define PPE_L3_DBG4_OFFSET		0x10005
+#define PPE_L3_DBG_PORT_OFFSET		0x11e80
+
+#define PPE_PKT_CODE_WR_OFFSET		0x100080
+#define PPE_PKT_CODE_RD_OFFSET		0x100084
+#define PPE_PKT_CODE_DROP0_OFFSET	0xf000000
+#define PPE_PKT_CODE_DROP1_OFFSET	0x10000000
+#define PPE_PKT_CODE_CPU_OFFSET		0x40000000
+
+#define PPE_PKT_CODE_DROP0_GET(x)	(((x) & 0xe0000000) >> 29)
+#define PPE_PKT_CODE_DROP1_GET(x)	(((x) & 0x7) << 3)
+#define PPE_PKT_CODE_DROP_GET(d0, d1)	(PPE_PKT_CODE_DROP0_GET(d0) + PPE_PKT_CODE_DROP1_GET(d1))
+
+#define PPE_PKT_CODE_CPU_GET(x)		(((x) >> 3) & 0xff)
+
+
+/*
+ * Data structures to store ppe nss debug stats
+ */
+static DEFINE_SPINLOCK(nss_ppe_stats_lock);
+static struct nss_stats_ppe_debug nss_ppe_debug_stats;
+
+/*
+ * Private data structure
+ */
+static struct nss_ppe_pvt {
+	void * __iomem ppe_base;
+} ppe_pvt;
+
+/*
+ * nss_ppe_reg_read()
+ */
+static inline void nss_ppe_reg_read(u32 reg, u32 *val)
+{
+	*val = readl((ppe_pvt.ppe_base + reg));
+}
+
+/*
+ * nss_ppe_reg_write()
+ */
+static inline void nss_ppe_reg_write(u32 reg, u32 val)
+{
+	writel(val, (ppe_pvt.ppe_base + reg));
+}
diff --git a/nss_stats.c b/nss_stats.c
index c772e87..edfe15f 100644
--- a/nss_stats.c
+++ b/nss_stats.c
@@ -625,6 +625,57 @@
 };
 
 /*
+ * nss_stats_str_ppe_conn
+ *	PPE statistics strings for nss flow stats
+ */
+static int8_t *nss_stats_str_ppe_conn[NSS_STATS_PPE_CONN_MAX] = {
+	"v4 routed flows",
+	"v4 bridge flows",
+	"v4 conn create req",
+	"v4 conn create fail",
+	"v4 conn destroy req",
+	"v4 conn destroy fail",
+
+	"v6 routed flows",
+	"v6 bridge flows",
+	"v6 conn create req",
+	"v6 conn create fail",
+	"v6 conn destroy req",
+	"v6 conn destroy fail",
+
+	"conn fail - nexthop full",
+	"conn fail - flow full",
+	"conn fail - host full",
+	"conn fail - pub-ip full",
+	"conn fail - port not setup",
+	"conn fail - rw fifo full",
+	"conn fail - unknown proto",
+	"conn fail - ppe not responding",
+};
+
+/*
+ * nss_stats_str_ppe_l3
+ *	PPE statistics strings for nss debug stats
+ */
+static int8_t *nss_stats_str_ppe_l3[NSS_STATS_PPE_L3_MAX] = {
+	"PPE L3 dbg reg 0",
+	"PPE L3 dbg reg 1",
+	"PPE L3 dbg reg 2",
+	"PPE L3 dbg reg 3",
+	"PPE L3 dbg reg 4",
+	"PPE L3 dbg reg port",
+};
+
+/*
+ * nss_stats_str_ppe_code
+ *	PPE statistics strings for nss debug stats
+ */
+static int8_t *nss_stats_str_ppe_code[NSS_STATS_PPE_CODE_MAX] = {
+	"PPE CPU_CODE",
+	"PPE DROP_CODE",
+};
+
+/*
  * nss_stats_str_ppt_session_stats
  *	PPTP statistics strings for nss session stats
  */
@@ -2171,6 +2222,157 @@
 }
 
 /*
+ * nss_stats_ppe_conn_read()
+ *	Read ppe connection stats
+ */
+static ssize_t nss_stats_ppe_conn_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
+{
+
+	int i;
+	char *lbuf = NULL;
+	size_t size_wr = 0;
+	ssize_t bytes_read = 0;
+	uint32_t ppe_stats[NSS_STATS_PPE_CONN_MAX];
+	uint32_t max_output_lines = 2 /* header & footer for session stats */
+				+ NSS_STATS_PPE_CONN_MAX /* PPE flow counters */
+				+ 2;
+	size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
+
+
+	lbuf = kzalloc(size_al, GFP_KERNEL);
+	if (unlikely(lbuf == NULL)) {
+		nss_warning("Could not allocate memory for local statistics buffer");
+		return 0;
+	}
+
+	memset(&ppe_stats, 0, sizeof(uint32_t) * NSS_STATS_PPE_CONN_MAX);
+
+	/*
+	 * Get all stats
+	 */
+	nss_ppe_stats_conn_get(ppe_stats);
+
+	/*
+	 * flow stats
+	 */
+	size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nppe flow counters start:\n\n");
+
+	for (i = 0; i < NSS_STATS_PPE_CONN_MAX; i++) {
+		size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
+				"\t%s = %u\n", nss_stats_str_ppe_conn[i],
+				ppe_stats[i]);
+	}
+
+	size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
+
+	size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nppe flow counters end\n");
+	bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, size_wr);
+
+	kfree(lbuf);
+	return bytes_read;
+}
+
+/*
+ * nss_stats_ppe_l3_read()
+ *	Read ppe L3 debug stats
+ */
+static ssize_t nss_stats_ppe_l3_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
+{
+
+	int i;
+	char *lbuf = NULL;
+	size_t size_wr = 0;
+	ssize_t bytes_read = 0;
+	uint32_t ppe_stats[NSS_STATS_PPE_L3_MAX];
+	uint32_t max_output_lines = 2 /* header & footer for session stats */
+				+ NSS_STATS_PPE_L3_MAX /* PPE flow counters */
+				+ 2;
+	size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
+
+	lbuf = kzalloc(size_al, GFP_KERNEL);
+	if (unlikely(!lbuf)) {
+		nss_warning("Could not allocate memory for local statistics buffer");
+		return 0;
+	}
+
+	memset(ppe_stats, 0, sizeof(uint32_t) * NSS_STATS_PPE_L3_MAX);
+
+	/*
+	 * Get all stats
+	 */
+	nss_ppe_stats_l3_get(ppe_stats);
+
+	/*
+	 * flow stats
+	 */
+	size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nppe l3 debug stats start:\n\n");
+
+	for (i = 0; i < NSS_STATS_PPE_L3_MAX; i++) {
+		size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
+				"\t%s = 0x%x\n", nss_stats_str_ppe_l3[i],
+				ppe_stats[i]);
+	}
+
+	size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
+
+	size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nppe l3 debug stats end\n");
+	bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, size_wr);
+
+	kfree(lbuf);
+	return bytes_read;
+}
+
+/*
+ * nss_stats_ppe_code_read()
+ *	Read ppe CPU & DROP code
+ */
+static ssize_t nss_stats_ppe_code_read(struct file *fp, char __user *ubuf, size_t sz, loff_t *ppos)
+{
+
+	int i;
+	char *lbuf = NULL;
+	size_t size_wr = 0;
+	ssize_t bytes_read = 0;
+	uint32_t ppe_stats[NSS_STATS_PPE_CODE_MAX];
+	uint32_t max_output_lines = 2 /* header & footer for session stats */
+				+ NSS_STATS_PPE_CODE_MAX /* PPE flow counters */
+				+ 2;
+	size_t size_al = NSS_STATS_MAX_STR_LENGTH * max_output_lines;
+
+	lbuf = kzalloc(size_al, GFP_KERNEL);
+	if (unlikely(!lbuf)) {
+		nss_warning("Could not allocate memory for local statistics buffer");
+		return 0;
+	}
+
+	memset(ppe_stats, 0, sizeof(uint32_t) * NSS_STATS_PPE_CODE_MAX);
+
+	/*
+	 * Get all stats
+	 */
+	nss_ppe_stats_code_get(ppe_stats);
+
+	/*
+	 * flow stats
+	 */
+	size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nppe session stats start:\n\n");
+
+	for (i = 0; i < NSS_STATS_PPE_CODE_MAX; i++) {
+		size_wr += scnprintf(lbuf + size_wr, size_al - size_wr,
+				"\t%s = %u\n", nss_stats_str_ppe_code[i],
+				ppe_stats[i]);
+	}
+
+	size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\n");
+
+	size_wr += scnprintf(lbuf + size_wr, size_al - size_wr, "\nppe session stats end\n");
+	bytes_read = simple_read_from_buffer(ubuf, sz, ppos, lbuf, size_wr);
+
+	kfree(lbuf);
+	return bytes_read;
+}
+
+/*
  * nss_stats_pptp_read()
  *	Read pptp statistics
  */
@@ -3032,6 +3234,13 @@
 NSS_STATS_DECLARE_FILE_OPERATIONS(map_t)
 
 /*
+ * ppe_stats_ops
+ */
+NSS_STATS_DECLARE_FILE_OPERATIONS(ppe_conn)
+NSS_STATS_DECLARE_FILE_OPERATIONS(ppe_l3)
+NSS_STATS_DECLARE_FILE_OPERATIONS(ppe_code)
+
+/*
  * pptp_stats_ops
  */
 NSS_STATS_DECLARE_FILE_OPERATIONS(pptp)
@@ -3520,6 +3729,33 @@
 	}
 
 	/*
+	 *  PPE Stats
+	 */
+	nss_top_main.ppe_dentry = debugfs_create_dir("ppe", nss_top_main.stats_dentry);
+	if (unlikely(nss_top_main.ppe_dentry == NULL)) {
+		nss_warning("Failed to create qca-nss-drv directory in debugfs");
+		return;
+	}
+
+	nss_top_main.ppe_conn_dentry = debugfs_create_file("connection", 0400,
+						nss_top_main.ppe_dentry, &nss_top_main, &nss_stats_ppe_conn_ops);
+	if (unlikely(nss_top_main.ppe_dentry == NULL)) {
+		nss_warning("Failed to create qca-nss-drv/stats/ppe/connection file in debugfs");
+	}
+
+	nss_top_main.ppe_l3_dentry = debugfs_create_file("l3", 0400,
+						nss_top_main.ppe_dentry, &nss_top_main, &nss_stats_ppe_l3_ops);
+	if (unlikely(nss_top_main.ppe_dentry == NULL)) {
+		nss_warning("Failed to create qca-nss-drv/stats/ppe/l3 file in debugfs");
+	}
+
+	nss_top_main.ppe_l3_dentry = debugfs_create_file("ppe_code", 0400,
+						nss_top_main.ppe_dentry, &nss_top_main, &nss_stats_ppe_code_ops);
+	if (unlikely(nss_top_main.ppe_dentry == NULL)) {
+		nss_warning("Failed to create qca-nss-drv/stats/ppe/ppe_code file in debugfs");
+	}
+
+	/*
 	 *  PPTP Stats
 	 */
 	nss_top_main.pptp_dentry = debugfs_create_file("pptp", 0400,