fix the bug about the interrupt during SDcard copy by USB,continue with the commit...
authorxbw <xbw@rock-chips.com>
Mon, 10 Oct 2011 01:24:33 +0000 (09:24 +0800)
committerxbw <xbw@rock-chips.com>
Mon, 10 Oct 2011 01:24:33 +0000 (09:24 +0800)
drivers/mmc/core/core.c
drivers/mmc/host/rk29_sdmmc.c
drivers/usb/gadget/f_mass_storage.c

index 20e0f52d9785ddba048ba5ad6b61835a1b0ab4b2..314b4ae171a4c0cc05484e8088fa36a04c3b3acc 100755 (executable)
@@ -221,7 +221,12 @@ void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
             multi += (datasize%unit)?1:0;
             multi = (multi>0) ? multi : 1;
             multi += (mrq->cmd->retries>0)?1:0;
-            waittime = wait_for_completion_timeout(&complete,HZ*2*multi);
+            waittime = wait_for_completion_timeout(&complete,HZ*5*multi); //It should be longer than bottom driver's time,due to the sum of two cmd time.
+                                                                          //modifyed by xbw at 2011-10-08
+                                                                          //
+                                                                          //example:
+                                                                          //rk29_sdmmc_request_end..2336...   CMD12 wait busy timeout!!!!! ====xbw=[sd_mmc]====
+                                                                          //mmc_wait_for_req..236.. !!!!! wait for CMD25 timeout ===xbw[mmc0]===
         }
         else
         {
@@ -232,6 +237,7 @@ void mmc_wait_for_req(struct mmc_host *host, struct mmc_request *mrq)
     if(waittime <= 1)
     {
         host->doneflag = 0;
+        mrq->cmd->error = -EIO;
         printk("%s..%d.. !!!!! wait for CMD%d timeout ===xbw[%s]===\n",\
             __FUNCTION__, __LINE__, mrq->cmd->opcode, mmc_hostname(host));
     }
index 46d69156d9a07448a0cbbef4e93a52d9fc594533..216353d21309ce1856d89f8e7a57956a824b4d37 100755 (executable)
@@ -72,7 +72,7 @@ int debug_level = 4;
 #define RK29_SDMMC_WAIT_DTO_INTERNVAL   1000  //The time interval from the CMD_DONE_INT to DTO_INT
 #define RK29_SDMMC_REMOVAL_DELAY        1000  //The time interval from the CD_INT to detect_timer react.
 
-#define RK29_SDMMC_VERSION "Ver.2.10 The last modify date is 2011-09-30,modifyed by XBW." 
+#define RK29_SDMMC_VERSION "Ver.2.11 The last modify date is 2011-10-08,modifyed by XBW." 
 
 #define RK29_CTRL_SDMMC_ID   0  //mainly used by SDMMC
 #define RK29_CTRL_SDIO1_ID   1  //mainly used by sdio-wifi
@@ -791,7 +791,7 @@ static int rk29_sdmmc_reset_fifo(struct rk29_sdmmc *host)
 
 static int rk29_sdmmc_wait_unbusy(struct rk29_sdmmc *host)
 {
-       int time_out = 250000; //max is 250ms
+       int time_out = 500000;//250000; //max is 250ms; //adapt the value to the sick card.  modify at 2011-10-08
 
        while (rk29_sdmmc_read(host->regs, SDMMC_STATUS) & (SDMMC_STAUTS_DATA_BUSY|SDMMC_STAUTS_MC_BUSY)) 
        {
@@ -1784,6 +1784,7 @@ static int rk29_sdmmc_start_request(struct mmc_host *mmc )
                 printk("%s..Error happen in CMD_PRV_DAT_WAIT. STATUS-reg=0x%x ===xbw[%s]===\n", \
                     __FUNCTION__, rk29_sdmmc_read(host->regs, SDMMC_STATUS),host->dma_name);
             }
+            rk29_sdmmc_clear_fifo(host);
             goto start_request_Err; 
         }
     }
@@ -1958,6 +1959,11 @@ static void rk29_sdmmc_request(struct mmc_host *mmc, struct mmc_request *mrq)
        }
        
        #if 1
