sthal: reset all route before handling crash recovery

note: The active count sometimes unbalance inside libaudioroute
      when codec crash happened
      It should clean all count after codec crash to make sure
      the synchronized state in both sides.

Bug: 144538590
Test: Manually test crash recovery and test team done the regression
test for specified and related use-case.

Change-Id: I63b2ecd02bcf311426b1a37825b83badec5d99eb
diff --git a/cvq_ioctl.h b/cvq_ioctl.h
index abce7f2..c212e42 100644
--- a/cvq_ioctl.h
+++ b/cvq_ioctl.h
@@ -127,25 +127,35 @@
 #define SRC_PACKAGE                 "SampleRateConverterPackage.bin"
 #define SRC_CONFIG                  "SampleRateConverterCreateCfgBlkGen.bin"
 
-#define MIC_ROUTE                            "mic1-route"
-#define MIC_ROUTE_EXT_CLK                    "mic-route-external-clock"
-#define MIC_ROUTE_INT_CLK                    "mic-route-internal-clock"
-#define SRC_ROUTE_MIC                        "src-route-mic"
-#define SRC_ROUTE_AMP_REF                    "src-route-amp-ref"
-#define BARGEIN_AMP_REF                      "bargein-amp-ref"
-#define BARGEIN_AMP_REF_48K                  "bargein-amp-ref-48k"
-#define BARGEIN_ROUTE                        "bargein-route"
-#define DOWNLINK_AUDIO_ROUTE                 "downlink-audio-route"
-#define MUSIC_AUDIO_ROUTE                    "music-audio-route"
-#define SENSOR_ROTUE                         "oslo-route"
-#define HOTWORD_WITH_BARGEIN_ROUTE           "hotword-route-with-bargein"
-#define HOTWORD_WITHOUT_BARGEIN_ROUTE        "hotword-route-without-bargein"
-#define CHRE_WITH_BARGEIN_ROUTE              "chre-route-with-bargein"
-#define CHRE_WITHOUT_BARGEIN_ROUTE           "chre-route-without-bargein"
-#define AMBIENT_WITH_BARGEIN_ROUTE           "ambient-route-with-bargein"
-#define AMBIENT_WITHOUT_BARGEIN_ROUTE        "ambient-route-without-bargein"
-#define BUFFER_WITH_BARGEIN_ROUTE            "buffer-route-with-bargein"
-#define BUFFER_WITHOUT_BARGEIN_ROUTE         "buffer-route-without-bargein"
+/* The routing definition depend on the platform
+   and the features plugin.
+ */
+enum {
+    ST_ROUTE_MIN = 0,
+
+/* Input Port routing definition */
+    ST_MIC_ROUTE_INT_CLK = ST_ROUTE_MIN,
+    ST_MIC_ROUTE_EXT_CLK,
+    ST_BARGEIN_AMP_REF,
+    ST_BARGEIN_AMP_REF_48K,
+
+/* Plugin routing definition */
+    ST_HOTWORD_WITHOUT_BARGEIN,
+    ST_HOTWORD_WITH_BARGEIN,
+    ST_HOTWORD_BUFFER_WITHOUT_BARGEIN,
+    ST_HOTWORD_BUFFER_WITH_BARGEIN,
+    ST_AMBIENT_WITHOUT_BARGEIN,
+    ST_AMBIENT_WITH_BARGEIN,
+    ST_AMBIENT_BUFFER_WITHOUT_BARGEIN,
+    ST_AMBIENT_BUFFER_WITH_BARGEIN,
+    ST_BARGEIN_ROUTE,
+    ST_CHRE_WITHOUT_BARGEIN,
+    ST_CHRE_WITH_BARGEIN,
+    ST_SRC_ROUTE_MIC,
+    ST_SRC_ROUTE_AMP_REF,
+    ST_SENSOR_ROUTE,
+    ST_ROUTE_MAX,
+};
 
 enum clock_type {
     INTERNAL_OSCILLATOR,
@@ -236,6 +246,7 @@
 int set_default_apll_clk(struct mixer *mixer);
 int get_fw_status(struct iaxxx_odsp_hw *odsp_hdl, unsigned int *status);
 int reset_fw(struct iaxxx_odsp_hw *odsp_hdl);
+int reset_all_route(struct audio_route *route_hdl);
 int trigger_sensor_destroy_event(struct iaxxx_odsp_hw *odsp_hdl);
 int trigger_chre_destroy_event(struct iaxxx_odsp_hw *odsp_hdl);
 int setup_slpi_wakeup_event(struct iaxxx_odsp_hw *odsp_hdl, bool enabled);
diff --git a/cvq_util.c b/cvq_util.c
index 112d4e2..e8631e0 100644
--- a/cvq_util.c
+++ b/cvq_util.c
@@ -32,6 +32,32 @@
 
 #include "cvq_ioctl.h"
 
+/* Array for ST route */
+static const char * const route_table[ST_ROUTE_MAX] = {
+
+/* Input Port routing definition */
+    [ST_MIC_ROUTE_INT_CLK] = "mic-route-internal-clock",
+    [ST_MIC_ROUTE_EXT_CLK] = "mic-route-external-clock",
+    [ST_BARGEIN_AMP_REF] = "bargein-amp-ref",
+    [ST_BARGEIN_AMP_REF_48K] = "bargein-amp-ref-48k",
+
+/* Plugin routing definition */
+    [ST_HOTWORD_WITHOUT_BARGEIN] = "hotword-route-without-bargein",
+    [ST_HOTWORD_WITH_BARGEIN] = "hotword-route-with-bargein",
+    [ST_HOTWORD_BUFFER_WITHOUT_BARGEIN] = "buffer-route-without-bargein",
+    [ST_HOTWORD_BUFFER_WITH_BARGEIN] = "buffer-route-with-bargein",
+    [ST_AMBIENT_WITHOUT_BARGEIN] = "ambient-route-without-bargein",
+    [ST_AMBIENT_WITH_BARGEIN] = "ambient-route-with-bargein",
+    [ST_AMBIENT_BUFFER_WITHOUT_BARGEIN] = "downlink-audio-route",
+    [ST_AMBIENT_BUFFER_WITH_BARGEIN] = "music-audio-route",
+    [ST_BARGEIN_ROUTE] = "bargein-route",
+    [ST_CHRE_WITHOUT_BARGEIN] = "chre-route-without-bargein",
+    [ST_CHRE_WITH_BARGEIN] = "chre-route-with-bargein",
+    [ST_SRC_ROUTE_MIC] = "src-route-mic",
+    [ST_SRC_ROUTE_AMP_REF] = "src-route-amp-ref",
+    [ST_SENSOR_ROUTE] = "oslo-route",
+};
+
 int write_model(struct iaxxx_odsp_hw *odsp_hdl, unsigned char *data,
                 int length, int kw_type)
  {
@@ -140,9 +166,9 @@
 
     ALOGV("+%s+", __func__);
     if (enable)
-        err = audio_route_apply_and_update_path(route_hdl, SENSOR_ROTUE);
+        err = audio_route_apply_and_update_path(route_hdl, route_table[ST_SENSOR_ROUTE]);
     else
-        err = audio_route_reset_and_update_path(route_hdl, SENSOR_ROTUE);
+        err = audio_route_reset_and_update_path(route_hdl, route_table[ST_SENSOR_ROUTE]);
     if (err)
         ALOGE("%s: route fail %d", __func__, err);
 
@@ -249,10 +275,10 @@
 
     if (bargein == true)
         err = audio_route_apply_and_update_path(route_hdl,
-                                        AMBIENT_WITH_BARGEIN_ROUTE);
+                                        route_table[ST_AMBIENT_WITH_BARGEIN]);
     else
         err = audio_route_apply_and_update_path(route_hdl,
-                                        AMBIENT_WITHOUT_BARGEIN_ROUTE);
+                                        route_table[ST_AMBIENT_WITHOUT_BARGEIN]);
     if (err)
         ALOGE("%s: route apply fail %d", __func__, err);
 
