浏览代码

qcacld-3.0: Allocate for cfg int and str buffer dynamically

This is pass 2 of cfg mechanism enahancement. With this patch cfg int
and cfg str buffer are allocated dynamically so no need to maintain
CFG_STA_IBUF_MAX_SIZE and CFG_STA_SBUF_MAX_SIZE manually.

Change-Id: I0f8cb942e93236546aad9963c9451e0399a251ac
CRs-Fixed: 914157
Naveen Rawat 9 年之前
父节点
当前提交
318fce978c
共有 4 个文件被更改,包括 58 次插入20 次删除
  1. 0 2
      core/mac/inc/wni_cfg.h
  2. 54 9
      core/mac/src/cfg/cfg_api.c
  3. 1 7
      core/mac/src/cfg/cfg_proc_msg.c
  4. 3 2
      core/mac/src/include/cfg_global.h

+ 0 - 2
core/mac/inc/wni_cfg.h

@@ -1549,8 +1549,6 @@ enum {
 #define WNI_CFG_TDLS_WMM_MODE_ENABLED_STADEF    0
 
 #define CFG_PARAM_MAX_NUM        286
-#define CFG_STA_IBUF_MAX_SIZE    234
-#define CFG_STA_SBUF_MAX_SIZE    3199
 
 #define CFG_STA_MAGIC_DWORD    0xbeefbeef
 

+ 54 - 9
core/mac/src/cfg/cfg_api.c

@@ -46,10 +46,6 @@
 /* Static Variables */
 /* ---------------------------------------------------------------------- */
 static tCfgCtl __g_cfg_entry[CFG_PARAM_MAX_NUM];
-static uint32_t __g_cfg_i_buf_min[CFG_STA_IBUF_MAX_SIZE];
-static uint32_t __g_cfg_i_buf_max[CFG_STA_IBUF_MAX_SIZE];
-static uint32_t __g_cfg_i_buf[CFG_STA_IBUF_MAX_SIZE];
-static uint8_t __g_cfg_s_buf[CFG_STA_SBUF_MAX_SIZE];
 static uint8_t __g_s_buffer[CFG_MAX_STR_LEN];
 static uint32_t __g_param_list[WNI_CFG_MAX_PARAM_NUM +
 			     WNI_CFG_GET_PER_STA_STAT_RSP_NUM];
@@ -104,10 +100,11 @@ uint32_t cfg_need_reload(tpAniSirGlobal pMac, uint16_t cfgId)
 tSirRetStatus cfg_init(tpAniSirGlobal pMac)
 {
 	uint16_t i = 0;
-	pMac->cfg.gCfgIBufMin = __g_cfg_i_buf_min;
-	pMac->cfg.gCfgIBufMax = __g_cfg_i_buf_max;
-	pMac->cfg.gCfgIBuf = __g_cfg_i_buf;
-	pMac->cfg.gCfgSBuf = __g_cfg_s_buf;
+	uint16_t combined_buff_size = 0;
+	uint32_t    max_i_count = 0;
+	uint32_t    max_s_count = 0;
+	cfgstatic_string *str_cfg;
+
 	pMac->cfg.gSBuffer = __g_s_buffer;
 	pMac->cfg.gCfgEntry = __g_cfg_entry;
 	pMac->cfg.gParamList = __g_param_list;
@@ -119,12 +116,60 @@ tSirRetStatus cfg_init(tpAniSirGlobal pMac)
 			cfg_static[i].pStrData = NULL;
 		}
 	}
