qcacmn: Add WMI changes for Dynamic HW mode configuration

This feature enables user to change HW mode dynamically
from DBS to DBS_SBS mode and vice-versa. Currently, HW
mode configuration is only possible through INI setting
requiring a subsequent reboot.

Relevant WMI changes are:

1. Relocate API wmi_unified_soc_set_hw_mode_cmd from
wmi_unified_sta_api.c to wmi_unified_api.c
2. Define API wmi_unified_extract_hw_mode_resp to extract
FW response
3. Parse and store new dev-cap fields wireless_modes,
low_2ghz_chan_freq, high_2ghz_chan_freq, low_5ghz_chan_freq,
and high_5ghz_chan_freq.

Change-Id: I49f975e7c5abc8503b651a3ebd4d56b23af915db
CRs-fixed: 2490212
diff --git a/wmi/inc/wmi_unified_api.h b/wmi/inc/wmi_unified_api.h
index c820888..a7b0c92 100644
--- a/wmi/inc/wmi_unified_api.h
+++ b/wmi/inc/wmi_unified_api.h
@@ -470,6 +470,32 @@
 uint16_t wmi_get_max_msg_len(wmi_unified_t wmi_handle);
 
 /**
+ * wmi_unified_soc_set_hw_mode_cmd() - Send WMI_SOC_SET_HW_MODE_CMDID to FW
+ * @wmi_handle: wmi handle
+ * @hw_mode_index: The HW_Mode field is a enumerated type that is selected
+ * from the HW_Mode table, which is returned in the WMI_SERVICE_READY_EVENTID.
+ *
+ * Request HardWare (HW) Mode change to WLAN firmware
+ *
+ * Return: QDF_STATUS_SUCCESS on success and QDF_STATUS_E_FAILURE for failure
+ */
+QDF_STATUS wmi_unified_soc_set_hw_mode_cmd(wmi_unified_t wmi_handle,
+					   uint32_t hw_mode_index);
+
+/**
+ * wmi_extract_hw_mode_resp() - function to extract HW mode change response
+ * @wmi_hdl: WMI handle
+ * @evt_buf: Buffer holding event data
+ * @cmd_status: command status
+ *
+ * Return: QDF_STATUS_SUCCESS if success, else returns proper error code.
+ */
+QDF_STATUS
+wmi_unified_extract_hw_mode_resp(wmi_unified_t wmi,
+				 void *evt_buf,
+				 uint32_t *cmd_status);
+
+/**
  * wmi_unified_vdev_create_send() - send VDEV create command to fw
  * @wmi_handle: wmi handle
  * @param: pointer to hold vdev create parameter
diff --git a/wmi/inc/wmi_unified_param.h b/wmi/inc/wmi_unified_param.h
index 07c2b8a..44803f5 100644
--- a/wmi/inc/wmi_unified_param.h
+++ b/wmi/inc/wmi_unified_param.h
@@ -5355,6 +5355,7 @@
 	wmi_service_vdev_delete_all_peer,
 	wmi_service_three_way_coex_config_legacy,
 	wmi_service_rx_fse_support,
+	wmi_service_dynamic_hw_mode,
 	wmi_services_max,
 } wmi_conv_service_ids;
 #define WMI_SERVICE_UNAVAILABLE 0xFFFF
diff --git a/wmi/inc/wmi_unified_priv.h b/wmi/inc/wmi_unified_priv.h
index 3ac2732..5fd5ee2 100644
--- a/wmi/inc/wmi_unified_priv.h
+++ b/wmi/inc/wmi_unified_priv.h
@@ -333,12 +333,15 @@
 (*send_pdev_utf_cmd)(wmi_unified_t wmi_handle,
 				struct pdev_utf_params *param,
 				uint8_t mac_id);
-
 QDF_STATUS
 (*send_pdev_param_cmd)(wmi_unified_t wmi_handle,
 			   struct pdev_params *param,
 				uint8_t mac_id);
 
+QDF_STATUS
+(*send_pdev_set_hw_mode_cmd)(wmi_unified_t wmi_handle,
+			     uint32_t hw_mode_index);
+
 QDF_STATUS (*send_suspend_cmd)(wmi_unified_t wmi_handle,
 				struct suspend_params *param,
 				uint8_t mac_id);
@@ -874,9 +877,6 @@
 QDF_STATUS (*send_pdev_set_pcl_cmd)(wmi_unified_t wmi_handle,
 				struct wmi_pcl_chan_weights *msg);
 
-QDF_STATUS (*send_pdev_set_hw_mode_cmd)(wmi_unified_t wmi_handle,
-				uint32_t hw_mode_index);
-
 #ifdef WLAN_POLICY_MGR_ENABLE
 QDF_STATUS (*send_pdev_set_dual_mac_config_cmd)(wmi_unified_t wmi_handle,
 		struct policy_mgr_dual_mac_config *msg);
@@ -1992,6 +1992,10 @@
 		(wmi_unified_t wmi_hdl, void *resp_buf,
 		 struct wmi_oem_response_param *oem_resp_param);
 #endif /* WIFI_POS_CONVERGED */