@@ -268,10 +294,10 @@
     /* check cvq node to send ioctl */
     if (bargein == true)
         err = audio_route_reset_and_update_path(route_hdl,
-                                        AMBIENT_WITH_BARGEIN_ROUTE);
+                                        route_table[ST_AMBIENT_WITH_BARGEIN]);
     else
         err = audio_route_reset_and_update_path(route_hdl,
-                                        AMBIENT_WITHOUT_BARGEIN_ROUTE);
+                                        route_table[ST_AMBIENT_WITHOUT_BARGEIN]);
     if (err)
         ALOGE("%s: route reset fail %d", __func__, err);
 
@@ -382,10 +408,10 @@
 
     if (bargein == true)
         err = audio_route_apply_and_update_path(route_hdl,
-                                            HOTWORD_WITH_BARGEIN_ROUTE);
+                                            route_table[ST_HOTWORD_WITH_BARGEIN]);
     else
         err = audio_route_apply_and_update_path(route_hdl,
-                                            HOTWORD_WITHOUT_BARGEIN_ROUTE);
+                                            route_table[ST_HOTWORD_WITHOUT_BARGEIN]);
     if (err)
         ALOGE("%s: route apply fail %d", __func__, err);
 
@@ -401,10 +427,10 @@
     /* check cvq node to send ioctl */
     if (bargein == true)
         err = audio_route_reset_and_update_path(route_hdl,
-                                            HOTWORD_WITH_BARGEIN_ROUTE);
+                                            route_table[ST_HOTWORD_WITH_BARGEIN]);
     else
         err = audio_route_reset_and_update_path(route_hdl,
-                                            HOTWORD_WITHOUT_BARGEIN_ROUTE);
+                                            route_table[ST_HOTWORD_WITHOUT_BARGEIN]);
     if (err)
         ALOGE("%s: route reset fail %d", __func__, err);
 
