X-Git-Url: https://repo.jachan.dev/esp-hosted.git/blobdiff_plain/50785e929bec9331560492187d54be85131ff62d..f50515988b8cde8db9a26f6fdf881b341a4322ec:/esp_hosted_ng/host/main.c diff --git a/esp_hosted_ng/host/main.c b/esp_hosted_ng/host/main.c index debb587..977f6cb 100644 --- a/esp_hosted_ng/host/main.c +++ b/esp_hosted_ng/host/main.c @@ -26,10 +26,13 @@ #define HOST_GPIO_PIN_INVALID -1 #define CONFIG_ALLOW_MULTICAST_WAKEUP 1 static int resetpin = HOST_GPIO_PIN_INVALID; +static int readypin = HOST_GPIO_PIN_INVALID; +static int handshakepin = HOST_GPIO_PIN_INVALID; static u32 clockspeed = 0; extern u8 ap_bssid[MAC_ADDR_LEN]; extern volatile u8 host_sleep; u32 raw_tp_mode = 0; +int log_level = ESP_INFO; module_param(resetpin, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); MODULE_PARM_DESC(resetpin, "Host's GPIO pin number which is connected to ESP32's EN to reset ESP32 device"); @@ -40,6 +43,12 @@ MODULE_PARM_DESC(clockspeed, "Hosts clock speed in MHz"); module_param(raw_tp_mode, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); MODULE_PARM_DESC(raw_tp_mode, "Mode choosed to test raw throughput"); +module_param(readypin, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); +MODULE_PARM_DESC(readypin, "Data ready pin default is pin 13, gpio27"); + +module_param(handshakepin, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); +MODULE_PARM_DESC(handshakepin, "Handshake pin default is pin 15, gpio22"); + static void deinit_adapter(void); @@ -286,6 +295,7 @@ int process_event_esp_bootup(struct esp_adapter *adapter, u8 *evt_buf, u8 len) clear_bit(ESP_INIT_DONE, &adapter->state_flags); /* Deinit module if already initialized */ + test_raw_tp_cleanup(); esp_deinit_module(adapter); pos = evt_buf; @@ -449,7 +459,7 @@ static int esp_add_network_ifaces(struct esp_adapter *adapter) } rtnl_lock(); - wdev = esp_cfg80211_add_iface(adapter->wiphy, "espsta%d", 1, NL80211_IFTYPE_STATION, NULL); + wdev = esp_cfg80211_add_iface(adapter->wiphy, "wlan%d", 1, NL80211_IFTYPE_STATION, NULL); rtnl_unlock(); /* Return success if network added successfully */ @@ -470,6 +480,7 @@ int esp_add_card(struct esp_adapter *adapter) RET_ON_FAIL(esp_commands_setup(adapter)); RET_ON_FAIL(esp_add_wiphy(adapter)); RET_ON_FAIL(esp_add_network_ifaces(adapter)); + clear_bit(ESP_CLEANUP_IN_PROGRESS, &adapter->state_flags); return 0; } @@ -560,6 +571,7 @@ int esp_remove_card(struct esp_adapter *adapter) } esp_stop_network_ifaces(adapter); + esp_cfg_cleanup(adapter); /* BT may have been initialized after fw bootup event, deinit it */ esp_deinit_bt(adapter); esp_commands_teardown(adapter); @@ -645,8 +657,6 @@ static void process_rx_packet(struct esp_adapter *adapter, struct sk_buff *skb) u16 rx_checksum = 0, checksum = 0; struct hci_dev *hdev = adapter->hcidev; u8 *type = NULL; - struct sk_buff *eap_skb = NULL; - struct ethhdr *eth = NULL; if (!skb) return; @@ -688,31 +698,11 @@ static void process_rx_packet(struct esp_adapter *adapter, struct sk_buff *skb) } if (payload_header->packet_type == PACKET_TYPE_EAPOL) { - esp_info("Rx PACKET_TYPE_EAPOL!!!!\n"); + esp_dbg("Rx PACKET_TYPE_EAPOL!!!!\n"); esp_port_open(priv); - - eap_skb = alloc_skb(skb->len + ETH_HLEN, GFP_KERNEL); - if (!eap_skb) { - esp_info("%u memory alloc failed\n", __LINE__); - dev_kfree_skb_any(skb); - return; - } - eap_skb->dev = priv->ndev; - - if (!IS_ALIGNED((unsigned long) eap_skb->data, SKB_DATA_ADDR_ALIGNMENT)) { - esp_info("%u eap skb unaligned\n", __LINE__); - } - - eth = (struct ethhdr *) skb_put(eap_skb, ETH_HLEN); - ether_addr_copy(eth->h_dest, /*skb->data*/priv->ndev->dev_addr); - ether_addr_copy(eth->h_source, /*skb->data+6*/ ap_bssid); - eth->h_proto = cpu_to_be16(ETH_P_PAE); - - skb_put_data(eap_skb, skb->data, skb->len); - eap_skb->protocol = eth_type_trans(eap_skb, eap_skb->dev); - dev_kfree_skb_any(skb); - - netif_rx(eap_skb); + skb->dev = priv->ndev; + skb->protocol = eth_type_trans(skb, priv->ndev); + netif_rx(skb); } else if (payload_header->packet_type == PACKET_TYPE_DATA) { @@ -770,6 +760,39 @@ static void process_rx_packet(struct esp_adapter *adapter, struct sk_buff *skb) } } +char *esp_get_hardware_name(int hardware_id) +{ + if(hardware_id == ESP_FIRMWARE_CHIP_ESP32) + return "ESP32"; + else if(hardware_id == ESP_FIRMWARE_CHIP_ESP32S2) + return "ESP32S2"; + else if(hardware_id == ESP_FIRMWARE_CHIP_ESP32C3) + return "ESP32C3"; + else if(hardware_id == ESP_FIRMWARE_CHIP_ESP32S3) + return "ESP32S3"; + else if(hardware_id == ESP_FIRMWARE_CHIP_ESP32C2) + return "ESP32C2"; + else if(hardware_id == ESP_FIRMWARE_CHIP_ESP32C6) + return "ESP32C6"; + else + return "N/A"; +} + +bool esp_is_valid_hardware_id(int hardware_id) +{ + switch(hardware_id) { + case ESP_FIRMWARE_CHIP_ESP32: + case ESP_FIRMWARE_CHIP_ESP32S2: + case ESP_FIRMWARE_CHIP_ESP32C3: + case ESP_FIRMWARE_CHIP_ESP32S3: + case ESP_FIRMWARE_CHIP_ESP32C2: + case ESP_FIRMWARE_CHIP_ESP32C6: + return true; + default: + return false; + } +} + int esp_is_tx_queue_paused(struct esp_wifi_device *priv) { if (!priv || !priv->ndev) @@ -970,11 +993,31 @@ static void esp_reset(void) } } +void dt_get_reset_pin(void) +{ + struct device_node *resetpin_node = NULL; + int temp_resetpin = HOST_GPIO_PIN_INVALID; + + + resetpin_node = of_find_compatible_node(NULL, NULL, "espressif,esp_sdio"); + if (!resetpin_node) + resetpin_node = of_find_compatible_node(NULL, NULL, "espressif,esp_spi"); + if (resetpin_node){ + of_property_read_u32(resetpin_node, "resetpin", &temp_resetpin); + if (temp_resetpin == HOST_GPIO_PIN_INVALID) + esp_warn("Unable to find resetpin in device tree.\n"); + else + resetpin = temp_resetpin; + } +} static int __init esp_init(void) { int ret = 0; struct esp_adapter *adapter = NULL; + struct esp_if_params if_params; + + dt_get_reset_pin(); /* Reset ESP, Clean start ESP */ esp_reset(); @@ -985,13 +1028,17 @@ static int __init esp_init(void) if (!adapter) return -EFAULT; + if_params.speed = clockspeed; + if_params.handshake_pin = handshakepin; + if_params.data_ready_pin = readypin; /* Init transport layer */ - ret = esp_init_interface_layer(adapter, clockspeed); + ret = esp_init_interface_layer(adapter, &if_params); if (ret != 0) { deinit_adapter(); } + ret = debugfs_init(); return ret; } @@ -1014,11 +1061,13 @@ static void __exit esp_exit(void) if (resetpin != HOST_GPIO_PIN_INVALID) { gpio_free(resetpin); } + debugfs_exit(); } MODULE_LICENSE("GPL"); MODULE_AUTHOR("Amey Inamdar "); MODULE_AUTHOR("Mangesh Malusare "); MODULE_AUTHOR("Yogesh Mantri "); +MODULE_AUTHOR("Kapil Gupta "); MODULE_DESCRIPTION("Wifi driver for ESP-Hosted solution"); MODULE_VERSION(RELEASE_VERSION); module_init(esp_init);