X-Git-Url: https://repo.jachan.dev/esp-hosted.git/blobdiff_plain/c343d51c54f935e53ce817378213d28cc7f4ac38..f50515988b8cde8db9a26f6fdf881b341a4322ec:/esp_hosted_ng/host/main.c diff --git a/esp_hosted_ng/host/main.c b/esp_hosted_ng/host/main.c index b30e81a..977f6cb 100644 --- a/esp_hosted_ng/host/main.c +++ b/esp_hosted_ng/host/main.c @@ -24,11 +24,15 @@ #define RELEASE_VERSION "1.0.3" #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"); @@ -39,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); @@ -155,7 +165,7 @@ static int process_tx_packet(struct sk_buff *skb) ret = esp_send_packet(priv->adapter, skb); if (ret) { -/* esp_err("Failed to send SKB");*/ + esp_verbose("Failed to send SKB"); priv->stats.tx_errors++; } else { priv->stats.tx_packets++; @@ -285,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; @@ -381,36 +392,9 @@ static int esp_set_mac_address(struct net_device *ndev, void *data) static void esp_set_rx_mode(struct net_device *ndev) { - struct esp_wifi_device *priv = netdev_priv(ndev); - struct netdev_hw_addr *mac_addr; - u32 count = 0; -#if 0 - struct in_device *in_dev = in_dev_get(ndev); - struct ip_mc_list *ip_list = in_dev->mc_list; -#endif - netdev_for_each_mc_addr(mac_addr, ndev) { - if (count < MAX_MULTICAST_ADDR_COUNT) { - /*esp_info("%d: "MACSTR"\n", count+1, MAC2STR(mac_addr->addr));*/ - memcpy(&mcast_list.mcast_addr[count++], mac_addr->addr, ETH_ALEN); - } - } - - mcast_list.priv = priv; - mcast_list.addr_count = count; - - if (priv->port_open) { - /*esp_info("Set Multicast list\n");*/ - if (adapter.mac_filter_wq) - queue_work(adapter.mac_filter_wq, &adapter.mac_flter_work); - } -#if 0 - cmd_set_mcast_mac_list(priv, &mcast_list); - while (ip_list) { - esp_dbg(" IP MC Address: 0x%x\n", ip_list->multiaddr); - ip_list = ip_list->next; - } -#endif + struct esp_adapter *adapter = esp_get_adapter(); + schedule_work(&adapter->mac_flter_work); } static int esp_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev) @@ -429,7 +413,7 @@ static int esp_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev) if (!priv->port_open) { priv->stats.tx_dropped++; - /*esp_err("Port not yet open\n");*/ + esp_verbose("Port not yet open\n"); dev_kfree_skb(skb); return NETDEV_TX_OK; } @@ -475,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 */ @@ -496,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; } @@ -586,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); @@ -671,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; @@ -684,7 +668,7 @@ static void process_rx_packet(struct esp_adapter *adapter, struct sk_buff *skb) offset = le16_to_cpu(payload_header->offset); if (payload_header->reserved2 == 0xFF) { - print_hex_dump(KERN_INFO, "Wake up packet: ", DUMP_PREFIX_ADDRESS, 16, 1, skb->data, len+offset, 1); + esp_hex_dump("Wake up packet: ", skb->data, len+offset); } if (adapter->capabilities & ESP_CHECKSUM_ENABLED) { @@ -714,29 +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__); - 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); - - 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) { @@ -794,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) @@ -880,7 +879,40 @@ static void esp_if_rx_work(struct work_struct *work) static void update_mac_filter(struct work_struct *work) { + struct esp_adapter *adapter = esp_get_adapter(); + struct esp_wifi_device *priv = adapter->priv[0]; + struct net_device *ndev; + struct netdev_hw_addr *mac_addr; + u32 count = 0; + + if (!priv) + return; + + ndev = priv->ndev; + if (!ndev) + return; + + if (!priv->port_open) { + esp_verbose("Port is not open yet, skipping mac filter update\n"); + return; + } + +#if CONFIG_ALLOW_MULTICAST_WAKEUP + netdev_for_each_mc_addr(mac_addr, ndev) { + if (count < MAX_MULTICAST_ADDR_COUNT) { + esp_verbose("%d: "MACSTR"\n", count+1, MAC2STR(mac_addr->addr)); + memcpy(&mcast_list.mcast_addr[count++], mac_addr->addr, ETH_ALEN); + } + } + + mcast_list.priv = priv; + mcast_list.addr_count = count; + + esp_verbose("Setting Multicast list\n"); cmd_set_mcast_mac_list(mcast_list.priv, &mcast_list); +#else + esp_info("Not setting FW multicast addresses\n"); +#endif } static void esp_events_work(struct work_struct *work) @@ -920,12 +952,6 @@ static struct esp_adapter *init_adapter(void) INIT_WORK(&adapter.events_work, esp_events_work); - adapter.mac_filter_wq = alloc_workqueue("MAC_FILTER", 0, 0); - if (!adapter.mac_filter_wq) { - deinit_adapter(); - return NULL; - } - INIT_WORK(&adapter.mac_flter_work, update_mac_filter); return &adapter; @@ -940,9 +966,6 @@ static void deinit_adapter(void) if (adapter.if_rx_workqueue) destroy_workqueue(adapter.if_rx_workqueue); - - if (adapter.mac_filter_wq) - destroy_workqueue(adapter.mac_filter_wq); } static void esp_reset(void) @@ -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);