Merge branch 'for-3.7' of git://git.infradead.org/users/dedekind/l2-mtd
[cascardo/linux.git] / drivers / net / wireless / mwifiex / main.h
1 /*
2  * Marvell Wireless LAN device driver: major data structures and prototypes
3  *
4  * Copyright (C) 2011, Marvell International Ltd.
5  *
6  * This software file (the "File") is distributed by Marvell International
7  * Ltd. under the terms of the GNU General Public License Version 2, June 1991
8  * (the "License").  You may use, redistribute and/or modify this File in
9  * accordance with the terms and conditions of the License, a copy of which
10  * is available by writing to the Free Software Foundation, Inc.,
11  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA or on the
12  * worldwide web at http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
13  *
14  * THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE
15  * IMPLIED WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE
16  * ARE EXPRESSLY DISCLAIMED.  The License provides additional details about
17  * this warranty disclaimer.
18  */
19
20 #ifndef _MWIFIEX_MAIN_H_
21 #define _MWIFIEX_MAIN_H_
22
23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/sched.h>
26 #include <linux/semaphore.h>
27 #include <linux/ip.h>
28 #include <linux/skbuff.h>
29 #include <linux/if_arp.h>
30 #include <linux/etherdevice.h>
31 #include <net/sock.h>
32 #include <net/lib80211.h>
33 #include <linux/firmware.h>
34 #include <linux/ctype.h>
35
36 #include "decl.h"
37 #include "ioctl.h"
38 #include "util.h"
39 #include "fw.h"
40 #include "pcie.h"
41
42 extern const char driver_version[];
43
44 enum {
45         MWIFIEX_ASYNC_CMD,
46         MWIFIEX_SYNC_CMD
47 };
48
49 #define MWIFIEX_MAX_AP                          64
50
51 #define MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT        (5 * HZ)
52
53 #define MWIFIEX_TIMER_10S                       10000
54 #define MWIFIEX_TIMER_1S                        1000
55
56 #define MAX_TX_PENDING      100
57 #define LOW_TX_PENDING      80
58
59 #define MWIFIEX_UPLD_SIZE               (2312)
60
61 #define MAX_EVENT_SIZE                  1024
62
63 #define ARP_FILTER_MAX_BUF_SIZE         68
64
65 #define MWIFIEX_KEY_BUFFER_SIZE                 16
66 #define MWIFIEX_DEFAULT_LISTEN_INTERVAL 10
67 #define MWIFIEX_MAX_REGION_CODE         7
68
69 #define DEFAULT_BCN_AVG_FACTOR          8
70 #define DEFAULT_DATA_AVG_FACTOR         8
71
72 #define FIRST_VALID_CHANNEL                             0xff
73 #define DEFAULT_AD_HOC_CHANNEL                  6
74 #define DEFAULT_AD_HOC_CHANNEL_A                36
75
76 #define DEFAULT_BCN_MISS_TIMEOUT                5
77
78 #define MAX_SCAN_BEACON_BUFFER                  8000
79
80 #define SCAN_BEACON_ENTRY_PAD                   6
81
82 #define MWIFIEX_PASSIVE_SCAN_CHAN_TIME  110
83 #define MWIFIEX_ACTIVE_SCAN_CHAN_TIME   30
84 #define MWIFIEX_SPECIFIC_SCAN_CHAN_TIME 30
85
86 #define SCAN_RSSI(RSSI)                                 (0x100 - ((u8)(RSSI)))
87
88 #define MWIFIEX_MAX_TOTAL_SCAN_TIME     (MWIFIEX_TIMER_10S - MWIFIEX_TIMER_1S)
89
90 #define MWIFIEX_MAX_SCAN_DELAY_CNT                      50
91 #define MWIFIEX_MAX_EMPTY_TX_Q_CNT                      10
92 #define MWIFIEX_SCAN_DELAY_MSEC                         20
93
94 #define MWIFIEX_MIN_TX_PENDING_TO_CANCEL_SCAN           2
95
96 #define RSN_GTK_OUI_OFFSET                              2
97
98 #define MWIFIEX_OUI_NOT_PRESENT                 0
99 #define MWIFIEX_OUI_PRESENT                             1
100
101 #define PKT_TYPE_MGMT   0xE5
102
103 /*
104  * Do not check for data_received for USB, as data_received
105  * is handled in mwifiex_usb_recv for USB
106  */
107 #define IS_CARD_RX_RCVD(adapter) (adapter->cmd_resp_received || \
108                                 adapter->event_received || \
109                                 ((adapter->iface_type != MWIFIEX_USB) && \
110                                 adapter->data_received) || \
111                                 ((adapter->iface_type == MWIFIEX_USB) && \
112                                 !skb_queue_empty(&adapter->usb_rx_data_q)))
113
114 #define MWIFIEX_TYPE_CMD                                1
115 #define MWIFIEX_TYPE_DATA                               0
116 #define MWIFIEX_TYPE_EVENT                              3
117
118 #define DBG_CMD_NUM                                             5
119
120 #define MAX_BITMAP_RATES_SIZE                   10
121
122 #define MAX_CHANNEL_BAND_BG     14
123 #define MAX_CHANNEL_BAND_A      165
124
125 #define MAX_FREQUENCY_BAND_BG   2484
126
127 #define MWIFIEX_EVENT_HEADER_LEN           4
128 #define MWIFIEX_UAP_EVENT_EXTRA_HEADER     2
129
130 #define MWIFIEX_TYPE_LEN                        4
131 #define MWIFIEX_USB_TYPE_CMD                    0xF00DFACE
132 #define MWIFIEX_USB_TYPE_DATA                   0xBEADC0DE
133 #define MWIFIEX_USB_TYPE_EVENT                  0xBEEFFACE
134
135 struct mwifiex_dbg {
136         u32 num_cmd_host_to_card_failure;
137         u32 num_cmd_sleep_cfm_host_to_card_failure;
138         u32 num_tx_host_to_card_failure;
139         u32 num_event_deauth;
140         u32 num_event_disassoc;
141         u32 num_event_link_lost;
142         u32 num_cmd_deauth;
143         u32 num_cmd_assoc_success;
144         u32 num_cmd_assoc_failure;
145         u32 num_tx_timeout;
146         u32 num_cmd_timeout;
147         u16 timeout_cmd_id;
148         u16 timeout_cmd_act;
149         u16 last_cmd_id[DBG_CMD_NUM];
150         u16 last_cmd_act[DBG_CMD_NUM];
151         u16 last_cmd_index;
152         u16 last_cmd_resp_id[DBG_CMD_NUM];
153         u16 last_cmd_resp_index;
154         u16 last_event[DBG_CMD_NUM];
155         u16 last_event_index;
156 };
157
158 enum MWIFIEX_HARDWARE_STATUS {
159         MWIFIEX_HW_STATUS_READY,
160         MWIFIEX_HW_STATUS_INITIALIZING,
161         MWIFIEX_HW_STATUS_FW_READY,
162         MWIFIEX_HW_STATUS_INIT_DONE,
163         MWIFIEX_HW_STATUS_RESET,
164         MWIFIEX_HW_STATUS_CLOSING,
165         MWIFIEX_HW_STATUS_NOT_READY
166 };
167
168 enum MWIFIEX_802_11_POWER_MODE {
169         MWIFIEX_802_11_POWER_MODE_CAM,
170         MWIFIEX_802_11_POWER_MODE_PSP
171 };
172
173 struct mwifiex_tx_param {
174         u32 next_pkt_len;
175 };
176
177 enum MWIFIEX_PS_STATE {
178         PS_STATE_AWAKE,
179         PS_STATE_PRE_SLEEP,
180         PS_STATE_SLEEP_CFM,
181         PS_STATE_SLEEP
182 };
183
184 enum mwifiex_iface_type {
185         MWIFIEX_SDIO,
186         MWIFIEX_PCIE,
187         MWIFIEX_USB
188 };
189
190 struct mwifiex_add_ba_param {
191         u32 tx_win_size;
192         u32 rx_win_size;
193         u32 timeout;
194 };
195
196 struct mwifiex_tx_aggr {
197         u8 ampdu_user;
198         u8 ampdu_ap;
199         u8 amsdu;
200 };
201
202 struct mwifiex_ra_list_tbl {
203         struct list_head list;
204         struct sk_buff_head skb_head;
205         u8 ra[ETH_ALEN];
206         u32 total_pkts_size;
207         u32 is_11n_enabled;
208         u16 max_amsdu;
209         u16 pkt_count;
210         u8 ba_packet_thr;
211 };
212
213 struct mwifiex_tid_tbl {
214         struct list_head ra_list;
215         /* spin lock for tid table */
216         spinlock_t tid_tbl_lock;
217         struct mwifiex_ra_list_tbl *ra_list_curr;
218 };
219
220 #define WMM_HIGHEST_PRIORITY            7
221 #define HIGH_PRIO_TID                           7
222 #define LOW_PRIO_TID                            0
223 #define NO_PKT_PRIO_TID                         (-1)
224
225 struct mwifiex_wmm_desc {
226         struct mwifiex_tid_tbl tid_tbl_ptr[MAX_NUM_TID];
227         u32 packets_out[MAX_NUM_TID];
228         /* spin lock to protect ra_list */
229         spinlock_t ra_list_spinlock;
230         struct mwifiex_wmm_ac_status ac_status[IEEE80211_NUM_ACS];
231         enum mwifiex_wmm_ac_e ac_down_graded_vals[IEEE80211_NUM_ACS];
232         u32 drv_pkt_delay_max;
233         u8 queue_priority[IEEE80211_NUM_ACS];
234         u32 user_pri_pkt_tx_ctrl[WMM_HIGHEST_PRIORITY + 1];     /* UP: 0 to 7 */
235         /* Number of transmit packets queued */
236         atomic_t tx_pkts_queued;
237         /* Tracks highest priority with a packet queued */
238         atomic_t highest_queued_prio;
239 };
240
241 struct mwifiex_802_11_security {
242         u8 wpa_enabled;
243         u8 wpa2_enabled;
244         u8 wapi_enabled;
245         u8 wapi_key_on;
246         u8 wep_enabled;
247         u32 authentication_mode;
248         u8 is_authtype_auto;
249         u32 encryption_mode;
250 };
251
252 struct ieee_types_header {
253         u8 element_id;
254         u8 len;
255 } __packed;
256
257 struct ieee_types_vendor_specific {
258         struct ieee_types_vendor_header vend_hdr;
259         u8 data[IEEE_MAX_IE_SIZE - sizeof(struct ieee_types_vendor_header)];
260 } __packed;
261
262 struct ieee_types_generic {
263         struct ieee_types_header ieee_hdr;
264         u8 data[IEEE_MAX_IE_SIZE - sizeof(struct ieee_types_header)];
265 } __packed;
266
267 struct mwifiex_bssdescriptor {
268         u8 mac_address[ETH_ALEN];
269         struct cfg80211_ssid ssid;
270         u32 privacy;
271         s32 rssi;
272         u32 channel;
273         u32 freq;
274         u16 beacon_period;
275         u8 erp_flags;
276         u32 bss_mode;
277         u8 supported_rates[MWIFIEX_SUPPORTED_RATES];
278         u8 data_rates[MWIFIEX_SUPPORTED_RATES];
279         /* Network band.
280          * BAND_B(0x01): 'b' band
281          * BAND_G(0x02): 'g' band
282          * BAND_A(0X04): 'a' band
283          */
284         u16 bss_band;
285         u64 fw_tsf;
286         u64 timestamp;
287         union ieee_types_phy_param_set phy_param_set;
288         union ieee_types_ss_param_set ss_param_set;
289         u16 cap_info_bitmap;
290         struct ieee_types_wmm_parameter wmm_ie;
291         u8  disable_11n;
292         struct ieee80211_ht_cap *bcn_ht_cap;
293         u16 ht_cap_offset;
294         struct ieee80211_ht_operation *bcn_ht_oper;
295         u16 ht_info_offset;
296         u8 *bcn_bss_co_2040;
297         u16 bss_co_2040_offset;
298         u8 *bcn_ext_cap;
299         u16 ext_cap_offset;
300         struct ieee_types_vendor_specific *bcn_wpa_ie;
301         u16 wpa_offset;
302         struct ieee_types_generic *bcn_rsn_ie;
303         u16 rsn_offset;
304         struct ieee_types_generic *bcn_wapi_ie;
305         u16 wapi_offset;
306         u8 *beacon_buf;
307         u32 beacon_buf_size;
308 };
309
310 struct mwifiex_current_bss_params {
311         struct mwifiex_bssdescriptor bss_descriptor;
312         u8 wmm_enabled;
313         u8 wmm_uapsd_enabled;
314         u8 band;
315         u32 num_of_rates;
316         u8 data_rates[MWIFIEX_SUPPORTED_RATES];
317 };
318
319 struct mwifiex_sleep_params {
320         u16 sp_error;
321         u16 sp_offset;
322         u16 sp_stable_time;
323         u8 sp_cal_control;
324         u8 sp_ext_sleep_clk;
325         u16 sp_reserved;
326 };
327
328 struct mwifiex_sleep_period {
329         u16 period;
330         u16 reserved;
331 };
332
333 struct mwifiex_wep_key {
334         u32 length;
335         u32 key_index;
336         u32 key_length;
337         u8 key_material[MWIFIEX_KEY_BUFFER_SIZE];
338 };
339
340 #define MAX_REGION_CHANNEL_NUM  2
341
342 struct mwifiex_chan_freq_power {
343         u16 channel;
344         u32 freq;
345         u16 max_tx_power;
346         u8 unsupported;
347 };
348
349 enum state_11d_t {
350         DISABLE_11D = 0,
351         ENABLE_11D = 1,
352 };
353
354 #define MWIFIEX_MAX_TRIPLET_802_11D             83
355
356 struct mwifiex_802_11d_domain_reg {
357         u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
358         u8 no_of_triplet;
359         struct ieee80211_country_ie_triplet
360                 triplet[MWIFIEX_MAX_TRIPLET_802_11D];
361 };
362
363 struct mwifiex_vendor_spec_cfg_ie {
364         u16 mask;
365         u16 flag;
366         u8 ie[MWIFIEX_MAX_VSIE_LEN];
367 };
368
369 struct wps {
370         u8 session_enable;
371 };
372
373 struct mwifiex_roc_cfg {
374         u64 cookie;
375         struct ieee80211_channel chan;
376         enum nl80211_channel_type chan_type;
377 };
378
379 struct mwifiex_adapter;
380 struct mwifiex_private;
381
382 struct mwifiex_private {
383         struct mwifiex_adapter *adapter;
384         u8 bss_type;
385         u8 bss_role;
386         u8 bss_priority;
387         u8 bss_num;
388         u8 bss_started;
389         u8 frame_type;
390         u8 curr_addr[ETH_ALEN];
391         u8 media_connected;
392         u32 num_tx_timeout;
393         struct net_device *netdev;
394         struct net_device_stats stats;
395         u16 curr_pkt_filter;
396         u32 bss_mode;
397         u32 pkt_tx_ctrl;
398         u16 tx_power_level;
399         u8 max_tx_power_level;
400         u8 min_tx_power_level;
401         u8 tx_rate;
402         u8 tx_htinfo;
403         u8 rxpd_htinfo;
404         u8 rxpd_rate;
405         u16 rate_bitmap;
406         u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
407         u32 data_rate;
408         u8 is_data_rate_auto;
409         u16 bcn_avg_factor;
410         u16 data_avg_factor;
411         s16 data_rssi_last;
412         s16 data_nf_last;
413         s16 data_rssi_avg;
414         s16 data_nf_avg;
415         s16 bcn_rssi_last;
416         s16 bcn_nf_last;
417         s16 bcn_rssi_avg;
418         s16 bcn_nf_avg;
419         struct mwifiex_bssdescriptor *attempted_bss_desc;
420         struct cfg80211_ssid prev_ssid;
421         u8 prev_bssid[ETH_ALEN];
422         struct mwifiex_current_bss_params curr_bss_params;
423         u16 beacon_period;
424         u8 dtim_period;
425         u16 listen_interval;
426         u16 atim_window;
427         u8 adhoc_channel;
428         u8 adhoc_is_link_sensed;
429         u8 adhoc_state;
430         struct mwifiex_802_11_security sec_info;
431         struct mwifiex_wep_key wep_key[NUM_WEP_KEYS];
432         u16 wep_key_curr_index;
433         u8 wpa_ie[256];
434         u8 wpa_ie_len;
435         u8 wpa_is_gtk_set;
436         struct host_cmd_ds_802_11_key_material aes_key;
437         u8 wapi_ie[256];
438         u8 wapi_ie_len;
439         u8 *wps_ie;
440         u8 wps_ie_len;
441         u8 wmm_required;
442         u8 wmm_enabled;
443         u8 wmm_qosinfo;
444         struct mwifiex_wmm_desc wmm;
445         struct list_head sta_list;
446         /* spin lock for associated station list */
447         spinlock_t sta_list_spinlock;
448         struct list_head tx_ba_stream_tbl_ptr;
449         /* spin lock for tx_ba_stream_tbl_ptr queue */
450         spinlock_t tx_ba_stream_tbl_lock;
451         struct mwifiex_tx_aggr aggr_prio_tbl[MAX_NUM_TID];
452         struct mwifiex_add_ba_param add_ba_param;
453         u16 rx_seq[MAX_NUM_TID];
454         struct list_head rx_reorder_tbl_ptr;
455         /* spin lock for rx_reorder_tbl_ptr queue */
456         spinlock_t rx_reorder_tbl_lock;
457         /* spin lock for Rx packets */
458         spinlock_t rx_pkt_lock;
459
460 #define MWIFIEX_ASSOC_RSP_BUF_SIZE  500
461         u8 assoc_rsp_buf[MWIFIEX_ASSOC_RSP_BUF_SIZE];
462         u32 assoc_rsp_size;
463
464 #define MWIFIEX_GENIE_BUF_SIZE      256
465         u8 gen_ie_buf[MWIFIEX_GENIE_BUF_SIZE];
466         u8 gen_ie_buf_len;
467
468         struct mwifiex_vendor_spec_cfg_ie vs_ie[MWIFIEX_MAX_VSIE_NUM];
469
470 #define MWIFIEX_ASSOC_TLV_BUF_SIZE  256
471         u8 assoc_tlv_buf[MWIFIEX_ASSOC_TLV_BUF_SIZE];
472         u8 assoc_tlv_buf_len;
473
474         u8 *curr_bcn_buf;
475         u32 curr_bcn_size;
476         /* spin lock for beacon buffer */
477         spinlock_t curr_bcn_buf_lock;
478         struct wireless_dev *wdev;
479         struct mwifiex_chan_freq_power cfp;
480         char version_str[128];
481 #ifdef CONFIG_DEBUG_FS
482         struct dentry *dfs_dev_dir;
483 #endif
484         u8 nick_name[16];
485         u16 current_key_index;
486         struct semaphore async_sem;
487         u8 scan_pending_on_block;
488         u8 report_scan_result;
489         struct cfg80211_scan_request *scan_request;
490         struct mwifiex_user_scan_cfg *user_scan_cfg;
491         u8 cfg_bssid[6];
492         struct wps wps;
493         u8 scan_block;
494         s32 cqm_rssi_thold;
495         u32 cqm_rssi_hyst;
496         u8 subsc_evt_rssi_state;
497         struct mwifiex_ds_misc_subsc_evt async_subsc_evt_storage;
498         struct mwifiex_ie mgmt_ie[MAX_MGMT_IE_INDEX];
499         u16 beacon_idx;
500         u16 proberesp_idx;
501         u16 assocresp_idx;
502         u16 rsn_idx;
503         struct timer_list scan_delay_timer;
504         u8 ap_11n_enabled;
505         u32 mgmt_frame_mask;
506         struct mwifiex_roc_cfg roc_cfg;
507 };
508
509 enum mwifiex_ba_status {
510         BA_SETUP_NONE = 0,
511         BA_SETUP_INPROGRESS,
512         BA_SETUP_COMPLETE
513 };
514
515 struct mwifiex_tx_ba_stream_tbl {
516         struct list_head list;
517         int tid;
518         u8 ra[ETH_ALEN];
519         enum mwifiex_ba_status ba_status;
520 };
521
522 struct mwifiex_rx_reorder_tbl;
523
524 struct reorder_tmr_cnxt {
525         struct timer_list timer;
526         struct mwifiex_rx_reorder_tbl *ptr;
527         struct mwifiex_private *priv;
528 };
529
530 struct mwifiex_rx_reorder_tbl {
531         struct list_head list;
532         int tid;
533         u8 ta[ETH_ALEN];
534         int start_win;
535         int win_size;
536         void **rx_reorder_ptr;
537         struct reorder_tmr_cnxt timer_context;
538         u8 flags;
539 };
540
541 struct mwifiex_bss_prio_node {
542         struct list_head list;
543         struct mwifiex_private *priv;
544 };
545
546 struct mwifiex_bss_prio_tbl {
547         struct list_head bss_prio_head;
548         /* spin lock for bss priority  */
549         spinlock_t bss_prio_lock;
550         struct mwifiex_bss_prio_node *bss_prio_cur;
551 };
552
553 struct cmd_ctrl_node {
554         struct list_head list;
555         struct mwifiex_private *priv;
556         u32 cmd_oid;
557         u32 cmd_flag;
558         struct sk_buff *cmd_skb;
559         struct sk_buff *resp_skb;
560         void *data_buf;
561         u32 wait_q_enabled;
562         struct sk_buff *skb;
563         u8 *condition;
564         u8 cmd_wait_q_woken;
565 };
566
567 struct mwifiex_bss_priv {
568         u8 band;
569         u64 fw_tsf;
570 };
571
572 /* This is AP specific structure which stores information
573  * about associated STA
574  */
575 struct mwifiex_sta_node {
576         struct list_head list;
577         u8 mac_addr[ETH_ALEN];
578         u8 is_wmm_enabled;
579         u8 is_11n_enabled;
580         u8 ampdu_sta[MAX_NUM_TID];
581         u16 rx_seq[MAX_NUM_TID];
582         u16 max_amsdu;
583 };
584
585 struct mwifiex_if_ops {
586         int (*init_if) (struct mwifiex_adapter *);
587         void (*cleanup_if) (struct mwifiex_adapter *);
588         int (*check_fw_status) (struct mwifiex_adapter *, u32);
589         int (*prog_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
590         int (*register_dev) (struct mwifiex_adapter *);
591         void (*unregister_dev) (struct mwifiex_adapter *);
592         int (*enable_int) (struct mwifiex_adapter *);
593         int (*process_int_status) (struct mwifiex_adapter *);
594         int (*host_to_card) (struct mwifiex_adapter *, u8, struct sk_buff *,
595                              struct mwifiex_tx_param *);
596         int (*wakeup) (struct mwifiex_adapter *);
597         int (*wakeup_complete) (struct mwifiex_adapter *);
598
599         /* Interface specific functions */
600         void (*update_mp_end_port) (struct mwifiex_adapter *, u16);
601         void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
602         int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
603         int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
604         int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
605         int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
606 };
607
608 struct mwifiex_adapter {
609         u8 iface_type;
610         struct mwifiex_private *priv[MWIFIEX_MAX_BSS_NUM];
611         u8 priv_num;
612         const struct firmware *firmware;
613         char fw_name[32];
614         int winner;
615         struct device *dev;
616         struct wiphy *wiphy;
617         bool surprise_removed;
618         u32 fw_release_number;
619         u16 init_wait_q_woken;
620         wait_queue_head_t init_wait_q;
621         void *card;
622         struct mwifiex_if_ops if_ops;
623         atomic_t rx_pending;
624         atomic_t tx_pending;
625         atomic_t cmd_pending;
626         struct workqueue_struct *workqueue;
627         struct work_struct main_work;
628         struct mwifiex_bss_prio_tbl bss_prio_tbl[MWIFIEX_MAX_BSS_NUM];
629         /* spin lock for init/shutdown */
630         spinlock_t mwifiex_lock;
631         /* spin lock for main process */
632         spinlock_t main_proc_lock;
633         u32 mwifiex_processing;
634         u16 max_tx_buf_size;
635         u16 tx_buf_size;
636         u16 curr_tx_buf_size;
637         u32 ioport;
638         enum MWIFIEX_HARDWARE_STATUS hw_status;
639         u16 number_of_antenna;
640         u32 fw_cap_info;
641         /* spin lock for interrupt handling */
642         spinlock_t int_lock;
643         u8 int_status;
644         u32 event_cause;
645         struct sk_buff *event_skb;
646         u8 upld_buf[MWIFIEX_UPLD_SIZE];
647         u8 data_sent;
648         u8 cmd_sent;
649         u8 cmd_resp_received;
650         u8 event_received;
651         u8 data_received;
652         u16 seq_num;
653         struct cmd_ctrl_node *cmd_pool;
654         struct cmd_ctrl_node *curr_cmd;
655         /* spin lock for command */
656         spinlock_t mwifiex_cmd_lock;
657         u32 num_cmd_timeout;
658         u16 last_init_cmd;
659         struct timer_list cmd_timer;
660         struct list_head cmd_free_q;
661         /* spin lock for cmd_free_q */
662         spinlock_t cmd_free_q_lock;
663         struct list_head cmd_pending_q;
664         /* spin lock for cmd_pending_q */
665         spinlock_t cmd_pending_q_lock;
666         struct list_head scan_pending_q;
667         /* spin lock for scan_pending_q */
668         spinlock_t scan_pending_q_lock;
669         struct sk_buff_head usb_rx_data_q;
670         u32 scan_processing;
671         u16 region_code;
672         struct mwifiex_802_11d_domain_reg domain_reg;
673         u16 scan_probes;
674         u32 scan_mode;
675         u16 specific_scan_time;
676         u16 active_scan_time;
677         u16 passive_scan_time;
678         u8 fw_bands;
679         u8 adhoc_start_band;
680         u8 config_bands;
681         struct mwifiex_chan_scan_param_set *scan_channels;
682         u8 tx_lock_flag;
683         struct mwifiex_sleep_params sleep_params;
684         struct mwifiex_sleep_period sleep_period;
685         u16 ps_mode;
686         u32 ps_state;
687         u8 need_to_wakeup;
688         u16 multiple_dtim;
689         u16 local_listen_interval;
690         u16 null_pkt_interval;
691         struct sk_buff *sleep_cfm;
692         u16 bcn_miss_time_out;
693         u16 adhoc_awake_period;
694         u8 is_deep_sleep;
695         u8 delay_null_pkt;
696         u16 delay_to_ps;
697         u16 enhanced_ps_mode;
698         u8 pm_wakeup_card_req;
699         u16 gen_null_pkt;
700         u16 pps_uapsd_mode;
701         u32 pm_wakeup_fw_try;
702         u8 is_hs_configured;
703         struct mwifiex_hs_config_param hs_cfg;
704         u8 hs_activated;
705         u16 hs_activate_wait_q_woken;
706         wait_queue_head_t hs_activate_wait_q;
707         bool is_suspended;
708         u8 event_body[MAX_EVENT_SIZE];
709         u32 hw_dot_11n_dev_cap;
710         u8 hw_dev_mcs_support;
711         u8 adhoc_11n_enabled;
712         u8 sec_chan_offset;
713         struct mwifiex_dbg dbg;
714         u8 arp_filter[ARP_FILTER_MAX_BUF_SIZE];
715         u32 arp_filter_size;
716         u16 cmd_wait_q_required;
717         struct mwifiex_wait_queue cmd_wait_q;
718         u8 scan_wait_q_woken;
719         struct cmd_ctrl_node *cmd_queued;
720         spinlock_t queue_lock;          /* lock for tx queues */
721         struct completion fw_load;
722         u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
723         u16 max_mgmt_ie_index;
724         u8 scan_delay_cnt;
725         u8 empty_tx_q_cnt;
726         atomic_t is_tx_received;
727         atomic_t pending_bridged_pkts;
728 };
729
730 int mwifiex_init_lock_list(struct mwifiex_adapter *adapter);
731
732 void mwifiex_set_trans_start(struct net_device *dev);
733
734 void mwifiex_stop_net_dev_queue(struct net_device *netdev,
735                 struct mwifiex_adapter *adapter);
736
737 void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
738                 struct mwifiex_adapter *adapter);
739
740 int mwifiex_init_priv(struct mwifiex_private *priv);
741 void mwifiex_free_priv(struct mwifiex_private *priv);
742
743 int mwifiex_init_fw(struct mwifiex_adapter *adapter);
744
745 int mwifiex_init_fw_complete(struct mwifiex_adapter *adapter);
746
747 int mwifiex_shutdown_drv(struct mwifiex_adapter *adapter);
748
749 int mwifiex_shutdown_fw_complete(struct mwifiex_adapter *adapter);
750
751 int mwifiex_dnld_fw(struct mwifiex_adapter *, struct mwifiex_fw_image *);
752
753 int mwifiex_recv_packet(struct mwifiex_adapter *, struct sk_buff *skb);
754
755 int mwifiex_process_mgmt_packet(struct mwifiex_adapter *adapter,
756                                 struct sk_buff *skb);
757
758 int mwifiex_process_event(struct mwifiex_adapter *adapter);
759
760 int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
761                          struct cmd_ctrl_node *cmd_node);
762
763 int mwifiex_send_cmd_async(struct mwifiex_private *priv, uint16_t cmd_no,
764                            u16 cmd_action, u32 cmd_oid, void *data_buf);
765
766 int mwifiex_send_cmd_sync(struct mwifiex_private *priv, uint16_t cmd_no,
767                           u16 cmd_action, u32 cmd_oid, void *data_buf);
768
769 void mwifiex_cmd_timeout_func(unsigned long function_context);
770
771 int mwifiex_get_debug_info(struct mwifiex_private *,
772                            struct mwifiex_debug_info *);
773
774 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter);
775 int mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter);
776 void mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter);
777 void mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter);
778
779 void mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter,
780                                   struct cmd_ctrl_node *cmd_node);
781
782 void mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter,
783                                      struct cmd_ctrl_node *cmd_node,
784                                      u32 addtail);
785
786 int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter);
787 int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter);
788 int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
789                              struct sk_buff *skb);
790 int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
791                        struct mwifiex_tx_param *tx_param);
792 int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags);
793 int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
794                                 struct sk_buff *skb, int status);
795 void mwifiex_clean_txrx(struct mwifiex_private *priv);
796 u8 mwifiex_check_last_packet_indication(struct mwifiex_private *priv);
797 void mwifiex_check_ps_cond(struct mwifiex_adapter *adapter);
798 void mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *, u8 *,
799                                         u32);
800 int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv,
801                                struct host_cmd_ds_command *cmd,
802                                u16 cmd_action, uint16_t ps_bitmap,
803                                struct mwifiex_ds_auto_ds *auto_ds);
804 int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv,
805                                struct host_cmd_ds_command *resp,
806                                struct mwifiex_ds_pm_cfg *pm_cfg);
807 void mwifiex_process_hs_config(struct mwifiex_adapter *adapter);
808 void mwifiex_hs_activated_event(struct mwifiex_private *priv,
809                                         u8 activated);
810 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
811                               struct host_cmd_ds_command *resp);
812 int mwifiex_process_rx_packet(struct mwifiex_adapter *adapter,
813                               struct sk_buff *skb);
814 int mwifiex_sta_prepare_cmd(struct mwifiex_private *, uint16_t cmd_no,
815                             u16 cmd_action, u32 cmd_oid,
816                             void *data_buf, void *cmd_buf);
817 int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
818                             u16 cmd_action, u32 cmd_oid,
819                             void *data_buf, void *cmd_buf);
820 int mwifiex_process_sta_cmdresp(struct mwifiex_private *, u16 cmdresp_no,
821                                 struct host_cmd_ds_command *resp);
822 int mwifiex_process_sta_rx_packet(struct mwifiex_adapter *,
823                                   struct sk_buff *skb);
824 int mwifiex_process_uap_rx_packet(struct mwifiex_adapter *adapter,
825                                   struct sk_buff *skb);
826 int mwifiex_handle_uap_rx_forward(struct mwifiex_private *priv,
827                                   struct sk_buff *skb);
828 int mwifiex_process_sta_event(struct mwifiex_private *);
829 int mwifiex_process_uap_event(struct mwifiex_private *);
830 struct mwifiex_sta_node *
831 mwifiex_get_sta_entry(struct mwifiex_private *priv, u8 *mac);
832 void mwifiex_delete_all_station_list(struct mwifiex_private *priv);
833 void *mwifiex_process_sta_txpd(struct mwifiex_private *, struct sk_buff *skb);
834 void *mwifiex_process_uap_txpd(struct mwifiex_private *, struct sk_buff *skb);
835 int mwifiex_sta_init_cmd(struct mwifiex_private *, u8 first_sta);
836 int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
837                             struct mwifiex_scan_cmd_config *scan_cfg);
838 void mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
839                             struct cmd_ctrl_node *cmd_node);
840 int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
841                             struct host_cmd_ds_command *resp);
842 s32 mwifiex_ssid_cmp(struct cfg80211_ssid *ssid1, struct cfg80211_ssid *ssid2);
843 int mwifiex_associate(struct mwifiex_private *priv,
844                       struct mwifiex_bssdescriptor *bss_desc);
845 int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
846                                  struct host_cmd_ds_command *cmd,
847                                  struct mwifiex_bssdescriptor *bss_desc);
848 int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
849                                  struct host_cmd_ds_command *resp);
850 void mwifiex_reset_connect_state(struct mwifiex_private *priv, u16 reason);
851 u8 mwifiex_band_to_radio_type(u8 band);
852 int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac);
853 int mwifiex_adhoc_start(struct mwifiex_private *priv,
854                         struct cfg80211_ssid *adhoc_ssid);
855 int mwifiex_adhoc_join(struct mwifiex_private *priv,
856                        struct mwifiex_bssdescriptor *bss_desc);
857 int mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
858                                     struct host_cmd_ds_command *cmd,
859                                     struct cfg80211_ssid *req_ssid);
860 int mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
861                                    struct host_cmd_ds_command *cmd,
862                                    struct mwifiex_bssdescriptor *bss_desc);
863 int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
864                               struct host_cmd_ds_command *resp);
865 int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd);
866 struct mwifiex_chan_freq_power *mwifiex_get_cfp(struct mwifiex_private *priv,
867                                                 u8 band, u16 channel, u32 freq);
868 u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv, u8 index,
869                                                         u8 ht_info);
870 u32 mwifiex_find_freq_from_band_chan(u8, u8);
871 int mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv, u16 vsie_mask,
872                                 u8 **buffer);
873 u32 mwifiex_get_active_data_rates(struct mwifiex_private *priv,
874                                     u8 *rates);
875 u32 mwifiex_get_supported_rates(struct mwifiex_private *priv, u8 *rates);
876 u8 mwifiex_is_rate_auto(struct mwifiex_private *priv);
877 extern u16 region_code_index[MWIFIEX_MAX_REGION_CODE];
878 void mwifiex_save_curr_bcn(struct mwifiex_private *priv);
879 void mwifiex_free_curr_bcn(struct mwifiex_private *priv);
880 int mwifiex_cmd_get_hw_spec(struct mwifiex_private *priv,
881                             struct host_cmd_ds_command *cmd);
882 int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
883                             struct host_cmd_ds_command *resp);
884 int is_command_pending(struct mwifiex_adapter *adapter);
885 void mwifiex_init_priv_params(struct mwifiex_private *priv,
886                                                 struct net_device *dev);
887 int mwifiex_set_secure_params(struct mwifiex_private *priv,
888                               struct mwifiex_uap_bss_param *bss_config,
889                               struct cfg80211_ap_settings *params);
890 void mwifiex_set_ht_params(struct mwifiex_private *priv,
891                            struct mwifiex_uap_bss_param *bss_cfg,
892                            struct cfg80211_ap_settings *params);
893 void mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
894                            struct cfg80211_ap_settings *params);
895
896 /*
897  * This function checks if the queuing is RA based or not.
898  */
899 static inline u8
900 mwifiex_queuing_ra_based(struct mwifiex_private *priv)
901 {
902         /*
903          * Currently we assume if we are in Infra, then DA=RA. This might not be
904          * true in the future
905          */
906         if ((priv->bss_mode == NL80211_IFTYPE_STATION) &&
907             (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA))
908                 return false;
909
910         return true;
911 }
912
913 /*
914  * This function copies rates.
915  */
916 static inline u32
917 mwifiex_copy_rates(u8 *dest, u32 pos, u8 *src, int len)
918 {
919         int i;
920
921         for (i = 0; i < len && src[i]; i++, pos++) {
922                 if (pos >= MWIFIEX_SUPPORTED_RATES)
923                         break;
924                 dest[pos] = src[i];
925         }
926
927         return pos;
928 }
929
930 /*
931  * This function returns the correct private structure pointer based
932  * upon the BSS type and BSS number.
933  */
934 static inline struct mwifiex_private *
935 mwifiex_get_priv_by_id(struct mwifiex_adapter *adapter,
936                        u8 bss_num, u8 bss_type)
937 {
938         int i;
939
940         for (i = 0; i < adapter->priv_num; i++) {
941                 if (adapter->priv[i]) {
942                         if ((adapter->priv[i]->bss_num == bss_num) &&
943                             (adapter->priv[i]->bss_type == bss_type))
944                                 break;
945                 }
946         }
947         return ((i < adapter->priv_num) ? adapter->priv[i] : NULL);
948 }
949
950 /*
951  * This function returns the first available private structure pointer
952  * based upon the BSS role.
953  */
954 static inline struct mwifiex_private *
955 mwifiex_get_priv(struct mwifiex_adapter *adapter,
956                  enum mwifiex_bss_role bss_role)
957 {
958         int i;
959
960         for (i = 0; i < adapter->priv_num; i++) {
961                 if (adapter->priv[i]) {
962                         if (bss_role == MWIFIEX_BSS_ROLE_ANY ||
963                             GET_BSS_ROLE(adapter->priv[i]) == bss_role)
964                                 break;
965                 }
966         }
967
968         return ((i < adapter->priv_num) ? adapter->priv[i] : NULL);
969 }
970
971 /*
972  * This function returns the driver private structure of a network device.
973  */
974 static inline struct mwifiex_private *
975 mwifiex_netdev_get_priv(struct net_device *dev)
976 {
977         return (struct mwifiex_private *) (*(unsigned long *) netdev_priv(dev));
978 }
979
980 /*
981  * This function checks if a skb holds a management frame.
982  */
983 static inline bool mwifiex_is_skb_mgmt_frame(struct sk_buff *skb)
984 {
985         return (*(u32 *)skb->data == PKT_TYPE_MGMT);
986 }
987
988 int mwifiex_init_shutdown_fw(struct mwifiex_private *priv,
989                              u32 func_init_shutdown);
990 int mwifiex_add_card(void *, struct semaphore *, struct mwifiex_if_ops *, u8);
991 int mwifiex_remove_card(struct mwifiex_adapter *, struct semaphore *);
992
993 void mwifiex_get_version(struct mwifiex_adapter *adapter, char *version,
994                          int maxlen);
995 int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
996                         struct mwifiex_multicast_list *mcast_list);
997 int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
998                             struct net_device *dev);
999 int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter);
1000 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
1001                       struct cfg80211_ssid *req_ssid);
1002 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type);
1003 int mwifiex_enable_hs(struct mwifiex_adapter *adapter);
1004 int mwifiex_disable_auto_ds(struct mwifiex_private *priv);
1005 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate);
1006 int mwifiex_request_scan(struct mwifiex_private *priv,
1007                          struct cfg80211_ssid *req_ssid);
1008 int mwifiex_scan_networks(struct mwifiex_private *priv,
1009                           const struct mwifiex_user_scan_cfg *user_scan_in);
1010 int mwifiex_set_radio(struct mwifiex_private *priv, u8 option);
1011
1012 int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1013                        const u8 *key, int key_len, u8 key_index,
1014                        const u8 *mac_addr, int disable);
1015
1016 int mwifiex_set_gen_ie(struct mwifiex_private *priv, u8 *ie, int ie_len);
1017
1018 int mwifiex_get_ver_ext(struct mwifiex_private *priv);
1019
1020 int mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1021                                struct ieee80211_channel *chan,
1022                                enum nl80211_channel_type *channel_type,
1023                                unsigned int duration);
1024
1025 int mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role);
1026
1027 int mwifiex_get_stats_info(struct mwifiex_private *priv,
1028                            struct mwifiex_ds_get_stats *log);
1029
1030 int mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1031                       u32 reg_offset, u32 reg_value);
1032
1033 int mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1034                      u32 reg_offset, u32 *value);
1035
1036 int mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1037                         u8 *value);
1038
1039 int mwifiex_set_11n_httx_cfg(struct mwifiex_private *priv, int data);
1040
1041 int mwifiex_get_11n_httx_cfg(struct mwifiex_private *priv, int *data);
1042
1043 int mwifiex_set_tx_rate_cfg(struct mwifiex_private *priv, int tx_rate_index);
1044
1045 int mwifiex_get_tx_rate_cfg(struct mwifiex_private *priv, int *tx_rate_index);
1046
1047 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode);
1048
1049 int mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter,
1050                                    char *version, int max_len);
1051
1052 int mwifiex_set_tx_power(struct mwifiex_private *priv,
1053                          struct mwifiex_power_cfg *power_cfg);
1054
1055 int mwifiex_main_process(struct mwifiex_adapter *);
1056
1057 int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb);
1058
1059 int mwifiex_get_bss_info(struct mwifiex_private *,
1060                          struct mwifiex_bss_info *);
1061 int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
1062                               struct cfg80211_bss *bss,
1063                               struct mwifiex_bssdescriptor *bss_desc);
1064 int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1065                                     struct mwifiex_bssdescriptor *bss_entry);
1066 int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
1067                                         struct mwifiex_bssdescriptor *bss_desc);
1068
1069 u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type);
1070
1071 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
1072                                               const char *name,
1073                                               enum nl80211_iftype type,
1074                                               u32 *flags,
1075                                               struct vif_params *params);
1076 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev);
1077
1078 void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config);
1079
1080 int mwifiex_set_mgmt_ies(struct mwifiex_private *priv,
1081                          struct cfg80211_beacon_data *data);
1082 int mwifiex_del_mgmt_ies(struct mwifiex_private *priv);
1083 u8 *mwifiex_11d_code_2_region(u8 code);
1084
1085 #ifdef CONFIG_DEBUG_FS
1086 void mwifiex_debugfs_init(void);
1087 void mwifiex_debugfs_remove(void);
1088
1089 void mwifiex_dev_debugfs_init(struct mwifiex_private *priv);
1090 void mwifiex_dev_debugfs_remove(struct mwifiex_private *priv);
1091 #endif
1092 #endif /* !_MWIFIEX_MAIN_H_ */