From f522b85f3e95c053521cdb969e0d0cdf8de69613 Mon Sep 17 00:00:00 2001
From: avishad verma <avishad.verma@infineon.com>
Date: Fri, 5 Jan 2024 06:45:59 -0600
Subject: [PATCH 275/301] brcmfmac: fix CERT-11N: Traffic Differentiation in
 Single BSS with 802.11n STA

Increased PSQ Size from 256 to 256*8.
Increased Low and High Watermark accordingly.
Added Module param to use the old config if required.

Issue:While running muliple streams of 2-BE and 1-VO,
It has been observed the PSQ LOW Watermark is reached.
Reason for reaching Low Mark is VO is borrowing all credits
from BE and BK, causing BE packets to accumulate in PSQ.
Netif queue is stopped once the PSQ Low watermark is reached.
During this queue stop period, PSQ will not be having any VO
packets, causing a drop in VO traffic and WMM test failure.
PSQ size is increased to avoid Netif queue stop.


Signed-off-by: avishad verma <avishad.verma@infineon.com>
---
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
index ad993b555..90b953d46 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.c
@@ -134,6 +134,10 @@ static int brcmf_idle_time_zero;
 module_param_named(idle_time_zero, brcmf_idle_time_zero, int, 0644);
 MODULE_PARM_DESC(idle_time_zero, "Set idle interval to zero");
 
+static int brcmf_short_psq;
+module_param_named(short_psq, brcmf_short_psq, int, 0);
+MODULE_PARM_DESC(short_psq, "Use shorter PS Queue");
+
 static struct brcmfmac_platform_data *brcmfmac_pdata;
 struct brcmf_mp_global_t brcmf_mp_global;
 
@@ -788,6 +792,9 @@ struct brcmf_mp_device *brcmf_get_module_param(struct device *dev,
 	if (bus_type == BRCMF_BUSTYPE_SDIO)
 		settings->bus.sdio.txglomsz = brcmf_sdiod_txglomsz;
 
+	settings->short_psq = !!brcmf_short_psq;
+	brcmf_dbg(INFO, "brcmf_short_psq: %d\n", settings->short_psq);
+
 	settings->idle_time_zero = brcmf_idle_time_zero;
 	brcmf_dbg(INFO, "idle_time_zero: %d\n", settings->idle_time_zero);
 
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
index 54b8fb95c..0379b6641 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/common.h
@@ -67,6 +67,7 @@ struct brcmf_mp_device {
 	bool		sdio_rxf_in_kthread_enabled;
 	unsigned int	offload_prof;
 	unsigned int	offload_feat;
+	bool		short_psq;
 	struct brcmfmac_pd_cc *country_codes;
 	const char	*board_type;
 	unsigned char	mac[ETH_ALEN];
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwsignal.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwsignal.c
index 827c1d5e8..5e0a02363 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwsignal.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/fwsignal.c
@@ -149,11 +149,14 @@ static const char *brcmf_fws_get_tlv_name(enum brcmf_fws_tlv_type id)
 
 #define BRCMF_FWS_HOSTIF_FLOWSTATE_OFF			0
 #define BRCMF_FWS_HOSTIF_FLOWSTATE_ON			1
-#define BRCMF_FWS_FLOWCONTROL_HIWATER			128
-#define BRCMF_FWS_FLOWCONTROL_LOWATER			64
+#define BRCMF_FWS_FLOWCONTROL_HIWATER			((256 * 8) - 256)
+#define BRCMF_FWS_FLOWCONTROL_LOWATER			256
+#define BRCMF_FWS_FLOWCONTROL_SHQUEUE_HIWATER		128
+#define BRCMF_FWS_FLOWCONTROL_SHQUEUE_LOWATER		64
 
 #define BRCMF_FWS_PSQ_PREC_COUNT		((BRCMF_FWS_FIFO_COUNT + 1) * 2)
-#define BRCMF_FWS_PSQ_LEN				256
+#define BRCMF_FWS_PSQ_LEN				(256 * 8)
+#define BRCMF_FWS_SHQUEUE_PSQ_LEN			256
 
 #define BRCMF_FWS_HTOD_FLAG_PKTFROMHOST			0x01
 #define BRCMF_FWS_HTOD_FLAG_PKT_REQUESTED		0x02
@@ -502,6 +505,9 @@ struct brcmf_fws_info {
 	bool creditmap_received;
 	u8 mode;
 	bool avoid_queueing;
+	int fws_psq_len;
+	int fws_psq_hi_water;
+	int fws_psq_low_water;
 };
 
 #define BRCMF_FWS_TLV_DEF(name, id, len) \
@@ -961,11 +967,11 @@ brcmf_fws_flow_control_check(struct brcmf_fws_info *fws, struct pktq *pq,
 		return;
 
 	if ((ifp->netif_stop & BRCMF_NETIF_STOP_REASON_FWS_FC) &&
-	    pq->len <= BRCMF_FWS_FLOWCONTROL_LOWATER)
+	    pq->len <= fws->fws_psq_low_water)
 		brcmf_txflowblock_if(ifp,
 				     BRCMF_NETIF_STOP_REASON_FWS_FC, false);
 	if (!(ifp->netif_stop & BRCMF_NETIF_STOP_REASON_FWS_FC) &&
-	    pq->len >= BRCMF_FWS_FLOWCONTROL_HIWATER) {
+	    pq->len >= fws->fws_psq_hi_water) {
 		fws->stats.fws_flow_block++;
 		brcmf_txflowblock_if(ifp, BRCMF_NETIF_STOP_REASON_FWS_FC, true);
 	}
@@ -1011,8 +1017,9 @@ int brcmf_fws_macdesc_indicate(struct brcmf_fws_info *fws, u8 type, u8 *data)
 			entry->mac_handle = mac_handle;
 			brcmf_fws_macdesc_init(entry, addr, ifidx);
 			brcmf_fws_macdesc_set_name(fws, entry);
-			brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT,
-					BRCMF_FWS_PSQ_LEN);
+			brcmu_pktq_init(&entry->psq,
+					BRCMF_FWS_PSQ_PREC_COUNT,
+					fws->fws_psq_len);
 			brcmf_fws_unlock(fws);
 			brcmf_dbg(TRACE, "add %s mac %pM\n", entry->name, addr);
 		} else {
@@ -2166,8 +2173,9 @@ void brcmf_fws_add_interface(struct brcmf_if *ifp)
 	ifp->fws_desc = entry;
 	brcmf_fws_macdesc_init(entry, ifp->mac_addr, ifp->ifidx);
 	brcmf_fws_macdesc_set_name(fws, entry);
-	brcmu_pktq_init(&entry->psq, BRCMF_FWS_PSQ_PREC_COUNT,
-			BRCMF_FWS_PSQ_LEN);
+	brcmu_pktq_init(&entry->psq,
+			BRCMF_FWS_PSQ_PREC_COUNT,
+			fws->fws_psq_len);
 	brcmf_dbg(TRACE, "added %s\n", entry->name);
 }
 
