Browse Source

qcacld-3.0: Add base code for Bus Bandwidth Manager

Add the init and de-init APIs for Bus Bandwidth
Manager.

Change-Id: I63c9bf0dbcbac458dd6467e5b073a5cb569ce502
CRs-Fixed: 2810496
Yeshwanth Sriram Guntuka 4 years ago
parent
commit
1cbef73e16

+ 5 - 0
Kbuild

@@ -432,6 +432,10 @@ ifeq ($(CONFIG_WLAN_BOOTUP_MARKER), y)
 HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_bootup_marker.o
 endif
 
+ifeq ($(CONFIG_FEATURE_BUS_BANDWIDTH_MGR),y)
+HDD_OBJS += $(HDD_SRC_DIR)/wlan_hdd_bus_bandwidth.o
+endif
+
 ###### OSIF_SYNC ########
 SYNC_DIR := os_if/sync
 SYNC_INC_DIR := $(SYNC_DIR)/inc
@@ -2671,6 +2675,7 @@ cppflags-$(CONFIG_PLD_IPCI_ICNSS_FLAG) += -DCONFIG_PLD_IPCI_ICNSS
 cppflags-$(CONFIG_PLD_SDIO_CNSS_FLAG) += -DCONFIG_PLD_SDIO_CNSS
 cppflags-$(CONFIG_WLAN_RESIDENT_DRIVER) += -DFEATURE_WLAN_RESIDENT_DRIVER
 cppflags-$(CONFIG_FEATURE_GPIO_CFG) += -DWLAN_FEATURE_GPIO_CFG
+cppflags-$(CONFIG_FEATURE_BUS_BANDWIDTH_MGR) += -DFEATURE_BUS_BANDWIDTH_MGR
 
 ifeq ($(CONFIG_IPCIE_FW_SIM), y)
 cppflags-y += -DCONFIG_PLD_IPCIE_FW_SIM

+ 2 - 0
configs/default_defconfig

@@ -1097,11 +1097,13 @@ CONFIG_PLD_SDIO_CNSS_FLAG := y
 endif
 ifeq ($(CONFIG_HIF_PCI), y)
 CONFIG_PLD_PCIE_CNSS_FLAG := y
+CONFIG_FEATURE_BUS_BANDWIDTH_MGR := y
 endif
 endif
 
 ifeq (y,$(findstring y,$(CONFIG_CNSS2) $(CONFIG_CNSS2_MODULE)))
 ifeq ($(CONFIG_HIF_PCI), y)
+CONFIG_FEATURE_BUS_BANDWIDTH_MGR := y
 CONFIG_PLD_PCIE_CNSS_FLAG := y
 CONFIG_PLD_PCIE_INIT_FLAG := y
 endif

+ 5 - 0
core/hdd/inc/wlan_hdd_main.h

@@ -117,6 +117,7 @@
 #endif
 
 #include "wlan_hdd_sta_info.h"
