qcacmn: Make One HIF Context

Have the hif context componentized but make it one contiguous pointer.
This simplifies the design as all apis can use the same default pointer
and all members will be one load away with a precomputed offset.

Change-Id: I181c9f011a7bac02944af53188b549efeea68470
CRs-Fixed: 967765
diff --git a/hif/src/ce/ce_main.c b/hif/src/ce/ce_main.c
index 89202ed..db85368 100644
--- a/hif/src/ce/ce_main.c
+++ b/hif/src/ce/ce_main.c
@@ -1838,7 +1838,6 @@
  */
 int hif_config_ce(hif_handle_t hif_hdl)
 {
-	struct HIF_CE_state *hif_state;
 	struct HIF_CE_pipe_info *pipe_info;
 	int pipe_num;
 #ifdef ADRASTEA_SHADOW_REGISTERS
@@ -1847,6 +1846,7 @@
 	CDF_STATUS rv = CDF_STATUS_SUCCESS;
 	int ret;
 	struct ol_softc *scn = hif_hdl;
+	struct HIF_CE_state *hif_state = (struct HIF_CE_state *)scn;
 	struct icnss_soc_info soc_info;
 	struct hif_target_info *tgt_info = hif_get_target_info_handle(scn);
 
@@ -1880,12 +1880,6 @@
 		return CDF_STATUS_NOT_INITIALIZED;
 	}
 
-	hif_state = (struct HIF_CE_state *)cdf_mem_malloc(sizeof(*hif_state));
-	if (!hif_state) {
-		return -ENOMEM;
-	}
-	cdf_mem_zero(hif_state, sizeof(*hif_state));
-
 	hif_state->scn = scn;
 	scn->hif_hdl = hif_state;
 	scn->mem = soc_info.v_addr;
@@ -2016,10 +2010,8 @@
 		cdf_softirq_timer_free(&hif_state->sleep_timer);
 		hif_state->sleep_timer_init = false;
 	}
-	if (scn->hif_hdl) {
-		scn->hif_hdl = NULL;
-		cdf_mem_free(hif_state);
-	}
+
+	scn->hif_hdl = NULL;
 	athdiag_procfs_remove();
 	scn->athdiag_procfs_inited = false;
 	HIF_TRACE("%s: X, ret = %d\n", __func__, rv);
diff --git a/hif/src/ce/ce_main.h b/hif/src/ce/ce_main.h
index 4589c46..354c812 100644
--- a/hif/src/ce/ce_main.h
+++ b/hif/src/ce/ce_main.h
@@ -108,6 +108,7 @@
 };
 
 struct HIF_CE_state {
+	struct ol_softc ol_sc;
 	struct ol_softc *scn;
 	bool started;
 	struct ce_tasklet_entry tasklets[CE_COUNT_MAX];
diff --git a/hif/src/hif_main.c b/hif/src/hif_main.c
index f6d42a5..52dec6e 100644
--- a/hif/src/hif_main.c
+++ b/hif/src/hif_main.c
@@ -497,16 +497,17 @@
 	v_CONTEXT_t cds_context;
 	CDF_STATUS status = CDF_STATUS_SUCCESS;
 	struct hif_config_info *cfg;
+	int bus_context_size = hif_bus_get_context_size();
 
 	cds_context = cds_get_global_context();
 	status = cds_alloc_context(cds_context, CDF_MODULE_ID_HIF,
-				(void **)&scn, sizeof(*scn));
+				(void **)&scn, bus_context_size);
 	if (status != CDF_STATUS_SUCCESS) {
 		HIF_ERROR("%s: cannot alloc ol_sc", __func__);
 		return status;
 	}
 
-	cdf_mem_zero(scn, sizeof(*scn));
+	cdf_mem_zero(scn, bus_context_size);
 	scn->cdf_dev = cdf_ctx;
 	cfg = hif_get_ini_handle(scn);
 	cfg->max_no_of_peers = 1;
diff --git a/hif/src/hif_main.h b/hif/src/hif_main.h
index 9544ef8..c357c8e 100644
--- a/hif/src/hif_main.h
+++ b/hif/src/hif_main.h
@@ -132,5 +132,5 @@
 	void *bdev, const hif_bus_id *bid, enum hif_enable_type type);
 void hif_disable_bus(void *bdev);
 void hif_bus_prevent_linkdown(struct ol_softc *scn, bool flag);
-
+int hif_bus_get_context_size(void);
 #endif /* __HIF_MAIN_H__ */
diff --git a/hif/src/pcie/if_pci.c b/hif/src/pcie/if_pci.c
index 2241313..de4b74a 100644
--- a/hif/src/pcie/if_pci.c
+++ b/hif/src/pcie/if_pci.c
@@ -1184,6 +1184,16 @@
 
 #define ATH_PCI_PROBE_RETRY_MAX 3
 /**
+ * hif_bus_get_context_size - API to return size of the bus specific structure
+ *
+ * Return: sizeof of hif_pci_softc
+ */
+int hif_bus_get_context_size(void)
+{
+	return sizeof(struct hif_pci_softc);
+}
+
+/**
  * hif_bus_open(): hif_bus_open
  * @scn: scn
  * @bus_type: bus type
@@ -1192,13 +1202,8 @@
  */
 CDF_STATUS hif_bus_open(struct ol_softc *ol_sc, enum ath_hal_bus_type bus_type)
 {
-	struct hif_pci_softc *sc;
+	struct hif_pci_softc *sc = (struct hif_pci_softc *)ol_sc;
 
-	sc = cdf_mem_malloc(sizeof(*sc));
-	if (!sc) {
-		HIF_ERROR("%s: no mem", __func__);
-		return CDF_STATUS_E_NOMEM;
-	}
 	ol_sc->hif_sc = (void *)sc;
 	sc->ol_sc = ol_sc;
 	ol_sc->bus_type = bus_type;
@@ -1227,7 +1232,6 @@
 		return;
 
 	hif_pm_runtime_close(sc);
-	cdf_mem_free(sc);
 	ol_sc->hif_sc = NULL;
 }
 
diff --git a/hif/src/pcie/if_pci.h b/hif/src/pcie/if_pci.h
index 0c05cdd..849d06f 100644
--- a/hif/src/pcie/if_pci.h
+++ b/hif/src/pcie/if_pci.h
@@ -39,9 +39,7 @@
 #include "osapi_linux.h"
 #include "hif.h"
 #include "cepci.h"
-
-struct CE_state;
-struct ol_softc;
+#include "ce_main.h"
 
 /* An address (e.g. of a buffer) in Copy Engine space. */
 
@@ -113,6 +111,7 @@
 };
 
 struct hif_pci_softc {
+	struct HIF_CE_state ce_sc;
 	void __iomem *mem;      /* PCI address. */
 	/* For efficiency, should be first in struct */
 
diff --git a/hif/src/snoc/if_snoc.c b/hif/src/snoc/if_snoc.c
index 6d46dfa..e739a00 100644
--- a/hif/src/snoc/if_snoc.c
+++ b/hif/src/snoc/if_snoc.c
@@ -188,6 +188,15 @@
 }
 
 /**
+ * hif_bus_get_context_size - API to get Bus Context Size
+ *
+ * Return: Sizeof HIF_CE_state
+ */
+int hif_bus_get_context_size(void)
+{
+	return sizeof(struct HIF_CE_state);
+}
+/**
  * hif_bus_open(): hif_bus_open
  * @scn: scn
  * @bus_type: bus type