[WCNCR00151648] sdio: fix kerenl crash when iperf rx

[Description]
1. Fix kerenl panic when iperf rx with Ricoh SDIO host.
2. The reason is that the memory is not alignment
   as kernel expexted.
3. Add a compile option CFG_PRE_ALLOCATION_IO_BUFFER
   to decide if pre-allocate all IO buffer at one time or not.
4. Default the compile option is off.
   Using kmalloc for each IO buffer request.

Change-Id: I2f1bbe2e0a2364dff0108e6a4e604eebeee8bfe3
Feature: sdio
Signed-off-by: Chiahsuan Chuang <chiahsuan.chuang@mediatek.com>
CR-Id: WCNCR00151648
Reviewed-on: http://gerrit.mediatek.inc:8080/793704
CheckPatch: Check Patch <srv_checkpatch@mediatek.com>
Reviewed-by: Chih-pin Wu <cp.wu@mediatek.com>
Reviewed-by: George Kuo <george.kuo@mediatek.com>
Build: srv_neptune_adm <srv_neptune_adm@mediatek.com>
diff --git a/include/config.h b/include/config.h
index dc444d5..3d278f6 100644
--- a/include/config.h
+++ b/include/config.h
@@ -941,6 +941,14 @@
  */
 #define CFG_SUPPORT_ADVANCE_CONTROL 1
 
+
+/*------------------------------------------------------------------------------
+ * Driver pre-allocate total size of memory in one time
+ *------------------------------------------------------------------------------
+ */
+#ifndef CFG_PRE_ALLOCATION_IO_BUFFER
+#define CFG_PRE_ALLOCATION_IO_BUFFER 0
+#endif
 /*******************************************************************************
 *                             D A T A   T Y P E S
 ********************************************************************************
diff --git a/os/linux/gl_init.c b/os/linux/gl_init.c
index 7bb4d7f..33a56ab 100644
--- a/os/linux/gl_init.c
+++ b/os/linux/gl_init.c
@@ -2670,7 +2670,13 @@
 	wlanDebugInit();
 
 	/* memory pre-allocation */
-	kalInitIOBuffer();
+#if CFG_PRE_ALLOCATION_IO_BUFFER
+	kalInitIOBuffer(TRUE);
+#else
+	kalInitIOBuffer(FALSE);
+#endif
+
+
 #if WLAN_INCLUDE_PROC
 	procInitFs();
 #endif
diff --git a/os/linux/gl_kal.c b/os/linux/gl_kal.c
index b5c945e..c1ffa38 100644
--- a/os/linux/gl_kal.c
+++ b/os/linux/gl_kal.c
@@ -3685,10 +3685,17 @@
 *           FALSE
 */
 /*----------------------------------------------------------------------------*/
-BOOLEAN kalInitIOBuffer(VOID)
+BOOLEAN kalInitIOBuffer(BOOLEAN is_pre_alloc)
 {
 	UINT_32 u4Size;
 
+	/* not pre-allocation for all memory usage */
+	if (!is_pre_alloc) {
+		pvIoBuffer = NULL;
+		return FALSE;
+	}
+
+	/* pre-allocation for all memory usage */
 	if (HIF_TX_COALESCING_BUFFER_SIZE > HIF_RX_COALESCING_BUFFER_SIZE)
 		u4Size = HIF_TX_COALESCING_BUFFER_SIZE;
 	else
@@ -3725,7 +3732,6 @@
 	pvIoBuffer = (PVOID) NULL;
 	pvIoBufferSize = 0;
 	pvIoBufferUsage = 0;
-
 }
 
 /*----------------------------------------------------------------------------*/
diff --git a/os/linux/include/gl_kal.h b/os/linux/include/gl_kal.h
index 125af23..d12e155 100644
--- a/os/linux/include/gl_kal.h
+++ b/os/linux/include/gl_kal.h
@@ -977,7 +977,7 @@
 /*----------------------------------------------------------------------------*/
 /* I/O Buffer Pre-allocation                                                  */
 /*----------------------------------------------------------------------------*/
-BOOLEAN kalInitIOBuffer(VOID);
+BOOLEAN kalInitIOBuffer(BOOLEAN is_pre_alloc);
 
 VOID kalUninitIOBuffer(VOID);