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,
46 #define ESP_PAYLOAD_HEADER 8
50 #define ACQUIRE_LOCK 1
51 #define LOCK_ALREADY_ACQUIRED 0
53 #define SKB_DATA_ADDR_ALIGNMENT 4
54 #define INTERFACE_HEADER_PADDING (SKB_DATA_ADDR_ALIGNMENT*3)
56 #define MAX_COUNTRY_LEN 3
58 enum adapter_flags_e {
59 ESP_CLEANUP_IN_PROGRESS, /* Driver unloading or ESP reseted */
60 ESP_CMD_INIT_DONE, /* Cmd component is initialized with esp_commands_setup() */
61 ESP_DRIVER_ACTIVE, /* kernel module __exit is not yet invoked */
69 struct list_head list;
71 struct sk_buff *cmd_skb;
72 struct sk_buff *resp_skb;
80 uint32_t capabilities;
83 * struct esp_sdio_context */
86 struct esp_if_ops *if_ops;
88 /* Private for each interface */
89 struct esp_wifi_device *priv[ESP_MAX_INTERFACE];
90 struct hci_dev *hcidev;
92 struct workqueue_struct *if_rx_workqueue;
93 struct work_struct if_rx_work;
95 wait_queue_head_t wait_for_cmd_resp;
98 /* wpa supplicant commands structures */
99 struct command_node *cmd_pool;
100 struct list_head cmd_free_queue;
101 spinlock_t cmd_free_queue_lock;
102 struct list_head cmd_pending_queue;
103 spinlock_t cmd_pending_queue_lock;
105 struct command_node *cur_cmd;
108 struct workqueue_struct *mac_filter_wq;
109 struct work_struct mac_flter_work;
111 struct workqueue_struct *cmd_wq;
112 struct work_struct cmd_work;
114 struct sk_buff_head events_skb_q;
115 struct workqueue_struct *events_wq;
116 struct work_struct events_work;
118 unsigned long state_flags;
124 struct esp_adapter *adapter;
127 struct esp_wifi_device {
128 struct wireless_dev wdev;
129 struct net_device *ndev;
130 struct esp_device *esp_dev;
131 struct esp_adapter *adapter;
133 struct net_device_stats stats;
134 uint8_t mac_address[MAC_ADDR_LEN];
141 /* This is needed to notify scan completion*/
142 struct cfg80211_scan_request *request;
143 struct cfg80211_bss *bss;
144 uint8_t *assoc_req_ie;
145 size_t assoc_req_ie_len;
147 uint8_t scan_in_progress;
148 uint8_t waiting_for_scan_done;
152 volatile uint8_t stop_data;
153 volatile uint8_t port_open;
155 char country_code[MAX_COUNTRY_LEN];
157 wait_queue_head_t wait_for_scan_completion;
158 unsigned long priv_flags;
159 struct notifier_block nb;
166 struct esp_wifi_device *priv;