[WCNCR00167033] misc: add N9 firmware debug log control

[Description]
 1. Add FW log control feature, needs the corresponding firmware
    ERROR level:        iwpriv wlan0 driver "set_fwlog x x 1"
    WARN level above:   iwpriv wlan0 driver "set_fwlog x x 2"
    STATE level above:  iwpriv wlan0 driver "set_fwlog x x 4"
    INGO level above:   iwpriv wlan0 driver "set_fwlog x x 8"
    LOUD level above:   iwpriv wlan0 driver "set_fwlog x x 16"
 2. Command backward compatibility
    Support original command to enable N9 log to host
    likes "set_fwlog 0 2",
    it is still working after apply this driver change
    and the corresponding firmware.

CR-Id: WCNCR00167033
Feature: misc
Signed-off-by: CP Wang <cp.wang@mediatek.com>
Change-Id: I15aea5c6db553e17aaf9d187327761a7245264e6
diff --git a/common/wlan_oid.c b/common/wlan_oid.c
index 1aa4094..204002f 100644
--- a/common/wlan_oid.c
+++ b/common/wlan_oid.c
@@ -12036,7 +12036,13 @@
 	prFwLog2HostCtrl->u4HostTimeSec = (UINT_32)ts;
 	prFwLog2HostCtrl->u4HostTimeMSec = (UINT_32)(do_div(ts, 1000000000) / 1000);
 
-	DBGLOG(REQ, INFO, "McuDest %d, LogType %d\n", prFwLog2HostCtrl->ucMcuDest, prFwLog2HostCtrl->ucFwLog2HostCtrl);
+#if CFG_SUPPORT_FW_DBG_LEVEL_CTRL
+	DBGLOG(REQ, INFO, "McuDest %d, LogType %d, (FwLogLevel %d)\n", prFwLog2HostCtrl->ucMcuDest,
+		prFwLog2HostCtrl->ucFwLog2HostCtrl, prFwLog2HostCtrl->ucFwLogLevel);
+#else
+	DBGLOG(REQ, INFO, "McuDest %d, LogType %d\n", prFwLog2HostCtrl->ucMcuDest,
+		prFwLog2HostCtrl->ucFwLog2HostCtrl);
+#endif
 
 	return wlanSendSetQueryCmd(prAdapter,
 				CMD_ID_FW_LOG_2_HOST,
diff --git a/include/config.h b/include/config.h
index 7edcf6e..df3387e 100644
--- a/include/config.h
+++ b/include/config.h
@@ -863,6 +863,7 @@
  */
 
 #define CFG_SUPPORT_EASY_DEBUG               1
+#define CFG_SUPPORT_FW_DBG_LEVEL_CTRL        1
 
 
 /*------------------------------------------------------------------------------
diff --git a/include/nic_cmd_event.h b/include/nic_cmd_event.h
index d187fb1..7beea0a 100644
--- a/include/nic_cmd_event.h
+++ b/include/nic_cmd_event.h
@@ -1515,7 +1515,12 @@
 typedef struct _CMD_FW_LOG_2_HOST_CTRL_T {
 	UINT_8 ucFwLog2HostCtrl;
 	UINT_8 ucMcuDest;
+#if     CFG_SUPPORT_FW_DBG_LEVEL_CTRL
+	UINT_8 ucFwLogLevel;
+	UINT_8 ucReserve;
+#else
 	UINT_8 ucReserve[2];
+#endif
 	UINT_32 u4HostTimeSec;
 	UINT_32 u4HostTimeMSec;
 } CMD_FW_LOG_2_HOST_CTRL_T, *P_CMD_FW_LOG_2_HOST_CTRL_T;
diff --git a/include/wlan_oid.h b/include/wlan_oid.h
index 51a832b..f4ff862 100644
--- a/include/wlan_oid.h
+++ b/include/wlan_oid.h
@@ -469,6 +469,16 @@
 	ParamDeviceStateMaximum
 } PARAM_DEVICE_POWER_STATE, *PPARAM_DEVICE_POWER_STATE;
 
+#if CFG_SUPPORT_FW_DBG_LEVEL_CTRL
+/* FW debug control level related definition and enumerations */
+#define FW_DBG_LEVEL_DONT_SET   0
+#define FW_DBG_LEVEL_ERROR      (1 << 0)
+#define FW_DBG_LEVEL_WARN       (1 << 1)
+#define FW_DBG_LEVEL_STATE      (1 << 2)
+#define FW_DBG_LEVEL_INFO       (1 << 3)
+#define FW_DBG_LEVEL_LOUD       (1 << 4)
+#endif
+
 typedef struct _PARAM_POWER_MODE_T {
 	UINT_8 ucBssIdx;
 	PARAM_POWER_MODE ePowerMode;
@@ -1211,7 +1221,7 @@
 	UINT_8 ucPfMuIdOfUser0;	/* zero-base : for now, uesr0 use pf mu id 0 */
 	UINT_8 ucPfMuIdOfUser1;	/* zero-base : for now, uesr1 use pf mu id 1 */
 	UINT_8 ucNumOfTxer;	/* 0~3: mean use 1~4 anntain, for now, should fix 3 */
-	UINT_8 ucSpeIndex;	/*add new field to fill¡§special extension index¡¨which replace reserve */
+	UINT_8 ucSpeIndex;	/*add new field to fill special extension index which replace reserve */
 	UINT_32 u4GroupIndex;	/* 0~ :the index of group table entry for calculation */
 } MU_SET_INIT_MCS_T, *P_MU_SET_INIT_MCS_T;
 
@@ -1223,7 +1233,7 @@
 	UINT_8 ucPfMuIdOfUser0;	/* zero-base : for now, uesr0 use pf mu id 0 */
 	UINT_8 ucPfMuIdOfUser1;	/* zero-base : for now, uesr1 use pf mu id 1 */
 	UINT_8 ucNumOfTxer;	/* 0~3: mean use 1~4 anntain, for now, should fix 3 */
-	UINT_8 ucSpeIndex;	/*add new field to fill¡§special extension index¡¨which replace reserve */
+	UINT_8 ucSpeIndex;	/*add new field to fill special extension index which replace reserve */
 	UINT_32 u4GroupIndex;	/* 0~ :the index of group table entry for calculation */
 } MU_SET_CALC_LQ_T, *P_MU_SET_CALC_LQ_T;
 