+
+	for (i = 0; i < CFG_PARAM_MAX_NUM ; i++) {
+		if (cfg_static[i].control & CFG_CTL_INT) {
+			max_i_count++;
+		} else {
+			str_cfg = (cfgstatic_string *)cfg_static[i].pStrData;
+			if (str_cfg == NULL) {
+				cfg_log(pMac, LOGE,
+					FL("pStrCfg is NULL for CfigID : %d"),
+					i);
+				continue;
+			}
+			/* + 2 to include len field and max len field */
+			max_s_count += str_cfg->maxLen + 2;
+		}
+	}
+
+	pMac->cfg.gCfgMaxIBufSize = max_i_count;
+	pMac->cfg.gCfgMaxSBufSize = max_s_count;
+
+	/* Allocate a combined memory */
+	combined_buff_size = max_s_count + (3 * sizeof(uint32_t) * max_i_count);
+
+	cfg_log(pMac, LOGE, FL("Size of cfg I buffer:%d  S buffer: %d"),
+		max_i_count, max_s_count);
+
+	cfg_log(pMac, LOGE, FL("Allocation for cfg buffers: %d bytes"),
+		combined_buff_size);
+
+	if (combined_buff_size > 4 * PAGE_SIZE) {
+		cfg_log(pMac, LOGE, FL("Mem alloc request too big"));
+		return eSIR_MEM_ALLOC_FAILED;
+	}
+	/* at this point pMac->cfg.gCfgSBuf starts */
+	pMac->cfg.gCfgSBuf = cdf_mem_malloc(combined_buff_size);
+	if (NULL == pMac->cfg.gCfgSBuf) {
+		cfg_log(pMac, LOGE,
+			FL("Failed to allocate memory for cfg array"));
+		return eSIR_MEM_ALLOC_FAILED;
+	}
+	/* at offset max_s_count, pMac->cfg.gCfgIBuf starts */
+	pMac->cfg.gCfgIBuf = (uint32_t *)&pMac->cfg.gCfgSBuf[max_s_count];
+	/* after max_i_count integers, pMac->cfg.gCfgIBufMin starts */
+	pMac->cfg.gCfgIBufMin = &pMac->cfg.gCfgIBuf[max_i_count];
+	/* after max_i_count integers, pMac->cfg.gCfgIBufMax starts */
+	pMac->cfg.gCfgIBufMax = &pMac->cfg.gCfgIBufMin[max_i_count];
+
 	return (eSIR_SUCCESS);
 }
 
 /* ---------------------------------------------------------------------- */
 void cfg_de_init(tpAniSirGlobal pMac)
 {
+	cdf_mem_free(pMac->cfg.gCfgSBuf);
 	pMac->cfg.gCfgIBufMin = NULL;
 	pMac->cfg.gCfgIBufMax = NULL;
 	pMac->cfg.gCfgIBuf = NULL;
@@ -176,7 +221,7 @@ tSirRetStatus cfg_check_valid(tpAniSirGlobal pMac, uint16_t cfgId,
 
 	*index = control & CFG_BUF_INDX_MASK;
 
-	if (*index >= CFG_STA_SBUF_MAX_SIZE) {
+	if (*index >= pMac->cfg.gCfgMaxSBufSize) {
 		PELOGE(cfg_log(pMac, LOGE, FL("cfg index out of bounds %d"),
 					*index);)
 		return eSIR_CFG_INVALID_ID;

+ 1 - 7
core/mac/src/cfg/cfg_proc_msg.c

@@ -1886,12 +1886,6 @@ static void proc_dnld_rsp(tpAniSirGlobal pMac, uint16_t length, uint32_t *pParam
 	pParam++;
 	length -= 4;
 
-	/* Verify message length */
-	{
-		pMac->cfg.gCfgMaxIBufSize = CFG_STA_IBUF_MAX_SIZE;
-		pMac->cfg.gCfgMaxSBufSize = CFG_STA_SBUF_MAX_SIZE;
-	}
-
 	/* Parse the Cfg header */
 	pHdr = (tpCfgBinHdr) pParam;
 	pParam += (sizeof(tCfgBinHdr) >> 2);
@@ -2554,7 +2548,7 @@ process_cfg_download_req(tpAniSirGlobal pMac)
 			uint8_t maxSavedLen;
 			if ((pMac->cfg.gCfgEntry[i].control & CFG_CTL_VALID) == 0)
 				continue;
-			if (index >= CFG_STA_SBUF_MAX_SIZE)
+			if (index >= pMac->cfg.gCfgMaxSBufSize)
 				continue;
 
 			pDstTest = &pMac->cfg.gCfgSBuf[index];

+ 3 - 2
core/mac/src/include/cfg_global.h

@@ -77,10 +77,11 @@ typedef struct sAniSirCfg {
 	uint8_t gCfgStatus;
 
 	tCfgCtl *gCfgEntry;
+
+	uint8_t *gCfgSBuf;
+	uint32_t *gCfgIBuf;
 	uint32_t *gCfgIBufMin;
 	uint32_t *gCfgIBufMax;
-	uint32_t *gCfgIBuf;
-	uint8_t *gCfgSBuf;
 
 	uint16_t gCfgMaxIBufSize;
 	uint16_t gCfgMaxSBufSize;