From 955dadbcd49c89dbc5b85f013b769e4b2eb1aa89 Mon Sep 17 00:00:00 2001
From: JasonHuang <Jason.Huang2@infineon.com>
Date: Mon, 26 Feb 2024 02:58:21 -0600
Subject: [PATCH] non-upstream: vendor cmd addition for replay counter

The 43022's number of replay counters is 4. The legacy chips are 16.
Therefore, we need to add the vendor cmd for app to get and set the
right value.

Signed-off-by: JasonHuang <Jason.Huang2@infineon.com>
---
 .../broadcom/brcm80211/brcmfmac/vendor.c      |  7 ++++
 .../broadcom/brcm80211/brcmfmac/vendor_ifx.c  | 32 +++++++++++++++++++
 .../broadcom/brcm80211/brcmfmac/vendor_ifx.h  | 17 +++++++++-
 3 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
index c239c64dd..ed618babc 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor.c
@@ -336,6 +336,13 @@ const struct wiphy_vendor_command brcmf_vendor_cmds[] = {
 			ifx_cfg80211_vndr_cmds_wnm),
 		.maxattr = IFX_VENDOR_ATTR_WNM_MAX
 	},
+	{
+		IFX_SUBCMD(HWCAPS,
+			   (WIPHY_VENDOR_CMD_NEED_WDEV |
+				WIPHY_VENDOR_CMD_NEED_NETDEV),
+			VENDOR_CMD_RAW_DATA,
+			ifx_cfg80211_vndr_cmds_hwcaps),
+	},
 };

 const struct nl80211_vendor_cmd_info brcmf_vendor_events[] = {
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.c b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.c
index ad25ecdfc..0d704773e 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.c
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.c
@@ -32,6 +32,7 @@
  */

 #include <net/netlink.h>
+#include <brcm_hw_ids.h>
 #include "core.h"
 #include "cfg80211.h"
 #include "debug.h"
@@ -39,6 +40,7 @@
 #include "vendor_ifx.h"
 #include "xtlv.h"
 #include "twt.h"
+#include "bus.h"

 static int ifx_cfg80211_vndr_send_cmd_reply(struct wiphy *wiphy,
 					    const void  *data, int len)
@@ -710,3 +712,33 @@ int ifx_cfg80211_vndr_cmds_wnm(struct wiphy *wiphy,

 	return ret;
 }
+
+int ifx_cfg80211_vndr_cmds_hwcaps(struct wiphy *wiphy,
+				  struct wireless_dev *wdev,
+				  const void *data, int len)
+{
+	int ret = 0, i;
+	struct brcmf_cfg80211_vif *vif;
+	struct brcmf_if *ifp;
+	struct brcmf_bus *bus_if;
+	s32 buf[IFX_VENDOR_HW_CAPS_MAX] = {0};
+
+	vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
+	ifp = vif->ifp;
+	bus_if = ifp->drvr->bus_if;
+
+	//if (bus_if->chip == CY_CC_43022_CHIP_ID)
+	//	buf[IFX_VENDOR_HW_CAPS_REPLAYCNTS] = 4;
+	//else
+	buf[IFX_VENDOR_HW_CAPS_REPLAYCNTS] = 16;
+
+	ret = ifx_cfg80211_vndr_send_cmd_reply(wiphy, buf, sizeof(int));
+	if (ret) {
+		brcmf_dbg(INFO, "get HW capability error %d\n", ret);
+	} else {
+		for (i = 0; i < IFX_VENDOR_HW_CAPS_MAX; i++)
+			brcmf_dbg(INFO, "get %s: %d\n", hw_caps_name[i], buf[i]);
+	}
+
+	return ret;
+}
diff --git a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.h b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.h
index ddfa2025f..d5e722cd8 100644
--- a/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.h
+++ b/drivers/net/wireless/broadcom/brcm80211/brcmfmac/vendor_ifx.h
@@ -109,6 +109,8 @@ struct bcm_iov_buf {
  * @IFX_VENDOR_SCMD_WNM: Configure the Wireless Network Management (WNM) 802.11v functionaltiy
  *	related parameters.
  *
+ * @IFX_VENDOR_SCMD_HWCAPS: Get device's capability.
+ *
  * @IFX_VENDOR_SCMD_MAX: This acts as a the tail of cmds list.
  *      Make sure it located at the end of the list.
  */
@@ -139,7 +141,8 @@ enum ifx_nl80211_vendor_subcmds {
 	SCMD(RSV22)		= 23,
 	SCMD(RSV24)		= 24,
 	SCMD(WNM)		= 25,
-	SCMD(MAX)		= 26
+	SCMD(HWCAPS)		= 26,
+	SCMD(MAX)		= 27
 };

 /*
@@ -633,6 +636,15 @@ enum ifx_vendor_attr_wnm {
 	IFX_VENDOR_ATTR_WNM_MAX
 };

+enum ifx_vendor_hw_caps {
+	IFX_VENDOR_HW_CAPS_REPLAYCNTS,
+	IFX_VENDOR_HW_CAPS_MAX
+};
+
+static const char * const hw_caps_name[] = {
+	[IFX_VENDOR_HW_CAPS_REPLAYCNTS] = "replay counters"
+};
+
 static const struct nla_policy ifx_vendor_attr_wnm_policy[IFX_VENDOR_ATTR_WNM_MAX + 1] = {
 	[IFX_VENDOR_ATTR_WNM_UNSPEC] = {.type = NLA_U8},
 	[IFX_VENDOR_ATTR_WNM_CMD] = {.type = NLA_U8},
@@ -716,6 +728,9 @@ int ifx_cfg80211_vndr_cmds_giantrx(struct wiphy *wiphy,
 int ifx_cfg80211_vndr_cmds_wnm(struct wiphy *wiphy,
 			       struct wireless_dev *wdev,
 			       const void *data, int len);
+int ifx_cfg80211_vndr_cmds_hwcaps(struct wiphy *wiphy,
+				  struct wireless_dev *wdev,
+				  const void *data, int len);

 #endif /* IFX_VENDOR_H */

--
2.39.5 (Apple Git-154)

