treewide: remove duplicate includes
[firefly-linux-kernel-4.4.55.git] / drivers / staging / brcm80211 / brcmfmac / wl_cfg80211.h
1 /*
2  * Copyright (c) 2010 Broadcom Corporation
3  *
4  * Permission to use, copy, modify, and/or distribute this software for any
5  * purpose with or without fee is hereby granted, provided that the above
6  * copyright notice and this permission notice appear in all copies.
7  *
8  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
11  * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
13  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15  */
16
17 #ifndef _wl_cfg80211_h_
18 #define _wl_cfg80211_h_
19
20 #include <linux/wireless.h>
21 #include <net/cfg80211.h>
22 #include <wlioctl.h>
23
24 struct wl_conf;
25 struct wl_iface;
26 struct wl_priv;
27 struct wl_security;
28 struct wl_ibss;
29
30 #define WL_DBG_NONE             0
31 #define WL_DBG_CONN             (1 << 5)
32 #define WL_DBG_SCAN             (1 << 4)
33 #define WL_DBG_TRACE            (1 << 3)
34 #define WL_DBG_INFO             (1 << 1)
35 #define WL_DBG_ERR              (1 << 0)
36 #define WL_DBG_MASK             ((WL_DBG_INFO | WL_DBG_ERR | WL_DBG_TRACE) | \
37                                 (WL_DBG_SCAN) | (WL_DBG_CONN))
38
39 #define WL_ERR(fmt, args...)                                    \
40 do {                                                            \
41         if (wl_dbg_level & WL_DBG_ERR) {                        \
42                 if (net_ratelimit()) {                          \
43                         printk(KERN_ERR "ERROR @%s : " fmt,     \
44                                 __func__, ##args);              \
45                 }                                               \
46         }                                                       \
47 } while (0)
48
49 #if (defined BCMDBG)
50 #define WL_INFO(fmt, args...)                                   \
51 do {                                                            \
52         if (wl_dbg_level & WL_DBG_INFO) {                       \
53                 if (net_ratelimit()) {                          \
54                         printk(KERN_ERR "INFO @%s : " fmt,      \
55                                 __func__, ##args);              \
56                 }                                               \
57         }                                                       \
58 } while (0)
59
60 #define WL_TRACE(fmt, args...)                                  \
61 do {                                                            \
62         if (wl_dbg_level & WL_DBG_TRACE) {                      \
63                 if (net_ratelimit()) {                          \
64                         printk(KERN_ERR "TRACE @%s : " fmt,     \
65                                 __func__, ##args);              \
66                 }                                               \
67         }                                                       \
68 } while (0)
69
70 #define WL_SCAN(fmt, args...)                                   \
71 do {                                                            \
72         if (wl_dbg_level & WL_DBG_SCAN) {                       \
73                 if (net_ratelimit()) {                          \
74                         printk(KERN_ERR "SCAN @%s : " fmt,      \
75                                 __func__, ##args);              \
76                 }                                               \
77         }                                                       \
78 } while (0)
79
80 #define WL_CONN(fmt, args...)                                   \
81 do {                                                            \
82         if (wl_dbg_level & WL_DBG_CONN) {                       \
83                 if (net_ratelimit()) {                          \
84                         printk(KERN_ERR "CONN @%s : " fmt,      \
85                                 __func__, ##args);              \
86                 }                                               \
87         }                                                       \
88 } while (0)
89
90 #else /* (defined BCMDBG) */
91 #define WL_INFO(fmt, args...)
92 #define WL_TRACE(fmt, args...)
93 #define WL_SCAN(fmt, args...)
94 #define WL_CONN(fmt, args...)
95 #endif /* (defined BCMDBG) */
96
97
98 #define WL_SCAN_RETRY_MAX       3       /* used for ibss scan */
99 #define WL_NUM_SCAN_MAX         1
100 #define WL_NUM_PMKIDS_MAX       MAXPMKID        /* will be used
101                                                  * for 2.6.33 kernel
102                                                  * or later
103                                                  */
104 #define WL_SCAN_BUF_MAX                 (1024 * 8)
105 #define WL_TLV_INFO_MAX                 1024
106 #define WL_BSS_INFO_MAX                 2048
107 #define WL_ASSOC_INFO_MAX       512     /*
108                                  * needs to grab assoc info from dongle to
109                                  * report it to cfg80211 through "connect"
110                                  * event
111                                  */
112 #define WL_IOCTL_LEN_MAX        1024
113 #define WL_EXTRA_BUF_MAX        2048
114 #define WL_ISCAN_BUF_MAX        2048    /*
115                                  * the buf lengh can be WLC_IOCTL_MAXLEN (8K)
116                                  * to reduce iteration
117                                  */
118 #define WL_ISCAN_TIMER_INTERVAL_MS      3000
119 #define WL_SCAN_ERSULTS_LAST    (WL_SCAN_RESULTS_NO_MEM+1)
120 #define WL_AP_MAX       256     /* virtually unlimitted as long
121                                  * as kernel memory allows
122                                  */
123 #define WL_FILE_NAME_MAX                256
124
125 #define WL_ROAM_TRIGGER_LEVEL           -75
126 #define WL_ROAM_DELTA                   20
127 #define WL_BEACON_TIMEOUT               3
128
129 #define WL_SCAN_CHANNEL_TIME            40
130 #define WL_SCAN_UNASSOC_TIME            40
131 #define WL_SCAN_PASSIVE_TIME            120
132
133 /* dongle status */
134 enum wl_status {
135         WL_STATUS_READY,
136         WL_STATUS_SCANNING,
137         WL_STATUS_SCAN_ABORTING,
138         WL_STATUS_CONNECTING,
139         WL_STATUS_CONNECTED
140 };
141
142 /* wi-fi mode */
143 enum wl_mode {
144         WL_MODE_BSS,
145         WL_MODE_IBSS,
146         WL_MODE_AP
147 };
148
149 /* dongle profile list */
150 enum wl_prof_list {
151         WL_PROF_MODE,
152         WL_PROF_SSID,
153         WL_PROF_SEC,
154         WL_PROF_IBSS,
155         WL_PROF_BAND,
156         WL_PROF_BSSID,
157         WL_PROF_ACT,
158         WL_PROF_BEACONINT,
159         WL_PROF_DTIMPERIOD
160 };
161
162 /* dongle iscan state */
163 enum wl_iscan_state {
164         WL_ISCAN_STATE_IDLE,
165         WL_ISCAN_STATE_SCANING
166 };
167
168 /* fw downloading status */
169 enum wl_fw_status {
170         WL_FW_LOADING_DONE,
171         WL_NVRAM_LOADING_DONE
172 };
173
174 /* beacon / probe_response */
175 struct beacon_proberesp {
176         __le64 timestamp;
177         __le16 beacon_int;
178         __le16 capab_info;
179         u8 variable[0];
180 } __attribute__ ((packed));
181
182 /* dongle configuration */
183 struct wl_conf {
184         u32 mode;               /* adhoc , infrastructure or ap */
185         u32 frag_threshold;
186         u32 rts_threshold;
187         u32 retry_short;
188         u32 retry_long;
189         s32 tx_power;
190         struct ieee80211_channel channel;
191 };
192
193 /* cfg80211 main event loop */
194 struct wl_event_loop {
195         s32(*handler[WLC_E_LAST]) (struct wl_priv *wl,
196                                      struct net_device *ndev,
197                                      const wl_event_msg_t *e, void *data);
198 };
199
200 /* representing interface of cfg80211 plane */
201 struct wl_iface {
202         struct wl_priv *wl;
203 };
204
205 struct wl_dev {
206         void *driver_data;      /* to store cfg80211 object information */
207 };
208
209 /* bss inform structure for cfg80211 interface */
210 struct wl_cfg80211_bss_info {
211         u16 band;
212         u16 channel;
213         s16 rssi;
214         u16 frame_len;
215         u8 frame_buf[1];
216 };
217
218 /* basic structure of scan request */
219 struct wl_scan_req {
220         struct wlc_ssid ssid;
221 };
222
223 /* basic structure of information element */
224 struct wl_ie {
225         u16 offset;
226         u8 buf[WL_TLV_INFO_MAX];
227 };
228
229 /* event queue for cfg80211 main event */
230 struct wl_event_q {
231         struct list_head eq_list;
232         u32 etype;
233         wl_event_msg_t emsg;
234         s8 edata[1];
235 };
236
237 /* security information with currently associated ap */
238 struct wl_security {
239         u32 wpa_versions;
240         u32 auth_type;
241         u32 cipher_pairwise;
242         u32 cipher_group;
243         u32 wpa_auth;
244 };
245
246 /* ibss information for currently joined ibss network */
247 struct wl_ibss {
248         u8 beacon_interval;     /* in millisecond */
249         u8 atim;                /* in millisecond */
250         s8 join_only;
251         u8 band;
252         u8 channel;
253 };
254
255 /* dongle profile */
256 struct wl_profile {
257         u32 mode;
258         struct wlc_ssid ssid;
259         u8 bssid[ETH_ALEN];
260         u16 beacon_interval;
261         u8 dtim_period;
262         struct wl_security sec;
263         struct wl_ibss ibss;
264         s32 band;
265 };
266
267 /* dongle iscan event loop */
268 struct wl_iscan_eloop {
269         s32(*handler[WL_SCAN_ERSULTS_LAST]) (struct wl_priv *wl);
270 };
271
272 /* dongle iscan controller */
273 struct wl_iscan_ctrl {
274         struct net_device *dev;
275         struct timer_list timer;
276         u32 timer_ms;
277         u32 timer_on;
278         s32 state;
279         struct task_struct *tsk;
280         struct semaphore sync;
281         struct wl_iscan_eloop el;
282         void *data;
283         s8 ioctl_buf[WLC_IOCTL_SMLEN];
284         s8 scan_buf[WL_ISCAN_BUF_MAX];
285 };
286
287 /* association inform */
288 struct wl_connect_info {
289         u8 *req_ie;
290         s32 req_ie_len;
291         u8 *resp_ie;
292         s32 resp_ie_len;
293 };
294
295 /* firmware /nvram downloading controller */
296 struct wl_fw_ctrl {
297         const struct firmware *fw_entry;
298         unsigned long status;
299         u32 ptr;
300         s8 fw_name[WL_FILE_NAME_MAX];
301         s8 nvram_name[WL_FILE_NAME_MAX];
302 };
303
304 /* assoc ie length */
305 struct wl_assoc_ielen {
306         u32 req_len;
307         u32 resp_len;
308 };
309
310 /* wpa2 pmk list */
311 struct wl_pmk_list {
312         pmkid_list_t pmkids;
313         pmkid_t foo[MAXPMKID - 1];
314 };
315
316 /* dongle private data of cfg80211 interface */
317 struct wl_priv {
318         struct wireless_dev *wdev;      /* representing wl cfg80211 device */
319         struct wl_conf *conf;   /* dongle configuration */
320         struct cfg80211_scan_request *scan_request;     /* scan request
321                                                          object */
322         struct wl_event_loop el;        /* main event loop */
323         struct list_head eq_list;       /* used for event queue */
324         spinlock_t eq_lock;     /* for event queue synchronization */
325         struct mutex usr_sync;  /* maily for dongle up/down synchronization */
326         struct wl_scan_results *bss_list;       /* bss_list holding scanned
327                                                  ap information */
328         struct wl_scan_results *scan_results;
329         struct wl_scan_req *scan_req_int;       /* scan request object for
330                                                  internal purpose */
331         struct wl_cfg80211_bss_info *bss_info;  /* bss information for
332                                                  cfg80211 layer */
333         struct wl_ie ie;        /* information element object for
334                                          internal purpose */
335         struct semaphore event_sync;    /* for synchronization of main event
336                                          thread */
337         struct wl_profile *profile;     /* holding dongle profile */
338         struct wl_iscan_ctrl *iscan;    /* iscan controller */
339         struct wl_connect_info conn_info;       /* association information
340                                                  container */
341         struct wl_fw_ctrl *fw;  /* control firwmare / nvram paramter
342                                  downloading */
343         struct wl_pmk_list *pmk_list;   /* wpa2 pmk list */
344         struct task_struct *event_tsk;  /* task of main event handler thread */
345         unsigned long status;           /* current dongle status */
346         void *pub;
347         u32 channel;            /* current channel */
348         bool iscan_on;          /* iscan on/off switch */
349         bool iscan_kickstart;   /* indicate iscan already started */
350         bool active_scan;       /* current scan mode */
351         bool ibss_starter;      /* indicates this sta is ibss starter */
352         bool link_up;           /* link/connection up flag */
353         bool pwr_save;          /* indicate whether dongle to support
354                                          power save mode */
355         bool dongle_up;         /* indicate whether dongle up or not */
356         bool roam_on;           /* on/off switch for dongle self-roaming */
357         bool scan_tried;        /* indicates if first scan attempted */
358         u8 *ioctl_buf;  /* ioctl buffer */
359         u8 *extra_buf;  /* maily to grab assoc information */
360         struct dentry *debugfsdir;
361         u8 ci[0] __attribute__ ((__aligned__(NETDEV_ALIGN)));
362 };
363
364 #define wl_to_dev(w) (wiphy_dev(wl->wdev->wiphy))
365 #define wl_to_wiphy(w) (w->wdev->wiphy)
366 #define wiphy_to_wl(w) ((struct wl_priv *)(wiphy_priv(w)))
367 #define wl_to_wdev(w) (w->wdev)
368 #define wdev_to_wl(w) ((struct wl_priv *)(wdev_priv(w)))
369 #define wl_to_ndev(w) (w->wdev->netdev)
370 #define ndev_to_wl(n) (wdev_to_wl(n->ieee80211_ptr))
371 #define ci_to_wl(c) (ci->wl)
372 #define wl_to_ci(w) (&w->ci)
373 #define wl_to_sr(w) (w->scan_req_int)
374 #define wl_to_ie(w) (&w->ie)
375 #define iscan_to_wl(i) ((struct wl_priv *)(i->data))
376 #define wl_to_iscan(w) (w->iscan)
377 #define wl_to_conn(w) (&w->conn_info)
378
379 static inline struct wl_bss_info *next_bss(struct wl_scan_results *list,
380                                            struct wl_bss_info *bss)
381 {
382         return bss = bss ?
383                 (struct wl_bss_info *)((unsigned long)bss +
384                                        le32_to_cpu(bss->length)) :
385                 list->bss_info;
386 }
387
388 #define for_each_bss(list, bss, __i)    \
389         for (__i = 0; __i < list->count && __i < WL_AP_MAX; __i++, bss = next_bss(list, bss))
390
391 extern s32 wl_cfg80211_attach(struct net_device *ndev, void *data);
392 extern void wl_cfg80211_detach(void);
393 /* event handler from dongle */
394 extern void wl_cfg80211_event(struct net_device *ndev, const wl_event_msg_t *e,
395                               void *data);
396 extern void wl_cfg80211_sdio_func(void *func);  /* set sdio function info */
397 extern struct sdio_func *wl_cfg80211_get_sdio_func(void);       /* set sdio function info */
398 extern s32 wl_cfg80211_up(void);        /* dongle up */
399 extern s32 wl_cfg80211_down(void);      /* dongle down */
400 extern void wl_cfg80211_dbg_level(u32 level);   /* set dongle
401                                                          debugging level */
402 extern void *wl_cfg80211_request_fw(s8 *file_name);     /* request fw /nvram
403                                                          downloading */
404 extern s32 wl_cfg80211_read_fw(s8 *buf, u32 size);      /* read fw
405                                                                  image */
406 extern void wl_cfg80211_release_fw(void);       /* release fw */
407 extern s8 *wl_cfg80211_get_fwname(void);        /* get firmware name for
408                                                  the dongle */
409 extern s8 *wl_cfg80211_get_nvramname(void);     /* get nvram name for
410                                                  the dongle */
411 extern void wl_os_wd_timer(struct net_device *ndev, uint wdtick);
412
413 #endif                          /* _wl_cfg80211_h_ */