Merge "[qca-nss-drv] OAM Logging"
diff --git a/Makefile b/Makefile
index 4987c21..441ceb9 100644
--- a/Makefile
+++ b/Makefile
@@ -64,6 +64,7 @@
 			nss_n2h.o \
 			nss_n2h_stats.o \
 			nss_oam.o \
+			nss_oam_log.o \
 			nss_phys_if.o \
 			nss_pm.o \
 			nss_profiler.o \
diff --git a/Makefile.fsm b/Makefile.fsm
index 1874c74..4077293 100644
--- a/Makefile.fsm
+++ b/Makefile.fsm
@@ -55,6 +55,7 @@
 			nss_n2h.o \
 			nss_n2h_stats.o \
 			nss_oam.o \
+			nss_oam_log.o \
 			nss_phys_if.o \
 			nss_pm.o \
 			nss_profiler.o \
diff --git a/nss_oam.c b/nss_oam.c
index 1e31c1b..ce77e89 100644
--- a/nss_oam.c
+++ b/nss_oam.c
@@ -25,6 +25,7 @@
  */
 
 #include "nss_tx_rx_common.h"
+#include "nss_oam_log.h"
 
 /*
  * nss_oam_rx_msg_handler()
@@ -36,6 +37,11 @@
 	nss_oam_msg_callback_t cb;
 
 	/*
+	 * Trace Messages
+	 */
+	nss_oam_log_rx_msg(nom);
+
+	/*
 	 * Sanity check the message type
 	 */
 	if (nss_cmn_get_msg_len(ncm) > sizeof(struct nss_oam_msg)) {
@@ -74,6 +80,11 @@
 {
 	struct nss_cmn_msg *ncm = &nom->cm;
 
+	/*
+	 * Trace Messages
+	 */
+	nss_oam_log_tx_msg(nom);
+
 	if (ncm->type > NSS_OAM_MSG_TYPE_MAX) {
 		nss_warning("%p: CMD type for oam module is invalid - %d", nss_ctx, ncm->type);
 		return NSS_TX_FAILURE_BAD_PARAM;
diff --git a/nss_oam_log.c b/nss_oam_log.c
new file mode 100644
index 0000000..9fb4823
--- /dev/null
+++ b/nss_oam_log.c
@@ -0,0 +1,101 @@
+/*
+ **************************************************************************
+ * 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_oam_log.c
+ *	NSS OAM logger file.
+ */
+
+#include "nss_core.h"
+
+/*
+ * nss_oam_log_message_types_str
+ *	NSS OAM message strings
+ */
+static int8_t *nss_oam_log_message_types_str[NSS_OAM_MSG_TYPE_MAX] __maybe_unused = {
+	"OAM Message None",
+	"OAM Get FW Version",
+};
+
+/*
+ * nss_oam_log_get_fw_version_msg()
+ *	Log NSS OAM GET FW Version.
+ */
+static void nss_oam_log_get_fw_version_msg(struct nss_oam_msg *nom)
+{
+	struct nss_oam_fw_ver *nofm __maybe_unused = &nom->msg.fw_ver;
+	nss_trace("%p: NSS OAM Get FW Version message \n"
+		"OAM FW Version: %p\n",
+		nofm, nofm->string);
+}
+
+/*
+ * nss_oam_log_verbose()
+ *	Log message contents.
+ */
+static void nss_oam_log_verbose(struct nss_oam_msg *nom)
+{
+	switch (nom->cm.type) {
+	case NSS_OAM_MSG_TYPE_GET_FW_VER:
+		nss_oam_log_get_fw_version_msg(nom);
+		break;
+
+	default:
+		nss_trace("%p: Invalid message type\n", nom);
+		break;
+	}
+}
+
+/*
+ * nss_oam_log_tx_msg()
+ *	Log messages transmitted to FW.
+ */
+void nss_oam_log_tx_msg(struct nss_oam_msg *nom)
+{
+	if (nom->cm.type >= NSS_OAM_MSG_TYPE_MAX) {
+		nss_warning("%p: Invalid message type\n", nom);
+		return;
+	}
+
+	nss_info("%p: type[%d]:%s\n", nom, nom->cm.type, nss_oam_log_message_types_str[nom->cm.type]);
+	nss_oam_log_verbose(nom);
+}
+
+/*
+ * nss_oam_log_rx_msg()
+ *	Log messages received from FW.
+ */
+void nss_oam_log_rx_msg(struct nss_oam_msg *nom)
+{
+	if (nom->cm.response >= NSS_CMN_RESPONSE_LAST) {
+		nss_warning("%p: Invalid response\n", nom);
+		return;
+	}
+
+	if (nom->cm.response == NSS_CMN_RESPONSE_NOTIFY || (nom->cm.response == NSS_CMN_RESPONSE_ACK)) {
+		nss_info("%p: type[%d]:%s, response[%d]:%s\n", nom, nom->cm.type,
+			nss_oam_log_message_types_str[nom->cm.type],
+			nom->cm.response, nss_cmn_response_str[nom->cm.response]);
+		goto verbose;
+	}
+
+	nss_info("%p: msg nack - type[%d]:%s, response[%d]:%s\n",
+		nom, nom->cm.type, nss_oam_log_message_types_str[nom->cm.type],
+		nom->cm.response, nss_cmn_response_str[nom->cm.response]);
+
+verbose:
+	nss_oam_log_verbose(nom);
+}
diff --git a/nss_oam_log.h b/nss_oam_log.h
new file mode 100644
index 0000000..b02611b
--- /dev/null
+++ b/nss_oam_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_OAM_LOG_H
+#define __NSS_OAM_LOG_H
+
+/*
+ * nss_oam.h
+ *	NSS OAM header file.
+ */
+
+/*
+ * Logger APIs
+ */
+
+/*
+ * nss_oam_log_tx_msg
+ *	Logs a oam message that is sent to the NSS firmware.
+ */
+void nss_oam_log_tx_msg(struct nss_oam_msg *nom);
+
+/*
+ * nss_oam_log_rx_msg
+ *	Logs a oam message that is received from the NSS firmware.
+ */
+void nss_oam_log_rx_msg(struct nss_oam_msg *nom);
+
+#endif /* __NSS_OAM_LOG_H */