From 50b57516e8caca33dee89be89c7b296fed77a591 Mon Sep 17 00:00:00 2001 From: liu zhifu Date: Fri, 13 Mar 2020 12:48:34 +0800 Subject: [PATCH] esp_wifi: fix WiFi TX performance --- components/esp32/Kconfig | 16 ++++++++++++++++ components/esp32/include/esp_wifi.h | 17 +++++++++-------- components/esp32/lib | 2 +- components/esp32/wifi_init.c | 7 +++++++ components/lwip/port/esp32/netif/wlanif.c | 10 +++++++++- 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/components/esp32/Kconfig b/components/esp32/Kconfig index 02053e1af4..83ccfcd1cc 100644 --- a/components/esp32/Kconfig +++ b/components/esp32/Kconfig @@ -1144,6 +1144,22 @@ menu Wi-Fi layer can deliver frames faster than WiFi layer can transmit. In these cases, we may run out of TX buffers. + config ESP32_WIFI_CACHE_TX_BUFFER_NUM + int "Max number of WiFi cache TX buffers" + depends on ESP32_WIFI_STATIC_TX_BUFFER + range 0 64 if !SPIRAM_TRY_ALLOCATE_WIFI_LWIP + range 0 1024 if SPIRAM_TRY_ALLOCATE_WIFI_LWIP + default 32 if !SPIRAM_TRY_ALLOCATE_WIFI_LWIP + default 64 if SPIRAM_TRY_ALLOCATE_WIFI_LWIP + help + Set the number of WiFi cache TX buffer number, this option can be configured only when the TX + buffer type is static. + + For each TX packet from uplayer, such as LWIP etc, WiFi driver needs to allocate a static TX + buffer and makes a copy of uplayer packet. If WiFi driver fails to allocate the static TX buffer, + it caches the uplayer packets to a dedicated buffer queue, this option is used to configure the + size of the cached TX queue. + config ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM int "Max number of WiFi dynamic TX buffers" depends on ESP32_WIFI_DYNAMIC_TX_BUFFER diff --git a/components/esp32/include/esp_wifi.h b/components/esp32/include/esp_wifi.h index 2b55d39965..e642808dde 100644 --- a/components/esp32/include/esp_wifi.h +++ b/components/esp32/include/esp_wifi.h @@ -100,23 +100,26 @@ 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 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 */ int ampdu_tx_enable; /**< WiFi AMPDU TX feature enable flag */ int nvs_enable; /**< WiFi NVS flash enable flag */ int nano_enable; /**< Nano option for printf/scan family enable flag */ - int tx_ba_win; /**< WiFi Block Ack TX window size */ int rx_ba_win; /**< WiFi Block Ack RX window size */ int wifi_task_core_id; /**< WiFi Task Core ID */ int beacon_max_len; /**< WiFi softAP maximum length of the beacon */ int mgmt_sbuf_num; /**< WiFi management short buffer number, the minimum value is 6, the maximum value is 32 */ + uint64_t feature_caps; /**< Enables additional WiFi features and capabilities */ int magic; /**< WiFi init magic number, it should be the last field */ } wifi_init_config_t; #ifdef CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM #define WIFI_STATIC_TX_BUFFER_NUM CONFIG_ESP32_WIFI_STATIC_TX_BUFFER_NUM +#define WIFI_CACHE_TX_BUFFER_NUM CONFIG_ESP32_WIFI_CACHE_TX_BUFFER_NUM #else #define WIFI_STATIC_TX_BUFFER_NUM 0 +#define WIFI_CACHE_TX_BUFFER_NUM CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM #endif #ifdef CONFIG_ESP32_WIFI_DYNAMIC_TX_BUFFER_NUM @@ -156,15 +159,10 @@ typedef struct { #endif extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs; +extern uint64_t g_wifi_feature_caps; #define WIFI_INIT_CONFIG_MAGIC 0x1F2F3F4F -#ifdef CONFIG_ESP32_WIFI_AMPDU_TX_ENABLED -#define WIFI_DEFAULT_TX_BA_WIN CONFIG_ESP32_WIFI_TX_BA_WIN -#else -#define WIFI_DEFAULT_TX_BA_WIN 0 /* unused if ampdu_tx_enable == false */ -#endif - #ifdef CONFIG_ESP32_WIFI_AMPDU_RX_ENABLED #define WIFI_DEFAULT_RX_BA_WIN CONFIG_ESP32_WIFI_RX_BA_WIN #else @@ -189,6 +187,8 @@ extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs; #define WIFI_MGMT_SBUF_NUM 32 #endif +#define CONFIG_FEATURE_CACHE_TX_BUF_BIT (1<<1) + #define WIFI_INIT_CONFIG_DEFAULT() { \ .event_handler = &esp_event_send, \ .osi_funcs = &g_wifi_osi_funcs, \ @@ -198,16 +198,17 @@ extern const wpa_crypto_funcs_t g_wifi_default_wpa_crypto_funcs; .tx_buf_type = CONFIG_ESP32_WIFI_TX_BUFFER_TYPE,\ .static_tx_buf_num = WIFI_STATIC_TX_BUFFER_NUM,\ .dynamic_tx_buf_num = WIFI_DYNAMIC_TX_BUFFER_NUM,\ + .cache_tx_buf_num = WIFI_CACHE_TX_BUFFER_NUM,\ .csi_enable = WIFI_CSI_ENABLED,\ .ampdu_rx_enable = WIFI_AMPDU_RX_ENABLED,\ .ampdu_tx_enable = WIFI_AMPDU_TX_ENABLED,\ .nvs_enable = WIFI_NVS_ENABLED,\ .nano_enable = WIFI_NANO_FORMAT_ENABLED,\ - .tx_ba_win = WIFI_DEFAULT_TX_BA_WIN,\ .rx_ba_win = WIFI_DEFAULT_RX_BA_WIN,\ .wifi_task_core_id = WIFI_TASK_CORE_ID,\ .beacon_max_len = WIFI_SOFTAP_BEACON_MAX_LEN, \ .mgmt_sbuf_num = WIFI_MGMT_SBUF_NUM, \ + .feature_caps = g_wifi_feature_caps, \ .magic = WIFI_INIT_CONFIG_MAGIC\ }; diff --git a/components/esp32/lib b/components/esp32/lib index a1d1e5d3a0..6792e41cff 160000 --- a/components/esp32/lib +++ b/components/esp32/lib @@ -1 +1 @@ -Subproject commit a1d1e5d3a0e3ecf3d7154eddf4f23e2ba73aca92 +Subproject commit 6792e41cff96a59f686f95a000a059d144b8ffb4 diff --git a/components/esp32/wifi_init.c b/components/esp32/wifi_init.c index 7b700dd4ec..01c5de48a2 100644 --- a/components/esp32/wifi_init.c +++ b/components/esp32/wifi_init.c @@ -35,6 +35,13 @@ mesh_event_cb_t g_mesh_event_cb = NULL; static esp_pm_lock_handle_t s_wifi_modem_sleep_lock; #endif +/* Set additional WiFi features and capabilities */ +uint64_t g_wifi_feature_caps = +#if CONFIG_SPIRAM_SUPPORT + CONFIG_FEATURE_CACHE_TX_BUF_BIT | +#endif +0; + /* Callback function to update WiFi MAC time */ wifi_mac_time_update_cb_t s_wifi_mac_time_update_cb = NULL; diff --git a/components/lwip/port/esp32/netif/wlanif.c b/components/lwip/port/esp32/netif/wlanif.c index 7c60b69349..838b06f82d 100644 --- a/components/lwip/port/esp32/netif/wlanif.c +++ b/components/lwip/port/esp32/netif/wlanif.c @@ -106,7 +106,7 @@ low_level_output(struct netif *netif, struct pbuf *p) { wifi_interface_t wifi_if = tcpip_adapter_get_esp_if(netif); struct pbuf *q = p; - err_t ret; + esp_err_t ret; if (wifi_if >= ESP_IF_MAX) { return ERR_IF; @@ -127,6 +127,14 @@ low_level_output(struct netif *netif, struct pbuf *p) pbuf_free(q); } + if (ret == ESP_OK) { + return ERR_OK; + } else if (ret == ESP_ERR_NO_MEM) { + return ERR_MEM; + } else { + return ERR_ABRT; + } + return ret; }