@@ -419,10 +445,10 @@
     ALOGV("+%s+", __func__);
     if (bargein)
         err = audio_route_apply_and_update_path(route_hdl,
-                                        CHRE_WITH_BARGEIN_ROUTE);
+                                        route_table[ST_CHRE_WITH_BARGEIN]);
     else
         err = audio_route_apply_and_update_path(route_hdl,
-                                        CHRE_WITHOUT_BARGEIN_ROUTE);
+                                        route_table[ST_CHRE_WITHOUT_BARGEIN]);
     if (err)
         ALOGE("%s: route apply fail %d", __func__, err);
 
@@ -437,10 +463,10 @@
     ALOGV("+%s+", __func__);
     if (bargein == true)
         err = audio_route_reset_and_update_path(route_hdl,
-                                        CHRE_WITH_BARGEIN_ROUTE);
+                                        route_table[ST_CHRE_WITH_BARGEIN]);
     else
         err = audio_route_reset_and_update_path(route_hdl,
-                                        CHRE_WITHOUT_BARGEIN_ROUTE);
+                                        route_table[ST_CHRE_WITHOUT_BARGEIN]);
     if (err)
         ALOGE("%s: route reset fail %d", __func__, err);
 
@@ -1492,10 +1518,10 @@
 
     if (bargein == true)
         err = audio_route_apply_and_update_path(route_hdl,
-                                                BUFFER_WITH_BARGEIN_ROUTE);
+                                                route_table[ST_HOTWORD_BUFFER_WITH_BARGEIN]);
     else
         err = audio_route_apply_and_update_path(route_hdl,
-                                                BUFFER_WITHOUT_BARGEIN_ROUTE);
+                                                route_table[ST_HOTWORD_BUFFER_WITHOUT_BARGEIN]);
     if (err)
         ALOGE("%s: route fail %d", __func__, err);
 
@@ -1511,10 +1537,10 @@
 
     if (bargein == true)
         err = audio_route_reset_and_update_path(route_hdl,
-                                                BUFFER_WITH_BARGEIN_ROUTE);
+                                                route_table[ST_HOTWORD_BUFFER_WITH_BARGEIN]);
     else
         err = audio_route_reset_and_update_path(route_hdl,
-                                                BUFFER_WITHOUT_BARGEIN_ROUTE);
+                                                route_table[ST_HOTWORD_BUFFER_WITHOUT_BARGEIN]);
     if (err)
         ALOGE("%s: route fail %d", __func__, err);
 
@@ -1528,9 +1554,9 @@
 
     ALOGV("+%s+ %d", __func__, enable);
     if (enable)
-        err = audio_route_apply_and_update_path(route_hdl, BARGEIN_ROUTE);
+        err = audio_route_apply_and_update_path(route_hdl, route_table[ST_BARGEIN_ROUTE]);
     else
-        err = audio_route_reset_and_update_path(route_hdl, BARGEIN_ROUTE);
+        err = audio_route_reset_and_update_path(route_hdl, route_table[ST_BARGEIN_ROUTE]);
     if (err)
         ALOGE("%s: route fail %d", __func__, err);
 
