diff --git a/components/esp_hw_support/include/esp_private/sleep_modem.h b/components/esp_hw_support/include/esp_private/sleep_modem.h index 2e84830b6d..fe8e3ea220 100644 --- a/components/esp_hw_support/include/esp_private/sleep_modem.h +++ b/components/esp_hw_support/include/esp_private/sleep_modem.h @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -161,6 +161,35 @@ void esp_pm_register_light_sleep_default_params_config_callback(update_light_sle */ void esp_pm_unregister_light_sleep_default_params_config_callback(void); +#if SOC_PM_SUPPORT_PMU_MODEM_STATE +/** + * @brief Init Wi-Fi modem state. + * + * This function init wifi modem state. + * @return + * - ESP_OK on success + * - ESP_ERR_NO_MEM if no memory for link + */ +esp_err_t sleep_modem_wifi_modem_state_init(void); + +/** + * @brief Deinit Wi-Fi modem state. + * + * This function deinit wifi modem state. + */ +void sleep_modem_wifi_modem_state_deinit(void); + +/** + * @brief Function to check Wi-Fi modem state to skip light sleep. + * + * This function is to check if light sleep should skip by Wi-Fi modem state . + * @return + * - true skip light sleep + * - false not skip light sleep + */ +bool sleep_modem_wifi_modem_state_skip_light_sleep(void); +#endif + #ifdef __cplusplus } #endif diff --git a/components/esp_hw_support/sleep_modem.c b/components/esp_hw_support/sleep_modem.c index aeadef2f33..694f462bb6 100644 --- a/components/esp_hw_support/sleep_modem.c +++ b/components/esp_hw_support/sleep_modem.c @@ -167,7 +167,7 @@ typedef struct sleep_modem_config { static sleep_modem_config_t s_sleep_modem = { .wifi.phy_link = NULL, .wifi.flags = 0 }; -static __attribute__((unused)) esp_err_t sleep_modem_wifi_modem_state_init(void) +esp_err_t sleep_modem_wifi_modem_state_init(void) { esp_err_t err = ESP_OK; phy_i2c_master_command_attribute_t cmd; @@ -244,7 +244,7 @@ static __attribute__((unused)) esp_err_t sleep_modem_wifi_modem_state_init(void) return err; } -static __attribute__((unused)) void sleep_modem_wifi_modem_state_deinit(void) +__attribute__((unused)) void sleep_modem_wifi_modem_state_deinit(void) { if (s_sleep_modem.wifi.phy_link) { regdma_link_destroy(s_sleep_modem.wifi.phy_link, 0); @@ -302,7 +302,7 @@ uint32_t IRAM_ATTR sleep_modem_reject_triggers(void) return reject_triggers; } -static __attribute__((unused)) bool IRAM_ATTR sleep_modem_wifi_modem_state_skip_light_sleep(void) +bool IRAM_ATTR sleep_modem_wifi_modem_state_skip_light_sleep(void) { bool skip = false; #if SOC_PM_SUPPORT_PMU_MODEM_STATE @@ -317,17 +317,8 @@ static __attribute__((unused)) bool IRAM_ATTR sleep_modem_wifi_modem_state_skip_ esp_err_t sleep_modem_configure(int max_freq_mhz, int min_freq_mhz, bool light_sleep_enable) { #if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP - extern int esp_wifi_internal_mac_sleep_configure(bool, bool); - if (light_sleep_enable) { - if (sleep_modem_wifi_modem_state_init() == ESP_OK) { - esp_pm_register_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep); - esp_wifi_internal_mac_sleep_configure(light_sleep_enable, true); /* require WiFi to enable automatically receives the beacon */ - } - } else { - esp_wifi_internal_mac_sleep_configure(light_sleep_enable, false); /* require WiFi to disable automatically receives the beacon */ - esp_pm_unregister_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep); - sleep_modem_wifi_modem_state_deinit(); - } + extern int esp_wifi_internal_light_sleep_configure(bool); + esp_wifi_internal_light_sleep_configure(light_sleep_enable); #endif #if CONFIG_PM_SLP_DEFAULT_PARAMS_OPT if (light_sleep_enable) { diff --git a/components/esp_phy/src/phy_init.c b/components/esp_phy/src/phy_init.c index 1a6ccfdde0..467c12a67a 100644 --- a/components/esp_phy/src/phy_init.c +++ b/components/esp_phy/src/phy_init.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -85,8 +85,10 @@ static bool s_is_phy_calibrated = false; static bool s_is_phy_reg_stored = false; /* Memory to store PHY digital registers */ static uint32_t* s_phy_digital_regs_mem = NULL; -static uint8_t s_phy_modem_init_ref = 0; #endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA +#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA || CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP +static uint8_t s_phy_modem_init_ref = 0; +#endif #if CONFIG_ESP_PHY_MULTIPLE_INIT_DATA_BIN @@ -349,23 +351,29 @@ void esp_wifi_bt_power_domain_off(void) void esp_phy_modem_init(void) { -#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA +#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA || CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP _lock_acquire(&s_phy_access_lock); s_phy_modem_init_ref++; +#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA if (s_phy_digital_regs_mem == NULL) { s_phy_digital_regs_mem = (uint32_t *)heap_caps_malloc(SOC_PHY_DIG_REGS_MEM_SIZE, MALLOC_CAP_DMA|MALLOC_CAP_INTERNAL); } - _lock_release(&s_phy_access_lock); #endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA +#if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP + sleep_modem_wifi_modem_state_init(); +#endif // CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP + _lock_release(&s_phy_access_lock); +#endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA || CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP } void esp_phy_modem_deinit(void) { -#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA +#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA || CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP _lock_acquire(&s_phy_access_lock); s_phy_modem_init_ref--; if (s_phy_modem_init_ref == 0) { +#if SOC_PM_MODEM_RETENTION_BY_BACKUPDMA s_is_phy_reg_stored = false; free(s_phy_digital_regs_mem); s_phy_digital_regs_mem = NULL; @@ -374,11 +382,14 @@ void esp_phy_modem_deinit(void) */ #if CONFIG_IDF_TARGET_ESP32C3 phy_init_flag(); -#endif - } - - _lock_release(&s_phy_access_lock); +#endif // CONFIG_IDF_TARGET_ESP32C3 #endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA +#if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP + sleep_modem_wifi_modem_state_deinit(); +#endif // CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP + } + _lock_release(&s_phy_access_lock); +#endif // SOC_PM_MODEM_RETENTION_BY_BACKUPDMA || CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP } #if CONFIG_MAC_BB_PD diff --git a/components/esp_pm/pm_impl.c b/components/esp_pm/pm_impl.c index 615eaf31c3..0cf529912a 100644 --- a/components/esp_pm/pm_impl.c +++ b/components/esp_pm/pm_impl.c @@ -121,6 +121,8 @@ static bool s_skipped_light_sleep[portNUM_PROCESSORS]; */ static bool s_skip_light_sleep[portNUM_PROCESSORS]; #endif // portNUM_PROCESSORS == 2 + +static _lock_t s_skip_light_sleep_lock; #endif // CONFIG_FREERTOS_USE_TICKLESS_IDLE /* A flag indicating that Idle hook has run on a given CPU; @@ -546,25 +548,32 @@ static void IRAM_ATTR leave_idle(void) esp_err_t esp_pm_register_skip_light_sleep_callback(skip_light_sleep_cb_t cb) { + _lock_acquire(&s_skip_light_sleep_lock); for (int i = 0; i < PERIPH_SKIP_LIGHT_SLEEP_NO; i++) { if (s_periph_skip_light_sleep_cb[i] == cb) { + _lock_release(&s_skip_light_sleep_lock); return ESP_OK; } else if (s_periph_skip_light_sleep_cb[i] == NULL) { s_periph_skip_light_sleep_cb[i] = cb; + _lock_release(&s_skip_light_sleep_lock); return ESP_OK; } } + _lock_release(&s_skip_light_sleep_lock); return ESP_ERR_NO_MEM; } esp_err_t esp_pm_unregister_skip_light_sleep_callback(skip_light_sleep_cb_t cb) { + _lock_acquire(&s_skip_light_sleep_lock); for (int i = 0; i < PERIPH_SKIP_LIGHT_SLEEP_NO; i++) { if (s_periph_skip_light_sleep_cb[i] == cb) { s_periph_skip_light_sleep_cb[i] = NULL; + _lock_release(&s_skip_light_sleep_lock); return ESP_OK; } } + _lock_release(&s_skip_light_sleep_lock); return ESP_ERR_INVALID_STATE; } diff --git a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld index 55d4a555cf..806d9440ea 100644 --- a/components/esp_rom/esp32c2/ld/esp32c2.rom.ld +++ b/components/esp_rom/esp32c2/ld/esp32c2.rom.ld @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2021-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -1494,9 +1494,9 @@ g_os_mempool_list = 0x3fcdfdf0; esp_pp_rom_version_get = 0x40001ad4; RC_GetBlockAckTime = 0x40001ad8; ebuf_list_remove = 0x40001adc; -esf_buf_alloc = 0x40001ae0; -esf_buf_alloc_dynamic = 0x40001ae4; -esf_buf_recycle = 0x40001ae8; +/*esf_buf_alloc = 0x40001ae0;*/ +/*esf_buf_alloc_dynamic = 0x40001ae4;*/ +/*esf_buf_recycle = 0x40001ae8;*/ GetAccess = 0x40001aec; hal_mac_is_low_rate_enabled = 0x40001af0; hal_mac_tx_get_blockack = 0x40001af4; @@ -1625,7 +1625,7 @@ wDev_AppendRxBlocks = 0x40001cdc; wDev_DiscardFrame = 0x40001ce0; wDev_GetNoiseFloor = 0x40001ce4; wDev_IndicateAmpdu = 0x40001ce8; -wDev_IndicateFrame = 0x40001cec; +/*wDev_IndicateFrame = 0x40001cec;*/ wdev_mac_reg_load = 0x40001cf0; wdev_mac_reg_store = 0x40001cf4; wdev_mac_special_reg_load = 0x40001cf8; @@ -1633,7 +1633,7 @@ wdev_mac_special_reg_store = 0x40001cfc; wdev_mac_wakeup = 0x40001d00; wdev_mac_sleep = 0x40001d04; /* wDev_ProcessFiq = 0x40001d08; */ -wDev_ProcessRxSucData = 0x40001d0c; +/*wDev_ProcessRxSucData = 0x40001d0c;*/ wdevProcessRxSucDataAll = 0x40001d10; wdev_csi_len_align = 0x40001d14; ppDequeueTxDone_Locked = 0x40001d18; @@ -1934,7 +1934,7 @@ ieee80211_vnd_lora_ie_set = 0x400020bc; ieee80211_add_wme_param = 0x400020c0; ieee80211_add_dsparams = 0x400020c4; ieee80211_add_csa = 0x400020c8; -ieee80211_add_extcap = 0x400020cc; +/*ieee80211_add_extcap = 0x400020cc;*/ ieee80211_regdomain_get_country = 0x400020d0; ieee80211_add_countryie = 0x400020d4; ieee80211_amsdu_adjust_head = 0x400020dc; diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld index 13940e252f..8c3b31e942 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.eco3.ld @@ -3,8 +3,8 @@ ESP32C3 ECO3 ROM address table Version 3 API's imported from the ROM */ -esf_buf_alloc_dynamic = 0x400015c0; -esf_buf_recycle = 0x400015c4; +/*esf_buf_alloc_dynamic = 0x400015c0;*/ +/*esf_buf_recycle = 0x400015c4;*/ /*lmacTxDone = 0x4000162c;*/ /*ppMapTxQueue = 0x400016d8;*/ /*rcGetSched = 0x40001764;*/ diff --git a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld index 49d887783f..b2f63271c7 100644 --- a/components/esp_rom/esp32c3/ld/esp32c3.rom.ld +++ b/components/esp_rom/esp32c3/ld/esp32c3.rom.ld @@ -1583,7 +1583,7 @@ r_sch_plan_offset_req_hook = 0x40001ce4; esp_pp_rom_version_get = 0x400015b0; RC_GetBlockAckTime = 0x400015b4; ebuf_list_remove = 0x400015b8; -esf_buf_alloc = 0x400015bc; +/*esf_buf_alloc = 0x400015bc;*/ GetAccess = 0x400015c8; hal_mac_is_low_rate_enabled = 0x400015cc; hal_mac_tx_get_blockack = 0x400015d0; @@ -1707,7 +1707,7 @@ wDev_AppendRxBlocks = 0x400017b8; wDev_DiscardFrame = 0x400017bc; wDev_GetNoiseFloor = 0x400017c0; wDev_IndicateAmpdu = 0x400017c4; -wDev_IndicateFrame = 0x400017c8; +/*wDev_IndicateFrame = 0x400017c8;*/ wdev_bank_store = 0x400017cc; wdev_bank_load = 0x400017d0; wdev_mac_reg_load = 0x400017d4; @@ -1718,7 +1718,7 @@ wdev_mac_wakeup = 0x400017e4; wdev_mac_sleep = 0x400017e8; hal_mac_is_dma_enable = 0x400017ec; /*wDev_ProcessFiq = 0x400017f0;*/ -wDev_ProcessRxSucData = 0x400017f4; +/*wDev_ProcessRxSucData = 0x400017f4;*/ wdevProcessRxSucDataAll = 0x400017f8; wdev_csi_len_align = 0x400017fc; ppDequeueTxDone_Locked = 0x40001800; diff --git a/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld b/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld index 10b0a3e6b3..5cfc163ddc 100644 --- a/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld +++ b/components/esp_rom/esp32c6/ld/esp32c6.rom.pp.ld @@ -22,7 +22,7 @@ esp_pp_rom_version_get = 0x40000bd8; ppCalTxopRTSThreshold = 0x40000bdc; RC_GetBlockAckTime = 0x40000be0; ebuf_list_remove = 0x40000be4; -esf_buf_alloc = 0x40000be8; +//esf_buf_alloc = 0x40000be8; //esf_buf_alloc_dynamic = 0x40000bec; //esf_buf_recycle = 0x40000bf0; GetAccess = 0x40000bf4; @@ -149,7 +149,7 @@ wDev_AppendRxBlocks = 0x40000dd4; wDev_DiscardFrame = 0x40000dd8; wDev_GetNoiseFloor = 0x40000ddc; wDev_IndicateAmpdu = 0x40000de0; -wDev_IndicateFrame = 0x40000de4; +//wDev_IndicateFrame = 0x40000de4; wdev_mac_reg_load = 0x40000de8; wdev_mac_reg_store = 0x40000dec; wdev_mac_special_reg_load = 0x40000df0; diff --git a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld index fd55961bf3..f7e8058c22 100644 --- a/components/esp_rom/esp32s3/ld/esp32s3.rom.ld +++ b/components/esp_rom/esp32s3/ld/esp32s3.rom.ld @@ -1891,8 +1891,8 @@ r_sch_plan_offset_req_hook = 0x40001ce4; esp_pp_rom_version_get = 0x40005250; RC_GetBlockAckTime = 0x4000525c; ebuf_list_remove = 0x40005268; -esf_buf_alloc = 0x40005274; -esf_buf_alloc_dynamic = 0x40005280; +/*esf_buf_alloc = 0x40005274;*/ +/*esf_buf_alloc_dynamic = 0x40005280;*/ /*esf_buf_recycle = 0x4000528c;*/ GetAccess = 0x40005298; hal_mac_is_low_rate_enabled = 0x400052a4; @@ -2021,7 +2021,7 @@ wDev_AppendRxBlocks = 0x40005868; wDev_DiscardFrame = 0x40005874; wDev_GetNoiseFloor = 0x40005880; wDev_IndicateAmpdu = 0x4000588c; -wDev_IndicateFrame = 0x40005898; +/*wDev_IndicateFrame = 0x40005898;*/ wdev_bank_store = 0x400058a4; wdev_bank_load = 0x400058b0; wdev_mac_reg_load = 0x400058bc; @@ -2032,7 +2032,7 @@ wdev_mac_wakeup = 0x400058ec; wdev_mac_sleep = 0x400058f8; hal_mac_is_dma_enable = 0x40005904; /* wDev_ProcessFiq = 0x40005910; */ -wDev_ProcessRxSucData = 0x4000591c; +/*wDev_ProcessRxSucData = 0x4000591c;*/ wdevProcessRxSucDataAll = 0x40005928; wdev_csi_len_align = 0x40005934; ppDequeueTxDone_Locked = 0x40005940; diff --git a/components/esp_wifi/Kconfig b/components/esp_wifi/Kconfig index 8698af9555..0d52f1ec4d 100644 --- a/components/esp_wifi/Kconfig +++ b/components/esp_wifi/Kconfig @@ -113,6 +113,40 @@ menu "Wi-Fi" can deliver frames faster than WiFi layer can transmit. In these cases, we may run out of TX buffers. + choice ESP_WIFI_MGMT_RX_BUFFER + prompt "Type of WiFi RX MGMT buffers" + default ESP_WIFI_STATIC_RX_MGMT_BUFFER + help + Select type of WiFi RX MGMT buffers: + + If "Static" is selected, WiFi RX MGMT buffers are allocated when WiFi is initialized and released + when WiFi is de-initialized. The size of each static RX MGMT buffer is fixed to about 500 Bytes. + + If "Dynamic" is selected, each WiFi RX MGMT buffer is allocated as needed when a MGMT data frame is + received. The MGMT buffer is freed after the MGMT data frame has been processed by the WiFi driver. + + + config ESP_WIFI_STATIC_RX_MGMT_BUFFER + bool "Static" + config ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER + bool "Dynamic" + endchoice + + config ESP_WIFI_DYNAMIC_RX_MGMT_BUF + int + default 0 if ESP_WIFI_STATIC_RX_MGMT_BUFFER + default 1 if ESP_WIFI_DYNAMIC_RX_MGMT_BUFFER + + config ESP_WIFI_RX_MGMT_BUF_NUM_DEF + int "Max number of WiFi RX MGMT buffers" + range 1 10 + default 5 + help + Set the number of WiFi RX_MGMT buffers. + + For Management buffers, the number of dynamic and static management buffers is the same. + In order to prevent memory fragmentation, the management buffer type should be set to static first. + config ESP_WIFI_CSI_ENABLED bool "WiFi CSI(Channel State Information)" depends on SOC_WIFI_CSI_SUPPORT diff --git a/components/esp_wifi/include/esp_now.h b/components/esp_wifi/include/esp_now.h index 2a39856601..728c69ba5e 100644 --- a/components/esp_wifi/include/esp_now.h +++ b/components/esp_wifi/include/esp_now.h @@ -264,7 +264,9 @@ esp_err_t esp_now_mod_peer(const esp_now_peer_info_t *peer); * - ESP_OK: succeed * - others: failed */ -esp_err_t esp_wifi_config_espnow_rate(wifi_interface_t ifx, wifi_phy_rate_t rate); +esp_err_t esp_wifi_config_espnow_rate(wifi_interface_t ifx, wifi_phy_rate_t rate) + __attribute__((deprecated("This API can be only used when rate is non-HE rate, \ + please use esp_now_set_peer_rate_config if you want full support of the rate."))); /** * @brief Set ESPNOW rate config for each peer diff --git a/components/esp_wifi/include/esp_private/esp_wifi_he_types_private.h b/components/esp_wifi/include/esp_private/esp_wifi_he_types_private.h index f807cd60aa..4aa855fbda 100644 --- a/components/esp_wifi/include/esp_private/esp_wifi_he_types_private.h +++ b/components/esp_wifi/include/esp_private/esp_wifi_he_types_private.h @@ -235,10 +235,10 @@ typedef struct { int64_t tx_start_time; int64_t tx_seqno_time; int64_t tx_muedca_time; - int64_t tx_max_muedca_time; - int64_t tx_min_muedca_time; - int64_t tx_tot_muedca_time; - int64_t muedca_times; + uint32_t tx_max_muedca_time; + uint32_t tx_min_muedca_time; + uint32_t tx_tot_muedca_time; + uint32_t muedca_times; uint32_t tx_muedca_enable; /* count TX times within mu-timer working */ uint32_t collision; uint32_t timeout; diff --git a/components/esp_wifi/include/esp_private/wifi.h b/components/esp_wifi/include/esp_private/wifi.h index acb18626ef..fc7ae119b0 100644 --- a/components/esp_wifi/include/esp_private/wifi.h +++ b/components/esp_wifi/include/esp_private/wifi.h @@ -629,15 +629,23 @@ void esp_wifi_set_keep_alive_time(uint32_t keep_alive_time); void esp_wifi_beacon_monitor_configure(wifi_beacon_monitor_config_t *config); /** - * @brief Require WiFi to enable or disable Advanced DTIM sleep function + * @brief Set modem state mode to require WiFi to enable or disable Advanced DTIM sleep function * - * @param light_sleep_enable: true for light sleep mode is enabled, false for light sleep mode is disabled. - * @param modem_state_enable: true for require WiFi to enable Advanced DTIM sleep function, + * @param require_modem_state: true for require WiFi to enable Advanced DTIM sleep function, * false for require WiFi to disable Advanced DTIM sleep function. * @return * - ESP_OK: succeed */ -void esp_wifi_internal_mac_sleep_configure(bool light_sleep_enable, bool modem_state_enable); +void esp_wifi_internal_modem_state_configure(bool require_modem_state); + +/** + * @brief Set light sleep mode to require WiFi to enable or disable Advanced DTIM sleep function + * + * @param light_sleep_enable: true for light sleep mode is enabled, false for light sleep mode is disabled. + * @return + * - ESP_OK: succeed + */ +void esp_wifi_internal_light_sleep_configure(bool light_sleep_enable); /** * @brief Start Publishing a service in the NAN cluster diff --git a/components/esp_wifi/include/esp_wifi.h b/components/esp_wifi/include/esp_wifi.h index dcaaee7f54..4a233406e5 100644 --- a/components/esp_wifi/include/esp_wifi.h +++ b/components/esp_wifi/include/esp_wifi.h @@ -100,6 +100,8 @@ typedef struct { int tx_buf_type; /**< WiFi TX buffer type */ int static_tx_buf_num; /**< WiFi static TX buffer number */ int dynamic_tx_buf_num; /**< WiFi dynamic TX buffer number */ + int rx_mgmt_buf_type; /**< WiFi RX MGMT buffer type */ + int rx_mgmt_buf_num; /**< WiFi RX MGMT buffer number */ int cache_tx_buf_num; /**< WiFi TX cache buffer number */ int csi_enable; /**< WiFi channel state information enable flag */ int ampdu_rx_enable; /**< WiFi AMPDU RX feature enable flag */ @@ -135,6 +137,12 @@ typedef struct { #define WIFI_DYNAMIC_TX_BUFFER_NUM 0 #endif +#ifdef CONFIG_ESP_WIFI_RX_MGMT_BUF_NUM_DEF +#define WIFI_RX_MGMT_BUF_NUM_DEF CONFIG_ESP_WIFI_RX_MGMT_BUF_NUM_DEF +#else +#define WIFI_RX_MGMT_BUF_NUM_DEF 0 +#endif + #if CONFIG_ESP_WIFI_CSI_ENABLED #define WIFI_CSI_ENABLED 1 #else @@ -219,6 +227,8 @@ extern uint64_t g_wifi_feature_caps; .tx_buf_type = CONFIG_ESP_WIFI_TX_BUFFER_TYPE,\ .static_tx_buf_num = WIFI_STATIC_TX_BUFFER_NUM,\ .dynamic_tx_buf_num = WIFI_DYNAMIC_TX_BUFFER_NUM,\ + .rx_mgmt_buf_type = CONFIG_ESP_WIFI_DYNAMIC_RX_MGMT_BUF,\ + .rx_mgmt_buf_num = WIFI_RX_MGMT_BUF_NUM_DEF,\ .cache_tx_buf_num = WIFI_CACHE_TX_BUFFER_NUM,\ .csi_enable = WIFI_CSI_ENABLED,\ .ampdu_rx_enable = WIFI_AMPDU_RX_ENABLED,\ @@ -1261,6 +1271,32 @@ esp_err_t esp_wifi_config_11b_rate(wifi_interface_t ifx, bool disable); */ esp_err_t esp_wifi_connectionless_module_set_wake_interval(uint16_t wake_interval); +/** + * @brief Request extra reference of Wi-Fi radio. + * Wi-Fi keep active state(RF opened) to be able to receive packets. + * + * @attention Please pair the use of `esp_wifi_force_wakeup_acquire` with `esp_wifi_force_wakeup_release`. + * + * @return + * - ESP_OK: succeed + * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init + * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start + */ +esp_err_t esp_wifi_force_wakeup_acquire(void); + +/** + * @brief Release extra reference of Wi-Fi radio. + * Wi-Fi go to sleep state(RF closed) if no more use of radio. + * + * @attention Please pair the use of `esp_wifi_force_wakeup_acquire` with `esp_wifi_force_wakeup_release`. + * + * @return + * - ESP_OK: succeed + * - ESP_ERR_WIFI_NOT_INIT: WiFi is not initialized by esp_wifi_init + * - ESP_ERR_WIFI_NOT_STARTED: WiFi is not started by esp_wifi_start + */ +esp_err_t esp_wifi_force_wakeup_release(void); + /** * @brief configure country * diff --git a/components/esp_wifi/include/esp_wifi_he_types.h b/components/esp_wifi/include/esp_wifi_he_types.h index f7c1b9a59e..01f753dddb 100644 --- a/components/esp_wifi/include/esp_wifi_he_types.h +++ b/components/esp_wifi/include/esp_wifi_he_types.h @@ -158,12 +158,11 @@ typedef struct { unsigned : 15; /**< reserved */ unsigned : 2; /**< reserved */ unsigned noise_floor : 8; /**< the noise floor of the reception frame */ - signed data_rssi : 8; /**< the RSSI of the DATA field */ - unsigned : 8; /**< reserved */ - unsigned : 8; /**< reserved */ unsigned channel : 4; /**< the primary channel */ unsigned second : 4; /**< the second channel if in HT40 */ - unsigned : 24; /**< reserved */ + unsigned : 8; /**< reserved */ + unsigned : 8; /**< reserved */ + unsigned : 32; /**< reserved */ unsigned : 32; /**< reserved */ unsigned : 2; /**< reserved */ unsigned : 4; /**< reserved */ diff --git a/components/esp_wifi/lib b/components/esp_wifi/lib index c2b2ae5381..7759f9bdf0 160000 --- a/components/esp_wifi/lib +++ b/components/esp_wifi/lib @@ -1 +1 @@ -Subproject commit c2b2ae53810965f75d6b866deb802b01d316cc1f +Subproject commit 7759f9bdf087eb7fb31e4a612b4d310633fb4dcb diff --git a/components/esp_wifi/src/wifi_init.c b/components/esp_wifi/src/wifi_init.c index 232e6fbbbf..467d645656 100644 --- a/components/esp_wifi/src/wifi_init.c +++ b/components/esp_wifi/src/wifi_init.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -167,6 +167,10 @@ esp_err_t esp_wifi_deinit(void) #if CONFIG_MAC_BB_PD esp_wifi_internal_set_mac_sleep(false); esp_mac_bb_pd_mem_deinit(); +#endif +#if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP + esp_wifi_internal_modem_state_configure(false); + esp_pm_unregister_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep); #endif esp_phy_modem_deinit(); @@ -231,12 +235,12 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) #endif #if CONFIG_ESP_WIFI_SLP_IRAM_OPT - esp_pm_register_light_sleep_default_params_config_callback(esp_wifi_internal_update_light_sleep_default_params); - int min_freq_mhz = esp_pm_impl_get_cpu_freq(PM_MODE_LIGHT_SLEEP); int max_freq_mhz = esp_pm_impl_get_cpu_freq(PM_MODE_CPU_MAX); esp_wifi_internal_update_light_sleep_default_params(min_freq_mhz, max_freq_mhz); + esp_pm_register_light_sleep_default_params_config_callback(esp_wifi_internal_update_light_sleep_default_params); + uint32_t sleep_delay_us = CONFIG_ESP_WIFI_SLP_DEFAULT_MIN_ACTIVE_TIME * 1000; esp_wifi_set_sleep_delay_time(sleep_delay_us); @@ -291,6 +295,12 @@ esp_err_t esp_wifi_init(const wifi_init_config_t *config) esp_wifi_internal_set_mac_sleep(true); #endif esp_phy_modem_init(); +#if CONFIG_ESP_WIFI_ENHANCED_LIGHT_SLEEP + if (sleep_modem_wifi_modem_state_enabled()) { + esp_pm_register_skip_light_sleep_callback(sleep_modem_wifi_modem_state_skip_light_sleep); + esp_wifi_internal_modem_state_configure(true); /* require WiFi to enable automatically receives the beacon */ + } +#endif #if CONFIG_IDF_TARGET_ESP32 s_wifi_mac_time_update_cb = esp_wifi_internal_update_mac_time; #endif diff --git a/components/wpa_supplicant/esp_supplicant/src/esp_common.c b/components/wpa_supplicant/esp_supplicant/src/esp_common.c index 19176028fd..20c2c1187b 100644 --- a/components/wpa_supplicant/esp_supplicant/src/esp_common.c +++ b/components/wpa_supplicant/esp_supplicant/src/esp_common.c @@ -22,6 +22,7 @@ #include "esp_wnm.h" #include "rsn_supp/wpa_i.h" #include "rsn_supp/wpa.h" +#include "esp_private/wifi.h" /* Utility Functions */ esp_err_t esp_supplicant_str_to_mac(const char *str, uint8_t dest[6]) @@ -652,6 +653,8 @@ static uint8_t get_extended_caps_ie(uint8_t *ie, size_t len) uint8_t ext_caps_ie[5] = {0}; uint8_t ext_caps_ie_len = 3; uint8_t *pos = ext_caps_ie; + wifi_ioctl_config_t cfg = {0}; + esp_err_t err = 0; if (!esp_wifi_is_btm_enabled_internal(WIFI_IF_STA)) { return 0; @@ -659,8 +662,14 @@ static uint8_t get_extended_caps_ie(uint8_t *ie, size_t len) *pos++ = WLAN_EID_EXT_CAPAB; *pos++ = ext_caps_ie_len; - *pos++ = 0; - *pos++ = 0; + + err = esp_wifi_internal_ioctl(WIFI_IOCTL_GET_STA_HT2040_COEX, &cfg); + if (err == ESP_OK && cfg.data.ht2040_coex.enable) { + *pos++ |= BIT(WLAN_EXT_CAPAB_20_40_COEX); + } else { + *pos++ = 0; + } + *pos ++ = 0; #define CAPAB_BSS_TRANSITION BIT(3) *pos |= CAPAB_BSS_TRANSITION; #undef CAPAB_BSS_TRANSITION @@ -872,9 +881,6 @@ void esp_set_assoc_ie(uint8_t *bssid, const u8 *ies, size_t ies_len, bool mdie) } pos = ie; #ifdef CONFIG_IEEE80211KV - ie_len = get_extended_caps_ie(pos, len); - pos += ie_len; - len -= ie_len; ie_len = get_rm_enabled_ie(pos, len); pos += ie_len; len -= ie_len; diff --git a/components/wpa_supplicant/src/common/ieee802_11_defs.h b/components/wpa_supplicant/src/common/ieee802_11_defs.h index 8d5f3aea2b..3c7eab6a44 100644 --- a/components/wpa_supplicant/src/common/ieee802_11_defs.h +++ b/components/wpa_supplicant/src/common/ieee802_11_defs.h @@ -261,6 +261,7 @@ #define WLAN_RSNX_CAPAB_SAE_H2E 5 #define WLAN_RSNX_CAPAB_SAE_PK 6 +#define WLAN_EXT_CAPAB_20_40_COEX 0 #define WLAN_EXT_CAPAB_BSS_TRANSITION 19 /* Action frame categories (IEEE Std 802.11-2016, 9.4.1.11, Table 9-76) */ diff --git a/examples/common_components/iperf/wifi_stats.c b/examples/common_components/iperf/wifi_stats.c index f10cc3b71c..2a1cd07c71 100644 --- a/examples/common_components/iperf/wifi_stats.c +++ b/examples/common_components/iperf/wifi_stats.c @@ -210,7 +210,7 @@ int wifi_cmd_get_tx_statistics(int argc, char **argv) tx_stats.collision, tx_stats.timeout); float tot_rtt_ms = (float) tx_stats.tx_tot_rtt / (float) 1000; - printf("(test)aci:%" PRIu8 ", seqno_rtt[%" PRIu32 ",%" PRIu32 "], hw_rtt[%" PRIu32 ", %" PRIu32 "], muedca[enable:%" PRIu32 ", times:%" PRIi64 ", %.2f, %.2f, tot:%.2f], avg:%.3f ms, tot:%.3f secs\n", + printf("(test)aci:%" PRIu8 ", seqno_rtt[%" PRIu32 ",%" PRIu32 "], hw_rtt[%" PRIu32 ", %" PRIu32 "], muedca[enable:%" PRIu32 ", times:%" PRIu32 ", %.2f, %.2f, tot:%.2f], avg:%.3f ms, tot:%.3f secs\n", i, tx_stats.tx_seq_min_rtt, tx_stats.tx_seq_max_rtt,