Merge commit '4e6ce4dc7ce71d0886908d55129d5d6482a27ff9' of git://git.kernel.org/pub...
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / mwifiex / main.h
1 /*
2  * Marvell Wireless LAN device driver: major data structures and prototypes
3  *
4  * Copyright (C) 2011-2014, 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/vmalloc.h>
34 #include <linux/firmware.h>
35 #include <linux/ctype.h>
36 #include <linux/of.h>
37
38 #include "decl.h"
39 #include "ioctl.h"
40 #include "util.h"
41 #include "fw.h"
42 #include "pcie.h"
43
44 extern const char driver_version[];
45
46 enum {
47         MWIFIEX_ASYNC_CMD,
48         MWIFIEX_SYNC_CMD
49 };
50
51 #define MWIFIEX_DRIVER_MODE_STA                 BIT(0)
52 #define MWIFIEX_DRIVER_MODE_UAP                 BIT(1)
53 #define MWIFIEX_DRIVER_MODE_P2P                 BIT(2)
54 #define MWIFIEX_DRIVER_MODE_BITMASK             (BIT(0) | BIT(1) | BIT(2))
55
56 #define MWIFIEX_MAX_AP                          64
57
58 #define MWIFIEX_DEFAULT_WATCHDOG_TIMEOUT        (5 * HZ)
59
60 #define MWIFIEX_TIMER_10S                       10000
61 #define MWIFIEX_TIMER_1S                        1000
62
63 #define MAX_TX_PENDING      100
64 #define LOW_TX_PENDING      80
65
66 #define HIGH_RX_PENDING     50
67 #define LOW_RX_PENDING      20
68
69 #define MWIFIEX_UPLD_SIZE               (2312)
70
71 #define MAX_EVENT_SIZE                  2048
72
73 #define ARP_FILTER_MAX_BUF_SIZE         68
74
75 #define MWIFIEX_KEY_BUFFER_SIZE                 16
76 #define MWIFIEX_DEFAULT_LISTEN_INTERVAL 10
77 #define MWIFIEX_MAX_REGION_CODE         7
78
79 #define DEFAULT_BCN_AVG_FACTOR          8
80 #define DEFAULT_DATA_AVG_FACTOR         8
81
82 #define FIRST_VALID_CHANNEL                             0xff
83 #define DEFAULT_AD_HOC_CHANNEL                  6
84 #define DEFAULT_AD_HOC_CHANNEL_A                36
85
86 #define DEFAULT_BCN_MISS_TIMEOUT                5
87
88 #define MAX_SCAN_BEACON_BUFFER                  8000
89
90 #define SCAN_BEACON_ENTRY_PAD                   6
91
92 #define MWIFIEX_PASSIVE_SCAN_CHAN_TIME  110
93 #define MWIFIEX_ACTIVE_SCAN_CHAN_TIME   30
94 #define MWIFIEX_SPECIFIC_SCAN_CHAN_TIME 30
95 #define MWIFIEX_DEF_SCAN_CHAN_GAP_TIME  50
96
97 #define SCAN_RSSI(RSSI)                                 (0x100 - ((u8)(RSSI)))
98
99 #define MWIFIEX_MAX_TOTAL_SCAN_TIME     (MWIFIEX_TIMER_10S - MWIFIEX_TIMER_1S)
100
101 #define RSN_GTK_OUI_OFFSET                              2
102
103 #define MWIFIEX_OUI_NOT_PRESENT                 0
104 #define MWIFIEX_OUI_PRESENT                             1
105
106 #define PKT_TYPE_MGMT   0xE5
107
108 /*
109  * Do not check for data_received for USB, as data_received
110  * is handled in mwifiex_usb_recv for USB
111  */
112 #define IS_CARD_RX_RCVD(adapter) (adapter->cmd_resp_received || \
113                                 adapter->event_received || \
114                                 adapter->data_received)
115
116 #define MWIFIEX_TYPE_CMD                                1
117 #define MWIFIEX_TYPE_DATA                               0
118 #define MWIFIEX_TYPE_EVENT                              3
119
120 #define MAX_BITMAP_RATES_SIZE                   18
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 /* Threshold for tx_timeout_cnt before we trigger a card reset */
136 #define TX_TIMEOUT_THRESHOLD    6
137
138 struct mwifiex_dbg {
139         u32 num_cmd_host_to_card_failure;
140         u32 num_cmd_sleep_cfm_host_to_card_failure;
141         u32 num_tx_host_to_card_failure;
142         u32 num_event_deauth;
143         u32 num_event_disassoc;
144         u32 num_event_link_lost;
145         u32 num_cmd_deauth;
146         u32 num_cmd_assoc_success;
147         u32 num_cmd_assoc_failure;
148         u32 num_tx_timeout;
149         u16 timeout_cmd_id;
150         u16 timeout_cmd_act;
151         u16 last_cmd_id[DBG_CMD_NUM];
152         u16 last_cmd_act[DBG_CMD_NUM];
153         u16 last_cmd_index;
154         u16 last_cmd_resp_id[DBG_CMD_NUM];
155         u16 last_cmd_resp_index;
156         u16 last_event[DBG_CMD_NUM];
157         u16 last_event_index;
158 };
159
160 enum MWIFIEX_HARDWARE_STATUS {
161         MWIFIEX_HW_STATUS_READY,
162         MWIFIEX_HW_STATUS_INITIALIZING,
163         MWIFIEX_HW_STATUS_FW_READY,
164         MWIFIEX_HW_STATUS_INIT_DONE,
165         MWIFIEX_HW_STATUS_RESET,
166         MWIFIEX_HW_STATUS_CLOSING,
167         MWIFIEX_HW_STATUS_NOT_READY
168 };
169
170 enum MWIFIEX_802_11_POWER_MODE {
171         MWIFIEX_802_11_POWER_MODE_CAM,
172         MWIFIEX_802_11_POWER_MODE_PSP
173 };
174
175 struct mwifiex_tx_param {
176         u32 next_pkt_len;
177 };
178
179 enum MWIFIEX_PS_STATE {
180         PS_STATE_AWAKE,
181         PS_STATE_PRE_SLEEP,
182         PS_STATE_SLEEP_CFM,
183         PS_STATE_SLEEP
184 };
185
186 enum mwifiex_iface_type {
187         MWIFIEX_SDIO,
188         MWIFIEX_PCIE,
189         MWIFIEX_USB
190 };
191
192 struct mwifiex_add_ba_param {
193         u32 tx_win_size;
194         u32 rx_win_size;
195         u32 timeout;
196         u8 tx_amsdu;
197         u8 rx_amsdu;
198 };
199
200 struct mwifiex_tx_aggr {
201         u8 ampdu_user;
202         u8 ampdu_ap;
203         u8 amsdu;
204 };
205
206 struct mwifiex_ra_list_tbl {
207         struct list_head list;
208         struct sk_buff_head skb_head;
209         u8 ra[ETH_ALEN];
210         u32 is_11n_enabled;
211         u16 max_amsdu;
212         u16 ba_pkt_count;
213         u8 ba_packet_thr;
214         u16 total_pkt_count;
215         bool tdls_link;
216 };
217
218 struct mwifiex_tid_tbl {
219         struct list_head ra_list;
220 };
221
222 #define WMM_HIGHEST_PRIORITY            7
223 #define HIGH_PRIO_TID                           7
224 #define LOW_PRIO_TID                            0
225
226 struct mwifiex_wmm_desc {
227         struct mwifiex_tid_tbl tid_tbl_ptr[MAX_NUM_TID];
228         u32 packets_out[MAX_NUM_TID];
229         /* spin lock to protect ra_list */
230         spinlock_t ra_list_spinlock;
231         struct mwifiex_wmm_ac_status ac_status[IEEE80211_NUM_ACS];
232         enum mwifiex_wmm_ac_e ac_down_graded_vals[IEEE80211_NUM_ACS];
233         u32 drv_pkt_delay_max;
234         u8 queue_priority[IEEE80211_NUM_ACS];
235         u32 user_pri_pkt_tx_ctrl[WMM_HIGHEST_PRIORITY + 1];     /* UP: 0 to 7 */
236         /* Number of transmit packets queued */
237         atomic_t tx_pkts_queued;
238         /* Tracks highest priority with a packet queued */
239         atomic_t highest_queued_prio;
240 };
241
242 struct mwifiex_802_11_security {
243         u8 wpa_enabled;
244         u8 wpa2_enabled;
245         u8 wapi_enabled;
246         u8 wapi_key_on;
247         u8 wep_enabled;
248         u32 authentication_mode;
249         u8 is_authtype_auto;
250         u32 encryption_mode;
251 };
252
253 struct ieee_types_header {
254         u8 element_id;
255         u8 len;
256 } __packed;
257
258 struct ieee_types_vendor_specific {
259         struct ieee_types_vendor_header vend_hdr;
260         u8 data[IEEE_MAX_IE_SIZE - sizeof(struct ieee_types_vendor_header)];
261 } __packed;
262
263 struct ieee_types_generic {
264         struct ieee_types_header ieee_hdr;
265         u8 data[IEEE_MAX_IE_SIZE - sizeof(struct ieee_types_header)];
266 } __packed;
267
268 struct ieee_types_bss_co_2040 {
269         struct ieee_types_header ieee_hdr;
270         u8 bss_2040co;
271 } __packed;
272
273 struct ieee_types_extcap {
274         struct ieee_types_header ieee_hdr;
275         u8 ext_capab[8];
276 } __packed;
277
278 struct ieee_types_vht_cap {
279         struct ieee_types_header ieee_hdr;
280         struct ieee80211_vht_cap vhtcap;
281 } __packed;
282
283 struct ieee_types_vht_oper {
284         struct ieee_types_header ieee_hdr;
285         struct ieee80211_vht_operation vhtoper;
286 } __packed;
287
288 struct ieee_types_aid {
289         struct ieee_types_header ieee_hdr;
290         u16 aid;
291 } __packed;
292
293 struct mwifiex_bssdescriptor {
294         u8 mac_address[ETH_ALEN];
295         struct cfg80211_ssid ssid;
296         u32 privacy;
297         s32 rssi;
298         u32 channel;
299         u32 freq;
300         u16 beacon_period;
301         u8 erp_flags;
302         u32 bss_mode;
303         u8 supported_rates[MWIFIEX_SUPPORTED_RATES];
304         u8 data_rates[MWIFIEX_SUPPORTED_RATES];
305         /* Network band.
306          * BAND_B(0x01): 'b' band
307          * BAND_G(0x02): 'g' band
308          * BAND_A(0X04): 'a' band
309          */
310         u16 bss_band;
311         u64 fw_tsf;
312         u64 timestamp;
313         union ieee_types_phy_param_set phy_param_set;
314         union ieee_types_ss_param_set ss_param_set;
315         u16 cap_info_bitmap;
316         struct ieee_types_wmm_parameter wmm_ie;
317         u8  disable_11n;
318         struct ieee80211_ht_cap *bcn_ht_cap;
319         u16 ht_cap_offset;
320         struct ieee80211_ht_operation *bcn_ht_oper;
321         u16 ht_info_offset;
322         u8 *bcn_bss_co_2040;
323         u16 bss_co_2040_offset;
324         u8 *bcn_ext_cap;
325         u16 ext_cap_offset;
326         struct ieee80211_vht_cap *bcn_vht_cap;
327         u16 vht_cap_offset;
328         struct ieee80211_vht_operation *bcn_vht_oper;
329         u16 vht_info_offset;
330         struct ieee_types_oper_mode_ntf *oper_mode;
331         u16 oper_mode_offset;
332         u8 disable_11ac;
333         struct ieee_types_vendor_specific *bcn_wpa_ie;
334         u16 wpa_offset;
335         struct ieee_types_generic *bcn_rsn_ie;
336         u16 rsn_offset;
337         struct ieee_types_generic *bcn_wapi_ie;
338         u16 wapi_offset;
339         u8 *beacon_buf;
340         u32 beacon_buf_size;
341         u8 sensed_11h;
342         u8 local_constraint;
343         u8 chan_sw_ie_present;
344 };
345
346 struct mwifiex_current_bss_params {
347         struct mwifiex_bssdescriptor bss_descriptor;
348         u8 wmm_enabled;
349         u8 wmm_uapsd_enabled;
350         u8 band;
351         u32 num_of_rates;
352         u8 data_rates[MWIFIEX_SUPPORTED_RATES];
353 };
354
355 struct mwifiex_sleep_params {
356         u16 sp_error;
357         u16 sp_offset;
358         u16 sp_stable_time;
359         u8 sp_cal_control;
360         u8 sp_ext_sleep_clk;
361         u16 sp_reserved;
362 };
363
364 struct mwifiex_sleep_period {
365         u16 period;
366         u16 reserved;
367 };
368
369 struct mwifiex_wep_key {
370         u32 length;
371         u32 key_index;
372         u32 key_length;
373         u8 key_material[MWIFIEX_KEY_BUFFER_SIZE];
374 };
375
376 #define MAX_REGION_CHANNEL_NUM  2
377
378 struct mwifiex_chan_freq_power {
379         u16 channel;
380         u32 freq;
381         u16 max_tx_power;
382         u8 unsupported;
383 };
384
385 enum state_11d_t {
386         DISABLE_11D = 0,
387         ENABLE_11D = 1,
388 };
389
390 #define MWIFIEX_MAX_TRIPLET_802_11D             83
391
392 struct mwifiex_802_11d_domain_reg {
393         u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
394         u8 no_of_triplet;
395         struct ieee80211_country_ie_triplet
396                 triplet[MWIFIEX_MAX_TRIPLET_802_11D];
397 };
398
399 struct mwifiex_vendor_spec_cfg_ie {
400         u16 mask;
401         u16 flag;
402         u8 ie[MWIFIEX_MAX_VSIE_LEN];
403 };
404
405 struct wps {
406         u8 session_enable;
407 };
408
409 struct mwifiex_roc_cfg {
410         u64 cookie;
411         struct ieee80211_channel chan;
412 };
413
414 #define MWIFIEX_FW_DUMP_IDX             0xff
415 #define FW_DUMP_MAX_NAME_LEN            8
416 #define FW_DUMP_HOST_READY              0xEE
417 #define FW_DUMP_DONE                    0xFF
418 #define FW_DUMP_READ_DONE               0xFE
419
420 struct memory_type_mapping {
421         u8 mem_name[FW_DUMP_MAX_NAME_LEN];
422         u8 *mem_ptr;
423         u32 mem_size;
424         u8 done_flag;
425 };
426
427 enum rdwr_status {
428         RDWR_STATUS_SUCCESS = 0,
429         RDWR_STATUS_FAILURE = 1,
430         RDWR_STATUS_DONE = 2
431 };
432
433 enum mwifiex_iface_work_flags {
434         MWIFIEX_IFACE_WORK_FW_DUMP,
435         MWIFIEX_IFACE_WORK_CARD_RESET,
436 };
437
438 struct mwifiex_adapter;
439 struct mwifiex_private;
440
441 struct mwifiex_private {
442         struct mwifiex_adapter *adapter;
443         u8 bss_type;
444         u8 bss_role;
445         u8 bss_priority;
446         u8 bss_num;
447         u8 bss_started;
448         u8 frame_type;
449         u8 curr_addr[ETH_ALEN];
450         u8 media_connected;
451         u32 num_tx_timeout;
452         /* track consecutive timeout */
453         u8 tx_timeout_cnt;
454         struct net_device *netdev;
455         struct net_device_stats stats;
456         u16 curr_pkt_filter;
457         u32 bss_mode;
458         u32 pkt_tx_ctrl;
459         u16 tx_power_level;
460         u8 max_tx_power_level;
461         u8 min_tx_power_level;
462         u8 tx_rate;
463         u8 tx_htinfo;
464         u8 rxpd_htinfo;
465         u8 rxpd_rate;
466         u16 rate_bitmap;
467         u16 bitmap_rates[MAX_BITMAP_RATES_SIZE];
468         u32 data_rate;
469         u8 is_data_rate_auto;
470         u16 bcn_avg_factor;
471         u16 data_avg_factor;
472         s16 data_rssi_last;
473         s16 data_nf_last;
474         s16 data_rssi_avg;
475         s16 data_nf_avg;
476         s16 bcn_rssi_last;
477         s16 bcn_nf_last;
478         s16 bcn_rssi_avg;
479         s16 bcn_nf_avg;
480         struct mwifiex_bssdescriptor *attempted_bss_desc;
481         struct cfg80211_ssid prev_ssid;
482         u8 prev_bssid[ETH_ALEN];
483         struct mwifiex_current_bss_params curr_bss_params;
484         u16 beacon_period;
485         u8 dtim_period;
486         u16 listen_interval;
487         u16 atim_window;
488         u8 adhoc_channel;
489         u8 adhoc_is_link_sensed;
490         u8 adhoc_state;
491         struct mwifiex_802_11_security sec_info;
492         struct mwifiex_wep_key wep_key[NUM_WEP_KEYS];
493         u16 wep_key_curr_index;
494         u8 wpa_ie[256];
495         u8 wpa_ie_len;
496         u8 wpa_is_gtk_set;
497         struct host_cmd_ds_802_11_key_material aes_key;
498         struct host_cmd_ds_802_11_key_material_v2 aes_key_v2;
499         u8 wapi_ie[256];
500         u8 wapi_ie_len;
501         u8 *wps_ie;
502         u8 wps_ie_len;
503         u8 wmm_required;
504         u8 wmm_enabled;
505         u8 wmm_qosinfo;
506         struct mwifiex_wmm_desc wmm;
507         atomic_t wmm_tx_pending[IEEE80211_NUM_ACS];
508         struct list_head sta_list;
509         /* spin lock for associated station/TDLS peers list */
510         spinlock_t sta_list_spinlock;
511         struct list_head auto_tdls_list;
512         /* spin lock for auto TDLS peer list */
513         spinlock_t auto_tdls_lock;
514         struct list_head tx_ba_stream_tbl_ptr;
515         /* spin lock for tx_ba_stream_tbl_ptr queue */
516         spinlock_t tx_ba_stream_tbl_lock;
517         struct mwifiex_tx_aggr aggr_prio_tbl[MAX_NUM_TID];
518         struct mwifiex_add_ba_param add_ba_param;
519         u16 rx_seq[MAX_NUM_TID];
520         u8 tos_to_tid_inv[MAX_NUM_TID];
521         struct list_head rx_reorder_tbl_ptr;
522         /* spin lock for rx_reorder_tbl_ptr queue */
523         spinlock_t rx_reorder_tbl_lock;
524         /* spin lock for Rx packets */
525         spinlock_t rx_pkt_lock;
526
527 #define MWIFIEX_ASSOC_RSP_BUF_SIZE  500
528         u8 assoc_rsp_buf[MWIFIEX_ASSOC_RSP_BUF_SIZE];
529         u32 assoc_rsp_size;
530
531 #define MWIFIEX_GENIE_BUF_SIZE      256
532         u8 gen_ie_buf[MWIFIEX_GENIE_BUF_SIZE];
533         u8 gen_ie_buf_len;
534
535         struct mwifiex_vendor_spec_cfg_ie vs_ie[MWIFIEX_MAX_VSIE_NUM];
536
537 #define MWIFIEX_ASSOC_TLV_BUF_SIZE  256
538         u8 assoc_tlv_buf[MWIFIEX_ASSOC_TLV_BUF_SIZE];
539         u8 assoc_tlv_buf_len;
540
541         u8 *curr_bcn_buf;
542         u32 curr_bcn_size;
543         /* spin lock for beacon buffer */
544         spinlock_t curr_bcn_buf_lock;
545         struct wireless_dev *wdev;
546         struct mwifiex_chan_freq_power cfp;
547         char version_str[128];
548 #ifdef CONFIG_DEBUG_FS
549         struct dentry *dfs_dev_dir;
550 #endif
551         u8 nick_name[16];
552         u16 current_key_index;
553         struct semaphore async_sem;
554         struct cfg80211_scan_request *scan_request;
555         u8 cfg_bssid[6];
556         struct wps wps;
557         u8 scan_block;
558         s32 cqm_rssi_thold;
559         u32 cqm_rssi_hyst;
560         u8 subsc_evt_rssi_state;
561         struct mwifiex_ds_misc_subsc_evt async_subsc_evt_storage;
562         struct mwifiex_ie mgmt_ie[MAX_MGMT_IE_INDEX];
563         u16 beacon_idx;
564         u16 proberesp_idx;
565         u16 assocresp_idx;
566         u16 rsn_idx;
567         u8 ap_11n_enabled;
568         u8 ap_11ac_enabled;
569         u32 mgmt_frame_mask;
570         struct mwifiex_roc_cfg roc_cfg;
571         bool scan_aborting;
572         u8 csa_chan;
573         unsigned long csa_expire_time;
574         u8 del_list_idx;
575         bool hs2_enabled;
576         struct station_parameters *sta_params;
577         struct sk_buff_head tdls_txq;
578         u8 check_tdls_tx;
579         struct timer_list auto_tdls_timer;
580         bool auto_tdls_timer_active;
581 };
582
583 enum mwifiex_ba_status {
584         BA_SETUP_NONE = 0,
585         BA_SETUP_INPROGRESS,
586         BA_SETUP_COMPLETE
587 };
588
589 struct mwifiex_tx_ba_stream_tbl {
590         struct list_head list;
591         int tid;
592         u8 ra[ETH_ALEN];
593         enum mwifiex_ba_status ba_status;
594         u8 amsdu;
595 };
596
597 struct mwifiex_rx_reorder_tbl;
598
599 struct reorder_tmr_cnxt {
600         struct timer_list timer;
601         struct mwifiex_rx_reorder_tbl *ptr;
602         struct mwifiex_private *priv;
603         u8 timer_is_set;
604 };
605
606 struct mwifiex_rx_reorder_tbl {
607         struct list_head list;
608         int tid;
609         u8 ta[ETH_ALEN];
610         int init_win;
611         int start_win;
612         int win_size;
613         void **rx_reorder_ptr;
614         struct reorder_tmr_cnxt timer_context;
615         u8 amsdu;
616         u8 flags;
617 };
618
619 struct mwifiex_bss_prio_node {
620         struct list_head list;
621         struct mwifiex_private *priv;
622 };
623
624 struct mwifiex_bss_prio_tbl {
625         struct list_head bss_prio_head;
626         /* spin lock for bss priority  */
627         spinlock_t bss_prio_lock;
628         struct mwifiex_bss_prio_node *bss_prio_cur;
629 };
630
631 struct cmd_ctrl_node {
632         struct list_head list;
633         struct mwifiex_private *priv;
634         u32 cmd_oid;
635         u32 cmd_flag;
636         struct sk_buff *cmd_skb;
637         struct sk_buff *resp_skb;
638         void *data_buf;
639         u32 wait_q_enabled;
640         struct sk_buff *skb;
641         u8 *condition;
642         u8 cmd_wait_q_woken;
643 };
644
645 struct mwifiex_bss_priv {
646         u8 band;
647         u64 fw_tsf;
648 };
649
650 struct mwifiex_tdls_capab {
651         __le16 capab;
652         u8 rates[32];
653         u8 rates_len;
654         u8 qos_info;
655         u8 coex_2040;
656         u16 aid;
657         struct ieee80211_ht_cap ht_capb;
658         struct ieee80211_ht_operation ht_oper;
659         struct ieee_types_extcap extcap;
660         struct ieee_types_generic rsn_ie;
661         struct ieee80211_vht_cap vhtcap;
662         struct ieee80211_vht_operation vhtoper;
663 };
664
665 /* This is AP/TDLS specific structure which stores information
666  * about associated/peer STA
667  */
668 struct mwifiex_sta_node {
669         struct list_head list;
670         u8 mac_addr[ETH_ALEN];
671         u8 is_wmm_enabled;
672         u8 is_11n_enabled;
673         u8 is_11ac_enabled;
674         u8 ampdu_sta[MAX_NUM_TID];
675         u16 rx_seq[MAX_NUM_TID];
676         u16 max_amsdu;
677         u8 tdls_status;
678         struct mwifiex_tdls_capab tdls_cap;
679 };
680
681 struct mwifiex_auto_tdls_peer {
682         struct list_head list;
683         u8 mac_addr[ETH_ALEN];
684         u8 tdls_status;
685         int rssi;
686         long rssi_jiffies;
687         u8 failure_count;
688         u8 do_discover;
689         u8 do_setup;
690 };
691
692 struct mwifiex_if_ops {
693         int (*init_if) (struct mwifiex_adapter *);
694         void (*cleanup_if) (struct mwifiex_adapter *);
695         int (*check_fw_status) (struct mwifiex_adapter *, u32);
696         int (*prog_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
697         int (*register_dev) (struct mwifiex_adapter *);
698         void (*unregister_dev) (struct mwifiex_adapter *);
699         int (*enable_int) (struct mwifiex_adapter *);
700         void (*disable_int) (struct mwifiex_adapter *);
701         int (*process_int_status) (struct mwifiex_adapter *);
702         int (*host_to_card) (struct mwifiex_adapter *, u8, struct sk_buff *,
703                              struct mwifiex_tx_param *);
704         int (*wakeup) (struct mwifiex_adapter *);
705         int (*wakeup_complete) (struct mwifiex_adapter *);
706
707         /* Interface specific functions */
708         void (*update_mp_end_port) (struct mwifiex_adapter *, u16);
709         void (*cleanup_mpa_buf) (struct mwifiex_adapter *);
710         int (*cmdrsp_complete) (struct mwifiex_adapter *, struct sk_buff *);
711         int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
712         int (*init_fw_port) (struct mwifiex_adapter *);
713         int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
714         void (*card_reset) (struct mwifiex_adapter *);
715         void (*fw_dump)(struct mwifiex_adapter *);
716         int (*clean_pcie_ring) (struct mwifiex_adapter *adapter);
717         void (*iface_work)(struct work_struct *work);
718         void (*submit_rem_rx_urbs)(struct mwifiex_adapter *adapter);
719 };
720
721 struct mwifiex_adapter {
722         u8 iface_type;
723         struct mwifiex_private *priv[MWIFIEX_MAX_BSS_NUM];
724         u8 priv_num;
725         const struct firmware *firmware;
726         char fw_name[32];
727         int winner;
728         struct device *dev;
729         struct wiphy *wiphy;
730         bool surprise_removed;
731         u32 fw_release_number;
732         u16 init_wait_q_woken;
733         wait_queue_head_t init_wait_q;
734         void *card;
735         struct mwifiex_if_ops if_ops;
736         atomic_t rx_pending;
737         atomic_t tx_pending;
738         atomic_t cmd_pending;
739         struct workqueue_struct *workqueue;
740         struct work_struct main_work;
741         struct workqueue_struct *rx_workqueue;
742         struct work_struct rx_work;
743         bool rx_work_enabled;
744         bool rx_processing;
745         bool delay_main_work;
746         bool rx_locked;
747         struct mwifiex_bss_prio_tbl bss_prio_tbl[MWIFIEX_MAX_BSS_NUM];
748         /* spin lock for init/shutdown */
749         spinlock_t mwifiex_lock;
750         /* spin lock for main process */
751         spinlock_t main_proc_lock;
752         u32 mwifiex_processing;
753         u16 tx_buf_size;
754         u16 curr_tx_buf_size;
755         u32 ioport;
756         enum MWIFIEX_HARDWARE_STATUS hw_status;
757         u16 number_of_antenna;
758         u32 fw_cap_info;
759         /* spin lock for interrupt handling */
760         spinlock_t int_lock;
761         u8 int_status;
762         u32 event_cause;
763         struct sk_buff *event_skb;
764         u8 upld_buf[MWIFIEX_UPLD_SIZE];
765         u8 data_sent;
766         u8 cmd_sent;
767         u8 cmd_resp_received;
768         u8 event_received;
769         u8 data_received;
770         u16 seq_num;
771         struct cmd_ctrl_node *cmd_pool;
772         struct cmd_ctrl_node *curr_cmd;
773         /* spin lock for command */
774         spinlock_t mwifiex_cmd_lock;
775         u8 is_cmd_timedout;
776         u16 last_init_cmd;
777         struct timer_list cmd_timer;
778         struct list_head cmd_free_q;
779         /* spin lock for cmd_free_q */
780         spinlock_t cmd_free_q_lock;
781         struct list_head cmd_pending_q;
782         /* spin lock for cmd_pending_q */
783         spinlock_t cmd_pending_q_lock;
784         struct list_head scan_pending_q;
785         /* spin lock for scan_pending_q */
786         spinlock_t scan_pending_q_lock;
787         /* spin lock for RX processing routine */
788         spinlock_t rx_proc_lock;
789         u32 scan_processing;
790         u16 region_code;
791         struct mwifiex_802_11d_domain_reg domain_reg;
792         u16 scan_probes;
793         u32 scan_mode;
794         u16 specific_scan_time;
795         u16 active_scan_time;
796         u16 passive_scan_time;
797         u16 scan_chan_gap_time;
798         u8 fw_bands;
799         u8 adhoc_start_band;
800         u8 config_bands;
801         struct mwifiex_chan_scan_param_set *scan_channels;
802         u8 tx_lock_flag;
803         struct mwifiex_sleep_params sleep_params;
804         struct mwifiex_sleep_period sleep_period;
805         u16 ps_mode;
806         u32 ps_state;
807         u8 need_to_wakeup;
808         u16 multiple_dtim;
809         u16 local_listen_interval;
810         u16 null_pkt_interval;
811         struct sk_buff *sleep_cfm;
812         u16 bcn_miss_time_out;
813         u16 adhoc_awake_period;
814         u8 is_deep_sleep;
815         u8 delay_null_pkt;
816         u16 delay_to_ps;
817         u16 enhanced_ps_mode;
818         u8 pm_wakeup_card_req;
819         u16 gen_null_pkt;
820         u16 pps_uapsd_mode;
821         u32 pm_wakeup_fw_try;
822         u8 is_hs_configured;
823         struct mwifiex_hs_config_param hs_cfg;
824         u8 hs_activated;
825         u16 hs_activate_wait_q_woken;
826         wait_queue_head_t hs_activate_wait_q;
827         bool is_suspended;
828         bool hs_enabling;
829         u8 event_body[MAX_EVENT_SIZE];
830         u32 hw_dot_11n_dev_cap;
831         u8 hw_dev_mcs_support;
832         u8 user_dev_mcs_support;
833         u8 adhoc_11n_enabled;
834         u8 sec_chan_offset;
835         struct mwifiex_dbg dbg;
836         u8 arp_filter[ARP_FILTER_MAX_BUF_SIZE];
837         u32 arp_filter_size;
838         struct mwifiex_wait_queue cmd_wait_q;
839         u8 scan_wait_q_woken;
840         spinlock_t queue_lock;          /* lock for tx queues */
841         u8 country_code[IEEE80211_COUNTRY_STRING_LEN];
842         u16 max_mgmt_ie_index;
843         const struct firmware *cal_data;
844         struct device_node *dt_node;
845
846         /* 11AC */
847         u32 is_hw_11ac_capable;
848         u32 hw_dot_11ac_dev_cap;
849         u32 hw_dot_11ac_mcs_support;
850         u32 usr_dot_11ac_dev_cap_bg;
851         u32 usr_dot_11ac_dev_cap_a;
852         u32 usr_dot_11ac_mcs_support;
853
854         atomic_t pending_bridged_pkts;
855         struct semaphore *card_sem;
856         bool ext_scan;
857         u8 fw_api_ver;
858         u8 key_api_major_ver, key_api_minor_ver;
859         struct work_struct iface_work;
860         unsigned long iface_work_flags;
861         struct memory_type_mapping *mem_type_mapping_tbl;
862         u8 num_mem_types;
863         u8 curr_mem_idx;
864         bool scan_chan_gap_enabled;
865         struct sk_buff_head rx_data_q;
866         struct mwifiex_chan_stats *chan_stats;
867         u32 num_in_chan_stats;
868         int survey_idx;
869         bool auto_tdls;
870 };
871
872 int mwifiex_init_lock_list(struct mwifiex_adapter *adapter);
873
874 void mwifiex_set_trans_start(struct net_device *dev);
875
876 void mwifiex_stop_net_dev_queue(struct net_device *netdev,
877                 struct mwifiex_adapter *adapter);
878
879 void mwifiex_wake_up_net_dev_queue(struct net_device *netdev,
880                 struct mwifiex_adapter *adapter);
881
882 int mwifiex_init_priv(struct mwifiex_private *priv);
883 void mwifiex_free_priv(struct mwifiex_private *priv);
884
885 int mwifiex_init_fw(struct mwifiex_adapter *adapter);
886
887 int mwifiex_init_fw_complete(struct mwifiex_adapter *adapter);
888
889 int mwifiex_shutdown_drv(struct mwifiex_adapter *adapter);
890
891 int mwifiex_shutdown_fw_complete(struct mwifiex_adapter *adapter);
892
893 int mwifiex_dnld_fw(struct mwifiex_adapter *, struct mwifiex_fw_image *);
894
895 int mwifiex_recv_packet(struct mwifiex_private *priv, struct sk_buff *skb);
896
897 int mwifiex_process_mgmt_packet(struct mwifiex_private *priv,
898                                 struct sk_buff *skb);
899
900 int mwifiex_process_event(struct mwifiex_adapter *adapter);
901
902 int mwifiex_complete_cmd(struct mwifiex_adapter *adapter,
903                          struct cmd_ctrl_node *cmd_node);
904
905 int mwifiex_send_cmd(struct mwifiex_private *priv, u16 cmd_no,
906                      u16 cmd_action, u32 cmd_oid, void *data_buf, bool sync);
907
908 void mwifiex_cmd_timeout_func(unsigned long function_context);
909
910 int mwifiex_get_debug_info(struct mwifiex_private *,
911                            struct mwifiex_debug_info *);
912
913 int mwifiex_alloc_cmd_buffer(struct mwifiex_adapter *adapter);
914 int mwifiex_free_cmd_buffer(struct mwifiex_adapter *adapter);
915 void mwifiex_cancel_all_pending_cmd(struct mwifiex_adapter *adapter);
916 void mwifiex_cancel_pending_ioctl(struct mwifiex_adapter *adapter);
917
918 void mwifiex_insert_cmd_to_free_q(struct mwifiex_adapter *adapter,
919                                   struct cmd_ctrl_node *cmd_node);
920 void mwifiex_recycle_cmd_node(struct mwifiex_adapter *adapter,
921                               struct cmd_ctrl_node *cmd_node);
922
923 void mwifiex_insert_cmd_to_pending_q(struct mwifiex_adapter *adapter,
924                                      struct cmd_ctrl_node *cmd_node,
925                                      u32 addtail);
926
927 int mwifiex_exec_next_cmd(struct mwifiex_adapter *adapter);
928 int mwifiex_process_cmdresp(struct mwifiex_adapter *adapter);
929 int mwifiex_handle_rx_packet(struct mwifiex_adapter *adapter,
930                              struct sk_buff *skb);
931 int mwifiex_process_tx(struct mwifiex_private *priv, struct sk_buff *skb,
932                        struct mwifiex_tx_param *tx_param);
933 int mwifiex_send_null_packet(struct mwifiex_private *priv, u8 flags);
934 int mwifiex_write_data_complete(struct mwifiex_adapter *adapter,
935                                 struct sk_buff *skb, int aggr, int status);
936 void mwifiex_clean_txrx(struct mwifiex_private *priv);
937 u8 mwifiex_check_last_packet_indication(struct mwifiex_private *priv);
938 void mwifiex_check_ps_cond(struct mwifiex_adapter *adapter);
939 void mwifiex_process_sleep_confirm_resp(struct mwifiex_adapter *, u8 *,
940                                         u32);
941 int mwifiex_cmd_enh_power_mode(struct mwifiex_private *priv,
942                                struct host_cmd_ds_command *cmd,
943                                u16 cmd_action, uint16_t ps_bitmap,
944                                struct mwifiex_ds_auto_ds *auto_ds);
945 int mwifiex_ret_enh_power_mode(struct mwifiex_private *priv,
946                                struct host_cmd_ds_command *resp,
947                                struct mwifiex_ds_pm_cfg *pm_cfg);
948 void mwifiex_process_hs_config(struct mwifiex_adapter *adapter);
949 void mwifiex_hs_activated_event(struct mwifiex_private *priv,
950                                         u8 activated);
951 int mwifiex_set_hs_params(struct mwifiex_private *priv, u16 action,
952                           int cmd_type, struct mwifiex_ds_hs_cfg *hs_cfg);
953 int mwifiex_ret_802_11_hs_cfg(struct mwifiex_private *priv,
954                               struct host_cmd_ds_command *resp);
955 int mwifiex_process_rx_packet(struct mwifiex_private *priv,
956                               struct sk_buff *skb);
957 int mwifiex_sta_prepare_cmd(struct mwifiex_private *, uint16_t cmd_no,
958                             u16 cmd_action, u32 cmd_oid,
959                             void *data_buf, void *cmd_buf);
960 int mwifiex_uap_prepare_cmd(struct mwifiex_private *priv, uint16_t cmd_no,
961                             u16 cmd_action, u32 cmd_oid,
962                             void *data_buf, void *cmd_buf);
963 int mwifiex_process_sta_cmdresp(struct mwifiex_private *, u16 cmdresp_no,
964                                 struct host_cmd_ds_command *resp);
965 int mwifiex_process_sta_rx_packet(struct mwifiex_private *,
966                                   struct sk_buff *skb);
967 int mwifiex_process_uap_rx_packet(struct mwifiex_private *priv,
968                                   struct sk_buff *skb);
969 int mwifiex_handle_uap_rx_forward(struct mwifiex_private *priv,
970                                   struct sk_buff *skb);
971 int mwifiex_process_sta_event(struct mwifiex_private *);
972 int mwifiex_process_uap_event(struct mwifiex_private *);
973 void mwifiex_delete_all_station_list(struct mwifiex_private *priv);
974 void *mwifiex_process_sta_txpd(struct mwifiex_private *, struct sk_buff *skb);
975 void *mwifiex_process_uap_txpd(struct mwifiex_private *, struct sk_buff *skb);
976 int mwifiex_sta_init_cmd(struct mwifiex_private *, u8 first_sta);
977 int mwifiex_cmd_802_11_scan(struct host_cmd_ds_command *cmd,
978                             struct mwifiex_scan_cmd_config *scan_cfg);
979 void mwifiex_queue_scan_cmd(struct mwifiex_private *priv,
980                             struct cmd_ctrl_node *cmd_node);
981 int mwifiex_ret_802_11_scan(struct mwifiex_private *priv,
982                             struct host_cmd_ds_command *resp);
983 s32 mwifiex_ssid_cmp(struct cfg80211_ssid *ssid1, struct cfg80211_ssid *ssid2);
984 int mwifiex_associate(struct mwifiex_private *priv,
985                       struct mwifiex_bssdescriptor *bss_desc);
986 int mwifiex_cmd_802_11_associate(struct mwifiex_private *priv,
987                                  struct host_cmd_ds_command *cmd,
988                                  struct mwifiex_bssdescriptor *bss_desc);
989 int mwifiex_ret_802_11_associate(struct mwifiex_private *priv,
990                                  struct host_cmd_ds_command *resp);
991 void mwifiex_reset_connect_state(struct mwifiex_private *priv, u16 reason);
992 u8 mwifiex_band_to_radio_type(u8 band);
993 int mwifiex_deauthenticate(struct mwifiex_private *priv, u8 *mac);
994 void mwifiex_deauthenticate_all(struct mwifiex_adapter *adapter);
995 int mwifiex_adhoc_start(struct mwifiex_private *priv,
996                         struct cfg80211_ssid *adhoc_ssid);
997 int mwifiex_adhoc_join(struct mwifiex_private *priv,
998                        struct mwifiex_bssdescriptor *bss_desc);
999 int mwifiex_cmd_802_11_ad_hoc_start(struct mwifiex_private *priv,
1000                                     struct host_cmd_ds_command *cmd,
1001                                     struct cfg80211_ssid *req_ssid);
1002 int mwifiex_cmd_802_11_ad_hoc_join(struct mwifiex_private *priv,
1003                                    struct host_cmd_ds_command *cmd,
1004                                    struct mwifiex_bssdescriptor *bss_desc);
1005 int mwifiex_ret_802_11_ad_hoc(struct mwifiex_private *priv,
1006                               struct host_cmd_ds_command *resp);
1007 int mwifiex_cmd_802_11_bg_scan_query(struct host_cmd_ds_command *cmd);
1008 struct mwifiex_chan_freq_power *mwifiex_get_cfp(struct mwifiex_private *priv,
1009                                                 u8 band, u16 channel, u32 freq);
1010 u32 mwifiex_index_to_data_rate(struct mwifiex_private *priv,
1011                                u8 index, u8 ht_info);
1012 u32 mwifiex_index_to_acs_data_rate(struct mwifiex_private *priv,
1013                                    u8 index, u8 ht_info);
1014 u32 mwifiex_find_freq_from_band_chan(u8, u8);
1015 int mwifiex_cmd_append_vsie_tlv(struct mwifiex_private *priv, u16 vsie_mask,
1016                                 u8 **buffer);
1017 u32 mwifiex_get_active_data_rates(struct mwifiex_private *priv,
1018                                     u8 *rates);
1019 u32 mwifiex_get_supported_rates(struct mwifiex_private *priv, u8 *rates);
1020 u32 mwifiex_get_rates_from_cfg80211(struct mwifiex_private *priv,
1021                                     u8 *rates, u8 radio_type);
1022 u8 mwifiex_is_rate_auto(struct mwifiex_private *priv);
1023 extern u16 region_code_index[MWIFIEX_MAX_REGION_CODE];
1024 void mwifiex_save_curr_bcn(struct mwifiex_private *priv);
1025 void mwifiex_free_curr_bcn(struct mwifiex_private *priv);
1026 int mwifiex_cmd_get_hw_spec(struct mwifiex_private *priv,
1027                             struct host_cmd_ds_command *cmd);
1028 int mwifiex_ret_get_hw_spec(struct mwifiex_private *priv,
1029                             struct host_cmd_ds_command *resp);
1030 int is_command_pending(struct mwifiex_adapter *adapter);
1031 void mwifiex_init_priv_params(struct mwifiex_private *priv,
1032                                                 struct net_device *dev);
1033 int mwifiex_set_secure_params(struct mwifiex_private *priv,
1034                               struct mwifiex_uap_bss_param *bss_config,
1035                               struct cfg80211_ap_settings *params);
1036 void mwifiex_set_ht_params(struct mwifiex_private *priv,
1037                            struct mwifiex_uap_bss_param *bss_cfg,
1038                            struct cfg80211_ap_settings *params);
1039 void mwifiex_set_vht_params(struct mwifiex_private *priv,
1040                             struct mwifiex_uap_bss_param *bss_cfg,
1041                             struct cfg80211_ap_settings *params);
1042 void mwifiex_set_uap_rates(struct mwifiex_uap_bss_param *bss_cfg,
1043                            struct cfg80211_ap_settings *params);
1044 void mwifiex_set_vht_width(struct mwifiex_private *priv,
1045                            enum nl80211_chan_width width,
1046                            bool ap_11ac_disable);
1047 void
1048 mwifiex_set_wmm_params(struct mwifiex_private *priv,
1049                        struct mwifiex_uap_bss_param *bss_cfg,
1050                        struct cfg80211_ap_settings *params);
1051 void mwifiex_set_ba_params(struct mwifiex_private *priv);
1052 void mwifiex_set_11ac_ba_params(struct mwifiex_private *priv);
1053 int mwifiex_cmd_802_11_scan_ext(struct mwifiex_private *priv,
1054                                 struct host_cmd_ds_command *cmd,
1055                                 void *data_buf);
1056 int mwifiex_ret_802_11_scan_ext(struct mwifiex_private *priv,
1057                                 struct host_cmd_ds_command *resp);
1058 int mwifiex_handle_event_ext_scan_report(struct mwifiex_private *priv,
1059                                          void *buf);
1060
1061 /*
1062  * This function checks if the queuing is RA based or not.
1063  */
1064 static inline u8
1065 mwifiex_queuing_ra_based(struct mwifiex_private *priv)
1066 {
1067         /*
1068          * Currently we assume if we are in Infra, then DA=RA. This might not be
1069          * true in the future
1070          */
1071         if ((priv->bss_mode == NL80211_IFTYPE_STATION) &&
1072             (GET_BSS_ROLE(priv) == MWIFIEX_BSS_ROLE_STA))
1073                 return false;
1074
1075         return true;
1076 }
1077
1078 /*
1079  * This function copies rates.
1080  */
1081 static inline u32
1082 mwifiex_copy_rates(u8 *dest, u32 pos, u8 *src, int len)
1083 {
1084         int i;
1085
1086         for (i = 0; i < len && src[i]; i++, pos++) {
1087                 if (pos >= MWIFIEX_SUPPORTED_RATES)
1088                         break;
1089                 dest[pos] = src[i];
1090         }
1091
1092         return pos;
1093 }
1094
1095 /*
1096  * This function returns the correct private structure pointer based
1097  * upon the BSS type and BSS number.
1098  */
1099 static inline struct mwifiex_private *
1100 mwifiex_get_priv_by_id(struct mwifiex_adapter *adapter,
1101                        u8 bss_num, u8 bss_type)
1102 {
1103         int i;
1104
1105         for (i = 0; i < adapter->priv_num; i++) {
1106                 if (adapter->priv[i]) {
1107                         if ((adapter->priv[i]->bss_num == bss_num) &&
1108                             (adapter->priv[i]->bss_type == bss_type))
1109                                 break;
1110                 }
1111         }
1112         return ((i < adapter->priv_num) ? adapter->priv[i] : NULL);
1113 }
1114
1115 /*
1116  * This function returns the first available private structure pointer
1117  * based upon the BSS role.
1118  */
1119 static inline struct mwifiex_private *
1120 mwifiex_get_priv(struct mwifiex_adapter *adapter,
1121                  enum mwifiex_bss_role bss_role)
1122 {
1123         int i;
1124
1125         for (i = 0; i < adapter->priv_num; i++) {
1126                 if (adapter->priv[i]) {
1127                         if (bss_role == MWIFIEX_BSS_ROLE_ANY ||
1128                             GET_BSS_ROLE(adapter->priv[i]) == bss_role)
1129                                 break;
1130                 }
1131         }
1132
1133         return ((i < adapter->priv_num) ? adapter->priv[i] : NULL);
1134 }
1135
1136 /*
1137  * This function returns the driver private structure of a network device.
1138  */
1139 static inline struct mwifiex_private *
1140 mwifiex_netdev_get_priv(struct net_device *dev)
1141 {
1142         return (struct mwifiex_private *) (*(unsigned long *) netdev_priv(dev));
1143 }
1144
1145 /*
1146  * This function checks if a skb holds a management frame.
1147  */
1148 static inline bool mwifiex_is_skb_mgmt_frame(struct sk_buff *skb)
1149 {
1150         return (le32_to_cpu(*(__le32 *)skb->data) == PKT_TYPE_MGMT);
1151 }
1152
1153 /* This function retrieves channel closed for operation by Channel
1154  * Switch Announcement.
1155  */
1156 static inline u8
1157 mwifiex_11h_get_csa_closed_channel(struct mwifiex_private *priv)
1158 {
1159         if (!priv->csa_chan)
1160                 return 0;
1161
1162         /* Clear csa channel, if DFS channel move time has passed */
1163         if (time_after(jiffies, priv->csa_expire_time)) {
1164                 priv->csa_chan = 0;
1165                 priv->csa_expire_time = 0;
1166         }
1167
1168         return priv->csa_chan;
1169 }
1170
1171 static inline u8 mwifiex_is_any_intf_active(struct mwifiex_private *priv)
1172 {
1173         struct mwifiex_private *priv_num;
1174         int i;
1175
1176         for (i = 0; i < priv->adapter->priv_num; i++) {
1177                 priv_num = priv->adapter->priv[i];
1178                 if (priv_num) {
1179                         if ((GET_BSS_ROLE(priv_num) == MWIFIEX_BSS_ROLE_UAP &&
1180                              priv_num->bss_started) ||
1181                             (GET_BSS_ROLE(priv_num) == MWIFIEX_BSS_ROLE_STA &&
1182                              priv_num->media_connected))
1183                                 return 1;
1184                 }
1185         }
1186
1187         return 0;
1188 }
1189
1190 int mwifiex_init_shutdown_fw(struct mwifiex_private *priv,
1191                              u32 func_init_shutdown);
1192 int mwifiex_add_card(void *, struct semaphore *, struct mwifiex_if_ops *, u8);
1193 int mwifiex_remove_card(struct mwifiex_adapter *, struct semaphore *);
1194
1195 void mwifiex_get_version(struct mwifiex_adapter *adapter, char *version,
1196                          int maxlen);
1197 int mwifiex_request_set_multicast_list(struct mwifiex_private *priv,
1198                         struct mwifiex_multicast_list *mcast_list);
1199 int mwifiex_copy_mcast_addr(struct mwifiex_multicast_list *mlist,
1200                             struct net_device *dev);
1201 int mwifiex_wait_queue_complete(struct mwifiex_adapter *adapter,
1202                                 struct cmd_ctrl_node *cmd_queued);
1203 int mwifiex_bss_start(struct mwifiex_private *priv, struct cfg80211_bss *bss,
1204                       struct cfg80211_ssid *req_ssid);
1205 int mwifiex_cancel_hs(struct mwifiex_private *priv, int cmd_type);
1206 int mwifiex_enable_hs(struct mwifiex_adapter *adapter);
1207 int mwifiex_disable_auto_ds(struct mwifiex_private *priv);
1208 int mwifiex_drv_get_data_rate(struct mwifiex_private *priv, u32 *rate);
1209 int mwifiex_request_scan(struct mwifiex_private *priv,
1210                          struct cfg80211_ssid *req_ssid);
1211 int mwifiex_scan_networks(struct mwifiex_private *priv,
1212                           const struct mwifiex_user_scan_cfg *user_scan_in);
1213 int mwifiex_set_radio(struct mwifiex_private *priv, u8 option);
1214
1215 int mwifiex_set_encode(struct mwifiex_private *priv, struct key_params *kp,
1216                        const u8 *key, int key_len, u8 key_index,
1217                        const u8 *mac_addr, int disable);
1218
1219 int mwifiex_set_gen_ie(struct mwifiex_private *priv, const u8 *ie, int ie_len);
1220
1221 int mwifiex_get_ver_ext(struct mwifiex_private *priv);
1222
1223 int mwifiex_remain_on_chan_cfg(struct mwifiex_private *priv, u16 action,
1224                                struct ieee80211_channel *chan,
1225                                unsigned int duration);
1226
1227 int mwifiex_set_bss_role(struct mwifiex_private *priv, u8 bss_role);
1228
1229 int mwifiex_get_stats_info(struct mwifiex_private *priv,
1230                            struct mwifiex_ds_get_stats *log);
1231
1232 int mwifiex_reg_write(struct mwifiex_private *priv, u32 reg_type,
1233                       u32 reg_offset, u32 reg_value);
1234
1235 int mwifiex_reg_read(struct mwifiex_private *priv, u32 reg_type,
1236                      u32 reg_offset, u32 *value);
1237
1238 int mwifiex_eeprom_read(struct mwifiex_private *priv, u16 offset, u16 bytes,
1239                         u8 *value);
1240
1241 int mwifiex_set_11n_httx_cfg(struct mwifiex_private *priv, int data);
1242
1243 int mwifiex_get_11n_httx_cfg(struct mwifiex_private *priv, int *data);
1244
1245 int mwifiex_set_tx_rate_cfg(struct mwifiex_private *priv, int tx_rate_index);
1246
1247 int mwifiex_get_tx_rate_cfg(struct mwifiex_private *priv, int *tx_rate_index);
1248
1249 int mwifiex_drv_set_power(struct mwifiex_private *priv, u32 *ps_mode);
1250
1251 int mwifiex_drv_get_driver_version(struct mwifiex_adapter *adapter,
1252                                    char *version, int max_len);
1253
1254 int mwifiex_set_tx_power(struct mwifiex_private *priv,
1255                          struct mwifiex_power_cfg *power_cfg);
1256
1257 int mwifiex_main_process(struct mwifiex_adapter *);
1258
1259 int mwifiex_queue_tx_pkt(struct mwifiex_private *priv, struct sk_buff *skb);
1260
1261 int mwifiex_get_bss_info(struct mwifiex_private *,
1262                          struct mwifiex_bss_info *);
1263 int mwifiex_fill_new_bss_desc(struct mwifiex_private *priv,
1264                               struct cfg80211_bss *bss,
1265                               struct mwifiex_bssdescriptor *bss_desc);
1266 int mwifiex_update_bss_desc_with_ie(struct mwifiex_adapter *adapter,
1267                                     struct mwifiex_bssdescriptor *bss_entry);
1268 int mwifiex_check_network_compatibility(struct mwifiex_private *priv,
1269                                         struct mwifiex_bssdescriptor *bss_desc);
1270
1271 u8 mwifiex_chan_type_to_sec_chan_offset(enum nl80211_channel_type chan_type);
1272
1273 struct wireless_dev *mwifiex_add_virtual_intf(struct wiphy *wiphy,
1274                                               const char *name,
1275                                               enum nl80211_iftype type,
1276                                               u32 *flags,
1277                                               struct vif_params *params);
1278 int mwifiex_del_virtual_intf(struct wiphy *wiphy, struct wireless_dev *wdev);
1279
1280 void mwifiex_set_sys_config_invalid_data(struct mwifiex_uap_bss_param *config);
1281
1282 int mwifiex_add_wowlan_magic_pkt_filter(struct mwifiex_adapter *adapter);
1283
1284 int mwifiex_set_mgmt_ies(struct mwifiex_private *priv,
1285                          struct cfg80211_beacon_data *data);
1286 int mwifiex_del_mgmt_ies(struct mwifiex_private *priv);
1287 u8 *mwifiex_11d_code_2_region(u8 code);
1288 void mwifiex_uap_del_sta_data(struct mwifiex_private *priv,
1289                               struct mwifiex_sta_node *node);
1290
1291 void mwifiex_11h_process_join(struct mwifiex_private *priv, u8 **buffer,
1292                               struct mwifiex_bssdescriptor *bss_desc);
1293 int mwifiex_11h_handle_event_chanswann(struct mwifiex_private *priv);
1294 int mwifiex_dnld_dt_cfgdata(struct mwifiex_private *priv,
1295                             struct device_node *node, const char *prefix);
1296 void mwifiex_dnld_txpwr_table(struct mwifiex_private *priv);
1297
1298 extern const struct ethtool_ops mwifiex_ethtool_ops;
1299
1300 void mwifiex_del_all_sta_list(struct mwifiex_private *priv);
1301 void mwifiex_del_sta_entry(struct mwifiex_private *priv, const u8 *mac);
1302 void
1303 mwifiex_set_sta_ht_cap(struct mwifiex_private *priv, const u8 *ies,
1304                        int ies_len, struct mwifiex_sta_node *node);
1305 struct mwifiex_sta_node *
1306 mwifiex_add_sta_entry(struct mwifiex_private *priv, const u8 *mac);
1307 struct mwifiex_sta_node *
1308 mwifiex_get_sta_entry(struct mwifiex_private *priv, const u8 *mac);
1309 int mwifiex_send_tdls_data_frame(struct mwifiex_private *priv, const u8 *peer,
1310                                  u8 action_code, u8 dialog_token,
1311                                  u16 status_code, const u8 *extra_ies,
1312                                  size_t extra_ies_len);
1313 int mwifiex_send_tdls_action_frame(struct mwifiex_private *priv, const u8 *peer,
1314                                    u8 action_code, u8 dialog_token,
1315                                    u16 status_code, const u8 *extra_ies,
1316                                    size_t extra_ies_len);
1317 void mwifiex_process_tdls_action_frame(struct mwifiex_private *priv,
1318                                        u8 *buf, int len);
1319 int mwifiex_tdls_oper(struct mwifiex_private *priv, const u8 *peer, u8 action);
1320 int mwifiex_get_tdls_link_status(struct mwifiex_private *priv, const u8 *mac);
1321 void mwifiex_disable_all_tdls_links(struct mwifiex_private *priv);
1322 bool mwifiex_is_bss_in_11ac_mode(struct mwifiex_private *priv);
1323 u8 mwifiex_get_center_freq_index(struct mwifiex_private *priv, u8 band,
1324                                  u32 pri_chan, u8 chan_bw);
1325 int mwifiex_init_channel_scan_gap(struct mwifiex_adapter *adapter);
1326
1327 int mwifiex_tdls_check_tx(struct mwifiex_private *priv, struct sk_buff *skb);
1328 void mwifiex_flush_auto_tdls_list(struct mwifiex_private *priv);
1329 void mwifiex_auto_tdls_update_peer_status(struct mwifiex_private *priv,
1330                                           const u8 *mac, u8 link_status);
1331 void mwifiex_auto_tdls_update_peer_signal(struct mwifiex_private *priv,
1332                                           u8 *mac, s8 snr, s8 nflr);
1333 void mwifiex_check_auto_tdls(unsigned long context);
1334 void mwifiex_add_auto_tdls_peer(struct mwifiex_private *priv, const u8 *mac);
1335 void mwifiex_setup_auto_tdls_timer(struct mwifiex_private *priv);
1336 void mwifiex_clean_auto_tdls(struct mwifiex_private *priv);
1337
1338 #ifdef CONFIG_DEBUG_FS
1339 void mwifiex_debugfs_init(void);
1340 void mwifiex_debugfs_remove(void);
1341
1342 void mwifiex_dev_debugfs_init(struct mwifiex_private *priv);
1343 void mwifiex_dev_debugfs_remove(struct mwifiex_private *priv);
1344 #endif
1345 #endif /* !_MWIFIEX_MAIN_H_ */