Browse Source

cnss2: Add SMEM based Secure Peripheral check

Check secure peripheral HW state using SMEM APIs instead of
SCM APIs.

Change-Id: I3e652859189221d3b9d26bd2e71e254edf6843b0
CRs-Fixed: 3601121
Naman Padhiar 1 year ago
parent
commit
e9066ddd35
5 changed files with 54 additions and 1 deletions
  1. 4 0
      Kbuild
  2. 7 0
      cnss2/Kconfig
  3. 41 1
      cnss2/main.c
  4. 1 0
      cnss2/pineapple_consolidate_defconfig
  5. 1 0
      cnss2/pineapple_gki_defconfig

+ 4 - 0
Kbuild

@@ -38,6 +38,10 @@ ifeq ($(CONFIG_CNSS_HW_SECURE_DISABLE), y)
 KBUILD_CPPFLAGS += -DCONFIG_CNSS_HW_SECURE_DISABLE
 KBUILD_CPPFLAGS += -DCONFIG_CNSS_HW_SECURE_DISABLE
 endif
 endif
 
 
+ifeq ($(CONFIG_CNSS_HW_SECURE_SMEM), y)
+KBUILD_CPPFLAGS += -DCONFIG_CNSS_HW_SECURE_SMEM
+endif
+
 ifeq ($(CONFIG_CNSS2_CONDITIONAL_POWEROFF),y)
 ifeq ($(CONFIG_CNSS2_CONDITIONAL_POWEROFF),y)
 KBUILD_CPPFLAGS += -DCONFIG_CNSS2_CONDITIONAL_POWEROFF
 KBUILD_CPPFLAGS += -DCONFIG_CNSS2_CONDITIONAL_POWEROFF
 endif
 endif

+ 7 - 0
cnss2/Kconfig

@@ -144,6 +144,13 @@ config CNSS_HW_SECURE_DISABLE
 	  handle WLAN cold boot initialization sequence changes if HW is
 	  handle WLAN cold boot initialization sequence changes if HW is
 	  disabled at boot and WLAN resume sequence after WLAN HW is enabled.
 	  disabled at boot and WLAN resume sequence after WLAN HW is enabled.
 
 
+config CNSS_HW_SECURE_SMEM
+	bool "Enable SMEM API based HW peripheral security"
+	depends on CNSS2
+	help
+	  If enabled, CNSS platform driver will use SMEM APIs intead of SCM
+	  APIs to check peripheral secure state of HW.
+
 config CNSS2_SSR_DRIVER_DUMP
 config CNSS2_SSR_DRIVER_DUMP
 	bool "Enable Host SSR DRIVER DUMP Collection"
 	bool "Enable Host SSR DRIVER DUMP Collection"
 	depends on CNSS2
 	depends on CNSS2

+ 41 - 1
cnss2/main.c

@@ -35,16 +35,21 @@
 #include "reg.h"
 #include "reg.h"
 
 
 #ifdef CONFIG_CNSS_HW_SECURE_DISABLE
 #ifdef CONFIG_CNSS_HW_SECURE_DISABLE
+#ifdef CONFIG_CNSS_HW_SECURE_SMEM
+#include <linux/soc/qcom/smem.h>
+#define PERISEC_SMEM_ID 651
+#define HW_WIFI_UID 0x508
+#else
 #include "smcinvoke.h"
 #include "smcinvoke.h"
 #include "smcinvoke_object.h"
 #include "smcinvoke_object.h"
 #include "IClientEnv.h"
 #include "IClientEnv.h"
-
 #define HW_STATE_UID 0x108
 #define HW_STATE_UID 0x108
 #define HW_OP_GET_STATE 1
 #define HW_OP_GET_STATE 1
 #define HW_WIFI_UID 0x508
 #define HW_WIFI_UID 0x508
 #define FEATURE_NOT_SUPPORTED 12
 #define FEATURE_NOT_SUPPORTED 12
 #define PERIPHERAL_NOT_FOUND 10
 #define PERIPHERAL_NOT_FOUND 10
 #endif
 #endif
+#endif
 
 
 #define CNSS_DUMP_FORMAT_VER		0x11
 #define CNSS_DUMP_FORMAT_VER		0x11
 #define CNSS_DUMP_FORMAT_VER_V2		0x22
 #define CNSS_DUMP_FORMAT_VER_V2		0x22