+#include "wlan_hdd_bus_bandwidth.h"
 
 /*
  * Preprocessor definitions and constants
@@ -1767,6 +1768,7 @@ struct hdd_adapter_ops_history {
  * @multi_client_thermal_mitigation: Multi client thermal mitigation by fw
  * @is_therm_cmd_supp: get temperature command enable or disable
  * @disconnect_for_sta_mon_conc: disconnect if sta monitor intf concurrency
+ * @bbm_ctx: bus bandwidth manager context
  */
 struct hdd_context {
 	struct wlan_objmgr_psoc *psoc;
@@ -2110,6 +2112,9 @@ struct hdd_context {
 	bool multi_client_thermal_mitigation;
 #endif
 	bool disconnect_for_sta_mon_conc;
+#ifdef FEATURE_BUS_BANDWIDTH_MGR
+	struct bbm_context *bbm_ctx;
+#endif
 };
 
 /**

+ 116 - 0
core/hdd/src/wlan_hdd_bus_bandwidth.c

@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2020 The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+/**
+ * DOC: wlan_hdd_bus_bandwidth.c
+ *
+ * Bus Bandwidth Manager implementation
+ */
+
+#include <wlan_hdd_includes.h>
+#include "qca_vendor.h"
+#include "wlan_hdd_bus_bandwidth.h"
+
+/**
+ * bus_bw_table_default - default table which provides bus bandwidth level
+ *  corresonding to a given connection mode and throughput level.
+ */
+static bus_bw_table_type bus_bw_table_default = {
+	[QCA_WLAN_802_11_MODE_11B] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_1,
+				      BUS_BW_LEVEL_2, BUS_BW_LEVEL_3,
+				      BUS_BW_LEVEL_4, BUS_BW_LEVEL_6},
+	[QCA_WLAN_802_11_MODE_11G] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_5,
+				      BUS_BW_LEVEL_5, BUS_BW_LEVEL_5,
+				      BUS_BW_LEVEL_5, BUS_BW_LEVEL_5},
+	[QCA_WLAN_802_11_MODE_11A] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_5,
+				      BUS_BW_LEVEL_5, BUS_BW_LEVEL_5,
+				      BUS_BW_LEVEL_5, BUS_BW_LEVEL_5},
+	[QCA_WLAN_802_11_MODE_11N] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_1,
+				      BUS_BW_LEVEL_2, BUS_BW_LEVEL_3,
+				      BUS_BW_LEVEL_4, BUS_BW_LEVEL_6},
+	[QCA_WLAN_802_11_MODE_11AC] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_1,
+				       BUS_BW_LEVEL_2, BUS_BW_LEVEL_3,
+				       BUS_BW_LEVEL_4, BUS_BW_LEVEL_6},
+	[QCA_WLAN_802_11_MODE_11AX] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_1,
+				       BUS_BW_LEVEL_2, BUS_BW_LEVEL_3,
+				       BUS_BW_LEVEL_4, BUS_BW_LEVEL_6},
+};
+
+/**
+ * bus_bw_table_low_latency - table which provides bus bandwidth level
+ *  corresonding to a given connection mode and throughput level in low
+ *  latency setting.
+ */
+static bus_bw_table_type bus_bw_table_low_latency = {
+	[QCA_WLAN_802_11_MODE_11B] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_6,
+				      BUS_BW_LEVEL_6, BUS_BW_LEVEL_6,
+				      BUS_BW_LEVEL_6, BUS_BW_LEVEL_6},
+	[QCA_WLAN_802_11_MODE_11G] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_6,
+				      BUS_BW_LEVEL_6, BUS_BW_LEVEL_6,
+				      BUS_BW_LEVEL_6, BUS_BW_LEVEL_6},
+	[QCA_WLAN_802_11_MODE_11A] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_6,
+				      BUS_BW_LEVEL_6, BUS_BW_LEVEL_6,
+				      BUS_BW_LEVEL_6, BUS_BW_LEVEL_6},
+	[QCA_WLAN_802_11_MODE_11N] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_6,
+				      BUS_BW_LEVEL_6, BUS_BW_LEVEL_6,
+				      BUS_BW_LEVEL_6, BUS_BW_LEVEL_6},
+	[QCA_WLAN_802_11_MODE_11AC] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_6,
+				       BUS_BW_LEVEL_6, BUS_BW_LEVEL_6,
+				       BUS_BW_LEVEL_6, BUS_BW_LEVEL_6},
+	[QCA_WLAN_802_11_MODE_11AX] = {BUS_BW_LEVEL_NONE, BUS_BW_LEVEL_6,
+				       BUS_BW_LEVEL_6, BUS_BW_LEVEL_6,
+				       BUS_BW_LEVEL_6, BUS_BW_LEVEL_6},
+};
+
+int hdd_bbm_context_init(struct hdd_context *hdd_ctx)
+{
+	struct bbm_context *bbm_ctx;
+	QDF_STATUS status;
+
+	bbm_ctx = qdf_mem_malloc(sizeof(*bbm_ctx));
+	if (!bbm_ctx)
+		return -ENOMEM;
+
+	bbm_ctx->curr_bus_bw_lookup_table = &bus_bw_table_default;
+
+	status = qdf_mutex_create(&bbm_ctx->bbm_lock);
+	if (QDF_IS_STATUS_ERROR(status))
+		goto free_ctx;
+
+	hdd_ctx->bbm_ctx = bbm_ctx;
+
+	return 0;
+
+free_ctx:
+	qdf_mem_free(bbm_ctx);
+
+	return qdf_status_to_os_return(status);
+}
+
+void hdd_bbm_context_deinit(struct hdd_context *hdd_ctx)
+{
+	struct bbm_context *bbm_ctx = hdd_ctx->bbm_ctx;
+
+	if (!bbm_ctx)
+		return;
+
+	hdd_ctx->bbm_ctx = NULL;
+	qdf_mutex_destroy(&bbm_ctx->bbm_lock);
+
+	qdf_mem_free(bbm_ctx);
+}

+ 194 - 0
core/hdd/src/wlan_hdd_bus_bandwidth.h

