ba3c1fafcc603d4236d3ebf4ad698f2cdd194727
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / net / wireless / sc2331 / wlan_common.h
1 #ifndef SPRD_WLAN_COMMON_H_
2 #define SPRD_WLAN_COMMON_H_
3
4 #include <linux/proc_fs.h>
5 #include <linux/sipc.h>
6 #include <linux/mutex.h>
7 #include <linux/spinlock.h>
8 #include <linux/ieee80211.h>
9 #include <linux/printk.h>
10 #include <linux/inetdevice.h>
11 #include <linux/spinlock.h>
12 #include <net/cfg80211.h>
13 #include <linux/kernel.h>
14 #include <linux/errno.h>
15 #include <linux/module.h>
16 #include <linux/netdevice.h>
17 #include <linux/skbuff.h>
18 #include <net/ieee80211_radiotap.h>
19 #include <linux/etherdevice.h>
20 #include <linux/wireless.h>
21 #include <net/iw_handler.h>
22 #include <linux/string.h>
23 #include <linux/delay.h>
24 #include <linux/interrupt.h>
25 #include <linux/init.h>
26 #include <linux/wakelock.h>
27 #include <linux/workqueue.h>
28 #include <linux/ipv6.h>
29 #include <linux/ip.h>
30 #include <linux/inetdevice.h>
31 #include <asm/byteorder.h>
32 #include <linux/platform_device.h>
33 #include <linux/atomic.h>
34 #include <linux/wait.h>
35 #include <linux/semaphore.h>
36 #include <linux/vmalloc.h>
37 #include <linux/kthread.h>
38 #include <linux/time.h>
39 #include <linux/delay.h>
40 #include <linux/timer.h>
41 #include <linux/completion.h>
42 #include <asm/atomic.h>
43 #include <linux/ieee80211.h>
44 #include <linux/delay.h>
45 #include <linux/wakelock.h>
46 #include <linux/earlysuspend.h>
47 #include <mach/gpio.h>
48 #include <linux/of.h>
49 #include <linux/of_gpio.h>
50 #include "wlan_fifo.h"
51 #include "wlan_cmd.h"
52 #include "wlan_cfg80211.h"
53 #include "wlan_msg_q.h"
54 #include <linux/fb.h>
55
56 /* #define WLAN_LESS_WAKEUP_CP */
57 #define WLAN_THREAD_SLEPP_POLICE
58 #define WIFI_DRV_WAPI
59
60 #define INCR_RING_BUFF_INDX(indx, max_num)   ((((indx) + 1) < (max_num)) ? ((indx) + 1) : (0))
61 #define KERNEL_VERSION(a, b, c)              (((a) << 16) + ((b) << 8) + (c))
62 #define LINUX_VERSION_CODE                   KERNEL_VERSION(3, 10, 0)
63 #define SDIO_ALIGN_SIZE                      (1024)
64 #define ALIGN_4BYTE(a)                       ((((a)+3)&(~3)))
65 #define MAX_TX_BUFFER_ID                     (12)
66 #define TEST_BIT(a, k)                       ((a>>k)&1)
67 #define CLEAR_BIT(a, k)                      ({a = (a&(~(1<<k))); 0; })
68 #define SET_BIT(a, k)                        ({a = (a | (1<<k)); 0; })
69 #define WLAN_SYSTEM_DBG                      TEST_BIT(g_dbg, 1)
70 #define WLAN_PATH_DBG                        TEST_BIT(g_dbg, 2)
71 #define WLAN_HEX_DBG                         TEST_BIT(g_dbg, 3)
72 #define ETH_PCAP                             TEST_BIT(g_dbg, 4)
73 #define MAC_PCAP                             TEST_BIT(g_dbg, 5)
74 #define ETH_ALEN                                     (6)
75 #define SIOGETSSID                           (0x89F2)
76
77 /* HW_TX_SIZE, HW_RX_SIZE and PKT_AGGR_NUM must keep pace with CP
78  * TX: CP discrp number 38, use 3 blocks, 13k per block
79  * PKT_AGGR_NUM 12 = 38 / 3
80  */
81 #define OK                                   (0)
82 #define ERROR                                (-1)
83 #define HW_TX_SIZE                           (13312)
84 #define HW_RX_SIZE                           (12288)
85 #define PKT_AGGR_NUM                         (12)
86 #define MAX_TCP_SESSION                      (10)
87
88 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(3, 10, 0))
89 #define KERNEL_DEBUG_LEVE     "\001" "0"
90 #else
91 #define KERNEL_DEBUG_LEVE       "<0>"
92 #endif
93
94 #define printkd(fmt, ...)     ({if (WLAN_SYSTEM_DBG)printk("[SC2331]" fmt, ##__VA_ARGS__); 0; })
95 #define printkp(fmt, ...)     ({if (WLAN_PATH_DBG)printk("[SC2331]" fmt, ##__VA_ARGS__); 0; })
96 #define printke(fmt, ...)     ({printk(KERNEL_DEBUG_LEVE "[SC2331]" fmt, ##__VA_ARGS__); 0; })
97 #define ASSERT(fmt, ...)      ({printk(KERNEL_DEBUG_LEVE  "[SC2331][ASSERT][%s][%d]" fmt "\n", __func__, __LINE__,  ##__VA_ARGS__); 0; })
98
99 #define MACSTR "%02x:%02x:%02x:%02x:%02x:%02x"
100 #define MAC2STR(a) ((a)[0], (a)[1], (a)[2], (a)[3], (a)[4], (a)[5])
101
102 typedef struct {
103         unsigned char chn[16];
104         unsigned char num;
105         unsigned short bit_map;
106         spinlock_t lock;
107         int gpio_high;
108         int chn_timeout_cnt;
109         unsigned long timeout;
110         unsigned long timeout_time;
111         bool timeout_flag;
112 } sdio_chn_t;
113
114 typedef enum {
115         EVENT_Q_ID_0 = 0,
116         EVENT_Q_ID_1 = 1,
117         EVENT_Q_ID_2 = 2,
118         EVENT_Q_ID_3 = 3,
119         EVENT_Q_ID_4 = 4,
120         EVENT_Q_MAX_ID = 5,
121 } EVENT_Q_ID_T;
122
123 typedef enum {
124         NETIF_0_ID = 0,
125         NETIF_1_ID = 1,
126         WLAN_MAX_ID = 2,
127 } NETIF_ID_T;
128
129 typedef struct {
130         int exit;
131         struct semaphore sem;
132         int drv_status;
133         int cp2_status;
134 } drv_sync_t;
135
136 typedef struct {
137         sdio_chn_t sdio_tx_chn;
138         sdio_chn_t sdio_rx_chn;
139         unsigned int tx_cnt;
140         unsigned int rx_cnt;
141         unsigned int rx_record;
142         struct wake_lock wlan_lock;
143         struct early_suspend early_suspend;
144         int wakeup;
145         struct timer_list wakeup_timer;
146         unsigned long wakeup_time;
147         int can_sleep;
148         u32 rx_gpio;
149         int suspend;
150         int is_timer_set;
151 } hw_info_t;
152
153 typedef struct {
154         struct task_struct *task;
155         struct semaphore sem;
156         int null_run;
157         int max_null_run;
158         int idle_sleep;
159         int prio;
160         unsigned int need_tx;
161         unsigned int done_tx;
162         unsigned int need_rx;
163         unsigned int done_rx;
164         atomic_t retry;
165         /*exit_status: 0 --not exit; 1--already exit. */
166         atomic_t exit_status;
167         int exit_flag;
168 } wlan_thread_t;
169
170 typedef struct {
171         unsigned char mac[ETH_ALEN];
172         unsigned char netif_id;
173         unsigned char prio;
174         unsigned char wmm_supp;
175         unsigned char status;
176 } net_connect_dev_t;
177
178 typedef struct {
179         wait_queue_head_t waitQ;
180         int wakeup;
181         struct mutex cmd_lock;
182         struct mutex mem_lock;
183         unsigned char *mem;
184         atomic_t refcnt;
185 } wlan_cmd_t;
186
187 typedef struct {
188         struct work_struct work;
189         unsigned short frame_type;
190         bool reg;
191         void *vif;
192 } register_frame_param_t;
193
194 typedef struct {
195 #ifdef CONFIG_HAS_WAKELOCK
196         struct wake_lock scan_done_lock;
197 #endif
198         atomic_t scan_status;
199         struct cfg80211_scan_request *scan_request;
200         struct timer_list scan_timeout;
201         int connect_status;
202         int ssid_len;
203         unsigned char ssid[IEEE80211_MAX_SSID_LEN];
204         unsigned char bssid[ETH_ALEN];
205         unsigned char cipher_type;
206         unsigned char key_index[2];
207         unsigned char key[2][4][WLAN_MAX_KEY_LEN];
208         unsigned char key_len[2][4];
209         unsigned char key_txrsc[2][WLAN_MAX_KEY_LEN];
210         unsigned char *scan_frame_array;
211         int p2p_mode;
212         register_frame_param_t register_frame;
213 } wlan_cfg80211_t;
214
215 /* Best not to use the work to send deauth cmd
216  * FIXME in the future
217  */
218 struct deauth_info {
219         struct work_struct work;
220         /* 60 length is enough, maybe FIXME */
221         unsigned char mac[60];
222         unsigned short len;
223 };
224
225 typedef struct {
226         int tid;
227         int active;
228         unsigned int data_seq;
229         unsigned int ack_seq;
230         struct timeval data_time;
231         struct timeval ack_time;
232         msg_q_t msg_q;
233 } wlan_tcp_session_t;
234
235 typedef struct {
236         struct net_device *ndev;
237         struct wireless_dev wdev;
238         unsigned short id;
239         unsigned char mac[ETH_ALEN];
240         u8 beacon_loss;
241         int mode;
242         wlan_cfg80211_t cfg80211;
243         net_connect_dev_t connect_dev[8];
244         struct deauth_info deauth_info;
245         txfifo_t txfifo;
246         msg_q_t msg_q[2];
247         bool tcp_ack_suppress;
248         wlan_tcp_session_t tcp_session[MAX_TCP_SESSION];
249         struct wlan_cmd_hidden_ssid hssid;
250 } wlan_vif_t;
251
252 typedef struct {
253         int version;
254         struct wiphy *wiphy;
255         struct device *dev;
256         wlan_thread_t wlan_core;
257         wlan_thread_t wlan_trans;
258         hw_info_t hw;
259         wlan_cmd_t cmd;
260         drv_sync_t sync;
261         wlan_vif_t netif[2];
262         rxfifo_t rxfifo;
263 } wlan_info_t;
264
265 extern void core_down(void);
266 extern void core_up(void);
267 extern void trans_down(void);
268 extern void trans_up(void);
269 extern void up_wlan_rx_trans(void);
270 extern int wlan_module_init(struct device *dev);
271 extern int wlan_module_exit(struct device *dev);
272 extern int hex_dump(unsigned char *name, unsigned short nLen,
273                     unsigned char *pData, unsigned short len);
274 extern void init_register_frame_param(wlan_vif_t *vif);
275 extern void init_send_deauth_work(wlan_vif_t *vif);
276 extern wlan_vif_t *ndev_to_vif(struct net_device *ndev);
277 extern wlan_vif_t *id_to_vif(unsigned char id);
278 extern int hostap_conf_load(char *filename, unsigned char *key_val);
279 extern int mac_addr_cfg(wlan_vif_t *vif, unsigned char vif_id);
280 extern int wlan_vif_init(wlan_vif_t *vif, int type, const char *name,
281                          void *ops);
282 extern int wlan_wiphy_new(wlan_info_t *wlan);
283 extern int wlan_vif_free(wlan_vif_t *vif);
284 extern int wlan_wiphy_free(wlan_info_t *wlan);
285 extern void wlan_nl_init(void);
286 extern void wlan_nl_deinit(void);
287
288 extern bool get_sdiohal_status(void);
289 extern int sdio_chn_status(unsigned short chn, unsigned short *status);
290 extern int sdio_dev_read(unsigned int chn, void *read_buf, unsigned int *count);
291 extern int sdio_dev_write(unsigned int chn, void *data_buf, unsigned int count);
292 extern int sdiodev_readchn_init(int chn, void *callback, bool with_para);
293 extern int sdio_read_wlan(unsigned int chn, void *read_buf,
294                           unsigned int *count);
295 extern int sdiodev_readchn_uninit(unsigned int chn);
296 extern void mdbg_at_cmd_read(void);
297 extern void mdbg_loopcheck_read(void);
298 extern void mdbg_assert_read(void);
299
300 extern void mdbg_sdio_read(void);
301 extern void marlin_pa_enable(bool enable);
302 extern int set_wlan_status(int status);
303 extern int set_marlin_wakeup(unsigned int chn, unsigned int user_id);
304 extern int set_marlin_sleep(unsigned int chn, unsigned int user_id);
305 extern char *get_cmd_name(int id);
306 extern unsigned int g_dbg;
307 extern wlan_info_t g_wlan;
308 extern msg_q_t *wlan_tcpack_q(wlan_vif_t *vif, unsigned char *frame,
309                               unsigned int len);
310 extern int wlan_tcpack_tx(wlan_vif_t *vif, int *done);
311 extern int wlan_tcpack_buf_malloc(wlan_vif_t *vif);
312 extern int wlan_tcpack_buf_free(wlan_vif_t *vif);
313 extern int wlan_rx_buf_decode(unsigned char *buf, unsigned int max_len);
314 extern int wlan_tx_buf_decode(unsigned char *buf, unsigned int max_len);
315 extern void seq_point(unsigned char *frame, unsigned int len);
316 extern void ack_timeout_point(unsigned char *frame, unsigned int len);
317 extern void tcp_session_cfg(int cmd, int value);
318 #endif