From: Kapil Gupta Date: Fri, 5 Jan 2024 13:48:29 +0000 (+0530) Subject: fix(esp_hosted_ng): Add support for esp32-c6 SDIO X-Git-Tag: example~62^2~1 X-Git-Url: https://repo.jachan.dev/esp-hosted.git/commitdiff_plain/366297f99e61c998558598c66657e58152ae3bef fix(esp_hosted_ng): Add support for esp32-c6 SDIO --- diff --git a/esp_hosted_ng/esp/esp_driver/network_adapter/main/app_main.c b/esp_hosted_ng/esp/esp_driver/network_adapter/main/app_main.c index dce11a3..48d5a60 100644 --- a/esp_hosted_ng/esp/esp_driver/network_adapter/main/app_main.c +++ b/esp_hosted_ng/esp/esp_driver/network_adapter/main/app_main.c @@ -300,7 +300,6 @@ void process_tx_pkt(interface_buffer_handle_t *buf_handle) buf_handle->free_buf_handle(buf_handle->priv_buffer_handle); buf_handle->priv_buffer_handle = NULL; } - ESP_LOGD(TAG, "Data path stopped"); usleep(100*1000); return; } diff --git a/esp_hosted_ng/esp/esp_driver/network_adapter/main/include/interface.h b/esp_hosted_ng/esp/esp_driver/network_adapter/main/include/interface.h index d4d79d6..07c5920 100644 --- a/esp_hosted_ng/esp/esp_driver/network_adapter/main/include/interface.h +++ b/esp_hosted_ng/esp/esp_driver/network_adapter/main/include/interface.h @@ -23,7 +23,7 @@ #if defined(CONFIG_IDF_TARGET_ESP32)||defined(CONFIG_IDF_TARGET_ESP32C6) #include "driver/sdio_slave.h" #else - #error "SDIO is not supported ESP32S2" + #error "SDIO is not supported" #endif #endif diff --git a/esp_hosted_ng/host/Makefile b/esp_hosted_ng/host/Makefile index 4cf3c20..9e820da 100644 --- a/esp_hosted_ng/host/Makefile +++ b/esp_hosted_ng/host/Makefile @@ -8,11 +8,11 @@ CONFIG_ENABLE_MONITOR_PROCESS = n ESP_SLAVE := "" # Toolchain Path -CROSS_COMPILE := /usr/bin/arm-linux-gnueabihf- +CROSS_COMPILE := # Linux Kernel header KERNEL := /lib/modules/$(shell uname -r)/build # Architecture -ARCH := arm +ARCH := arm64 #Default interface is sdio MODULE_NAME=esp32_sdio diff --git a/esp_hosted_ng/host/esp_bt.c b/esp_hosted_ng/host/esp_bt.c index 9fdc08a..d2a3bee 100644 --- a/esp_hosted_ng/host/esp_bt.c +++ b/esp_hosted_ng/host/esp_bt.c @@ -242,6 +242,9 @@ int esp_init_bt(struct esp_adapter *adapter) hdev->dev_type = HCI_PRIMARY; + if (adapter->if_type == ESP_IF_TYPE_SDIO) + SET_HCIDEV_DEV(hdev, adapter->dev); + ret = hci_register_dev(hdev); if (ret < 0) { BT_ERR("Can not register HCI device"); diff --git a/esp_hosted_ng/host/esp_cfg80211.c b/esp_hosted_ng/host/esp_cfg80211.c index 62ed5f2..65ddaec 100644 --- a/esp_hosted_ng/host/esp_cfg80211.c +++ b/esp_hosted_ng/host/esp_cfg80211.c @@ -599,15 +599,21 @@ static void esp_reg_notifier(struct wiphy *wiphy, return; } + if (!test_bit(ESP_INIT_DONE, &adapter->state_flags)) { + esp_info("Driver init is ongoing\n"); + return; + } + if (test_bit(ESP_CLEANUP_IN_PROGRESS, &adapter->state_flags)) { + esp_info("Driver cleanup is ongoing\n"); + return; + } + esp_dev = wiphy_priv(wiphy); if (!esp_dev || !esp_dev->adapter) { esp_info("%u esp_dev not initialized yet \n", __LINE__); return; } - if (test_bit(ESP_CLEANUP_IN_PROGRESS, &adapter->state_flags)) { - return; - } priv = esp_dev->adapter->priv[0]; diff --git a/esp_hosted_ng/host/include/esp.h b/esp_hosted_ng/host/include/esp.h index 39501fb..c00db16 100644 --- a/esp_hosted_ng/host/include/esp.h +++ b/esp_hosted_ng/host/include/esp.h @@ -60,6 +60,7 @@ enum adapter_flags_e { ESP_CLEANUP_IN_PROGRESS, /* Driver unloading or ESP reseted */ ESP_CMD_INIT_DONE, /* Cmd component is initialized with esp_commands_setup() */ ESP_DRIVER_ACTIVE, /* kernel module __exit is not yet invoked */ + ESP_INIT_DONE, /* Driver init done */ }; enum priv_flags_e { diff --git a/esp_hosted_ng/host/rpi_init.sh b/esp_hosted_ng/host/rpi_init.sh index 588fe26..15a7ff8 100755 --- a/esp_hosted_ng/host/rpi_init.sh +++ b/esp_hosted_ng/host/rpi_init.sh @@ -49,12 +49,25 @@ wlan_init() VAL_CONFIG_TEST_RAW_TP=y fi + if [ "$ESP_SLAVE" != "" ] ; then + CUSTOM_OPTS=${CUSTOM_OPTS}" ESP_SLAVE=\"$ESP_SLAVE"\" + fi + if [ "$CUSTOM_OPTS" != "" ] ; then + echo "Adding $CUSTOM_OPTS" + fi + # For Linux other than Raspberry Pi, Please point # CROSS_COMPILE -> /bin/arm-linux-gnueabihf- # KERNEL -> Place where kernel is checked out and built # ARCH -> Architecture - make -j8 target=$IF_TYPE CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- KERNEL="/lib/modules/$(uname -r)/build" \ - CONFIG_TEST_RAW_TP="$VAL_CONFIG_TEST_RAW_TP" ARCH=arm + # make -j8 target=$IF_TYPE CROSS_COMPILE=/usr/bin/arm-linux-gnueabihf- KERNEL="/lib/modules/$(uname -r)/build" \ + # CONFIG_TEST_RAW_TP="$VAL_CONFIG_TEST_RAW_TP" ARCH=arm64 + + # Populate your arch if not populated correctly. + arch_num_bits=$(getconf LONG_BIT) + if [ "$arch_num_bits" = "32" ] ; then arch_found="arm"; else arch_found="arm64"; fi + + make -j8 target=$IF_TYPE KERNEL="/lib/modules/$(uname -r)/build" CONFIG_TEST_RAW_TP="$VAL_CONFIG_TEST_RAW_TP" ARCH=$arch_found $CUSTOM_OPTS if [ "$RESETPIN" = "" ] ; then #By Default, BCM6 is GPIO on host. use resetpin=6 @@ -153,6 +166,10 @@ select_esp_slave() echo "Building for esp32" ESP_SLAVE='CONFIG_TARGET_ESP32=y' ;; + [Ee][Ss][Pp]32[Cc]6) + echo "Building for esp32c6" + ESP_SLAVE='CONFIG_TARGET_ESP32C6=y' + ;; [Ee][Ss][Pp]32-[Cc]6) echo "Building for esp32c6" ESP_SLAVE='CONFIG_TARGET_ESP32C6=y' @@ -172,10 +189,10 @@ if [ "$IF_TYPE" = "" ] ; then usage exit 1 else - if [ "$IF_TYPE" = "sdio" ] ; then - # SDIO Kernel driver registration varies for ESP32 and ESP32-C6 slave chipsets - select_esp_slave - fi +if [ "$IF_TYPE" = "sdio" ] ; then + # SDIO Kernel driver registration varies for ESP32 and ESP32-C6 slave chipsets + select_esp_slave +fi echo "Building for $IF_TYPE protocol" MODULE_NAME=esp32_${IF_TYPE}.ko fi diff --git a/esp_hosted_ng/host/sdio/esp_sdio.c b/esp_hosted_ng/host/sdio/esp_sdio.c index a3a74f8..dba7f4b 100644 --- a/esp_hosted_ng/host/sdio/esp_sdio.c +++ b/esp_hosted_ng/host/sdio/esp_sdio.c @@ -653,7 +653,7 @@ static int tx_process(void *data) return 0; } -static struct esp_sdio_context *init_sdio_func(struct sdio_func *func) +static struct esp_sdio_context *init_sdio_func(struct sdio_func *func, int *sdio_ret) { struct esp_sdio_context *context = NULL; int ret = 0; @@ -670,13 +670,24 @@ static struct esp_sdio_context *init_sdio_func(struct sdio_func *func) /* Enable Function */ ret = sdio_enable_func(func); if (ret) { + esp_err("sdio_enable_func ret: %d\n", ret); + if (sdio_ret) + *sdio_ret = ret; + sdio_release_host(func); + return NULL; } /* Register IRQ */ ret = sdio_claim_irq(func, esp_handle_isr); if (ret) { + esp_err("sdio_claim_irq ret: %d\n", ret); sdio_disable_func(func); + + if (sdio_ret) + *sdio_ret = ret; + sdio_release_host(func); + return NULL; } @@ -757,10 +768,13 @@ static int esp_probe(struct sdio_func *func, esp_info("ESP network device detected\n"); - context = init_sdio_func(func); + context = init_sdio_func(func, &ret);; if (!context) { - return -EINVAL; + if (ret) + return ret; + else + return -EINVAL; } if (sdio_context.sdio_clk_mhz) { @@ -886,12 +900,12 @@ MODULE_DEVICE_TABLE(of, esp_sdio_of_match); /* SDIO driver structure to be registered with kernel */ static struct sdio_driver esp_sdio_driver = { - .name = "esp_sdio", + .name = KBUILD_MODNAME, .id_table = esp_devices, .probe = esp_probe, .remove = esp_remove, .drv = { - .name = "esp_sdio", + .name = KBUILD_MODNAME, .owner = THIS_MODULE, .pm = &esp_pm_ops, .of_match_table = esp_sdio_of_match, @@ -923,8 +937,14 @@ void process_event_esp_bootup(struct esp_adapter *adapter, u8 *evt_buf, u8 len) if (!evt_buf) return; + if (len_left >= 64) { + esp_info("ESP init event len looks unexpected: %u (>=64)\n", len_left); + esp_info("You probably facing timing mismatch at transport layer\n"); + } + pos = evt_buf; + clear_bit(ESP_INIT_DONE, &adapter->state_flags); while (len_left) { tag_len = *(pos + 1); @@ -933,8 +953,6 @@ void process_event_esp_bootup(struct esp_adapter *adapter, u8 *evt_buf, u8 len) if (*pos == ESP_BOOTUP_CAPABILITY) { adapter->capabilities = *(pos + 2); - process_capabilities(adapter); - print_capabilities(*(pos + 2)); } else if (*pos == ESP_BOOTUP_FIRMWARE_CHIP_ID) { @@ -958,11 +976,12 @@ void process_event_esp_bootup(struct esp_adapter *adapter, u8 *evt_buf, u8 len) if (tag_len != sizeof(struct fw_data)) esp_info("Length not matching to firmware data size\n"); else - if (process_fw_data((struct fw_data *)(pos + 2))) + if (process_fw_data((struct fw_data *)(pos + 2))) { if (context->func) { generate_slave_intr(context, BIT(ESP_CLOSE_DATA_PATH)); return; } + } } else { esp_warn("Unsupported tag in event"); @@ -975,6 +994,10 @@ void process_event_esp_bootup(struct esp_adapter *adapter, u8 *evt_buf, u8 len) if (esp_add_card(adapter)) { esp_err("network iterface init failed\n"); generate_slave_intr(context, BIT(ESP_CLOSE_DATA_PATH)); + } else { + set_bit(ESP_INIT_DONE, &adapter->state_flags); + process_capabilities(adapter); + print_capabilities(adapter->capabilities); } } diff --git a/esp_hosted_ng/host/spi/esp_spi.c b/esp_hosted_ng/host/spi/esp_spi.c index 9179e66..0395bbd 100644 --- a/esp_hosted_ng/host/spi/esp_spi.c +++ b/esp_hosted_ng/host/spi/esp_spi.c @@ -286,6 +286,8 @@ void process_event_esp_bootup(struct esp_adapter *adapter, u8 *evt_buf, u8 len) if (esp_add_card(adapter)) { esp_err("network iterface init failed\n"); + } else { + set_bit(ESP_INIT_DONE, &adapter->state_flags); } process_capabilities(adapter);