[WCNCR00152235] sdio: fix command port Tx over flow issue

[Description]
Fix Tx over flow issue when in Trooper AP mode.
BUG: TC4 resource recycle is incorrect. Extra resource is added back.
Solution: read clear the TQ counters after update totla resource based on
  Capability_V2's response.

Change-Id: If0fd158c739bf93797621f1fbde733a9cb2652b6
Feature: sdio
Signed-off-by: Chiahsuan Chuang <chiahsuan.chuang@mediatek.com>
CR-Id: WCNCR00152235
Reviewed-on: http://gerrit.mediatek.inc:8080/813712
CheckPatch: Check Patch <srv_checkpatch@mediatek.com>
Reviewed-by: TH3 Huang <th3.huang@mediatek.com>
Reviewed-by: Wayne Guo <wayne.guo@mediatek.com>
Build: srv_neptune_adm <srv_neptune_adm@mediatek.com>
diff --git a/common/wlan_lib.c b/common/wlan_lib.c
index 8d9a608..d4dd68a 100644
--- a/common/wlan_lib.c
+++ b/common/wlan_lib.c
@@ -6425,6 +6425,8 @@
 	/* 3 4. Reset QM resource */
 	qmResetTcControlResource(prAdapter);
 #endif
+
+	halTxResourceResetHwTQCounter(prAdapter);
 }
 
 
diff --git a/include/nic/hal.h b/include/nic/hal.h
index 8f299d2..0f8c52e 100644
--- a/include/nic/hal.h
+++ b/include/nic/hal.h
@@ -1052,4 +1052,6 @@
 VOID halTxCompleteTasklet(unsigned long data);
 VOID halPrintHifDbgInfo(IN P_ADAPTER_T prAdapter);
 BOOLEAN halIsTxResourceControlEn(IN P_ADAPTER_T prAdapter);
+VOID halTxResourceResetHwTQCounter(IN P_ADAPTER_T prAdapter);
+
 #endif /* _HAL_H */
diff --git a/os/linux/hif/pcie/hal_api.c b/os/linux/hif/pcie/hal_api.c
index b42b026..d14dceb 100644
--- a/os/linux/hif/pcie/hal_api.c
+++ b/os/linux/hif/pcie/hal_api.c
@@ -1693,3 +1693,8 @@
 {
 	return FALSE;
 }
+
+VOID halTxResourceResetHwTQCounter(IN P_ADAPTER_T prAdapter)
+{
+}
+
diff --git a/os/linux/hif/sdio/hal_api.c b/os/linux/hif/sdio/hal_api.c
index dfde0ea..57f9584 100644
--- a/os/linux/hif/sdio/hal_api.c
+++ b/os/linux/hif/sdio/hal_api.c
@@ -2120,3 +2120,13 @@
 	return TRUE;
 }
 
+VOID halTxResourceResetHwTQCounter(IN P_ADAPTER_T prAdapter)
+{
+	UINT_32 u4WHISR = 0;
+	UINT_16 au2TxCount[16];
+
+	HAL_READ_INTR_STATUS(prAdapter, 4, (PUINT_8)&u4WHISR);
+	if (HAL_IS_TX_DONE_INTR(u4WHISR))
+		HAL_READ_TX_RELEASED_COUNT(prAdapter, au2TxCount);
+}
+
diff --git a/os/linux/hif/usb/hal_api.c b/os/linux/hif/usb/hal_api.c
index 1b527b2..fbbdc86 100644
--- a/os/linux/hif/usb/hal_api.c
+++ b/os/linux/hif/usb/hal_api.c
@@ -1479,3 +1479,7 @@
 	return FALSE;
 }
 
+VOID halTxResourceResetHwTQCounter(IN P_ADAPTER_T prAdapter)
+{
+}
+