From 45563e9eacf285f6bcce5e3cab73178293361ef1 Mon Sep 17 00:00:00 2001 From: Ajay Parida Date: Mon, 27 Nov 2023 15:50:23 +0530 Subject: [PATCH] drivers: wifi: Set RTS threshold [SHEL-2307] Configure RTS threshold to firmware. Signed-off-by: Ajay Parida --- .../releases/release-notes-changelog.rst | 2 +- drivers/wifi/nrf700x/inc/wifi_mgmt.h | 2 + drivers/wifi/nrf700x/src/fmac_main.c | 1 + drivers/wifi/nrf700x/src/wifi_mgmt.c | 65 +++++++++++++++++++ drivers/wifi/nrf700x/src/wifi_util.c | 46 ------------- modules/hostap/src/supp_api.c | 13 ++++ modules/hostap/src/supp_api.h | 10 +++ modules/hostap/src/supp_main.c | 1 + 8 files changed, 93 insertions(+), 47 deletions(-) diff --git a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst index 89cd52d55ea9..12c9de4db8dd 100644 --- a/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst +++ b/doc/nrf/releases_and_maturity/releases/release-notes-changelog.rst @@ -626,7 +626,7 @@ This section provides detailed lists of changes by :ref:`driver `. Wi-Fi drivers ------------- -|no_changes_yet_note| +* Removed support for setting RTS threshold through ``wifi_util`` command. Libraries ========= diff --git a/drivers/wifi/nrf700x/inc/wifi_mgmt.h b/drivers/wifi/nrf700x/inc/wifi_mgmt.h index a90e78dcd2e3..9e8424d43a05 100644 --- a/drivers/wifi/nrf700x/inc/wifi_mgmt.h +++ b/drivers/wifi/nrf700x/inc/wifi_mgmt.h @@ -70,4 +70,6 @@ int nrf_wifi_filter(const struct device *dev, struct wifi_filter_info *filter); #endif /* CONFIG_NRF700X_RAW_DATA_RX || CONFIG_NRF700X_PROMISC_DATA_RX */ +int nrf_wifi_set_rts_threshold(const struct device *dev, + unsigned int rts_threshold); #endif /* __ZEPHYR_WIFI_MGMT_H__ */ diff --git a/drivers/wifi/nrf700x/src/fmac_main.c b/drivers/wifi/nrf700x/src/fmac_main.c index e5c2ea8c5e56..370dabb6ec4c 100644 --- a/drivers/wifi/nrf700x/src/fmac_main.c +++ b/drivers/wifi/nrf700x/src/fmac_main.c @@ -793,6 +793,7 @@ static struct wifi_mgmt_ops nrf_wifi_mgmt_ops = { .set_twt = nrf_wifi_set_twt, .reg_domain = nrf_wifi_reg_domain, .get_power_save_config = nrf_wifi_get_power_save_config, + .set_rts_threshold = nrf_wifi_set_rts_threshold, #endif /* CONFIG_NRF700X_STA_MODE */ #ifdef CONFIG_NRF700X_SYSTEM_WITH_RAW_MODES .mode = nrf_wifi_mode, diff --git a/drivers/wifi/nrf700x/src/wifi_mgmt.c b/drivers/wifi/nrf700x/src/wifi_mgmt.c index 1dece1222b17..99a1cde00586 100644 --- a/drivers/wifi/nrf700x/src/wifi_mgmt.c +++ b/drivers/wifi/nrf700x/src/wifi_mgmt.c @@ -948,3 +948,68 @@ int nrf_wifi_filter(const struct device *dev, return ret; } #endif /* CONFIG_NRF700X_RAW_DATA_RX || CONFIG_NRF700X_PROMISC_DATA_RX */ + +int nrf_wifi_set_rts_threshold(const struct device *dev, + unsigned int rts_threshold) +{ + enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; + struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL; + struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL; + struct nrf_wifi_umac_set_wiphy_info wiphy_info; + int ret = -1; + + if (!dev) { + LOG_ERR("%s: dev is NULL", __func__); + return ret; + } + + vif_ctx_zep = dev->data; + + if (!vif_ctx_zep) { + LOG_ERR("%s: vif_ctx_zep is NULL", __func__); + return ret; + } + + rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep; + + if (!rpu_ctx_zep) { + LOG_ERR("%s: rpu_ctx_zep is NULL", __func__); + return ret; + } + + + if (!rpu_ctx_zep->rpu_ctx) { + LOG_ERR("%s: RPU context not initialized", __func__); + return ret; + } + + if ((int)rts_threshold < -1) { + /* 0 or any positive value is passed to f/w. + * For RTS off, -1 is passed to f/w. + * All other negative values considered as invalid. + */ + LOG_ERR("%s: Invalid threshold value : %d", __func__, (int)rts_threshold); + return ret; + } + + memset(&wiphy_info, 0, sizeof(struct nrf_wifi_umac_set_wiphy_info)); + + wiphy_info.rts_threshold = (int)rts_threshold; + + k_mutex_lock(&vif_ctx_zep->vif_lock, K_FOREVER); + + status = nrf_wifi_fmac_set_wiphy_params(rpu_ctx_zep->rpu_ctx, + vif_ctx_zep->vif_idx, + &wiphy_info); + + if (status != NRF_WIFI_STATUS_SUCCESS) { + LOG_ERR("%s: Configuring rts threshold failed\n", __func__); + goto out; + } + + ret = 0; +out: + k_mutex_unlock(&vif_ctx_zep->vif_lock); + + return ret; +} diff --git a/drivers/wifi/nrf700x/src/wifi_util.c b/drivers/wifi/nrf700x/src/wifi_util.c index 0ff492ecb28e..9a3e21e5e7f5 100644 --- a/drivers/wifi/nrf700x/src/wifi_util.c +++ b/drivers/wifi/nrf700x/src/wifi_util.c @@ -178,41 +178,6 @@ static int nrf_wifi_util_set_he_ltf_gi(const struct shell *shell, return 0; } - -static int nrf_wifi_util_set_rts_threshold(const struct shell *shell, - size_t argc, - const char *argv[]) -{ - enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL; - char *ptr = NULL; - unsigned long val = 0; - struct nrf_wifi_umac_set_wiphy_info wiphy_info; - - memset(&wiphy_info, 0, sizeof(struct nrf_wifi_umac_set_wiphy_info)); - - val = strtoul(argv[1], &ptr, 10); - - if (ctx->conf_params.rts_threshold != val) { - - wiphy_info.rts_threshold = val; - - status = nrf_wifi_fmac_set_wiphy_params(ctx->rpu_ctx, - 0, - &wiphy_info); - - if (status != NRF_WIFI_STATUS_SUCCESS) { - shell_fprintf(shell, - SHELL_ERROR, - "Programming threshold failed\n"); - return -ENOEXEC; - } - - ctx->conf_params.rts_threshold = val; - } - - return 0; -} - #ifdef CONFIG_NRF700X_STA_MODE static int nrf_wifi_util_set_uapsd_queue(const struct shell *shell, size_t argc, @@ -283,11 +248,6 @@ static int nrf_wifi_util_show_cfg(const struct shell *shell, "set_he_ltf_gi = %d\n", conf_params->set_he_ltf_gi); - shell_fprintf(shell, - SHELL_INFO, - "rts_threshold = %d\n", - conf_params->rts_threshold); - shell_fprintf(shell, SHELL_INFO, "uapsd_queue = %d\n", @@ -916,12 +876,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE( nrf_wifi_util_set_he_ltf_gi, 2, 0), - SHELL_CMD_ARG(rts_threshold, - NULL, - " - Value > 0", - nrf_wifi_util_set_rts_threshold, - 2, - 0), #ifdef CONFIG_NRF700X_STA_MODE SHELL_CMD_ARG(uapsd_queue, NULL, diff --git a/modules/hostap/src/supp_api.c b/modules/hostap/src/supp_api.c index 21aea0a217ce..9ba1bd45c2d8 100644 --- a/modules/hostap/src/supp_api.c +++ b/modules/hostap/src/supp_api.c @@ -814,6 +814,19 @@ int z_wpa_supplicant_channel(const struct device *dev, return wifi_mgmt_api->channel(dev, channel); } +int z_wpa_supplicant_set_rts_threshold(const struct device *dev, + unsigned int rts_threshold) +{ + const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev); + + if (!wifi_mgmt_api || !wifi_mgmt_api->set_rts_threshold) { + wpa_printf(MSG_ERROR, "Set RTS not supported"); + return -ENOTSUP; + } + + return wifi_mgmt_api->set_rts_threshold(dev, rts_threshold); +} + #ifdef CONFIG_AP int z_wpa_supplicant_ap_enable(const struct device *dev, struct wifi_connect_req_params *params) diff --git a/modules/hostap/src/supp_api.h b/modules/hostap/src/supp_api.h index adf75dccb068..11f19502c431 100644 --- a/modules/hostap/src/supp_api.h +++ b/modules/hostap/src/supp_api.h @@ -142,6 +142,16 @@ int z_wpa_supplicant_filter(const struct device *dev, int z_wpa_supplicant_channel(const struct device *dev, struct wifi_channel_info *channel); +/** + * @brief Set Wi-Fi RTS threshold + * + * @param dev Wi-Fi interface handle to use + * @param rts_threshold RTS threshold to set + * @return 0 for OK; -1 for ERROR + */ +int z_wpa_supplicant_set_rts_threshold(const struct device *dev, + unsigned int rts_threshold); + #ifdef CONFIG_AP /** * @brief Set Wi-Fi AP configuration diff --git a/modules/hostap/src/supp_main.c b/modules/hostap/src/supp_main.c index f134f99adab5..348137d767ce 100644 --- a/modules/hostap/src/supp_main.c +++ b/modules/hostap/src/supp_main.c @@ -83,6 +83,7 @@ static const struct wifi_mgmt_ops wpa_supp_ops = { .mode = z_wpa_supplicant_mode, .filter = z_wpa_supplicant_filter, .channel = z_wpa_supplicant_channel, + .set_rts_threshold = z_wpa_supplicant_set_rts_threshold, #ifdef CONFIG_AP .ap_enable = z_wpa_supplicant_ap_enable, .ap_disable = z_wpa_supplicant_ap_disable,