@@ -2351,6 +2359,16 @@ struct brcmf_fws_info *brcmf_fws_attach(struct brcmf_pub *drvr)
 	fws->drvr = drvr;
 	fws->fcmode = drvr->settings->fcmode;
 
+	if (drvr->settings->short_psq) {
+		fws->fws_psq_len = BRCMF_FWS_SHQUEUE_PSQ_LEN;
+		fws->fws_psq_hi_water = BRCMF_FWS_FLOWCONTROL_SHQUEUE_HIWATER;
+		fws->fws_psq_low_water = BRCMF_FWS_FLOWCONTROL_SHQUEUE_LOWATER;
+	} else {
+		fws->fws_psq_len = BRCMF_FWS_PSQ_LEN;
+		fws->fws_psq_hi_water = BRCMF_FWS_FLOWCONTROL_HIWATER;
+		fws->fws_psq_low_water = BRCMF_FWS_FLOWCONTROL_LOWATER;
+	}
+
 	if (!drvr->bus_if->always_use_fws_queue &&
 	    (fws->fcmode == BRCMF_FWS_FCMODE_NONE)) {
 		fws->avoid_queueing = true;
@@ -2418,8 +2436,9 @@ struct brcmf_fws_info *brcmf_fws_attach(struct brcmf_pub *drvr)
 	brcmf_fws_macdesc_init(&fws->desc.other, NULL, 0);
 	brcmf_fws_macdesc_set_name(fws, &fws->desc.other);
 	brcmf_dbg(INFO, "added %s\n", fws->desc.other.name);
-	brcmu_pktq_init(&fws->desc.other.psq, BRCMF_FWS_PSQ_PREC_COUNT,
-			BRCMF_FWS_PSQ_LEN);
+	brcmu_pktq_init(&fws->desc.other.psq,
+			BRCMF_FWS_PSQ_PREC_COUNT,
+			fws->fws_psq_len);
 
 	brcmf_dbg(INFO, "%s bdcv2 tlv signaling [%x]\n",
 		  fws->fw_signals ? "enabled" : "disabled", tlv);