+
+QDF_STATUS (*extract_hw_mode_resp_event)(wmi_unified_t wmi_handle,
+					 void *evt_buf, uint32_t *cmd_status);
+
 };
 
 /* Forward declartion for psoc*/
diff --git a/wmi/inc/wmi_unified_sta_api.h b/wmi/inc/wmi_unified_sta_api.h
index 13e8fcb..458fe59 100644
--- a/wmi/inc/wmi_unified_sta_api.h
+++ b/wmi/inc/wmi_unified_sta_api.h
@@ -406,21 +406,6 @@
 QDF_STATUS wmi_unified_pdev_set_pcl_cmd(wmi_unified_t wmi_handle,
 					struct wmi_pcl_chan_weights *msg);
 
-/**
- * wmi_unified_soc_set_hw_mode_cmd() - Send WMI_SOC_SET_HW_MODE_CMDID to FW
- * @wmi_handle: wmi handle
- * hw_mode_index: The HW_Mode field is a enumerated type that is selected
- * from the HW_Mode table, which is returned in the WMI_SERVICE_READY_EVENTID.
- *
- * Provides notification to the WLAN firmware that host driver is requesting a
- * HardWare (HW) Mode change. This command is needed to support iHelium in the
- * configurations that include the Dual Band Simultaneous (DBS) feature.
- *
- * Return: QDF_STATUS_SUCCESS on success and QDF_STATUS_E_FAILURE for failure
- */
-QDF_STATUS wmi_unified_soc_set_hw_mode_cmd(wmi_unified_t wmi_handle,
-					   uint32_t hw_mode_index);
-
 #ifdef WLAN_POLICY_MGR_ENABLE
 /**
  * wmi_unified_pdev_set_dual_mac_config_cmd() - Set dual mac config to FW
diff --git a/wmi/src/wmi_unified_api.c b/wmi/src/wmi_unified_api.c
index 899567c..8ecbde9 100644
--- a/wmi/src/wmi_unified_api.c
+++ b/wmi/src/wmi_unified_api.c
@@ -54,6 +54,17 @@
 #endif
 };
 
+QDF_STATUS wmi_unified_soc_set_hw_mode_cmd(wmi_unified_t wmi_handle,
+					   uint32_t hw_mode_index)
+{
+	if (wmi_handle->ops->send_pdev_set_hw_mode_cmd)
+		return wmi_handle->ops->send_pdev_set_hw_mode_cmd(
+								wmi_handle,
+								hw_mode_index);
+
+	return QDF_STATUS_E_FAILURE;
+}
+
 QDF_STATUS wmi_unified_vdev_create_send(wmi_unified_t wmi_handle,
 					uint8_t macaddr[QDF_MAC_ADDR_SIZE],
 					struct vdev_create_params *param)
@@ -2896,3 +2907,15 @@
 	return QDF_STATUS_E_FAILURE;
 }
 #endif /* WIFI_POS_CONVERGED */
