diff --git a/dsp/adsp-loader.c b/dsp/adsp-loader.c index c8408d0c9a..8d135eedb0 100644 --- a/dsp/adsp-loader.c +++ b/dsp/adsp-loader.c @@ -26,6 +26,7 @@ #define SSR_RESET_CMD 1 #define IMAGE_UNLOAD_CMD 0 #define MAX_FW_IMAGES 4 +#define ADSP_LOADER_APM_TIMEOUT_MS 10000 enum spf_subsys_state { SPF_SUBSYS_DOWN, @@ -137,7 +138,7 @@ static void adsp_load_fw(struct work_struct *adsp_ldr_work) load_adsp: { - adsp_state = spf_core_is_apm_ready(); + adsp_state = spf_core_is_apm_ready(ADSP_LOADER_APM_TIMEOUT_MS); if (adsp_state == SPF_SUBSYS_DOWN) { if (!priv->adsp_fw_name) { dev_info(&pdev->dev, "%s: Load default ADSP\n", diff --git a/dsp/audio_prm.c b/dsp/audio_prm.c index 5d9c82f5c7..953762bfc8 100644 --- a/dsp/audio_prm.c +++ b/dsp/audio_prm.c @@ -22,6 +22,7 @@ #define TIMEOUT_MS 500 #define MAX_RETRY_COUNT 3 #define APM_READY_WAIT_DURATION 2 +#define GPR_SEND_PKT_APM_TIMEOUT_MS 0 struct audio_prm { struct gpr_device *adev; @@ -104,7 +105,8 @@ static int prm_gpr_send_pkt(struct gpr_pkt *pkt, wait_queue_head_t *wait) (gpr_get_q6_state() == GPR_SUBSYS_LOADED)) { pr_info("%s: apm ready check not done\n", __func__); retry = 0; - while (!spf_core_is_apm_ready() && retry < MAX_RETRY_COUNT) { + while (!spf_core_is_apm_ready(GPR_SEND_PKT_APM_TIMEOUT_MS) && + retry < MAX_RETRY_COUNT) { msleep(APM_READY_WAIT_DURATION); ++retry; } diff --git a/dsp/spf-core.c b/dsp/spf-core.c index 59615021f3..a3b473fefc 100644 --- a/dsp/spf-core.c +++ b/dsp/spf-core.c @@ -1,5 +1,5 @@ /* Copyright (c) 2019-2021, The Linux Foundation. All rights reserved. - * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -24,7 +24,6 @@ #include #include -#define APM_STATE_READY_TIMEOUT_MS 10000 #define Q6_READY_TIMEOUT_MS 1000 #define Q6_CLOSE_ALL_TIMEOUT_MS 5000 #define APM_CMD_GET_SPF_STATE 0x01001021 @@ -32,6 +31,7 @@ #define APM_CMD_RSP_GET_SPF_STATE 0x02001007 #define APM_MODULE_INSTANCE_ID 0x00000001 #define GPR_SVC_ADSP_CORE 0x3 +#define ADD_CHILD_DEVICES_APM_TIMEOUT_MS 5000 struct spf_core { struct gpr_device *adev; @@ -158,7 +158,7 @@ done: * * Return: Will return true if apm is ready and false if not. */ -bool spf_core_is_apm_ready(void) +bool spf_core_is_apm_ready(int timeout_ms) { unsigned long timeout; bool ret = false; @@ -172,13 +172,16 @@ bool spf_core_is_apm_ready(void) if (!core) goto done; - timeout = jiffies + msecs_to_jiffies(APM_STATE_READY_TIMEOUT_MS); + timeout = jiffies + msecs_to_jiffies(timeout_ms); mutex_lock(&core->lock); for (;;) { if (__spf_core_is_apm_ready(core)) { ret = true; break; } + if (!timeout_ms) + break; + usleep_range(50000, 50050); if (!time_after(timeout, jiffies)) { ret = false; @@ -336,7 +339,7 @@ static void spf_core_add_child_devices(struct work_struct *work) int ret; pr_err("%s:enumarate machine driver\n", __func__); - if(spf_core_is_apm_ready()) { + if (spf_core_is_apm_ready(ADD_CHILD_DEVICES_APM_TIMEOUT_MS)) { dev_err(spf_core_priv->dev, "%s: apm is up\n", __func__); } else { diff --git a/include/dsp/spf-core.h b/include/dsp/spf-core.h index 1e5e2ba2c3..61f8aea920 100644 --- a/include/dsp/spf-core.h +++ b/include/dsp/spf-core.h @@ -1,4 +1,5 @@ /* Copyright (c) 2019-2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -14,7 +15,7 @@ #define __SPF_CORE_H__ #include -bool spf_core_is_apm_ready(void); +bool spf_core_is_apm_ready(int timeout_ms); void spf_core_apm_close_all(void); #endif diff --git a/ipc/gpr-lite.c b/ipc/gpr-lite.c index dd22d393cb..44c7ca8243 100644 --- a/ipc/gpr-lite.c +++ b/ipc/gpr-lite.c @@ -1,6 +1,6 @@ /* Copyright (c) 2011-2017, 2019-2021 The Linux Foundation. All rights reserved. * Copyright (c) 2018, Linaro Limited - * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 and @@ -95,6 +95,11 @@ int gpr_send_pkt(struct gpr_device *adev, struct gpr_pkt *pkt) uint32_t pkt_size; int ret; + if (gpr_get_q6_state() == GPR_SUBSYS_DOWN) { + pr_err_ratelimited("%s: q6 state is down\n", __func__); + return -EINVAL; + } + if(!adev) { pr_err_ratelimited("%s: enter pointer adev[%pK] \n", __func__, adev); @@ -118,13 +123,11 @@ int gpr_send_pkt(struct gpr_device *adev, struct gpr_pkt *pkt) if ((adev->domain_id == GPR_DOMAIN_ADSP) && (gpr_get_q6_state() != GPR_SUBSYS_LOADED)) { - dev_err_ratelimited(gpr->dev, "%s: domain_id[%d], Still Dsp is not Up\n", - __func__, adev->domain_id); + dev_err_ratelimited(gpr->dev, "%s: Still Dsp is not Up\n", __func__); return -ENETRESET; - } else if ((adev->domain_id == GPR_DOMAIN_MODEM) && + } else if ((adev->domain_id == GPR_DOMAIN_MODEM) && (gpr_get_modem_state() == GPR_SUBSYS_DOWN)) { - dev_err_ratelimited(gpr->dev, "%s: domain_id[%d], Still Modem is not Up\n", - __func__, adev->domain_id ); + dev_err_ratelimited(gpr->dev, "%s: Still Modem is not Up\n", __func__); return -ENETRESET; }