+    if(0 == host->mmc->doneflag)
+    {
+        host->state = STATE_IDLE;
+    }
+    
        if(host->state != STATE_IDLE)
        {
             printk("%s..%d..state Error! ,old_state=%d, OldCMD=%d ,NewCMD%2d,arg=0x%x ===xbw[%s]===\n", \
@@ -2176,14 +2182,10 @@ static int rk29_sdmmc_clear_fifo(struct rk29_sdmmc *host)
         rk29_sdmmc_write(host->regs, SDMMC_RINTSTS, 0xFFFFFFFF);
     }
 
-    //stop DMA
-    if(host->dodma)
-    {
-        rk29_sdmmc_stop_dma(host);
-        rk29_sdmmc_control_host_dma(host, FALSE);
-        host->dodma = 0;
-    }
-    
+    rk29_sdmmc_stop_dma(host);
+    rk29_sdmmc_control_host_dma(host, FALSE);
+    host->dodma = 0;
+   
     //Clean the fifo.
     for(timeout=0; timeout<FIFO_DEPTH; timeout++)
     {
@@ -2326,14 +2328,14 @@ static void rk29_sdmmc_request_end(struct rk29_sdmmc *host, struct mmc_command *
         if ((mmc_resp_type(cmd) == MMC_RSP_R1B) || (MMC_STOP_TRANSMISSION == cmd->opcode))
         {
             output = rk29_sdmmc_wait_unbusy(host);
-            if(SDM_SUCCESS != output)
+            if((SDM_SUCCESS != output) && (!host->mrq->cmd->error))
             {
+                printk("%s..%d...   CMD12 wait busy timeout!!!!! errorStep=0x%x     ====xbw=[%s]====\n", \
+                                               __FUNCTION__, __LINE__, host->errorstep, host->dma_name);
                 rk29_sdmmc_clear_fifo(host);
                 cmd->error = -ETIMEDOUT;
                 host->mrq->cmd->error = -ETIMEDOUT;
                 host->errorstep = 0x1C;
-                printk("%s..%d...   CMD12 wait busy timeout!!!!!      ====xbw=[%s]====\n", \
-                                               __FUNCTION__, __LINE__,  host->dma_name);
             }
         }
     }
@@ -2342,7 +2344,7 @@ static void rk29_sdmmc_request_end(struct rk29_sdmmc *host, struct mmc_command *
     //trace error
     if(cmd->data && cmd->data->error)
     { 
-        if( (!cmd->error) && (0==cmd->retries) && (host->error_times++%RK29_ERROR_PRINTK_INTERVAL == 0))
+        if( (!cmd->error) && (0==cmd->retries))
         {         
             printk("%s..%d......CMD=%d error!!!(arg=0x%x,cmdretry=%d,blksize=%d, blocks=%d), \n \
                 statusReg=0x%x, ctrlReg=0x%x, nerrorTimes=%d, errorStep=0x%x ====xbw[%s]====\n",\
index 072ae172d05f23bfb6008358a5d1d184435888a8..79aad93fcdeb0be27a13b166ea31ff3a569647c2 100755 (executable)
@@ -84,8 +84,8 @@
 #define BULK_BUFFER_SIZE           16384 * 4//4096
 
 /* flush after every 4 meg of writes to avoid excessive block level caching */
-//#define MAX_UNFLUSHED_BYTES  (512 * 1024)// (4 * 1024 * 1024) //original value is 4MB,Modifyed by xbw at 2011-08-18
-#define MAX_UNFLUSHED_PACKETS 16
+#define MAX_UNFLUSHED_BYTES  (64 * 1024)// (4 * 1024 * 1024) //original value is 4MB,Modifyed by xbw at 2011-08-18
+#define MAX_UNFLUSHED_PACKETS 4//16
 
 /*-------------------------------------------------------------------------*/
 
@@ -235,6 +235,7 @@ struct lun {
        loff_t          file_length;
        loff_t          num_sectors;
        unsigned int unflushed_packet;
+       unsigned int unflushed_bytes;
 
        unsigned int    ro : 1;
        unsigned int    prevent_medium_removal : 1;
@@ -1081,9 +1082,11 @@ static int do_write(struct fsg_dev *fsg)
 
 #ifdef MAX_UNFLUSHED_PACKETS
                        curlun->unflushed_packet ++;
-                       if (curlun->unflushed_packet >= MAX_UNFLUSHED_PACKETS) {
+                       curlun->unflushed_bytes += nwritten;
+                       if( (curlun->unflushed_packet >= MAX_UNFLUSHED_PACKETS) || (curlun->unflushed_bytes >= MAX_UNFLUSHED_BYTES)) {
                                fsync_sub(curlun);
                                curlun->unflushed_packet = 0;
+                               curlun->unflushed_bytes = 0;
                        }
 #endif
                        /* If an error occurred, report it and its position */
@@ -2764,6 +2767,7 @@ static int open_backing_file(struct fsg_dev *fsg, struct lun *curlun,
        curlun->filp = filp;
        curlun->file_length = size;
        curlun->unflushed_packet = 0;
+       curlun->unflushed_bytes = 0;
        curlun->num_sectors = num_sectors;
        LDBG(curlun, "open backing file: %s size: %lld num_sectors: %lld\n",
                        filename, size, num_sectors);