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
11 #include <linux/workqueue.h>
12 #include <linux/wait.h>
13 #include <linux/interrupt.h>
14 #include <linux/netdevice.h>
15 #include <linux/inetdevice.h>
16 #include <linux/etherdevice.h>
17 #include <linux/spinlock.h>
18 #include <net/cfg80211.h>
19 #include <net/bluetooth/bluetooth.h>
20 #include <net/bluetooth/hci_core.h>
23 #define ESP_IF_TYPE_SDIO 1
24 #define ESP_IF_TYPE_SPI 2
26 /* Network link status */
27 #define ESP_LINK_DOWN 0
30 #define ESP_MAX_INTERFACE 1
31 //#define ESP_MAX_INTERFACE 2
32 #define ESP_STA_NW_IF 0
33 #define ESP_AP_NW_IF 1
35 /* ESP in sdkconfig has CONFIG_IDF_FIRMWARE_CHIP_ID entry.
36 * supported values of CONFIG_IDF_FIRMWARE_CHIP_ID are - */
38 ESP_FIRMWARE_CHIP_UNRECOGNIZED = 0xff,
39 ESP_FIRMWARE_CHIP_ESP32 = 0x0,
40 ESP_FIRMWARE_CHIP_ESP32S2 = 0x2,
41 ESP_FIRMWARE_CHIP_ESP32C3 = 0x5,
42 ESP_FIRMWARE_CHIP_ESP32S3 = 0x9,
43 ESP_FIRMWARE_CHIP_ESP32C2 = 0x0C,
44 ESP_FIRMWARE_CHIP_ESP32C6 = 0x0D,
47 #define ESP_PAYLOAD_HEADER 8
51 #define ACQUIRE_LOCK 1
52 #define LOCK_ALREADY_ACQUIRED 0
54 #define SKB_DATA_ADDR_ALIGNMENT 4
55 #define INTERFACE_HEADER_PADDING (SKB_DATA_ADDR_ALIGNMENT*3)
57 #define MAX_COUNTRY_LEN 3
59 enum adapter_flags_e {
60 ESP_CLEANUP_IN_PROGRESS, /* Driver unloading or ESP reseted */
61 ESP_CMD_INIT_DONE, /* Cmd component is initialized with esp_commands_setup() */
62 ESP_DRIVER_ACTIVE, /* kernel module __exit is not yet invoked */
63 ESP_INIT_DONE, /* Driver init done */
71 struct list_head list;
73 struct sk_buff *cmd_skb;
74 struct sk_buff *resp_skb;
82 uint32_t capabilities;
85 * struct esp_sdio_context */
88 struct esp_if_ops *if_ops;
90 /* Private for each interface */
91 struct esp_wifi_device *priv[ESP_MAX_INTERFACE];
92 struct hci_dev *hcidev;
94 struct workqueue_struct *if_rx_workqueue;
95 struct work_struct if_rx_work;
97 wait_queue_head_t wait_for_cmd_resp;
100 /* wpa supplicant commands structures */
101 struct command_node *cmd_pool;
102 struct list_head cmd_free_queue;
103 spinlock_t cmd_free_queue_lock;
104 struct list_head cmd_pending_queue;
105 spinlock_t cmd_pending_queue_lock;
107 struct command_node *cur_cmd;
110 struct workqueue_struct *mac_filter_wq;
111 struct work_struct mac_flter_work;
113 struct workqueue_struct *cmd_wq;
114 struct work_struct cmd_work;
116 struct sk_buff_head events_skb_q;
117 struct workqueue_struct *events_wq;
118 struct work_struct events_work;
120 unsigned long state_flags;
126 struct esp_adapter *adapter;
129 struct esp_wifi_device {
130 struct wireless_dev wdev;
131 struct net_device *ndev;
132 struct esp_device *esp_dev;
133 struct esp_adapter *adapter;
135 struct net_device_stats stats;
136 uint8_t mac_address[MAC_ADDR_LEN];
143 /* This is needed to notify scan completion*/
144 struct cfg80211_scan_request *request;
145 struct cfg80211_bss *bss;
146 uint8_t *assoc_req_ie;
147 size_t assoc_req_ie_len;
149 uint8_t scan_in_progress;
150 uint8_t waiting_for_scan_done;
154 volatile uint8_t stop_data;
155 volatile uint8_t port_open;
157 char country_code[MAX_COUNTRY_LEN];
159 wait_queue_head_t wait_for_scan_completion;
160 unsigned long priv_flags;
161 struct notifier_block nb;
168 struct esp_wifi_device *priv;