[qca-nss-drv] SJACK Logging

Change-Id: I2af98d7e47af9d6492e885426645decfce811ef2
Signed-off-by: Sachin Shashidhar <sshashid@codeaurora.org>
diff --git a/Makefile b/Makefile
index 9c0b291..fc1a531 100644
--- a/Makefile
+++ b/Makefile
@@ -86,6 +86,7 @@
 			nss_qrfs_stats.o \
 			nss_shaper.o \
 			nss_sjack.o \
+			nss_sjack_log.o \
 			nss_sjack_stats.o \
 			nss_stats.o \
 			nss_tstamp.o \
diff --git a/Makefile.fsm b/Makefile.fsm
index acf426b..8a209e1 100644
--- a/Makefile.fsm
+++ b/Makefile.fsm
@@ -74,6 +74,7 @@
 			nss_rps.o \
 			nss_shaper.o \
 			nss_sjack.o \
+			nss_sjack_log.o \
 			nss_sjack_stats.o \
 			nss_stats.o \
 			nss_tstamp.o \
diff --git a/nss_sjack.c b/nss_sjack.c
index d9ded99..f13685e 100644
--- a/nss_sjack.c
+++ b/nss_sjack.c
@@ -16,6 +16,7 @@
 
 #include "nss_tx_rx_common.h"
 #include "nss_sjack_stats.h"
