2 * Espressif Systems Wireless LAN device driver
4 * Copyright (C) 2015-2021 Espressif Systems (Shanghai) PTE LTD
6 * This software file (the "File") is distributed by Espressif Systems (Shanghai)
7 * PTE LTD under the terms of the GNU General Public License Version 2, June 1991
8 * (the "License"). You may use, redistribute and/or modify this File in
9 * accordance with the terms and conditions of the License, a copy of which
10 * is available by writing to the Free Software Foundation, Inc.,
11 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12 * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
14 * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16 * ARE EXPRESSLY DISCLAIMED. The License provides additional details about
17 * this warranty disclaimer.
20 #include <linux/init.h>
21 #include <linux/module.h>
22 #include <linux/kernel.h>
23 #include <linux/gpio.h>
24 #include <linux/igmp.h>
28 #include "esp_bt_api.h"
31 #include "esp_kernel_port.h"
33 #include "esp_cfg80211.h"
34 #include "esp_stats.h"
36 #define HOST_GPIO_PIN_INVALID -1
37 static int resetpin = HOST_GPIO_PIN_INVALID;
38 extern u8 ap_bssid[MAC_ADDR_LEN];
39 extern volatile u8 host_sleep;
41 module_param(resetpin, int, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
42 MODULE_PARM_DESC(resetpin, "Host's GPIO pin number which is connected to ESP32's EN to reset ESP32 device");
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 printk(KERN_INFO "%s: no priv\n", __func__);
86 if (netif_queue_stopped((const struct net_device *) priv->ndev)) {
87 printk(KERN_INFO "%s: Netif queue stopped\n", __func__);
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 printk(KERN_ERR "%s: Failed to linearize SKB", __func__);
119 new_skb = esp_alloc_skb(skb->len + pad_len);
122 printk(KERN_ERR "%s: Failed to allocate SKB", __func__);
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 /* printk(KERN_ERR "%s: Failed to send SKB", __func__);*/
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 printk(KERN_INFO "Capabilities: 0x%x. Features supported are:\n", cap);
192 if (cap & ESP_WLAN_SDIO_SUPPORT)
193 printk(KERN_INFO "\t * WLAN on SDIO\n");
194 else if (cap & ESP_WLAN_SPI_SUPPORT)
195 printk(KERN_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 printk(KERN_INFO "\t * BT/BLE\n");
201 if (cap & ESP_BT_UART_SUPPORT)
202 printk(KERN_INFO "\t - HCI over UART\n");
203 if (cap & ESP_BT_SDIO_SUPPORT)
204 printk(KERN_INFO "\t - HCI over SDIO\n");
205 if (cap & ESP_BT_SPI_SUPPORT)
206 printk(KERN_INFO "\t - HCI over SPI\n");
208 if ((cap & ESP_BLE_ONLY_SUPPORT) && (cap & ESP_BR_EDR_ONLY_SUPPORT))
209 printk(KERN_INFO "\t - BT/BLE dual mode\n");
210 else if (cap & ESP_BLE_ONLY_SUPPORT)
211 printk(KERN_INFO "\t - BLE only\n");
212 else if (cap & ESP_BR_EDR_ONLY_SUPPORT)
213 printk(KERN_INFO "\t - BR EDR only\n");
217 void process_capabilities(struct esp_adapter *adapter)
219 printk(KERN_INFO "ESP peripheral capabilities: 0x%x\n", adapter->capabilities);
222 esp_deinit_bt(adapter);
224 if ((adapter->capabilities & ESP_BT_SPI_SUPPORT) ||
225 (adapter->capabilities & ESP_BT_SDIO_SUPPORT)) {
227 printk(KERN_INFO "ESP Bluetooth init\n");
228 esp_init_bt(adapter);
232 static int check_esp_version(struct fw_version *ver)
234 printk(KERN_INFO "esp32: ESP Firmware version: %u.%u.%u\n",
235 ver->major1, ver->major2, ver->minor);
237 printk(KERN_ERR "Incompatible ESP firmware release detected, Please use correct ESP-Hosted branch/compatible release\n");
243 static void print_reset_reason(uint32_t reason)
247 case 1 : printk(KERN_INFO "POWERON_RESET\n");break; /**<1, Vbat power on reset*/
248 case 3 : printk(KERN_INFO "SW_RESET\n");break; /**<3, Software reset digital core*/
249 case 4 : printk(KERN_INFO "OWDT_RESET\n");break; /**<4, Legacy watch dog reset digital core*/
250 case 5 : printk(KERN_INFO "DEEPSLEEP_RESET\n");break; /**<5, Deep Sleep reset digital core*/
251 case 6 : printk(KERN_INFO "SDIO_RESET\n");break; /**<6, Reset by SLC module, reset digital core*/
252 case 7 : printk(KERN_INFO "TG0WDT_SYS_RESET\n");break; /**<7, Timer Group0 Watch dog reset digital core*/
253 case 8 : printk(KERN_INFO "TG1WDT_SYS_RESET\n");break; /**<8, Timer Group1 Watch dog reset digital core*/
254 case 9 : printk(KERN_INFO "RTCWDT_SYS_RESET\n");break; /**<9, RTC Watch dog Reset digital core*/
255 case 10 : printk(KERN_INFO "INTRUSION_RESET\n");break; /**<10, Instrusion tested to reset CPU*/
256 case 11 : printk(KERN_INFO "TGWDT_CPU_RESET\n");break; /**<11, Time Group reset CPU*/
257 case 12 : printk(KERN_INFO "SW_CPU_RESET\n");break; /**<12, Software reset CPU*/
258 case 13 : printk(KERN_INFO "RTCWDT_CPU_RESET\n");break; /**<13, RTC Watch dog Reset CPU*/
259 case 14 : printk(KERN_INFO "EXT_CPU_RESET\n");break; /**<14, for APP CPU, reseted by PRO CPU*/
260 case 15 : printk(KERN_INFO "RTCWDT_BROWN_OUT_RESET\n");break;/**<15, Reset when the vdd voltage is not stable*/
261 case 16 : printk(KERN_INFO "RTCWDT_RTC_RESET\n");break; /**<16, RTC Watch dog reset digital core and rtc module*/
262 default : printk(KERN_INFO "Unknown[%u]\n",reason);break;
266 int process_fw_data(struct fw_data *fw_p)
269 printk(KERN_ERR "Incomplete/incorrect bootup event received\n");
273 printk(KERN_INFO "esp32: %s ESP chipset's last reset cause: ", __func__);
274 print_reset_reason(le32_to_cpu(fw_p->last_reset_reason));
275 return check_esp_version(&fw_p->version);
278 static int esp_open(struct net_device *ndev)
283 static int esp_stop(struct net_device *ndev)
285 struct esp_wifi_device *priv = netdev_priv(ndev);
286 ESP_MARK_SCAN_DONE(priv, true);
290 static struct net_device_stats* esp_get_stats(struct net_device *ndev)
292 struct esp_wifi_device *priv = netdev_priv(ndev);
301 static int esp_set_mac_address(struct net_device *ndev, void *data)
303 struct esp_wifi_device *priv = netdev_priv(ndev);
304 //struct sockaddr *mac_addr = data;
306 if (!priv || !priv->adapter)
309 printk(KERN_INFO "%s:%u %pM\n", __func__, __LINE__, priv->mac_address);
310 eth_hw_addr_set(ndev, priv->mac_address/*mac_addr->sa_data*/);
316 static NDO_TX_TIMEOUT_PROTOTYPE()
320 static void esp_set_rx_mode(struct net_device *ndev)
322 struct esp_wifi_device *priv = netdev_priv(ndev);
323 struct netdev_hw_addr *mac_addr;
326 struct in_device *in_dev = in_dev_get(ndev);
327 struct ip_mc_list *ip_list = in_dev->mc_list;
329 netdev_for_each_mc_addr(mac_addr, ndev) {
330 if (count < MAX_MULTICAST_ADDR_COUNT) {
331 /*printk(KERN_INFO "%d: %pM\n", count+1, mac_addr->addr);*/
332 memcpy(&mcast_list.mcast_addr[count++], mac_addr->addr, ETH_ALEN);
336 mcast_list.priv = priv;
337 mcast_list.addr_count = count;
339 if (priv->port_open) {
340 /*printk (KERN_INFO "Set Multicast list\n");*/
341 if (adapter.mac_filter_wq)
342 queue_work(adapter.mac_filter_wq, &adapter.mac_flter_work);
345 cmd_set_mcast_mac_list(priv, &mcast_list);
347 printk(KERN_DEBUG " IP MC Address: 0x%x\n", ip_list->multiaddr);
348 ip_list = ip_list->next;
354 static int esp_hard_start_xmit(struct sk_buff *skb, struct net_device *ndev)
356 struct esp_wifi_device *priv = NULL;
357 struct esp_skb_cb *cb = NULL;
362 priv = netdev_priv(ndev);
368 if (!priv->port_open) {
369 priv->stats.tx_dropped++;
370 /*printk(KERN_ERR "esp32: %s: port not yet open\n", __func__);*/
375 if (!skb->len || (skb->len > ETH_FRAME_LEN)) {
376 printk(KERN_ERR "esp32: %s: Bad len %d\n", __func__, skb->len);
377 priv->stats.tx_dropped++;
382 cb = (struct esp_skb_cb *) skb->cb;
385 return process_tx_packet(skb);
388 static const struct net_device_ops esp_netdev_ops = {
389 .ndo_open = esp_open,
390 .ndo_stop = esp_stop,
391 .ndo_start_xmit = esp_hard_start_xmit,
392 .ndo_validate_addr = eth_validate_addr,
393 .ndo_tx_timeout = esp_tx_timeout,
394 .ndo_get_stats = esp_get_stats,
395 .ndo_set_rx_mode = esp_set_rx_mode,
399 void esp_init_priv(struct net_device *ndev)
401 ndev->netdev_ops = &esp_netdev_ops;
402 ndev->needed_headroom = roundup(sizeof(struct esp_payload_header) +
403 INTERFACE_HEADER_PADDING, 4);
406 static int add_network_iface(void)
409 struct esp_adapter * adapter = esp_get_adapter();
410 struct wireless_dev * wdev = NULL;
413 printk(KERN_INFO "%s: adapter not yet init\n", __func__);
417 ret = esp_cfg80211_register(adapter);
419 printk(KERN_ERR "Failed to register with cfg80211 (err code 0x%x)\n", ret);
424 wdev = esp_cfg80211_add_iface(adapter->wiphy, "espsta%d", 1, NL80211_IFTYPE_STATION, NULL);
427 /* Return success if network added successfully */
434 int esp_add_card(struct esp_adapter *adapter)
436 RET_ON_FAIL(esp_commands_setup(adapter));
438 RET_ON_FAIL(add_network_iface());
443 void esp_remove_network_interfaces(struct esp_adapter *adapter)
445 uint8_t iface_idx = 0;
446 struct net_device *ndev = NULL;
447 struct esp_wifi_device *priv = NULL;
449 for (iface_idx=0; iface_idx < ESP_MAX_INTERFACE; iface_idx++) {
451 priv = adapter->priv[iface_idx];
456 if (!test_bit(ESP_NETWORK_UP, &priv->priv_flags))
459 /* stop and unregister network */
464 if (netif_carrier_ok(ndev))
465 netif_carrier_off(ndev);
467 netif_device_detach(ndev);
469 if (ndev->reg_state == NETREG_REGISTERED) {
470 unregister_inetaddr_notifier(&(adapter->priv[0]->nb));
471 unregister_netdev(ndev);
476 clear_bit(ESP_NETWORK_UP, &priv->priv_flags);
479 if (adapter->wiphy) {
481 wiphy_unregister(adapter->wiphy);
482 wiphy_free(adapter->wiphy);
483 adapter->wiphy = NULL;
487 int esp_remove_card(struct esp_adapter *adapter)
489 uint8_t iface_idx = 0;
495 esp_deinit_bt(adapter);
497 esp_commands_teardown(adapter);
499 esp_remove_network_interfaces(adapter);
501 for (iface_idx=0; iface_idx < ESP_MAX_INTERFACE; iface_idx++) {
502 esp_port_close(adapter->priv[iface_idx]);
503 adapter->priv[iface_idx] = NULL;
509 struct esp_wifi_device * get_priv_from_payload_header(
510 struct esp_payload_header *header)
512 struct esp_wifi_device *priv = NULL;
518 for (i = 0; i < ESP_MAX_INTERFACE; i++) {
519 priv = adapter.priv[i];
524 if (priv->if_type == header->if_type &&
525 priv->if_num == header->if_num) {
532 static void process_esp_bootup_event(struct esp_adapter *adapter,
533 struct esp_internal_bootup_event *evt)
535 if (!adapter || !evt) {
536 printk(KERN_ERR "%s: Invalid arguments\n", __func__);
540 if (evt->header.status) {
541 printk(KERN_ERR "%s: Incorrect ESP bootup event\n", __func__);
545 printk (KERN_INFO "\nReceived ESP bootup event\n");
546 process_event_esp_bootup(adapter, evt->data, evt->len);
549 static int process_internal_event(struct esp_adapter *adapter,
552 struct event_header *header = NULL;
554 if (!skb || !adapter) {
555 printk (KERN_ERR "esp32: Incorrect event data!\n");
559 header = (struct event_header *) (skb->data);
561 switch (header->event_code) {
563 case ESP_INTERNAL_BOOTUP_EVENT:
564 process_esp_bootup_event(adapter,
565 (struct esp_internal_bootup_event *)(skb->data));
569 printk(KERN_INFO "%s:%u unhandled internal event[%u]\n",
570 __func__, __LINE__, header->event_code);
577 static void process_rx_packet(struct esp_adapter *adapter, struct sk_buff *skb)
579 struct esp_wifi_device *priv = NULL;
580 struct esp_payload_header *payload_header = NULL;
581 u16 len = 0, offset = 0;
582 u16 rx_checksum = 0, checksum = 0;
583 struct hci_dev *hdev = adapter->hcidev;
585 struct sk_buff * eap_skb = NULL;
586 struct ethhdr * eth = NULL;
591 /* get the paload header */
592 payload_header = (struct esp_payload_header *) skb->data;
594 len = le16_to_cpu(payload_header->len);
595 offset = le16_to_cpu(payload_header->offset);
597 if (payload_header->reserved2 == 0xFF) {
598 print_hex_dump(KERN_INFO, "Wake up packet: ", DUMP_PREFIX_ADDRESS, 16, 1, skb->data, len+offset, 1);
601 if (adapter->capabilities & ESP_CHECKSUM_ENABLED) {
602 rx_checksum = le16_to_cpu(payload_header->checksum);
603 payload_header->checksum = 0;
605 checksum = compute_checksum(skb->data, (len + offset));
607 if (checksum != rx_checksum) {
608 dev_kfree_skb_any(skb);
613 /* chop off the header from skb */
614 skb_pull(skb, offset);
616 if (payload_header->if_type == ESP_STA_IF || payload_header->if_type == ESP_AP_IF) {
618 /* retrieve priv based on payload header contents */
619 priv = get_priv_from_payload_header(payload_header);
622 printk(KERN_ERR "%s: empty priv\n", __func__);
623 dev_kfree_skb_any(skb);
627 if (payload_header->packet_type == PACKET_TYPE_EAPOL) {
628 printk(KERN_INFO "%s: Rx PACKET_TYPE_EAPOL!!!!\n", __func__);
631 eap_skb = alloc_skb(skb->len + ETH_HLEN, GFP_KERNEL);
633 printk(KERN_INFO "%s:%u memory alloc failed\n",__func__, __LINE__);
636 eap_skb->dev = priv->ndev;
638 if (!IS_ALIGNED((unsigned long) eap_skb->data, SKB_DATA_ADDR_ALIGNMENT)) {
639 printk(KERN_INFO "%s:%u eap skb unaligned\n",__func__, __LINE__);
642 eth = (struct ethhdr *) skb_put(eap_skb, ETH_HLEN);
643 ether_addr_copy(eth->h_dest, /*skb->data*/priv->ndev->dev_addr);
644 ether_addr_copy(eth->h_source, /*skb->data+6*/ ap_bssid);
645 eth->h_proto = cpu_to_be16(ETH_P_PAE);
647 skb_put_data(eap_skb, skb->data, skb->len);
648 eap_skb->protocol = eth_type_trans(eap_skb, eap_skb->dev);
652 } else if (payload_header->packet_type == PACKET_TYPE_DATA) {
654 skb->dev = priv->ndev;
655 skb->protocol = eth_type_trans(skb, priv->ndev);
656 skb->ip_summed = CHECKSUM_NONE;
658 priv->stats.rx_bytes += skb->len;
659 /* Forward skb to kernel */
661 priv->stats.rx_packets++;
662 } else if (payload_header->packet_type == PACKET_TYPE_COMMAND_RESPONSE) {
663 process_cmd_resp(priv->adapter, skb);
664 } else if (payload_header->packet_type == PACKET_TYPE_EVENT) {
665 process_cmd_event(priv, skb);
666 dev_kfree_skb_any(skb);
669 } else if (payload_header->if_type == ESP_HCI_IF) {
673 hci_skb_pkt_type(skb) = *type;
676 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0))
677 if (hci_recv_frame(hdev, skb)) {
679 if (hci_recv_frame(skb)) {
683 esp_hci_update_rx_counter(hdev, *type, skb->len);
686 } else if (payload_header->if_type == ESP_INTERNAL_IF) {
688 /* Queue event skb for processing in events workqueue */
689 skb_queue_tail(&adapter->events_skb_q, skb);
691 if (adapter->events_wq)
692 queue_work(adapter->events_wq, &adapter->events_work);
694 dev_kfree_skb_any(skb);
696 } else if (payload_header->if_type == ESP_TEST_IF) {
698 update_test_raw_tp_rx_stats(len);
700 dev_kfree_skb_any(skb);
702 dev_kfree_skb_any(skb);
706 int esp_is_tx_queue_paused(struct esp_wifi_device *priv)
708 if (!priv || !priv->ndev)
712 !netif_queue_stopped((const struct net_device *)priv->ndev)))
717 void esp_tx_pause(struct esp_wifi_device *priv)
719 if (!priv || !priv->ndev)
722 if (!netif_queue_stopped((const struct net_device *)priv->ndev)) {
723 netif_stop_queue(priv->ndev);
727 void esp_tx_resume(struct esp_wifi_device *priv)
729 if (!priv || !priv->ndev)
732 if (netif_queue_stopped((const struct net_device *)priv->ndev)) {
733 netif_wake_queue(priv->ndev);
737 struct sk_buff * esp_alloc_skb(u32 len)
739 struct sk_buff *skb = NULL;
743 skb = netdev_alloc_skb(NULL, len + INTERFACE_HEADER_PADDING);
746 /* Align SKB data pointer */
747 offset = ((unsigned long)skb->data) & (SKB_DATA_ADDR_ALIGNMENT - 1);
750 skb_reserve(skb, INTERFACE_HEADER_PADDING - offset);
757 static int esp_get_packets(struct esp_adapter *adapter)
759 struct sk_buff *skb = NULL;
761 if (!adapter || !adapter->if_ops || !adapter->if_ops->read)
764 skb = adapter->if_ops->read(adapter);
769 process_rx_packet(adapter, skb);
774 int esp_send_packet(struct esp_adapter *adapter, struct sk_buff *skb)
776 if (!adapter || !adapter->if_ops || !adapter->if_ops->write) {
777 printk(KERN_ERR "esp32: %s:%u adapter: %p\n", __func__, __LINE__, adapter);
781 return adapter->if_ops->write(adapter, skb);
784 static void esp_if_rx_work(struct work_struct *work)
786 /* read inbound packet and forward it to network/serial interface */
787 esp_get_packets(&adapter);
790 static void update_mac_filter(struct work_struct *work)
792 cmd_set_mcast_mac_list(mcast_list.priv, &mcast_list);
795 static void esp_events_work(struct work_struct *work)
797 struct sk_buff *skb = NULL;
799 skb = skb_dequeue(&adapter.events_skb_q);
803 process_internal_event(&adapter, skb);
804 dev_kfree_skb_any(skb);
807 static struct esp_adapter * init_adapter(void)
809 memset(&adapter, 0, sizeof(adapter));
811 /* Prepare interface RX work */
812 adapter.if_rx_workqueue = alloc_workqueue("ESP_IF_RX_WORK_QUEUE", 0, 0);
814 if (!adapter.if_rx_workqueue) {
819 INIT_WORK(&adapter.if_rx_work, esp_if_rx_work);
821 skb_queue_head_init(&adapter.events_skb_q);
823 adapter.events_wq = alloc_workqueue("ESP_EVENTS_WORKQUEUE", WQ_HIGHPRI, 0);
825 if (!adapter.events_wq) {
830 INIT_WORK(&adapter.events_work, esp_events_work);
832 adapter.mac_filter_wq = alloc_workqueue("MAC_FILTER", 0, 0);
833 if (!adapter.mac_filter_wq) {
838 INIT_WORK(&adapter.mac_flter_work, update_mac_filter);
843 static void deinit_adapter(void)
845 skb_queue_purge(&adapter.events_skb_q);
847 if (adapter.events_wq)
848 destroy_workqueue(adapter.events_wq);
850 if (adapter.if_rx_workqueue)
851 destroy_workqueue(adapter.if_rx_workqueue);
853 if (adapter.mac_filter_wq)
854 destroy_workqueue(adapter.mac_filter_wq);
857 static void esp_reset(void)
859 if (resetpin != HOST_GPIO_PIN_INVALID) {
860 /* Check valid GPIO or not */
861 if (!gpio_is_valid(resetpin)) {
862 printk(KERN_WARNING "%s, ESP32: host resetpin (%d) configured is invalid GPIO\n", __func__, resetpin);
863 resetpin = HOST_GPIO_PIN_INVALID;
865 gpio_request(resetpin, "sysfs");
867 /* HOST's resetpin set to OUTPUT, HIGH */
868 gpio_direction_output(resetpin, true);
870 /* HOST's resetpin set to LOW */
871 gpio_set_value(resetpin, 0);
874 /* HOST's resetpin set to INPUT */
875 gpio_direction_input(resetpin);
877 printk(KERN_DEBUG "%s, ESP32: Triggering ESP reset.\n", __func__);
883 static int __init esp_init(void)
886 struct esp_adapter *adapter = NULL;
888 /* Reset ESP, Clean start ESP */
892 adapter = init_adapter();
897 /* Init transport layer */
898 ret = esp_init_interface_layer(adapter);
907 static void __exit esp_exit(void)
909 uint8_t iface_idx = 0;
911 test_raw_tp_cleanup();
913 for (iface_idx=0; iface_idx<ESP_MAX_INTERFACE; iface_idx++) {
914 cmd_deinit_interface(adapter.priv[iface_idx]);
916 clear_bit(ESP_DRIVER_ACTIVE, &adapter.state_flags);
918 esp_deinit_interface_layer();
921 if (resetpin != HOST_GPIO_PIN_INVALID) {
925 MODULE_LICENSE("GPL");
929 MODULE_DESCRIPTION("Wifi driver for ESP-Hosted solution");
930 MODULE_VERSION("0.1");
931 module_init(esp_init);
932 module_exit(esp_exit);