@@ -0,0 +1,194 @@
+/*
+ * Copyright (c) 2020 The Linux Foundation. All rights reserved.
+ *
+ * Permission to use, copy, modify, and/or distribute this software for
+ * any purpose with or without fee is hereby granted, provided that the
+ * above copyright notice and this permission notice appear in all
+ * copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
+ * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
+ * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
+ * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
+ * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
+ * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+ * PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#if !defined(WLAN_HDD_BUS_BANDWIDTH_H)
+#define WLAN_HDD_BUS_BANDWIDTH_H
+/**
+ * DOC: wlan_hdd_bus_bandwidth.h
+ *
+ * Bus Bandwidth Manager implementation
+ */
+
+#include "qca_vendor.h"
+
+/**
+ * enum bus_bw_level - bus bandwidth vote levels
+ *
+ * @BUS_BW_LEVEL_NONE: No vote for bus bandwidth
+ * @BUS_BW_LEVEL_1: vote for level-1 bus bandwidth
+ * @BUS_BW_LEVEL_2: vote for level-2 bus bandwidth
+ * @BUS_BW_LEVEL_3: vote for level-3 bus bandwidth
+ * @BUS_BW_LEVEL_4: vote for level-4 bus bandwidth
+ * @BUS_BW_LEVEL_5: vote for level-5 bus bandwidth
+ * @BUS_BW_LEVEL_6: vote for level-6 bus bandwidth
+ */
+enum bus_bw_level {
+	BUS_BW_LEVEL_NONE,
+	BUS_BW_LEVEL_1,
+	BUS_BW_LEVEL_2,
+	BUS_BW_LEVEL_3,
+	BUS_BW_LEVEL_4,
+	BUS_BW_LEVEL_5,
+	BUS_BW_LEVEL_6,
+	BUS_BW_LEVEL_MAX,
+};
+
+/**
+ * enum tput_level - throughput levels
+ *
+ * @TPUT_LEVEL_NONE: No throughput
+ * @TPUT_LEVEL_IDLE: idle throughtput level
+ * @TPUT_LEVEL_LOW: low throughput level
+ * @TPUT_LEVEL_MEDIUM: medium throughtput level
+ * @TPUT_LEVEL_HIGH: high throughput level
+ * @TPUT_LEVEL_VERY_HIGH: very high throughput level
+ */
+enum tput_level {
+	TPUT_LEVEL_NONE,
+	TPUT_LEVEL_IDLE,
+	TPUT_LEVEL_LOW,
+	TPUT_LEVEL_MEDIUM,
+	TPUT_LEVEL_HIGH,
+	TPUT_LEVEL_VERY_HIGH,
+	TPUT_LEVEL_MAX,
+};
+
+/**
+ * enum bbm_non_per_flag - Non persistent policy related flag
+ *
+ * @BBM_APPS_RESUME: system resume flag
+ * @BBM_APPS_SUSPEND: system suspend flag
+ */
+enum bbm_non_per_flag {
+	BBM_APPS_RESUME,
+	BBM_APPS_SUSPEND,
+	BBM_FLAG_MAX,
+};
+
+/**
+ * enum bbm_policy - BBM policy
+ *
+ * @BBM_DRIVER_MODE_POLICY: driver mode policy
+ * @BBM_TPUT_POLICY: throughput policy
+ * @BBM_USER_POLICY: user policy
+ * @BBM_NON_PERSISTENT_POLICY: non persistent policy. For example, bus resume
+ *  sets the bus bw level to LEVEL_3 if any adapter is connected but
+ *  this is only a one time setting and is not persistent. This bus bw level
+ *  is set without taking other policy vote levels into consideration.
+ * @BBM_SELECT_TABLE_POLICY: policy where bus bw table is selected based on
+ *  the latency level.
+ */
+enum bbm_policy {
+	BBM_DRIVER_MODE_POLICY,
+	BBM_TPUT_POLICY,
+	BBM_USER_POLICY,
+	BBM_NON_PERSISTENT_POLICY,
+	BBM_SELECT_TABLE_POLICY,
+	BBM_MAX_POLICY,
+};
+
+/**
+ * enum wlm_ll_level - WLM latency levels
+ *
+ * @WLM_LL_NORMAL: normal latency level
+ * @WLM_LL_LOW: low latency level
+ */
+enum wlm_ll_level {
+	WLM_LL_NORMAL,
+	WLM_LL_LOW,
+	WLM_LL_MAX,
+};
+
+/**
+ * union bbm_policy_info - BBM policy specific info. Only one of the value
+ *  would be valid based on the BBM policy.
+ *
+ * @driver_mode: global driver mode. valid for BBM_DRIVER_MODE_POLICY.
+ * @flag: BBM non persistent flag. valid for BBM_NON_PERSISTENT_POLICY.
+ * @tput_level: throughput level. valid for BBM_TPUT_POLICY.
+ * @wlm_level: latency level. valid for BBM_WLM_POLICY.
+ * @user_level: user bus bandwidth vote. valid for BBM_USER_POLICY.
+ * @set: set or reset user level. valid for BBM_USER_POLICY.
+ */
+union bbm_policy_info {
+	enum QDF_GLOBAL_MODE driver_mode;
+	enum bbm_non_per_flag flag;
+	enum tput_level tput_level;
+	enum wlm_ll_level wlm_level;
+	struct {
+		enum bus_bw_level user_level;
+		bool set;
+	} usr;
+};
+
+/**
+ * struct bbm_params - BBM params
+ *
+ * @policy: BBM policy
+ * @policy_info: policy related info
+ */
+struct bbm_params {
+	enum bbm_policy policy;
+	union bbm_policy_info policy_info;
+};
+
+typedef const enum bus_bw_level
+	bus_bw_table_type[QCA_WLAN_802_11_MODE_INVALID][TPUT_LEVEL_MAX];
+
+/**
+ * struct bbm_context: Bus Bandwidth Manager context
+ *
+ * @curr_bus_bw_lookup_table: current bus bw lookup table
+ * @curr_vote_level: current vote level
+ * @per_policy_vote: per BBM policy related vote
+ * @bbm_lock: BBM API lock
+ */
+struct bbm_context {
+	bus_bw_table_type *curr_bus_bw_lookup_table;
+	enum bus_bw_level curr_vote_level;
+	enum bus_bw_level per_policy_vote[BBM_MAX_POLICY];
+	qdf_mutex_t bbm_lock;
+};
+
+#ifdef FEATURE_BUS_BANDWIDTH_MGR
+/**
+ * hdd_bbm_context_init() - Initialize BBM context
+ * @hdd_ctx: HDD context
+ *
+ * Returns: error code
+ */
+int hdd_bbm_context_init(struct hdd_context *hdd_ctx);
+
+/**
+ * hdd_bbm_context_deinit() - De-initialize BBM context
+ * @hdd_ctx: HDD context
+ *
+ * Returns: None
+ */
+void hdd_bbm_context_deinit(struct hdd_context *hdd_ctx);
+#else
+static inline int hdd_bbm_context_init(struct hdd_context *hdd_ctx)
+{
+	return 0;
+}
+
+static inline void hdd_bbm_context_deinit(struct hdd_context *hdd_ctx)
+{
+}
+#endif
+#endif

