]> Git Repo - esp-hosted.git/blobdiff - esp_hosted_ng/host/main.c
Allow to specify reset pins via DT
[esp-hosted.git] / esp_hosted_ng / host / main.c
index 258d2bddef1d89623eb31de1c8bdb1412a923594..977f6cb6ef4a4d29458cb8a4fb2e68eadc1fa154 100644 (file)
@@ -26,6 +26,8 @@
 #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;
@@ -41,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);
 
 
@@ -287,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;
@@ -450,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 */
@@ -471,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;
 }
@@ -561,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);
@@ -646,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;
@@ -689,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) {
 
@@ -771,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)
@@ -971,10 +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,8 +1028,11 @@ 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();
This page took 0.027846 seconds and 4 git commands to generate.