wifi->esp8089:
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rockchip_wlan / esp8089 / esp_driver / esp_pub.h
1 /*
2  * Copyright (c) 2011-2014 Espressif System.
3  *
4  *   wlan device header file
5  */
6
7 #ifndef _ESP_PUB_H_
8 #define _ESP_PUB_H_
9
10 #include <linux/etherdevice.h>
11 #include <linux/rtnetlink.h>
12 #include <linux/firmware.h>
13 #include <linux/sched.h>
14 #include <net/mac80211.h>
15 #include <net/cfg80211.h>
16 #include <linux/version.h>
17 #include "sip2_common.h"
18
19 // to support kernel < 2.6.28 there's no ieee80211_sta
20 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
21 #include <net/wireless.h>
22 #endif
23
24 enum esp_sdio_state{
25         ESP_SDIO_STATE_FIRST_INIT,
26         ESP_SDIO_STATE_FIRST_NORMAL_EXIT,
27         ESP_SDIO_STATE_FIRST_ERROR_EXIT,
28         ESP_SDIO_STATE_SECOND_INIT,
29         ESP_SDIO_STATE_SECOND_ERROR_EXIT,
30 };
31
32 enum esp_tid_state {
33         ESP_TID_STATE_INIT,
34         ESP_TID_STATE_TRIGGER,
35         ESP_TID_STATE_PROGRESS,
36         ESP_TID_STATE_OPERATIONAL,
37         ESP_TID_STATE_WAIT_STOP,
38         ESP_TID_STATE_STOP,
39 };
40
41 struct esp_tx_tid {
42         u8 state;
43         u8 cnt;
44         u16 ssn;
45 };
46
47 #define WME_NUM_TID 16
48 struct esp_node {
49         struct esp_tx_tid tid[WME_NUM_TID];
50 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 28))
51         struct ieee80211_sta *sta;
52 #else
53         u8 addr[ETH_ALEN];
54         u16 aid;
55         u64 supp_rates[IEEE80211_NUM_BANDS];
56         struct ieee80211_ht_info ht_info;
57 #endif
58         u8 ifidx;
59         u8 index;
60 };
61
62 #define WME_AC_BE 2
63 #define WME_AC_BK 3
64 #define WME_AC_VI 1
65 #define WME_AC_VO 0
66
67 struct llc_snap_hdr {
68         u8 dsap;
69         u8 ssap;
70         u8 cntl;
71         u8 org_code[3];
72         __be16 eth_type;
73 } __packed;
74
75 struct esp_vif {
76         struct esp_pub *epub;
77         u8 index;
78         u32 beacon_interval;
79         bool ap_up;
80         struct timer_list beacon_timer;
81 };
82
83 /* WLAN related, mostly... */
84 /*struct hw_scan_timeout {
85         struct delayed_work w;
86         struct ieee80211_hw *hw;
87 };*/
88
89 typedef struct esp_wl {
90         u8 bssid[ETH_ALEN];
91         u8 req_bssid[ETH_ALEN];
92
93         //struct hw_scan_timeout *hsd;
94         struct cfg80211_scan_request *scan_req;
95         atomic_t ptk_cnt;
96         atomic_t gtk_cnt;
97         atomic_t tkip_key_set;
98
99         /* so far only 2G band */
100         struct ieee80211_supported_band sbands[IEEE80211_NUM_BANDS];
101
102         unsigned long flags;
103         atomic_t off;
104 } esp_wl_t;
105
106 typedef struct esp_hw_idx_map {
107         u8 mac[ETH_ALEN];
108         u8 flag;
109 } esp_hw_idx_map_t;
110
111 #define ESP_WL_FLAG_RFKILL                      BIT(0)
112 #define ESP_WL_FLAG_HW_REGISTERED               BIT(1)
113 #define ESP_WL_FLAG_CONNECT                             BIT(2)
114 #define ESP_WL_FLAG_STOP_TXQ                    BIT(3)
115
116 #define ESP_PUB_MAX_VIF         2
117 #define ESP_PUB_MAX_STA         4 //for one interface
118 #define ESP_PUB_MAX_RXAMPDU     8 //for all interfaces
119
120 enum {
121         ESP_PM_OFF = 0,
122         ESP_PM_TURNING_ON,
123         ESP_PM_ON,
124         ESP_PM_TURNING_OFF,  /* Do NOT change the order */
125 };
126
127 struct esp_ps {
128         u32 dtim_period;
129         u32 max_sleep_period;
130         unsigned long last_config_time;
131         atomic_t state;
132         bool nulldata_pm_on;
133 };
134
135 struct esp_mac_prefix {  
136         u8 mac_index;
137         u8 mac_addr_prefix[3];
138 };
139
140 struct esp_pub {
141         struct device *dev;
142 #ifdef ESP_NO_MAC80211
143         struct net_device *net_dev;
144         struct wireless_dev *wdev;
145         struct net_device_stats *net_stats;
146 #else
147         struct ieee80211_hw *hw;
148         struct ieee80211_vif *vif;
149         u8 vif_slot;
150 #endif /* ESP_MAC80211 */
151
152         void *sif; /* serial interface control block, e.g. sdio */
153         enum esp_sdio_state sdio_state;
154         struct esp_sip *sip;
155         struct esp_wl wl;
156         struct esp_hw_idx_map hi_map[19];
157         struct esp_hw_idx_map low_map[ESP_PUB_MAX_VIF][2];
158         //u32 flags; //flags to represent rfkill switch,start
159         u8 roc_flags;   //0: not in remain on channel state, 1: in roc state
160
161         struct work_struct tx_work; /* attach to ieee80211 workqueue */
162         /* latest mac80211 has multiple tx queue, but we stick with single queue now */
163         spinlock_t rx_lock;
164         spinlock_t tx_ampdu_lock;
165         spinlock_t rx_ampdu_lock;
166         spinlock_t tx_lock;
167         struct mutex tx_mtx;
168         struct sk_buff_head txq;
169         atomic_t txq_stopped;
170
171         struct work_struct sendup_work; /* attach to ieee80211 workqueue */
172         struct sk_buff_head txdoneq;
173         struct sk_buff_head rxq;
174
175         struct workqueue_struct *esp_wkq;
176
177         //u8 bssid[ETH_ALEN];
178         u8 mac_addr[ETH_ALEN];
179
180         u32 rx_filter;
181         unsigned long scan_permit;
182         bool scan_permit_valid;
183         struct delayed_work scan_timeout_work;
184         u32 enodes_map;
185         u8 rxampdu_map;
186         u32 enodes_maps[ESP_PUB_MAX_VIF];
187 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28))
188         struct esp_node nodes[ESP_PUB_MAX_STA + 1];
189 #endif
190         struct esp_node * enodes[ESP_PUB_MAX_STA + 1];
191         struct esp_node * rxampdu_node[ESP_PUB_MAX_RXAMPDU];
192         u8 rxampdu_tid[ESP_PUB_MAX_RXAMPDU];
193         struct esp_ps ps;
194         int enable_int;
195         int wait_reset;
196 };
197
198 typedef struct esp_pub esp_pub_t;
199
200 struct esp_pub *esp_pub_alloc_mac80211(struct device *dev);
201 int esp_pub_dealloc_mac80211(struct esp_pub  *epub);
202 int esp_register_mac80211(struct esp_pub *epub);
203
204 int esp_pub_init_all(struct esp_pub *epub);
205
206 char *mod_eagle_path_get(void);
207
208 void esp_dsr(struct esp_pub *epub);
209 void hw_scan_done(struct esp_pub *epub, bool aborted);
210 void esp_rocdone_process(struct ieee80211_hw *hw, struct sip_evt_roc *report);
211
212 void esp_ps_config(struct esp_pub *epub, struct esp_ps *ps, bool on);
213
214
215 void esp_register_early_suspend(void);
216 void esp_unregister_early_suspend(void);
217 void esp_wakelock_init(void);
218 void esp_wakelock_destroy(void);
219 void esp_wake_lock(void);
220 void esp_wake_unlock(void);
221 struct esp_node * esp_get_node_by_addr(struct esp_pub * epub, const u8 *addr);
222 struct esp_node * esp_get_node_by_index(struct esp_pub * epub, u8 index);
223 int esp_get_empty_rxampdu(struct esp_pub * epub, const u8 *addr, u8 tid);
224 int esp_get_exist_rxampdu(struct esp_pub * epub, const u8 *addr, u8 tid);
225
226 #ifdef TEST_MODE
227 int test_init_netlink(struct esp_sip *sip);
228 void test_exit_netlink(void);
229 void esp_test_cmd_event(u32 cmd_type, char *reply_info);
230 void esp_test_init(struct esp_pub *epub);
231 #endif
232 #endif /* _ESP_PUB_H_ */