wlan: Re-enable wifi on WDI timeout

Optional feature to re-enable wifi on WDI timeout. When it is enabled,
it sends the hang event to supplicant to re-enable wifi.

Change-Id: Ibec2eeca552a59fa73eda516f94ab1234ab53cae
CR-Fixed: 412636
diff --git a/CORE/VOSS/src/vos_api.c b/CORE/VOSS/src/vos_api.c
index 13bde79..8cca0d1 100644
--- a/CORE/VOSS/src/vos_api.c
+++ b/CORE/VOSS/src/vos_api.c
@@ -962,7 +962,10 @@
      VOS_TRACE( VOS_MODULE_ID_VOSS, VOS_TRACE_LEVEL_ERROR,
          "%s: Failed to stop WDA", __func__);
      VOS_ASSERT( VOS_IS_STATUS_SUCCESS( vosStatus ) );
+     WDA_stopFailed(vosContext);
   }
+  else
+  {
 
   vosStatus = vos_wait_single_event( &(gpVosContext->wdaCompleteEvent),
                                      VOS_WDA_STOP_TIMEOUT );
@@ -980,6 +983,7 @@
          "%s: WDA_stop reporting other error", __func__ );
      }
      WDA_stopFailed(vosContext);
+     }
   }
 #endif
 
diff --git a/CORE/WDA/inc/wlan_qct_wda.h b/CORE/WDA/inc/wlan_qct_wda.h
index 2f5349f..40b87fc 100644
--- a/CORE/WDA/inc/wlan_qct_wda.h
+++ b/CORE/WDA/inc/wlan_qct_wda.h
@@ -423,6 +423,7 @@
    v_BOOL_t             wdaAmpSessionOn;
    v_U32_t              VosPacketToFree;
    v_BOOL_t             needShutdown;
+   v_BOOL_t             wdiFailed;
 } tWDA_CbContext ; 
 
 typedef struct
diff --git a/CORE/WDA/src/wlan_qct_wda.c b/CORE/WDA/src/wlan_qct_wda.c
index 06c0b87..fb9e729 100644
--- a/CORE/WDA/src/wlan_qct_wda.c
+++ b/CORE/WDA/src/wlan_qct_wda.c
@@ -1459,6 +1459,12 @@
       VOS_ASSERT(0);
       return VOS_STATUS_E_FAILURE;
    }
+   if (pWDA->wdiFailed == true)
+   {
+      VOS_TRACE( VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_FATAL,
+                 "%s: WDI in failed state", __FUNCTION__ );
+      return VOS_STATUS_E_ALREADY;
+   }
    /* FTM mode stay START_STATE */
    if( (WDA_READY_STATE != pWDA->wdaState) &&
        (WDA_INIT_STATE != pWDA->wdaState) &&
@@ -9856,6 +9862,7 @@
       }
       case WDI_FATAL_ERROR_IND:
       {
+         pWDA->wdiFailed = true;
          /* TODO: Decode Ind and send Ind to PE */
          VOS_TRACE( VOS_MODULE_ID_WDA, VOS_TRACE_LEVEL_INFO,
                                   "Received WDI_FATAL_ERROR_IND from WDI ");
diff --git a/CORE/WDI/CP/src/wlan_qct_wdi.c b/CORE/WDI/CP/src/wlan_qct_wdi.c
index f2efc2d..1ef4c2d 100644
--- a/CORE/WDI/CP/src/wlan_qct_wdi.c
+++ b/CORE/WDI/CP/src/wlan_qct_wdi.c
@@ -141,7 +141,7 @@
     NULL,                       /*WDI_REQUEST_EVENT*/
     WDI_MainRsp,                /*WDI_RESPONSE_EVENT*/
     WDI_MainClose,              /*WDI_CLOSE_EVENT*/
-    NULL                        /*WDI_SHUTDOWN_EVENT*/
+    WDI_MainShutdown            /*WDI_SHUTDOWN_EVENT*/
   }},
 
   /*WDI_BUSY_ST*/
@@ -19407,8 +19407,16 @@
             pWDICtx->wdiExpectedResponse);
   /* WDI timeout means Riva is not responding or SMD communication to Riva
    * is not happening. The only possible way to recover from this error
-   * is to initiate SSR from APPS */
+   * is to initiate SSR from APPS 
+   * There is also an option to re-enable wifi, which will eventually
+   * trigger SSR
+   */
+#ifndef WDI_RE_ENABLE_WIFI_ON_WDI_TIMEOUT
   wpalRivaSubystemRestart();
+#else
+  WDI_DetectedDeviceError( pWDICtx, WDI_ERR_BASIC_OP_FAILURE);
+  wpalWlanReload();
+#endif
   }
   else
   {
diff --git a/Makefile b/Makefile
index 81f3c43..bb08240 100644
--- a/Makefile
+++ b/Makefile
@@ -3,6 +3,9 @@
 #Do we panic on bug?  default is to warn
 PANIC_ON_BUG := 0
 
+#Re-enable wifi on WDI timeout
+RE_ENABLE_WIFI_ON_WDI_TIMEOUT := 0
+
 ifeq ($(CONFIG_CFG80211),y)
 HAVE_CFG80211 := 1
 else
@@ -521,6 +524,10 @@
 CDEFINES += -DPANIC_ON_BUG
 endif
 
+ifeq ($(RE_ENABLE_WIFI_ON_WDI_TIMEOUT),1)
+CDEFINES += -DWDI_RE_ENABLE_WIFI_ON_WDI_TIMEOUT
+endif
+
 ifeq ($(CONFIG_PRIMA_WLAN_BTAMP),y)
 CDEFINES += -DWLAN_BTAMP_FEATURE
 endif