+
+QDF_STATUS wmi_unified_extract_hw_mode_resp(wmi_unified_t wmi,
+					    void *evt_buf,
+					    uint32_t *cmd_status)
+{
+	if (wmi->ops->extract_hw_mode_resp_event)
+		return wmi->ops->extract_hw_mode_resp_event(wmi,
+							    evt_buf,
+							    cmd_status);
+
+	return QDF_STATUS_E_FAILURE;
+}
diff --git a/wmi/src/wmi_unified_sta_api.c b/wmi/src/wmi_unified_sta_api.c
index b3d3e55..aaccd46 100644
--- a/wmi/src/wmi_unified_sta_api.c
+++ b/wmi/src/wmi_unified_sta_api.c
@@ -370,16 +370,6 @@
 	return QDF_STATUS_E_FAILURE;
 }
 
-QDF_STATUS wmi_unified_soc_set_hw_mode_cmd(wmi_unified_t wmi_handle,
-					   uint32_t hw_mode_index)
-{
-	if (wmi_handle->ops->send_pdev_set_hw_mode_cmd)
-		return wmi_handle->ops->send_pdev_set_hw_mode_cmd(wmi_handle,
-				  hw_mode_index);
-
-	return QDF_STATUS_E_FAILURE;
-}
-
 #ifdef WLAN_POLICY_MGR_ENABLE
 QDF_STATUS wmi_unified_pdev_set_dual_mac_config_cmd(
 		wmi_unified_t wmi_handle,
diff --git a/wmi/src/wmi_unified_sta_tlv.c b/wmi/src/wmi_unified_sta_tlv.c
index dfcfbc0..bb75b67 100644
--- a/wmi/src/wmi_unified_sta_tlv.c
+++ b/wmi/src/wmi_unified_sta_tlv.c
@@ -2099,56 +2099,6 @@
 	return QDF_STATUS_SUCCESS;
 }
 