@@ -1546,14 +1572,14 @@
     ALOGV("+%s+ %d strm type %d", __func__, enable, strmt);
     if (strmt == STRM_16K) {
         if (enable)
-            err = audio_route_apply_and_update_path(route_hdl, BARGEIN_AMP_REF);
+            err = audio_route_apply_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF]);
         else
-            err = audio_route_reset_and_update_path(route_hdl, BARGEIN_AMP_REF);
+            err = audio_route_reset_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF]);
     } else if (strmt == STRM_48K) {
         if (enable)
-            err = audio_route_apply_and_update_path(route_hdl, BARGEIN_AMP_REF_48K);
+            err = audio_route_apply_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF_48K]);
         else
-            err = audio_route_reset_and_update_path(route_hdl, BARGEIN_AMP_REF_48K);
+            err = audio_route_reset_and_update_path(route_hdl, route_table[ST_BARGEIN_AMP_REF_48K]);
     } else {
         ALOGE("%s: ERROR: Invalid strm type", __func__);
         err = -EINVAL;
@@ -1573,10 +1599,10 @@
     ALOGD("+%s+ %d", __func__, downlink);
     if (downlink)
         err = audio_route_apply_and_update_path(route_hdl,
-                                                DOWNLINK_AUDIO_ROUTE);
+                                                route_table[ST_AMBIENT_BUFFER_WITHOUT_BARGEIN]);
     else
         err = audio_route_apply_and_update_path(route_hdl,
-                                                MUSIC_AUDIO_ROUTE);
+                                                route_table[ST_AMBIENT_BUFFER_WITH_BARGEIN]);
     if (err)
         ALOGE("%s: route fail %d", __func__, err);
 
@@ -1591,10 +1617,10 @@
     ALOGD("+%s+ %d", __func__, downlink);
     if (downlink)
         err = audio_route_reset_and_update_path(route_hdl,
-                                                DOWNLINK_AUDIO_ROUTE);
+                                                route_table[ST_AMBIENT_BUFFER_WITHOUT_BARGEIN]);
     else
         err = audio_route_reset_and_update_path(route_hdl,
-                                                MUSIC_AUDIO_ROUTE);
+                                                route_table[ST_AMBIENT_BUFFER_WITH_BARGEIN]);
     if (err)
         ALOGE("%s: route fail %d", __func__, err);
 
@@ -1610,14 +1636,14 @@
 
     if (st == SRC_MIC) {
         if (enable)
-            err = audio_route_apply_and_update_path(route_hdl, SRC_ROUTE_MIC);
+            err = audio_route_apply_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_MIC]);
         else
-            err = audio_route_reset_and_update_path(route_hdl, SRC_ROUTE_MIC);
+            err = audio_route_reset_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_MIC]);
     } else if (st == SRC_AMP_REF) {
         if (enable)
-            err = audio_route_apply_and_update_path(route_hdl, SRC_ROUTE_AMP_REF);
+            err = audio_route_apply_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_AMP_REF]);
         else
-            err = audio_route_reset_and_update_path(route_hdl, SRC_ROUTE_AMP_REF);
+            err = audio_route_reset_and_update_path(route_hdl, route_table[ST_SRC_ROUTE_AMP_REF]);
 
     } else {
         ALOGE("%s: ERROR: Invalid src type", __func__);
@@ -1641,18 +1667,18 @@
     if (ct == EXTERNAL_OSCILLATOR) {
         if (enable) {
             err = audio_route_apply_and_update_path(route_hdl,
-                                                    MIC_ROUTE_EXT_CLK);
+                                                    route_table[ST_MIC_ROUTE_EXT_CLK]);
         } else {
             err = audio_route_reset_and_update_path(route_hdl,
-                                                    MIC_ROUTE_EXT_CLK);
+                                                    route_table[ST_MIC_ROUTE_EXT_CLK]);
         }
     } else if (ct == INTERNAL_OSCILLATOR) {
         if (enable) {
             err = audio_route_apply_and_update_path(route_hdl,
-                                                    MIC_ROUTE_INT_CLK);
+                                                    route_table[ST_MIC_ROUTE_INT_CLK]);
         } else {
             err = audio_route_reset_and_update_path(route_hdl,
-                                                    MIC_ROUTE_INT_CLK);
+                                                    route_table[ST_MIC_ROUTE_INT_CLK]);
         }
     } else {
         ALOGE("%s: ERROR: Invalid clock type", __func__);
@@ -1764,6 +1790,21 @@
     return err;
 }
 
