qcacmn: Re-factor processing of WMI_REG_CHAN_LIST_CC_EVENTID

Due to different layers, TLV processing is confined to WMI folder.
Therefore, move the TLV layer processing of WMI_REG_CHAN_LIST_EVENTID
to the wmi folder.

Change-Id: I7e7182997a9506035030f33d2f81a403fbe97a2f
CR-Fixed: 2019750
diff --git a/target_if/regulatory/src/target_if_reg.c b/target_if/regulatory/src/target_if_reg.c
index 3fab352..c2af914 100644
--- a/target_if/regulatory/src/target_if_reg.c
+++ b/target_if/regulatory/src/target_if_reg.c
@@ -24,116 +24,75 @@
 
 
 #include <wmi_unified_api.h>
-#include <wmi.h>
-#include <osdep.h>
 #include <reg_services_public_struct.h>
 #include <wlan_reg_tgt_api.h>
 #include <target_if.h>
 #include <target_if_reg.h>
+#include <wmi_unified_reg_api.h>
 
-static struct cur_reg_rule
-*create_reg_rules_from_wmi(uint32_t num_reg_rules,
-			   wmi_regulatory_rule_struct *wmi_reg_rule)
+#ifdef CONFIG_MCL
+static inline uint32_t get_chan_list_cc_event_id(void)
 {
-	struct cur_reg_rule *reg_rule_ptr;
-	uint32_t count;
+	return WMI_REG_CHAN_LIST_CC_EVENTID;
+}
+#else
+static inline uint32_t get_chan_list_cc_event_id(void)
+{
+	return wmi_reg_chan_list_cc_event_id;
+}
+#endif
 
-	reg_rule_ptr = qdf_mem_malloc(num_reg_rules * sizeof(*reg_rule_ptr));
-
-	if (NULL == reg_rule_ptr) {
-		target_if_err("memory allocation failure");
-		return NULL;
-	}
-
-	for (count = 0; count < num_reg_rules; count++) {
-		reg_rule_ptr[count].start_freq =
-			WMI_REG_RULE_START_FREQ_GET(
-				wmi_reg_rule[count].freq_info);
-		reg_rule_ptr[count].end_freq =
-			WMI_REG_RULE_END_FREQ_GET(
-				wmi_reg_rule[count].freq_info);
-		reg_rule_ptr[count].max_bw =
-			WMI_REG_RULE_MAX_BW_GET(
-				wmi_reg_rule[count].bw_info);
-		reg_rule_ptr[count].reg_power =
-			WMI_REG_RULE_REG_POWER_GET(
-				wmi_reg_rule[count].bw_info);
-		reg_rule_ptr[count].flags =
-			WMI_REG_RULE_FLAGS_GET(
-				wmi_reg_rule[count].power_flag_info);
-	}
-
-	return reg_rule_ptr;
+static inline struct wlan_lmac_if_reg_rx_ops *
+target_if_regulatory_get_rx_ops(struct wlan_objmgr_psoc *psoc)
+{
+	return &psoc->soc_cb.rx_ops.reg_rx_ops;
 }
 
