diff --git a/components/esp_phy/esp32c5/phy_init_data.c b/components/esp_phy/esp32c5/phy_init_data.c index a216a678c0b..0ee2aa51599 100644 --- a/components/esp_phy/esp32c5/phy_init_data.c +++ b/components/esp_phy/esp32c5/phy_init_data.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -312,6 +312,24 @@ static esp_err_t sleep_retention_wifi_bb_init(void *arg) return ESP_OK; } +esp_err_t esp_phy_wifi_bb_sleep_retention_attach(void) +{ + esp_err_t err = sleep_retention_module_attach(SLEEP_RETENTION_MODULE_WIFI_BB); + if (err != ESP_OK) { + ESP_LOGW(TAG, "failed to attach sleep retention linked list for wifi bb retention"); + } + return err; +} + +esp_err_t esp_phy_wifi_bb_sleep_retention_detach(void) +{ + esp_err_t err = sleep_retention_module_detach(SLEEP_RETENTION_MODULE_WIFI_BB); + if (err != ESP_OK) { + ESP_LOGW(TAG, "failed to detach sleep retention linked list for wifi bb retention"); + } + return err; +} + void esp_phy_sleep_data_init(void) { sleep_retention_module_init_param_t init_param = { @@ -327,22 +345,12 @@ void esp_phy_sleep_data_init(void) err = sleep_retention_module_allocate(SLEEP_RETENTION_MODULE_WIFI_BB); if (err != ESP_OK) { ESP_LOGW(TAG, "failed to allocate sleep retention linked list for wifi bb retention"); - return; - } - err = sleep_retention_module_attach(SLEEP_RETENTION_MODULE_WIFI_BB); - if (err != ESP_OK) { - ESP_LOGW(TAG, "failed to attach sleep retention linked list for wifi bb retention"); } } void esp_phy_sleep_data_deinit(void) { - esp_err_t err = sleep_retention_module_detach(SLEEP_RETENTION_MODULE_WIFI_BB); - if (err != ESP_OK) { - ESP_LOGW(TAG, "failed to detach sleep retention linked list for wifi bb retention"); - return; - } - err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_WIFI_BB); + esp_err_t err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_WIFI_BB); if (err != ESP_OK) { ESP_LOGW(TAG, "failed to free sleep retention linked list for wifi bb retention"); return; diff --git a/components/esp_phy/esp32c6/phy_init_data.c b/components/esp_phy/esp32c6/phy_init_data.c index a32c3c4668d..068b66a6088 100644 --- a/components/esp_phy/esp32c6/phy_init_data.c +++ b/components/esp_phy/esp32c6/phy_init_data.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2016-2024 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2016-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -176,10 +176,29 @@ static esp_err_t sleep_retention_wifi_bb_init(void *arg) return ESP_OK; } +esp_err_t esp_phy_wifi_bb_sleep_retention_attach(void) +{ + esp_err_t err = sleep_retention_module_attach(SLEEP_RETENTION_MODULE_WIFI_BB); + if (err != ESP_OK) { + ESP_LOGW(TAG, "failed to attach sleep retention linked list for wifi bb retention"); + } + return err; +} + +esp_err_t esp_phy_wifi_bb_sleep_retention_detach(void) +{ + esp_err_t err = sleep_retention_module_detach(SLEEP_RETENTION_MODULE_WIFI_BB); + if (err != ESP_OK) { + ESP_LOGW(TAG, "failed to detach sleep retention linked list for wifi bb retention"); + } + return err; +} + void esp_phy_sleep_data_init(void) { sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_retention_wifi_bb_init, .arg = NULL } }, + .attribute = SLEEP_RETENTION_MODULE_ATTR_ATTACH, .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM) }; esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_WIFI_BB, &init_param); diff --git a/components/esp_phy/esp32c61/phy_init_data.c b/components/esp_phy/esp32c61/phy_init_data.c index b06b158688d..081df9a8261 100644 --- a/components/esp_phy/esp32c61/phy_init_data.c +++ b/components/esp_phy/esp32c61/phy_init_data.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2024-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2024-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -184,10 +184,29 @@ static esp_err_t sleep_retention_wifi_bb_init(void *arg) return ESP_OK; } +esp_err_t esp_phy_wifi_bb_sleep_retention_attach(void) +{ + esp_err_t err = sleep_retention_module_attach(SLEEP_RETENTION_MODULE_WIFI_BB); + if (err != ESP_OK) { + ESP_LOGW(TAG, "failed to attach sleep retention linked list for wifi bb retention"); + } + return err; +} + +esp_err_t esp_phy_wifi_bb_sleep_retention_detach(void) +{ + esp_err_t err = sleep_retention_module_detach(SLEEP_RETENTION_MODULE_WIFI_BB); + if (err != ESP_OK) { + ESP_LOGW(TAG, "failed to detach sleep retention linked list for wifi bb retention"); + } + return err; +} + void esp_phy_sleep_data_init(void) { sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_retention_wifi_bb_init, .arg = NULL } }, + .attribute = SLEEP_RETENTION_MODULE_ATTR_ATTACH, .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM) }; esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_WIFI_BB, &init_param); diff --git a/components/esp_phy/esp32s31/phy_init_data.c b/components/esp_phy/esp32s31/phy_init_data.c index 8b732ddeb5c..e6a2b1eac44 100644 --- a/components/esp_phy/esp32s31/phy_init_data.c +++ b/components/esp_phy/esp32s31/phy_init_data.c @@ -184,10 +184,29 @@ static esp_err_t sleep_retention_wifi_bb_init(void *arg) return ESP_OK; } +esp_err_t esp_phy_wifi_bb_sleep_retention_attach(void) +{ + esp_err_t err = sleep_retention_module_attach(SLEEP_RETENTION_MODULE_WIFI_BB); + if (err != ESP_OK) { + ESP_LOGW(TAG, "failed to attach sleep retention linked list for wifi bb retention"); + } + return err; +} + +esp_err_t esp_phy_wifi_bb_sleep_retention_detach(void) +{ + esp_err_t err = sleep_retention_module_detach(SLEEP_RETENTION_MODULE_WIFI_BB); + if (err != ESP_OK) { + ESP_LOGW(TAG, "failed to detach sleep retention linked list for wifi bb retention"); + } + return err; +} + void esp_phy_sleep_data_init(void) { sleep_retention_module_init_param_t init_param = { .cbs = { .create = { .handle = sleep_retention_wifi_bb_init, .arg = NULL } }, + .attribute = SLEEP_RETENTION_MODULE_ATTR_ATTACH, .depends = RETENTION_MODULE_BITMAP_INIT(CLOCK_MODEM) }; esp_err_t err = sleep_retention_module_init(SLEEP_RETENTION_MODULE_WIFI_BB, &init_param); diff --git a/components/esp_phy/include/esp_private/phy.h b/components/esp_phy/include/esp_private/phy.h index de9a9820227..dcbafcab296 100644 --- a/components/esp_phy/include/esp_private/phy.h +++ b/components/esp_phy/include/esp_private/phy.h @@ -261,6 +261,24 @@ void esp_phy_modem_rf_flag_update(void); */ void esp_phy_sleep_data_init(void); +/** + * @brief Attach WiFi BB sleep retention linked list (REGDMA) after entries are allocated in `esp_phy_sleep_data_init()`. + * + * @return + * - ESP_OK on success + * - error code from sleep retention otherwise + */ +esp_err_t esp_phy_wifi_bb_sleep_retention_attach(void); + +/** + * @brief Detach WiFi BB sleep retention linked list (REGDMA) before `sleep_retention_module_free()` in `esp_phy_sleep_data_deinit()`. + * + * @return + * - ESP_OK on success + * - error code from sleep retention otherwise + */ +esp_err_t esp_phy_wifi_bb_sleep_retention_detach(void); + /** * @brief PHY module sleep data de-initialize. */ diff --git a/components/esp_wifi/esp32c5/esp_adapter.c b/components/esp_wifi/esp32c5/esp_adapter.c index 3d3030f2d09..e21354640b7 100644 --- a/components/esp_wifi/esp32c5/esp_adapter.c +++ b/components/esp_wifi/esp32c5/esp_adapter.c @@ -35,6 +35,9 @@ #include "esp_phy_init.h" #include "phy_init_data.h" #endif +#if CONFIG_MAC_BB_PD && SOC_PM_MODEM_RETENTION_BY_REGDMA +#include "esp_private/phy.h" +#endif #include "soc/rtc_cntl_periph.h" #include "soc/rtc.h" #include "esp_private/periph_ctrl.h" @@ -646,6 +649,44 @@ static bool esp_wifi_disable_ac_ax_wrapper(void) return false; // disable 11ac and 11ax is not supported on esp32c5. } +#if SOC_PM_MODEM_RETENTION_BY_REGDMA +static int32_t esp_phy_wifi_bb_sleep_retention_attach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_phy_wifi_bb_sleep_retention_attach(); +#else + return 1; +#endif +} + +static int32_t esp_phy_wifi_bb_sleep_retention_detach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_phy_wifi_bb_sleep_retention_detach(); +#else + return 1; +#endif +} + +static int32_t esp_wifi_mac_sleep_retention_attach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_wifi_internal_mac_sleep_retention_attach(); +#else + return 1; +#endif +} + +static int32_t esp_wifi_mac_sleep_retention_detach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_wifi_internal_mac_sleep_retention_detach(); +#else + return 1; +#endif +} +#endif + wifi_osi_funcs_t g_wifi_osi_funcs = { ._version = ESP_WIFI_OS_ADAPTER_VERSION, ._env_is_chip = esp_coex_common_env_is_chip_wrapper, @@ -770,5 +811,11 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._wifi_disable_ac_ax = esp_wifi_disable_ac_ax_wrapper, +#if SOC_PM_MODEM_RETENTION_BY_REGDMA + ._wifi_bb_sleep_retention_attach = esp_phy_wifi_bb_sleep_retention_attach_wrapper, + ._wifi_bb_sleep_retention_detach = esp_phy_wifi_bb_sleep_retention_detach_wrapper, + ._wifi_mac_sleep_retention_attach = esp_wifi_mac_sleep_retention_attach_wrapper, + ._wifi_mac_sleep_retention_detach = esp_wifi_mac_sleep_retention_detach_wrapper, +#endif ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32c6/esp_adapter.c b/components/esp_wifi/esp32c6/esp_adapter.c index 3b1af40aa1a..f3eafd771ca 100644 --- a/components/esp_wifi/esp32c6/esp_adapter.c +++ b/components/esp_wifi/esp32c6/esp_adapter.c @@ -36,6 +36,9 @@ #include "esp_phy_init.h" #include "phy_init_data.h" #endif +#if CONFIG_MAC_BB_PD && SOC_PM_MODEM_RETENTION_BY_REGDMA +#include "esp_private/phy.h" +#endif #include "soc/rtc_cntl_periph.h" #include "soc/rtc.h" #include "esp_private/periph_ctrl.h" @@ -584,6 +587,44 @@ static bool esp_wifi_disable_ac_ax_wrapper(void) return false; // disable 11ac and 11ax is not supported on esp32c6. } +#if SOC_PM_MODEM_RETENTION_BY_REGDMA +static int32_t esp_phy_wifi_bb_sleep_retention_attach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_phy_wifi_bb_sleep_retention_attach(); +#else + return 1; +#endif +} + +static int32_t esp_phy_wifi_bb_sleep_retention_detach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_phy_wifi_bb_sleep_retention_detach(); +#else + return 1; +#endif +} + +static int32_t esp_wifi_mac_sleep_retention_attach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_wifi_internal_mac_sleep_retention_attach(); +#else + return 1; +#endif +} + +static int32_t esp_wifi_mac_sleep_retention_detach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_wifi_internal_mac_sleep_retention_detach(); +#else + return 1; +#endif +} +#endif + wifi_osi_funcs_t g_wifi_osi_funcs = { ._version = ESP_WIFI_OS_ADAPTER_VERSION, ._env_is_chip = esp_coex_common_env_is_chip_wrapper, @@ -708,5 +749,11 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._wifi_disable_ac_ax = esp_wifi_disable_ac_ax_wrapper, +#if SOC_PM_MODEM_RETENTION_BY_REGDMA + ._wifi_bb_sleep_retention_attach = esp_phy_wifi_bb_sleep_retention_attach_wrapper, + ._wifi_bb_sleep_retention_detach = esp_phy_wifi_bb_sleep_retention_detach_wrapper, + ._wifi_mac_sleep_retention_attach = esp_wifi_mac_sleep_retention_attach_wrapper, + ._wifi_mac_sleep_retention_detach = esp_wifi_mac_sleep_retention_detach_wrapper, +#endif ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32c61/esp_adapter.c b/components/esp_wifi/esp32c61/esp_adapter.c index f62435ef0d4..2b11cf6f64b 100644 --- a/components/esp_wifi/esp32c61/esp_adapter.c +++ b/components/esp_wifi/esp32c61/esp_adapter.c @@ -35,6 +35,9 @@ #include "esp_phy_init.h" #include "phy_init_data.h" #endif +#if CONFIG_MAC_BB_PD && SOC_PM_MODEM_RETENTION_BY_REGDMA +#include "esp_private/phy.h" +#endif #include "soc/rtc_cntl_periph.h" #include "soc/rtc.h" #include "esp_private/periph_ctrl.h" @@ -648,6 +651,44 @@ static bool esp_wifi_disable_ac_ax_wrapper(void) return esp_efuse_read_field_bit(ESP_EFUSE_DIS_WIFI6); } +#if SOC_PM_MODEM_RETENTION_BY_REGDMA +static int32_t esp_phy_wifi_bb_sleep_retention_attach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_phy_wifi_bb_sleep_retention_attach(); +#else + return 1; +#endif +} + +static int32_t esp_phy_wifi_bb_sleep_retention_detach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_phy_wifi_bb_sleep_retention_detach(); +#else + return 1; +#endif +} + +static int32_t esp_wifi_mac_sleep_retention_attach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_wifi_internal_mac_sleep_retention_attach(); +#else + return 1; +#endif +} + +static int32_t esp_wifi_mac_sleep_retention_detach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_wifi_internal_mac_sleep_retention_detach(); +#else + return 1; +#endif +} +#endif + wifi_osi_funcs_t g_wifi_osi_funcs = { ._version = ESP_WIFI_OS_ADAPTER_VERSION, ._env_is_chip = esp_coex_common_env_is_chip_wrapper, @@ -772,5 +813,11 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_flexible_period_get = coex_schm_flexible_period_get_wrapper, ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._wifi_disable_ac_ax = esp_wifi_disable_ac_ax_wrapper, +#if SOC_PM_MODEM_RETENTION_BY_REGDMA + ._wifi_bb_sleep_retention_attach = esp_phy_wifi_bb_sleep_retention_attach_wrapper, + ._wifi_bb_sleep_retention_detach = esp_phy_wifi_bb_sleep_retention_detach_wrapper, + ._wifi_mac_sleep_retention_attach = esp_wifi_mac_sleep_retention_attach_wrapper, + ._wifi_mac_sleep_retention_detach = esp_wifi_mac_sleep_retention_detach_wrapper, +#endif ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/esp32s31/esp_adapter.c b/components/esp_wifi/esp32s31/esp_adapter.c index 6e732d27f87..625f4b4b016 100644 --- a/components/esp_wifi/esp32s31/esp_adapter.c +++ b/components/esp_wifi/esp32s31/esp_adapter.c @@ -35,6 +35,9 @@ #include "esp_phy_init.h" #include "phy_init_data.h" #endif +#if CONFIG_MAC_BB_PD && SOC_PM_MODEM_RETENTION_BY_REGDMA +#include "esp_private/phy.h" +#endif #include "soc/rtc_cntl_periph.h" #include "soc/rtc.h" #include "esp_private/periph_ctrl.h" @@ -655,6 +658,44 @@ static bool esp_wifi_disable_ac_ax_wrapper(void) return false; // disable 11ac and 11ax is not supported on esp32s31. } +#if SOC_PM_MODEM_RETENTION_BY_REGDMA +static int32_t esp_phy_wifi_bb_sleep_retention_attach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_phy_wifi_bb_sleep_retention_attach(); +#else + return 1; +#endif +} + +static int32_t esp_phy_wifi_bb_sleep_retention_detach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_phy_wifi_bb_sleep_retention_detach(); +#else + return 1; +#endif +} + +static int32_t esp_wifi_mac_sleep_retention_attach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_wifi_internal_mac_sleep_retention_attach(); +#else + return 1; +#endif +} + +static int32_t esp_wifi_mac_sleep_retention_detach_wrapper(void) +{ +#if CONFIG_MAC_BB_PD + return (int32_t)esp_wifi_internal_mac_sleep_retention_detach(); +#else + return 1; +#endif +} +#endif + wifi_osi_funcs_t g_wifi_osi_funcs = { ._version = ESP_WIFI_OS_ADAPTER_VERSION, ._env_is_chip = esp_coex_common_env_is_chip_wrapper, @@ -780,5 +821,11 @@ wifi_osi_funcs_t g_wifi_osi_funcs = { ._coex_schm_get_phase_by_idx = coex_schm_get_phase_by_idx_wrapper, ._coex_configure_preemption_end_cb = coex_configure_preemption_end_cb_wrapper, ._wifi_disable_ac_ax = esp_wifi_disable_ac_ax_wrapper, +#if SOC_PM_MODEM_RETENTION_BY_REGDMA + ._wifi_bb_sleep_retention_attach = esp_phy_wifi_bb_sleep_retention_attach_wrapper, + ._wifi_bb_sleep_retention_detach = esp_phy_wifi_bb_sleep_retention_detach_wrapper, + ._wifi_mac_sleep_retention_attach = esp_wifi_mac_sleep_retention_attach_wrapper, + ._wifi_mac_sleep_retention_detach = esp_wifi_mac_sleep_retention_detach_wrapper, +#endif ._magic = ESP_WIFI_OS_ADAPTER_MAGIC, }; diff --git a/components/esp_wifi/include/esp_private/wifi.h b/components/esp_wifi/include/esp_private/wifi.h index 077f1d1354b..2d783a08d21 100644 --- a/components/esp_wifi/include/esp_private/wifi.h +++ b/components/esp_wifi/include/esp_private/wifi.h @@ -854,6 +854,26 @@ void esp_wifi_power_domain_off(void); void * esp_wifi_internal_mac_retention_context_get(int *config_size); #endif +#if CONFIG_MAC_BB_PD && SOC_PM_MODEM_RETENTION_BY_REGDMA +/** + * @brief Attach Wi-Fi MAC sleep retention (REGDMA) linked list after allocation. + * + * @return + * - ESP_OK on success + * - error code from sleep retention otherwise + */ +esp_err_t esp_wifi_internal_mac_sleep_retention_attach(void); + +/** + * @brief Detach Wi-Fi MAC sleep retention (REGDMA) linked list before free. + * + * @return + * - ESP_OK on success + * - error code from sleep retention otherwise + */ +esp_err_t esp_wifi_internal_mac_sleep_retention_detach(void); +#endif + #if CONFIG_MAC_BB_PD /** * @brief Enable or disable powering down MAC and baseband when Wi-Fi is sleeping. diff --git a/components/esp_wifi/include/esp_private/wifi_os_adapter.h b/components/esp_wifi/include/esp_private/wifi_os_adapter.h index 3315044ab23..0c9ec1e06b8 100644 --- a/components/esp_wifi/include/esp_private/wifi_os_adapter.h +++ b/components/esp_wifi/include/esp_private/wifi_os_adapter.h @@ -17,7 +17,7 @@ extern "C" { #endif -#define ESP_WIFI_OS_ADAPTER_VERSION 0x00000008 +#define ESP_WIFI_OS_ADAPTER_VERSION 0x00000009 #define ESP_WIFI_OS_ADAPTER_MAGIC 0xDEADBEAF #define OSI_FUNCS_TIME_BLOCKING 0xffffffff @@ -161,6 +161,12 @@ typedef struct wifi_osi_funcs_t { #endif #if CONFIG_SOC_WIFI_HE_SUPPORT bool (*_wifi_disable_ac_ax)(void); +#endif +#if CONFIG_IDF_TARGET_ESP32C6 || CONFIG_IDF_TARGET_ESP32C5 || CONFIG_IDF_TARGET_ESP32C61 || CONFIG_IDF_TARGET_ESP32S31 + int32_t (* _wifi_bb_sleep_retention_attach)(void); + int32_t (* _wifi_bb_sleep_retention_detach)(void); + int32_t (* _wifi_mac_sleep_retention_attach)(void); + int32_t (* _wifi_mac_sleep_retention_detach)(void); #endif int32_t _magic; } wifi_osi_funcs_t; diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index bf7ccb11fe8..e61a56b9e6d 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit bf7ccb11fe8125539f3709dc49e6d7523f3cdeb0 +Subproject commit e61a56b9e6d1a522a2f47a43ef4e7db1684c6825 diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 81394283272..216c9dfff2b 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2025 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2026 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -154,6 +154,28 @@ static esp_err_t init_wifi_mac_sleep_retention(void *arg) } #endif +#if CONFIG_MAC_BB_PD && SOC_PM_MODEM_RETENTION_BY_REGDMA +esp_err_t esp_wifi_internal_mac_sleep_retention_attach(void) +{ + esp_err_t err = sleep_retention_module_attach(SLEEP_RETENTION_MODULE_WIFI_MAC); + if (err != ESP_OK) { + ESP_LOGW(TAG, "failed to attach sleep retention linked list for wifi mac retention"); + } + esp_wifi_internal_set_mac_sleep(true); + return err; +} + +esp_err_t esp_wifi_internal_mac_sleep_retention_detach(void) +{ + esp_wifi_internal_set_mac_sleep(false); + esp_err_t err = sleep_retention_module_detach(SLEEP_RETENTION_MODULE_WIFI_MAC); + if (err != ESP_OK) { + ESP_LOGW(TAG, "failed to detach sleep retention linked list for wifi mac retention"); + } + return err; +} +#endif + #if CONFIG_MAC_BB_PD static void esp_wifi_mac_pd_mem_init(void) { @@ -162,25 +184,19 @@ static void esp_wifi_mac_pd_mem_init(void) if (err != ESP_OK) { ESP_LOGW(TAG, "failed to allocate sleep retention linked list for wifi mac retention"); } - err = sleep_retention_module_attach(SLEEP_RETENTION_MODULE_WIFI_MAC); - if (err != ESP_OK) { - ESP_LOGW(TAG, "failed to attach sleep retention linked list for wifi mac retention"); - } -#endif +#else esp_wifi_internal_set_mac_sleep(true); +#endif } static void esp_wifi_mac_pd_mem_deinit(void) { - esp_wifi_internal_set_mac_sleep(false); #if SOC_PM_MODEM_RETENTION_BY_REGDMA - esp_err_t err = sleep_retention_module_detach(SLEEP_RETENTION_MODULE_WIFI_MAC); - if (err != ESP_OK) { - ESP_LOGW(TAG, "failed to detach sleep retention linked list for wifi mac retention"); - } - err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_WIFI_MAC); + esp_err_t err = sleep_retention_module_free(SLEEP_RETENTION_MODULE_WIFI_MAC); if (err != ESP_OK) { ESP_LOGW(TAG, "failed to free sleep retention linked list for wifi mac retention"); } +#else + esp_wifi_internal_set_mac_sleep(false); #endif } #endif