+int reset_all_route(struct audio_route *route_hdl)
+{
+    int err = 0;
+
+    ALOGD("+%s+", __func__);
+    for (int i = ST_ROUTE_MIN; i < ST_ROUTE_MAX; i++) {
+    /*[TODO] Need to use force_reset to clean the active count
+     *       inside libaudioroute
+     */
+        audio_route_reset_and_update_path(route_hdl, route_table[i]);
+    }
+    ALOGD("-%s-", __func__);
+    return err;
+}
+
 int setup_slpi_wakeup_event(struct iaxxx_odsp_hw *odsp_hdl, bool enabled)
 {
     int err;
diff --git a/sound_trigger_hw_iaxxx.c b/sound_trigger_hw_iaxxx.c
index 15430c1..0652389 100644
--- a/sound_trigger_hw_iaxxx.c
+++ b/sound_trigger_hw_iaxxx.c
@@ -1588,51 +1588,14 @@
     }
 
     /*
-     * If ST mode is IN_CALL, tear all route and they will be
-     * reloaded after ending the call
+     * If ST mode is IN_CALL, make sure mic route as false,
+     * that would be reloaded after ending the call
      */
     if (get_sthal_mode(stdev) == IN_CALL) {
         ALOGD("%s: ST mode is in_call, reset all routes", __func__);
-        err = enable_mic_route(stdev->route_hdl, false, ct);
-        if (err != 0) {
-            ALOGE("failed to tear mic route");
-        }
+
         stdev->is_mic_route_enabled = false;
 
-        err = enable_src_route(stdev->route_hdl, false, SRC_MIC);
-        if (err != 0) {
-            ALOGE("Failed to tear SRC-mic route");
-        }
-        if (stdev->is_music_playing == true &&
-            stdev->is_bargein_route_enabled == true) {
-            err = enable_amp_ref_route(stdev->route_hdl, false, strmt);
-            if (err != 0) {
-                ALOGE("Failed to tear amp-ref route");
-            }
-            err = enable_src_route(stdev->route_hdl, false, SRC_AMP_REF);
-            if (err != 0) {
-                ALOGE("Failed to tear SRC-amp route");
-            }
-            err = enable_bargein_route(stdev->route_hdl, false);
-            if (err != 0) {
-                ALOGE("Failed to tear bargein route");
-            }
-        }
-        // reset model route
-        for (i = 0; i < MAX_MODELS; i++) {
-            if (check_uuid_equality(stdev->models[i].uuid, stdev->hotword_model_uuid) ||
-                (check_uuid_equality(stdev->models[i].uuid, stdev->wakeup_model_uuid))) {
-                tear_hotword_buffer_route(stdev->route_hdl,
-                                          stdev->is_bargein_route_enabled);
-            }
-            if (check_uuid_equality(stdev->models[i].uuid, stdev->ambient_model_uuid) ||
-                (check_uuid_equality(stdev->models[i].uuid, stdev->entity_model_uuid))) {
-                tear_music_buffer_route(stdev->route_hdl,
-                                        stdev->is_bargein_route_enabled);
-            }
-            tear_package_route(stdev, stdev->models[i].uuid,
-                               stdev->is_bargein_route_enabled);
-        }
         // if chre enabled before crash during call, need to setup package for SLPI.
         if (stdev->is_chre_loaded == true) {
             err = setup_chre_package(stdev->odsp_hdl);
@@ -1658,10 +1621,6 @@
         if (err != 0) {
             ALOGE("failed to load SRC package");
         }
-        err = enable_src_route(stdev->route_hdl, false, SRC_MIC);
-        if (err != 0) {
-            ALOGE("Failed to tear SRC-mic route");
-        }
         err = enable_src_route(stdev->route_hdl, true, SRC_MIC);
         if (err != 0) {
             ALOGE("Failed to restart SRC-mic route");
@@ -1677,10 +1636,6 @@
         if (err != 0) {
             ALOGE("failed to load SRC package");
         }
-        err = enable_src_route(stdev->route_hdl, false, SRC_AMP_REF);
-        if (err != 0) {
-            ALOGE("Failed to tear SRC-amp route");
-        }
         err = enable_src_route(stdev->route_hdl, true, SRC_AMP_REF);
         if (err != 0) {
             ALOGE("Failed to restart SRC-amp route");
@@ -1690,18 +1645,10 @@
         if (err != 0) {
             ALOGE("Failed to restart AEC package");
         }
-        err = enable_bargein_route(stdev->route_hdl, false);
-        if (err != 0) {
-            ALOGE("Failed to tear bargein route");
-        }
         err = enable_bargein_route(stdev->route_hdl, true);
         if (err != 0) {
             ALOGE("Failed to restart bargein route");
         }
-        err = enable_amp_ref_route(stdev->route_hdl, false, strmt);
-        if (err != 0) {
-            ALOGE("Failed to tear amp-ref route");
-        }
         err = enable_amp_ref_route(stdev->route_hdl, true, strmt);
         if (err != 0) {
             ALOGE("Failed to restart amp-ref route");
@@ -1710,10 +1657,6 @@
 
     if (stdev->is_mic_route_enabled == true) {
         if (is_mic_controlled_by_ahal(stdev) == false) {
-            err = enable_mic_route(stdev->route_hdl, false, ct);
-            if (err != 0) {
-                ALOGE("failed to tear mic route");
-            }
             err = enable_mic_route(stdev->route_hdl, true, ct);
             if (err != 0) {
                 ALOGE("failed to restart mic route");
@@ -1732,8 +1675,6 @@
                 if ((stdev->hotword_buffer_enable) &&
                     (!(stdev->current_enable & HOTWORD_MASK) ||
                       (stdev->current_enable & WAKEUP_MASK))) {
-                    tear_hotword_buffer_route(stdev->route_hdl,
-                                            stdev->is_bargein_route_enabled);
                     set_hotword_buffer_route(stdev->route_hdl,
                                             stdev->is_bargein_route_enabled);
                 }
@@ -1743,15 +1684,11 @@
                 if ((stdev->music_buffer_enable) &&
                     (!(stdev->current_enable & AMBIENT_MASK) ||
                       (stdev->current_enable & ENTITY_MASK))) {
-                    tear_music_buffer_route(stdev->route_hdl,
-                                        stdev->is_bargein_route_enabled);
                     set_music_buffer_route(stdev->route_hdl,
                                         stdev->is_bargein_route_enabled);
                 }
             }
             setup_package(stdev, &stdev->models[i]);
-            tear_package_route(stdev, stdev->models[i].uuid,
-                            stdev->is_bargein_route_enabled);
             set_package_route(stdev, stdev->models[i].uuid,
                             stdev->is_bargein_route_enabled);
         }
@@ -1764,13 +1701,6 @@
         if (stdev->models[i].is_loaded == true) {
             if (check_uuid_equality(stdev->models[i].uuid,
                                     stdev->sensor_model_uuid)) {
-                err = set_sensor_route(stdev->route_hdl, false);
-                if (err != 0) {
-                    ALOGE("%s: tear Sensor route fail", __func__);
-                    goto exit;
-                }
-                stdev->is_sensor_route_enabled = false;
-
                 // setup the sensor route
                 err = setup_sensor_package(stdev->odsp_hdl);
                 if (err != 0) {
@@ -1908,6 +1838,7 @@
                 ALOGE("%s: ERROR: Failed to reset the firmware %d(%s)",
                       __func__, errno, strerror(errno));
             }
+            reset_all_route(stdev->route_hdl);
             sensor_crash_handler(stdev);
         }
     }
@@ -2149,6 +2080,7 @@
                 ALOGE("%s: ERROR: Failed to reset the firmware %d(%s)",
                       __func__, errno, strerror(errno));
             }
+            reset_all_route(stdev->route_hdl);
             chre_crash_handler(stdev);
         }
     }
@@ -2421,6 +2353,7 @@
                     ALOGD("Firmware has crashed");
                     // Don't allow any op on ST HAL until recovery is complete
                     stdev->is_st_hal_ready = false;
+                    reset_all_route(stdev->route_hdl);
                     stdev->is_streaming = 0;
 
                     // Firmware crashed, clear CHRE/Oslo timer and flags here