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 static int resetpin = HOST_GPIO_PIN_INVALID;
28 static u32 clockspeed = 0;
29 extern u8 ap_bssid[MAC_ADDR_LEN];
30 extern volatile u8 host_sleep;
32 module_param(resetpin, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
33 MODULE_PARM_DESC(resetpin, "Host's GPIO pin number which is connected to ESP32's EN to reset ESP32 device");
35 module_param(clockspeed, uint, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
36 MODULE_PARM_DESC(clockspeed, "Hosts clock speed in MHz");
38 static void deinit_adapter(void);
41 struct multicast_list mcast_list = {0};
42 struct esp_adapter adapter;
43 /*struct esp_device esp_dev;*/
45 struct esp_adapter *esp_get_adapter(void)
50 void esp_process_new_packet_intr(struct esp_adapter *adapter)
53 queue_work(adapter->if_rx_workqueue, &adapter->if_rx_work);
56 static int process_tx_packet(struct sk_buff *skb)
58 struct esp_wifi_device *priv = NULL;
59 struct esp_skb_cb *cb = NULL;
60 struct esp_payload_header *payload_header = NULL;
61 struct sk_buff *new_skb = NULL;
63 u8 pad_len = 0, realloc_skb = 0;
71 cb = (struct esp_skb_cb *) skb->cb;
76 esp_info("No priv\n");
80 if (netif_queue_stopped((const struct net_device *) priv->ndev)) {
81 esp_info("Netif queue stopped\n");
82 return NETDEV_TX_BUSY;
86 return NETDEV_TX_BUSY;
91 /* Create space for payload header */
92 pad_len = sizeof(struct esp_payload_header);
94 total_len = len + pad_len;
96 /* Align buffer length */
97 pad_len += SKB_DATA_ADDR_ALIGNMENT - (total_len % SKB_DATA_ADDR_ALIGNMENT);
99 if (skb_headroom(skb) < pad_len) {
100 /* Headroom is not sufficient */
104 if (realloc_skb || !IS_ALIGNED((unsigned long) skb->data, SKB_DATA_ADDR_ALIGNMENT)) {
106 if (skb_linearize(skb)) {
107 priv->stats.tx_errors++;
109 esp_err("Failed to linearize SKB");
113 new_skb = esp_alloc_skb(skb->len + pad_len);
116 esp_err("Failed to allocate SKB");
117 priv->stats.tx_errors++;
125 /* Populate new SKB */
126 skb_copy_from_linear_data(skb, pos, skb->len);
127 skb_put(new_skb, skb->len + pad_len);
129 /* Replace old SKB */
130 dev_kfree_skb_any(skb);
133 /* Realloc is not needed, Make space for interface header */
134 skb_push(skb, pad_len);
137 /* Set payload header */
138 payload_header = (struct esp_payload_header *) skb->data;
139 memset(payload_header, 0, pad_len);
141 payload_header->if_type = priv->if_type;
142 payload_header->if_num = priv->if_num;
143 payload_header->len = cpu_to_le16(len);
144 payload_header->offset = cpu_to_le16(pad_len);
145 payload_header->packet_type = PACKET_TYPE_DATA;
147 if (adapter.capabilities & ESP_CHECKSUM_ENABLED)
148 payload_header->checksum = cpu_to_le16(compute_checksum(skb->data, (len + pad_len)));
150 if (!priv->stop_data) {
151 ret = esp_send_packet(priv->adapter, skb);
154 /* esp_err("Failed to send SKB");*/
155 priv->stats.tx_errors++;
157 priv->stats.tx_packets++;
158 priv->stats.tx_bytes += skb->len;
161 dev_kfree_skb_any(skb);
162 priv->stats.tx_dropped++;
168 void esp_port_open(struct esp_wifi_device *priv)
174 void esp_port_close(struct esp_wifi_device *priv)
183 void print_capabilities(u32 cap)
185 esp_info("Capabilities: 0x%x. Features supported are:\n", cap);
186 if (cap & ESP_WLAN_SDIO_SUPPORT)
187 esp_info("\t * WLAN on SDIO\n");
188 else if (cap & ESP_WLAN_SPI_SUPPORT)
189 esp_info("\t * WLAN on SPI\n");
191 if ((cap & ESP_BT_UART_SUPPORT) ||
192 (cap & ESP_BT_SDIO_SUPPORT) ||
193 (cap & ESP_BT_SPI_SUPPORT)) {
194 esp_info("\t * BT/BLE\n");
195 if (cap & ESP_BT_UART_SUPPORT)
196 esp_info("\t - HCI over UART\n");
197 if (cap & ESP_BT_SDIO_SUPPORT)
198 esp_info("\t - HCI over SDIO\n");
199 if (cap & ESP_BT_SPI_SUPPORT)
200 esp_info("\t - HCI over SPI\n");
202 if ((cap & ESP_BLE_ONLY_SUPPORT) && (cap & ESP_BR_EDR_ONLY_SUPPORT))
203 esp_info("\t - BT/BLE dual mode\n");
204 else if (cap & ESP_BLE_ONLY_SUPPORT)
205 esp_info("\t - BLE only\n");
206 else if (cap & ESP_BR_EDR_ONLY_SUPPORT)
207 esp_info("\t - BR EDR only\n");
211 void init_bt(struct esp_adapter *adapter)
214 if ((adapter->capabilities & ESP_BT_SPI_SUPPORT) ||
215 (adapter->capabilities & ESP_BT_SDIO_SUPPORT)) {
217 esp_info("ESP Bluetooth init\n");
218 esp_init_bt(adapter);
222 static int check_esp_version(struct fw_version *ver)
224 esp_info("ESP Firmware version: %u.%u.%u\n",
225 ver->major1, ver->major2, ver->minor);
227 esp_err("Incompatible ESP firmware release detected, Please use correct ESP-Hosted branch/compatible release\n");
233 static void print_reset_reason(uint32_t reason)
237 case 1: esp_info("POWERON_RESET\n"); break; /**<1, Vbat power on reset*/
238 case 3: esp_info("SW_RESET\n"); break; /**<3, Software reset digital core*/
239 case 4: esp_info("OWDT_RESET\n"); break; /**<4, Legacy watch dog reset digital core*/
240 case 5: esp_info("DEEPSLEEP_RESET\n"); break; /**<5, Deep Sleep reset digital core*/
241 case 6: esp_info("SDIO_RESET\n"); break; /**<6, Reset by SLC module, reset digital core*/
242 case 7: esp_info("TG0WDT_SYS_RESET\n"); break; /**<7, Timer Group0 Watch dog reset digital core*/
243 case 8: esp_info("TG1WDT_SYS_RESET\n"); break; /**<8, Timer Group1 Watch dog reset digital core*/
244 case 9: esp_info("RTCWDT_SYS_RESET\n"); break; /**<9, RTC Watch dog Reset digital core*/
245 case 10: esp_info("INTRUSION_RESET\n"); break; /**<10, Instrusion tested to reset CPU*/
246 case 11: esp_info("TGWDT_CPU_RESET\n"); break; /**<11, Time Group reset CPU*/
247 case 12: esp_info("SW_CPU_RESET\n"); break; /**<12, Software reset CPU*/
248 case 13: esp_info("RTCWDT_CPU_RESET\n"); break; /**<13, RTC Watch dog Reset CPU*/
249 case 14: esp_info("EXT_CPU_RESET\n"); break; /**<14, for APP CPU, reseted by PRO CPU*/
250 case 15: esp_info("RTCWDT_BROWN_OUT_RESET\n"); break;/**<15, Reset when the vdd voltage is not stable*/
251 case 16: esp_info("RTCWDT_RTC_RESET\n"); break; /**<16, RTC Watch dog reset digital core and rtc module*/
252 default: esp_info("Unknown[%u]\n", reason); break;
256 static int process_fw_data(struct fw_data *fw_p, int tag_len)
258 if (tag_len != sizeof(struct fw_data)) {
259 esp_err("Length not matching to firmware data size\n");
263 esp_info("ESP chipset's last reset cause:\n");
264 print_reset_reason(le32_to_cpu(fw_p->last_reset_reason));
266 return check_esp_version(&fw_p->version);
269 int process_event_esp_bootup(struct esp_adapter *adapter, u8 *evt_buf, u8 len)
271 int len_left = len, tag_len, ret = 0;
274 if (!adapter || !evt_buf)
277 if (len_left >= 64) {
278 esp_info("ESP init event len looks unexpected: %u (>=64)\n", len_left);
279 esp_info("You probably facing timing mismatch at transport layer\n");
282 clear_bit(ESP_INIT_DONE, &adapter->state_flags);
283 /* Deinit module if already initialized */
284 esp_deinit_module(adapter);
288 while (len_left > 0) {
289 tag_len = *(pos + 1);
291 esp_info("Bootup Event tag: %d\n", *pos);
294 case ESP_BOOTUP_CAPABILITY:
295 adapter->capabilities = *(pos + 2);
297 case ESP_BOOTUP_FIRMWARE_CHIP_ID:
298 ret = esp_validate_chipset(adapter, *(pos + 2));
300 case ESP_BOOTUP_FW_DATA:
301 ret = process_fw_data((struct fw_data *)(pos + 2), tag_len);
303 case ESP_BOOTUP_SPI_CLK_MHZ:
304 ret = esp_adjust_spi_clock(adapter, *(pos + 2));
307 esp_warn("Unsupported tag=%x in bootup event\n", *pos);
311 esp_err("failed to process tag=%x in bootup event\n", *pos);
314 pos += (tag_len + 2);
315 len_left -= (tag_len + 2);
318 if (esp_add_card(adapter)) {
319 esp_err("network iterface init failed\n");
323 set_bit(ESP_INIT_DONE, &adapter->state_flags);
324 print_capabilities(adapter->capabilities);
329 static int esp_open(struct net_device *ndev)
334 static int esp_stop(struct net_device *ndev)
339 static struct net_device_stats *esp_get_stats(struct net_device *ndev)
341 struct esp_wifi_device *priv = netdev_priv(ndev);
349 static int esp_set_mac_address(struct net_device *ndev, void *data)
351 struct esp_wifi_device *priv = netdev_priv(ndev);
352 struct sockaddr *sa = (struct sockaddr *)data;
355 if (!priv || !priv->adapter)
358 esp_info("%u "MACSTR"\n", __LINE__, MAC2STR(sa->sa_data));
360 ret = cmd_set_mac(priv, sa->sa_data);
363 eth_hw_addr_set(ndev, priv->mac_address/*mac_addr->sa_data*/);
368 static void esp_set_rx_mode(struct net_device *ndev)
370 struct esp_wifi_device *priv = netdev_priv(ndev);
371 struct netdev_hw_addr *mac_addr;
374 struct in_device *in_dev = in_dev_get(ndev);
375 struct ip_mc_list *ip_list = in_dev->mc_list;
377 netdev_for_each_mc_addr(mac_addr, ndev) {
378 if (count < MAX_MULTICAST_ADDR_COUNT) {
379 /*esp_info("%d: "MACSTR"\n", count+1, MAC2STR(mac_addr->addr));*/
380 memcpy(&mcast_list.mcast_addr[count++], mac_addr->addr, ETH_ALEN);
384 mcast_list.priv = priv;
385 mcast_list.addr_count = count;
387 if (priv->port_open) {
388 /*esp_info("Set Multicast list\n");*/
389 if (adapter.mac_filter_wq)
390 queue_work(adapter.mac_filter_wq, &adapter.mac_flter_work);
393 cmd_set_mcast_mac_list(priv, &mcast_list);
395 esp_dbg(" IP MC Address: 0x%x\n", ip_list->multiaddr);
396 ip_list = ip_list->next;
402 static int esp_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
404 struct esp_wifi_device *priv = NULL;
405 struct esp_skb_cb *cb = NULL;
410 priv = netdev_priv(ndev);
416 if (!priv->port_open) {
417 priv->stats.tx_dropped++;
418 /*esp_err("Port not yet open\n");*/
423 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
424 esp_err("Bad len %d\n", skb->len);
425 priv->stats.tx_dropped++;
430 cb = (struct esp_skb_cb *) skb->cb;
433 return process_tx_packet(skb);
436 static const struct net_device_ops esp_netdev_ops = {
437 .ndo_open = esp_open,
438 .ndo_stop = esp_stop,
439 .ndo_start_xmit = esp_hard_start_xmit,
440 .ndo_set_mac_address = esp_set_mac_address,
441 .ndo_validate_addr = eth_validate_addr,
442 .ndo_get_stats = esp_get_stats,
443 .ndo_set_rx_mode = esp_set_rx_mode,
447 void esp_init_priv(struct net_device *ndev)
449 ndev->netdev_ops = &esp_netdev_ops;
450 ndev->needed_headroom = roundup(sizeof(struct esp_payload_header) +
451 INTERFACE_HEADER_PADDING, 4);
454 static int esp_add_network_ifaces(struct esp_adapter *adapter)
456 struct wireless_dev *wdev = NULL;
459 esp_info("adapter not yet init\n");
464 wdev = esp_cfg80211_add_iface(adapter->wiphy, "espsta%d", 1, NL80211_IFTYPE_STATION, NULL);
467 /* Return success if network added successfully */
474 int esp_add_card(struct esp_adapter *adapter)
476 RET_ON_FAIL(esp_commands_setup(adapter));
477 RET_ON_FAIL(esp_add_wiphy(adapter));
478 RET_ON_FAIL(esp_add_network_ifaces(adapter));
483 static int esp_remove_network_ifaces(struct esp_adapter *adapter)
485 uint8_t iface_idx = 0;
486 struct net_device *ndev = NULL;
487 struct esp_wifi_device *priv = NULL;
489 for (iface_idx = 0; iface_idx < ESP_MAX_INTERFACE; iface_idx++) {
491 priv = adapter->priv[iface_idx];
494 if (!test_bit(ESP_NETWORK_UP, &priv->priv_flags))
498 #if LINUX_VERSION_CODE >= KERNEL_VERSION(5, 12, 0)
500 ndev->needs_free_netdev = true;
502 wiphy_lock(adapter->wiphy);
503 cfg80211_unregister_wdev(&priv->wdev);
504 wiphy_unlock(adapter->wiphy);
507 if (ndev && ndev->reg_state == NETREG_REGISTERED) {
508 unregister_netdev(ndev);
513 adapter->priv[iface_idx] = NULL;
519 static int stop_network_iface(struct esp_wifi_device *priv)
521 struct net_device *ndev;
526 if (!test_bit(ESP_NETWORK_UP, &priv->priv_flags))
529 esp_mark_scan_done_and_disconnect(priv, false);
530 esp_port_close(priv);
532 /* stop and unregister network */
536 netif_carrier_off(ndev);
537 netif_device_detach(ndev);
539 unregister_inetaddr_notifier(&(priv->nb));
545 int esp_stop_network_ifaces(struct esp_adapter *adapter)
547 uint8_t iface_idx = 0;
549 for (iface_idx = 0; iface_idx < ESP_MAX_INTERFACE; iface_idx++) {
550 stop_network_iface(adapter->priv[iface_idx]);
555 cfg80211_shutdown_all_interfaces(adapter->wiphy);
562 int esp_remove_card(struct esp_adapter *adapter)
568 esp_stop_network_ifaces(adapter);
569 /* BT may have been initialized after fw bootup event, deinit it */
570 esp_deinit_bt(adapter);
571 esp_commands_teardown(adapter);
572 esp_remove_network_ifaces(adapter);
573 esp_remove_wiphy(adapter);
578 struct esp_wifi_device *get_priv_from_payload_header(
579 struct esp_payload_header *header)
581 struct esp_wifi_device *priv = NULL;
587 for (i = 0; i < ESP_MAX_INTERFACE; i++) {
588 priv = adapter.priv[i];
593 if (priv->if_type == header->if_type &&
594 priv->if_num == header->if_num) {
601 static void process_esp_bootup_event(struct esp_adapter *adapter,
602 struct esp_internal_bootup_event *evt)
604 if (!adapter || !evt) {
605 esp_err("Invalid arguments\n");
609 if (evt->header.status) {
610 esp_err("Incorrect ESP bootup event\n");
614 esp_info("Received ESP bootup event\n");
615 process_event_esp_bootup(adapter, evt->data, evt->len);
618 static int process_internal_event(struct esp_adapter *adapter,
621 struct event_header *header = NULL;
623 if (!skb || !adapter) {
624 esp_err("Incorrect event data!\n");
628 header = (struct event_header *) (skb->data);
630 switch (header->event_code) {
632 case ESP_INTERNAL_BOOTUP_EVENT:
633 process_esp_bootup_event(adapter,
634 (struct esp_internal_bootup_event *)(skb->data));
638 esp_info("%u unhandled internal event[%u]\n",
639 __LINE__, header->event_code);
646 static void process_rx_packet(struct esp_adapter *adapter, struct sk_buff *skb)
648 struct esp_wifi_device *priv = NULL;
649 struct esp_payload_header *payload_header = NULL;
650 u16 len = 0, offset = 0;
651 u16 rx_checksum = 0, checksum = 0;
652 struct hci_dev *hdev = adapter->hcidev;
654 struct sk_buff *eap_skb = NULL;
655 struct ethhdr *eth = NULL;
660 /* get the paload header */
661 payload_header = (struct esp_payload_header *) skb->data;
663 len = le16_to_cpu(payload_header->len);
664 offset = le16_to_cpu(payload_header->offset);
666 if (payload_header->reserved2 == 0xFF) {
667 print_hex_dump(KERN_INFO, "Wake up packet: ", DUMP_PREFIX_ADDRESS, 16, 1, skb->data, len+offset, 1);
670 if (adapter->capabilities & ESP_CHECKSUM_ENABLED) {
671 rx_checksum = le16_to_cpu(payload_header->checksum);
672 payload_header->checksum = 0;
674 checksum = compute_checksum(skb->data, (len + offset));
676 if (checksum != rx_checksum) {
677 dev_kfree_skb_any(skb);
682 /* chop off the header from skb */
683 skb_pull(skb, offset);
685 if (payload_header->if_type == ESP_STA_IF || payload_header->if_type == ESP_AP_IF) {
687 /* retrieve priv based on payload header contents */
688 priv = get_priv_from_payload_header(payload_header);
691 esp_err("Empty priv\n");
692 dev_kfree_skb_any(skb);
696 if (payload_header->packet_type == PACKET_TYPE_EAPOL) {
697 esp_info("Rx PACKET_TYPE_EAPOL!!!!\n");
700 eap_skb = alloc_skb(skb->len + ETH_HLEN, GFP_KERNEL);
702 esp_info("%u memory alloc failed\n", __LINE__);
705 eap_skb->dev = priv->ndev;
707 if (!IS_ALIGNED((unsigned long) eap_skb->data, SKB_DATA_ADDR_ALIGNMENT)) {
708 esp_info("%u eap skb unaligned\n", __LINE__);
711 eth = (struct ethhdr *) skb_put(eap_skb, ETH_HLEN);
712 ether_addr_copy(eth->h_dest, /*skb->data*/priv->ndev->dev_addr);
713 ether_addr_copy(eth->h_source, /*skb->data+6*/ ap_bssid);
714 eth->h_proto = cpu_to_be16(ETH_P_PAE);
716 skb_put_data(eap_skb, skb->data, skb->len);
717 eap_skb->protocol = eth_type_trans(eap_skb, eap_skb->dev);
721 } else if (payload_header->packet_type == PACKET_TYPE_DATA) {
723 skb->dev = priv->ndev;
724 skb->protocol = eth_type_trans(skb, priv->ndev);
725 skb->ip_summed = CHECKSUM_NONE;
727 priv->stats.rx_bytes += skb->len;
728 /* Forward skb to kernel */
730 priv->stats.rx_packets++;
731 } else if (payload_header->packet_type == PACKET_TYPE_COMMAND_RESPONSE) {
732 process_cmd_resp(priv->adapter, skb);
733 } else if (payload_header->packet_type == PACKET_TYPE_EVENT) {
734 process_cmd_event(priv, skb);
735 dev_kfree_skb_any(skb);
738 } else if (payload_header->if_type == ESP_HCI_IF) {
742 hci_skb_pkt_type(skb) = *type;
745 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
746 if (hci_recv_frame(hdev, skb)) {
748 if (hci_recv_frame(skb)) {
752 esp_hci_update_rx_counter(hdev, *type, skb->len);
755 } else if (payload_header->if_type == ESP_INTERNAL_IF) {
757 /* Queue event skb for processing in events workqueue */
758 skb_queue_tail(&adapter->events_skb_q, skb);
760 if (adapter->events_wq)
761 queue_work(adapter->events_wq, &adapter->events_work);
763 dev_kfree_skb_any(skb);
765 } else if (payload_header->if_type == ESP_TEST_IF) {
767 update_test_raw_tp_rx_stats(len);
769 dev_kfree_skb_any(skb);
771 dev_kfree_skb_any(skb);
775 int esp_is_tx_queue_paused(struct esp_wifi_device *priv)
777 if (!priv || !priv->ndev)
781 !netif_queue_stopped((const struct net_device *)priv->ndev)))
786 void esp_tx_pause(struct esp_wifi_device *priv)
788 if (!priv || !priv->ndev)
791 if (!netif_queue_stopped((const struct net_device *)priv->ndev)) {
792 netif_stop_queue(priv->ndev);
796 void esp_tx_resume(struct esp_wifi_device *priv)
798 if (!priv || !priv->ndev)
801 if (netif_queue_stopped((const struct net_device *)priv->ndev)) {
802 netif_wake_queue(priv->ndev);
806 struct sk_buff *esp_alloc_skb(u32 len)
808 struct sk_buff *skb = NULL;
812 skb = netdev_alloc_skb(NULL, len + INTERFACE_HEADER_PADDING);
815 /* Align SKB data pointer */
816 offset = ((unsigned long)skb->data) & (SKB_DATA_ADDR_ALIGNMENT - 1);
819 skb_reserve(skb, INTERFACE_HEADER_PADDING - offset);
826 static int esp_get_packets(struct esp_adapter *adapter)
828 struct sk_buff *skb = NULL;
830 if (!adapter || !adapter->if_ops || !adapter->if_ops->read)
833 skb = adapter->if_ops->read(adapter);
838 process_rx_packet(adapter, skb);
843 int esp_send_packet(struct esp_adapter *adapter, struct sk_buff *skb)
845 if (!adapter || !adapter->if_ops || !adapter->if_ops->write) {
846 esp_err("%u adapter: %p\n", __LINE__, adapter);
850 return adapter->if_ops->write(adapter, skb);
853 static void esp_if_rx_work(struct work_struct *work)
855 /* read inbound packet and forward it to network/serial interface */
856 esp_get_packets(&adapter);
859 static void update_mac_filter(struct work_struct *work)
861 cmd_set_mcast_mac_list(mcast_list.priv, &mcast_list);
864 static void esp_events_work(struct work_struct *work)
866 struct sk_buff *skb = NULL;
868 skb = skb_dequeue(&adapter.events_skb_q);
872 process_internal_event(&adapter, skb);
873 dev_kfree_skb_any(skb);
876 static struct esp_adapter *init_adapter(void)
878 memset(&adapter, 0, sizeof(adapter));
880 /* Prepare interface RX work */
881 adapter.if_rx_workqueue = alloc_workqueue("ESP_IF_RX_WORK_QUEUE", 0, 0);
883 if (!adapter.if_rx_workqueue) {
888 INIT_WORK(&adapter.if_rx_work, esp_if_rx_work);
890 skb_queue_head_init(&adapter.events_skb_q);
892 adapter.events_wq = alloc_workqueue("ESP_EVENTS_WORKQUEUE", WQ_HIGHPRI, 0);
894 if (!adapter.events_wq) {
899 INIT_WORK(&adapter.events_work, esp_events_work);
901 adapter.mac_filter_wq = alloc_workqueue("MAC_FILTER", 0, 0);
902 if (!adapter.mac_filter_wq) {
907 INIT_WORK(&adapter.mac_flter_work, update_mac_filter);
912 static void deinit_adapter(void)
914 skb_queue_purge(&adapter.events_skb_q);
916 if (adapter.events_wq)
917 destroy_workqueue(adapter.events_wq);
919 if (adapter.if_rx_workqueue)
920 destroy_workqueue(adapter.if_rx_workqueue);
922 if (adapter.mac_filter_wq)
923 destroy_workqueue(adapter.mac_filter_wq);
926 static void esp_reset(void)
928 if (resetpin != HOST_GPIO_PIN_INVALID) {
929 /* Check valid GPIO or not */
930 if (!gpio_is_valid(resetpin)) {
931 esp_warn("host resetpin (%d) configured is invalid GPIO\n", resetpin);
932 resetpin = HOST_GPIO_PIN_INVALID;
934 gpio_request(resetpin, "sysfs");
936 /* HOST's resetpin set to OUTPUT, HIGH */
937 gpio_direction_output(resetpin, true);
939 /* HOST's resetpin set to LOW */
940 gpio_set_value(resetpin, 0);
943 /* HOST's resetpin set to INPUT */
944 gpio_direction_input(resetpin);
946 esp_dbg("Triggering ESP reset.\n");
952 static int __init esp_init(void)
955 struct esp_adapter *adapter = NULL;
957 /* Reset ESP, Clean start ESP */
961 adapter = init_adapter();
966 /* Init transport layer */
967 ret = esp_init_interface_layer(adapter, clockspeed);
976 static void __exit esp_exit(void)
978 uint8_t iface_idx = 0;
980 test_raw_tp_cleanup();
982 for (iface_idx = 0; iface_idx < ESP_MAX_INTERFACE; iface_idx++) {
983 cmd_deinit_interface(adapter.priv[iface_idx]);
985 clear_bit(ESP_DRIVER_ACTIVE, &adapter.state_flags);
987 esp_deinit_interface_layer();
990 if (resetpin != HOST_GPIO_PIN_INVALID) {
994 MODULE_LICENSE("GPL");
998 MODULE_DESCRIPTION("Wifi driver for ESP-Hosted solution");
999 MODULE_VERSION(RELEASE_VERSION);
1000 module_init(esp_init);
1001 module_exit(esp_exit);