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