www.usr.com/support/gpl/USR9113_release1.0.tar.gz
[bcm963xx.git] / bcmdrivers / opensource / char / board / bcm963xx / impl1 / bcm63xx_flash.c
index 0c7fb9f..5b90057 100755 (executable)
@@ -33,6 +33,7 @@
 #include <linux/slab.h>
 #include <linux/errno.h>
 #include <linux/module.h>
+#include <linux/interrupt.h>
 #include <asm/uaccess.h>
 
 #include <bcm_map_part.h>
@@ -53,9 +54,16 @@ void *retriedKmalloc(size_t size)
 {
        void *pBuf;
     int tryCount = 0;
+    int allocType = GFP_KERNEL;
+
+    if( in_interrupt() )
+    {
+        allocType = GFP_ATOMIC;
+        tryCount = 999;
+    }
 
     // try 1000 times before quit
-    while (((pBuf = kmalloc(size, GFP_KERNEL)) == NULL) && (tryCount++ < 1000))
+    while (((pBuf = kmalloc(size, allocType)) == NULL) && (++tryCount < 1000))
     {
                current->state   = TASK_INTERRUPTIBLE;
                schedule_timeout(HZ/10);
@@ -606,6 +614,7 @@ int kerSysScratchPadGet(char *tokenId, char *tokBuf, int bufLen)
     if(memcmp(((PSP_HEADER)pBuf)->SPMagicNum, MAGIC_NUMBER, MAGIC_NUM_LEN) != 0) 
     {
         printk("Scratch pad is not initialized.\n");
+        retriedKfree(pShareBuf);
         return sts;
     }
 
@@ -620,7 +629,12 @@ int kerSysScratchPadGet(char *tokenId, char *tokBuf, int bufLen)
 
         if (strncmp(pToken->tokenName, tokenId, TOKEN_NAME_LEN) == 0)
         {
-            sts = pToken->tokenLen;
+            if ( pToken->tokenLen > bufLen )
+            {
+                printk("The length %d of token %s is greater than buffer len %d.\n", pToken->tokenLen, pToken->tokenName, bufLen);
+                break;
+            } else             
+                sts = pToken->tokenLen;
             memcpy(tokBuf, startPtr + sizeof(SP_TOKEN), sts);
             break;
         }
@@ -785,6 +799,32 @@ int kerSysScratchPadSet(char *tokenId, char *tokBuf, int bufLen)
     
 }
 
+// wipe out the scratchPad
+// return:
+//  0 - ok
+//  -1 - fail
+int kerSysScratchPadClearAll(void)
+{ 
+    int sts = -1;
+    char *pShareBuf = NULL;
+    char *pBuf = NULL;
+       
+
+    if (fInfo.flash_scratch_pad_length == 0)
+        return sts;
+    if( (pShareBuf = getSharedBlks( fInfo.flash_scratch_pad_start_blk,
+        (fInfo.flash_scratch_pad_start_blk + fInfo.flash_scratch_pad_number_blk) )) == NULL )
+        return sts;
+    pBuf = pShareBuf + fInfo.flash_scratch_pad_blk_offset;  
+    memset(pBuf, 0x00,  fInfo.flash_scratch_pad_length);
+    sts = setSharedBlks(fInfo.flash_scratch_pad_start_blk,    
+               (fInfo.flash_scratch_pad_number_blk + fInfo.flash_scratch_pad_start_blk),  pShareBuf);
+
+   retriedKfree(pShareBuf);
+       
+   return sts;
+}
+
 int kerSysFlashSizeGet(void)
 {
    return flash_get_total_size();