diff --git a/drivers/wifi/nrf_wifi/CMakeLists.txt b/drivers/wifi/nrf_wifi/CMakeLists.txt index e631e930e07..27d8ba8081c 100644 --- a/drivers/wifi/nrf_wifi/CMakeLists.txt +++ b/drivers/wifi/nrf_wifi/CMakeLists.txt @@ -11,7 +11,6 @@ set(FW_BINS_BASE ${ZEPHYR_NRF_WIFI_MODULE_DIR}/zephyr/blobs/wifi_fw_bins) zephyr_include_directories( inc - src/qspi/inc # for net_sprint_ll_addr ${ZEPHYR_BASE}/subsys/net/ip ) @@ -24,12 +23,6 @@ zephyr_library_sources_ifdef(CONFIG_NRF70_SR_COEX src/coex.c ) -zephyr_library_sources( - src/qspi/src/device.c - src/qspi/src/rpu_hw_if.c - src/qspi/src/ficr_prog.c -) - zephyr_library_sources_ifndef(CONFIG_NRF70_OFFLOADED_RAW_TX src/fmac_main.c ) @@ -65,14 +58,6 @@ zephyr_library_sources_ifdef(CONFIG_NRF70_STA_MODE zephyr_library_sources_ifdef(CONFIG_NRF70_STA_MODE src/wpa_supp_if.c) -zephyr_library_sources_ifdef(CONFIG_NRF70_ON_QSPI - src/qspi/src/qspi_if.c -) - -zephyr_library_sources_ifdef(CONFIG_NRF70_ON_SPI - src/qspi/src/spi_if.c -) - zephyr_library_sources_ifdef(CONFIG_NRF70_UTIL src/wifi_util.c ) @@ -88,6 +73,8 @@ zephyr_compile_definitions_ifdef(CONFIG_NRF70_ON_QSPI -DNRF53_ERRATA_159_ENABLE_WORKAROUND=0 ) +target_link_libraries(nrf_wifi PRIVATE nrf70-buslib) + if (CONFIG_NRF_WIFI_BUILD_ONLY_MODE) message(WARNING " ------------------------------------------------------------------------ diff --git a/drivers/wifi/nrf_wifi/Kconfig.nrfwifi b/drivers/wifi/nrf_wifi/Kconfig.nrfwifi index f0d2c8ead71..45a22b7e7fa 100644 --- a/drivers/wifi/nrf_wifi/Kconfig.nrfwifi +++ b/drivers/wifi/nrf_wifi/Kconfig.nrfwifi @@ -11,6 +11,7 @@ menuconfig WIFI_NRF70 select NET_L2_ETHERNET_MGMT if NETWORKING && NET_L2_ETHERNET select WIFI_USE_NATIVE_NETWORKING if NETWORKING select EXPERIMENTAL if !SOC_SERIES_NRF53X && !SOC_SERIES_NRF91X + select NRF70_BUSLIB default y depends on \ DT_HAS_NORDIC_NRF7002_SPI_ENABLED || DT_HAS_NORDIC_NRF7002_QSPI_ENABLED || \ @@ -33,16 +34,9 @@ config WIFI_NRF7000 bool default y if DT_HAS_NORDIC_NRF7000_SPI_ENABLED || DT_HAS_NORDIC_NRF7000_QSPI_ENABLED - -module = WIFI_NRF70_BUS -module-dep = LOG -module-str = Log level for Wi-Fi nRF70 bus layers -module-help = Sets log level for Wi-Fi nRF70 bus layers -source "subsys/net/Kconfig.template.log_config.net" - -config WIFI_NRF70_BUS_LOG_LEVEL - # Enable error by default - default 1 +config NRF70_QSPI_LOW_POWER + bool "low power mode in QSPI" + default y if NRF_WIFI_LOW_POWER choice NRF70_OPER_MODES bool "nRF70 operating modes" diff --git a/drivers/wifi/nrf_wifi/src/qspi/inc/ficr_prog.h b/drivers/wifi/nrf_wifi/src/qspi/inc/ficr_prog.h deleted file mode 100644 index 35c4bda1fa3..00000000000 --- a/drivers/wifi/nrf_wifi/src/qspi/inc/ficr_prog.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/** - * @brief Header containing address/offets and functions for writing - * the FICR fields of the OTP memory on nRF7002 device - */ - -#ifndef __OTP_PROG_H_ -#define __OTP_PROG_H_ - -#include -#include - -int write_otp_memory(unsigned int otp_addr, unsigned int *write_val); -int read_otp_memory(unsigned int otp_addr, unsigned int *read_val, int len); -unsigned int check_protection(unsigned int *buff, unsigned int off1, unsigned int off2, - unsigned int off3, unsigned int off4); - -#endif /* __OTP_PROG_H_ */ diff --git a/drivers/wifi/nrf_wifi/src/qspi/src/ficr_prog.c b/drivers/wifi/nrf_wifi/src/qspi/src/ficr_prog.c deleted file mode 100644 index 5558b35e837..00000000000 --- a/drivers/wifi/nrf_wifi/src/qspi/src/ficr_prog.c +++ /dev/null @@ -1,379 +0,0 @@ -/* - * Copyright (c) 2024 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -/* @file - * @brief NRF Wi-Fi radio FICR programming functions - */ - -#include -#include -#include "rpu_if.h" -#include "rpu_hw_if.h" -#include "ficr_prog.h" - - -LOG_MODULE_DECLARE(otp_prog, CONFIG_WIFI_NRF70_BUS_LOG_LEVEL); - -static void write_word(unsigned int addr, unsigned int data) -{ - rpu_write(addr, &data, 4); -} - -static void read_word(unsigned int addr, unsigned int *data) -{ - rpu_read(addr, data, 4); -} - -unsigned int check_protection(unsigned int *buff, unsigned int off1, unsigned int off2, - unsigned int off3, unsigned int off4) -{ - if ((buff[off1] == OTP_PROGRAMMED) && - (buff[off2] == OTP_PROGRAMMED) && - (buff[off3] == OTP_PROGRAMMED) && - (buff[off4] == OTP_PROGRAMMED)) - return OTP_PROGRAMMED; - else if ((buff[off1] == OTP_FRESH_FROM_FAB) && - (buff[off2] == OTP_FRESH_FROM_FAB) && - (buff[off3] == OTP_FRESH_FROM_FAB) && - (buff[off4] == OTP_FRESH_FROM_FAB)) - return OTP_FRESH_FROM_FAB; - else if ((buff[off1] == OTP_ENABLE_PATTERN) && - (buff[off2] == OTP_ENABLE_PATTERN) && - (buff[off3] == OTP_ENABLE_PATTERN) && - (buff[off4] == OTP_ENABLE_PATTERN)) - return OTP_ENABLE_PATTERN; - else - return OTP_INVALID; -} - - -static void set_otp_timing_reg_40mhz(void) -{ - write_word(OTP_TIMING_REG1_ADDR, OTP_TIMING_REG1_VAL); - write_word(OTP_TIMING_REG2_ADDR, OTP_TIMING_REG2_VAL); -} - -static int poll_otp_ready(void) -{ - int otp_mem_status = 0; - int poll = 0; - - while (poll != 100) { - read_word(OTP_POLL_ADDR, &otp_mem_status); - - if ((otp_mem_status & OTP_READY) == OTP_READY) { - return 0; - } - poll++; - } - LOG_ERR("OTP is not ready"); - return -ENOEXEC; -} - - -static int req_otp_standby_mode(void) -{ - write_word(OTP_RWSBMODE_ADDR, 0x0); - return poll_otp_ready(); -} - - -static int otp_wr_voltage_2V5(void) -{ - int err; - - err = req_otp_standby_mode(); - - if (err) { - LOG_ERR("Failed Setting OTP voltage IOVDD to 2.5V"); - return -ENOEXEC; - } - write_word(OTP_VOLTCTRL_ADDR, OTP_VOLTCTRL_2V5); - return 0; -} - -static int poll_otp_read_valid(void) -{ - int otp_mem_status = 0; - int poll = 0; - - while (poll < 100) { - read_word(OTP_POLL_ADDR, &otp_mem_status); - - if ((otp_mem_status & OTP_READ_VALID) == OTP_READ_VALID) { - return 0; - } - poll++; - } - LOG_ERR("%s: OTP read failed", __func__); - return -ENOEXEC; -} - -static int poll_otp_wrdone(void) -{ - int otp_mem_status = 0; - int poll = 0; - - while (poll < 100) { - read_word(OTP_POLL_ADDR, &otp_mem_status); - - if ((otp_mem_status & OTP_WR_DONE) == OTP_WR_DONE) { - return 0; - } - poll++; - } - LOG_ERR("%s: OTP write done failed", __func__); - return -ENOEXEC; -} - -static int req_otp_read_mode(void) -{ - write_word(OTP_RWSBMODE_ADDR, OTP_READ_MODE); - return poll_otp_ready(); -} - - -static int req_otp_byte_write_mode(void) -{ - write_word(OTP_RWSBMODE_ADDR, OTP_BYTE_WRITE_MODE); - return poll_otp_ready(); -} - -static unsigned int read_otp_location(unsigned int offset, unsigned int *read_val) -{ - int err; - - write_word(OTP_RDENABLE_ADDR, offset); - err = poll_otp_read_valid(); - if (err) { - LOG_ERR("OTP read failed"); - return err; - } - read_word(OTP_READREG_ADDR, read_val); - - return 0; -} - -static int write_otp_location(unsigned int otp_location_offset, unsigned int otp_data) -{ - write_word(OTP_WRENABLE_ADDR, otp_location_offset); - write_word(OTP_WRITEREG_ADDR, otp_data); - - return poll_otp_wrdone(); -} - - -static int otp_rd_voltage_1V8(void) -{ - int err; - - err = req_otp_standby_mode(); - if (err) { - LOG_ERR("error in %s", __func__); - return err; - } - write_word(OTP_VOLTCTRL_ADDR, OTP_VOLTCTRL_1V8); - - return 0; -} - -static int update_mac_addr(unsigned int index, unsigned int *write_val) -{ - int ret = 0; - - for (int i = 0; i < 2; i++) { - ret = write_otp_location(MAC0_ADDR + 2 * index + i, write_val[i]); - if (ret == -ENOEXEC) { - LOG_ERR("FICR: Failed to update MAC ADDR%d", index); - break; - } - LOG_INF("mac addr %d : Reg%d (0x%x) = 0x%04x", - index, (i+1), (MAC0_ADDR + i) << 2, write_val[i]); - } - return ret; -} - -int write_otp_memory(unsigned int otp_addr, unsigned int *write_val) -{ - int err = 0; - int mask_val; - int ret = 0; - int retrim_loc = 0; - - err = poll_otp_ready(); - if (err) { - LOG_ERR("err in otp ready poll"); - return err; - } - - set_otp_timing_reg_40mhz(); - - err = otp_wr_voltage_2V5(); - if (err) { - LOG_ERR("error in write_voltage 2V5"); - goto _exit_otp_write; - } - - err = req_otp_byte_write_mode(); - if (err) { - LOG_ERR("error in OTP byte write mode"); - goto _exit_otp_write; - } - - switch (otp_addr) { - case REGION_PROTECT: - write_otp_location(REGION_PROTECT, write_val[0]); - write_otp_location(REGION_PROTECT+1, write_val[0]); - write_otp_location(REGION_PROTECT+2, write_val[0]); - write_otp_location(REGION_PROTECT+3, write_val[0]); - - LOG_INF("Written REGION_PROTECT0 (0x%x) : 0x%04x", - (REGION_PROTECT << 2), write_val[0]); - LOG_INF("Written REGION_PROTECT1 (0x%x) : 0x%04x", - (REGION_PROTECT+1) << 2, write_val[0]); - LOG_INF("Written REGION_PROTECT2 (0x%x) : 0x%04x", - (REGION_PROTECT+2) << 2, write_val[0]); - LOG_INF("Written REGION_PROTECT3 (0x%x) : 0x%04x", - (REGION_PROTECT+3) << 2, write_val[0]); - break; - case QSPI_KEY: - mask_val = QSPI_KEY_FLAG_MASK; - for (int i = 0; i < QSPI_KEY_LENGTH_BYTES / 4; i++) { - ret = write_otp_location(QSPI_KEY + i, write_val[i]); - if (ret == -ENOEXEC) { - LOG_ERR("FICR: Failed to write QSPI key offset-%d", QSPI_KEY + i); - goto _exit_otp_write; - } - LOG_INF("Written QSPI_KEY0 (0x%x) : 0x%04x", - (QSPI_KEY + i) << 2, write_val[i]); - } - write_otp_location(REGION_DEFAULTS, mask_val); - LOG_INF("Written REGION_DEFAULTS (0x%x) : 0x%04x", - (REGION_DEFAULTS) << 2, mask_val); - break; - case MAC0_ADDR: - mask_val = MAC0_ADDR_FLAG_MASK; - ret = update_mac_addr(0, write_val); - if (ret == -ENOEXEC) { - goto _exit_otp_write; - } - - write_otp_location(REGION_DEFAULTS, mask_val); - LOG_INF("Written MAC address 0"); - LOG_INF("Written REGION_DEFAULTS (0x%x) : 0x%04x", - (REGION_DEFAULTS) << 2, mask_val); - break; - case MAC1_ADDR: - mask_val = MAC1_ADDR_FLAG_MASK; - ret = update_mac_addr(1, write_val); - if (ret == -ENOEXEC) { - goto _exit_otp_write; - } - write_otp_location(REGION_DEFAULTS, mask_val); - LOG_INF("Written MAC address 1"); - LOG_INF("Written REGION_DEFAULTS (0x%x) : 0x%04x", - (REGION_DEFAULTS) << 2, mask_val); - break; - case CALIB_XO: - mask_val = CALIB_XO_FLAG_MASK; - ret = write_otp_location(CALIB_XO, write_val[0]); - - if (ret == -ENOEXEC) { - LOG_ERR("XO_Update Exception"); - goto _exit_otp_write; - } else { - write_otp_location(REGION_DEFAULTS, mask_val); - - LOG_INF("Written CALIB_XO (0x%x) to 0x%04x", - CALIB_XO << 2, write_val[0]); - LOG_INF("Written REGION_DEFAULTS (0x%x) : 0x%04x", - (REGION_DEFAULTS) << 2, mask_val); - } - break; - case PRODRETEST_PROGVERSION: - ret = write_otp_location(PRODRETEST_PROGVERSION, *write_val); - - if (ret == -ENOEXEC) { - LOG_ERR("PRODRETEST.PROGVERSION_Update Exception"); - goto _exit_otp_write; - } else { - LOG_INF("Written PRODRETEST.PROGVERSION 0x%04x", *write_val); - } - break; - case PRODRETEST_TRIM0: - case PRODRETEST_TRIM1: - case PRODRETEST_TRIM2: - case PRODRETEST_TRIM3: - case PRODRETEST_TRIM4: - case PRODRETEST_TRIM5: - case PRODRETEST_TRIM6: - case PRODRETEST_TRIM7: - case PRODRETEST_TRIM8: - case PRODRETEST_TRIM9: - case PRODRETEST_TRIM10: - case PRODRETEST_TRIM11: - case PRODRETEST_TRIM12: - case PRODRETEST_TRIM13: - case PRODRETEST_TRIM14: - retrim_loc = otp_addr - PRODRETEST_TRIM0; - ret = write_otp_location(otp_addr, *write_val); - - if (ret == -ENOEXEC) { - LOG_ERR("PRODRETEST.TRIM_Update Exception"); - goto _exit_otp_write; - } else { - LOG_INF("Written PRODRETEST.TRIM%d 0x%04x", - retrim_loc, *write_val); - } - break; - case REGION_DEFAULTS: - write_otp_location(REGION_DEFAULTS, write_val[0]); - - LOG_INF("Written REGION_DEFAULTS (0x%x) to 0x%04x", - REGION_DEFAULTS << 2, write_val[0]); - break; - default: - LOG_ERR("unknown field received: %d", otp_addr); - - } - return ret; - -_exit_otp_write: - err = req_otp_standby_mode(); - err |= otp_rd_voltage_1V8(); - return err; -} - -int read_otp_memory(unsigned int otp_addr, unsigned int *read_val, int len) -{ - int err; - - err = poll_otp_ready(); - if (err) { - LOG_ERR("err in otp ready poll"); - return -ENOEXEC; - } - - set_otp_timing_reg_40mhz(); - - err = otp_rd_voltage_1V8(); - if (err) { - LOG_ERR("error in read_voltage 1V8"); - return -ENOEXEC; - } - - err = req_otp_read_mode(); - if (err) { - LOG_ERR("error in req_otp_read_mode()"); - return -ENOEXEC; - } - - for (int i = 0; i < len; i++) { - read_otp_location(otp_addr + i, &read_val[i]); - } - - return req_otp_standby_mode(); -} diff --git a/drivers/wifi/nrf_wifi/src/qspi/inc/qspi_if.h b/include/zephyr/drivers/wifi/nrf_wifi/bus/qspi_if.h similarity index 100% rename from drivers/wifi/nrf_wifi/src/qspi/inc/qspi_if.h rename to include/zephyr/drivers/wifi/nrf_wifi/bus/qspi_if.h diff --git a/drivers/wifi/nrf_wifi/src/qspi/inc/rpu_hw_if.h b/include/zephyr/drivers/wifi/nrf_wifi/bus/rpu_hw_if.h similarity index 100% rename from drivers/wifi/nrf_wifi/src/qspi/inc/rpu_hw_if.h rename to include/zephyr/drivers/wifi/nrf_wifi/bus/rpu_hw_if.h diff --git a/modules/nrf_wifi/CMakeLists.txt b/modules/nrf_wifi/CMakeLists.txt index e3b96f0db7b..982272fce6a 100644 --- a/modules/nrf_wifi/CMakeLists.txt +++ b/modules/nrf_wifi/CMakeLists.txt @@ -1,184 +1,6 @@ -# Copyright (c) 2024 Nordic Semiconductor ASA +# # SPDX-License-Identifier: Apache-2.0 +# -if(NOT CONFIG_WIFI_NRF70) - return() -endif() -zephyr_interface_library_named(nrf-wifi-interface) -zephyr_library() - -set(NRF_WIFI_DIR ${ZEPHYR_CURRENT_MODULE_DIR}) - -# Translate the configuration to the OS agnostic code -target_compile_definitions( - nrf-wifi-interface - INTERFACE - $<$:NRF_WIFI_LOW_POWER> - $<$:NRF_WIFI_RPU_RECOVERY> - $<$:NRF_WIFI_AP_DEAD_DETECT_TIMEOUT=${CONFIG_NRF_WIFI_AP_DEAD_DETECT_TIMEOUT}> - $<$:NRF_WIFI_IFACE_MTU=${CONFIG_NRF_WIFI_IFACE_MTU}> - $<$:NRF70_STA_MODE> - $<$:NRF70_DATA_TX> - $<$:NRF70_RAW_DATA_TX> - $<$:NRF70_RAW_DATA_RX> - $<$:NRF70_PROMISC_DATA_RX> - $<$:NRF70_TX_DONE_WQ_ENABLED> - $<$:NRF70_RX_WQ_ENABLED> - $<$:NRF70_UTIL> - $<$:NRF70_RADIO_TEST> - $<$:NRF70_OFFLOADED_RAW_TX> - $<$:NRF70_TCP_IP_CHECKSUM_OFFLOAD> - $<$:NRF70_RPU_EXTEND_TWT_SP> - $<$:NRF70_SYSTEM_WITH_RAW_MODES> - $<$:NRF70_SCAN_ONLY> - $<$:NRF70_SYSTEM_MODE> - $<$:NRF70_2_4G_ONLY> - $<$:NRF70_LOG_VERBOSE> - $<$:NRF70_AP_MODE> - $<$:NRF_WIFI_MGMT_BUFF_OFFLOAD> - $<$:NRF_WIFI_FEAT_KEEPALIVE> - $<$:NRF_WIFI_KEEPALIVE_PERIOD_S=${CONFIG_NRF_WIFI_KEEPALIVE_PERIOD_S}> - $<$:WIFI_MGMT_RAW_SCAN_RESULTS> - NRF70_RX_NUM_BUFS=${CONFIG_NRF70_RX_NUM_BUFS} - NRF70_MAX_TX_TOKENS=${CONFIG_NRF70_MAX_TX_TOKENS} - NRF70_RX_MAX_DATA_SIZE=${CONFIG_NRF70_RX_MAX_DATA_SIZE} - NRF70_MAX_TX_PENDING_QLEN=${CONFIG_NRF70_MAX_TX_PENDING_QLEN} - NRF70_RPU_PS_IDLE_TIMEOUT_MS=${CONFIG_NRF70_RPU_PS_IDLE_TIMEOUT_MS} - NRF70_REG_DOMAIN=${CONFIG_NRF70_REG_DOMAIN} - NRF70_BAND_2G_LOWER_EDGE_BACKOFF_DSSS=${CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_DSSS} - NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HT} - NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HE} - NRF70_BAND_2G_UPPER_EDGE_BACKOFF_DSSS=${CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_DSSS} - NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HT} - NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HE} - NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HT} - NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HE} - NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HT} - NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HE} - NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HT} - NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HE} - NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HT} - NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HE} - NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HT} - NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HE} - NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HT} - NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HE} - NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HT} - NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HE} - NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HT} - NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HE} - NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HT} - NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HE} - NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HT} - NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HE} - NRF70_PCB_LOSS_2G=${CONFIG_NRF70_PCB_LOSS_2G} - NRF70_PCB_LOSS_5G_BAND1=${CONFIG_NRF70_PCB_LOSS_5G_BAND1} - NRF70_PCB_LOSS_5G_BAND2=${CONFIG_NRF70_PCB_LOSS_5G_BAND2} - NRF70_PCB_LOSS_5G_BAND3=${CONFIG_NRF70_PCB_LOSS_5G_BAND3} - NRF70_ANT_GAIN_2G=${CONFIG_NRF70_ANT_GAIN_2G} - NRF70_ANT_GAIN_5G_BAND1=${CONFIG_NRF70_ANT_GAIN_5G_BAND1} - NRF70_ANT_GAIN_5G_BAND2=${CONFIG_NRF70_ANT_GAIN_5G_BAND2} - NRF70_ANT_GAIN_5G_BAND3=${CONFIG_NRF70_ANT_GAIN_5G_BAND3} - NRF_WIFI_PS_INT_PS=${CONFIG_NRF_WIFI_PS_INT_PS} - NRF_WIFI_RPU_RECOVERY_PS_ACTIVE_TIMEOUT_MS=${CONFIG_NRF_WIFI_RPU_RECOVERY_PS_ACTIVE_TIMEOUT_MS} -) - -target_include_directories( - nrf-wifi-interface - INTERFACE - ${CMAKE_CURRENT_LIST_DIR} - ${NRF_WIFI_DIR}/utils/inc - ${NRF_WIFI_DIR}/os_if/inc - ${NRF_WIFI_DIR}/bus_if/bus/qspi/inc - ${NRF_WIFI_DIR}/bus_if/bal/inc - ${NRF_WIFI_DIR}/fw_if/umac_if/inc - ${NRF_WIFI_DIR}/fw_load/mips/fw/inc - ${NRF_WIFI_DIR}/hw_if/hal/inc - ${NRF_WIFI_DIR}/hw_if/hal/inc/fw - ${NRF_WIFI_DIR}/fw_if/umac_if/inc/fw -) - -if(CONFIG_NRF70_RADIO_TEST) - target_include_directories(nrf-wifi-interface INTERFACE - ${NRF_WIFI_DIR}/fw_if/umac_if/inc/radio_test - ) -elseif(CONFIG_NRF70_OFFLOADED_RAW_TX) - target_include_directories(nrf-wifi-interface INTERFACE - ${NRF_WIFI_DIR}/fw_if/umac_if/inc/offload_raw_tx - off_raw_tx/inc - ) -else() - target_include_directories(nrf-wifi-interface INTERFACE - ${NRF_WIFI_DIR}/fw_if/umac_if/inc/default - ) -endif() - -zephyr_library_sources( - ${NRF_WIFI_DIR}/os_if/src/osal.c - ${NRF_WIFI_DIR}/utils/src/list.c - ${NRF_WIFI_DIR}/utils/src/queue.c - ${NRF_WIFI_DIR}/utils/src/util.c - ${NRF_WIFI_DIR}/hw_if/hal/src/hal_api.c - ${NRF_WIFI_DIR}/hw_if/hal/src/hal_fw_patch_loader.c - ${NRF_WIFI_DIR}/hw_if/hal/src/hal_interrupt.c - ${NRF_WIFI_DIR}/hw_if/hal/src/hal_mem.c - ${NRF_WIFI_DIR}/hw_if/hal/src/hal_reg.c - ${NRF_WIFI_DIR}/hw_if/hal/src/hpqm.c - ${NRF_WIFI_DIR}/hw_if/hal/src/pal.c - ${NRF_WIFI_DIR}/bus_if/bal/src/bal.c - ${NRF_WIFI_DIR}/bus_if/bus/qspi/src/qspi.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/cmd.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/event.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_api_common.c -) - -if(CONFIG_NRF70_RADIO_TEST) - zephyr_library_sources( - ${NRF_WIFI_DIR}/fw_if/umac_if/src/radio_test/fmac_api.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c - ) -elseif(CONFIG_NRF70_OFFLOADED_RAW_TX) - zephyr_library_sources( - ${NRF_WIFI_DIR}/fw_if/umac_if/src/offload_raw_tx/fmac_api.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c - ) -else() - zephyr_library_sources( - ${NRF_WIFI_DIR}/fw_if/umac_if/src/rx.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_vif.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/default/fmac_api.c - ) -endif() - -zephyr_library_sources_ifdef(CONFIG_NRF70_DATA_TX - ${NRF_WIFI_DIR}/fw_if/umac_if/src/tx.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_peer.c -) - -zephyr_library_sources_ifdef(CONFIG_NRF70_STA_MODE - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_peer.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c -) - -zephyr_library_sources_ifdef(CONFIG_NRF70_PROMISC_DATA_RX - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_promisc.c -) - -zephyr_library_sources_ifdef(CONFIG_NRF70_AP_MODE - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_ap.c -) - -# Without WPA supplicant we only support scan -zephyr_library_sources_ifdef(CONFIG_NRF70_STA_MODE - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_peer.c - ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c -) - -zephyr_library_sources( - shim.c - timer.c - work.c -) - -target_link_libraries(zephyr_interface INTERFACE nrf-wifi-interface) +add_subdirectory_ifdef(CONFIG_WIFI_NRF70 os) +add_subdirectory_ifdef(CONFIG_NRF70_BUSLIB bus) diff --git a/modules/nrf_wifi/Kconfig b/modules/nrf_wifi/Kconfig index 9fe8172c68d..655fce838e5 100644 --- a/modules/nrf_wifi/Kconfig +++ b/modules/nrf_wifi/Kconfig @@ -3,3 +3,5 @@ config ZEPHYR_NRF_WIFI_MODULE bool + +source "modules/nrf_wifi/bus/Kconfig" diff --git a/modules/nrf_wifi/bus/CMakeLists.txt b/modules/nrf_wifi/bus/CMakeLists.txt new file mode 100644 index 00000000000..f939ce3287c --- /dev/null +++ b/modules/nrf_wifi/bus/CMakeLists.txt @@ -0,0 +1,27 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: BSD-3-Clause +# + +# Check if ZEPHYR_BASE is set +if(NOT DEFINED ENV{ZEPHYR_BASE}) + message(FATAL_ERROR "ZEPHYR_BASE environment variable is not set. Please set it to the Zephyr base directory.") +endif() + +if (CONFIG_NRF70_BUSLIB) + zephyr_library_named(nrf70-buslib) + zephyr_library_include_directories( + inc + ) + zephyr_library_sources( + rpu_hw_if.c + device.c + ) + zephyr_library_sources_ifdef(CONFIG_NRF70_ON_QSPI + qspi_if.c + ) + zephyr_library_sources_ifdef(CONFIG_NRF70_ON_SPI + spi_if.c + ) +endif() diff --git a/modules/nrf_wifi/bus/Kconfig b/modules/nrf_wifi/bus/Kconfig new file mode 100644 index 00000000000..152904e86b7 --- /dev/null +++ b/modules/nrf_wifi/bus/Kconfig @@ -0,0 +1,46 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 +# + +DT_COMPAT_NORDIC_NRF7002_QSPI := nordic,nrf7002-qspi +DT_COMPAT_NORDIC_NRF7002_SPI := nordic,nrf7002-spi +DT_COMPAT_NORDIC_NRF7001_QSPI := nordic,nrf7001-qspi +DT_COMPAT_NORDIC_NRF7001_SPI := nordic,nrf7001-spi +DT_COMPAT_NORDIC_NRF7000_QSPI := nordic,nrf7000-qspi +DT_COMPAT_NORDIC_NRF7000_SPI := nordic,nrf7000-spi + +menuconfig NRF70_BUSLIB + bool "NRF70 Bus Library" + help + Enable the NRF70 Bus Library for the nRF7002 Wi-Fi shield. + +if NRF70_BUSLIB + +config NRF70_ON_QSPI + def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF7002_QSPI)) ||\ + $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF7001_QSPI)) ||\ + $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF7000_QSPI)) + select NRFX_QSPI + +config NRF70_ON_SPI + def_bool $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF7002_SPI)) ||\ + $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF7001_SPI)) ||\ + $(dt_compat_enabled,$(DT_COMPAT_NORDIC_NRF7000_SPI)) + select SPI + +module = WIFI_NRF70_BUSLIB +module-dep = LOG +module-str = Log level for Wi-Fi nRF70 bus library +source "${ZEPHYR_BASE}/subsys/logging/Kconfig.template.log_config" + +config WIFI_NRF70_BUSLIB_LOG_LEVEL + # Enable error by default + default 1 + +config NRF70_LOG_VERBOSE + bool "Maintains the verbosity of information in logs" + default y + +endif # NRF70_BUSLIB diff --git a/drivers/wifi/nrf_wifi/src/qspi/src/device.c b/modules/nrf_wifi/bus/device.c similarity index 78% rename from drivers/wifi/nrf_wifi/src/qspi/src/device.c rename to modules/nrf_wifi/bus/device.c index 4acbaf3861f..8cf0b77cd67 100644 --- a/drivers/wifi/nrf_wifi/src/qspi/src/device.c +++ b/modules/nrf_wifi/bus/device.c @@ -12,30 +12,26 @@ #include #include #include +#include #include #include -#include "qspi_if.h" #include "spi_if.h" static struct qspi_config config; #if defined(CONFIG_NRF70_ON_QSPI) -static struct qspi_dev qspi = { - .init = qspi_init, - .deinit = qspi_deinit, - .read = qspi_read, - .write = qspi_write, - .hl_read = qspi_hl_read -}; +static struct qspi_dev qspi = {.init = qspi_init, + .deinit = qspi_deinit, + .read = qspi_read, + .write = qspi_write, + .hl_read = qspi_hl_read}; #else -static struct qspi_dev spim = { - .init = spim_init, - .deinit = spim_deinit, - .read = spim_read, - .write = spim_write, - .hl_read = spim_hl_read -}; +static struct qspi_dev spim = {.init = spim_init, + .deinit = spim_deinit, + .read = spim_read, + .write = spim_write, + .hl_read = spim_hl_read}; #endif struct qspi_config *qspi_defconfig(void) diff --git a/drivers/wifi/nrf_wifi/src/qspi/src/qspi_if.c b/modules/nrf_wifi/bus/qspi_if.c similarity index 99% rename from drivers/wifi/nrf_wifi/src/qspi/src/qspi_if.c rename to modules/nrf_wifi/bus/qspi_if.c index 754fe149713..8c381ff60c5 100644 --- a/drivers/wifi/nrf_wifi/src/qspi/src/qspi_if.c +++ b/modules/nrf_wifi/bus/qspi_if.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -23,7 +24,6 @@ #include #include "spi_nor.h" -#include "qspi_if.h" /* The QSPI bus node which the NRF70 is on */ #define QSPI_IF_BUS_NODE DT_NODELABEL(qspi) @@ -152,7 +152,7 @@ static void qspi_device_uninit(const struct device *dev); #define WORD_SIZE 4 -LOG_MODULE_DECLARE(wifi_nrf_bus, CONFIG_WIFI_NRF70_BUS_LOG_LEVEL); +LOG_MODULE_DECLARE(wifi_nrf_bus, CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL); /** * @brief QSPI buffer structure diff --git a/drivers/wifi/nrf_wifi/src/qspi/src/rpu_hw_if.c b/modules/nrf_wifi/bus/rpu_hw_if.c similarity index 96% rename from drivers/wifi/nrf_wifi/src/qspi/src/rpu_hw_if.c rename to modules/nrf_wifi/bus/rpu_hw_if.c index 6fac7412362..8b9393f6f2e 100644 --- a/drivers/wifi/nrf_wifi/src/qspi/src/rpu_hw_if.c +++ b/modules/nrf_wifi/bus/rpu_hw_if.c @@ -17,12 +17,12 @@ #include #include #include +#include +#include -#include "rpu_hw_if.h" -#include "qspi_if.h" #include "spi_if.h" -LOG_MODULE_REGISTER(wifi_nrf_bus, CONFIG_WIFI_NRF70_BUS_LOG_LEVEL); +LOG_MODULE_REGISTER(wifi_nrf_bus, CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL); #define NRF7002_NODE DT_NODELABEL(nrf70) @@ -44,7 +44,7 @@ uint32_t rpu_7002_memmap[][3] = { { 0x009000, 0x03FFFF, 2 }, { 0x040000, 0x07FFFF, 1 }, { 0x0C0000, 0x0F0FFF, 0 }, - { 0x080000, 0x092000, 1 }, + { 0x080000, 0x092000, 2 }, { 0x100000, 0x134000, 1 }, { 0x140000, 0x14C000, 1 }, { 0x180000, 0x190000, 1 }, @@ -483,11 +483,16 @@ int rpu_enable(void) goto rpu_pwroff; } +/* TODO: rpu_validate_comms() needs firmware download to be done + * successfully before it can be called. So, disable this for + * nrf70_buslib only usage. + */ +#ifdef CONFIG_WIFI_NRF70 ret = rpu_validate_comms(); if (ret) { goto rpu_pwroff; } - +#endif return 0; rpu_pwroff: rpu_pwroff(); diff --git a/drivers/wifi/nrf_wifi/src/qspi/src/spi_if.c b/modules/nrf_wifi/bus/spi_if.c similarity index 98% rename from drivers/wifi/nrf_wifi/src/qspi/src/spi_if.c rename to modules/nrf_wifi/bus/spi_if.c index 4bf9f464391..fba9f1f00bf 100644 --- a/drivers/wifi/nrf_wifi/src/qspi/src/spi_if.c +++ b/modules/nrf_wifi/bus/spi_if.c @@ -13,11 +13,11 @@ #include #include +#include -#include "qspi_if.h" #include "spi_if.h" -LOG_MODULE_DECLARE(wifi_nrf_bus, CONFIG_WIFI_NRF70_BUS_LOG_LEVEL); +LOG_MODULE_DECLARE(wifi_nrf_bus, CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL); #define NRF7002_NODE DT_NODELABEL(nrf70) diff --git a/drivers/wifi/nrf_wifi/src/qspi/inc/spi_if.h b/modules/nrf_wifi/bus/spi_if.h similarity index 100% rename from drivers/wifi/nrf_wifi/src/qspi/inc/spi_if.h rename to modules/nrf_wifi/bus/spi_if.h diff --git a/drivers/wifi/nrf_wifi/src/qspi/inc/spi_nor.h b/modules/nrf_wifi/bus/spi_nor.h similarity index 100% rename from drivers/wifi/nrf_wifi/src/qspi/inc/spi_nor.h rename to modules/nrf_wifi/bus/spi_nor.h diff --git a/modules/nrf_wifi/os/CMakeLists.txt b/modules/nrf_wifi/os/CMakeLists.txt new file mode 100644 index 00000000000..daef05f2098 --- /dev/null +++ b/modules/nrf_wifi/os/CMakeLists.txt @@ -0,0 +1,186 @@ +# Copyright (c) 2024 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if(NOT CONFIG_WIFI_NRF70) + return() +endif() +zephyr_interface_library_named(nrf-wifi-interface) +zephyr_library() + +set(NRF_WIFI_DIR ${ZEPHYR_CURRENT_MODULE_DIR}) + +# Translate the configuration to the OS agnostic code +target_compile_definitions( + nrf-wifi-interface + INTERFACE + $<$:NRF_WIFI_LOW_POWER> + $<$:NRF_WIFI_RPU_RECOVERY> + $<$:NRF_WIFI_AP_DEAD_DETECT_TIMEOUT=${CONFIG_NRF_WIFI_AP_DEAD_DETECT_TIMEOUT}> + $<$:NRF_WIFI_IFACE_MTU=${CONFIG_NRF_WIFI_IFACE_MTU}> + $<$:NRF70_STA_MODE> + $<$:NRF70_DATA_TX> + $<$:NRF70_RAW_DATA_TX> + $<$:NRF70_RAW_DATA_RX> + $<$:NRF70_PROMISC_DATA_RX> + $<$:NRF70_TX_DONE_WQ_ENABLED> + $<$:NRF70_RX_WQ_ENABLED> + $<$:NRF70_UTIL> + $<$:NRF70_RADIO_TEST> + $<$:NRF70_OFFLOADED_RAW_TX> + $<$:NRF70_TCP_IP_CHECKSUM_OFFLOAD> + $<$:NRF70_RPU_EXTEND_TWT_SP> + $<$:NRF70_SYSTEM_WITH_RAW_MODES> + $<$:NRF70_SCAN_ONLY> + $<$:NRF70_SYSTEM_MODE> + $<$:NRF70_2_4G_ONLY> + $<$:NRF70_LOG_VERBOSE> + $<$:NRF70_AP_MODE> + $<$:NRF_WIFI_MGMT_BUFF_OFFLOAD> + $<$:NRF_WIFI_FEAT_KEEPALIVE> + $<$:NRF_WIFI_KEEPALIVE_PERIOD_S=${CONFIG_NRF_WIFI_KEEPALIVE_PERIOD_S}> + $<$:WIFI_MGMT_RAW_SCAN_RESULTS> + NRF70_RX_NUM_BUFS=${CONFIG_NRF70_RX_NUM_BUFS} + NRF70_MAX_TX_TOKENS=${CONFIG_NRF70_MAX_TX_TOKENS} + NRF70_RX_MAX_DATA_SIZE=${CONFIG_NRF70_RX_MAX_DATA_SIZE} + NRF70_MAX_TX_PENDING_QLEN=${CONFIG_NRF70_MAX_TX_PENDING_QLEN} + NRF70_RPU_PS_IDLE_TIMEOUT_MS=${CONFIG_NRF70_RPU_PS_IDLE_TIMEOUT_MS} + NRF70_REG_DOMAIN=${CONFIG_NRF70_REG_DOMAIN} + NRF70_BAND_2G_LOWER_EDGE_BACKOFF_DSSS=${CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_DSSS} + NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HT} + NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_2G_LOWER_EDGE_BACKOFF_HE} + NRF70_BAND_2G_UPPER_EDGE_BACKOFF_DSSS=${CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_DSSS} + NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HT} + NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_2G_UPPER_EDGE_BACKOFF_HE} + NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HT} + NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_1_LOWER_EDGE_BACKOFF_HE} + NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HT} + NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_1_UPPER_EDGE_BACKOFF_HE} + NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HT} + NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_2A_LOWER_EDGE_BACKOFF_HE} + NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HT} + NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_2A_UPPER_EDGE_BACKOFF_HE} + NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HT} + NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_2C_LOWER_EDGE_BACKOFF_HE} + NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HT} + NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_2C_UPPER_EDGE_BACKOFF_HE} + NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HT} + NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_3_LOWER_EDGE_BACKOFF_HE} + NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HT} + NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_3_UPPER_EDGE_BACKOFF_HE} + NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HT} + NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_4_LOWER_EDGE_BACKOFF_HE} + NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HT=${CONFIG_NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HT} + NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HE=${CONFIG_NRF70_BAND_UNII_4_UPPER_EDGE_BACKOFF_HE} + NRF70_PCB_LOSS_2G=${CONFIG_NRF70_PCB_LOSS_2G} + NRF70_PCB_LOSS_5G_BAND1=${CONFIG_NRF70_PCB_LOSS_5G_BAND1} + NRF70_PCB_LOSS_5G_BAND2=${CONFIG_NRF70_PCB_LOSS_5G_BAND2} + NRF70_PCB_LOSS_5G_BAND3=${CONFIG_NRF70_PCB_LOSS_5G_BAND3} + NRF70_ANT_GAIN_2G=${CONFIG_NRF70_ANT_GAIN_2G} + NRF70_ANT_GAIN_5G_BAND1=${CONFIG_NRF70_ANT_GAIN_5G_BAND1} + NRF70_ANT_GAIN_5G_BAND2=${CONFIG_NRF70_ANT_GAIN_5G_BAND2} + NRF70_ANT_GAIN_5G_BAND3=${CONFIG_NRF70_ANT_GAIN_5G_BAND3} + NRF_WIFI_PS_INT_PS=${CONFIG_NRF_WIFI_PS_INT_PS} + NRF_WIFI_RPU_RECOVERY_PS_ACTIVE_TIMEOUT_MS=${CONFIG_NRF_WIFI_RPU_RECOVERY_PS_ACTIVE_TIMEOUT_MS} +) + +target_include_directories( + nrf-wifi-interface + INTERFACE + ${CMAKE_CURRENT_LIST_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/../bus + ${NRF_WIFI_DIR}/utils/inc + ${NRF_WIFI_DIR}/os_if/inc + ${NRF_WIFI_DIR}/bus_if/bus/qspi/inc + ${NRF_WIFI_DIR}/bus_if/bal/inc + ${NRF_WIFI_DIR}/fw_if/umac_if/inc + ${NRF_WIFI_DIR}/fw_load/mips/fw/inc + ${NRF_WIFI_DIR}/hw_if/hal/inc + ${NRF_WIFI_DIR}/hw_if/hal/inc/fw + ${NRF_WIFI_DIR}/fw_if/umac_if/inc/fw +) + +if(CONFIG_NRF70_RADIO_TEST) + target_include_directories(nrf-wifi-interface INTERFACE + ${NRF_WIFI_DIR}/fw_if/umac_if/inc/radio_test + ) +elseif(CONFIG_NRF70_OFFLOADED_RAW_TX) + target_include_directories(nrf-wifi-interface INTERFACE + ${NRF_WIFI_DIR}/fw_if/umac_if/inc/offload_raw_tx + off_raw_tx/inc + ) +else() + target_include_directories(nrf-wifi-interface INTERFACE + ${NRF_WIFI_DIR}/fw_if/umac_if/inc/default + ) +endif() + +zephyr_library_sources( + ${NRF_WIFI_DIR}/os_if/src/osal.c + ${NRF_WIFI_DIR}/utils/src/list.c + ${NRF_WIFI_DIR}/utils/src/queue.c + ${NRF_WIFI_DIR}/utils/src/util.c + ${NRF_WIFI_DIR}/hw_if/hal/src/hal_api.c + ${NRF_WIFI_DIR}/hw_if/hal/src/hal_fw_patch_loader.c + ${NRF_WIFI_DIR}/hw_if/hal/src/hal_interrupt.c + ${NRF_WIFI_DIR}/hw_if/hal/src/hal_mem.c + ${NRF_WIFI_DIR}/hw_if/hal/src/hal_reg.c + ${NRF_WIFI_DIR}/hw_if/hal/src/hpqm.c + ${NRF_WIFI_DIR}/hw_if/hal/src/pal.c + ${NRF_WIFI_DIR}/bus_if/bal/src/bal.c + ${NRF_WIFI_DIR}/bus_if/bus/qspi/src/qspi.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/cmd.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/event.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_api_common.c +) + +if(CONFIG_NRF70_RADIO_TEST) + zephyr_library_sources( + ${NRF_WIFI_DIR}/fw_if/umac_if/src/radio_test/fmac_api.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c + ) +elseif(CONFIG_NRF70_OFFLOADED_RAW_TX) + zephyr_library_sources( + ${NRF_WIFI_DIR}/fw_if/umac_if/src/offload_raw_tx/fmac_api.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c + ) +else() + zephyr_library_sources( + ${NRF_WIFI_DIR}/fw_if/umac_if/src/rx.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_vif.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/default/fmac_api.c + ) +endif() + +zephyr_library_sources_ifdef(CONFIG_NRF70_DATA_TX + ${NRF_WIFI_DIR}/fw_if/umac_if/src/tx.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_peer.c +) + +zephyr_library_sources_ifdef(CONFIG_NRF70_STA_MODE + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_peer.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c +) + +zephyr_library_sources_ifdef(CONFIG_NRF70_PROMISC_DATA_RX + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_promisc.c +) + +zephyr_library_sources_ifdef(CONFIG_NRF70_AP_MODE + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_ap.c +) + +# Without WPA supplicant we only support scan +zephyr_library_sources_ifdef(CONFIG_NRF70_STA_MODE + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_peer.c + ${NRF_WIFI_DIR}/fw_if/umac_if/src/fmac_util.c +) + +zephyr_library_sources( + shim.c + timer.c + work.c +) + +target_link_libraries(zephyr_interface INTERFACE nrf-wifi-interface) +target_link_libraries(nrf_wifi PRIVATE nrf70-buslib) diff --git a/modules/nrf_wifi/shim.c b/modules/nrf_wifi/os/shim.c similarity index 99% rename from modules/nrf_wifi/shim.c rename to modules/nrf_wifi/os/shim.c index 93cafa905c2..ed6acf95846 100644 --- a/modules/nrf_wifi/shim.c +++ b/modules/nrf_wifi/os/shim.c @@ -18,13 +18,13 @@ #include #include #include +#include +#include -#include "rpu_hw_if.h" #include "shim.h" #include "work.h" #include "timer.h" #include "osal_ops.h" -#include "qspi_if.h" LOG_MODULE_REGISTER(wifi_nrf, CONFIG_WIFI_NRF70_LOG_LEVEL); diff --git a/modules/nrf_wifi/shim.h b/modules/nrf_wifi/os/shim.h similarity index 100% rename from modules/nrf_wifi/shim.h rename to modules/nrf_wifi/os/shim.h diff --git a/modules/nrf_wifi/timer.c b/modules/nrf_wifi/os/timer.c similarity index 100% rename from modules/nrf_wifi/timer.c rename to modules/nrf_wifi/os/timer.c diff --git a/modules/nrf_wifi/timer.h b/modules/nrf_wifi/os/timer.h similarity index 100% rename from modules/nrf_wifi/timer.h rename to modules/nrf_wifi/os/timer.h diff --git a/modules/nrf_wifi/work.c b/modules/nrf_wifi/os/work.c similarity index 100% rename from modules/nrf_wifi/work.c rename to modules/nrf_wifi/os/work.c diff --git a/modules/nrf_wifi/work.h b/modules/nrf_wifi/os/work.h similarity index 100% rename from modules/nrf_wifi/work.h rename to modules/nrf_wifi/os/work.h diff --git a/tests/boards/nrf/nrf70/bustest/CMakeLists.txt b/tests/boards/nrf/nrf70/bustest/CMakeLists.txt new file mode 100644 index 00000000000..741d622b119 --- /dev/null +++ b/tests/boards/nrf/nrf70/bustest/CMakeLists.txt @@ -0,0 +1,16 @@ +# +# Copyright (c) 2024 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: BSD-3-Clause +# + +cmake_minimum_required(VERSION 3.20.0) + +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) +project(nrf70_bustest) + +target_sources(app PRIVATE + src/main.c +) + +target_link_libraries(app PUBLIC nrf70-buslib) diff --git a/tests/boards/nrf/nrf70/bustest/Kconfig b/tests/boards/nrf/nrf70/bustest/Kconfig new file mode 100644 index 00000000000..d76ab2cda6c --- /dev/null +++ b/tests/boards/nrf/nrf70/bustest/Kconfig @@ -0,0 +1,15 @@ +# +# Copyright (c) 2024 Nordic Semiconductor +# +# SPDX-License-Identifier: Apache-2.0 +# +source "Kconfig.zephyr" + +menu "NRF70 Buslib test sample" + +config NRF70BUS_MEMTEST_LENGTH + int "Memory test length" + default 1024 + help + This option sets the default length for the memory test. +endmenu diff --git a/tests/boards/nrf/nrf70/bustest/prj.conf b/tests/boards/nrf/nrf70/bustest/prj.conf new file mode 100644 index 00000000000..52107957801 --- /dev/null +++ b/tests/boards/nrf/nrf70/bustest/prj.conf @@ -0,0 +1,27 @@ +CONFIG_NRF70_BUSLIB=y +CONFIG_ZTEST=y + +CONFIG_HEAP_MEM_POOL_SIZE=50000 +CONFIG_HEAP_MEM_POOL_IGNORE_MIN=y + +# System settings +CONFIG_ASSERT=y + +CONFIG_INIT_STACKS=y + +# Memories +CONFIG_MAIN_STACK_SIZE=5200 + +# Debugging +CONFIG_STACK_SENTINEL=y +CONFIG_DEBUG_COREDUMP=y +CONFIG_DEBUG_COREDUMP_BACKEND_LOGGING=y +CONFIG_SHELL_CMDS_RESIZE=n +CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL_DBG=y + +# Logging +CONFIG_LOG=y +CONFIG_PRINTK=y +# If below config is enabled, printk logs are +# buffered. For unbuffered messages, disable this. +CONFIG_LOG_PRINTK=n diff --git a/tests/boards/nrf/nrf70/bustest/src/main.c b/tests/boards/nrf/nrf70/bustest/src/main.c new file mode 100644 index 00000000000..cf7cdfa4164 --- /dev/null +++ b/tests/boards/nrf/nrf70/bustest/src/main.c @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2024 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/** + * @brief File containing ztests for nrf70 buslib library + */ + +#include +#include +#include +#include +#include + +LOG_MODULE_REGISTER(nrf70_bustest, CONFIG_WIFI_NRF70_BUSLIB_LOG_LEVEL); + +#define DATARAM_ADDR 0x0C0000 +static struct qspi_dev *dev; + +static int wifi_on(void *state) +{ + int ret; + + ARG_UNUSED(state); + + dev = qspi_dev(); + + ret = rpu_init(); + if (ret) { + LOG_ERR("%s: RPU init failed with error %d", __func__, ret); + return -1; + } + + ret = dev->init(qspi_defconfig()); + if (ret) { + LOG_ERR("%s: QSPI device init failed", __func__); + return -1; + } + + ret = rpu_enable(); + if (ret) { + LOG_ERR("%s: RPU enable failed with error %d", __func__, ret); + return -1; + } + k_sleep(K_MSEC(10)); + LOG_INF("Wi-Fi ON done"); + return 0; +} + +static void wifi_off(void *state) +{ + ARG_UNUSED(state); + + int ret; + + ret = rpu_disable(); + if (ret) { + LOG_ERR("%s: RPU disable failed with error %d", __func__, ret); + } + + ret = dev->deinit(); + if (ret) { + LOG_ERR("%s: QSPI device de-init failed", __func__); + } + k_sleep(K_MSEC(10)); + LOG_INF("Wi-Fi OFF done"); +} + + +static int memtest(uint32_t addr, char *memblock_name) +{ + const uint32_t pattern = 0x12345678; + uint32_t offset = 1; + uint32_t *buff, *rxbuff; + int i; + + int err_count; + int32_t rem_words = CONFIG_NRF70BUS_MEMTEST_LENGTH; + uint32_t test_chunk, chunk_no = 0; + int ret = -1; + + buff = k_malloc(CONFIG_NRF70BUS_MEMTEST_LENGTH * 4); + if (buff == NULL) { + LOG_ERR("Failed to allocate memory for buff"); + return -1; + } + + rxbuff = k_malloc(CONFIG_NRF70BUS_MEMTEST_LENGTH * 4); + if (rxbuff == NULL) { + LOG_ERR("Failed to allocate memory for rxbuff"); + k_free(buff); + return -1; + } + + while (rem_words > 0) { + test_chunk = (rem_words < CONFIG_NRF70BUS_MEMTEST_LENGTH) ? + rem_words : CONFIG_NRF70BUS_MEMTEST_LENGTH; + + for (i = 0; i < test_chunk; i++) { + buff[i] = pattern + + (i + chunk_no * CONFIG_NRF70BUS_MEMTEST_LENGTH) * offset; + } + + addr = addr + chunk_no * CONFIG_NRF70BUS_MEMTEST_LENGTH; + + if (rpu_write(addr, buff, test_chunk * 4) || + rpu_read(addr, rxbuff, test_chunk * 4)) { + goto err; + } + + err_count = 0; + for (i = 0; i < test_chunk; i++) { + if (buff[i] != rxbuff[i]) { + err_count++; + LOG_ERR("%s: failed (%d), Expected 0x%x, Read 0x%x", + __func__, i, buff[i], rxbuff[i]); + if (err_count > 4) + goto err; + } + } + if (err_count) { + goto err; + } + rem_words -= CONFIG_NRF70BUS_MEMTEST_LENGTH; + chunk_no++; + } + ret = 0; +err: + k_free(rxbuff); + k_free(buff); + return ret; +} + +static int test_sysbus(void) +{ + int val, i; + /* List of some SYS bus addresses and default values to test bus read + * integrity + */ + const uint32_t addr[] = {0x714, 0x71c, 0x720, + 0x728, 0x734, 0x738}; + const uint32_t val_arr[] = { + 0x000003f3, 0x0110f13f, 0x000003f3, + 0x0003073f, 0x0003073f, 0x03013f8f}; + + for (i = 0; i < ARRAY_SIZE(addr); i++) { + rpu_read(addr[i], &val, 4); + if (val != val_arr[i]) { + LOG_ERR("%s: SYSBUS R/W failed (%d) : read = 0x%x, expected = 0x%x", + __func__, i, val, val_arr[i]); + return -1; + } + } + return 0; +} + +static int test_peripbus(void) +{ + uint32_t val; + int i; + /* Some Perip bus addresses that we can write/read to validate bus access*/ + const uint32_t addr[] = {0x62820, 0x62830, 0x62840, 0x62850, 0x62860, 0x62870}; + + for (i = 0; i < ARRAY_SIZE(addr); i++) { + val = 0xA5A5A5A5; /* Test pattern */ + rpu_write(addr[i], &val, 4); + val = 0; + rpu_read(addr[i], &val, 4); + /* Perip bus is 24-bit and hence LS 8 bits read are invalid, so discard them + * in the check + */ + if (val >> 8 != 0xA5A5A5) { + LOG_ERR("%s: PERIP BUS R/W failed (%d): read = 0x%x", + __func__, i, val >> 8); + return -1; + } + } + return 0; +} + +ZTEST_SUITE(bustest_suite, NULL, (void *)wifi_on, NULL, NULL, wifi_off); + +ZTEST(bustest_suite, test_sysbus) +{ + zassert_equal(0, test_sysbus(), "SYSBUS read validation failed!!!"); +} + +ZTEST(bustest_suite, test_peripbus) +{ + zassert_equal(0, test_peripbus(), "PERIP BUS read/write validation failed!!!"); +} + +ZTEST(bustest_suite, test_dataram) +{ + zassert_equal(0, memtest(DATARAM_ADDR, "DATA RAM"), "DATA RAM memtest failed!!!"); +} diff --git a/tests/boards/nrf/nrf70/bustest/testcase.yaml b/tests/boards/nrf/nrf70/bustest/testcase.yaml new file mode 100644 index 00000000000..29dc054b823 --- /dev/null +++ b/tests/boards/nrf/nrf70/bustest/testcase.yaml @@ -0,0 +1,20 @@ +tests: + nrf_wifi.bustest.nrf7002: + sysbuild: true + build_only: true + integration_platforms: + - nrf7002dk/nrf5340/cpuapp + platform_allow: nrf7002dk/nrf5340/cpuapp + + nrf_wifi.bustest.nrf7002ek: + sysbuild: true + build_only: true + extra_args: SHIELD=nrf7002ek + integration_platforms: + - nrf5340dk/nrf5340/cpuapp + - nrf52840dk/nrf52840 + - nucleo_h723zg + platform_allow: + - nrf5340dk/nrf5340/cpuapp + - nrf52840dk/nrf52840 + - nucleo_h723zg