-
-/**
- * reg_chan_list_update_handler() - function to update channel list
- * @handle: wma handle
- * @event_buf: event buffer
- * @len: length of buffer
- *
- * Return: 0 for success or error code
- */
-static int reg_chan_list_update_handler(ol_scn_t handle, uint8_t *event_buf,
-				 uint32_t len)
+static int tgt_reg_chan_list_update_handler(ol_scn_t handle,
+					    uint8_t *event_buf,
+					    uint32_t len)
 {
-	WMI_REG_CHAN_LIST_CC_EVENTID_param_tlvs *param_buf;
-	struct cur_regulatory_info *reg_info;
-	wmi_reg_chan_list_cc_event_fixed_param *chan_list_event_hdr;
-	wmi_regulatory_rule_struct *wmi_reg_rule;
-	uint32_t num_2g_reg_rules, num_5g_reg_rules;
 	struct wlan_objmgr_psoc *psoc;
+	struct wlan_lmac_if_reg_rx_ops *reg_rx_ops;
+	struct cur_regulatory_info *reg_info;
 	QDF_STATUS status;
 
-	target_if_info("processing regulatory channel list");
+	TARGET_IF_ENTER();
 
-	param_buf = (WMI_REG_CHAN_LIST_CC_EVENTID_param_tlvs *)event_buf;
-	if (!param_buf) {
-		target_if_err("invalid channel list event buf");
+	psoc = target_if_get_psoc_from_scn_hdl(handle);
+	if (!psoc) {
+		target_if_err("psoc ptr is NULL");
 		return -EINVAL;
 	}
 
-	chan_list_event_hdr = param_buf->fixed_param;
+	reg_rx_ops = target_if_regulatory_get_rx_ops(psoc);
+	if (!reg_rx_ops->master_list_handler) {
+		target_if_err("master_list_handler is NULL");
+		return -EINVAL;
+	}
 
 	reg_info = qdf_mem_malloc(sizeof(*reg_info));
-
-	if (NULL == reg_info) {
-		target_if_err("memory allocation failure");
+	if (!reg_info) {
+		target_if_err("memory allocation failed");
 		return -ENOMEM;
 	}
 
-	psoc = target_if_get_psoc_from_scn_hdl(handle);
+	if (wmi_extract_reg_chan_list_update_event(GET_WMI_HDL_FROM_PSOC(psoc),
+						   event_buf, reg_info, len)
+	    != QDF_STATUS_SUCCESS) {
+
+		target_if_err("Extraction of channel list event failed");
+		qdf_mem_free(reg_info->reg_rules_2g_ptr);
+		qdf_mem_free(reg_info->reg_rules_5g_ptr);
+		qdf_mem_free(reg_info);
+		return -EFAULT;
+	}
 
 	reg_info->psoc = psoc;
-	reg_info->num_2g_reg_rules = chan_list_event_hdr->num_2g_reg_rules;
-	reg_info->num_5g_reg_rules = chan_list_event_hdr->num_5g_reg_rules;
-	qdf_mem_copy(reg_info->alpha2, &(chan_list_event_hdr->alpha2),
-		     REG_ALPHA2_LEN);
-	reg_info->dfs_region = chan_list_event_hdr->dfs_region;
-	reg_info->phybitmap = chan_list_event_hdr->phybitmap;
-	reg_info->min_bw_2g = chan_list_event_hdr->min_bw_2g;
-	reg_info->max_bw_2g = chan_list_event_hdr->max_bw_2g;
-	reg_info->min_bw_5g = chan_list_event_hdr->min_bw_5g;
-	reg_info->max_bw_5g = chan_list_event_hdr->max_bw_5g;
 
-	num_2g_reg_rules = reg_info->num_2g_reg_rules;
-	num_5g_reg_rules = reg_info->num_5g_reg_rules;
-
-	wmi_reg_rule = (wmi_regulatory_rule_struct *)(chan_list_event_hdr
-			    + sizeof(wmi_reg_chan_list_cc_event_fixed_param));
-
-	reg_info->reg_rules_2g_ptr = create_reg_rules_from_wmi(num_2g_reg_rules,
-							       wmi_reg_rule);
-	wmi_reg_rule += num_2g_reg_rules;
-
-	reg_info->reg_rules_5g_ptr = create_reg_rules_from_wmi(num_5g_reg_rules,
-							       wmi_reg_rule);
-
-	status = psoc->soc_cb.rx_ops.reg_rx_ops.master_list_handler(reg_info);
-
+	status = reg_rx_ops->master_list_handler(reg_info);
 	if (status != QDF_STATUS_SUCCESS) {
-		target_if_err("component could not process regulatory message");
+		target_if_err("Failed to process master channel list handler");
 		qdf_mem_free(reg_info->reg_rules_2g_ptr);
 		qdf_mem_free(reg_info->reg_rules_5g_ptr);
 		qdf_mem_free(reg_info);
@@ -149,16 +108,15 @@
 	return 0;
 }
 
-
 static QDF_STATUS tgt_if_regulatory_register_master_list_handler(
 	struct wlan_objmgr_psoc *psoc, void *arg)
 {
 	wmi_unified_t wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
 
 	return wmi_unified_register_event_handler(wmi_handle,
-						  WMI_REG_CHAN_LIST_CC_EVENTID,
-						  reg_chan_list_update_handler,
-						  WMI_RX_UMAC_CTX);
+					       get_chan_list_cc_event_id(),
+					       tgt_reg_chan_list_update_handler,
+					       WMI_RX_UMAC_CTX);
 
 }
 
@@ -168,8 +126,7 @@
 	wmi_unified_t wmi_handle = GET_WMI_HDL_FROM_PSOC(psoc);
 
 	return wmi_unified_unregister_event_handler(wmi_handle,
-					    WMI_REG_CHAN_LIST_CC_EVENTID);
-
+					       get_chan_list_cc_event_id());
 }
 
 QDF_STATUS target_if_register_regulatory_tx_ops(struct wlan_lmac_if_tx_ops
diff --git a/wmi/inc/wmi_unified_param.h b/wmi/inc/wmi_unified_param.h
index 728bde2..0d7e0b1 100644
--- a/wmi/inc/wmi_unified_param.h
+++ b/wmi/inc/wmi_unified_param.h
@@ -5085,6 +5085,7 @@
 	wmi_atf_peer_stats_event_id,
 	wmi_peer_delete_response_event_id,
 	wmi_pdev_csa_switch_count_status_event_id,
+	wmi_reg_chan_list_cc_event_id,
 
 	wmi_events_max,
 } wmi_conv_event_id;