+#include "nss_sjack_log.h"
 
 /*
  * nss_sjack_handler()
@@ -31,6 +32,11 @@
 	BUG_ON(ncm->interface != NSS_SJACK_INTERFACE);
 
 	/*
+	 * Trace Messages
+	 */
+	nss_sjack_log_rx_msg(nsm);
+
+	/*
 	 * Is this a valid request/response packet?
 	 */
 	if (ncm->type >=  NSS_SJACK_MAX_MSG_TYPE) {
@@ -90,6 +96,11 @@
 	struct nss_cmn_msg *ncm = &msg->cm;
 
 	/*
+	 * Trace Messages
+	 */
+	nss_sjack_log_tx_msg(msg);
+
+	/*
 	 * Sanity check the message
 	 */
 	if (ncm->interface != NSS_SJACK_INTERFACE) {
diff --git a/nss_sjack_log.c b/nss_sjack_log.c
new file mode 100644
index 0000000..166fce6
--- /dev/null
+++ b/nss_sjack_log.c
@@ -0,0 +1,133 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2018, 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_sjack_log.c
+ *	NSS SJACK logger file.
+ */
+
+#include "nss_core.h"
+
+/*
+ * nss_sjack_log_message_types_str
+ *	NSS SJACK message strings
+ */
+static int8_t *nss_sjack_log_message_types_str[NSS_SJACK_MAX_MSG_TYPE] __maybe_unused = {
+	"SJACK Configure",
+	"SJACK Unconfigure",
+	"SJACK Stats",
+};
+
+/*
+ * nss_sjack_log_configure_msg()
+ *	Log NSS SJACK Configure.
+ */
+static void nss_sjack_log_configure_msg(struct nss_sjack_msg *nsm)
+{
+	struct nss_sjack_configure_msg *nscm __maybe_unused = &nsm->msg.configure;
+	nss_trace("%p: NSS SJACK Configure message \n"
+		"SJACK Ingress Interface Number: %d\n"
+		"SJACK Engress Interface Number: %d\n"
+		"SJACK Tunnel ID: %d\n"
+		"SJACK DSCP Value: %d\n"
+		"SJACK GRE Priority: %d\n"
+		"SJACK GRE Flags: %d\n"
+		"SJACK IPSEC SA Pattern Flag: %d\n",
+		nscm, nscm->ingress_if_num,
+		nscm->egress_if_num, nscm->tunnel_id,
+		nscm->ip_dscp, nscm->gre_prio,
+		nscm->gre_flags, nscm->use_ipsec_sa_pattern);
+}
+
+/*
+ * nss_sjack_log_unconfigure_msg()
+ *	Log NSS SJACK Unconfigure.
+ */
+static void nss_sjack_log_unconfigure_msg(struct nss_sjack_msg *nsm)
+{
+	struct nss_sjack_unconfigure_msg *nsum __maybe_unused = &nsm->msg.unconfigure;
+	nss_trace("%p: NSS SJACK UnConfigure message \n"
+		"SJACK Ingress Interface Number: %d\n",
+		nsum, nsum->ingress_if_num);
+}
+
+/*
+ * nss_sjack_log_verbose()
+ *	Log message contents.
+ */
+static void nss_sjack_log_verbose(struct nss_sjack_msg *nsm)
+{
+	switch (nsm->cm.type) {
+	case NSS_SJACK_CONFIGURE_MSG:
+		nss_sjack_log_configure_msg(nsm);
+		break;
+
+	case NSS_SJACK_UNCONFIGURE_MSG:
+		nss_sjack_log_unconfigure_msg(nsm);
+		break;
+
+	case NSS_SJACK_STATS_SYNC_MSG:
+		/*
+		 * No log for valid stats message.
+		 */
+		break;
+
+	default:
+		nss_trace("%p: Invalid message type\n", nsm);
+		break;
+	}
+}
+
+/*
+ * nss_sjack_log_tx_msg()
+ *	Log messages transmitted to FW.
+ */
+void nss_sjack_log_tx_msg(struct nss_sjack_msg *nsm)
+{
+	if (nsm->cm.type >= NSS_SJACK_MAX_MSG_TYPE) {
+		nss_warning("%p: Invalid message type\n", nsm);
+		return;
+	}
+
+	nss_info("%p: type[%d]:%s\n", nsm, nsm->cm.type, nss_sjack_log_message_types_str[nsm->cm.type]);
+	nss_sjack_log_verbose(nsm);
+}
+
+/*
+ * nss_sjack_log_rx_msg()
+ *	Log messages received from FW.
+ */
+void nss_sjack_log_rx_msg(struct nss_sjack_msg *nsm)
+{
+	if (nsm->cm.response >= NSS_CMN_RESPONSE_LAST) {
+		nss_warning("%p: Invalid response\n", nsm);
+		return;
+	}
+
+	if (nsm->cm.response == NSS_CMN_RESPONSE_NOTIFY || (nsm->cm.response == NSS_CMN_RESPONSE_ACK)) {
+		nss_info("%p: type[%d]:%s, response[%d]:%s\n", nsm, nsm->cm.type,
+			nss_sjack_log_message_types_str[nsm->cm.type],
+			nsm->cm.response, nss_cmn_response_str[nsm->cm.response]);
+		goto verbose;
+	}
+
+	nss_info("%p: msg nack - type[%d]:%s, response[%d]:%s\n",
+		nsm, nsm->cm.type, nss_sjack_log_message_types_str[nsm->cm.type],
+		nsm->cm.response, nss_cmn_response_str[nsm->cm.response]);
+
+verbose:
+	nss_sjack_log_verbose(nsm);
+}
diff --git a/nss_sjack_log.h b/nss_sjack_log.h
new file mode 100644
index 0000000..56435a4
--- /dev/null
+++ b/nss_sjack_log.h
@@ -0,0 +1,41 @@
+/*
+ **************************************************************************
+ * Copyright (c) 2018, 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.
+ **************************************************************************
+ */
+
+#ifndef __NSS_SJACK_LOG_H
+#define __NSS_SJACK_LOG_H
+
+/*
+ * nss_sjack.h
+ *	NSS SJACK header file.
+ */
+
+/*
+ * Logger APIs
+ */
+
+/*
+ * nss_sjack_log_tx_msg
+ *	Logs a sjack message that is sent to the NSS firmware.
+ */
+void nss_sjack_log_tx_msg(struct nss_sjack_msg *nsm);
+
+/*
+ * nss_sjack_log_rx_msg
+ *	Logs a sjack message that is received from the NSS firmware.
+ */
+void nss_sjack_log_rx_msg(struct nss_sjack_msg *nsm);
+
+#endif /* __NSS_SJACK_LOG_H */