1 // SPDX-License-Identifier: GPL-2.0-only
3 * Espressif Systems Wireless LAN device driver
5 * SPDX-FileCopyrightText: 2015-2023 Espressif Systems (Shanghai) CO LTD
9 #include <linux/init.h>
10 #include <linux/module.h>
11 #include <linux/kernel.h>
12 #include <linux/gpio.h>
13 #include <linux/igmp.h>
17 #include "esp_bt_api.h"
20 #include "esp_kernel_port.h"
22 #include "esp_cfg80211.h"
23 #include "esp_stats.h"
25 #define RELEASE_VERSION "1.0.3"
26 #define HOST_GPIO_PIN_INVALID -1
27 #define CONFIG_ALLOW_MULTICAST_WAKEUP 1
28 static int resetpin = HOST_GPIO_PIN_INVALID;
29 static u32 clockspeed = 0;
30 extern u8 ap_bssid[MAC_ADDR_LEN];
31 extern volatile u8 host_sleep;
33 int log_level = ESP_INFO;
35 module_param(resetpin, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
36 MODULE_PARM_DESC(resetpin, "Host's GPIO pin number which is connected to ESP32's EN to reset ESP32 device");
38 module_param(clockspeed, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
39 MODULE_PARM_DESC(clockspeed, "Hosts clock speed in MHz");
41 module_param(raw_tp_mode, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
42 MODULE_PARM_DESC(raw_tp_mode, "Mode choosed to test raw throughput");
44 static void deinit_adapter(void);
47 struct multicast_list mcast_list = {0};
48 struct esp_adapter adapter;
49 /*struct esp_device esp_dev;*/
51 struct esp_adapter *esp_get_adapter(void)
56 void esp_process_new_packet_intr(struct esp_adapter *adapter)
59 queue_work(adapter->if_rx_workqueue, &adapter->if_rx_work);
62 static int process_tx_packet(struct sk_buff *skb)
64 struct esp_wifi_device *priv = NULL;
65 struct esp_skb_cb *cb = NULL;
66 struct esp_payload_header *payload_header = NULL;
67 struct sk_buff *new_skb = NULL;
69 u8 pad_len = 0, realloc_skb = 0;
77 cb = (struct esp_skb_cb *) skb->cb;
82 esp_info("No priv\n");
86 if (netif_queue_stopped((const struct net_device *) priv->ndev)) {
87 esp_info("Netif queue stopped\n");
88 return NETDEV_TX_BUSY;
92 return NETDEV_TX_BUSY;
97 /* Create space for payload header */
98 pad_len = sizeof(struct esp_payload_header);
100 total_len = len + pad_len;
102 /* Align buffer length */
103 pad_len += SKB_DATA_ADDR_ALIGNMENT - (total_len % SKB_DATA_ADDR_ALIGNMENT);
105 if (skb_headroom(skb) < pad_len) {
106 /* Headroom is not sufficient */
110 if (realloc_skb || !IS_ALIGNED((unsigned long) skb->data, SKB_DATA_ADDR_ALIGNMENT)) {
112 if (skb_linearize(skb)) {
113 priv->stats.tx_errors++;
115 esp_err("Failed to linearize SKB");
119 new_skb = esp_alloc_skb(skb->len + pad_len);
122 esp_err("Failed to allocate SKB");
123 priv->stats.tx_errors++;
131 /* Populate new SKB */
132 skb_copy_from_linear_data(skb, pos, skb->len);
133 skb_put(new_skb, skb->len + pad_len);
135 /* Replace old SKB */
136 dev_kfree_skb_any(skb);
139 /* Realloc is not needed, Make space for interface header */
140 skb_push(skb, pad_len);
143 /* Set payload header */
144 payload_header = (struct esp_payload_header *) skb->data;
145 memset(payload_header, 0, pad_len);
147 payload_header->if_type = priv->if_type;
148 payload_header->if_num = priv->if_num;
149 payload_header->len = cpu_to_le16(len);
150 payload_header->offset = cpu_to_le16(pad_len);
151 payload_header->packet_type = PACKET_TYPE_DATA;
153 if (adapter.capabilities & ESP_CHECKSUM_ENABLED)
154 payload_header->checksum = cpu_to_le16(compute_checksum(skb->data, (len + pad_len)));
156 if (!priv->stop_data) {
157 ret = esp_send_packet(priv->adapter, skb);
160 esp_verbose("Failed to send SKB");
161 priv->stats.tx_errors++;
163 priv->stats.tx_packets++;
164 priv->stats.tx_bytes += skb->len;
167 dev_kfree_skb_any(skb);
168 priv->stats.tx_dropped++;
174 void esp_port_open(struct esp_wifi_device *priv)
180 void esp_port_close(struct esp_wifi_device *priv)
189 void print_capabilities(u32 cap)
191 esp_info("Capabilities: 0x%x. Features supported are:\n", cap);
192 if (cap & ESP_WLAN_SDIO_SUPPORT)
193 esp_info("\t * WLAN on SDIO\n");
194 else if (cap & ESP_WLAN_SPI_SUPPORT)
195 esp_info("\t * WLAN on SPI\n");
197 if ((cap & ESP_BT_UART_SUPPORT) ||
198 (cap & ESP_BT_SDIO_SUPPORT) ||
199 (cap & ESP_BT_SPI_SUPPORT)) {
200 esp_info("\t * BT/BLE\n");
201 if (cap & ESP_BT_UART_SUPPORT)
202 esp_info("\t - HCI over UART\n");
203 if (cap & ESP_BT_SDIO_SUPPORT)
204 esp_info("\t - HCI over SDIO\n");
205 if (cap & ESP_BT_SPI_SUPPORT)
206 esp_info("\t - HCI over SPI\n");
208 if ((cap & ESP_BLE_ONLY_SUPPORT) && (cap & ESP_BR_EDR_ONLY_SUPPORT))
209 esp_info("\t - BT/BLE dual mode\n");
210 else if (cap & ESP_BLE_ONLY_SUPPORT)
211 esp_info("\t - BLE only\n");
212 else if (cap & ESP_BR_EDR_ONLY_SUPPORT)
213 esp_info("\t - BR EDR only\n");
217 void init_bt(struct esp_adapter *adapter)
220 if ((adapter->capabilities & ESP_BT_SPI_SUPPORT) ||
221 (adapter->capabilities & ESP_BT_SDIO_SUPPORT)) {
223 esp_info("ESP Bluetooth init\n");
224 esp_init_bt(adapter);
228 static int check_esp_version(struct fw_version *ver)
230 esp_info("ESP Firmware version: %u.%u.%u\n",
231 ver->major1, ver->major2, ver->minor);
233 esp_err("Incompatible ESP firmware release detected, Please use correct ESP-Hosted branch/compatible release\n");
239 static void print_reset_reason(uint32_t reason)
243 case 1: esp_info("POWERON_RESET\n"); break; /**<1, Vbat power on reset*/
244 case 3: esp_info("SW_RESET\n"); break; /**<3, Software reset digital core*/
245 case 4: esp_info("OWDT_RESET\n"); break; /**<4, Legacy watch dog reset digital core*/
246 case 5: esp_info("DEEPSLEEP_RESET\n"); break; /**<5, Deep Sleep reset digital core*/
247 case 6: esp_info("SDIO_RESET\n"); break; /**<6, Reset by SLC module, reset digital core*/
248 case 7: esp_info("TG0WDT_SYS_RESET\n"); break; /**<7, Timer Group0 Watch dog reset digital core*/
249 case 8: esp_info("TG1WDT_SYS_RESET\n"); break; /**<8, Timer Group1 Watch dog reset digital core*/
250 case 9: esp_info("RTCWDT_SYS_RESET\n"); break; /**<9, RTC Watch dog Reset digital core*/
251 case 10: esp_info("INTRUSION_RESET\n"); break; /**<10, Instrusion tested to reset CPU*/
252 case 11: esp_info("TGWDT_CPU_RESET\n"); break; /**<11, Time Group reset CPU*/
253 case 12: esp_info("SW_CPU_RESET\n"); break; /**<12, Software reset CPU*/
254 case 13: esp_info("RTCWDT_CPU_RESET\n"); break; /**<13, RTC Watch dog Reset CPU*/
255 case 14: esp_info("EXT_CPU_RESET\n"); break; /**<14, for APP CPU, reseted by PRO CPU*/
256 case 15: esp_info("RTCWDT_BROWN_OUT_RESET\n"); break;/**<15, Reset when the vdd voltage is not stable*/
257 case 16: esp_info("RTCWDT_RTC_RESET\n"); break; /**<16, RTC Watch dog reset digital core and rtc module*/
258 default: esp_info("Unknown[%u]\n", reason); break;
262 static int process_fw_data(struct fw_data *fw_p, int tag_len)
264 if (tag_len != sizeof(struct fw_data)) {
265 esp_err("Length not matching to firmware data size\n");
269 esp_info("ESP chipset's last reset cause:\n");
270 print_reset_reason(le32_to_cpu(fw_p->last_reset_reason));
272 return check_esp_version(&fw_p->version);
275 int process_event_esp_bootup(struct esp_adapter *adapter, u8 *evt_buf, u8 len)
277 int len_left = len, tag_len, ret = 0;
280 if (!adapter || !evt_buf)
283 if (len_left >= 64) {
284 esp_info("ESP init event len looks unexpected: %u (>=64)\n", len_left);
285 esp_info("You probably facing timing mismatch at transport layer\n");
288 clear_bit(ESP_INIT_DONE, &adapter->state_flags);
289 /* Deinit module if already initialized */
290 esp_deinit_module(adapter);
294 while (len_left > 0) {
295 tag_len = *(pos + 1);
297 esp_info("Bootup Event tag: %d\n", *pos);
300 case ESP_BOOTUP_CAPABILITY:
301 adapter->capabilities = *(pos + 2);
303 case ESP_BOOTUP_FIRMWARE_CHIP_ID:
304 ret = esp_validate_chipset(adapter, *(pos + 2));
306 case ESP_BOOTUP_FW_DATA:
307 ret = process_fw_data((struct fw_data *)(pos + 2), tag_len);
309 case ESP_BOOTUP_SPI_CLK_MHZ:
310 ret = esp_adjust_spi_clock(adapter, *(pos + 2));
313 esp_warn("Unsupported tag=%x in bootup event\n", *pos);
317 esp_err("failed to process tag=%x in bootup event\n", *pos);
320 pos += (tag_len + 2);
321 len_left -= (tag_len + 2);
324 if (esp_add_card(adapter)) {
325 esp_err("network iterface init failed\n");
330 if (raw_tp_mode !=0) {
332 process_test_capabilities(raw_tp_mode);
333 esp_init_raw_tp(adapter);
335 esp_err("RAW TP mode selected but not enabled\n");
339 set_bit(ESP_INIT_DONE, &adapter->state_flags);
340 print_capabilities(adapter->capabilities);
345 static int esp_open(struct net_device *ndev)
350 static int esp_stop(struct net_device *ndev)
355 static struct net_device_stats *esp_get_stats(struct net_device *ndev)
357 struct esp_wifi_device *priv = netdev_priv(ndev);
365 static int esp_set_mac_address(struct net_device *ndev, void *data)
367 struct esp_wifi_device *priv = netdev_priv(ndev);
368 struct sockaddr *sa = (struct sockaddr *)data;
371 if (!priv || !priv->adapter)
374 esp_info("%u "MACSTR"\n", __LINE__, MAC2STR(sa->sa_data));
376 ret = cmd_set_mac(priv, sa->sa_data);
379 eth_hw_addr_set(ndev, priv->mac_address/*mac_addr->sa_data*/);
384 static void esp_set_rx_mode(struct net_device *ndev)
386 struct esp_adapter *adapter = esp_get_adapter();
388 schedule_work(&adapter->mac_flter_work);
391 static int esp_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
393 struct esp_wifi_device *priv = NULL;
394 struct esp_skb_cb *cb = NULL;
399 priv = netdev_priv(ndev);
405 if (!priv->port_open) {
406 priv->stats.tx_dropped++;
407 esp_verbose("Port not yet open\n");
412 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
413 esp_err("Bad len %d\n", skb->len);
414 priv->stats.tx_dropped++;
419 cb = (struct esp_skb_cb *) skb->cb;
422 return process_tx_packet(skb);
425 static const struct net_device_ops esp_netdev_ops = {
426 .ndo_open = esp_open,
427 .ndo_stop = esp_stop,
428 .ndo_start_xmit = esp_hard_start_xmit,
429 .ndo_set_mac_address = esp_set_mac_address,
430 .ndo_validate_addr = eth_validate_addr,
431 .ndo_get_stats = esp_get_stats,
432 .ndo_set_rx_mode = esp_set_rx_mode,
436 void esp_init_priv(struct net_device *ndev)
438 ndev->netdev_ops = &esp_netdev_ops;
439 ndev->needed_headroom = roundup(sizeof(struct esp_payload_header) +
440 INTERFACE_HEADER_PADDING, 4);
443 static int esp_add_network_ifaces(struct esp_adapter *adapter)
445 struct wireless_dev *wdev = NULL;
448 esp_info("adapter not yet init\n");
453 wdev = esp_cfg80211_add_iface(adapter->wiphy, "wlan%d", 1, NL80211_IFTYPE_STATION, NULL);
456 /* Return success if network added successfully */
463 int esp_init_raw_tp(struct esp_adapter *adapter)
465 RET_ON_FAIL(cmd_init_raw_tp_task_timer(adapter->priv[ESP_STA_NW_IF]));
469 int esp_add_card(struct esp_adapter *adapter)
471 RET_ON_FAIL(esp_commands_setup(adapter));
472 RET_ON_FAIL(esp_add_wiphy(adapter));
473 RET_ON_FAIL(esp_add_network_ifaces(adapter));
474 clear_bit(ESP_CLEANUP_IN_PROGRESS, &adapter->state_flags);
479 static int esp_remove_network_ifaces(struct esp_adapter *adapter)
481 uint8_t iface_idx = 0;
482 struct net_device *ndev = NULL;
483 struct esp_wifi_device *priv = NULL;
485 for (iface_idx = 0; iface_idx < ESP_MAX_INTERFACE; iface_idx++) {
487 priv = adapter->priv[iface_idx];
490 if (!test_bit(ESP_NETWORK_UP, &priv->priv_flags))
494 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
496 ndev->needs_free_netdev = true;
498 wiphy_lock(adapter->wiphy);
499 cfg80211_unregister_wdev(&priv->wdev);
500 wiphy_unlock(adapter->wiphy);
503 if (ndev && ndev->reg_state == NETREG_REGISTERED) {
504 unregister_netdev(ndev);
509 adapter->priv[iface_idx] = NULL;
515 static int stop_network_iface(struct esp_wifi_device *priv)
517 struct net_device *ndev;
522 if (!test_bit(ESP_NETWORK_UP, &priv->priv_flags))
525 esp_mark_scan_done_and_disconnect(priv, false);
526 esp_port_close(priv);
528 /* stop and unregister network */
532 netif_carrier_off(ndev);
533 netif_device_detach(ndev);
535 unregister_inetaddr_notifier(&(priv->nb));
541 int esp_stop_network_ifaces(struct esp_adapter *adapter)
543 uint8_t iface_idx = 0;
545 for (iface_idx = 0; iface_idx < ESP_MAX_INTERFACE; iface_idx++) {
546 stop_network_iface(adapter->priv[iface_idx]);
551 cfg80211_shutdown_all_interfaces(adapter->wiphy);
558 int esp_remove_card(struct esp_adapter *adapter)
564 esp_stop_network_ifaces(adapter);
565 esp_cfg_cleanup(adapter);
566 /* BT may have been initialized after fw bootup event, deinit it */
567 esp_deinit_bt(adapter);
568 esp_commands_teardown(adapter);
569 esp_remove_network_ifaces(adapter);
570 esp_remove_wiphy(adapter);
575 struct esp_wifi_device *get_priv_from_payload_header(
576 struct esp_payload_header *header)
578 struct esp_wifi_device *priv = NULL;
584 for (i = 0; i < ESP_MAX_INTERFACE; i++) {
585 priv = adapter.priv[i];
590 if (priv->if_type == header->if_type &&
591 priv->if_num == header->if_num) {
598 static void process_esp_bootup_event(struct esp_adapter *adapter,
599 struct esp_internal_bootup_event *evt)
601 if (!adapter || !evt) {
602 esp_err("Invalid arguments\n");
606 if (evt->header.status) {
607 esp_err("Incorrect ESP bootup event\n");
611 esp_info("Received ESP bootup event\n");
612 process_event_esp_bootup(adapter, evt->data, evt->len);
615 static int process_internal_event(struct esp_adapter *adapter,
618 struct event_header *header = NULL;
620 if (!skb || !adapter) {
621 esp_err("Incorrect event data!\n");
625 header = (struct event_header *) (skb->data);
627 switch (header->event_code) {
629 case ESP_INTERNAL_BOOTUP_EVENT:
630 process_esp_bootup_event(adapter,
631 (struct esp_internal_bootup_event *)(skb->data));
635 esp_info("%u unhandled internal event[%u]\n",
636 __LINE__, header->event_code);
643 static void process_rx_packet(struct esp_adapter *adapter, struct sk_buff *skb)
645 struct esp_wifi_device *priv = NULL;
646 struct esp_payload_header *payload_header = NULL;
647 u16 len = 0, offset = 0;
648 u16 rx_checksum = 0, checksum = 0;
649 struct hci_dev *hdev = adapter->hcidev;
655 /* get the paload header */
656 payload_header = (struct esp_payload_header *) skb->data;
658 len = le16_to_cpu(payload_header->len);
659 offset = le16_to_cpu(payload_header->offset);
661 if (payload_header->reserved2 == 0xFF) {
662 esp_hex_dump("Wake up packet: ", skb->data, len+offset);
665 if (adapter->capabilities & ESP_CHECKSUM_ENABLED) {
666 rx_checksum = le16_to_cpu(payload_header->checksum);
667 payload_header->checksum = 0;
669 checksum = compute_checksum(skb->data, (len + offset));
671 if (checksum != rx_checksum) {
672 dev_kfree_skb_any(skb);
677 /* chop off the header from skb */
678 skb_pull(skb, offset);
680 if (payload_header->if_type == ESP_STA_IF || payload_header->if_type == ESP_AP_IF) {
682 /* retrieve priv based on payload header contents */
683 priv = get_priv_from_payload_header(payload_header);
686 esp_err("Empty priv\n");
687 dev_kfree_skb_any(skb);
691 if (payload_header->packet_type == PACKET_TYPE_EAPOL) {
692 esp_dbg("Rx PACKET_TYPE_EAPOL!!!!\n");
694 skb->dev = priv->ndev;
695 skb->protocol = eth_type_trans(skb, priv->ndev);
698 } else if (payload_header->packet_type == PACKET_TYPE_DATA) {
700 skb->dev = priv->ndev;
701 skb->protocol = eth_type_trans(skb, priv->ndev);
702 skb->ip_summed = CHECKSUM_NONE;
704 priv->stats.rx_bytes += skb->len;
705 /* Forward skb to kernel */
707 priv->stats.rx_packets++;
708 } else if (payload_header->packet_type == PACKET_TYPE_COMMAND_RESPONSE) {
709 process_cmd_resp(priv->adapter, skb);
710 } else if (payload_header->packet_type == PACKET_TYPE_EVENT) {
711 process_cmd_event(priv, skb);
712 dev_kfree_skb_any(skb);
715 } else if (payload_header->if_type == ESP_HCI_IF) {
719 hci_skb_pkt_type(skb) = *type;
722 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
723 if (hci_recv_frame(hdev, skb)) {
725 if (hci_recv_frame(skb)) {
729 esp_hci_update_rx_counter(hdev, *type, skb->len);
732 } else if (payload_header->if_type == ESP_INTERNAL_IF) {
734 /* Queue event skb for processing in events workqueue */
735 skb_queue_tail(&adapter->events_skb_q, skb);
737 if (adapter->events_wq)
738 queue_work(adapter->events_wq, &adapter->events_work);
740 dev_kfree_skb_any(skb);
742 } else if (payload_header->if_type == ESP_TEST_IF) {
744 if (raw_tp_mode != 0) {
745 update_test_raw_tp_rx_stats(len);
748 dev_kfree_skb_any(skb);
750 dev_kfree_skb_any(skb);
754 char *esp_get_hardware_name(int hardware_id)
756 if(hardware_id == ESP_FIRMWARE_CHIP_ESP32)
758 else if(hardware_id == ESP_FIRMWARE_CHIP_ESP32S2)
760 else if(hardware_id == ESP_FIRMWARE_CHIP_ESP32C3)
762 else if(hardware_id == ESP_FIRMWARE_CHIP_ESP32S3)
764 else if(hardware_id == ESP_FIRMWARE_CHIP_ESP32C2)
766 else if(hardware_id == ESP_FIRMWARE_CHIP_ESP32C6)
772 bool esp_is_valid_hardware_id(int hardware_id)
774 switch(hardware_id) {
775 case ESP_FIRMWARE_CHIP_ESP32:
776 case ESP_FIRMWARE_CHIP_ESP32S2:
777 case ESP_FIRMWARE_CHIP_ESP32C3:
778 case ESP_FIRMWARE_CHIP_ESP32S3:
779 case ESP_FIRMWARE_CHIP_ESP32C2:
780 case ESP_FIRMWARE_CHIP_ESP32C6:
787 int esp_is_tx_queue_paused(struct esp_wifi_device *priv)
789 if (!priv || !priv->ndev)
793 !netif_queue_stopped((const struct net_device *)priv->ndev)))
798 void esp_tx_pause(struct esp_wifi_device *priv)
800 if (!priv || !priv->ndev)
803 if (!netif_queue_stopped((const struct net_device *)priv->ndev)) {
804 netif_stop_queue(priv->ndev);
808 void esp_tx_resume(struct esp_wifi_device *priv)
810 if (!priv || !priv->ndev)
813 if (netif_queue_stopped((const struct net_device *)priv->ndev)) {
814 netif_wake_queue(priv->ndev);
818 struct sk_buff *esp_alloc_skb(u32 len)
820 struct sk_buff *skb = NULL;
824 skb = netdev_alloc_skb(NULL, len + INTERFACE_HEADER_PADDING);
827 /* Align SKB data pointer */
828 offset = ((unsigned long)skb->data) & (SKB_DATA_ADDR_ALIGNMENT - 1);
831 skb_reserve(skb, INTERFACE_HEADER_PADDING - offset);
838 static int esp_get_packets(struct esp_adapter *adapter)
840 struct sk_buff *skb = NULL;
842 if (!adapter || !adapter->if_ops || !adapter->if_ops->read)
845 skb = adapter->if_ops->read(adapter);
850 process_rx_packet(adapter, skb);
855 int esp_send_packet(struct esp_adapter *adapter, struct sk_buff *skb)
857 if (!adapter || !adapter->if_ops || !adapter->if_ops->write) {
858 esp_err("%u adapter: %p\n", __LINE__, adapter);
862 return adapter->if_ops->write(adapter, skb);
865 static void esp_if_rx_work(struct work_struct *work)
867 /* read inbound packet and forward it to network/serial interface */
868 esp_get_packets(&adapter);
871 static void update_mac_filter(struct work_struct *work)
873 struct esp_adapter *adapter = esp_get_adapter();
874 struct esp_wifi_device *priv = adapter->priv[0];
875 struct net_device *ndev;
876 struct netdev_hw_addr *mac_addr;
886 if (!priv->port_open) {
887 esp_verbose("Port is not open yet, skipping mac filter update\n");
891 #if CONFIG_ALLOW_MULTICAST_WAKEUP
892 netdev_for_each_mc_addr(mac_addr, ndev) {
893 if (count < MAX_MULTICAST_ADDR_COUNT) {
894 esp_verbose("%d: "MACSTR"\n", count+1, MAC2STR(mac_addr->addr));
895 memcpy(&mcast_list.mcast_addr[count++], mac_addr->addr, ETH_ALEN);
899 mcast_list.priv = priv;
900 mcast_list.addr_count = count;
902 esp_verbose("Setting Multicast list\n");
903 cmd_set_mcast_mac_list(mcast_list.priv, &mcast_list);
905 esp_info("Not setting FW multicast addresses\n");
909 static void esp_events_work(struct work_struct *work)
911 struct sk_buff *skb = NULL;
913 skb = skb_dequeue(&adapter.events_skb_q);
917 process_internal_event(&adapter, skb);
918 dev_kfree_skb_any(skb);
921 static struct esp_adapter *init_adapter(void)
923 memset(&adapter, 0, sizeof(adapter));
925 /* Prepare interface RX work */
926 adapter.if_rx_workqueue = alloc_workqueue("ESP_IF_RX_WORK_QUEUE", 0, 0);
928 if (!adapter.if_rx_workqueue) {
933 INIT_WORK(&adapter.if_rx_work, esp_if_rx_work);
935 skb_queue_head_init(&adapter.events_skb_q);
937 adapter.events_wq = alloc_workqueue("ESP_EVENTS_WORKQUEUE", WQ_HIGHPRI, 0);
939 if (!adapter.events_wq) {
944 INIT_WORK(&adapter.events_work, esp_events_work);
946 INIT_WORK(&adapter.mac_flter_work, update_mac_filter);
951 static void deinit_adapter(void)
953 skb_queue_purge(&adapter.events_skb_q);
955 if (adapter.events_wq)
956 destroy_workqueue(adapter.events_wq);
958 if (adapter.if_rx_workqueue)
959 destroy_workqueue(adapter.if_rx_workqueue);
962 static void esp_reset(void)
964 if (resetpin != HOST_GPIO_PIN_INVALID) {
965 /* Check valid GPIO or not */
966 if (!gpio_is_valid(resetpin)) {
967 esp_warn("host resetpin (%d) configured is invalid GPIO\n", resetpin);
968 resetpin = HOST_GPIO_PIN_INVALID;
970 gpio_request(resetpin, "sysfs");
972 /* HOST's resetpin set to OUTPUT, HIGH */
973 gpio_direction_output(resetpin, true);
975 /* HOST's resetpin set to LOW */
976 gpio_set_value(resetpin, 0);
979 /* HOST's resetpin set to INPUT */
980 gpio_direction_input(resetpin);
982 esp_dbg("Triggering ESP reset.\n");
987 static int __init esp_init(void)
990 struct esp_adapter *adapter = NULL;
992 /* Reset ESP, Clean start ESP */
996 adapter = init_adapter();
1001 /* Init transport layer */
1002 ret = esp_init_interface_layer(adapter, clockspeed);
1008 ret = debugfs_init();
1012 static void __exit esp_exit(void)
1014 uint8_t iface_idx = 0;
1016 if (raw_tp_mode != 0) {
1017 test_raw_tp_cleanup();
1020 for (iface_idx = 0; iface_idx < ESP_MAX_INTERFACE; iface_idx++) {
1021 cmd_deinit_interface(adapter.priv[iface_idx]);
1023 clear_bit(ESP_DRIVER_ACTIVE, &adapter.state_flags);
1025 esp_deinit_interface_layer();
1028 if (resetpin != HOST_GPIO_PIN_INVALID) {
1029 gpio_free(resetpin);
1033 MODULE_LICENSE("GPL");
1038 MODULE_DESCRIPTION("Wifi driver for ESP-Hosted solution");
1039 MODULE_VERSION(RELEASE_VERSION);
1040 module_init(esp_init);
1041 module_exit(esp_exit);