diff --git a/wmi/inc/wmi_unified_priv.h b/wmi/inc/wmi_unified_priv.h
index 112fceb..c1e0a89 100644
--- a/wmi/inc/wmi_unified_priv.h
+++ b/wmi/inc/wmi_unified_priv.h
@@ -1275,6 +1275,11 @@
 		uint32_t pdev_id);
 QDF_STATUS (*send_dfs_phyerr_offload_dis_cmd)(wmi_unified_t wmi_handle,
 		uint32_t pdev_id);
+QDF_STATUS (*extract_reg_chan_list_update_event)(wmi_unified_t wmi_handle,
+						 uint8_t *evt_buf,
+						 struct cur_regulatory_info
+						 *reg_info,
+						 uint32_t len);
 };
 
 struct target_abi_version {
diff --git a/wmi/inc/wmi_unified_reg_api.h b/wmi/inc/wmi_unified_reg_api.h
new file mode 100644
index 0000000..e986536
--- /dev/null
+++ b/wmi/inc/wmi_unified_reg_api.h
@@ -0,0 +1,40 @@
+/*
+ * Copyright (c) 2017 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: This file contains the API definitions for the Unified Wireless Module
+ * Interface (WMI) which are specific to Regulatory module.
+ */
+
+#ifndef _WMI_UNIFIED_REG_API_H_
+#define _WMI_UNIFIED_REG_API_H_
+
+#include "reg_services_public_struct.h"
+/**
+ * reg_chan_list_update_handler() - function to update channel list
+ * @handle: wma handle
+ * @event_buf: event buffer
+ * @len: length of buffer
+ *
+ * Return: 0 for success or error code
+ */
+QDF_STATUS wmi_extract_reg_chan_list_update_event(void *wmi_hdl,
+						  uint8_t *evt_buf,
+						  struct cur_regulatory_info
+						  *reg_info,
+						  uint32_t len);
+#endif /* _WMI_UNIFIED_REG_API_H_ */
diff --git a/wmi/src/wmi_unified_reg_api.c b/wmi/src/wmi_unified_reg_api.c
new file mode 100644
index 0000000..b10f5bc
--- /dev/null
+++ b/wmi/src/wmi_unified_reg_api.c
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2017 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: Implement API's specific to Regulatory component.
+ */
+
+#include <qdf_status.h>
+#include <wmi_unified_api.h>
+#include <wmi_unified_priv.h>
+#include <wmi_unified_reg_api.h>
+
+QDF_STATUS wmi_extract_reg_chan_list_update_event(void *wmi_hdl,
+						  uint8_t *evt_buf,
+						  struct cur_regulatory_info
+						  *reg_info,
+						  uint32_t len)
+{
+	struct wmi_unified *wmi_handle = (struct wmi_unified *)wmi_hdl;
+
+	if (wmi_handle->ops->extract_reg_chan_list_update_event)
+		return wmi_handle->ops->extract_reg_chan_list_update_event
+			(wmi_handle,
+			 evt_buf, reg_info, len);
+
+	return QDF_STATUS_E_FAILURE;
+}
diff --git a/wmi/src/wmi_unified_tlv.c b/wmi/src/wmi_unified_tlv.c
index ee78dc5..77832ca 100644
--- a/wmi/src/wmi_unified_tlv.c
+++ b/wmi/src/wmi_unified_tlv.c
@@ -16020,6 +16020,89 @@
 	return QDF_STATUS_SUCCESS;
 }
 