diff --git a/os/linux/gl_wext_priv.c b/os/linux/gl_wext_priv.c
index f48a537..d9a7080 100644
--- a/os/linux/gl_wext_priv.c
+++ b/os/linux/gl_wext_priv.c
@@ -3693,6 +3693,9 @@
 	PCHAR apcArgv[WLAN_CFG_ARGV_MAX];
 	UINT_32 u4McuDest = 0;
 	UINT_32 u4LogType = 0;
+#if CFG_SUPPORT_FW_DBG_LEVEL_CTRL
+	UINT_32 ucFwLogLevel = FW_DBG_LEVEL_DONT_SET;
+#endif
 	P_CMD_FW_LOG_2_HOST_CTRL_T prFwLog2HostCtrl = NULL;
 	UINT_32 u4Ret = 0;
 
@@ -3711,11 +3714,19 @@
 		goto out;
 	}
 
+#if CFG_SUPPORT_FW_DBG_LEVEL_CTRL
+	if ((i4Argc != 3) && (i4Argc != 4)) {
+		DBGLOG(REQ, ERROR, "argc %i  must be 3 or 4\n", i4Argc);
+		i4BytesWritten = -1;
+		goto out;
+	}
+#else
 	if (i4Argc != 3) {
 		DBGLOG(REQ, ERROR, "argc %i is not equal to 3\n", i4Argc);
 		i4BytesWritten = -1;
 		goto out;
 	}
+#endif
 
 	u4Ret = kalkStrtou32(apcArgv[1], 0, &u4McuDest);
 	if (u4Ret)
@@ -3725,6 +3736,15 @@
 	if (u4Ret)
 		DBGLOG(REQ, LOUD, "parse u4LogType error u4Ret=%d\n", u4Ret);
 
+#if CFG_SUPPORT_FW_DBG_LEVEL_CTRL
+	if (i4Argc == 4) {
+		u4Ret = kalkStrtou32(apcArgv[3], 0, &ucFwLogLevel);
+		if (u4Ret)
+			DBGLOG(REQ, LOUD, "parse ucFwLogLevel error u4Ret=%d\n", u4Ret);
+	}
+	prFwLog2HostCtrl->ucFwLogLevel = (UINT_8)ucFwLogLevel;
+#endif
+
 	prFwLog2HostCtrl->ucMcuDest = (UINT_8)u4McuDest;
 	prFwLog2HostCtrl->ucFwLog2HostCtrl = (UINT_8)u4LogType;