+ 11 - 1
core/hdd/src/wlan_hdd_main.c

@@ -199,6 +199,7 @@
 #include "osif_cm_util.h"
 #include "wlan_hdd_gpio_wakeup.h"
 #include "wlan_hdd_bootup_marker.h"
+#include "wlan_hdd_bus_bandwidth.h"
 
 #ifdef MODULE
 #define WLAN_MODULE_NAME  module_name(THIS_MODULE)
@@ -8889,6 +8890,8 @@ static int hdd_context_deinit(struct hdd_context *hdd_ctx)
 
 	wlan_hdd_cfg80211_deinit(hdd_ctx->wiphy);
 
+	hdd_bbm_context_deinit(hdd_ctx);
+
 	hdd_sap_context_destroy(hdd_ctx);
 
 	hdd_rx_wake_lock_destroy(hdd_ctx);
@@ -11646,6 +11649,10 @@ static int hdd_context_init(struct hdd_context *hdd_ctx)
 	if (ret)
 		goto scan_destroy;
 
+	ret = hdd_bbm_context_init(hdd_ctx);
+	if (ret)
+		goto sap_destroy;
+
 	wlan_hdd_cfg80211_extscan_init(hdd_ctx);
 
 	hdd_init_offloaded_packets_ctx(hdd_ctx);
@@ -11653,13 +11660,16 @@ static int hdd_context_init(struct hdd_context *hdd_ctx)
 	ret = wlan_hdd_cfg80211_init(hdd_ctx->parent_dev, hdd_ctx->wiphy,
 				     hdd_ctx->config);
 	if (ret)
-		goto sap_destroy;
+		goto bbm_destroy;
 
 	qdf_wake_lock_create(&hdd_ctx->monitor_mode_wakelock,
 			     "monitor_mode_wakelock");
 
 	return 0;
 
+bbm_destroy:
+	hdd_bbm_context_deinit(hdd_ctx);
+
 sap_destroy:
 	hdd_sap_context_destroy(hdd_ctx);