+static struct cur_reg_rule
+*create_reg_rules_from_wmi(uint32_t num_reg_rules,
+		wmi_regulatory_rule_struct *wmi_reg_rule)
+{
+	struct cur_reg_rule *reg_rule_ptr;
+	uint32_t count;
+
+	reg_rule_ptr = qdf_mem_malloc(num_reg_rules * sizeof(*reg_rule_ptr));
+
+	if (NULL == reg_rule_ptr) {
+		WMI_LOGE("memory allocation failure");
+		return NULL;
+	}
+
+	for (count = 0; count < num_reg_rules; count++) {
+		reg_rule_ptr[count].start_freq =
+			WMI_REG_RULE_START_FREQ_GET(
+					wmi_reg_rule[count].freq_info);
+		reg_rule_ptr[count].end_freq =
+			WMI_REG_RULE_END_FREQ_GET(
+					wmi_reg_rule[count].freq_info);
+		reg_rule_ptr[count].max_bw =
+			WMI_REG_RULE_MAX_BW_GET(
+					wmi_reg_rule[count].bw_info);
+		reg_rule_ptr[count].reg_power =
+			WMI_REG_RULE_REG_POWER_GET(
+					wmi_reg_rule[count].bw_info);
+		reg_rule_ptr[count].flags =
+			WMI_REG_RULE_FLAGS_GET(
+					wmi_reg_rule[count].power_flag_info);
+	}
+
+	return reg_rule_ptr;
+}
+
+static QDF_STATUS extract_reg_chan_list_update_event_tlv(
+	wmi_unified_t wmi_handle, uint8_t *evt_buf,
+	struct cur_regulatory_info *reg_info, uint32_t len)
+{
+	WMI_REG_CHAN_LIST_CC_EVENTID_param_tlvs *param_buf;
+	wmi_reg_chan_list_cc_event_fixed_param *chan_list_event_hdr;
+	wmi_regulatory_rule_struct *wmi_reg_rule;
+	uint32_t num_2g_reg_rules, num_5g_reg_rules;
+
+	WMI_LOGD("processing regulatory channel list");
+
+	param_buf = (WMI_REG_CHAN_LIST_CC_EVENTID_param_tlvs *)evt_buf;
+	if (!param_buf) {
+		WMI_LOGE("invalid channel list event buf");
+		return QDF_STATUS_E_FAILURE;
+	}
+
+	chan_list_event_hdr = param_buf->fixed_param;
+
+	reg_info->num_2g_reg_rules = chan_list_event_hdr->num_2g_reg_rules;
+	reg_info->num_5g_reg_rules = chan_list_event_hdr->num_5g_reg_rules;
+	qdf_mem_copy(reg_info->alpha2, &(chan_list_event_hdr->alpha2),
+			REG_ALPHA2_LEN);
+	reg_info->dfs_region = chan_list_event_hdr->dfs_region;
+	reg_info->phybitmap = chan_list_event_hdr->phybitmap;
+	reg_info->min_bw_2g = chan_list_event_hdr->min_bw_2g;
+	reg_info->max_bw_2g = chan_list_event_hdr->max_bw_2g;
+	reg_info->min_bw_5g = chan_list_event_hdr->min_bw_5g;
+	reg_info->max_bw_5g = chan_list_event_hdr->max_bw_5g;
+
+	num_2g_reg_rules = reg_info->num_2g_reg_rules;
+	num_5g_reg_rules = reg_info->num_5g_reg_rules;
+
+	wmi_reg_rule = (wmi_regulatory_rule_struct *)(chan_list_event_hdr
+			+ sizeof(wmi_reg_chan_list_cc_event_fixed_param));
+
+	reg_info->reg_rules_2g_ptr = create_reg_rules_from_wmi(num_2g_reg_rules,
+			wmi_reg_rule);
+	wmi_reg_rule += num_2g_reg_rules;
+
+	reg_info->reg_rules_5g_ptr = create_reg_rules_from_wmi(num_5g_reg_rules,
+			wmi_reg_rule);
+
+	WMI_LOGD("processed regulatory channel list");
+
+	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,
@@ -16343,7 +16426,7 @@
 	.extract_fips_event_data = extract_fips_event_data_tlv,
 	.send_pdev_fips_cmd = send_pdev_fips_cmd_tlv,
 	.extract_peer_delete_response_event =
-				extract_peer_delete_response_event_tlv,
+	extract_peer_delete_response_event_tlv,
 	.is_management_record = is_management_record_tlv,
 	.extract_pdev_csa_switch_count_status =
 				extract_pdev_csa_switch_count_status_tlv,
@@ -16355,6 +16438,8 @@
 	.send_per_roam_config_cmd = send_per_roam_config_cmd_tlv,
 	.send_dfs_phyerr_offload_en_cmd = send_dfs_phyerr_offload_en_cmd_tlv,
 	.send_dfs_phyerr_offload_dis_cmd = send_dfs_phyerr_offload_dis_cmd_tlv,
+	.extract_reg_chan_list_update_event =
+	extract_reg_chan_list_update_event_tlv,
 };
 
 /**
@@ -16569,6 +16654,7 @@
 	event_ids[wmi_pdev_fips_event_id] = WMI_PDEV_FIPS_EVENTID;
 	event_ids[wmi_pdev_csa_switch_count_status_event_id] =
 				WMI_PDEV_CSA_SWITCH_COUNT_STATUS_EVENTID;
+	event_ids[wmi_reg_chan_list_cc_event_id] = WMI_REG_CHAN_LIST_CC_EVENTID;
 }
 
 #ifndef CONFIG_MCL