-/**
- * send_pdev_set_hw_mode_cmd_tlv() - Send WMI_PDEV_SET_HW_MODE_CMDID to FW
- * @wmi_handle: wmi handle
- * @msg: Structure containing the following parameters
- *
- * - hw_mode_index: The HW_Mode field is a enumerated type that is selected
- * from the HW_Mode table, which is returned in the WMI_SERVICE_READY_EVENTID.
- *
- * Provides notification to the WLAN firmware that host driver is requesting a
- * HardWare (HW) Mode change. This command is needed to support iHelium in the
- * configurations that include the Dual Band Simultaneous (DBS) feature.
- *
- * Return: Success if the cmd is sent successfully to the firmware
- */
-static QDF_STATUS send_pdev_set_hw_mode_cmd_tlv(wmi_unified_t wmi_handle,
-						uint32_t hw_mode_index)
-{
-	wmi_pdev_set_hw_mode_cmd_fixed_param *cmd;
-	wmi_buf_t buf;
-	uint32_t len;
-
-	len = sizeof(*cmd);
-
-	buf = wmi_buf_alloc(wmi_handle, len);
-	if (!buf) {
-		return QDF_STATUS_E_NOMEM;
-	}
-
-	cmd = (wmi_pdev_set_hw_mode_cmd_fixed_param *) wmi_buf_data(buf);
-	WMITLV_SET_HDR(&cmd->tlv_header,
-		WMITLV_TAG_STRUC_wmi_pdev_set_hw_mode_cmd_fixed_param,
-		WMITLV_GET_STRUCT_TLVLEN(wmi_pdev_set_hw_mode_cmd_fixed_param));
-
-	cmd->pdev_id = wmi_handle->ops->convert_pdev_id_host_to_target(
-							WMI_HOST_PDEV_ID_SOC);
-	cmd->hw_mode_index = hw_mode_index;
-	WMI_LOGI("%s: HW mode index:%d", __func__, cmd->hw_mode_index);
-
-	wmi_mtrace(WMI_PDEV_SET_HW_MODE_CMDID, NO_SESSION, 0);
-	if (wmi_unified_cmd_send(wmi_handle, buf, len,
-				 WMI_PDEV_SET_HW_MODE_CMDID)) {
-		WMI_LOGE("%s: Failed to send WMI_PDEV_SET_HW_MODE_CMDID",
-			 __func__);
-		wmi_buf_free(buf);
-		return QDF_STATUS_E_FAILURE;
-	}
-
-	return QDF_STATUS_SUCCESS;
-}
-
 #ifdef WLAN_POLICY_MGR_ENABLE
 /**
  * send_pdev_set_dual_mac_config_cmd_tlv() - Set dual mac config to FW
@@ -2587,7 +2537,6 @@
 	ops->send_process_ch_avoid_update_cmd =
 		send_process_ch_avoid_update_cmd_tlv;
 	ops->send_pdev_set_pcl_cmd = send_pdev_set_pcl_cmd_tlv;
-	ops->send_pdev_set_hw_mode_cmd = send_pdev_set_hw_mode_cmd_tlv;
 	ops->send_adapt_dwelltime_params_cmd =
 		send_adapt_dwelltime_params_cmd_tlv;
 	ops->send_dbs_scan_sel_params_cmd =
diff --git a/wmi/src/wmi_unified_tlv.c b/wmi/src/wmi_unified_tlv.c
index d12d82c..f2c5f42 100644
--- a/wmi/src/wmi_unified_tlv.c
+++ b/wmi/src/wmi_unified_tlv.c
@@ -1604,6 +1604,55 @@
 }
 
 /**
+ * send_pdev_set_hw_mode_cmd_tlv() - Send WMI_PDEV_SET_HW_MODE_CMDID to FW
+ * @wmi_handle: wmi handle
+ * @msg: Structure containing the following parameters
+ * @hw_mode_index: The HW_Mode field is a enumerated type that is selected
+ * from the HW_Mode table, which is returned in the WMI_SERVICE_READY_EVENTID.
+ *
+ * Provides notification to the WLAN firmware that host driver is requesting a
+ * HardWare (HW) Mode change. This command is needed to support iHelium in the
+ * configurations that include the Dual Band Simultaneous (DBS) feature.
+ *
+ * Return: Success if the cmd is sent successfully to the firmware
+ */
+static QDF_STATUS send_pdev_set_hw_mode_cmd_tlv(wmi_unified_t wmi_handle,
+						uint32_t hw_mode_index)
+{
+	wmi_pdev_set_hw_mode_cmd_fixed_param *cmd;
+	wmi_buf_t buf;
+	uint32_t len;
+
+	len = sizeof(*cmd);
+
+	buf = wmi_buf_alloc(wmi_handle, len);
+	if (!buf)
+		return QDF_STATUS_E_NOMEM;
+
+	cmd = (wmi_pdev_set_hw_mode_cmd_fixed_param *)wmi_buf_data(buf);
+	WMITLV_SET_HDR(&cmd->tlv_header,
+		       WMITLV_TAG_STRUC_wmi_pdev_set_hw_mode_cmd_fixed_param,
+		       WMITLV_GET_STRUCT_TLVLEN(
+				wmi_pdev_set_hw_mode_cmd_fixed_param));
+
+	cmd->pdev_id = wmi_handle->ops->convert_pdev_id_host_to_target(
+							WMI_HOST_PDEV_ID_SOC);
+	cmd->hw_mode_index = hw_mode_index;
+	WMI_LOGI("%s: HW mode index:%d", __func__, cmd->hw_mode_index);
+
+	wmi_mtrace(WMI_PDEV_SET_HW_MODE_CMDID, NO_SESSION, 0);
+	if (wmi_unified_cmd_send(wmi_handle, buf, len,
+				 WMI_PDEV_SET_HW_MODE_CMDID)) {
+		WMI_LOGE("%s: Failed to send WMI_PDEV_SET_HW_MODE_CMDID",
+			 __func__);
+		wmi_buf_free(buf);
+		return QDF_STATUS_E_FAILURE;
+	}
+
+	return QDF_STATUS_SUCCESS;
+}
+
+/**
  * send_suspend_cmd_tlv() - WMI suspend function
  * @param wmi_handle      : handle to WMI.
  * @param param    : pointer to hold suspend parameter
@@ -9759,6 +9808,12 @@
 				sizeof(param->he_ppet5G));
 	param->chainmask_table_id = mac_phy_caps->chainmask_table_id;
 	param->lmac_id = mac_phy_caps->lmac_id;
+	param->reg_cap_ext.wireless_modes = convert_wireless_modes_tlv
+						(mac_phy_caps->wireless_modes);
+	param->reg_cap_ext.low_2ghz_chan  = mac_phy_caps->low_2ghz_chan_freq;
+	param->reg_cap_ext.high_2ghz_chan = mac_phy_caps->high_2ghz_chan_freq;
+	param->reg_cap_ext.low_5ghz_chan  = mac_phy_caps->low_5ghz_chan_freq;
+	param->reg_cap_ext.high_5ghz_chan = mac_phy_caps->high_5ghz_chan_freq;
 
 	return QDF_STATUS_SUCCESS;
 }
@@ -11676,6 +11731,37 @@
 }
 #endif /* WIFI_POS_CONVERGED */
 
