[qca-nss-drv] LAG Log

Change-Id: I49edf07db6c0326aa76e08c80b2133f41c10aa7b
Signed-off-by: Sachin Shashidhar <sshashid@codeaurora.org>
diff --git a/Makefile b/Makefile
index 53718a1..763d273 100644
--- a/Makefile
+++ b/Makefile
@@ -52,6 +52,7 @@
 			nss_l2tpv2.o \
 			nss_l2tpv2_stats.o \
 			nss_lag.o \
+			nss_lag_log.o \
 			nss_log.o \
 			nss_lso_rx.o \
 			nss_lso_rx_stats.o \
diff --git a/Makefile.fsm b/Makefile.fsm
index 04cc2a5..02a9261 100644
--- a/Makefile.fsm
+++ b/Makefile.fsm
@@ -46,6 +46,7 @@
 			nss_l2tpv2.o \
 			nss_l2tpv2_stats.o \
 			nss_lag.o \
+			nss_lag_log.o \
 			nss_log.o \
 			nss_lso_rx.o \
 			nss_lso_rx_stats.o \
diff --git a/nss_lag.c b/nss_lag.c
index 23aa0da..b58451f 100644
--- a/nss_lag.c
+++ b/nss_lag.c
@@ -22,6 +22,7 @@
 #include <linux/if_bonding.h>
 
 #include "nss_tx_rx_common.h"
+#include "nss_lag_log.h"
 
 #define NSS_LAG_RESP_TIMEOUT 60000	/* 60 Sec */
 
@@ -79,6 +80,11 @@
 	struct nss_cmn_msg *ncm = &msg->cm;
 
 	/*
+	 * Trace Messages
+	 */
+	nss_lag_log_tx_msg(msg);
+
+	/*
 	 * Sanity check the message
 	 */
 	nss_lag_verify_ifnum(ncm->interface);
@@ -151,6 +157,11 @@
 		&& ncm->interface != NSS_LAG2_INTERFACE_NUM
 		&& ncm->interface != NSS_LAG3_INTERFACE_NUM);
 
+	/*
+	 * Trace Messages
+	 */
+	nss_lag_log_rx_msg(lm);
+
 	if (ncm->type >= NSS_TX_METADATA_LAG_MAX) {
 		nss_warning("%p: received invalid message %d for LAG interface", nss_ctx, ncm->type);
 		return;
diff --git a/nss_lag_log.c b/nss_lag_log.c
new file mode 100644
index 0000000..7dc5a77
--- /dev/null
+++ b/nss_lag_log.c
@@ -0,0 +1,103 @@
+/*
+ **************************************************************************
+ * 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_lag_log.c
+ *	NSS LAG logger file.
+ */
+
+#include "nss_core.h"
+
+/*
+ * nss_lag_log_message_types_str
+ *	NSS LAG message strings
+ */
+static int8_t *nss_lag_log_message_types_str[NSS_TX_METADATA_LAG_MAX] __maybe_unused = {
+	"LAG State Change",
+};
+
+/*
+ * nss_lag_log_state_change_msg()
+ *	Log NSS LAG State Change.
+ */
+static void nss_lag_log_state_change_msg(struct nss_lag_msg *nlm)
+{
+	struct nss_lag_state_change *nlcm __maybe_unused = &nlm->msg.state;
+	nss_trace("%p: NSS LAG State Change message \n"
+		"LAG ID: %x\n"
+		"LAG Interface: %x\n"
+		"LAG Event: %d\n",
+		nlcm, nlcm->lagid,
+		nlcm->interface, nlcm->event);
+}
+
+/*
+ * nss_lag_log_verbose()
+ *	Log message contents.
+ */
+static void nss_lag_log_verbose(struct nss_lag_msg *nlm)
+{
+	switch (nlm->cm.type) {
+	case NSS_TX_METADATA_LAG_STATE_CHANGE:
+		nss_lag_log_state_change_msg(nlm);
+		break;
+	
+	default:
+		nss_trace("%p: Invalid message type\n", nlm);
+		break;
+	}
+}
+
+/*
+ * nss_lag_log_tx_msg()
+ *	Log messages transmitted to FW.
+ */
+void nss_lag_log_tx_msg(struct nss_lag_msg *nlm)
+{
+	if (nlm->cm.type >= NSS_TX_METADATA_LAG_MAX) {
+		nss_warning("%p: Invalid message type\n", nlm);
+		return;
+	}
+
+	nss_info("%p: type[%d]:%s\n", nlm, nlm->cm.type, nss_lag_log_message_types_str[nlm->cm.type]);
+	nss_lag_log_verbose(nlm);
+}
+
+/*
+ * nss_lag_log_rx_msg()
+ *	Log messages received from FW.
+ */
+void nss_lag_log_rx_msg(struct nss_lag_msg *nlm)
+{
+	if (nlm->cm.response >= NSS_CMN_RESPONSE_LAST) {
+		nss_warning("%p: Invalid response\n", nlm);
+		return;
+	}
+
+	if (nlm->cm.response == NSS_CMN_RESPONSE_NOTIFY || (nlm->cm.response == NSS_CMN_RESPONSE_ACK)) {
+		nss_info("%p: type[%d]:%s, response[%d]:%s\n", nlm, nlm->cm.type,
+			nss_lag_log_message_types_str[nlm->cm.type],
+			nlm->cm.response, nss_cmn_response_str[nlm->cm.response]);
+		goto verbose;
+	}
+
+	nss_info("%p: msg nack - type[%d]:%s, response[%d]:%s\n",
+		nlm, nlm->cm.type, nss_lag_log_message_types_str[nlm->cm.type],
+		nlm->cm.response, nss_cmn_response_str[nlm->cm.response]);
+
+verbose:
+	nss_lag_log_verbose(nlm);
+}
diff --git a/nss_lag_log.h b/nss_lag_log.h
new file mode 100644
index 0000000..4efe393
--- /dev/null
+++ b/nss_lag_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_LAG_LOG_H
+#define __NSS_LAG_LOG_H
+
+/*
+ * nss_lag.h
+ *	NSS LAG header file.
+ */
+
+/*
+ * Logger APIs
+ */
+
+/*
+ * nss_lag_log_tx_msg
+ *	Logs a lag message that is sent to the NSS firmware.
+ */
+void nss_lag_log_tx_msg(struct nss_lag_msg *nlm);
+
+/*
+ * nss_lag_log_rx_msg
+ *	Logs a lag message that is received from the NSS firmware.
+ */
+void nss_lag_log_rx_msg(struct nss_lag_msg *nlm);
+
+#endif /* __NSS_LAG_LOG_H */