Преглед на файлове

qcacmn: Use statically allocated memory for a few DFS structures

Change a few memory allocations of the DFS module from dynamic to
statically allocated memory from .bss segment to avoid any possible
runtime memory allocation failure because of the requested contiguous
memory of a large size.

The static allocation will not work for Multiple RADIO based boards as
it will use the same memory for all the radios.

Change-Id: I93b30a0a3f2f7d91466c930c12e9fae60699605a
CRs-Fixed: 2302097
Arif Hussain преди 6 години
родител
ревизия
0dd995fb96
променени са 2 файла, в които са добавени 161 реда и са изтрити 24 реда
  1. 83 8
      umac/dfs/core/src/misc/dfs.c
  2. 78 16
      umac/dfs/core/src/misc/dfs_filter_init.c

+ 83 - 8
umac/dfs/core/src/misc/dfs.c

@@ -33,6 +33,74 @@
 #include "../dfs_etsi_precac.h"
 #include "../dfs_partial_offload_radar.h"
 
+#ifndef WLAN_DFS_STATIC_MEM_ALLOC
+/*
+ * dfs_alloc_wlan_dfs() - allocate wlan_dfs buffer
+ *
+ * Return: buffer, null on failure.
+ */
+static inline struct wlan_dfs *dfs_alloc_wlan_dfs(void)
+{
+	return qdf_mem_malloc(sizeof(struct wlan_dfs));
+}
+
+/*
+ * dfs_free_wlan_dfs() - Free wlan_dfs buffer
+ * @dfs: wlan_dfs buffer pointer
+ *
+ * Return: None
+ */
+static inline void dfs_free_wlan_dfs(struct wlan_dfs *dfs)
+{
+	qdf_mem_free(dfs);
+}
+
+/*
+ * dfs_alloc_dfs_curchan() - allocate dfs_channel buffer
+ *
+ * Return: buffer, null on failure.
+ */
+static inline struct dfs_channel *dfs_alloc_dfs_curchan(void)
+{
+	return qdf_mem_malloc(sizeof(struct dfs_channel));
+}
+
+/*
+ * dfs_free_dfs_curchan() - Free dfs_channel buffer
+ * @dfs_curchan: dfs_channel buffer pointer
+ *
+ * Return: None
+ */
+static inline void dfs_free_dfs_curchan(struct dfs_channel *dfs_curchan)
+{
+	qdf_mem_free(dfs_curchan);
+}
+
+#else
+
+/* Static buffers for DFS objects */
+static struct wlan_dfs global_dfs;
+static struct dfs_channel global_dfs_curchan;
+
+static inline struct wlan_dfs *dfs_alloc_wlan_dfs(void)
+{
+	return &global_dfs;
+}
+
+static inline void dfs_free_wlan_dfs(struct wlan_dfs *dfs)
+{
+}
+
+static inline struct dfs_channel *dfs_alloc_dfs_curchan(void)
+{
+	return &global_dfs_curchan;
+}
+
+static inline void dfs_free_dfs_curchan(struct dfs_channel *dfs_curchan)
+{
+}
+#endif
+
 /**
  * dfs_testtimer_task() - Sends CSA in the current channel.
  *
@@ -78,19 +146,20 @@ void dfs_main_task_testtimer_init(struct wlan_dfs *dfs)
 
 int dfs_create_object(struct wlan_dfs **dfs)
 {
-	*dfs = (struct wlan_dfs *)qdf_mem_malloc(sizeof(**dfs));
+	*dfs = dfs_alloc_wlan_dfs();
 	if (!(*dfs)) {
-		dfs_alert(*dfs, WLAN_DEBUG_DFS_ALWAYS, "wlan_dfs allocation failed");
+		dfs_alert(NULL, WLAN_DEBUG_DFS_ALWAYS,
+			  "wlan_dfs allocation failed");
 		return 1;
 	}
 
 	qdf_mem_zero(*dfs, sizeof(**dfs));
 
-	(*dfs)->dfs_curchan = (struct dfs_channel *)qdf_mem_malloc(
-			sizeof(struct dfs_channel));
-
+	(*dfs)->dfs_curchan = dfs_alloc_dfs_curchan();
 	if (!((*dfs)->dfs_curchan)) {
-		dfs_alert(*dfs, WLAN_DEBUG_DFS_ALWAYS, "dfs_curchan allocation failed");
+		dfs_free_wlan_dfs(*dfs);
+		dfs_alert(*dfs, WLAN_DEBUG_DFS_ALWAYS,
+			  "dfs_curchan allocation failed");
 		return 1;
 	}
 
@@ -193,11 +262,17 @@ void dfs_detach(struct wlan_dfs *dfs)
 	dfs_nol_detach(dfs);
 }
 
+#ifndef WLAN_DFS_STATIC_MEM_ALLOC
+void dfs_destroy_object(struct wlan_dfs *dfs)
+{
+	dfs_free_dfs_curchan(dfs->dfs_curchan);
+	dfs_free_wlan_dfs(dfs);
+}
+#else
 void dfs_destroy_object(struct wlan_dfs *dfs)
 {
-	qdf_mem_free(dfs->dfs_curchan);
-	qdf_mem_free(dfs);
 }
+#endif
 
 int dfs_control(struct wlan_dfs *dfs,
 		u_int id,

+ 78 - 16
umac/dfs/core/src/misc/dfs_filter_init.c

@@ -30,6 +30,72 @@
 #include "../dfs_filter_init.h"
 #include "../dfs_partial_offload_radar.h"
 
+#ifndef WLAN_DFS_STATIC_MEM_ALLOC
+/*
+ * dfs_alloc_dfs_events() - allocate dfs events buffer
+ *
+ * Return: events buffer, null on failure.
+ */
+static inline struct dfs_event *dfs_alloc_dfs_events(void)
+{
+	return qdf_mem_malloc(sizeof(struct dfs_event) * DFS_MAX_EVENTS);
+}
+
+/*
+ * dfs_free_dfs_events() - Free events buffer
+ * @events: Events buffer pointer
+ *
+ * Return: None
+ */
+static inline void dfs_free_dfs_events(struct dfs_event *events)
+{
+	qdf_mem_free(events);
+}
+
+/*
+ * dfs_alloc_dfs_pulseline() - allocate buffer for dfs pulses
+ *
+ * Return: events buffer, null on failure.
+ */
+static inline struct dfs_pulseline *dfs_alloc_dfs_pulseline(void)
+{
+	return qdf_mem_malloc(sizeof(struct dfs_pulseline));
+}
+
+/*
+ * dfs_free_dfs_pulseline() - Free pulse buffer
+ * @pulses: Pulses buffer pointer
+ *
+ * Return: None
+ */
+static inline void dfs_free_dfs_pulseline(struct dfs_pulseline *pulses)
+{
+	qdf_mem_free(pulses);
+}
+#else
+/* Static buffers for DFS objects */
+static struct dfs_event global_dfs_event[DFS_MAX_EVENTS];
+static struct dfs_pulseline global_dfs_pulseline;
+
+static inline struct dfs_event *dfs_alloc_dfs_events(void)
+{
+	return global_dfs_event;
+}
+
+static inline void dfs_free_dfs_events(struct dfs_event *events)
+{
+}
+
+static inline struct dfs_pulseline *dfs_alloc_dfs_pulseline(void)
+{
+	return &global_dfs_pulseline;
+}
+
+static inline void dfs_free_dfs_pulseline(struct dfs_pulseline *pulses)
+{
+}
+#endif
+
 /*
  * Channel switch announcement (CSA)
  * usenol=1 (default) make CSA and switch to a new channel on radar detect
@@ -113,22 +179,23 @@ int dfs_main_attach(struct wlan_dfs *dfs)
 	STAILQ_INIT(&(dfs->dfs_eventq));
 	WLAN_DFSEVENTQ_LOCK_CREATE(dfs);
 
-	dfs->events = (struct dfs_event *)qdf_mem_malloc(
-			sizeof(struct dfs_event)*DFS_MAX_EVENTS);
+	dfs->events = dfs_alloc_dfs_events();
 	if (!(dfs->events)) {
-		dfs_alert(dfs, WLAN_DEBUG_DFS_ALWAYS, "events allocation failed");
+		dfs_alert(dfs, WLAN_DEBUG_DFS_ALWAYS,
+			  "events allocation failed");
 		return 1;
 	}
+
 	for (i = 0; i < DFS_MAX_EVENTS; i++)
 		STAILQ_INSERT_TAIL(&(dfs->dfs_eventq), &dfs->events[i],
 				re_list);
 
-	dfs->pulses = (struct dfs_pulseline *)qdf_mem_malloc(
-			sizeof(struct dfs_pulseline));
+	dfs->pulses = dfs_alloc_dfs_pulseline();
 	if (!(dfs->pulses)) {
-		qdf_mem_free(dfs->events);
+		dfs_free_dfs_events(dfs->events);
 		dfs->events = NULL;
-		dfs_alert(dfs, WLAN_DEBUG_DFS_ALWAYS, "Pulse buffer allocation failed");
+		dfs_alert(dfs, WLAN_DEBUG_DFS_ALWAYS,
+			  "Pulse buffer allocation failed");
 		return 1;
 	}
 
@@ -205,11 +272,11 @@ bad1:
 		}
 	}
 	if (dfs->pulses) {
-		qdf_mem_free(dfs->pulses);
+		dfs_free_dfs_pulseline(dfs->pulses);
 		dfs->pulses = NULL;
 	}
 	if (dfs->events) {
-		qdf_mem_free(dfs->events);
+		dfs_free_dfs_events(dfs->events);
 		dfs->events = NULL;
 	}
 
@@ -248,16 +315,11 @@ void dfs_main_detach(struct wlan_dfs *dfs)
 
 	dfs->dfs_enable = 0;
 
-	if (dfs->dfs_curchan != NULL) {
-		qdf_mem_free(dfs->dfs_curchan);
-		dfs->dfs_curchan = NULL;
-	}
-
 	dfs_reset_radarq(dfs);
 	dfs_reset_alldelaylines(dfs);
 
 	if (dfs->pulses != NULL) {
-		qdf_mem_free(dfs->pulses);
+		dfs_free_dfs_pulseline(dfs->pulses);
 		dfs->pulses = NULL;
 	}
 
@@ -294,7 +356,7 @@ void dfs_main_detach(struct wlan_dfs *dfs)
 		dfs_reset_arq(dfs);
 
 	if (dfs->events != NULL) {
-		qdf_mem_free(dfs->events);
+		dfs_free_dfs_events(dfs->events);
 		dfs->events = NULL;
 	}