add rk3288 pinctrl dts code
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / rda5990 / rda_wlan / rda5890_dev.h
1 /**
2   * This file contains definitions and data structures specific
3   * to Marvell 802.11 NIC. It contains the Device Information
4   * structure struct lbs_private..
5   */
6 #ifndef _RDA5890_DEV_H_
7 #define _RDA5890_DEV_H_
8 #include <linux/netdevice.h>
9 #include <linux/wireless.h>
10 #include <linux/ethtool.h>
11 #include <linux/delay.h>
12 #include <linux/debugfs.h>
13 #include <linux/wakelock.h>
14 #include "rda5890_defs.h"
15 //#include "hif_sdio.h"
16
17
18 #ifndef MAX_WPA_IE_LEN
19 #define MAX_WPA_IE_LEN 100
20 #endif
21
22 #ifndef MAX_RATES
23 #define MAX_RATES                       14
24 #endif
25
26 #define DEV_NAME_LEN                    32
27
28 #define RDA5890_MAX_NETWORK_NUM    32
29
30 /** RSSI related MACRO DEFINITIONS */
31 #define RDA5890_NF_DEFAULT_SCAN_VALUE           (-96)
32 #define PERFECT_RSSI ((u8)50)
33 #define WORST_RSSI   ((u8)0)
34 #define RSSI_DIFF    ((u8)(PERFECT_RSSI - WORST_RSSI))
35
36 /** RTS/FRAG related defines */
37 #define RDA5890_RTS_MIN_VALUE           0
38 #define RDA5890_RTS_MAX_VALUE           2347
39 #define RDA5890_FRAG_MIN_VALUE          256
40 #define RDA5890_FRAG_MAX_VALUE          2346
41
42 #define KEY_LEN_WPA_AES                 16
43 #define KEY_LEN_WPA_TKIP                32
44 #define KEY_LEN_WEP_104                 13
45 #define KEY_LEN_WEP_40                  5
46
47 #define BIT7                    (1 << 7)
48 #define BIT6                    (1 << 6)
49 #define BIT5                    (1 << 5)
50 #define BIT4                    (1 << 4)
51 #define BIT3                    (1 << 3)
52 #define BIT2                    (1 << 2)
53 #define BIT1                    (1 << 1)
54 #define BIT0                    (1 << 0)
55
56 #define RDA_SLEEP_ENABLE        BIT0
57 #define RDA_SLEEP_PREASSO       BIT1
58
59 //#define WIFI_UNIT_TEST
60
61 /** KEY_TYPE_ID */
62 enum KEY_TYPE_ID {
63         KEY_TYPE_ID_WEP = 0,
64         KEY_TYPE_ID_TKIP,
65         KEY_TYPE_ID_AES
66 };
67
68 enum PACKET_TYPE{
69     WID_REQUEST_PACKET,
70     WID_REQUEST_POLLING_PACKET,
71     DATA_REQUEST_PACKET
72 };
73
74 /** KEY_INFO_WPA (applies to both TKIP and AES/CCMP) */
75 enum KEY_INFO_WPA {
76         KEY_INFO_WPA_MCAST = 0x01,
77         KEY_INFO_WPA_UNICAST = 0x02,
78         KEY_INFO_WPA_ENABLED = 0x04
79 };
80
81 /* RDA5890 defined bss descriptor, 44 bytes for each bss */
82 struct rda5890_bss_descriptor {
83         u8 ssid[IW_ESSID_MAX_SIZE + 1];
84         u8 bss_type;
85         u8 channel;
86         u8 dot11i_info;
87         u8 bssid[ETH_ALEN];
88         u8 rssi;
89         u8 auth_info;
90         u8 rsn_cap[2];
91 } __attribute__ ((packed));
92
93 /**
94  *  @brief Structure used to store information for each beacon/probe response
95  */
96 struct bss_descriptor {
97         struct rda5890_bss_descriptor data;
98
99         u8 bssid[ETH_ALEN];
100
101         u8 ssid[IW_ESSID_MAX_SIZE + 1];
102         u8 ssid_len;
103
104         u16 capability;
105         u32 rssi;
106         u32 channel;
107         u16 beaconperiod;
108
109         /* IW_MODE_AUTO, IW_MODE_ADHOC, IW_MODE_INFRA */
110         u8 mode;
111
112         /* zero-terminated array of supported data rates */
113         u8 rates[MAX_RATES + 1];    
114         u8 wpa_ie[MAX_WPA_IE_LEN];
115         size_t wpa_ie_len;
116         u8 rsn_ie[MAX_WPA_IE_LEN];
117         size_t rsn_ie_len;
118
119       u8 wapi_ie[100];
120       size_t wapi_ie_len; //wapi valid payload length
121
122         unsigned long last_scanned;
123
124
125         struct list_head list;
126 };
127
128 /* Generic structure to hold all key types. */
129 struct enc_key {
130         u16 len;
131         u16 flags;  /* KEY_INFO_* from defs.h */
132         u16 type; /* KEY_TYPE_* from defs.h */
133         u8 key[32];
134 };
135
136 struct rda5890_802_11_security {
137         u8 WPAenabled;
138         u8 WPA2enabled;
139         u8 wep_enabled;
140         u8 auth_mode;
141         u32 key_mgmt;
142     u32 cipther_type;
143 };
144
145 /** Private structure for the rda5890 device */
146 struct rda5890_private {
147         char name[DEV_NAME_LEN];
148
149         void *card;
150         struct net_device *dev;
151
152         struct net_device_stats stats;
153
154         /** current ssid/bssid related parameters and status */
155         int connect_status;
156         struct rda5890_bss_descriptor curbssparams;
157         struct iw_statistics wstats; 
158
159         /** association flags */
160         unsigned char assoc_ssid[IW_ESSID_MAX_SIZE + 1];
161     unsigned char assoc_bssid[6];
162         unsigned char assoc_ssid_len; 
163 #define ASSOC_FLAG_SSID                 1
164 #define ASSOC_FLAG_CHANNEL              2
165 #define ASSOC_FLAG_BAND                 3
166 #define ASSOC_FLAG_MODE                 4
167 #define ASSOC_FLAG_BSSID                5
168 #define ASSOC_FLAG_WEP_KEYS             6
169 #define ASSOC_FLAG_WEP_TX_KEYIDX        7
170 #define ASSOC_FLAG_WPA_MCAST_KEY        8
171 #define ASSOC_FLAG_WPA_UCAST_KEY        9
172 #define ASSOC_FLAG_SECINFO              10
173 #define ASSOC_FLAG_WPA_IE               11
174 #define ASSOC_FLAG_ASSOC_RETRY          12
175 #define ASSOC_FLAG_ASSOC_START  13
176 #define ASSOC_FLAG_WLAN_CONNECTING  14
177
178         unsigned long assoc_flags;
179         unsigned char imode;
180         unsigned char authtype;
181
182         /** debugfs */
183         struct dentry *debugfs_dir;
184         struct dentry *debugfs_files[6];
185
186         /** for wid request and response */
187         struct mutex wid_lock;
188         struct completion wid_done;
189         int wid_pending;
190         char *wid_rsp;
191         unsigned short wid_rsp_len;
192         char wid_msg_id;
193
194         /** delayed worker */
195         struct workqueue_struct *work_thread;
196         struct delayed_work scan_work;
197         struct delayed_work assoc_work;
198         struct delayed_work assoc_done_work;
199     struct delayed_work   wlan_connect_work;
200
201         /** Hardware access */
202         int (*hw_host_to_card) (struct rda5890_private *priv, u8 *payload, u16 nb, 
203                                     unsigned char packet_type);
204
205         /** Scan results list */
206         int scan_running;
207         struct list_head network_list;
208         struct list_head network_free_list;
209         struct bss_descriptor *networks;
210
211         /** Encryption parameter */
212         struct rda5890_802_11_security secinfo;
213
214         /** WEP keys */
215         struct enc_key wep_keys[4];
216         u16 wep_tx_keyidx;
217
218         /** WPA keys */
219         struct enc_key wpa_mcast_key;
220         struct enc_key wpa_unicast_key;
221
222         /** WPA Information Elements*/
223         u8 wpa_ie[MAX_WPA_IE_LEN];
224         u8 wpa_ie_len;
225
226         u8 is_wapi;
227         /** sleep/awake flag */
228 #ifdef WIFI_POWER_MANAGER        
229         atomic_t sleep_flag;
230 #endif
231     u8  first_init;
232     u16 version;
233 };
234
235 extern int rda5890_sleep_flags;
236
237 #ifdef WIFI_TEST_MODE
238 extern unsigned char rda_5990_wifi_in_test_mode(void);
239 #endif
240
241 #ifdef WIFI_UNLOCK_SYSTEM
242 extern atomic_t     wake_lock_counter;
243 extern struct wake_lock sleep_worker_wake_lock;
244 extern void rda5990_wakeLock(void);
245 extern void rda5990_wakeUnlock(void);
246 extern void rda5990_wakeLock_destroy(void);
247 #endif
248
249 struct rda5890_private *rda5890_add_card(void *card);
250 void rda5890_remove_card(struct rda5890_private *priv);
251 int  rda5890_start_card(struct rda5890_private *priv);
252 void rda5890_stop_card(struct rda5890_private *priv);
253 int rda5890_sdio_core_wake_mode(struct rda5890_private *priv);
254 int rda5890_sdio_core_sleep_mode(struct rda5890_private *priv);
255 int rda5890_sdio_core_wake_mode_polling(struct rda5890_private *priv);
256
257 void rda5890_sdio_set_notch_by_channel(struct rda5890_private *priv, unsigned int channel);
258 void rda5890_rssi_up_to_200(struct rda5890_private *priv);
259 void rda5990_assoc_power_save(struct rda5890_private *priv);
260 unsigned char is_sdio_init_complete(void);
261 unsigned char is_sdio_patch_complete(void);
262 int rda5890_sdio_init(struct rda5890_private *priv);
263 int rda5890_init_pm(struct rda5890_private *priv);
264 void rda5890_shedule_timeout(int msecs);
265 int rda5890_read_mac(char* buf);
266 int rda5890_write_mac(char * buf);
267 int rda5890_disable_block_bt(struct rda5890_private *priv);
268 int rda5890_disable_self_cts(struct rda5890_private *priv);
269 int rda5890_set_active_scan_time(struct rda5890_private *priv);
270 int rda5890_set_test_mode(struct rda5890_private *priv);
271 int rda5890_get_fw_version_polling(struct rda5890_private *priv, unsigned int* version);
272 #endif