@@ -4394,6 +4399,40 @@ static int cnss_reboot_notifier(struct notifier_block *nb,
 }
 }
 
 
 #ifdef CONFIG_CNSS_HW_SECURE_DISABLE
 #ifdef CONFIG_CNSS_HW_SECURE_DISABLE
+#ifdef CONFIG_CNSS_HW_SECURE_SMEM
+int cnss_wlan_hw_disable_check(struct cnss_plat_data *plat_priv)
+{
+	uint32_t *peripheralStateInfo = NULL;
+	size_t size = 0;
+
+	/* Once this flag is set, secure peripheral feature
+	 * will not be supported till next reboot
+	 */
+	if (plat_priv->sec_peri_feature_disable)
+		return 0;
+
+	peripheralStateInfo = qcom_smem_get(QCOM_SMEM_HOST_ANY, PERISEC_SMEM_ID, &size);
+	if (IS_ERR_OR_NULL(peripheralStateInfo)) {
+		if (PTR_ERR(peripheralStateInfo) != -ENOENT)
+			CNSS_ASSERT(0);
+
+		cnss_pr_dbg("Secure HW feature not enabled. ret = %d\n",
+			    PTR_ERR(peripheralStateInfo));
+		plat_priv->sec_peri_feature_disable = true;
+		return 0;
+	}
+
+	cnss_pr_dbg("Secure HW state: %d\n", *peripheralStateInfo);
+	if ((*peripheralStateInfo >> (HW_WIFI_UID - 0x500)) & 0x1)
+		set_bit(CNSS_WLAN_HW_DISABLED,
+			&plat_priv->driver_state);
+	else
+		clear_bit(CNSS_WLAN_HW_DISABLED,
+			  &plat_priv->driver_state);
+
+	return 0;
+}
+#else
 int cnss_wlan_hw_disable_check(struct cnss_plat_data *plat_priv)
 int cnss_wlan_hw_disable_check(struct cnss_plat_data *plat_priv)
 {
 {
 	struct Object client_env;
 	struct Object client_env;
@@ -4459,6 +4498,7 @@ end:
 	}
 	}
 	return ret;
 	return ret;
 }
 }
+#endif
 #else
 #else
 int cnss_wlan_hw_disable_check(struct cnss_plat_data *plat_priv)
 int cnss_wlan_hw_disable_check(struct cnss_plat_data *plat_priv)
 {
 {

+ 1 - 0
cnss2/pineapple_consolidate_defconfig

@@ -5,6 +5,7 @@ CONFIG_CNSS_QMI_SVC=m
 CONFIG_BUS_AUTO_SUSPEND=y
 CONFIG_BUS_AUTO_SUSPEND=y
 CONFIG_CNSS2_SSR_DRIVER_DUMP=y
 CONFIG_CNSS2_SSR_DRIVER_DUMP=y
 CONFIG_CNSS_HW_SECURE_DISABLE=y
 CONFIG_CNSS_HW_SECURE_DISABLE=y
+CONFIG_CNSS_HW_SECURE_SMEM=y
 CONFIG_CNSS2_SMMU_DB_SUPPORT=y
 CONFIG_CNSS2_SMMU_DB_SUPPORT=y
 CONFIG_CNSS_PLAT_IPC_QMI_SVC=m
 CONFIG_CNSS_PLAT_IPC_QMI_SVC=m
 CONFIG_WCNSS_MEM_PRE_ALLOC=m
 CONFIG_WCNSS_MEM_PRE_ALLOC=m

+ 1 - 0
cnss2/pineapple_gki_defconfig

@@ -5,6 +5,7 @@ CONFIG_CNSS_QMI_SVC=m
 CONFIG_BUS_AUTO_SUSPEND=y
 CONFIG_BUS_AUTO_SUSPEND=y
 CONFIG_CNSS2_SSR_DRIVER_DUMP=y
 CONFIG_CNSS2_SSR_DRIVER_DUMP=y
 CONFIG_CNSS_HW_SECURE_DISABLE=y
 CONFIG_CNSS_HW_SECURE_DISABLE=y
+CONFIG_CNSS_HW_SECURE_SMEM=y
 CONFIG_CNSS2_SMMU_DB_SUPPORT=y
 CONFIG_CNSS2_SMMU_DB_SUPPORT=y
 CONFIG_CNSS_PLAT_IPC_QMI_SVC=m
 CONFIG_CNSS_PLAT_IPC_QMI_SVC=m
 CONFIG_WCNSS_MEM_PRE_ALLOC=m
 CONFIG_WCNSS_MEM_PRE_ALLOC=m