+/**
+ * extract_hw_mode_resp_event_status_tlv() - Extract HW mode change status
+ * @wmi_handle: wmi handle
+ * @event_buf: pointer to event buffer
+ * @cmd_status: status of HW mode change command
+ *
+ * Return QDF_STATUS_SUCCESS on success or proper error code.
+ */
+static QDF_STATUS
+extract_hw_mode_resp_event_status_tlv(wmi_unified_t wmi_handle, void *evt_buf,
+				      uint32_t *cmd_status)
+{
+	WMI_PDEV_SET_HW_MODE_RESP_EVENTID_param_tlvs *param_buf;
+	wmi_pdev_set_hw_mode_response_event_fixed_param *fixed_param;
+
+	param_buf = (WMI_PDEV_SET_HW_MODE_RESP_EVENTID_param_tlvs *)evt_buf;
+	if (!param_buf) {
+		WMI_LOGE("Invalid mode change event buffer");
+		return QDF_STATUS_E_INVAL;
+	}
+
+	fixed_param = param_buf->fixed_param;
+	if (!fixed_param) {
+		WMI_LOGE("Invalid fixed param");
+		return QDF_STATUS_E_INVAL;
+	}
+
+	*cmd_status = fixed_param->status;
+	return QDF_STATUS_SUCCESS;
+}
+
 struct wmi_ops tlv_ops =  {
 	.send_vdev_create_cmd = send_vdev_create_cmd_tlv,
 	.send_vdev_delete_cmd = send_vdev_delete_cmd_tlv,
@@ -11697,6 +11783,7 @@
 		send_peer_rx_reorder_queue_remove_cmd_tlv,
 	.send_pdev_utf_cmd = send_pdev_utf_cmd_tlv,
 	.send_pdev_param_cmd = send_pdev_param_cmd_tlv,
+	.send_pdev_set_hw_mode_cmd = send_pdev_set_hw_mode_cmd_tlv,
 	.send_suspend_cmd = send_suspend_cmd_tlv,
 	.send_resume_cmd = send_resume_cmd_tlv,
 	.send_wow_enable_cmd = send_wow_enable_cmd_tlv,
@@ -11956,6 +12043,7 @@
 #ifdef TGT_IF_VDEV_MGR_CONV
 	.extract_vdev_delete_resp = extract_vdev_delete_resp_tlv,
 #endif
+	.extract_hw_mode_resp_event = extract_hw_mode_resp_event_status_tlv,
 };
 
 /**